lpfc_sli.c 392 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. return iocbq;
  419. }
  420. /**
  421. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  422. * @phba: Pointer to HBA context object.
  423. * @xritag: XRI value.
  424. *
  425. * This function clears the sglq pointer from the array of acive
  426. * sglq's. The xritag that is passed in is used to index into the
  427. * array. Before the xritag can be used it needs to be adjusted
  428. * by subtracting the xribase.
  429. *
  430. * Returns sglq ponter = success, NULL = Failure.
  431. **/
  432. static struct lpfc_sglq *
  433. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  434. {
  435. uint16_t adj_xri;
  436. struct lpfc_sglq *sglq;
  437. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  438. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  439. return NULL;
  440. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  441. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  442. return sglq;
  443. }
  444. /**
  445. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  446. * @phba: Pointer to HBA context object.
  447. * @xritag: XRI value.
  448. *
  449. * This function returns the sglq pointer from the array of acive
  450. * sglq's. The xritag that is passed in is used to index into the
  451. * array. Before the xritag can be used it needs to be adjusted
  452. * by subtracting the xribase.
  453. *
  454. * Returns sglq ponter = success, NULL = Failure.
  455. **/
  456. struct lpfc_sglq *
  457. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  458. {
  459. uint16_t adj_xri;
  460. struct lpfc_sglq *sglq;
  461. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  462. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  463. return NULL;
  464. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  465. return sglq;
  466. }
  467. /**
  468. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  469. * @phba: Pointer to HBA context object.
  470. *
  471. * This function is called with hbalock held. This function
  472. * Gets a new driver sglq object from the sglq list. If the
  473. * list is not empty then it is successful, it returns pointer to the newly
  474. * allocated sglq object else it returns NULL.
  475. **/
  476. static struct lpfc_sglq *
  477. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  478. {
  479. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  480. struct lpfc_sglq *sglq = NULL;
  481. uint16_t adj_xri;
  482. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  483. if (!sglq)
  484. return NULL;
  485. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  486. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  487. sglq->state = SGL_ALLOCATED;
  488. return sglq;
  489. }
  490. /**
  491. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  492. * @phba: Pointer to HBA context object.
  493. *
  494. * This function is called with no lock held. This function
  495. * allocates a new driver iocb object from the iocb pool. If the
  496. * allocation is successful, it returns pointer to the newly
  497. * allocated iocb object else it returns NULL.
  498. **/
  499. struct lpfc_iocbq *
  500. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  501. {
  502. struct lpfc_iocbq * iocbq = NULL;
  503. unsigned long iflags;
  504. spin_lock_irqsave(&phba->hbalock, iflags);
  505. iocbq = __lpfc_sli_get_iocbq(phba);
  506. spin_unlock_irqrestore(&phba->hbalock, iflags);
  507. return iocbq;
  508. }
  509. /**
  510. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  511. * @phba: Pointer to HBA context object.
  512. * @iocbq: Pointer to driver iocb object.
  513. *
  514. * This function is called with hbalock held to release driver
  515. * iocb object to the iocb pool. The iotag in the iocb object
  516. * does not change for each use of the iocb object. This function
  517. * clears all other fields of the iocb object when it is freed.
  518. * The sqlq structure that holds the xritag and phys and virtual
  519. * mappings for the scatter gather list is retrieved from the
  520. * active array of sglq. The get of the sglq pointer also clears
  521. * the entry in the array. If the status of the IO indiactes that
  522. * this IO was aborted then the sglq entry it put on the
  523. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  524. * IO has good status or fails for any other reason then the sglq
  525. * entry is added to the free list (lpfc_sgl_list).
  526. **/
  527. static void
  528. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  529. {
  530. struct lpfc_sglq *sglq;
  531. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  532. unsigned long iflag;
  533. if (iocbq->sli4_xritag == NO_XRI)
  534. sglq = NULL;
  535. else
  536. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  537. if (sglq) {
  538. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  539. (sglq->state != SGL_XRI_ABORTED)) {
  540. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  541. iflag);
  542. list_add(&sglq->list,
  543. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  544. spin_unlock_irqrestore(
  545. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  546. } else {
  547. sglq->state = SGL_FREED;
  548. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  549. }
  550. }
  551. /*
  552. * Clean all volatile data fields, preserve iotag and node struct.
  553. */
  554. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  555. iocbq->sli4_xritag = NO_XRI;
  556. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  557. }
  558. /**
  559. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  560. * @phba: Pointer to HBA context object.
  561. * @iocbq: Pointer to driver iocb object.
  562. *
  563. * This function is called with hbalock held to release driver
  564. * iocb object to the iocb pool. The iotag in the iocb object
  565. * does not change for each use of the iocb object. This function
  566. * clears all other fields of the iocb object when it is freed.
  567. **/
  568. static void
  569. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  570. {
  571. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  572. /*
  573. * Clean all volatile data fields, preserve iotag and node struct.
  574. */
  575. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  576. iocbq->sli4_xritag = NO_XRI;
  577. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  578. }
  579. /**
  580. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  581. * @phba: Pointer to HBA context object.
  582. * @iocbq: Pointer to driver iocb object.
  583. *
  584. * This function is called with hbalock held to release driver
  585. * iocb object to the iocb pool. The iotag in the iocb object
  586. * does not change for each use of the iocb object. This function
  587. * clears all other fields of the iocb object when it is freed.
  588. **/
  589. static void
  590. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  591. {
  592. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  593. }
  594. /**
  595. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  596. * @phba: Pointer to HBA context object.
  597. * @iocbq: Pointer to driver iocb object.
  598. *
  599. * This function is called with no lock held to release the iocb to
  600. * iocb pool.
  601. **/
  602. void
  603. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  604. {
  605. unsigned long iflags;
  606. /*
  607. * Clean all volatile data fields, preserve iotag and node struct.
  608. */
  609. spin_lock_irqsave(&phba->hbalock, iflags);
  610. __lpfc_sli_release_iocbq(phba, iocbq);
  611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  612. }
  613. /**
  614. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  615. * @phba: Pointer to HBA context object.
  616. * @iocblist: List of IOCBs.
  617. * @ulpstatus: ULP status in IOCB command field.
  618. * @ulpWord4: ULP word-4 in IOCB command field.
  619. *
  620. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  621. * on the list by invoking the complete callback function associated with the
  622. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  623. * fields.
  624. **/
  625. void
  626. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  627. uint32_t ulpstatus, uint32_t ulpWord4)
  628. {
  629. struct lpfc_iocbq *piocb;
  630. while (!list_empty(iocblist)) {
  631. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  632. if (!piocb->iocb_cmpl)
  633. lpfc_sli_release_iocbq(phba, piocb);
  634. else {
  635. piocb->iocb.ulpStatus = ulpstatus;
  636. piocb->iocb.un.ulpWord[4] = ulpWord4;
  637. (piocb->iocb_cmpl) (phba, piocb, piocb);
  638. }
  639. }
  640. return;
  641. }
  642. /**
  643. * lpfc_sli_iocb_cmd_type - Get the iocb type
  644. * @iocb_cmnd: iocb command code.
  645. *
  646. * This function is called by ring event handler function to get the iocb type.
  647. * This function translates the iocb command to an iocb command type used to
  648. * decide the final disposition of each completed IOCB.
  649. * The function returns
  650. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  651. * LPFC_SOL_IOCB if it is a solicited iocb completion
  652. * LPFC_ABORT_IOCB if it is an abort iocb
  653. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  654. *
  655. * The caller is not required to hold any lock.
  656. **/
  657. static lpfc_iocb_type
  658. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  659. {
  660. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  661. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  662. return 0;
  663. switch (iocb_cmnd) {
  664. case CMD_XMIT_SEQUENCE_CR:
  665. case CMD_XMIT_SEQUENCE_CX:
  666. case CMD_XMIT_BCAST_CN:
  667. case CMD_XMIT_BCAST_CX:
  668. case CMD_ELS_REQUEST_CR:
  669. case CMD_ELS_REQUEST_CX:
  670. case CMD_CREATE_XRI_CR:
  671. case CMD_CREATE_XRI_CX:
  672. case CMD_GET_RPI_CN:
  673. case CMD_XMIT_ELS_RSP_CX:
  674. case CMD_GET_RPI_CR:
  675. case CMD_FCP_IWRITE_CR:
  676. case CMD_FCP_IWRITE_CX:
  677. case CMD_FCP_IREAD_CR:
  678. case CMD_FCP_IREAD_CX:
  679. case CMD_FCP_ICMND_CR:
  680. case CMD_FCP_ICMND_CX:
  681. case CMD_FCP_TSEND_CX:
  682. case CMD_FCP_TRSP_CX:
  683. case CMD_FCP_TRECEIVE_CX:
  684. case CMD_FCP_AUTO_TRSP_CX:
  685. case CMD_ADAPTER_MSG:
  686. case CMD_ADAPTER_DUMP:
  687. case CMD_XMIT_SEQUENCE64_CR:
  688. case CMD_XMIT_SEQUENCE64_CX:
  689. case CMD_XMIT_BCAST64_CN:
  690. case CMD_XMIT_BCAST64_CX:
  691. case CMD_ELS_REQUEST64_CR:
  692. case CMD_ELS_REQUEST64_CX:
  693. case CMD_FCP_IWRITE64_CR:
  694. case CMD_FCP_IWRITE64_CX:
  695. case CMD_FCP_IREAD64_CR:
  696. case CMD_FCP_IREAD64_CX:
  697. case CMD_FCP_ICMND64_CR:
  698. case CMD_FCP_ICMND64_CX:
  699. case CMD_FCP_TSEND64_CX:
  700. case CMD_FCP_TRSP64_CX:
  701. case CMD_FCP_TRECEIVE64_CX:
  702. case CMD_GEN_REQUEST64_CR:
  703. case CMD_GEN_REQUEST64_CX:
  704. case CMD_XMIT_ELS_RSP64_CX:
  705. case DSSCMD_IWRITE64_CR:
  706. case DSSCMD_IWRITE64_CX:
  707. case DSSCMD_IREAD64_CR:
  708. case DSSCMD_IREAD64_CX:
  709. type = LPFC_SOL_IOCB;
  710. break;
  711. case CMD_ABORT_XRI_CN:
  712. case CMD_ABORT_XRI_CX:
  713. case CMD_CLOSE_XRI_CN:
  714. case CMD_CLOSE_XRI_CX:
  715. case CMD_XRI_ABORTED_CX:
  716. case CMD_ABORT_MXRI64_CN:
  717. case CMD_XMIT_BLS_RSP64_CX:
  718. type = LPFC_ABORT_IOCB;
  719. break;
  720. case CMD_RCV_SEQUENCE_CX:
  721. case CMD_RCV_ELS_REQ_CX:
  722. case CMD_RCV_SEQUENCE64_CX:
  723. case CMD_RCV_ELS_REQ64_CX:
  724. case CMD_ASYNC_STATUS:
  725. case CMD_IOCB_RCV_SEQ64_CX:
  726. case CMD_IOCB_RCV_ELS64_CX:
  727. case CMD_IOCB_RCV_CONT64_CX:
  728. case CMD_IOCB_RET_XRI64_CX:
  729. type = LPFC_UNSOL_IOCB;
  730. break;
  731. case CMD_IOCB_XMIT_MSEQ64_CR:
  732. case CMD_IOCB_XMIT_MSEQ64_CX:
  733. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  734. case CMD_IOCB_RCV_ELS_LIST64_CX:
  735. case CMD_IOCB_CLOSE_EXTENDED_CN:
  736. case CMD_IOCB_ABORT_EXTENDED_CN:
  737. case CMD_IOCB_RET_HBQE64_CN:
  738. case CMD_IOCB_FCP_IBIDIR64_CR:
  739. case CMD_IOCB_FCP_IBIDIR64_CX:
  740. case CMD_IOCB_FCP_ITASKMGT64_CX:
  741. case CMD_IOCB_LOGENTRY_CN:
  742. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  743. printk("%s - Unhandled SLI-3 Command x%x\n",
  744. __func__, iocb_cmnd);
  745. type = LPFC_UNKNOWN_IOCB;
  746. break;
  747. default:
  748. type = LPFC_UNKNOWN_IOCB;
  749. break;
  750. }
  751. return type;
  752. }
  753. /**
  754. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  755. * @phba: Pointer to HBA context object.
  756. *
  757. * This function is called from SLI initialization code
  758. * to configure every ring of the HBA's SLI interface. The
  759. * caller is not required to hold any lock. This function issues
  760. * a config_ring mailbox command for each ring.
  761. * This function returns zero if successful else returns a negative
  762. * error code.
  763. **/
  764. static int
  765. lpfc_sli_ring_map(struct lpfc_hba *phba)
  766. {
  767. struct lpfc_sli *psli = &phba->sli;
  768. LPFC_MBOXQ_t *pmb;
  769. MAILBOX_t *pmbox;
  770. int i, rc, ret = 0;
  771. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  772. if (!pmb)
  773. return -ENOMEM;
  774. pmbox = &pmb->u.mb;
  775. phba->link_state = LPFC_INIT_MBX_CMDS;
  776. for (i = 0; i < psli->num_rings; i++) {
  777. lpfc_config_ring(phba, i, pmb);
  778. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  779. if (rc != MBX_SUCCESS) {
  780. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  781. "0446 Adapter failed to init (%d), "
  782. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  783. "ring %d\n",
  784. rc, pmbox->mbxCommand,
  785. pmbox->mbxStatus, i);
  786. phba->link_state = LPFC_HBA_ERROR;
  787. ret = -ENXIO;
  788. break;
  789. }
  790. }
  791. mempool_free(pmb, phba->mbox_mem_pool);
  792. return ret;
  793. }
  794. /**
  795. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  796. * @phba: Pointer to HBA context object.
  797. * @pring: Pointer to driver SLI ring object.
  798. * @piocb: Pointer to the driver iocb object.
  799. *
  800. * This function is called with hbalock held. The function adds the
  801. * new iocb to txcmplq of the given ring. This function always returns
  802. * 0. If this function is called for ELS ring, this function checks if
  803. * there is a vport associated with the ELS command. This function also
  804. * starts els_tmofunc timer if this is an ELS command.
  805. **/
  806. static int
  807. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  808. struct lpfc_iocbq *piocb)
  809. {
  810. list_add_tail(&piocb->list, &pring->txcmplq);
  811. pring->txcmplq_cnt++;
  812. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  813. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  814. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  815. if (!piocb->vport)
  816. BUG();
  817. else
  818. mod_timer(&piocb->vport->els_tmofunc,
  819. jiffies + HZ * (phba->fc_ratov << 1));
  820. }
  821. return 0;
  822. }
  823. /**
  824. * lpfc_sli_ringtx_get - Get first element of the txq
  825. * @phba: Pointer to HBA context object.
  826. * @pring: Pointer to driver SLI ring object.
  827. *
  828. * This function is called with hbalock held to get next
  829. * iocb in txq of the given ring. If there is any iocb in
  830. * the txq, the function returns first iocb in the list after
  831. * removing the iocb from the list, else it returns NULL.
  832. **/
  833. static struct lpfc_iocbq *
  834. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  835. {
  836. struct lpfc_iocbq *cmd_iocb;
  837. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  838. if (cmd_iocb != NULL)
  839. pring->txq_cnt--;
  840. return cmd_iocb;
  841. }
  842. /**
  843. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  844. * @phba: Pointer to HBA context object.
  845. * @pring: Pointer to driver SLI ring object.
  846. *
  847. * This function is called with hbalock held and the caller must post the
  848. * iocb without releasing the lock. If the caller releases the lock,
  849. * iocb slot returned by the function is not guaranteed to be available.
  850. * The function returns pointer to the next available iocb slot if there
  851. * is available slot in the ring, else it returns NULL.
  852. * If the get index of the ring is ahead of the put index, the function
  853. * will post an error attention event to the worker thread to take the
  854. * HBA to offline state.
  855. **/
  856. static IOCB_t *
  857. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  858. {
  859. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  860. uint32_t max_cmd_idx = pring->numCiocb;
  861. if ((pring->next_cmdidx == pring->cmdidx) &&
  862. (++pring->next_cmdidx >= max_cmd_idx))
  863. pring->next_cmdidx = 0;
  864. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  865. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  866. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  867. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  868. "0315 Ring %d issue: portCmdGet %d "
  869. "is bigger than cmd ring %d\n",
  870. pring->ringno,
  871. pring->local_getidx, max_cmd_idx);
  872. phba->link_state = LPFC_HBA_ERROR;
  873. /*
  874. * All error attention handlers are posted to
  875. * worker thread
  876. */
  877. phba->work_ha |= HA_ERATT;
  878. phba->work_hs = HS_FFER3;
  879. lpfc_worker_wake_up(phba);
  880. return NULL;
  881. }
  882. if (pring->local_getidx == pring->next_cmdidx)
  883. return NULL;
  884. }
  885. return lpfc_cmd_iocb(phba, pring);
  886. }
  887. /**
  888. * lpfc_sli_next_iotag - Get an iotag for the iocb
  889. * @phba: Pointer to HBA context object.
  890. * @iocbq: Pointer to driver iocb object.
  891. *
  892. * This function gets an iotag for the iocb. If there is no unused iotag and
  893. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  894. * array and assigns a new iotag.
  895. * The function returns the allocated iotag if successful, else returns zero.
  896. * Zero is not a valid iotag.
  897. * The caller is not required to hold any lock.
  898. **/
  899. uint16_t
  900. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  901. {
  902. struct lpfc_iocbq **new_arr;
  903. struct lpfc_iocbq **old_arr;
  904. size_t new_len;
  905. struct lpfc_sli *psli = &phba->sli;
  906. uint16_t iotag;
  907. spin_lock_irq(&phba->hbalock);
  908. iotag = psli->last_iotag;
  909. if(++iotag < psli->iocbq_lookup_len) {
  910. psli->last_iotag = iotag;
  911. psli->iocbq_lookup[iotag] = iocbq;
  912. spin_unlock_irq(&phba->hbalock);
  913. iocbq->iotag = iotag;
  914. return iotag;
  915. } else if (psli->iocbq_lookup_len < (0xffff
  916. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  917. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  918. spin_unlock_irq(&phba->hbalock);
  919. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  920. GFP_KERNEL);
  921. if (new_arr) {
  922. spin_lock_irq(&phba->hbalock);
  923. old_arr = psli->iocbq_lookup;
  924. if (new_len <= psli->iocbq_lookup_len) {
  925. /* highly unprobable case */
  926. kfree(new_arr);
  927. iotag = psli->last_iotag;
  928. if(++iotag < psli->iocbq_lookup_len) {
  929. psli->last_iotag = iotag;
  930. psli->iocbq_lookup[iotag] = iocbq;
  931. spin_unlock_irq(&phba->hbalock);
  932. iocbq->iotag = iotag;
  933. return iotag;
  934. }
  935. spin_unlock_irq(&phba->hbalock);
  936. return 0;
  937. }
  938. if (psli->iocbq_lookup)
  939. memcpy(new_arr, old_arr,
  940. ((psli->last_iotag + 1) *
  941. sizeof (struct lpfc_iocbq *)));
  942. psli->iocbq_lookup = new_arr;
  943. psli->iocbq_lookup_len = new_len;
  944. psli->last_iotag = iotag;
  945. psli->iocbq_lookup[iotag] = iocbq;
  946. spin_unlock_irq(&phba->hbalock);
  947. iocbq->iotag = iotag;
  948. kfree(old_arr);
  949. return iotag;
  950. }
  951. } else
  952. spin_unlock_irq(&phba->hbalock);
  953. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  954. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  955. psli->last_iotag);
  956. return 0;
  957. }
  958. /**
  959. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  960. * @phba: Pointer to HBA context object.
  961. * @pring: Pointer to driver SLI ring object.
  962. * @iocb: Pointer to iocb slot in the ring.
  963. * @nextiocb: Pointer to driver iocb object which need to be
  964. * posted to firmware.
  965. *
  966. * This function is called with hbalock held to post a new iocb to
  967. * the firmware. This function copies the new iocb to ring iocb slot and
  968. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  969. * a completion call back for this iocb else the function will free the
  970. * iocb object.
  971. **/
  972. static void
  973. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  974. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  975. {
  976. /*
  977. * Set up an iotag
  978. */
  979. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  980. if (pring->ringno == LPFC_ELS_RING) {
  981. lpfc_debugfs_slow_ring_trc(phba,
  982. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  983. *(((uint32_t *) &nextiocb->iocb) + 4),
  984. *(((uint32_t *) &nextiocb->iocb) + 6),
  985. *(((uint32_t *) &nextiocb->iocb) + 7));
  986. }
  987. /*
  988. * Issue iocb command to adapter
  989. */
  990. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  991. wmb();
  992. pring->stats.iocb_cmd++;
  993. /*
  994. * If there is no completion routine to call, we can release the
  995. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  996. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  997. */
  998. if (nextiocb->iocb_cmpl)
  999. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1000. else
  1001. __lpfc_sli_release_iocbq(phba, nextiocb);
  1002. /*
  1003. * Let the HBA know what IOCB slot will be the next one the
  1004. * driver will put a command into.
  1005. */
  1006. pring->cmdidx = pring->next_cmdidx;
  1007. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1008. }
  1009. /**
  1010. * lpfc_sli_update_full_ring - Update the chip attention register
  1011. * @phba: Pointer to HBA context object.
  1012. * @pring: Pointer to driver SLI ring object.
  1013. *
  1014. * The caller is not required to hold any lock for calling this function.
  1015. * This function updates the chip attention bits for the ring to inform firmware
  1016. * that there are pending work to be done for this ring and requests an
  1017. * interrupt when there is space available in the ring. This function is
  1018. * called when the driver is unable to post more iocbs to the ring due
  1019. * to unavailability of space in the ring.
  1020. **/
  1021. static void
  1022. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1023. {
  1024. int ringno = pring->ringno;
  1025. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1026. wmb();
  1027. /*
  1028. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1029. * The HBA will tell us when an IOCB entry is available.
  1030. */
  1031. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1032. readl(phba->CAregaddr); /* flush */
  1033. pring->stats.iocb_cmd_full++;
  1034. }
  1035. /**
  1036. * lpfc_sli_update_ring - Update chip attention register
  1037. * @phba: Pointer to HBA context object.
  1038. * @pring: Pointer to driver SLI ring object.
  1039. *
  1040. * This function updates the chip attention register bit for the
  1041. * given ring to inform HBA that there is more work to be done
  1042. * in this ring. The caller is not required to hold any lock.
  1043. **/
  1044. static void
  1045. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1046. {
  1047. int ringno = pring->ringno;
  1048. /*
  1049. * Tell the HBA that there is work to do in this ring.
  1050. */
  1051. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1052. wmb();
  1053. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1054. readl(phba->CAregaddr); /* flush */
  1055. }
  1056. }
  1057. /**
  1058. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1059. * @phba: Pointer to HBA context object.
  1060. * @pring: Pointer to driver SLI ring object.
  1061. *
  1062. * This function is called with hbalock held to post pending iocbs
  1063. * in the txq to the firmware. This function is called when driver
  1064. * detects space available in the ring.
  1065. **/
  1066. static void
  1067. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1068. {
  1069. IOCB_t *iocb;
  1070. struct lpfc_iocbq *nextiocb;
  1071. /*
  1072. * Check to see if:
  1073. * (a) there is anything on the txq to send
  1074. * (b) link is up
  1075. * (c) link attention events can be processed (fcp ring only)
  1076. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1077. */
  1078. if (pring->txq_cnt &&
  1079. lpfc_is_link_up(phba) &&
  1080. (pring->ringno != phba->sli.fcp_ring ||
  1081. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1082. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1083. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1084. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1085. if (iocb)
  1086. lpfc_sli_update_ring(phba, pring);
  1087. else
  1088. lpfc_sli_update_full_ring(phba, pring);
  1089. }
  1090. return;
  1091. }
  1092. /**
  1093. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1094. * @phba: Pointer to HBA context object.
  1095. * @hbqno: HBQ number.
  1096. *
  1097. * This function is called with hbalock held to get the next
  1098. * available slot for the given HBQ. If there is free slot
  1099. * available for the HBQ it will return pointer to the next available
  1100. * HBQ entry else it will return NULL.
  1101. **/
  1102. static struct lpfc_hbq_entry *
  1103. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1104. {
  1105. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1106. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1107. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1108. hbqp->next_hbqPutIdx = 0;
  1109. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1110. uint32_t raw_index = phba->hbq_get[hbqno];
  1111. uint32_t getidx = le32_to_cpu(raw_index);
  1112. hbqp->local_hbqGetIdx = getidx;
  1113. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1114. lpfc_printf_log(phba, KERN_ERR,
  1115. LOG_SLI | LOG_VPORT,
  1116. "1802 HBQ %d: local_hbqGetIdx "
  1117. "%u is > than hbqp->entry_count %u\n",
  1118. hbqno, hbqp->local_hbqGetIdx,
  1119. hbqp->entry_count);
  1120. phba->link_state = LPFC_HBA_ERROR;
  1121. return NULL;
  1122. }
  1123. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1124. return NULL;
  1125. }
  1126. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1127. hbqp->hbqPutIdx;
  1128. }
  1129. /**
  1130. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1131. * @phba: Pointer to HBA context object.
  1132. *
  1133. * This function is called with no lock held to free all the
  1134. * hbq buffers while uninitializing the SLI interface. It also
  1135. * frees the HBQ buffers returned by the firmware but not yet
  1136. * processed by the upper layers.
  1137. **/
  1138. void
  1139. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1140. {
  1141. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1142. struct hbq_dmabuf *hbq_buf;
  1143. unsigned long flags;
  1144. int i, hbq_count;
  1145. uint32_t hbqno;
  1146. hbq_count = lpfc_sli_hbq_count();
  1147. /* Return all memory used by all HBQs */
  1148. spin_lock_irqsave(&phba->hbalock, flags);
  1149. for (i = 0; i < hbq_count; ++i) {
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1151. &phba->hbqs[i].hbq_buffer_list, list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1155. }
  1156. phba->hbqs[i].buffer_count = 0;
  1157. }
  1158. /* Return all HBQ buffer that are in-fly */
  1159. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1160. list) {
  1161. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1162. list_del(&hbq_buf->dbuf.list);
  1163. if (hbq_buf->tag == -1) {
  1164. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1165. (phba, hbq_buf);
  1166. } else {
  1167. hbqno = hbq_buf->tag >> 16;
  1168. if (hbqno >= LPFC_MAX_HBQS)
  1169. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1170. (phba, hbq_buf);
  1171. else
  1172. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1173. hbq_buf);
  1174. }
  1175. }
  1176. /* Mark the HBQs not in use */
  1177. phba->hbq_in_use = 0;
  1178. spin_unlock_irqrestore(&phba->hbalock, flags);
  1179. }
  1180. /**
  1181. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1182. * @phba: Pointer to HBA context object.
  1183. * @hbqno: HBQ number.
  1184. * @hbq_buf: Pointer to HBQ buffer.
  1185. *
  1186. * This function is called with the hbalock held to post a
  1187. * hbq buffer to the firmware. If the function finds an empty
  1188. * slot in the HBQ, it will post the buffer. The function will return
  1189. * pointer to the hbq entry if it successfully post the buffer
  1190. * else it will return NULL.
  1191. **/
  1192. static int
  1193. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1194. struct hbq_dmabuf *hbq_buf)
  1195. {
  1196. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1197. }
  1198. /**
  1199. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1200. * @phba: Pointer to HBA context object.
  1201. * @hbqno: HBQ number.
  1202. * @hbq_buf: Pointer to HBQ buffer.
  1203. *
  1204. * This function is called with the hbalock held to post a hbq buffer to the
  1205. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1206. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1207. * it successfully post the buffer else it will return an error.
  1208. **/
  1209. static int
  1210. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1211. struct hbq_dmabuf *hbq_buf)
  1212. {
  1213. struct lpfc_hbq_entry *hbqe;
  1214. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1215. /* Get next HBQ entry slot to use */
  1216. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1217. if (hbqe) {
  1218. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1219. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1220. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1221. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1222. hbqe->bde.tus.f.bdeFlags = 0;
  1223. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1224. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1225. /* Sync SLIM */
  1226. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1227. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1228. /* flush */
  1229. readl(phba->hbq_put + hbqno);
  1230. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1231. return 0;
  1232. } else
  1233. return -ENOMEM;
  1234. }
  1235. /**
  1236. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1237. * @phba: Pointer to HBA context object.
  1238. * @hbqno: HBQ number.
  1239. * @hbq_buf: Pointer to HBQ buffer.
  1240. *
  1241. * This function is called with the hbalock held to post an RQE to the SLI4
  1242. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1243. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1244. **/
  1245. static int
  1246. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1247. struct hbq_dmabuf *hbq_buf)
  1248. {
  1249. int rc;
  1250. struct lpfc_rqe hrqe;
  1251. struct lpfc_rqe drqe;
  1252. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1253. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1254. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1255. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1256. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1257. &hrqe, &drqe);
  1258. if (rc < 0)
  1259. return rc;
  1260. hbq_buf->tag = rc;
  1261. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1262. return 0;
  1263. }
  1264. /* HBQ for ELS and CT traffic. */
  1265. static struct lpfc_hbq_init lpfc_els_hbq = {
  1266. .rn = 1,
  1267. .entry_count = 256,
  1268. .mask_count = 0,
  1269. .profile = 0,
  1270. .ring_mask = (1 << LPFC_ELS_RING),
  1271. .buffer_count = 0,
  1272. .init_count = 40,
  1273. .add_count = 40,
  1274. };
  1275. /* HBQ for the extra ring if needed */
  1276. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1277. .rn = 1,
  1278. .entry_count = 200,
  1279. .mask_count = 0,
  1280. .profile = 0,
  1281. .ring_mask = (1 << LPFC_EXTRA_RING),
  1282. .buffer_count = 0,
  1283. .init_count = 0,
  1284. .add_count = 5,
  1285. };
  1286. /* Array of HBQs */
  1287. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1288. &lpfc_els_hbq,
  1289. &lpfc_extra_hbq,
  1290. };
  1291. /**
  1292. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1293. * @phba: Pointer to HBA context object.
  1294. * @hbqno: HBQ number.
  1295. * @count: Number of HBQ buffers to be posted.
  1296. *
  1297. * This function is called with no lock held to post more hbq buffers to the
  1298. * given HBQ. The function returns the number of HBQ buffers successfully
  1299. * posted.
  1300. **/
  1301. static int
  1302. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1303. {
  1304. uint32_t i, posted = 0;
  1305. unsigned long flags;
  1306. struct hbq_dmabuf *hbq_buffer;
  1307. LIST_HEAD(hbq_buf_list);
  1308. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1309. return 0;
  1310. if ((phba->hbqs[hbqno].buffer_count + count) >
  1311. lpfc_hbq_defs[hbqno]->entry_count)
  1312. count = lpfc_hbq_defs[hbqno]->entry_count -
  1313. phba->hbqs[hbqno].buffer_count;
  1314. if (!count)
  1315. return 0;
  1316. /* Allocate HBQ entries */
  1317. for (i = 0; i < count; i++) {
  1318. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1319. if (!hbq_buffer)
  1320. break;
  1321. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1322. }
  1323. /* Check whether HBQ is still in use */
  1324. spin_lock_irqsave(&phba->hbalock, flags);
  1325. if (!phba->hbq_in_use)
  1326. goto err;
  1327. while (!list_empty(&hbq_buf_list)) {
  1328. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1329. dbuf.list);
  1330. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1331. (hbqno << 16));
  1332. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1333. phba->hbqs[hbqno].buffer_count++;
  1334. posted++;
  1335. } else
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. spin_unlock_irqrestore(&phba->hbalock, flags);
  1339. return posted;
  1340. err:
  1341. spin_unlock_irqrestore(&phba->hbalock, flags);
  1342. while (!list_empty(&hbq_buf_list)) {
  1343. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1344. dbuf.list);
  1345. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1346. }
  1347. return 0;
  1348. }
  1349. /**
  1350. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1351. * @phba: Pointer to HBA context object.
  1352. * @qno: HBQ number.
  1353. *
  1354. * This function posts more buffers to the HBQ. This function
  1355. * is called with no lock held. The function returns the number of HBQ entries
  1356. * successfully allocated.
  1357. **/
  1358. int
  1359. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1360. {
  1361. if (phba->sli_rev == LPFC_SLI_REV4)
  1362. return 0;
  1363. else
  1364. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1365. lpfc_hbq_defs[qno]->add_count);
  1366. }
  1367. /**
  1368. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1369. * @phba: Pointer to HBA context object.
  1370. * @qno: HBQ queue number.
  1371. *
  1372. * This function is called from SLI initialization code path with
  1373. * no lock held to post initial HBQ buffers to firmware. The
  1374. * function returns the number of HBQ entries successfully allocated.
  1375. **/
  1376. static int
  1377. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1378. {
  1379. if (phba->sli_rev == LPFC_SLI_REV4)
  1380. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1381. lpfc_hbq_defs[qno]->entry_count);
  1382. else
  1383. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1384. lpfc_hbq_defs[qno]->init_count);
  1385. }
  1386. /**
  1387. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1388. * @phba: Pointer to HBA context object.
  1389. * @hbqno: HBQ number.
  1390. *
  1391. * This function removes the first hbq buffer on an hbq list and returns a
  1392. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1393. **/
  1394. static struct hbq_dmabuf *
  1395. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1396. {
  1397. struct lpfc_dmabuf *d_buf;
  1398. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1399. if (!d_buf)
  1400. return NULL;
  1401. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1402. }
  1403. /**
  1404. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1405. * @phba: Pointer to HBA context object.
  1406. * @tag: Tag of the hbq buffer.
  1407. *
  1408. * This function is called with hbalock held. This function searches
  1409. * for the hbq buffer associated with the given tag in the hbq buffer
  1410. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1411. * it returns NULL.
  1412. **/
  1413. static struct hbq_dmabuf *
  1414. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1415. {
  1416. struct lpfc_dmabuf *d_buf;
  1417. struct hbq_dmabuf *hbq_buf;
  1418. uint32_t hbqno;
  1419. hbqno = tag >> 16;
  1420. if (hbqno >= LPFC_MAX_HBQS)
  1421. return NULL;
  1422. spin_lock_irq(&phba->hbalock);
  1423. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1424. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1425. if (hbq_buf->tag == tag) {
  1426. spin_unlock_irq(&phba->hbalock);
  1427. return hbq_buf;
  1428. }
  1429. }
  1430. spin_unlock_irq(&phba->hbalock);
  1431. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1432. "1803 Bad hbq tag. Data: x%x x%x\n",
  1433. tag, phba->hbqs[tag >> 16].buffer_count);
  1434. return NULL;
  1435. }
  1436. /**
  1437. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1438. * @phba: Pointer to HBA context object.
  1439. * @hbq_buffer: Pointer to HBQ buffer.
  1440. *
  1441. * This function is called with hbalock. This function gives back
  1442. * the hbq buffer to firmware. If the HBQ does not have space to
  1443. * post the buffer, it will free the buffer.
  1444. **/
  1445. void
  1446. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1447. {
  1448. uint32_t hbqno;
  1449. if (hbq_buffer) {
  1450. hbqno = hbq_buffer->tag >> 16;
  1451. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1452. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1453. }
  1454. }
  1455. /**
  1456. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1457. * @mbxCommand: mailbox command code.
  1458. *
  1459. * This function is called by the mailbox event handler function to verify
  1460. * that the completed mailbox command is a legitimate mailbox command. If the
  1461. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1462. * and the mailbox event handler will take the HBA offline.
  1463. **/
  1464. static int
  1465. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1466. {
  1467. uint8_t ret;
  1468. switch (mbxCommand) {
  1469. case MBX_LOAD_SM:
  1470. case MBX_READ_NV:
  1471. case MBX_WRITE_NV:
  1472. case MBX_WRITE_VPARMS:
  1473. case MBX_RUN_BIU_DIAG:
  1474. case MBX_INIT_LINK:
  1475. case MBX_DOWN_LINK:
  1476. case MBX_CONFIG_LINK:
  1477. case MBX_CONFIG_RING:
  1478. case MBX_RESET_RING:
  1479. case MBX_READ_CONFIG:
  1480. case MBX_READ_RCONFIG:
  1481. case MBX_READ_SPARM:
  1482. case MBX_READ_STATUS:
  1483. case MBX_READ_RPI:
  1484. case MBX_READ_XRI:
  1485. case MBX_READ_REV:
  1486. case MBX_READ_LNK_STAT:
  1487. case MBX_REG_LOGIN:
  1488. case MBX_UNREG_LOGIN:
  1489. case MBX_READ_LA:
  1490. case MBX_CLEAR_LA:
  1491. case MBX_DUMP_MEMORY:
  1492. case MBX_DUMP_CONTEXT:
  1493. case MBX_RUN_DIAGS:
  1494. case MBX_RESTART:
  1495. case MBX_UPDATE_CFG:
  1496. case MBX_DOWN_LOAD:
  1497. case MBX_DEL_LD_ENTRY:
  1498. case MBX_RUN_PROGRAM:
  1499. case MBX_SET_MASK:
  1500. case MBX_SET_VARIABLE:
  1501. case MBX_UNREG_D_ID:
  1502. case MBX_KILL_BOARD:
  1503. case MBX_CONFIG_FARP:
  1504. case MBX_BEACON:
  1505. case MBX_LOAD_AREA:
  1506. case MBX_RUN_BIU_DIAG64:
  1507. case MBX_CONFIG_PORT:
  1508. case MBX_READ_SPARM64:
  1509. case MBX_READ_RPI64:
  1510. case MBX_REG_LOGIN64:
  1511. case MBX_READ_LA64:
  1512. case MBX_WRITE_WWN:
  1513. case MBX_SET_DEBUG:
  1514. case MBX_LOAD_EXP_ROM:
  1515. case MBX_ASYNCEVT_ENABLE:
  1516. case MBX_REG_VPI:
  1517. case MBX_UNREG_VPI:
  1518. case MBX_HEARTBEAT:
  1519. case MBX_PORT_CAPABILITIES:
  1520. case MBX_PORT_IOV_CONTROL:
  1521. case MBX_SLI4_CONFIG:
  1522. case MBX_SLI4_REQ_FTRS:
  1523. case MBX_REG_FCFI:
  1524. case MBX_UNREG_FCFI:
  1525. case MBX_REG_VFI:
  1526. case MBX_UNREG_VFI:
  1527. case MBX_INIT_VPI:
  1528. case MBX_INIT_VFI:
  1529. case MBX_RESUME_RPI:
  1530. case MBX_READ_EVENT_LOG_STATUS:
  1531. case MBX_READ_EVENT_LOG:
  1532. ret = mbxCommand;
  1533. break;
  1534. default:
  1535. ret = MBX_SHUTDOWN;
  1536. break;
  1537. }
  1538. return ret;
  1539. }
  1540. /**
  1541. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1542. * @phba: Pointer to HBA context object.
  1543. * @pmboxq: Pointer to mailbox command.
  1544. *
  1545. * This is completion handler function for mailbox commands issued from
  1546. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1547. * mailbox event handler function with no lock held. This function
  1548. * will wake up thread waiting on the wait queue pointed by context1
  1549. * of the mailbox.
  1550. **/
  1551. void
  1552. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1553. {
  1554. wait_queue_head_t *pdone_q;
  1555. unsigned long drvr_flag;
  1556. /*
  1557. * If pdone_q is empty, the driver thread gave up waiting and
  1558. * continued running.
  1559. */
  1560. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1561. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1562. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1563. if (pdone_q)
  1564. wake_up_interruptible(pdone_q);
  1565. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1566. return;
  1567. }
  1568. /**
  1569. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1570. * @phba: Pointer to HBA context object.
  1571. * @pmb: Pointer to mailbox object.
  1572. *
  1573. * This function is the default mailbox completion handler. It
  1574. * frees the memory resources associated with the completed mailbox
  1575. * command. If the completed command is a REG_LOGIN mailbox command,
  1576. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1577. **/
  1578. void
  1579. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1580. {
  1581. struct lpfc_dmabuf *mp;
  1582. uint16_t rpi, vpi;
  1583. int rc;
  1584. struct lpfc_vport *vport = pmb->vport;
  1585. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1586. if (mp) {
  1587. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1588. kfree(mp);
  1589. }
  1590. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1591. (phba->sli_rev == LPFC_SLI_REV4))
  1592. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1593. /*
  1594. * If a REG_LOGIN succeeded after node is destroyed or node
  1595. * is in re-discovery driver need to cleanup the RPI.
  1596. */
  1597. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1598. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1599. !pmb->u.mb.mbxStatus) {
  1600. rpi = pmb->u.mb.un.varWords[0];
  1601. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1602. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1603. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1604. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1605. if (rc != MBX_NOT_FINISHED)
  1606. return;
  1607. }
  1608. /* Unreg VPI, if the REG_VPI succeed after VLink failure */
  1609. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1610. !(phba->pport->load_flag & FC_UNLOADING) &&
  1611. !pmb->u.mb.mbxStatus) {
  1612. lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
  1613. pmb->vport = vport;
  1614. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1615. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1616. if (rc != MBX_NOT_FINISHED)
  1617. return;
  1618. }
  1619. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1620. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1621. else
  1622. mempool_free(pmb, phba->mbox_mem_pool);
  1623. }
  1624. /**
  1625. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1626. * @phba: Pointer to HBA context object.
  1627. *
  1628. * This function is called with no lock held. This function processes all
  1629. * the completed mailbox commands and gives it to upper layers. The interrupt
  1630. * service routine processes mailbox completion interrupt and adds completed
  1631. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1632. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1633. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1634. * function returns the mailbox commands to the upper layer by calling the
  1635. * completion handler function of each mailbox.
  1636. **/
  1637. int
  1638. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1639. {
  1640. MAILBOX_t *pmbox;
  1641. LPFC_MBOXQ_t *pmb;
  1642. int rc;
  1643. LIST_HEAD(cmplq);
  1644. phba->sli.slistat.mbox_event++;
  1645. /* Get all completed mailboxe buffers into the cmplq */
  1646. spin_lock_irq(&phba->hbalock);
  1647. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1648. spin_unlock_irq(&phba->hbalock);
  1649. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1650. do {
  1651. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1652. if (pmb == NULL)
  1653. break;
  1654. pmbox = &pmb->u.mb;
  1655. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1656. if (pmb->vport) {
  1657. lpfc_debugfs_disc_trc(pmb->vport,
  1658. LPFC_DISC_TRC_MBOX_VPORT,
  1659. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1660. (uint32_t)pmbox->mbxCommand,
  1661. pmbox->un.varWords[0],
  1662. pmbox->un.varWords[1]);
  1663. }
  1664. else {
  1665. lpfc_debugfs_disc_trc(phba->pport,
  1666. LPFC_DISC_TRC_MBOX,
  1667. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1668. (uint32_t)pmbox->mbxCommand,
  1669. pmbox->un.varWords[0],
  1670. pmbox->un.varWords[1]);
  1671. }
  1672. }
  1673. /*
  1674. * It is a fatal error if unknown mbox command completion.
  1675. */
  1676. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1677. MBX_SHUTDOWN) {
  1678. /* Unknown mailbox command compl */
  1679. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1680. "(%d):0323 Unknown Mailbox command "
  1681. "x%x (x%x) Cmpl\n",
  1682. pmb->vport ? pmb->vport->vpi : 0,
  1683. pmbox->mbxCommand,
  1684. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1685. phba->link_state = LPFC_HBA_ERROR;
  1686. phba->work_hs = HS_FFER3;
  1687. lpfc_handle_eratt(phba);
  1688. continue;
  1689. }
  1690. if (pmbox->mbxStatus) {
  1691. phba->sli.slistat.mbox_stat_err++;
  1692. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1693. /* Mbox cmd cmpl error - RETRYing */
  1694. lpfc_printf_log(phba, KERN_INFO,
  1695. LOG_MBOX | LOG_SLI,
  1696. "(%d):0305 Mbox cmd cmpl "
  1697. "error - RETRYing Data: x%x "
  1698. "(x%x) x%x x%x x%x\n",
  1699. pmb->vport ? pmb->vport->vpi :0,
  1700. pmbox->mbxCommand,
  1701. lpfc_sli4_mbox_opcode_get(phba,
  1702. pmb),
  1703. pmbox->mbxStatus,
  1704. pmbox->un.varWords[0],
  1705. pmb->vport->port_state);
  1706. pmbox->mbxStatus = 0;
  1707. pmbox->mbxOwner = OWN_HOST;
  1708. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1709. if (rc != MBX_NOT_FINISHED)
  1710. continue;
  1711. }
  1712. }
  1713. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1714. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1715. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1716. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1717. pmb->vport ? pmb->vport->vpi : 0,
  1718. pmbox->mbxCommand,
  1719. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1720. pmb->mbox_cmpl,
  1721. *((uint32_t *) pmbox),
  1722. pmbox->un.varWords[0],
  1723. pmbox->un.varWords[1],
  1724. pmbox->un.varWords[2],
  1725. pmbox->un.varWords[3],
  1726. pmbox->un.varWords[4],
  1727. pmbox->un.varWords[5],
  1728. pmbox->un.varWords[6],
  1729. pmbox->un.varWords[7]);
  1730. if (pmb->mbox_cmpl)
  1731. pmb->mbox_cmpl(phba,pmb);
  1732. } while (1);
  1733. return 0;
  1734. }
  1735. /**
  1736. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1737. * @phba: Pointer to HBA context object.
  1738. * @pring: Pointer to driver SLI ring object.
  1739. * @tag: buffer tag.
  1740. *
  1741. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1742. * is set in the tag the buffer is posted for a particular exchange,
  1743. * the function will return the buffer without replacing the buffer.
  1744. * If the buffer is for unsolicited ELS or CT traffic, this function
  1745. * returns the buffer and also posts another buffer to the firmware.
  1746. **/
  1747. static struct lpfc_dmabuf *
  1748. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1749. struct lpfc_sli_ring *pring,
  1750. uint32_t tag)
  1751. {
  1752. struct hbq_dmabuf *hbq_entry;
  1753. if (tag & QUE_BUFTAG_BIT)
  1754. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1755. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1756. if (!hbq_entry)
  1757. return NULL;
  1758. return &hbq_entry->dbuf;
  1759. }
  1760. /**
  1761. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1762. * @phba: Pointer to HBA context object.
  1763. * @pring: Pointer to driver SLI ring object.
  1764. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1765. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1766. * @fch_type: the type for the first frame of the sequence.
  1767. *
  1768. * This function is called with no lock held. This function uses the r_ctl and
  1769. * type of the received sequence to find the correct callback function to call
  1770. * to process the sequence.
  1771. **/
  1772. static int
  1773. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1774. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1775. uint32_t fch_type)
  1776. {
  1777. int i;
  1778. /* unSolicited Responses */
  1779. if (pring->prt[0].profile) {
  1780. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1781. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1782. saveq);
  1783. return 1;
  1784. }
  1785. /* We must search, based on rctl / type
  1786. for the right routine */
  1787. for (i = 0; i < pring->num_mask; i++) {
  1788. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1789. (pring->prt[i].type == fch_type)) {
  1790. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1791. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1792. (phba, pring, saveq);
  1793. return 1;
  1794. }
  1795. }
  1796. return 0;
  1797. }
  1798. /**
  1799. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1800. * @phba: Pointer to HBA context object.
  1801. * @pring: Pointer to driver SLI ring object.
  1802. * @saveq: Pointer to the unsolicited iocb.
  1803. *
  1804. * This function is called with no lock held by the ring event handler
  1805. * when there is an unsolicited iocb posted to the response ring by the
  1806. * firmware. This function gets the buffer associated with the iocbs
  1807. * and calls the event handler for the ring. This function handles both
  1808. * qring buffers and hbq buffers.
  1809. * When the function returns 1 the caller can free the iocb object otherwise
  1810. * upper layer functions will free the iocb objects.
  1811. **/
  1812. static int
  1813. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1814. struct lpfc_iocbq *saveq)
  1815. {
  1816. IOCB_t * irsp;
  1817. WORD5 * w5p;
  1818. uint32_t Rctl, Type;
  1819. uint32_t match;
  1820. struct lpfc_iocbq *iocbq;
  1821. struct lpfc_dmabuf *dmzbuf;
  1822. match = 0;
  1823. irsp = &(saveq->iocb);
  1824. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1825. if (pring->lpfc_sli_rcv_async_status)
  1826. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1827. else
  1828. lpfc_printf_log(phba,
  1829. KERN_WARNING,
  1830. LOG_SLI,
  1831. "0316 Ring %d handler: unexpected "
  1832. "ASYNC_STATUS iocb received evt_code "
  1833. "0x%x\n",
  1834. pring->ringno,
  1835. irsp->un.asyncstat.evt_code);
  1836. return 1;
  1837. }
  1838. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1839. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1840. if (irsp->ulpBdeCount > 0) {
  1841. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1842. irsp->un.ulpWord[3]);
  1843. lpfc_in_buf_free(phba, dmzbuf);
  1844. }
  1845. if (irsp->ulpBdeCount > 1) {
  1846. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1847. irsp->unsli3.sli3Words[3]);
  1848. lpfc_in_buf_free(phba, dmzbuf);
  1849. }
  1850. if (irsp->ulpBdeCount > 2) {
  1851. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1852. irsp->unsli3.sli3Words[7]);
  1853. lpfc_in_buf_free(phba, dmzbuf);
  1854. }
  1855. return 1;
  1856. }
  1857. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1858. if (irsp->ulpBdeCount != 0) {
  1859. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1860. irsp->un.ulpWord[3]);
  1861. if (!saveq->context2)
  1862. lpfc_printf_log(phba,
  1863. KERN_ERR,
  1864. LOG_SLI,
  1865. "0341 Ring %d Cannot find buffer for "
  1866. "an unsolicited iocb. tag 0x%x\n",
  1867. pring->ringno,
  1868. irsp->un.ulpWord[3]);
  1869. }
  1870. if (irsp->ulpBdeCount == 2) {
  1871. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1872. irsp->unsli3.sli3Words[7]);
  1873. if (!saveq->context3)
  1874. lpfc_printf_log(phba,
  1875. KERN_ERR,
  1876. LOG_SLI,
  1877. "0342 Ring %d Cannot find buffer for an"
  1878. " unsolicited iocb. tag 0x%x\n",
  1879. pring->ringno,
  1880. irsp->unsli3.sli3Words[7]);
  1881. }
  1882. list_for_each_entry(iocbq, &saveq->list, list) {
  1883. irsp = &(iocbq->iocb);
  1884. if (irsp->ulpBdeCount != 0) {
  1885. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1886. irsp->un.ulpWord[3]);
  1887. if (!iocbq->context2)
  1888. lpfc_printf_log(phba,
  1889. KERN_ERR,
  1890. LOG_SLI,
  1891. "0343 Ring %d Cannot find "
  1892. "buffer for an unsolicited iocb"
  1893. ". tag 0x%x\n", pring->ringno,
  1894. irsp->un.ulpWord[3]);
  1895. }
  1896. if (irsp->ulpBdeCount == 2) {
  1897. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1898. irsp->unsli3.sli3Words[7]);
  1899. if (!iocbq->context3)
  1900. lpfc_printf_log(phba,
  1901. KERN_ERR,
  1902. LOG_SLI,
  1903. "0344 Ring %d Cannot find "
  1904. "buffer for an unsolicited "
  1905. "iocb. tag 0x%x\n",
  1906. pring->ringno,
  1907. irsp->unsli3.sli3Words[7]);
  1908. }
  1909. }
  1910. }
  1911. if (irsp->ulpBdeCount != 0 &&
  1912. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1913. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1914. int found = 0;
  1915. /* search continue save q for same XRI */
  1916. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1917. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1918. list_add_tail(&saveq->list, &iocbq->list);
  1919. found = 1;
  1920. break;
  1921. }
  1922. }
  1923. if (!found)
  1924. list_add_tail(&saveq->clist,
  1925. &pring->iocb_continue_saveq);
  1926. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1927. list_del_init(&iocbq->clist);
  1928. saveq = iocbq;
  1929. irsp = &(saveq->iocb);
  1930. } else
  1931. return 0;
  1932. }
  1933. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1934. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1935. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1936. Rctl = FC_RCTL_ELS_REQ;
  1937. Type = FC_TYPE_ELS;
  1938. } else {
  1939. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1940. Rctl = w5p->hcsw.Rctl;
  1941. Type = w5p->hcsw.Type;
  1942. /* Firmware Workaround */
  1943. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1944. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1945. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1946. Rctl = FC_RCTL_ELS_REQ;
  1947. Type = FC_TYPE_ELS;
  1948. w5p->hcsw.Rctl = Rctl;
  1949. w5p->hcsw.Type = Type;
  1950. }
  1951. }
  1952. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1953. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1954. "0313 Ring %d handler: unexpected Rctl x%x "
  1955. "Type x%x received\n",
  1956. pring->ringno, Rctl, Type);
  1957. return 1;
  1958. }
  1959. /**
  1960. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1961. * @phba: Pointer to HBA context object.
  1962. * @pring: Pointer to driver SLI ring object.
  1963. * @prspiocb: Pointer to response iocb object.
  1964. *
  1965. * This function looks up the iocb_lookup table to get the command iocb
  1966. * corresponding to the given response iocb using the iotag of the
  1967. * response iocb. This function is called with the hbalock held.
  1968. * This function returns the command iocb object if it finds the command
  1969. * iocb else returns NULL.
  1970. **/
  1971. static struct lpfc_iocbq *
  1972. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1973. struct lpfc_sli_ring *pring,
  1974. struct lpfc_iocbq *prspiocb)
  1975. {
  1976. struct lpfc_iocbq *cmd_iocb = NULL;
  1977. uint16_t iotag;
  1978. iotag = prspiocb->iocb.ulpIoTag;
  1979. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1980. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1981. list_del_init(&cmd_iocb->list);
  1982. pring->txcmplq_cnt--;
  1983. return cmd_iocb;
  1984. }
  1985. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1986. "0317 iotag x%x is out off "
  1987. "range: max iotag x%x wd0 x%x\n",
  1988. iotag, phba->sli.last_iotag,
  1989. *(((uint32_t *) &prspiocb->iocb) + 7));
  1990. return NULL;
  1991. }
  1992. /**
  1993. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1994. * @phba: Pointer to HBA context object.
  1995. * @pring: Pointer to driver SLI ring object.
  1996. * @iotag: IOCB tag.
  1997. *
  1998. * This function looks up the iocb_lookup table to get the command iocb
  1999. * corresponding to the given iotag. This function is called with the
  2000. * hbalock held.
  2001. * This function returns the command iocb object if it finds the command
  2002. * iocb else returns NULL.
  2003. **/
  2004. static struct lpfc_iocbq *
  2005. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2006. struct lpfc_sli_ring *pring, uint16_t iotag)
  2007. {
  2008. struct lpfc_iocbq *cmd_iocb;
  2009. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2010. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2011. list_del_init(&cmd_iocb->list);
  2012. pring->txcmplq_cnt--;
  2013. return cmd_iocb;
  2014. }
  2015. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2016. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2017. iotag, phba->sli.last_iotag);
  2018. return NULL;
  2019. }
  2020. /**
  2021. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2022. * @phba: Pointer to HBA context object.
  2023. * @pring: Pointer to driver SLI ring object.
  2024. * @saveq: Pointer to the response iocb to be processed.
  2025. *
  2026. * This function is called by the ring event handler for non-fcp
  2027. * rings when there is a new response iocb in the response ring.
  2028. * The caller is not required to hold any locks. This function
  2029. * gets the command iocb associated with the response iocb and
  2030. * calls the completion handler for the command iocb. If there
  2031. * is no completion handler, the function will free the resources
  2032. * associated with command iocb. If the response iocb is for
  2033. * an already aborted command iocb, the status of the completion
  2034. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2035. * This function always returns 1.
  2036. **/
  2037. static int
  2038. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2039. struct lpfc_iocbq *saveq)
  2040. {
  2041. struct lpfc_iocbq *cmdiocbp;
  2042. int rc = 1;
  2043. unsigned long iflag;
  2044. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2045. spin_lock_irqsave(&phba->hbalock, iflag);
  2046. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2048. if (cmdiocbp) {
  2049. if (cmdiocbp->iocb_cmpl) {
  2050. /*
  2051. * If an ELS command failed send an event to mgmt
  2052. * application.
  2053. */
  2054. if (saveq->iocb.ulpStatus &&
  2055. (pring->ringno == LPFC_ELS_RING) &&
  2056. (cmdiocbp->iocb.ulpCommand ==
  2057. CMD_ELS_REQUEST64_CR))
  2058. lpfc_send_els_failure_event(phba,
  2059. cmdiocbp, saveq);
  2060. /*
  2061. * Post all ELS completions to the worker thread.
  2062. * All other are passed to the completion callback.
  2063. */
  2064. if (pring->ringno == LPFC_ELS_RING) {
  2065. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2066. (cmdiocbp->iocb_flag &
  2067. LPFC_DRIVER_ABORTED)) {
  2068. spin_lock_irqsave(&phba->hbalock,
  2069. iflag);
  2070. cmdiocbp->iocb_flag &=
  2071. ~LPFC_DRIVER_ABORTED;
  2072. spin_unlock_irqrestore(&phba->hbalock,
  2073. iflag);
  2074. saveq->iocb.ulpStatus =
  2075. IOSTAT_LOCAL_REJECT;
  2076. saveq->iocb.un.ulpWord[4] =
  2077. IOERR_SLI_ABORTED;
  2078. /* Firmware could still be in progress
  2079. * of DMAing payload, so don't free data
  2080. * buffer till after a hbeat.
  2081. */
  2082. spin_lock_irqsave(&phba->hbalock,
  2083. iflag);
  2084. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2085. spin_unlock_irqrestore(&phba->hbalock,
  2086. iflag);
  2087. }
  2088. if (phba->sli_rev == LPFC_SLI_REV4) {
  2089. if (saveq->iocb_flag &
  2090. LPFC_EXCHANGE_BUSY) {
  2091. /* Set cmdiocb flag for the
  2092. * exchange busy so sgl (xri)
  2093. * will not be released until
  2094. * the abort xri is received
  2095. * from hba.
  2096. */
  2097. spin_lock_irqsave(
  2098. &phba->hbalock, iflag);
  2099. cmdiocbp->iocb_flag |=
  2100. LPFC_EXCHANGE_BUSY;
  2101. spin_unlock_irqrestore(
  2102. &phba->hbalock, iflag);
  2103. }
  2104. if (cmdiocbp->iocb_flag &
  2105. LPFC_DRIVER_ABORTED) {
  2106. /*
  2107. * Clear LPFC_DRIVER_ABORTED
  2108. * bit in case it was driver
  2109. * initiated abort.
  2110. */
  2111. spin_lock_irqsave(
  2112. &phba->hbalock, iflag);
  2113. cmdiocbp->iocb_flag &=
  2114. ~LPFC_DRIVER_ABORTED;
  2115. spin_unlock_irqrestore(
  2116. &phba->hbalock, iflag);
  2117. cmdiocbp->iocb.ulpStatus =
  2118. IOSTAT_LOCAL_REJECT;
  2119. cmdiocbp->iocb.un.ulpWord[4] =
  2120. IOERR_ABORT_REQUESTED;
  2121. /*
  2122. * For SLI4, irsiocb contains
  2123. * NO_XRI in sli_xritag, it
  2124. * shall not affect releasing
  2125. * sgl (xri) process.
  2126. */
  2127. saveq->iocb.ulpStatus =
  2128. IOSTAT_LOCAL_REJECT;
  2129. saveq->iocb.un.ulpWord[4] =
  2130. IOERR_SLI_ABORTED;
  2131. spin_lock_irqsave(
  2132. &phba->hbalock, iflag);
  2133. saveq->iocb_flag |=
  2134. LPFC_DELAY_MEM_FREE;
  2135. spin_unlock_irqrestore(
  2136. &phba->hbalock, iflag);
  2137. }
  2138. }
  2139. }
  2140. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2141. } else
  2142. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2143. } else {
  2144. /*
  2145. * Unknown initiating command based on the response iotag.
  2146. * This could be the case on the ELS ring because of
  2147. * lpfc_els_abort().
  2148. */
  2149. if (pring->ringno != LPFC_ELS_RING) {
  2150. /*
  2151. * Ring <ringno> handler: unexpected completion IoTag
  2152. * <IoTag>
  2153. */
  2154. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2155. "0322 Ring %d handler: "
  2156. "unexpected completion IoTag x%x "
  2157. "Data: x%x x%x x%x x%x\n",
  2158. pring->ringno,
  2159. saveq->iocb.ulpIoTag,
  2160. saveq->iocb.ulpStatus,
  2161. saveq->iocb.un.ulpWord[4],
  2162. saveq->iocb.ulpCommand,
  2163. saveq->iocb.ulpContext);
  2164. }
  2165. }
  2166. return rc;
  2167. }
  2168. /**
  2169. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2170. * @phba: Pointer to HBA context object.
  2171. * @pring: Pointer to driver SLI ring object.
  2172. *
  2173. * This function is called from the iocb ring event handlers when
  2174. * put pointer is ahead of the get pointer for a ring. This function signal
  2175. * an error attention condition to the worker thread and the worker
  2176. * thread will transition the HBA to offline state.
  2177. **/
  2178. static void
  2179. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2180. {
  2181. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2182. /*
  2183. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2184. * rsp ring <portRspMax>
  2185. */
  2186. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2187. "0312 Ring %d handler: portRspPut %d "
  2188. "is bigger than rsp ring %d\n",
  2189. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2190. pring->numRiocb);
  2191. phba->link_state = LPFC_HBA_ERROR;
  2192. /*
  2193. * All error attention handlers are posted to
  2194. * worker thread
  2195. */
  2196. phba->work_ha |= HA_ERATT;
  2197. phba->work_hs = HS_FFER3;
  2198. lpfc_worker_wake_up(phba);
  2199. return;
  2200. }
  2201. /**
  2202. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2203. * @ptr: Pointer to address of HBA context object.
  2204. *
  2205. * This function is invoked by the Error Attention polling timer when the
  2206. * timer times out. It will check the SLI Error Attention register for
  2207. * possible attention events. If so, it will post an Error Attention event
  2208. * and wake up worker thread to process it. Otherwise, it will set up the
  2209. * Error Attention polling timer for the next poll.
  2210. **/
  2211. void lpfc_poll_eratt(unsigned long ptr)
  2212. {
  2213. struct lpfc_hba *phba;
  2214. uint32_t eratt = 0;
  2215. phba = (struct lpfc_hba *)ptr;
  2216. /* Check chip HA register for error event */
  2217. eratt = lpfc_sli_check_eratt(phba);
  2218. if (eratt)
  2219. /* Tell the worker thread there is work to do */
  2220. lpfc_worker_wake_up(phba);
  2221. else
  2222. /* Restart the timer for next eratt poll */
  2223. mod_timer(&phba->eratt_poll, jiffies +
  2224. HZ * LPFC_ERATT_POLL_INTERVAL);
  2225. return;
  2226. }
  2227. /**
  2228. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2229. * @phba: Pointer to HBA context object.
  2230. * @pring: Pointer to driver SLI ring object.
  2231. * @mask: Host attention register mask for this ring.
  2232. *
  2233. * This function is called from the interrupt context when there is a ring
  2234. * event for the fcp ring. The caller does not hold any lock.
  2235. * The function processes each response iocb in the response ring until it
  2236. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2237. * LE bit set. The function will call the completion handler of the command iocb
  2238. * if the response iocb indicates a completion for a command iocb or it is
  2239. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2240. * function if this is an unsolicited iocb.
  2241. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2242. * to check it explicitly.
  2243. */
  2244. int
  2245. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2246. struct lpfc_sli_ring *pring, uint32_t mask)
  2247. {
  2248. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2249. IOCB_t *irsp = NULL;
  2250. IOCB_t *entry = NULL;
  2251. struct lpfc_iocbq *cmdiocbq = NULL;
  2252. struct lpfc_iocbq rspiocbq;
  2253. uint32_t status;
  2254. uint32_t portRspPut, portRspMax;
  2255. int rc = 1;
  2256. lpfc_iocb_type type;
  2257. unsigned long iflag;
  2258. uint32_t rsp_cmpl = 0;
  2259. spin_lock_irqsave(&phba->hbalock, iflag);
  2260. pring->stats.iocb_event++;
  2261. /*
  2262. * The next available response entry should never exceed the maximum
  2263. * entries. If it does, treat it as an adapter hardware error.
  2264. */
  2265. portRspMax = pring->numRiocb;
  2266. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2267. if (unlikely(portRspPut >= portRspMax)) {
  2268. lpfc_sli_rsp_pointers_error(phba, pring);
  2269. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2270. return 1;
  2271. }
  2272. if (phba->fcp_ring_in_use) {
  2273. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2274. return 1;
  2275. } else
  2276. phba->fcp_ring_in_use = 1;
  2277. rmb();
  2278. while (pring->rspidx != portRspPut) {
  2279. /*
  2280. * Fetch an entry off the ring and copy it into a local data
  2281. * structure. The copy involves a byte-swap since the
  2282. * network byte order and pci byte orders are different.
  2283. */
  2284. entry = lpfc_resp_iocb(phba, pring);
  2285. phba->last_completion_time = jiffies;
  2286. if (++pring->rspidx >= portRspMax)
  2287. pring->rspidx = 0;
  2288. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2289. (uint32_t *) &rspiocbq.iocb,
  2290. phba->iocb_rsp_size);
  2291. INIT_LIST_HEAD(&(rspiocbq.list));
  2292. irsp = &rspiocbq.iocb;
  2293. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2294. pring->stats.iocb_rsp++;
  2295. rsp_cmpl++;
  2296. if (unlikely(irsp->ulpStatus)) {
  2297. /*
  2298. * If resource errors reported from HBA, reduce
  2299. * queuedepths of the SCSI device.
  2300. */
  2301. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2302. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2303. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2304. phba->lpfc_rampdown_queue_depth(phba);
  2305. spin_lock_irqsave(&phba->hbalock, iflag);
  2306. }
  2307. /* Rsp ring <ringno> error: IOCB */
  2308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2309. "0336 Rsp Ring %d error: IOCB Data: "
  2310. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2311. pring->ringno,
  2312. irsp->un.ulpWord[0],
  2313. irsp->un.ulpWord[1],
  2314. irsp->un.ulpWord[2],
  2315. irsp->un.ulpWord[3],
  2316. irsp->un.ulpWord[4],
  2317. irsp->un.ulpWord[5],
  2318. *(uint32_t *)&irsp->un1,
  2319. *((uint32_t *)&irsp->un1 + 1));
  2320. }
  2321. switch (type) {
  2322. case LPFC_ABORT_IOCB:
  2323. case LPFC_SOL_IOCB:
  2324. /*
  2325. * Idle exchange closed via ABTS from port. No iocb
  2326. * resources need to be recovered.
  2327. */
  2328. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2329. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2330. "0333 IOCB cmd 0x%x"
  2331. " processed. Skipping"
  2332. " completion\n",
  2333. irsp->ulpCommand);
  2334. break;
  2335. }
  2336. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2337. &rspiocbq);
  2338. if (unlikely(!cmdiocbq))
  2339. break;
  2340. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2341. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2342. if (cmdiocbq->iocb_cmpl) {
  2343. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2344. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2345. &rspiocbq);
  2346. spin_lock_irqsave(&phba->hbalock, iflag);
  2347. }
  2348. break;
  2349. case LPFC_UNSOL_IOCB:
  2350. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2351. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2352. spin_lock_irqsave(&phba->hbalock, iflag);
  2353. break;
  2354. default:
  2355. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2356. char adaptermsg[LPFC_MAX_ADPTMSG];
  2357. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2358. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2359. MAX_MSG_DATA);
  2360. dev_warn(&((phba->pcidev)->dev),
  2361. "lpfc%d: %s\n",
  2362. phba->brd_no, adaptermsg);
  2363. } else {
  2364. /* Unknown IOCB command */
  2365. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2366. "0334 Unknown IOCB command "
  2367. "Data: x%x, x%x x%x x%x x%x\n",
  2368. type, irsp->ulpCommand,
  2369. irsp->ulpStatus,
  2370. irsp->ulpIoTag,
  2371. irsp->ulpContext);
  2372. }
  2373. break;
  2374. }
  2375. /*
  2376. * The response IOCB has been processed. Update the ring
  2377. * pointer in SLIM. If the port response put pointer has not
  2378. * been updated, sync the pgp->rspPutInx and fetch the new port
  2379. * response put pointer.
  2380. */
  2381. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2382. if (pring->rspidx == portRspPut)
  2383. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2384. }
  2385. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2386. pring->stats.iocb_rsp_full++;
  2387. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2388. writel(status, phba->CAregaddr);
  2389. readl(phba->CAregaddr);
  2390. }
  2391. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2392. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2393. pring->stats.iocb_cmd_empty++;
  2394. /* Force update of the local copy of cmdGetInx */
  2395. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2396. lpfc_sli_resume_iocb(phba, pring);
  2397. if ((pring->lpfc_sli_cmd_available))
  2398. (pring->lpfc_sli_cmd_available) (phba, pring);
  2399. }
  2400. phba->fcp_ring_in_use = 0;
  2401. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2402. return rc;
  2403. }
  2404. /**
  2405. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2406. * @phba: Pointer to HBA context object.
  2407. * @pring: Pointer to driver SLI ring object.
  2408. * @rspiocbp: Pointer to driver response IOCB object.
  2409. *
  2410. * This function is called from the worker thread when there is a slow-path
  2411. * response IOCB to process. This function chains all the response iocbs until
  2412. * seeing the iocb with the LE bit set. The function will call
  2413. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2414. * completion of a command iocb. The function will call the
  2415. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2416. * The function frees the resources or calls the completion handler if this
  2417. * iocb is an abort completion. The function returns NULL when the response
  2418. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2419. * this function shall chain the iocb on to the iocb_continueq and return the
  2420. * response iocb passed in.
  2421. **/
  2422. static struct lpfc_iocbq *
  2423. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2424. struct lpfc_iocbq *rspiocbp)
  2425. {
  2426. struct lpfc_iocbq *saveq;
  2427. struct lpfc_iocbq *cmdiocbp;
  2428. struct lpfc_iocbq *next_iocb;
  2429. IOCB_t *irsp = NULL;
  2430. uint32_t free_saveq;
  2431. uint8_t iocb_cmd_type;
  2432. lpfc_iocb_type type;
  2433. unsigned long iflag;
  2434. int rc;
  2435. spin_lock_irqsave(&phba->hbalock, iflag);
  2436. /* First add the response iocb to the countinueq list */
  2437. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2438. pring->iocb_continueq_cnt++;
  2439. /* Now, determine whetehr the list is completed for processing */
  2440. irsp = &rspiocbp->iocb;
  2441. if (irsp->ulpLe) {
  2442. /*
  2443. * By default, the driver expects to free all resources
  2444. * associated with this iocb completion.
  2445. */
  2446. free_saveq = 1;
  2447. saveq = list_get_first(&pring->iocb_continueq,
  2448. struct lpfc_iocbq, list);
  2449. irsp = &(saveq->iocb);
  2450. list_del_init(&pring->iocb_continueq);
  2451. pring->iocb_continueq_cnt = 0;
  2452. pring->stats.iocb_rsp++;
  2453. /*
  2454. * If resource errors reported from HBA, reduce
  2455. * queuedepths of the SCSI device.
  2456. */
  2457. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2458. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2459. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2460. phba->lpfc_rampdown_queue_depth(phba);
  2461. spin_lock_irqsave(&phba->hbalock, iflag);
  2462. }
  2463. if (irsp->ulpStatus) {
  2464. /* Rsp ring <ringno> error: IOCB */
  2465. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2466. "0328 Rsp Ring %d error: "
  2467. "IOCB Data: "
  2468. "x%x x%x x%x x%x "
  2469. "x%x x%x x%x x%x "
  2470. "x%x x%x x%x x%x "
  2471. "x%x x%x x%x x%x\n",
  2472. pring->ringno,
  2473. irsp->un.ulpWord[0],
  2474. irsp->un.ulpWord[1],
  2475. irsp->un.ulpWord[2],
  2476. irsp->un.ulpWord[3],
  2477. irsp->un.ulpWord[4],
  2478. irsp->un.ulpWord[5],
  2479. *(((uint32_t *) irsp) + 6),
  2480. *(((uint32_t *) irsp) + 7),
  2481. *(((uint32_t *) irsp) + 8),
  2482. *(((uint32_t *) irsp) + 9),
  2483. *(((uint32_t *) irsp) + 10),
  2484. *(((uint32_t *) irsp) + 11),
  2485. *(((uint32_t *) irsp) + 12),
  2486. *(((uint32_t *) irsp) + 13),
  2487. *(((uint32_t *) irsp) + 14),
  2488. *(((uint32_t *) irsp) + 15));
  2489. }
  2490. /*
  2491. * Fetch the IOCB command type and call the correct completion
  2492. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2493. * get freed back to the lpfc_iocb_list by the discovery
  2494. * kernel thread.
  2495. */
  2496. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2497. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2498. switch (type) {
  2499. case LPFC_SOL_IOCB:
  2500. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2501. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2502. spin_lock_irqsave(&phba->hbalock, iflag);
  2503. break;
  2504. case LPFC_UNSOL_IOCB:
  2505. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2506. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2507. spin_lock_irqsave(&phba->hbalock, iflag);
  2508. if (!rc)
  2509. free_saveq = 0;
  2510. break;
  2511. case LPFC_ABORT_IOCB:
  2512. cmdiocbp = NULL;
  2513. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2514. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2515. saveq);
  2516. if (cmdiocbp) {
  2517. /* Call the specified completion routine */
  2518. if (cmdiocbp->iocb_cmpl) {
  2519. spin_unlock_irqrestore(&phba->hbalock,
  2520. iflag);
  2521. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2522. saveq);
  2523. spin_lock_irqsave(&phba->hbalock,
  2524. iflag);
  2525. } else
  2526. __lpfc_sli_release_iocbq(phba,
  2527. cmdiocbp);
  2528. }
  2529. break;
  2530. case LPFC_UNKNOWN_IOCB:
  2531. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2532. char adaptermsg[LPFC_MAX_ADPTMSG];
  2533. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2534. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2535. MAX_MSG_DATA);
  2536. dev_warn(&((phba->pcidev)->dev),
  2537. "lpfc%d: %s\n",
  2538. phba->brd_no, adaptermsg);
  2539. } else {
  2540. /* Unknown IOCB command */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0335 Unknown IOCB "
  2543. "command Data: x%x "
  2544. "x%x x%x x%x\n",
  2545. irsp->ulpCommand,
  2546. irsp->ulpStatus,
  2547. irsp->ulpIoTag,
  2548. irsp->ulpContext);
  2549. }
  2550. break;
  2551. }
  2552. if (free_saveq) {
  2553. list_for_each_entry_safe(rspiocbp, next_iocb,
  2554. &saveq->list, list) {
  2555. list_del(&rspiocbp->list);
  2556. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2557. }
  2558. __lpfc_sli_release_iocbq(phba, saveq);
  2559. }
  2560. rspiocbp = NULL;
  2561. }
  2562. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2563. return rspiocbp;
  2564. }
  2565. /**
  2566. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2567. * @phba: Pointer to HBA context object.
  2568. * @pring: Pointer to driver SLI ring object.
  2569. * @mask: Host attention register mask for this ring.
  2570. *
  2571. * This routine wraps the actual slow_ring event process routine from the
  2572. * API jump table function pointer from the lpfc_hba struct.
  2573. **/
  2574. void
  2575. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2576. struct lpfc_sli_ring *pring, uint32_t mask)
  2577. {
  2578. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2579. }
  2580. /**
  2581. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2582. * @phba: Pointer to HBA context object.
  2583. * @pring: Pointer to driver SLI ring object.
  2584. * @mask: Host attention register mask for this ring.
  2585. *
  2586. * This function is called from the worker thread when there is a ring event
  2587. * for non-fcp rings. The caller does not hold any lock. The function will
  2588. * remove each response iocb in the response ring and calls the handle
  2589. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2590. **/
  2591. static void
  2592. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2593. struct lpfc_sli_ring *pring, uint32_t mask)
  2594. {
  2595. struct lpfc_pgp *pgp;
  2596. IOCB_t *entry;
  2597. IOCB_t *irsp = NULL;
  2598. struct lpfc_iocbq *rspiocbp = NULL;
  2599. uint32_t portRspPut, portRspMax;
  2600. unsigned long iflag;
  2601. uint32_t status;
  2602. pgp = &phba->port_gp[pring->ringno];
  2603. spin_lock_irqsave(&phba->hbalock, iflag);
  2604. pring->stats.iocb_event++;
  2605. /*
  2606. * The next available response entry should never exceed the maximum
  2607. * entries. If it does, treat it as an adapter hardware error.
  2608. */
  2609. portRspMax = pring->numRiocb;
  2610. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2611. if (portRspPut >= portRspMax) {
  2612. /*
  2613. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2614. * rsp ring <portRspMax>
  2615. */
  2616. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2617. "0303 Ring %d handler: portRspPut %d "
  2618. "is bigger than rsp ring %d\n",
  2619. pring->ringno, portRspPut, portRspMax);
  2620. phba->link_state = LPFC_HBA_ERROR;
  2621. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2622. phba->work_hs = HS_FFER3;
  2623. lpfc_handle_eratt(phba);
  2624. return;
  2625. }
  2626. rmb();
  2627. while (pring->rspidx != portRspPut) {
  2628. /*
  2629. * Build a completion list and call the appropriate handler.
  2630. * The process is to get the next available response iocb, get
  2631. * a free iocb from the list, copy the response data into the
  2632. * free iocb, insert to the continuation list, and update the
  2633. * next response index to slim. This process makes response
  2634. * iocb's in the ring available to DMA as fast as possible but
  2635. * pays a penalty for a copy operation. Since the iocb is
  2636. * only 32 bytes, this penalty is considered small relative to
  2637. * the PCI reads for register values and a slim write. When
  2638. * the ulpLe field is set, the entire Command has been
  2639. * received.
  2640. */
  2641. entry = lpfc_resp_iocb(phba, pring);
  2642. phba->last_completion_time = jiffies;
  2643. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2644. if (rspiocbp == NULL) {
  2645. printk(KERN_ERR "%s: out of buffers! Failing "
  2646. "completion.\n", __func__);
  2647. break;
  2648. }
  2649. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2650. phba->iocb_rsp_size);
  2651. irsp = &rspiocbp->iocb;
  2652. if (++pring->rspidx >= portRspMax)
  2653. pring->rspidx = 0;
  2654. if (pring->ringno == LPFC_ELS_RING) {
  2655. lpfc_debugfs_slow_ring_trc(phba,
  2656. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2657. *(((uint32_t *) irsp) + 4),
  2658. *(((uint32_t *) irsp) + 6),
  2659. *(((uint32_t *) irsp) + 7));
  2660. }
  2661. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2662. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2663. /* Handle the response IOCB */
  2664. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2665. spin_lock_irqsave(&phba->hbalock, iflag);
  2666. /*
  2667. * If the port response put pointer has not been updated, sync
  2668. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2669. * response put pointer.
  2670. */
  2671. if (pring->rspidx == portRspPut) {
  2672. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2673. }
  2674. } /* while (pring->rspidx != portRspPut) */
  2675. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2676. /* At least one response entry has been freed */
  2677. pring->stats.iocb_rsp_full++;
  2678. /* SET RxRE_RSP in Chip Att register */
  2679. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2680. writel(status, phba->CAregaddr);
  2681. readl(phba->CAregaddr); /* flush */
  2682. }
  2683. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2684. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2685. pring->stats.iocb_cmd_empty++;
  2686. /* Force update of the local copy of cmdGetInx */
  2687. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2688. lpfc_sli_resume_iocb(phba, pring);
  2689. if ((pring->lpfc_sli_cmd_available))
  2690. (pring->lpfc_sli_cmd_available) (phba, pring);
  2691. }
  2692. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2693. return;
  2694. }
  2695. /**
  2696. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2697. * @phba: Pointer to HBA context object.
  2698. * @pring: Pointer to driver SLI ring object.
  2699. * @mask: Host attention register mask for this ring.
  2700. *
  2701. * This function is called from the worker thread when there is a pending
  2702. * ELS response iocb on the driver internal slow-path response iocb worker
  2703. * queue. The caller does not hold any lock. The function will remove each
  2704. * response iocb from the response worker queue and calls the handle
  2705. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2706. **/
  2707. static void
  2708. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2709. struct lpfc_sli_ring *pring, uint32_t mask)
  2710. {
  2711. struct lpfc_iocbq *irspiocbq;
  2712. struct hbq_dmabuf *dmabuf;
  2713. struct lpfc_cq_event *cq_event;
  2714. unsigned long iflag;
  2715. spin_lock_irqsave(&phba->hbalock, iflag);
  2716. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2719. /* Get the response iocb from the head of work queue */
  2720. spin_lock_irqsave(&phba->hbalock, iflag);
  2721. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2722. cq_event, struct lpfc_cq_event, list);
  2723. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2724. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2725. case CQE_CODE_COMPL_WQE:
  2726. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2727. cq_event);
  2728. /* Translate ELS WCQE to response IOCBQ */
  2729. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2730. irspiocbq);
  2731. if (irspiocbq)
  2732. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2733. irspiocbq);
  2734. break;
  2735. case CQE_CODE_RECEIVE:
  2736. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2737. cq_event);
  2738. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2739. break;
  2740. default:
  2741. break;
  2742. }
  2743. }
  2744. }
  2745. /**
  2746. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2747. * @phba: Pointer to HBA context object.
  2748. * @pring: Pointer to driver SLI ring object.
  2749. *
  2750. * This function aborts all iocbs in the given ring and frees all the iocb
  2751. * objects in txq. This function issues an abort iocb for all the iocb commands
  2752. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2753. * the return of this function. The caller is not required to hold any locks.
  2754. **/
  2755. void
  2756. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2757. {
  2758. LIST_HEAD(completions);
  2759. struct lpfc_iocbq *iocb, *next_iocb;
  2760. if (pring->ringno == LPFC_ELS_RING) {
  2761. lpfc_fabric_abort_hba(phba);
  2762. }
  2763. /* Error everything on txq and txcmplq
  2764. * First do the txq.
  2765. */
  2766. spin_lock_irq(&phba->hbalock);
  2767. list_splice_init(&pring->txq, &completions);
  2768. pring->txq_cnt = 0;
  2769. /* Next issue ABTS for everything on the txcmplq */
  2770. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2771. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2772. spin_unlock_irq(&phba->hbalock);
  2773. /* Cancel all the IOCBs from the completions list */
  2774. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2775. IOERR_SLI_ABORTED);
  2776. }
  2777. /**
  2778. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2779. * @phba: Pointer to HBA context object.
  2780. *
  2781. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2782. * objects in txq and txcmplq. This function will not issue abort iocbs
  2783. * for all the iocb commands in txcmplq, they will just be returned with
  2784. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2785. * slot has been permanently disabled.
  2786. **/
  2787. void
  2788. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2789. {
  2790. LIST_HEAD(txq);
  2791. LIST_HEAD(txcmplq);
  2792. struct lpfc_sli *psli = &phba->sli;
  2793. struct lpfc_sli_ring *pring;
  2794. /* Currently, only one fcp ring */
  2795. pring = &psli->ring[psli->fcp_ring];
  2796. spin_lock_irq(&phba->hbalock);
  2797. /* Retrieve everything on txq */
  2798. list_splice_init(&pring->txq, &txq);
  2799. pring->txq_cnt = 0;
  2800. /* Retrieve everything on the txcmplq */
  2801. list_splice_init(&pring->txcmplq, &txcmplq);
  2802. pring->txcmplq_cnt = 0;
  2803. spin_unlock_irq(&phba->hbalock);
  2804. /* Flush the txq */
  2805. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_DOWN);
  2807. /* Flush the txcmpq */
  2808. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2809. IOERR_SLI_DOWN);
  2810. }
  2811. /**
  2812. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2813. * @phba: Pointer to HBA context object.
  2814. * @mask: Bit mask to be checked.
  2815. *
  2816. * This function reads the host status register and compares
  2817. * with the provided bit mask to check if HBA completed
  2818. * the restart. This function will wait in a loop for the
  2819. * HBA to complete restart. If the HBA does not restart within
  2820. * 15 iterations, the function will reset the HBA again. The
  2821. * function returns 1 when HBA fail to restart otherwise returns
  2822. * zero.
  2823. **/
  2824. static int
  2825. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2826. {
  2827. uint32_t status;
  2828. int i = 0;
  2829. int retval = 0;
  2830. /* Read the HBA Host Status Register */
  2831. status = readl(phba->HSregaddr);
  2832. /*
  2833. * Check status register every 100ms for 5 retries, then every
  2834. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2835. * every 2.5 sec for 4.
  2836. * Break our of the loop if errors occurred during init.
  2837. */
  2838. while (((status & mask) != mask) &&
  2839. !(status & HS_FFERM) &&
  2840. i++ < 20) {
  2841. if (i <= 5)
  2842. msleep(10);
  2843. else if (i <= 10)
  2844. msleep(500);
  2845. else
  2846. msleep(2500);
  2847. if (i == 15) {
  2848. /* Do post */
  2849. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2850. lpfc_sli_brdrestart(phba);
  2851. }
  2852. /* Read the HBA Host Status Register */
  2853. status = readl(phba->HSregaddr);
  2854. }
  2855. /* Check to see if any errors occurred during init */
  2856. if ((status & HS_FFERM) || (i >= 20)) {
  2857. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2858. "2751 Adapter failed to restart, "
  2859. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2860. status,
  2861. readl(phba->MBslimaddr + 0xa8),
  2862. readl(phba->MBslimaddr + 0xac));
  2863. phba->link_state = LPFC_HBA_ERROR;
  2864. retval = 1;
  2865. }
  2866. return retval;
  2867. }
  2868. /**
  2869. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2870. * @phba: Pointer to HBA context object.
  2871. * @mask: Bit mask to be checked.
  2872. *
  2873. * This function checks the host status register to check if HBA is
  2874. * ready. This function will wait in a loop for the HBA to be ready
  2875. * If the HBA is not ready , the function will will reset the HBA PCI
  2876. * function again. The function returns 1 when HBA fail to be ready
  2877. * otherwise returns zero.
  2878. **/
  2879. static int
  2880. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2881. {
  2882. uint32_t status;
  2883. int retval = 0;
  2884. /* Read the HBA Host Status Register */
  2885. status = lpfc_sli4_post_status_check(phba);
  2886. if (status) {
  2887. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2888. lpfc_sli_brdrestart(phba);
  2889. status = lpfc_sli4_post_status_check(phba);
  2890. }
  2891. /* Check to see if any errors occurred during init */
  2892. if (status) {
  2893. phba->link_state = LPFC_HBA_ERROR;
  2894. retval = 1;
  2895. } else
  2896. phba->sli4_hba.intr_enable = 0;
  2897. return retval;
  2898. }
  2899. /**
  2900. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2901. * @phba: Pointer to HBA context object.
  2902. * @mask: Bit mask to be checked.
  2903. *
  2904. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2905. * from the API jump table function pointer from the lpfc_hba struct.
  2906. **/
  2907. int
  2908. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2909. {
  2910. return phba->lpfc_sli_brdready(phba, mask);
  2911. }
  2912. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2913. /**
  2914. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2915. * @phba: Pointer to HBA context object.
  2916. *
  2917. * This function is called before resetting an HBA. This
  2918. * function requests HBA to quiesce DMAs before a reset.
  2919. **/
  2920. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2921. {
  2922. uint32_t __iomem *resp_buf;
  2923. uint32_t __iomem *mbox_buf;
  2924. volatile uint32_t mbox;
  2925. uint32_t hc_copy;
  2926. int i;
  2927. uint8_t hdrtype;
  2928. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2929. if (hdrtype != 0x80 ||
  2930. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2931. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2932. return;
  2933. /*
  2934. * Tell the other part of the chip to suspend temporarily all
  2935. * its DMA activity.
  2936. */
  2937. resp_buf = phba->MBslimaddr;
  2938. /* Disable the error attention */
  2939. hc_copy = readl(phba->HCregaddr);
  2940. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2941. readl(phba->HCregaddr); /* flush */
  2942. phba->link_flag |= LS_IGNORE_ERATT;
  2943. if (readl(phba->HAregaddr) & HA_ERATT) {
  2944. /* Clear Chip error bit */
  2945. writel(HA_ERATT, phba->HAregaddr);
  2946. phba->pport->stopped = 1;
  2947. }
  2948. mbox = 0;
  2949. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2950. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2951. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2952. mbox_buf = phba->MBslimaddr;
  2953. writel(mbox, mbox_buf);
  2954. for (i = 0;
  2955. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2956. mdelay(1);
  2957. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2958. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2959. phba->pport->stopped)
  2960. goto restore_hc;
  2961. else
  2962. goto clear_errat;
  2963. }
  2964. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2965. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2966. mdelay(1);
  2967. clear_errat:
  2968. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2969. mdelay(1);
  2970. if (readl(phba->HAregaddr) & HA_ERATT) {
  2971. writel(HA_ERATT, phba->HAregaddr);
  2972. phba->pport->stopped = 1;
  2973. }
  2974. restore_hc:
  2975. phba->link_flag &= ~LS_IGNORE_ERATT;
  2976. writel(hc_copy, phba->HCregaddr);
  2977. readl(phba->HCregaddr); /* flush */
  2978. }
  2979. /**
  2980. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2981. * @phba: Pointer to HBA context object.
  2982. *
  2983. * This function issues a kill_board mailbox command and waits for
  2984. * the error attention interrupt. This function is called for stopping
  2985. * the firmware processing. The caller is not required to hold any
  2986. * locks. This function calls lpfc_hba_down_post function to free
  2987. * any pending commands after the kill. The function will return 1 when it
  2988. * fails to kill the board else will return 0.
  2989. **/
  2990. int
  2991. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2992. {
  2993. struct lpfc_sli *psli;
  2994. LPFC_MBOXQ_t *pmb;
  2995. uint32_t status;
  2996. uint32_t ha_copy;
  2997. int retval;
  2998. int i = 0;
  2999. psli = &phba->sli;
  3000. /* Kill HBA */
  3001. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3002. "0329 Kill HBA Data: x%x x%x\n",
  3003. phba->pport->port_state, psli->sli_flag);
  3004. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3005. if (!pmb)
  3006. return 1;
  3007. /* Disable the error attention */
  3008. spin_lock_irq(&phba->hbalock);
  3009. status = readl(phba->HCregaddr);
  3010. status &= ~HC_ERINT_ENA;
  3011. writel(status, phba->HCregaddr);
  3012. readl(phba->HCregaddr); /* flush */
  3013. phba->link_flag |= LS_IGNORE_ERATT;
  3014. spin_unlock_irq(&phba->hbalock);
  3015. lpfc_kill_board(phba, pmb);
  3016. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3017. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3018. if (retval != MBX_SUCCESS) {
  3019. if (retval != MBX_BUSY)
  3020. mempool_free(pmb, phba->mbox_mem_pool);
  3021. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3022. "2752 KILL_BOARD command failed retval %d\n",
  3023. retval);
  3024. spin_lock_irq(&phba->hbalock);
  3025. phba->link_flag &= ~LS_IGNORE_ERATT;
  3026. spin_unlock_irq(&phba->hbalock);
  3027. return 1;
  3028. }
  3029. spin_lock_irq(&phba->hbalock);
  3030. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3031. spin_unlock_irq(&phba->hbalock);
  3032. mempool_free(pmb, phba->mbox_mem_pool);
  3033. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3034. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3035. * 3 seconds we still set HBA_ERROR state because the status of the
  3036. * board is now undefined.
  3037. */
  3038. ha_copy = readl(phba->HAregaddr);
  3039. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3040. mdelay(100);
  3041. ha_copy = readl(phba->HAregaddr);
  3042. }
  3043. del_timer_sync(&psli->mbox_tmo);
  3044. if (ha_copy & HA_ERATT) {
  3045. writel(HA_ERATT, phba->HAregaddr);
  3046. phba->pport->stopped = 1;
  3047. }
  3048. spin_lock_irq(&phba->hbalock);
  3049. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3050. psli->mbox_active = NULL;
  3051. phba->link_flag &= ~LS_IGNORE_ERATT;
  3052. spin_unlock_irq(&phba->hbalock);
  3053. lpfc_hba_down_post(phba);
  3054. phba->link_state = LPFC_HBA_ERROR;
  3055. return ha_copy & HA_ERATT ? 0 : 1;
  3056. }
  3057. /**
  3058. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3059. * @phba: Pointer to HBA context object.
  3060. *
  3061. * This function resets the HBA by writing HC_INITFF to the control
  3062. * register. After the HBA resets, this function resets all the iocb ring
  3063. * indices. This function disables PCI layer parity checking during
  3064. * the reset.
  3065. * This function returns 0 always.
  3066. * The caller is not required to hold any locks.
  3067. **/
  3068. int
  3069. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3070. {
  3071. struct lpfc_sli *psli;
  3072. struct lpfc_sli_ring *pring;
  3073. uint16_t cfg_value;
  3074. int i;
  3075. psli = &phba->sli;
  3076. /* Reset HBA */
  3077. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3078. "0325 Reset HBA Data: x%x x%x\n",
  3079. phba->pport->port_state, psli->sli_flag);
  3080. /* perform board reset */
  3081. phba->fc_eventTag = 0;
  3082. phba->link_events = 0;
  3083. phba->pport->fc_myDID = 0;
  3084. phba->pport->fc_prevDID = 0;
  3085. /* Turn off parity checking and serr during the physical reset */
  3086. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3087. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3088. (cfg_value &
  3089. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3090. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3091. /* Now toggle INITFF bit in the Host Control Register */
  3092. writel(HC_INITFF, phba->HCregaddr);
  3093. mdelay(1);
  3094. readl(phba->HCregaddr); /* flush */
  3095. writel(0, phba->HCregaddr);
  3096. readl(phba->HCregaddr); /* flush */
  3097. /* Restore PCI cmd register */
  3098. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3099. /* Initialize relevant SLI info */
  3100. for (i = 0; i < psli->num_rings; i++) {
  3101. pring = &psli->ring[i];
  3102. pring->flag = 0;
  3103. pring->rspidx = 0;
  3104. pring->next_cmdidx = 0;
  3105. pring->local_getidx = 0;
  3106. pring->cmdidx = 0;
  3107. pring->missbufcnt = 0;
  3108. }
  3109. phba->link_state = LPFC_WARM_START;
  3110. return 0;
  3111. }
  3112. /**
  3113. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3114. * @phba: Pointer to HBA context object.
  3115. *
  3116. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3117. * checking during resets the device. The caller is not required to hold
  3118. * any locks.
  3119. *
  3120. * This function returns 0 always.
  3121. **/
  3122. int
  3123. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3124. {
  3125. struct lpfc_sli *psli = &phba->sli;
  3126. uint16_t cfg_value;
  3127. uint8_t qindx;
  3128. /* Reset HBA */
  3129. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3130. "0295 Reset HBA Data: x%x x%x\n",
  3131. phba->pport->port_state, psli->sli_flag);
  3132. /* perform board reset */
  3133. phba->fc_eventTag = 0;
  3134. phba->link_events = 0;
  3135. phba->pport->fc_myDID = 0;
  3136. phba->pport->fc_prevDID = 0;
  3137. /* Turn off parity checking and serr during the physical reset */
  3138. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3139. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3140. (cfg_value &
  3141. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3142. spin_lock_irq(&phba->hbalock);
  3143. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3144. phba->fcf.fcf_flag = 0;
  3145. /* Clean up the child queue list for the CQs */
  3146. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3147. list_del_init(&phba->sli4_hba.els_wq->list);
  3148. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3149. list_del_init(&phba->sli4_hba.dat_rq->list);
  3150. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3151. list_del_init(&phba->sli4_hba.els_cq->list);
  3152. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3153. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3154. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3155. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3156. spin_unlock_irq(&phba->hbalock);
  3157. /* Now physically reset the device */
  3158. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3159. "0389 Performing PCI function reset!\n");
  3160. /* Perform FCoE PCI function reset */
  3161. lpfc_pci_function_reset(phba);
  3162. return 0;
  3163. }
  3164. /**
  3165. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3166. * @phba: Pointer to HBA context object.
  3167. *
  3168. * This function is called in the SLI initialization code path to
  3169. * restart the HBA. The caller is not required to hold any lock.
  3170. * This function writes MBX_RESTART mailbox command to the SLIM and
  3171. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3172. * function to free any pending commands. The function enables
  3173. * POST only during the first initialization. The function returns zero.
  3174. * The function does not guarantee completion of MBX_RESTART mailbox
  3175. * command before the return of this function.
  3176. **/
  3177. static int
  3178. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3179. {
  3180. MAILBOX_t *mb;
  3181. struct lpfc_sli *psli;
  3182. volatile uint32_t word0;
  3183. void __iomem *to_slim;
  3184. uint32_t hba_aer_enabled;
  3185. spin_lock_irq(&phba->hbalock);
  3186. /* Take PCIe device Advanced Error Reporting (AER) state */
  3187. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3188. psli = &phba->sli;
  3189. /* Restart HBA */
  3190. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3191. "0337 Restart HBA Data: x%x x%x\n",
  3192. phba->pport->port_state, psli->sli_flag);
  3193. word0 = 0;
  3194. mb = (MAILBOX_t *) &word0;
  3195. mb->mbxCommand = MBX_RESTART;
  3196. mb->mbxHc = 1;
  3197. lpfc_reset_barrier(phba);
  3198. to_slim = phba->MBslimaddr;
  3199. writel(*(uint32_t *) mb, to_slim);
  3200. readl(to_slim); /* flush */
  3201. /* Only skip post after fc_ffinit is completed */
  3202. if (phba->pport->port_state)
  3203. word0 = 1; /* This is really setting up word1 */
  3204. else
  3205. word0 = 0; /* This is really setting up word1 */
  3206. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3207. writel(*(uint32_t *) mb, to_slim);
  3208. readl(to_slim); /* flush */
  3209. lpfc_sli_brdreset(phba);
  3210. phba->pport->stopped = 0;
  3211. phba->link_state = LPFC_INIT_START;
  3212. phba->hba_flag = 0;
  3213. spin_unlock_irq(&phba->hbalock);
  3214. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3215. psli->stats_start = get_seconds();
  3216. /* Give the INITFF and Post time to settle. */
  3217. mdelay(100);
  3218. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3219. if (hba_aer_enabled)
  3220. pci_disable_pcie_error_reporting(phba->pcidev);
  3221. lpfc_hba_down_post(phba);
  3222. return 0;
  3223. }
  3224. /**
  3225. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3226. * @phba: Pointer to HBA context object.
  3227. *
  3228. * This function is called in the SLI initialization code path to restart
  3229. * a SLI4 HBA. The caller is not required to hold any lock.
  3230. * At the end of the function, it calls lpfc_hba_down_post function to
  3231. * free any pending commands.
  3232. **/
  3233. static int
  3234. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3235. {
  3236. struct lpfc_sli *psli = &phba->sli;
  3237. /* Restart HBA */
  3238. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3239. "0296 Restart HBA Data: x%x x%x\n",
  3240. phba->pport->port_state, psli->sli_flag);
  3241. lpfc_sli4_brdreset(phba);
  3242. spin_lock_irq(&phba->hbalock);
  3243. phba->pport->stopped = 0;
  3244. phba->link_state = LPFC_INIT_START;
  3245. phba->hba_flag = 0;
  3246. spin_unlock_irq(&phba->hbalock);
  3247. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3248. psli->stats_start = get_seconds();
  3249. lpfc_hba_down_post(phba);
  3250. return 0;
  3251. }
  3252. /**
  3253. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3254. * @phba: Pointer to HBA context object.
  3255. *
  3256. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3257. * API jump table function pointer from the lpfc_hba struct.
  3258. **/
  3259. int
  3260. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3261. {
  3262. return phba->lpfc_sli_brdrestart(phba);
  3263. }
  3264. /**
  3265. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3266. * @phba: Pointer to HBA context object.
  3267. *
  3268. * This function is called after a HBA restart to wait for successful
  3269. * restart of the HBA. Successful restart of the HBA is indicated by
  3270. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3271. * iteration, the function will restart the HBA again. The function returns
  3272. * zero if HBA successfully restarted else returns negative error code.
  3273. **/
  3274. static int
  3275. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3276. {
  3277. uint32_t status, i = 0;
  3278. /* Read the HBA Host Status Register */
  3279. status = readl(phba->HSregaddr);
  3280. /* Check status register to see what current state is */
  3281. i = 0;
  3282. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3283. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3284. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3285. * 4.
  3286. */
  3287. if (i++ >= 20) {
  3288. /* Adapter failed to init, timeout, status reg
  3289. <status> */
  3290. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3291. "0436 Adapter failed to init, "
  3292. "timeout, status reg x%x, "
  3293. "FW Data: A8 x%x AC x%x\n", status,
  3294. readl(phba->MBslimaddr + 0xa8),
  3295. readl(phba->MBslimaddr + 0xac));
  3296. phba->link_state = LPFC_HBA_ERROR;
  3297. return -ETIMEDOUT;
  3298. }
  3299. /* Check to see if any errors occurred during init */
  3300. if (status & HS_FFERM) {
  3301. /* ERROR: During chipset initialization */
  3302. /* Adapter failed to init, chipset, status reg
  3303. <status> */
  3304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3305. "0437 Adapter failed to init, "
  3306. "chipset, status reg x%x, "
  3307. "FW Data: A8 x%x AC x%x\n", status,
  3308. readl(phba->MBslimaddr + 0xa8),
  3309. readl(phba->MBslimaddr + 0xac));
  3310. phba->link_state = LPFC_HBA_ERROR;
  3311. return -EIO;
  3312. }
  3313. if (i <= 5) {
  3314. msleep(10);
  3315. } else if (i <= 10) {
  3316. msleep(500);
  3317. } else {
  3318. msleep(2500);
  3319. }
  3320. if (i == 15) {
  3321. /* Do post */
  3322. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3323. lpfc_sli_brdrestart(phba);
  3324. }
  3325. /* Read the HBA Host Status Register */
  3326. status = readl(phba->HSregaddr);
  3327. }
  3328. /* Check to see if any errors occurred during init */
  3329. if (status & HS_FFERM) {
  3330. /* ERROR: During chipset initialization */
  3331. /* Adapter failed to init, chipset, status reg <status> */
  3332. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3333. "0438 Adapter failed to init, chipset, "
  3334. "status reg x%x, "
  3335. "FW Data: A8 x%x AC x%x\n", status,
  3336. readl(phba->MBslimaddr + 0xa8),
  3337. readl(phba->MBslimaddr + 0xac));
  3338. phba->link_state = LPFC_HBA_ERROR;
  3339. return -EIO;
  3340. }
  3341. /* Clear all interrupt enable conditions */
  3342. writel(0, phba->HCregaddr);
  3343. readl(phba->HCregaddr); /* flush */
  3344. /* setup host attn register */
  3345. writel(0xffffffff, phba->HAregaddr);
  3346. readl(phba->HAregaddr); /* flush */
  3347. return 0;
  3348. }
  3349. /**
  3350. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3351. *
  3352. * This function calculates and returns the number of HBQs required to be
  3353. * configured.
  3354. **/
  3355. int
  3356. lpfc_sli_hbq_count(void)
  3357. {
  3358. return ARRAY_SIZE(lpfc_hbq_defs);
  3359. }
  3360. /**
  3361. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3362. *
  3363. * This function adds the number of hbq entries in every HBQ to get
  3364. * the total number of hbq entries required for the HBA and returns
  3365. * the total count.
  3366. **/
  3367. static int
  3368. lpfc_sli_hbq_entry_count(void)
  3369. {
  3370. int hbq_count = lpfc_sli_hbq_count();
  3371. int count = 0;
  3372. int i;
  3373. for (i = 0; i < hbq_count; ++i)
  3374. count += lpfc_hbq_defs[i]->entry_count;
  3375. return count;
  3376. }
  3377. /**
  3378. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3379. *
  3380. * This function calculates amount of memory required for all hbq entries
  3381. * to be configured and returns the total memory required.
  3382. **/
  3383. int
  3384. lpfc_sli_hbq_size(void)
  3385. {
  3386. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3387. }
  3388. /**
  3389. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3390. * @phba: Pointer to HBA context object.
  3391. *
  3392. * This function is called during the SLI initialization to configure
  3393. * all the HBQs and post buffers to the HBQ. The caller is not
  3394. * required to hold any locks. This function will return zero if successful
  3395. * else it will return negative error code.
  3396. **/
  3397. static int
  3398. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3399. {
  3400. int hbq_count = lpfc_sli_hbq_count();
  3401. LPFC_MBOXQ_t *pmb;
  3402. MAILBOX_t *pmbox;
  3403. uint32_t hbqno;
  3404. uint32_t hbq_entry_index;
  3405. /* Get a Mailbox buffer to setup mailbox
  3406. * commands for HBA initialization
  3407. */
  3408. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3409. if (!pmb)
  3410. return -ENOMEM;
  3411. pmbox = &pmb->u.mb;
  3412. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3413. phba->link_state = LPFC_INIT_MBX_CMDS;
  3414. phba->hbq_in_use = 1;
  3415. hbq_entry_index = 0;
  3416. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3417. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3418. phba->hbqs[hbqno].hbqPutIdx = 0;
  3419. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3420. phba->hbqs[hbqno].entry_count =
  3421. lpfc_hbq_defs[hbqno]->entry_count;
  3422. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3423. hbq_entry_index, pmb);
  3424. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3425. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3426. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3427. mbxStatus <status>, ring <num> */
  3428. lpfc_printf_log(phba, KERN_ERR,
  3429. LOG_SLI | LOG_VPORT,
  3430. "1805 Adapter failed to init. "
  3431. "Data: x%x x%x x%x\n",
  3432. pmbox->mbxCommand,
  3433. pmbox->mbxStatus, hbqno);
  3434. phba->link_state = LPFC_HBA_ERROR;
  3435. mempool_free(pmb, phba->mbox_mem_pool);
  3436. return ENXIO;
  3437. }
  3438. }
  3439. phba->hbq_count = hbq_count;
  3440. mempool_free(pmb, phba->mbox_mem_pool);
  3441. /* Initially populate or replenish the HBQs */
  3442. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3443. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3444. return 0;
  3445. }
  3446. /**
  3447. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3448. * @phba: Pointer to HBA context object.
  3449. *
  3450. * This function is called during the SLI initialization to configure
  3451. * all the HBQs and post buffers to the HBQ. The caller is not
  3452. * required to hold any locks. This function will return zero if successful
  3453. * else it will return negative error code.
  3454. **/
  3455. static int
  3456. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3457. {
  3458. phba->hbq_in_use = 1;
  3459. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3460. phba->hbq_count = 1;
  3461. /* Initially populate or replenish the HBQs */
  3462. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3463. return 0;
  3464. }
  3465. /**
  3466. * lpfc_sli_config_port - Issue config port mailbox command
  3467. * @phba: Pointer to HBA context object.
  3468. * @sli_mode: sli mode - 2/3
  3469. *
  3470. * This function is called by the sli intialization code path
  3471. * to issue config_port mailbox command. This function restarts the
  3472. * HBA firmware and issues a config_port mailbox command to configure
  3473. * the SLI interface in the sli mode specified by sli_mode
  3474. * variable. The caller is not required to hold any locks.
  3475. * The function returns 0 if successful, else returns negative error
  3476. * code.
  3477. **/
  3478. int
  3479. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3480. {
  3481. LPFC_MBOXQ_t *pmb;
  3482. uint32_t resetcount = 0, rc = 0, done = 0;
  3483. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3484. if (!pmb) {
  3485. phba->link_state = LPFC_HBA_ERROR;
  3486. return -ENOMEM;
  3487. }
  3488. phba->sli_rev = sli_mode;
  3489. while (resetcount < 2 && !done) {
  3490. spin_lock_irq(&phba->hbalock);
  3491. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3492. spin_unlock_irq(&phba->hbalock);
  3493. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3494. lpfc_sli_brdrestart(phba);
  3495. rc = lpfc_sli_chipset_init(phba);
  3496. if (rc)
  3497. break;
  3498. spin_lock_irq(&phba->hbalock);
  3499. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3500. spin_unlock_irq(&phba->hbalock);
  3501. resetcount++;
  3502. /* Call pre CONFIG_PORT mailbox command initialization. A
  3503. * value of 0 means the call was successful. Any other
  3504. * nonzero value is a failure, but if ERESTART is returned,
  3505. * the driver may reset the HBA and try again.
  3506. */
  3507. rc = lpfc_config_port_prep(phba);
  3508. if (rc == -ERESTART) {
  3509. phba->link_state = LPFC_LINK_UNKNOWN;
  3510. continue;
  3511. } else if (rc)
  3512. break;
  3513. phba->link_state = LPFC_INIT_MBX_CMDS;
  3514. lpfc_config_port(phba, pmb);
  3515. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3516. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3517. LPFC_SLI3_HBQ_ENABLED |
  3518. LPFC_SLI3_CRP_ENABLED |
  3519. LPFC_SLI3_INB_ENABLED |
  3520. LPFC_SLI3_BG_ENABLED);
  3521. if (rc != MBX_SUCCESS) {
  3522. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3523. "0442 Adapter failed to init, mbxCmd x%x "
  3524. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3525. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3526. spin_lock_irq(&phba->hbalock);
  3527. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3528. spin_unlock_irq(&phba->hbalock);
  3529. rc = -ENXIO;
  3530. } else {
  3531. /* Allow asynchronous mailbox command to go through */
  3532. spin_lock_irq(&phba->hbalock);
  3533. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3534. spin_unlock_irq(&phba->hbalock);
  3535. done = 1;
  3536. }
  3537. }
  3538. if (!done) {
  3539. rc = -EINVAL;
  3540. goto do_prep_failed;
  3541. }
  3542. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3543. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3544. rc = -ENXIO;
  3545. goto do_prep_failed;
  3546. }
  3547. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3548. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3549. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3550. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3551. phba->max_vpi : phba->max_vports;
  3552. } else
  3553. phba->max_vpi = 0;
  3554. if (pmb->u.mb.un.varCfgPort.gdss)
  3555. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3556. if (pmb->u.mb.un.varCfgPort.gerbm)
  3557. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3558. if (pmb->u.mb.un.varCfgPort.gcrp)
  3559. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3560. if (pmb->u.mb.un.varCfgPort.ginb) {
  3561. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3562. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3563. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3564. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3565. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3566. phba->inb_last_counter =
  3567. phba->mbox->us.s3_inb_pgp.counter;
  3568. } else {
  3569. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3570. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3571. phba->inb_ha_copy = NULL;
  3572. phba->inb_counter = NULL;
  3573. }
  3574. if (phba->cfg_enable_bg) {
  3575. if (pmb->u.mb.un.varCfgPort.gbg)
  3576. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3577. else
  3578. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3579. "0443 Adapter did not grant "
  3580. "BlockGuard\n");
  3581. }
  3582. } else {
  3583. phba->hbq_get = NULL;
  3584. phba->port_gp = phba->mbox->us.s2.port;
  3585. phba->inb_ha_copy = NULL;
  3586. phba->inb_counter = NULL;
  3587. phba->max_vpi = 0;
  3588. }
  3589. do_prep_failed:
  3590. mempool_free(pmb, phba->mbox_mem_pool);
  3591. return rc;
  3592. }
  3593. /**
  3594. * lpfc_sli_hba_setup - SLI intialization function
  3595. * @phba: Pointer to HBA context object.
  3596. *
  3597. * This function is the main SLI intialization function. This function
  3598. * is called by the HBA intialization code, HBA reset code and HBA
  3599. * error attention handler code. Caller is not required to hold any
  3600. * locks. This function issues config_port mailbox command to configure
  3601. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3602. * calls the config_port_post function to issue init_link mailbox
  3603. * command and to start the discovery. The function will return zero
  3604. * if successful, else it will return negative error code.
  3605. **/
  3606. int
  3607. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3608. {
  3609. uint32_t rc;
  3610. int mode = 3;
  3611. switch (lpfc_sli_mode) {
  3612. case 2:
  3613. if (phba->cfg_enable_npiv) {
  3614. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3615. "1824 NPIV enabled: Override lpfc_sli_mode "
  3616. "parameter (%d) to auto (0).\n",
  3617. lpfc_sli_mode);
  3618. break;
  3619. }
  3620. mode = 2;
  3621. break;
  3622. case 0:
  3623. case 3:
  3624. break;
  3625. default:
  3626. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3627. "1819 Unrecognized lpfc_sli_mode "
  3628. "parameter: %d.\n", lpfc_sli_mode);
  3629. break;
  3630. }
  3631. rc = lpfc_sli_config_port(phba, mode);
  3632. if (rc && lpfc_sli_mode == 3)
  3633. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3634. "1820 Unable to select SLI-3. "
  3635. "Not supported by adapter.\n");
  3636. if (rc && mode != 2)
  3637. rc = lpfc_sli_config_port(phba, 2);
  3638. if (rc)
  3639. goto lpfc_sli_hba_setup_error;
  3640. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3641. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3642. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3643. if (!rc) {
  3644. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3645. "2709 This device supports "
  3646. "Advanced Error Reporting (AER)\n");
  3647. spin_lock_irq(&phba->hbalock);
  3648. phba->hba_flag |= HBA_AER_ENABLED;
  3649. spin_unlock_irq(&phba->hbalock);
  3650. } else {
  3651. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3652. "2708 This device does not support "
  3653. "Advanced Error Reporting (AER)\n");
  3654. phba->cfg_aer_support = 0;
  3655. }
  3656. }
  3657. if (phba->sli_rev == 3) {
  3658. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3659. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3660. } else {
  3661. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3662. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3663. phba->sli3_options = 0;
  3664. }
  3665. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3666. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3667. phba->sli_rev, phba->max_vpi);
  3668. rc = lpfc_sli_ring_map(phba);
  3669. if (rc)
  3670. goto lpfc_sli_hba_setup_error;
  3671. /* Init HBQs */
  3672. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3673. rc = lpfc_sli_hbq_setup(phba);
  3674. if (rc)
  3675. goto lpfc_sli_hba_setup_error;
  3676. }
  3677. spin_lock_irq(&phba->hbalock);
  3678. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3679. spin_unlock_irq(&phba->hbalock);
  3680. rc = lpfc_config_port_post(phba);
  3681. if (rc)
  3682. goto lpfc_sli_hba_setup_error;
  3683. return rc;
  3684. lpfc_sli_hba_setup_error:
  3685. phba->link_state = LPFC_HBA_ERROR;
  3686. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3687. "0445 Firmware initialization failed\n");
  3688. return rc;
  3689. }
  3690. /**
  3691. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3692. * @phba: Pointer to HBA context object.
  3693. * @mboxq: mailbox pointer.
  3694. * This function issue a dump mailbox command to read config region
  3695. * 23 and parse the records in the region and populate driver
  3696. * data structure.
  3697. **/
  3698. static int
  3699. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3700. LPFC_MBOXQ_t *mboxq)
  3701. {
  3702. struct lpfc_dmabuf *mp;
  3703. struct lpfc_mqe *mqe;
  3704. uint32_t data_length;
  3705. int rc;
  3706. /* Program the default value of vlan_id and fc_map */
  3707. phba->valid_vlan = 0;
  3708. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3709. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3710. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3711. mqe = &mboxq->u.mqe;
  3712. if (lpfc_dump_fcoe_param(phba, mboxq))
  3713. return -ENOMEM;
  3714. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3715. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3716. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3717. "(%d):2571 Mailbox cmd x%x Status x%x "
  3718. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3719. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3720. "CQ: x%x x%x x%x x%x\n",
  3721. mboxq->vport ? mboxq->vport->vpi : 0,
  3722. bf_get(lpfc_mqe_command, mqe),
  3723. bf_get(lpfc_mqe_status, mqe),
  3724. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3725. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3726. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3727. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3728. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3729. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3730. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3731. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3732. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3733. mboxq->mcqe.word0,
  3734. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3735. mboxq->mcqe.trailer);
  3736. if (rc) {
  3737. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3738. kfree(mp);
  3739. return -EIO;
  3740. }
  3741. data_length = mqe->un.mb_words[5];
  3742. if (data_length > DMP_RGN23_SIZE) {
  3743. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3744. kfree(mp);
  3745. return -EIO;
  3746. }
  3747. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3748. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3749. kfree(mp);
  3750. return 0;
  3751. }
  3752. /**
  3753. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3754. * @phba: pointer to lpfc hba data structure.
  3755. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3756. * @vpd: pointer to the memory to hold resulting port vpd data.
  3757. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3758. * On output, the number of data bytes in @vpd.
  3759. *
  3760. * This routine executes a READ_REV SLI4 mailbox command. In
  3761. * addition, this routine gets the port vpd data.
  3762. *
  3763. * Return codes
  3764. * 0 - successful
  3765. * ENOMEM - could not allocated memory.
  3766. **/
  3767. static int
  3768. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3769. uint8_t *vpd, uint32_t *vpd_size)
  3770. {
  3771. int rc = 0;
  3772. uint32_t dma_size;
  3773. struct lpfc_dmabuf *dmabuf;
  3774. struct lpfc_mqe *mqe;
  3775. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3776. if (!dmabuf)
  3777. return -ENOMEM;
  3778. /*
  3779. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3780. * mailbox command.
  3781. */
  3782. dma_size = *vpd_size;
  3783. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3784. dma_size,
  3785. &dmabuf->phys,
  3786. GFP_KERNEL);
  3787. if (!dmabuf->virt) {
  3788. kfree(dmabuf);
  3789. return -ENOMEM;
  3790. }
  3791. memset(dmabuf->virt, 0, dma_size);
  3792. /*
  3793. * The SLI4 implementation of READ_REV conflicts at word1,
  3794. * bits 31:16 and SLI4 adds vpd functionality not present
  3795. * in SLI3. This code corrects the conflicts.
  3796. */
  3797. lpfc_read_rev(phba, mboxq);
  3798. mqe = &mboxq->u.mqe;
  3799. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3800. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3801. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3802. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3803. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3804. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3805. if (rc) {
  3806. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3807. dmabuf->virt, dmabuf->phys);
  3808. kfree(dmabuf);
  3809. return -EIO;
  3810. }
  3811. /*
  3812. * The available vpd length cannot be bigger than the
  3813. * DMA buffer passed to the port. Catch the less than
  3814. * case and update the caller's size.
  3815. */
  3816. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3817. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3818. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3819. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3820. dmabuf->virt, dmabuf->phys);
  3821. kfree(dmabuf);
  3822. return 0;
  3823. }
  3824. /**
  3825. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3826. * @phba: pointer to lpfc hba data structure.
  3827. *
  3828. * This routine is called to explicitly arm the SLI4 device's completion and
  3829. * event queues
  3830. **/
  3831. static void
  3832. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3833. {
  3834. uint8_t fcp_eqidx;
  3835. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3836. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3837. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3838. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3839. LPFC_QUEUE_REARM);
  3840. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3841. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3842. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3843. LPFC_QUEUE_REARM);
  3844. }
  3845. /**
  3846. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3847. * @phba: Pointer to HBA context object.
  3848. *
  3849. * This function is the main SLI4 device intialization PCI function. This
  3850. * function is called by the HBA intialization code, HBA reset code and
  3851. * HBA error attention handler code. Caller is not required to hold any
  3852. * locks.
  3853. **/
  3854. int
  3855. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3856. {
  3857. int rc;
  3858. LPFC_MBOXQ_t *mboxq;
  3859. struct lpfc_mqe *mqe;
  3860. uint8_t *vpd;
  3861. uint32_t vpd_size;
  3862. uint32_t ftr_rsp = 0;
  3863. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3864. struct lpfc_vport *vport = phba->pport;
  3865. struct lpfc_dmabuf *mp;
  3866. /* Perform a PCI function reset to start from clean */
  3867. rc = lpfc_pci_function_reset(phba);
  3868. if (unlikely(rc))
  3869. return -ENODEV;
  3870. /* Check the HBA Host Status Register for readyness */
  3871. rc = lpfc_sli4_post_status_check(phba);
  3872. if (unlikely(rc))
  3873. return -ENODEV;
  3874. else {
  3875. spin_lock_irq(&phba->hbalock);
  3876. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3877. spin_unlock_irq(&phba->hbalock);
  3878. }
  3879. /*
  3880. * Allocate a single mailbox container for initializing the
  3881. * port.
  3882. */
  3883. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3884. if (!mboxq)
  3885. return -ENOMEM;
  3886. /*
  3887. * Continue initialization with default values even if driver failed
  3888. * to read FCoE param config regions
  3889. */
  3890. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3891. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3892. "2570 Failed to read FCoE parameters\n");
  3893. /* Issue READ_REV to collect vpd and FW information. */
  3894. vpd_size = SLI4_PAGE_SIZE;
  3895. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3896. if (!vpd) {
  3897. rc = -ENOMEM;
  3898. goto out_free_mbox;
  3899. }
  3900. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3901. if (unlikely(rc))
  3902. goto out_free_vpd;
  3903. mqe = &mboxq->u.mqe;
  3904. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3905. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3906. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3907. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3908. LPFC_DCBX_CEE_MODE)
  3909. phba->hba_flag |= HBA_FIP_SUPPORT;
  3910. else
  3911. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3912. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3913. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3914. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3915. "0376 READ_REV Error. SLI Level %d "
  3916. "FCoE enabled %d\n",
  3917. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3918. rc = -EIO;
  3919. goto out_free_vpd;
  3920. }
  3921. /*
  3922. * Evaluate the read rev and vpd data. Populate the driver
  3923. * state with the results. If this routine fails, the failure
  3924. * is not fatal as the driver will use generic values.
  3925. */
  3926. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3927. if (unlikely(!rc)) {
  3928. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3929. "0377 Error %d parsing vpd. "
  3930. "Using defaults.\n", rc);
  3931. rc = 0;
  3932. }
  3933. /* Save information as VPD data */
  3934. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3935. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3936. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3937. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3938. &mqe->un.read_rev);
  3939. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3940. &mqe->un.read_rev);
  3941. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3942. &mqe->un.read_rev);
  3943. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3944. &mqe->un.read_rev);
  3945. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3946. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3947. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3948. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3949. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3950. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3951. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3952. "(%d):0380 READ_REV Status x%x "
  3953. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3954. mboxq->vport ? mboxq->vport->vpi : 0,
  3955. bf_get(lpfc_mqe_status, mqe),
  3956. phba->vpd.rev.opFwName,
  3957. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3958. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3959. /*
  3960. * Discover the port's supported feature set and match it against the
  3961. * hosts requests.
  3962. */
  3963. lpfc_request_features(phba, mboxq);
  3964. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3965. if (unlikely(rc)) {
  3966. rc = -EIO;
  3967. goto out_free_vpd;
  3968. }
  3969. /*
  3970. * The port must support FCP initiator mode as this is the
  3971. * only mode running in the host.
  3972. */
  3973. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3974. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3975. "0378 No support for fcpi mode.\n");
  3976. ftr_rsp++;
  3977. }
  3978. /*
  3979. * If the port cannot support the host's requested features
  3980. * then turn off the global config parameters to disable the
  3981. * feature in the driver. This is not a fatal error.
  3982. */
  3983. if ((phba->cfg_enable_bg) &&
  3984. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3985. ftr_rsp++;
  3986. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3987. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3988. ftr_rsp++;
  3989. if (ftr_rsp) {
  3990. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3991. "0379 Feature Mismatch Data: x%08x %08x "
  3992. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3993. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3994. phba->cfg_enable_npiv, phba->max_vpi);
  3995. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3996. phba->cfg_enable_bg = 0;
  3997. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3998. phba->cfg_enable_npiv = 0;
  3999. }
  4000. /* These SLI3 features are assumed in SLI4 */
  4001. spin_lock_irq(&phba->hbalock);
  4002. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4003. spin_unlock_irq(&phba->hbalock);
  4004. /* Read the port's service parameters. */
  4005. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4006. if (rc) {
  4007. phba->link_state = LPFC_HBA_ERROR;
  4008. rc = -ENOMEM;
  4009. goto out_free_vpd;
  4010. }
  4011. mboxq->vport = vport;
  4012. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4013. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4014. if (rc == MBX_SUCCESS) {
  4015. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4016. rc = 0;
  4017. }
  4018. /*
  4019. * This memory was allocated by the lpfc_read_sparam routine. Release
  4020. * it to the mbuf pool.
  4021. */
  4022. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4023. kfree(mp);
  4024. mboxq->context1 = NULL;
  4025. if (unlikely(rc)) {
  4026. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4027. "0382 READ_SPARAM command failed "
  4028. "status %d, mbxStatus x%x\n",
  4029. rc, bf_get(lpfc_mqe_status, mqe));
  4030. phba->link_state = LPFC_HBA_ERROR;
  4031. rc = -EIO;
  4032. goto out_free_vpd;
  4033. }
  4034. if (phba->cfg_soft_wwnn)
  4035. u64_to_wwn(phba->cfg_soft_wwnn,
  4036. vport->fc_sparam.nodeName.u.wwn);
  4037. if (phba->cfg_soft_wwpn)
  4038. u64_to_wwn(phba->cfg_soft_wwpn,
  4039. vport->fc_sparam.portName.u.wwn);
  4040. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4041. sizeof(struct lpfc_name));
  4042. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4043. sizeof(struct lpfc_name));
  4044. /* Update the fc_host data structures with new wwn. */
  4045. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4046. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4047. /* Register SGL pool to the device using non-embedded mailbox command */
  4048. rc = lpfc_sli4_post_sgl_list(phba);
  4049. if (unlikely(rc)) {
  4050. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4051. "0582 Error %d during sgl post operation\n",
  4052. rc);
  4053. rc = -ENODEV;
  4054. goto out_free_vpd;
  4055. }
  4056. /* Register SCSI SGL pool to the device */
  4057. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4058. if (unlikely(rc)) {
  4059. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4060. "0383 Error %d during scsi sgl post "
  4061. "operation\n", rc);
  4062. /* Some Scsi buffers were moved to the abort scsi list */
  4063. /* A pci function reset will repost them */
  4064. rc = -ENODEV;
  4065. goto out_free_vpd;
  4066. }
  4067. /* Post the rpi header region to the device. */
  4068. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4069. if (unlikely(rc)) {
  4070. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4071. "0393 Error %d during rpi post operation\n",
  4072. rc);
  4073. rc = -ENODEV;
  4074. goto out_free_vpd;
  4075. }
  4076. /* Set up all the queues to the device */
  4077. rc = lpfc_sli4_queue_setup(phba);
  4078. if (unlikely(rc)) {
  4079. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4080. "0381 Error %d during queue setup.\n ", rc);
  4081. goto out_stop_timers;
  4082. }
  4083. /* Arm the CQs and then EQs on device */
  4084. lpfc_sli4_arm_cqeq_intr(phba);
  4085. /* Indicate device interrupt mode */
  4086. phba->sli4_hba.intr_enable = 1;
  4087. /* Allow asynchronous mailbox command to go through */
  4088. spin_lock_irq(&phba->hbalock);
  4089. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4090. spin_unlock_irq(&phba->hbalock);
  4091. /* Post receive buffers to the device */
  4092. lpfc_sli4_rb_setup(phba);
  4093. /* Reset HBA FCF states after HBA reset */
  4094. phba->fcf.fcf_flag = 0;
  4095. phba->fcf.current_rec.flag = 0;
  4096. /* Start the ELS watchdog timer */
  4097. mod_timer(&vport->els_tmofunc,
  4098. jiffies + HZ * (phba->fc_ratov * 2));
  4099. /* Start heart beat timer */
  4100. mod_timer(&phba->hb_tmofunc,
  4101. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4102. phba->hb_outstanding = 0;
  4103. phba->last_completion_time = jiffies;
  4104. /* Start error attention (ERATT) polling timer */
  4105. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4106. /*
  4107. * The port is ready, set the host's link state to LINK_DOWN
  4108. * in preparation for link interrupts.
  4109. */
  4110. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4111. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4112. lpfc_set_loopback_flag(phba);
  4113. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4114. spin_lock_irq(&phba->hbalock);
  4115. phba->link_state = LPFC_LINK_DOWN;
  4116. spin_unlock_irq(&phba->hbalock);
  4117. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4118. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4119. kfree(vpd);
  4120. return 0;
  4121. } else
  4122. rc = -EIO;
  4123. /* Unset all the queues set up in this routine when error out */
  4124. if (rc)
  4125. lpfc_sli4_queue_unset(phba);
  4126. out_stop_timers:
  4127. if (rc)
  4128. lpfc_stop_hba_timers(phba);
  4129. out_free_vpd:
  4130. kfree(vpd);
  4131. out_free_mbox:
  4132. mempool_free(mboxq, phba->mbox_mem_pool);
  4133. return rc;
  4134. }
  4135. /**
  4136. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4137. * @ptr: context object - pointer to hba structure.
  4138. *
  4139. * This is the callback function for mailbox timer. The mailbox
  4140. * timer is armed when a new mailbox command is issued and the timer
  4141. * is deleted when the mailbox complete. The function is called by
  4142. * the kernel timer code when a mailbox does not complete within
  4143. * expected time. This function wakes up the worker thread to
  4144. * process the mailbox timeout and returns. All the processing is
  4145. * done by the worker thread function lpfc_mbox_timeout_handler.
  4146. **/
  4147. void
  4148. lpfc_mbox_timeout(unsigned long ptr)
  4149. {
  4150. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4151. unsigned long iflag;
  4152. uint32_t tmo_posted;
  4153. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4154. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4155. if (!tmo_posted)
  4156. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4157. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4158. if (!tmo_posted)
  4159. lpfc_worker_wake_up(phba);
  4160. return;
  4161. }
  4162. /**
  4163. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4164. * @phba: Pointer to HBA context object.
  4165. *
  4166. * This function is called from worker thread when a mailbox command times out.
  4167. * The caller is not required to hold any locks. This function will reset the
  4168. * HBA and recover all the pending commands.
  4169. **/
  4170. void
  4171. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4172. {
  4173. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4174. MAILBOX_t *mb = &pmbox->u.mb;
  4175. struct lpfc_sli *psli = &phba->sli;
  4176. struct lpfc_sli_ring *pring;
  4177. /* Check the pmbox pointer first. There is a race condition
  4178. * between the mbox timeout handler getting executed in the
  4179. * worklist and the mailbox actually completing. When this
  4180. * race condition occurs, the mbox_active will be NULL.
  4181. */
  4182. spin_lock_irq(&phba->hbalock);
  4183. if (pmbox == NULL) {
  4184. lpfc_printf_log(phba, KERN_WARNING,
  4185. LOG_MBOX | LOG_SLI,
  4186. "0353 Active Mailbox cleared - mailbox timeout "
  4187. "exiting\n");
  4188. spin_unlock_irq(&phba->hbalock);
  4189. return;
  4190. }
  4191. /* Mbox cmd <mbxCommand> timeout */
  4192. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4193. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4194. mb->mbxCommand,
  4195. phba->pport->port_state,
  4196. phba->sli.sli_flag,
  4197. phba->sli.mbox_active);
  4198. spin_unlock_irq(&phba->hbalock);
  4199. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4200. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4201. * it to fail all oustanding SCSI IO.
  4202. */
  4203. spin_lock_irq(&phba->pport->work_port_lock);
  4204. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4205. spin_unlock_irq(&phba->pport->work_port_lock);
  4206. spin_lock_irq(&phba->hbalock);
  4207. phba->link_state = LPFC_LINK_UNKNOWN;
  4208. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4209. spin_unlock_irq(&phba->hbalock);
  4210. pring = &psli->ring[psli->fcp_ring];
  4211. lpfc_sli_abort_iocb_ring(phba, pring);
  4212. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4213. "0345 Resetting board due to mailbox timeout\n");
  4214. /* Reset the HBA device */
  4215. lpfc_reset_hba(phba);
  4216. }
  4217. /**
  4218. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4219. * @phba: Pointer to HBA context object.
  4220. * @pmbox: Pointer to mailbox object.
  4221. * @flag: Flag indicating how the mailbox need to be processed.
  4222. *
  4223. * This function is called by discovery code and HBA management code
  4224. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4225. * function gets the hbalock to protect the data structures.
  4226. * The mailbox command can be submitted in polling mode, in which case
  4227. * this function will wait in a polling loop for the completion of the
  4228. * mailbox.
  4229. * If the mailbox is submitted in no_wait mode (not polling) the
  4230. * function will submit the command and returns immediately without waiting
  4231. * for the mailbox completion. The no_wait is supported only when HBA
  4232. * is in SLI2/SLI3 mode - interrupts are enabled.
  4233. * The SLI interface allows only one mailbox pending at a time. If the
  4234. * mailbox is issued in polling mode and there is already a mailbox
  4235. * pending, then the function will return an error. If the mailbox is issued
  4236. * in NO_WAIT mode and there is a mailbox pending already, the function
  4237. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4238. * The sli layer owns the mailbox object until the completion of mailbox
  4239. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4240. * return codes the caller owns the mailbox command after the return of
  4241. * the function.
  4242. **/
  4243. static int
  4244. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4245. uint32_t flag)
  4246. {
  4247. MAILBOX_t *mb;
  4248. struct lpfc_sli *psli = &phba->sli;
  4249. uint32_t status, evtctr;
  4250. uint32_t ha_copy;
  4251. int i;
  4252. unsigned long timeout;
  4253. unsigned long drvr_flag = 0;
  4254. uint32_t word0, ldata;
  4255. void __iomem *to_slim;
  4256. int processing_queue = 0;
  4257. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4258. if (!pmbox) {
  4259. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4260. /* processing mbox queue from intr_handler */
  4261. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4262. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4263. return MBX_SUCCESS;
  4264. }
  4265. processing_queue = 1;
  4266. pmbox = lpfc_mbox_get(phba);
  4267. if (!pmbox) {
  4268. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4269. return MBX_SUCCESS;
  4270. }
  4271. }
  4272. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4273. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4274. if(!pmbox->vport) {
  4275. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4276. lpfc_printf_log(phba, KERN_ERR,
  4277. LOG_MBOX | LOG_VPORT,
  4278. "1806 Mbox x%x failed. No vport\n",
  4279. pmbox->u.mb.mbxCommand);
  4280. dump_stack();
  4281. goto out_not_finished;
  4282. }
  4283. }
  4284. /* If the PCI channel is in offline state, do not post mbox. */
  4285. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4286. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4287. goto out_not_finished;
  4288. }
  4289. /* If HBA has a deferred error attention, fail the iocb. */
  4290. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4291. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4292. goto out_not_finished;
  4293. }
  4294. psli = &phba->sli;
  4295. mb = &pmbox->u.mb;
  4296. status = MBX_SUCCESS;
  4297. if (phba->link_state == LPFC_HBA_ERROR) {
  4298. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4299. /* Mbox command <mbxCommand> cannot issue */
  4300. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4301. "(%d):0311 Mailbox command x%x cannot "
  4302. "issue Data: x%x x%x\n",
  4303. pmbox->vport ? pmbox->vport->vpi : 0,
  4304. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4305. goto out_not_finished;
  4306. }
  4307. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4308. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4309. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4310. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4311. "(%d):2528 Mailbox command x%x cannot "
  4312. "issue Data: x%x x%x\n",
  4313. pmbox->vport ? pmbox->vport->vpi : 0,
  4314. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4315. goto out_not_finished;
  4316. }
  4317. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4318. /* Polling for a mbox command when another one is already active
  4319. * is not allowed in SLI. Also, the driver must have established
  4320. * SLI2 mode to queue and process multiple mbox commands.
  4321. */
  4322. if (flag & MBX_POLL) {
  4323. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4324. /* Mbox command <mbxCommand> cannot issue */
  4325. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4326. "(%d):2529 Mailbox command x%x "
  4327. "cannot issue Data: x%x x%x\n",
  4328. pmbox->vport ? pmbox->vport->vpi : 0,
  4329. pmbox->u.mb.mbxCommand,
  4330. psli->sli_flag, flag);
  4331. goto out_not_finished;
  4332. }
  4333. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4334. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4335. /* Mbox command <mbxCommand> cannot issue */
  4336. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4337. "(%d):2530 Mailbox command x%x "
  4338. "cannot issue Data: x%x x%x\n",
  4339. pmbox->vport ? pmbox->vport->vpi : 0,
  4340. pmbox->u.mb.mbxCommand,
  4341. psli->sli_flag, flag);
  4342. goto out_not_finished;
  4343. }
  4344. /* Another mailbox command is still being processed, queue this
  4345. * command to be processed later.
  4346. */
  4347. lpfc_mbox_put(phba, pmbox);
  4348. /* Mbox cmd issue - BUSY */
  4349. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4350. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4351. "x%x x%x x%x x%x\n",
  4352. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4353. mb->mbxCommand, phba->pport->port_state,
  4354. psli->sli_flag, flag);
  4355. psli->slistat.mbox_busy++;
  4356. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4357. if (pmbox->vport) {
  4358. lpfc_debugfs_disc_trc(pmbox->vport,
  4359. LPFC_DISC_TRC_MBOX_VPORT,
  4360. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4361. (uint32_t)mb->mbxCommand,
  4362. mb->un.varWords[0], mb->un.varWords[1]);
  4363. }
  4364. else {
  4365. lpfc_debugfs_disc_trc(phba->pport,
  4366. LPFC_DISC_TRC_MBOX,
  4367. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4368. (uint32_t)mb->mbxCommand,
  4369. mb->un.varWords[0], mb->un.varWords[1]);
  4370. }
  4371. return MBX_BUSY;
  4372. }
  4373. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4374. /* If we are not polling, we MUST be in SLI2 mode */
  4375. if (flag != MBX_POLL) {
  4376. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4377. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4378. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4379. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4380. /* Mbox command <mbxCommand> cannot issue */
  4381. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4382. "(%d):2531 Mailbox command x%x "
  4383. "cannot issue Data: x%x x%x\n",
  4384. pmbox->vport ? pmbox->vport->vpi : 0,
  4385. pmbox->u.mb.mbxCommand,
  4386. psli->sli_flag, flag);
  4387. goto out_not_finished;
  4388. }
  4389. /* timeout active mbox command */
  4390. mod_timer(&psli->mbox_tmo, (jiffies +
  4391. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4392. }
  4393. /* Mailbox cmd <cmd> issue */
  4394. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4395. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4396. "x%x\n",
  4397. pmbox->vport ? pmbox->vport->vpi : 0,
  4398. mb->mbxCommand, phba->pport->port_state,
  4399. psli->sli_flag, flag);
  4400. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4401. if (pmbox->vport) {
  4402. lpfc_debugfs_disc_trc(pmbox->vport,
  4403. LPFC_DISC_TRC_MBOX_VPORT,
  4404. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4405. (uint32_t)mb->mbxCommand,
  4406. mb->un.varWords[0], mb->un.varWords[1]);
  4407. }
  4408. else {
  4409. lpfc_debugfs_disc_trc(phba->pport,
  4410. LPFC_DISC_TRC_MBOX,
  4411. "MBOX Send: cmd:x%x mb:x%x x%x",
  4412. (uint32_t)mb->mbxCommand,
  4413. mb->un.varWords[0], mb->un.varWords[1]);
  4414. }
  4415. }
  4416. psli->slistat.mbox_cmd++;
  4417. evtctr = psli->slistat.mbox_event;
  4418. /* next set own bit for the adapter and copy over command word */
  4419. mb->mbxOwner = OWN_CHIP;
  4420. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4421. /* Populate mbox extension offset word. */
  4422. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4423. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4424. = (uint8_t *)phba->mbox_ext
  4425. - (uint8_t *)phba->mbox;
  4426. }
  4427. /* Copy the mailbox extension data */
  4428. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4429. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4430. (uint8_t *)phba->mbox_ext,
  4431. pmbox->in_ext_byte_len);
  4432. }
  4433. /* Copy command data to host SLIM area */
  4434. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4435. } else {
  4436. /* Populate mbox extension offset word. */
  4437. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4438. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4439. = MAILBOX_HBA_EXT_OFFSET;
  4440. /* Copy the mailbox extension data */
  4441. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4442. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4443. MAILBOX_HBA_EXT_OFFSET,
  4444. pmbox->context2, pmbox->in_ext_byte_len);
  4445. }
  4446. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4447. /* copy command data into host mbox for cmpl */
  4448. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4449. }
  4450. /* First copy mbox command data to HBA SLIM, skip past first
  4451. word */
  4452. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4453. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4454. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4455. /* Next copy over first word, with mbxOwner set */
  4456. ldata = *((uint32_t *)mb);
  4457. to_slim = phba->MBslimaddr;
  4458. writel(ldata, to_slim);
  4459. readl(to_slim); /* flush */
  4460. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4461. /* switch over to host mailbox */
  4462. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4463. }
  4464. }
  4465. wmb();
  4466. switch (flag) {
  4467. case MBX_NOWAIT:
  4468. /* Set up reference to mailbox command */
  4469. psli->mbox_active = pmbox;
  4470. /* Interrupt board to do it */
  4471. writel(CA_MBATT, phba->CAregaddr);
  4472. readl(phba->CAregaddr); /* flush */
  4473. /* Don't wait for it to finish, just return */
  4474. break;
  4475. case MBX_POLL:
  4476. /* Set up null reference to mailbox command */
  4477. psli->mbox_active = NULL;
  4478. /* Interrupt board to do it */
  4479. writel(CA_MBATT, phba->CAregaddr);
  4480. readl(phba->CAregaddr); /* flush */
  4481. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4482. /* First read mbox status word */
  4483. word0 = *((uint32_t *)phba->mbox);
  4484. word0 = le32_to_cpu(word0);
  4485. } else {
  4486. /* First read mbox status word */
  4487. word0 = readl(phba->MBslimaddr);
  4488. }
  4489. /* Read the HBA Host Attention Register */
  4490. ha_copy = readl(phba->HAregaddr);
  4491. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4492. mb->mbxCommand) *
  4493. 1000) + jiffies;
  4494. i = 0;
  4495. /* Wait for command to complete */
  4496. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4497. (!(ha_copy & HA_MBATT) &&
  4498. (phba->link_state > LPFC_WARM_START))) {
  4499. if (time_after(jiffies, timeout)) {
  4500. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4501. spin_unlock_irqrestore(&phba->hbalock,
  4502. drvr_flag);
  4503. goto out_not_finished;
  4504. }
  4505. /* Check if we took a mbox interrupt while we were
  4506. polling */
  4507. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4508. && (evtctr != psli->slistat.mbox_event))
  4509. break;
  4510. if (i++ > 10) {
  4511. spin_unlock_irqrestore(&phba->hbalock,
  4512. drvr_flag);
  4513. msleep(1);
  4514. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4515. }
  4516. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4517. /* First copy command data */
  4518. word0 = *((uint32_t *)phba->mbox);
  4519. word0 = le32_to_cpu(word0);
  4520. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4521. MAILBOX_t *slimmb;
  4522. uint32_t slimword0;
  4523. /* Check real SLIM for any errors */
  4524. slimword0 = readl(phba->MBslimaddr);
  4525. slimmb = (MAILBOX_t *) & slimword0;
  4526. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4527. && slimmb->mbxStatus) {
  4528. psli->sli_flag &=
  4529. ~LPFC_SLI_ACTIVE;
  4530. word0 = slimword0;
  4531. }
  4532. }
  4533. } else {
  4534. /* First copy command data */
  4535. word0 = readl(phba->MBslimaddr);
  4536. }
  4537. /* Read the HBA Host Attention Register */
  4538. ha_copy = readl(phba->HAregaddr);
  4539. }
  4540. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4541. /* copy results back to user */
  4542. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4543. /* Copy the mailbox extension data */
  4544. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4545. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4546. pmbox->context2,
  4547. pmbox->out_ext_byte_len);
  4548. }
  4549. } else {
  4550. /* First copy command data */
  4551. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4552. MAILBOX_CMD_SIZE);
  4553. /* Copy the mailbox extension data */
  4554. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4555. lpfc_memcpy_from_slim(pmbox->context2,
  4556. phba->MBslimaddr +
  4557. MAILBOX_HBA_EXT_OFFSET,
  4558. pmbox->out_ext_byte_len);
  4559. }
  4560. }
  4561. writel(HA_MBATT, phba->HAregaddr);
  4562. readl(phba->HAregaddr); /* flush */
  4563. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4564. status = mb->mbxStatus;
  4565. }
  4566. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4567. return status;
  4568. out_not_finished:
  4569. if (processing_queue) {
  4570. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4571. lpfc_mbox_cmpl_put(phba, pmbox);
  4572. }
  4573. return MBX_NOT_FINISHED;
  4574. }
  4575. /**
  4576. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4577. * @phba: Pointer to HBA context object.
  4578. *
  4579. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4580. * the driver internal pending mailbox queue. It will then try to wait out the
  4581. * possible outstanding mailbox command before return.
  4582. *
  4583. * Returns:
  4584. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4585. * the outstanding mailbox command timed out.
  4586. **/
  4587. static int
  4588. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4589. {
  4590. struct lpfc_sli *psli = &phba->sli;
  4591. uint8_t actcmd = MBX_HEARTBEAT;
  4592. int rc = 0;
  4593. unsigned long timeout;
  4594. /* Mark the asynchronous mailbox command posting as blocked */
  4595. spin_lock_irq(&phba->hbalock);
  4596. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4597. if (phba->sli.mbox_active)
  4598. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4599. spin_unlock_irq(&phba->hbalock);
  4600. /* Determine how long we might wait for the active mailbox
  4601. * command to be gracefully completed by firmware.
  4602. */
  4603. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4604. jiffies;
  4605. /* Wait for the outstnading mailbox command to complete */
  4606. while (phba->sli.mbox_active) {
  4607. /* Check active mailbox complete status every 2ms */
  4608. msleep(2);
  4609. if (time_after(jiffies, timeout)) {
  4610. /* Timeout, marked the outstanding cmd not complete */
  4611. rc = 1;
  4612. break;
  4613. }
  4614. }
  4615. /* Can not cleanly block async mailbox command, fails it */
  4616. if (rc) {
  4617. spin_lock_irq(&phba->hbalock);
  4618. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4619. spin_unlock_irq(&phba->hbalock);
  4620. }
  4621. return rc;
  4622. }
  4623. /**
  4624. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4625. * @phba: Pointer to HBA context object.
  4626. *
  4627. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4628. * commands from the driver internal pending mailbox queue. It makes sure
  4629. * that there is no outstanding mailbox command before resuming posting
  4630. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4631. * mailbox command, it will try to wait it out before resuming asynchronous
  4632. * mailbox command posting.
  4633. **/
  4634. static void
  4635. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4636. {
  4637. struct lpfc_sli *psli = &phba->sli;
  4638. spin_lock_irq(&phba->hbalock);
  4639. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4640. /* Asynchronous mailbox posting is not blocked, do nothing */
  4641. spin_unlock_irq(&phba->hbalock);
  4642. return;
  4643. }
  4644. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4645. * successful or timeout, after timing-out the outstanding mailbox
  4646. * command shall always be removed, so just unblock posting async
  4647. * mailbox command and resume
  4648. */
  4649. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4650. spin_unlock_irq(&phba->hbalock);
  4651. /* wake up worker thread to post asynchronlous mailbox command */
  4652. lpfc_worker_wake_up(phba);
  4653. }
  4654. /**
  4655. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4656. * @phba: Pointer to HBA context object.
  4657. * @mboxq: Pointer to mailbox object.
  4658. *
  4659. * The function posts a mailbox to the port. The mailbox is expected
  4660. * to be comletely filled in and ready for the port to operate on it.
  4661. * This routine executes a synchronous completion operation on the
  4662. * mailbox by polling for its completion.
  4663. *
  4664. * The caller must not be holding any locks when calling this routine.
  4665. *
  4666. * Returns:
  4667. * MBX_SUCCESS - mailbox posted successfully
  4668. * Any of the MBX error values.
  4669. **/
  4670. static int
  4671. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4672. {
  4673. int rc = MBX_SUCCESS;
  4674. unsigned long iflag;
  4675. uint32_t db_ready;
  4676. uint32_t mcqe_status;
  4677. uint32_t mbx_cmnd;
  4678. unsigned long timeout;
  4679. struct lpfc_sli *psli = &phba->sli;
  4680. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4681. struct lpfc_bmbx_create *mbox_rgn;
  4682. struct dma_address *dma_address;
  4683. struct lpfc_register bmbx_reg;
  4684. /*
  4685. * Only one mailbox can be active to the bootstrap mailbox region
  4686. * at a time and there is no queueing provided.
  4687. */
  4688. spin_lock_irqsave(&phba->hbalock, iflag);
  4689. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4690. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4691. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4692. "(%d):2532 Mailbox command x%x (x%x) "
  4693. "cannot issue Data: x%x x%x\n",
  4694. mboxq->vport ? mboxq->vport->vpi : 0,
  4695. mboxq->u.mb.mbxCommand,
  4696. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4697. psli->sli_flag, MBX_POLL);
  4698. return MBXERR_ERROR;
  4699. }
  4700. /* The server grabs the token and owns it until release */
  4701. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4702. phba->sli.mbox_active = mboxq;
  4703. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4704. /*
  4705. * Initialize the bootstrap memory region to avoid stale data areas
  4706. * in the mailbox post. Then copy the caller's mailbox contents to
  4707. * the bmbx mailbox region.
  4708. */
  4709. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4710. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4711. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4712. sizeof(struct lpfc_mqe));
  4713. /* Post the high mailbox dma address to the port and wait for ready. */
  4714. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4715. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4716. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4717. * 1000) + jiffies;
  4718. do {
  4719. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4720. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4721. if (!db_ready)
  4722. msleep(2);
  4723. if (time_after(jiffies, timeout)) {
  4724. rc = MBXERR_ERROR;
  4725. goto exit;
  4726. }
  4727. } while (!db_ready);
  4728. /* Post the low mailbox dma address to the port. */
  4729. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4730. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4731. * 1000) + jiffies;
  4732. do {
  4733. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4734. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4735. if (!db_ready)
  4736. msleep(2);
  4737. if (time_after(jiffies, timeout)) {
  4738. rc = MBXERR_ERROR;
  4739. goto exit;
  4740. }
  4741. } while (!db_ready);
  4742. /*
  4743. * Read the CQ to ensure the mailbox has completed.
  4744. * If so, update the mailbox status so that the upper layers
  4745. * can complete the request normally.
  4746. */
  4747. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4748. sizeof(struct lpfc_mqe));
  4749. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4750. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4751. sizeof(struct lpfc_mcqe));
  4752. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4753. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4754. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4755. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4756. rc = MBXERR_ERROR;
  4757. }
  4758. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4759. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4760. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4761. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4762. mboxq->vport ? mboxq->vport->vpi : 0,
  4763. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4764. bf_get(lpfc_mqe_status, mb),
  4765. mb->un.mb_words[0], mb->un.mb_words[1],
  4766. mb->un.mb_words[2], mb->un.mb_words[3],
  4767. mb->un.mb_words[4], mb->un.mb_words[5],
  4768. mb->un.mb_words[6], mb->un.mb_words[7],
  4769. mb->un.mb_words[8], mb->un.mb_words[9],
  4770. mb->un.mb_words[10], mb->un.mb_words[11],
  4771. mb->un.mb_words[12], mboxq->mcqe.word0,
  4772. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4773. mboxq->mcqe.trailer);
  4774. exit:
  4775. /* We are holding the token, no needed for lock when release */
  4776. spin_lock_irqsave(&phba->hbalock, iflag);
  4777. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4778. phba->sli.mbox_active = NULL;
  4779. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4780. return rc;
  4781. }
  4782. /**
  4783. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4784. * @phba: Pointer to HBA context object.
  4785. * @pmbox: Pointer to mailbox object.
  4786. * @flag: Flag indicating how the mailbox need to be processed.
  4787. *
  4788. * This function is called by discovery code and HBA management code to submit
  4789. * a mailbox command to firmware with SLI-4 interface spec.
  4790. *
  4791. * Return codes the caller owns the mailbox command after the return of the
  4792. * function.
  4793. **/
  4794. static int
  4795. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4796. uint32_t flag)
  4797. {
  4798. struct lpfc_sli *psli = &phba->sli;
  4799. unsigned long iflags;
  4800. int rc;
  4801. rc = lpfc_mbox_dev_check(phba);
  4802. if (unlikely(rc)) {
  4803. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4804. "(%d):2544 Mailbox command x%x (x%x) "
  4805. "cannot issue Data: x%x x%x\n",
  4806. mboxq->vport ? mboxq->vport->vpi : 0,
  4807. mboxq->u.mb.mbxCommand,
  4808. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4809. psli->sli_flag, flag);
  4810. goto out_not_finished;
  4811. }
  4812. /* Detect polling mode and jump to a handler */
  4813. if (!phba->sli4_hba.intr_enable) {
  4814. if (flag == MBX_POLL)
  4815. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4816. else
  4817. rc = -EIO;
  4818. if (rc != MBX_SUCCESS)
  4819. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4820. "(%d):2541 Mailbox command x%x "
  4821. "(x%x) cannot issue Data: x%x x%x\n",
  4822. mboxq->vport ? mboxq->vport->vpi : 0,
  4823. mboxq->u.mb.mbxCommand,
  4824. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4825. psli->sli_flag, flag);
  4826. return rc;
  4827. } else if (flag == MBX_POLL) {
  4828. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4829. "(%d):2542 Try to issue mailbox command "
  4830. "x%x (x%x) synchronously ahead of async"
  4831. "mailbox command queue: x%x x%x\n",
  4832. mboxq->vport ? mboxq->vport->vpi : 0,
  4833. mboxq->u.mb.mbxCommand,
  4834. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4835. psli->sli_flag, flag);
  4836. /* Try to block the asynchronous mailbox posting */
  4837. rc = lpfc_sli4_async_mbox_block(phba);
  4838. if (!rc) {
  4839. /* Successfully blocked, now issue sync mbox cmd */
  4840. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4841. if (rc != MBX_SUCCESS)
  4842. lpfc_printf_log(phba, KERN_ERR,
  4843. LOG_MBOX | LOG_SLI,
  4844. "(%d):2597 Mailbox command "
  4845. "x%x (x%x) cannot issue "
  4846. "Data: x%x x%x\n",
  4847. mboxq->vport ?
  4848. mboxq->vport->vpi : 0,
  4849. mboxq->u.mb.mbxCommand,
  4850. lpfc_sli4_mbox_opcode_get(phba,
  4851. mboxq),
  4852. psli->sli_flag, flag);
  4853. /* Unblock the async mailbox posting afterward */
  4854. lpfc_sli4_async_mbox_unblock(phba);
  4855. }
  4856. return rc;
  4857. }
  4858. /* Now, interrupt mode asynchrous mailbox command */
  4859. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4860. if (rc) {
  4861. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4862. "(%d):2543 Mailbox command x%x (x%x) "
  4863. "cannot issue Data: x%x x%x\n",
  4864. mboxq->vport ? mboxq->vport->vpi : 0,
  4865. mboxq->u.mb.mbxCommand,
  4866. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4867. psli->sli_flag, flag);
  4868. goto out_not_finished;
  4869. }
  4870. /* Put the mailbox command to the driver internal FIFO */
  4871. psli->slistat.mbox_busy++;
  4872. spin_lock_irqsave(&phba->hbalock, iflags);
  4873. lpfc_mbox_put(phba, mboxq);
  4874. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4875. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4876. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4877. "x%x (x%x) x%x x%x x%x\n",
  4878. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4879. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4880. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4881. phba->pport->port_state,
  4882. psli->sli_flag, MBX_NOWAIT);
  4883. /* Wake up worker thread to transport mailbox command from head */
  4884. lpfc_worker_wake_up(phba);
  4885. return MBX_BUSY;
  4886. out_not_finished:
  4887. return MBX_NOT_FINISHED;
  4888. }
  4889. /**
  4890. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4891. * @phba: Pointer to HBA context object.
  4892. *
  4893. * This function is called by worker thread to send a mailbox command to
  4894. * SLI4 HBA firmware.
  4895. *
  4896. **/
  4897. int
  4898. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4899. {
  4900. struct lpfc_sli *psli = &phba->sli;
  4901. LPFC_MBOXQ_t *mboxq;
  4902. int rc = MBX_SUCCESS;
  4903. unsigned long iflags;
  4904. struct lpfc_mqe *mqe;
  4905. uint32_t mbx_cmnd;
  4906. /* Check interrupt mode before post async mailbox command */
  4907. if (unlikely(!phba->sli4_hba.intr_enable))
  4908. return MBX_NOT_FINISHED;
  4909. /* Check for mailbox command service token */
  4910. spin_lock_irqsave(&phba->hbalock, iflags);
  4911. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4912. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4913. return MBX_NOT_FINISHED;
  4914. }
  4915. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4916. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4917. return MBX_NOT_FINISHED;
  4918. }
  4919. if (unlikely(phba->sli.mbox_active)) {
  4920. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4921. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4922. "0384 There is pending active mailbox cmd\n");
  4923. return MBX_NOT_FINISHED;
  4924. }
  4925. /* Take the mailbox command service token */
  4926. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4927. /* Get the next mailbox command from head of queue */
  4928. mboxq = lpfc_mbox_get(phba);
  4929. /* If no more mailbox command waiting for post, we're done */
  4930. if (!mboxq) {
  4931. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4932. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4933. return MBX_SUCCESS;
  4934. }
  4935. phba->sli.mbox_active = mboxq;
  4936. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4937. /* Check device readiness for posting mailbox command */
  4938. rc = lpfc_mbox_dev_check(phba);
  4939. if (unlikely(rc))
  4940. /* Driver clean routine will clean up pending mailbox */
  4941. goto out_not_finished;
  4942. /* Prepare the mbox command to be posted */
  4943. mqe = &mboxq->u.mqe;
  4944. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4945. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4946. mod_timer(&psli->mbox_tmo, (jiffies +
  4947. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4948. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4949. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4950. "x%x x%x\n",
  4951. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4952. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4953. phba->pport->port_state, psli->sli_flag);
  4954. if (mbx_cmnd != MBX_HEARTBEAT) {
  4955. if (mboxq->vport) {
  4956. lpfc_debugfs_disc_trc(mboxq->vport,
  4957. LPFC_DISC_TRC_MBOX_VPORT,
  4958. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4959. mbx_cmnd, mqe->un.mb_words[0],
  4960. mqe->un.mb_words[1]);
  4961. } else {
  4962. lpfc_debugfs_disc_trc(phba->pport,
  4963. LPFC_DISC_TRC_MBOX,
  4964. "MBOX Send: cmd:x%x mb:x%x x%x",
  4965. mbx_cmnd, mqe->un.mb_words[0],
  4966. mqe->un.mb_words[1]);
  4967. }
  4968. }
  4969. psli->slistat.mbox_cmd++;
  4970. /* Post the mailbox command to the port */
  4971. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4972. if (rc != MBX_SUCCESS) {
  4973. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4974. "(%d):2533 Mailbox command x%x (x%x) "
  4975. "cannot issue Data: x%x x%x\n",
  4976. mboxq->vport ? mboxq->vport->vpi : 0,
  4977. mboxq->u.mb.mbxCommand,
  4978. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4979. psli->sli_flag, MBX_NOWAIT);
  4980. goto out_not_finished;
  4981. }
  4982. return rc;
  4983. out_not_finished:
  4984. spin_lock_irqsave(&phba->hbalock, iflags);
  4985. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4986. __lpfc_mbox_cmpl_put(phba, mboxq);
  4987. /* Release the token */
  4988. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4989. phba->sli.mbox_active = NULL;
  4990. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4991. return MBX_NOT_FINISHED;
  4992. }
  4993. /**
  4994. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4995. * @phba: Pointer to HBA context object.
  4996. * @pmbox: Pointer to mailbox object.
  4997. * @flag: Flag indicating how the mailbox need to be processed.
  4998. *
  4999. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5000. * the API jump table function pointer from the lpfc_hba struct.
  5001. *
  5002. * Return codes the caller owns the mailbox command after the return of the
  5003. * function.
  5004. **/
  5005. int
  5006. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5007. {
  5008. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5009. }
  5010. /**
  5011. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5012. * @phba: The hba struct for which this call is being executed.
  5013. * @dev_grp: The HBA PCI-Device group number.
  5014. *
  5015. * This routine sets up the mbox interface API function jump table in @phba
  5016. * struct.
  5017. * Returns: 0 - success, -ENODEV - failure.
  5018. **/
  5019. int
  5020. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5021. {
  5022. switch (dev_grp) {
  5023. case LPFC_PCI_DEV_LP:
  5024. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5025. phba->lpfc_sli_handle_slow_ring_event =
  5026. lpfc_sli_handle_slow_ring_event_s3;
  5027. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5028. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5029. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5030. break;
  5031. case LPFC_PCI_DEV_OC:
  5032. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5033. phba->lpfc_sli_handle_slow_ring_event =
  5034. lpfc_sli_handle_slow_ring_event_s4;
  5035. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5036. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5037. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5038. break;
  5039. default:
  5040. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5041. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5042. dev_grp);
  5043. return -ENODEV;
  5044. break;
  5045. }
  5046. return 0;
  5047. }
  5048. /**
  5049. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5050. * @phba: Pointer to HBA context object.
  5051. * @pring: Pointer to driver SLI ring object.
  5052. * @piocb: Pointer to address of newly added command iocb.
  5053. *
  5054. * This function is called with hbalock held to add a command
  5055. * iocb to the txq when SLI layer cannot submit the command iocb
  5056. * to the ring.
  5057. **/
  5058. static void
  5059. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5060. struct lpfc_iocbq *piocb)
  5061. {
  5062. /* Insert the caller's iocb in the txq tail for later processing. */
  5063. list_add_tail(&piocb->list, &pring->txq);
  5064. pring->txq_cnt++;
  5065. }
  5066. /**
  5067. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5068. * @phba: Pointer to HBA context object.
  5069. * @pring: Pointer to driver SLI ring object.
  5070. * @piocb: Pointer to address of newly added command iocb.
  5071. *
  5072. * This function is called with hbalock held before a new
  5073. * iocb is submitted to the firmware. This function checks
  5074. * txq to flush the iocbs in txq to Firmware before
  5075. * submitting new iocbs to the Firmware.
  5076. * If there are iocbs in the txq which need to be submitted
  5077. * to firmware, lpfc_sli_next_iocb returns the first element
  5078. * of the txq after dequeuing it from txq.
  5079. * If there is no iocb in the txq then the function will return
  5080. * *piocb and *piocb is set to NULL. Caller needs to check
  5081. * *piocb to find if there are more commands in the txq.
  5082. **/
  5083. static struct lpfc_iocbq *
  5084. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5085. struct lpfc_iocbq **piocb)
  5086. {
  5087. struct lpfc_iocbq * nextiocb;
  5088. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5089. if (!nextiocb) {
  5090. nextiocb = *piocb;
  5091. *piocb = NULL;
  5092. }
  5093. return nextiocb;
  5094. }
  5095. /**
  5096. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5097. * @phba: Pointer to HBA context object.
  5098. * @ring_number: SLI ring number to issue iocb on.
  5099. * @piocb: Pointer to command iocb.
  5100. * @flag: Flag indicating if this command can be put into txq.
  5101. *
  5102. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5103. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5104. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5105. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5106. * this function allows only iocbs for posting buffers. This function finds
  5107. * next available slot in the command ring and posts the command to the
  5108. * available slot and writes the port attention register to request HBA start
  5109. * processing new iocb. If there is no slot available in the ring and
  5110. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5111. * the function returns IOCB_BUSY.
  5112. *
  5113. * This function is called with hbalock held. The function will return success
  5114. * after it successfully submit the iocb to firmware or after adding to the
  5115. * txq.
  5116. **/
  5117. static int
  5118. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5119. struct lpfc_iocbq *piocb, uint32_t flag)
  5120. {
  5121. struct lpfc_iocbq *nextiocb;
  5122. IOCB_t *iocb;
  5123. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5124. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5125. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5126. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5127. lpfc_printf_log(phba, KERN_ERR,
  5128. LOG_SLI | LOG_VPORT,
  5129. "1807 IOCB x%x failed. No vport\n",
  5130. piocb->iocb.ulpCommand);
  5131. dump_stack();
  5132. return IOCB_ERROR;
  5133. }
  5134. /* If the PCI channel is in offline state, do not post iocbs. */
  5135. if (unlikely(pci_channel_offline(phba->pcidev)))
  5136. return IOCB_ERROR;
  5137. /* If HBA has a deferred error attention, fail the iocb. */
  5138. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5139. return IOCB_ERROR;
  5140. /*
  5141. * We should never get an IOCB if we are in a < LINK_DOWN state
  5142. */
  5143. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5144. return IOCB_ERROR;
  5145. /*
  5146. * Check to see if we are blocking IOCB processing because of a
  5147. * outstanding event.
  5148. */
  5149. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5150. goto iocb_busy;
  5151. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5152. /*
  5153. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5154. * can be issued if the link is not up.
  5155. */
  5156. switch (piocb->iocb.ulpCommand) {
  5157. case CMD_GEN_REQUEST64_CR:
  5158. case CMD_GEN_REQUEST64_CX:
  5159. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5160. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5161. FC_RCTL_DD_UNSOL_CMD) ||
  5162. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5163. MENLO_TRANSPORT_TYPE))
  5164. goto iocb_busy;
  5165. break;
  5166. case CMD_QUE_RING_BUF_CN:
  5167. case CMD_QUE_RING_BUF64_CN:
  5168. /*
  5169. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5170. * completion, iocb_cmpl MUST be 0.
  5171. */
  5172. if (piocb->iocb_cmpl)
  5173. piocb->iocb_cmpl = NULL;
  5174. /*FALLTHROUGH*/
  5175. case CMD_CREATE_XRI_CR:
  5176. case CMD_CLOSE_XRI_CN:
  5177. case CMD_CLOSE_XRI_CX:
  5178. break;
  5179. default:
  5180. goto iocb_busy;
  5181. }
  5182. /*
  5183. * For FCP commands, we must be in a state where we can process link
  5184. * attention events.
  5185. */
  5186. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5187. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5188. goto iocb_busy;
  5189. }
  5190. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5191. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5192. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5193. if (iocb)
  5194. lpfc_sli_update_ring(phba, pring);
  5195. else
  5196. lpfc_sli_update_full_ring(phba, pring);
  5197. if (!piocb)
  5198. return IOCB_SUCCESS;
  5199. goto out_busy;
  5200. iocb_busy:
  5201. pring->stats.iocb_cmd_delay++;
  5202. out_busy:
  5203. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5204. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5205. return IOCB_SUCCESS;
  5206. }
  5207. return IOCB_BUSY;
  5208. }
  5209. /**
  5210. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5211. * @phba: Pointer to HBA context object.
  5212. * @piocb: Pointer to command iocb.
  5213. * @sglq: Pointer to the scatter gather queue object.
  5214. *
  5215. * This routine converts the bpl or bde that is in the IOCB
  5216. * to a sgl list for the sli4 hardware. The physical address
  5217. * of the bpl/bde is converted back to a virtual address.
  5218. * If the IOCB contains a BPL then the list of BDE's is
  5219. * converted to sli4_sge's. If the IOCB contains a single
  5220. * BDE then it is converted to a single sli_sge.
  5221. * The IOCB is still in cpu endianess so the contents of
  5222. * the bpl can be used without byte swapping.
  5223. *
  5224. * Returns valid XRI = Success, NO_XRI = Failure.
  5225. **/
  5226. static uint16_t
  5227. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5228. struct lpfc_sglq *sglq)
  5229. {
  5230. uint16_t xritag = NO_XRI;
  5231. struct ulp_bde64 *bpl = NULL;
  5232. struct ulp_bde64 bde;
  5233. struct sli4_sge *sgl = NULL;
  5234. IOCB_t *icmd;
  5235. int numBdes = 0;
  5236. int i = 0;
  5237. if (!piocbq || !sglq)
  5238. return xritag;
  5239. sgl = (struct sli4_sge *)sglq->sgl;
  5240. icmd = &piocbq->iocb;
  5241. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5242. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5243. sizeof(struct ulp_bde64);
  5244. /* The addrHigh and addrLow fields within the IOCB
  5245. * have not been byteswapped yet so there is no
  5246. * need to swap them back.
  5247. */
  5248. bpl = (struct ulp_bde64 *)
  5249. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5250. if (!bpl)
  5251. return xritag;
  5252. for (i = 0; i < numBdes; i++) {
  5253. /* Should already be byte swapped. */
  5254. sgl->addr_hi = bpl->addrHigh;
  5255. sgl->addr_lo = bpl->addrLow;
  5256. if ((i+1) == numBdes)
  5257. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5258. else
  5259. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5260. sgl->word2 = cpu_to_le32(sgl->word2);
  5261. /* swap the size field back to the cpu so we
  5262. * can assign it to the sgl.
  5263. */
  5264. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5265. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5266. bpl++;
  5267. sgl++;
  5268. }
  5269. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5270. /* The addrHigh and addrLow fields of the BDE have not
  5271. * been byteswapped yet so they need to be swapped
  5272. * before putting them in the sgl.
  5273. */
  5274. sgl->addr_hi =
  5275. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5276. sgl->addr_lo =
  5277. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5278. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5279. sgl->word2 = cpu_to_le32(sgl->word2);
  5280. sgl->sge_len =
  5281. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5282. }
  5283. return sglq->sli4_xritag;
  5284. }
  5285. /**
  5286. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5287. * @phba: Pointer to HBA context object.
  5288. *
  5289. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5290. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5291. * held.
  5292. *
  5293. * Return: index into SLI4 fast-path FCP queue index.
  5294. **/
  5295. static uint32_t
  5296. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5297. {
  5298. ++phba->fcp_qidx;
  5299. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5300. phba->fcp_qidx = 0;
  5301. return phba->fcp_qidx;
  5302. }
  5303. /**
  5304. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5305. * @phba: Pointer to HBA context object.
  5306. * @piocb: Pointer to command iocb.
  5307. * @wqe: Pointer to the work queue entry.
  5308. *
  5309. * This routine converts the iocb command to its Work Queue Entry
  5310. * equivalent. The wqe pointer should not have any fields set when
  5311. * this routine is called because it will memcpy over them.
  5312. * This routine does not set the CQ_ID or the WQEC bits in the
  5313. * wqe.
  5314. *
  5315. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5316. **/
  5317. static int
  5318. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5319. union lpfc_wqe *wqe)
  5320. {
  5321. uint32_t xmit_len = 0, total_len = 0;
  5322. uint8_t ct = 0;
  5323. uint32_t fip;
  5324. uint32_t abort_tag;
  5325. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5326. uint8_t cmnd;
  5327. uint16_t xritag;
  5328. struct ulp_bde64 *bpl = NULL;
  5329. uint32_t els_id = ELS_ID_DEFAULT;
  5330. int numBdes, i;
  5331. struct ulp_bde64 bde;
  5332. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5333. /* The fcp commands will set command type */
  5334. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5335. command_type = FCP_COMMAND;
  5336. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5337. command_type = ELS_COMMAND_FIP;
  5338. else
  5339. command_type = ELS_COMMAND_NON_FIP;
  5340. /* Some of the fields are in the right position already */
  5341. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5342. abort_tag = (uint32_t) iocbq->iotag;
  5343. xritag = iocbq->sli4_xritag;
  5344. wqe->words[7] = 0; /* The ct field has moved so reset */
  5345. /* words0-2 bpl convert bde */
  5346. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5347. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5348. sizeof(struct ulp_bde64);
  5349. bpl = (struct ulp_bde64 *)
  5350. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5351. if (!bpl)
  5352. return IOCB_ERROR;
  5353. /* Should already be byte swapped. */
  5354. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5355. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5356. /* swap the size field back to the cpu so we
  5357. * can assign it to the sgl.
  5358. */
  5359. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5360. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5361. total_len = 0;
  5362. for (i = 0; i < numBdes; i++) {
  5363. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5364. total_len += bde.tus.f.bdeSize;
  5365. }
  5366. } else
  5367. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5368. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5369. cmnd = iocbq->iocb.ulpCommand;
  5370. switch (iocbq->iocb.ulpCommand) {
  5371. case CMD_ELS_REQUEST64_CR:
  5372. if (!iocbq->iocb.ulpLe) {
  5373. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5374. "2007 Only Limited Edition cmd Format"
  5375. " supported 0x%x\n",
  5376. iocbq->iocb.ulpCommand);
  5377. return IOCB_ERROR;
  5378. }
  5379. wqe->els_req.payload_len = xmit_len;
  5380. /* Els_reguest64 has a TMO */
  5381. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5382. iocbq->iocb.ulpTimeout);
  5383. /* Need a VF for word 4 set the vf bit*/
  5384. bf_set(els_req64_vf, &wqe->els_req, 0);
  5385. /* And a VFID for word 12 */
  5386. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5387. /*
  5388. * Set ct field to 3, indicates that the context_tag field
  5389. * contains the FCFI and remote N_Port_ID is
  5390. * in word 5.
  5391. */
  5392. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5393. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5394. iocbq->iocb.ulpContext);
  5395. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5396. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5397. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5398. if (command_type == ELS_COMMAND_FIP) {
  5399. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5400. >> LPFC_FIP_ELS_ID_SHIFT);
  5401. }
  5402. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5403. break;
  5404. case CMD_XMIT_SEQUENCE64_CX:
  5405. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5406. iocbq->iocb.un.ulpWord[3]);
  5407. wqe->generic.word3 = 0;
  5408. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5409. /* The entire sequence is transmitted for this IOCB */
  5410. xmit_len = total_len;
  5411. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5412. case CMD_XMIT_SEQUENCE64_CR:
  5413. /* word3 iocb=io_tag32 wqe=payload_offset */
  5414. /* payload offset used for multilpe outstanding
  5415. * sequences on the same exchange
  5416. */
  5417. wqe->words[3] = 0;
  5418. /* word4 relative_offset memcpy */
  5419. /* word5 r_ctl/df_ctl memcpy */
  5420. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5421. wqe->xmit_sequence.xmit_len = xmit_len;
  5422. command_type = OTHER_COMMAND;
  5423. break;
  5424. case CMD_XMIT_BCAST64_CN:
  5425. /* word3 iocb=iotag32 wqe=payload_len */
  5426. wqe->words[3] = 0; /* no definition for this in wqe */
  5427. /* word4 iocb=rsvd wqe=rsvd */
  5428. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5429. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5430. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5431. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5432. break;
  5433. case CMD_FCP_IWRITE64_CR:
  5434. command_type = FCP_COMMAND_DATA_OUT;
  5435. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5436. * confusing.
  5437. * word3 is payload_len: byte offset to the sgl entry for the
  5438. * fcp_command.
  5439. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5440. * word5 is initial xfer len 0 = wait for xfer-ready
  5441. */
  5442. /* Always wait for xfer-ready before sending data */
  5443. wqe->fcp_iwrite.initial_xfer_len = 0;
  5444. /* word 4 (xfer length) should have been set on the memcpy */
  5445. /* allow write to fall through to read */
  5446. case CMD_FCP_IREAD64_CR:
  5447. /* FCP_CMD is always the 1st sgl entry */
  5448. wqe->fcp_iread.payload_len =
  5449. xmit_len + sizeof(struct fcp_rsp);
  5450. /* word 4 (xfer length) should have been set on the memcpy */
  5451. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5452. iocbq->iocb.ulpFCP2Rcvy);
  5453. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5454. /* The XC bit and the XS bit are similar. The driver never
  5455. * tracked whether or not the exchange was previouslly open.
  5456. * XC = Exchange create, 0 is create. 1 is already open.
  5457. * XS = link cmd: 1 do not close the exchange after command.
  5458. * XS = 0 close exchange when command completes.
  5459. * The only time we would not set the XC bit is when the XS bit
  5460. * is set and we are sending our 2nd or greater command on
  5461. * this exchange.
  5462. */
  5463. /* Always open the exchange */
  5464. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5465. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5466. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5467. break;
  5468. case CMD_FCP_ICMND64_CR:
  5469. /* Always open the exchange */
  5470. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5471. wqe->words[4] = 0;
  5472. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5473. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5474. break;
  5475. case CMD_GEN_REQUEST64_CR:
  5476. /* word3 command length is described as byte offset to the
  5477. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5478. * sgl[0] = cmnd
  5479. * sgl[1] = rsp.
  5480. *
  5481. */
  5482. wqe->gen_req.command_len = xmit_len;
  5483. /* Word4 parameter copied in the memcpy */
  5484. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5485. /* word6 context tag copied in memcpy */
  5486. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5487. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5488. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5489. "2015 Invalid CT %x command 0x%x\n",
  5490. ct, iocbq->iocb.ulpCommand);
  5491. return IOCB_ERROR;
  5492. }
  5493. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5494. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5495. iocbq->iocb.ulpTimeout);
  5496. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5497. command_type = OTHER_COMMAND;
  5498. break;
  5499. case CMD_XMIT_ELS_RSP64_CX:
  5500. /* words0-2 BDE memcpy */
  5501. /* word3 iocb=iotag32 wqe=rsvd */
  5502. wqe->words[3] = 0;
  5503. /* word4 iocb=did wge=rsvd. */
  5504. wqe->words[4] = 0;
  5505. /* word5 iocb=rsvd wge=did */
  5506. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5507. iocbq->iocb.un.elsreq64.remoteID);
  5508. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5509. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5510. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5511. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5512. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5513. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5514. iocbq->vport->vpi + phba->vpi_base);
  5515. command_type = OTHER_COMMAND;
  5516. break;
  5517. case CMD_CLOSE_XRI_CN:
  5518. case CMD_ABORT_XRI_CN:
  5519. case CMD_ABORT_XRI_CX:
  5520. /* words 0-2 memcpy should be 0 rserved */
  5521. /* port will send abts */
  5522. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5523. /*
  5524. * The link is down so the fw does not need to send abts
  5525. * on the wire.
  5526. */
  5527. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5528. else
  5529. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5530. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5531. wqe->words[5] = 0;
  5532. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5533. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5534. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5535. /*
  5536. * The abort handler will send us CMD_ABORT_XRI_CN or
  5537. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5538. */
  5539. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5540. cmnd = CMD_ABORT_XRI_CX;
  5541. command_type = OTHER_COMMAND;
  5542. xritag = 0;
  5543. break;
  5544. case CMD_XMIT_BLS_RSP64_CX:
  5545. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5546. * we re-construct this WQE here based on information in
  5547. * iocbq from scratch.
  5548. */
  5549. memset(wqe, 0, sizeof(union lpfc_wqe));
  5550. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5551. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5552. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5553. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5554. LPFC_ABTS_UNSOL_INT) {
  5555. /* ABTS sent by initiator to CT exchange, the
  5556. * RX_ID field will be filled with the newly
  5557. * allocated responder XRI.
  5558. */
  5559. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5560. iocbq->sli4_xritag);
  5561. } else {
  5562. /* ABTS sent by responder to CT exchange, the
  5563. * RX_ID field will be filled with the responder
  5564. * RX_ID from ABTS.
  5565. */
  5566. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5567. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5568. }
  5569. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5570. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5571. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5572. iocbq->iocb.ulpContext);
  5573. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5574. command_type = OTHER_COMMAND;
  5575. break;
  5576. case CMD_XRI_ABORTED_CX:
  5577. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5578. /* words0-2 are all 0's no bde */
  5579. /* word3 and word4 are rsvrd */
  5580. wqe->words[3] = 0;
  5581. wqe->words[4] = 0;
  5582. /* word5 iocb=rsvd wge=did */
  5583. /* There is no remote port id in the IOCB? */
  5584. /* Let this fall through and fail */
  5585. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5586. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5587. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5588. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5589. default:
  5590. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5591. "2014 Invalid command 0x%x\n",
  5592. iocbq->iocb.ulpCommand);
  5593. return IOCB_ERROR;
  5594. break;
  5595. }
  5596. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5597. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5598. wqe->generic.abort_tag = abort_tag;
  5599. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5600. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5601. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5602. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5603. return 0;
  5604. }
  5605. /**
  5606. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5607. * @phba: Pointer to HBA context object.
  5608. * @ring_number: SLI ring number to issue iocb on.
  5609. * @piocb: Pointer to command iocb.
  5610. * @flag: Flag indicating if this command can be put into txq.
  5611. *
  5612. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5613. * an iocb command to an HBA with SLI-4 interface spec.
  5614. *
  5615. * This function is called with hbalock held. The function will return success
  5616. * after it successfully submit the iocb to firmware or after adding to the
  5617. * txq.
  5618. **/
  5619. static int
  5620. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5621. struct lpfc_iocbq *piocb, uint32_t flag)
  5622. {
  5623. struct lpfc_sglq *sglq;
  5624. uint16_t xritag;
  5625. union lpfc_wqe wqe;
  5626. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5627. if (piocb->sli4_xritag == NO_XRI) {
  5628. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5629. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5630. sglq = NULL;
  5631. else {
  5632. sglq = __lpfc_sli_get_sglq(phba);
  5633. if (!sglq)
  5634. return IOCB_ERROR;
  5635. piocb->sli4_xritag = sglq->sli4_xritag;
  5636. }
  5637. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5638. sglq = NULL; /* These IO's already have an XRI and
  5639. * a mapped sgl.
  5640. */
  5641. } else {
  5642. /* This is a continuation of a commandi,(CX) so this
  5643. * sglq is on the active list
  5644. */
  5645. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5646. if (!sglq)
  5647. return IOCB_ERROR;
  5648. }
  5649. if (sglq) {
  5650. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5651. if (xritag != sglq->sli4_xritag)
  5652. return IOCB_ERROR;
  5653. }
  5654. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5655. return IOCB_ERROR;
  5656. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5657. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5658. /*
  5659. * For FCP command IOCB, get a new WQ index to distribute
  5660. * WQE across the WQsr. On the other hand, for abort IOCB,
  5661. * it carries the same WQ index to the original command
  5662. * IOCB.
  5663. */
  5664. if (piocb->iocb_flag & LPFC_IO_FCP)
  5665. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5666. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5667. &wqe))
  5668. return IOCB_ERROR;
  5669. } else {
  5670. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5671. return IOCB_ERROR;
  5672. }
  5673. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5674. return 0;
  5675. }
  5676. /**
  5677. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5678. *
  5679. * This routine wraps the actual lockless version for issusing IOCB function
  5680. * pointer from the lpfc_hba struct.
  5681. *
  5682. * Return codes:
  5683. * IOCB_ERROR - Error
  5684. * IOCB_SUCCESS - Success
  5685. * IOCB_BUSY - Busy
  5686. **/
  5687. static inline int
  5688. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5689. struct lpfc_iocbq *piocb, uint32_t flag)
  5690. {
  5691. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5692. }
  5693. /**
  5694. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5695. * @phba: The hba struct for which this call is being executed.
  5696. * @dev_grp: The HBA PCI-Device group number.
  5697. *
  5698. * This routine sets up the SLI interface API function jump table in @phba
  5699. * struct.
  5700. * Returns: 0 - success, -ENODEV - failure.
  5701. **/
  5702. int
  5703. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5704. {
  5705. switch (dev_grp) {
  5706. case LPFC_PCI_DEV_LP:
  5707. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5708. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5709. break;
  5710. case LPFC_PCI_DEV_OC:
  5711. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5712. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5713. break;
  5714. default:
  5715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5716. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5717. dev_grp);
  5718. return -ENODEV;
  5719. break;
  5720. }
  5721. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5722. return 0;
  5723. }
  5724. /**
  5725. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5726. * @phba: Pointer to HBA context object.
  5727. * @pring: Pointer to driver SLI ring object.
  5728. * @piocb: Pointer to command iocb.
  5729. * @flag: Flag indicating if this command can be put into txq.
  5730. *
  5731. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5732. * function. This function gets the hbalock and calls
  5733. * __lpfc_sli_issue_iocb function and will return the error returned
  5734. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5735. * functions which do not hold hbalock.
  5736. **/
  5737. int
  5738. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5739. struct lpfc_iocbq *piocb, uint32_t flag)
  5740. {
  5741. unsigned long iflags;
  5742. int rc;
  5743. spin_lock_irqsave(&phba->hbalock, iflags);
  5744. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5746. return rc;
  5747. }
  5748. /**
  5749. * lpfc_extra_ring_setup - Extra ring setup function
  5750. * @phba: Pointer to HBA context object.
  5751. *
  5752. * This function is called while driver attaches with the
  5753. * HBA to setup the extra ring. The extra ring is used
  5754. * only when driver needs to support target mode functionality
  5755. * or IP over FC functionalities.
  5756. *
  5757. * This function is called with no lock held.
  5758. **/
  5759. static int
  5760. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5761. {
  5762. struct lpfc_sli *psli;
  5763. struct lpfc_sli_ring *pring;
  5764. psli = &phba->sli;
  5765. /* Adjust cmd/rsp ring iocb entries more evenly */
  5766. /* Take some away from the FCP ring */
  5767. pring = &psli->ring[psli->fcp_ring];
  5768. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5769. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5770. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5771. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5772. /* and give them to the extra ring */
  5773. pring = &psli->ring[psli->extra_ring];
  5774. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5775. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5776. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5777. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5778. /* Setup default profile for this ring */
  5779. pring->iotag_max = 4096;
  5780. pring->num_mask = 1;
  5781. pring->prt[0].profile = 0; /* Mask 0 */
  5782. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5783. pring->prt[0].type = phba->cfg_multi_ring_type;
  5784. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5785. return 0;
  5786. }
  5787. /**
  5788. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5789. * @phba: Pointer to HBA context object.
  5790. * @pring: Pointer to driver SLI ring object.
  5791. * @iocbq: Pointer to iocb object.
  5792. *
  5793. * This function is called by the slow ring event handler
  5794. * function when there is an ASYNC event iocb in the ring.
  5795. * This function is called with no lock held.
  5796. * Currently this function handles only temperature related
  5797. * ASYNC events. The function decodes the temperature sensor
  5798. * event message and posts events for the management applications.
  5799. **/
  5800. static void
  5801. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5802. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5803. {
  5804. IOCB_t *icmd;
  5805. uint16_t evt_code;
  5806. uint16_t temp;
  5807. struct temp_event temp_event_data;
  5808. struct Scsi_Host *shost;
  5809. uint32_t *iocb_w;
  5810. icmd = &iocbq->iocb;
  5811. evt_code = icmd->un.asyncstat.evt_code;
  5812. temp = icmd->ulpContext;
  5813. if ((evt_code != ASYNC_TEMP_WARN) &&
  5814. (evt_code != ASYNC_TEMP_SAFE)) {
  5815. iocb_w = (uint32_t *) icmd;
  5816. lpfc_printf_log(phba,
  5817. KERN_ERR,
  5818. LOG_SLI,
  5819. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5820. " evt_code 0x%x\n"
  5821. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5822. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5823. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5824. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5825. pring->ringno,
  5826. icmd->un.asyncstat.evt_code,
  5827. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5828. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5829. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5830. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5831. return;
  5832. }
  5833. temp_event_data.data = (uint32_t)temp;
  5834. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5835. if (evt_code == ASYNC_TEMP_WARN) {
  5836. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5837. lpfc_printf_log(phba,
  5838. KERN_ERR,
  5839. LOG_TEMP,
  5840. "0347 Adapter is very hot, please take "
  5841. "corrective action. temperature : %d Celsius\n",
  5842. temp);
  5843. }
  5844. if (evt_code == ASYNC_TEMP_SAFE) {
  5845. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5846. lpfc_printf_log(phba,
  5847. KERN_ERR,
  5848. LOG_TEMP,
  5849. "0340 Adapter temperature is OK now. "
  5850. "temperature : %d Celsius\n",
  5851. temp);
  5852. }
  5853. /* Send temperature change event to applications */
  5854. shost = lpfc_shost_from_vport(phba->pport);
  5855. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5856. sizeof(temp_event_data), (char *) &temp_event_data,
  5857. LPFC_NL_VENDOR_ID);
  5858. }
  5859. /**
  5860. * lpfc_sli_setup - SLI ring setup function
  5861. * @phba: Pointer to HBA context object.
  5862. *
  5863. * lpfc_sli_setup sets up rings of the SLI interface with
  5864. * number of iocbs per ring and iotags. This function is
  5865. * called while driver attach to the HBA and before the
  5866. * interrupts are enabled. So there is no need for locking.
  5867. *
  5868. * This function always returns 0.
  5869. **/
  5870. int
  5871. lpfc_sli_setup(struct lpfc_hba *phba)
  5872. {
  5873. int i, totiocbsize = 0;
  5874. struct lpfc_sli *psli = &phba->sli;
  5875. struct lpfc_sli_ring *pring;
  5876. psli->num_rings = MAX_CONFIGURED_RINGS;
  5877. psli->sli_flag = 0;
  5878. psli->fcp_ring = LPFC_FCP_RING;
  5879. psli->next_ring = LPFC_FCP_NEXT_RING;
  5880. psli->extra_ring = LPFC_EXTRA_RING;
  5881. psli->iocbq_lookup = NULL;
  5882. psli->iocbq_lookup_len = 0;
  5883. psli->last_iotag = 0;
  5884. for (i = 0; i < psli->num_rings; i++) {
  5885. pring = &psli->ring[i];
  5886. switch (i) {
  5887. case LPFC_FCP_RING: /* ring 0 - FCP */
  5888. /* numCiocb and numRiocb are used in config_port */
  5889. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5890. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5891. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5892. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5893. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5894. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5895. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5896. SLI3_IOCB_CMD_SIZE :
  5897. SLI2_IOCB_CMD_SIZE;
  5898. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5899. SLI3_IOCB_RSP_SIZE :
  5900. SLI2_IOCB_RSP_SIZE;
  5901. pring->iotag_ctr = 0;
  5902. pring->iotag_max =
  5903. (phba->cfg_hba_queue_depth * 2);
  5904. pring->fast_iotag = pring->iotag_max;
  5905. pring->num_mask = 0;
  5906. break;
  5907. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5908. /* numCiocb and numRiocb are used in config_port */
  5909. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5910. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5911. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5912. SLI3_IOCB_CMD_SIZE :
  5913. SLI2_IOCB_CMD_SIZE;
  5914. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5915. SLI3_IOCB_RSP_SIZE :
  5916. SLI2_IOCB_RSP_SIZE;
  5917. pring->iotag_max = phba->cfg_hba_queue_depth;
  5918. pring->num_mask = 0;
  5919. break;
  5920. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5921. /* numCiocb and numRiocb are used in config_port */
  5922. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5923. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5924. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5925. SLI3_IOCB_CMD_SIZE :
  5926. SLI2_IOCB_CMD_SIZE;
  5927. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5928. SLI3_IOCB_RSP_SIZE :
  5929. SLI2_IOCB_RSP_SIZE;
  5930. pring->fast_iotag = 0;
  5931. pring->iotag_ctr = 0;
  5932. pring->iotag_max = 4096;
  5933. pring->lpfc_sli_rcv_async_status =
  5934. lpfc_sli_async_event_handler;
  5935. pring->num_mask = LPFC_MAX_RING_MASK;
  5936. pring->prt[0].profile = 0; /* Mask 0 */
  5937. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5938. pring->prt[0].type = FC_TYPE_ELS;
  5939. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5940. lpfc_els_unsol_event;
  5941. pring->prt[1].profile = 0; /* Mask 1 */
  5942. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5943. pring->prt[1].type = FC_TYPE_ELS;
  5944. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5945. lpfc_els_unsol_event;
  5946. pring->prt[2].profile = 0; /* Mask 2 */
  5947. /* NameServer Inquiry */
  5948. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5949. /* NameServer */
  5950. pring->prt[2].type = FC_TYPE_CT;
  5951. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5952. lpfc_ct_unsol_event;
  5953. pring->prt[3].profile = 0; /* Mask 3 */
  5954. /* NameServer response */
  5955. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5956. /* NameServer */
  5957. pring->prt[3].type = FC_TYPE_CT;
  5958. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5959. lpfc_ct_unsol_event;
  5960. /* abort unsolicited sequence */
  5961. pring->prt[4].profile = 0; /* Mask 4 */
  5962. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5963. pring->prt[4].type = FC_TYPE_BLS;
  5964. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5965. lpfc_sli4_ct_abort_unsol_event;
  5966. break;
  5967. }
  5968. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5969. (pring->numRiocb * pring->sizeRiocb);
  5970. }
  5971. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5972. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5973. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5974. "SLI2 SLIM Data: x%x x%lx\n",
  5975. phba->brd_no, totiocbsize,
  5976. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5977. }
  5978. if (phba->cfg_multi_ring_support == 2)
  5979. lpfc_extra_ring_setup(phba);
  5980. return 0;
  5981. }
  5982. /**
  5983. * lpfc_sli_queue_setup - Queue initialization function
  5984. * @phba: Pointer to HBA context object.
  5985. *
  5986. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5987. * ring. This function also initializes ring indices of each ring.
  5988. * This function is called during the initialization of the SLI
  5989. * interface of an HBA.
  5990. * This function is called with no lock held and always returns
  5991. * 1.
  5992. **/
  5993. int
  5994. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5995. {
  5996. struct lpfc_sli *psli;
  5997. struct lpfc_sli_ring *pring;
  5998. int i;
  5999. psli = &phba->sli;
  6000. spin_lock_irq(&phba->hbalock);
  6001. INIT_LIST_HEAD(&psli->mboxq);
  6002. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6003. /* Initialize list headers for txq and txcmplq as double linked lists */
  6004. for (i = 0; i < psli->num_rings; i++) {
  6005. pring = &psli->ring[i];
  6006. pring->ringno = i;
  6007. pring->next_cmdidx = 0;
  6008. pring->local_getidx = 0;
  6009. pring->cmdidx = 0;
  6010. INIT_LIST_HEAD(&pring->txq);
  6011. INIT_LIST_HEAD(&pring->txcmplq);
  6012. INIT_LIST_HEAD(&pring->iocb_continueq);
  6013. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6014. INIT_LIST_HEAD(&pring->postbufq);
  6015. }
  6016. spin_unlock_irq(&phba->hbalock);
  6017. return 1;
  6018. }
  6019. /**
  6020. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6021. * @phba: Pointer to HBA context object.
  6022. *
  6023. * This routine flushes the mailbox command subsystem. It will unconditionally
  6024. * flush all the mailbox commands in the three possible stages in the mailbox
  6025. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6026. * command; and completed mailbox command queue. It is caller's responsibility
  6027. * to make sure that the driver is in the proper state to flush the mailbox
  6028. * command sub-system. Namely, the posting of mailbox commands into the
  6029. * pending mailbox command queue from the various clients must be stopped;
  6030. * either the HBA is in a state that it will never works on the outstanding
  6031. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6032. * mailbox command has been completed.
  6033. **/
  6034. static void
  6035. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6036. {
  6037. LIST_HEAD(completions);
  6038. struct lpfc_sli *psli = &phba->sli;
  6039. LPFC_MBOXQ_t *pmb;
  6040. unsigned long iflag;
  6041. /* Flush all the mailbox commands in the mbox system */
  6042. spin_lock_irqsave(&phba->hbalock, iflag);
  6043. /* The pending mailbox command queue */
  6044. list_splice_init(&phba->sli.mboxq, &completions);
  6045. /* The outstanding active mailbox command */
  6046. if (psli->mbox_active) {
  6047. list_add_tail(&psli->mbox_active->list, &completions);
  6048. psli->mbox_active = NULL;
  6049. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6050. }
  6051. /* The completed mailbox command queue */
  6052. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6053. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6054. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6055. while (!list_empty(&completions)) {
  6056. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6057. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6058. if (pmb->mbox_cmpl)
  6059. pmb->mbox_cmpl(phba, pmb);
  6060. }
  6061. }
  6062. /**
  6063. * lpfc_sli_host_down - Vport cleanup function
  6064. * @vport: Pointer to virtual port object.
  6065. *
  6066. * lpfc_sli_host_down is called to clean up the resources
  6067. * associated with a vport before destroying virtual
  6068. * port data structures.
  6069. * This function does following operations:
  6070. * - Free discovery resources associated with this virtual
  6071. * port.
  6072. * - Free iocbs associated with this virtual port in
  6073. * the txq.
  6074. * - Send abort for all iocb commands associated with this
  6075. * vport in txcmplq.
  6076. *
  6077. * This function is called with no lock held and always returns 1.
  6078. **/
  6079. int
  6080. lpfc_sli_host_down(struct lpfc_vport *vport)
  6081. {
  6082. LIST_HEAD(completions);
  6083. struct lpfc_hba *phba = vport->phba;
  6084. struct lpfc_sli *psli = &phba->sli;
  6085. struct lpfc_sli_ring *pring;
  6086. struct lpfc_iocbq *iocb, *next_iocb;
  6087. int i;
  6088. unsigned long flags = 0;
  6089. uint16_t prev_pring_flag;
  6090. lpfc_cleanup_discovery_resources(vport);
  6091. spin_lock_irqsave(&phba->hbalock, flags);
  6092. for (i = 0; i < psli->num_rings; i++) {
  6093. pring = &psli->ring[i];
  6094. prev_pring_flag = pring->flag;
  6095. /* Only slow rings */
  6096. if (pring->ringno == LPFC_ELS_RING) {
  6097. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6098. /* Set the lpfc data pending flag */
  6099. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6100. }
  6101. /*
  6102. * Error everything on the txq since these iocbs have not been
  6103. * given to the FW yet.
  6104. */
  6105. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6106. if (iocb->vport != vport)
  6107. continue;
  6108. list_move_tail(&iocb->list, &completions);
  6109. pring->txq_cnt--;
  6110. }
  6111. /* Next issue ABTS for everything on the txcmplq */
  6112. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6113. list) {
  6114. if (iocb->vport != vport)
  6115. continue;
  6116. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6117. }
  6118. pring->flag = prev_pring_flag;
  6119. }
  6120. spin_unlock_irqrestore(&phba->hbalock, flags);
  6121. /* Cancel all the IOCBs from the completions list */
  6122. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6123. IOERR_SLI_DOWN);
  6124. return 1;
  6125. }
  6126. /**
  6127. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6128. * @phba: Pointer to HBA context object.
  6129. *
  6130. * This function cleans up all iocb, buffers, mailbox commands
  6131. * while shutting down the HBA. This function is called with no
  6132. * lock held and always returns 1.
  6133. * This function does the following to cleanup driver resources:
  6134. * - Free discovery resources for each virtual port
  6135. * - Cleanup any pending fabric iocbs
  6136. * - Iterate through the iocb txq and free each entry
  6137. * in the list.
  6138. * - Free up any buffer posted to the HBA
  6139. * - Free mailbox commands in the mailbox queue.
  6140. **/
  6141. int
  6142. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6143. {
  6144. LIST_HEAD(completions);
  6145. struct lpfc_sli *psli = &phba->sli;
  6146. struct lpfc_sli_ring *pring;
  6147. struct lpfc_dmabuf *buf_ptr;
  6148. unsigned long flags = 0;
  6149. int i;
  6150. /* Shutdown the mailbox command sub-system */
  6151. lpfc_sli_mbox_sys_shutdown(phba);
  6152. lpfc_hba_down_prep(phba);
  6153. lpfc_fabric_abort_hba(phba);
  6154. spin_lock_irqsave(&phba->hbalock, flags);
  6155. for (i = 0; i < psli->num_rings; i++) {
  6156. pring = &psli->ring[i];
  6157. /* Only slow rings */
  6158. if (pring->ringno == LPFC_ELS_RING) {
  6159. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6160. /* Set the lpfc data pending flag */
  6161. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6162. }
  6163. /*
  6164. * Error everything on the txq since these iocbs have not been
  6165. * given to the FW yet.
  6166. */
  6167. list_splice_init(&pring->txq, &completions);
  6168. pring->txq_cnt = 0;
  6169. }
  6170. spin_unlock_irqrestore(&phba->hbalock, flags);
  6171. /* Cancel all the IOCBs from the completions list */
  6172. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6173. IOERR_SLI_DOWN);
  6174. spin_lock_irqsave(&phba->hbalock, flags);
  6175. list_splice_init(&phba->elsbuf, &completions);
  6176. phba->elsbuf_cnt = 0;
  6177. phba->elsbuf_prev_cnt = 0;
  6178. spin_unlock_irqrestore(&phba->hbalock, flags);
  6179. while (!list_empty(&completions)) {
  6180. list_remove_head(&completions, buf_ptr,
  6181. struct lpfc_dmabuf, list);
  6182. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6183. kfree(buf_ptr);
  6184. }
  6185. /* Return any active mbox cmds */
  6186. del_timer_sync(&psli->mbox_tmo);
  6187. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6188. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6189. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6190. return 1;
  6191. }
  6192. /**
  6193. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6194. * @phba: Pointer to HBA context object.
  6195. *
  6196. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6197. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6198. * lock held and always returns 1.
  6199. *
  6200. * This function does the following to cleanup driver FCoE function resources:
  6201. * - Free discovery resources for each virtual port
  6202. * - Cleanup any pending fabric iocbs
  6203. * - Iterate through the iocb txq and free each entry in the list.
  6204. * - Free up any buffer posted to the HBA.
  6205. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6206. * - Free mailbox commands in the mailbox queue.
  6207. **/
  6208. int
  6209. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6210. {
  6211. /* Stop the SLI4 device port */
  6212. lpfc_stop_port(phba);
  6213. /* Tear down the queues in the HBA */
  6214. lpfc_sli4_queue_unset(phba);
  6215. /* unregister default FCFI from the HBA */
  6216. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6217. return 1;
  6218. }
  6219. /**
  6220. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6221. * @srcp: Source memory pointer.
  6222. * @destp: Destination memory pointer.
  6223. * @cnt: Number of words required to be copied.
  6224. *
  6225. * This function is used for copying data between driver memory
  6226. * and the SLI memory. This function also changes the endianness
  6227. * of each word if native endianness is different from SLI
  6228. * endianness. This function can be called with or without
  6229. * lock.
  6230. **/
  6231. void
  6232. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6233. {
  6234. uint32_t *src = srcp;
  6235. uint32_t *dest = destp;
  6236. uint32_t ldata;
  6237. int i;
  6238. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6239. ldata = *src;
  6240. ldata = le32_to_cpu(ldata);
  6241. *dest = ldata;
  6242. src++;
  6243. dest++;
  6244. }
  6245. }
  6246. /**
  6247. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6248. * @srcp: Source memory pointer.
  6249. * @destp: Destination memory pointer.
  6250. * @cnt: Number of words required to be copied.
  6251. *
  6252. * This function is used for copying data between a data structure
  6253. * with big endian representation to local endianness.
  6254. * This function can be called with or without lock.
  6255. **/
  6256. void
  6257. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6258. {
  6259. uint32_t *src = srcp;
  6260. uint32_t *dest = destp;
  6261. uint32_t ldata;
  6262. int i;
  6263. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6264. ldata = *src;
  6265. ldata = be32_to_cpu(ldata);
  6266. *dest = ldata;
  6267. src++;
  6268. dest++;
  6269. }
  6270. }
  6271. /**
  6272. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6273. * @phba: Pointer to HBA context object.
  6274. * @pring: Pointer to driver SLI ring object.
  6275. * @mp: Pointer to driver buffer object.
  6276. *
  6277. * This function is called with no lock held.
  6278. * It always return zero after adding the buffer to the postbufq
  6279. * buffer list.
  6280. **/
  6281. int
  6282. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6283. struct lpfc_dmabuf *mp)
  6284. {
  6285. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6286. later */
  6287. spin_lock_irq(&phba->hbalock);
  6288. list_add_tail(&mp->list, &pring->postbufq);
  6289. pring->postbufq_cnt++;
  6290. spin_unlock_irq(&phba->hbalock);
  6291. return 0;
  6292. }
  6293. /**
  6294. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6295. * @phba: Pointer to HBA context object.
  6296. *
  6297. * When HBQ is enabled, buffers are searched based on tags. This function
  6298. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6299. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6300. * does not conflict with tags of buffer posted for unsolicited events.
  6301. * The function returns the allocated tag. The function is called with
  6302. * no locks held.
  6303. **/
  6304. uint32_t
  6305. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6306. {
  6307. spin_lock_irq(&phba->hbalock);
  6308. phba->buffer_tag_count++;
  6309. /*
  6310. * Always set the QUE_BUFTAG_BIT to distiguish between
  6311. * a tag assigned by HBQ.
  6312. */
  6313. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6314. spin_unlock_irq(&phba->hbalock);
  6315. return phba->buffer_tag_count;
  6316. }
  6317. /**
  6318. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6319. * @phba: Pointer to HBA context object.
  6320. * @pring: Pointer to driver SLI ring object.
  6321. * @tag: Buffer tag.
  6322. *
  6323. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6324. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6325. * iocb is posted to the response ring with the tag of the buffer.
  6326. * This function searches the pring->postbufq list using the tag
  6327. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6328. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6329. * buffer is returned to the caller else NULL is returned.
  6330. * This function is called with no lock held.
  6331. **/
  6332. struct lpfc_dmabuf *
  6333. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6334. uint32_t tag)
  6335. {
  6336. struct lpfc_dmabuf *mp, *next_mp;
  6337. struct list_head *slp = &pring->postbufq;
  6338. /* Search postbufq, from the begining, looking for a match on tag */
  6339. spin_lock_irq(&phba->hbalock);
  6340. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6341. if (mp->buffer_tag == tag) {
  6342. list_del_init(&mp->list);
  6343. pring->postbufq_cnt--;
  6344. spin_unlock_irq(&phba->hbalock);
  6345. return mp;
  6346. }
  6347. }
  6348. spin_unlock_irq(&phba->hbalock);
  6349. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6350. "0402 Cannot find virtual addr for buffer tag on "
  6351. "ring %d Data x%lx x%p x%p x%x\n",
  6352. pring->ringno, (unsigned long) tag,
  6353. slp->next, slp->prev, pring->postbufq_cnt);
  6354. return NULL;
  6355. }
  6356. /**
  6357. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6358. * @phba: Pointer to HBA context object.
  6359. * @pring: Pointer to driver SLI ring object.
  6360. * @phys: DMA address of the buffer.
  6361. *
  6362. * This function searches the buffer list using the dma_address
  6363. * of unsolicited event to find the driver's lpfc_dmabuf object
  6364. * corresponding to the dma_address. The function returns the
  6365. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6366. * This function is called by the ct and els unsolicited event
  6367. * handlers to get the buffer associated with the unsolicited
  6368. * event.
  6369. *
  6370. * This function is called with no lock held.
  6371. **/
  6372. struct lpfc_dmabuf *
  6373. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6374. dma_addr_t phys)
  6375. {
  6376. struct lpfc_dmabuf *mp, *next_mp;
  6377. struct list_head *slp = &pring->postbufq;
  6378. /* Search postbufq, from the begining, looking for a match on phys */
  6379. spin_lock_irq(&phba->hbalock);
  6380. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6381. if (mp->phys == phys) {
  6382. list_del_init(&mp->list);
  6383. pring->postbufq_cnt--;
  6384. spin_unlock_irq(&phba->hbalock);
  6385. return mp;
  6386. }
  6387. }
  6388. spin_unlock_irq(&phba->hbalock);
  6389. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6390. "0410 Cannot find virtual addr for mapped buf on "
  6391. "ring %d Data x%llx x%p x%p x%x\n",
  6392. pring->ringno, (unsigned long long)phys,
  6393. slp->next, slp->prev, pring->postbufq_cnt);
  6394. return NULL;
  6395. }
  6396. /**
  6397. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6398. * @phba: Pointer to HBA context object.
  6399. * @cmdiocb: Pointer to driver command iocb object.
  6400. * @rspiocb: Pointer to driver response iocb object.
  6401. *
  6402. * This function is the completion handler for the abort iocbs for
  6403. * ELS commands. This function is called from the ELS ring event
  6404. * handler with no lock held. This function frees memory resources
  6405. * associated with the abort iocb.
  6406. **/
  6407. static void
  6408. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6409. struct lpfc_iocbq *rspiocb)
  6410. {
  6411. IOCB_t *irsp = &rspiocb->iocb;
  6412. uint16_t abort_iotag, abort_context;
  6413. struct lpfc_iocbq *abort_iocb;
  6414. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6415. abort_iocb = NULL;
  6416. if (irsp->ulpStatus) {
  6417. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6418. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6419. spin_lock_irq(&phba->hbalock);
  6420. if (phba->sli_rev < LPFC_SLI_REV4) {
  6421. if (abort_iotag != 0 &&
  6422. abort_iotag <= phba->sli.last_iotag)
  6423. abort_iocb =
  6424. phba->sli.iocbq_lookup[abort_iotag];
  6425. } else
  6426. /* For sli4 the abort_tag is the XRI,
  6427. * so the abort routine puts the iotag of the iocb
  6428. * being aborted in the context field of the abort
  6429. * IOCB.
  6430. */
  6431. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6432. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6433. "0327 Cannot abort els iocb %p "
  6434. "with tag %x context %x, abort status %x, "
  6435. "abort code %x\n",
  6436. abort_iocb, abort_iotag, abort_context,
  6437. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6438. /*
  6439. * If the iocb is not found in Firmware queue the iocb
  6440. * might have completed already. Do not free it again.
  6441. */
  6442. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6443. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6444. spin_unlock_irq(&phba->hbalock);
  6445. lpfc_sli_release_iocbq(phba, cmdiocb);
  6446. return;
  6447. }
  6448. /* For SLI4 the ulpContext field for abort IOCB
  6449. * holds the iotag of the IOCB being aborted so
  6450. * the local abort_context needs to be reset to
  6451. * match the aborted IOCBs ulpContext.
  6452. */
  6453. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6454. abort_context = abort_iocb->iocb.ulpContext;
  6455. }
  6456. /*
  6457. * make sure we have the right iocbq before taking it
  6458. * off the txcmplq and try to call completion routine.
  6459. */
  6460. if (!abort_iocb ||
  6461. abort_iocb->iocb.ulpContext != abort_context ||
  6462. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6463. spin_unlock_irq(&phba->hbalock);
  6464. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6465. /*
  6466. * leave the SLI4 aborted command on the txcmplq
  6467. * list and the command complete WCQE's XB bit
  6468. * will tell whether the SGL (XRI) can be released
  6469. * immediately or to the aborted SGL list for the
  6470. * following abort XRI from the HBA.
  6471. */
  6472. list_del_init(&abort_iocb->list);
  6473. pring->txcmplq_cnt--;
  6474. /* Firmware could still be in progress of DMAing
  6475. * payload, so don't free data buffer till after
  6476. * a hbeat.
  6477. */
  6478. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6479. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6480. spin_unlock_irq(&phba->hbalock);
  6481. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6482. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6483. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6484. } else
  6485. spin_unlock_irq(&phba->hbalock);
  6486. }
  6487. lpfc_sli_release_iocbq(phba, cmdiocb);
  6488. return;
  6489. }
  6490. /**
  6491. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6492. * @phba: Pointer to HBA context object.
  6493. * @cmdiocb: Pointer to driver command iocb object.
  6494. * @rspiocb: Pointer to driver response iocb object.
  6495. *
  6496. * The function is called from SLI ring event handler with no
  6497. * lock held. This function is the completion handler for ELS commands
  6498. * which are aborted. The function frees memory resources used for
  6499. * the aborted ELS commands.
  6500. **/
  6501. static void
  6502. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6503. struct lpfc_iocbq *rspiocb)
  6504. {
  6505. IOCB_t *irsp = &rspiocb->iocb;
  6506. /* ELS cmd tag <ulpIoTag> completes */
  6507. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6508. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6509. "x%x x%x x%x\n",
  6510. irsp->ulpIoTag, irsp->ulpStatus,
  6511. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6512. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6513. lpfc_ct_free_iocb(phba, cmdiocb);
  6514. else
  6515. lpfc_els_free_iocb(phba, cmdiocb);
  6516. return;
  6517. }
  6518. /**
  6519. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6520. * @phba: Pointer to HBA context object.
  6521. * @pring: Pointer to driver SLI ring object.
  6522. * @cmdiocb: Pointer to driver command iocb object.
  6523. *
  6524. * This function issues an abort iocb for the provided command
  6525. * iocb. This function is called with hbalock held.
  6526. * The function returns 0 when it fails due to memory allocation
  6527. * failure or when the command iocb is an abort request.
  6528. **/
  6529. int
  6530. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6531. struct lpfc_iocbq *cmdiocb)
  6532. {
  6533. struct lpfc_vport *vport = cmdiocb->vport;
  6534. struct lpfc_iocbq *abtsiocbp;
  6535. IOCB_t *icmd = NULL;
  6536. IOCB_t *iabt = NULL;
  6537. int retval = IOCB_ERROR;
  6538. /*
  6539. * There are certain command types we don't want to abort. And we
  6540. * don't want to abort commands that are already in the process of
  6541. * being aborted.
  6542. */
  6543. icmd = &cmdiocb->iocb;
  6544. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6545. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6546. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6547. return 0;
  6548. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6549. * callback so that nothing happens when it finishes.
  6550. */
  6551. if ((vport->load_flag & FC_UNLOADING) &&
  6552. (pring->ringno == LPFC_ELS_RING)) {
  6553. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6554. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6555. else
  6556. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6557. goto abort_iotag_exit;
  6558. }
  6559. /* issue ABTS for this IOCB based on iotag */
  6560. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6561. if (abtsiocbp == NULL)
  6562. return 0;
  6563. /* This signals the response to set the correct status
  6564. * before calling the completion handler
  6565. */
  6566. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6567. iabt = &abtsiocbp->iocb;
  6568. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6569. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6570. if (phba->sli_rev == LPFC_SLI_REV4) {
  6571. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6572. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6573. }
  6574. else
  6575. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6576. iabt->ulpLe = 1;
  6577. iabt->ulpClass = icmd->ulpClass;
  6578. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6579. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6580. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6581. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6582. if (phba->link_state >= LPFC_LINK_UP)
  6583. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6584. else
  6585. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6586. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6587. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6588. "0339 Abort xri x%x, original iotag x%x, "
  6589. "abort cmd iotag x%x\n",
  6590. iabt->un.acxri.abortContextTag,
  6591. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6592. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6593. if (retval)
  6594. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6595. abort_iotag_exit:
  6596. /*
  6597. * Caller to this routine should check for IOCB_ERROR
  6598. * and handle it properly. This routine no longer removes
  6599. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6600. */
  6601. return retval;
  6602. }
  6603. /**
  6604. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6605. * @iocbq: Pointer to driver iocb object.
  6606. * @vport: Pointer to driver virtual port object.
  6607. * @tgt_id: SCSI ID of the target.
  6608. * @lun_id: LUN ID of the scsi device.
  6609. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6610. *
  6611. * This function acts as an iocb filter for functions which abort or count
  6612. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6613. * 0 if the filtering criteria is met for the given iocb and will return
  6614. * 1 if the filtering criteria is not met.
  6615. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6616. * given iocb is for the SCSI device specified by vport, tgt_id and
  6617. * lun_id parameter.
  6618. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6619. * given iocb is for the SCSI target specified by vport and tgt_id
  6620. * parameters.
  6621. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6622. * given iocb is for the SCSI host associated with the given vport.
  6623. * This function is called with no locks held.
  6624. **/
  6625. static int
  6626. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6627. uint16_t tgt_id, uint64_t lun_id,
  6628. lpfc_ctx_cmd ctx_cmd)
  6629. {
  6630. struct lpfc_scsi_buf *lpfc_cmd;
  6631. int rc = 1;
  6632. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6633. return rc;
  6634. if (iocbq->vport != vport)
  6635. return rc;
  6636. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6637. if (lpfc_cmd->pCmd == NULL)
  6638. return rc;
  6639. switch (ctx_cmd) {
  6640. case LPFC_CTX_LUN:
  6641. if ((lpfc_cmd->rdata->pnode) &&
  6642. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6643. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6644. rc = 0;
  6645. break;
  6646. case LPFC_CTX_TGT:
  6647. if ((lpfc_cmd->rdata->pnode) &&
  6648. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6649. rc = 0;
  6650. break;
  6651. case LPFC_CTX_HOST:
  6652. rc = 0;
  6653. break;
  6654. default:
  6655. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6656. __func__, ctx_cmd);
  6657. break;
  6658. }
  6659. return rc;
  6660. }
  6661. /**
  6662. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6663. * @vport: Pointer to virtual port.
  6664. * @tgt_id: SCSI ID of the target.
  6665. * @lun_id: LUN ID of the scsi device.
  6666. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6667. *
  6668. * This function returns number of FCP commands pending for the vport.
  6669. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6670. * commands pending on the vport associated with SCSI device specified
  6671. * by tgt_id and lun_id parameters.
  6672. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6673. * commands pending on the vport associated with SCSI target specified
  6674. * by tgt_id parameter.
  6675. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6676. * commands pending on the vport.
  6677. * This function returns the number of iocbs which satisfy the filter.
  6678. * This function is called without any lock held.
  6679. **/
  6680. int
  6681. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6682. lpfc_ctx_cmd ctx_cmd)
  6683. {
  6684. struct lpfc_hba *phba = vport->phba;
  6685. struct lpfc_iocbq *iocbq;
  6686. int sum, i;
  6687. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6688. iocbq = phba->sli.iocbq_lookup[i];
  6689. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6690. ctx_cmd) == 0)
  6691. sum++;
  6692. }
  6693. return sum;
  6694. }
  6695. /**
  6696. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6697. * @phba: Pointer to HBA context object
  6698. * @cmdiocb: Pointer to command iocb object.
  6699. * @rspiocb: Pointer to response iocb object.
  6700. *
  6701. * This function is called when an aborted FCP iocb completes. This
  6702. * function is called by the ring event handler with no lock held.
  6703. * This function frees the iocb.
  6704. **/
  6705. void
  6706. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6707. struct lpfc_iocbq *rspiocb)
  6708. {
  6709. lpfc_sli_release_iocbq(phba, cmdiocb);
  6710. return;
  6711. }
  6712. /**
  6713. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6714. * @vport: Pointer to virtual port.
  6715. * @pring: Pointer to driver SLI ring object.
  6716. * @tgt_id: SCSI ID of the target.
  6717. * @lun_id: LUN ID of the scsi device.
  6718. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6719. *
  6720. * This function sends an abort command for every SCSI command
  6721. * associated with the given virtual port pending on the ring
  6722. * filtered by lpfc_sli_validate_fcp_iocb function.
  6723. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6724. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6725. * parameters
  6726. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6727. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6728. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6729. * FCP iocbs associated with virtual port.
  6730. * This function returns number of iocbs it failed to abort.
  6731. * This function is called with no locks held.
  6732. **/
  6733. int
  6734. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6735. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6736. {
  6737. struct lpfc_hba *phba = vport->phba;
  6738. struct lpfc_iocbq *iocbq;
  6739. struct lpfc_iocbq *abtsiocb;
  6740. IOCB_t *cmd = NULL;
  6741. int errcnt = 0, ret_val = 0;
  6742. int i;
  6743. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6744. iocbq = phba->sli.iocbq_lookup[i];
  6745. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6746. abort_cmd) != 0)
  6747. continue;
  6748. /* issue ABTS for this IOCB based on iotag */
  6749. abtsiocb = lpfc_sli_get_iocbq(phba);
  6750. if (abtsiocb == NULL) {
  6751. errcnt++;
  6752. continue;
  6753. }
  6754. cmd = &iocbq->iocb;
  6755. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6756. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6757. if (phba->sli_rev == LPFC_SLI_REV4)
  6758. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6759. else
  6760. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6761. abtsiocb->iocb.ulpLe = 1;
  6762. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6763. abtsiocb->vport = phba->pport;
  6764. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6765. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6766. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6767. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6768. if (lpfc_is_link_up(phba))
  6769. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6770. else
  6771. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6772. /* Setup callback routine and issue the command. */
  6773. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6774. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6775. abtsiocb, 0);
  6776. if (ret_val == IOCB_ERROR) {
  6777. lpfc_sli_release_iocbq(phba, abtsiocb);
  6778. errcnt++;
  6779. continue;
  6780. }
  6781. }
  6782. return errcnt;
  6783. }
  6784. /**
  6785. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6786. * @phba: Pointer to HBA context object.
  6787. * @cmdiocbq: Pointer to command iocb.
  6788. * @rspiocbq: Pointer to response iocb.
  6789. *
  6790. * This function is the completion handler for iocbs issued using
  6791. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6792. * ring event handler function without any lock held. This function
  6793. * can be called from both worker thread context and interrupt
  6794. * context. This function also can be called from other thread which
  6795. * cleans up the SLI layer objects.
  6796. * This function copy the contents of the response iocb to the
  6797. * response iocb memory object provided by the caller of
  6798. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6799. * sleeps for the iocb completion.
  6800. **/
  6801. static void
  6802. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6803. struct lpfc_iocbq *cmdiocbq,
  6804. struct lpfc_iocbq *rspiocbq)
  6805. {
  6806. wait_queue_head_t *pdone_q;
  6807. unsigned long iflags;
  6808. struct lpfc_scsi_buf *lpfc_cmd;
  6809. spin_lock_irqsave(&phba->hbalock, iflags);
  6810. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6811. if (cmdiocbq->context2 && rspiocbq)
  6812. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6813. &rspiocbq->iocb, sizeof(IOCB_t));
  6814. /* Set the exchange busy flag for task management commands */
  6815. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6816. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6817. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6818. cur_iocbq);
  6819. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6820. }
  6821. pdone_q = cmdiocbq->context_un.wait_queue;
  6822. if (pdone_q)
  6823. wake_up(pdone_q);
  6824. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6825. return;
  6826. }
  6827. /**
  6828. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6829. * @phba: Pointer to HBA context object..
  6830. * @piocbq: Pointer to command iocb.
  6831. * @flag: Flag to test.
  6832. *
  6833. * This routine grabs the hbalock and then test the iocb_flag to
  6834. * see if the passed in flag is set.
  6835. * Returns:
  6836. * 1 if flag is set.
  6837. * 0 if flag is not set.
  6838. **/
  6839. static int
  6840. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6841. struct lpfc_iocbq *piocbq, uint32_t flag)
  6842. {
  6843. unsigned long iflags;
  6844. int ret;
  6845. spin_lock_irqsave(&phba->hbalock, iflags);
  6846. ret = piocbq->iocb_flag & flag;
  6847. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6848. return ret;
  6849. }
  6850. /**
  6851. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6852. * @phba: Pointer to HBA context object..
  6853. * @pring: Pointer to sli ring.
  6854. * @piocb: Pointer to command iocb.
  6855. * @prspiocbq: Pointer to response iocb.
  6856. * @timeout: Timeout in number of seconds.
  6857. *
  6858. * This function issues the iocb to firmware and waits for the
  6859. * iocb to complete. If the iocb command is not
  6860. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6861. * Caller should not free the iocb resources if this function
  6862. * returns IOCB_TIMEDOUT.
  6863. * The function waits for the iocb completion using an
  6864. * non-interruptible wait.
  6865. * This function will sleep while waiting for iocb completion.
  6866. * So, this function should not be called from any context which
  6867. * does not allow sleeping. Due to the same reason, this function
  6868. * cannot be called with interrupt disabled.
  6869. * This function assumes that the iocb completions occur while
  6870. * this function sleep. So, this function cannot be called from
  6871. * the thread which process iocb completion for this ring.
  6872. * This function clears the iocb_flag of the iocb object before
  6873. * issuing the iocb and the iocb completion handler sets this
  6874. * flag and wakes this thread when the iocb completes.
  6875. * The contents of the response iocb will be copied to prspiocbq
  6876. * by the completion handler when the command completes.
  6877. * This function returns IOCB_SUCCESS when success.
  6878. * This function is called with no lock held.
  6879. **/
  6880. int
  6881. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6882. uint32_t ring_number,
  6883. struct lpfc_iocbq *piocb,
  6884. struct lpfc_iocbq *prspiocbq,
  6885. uint32_t timeout)
  6886. {
  6887. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6888. long timeleft, timeout_req = 0;
  6889. int retval = IOCB_SUCCESS;
  6890. uint32_t creg_val;
  6891. /*
  6892. * If the caller has provided a response iocbq buffer, then context2
  6893. * is NULL or its an error.
  6894. */
  6895. if (prspiocbq) {
  6896. if (piocb->context2)
  6897. return IOCB_ERROR;
  6898. piocb->context2 = prspiocbq;
  6899. }
  6900. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6901. piocb->context_un.wait_queue = &done_q;
  6902. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6903. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6904. creg_val = readl(phba->HCregaddr);
  6905. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6906. writel(creg_val, phba->HCregaddr);
  6907. readl(phba->HCregaddr); /* flush */
  6908. }
  6909. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6910. if (retval == IOCB_SUCCESS) {
  6911. timeout_req = timeout * HZ;
  6912. timeleft = wait_event_timeout(done_q,
  6913. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6914. timeout_req);
  6915. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6916. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6917. "0331 IOCB wake signaled\n");
  6918. } else if (timeleft == 0) {
  6919. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6920. "0338 IOCB wait timeout error - no "
  6921. "wake response Data x%x\n", timeout);
  6922. retval = IOCB_TIMEDOUT;
  6923. } else {
  6924. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6925. "0330 IOCB wake NOT set, "
  6926. "Data x%x x%lx\n",
  6927. timeout, (timeleft / jiffies));
  6928. retval = IOCB_TIMEDOUT;
  6929. }
  6930. } else {
  6931. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6932. "0332 IOCB wait issue failed, Data x%x\n",
  6933. retval);
  6934. retval = IOCB_ERROR;
  6935. }
  6936. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6937. creg_val = readl(phba->HCregaddr);
  6938. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6939. writel(creg_val, phba->HCregaddr);
  6940. readl(phba->HCregaddr); /* flush */
  6941. }
  6942. if (prspiocbq)
  6943. piocb->context2 = NULL;
  6944. piocb->context_un.wait_queue = NULL;
  6945. piocb->iocb_cmpl = NULL;
  6946. return retval;
  6947. }
  6948. /**
  6949. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6950. * @phba: Pointer to HBA context object.
  6951. * @pmboxq: Pointer to driver mailbox object.
  6952. * @timeout: Timeout in number of seconds.
  6953. *
  6954. * This function issues the mailbox to firmware and waits for the
  6955. * mailbox command to complete. If the mailbox command is not
  6956. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6957. * The function waits for the mailbox completion using an
  6958. * interruptible wait. If the thread is woken up due to a
  6959. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6960. * should not free the mailbox resources, if this function returns
  6961. * MBX_TIMEOUT.
  6962. * This function will sleep while waiting for mailbox completion.
  6963. * So, this function should not be called from any context which
  6964. * does not allow sleeping. Due to the same reason, this function
  6965. * cannot be called with interrupt disabled.
  6966. * This function assumes that the mailbox completion occurs while
  6967. * this function sleep. So, this function cannot be called from
  6968. * the worker thread which processes mailbox completion.
  6969. * This function is called in the context of HBA management
  6970. * applications.
  6971. * This function returns MBX_SUCCESS when successful.
  6972. * This function is called with no lock held.
  6973. **/
  6974. int
  6975. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6976. uint32_t timeout)
  6977. {
  6978. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6979. int retval;
  6980. unsigned long flag;
  6981. /* The caller must leave context1 empty. */
  6982. if (pmboxq->context1)
  6983. return MBX_NOT_FINISHED;
  6984. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6985. /* setup wake call as IOCB callback */
  6986. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6987. /* setup context field to pass wait_queue pointer to wake function */
  6988. pmboxq->context1 = &done_q;
  6989. /* now issue the command */
  6990. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6991. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6992. wait_event_interruptible_timeout(done_q,
  6993. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6994. timeout * HZ);
  6995. spin_lock_irqsave(&phba->hbalock, flag);
  6996. pmboxq->context1 = NULL;
  6997. /*
  6998. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6999. * else do not free the resources.
  7000. */
  7001. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  7002. retval = MBX_SUCCESS;
  7003. else {
  7004. retval = MBX_TIMEOUT;
  7005. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7006. }
  7007. spin_unlock_irqrestore(&phba->hbalock, flag);
  7008. }
  7009. return retval;
  7010. }
  7011. /**
  7012. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7013. * @phba: Pointer to HBA context.
  7014. *
  7015. * This function is called to shutdown the driver's mailbox sub-system.
  7016. * It first marks the mailbox sub-system is in a block state to prevent
  7017. * the asynchronous mailbox command from issued off the pending mailbox
  7018. * command queue. If the mailbox command sub-system shutdown is due to
  7019. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7020. * the mailbox sub-system flush routine to forcefully bring down the
  7021. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7022. * as with offline or HBA function reset), this routine will wait for the
  7023. * outstanding mailbox command to complete before invoking the mailbox
  7024. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7025. **/
  7026. void
  7027. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7028. {
  7029. struct lpfc_sli *psli = &phba->sli;
  7030. uint8_t actcmd = MBX_HEARTBEAT;
  7031. unsigned long timeout;
  7032. spin_lock_irq(&phba->hbalock);
  7033. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7034. spin_unlock_irq(&phba->hbalock);
  7035. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7036. spin_lock_irq(&phba->hbalock);
  7037. if (phba->sli.mbox_active)
  7038. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7039. spin_unlock_irq(&phba->hbalock);
  7040. /* Determine how long we might wait for the active mailbox
  7041. * command to be gracefully completed by firmware.
  7042. */
  7043. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7044. 1000) + jiffies;
  7045. while (phba->sli.mbox_active) {
  7046. /* Check active mailbox complete status every 2ms */
  7047. msleep(2);
  7048. if (time_after(jiffies, timeout))
  7049. /* Timeout, let the mailbox flush routine to
  7050. * forcefully release active mailbox command
  7051. */
  7052. break;
  7053. }
  7054. }
  7055. lpfc_sli_mbox_sys_flush(phba);
  7056. }
  7057. /**
  7058. * lpfc_sli_eratt_read - read sli-3 error attention events
  7059. * @phba: Pointer to HBA context.
  7060. *
  7061. * This function is called to read the SLI3 device error attention registers
  7062. * for possible error attention events. The caller must hold the hostlock
  7063. * with spin_lock_irq().
  7064. *
  7065. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7066. * Register and returns 0 otherwise.
  7067. **/
  7068. static int
  7069. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7070. {
  7071. uint32_t ha_copy;
  7072. /* Read chip Host Attention (HA) register */
  7073. ha_copy = readl(phba->HAregaddr);
  7074. if (ha_copy & HA_ERATT) {
  7075. /* Read host status register to retrieve error event */
  7076. lpfc_sli_read_hs(phba);
  7077. /* Check if there is a deferred error condition is active */
  7078. if ((HS_FFER1 & phba->work_hs) &&
  7079. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7080. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7081. phba->hba_flag |= DEFER_ERATT;
  7082. /* Clear all interrupt enable conditions */
  7083. writel(0, phba->HCregaddr);
  7084. readl(phba->HCregaddr);
  7085. }
  7086. /* Set the driver HA work bitmap */
  7087. phba->work_ha |= HA_ERATT;
  7088. /* Indicate polling handles this ERATT */
  7089. phba->hba_flag |= HBA_ERATT_HANDLED;
  7090. return 1;
  7091. }
  7092. return 0;
  7093. }
  7094. /**
  7095. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7096. * @phba: Pointer to HBA context.
  7097. *
  7098. * This function is called to read the SLI4 device error attention registers
  7099. * for possible error attention events. The caller must hold the hostlock
  7100. * with spin_lock_irq().
  7101. *
  7102. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7103. * Register and returns 0 otherwise.
  7104. **/
  7105. static int
  7106. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7107. {
  7108. uint32_t uerr_sta_hi, uerr_sta_lo;
  7109. /* For now, use the SLI4 device internal unrecoverable error
  7110. * registers for error attention. This can be changed later.
  7111. */
  7112. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7113. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7114. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7115. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7117. "1423 HBA Unrecoverable error: "
  7118. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7119. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7120. uerr_sta_lo, uerr_sta_hi,
  7121. phba->sli4_hba.ue_mask_lo,
  7122. phba->sli4_hba.ue_mask_hi);
  7123. phba->work_status[0] = uerr_sta_lo;
  7124. phba->work_status[1] = uerr_sta_hi;
  7125. /* Set the driver HA work bitmap */
  7126. phba->work_ha |= HA_ERATT;
  7127. /* Indicate polling handles this ERATT */
  7128. phba->hba_flag |= HBA_ERATT_HANDLED;
  7129. return 1;
  7130. }
  7131. return 0;
  7132. }
  7133. /**
  7134. * lpfc_sli_check_eratt - check error attention events
  7135. * @phba: Pointer to HBA context.
  7136. *
  7137. * This function is called from timer soft interrupt context to check HBA's
  7138. * error attention register bit for error attention events.
  7139. *
  7140. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7141. * Register and returns 0 otherwise.
  7142. **/
  7143. int
  7144. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7145. {
  7146. uint32_t ha_copy;
  7147. /* If somebody is waiting to handle an eratt, don't process it
  7148. * here. The brdkill function will do this.
  7149. */
  7150. if (phba->link_flag & LS_IGNORE_ERATT)
  7151. return 0;
  7152. /* Check if interrupt handler handles this ERATT */
  7153. spin_lock_irq(&phba->hbalock);
  7154. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7155. /* Interrupt handler has handled ERATT */
  7156. spin_unlock_irq(&phba->hbalock);
  7157. return 0;
  7158. }
  7159. /*
  7160. * If there is deferred error attention, do not check for error
  7161. * attention
  7162. */
  7163. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7164. spin_unlock_irq(&phba->hbalock);
  7165. return 0;
  7166. }
  7167. /* If PCI channel is offline, don't process it */
  7168. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7169. spin_unlock_irq(&phba->hbalock);
  7170. return 0;
  7171. }
  7172. switch (phba->sli_rev) {
  7173. case LPFC_SLI_REV2:
  7174. case LPFC_SLI_REV3:
  7175. /* Read chip Host Attention (HA) register */
  7176. ha_copy = lpfc_sli_eratt_read(phba);
  7177. break;
  7178. case LPFC_SLI_REV4:
  7179. /* Read devcie Uncoverable Error (UERR) registers */
  7180. ha_copy = lpfc_sli4_eratt_read(phba);
  7181. break;
  7182. default:
  7183. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7184. "0299 Invalid SLI revision (%d)\n",
  7185. phba->sli_rev);
  7186. ha_copy = 0;
  7187. break;
  7188. }
  7189. spin_unlock_irq(&phba->hbalock);
  7190. return ha_copy;
  7191. }
  7192. /**
  7193. * lpfc_intr_state_check - Check device state for interrupt handling
  7194. * @phba: Pointer to HBA context.
  7195. *
  7196. * This inline routine checks whether a device or its PCI slot is in a state
  7197. * that the interrupt should be handled.
  7198. *
  7199. * This function returns 0 if the device or the PCI slot is in a state that
  7200. * interrupt should be handled, otherwise -EIO.
  7201. */
  7202. static inline int
  7203. lpfc_intr_state_check(struct lpfc_hba *phba)
  7204. {
  7205. /* If the pci channel is offline, ignore all the interrupts */
  7206. if (unlikely(pci_channel_offline(phba->pcidev)))
  7207. return -EIO;
  7208. /* Update device level interrupt statistics */
  7209. phba->sli.slistat.sli_intr++;
  7210. /* Ignore all interrupts during initialization. */
  7211. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7212. return -EIO;
  7213. return 0;
  7214. }
  7215. /**
  7216. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7217. * @irq: Interrupt number.
  7218. * @dev_id: The device context pointer.
  7219. *
  7220. * This function is directly called from the PCI layer as an interrupt
  7221. * service routine when device with SLI-3 interface spec is enabled with
  7222. * MSI-X multi-message interrupt mode and there are slow-path events in
  7223. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7224. * interrupt mode, this function is called as part of the device-level
  7225. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7226. * is undergoing initialization, the interrupt handler will not process
  7227. * the interrupt. The link attention and ELS ring attention events are
  7228. * handled by the worker thread. The interrupt handler signals the worker
  7229. * thread and returns for these events. This function is called without
  7230. * any lock held. It gets the hbalock to access and update SLI data
  7231. * structures.
  7232. *
  7233. * This function returns IRQ_HANDLED when interrupt is handled else it
  7234. * returns IRQ_NONE.
  7235. **/
  7236. irqreturn_t
  7237. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7238. {
  7239. struct lpfc_hba *phba;
  7240. uint32_t ha_copy, hc_copy;
  7241. uint32_t work_ha_copy;
  7242. unsigned long status;
  7243. unsigned long iflag;
  7244. uint32_t control;
  7245. MAILBOX_t *mbox, *pmbox;
  7246. struct lpfc_vport *vport;
  7247. struct lpfc_nodelist *ndlp;
  7248. struct lpfc_dmabuf *mp;
  7249. LPFC_MBOXQ_t *pmb;
  7250. int rc;
  7251. /*
  7252. * Get the driver's phba structure from the dev_id and
  7253. * assume the HBA is not interrupting.
  7254. */
  7255. phba = (struct lpfc_hba *)dev_id;
  7256. if (unlikely(!phba))
  7257. return IRQ_NONE;
  7258. /*
  7259. * Stuff needs to be attented to when this function is invoked as an
  7260. * individual interrupt handler in MSI-X multi-message interrupt mode
  7261. */
  7262. if (phba->intr_type == MSIX) {
  7263. /* Check device state for handling interrupt */
  7264. if (lpfc_intr_state_check(phba))
  7265. return IRQ_NONE;
  7266. /* Need to read HA REG for slow-path events */
  7267. spin_lock_irqsave(&phba->hbalock, iflag);
  7268. ha_copy = readl(phba->HAregaddr);
  7269. /* If somebody is waiting to handle an eratt don't process it
  7270. * here. The brdkill function will do this.
  7271. */
  7272. if (phba->link_flag & LS_IGNORE_ERATT)
  7273. ha_copy &= ~HA_ERATT;
  7274. /* Check the need for handling ERATT in interrupt handler */
  7275. if (ha_copy & HA_ERATT) {
  7276. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7277. /* ERATT polling has handled ERATT */
  7278. ha_copy &= ~HA_ERATT;
  7279. else
  7280. /* Indicate interrupt handler handles ERATT */
  7281. phba->hba_flag |= HBA_ERATT_HANDLED;
  7282. }
  7283. /*
  7284. * If there is deferred error attention, do not check for any
  7285. * interrupt.
  7286. */
  7287. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7288. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7289. return IRQ_NONE;
  7290. }
  7291. /* Clear up only attention source related to slow-path */
  7292. hc_copy = readl(phba->HCregaddr);
  7293. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7294. HC_LAINT_ENA | HC_ERINT_ENA),
  7295. phba->HCregaddr);
  7296. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7297. phba->HAregaddr);
  7298. writel(hc_copy, phba->HCregaddr);
  7299. readl(phba->HAregaddr); /* flush */
  7300. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7301. } else
  7302. ha_copy = phba->ha_copy;
  7303. work_ha_copy = ha_copy & phba->work_ha_mask;
  7304. if (work_ha_copy) {
  7305. if (work_ha_copy & HA_LATT) {
  7306. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7307. /*
  7308. * Turn off Link Attention interrupts
  7309. * until CLEAR_LA done
  7310. */
  7311. spin_lock_irqsave(&phba->hbalock, iflag);
  7312. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7313. control = readl(phba->HCregaddr);
  7314. control &= ~HC_LAINT_ENA;
  7315. writel(control, phba->HCregaddr);
  7316. readl(phba->HCregaddr); /* flush */
  7317. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7318. }
  7319. else
  7320. work_ha_copy &= ~HA_LATT;
  7321. }
  7322. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7323. /*
  7324. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7325. * the only slow ring.
  7326. */
  7327. status = (work_ha_copy &
  7328. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7329. status >>= (4*LPFC_ELS_RING);
  7330. if (status & HA_RXMASK) {
  7331. spin_lock_irqsave(&phba->hbalock, iflag);
  7332. control = readl(phba->HCregaddr);
  7333. lpfc_debugfs_slow_ring_trc(phba,
  7334. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7335. control, status,
  7336. (uint32_t)phba->sli.slistat.sli_intr);
  7337. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7338. lpfc_debugfs_slow_ring_trc(phba,
  7339. "ISR Disable ring:"
  7340. "pwork:x%x hawork:x%x wait:x%x",
  7341. phba->work_ha, work_ha_copy,
  7342. (uint32_t)((unsigned long)
  7343. &phba->work_waitq));
  7344. control &=
  7345. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7346. writel(control, phba->HCregaddr);
  7347. readl(phba->HCregaddr); /* flush */
  7348. }
  7349. else {
  7350. lpfc_debugfs_slow_ring_trc(phba,
  7351. "ISR slow ring: pwork:"
  7352. "x%x hawork:x%x wait:x%x",
  7353. phba->work_ha, work_ha_copy,
  7354. (uint32_t)((unsigned long)
  7355. &phba->work_waitq));
  7356. }
  7357. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7358. }
  7359. }
  7360. spin_lock_irqsave(&phba->hbalock, iflag);
  7361. if (work_ha_copy & HA_ERATT) {
  7362. lpfc_sli_read_hs(phba);
  7363. /*
  7364. * Check if there is a deferred error condition
  7365. * is active
  7366. */
  7367. if ((HS_FFER1 & phba->work_hs) &&
  7368. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7369. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7370. phba->hba_flag |= DEFER_ERATT;
  7371. /* Clear all interrupt enable conditions */
  7372. writel(0, phba->HCregaddr);
  7373. readl(phba->HCregaddr);
  7374. }
  7375. }
  7376. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7377. pmb = phba->sli.mbox_active;
  7378. pmbox = &pmb->u.mb;
  7379. mbox = phba->mbox;
  7380. vport = pmb->vport;
  7381. /* First check out the status word */
  7382. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7383. if (pmbox->mbxOwner != OWN_HOST) {
  7384. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7385. /*
  7386. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7387. * mbxStatus <status>
  7388. */
  7389. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7390. LOG_SLI,
  7391. "(%d):0304 Stray Mailbox "
  7392. "Interrupt mbxCommand x%x "
  7393. "mbxStatus x%x\n",
  7394. (vport ? vport->vpi : 0),
  7395. pmbox->mbxCommand,
  7396. pmbox->mbxStatus);
  7397. /* clear mailbox attention bit */
  7398. work_ha_copy &= ~HA_MBATT;
  7399. } else {
  7400. phba->sli.mbox_active = NULL;
  7401. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7402. phba->last_completion_time = jiffies;
  7403. del_timer(&phba->sli.mbox_tmo);
  7404. if (pmb->mbox_cmpl) {
  7405. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7406. MAILBOX_CMD_SIZE);
  7407. if (pmb->out_ext_byte_len &&
  7408. pmb->context2)
  7409. lpfc_sli_pcimem_bcopy(
  7410. phba->mbox_ext,
  7411. pmb->context2,
  7412. pmb->out_ext_byte_len);
  7413. }
  7414. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7415. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7416. lpfc_debugfs_disc_trc(vport,
  7417. LPFC_DISC_TRC_MBOX_VPORT,
  7418. "MBOX dflt rpi: : "
  7419. "status:x%x rpi:x%x",
  7420. (uint32_t)pmbox->mbxStatus,
  7421. pmbox->un.varWords[0], 0);
  7422. if (!pmbox->mbxStatus) {
  7423. mp = (struct lpfc_dmabuf *)
  7424. (pmb->context1);
  7425. ndlp = (struct lpfc_nodelist *)
  7426. pmb->context2;
  7427. /* Reg_LOGIN of dflt RPI was
  7428. * successful. new lets get
  7429. * rid of the RPI using the
  7430. * same mbox buffer.
  7431. */
  7432. lpfc_unreg_login(phba,
  7433. vport->vpi,
  7434. pmbox->un.varWords[0],
  7435. pmb);
  7436. pmb->mbox_cmpl =
  7437. lpfc_mbx_cmpl_dflt_rpi;
  7438. pmb->context1 = mp;
  7439. pmb->context2 = ndlp;
  7440. pmb->vport = vport;
  7441. rc = lpfc_sli_issue_mbox(phba,
  7442. pmb,
  7443. MBX_NOWAIT);
  7444. if (rc != MBX_BUSY)
  7445. lpfc_printf_log(phba,
  7446. KERN_ERR,
  7447. LOG_MBOX | LOG_SLI,
  7448. "0350 rc should have"
  7449. "been MBX_BUSY\n");
  7450. if (rc != MBX_NOT_FINISHED)
  7451. goto send_current_mbox;
  7452. }
  7453. }
  7454. spin_lock_irqsave(
  7455. &phba->pport->work_port_lock,
  7456. iflag);
  7457. phba->pport->work_port_events &=
  7458. ~WORKER_MBOX_TMO;
  7459. spin_unlock_irqrestore(
  7460. &phba->pport->work_port_lock,
  7461. iflag);
  7462. lpfc_mbox_cmpl_put(phba, pmb);
  7463. }
  7464. } else
  7465. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7466. if ((work_ha_copy & HA_MBATT) &&
  7467. (phba->sli.mbox_active == NULL)) {
  7468. send_current_mbox:
  7469. /* Process next mailbox command if there is one */
  7470. do {
  7471. rc = lpfc_sli_issue_mbox(phba, NULL,
  7472. MBX_NOWAIT);
  7473. } while (rc == MBX_NOT_FINISHED);
  7474. if (rc != MBX_SUCCESS)
  7475. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7476. LOG_SLI, "0349 rc should be "
  7477. "MBX_SUCCESS\n");
  7478. }
  7479. spin_lock_irqsave(&phba->hbalock, iflag);
  7480. phba->work_ha |= work_ha_copy;
  7481. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7482. lpfc_worker_wake_up(phba);
  7483. }
  7484. return IRQ_HANDLED;
  7485. } /* lpfc_sli_sp_intr_handler */
  7486. /**
  7487. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7488. * @irq: Interrupt number.
  7489. * @dev_id: The device context pointer.
  7490. *
  7491. * This function is directly called from the PCI layer as an interrupt
  7492. * service routine when device with SLI-3 interface spec is enabled with
  7493. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7494. * ring event in the HBA. However, when the device is enabled with either
  7495. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7496. * device-level interrupt handler. When the PCI slot is in error recovery
  7497. * or the HBA is undergoing initialization, the interrupt handler will not
  7498. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7499. * the intrrupt context. This function is called without any lock held.
  7500. * It gets the hbalock to access and update SLI data structures.
  7501. *
  7502. * This function returns IRQ_HANDLED when interrupt is handled else it
  7503. * returns IRQ_NONE.
  7504. **/
  7505. irqreturn_t
  7506. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7507. {
  7508. struct lpfc_hba *phba;
  7509. uint32_t ha_copy;
  7510. unsigned long status;
  7511. unsigned long iflag;
  7512. /* Get the driver's phba structure from the dev_id and
  7513. * assume the HBA is not interrupting.
  7514. */
  7515. phba = (struct lpfc_hba *) dev_id;
  7516. if (unlikely(!phba))
  7517. return IRQ_NONE;
  7518. /*
  7519. * Stuff needs to be attented to when this function is invoked as an
  7520. * individual interrupt handler in MSI-X multi-message interrupt mode
  7521. */
  7522. if (phba->intr_type == MSIX) {
  7523. /* Check device state for handling interrupt */
  7524. if (lpfc_intr_state_check(phba))
  7525. return IRQ_NONE;
  7526. /* Need to read HA REG for FCP ring and other ring events */
  7527. ha_copy = readl(phba->HAregaddr);
  7528. /* Clear up only attention source related to fast-path */
  7529. spin_lock_irqsave(&phba->hbalock, iflag);
  7530. /*
  7531. * If there is deferred error attention, do not check for
  7532. * any interrupt.
  7533. */
  7534. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7535. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7536. return IRQ_NONE;
  7537. }
  7538. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7539. phba->HAregaddr);
  7540. readl(phba->HAregaddr); /* flush */
  7541. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7542. } else
  7543. ha_copy = phba->ha_copy;
  7544. /*
  7545. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7546. */
  7547. ha_copy &= ~(phba->work_ha_mask);
  7548. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7549. status >>= (4*LPFC_FCP_RING);
  7550. if (status & HA_RXMASK)
  7551. lpfc_sli_handle_fast_ring_event(phba,
  7552. &phba->sli.ring[LPFC_FCP_RING],
  7553. status);
  7554. if (phba->cfg_multi_ring_support == 2) {
  7555. /*
  7556. * Process all events on extra ring. Take the optimized path
  7557. * for extra ring IO.
  7558. */
  7559. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7560. status >>= (4*LPFC_EXTRA_RING);
  7561. if (status & HA_RXMASK) {
  7562. lpfc_sli_handle_fast_ring_event(phba,
  7563. &phba->sli.ring[LPFC_EXTRA_RING],
  7564. status);
  7565. }
  7566. }
  7567. return IRQ_HANDLED;
  7568. } /* lpfc_sli_fp_intr_handler */
  7569. /**
  7570. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7571. * @irq: Interrupt number.
  7572. * @dev_id: The device context pointer.
  7573. *
  7574. * This function is the HBA device-level interrupt handler to device with
  7575. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7576. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7577. * requires driver attention. This function invokes the slow-path interrupt
  7578. * attention handling function and fast-path interrupt attention handling
  7579. * function in turn to process the relevant HBA attention events. This
  7580. * function is called without any lock held. It gets the hbalock to access
  7581. * and update SLI data structures.
  7582. *
  7583. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7584. * returns IRQ_NONE.
  7585. **/
  7586. irqreturn_t
  7587. lpfc_sli_intr_handler(int irq, void *dev_id)
  7588. {
  7589. struct lpfc_hba *phba;
  7590. irqreturn_t sp_irq_rc, fp_irq_rc;
  7591. unsigned long status1, status2;
  7592. uint32_t hc_copy;
  7593. /*
  7594. * Get the driver's phba structure from the dev_id and
  7595. * assume the HBA is not interrupting.
  7596. */
  7597. phba = (struct lpfc_hba *) dev_id;
  7598. if (unlikely(!phba))
  7599. return IRQ_NONE;
  7600. /* Check device state for handling interrupt */
  7601. if (lpfc_intr_state_check(phba))
  7602. return IRQ_NONE;
  7603. spin_lock(&phba->hbalock);
  7604. phba->ha_copy = readl(phba->HAregaddr);
  7605. if (unlikely(!phba->ha_copy)) {
  7606. spin_unlock(&phba->hbalock);
  7607. return IRQ_NONE;
  7608. } else if (phba->ha_copy & HA_ERATT) {
  7609. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7610. /* ERATT polling has handled ERATT */
  7611. phba->ha_copy &= ~HA_ERATT;
  7612. else
  7613. /* Indicate interrupt handler handles ERATT */
  7614. phba->hba_flag |= HBA_ERATT_HANDLED;
  7615. }
  7616. /*
  7617. * If there is deferred error attention, do not check for any interrupt.
  7618. */
  7619. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7620. spin_unlock_irq(&phba->hbalock);
  7621. return IRQ_NONE;
  7622. }
  7623. /* Clear attention sources except link and error attentions */
  7624. hc_copy = readl(phba->HCregaddr);
  7625. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7626. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7627. phba->HCregaddr);
  7628. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7629. writel(hc_copy, phba->HCregaddr);
  7630. readl(phba->HAregaddr); /* flush */
  7631. spin_unlock(&phba->hbalock);
  7632. /*
  7633. * Invokes slow-path host attention interrupt handling as appropriate.
  7634. */
  7635. /* status of events with mailbox and link attention */
  7636. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7637. /* status of events with ELS ring */
  7638. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7639. status2 >>= (4*LPFC_ELS_RING);
  7640. if (status1 || (status2 & HA_RXMASK))
  7641. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7642. else
  7643. sp_irq_rc = IRQ_NONE;
  7644. /*
  7645. * Invoke fast-path host attention interrupt handling as appropriate.
  7646. */
  7647. /* status of events with FCP ring */
  7648. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7649. status1 >>= (4*LPFC_FCP_RING);
  7650. /* status of events with extra ring */
  7651. if (phba->cfg_multi_ring_support == 2) {
  7652. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7653. status2 >>= (4*LPFC_EXTRA_RING);
  7654. } else
  7655. status2 = 0;
  7656. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7657. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7658. else
  7659. fp_irq_rc = IRQ_NONE;
  7660. /* Return device-level interrupt handling status */
  7661. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7662. } /* lpfc_sli_intr_handler */
  7663. /**
  7664. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7665. * @phba: pointer to lpfc hba data structure.
  7666. *
  7667. * This routine is invoked by the worker thread to process all the pending
  7668. * SLI4 FCP abort XRI events.
  7669. **/
  7670. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7671. {
  7672. struct lpfc_cq_event *cq_event;
  7673. /* First, declare the fcp xri abort event has been handled */
  7674. spin_lock_irq(&phba->hbalock);
  7675. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7676. spin_unlock_irq(&phba->hbalock);
  7677. /* Now, handle all the fcp xri abort events */
  7678. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7679. /* Get the first event from the head of the event queue */
  7680. spin_lock_irq(&phba->hbalock);
  7681. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7682. cq_event, struct lpfc_cq_event, list);
  7683. spin_unlock_irq(&phba->hbalock);
  7684. /* Notify aborted XRI for FCP work queue */
  7685. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7686. /* Free the event processed back to the free pool */
  7687. lpfc_sli4_cq_event_release(phba, cq_event);
  7688. }
  7689. }
  7690. /**
  7691. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7692. * @phba: pointer to lpfc hba data structure.
  7693. *
  7694. * This routine is invoked by the worker thread to process all the pending
  7695. * SLI4 els abort xri events.
  7696. **/
  7697. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7698. {
  7699. struct lpfc_cq_event *cq_event;
  7700. /* First, declare the els xri abort event has been handled */
  7701. spin_lock_irq(&phba->hbalock);
  7702. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7703. spin_unlock_irq(&phba->hbalock);
  7704. /* Now, handle all the els xri abort events */
  7705. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7706. /* Get the first event from the head of the event queue */
  7707. spin_lock_irq(&phba->hbalock);
  7708. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7709. cq_event, struct lpfc_cq_event, list);
  7710. spin_unlock_irq(&phba->hbalock);
  7711. /* Notify aborted XRI for ELS work queue */
  7712. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7713. /* Free the event processed back to the free pool */
  7714. lpfc_sli4_cq_event_release(phba, cq_event);
  7715. }
  7716. }
  7717. /**
  7718. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7719. * @phba: pointer to lpfc hba data structure
  7720. * @pIocbIn: pointer to the rspiocbq
  7721. * @pIocbOut: pointer to the cmdiocbq
  7722. * @wcqe: pointer to the complete wcqe
  7723. *
  7724. * This routine transfers the fields of a command iocbq to a response iocbq
  7725. * by copying all the IOCB fields from command iocbq and transferring the
  7726. * completion status information from the complete wcqe.
  7727. **/
  7728. static void
  7729. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7730. struct lpfc_iocbq *pIocbIn,
  7731. struct lpfc_iocbq *pIocbOut,
  7732. struct lpfc_wcqe_complete *wcqe)
  7733. {
  7734. unsigned long iflags;
  7735. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7736. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7737. sizeof(struct lpfc_iocbq) - offset);
  7738. /* Map WCQE parameters into irspiocb parameters */
  7739. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7740. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7741. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7742. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7743. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7744. wcqe->total_data_placed;
  7745. else
  7746. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7747. else {
  7748. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7749. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7750. }
  7751. /* Pick up HBA exchange busy condition */
  7752. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7753. spin_lock_irqsave(&phba->hbalock, iflags);
  7754. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7755. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7756. }
  7757. }
  7758. /**
  7759. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7760. * @phba: Pointer to HBA context object.
  7761. * @wcqe: Pointer to work-queue completion queue entry.
  7762. *
  7763. * This routine handles an ELS work-queue completion event and construct
  7764. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7765. * discovery engine to handle.
  7766. *
  7767. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7768. **/
  7769. static struct lpfc_iocbq *
  7770. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7771. struct lpfc_iocbq *irspiocbq)
  7772. {
  7773. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7774. struct lpfc_iocbq *cmdiocbq;
  7775. struct lpfc_wcqe_complete *wcqe;
  7776. unsigned long iflags;
  7777. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7778. spin_lock_irqsave(&phba->hbalock, iflags);
  7779. pring->stats.iocb_event++;
  7780. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7781. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7782. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7784. if (unlikely(!cmdiocbq)) {
  7785. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7786. "0386 ELS complete with no corresponding "
  7787. "cmdiocb: iotag (%d)\n",
  7788. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7789. lpfc_sli_release_iocbq(phba, irspiocbq);
  7790. return NULL;
  7791. }
  7792. /* Fake the irspiocbq and copy necessary response information */
  7793. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7794. return irspiocbq;
  7795. }
  7796. /**
  7797. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7798. * @phba: Pointer to HBA context object.
  7799. * @cqe: Pointer to mailbox completion queue entry.
  7800. *
  7801. * This routine process a mailbox completion queue entry with asynchrous
  7802. * event.
  7803. *
  7804. * Return: true if work posted to worker thread, otherwise false.
  7805. **/
  7806. static bool
  7807. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7808. {
  7809. struct lpfc_cq_event *cq_event;
  7810. unsigned long iflags;
  7811. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7812. "0392 Async Event: word0:x%x, word1:x%x, "
  7813. "word2:x%x, word3:x%x\n", mcqe->word0,
  7814. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7815. /* Allocate a new internal CQ_EVENT entry */
  7816. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7817. if (!cq_event) {
  7818. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7819. "0394 Failed to allocate CQ_EVENT entry\n");
  7820. return false;
  7821. }
  7822. /* Move the CQE into an asynchronous event entry */
  7823. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7824. spin_lock_irqsave(&phba->hbalock, iflags);
  7825. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7826. /* Set the async event flag */
  7827. phba->hba_flag |= ASYNC_EVENT;
  7828. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7829. return true;
  7830. }
  7831. /**
  7832. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7833. * @phba: Pointer to HBA context object.
  7834. * @cqe: Pointer to mailbox completion queue entry.
  7835. *
  7836. * This routine process a mailbox completion queue entry with mailbox
  7837. * completion event.
  7838. *
  7839. * Return: true if work posted to worker thread, otherwise false.
  7840. **/
  7841. static bool
  7842. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7843. {
  7844. uint32_t mcqe_status;
  7845. MAILBOX_t *mbox, *pmbox;
  7846. struct lpfc_mqe *mqe;
  7847. struct lpfc_vport *vport;
  7848. struct lpfc_nodelist *ndlp;
  7849. struct lpfc_dmabuf *mp;
  7850. unsigned long iflags;
  7851. LPFC_MBOXQ_t *pmb;
  7852. bool workposted = false;
  7853. int rc;
  7854. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7855. if (!bf_get(lpfc_trailer_completed, mcqe))
  7856. goto out_no_mqe_complete;
  7857. /* Get the reference to the active mbox command */
  7858. spin_lock_irqsave(&phba->hbalock, iflags);
  7859. pmb = phba->sli.mbox_active;
  7860. if (unlikely(!pmb)) {
  7861. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7862. "1832 No pending MBOX command to handle\n");
  7863. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7864. goto out_no_mqe_complete;
  7865. }
  7866. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7867. mqe = &pmb->u.mqe;
  7868. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7869. mbox = phba->mbox;
  7870. vport = pmb->vport;
  7871. /* Reset heartbeat timer */
  7872. phba->last_completion_time = jiffies;
  7873. del_timer(&phba->sli.mbox_tmo);
  7874. /* Move mbox data to caller's mailbox region, do endian swapping */
  7875. if (pmb->mbox_cmpl && mbox)
  7876. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7877. /* Set the mailbox status with SLI4 range 0x4000 */
  7878. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7879. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7880. bf_set(lpfc_mqe_status, mqe,
  7881. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7882. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7883. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7884. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7885. "MBOX dflt rpi: status:x%x rpi:x%x",
  7886. mcqe_status,
  7887. pmbox->un.varWords[0], 0);
  7888. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7889. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7890. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7891. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7892. * RID of the PPI using the same mbox buffer.
  7893. */
  7894. lpfc_unreg_login(phba, vport->vpi,
  7895. pmbox->un.varWords[0], pmb);
  7896. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7897. pmb->context1 = mp;
  7898. pmb->context2 = ndlp;
  7899. pmb->vport = vport;
  7900. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7901. if (rc != MBX_BUSY)
  7902. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7903. LOG_SLI, "0385 rc should "
  7904. "have been MBX_BUSY\n");
  7905. if (rc != MBX_NOT_FINISHED)
  7906. goto send_current_mbox;
  7907. }
  7908. }
  7909. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7910. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7911. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7912. /* There is mailbox completion work to do */
  7913. spin_lock_irqsave(&phba->hbalock, iflags);
  7914. __lpfc_mbox_cmpl_put(phba, pmb);
  7915. phba->work_ha |= HA_MBATT;
  7916. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7917. workposted = true;
  7918. send_current_mbox:
  7919. spin_lock_irqsave(&phba->hbalock, iflags);
  7920. /* Release the mailbox command posting token */
  7921. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7922. /* Setting active mailbox pointer need to be in sync to flag clear */
  7923. phba->sli.mbox_active = NULL;
  7924. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7925. /* Wake up worker thread to post the next pending mailbox command */
  7926. lpfc_worker_wake_up(phba);
  7927. out_no_mqe_complete:
  7928. if (bf_get(lpfc_trailer_consumed, mcqe))
  7929. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7930. return workposted;
  7931. }
  7932. /**
  7933. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7934. * @phba: Pointer to HBA context object.
  7935. * @cqe: Pointer to mailbox completion queue entry.
  7936. *
  7937. * This routine process a mailbox completion queue entry, it invokes the
  7938. * proper mailbox complete handling or asynchrous event handling routine
  7939. * according to the MCQE's async bit.
  7940. *
  7941. * Return: true if work posted to worker thread, otherwise false.
  7942. **/
  7943. static bool
  7944. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7945. {
  7946. struct lpfc_mcqe mcqe;
  7947. bool workposted;
  7948. /* Copy the mailbox MCQE and convert endian order as needed */
  7949. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7950. /* Invoke the proper event handling routine */
  7951. if (!bf_get(lpfc_trailer_async, &mcqe))
  7952. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7953. else
  7954. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7955. return workposted;
  7956. }
  7957. /**
  7958. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7959. * @phba: Pointer to HBA context object.
  7960. * @wcqe: Pointer to work-queue completion queue entry.
  7961. *
  7962. * This routine handles an ELS work-queue completion event.
  7963. *
  7964. * Return: true if work posted to worker thread, otherwise false.
  7965. **/
  7966. static bool
  7967. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7968. struct lpfc_wcqe_complete *wcqe)
  7969. {
  7970. struct lpfc_iocbq *irspiocbq;
  7971. unsigned long iflags;
  7972. /* Get an irspiocbq for later ELS response processing use */
  7973. irspiocbq = lpfc_sli_get_iocbq(phba);
  7974. if (!irspiocbq) {
  7975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7976. "0387 Failed to allocate an iocbq\n");
  7977. return false;
  7978. }
  7979. /* Save off the slow-path queue event for work thread to process */
  7980. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7981. spin_lock_irqsave(&phba->hbalock, iflags);
  7982. list_add_tail(&irspiocbq->cq_event.list,
  7983. &phba->sli4_hba.sp_queue_event);
  7984. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7986. return true;
  7987. }
  7988. /**
  7989. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7990. * @phba: Pointer to HBA context object.
  7991. * @wcqe: Pointer to work-queue completion queue entry.
  7992. *
  7993. * This routine handles slow-path WQ entry comsumed event by invoking the
  7994. * proper WQ release routine to the slow-path WQ.
  7995. **/
  7996. static void
  7997. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7998. struct lpfc_wcqe_release *wcqe)
  7999. {
  8000. /* Check for the slow-path ELS work queue */
  8001. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8002. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8003. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8004. else
  8005. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8006. "2579 Slow-path wqe consume event carries "
  8007. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8008. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8009. phba->sli4_hba.els_wq->queue_id);
  8010. }
  8011. /**
  8012. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8013. * @phba: Pointer to HBA context object.
  8014. * @cq: Pointer to a WQ completion queue.
  8015. * @wcqe: Pointer to work-queue completion queue entry.
  8016. *
  8017. * This routine handles an XRI abort event.
  8018. *
  8019. * Return: true if work posted to worker thread, otherwise false.
  8020. **/
  8021. static bool
  8022. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8023. struct lpfc_queue *cq,
  8024. struct sli4_wcqe_xri_aborted *wcqe)
  8025. {
  8026. bool workposted = false;
  8027. struct lpfc_cq_event *cq_event;
  8028. unsigned long iflags;
  8029. /* Allocate a new internal CQ_EVENT entry */
  8030. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8031. if (!cq_event) {
  8032. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8033. "0602 Failed to allocate CQ_EVENT entry\n");
  8034. return false;
  8035. }
  8036. /* Move the CQE into the proper xri abort event list */
  8037. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8038. switch (cq->subtype) {
  8039. case LPFC_FCP:
  8040. spin_lock_irqsave(&phba->hbalock, iflags);
  8041. list_add_tail(&cq_event->list,
  8042. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8043. /* Set the fcp xri abort event flag */
  8044. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8045. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8046. workposted = true;
  8047. break;
  8048. case LPFC_ELS:
  8049. spin_lock_irqsave(&phba->hbalock, iflags);
  8050. list_add_tail(&cq_event->list,
  8051. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8052. /* Set the els xri abort event flag */
  8053. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8054. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8055. workposted = true;
  8056. break;
  8057. default:
  8058. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8059. "0603 Invalid work queue CQE subtype (x%x)\n",
  8060. cq->subtype);
  8061. workposted = false;
  8062. break;
  8063. }
  8064. return workposted;
  8065. }
  8066. /**
  8067. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8068. * @phba: Pointer to HBA context object.
  8069. * @rcqe: Pointer to receive-queue completion queue entry.
  8070. *
  8071. * This routine process a receive-queue completion queue entry.
  8072. *
  8073. * Return: true if work posted to worker thread, otherwise false.
  8074. **/
  8075. static bool
  8076. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8077. {
  8078. bool workposted = false;
  8079. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8080. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8081. struct hbq_dmabuf *dma_buf;
  8082. uint32_t status;
  8083. unsigned long iflags;
  8084. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8085. goto out;
  8086. status = bf_get(lpfc_rcqe_status, rcqe);
  8087. switch (status) {
  8088. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8089. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8090. "2537 Receive Frame Truncated!!\n");
  8091. case FC_STATUS_RQ_SUCCESS:
  8092. lpfc_sli4_rq_release(hrq, drq);
  8093. spin_lock_irqsave(&phba->hbalock, iflags);
  8094. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8095. if (!dma_buf) {
  8096. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8097. goto out;
  8098. }
  8099. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8100. /* save off the frame for the word thread to process */
  8101. list_add_tail(&dma_buf->cq_event.list,
  8102. &phba->sli4_hba.sp_queue_event);
  8103. /* Frame received */
  8104. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8105. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8106. workposted = true;
  8107. break;
  8108. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8109. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8110. /* Post more buffers if possible */
  8111. spin_lock_irqsave(&phba->hbalock, iflags);
  8112. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8113. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8114. workposted = true;
  8115. break;
  8116. }
  8117. out:
  8118. return workposted;
  8119. }
  8120. /**
  8121. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8122. * @phba: Pointer to HBA context object.
  8123. * @cq: Pointer to the completion queue.
  8124. * @wcqe: Pointer to a completion queue entry.
  8125. *
  8126. * This routine process a slow-path work-queue or recieve queue completion queue
  8127. * entry.
  8128. *
  8129. * Return: true if work posted to worker thread, otherwise false.
  8130. **/
  8131. static bool
  8132. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8133. struct lpfc_cqe *cqe)
  8134. {
  8135. struct lpfc_cqe cqevt;
  8136. bool workposted = false;
  8137. /* Copy the work queue CQE and convert endian order if needed */
  8138. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8139. /* Check and process for different type of WCQE and dispatch */
  8140. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8141. case CQE_CODE_COMPL_WQE:
  8142. /* Process the WQ/RQ complete event */
  8143. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8144. (struct lpfc_wcqe_complete *)&cqevt);
  8145. break;
  8146. case CQE_CODE_RELEASE_WQE:
  8147. /* Process the WQ release event */
  8148. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8149. (struct lpfc_wcqe_release *)&cqevt);
  8150. break;
  8151. case CQE_CODE_XRI_ABORTED:
  8152. /* Process the WQ XRI abort event */
  8153. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8154. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8155. break;
  8156. case CQE_CODE_RECEIVE:
  8157. /* Process the RQ event */
  8158. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8159. (struct lpfc_rcqe *)&cqevt);
  8160. break;
  8161. default:
  8162. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8163. "0388 Not a valid WCQE code: x%x\n",
  8164. bf_get(lpfc_cqe_code, &cqevt));
  8165. break;
  8166. }
  8167. return workposted;
  8168. }
  8169. /**
  8170. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8171. * @phba: Pointer to HBA context object.
  8172. * @eqe: Pointer to fast-path event queue entry.
  8173. *
  8174. * This routine process a event queue entry from the slow-path event queue.
  8175. * It will check the MajorCode and MinorCode to determine this is for a
  8176. * completion event on a completion queue, if not, an error shall be logged
  8177. * and just return. Otherwise, it will get to the corresponding completion
  8178. * queue and process all the entries on that completion queue, rearm the
  8179. * completion queue, and then return.
  8180. *
  8181. **/
  8182. static void
  8183. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8184. {
  8185. struct lpfc_queue *cq = NULL, *childq, *speq;
  8186. struct lpfc_cqe *cqe;
  8187. bool workposted = false;
  8188. int ecount = 0;
  8189. uint16_t cqid;
  8190. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8191. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8192. "0359 Not a valid slow-path completion "
  8193. "event: majorcode=x%x, minorcode=x%x\n",
  8194. bf_get_le32(lpfc_eqe_major_code, eqe),
  8195. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8196. return;
  8197. }
  8198. /* Get the reference to the corresponding CQ */
  8199. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8200. /* Search for completion queue pointer matching this cqid */
  8201. speq = phba->sli4_hba.sp_eq;
  8202. list_for_each_entry(childq, &speq->child_list, list) {
  8203. if (childq->queue_id == cqid) {
  8204. cq = childq;
  8205. break;
  8206. }
  8207. }
  8208. if (unlikely(!cq)) {
  8209. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8210. "0365 Slow-path CQ identifier (%d) does "
  8211. "not exist\n", cqid);
  8212. return;
  8213. }
  8214. /* Process all the entries to the CQ */
  8215. switch (cq->type) {
  8216. case LPFC_MCQ:
  8217. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8218. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8219. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8220. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8221. }
  8222. break;
  8223. case LPFC_WCQ:
  8224. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8225. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8226. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8227. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8228. }
  8229. break;
  8230. default:
  8231. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8232. "0370 Invalid completion queue type (%d)\n",
  8233. cq->type);
  8234. return;
  8235. }
  8236. /* Catch the no cq entry condition, log an error */
  8237. if (unlikely(ecount == 0))
  8238. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8239. "0371 No entry from the CQ: identifier "
  8240. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8241. /* In any case, flash and re-arm the RCQ */
  8242. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8243. /* wake up worker thread if there are works to be done */
  8244. if (workposted)
  8245. lpfc_worker_wake_up(phba);
  8246. }
  8247. /**
  8248. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8249. * @eqe: Pointer to fast-path completion queue entry.
  8250. *
  8251. * This routine process a fast-path work queue completion entry from fast-path
  8252. * event queue for FCP command response completion.
  8253. **/
  8254. static void
  8255. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8256. struct lpfc_wcqe_complete *wcqe)
  8257. {
  8258. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8259. struct lpfc_iocbq *cmdiocbq;
  8260. struct lpfc_iocbq irspiocbq;
  8261. unsigned long iflags;
  8262. spin_lock_irqsave(&phba->hbalock, iflags);
  8263. pring->stats.iocb_event++;
  8264. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8265. /* Check for response status */
  8266. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8267. /* If resource errors reported from HBA, reduce queue
  8268. * depth of the SCSI device.
  8269. */
  8270. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8271. IOSTAT_LOCAL_REJECT) &&
  8272. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8273. phba->lpfc_rampdown_queue_depth(phba);
  8274. }
  8275. /* Log the error status */
  8276. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8277. "0373 FCP complete error: status=x%x, "
  8278. "hw_status=x%x, total_data_specified=%d, "
  8279. "parameter=x%x, word3=x%x\n",
  8280. bf_get(lpfc_wcqe_c_status, wcqe),
  8281. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8282. wcqe->total_data_placed, wcqe->parameter,
  8283. wcqe->word3);
  8284. }
  8285. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8286. spin_lock_irqsave(&phba->hbalock, iflags);
  8287. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8288. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8289. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8290. if (unlikely(!cmdiocbq)) {
  8291. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8292. "0374 FCP complete with no corresponding "
  8293. "cmdiocb: iotag (%d)\n",
  8294. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8295. return;
  8296. }
  8297. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8298. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8299. "0375 FCP cmdiocb not callback function "
  8300. "iotag: (%d)\n",
  8301. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8302. return;
  8303. }
  8304. /* Fake the irspiocb and copy necessary response information */
  8305. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8306. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8307. spin_lock_irqsave(&phba->hbalock, iflags);
  8308. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8309. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8310. }
  8311. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8312. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8313. }
  8314. /**
  8315. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8316. * @phba: Pointer to HBA context object.
  8317. * @cq: Pointer to completion queue.
  8318. * @wcqe: Pointer to work-queue completion queue entry.
  8319. *
  8320. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8321. * proper WQ release routine to the slow-path WQ.
  8322. **/
  8323. static void
  8324. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8325. struct lpfc_wcqe_release *wcqe)
  8326. {
  8327. struct lpfc_queue *childwq;
  8328. bool wqid_matched = false;
  8329. uint16_t fcp_wqid;
  8330. /* Check for fast-path FCP work queue release */
  8331. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8332. list_for_each_entry(childwq, &cq->child_list, list) {
  8333. if (childwq->queue_id == fcp_wqid) {
  8334. lpfc_sli4_wq_release(childwq,
  8335. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8336. wqid_matched = true;
  8337. break;
  8338. }
  8339. }
  8340. /* Report warning log message if no match found */
  8341. if (wqid_matched != true)
  8342. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8343. "2580 Fast-path wqe consume event carries "
  8344. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8345. }
  8346. /**
  8347. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8348. * @cq: Pointer to the completion queue.
  8349. * @eqe: Pointer to fast-path completion queue entry.
  8350. *
  8351. * This routine process a fast-path work queue completion entry from fast-path
  8352. * event queue for FCP command response completion.
  8353. **/
  8354. static int
  8355. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8356. struct lpfc_cqe *cqe)
  8357. {
  8358. struct lpfc_wcqe_release wcqe;
  8359. bool workposted = false;
  8360. /* Copy the work queue CQE and convert endian order if needed */
  8361. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8362. /* Check and process for different type of WCQE and dispatch */
  8363. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8364. case CQE_CODE_COMPL_WQE:
  8365. /* Process the WQ complete event */
  8366. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8367. (struct lpfc_wcqe_complete *)&wcqe);
  8368. break;
  8369. case CQE_CODE_RELEASE_WQE:
  8370. /* Process the WQ release event */
  8371. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8372. (struct lpfc_wcqe_release *)&wcqe);
  8373. break;
  8374. case CQE_CODE_XRI_ABORTED:
  8375. /* Process the WQ XRI abort event */
  8376. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8377. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8378. break;
  8379. default:
  8380. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8381. "0144 Not a valid WCQE code: x%x\n",
  8382. bf_get(lpfc_wcqe_c_code, &wcqe));
  8383. break;
  8384. }
  8385. return workposted;
  8386. }
  8387. /**
  8388. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8389. * @phba: Pointer to HBA context object.
  8390. * @eqe: Pointer to fast-path event queue entry.
  8391. *
  8392. * This routine process a event queue entry from the fast-path event queue.
  8393. * It will check the MajorCode and MinorCode to determine this is for a
  8394. * completion event on a completion queue, if not, an error shall be logged
  8395. * and just return. Otherwise, it will get to the corresponding completion
  8396. * queue and process all the entries on the completion queue, rearm the
  8397. * completion queue, and then return.
  8398. **/
  8399. static void
  8400. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8401. uint32_t fcp_cqidx)
  8402. {
  8403. struct lpfc_queue *cq;
  8404. struct lpfc_cqe *cqe;
  8405. bool workposted = false;
  8406. uint16_t cqid;
  8407. int ecount = 0;
  8408. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8409. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8410. "0366 Not a valid fast-path completion "
  8411. "event: majorcode=x%x, minorcode=x%x\n",
  8412. bf_get_le32(lpfc_eqe_major_code, eqe),
  8413. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8414. return;
  8415. }
  8416. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8417. if (unlikely(!cq)) {
  8418. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8419. "0367 Fast-path completion queue does not "
  8420. "exist\n");
  8421. return;
  8422. }
  8423. /* Get the reference to the corresponding CQ */
  8424. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8425. if (unlikely(cqid != cq->queue_id)) {
  8426. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8427. "0368 Miss-matched fast-path completion "
  8428. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8429. cqid, cq->queue_id);
  8430. return;
  8431. }
  8432. /* Process all the entries to the CQ */
  8433. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8434. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8435. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8436. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8437. }
  8438. /* Catch the no cq entry condition */
  8439. if (unlikely(ecount == 0))
  8440. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8441. "0369 No entry from fast-path completion "
  8442. "queue fcpcqid=%d\n", cq->queue_id);
  8443. /* In any case, flash and re-arm the CQ */
  8444. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8445. /* wake up worker thread if there are works to be done */
  8446. if (workposted)
  8447. lpfc_worker_wake_up(phba);
  8448. }
  8449. static void
  8450. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8451. {
  8452. struct lpfc_eqe *eqe;
  8453. /* walk all the EQ entries and drop on the floor */
  8454. while ((eqe = lpfc_sli4_eq_get(eq)))
  8455. ;
  8456. /* Clear and re-arm the EQ */
  8457. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8458. }
  8459. /**
  8460. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8461. * @irq: Interrupt number.
  8462. * @dev_id: The device context pointer.
  8463. *
  8464. * This function is directly called from the PCI layer as an interrupt
  8465. * service routine when device with SLI-4 interface spec is enabled with
  8466. * MSI-X multi-message interrupt mode and there are slow-path events in
  8467. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8468. * interrupt mode, this function is called as part of the device-level
  8469. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8470. * undergoing initialization, the interrupt handler will not process the
  8471. * interrupt. The link attention and ELS ring attention events are handled
  8472. * by the worker thread. The interrupt handler signals the worker thread
  8473. * and returns for these events. This function is called without any lock
  8474. * held. It gets the hbalock to access and update SLI data structures.
  8475. *
  8476. * This function returns IRQ_HANDLED when interrupt is handled else it
  8477. * returns IRQ_NONE.
  8478. **/
  8479. irqreturn_t
  8480. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8481. {
  8482. struct lpfc_hba *phba;
  8483. struct lpfc_queue *speq;
  8484. struct lpfc_eqe *eqe;
  8485. unsigned long iflag;
  8486. int ecount = 0;
  8487. /*
  8488. * Get the driver's phba structure from the dev_id
  8489. */
  8490. phba = (struct lpfc_hba *)dev_id;
  8491. if (unlikely(!phba))
  8492. return IRQ_NONE;
  8493. /* Get to the EQ struct associated with this vector */
  8494. speq = phba->sli4_hba.sp_eq;
  8495. /* Check device state for handling interrupt */
  8496. if (unlikely(lpfc_intr_state_check(phba))) {
  8497. /* Check again for link_state with lock held */
  8498. spin_lock_irqsave(&phba->hbalock, iflag);
  8499. if (phba->link_state < LPFC_LINK_DOWN)
  8500. /* Flush, clear interrupt, and rearm the EQ */
  8501. lpfc_sli4_eq_flush(phba, speq);
  8502. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8503. return IRQ_NONE;
  8504. }
  8505. /*
  8506. * Process all the event on FCP slow-path EQ
  8507. */
  8508. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8509. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8510. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8511. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8512. }
  8513. /* Always clear and re-arm the slow-path EQ */
  8514. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8515. /* Catch the no cq entry condition */
  8516. if (unlikely(ecount == 0)) {
  8517. if (phba->intr_type == MSIX)
  8518. /* MSI-X treated interrupt served as no EQ share INT */
  8519. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8520. "0357 MSI-X interrupt with no EQE\n");
  8521. else
  8522. /* Non MSI-X treated on interrupt as EQ share INT */
  8523. return IRQ_NONE;
  8524. }
  8525. return IRQ_HANDLED;
  8526. } /* lpfc_sli4_sp_intr_handler */
  8527. /**
  8528. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8529. * @irq: Interrupt number.
  8530. * @dev_id: The device context pointer.
  8531. *
  8532. * This function is directly called from the PCI layer as an interrupt
  8533. * service routine when device with SLI-4 interface spec is enabled with
  8534. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8535. * ring event in the HBA. However, when the device is enabled with either
  8536. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8537. * device-level interrupt handler. When the PCI slot is in error recovery
  8538. * or the HBA is undergoing initialization, the interrupt handler will not
  8539. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8540. * the intrrupt context. This function is called without any lock held.
  8541. * It gets the hbalock to access and update SLI data structures. Note that,
  8542. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8543. * equal to that of FCP CQ index.
  8544. *
  8545. * This function returns IRQ_HANDLED when interrupt is handled else it
  8546. * returns IRQ_NONE.
  8547. **/
  8548. irqreturn_t
  8549. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8550. {
  8551. struct lpfc_hba *phba;
  8552. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8553. struct lpfc_queue *fpeq;
  8554. struct lpfc_eqe *eqe;
  8555. unsigned long iflag;
  8556. int ecount = 0;
  8557. uint32_t fcp_eqidx;
  8558. /* Get the driver's phba structure from the dev_id */
  8559. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8560. phba = fcp_eq_hdl->phba;
  8561. fcp_eqidx = fcp_eq_hdl->idx;
  8562. if (unlikely(!phba))
  8563. return IRQ_NONE;
  8564. /* Get to the EQ struct associated with this vector */
  8565. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8566. /* Check device state for handling interrupt */
  8567. if (unlikely(lpfc_intr_state_check(phba))) {
  8568. /* Check again for link_state with lock held */
  8569. spin_lock_irqsave(&phba->hbalock, iflag);
  8570. if (phba->link_state < LPFC_LINK_DOWN)
  8571. /* Flush, clear interrupt, and rearm the EQ */
  8572. lpfc_sli4_eq_flush(phba, fpeq);
  8573. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8574. return IRQ_NONE;
  8575. }
  8576. /*
  8577. * Process all the event on FCP fast-path EQ
  8578. */
  8579. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8580. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8581. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8582. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8583. }
  8584. /* Always clear and re-arm the fast-path EQ */
  8585. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8586. if (unlikely(ecount == 0)) {
  8587. if (phba->intr_type == MSIX)
  8588. /* MSI-X treated interrupt served as no EQ share INT */
  8589. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8590. "0358 MSI-X interrupt with no EQE\n");
  8591. else
  8592. /* Non MSI-X treated on interrupt as EQ share INT */
  8593. return IRQ_NONE;
  8594. }
  8595. return IRQ_HANDLED;
  8596. } /* lpfc_sli4_fp_intr_handler */
  8597. /**
  8598. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8599. * @irq: Interrupt number.
  8600. * @dev_id: The device context pointer.
  8601. *
  8602. * This function is the device-level interrupt handler to device with SLI-4
  8603. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8604. * interrupt mode is enabled and there is an event in the HBA which requires
  8605. * driver attention. This function invokes the slow-path interrupt attention
  8606. * handling function and fast-path interrupt attention handling function in
  8607. * turn to process the relevant HBA attention events. This function is called
  8608. * without any lock held. It gets the hbalock to access and update SLI data
  8609. * structures.
  8610. *
  8611. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8612. * returns IRQ_NONE.
  8613. **/
  8614. irqreturn_t
  8615. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8616. {
  8617. struct lpfc_hba *phba;
  8618. irqreturn_t sp_irq_rc, fp_irq_rc;
  8619. bool fp_handled = false;
  8620. uint32_t fcp_eqidx;
  8621. /* Get the driver's phba structure from the dev_id */
  8622. phba = (struct lpfc_hba *)dev_id;
  8623. if (unlikely(!phba))
  8624. return IRQ_NONE;
  8625. /*
  8626. * Invokes slow-path host attention interrupt handling as appropriate.
  8627. */
  8628. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8629. /*
  8630. * Invoke fast-path host attention interrupt handling as appropriate.
  8631. */
  8632. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8633. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8634. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8635. if (fp_irq_rc == IRQ_HANDLED)
  8636. fp_handled |= true;
  8637. }
  8638. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8639. } /* lpfc_sli4_intr_handler */
  8640. /**
  8641. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8642. * @queue: The queue structure to free.
  8643. *
  8644. * This function frees a queue structure and the DMAable memeory used for
  8645. * the host resident queue. This function must be called after destroying the
  8646. * queue on the HBA.
  8647. **/
  8648. void
  8649. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8650. {
  8651. struct lpfc_dmabuf *dmabuf;
  8652. if (!queue)
  8653. return;
  8654. while (!list_empty(&queue->page_list)) {
  8655. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8656. list);
  8657. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8658. dmabuf->virt, dmabuf->phys);
  8659. kfree(dmabuf);
  8660. }
  8661. kfree(queue);
  8662. return;
  8663. }
  8664. /**
  8665. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8666. * @phba: The HBA that this queue is being created on.
  8667. * @entry_size: The size of each queue entry for this queue.
  8668. * @entry count: The number of entries that this queue will handle.
  8669. *
  8670. * This function allocates a queue structure and the DMAable memory used for
  8671. * the host resident queue. This function must be called before creating the
  8672. * queue on the HBA.
  8673. **/
  8674. struct lpfc_queue *
  8675. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8676. uint32_t entry_count)
  8677. {
  8678. struct lpfc_queue *queue;
  8679. struct lpfc_dmabuf *dmabuf;
  8680. int x, total_qe_count;
  8681. void *dma_pointer;
  8682. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8683. if (!phba->sli4_hba.pc_sli4_params.supported)
  8684. hw_page_size = SLI4_PAGE_SIZE;
  8685. queue = kzalloc(sizeof(struct lpfc_queue) +
  8686. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8687. if (!queue)
  8688. return NULL;
  8689. queue->page_count = (ALIGN(entry_size * entry_count,
  8690. hw_page_size))/hw_page_size;
  8691. INIT_LIST_HEAD(&queue->list);
  8692. INIT_LIST_HEAD(&queue->page_list);
  8693. INIT_LIST_HEAD(&queue->child_list);
  8694. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8695. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8696. if (!dmabuf)
  8697. goto out_fail;
  8698. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8699. hw_page_size, &dmabuf->phys,
  8700. GFP_KERNEL);
  8701. if (!dmabuf->virt) {
  8702. kfree(dmabuf);
  8703. goto out_fail;
  8704. }
  8705. memset(dmabuf->virt, 0, hw_page_size);
  8706. dmabuf->buffer_tag = x;
  8707. list_add_tail(&dmabuf->list, &queue->page_list);
  8708. /* initialize queue's entry array */
  8709. dma_pointer = dmabuf->virt;
  8710. for (; total_qe_count < entry_count &&
  8711. dma_pointer < (hw_page_size + dmabuf->virt);
  8712. total_qe_count++, dma_pointer += entry_size) {
  8713. queue->qe[total_qe_count].address = dma_pointer;
  8714. }
  8715. }
  8716. queue->entry_size = entry_size;
  8717. queue->entry_count = entry_count;
  8718. queue->phba = phba;
  8719. return queue;
  8720. out_fail:
  8721. lpfc_sli4_queue_free(queue);
  8722. return NULL;
  8723. }
  8724. /**
  8725. * lpfc_eq_create - Create an Event Queue on the HBA
  8726. * @phba: HBA structure that indicates port to create a queue on.
  8727. * @eq: The queue structure to use to create the event queue.
  8728. * @imax: The maximum interrupt per second limit.
  8729. *
  8730. * This function creates an event queue, as detailed in @eq, on a port,
  8731. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8732. *
  8733. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8734. * is used to get the entry count and entry size that are necessary to
  8735. * determine the number of pages to allocate and use for this queue. This
  8736. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8737. * event queue. This function is asynchronous and will wait for the mailbox
  8738. * command to finish before continuing.
  8739. *
  8740. * On success this function will return a zero. If unable to allocate enough
  8741. * memory this function will return ENOMEM. If the queue create mailbox command
  8742. * fails this function will return ENXIO.
  8743. **/
  8744. uint32_t
  8745. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8746. {
  8747. struct lpfc_mbx_eq_create *eq_create;
  8748. LPFC_MBOXQ_t *mbox;
  8749. int rc, length, status = 0;
  8750. struct lpfc_dmabuf *dmabuf;
  8751. uint32_t shdr_status, shdr_add_status;
  8752. union lpfc_sli4_cfg_shdr *shdr;
  8753. uint16_t dmult;
  8754. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8755. if (!phba->sli4_hba.pc_sli4_params.supported)
  8756. hw_page_size = SLI4_PAGE_SIZE;
  8757. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8758. if (!mbox)
  8759. return -ENOMEM;
  8760. length = (sizeof(struct lpfc_mbx_eq_create) -
  8761. sizeof(struct lpfc_sli4_cfg_mhdr));
  8762. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8763. LPFC_MBOX_OPCODE_EQ_CREATE,
  8764. length, LPFC_SLI4_MBX_EMBED);
  8765. eq_create = &mbox->u.mqe.un.eq_create;
  8766. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8767. eq->page_count);
  8768. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8769. LPFC_EQE_SIZE);
  8770. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8771. /* Calculate delay multiper from maximum interrupt per second */
  8772. dmult = LPFC_DMULT_CONST/imax - 1;
  8773. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8774. dmult);
  8775. switch (eq->entry_count) {
  8776. default:
  8777. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8778. "0360 Unsupported EQ count. (%d)\n",
  8779. eq->entry_count);
  8780. if (eq->entry_count < 256)
  8781. return -EINVAL;
  8782. /* otherwise default to smallest count (drop through) */
  8783. case 256:
  8784. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8785. LPFC_EQ_CNT_256);
  8786. break;
  8787. case 512:
  8788. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8789. LPFC_EQ_CNT_512);
  8790. break;
  8791. case 1024:
  8792. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8793. LPFC_EQ_CNT_1024);
  8794. break;
  8795. case 2048:
  8796. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8797. LPFC_EQ_CNT_2048);
  8798. break;
  8799. case 4096:
  8800. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8801. LPFC_EQ_CNT_4096);
  8802. break;
  8803. }
  8804. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8805. memset(dmabuf->virt, 0, hw_page_size);
  8806. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8807. putPaddrLow(dmabuf->phys);
  8808. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8809. putPaddrHigh(dmabuf->phys);
  8810. }
  8811. mbox->vport = phba->pport;
  8812. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8813. mbox->context1 = NULL;
  8814. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8815. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8816. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8817. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8818. if (shdr_status || shdr_add_status || rc) {
  8819. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8820. "2500 EQ_CREATE mailbox failed with "
  8821. "status x%x add_status x%x, mbx status x%x\n",
  8822. shdr_status, shdr_add_status, rc);
  8823. status = -ENXIO;
  8824. }
  8825. eq->type = LPFC_EQ;
  8826. eq->subtype = LPFC_NONE;
  8827. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8828. if (eq->queue_id == 0xFFFF)
  8829. status = -ENXIO;
  8830. eq->host_index = 0;
  8831. eq->hba_index = 0;
  8832. mempool_free(mbox, phba->mbox_mem_pool);
  8833. return status;
  8834. }
  8835. /**
  8836. * lpfc_cq_create - Create a Completion Queue on the HBA
  8837. * @phba: HBA structure that indicates port to create a queue on.
  8838. * @cq: The queue structure to use to create the completion queue.
  8839. * @eq: The event queue to bind this completion queue to.
  8840. *
  8841. * This function creates a completion queue, as detailed in @wq, on a port,
  8842. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8843. *
  8844. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8845. * is used to get the entry count and entry size that are necessary to
  8846. * determine the number of pages to allocate and use for this queue. The @eq
  8847. * is used to indicate which event queue to bind this completion queue to. This
  8848. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8849. * completion queue. This function is asynchronous and will wait for the mailbox
  8850. * command to finish before continuing.
  8851. *
  8852. * On success this function will return a zero. If unable to allocate enough
  8853. * memory this function will return ENOMEM. If the queue create mailbox command
  8854. * fails this function will return ENXIO.
  8855. **/
  8856. uint32_t
  8857. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8858. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8859. {
  8860. struct lpfc_mbx_cq_create *cq_create;
  8861. struct lpfc_dmabuf *dmabuf;
  8862. LPFC_MBOXQ_t *mbox;
  8863. int rc, length, status = 0;
  8864. uint32_t shdr_status, shdr_add_status;
  8865. union lpfc_sli4_cfg_shdr *shdr;
  8866. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8867. if (!phba->sli4_hba.pc_sli4_params.supported)
  8868. hw_page_size = SLI4_PAGE_SIZE;
  8869. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8870. if (!mbox)
  8871. return -ENOMEM;
  8872. length = (sizeof(struct lpfc_mbx_cq_create) -
  8873. sizeof(struct lpfc_sli4_cfg_mhdr));
  8874. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8875. LPFC_MBOX_OPCODE_CQ_CREATE,
  8876. length, LPFC_SLI4_MBX_EMBED);
  8877. cq_create = &mbox->u.mqe.un.cq_create;
  8878. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8879. cq->page_count);
  8880. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8881. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8882. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8883. switch (cq->entry_count) {
  8884. default:
  8885. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8886. "0361 Unsupported CQ count. (%d)\n",
  8887. cq->entry_count);
  8888. if (cq->entry_count < 256)
  8889. return -EINVAL;
  8890. /* otherwise default to smallest count (drop through) */
  8891. case 256:
  8892. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8893. LPFC_CQ_CNT_256);
  8894. break;
  8895. case 512:
  8896. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8897. LPFC_CQ_CNT_512);
  8898. break;
  8899. case 1024:
  8900. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8901. LPFC_CQ_CNT_1024);
  8902. break;
  8903. }
  8904. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8905. memset(dmabuf->virt, 0, hw_page_size);
  8906. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8907. putPaddrLow(dmabuf->phys);
  8908. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8909. putPaddrHigh(dmabuf->phys);
  8910. }
  8911. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8912. /* The IOCTL status is embedded in the mailbox subheader. */
  8913. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8914. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8915. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8916. if (shdr_status || shdr_add_status || rc) {
  8917. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8918. "2501 CQ_CREATE mailbox failed with "
  8919. "status x%x add_status x%x, mbx status x%x\n",
  8920. shdr_status, shdr_add_status, rc);
  8921. status = -ENXIO;
  8922. goto out;
  8923. }
  8924. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8925. if (cq->queue_id == 0xFFFF) {
  8926. status = -ENXIO;
  8927. goto out;
  8928. }
  8929. /* link the cq onto the parent eq child list */
  8930. list_add_tail(&cq->list, &eq->child_list);
  8931. /* Set up completion queue's type and subtype */
  8932. cq->type = type;
  8933. cq->subtype = subtype;
  8934. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8935. cq->host_index = 0;
  8936. cq->hba_index = 0;
  8937. out:
  8938. mempool_free(mbox, phba->mbox_mem_pool);
  8939. return status;
  8940. }
  8941. /**
  8942. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  8943. * @phba: HBA structure that indicates port to create a queue on.
  8944. * @mq: The queue structure to use to create the mailbox queue.
  8945. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  8946. * @cq: The completion queue to associate with this cq.
  8947. *
  8948. * This function provides failback (fb) functionality when the
  8949. * mq_create_ext fails on older FW generations. It's purpose is identical
  8950. * to mq_create_ext otherwise.
  8951. *
  8952. * This routine cannot fail as all attributes were previously accessed and
  8953. * initialized in mq_create_ext.
  8954. **/
  8955. static void
  8956. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8957. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  8958. {
  8959. struct lpfc_mbx_mq_create *mq_create;
  8960. struct lpfc_dmabuf *dmabuf;
  8961. int length;
  8962. length = (sizeof(struct lpfc_mbx_mq_create) -
  8963. sizeof(struct lpfc_sli4_cfg_mhdr));
  8964. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8965. LPFC_MBOX_OPCODE_MQ_CREATE,
  8966. length, LPFC_SLI4_MBX_EMBED);
  8967. mq_create = &mbox->u.mqe.un.mq_create;
  8968. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8969. mq->page_count);
  8970. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8971. cq->queue_id);
  8972. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8973. switch (mq->entry_count) {
  8974. case 16:
  8975. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8976. LPFC_MQ_CNT_16);
  8977. break;
  8978. case 32:
  8979. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8980. LPFC_MQ_CNT_32);
  8981. break;
  8982. case 64:
  8983. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8984. LPFC_MQ_CNT_64);
  8985. break;
  8986. case 128:
  8987. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8988. LPFC_MQ_CNT_128);
  8989. break;
  8990. }
  8991. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8992. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8993. putPaddrLow(dmabuf->phys);
  8994. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8995. putPaddrHigh(dmabuf->phys);
  8996. }
  8997. }
  8998. /**
  8999. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9000. * @phba: HBA structure that indicates port to create a queue on.
  9001. * @mq: The queue structure to use to create the mailbox queue.
  9002. * @cq: The completion queue to associate with this cq.
  9003. * @subtype: The queue's subtype.
  9004. *
  9005. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9006. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9007. *
  9008. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9009. * is used to get the entry count and entry size that are necessary to
  9010. * determine the number of pages to allocate and use for this queue. This
  9011. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9012. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9013. * command to finish before continuing.
  9014. *
  9015. * On success this function will return a zero. If unable to allocate enough
  9016. * memory this function will return ENOMEM. If the queue create mailbox command
  9017. * fails this function will return ENXIO.
  9018. **/
  9019. int32_t
  9020. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9021. struct lpfc_queue *cq, uint32_t subtype)
  9022. {
  9023. struct lpfc_mbx_mq_create *mq_create;
  9024. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9025. struct lpfc_dmabuf *dmabuf;
  9026. LPFC_MBOXQ_t *mbox;
  9027. int rc, length, status = 0;
  9028. uint32_t shdr_status, shdr_add_status;
  9029. union lpfc_sli4_cfg_shdr *shdr;
  9030. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9031. if (!phba->sli4_hba.pc_sli4_params.supported)
  9032. hw_page_size = SLI4_PAGE_SIZE;
  9033. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9034. if (!mbox)
  9035. return -ENOMEM;
  9036. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9037. sizeof(struct lpfc_sli4_cfg_mhdr));
  9038. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9039. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9040. length, LPFC_SLI4_MBX_EMBED);
  9041. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9042. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9043. mq->page_count);
  9044. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9045. 1);
  9046. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9047. &mq_create_ext->u.request, 1);
  9048. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9049. &mq_create_ext->u.request, 1);
  9050. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9051. cq->queue_id);
  9052. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9053. switch (mq->entry_count) {
  9054. default:
  9055. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9056. "0362 Unsupported MQ count. (%d)\n",
  9057. mq->entry_count);
  9058. if (mq->entry_count < 16)
  9059. return -EINVAL;
  9060. /* otherwise default to smallest count (drop through) */
  9061. case 16:
  9062. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9063. LPFC_MQ_CNT_16);
  9064. break;
  9065. case 32:
  9066. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9067. LPFC_MQ_CNT_32);
  9068. break;
  9069. case 64:
  9070. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9071. LPFC_MQ_CNT_64);
  9072. break;
  9073. case 128:
  9074. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9075. LPFC_MQ_CNT_128);
  9076. break;
  9077. }
  9078. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9079. memset(dmabuf->virt, 0, hw_page_size);
  9080. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9081. putPaddrLow(dmabuf->phys);
  9082. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9083. putPaddrHigh(dmabuf->phys);
  9084. }
  9085. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9086. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9087. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9088. &mq_create_ext->u.response);
  9089. if (rc != MBX_SUCCESS) {
  9090. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9091. "2795 MQ_CREATE_EXT failed with "
  9092. "status x%x. Failback to MQ_CREATE.\n",
  9093. rc);
  9094. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9095. mq_create = &mbox->u.mqe.un.mq_create;
  9096. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9097. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9098. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9099. &mq_create->u.response);
  9100. }
  9101. /* The IOCTL status is embedded in the mailbox subheader. */
  9102. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9103. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9104. if (shdr_status || shdr_add_status || rc) {
  9105. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9106. "2502 MQ_CREATE mailbox failed with "
  9107. "status x%x add_status x%x, mbx status x%x\n",
  9108. shdr_status, shdr_add_status, rc);
  9109. status = -ENXIO;
  9110. goto out;
  9111. }
  9112. if (mq->queue_id == 0xFFFF) {
  9113. status = -ENXIO;
  9114. goto out;
  9115. }
  9116. mq->type = LPFC_MQ;
  9117. mq->subtype = subtype;
  9118. mq->host_index = 0;
  9119. mq->hba_index = 0;
  9120. /* link the mq onto the parent cq child list */
  9121. list_add_tail(&mq->list, &cq->child_list);
  9122. out:
  9123. mempool_free(mbox, phba->mbox_mem_pool);
  9124. return status;
  9125. }
  9126. /**
  9127. * lpfc_wq_create - Create a Work Queue on the HBA
  9128. * @phba: HBA structure that indicates port to create a queue on.
  9129. * @wq: The queue structure to use to create the work queue.
  9130. * @cq: The completion queue to bind this work queue to.
  9131. * @subtype: The subtype of the work queue indicating its functionality.
  9132. *
  9133. * This function creates a work queue, as detailed in @wq, on a port, described
  9134. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9135. *
  9136. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9137. * is used to get the entry count and entry size that are necessary to
  9138. * determine the number of pages to allocate and use for this queue. The @cq
  9139. * is used to indicate which completion queue to bind this work queue to. This
  9140. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9141. * work queue. This function is asynchronous and will wait for the mailbox
  9142. * command to finish before continuing.
  9143. *
  9144. * On success this function will return a zero. If unable to allocate enough
  9145. * memory this function will return ENOMEM. If the queue create mailbox command
  9146. * fails this function will return ENXIO.
  9147. **/
  9148. uint32_t
  9149. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9150. struct lpfc_queue *cq, uint32_t subtype)
  9151. {
  9152. struct lpfc_mbx_wq_create *wq_create;
  9153. struct lpfc_dmabuf *dmabuf;
  9154. LPFC_MBOXQ_t *mbox;
  9155. int rc, length, status = 0;
  9156. uint32_t shdr_status, shdr_add_status;
  9157. union lpfc_sli4_cfg_shdr *shdr;
  9158. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9159. if (!phba->sli4_hba.pc_sli4_params.supported)
  9160. hw_page_size = SLI4_PAGE_SIZE;
  9161. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9162. if (!mbox)
  9163. return -ENOMEM;
  9164. length = (sizeof(struct lpfc_mbx_wq_create) -
  9165. sizeof(struct lpfc_sli4_cfg_mhdr));
  9166. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9167. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9168. length, LPFC_SLI4_MBX_EMBED);
  9169. wq_create = &mbox->u.mqe.un.wq_create;
  9170. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9171. wq->page_count);
  9172. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9173. cq->queue_id);
  9174. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9175. memset(dmabuf->virt, 0, hw_page_size);
  9176. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9177. putPaddrLow(dmabuf->phys);
  9178. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9179. putPaddrHigh(dmabuf->phys);
  9180. }
  9181. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9182. /* The IOCTL status is embedded in the mailbox subheader. */
  9183. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9184. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9185. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9186. if (shdr_status || shdr_add_status || rc) {
  9187. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9188. "2503 WQ_CREATE mailbox failed with "
  9189. "status x%x add_status x%x, mbx status x%x\n",
  9190. shdr_status, shdr_add_status, rc);
  9191. status = -ENXIO;
  9192. goto out;
  9193. }
  9194. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9195. if (wq->queue_id == 0xFFFF) {
  9196. status = -ENXIO;
  9197. goto out;
  9198. }
  9199. wq->type = LPFC_WQ;
  9200. wq->subtype = subtype;
  9201. wq->host_index = 0;
  9202. wq->hba_index = 0;
  9203. /* link the wq onto the parent cq child list */
  9204. list_add_tail(&wq->list, &cq->child_list);
  9205. out:
  9206. mempool_free(mbox, phba->mbox_mem_pool);
  9207. return status;
  9208. }
  9209. /**
  9210. * lpfc_rq_create - Create a Receive Queue on the HBA
  9211. * @phba: HBA structure that indicates port to create a queue on.
  9212. * @hrq: The queue structure to use to create the header receive queue.
  9213. * @drq: The queue structure to use to create the data receive queue.
  9214. * @cq: The completion queue to bind this work queue to.
  9215. *
  9216. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9217. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9218. * to the HBA.
  9219. *
  9220. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9221. * struct is used to get the entry count that is necessary to determine the
  9222. * number of pages to use for this queue. The @cq is used to indicate which
  9223. * completion queue to bind received buffers that are posted to these queues to.
  9224. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9225. * receive queue pair. This function is asynchronous and will wait for the
  9226. * mailbox command to finish before continuing.
  9227. *
  9228. * On success this function will return a zero. If unable to allocate enough
  9229. * memory this function will return ENOMEM. If the queue create mailbox command
  9230. * fails this function will return ENXIO.
  9231. **/
  9232. uint32_t
  9233. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9234. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9235. {
  9236. struct lpfc_mbx_rq_create *rq_create;
  9237. struct lpfc_dmabuf *dmabuf;
  9238. LPFC_MBOXQ_t *mbox;
  9239. int rc, length, status = 0;
  9240. uint32_t shdr_status, shdr_add_status;
  9241. union lpfc_sli4_cfg_shdr *shdr;
  9242. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9243. if (!phba->sli4_hba.pc_sli4_params.supported)
  9244. hw_page_size = SLI4_PAGE_SIZE;
  9245. if (hrq->entry_count != drq->entry_count)
  9246. return -EINVAL;
  9247. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9248. if (!mbox)
  9249. return -ENOMEM;
  9250. length = (sizeof(struct lpfc_mbx_rq_create) -
  9251. sizeof(struct lpfc_sli4_cfg_mhdr));
  9252. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9253. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9254. length, LPFC_SLI4_MBX_EMBED);
  9255. rq_create = &mbox->u.mqe.un.rq_create;
  9256. switch (hrq->entry_count) {
  9257. default:
  9258. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9259. "2535 Unsupported RQ count. (%d)\n",
  9260. hrq->entry_count);
  9261. if (hrq->entry_count < 512)
  9262. return -EINVAL;
  9263. /* otherwise default to smallest count (drop through) */
  9264. case 512:
  9265. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9266. LPFC_RQ_RING_SIZE_512);
  9267. break;
  9268. case 1024:
  9269. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9270. LPFC_RQ_RING_SIZE_1024);
  9271. break;
  9272. case 2048:
  9273. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9274. LPFC_RQ_RING_SIZE_2048);
  9275. break;
  9276. case 4096:
  9277. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9278. LPFC_RQ_RING_SIZE_4096);
  9279. break;
  9280. }
  9281. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9282. cq->queue_id);
  9283. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9284. hrq->page_count);
  9285. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9286. LPFC_HDR_BUF_SIZE);
  9287. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9288. memset(dmabuf->virt, 0, hw_page_size);
  9289. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9290. putPaddrLow(dmabuf->phys);
  9291. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9292. putPaddrHigh(dmabuf->phys);
  9293. }
  9294. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9295. /* The IOCTL status is embedded in the mailbox subheader. */
  9296. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9297. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9298. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9299. if (shdr_status || shdr_add_status || rc) {
  9300. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9301. "2504 RQ_CREATE mailbox failed with "
  9302. "status x%x add_status x%x, mbx status x%x\n",
  9303. shdr_status, shdr_add_status, rc);
  9304. status = -ENXIO;
  9305. goto out;
  9306. }
  9307. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9308. if (hrq->queue_id == 0xFFFF) {
  9309. status = -ENXIO;
  9310. goto out;
  9311. }
  9312. hrq->type = LPFC_HRQ;
  9313. hrq->subtype = subtype;
  9314. hrq->host_index = 0;
  9315. hrq->hba_index = 0;
  9316. /* now create the data queue */
  9317. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9318. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9319. length, LPFC_SLI4_MBX_EMBED);
  9320. switch (drq->entry_count) {
  9321. default:
  9322. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9323. "2536 Unsupported RQ count. (%d)\n",
  9324. drq->entry_count);
  9325. if (drq->entry_count < 512)
  9326. return -EINVAL;
  9327. /* otherwise default to smallest count (drop through) */
  9328. case 512:
  9329. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9330. LPFC_RQ_RING_SIZE_512);
  9331. break;
  9332. case 1024:
  9333. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9334. LPFC_RQ_RING_SIZE_1024);
  9335. break;
  9336. case 2048:
  9337. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9338. LPFC_RQ_RING_SIZE_2048);
  9339. break;
  9340. case 4096:
  9341. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9342. LPFC_RQ_RING_SIZE_4096);
  9343. break;
  9344. }
  9345. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9346. cq->queue_id);
  9347. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9348. drq->page_count);
  9349. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9350. LPFC_DATA_BUF_SIZE);
  9351. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9352. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9353. putPaddrLow(dmabuf->phys);
  9354. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9355. putPaddrHigh(dmabuf->phys);
  9356. }
  9357. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9358. /* The IOCTL status is embedded in the mailbox subheader. */
  9359. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9360. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9361. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9362. if (shdr_status || shdr_add_status || rc) {
  9363. status = -ENXIO;
  9364. goto out;
  9365. }
  9366. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9367. if (drq->queue_id == 0xFFFF) {
  9368. status = -ENXIO;
  9369. goto out;
  9370. }
  9371. drq->type = LPFC_DRQ;
  9372. drq->subtype = subtype;
  9373. drq->host_index = 0;
  9374. drq->hba_index = 0;
  9375. /* link the header and data RQs onto the parent cq child list */
  9376. list_add_tail(&hrq->list, &cq->child_list);
  9377. list_add_tail(&drq->list, &cq->child_list);
  9378. out:
  9379. mempool_free(mbox, phba->mbox_mem_pool);
  9380. return status;
  9381. }
  9382. /**
  9383. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9384. * @eq: The queue structure associated with the queue to destroy.
  9385. *
  9386. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9387. * command, specific to the type of queue, to the HBA.
  9388. *
  9389. * The @eq struct is used to get the queue ID of the queue to destroy.
  9390. *
  9391. * On success this function will return a zero. If the queue destroy mailbox
  9392. * command fails this function will return ENXIO.
  9393. **/
  9394. uint32_t
  9395. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9396. {
  9397. LPFC_MBOXQ_t *mbox;
  9398. int rc, length, status = 0;
  9399. uint32_t shdr_status, shdr_add_status;
  9400. union lpfc_sli4_cfg_shdr *shdr;
  9401. if (!eq)
  9402. return -ENODEV;
  9403. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9404. if (!mbox)
  9405. return -ENOMEM;
  9406. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9407. sizeof(struct lpfc_sli4_cfg_mhdr));
  9408. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9409. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9410. length, LPFC_SLI4_MBX_EMBED);
  9411. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9412. eq->queue_id);
  9413. mbox->vport = eq->phba->pport;
  9414. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9415. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9416. /* The IOCTL status is embedded in the mailbox subheader. */
  9417. shdr = (union lpfc_sli4_cfg_shdr *)
  9418. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9419. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9420. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9421. if (shdr_status || shdr_add_status || rc) {
  9422. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9423. "2505 EQ_DESTROY mailbox failed with "
  9424. "status x%x add_status x%x, mbx status x%x\n",
  9425. shdr_status, shdr_add_status, rc);
  9426. status = -ENXIO;
  9427. }
  9428. /* Remove eq from any list */
  9429. list_del_init(&eq->list);
  9430. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9431. return status;
  9432. }
  9433. /**
  9434. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9435. * @cq: The queue structure associated with the queue to destroy.
  9436. *
  9437. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9438. * command, specific to the type of queue, to the HBA.
  9439. *
  9440. * The @cq struct is used to get the queue ID of the queue to destroy.
  9441. *
  9442. * On success this function will return a zero. If the queue destroy mailbox
  9443. * command fails this function will return ENXIO.
  9444. **/
  9445. uint32_t
  9446. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9447. {
  9448. LPFC_MBOXQ_t *mbox;
  9449. int rc, length, status = 0;
  9450. uint32_t shdr_status, shdr_add_status;
  9451. union lpfc_sli4_cfg_shdr *shdr;
  9452. if (!cq)
  9453. return -ENODEV;
  9454. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9455. if (!mbox)
  9456. return -ENOMEM;
  9457. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9458. sizeof(struct lpfc_sli4_cfg_mhdr));
  9459. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9460. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9461. length, LPFC_SLI4_MBX_EMBED);
  9462. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9463. cq->queue_id);
  9464. mbox->vport = cq->phba->pport;
  9465. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9466. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9467. /* The IOCTL status is embedded in the mailbox subheader. */
  9468. shdr = (union lpfc_sli4_cfg_shdr *)
  9469. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9470. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9471. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9472. if (shdr_status || shdr_add_status || rc) {
  9473. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9474. "2506 CQ_DESTROY mailbox failed with "
  9475. "status x%x add_status x%x, mbx status x%x\n",
  9476. shdr_status, shdr_add_status, rc);
  9477. status = -ENXIO;
  9478. }
  9479. /* Remove cq from any list */
  9480. list_del_init(&cq->list);
  9481. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9482. return status;
  9483. }
  9484. /**
  9485. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9486. * @qm: The queue structure associated with the queue to destroy.
  9487. *
  9488. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9489. * command, specific to the type of queue, to the HBA.
  9490. *
  9491. * The @mq struct is used to get the queue ID of the queue to destroy.
  9492. *
  9493. * On success this function will return a zero. If the queue destroy mailbox
  9494. * command fails this function will return ENXIO.
  9495. **/
  9496. uint32_t
  9497. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9498. {
  9499. LPFC_MBOXQ_t *mbox;
  9500. int rc, length, status = 0;
  9501. uint32_t shdr_status, shdr_add_status;
  9502. union lpfc_sli4_cfg_shdr *shdr;
  9503. if (!mq)
  9504. return -ENODEV;
  9505. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9506. if (!mbox)
  9507. return -ENOMEM;
  9508. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9509. sizeof(struct lpfc_sli4_cfg_mhdr));
  9510. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9511. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9512. length, LPFC_SLI4_MBX_EMBED);
  9513. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9514. mq->queue_id);
  9515. mbox->vport = mq->phba->pport;
  9516. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9517. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9518. /* The IOCTL status is embedded in the mailbox subheader. */
  9519. shdr = (union lpfc_sli4_cfg_shdr *)
  9520. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9521. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9522. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9523. if (shdr_status || shdr_add_status || rc) {
  9524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9525. "2507 MQ_DESTROY mailbox failed with "
  9526. "status x%x add_status x%x, mbx status x%x\n",
  9527. shdr_status, shdr_add_status, rc);
  9528. status = -ENXIO;
  9529. }
  9530. /* Remove mq from any list */
  9531. list_del_init(&mq->list);
  9532. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9533. return status;
  9534. }
  9535. /**
  9536. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9537. * @wq: The queue structure associated with the queue to destroy.
  9538. *
  9539. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9540. * command, specific to the type of queue, to the HBA.
  9541. *
  9542. * The @wq struct is used to get the queue ID of the queue to destroy.
  9543. *
  9544. * On success this function will return a zero. If the queue destroy mailbox
  9545. * command fails this function will return ENXIO.
  9546. **/
  9547. uint32_t
  9548. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9549. {
  9550. LPFC_MBOXQ_t *mbox;
  9551. int rc, length, status = 0;
  9552. uint32_t shdr_status, shdr_add_status;
  9553. union lpfc_sli4_cfg_shdr *shdr;
  9554. if (!wq)
  9555. return -ENODEV;
  9556. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9557. if (!mbox)
  9558. return -ENOMEM;
  9559. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9560. sizeof(struct lpfc_sli4_cfg_mhdr));
  9561. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9562. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9563. length, LPFC_SLI4_MBX_EMBED);
  9564. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9565. wq->queue_id);
  9566. mbox->vport = wq->phba->pport;
  9567. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9568. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9569. shdr = (union lpfc_sli4_cfg_shdr *)
  9570. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9571. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9572. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9573. if (shdr_status || shdr_add_status || rc) {
  9574. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9575. "2508 WQ_DESTROY mailbox failed with "
  9576. "status x%x add_status x%x, mbx status x%x\n",
  9577. shdr_status, shdr_add_status, rc);
  9578. status = -ENXIO;
  9579. }
  9580. /* Remove wq from any list */
  9581. list_del_init(&wq->list);
  9582. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9583. return status;
  9584. }
  9585. /**
  9586. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9587. * @rq: The queue structure associated with the queue to destroy.
  9588. *
  9589. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9590. * command, specific to the type of queue, to the HBA.
  9591. *
  9592. * The @rq struct is used to get the queue ID of the queue to destroy.
  9593. *
  9594. * On success this function will return a zero. If the queue destroy mailbox
  9595. * command fails this function will return ENXIO.
  9596. **/
  9597. uint32_t
  9598. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9599. struct lpfc_queue *drq)
  9600. {
  9601. LPFC_MBOXQ_t *mbox;
  9602. int rc, length, status = 0;
  9603. uint32_t shdr_status, shdr_add_status;
  9604. union lpfc_sli4_cfg_shdr *shdr;
  9605. if (!hrq || !drq)
  9606. return -ENODEV;
  9607. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9608. if (!mbox)
  9609. return -ENOMEM;
  9610. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9611. sizeof(struct mbox_header));
  9612. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9613. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9614. length, LPFC_SLI4_MBX_EMBED);
  9615. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9616. hrq->queue_id);
  9617. mbox->vport = hrq->phba->pport;
  9618. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9619. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9620. /* The IOCTL status is embedded in the mailbox subheader. */
  9621. shdr = (union lpfc_sli4_cfg_shdr *)
  9622. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9623. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9624. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9625. if (shdr_status || shdr_add_status || rc) {
  9626. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9627. "2509 RQ_DESTROY mailbox failed with "
  9628. "status x%x add_status x%x, mbx status x%x\n",
  9629. shdr_status, shdr_add_status, rc);
  9630. if (rc != MBX_TIMEOUT)
  9631. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9632. return -ENXIO;
  9633. }
  9634. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9635. drq->queue_id);
  9636. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9637. shdr = (union lpfc_sli4_cfg_shdr *)
  9638. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9639. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9640. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9641. if (shdr_status || shdr_add_status || rc) {
  9642. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9643. "2510 RQ_DESTROY mailbox failed with "
  9644. "status x%x add_status x%x, mbx status x%x\n",
  9645. shdr_status, shdr_add_status, rc);
  9646. status = -ENXIO;
  9647. }
  9648. list_del_init(&hrq->list);
  9649. list_del_init(&drq->list);
  9650. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9651. return status;
  9652. }
  9653. /**
  9654. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9655. * @phba: The virtual port for which this call being executed.
  9656. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9657. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9658. * @xritag: the xritag that ties this io to the SGL pages.
  9659. *
  9660. * This routine will post the sgl pages for the IO that has the xritag
  9661. * that is in the iocbq structure. The xritag is assigned during iocbq
  9662. * creation and persists for as long as the driver is loaded.
  9663. * if the caller has fewer than 256 scatter gather segments to map then
  9664. * pdma_phys_addr1 should be 0.
  9665. * If the caller needs to map more than 256 scatter gather segment then
  9666. * pdma_phys_addr1 should be a valid physical address.
  9667. * physical address for SGLs must be 64 byte aligned.
  9668. * If you are going to map 2 SGL's then the first one must have 256 entries
  9669. * the second sgl can have between 1 and 256 entries.
  9670. *
  9671. * Return codes:
  9672. * 0 - Success
  9673. * -ENXIO, -ENOMEM - Failure
  9674. **/
  9675. int
  9676. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9677. dma_addr_t pdma_phys_addr0,
  9678. dma_addr_t pdma_phys_addr1,
  9679. uint16_t xritag)
  9680. {
  9681. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9682. LPFC_MBOXQ_t *mbox;
  9683. int rc;
  9684. uint32_t shdr_status, shdr_add_status;
  9685. union lpfc_sli4_cfg_shdr *shdr;
  9686. if (xritag == NO_XRI) {
  9687. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9688. "0364 Invalid param:\n");
  9689. return -EINVAL;
  9690. }
  9691. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9692. if (!mbox)
  9693. return -ENOMEM;
  9694. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9695. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9696. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9697. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9698. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9699. &mbox->u.mqe.un.post_sgl_pages;
  9700. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9701. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9702. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9703. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9704. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9705. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9706. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9707. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9708. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9709. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9710. if (!phba->sli4_hba.intr_enable)
  9711. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9712. else
  9713. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9714. /* The IOCTL status is embedded in the mailbox subheader. */
  9715. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9716. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9717. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9718. if (rc != MBX_TIMEOUT)
  9719. mempool_free(mbox, phba->mbox_mem_pool);
  9720. if (shdr_status || shdr_add_status || rc) {
  9721. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9722. "2511 POST_SGL mailbox failed with "
  9723. "status x%x add_status x%x, mbx status x%x\n",
  9724. shdr_status, shdr_add_status, rc);
  9725. rc = -ENXIO;
  9726. }
  9727. return 0;
  9728. }
  9729. /**
  9730. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9731. * @phba: The virtual port for which this call being executed.
  9732. *
  9733. * This routine will remove all of the sgl pages registered with the hba.
  9734. *
  9735. * Return codes:
  9736. * 0 - Success
  9737. * -ENXIO, -ENOMEM - Failure
  9738. **/
  9739. int
  9740. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9741. {
  9742. LPFC_MBOXQ_t *mbox;
  9743. int rc;
  9744. uint32_t shdr_status, shdr_add_status;
  9745. union lpfc_sli4_cfg_shdr *shdr;
  9746. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9747. if (!mbox)
  9748. return -ENOMEM;
  9749. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9750. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9751. LPFC_SLI4_MBX_EMBED);
  9752. if (!phba->sli4_hba.intr_enable)
  9753. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9754. else
  9755. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9756. /* The IOCTL status is embedded in the mailbox subheader. */
  9757. shdr = (union lpfc_sli4_cfg_shdr *)
  9758. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9759. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9760. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9761. if (rc != MBX_TIMEOUT)
  9762. mempool_free(mbox, phba->mbox_mem_pool);
  9763. if (shdr_status || shdr_add_status || rc) {
  9764. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9765. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9766. "status x%x add_status x%x, mbx status x%x\n",
  9767. shdr_status, shdr_add_status, rc);
  9768. rc = -ENXIO;
  9769. }
  9770. return rc;
  9771. }
  9772. /**
  9773. * lpfc_sli4_next_xritag - Get an xritag for the io
  9774. * @phba: Pointer to HBA context object.
  9775. *
  9776. * This function gets an xritag for the iocb. If there is no unused xritag
  9777. * it will return 0xffff.
  9778. * The function returns the allocated xritag if successful, else returns zero.
  9779. * Zero is not a valid xritag.
  9780. * The caller is not required to hold any lock.
  9781. **/
  9782. uint16_t
  9783. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9784. {
  9785. uint16_t xritag;
  9786. spin_lock_irq(&phba->hbalock);
  9787. xritag = phba->sli4_hba.next_xri;
  9788. if ((xritag != (uint16_t) -1) && xritag <
  9789. (phba->sli4_hba.max_cfg_param.max_xri
  9790. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9791. phba->sli4_hba.next_xri++;
  9792. phba->sli4_hba.max_cfg_param.xri_used++;
  9793. spin_unlock_irq(&phba->hbalock);
  9794. return xritag;
  9795. }
  9796. spin_unlock_irq(&phba->hbalock);
  9797. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9798. "2004 Failed to allocate XRI.last XRITAG is %d"
  9799. " Max XRI is %d, Used XRI is %d\n",
  9800. phba->sli4_hba.next_xri,
  9801. phba->sli4_hba.max_cfg_param.max_xri,
  9802. phba->sli4_hba.max_cfg_param.xri_used);
  9803. return -1;
  9804. }
  9805. /**
  9806. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9807. * @phba: pointer to lpfc hba data structure.
  9808. *
  9809. * This routine is invoked to post a block of driver's sgl pages to the
  9810. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9811. * is only called when the driver is loading and after all IO has been
  9812. * stopped.
  9813. **/
  9814. int
  9815. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9816. {
  9817. struct lpfc_sglq *sglq_entry;
  9818. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9819. struct sgl_page_pairs *sgl_pg_pairs;
  9820. void *viraddr;
  9821. LPFC_MBOXQ_t *mbox;
  9822. uint32_t reqlen, alloclen, pg_pairs;
  9823. uint32_t mbox_tmo;
  9824. uint16_t xritag_start = 0;
  9825. int els_xri_cnt, rc = 0;
  9826. uint32_t shdr_status, shdr_add_status;
  9827. union lpfc_sli4_cfg_shdr *shdr;
  9828. /* The number of sgls to be posted */
  9829. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9830. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9831. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9832. if (reqlen > SLI4_PAGE_SIZE) {
  9833. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9834. "2559 Block sgl registration required DMA "
  9835. "size (%d) great than a page\n", reqlen);
  9836. return -ENOMEM;
  9837. }
  9838. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9839. if (!mbox) {
  9840. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9841. "2560 Failed to allocate mbox cmd memory\n");
  9842. return -ENOMEM;
  9843. }
  9844. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9845. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9846. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9847. LPFC_SLI4_MBX_NEMBED);
  9848. if (alloclen < reqlen) {
  9849. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9850. "0285 Allocated DMA memory size (%d) is "
  9851. "less than the requested DMA memory "
  9852. "size (%d)\n", alloclen, reqlen);
  9853. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9854. return -ENOMEM;
  9855. }
  9856. /* Get the first SGE entry from the non-embedded DMA memory */
  9857. viraddr = mbox->sge_array->addr[0];
  9858. /* Set up the SGL pages in the non-embedded DMA pages */
  9859. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9860. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9861. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9862. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9863. /* Set up the sge entry */
  9864. sgl_pg_pairs->sgl_pg0_addr_lo =
  9865. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9866. sgl_pg_pairs->sgl_pg0_addr_hi =
  9867. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9868. sgl_pg_pairs->sgl_pg1_addr_lo =
  9869. cpu_to_le32(putPaddrLow(0));
  9870. sgl_pg_pairs->sgl_pg1_addr_hi =
  9871. cpu_to_le32(putPaddrHigh(0));
  9872. /* Keep the first xritag on the list */
  9873. if (pg_pairs == 0)
  9874. xritag_start = sglq_entry->sli4_xritag;
  9875. sgl_pg_pairs++;
  9876. }
  9877. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9878. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9879. /* Perform endian conversion if necessary */
  9880. sgl->word0 = cpu_to_le32(sgl->word0);
  9881. if (!phba->sli4_hba.intr_enable)
  9882. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9883. else {
  9884. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9885. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9886. }
  9887. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9888. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9889. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9890. if (rc != MBX_TIMEOUT)
  9891. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9892. if (shdr_status || shdr_add_status || rc) {
  9893. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9894. "2513 POST_SGL_BLOCK mailbox command failed "
  9895. "status x%x add_status x%x mbx status x%x\n",
  9896. shdr_status, shdr_add_status, rc);
  9897. rc = -ENXIO;
  9898. }
  9899. return rc;
  9900. }
  9901. /**
  9902. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9903. * @phba: pointer to lpfc hba data structure.
  9904. * @sblist: pointer to scsi buffer list.
  9905. * @count: number of scsi buffers on the list.
  9906. *
  9907. * This routine is invoked to post a block of @count scsi sgl pages from a
  9908. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9909. * No Lock is held.
  9910. *
  9911. **/
  9912. int
  9913. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9914. int cnt)
  9915. {
  9916. struct lpfc_scsi_buf *psb;
  9917. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9918. struct sgl_page_pairs *sgl_pg_pairs;
  9919. void *viraddr;
  9920. LPFC_MBOXQ_t *mbox;
  9921. uint32_t reqlen, alloclen, pg_pairs;
  9922. uint32_t mbox_tmo;
  9923. uint16_t xritag_start = 0;
  9924. int rc = 0;
  9925. uint32_t shdr_status, shdr_add_status;
  9926. dma_addr_t pdma_phys_bpl1;
  9927. union lpfc_sli4_cfg_shdr *shdr;
  9928. /* Calculate the requested length of the dma memory */
  9929. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9930. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9931. if (reqlen > SLI4_PAGE_SIZE) {
  9932. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9933. "0217 Block sgl registration required DMA "
  9934. "size (%d) great than a page\n", reqlen);
  9935. return -ENOMEM;
  9936. }
  9937. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9938. if (!mbox) {
  9939. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9940. "0283 Failed to allocate mbox cmd memory\n");
  9941. return -ENOMEM;
  9942. }
  9943. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9944. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9945. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9946. LPFC_SLI4_MBX_NEMBED);
  9947. if (alloclen < reqlen) {
  9948. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9949. "2561 Allocated DMA memory size (%d) is "
  9950. "less than the requested DMA memory "
  9951. "size (%d)\n", alloclen, reqlen);
  9952. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9953. return -ENOMEM;
  9954. }
  9955. /* Get the first SGE entry from the non-embedded DMA memory */
  9956. viraddr = mbox->sge_array->addr[0];
  9957. /* Set up the SGL pages in the non-embedded DMA pages */
  9958. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9959. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9960. pg_pairs = 0;
  9961. list_for_each_entry(psb, sblist, list) {
  9962. /* Set up the sge entry */
  9963. sgl_pg_pairs->sgl_pg0_addr_lo =
  9964. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9965. sgl_pg_pairs->sgl_pg0_addr_hi =
  9966. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9967. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9968. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9969. else
  9970. pdma_phys_bpl1 = 0;
  9971. sgl_pg_pairs->sgl_pg1_addr_lo =
  9972. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9973. sgl_pg_pairs->sgl_pg1_addr_hi =
  9974. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9975. /* Keep the first xritag on the list */
  9976. if (pg_pairs == 0)
  9977. xritag_start = psb->cur_iocbq.sli4_xritag;
  9978. sgl_pg_pairs++;
  9979. pg_pairs++;
  9980. }
  9981. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9982. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9983. /* Perform endian conversion if necessary */
  9984. sgl->word0 = cpu_to_le32(sgl->word0);
  9985. if (!phba->sli4_hba.intr_enable)
  9986. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9987. else {
  9988. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9989. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9990. }
  9991. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9992. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9993. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9994. if (rc != MBX_TIMEOUT)
  9995. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9996. if (shdr_status || shdr_add_status || rc) {
  9997. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9998. "2564 POST_SGL_BLOCK mailbox command failed "
  9999. "status x%x add_status x%x mbx status x%x\n",
  10000. shdr_status, shdr_add_status, rc);
  10001. rc = -ENXIO;
  10002. }
  10003. return rc;
  10004. }
  10005. /**
  10006. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10007. * @phba: pointer to lpfc_hba struct that the frame was received on
  10008. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10009. *
  10010. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10011. * valid type of frame that the LPFC driver will handle. This function will
  10012. * return a zero if the frame is a valid frame or a non zero value when the
  10013. * frame does not pass the check.
  10014. **/
  10015. static int
  10016. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10017. {
  10018. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10019. char *type_names[] = FC_TYPE_NAMES_INIT;
  10020. struct fc_vft_header *fc_vft_hdr;
  10021. switch (fc_hdr->fh_r_ctl) {
  10022. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10023. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10024. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10025. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10026. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10027. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10028. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10029. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10030. case FC_RCTL_ELS_REQ: /* extended link services request */
  10031. case FC_RCTL_ELS_REP: /* extended link services reply */
  10032. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10033. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10034. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10035. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10036. case FC_RCTL_BA_RMC: /* remove connection */
  10037. case FC_RCTL_BA_ACC: /* basic accept */
  10038. case FC_RCTL_BA_RJT: /* basic reject */
  10039. case FC_RCTL_BA_PRMT:
  10040. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10041. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10042. case FC_RCTL_P_RJT: /* port reject */
  10043. case FC_RCTL_F_RJT: /* fabric reject */
  10044. case FC_RCTL_P_BSY: /* port busy */
  10045. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10046. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10047. case FC_RCTL_LCR: /* link credit reset */
  10048. case FC_RCTL_END: /* end */
  10049. break;
  10050. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10051. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10052. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10053. return lpfc_fc_frame_check(phba, fc_hdr);
  10054. default:
  10055. goto drop;
  10056. }
  10057. switch (fc_hdr->fh_type) {
  10058. case FC_TYPE_BLS:
  10059. case FC_TYPE_ELS:
  10060. case FC_TYPE_FCP:
  10061. case FC_TYPE_CT:
  10062. break;
  10063. case FC_TYPE_IP:
  10064. case FC_TYPE_ILS:
  10065. default:
  10066. goto drop;
  10067. }
  10068. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10069. "2538 Received frame rctl:%s type:%s\n",
  10070. rctl_names[fc_hdr->fh_r_ctl],
  10071. type_names[fc_hdr->fh_type]);
  10072. return 0;
  10073. drop:
  10074. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10075. "2539 Dropped frame rctl:%s type:%s\n",
  10076. rctl_names[fc_hdr->fh_r_ctl],
  10077. type_names[fc_hdr->fh_type]);
  10078. return 1;
  10079. }
  10080. /**
  10081. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10082. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10083. *
  10084. * This function processes the FC header to retrieve the VFI from the VF
  10085. * header, if one exists. This function will return the VFI if one exists
  10086. * or 0 if no VSAN Header exists.
  10087. **/
  10088. static uint32_t
  10089. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10090. {
  10091. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10092. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10093. return 0;
  10094. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10095. }
  10096. /**
  10097. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10098. * @phba: Pointer to the HBA structure to search for the vport on
  10099. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10100. * @fcfi: The FC Fabric ID that the frame came from
  10101. *
  10102. * This function searches the @phba for a vport that matches the content of the
  10103. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10104. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10105. * returns the matching vport pointer or NULL if unable to match frame to a
  10106. * vport.
  10107. **/
  10108. static struct lpfc_vport *
  10109. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10110. uint16_t fcfi)
  10111. {
  10112. struct lpfc_vport **vports;
  10113. struct lpfc_vport *vport = NULL;
  10114. int i;
  10115. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10116. fc_hdr->fh_d_id[1] << 8 |
  10117. fc_hdr->fh_d_id[2]);
  10118. vports = lpfc_create_vport_work_array(phba);
  10119. if (vports != NULL)
  10120. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10121. if (phba->fcf.fcfi == fcfi &&
  10122. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10123. vports[i]->fc_myDID == did) {
  10124. vport = vports[i];
  10125. break;
  10126. }
  10127. }
  10128. lpfc_destroy_vport_work_array(phba, vports);
  10129. return vport;
  10130. }
  10131. /**
  10132. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10133. * @vport: The vport to work on.
  10134. *
  10135. * This function updates the receive sequence time stamp for this vport. The
  10136. * receive sequence time stamp indicates the time that the last frame of the
  10137. * the sequence that has been idle for the longest amount of time was received.
  10138. * the driver uses this time stamp to indicate if any received sequences have
  10139. * timed out.
  10140. **/
  10141. void
  10142. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10143. {
  10144. struct lpfc_dmabuf *h_buf;
  10145. struct hbq_dmabuf *dmabuf = NULL;
  10146. /* get the oldest sequence on the rcv list */
  10147. h_buf = list_get_first(&vport->rcv_buffer_list,
  10148. struct lpfc_dmabuf, list);
  10149. if (!h_buf)
  10150. return;
  10151. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10152. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10153. }
  10154. /**
  10155. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10156. * @vport: The vport that the received sequences were sent to.
  10157. *
  10158. * This function cleans up all outstanding received sequences. This is called
  10159. * by the driver when a link event or user action invalidates all the received
  10160. * sequences.
  10161. **/
  10162. void
  10163. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10164. {
  10165. struct lpfc_dmabuf *h_buf, *hnext;
  10166. struct lpfc_dmabuf *d_buf, *dnext;
  10167. struct hbq_dmabuf *dmabuf = NULL;
  10168. /* start with the oldest sequence on the rcv list */
  10169. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10170. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10171. list_del_init(&dmabuf->hbuf.list);
  10172. list_for_each_entry_safe(d_buf, dnext,
  10173. &dmabuf->dbuf.list, list) {
  10174. list_del_init(&d_buf->list);
  10175. lpfc_in_buf_free(vport->phba, d_buf);
  10176. }
  10177. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10178. }
  10179. }
  10180. /**
  10181. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10182. * @vport: The vport that the received sequences were sent to.
  10183. *
  10184. * This function determines whether any received sequences have timed out by
  10185. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10186. * indicates that there is at least one timed out sequence this routine will
  10187. * go through the received sequences one at a time from most inactive to most
  10188. * active to determine which ones need to be cleaned up. Once it has determined
  10189. * that a sequence needs to be cleaned up it will simply free up the resources
  10190. * without sending an abort.
  10191. **/
  10192. void
  10193. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10194. {
  10195. struct lpfc_dmabuf *h_buf, *hnext;
  10196. struct lpfc_dmabuf *d_buf, *dnext;
  10197. struct hbq_dmabuf *dmabuf = NULL;
  10198. unsigned long timeout;
  10199. int abort_count = 0;
  10200. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10201. vport->rcv_buffer_time_stamp);
  10202. if (list_empty(&vport->rcv_buffer_list) ||
  10203. time_before(jiffies, timeout))
  10204. return;
  10205. /* start with the oldest sequence on the rcv list */
  10206. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10207. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10208. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10209. dmabuf->time_stamp);
  10210. if (time_before(jiffies, timeout))
  10211. break;
  10212. abort_count++;
  10213. list_del_init(&dmabuf->hbuf.list);
  10214. list_for_each_entry_safe(d_buf, dnext,
  10215. &dmabuf->dbuf.list, list) {
  10216. list_del_init(&d_buf->list);
  10217. lpfc_in_buf_free(vport->phba, d_buf);
  10218. }
  10219. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10220. }
  10221. if (abort_count)
  10222. lpfc_update_rcv_time_stamp(vport);
  10223. }
  10224. /**
  10225. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10226. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10227. *
  10228. * This function searches through the existing incomplete sequences that have
  10229. * been sent to this @vport. If the frame matches one of the incomplete
  10230. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10231. * make up that sequence. If no sequence is found that matches this frame then
  10232. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10233. * This function returns a pointer to the first dmabuf in the sequence list that
  10234. * the frame was linked to.
  10235. **/
  10236. static struct hbq_dmabuf *
  10237. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10238. {
  10239. struct fc_frame_header *new_hdr;
  10240. struct fc_frame_header *temp_hdr;
  10241. struct lpfc_dmabuf *d_buf;
  10242. struct lpfc_dmabuf *h_buf;
  10243. struct hbq_dmabuf *seq_dmabuf = NULL;
  10244. struct hbq_dmabuf *temp_dmabuf = NULL;
  10245. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10246. dmabuf->time_stamp = jiffies;
  10247. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10248. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10249. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10250. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10251. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10252. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10253. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10254. continue;
  10255. /* found a pending sequence that matches this frame */
  10256. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10257. break;
  10258. }
  10259. if (!seq_dmabuf) {
  10260. /*
  10261. * This indicates first frame received for this sequence.
  10262. * Queue the buffer on the vport's rcv_buffer_list.
  10263. */
  10264. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10265. lpfc_update_rcv_time_stamp(vport);
  10266. return dmabuf;
  10267. }
  10268. temp_hdr = seq_dmabuf->hbuf.virt;
  10269. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10270. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10271. list_del_init(&seq_dmabuf->hbuf.list);
  10272. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10273. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10274. lpfc_update_rcv_time_stamp(vport);
  10275. return dmabuf;
  10276. }
  10277. /* move this sequence to the tail to indicate a young sequence */
  10278. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10279. seq_dmabuf->time_stamp = jiffies;
  10280. lpfc_update_rcv_time_stamp(vport);
  10281. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10282. temp_hdr = dmabuf->hbuf.virt;
  10283. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10284. return seq_dmabuf;
  10285. }
  10286. /* find the correct place in the sequence to insert this frame */
  10287. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10288. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10289. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10290. /*
  10291. * If the frame's sequence count is greater than the frame on
  10292. * the list then insert the frame right after this frame
  10293. */
  10294. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10295. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10296. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10297. return seq_dmabuf;
  10298. }
  10299. }
  10300. return NULL;
  10301. }
  10302. /**
  10303. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10304. * @vport: pointer to a vitural port
  10305. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10306. *
  10307. * This function tries to abort from the partially assembed sequence, described
  10308. * by the information from basic abbort @dmabuf. It checks to see whether such
  10309. * partially assembled sequence held by the driver. If so, it shall free up all
  10310. * the frames from the partially assembled sequence.
  10311. *
  10312. * Return
  10313. * true -- if there is matching partially assembled sequence present and all
  10314. * the frames freed with the sequence;
  10315. * false -- if there is no matching partially assembled sequence present so
  10316. * nothing got aborted in the lower layer driver
  10317. **/
  10318. static bool
  10319. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10320. struct hbq_dmabuf *dmabuf)
  10321. {
  10322. struct fc_frame_header *new_hdr;
  10323. struct fc_frame_header *temp_hdr;
  10324. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10325. struct hbq_dmabuf *seq_dmabuf = NULL;
  10326. /* Use the hdr_buf to find the sequence that matches this frame */
  10327. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10328. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10329. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10330. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10331. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10332. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10333. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10334. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10335. continue;
  10336. /* found a pending sequence that matches this frame */
  10337. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10338. break;
  10339. }
  10340. /* Free up all the frames from the partially assembled sequence */
  10341. if (seq_dmabuf) {
  10342. list_for_each_entry_safe(d_buf, n_buf,
  10343. &seq_dmabuf->dbuf.list, list) {
  10344. list_del_init(&d_buf->list);
  10345. lpfc_in_buf_free(vport->phba, d_buf);
  10346. }
  10347. return true;
  10348. }
  10349. return false;
  10350. }
  10351. /**
  10352. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10353. * @phba: Pointer to HBA context object.
  10354. * @cmd_iocbq: pointer to the command iocbq structure.
  10355. * @rsp_iocbq: pointer to the response iocbq structure.
  10356. *
  10357. * This function handles the sequence abort accept iocb command complete
  10358. * event. It properly releases the memory allocated to the sequence abort
  10359. * accept iocb.
  10360. **/
  10361. static void
  10362. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10363. struct lpfc_iocbq *cmd_iocbq,
  10364. struct lpfc_iocbq *rsp_iocbq)
  10365. {
  10366. if (cmd_iocbq)
  10367. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10368. }
  10369. /**
  10370. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10371. * @phba: Pointer to HBA context object.
  10372. * @fc_hdr: pointer to a FC frame header.
  10373. *
  10374. * This function sends a basic accept to a previous unsol sequence abort
  10375. * event after aborting the sequence handling.
  10376. **/
  10377. static void
  10378. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10379. struct fc_frame_header *fc_hdr)
  10380. {
  10381. struct lpfc_iocbq *ctiocb = NULL;
  10382. struct lpfc_nodelist *ndlp;
  10383. uint16_t oxid, rxid;
  10384. uint32_t sid, fctl;
  10385. IOCB_t *icmd;
  10386. if (!lpfc_is_link_up(phba))
  10387. return;
  10388. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10389. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10390. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10391. ndlp = lpfc_findnode_did(phba->pport, sid);
  10392. if (!ndlp) {
  10393. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10394. "1268 Find ndlp returned NULL for oxid:x%x "
  10395. "SID:x%x\n", oxid, sid);
  10396. return;
  10397. }
  10398. /* Allocate buffer for acc iocb */
  10399. ctiocb = lpfc_sli_get_iocbq(phba);
  10400. if (!ctiocb)
  10401. return;
  10402. /* Extract the F_CTL field from FC_HDR */
  10403. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10404. icmd = &ctiocb->iocb;
  10405. icmd->un.xseq64.bdl.bdeSize = 0;
  10406. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10407. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10408. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10409. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10410. /* Fill in the rest of iocb fields */
  10411. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10412. icmd->ulpBdeCount = 0;
  10413. icmd->ulpLe = 1;
  10414. icmd->ulpClass = CLASS3;
  10415. icmd->ulpContext = ndlp->nlp_rpi;
  10416. ctiocb->iocb_cmpl = NULL;
  10417. ctiocb->vport = phba->pport;
  10418. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10419. if (fctl & FC_FC_EX_CTX) {
  10420. /* ABTS sent by responder to CT exchange, construction
  10421. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10422. * field and RX_ID from ABTS for RX_ID field.
  10423. */
  10424. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10425. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10426. ctiocb->sli4_xritag = oxid;
  10427. } else {
  10428. /* ABTS sent by initiator to CT exchange, construction
  10429. * of BA_ACC will need to allocate a new XRI as for the
  10430. * XRI_TAG and RX_ID fields.
  10431. */
  10432. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10433. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10434. ctiocb->sli4_xritag = NO_XRI;
  10435. }
  10436. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10437. /* Xmit CT abts accept on exchange <xid> */
  10438. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10439. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10440. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10441. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10442. }
  10443. /**
  10444. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10445. * @vport: Pointer to the vport on which this sequence was received
  10446. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10447. *
  10448. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10449. * receive sequence is only partially assembed by the driver, it shall abort
  10450. * the partially assembled frames for the sequence. Otherwise, if the
  10451. * unsolicited receive sequence has been completely assembled and passed to
  10452. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10453. * unsolicited sequence has been aborted. After that, it will issue a basic
  10454. * accept to accept the abort.
  10455. **/
  10456. void
  10457. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10458. struct hbq_dmabuf *dmabuf)
  10459. {
  10460. struct lpfc_hba *phba = vport->phba;
  10461. struct fc_frame_header fc_hdr;
  10462. uint32_t fctl;
  10463. bool abts_par;
  10464. /* Make a copy of fc_hdr before the dmabuf being released */
  10465. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10466. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10467. if (fctl & FC_FC_EX_CTX) {
  10468. /*
  10469. * ABTS sent by responder to exchange, just free the buffer
  10470. */
  10471. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10472. } else {
  10473. /*
  10474. * ABTS sent by initiator to exchange, need to do cleanup
  10475. */
  10476. /* Try to abort partially assembled seq */
  10477. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10478. /* Send abort to ULP if partially seq abort failed */
  10479. if (abts_par == false)
  10480. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10481. else
  10482. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10483. }
  10484. /* Send basic accept (BA_ACC) to the abort requester */
  10485. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10486. }
  10487. /**
  10488. * lpfc_seq_complete - Indicates if a sequence is complete
  10489. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10490. *
  10491. * This function checks the sequence, starting with the frame described by
  10492. * @dmabuf, to see if all the frames associated with this sequence are present.
  10493. * the frames associated with this sequence are linked to the @dmabuf using the
  10494. * dbuf list. This function looks for two major things. 1) That the first frame
  10495. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10496. * set. 3) That there are no holes in the sequence count. The function will
  10497. * return 1 when the sequence is complete, otherwise it will return 0.
  10498. **/
  10499. static int
  10500. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10501. {
  10502. struct fc_frame_header *hdr;
  10503. struct lpfc_dmabuf *d_buf;
  10504. struct hbq_dmabuf *seq_dmabuf;
  10505. uint32_t fctl;
  10506. int seq_count = 0;
  10507. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10508. /* make sure first fame of sequence has a sequence count of zero */
  10509. if (hdr->fh_seq_cnt != seq_count)
  10510. return 0;
  10511. fctl = (hdr->fh_f_ctl[0] << 16 |
  10512. hdr->fh_f_ctl[1] << 8 |
  10513. hdr->fh_f_ctl[2]);
  10514. /* If last frame of sequence we can return success. */
  10515. if (fctl & FC_FC_END_SEQ)
  10516. return 1;
  10517. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10518. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10519. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10520. /* If there is a hole in the sequence count then fail. */
  10521. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10522. return 0;
  10523. fctl = (hdr->fh_f_ctl[0] << 16 |
  10524. hdr->fh_f_ctl[1] << 8 |
  10525. hdr->fh_f_ctl[2]);
  10526. /* If last frame of sequence we can return success. */
  10527. if (fctl & FC_FC_END_SEQ)
  10528. return 1;
  10529. }
  10530. return 0;
  10531. }
  10532. /**
  10533. * lpfc_prep_seq - Prep sequence for ULP processing
  10534. * @vport: Pointer to the vport on which this sequence was received
  10535. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10536. *
  10537. * This function takes a sequence, described by a list of frames, and creates
  10538. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10539. * used to issue to the generic unsolicited sequence handler. This routine
  10540. * returns a pointer to the first iocbq in the list. If the function is unable
  10541. * to allocate an iocbq then it throw out the received frames that were not
  10542. * able to be described and return a pointer to the first iocbq. If unable to
  10543. * allocate any iocbqs (including the first) this function will return NULL.
  10544. **/
  10545. static struct lpfc_iocbq *
  10546. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10547. {
  10548. struct lpfc_dmabuf *d_buf, *n_buf;
  10549. struct lpfc_iocbq *first_iocbq, *iocbq;
  10550. struct fc_frame_header *fc_hdr;
  10551. uint32_t sid;
  10552. struct ulp_bde64 *pbde;
  10553. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10554. /* remove from receive buffer list */
  10555. list_del_init(&seq_dmabuf->hbuf.list);
  10556. lpfc_update_rcv_time_stamp(vport);
  10557. /* get the Remote Port's SID */
  10558. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10559. /* Get an iocbq struct to fill in. */
  10560. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10561. if (first_iocbq) {
  10562. /* Initialize the first IOCB. */
  10563. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10564. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10565. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10566. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10567. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10568. vport->vpi + vport->phba->vpi_base;
  10569. /* put the first buffer into the first IOCBq */
  10570. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10571. first_iocbq->context3 = NULL;
  10572. first_iocbq->iocb.ulpBdeCount = 1;
  10573. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10574. LPFC_DATA_BUF_SIZE;
  10575. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10576. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10577. bf_get(lpfc_rcqe_length,
  10578. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10579. }
  10580. iocbq = first_iocbq;
  10581. /*
  10582. * Each IOCBq can have two Buffers assigned, so go through the list
  10583. * of buffers for this sequence and save two buffers in each IOCBq
  10584. */
  10585. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10586. if (!iocbq) {
  10587. lpfc_in_buf_free(vport->phba, d_buf);
  10588. continue;
  10589. }
  10590. if (!iocbq->context3) {
  10591. iocbq->context3 = d_buf;
  10592. iocbq->iocb.ulpBdeCount++;
  10593. pbde = (struct ulp_bde64 *)
  10594. &iocbq->iocb.unsli3.sli3Words[4];
  10595. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10596. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10597. bf_get(lpfc_rcqe_length,
  10598. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10599. } else {
  10600. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10601. if (!iocbq) {
  10602. if (first_iocbq) {
  10603. first_iocbq->iocb.ulpStatus =
  10604. IOSTAT_FCP_RSP_ERROR;
  10605. first_iocbq->iocb.un.ulpWord[4] =
  10606. IOERR_NO_RESOURCES;
  10607. }
  10608. lpfc_in_buf_free(vport->phba, d_buf);
  10609. continue;
  10610. }
  10611. iocbq->context2 = d_buf;
  10612. iocbq->context3 = NULL;
  10613. iocbq->iocb.ulpBdeCount = 1;
  10614. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10615. LPFC_DATA_BUF_SIZE;
  10616. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10617. bf_get(lpfc_rcqe_length,
  10618. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10619. iocbq->iocb.un.rcvels.remoteID = sid;
  10620. list_add_tail(&iocbq->list, &first_iocbq->list);
  10621. }
  10622. }
  10623. return first_iocbq;
  10624. }
  10625. static void
  10626. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10627. struct hbq_dmabuf *seq_dmabuf)
  10628. {
  10629. struct fc_frame_header *fc_hdr;
  10630. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10631. struct lpfc_hba *phba = vport->phba;
  10632. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10633. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10634. if (!iocbq) {
  10635. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10636. "2707 Ring %d handler: Failed to allocate "
  10637. "iocb Rctl x%x Type x%x received\n",
  10638. LPFC_ELS_RING,
  10639. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10640. return;
  10641. }
  10642. if (!lpfc_complete_unsol_iocb(phba,
  10643. &phba->sli.ring[LPFC_ELS_RING],
  10644. iocbq, fc_hdr->fh_r_ctl,
  10645. fc_hdr->fh_type))
  10646. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10647. "2540 Ring %d handler: unexpected Rctl "
  10648. "x%x Type x%x received\n",
  10649. LPFC_ELS_RING,
  10650. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10651. /* Free iocb created in lpfc_prep_seq */
  10652. list_for_each_entry_safe(curr_iocb, next_iocb,
  10653. &iocbq->list, list) {
  10654. list_del_init(&curr_iocb->list);
  10655. lpfc_sli_release_iocbq(phba, curr_iocb);
  10656. }
  10657. lpfc_sli_release_iocbq(phba, iocbq);
  10658. }
  10659. /**
  10660. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10661. * @phba: Pointer to HBA context object.
  10662. *
  10663. * This function is called with no lock held. This function processes all
  10664. * the received buffers and gives it to upper layers when a received buffer
  10665. * indicates that it is the final frame in the sequence. The interrupt
  10666. * service routine processes received buffers at interrupt contexts and adds
  10667. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10668. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10669. * appropriate receive function when the final frame in a sequence is received.
  10670. **/
  10671. void
  10672. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10673. struct hbq_dmabuf *dmabuf)
  10674. {
  10675. struct hbq_dmabuf *seq_dmabuf;
  10676. struct fc_frame_header *fc_hdr;
  10677. struct lpfc_vport *vport;
  10678. uint32_t fcfi;
  10679. /* Process each received buffer */
  10680. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10681. /* check to see if this a valid type of frame */
  10682. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10683. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10684. return;
  10685. }
  10686. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10687. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10688. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10689. /* throw out the frame */
  10690. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10691. return;
  10692. }
  10693. /* Handle the basic abort sequence (BA_ABTS) event */
  10694. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10695. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10696. return;
  10697. }
  10698. /* Link this frame */
  10699. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10700. if (!seq_dmabuf) {
  10701. /* unable to add frame to vport - throw it out */
  10702. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10703. return;
  10704. }
  10705. /* If not last frame in sequence continue processing frames. */
  10706. if (!lpfc_seq_complete(seq_dmabuf))
  10707. return;
  10708. /* Send the complete sequence to the upper layer protocol */
  10709. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10710. }
  10711. /**
  10712. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10713. * @phba: pointer to lpfc hba data structure.
  10714. *
  10715. * This routine is invoked to post rpi header templates to the
  10716. * HBA consistent with the SLI-4 interface spec. This routine
  10717. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10718. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10719. *
  10720. * This routine does not require any locks. It's usage is expected
  10721. * to be driver load or reset recovery when the driver is
  10722. * sequential.
  10723. *
  10724. * Return codes
  10725. * 0 - successful
  10726. * EIO - The mailbox failed to complete successfully.
  10727. * When this error occurs, the driver is not guaranteed
  10728. * to have any rpi regions posted to the device and
  10729. * must either attempt to repost the regions or take a
  10730. * fatal error.
  10731. **/
  10732. int
  10733. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10734. {
  10735. struct lpfc_rpi_hdr *rpi_page;
  10736. uint32_t rc = 0;
  10737. /* Post all rpi memory regions to the port. */
  10738. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10739. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10740. if (rc != MBX_SUCCESS) {
  10741. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10742. "2008 Error %d posting all rpi "
  10743. "headers\n", rc);
  10744. rc = -EIO;
  10745. break;
  10746. }
  10747. }
  10748. return rc;
  10749. }
  10750. /**
  10751. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10752. * @phba: pointer to lpfc hba data structure.
  10753. * @rpi_page: pointer to the rpi memory region.
  10754. *
  10755. * This routine is invoked to post a single rpi header to the
  10756. * HBA consistent with the SLI-4 interface spec. This memory region
  10757. * maps up to 64 rpi context regions.
  10758. *
  10759. * Return codes
  10760. * 0 - successful
  10761. * ENOMEM - No available memory
  10762. * EIO - The mailbox failed to complete successfully.
  10763. **/
  10764. int
  10765. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10766. {
  10767. LPFC_MBOXQ_t *mboxq;
  10768. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10769. uint32_t rc = 0;
  10770. uint32_t mbox_tmo;
  10771. uint32_t shdr_status, shdr_add_status;
  10772. union lpfc_sli4_cfg_shdr *shdr;
  10773. /* The port is notified of the header region via a mailbox command. */
  10774. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10775. if (!mboxq) {
  10776. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10777. "2001 Unable to allocate memory for issuing "
  10778. "SLI_CONFIG_SPECIAL mailbox command\n");
  10779. return -ENOMEM;
  10780. }
  10781. /* Post all rpi memory regions to the port. */
  10782. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10783. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10784. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10785. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10786. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10787. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10788. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10789. hdr_tmpl, rpi_page->page_count);
  10790. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10791. rpi_page->start_rpi);
  10792. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10793. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10794. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10795. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10796. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10797. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10798. if (rc != MBX_TIMEOUT)
  10799. mempool_free(mboxq, phba->mbox_mem_pool);
  10800. if (shdr_status || shdr_add_status || rc) {
  10801. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10802. "2514 POST_RPI_HDR mailbox failed with "
  10803. "status x%x add_status x%x, mbx status x%x\n",
  10804. shdr_status, shdr_add_status, rc);
  10805. rc = -ENXIO;
  10806. }
  10807. return rc;
  10808. }
  10809. /**
  10810. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10811. * @phba: pointer to lpfc hba data structure.
  10812. *
  10813. * This routine is invoked to post rpi header templates to the
  10814. * HBA consistent with the SLI-4 interface spec. This routine
  10815. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10816. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10817. *
  10818. * Returns
  10819. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10820. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10821. **/
  10822. int
  10823. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10824. {
  10825. int rpi;
  10826. uint16_t max_rpi, rpi_base, rpi_limit;
  10827. uint16_t rpi_remaining;
  10828. struct lpfc_rpi_hdr *rpi_hdr;
  10829. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10830. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10831. rpi_limit = phba->sli4_hba.next_rpi;
  10832. /*
  10833. * The valid rpi range is not guaranteed to be zero-based. Start
  10834. * the search at the rpi_base as reported by the port.
  10835. */
  10836. spin_lock_irq(&phba->hbalock);
  10837. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10838. if (rpi >= rpi_limit || rpi < rpi_base)
  10839. rpi = LPFC_RPI_ALLOC_ERROR;
  10840. else {
  10841. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10842. phba->sli4_hba.max_cfg_param.rpi_used++;
  10843. phba->sli4_hba.rpi_count++;
  10844. }
  10845. /*
  10846. * Don't try to allocate more rpi header regions if the device limit
  10847. * on available rpis max has been exhausted.
  10848. */
  10849. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10850. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10851. spin_unlock_irq(&phba->hbalock);
  10852. return rpi;
  10853. }
  10854. /*
  10855. * If the driver is running low on rpi resources, allocate another
  10856. * page now. Note that the next_rpi value is used because
  10857. * it represents how many are actually in use whereas max_rpi notes
  10858. * how many are supported max by the device.
  10859. */
  10860. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10861. phba->sli4_hba.rpi_count;
  10862. spin_unlock_irq(&phba->hbalock);
  10863. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10864. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10865. if (!rpi_hdr) {
  10866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10867. "2002 Error Could not grow rpi "
  10868. "count\n");
  10869. } else {
  10870. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10871. }
  10872. }
  10873. return rpi;
  10874. }
  10875. /**
  10876. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10877. * @phba: pointer to lpfc hba data structure.
  10878. *
  10879. * This routine is invoked to release an rpi to the pool of
  10880. * available rpis maintained by the driver.
  10881. **/
  10882. void
  10883. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10884. {
  10885. spin_lock_irq(&phba->hbalock);
  10886. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10887. phba->sli4_hba.rpi_count--;
  10888. phba->sli4_hba.max_cfg_param.rpi_used--;
  10889. spin_unlock_irq(&phba->hbalock);
  10890. }
  10891. /**
  10892. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10893. * @phba: pointer to lpfc hba data structure.
  10894. *
  10895. * This routine is invoked to remove the memory region that
  10896. * provided rpi via a bitmask.
  10897. **/
  10898. void
  10899. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10900. {
  10901. kfree(phba->sli4_hba.rpi_bmask);
  10902. }
  10903. /**
  10904. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10905. * @phba: pointer to lpfc hba data structure.
  10906. *
  10907. * This routine is invoked to remove the memory region that
  10908. * provided rpi via a bitmask.
  10909. **/
  10910. int
  10911. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10912. {
  10913. LPFC_MBOXQ_t *mboxq;
  10914. struct lpfc_hba *phba = ndlp->phba;
  10915. int rc;
  10916. /* The port is notified of the header region via a mailbox command. */
  10917. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10918. if (!mboxq)
  10919. return -ENOMEM;
  10920. /* Post all rpi memory regions to the port. */
  10921. lpfc_resume_rpi(mboxq, ndlp);
  10922. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10923. if (rc == MBX_NOT_FINISHED) {
  10924. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10925. "2010 Resume RPI Mailbox failed "
  10926. "status %d, mbxStatus x%x\n", rc,
  10927. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10928. mempool_free(mboxq, phba->mbox_mem_pool);
  10929. return -EIO;
  10930. }
  10931. return 0;
  10932. }
  10933. /**
  10934. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10935. * @phba: pointer to lpfc hba data structure.
  10936. * @vpi: vpi value to activate with the port.
  10937. *
  10938. * This routine is invoked to activate a vpi with the
  10939. * port when the host intends to use vports with a
  10940. * nonzero vpi.
  10941. *
  10942. * Returns:
  10943. * 0 success
  10944. * -Evalue otherwise
  10945. **/
  10946. int
  10947. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10948. {
  10949. LPFC_MBOXQ_t *mboxq;
  10950. int rc = 0;
  10951. int retval = MBX_SUCCESS;
  10952. uint32_t mbox_tmo;
  10953. if (vpi == 0)
  10954. return -EINVAL;
  10955. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10956. if (!mboxq)
  10957. return -ENOMEM;
  10958. lpfc_init_vpi(phba, mboxq, vpi);
  10959. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10960. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10961. if (rc != MBX_SUCCESS) {
  10962. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10963. "2022 INIT VPI Mailbox failed "
  10964. "status %d, mbxStatus x%x\n", rc,
  10965. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10966. retval = -EIO;
  10967. }
  10968. if (rc != MBX_TIMEOUT)
  10969. mempool_free(mboxq, phba->mbox_mem_pool);
  10970. return retval;
  10971. }
  10972. /**
  10973. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10974. * @phba: pointer to lpfc hba data structure.
  10975. * @mboxq: Pointer to mailbox object.
  10976. *
  10977. * This routine is invoked to manually add a single FCF record. The caller
  10978. * must pass a completely initialized FCF_Record. This routine takes
  10979. * care of the nonembedded mailbox operations.
  10980. **/
  10981. static void
  10982. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10983. {
  10984. void *virt_addr;
  10985. union lpfc_sli4_cfg_shdr *shdr;
  10986. uint32_t shdr_status, shdr_add_status;
  10987. virt_addr = mboxq->sge_array->addr[0];
  10988. /* The IOCTL status is embedded in the mailbox subheader. */
  10989. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10990. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10991. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10992. if ((shdr_status || shdr_add_status) &&
  10993. (shdr_status != STATUS_FCF_IN_USE))
  10994. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10995. "2558 ADD_FCF_RECORD mailbox failed with "
  10996. "status x%x add_status x%x\n",
  10997. shdr_status, shdr_add_status);
  10998. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10999. }
  11000. /**
  11001. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11002. * @phba: pointer to lpfc hba data structure.
  11003. * @fcf_record: pointer to the initialized fcf record to add.
  11004. *
  11005. * This routine is invoked to manually add a single FCF record. The caller
  11006. * must pass a completely initialized FCF_Record. This routine takes
  11007. * care of the nonembedded mailbox operations.
  11008. **/
  11009. int
  11010. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11011. {
  11012. int rc = 0;
  11013. LPFC_MBOXQ_t *mboxq;
  11014. uint8_t *bytep;
  11015. void *virt_addr;
  11016. dma_addr_t phys_addr;
  11017. struct lpfc_mbx_sge sge;
  11018. uint32_t alloc_len, req_len;
  11019. uint32_t fcfindex;
  11020. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11021. if (!mboxq) {
  11022. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11023. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11024. return -ENOMEM;
  11025. }
  11026. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11027. sizeof(uint32_t);
  11028. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11029. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11030. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11031. req_len, LPFC_SLI4_MBX_NEMBED);
  11032. if (alloc_len < req_len) {
  11033. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11034. "2523 Allocated DMA memory size (x%x) is "
  11035. "less than the requested DMA memory "
  11036. "size (x%x)\n", alloc_len, req_len);
  11037. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11038. return -ENOMEM;
  11039. }
  11040. /*
  11041. * Get the first SGE entry from the non-embedded DMA memory. This
  11042. * routine only uses a single SGE.
  11043. */
  11044. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11045. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11046. virt_addr = mboxq->sge_array->addr[0];
  11047. /*
  11048. * Configure the FCF record for FCFI 0. This is the driver's
  11049. * hardcoded default and gets used in nonFIP mode.
  11050. */
  11051. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11052. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11053. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11054. /*
  11055. * Copy the fcf_index and the FCF Record Data. The data starts after
  11056. * the FCoE header plus word10. The data copy needs to be endian
  11057. * correct.
  11058. */
  11059. bytep += sizeof(uint32_t);
  11060. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11061. mboxq->vport = phba->pport;
  11062. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11063. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11064. if (rc == MBX_NOT_FINISHED) {
  11065. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11066. "2515 ADD_FCF_RECORD mailbox failed with "
  11067. "status 0x%x\n", rc);
  11068. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11069. rc = -EIO;
  11070. } else
  11071. rc = 0;
  11072. return rc;
  11073. }
  11074. /**
  11075. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11076. * @phba: pointer to lpfc hba data structure.
  11077. * @fcf_record: pointer to the fcf record to write the default data.
  11078. * @fcf_index: FCF table entry index.
  11079. *
  11080. * This routine is invoked to build the driver's default FCF record. The
  11081. * values used are hardcoded. This routine handles memory initialization.
  11082. *
  11083. **/
  11084. void
  11085. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11086. struct fcf_record *fcf_record,
  11087. uint16_t fcf_index)
  11088. {
  11089. memset(fcf_record, 0, sizeof(struct fcf_record));
  11090. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11091. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11092. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11093. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11094. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11095. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11096. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11097. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11098. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11099. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11100. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11101. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11102. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11103. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11104. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11105. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11106. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11107. /* Set the VLAN bit map */
  11108. if (phba->valid_vlan) {
  11109. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11110. = 1 << (phba->vlan_id % 8);
  11111. }
  11112. }
  11113. /**
  11114. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11115. * @phba: pointer to lpfc hba data structure.
  11116. * @fcf_index: FCF table entry offset.
  11117. *
  11118. * This routine is invoked to scan the entire FCF table by reading FCF
  11119. * record and processing it one at a time starting from the @fcf_index
  11120. * for initial FCF discovery or fast FCF failover rediscovery.
  11121. *
  11122. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11123. * otherwise.
  11124. **/
  11125. int
  11126. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11127. {
  11128. int rc = 0, error;
  11129. LPFC_MBOXQ_t *mboxq;
  11130. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11131. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11132. if (!mboxq) {
  11133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11134. "2000 Failed to allocate mbox for "
  11135. "READ_FCF cmd\n");
  11136. error = -ENOMEM;
  11137. goto fail_fcf_scan;
  11138. }
  11139. /* Construct the read FCF record mailbox command */
  11140. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11141. if (rc) {
  11142. error = -EINVAL;
  11143. goto fail_fcf_scan;
  11144. }
  11145. /* Issue the mailbox command asynchronously */
  11146. mboxq->vport = phba->pport;
  11147. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11148. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11149. if (rc == MBX_NOT_FINISHED)
  11150. error = -EIO;
  11151. else {
  11152. spin_lock_irq(&phba->hbalock);
  11153. phba->hba_flag |= FCF_DISC_INPROGRESS;
  11154. spin_unlock_irq(&phba->hbalock);
  11155. /* Reset FCF round robin index bmask for new scan */
  11156. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) {
  11157. memset(phba->fcf.fcf_rr_bmask, 0,
  11158. sizeof(*phba->fcf.fcf_rr_bmask));
  11159. phba->fcf.eligible_fcf_cnt = 0;
  11160. }
  11161. error = 0;
  11162. }
  11163. fail_fcf_scan:
  11164. if (error) {
  11165. if (mboxq)
  11166. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11167. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  11168. spin_lock_irq(&phba->hbalock);
  11169. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  11170. spin_unlock_irq(&phba->hbalock);
  11171. }
  11172. return error;
  11173. }
  11174. /**
  11175. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf.
  11176. * @phba: pointer to lpfc hba data structure.
  11177. * @fcf_index: FCF table entry offset.
  11178. *
  11179. * This routine is invoked to read an FCF record indicated by @fcf_index
  11180. * and to use it for FLOGI round robin FCF failover.
  11181. *
  11182. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11183. * otherwise.
  11184. **/
  11185. int
  11186. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11187. {
  11188. int rc = 0, error;
  11189. LPFC_MBOXQ_t *mboxq;
  11190. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11191. if (!mboxq) {
  11192. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11193. "2763 Failed to allocate mbox for "
  11194. "READ_FCF cmd\n");
  11195. error = -ENOMEM;
  11196. goto fail_fcf_read;
  11197. }
  11198. /* Construct the read FCF record mailbox command */
  11199. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11200. if (rc) {
  11201. error = -EINVAL;
  11202. goto fail_fcf_read;
  11203. }
  11204. /* Issue the mailbox command asynchronously */
  11205. mboxq->vport = phba->pport;
  11206. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11207. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11208. if (rc == MBX_NOT_FINISHED)
  11209. error = -EIO;
  11210. else
  11211. error = 0;
  11212. fail_fcf_read:
  11213. if (error && mboxq)
  11214. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11215. return error;
  11216. }
  11217. /**
  11218. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11219. * @phba: pointer to lpfc hba data structure.
  11220. * @fcf_index: FCF table entry offset.
  11221. *
  11222. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11223. * determine whether it's eligible for FLOGI round robin failover list.
  11224. *
  11225. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11226. * otherwise.
  11227. **/
  11228. int
  11229. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11230. {
  11231. int rc = 0, error;
  11232. LPFC_MBOXQ_t *mboxq;
  11233. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11234. if (!mboxq) {
  11235. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11236. "2758 Failed to allocate mbox for "
  11237. "READ_FCF cmd\n");
  11238. error = -ENOMEM;
  11239. goto fail_fcf_read;
  11240. }
  11241. /* Construct the read FCF record mailbox command */
  11242. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11243. if (rc) {
  11244. error = -EINVAL;
  11245. goto fail_fcf_read;
  11246. }
  11247. /* Issue the mailbox command asynchronously */
  11248. mboxq->vport = phba->pport;
  11249. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11250. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11251. if (rc == MBX_NOT_FINISHED)
  11252. error = -EIO;
  11253. else
  11254. error = 0;
  11255. fail_fcf_read:
  11256. if (error && mboxq)
  11257. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11258. return error;
  11259. }
  11260. /**
  11261. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11262. * @phba: pointer to lpfc hba data structure.
  11263. *
  11264. * This routine is to get the next eligible FCF record index in a round
  11265. * robin fashion. If the next eligible FCF record index equals to the
  11266. * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11267. * shall be returned, otherwise, the next eligible FCF record's index
  11268. * shall be returned.
  11269. **/
  11270. uint16_t
  11271. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11272. {
  11273. uint16_t next_fcf_index;
  11274. /* Search from the currently registered FCF index */
  11275. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11276. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11277. phba->fcf.current_rec.fcf_indx);
  11278. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11279. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11280. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11281. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11282. /* Round robin failover stop condition */
  11283. if (next_fcf_index == phba->fcf.fcf_rr_init_indx)
  11284. return LPFC_FCOE_FCF_NEXT_NONE;
  11285. return next_fcf_index;
  11286. }
  11287. /**
  11288. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11289. * @phba: pointer to lpfc hba data structure.
  11290. *
  11291. * This routine sets the FCF record index in to the eligible bmask for
  11292. * round robin failover search. It checks to make sure that the index
  11293. * does not go beyond the range of the driver allocated bmask dimension
  11294. * before setting the bit.
  11295. *
  11296. * Returns 0 if the index bit successfully set, otherwise, it returns
  11297. * -EINVAL.
  11298. **/
  11299. int
  11300. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11301. {
  11302. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11303. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11304. "2610 HBA FCF index reached driver's "
  11305. "book keeping dimension: fcf_index:%d, "
  11306. "driver_bmask_max:%d\n",
  11307. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11308. return -EINVAL;
  11309. }
  11310. /* Set the eligible FCF record index bmask */
  11311. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11312. return 0;
  11313. }
  11314. /**
  11315. * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index
  11316. * @phba: pointer to lpfc hba data structure.
  11317. *
  11318. * This routine clears the FCF record index from the eligible bmask for
  11319. * round robin failover search. It checks to make sure that the index
  11320. * does not go beyond the range of the driver allocated bmask dimension
  11321. * before clearing the bit.
  11322. **/
  11323. void
  11324. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11325. {
  11326. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11327. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11328. "2762 HBA FCF index goes beyond driver's "
  11329. "book keeping dimension: fcf_index:%d, "
  11330. "driver_bmask_max:%d\n",
  11331. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11332. return;
  11333. }
  11334. /* Clear the eligible FCF record index bmask */
  11335. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11336. }
  11337. /**
  11338. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11339. * @phba: pointer to lpfc hba data structure.
  11340. *
  11341. * This routine is the completion routine for the rediscover FCF table mailbox
  11342. * command. If the mailbox command returned failure, it will try to stop the
  11343. * FCF rediscover wait timer.
  11344. **/
  11345. void
  11346. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11347. {
  11348. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11349. uint32_t shdr_status, shdr_add_status;
  11350. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11351. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11352. &redisc_fcf->header.cfg_shdr.response);
  11353. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11354. &redisc_fcf->header.cfg_shdr.response);
  11355. if (shdr_status || shdr_add_status) {
  11356. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11357. "2746 Requesting for FCF rediscovery failed "
  11358. "status x%x add_status x%x\n",
  11359. shdr_status, shdr_add_status);
  11360. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11361. spin_lock_irq(&phba->hbalock);
  11362. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11363. spin_unlock_irq(&phba->hbalock);
  11364. /*
  11365. * CVL event triggered FCF rediscover request failed,
  11366. * last resort to re-try current registered FCF entry.
  11367. */
  11368. lpfc_retry_pport_discovery(phba);
  11369. } else {
  11370. spin_lock_irq(&phba->hbalock);
  11371. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11372. spin_unlock_irq(&phba->hbalock);
  11373. /*
  11374. * DEAD FCF event triggered FCF rediscover request
  11375. * failed, last resort to fail over as a link down
  11376. * to FCF registration.
  11377. */
  11378. lpfc_sli4_fcf_dead_failthrough(phba);
  11379. }
  11380. } else {
  11381. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11382. "2775 Start FCF rediscovery quiescent period "
  11383. "wait timer before scaning FCF table\n");
  11384. /*
  11385. * Start FCF rediscovery wait timer for pending FCF
  11386. * before rescan FCF record table.
  11387. */
  11388. lpfc_fcf_redisc_wait_start_timer(phba);
  11389. }
  11390. mempool_free(mbox, phba->mbox_mem_pool);
  11391. }
  11392. /**
  11393. * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
  11394. * @phba: pointer to lpfc hba data structure.
  11395. *
  11396. * This routine is invoked to request for rediscovery of the entire FCF table
  11397. * by the port.
  11398. **/
  11399. int
  11400. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11401. {
  11402. LPFC_MBOXQ_t *mbox;
  11403. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11404. int rc, length;
  11405. /* Cancel retry delay timers to all vports before FCF rediscover */
  11406. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11407. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11408. if (!mbox) {
  11409. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11410. "2745 Failed to allocate mbox for "
  11411. "requesting FCF rediscover.\n");
  11412. return -ENOMEM;
  11413. }
  11414. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11415. sizeof(struct lpfc_sli4_cfg_mhdr));
  11416. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11417. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11418. length, LPFC_SLI4_MBX_EMBED);
  11419. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11420. /* Set count to 0 for invalidating the entire FCF database */
  11421. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11422. /* Issue the mailbox command asynchronously */
  11423. mbox->vport = phba->pport;
  11424. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11425. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11426. if (rc == MBX_NOT_FINISHED) {
  11427. mempool_free(mbox, phba->mbox_mem_pool);
  11428. return -EIO;
  11429. }
  11430. return 0;
  11431. }
  11432. /**
  11433. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11434. * @phba: pointer to lpfc hba data structure.
  11435. *
  11436. * This function is the failover routine as a last resort to the FCF DEAD
  11437. * event when driver failed to perform fast FCF failover.
  11438. **/
  11439. void
  11440. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11441. {
  11442. uint32_t link_state;
  11443. /*
  11444. * Last resort as FCF DEAD event failover will treat this as
  11445. * a link down, but save the link state because we don't want
  11446. * it to be changed to Link Down unless it is already down.
  11447. */
  11448. link_state = phba->link_state;
  11449. lpfc_linkdown(phba);
  11450. phba->link_state = link_state;
  11451. /* Unregister FCF if no devices connected to it */
  11452. lpfc_unregister_unused_fcf(phba);
  11453. }
  11454. /**
  11455. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11456. * @phba: pointer to lpfc hba data structure.
  11457. *
  11458. * This function read region 23 and parse TLV for port status to
  11459. * decide if the user disaled the port. If the TLV indicates the
  11460. * port is disabled, the hba_flag is set accordingly.
  11461. **/
  11462. void
  11463. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11464. {
  11465. LPFC_MBOXQ_t *pmb = NULL;
  11466. MAILBOX_t *mb;
  11467. uint8_t *rgn23_data = NULL;
  11468. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11469. int rc;
  11470. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11471. if (!pmb) {
  11472. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11473. "2600 lpfc_sli_read_serdes_param failed to"
  11474. " allocate mailbox memory\n");
  11475. goto out;
  11476. }
  11477. mb = &pmb->u.mb;
  11478. /* Get adapter Region 23 data */
  11479. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11480. if (!rgn23_data)
  11481. goto out;
  11482. do {
  11483. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11484. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11485. if (rc != MBX_SUCCESS) {
  11486. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11487. "2601 lpfc_sli_read_link_ste failed to"
  11488. " read config region 23 rc 0x%x Status 0x%x\n",
  11489. rc, mb->mbxStatus);
  11490. mb->un.varDmp.word_cnt = 0;
  11491. }
  11492. /*
  11493. * dump mem may return a zero when finished or we got a
  11494. * mailbox error, either way we are done.
  11495. */
  11496. if (mb->un.varDmp.word_cnt == 0)
  11497. break;
  11498. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11499. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11500. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11501. rgn23_data + offset,
  11502. mb->un.varDmp.word_cnt);
  11503. offset += mb->un.varDmp.word_cnt;
  11504. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11505. data_size = offset;
  11506. offset = 0;
  11507. if (!data_size)
  11508. goto out;
  11509. /* Check the region signature first */
  11510. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11511. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11512. "2619 Config region 23 has bad signature\n");
  11513. goto out;
  11514. }
  11515. offset += 4;
  11516. /* Check the data structure version */
  11517. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11519. "2620 Config region 23 has bad version\n");
  11520. goto out;
  11521. }
  11522. offset += 4;
  11523. /* Parse TLV entries in the region */
  11524. while (offset < data_size) {
  11525. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11526. break;
  11527. /*
  11528. * If the TLV is not driver specific TLV or driver id is
  11529. * not linux driver id, skip the record.
  11530. */
  11531. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11532. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11533. (rgn23_data[offset + 3] != 0)) {
  11534. offset += rgn23_data[offset + 1] * 4 + 4;
  11535. continue;
  11536. }
  11537. /* Driver found a driver specific TLV in the config region */
  11538. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11539. offset += 4;
  11540. tlv_offset = 0;
  11541. /*
  11542. * Search for configured port state sub-TLV.
  11543. */
  11544. while ((offset < data_size) &&
  11545. (tlv_offset < sub_tlv_len)) {
  11546. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11547. offset += 4;
  11548. tlv_offset += 4;
  11549. break;
  11550. }
  11551. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11552. offset += rgn23_data[offset + 1] * 4 + 4;
  11553. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11554. continue;
  11555. }
  11556. /* This HBA contains PORT_STE configured */
  11557. if (!rgn23_data[offset + 2])
  11558. phba->hba_flag |= LINK_DISABLED;
  11559. goto out;
  11560. }
  11561. }
  11562. out:
  11563. if (pmb)
  11564. mempool_free(pmb, phba->mbox_mem_pool);
  11565. kfree(rgn23_data);
  11566. return;
  11567. }
  11568. /**
  11569. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11570. * @vport: pointer to vport data structure.
  11571. *
  11572. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11573. * and REG_VPI mailbox commands associated with the vport. This function
  11574. * is called when driver want to restart discovery of the vport due to
  11575. * a Clear Virtual Link event.
  11576. **/
  11577. void
  11578. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11579. {
  11580. struct lpfc_hba *phba = vport->phba;
  11581. LPFC_MBOXQ_t *mb, *nextmb;
  11582. struct lpfc_dmabuf *mp;
  11583. struct lpfc_nodelist *ndlp;
  11584. spin_lock_irq(&phba->hbalock);
  11585. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11586. if (mb->vport != vport)
  11587. continue;
  11588. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11589. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11590. continue;
  11591. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11592. mp = (struct lpfc_dmabuf *) (mb->context1);
  11593. if (mp) {
  11594. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11595. kfree(mp);
  11596. }
  11597. ndlp = (struct lpfc_nodelist *) mb->context2;
  11598. if (ndlp) {
  11599. lpfc_nlp_put(ndlp);
  11600. mb->context2 = NULL;
  11601. }
  11602. }
  11603. list_del(&mb->list);
  11604. mempool_free(mb, phba->mbox_mem_pool);
  11605. }
  11606. mb = phba->sli.mbox_active;
  11607. if (mb && (mb->vport == vport)) {
  11608. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11609. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11610. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11611. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11612. ndlp = (struct lpfc_nodelist *) mb->context2;
  11613. if (ndlp) {
  11614. lpfc_nlp_put(ndlp);
  11615. mb->context2 = NULL;
  11616. }
  11617. /* Unregister the RPI when mailbox complete */
  11618. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11619. }
  11620. }
  11621. spin_unlock_irq(&phba->hbalock);
  11622. }