bfa_ioc.c 161 KB

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