bfa_svc.c 120 KB

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