bfa_ioc.c 146 KB

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