bfa_ioc.c 136 KB

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