bfa_svc.c 137 KB

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