bfa_ioc.c 110 KB

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