bfa_ioc.c 136 KB

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