bfa_svc.c 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722
  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. bfa_lps_send_login(lps);
  1098. break;
  1099. case BFA_LPS_SM_OFFLINE:
  1100. case BFA_LPS_SM_DELETE:
  1101. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1102. bfa_reqq_wcancel(&lps->wqe);
  1103. break;
  1104. case BFA_LPS_SM_RX_CVL:
  1105. /*
  1106. * Login was not even sent out; so when getting out
  1107. * of this state, it will appear like a login retry
  1108. * after Clear virtual link
  1109. */
  1110. break;
  1111. default:
  1112. bfa_sm_fault(lps->bfa, event);
  1113. }
  1114. }
  1115. /*
  1116. * login complete
  1117. */
  1118. static void
  1119. bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1120. {
  1121. bfa_trc(lps->bfa, lps->bfa_tag);
  1122. bfa_trc(lps->bfa, event);
  1123. switch (event) {
  1124. case BFA_LPS_SM_LOGOUT:
  1125. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1126. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1127. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1128. } else {
  1129. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1130. bfa_lps_send_logout(lps);
  1131. }
  1132. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1133. BFA_PL_EID_LOGO, 0, "Logout");
  1134. break;
  1135. case BFA_LPS_SM_RX_CVL:
  1136. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1137. /* Let the vport module know about this event */
  1138. bfa_lps_cvl_event(lps);
  1139. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1140. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1141. break;
  1142. case BFA_LPS_SM_SET_N2N_PID:
  1143. if (bfa_reqq_full(lps->bfa, lps->reqq)) {
  1144. bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait);
  1145. bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe);
  1146. } else
  1147. bfa_lps_send_set_n2n_pid(lps);
  1148. break;
  1149. case BFA_LPS_SM_OFFLINE:
  1150. case BFA_LPS_SM_DELETE:
  1151. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1152. break;
  1153. default:
  1154. bfa_sm_fault(lps->bfa, event);
  1155. }
  1156. }
  1157. /*
  1158. * login complete
  1159. */
  1160. static void
  1161. bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1162. {
  1163. bfa_trc(lps->bfa, lps->bfa_tag);
  1164. bfa_trc(lps->bfa, event);
  1165. switch (event) {
  1166. case BFA_LPS_SM_RESUME:
  1167. bfa_sm_set_state(lps, bfa_lps_sm_online);
  1168. bfa_lps_send_set_n2n_pid(lps);
  1169. break;
  1170. case BFA_LPS_SM_LOGOUT:
  1171. bfa_sm_set_state(lps, bfa_lps_sm_logowait);
  1172. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1173. BFA_PL_EID_LOGO, 0, "Logout");
  1174. break;
  1175. case BFA_LPS_SM_RX_CVL:
  1176. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1177. bfa_reqq_wcancel(&lps->wqe);
  1178. /* Let the vport module know about this event */
  1179. bfa_lps_cvl_event(lps);
  1180. bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS,
  1181. BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx");
  1182. break;
  1183. case BFA_LPS_SM_OFFLINE:
  1184. case BFA_LPS_SM_DELETE:
  1185. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1186. bfa_reqq_wcancel(&lps->wqe);
  1187. break;
  1188. default:
  1189. bfa_sm_fault(lps->bfa, event);
  1190. }
  1191. }
  1192. /*
  1193. * logout in progress - awaiting firmware response
  1194. */
  1195. static void
  1196. bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1197. {
  1198. bfa_trc(lps->bfa, lps->bfa_tag);
  1199. bfa_trc(lps->bfa, event);
  1200. switch (event) {
  1201. case BFA_LPS_SM_FWRSP:
  1202. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1203. bfa_lps_logout_comp(lps);
  1204. break;
  1205. case BFA_LPS_SM_OFFLINE:
  1206. case BFA_LPS_SM_DELETE:
  1207. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1208. break;
  1209. default:
  1210. bfa_sm_fault(lps->bfa, event);
  1211. }
  1212. }
  1213. /*
  1214. * logout pending -- awaiting space in request queue
  1215. */
  1216. static void
  1217. bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event)
  1218. {
  1219. bfa_trc(lps->bfa, lps->bfa_tag);
  1220. bfa_trc(lps->bfa, event);
  1221. switch (event) {
  1222. case BFA_LPS_SM_RESUME:
  1223. bfa_sm_set_state(lps, bfa_lps_sm_logout);
  1224. bfa_lps_send_logout(lps);
  1225. break;
  1226. case BFA_LPS_SM_OFFLINE:
  1227. case BFA_LPS_SM_DELETE:
  1228. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1229. bfa_reqq_wcancel(&lps->wqe);
  1230. break;
  1231. default:
  1232. bfa_sm_fault(lps->bfa, event);
  1233. }
  1234. }
  1235. /*
  1236. * lps_pvt BFA LPS private functions
  1237. */
  1238. /*
  1239. * return memory requirement
  1240. */
  1241. static void
  1242. bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  1243. struct bfa_s *bfa)
  1244. {
  1245. struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa);
  1246. if (cfg->drvcfg.min_cfg)
  1247. bfa_mem_kva_setup(minfo, lps_kva,
  1248. sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS);
  1249. else
  1250. bfa_mem_kva_setup(minfo, lps_kva,
  1251. sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS);
  1252. }
  1253. /*
  1254. * bfa module attach at initialization time
  1255. */
  1256. static void
  1257. bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1258. struct bfa_pcidev_s *pcidev)
  1259. {
  1260. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1261. struct bfa_lps_s *lps;
  1262. int i;
  1263. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1264. if (cfg->drvcfg.min_cfg)
  1265. mod->num_lps = BFA_LPS_MIN_LPORTS;
  1266. else
  1267. mod->num_lps = BFA_LPS_MAX_LPORTS;
  1268. mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod);
  1269. bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s);
  1270. INIT_LIST_HEAD(&mod->lps_free_q);
  1271. INIT_LIST_HEAD(&mod->lps_active_q);
  1272. INIT_LIST_HEAD(&mod->lps_login_q);
  1273. for (i = 0; i < mod->num_lps; i++, lps++) {
  1274. lps->bfa = bfa;
  1275. lps->bfa_tag = (u8) i;
  1276. lps->reqq = BFA_REQQ_LPS;
  1277. bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps);
  1278. list_add_tail(&lps->qe, &mod->lps_free_q);
  1279. }
  1280. }
  1281. static void
  1282. bfa_lps_detach(struct bfa_s *bfa)
  1283. {
  1284. }
  1285. static void
  1286. bfa_lps_start(struct bfa_s *bfa)
  1287. {
  1288. }
  1289. static void
  1290. bfa_lps_stop(struct bfa_s *bfa)
  1291. {
  1292. }
  1293. /*
  1294. * IOC in disabled state -- consider all lps offline
  1295. */
  1296. static void
  1297. bfa_lps_iocdisable(struct bfa_s *bfa)
  1298. {
  1299. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1300. struct bfa_lps_s *lps;
  1301. struct list_head *qe, *qen;
  1302. list_for_each_safe(qe, qen, &mod->lps_active_q) {
  1303. lps = (struct bfa_lps_s *) qe;
  1304. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1305. }
  1306. list_for_each_safe(qe, qen, &mod->lps_login_q) {
  1307. lps = (struct bfa_lps_s *) qe;
  1308. bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE);
  1309. }
  1310. list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q);
  1311. }
  1312. /*
  1313. * Firmware login response
  1314. */
  1315. static void
  1316. bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp)
  1317. {
  1318. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1319. struct bfa_lps_s *lps;
  1320. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1321. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1322. lps->status = rsp->status;
  1323. switch (rsp->status) {
  1324. case BFA_STATUS_OK:
  1325. lps->fw_tag = rsp->fw_tag;
  1326. lps->fport = rsp->f_port;
  1327. if (lps->fport)
  1328. lps->lp_pid = rsp->lp_pid;
  1329. lps->npiv_en = rsp->npiv_en;
  1330. lps->pr_bbcred = be16_to_cpu(rsp->bb_credit);
  1331. lps->pr_pwwn = rsp->port_name;
  1332. lps->pr_nwwn = rsp->node_name;
  1333. lps->auth_req = rsp->auth_req;
  1334. lps->lp_mac = rsp->lp_mac;
  1335. lps->brcd_switch = rsp->brcd_switch;
  1336. lps->fcf_mac = rsp->fcf_mac;
  1337. lps->pr_bbscn = rsp->bb_scn;
  1338. break;
  1339. case BFA_STATUS_FABRIC_RJT:
  1340. lps->lsrjt_rsn = rsp->lsrjt_rsn;
  1341. lps->lsrjt_expl = rsp->lsrjt_expl;
  1342. break;
  1343. case BFA_STATUS_EPROTOCOL:
  1344. lps->ext_status = rsp->ext_status;
  1345. break;
  1346. case BFA_STATUS_VPORT_MAX:
  1347. if (rsp->ext_status)
  1348. bfa_lps_no_res(lps, rsp->ext_status);
  1349. break;
  1350. default:
  1351. /* Nothing to do with other status */
  1352. break;
  1353. }
  1354. list_del(&lps->qe);
  1355. list_add_tail(&lps->qe, &mod->lps_active_q);
  1356. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1357. }
  1358. static void
  1359. bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count)
  1360. {
  1361. struct bfa_s *bfa = first_lps->bfa;
  1362. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1363. struct list_head *qe, *qe_next;
  1364. struct bfa_lps_s *lps;
  1365. bfa_trc(bfa, count);
  1366. qe = bfa_q_next(first_lps);
  1367. while (count && qe) {
  1368. qe_next = bfa_q_next(qe);
  1369. lps = (struct bfa_lps_s *)qe;
  1370. bfa_trc(bfa, lps->bfa_tag);
  1371. lps->status = first_lps->status;
  1372. list_del(&lps->qe);
  1373. list_add_tail(&lps->qe, &mod->lps_active_q);
  1374. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1375. qe = qe_next;
  1376. count--;
  1377. }
  1378. }
  1379. /*
  1380. * Firmware logout response
  1381. */
  1382. static void
  1383. bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp)
  1384. {
  1385. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1386. struct bfa_lps_s *lps;
  1387. WARN_ON(rsp->bfa_tag >= mod->num_lps);
  1388. lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag);
  1389. bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP);
  1390. }
  1391. /*
  1392. * Firmware received a Clear virtual link request (for FCoE)
  1393. */
  1394. static void
  1395. bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl)
  1396. {
  1397. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1398. struct bfa_lps_s *lps;
  1399. lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag);
  1400. bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL);
  1401. }
  1402. /*
  1403. * Space is available in request queue, resume queueing request to firmware.
  1404. */
  1405. static void
  1406. bfa_lps_reqq_resume(void *lps_arg)
  1407. {
  1408. struct bfa_lps_s *lps = lps_arg;
  1409. bfa_sm_send_event(lps, BFA_LPS_SM_RESUME);
  1410. }
  1411. /*
  1412. * lps is freed -- triggered by vport delete
  1413. */
  1414. static void
  1415. bfa_lps_free(struct bfa_lps_s *lps)
  1416. {
  1417. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1418. lps->lp_pid = 0;
  1419. list_del(&lps->qe);
  1420. list_add_tail(&lps->qe, &mod->lps_free_q);
  1421. }
  1422. /*
  1423. * send login request to firmware
  1424. */
  1425. static void
  1426. bfa_lps_send_login(struct bfa_lps_s *lps)
  1427. {
  1428. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa);
  1429. struct bfi_lps_login_req_s *m;
  1430. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1431. WARN_ON(!m);
  1432. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ,
  1433. bfa_fn_lpu(lps->bfa));
  1434. m->bfa_tag = lps->bfa_tag;
  1435. m->alpa = lps->alpa;
  1436. m->pdu_size = cpu_to_be16(lps->pdusz);
  1437. m->pwwn = lps->pwwn;
  1438. m->nwwn = lps->nwwn;
  1439. m->fdisc = lps->fdisc;
  1440. m->auth_en = lps->auth_en;
  1441. m->bb_scn = lps->bb_scn;
  1442. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1443. list_del(&lps->qe);
  1444. list_add_tail(&lps->qe, &mod->lps_login_q);
  1445. }
  1446. /*
  1447. * send logout request to firmware
  1448. */
  1449. static void
  1450. bfa_lps_send_logout(struct bfa_lps_s *lps)
  1451. {
  1452. struct bfi_lps_logout_req_s *m;
  1453. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1454. WARN_ON(!m);
  1455. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ,
  1456. bfa_fn_lpu(lps->bfa));
  1457. m->fw_tag = lps->fw_tag;
  1458. m->port_name = lps->pwwn;
  1459. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1460. }
  1461. /*
  1462. * send n2n pid set request to firmware
  1463. */
  1464. static void
  1465. bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps)
  1466. {
  1467. struct bfi_lps_n2n_pid_req_s *m;
  1468. m = bfa_reqq_next(lps->bfa, lps->reqq);
  1469. WARN_ON(!m);
  1470. bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ,
  1471. bfa_fn_lpu(lps->bfa));
  1472. m->fw_tag = lps->fw_tag;
  1473. m->lp_pid = lps->lp_pid;
  1474. bfa_reqq_produce(lps->bfa, lps->reqq, m->mh);
  1475. }
  1476. /*
  1477. * Indirect login completion handler for non-fcs
  1478. */
  1479. static void
  1480. bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete)
  1481. {
  1482. struct bfa_lps_s *lps = arg;
  1483. if (!complete)
  1484. return;
  1485. if (lps->fdisc)
  1486. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1487. else
  1488. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1489. }
  1490. /*
  1491. * Login completion handler -- direct call for fcs, queue for others
  1492. */
  1493. static void
  1494. bfa_lps_login_comp(struct bfa_lps_s *lps)
  1495. {
  1496. if (!lps->bfa->fcs) {
  1497. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb,
  1498. lps);
  1499. return;
  1500. }
  1501. if (lps->fdisc)
  1502. bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1503. else
  1504. bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status);
  1505. }
  1506. /*
  1507. * Indirect logout completion handler for non-fcs
  1508. */
  1509. static void
  1510. bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete)
  1511. {
  1512. struct bfa_lps_s *lps = arg;
  1513. if (!complete)
  1514. return;
  1515. if (lps->fdisc)
  1516. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1517. }
  1518. /*
  1519. * Logout completion handler -- direct call for fcs, queue for others
  1520. */
  1521. static void
  1522. bfa_lps_logout_comp(struct bfa_lps_s *lps)
  1523. {
  1524. if (!lps->bfa->fcs) {
  1525. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb,
  1526. lps);
  1527. return;
  1528. }
  1529. if (lps->fdisc)
  1530. bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg);
  1531. }
  1532. /*
  1533. * Clear virtual link completion handler for non-fcs
  1534. */
  1535. static void
  1536. bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete)
  1537. {
  1538. struct bfa_lps_s *lps = arg;
  1539. if (!complete)
  1540. return;
  1541. /* Clear virtual link to base port will result in link down */
  1542. if (lps->fdisc)
  1543. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1544. }
  1545. /*
  1546. * Received Clear virtual link event --direct call for fcs,
  1547. * queue for others
  1548. */
  1549. static void
  1550. bfa_lps_cvl_event(struct bfa_lps_s *lps)
  1551. {
  1552. if (!lps->bfa->fcs) {
  1553. bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb,
  1554. lps);
  1555. return;
  1556. }
  1557. /* Clear virtual link to base port will result in link down */
  1558. if (lps->fdisc)
  1559. bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg);
  1560. }
  1561. /*
  1562. * lps_public BFA LPS public functions
  1563. */
  1564. u32
  1565. bfa_lps_get_max_vport(struct bfa_s *bfa)
  1566. {
  1567. if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT)
  1568. return BFA_LPS_MAX_VPORTS_SUPP_CT;
  1569. else
  1570. return BFA_LPS_MAX_VPORTS_SUPP_CB;
  1571. }
  1572. /*
  1573. * Allocate a lport srvice tag.
  1574. */
  1575. struct bfa_lps_s *
  1576. bfa_lps_alloc(struct bfa_s *bfa)
  1577. {
  1578. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1579. struct bfa_lps_s *lps = NULL;
  1580. bfa_q_deq(&mod->lps_free_q, &lps);
  1581. if (lps == NULL)
  1582. return NULL;
  1583. list_add_tail(&lps->qe, &mod->lps_active_q);
  1584. bfa_sm_set_state(lps, bfa_lps_sm_init);
  1585. return lps;
  1586. }
  1587. /*
  1588. * Free lport service tag. This can be called anytime after an alloc.
  1589. * No need to wait for any pending login/logout completions.
  1590. */
  1591. void
  1592. bfa_lps_delete(struct bfa_lps_s *lps)
  1593. {
  1594. bfa_sm_send_event(lps, BFA_LPS_SM_DELETE);
  1595. }
  1596. /*
  1597. * Initiate a lport login.
  1598. */
  1599. void
  1600. bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
  1601. wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn)
  1602. {
  1603. lps->uarg = uarg;
  1604. lps->alpa = alpa;
  1605. lps->pdusz = pdusz;
  1606. lps->pwwn = pwwn;
  1607. lps->nwwn = nwwn;
  1608. lps->fdisc = BFA_FALSE;
  1609. lps->auth_en = auth_en;
  1610. lps->bb_scn = bb_scn;
  1611. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1612. }
  1613. /*
  1614. * Initiate a lport fdisc login.
  1615. */
  1616. void
  1617. bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
  1618. wwn_t nwwn)
  1619. {
  1620. lps->uarg = uarg;
  1621. lps->alpa = 0;
  1622. lps->pdusz = pdusz;
  1623. lps->pwwn = pwwn;
  1624. lps->nwwn = nwwn;
  1625. lps->fdisc = BFA_TRUE;
  1626. lps->auth_en = BFA_FALSE;
  1627. bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN);
  1628. }
  1629. /*
  1630. * Initiate a lport FDSIC logout.
  1631. */
  1632. void
  1633. bfa_lps_fdisclogo(struct bfa_lps_s *lps)
  1634. {
  1635. bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT);
  1636. }
  1637. u8
  1638. bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag)
  1639. {
  1640. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1641. return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag;
  1642. }
  1643. /*
  1644. * Return lport services tag given the pid
  1645. */
  1646. u8
  1647. bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid)
  1648. {
  1649. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1650. struct bfa_lps_s *lps;
  1651. int i;
  1652. for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) {
  1653. if (lps->lp_pid == pid)
  1654. return lps->bfa_tag;
  1655. }
  1656. /* Return base port tag anyway */
  1657. return 0;
  1658. }
  1659. /*
  1660. * return port id assigned to the base lport
  1661. */
  1662. u32
  1663. bfa_lps_get_base_pid(struct bfa_s *bfa)
  1664. {
  1665. struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa);
  1666. return BFA_LPS_FROM_TAG(mod, 0)->lp_pid;
  1667. }
  1668. /*
  1669. * Set PID in case of n2n (which is assigned during PLOGI)
  1670. */
  1671. void
  1672. bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid)
  1673. {
  1674. bfa_trc(lps->bfa, lps->bfa_tag);
  1675. bfa_trc(lps->bfa, n2n_pid);
  1676. lps->lp_pid = n2n_pid;
  1677. bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID);
  1678. }
  1679. /*
  1680. * LPS firmware message class handler.
  1681. */
  1682. void
  1683. bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  1684. {
  1685. union bfi_lps_i2h_msg_u msg;
  1686. bfa_trc(bfa, m->mhdr.msg_id);
  1687. msg.msg = m;
  1688. switch (m->mhdr.msg_id) {
  1689. case BFI_LPS_I2H_LOGIN_RSP:
  1690. bfa_lps_login_rsp(bfa, msg.login_rsp);
  1691. break;
  1692. case BFI_LPS_I2H_LOGOUT_RSP:
  1693. bfa_lps_logout_rsp(bfa, msg.logout_rsp);
  1694. break;
  1695. case BFI_LPS_I2H_CVL_EVENT:
  1696. bfa_lps_rx_cvl_event(bfa, msg.cvl_event);
  1697. break;
  1698. default:
  1699. bfa_trc(bfa, m->mhdr.msg_id);
  1700. WARN_ON(1);
  1701. }
  1702. }
  1703. static void
  1704. bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
  1705. {
  1706. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1707. struct bfa_aen_entry_s *aen_entry;
  1708. bfad_get_aen_entry(bfad, aen_entry);
  1709. if (!aen_entry)
  1710. return;
  1711. aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
  1712. aen_entry->aen_data.port.pwwn = fcport->pwwn;
  1713. /* Send the AEN notification */
  1714. bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq,
  1715. BFA_AEN_CAT_PORT, event);
  1716. }
  1717. /*
  1718. * FC PORT state machine functions
  1719. */
  1720. static void
  1721. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  1722. enum bfa_fcport_sm_event event)
  1723. {
  1724. bfa_trc(fcport->bfa, event);
  1725. switch (event) {
  1726. case BFA_FCPORT_SM_START:
  1727. /*
  1728. * Start event after IOC is configured and BFA is started.
  1729. */
  1730. fcport->use_flash_cfg = BFA_TRUE;
  1731. if (bfa_fcport_send_enable(fcport)) {
  1732. bfa_trc(fcport->bfa, BFA_TRUE);
  1733. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1734. } else {
  1735. bfa_trc(fcport->bfa, BFA_FALSE);
  1736. bfa_sm_set_state(fcport,
  1737. bfa_fcport_sm_enabling_qwait);
  1738. }
  1739. break;
  1740. case BFA_FCPORT_SM_ENABLE:
  1741. /*
  1742. * Port is persistently configured to be in enabled state. Do
  1743. * not change state. Port enabling is done when START event is
  1744. * received.
  1745. */
  1746. break;
  1747. case BFA_FCPORT_SM_DISABLE:
  1748. /*
  1749. * If a port is persistently configured to be disabled, the
  1750. * first event will a port disable request.
  1751. */
  1752. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1753. break;
  1754. case BFA_FCPORT_SM_HWFAIL:
  1755. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1756. break;
  1757. default:
  1758. bfa_sm_fault(fcport->bfa, event);
  1759. }
  1760. }
  1761. static void
  1762. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  1763. enum bfa_fcport_sm_event event)
  1764. {
  1765. char pwwn_buf[BFA_STRING_32];
  1766. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1767. bfa_trc(fcport->bfa, event);
  1768. switch (event) {
  1769. case BFA_FCPORT_SM_QRESUME:
  1770. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  1771. bfa_fcport_send_enable(fcport);
  1772. break;
  1773. case BFA_FCPORT_SM_STOP:
  1774. bfa_reqq_wcancel(&fcport->reqq_wait);
  1775. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1776. break;
  1777. case BFA_FCPORT_SM_ENABLE:
  1778. /*
  1779. * Already enable is in progress.
  1780. */
  1781. break;
  1782. case BFA_FCPORT_SM_DISABLE:
  1783. /*
  1784. * Just send disable request to firmware when room becomes
  1785. * available in request queue.
  1786. */
  1787. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  1788. bfa_reqq_wcancel(&fcport->reqq_wait);
  1789. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1790. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1791. wwn2str(pwwn_buf, fcport->pwwn);
  1792. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1793. "Base port disabled: WWN = %s\n", pwwn_buf);
  1794. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1795. break;
  1796. case BFA_FCPORT_SM_LINKUP:
  1797. case BFA_FCPORT_SM_LINKDOWN:
  1798. /*
  1799. * Possible to get link events when doing back-to-back
  1800. * enable/disables.
  1801. */
  1802. break;
  1803. case BFA_FCPORT_SM_HWFAIL:
  1804. bfa_reqq_wcancel(&fcport->reqq_wait);
  1805. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1806. break;
  1807. default:
  1808. bfa_sm_fault(fcport->bfa, event);
  1809. }
  1810. }
  1811. static void
  1812. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  1813. enum bfa_fcport_sm_event event)
  1814. {
  1815. char pwwn_buf[BFA_STRING_32];
  1816. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1817. bfa_trc(fcport->bfa, event);
  1818. switch (event) {
  1819. case BFA_FCPORT_SM_FWRSP:
  1820. case BFA_FCPORT_SM_LINKDOWN:
  1821. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1822. break;
  1823. case BFA_FCPORT_SM_LINKUP:
  1824. bfa_fcport_update_linkinfo(fcport);
  1825. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1826. WARN_ON(!fcport->event_cbfn);
  1827. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1828. break;
  1829. case BFA_FCPORT_SM_ENABLE:
  1830. /*
  1831. * Already being enabled.
  1832. */
  1833. break;
  1834. case BFA_FCPORT_SM_DISABLE:
  1835. if (bfa_fcport_send_disable(fcport))
  1836. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1837. else
  1838. bfa_sm_set_state(fcport,
  1839. bfa_fcport_sm_disabling_qwait);
  1840. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1841. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1842. wwn2str(pwwn_buf, fcport->pwwn);
  1843. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1844. "Base port disabled: WWN = %s\n", pwwn_buf);
  1845. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1846. break;
  1847. case BFA_FCPORT_SM_STOP:
  1848. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1849. break;
  1850. case BFA_FCPORT_SM_HWFAIL:
  1851. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1852. break;
  1853. default:
  1854. bfa_sm_fault(fcport->bfa, event);
  1855. }
  1856. }
  1857. static void
  1858. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  1859. enum bfa_fcport_sm_event event)
  1860. {
  1861. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  1862. char pwwn_buf[BFA_STRING_32];
  1863. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1864. bfa_trc(fcport->bfa, event);
  1865. switch (event) {
  1866. case BFA_FCPORT_SM_LINKUP:
  1867. bfa_fcport_update_linkinfo(fcport);
  1868. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  1869. WARN_ON(!fcport->event_cbfn);
  1870. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1871. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  1872. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  1873. bfa_trc(fcport->bfa,
  1874. pevent->link_state.vc_fcf.fcf.fipenabled);
  1875. bfa_trc(fcport->bfa,
  1876. pevent->link_state.vc_fcf.fcf.fipfailed);
  1877. if (pevent->link_state.vc_fcf.fcf.fipfailed)
  1878. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1879. BFA_PL_EID_FIP_FCF_DISC, 0,
  1880. "FIP FCF Discovery Failed");
  1881. else
  1882. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1883. BFA_PL_EID_FIP_FCF_DISC, 0,
  1884. "FIP FCF Discovered");
  1885. }
  1886. bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE);
  1887. wwn2str(pwwn_buf, fcport->pwwn);
  1888. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1889. "Base port online: WWN = %s\n", pwwn_buf);
  1890. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
  1891. /* If QoS is enabled and it is not online, send AEN */
  1892. if (fcport->cfg.qos_enabled &&
  1893. fcport->qos_attr.state != BFA_QOS_ONLINE)
  1894. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
  1895. break;
  1896. case BFA_FCPORT_SM_LINKDOWN:
  1897. /*
  1898. * Possible to get link down event.
  1899. */
  1900. break;
  1901. case BFA_FCPORT_SM_ENABLE:
  1902. /*
  1903. * Already enabled.
  1904. */
  1905. break;
  1906. case BFA_FCPORT_SM_DISABLE:
  1907. if (bfa_fcport_send_disable(fcport))
  1908. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1909. else
  1910. bfa_sm_set_state(fcport,
  1911. bfa_fcport_sm_disabling_qwait);
  1912. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1913. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1914. wwn2str(pwwn_buf, fcport->pwwn);
  1915. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1916. "Base port disabled: WWN = %s\n", pwwn_buf);
  1917. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1918. break;
  1919. case BFA_FCPORT_SM_STOP:
  1920. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1921. break;
  1922. case BFA_FCPORT_SM_HWFAIL:
  1923. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1924. break;
  1925. default:
  1926. bfa_sm_fault(fcport->bfa, event);
  1927. }
  1928. }
  1929. static void
  1930. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  1931. enum bfa_fcport_sm_event event)
  1932. {
  1933. char pwwn_buf[BFA_STRING_32];
  1934. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  1935. bfa_trc(fcport->bfa, event);
  1936. switch (event) {
  1937. case BFA_FCPORT_SM_ENABLE:
  1938. /*
  1939. * Already enabled.
  1940. */
  1941. break;
  1942. case BFA_FCPORT_SM_DISABLE:
  1943. if (bfa_fcport_send_disable(fcport))
  1944. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  1945. else
  1946. bfa_sm_set_state(fcport,
  1947. bfa_fcport_sm_disabling_qwait);
  1948. bfa_fcport_reset_linkinfo(fcport);
  1949. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1950. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1951. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  1952. wwn2str(pwwn_buf, fcport->pwwn);
  1953. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1954. "Base port offline: WWN = %s\n", pwwn_buf);
  1955. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1956. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1957. "Base port disabled: WWN = %s\n", pwwn_buf);
  1958. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  1959. break;
  1960. case BFA_FCPORT_SM_LINKDOWN:
  1961. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  1962. bfa_fcport_reset_linkinfo(fcport);
  1963. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1964. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  1965. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  1966. wwn2str(pwwn_buf, fcport->pwwn);
  1967. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  1968. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1969. "Base port offline: WWN = %s\n", pwwn_buf);
  1970. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1971. } else {
  1972. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1973. "Base port (WWN = %s) "
  1974. "lost fabric connectivity\n", pwwn_buf);
  1975. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1976. }
  1977. break;
  1978. case BFA_FCPORT_SM_STOP:
  1979. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  1980. bfa_fcport_reset_linkinfo(fcport);
  1981. wwn2str(pwwn_buf, fcport->pwwn);
  1982. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  1983. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  1984. "Base port offline: WWN = %s\n", pwwn_buf);
  1985. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  1986. } else {
  1987. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  1988. "Base port (WWN = %s) "
  1989. "lost fabric connectivity\n", pwwn_buf);
  1990. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  1991. }
  1992. break;
  1993. case BFA_FCPORT_SM_HWFAIL:
  1994. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  1995. bfa_fcport_reset_linkinfo(fcport);
  1996. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE);
  1997. wwn2str(pwwn_buf, fcport->pwwn);
  1998. if (BFA_PORT_IS_DISABLED(fcport->bfa)) {
  1999. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2000. "Base port offline: WWN = %s\n", pwwn_buf);
  2001. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  2002. } else {
  2003. BFA_LOG(KERN_ERR, bfad, bfa_log_level,
  2004. "Base port (WWN = %s) "
  2005. "lost fabric connectivity\n", pwwn_buf);
  2006. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  2007. }
  2008. break;
  2009. default:
  2010. bfa_sm_fault(fcport->bfa, event);
  2011. }
  2012. }
  2013. static void
  2014. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  2015. enum bfa_fcport_sm_event event)
  2016. {
  2017. bfa_trc(fcport->bfa, event);
  2018. switch (event) {
  2019. case BFA_FCPORT_SM_QRESUME:
  2020. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2021. bfa_fcport_send_disable(fcport);
  2022. break;
  2023. case BFA_FCPORT_SM_STOP:
  2024. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2025. bfa_reqq_wcancel(&fcport->reqq_wait);
  2026. break;
  2027. case BFA_FCPORT_SM_ENABLE:
  2028. bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait);
  2029. break;
  2030. case BFA_FCPORT_SM_DISABLE:
  2031. /*
  2032. * Already being disabled.
  2033. */
  2034. break;
  2035. case BFA_FCPORT_SM_LINKUP:
  2036. case BFA_FCPORT_SM_LINKDOWN:
  2037. /*
  2038. * Possible to get link events when doing back-to-back
  2039. * enable/disables.
  2040. */
  2041. break;
  2042. case BFA_FCPORT_SM_HWFAIL:
  2043. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2044. bfa_reqq_wcancel(&fcport->reqq_wait);
  2045. break;
  2046. default:
  2047. bfa_sm_fault(fcport->bfa, event);
  2048. }
  2049. }
  2050. static void
  2051. bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport,
  2052. enum bfa_fcport_sm_event event)
  2053. {
  2054. bfa_trc(fcport->bfa, event);
  2055. switch (event) {
  2056. case BFA_FCPORT_SM_QRESUME:
  2057. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  2058. bfa_fcport_send_disable(fcport);
  2059. if (bfa_fcport_send_enable(fcport))
  2060. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2061. else
  2062. bfa_sm_set_state(fcport,
  2063. bfa_fcport_sm_enabling_qwait);
  2064. break;
  2065. case BFA_FCPORT_SM_STOP:
  2066. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2067. bfa_reqq_wcancel(&fcport->reqq_wait);
  2068. break;
  2069. case BFA_FCPORT_SM_ENABLE:
  2070. break;
  2071. case BFA_FCPORT_SM_DISABLE:
  2072. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  2073. break;
  2074. case BFA_FCPORT_SM_LINKUP:
  2075. case BFA_FCPORT_SM_LINKDOWN:
  2076. /*
  2077. * Possible to get link events when doing back-to-back
  2078. * enable/disables.
  2079. */
  2080. break;
  2081. case BFA_FCPORT_SM_HWFAIL:
  2082. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2083. bfa_reqq_wcancel(&fcport->reqq_wait);
  2084. break;
  2085. default:
  2086. bfa_sm_fault(fcport->bfa, event);
  2087. }
  2088. }
  2089. static void
  2090. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  2091. enum bfa_fcport_sm_event event)
  2092. {
  2093. char pwwn_buf[BFA_STRING_32];
  2094. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2095. bfa_trc(fcport->bfa, event);
  2096. switch (event) {
  2097. case BFA_FCPORT_SM_FWRSP:
  2098. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2099. break;
  2100. case BFA_FCPORT_SM_DISABLE:
  2101. /*
  2102. * Already being disabled.
  2103. */
  2104. break;
  2105. case BFA_FCPORT_SM_ENABLE:
  2106. if (bfa_fcport_send_enable(fcport))
  2107. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2108. else
  2109. bfa_sm_set_state(fcport,
  2110. bfa_fcport_sm_enabling_qwait);
  2111. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2112. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2113. wwn2str(pwwn_buf, fcport->pwwn);
  2114. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2115. "Base port enabled: WWN = %s\n", pwwn_buf);
  2116. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2117. break;
  2118. case BFA_FCPORT_SM_STOP:
  2119. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2120. break;
  2121. case BFA_FCPORT_SM_LINKUP:
  2122. case BFA_FCPORT_SM_LINKDOWN:
  2123. /*
  2124. * Possible to get link events when doing back-to-back
  2125. * enable/disables.
  2126. */
  2127. break;
  2128. case BFA_FCPORT_SM_HWFAIL:
  2129. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2130. break;
  2131. default:
  2132. bfa_sm_fault(fcport->bfa, event);
  2133. }
  2134. }
  2135. static void
  2136. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  2137. enum bfa_fcport_sm_event event)
  2138. {
  2139. char pwwn_buf[BFA_STRING_32];
  2140. struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad;
  2141. bfa_trc(fcport->bfa, event);
  2142. switch (event) {
  2143. case BFA_FCPORT_SM_START:
  2144. /*
  2145. * Ignore start event for a port that is disabled.
  2146. */
  2147. break;
  2148. case BFA_FCPORT_SM_STOP:
  2149. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  2150. break;
  2151. case BFA_FCPORT_SM_ENABLE:
  2152. if (bfa_fcport_send_enable(fcport))
  2153. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2154. else
  2155. bfa_sm_set_state(fcport,
  2156. bfa_fcport_sm_enabling_qwait);
  2157. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2158. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  2159. wwn2str(pwwn_buf, fcport->pwwn);
  2160. BFA_LOG(KERN_INFO, bfad, bfa_log_level,
  2161. "Base port enabled: WWN = %s\n", pwwn_buf);
  2162. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  2163. break;
  2164. case BFA_FCPORT_SM_DISABLE:
  2165. /*
  2166. * Already disabled.
  2167. */
  2168. break;
  2169. case BFA_FCPORT_SM_HWFAIL:
  2170. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  2171. break;
  2172. default:
  2173. bfa_sm_fault(fcport->bfa, event);
  2174. }
  2175. }
  2176. static void
  2177. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  2178. enum bfa_fcport_sm_event event)
  2179. {
  2180. bfa_trc(fcport->bfa, event);
  2181. switch (event) {
  2182. case BFA_FCPORT_SM_START:
  2183. if (bfa_fcport_send_enable(fcport))
  2184. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2185. else
  2186. bfa_sm_set_state(fcport,
  2187. bfa_fcport_sm_enabling_qwait);
  2188. break;
  2189. default:
  2190. /*
  2191. * Ignore all other events.
  2192. */
  2193. ;
  2194. }
  2195. }
  2196. /*
  2197. * Port is enabled. IOC is down/failed.
  2198. */
  2199. static void
  2200. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  2201. enum bfa_fcport_sm_event event)
  2202. {
  2203. bfa_trc(fcport->bfa, event);
  2204. switch (event) {
  2205. case BFA_FCPORT_SM_START:
  2206. if (bfa_fcport_send_enable(fcport))
  2207. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  2208. else
  2209. bfa_sm_set_state(fcport,
  2210. bfa_fcport_sm_enabling_qwait);
  2211. break;
  2212. default:
  2213. /*
  2214. * Ignore all events.
  2215. */
  2216. ;
  2217. }
  2218. }
  2219. /*
  2220. * Port is disabled. IOC is down/failed.
  2221. */
  2222. static void
  2223. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  2224. enum bfa_fcport_sm_event event)
  2225. {
  2226. bfa_trc(fcport->bfa, event);
  2227. switch (event) {
  2228. case BFA_FCPORT_SM_START:
  2229. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  2230. break;
  2231. case BFA_FCPORT_SM_ENABLE:
  2232. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  2233. break;
  2234. default:
  2235. /*
  2236. * Ignore all events.
  2237. */
  2238. ;
  2239. }
  2240. }
  2241. /*
  2242. * Link state is down
  2243. */
  2244. static void
  2245. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  2246. enum bfa_fcport_ln_sm_event event)
  2247. {
  2248. bfa_trc(ln->fcport->bfa, event);
  2249. switch (event) {
  2250. case BFA_FCPORT_LN_SM_LINKUP:
  2251. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2252. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2253. break;
  2254. default:
  2255. bfa_sm_fault(ln->fcport->bfa, event);
  2256. }
  2257. }
  2258. /*
  2259. * Link state is waiting for down notification
  2260. */
  2261. static void
  2262. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  2263. enum bfa_fcport_ln_sm_event event)
  2264. {
  2265. bfa_trc(ln->fcport->bfa, event);
  2266. switch (event) {
  2267. case BFA_FCPORT_LN_SM_LINKUP:
  2268. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2269. break;
  2270. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2271. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2272. break;
  2273. default:
  2274. bfa_sm_fault(ln->fcport->bfa, event);
  2275. }
  2276. }
  2277. /*
  2278. * Link state is waiting for down notification and there is a pending up
  2279. */
  2280. static void
  2281. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2282. enum bfa_fcport_ln_sm_event event)
  2283. {
  2284. bfa_trc(ln->fcport->bfa, event);
  2285. switch (event) {
  2286. case BFA_FCPORT_LN_SM_LINKDOWN:
  2287. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2288. break;
  2289. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2290. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  2291. bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP);
  2292. break;
  2293. default:
  2294. bfa_sm_fault(ln->fcport->bfa, event);
  2295. }
  2296. }
  2297. /*
  2298. * Link state is up
  2299. */
  2300. static void
  2301. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  2302. enum bfa_fcport_ln_sm_event event)
  2303. {
  2304. bfa_trc(ln->fcport->bfa, event);
  2305. switch (event) {
  2306. case BFA_FCPORT_LN_SM_LINKDOWN:
  2307. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2308. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2309. break;
  2310. default:
  2311. bfa_sm_fault(ln->fcport->bfa, event);
  2312. }
  2313. }
  2314. /*
  2315. * Link state is waiting for up notification
  2316. */
  2317. static void
  2318. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  2319. enum bfa_fcport_ln_sm_event event)
  2320. {
  2321. bfa_trc(ln->fcport->bfa, event);
  2322. switch (event) {
  2323. case BFA_FCPORT_LN_SM_LINKDOWN:
  2324. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2325. break;
  2326. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2327. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  2328. break;
  2329. default:
  2330. bfa_sm_fault(ln->fcport->bfa, event);
  2331. }
  2332. }
  2333. /*
  2334. * Link state is waiting for up notification and there is a pending down
  2335. */
  2336. static void
  2337. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  2338. enum bfa_fcport_ln_sm_event event)
  2339. {
  2340. bfa_trc(ln->fcport->bfa, event);
  2341. switch (event) {
  2342. case BFA_FCPORT_LN_SM_LINKUP:
  2343. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  2344. break;
  2345. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2346. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  2347. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2348. break;
  2349. default:
  2350. bfa_sm_fault(ln->fcport->bfa, event);
  2351. }
  2352. }
  2353. /*
  2354. * Link state is waiting for up notification and there are pending down and up
  2355. */
  2356. static void
  2357. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  2358. enum bfa_fcport_ln_sm_event event)
  2359. {
  2360. bfa_trc(ln->fcport->bfa, event);
  2361. switch (event) {
  2362. case BFA_FCPORT_LN_SM_LINKDOWN:
  2363. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  2364. break;
  2365. case BFA_FCPORT_LN_SM_NOTIFICATION:
  2366. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  2367. bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN);
  2368. break;
  2369. default:
  2370. bfa_sm_fault(ln->fcport->bfa, event);
  2371. }
  2372. }
  2373. static void
  2374. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  2375. {
  2376. struct bfa_fcport_ln_s *ln = cbarg;
  2377. if (complete)
  2378. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  2379. else
  2380. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2381. }
  2382. /*
  2383. * Send SCN notification to upper layers.
  2384. * trunk - false if caller is fcport to ignore fcport event in trunked mode
  2385. */
  2386. static void
  2387. bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event,
  2388. bfa_boolean_t trunk)
  2389. {
  2390. if (fcport->cfg.trunked && !trunk)
  2391. return;
  2392. switch (event) {
  2393. case BFA_PORT_LINKUP:
  2394. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  2395. break;
  2396. case BFA_PORT_LINKDOWN:
  2397. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  2398. break;
  2399. default:
  2400. WARN_ON(1);
  2401. }
  2402. }
  2403. static void
  2404. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event)
  2405. {
  2406. struct bfa_fcport_s *fcport = ln->fcport;
  2407. if (fcport->bfa->fcs) {
  2408. fcport->event_cbfn(fcport->event_cbarg, event);
  2409. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  2410. } else {
  2411. ln->ln_event = event;
  2412. bfa_cb_queue(fcport->bfa, &ln->ln_qe,
  2413. __bfa_cb_fcport_event, ln);
  2414. }
  2415. }
  2416. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  2417. BFA_CACHELINE_SZ))
  2418. static void
  2419. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  2420. struct bfa_s *bfa)
  2421. {
  2422. struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa);
  2423. bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ);
  2424. }
  2425. static void
  2426. bfa_fcport_qresume(void *cbarg)
  2427. {
  2428. struct bfa_fcport_s *fcport = cbarg;
  2429. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  2430. }
  2431. static void
  2432. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport)
  2433. {
  2434. struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma;
  2435. fcport->stats_kva = bfa_mem_dma_virt(fcport_dma);
  2436. fcport->stats_pa = bfa_mem_dma_phys(fcport_dma);
  2437. fcport->stats = (union bfa_fcport_stats_u *)
  2438. bfa_mem_dma_virt(fcport_dma);
  2439. }
  2440. /*
  2441. * Memory initialization.
  2442. */
  2443. static void
  2444. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  2445. struct bfa_pcidev_s *pcidev)
  2446. {
  2447. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2448. struct bfa_port_cfg_s *port_cfg = &fcport->cfg;
  2449. struct bfa_fcport_ln_s *ln = &fcport->ln;
  2450. struct timeval tv;
  2451. fcport->bfa = bfa;
  2452. ln->fcport = fcport;
  2453. bfa_fcport_mem_claim(fcport);
  2454. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  2455. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  2456. /*
  2457. * initialize time stamp for stats reset
  2458. */
  2459. do_gettimeofday(&tv);
  2460. fcport->stats_reset_time = tv.tv_sec;
  2461. /*
  2462. * initialize and set default configuration
  2463. */
  2464. port_cfg->topology = BFA_PORT_TOPOLOGY_P2P;
  2465. port_cfg->speed = BFA_PORT_SPEED_AUTO;
  2466. port_cfg->trunked = BFA_FALSE;
  2467. port_cfg->maxfrsize = 0;
  2468. port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS;
  2469. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2470. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2471. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  2472. }
  2473. static void
  2474. bfa_fcport_detach(struct bfa_s *bfa)
  2475. {
  2476. }
  2477. /*
  2478. * Called when IOC is ready.
  2479. */
  2480. static void
  2481. bfa_fcport_start(struct bfa_s *bfa)
  2482. {
  2483. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  2484. }
  2485. /*
  2486. * Called before IOC is stopped.
  2487. */
  2488. static void
  2489. bfa_fcport_stop(struct bfa_s *bfa)
  2490. {
  2491. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  2492. bfa_trunk_iocdisable(bfa);
  2493. }
  2494. /*
  2495. * Called when IOC failure is detected.
  2496. */
  2497. static void
  2498. bfa_fcport_iocdisable(struct bfa_s *bfa)
  2499. {
  2500. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2501. bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL);
  2502. bfa_trunk_iocdisable(bfa);
  2503. }
  2504. static void
  2505. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  2506. {
  2507. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  2508. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2509. fcport->speed = pevent->link_state.speed;
  2510. fcport->topology = pevent->link_state.topology;
  2511. if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)
  2512. fcport->myalpa = 0;
  2513. /* QoS Details */
  2514. fcport->qos_attr = pevent->link_state.qos_attr;
  2515. fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr;
  2516. /*
  2517. * update trunk state if applicable
  2518. */
  2519. if (!fcport->cfg.trunked)
  2520. trunk->attr.state = BFA_TRUNK_DISABLED;
  2521. /* update FCoE specific */
  2522. fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan);
  2523. bfa_trc(fcport->bfa, fcport->speed);
  2524. bfa_trc(fcport->bfa, fcport->topology);
  2525. }
  2526. static void
  2527. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  2528. {
  2529. fcport->speed = BFA_PORT_SPEED_UNKNOWN;
  2530. fcport->topology = BFA_PORT_TOPOLOGY_NONE;
  2531. fcport->bbsc_op_state = BFA_FALSE;
  2532. }
  2533. /*
  2534. * Send port enable message to firmware.
  2535. */
  2536. static bfa_boolean_t
  2537. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  2538. {
  2539. struct bfi_fcport_enable_req_s *m;
  2540. /*
  2541. * Increment message tag before queue check, so that responses to old
  2542. * requests are discarded.
  2543. */
  2544. fcport->msgtag++;
  2545. /*
  2546. * check for room in queue to send request now
  2547. */
  2548. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2549. if (!m) {
  2550. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2551. &fcport->reqq_wait);
  2552. return BFA_FALSE;
  2553. }
  2554. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  2555. bfa_fn_lpu(fcport->bfa));
  2556. m->nwwn = fcport->nwwn;
  2557. m->pwwn = fcport->pwwn;
  2558. m->port_cfg = fcport->cfg;
  2559. m->msgtag = fcport->msgtag;
  2560. m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize);
  2561. m->use_flash_cfg = fcport->use_flash_cfg;
  2562. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  2563. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  2564. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  2565. /*
  2566. * queue I/O message to firmware
  2567. */
  2568. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2569. return BFA_TRUE;
  2570. }
  2571. /*
  2572. * Send port disable message to firmware.
  2573. */
  2574. static bfa_boolean_t
  2575. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  2576. {
  2577. struct bfi_fcport_req_s *m;
  2578. /*
  2579. * Increment message tag before queue check, so that responses to old
  2580. * requests are discarded.
  2581. */
  2582. fcport->msgtag++;
  2583. /*
  2584. * check for room in queue to send request now
  2585. */
  2586. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2587. if (!m) {
  2588. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2589. &fcport->reqq_wait);
  2590. return BFA_FALSE;
  2591. }
  2592. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  2593. bfa_fn_lpu(fcport->bfa));
  2594. m->msgtag = fcport->msgtag;
  2595. /*
  2596. * queue I/O message to firmware
  2597. */
  2598. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
  2599. return BFA_TRUE;
  2600. }
  2601. static void
  2602. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  2603. {
  2604. fcport->pwwn = fcport->bfa->ioc.attr->pwwn;
  2605. fcport->nwwn = fcport->bfa->ioc.attr->nwwn;
  2606. bfa_trc(fcport->bfa, fcport->pwwn);
  2607. bfa_trc(fcport->bfa, fcport->nwwn);
  2608. }
  2609. static void
  2610. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  2611. struct bfa_qos_stats_s *s)
  2612. {
  2613. u32 *dip = (u32 *) d;
  2614. __be32 *sip = (__be32 *) s;
  2615. int i;
  2616. /* Now swap the 32 bit fields */
  2617. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  2618. dip[i] = be32_to_cpu(sip[i]);
  2619. }
  2620. static void
  2621. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  2622. struct bfa_fcoe_stats_s *s)
  2623. {
  2624. u32 *dip = (u32 *) d;
  2625. __be32 *sip = (__be32 *) s;
  2626. int i;
  2627. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  2628. i = i + 2) {
  2629. #ifdef __BIG_ENDIAN
  2630. dip[i] = be32_to_cpu(sip[i]);
  2631. dip[i + 1] = be32_to_cpu(sip[i + 1]);
  2632. #else
  2633. dip[i] = be32_to_cpu(sip[i + 1]);
  2634. dip[i + 1] = be32_to_cpu(sip[i]);
  2635. #endif
  2636. }
  2637. }
  2638. static void
  2639. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  2640. {
  2641. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg;
  2642. struct bfa_cb_pending_q_s *cb;
  2643. struct list_head *qe, *qen;
  2644. union bfa_fcport_stats_u *ret;
  2645. if (complete) {
  2646. struct timeval tv;
  2647. if (fcport->stats_status == BFA_STATUS_OK)
  2648. do_gettimeofday(&tv);
  2649. list_for_each_safe(qe, qen, &fcport->stats_pending_q) {
  2650. bfa_q_deq(&fcport->stats_pending_q, &qe);
  2651. cb = (struct bfa_cb_pending_q_s *)qe;
  2652. if (fcport->stats_status == BFA_STATUS_OK) {
  2653. ret = (union bfa_fcport_stats_u *)cb->data;
  2654. /* Swap FC QoS or FCoE stats */
  2655. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
  2656. bfa_fcport_qos_stats_swap(&ret->fcqos,
  2657. &fcport->stats->fcqos);
  2658. else {
  2659. bfa_fcport_fcoe_stats_swap(&ret->fcoe,
  2660. &fcport->stats->fcoe);
  2661. ret->fcoe.secs_reset =
  2662. tv.tv_sec - fcport->stats_reset_time;
  2663. }
  2664. }
  2665. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2666. fcport->stats_status);
  2667. }
  2668. fcport->stats_status = BFA_STATUS_OK;
  2669. } else {
  2670. INIT_LIST_HEAD(&fcport->stats_pending_q);
  2671. fcport->stats_status = BFA_STATUS_OK;
  2672. }
  2673. }
  2674. static void
  2675. bfa_fcport_stats_get_timeout(void *cbarg)
  2676. {
  2677. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2678. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2679. if (fcport->stats_qfull) {
  2680. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2681. fcport->stats_qfull = BFA_FALSE;
  2682. }
  2683. fcport->stats_status = BFA_STATUS_ETIMER;
  2684. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  2685. }
  2686. static void
  2687. bfa_fcport_send_stats_get(void *cbarg)
  2688. {
  2689. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2690. struct bfi_fcport_req_s *msg;
  2691. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2692. if (!msg) {
  2693. fcport->stats_qfull = BFA_TRUE;
  2694. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2695. bfa_fcport_send_stats_get, fcport);
  2696. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2697. &fcport->stats_reqq_wait);
  2698. return;
  2699. }
  2700. fcport->stats_qfull = BFA_FALSE;
  2701. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2702. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  2703. bfa_fn_lpu(fcport->bfa));
  2704. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2705. }
  2706. static void
  2707. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  2708. {
  2709. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2710. struct bfa_cb_pending_q_s *cb;
  2711. struct list_head *qe, *qen;
  2712. if (complete) {
  2713. struct timeval tv;
  2714. /*
  2715. * re-initialize time stamp for stats reset
  2716. */
  2717. do_gettimeofday(&tv);
  2718. fcport->stats_reset_time = tv.tv_sec;
  2719. list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) {
  2720. bfa_q_deq(&fcport->statsclr_pending_q, &qe);
  2721. cb = (struct bfa_cb_pending_q_s *)qe;
  2722. bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe,
  2723. fcport->stats_status);
  2724. }
  2725. fcport->stats_status = BFA_STATUS_OK;
  2726. } else {
  2727. INIT_LIST_HEAD(&fcport->statsclr_pending_q);
  2728. fcport->stats_status = BFA_STATUS_OK;
  2729. }
  2730. }
  2731. static void
  2732. bfa_fcport_stats_clr_timeout(void *cbarg)
  2733. {
  2734. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2735. bfa_trc(fcport->bfa, fcport->stats_qfull);
  2736. if (fcport->stats_qfull) {
  2737. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  2738. fcport->stats_qfull = BFA_FALSE;
  2739. }
  2740. fcport->stats_status = BFA_STATUS_ETIMER;
  2741. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  2742. }
  2743. static void
  2744. bfa_fcport_send_stats_clear(void *cbarg)
  2745. {
  2746. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  2747. struct bfi_fcport_req_s *msg;
  2748. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  2749. if (!msg) {
  2750. fcport->stats_qfull = BFA_TRUE;
  2751. bfa_reqq_winit(&fcport->stats_reqq_wait,
  2752. bfa_fcport_send_stats_clear, fcport);
  2753. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  2754. &fcport->stats_reqq_wait);
  2755. return;
  2756. }
  2757. fcport->stats_qfull = BFA_FALSE;
  2758. memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  2759. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  2760. bfa_fn_lpu(fcport->bfa));
  2761. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh);
  2762. }
  2763. /*
  2764. * Handle trunk SCN event from firmware.
  2765. */
  2766. static void
  2767. bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn)
  2768. {
  2769. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2770. struct bfi_fcport_trunk_link_s *tlink;
  2771. struct bfa_trunk_link_attr_s *lattr;
  2772. enum bfa_trunk_state state_prev;
  2773. int i;
  2774. int link_bm = 0;
  2775. bfa_trc(fcport->bfa, fcport->cfg.trunked);
  2776. WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE &&
  2777. scn->trunk_state != BFA_TRUNK_OFFLINE);
  2778. bfa_trc(fcport->bfa, trunk->attr.state);
  2779. bfa_trc(fcport->bfa, scn->trunk_state);
  2780. bfa_trc(fcport->bfa, scn->trunk_speed);
  2781. /*
  2782. * Save off new state for trunk attribute query
  2783. */
  2784. state_prev = trunk->attr.state;
  2785. if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED))
  2786. trunk->attr.state = scn->trunk_state;
  2787. trunk->attr.speed = scn->trunk_speed;
  2788. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2789. lattr = &trunk->attr.link_attr[i];
  2790. tlink = &scn->tlink[i];
  2791. lattr->link_state = tlink->state;
  2792. lattr->trunk_wwn = tlink->trunk_wwn;
  2793. lattr->fctl = tlink->fctl;
  2794. lattr->speed = tlink->speed;
  2795. lattr->deskew = be32_to_cpu(tlink->deskew);
  2796. if (tlink->state == BFA_TRUNK_LINK_STATE_UP) {
  2797. fcport->speed = tlink->speed;
  2798. fcport->topology = BFA_PORT_TOPOLOGY_P2P;
  2799. link_bm |= 1 << i;
  2800. }
  2801. bfa_trc(fcport->bfa, lattr->link_state);
  2802. bfa_trc(fcport->bfa, lattr->trunk_wwn);
  2803. bfa_trc(fcport->bfa, lattr->fctl);
  2804. bfa_trc(fcport->bfa, lattr->speed);
  2805. bfa_trc(fcport->bfa, lattr->deskew);
  2806. }
  2807. switch (link_bm) {
  2808. case 3:
  2809. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2810. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)");
  2811. break;
  2812. case 2:
  2813. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2814. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)");
  2815. break;
  2816. case 1:
  2817. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2818. BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)");
  2819. break;
  2820. default:
  2821. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  2822. BFA_PL_EID_TRUNK_SCN, 0, "Trunk down");
  2823. }
  2824. /*
  2825. * Notify upper layers if trunk state changed.
  2826. */
  2827. if ((state_prev != trunk->attr.state) ||
  2828. (scn->trunk_state == BFA_TRUNK_OFFLINE)) {
  2829. bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ?
  2830. BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE);
  2831. }
  2832. }
  2833. static void
  2834. bfa_trunk_iocdisable(struct bfa_s *bfa)
  2835. {
  2836. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2837. int i = 0;
  2838. /*
  2839. * In trunked mode, notify upper layers that link is down
  2840. */
  2841. if (fcport->cfg.trunked) {
  2842. if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE)
  2843. bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE);
  2844. fcport->trunk.attr.state = BFA_TRUNK_OFFLINE;
  2845. fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN;
  2846. for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) {
  2847. fcport->trunk.attr.link_attr[i].trunk_wwn = 0;
  2848. fcport->trunk.attr.link_attr[i].fctl =
  2849. BFA_TRUNK_LINK_FCTL_NORMAL;
  2850. fcport->trunk.attr.link_attr[i].link_state =
  2851. BFA_TRUNK_LINK_STATE_DN_LINKDN;
  2852. fcport->trunk.attr.link_attr[i].speed =
  2853. BFA_PORT_SPEED_UNKNOWN;
  2854. fcport->trunk.attr.link_attr[i].deskew = 0;
  2855. }
  2856. }
  2857. }
  2858. /*
  2859. * Called to initialize port attributes
  2860. */
  2861. void
  2862. bfa_fcport_init(struct bfa_s *bfa)
  2863. {
  2864. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2865. /*
  2866. * Initialize port attributes from IOC hardware data.
  2867. */
  2868. bfa_fcport_set_wwns(fcport);
  2869. if (fcport->cfg.maxfrsize == 0)
  2870. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  2871. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  2872. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  2873. if (bfa_fcport_is_pbcdisabled(bfa))
  2874. bfa->modules.port.pbc_disabled = BFA_TRUE;
  2875. WARN_ON(!fcport->cfg.maxfrsize);
  2876. WARN_ON(!fcport->cfg.rx_bbcredit);
  2877. WARN_ON(!fcport->speed_sup);
  2878. }
  2879. /*
  2880. * Firmware message handler.
  2881. */
  2882. void
  2883. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  2884. {
  2885. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2886. union bfi_fcport_i2h_msg_u i2hmsg;
  2887. i2hmsg.msg = msg;
  2888. fcport->event_arg.i2hmsg = i2hmsg;
  2889. bfa_trc(bfa, msg->mhdr.msg_id);
  2890. bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm));
  2891. switch (msg->mhdr.msg_id) {
  2892. case BFI_FCPORT_I2H_ENABLE_RSP:
  2893. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) {
  2894. if (fcport->use_flash_cfg) {
  2895. fcport->cfg = i2hmsg.penable_rsp->port_cfg;
  2896. fcport->cfg.maxfrsize =
  2897. cpu_to_be16(fcport->cfg.maxfrsize);
  2898. fcport->cfg.path_tov =
  2899. cpu_to_be16(fcport->cfg.path_tov);
  2900. fcport->cfg.q_depth =
  2901. cpu_to_be16(fcport->cfg.q_depth);
  2902. if (fcport->cfg.trunked)
  2903. fcport->trunk.attr.state =
  2904. BFA_TRUNK_OFFLINE;
  2905. else
  2906. fcport->trunk.attr.state =
  2907. BFA_TRUNK_DISABLED;
  2908. fcport->use_flash_cfg = BFA_FALSE;
  2909. }
  2910. if (fcport->cfg.qos_enabled)
  2911. fcport->qos_attr.state = BFA_QOS_OFFLINE;
  2912. else
  2913. fcport->qos_attr.state = BFA_QOS_DISABLED;
  2914. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2915. }
  2916. break;
  2917. case BFI_FCPORT_I2H_DISABLE_RSP:
  2918. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  2919. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  2920. break;
  2921. case BFI_FCPORT_I2H_EVENT:
  2922. if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP)
  2923. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  2924. else
  2925. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  2926. break;
  2927. case BFI_FCPORT_I2H_TRUNK_SCN:
  2928. bfa_trunk_scn(fcport, i2hmsg.trunk_scn);
  2929. break;
  2930. case BFI_FCPORT_I2H_STATS_GET_RSP:
  2931. /*
  2932. * check for timer pop before processing the rsp
  2933. */
  2934. if (list_empty(&fcport->stats_pending_q) ||
  2935. (fcport->stats_status == BFA_STATUS_ETIMER))
  2936. break;
  2937. bfa_timer_stop(&fcport->timer);
  2938. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  2939. __bfa_cb_fcport_stats_get(fcport, BFA_TRUE);
  2940. break;
  2941. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  2942. /*
  2943. * check for timer pop before processing the rsp
  2944. */
  2945. if (list_empty(&fcport->statsclr_pending_q) ||
  2946. (fcport->stats_status == BFA_STATUS_ETIMER))
  2947. break;
  2948. bfa_timer_stop(&fcport->timer);
  2949. fcport->stats_status = BFA_STATUS_OK;
  2950. __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE);
  2951. break;
  2952. case BFI_FCPORT_I2H_ENABLE_AEN:
  2953. bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE);
  2954. break;
  2955. case BFI_FCPORT_I2H_DISABLE_AEN:
  2956. bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE);
  2957. break;
  2958. default:
  2959. WARN_ON(1);
  2960. break;
  2961. }
  2962. }
  2963. /*
  2964. * Registered callback for port events.
  2965. */
  2966. void
  2967. bfa_fcport_event_register(struct bfa_s *bfa,
  2968. void (*cbfn) (void *cbarg,
  2969. enum bfa_port_linkstate event),
  2970. void *cbarg)
  2971. {
  2972. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2973. fcport->event_cbfn = cbfn;
  2974. fcport->event_cbarg = cbarg;
  2975. }
  2976. bfa_status_t
  2977. bfa_fcport_enable(struct bfa_s *bfa)
  2978. {
  2979. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  2980. if (bfa_fcport_is_pbcdisabled(bfa))
  2981. return BFA_STATUS_PBC;
  2982. if (bfa_ioc_is_disabled(&bfa->ioc))
  2983. return BFA_STATUS_IOC_DISABLED;
  2984. if (fcport->diag_busy)
  2985. return BFA_STATUS_DIAG_BUSY;
  2986. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  2987. return BFA_STATUS_OK;
  2988. }
  2989. bfa_status_t
  2990. bfa_fcport_disable(struct bfa_s *bfa)
  2991. {
  2992. if (bfa_fcport_is_pbcdisabled(bfa))
  2993. return BFA_STATUS_PBC;
  2994. if (bfa_ioc_is_disabled(&bfa->ioc))
  2995. return BFA_STATUS_IOC_DISABLED;
  2996. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  2997. return BFA_STATUS_OK;
  2998. }
  2999. /* If PBC is disabled on port, return error */
  3000. bfa_status_t
  3001. bfa_fcport_is_pbcdisabled(struct bfa_s *bfa)
  3002. {
  3003. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3004. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  3005. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  3006. if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) {
  3007. bfa_trc(bfa, fcport->pwwn);
  3008. return BFA_STATUS_PBC;
  3009. }
  3010. return BFA_STATUS_OK;
  3011. }
  3012. /*
  3013. * Configure port speed.
  3014. */
  3015. bfa_status_t
  3016. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed)
  3017. {
  3018. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3019. bfa_trc(bfa, speed);
  3020. if (fcport->cfg.trunked == BFA_TRUE)
  3021. return BFA_STATUS_TRUNK_ENABLED;
  3022. if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  3023. bfa_trc(bfa, fcport->speed_sup);
  3024. return BFA_STATUS_UNSUPP_SPEED;
  3025. }
  3026. /* Port speed entered needs to be checked */
  3027. if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
  3028. /* For CT2, 1G is not supported */
  3029. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  3030. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
  3031. return BFA_STATUS_UNSUPP_SPEED;
  3032. /* Already checked for Auto Speed and Max Speed supp */
  3033. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  3034. speed == BFA_PORT_SPEED_2GBPS ||
  3035. speed == BFA_PORT_SPEED_4GBPS ||
  3036. speed == BFA_PORT_SPEED_8GBPS ||
  3037. speed == BFA_PORT_SPEED_16GBPS ||
  3038. speed == BFA_PORT_SPEED_AUTO))
  3039. return BFA_STATUS_UNSUPP_SPEED;
  3040. } else {
  3041. if (speed != BFA_PORT_SPEED_10GBPS)
  3042. return BFA_STATUS_UNSUPP_SPEED;
  3043. }
  3044. fcport->cfg.speed = speed;
  3045. return BFA_STATUS_OK;
  3046. }
  3047. /*
  3048. * Get current speed.
  3049. */
  3050. enum bfa_port_speed
  3051. bfa_fcport_get_speed(struct bfa_s *bfa)
  3052. {
  3053. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3054. return fcport->speed;
  3055. }
  3056. /*
  3057. * Configure port topology.
  3058. */
  3059. bfa_status_t
  3060. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology)
  3061. {
  3062. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3063. bfa_trc(bfa, topology);
  3064. bfa_trc(bfa, fcport->cfg.topology);
  3065. switch (topology) {
  3066. case BFA_PORT_TOPOLOGY_P2P:
  3067. case BFA_PORT_TOPOLOGY_LOOP:
  3068. case BFA_PORT_TOPOLOGY_AUTO:
  3069. break;
  3070. default:
  3071. return BFA_STATUS_EINVAL;
  3072. }
  3073. fcport->cfg.topology = topology;
  3074. return BFA_STATUS_OK;
  3075. }
  3076. /*
  3077. * Get current topology.
  3078. */
  3079. enum bfa_port_topology
  3080. bfa_fcport_get_topology(struct bfa_s *bfa)
  3081. {
  3082. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3083. return fcport->topology;
  3084. }
  3085. bfa_status_t
  3086. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  3087. {
  3088. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3089. bfa_trc(bfa, alpa);
  3090. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3091. bfa_trc(bfa, fcport->cfg.hardalpa);
  3092. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  3093. fcport->cfg.hardalpa = alpa;
  3094. return BFA_STATUS_OK;
  3095. }
  3096. bfa_status_t
  3097. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  3098. {
  3099. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3100. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  3101. bfa_trc(bfa, fcport->cfg.hardalpa);
  3102. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  3103. return BFA_STATUS_OK;
  3104. }
  3105. bfa_boolean_t
  3106. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  3107. {
  3108. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3109. *alpa = fcport->cfg.hardalpa;
  3110. return fcport->cfg.cfg_hardalpa;
  3111. }
  3112. u8
  3113. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  3114. {
  3115. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3116. return fcport->myalpa;
  3117. }
  3118. bfa_status_t
  3119. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  3120. {
  3121. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3122. bfa_trc(bfa, maxfrsize);
  3123. bfa_trc(bfa, fcport->cfg.maxfrsize);
  3124. /* with in range */
  3125. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  3126. return BFA_STATUS_INVLD_DFSZ;
  3127. /* power of 2, if not the max frame size of 2112 */
  3128. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  3129. return BFA_STATUS_INVLD_DFSZ;
  3130. fcport->cfg.maxfrsize = maxfrsize;
  3131. return BFA_STATUS_OK;
  3132. }
  3133. u16
  3134. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  3135. {
  3136. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3137. return fcport->cfg.maxfrsize;
  3138. }
  3139. u8
  3140. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  3141. {
  3142. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3143. return fcport->cfg.rx_bbcredit;
  3144. }
  3145. void
  3146. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn)
  3147. {
  3148. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3149. fcport->cfg.tx_bbcredit = (u8)tx_bbcredit;
  3150. fcport->cfg.bb_scn = bb_scn;
  3151. if (bb_scn)
  3152. fcport->bbsc_op_state = BFA_TRUE;
  3153. }
  3154. /*
  3155. * Get port attributes.
  3156. */
  3157. wwn_t
  3158. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  3159. {
  3160. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3161. if (node)
  3162. return fcport->nwwn;
  3163. else
  3164. return fcport->pwwn;
  3165. }
  3166. void
  3167. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr)
  3168. {
  3169. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3170. memset(attr, 0, sizeof(struct bfa_port_attr_s));
  3171. attr->nwwn = fcport->nwwn;
  3172. attr->pwwn = fcport->pwwn;
  3173. attr->factorypwwn = bfa->ioc.attr->mfg_pwwn;
  3174. attr->factorynwwn = bfa->ioc.attr->mfg_nwwn;
  3175. memcpy(&attr->pport_cfg, &fcport->cfg,
  3176. sizeof(struct bfa_port_cfg_s));
  3177. /* speed attributes */
  3178. attr->pport_cfg.speed = fcport->cfg.speed;
  3179. attr->speed_supported = fcport->speed_sup;
  3180. attr->speed = fcport->speed;
  3181. attr->cos_supported = FC_CLASS_3;
  3182. /* topology attributes */
  3183. attr->pport_cfg.topology = fcport->cfg.topology;
  3184. attr->topology = fcport->topology;
  3185. attr->pport_cfg.trunked = fcport->cfg.trunked;
  3186. /* beacon attributes */
  3187. attr->beacon = fcport->beacon;
  3188. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  3189. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  3190. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  3191. attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm);
  3192. attr->bbsc_op_status = fcport->bbsc_op_state;
  3193. /* PBC Disabled State */
  3194. if (bfa_fcport_is_pbcdisabled(bfa))
  3195. attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED;
  3196. else {
  3197. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  3198. attr->port_state = BFA_PORT_ST_IOCDIS;
  3199. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  3200. attr->port_state = BFA_PORT_ST_FWMISMATCH;
  3201. }
  3202. /* FCoE vlan */
  3203. attr->fcoe_vlan = fcport->fcoe_vlan;
  3204. }
  3205. #define BFA_FCPORT_STATS_TOV 1000
  3206. /*
  3207. * Fetch port statistics (FCQoS or FCoE).
  3208. */
  3209. bfa_status_t
  3210. bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3211. {
  3212. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3213. if (bfa_ioc_is_disabled(&bfa->ioc))
  3214. return BFA_STATUS_IOC_DISABLED;
  3215. if (!list_empty(&fcport->statsclr_pending_q))
  3216. return BFA_STATUS_DEVBUSY;
  3217. if (list_empty(&fcport->stats_pending_q)) {
  3218. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3219. bfa_fcport_send_stats_get(fcport);
  3220. bfa_timer_start(bfa, &fcport->timer,
  3221. bfa_fcport_stats_get_timeout,
  3222. fcport, BFA_FCPORT_STATS_TOV);
  3223. } else
  3224. list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q);
  3225. return BFA_STATUS_OK;
  3226. }
  3227. /*
  3228. * Reset port statistics (FCQoS or FCoE).
  3229. */
  3230. bfa_status_t
  3231. bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb)
  3232. {
  3233. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3234. if (!list_empty(&fcport->stats_pending_q))
  3235. return BFA_STATUS_DEVBUSY;
  3236. if (list_empty(&fcport->statsclr_pending_q)) {
  3237. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3238. bfa_fcport_send_stats_clear(fcport);
  3239. bfa_timer_start(bfa, &fcport->timer,
  3240. bfa_fcport_stats_clr_timeout,
  3241. fcport, BFA_FCPORT_STATS_TOV);
  3242. } else
  3243. list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q);
  3244. return BFA_STATUS_OK;
  3245. }
  3246. /*
  3247. * Fetch port attributes.
  3248. */
  3249. bfa_boolean_t
  3250. bfa_fcport_is_disabled(struct bfa_s *bfa)
  3251. {
  3252. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3253. return bfa_sm_to_state(hal_port_sm_table, fcport->sm) ==
  3254. BFA_PORT_ST_DISABLED;
  3255. }
  3256. bfa_boolean_t
  3257. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  3258. {
  3259. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3260. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  3261. }
  3262. /*
  3263. * Enable/Disable FAA feature in port config
  3264. */
  3265. void
  3266. bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state)
  3267. {
  3268. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3269. bfa_trc(bfa, state);
  3270. fcport->cfg.faa_state = state;
  3271. }
  3272. /*
  3273. * Get default minimum ratelim speed
  3274. */
  3275. enum bfa_port_speed
  3276. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  3277. {
  3278. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3279. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  3280. return fcport->cfg.trl_def_speed;
  3281. }
  3282. void
  3283. bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
  3284. bfa_boolean_t link_e2e_beacon)
  3285. {
  3286. struct bfa_s *bfa = dev;
  3287. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3288. bfa_trc(bfa, beacon);
  3289. bfa_trc(bfa, link_e2e_beacon);
  3290. bfa_trc(bfa, fcport->beacon);
  3291. bfa_trc(bfa, fcport->link_e2e_beacon);
  3292. fcport->beacon = beacon;
  3293. fcport->link_e2e_beacon = link_e2e_beacon;
  3294. }
  3295. bfa_boolean_t
  3296. bfa_fcport_is_linkup(struct bfa_s *bfa)
  3297. {
  3298. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3299. return (!fcport->cfg.trunked &&
  3300. bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) ||
  3301. (fcport->cfg.trunked &&
  3302. fcport->trunk.attr.state == BFA_TRUNK_ONLINE);
  3303. }
  3304. bfa_boolean_t
  3305. bfa_fcport_is_qos_enabled(struct bfa_s *bfa)
  3306. {
  3307. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3308. return fcport->cfg.qos_enabled;
  3309. }
  3310. bfa_boolean_t
  3311. bfa_fcport_is_trunk_enabled(struct bfa_s *bfa)
  3312. {
  3313. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  3314. return fcport->cfg.trunked;
  3315. }
  3316. /*
  3317. * Rport State machine functions
  3318. */
  3319. /*
  3320. * Beginning state, only online event expected.
  3321. */
  3322. static void
  3323. bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3324. {
  3325. bfa_trc(rp->bfa, rp->rport_tag);
  3326. bfa_trc(rp->bfa, event);
  3327. switch (event) {
  3328. case BFA_RPORT_SM_CREATE:
  3329. bfa_stats(rp, sm_un_cr);
  3330. bfa_sm_set_state(rp, bfa_rport_sm_created);
  3331. break;
  3332. default:
  3333. bfa_stats(rp, sm_un_unexp);
  3334. bfa_sm_fault(rp->bfa, event);
  3335. }
  3336. }
  3337. static void
  3338. bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3339. {
  3340. bfa_trc(rp->bfa, rp->rport_tag);
  3341. bfa_trc(rp->bfa, event);
  3342. switch (event) {
  3343. case BFA_RPORT_SM_ONLINE:
  3344. bfa_stats(rp, sm_cr_on);
  3345. if (bfa_rport_send_fwcreate(rp))
  3346. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3347. else
  3348. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3349. break;
  3350. case BFA_RPORT_SM_DELETE:
  3351. bfa_stats(rp, sm_cr_del);
  3352. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3353. bfa_rport_free(rp);
  3354. break;
  3355. case BFA_RPORT_SM_HWFAIL:
  3356. bfa_stats(rp, sm_cr_hwf);
  3357. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3358. break;
  3359. default:
  3360. bfa_stats(rp, sm_cr_unexp);
  3361. bfa_sm_fault(rp->bfa, event);
  3362. }
  3363. }
  3364. /*
  3365. * Waiting for rport create response from firmware.
  3366. */
  3367. static void
  3368. bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3369. {
  3370. bfa_trc(rp->bfa, rp->rport_tag);
  3371. bfa_trc(rp->bfa, event);
  3372. switch (event) {
  3373. case BFA_RPORT_SM_FWRSP:
  3374. bfa_stats(rp, sm_fwc_rsp);
  3375. bfa_sm_set_state(rp, bfa_rport_sm_online);
  3376. bfa_rport_online_cb(rp);
  3377. break;
  3378. case BFA_RPORT_SM_DELETE:
  3379. bfa_stats(rp, sm_fwc_del);
  3380. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3381. break;
  3382. case BFA_RPORT_SM_OFFLINE:
  3383. bfa_stats(rp, sm_fwc_off);
  3384. bfa_sm_set_state(rp, bfa_rport_sm_offline_pending);
  3385. break;
  3386. case BFA_RPORT_SM_HWFAIL:
  3387. bfa_stats(rp, sm_fwc_hwf);
  3388. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3389. break;
  3390. default:
  3391. bfa_stats(rp, sm_fwc_unexp);
  3392. bfa_sm_fault(rp->bfa, event);
  3393. }
  3394. }
  3395. /*
  3396. * Request queue is full, awaiting queue resume to send create request.
  3397. */
  3398. static void
  3399. bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3400. {
  3401. bfa_trc(rp->bfa, rp->rport_tag);
  3402. bfa_trc(rp->bfa, event);
  3403. switch (event) {
  3404. case BFA_RPORT_SM_QRESUME:
  3405. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3406. bfa_rport_send_fwcreate(rp);
  3407. break;
  3408. case BFA_RPORT_SM_DELETE:
  3409. bfa_stats(rp, sm_fwc_del);
  3410. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3411. bfa_reqq_wcancel(&rp->reqq_wait);
  3412. bfa_rport_free(rp);
  3413. break;
  3414. case BFA_RPORT_SM_OFFLINE:
  3415. bfa_stats(rp, sm_fwc_off);
  3416. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3417. bfa_reqq_wcancel(&rp->reqq_wait);
  3418. bfa_rport_offline_cb(rp);
  3419. break;
  3420. case BFA_RPORT_SM_HWFAIL:
  3421. bfa_stats(rp, sm_fwc_hwf);
  3422. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3423. bfa_reqq_wcancel(&rp->reqq_wait);
  3424. break;
  3425. default:
  3426. bfa_stats(rp, sm_fwc_unexp);
  3427. bfa_sm_fault(rp->bfa, event);
  3428. }
  3429. }
  3430. /*
  3431. * Online state - normal parking state.
  3432. */
  3433. static void
  3434. bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3435. {
  3436. struct bfi_rport_qos_scn_s *qos_scn;
  3437. bfa_trc(rp->bfa, rp->rport_tag);
  3438. bfa_trc(rp->bfa, event);
  3439. switch (event) {
  3440. case BFA_RPORT_SM_OFFLINE:
  3441. bfa_stats(rp, sm_on_off);
  3442. if (bfa_rport_send_fwdelete(rp))
  3443. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3444. else
  3445. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3446. break;
  3447. case BFA_RPORT_SM_DELETE:
  3448. bfa_stats(rp, sm_on_del);
  3449. if (bfa_rport_send_fwdelete(rp))
  3450. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3451. else
  3452. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3453. break;
  3454. case BFA_RPORT_SM_HWFAIL:
  3455. bfa_stats(rp, sm_on_hwf);
  3456. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3457. break;
  3458. case BFA_RPORT_SM_SET_SPEED:
  3459. bfa_rport_send_fwspeed(rp);
  3460. break;
  3461. case BFA_RPORT_SM_QOS_SCN:
  3462. qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg;
  3463. rp->qos_attr = qos_scn->new_qos_attr;
  3464. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id);
  3465. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id);
  3466. bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority);
  3467. bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority);
  3468. qos_scn->old_qos_attr.qos_flow_id =
  3469. be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id);
  3470. qos_scn->new_qos_attr.qos_flow_id =
  3471. be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id);
  3472. if (qos_scn->old_qos_attr.qos_flow_id !=
  3473. qos_scn->new_qos_attr.qos_flow_id)
  3474. bfa_cb_rport_qos_scn_flowid(rp->rport_drv,
  3475. qos_scn->old_qos_attr,
  3476. qos_scn->new_qos_attr);
  3477. if (qos_scn->old_qos_attr.qos_priority !=
  3478. qos_scn->new_qos_attr.qos_priority)
  3479. bfa_cb_rport_qos_scn_prio(rp->rport_drv,
  3480. qos_scn->old_qos_attr,
  3481. qos_scn->new_qos_attr);
  3482. break;
  3483. default:
  3484. bfa_stats(rp, sm_on_unexp);
  3485. bfa_sm_fault(rp->bfa, event);
  3486. }
  3487. }
  3488. /*
  3489. * Firmware rport is being deleted - awaiting f/w response.
  3490. */
  3491. static void
  3492. bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3493. {
  3494. bfa_trc(rp->bfa, rp->rport_tag);
  3495. bfa_trc(rp->bfa, event);
  3496. switch (event) {
  3497. case BFA_RPORT_SM_FWRSP:
  3498. bfa_stats(rp, sm_fwd_rsp);
  3499. bfa_sm_set_state(rp, bfa_rport_sm_offline);
  3500. bfa_rport_offline_cb(rp);
  3501. break;
  3502. case BFA_RPORT_SM_DELETE:
  3503. bfa_stats(rp, sm_fwd_del);
  3504. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3505. break;
  3506. case BFA_RPORT_SM_HWFAIL:
  3507. bfa_stats(rp, sm_fwd_hwf);
  3508. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3509. bfa_rport_offline_cb(rp);
  3510. break;
  3511. default:
  3512. bfa_stats(rp, sm_fwd_unexp);
  3513. bfa_sm_fault(rp->bfa, event);
  3514. }
  3515. }
  3516. static void
  3517. bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3518. {
  3519. bfa_trc(rp->bfa, rp->rport_tag);
  3520. bfa_trc(rp->bfa, event);
  3521. switch (event) {
  3522. case BFA_RPORT_SM_QRESUME:
  3523. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3524. bfa_rport_send_fwdelete(rp);
  3525. break;
  3526. case BFA_RPORT_SM_DELETE:
  3527. bfa_stats(rp, sm_fwd_del);
  3528. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3529. break;
  3530. case BFA_RPORT_SM_HWFAIL:
  3531. bfa_stats(rp, sm_fwd_hwf);
  3532. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3533. bfa_reqq_wcancel(&rp->reqq_wait);
  3534. bfa_rport_offline_cb(rp);
  3535. break;
  3536. default:
  3537. bfa_stats(rp, sm_fwd_unexp);
  3538. bfa_sm_fault(rp->bfa, event);
  3539. }
  3540. }
  3541. /*
  3542. * Offline state.
  3543. */
  3544. static void
  3545. bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3546. {
  3547. bfa_trc(rp->bfa, rp->rport_tag);
  3548. bfa_trc(rp->bfa, event);
  3549. switch (event) {
  3550. case BFA_RPORT_SM_DELETE:
  3551. bfa_stats(rp, sm_off_del);
  3552. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3553. bfa_rport_free(rp);
  3554. break;
  3555. case BFA_RPORT_SM_ONLINE:
  3556. bfa_stats(rp, sm_off_on);
  3557. if (bfa_rport_send_fwcreate(rp))
  3558. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3559. else
  3560. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3561. break;
  3562. case BFA_RPORT_SM_HWFAIL:
  3563. bfa_stats(rp, sm_off_hwf);
  3564. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3565. break;
  3566. default:
  3567. bfa_stats(rp, sm_off_unexp);
  3568. bfa_sm_fault(rp->bfa, event);
  3569. }
  3570. }
  3571. /*
  3572. * Rport is deleted, waiting for firmware response to delete.
  3573. */
  3574. static void
  3575. bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3576. {
  3577. bfa_trc(rp->bfa, rp->rport_tag);
  3578. bfa_trc(rp->bfa, event);
  3579. switch (event) {
  3580. case BFA_RPORT_SM_FWRSP:
  3581. bfa_stats(rp, sm_del_fwrsp);
  3582. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3583. bfa_rport_free(rp);
  3584. break;
  3585. case BFA_RPORT_SM_HWFAIL:
  3586. bfa_stats(rp, sm_del_hwf);
  3587. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3588. bfa_rport_free(rp);
  3589. break;
  3590. default:
  3591. bfa_sm_fault(rp->bfa, event);
  3592. }
  3593. }
  3594. static void
  3595. bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3596. {
  3597. bfa_trc(rp->bfa, rp->rport_tag);
  3598. bfa_trc(rp->bfa, event);
  3599. switch (event) {
  3600. case BFA_RPORT_SM_QRESUME:
  3601. bfa_stats(rp, sm_del_fwrsp);
  3602. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3603. bfa_rport_send_fwdelete(rp);
  3604. break;
  3605. case BFA_RPORT_SM_HWFAIL:
  3606. bfa_stats(rp, sm_del_hwf);
  3607. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3608. bfa_reqq_wcancel(&rp->reqq_wait);
  3609. bfa_rport_free(rp);
  3610. break;
  3611. default:
  3612. bfa_sm_fault(rp->bfa, event);
  3613. }
  3614. }
  3615. /*
  3616. * Waiting for rport create response from firmware. A delete is pending.
  3617. */
  3618. static void
  3619. bfa_rport_sm_delete_pending(struct bfa_rport_s *rp,
  3620. enum bfa_rport_event event)
  3621. {
  3622. bfa_trc(rp->bfa, rp->rport_tag);
  3623. bfa_trc(rp->bfa, event);
  3624. switch (event) {
  3625. case BFA_RPORT_SM_FWRSP:
  3626. bfa_stats(rp, sm_delp_fwrsp);
  3627. if (bfa_rport_send_fwdelete(rp))
  3628. bfa_sm_set_state(rp, bfa_rport_sm_deleting);
  3629. else
  3630. bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull);
  3631. break;
  3632. case BFA_RPORT_SM_HWFAIL:
  3633. bfa_stats(rp, sm_delp_hwf);
  3634. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3635. bfa_rport_free(rp);
  3636. break;
  3637. default:
  3638. bfa_stats(rp, sm_delp_unexp);
  3639. bfa_sm_fault(rp->bfa, event);
  3640. }
  3641. }
  3642. /*
  3643. * Waiting for rport create response from firmware. Rport offline is pending.
  3644. */
  3645. static void
  3646. bfa_rport_sm_offline_pending(struct bfa_rport_s *rp,
  3647. enum bfa_rport_event event)
  3648. {
  3649. bfa_trc(rp->bfa, rp->rport_tag);
  3650. bfa_trc(rp->bfa, event);
  3651. switch (event) {
  3652. case BFA_RPORT_SM_FWRSP:
  3653. bfa_stats(rp, sm_offp_fwrsp);
  3654. if (bfa_rport_send_fwdelete(rp))
  3655. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete);
  3656. else
  3657. bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull);
  3658. break;
  3659. case BFA_RPORT_SM_DELETE:
  3660. bfa_stats(rp, sm_offp_del);
  3661. bfa_sm_set_state(rp, bfa_rport_sm_delete_pending);
  3662. break;
  3663. case BFA_RPORT_SM_HWFAIL:
  3664. bfa_stats(rp, sm_offp_hwf);
  3665. bfa_sm_set_state(rp, bfa_rport_sm_iocdisable);
  3666. break;
  3667. default:
  3668. bfa_stats(rp, sm_offp_unexp);
  3669. bfa_sm_fault(rp->bfa, event);
  3670. }
  3671. }
  3672. /*
  3673. * IOC h/w failed.
  3674. */
  3675. static void
  3676. bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event)
  3677. {
  3678. bfa_trc(rp->bfa, rp->rport_tag);
  3679. bfa_trc(rp->bfa, event);
  3680. switch (event) {
  3681. case BFA_RPORT_SM_OFFLINE:
  3682. bfa_stats(rp, sm_iocd_off);
  3683. bfa_rport_offline_cb(rp);
  3684. break;
  3685. case BFA_RPORT_SM_DELETE:
  3686. bfa_stats(rp, sm_iocd_del);
  3687. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3688. bfa_rport_free(rp);
  3689. break;
  3690. case BFA_RPORT_SM_ONLINE:
  3691. bfa_stats(rp, sm_iocd_on);
  3692. if (bfa_rport_send_fwcreate(rp))
  3693. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate);
  3694. else
  3695. bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull);
  3696. break;
  3697. case BFA_RPORT_SM_HWFAIL:
  3698. break;
  3699. default:
  3700. bfa_stats(rp, sm_iocd_unexp);
  3701. bfa_sm_fault(rp->bfa, event);
  3702. }
  3703. }
  3704. /*
  3705. * bfa_rport_private BFA rport private functions
  3706. */
  3707. static void
  3708. __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete)
  3709. {
  3710. struct bfa_rport_s *rp = cbarg;
  3711. if (complete)
  3712. bfa_cb_rport_online(rp->rport_drv);
  3713. }
  3714. static void
  3715. __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete)
  3716. {
  3717. struct bfa_rport_s *rp = cbarg;
  3718. if (complete)
  3719. bfa_cb_rport_offline(rp->rport_drv);
  3720. }
  3721. static void
  3722. bfa_rport_qresume(void *cbarg)
  3723. {
  3724. struct bfa_rport_s *rp = cbarg;
  3725. bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME);
  3726. }
  3727. static void
  3728. bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  3729. struct bfa_s *bfa)
  3730. {
  3731. struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa);
  3732. if (cfg->fwcfg.num_rports < BFA_RPORT_MIN)
  3733. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  3734. /* kva memory */
  3735. bfa_mem_kva_setup(minfo, rport_kva,
  3736. cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s));
  3737. }
  3738. static void
  3739. bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  3740. struct bfa_pcidev_s *pcidev)
  3741. {
  3742. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3743. struct bfa_rport_s *rp;
  3744. u16 i;
  3745. INIT_LIST_HEAD(&mod->rp_free_q);
  3746. INIT_LIST_HEAD(&mod->rp_active_q);
  3747. INIT_LIST_HEAD(&mod->rp_unused_q);
  3748. rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod);
  3749. mod->rps_list = rp;
  3750. mod->num_rports = cfg->fwcfg.num_rports;
  3751. WARN_ON(!mod->num_rports ||
  3752. (mod->num_rports & (mod->num_rports - 1)));
  3753. for (i = 0; i < mod->num_rports; i++, rp++) {
  3754. memset(rp, 0, sizeof(struct bfa_rport_s));
  3755. rp->bfa = bfa;
  3756. rp->rport_tag = i;
  3757. bfa_sm_set_state(rp, bfa_rport_sm_uninit);
  3758. /*
  3759. * - is unused
  3760. */
  3761. if (i)
  3762. list_add_tail(&rp->qe, &mod->rp_free_q);
  3763. bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp);
  3764. }
  3765. /*
  3766. * consume memory
  3767. */
  3768. bfa_mem_kva_curp(mod) = (u8 *) rp;
  3769. }
  3770. static void
  3771. bfa_rport_detach(struct bfa_s *bfa)
  3772. {
  3773. }
  3774. static void
  3775. bfa_rport_start(struct bfa_s *bfa)
  3776. {
  3777. }
  3778. static void
  3779. bfa_rport_stop(struct bfa_s *bfa)
  3780. {
  3781. }
  3782. static void
  3783. bfa_rport_iocdisable(struct bfa_s *bfa)
  3784. {
  3785. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3786. struct bfa_rport_s *rport;
  3787. struct list_head *qe, *qen;
  3788. /* Enqueue unused rport resources to free_q */
  3789. list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q);
  3790. list_for_each_safe(qe, qen, &mod->rp_active_q) {
  3791. rport = (struct bfa_rport_s *) qe;
  3792. bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL);
  3793. }
  3794. }
  3795. static struct bfa_rport_s *
  3796. bfa_rport_alloc(struct bfa_rport_mod_s *mod)
  3797. {
  3798. struct bfa_rport_s *rport;
  3799. bfa_q_deq(&mod->rp_free_q, &rport);
  3800. if (rport)
  3801. list_add_tail(&rport->qe, &mod->rp_active_q);
  3802. return rport;
  3803. }
  3804. static void
  3805. bfa_rport_free(struct bfa_rport_s *rport)
  3806. {
  3807. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa);
  3808. WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport));
  3809. list_del(&rport->qe);
  3810. list_add_tail(&rport->qe, &mod->rp_free_q);
  3811. }
  3812. static bfa_boolean_t
  3813. bfa_rport_send_fwcreate(struct bfa_rport_s *rp)
  3814. {
  3815. struct bfi_rport_create_req_s *m;
  3816. /*
  3817. * check for room in queue to send request now
  3818. */
  3819. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3820. if (!m) {
  3821. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3822. return BFA_FALSE;
  3823. }
  3824. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ,
  3825. bfa_fn_lpu(rp->bfa));
  3826. m->bfa_handle = rp->rport_tag;
  3827. m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz);
  3828. m->pid = rp->rport_info.pid;
  3829. m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag);
  3830. m->local_pid = rp->rport_info.local_pid;
  3831. m->fc_class = rp->rport_info.fc_class;
  3832. m->vf_en = rp->rport_info.vf_en;
  3833. m->vf_id = rp->rport_info.vf_id;
  3834. m->cisc = rp->rport_info.cisc;
  3835. /*
  3836. * queue I/O message to firmware
  3837. */
  3838. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  3839. return BFA_TRUE;
  3840. }
  3841. static bfa_boolean_t
  3842. bfa_rport_send_fwdelete(struct bfa_rport_s *rp)
  3843. {
  3844. struct bfi_rport_delete_req_s *m;
  3845. /*
  3846. * check for room in queue to send request now
  3847. */
  3848. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3849. if (!m) {
  3850. bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait);
  3851. return BFA_FALSE;
  3852. }
  3853. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ,
  3854. bfa_fn_lpu(rp->bfa));
  3855. m->fw_handle = rp->fw_handle;
  3856. /*
  3857. * queue I/O message to firmware
  3858. */
  3859. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  3860. return BFA_TRUE;
  3861. }
  3862. static bfa_boolean_t
  3863. bfa_rport_send_fwspeed(struct bfa_rport_s *rp)
  3864. {
  3865. struct bfa_rport_speed_req_s *m;
  3866. /*
  3867. * check for room in queue to send request now
  3868. */
  3869. m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT);
  3870. if (!m) {
  3871. bfa_trc(rp->bfa, rp->rport_info.speed);
  3872. return BFA_FALSE;
  3873. }
  3874. bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ,
  3875. bfa_fn_lpu(rp->bfa));
  3876. m->fw_handle = rp->fw_handle;
  3877. m->speed = (u8)rp->rport_info.speed;
  3878. /*
  3879. * queue I/O message to firmware
  3880. */
  3881. bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh);
  3882. return BFA_TRUE;
  3883. }
  3884. /*
  3885. * bfa_rport_public
  3886. */
  3887. /*
  3888. * Rport interrupt processing.
  3889. */
  3890. void
  3891. bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
  3892. {
  3893. union bfi_rport_i2h_msg_u msg;
  3894. struct bfa_rport_s *rp;
  3895. bfa_trc(bfa, m->mhdr.msg_id);
  3896. msg.msg = m;
  3897. switch (m->mhdr.msg_id) {
  3898. case BFI_RPORT_I2H_CREATE_RSP:
  3899. rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle);
  3900. rp->fw_handle = msg.create_rsp->fw_handle;
  3901. rp->qos_attr = msg.create_rsp->qos_attr;
  3902. bfa_rport_set_lunmask(bfa, rp);
  3903. WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
  3904. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3905. break;
  3906. case BFI_RPORT_I2H_DELETE_RSP:
  3907. rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle);
  3908. WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
  3909. bfa_rport_unset_lunmask(bfa, rp);
  3910. bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP);
  3911. break;
  3912. case BFI_RPORT_I2H_QOS_SCN:
  3913. rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle);
  3914. rp->event_arg.fw_msg = msg.qos_scn_evt;
  3915. bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN);
  3916. break;
  3917. default:
  3918. bfa_trc(bfa, m->mhdr.msg_id);
  3919. WARN_ON(1);
  3920. }
  3921. }
  3922. void
  3923. bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw)
  3924. {
  3925. struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa);
  3926. struct list_head *qe;
  3927. int i;
  3928. for (i = 0; i < (mod->num_rports - num_rport_fw); i++) {
  3929. bfa_q_deq_tail(&mod->rp_free_q, &qe);
  3930. list_add_tail(qe, &mod->rp_unused_q);
  3931. }
  3932. }
  3933. /*
  3934. * bfa_rport_api
  3935. */
  3936. struct bfa_rport_s *
  3937. bfa_rport_create(struct bfa_s *bfa, void *rport_drv)
  3938. {
  3939. struct bfa_rport_s *rp;
  3940. rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa));
  3941. if (rp == NULL)
  3942. return NULL;
  3943. rp->bfa = bfa;
  3944. rp->rport_drv = rport_drv;
  3945. memset(&rp->stats, 0, sizeof(rp->stats));
  3946. WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit));
  3947. bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE);
  3948. return rp;
  3949. }
  3950. void
  3951. bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info)
  3952. {
  3953. WARN_ON(rport_info->max_frmsz == 0);
  3954. /*
  3955. * Some JBODs are seen to be not setting PDU size correctly in PLOGI
  3956. * responses. Default to minimum size.
  3957. */
  3958. if (rport_info->max_frmsz == 0) {
  3959. bfa_trc(rport->bfa, rport->rport_tag);
  3960. rport_info->max_frmsz = FC_MIN_PDUSZ;
  3961. }
  3962. rport->rport_info = *rport_info;
  3963. bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE);
  3964. }
  3965. void
  3966. bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed)
  3967. {
  3968. WARN_ON(speed == 0);
  3969. WARN_ON(speed == BFA_PORT_SPEED_AUTO);
  3970. rport->rport_info.speed = speed;
  3971. bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED);
  3972. }
  3973. /* Set Rport LUN Mask */
  3974. void
  3975. bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  3976. {
  3977. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  3978. wwn_t lp_wwn, rp_wwn;
  3979. u8 lp_tag = (u8)rp->rport_info.lp_tag;
  3980. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  3981. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  3982. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  3983. rp->lun_mask = BFA_TRUE;
  3984. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag);
  3985. }
  3986. /* Unset Rport LUN mask */
  3987. void
  3988. bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp)
  3989. {
  3990. struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa);
  3991. wwn_t lp_wwn, rp_wwn;
  3992. rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn;
  3993. lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn;
  3994. BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask =
  3995. rp->lun_mask = BFA_FALSE;
  3996. bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn,
  3997. BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID);
  3998. }
  3999. /*
  4000. * SGPG related functions
  4001. */
  4002. /*
  4003. * Compute and return memory needed by FCP(im) module.
  4004. */
  4005. static void
  4006. bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4007. struct bfa_s *bfa)
  4008. {
  4009. struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa);
  4010. struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa);
  4011. struct bfa_mem_dma_s *seg_ptr;
  4012. u16 nsegs, idx, per_seg_sgpg, num_sgpg;
  4013. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4014. if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN)
  4015. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  4016. else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX)
  4017. cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX;
  4018. num_sgpg = cfg->drvcfg.num_sgpgs;
  4019. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4020. per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz);
  4021. bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) {
  4022. if (num_sgpg >= per_seg_sgpg) {
  4023. num_sgpg -= per_seg_sgpg;
  4024. bfa_mem_dma_setup(minfo, seg_ptr,
  4025. per_seg_sgpg * sgpg_sz);
  4026. } else
  4027. bfa_mem_dma_setup(minfo, seg_ptr,
  4028. num_sgpg * sgpg_sz);
  4029. }
  4030. /* kva memory */
  4031. bfa_mem_kva_setup(minfo, sgpg_kva,
  4032. cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s));
  4033. }
  4034. static void
  4035. bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4036. struct bfa_pcidev_s *pcidev)
  4037. {
  4038. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4039. struct bfa_sgpg_s *hsgpg;
  4040. struct bfi_sgpg_s *sgpg;
  4041. u64 align_len;
  4042. struct bfa_mem_dma_s *seg_ptr;
  4043. u32 sgpg_sz = sizeof(struct bfi_sgpg_s);
  4044. u16 i, idx, nsegs, per_seg_sgpg, num_sgpg;
  4045. union {
  4046. u64 pa;
  4047. union bfi_addr_u addr;
  4048. } sgpg_pa, sgpg_pa_tmp;
  4049. INIT_LIST_HEAD(&mod->sgpg_q);
  4050. INIT_LIST_HEAD(&mod->sgpg_wait_q);
  4051. bfa_trc(bfa, cfg->drvcfg.num_sgpgs);
  4052. mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs;
  4053. num_sgpg = cfg->drvcfg.num_sgpgs;
  4054. nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz);
  4055. /* dma/kva mem claim */
  4056. hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod);
  4057. bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) {
  4058. if (!bfa_mem_dma_virt(seg_ptr))
  4059. break;
  4060. align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) -
  4061. bfa_mem_dma_phys(seg_ptr);
  4062. sgpg = (struct bfi_sgpg_s *)
  4063. (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len);
  4064. sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len;
  4065. WARN_ON(sgpg_pa.pa & (sgpg_sz - 1));
  4066. per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz;
  4067. for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) {
  4068. memset(hsgpg, 0, sizeof(*hsgpg));
  4069. memset(sgpg, 0, sizeof(*sgpg));
  4070. hsgpg->sgpg = sgpg;
  4071. sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa);
  4072. hsgpg->sgpg_pa = sgpg_pa_tmp.addr;
  4073. list_add_tail(&hsgpg->qe, &mod->sgpg_q);
  4074. sgpg++;
  4075. hsgpg++;
  4076. sgpg_pa.pa += sgpg_sz;
  4077. }
  4078. }
  4079. bfa_mem_kva_curp(mod) = (u8 *) hsgpg;
  4080. }
  4081. static void
  4082. bfa_sgpg_detach(struct bfa_s *bfa)
  4083. {
  4084. }
  4085. static void
  4086. bfa_sgpg_start(struct bfa_s *bfa)
  4087. {
  4088. }
  4089. static void
  4090. bfa_sgpg_stop(struct bfa_s *bfa)
  4091. {
  4092. }
  4093. static void
  4094. bfa_sgpg_iocdisable(struct bfa_s *bfa)
  4095. {
  4096. }
  4097. bfa_status_t
  4098. bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs)
  4099. {
  4100. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4101. struct bfa_sgpg_s *hsgpg;
  4102. int i;
  4103. if (mod->free_sgpgs < nsgpgs)
  4104. return BFA_STATUS_ENOMEM;
  4105. for (i = 0; i < nsgpgs; i++) {
  4106. bfa_q_deq(&mod->sgpg_q, &hsgpg);
  4107. WARN_ON(!hsgpg);
  4108. list_add_tail(&hsgpg->qe, sgpg_q);
  4109. }
  4110. mod->free_sgpgs -= nsgpgs;
  4111. return BFA_STATUS_OK;
  4112. }
  4113. void
  4114. bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
  4115. {
  4116. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4117. struct bfa_sgpg_wqe_s *wqe;
  4118. mod->free_sgpgs += nsgpg;
  4119. WARN_ON(mod->free_sgpgs > mod->num_sgpgs);
  4120. list_splice_tail_init(sgpg_q, &mod->sgpg_q);
  4121. if (list_empty(&mod->sgpg_wait_q))
  4122. return;
  4123. /*
  4124. * satisfy as many waiting requests as possible
  4125. */
  4126. do {
  4127. wqe = bfa_q_first(&mod->sgpg_wait_q);
  4128. if (mod->free_sgpgs < wqe->nsgpg)
  4129. nsgpg = mod->free_sgpgs;
  4130. else
  4131. nsgpg = wqe->nsgpg;
  4132. bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
  4133. wqe->nsgpg -= nsgpg;
  4134. if (wqe->nsgpg == 0) {
  4135. list_del(&wqe->qe);
  4136. wqe->cbfn(wqe->cbarg);
  4137. }
  4138. } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q));
  4139. }
  4140. void
  4141. bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg)
  4142. {
  4143. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4144. WARN_ON(nsgpg <= 0);
  4145. WARN_ON(nsgpg <= mod->free_sgpgs);
  4146. wqe->nsgpg_total = wqe->nsgpg = nsgpg;
  4147. /*
  4148. * allocate any left to this one first
  4149. */
  4150. if (mod->free_sgpgs) {
  4151. /*
  4152. * no one else is waiting for SGPG
  4153. */
  4154. WARN_ON(!list_empty(&mod->sgpg_wait_q));
  4155. list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q);
  4156. wqe->nsgpg -= mod->free_sgpgs;
  4157. mod->free_sgpgs = 0;
  4158. }
  4159. list_add_tail(&wqe->qe, &mod->sgpg_wait_q);
  4160. }
  4161. void
  4162. bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe)
  4163. {
  4164. struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa);
  4165. WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe));
  4166. list_del(&wqe->qe);
  4167. if (wqe->nsgpg_total != wqe->nsgpg)
  4168. bfa_sgpg_mfree(bfa, &wqe->sgpg_q,
  4169. wqe->nsgpg_total - wqe->nsgpg);
  4170. }
  4171. void
  4172. bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg),
  4173. void *cbarg)
  4174. {
  4175. INIT_LIST_HEAD(&wqe->sgpg_q);
  4176. wqe->cbfn = cbfn;
  4177. wqe->cbarg = cbarg;
  4178. }
  4179. /*
  4180. * UF related functions
  4181. */
  4182. /*
  4183. *****************************************************************************
  4184. * Internal functions
  4185. *****************************************************************************
  4186. */
  4187. static void
  4188. __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete)
  4189. {
  4190. struct bfa_uf_s *uf = cbarg;
  4191. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa);
  4192. if (complete)
  4193. ufm->ufrecv(ufm->cbarg, uf);
  4194. }
  4195. static void
  4196. claim_uf_post_msgs(struct bfa_uf_mod_s *ufm)
  4197. {
  4198. struct bfi_uf_buf_post_s *uf_bp_msg;
  4199. u16 i;
  4200. u16 buf_len;
  4201. ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm);
  4202. uf_bp_msg = ufm->uf_buf_posts;
  4203. for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs;
  4204. i++, uf_bp_msg++) {
  4205. memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s));
  4206. uf_bp_msg->buf_tag = i;
  4207. buf_len = sizeof(struct bfa_uf_buf_s);
  4208. uf_bp_msg->buf_len = cpu_to_be16(buf_len);
  4209. bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST,
  4210. bfa_fn_lpu(ufm->bfa));
  4211. bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i));
  4212. }
  4213. /*
  4214. * advance pointer beyond consumed memory
  4215. */
  4216. bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg;
  4217. }
  4218. static void
  4219. claim_ufs(struct bfa_uf_mod_s *ufm)
  4220. {
  4221. u16 i;
  4222. struct bfa_uf_s *uf;
  4223. /*
  4224. * Claim block of memory for UF list
  4225. */
  4226. ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm);
  4227. /*
  4228. * Initialize UFs and queue it in UF free queue
  4229. */
  4230. for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) {
  4231. memset(uf, 0, sizeof(struct bfa_uf_s));
  4232. uf->bfa = ufm->bfa;
  4233. uf->uf_tag = i;
  4234. uf->pb_len = BFA_PER_UF_DMA_SZ;
  4235. uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ);
  4236. uf->buf_pa = ufm_pbs_pa(ufm, i);
  4237. list_add_tail(&uf->qe, &ufm->uf_free_q);
  4238. }
  4239. /*
  4240. * advance memory pointer
  4241. */
  4242. bfa_mem_kva_curp(ufm) = (u8 *) uf;
  4243. }
  4244. static void
  4245. uf_mem_claim(struct bfa_uf_mod_s *ufm)
  4246. {
  4247. claim_ufs(ufm);
  4248. claim_uf_post_msgs(ufm);
  4249. }
  4250. static void
  4251. bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
  4252. struct bfa_s *bfa)
  4253. {
  4254. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4255. struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa);
  4256. u32 num_ufs = cfg->fwcfg.num_uf_bufs;
  4257. struct bfa_mem_dma_s *seg_ptr;
  4258. u16 nsegs, idx, per_seg_uf = 0;
  4259. nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ);
  4260. per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ);
  4261. bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) {
  4262. if (num_ufs >= per_seg_uf) {
  4263. num_ufs -= per_seg_uf;
  4264. bfa_mem_dma_setup(minfo, seg_ptr,
  4265. per_seg_uf * BFA_PER_UF_DMA_SZ);
  4266. } else
  4267. bfa_mem_dma_setup(minfo, seg_ptr,
  4268. num_ufs * BFA_PER_UF_DMA_SZ);
  4269. }
  4270. /* kva memory */
  4271. bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs *
  4272. (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s)));
  4273. }
  4274. static void
  4275. bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4276. struct bfa_pcidev_s *pcidev)
  4277. {
  4278. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4279. ufm->bfa = bfa;
  4280. ufm->num_ufs = cfg->fwcfg.num_uf_bufs;
  4281. INIT_LIST_HEAD(&ufm->uf_free_q);
  4282. INIT_LIST_HEAD(&ufm->uf_posted_q);
  4283. INIT_LIST_HEAD(&ufm->uf_unused_q);
  4284. uf_mem_claim(ufm);
  4285. }
  4286. static void
  4287. bfa_uf_detach(struct bfa_s *bfa)
  4288. {
  4289. }
  4290. static struct bfa_uf_s *
  4291. bfa_uf_get(struct bfa_uf_mod_s *uf_mod)
  4292. {
  4293. struct bfa_uf_s *uf;
  4294. bfa_q_deq(&uf_mod->uf_free_q, &uf);
  4295. return uf;
  4296. }
  4297. static void
  4298. bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf)
  4299. {
  4300. list_add_tail(&uf->qe, &uf_mod->uf_free_q);
  4301. }
  4302. static bfa_status_t
  4303. bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf)
  4304. {
  4305. struct bfi_uf_buf_post_s *uf_post_msg;
  4306. uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP);
  4307. if (!uf_post_msg)
  4308. return BFA_STATUS_FAILED;
  4309. memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag],
  4310. sizeof(struct bfi_uf_buf_post_s));
  4311. bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh);
  4312. bfa_trc(ufm->bfa, uf->uf_tag);
  4313. list_add_tail(&uf->qe, &ufm->uf_posted_q);
  4314. return BFA_STATUS_OK;
  4315. }
  4316. static void
  4317. bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod)
  4318. {
  4319. struct bfa_uf_s *uf;
  4320. while ((uf = bfa_uf_get(uf_mod)) != NULL) {
  4321. if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK)
  4322. break;
  4323. }
  4324. }
  4325. static void
  4326. uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)
  4327. {
  4328. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4329. u16 uf_tag = m->buf_tag;
  4330. struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
  4331. struct bfa_uf_buf_s *uf_buf;
  4332. uint8_t *buf;
  4333. struct fchs_s *fchs;
  4334. uf_buf = (struct bfa_uf_buf_s *)
  4335. bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
  4336. buf = &uf_buf->d[0];
  4337. m->frm_len = be16_to_cpu(m->frm_len);
  4338. m->xfr_len = be16_to_cpu(m->xfr_len);
  4339. fchs = (struct fchs_s *)uf_buf;
  4340. list_del(&uf->qe); /* dequeue from posted queue */
  4341. uf->data_ptr = buf;
  4342. uf->data_len = m->xfr_len;
  4343. WARN_ON(uf->data_len < sizeof(struct fchs_s));
  4344. if (uf->data_len == sizeof(struct fchs_s)) {
  4345. bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX,
  4346. uf->data_len, (struct fchs_s *)buf);
  4347. } else {
  4348. u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s)));
  4349. bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF,
  4350. BFA_PL_EID_RX, uf->data_len,
  4351. (struct fchs_s *)buf, pld_w0);
  4352. }
  4353. if (bfa->fcs)
  4354. __bfa_cb_uf_recv(uf, BFA_TRUE);
  4355. else
  4356. bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf);
  4357. }
  4358. static void
  4359. bfa_uf_stop(struct bfa_s *bfa)
  4360. {
  4361. }
  4362. static void
  4363. bfa_uf_iocdisable(struct bfa_s *bfa)
  4364. {
  4365. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4366. struct bfa_uf_s *uf;
  4367. struct list_head *qe, *qen;
  4368. /* Enqueue unused uf resources to free_q */
  4369. list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q);
  4370. list_for_each_safe(qe, qen, &ufm->uf_posted_q) {
  4371. uf = (struct bfa_uf_s *) qe;
  4372. list_del(&uf->qe);
  4373. bfa_uf_put(ufm, uf);
  4374. }
  4375. }
  4376. static void
  4377. bfa_uf_start(struct bfa_s *bfa)
  4378. {
  4379. bfa_uf_post_all(BFA_UF_MOD(bfa));
  4380. }
  4381. /*
  4382. * Register handler for all unsolicted receive frames.
  4383. *
  4384. * @param[in] bfa BFA instance
  4385. * @param[in] ufrecv receive handler function
  4386. * @param[in] cbarg receive handler arg
  4387. */
  4388. void
  4389. bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg)
  4390. {
  4391. struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa);
  4392. ufm->ufrecv = ufrecv;
  4393. ufm->cbarg = cbarg;
  4394. }
  4395. /*
  4396. * Free an unsolicited frame back to BFA.
  4397. *
  4398. * @param[in] uf unsolicited frame to be freed
  4399. *
  4400. * @return None
  4401. */
  4402. void
  4403. bfa_uf_free(struct bfa_uf_s *uf)
  4404. {
  4405. bfa_uf_put(BFA_UF_MOD(uf->bfa), uf);
  4406. bfa_uf_post_all(BFA_UF_MOD(uf->bfa));
  4407. }
  4408. /*
  4409. * uf_pub BFA uf module public functions
  4410. */
  4411. void
  4412. bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4413. {
  4414. bfa_trc(bfa, msg->mhdr.msg_id);
  4415. switch (msg->mhdr.msg_id) {
  4416. case BFI_UF_I2H_FRM_RCVD:
  4417. uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg);
  4418. break;
  4419. default:
  4420. bfa_trc(bfa, msg->mhdr.msg_id);
  4421. WARN_ON(1);
  4422. }
  4423. }
  4424. void
  4425. bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw)
  4426. {
  4427. struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa);
  4428. struct list_head *qe;
  4429. int i;
  4430. for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) {
  4431. bfa_q_deq_tail(&mod->uf_free_q, &qe);
  4432. list_add_tail(qe, &mod->uf_unused_q);
  4433. }
  4434. }
  4435. /*
  4436. * BFA fcdiag module
  4437. */
  4438. #define BFA_DIAG_QTEST_TOV 1000 /* msec */
  4439. /*
  4440. * Set port status to busy
  4441. */
  4442. static void
  4443. bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag)
  4444. {
  4445. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa);
  4446. if (fcdiag->lb.lock)
  4447. fcport->diag_busy = BFA_TRUE;
  4448. else
  4449. fcport->diag_busy = BFA_FALSE;
  4450. }
  4451. static void
  4452. bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  4453. struct bfa_s *bfa)
  4454. {
  4455. }
  4456. static void
  4457. bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  4458. struct bfa_pcidev_s *pcidev)
  4459. {
  4460. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4461. fcdiag->bfa = bfa;
  4462. fcdiag->trcmod = bfa->trcmod;
  4463. /* The common DIAG attach bfa_diag_attach() will do all memory claim */
  4464. }
  4465. static void
  4466. bfa_fcdiag_iocdisable(struct bfa_s *bfa)
  4467. {
  4468. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4469. bfa_trc(fcdiag, fcdiag->lb.lock);
  4470. if (fcdiag->lb.lock) {
  4471. fcdiag->lb.status = BFA_STATUS_IOC_FAILURE;
  4472. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4473. fcdiag->lb.lock = 0;
  4474. bfa_fcdiag_set_busy_status(fcdiag);
  4475. }
  4476. }
  4477. static void
  4478. bfa_fcdiag_detach(struct bfa_s *bfa)
  4479. {
  4480. }
  4481. static void
  4482. bfa_fcdiag_start(struct bfa_s *bfa)
  4483. {
  4484. }
  4485. static void
  4486. bfa_fcdiag_stop(struct bfa_s *bfa)
  4487. {
  4488. }
  4489. static void
  4490. bfa_fcdiag_queuetest_timeout(void *cbarg)
  4491. {
  4492. struct bfa_fcdiag_s *fcdiag = cbarg;
  4493. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4494. bfa_trc(fcdiag, fcdiag->qtest.all);
  4495. bfa_trc(fcdiag, fcdiag->qtest.count);
  4496. fcdiag->qtest.timer_active = 0;
  4497. res->status = BFA_STATUS_ETIMER;
  4498. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4499. if (fcdiag->qtest.all)
  4500. res->queue = fcdiag->qtest.all;
  4501. bfa_trc(fcdiag, BFA_STATUS_ETIMER);
  4502. fcdiag->qtest.status = BFA_STATUS_ETIMER;
  4503. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4504. fcdiag->qtest.lock = 0;
  4505. }
  4506. static bfa_status_t
  4507. bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag)
  4508. {
  4509. u32 i;
  4510. struct bfi_diag_qtest_req_s *req;
  4511. req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue);
  4512. if (!req)
  4513. return BFA_STATUS_DEVBUSY;
  4514. /* build host command */
  4515. bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST,
  4516. bfa_fn_lpu(fcdiag->bfa));
  4517. for (i = 0; i < BFI_LMSG_PL_WSZ; i++)
  4518. req->data[i] = QTEST_PAT_DEFAULT;
  4519. bfa_trc(fcdiag, fcdiag->qtest.queue);
  4520. /* ring door bell */
  4521. bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh);
  4522. return BFA_STATUS_OK;
  4523. }
  4524. static void
  4525. bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag,
  4526. bfi_diag_qtest_rsp_t *rsp)
  4527. {
  4528. struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result;
  4529. bfa_status_t status = BFA_STATUS_OK;
  4530. int i;
  4531. /* Check timer, should still be active */
  4532. if (!fcdiag->qtest.timer_active) {
  4533. bfa_trc(fcdiag, fcdiag->qtest.timer_active);
  4534. return;
  4535. }
  4536. /* update count */
  4537. fcdiag->qtest.count--;
  4538. /* Check result */
  4539. for (i = 0; i < BFI_LMSG_PL_WSZ; i++) {
  4540. if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) {
  4541. res->status = BFA_STATUS_DATACORRUPTED;
  4542. break;
  4543. }
  4544. }
  4545. if (res->status == BFA_STATUS_OK) {
  4546. if (fcdiag->qtest.count > 0) {
  4547. status = bfa_fcdiag_queuetest_send(fcdiag);
  4548. if (status == BFA_STATUS_OK)
  4549. return;
  4550. else
  4551. res->status = status;
  4552. } else if (fcdiag->qtest.all > 0 &&
  4553. fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) {
  4554. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  4555. fcdiag->qtest.queue++;
  4556. status = bfa_fcdiag_queuetest_send(fcdiag);
  4557. if (status == BFA_STATUS_OK)
  4558. return;
  4559. else
  4560. res->status = status;
  4561. }
  4562. }
  4563. /* Stop timer when we comp all queue */
  4564. if (fcdiag->qtest.timer_active) {
  4565. bfa_timer_stop(&fcdiag->qtest.timer);
  4566. fcdiag->qtest.timer_active = 0;
  4567. }
  4568. res->queue = fcdiag->qtest.queue;
  4569. res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count;
  4570. bfa_trc(fcdiag, res->count);
  4571. bfa_trc(fcdiag, res->status);
  4572. fcdiag->qtest.status = res->status;
  4573. fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status);
  4574. fcdiag->qtest.lock = 0;
  4575. }
  4576. static void
  4577. bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag,
  4578. struct bfi_diag_lb_rsp_s *rsp)
  4579. {
  4580. struct bfa_diag_loopback_result_s *res = fcdiag->lb.result;
  4581. res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm);
  4582. res->numosffrm = be32_to_cpu(rsp->res.numosffrm);
  4583. res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm);
  4584. res->badfrminf = be32_to_cpu(rsp->res.badfrminf);
  4585. res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum);
  4586. res->status = rsp->res.status;
  4587. fcdiag->lb.status = rsp->res.status;
  4588. bfa_trc(fcdiag, fcdiag->lb.status);
  4589. fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status);
  4590. fcdiag->lb.lock = 0;
  4591. bfa_fcdiag_set_busy_status(fcdiag);
  4592. }
  4593. static bfa_status_t
  4594. bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag,
  4595. struct bfa_diag_loopback_s *loopback)
  4596. {
  4597. struct bfi_diag_lb_req_s *lb_req;
  4598. lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG);
  4599. if (!lb_req)
  4600. return BFA_STATUS_DEVBUSY;
  4601. /* build host command */
  4602. bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK,
  4603. bfa_fn_lpu(fcdiag->bfa));
  4604. lb_req->lb_mode = loopback->lb_mode;
  4605. lb_req->speed = loopback->speed;
  4606. lb_req->loopcnt = loopback->loopcnt;
  4607. lb_req->pattern = loopback->pattern;
  4608. /* ring door bell */
  4609. bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh);
  4610. bfa_trc(fcdiag, loopback->lb_mode);
  4611. bfa_trc(fcdiag, loopback->speed);
  4612. bfa_trc(fcdiag, loopback->loopcnt);
  4613. bfa_trc(fcdiag, loopback->pattern);
  4614. return BFA_STATUS_OK;
  4615. }
  4616. /*
  4617. * cpe/rme intr handler
  4618. */
  4619. void
  4620. bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  4621. {
  4622. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4623. switch (msg->mhdr.msg_id) {
  4624. case BFI_DIAG_I2H_LOOPBACK:
  4625. bfa_fcdiag_loopback_comp(fcdiag,
  4626. (struct bfi_diag_lb_rsp_s *) msg);
  4627. break;
  4628. case BFI_DIAG_I2H_QTEST:
  4629. bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg);
  4630. break;
  4631. default:
  4632. bfa_trc(fcdiag, msg->mhdr.msg_id);
  4633. WARN_ON(1);
  4634. }
  4635. }
  4636. /*
  4637. * Loopback test
  4638. *
  4639. * @param[in] *bfa - bfa data struct
  4640. * @param[in] opmode - port operation mode
  4641. * @param[in] speed - port speed
  4642. * @param[in] lpcnt - loop count
  4643. * @param[in] pat - pattern to build packet
  4644. * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
  4645. * @param[in] cbfn - callback function
  4646. * @param[in] cbarg - callback functioin arg
  4647. *
  4648. * @param[out]
  4649. */
  4650. bfa_status_t
  4651. bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode,
  4652. enum bfa_port_speed speed, u32 lpcnt, u32 pat,
  4653. struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn,
  4654. void *cbarg)
  4655. {
  4656. struct bfa_diag_loopback_s loopback;
  4657. struct bfa_port_attr_s attr;
  4658. bfa_status_t status;
  4659. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4660. if (!bfa_iocfc_is_operational(bfa))
  4661. return BFA_STATUS_IOC_NON_OP;
  4662. /* if port is PBC disabled, return error */
  4663. if (bfa_fcport_is_pbcdisabled(bfa)) {
  4664. bfa_trc(fcdiag, BFA_STATUS_PBC);
  4665. return BFA_STATUS_PBC;
  4666. }
  4667. if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) {
  4668. bfa_trc(fcdiag, opmode);
  4669. return BFA_STATUS_PORT_NOT_DISABLED;
  4670. }
  4671. /*
  4672. * Check if input speed is supported by the port mode
  4673. */
  4674. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  4675. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  4676. speed == BFA_PORT_SPEED_2GBPS ||
  4677. speed == BFA_PORT_SPEED_4GBPS ||
  4678. speed == BFA_PORT_SPEED_8GBPS ||
  4679. speed == BFA_PORT_SPEED_16GBPS ||
  4680. speed == BFA_PORT_SPEED_AUTO)) {
  4681. bfa_trc(fcdiag, speed);
  4682. return BFA_STATUS_UNSUPP_SPEED;
  4683. }
  4684. bfa_fcport_get_attr(bfa, &attr);
  4685. bfa_trc(fcdiag, attr.speed_supported);
  4686. if (speed > attr.speed_supported)
  4687. return BFA_STATUS_UNSUPP_SPEED;
  4688. } else {
  4689. if (speed != BFA_PORT_SPEED_10GBPS) {
  4690. bfa_trc(fcdiag, speed);
  4691. return BFA_STATUS_UNSUPP_SPEED;
  4692. }
  4693. }
  4694. /* For Mezz card, port speed entered needs to be checked */
  4695. if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) {
  4696. if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) {
  4697. if ((speed == BFA_PORT_SPEED_1GBPS) &&
  4698. (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
  4699. return BFA_STATUS_UNSUPP_SPEED;
  4700. if (!(speed == BFA_PORT_SPEED_1GBPS ||
  4701. speed == BFA_PORT_SPEED_2GBPS ||
  4702. speed == BFA_PORT_SPEED_4GBPS ||
  4703. speed == BFA_PORT_SPEED_8GBPS ||
  4704. speed == BFA_PORT_SPEED_16GBPS ||
  4705. speed == BFA_PORT_SPEED_AUTO))
  4706. return BFA_STATUS_UNSUPP_SPEED;
  4707. } else {
  4708. if (speed != BFA_PORT_SPEED_10GBPS)
  4709. return BFA_STATUS_UNSUPP_SPEED;
  4710. }
  4711. }
  4712. /* check to see if there is another destructive diag cmd running */
  4713. if (fcdiag->lb.lock) {
  4714. bfa_trc(fcdiag, fcdiag->lb.lock);
  4715. return BFA_STATUS_DEVBUSY;
  4716. }
  4717. fcdiag->lb.lock = 1;
  4718. loopback.lb_mode = opmode;
  4719. loopback.speed = speed;
  4720. loopback.loopcnt = lpcnt;
  4721. loopback.pattern = pat;
  4722. fcdiag->lb.result = result;
  4723. fcdiag->lb.cbfn = cbfn;
  4724. fcdiag->lb.cbarg = cbarg;
  4725. memset(result, 0, sizeof(struct bfa_diag_loopback_result_s));
  4726. bfa_fcdiag_set_busy_status(fcdiag);
  4727. /* Send msg to fw */
  4728. status = bfa_fcdiag_loopback_send(fcdiag, &loopback);
  4729. return status;
  4730. }
  4731. /*
  4732. * DIAG queue test command
  4733. *
  4734. * @param[in] *bfa - bfa data struct
  4735. * @param[in] force - 1: don't do ioc op checking
  4736. * @param[in] queue - queue no. to test
  4737. * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
  4738. * @param[in] cbfn - callback function
  4739. * @param[in] *cbarg - callback functioin arg
  4740. *
  4741. * @param[out]
  4742. */
  4743. bfa_status_t
  4744. bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue,
  4745. struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn,
  4746. void *cbarg)
  4747. {
  4748. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4749. bfa_status_t status;
  4750. bfa_trc(fcdiag, force);
  4751. bfa_trc(fcdiag, queue);
  4752. if (!force && !bfa_iocfc_is_operational(bfa))
  4753. return BFA_STATUS_IOC_NON_OP;
  4754. /* check to see if there is another destructive diag cmd running */
  4755. if (fcdiag->qtest.lock) {
  4756. bfa_trc(fcdiag, fcdiag->qtest.lock);
  4757. return BFA_STATUS_DEVBUSY;
  4758. }
  4759. /* Initialization */
  4760. fcdiag->qtest.lock = 1;
  4761. fcdiag->qtest.cbfn = cbfn;
  4762. fcdiag->qtest.cbarg = cbarg;
  4763. fcdiag->qtest.result = result;
  4764. fcdiag->qtest.count = QTEST_CNT_DEFAULT;
  4765. /* Init test results */
  4766. fcdiag->qtest.result->status = BFA_STATUS_OK;
  4767. fcdiag->qtest.result->count = 0;
  4768. /* send */
  4769. if (queue < BFI_IOC_MAX_CQS) {
  4770. fcdiag->qtest.result->queue = (u8)queue;
  4771. fcdiag->qtest.queue = (u8)queue;
  4772. fcdiag->qtest.all = 0;
  4773. } else {
  4774. fcdiag->qtest.result->queue = 0;
  4775. fcdiag->qtest.queue = 0;
  4776. fcdiag->qtest.all = 1;
  4777. }
  4778. status = bfa_fcdiag_queuetest_send(fcdiag);
  4779. /* Start a timer */
  4780. if (status == BFA_STATUS_OK) {
  4781. bfa_timer_start(bfa, &fcdiag->qtest.timer,
  4782. bfa_fcdiag_queuetest_timeout, fcdiag,
  4783. BFA_DIAG_QTEST_TOV);
  4784. fcdiag->qtest.timer_active = 1;
  4785. }
  4786. return status;
  4787. }
  4788. /*
  4789. * DIAG PLB is running
  4790. *
  4791. * @param[in] *bfa - bfa data struct
  4792. *
  4793. * @param[out]
  4794. */
  4795. bfa_status_t
  4796. bfa_fcdiag_lb_is_running(struct bfa_s *bfa)
  4797. {
  4798. struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa);
  4799. return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK;
  4800. }