bfa_ioc.c 147 KB

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