bfa_svc.c 154 KB

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