bfa_svc.c 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071
  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_plog.h"
  19. #include "bfa_cs.h"
  20. #include "bfa_modules.h"
  21. BFA_TRC_FILE(HAL, FCXP);
  22. BFA_MODULE(fcxp);
  23. BFA_MODULE(sgpg);
  24. BFA_MODULE(lps);
  25. BFA_MODULE(fcport);
  26. BFA_MODULE(rport);
  27. BFA_MODULE(uf);
  28. /*
  29. * LPS related definitions
  30. */
  31. #define BFA_LPS_MIN_LPORTS (1)
  32. #define BFA_LPS_MAX_LPORTS (256)
  33. /*
  34. * Maximum Vports supported per physical port or vf.
  35. */
  36. #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
  37. #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
  38. /*
  39. * FC PORT related definitions
  40. */
  41. /*
  42. * The port is considered disabled if corresponding physical port or IOC are
  43. * disabled explicitly
  44. */
  45. #define BFA_PORT_IS_DISABLED(bfa) \
  46. ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
  47. (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
  48. /*
  49. * BFA port state machine events
  50. */
  51. enum bfa_fcport_sm_event {
  52. BFA_FCPORT_SM_START = 1, /* start port state machine */
  53. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  54. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  55. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  56. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  57. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  58. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  59. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  60. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  61. };
  62. /*
  63. * BFA port link notification state machine events
  64. */
  65. enum bfa_fcport_ln_sm_event {
  66. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  67. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  68. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  69. };
  70. /*
  71. * RPORT related definitions
  72. */
  73. #define bfa_rport_offline_cb(__rp) do { \
  74. if ((__rp)->bfa->fcs) \
  75. bfa_cb_rport_offline((__rp)->rport_drv); \
  76. else { \
  77. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  78. __bfa_cb_rport_offline, (__rp)); \
  79. } \
  80. } while (0)
  81. #define bfa_rport_online_cb(__rp) do { \
  82. if ((__rp)->bfa->fcs) \
  83. bfa_cb_rport_online((__rp)->rport_drv); \
  84. else { \
  85. bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
  86. __bfa_cb_rport_online, (__rp)); \
  87. } \
  88. } while (0)
  89. /*
  90. * forward declarations FCXP related functions
  91. */
  92. static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete);
  93. static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  94. struct bfi_fcxp_send_rsp_s *fcxp_rsp);
  95. static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen,
  96. struct bfa_fcxp_s *fcxp, struct fchs_s *fchs);
  97. static void bfa_fcxp_qresume(void *cbarg);
  98. static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp,
  99. struct bfi_fcxp_send_req_s *send_req);
  100. /*
  101. * forward declarations for LPS functions
  102. */
  103. static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  104. u32 *dm_len);
  105. static void bfa_lps_attach(struct bfa_s *bfa, void *bfad,
  106. struct bfa_iocfc_cfg_s *cfg,
  107. struct bfa_meminfo_s *meminfo,
  108. struct bfa_pcidev_s *pcidev);
  109. static void bfa_lps_detach(struct bfa_s *bfa);
  110. static void bfa_lps_start(struct bfa_s *bfa);
  111. static void bfa_lps_stop(struct bfa_s *bfa);
  112. static void bfa_lps_iocdisable(struct bfa_s *bfa);
  113. static void bfa_lps_login_rsp(struct bfa_s *bfa,
  114. struct bfi_lps_login_rsp_s *rsp);
  115. static void bfa_lps_logout_rsp(struct bfa_s *bfa,
  116. struct bfi_lps_logout_rsp_s *rsp);
  117. static void bfa_lps_reqq_resume(void *lps_arg);
  118. static void bfa_lps_free(struct bfa_lps_s *lps);
  119. static void bfa_lps_send_login(struct bfa_lps_s *lps);
  120. static void bfa_lps_send_logout(struct bfa_lps_s *lps);
  121. static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps);
  122. static void bfa_lps_login_comp(struct bfa_lps_s *lps);
  123. static void bfa_lps_logout_comp(struct bfa_lps_s *lps);
  124. static void bfa_lps_cvl_event(struct bfa_lps_s *lps);
  125. /*
  126. * forward declaration for LPS state machine
  127. */
  128. static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event);
  129. static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event);
  130. static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event
  131. event);
  132. static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event);
  133. static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps,
  134. enum bfa_lps_event event);
  135. static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event);
  136. static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event
  137. event);
  138. /*
  139. * forward declaration for FC Port functions
  140. */
  141. static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
  142. static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
  143. static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
  144. static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
  145. static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
  146. static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
  147. static void bfa_fcport_scn(struct bfa_fcport_s *fcport,
  148. enum bfa_port_linkstate event, bfa_boolean_t trunk);
  149. static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
  150. enum bfa_port_linkstate event);
  151. static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
  152. static void bfa_fcport_stats_get_timeout(void *cbarg);
  153. static void bfa_fcport_stats_clr_timeout(void *cbarg);
  154. static void bfa_trunk_iocdisable(struct bfa_s *bfa);
  155. /*
  156. * forward declaration for FC PORT state machine
  157. */
  158. static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  159. enum bfa_fcport_sm_event event);
  160. static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  161. enum bfa_fcport_sm_event event);
  162. static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  163. enum bfa_fcport_sm_event event);
  164. static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  165. enum bfa_fcport_sm_event event);
  166. static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  167. enum bfa_fcport_sm_event event);
  168. static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  169. enum bfa_fcport_sm_event event);
  170. static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  171. enum bfa_fcport_sm_event event);
  172. static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  173. enum bfa_fcport_sm_event event);
  174. static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  175. enum bfa_fcport_sm_event event);
  176. static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  177. enum bfa_fcport_sm_event event);
  178. static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  179. enum bfa_fcport_sm_event event);
  180. static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  181. enum bfa_fcport_sm_event event);
  182. static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  183. enum bfa_fcport_ln_sm_event event);
  184. static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  185. enum bfa_fcport_ln_sm_event event);
  186. static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  187. enum bfa_fcport_ln_sm_event event);
  188. static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  189. enum bfa_fcport_ln_sm_event event);
  190. static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  191. enum bfa_fcport_ln_sm_event event);
  192. static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  193. enum bfa_fcport_ln_sm_event event);
  194. static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  195. enum bfa_fcport_ln_sm_event event);
  196. static struct bfa_sm_table_s hal_port_sm_table[] = {
  197. {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT},
  198. {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT},
  199. {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING},
  200. {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN},
  201. {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP},
  202. {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT},
  203. {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT},
  204. {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING},
  205. {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED},
  206. {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED},
  207. {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN},
  208. {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN},
  209. };
  210. /*
  211. * forward declaration for RPORT related functions
  212. */
  213. static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod);
  214. static void bfa_rport_free(struct bfa_rport_s *rport);
  215. static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp);
  216. static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp);
  217. static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp);
  218. static void __bfa_cb_rport_online(void *cbarg,
  219. bfa_boolean_t complete);
  220. static void __bfa_cb_rport_offline(void *cbarg,
  221. bfa_boolean_t complete);
  222. /*
  223. * forward declaration for RPORT state machine
  224. */
  225. static void bfa_rport_sm_uninit(struct bfa_rport_s *rp,
  226. enum bfa_rport_event event);
  227. static void bfa_rport_sm_created(struct bfa_rport_s *rp,
  228. enum bfa_rport_event event);
  229. static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp,
  230. enum bfa_rport_event event);
  231. static void bfa_rport_sm_online(struct bfa_rport_s *rp,
  232. enum bfa_rport_event event);
  233. static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp,
  234. enum bfa_rport_event event);
  235. static void bfa_rport_sm_offline(struct bfa_rport_s *rp,
  236. enum bfa_rport_event event);
  237. static void bfa_rport_sm_deleting(struct bfa_rport_s *rp,
  238. enum bfa_rport_event event);
  239. static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  240. enum bfa_rport_event event);
  241. static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  242. enum bfa_rport_event event);
  243. static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp,
  244. enum bfa_rport_event event);
  245. static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp,
  246. enum bfa_rport_event event);
  247. static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp,
  248. enum bfa_rport_event event);
  249. static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp,
  250. enum bfa_rport_event event);
  251. /*
  252. * PLOG related definitions
  253. */
  254. static int
  255. plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
  256. {
  257. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  258. (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
  259. return 1;
  260. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) &&
  261. (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
  262. return 1;
  263. return 0;
  264. }
  265. static u64
  266. bfa_get_log_time(void)
  267. {
  268. u64 system_time = 0;
  269. struct timeval tv;
  270. do_gettimeofday(&tv);
  271. /* We are interested in seconds only. */
  272. system_time = tv.tv_sec;
  273. return system_time;
  274. }
  275. static void
  276. bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
  277. {
  278. u16 tail;
  279. struct bfa_plog_rec_s *pl_recp;
  280. if (plog->plog_enabled == 0)
  281. return;
  282. if (plkd_validate_logrec(pl_rec)) {
  283. WARN_ON(1);
  284. return;
  285. }
  286. tail = plog->tail;
  287. pl_recp = &(plog->plog_recs[tail]);
  288. memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
  289. pl_recp->tv = bfa_get_log_time();
  290. BFA_PL_LOG_REC_INCR(plog->tail);
  291. if (plog->head == plog->tail)
  292. BFA_PL_LOG_REC_INCR(plog->head);
  293. }
  294. void
  295. bfa_plog_init(struct bfa_plog_s *plog)
  296. {
  297. memset((char *)plog, 0, sizeof(struct bfa_plog_s));
  298. memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
  299. plog->head = plog->tail = 0;
  300. plog->plog_enabled = 1;
  301. }
  302. void
  303. bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  304. enum bfa_plog_eid event,
  305. u16 misc, char *log_str)
  306. {
  307. struct bfa_plog_rec_s lp;
  308. if (plog->plog_enabled) {
  309. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  310. lp.mid = mid;
  311. lp.eid = event;
  312. lp.log_type = BFA_PL_LOG_TYPE_STRING;
  313. lp.misc = misc;
  314. strncpy(lp.log_entry.string_log, log_str,
  315. BFA_PL_STRING_LOG_SZ - 1);
  316. lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
  317. bfa_plog_add(plog, &lp);
  318. }
  319. }
  320. void
  321. bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  322. enum bfa_plog_eid event,
  323. u16 misc, u32 *intarr, u32 num_ints)
  324. {
  325. struct bfa_plog_rec_s lp;
  326. u32 i;
  327. if (num_ints > BFA_PL_INT_LOG_SZ)
  328. num_ints = BFA_PL_INT_LOG_SZ;
  329. if (plog->plog_enabled) {
  330. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  331. lp.mid = mid;
  332. lp.eid = event;
  333. lp.log_type = BFA_PL_LOG_TYPE_INT;
  334. lp.misc = misc;
  335. for (i = 0; i < num_ints; i++)
  336. lp.log_entry.int_log[i] = intarr[i];
  337. lp.log_num_ints = (u8) num_ints;
  338. bfa_plog_add(plog, &lp);
  339. }
  340. }
  341. void
  342. bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  343. enum bfa_plog_eid event,
  344. u16 misc, struct fchs_s *fchdr)
  345. {
  346. struct bfa_plog_rec_s lp;
  347. u32 *tmp_int = (u32 *) fchdr;
  348. u32 ints[BFA_PL_INT_LOG_SZ];
  349. if (plog->plog_enabled) {
  350. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  351. ints[0] = tmp_int[0];
  352. ints[1] = tmp_int[1];
  353. ints[2] = tmp_int[4];
  354. bfa_plog_intarr(plog, mid, event, misc, ints, 3);
  355. }
  356. }
  357. void
  358. bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  359. enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  360. u32 pld_w0)
  361. {
  362. struct bfa_plog_rec_s lp;
  363. u32 *tmp_int = (u32 *) fchdr;
  364. u32 ints[BFA_PL_INT_LOG_SZ];
  365. if (plog->plog_enabled) {
  366. memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  367. ints[0] = tmp_int[0];
  368. ints[1] = tmp_int[1];
  369. ints[2] = tmp_int[4];
  370. ints[3] = pld_w0;
  371. bfa_plog_intarr(plog, mid, event, misc, ints, 4);
  372. }
  373. }
  374. /*
  375. * fcxp_pvt BFA FCXP private functions
  376. */
  377. static void
  378. claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
  379. {
  380. u8 *dm_kva = NULL;
  381. u64 dm_pa;
  382. u32 buf_pool_sz;
  383. dm_kva = bfa_meminfo_dma_virt(mi);
  384. dm_pa = bfa_meminfo_dma_phys(mi);
  385. buf_pool_sz = mod->req_pld_sz * mod->num_fcxps;
  386. /*
  387. * Initialize the fcxp req payload list
  388. */
  389. mod->req_pld_list_kva = dm_kva;
  390. mod->req_pld_list_pa = dm_pa;
  391. dm_kva += buf_pool_sz;
  392. dm_pa += buf_pool_sz;
  393. memset(mod->req_pld_list_kva, 0, buf_pool_sz);
  394. /*
  395. * Initialize the fcxp rsp payload list
  396. */
  397. buf_pool_sz = mod->rsp_pld_sz * mod->num_fcxps;
  398. mod->rsp_pld_list_kva = dm_kva;
  399. mod->rsp_pld_list_pa = dm_pa;
  400. dm_kva += buf_pool_sz;
  401. dm_pa += buf_pool_sz;
  402. memset(mod->rsp_pld_list_kva, 0, buf_pool_sz);
  403. bfa_meminfo_dma_virt(mi) = dm_kva;
  404. bfa_meminfo_dma_phys(mi) = dm_pa;
  405. }
  406. static void
  407. claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi)
  408. {
  409. u16 i;
  410. struct bfa_fcxp_s *fcxp;
  411. fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi);
  412. memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps);
  413. INIT_LIST_HEAD(&mod->fcxp_free_q);
  414. INIT_LIST_HEAD(&mod->fcxp_active_q);
  415. mod->fcxp_list = fcxp;
  416. for (i = 0; i < mod->num_fcxps; i++) {
  417. fcxp->fcxp_mod = mod;
  418. fcxp->fcxp_tag = i;
  419. list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
  420. bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp);
  421. fcxp->reqq_waiting = BFA_FALSE;
  422. fcxp = fcxp + 1;
  423. }
  424. bfa_meminfo_kva(mi) = (void *)fcxp;
  425. }
  426. static void
  427. bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  428. u32 *dm_len)
  429. {
  430. u16 num_fcxp_reqs = cfg->fwcfg.num_fcxp_reqs;
  431. if (num_fcxp_reqs == 0)
  432. return;
  433. /*
  434. * Account for req/rsp payload
  435. */
  436. *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
  437. if (cfg->drvcfg.min_cfg)
  438. *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs;
  439. else
  440. *dm_len += BFA_FCXP_MAX_LBUF_SZ * num_fcxp_reqs;
  441. /*
  442. * Account for fcxp structs
  443. */
  444. *ndm_len += sizeof(struct bfa_fcxp_s) * num_fcxp_reqs;
  445. }
  446. static void
  447. bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  448. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  449. {
  450. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  451. memset(mod, 0, sizeof(struct bfa_fcxp_mod_s));
  452. mod->bfa = bfa;
  453. mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs;
  454. /*
  455. * Initialize FCXP request and response payload sizes.
  456. */
  457. mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ;
  458. if (!cfg->drvcfg.min_cfg)
  459. mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ;
  460. INIT_LIST_HEAD(&mod->wait_q);
  461. claim_fcxp_req_rsp_mem(mod, meminfo);
  462. claim_fcxps_mem(mod, meminfo);
  463. }
  464. static void
  465. bfa_fcxp_detach(struct bfa_s *bfa)
  466. {
  467. }
  468. static void
  469. bfa_fcxp_start(struct bfa_s *bfa)
  470. {
  471. }
  472. static void
  473. bfa_fcxp_stop(struct bfa_s *bfa)
  474. {
  475. }
  476. static void
  477. bfa_fcxp_iocdisable(struct bfa_s *bfa)
  478. {
  479. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  480. struct bfa_fcxp_s *fcxp;
  481. struct list_head *qe, *qen;
  482. list_for_each_safe(qe, qen, &mod->fcxp_active_q) {
  483. fcxp = (struct bfa_fcxp_s *) qe;
  484. if (fcxp->caller == NULL) {
  485. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  486. BFA_STATUS_IOC_FAILURE, 0, 0, NULL);
  487. bfa_fcxp_free(fcxp);
  488. } else {
  489. fcxp->rsp_status = BFA_STATUS_IOC_FAILURE;
  490. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  491. __bfa_fcxp_send_cbfn, fcxp);
  492. }
  493. }
  494. }
  495. static struct bfa_fcxp_s *
  496. bfa_fcxp_get(struct bfa_fcxp_mod_s *fm)
  497. {
  498. struct bfa_fcxp_s *fcxp;
  499. bfa_q_deq(&fm->fcxp_free_q, &fcxp);
  500. if (fcxp)
  501. list_add_tail(&fcxp->qe, &fm->fcxp_active_q);
  502. return fcxp;
  503. }
  504. static void
  505. bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
  506. struct bfa_s *bfa,
  507. u8 *use_ibuf,
  508. u32 *nr_sgles,
  509. bfa_fcxp_get_sgaddr_t *r_sga_cbfn,
  510. bfa_fcxp_get_sglen_t *r_sglen_cbfn,
  511. struct list_head *r_sgpg_q,
  512. int n_sgles,
  513. bfa_fcxp_get_sgaddr_t sga_cbfn,
  514. bfa_fcxp_get_sglen_t sglen_cbfn)
  515. {
  516. WARN_ON(bfa == NULL);
  517. bfa_trc(bfa, fcxp->fcxp_tag);
  518. if (n_sgles == 0) {
  519. *use_ibuf = 1;
  520. } else {
  521. WARN_ON(*sga_cbfn == NULL);
  522. WARN_ON(*sglen_cbfn == NULL);
  523. *use_ibuf = 0;
  524. *r_sga_cbfn = sga_cbfn;
  525. *r_sglen_cbfn = sglen_cbfn;
  526. *nr_sgles = n_sgles;
  527. /*
  528. * alloc required sgpgs
  529. */
  530. if (n_sgles > BFI_SGE_INLINE)
  531. WARN_ON(1);
  532. }
  533. }
  534. static void
  535. bfa_fcxp_init(struct bfa_fcxp_s *fcxp,
  536. void *caller, struct bfa_s *bfa, int nreq_sgles,
  537. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  538. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  539. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  540. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  541. {
  542. WARN_ON(bfa == NULL);
  543. bfa_trc(bfa, fcxp->fcxp_tag);
  544. fcxp->caller = caller;
  545. bfa_fcxp_init_reqrsp(fcxp, bfa,
  546. &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn,
  547. &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q,
  548. nreq_sgles, req_sga_cbfn, req_sglen_cbfn);
  549. bfa_fcxp_init_reqrsp(fcxp, bfa,
  550. &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn,
  551. &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q,
  552. nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn);
  553. }
  554. static void
  555. bfa_fcxp_put(struct bfa_fcxp_s *fcxp)
  556. {
  557. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  558. struct bfa_fcxp_wqe_s *wqe;
  559. bfa_q_deq(&mod->wait_q, &wqe);
  560. if (wqe) {
  561. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  562. bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles,
  563. wqe->nrsp_sgles, wqe->req_sga_cbfn,
  564. wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn,
  565. wqe->rsp_sglen_cbfn);
  566. wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp);
  567. return;
  568. }
  569. WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp));
  570. list_del(&fcxp->qe);
  571. list_add_tail(&fcxp->qe, &mod->fcxp_free_q);
  572. }
  573. static void
  574. bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  575. bfa_status_t req_status, u32 rsp_len,
  576. u32 resid_len, struct fchs_s *rsp_fchs)
  577. {
  578. /* discarded fcxp completion */
  579. }
  580. static void
  581. __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete)
  582. {
  583. struct bfa_fcxp_s *fcxp = cbarg;
  584. if (complete) {
  585. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  586. fcxp->rsp_status, fcxp->rsp_len,
  587. fcxp->residue_len, &fcxp->rsp_fchs);
  588. } else {
  589. bfa_fcxp_free(fcxp);
  590. }
  591. }
  592. static void
  593. hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  594. {
  595. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  596. struct bfa_fcxp_s *fcxp;
  597. u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag);
  598. bfa_trc(bfa, fcxp_tag);
  599. fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len);
  600. /*
  601. * @todo f/w should not set residue to non-0 when everything
  602. * is received.
  603. */
  604. if (fcxp_rsp->req_status == BFA_STATUS_OK)
  605. fcxp_rsp->residue_len = 0;
  606. else
  607. fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len);
  608. fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag);
  609. WARN_ON(fcxp->send_cbfn == NULL);
  610. hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp);
  611. if (fcxp->send_cbfn != NULL) {
  612. bfa_trc(mod->bfa, (NULL == fcxp->caller));
  613. if (fcxp->caller == NULL) {
  614. fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg,
  615. fcxp_rsp->req_status, fcxp_rsp->rsp_len,
  616. fcxp_rsp->residue_len, &fcxp_rsp->fchs);
  617. /*
  618. * fcxp automatically freed on return from the callback
  619. */
  620. bfa_fcxp_free(fcxp);
  621. } else {
  622. fcxp->rsp_status = fcxp_rsp->req_status;
  623. fcxp->rsp_len = fcxp_rsp->rsp_len;
  624. fcxp->residue_len = fcxp_rsp->residue_len;
  625. fcxp->rsp_fchs = fcxp_rsp->fchs;
  626. bfa_cb_queue(bfa, &fcxp->hcb_qe,
  627. __bfa_fcxp_send_cbfn, fcxp);
  628. }
  629. } else {
  630. bfa_trc(bfa, (NULL == fcxp->send_cbfn));
  631. }
  632. }
  633. static void
  634. hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp,
  635. struct fchs_s *fchs)
  636. {
  637. /*
  638. * TODO: TX ox_id
  639. */
  640. if (reqlen > 0) {
  641. if (fcxp->use_ireqbuf) {
  642. u32 pld_w0 =
  643. *((u32 *) BFA_FCXP_REQ_PLD(fcxp));
  644. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  645. BFA_PL_EID_TX,
  646. reqlen + sizeof(struct fchs_s), fchs,
  647. pld_w0);
  648. } else {
  649. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  650. BFA_PL_EID_TX,
  651. reqlen + sizeof(struct fchs_s),
  652. fchs);
  653. }
  654. } else {
  655. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX,
  656. reqlen + sizeof(struct fchs_s), fchs);
  657. }
  658. }
  659. static void
  660. hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp,
  661. struct bfi_fcxp_send_rsp_s *fcxp_rsp)
  662. {
  663. if (fcxp_rsp->rsp_len > 0) {
  664. if (fcxp->use_irspbuf) {
  665. u32 pld_w0 =
  666. *((u32 *) BFA_FCXP_RSP_PLD(fcxp));
  667. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP,
  668. BFA_PL_EID_RX,
  669. (u16) fcxp_rsp->rsp_len,
  670. &fcxp_rsp->fchs, pld_w0);
  671. } else {
  672. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP,
  673. BFA_PL_EID_RX,
  674. (u16) fcxp_rsp->rsp_len,
  675. &fcxp_rsp->fchs);
  676. }
  677. } else {
  678. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX,
  679. (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs);
  680. }
  681. }
  682. /*
  683. * Handler to resume sending fcxp when space in available in cpe queue.
  684. */
  685. static void
  686. bfa_fcxp_qresume(void *cbarg)
  687. {
  688. struct bfa_fcxp_s *fcxp = cbarg;
  689. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  690. struct bfi_fcxp_send_req_s *send_req;
  691. fcxp->reqq_waiting = BFA_FALSE;
  692. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  693. bfa_fcxp_queue(fcxp, send_req);
  694. }
  695. /*
  696. * Queue fcxp send request to foimrware.
  697. */
  698. static void
  699. bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req)
  700. {
  701. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  702. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  703. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  704. struct bfa_rport_s *rport = reqi->bfa_rport;
  705. bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ,
  706. bfa_lpuid(bfa));
  707. send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag);
  708. if (rport) {
  709. send_req->rport_fw_hndl = rport->fw_handle;
  710. send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz);
  711. if (send_req->max_frmsz == 0)
  712. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  713. } else {
  714. send_req->rport_fw_hndl = 0;
  715. send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ);
  716. }
  717. send_req->vf_id = cpu_to_be16(reqi->vf_id);
  718. send_req->lp_tag = reqi->lp_tag;
  719. send_req->class = reqi->class;
  720. send_req->rsp_timeout = rspi->rsp_timeout;
  721. send_req->cts = reqi->cts;
  722. send_req->fchs = reqi->fchs;
  723. send_req->req_len = cpu_to_be32(reqi->req_tot_len);
  724. send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen);
  725. /*
  726. * setup req sgles
  727. */
  728. if (fcxp->use_ireqbuf == 1) {
  729. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  730. BFA_FCXP_REQ_PLD_PA(fcxp));
  731. } else {
  732. if (fcxp->nreq_sgles > 0) {
  733. WARN_ON(fcxp->nreq_sgles != 1);
  734. bfa_alen_set(&send_req->req_alen, reqi->req_tot_len,
  735. fcxp->req_sga_cbfn(fcxp->caller, 0));
  736. } else {
  737. WARN_ON(reqi->req_tot_len != 0);
  738. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  739. }
  740. }
  741. /*
  742. * setup rsp sgles
  743. */
  744. if (fcxp->use_irspbuf == 1) {
  745. WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ);
  746. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  747. BFA_FCXP_RSP_PLD_PA(fcxp));
  748. } else {
  749. if (fcxp->nrsp_sgles > 0) {
  750. WARN_ON(fcxp->nrsp_sgles != 1);
  751. bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen,
  752. fcxp->rsp_sga_cbfn(fcxp->caller, 0));
  753. } else {
  754. WARN_ON(rspi->rsp_maxlen != 0);
  755. bfa_alen_set(&send_req->rsp_alen, 0, 0);
  756. }
  757. }
  758. hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs);
  759. bfa_reqq_produce(bfa, BFA_REQQ_FCXP);
  760. bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP));
  761. bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP));
  762. }
  763. /*
  764. * Allocate an FCXP instance to send a response or to send a request
  765. * that has a response. Request/response buffers are allocated by caller.
  766. *
  767. * @param[in] bfa BFA bfa instance
  768. * @param[in] nreq_sgles Number of SG elements required for request
  769. * buffer. 0, if fcxp internal buffers are used.
  770. * Use bfa_fcxp_get_reqbuf() to get the
  771. * internal req buffer.
  772. * @param[in] req_sgles SG elements describing request buffer. Will be
  773. * copied in by BFA and hence can be freed on
  774. * return from this function.
  775. * @param[in] get_req_sga function ptr to be called to get a request SG
  776. * Address (given the sge index).
  777. * @param[in] get_req_sglen function ptr to be called to get a request SG
  778. * len (given the sge index).
  779. * @param[in] get_rsp_sga function ptr to be called to get a response SG
  780. * Address (given the sge index).
  781. * @param[in] get_rsp_sglen function ptr to be called to get a response SG
  782. * len (given the sge index).
  783. *
  784. * @return FCXP instance. NULL on failure.
  785. */
  786. struct bfa_fcxp_s *
  787. bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles,
  788. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  789. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  790. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  791. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  792. {
  793. struct bfa_fcxp_s *fcxp = NULL;
  794. WARN_ON(bfa == NULL);
  795. fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa));
  796. if (fcxp == NULL)
  797. return NULL;
  798. bfa_trc(bfa, fcxp->fcxp_tag);
  799. bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn,
  800. req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn);
  801. return fcxp;
  802. }
  803. /*
  804. * Get the internal request buffer pointer
  805. *
  806. * @param[in] fcxp BFA fcxp pointer
  807. *
  808. * @return pointer to the internal request buffer
  809. */
  810. void *
  811. bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp)
  812. {
  813. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  814. void *reqbuf;
  815. WARN_ON(fcxp->use_ireqbuf != 1);
  816. reqbuf = ((u8 *)mod->req_pld_list_kva) +
  817. fcxp->fcxp_tag * mod->req_pld_sz;
  818. return reqbuf;
  819. }
  820. u32
  821. bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp)
  822. {
  823. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  824. return mod->req_pld_sz;
  825. }
  826. /*
  827. * Get the internal response buffer pointer
  828. *
  829. * @param[in] fcxp BFA fcxp pointer
  830. *
  831. * @return pointer to the internal request buffer
  832. */
  833. void *
  834. bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp)
  835. {
  836. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  837. void *rspbuf;
  838. WARN_ON(fcxp->use_irspbuf != 1);
  839. rspbuf = ((u8 *)mod->rsp_pld_list_kva) +
  840. fcxp->fcxp_tag * mod->rsp_pld_sz;
  841. return rspbuf;
  842. }
  843. /*
  844. * Free the BFA FCXP
  845. *
  846. * @param[in] fcxp BFA fcxp pointer
  847. *
  848. * @return void
  849. */
  850. void
  851. bfa_fcxp_free(struct bfa_fcxp_s *fcxp)
  852. {
  853. struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod;
  854. WARN_ON(fcxp == NULL);
  855. bfa_trc(mod->bfa, fcxp->fcxp_tag);
  856. bfa_fcxp_put(fcxp);
  857. }
  858. /*
  859. * Send a FCXP request
  860. *
  861. * @param[in] fcxp BFA fcxp pointer
  862. * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
  863. * @param[in] vf_id virtual Fabric ID
  864. * @param[in] lp_tag lport tag
  865. * @param[in] cts use Continuous sequence
  866. * @param[in] cos fc Class of Service
  867. * @param[in] reqlen request length, does not include FCHS length
  868. * @param[in] fchs fc Header Pointer. The header content will be copied
  869. * in by BFA.
  870. *
  871. * @param[in] cbfn call back function to be called on receiving
  872. * the response
  873. * @param[in] cbarg arg for cbfn
  874. * @param[in] rsp_timeout
  875. * response timeout
  876. *
  877. * @return bfa_status_t
  878. */
  879. void
  880. bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
  881. u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos,
  882. u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn,
  883. void *cbarg, u32 rsp_maxlen, u8 rsp_timeout)
  884. {
  885. struct bfa_s *bfa = fcxp->fcxp_mod->bfa;
  886. struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info;
  887. struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info;
  888. struct bfi_fcxp_send_req_s *send_req;
  889. bfa_trc(bfa, fcxp->fcxp_tag);
  890. /*
  891. * setup request/response info
  892. */
  893. reqi->bfa_rport = rport;
  894. reqi->vf_id = vf_id;
  895. reqi->lp_tag = lp_tag;
  896. reqi->class = cos;
  897. rspi->rsp_timeout = rsp_timeout;
  898. reqi->cts = cts;
  899. reqi->fchs = *fchs;
  900. reqi->req_tot_len = reqlen;
  901. rspi->rsp_maxlen = rsp_maxlen;
  902. fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp;
  903. fcxp->send_cbarg = cbarg;
  904. /*
  905. * If no room in CPE queue, wait for space in request queue
  906. */
  907. send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP);
  908. if (!send_req) {
  909. bfa_trc(bfa, fcxp->fcxp_tag);
  910. fcxp->reqq_waiting = BFA_TRUE;
  911. bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe);
  912. return;
  913. }
  914. bfa_fcxp_queue(fcxp, send_req);
  915. }
  916. /*
  917. * Abort a BFA FCXP
  918. *
  919. * @param[in] fcxp BFA fcxp pointer
  920. *
  921. * @return void
  922. */
  923. bfa_status_t
  924. bfa_fcxp_abort(struct bfa_fcxp_s *fcxp)
  925. {
  926. bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag);
  927. WARN_ON(1);
  928. return BFA_STATUS_OK;
  929. }
  930. void
  931. bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
  932. bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg,
  933. void *caller, int nreq_sgles,
  934. int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn,
  935. bfa_fcxp_get_sglen_t req_sglen_cbfn,
  936. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn,
  937. bfa_fcxp_get_sglen_t rsp_sglen_cbfn)
  938. {
  939. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  940. WARN_ON(!list_empty(&mod->fcxp_free_q));
  941. wqe->alloc_cbfn = alloc_cbfn;
  942. wqe->alloc_cbarg = alloc_cbarg;
  943. wqe->caller = caller;
  944. wqe->bfa = bfa;
  945. wqe->nreq_sgles = nreq_sgles;
  946. wqe->nrsp_sgles = nrsp_sgles;
  947. wqe->req_sga_cbfn = req_sga_cbfn;
  948. wqe->req_sglen_cbfn = req_sglen_cbfn;
  949. wqe->rsp_sga_cbfn = rsp_sga_cbfn;
  950. wqe->rsp_sglen_cbfn = rsp_sglen_cbfn;
  951. list_add_tail(&wqe->qe, &mod->wait_q);
  952. }
  953. void
  954. bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe)
  955. {
  956. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  957. WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe));
  958. list_del(&wqe->qe);
  959. }
  960. void
  961. bfa_fcxp_discard(struct bfa_fcxp_s *fcxp)
  962. {
  963. /*
  964. * If waiting for room in request queue, cancel reqq wait
  965. * and free fcxp.
  966. */
  967. if (fcxp->reqq_waiting) {
  968. fcxp->reqq_waiting = BFA_FALSE;
  969. bfa_reqq_wcancel(&fcxp->reqq_wqe);
  970. bfa_fcxp_free(fcxp);
  971. return;
  972. }
  973. fcxp->send_cbfn = bfa_fcxp_null_comp;
  974. }
  975. void
  976. bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  977. {
  978. switch (msg->mhdr.msg_id) {
  979. case BFI_FCXP_I2H_SEND_RSP:
  980. hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg);
  981. break;
  982. default:
  983. bfa_trc(bfa, msg->mhdr.msg_id);
  984. WARN_ON(1);
  985. }
  986. }
  987. u32
  988. bfa_fcxp_get_maxrsp(struct bfa_s *bfa)
  989. {
  990. struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa);
  991. return mod->rsp_pld_sz;
  992. }
  993. /*
  994. * BFA LPS state machine functions
  995. */
  996. /*
  997. * Init state -- no login
  998. */
  999. static void
  1000. bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1001. {
  1002. bfa_trc(lps->bfa, lps->lp_tag);
  1003. bfa_trc(lps->bfa, event);
  1004. switch (event) {
  1005. case BFA_LPS_SM_LOGIN:
  1006. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1007. bfa_sm_set_state(lps, bfa_lps_sm_loginwait);
  1008. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1009. } else {
  1010. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1011. bfa_lps_send_login(lps);
  1012. }
  1013. if (lps->fdisc)
  1014. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1015. BFA_PL_EID_LOGIN, 0, "FDISC Request");
  1016. else
  1017. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1018. BFA_PL_EID_LOGIN, 0, "FLOGI Request");
  1019. break;
  1020. case BFA_LPS_SM_LOGOUT:
  1021. bfa_lps_logout_comp(lps);
  1022. break;
  1023. case BFA_LPS_SM_DELETE:
  1024. bfa_lps_free(lps);
  1025. break;
  1026. case BFA_LPS_SM_RX_CVL:
  1027. case BFA_LPS_SM_OFFLINE:
  1028. break;
  1029. case BFA_LPS_SM_FWRSP:
  1030. /*
  1031. * Could happen when fabric detects loopback and discards
  1032. * the lps request. Fw will eventually sent out the timeout
  1033. * Just ignore
  1034. */
  1035. break;
  1036. default:
  1037. bfa_sm_fault(lps->bfa, event);
  1038. }
  1039. }
  1040. /*
  1041. * login is in progress -- awaiting response from firmware
  1042. */
  1043. static void
  1044. bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1045. {
  1046. bfa_trc(lps->bfa, lps->lp_tag);
  1047. bfa_trc(lps->bfa, event);
  1048. switch (event) {
  1049. case BFA_LPS_SM_FWRSP:
  1050. if (lps->status == BFA_STATUS_OK) {
  1051. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1052. if (lps->fdisc)
  1053. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1054. BFA_PL_EID_LOGIN, 0, "FDISC Accept");
  1055. else
  1056. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1057. BFA_PL_EID_LOGIN, 0, "FLOGI Accept");
  1058. /* If N2N, send the assigned PID to FW */
  1059. bfa_trc(lps->bfa, lps->fport);
  1060. bfa_trc(lps->bfa, lps->lp_pid);
  1061. if (!lps->fport && lps->lp_pid)
  1062. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1063. } else {
  1064. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1065. if (lps->fdisc)
  1066. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1067. BFA_PL_EID_LOGIN, 0,
  1068. "FDISC Fail (RJT or timeout)");
  1069. else
  1070. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1071. BFA_PL_EID_LOGIN, 0,
  1072. "FLOGI Fail (RJT or timeout)");
  1073. }
  1074. bfa_lps_login_comp(lps);
  1075. break;
  1076. case BFA_LPS_SM_OFFLINE:
  1077. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1078. break;
  1079. case BFA_LPS_SM_SET_N2N_PID:
  1080. bfa_trc(lps->bfa, lps->fport);
  1081. bfa_trc(lps->bfa, lps->lp_pid);
  1082. break;
  1083. default:
  1084. bfa_sm_fault(lps->bfa, event);
  1085. }
  1086. }
  1087. /*
  1088. * login pending - awaiting space in request queue
  1089. */
  1090. static void
  1091. bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1092. {
  1093. bfa_trc(lps->bfa, lps->lp_tag);
  1094. bfa_trc(lps->bfa, event);
  1095. switch (event) {
  1096. case BFA_LPS_SM_RESUME:
  1097. bfa_sm_set_state(lps, bfa_lps_sm_login);
  1098. break;
  1099. case BFA_LPS_SM_OFFLINE:
  1100. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1101. bfa_reqq_wcancel(&lps->wqe);
  1102. break;
  1103. case BFA_LPS_SM_RX_CVL:
  1104. /*
  1105. * Login was not even sent out; so when getting out
  1106. * of this state, it will appear like a login retry
  1107. * after Clear virtual link
  1108. */
  1109. break;
  1110. default:
  1111. bfa_sm_fault(lps->bfa, event);
  1112. }
  1113. }
  1114. /*
  1115. * login complete
  1116. */
  1117. static void
  1118. bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1119. {
  1120. bfa_trc(lps->bfa, lps->lp_tag);
  1121. bfa_trc(lps->bfa, event);
  1122. switch (event) {
  1123. case BFA_LPS_SM_LOGOUT:
  1124. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1125. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1126. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1127. } else {
  1128. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1129. bfa_lps_send_logout(lps);
  1130. }
  1131. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1132. BFA_PL_EID_LOGO, 0, "Logout");
  1133. break;
  1134. case BFA_LPS_SM_RX_CVL:
  1135. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1136. /* Let the vport module know about this event */
  1137. bfa_lps_cvl_event(lps);
  1138. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1139. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1140. break;
  1141. case BFA_LPS_SM_SET_N2N_PID:
  1142. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1143. bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
  1144. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1145. } else
  1146. bfa_lps_send_set_n2n_pid(lps);
  1147. break;
  1148. case BFA_LPS_SM_OFFLINE:
  1149. case BFA_LPS_SM_DELETE:
  1150. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1151. break;
  1152. default:
  1153. bfa_sm_fault(lps->bfa, event);
  1154. }
  1155. }
  1156. /*
  1157. * login complete
  1158. */
  1159. static void
  1160. bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1161. {
  1162. bfa_trc(lps->bfa, lps->lp_tag);
  1163. bfa_trc(lps->bfa, event);
  1164. switch (event) {
  1165. case BFA_LPS_SM_RESUME:
  1166. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1167. bfa_lps_send_set_n2n_pid(lps);
  1168. break;
  1169. case BFA_LPS_SM_LOGOUT:
  1170. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1171. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1172. BFA_PL_EID_LOGO, 0, "Logout");
  1173. break;
  1174. case BFA_LPS_SM_RX_CVL:
  1175. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1176. bfa_reqq_wcancel(&lps->wqe);
  1177. /* Let the vport module know about this event */
  1178. bfa_lps_cvl_event(lps);
  1179. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1180. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1181. break;
  1182. case BFA_LPS_SM_OFFLINE:
  1183. case BFA_LPS_SM_DELETE:
  1184. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1185. bfa_reqq_wcancel(&lps->wqe);
  1186. break;
  1187. default:
  1188. bfa_sm_fault(lps->bfa, event);
  1189. }
  1190. }
  1191. /*
  1192. * logout in progress - awaiting firmware response
  1193. */
  1194. static void
  1195. bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1196. {
  1197. bfa_trc(lps->bfa, lps->lp_tag);
  1198. bfa_trc(lps->bfa, event);
  1199. switch (event) {
  1200. case BFA_LPS_SM_FWRSP:
  1201. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1202. bfa_lps_logout_comp(lps);
  1203. break;
  1204. case BFA_LPS_SM_OFFLINE:
  1205. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1206. break;
  1207. default:
  1208. bfa_sm_fault(lps->bfa, event);
  1209. }
  1210. }
  1211. /*
  1212. * logout pending -- awaiting space in request queue
  1213. */
  1214. static void
  1215. bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1216. {
  1217. bfa_trc(lps->bfa, lps->lp_tag);
  1218. bfa_trc(lps->bfa, event);
  1219. switch (event) {
  1220. case BFA_LPS_SM_RESUME:
  1221. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1222. bfa_lps_send_logout(lps);
  1223. break;
  1224. case BFA_LPS_SM_OFFLINE:
  1225. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1226. bfa_reqq_wcancel(&lps->wqe);
  1227. break;
  1228. default:
  1229. bfa_sm_fault(lps->bfa, event);
  1230. }
  1231. }
  1232. /*
  1233. * lps_pvt BFA LPS private functions
  1234. */
  1235. /*
  1236. * return memory requirement
  1237. */
  1238. static void
  1239. bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  1240. u32 *dm_len)
  1241. {
  1242. if (cfg->drvcfg.min_cfg)
  1243. *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS;
  1244. else
  1245. *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS;
  1246. }
  1247. /*
  1248. * bfa module attach at initialization time
  1249. */
  1250. static void
  1251. bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1252. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  1253. {
  1254. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1255. struct bfa_lps_s *lps;
  1256. int i;
  1257. memset(mod, 0, sizeof(struct bfa_lps_mod_s));
  1258. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1259. if (cfg->drvcfg.min_cfg)
  1260. mod->num_lps = BFA_LPS_MIN_LPORTS;
  1261. else
  1262. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1263. mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo);
  1264. bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s);
  1265. INIT_LIST_HEAD(&mod->lps_free_q);
  1266. INIT_LIST_HEAD(&mod->lps_active_q);
  1267. for (i = 0; i < mod->num_lps; i++, lps++) {
  1268. lps->bfa = bfa;
  1269. lps->lp_tag = (u8) i;
  1270. lps->reqq = BFA_REQQ_LPS;
  1271. bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
  1272. list_add_tail(&lps->qe, &mod->lps_free_q);
  1273. }
  1274. }
  1275. static void
  1276. bfa_lps_detach(struct bfa_s *bfa)
  1277. {
  1278. }
  1279. static void
  1280. bfa_lps_start(struct bfa_s *bfa)
  1281. {
  1282. }
  1283. static void
  1284. bfa_lps_stop(struct bfa_s *bfa)
  1285. {
  1286. }
  1287. /*
  1288. * IOC in disabled state -- consider all lps offline
  1289. */
  1290. static void
  1291. bfa_lps_iocdisable(struct bfa_s *bfa)
  1292. {
  1293. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1294. struct bfa_lps_s *lps;
  1295. struct list_head *qe, *qen;
  1296. list_for_each_safe(qe, qen, &mod->lps_active_q) {
  1297. lps = (struct bfa_lps_s *) qe;
  1298. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1299. }
  1300. }
  1301. /*
  1302. * Firmware login response
  1303. */
  1304. static void
  1305. bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
  1306. {
  1307. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1308. struct bfa_lps_s *lps;
  1309. WARN_ON(rsp->lp_tag >= mod->num_lps);
  1310. lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
  1311. lps->status = rsp->status;
  1312. switch (rsp->status) {
  1313. case BFA_STATUS_OK:
  1314. lps->fport = rsp->f_port;
  1315. if (lps->fport)
  1316. lps->lp_pid = rsp->lp_pid;
  1317. lps->npiv_en = rsp->npiv_en;
  1318. lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
  1319. lps->pr_pwwn = rsp->port_name;
  1320. lps->pr_nwwn = rsp->node_name;
  1321. lps->auth_req = rsp->auth_req;
  1322. lps->lp_mac = rsp->lp_mac;
  1323. lps->brcd_switch = rsp->brcd_switch;
  1324. lps->fcf_mac = rsp->fcf_mac;
  1325. break;
  1326. case BFA_STATUS_FABRIC_RJT:
  1327. lps->lsrjt_rsn = rsp->lsrjt_rsn;
  1328. lps->lsrjt_expl = rsp->lsrjt_expl;
  1329. break;
  1330. case BFA_STATUS_EPROTOCOL:
  1331. lps->ext_status = rsp->ext_status;
  1332. break;
  1333. default:
  1334. /* Nothing to do with other status */
  1335. break;
  1336. }
  1337. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1338. }
  1339. /*
  1340. * Firmware logout response
  1341. */
  1342. static void
  1343. bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
  1344. {
  1345. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1346. struct bfa_lps_s *lps;
  1347. WARN_ON(rsp->lp_tag >= mod->num_lps);
  1348. lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag);
  1349. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1350. }
  1351. /*
  1352. * Firmware received a Clear virtual link request (for FCoE)
  1353. */
  1354. static void
  1355. bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
  1356. {
  1357. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1358. struct bfa_lps_s *lps;
  1359. lps = BFA_LPS_FROM_TAG(mod, cvl->lp_tag);
  1360. bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
  1361. }
  1362. /*
  1363. * Space is available in request queue, resume queueing request to firmware.
  1364. */
  1365. static void
  1366. bfa_lps_reqq_resume(void *lps_arg)
  1367. {
  1368. struct bfa_lps_s *lps = lps_arg;
  1369. bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
  1370. }
  1371. /*
  1372. * lps is freed -- triggered by vport delete
  1373. */
  1374. static void
  1375. bfa_lps_free(struct bfa_lps_s *lps)
  1376. {
  1377. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1378. lps->lp_pid = 0;
  1379. list_del(&lps->qe);
  1380. list_add_tail(&lps->qe, &mod->lps_free_q);
  1381. }
  1382. /*
  1383. * send login request to firmware
  1384. */
  1385. static void
  1386. bfa_lps_send_login(struct bfa_lps_s *lps)
  1387. {
  1388. struct bfi_lps_login_req_s *m;
  1389. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1390. WARN_ON(!m);
  1391. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
  1392. bfa_lpuid(lps->bfa));
  1393. m->lp_tag = lps->lp_tag;
  1394. m->alpa = lps->alpa;
  1395. m->pdu_size = cpu_to_be16(lps->pdusz);
  1396. m->pwwn = lps->pwwn;
  1397. m->nwwn = lps->nwwn;
  1398. m->fdisc = lps->fdisc;
  1399. m->auth_en = lps->auth_en;
  1400. bfa_reqq_produce(lps->bfa, lps->reqq);
  1401. }
  1402. /*
  1403. * send logout request to firmware
  1404. */
  1405. static void
  1406. bfa_lps_send_logout(struct bfa_lps_s *lps)
  1407. {
  1408. struct bfi_lps_logout_req_s *m;
  1409. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1410. WARN_ON(!m);
  1411. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
  1412. bfa_lpuid(lps->bfa));
  1413. m->lp_tag = lps->lp_tag;
  1414. m->port_name = lps->pwwn;
  1415. bfa_reqq_produce(lps->bfa, lps->reqq);
  1416. }
  1417. /*
  1418. * send n2n pid set request to firmware
  1419. */
  1420. static void
  1421. bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
  1422. {
  1423. struct bfi_lps_n2n_pid_req_s *m;
  1424. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1425. WARN_ON(!m);
  1426. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
  1427. bfa_lpuid(lps->bfa));
  1428. m->lp_tag = lps->lp_tag;
  1429. m->lp_pid = lps->lp_pid;
  1430. bfa_reqq_produce(lps->bfa, lps->reqq);
  1431. }
  1432. /*
  1433. * Indirect login completion handler for non-fcs
  1434. */
  1435. static void
  1436. bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
  1437. {
  1438. struct bfa_lps_s *lps = arg;
  1439. if (!complete)
  1440. return;
  1441. if (lps->fdisc)
  1442. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1443. else
  1444. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1445. }
  1446. /*
  1447. * Login completion handler -- direct call for fcs, queue for others
  1448. */
  1449. static void
  1450. bfa_lps_login_comp(struct bfa_lps_s *lps)
  1451. {
  1452. if (!lps->bfa->fcs) {
  1453. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
  1454. lps);
  1455. return;
  1456. }
  1457. if (lps->fdisc)
  1458. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1459. else
  1460. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1461. }
  1462. /*
  1463. * Indirect logout completion handler for non-fcs
  1464. */
  1465. static void
  1466. bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
  1467. {
  1468. struct bfa_lps_s *lps = arg;
  1469. if (!complete)
  1470. return;
  1471. if (lps->fdisc)
  1472. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1473. }
  1474. /*
  1475. * Logout completion handler -- direct call for fcs, queue for others
  1476. */
  1477. static void
  1478. bfa_lps_logout_comp(struct bfa_lps_s *lps)
  1479. {
  1480. if (!lps->bfa->fcs) {
  1481. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
  1482. lps);
  1483. return;
  1484. }
  1485. if (lps->fdisc)
  1486. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1487. }
  1488. /*
  1489. * Clear virtual link completion handler for non-fcs
  1490. */
  1491. static void
  1492. bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
  1493. {
  1494. struct bfa_lps_s *lps = arg;
  1495. if (!complete)
  1496. return;
  1497. /* Clear virtual link to base port will result in link down */
  1498. if (lps->fdisc)
  1499. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1500. }
  1501. /*
  1502. * Received Clear virtual link event --direct call for fcs,
  1503. * queue for others
  1504. */
  1505. static void
  1506. bfa_lps_cvl_event(struct bfa_lps_s *lps)
  1507. {
  1508. if (!lps->bfa->fcs) {
  1509. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
  1510. lps);
  1511. return;
  1512. }
  1513. /* Clear virtual link to base port will result in link down */
  1514. if (lps->fdisc)
  1515. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1516. }
  1517. /*
  1518. * lps_public BFA LPS public functions
  1519. */
  1520. u32
  1521. bfa_lps_get_max_vport(struct bfa_s *bfa)
  1522. {
  1523. if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
  1524. return BFA_LPS_MAX_VPORTS_SUPP_CT;
  1525. else
  1526. return BFA_LPS_MAX_VPORTS_SUPP_CB;
  1527. }
  1528. /*
  1529. * Allocate a lport srvice tag.
  1530. */
  1531. struct bfa_lps_s *
  1532. bfa_lps_alloc(struct bfa_s *bfa)
  1533. {
  1534. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1535. struct bfa_lps_s *lps = NULL;
  1536. bfa_q_deq(&mod->lps_free_q, &lps);
  1537. if (lps == NULL)
  1538. return NULL;
  1539. list_add_tail(&lps->qe, &mod->lps_active_q);
  1540. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1541. return lps;
  1542. }
  1543. /*
  1544. * Free lport service tag. This can be called anytime after an alloc.
  1545. * No need to wait for any pending login/logout completions.
  1546. */
  1547. void
  1548. bfa_lps_delete(struct bfa_lps_s *lps)
  1549. {
  1550. bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
  1551. }
  1552. /*
  1553. * Initiate a lport login.
  1554. */
  1555. void
  1556. bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
  1557. wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en)
  1558. {
  1559. lps->uarg = uarg;
  1560. lps->alpa = alpa;
  1561. lps->pdusz = pdusz;
  1562. lps->pwwn = pwwn;
  1563. lps->nwwn = nwwn;
  1564. lps->fdisc = BFA_FALSE;
  1565. lps->auth_en = auth_en;
  1566. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1567. }
  1568. /*
  1569. * Initiate a lport fdisc login.
  1570. */
  1571. void
  1572. bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
  1573. wwn_t nwwn)
  1574. {
  1575. lps->uarg = uarg;
  1576. lps->alpa = 0;
  1577. lps->pdusz = pdusz;
  1578. lps->pwwn = pwwn;
  1579. lps->nwwn = nwwn;
  1580. lps->fdisc = BFA_TRUE;
  1581. lps->auth_en = BFA_FALSE;
  1582. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1583. }
  1584. /*
  1585. * Initiate a lport FDSIC logout.
  1586. */
  1587. void
  1588. bfa_lps_fdisclogo(struct bfa_lps_s *lps)
  1589. {
  1590. bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
  1591. }
  1592. /*
  1593. * Return lport services tag given the pid
  1594. */
  1595. u8
  1596. bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
  1597. {
  1598. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1599. struct bfa_lps_s *lps;
  1600. int i;
  1601. for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
  1602. if (lps->lp_pid == pid)
  1603. return lps->lp_tag;
  1604. }
  1605. /* Return base port tag anyway */
  1606. return 0;
  1607. }
  1608. /*
  1609. * return port id assigned to the base lport
  1610. */
  1611. u32
  1612. bfa_lps_get_base_pid(struct bfa_s *bfa)
  1613. {
  1614. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1615. return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
  1616. }
  1617. /*
  1618. * Set PID in case of n2n (which is assigned during PLOGI)
  1619. */
  1620. void
  1621. bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
  1622. {
  1623. bfa_trc(lps->bfa, lps->lp_tag);
  1624. bfa_trc(lps->bfa, n2n_pid);
  1625. lps->lp_pid = n2n_pid;
  1626. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1627. }
  1628. /*
  1629. * LPS firmware message class handler.
  1630. */
  1631. void
  1632. bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  1633. {
  1634. union bfi_lps_i2h_msg_u msg;
  1635. bfa_trc(bfa, m->mhdr.msg_id);
  1636. msg.msg = m;
  1637. switch (m->mhdr.msg_id) {
  1638. case BFI_LPS_I2H_LOGIN_RSP:
  1639. bfa_lps_login_rsp(bfa, msg.login_rsp);
  1640. break;
  1641. case BFI_LPS_I2H_LOGOUT_RSP:
  1642. bfa_lps_logout_rsp(bfa, msg.logout_rsp);
  1643. break;
  1644. case BFI_LPS_I2H_CVL_EVENT:
  1645. bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
  1646. break;
  1647. default:
  1648. bfa_trc(bfa, m->mhdr.msg_id);
  1649. WARN_ON(1);
  1650. }
  1651. }
  1652. /*
  1653. * FC PORT state machine functions
  1654. */
  1655. static void
  1656. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  1657. enum bfa_fcport_sm_event event)
  1658. {
  1659. bfa_trc(fcport->bfa, event);
  1660. switch (event) {
  1661. case BFA_FCPORT_SM_START:
  1662. /*
  1663. * Start event after IOC is configured and BFA is started.
  1664. */
  1665. fcport->use_flash_cfg = BFA_TRUE;
  1666. if (bfa_fcport_send_enable(fcport)) {
  1667. bfa_trc(fcport->bfa, BFA_TRUE);
  1668. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1669. } else {
  1670. bfa_trc(fcport->bfa, BFA_FALSE);
  1671. bfa_sm_set_state(fcport,
  1672. bfa_fcport_sm_enabling_qwait);
  1673. }
  1674. break;
  1675. case BFA_FCPORT_SM_ENABLE:
  1676. /*
  1677. * Port is persistently configured to be in enabled state. Do
  1678. * not change state. Port enabling is done when START event is
  1679. * received.
  1680. */
  1681. break;
  1682. case BFA_FCPORT_SM_DISABLE:
  1683. /*
  1684. * If a port is persistently configured to be disabled, the
  1685. * first event will a port disable request.
  1686. */
  1687. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1688. break;
  1689. case BFA_FCPORT_SM_HWFAIL:
  1690. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1691. break;
  1692. default:
  1693. bfa_sm_fault(fcport->bfa, event);
  1694. }
  1695. }
  1696. static void
  1697. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  1698. enum bfa_fcport_sm_event event)
  1699. {
  1700. char pwwn_buf[BFA_STRING_32];
  1701. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1702. bfa_trc(fcport->bfa, event);
  1703. switch (event) {
  1704. case BFA_FCPORT_SM_QRESUME:
  1705. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1706. bfa_fcport_send_enable(fcport);
  1707. break;
  1708. case BFA_FCPORT_SM_STOP:
  1709. bfa_reqq_wcancel(&fcport->reqq_wait);
  1710. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1711. break;
  1712. case BFA_FCPORT_SM_ENABLE:
  1713. /*
  1714. * Already enable is in progress.
  1715. */
  1716. break;
  1717. case BFA_FCPORT_SM_DISABLE:
  1718. /*
  1719. * Just send disable request to firmware when room becomes
  1720. * available in request queue.
  1721. */
  1722. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1723. bfa_reqq_wcancel(&fcport->reqq_wait);
  1724. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1725. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1726. wwn2str(pwwn_buf, fcport->pwwn);
  1727. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1728. "Base port disabled: WWN = %s\n", pwwn_buf);
  1729. break;
  1730. case BFA_FCPORT_SM_LINKUP:
  1731. case BFA_FCPORT_SM_LINKDOWN:
  1732. /*
  1733. * Possible to get link events when doing back-to-back
  1734. * enable/disables.
  1735. */
  1736. break;
  1737. case BFA_FCPORT_SM_HWFAIL:
  1738. bfa_reqq_wcancel(&fcport->reqq_wait);
  1739. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1740. break;
  1741. default:
  1742. bfa_sm_fault(fcport->bfa, event);
  1743. }
  1744. }
  1745. static void
  1746. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  1747. enum bfa_fcport_sm_event event)
  1748. {
  1749. char pwwn_buf[BFA_STRING_32];
  1750. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1751. bfa_trc(fcport->bfa, event);
  1752. switch (event) {
  1753. case BFA_FCPORT_SM_FWRSP:
  1754. case BFA_FCPORT_SM_LINKDOWN:
  1755. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1756. break;
  1757. case BFA_FCPORT_SM_LINKUP:
  1758. bfa_fcport_update_linkinfo(fcport);
  1759. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1760. WARN_ON(!fcport->event_cbfn);
  1761. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1762. break;
  1763. case BFA_FCPORT_SM_ENABLE:
  1764. /*
  1765. * Already being enabled.
  1766. */
  1767. break;
  1768. case BFA_FCPORT_SM_DISABLE:
  1769. if (bfa_fcport_send_disable(fcport))
  1770. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1771. else
  1772. bfa_sm_set_state(fcport,
  1773. bfa_fcport_sm_disabling_qwait);
  1774. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1775. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1776. wwn2str(pwwn_buf, fcport->pwwn);
  1777. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1778. "Base port disabled: WWN = %s\n", pwwn_buf);
  1779. break;
  1780. case BFA_FCPORT_SM_STOP:
  1781. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1782. break;
  1783. case BFA_FCPORT_SM_HWFAIL:
  1784. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1785. break;
  1786. default:
  1787. bfa_sm_fault(fcport->bfa, event);
  1788. }
  1789. }
  1790. static void
  1791. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  1792. enum bfa_fcport_sm_event event)
  1793. {
  1794. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  1795. char pwwn_buf[BFA_STRING_32];
  1796. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1797. bfa_trc(fcport->bfa, event);
  1798. switch (event) {
  1799. case BFA_FCPORT_SM_LINKUP:
  1800. bfa_fcport_update_linkinfo(fcport);
  1801. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1802. WARN_ON(!fcport->event_cbfn);
  1803. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1804. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  1805. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  1806. bfa_trc(fcport->bfa,
  1807. pevent->link_state.vc_fcf.fcf.fipenabled);
  1808. bfa_trc(fcport->bfa,
  1809. pevent->link_state.vc_fcf.fcf.fipfailed);
  1810. if (pevent->link_state.vc_fcf.fcf.fipfailed)
  1811. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1812. BFA_PL_EID_FIP_FCF_DISC, 0,
  1813. "FIP FCF Discovery Failed");
  1814. else
  1815. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1816. BFA_PL_EID_FIP_FCF_DISC, 0,
  1817. "FIP FCF Discovered");
  1818. }
  1819. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1820. wwn2str(pwwn_buf, fcport->pwwn);
  1821. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1822. "Base port online: WWN = %s\n", pwwn_buf);
  1823. break;
  1824. case BFA_FCPORT_SM_LINKDOWN:
  1825. /*
  1826. * Possible to get link down event.
  1827. */
  1828. break;
  1829. case BFA_FCPORT_SM_ENABLE:
  1830. /*
  1831. * Already enabled.
  1832. */
  1833. break;
  1834. case BFA_FCPORT_SM_DISABLE:
  1835. if (bfa_fcport_send_disable(fcport))
  1836. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1837. else
  1838. bfa_sm_set_state(fcport,
  1839. bfa_fcport_sm_disabling_qwait);
  1840. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1841. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1842. wwn2str(pwwn_buf, fcport->pwwn);
  1843. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1844. "Base port disabled: WWN = %s\n", pwwn_buf);
  1845. break;
  1846. case BFA_FCPORT_SM_STOP:
  1847. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1848. break;
  1849. case BFA_FCPORT_SM_HWFAIL:
  1850. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1851. break;
  1852. default:
  1853. bfa_sm_fault(fcport->bfa, event);
  1854. }
  1855. }
  1856. static void
  1857. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  1858. enum bfa_fcport_sm_event event)
  1859. {
  1860. char pwwn_buf[BFA_STRING_32];
  1861. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1862. bfa_trc(fcport->bfa, event);
  1863. switch (event) {
  1864. case BFA_FCPORT_SM_ENABLE:
  1865. /*
  1866. * Already enabled.
  1867. */
  1868. break;
  1869. case BFA_FCPORT_SM_DISABLE:
  1870. if (bfa_fcport_send_disable(fcport))
  1871. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1872. else
  1873. bfa_sm_set_state(fcport,
  1874. bfa_fcport_sm_disabling_qwait);
  1875. bfa_fcport_reset_linkinfo(fcport);
  1876. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1877. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1878. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1879. wwn2str(pwwn_buf, fcport->pwwn);
  1880. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1881. "Base port offline: WWN = %s\n", pwwn_buf);
  1882. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1883. "Base port disabled: WWN = %s\n", pwwn_buf);
  1884. break;
  1885. case BFA_FCPORT_SM_LINKDOWN:
  1886. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1887. bfa_fcport_reset_linkinfo(fcport);
  1888. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1889. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1890. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  1891. wwn2str(pwwn_buf, fcport->pwwn);
  1892. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1893. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1894. "Base port offline: WWN = %s\n", pwwn_buf);
  1895. else
  1896. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1897. "Base port (WWN = %s) "
  1898. "lost fabric connectivity\n", pwwn_buf);
  1899. break;
  1900. case BFA_FCPORT_SM_STOP:
  1901. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1902. bfa_fcport_reset_linkinfo(fcport);
  1903. wwn2str(pwwn_buf, fcport->pwwn);
  1904. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1905. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1906. "Base port offline: WWN = %s\n", pwwn_buf);
  1907. else
  1908. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1909. "Base port (WWN = %s) "
  1910. "lost fabric connectivity\n", pwwn_buf);
  1911. break;
  1912. case BFA_FCPORT_SM_HWFAIL:
  1913. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1914. bfa_fcport_reset_linkinfo(fcport);
  1915. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1916. wwn2str(pwwn_buf, fcport->pwwn);
  1917. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  1918. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1919. "Base port offline: WWN = %s\n", pwwn_buf);
  1920. else
  1921. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1922. "Base port (WWN = %s) "
  1923. "lost fabric connectivity\n", pwwn_buf);
  1924. break;
  1925. default:
  1926. bfa_sm_fault(fcport->bfa, event);
  1927. }
  1928. }
  1929. static void
  1930. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  1931. enum bfa_fcport_sm_event event)
  1932. {
  1933. bfa_trc(fcport->bfa, event);
  1934. switch (event) {
  1935. case BFA_FCPORT_SM_QRESUME:
  1936. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1937. bfa_fcport_send_disable(fcport);
  1938. break;
  1939. case BFA_FCPORT_SM_STOP:
  1940. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1941. bfa_reqq_wcancel(&fcport->reqq_wait);
  1942. break;
  1943. case BFA_FCPORT_SM_ENABLE:
  1944. bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
  1945. break;
  1946. case BFA_FCPORT_SM_DISABLE:
  1947. /*
  1948. * Already being disabled.
  1949. */
  1950. break;
  1951. case BFA_FCPORT_SM_LINKUP:
  1952. case BFA_FCPORT_SM_LINKDOWN:
  1953. /*
  1954. * Possible to get link events when doing back-to-back
  1955. * enable/disables.
  1956. */
  1957. break;
  1958. case BFA_FCPORT_SM_HWFAIL:
  1959. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  1960. bfa_reqq_wcancel(&fcport->reqq_wait);
  1961. break;
  1962. default:
  1963. bfa_sm_fault(fcport->bfa, event);
  1964. }
  1965. }
  1966. static void
  1967. bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  1968. enum bfa_fcport_sm_event event)
  1969. {
  1970. bfa_trc(fcport->bfa, event);
  1971. switch (event) {
  1972. case BFA_FCPORT_SM_QRESUME:
  1973. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1974. bfa_fcport_send_disable(fcport);
  1975. if (bfa_fcport_send_enable(fcport))
  1976. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1977. else
  1978. bfa_sm_set_state(fcport,
  1979. bfa_fcport_sm_enabling_qwait);
  1980. break;
  1981. case BFA_FCPORT_SM_STOP:
  1982. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1983. bfa_reqq_wcancel(&fcport->reqq_wait);
  1984. break;
  1985. case BFA_FCPORT_SM_ENABLE:
  1986. break;
  1987. case BFA_FCPORT_SM_DISABLE:
  1988. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  1989. break;
  1990. case BFA_FCPORT_SM_LINKUP:
  1991. case BFA_FCPORT_SM_LINKDOWN:
  1992. /*
  1993. * Possible to get link events when doing back-to-back
  1994. * enable/disables.
  1995. */
  1996. break;
  1997. case BFA_FCPORT_SM_HWFAIL:
  1998. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  1999. bfa_reqq_wcancel(&fcport->reqq_wait);
  2000. break;
  2001. default:
  2002. bfa_sm_fault(fcport->bfa, event);
  2003. }
  2004. }
  2005. static void
  2006. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  2007. enum bfa_fcport_sm_event event)
  2008. {
  2009. char pwwn_buf[BFA_STRING_32];
  2010. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2011. bfa_trc(fcport->bfa, event);
  2012. switch (event) {
  2013. case BFA_FCPORT_SM_FWRSP:
  2014. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2015. break;
  2016. case BFA_FCPORT_SM_DISABLE:
  2017. /*
  2018. * Already being disabled.
  2019. */
  2020. break;
  2021. case BFA_FCPORT_SM_ENABLE:
  2022. if (bfa_fcport_send_enable(fcport))
  2023. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2024. else
  2025. bfa_sm_set_state(fcport,
  2026. bfa_fcport_sm_enabling_qwait);
  2027. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2028. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2029. wwn2str(pwwn_buf, fcport->pwwn);
  2030. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2031. "Base port enabled: WWN = %s\n", pwwn_buf);
  2032. break;
  2033. case BFA_FCPORT_SM_STOP:
  2034. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2035. break;
  2036. case BFA_FCPORT_SM_LINKUP:
  2037. case BFA_FCPORT_SM_LINKDOWN:
  2038. /*
  2039. * Possible to get link events when doing back-to-back
  2040. * enable/disables.
  2041. */
  2042. break;
  2043. case BFA_FCPORT_SM_HWFAIL:
  2044. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2045. break;
  2046. default:
  2047. bfa_sm_fault(fcport->bfa, event);
  2048. }
  2049. }
  2050. static void
  2051. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  2052. enum bfa_fcport_sm_event event)
  2053. {
  2054. char pwwn_buf[BFA_STRING_32];
  2055. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2056. bfa_trc(fcport->bfa, event);
  2057. switch (event) {
  2058. case BFA_FCPORT_SM_START:
  2059. /*
  2060. * Ignore start event for a port that is disabled.
  2061. */
  2062. break;
  2063. case BFA_FCPORT_SM_STOP:
  2064. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2065. break;
  2066. case BFA_FCPORT_SM_ENABLE:
  2067. if (bfa_fcport_send_enable(fcport))
  2068. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2069. else
  2070. bfa_sm_set_state(fcport,
  2071. bfa_fcport_sm_enabling_qwait);
  2072. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2073. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2074. wwn2str(pwwn_buf, fcport->pwwn);
  2075. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2076. "Base port enabled: WWN = %s\n", pwwn_buf);
  2077. break;
  2078. case BFA_FCPORT_SM_DISABLE:
  2079. /*
  2080. * Already disabled.
  2081. */
  2082. break;
  2083. case BFA_FCPORT_SM_HWFAIL:
  2084. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2085. break;
  2086. default:
  2087. bfa_sm_fault(fcport->bfa, event);
  2088. }
  2089. }
  2090. static void
  2091. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  2092. enum bfa_fcport_sm_event event)
  2093. {
  2094. bfa_trc(fcport->bfa, event);
  2095. switch (event) {
  2096. case BFA_FCPORT_SM_START:
  2097. if (bfa_fcport_send_enable(fcport))
  2098. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2099. else
  2100. bfa_sm_set_state(fcport,
  2101. bfa_fcport_sm_enabling_qwait);
  2102. break;
  2103. default:
  2104. /*
  2105. * Ignore all other events.
  2106. */
  2107. ;
  2108. }
  2109. }
  2110. /*
  2111. * Port is enabled. IOC is down/failed.
  2112. */
  2113. static void
  2114. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  2115. enum bfa_fcport_sm_event event)
  2116. {
  2117. bfa_trc(fcport->bfa, event);
  2118. switch (event) {
  2119. case BFA_FCPORT_SM_START:
  2120. if (bfa_fcport_send_enable(fcport))
  2121. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2122. else
  2123. bfa_sm_set_state(fcport,
  2124. bfa_fcport_sm_enabling_qwait);
  2125. break;
  2126. default:
  2127. /*
  2128. * Ignore all events.
  2129. */
  2130. ;
  2131. }
  2132. }
  2133. /*
  2134. * Port is disabled. IOC is down/failed.
  2135. */
  2136. static void
  2137. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  2138. enum bfa_fcport_sm_event event)
  2139. {
  2140. bfa_trc(fcport->bfa, event);
  2141. switch (event) {
  2142. case BFA_FCPORT_SM_START:
  2143. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2144. break;
  2145. case BFA_FCPORT_SM_ENABLE:
  2146. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2147. break;
  2148. default:
  2149. /*
  2150. * Ignore all events.
  2151. */
  2152. ;
  2153. }
  2154. }
  2155. /*
  2156. * Link state is down
  2157. */
  2158. static void
  2159. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  2160. enum bfa_fcport_ln_sm_event event)
  2161. {
  2162. bfa_trc(ln->fcport->bfa, event);
  2163. switch (event) {
  2164. case BFA_FCPORT_LN_SM_LINKUP:
  2165. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2166. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2167. break;
  2168. default:
  2169. bfa_sm_fault(ln->fcport->bfa, event);
  2170. }
  2171. }
  2172. /*
  2173. * Link state is waiting for down notification
  2174. */
  2175. static void
  2176. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  2177. enum bfa_fcport_ln_sm_event event)
  2178. {
  2179. bfa_trc(ln->fcport->bfa, event);
  2180. switch (event) {
  2181. case BFA_FCPORT_LN_SM_LINKUP:
  2182. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2183. break;
  2184. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2185. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2186. break;
  2187. default:
  2188. bfa_sm_fault(ln->fcport->bfa, event);
  2189. }
  2190. }
  2191. /*
  2192. * Link state is waiting for down notification and there is a pending up
  2193. */
  2194. static void
  2195. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2196. enum bfa_fcport_ln_sm_event event)
  2197. {
  2198. bfa_trc(ln->fcport->bfa, event);
  2199. switch (event) {
  2200. case BFA_FCPORT_LN_SM_LINKDOWN:
  2201. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2202. break;
  2203. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2204. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2205. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2206. break;
  2207. default:
  2208. bfa_sm_fault(ln->fcport->bfa, event);
  2209. }
  2210. }
  2211. /*
  2212. * Link state is up
  2213. */
  2214. static void
  2215. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  2216. enum bfa_fcport_ln_sm_event event)
  2217. {
  2218. bfa_trc(ln->fcport->bfa, event);
  2219. switch (event) {
  2220. case BFA_FCPORT_LN_SM_LINKDOWN:
  2221. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2222. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2223. break;
  2224. default:
  2225. bfa_sm_fault(ln->fcport->bfa, event);
  2226. }
  2227. }
  2228. /*
  2229. * Link state is waiting for up notification
  2230. */
  2231. static void
  2232. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  2233. enum bfa_fcport_ln_sm_event event)
  2234. {
  2235. bfa_trc(ln->fcport->bfa, event);
  2236. switch (event) {
  2237. case BFA_FCPORT_LN_SM_LINKDOWN:
  2238. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2239. break;
  2240. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2241. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  2242. break;
  2243. default:
  2244. bfa_sm_fault(ln->fcport->bfa, event);
  2245. }
  2246. }
  2247. /*
  2248. * Link state is waiting for up notification and there is a pending down
  2249. */
  2250. static void
  2251. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  2252. enum bfa_fcport_ln_sm_event event)
  2253. {
  2254. bfa_trc(ln->fcport->bfa, event);
  2255. switch (event) {
  2256. case BFA_FCPORT_LN_SM_LINKUP:
  2257. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  2258. break;
  2259. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2260. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2261. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2262. break;
  2263. default:
  2264. bfa_sm_fault(ln->fcport->bfa, event);
  2265. }
  2266. }
  2267. /*
  2268. * Link state is waiting for up notification and there are pending down and up
  2269. */
  2270. static void
  2271. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2272. enum bfa_fcport_ln_sm_event event)
  2273. {
  2274. bfa_trc(ln->fcport->bfa, event);
  2275. switch (event) {
  2276. case BFA_FCPORT_LN_SM_LINKDOWN:
  2277. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2278. break;
  2279. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2280. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2281. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2282. break;
  2283. default:
  2284. bfa_sm_fault(ln->fcport->bfa, event);
  2285. }
  2286. }
  2287. static void
  2288. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  2289. {
  2290. struct bfa_fcport_ln_s *ln = cbarg;
  2291. if (complete)
  2292. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  2293. else
  2294. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2295. }
  2296. /*
  2297. * Send SCN notification to upper layers.
  2298. * trunk - false if caller is fcport to ignore fcport event in trunked mode
  2299. */
  2300. static void
  2301. bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
  2302. bfa_boolean_t trunk)
  2303. {
  2304. if (fcport->cfg.trunked && !trunk)
  2305. return;
  2306. switch (event) {
  2307. case BFA_PORT_LINKUP:
  2308. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  2309. break;
  2310. case BFA_PORT_LINKDOWN:
  2311. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  2312. break;
  2313. default:
  2314. WARN_ON(1);
  2315. }
  2316. }
  2317. static void
  2318. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
  2319. {
  2320. struct bfa_fcport_s *fcport = ln->fcport;
  2321. if (fcport->bfa->fcs) {
  2322. fcport->event_cbfn(fcport->event_cbarg, event);
  2323. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2324. } else {
  2325. ln->ln_event = event;
  2326. bfa_cb_queue(fcport->bfa, &ln->ln_qe,
  2327. __bfa_cb_fcport_event, ln);
  2328. }
  2329. }
  2330. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  2331. BFA_CACHELINE_SZ))
  2332. static void
  2333. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  2334. u32 *dm_len)
  2335. {
  2336. *dm_len += FCPORT_STATS_DMA_SZ;
  2337. }
  2338. static void
  2339. bfa_fcport_qresume(void *cbarg)
  2340. {
  2341. struct bfa_fcport_s *fcport = cbarg;
  2342. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  2343. }
  2344. static void
  2345. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
  2346. {
  2347. u8 *dm_kva;
  2348. u64 dm_pa;
  2349. dm_kva = bfa_meminfo_dma_virt(meminfo);
  2350. dm_pa = bfa_meminfo_dma_phys(meminfo);
  2351. fcport->stats_kva = dm_kva;
  2352. fcport->stats_pa = dm_pa;
  2353. fcport->stats = (union bfa_fcport_stats_u *) dm_kva;
  2354. dm_kva += FCPORT_STATS_DMA_SZ;
  2355. dm_pa += FCPORT_STATS_DMA_SZ;
  2356. bfa_meminfo_dma_virt(meminfo) = dm_kva;
  2357. bfa_meminfo_dma_phys(meminfo) = dm_pa;
  2358. }
  2359. /*
  2360. * Memory initialization.
  2361. */
  2362. static void
  2363. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  2364. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  2365. {
  2366. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2367. struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
  2368. struct bfa_fcport_ln_s *ln = &fcport->ln;
  2369. struct timeval tv;
  2370. memset(fcport, 0, sizeof(struct bfa_fcport_s));
  2371. fcport->bfa = bfa;
  2372. ln->fcport = fcport;
  2373. bfa_fcport_mem_claim(fcport, meminfo);
  2374. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  2375. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2376. /*
  2377. * initialize time stamp for stats reset
  2378. */
  2379. do_gettimeofday(&tv);
  2380. fcport->stats_reset_time = tv.tv_sec;
  2381. /*
  2382. * initialize and set default configuration
  2383. */
  2384. port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
  2385. port_cfg->speed = BFA_PORT_SPEED_AUTO;
  2386. port_cfg->trunked = BFA_FALSE;
  2387. port_cfg->maxfrsize = 0;
  2388. port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
  2389. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  2390. }
  2391. static void
  2392. bfa_fcport_detach(struct bfa_s *bfa)
  2393. {
  2394. }
  2395. /*
  2396. * Called when IOC is ready.
  2397. */
  2398. static void
  2399. bfa_fcport_start(struct bfa_s *bfa)
  2400. {
  2401. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  2402. }
  2403. /*
  2404. * Called before IOC is stopped.
  2405. */
  2406. static void
  2407. bfa_fcport_stop(struct bfa_s *bfa)
  2408. {
  2409. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  2410. bfa_trunk_iocdisable(bfa);
  2411. }
  2412. /*
  2413. * Called when IOC failure is detected.
  2414. */
  2415. static void
  2416. bfa_fcport_iocdisable(struct bfa_s *bfa)
  2417. {
  2418. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2419. bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
  2420. bfa_trunk_iocdisable(bfa);
  2421. }
  2422. static void
  2423. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  2424. {
  2425. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  2426. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2427. fcport->speed = pevent->link_state.speed;
  2428. fcport->topology = pevent->link_state.topology;
  2429. if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
  2430. fcport->myalpa = 0;
  2431. /* QoS Details */
  2432. fcport->qos_attr = pevent->link_state.qos_attr;
  2433. fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
  2434. /*
  2435. * update trunk state if applicable
  2436. */
  2437. if (!fcport->cfg.trunked)
  2438. trunk->attr.state = BFA_TRUNK_DISABLED;
  2439. /* update FCoE specific */
  2440. fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
  2441. bfa_trc(fcport->bfa, fcport->speed);
  2442. bfa_trc(fcport->bfa, fcport->topology);
  2443. }
  2444. static void
  2445. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  2446. {
  2447. fcport->speed = BFA_PORT_SPEED_UNKNOWN;
  2448. fcport->topology = BFA_PORT_TOPOLOGY_NONE;
  2449. }
  2450. /*
  2451. * Send port enable message to firmware.
  2452. */
  2453. static bfa_boolean_t
  2454. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  2455. {
  2456. struct bfi_fcport_enable_req_s *m;
  2457. /*
  2458. * Increment message tag before queue check, so that responses to old
  2459. * requests are discarded.
  2460. */
  2461. fcport->msgtag++;
  2462. /*
  2463. * check for room in queue to send request now
  2464. */
  2465. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2466. if (!m) {
  2467. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2468. &fcport->reqq_wait);
  2469. return BFA_FALSE;
  2470. }
  2471. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  2472. bfa_lpuid(fcport->bfa));
  2473. m->nwwn = fcport->nwwn;
  2474. m->pwwn = fcport->pwwn;
  2475. m->port_cfg = fcport->cfg;
  2476. m->msgtag = fcport->msgtag;
  2477. m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
  2478. m->use_flash_cfg = fcport->use_flash_cfg;
  2479. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  2480. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  2481. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  2482. /*
  2483. * queue I/O message to firmware
  2484. */
  2485. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2486. return BFA_TRUE;
  2487. }
  2488. /*
  2489. * Send port disable message to firmware.
  2490. */
  2491. static bfa_boolean_t
  2492. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  2493. {
  2494. struct bfi_fcport_req_s *m;
  2495. /*
  2496. * Increment message tag before queue check, so that responses to old
  2497. * requests are discarded.
  2498. */
  2499. fcport->msgtag++;
  2500. /*
  2501. * check for room in queue to send request now
  2502. */
  2503. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2504. if (!m) {
  2505. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2506. &fcport->reqq_wait);
  2507. return BFA_FALSE;
  2508. }
  2509. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  2510. bfa_lpuid(fcport->bfa));
  2511. m->msgtag = fcport->msgtag;
  2512. /*
  2513. * queue I/O message to firmware
  2514. */
  2515. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2516. return BFA_TRUE;
  2517. }
  2518. static void
  2519. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  2520. {
  2521. fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
  2522. fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
  2523. bfa_trc(fcport->bfa, fcport->pwwn);
  2524. bfa_trc(fcport->bfa, fcport->nwwn);
  2525. }
  2526. static void
  2527. bfa_fcport_send_txcredit(void *port_cbarg)
  2528. {
  2529. struct bfa_fcport_s *fcport = port_cbarg;
  2530. struct bfi_fcport_set_svc_params_req_s *m;
  2531. /*
  2532. * check for room in queue to send request now
  2533. */
  2534. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2535. if (!m) {
  2536. bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
  2537. return;
  2538. }
  2539. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
  2540. bfa_lpuid(fcport->bfa));
  2541. m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
  2542. /*
  2543. * queue I/O message to firmware
  2544. */
  2545. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2546. }
  2547. static void
  2548. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  2549. struct bfa_qos_stats_s *s)
  2550. {
  2551. u32 *dip = (u32 *) d;
  2552. __be32 *sip = (__be32 *) s;
  2553. int i;
  2554. /* Now swap the 32 bit fields */
  2555. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  2556. dip[i] = be32_to_cpu(sip[i]);
  2557. }
  2558. static void
  2559. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  2560. struct bfa_fcoe_stats_s *s)
  2561. {
  2562. u32 *dip = (u32 *) d;
  2563. __be32 *sip = (__be32 *) s;
  2564. int i;
  2565. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  2566. i = i + 2) {
  2567. #ifdef __BIG_ENDIAN
  2568. dip[i] = be32_to_cpu(sip[i]);
  2569. dip[i + 1] = be32_to_cpu(sip[i + 1]);
  2570. #else
  2571. dip[i] = be32_to_cpu(sip[i + 1]);
  2572. dip[i + 1] = be32_to_cpu(sip[i]);
  2573. #endif
  2574. }
  2575. }
  2576. static void
  2577. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  2578. {
  2579. struct bfa_fcport_s *fcport = cbarg;
  2580. if (complete) {
  2581. if (fcport->stats_status == BFA_STATUS_OK) {
  2582. struct timeval tv;
  2583. /* Swap FC QoS or FCoE stats */
  2584. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  2585. bfa_fcport_qos_stats_swap(
  2586. &fcport->stats_ret->fcqos,
  2587. &fcport->stats->fcqos);
  2588. } else {
  2589. bfa_fcport_fcoe_stats_swap(
  2590. &fcport->stats_ret->fcoe,
  2591. &fcport->stats->fcoe);
  2592. do_gettimeofday(&tv);
  2593. fcport->stats_ret->fcoe.secs_reset =
  2594. tv.tv_sec - fcport->stats_reset_time;
  2595. }
  2596. }
  2597. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  2598. } else {
  2599. fcport->stats_busy = BFA_FALSE;
  2600. fcport->stats_status = BFA_STATUS_OK;
  2601. }
  2602. }
  2603. static void
  2604. bfa_fcport_stats_get_timeout(void *cbarg)
  2605. {
  2606. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2607. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2608. if (fcport->stats_qfull) {
  2609. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2610. fcport->stats_qfull = BFA_FALSE;
  2611. }
  2612. fcport->stats_status = BFA_STATUS_ETIMER;
  2613. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
  2614. fcport);
  2615. }
  2616. static void
  2617. bfa_fcport_send_stats_get(void *cbarg)
  2618. {
  2619. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2620. struct bfi_fcport_req_s *msg;
  2621. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2622. if (!msg) {
  2623. fcport->stats_qfull = BFA_TRUE;
  2624. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2625. bfa_fcport_send_stats_get, fcport);
  2626. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2627. &fcport->stats_reqq_wait);
  2628. return;
  2629. }
  2630. fcport->stats_qfull = BFA_FALSE;
  2631. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2632. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  2633. bfa_lpuid(fcport->bfa));
  2634. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2635. }
  2636. static void
  2637. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  2638. {
  2639. struct bfa_fcport_s *fcport = cbarg;
  2640. if (complete) {
  2641. struct timeval tv;
  2642. /*
  2643. * re-initialize time stamp for stats reset
  2644. */
  2645. do_gettimeofday(&tv);
  2646. fcport->stats_reset_time = tv.tv_sec;
  2647. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  2648. } else {
  2649. fcport->stats_busy = BFA_FALSE;
  2650. fcport->stats_status = BFA_STATUS_OK;
  2651. }
  2652. }
  2653. static void
  2654. bfa_fcport_stats_clr_timeout(void *cbarg)
  2655. {
  2656. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2657. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2658. if (fcport->stats_qfull) {
  2659. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2660. fcport->stats_qfull = BFA_FALSE;
  2661. }
  2662. fcport->stats_status = BFA_STATUS_ETIMER;
  2663. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2664. __bfa_cb_fcport_stats_clr, fcport);
  2665. }
  2666. static void
  2667. bfa_fcport_send_stats_clear(void *cbarg)
  2668. {
  2669. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2670. struct bfi_fcport_req_s *msg;
  2671. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2672. if (!msg) {
  2673. fcport->stats_qfull = BFA_TRUE;
  2674. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2675. bfa_fcport_send_stats_clear, fcport);
  2676. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2677. &fcport->stats_reqq_wait);
  2678. return;
  2679. }
  2680. fcport->stats_qfull = BFA_FALSE;
  2681. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2682. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  2683. bfa_lpuid(fcport->bfa));
  2684. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  2685. }
  2686. /*
  2687. * Handle trunk SCN event from firmware.
  2688. */
  2689. static void
  2690. bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
  2691. {
  2692. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2693. struct bfi_fcport_trunk_link_s *tlink;
  2694. struct bfa_trunk_link_attr_s *lattr;
  2695. enum bfa_trunk_state state_prev;
  2696. int i;
  2697. int link_bm = 0;
  2698. bfa_trc(fcport->bfa, fcport->cfg.trunked);
  2699. WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
  2700. scn->trunk_state != BFA_TRUNK_OFFLINE);
  2701. bfa_trc(fcport->bfa, trunk->attr.state);
  2702. bfa_trc(fcport->bfa, scn->trunk_state);
  2703. bfa_trc(fcport->bfa, scn->trunk_speed);
  2704. /*
  2705. * Save off new state for trunk attribute query
  2706. */
  2707. state_prev = trunk->attr.state;
  2708. if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
  2709. trunk->attr.state = scn->trunk_state;
  2710. trunk->attr.speed = scn->trunk_speed;
  2711. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2712. lattr = &trunk->attr.link_attr[i];
  2713. tlink = &scn->tlink[i];
  2714. lattr->link_state = tlink->state;
  2715. lattr->trunk_wwn = tlink->trunk_wwn;
  2716. lattr->fctl = tlink->fctl;
  2717. lattr->speed = tlink->speed;
  2718. lattr->deskew = be32_to_cpu(tlink->deskew);
  2719. if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
  2720. fcport->speed = tlink->speed;
  2721. fcport->topology = BFA_PORT_TOPOLOGY_P2P;
  2722. link_bm |= 1 << i;
  2723. }
  2724. bfa_trc(fcport->bfa, lattr->link_state);
  2725. bfa_trc(fcport->bfa, lattr->trunk_wwn);
  2726. bfa_trc(fcport->bfa, lattr->fctl);
  2727. bfa_trc(fcport->bfa, lattr->speed);
  2728. bfa_trc(fcport->bfa, lattr->deskew);
  2729. }
  2730. switch (link_bm) {
  2731. case 3:
  2732. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2733. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
  2734. break;
  2735. case 2:
  2736. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2737. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
  2738. break;
  2739. case 1:
  2740. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2741. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
  2742. break;
  2743. default:
  2744. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2745. BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
  2746. }
  2747. /*
  2748. * Notify upper layers if trunk state changed.
  2749. */
  2750. if ((state_prev != trunk->attr.state) ||
  2751. (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
  2752. bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
  2753. BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
  2754. }
  2755. }
  2756. static void
  2757. bfa_trunk_iocdisable(struct bfa_s *bfa)
  2758. {
  2759. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2760. int i = 0;
  2761. /*
  2762. * In trunked mode, notify upper layers that link is down
  2763. */
  2764. if (fcport->cfg.trunked) {
  2765. if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
  2766. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
  2767. fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
  2768. fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
  2769. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2770. fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
  2771. fcport->trunk.attr.link_attr[i].fctl =
  2772. BFA_TRUNK_LINK_FCTL_NORMAL;
  2773. fcport->trunk.attr.link_attr[i].link_state =
  2774. BFA_TRUNK_LINK_STATE_DN_LINKDN;
  2775. fcport->trunk.attr.link_attr[i].speed =
  2776. BFA_PORT_SPEED_UNKNOWN;
  2777. fcport->trunk.attr.link_attr[i].deskew = 0;
  2778. }
  2779. }
  2780. }
  2781. /*
  2782. * Called to initialize port attributes
  2783. */
  2784. void
  2785. bfa_fcport_init(struct bfa_s *bfa)
  2786. {
  2787. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2788. /*
  2789. * Initialize port attributes from IOC hardware data.
  2790. */
  2791. bfa_fcport_set_wwns(fcport);
  2792. if (fcport->cfg.maxfrsize == 0)
  2793. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  2794. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  2795. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  2796. if (bfa_fcport_is_pbcdisabled(bfa))
  2797. bfa->modules.port.pbc_disabled = BFA_TRUE;
  2798. WARN_ON(!fcport->cfg.maxfrsize);
  2799. WARN_ON(!fcport->cfg.rx_bbcredit);
  2800. WARN_ON(!fcport->speed_sup);
  2801. }
  2802. /*
  2803. * Firmware message handler.
  2804. */
  2805. void
  2806. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  2807. {
  2808. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2809. union bfi_fcport_i2h_msg_u i2hmsg;
  2810. i2hmsg.msg = msg;
  2811. fcport->event_arg.i2hmsg = i2hmsg;
  2812. bfa_trc(bfa, msg->mhdr.msg_id);
  2813. bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
  2814. switch (msg->mhdr.msg_id) {
  2815. case BFI_FCPORT_I2H_ENABLE_RSP:
  2816. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
  2817. if (fcport->use_flash_cfg) {
  2818. fcport->cfg = i2hmsg.penable_rsp->port_cfg;
  2819. fcport->cfg.maxfrsize =
  2820. cpu_to_be16(fcport->cfg.maxfrsize);
  2821. fcport->cfg.path_tov =
  2822. cpu_to_be16(fcport->cfg.path_tov);
  2823. fcport->cfg.q_depth =
  2824. cpu_to_be16(fcport->cfg.q_depth);
  2825. if (fcport->cfg.trunked)
  2826. fcport->trunk.attr.state =
  2827. BFA_TRUNK_OFFLINE;
  2828. else
  2829. fcport->trunk.attr.state =
  2830. BFA_TRUNK_DISABLED;
  2831. fcport->use_flash_cfg = BFA_FALSE;
  2832. }
  2833. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2834. }
  2835. break;
  2836. case BFI_FCPORT_I2H_DISABLE_RSP:
  2837. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  2838. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2839. break;
  2840. case BFI_FCPORT_I2H_EVENT:
  2841. if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
  2842. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  2843. else
  2844. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  2845. break;
  2846. case BFI_FCPORT_I2H_TRUNK_SCN:
  2847. bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
  2848. break;
  2849. case BFI_FCPORT_I2H_STATS_GET_RSP:
  2850. /*
  2851. * check for timer pop before processing the rsp
  2852. */
  2853. if (fcport->stats_busy == BFA_FALSE ||
  2854. fcport->stats_status == BFA_STATUS_ETIMER)
  2855. break;
  2856. bfa_timer_stop(&fcport->timer);
  2857. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  2858. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2859. __bfa_cb_fcport_stats_get, fcport);
  2860. break;
  2861. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  2862. /*
  2863. * check for timer pop before processing the rsp
  2864. */
  2865. if (fcport->stats_busy == BFA_FALSE ||
  2866. fcport->stats_status == BFA_STATUS_ETIMER)
  2867. break;
  2868. bfa_timer_stop(&fcport->timer);
  2869. fcport->stats_status = BFA_STATUS_OK;
  2870. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  2871. __bfa_cb_fcport_stats_clr, fcport);
  2872. break;
  2873. case BFI_FCPORT_I2H_ENABLE_AEN:
  2874. bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
  2875. break;
  2876. case BFI_FCPORT_I2H_DISABLE_AEN:
  2877. bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
  2878. break;
  2879. default:
  2880. WARN_ON(1);
  2881. break;
  2882. }
  2883. }
  2884. /*
  2885. * Registered callback for port events.
  2886. */
  2887. void
  2888. bfa_fcport_event_register(struct bfa_s *bfa,
  2889. void (*cbfn) (void *cbarg,
  2890. enum bfa_port_linkstate event),
  2891. void *cbarg)
  2892. {
  2893. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2894. fcport->event_cbfn = cbfn;
  2895. fcport->event_cbarg = cbarg;
  2896. }
  2897. bfa_status_t
  2898. bfa_fcport_enable(struct bfa_s *bfa)
  2899. {
  2900. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2901. if (bfa_fcport_is_pbcdisabled(bfa))
  2902. return BFA_STATUS_PBC;
  2903. if (bfa_ioc_is_disabled(&bfa->ioc))
  2904. return BFA_STATUS_IOC_DISABLED;
  2905. if (fcport->diag_busy)
  2906. return BFA_STATUS_DIAG_BUSY;
  2907. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  2908. return BFA_STATUS_OK;
  2909. }
  2910. bfa_status_t
  2911. bfa_fcport_disable(struct bfa_s *bfa)
  2912. {
  2913. if (bfa_fcport_is_pbcdisabled(bfa))
  2914. return BFA_STATUS_PBC;
  2915. if (bfa_ioc_is_disabled(&bfa->ioc))
  2916. return BFA_STATUS_IOC_DISABLED;
  2917. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  2918. return BFA_STATUS_OK;
  2919. }
  2920. /* If PBC is disabled on port, return error */
  2921. bfa_status_t
  2922. bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
  2923. {
  2924. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2925. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  2926. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  2927. if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
  2928. bfa_trc(bfa, fcport->pwwn);
  2929. return BFA_STATUS_PBC;
  2930. }
  2931. return BFA_STATUS_OK;
  2932. }
  2933. /*
  2934. * Configure port speed.
  2935. */
  2936. bfa_status_t
  2937. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
  2938. {
  2939. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2940. bfa_trc(bfa, speed);
  2941. if (fcport->cfg.trunked == BFA_TRUE)
  2942. return BFA_STATUS_TRUNK_ENABLED;
  2943. if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  2944. bfa_trc(bfa, fcport->speed_sup);
  2945. return BFA_STATUS_UNSUPP_SPEED;
  2946. }
  2947. fcport->cfg.speed = speed;
  2948. return BFA_STATUS_OK;
  2949. }
  2950. /*
  2951. * Get current speed.
  2952. */
  2953. enum bfa_port_speed
  2954. bfa_fcport_get_speed(struct bfa_s *bfa)
  2955. {
  2956. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2957. return fcport->speed;
  2958. }
  2959. /*
  2960. * Configure port topology.
  2961. */
  2962. bfa_status_t
  2963. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
  2964. {
  2965. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2966. bfa_trc(bfa, topology);
  2967. bfa_trc(bfa, fcport->cfg.topology);
  2968. switch (topology) {
  2969. case BFA_PORT_TOPOLOGY_P2P:
  2970. case BFA_PORT_TOPOLOGY_LOOP:
  2971. case BFA_PORT_TOPOLOGY_AUTO:
  2972. break;
  2973. default:
  2974. return BFA_STATUS_EINVAL;
  2975. }
  2976. fcport->cfg.topology = topology;
  2977. return BFA_STATUS_OK;
  2978. }
  2979. /*
  2980. * Get current topology.
  2981. */
  2982. enum bfa_port_topology
  2983. bfa_fcport_get_topology(struct bfa_s *bfa)
  2984. {
  2985. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2986. return fcport->topology;
  2987. }
  2988. bfa_status_t
  2989. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  2990. {
  2991. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2992. bfa_trc(bfa, alpa);
  2993. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  2994. bfa_trc(bfa, fcport->cfg.hardalpa);
  2995. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  2996. fcport->cfg.hardalpa = alpa;
  2997. return BFA_STATUS_OK;
  2998. }
  2999. bfa_status_t
  3000. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  3001. {
  3002. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3003. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3004. bfa_trc(bfa, fcport->cfg.hardalpa);
  3005. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  3006. return BFA_STATUS_OK;
  3007. }
  3008. bfa_boolean_t
  3009. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  3010. {
  3011. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3012. *alpa = fcport->cfg.hardalpa;
  3013. return fcport->cfg.cfg_hardalpa;
  3014. }
  3015. u8
  3016. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  3017. {
  3018. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3019. return fcport->myalpa;
  3020. }
  3021. bfa_status_t
  3022. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  3023. {
  3024. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3025. bfa_trc(bfa, maxfrsize);
  3026. bfa_trc(bfa, fcport->cfg.maxfrsize);
  3027. /* with in range */
  3028. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  3029. return BFA_STATUS_INVLD_DFSZ;
  3030. /* power of 2, if not the max frame size of 2112 */
  3031. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  3032. return BFA_STATUS_INVLD_DFSZ;
  3033. fcport->cfg.maxfrsize = maxfrsize;
  3034. return BFA_STATUS_OK;
  3035. }
  3036. u16
  3037. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  3038. {
  3039. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3040. return fcport->cfg.maxfrsize;
  3041. }
  3042. u8
  3043. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  3044. {
  3045. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3046. return fcport->cfg.rx_bbcredit;
  3047. }
  3048. void
  3049. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  3050. {
  3051. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3052. fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
  3053. bfa_fcport_send_txcredit(fcport);
  3054. }
  3055. /*
  3056. * Get port attributes.
  3057. */
  3058. wwn_t
  3059. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  3060. {
  3061. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3062. if (node)
  3063. return fcport->nwwn;
  3064. else
  3065. return fcport->pwwn;
  3066. }
  3067. void
  3068. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
  3069. {
  3070. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3071. memset(attr, 0, sizeof(struct bfa_port_attr_s));
  3072. attr->nwwn = fcport->nwwn;
  3073. attr->pwwn = fcport->pwwn;
  3074. attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
  3075. attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
  3076. memcpy(&attr->pport_cfg, &fcport->cfg,
  3077. sizeof(struct bfa_port_cfg_s));
  3078. /* speed attributes */
  3079. attr->pport_cfg.speed = fcport->cfg.speed;
  3080. attr->speed_supported = fcport->speed_sup;
  3081. attr->speed = fcport->speed;
  3082. attr->cos_supported = FC_CLASS_3;
  3083. /* topology attributes */
  3084. attr->pport_cfg.topology = fcport->cfg.topology;
  3085. attr->topology = fcport->topology;
  3086. attr->pport_cfg.trunked = fcport->cfg.trunked;
  3087. /* beacon attributes */
  3088. attr->beacon = fcport->beacon;
  3089. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  3090. attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled;
  3091. attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa);
  3092. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  3093. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  3094. attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
  3095. /* PBC Disabled State */
  3096. if (bfa_fcport_is_pbcdisabled(bfa))
  3097. attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
  3098. else {
  3099. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  3100. attr->port_state = BFA_PORT_ST_IOCDIS;
  3101. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  3102. attr->port_state = BFA_PORT_ST_FWMISMATCH;
  3103. }
  3104. /* FCoE vlan */
  3105. attr->fcoe_vlan = fcport->fcoe_vlan;
  3106. }
  3107. #define BFA_FCPORT_STATS_TOV 1000
  3108. /*
  3109. * Fetch port statistics (FCQoS or FCoE).
  3110. */
  3111. bfa_status_t
  3112. bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  3113. bfa_cb_port_t cbfn, void *cbarg)
  3114. {
  3115. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3116. if (fcport->stats_busy) {
  3117. bfa_trc(bfa, fcport->stats_busy);
  3118. return BFA_STATUS_DEVBUSY;
  3119. }
  3120. fcport->stats_busy = BFA_TRUE;
  3121. fcport->stats_ret = stats;
  3122. fcport->stats_cbfn = cbfn;
  3123. fcport->stats_cbarg = cbarg;
  3124. bfa_fcport_send_stats_get(fcport);
  3125. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
  3126. fcport, BFA_FCPORT_STATS_TOV);
  3127. return BFA_STATUS_OK;
  3128. }
  3129. /*
  3130. * Reset port statistics (FCQoS or FCoE).
  3131. */
  3132. bfa_status_t
  3133. bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg)
  3134. {
  3135. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3136. if (fcport->stats_busy) {
  3137. bfa_trc(bfa, fcport->stats_busy);
  3138. return BFA_STATUS_DEVBUSY;
  3139. }
  3140. fcport->stats_busy = BFA_TRUE;
  3141. fcport->stats_cbfn = cbfn;
  3142. fcport->stats_cbarg = cbarg;
  3143. bfa_fcport_send_stats_clear(fcport);
  3144. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
  3145. fcport, BFA_FCPORT_STATS_TOV);
  3146. return BFA_STATUS_OK;
  3147. }
  3148. /*
  3149. * Fetch port attributes.
  3150. */
  3151. bfa_boolean_t
  3152. bfa_fcport_is_disabled(struct bfa_s *bfa)
  3153. {
  3154. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3155. return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3156. BFA_PORT_ST_DISABLED;
  3157. }
  3158. bfa_boolean_t
  3159. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  3160. {
  3161. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3162. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  3163. }
  3164. /*
  3165. * Get default minimum ratelim speed
  3166. */
  3167. enum bfa_port_speed
  3168. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  3169. {
  3170. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3171. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  3172. return fcport->cfg.trl_def_speed;
  3173. }
  3174. bfa_boolean_t
  3175. bfa_fcport_is_linkup(struct bfa_s *bfa)
  3176. {
  3177. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3178. return (!fcport->cfg.trunked &&
  3179. bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
  3180. (fcport->cfg.trunked &&
  3181. fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
  3182. }
  3183. bfa_boolean_t
  3184. bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
  3185. {
  3186. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3187. return fcport->cfg.qos_enabled;
  3188. }
  3189. /*
  3190. * Rport State machine functions
  3191. */
  3192. /*
  3193. * Beginning state, only online event expected.
  3194. */
  3195. static void
  3196. bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3197. {
  3198. bfa_trc(rp->bfa, rp->rport_tag);
  3199. bfa_trc(rp->bfa, event);
  3200. switch (event) {
  3201. case BFA_RPORT_SM_CREATE:
  3202. bfa_stats(rp, sm_un_cr);
  3203. bfa_sm_set_state(rp, bfa_rport_sm_created);
  3204. break;
  3205. default:
  3206. bfa_stats(rp, sm_un_unexp);
  3207. bfa_sm_fault(rp->bfa, event);
  3208. }
  3209. }
  3210. static void
  3211. bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3212. {
  3213. bfa_trc(rp->bfa, rp->rport_tag);
  3214. bfa_trc(rp->bfa, event);
  3215. switch (event) {
  3216. case BFA_RPORT_SM_ONLINE:
  3217. bfa_stats(rp, sm_cr_on);
  3218. if (bfa_rport_send_fwcreate(rp))
  3219. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3220. else
  3221. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3222. break;
  3223. case BFA_RPORT_SM_DELETE:
  3224. bfa_stats(rp, sm_cr_del);
  3225. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3226. bfa_rport_free(rp);
  3227. break;
  3228. case BFA_RPORT_SM_HWFAIL:
  3229. bfa_stats(rp, sm_cr_hwf);
  3230. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3231. break;
  3232. default:
  3233. bfa_stats(rp, sm_cr_unexp);
  3234. bfa_sm_fault(rp->bfa, event);
  3235. }
  3236. }
  3237. /*
  3238. * Waiting for rport create response from firmware.
  3239. */
  3240. static void
  3241. bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3242. {
  3243. bfa_trc(rp->bfa, rp->rport_tag);
  3244. bfa_trc(rp->bfa, event);
  3245. switch (event) {
  3246. case BFA_RPORT_SM_FWRSP:
  3247. bfa_stats(rp, sm_fwc_rsp);
  3248. bfa_sm_set_state(rp, bfa_rport_sm_online);
  3249. bfa_rport_online_cb(rp);
  3250. break;
  3251. case BFA_RPORT_SM_DELETE:
  3252. bfa_stats(rp, sm_fwc_del);
  3253. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3254. break;
  3255. case BFA_RPORT_SM_OFFLINE:
  3256. bfa_stats(rp, sm_fwc_off);
  3257. bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
  3258. break;
  3259. case BFA_RPORT_SM_HWFAIL:
  3260. bfa_stats(rp, sm_fwc_hwf);
  3261. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3262. break;
  3263. default:
  3264. bfa_stats(rp, sm_fwc_unexp);
  3265. bfa_sm_fault(rp->bfa, event);
  3266. }
  3267. }
  3268. /*
  3269. * Request queue is full, awaiting queue resume to send create request.
  3270. */
  3271. static void
  3272. bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3273. {
  3274. bfa_trc(rp->bfa, rp->rport_tag);
  3275. bfa_trc(rp->bfa, event);
  3276. switch (event) {
  3277. case BFA_RPORT_SM_QRESUME:
  3278. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3279. bfa_rport_send_fwcreate(rp);
  3280. break;
  3281. case BFA_RPORT_SM_DELETE:
  3282. bfa_stats(rp, sm_fwc_del);
  3283. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3284. bfa_reqq_wcancel(&rp->reqq_wait);
  3285. bfa_rport_free(rp);
  3286. break;
  3287. case BFA_RPORT_SM_OFFLINE:
  3288. bfa_stats(rp, sm_fwc_off);
  3289. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3290. bfa_reqq_wcancel(&rp->reqq_wait);
  3291. bfa_rport_offline_cb(rp);
  3292. break;
  3293. case BFA_RPORT_SM_HWFAIL:
  3294. bfa_stats(rp, sm_fwc_hwf);
  3295. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3296. bfa_reqq_wcancel(&rp->reqq_wait);
  3297. break;
  3298. default:
  3299. bfa_stats(rp, sm_fwc_unexp);
  3300. bfa_sm_fault(rp->bfa, event);
  3301. }
  3302. }
  3303. /*
  3304. * Online state - normal parking state.
  3305. */
  3306. static void
  3307. bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3308. {
  3309. struct bfi_rport_qos_scn_s *qos_scn;
  3310. bfa_trc(rp->bfa, rp->rport_tag);
  3311. bfa_trc(rp->bfa, event);
  3312. switch (event) {
  3313. case BFA_RPORT_SM_OFFLINE:
  3314. bfa_stats(rp, sm_on_off);
  3315. if (bfa_rport_send_fwdelete(rp))
  3316. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3317. else
  3318. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3319. break;
  3320. case BFA_RPORT_SM_DELETE:
  3321. bfa_stats(rp, sm_on_del);
  3322. if (bfa_rport_send_fwdelete(rp))
  3323. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3324. else
  3325. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3326. break;
  3327. case BFA_RPORT_SM_HWFAIL:
  3328. bfa_stats(rp, sm_on_hwf);
  3329. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3330. break;
  3331. case BFA_RPORT_SM_SET_SPEED:
  3332. bfa_rport_send_fwspeed(rp);
  3333. break;
  3334. case BFA_RPORT_SM_QOS_SCN:
  3335. qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
  3336. rp->qos_attr = qos_scn->new_qos_attr;
  3337. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
  3338. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
  3339. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
  3340. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
  3341. qos_scn->old_qos_attr.qos_flow_id =
  3342. be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
  3343. qos_scn->new_qos_attr.qos_flow_id =
  3344. be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
  3345. if (qos_scn->old_qos_attr.qos_flow_id !=
  3346. qos_scn->new_qos_attr.qos_flow_id)
  3347. bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
  3348. qos_scn->old_qos_attr,
  3349. qos_scn->new_qos_attr);
  3350. if (qos_scn->old_qos_attr.qos_priority !=
  3351. qos_scn->new_qos_attr.qos_priority)
  3352. bfa_cb_rport_qos_scn_prio(rp->rport_drv,
  3353. qos_scn->old_qos_attr,
  3354. qos_scn->new_qos_attr);
  3355. break;
  3356. default:
  3357. bfa_stats(rp, sm_on_unexp);
  3358. bfa_sm_fault(rp->bfa, event);
  3359. }
  3360. }
  3361. /*
  3362. * Firmware rport is being deleted - awaiting f/w response.
  3363. */
  3364. static void
  3365. bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3366. {
  3367. bfa_trc(rp->bfa, rp->rport_tag);
  3368. bfa_trc(rp->bfa, event);
  3369. switch (event) {
  3370. case BFA_RPORT_SM_FWRSP:
  3371. bfa_stats(rp, sm_fwd_rsp);
  3372. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3373. bfa_rport_offline_cb(rp);
  3374. break;
  3375. case BFA_RPORT_SM_DELETE:
  3376. bfa_stats(rp, sm_fwd_del);
  3377. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3378. break;
  3379. case BFA_RPORT_SM_HWFAIL:
  3380. bfa_stats(rp, sm_fwd_hwf);
  3381. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3382. bfa_rport_offline_cb(rp);
  3383. break;
  3384. default:
  3385. bfa_stats(rp, sm_fwd_unexp);
  3386. bfa_sm_fault(rp->bfa, event);
  3387. }
  3388. }
  3389. static void
  3390. bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3391. {
  3392. bfa_trc(rp->bfa, rp->rport_tag);
  3393. bfa_trc(rp->bfa, event);
  3394. switch (event) {
  3395. case BFA_RPORT_SM_QRESUME:
  3396. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3397. bfa_rport_send_fwdelete(rp);
  3398. break;
  3399. case BFA_RPORT_SM_DELETE:
  3400. bfa_stats(rp, sm_fwd_del);
  3401. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3402. break;
  3403. case BFA_RPORT_SM_HWFAIL:
  3404. bfa_stats(rp, sm_fwd_hwf);
  3405. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3406. bfa_reqq_wcancel(&rp->reqq_wait);
  3407. bfa_rport_offline_cb(rp);
  3408. break;
  3409. default:
  3410. bfa_stats(rp, sm_fwd_unexp);
  3411. bfa_sm_fault(rp->bfa, event);
  3412. }
  3413. }
  3414. /*
  3415. * Offline state.
  3416. */
  3417. static void
  3418. bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3419. {
  3420. bfa_trc(rp->bfa, rp->rport_tag);
  3421. bfa_trc(rp->bfa, event);
  3422. switch (event) {
  3423. case BFA_RPORT_SM_DELETE:
  3424. bfa_stats(rp, sm_off_del);
  3425. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3426. bfa_rport_free(rp);
  3427. break;
  3428. case BFA_RPORT_SM_ONLINE:
  3429. bfa_stats(rp, sm_off_on);
  3430. if (bfa_rport_send_fwcreate(rp))
  3431. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3432. else
  3433. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3434. break;
  3435. case BFA_RPORT_SM_HWFAIL:
  3436. bfa_stats(rp, sm_off_hwf);
  3437. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3438. break;
  3439. default:
  3440. bfa_stats(rp, sm_off_unexp);
  3441. bfa_sm_fault(rp->bfa, event);
  3442. }
  3443. }
  3444. /*
  3445. * Rport is deleted, waiting for firmware response to delete.
  3446. */
  3447. static void
  3448. bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3449. {
  3450. bfa_trc(rp->bfa, rp->rport_tag);
  3451. bfa_trc(rp->bfa, event);
  3452. switch (event) {
  3453. case BFA_RPORT_SM_FWRSP:
  3454. bfa_stats(rp, sm_del_fwrsp);
  3455. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3456. bfa_rport_free(rp);
  3457. break;
  3458. case BFA_RPORT_SM_HWFAIL:
  3459. bfa_stats(rp, sm_del_hwf);
  3460. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3461. bfa_rport_free(rp);
  3462. break;
  3463. default:
  3464. bfa_sm_fault(rp->bfa, event);
  3465. }
  3466. }
  3467. static void
  3468. bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3469. {
  3470. bfa_trc(rp->bfa, rp->rport_tag);
  3471. bfa_trc(rp->bfa, event);
  3472. switch (event) {
  3473. case BFA_RPORT_SM_QRESUME:
  3474. bfa_stats(rp, sm_del_fwrsp);
  3475. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3476. bfa_rport_send_fwdelete(rp);
  3477. break;
  3478. case BFA_RPORT_SM_HWFAIL:
  3479. bfa_stats(rp, sm_del_hwf);
  3480. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3481. bfa_reqq_wcancel(&rp->reqq_wait);
  3482. bfa_rport_free(rp);
  3483. break;
  3484. default:
  3485. bfa_sm_fault(rp->bfa, event);
  3486. }
  3487. }
  3488. /*
  3489. * Waiting for rport create response from firmware. A delete is pending.
  3490. */
  3491. static void
  3492. bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  3493. enum bfa_rport_event event)
  3494. {
  3495. bfa_trc(rp->bfa, rp->rport_tag);
  3496. bfa_trc(rp->bfa, event);
  3497. switch (event) {
  3498. case BFA_RPORT_SM_FWRSP:
  3499. bfa_stats(rp, sm_delp_fwrsp);
  3500. if (bfa_rport_send_fwdelete(rp))
  3501. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3502. else
  3503. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3504. break;
  3505. case BFA_RPORT_SM_HWFAIL:
  3506. bfa_stats(rp, sm_delp_hwf);
  3507. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3508. bfa_rport_free(rp);
  3509. break;
  3510. default:
  3511. bfa_stats(rp, sm_delp_unexp);
  3512. bfa_sm_fault(rp->bfa, event);
  3513. }
  3514. }
  3515. /*
  3516. * Waiting for rport create response from firmware. Rport offline is pending.
  3517. */
  3518. static void
  3519. bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  3520. enum bfa_rport_event event)
  3521. {
  3522. bfa_trc(rp->bfa, rp->rport_tag);
  3523. bfa_trc(rp->bfa, event);
  3524. switch (event) {
  3525. case BFA_RPORT_SM_FWRSP:
  3526. bfa_stats(rp, sm_offp_fwrsp);
  3527. if (bfa_rport_send_fwdelete(rp))
  3528. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3529. else
  3530. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3531. break;
  3532. case BFA_RPORT_SM_DELETE:
  3533. bfa_stats(rp, sm_offp_del);
  3534. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3535. break;
  3536. case BFA_RPORT_SM_HWFAIL:
  3537. bfa_stats(rp, sm_offp_hwf);
  3538. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3539. break;
  3540. default:
  3541. bfa_stats(rp, sm_offp_unexp);
  3542. bfa_sm_fault(rp->bfa, event);
  3543. }
  3544. }
  3545. /*
  3546. * IOC h/w failed.
  3547. */
  3548. static void
  3549. bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3550. {
  3551. bfa_trc(rp->bfa, rp->rport_tag);
  3552. bfa_trc(rp->bfa, event);
  3553. switch (event) {
  3554. case BFA_RPORT_SM_OFFLINE:
  3555. bfa_stats(rp, sm_iocd_off);
  3556. bfa_rport_offline_cb(rp);
  3557. break;
  3558. case BFA_RPORT_SM_DELETE:
  3559. bfa_stats(rp, sm_iocd_del);
  3560. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3561. bfa_rport_free(rp);
  3562. break;
  3563. case BFA_RPORT_SM_ONLINE:
  3564. bfa_stats(rp, sm_iocd_on);
  3565. if (bfa_rport_send_fwcreate(rp))
  3566. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3567. else
  3568. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3569. break;
  3570. case BFA_RPORT_SM_HWFAIL:
  3571. break;
  3572. default:
  3573. bfa_stats(rp, sm_iocd_unexp);
  3574. bfa_sm_fault(rp->bfa, event);
  3575. }
  3576. }
  3577. /*
  3578. * bfa_rport_private BFA rport private functions
  3579. */
  3580. static void
  3581. __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
  3582. {
  3583. struct bfa_rport_s *rp = cbarg;
  3584. if (complete)
  3585. bfa_cb_rport_online(rp->rport_drv);
  3586. }
  3587. static void
  3588. __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
  3589. {
  3590. struct bfa_rport_s *rp = cbarg;
  3591. if (complete)
  3592. bfa_cb_rport_offline(rp->rport_drv);
  3593. }
  3594. static void
  3595. bfa_rport_qresume(void *cbarg)
  3596. {
  3597. struct bfa_rport_s *rp = cbarg;
  3598. bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
  3599. }
  3600. static void
  3601. bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  3602. u32 *dm_len)
  3603. {
  3604. if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
  3605. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  3606. *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s);
  3607. }
  3608. static void
  3609. bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3610. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  3611. {
  3612. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3613. struct bfa_rport_s *rp;
  3614. u16 i;
  3615. INIT_LIST_HEAD(&mod->rp_free_q);
  3616. INIT_LIST_HEAD(&mod->rp_active_q);
  3617. rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo);
  3618. mod->rps_list = rp;
  3619. mod->num_rports = cfg->fwcfg.num_rports;
  3620. WARN_ON(!mod->num_rports ||
  3621. (mod->num_rports & (mod->num_rports - 1)));
  3622. for (i = 0; i < mod->num_rports; i++, rp++) {
  3623. memset(rp, 0, sizeof(struct bfa_rport_s));
  3624. rp->bfa = bfa;
  3625. rp->rport_tag = i;
  3626. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3627. /*
  3628. * - is unused
  3629. */
  3630. if (i)
  3631. list_add_tail(&rp->qe, &mod->rp_free_q);
  3632. bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
  3633. }
  3634. /*
  3635. * consume memory
  3636. */
  3637. bfa_meminfo_kva(meminfo) = (u8 *) rp;
  3638. }
  3639. static void
  3640. bfa_rport_detach(struct bfa_s *bfa)
  3641. {
  3642. }
  3643. static void
  3644. bfa_rport_start(struct bfa_s *bfa)
  3645. {
  3646. }
  3647. static void
  3648. bfa_rport_stop(struct bfa_s *bfa)
  3649. {
  3650. }
  3651. static void
  3652. bfa_rport_iocdisable(struct bfa_s *bfa)
  3653. {
  3654. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3655. struct bfa_rport_s *rport;
  3656. struct list_head *qe, *qen;
  3657. list_for_each_safe(qe, qen, &mod->rp_active_q) {
  3658. rport = (struct bfa_rport_s *) qe;
  3659. bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
  3660. }
  3661. }
  3662. static struct bfa_rport_s *
  3663. bfa_rport_alloc(struct bfa_rport_mod_s *mod)
  3664. {
  3665. struct bfa_rport_s *rport;
  3666. bfa_q_deq(&mod->rp_free_q, &rport);
  3667. if (rport)
  3668. list_add_tail(&rport->qe, &mod->rp_active_q);
  3669. return rport;
  3670. }
  3671. static void
  3672. bfa_rport_free(struct bfa_rport_s *rport)
  3673. {
  3674. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
  3675. WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
  3676. list_del(&rport->qe);
  3677. list_add_tail(&rport->qe, &mod->rp_free_q);
  3678. }
  3679. static bfa_boolean_t
  3680. bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
  3681. {
  3682. struct bfi_rport_create_req_s *m;
  3683. /*
  3684. * check for room in queue to send request now
  3685. */
  3686. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3687. if (!m) {
  3688. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3689. return BFA_FALSE;
  3690. }
  3691. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
  3692. bfa_lpuid(rp->bfa));
  3693. m->bfa_handle = rp->rport_tag;
  3694. m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
  3695. m->pid = rp->rport_info.pid;
  3696. m->lp_tag = rp->rport_info.lp_tag;
  3697. m->local_pid = rp->rport_info.local_pid;
  3698. m->fc_class = rp->rport_info.fc_class;
  3699. m->vf_en = rp->rport_info.vf_en;
  3700. m->vf_id = rp->rport_info.vf_id;
  3701. m->cisc = rp->rport_info.cisc;
  3702. /*
  3703. * queue I/O message to firmware
  3704. */
  3705. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3706. return BFA_TRUE;
  3707. }
  3708. static bfa_boolean_t
  3709. bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
  3710. {
  3711. struct bfi_rport_delete_req_s *m;
  3712. /*
  3713. * check for room in queue to send request now
  3714. */
  3715. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3716. if (!m) {
  3717. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3718. return BFA_FALSE;
  3719. }
  3720. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
  3721. bfa_lpuid(rp->bfa));
  3722. m->fw_handle = rp->fw_handle;
  3723. /*
  3724. * queue I/O message to firmware
  3725. */
  3726. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3727. return BFA_TRUE;
  3728. }
  3729. static bfa_boolean_t
  3730. bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
  3731. {
  3732. struct bfa_rport_speed_req_s *m;
  3733. /*
  3734. * check for room in queue to send request now
  3735. */
  3736. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3737. if (!m) {
  3738. bfa_trc(rp->bfa, rp->rport_info.speed);
  3739. return BFA_FALSE;
  3740. }
  3741. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
  3742. bfa_lpuid(rp->bfa));
  3743. m->fw_handle = rp->fw_handle;
  3744. m->speed = (u8)rp->rport_info.speed;
  3745. /*
  3746. * queue I/O message to firmware
  3747. */
  3748. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT);
  3749. return BFA_TRUE;
  3750. }
  3751. /*
  3752. * bfa_rport_public
  3753. */
  3754. /*
  3755. * Rport interrupt processing.
  3756. */
  3757. void
  3758. bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  3759. {
  3760. union bfi_rport_i2h_msg_u msg;
  3761. struct bfa_rport_s *rp;
  3762. bfa_trc(bfa, m->mhdr.msg_id);
  3763. msg.msg = m;
  3764. switch (m->mhdr.msg_id) {
  3765. case BFI_RPORT_I2H_CREATE_RSP:
  3766. rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
  3767. rp->fw_handle = msg.create_rsp->fw_handle;
  3768. rp->qos_attr = msg.create_rsp->qos_attr;
  3769. WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
  3770. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3771. break;
  3772. case BFI_RPORT_I2H_DELETE_RSP:
  3773. rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
  3774. WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
  3775. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3776. break;
  3777. case BFI_RPORT_I2H_QOS_SCN:
  3778. rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
  3779. rp->event_arg.fw_msg = msg.qos_scn_evt;
  3780. bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
  3781. break;
  3782. default:
  3783. bfa_trc(bfa, m->mhdr.msg_id);
  3784. WARN_ON(1);
  3785. }
  3786. }
  3787. /*
  3788. * bfa_rport_api
  3789. */
  3790. struct bfa_rport_s *
  3791. bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
  3792. {
  3793. struct bfa_rport_s *rp;
  3794. rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
  3795. if (rp == NULL)
  3796. return NULL;
  3797. rp->bfa = bfa;
  3798. rp->rport_drv = rport_drv;
  3799. memset(&rp->stats, 0, sizeof(rp->stats));
  3800. WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
  3801. bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
  3802. return rp;
  3803. }
  3804. void
  3805. bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
  3806. {
  3807. WARN_ON(rport_info->max_frmsz == 0);
  3808. /*
  3809. * Some JBODs are seen to be not setting PDU size correctly in PLOGI
  3810. * responses. Default to minimum size.
  3811. */
  3812. if (rport_info->max_frmsz == 0) {
  3813. bfa_trc(rport->bfa, rport->rport_tag);
  3814. rport_info->max_frmsz = FC_MIN_PDUSZ;
  3815. }
  3816. rport->rport_info = *rport_info;
  3817. bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
  3818. }
  3819. void
  3820. bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
  3821. {
  3822. WARN_ON(speed == 0);
  3823. WARN_ON(speed == BFA_PORT_SPEED_AUTO);
  3824. rport->rport_info.speed = speed;
  3825. bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
  3826. }
  3827. /*
  3828. * SGPG related functions
  3829. */
  3830. /*
  3831. * Compute and return memory needed by FCP(im) module.
  3832. */
  3833. static void
  3834. bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  3835. u32 *dm_len)
  3836. {
  3837. if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
  3838. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  3839. *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s);
  3840. *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s);
  3841. }
  3842. static void
  3843. bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3844. struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev)
  3845. {
  3846. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3847. int i;
  3848. struct bfa_sgpg_s *hsgpg;
  3849. struct bfi_sgpg_s *sgpg;
  3850. u64 align_len;
  3851. union {
  3852. u64 pa;
  3853. union bfi_addr_u addr;
  3854. } sgpg_pa, sgpg_pa_tmp;
  3855. INIT_LIST_HEAD(&mod->sgpg_q);
  3856. INIT_LIST_HEAD(&mod->sgpg_wait_q);
  3857. bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
  3858. mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
  3859. mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo);
  3860. align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa);
  3861. mod->sgpg_arr_pa += align_len;
  3862. mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) +
  3863. align_len);
  3864. mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) +
  3865. align_len);
  3866. hsgpg = mod->hsgpg_arr;
  3867. sgpg = mod->sgpg_arr;
  3868. sgpg_pa.pa = mod->sgpg_arr_pa;
  3869. mod->free_sgpgs = mod->num_sgpgs;
  3870. WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1));
  3871. for (i = 0; i < mod->num_sgpgs; i++) {
  3872. memset(hsgpg, 0, sizeof(*hsgpg));
  3873. memset(sgpg, 0, sizeof(*sgpg));
  3874. hsgpg->sgpg = sgpg;
  3875. sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
  3876. hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
  3877. list_add_tail(&hsgpg->qe, &mod->sgpg_q);
  3878. hsgpg++;
  3879. sgpg++;
  3880. sgpg_pa.pa += sizeof(struct bfi_sgpg_s);
  3881. }
  3882. bfa_meminfo_kva(minfo) = (u8 *) hsgpg;
  3883. bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg;
  3884. bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa;
  3885. }
  3886. static void
  3887. bfa_sgpg_detach(struct bfa_s *bfa)
  3888. {
  3889. }
  3890. static void
  3891. bfa_sgpg_start(struct bfa_s *bfa)
  3892. {
  3893. }
  3894. static void
  3895. bfa_sgpg_stop(struct bfa_s *bfa)
  3896. {
  3897. }
  3898. static void
  3899. bfa_sgpg_iocdisable(struct bfa_s *bfa)
  3900. {
  3901. }
  3902. bfa_status_t
  3903. bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
  3904. {
  3905. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3906. struct bfa_sgpg_s *hsgpg;
  3907. int i;
  3908. if (mod->free_sgpgs < nsgpgs)
  3909. return BFA_STATUS_ENOMEM;
  3910. for (i = 0; i < nsgpgs; i++) {
  3911. bfa_q_deq(&mod->sgpg_q, &hsgpg);
  3912. WARN_ON(!hsgpg);
  3913. list_add_tail(&hsgpg->qe, sgpg_q);
  3914. }
  3915. mod->free_sgpgs -= nsgpgs;
  3916. return BFA_STATUS_OK;
  3917. }
  3918. void
  3919. bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
  3920. {
  3921. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3922. struct bfa_sgpg_wqe_s *wqe;
  3923. mod->free_sgpgs += nsgpg;
  3924. WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
  3925. list_splice_tail_init(sgpg_q, &mod->sgpg_q);
  3926. if (list_empty(&mod->sgpg_wait_q))
  3927. return;
  3928. /*
  3929. * satisfy as many waiting requests as possible
  3930. */
  3931. do {
  3932. wqe = bfa_q_first(&mod->sgpg_wait_q);
  3933. if (mod->free_sgpgs < wqe->nsgpg)
  3934. nsgpg = mod->free_sgpgs;
  3935. else
  3936. nsgpg = wqe->nsgpg;
  3937. bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
  3938. wqe->nsgpg -= nsgpg;
  3939. if (wqe->nsgpg == 0) {
  3940. list_del(&wqe->qe);
  3941. wqe->cbfn(wqe->cbarg);
  3942. }
  3943. } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
  3944. }
  3945. void
  3946. bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
  3947. {
  3948. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3949. WARN_ON(nsgpg <= 0);
  3950. WARN_ON(nsgpg <= mod->free_sgpgs);
  3951. wqe->nsgpg_total = wqe->nsgpg = nsgpg;
  3952. /*
  3953. * allocate any left to this one first
  3954. */
  3955. if (mod->free_sgpgs) {
  3956. /*
  3957. * no one else is waiting for SGPG
  3958. */
  3959. WARN_ON(!list_empty(&mod->sgpg_wait_q));
  3960. list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
  3961. wqe->nsgpg -= mod->free_sgpgs;
  3962. mod->free_sgpgs = 0;
  3963. }
  3964. list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
  3965. }
  3966. void
  3967. bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
  3968. {
  3969. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  3970. WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
  3971. list_del(&wqe->qe);
  3972. if (wqe->nsgpg_total != wqe->nsgpg)
  3973. bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
  3974. wqe->nsgpg_total - wqe->nsgpg);
  3975. }
  3976. void
  3977. bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
  3978. void *cbarg)
  3979. {
  3980. INIT_LIST_HEAD(&wqe->sgpg_q);
  3981. wqe->cbfn = cbfn;
  3982. wqe->cbarg = cbarg;
  3983. }
  3984. /*
  3985. * UF related functions
  3986. */
  3987. /*
  3988. *****************************************************************************
  3989. * Internal functions
  3990. *****************************************************************************
  3991. */
  3992. static void
  3993. __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
  3994. {
  3995. struct bfa_uf_s *uf = cbarg;
  3996. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
  3997. if (complete)
  3998. ufm->ufrecv(ufm->cbarg, uf);
  3999. }
  4000. static void
  4001. claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4002. {
  4003. u32 uf_pb_tot_sz;
  4004. ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi);
  4005. ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi);
  4006. uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs),
  4007. BFA_DMA_ALIGN_SZ);
  4008. bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz;
  4009. bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz;
  4010. memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz);
  4011. }
  4012. static void
  4013. claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4014. {
  4015. struct bfi_uf_buf_post_s *uf_bp_msg;
  4016. u16 i;
  4017. u16 buf_len;
  4018. ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi);
  4019. uf_bp_msg = ufm->uf_buf_posts;
  4020. for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
  4021. i++, uf_bp_msg++) {
  4022. memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
  4023. uf_bp_msg->buf_tag = i;
  4024. buf_len = sizeof(struct bfa_uf_buf_s);
  4025. uf_bp_msg->buf_len = cpu_to_be16(buf_len);
  4026. bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
  4027. bfa_lpuid(ufm->bfa));
  4028. bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
  4029. }
  4030. /*
  4031. * advance pointer beyond consumed memory
  4032. */
  4033. bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg;
  4034. }
  4035. static void
  4036. claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4037. {
  4038. u16 i;
  4039. struct bfa_uf_s *uf;
  4040. /*
  4041. * Claim block of memory for UF list
  4042. */
  4043. ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi);
  4044. /*
  4045. * Initialize UFs and queue it in UF free queue
  4046. */
  4047. for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
  4048. memset(uf, 0, sizeof(struct bfa_uf_s));
  4049. uf->bfa = ufm->bfa;
  4050. uf->uf_tag = i;
  4051. uf->pb_len = sizeof(struct bfa_uf_buf_s);
  4052. uf->buf_kva = (void *)&ufm->uf_pbs_kva[i];
  4053. uf->buf_pa = ufm_pbs_pa(ufm, i);
  4054. list_add_tail(&uf->qe, &ufm->uf_free_q);
  4055. }
  4056. /*
  4057. * advance memory pointer
  4058. */
  4059. bfa_meminfo_kva(mi) = (u8 *) uf;
  4060. }
  4061. static void
  4062. uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi)
  4063. {
  4064. claim_uf_pbs(ufm, mi);
  4065. claim_ufs(ufm, mi);
  4066. claim_uf_post_msgs(ufm, mi);
  4067. }
  4068. static void
  4069. bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len)
  4070. {
  4071. u32 num_ufs = cfg->fwcfg.num_uf_bufs;
  4072. /*
  4073. * dma-able memory for UF posted bufs
  4074. */
  4075. *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs),
  4076. BFA_DMA_ALIGN_SZ);
  4077. /*
  4078. * kernel Virtual memory for UFs and UF buf post msg copies
  4079. */
  4080. *ndm_len += sizeof(struct bfa_uf_s) * num_ufs;
  4081. *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs;
  4082. }
  4083. static void
  4084. bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4085. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  4086. {
  4087. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4088. memset(ufm, 0, sizeof(struct bfa_uf_mod_s));
  4089. ufm->bfa = bfa;
  4090. ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
  4091. INIT_LIST_HEAD(&ufm->uf_free_q);
  4092. INIT_LIST_HEAD(&ufm->uf_posted_q);
  4093. uf_mem_claim(ufm, meminfo);
  4094. }
  4095. static void
  4096. bfa_uf_detach(struct bfa_s *bfa)
  4097. {
  4098. }
  4099. static struct bfa_uf_s *
  4100. bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
  4101. {
  4102. struct bfa_uf_s *uf;
  4103. bfa_q_deq(&uf_mod->uf_free_q, &uf);
  4104. return uf;
  4105. }
  4106. static void
  4107. bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
  4108. {
  4109. list_add_tail(&uf->qe, &uf_mod->uf_free_q);
  4110. }
  4111. static bfa_status_t
  4112. bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
  4113. {
  4114. struct bfi_uf_buf_post_s *uf_post_msg;
  4115. uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
  4116. if (!uf_post_msg)
  4117. return BFA_STATUS_FAILED;
  4118. memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
  4119. sizeof(struct bfi_uf_buf_post_s));
  4120. bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP);
  4121. bfa_trc(ufm->bfa, uf->uf_tag);
  4122. list_add_tail(&uf->qe, &ufm->uf_posted_q);
  4123. return BFA_STATUS_OK;
  4124. }
  4125. static void
  4126. bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
  4127. {
  4128. struct bfa_uf_s *uf;
  4129. while ((uf = bfa_uf_get(uf_mod)) != NULL) {
  4130. if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
  4131. break;
  4132. }
  4133. }
  4134. static void
  4135. uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
  4136. {
  4137. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4138. u16 uf_tag = m->buf_tag;
  4139. struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag];
  4140. struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
  4141. u8 *buf = &uf_buf->d[0];
  4142. struct fchs_s *fchs;
  4143. m->frm_len = be16_to_cpu(m->frm_len);
  4144. m->xfr_len = be16_to_cpu(m->xfr_len);
  4145. fchs = (struct fchs_s *)uf_buf;
  4146. list_del(&uf->qe); /* dequeue from posted queue */
  4147. uf->data_ptr = buf;
  4148. uf->data_len = m->xfr_len;
  4149. WARN_ON(uf->data_len < sizeof(struct fchs_s));
  4150. if (uf->data_len == sizeof(struct fchs_s)) {
  4151. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
  4152. uf->data_len, (struct fchs_s *)buf);
  4153. } else {
  4154. u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
  4155. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
  4156. BFA_PL_EID_RX, uf->data_len,
  4157. (struct fchs_s *)buf, pld_w0);
  4158. }
  4159. if (bfa->fcs)
  4160. __bfa_cb_uf_recv(uf, BFA_TRUE);
  4161. else
  4162. bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
  4163. }
  4164. static void
  4165. bfa_uf_stop(struct bfa_s *bfa)
  4166. {
  4167. }
  4168. static void
  4169. bfa_uf_iocdisable(struct bfa_s *bfa)
  4170. {
  4171. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4172. struct bfa_uf_s *uf;
  4173. struct list_head *qe, *qen;
  4174. list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
  4175. uf = (struct bfa_uf_s *) qe;
  4176. list_del(&uf->qe);
  4177. bfa_uf_put(ufm, uf);
  4178. }
  4179. }
  4180. static void
  4181. bfa_uf_start(struct bfa_s *bfa)
  4182. {
  4183. bfa_uf_post_all(BFA_UF_MOD(bfa));
  4184. }
  4185. /*
  4186. * Register handler for all unsolicted receive frames.
  4187. *
  4188. * @param[in] bfa BFA instance
  4189. * @param[in] ufrecv receive handler function
  4190. * @param[in] cbarg receive handler arg
  4191. */
  4192. void
  4193. bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
  4194. {
  4195. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4196. ufm->ufrecv = ufrecv;
  4197. ufm->cbarg = cbarg;
  4198. }
  4199. /*
  4200. * Free an unsolicited frame back to BFA.
  4201. *
  4202. * @param[in] uf unsolicited frame to be freed
  4203. *
  4204. * @return None
  4205. */
  4206. void
  4207. bfa_uf_free(struct bfa_uf_s *uf)
  4208. {
  4209. bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
  4210. bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
  4211. }
  4212. /*
  4213. * uf_pub BFA uf module public functions
  4214. */
  4215. void
  4216. bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4217. {
  4218. bfa_trc(bfa, msg->mhdr.msg_id);
  4219. switch (msg->mhdr.msg_id) {
  4220. case BFI_UF_I2H_FRM_RCVD:
  4221. uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
  4222. break;
  4223. default:
  4224. bfa_trc(bfa, msg->mhdr.msg_id);
  4225. WARN_ON(1);
  4226. }
  4227. }