bfa_ioc.c 136 KB

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