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