bfa_svc.c 135 KB

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