bfa_ioc.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998
  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. bfa_boolean_t
  1879. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1880. {
  1881. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1882. }
  1883. bfa_boolean_t
  1884. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1885. {
  1886. __be32 *msgp = mbmsg;
  1887. u32 r32;
  1888. int i;
  1889. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1890. if ((r32 & 1) == 0)
  1891. return BFA_FALSE;
  1892. /*
  1893. * read the MBOX msg
  1894. */
  1895. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1896. i++) {
  1897. r32 = readl(ioc->ioc_regs.lpu_mbox +
  1898. i * sizeof(u32));
  1899. msgp[i] = cpu_to_be32(r32);
  1900. }
  1901. /*
  1902. * turn off mailbox interrupt by clearing mailbox status
  1903. */
  1904. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1905. readl(ioc->ioc_regs.lpu_mbox_cmd);
  1906. return BFA_TRUE;
  1907. }
  1908. void
  1909. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1910. {
  1911. union bfi_ioc_i2h_msg_u *msg;
  1912. struct bfa_iocpf_s *iocpf = &ioc->iocpf;
  1913. msg = (union bfi_ioc_i2h_msg_u *) m;
  1914. bfa_ioc_stats(ioc, ioc_isrs);
  1915. switch (msg->mh.msg_id) {
  1916. case BFI_IOC_I2H_HBEAT:
  1917. break;
  1918. case BFI_IOC_I2H_ENABLE_REPLY:
  1919. ioc->port_mode = ioc->port_mode_cfg =
  1920. (enum bfa_mode_s)msg->fw_event.port_mode;
  1921. ioc->ad_cap_bm = msg->fw_event.cap_bm;
  1922. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1923. break;
  1924. case BFI_IOC_I2H_DISABLE_REPLY:
  1925. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  1926. break;
  1927. case BFI_IOC_I2H_GETATTR_REPLY:
  1928. bfa_ioc_getattr_reply(ioc);
  1929. break;
  1930. default:
  1931. bfa_trc(ioc, msg->mh.msg_id);
  1932. WARN_ON(1);
  1933. }
  1934. }
  1935. /*
  1936. * IOC attach time initialization and setup.
  1937. *
  1938. * @param[in] ioc memory for IOC
  1939. * @param[in] bfa driver instance structure
  1940. */
  1941. void
  1942. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1943. struct bfa_timer_mod_s *timer_mod)
  1944. {
  1945. ioc->bfa = bfa;
  1946. ioc->cbfn = cbfn;
  1947. ioc->timer_mod = timer_mod;
  1948. ioc->fcmode = BFA_FALSE;
  1949. ioc->pllinit = BFA_FALSE;
  1950. ioc->dbg_fwsave_once = BFA_TRUE;
  1951. ioc->iocpf.ioc = ioc;
  1952. bfa_ioc_mbox_attach(ioc);
  1953. INIT_LIST_HEAD(&ioc->notify_q);
  1954. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  1955. bfa_fsm_send_event(ioc, IOC_E_RESET);
  1956. }
  1957. /*
  1958. * Driver detach time IOC cleanup.
  1959. */
  1960. void
  1961. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1962. {
  1963. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1964. INIT_LIST_HEAD(&ioc->notify_q);
  1965. }
  1966. /*
  1967. * Setup IOC PCI properties.
  1968. *
  1969. * @param[in] pcidev PCI device information for this IOC
  1970. */
  1971. void
  1972. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1973. enum bfi_pcifn_class clscode)
  1974. {
  1975. ioc->clscode = clscode;
  1976. ioc->pcidev = *pcidev;
  1977. /*
  1978. * Initialize IOC and device personality
  1979. */
  1980. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
  1981. ioc->asic_mode = BFI_ASIC_MODE_FC;
  1982. switch (pcidev->device_id) {
  1983. case BFA_PCI_DEVICE_ID_FC_8G1P:
  1984. case BFA_PCI_DEVICE_ID_FC_8G2P:
  1985. ioc->asic_gen = BFI_ASIC_GEN_CB;
  1986. ioc->fcmode = BFA_TRUE;
  1987. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  1988. ioc->ad_cap_bm = BFA_CM_HBA;
  1989. break;
  1990. case BFA_PCI_DEVICE_ID_CT:
  1991. ioc->asic_gen = BFI_ASIC_GEN_CT;
  1992. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  1993. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  1994. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
  1995. ioc->ad_cap_bm = BFA_CM_CNA;
  1996. break;
  1997. case BFA_PCI_DEVICE_ID_CT_FC:
  1998. ioc->asic_gen = BFI_ASIC_GEN_CT;
  1999. ioc->fcmode = BFA_TRUE;
  2000. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2001. ioc->ad_cap_bm = BFA_CM_HBA;
  2002. break;
  2003. case BFA_PCI_DEVICE_ID_CT2:
  2004. case BFA_PCI_DEVICE_ID_CT2_QUAD:
  2005. ioc->asic_gen = BFI_ASIC_GEN_CT2;
  2006. if (clscode == BFI_PCIFN_CLASS_FC &&
  2007. pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
  2008. ioc->asic_mode = BFI_ASIC_MODE_FC16;
  2009. ioc->fcmode = BFA_TRUE;
  2010. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2011. ioc->ad_cap_bm = BFA_CM_HBA;
  2012. } else {
  2013. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2014. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2015. if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
  2016. ioc->port_mode =
  2017. ioc->port_mode_cfg = BFA_MODE_CNA;
  2018. ioc->ad_cap_bm = BFA_CM_CNA;
  2019. } else {
  2020. ioc->port_mode =
  2021. ioc->port_mode_cfg = BFA_MODE_NIC;
  2022. ioc->ad_cap_bm = BFA_CM_NIC;
  2023. }
  2024. }
  2025. break;
  2026. default:
  2027. WARN_ON(1);
  2028. }
  2029. /*
  2030. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  2031. */
  2032. if (ioc->asic_gen == BFI_ASIC_GEN_CB)
  2033. bfa_ioc_set_cb_hwif(ioc);
  2034. else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
  2035. bfa_ioc_set_ct_hwif(ioc);
  2036. else {
  2037. WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
  2038. bfa_ioc_set_ct2_hwif(ioc);
  2039. bfa_ioc_ct2_poweron(ioc);
  2040. }
  2041. bfa_ioc_map_port(ioc);
  2042. bfa_ioc_reg_init(ioc);
  2043. }
  2044. /*
  2045. * Initialize IOC dma memory
  2046. *
  2047. * @param[in] dm_kva kernel virtual address of IOC dma memory
  2048. * @param[in] dm_pa physical address of IOC dma memory
  2049. */
  2050. void
  2051. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  2052. {
  2053. /*
  2054. * dma memory for firmware attribute
  2055. */
  2056. ioc->attr_dma.kva = dm_kva;
  2057. ioc->attr_dma.pa = dm_pa;
  2058. ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
  2059. }
  2060. void
  2061. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  2062. {
  2063. bfa_ioc_stats(ioc, ioc_enables);
  2064. ioc->dbg_fwsave_once = BFA_TRUE;
  2065. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  2066. }
  2067. void
  2068. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  2069. {
  2070. bfa_ioc_stats(ioc, ioc_disables);
  2071. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  2072. }
  2073. void
  2074. bfa_ioc_suspend(struct bfa_ioc_s *ioc)
  2075. {
  2076. ioc->dbg_fwsave_once = BFA_TRUE;
  2077. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2078. }
  2079. /*
  2080. * Initialize memory for saving firmware trace. Driver must initialize
  2081. * trace memory before call bfa_ioc_enable().
  2082. */
  2083. void
  2084. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  2085. {
  2086. ioc->dbg_fwsave = dbg_fwsave;
  2087. ioc->dbg_fwsave_len = BFA_DBG_FWTRC_LEN;
  2088. }
  2089. /*
  2090. * Register mailbox message handler functions
  2091. *
  2092. * @param[in] ioc IOC instance
  2093. * @param[in] mcfuncs message class handler functions
  2094. */
  2095. void
  2096. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  2097. {
  2098. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2099. int mc;
  2100. for (mc = 0; mc < BFI_MC_MAX; mc++)
  2101. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  2102. }
  2103. /*
  2104. * Register mailbox message handler function, to be called by common modules
  2105. */
  2106. void
  2107. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  2108. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  2109. {
  2110. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2111. mod->mbhdlr[mc].cbfn = cbfn;
  2112. mod->mbhdlr[mc].cbarg = cbarg;
  2113. }
  2114. /*
  2115. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  2116. * Responsibility of caller to serialize
  2117. *
  2118. * @param[in] ioc IOC instance
  2119. * @param[i] cmd Mailbox command
  2120. */
  2121. void
  2122. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  2123. {
  2124. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2125. u32 stat;
  2126. /*
  2127. * If a previous command is pending, queue new command
  2128. */
  2129. if (!list_empty(&mod->cmd_q)) {
  2130. list_add_tail(&cmd->qe, &mod->cmd_q);
  2131. return;
  2132. }
  2133. /*
  2134. * If mailbox is busy, queue command for poll timer
  2135. */
  2136. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  2137. if (stat) {
  2138. list_add_tail(&cmd->qe, &mod->cmd_q);
  2139. return;
  2140. }
  2141. /*
  2142. * mailbox is free -- queue command to firmware
  2143. */
  2144. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  2145. }
  2146. /*
  2147. * Handle mailbox interrupts
  2148. */
  2149. void
  2150. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  2151. {
  2152. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2153. struct bfi_mbmsg_s m;
  2154. int mc;
  2155. if (bfa_ioc_msgget(ioc, &m)) {
  2156. /*
  2157. * Treat IOC message class as special.
  2158. */
  2159. mc = m.mh.msg_class;
  2160. if (mc == BFI_MC_IOC) {
  2161. bfa_ioc_isr(ioc, &m);
  2162. return;
  2163. }
  2164. if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  2165. return;
  2166. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  2167. }
  2168. bfa_ioc_lpu_read_stat(ioc);
  2169. /*
  2170. * Try to send pending mailbox commands
  2171. */
  2172. bfa_ioc_mbox_poll(ioc);
  2173. }
  2174. void
  2175. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  2176. {
  2177. bfa_ioc_stats(ioc, ioc_hbfails);
  2178. ioc->stats.hb_count = ioc->hb_count;
  2179. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2180. }
  2181. /*
  2182. * return true if IOC is disabled
  2183. */
  2184. bfa_boolean_t
  2185. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  2186. {
  2187. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  2188. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  2189. }
  2190. /*
  2191. * return true if IOC firmware is different.
  2192. */
  2193. bfa_boolean_t
  2194. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  2195. {
  2196. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
  2197. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
  2198. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
  2199. }
  2200. /*
  2201. * Check if adapter is disabled -- both IOCs should be in a disabled
  2202. * state.
  2203. */
  2204. bfa_boolean_t
  2205. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  2206. {
  2207. u32 ioc_state;
  2208. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  2209. return BFA_FALSE;
  2210. ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2211. if (!bfa_ioc_state_disabled(ioc_state))
  2212. return BFA_FALSE;
  2213. if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
  2214. ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2215. if (!bfa_ioc_state_disabled(ioc_state))
  2216. return BFA_FALSE;
  2217. }
  2218. return BFA_TRUE;
  2219. }
  2220. /*
  2221. * Reset IOC fwstate registers.
  2222. */
  2223. void
  2224. bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
  2225. {
  2226. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  2227. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  2228. }
  2229. #define BFA_MFG_NAME "QLogic"
  2230. void
  2231. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  2232. struct bfa_adapter_attr_s *ad_attr)
  2233. {
  2234. struct bfi_ioc_attr_s *ioc_attr;
  2235. ioc_attr = ioc->attr;
  2236. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  2237. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  2238. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  2239. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  2240. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  2241. sizeof(struct bfa_mfg_vpd_s));
  2242. ad_attr->nports = bfa_ioc_get_nports(ioc);
  2243. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  2244. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  2245. /* For now, model descr uses same model string */
  2246. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  2247. ad_attr->card_type = ioc_attr->card_type;
  2248. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  2249. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  2250. ad_attr->prototype = 1;
  2251. else
  2252. ad_attr->prototype = 0;
  2253. ad_attr->pwwn = ioc->attr->pwwn;
  2254. ad_attr->mac = bfa_ioc_get_mac(ioc);
  2255. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  2256. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  2257. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  2258. ad_attr->asic_rev = ioc_attr->asic_rev;
  2259. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  2260. ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
  2261. ad_attr->trunk_capable = (ad_attr->nports > 1) &&
  2262. !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
  2263. ad_attr->mfg_day = ioc_attr->mfg_day;
  2264. ad_attr->mfg_month = ioc_attr->mfg_month;
  2265. ad_attr->mfg_year = ioc_attr->mfg_year;
  2266. memcpy(ad_attr->uuid, ioc_attr->uuid, BFA_ADAPTER_UUID_LEN);
  2267. }
  2268. enum bfa_ioc_type_e
  2269. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  2270. {
  2271. if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
  2272. return BFA_IOC_TYPE_LL;
  2273. WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
  2274. return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
  2275. ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
  2276. }
  2277. void
  2278. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  2279. {
  2280. memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  2281. memcpy((void *)serial_num,
  2282. (void *)ioc->attr->brcd_serialnum,
  2283. BFA_ADAPTER_SERIAL_NUM_LEN);
  2284. }
  2285. void
  2286. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  2287. {
  2288. memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  2289. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  2290. }
  2291. void
  2292. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  2293. {
  2294. WARN_ON(!chip_rev);
  2295. memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  2296. chip_rev[0] = 'R';
  2297. chip_rev[1] = 'e';
  2298. chip_rev[2] = 'v';
  2299. chip_rev[3] = '-';
  2300. chip_rev[4] = ioc->attr->asic_rev;
  2301. chip_rev[5] = '\0';
  2302. }
  2303. void
  2304. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  2305. {
  2306. memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  2307. memcpy(optrom_ver, ioc->attr->optrom_version,
  2308. BFA_VERSION_LEN);
  2309. }
  2310. void
  2311. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  2312. {
  2313. memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  2314. strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2315. }
  2316. void
  2317. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  2318. {
  2319. struct bfi_ioc_attr_s *ioc_attr;
  2320. u8 nports = bfa_ioc_get_nports(ioc);
  2321. WARN_ON(!model);
  2322. memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2323. ioc_attr = ioc->attr;
  2324. if (bfa_asic_id_ct2(ioc->pcidev.device_id) &&
  2325. (!bfa_mfg_is_mezz(ioc_attr->card_type)))
  2326. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u-%u%s",
  2327. BFA_MFG_NAME, ioc_attr->card_type, nports, "p");
  2328. else
  2329. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2330. BFA_MFG_NAME, ioc_attr->card_type);
  2331. }
  2332. enum bfa_ioc_state
  2333. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  2334. {
  2335. enum bfa_iocpf_state iocpf_st;
  2336. enum bfa_ioc_state ioc_st = bfa_ioc_sm_to_state(ioc_sm_table, ioc->fsm);
  2337. if (ioc_st == BFA_IOC_ENABLING ||
  2338. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2339. iocpf_st = bfa_iocpf_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2340. switch (iocpf_st) {
  2341. case BFA_IOCPF_SEMWAIT:
  2342. ioc_st = BFA_IOC_SEMWAIT;
  2343. break;
  2344. case BFA_IOCPF_HWINIT:
  2345. ioc_st = BFA_IOC_HWINIT;
  2346. break;
  2347. case BFA_IOCPF_FWMISMATCH:
  2348. ioc_st = BFA_IOC_FWMISMATCH;
  2349. break;
  2350. case BFA_IOCPF_FAIL:
  2351. ioc_st = BFA_IOC_FAIL;
  2352. break;
  2353. case BFA_IOCPF_INITFAIL:
  2354. ioc_st = BFA_IOC_INITFAIL;
  2355. break;
  2356. default:
  2357. break;
  2358. }
  2359. }
  2360. return ioc_st;
  2361. }
  2362. void
  2363. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  2364. {
  2365. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  2366. ioc_attr->state = bfa_ioc_get_state(ioc);
  2367. ioc_attr->port_id = bfa_ioc_portid(ioc);
  2368. ioc_attr->port_mode = ioc->port_mode;
  2369. ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
  2370. ioc_attr->cap_bm = ioc->ad_cap_bm;
  2371. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2372. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2373. ioc_attr->pci_attr.device_id = bfa_ioc_devid(ioc);
  2374. ioc_attr->pci_attr.pcifn = bfa_ioc_pcifn(ioc);
  2375. ioc_attr->def_fn = (bfa_ioc_pcifn(ioc) == bfa_ioc_portid(ioc));
  2376. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2377. }
  2378. mac_t
  2379. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  2380. {
  2381. /*
  2382. * Check the IOC type and return the appropriate MAC
  2383. */
  2384. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  2385. return ioc->attr->fcoe_mac;
  2386. else
  2387. return ioc->attr->mac;
  2388. }
  2389. mac_t
  2390. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  2391. {
  2392. mac_t m;
  2393. m = ioc->attr->mfg_mac;
  2394. if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
  2395. m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  2396. else
  2397. bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
  2398. bfa_ioc_pcifn(ioc));
  2399. return m;
  2400. }
  2401. /*
  2402. * Send AEN notification
  2403. */
  2404. void
  2405. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  2406. {
  2407. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  2408. struct bfa_aen_entry_s *aen_entry;
  2409. enum bfa_ioc_type_e ioc_type;
  2410. bfad_get_aen_entry(bfad, aen_entry);
  2411. if (!aen_entry)
  2412. return;
  2413. ioc_type = bfa_ioc_get_type(ioc);
  2414. switch (ioc_type) {
  2415. case BFA_IOC_TYPE_FC:
  2416. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2417. break;
  2418. case BFA_IOC_TYPE_FCoE:
  2419. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2420. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2421. break;
  2422. case BFA_IOC_TYPE_LL:
  2423. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2424. break;
  2425. default:
  2426. WARN_ON(ioc_type != BFA_IOC_TYPE_FC);
  2427. break;
  2428. }
  2429. /* Send the AEN notification */
  2430. aen_entry->aen_data.ioc.ioc_type = ioc_type;
  2431. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  2432. BFA_AEN_CAT_IOC, event);
  2433. }
  2434. /*
  2435. * Retrieve saved firmware trace from a prior IOC failure.
  2436. */
  2437. bfa_status_t
  2438. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2439. {
  2440. int tlen;
  2441. if (ioc->dbg_fwsave_len == 0)
  2442. return BFA_STATUS_ENOFSAVE;
  2443. tlen = *trclen;
  2444. if (tlen > ioc->dbg_fwsave_len)
  2445. tlen = ioc->dbg_fwsave_len;
  2446. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  2447. *trclen = tlen;
  2448. return BFA_STATUS_OK;
  2449. }
  2450. /*
  2451. * Retrieve saved firmware trace from a prior IOC failure.
  2452. */
  2453. bfa_status_t
  2454. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2455. {
  2456. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  2457. int tlen;
  2458. bfa_status_t status;
  2459. bfa_trc(ioc, *trclen);
  2460. tlen = *trclen;
  2461. if (tlen > BFA_DBG_FWTRC_LEN)
  2462. tlen = BFA_DBG_FWTRC_LEN;
  2463. status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
  2464. *trclen = tlen;
  2465. return status;
  2466. }
  2467. static void
  2468. bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
  2469. {
  2470. struct bfa_mbox_cmd_s cmd;
  2471. struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
  2472. bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
  2473. bfa_ioc_portid(ioc));
  2474. req->clscode = cpu_to_be16(ioc->clscode);
  2475. bfa_ioc_mbox_queue(ioc, &cmd);
  2476. }
  2477. static void
  2478. bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
  2479. {
  2480. u32 fwsync_iter = 1000;
  2481. bfa_ioc_send_fwsync(ioc);
  2482. /*
  2483. * After sending a fw sync mbox command wait for it to
  2484. * take effect. We will not wait for a response because
  2485. * 1. fw_sync mbox cmd doesn't have a response.
  2486. * 2. Even if we implement that, interrupts might not
  2487. * be enabled when we call this function.
  2488. * So, just keep checking if any mbox cmd is pending, and
  2489. * after waiting for a reasonable amount of time, go ahead.
  2490. * It is possible that fw has crashed and the mbox command
  2491. * is never acknowledged.
  2492. */
  2493. while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
  2494. fwsync_iter--;
  2495. }
  2496. /*
  2497. * Dump firmware smem
  2498. */
  2499. bfa_status_t
  2500. bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  2501. u32 *offset, int *buflen)
  2502. {
  2503. u32 loff;
  2504. int dlen;
  2505. bfa_status_t status;
  2506. u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
  2507. if (*offset >= smem_len) {
  2508. *offset = *buflen = 0;
  2509. return BFA_STATUS_EINVAL;
  2510. }
  2511. loff = *offset;
  2512. dlen = *buflen;
  2513. /*
  2514. * First smem read, sync smem before proceeding
  2515. * No need to sync before reading every chunk.
  2516. */
  2517. if (loff == 0)
  2518. bfa_ioc_fwsync(ioc);
  2519. if ((loff + dlen) >= smem_len)
  2520. dlen = smem_len - loff;
  2521. status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
  2522. if (status != BFA_STATUS_OK) {
  2523. *offset = *buflen = 0;
  2524. return status;
  2525. }
  2526. *offset += dlen;
  2527. if (*offset >= smem_len)
  2528. *offset = 0;
  2529. *buflen = dlen;
  2530. return status;
  2531. }
  2532. /*
  2533. * Firmware statistics
  2534. */
  2535. bfa_status_t
  2536. bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
  2537. {
  2538. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2539. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2540. int tlen;
  2541. bfa_status_t status;
  2542. if (ioc->stats_busy) {
  2543. bfa_trc(ioc, ioc->stats_busy);
  2544. return BFA_STATUS_DEVBUSY;
  2545. }
  2546. ioc->stats_busy = BFA_TRUE;
  2547. tlen = sizeof(struct bfa_fw_stats_s);
  2548. status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
  2549. ioc->stats_busy = BFA_FALSE;
  2550. return status;
  2551. }
  2552. bfa_status_t
  2553. bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
  2554. {
  2555. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2556. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2557. int tlen;
  2558. bfa_status_t status;
  2559. if (ioc->stats_busy) {
  2560. bfa_trc(ioc, ioc->stats_busy);
  2561. return BFA_STATUS_DEVBUSY;
  2562. }
  2563. ioc->stats_busy = BFA_TRUE;
  2564. tlen = sizeof(struct bfa_fw_stats_s);
  2565. status = bfa_ioc_smem_clr(ioc, loff, tlen);
  2566. ioc->stats_busy = BFA_FALSE;
  2567. return status;
  2568. }
  2569. /*
  2570. * Save firmware trace if configured.
  2571. */
  2572. void
  2573. bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
  2574. {
  2575. int tlen;
  2576. if (ioc->dbg_fwsave_once) {
  2577. ioc->dbg_fwsave_once = BFA_FALSE;
  2578. if (ioc->dbg_fwsave_len) {
  2579. tlen = ioc->dbg_fwsave_len;
  2580. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  2581. }
  2582. }
  2583. }
  2584. /*
  2585. * Firmware failure detected. Start recovery actions.
  2586. */
  2587. static void
  2588. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  2589. {
  2590. bfa_ioc_stats(ioc, ioc_hbfails);
  2591. ioc->stats.hb_count = ioc->hb_count;
  2592. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2593. }
  2594. /*
  2595. * BFA IOC PF private functions
  2596. */
  2597. static void
  2598. bfa_iocpf_timeout(void *ioc_arg)
  2599. {
  2600. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2601. bfa_trc(ioc, 0);
  2602. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2603. }
  2604. static void
  2605. bfa_iocpf_sem_timeout(void *ioc_arg)
  2606. {
  2607. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2608. bfa_ioc_hw_sem_get(ioc);
  2609. }
  2610. static void
  2611. bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
  2612. {
  2613. u32 fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2614. bfa_trc(ioc, fwstate);
  2615. if (fwstate == BFI_IOC_DISABLED) {
  2616. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  2617. return;
  2618. }
  2619. if (ioc->iocpf.poll_time >= (3 * BFA_IOC_TOV))
  2620. bfa_iocpf_timeout(ioc);
  2621. else {
  2622. ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
  2623. bfa_iocpf_poll_timer_start(ioc);
  2624. }
  2625. }
  2626. static void
  2627. bfa_iocpf_poll_timeout(void *ioc_arg)
  2628. {
  2629. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2630. bfa_ioc_poll_fwinit(ioc);
  2631. }
  2632. /*
  2633. * bfa timer function
  2634. */
  2635. void
  2636. bfa_timer_beat(struct bfa_timer_mod_s *mod)
  2637. {
  2638. struct list_head *qh = &mod->timer_q;
  2639. struct list_head *qe, *qe_next;
  2640. struct bfa_timer_s *elem;
  2641. struct list_head timedout_q;
  2642. INIT_LIST_HEAD(&timedout_q);
  2643. qe = bfa_q_next(qh);
  2644. while (qe != qh) {
  2645. qe_next = bfa_q_next(qe);
  2646. elem = (struct bfa_timer_s *) qe;
  2647. if (elem->timeout <= BFA_TIMER_FREQ) {
  2648. elem->timeout = 0;
  2649. list_del(&elem->qe);
  2650. list_add_tail(&elem->qe, &timedout_q);
  2651. } else {
  2652. elem->timeout -= BFA_TIMER_FREQ;
  2653. }
  2654. qe = qe_next; /* go to next elem */
  2655. }
  2656. /*
  2657. * Pop all the timeout entries
  2658. */
  2659. while (!list_empty(&timedout_q)) {
  2660. bfa_q_deq(&timedout_q, &elem);
  2661. elem->timercb(elem->arg);
  2662. }
  2663. }
  2664. /*
  2665. * Should be called with lock protection
  2666. */
  2667. void
  2668. bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  2669. void (*timercb) (void *), void *arg, unsigned int timeout)
  2670. {
  2671. WARN_ON(timercb == NULL);
  2672. WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
  2673. timer->timeout = timeout;
  2674. timer->timercb = timercb;
  2675. timer->arg = arg;
  2676. list_add_tail(&timer->qe, &mod->timer_q);
  2677. }
  2678. /*
  2679. * Should be called with lock protection
  2680. */
  2681. void
  2682. bfa_timer_stop(struct bfa_timer_s *timer)
  2683. {
  2684. WARN_ON(list_empty(&timer->qe));
  2685. list_del(&timer->qe);
  2686. }
  2687. /*
  2688. * ASIC block related
  2689. */
  2690. static void
  2691. bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
  2692. {
  2693. struct bfa_ablk_cfg_inst_s *cfg_inst;
  2694. int i, j;
  2695. u16 be16;
  2696. for (i = 0; i < BFA_ABLK_MAX; i++) {
  2697. cfg_inst = &cfg->inst[i];
  2698. for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
  2699. be16 = cfg_inst->pf_cfg[j].pers;
  2700. cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
  2701. be16 = cfg_inst->pf_cfg[j].num_qpairs;
  2702. cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
  2703. be16 = cfg_inst->pf_cfg[j].num_vectors;
  2704. cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
  2705. be16 = cfg_inst->pf_cfg[j].bw_min;
  2706. cfg_inst->pf_cfg[j].bw_min = be16_to_cpu(be16);
  2707. be16 = cfg_inst->pf_cfg[j].bw_max;
  2708. cfg_inst->pf_cfg[j].bw_max = be16_to_cpu(be16);
  2709. }
  2710. }
  2711. }
  2712. static void
  2713. bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
  2714. {
  2715. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2716. struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
  2717. bfa_ablk_cbfn_t cbfn;
  2718. WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
  2719. bfa_trc(ablk->ioc, msg->mh.msg_id);
  2720. switch (msg->mh.msg_id) {
  2721. case BFI_ABLK_I2H_QUERY:
  2722. if (rsp->status == BFA_STATUS_OK) {
  2723. memcpy(ablk->cfg, ablk->dma_addr.kva,
  2724. sizeof(struct bfa_ablk_cfg_s));
  2725. bfa_ablk_config_swap(ablk->cfg);
  2726. ablk->cfg = NULL;
  2727. }
  2728. break;
  2729. case BFI_ABLK_I2H_ADPT_CONFIG:
  2730. case BFI_ABLK_I2H_PORT_CONFIG:
  2731. /* update config port mode */
  2732. ablk->ioc->port_mode_cfg = rsp->port_mode;
  2733. break;
  2734. case BFI_ABLK_I2H_PF_DELETE:
  2735. case BFI_ABLK_I2H_PF_UPDATE:
  2736. case BFI_ABLK_I2H_OPTROM_ENABLE:
  2737. case BFI_ABLK_I2H_OPTROM_DISABLE:
  2738. /* No-op */
  2739. break;
  2740. case BFI_ABLK_I2H_PF_CREATE:
  2741. *(ablk->pcifn) = rsp->pcifn;
  2742. ablk->pcifn = NULL;
  2743. break;
  2744. default:
  2745. WARN_ON(1);
  2746. }
  2747. ablk->busy = BFA_FALSE;
  2748. if (ablk->cbfn) {
  2749. cbfn = ablk->cbfn;
  2750. ablk->cbfn = NULL;
  2751. cbfn(ablk->cbarg, rsp->status);
  2752. }
  2753. }
  2754. static void
  2755. bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
  2756. {
  2757. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2758. bfa_trc(ablk->ioc, event);
  2759. switch (event) {
  2760. case BFA_IOC_E_ENABLED:
  2761. WARN_ON(ablk->busy != BFA_FALSE);
  2762. break;
  2763. case BFA_IOC_E_DISABLED:
  2764. case BFA_IOC_E_FAILED:
  2765. /* Fail any pending requests */
  2766. ablk->pcifn = NULL;
  2767. if (ablk->busy) {
  2768. if (ablk->cbfn)
  2769. ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
  2770. ablk->cbfn = NULL;
  2771. ablk->busy = BFA_FALSE;
  2772. }
  2773. break;
  2774. default:
  2775. WARN_ON(1);
  2776. break;
  2777. }
  2778. }
  2779. u32
  2780. bfa_ablk_meminfo(void)
  2781. {
  2782. return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
  2783. }
  2784. void
  2785. bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
  2786. {
  2787. ablk->dma_addr.kva = dma_kva;
  2788. ablk->dma_addr.pa = dma_pa;
  2789. }
  2790. void
  2791. bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
  2792. {
  2793. ablk->ioc = ioc;
  2794. bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
  2795. bfa_q_qe_init(&ablk->ioc_notify);
  2796. bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
  2797. list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
  2798. }
  2799. bfa_status_t
  2800. bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
  2801. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2802. {
  2803. struct bfi_ablk_h2i_query_s *m;
  2804. WARN_ON(!ablk_cfg);
  2805. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2806. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2807. return BFA_STATUS_IOC_FAILURE;
  2808. }
  2809. if (ablk->busy) {
  2810. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2811. return BFA_STATUS_DEVBUSY;
  2812. }
  2813. ablk->cfg = ablk_cfg;
  2814. ablk->cbfn = cbfn;
  2815. ablk->cbarg = cbarg;
  2816. ablk->busy = BFA_TRUE;
  2817. m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
  2818. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
  2819. bfa_ioc_portid(ablk->ioc));
  2820. bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
  2821. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2822. return BFA_STATUS_OK;
  2823. }
  2824. bfa_status_t
  2825. bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
  2826. u8 port, enum bfi_pcifn_class personality,
  2827. u16 bw_min, u16 bw_max,
  2828. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2829. {
  2830. struct bfi_ablk_h2i_pf_req_s *m;
  2831. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2832. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2833. return BFA_STATUS_IOC_FAILURE;
  2834. }
  2835. if (ablk->busy) {
  2836. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2837. return BFA_STATUS_DEVBUSY;
  2838. }
  2839. ablk->pcifn = pcifn;
  2840. ablk->cbfn = cbfn;
  2841. ablk->cbarg = cbarg;
  2842. ablk->busy = BFA_TRUE;
  2843. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2844. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
  2845. bfa_ioc_portid(ablk->ioc));
  2846. m->pers = cpu_to_be16((u16)personality);
  2847. m->bw_min = cpu_to_be16(bw_min);
  2848. m->bw_max = cpu_to_be16(bw_max);
  2849. m->port = port;
  2850. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2851. return BFA_STATUS_OK;
  2852. }
  2853. bfa_status_t
  2854. bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
  2855. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2856. {
  2857. struct bfi_ablk_h2i_pf_req_s *m;
  2858. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2859. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2860. return BFA_STATUS_IOC_FAILURE;
  2861. }
  2862. if (ablk->busy) {
  2863. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2864. return BFA_STATUS_DEVBUSY;
  2865. }
  2866. ablk->cbfn = cbfn;
  2867. ablk->cbarg = cbarg;
  2868. ablk->busy = BFA_TRUE;
  2869. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2870. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
  2871. bfa_ioc_portid(ablk->ioc));
  2872. m->pcifn = (u8)pcifn;
  2873. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2874. return BFA_STATUS_OK;
  2875. }
  2876. bfa_status_t
  2877. bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
  2878. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2879. {
  2880. struct bfi_ablk_h2i_cfg_req_s *m;
  2881. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2882. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2883. return BFA_STATUS_IOC_FAILURE;
  2884. }
  2885. if (ablk->busy) {
  2886. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2887. return BFA_STATUS_DEVBUSY;
  2888. }
  2889. ablk->cbfn = cbfn;
  2890. ablk->cbarg = cbarg;
  2891. ablk->busy = BFA_TRUE;
  2892. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2893. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
  2894. bfa_ioc_portid(ablk->ioc));
  2895. m->mode = (u8)mode;
  2896. m->max_pf = (u8)max_pf;
  2897. m->max_vf = (u8)max_vf;
  2898. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2899. return BFA_STATUS_OK;
  2900. }
  2901. bfa_status_t
  2902. bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
  2903. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2904. {
  2905. struct bfi_ablk_h2i_cfg_req_s *m;
  2906. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2907. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2908. return BFA_STATUS_IOC_FAILURE;
  2909. }
  2910. if (ablk->busy) {
  2911. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2912. return BFA_STATUS_DEVBUSY;
  2913. }
  2914. ablk->cbfn = cbfn;
  2915. ablk->cbarg = cbarg;
  2916. ablk->busy = BFA_TRUE;
  2917. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2918. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
  2919. bfa_ioc_portid(ablk->ioc));
  2920. m->port = (u8)port;
  2921. m->mode = (u8)mode;
  2922. m->max_pf = (u8)max_pf;
  2923. m->max_vf = (u8)max_vf;
  2924. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2925. return BFA_STATUS_OK;
  2926. }
  2927. bfa_status_t
  2928. bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, u16 bw_min,
  2929. u16 bw_max, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2930. {
  2931. struct bfi_ablk_h2i_pf_req_s *m;
  2932. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2933. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2934. return BFA_STATUS_IOC_FAILURE;
  2935. }
  2936. if (ablk->busy) {
  2937. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2938. return BFA_STATUS_DEVBUSY;
  2939. }
  2940. ablk->cbfn = cbfn;
  2941. ablk->cbarg = cbarg;
  2942. ablk->busy = BFA_TRUE;
  2943. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2944. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
  2945. bfa_ioc_portid(ablk->ioc));
  2946. m->pcifn = (u8)pcifn;
  2947. m->bw_min = cpu_to_be16(bw_min);
  2948. m->bw_max = cpu_to_be16(bw_max);
  2949. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2950. return BFA_STATUS_OK;
  2951. }
  2952. bfa_status_t
  2953. bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2954. {
  2955. struct bfi_ablk_h2i_optrom_s *m;
  2956. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2957. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2958. return BFA_STATUS_IOC_FAILURE;
  2959. }
  2960. if (ablk->busy) {
  2961. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2962. return BFA_STATUS_DEVBUSY;
  2963. }
  2964. ablk->cbfn = cbfn;
  2965. ablk->cbarg = cbarg;
  2966. ablk->busy = BFA_TRUE;
  2967. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  2968. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
  2969. bfa_ioc_portid(ablk->ioc));
  2970. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2971. return BFA_STATUS_OK;
  2972. }
  2973. bfa_status_t
  2974. bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2975. {
  2976. struct bfi_ablk_h2i_optrom_s *m;
  2977. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2978. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2979. return BFA_STATUS_IOC_FAILURE;
  2980. }
  2981. if (ablk->busy) {
  2982. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2983. return BFA_STATUS_DEVBUSY;
  2984. }
  2985. ablk->cbfn = cbfn;
  2986. ablk->cbarg = cbarg;
  2987. ablk->busy = BFA_TRUE;
  2988. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  2989. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
  2990. bfa_ioc_portid(ablk->ioc));
  2991. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2992. return BFA_STATUS_OK;
  2993. }
  2994. /*
  2995. * SFP module specific
  2996. */
  2997. /* forward declarations */
  2998. static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
  2999. static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
  3000. static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
  3001. enum bfa_port_speed portspeed);
  3002. static void
  3003. bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
  3004. {
  3005. bfa_trc(sfp, sfp->lock);
  3006. if (sfp->cbfn)
  3007. sfp->cbfn(sfp->cbarg, sfp->status);
  3008. sfp->lock = 0;
  3009. sfp->cbfn = NULL;
  3010. }
  3011. static void
  3012. bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
  3013. {
  3014. bfa_trc(sfp, sfp->portspeed);
  3015. if (sfp->media) {
  3016. bfa_sfp_media_get(sfp);
  3017. if (sfp->state_query_cbfn)
  3018. sfp->state_query_cbfn(sfp->state_query_cbarg,
  3019. sfp->status);
  3020. sfp->media = NULL;
  3021. }
  3022. if (sfp->portspeed) {
  3023. sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
  3024. if (sfp->state_query_cbfn)
  3025. sfp->state_query_cbfn(sfp->state_query_cbarg,
  3026. sfp->status);
  3027. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3028. }
  3029. sfp->state_query_lock = 0;
  3030. sfp->state_query_cbfn = NULL;
  3031. }
  3032. /*
  3033. * IOC event handler.
  3034. */
  3035. static void
  3036. bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
  3037. {
  3038. struct bfa_sfp_s *sfp = sfp_arg;
  3039. bfa_trc(sfp, event);
  3040. bfa_trc(sfp, sfp->lock);
  3041. bfa_trc(sfp, sfp->state_query_lock);
  3042. switch (event) {
  3043. case BFA_IOC_E_DISABLED:
  3044. case BFA_IOC_E_FAILED:
  3045. if (sfp->lock) {
  3046. sfp->status = BFA_STATUS_IOC_FAILURE;
  3047. bfa_cb_sfp_show(sfp);
  3048. }
  3049. if (sfp->state_query_lock) {
  3050. sfp->status = BFA_STATUS_IOC_FAILURE;
  3051. bfa_cb_sfp_state_query(sfp);
  3052. }
  3053. break;
  3054. default:
  3055. break;
  3056. }
  3057. }
  3058. /*
  3059. * SFP's State Change Notification post to AEN
  3060. */
  3061. static void
  3062. bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp)
  3063. {
  3064. struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad;
  3065. struct bfa_aen_entry_s *aen_entry;
  3066. enum bfa_port_aen_event aen_evt = 0;
  3067. bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) |
  3068. ((u64)rsp->event));
  3069. bfad_get_aen_entry(bfad, aen_entry);
  3070. if (!aen_entry)
  3071. return;
  3072. aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc);
  3073. aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn;
  3074. aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc);
  3075. switch (rsp->event) {
  3076. case BFA_SFP_SCN_INSERTED:
  3077. aen_evt = BFA_PORT_AEN_SFP_INSERT;
  3078. break;
  3079. case BFA_SFP_SCN_REMOVED:
  3080. aen_evt = BFA_PORT_AEN_SFP_REMOVE;
  3081. break;
  3082. case BFA_SFP_SCN_FAILED:
  3083. aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR;
  3084. break;
  3085. case BFA_SFP_SCN_UNSUPPORT:
  3086. aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT;
  3087. break;
  3088. case BFA_SFP_SCN_POM:
  3089. aen_evt = BFA_PORT_AEN_SFP_POM;
  3090. aen_entry->aen_data.port.level = rsp->pomlvl;
  3091. break;
  3092. default:
  3093. bfa_trc(sfp, rsp->event);
  3094. WARN_ON(1);
  3095. }
  3096. /* Send the AEN notification */
  3097. bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq,
  3098. BFA_AEN_CAT_PORT, aen_evt);
  3099. }
  3100. /*
  3101. * SFP get data send
  3102. */
  3103. static void
  3104. bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
  3105. {
  3106. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3107. bfa_trc(sfp, req->memtype);
  3108. /* build host command */
  3109. bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
  3110. bfa_ioc_portid(sfp->ioc));
  3111. /* send mbox cmd */
  3112. bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
  3113. }
  3114. /*
  3115. * SFP is valid, read sfp data
  3116. */
  3117. static void
  3118. bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
  3119. {
  3120. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3121. WARN_ON(sfp->lock != 0);
  3122. bfa_trc(sfp, sfp->state);
  3123. sfp->lock = 1;
  3124. sfp->memtype = memtype;
  3125. req->memtype = memtype;
  3126. /* Setup SG list */
  3127. bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
  3128. bfa_sfp_getdata_send(sfp);
  3129. }
  3130. /*
  3131. * SFP scn handler
  3132. */
  3133. static void
  3134. bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  3135. {
  3136. struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg;
  3137. switch (rsp->event) {
  3138. case BFA_SFP_SCN_INSERTED:
  3139. sfp->state = BFA_SFP_STATE_INSERTED;
  3140. sfp->data_valid = 0;
  3141. bfa_sfp_scn_aen_post(sfp, rsp);
  3142. break;
  3143. case BFA_SFP_SCN_REMOVED:
  3144. sfp->state = BFA_SFP_STATE_REMOVED;
  3145. sfp->data_valid = 0;
  3146. bfa_sfp_scn_aen_post(sfp, rsp);
  3147. break;
  3148. case BFA_SFP_SCN_FAILED:
  3149. sfp->state = BFA_SFP_STATE_FAILED;
  3150. sfp->data_valid = 0;
  3151. bfa_sfp_scn_aen_post(sfp, rsp);
  3152. break;
  3153. case BFA_SFP_SCN_UNSUPPORT:
  3154. sfp->state = BFA_SFP_STATE_UNSUPPORT;
  3155. bfa_sfp_scn_aen_post(sfp, rsp);
  3156. if (!sfp->lock)
  3157. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3158. break;
  3159. case BFA_SFP_SCN_POM:
  3160. bfa_sfp_scn_aen_post(sfp, rsp);
  3161. break;
  3162. case BFA_SFP_SCN_VALID:
  3163. sfp->state = BFA_SFP_STATE_VALID;
  3164. if (!sfp->lock)
  3165. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3166. break;
  3167. default:
  3168. bfa_trc(sfp, rsp->event);
  3169. WARN_ON(1);
  3170. }
  3171. }
  3172. /*
  3173. * SFP show complete
  3174. */
  3175. static void
  3176. bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  3177. {
  3178. struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
  3179. if (!sfp->lock) {
  3180. /*
  3181. * receiving response after ioc failure
  3182. */
  3183. bfa_trc(sfp, sfp->lock);
  3184. return;
  3185. }
  3186. bfa_trc(sfp, rsp->status);
  3187. if (rsp->status == BFA_STATUS_OK) {
  3188. sfp->data_valid = 1;
  3189. if (sfp->state == BFA_SFP_STATE_VALID)
  3190. sfp->status = BFA_STATUS_OK;
  3191. else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3192. sfp->status = BFA_STATUS_SFP_UNSUPP;
  3193. else
  3194. bfa_trc(sfp, sfp->state);
  3195. } else {
  3196. sfp->data_valid = 0;
  3197. sfp->status = rsp->status;
  3198. /* sfpshow shouldn't change sfp state */
  3199. }
  3200. bfa_trc(sfp, sfp->memtype);
  3201. if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
  3202. bfa_trc(sfp, sfp->data_valid);
  3203. if (sfp->data_valid) {
  3204. u32 size = sizeof(struct sfp_mem_s);
  3205. u8 *des = (u8 *)(sfp->sfpmem);
  3206. memcpy(des, sfp->dbuf_kva, size);
  3207. }
  3208. /*
  3209. * Queue completion callback.
  3210. */
  3211. bfa_cb_sfp_show(sfp);
  3212. } else
  3213. sfp->lock = 0;
  3214. bfa_trc(sfp, sfp->state_query_lock);
  3215. if (sfp->state_query_lock) {
  3216. sfp->state = rsp->state;
  3217. /* Complete callback */
  3218. bfa_cb_sfp_state_query(sfp);
  3219. }
  3220. }
  3221. /*
  3222. * SFP query fw sfp state
  3223. */
  3224. static void
  3225. bfa_sfp_state_query(struct bfa_sfp_s *sfp)
  3226. {
  3227. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3228. /* Should not be doing query if not in _INIT state */
  3229. WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
  3230. WARN_ON(sfp->state_query_lock != 0);
  3231. bfa_trc(sfp, sfp->state);
  3232. sfp->state_query_lock = 1;
  3233. req->memtype = 0;
  3234. if (!sfp->lock)
  3235. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3236. }
  3237. static void
  3238. bfa_sfp_media_get(struct bfa_sfp_s *sfp)
  3239. {
  3240. enum bfa_defs_sfp_media_e *media = sfp->media;
  3241. *media = BFA_SFP_MEDIA_UNKNOWN;
  3242. if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3243. *media = BFA_SFP_MEDIA_UNSUPPORT;
  3244. else if (sfp->state == BFA_SFP_STATE_VALID) {
  3245. union sfp_xcvr_e10g_code_u e10g;
  3246. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3247. u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
  3248. (sfpmem->srlid_base.xcvr[5] >> 1);
  3249. e10g.b = sfpmem->srlid_base.xcvr[0];
  3250. bfa_trc(sfp, e10g.b);
  3251. bfa_trc(sfp, xmtr_tech);
  3252. /* check fc transmitter tech */
  3253. if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
  3254. (xmtr_tech & SFP_XMTR_TECH_CP) ||
  3255. (xmtr_tech & SFP_XMTR_TECH_CA))
  3256. *media = BFA_SFP_MEDIA_CU;
  3257. else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
  3258. (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
  3259. *media = BFA_SFP_MEDIA_EL;
  3260. else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
  3261. (xmtr_tech & SFP_XMTR_TECH_LC))
  3262. *media = BFA_SFP_MEDIA_LW;
  3263. else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
  3264. (xmtr_tech & SFP_XMTR_TECH_SN) ||
  3265. (xmtr_tech & SFP_XMTR_TECH_SA))
  3266. *media = BFA_SFP_MEDIA_SW;
  3267. /* Check 10G Ethernet Compilance code */
  3268. else if (e10g.r.e10g_sr)
  3269. *media = BFA_SFP_MEDIA_SW;
  3270. else if (e10g.r.e10g_lrm && e10g.r.e10g_lr)
  3271. *media = BFA_SFP_MEDIA_LW;
  3272. else if (e10g.r.e10g_unall)
  3273. *media = BFA_SFP_MEDIA_UNKNOWN;
  3274. else
  3275. bfa_trc(sfp, 0);
  3276. } else
  3277. bfa_trc(sfp, sfp->state);
  3278. }
  3279. static bfa_status_t
  3280. bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
  3281. {
  3282. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3283. struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
  3284. union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
  3285. union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
  3286. if (portspeed == BFA_PORT_SPEED_10GBPS) {
  3287. if (e10g.r.e10g_sr || e10g.r.e10g_lr)
  3288. return BFA_STATUS_OK;
  3289. else {
  3290. bfa_trc(sfp, e10g.b);
  3291. return BFA_STATUS_UNSUPP_SPEED;
  3292. }
  3293. }
  3294. if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
  3295. ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
  3296. ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
  3297. ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
  3298. ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
  3299. return BFA_STATUS_OK;
  3300. else {
  3301. bfa_trc(sfp, portspeed);
  3302. bfa_trc(sfp, fc3.b);
  3303. bfa_trc(sfp, e10g.b);
  3304. return BFA_STATUS_UNSUPP_SPEED;
  3305. }
  3306. }
  3307. /*
  3308. * SFP hmbox handler
  3309. */
  3310. void
  3311. bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
  3312. {
  3313. struct bfa_sfp_s *sfp = sfparg;
  3314. switch (msg->mh.msg_id) {
  3315. case BFI_SFP_I2H_SHOW:
  3316. bfa_sfp_show_comp(sfp, msg);
  3317. break;
  3318. case BFI_SFP_I2H_SCN:
  3319. bfa_sfp_scn(sfp, msg);
  3320. break;
  3321. default:
  3322. bfa_trc(sfp, msg->mh.msg_id);
  3323. WARN_ON(1);
  3324. }
  3325. }
  3326. /*
  3327. * Return DMA memory needed by sfp module.
  3328. */
  3329. u32
  3330. bfa_sfp_meminfo(void)
  3331. {
  3332. return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3333. }
  3334. /*
  3335. * Attach virtual and physical memory for SFP.
  3336. */
  3337. void
  3338. bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
  3339. struct bfa_trc_mod_s *trcmod)
  3340. {
  3341. sfp->dev = dev;
  3342. sfp->ioc = ioc;
  3343. sfp->trcmod = trcmod;
  3344. sfp->cbfn = NULL;
  3345. sfp->cbarg = NULL;
  3346. sfp->sfpmem = NULL;
  3347. sfp->lock = 0;
  3348. sfp->data_valid = 0;
  3349. sfp->state = BFA_SFP_STATE_INIT;
  3350. sfp->state_query_lock = 0;
  3351. sfp->state_query_cbfn = NULL;
  3352. sfp->state_query_cbarg = NULL;
  3353. sfp->media = NULL;
  3354. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3355. sfp->is_elb = BFA_FALSE;
  3356. bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
  3357. bfa_q_qe_init(&sfp->ioc_notify);
  3358. bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
  3359. list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
  3360. }
  3361. /*
  3362. * Claim Memory for SFP
  3363. */
  3364. void
  3365. bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
  3366. {
  3367. sfp->dbuf_kva = dm_kva;
  3368. sfp->dbuf_pa = dm_pa;
  3369. memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
  3370. dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3371. dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3372. }
  3373. /*
  3374. * Show SFP eeprom content
  3375. *
  3376. * @param[in] sfp - bfa sfp module
  3377. *
  3378. * @param[out] sfpmem - sfp eeprom data
  3379. *
  3380. */
  3381. bfa_status_t
  3382. bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
  3383. bfa_cb_sfp_t cbfn, void *cbarg)
  3384. {
  3385. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3386. bfa_trc(sfp, 0);
  3387. return BFA_STATUS_IOC_NON_OP;
  3388. }
  3389. if (sfp->lock) {
  3390. bfa_trc(sfp, 0);
  3391. return BFA_STATUS_DEVBUSY;
  3392. }
  3393. sfp->cbfn = cbfn;
  3394. sfp->cbarg = cbarg;
  3395. sfp->sfpmem = sfpmem;
  3396. bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
  3397. return BFA_STATUS_OK;
  3398. }
  3399. /*
  3400. * Return SFP Media type
  3401. *
  3402. * @param[in] sfp - bfa sfp module
  3403. *
  3404. * @param[out] media - port speed from user
  3405. *
  3406. */
  3407. bfa_status_t
  3408. bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
  3409. bfa_cb_sfp_t cbfn, void *cbarg)
  3410. {
  3411. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3412. bfa_trc(sfp, 0);
  3413. return BFA_STATUS_IOC_NON_OP;
  3414. }
  3415. sfp->media = media;
  3416. if (sfp->state == BFA_SFP_STATE_INIT) {
  3417. if (sfp->state_query_lock) {
  3418. bfa_trc(sfp, 0);
  3419. return BFA_STATUS_DEVBUSY;
  3420. } else {
  3421. sfp->state_query_cbfn = cbfn;
  3422. sfp->state_query_cbarg = cbarg;
  3423. bfa_sfp_state_query(sfp);
  3424. return BFA_STATUS_SFP_NOT_READY;
  3425. }
  3426. }
  3427. bfa_sfp_media_get(sfp);
  3428. return BFA_STATUS_OK;
  3429. }
  3430. /*
  3431. * Check if user set port speed is allowed by the SFP
  3432. *
  3433. * @param[in] sfp - bfa sfp module
  3434. * @param[in] portspeed - port speed from user
  3435. *
  3436. */
  3437. bfa_status_t
  3438. bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
  3439. bfa_cb_sfp_t cbfn, void *cbarg)
  3440. {
  3441. WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
  3442. if (!bfa_ioc_is_operational(sfp->ioc))
  3443. return BFA_STATUS_IOC_NON_OP;
  3444. /* For Mezz card, all speed is allowed */
  3445. if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
  3446. return BFA_STATUS_OK;
  3447. /* Check SFP state */
  3448. sfp->portspeed = portspeed;
  3449. if (sfp->state == BFA_SFP_STATE_INIT) {
  3450. if (sfp->state_query_lock) {
  3451. bfa_trc(sfp, 0);
  3452. return BFA_STATUS_DEVBUSY;
  3453. } else {
  3454. sfp->state_query_cbfn = cbfn;
  3455. sfp->state_query_cbarg = cbarg;
  3456. bfa_sfp_state_query(sfp);
  3457. return BFA_STATUS_SFP_NOT_READY;
  3458. }
  3459. }
  3460. if (sfp->state == BFA_SFP_STATE_REMOVED ||
  3461. sfp->state == BFA_SFP_STATE_FAILED) {
  3462. bfa_trc(sfp, sfp->state);
  3463. return BFA_STATUS_NO_SFP_DEV;
  3464. }
  3465. if (sfp->state == BFA_SFP_STATE_INSERTED) {
  3466. bfa_trc(sfp, sfp->state);
  3467. return BFA_STATUS_DEVBUSY; /* sfp is reading data */
  3468. }
  3469. /* For eloopback, all speed is allowed */
  3470. if (sfp->is_elb)
  3471. return BFA_STATUS_OK;
  3472. return bfa_sfp_speed_valid(sfp, portspeed);
  3473. }
  3474. /*
  3475. * Flash module specific
  3476. */
  3477. /*
  3478. * FLASH DMA buffer should be big enough to hold both MFG block and
  3479. * asic block(64k) at the same time and also should be 2k aligned to
  3480. * avoid write segement to cross sector boundary.
  3481. */
  3482. #define BFA_FLASH_SEG_SZ 2048
  3483. #define BFA_FLASH_DMA_BUF_SZ \
  3484. BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
  3485. static void
  3486. bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event,
  3487. int inst, int type)
  3488. {
  3489. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  3490. struct bfa_aen_entry_s *aen_entry;
  3491. bfad_get_aen_entry(bfad, aen_entry);
  3492. if (!aen_entry)
  3493. return;
  3494. aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn;
  3495. aen_entry->aen_data.audit.partition_inst = inst;
  3496. aen_entry->aen_data.audit.partition_type = type;
  3497. /* Send the AEN notification */
  3498. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  3499. BFA_AEN_CAT_AUDIT, event);
  3500. }
  3501. static void
  3502. bfa_flash_cb(struct bfa_flash_s *flash)
  3503. {
  3504. flash->op_busy = 0;
  3505. if (flash->cbfn)
  3506. flash->cbfn(flash->cbarg, flash->status);
  3507. }
  3508. static void
  3509. bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event)
  3510. {
  3511. struct bfa_flash_s *flash = cbarg;
  3512. bfa_trc(flash, event);
  3513. switch (event) {
  3514. case BFA_IOC_E_DISABLED:
  3515. case BFA_IOC_E_FAILED:
  3516. if (flash->op_busy) {
  3517. flash->status = BFA_STATUS_IOC_FAILURE;
  3518. flash->cbfn(flash->cbarg, flash->status);
  3519. flash->op_busy = 0;
  3520. }
  3521. break;
  3522. default:
  3523. break;
  3524. }
  3525. }
  3526. /*
  3527. * Send flash attribute query request.
  3528. *
  3529. * @param[in] cbarg - callback argument
  3530. */
  3531. static void
  3532. bfa_flash_query_send(void *cbarg)
  3533. {
  3534. struct bfa_flash_s *flash = cbarg;
  3535. struct bfi_flash_query_req_s *msg =
  3536. (struct bfi_flash_query_req_s *) flash->mb.msg;
  3537. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
  3538. bfa_ioc_portid(flash->ioc));
  3539. bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s),
  3540. flash->dbuf_pa);
  3541. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3542. }
  3543. /*
  3544. * Send flash write request.
  3545. *
  3546. * @param[in] cbarg - callback argument
  3547. */
  3548. static void
  3549. bfa_flash_write_send(struct bfa_flash_s *flash)
  3550. {
  3551. struct bfi_flash_write_req_s *msg =
  3552. (struct bfi_flash_write_req_s *) flash->mb.msg;
  3553. u32 len;
  3554. msg->type = be32_to_cpu(flash->type);
  3555. msg->instance = flash->instance;
  3556. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3557. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3558. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3559. msg->length = be32_to_cpu(len);
  3560. /* indicate if it's the last msg of the whole write operation */
  3561. msg->last = (len == flash->residue) ? 1 : 0;
  3562. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
  3563. bfa_ioc_portid(flash->ioc));
  3564. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3565. memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
  3566. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3567. flash->residue -= len;
  3568. flash->offset += len;
  3569. }
  3570. /*
  3571. * Send flash read request.
  3572. *
  3573. * @param[in] cbarg - callback argument
  3574. */
  3575. static void
  3576. bfa_flash_read_send(void *cbarg)
  3577. {
  3578. struct bfa_flash_s *flash = cbarg;
  3579. struct bfi_flash_read_req_s *msg =
  3580. (struct bfi_flash_read_req_s *) flash->mb.msg;
  3581. u32 len;
  3582. msg->type = be32_to_cpu(flash->type);
  3583. msg->instance = flash->instance;
  3584. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3585. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3586. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3587. msg->length = be32_to_cpu(len);
  3588. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
  3589. bfa_ioc_portid(flash->ioc));
  3590. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3591. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3592. }
  3593. /*
  3594. * Send flash erase request.
  3595. *
  3596. * @param[in] cbarg - callback argument
  3597. */
  3598. static void
  3599. bfa_flash_erase_send(void *cbarg)
  3600. {
  3601. struct bfa_flash_s *flash = cbarg;
  3602. struct bfi_flash_erase_req_s *msg =
  3603. (struct bfi_flash_erase_req_s *) flash->mb.msg;
  3604. msg->type = be32_to_cpu(flash->type);
  3605. msg->instance = flash->instance;
  3606. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ,
  3607. bfa_ioc_portid(flash->ioc));
  3608. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3609. }
  3610. /*
  3611. * Process flash response messages upon receiving interrupts.
  3612. *
  3613. * @param[in] flasharg - flash structure
  3614. * @param[in] msg - message structure
  3615. */
  3616. static void
  3617. bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg)
  3618. {
  3619. struct bfa_flash_s *flash = flasharg;
  3620. u32 status;
  3621. union {
  3622. struct bfi_flash_query_rsp_s *query;
  3623. struct bfi_flash_erase_rsp_s *erase;
  3624. struct bfi_flash_write_rsp_s *write;
  3625. struct bfi_flash_read_rsp_s *read;
  3626. struct bfi_flash_event_s *event;
  3627. struct bfi_mbmsg_s *msg;
  3628. } m;
  3629. m.msg = msg;
  3630. bfa_trc(flash, msg->mh.msg_id);
  3631. if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) {
  3632. /* receiving response after ioc failure */
  3633. bfa_trc(flash, 0x9999);
  3634. return;
  3635. }
  3636. switch (msg->mh.msg_id) {
  3637. case BFI_FLASH_I2H_QUERY_RSP:
  3638. status = be32_to_cpu(m.query->status);
  3639. bfa_trc(flash, status);
  3640. if (status == BFA_STATUS_OK) {
  3641. u32 i;
  3642. struct bfa_flash_attr_s *attr, *f;
  3643. attr = (struct bfa_flash_attr_s *) flash->ubuf;
  3644. f = (struct bfa_flash_attr_s *) flash->dbuf_kva;
  3645. attr->status = be32_to_cpu(f->status);
  3646. attr->npart = be32_to_cpu(f->npart);
  3647. bfa_trc(flash, attr->status);
  3648. bfa_trc(flash, attr->npart);
  3649. for (i = 0; i < attr->npart; i++) {
  3650. attr->part[i].part_type =
  3651. be32_to_cpu(f->part[i].part_type);
  3652. attr->part[i].part_instance =
  3653. be32_to_cpu(f->part[i].part_instance);
  3654. attr->part[i].part_off =
  3655. be32_to_cpu(f->part[i].part_off);
  3656. attr->part[i].part_size =
  3657. be32_to_cpu(f->part[i].part_size);
  3658. attr->part[i].part_len =
  3659. be32_to_cpu(f->part[i].part_len);
  3660. attr->part[i].part_status =
  3661. be32_to_cpu(f->part[i].part_status);
  3662. }
  3663. }
  3664. flash->status = status;
  3665. bfa_flash_cb(flash);
  3666. break;
  3667. case BFI_FLASH_I2H_ERASE_RSP:
  3668. status = be32_to_cpu(m.erase->status);
  3669. bfa_trc(flash, status);
  3670. flash->status = status;
  3671. bfa_flash_cb(flash);
  3672. break;
  3673. case BFI_FLASH_I2H_WRITE_RSP:
  3674. status = be32_to_cpu(m.write->status);
  3675. bfa_trc(flash, status);
  3676. if (status != BFA_STATUS_OK || flash->residue == 0) {
  3677. flash->status = status;
  3678. bfa_flash_cb(flash);
  3679. } else {
  3680. bfa_trc(flash, flash->offset);
  3681. bfa_flash_write_send(flash);
  3682. }
  3683. break;
  3684. case BFI_FLASH_I2H_READ_RSP:
  3685. status = be32_to_cpu(m.read->status);
  3686. bfa_trc(flash, status);
  3687. if (status != BFA_STATUS_OK) {
  3688. flash->status = status;
  3689. bfa_flash_cb(flash);
  3690. } else {
  3691. u32 len = be32_to_cpu(m.read->length);
  3692. bfa_trc(flash, flash->offset);
  3693. bfa_trc(flash, len);
  3694. memcpy(flash->ubuf + flash->offset,
  3695. flash->dbuf_kva, len);
  3696. flash->residue -= len;
  3697. flash->offset += len;
  3698. if (flash->residue == 0) {
  3699. flash->status = status;
  3700. bfa_flash_cb(flash);
  3701. } else
  3702. bfa_flash_read_send(flash);
  3703. }
  3704. break;
  3705. case BFI_FLASH_I2H_BOOT_VER_RSP:
  3706. break;
  3707. case BFI_FLASH_I2H_EVENT:
  3708. status = be32_to_cpu(m.event->status);
  3709. bfa_trc(flash, status);
  3710. if (status == BFA_STATUS_BAD_FWCFG)
  3711. bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR);
  3712. else if (status == BFA_STATUS_INVALID_VENDOR) {
  3713. u32 param;
  3714. param = be32_to_cpu(m.event->param);
  3715. bfa_trc(flash, param);
  3716. bfa_ioc_aen_post(flash->ioc,
  3717. BFA_IOC_AEN_INVALID_VENDOR);
  3718. }
  3719. break;
  3720. default:
  3721. WARN_ON(1);
  3722. }
  3723. }
  3724. /*
  3725. * Flash memory info API.
  3726. *
  3727. * @param[in] mincfg - minimal cfg variable
  3728. */
  3729. u32
  3730. bfa_flash_meminfo(bfa_boolean_t mincfg)
  3731. {
  3732. /* min driver doesn't need flash */
  3733. if (mincfg)
  3734. return 0;
  3735. return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3736. }
  3737. /*
  3738. * Flash attach API.
  3739. *
  3740. * @param[in] flash - flash structure
  3741. * @param[in] ioc - ioc structure
  3742. * @param[in] dev - device structure
  3743. * @param[in] trcmod - trace module
  3744. * @param[in] logmod - log module
  3745. */
  3746. void
  3747. bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev,
  3748. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  3749. {
  3750. flash->ioc = ioc;
  3751. flash->trcmod = trcmod;
  3752. flash->cbfn = NULL;
  3753. flash->cbarg = NULL;
  3754. flash->op_busy = 0;
  3755. bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
  3756. bfa_q_qe_init(&flash->ioc_notify);
  3757. bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
  3758. list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
  3759. /* min driver doesn't need flash */
  3760. if (mincfg) {
  3761. flash->dbuf_kva = NULL;
  3762. flash->dbuf_pa = 0;
  3763. }
  3764. }
  3765. /*
  3766. * Claim memory for flash
  3767. *
  3768. * @param[in] flash - flash structure
  3769. * @param[in] dm_kva - pointer to virtual memory address
  3770. * @param[in] dm_pa - physical memory address
  3771. * @param[in] mincfg - minimal cfg variable
  3772. */
  3773. void
  3774. bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa,
  3775. bfa_boolean_t mincfg)
  3776. {
  3777. if (mincfg)
  3778. return;
  3779. flash->dbuf_kva = dm_kva;
  3780. flash->dbuf_pa = dm_pa;
  3781. memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
  3782. dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3783. dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3784. }
  3785. /*
  3786. * Get flash attribute.
  3787. *
  3788. * @param[in] flash - flash structure
  3789. * @param[in] attr - flash attribute structure
  3790. * @param[in] cbfn - callback function
  3791. * @param[in] cbarg - callback argument
  3792. *
  3793. * Return status.
  3794. */
  3795. bfa_status_t
  3796. bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr,
  3797. bfa_cb_flash_t cbfn, void *cbarg)
  3798. {
  3799. bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ);
  3800. if (!bfa_ioc_is_operational(flash->ioc))
  3801. return BFA_STATUS_IOC_NON_OP;
  3802. if (flash->op_busy) {
  3803. bfa_trc(flash, flash->op_busy);
  3804. return BFA_STATUS_DEVBUSY;
  3805. }
  3806. flash->op_busy = 1;
  3807. flash->cbfn = cbfn;
  3808. flash->cbarg = cbarg;
  3809. flash->ubuf = (u8 *) attr;
  3810. bfa_flash_query_send(flash);
  3811. return BFA_STATUS_OK;
  3812. }
  3813. /*
  3814. * Erase flash partition.
  3815. *
  3816. * @param[in] flash - flash structure
  3817. * @param[in] type - flash partition type
  3818. * @param[in] instance - flash partition instance
  3819. * @param[in] cbfn - callback function
  3820. * @param[in] cbarg - callback argument
  3821. *
  3822. * Return status.
  3823. */
  3824. bfa_status_t
  3825. bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3826. u8 instance, bfa_cb_flash_t cbfn, void *cbarg)
  3827. {
  3828. bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ);
  3829. bfa_trc(flash, type);
  3830. bfa_trc(flash, instance);
  3831. if (!bfa_ioc_is_operational(flash->ioc))
  3832. return BFA_STATUS_IOC_NON_OP;
  3833. if (flash->op_busy) {
  3834. bfa_trc(flash, flash->op_busy);
  3835. return BFA_STATUS_DEVBUSY;
  3836. }
  3837. flash->op_busy = 1;
  3838. flash->cbfn = cbfn;
  3839. flash->cbarg = cbarg;
  3840. flash->type = type;
  3841. flash->instance = instance;
  3842. bfa_flash_erase_send(flash);
  3843. bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE,
  3844. instance, type);
  3845. return BFA_STATUS_OK;
  3846. }
  3847. /*
  3848. * Update flash partition.
  3849. *
  3850. * @param[in] flash - flash structure
  3851. * @param[in] type - flash partition type
  3852. * @param[in] instance - flash partition instance
  3853. * @param[in] buf - update data buffer
  3854. * @param[in] len - data buffer length
  3855. * @param[in] offset - offset relative to the partition starting address
  3856. * @param[in] cbfn - callback function
  3857. * @param[in] cbarg - callback argument
  3858. *
  3859. * Return status.
  3860. */
  3861. bfa_status_t
  3862. bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3863. u8 instance, void *buf, u32 len, u32 offset,
  3864. bfa_cb_flash_t cbfn, void *cbarg)
  3865. {
  3866. bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ);
  3867. bfa_trc(flash, type);
  3868. bfa_trc(flash, instance);
  3869. bfa_trc(flash, len);
  3870. bfa_trc(flash, offset);
  3871. if (!bfa_ioc_is_operational(flash->ioc))
  3872. return BFA_STATUS_IOC_NON_OP;
  3873. /*
  3874. * 'len' must be in word (4-byte) boundary
  3875. * 'offset' must be in sector (16kb) boundary
  3876. */
  3877. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3878. return BFA_STATUS_FLASH_BAD_LEN;
  3879. if (type == BFA_FLASH_PART_MFG)
  3880. return BFA_STATUS_EINVAL;
  3881. if (flash->op_busy) {
  3882. bfa_trc(flash, flash->op_busy);
  3883. return BFA_STATUS_DEVBUSY;
  3884. }
  3885. flash->op_busy = 1;
  3886. flash->cbfn = cbfn;
  3887. flash->cbarg = cbarg;
  3888. flash->type = type;
  3889. flash->instance = instance;
  3890. flash->residue = len;
  3891. flash->offset = 0;
  3892. flash->addr_off = offset;
  3893. flash->ubuf = buf;
  3894. bfa_flash_write_send(flash);
  3895. return BFA_STATUS_OK;
  3896. }
  3897. /*
  3898. * Read flash partition.
  3899. *
  3900. * @param[in] flash - flash structure
  3901. * @param[in] type - flash partition type
  3902. * @param[in] instance - flash partition instance
  3903. * @param[in] buf - read data buffer
  3904. * @param[in] len - data buffer length
  3905. * @param[in] offset - offset relative to the partition starting address
  3906. * @param[in] cbfn - callback function
  3907. * @param[in] cbarg - callback argument
  3908. *
  3909. * Return status.
  3910. */
  3911. bfa_status_t
  3912. bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3913. u8 instance, void *buf, u32 len, u32 offset,
  3914. bfa_cb_flash_t cbfn, void *cbarg)
  3915. {
  3916. bfa_trc(flash, BFI_FLASH_H2I_READ_REQ);
  3917. bfa_trc(flash, type);
  3918. bfa_trc(flash, instance);
  3919. bfa_trc(flash, len);
  3920. bfa_trc(flash, offset);
  3921. if (!bfa_ioc_is_operational(flash->ioc))
  3922. return BFA_STATUS_IOC_NON_OP;
  3923. /*
  3924. * 'len' must be in word (4-byte) boundary
  3925. * 'offset' must be in sector (16kb) boundary
  3926. */
  3927. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3928. return BFA_STATUS_FLASH_BAD_LEN;
  3929. if (flash->op_busy) {
  3930. bfa_trc(flash, flash->op_busy);
  3931. return BFA_STATUS_DEVBUSY;
  3932. }
  3933. flash->op_busy = 1;
  3934. flash->cbfn = cbfn;
  3935. flash->cbarg = cbarg;
  3936. flash->type = type;
  3937. flash->instance = instance;
  3938. flash->residue = len;
  3939. flash->offset = 0;
  3940. flash->addr_off = offset;
  3941. flash->ubuf = buf;
  3942. bfa_flash_read_send(flash);
  3943. return BFA_STATUS_OK;
  3944. }
  3945. /*
  3946. * DIAG module specific
  3947. */
  3948. #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
  3949. #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
  3950. /* IOC event handler */
  3951. static void
  3952. bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event)
  3953. {
  3954. struct bfa_diag_s *diag = diag_arg;
  3955. bfa_trc(diag, event);
  3956. bfa_trc(diag, diag->block);
  3957. bfa_trc(diag, diag->fwping.lock);
  3958. bfa_trc(diag, diag->tsensor.lock);
  3959. switch (event) {
  3960. case BFA_IOC_E_DISABLED:
  3961. case BFA_IOC_E_FAILED:
  3962. if (diag->fwping.lock) {
  3963. diag->fwping.status = BFA_STATUS_IOC_FAILURE;
  3964. diag->fwping.cbfn(diag->fwping.cbarg,
  3965. diag->fwping.status);
  3966. diag->fwping.lock = 0;
  3967. }
  3968. if (diag->tsensor.lock) {
  3969. diag->tsensor.status = BFA_STATUS_IOC_FAILURE;
  3970. diag->tsensor.cbfn(diag->tsensor.cbarg,
  3971. diag->tsensor.status);
  3972. diag->tsensor.lock = 0;
  3973. }
  3974. if (diag->block) {
  3975. if (diag->timer_active) {
  3976. bfa_timer_stop(&diag->timer);
  3977. diag->timer_active = 0;
  3978. }
  3979. diag->status = BFA_STATUS_IOC_FAILURE;
  3980. diag->cbfn(diag->cbarg, diag->status);
  3981. diag->block = 0;
  3982. }
  3983. break;
  3984. default:
  3985. break;
  3986. }
  3987. }
  3988. static void
  3989. bfa_diag_memtest_done(void *cbarg)
  3990. {
  3991. struct bfa_diag_s *diag = cbarg;
  3992. struct bfa_ioc_s *ioc = diag->ioc;
  3993. struct bfa_diag_memtest_result *res = diag->result;
  3994. u32 loff = BFI_BOOT_MEMTEST_RES_ADDR;
  3995. u32 pgnum, i;
  3996. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  3997. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  3998. for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) /
  3999. sizeof(u32)); i++) {
  4000. /* read test result from smem */
  4001. *((u32 *) res + i) =
  4002. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  4003. loff += sizeof(u32);
  4004. }
  4005. /* Reset IOC fwstates to BFI_IOC_UNINIT */
  4006. bfa_ioc_reset_fwstate(ioc);
  4007. res->status = swab32(res->status);
  4008. bfa_trc(diag, res->status);
  4009. if (res->status == BFI_BOOT_MEMTEST_RES_SIG)
  4010. diag->status = BFA_STATUS_OK;
  4011. else {
  4012. diag->status = BFA_STATUS_MEMTEST_FAILED;
  4013. res->addr = swab32(res->addr);
  4014. res->exp = swab32(res->exp);
  4015. res->act = swab32(res->act);
  4016. res->err_status = swab32(res->err_status);
  4017. res->err_status1 = swab32(res->err_status1);
  4018. res->err_addr = swab32(res->err_addr);
  4019. bfa_trc(diag, res->addr);
  4020. bfa_trc(diag, res->exp);
  4021. bfa_trc(diag, res->act);
  4022. bfa_trc(diag, res->err_status);
  4023. bfa_trc(diag, res->err_status1);
  4024. bfa_trc(diag, res->err_addr);
  4025. }
  4026. diag->timer_active = 0;
  4027. diag->cbfn(diag->cbarg, diag->status);
  4028. diag->block = 0;
  4029. }
  4030. /*
  4031. * Firmware ping
  4032. */
  4033. /*
  4034. * Perform DMA test directly
  4035. */
  4036. static void
  4037. diag_fwping_send(struct bfa_diag_s *diag)
  4038. {
  4039. struct bfi_diag_fwping_req_s *fwping_req;
  4040. u32 i;
  4041. bfa_trc(diag, diag->fwping.dbuf_pa);
  4042. /* fill DMA area with pattern */
  4043. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++)
  4044. *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data;
  4045. /* Fill mbox msg */
  4046. fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg;
  4047. /* Setup SG list */
  4048. bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ,
  4049. diag->fwping.dbuf_pa);
  4050. /* Set up dma count */
  4051. fwping_req->count = cpu_to_be32(diag->fwping.count);
  4052. /* Set up data pattern */
  4053. fwping_req->data = diag->fwping.data;
  4054. /* build host command */
  4055. bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING,
  4056. bfa_ioc_portid(diag->ioc));
  4057. /* send mbox cmd */
  4058. bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd);
  4059. }
  4060. static void
  4061. diag_fwping_comp(struct bfa_diag_s *diag,
  4062. struct bfi_diag_fwping_rsp_s *diag_rsp)
  4063. {
  4064. u32 rsp_data = diag_rsp->data;
  4065. u8 rsp_dma_status = diag_rsp->dma_status;
  4066. bfa_trc(diag, rsp_data);
  4067. bfa_trc(diag, rsp_dma_status);
  4068. if (rsp_dma_status == BFA_STATUS_OK) {
  4069. u32 i, pat;
  4070. pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) :
  4071. diag->fwping.data;
  4072. /* Check mbox data */
  4073. if (diag->fwping.data != rsp_data) {
  4074. bfa_trc(diag, rsp_data);
  4075. diag->fwping.result->dmastatus =
  4076. BFA_STATUS_DATACORRUPTED;
  4077. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  4078. diag->fwping.cbfn(diag->fwping.cbarg,
  4079. diag->fwping.status);
  4080. diag->fwping.lock = 0;
  4081. return;
  4082. }
  4083. /* Check dma pattern */
  4084. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) {
  4085. if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) {
  4086. bfa_trc(diag, i);
  4087. bfa_trc(diag, pat);
  4088. bfa_trc(diag,
  4089. *((u32 *)diag->fwping.dbuf_kva + i));
  4090. diag->fwping.result->dmastatus =
  4091. BFA_STATUS_DATACORRUPTED;
  4092. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  4093. diag->fwping.cbfn(diag->fwping.cbarg,
  4094. diag->fwping.status);
  4095. diag->fwping.lock = 0;
  4096. return;
  4097. }
  4098. }
  4099. diag->fwping.result->dmastatus = BFA_STATUS_OK;
  4100. diag->fwping.status = BFA_STATUS_OK;
  4101. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  4102. diag->fwping.lock = 0;
  4103. } else {
  4104. diag->fwping.status = BFA_STATUS_HDMA_FAILED;
  4105. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  4106. diag->fwping.lock = 0;
  4107. }
  4108. }
  4109. /*
  4110. * Temperature Sensor
  4111. */
  4112. static void
  4113. diag_tempsensor_send(struct bfa_diag_s *diag)
  4114. {
  4115. struct bfi_diag_ts_req_s *msg;
  4116. msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg;
  4117. bfa_trc(diag, msg->temp);
  4118. /* build host command */
  4119. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR,
  4120. bfa_ioc_portid(diag->ioc));
  4121. /* send mbox cmd */
  4122. bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd);
  4123. }
  4124. static void
  4125. diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp)
  4126. {
  4127. if (!diag->tsensor.lock) {
  4128. /* receiving response after ioc failure */
  4129. bfa_trc(diag, diag->tsensor.lock);
  4130. return;
  4131. }
  4132. /*
  4133. * ASIC junction tempsensor is a reg read operation
  4134. * it will always return OK
  4135. */
  4136. diag->tsensor.temp->temp = be16_to_cpu(rsp->temp);
  4137. diag->tsensor.temp->ts_junc = rsp->ts_junc;
  4138. diag->tsensor.temp->ts_brd = rsp->ts_brd;
  4139. if (rsp->ts_brd) {
  4140. /* tsensor.temp->status is brd_temp status */
  4141. diag->tsensor.temp->status = rsp->status;
  4142. if (rsp->status == BFA_STATUS_OK) {
  4143. diag->tsensor.temp->brd_temp =
  4144. be16_to_cpu(rsp->brd_temp);
  4145. } else
  4146. diag->tsensor.temp->brd_temp = 0;
  4147. }
  4148. bfa_trc(diag, rsp->status);
  4149. bfa_trc(diag, rsp->ts_junc);
  4150. bfa_trc(diag, rsp->temp);
  4151. bfa_trc(diag, rsp->ts_brd);
  4152. bfa_trc(diag, rsp->brd_temp);
  4153. /* tsensor status is always good bcos we always have junction temp */
  4154. diag->tsensor.status = BFA_STATUS_OK;
  4155. diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status);
  4156. diag->tsensor.lock = 0;
  4157. }
  4158. /*
  4159. * LED Test command
  4160. */
  4161. static void
  4162. diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  4163. {
  4164. struct bfi_diag_ledtest_req_s *msg;
  4165. msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg;
  4166. /* build host command */
  4167. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST,
  4168. bfa_ioc_portid(diag->ioc));
  4169. /*
  4170. * convert the freq from N blinks per 10 sec to
  4171. * crossbow ontime value. We do it here because division is need
  4172. */
  4173. if (ledtest->freq)
  4174. ledtest->freq = 500 / ledtest->freq;
  4175. if (ledtest->freq == 0)
  4176. ledtest->freq = 1;
  4177. bfa_trc(diag, ledtest->freq);
  4178. /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
  4179. msg->cmd = (u8) ledtest->cmd;
  4180. msg->color = (u8) ledtest->color;
  4181. msg->portid = bfa_ioc_portid(diag->ioc);
  4182. msg->led = ledtest->led;
  4183. msg->freq = cpu_to_be16(ledtest->freq);
  4184. /* send mbox cmd */
  4185. bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd);
  4186. }
  4187. static void
  4188. diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
  4189. {
  4190. bfa_trc(diag, diag->ledtest.lock);
  4191. diag->ledtest.lock = BFA_FALSE;
  4192. /* no bfa_cb_queue is needed because driver is not waiting */
  4193. }
  4194. /*
  4195. * Port beaconing
  4196. */
  4197. static void
  4198. diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec)
  4199. {
  4200. struct bfi_diag_portbeacon_req_s *msg;
  4201. msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg;
  4202. /* build host command */
  4203. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON,
  4204. bfa_ioc_portid(diag->ioc));
  4205. msg->beacon = beacon;
  4206. msg->period = cpu_to_be32(sec);
  4207. /* send mbox cmd */
  4208. bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd);
  4209. }
  4210. static void
  4211. diag_portbeacon_comp(struct bfa_diag_s *diag)
  4212. {
  4213. bfa_trc(diag, diag->beacon.state);
  4214. diag->beacon.state = BFA_FALSE;
  4215. if (diag->cbfn_beacon)
  4216. diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e);
  4217. }
  4218. /*
  4219. * Diag hmbox handler
  4220. */
  4221. static void
  4222. bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg)
  4223. {
  4224. struct bfa_diag_s *diag = diagarg;
  4225. switch (msg->mh.msg_id) {
  4226. case BFI_DIAG_I2H_PORTBEACON:
  4227. diag_portbeacon_comp(diag);
  4228. break;
  4229. case BFI_DIAG_I2H_FWPING:
  4230. diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg);
  4231. break;
  4232. case BFI_DIAG_I2H_TEMPSENSOR:
  4233. diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg);
  4234. break;
  4235. case BFI_DIAG_I2H_LEDTEST:
  4236. diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg);
  4237. break;
  4238. default:
  4239. bfa_trc(diag, msg->mh.msg_id);
  4240. WARN_ON(1);
  4241. }
  4242. }
  4243. /*
  4244. * Gen RAM Test
  4245. *
  4246. * @param[in] *diag - diag data struct
  4247. * @param[in] *memtest - mem test params input from upper layer,
  4248. * @param[in] pattern - mem test pattern
  4249. * @param[in] *result - mem test result
  4250. * @param[in] cbfn - mem test callback functioin
  4251. * @param[in] cbarg - callback functioin arg
  4252. *
  4253. * @param[out]
  4254. */
  4255. bfa_status_t
  4256. bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest,
  4257. u32 pattern, struct bfa_diag_memtest_result *result,
  4258. bfa_cb_diag_t cbfn, void *cbarg)
  4259. {
  4260. u32 memtest_tov;
  4261. bfa_trc(diag, pattern);
  4262. if (!bfa_ioc_adapter_is_disabled(diag->ioc))
  4263. return BFA_STATUS_ADAPTER_ENABLED;
  4264. /* check to see if there is another destructive diag cmd running */
  4265. if (diag->block) {
  4266. bfa_trc(diag, diag->block);
  4267. return BFA_STATUS_DEVBUSY;
  4268. } else
  4269. diag->block = 1;
  4270. diag->result = result;
  4271. diag->cbfn = cbfn;
  4272. diag->cbarg = cbarg;
  4273. /* download memtest code and take LPU0 out of reset */
  4274. bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
  4275. memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
  4276. CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
  4277. bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
  4278. bfa_diag_memtest_done, diag, memtest_tov);
  4279. diag->timer_active = 1;
  4280. return BFA_STATUS_OK;
  4281. }
  4282. /*
  4283. * DIAG firmware ping command
  4284. *
  4285. * @param[in] *diag - diag data struct
  4286. * @param[in] cnt - dma loop count for testing PCIE
  4287. * @param[in] data - data pattern to pass in fw
  4288. * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
  4289. * @param[in] cbfn - callback function
  4290. * @param[in] *cbarg - callback functioin arg
  4291. *
  4292. * @param[out]
  4293. */
  4294. bfa_status_t
  4295. bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data,
  4296. struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn,
  4297. void *cbarg)
  4298. {
  4299. bfa_trc(diag, cnt);
  4300. bfa_trc(diag, data);
  4301. if (!bfa_ioc_is_operational(diag->ioc))
  4302. return BFA_STATUS_IOC_NON_OP;
  4303. if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) &&
  4304. ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH))
  4305. return BFA_STATUS_CMD_NOTSUPP;
  4306. /* check to see if there is another destructive diag cmd running */
  4307. if (diag->block || diag->fwping.lock) {
  4308. bfa_trc(diag, diag->block);
  4309. bfa_trc(diag, diag->fwping.lock);
  4310. return BFA_STATUS_DEVBUSY;
  4311. }
  4312. /* Initialization */
  4313. diag->fwping.lock = 1;
  4314. diag->fwping.cbfn = cbfn;
  4315. diag->fwping.cbarg = cbarg;
  4316. diag->fwping.result = result;
  4317. diag->fwping.data = data;
  4318. diag->fwping.count = cnt;
  4319. /* Init test results */
  4320. diag->fwping.result->data = 0;
  4321. diag->fwping.result->status = BFA_STATUS_OK;
  4322. /* kick off the first ping */
  4323. diag_fwping_send(diag);
  4324. return BFA_STATUS_OK;
  4325. }
  4326. /*
  4327. * Read Temperature Sensor
  4328. *
  4329. * @param[in] *diag - diag data struct
  4330. * @param[in] *result - pt to bfa_diag_temp_t data struct
  4331. * @param[in] cbfn - callback function
  4332. * @param[in] *cbarg - callback functioin arg
  4333. *
  4334. * @param[out]
  4335. */
  4336. bfa_status_t
  4337. bfa_diag_tsensor_query(struct bfa_diag_s *diag,
  4338. struct bfa_diag_results_tempsensor_s *result,
  4339. bfa_cb_diag_t cbfn, void *cbarg)
  4340. {
  4341. /* check to see if there is a destructive diag cmd running */
  4342. if (diag->block || diag->tsensor.lock) {
  4343. bfa_trc(diag, diag->block);
  4344. bfa_trc(diag, diag->tsensor.lock);
  4345. return BFA_STATUS_DEVBUSY;
  4346. }
  4347. if (!bfa_ioc_is_operational(diag->ioc))
  4348. return BFA_STATUS_IOC_NON_OP;
  4349. /* Init diag mod params */
  4350. diag->tsensor.lock = 1;
  4351. diag->tsensor.temp = result;
  4352. diag->tsensor.cbfn = cbfn;
  4353. diag->tsensor.cbarg = cbarg;
  4354. diag->tsensor.status = BFA_STATUS_OK;
  4355. /* Send msg to fw */
  4356. diag_tempsensor_send(diag);
  4357. return BFA_STATUS_OK;
  4358. }
  4359. /*
  4360. * LED Test command
  4361. *
  4362. * @param[in] *diag - diag data struct
  4363. * @param[in] *ledtest - pt to ledtest data structure
  4364. *
  4365. * @param[out]
  4366. */
  4367. bfa_status_t
  4368. bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  4369. {
  4370. bfa_trc(diag, ledtest->cmd);
  4371. if (!bfa_ioc_is_operational(diag->ioc))
  4372. return BFA_STATUS_IOC_NON_OP;
  4373. if (diag->beacon.state)
  4374. return BFA_STATUS_BEACON_ON;
  4375. if (diag->ledtest.lock)
  4376. return BFA_STATUS_LEDTEST_OP;
  4377. /* Send msg to fw */
  4378. diag->ledtest.lock = BFA_TRUE;
  4379. diag_ledtest_send(diag, ledtest);
  4380. return BFA_STATUS_OK;
  4381. }
  4382. /*
  4383. * Port beaconing command
  4384. *
  4385. * @param[in] *diag - diag data struct
  4386. * @param[in] beacon - port beaconing 1:ON 0:OFF
  4387. * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
  4388. * @param[in] sec - beaconing duration in seconds
  4389. *
  4390. * @param[out]
  4391. */
  4392. bfa_status_t
  4393. bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon,
  4394. bfa_boolean_t link_e2e_beacon, uint32_t sec)
  4395. {
  4396. bfa_trc(diag, beacon);
  4397. bfa_trc(diag, link_e2e_beacon);
  4398. bfa_trc(diag, sec);
  4399. if (!bfa_ioc_is_operational(diag->ioc))
  4400. return BFA_STATUS_IOC_NON_OP;
  4401. if (diag->ledtest.lock)
  4402. return BFA_STATUS_LEDTEST_OP;
  4403. if (diag->beacon.state && beacon) /* beacon alread on */
  4404. return BFA_STATUS_BEACON_ON;
  4405. diag->beacon.state = beacon;
  4406. diag->beacon.link_e2e = link_e2e_beacon;
  4407. if (diag->cbfn_beacon)
  4408. diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon);
  4409. /* Send msg to fw */
  4410. diag_portbeacon_send(diag, beacon, sec);
  4411. return BFA_STATUS_OK;
  4412. }
  4413. /*
  4414. * Return DMA memory needed by diag module.
  4415. */
  4416. u32
  4417. bfa_diag_meminfo(void)
  4418. {
  4419. return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4420. }
  4421. /*
  4422. * Attach virtual and physical memory for Diag.
  4423. */
  4424. void
  4425. bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
  4426. bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod)
  4427. {
  4428. diag->dev = dev;
  4429. diag->ioc = ioc;
  4430. diag->trcmod = trcmod;
  4431. diag->block = 0;
  4432. diag->cbfn = NULL;
  4433. diag->cbarg = NULL;
  4434. diag->result = NULL;
  4435. diag->cbfn_beacon = cbfn_beacon;
  4436. bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag);
  4437. bfa_q_qe_init(&diag->ioc_notify);
  4438. bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag);
  4439. list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q);
  4440. }
  4441. void
  4442. bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa)
  4443. {
  4444. diag->fwping.dbuf_kva = dm_kva;
  4445. diag->fwping.dbuf_pa = dm_pa;
  4446. memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ);
  4447. }
  4448. /*
  4449. * PHY module specific
  4450. */
  4451. #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
  4452. #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
  4453. static void
  4454. bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz)
  4455. {
  4456. int i, m = sz >> 2;
  4457. for (i = 0; i < m; i++)
  4458. obuf[i] = be32_to_cpu(ibuf[i]);
  4459. }
  4460. static bfa_boolean_t
  4461. bfa_phy_present(struct bfa_phy_s *phy)
  4462. {
  4463. return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING);
  4464. }
  4465. static void
  4466. bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event)
  4467. {
  4468. struct bfa_phy_s *phy = cbarg;
  4469. bfa_trc(phy, event);
  4470. switch (event) {
  4471. case BFA_IOC_E_DISABLED:
  4472. case BFA_IOC_E_FAILED:
  4473. if (phy->op_busy) {
  4474. phy->status = BFA_STATUS_IOC_FAILURE;
  4475. phy->cbfn(phy->cbarg, phy->status);
  4476. phy->op_busy = 0;
  4477. }
  4478. break;
  4479. default:
  4480. break;
  4481. }
  4482. }
  4483. /*
  4484. * Send phy attribute query request.
  4485. *
  4486. * @param[in] cbarg - callback argument
  4487. */
  4488. static void
  4489. bfa_phy_query_send(void *cbarg)
  4490. {
  4491. struct bfa_phy_s *phy = cbarg;
  4492. struct bfi_phy_query_req_s *msg =
  4493. (struct bfi_phy_query_req_s *) phy->mb.msg;
  4494. msg->instance = phy->instance;
  4495. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ,
  4496. bfa_ioc_portid(phy->ioc));
  4497. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa);
  4498. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4499. }
  4500. /*
  4501. * Send phy write request.
  4502. *
  4503. * @param[in] cbarg - callback argument
  4504. */
  4505. static void
  4506. bfa_phy_write_send(void *cbarg)
  4507. {
  4508. struct bfa_phy_s *phy = cbarg;
  4509. struct bfi_phy_write_req_s *msg =
  4510. (struct bfi_phy_write_req_s *) phy->mb.msg;
  4511. u32 len;
  4512. u16 *buf, *dbuf;
  4513. int i, sz;
  4514. msg->instance = phy->instance;
  4515. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4516. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4517. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4518. msg->length = cpu_to_be32(len);
  4519. /* indicate if it's the last msg of the whole write operation */
  4520. msg->last = (len == phy->residue) ? 1 : 0;
  4521. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ,
  4522. bfa_ioc_portid(phy->ioc));
  4523. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4524. buf = (u16 *) (phy->ubuf + phy->offset);
  4525. dbuf = (u16 *)phy->dbuf_kva;
  4526. sz = len >> 1;
  4527. for (i = 0; i < sz; i++)
  4528. buf[i] = cpu_to_be16(dbuf[i]);
  4529. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4530. phy->residue -= len;
  4531. phy->offset += len;
  4532. }
  4533. /*
  4534. * Send phy read request.
  4535. *
  4536. * @param[in] cbarg - callback argument
  4537. */
  4538. static void
  4539. bfa_phy_read_send(void *cbarg)
  4540. {
  4541. struct bfa_phy_s *phy = cbarg;
  4542. struct bfi_phy_read_req_s *msg =
  4543. (struct bfi_phy_read_req_s *) phy->mb.msg;
  4544. u32 len;
  4545. msg->instance = phy->instance;
  4546. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4547. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4548. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4549. msg->length = cpu_to_be32(len);
  4550. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ,
  4551. bfa_ioc_portid(phy->ioc));
  4552. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4553. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4554. }
  4555. /*
  4556. * Send phy stats request.
  4557. *
  4558. * @param[in] cbarg - callback argument
  4559. */
  4560. static void
  4561. bfa_phy_stats_send(void *cbarg)
  4562. {
  4563. struct bfa_phy_s *phy = cbarg;
  4564. struct bfi_phy_stats_req_s *msg =
  4565. (struct bfi_phy_stats_req_s *) phy->mb.msg;
  4566. msg->instance = phy->instance;
  4567. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ,
  4568. bfa_ioc_portid(phy->ioc));
  4569. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa);
  4570. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4571. }
  4572. /*
  4573. * Flash memory info API.
  4574. *
  4575. * @param[in] mincfg - minimal cfg variable
  4576. */
  4577. u32
  4578. bfa_phy_meminfo(bfa_boolean_t mincfg)
  4579. {
  4580. /* min driver doesn't need phy */
  4581. if (mincfg)
  4582. return 0;
  4583. return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4584. }
  4585. /*
  4586. * Flash attach API.
  4587. *
  4588. * @param[in] phy - phy structure
  4589. * @param[in] ioc - ioc structure
  4590. * @param[in] dev - device structure
  4591. * @param[in] trcmod - trace module
  4592. * @param[in] logmod - log module
  4593. */
  4594. void
  4595. bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev,
  4596. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  4597. {
  4598. phy->ioc = ioc;
  4599. phy->trcmod = trcmod;
  4600. phy->cbfn = NULL;
  4601. phy->cbarg = NULL;
  4602. phy->op_busy = 0;
  4603. bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy);
  4604. bfa_q_qe_init(&phy->ioc_notify);
  4605. bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy);
  4606. list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q);
  4607. /* min driver doesn't need phy */
  4608. if (mincfg) {
  4609. phy->dbuf_kva = NULL;
  4610. phy->dbuf_pa = 0;
  4611. }
  4612. }
  4613. /*
  4614. * Claim memory for phy
  4615. *
  4616. * @param[in] phy - phy structure
  4617. * @param[in] dm_kva - pointer to virtual memory address
  4618. * @param[in] dm_pa - physical memory address
  4619. * @param[in] mincfg - minimal cfg variable
  4620. */
  4621. void
  4622. bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa,
  4623. bfa_boolean_t mincfg)
  4624. {
  4625. if (mincfg)
  4626. return;
  4627. phy->dbuf_kva = dm_kva;
  4628. phy->dbuf_pa = dm_pa;
  4629. memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ);
  4630. dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4631. dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4632. }
  4633. bfa_boolean_t
  4634. bfa_phy_busy(struct bfa_ioc_s *ioc)
  4635. {
  4636. void __iomem *rb;
  4637. rb = bfa_ioc_bar0(ioc);
  4638. return readl(rb + BFA_PHY_LOCK_STATUS);
  4639. }
  4640. /*
  4641. * Get phy attribute.
  4642. *
  4643. * @param[in] phy - phy structure
  4644. * @param[in] attr - phy attribute structure
  4645. * @param[in] cbfn - callback function
  4646. * @param[in] cbarg - callback argument
  4647. *
  4648. * Return status.
  4649. */
  4650. bfa_status_t
  4651. bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance,
  4652. struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg)
  4653. {
  4654. bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ);
  4655. bfa_trc(phy, instance);
  4656. if (!bfa_phy_present(phy))
  4657. return BFA_STATUS_PHY_NOT_PRESENT;
  4658. if (!bfa_ioc_is_operational(phy->ioc))
  4659. return BFA_STATUS_IOC_NON_OP;
  4660. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4661. bfa_trc(phy, phy->op_busy);
  4662. return BFA_STATUS_DEVBUSY;
  4663. }
  4664. phy->op_busy = 1;
  4665. phy->cbfn = cbfn;
  4666. phy->cbarg = cbarg;
  4667. phy->instance = instance;
  4668. phy->ubuf = (uint8_t *) attr;
  4669. bfa_phy_query_send(phy);
  4670. return BFA_STATUS_OK;
  4671. }
  4672. /*
  4673. * Get phy stats.
  4674. *
  4675. * @param[in] phy - phy structure
  4676. * @param[in] instance - phy image instance
  4677. * @param[in] stats - pointer to phy stats
  4678. * @param[in] cbfn - callback function
  4679. * @param[in] cbarg - callback argument
  4680. *
  4681. * Return status.
  4682. */
  4683. bfa_status_t
  4684. bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance,
  4685. struct bfa_phy_stats_s *stats,
  4686. bfa_cb_phy_t cbfn, void *cbarg)
  4687. {
  4688. bfa_trc(phy, BFI_PHY_H2I_STATS_REQ);
  4689. bfa_trc(phy, instance);
  4690. if (!bfa_phy_present(phy))
  4691. return BFA_STATUS_PHY_NOT_PRESENT;
  4692. if (!bfa_ioc_is_operational(phy->ioc))
  4693. return BFA_STATUS_IOC_NON_OP;
  4694. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4695. bfa_trc(phy, phy->op_busy);
  4696. return BFA_STATUS_DEVBUSY;
  4697. }
  4698. phy->op_busy = 1;
  4699. phy->cbfn = cbfn;
  4700. phy->cbarg = cbarg;
  4701. phy->instance = instance;
  4702. phy->ubuf = (u8 *) stats;
  4703. bfa_phy_stats_send(phy);
  4704. return BFA_STATUS_OK;
  4705. }
  4706. /*
  4707. * Update phy image.
  4708. *
  4709. * @param[in] phy - phy structure
  4710. * @param[in] instance - phy image instance
  4711. * @param[in] buf - update data buffer
  4712. * @param[in] len - data buffer length
  4713. * @param[in] offset - offset relative to starting address
  4714. * @param[in] cbfn - callback function
  4715. * @param[in] cbarg - callback argument
  4716. *
  4717. * Return status.
  4718. */
  4719. bfa_status_t
  4720. bfa_phy_update(struct bfa_phy_s *phy, u8 instance,
  4721. void *buf, u32 len, u32 offset,
  4722. bfa_cb_phy_t cbfn, void *cbarg)
  4723. {
  4724. bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ);
  4725. bfa_trc(phy, instance);
  4726. bfa_trc(phy, len);
  4727. bfa_trc(phy, offset);
  4728. if (!bfa_phy_present(phy))
  4729. return BFA_STATUS_PHY_NOT_PRESENT;
  4730. if (!bfa_ioc_is_operational(phy->ioc))
  4731. return BFA_STATUS_IOC_NON_OP;
  4732. /* 'len' must be in word (4-byte) boundary */
  4733. if (!len || (len & 0x03))
  4734. return BFA_STATUS_FAILED;
  4735. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4736. bfa_trc(phy, phy->op_busy);
  4737. return BFA_STATUS_DEVBUSY;
  4738. }
  4739. phy->op_busy = 1;
  4740. phy->cbfn = cbfn;
  4741. phy->cbarg = cbarg;
  4742. phy->instance = instance;
  4743. phy->residue = len;
  4744. phy->offset = 0;
  4745. phy->addr_off = offset;
  4746. phy->ubuf = buf;
  4747. bfa_phy_write_send(phy);
  4748. return BFA_STATUS_OK;
  4749. }
  4750. /*
  4751. * Read phy image.
  4752. *
  4753. * @param[in] phy - phy structure
  4754. * @param[in] instance - phy image instance
  4755. * @param[in] buf - read data buffer
  4756. * @param[in] len - data buffer length
  4757. * @param[in] offset - offset relative to starting address
  4758. * @param[in] cbfn - callback function
  4759. * @param[in] cbarg - callback argument
  4760. *
  4761. * Return status.
  4762. */
  4763. bfa_status_t
  4764. bfa_phy_read(struct bfa_phy_s *phy, u8 instance,
  4765. void *buf, u32 len, u32 offset,
  4766. bfa_cb_phy_t cbfn, void *cbarg)
  4767. {
  4768. bfa_trc(phy, BFI_PHY_H2I_READ_REQ);
  4769. bfa_trc(phy, instance);
  4770. bfa_trc(phy, len);
  4771. bfa_trc(phy, offset);
  4772. if (!bfa_phy_present(phy))
  4773. return BFA_STATUS_PHY_NOT_PRESENT;
  4774. if (!bfa_ioc_is_operational(phy->ioc))
  4775. return BFA_STATUS_IOC_NON_OP;
  4776. /* 'len' must be in word (4-byte) boundary */
  4777. if (!len || (len & 0x03))
  4778. return BFA_STATUS_FAILED;
  4779. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4780. bfa_trc(phy, phy->op_busy);
  4781. return BFA_STATUS_DEVBUSY;
  4782. }
  4783. phy->op_busy = 1;
  4784. phy->cbfn = cbfn;
  4785. phy->cbarg = cbarg;
  4786. phy->instance = instance;
  4787. phy->residue = len;
  4788. phy->offset = 0;
  4789. phy->addr_off = offset;
  4790. phy->ubuf = buf;
  4791. bfa_phy_read_send(phy);
  4792. return BFA_STATUS_OK;
  4793. }
  4794. /*
  4795. * Process phy response messages upon receiving interrupts.
  4796. *
  4797. * @param[in] phyarg - phy structure
  4798. * @param[in] msg - message structure
  4799. */
  4800. void
  4801. bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg)
  4802. {
  4803. struct bfa_phy_s *phy = phyarg;
  4804. u32 status;
  4805. union {
  4806. struct bfi_phy_query_rsp_s *query;
  4807. struct bfi_phy_stats_rsp_s *stats;
  4808. struct bfi_phy_write_rsp_s *write;
  4809. struct bfi_phy_read_rsp_s *read;
  4810. struct bfi_mbmsg_s *msg;
  4811. } m;
  4812. m.msg = msg;
  4813. bfa_trc(phy, msg->mh.msg_id);
  4814. if (!phy->op_busy) {
  4815. /* receiving response after ioc failure */
  4816. bfa_trc(phy, 0x9999);
  4817. return;
  4818. }
  4819. switch (msg->mh.msg_id) {
  4820. case BFI_PHY_I2H_QUERY_RSP:
  4821. status = be32_to_cpu(m.query->status);
  4822. bfa_trc(phy, status);
  4823. if (status == BFA_STATUS_OK) {
  4824. struct bfa_phy_attr_s *attr =
  4825. (struct bfa_phy_attr_s *) phy->ubuf;
  4826. bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva,
  4827. sizeof(struct bfa_phy_attr_s));
  4828. bfa_trc(phy, attr->status);
  4829. bfa_trc(phy, attr->length);
  4830. }
  4831. phy->status = status;
  4832. phy->op_busy = 0;
  4833. if (phy->cbfn)
  4834. phy->cbfn(phy->cbarg, phy->status);
  4835. break;
  4836. case BFI_PHY_I2H_STATS_RSP:
  4837. status = be32_to_cpu(m.stats->status);
  4838. bfa_trc(phy, status);
  4839. if (status == BFA_STATUS_OK) {
  4840. struct bfa_phy_stats_s *stats =
  4841. (struct bfa_phy_stats_s *) phy->ubuf;
  4842. bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva,
  4843. sizeof(struct bfa_phy_stats_s));
  4844. bfa_trc(phy, stats->status);
  4845. }
  4846. phy->status = status;
  4847. phy->op_busy = 0;
  4848. if (phy->cbfn)
  4849. phy->cbfn(phy->cbarg, phy->status);
  4850. break;
  4851. case BFI_PHY_I2H_WRITE_RSP:
  4852. status = be32_to_cpu(m.write->status);
  4853. bfa_trc(phy, status);
  4854. if (status != BFA_STATUS_OK || phy->residue == 0) {
  4855. phy->status = status;
  4856. phy->op_busy = 0;
  4857. if (phy->cbfn)
  4858. phy->cbfn(phy->cbarg, phy->status);
  4859. } else {
  4860. bfa_trc(phy, phy->offset);
  4861. bfa_phy_write_send(phy);
  4862. }
  4863. break;
  4864. case BFI_PHY_I2H_READ_RSP:
  4865. status = be32_to_cpu(m.read->status);
  4866. bfa_trc(phy, status);
  4867. if (status != BFA_STATUS_OK) {
  4868. phy->status = status;
  4869. phy->op_busy = 0;
  4870. if (phy->cbfn)
  4871. phy->cbfn(phy->cbarg, phy->status);
  4872. } else {
  4873. u32 len = be32_to_cpu(m.read->length);
  4874. u16 *buf = (u16 *)(phy->ubuf + phy->offset);
  4875. u16 *dbuf = (u16 *)phy->dbuf_kva;
  4876. int i, sz = len >> 1;
  4877. bfa_trc(phy, phy->offset);
  4878. bfa_trc(phy, len);
  4879. for (i = 0; i < sz; i++)
  4880. buf[i] = be16_to_cpu(dbuf[i]);
  4881. phy->residue -= len;
  4882. phy->offset += len;
  4883. if (phy->residue == 0) {
  4884. phy->status = status;
  4885. phy->op_busy = 0;
  4886. if (phy->cbfn)
  4887. phy->cbfn(phy->cbarg, phy->status);
  4888. } else
  4889. bfa_phy_read_send(phy);
  4890. }
  4891. break;
  4892. default:
  4893. WARN_ON(1);
  4894. }
  4895. }
  4896. /* forward declaration of DCONF state machine */
  4897. static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf,
  4898. enum bfa_dconf_event event);
  4899. static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4900. enum bfa_dconf_event event);
  4901. static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf,
  4902. enum bfa_dconf_event event);
  4903. static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf,
  4904. enum bfa_dconf_event event);
  4905. static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf,
  4906. enum bfa_dconf_event event);
  4907. static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  4908. enum bfa_dconf_event event);
  4909. static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  4910. enum bfa_dconf_event event);
  4911. static void bfa_dconf_cbfn(void *dconf, bfa_status_t status);
  4912. static void bfa_dconf_timer(void *cbarg);
  4913. static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
  4914. static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
  4915. /*
  4916. * Beginning state of dconf module. Waiting for an event to start.
  4917. */
  4918. static void
  4919. bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4920. {
  4921. bfa_status_t bfa_status;
  4922. bfa_trc(dconf->bfa, event);
  4923. switch (event) {
  4924. case BFA_DCONF_SM_INIT:
  4925. if (dconf->min_cfg) {
  4926. bfa_trc(dconf->bfa, dconf->min_cfg);
  4927. bfa_fsm_send_event(&dconf->bfa->iocfc,
  4928. IOCFC_E_DCONF_DONE);
  4929. return;
  4930. }
  4931. bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
  4932. bfa_timer_start(dconf->bfa, &dconf->timer,
  4933. bfa_dconf_timer, dconf, 2 * BFA_DCONF_UPDATE_TOV);
  4934. bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
  4935. BFA_FLASH_PART_DRV, dconf->instance,
  4936. dconf->dconf,
  4937. sizeof(struct bfa_dconf_s), 0,
  4938. bfa_dconf_init_cb, dconf->bfa);
  4939. if (bfa_status != BFA_STATUS_OK) {
  4940. bfa_timer_stop(&dconf->timer);
  4941. bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
  4942. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4943. return;
  4944. }
  4945. break;
  4946. case BFA_DCONF_SM_EXIT:
  4947. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4948. break;
  4949. case BFA_DCONF_SM_IOCDISABLE:
  4950. case BFA_DCONF_SM_WR:
  4951. case BFA_DCONF_SM_FLASH_COMP:
  4952. break;
  4953. default:
  4954. bfa_sm_fault(dconf->bfa, event);
  4955. }
  4956. }
  4957. /*
  4958. * Read flash for dconf entries and make a call back to the driver once done.
  4959. */
  4960. static void
  4961. bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4962. enum bfa_dconf_event event)
  4963. {
  4964. bfa_trc(dconf->bfa, event);
  4965. switch (event) {
  4966. case BFA_DCONF_SM_FLASH_COMP:
  4967. bfa_timer_stop(&dconf->timer);
  4968. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4969. break;
  4970. case BFA_DCONF_SM_TIMEOUT:
  4971. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4972. bfa_ioc_suspend(&dconf->bfa->ioc);
  4973. break;
  4974. case BFA_DCONF_SM_EXIT:
  4975. bfa_timer_stop(&dconf->timer);
  4976. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4977. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4978. break;
  4979. case BFA_DCONF_SM_IOCDISABLE:
  4980. bfa_timer_stop(&dconf->timer);
  4981. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4982. break;
  4983. default:
  4984. bfa_sm_fault(dconf->bfa, event);
  4985. }
  4986. }
  4987. /*
  4988. * DCONF Module is in ready state. Has completed the initialization.
  4989. */
  4990. static void
  4991. bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4992. {
  4993. bfa_trc(dconf->bfa, event);
  4994. switch (event) {
  4995. case BFA_DCONF_SM_WR:
  4996. bfa_timer_start(dconf->bfa, &dconf->timer,
  4997. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  4998. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  4999. break;
  5000. case BFA_DCONF_SM_EXIT:
  5001. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5002. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5003. break;
  5004. case BFA_DCONF_SM_INIT:
  5005. case BFA_DCONF_SM_IOCDISABLE:
  5006. break;
  5007. default:
  5008. bfa_sm_fault(dconf->bfa, event);
  5009. }
  5010. }
  5011. /*
  5012. * entries are dirty, write back to the flash.
  5013. */
  5014. static void
  5015. bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  5016. {
  5017. bfa_trc(dconf->bfa, event);
  5018. switch (event) {
  5019. case BFA_DCONF_SM_TIMEOUT:
  5020. bfa_sm_set_state(dconf, bfa_dconf_sm_sync);
  5021. bfa_dconf_flash_write(dconf);
  5022. break;
  5023. case BFA_DCONF_SM_WR:
  5024. bfa_timer_stop(&dconf->timer);
  5025. bfa_timer_start(dconf->bfa, &dconf->timer,
  5026. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5027. break;
  5028. case BFA_DCONF_SM_EXIT:
  5029. bfa_timer_stop(&dconf->timer);
  5030. bfa_timer_start(dconf->bfa, &dconf->timer,
  5031. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5032. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  5033. bfa_dconf_flash_write(dconf);
  5034. break;
  5035. case BFA_DCONF_SM_FLASH_COMP:
  5036. break;
  5037. case BFA_DCONF_SM_IOCDISABLE:
  5038. bfa_timer_stop(&dconf->timer);
  5039. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  5040. break;
  5041. default:
  5042. bfa_sm_fault(dconf->bfa, event);
  5043. }
  5044. }
  5045. /*
  5046. * Sync the dconf entries to the flash.
  5047. */
  5048. static void
  5049. bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  5050. enum bfa_dconf_event event)
  5051. {
  5052. bfa_trc(dconf->bfa, event);
  5053. switch (event) {
  5054. case BFA_DCONF_SM_IOCDISABLE:
  5055. case BFA_DCONF_SM_FLASH_COMP:
  5056. bfa_timer_stop(&dconf->timer);
  5057. fallthrough;
  5058. case BFA_DCONF_SM_TIMEOUT:
  5059. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5060. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5061. break;
  5062. default:
  5063. bfa_sm_fault(dconf->bfa, event);
  5064. }
  5065. }
  5066. static void
  5067. bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  5068. {
  5069. bfa_trc(dconf->bfa, event);
  5070. switch (event) {
  5071. case BFA_DCONF_SM_FLASH_COMP:
  5072. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  5073. break;
  5074. case BFA_DCONF_SM_WR:
  5075. bfa_timer_start(dconf->bfa, &dconf->timer,
  5076. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5077. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  5078. break;
  5079. case BFA_DCONF_SM_EXIT:
  5080. bfa_timer_start(dconf->bfa, &dconf->timer,
  5081. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5082. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  5083. break;
  5084. case BFA_DCONF_SM_IOCDISABLE:
  5085. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  5086. break;
  5087. default:
  5088. bfa_sm_fault(dconf->bfa, event);
  5089. }
  5090. }
  5091. static void
  5092. bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  5093. enum bfa_dconf_event event)
  5094. {
  5095. bfa_trc(dconf->bfa, event);
  5096. switch (event) {
  5097. case BFA_DCONF_SM_INIT:
  5098. bfa_timer_start(dconf->bfa, &dconf->timer,
  5099. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5100. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  5101. break;
  5102. case BFA_DCONF_SM_EXIT:
  5103. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5104. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5105. break;
  5106. case BFA_DCONF_SM_IOCDISABLE:
  5107. break;
  5108. default:
  5109. bfa_sm_fault(dconf->bfa, event);
  5110. }
  5111. }
  5112. /*
  5113. * Compute and return memory needed by DRV_CFG module.
  5114. */
  5115. void
  5116. bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  5117. struct bfa_s *bfa)
  5118. {
  5119. struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa);
  5120. if (cfg->drvcfg.min_cfg)
  5121. bfa_mem_kva_setup(meminfo, dconf_kva,
  5122. sizeof(struct bfa_dconf_hdr_s));
  5123. else
  5124. bfa_mem_kva_setup(meminfo, dconf_kva,
  5125. sizeof(struct bfa_dconf_s));
  5126. }
  5127. void
  5128. bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg)
  5129. {
  5130. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5131. dconf->bfad = bfad;
  5132. dconf->bfa = bfa;
  5133. dconf->instance = bfa->ioc.port_id;
  5134. bfa_trc(bfa, dconf->instance);
  5135. dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf);
  5136. if (cfg->drvcfg.min_cfg) {
  5137. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
  5138. dconf->min_cfg = BFA_TRUE;
  5139. } else {
  5140. dconf->min_cfg = BFA_FALSE;
  5141. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
  5142. }
  5143. bfa_dconf_read_data_valid(bfa) = BFA_FALSE;
  5144. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5145. }
  5146. static void
  5147. bfa_dconf_init_cb(void *arg, bfa_status_t status)
  5148. {
  5149. struct bfa_s *bfa = arg;
  5150. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5151. if (status == BFA_STATUS_OK) {
  5152. bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
  5153. if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
  5154. dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE;
  5155. if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
  5156. dconf->dconf->hdr.version = BFI_DCONF_VERSION;
  5157. }
  5158. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  5159. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
  5160. }
  5161. void
  5162. bfa_dconf_modinit(struct bfa_s *bfa)
  5163. {
  5164. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5165. bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT);
  5166. }
  5167. static void bfa_dconf_timer(void *cbarg)
  5168. {
  5169. struct bfa_dconf_mod_s *dconf = cbarg;
  5170. bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT);
  5171. }
  5172. void
  5173. bfa_dconf_iocdisable(struct bfa_s *bfa)
  5174. {
  5175. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5176. bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE);
  5177. }
  5178. static bfa_status_t
  5179. bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf)
  5180. {
  5181. bfa_status_t bfa_status;
  5182. bfa_trc(dconf->bfa, 0);
  5183. bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa),
  5184. BFA_FLASH_PART_DRV, dconf->instance,
  5185. dconf->dconf, sizeof(struct bfa_dconf_s), 0,
  5186. bfa_dconf_cbfn, dconf);
  5187. if (bfa_status != BFA_STATUS_OK)
  5188. WARN_ON(bfa_status);
  5189. bfa_trc(dconf->bfa, bfa_status);
  5190. return bfa_status;
  5191. }
  5192. bfa_status_t
  5193. bfa_dconf_update(struct bfa_s *bfa)
  5194. {
  5195. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5196. bfa_trc(dconf->bfa, 0);
  5197. if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty))
  5198. return BFA_STATUS_FAILED;
  5199. if (dconf->min_cfg) {
  5200. bfa_trc(dconf->bfa, dconf->min_cfg);
  5201. return BFA_STATUS_FAILED;
  5202. }
  5203. bfa_sm_send_event(dconf, BFA_DCONF_SM_WR);
  5204. return BFA_STATUS_OK;
  5205. }
  5206. static void
  5207. bfa_dconf_cbfn(void *arg, bfa_status_t status)
  5208. {
  5209. struct bfa_dconf_mod_s *dconf = arg;
  5210. WARN_ON(status);
  5211. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  5212. }
  5213. void
  5214. bfa_dconf_modexit(struct bfa_s *bfa)
  5215. {
  5216. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5217. bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);
  5218. }
  5219. /*
  5220. * FRU specific functions
  5221. */
  5222. #define BFA_FRU_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
  5223. #define BFA_FRU_CHINOOK_MAX_SIZE 0x10000
  5224. #define BFA_FRU_LIGHTNING_MAX_SIZE 0x200
  5225. static void
  5226. bfa_fru_notify(void *cbarg, enum bfa_ioc_event_e event)
  5227. {
  5228. struct bfa_fru_s *fru = cbarg;
  5229. bfa_trc(fru, event);
  5230. switch (event) {
  5231. case BFA_IOC_E_DISABLED:
  5232. case BFA_IOC_E_FAILED:
  5233. if (fru->op_busy) {
  5234. fru->status = BFA_STATUS_IOC_FAILURE;
  5235. fru->cbfn(fru->cbarg, fru->status);
  5236. fru->op_busy = 0;
  5237. }
  5238. break;
  5239. default:
  5240. break;
  5241. }
  5242. }
  5243. /*
  5244. * Send fru write request.
  5245. *
  5246. * @param[in] cbarg - callback argument
  5247. */
  5248. static void
  5249. bfa_fru_write_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
  5250. {
  5251. struct bfa_fru_s *fru = cbarg;
  5252. struct bfi_fru_write_req_s *msg =
  5253. (struct bfi_fru_write_req_s *) fru->mb.msg;
  5254. u32 len;
  5255. msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
  5256. len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
  5257. fru->residue : BFA_FRU_DMA_BUF_SZ;
  5258. msg->length = cpu_to_be32(len);
  5259. /*
  5260. * indicate if it's the last msg of the whole write operation
  5261. */
  5262. msg->last = (len == fru->residue) ? 1 : 0;
  5263. msg->trfr_cmpl = (len == fru->residue) ? fru->trfr_cmpl : 0;
  5264. bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
  5265. bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
  5266. memcpy(fru->dbuf_kva, fru->ubuf + fru->offset, len);
  5267. bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
  5268. fru->residue -= len;
  5269. fru->offset += len;
  5270. }
  5271. /*
  5272. * Send fru read request.
  5273. *
  5274. * @param[in] cbarg - callback argument
  5275. */
  5276. static void
  5277. bfa_fru_read_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
  5278. {
  5279. struct bfa_fru_s *fru = cbarg;
  5280. struct bfi_fru_read_req_s *msg =
  5281. (struct bfi_fru_read_req_s *) fru->mb.msg;
  5282. u32 len;
  5283. msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
  5284. len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
  5285. fru->residue : BFA_FRU_DMA_BUF_SZ;
  5286. msg->length = cpu_to_be32(len);
  5287. bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
  5288. bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
  5289. bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
  5290. }
  5291. /*
  5292. * Flash memory info API.
  5293. *
  5294. * @param[in] mincfg - minimal cfg variable
  5295. */
  5296. u32
  5297. bfa_fru_meminfo(bfa_boolean_t mincfg)
  5298. {
  5299. /* min driver doesn't need fru */
  5300. if (mincfg)
  5301. return 0;
  5302. return BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5303. }
  5304. /*
  5305. * Flash attach API.
  5306. *
  5307. * @param[in] fru - fru structure
  5308. * @param[in] ioc - ioc structure
  5309. * @param[in] dev - device structure
  5310. * @param[in] trcmod - trace module
  5311. * @param[in] logmod - log module
  5312. */
  5313. void
  5314. bfa_fru_attach(struct bfa_fru_s *fru, struct bfa_ioc_s *ioc, void *dev,
  5315. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  5316. {
  5317. fru->ioc = ioc;
  5318. fru->trcmod = trcmod;
  5319. fru->cbfn = NULL;
  5320. fru->cbarg = NULL;
  5321. fru->op_busy = 0;
  5322. bfa_ioc_mbox_regisr(fru->ioc, BFI_MC_FRU, bfa_fru_intr, fru);
  5323. bfa_q_qe_init(&fru->ioc_notify);
  5324. bfa_ioc_notify_init(&fru->ioc_notify, bfa_fru_notify, fru);
  5325. list_add_tail(&fru->ioc_notify.qe, &fru->ioc->notify_q);
  5326. /* min driver doesn't need fru */
  5327. if (mincfg) {
  5328. fru->dbuf_kva = NULL;
  5329. fru->dbuf_pa = 0;
  5330. }
  5331. }
  5332. /*
  5333. * Claim memory for fru
  5334. *
  5335. * @param[in] fru - fru structure
  5336. * @param[in] dm_kva - pointer to virtual memory address
  5337. * @param[in] dm_pa - frusical memory address
  5338. * @param[in] mincfg - minimal cfg variable
  5339. */
  5340. void
  5341. bfa_fru_memclaim(struct bfa_fru_s *fru, u8 *dm_kva, u64 dm_pa,
  5342. bfa_boolean_t mincfg)
  5343. {
  5344. if (mincfg)
  5345. return;
  5346. fru->dbuf_kva = dm_kva;
  5347. fru->dbuf_pa = dm_pa;
  5348. memset(fru->dbuf_kva, 0, BFA_FRU_DMA_BUF_SZ);
  5349. dm_kva += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5350. dm_pa += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5351. }
  5352. /*
  5353. * Update fru vpd image.
  5354. *
  5355. * @param[in] fru - fru structure
  5356. * @param[in] buf - update data buffer
  5357. * @param[in] len - data buffer length
  5358. * @param[in] offset - offset relative to starting address
  5359. * @param[in] cbfn - callback function
  5360. * @param[in] cbarg - callback argument
  5361. *
  5362. * Return status.
  5363. */
  5364. bfa_status_t
  5365. bfa_fruvpd_update(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5366. bfa_cb_fru_t cbfn, void *cbarg, u8 trfr_cmpl)
  5367. {
  5368. bfa_trc(fru, BFI_FRUVPD_H2I_WRITE_REQ);
  5369. bfa_trc(fru, len);
  5370. bfa_trc(fru, offset);
  5371. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2 &&
  5372. fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK2)
  5373. return BFA_STATUS_FRU_NOT_PRESENT;
  5374. if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK)
  5375. return BFA_STATUS_CMD_NOTSUPP;
  5376. if (!bfa_ioc_is_operational(fru->ioc))
  5377. return BFA_STATUS_IOC_NON_OP;
  5378. if (fru->op_busy) {
  5379. bfa_trc(fru, fru->op_busy);
  5380. return BFA_STATUS_DEVBUSY;
  5381. }
  5382. fru->op_busy = 1;
  5383. fru->cbfn = cbfn;
  5384. fru->cbarg = cbarg;
  5385. fru->residue = len;
  5386. fru->offset = 0;
  5387. fru->addr_off = offset;
  5388. fru->ubuf = buf;
  5389. fru->trfr_cmpl = trfr_cmpl;
  5390. bfa_fru_write_send(fru, BFI_FRUVPD_H2I_WRITE_REQ);
  5391. return BFA_STATUS_OK;
  5392. }
  5393. /*
  5394. * Read fru vpd image.
  5395. *
  5396. * @param[in] fru - fru structure
  5397. * @param[in] buf - read data buffer
  5398. * @param[in] len - data buffer length
  5399. * @param[in] offset - offset relative to starting address
  5400. * @param[in] cbfn - callback function
  5401. * @param[in] cbarg - callback argument
  5402. *
  5403. * Return status.
  5404. */
  5405. bfa_status_t
  5406. bfa_fruvpd_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5407. bfa_cb_fru_t cbfn, void *cbarg)
  5408. {
  5409. bfa_trc(fru, BFI_FRUVPD_H2I_READ_REQ);
  5410. bfa_trc(fru, len);
  5411. bfa_trc(fru, offset);
  5412. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5413. return BFA_STATUS_FRU_NOT_PRESENT;
  5414. if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK &&
  5415. fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK2)
  5416. return BFA_STATUS_CMD_NOTSUPP;
  5417. if (!bfa_ioc_is_operational(fru->ioc))
  5418. return BFA_STATUS_IOC_NON_OP;
  5419. if (fru->op_busy) {
  5420. bfa_trc(fru, fru->op_busy);
  5421. return BFA_STATUS_DEVBUSY;
  5422. }
  5423. fru->op_busy = 1;
  5424. fru->cbfn = cbfn;
  5425. fru->cbarg = cbarg;
  5426. fru->residue = len;
  5427. fru->offset = 0;
  5428. fru->addr_off = offset;
  5429. fru->ubuf = buf;
  5430. bfa_fru_read_send(fru, BFI_FRUVPD_H2I_READ_REQ);
  5431. return BFA_STATUS_OK;
  5432. }
  5433. /*
  5434. * Get maximum size fru vpd image.
  5435. *
  5436. * @param[in] fru - fru structure
  5437. * @param[out] size - maximum size of fru vpd data
  5438. *
  5439. * Return status.
  5440. */
  5441. bfa_status_t
  5442. bfa_fruvpd_get_max_size(struct bfa_fru_s *fru, u32 *max_size)
  5443. {
  5444. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5445. return BFA_STATUS_FRU_NOT_PRESENT;
  5446. if (!bfa_ioc_is_operational(fru->ioc))
  5447. return BFA_STATUS_IOC_NON_OP;
  5448. if (fru->ioc->attr->card_type == BFA_MFG_TYPE_CHINOOK ||
  5449. fru->ioc->attr->card_type == BFA_MFG_TYPE_CHINOOK2)
  5450. *max_size = BFA_FRU_CHINOOK_MAX_SIZE;
  5451. else
  5452. return BFA_STATUS_CMD_NOTSUPP;
  5453. return BFA_STATUS_OK;
  5454. }
  5455. /*
  5456. * tfru write.
  5457. *
  5458. * @param[in] fru - fru structure
  5459. * @param[in] buf - update data buffer
  5460. * @param[in] len - data buffer length
  5461. * @param[in] offset - offset relative to starting address
  5462. * @param[in] cbfn - callback function
  5463. * @param[in] cbarg - callback argument
  5464. *
  5465. * Return status.
  5466. */
  5467. bfa_status_t
  5468. bfa_tfru_write(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5469. bfa_cb_fru_t cbfn, void *cbarg)
  5470. {
  5471. bfa_trc(fru, BFI_TFRU_H2I_WRITE_REQ);
  5472. bfa_trc(fru, len);
  5473. bfa_trc(fru, offset);
  5474. bfa_trc(fru, *((u8 *) buf));
  5475. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5476. return BFA_STATUS_FRU_NOT_PRESENT;
  5477. if (!bfa_ioc_is_operational(fru->ioc))
  5478. return BFA_STATUS_IOC_NON_OP;
  5479. if (fru->op_busy) {
  5480. bfa_trc(fru, fru->op_busy);
  5481. return BFA_STATUS_DEVBUSY;
  5482. }
  5483. fru->op_busy = 1;
  5484. fru->cbfn = cbfn;
  5485. fru->cbarg = cbarg;
  5486. fru->residue = len;
  5487. fru->offset = 0;
  5488. fru->addr_off = offset;
  5489. fru->ubuf = buf;
  5490. bfa_fru_write_send(fru, BFI_TFRU_H2I_WRITE_REQ);
  5491. return BFA_STATUS_OK;
  5492. }
  5493. /*
  5494. * tfru read.
  5495. *
  5496. * @param[in] fru - fru structure
  5497. * @param[in] buf - read data buffer
  5498. * @param[in] len - data buffer length
  5499. * @param[in] offset - offset relative to starting address
  5500. * @param[in] cbfn - callback function
  5501. * @param[in] cbarg - callback argument
  5502. *
  5503. * Return status.
  5504. */
  5505. bfa_status_t
  5506. bfa_tfru_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5507. bfa_cb_fru_t cbfn, void *cbarg)
  5508. {
  5509. bfa_trc(fru, BFI_TFRU_H2I_READ_REQ);
  5510. bfa_trc(fru, len);
  5511. bfa_trc(fru, offset);
  5512. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5513. return BFA_STATUS_FRU_NOT_PRESENT;
  5514. if (!bfa_ioc_is_operational(fru->ioc))
  5515. return BFA_STATUS_IOC_NON_OP;
  5516. if (fru->op_busy) {
  5517. bfa_trc(fru, fru->op_busy);
  5518. return BFA_STATUS_DEVBUSY;
  5519. }
  5520. fru->op_busy = 1;
  5521. fru->cbfn = cbfn;
  5522. fru->cbarg = cbarg;
  5523. fru->residue = len;
  5524. fru->offset = 0;
  5525. fru->addr_off = offset;
  5526. fru->ubuf = buf;
  5527. bfa_fru_read_send(fru, BFI_TFRU_H2I_READ_REQ);
  5528. return BFA_STATUS_OK;
  5529. }
  5530. /*
  5531. * Process fru response messages upon receiving interrupts.
  5532. *
  5533. * @param[in] fruarg - fru structure
  5534. * @param[in] msg - message structure
  5535. */
  5536. void
  5537. bfa_fru_intr(void *fruarg, struct bfi_mbmsg_s *msg)
  5538. {
  5539. struct bfa_fru_s *fru = fruarg;
  5540. struct bfi_fru_rsp_s *rsp = (struct bfi_fru_rsp_s *)msg;
  5541. u32 status;
  5542. bfa_trc(fru, msg->mh.msg_id);
  5543. if (!fru->op_busy) {
  5544. /*
  5545. * receiving response after ioc failure
  5546. */
  5547. bfa_trc(fru, 0x9999);
  5548. return;
  5549. }
  5550. switch (msg->mh.msg_id) {
  5551. case BFI_FRUVPD_I2H_WRITE_RSP:
  5552. case BFI_TFRU_I2H_WRITE_RSP:
  5553. status = be32_to_cpu(rsp->status);
  5554. bfa_trc(fru, status);
  5555. if (status != BFA_STATUS_OK || fru->residue == 0) {
  5556. fru->status = status;
  5557. fru->op_busy = 0;
  5558. if (fru->cbfn)
  5559. fru->cbfn(fru->cbarg, fru->status);
  5560. } else {
  5561. bfa_trc(fru, fru->offset);
  5562. if (msg->mh.msg_id == BFI_FRUVPD_I2H_WRITE_RSP)
  5563. bfa_fru_write_send(fru,
  5564. BFI_FRUVPD_H2I_WRITE_REQ);
  5565. else
  5566. bfa_fru_write_send(fru,
  5567. BFI_TFRU_H2I_WRITE_REQ);
  5568. }
  5569. break;
  5570. case BFI_FRUVPD_I2H_READ_RSP:
  5571. case BFI_TFRU_I2H_READ_RSP:
  5572. status = be32_to_cpu(rsp->status);
  5573. bfa_trc(fru, status);
  5574. if (status != BFA_STATUS_OK) {
  5575. fru->status = status;
  5576. fru->op_busy = 0;
  5577. if (fru->cbfn)
  5578. fru->cbfn(fru->cbarg, fru->status);
  5579. } else {
  5580. u32 len = be32_to_cpu(rsp->length);
  5581. bfa_trc(fru, fru->offset);
  5582. bfa_trc(fru, len);
  5583. memcpy(fru->ubuf + fru->offset, fru->dbuf_kva, len);
  5584. fru->residue -= len;
  5585. fru->offset += len;
  5586. if (fru->residue == 0) {
  5587. fru->status = status;
  5588. fru->op_busy = 0;
  5589. if (fru->cbfn)
  5590. fru->cbfn(fru->cbarg, fru->status);
  5591. } else {
  5592. if (msg->mh.msg_id == BFI_FRUVPD_I2H_READ_RSP)
  5593. bfa_fru_read_send(fru,
  5594. BFI_FRUVPD_H2I_READ_REQ);
  5595. else
  5596. bfa_fru_read_send(fru,
  5597. BFI_TFRU_H2I_READ_REQ);
  5598. }
  5599. }
  5600. break;
  5601. default:
  5602. WARN_ON(1);
  5603. }
  5604. }
  5605. /*
  5606. * register definitions
  5607. */
  5608. #define FLI_CMD_REG 0x0001d000
  5609. #define FLI_RDDATA_REG 0x0001d010
  5610. #define FLI_ADDR_REG 0x0001d004
  5611. #define FLI_DEV_STATUS_REG 0x0001d014
  5612. #define BFA_FLASH_FIFO_SIZE 128 /* fifo size */
  5613. #define BFA_FLASH_CHECK_MAX 10000 /* max # of status check */
  5614. #define BFA_FLASH_BLOCKING_OP_MAX 1000000 /* max # of blocking op check */
  5615. #define BFA_FLASH_WIP_MASK 0x01 /* write in progress bit mask */
  5616. enum bfa_flash_cmd {
  5617. BFA_FLASH_FAST_READ = 0x0b, /* fast read */
  5618. BFA_FLASH_READ_STATUS = 0x05, /* read status */
  5619. };
  5620. /*
  5621. * Hardware error definition
  5622. */
  5623. enum bfa_flash_err {
  5624. BFA_FLASH_NOT_PRESENT = -1, /*!< flash not present */
  5625. BFA_FLASH_UNINIT = -2, /*!< flash not initialized */
  5626. BFA_FLASH_BAD = -3, /*!< flash bad */
  5627. BFA_FLASH_BUSY = -4, /*!< flash busy */
  5628. BFA_FLASH_ERR_CMD_ACT = -5, /*!< command active never cleared */
  5629. BFA_FLASH_ERR_FIFO_CNT = -6, /*!< fifo count never cleared */
  5630. BFA_FLASH_ERR_WIP = -7, /*!< write-in-progress never cleared */
  5631. BFA_FLASH_ERR_TIMEOUT = -8, /*!< fli timeout */
  5632. BFA_FLASH_ERR_LEN = -9, /*!< invalid length */
  5633. };
  5634. /*
  5635. * Flash command register data structure
  5636. */
  5637. union bfa_flash_cmd_reg_u {
  5638. struct {
  5639. #ifdef __BIG_ENDIAN
  5640. u32 act:1;
  5641. u32 rsv:1;
  5642. u32 write_cnt:9;
  5643. u32 read_cnt:9;
  5644. u32 addr_cnt:4;
  5645. u32 cmd:8;
  5646. #else
  5647. u32 cmd:8;
  5648. u32 addr_cnt:4;
  5649. u32 read_cnt:9;
  5650. u32 write_cnt:9;
  5651. u32 rsv:1;
  5652. u32 act:1;
  5653. #endif
  5654. } r;
  5655. u32 i;
  5656. };
  5657. /*
  5658. * Flash device status register data structure
  5659. */
  5660. union bfa_flash_dev_status_reg_u {
  5661. struct {
  5662. #ifdef __BIG_ENDIAN
  5663. u32 rsv:21;
  5664. u32 fifo_cnt:6;
  5665. u32 busy:1;
  5666. u32 init_status:1;
  5667. u32 present:1;
  5668. u32 bad:1;
  5669. u32 good:1;
  5670. #else
  5671. u32 good:1;
  5672. u32 bad:1;
  5673. u32 present:1;
  5674. u32 init_status:1;
  5675. u32 busy:1;
  5676. u32 fifo_cnt:6;
  5677. u32 rsv:21;
  5678. #endif
  5679. } r;
  5680. u32 i;
  5681. };
  5682. /*
  5683. * Flash address register data structure
  5684. */
  5685. union bfa_flash_addr_reg_u {
  5686. struct {
  5687. #ifdef __BIG_ENDIAN
  5688. u32 addr:24;
  5689. u32 dummy:8;
  5690. #else
  5691. u32 dummy:8;
  5692. u32 addr:24;
  5693. #endif
  5694. } r;
  5695. u32 i;
  5696. };
  5697. /*
  5698. * dg flash_raw_private Flash raw private functions
  5699. */
  5700. static void
  5701. bfa_flash_set_cmd(void __iomem *pci_bar, u8 wr_cnt,
  5702. u8 rd_cnt, u8 ad_cnt, u8 op)
  5703. {
  5704. union bfa_flash_cmd_reg_u cmd;
  5705. cmd.i = 0;
  5706. cmd.r.act = 1;
  5707. cmd.r.write_cnt = wr_cnt;
  5708. cmd.r.read_cnt = rd_cnt;
  5709. cmd.r.addr_cnt = ad_cnt;
  5710. cmd.r.cmd = op;
  5711. writel(cmd.i, (pci_bar + FLI_CMD_REG));
  5712. }
  5713. static void
  5714. bfa_flash_set_addr(void __iomem *pci_bar, u32 address)
  5715. {
  5716. union bfa_flash_addr_reg_u addr;
  5717. addr.r.addr = address & 0x00ffffff;
  5718. addr.r.dummy = 0;
  5719. writel(addr.i, (pci_bar + FLI_ADDR_REG));
  5720. }
  5721. static int
  5722. bfa_flash_cmd_act_check(void __iomem *pci_bar)
  5723. {
  5724. union bfa_flash_cmd_reg_u cmd;
  5725. cmd.i = readl(pci_bar + FLI_CMD_REG);
  5726. if (cmd.r.act)
  5727. return BFA_FLASH_ERR_CMD_ACT;
  5728. return 0;
  5729. }
  5730. /*
  5731. * @brief
  5732. * Flush FLI data fifo.
  5733. *
  5734. * @param[in] pci_bar - pci bar address
  5735. * @param[in] dev_status - device status
  5736. *
  5737. * Return 0 on success, negative error number on error.
  5738. */
  5739. static u32
  5740. bfa_flash_fifo_flush(void __iomem *pci_bar)
  5741. {
  5742. u32 i;
  5743. union bfa_flash_dev_status_reg_u dev_status;
  5744. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5745. if (!dev_status.r.fifo_cnt)
  5746. return 0;
  5747. /* fifo counter in terms of words */
  5748. for (i = 0; i < dev_status.r.fifo_cnt; i++)
  5749. readl(pci_bar + FLI_RDDATA_REG);
  5750. /*
  5751. * Check the device status. It may take some time.
  5752. */
  5753. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  5754. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5755. if (!dev_status.r.fifo_cnt)
  5756. break;
  5757. }
  5758. if (dev_status.r.fifo_cnt)
  5759. return BFA_FLASH_ERR_FIFO_CNT;
  5760. return 0;
  5761. }
  5762. /*
  5763. * @brief
  5764. * Read flash status.
  5765. *
  5766. * @param[in] pci_bar - pci bar address
  5767. *
  5768. * Return 0 on success, negative error number on error.
  5769. */
  5770. static u32
  5771. bfa_flash_status_read(void __iomem *pci_bar)
  5772. {
  5773. union bfa_flash_dev_status_reg_u dev_status;
  5774. int status;
  5775. u32 ret_status;
  5776. int i;
  5777. status = bfa_flash_fifo_flush(pci_bar);
  5778. if (status < 0)
  5779. return status;
  5780. bfa_flash_set_cmd(pci_bar, 0, 4, 0, BFA_FLASH_READ_STATUS);
  5781. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  5782. status = bfa_flash_cmd_act_check(pci_bar);
  5783. if (!status)
  5784. break;
  5785. }
  5786. if (status)
  5787. return status;
  5788. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5789. if (!dev_status.r.fifo_cnt)
  5790. return BFA_FLASH_BUSY;
  5791. ret_status = readl(pci_bar + FLI_RDDATA_REG);
  5792. ret_status >>= 24;
  5793. status = bfa_flash_fifo_flush(pci_bar);
  5794. if (status < 0)
  5795. return status;
  5796. return ret_status;
  5797. }
  5798. /*
  5799. * @brief
  5800. * Start flash read operation.
  5801. *
  5802. * @param[in] pci_bar - pci bar address
  5803. * @param[in] offset - flash address offset
  5804. * @param[in] len - read data length
  5805. * @param[in] buf - read data buffer
  5806. *
  5807. * Return 0 on success, negative error number on error.
  5808. */
  5809. static u32
  5810. bfa_flash_read_start(void __iomem *pci_bar, u32 offset, u32 len,
  5811. char *buf)
  5812. {
  5813. int status;
  5814. /*
  5815. * len must be mutiple of 4 and not exceeding fifo size
  5816. */
  5817. if (len == 0 || len > BFA_FLASH_FIFO_SIZE || (len & 0x03) != 0)
  5818. return BFA_FLASH_ERR_LEN;
  5819. /*
  5820. * check status
  5821. */
  5822. status = bfa_flash_status_read(pci_bar);
  5823. if (status == BFA_FLASH_BUSY)
  5824. status = bfa_flash_status_read(pci_bar);
  5825. if (status < 0)
  5826. return status;
  5827. /*
  5828. * check if write-in-progress bit is cleared
  5829. */
  5830. if (status & BFA_FLASH_WIP_MASK)
  5831. return BFA_FLASH_ERR_WIP;
  5832. bfa_flash_set_addr(pci_bar, offset);
  5833. bfa_flash_set_cmd(pci_bar, 0, (u8)len, 4, BFA_FLASH_FAST_READ);
  5834. return 0;
  5835. }
  5836. /*
  5837. * @brief
  5838. * Check flash read operation.
  5839. *
  5840. * @param[in] pci_bar - pci bar address
  5841. *
  5842. * Return flash device status, 1 if busy, 0 if not.
  5843. */
  5844. static u32
  5845. bfa_flash_read_check(void __iomem *pci_bar)
  5846. {
  5847. if (bfa_flash_cmd_act_check(pci_bar))
  5848. return 1;
  5849. return 0;
  5850. }
  5851. /*
  5852. * @brief
  5853. * End flash read operation.
  5854. *
  5855. * @param[in] pci_bar - pci bar address
  5856. * @param[in] len - read data length
  5857. * @param[in] buf - read data buffer
  5858. *
  5859. */
  5860. static void
  5861. bfa_flash_read_end(void __iomem *pci_bar, u32 len, char *buf)
  5862. {
  5863. u32 i;
  5864. /*
  5865. * read data fifo up to 32 words
  5866. */
  5867. for (i = 0; i < len; i += 4) {
  5868. u32 w = readl(pci_bar + FLI_RDDATA_REG);
  5869. *((u32 *) (buf + i)) = swab32(w);
  5870. }
  5871. bfa_flash_fifo_flush(pci_bar);
  5872. }
  5873. /*
  5874. * @brief
  5875. * Perform flash raw read.
  5876. *
  5877. * @param[in] pci_bar - pci bar address
  5878. * @param[in] offset - flash partition address offset
  5879. * @param[in] buf - read data buffer
  5880. * @param[in] len - read data length
  5881. *
  5882. * Return status.
  5883. */
  5884. #define FLASH_BLOCKING_OP_MAX 500
  5885. #define FLASH_SEM_LOCK_REG 0x18820
  5886. static int
  5887. bfa_raw_sem_get(void __iomem *bar)
  5888. {
  5889. int locked;
  5890. locked = readl((bar + FLASH_SEM_LOCK_REG));
  5891. return !locked;
  5892. }
  5893. static bfa_status_t
  5894. bfa_flash_sem_get(void __iomem *bar)
  5895. {
  5896. u32 n = FLASH_BLOCKING_OP_MAX;
  5897. while (!bfa_raw_sem_get(bar)) {
  5898. if (--n <= 0)
  5899. return BFA_STATUS_BADFLASH;
  5900. mdelay(10);
  5901. }
  5902. return BFA_STATUS_OK;
  5903. }
  5904. static void
  5905. bfa_flash_sem_put(void __iomem *bar)
  5906. {
  5907. writel(0, (bar + FLASH_SEM_LOCK_REG));
  5908. }
  5909. bfa_status_t
  5910. bfa_flash_raw_read(void __iomem *pci_bar, u32 offset, char *buf,
  5911. u32 len)
  5912. {
  5913. u32 n;
  5914. int status;
  5915. u32 off, l, s, residue, fifo_sz;
  5916. residue = len;
  5917. off = 0;
  5918. fifo_sz = BFA_FLASH_FIFO_SIZE;
  5919. status = bfa_flash_sem_get(pci_bar);
  5920. if (status != BFA_STATUS_OK)
  5921. return status;
  5922. while (residue) {
  5923. s = offset + off;
  5924. n = s / fifo_sz;
  5925. l = (n + 1) * fifo_sz - s;
  5926. if (l > residue)
  5927. l = residue;
  5928. status = bfa_flash_read_start(pci_bar, offset + off, l,
  5929. &buf[off]);
  5930. if (status < 0) {
  5931. bfa_flash_sem_put(pci_bar);
  5932. return BFA_STATUS_FAILED;
  5933. }
  5934. n = BFA_FLASH_BLOCKING_OP_MAX;
  5935. while (bfa_flash_read_check(pci_bar)) {
  5936. if (--n <= 0) {
  5937. bfa_flash_sem_put(pci_bar);
  5938. return BFA_STATUS_FAILED;
  5939. }
  5940. }
  5941. bfa_flash_read_end(pci_bar, l, &buf[off]);
  5942. residue -= l;
  5943. off += l;
  5944. }
  5945. bfa_flash_sem_put(pci_bar);
  5946. return BFA_STATUS_OK;
  5947. }