bfa_svc.c 167 KB

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