bfa_ioc.c 135 KB

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