bfa_ioc.c 161 KB

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