bfa_ioc.c 137 KB

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