bfa_ioc.c 161 KB

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