bfa_ioc.c 161 KB

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