lpfc_sli.c 422 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 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(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  92. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  93. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  94. /* Update the host index before invoking device */
  95. host_index = q->host_index;
  96. q->host_index = ((q->host_index + 1) % q->entry_count);
  97. /* Ring Doorbell */
  98. doorbell.word0 = 0;
  99. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  100. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  101. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  102. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  103. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  104. return 0;
  105. }
  106. /**
  107. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  108. * @q: The Work Queue to operate on.
  109. * @index: The index to advance the hba index to.
  110. *
  111. * This routine will update the HBA index of a queue to reflect consumption of
  112. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  113. * an entry the host calls this function to update the queue's internal
  114. * pointers. This routine returns the number of entries that were consumed by
  115. * the HBA.
  116. **/
  117. static uint32_t
  118. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  119. {
  120. uint32_t released = 0;
  121. if (q->hba_index == index)
  122. return 0;
  123. do {
  124. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  125. released++;
  126. } while (q->hba_index != index);
  127. return released;
  128. }
  129. /**
  130. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  131. * @q: The Mailbox Queue to operate on.
  132. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  133. *
  134. * This routine will copy the contents of @mqe to the next available entry on
  135. * the @q. This function will then ring the Work Queue Doorbell to signal the
  136. * HBA to start processing the Work Queue Entry. This function returns 0 if
  137. * successful. If no entries are available on @q then this function will return
  138. * -ENOMEM.
  139. * The caller is expected to hold the hbalock when calling this routine.
  140. **/
  141. static uint32_t
  142. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  143. {
  144. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  145. struct lpfc_register doorbell;
  146. uint32_t host_index;
  147. /* If the host has not yet processed the next entry then we are done */
  148. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  149. return -ENOMEM;
  150. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  151. /* Save off the mailbox pointer for completion */
  152. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  153. /* Update the host index before invoking device */
  154. host_index = q->host_index;
  155. q->host_index = ((q->host_index + 1) % q->entry_count);
  156. /* Ring Doorbell */
  157. doorbell.word0 = 0;
  158. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  159. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  160. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  161. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  162. return 0;
  163. }
  164. /**
  165. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  166. * @q: The Mailbox Queue to operate on.
  167. *
  168. * This routine will update the HBA index of a queue to reflect consumption of
  169. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  170. * an entry the host calls this function to update the queue's internal
  171. * pointers. This routine returns the number of entries that were consumed by
  172. * the HBA.
  173. **/
  174. static uint32_t
  175. lpfc_sli4_mq_release(struct lpfc_queue *q)
  176. {
  177. /* Clear the mailbox pointer for completion */
  178. q->phba->mbox = NULL;
  179. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  180. return 1;
  181. }
  182. /**
  183. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  184. * @q: The Event Queue to get the first valid EQE from
  185. *
  186. * This routine will get the first valid Event Queue Entry from @q, update
  187. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  188. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  189. * processed, but not popped back to the HBA then this routine will return NULL.
  190. **/
  191. static struct lpfc_eqe *
  192. lpfc_sli4_eq_get(struct lpfc_queue *q)
  193. {
  194. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  195. /* If the next EQE is not valid then we are done */
  196. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  197. return NULL;
  198. /* If the host has not yet processed the next entry then we are done */
  199. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  200. return NULL;
  201. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  202. return eqe;
  203. }
  204. /**
  205. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  206. * @q: The Event Queue that the host has completed processing for.
  207. * @arm: Indicates whether the host wants to arms this CQ.
  208. *
  209. * This routine will mark all Event Queue Entries on @q, from the last
  210. * known completed entry to the last entry that was processed, as completed
  211. * by clearing the valid bit for each completion queue entry. Then it will
  212. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  213. * The internal host index in the @q will be updated by this routine to indicate
  214. * that the host has finished processing the entries. The @arm parameter
  215. * indicates that the queue should be rearmed when ringing the doorbell.
  216. *
  217. * This function will return the number of EQEs that were popped.
  218. **/
  219. uint32_t
  220. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  221. {
  222. uint32_t released = 0;
  223. struct lpfc_eqe *temp_eqe;
  224. struct lpfc_register doorbell;
  225. /* while there are valid entries */
  226. while (q->hba_index != q->host_index) {
  227. temp_eqe = q->qe[q->host_index].eqe;
  228. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  229. released++;
  230. q->host_index = ((q->host_index + 1) % q->entry_count);
  231. }
  232. if (unlikely(released == 0 && !arm))
  233. return 0;
  234. /* ring doorbell for number popped */
  235. doorbell.word0 = 0;
  236. if (arm) {
  237. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  238. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  239. }
  240. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  241. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  242. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  243. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  244. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  245. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  246. readl(q->phba->sli4_hba.EQCQDBregaddr);
  247. return released;
  248. }
  249. /**
  250. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  251. * @q: The Completion Queue to get the first valid CQE from
  252. *
  253. * This routine will get the first valid Completion Queue Entry from @q, update
  254. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  255. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  256. * processed, but not popped back to the HBA then this routine will return NULL.
  257. **/
  258. static struct lpfc_cqe *
  259. lpfc_sli4_cq_get(struct lpfc_queue *q)
  260. {
  261. struct lpfc_cqe *cqe;
  262. /* If the next CQE is not valid then we are done */
  263. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  264. return NULL;
  265. /* If the host has not yet processed the next entry then we are done */
  266. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  267. return NULL;
  268. cqe = q->qe[q->hba_index].cqe;
  269. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  270. return cqe;
  271. }
  272. /**
  273. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  274. * @q: The Completion Queue that the host has completed processing for.
  275. * @arm: Indicates whether the host wants to arms this CQ.
  276. *
  277. * This routine will mark all Completion queue entries on @q, from the last
  278. * known completed entry to the last entry that was processed, as completed
  279. * by clearing the valid bit for each completion queue entry. Then it will
  280. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  281. * The internal host index in the @q will be updated by this routine to indicate
  282. * that the host has finished processing the entries. The @arm parameter
  283. * indicates that the queue should be rearmed when ringing the doorbell.
  284. *
  285. * This function will return the number of CQEs that were released.
  286. **/
  287. uint32_t
  288. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  289. {
  290. uint32_t released = 0;
  291. struct lpfc_cqe *temp_qe;
  292. struct lpfc_register doorbell;
  293. /* while there are valid entries */
  294. while (q->hba_index != q->host_index) {
  295. temp_qe = q->qe[q->host_index].cqe;
  296. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  297. released++;
  298. q->host_index = ((q->host_index + 1) % q->entry_count);
  299. }
  300. if (unlikely(released == 0 && !arm))
  301. return 0;
  302. /* ring doorbell for number popped */
  303. doorbell.word0 = 0;
  304. if (arm)
  305. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  306. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  307. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  308. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  309. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  310. return released;
  311. }
  312. /**
  313. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  314. * @q: The Header Receive Queue to operate on.
  315. * @wqe: The Receive Queue Entry to put on the Receive queue.
  316. *
  317. * This routine will copy the contents of @wqe to the next available entry on
  318. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  319. * HBA to start processing the Receive Queue Entry. This function returns the
  320. * index that the rqe was copied to if successful. If no entries are available
  321. * on @q then this function will return -ENOMEM.
  322. * The caller is expected to hold the hbalock when calling this routine.
  323. **/
  324. static int
  325. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  326. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  327. {
  328. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  329. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  330. struct lpfc_register doorbell;
  331. int put_index = hq->host_index;
  332. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  333. return -EINVAL;
  334. if (hq->host_index != dq->host_index)
  335. return -EINVAL;
  336. /* If the host has not yet processed the next entry then we are done */
  337. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  338. return -EBUSY;
  339. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  340. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  341. /* Update the host index to point to the next slot */
  342. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  343. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  344. /* Ring The Header Receive Queue Doorbell */
  345. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  346. doorbell.word0 = 0;
  347. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  348. LPFC_RQ_POST_BATCH);
  349. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  350. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  351. }
  352. return put_index;
  353. }
  354. /**
  355. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  356. * @q: The Header Receive Queue to operate on.
  357. *
  358. * This routine will update the HBA index of a queue to reflect consumption of
  359. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  360. * consumed an entry the host calls this function to update the queue's
  361. * internal pointers. This routine returns the number of entries that were
  362. * consumed by the HBA.
  363. **/
  364. static uint32_t
  365. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  366. {
  367. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  368. return 0;
  369. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  370. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  371. return 1;
  372. }
  373. /**
  374. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  375. * @phba: Pointer to HBA context object.
  376. * @pring: Pointer to driver SLI ring object.
  377. *
  378. * This function returns pointer to next command iocb entry
  379. * in the command ring. The caller must hold hbalock to prevent
  380. * other threads consume the next command iocb.
  381. * SLI-2/SLI-3 provide different sized iocbs.
  382. **/
  383. static inline IOCB_t *
  384. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  385. {
  386. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  387. pring->cmdidx * phba->iocb_cmd_size);
  388. }
  389. /**
  390. * lpfc_resp_iocb - Get next response iocb entry in the ring
  391. * @phba: Pointer to HBA context object.
  392. * @pring: Pointer to driver SLI ring object.
  393. *
  394. * This function returns pointer to next response iocb entry
  395. * in the response ring. The caller must hold hbalock to make sure
  396. * that no other thread consume the next response iocb.
  397. * SLI-2/SLI-3 provide different sized iocbs.
  398. **/
  399. static inline IOCB_t *
  400. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  401. {
  402. return (IOCB_t *) (((char *) pring->rspringaddr) +
  403. pring->rspidx * phba->iocb_rsp_size);
  404. }
  405. /**
  406. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  407. * @phba: Pointer to HBA context object.
  408. *
  409. * This function is called with hbalock held. This function
  410. * allocates a new driver iocb object from the iocb pool. If the
  411. * allocation is successful, it returns pointer to the newly
  412. * allocated iocb object else it returns NULL.
  413. **/
  414. static struct lpfc_iocbq *
  415. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  416. {
  417. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  418. struct lpfc_iocbq * iocbq = NULL;
  419. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  420. if (iocbq)
  421. phba->iocb_cnt++;
  422. if (phba->iocb_cnt > phba->iocb_max)
  423. phba->iocb_max = phba->iocb_cnt;
  424. return iocbq;
  425. }
  426. /**
  427. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  428. * @phba: Pointer to HBA context object.
  429. * @xritag: XRI value.
  430. *
  431. * This function clears the sglq pointer from the array of acive
  432. * sglq's. The xritag that is passed in is used to index into the
  433. * array. Before the xritag can be used it needs to be adjusted
  434. * by subtracting the xribase.
  435. *
  436. * Returns sglq ponter = success, NULL = Failure.
  437. **/
  438. static struct lpfc_sglq *
  439. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  440. {
  441. uint16_t adj_xri;
  442. struct lpfc_sglq *sglq;
  443. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  444. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  445. return NULL;
  446. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  447. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  448. return sglq;
  449. }
  450. /**
  451. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  452. * @phba: Pointer to HBA context object.
  453. * @xritag: XRI value.
  454. *
  455. * This function returns the sglq pointer from the array of acive
  456. * sglq's. The xritag that is passed in is used to index into the
  457. * array. Before the xritag can be used it needs to be adjusted
  458. * by subtracting the xribase.
  459. *
  460. * Returns sglq ponter = success, NULL = Failure.
  461. **/
  462. struct lpfc_sglq *
  463. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  464. {
  465. uint16_t adj_xri;
  466. struct lpfc_sglq *sglq;
  467. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  468. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  469. return NULL;
  470. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  471. return sglq;
  472. }
  473. /**
  474. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  475. * @phba: Pointer to HBA context object.
  476. * @ndlp: nodelist pointer for this target.
  477. * @xritag: xri used in this exchange.
  478. * @rxid: Remote Exchange ID.
  479. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  480. *
  481. * This function is called with hbalock held.
  482. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  483. * rrq struct and adds it to the active_rrq_list.
  484. *
  485. * returns 0 for rrq slot for this xri
  486. * < 0 Were not able to get rrq mem or invalid parameter.
  487. **/
  488. static int
  489. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  490. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  491. {
  492. uint16_t adj_xri;
  493. struct lpfc_node_rrq *rrq;
  494. int empty;
  495. uint32_t did = 0;
  496. if (!ndlp)
  497. return -EINVAL;
  498. if (!phba->cfg_enable_rrq)
  499. return -EINVAL;
  500. if (phba->pport->load_flag & FC_UNLOADING) {
  501. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  502. goto out;
  503. }
  504. did = ndlp->nlp_DID;
  505. /*
  506. * set the active bit even if there is no mem available.
  507. */
  508. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  509. if (NLP_CHK_FREE_REQ(ndlp))
  510. goto out;
  511. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  512. goto out;
  513. if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  514. goto out;
  515. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  516. if (rrq) {
  517. rrq->send_rrq = send_rrq;
  518. rrq->xritag = xritag;
  519. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  520. rrq->ndlp = ndlp;
  521. rrq->nlp_DID = ndlp->nlp_DID;
  522. rrq->vport = ndlp->vport;
  523. rrq->rxid = rxid;
  524. empty = list_empty(&phba->active_rrq_list);
  525. rrq->send_rrq = send_rrq;
  526. list_add_tail(&rrq->list, &phba->active_rrq_list);
  527. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  528. phba->hba_flag |= HBA_RRQ_ACTIVE;
  529. if (empty)
  530. lpfc_worker_wake_up(phba);
  531. }
  532. return 0;
  533. }
  534. out:
  535. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  536. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  537. " DID:0x%x Send:%d\n",
  538. xritag, rxid, did, send_rrq);
  539. return -EINVAL;
  540. }
  541. /**
  542. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  543. * @phba: Pointer to HBA context object.
  544. * @xritag: xri used in this exchange.
  545. * @rrq: The RRQ to be cleared.
  546. *
  547. **/
  548. void
  549. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  550. uint16_t xritag,
  551. struct lpfc_node_rrq *rrq)
  552. {
  553. uint16_t adj_xri;
  554. struct lpfc_nodelist *ndlp = NULL;
  555. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  556. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  557. /* The target DID could have been swapped (cable swap)
  558. * we should use the ndlp from the findnode if it is
  559. * available.
  560. */
  561. if ((!ndlp) && rrq->ndlp)
  562. ndlp = rrq->ndlp;
  563. if (!ndlp)
  564. goto out;
  565. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  566. if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
  567. rrq->send_rrq = 0;
  568. rrq->xritag = 0;
  569. rrq->rrq_stop_time = 0;
  570. }
  571. out:
  572. mempool_free(rrq, phba->rrq_pool);
  573. }
  574. /**
  575. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  576. * @phba: Pointer to HBA context object.
  577. *
  578. * This function is called with hbalock held. This function
  579. * Checks if stop_time (ratov from setting rrq active) has
  580. * been reached, if it has and the send_rrq flag is set then
  581. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  582. * then it will just call the routine to clear the rrq and
  583. * free the rrq resource.
  584. * The timer is set to the next rrq that is going to expire before
  585. * leaving the routine.
  586. *
  587. **/
  588. void
  589. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  590. {
  591. struct lpfc_node_rrq *rrq;
  592. struct lpfc_node_rrq *nextrrq;
  593. unsigned long next_time;
  594. unsigned long iflags;
  595. LIST_HEAD(send_rrq);
  596. spin_lock_irqsave(&phba->hbalock, iflags);
  597. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  598. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  599. list_for_each_entry_safe(rrq, nextrrq,
  600. &phba->active_rrq_list, list) {
  601. if (time_after(jiffies, rrq->rrq_stop_time))
  602. list_move(&rrq->list, &send_rrq);
  603. else if (time_before(rrq->rrq_stop_time, next_time))
  604. next_time = rrq->rrq_stop_time;
  605. }
  606. spin_unlock_irqrestore(&phba->hbalock, iflags);
  607. if (!list_empty(&phba->active_rrq_list))
  608. mod_timer(&phba->rrq_tmr, next_time);
  609. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  610. list_del(&rrq->list);
  611. if (!rrq->send_rrq)
  612. /* this call will free the rrq */
  613. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  614. else if (lpfc_send_rrq(phba, rrq)) {
  615. /* if we send the rrq then the completion handler
  616. * will clear the bit in the xribitmap.
  617. */
  618. lpfc_clr_rrq_active(phba, rrq->xritag,
  619. rrq);
  620. }
  621. }
  622. }
  623. /**
  624. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  625. * @vport: Pointer to vport context object.
  626. * @xri: The xri used in the exchange.
  627. * @did: The targets DID for this exchange.
  628. *
  629. * returns NULL = rrq not found in the phba->active_rrq_list.
  630. * rrq = rrq for this xri and target.
  631. **/
  632. struct lpfc_node_rrq *
  633. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  634. {
  635. struct lpfc_hba *phba = vport->phba;
  636. struct lpfc_node_rrq *rrq;
  637. struct lpfc_node_rrq *nextrrq;
  638. unsigned long iflags;
  639. if (phba->sli_rev != LPFC_SLI_REV4)
  640. return NULL;
  641. spin_lock_irqsave(&phba->hbalock, iflags);
  642. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  643. if (rrq->vport == vport && rrq->xritag == xri &&
  644. rrq->nlp_DID == did){
  645. list_del(&rrq->list);
  646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  647. return rrq;
  648. }
  649. }
  650. spin_unlock_irqrestore(&phba->hbalock, iflags);
  651. return NULL;
  652. }
  653. /**
  654. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  655. * @vport: Pointer to vport context object.
  656. * @ndlp: Pointer to the lpfc_node_list structure.
  657. * If ndlp is NULL Remove all active RRQs for this vport from the
  658. * phba->active_rrq_list and clear the rrq.
  659. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  660. **/
  661. void
  662. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  663. {
  664. struct lpfc_hba *phba = vport->phba;
  665. struct lpfc_node_rrq *rrq;
  666. struct lpfc_node_rrq *nextrrq;
  667. unsigned long iflags;
  668. LIST_HEAD(rrq_list);
  669. if (phba->sli_rev != LPFC_SLI_REV4)
  670. return;
  671. if (!ndlp) {
  672. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  673. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  674. }
  675. spin_lock_irqsave(&phba->hbalock, iflags);
  676. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  677. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  678. list_move(&rrq->list, &rrq_list);
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  681. list_del(&rrq->list);
  682. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  683. }
  684. }
  685. /**
  686. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  687. * @phba: Pointer to HBA context object.
  688. *
  689. * Remove all rrqs from the phba->active_rrq_list and free them by
  690. * calling __lpfc_clr_active_rrq
  691. *
  692. **/
  693. void
  694. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  695. {
  696. struct lpfc_node_rrq *rrq;
  697. struct lpfc_node_rrq *nextrrq;
  698. unsigned long next_time;
  699. unsigned long iflags;
  700. LIST_HEAD(rrq_list);
  701. if (phba->sli_rev != LPFC_SLI_REV4)
  702. return;
  703. spin_lock_irqsave(&phba->hbalock, iflags);
  704. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  705. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  706. list_splice_init(&phba->active_rrq_list, &rrq_list);
  707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  708. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  709. list_del(&rrq->list);
  710. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  711. }
  712. if (!list_empty(&phba->active_rrq_list))
  713. mod_timer(&phba->rrq_tmr, next_time);
  714. }
  715. /**
  716. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  717. * @phba: Pointer to HBA context object.
  718. * @ndlp: Targets nodelist pointer for this exchange.
  719. * @xritag the xri in the bitmap to test.
  720. *
  721. * This function is called with hbalock held. This function
  722. * returns 0 = rrq not active for this xri
  723. * 1 = rrq is valid for this xri.
  724. **/
  725. int
  726. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  727. uint16_t xritag)
  728. {
  729. uint16_t adj_xri;
  730. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  731. if (!ndlp)
  732. return 0;
  733. if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
  734. return 1;
  735. else
  736. return 0;
  737. }
  738. /**
  739. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  740. * @phba: Pointer to HBA context object.
  741. * @ndlp: nodelist pointer for this target.
  742. * @xritag: xri used in this exchange.
  743. * @rxid: Remote Exchange ID.
  744. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  745. *
  746. * This function takes the hbalock.
  747. * The active bit is always set in the active rrq xri_bitmap even
  748. * if there is no slot avaiable for the other rrq information.
  749. *
  750. * returns 0 rrq actived for this xri
  751. * < 0 No memory or invalid ndlp.
  752. **/
  753. int
  754. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  755. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  756. {
  757. int ret;
  758. unsigned long iflags;
  759. spin_lock_irqsave(&phba->hbalock, iflags);
  760. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  761. spin_unlock_irqrestore(&phba->hbalock, iflags);
  762. return ret;
  763. }
  764. /**
  765. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  766. * @phba: Pointer to HBA context object.
  767. * @piocb: Pointer to the iocbq.
  768. *
  769. * This function is called with hbalock held. This function
  770. * Gets a new driver sglq object from the sglq list. If the
  771. * list is not empty then it is successful, it returns pointer to the newly
  772. * allocated sglq object else it returns NULL.
  773. **/
  774. static struct lpfc_sglq *
  775. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  776. {
  777. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  778. struct lpfc_sglq *sglq = NULL;
  779. struct lpfc_sglq *start_sglq = NULL;
  780. uint16_t adj_xri;
  781. struct lpfc_scsi_buf *lpfc_cmd;
  782. struct lpfc_nodelist *ndlp;
  783. int found = 0;
  784. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  785. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  786. ndlp = lpfc_cmd->rdata->pnode;
  787. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  788. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  789. ndlp = piocbq->context_un.ndlp;
  790. else
  791. ndlp = piocbq->context1;
  792. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  793. start_sglq = sglq;
  794. while (!found) {
  795. if (!sglq)
  796. return NULL;
  797. adj_xri = sglq->sli4_xritag -
  798. phba->sli4_hba.max_cfg_param.xri_base;
  799. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  800. /* This xri has an rrq outstanding for this DID.
  801. * put it back in the list and get another xri.
  802. */
  803. list_add_tail(&sglq->list, lpfc_sgl_list);
  804. sglq = NULL;
  805. list_remove_head(lpfc_sgl_list, sglq,
  806. struct lpfc_sglq, list);
  807. if (sglq == start_sglq) {
  808. sglq = NULL;
  809. break;
  810. } else
  811. continue;
  812. }
  813. sglq->ndlp = ndlp;
  814. found = 1;
  815. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  816. sglq->state = SGL_ALLOCATED;
  817. }
  818. return sglq;
  819. }
  820. /**
  821. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  822. * @phba: Pointer to HBA context object.
  823. *
  824. * This function is called with no lock held. This function
  825. * allocates a new driver iocb object from the iocb pool. If the
  826. * allocation is successful, it returns pointer to the newly
  827. * allocated iocb object else it returns NULL.
  828. **/
  829. struct lpfc_iocbq *
  830. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  831. {
  832. struct lpfc_iocbq * iocbq = NULL;
  833. unsigned long iflags;
  834. spin_lock_irqsave(&phba->hbalock, iflags);
  835. iocbq = __lpfc_sli_get_iocbq(phba);
  836. spin_unlock_irqrestore(&phba->hbalock, iflags);
  837. return iocbq;
  838. }
  839. /**
  840. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  841. * @phba: Pointer to HBA context object.
  842. * @iocbq: Pointer to driver iocb object.
  843. *
  844. * This function is called with hbalock held to release driver
  845. * iocb object to the iocb pool. The iotag in the iocb object
  846. * does not change for each use of the iocb object. This function
  847. * clears all other fields of the iocb object when it is freed.
  848. * The sqlq structure that holds the xritag and phys and virtual
  849. * mappings for the scatter gather list is retrieved from the
  850. * active array of sglq. The get of the sglq pointer also clears
  851. * the entry in the array. If the status of the IO indiactes that
  852. * this IO was aborted then the sglq entry it put on the
  853. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  854. * IO has good status or fails for any other reason then the sglq
  855. * entry is added to the free list (lpfc_sgl_list).
  856. **/
  857. static void
  858. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  859. {
  860. struct lpfc_sglq *sglq;
  861. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  862. unsigned long iflag = 0;
  863. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  864. if (iocbq->sli4_xritag == NO_XRI)
  865. sglq = NULL;
  866. else
  867. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  868. if (sglq) {
  869. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  870. (sglq->state != SGL_XRI_ABORTED)) {
  871. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  872. iflag);
  873. list_add(&sglq->list,
  874. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  875. spin_unlock_irqrestore(
  876. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  877. } else {
  878. sglq->state = SGL_FREED;
  879. sglq->ndlp = NULL;
  880. list_add_tail(&sglq->list,
  881. &phba->sli4_hba.lpfc_sgl_list);
  882. /* Check if TXQ queue needs to be serviced */
  883. if (pring->txq_cnt)
  884. lpfc_worker_wake_up(phba);
  885. }
  886. }
  887. /*
  888. * Clean all volatile data fields, preserve iotag and node struct.
  889. */
  890. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  891. iocbq->sli4_xritag = NO_XRI;
  892. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  893. }
  894. /**
  895. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  896. * @phba: Pointer to HBA context object.
  897. * @iocbq: Pointer to driver iocb object.
  898. *
  899. * This function is called with hbalock held to release driver
  900. * iocb object to the iocb pool. The iotag in the iocb object
  901. * does not change for each use of the iocb object. This function
  902. * clears all other fields of the iocb object when it is freed.
  903. **/
  904. static void
  905. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  906. {
  907. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  908. /*
  909. * Clean all volatile data fields, preserve iotag and node struct.
  910. */
  911. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  912. iocbq->sli4_xritag = NO_XRI;
  913. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  914. }
  915. /**
  916. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  917. * @phba: Pointer to HBA context object.
  918. * @iocbq: Pointer to driver iocb object.
  919. *
  920. * This function is called with hbalock held to release driver
  921. * iocb object to the iocb pool. The iotag in the iocb object
  922. * does not change for each use of the iocb object. This function
  923. * clears all other fields of the iocb object when it is freed.
  924. **/
  925. static void
  926. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  927. {
  928. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  929. phba->iocb_cnt--;
  930. }
  931. /**
  932. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  933. * @phba: Pointer to HBA context object.
  934. * @iocbq: Pointer to driver iocb object.
  935. *
  936. * This function is called with no lock held to release the iocb to
  937. * iocb pool.
  938. **/
  939. void
  940. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  941. {
  942. unsigned long iflags;
  943. /*
  944. * Clean all volatile data fields, preserve iotag and node struct.
  945. */
  946. spin_lock_irqsave(&phba->hbalock, iflags);
  947. __lpfc_sli_release_iocbq(phba, iocbq);
  948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  949. }
  950. /**
  951. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  952. * @phba: Pointer to HBA context object.
  953. * @iocblist: List of IOCBs.
  954. * @ulpstatus: ULP status in IOCB command field.
  955. * @ulpWord4: ULP word-4 in IOCB command field.
  956. *
  957. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  958. * on the list by invoking the complete callback function associated with the
  959. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  960. * fields.
  961. **/
  962. void
  963. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  964. uint32_t ulpstatus, uint32_t ulpWord4)
  965. {
  966. struct lpfc_iocbq *piocb;
  967. while (!list_empty(iocblist)) {
  968. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  969. if (!piocb->iocb_cmpl)
  970. lpfc_sli_release_iocbq(phba, piocb);
  971. else {
  972. piocb->iocb.ulpStatus = ulpstatus;
  973. piocb->iocb.un.ulpWord[4] = ulpWord4;
  974. (piocb->iocb_cmpl) (phba, piocb, piocb);
  975. }
  976. }
  977. return;
  978. }
  979. /**
  980. * lpfc_sli_iocb_cmd_type - Get the iocb type
  981. * @iocb_cmnd: iocb command code.
  982. *
  983. * This function is called by ring event handler function to get the iocb type.
  984. * This function translates the iocb command to an iocb command type used to
  985. * decide the final disposition of each completed IOCB.
  986. * The function returns
  987. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  988. * LPFC_SOL_IOCB if it is a solicited iocb completion
  989. * LPFC_ABORT_IOCB if it is an abort iocb
  990. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  991. *
  992. * The caller is not required to hold any lock.
  993. **/
  994. static lpfc_iocb_type
  995. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  996. {
  997. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  998. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  999. return 0;
  1000. switch (iocb_cmnd) {
  1001. case CMD_XMIT_SEQUENCE_CR:
  1002. case CMD_XMIT_SEQUENCE_CX:
  1003. case CMD_XMIT_BCAST_CN:
  1004. case CMD_XMIT_BCAST_CX:
  1005. case CMD_ELS_REQUEST_CR:
  1006. case CMD_ELS_REQUEST_CX:
  1007. case CMD_CREATE_XRI_CR:
  1008. case CMD_CREATE_XRI_CX:
  1009. case CMD_GET_RPI_CN:
  1010. case CMD_XMIT_ELS_RSP_CX:
  1011. case CMD_GET_RPI_CR:
  1012. case CMD_FCP_IWRITE_CR:
  1013. case CMD_FCP_IWRITE_CX:
  1014. case CMD_FCP_IREAD_CR:
  1015. case CMD_FCP_IREAD_CX:
  1016. case CMD_FCP_ICMND_CR:
  1017. case CMD_FCP_ICMND_CX:
  1018. case CMD_FCP_TSEND_CX:
  1019. case CMD_FCP_TRSP_CX:
  1020. case CMD_FCP_TRECEIVE_CX:
  1021. case CMD_FCP_AUTO_TRSP_CX:
  1022. case CMD_ADAPTER_MSG:
  1023. case CMD_ADAPTER_DUMP:
  1024. case CMD_XMIT_SEQUENCE64_CR:
  1025. case CMD_XMIT_SEQUENCE64_CX:
  1026. case CMD_XMIT_BCAST64_CN:
  1027. case CMD_XMIT_BCAST64_CX:
  1028. case CMD_ELS_REQUEST64_CR:
  1029. case CMD_ELS_REQUEST64_CX:
  1030. case CMD_FCP_IWRITE64_CR:
  1031. case CMD_FCP_IWRITE64_CX:
  1032. case CMD_FCP_IREAD64_CR:
  1033. case CMD_FCP_IREAD64_CX:
  1034. case CMD_FCP_ICMND64_CR:
  1035. case CMD_FCP_ICMND64_CX:
  1036. case CMD_FCP_TSEND64_CX:
  1037. case CMD_FCP_TRSP64_CX:
  1038. case CMD_FCP_TRECEIVE64_CX:
  1039. case CMD_GEN_REQUEST64_CR:
  1040. case CMD_GEN_REQUEST64_CX:
  1041. case CMD_XMIT_ELS_RSP64_CX:
  1042. case DSSCMD_IWRITE64_CR:
  1043. case DSSCMD_IWRITE64_CX:
  1044. case DSSCMD_IREAD64_CR:
  1045. case DSSCMD_IREAD64_CX:
  1046. type = LPFC_SOL_IOCB;
  1047. break;
  1048. case CMD_ABORT_XRI_CN:
  1049. case CMD_ABORT_XRI_CX:
  1050. case CMD_CLOSE_XRI_CN:
  1051. case CMD_CLOSE_XRI_CX:
  1052. case CMD_XRI_ABORTED_CX:
  1053. case CMD_ABORT_MXRI64_CN:
  1054. case CMD_XMIT_BLS_RSP64_CX:
  1055. type = LPFC_ABORT_IOCB;
  1056. break;
  1057. case CMD_RCV_SEQUENCE_CX:
  1058. case CMD_RCV_ELS_REQ_CX:
  1059. case CMD_RCV_SEQUENCE64_CX:
  1060. case CMD_RCV_ELS_REQ64_CX:
  1061. case CMD_ASYNC_STATUS:
  1062. case CMD_IOCB_RCV_SEQ64_CX:
  1063. case CMD_IOCB_RCV_ELS64_CX:
  1064. case CMD_IOCB_RCV_CONT64_CX:
  1065. case CMD_IOCB_RET_XRI64_CX:
  1066. type = LPFC_UNSOL_IOCB;
  1067. break;
  1068. case CMD_IOCB_XMIT_MSEQ64_CR:
  1069. case CMD_IOCB_XMIT_MSEQ64_CX:
  1070. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1071. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1072. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1073. case CMD_IOCB_ABORT_EXTENDED_CN:
  1074. case CMD_IOCB_RET_HBQE64_CN:
  1075. case CMD_IOCB_FCP_IBIDIR64_CR:
  1076. case CMD_IOCB_FCP_IBIDIR64_CX:
  1077. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1078. case CMD_IOCB_LOGENTRY_CN:
  1079. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1080. printk("%s - Unhandled SLI-3 Command x%x\n",
  1081. __func__, iocb_cmnd);
  1082. type = LPFC_UNKNOWN_IOCB;
  1083. break;
  1084. default:
  1085. type = LPFC_UNKNOWN_IOCB;
  1086. break;
  1087. }
  1088. return type;
  1089. }
  1090. /**
  1091. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1092. * @phba: Pointer to HBA context object.
  1093. *
  1094. * This function is called from SLI initialization code
  1095. * to configure every ring of the HBA's SLI interface. The
  1096. * caller is not required to hold any lock. This function issues
  1097. * a config_ring mailbox command for each ring.
  1098. * This function returns zero if successful else returns a negative
  1099. * error code.
  1100. **/
  1101. static int
  1102. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1103. {
  1104. struct lpfc_sli *psli = &phba->sli;
  1105. LPFC_MBOXQ_t *pmb;
  1106. MAILBOX_t *pmbox;
  1107. int i, rc, ret = 0;
  1108. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1109. if (!pmb)
  1110. return -ENOMEM;
  1111. pmbox = &pmb->u.mb;
  1112. phba->link_state = LPFC_INIT_MBX_CMDS;
  1113. for (i = 0; i < psli->num_rings; i++) {
  1114. lpfc_config_ring(phba, i, pmb);
  1115. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1116. if (rc != MBX_SUCCESS) {
  1117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1118. "0446 Adapter failed to init (%d), "
  1119. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1120. "ring %d\n",
  1121. rc, pmbox->mbxCommand,
  1122. pmbox->mbxStatus, i);
  1123. phba->link_state = LPFC_HBA_ERROR;
  1124. ret = -ENXIO;
  1125. break;
  1126. }
  1127. }
  1128. mempool_free(pmb, phba->mbox_mem_pool);
  1129. return ret;
  1130. }
  1131. /**
  1132. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1133. * @phba: Pointer to HBA context object.
  1134. * @pring: Pointer to driver SLI ring object.
  1135. * @piocb: Pointer to the driver iocb object.
  1136. *
  1137. * This function is called with hbalock held. The function adds the
  1138. * new iocb to txcmplq of the given ring. This function always returns
  1139. * 0. If this function is called for ELS ring, this function checks if
  1140. * there is a vport associated with the ELS command. This function also
  1141. * starts els_tmofunc timer if this is an ELS command.
  1142. **/
  1143. static int
  1144. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1145. struct lpfc_iocbq *piocb)
  1146. {
  1147. list_add_tail(&piocb->list, &pring->txcmplq);
  1148. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1149. pring->txcmplq_cnt++;
  1150. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1151. pring->txcmplq_max = pring->txcmplq_cnt;
  1152. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1153. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1154. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1155. if (!piocb->vport)
  1156. BUG();
  1157. else
  1158. mod_timer(&piocb->vport->els_tmofunc,
  1159. jiffies + HZ * (phba->fc_ratov << 1));
  1160. }
  1161. return 0;
  1162. }
  1163. /**
  1164. * lpfc_sli_ringtx_get - Get first element of the txq
  1165. * @phba: Pointer to HBA context object.
  1166. * @pring: Pointer to driver SLI ring object.
  1167. *
  1168. * This function is called with hbalock held to get next
  1169. * iocb in txq of the given ring. If there is any iocb in
  1170. * the txq, the function returns first iocb in the list after
  1171. * removing the iocb from the list, else it returns NULL.
  1172. **/
  1173. struct lpfc_iocbq *
  1174. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1175. {
  1176. struct lpfc_iocbq *cmd_iocb;
  1177. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1178. if (cmd_iocb != NULL)
  1179. pring->txq_cnt--;
  1180. return cmd_iocb;
  1181. }
  1182. /**
  1183. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1184. * @phba: Pointer to HBA context object.
  1185. * @pring: Pointer to driver SLI ring object.
  1186. *
  1187. * This function is called with hbalock held and the caller must post the
  1188. * iocb without releasing the lock. If the caller releases the lock,
  1189. * iocb slot returned by the function is not guaranteed to be available.
  1190. * The function returns pointer to the next available iocb slot if there
  1191. * is available slot in the ring, else it returns NULL.
  1192. * If the get index of the ring is ahead of the put index, the function
  1193. * will post an error attention event to the worker thread to take the
  1194. * HBA to offline state.
  1195. **/
  1196. static IOCB_t *
  1197. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1198. {
  1199. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1200. uint32_t max_cmd_idx = pring->numCiocb;
  1201. if ((pring->next_cmdidx == pring->cmdidx) &&
  1202. (++pring->next_cmdidx >= max_cmd_idx))
  1203. pring->next_cmdidx = 0;
  1204. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1205. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1206. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1207. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1208. "0315 Ring %d issue: portCmdGet %d "
  1209. "is bigger than cmd ring %d\n",
  1210. pring->ringno,
  1211. pring->local_getidx, max_cmd_idx);
  1212. phba->link_state = LPFC_HBA_ERROR;
  1213. /*
  1214. * All error attention handlers are posted to
  1215. * worker thread
  1216. */
  1217. phba->work_ha |= HA_ERATT;
  1218. phba->work_hs = HS_FFER3;
  1219. lpfc_worker_wake_up(phba);
  1220. return NULL;
  1221. }
  1222. if (pring->local_getidx == pring->next_cmdidx)
  1223. return NULL;
  1224. }
  1225. return lpfc_cmd_iocb(phba, pring);
  1226. }
  1227. /**
  1228. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1229. * @phba: Pointer to HBA context object.
  1230. * @iocbq: Pointer to driver iocb object.
  1231. *
  1232. * This function gets an iotag for the iocb. If there is no unused iotag and
  1233. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1234. * array and assigns a new iotag.
  1235. * The function returns the allocated iotag if successful, else returns zero.
  1236. * Zero is not a valid iotag.
  1237. * The caller is not required to hold any lock.
  1238. **/
  1239. uint16_t
  1240. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1241. {
  1242. struct lpfc_iocbq **new_arr;
  1243. struct lpfc_iocbq **old_arr;
  1244. size_t new_len;
  1245. struct lpfc_sli *psli = &phba->sli;
  1246. uint16_t iotag;
  1247. spin_lock_irq(&phba->hbalock);
  1248. iotag = psli->last_iotag;
  1249. if(++iotag < psli->iocbq_lookup_len) {
  1250. psli->last_iotag = iotag;
  1251. psli->iocbq_lookup[iotag] = iocbq;
  1252. spin_unlock_irq(&phba->hbalock);
  1253. iocbq->iotag = iotag;
  1254. return iotag;
  1255. } else if (psli->iocbq_lookup_len < (0xffff
  1256. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1257. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1258. spin_unlock_irq(&phba->hbalock);
  1259. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1260. GFP_KERNEL);
  1261. if (new_arr) {
  1262. spin_lock_irq(&phba->hbalock);
  1263. old_arr = psli->iocbq_lookup;
  1264. if (new_len <= psli->iocbq_lookup_len) {
  1265. /* highly unprobable case */
  1266. kfree(new_arr);
  1267. iotag = psli->last_iotag;
  1268. if(++iotag < psli->iocbq_lookup_len) {
  1269. psli->last_iotag = iotag;
  1270. psli->iocbq_lookup[iotag] = iocbq;
  1271. spin_unlock_irq(&phba->hbalock);
  1272. iocbq->iotag = iotag;
  1273. return iotag;
  1274. }
  1275. spin_unlock_irq(&phba->hbalock);
  1276. return 0;
  1277. }
  1278. if (psli->iocbq_lookup)
  1279. memcpy(new_arr, old_arr,
  1280. ((psli->last_iotag + 1) *
  1281. sizeof (struct lpfc_iocbq *)));
  1282. psli->iocbq_lookup = new_arr;
  1283. psli->iocbq_lookup_len = new_len;
  1284. psli->last_iotag = iotag;
  1285. psli->iocbq_lookup[iotag] = iocbq;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. iocbq->iotag = iotag;
  1288. kfree(old_arr);
  1289. return iotag;
  1290. }
  1291. } else
  1292. spin_unlock_irq(&phba->hbalock);
  1293. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1294. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1295. psli->last_iotag);
  1296. return 0;
  1297. }
  1298. /**
  1299. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1300. * @phba: Pointer to HBA context object.
  1301. * @pring: Pointer to driver SLI ring object.
  1302. * @iocb: Pointer to iocb slot in the ring.
  1303. * @nextiocb: Pointer to driver iocb object which need to be
  1304. * posted to firmware.
  1305. *
  1306. * This function is called with hbalock held to post a new iocb to
  1307. * the firmware. This function copies the new iocb to ring iocb slot and
  1308. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1309. * a completion call back for this iocb else the function will free the
  1310. * iocb object.
  1311. **/
  1312. static void
  1313. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1314. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1315. {
  1316. /*
  1317. * Set up an iotag
  1318. */
  1319. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1320. if (pring->ringno == LPFC_ELS_RING) {
  1321. lpfc_debugfs_slow_ring_trc(phba,
  1322. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1323. *(((uint32_t *) &nextiocb->iocb) + 4),
  1324. *(((uint32_t *) &nextiocb->iocb) + 6),
  1325. *(((uint32_t *) &nextiocb->iocb) + 7));
  1326. }
  1327. /*
  1328. * Issue iocb command to adapter
  1329. */
  1330. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1331. wmb();
  1332. pring->stats.iocb_cmd++;
  1333. /*
  1334. * If there is no completion routine to call, we can release the
  1335. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1336. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1337. */
  1338. if (nextiocb->iocb_cmpl)
  1339. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1340. else
  1341. __lpfc_sli_release_iocbq(phba, nextiocb);
  1342. /*
  1343. * Let the HBA know what IOCB slot will be the next one the
  1344. * driver will put a command into.
  1345. */
  1346. pring->cmdidx = pring->next_cmdidx;
  1347. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1348. }
  1349. /**
  1350. * lpfc_sli_update_full_ring - Update the chip attention register
  1351. * @phba: Pointer to HBA context object.
  1352. * @pring: Pointer to driver SLI ring object.
  1353. *
  1354. * The caller is not required to hold any lock for calling this function.
  1355. * This function updates the chip attention bits for the ring to inform firmware
  1356. * that there are pending work to be done for this ring and requests an
  1357. * interrupt when there is space available in the ring. This function is
  1358. * called when the driver is unable to post more iocbs to the ring due
  1359. * to unavailability of space in the ring.
  1360. **/
  1361. static void
  1362. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1363. {
  1364. int ringno = pring->ringno;
  1365. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1366. wmb();
  1367. /*
  1368. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1369. * The HBA will tell us when an IOCB entry is available.
  1370. */
  1371. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1372. readl(phba->CAregaddr); /* flush */
  1373. pring->stats.iocb_cmd_full++;
  1374. }
  1375. /**
  1376. * lpfc_sli_update_ring - Update chip attention register
  1377. * @phba: Pointer to HBA context object.
  1378. * @pring: Pointer to driver SLI ring object.
  1379. *
  1380. * This function updates the chip attention register bit for the
  1381. * given ring to inform HBA that there is more work to be done
  1382. * in this ring. The caller is not required to hold any lock.
  1383. **/
  1384. static void
  1385. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1386. {
  1387. int ringno = pring->ringno;
  1388. /*
  1389. * Tell the HBA that there is work to do in this ring.
  1390. */
  1391. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1392. wmb();
  1393. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1394. readl(phba->CAregaddr); /* flush */
  1395. }
  1396. }
  1397. /**
  1398. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1399. * @phba: Pointer to HBA context object.
  1400. * @pring: Pointer to driver SLI ring object.
  1401. *
  1402. * This function is called with hbalock held to post pending iocbs
  1403. * in the txq to the firmware. This function is called when driver
  1404. * detects space available in the ring.
  1405. **/
  1406. static void
  1407. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1408. {
  1409. IOCB_t *iocb;
  1410. struct lpfc_iocbq *nextiocb;
  1411. /*
  1412. * Check to see if:
  1413. * (a) there is anything on the txq to send
  1414. * (b) link is up
  1415. * (c) link attention events can be processed (fcp ring only)
  1416. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1417. */
  1418. if (pring->txq_cnt &&
  1419. lpfc_is_link_up(phba) &&
  1420. (pring->ringno != phba->sli.fcp_ring ||
  1421. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1422. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1423. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1424. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1425. if (iocb)
  1426. lpfc_sli_update_ring(phba, pring);
  1427. else
  1428. lpfc_sli_update_full_ring(phba, pring);
  1429. }
  1430. return;
  1431. }
  1432. /**
  1433. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1434. * @phba: Pointer to HBA context object.
  1435. * @hbqno: HBQ number.
  1436. *
  1437. * This function is called with hbalock held to get the next
  1438. * available slot for the given HBQ. If there is free slot
  1439. * available for the HBQ it will return pointer to the next available
  1440. * HBQ entry else it will return NULL.
  1441. **/
  1442. static struct lpfc_hbq_entry *
  1443. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1444. {
  1445. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1446. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1447. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1448. hbqp->next_hbqPutIdx = 0;
  1449. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1450. uint32_t raw_index = phba->hbq_get[hbqno];
  1451. uint32_t getidx = le32_to_cpu(raw_index);
  1452. hbqp->local_hbqGetIdx = getidx;
  1453. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1454. lpfc_printf_log(phba, KERN_ERR,
  1455. LOG_SLI | LOG_VPORT,
  1456. "1802 HBQ %d: local_hbqGetIdx "
  1457. "%u is > than hbqp->entry_count %u\n",
  1458. hbqno, hbqp->local_hbqGetIdx,
  1459. hbqp->entry_count);
  1460. phba->link_state = LPFC_HBA_ERROR;
  1461. return NULL;
  1462. }
  1463. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1464. return NULL;
  1465. }
  1466. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1467. hbqp->hbqPutIdx;
  1468. }
  1469. /**
  1470. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1471. * @phba: Pointer to HBA context object.
  1472. *
  1473. * This function is called with no lock held to free all the
  1474. * hbq buffers while uninitializing the SLI interface. It also
  1475. * frees the HBQ buffers returned by the firmware but not yet
  1476. * processed by the upper layers.
  1477. **/
  1478. void
  1479. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1480. {
  1481. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1482. struct hbq_dmabuf *hbq_buf;
  1483. unsigned long flags;
  1484. int i, hbq_count;
  1485. uint32_t hbqno;
  1486. hbq_count = lpfc_sli_hbq_count();
  1487. /* Return all memory used by all HBQs */
  1488. spin_lock_irqsave(&phba->hbalock, flags);
  1489. for (i = 0; i < hbq_count; ++i) {
  1490. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1491. &phba->hbqs[i].hbq_buffer_list, list) {
  1492. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1493. list_del(&hbq_buf->dbuf.list);
  1494. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1495. }
  1496. phba->hbqs[i].buffer_count = 0;
  1497. }
  1498. /* Return all HBQ buffer that are in-fly */
  1499. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1500. list) {
  1501. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1502. list_del(&hbq_buf->dbuf.list);
  1503. if (hbq_buf->tag == -1) {
  1504. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1505. (phba, hbq_buf);
  1506. } else {
  1507. hbqno = hbq_buf->tag >> 16;
  1508. if (hbqno >= LPFC_MAX_HBQS)
  1509. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1510. (phba, hbq_buf);
  1511. else
  1512. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1513. hbq_buf);
  1514. }
  1515. }
  1516. /* Mark the HBQs not in use */
  1517. phba->hbq_in_use = 0;
  1518. spin_unlock_irqrestore(&phba->hbalock, flags);
  1519. }
  1520. /**
  1521. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1522. * @phba: Pointer to HBA context object.
  1523. * @hbqno: HBQ number.
  1524. * @hbq_buf: Pointer to HBQ buffer.
  1525. *
  1526. * This function is called with the hbalock held to post a
  1527. * hbq buffer to the firmware. If the function finds an empty
  1528. * slot in the HBQ, it will post the buffer. The function will return
  1529. * pointer to the hbq entry if it successfully post the buffer
  1530. * else it will return NULL.
  1531. **/
  1532. static int
  1533. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1534. struct hbq_dmabuf *hbq_buf)
  1535. {
  1536. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1537. }
  1538. /**
  1539. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1540. * @phba: Pointer to HBA context object.
  1541. * @hbqno: HBQ number.
  1542. * @hbq_buf: Pointer to HBQ buffer.
  1543. *
  1544. * This function is called with the hbalock held to post a hbq buffer to the
  1545. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1546. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1547. * it successfully post the buffer else it will return an error.
  1548. **/
  1549. static int
  1550. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1551. struct hbq_dmabuf *hbq_buf)
  1552. {
  1553. struct lpfc_hbq_entry *hbqe;
  1554. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1555. /* Get next HBQ entry slot to use */
  1556. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1557. if (hbqe) {
  1558. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1559. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1560. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1561. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1562. hbqe->bde.tus.f.bdeFlags = 0;
  1563. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1564. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1565. /* Sync SLIM */
  1566. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1567. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1568. /* flush */
  1569. readl(phba->hbq_put + hbqno);
  1570. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1571. return 0;
  1572. } else
  1573. return -ENOMEM;
  1574. }
  1575. /**
  1576. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1577. * @phba: Pointer to HBA context object.
  1578. * @hbqno: HBQ number.
  1579. * @hbq_buf: Pointer to HBQ buffer.
  1580. *
  1581. * This function is called with the hbalock held to post an RQE to the SLI4
  1582. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1583. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1584. **/
  1585. static int
  1586. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1587. struct hbq_dmabuf *hbq_buf)
  1588. {
  1589. int rc;
  1590. struct lpfc_rqe hrqe;
  1591. struct lpfc_rqe drqe;
  1592. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1593. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1594. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1595. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1596. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1597. &hrqe, &drqe);
  1598. if (rc < 0)
  1599. return rc;
  1600. hbq_buf->tag = rc;
  1601. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1602. return 0;
  1603. }
  1604. /* HBQ for ELS and CT traffic. */
  1605. static struct lpfc_hbq_init lpfc_els_hbq = {
  1606. .rn = 1,
  1607. .entry_count = 256,
  1608. .mask_count = 0,
  1609. .profile = 0,
  1610. .ring_mask = (1 << LPFC_ELS_RING),
  1611. .buffer_count = 0,
  1612. .init_count = 40,
  1613. .add_count = 40,
  1614. };
  1615. /* HBQ for the extra ring if needed */
  1616. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1617. .rn = 1,
  1618. .entry_count = 200,
  1619. .mask_count = 0,
  1620. .profile = 0,
  1621. .ring_mask = (1 << LPFC_EXTRA_RING),
  1622. .buffer_count = 0,
  1623. .init_count = 0,
  1624. .add_count = 5,
  1625. };
  1626. /* Array of HBQs */
  1627. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1628. &lpfc_els_hbq,
  1629. &lpfc_extra_hbq,
  1630. };
  1631. /**
  1632. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1633. * @phba: Pointer to HBA context object.
  1634. * @hbqno: HBQ number.
  1635. * @count: Number of HBQ buffers to be posted.
  1636. *
  1637. * This function is called with no lock held to post more hbq buffers to the
  1638. * given HBQ. The function returns the number of HBQ buffers successfully
  1639. * posted.
  1640. **/
  1641. static int
  1642. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1643. {
  1644. uint32_t i, posted = 0;
  1645. unsigned long flags;
  1646. struct hbq_dmabuf *hbq_buffer;
  1647. LIST_HEAD(hbq_buf_list);
  1648. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1649. return 0;
  1650. if ((phba->hbqs[hbqno].buffer_count + count) >
  1651. lpfc_hbq_defs[hbqno]->entry_count)
  1652. count = lpfc_hbq_defs[hbqno]->entry_count -
  1653. phba->hbqs[hbqno].buffer_count;
  1654. if (!count)
  1655. return 0;
  1656. /* Allocate HBQ entries */
  1657. for (i = 0; i < count; i++) {
  1658. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1659. if (!hbq_buffer)
  1660. break;
  1661. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1662. }
  1663. /* Check whether HBQ is still in use */
  1664. spin_lock_irqsave(&phba->hbalock, flags);
  1665. if (!phba->hbq_in_use)
  1666. goto err;
  1667. while (!list_empty(&hbq_buf_list)) {
  1668. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1669. dbuf.list);
  1670. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1671. (hbqno << 16));
  1672. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1673. phba->hbqs[hbqno].buffer_count++;
  1674. posted++;
  1675. } else
  1676. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1677. }
  1678. spin_unlock_irqrestore(&phba->hbalock, flags);
  1679. return posted;
  1680. err:
  1681. spin_unlock_irqrestore(&phba->hbalock, flags);
  1682. while (!list_empty(&hbq_buf_list)) {
  1683. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1684. dbuf.list);
  1685. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1686. }
  1687. return 0;
  1688. }
  1689. /**
  1690. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1691. * @phba: Pointer to HBA context object.
  1692. * @qno: HBQ number.
  1693. *
  1694. * This function posts more buffers to the HBQ. This function
  1695. * is called with no lock held. The function returns the number of HBQ entries
  1696. * successfully allocated.
  1697. **/
  1698. int
  1699. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1700. {
  1701. if (phba->sli_rev == LPFC_SLI_REV4)
  1702. return 0;
  1703. else
  1704. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1705. lpfc_hbq_defs[qno]->add_count);
  1706. }
  1707. /**
  1708. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1709. * @phba: Pointer to HBA context object.
  1710. * @qno: HBQ queue number.
  1711. *
  1712. * This function is called from SLI initialization code path with
  1713. * no lock held to post initial HBQ buffers to firmware. The
  1714. * function returns the number of HBQ entries successfully allocated.
  1715. **/
  1716. static int
  1717. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1718. {
  1719. if (phba->sli_rev == LPFC_SLI_REV4)
  1720. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1721. lpfc_hbq_defs[qno]->entry_count);
  1722. else
  1723. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1724. lpfc_hbq_defs[qno]->init_count);
  1725. }
  1726. /**
  1727. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1728. * @phba: Pointer to HBA context object.
  1729. * @hbqno: HBQ number.
  1730. *
  1731. * This function removes the first hbq buffer on an hbq list and returns a
  1732. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1733. **/
  1734. static struct hbq_dmabuf *
  1735. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1736. {
  1737. struct lpfc_dmabuf *d_buf;
  1738. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1739. if (!d_buf)
  1740. return NULL;
  1741. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1742. }
  1743. /**
  1744. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1745. * @phba: Pointer to HBA context object.
  1746. * @tag: Tag of the hbq buffer.
  1747. *
  1748. * This function is called with hbalock held. This function searches
  1749. * for the hbq buffer associated with the given tag in the hbq buffer
  1750. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1751. * it returns NULL.
  1752. **/
  1753. static struct hbq_dmabuf *
  1754. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1755. {
  1756. struct lpfc_dmabuf *d_buf;
  1757. struct hbq_dmabuf *hbq_buf;
  1758. uint32_t hbqno;
  1759. hbqno = tag >> 16;
  1760. if (hbqno >= LPFC_MAX_HBQS)
  1761. return NULL;
  1762. spin_lock_irq(&phba->hbalock);
  1763. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1764. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1765. if (hbq_buf->tag == tag) {
  1766. spin_unlock_irq(&phba->hbalock);
  1767. return hbq_buf;
  1768. }
  1769. }
  1770. spin_unlock_irq(&phba->hbalock);
  1771. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1772. "1803 Bad hbq tag. Data: x%x x%x\n",
  1773. tag, phba->hbqs[tag >> 16].buffer_count);
  1774. return NULL;
  1775. }
  1776. /**
  1777. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1778. * @phba: Pointer to HBA context object.
  1779. * @hbq_buffer: Pointer to HBQ buffer.
  1780. *
  1781. * This function is called with hbalock. This function gives back
  1782. * the hbq buffer to firmware. If the HBQ does not have space to
  1783. * post the buffer, it will free the buffer.
  1784. **/
  1785. void
  1786. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1787. {
  1788. uint32_t hbqno;
  1789. if (hbq_buffer) {
  1790. hbqno = hbq_buffer->tag >> 16;
  1791. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1792. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1793. }
  1794. }
  1795. /**
  1796. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1797. * @mbxCommand: mailbox command code.
  1798. *
  1799. * This function is called by the mailbox event handler function to verify
  1800. * that the completed mailbox command is a legitimate mailbox command. If the
  1801. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1802. * and the mailbox event handler will take the HBA offline.
  1803. **/
  1804. static int
  1805. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1806. {
  1807. uint8_t ret;
  1808. switch (mbxCommand) {
  1809. case MBX_LOAD_SM:
  1810. case MBX_READ_NV:
  1811. case MBX_WRITE_NV:
  1812. case MBX_WRITE_VPARMS:
  1813. case MBX_RUN_BIU_DIAG:
  1814. case MBX_INIT_LINK:
  1815. case MBX_DOWN_LINK:
  1816. case MBX_CONFIG_LINK:
  1817. case MBX_CONFIG_RING:
  1818. case MBX_RESET_RING:
  1819. case MBX_READ_CONFIG:
  1820. case MBX_READ_RCONFIG:
  1821. case MBX_READ_SPARM:
  1822. case MBX_READ_STATUS:
  1823. case MBX_READ_RPI:
  1824. case MBX_READ_XRI:
  1825. case MBX_READ_REV:
  1826. case MBX_READ_LNK_STAT:
  1827. case MBX_REG_LOGIN:
  1828. case MBX_UNREG_LOGIN:
  1829. case MBX_CLEAR_LA:
  1830. case MBX_DUMP_MEMORY:
  1831. case MBX_DUMP_CONTEXT:
  1832. case MBX_RUN_DIAGS:
  1833. case MBX_RESTART:
  1834. case MBX_UPDATE_CFG:
  1835. case MBX_DOWN_LOAD:
  1836. case MBX_DEL_LD_ENTRY:
  1837. case MBX_RUN_PROGRAM:
  1838. case MBX_SET_MASK:
  1839. case MBX_SET_VARIABLE:
  1840. case MBX_UNREG_D_ID:
  1841. case MBX_KILL_BOARD:
  1842. case MBX_CONFIG_FARP:
  1843. case MBX_BEACON:
  1844. case MBX_LOAD_AREA:
  1845. case MBX_RUN_BIU_DIAG64:
  1846. case MBX_CONFIG_PORT:
  1847. case MBX_READ_SPARM64:
  1848. case MBX_READ_RPI64:
  1849. case MBX_REG_LOGIN64:
  1850. case MBX_READ_TOPOLOGY:
  1851. case MBX_WRITE_WWN:
  1852. case MBX_SET_DEBUG:
  1853. case MBX_LOAD_EXP_ROM:
  1854. case MBX_ASYNCEVT_ENABLE:
  1855. case MBX_REG_VPI:
  1856. case MBX_UNREG_VPI:
  1857. case MBX_HEARTBEAT:
  1858. case MBX_PORT_CAPABILITIES:
  1859. case MBX_PORT_IOV_CONTROL:
  1860. case MBX_SLI4_CONFIG:
  1861. case MBX_SLI4_REQ_FTRS:
  1862. case MBX_REG_FCFI:
  1863. case MBX_UNREG_FCFI:
  1864. case MBX_REG_VFI:
  1865. case MBX_UNREG_VFI:
  1866. case MBX_INIT_VPI:
  1867. case MBX_INIT_VFI:
  1868. case MBX_RESUME_RPI:
  1869. case MBX_READ_EVENT_LOG_STATUS:
  1870. case MBX_READ_EVENT_LOG:
  1871. case MBX_SECURITY_MGMT:
  1872. case MBX_AUTH_PORT:
  1873. ret = mbxCommand;
  1874. break;
  1875. default:
  1876. ret = MBX_SHUTDOWN;
  1877. break;
  1878. }
  1879. return ret;
  1880. }
  1881. /**
  1882. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1883. * @phba: Pointer to HBA context object.
  1884. * @pmboxq: Pointer to mailbox command.
  1885. *
  1886. * This is completion handler function for mailbox commands issued from
  1887. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1888. * mailbox event handler function with no lock held. This function
  1889. * will wake up thread waiting on the wait queue pointed by context1
  1890. * of the mailbox.
  1891. **/
  1892. void
  1893. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1894. {
  1895. wait_queue_head_t *pdone_q;
  1896. unsigned long drvr_flag;
  1897. /*
  1898. * If pdone_q is empty, the driver thread gave up waiting and
  1899. * continued running.
  1900. */
  1901. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1902. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1903. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1904. if (pdone_q)
  1905. wake_up_interruptible(pdone_q);
  1906. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1907. return;
  1908. }
  1909. /**
  1910. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1911. * @phba: Pointer to HBA context object.
  1912. * @pmb: Pointer to mailbox object.
  1913. *
  1914. * This function is the default mailbox completion handler. It
  1915. * frees the memory resources associated with the completed mailbox
  1916. * command. If the completed command is a REG_LOGIN mailbox command,
  1917. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1918. **/
  1919. void
  1920. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1921. {
  1922. struct lpfc_vport *vport = pmb->vport;
  1923. struct lpfc_dmabuf *mp;
  1924. struct lpfc_nodelist *ndlp;
  1925. struct Scsi_Host *shost;
  1926. uint16_t rpi, vpi;
  1927. int rc;
  1928. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1929. if (mp) {
  1930. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1931. kfree(mp);
  1932. }
  1933. /*
  1934. * If a REG_LOGIN succeeded after node is destroyed or node
  1935. * is in re-discovery driver need to cleanup the RPI.
  1936. */
  1937. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1938. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1939. !pmb->u.mb.mbxStatus) {
  1940. rpi = pmb->u.mb.un.varWords[0];
  1941. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1942. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1943. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1944. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1945. if (rc != MBX_NOT_FINISHED)
  1946. return;
  1947. }
  1948. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1949. !(phba->pport->load_flag & FC_UNLOADING) &&
  1950. !pmb->u.mb.mbxStatus) {
  1951. shost = lpfc_shost_from_vport(vport);
  1952. spin_lock_irq(shost->host_lock);
  1953. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1954. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1955. spin_unlock_irq(shost->host_lock);
  1956. }
  1957. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1958. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1959. lpfc_nlp_put(ndlp);
  1960. pmb->context2 = NULL;
  1961. }
  1962. /* Check security permission status on INIT_LINK mailbox command */
  1963. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1964. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1965. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1966. "2860 SLI authentication is required "
  1967. "for INIT_LINK but has not done yet\n");
  1968. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1969. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1970. else
  1971. mempool_free(pmb, phba->mbox_mem_pool);
  1972. }
  1973. /**
  1974. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1975. * @phba: Pointer to HBA context object.
  1976. *
  1977. * This function is called with no lock held. This function processes all
  1978. * the completed mailbox commands and gives it to upper layers. The interrupt
  1979. * service routine processes mailbox completion interrupt and adds completed
  1980. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1981. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1982. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1983. * function returns the mailbox commands to the upper layer by calling the
  1984. * completion handler function of each mailbox.
  1985. **/
  1986. int
  1987. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1988. {
  1989. MAILBOX_t *pmbox;
  1990. LPFC_MBOXQ_t *pmb;
  1991. int rc;
  1992. LIST_HEAD(cmplq);
  1993. phba->sli.slistat.mbox_event++;
  1994. /* Get all completed mailboxe buffers into the cmplq */
  1995. spin_lock_irq(&phba->hbalock);
  1996. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1997. spin_unlock_irq(&phba->hbalock);
  1998. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1999. do {
  2000. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2001. if (pmb == NULL)
  2002. break;
  2003. pmbox = &pmb->u.mb;
  2004. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2005. if (pmb->vport) {
  2006. lpfc_debugfs_disc_trc(pmb->vport,
  2007. LPFC_DISC_TRC_MBOX_VPORT,
  2008. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2009. (uint32_t)pmbox->mbxCommand,
  2010. pmbox->un.varWords[0],
  2011. pmbox->un.varWords[1]);
  2012. }
  2013. else {
  2014. lpfc_debugfs_disc_trc(phba->pport,
  2015. LPFC_DISC_TRC_MBOX,
  2016. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2017. (uint32_t)pmbox->mbxCommand,
  2018. pmbox->un.varWords[0],
  2019. pmbox->un.varWords[1]);
  2020. }
  2021. }
  2022. /*
  2023. * It is a fatal error if unknown mbox command completion.
  2024. */
  2025. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2026. MBX_SHUTDOWN) {
  2027. /* Unknown mailbox command compl */
  2028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2029. "(%d):0323 Unknown Mailbox command "
  2030. "x%x (x%x) Cmpl\n",
  2031. pmb->vport ? pmb->vport->vpi : 0,
  2032. pmbox->mbxCommand,
  2033. lpfc_sli4_mbox_opcode_get(phba, pmb));
  2034. phba->link_state = LPFC_HBA_ERROR;
  2035. phba->work_hs = HS_FFER3;
  2036. lpfc_handle_eratt(phba);
  2037. continue;
  2038. }
  2039. if (pmbox->mbxStatus) {
  2040. phba->sli.slistat.mbox_stat_err++;
  2041. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2042. /* Mbox cmd cmpl error - RETRYing */
  2043. lpfc_printf_log(phba, KERN_INFO,
  2044. LOG_MBOX | LOG_SLI,
  2045. "(%d):0305 Mbox cmd cmpl "
  2046. "error - RETRYing Data: x%x "
  2047. "(x%x) x%x x%x x%x\n",
  2048. pmb->vport ? pmb->vport->vpi :0,
  2049. pmbox->mbxCommand,
  2050. lpfc_sli4_mbox_opcode_get(phba,
  2051. pmb),
  2052. pmbox->mbxStatus,
  2053. pmbox->un.varWords[0],
  2054. pmb->vport->port_state);
  2055. pmbox->mbxStatus = 0;
  2056. pmbox->mbxOwner = OWN_HOST;
  2057. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2058. if (rc != MBX_NOT_FINISHED)
  2059. continue;
  2060. }
  2061. }
  2062. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2063. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2064. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  2065. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2066. pmb->vport ? pmb->vport->vpi : 0,
  2067. pmbox->mbxCommand,
  2068. lpfc_sli4_mbox_opcode_get(phba, pmb),
  2069. pmb->mbox_cmpl,
  2070. *((uint32_t *) pmbox),
  2071. pmbox->un.varWords[0],
  2072. pmbox->un.varWords[1],
  2073. pmbox->un.varWords[2],
  2074. pmbox->un.varWords[3],
  2075. pmbox->un.varWords[4],
  2076. pmbox->un.varWords[5],
  2077. pmbox->un.varWords[6],
  2078. pmbox->un.varWords[7]);
  2079. if (pmb->mbox_cmpl)
  2080. pmb->mbox_cmpl(phba,pmb);
  2081. } while (1);
  2082. return 0;
  2083. }
  2084. /**
  2085. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2086. * @phba: Pointer to HBA context object.
  2087. * @pring: Pointer to driver SLI ring object.
  2088. * @tag: buffer tag.
  2089. *
  2090. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2091. * is set in the tag the buffer is posted for a particular exchange,
  2092. * the function will return the buffer without replacing the buffer.
  2093. * If the buffer is for unsolicited ELS or CT traffic, this function
  2094. * returns the buffer and also posts another buffer to the firmware.
  2095. **/
  2096. static struct lpfc_dmabuf *
  2097. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2098. struct lpfc_sli_ring *pring,
  2099. uint32_t tag)
  2100. {
  2101. struct hbq_dmabuf *hbq_entry;
  2102. if (tag & QUE_BUFTAG_BIT)
  2103. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2104. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2105. if (!hbq_entry)
  2106. return NULL;
  2107. return &hbq_entry->dbuf;
  2108. }
  2109. /**
  2110. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2111. * @phba: Pointer to HBA context object.
  2112. * @pring: Pointer to driver SLI ring object.
  2113. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2114. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2115. * @fch_type: the type for the first frame of the sequence.
  2116. *
  2117. * This function is called with no lock held. This function uses the r_ctl and
  2118. * type of the received sequence to find the correct callback function to call
  2119. * to process the sequence.
  2120. **/
  2121. static int
  2122. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2123. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2124. uint32_t fch_type)
  2125. {
  2126. int i;
  2127. /* unSolicited Responses */
  2128. if (pring->prt[0].profile) {
  2129. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2130. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2131. saveq);
  2132. return 1;
  2133. }
  2134. /* We must search, based on rctl / type
  2135. for the right routine */
  2136. for (i = 0; i < pring->num_mask; i++) {
  2137. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2138. (pring->prt[i].type == fch_type)) {
  2139. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2140. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2141. (phba, pring, saveq);
  2142. return 1;
  2143. }
  2144. }
  2145. return 0;
  2146. }
  2147. /**
  2148. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2149. * @phba: Pointer to HBA context object.
  2150. * @pring: Pointer to driver SLI ring object.
  2151. * @saveq: Pointer to the unsolicited iocb.
  2152. *
  2153. * This function is called with no lock held by the ring event handler
  2154. * when there is an unsolicited iocb posted to the response ring by the
  2155. * firmware. This function gets the buffer associated with the iocbs
  2156. * and calls the event handler for the ring. This function handles both
  2157. * qring buffers and hbq buffers.
  2158. * When the function returns 1 the caller can free the iocb object otherwise
  2159. * upper layer functions will free the iocb objects.
  2160. **/
  2161. static int
  2162. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2163. struct lpfc_iocbq *saveq)
  2164. {
  2165. IOCB_t * irsp;
  2166. WORD5 * w5p;
  2167. uint32_t Rctl, Type;
  2168. uint32_t match;
  2169. struct lpfc_iocbq *iocbq;
  2170. struct lpfc_dmabuf *dmzbuf;
  2171. match = 0;
  2172. irsp = &(saveq->iocb);
  2173. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2174. if (pring->lpfc_sli_rcv_async_status)
  2175. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2176. else
  2177. lpfc_printf_log(phba,
  2178. KERN_WARNING,
  2179. LOG_SLI,
  2180. "0316 Ring %d handler: unexpected "
  2181. "ASYNC_STATUS iocb received evt_code "
  2182. "0x%x\n",
  2183. pring->ringno,
  2184. irsp->un.asyncstat.evt_code);
  2185. return 1;
  2186. }
  2187. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2188. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2189. if (irsp->ulpBdeCount > 0) {
  2190. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2191. irsp->un.ulpWord[3]);
  2192. lpfc_in_buf_free(phba, dmzbuf);
  2193. }
  2194. if (irsp->ulpBdeCount > 1) {
  2195. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2196. irsp->unsli3.sli3Words[3]);
  2197. lpfc_in_buf_free(phba, dmzbuf);
  2198. }
  2199. if (irsp->ulpBdeCount > 2) {
  2200. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2201. irsp->unsli3.sli3Words[7]);
  2202. lpfc_in_buf_free(phba, dmzbuf);
  2203. }
  2204. return 1;
  2205. }
  2206. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2207. if (irsp->ulpBdeCount != 0) {
  2208. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2209. irsp->un.ulpWord[3]);
  2210. if (!saveq->context2)
  2211. lpfc_printf_log(phba,
  2212. KERN_ERR,
  2213. LOG_SLI,
  2214. "0341 Ring %d Cannot find buffer for "
  2215. "an unsolicited iocb. tag 0x%x\n",
  2216. pring->ringno,
  2217. irsp->un.ulpWord[3]);
  2218. }
  2219. if (irsp->ulpBdeCount == 2) {
  2220. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2221. irsp->unsli3.sli3Words[7]);
  2222. if (!saveq->context3)
  2223. lpfc_printf_log(phba,
  2224. KERN_ERR,
  2225. LOG_SLI,
  2226. "0342 Ring %d Cannot find buffer for an"
  2227. " unsolicited iocb. tag 0x%x\n",
  2228. pring->ringno,
  2229. irsp->unsli3.sli3Words[7]);
  2230. }
  2231. list_for_each_entry(iocbq, &saveq->list, list) {
  2232. irsp = &(iocbq->iocb);
  2233. if (irsp->ulpBdeCount != 0) {
  2234. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2235. irsp->un.ulpWord[3]);
  2236. if (!iocbq->context2)
  2237. lpfc_printf_log(phba,
  2238. KERN_ERR,
  2239. LOG_SLI,
  2240. "0343 Ring %d Cannot find "
  2241. "buffer for an unsolicited iocb"
  2242. ". tag 0x%x\n", pring->ringno,
  2243. irsp->un.ulpWord[3]);
  2244. }
  2245. if (irsp->ulpBdeCount == 2) {
  2246. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2247. irsp->unsli3.sli3Words[7]);
  2248. if (!iocbq->context3)
  2249. lpfc_printf_log(phba,
  2250. KERN_ERR,
  2251. LOG_SLI,
  2252. "0344 Ring %d Cannot find "
  2253. "buffer for an unsolicited "
  2254. "iocb. tag 0x%x\n",
  2255. pring->ringno,
  2256. irsp->unsli3.sli3Words[7]);
  2257. }
  2258. }
  2259. }
  2260. if (irsp->ulpBdeCount != 0 &&
  2261. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2262. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2263. int found = 0;
  2264. /* search continue save q for same XRI */
  2265. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2266. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  2267. list_add_tail(&saveq->list, &iocbq->list);
  2268. found = 1;
  2269. break;
  2270. }
  2271. }
  2272. if (!found)
  2273. list_add_tail(&saveq->clist,
  2274. &pring->iocb_continue_saveq);
  2275. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2276. list_del_init(&iocbq->clist);
  2277. saveq = iocbq;
  2278. irsp = &(saveq->iocb);
  2279. } else
  2280. return 0;
  2281. }
  2282. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2283. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2284. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2285. Rctl = FC_RCTL_ELS_REQ;
  2286. Type = FC_TYPE_ELS;
  2287. } else {
  2288. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2289. Rctl = w5p->hcsw.Rctl;
  2290. Type = w5p->hcsw.Type;
  2291. /* Firmware Workaround */
  2292. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2293. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2294. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2295. Rctl = FC_RCTL_ELS_REQ;
  2296. Type = FC_TYPE_ELS;
  2297. w5p->hcsw.Rctl = Rctl;
  2298. w5p->hcsw.Type = Type;
  2299. }
  2300. }
  2301. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2302. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2303. "0313 Ring %d handler: unexpected Rctl x%x "
  2304. "Type x%x received\n",
  2305. pring->ringno, Rctl, Type);
  2306. return 1;
  2307. }
  2308. /**
  2309. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2310. * @phba: Pointer to HBA context object.
  2311. * @pring: Pointer to driver SLI ring object.
  2312. * @prspiocb: Pointer to response iocb object.
  2313. *
  2314. * This function looks up the iocb_lookup table to get the command iocb
  2315. * corresponding to the given response iocb using the iotag of the
  2316. * response iocb. This function is called with the hbalock held.
  2317. * This function returns the command iocb object if it finds the command
  2318. * iocb else returns NULL.
  2319. **/
  2320. static struct lpfc_iocbq *
  2321. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2322. struct lpfc_sli_ring *pring,
  2323. struct lpfc_iocbq *prspiocb)
  2324. {
  2325. struct lpfc_iocbq *cmd_iocb = NULL;
  2326. uint16_t iotag;
  2327. iotag = prspiocb->iocb.ulpIoTag;
  2328. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2329. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2330. list_del_init(&cmd_iocb->list);
  2331. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2332. pring->txcmplq_cnt--;
  2333. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2334. }
  2335. return cmd_iocb;
  2336. }
  2337. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2338. "0317 iotag x%x is out off "
  2339. "range: max iotag x%x wd0 x%x\n",
  2340. iotag, phba->sli.last_iotag,
  2341. *(((uint32_t *) &prspiocb->iocb) + 7));
  2342. return NULL;
  2343. }
  2344. /**
  2345. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2346. * @phba: Pointer to HBA context object.
  2347. * @pring: Pointer to driver SLI ring object.
  2348. * @iotag: IOCB tag.
  2349. *
  2350. * This function looks up the iocb_lookup table to get the command iocb
  2351. * corresponding to the given iotag. This function is called with the
  2352. * hbalock held.
  2353. * This function returns the command iocb object if it finds the command
  2354. * iocb else returns NULL.
  2355. **/
  2356. static struct lpfc_iocbq *
  2357. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2358. struct lpfc_sli_ring *pring, uint16_t iotag)
  2359. {
  2360. struct lpfc_iocbq *cmd_iocb;
  2361. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2362. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2363. list_del_init(&cmd_iocb->list);
  2364. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2365. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2366. pring->txcmplq_cnt--;
  2367. }
  2368. return cmd_iocb;
  2369. }
  2370. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2371. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2372. iotag, phba->sli.last_iotag);
  2373. return NULL;
  2374. }
  2375. /**
  2376. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2377. * @phba: Pointer to HBA context object.
  2378. * @pring: Pointer to driver SLI ring object.
  2379. * @saveq: Pointer to the response iocb to be processed.
  2380. *
  2381. * This function is called by the ring event handler for non-fcp
  2382. * rings when there is a new response iocb in the response ring.
  2383. * The caller is not required to hold any locks. This function
  2384. * gets the command iocb associated with the response iocb and
  2385. * calls the completion handler for the command iocb. If there
  2386. * is no completion handler, the function will free the resources
  2387. * associated with command iocb. If the response iocb is for
  2388. * an already aborted command iocb, the status of the completion
  2389. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2390. * This function always returns 1.
  2391. **/
  2392. static int
  2393. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2394. struct lpfc_iocbq *saveq)
  2395. {
  2396. struct lpfc_iocbq *cmdiocbp;
  2397. int rc = 1;
  2398. unsigned long iflag;
  2399. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2400. spin_lock_irqsave(&phba->hbalock, iflag);
  2401. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2402. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2403. if (cmdiocbp) {
  2404. if (cmdiocbp->iocb_cmpl) {
  2405. /*
  2406. * If an ELS command failed send an event to mgmt
  2407. * application.
  2408. */
  2409. if (saveq->iocb.ulpStatus &&
  2410. (pring->ringno == LPFC_ELS_RING) &&
  2411. (cmdiocbp->iocb.ulpCommand ==
  2412. CMD_ELS_REQUEST64_CR))
  2413. lpfc_send_els_failure_event(phba,
  2414. cmdiocbp, saveq);
  2415. /*
  2416. * Post all ELS completions to the worker thread.
  2417. * All other are passed to the completion callback.
  2418. */
  2419. if (pring->ringno == LPFC_ELS_RING) {
  2420. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2421. (cmdiocbp->iocb_flag &
  2422. LPFC_DRIVER_ABORTED)) {
  2423. spin_lock_irqsave(&phba->hbalock,
  2424. iflag);
  2425. cmdiocbp->iocb_flag &=
  2426. ~LPFC_DRIVER_ABORTED;
  2427. spin_unlock_irqrestore(&phba->hbalock,
  2428. iflag);
  2429. saveq->iocb.ulpStatus =
  2430. IOSTAT_LOCAL_REJECT;
  2431. saveq->iocb.un.ulpWord[4] =
  2432. IOERR_SLI_ABORTED;
  2433. /* Firmware could still be in progress
  2434. * of DMAing payload, so don't free data
  2435. * buffer till after a hbeat.
  2436. */
  2437. spin_lock_irqsave(&phba->hbalock,
  2438. iflag);
  2439. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2440. spin_unlock_irqrestore(&phba->hbalock,
  2441. iflag);
  2442. }
  2443. if (phba->sli_rev == LPFC_SLI_REV4) {
  2444. if (saveq->iocb_flag &
  2445. LPFC_EXCHANGE_BUSY) {
  2446. /* Set cmdiocb flag for the
  2447. * exchange busy so sgl (xri)
  2448. * will not be released until
  2449. * the abort xri is received
  2450. * from hba.
  2451. */
  2452. spin_lock_irqsave(
  2453. &phba->hbalock, iflag);
  2454. cmdiocbp->iocb_flag |=
  2455. LPFC_EXCHANGE_BUSY;
  2456. spin_unlock_irqrestore(
  2457. &phba->hbalock, iflag);
  2458. }
  2459. if (cmdiocbp->iocb_flag &
  2460. LPFC_DRIVER_ABORTED) {
  2461. /*
  2462. * Clear LPFC_DRIVER_ABORTED
  2463. * bit in case it was driver
  2464. * initiated abort.
  2465. */
  2466. spin_lock_irqsave(
  2467. &phba->hbalock, iflag);
  2468. cmdiocbp->iocb_flag &=
  2469. ~LPFC_DRIVER_ABORTED;
  2470. spin_unlock_irqrestore(
  2471. &phba->hbalock, iflag);
  2472. cmdiocbp->iocb.ulpStatus =
  2473. IOSTAT_LOCAL_REJECT;
  2474. cmdiocbp->iocb.un.ulpWord[4] =
  2475. IOERR_ABORT_REQUESTED;
  2476. /*
  2477. * For SLI4, irsiocb contains
  2478. * NO_XRI in sli_xritag, it
  2479. * shall not affect releasing
  2480. * sgl (xri) process.
  2481. */
  2482. saveq->iocb.ulpStatus =
  2483. IOSTAT_LOCAL_REJECT;
  2484. saveq->iocb.un.ulpWord[4] =
  2485. IOERR_SLI_ABORTED;
  2486. spin_lock_irqsave(
  2487. &phba->hbalock, iflag);
  2488. saveq->iocb_flag |=
  2489. LPFC_DELAY_MEM_FREE;
  2490. spin_unlock_irqrestore(
  2491. &phba->hbalock, iflag);
  2492. }
  2493. }
  2494. }
  2495. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2496. } else
  2497. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2498. } else {
  2499. /*
  2500. * Unknown initiating command based on the response iotag.
  2501. * This could be the case on the ELS ring because of
  2502. * lpfc_els_abort().
  2503. */
  2504. if (pring->ringno != LPFC_ELS_RING) {
  2505. /*
  2506. * Ring <ringno> handler: unexpected completion IoTag
  2507. * <IoTag>
  2508. */
  2509. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2510. "0322 Ring %d handler: "
  2511. "unexpected completion IoTag x%x "
  2512. "Data: x%x x%x x%x x%x\n",
  2513. pring->ringno,
  2514. saveq->iocb.ulpIoTag,
  2515. saveq->iocb.ulpStatus,
  2516. saveq->iocb.un.ulpWord[4],
  2517. saveq->iocb.ulpCommand,
  2518. saveq->iocb.ulpContext);
  2519. }
  2520. }
  2521. return rc;
  2522. }
  2523. /**
  2524. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2525. * @phba: Pointer to HBA context object.
  2526. * @pring: Pointer to driver SLI ring object.
  2527. *
  2528. * This function is called from the iocb ring event handlers when
  2529. * put pointer is ahead of the get pointer for a ring. This function signal
  2530. * an error attention condition to the worker thread and the worker
  2531. * thread will transition the HBA to offline state.
  2532. **/
  2533. static void
  2534. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2535. {
  2536. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2537. /*
  2538. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2539. * rsp ring <portRspMax>
  2540. */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0312 Ring %d handler: portRspPut %d "
  2543. "is bigger than rsp ring %d\n",
  2544. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2545. pring->numRiocb);
  2546. phba->link_state = LPFC_HBA_ERROR;
  2547. /*
  2548. * All error attention handlers are posted to
  2549. * worker thread
  2550. */
  2551. phba->work_ha |= HA_ERATT;
  2552. phba->work_hs = HS_FFER3;
  2553. lpfc_worker_wake_up(phba);
  2554. return;
  2555. }
  2556. /**
  2557. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2558. * @ptr: Pointer to address of HBA context object.
  2559. *
  2560. * This function is invoked by the Error Attention polling timer when the
  2561. * timer times out. It will check the SLI Error Attention register for
  2562. * possible attention events. If so, it will post an Error Attention event
  2563. * and wake up worker thread to process it. Otherwise, it will set up the
  2564. * Error Attention polling timer for the next poll.
  2565. **/
  2566. void lpfc_poll_eratt(unsigned long ptr)
  2567. {
  2568. struct lpfc_hba *phba;
  2569. uint32_t eratt = 0;
  2570. phba = (struct lpfc_hba *)ptr;
  2571. /* Check chip HA register for error event */
  2572. eratt = lpfc_sli_check_eratt(phba);
  2573. if (eratt)
  2574. /* Tell the worker thread there is work to do */
  2575. lpfc_worker_wake_up(phba);
  2576. else
  2577. /* Restart the timer for next eratt poll */
  2578. mod_timer(&phba->eratt_poll, jiffies +
  2579. HZ * LPFC_ERATT_POLL_INTERVAL);
  2580. return;
  2581. }
  2582. /**
  2583. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2584. * @phba: Pointer to HBA context object.
  2585. * @pring: Pointer to driver SLI ring object.
  2586. * @mask: Host attention register mask for this ring.
  2587. *
  2588. * This function is called from the interrupt context when there is a ring
  2589. * event for the fcp ring. The caller does not hold any lock.
  2590. * The function processes each response iocb in the response ring until it
  2591. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2592. * LE bit set. The function will call the completion handler of the command iocb
  2593. * if the response iocb indicates a completion for a command iocb or it is
  2594. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2595. * function if this is an unsolicited iocb.
  2596. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2597. * to check it explicitly.
  2598. */
  2599. int
  2600. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2601. struct lpfc_sli_ring *pring, uint32_t mask)
  2602. {
  2603. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2604. IOCB_t *irsp = NULL;
  2605. IOCB_t *entry = NULL;
  2606. struct lpfc_iocbq *cmdiocbq = NULL;
  2607. struct lpfc_iocbq rspiocbq;
  2608. uint32_t status;
  2609. uint32_t portRspPut, portRspMax;
  2610. int rc = 1;
  2611. lpfc_iocb_type type;
  2612. unsigned long iflag;
  2613. uint32_t rsp_cmpl = 0;
  2614. spin_lock_irqsave(&phba->hbalock, iflag);
  2615. pring->stats.iocb_event++;
  2616. /*
  2617. * The next available response entry should never exceed the maximum
  2618. * entries. If it does, treat it as an adapter hardware error.
  2619. */
  2620. portRspMax = pring->numRiocb;
  2621. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2622. if (unlikely(portRspPut >= portRspMax)) {
  2623. lpfc_sli_rsp_pointers_error(phba, pring);
  2624. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2625. return 1;
  2626. }
  2627. if (phba->fcp_ring_in_use) {
  2628. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2629. return 1;
  2630. } else
  2631. phba->fcp_ring_in_use = 1;
  2632. rmb();
  2633. while (pring->rspidx != portRspPut) {
  2634. /*
  2635. * Fetch an entry off the ring and copy it into a local data
  2636. * structure. The copy involves a byte-swap since the
  2637. * network byte order and pci byte orders are different.
  2638. */
  2639. entry = lpfc_resp_iocb(phba, pring);
  2640. phba->last_completion_time = jiffies;
  2641. if (++pring->rspidx >= portRspMax)
  2642. pring->rspidx = 0;
  2643. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2644. (uint32_t *) &rspiocbq.iocb,
  2645. phba->iocb_rsp_size);
  2646. INIT_LIST_HEAD(&(rspiocbq.list));
  2647. irsp = &rspiocbq.iocb;
  2648. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2649. pring->stats.iocb_rsp++;
  2650. rsp_cmpl++;
  2651. if (unlikely(irsp->ulpStatus)) {
  2652. /*
  2653. * If resource errors reported from HBA, reduce
  2654. * queuedepths of the SCSI device.
  2655. */
  2656. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2657. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2659. phba->lpfc_rampdown_queue_depth(phba);
  2660. spin_lock_irqsave(&phba->hbalock, iflag);
  2661. }
  2662. /* Rsp ring <ringno> error: IOCB */
  2663. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2664. "0336 Rsp Ring %d error: IOCB Data: "
  2665. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2666. pring->ringno,
  2667. irsp->un.ulpWord[0],
  2668. irsp->un.ulpWord[1],
  2669. irsp->un.ulpWord[2],
  2670. irsp->un.ulpWord[3],
  2671. irsp->un.ulpWord[4],
  2672. irsp->un.ulpWord[5],
  2673. *(uint32_t *)&irsp->un1,
  2674. *((uint32_t *)&irsp->un1 + 1));
  2675. }
  2676. switch (type) {
  2677. case LPFC_ABORT_IOCB:
  2678. case LPFC_SOL_IOCB:
  2679. /*
  2680. * Idle exchange closed via ABTS from port. No iocb
  2681. * resources need to be recovered.
  2682. */
  2683. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2684. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2685. "0333 IOCB cmd 0x%x"
  2686. " processed. Skipping"
  2687. " completion\n",
  2688. irsp->ulpCommand);
  2689. break;
  2690. }
  2691. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2692. &rspiocbq);
  2693. if (unlikely(!cmdiocbq))
  2694. break;
  2695. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2696. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2697. if (cmdiocbq->iocb_cmpl) {
  2698. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2699. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2700. &rspiocbq);
  2701. spin_lock_irqsave(&phba->hbalock, iflag);
  2702. }
  2703. break;
  2704. case LPFC_UNSOL_IOCB:
  2705. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2706. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2707. spin_lock_irqsave(&phba->hbalock, iflag);
  2708. break;
  2709. default:
  2710. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2711. char adaptermsg[LPFC_MAX_ADPTMSG];
  2712. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2713. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2714. MAX_MSG_DATA);
  2715. dev_warn(&((phba->pcidev)->dev),
  2716. "lpfc%d: %s\n",
  2717. phba->brd_no, adaptermsg);
  2718. } else {
  2719. /* Unknown IOCB command */
  2720. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2721. "0334 Unknown IOCB command "
  2722. "Data: x%x, x%x x%x x%x x%x\n",
  2723. type, irsp->ulpCommand,
  2724. irsp->ulpStatus,
  2725. irsp->ulpIoTag,
  2726. irsp->ulpContext);
  2727. }
  2728. break;
  2729. }
  2730. /*
  2731. * The response IOCB has been processed. Update the ring
  2732. * pointer in SLIM. If the port response put pointer has not
  2733. * been updated, sync the pgp->rspPutInx and fetch the new port
  2734. * response put pointer.
  2735. */
  2736. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2737. if (pring->rspidx == portRspPut)
  2738. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2739. }
  2740. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2741. pring->stats.iocb_rsp_full++;
  2742. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2743. writel(status, phba->CAregaddr);
  2744. readl(phba->CAregaddr);
  2745. }
  2746. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2747. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2748. pring->stats.iocb_cmd_empty++;
  2749. /* Force update of the local copy of cmdGetInx */
  2750. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2751. lpfc_sli_resume_iocb(phba, pring);
  2752. if ((pring->lpfc_sli_cmd_available))
  2753. (pring->lpfc_sli_cmd_available) (phba, pring);
  2754. }
  2755. phba->fcp_ring_in_use = 0;
  2756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2757. return rc;
  2758. }
  2759. /**
  2760. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2761. * @phba: Pointer to HBA context object.
  2762. * @pring: Pointer to driver SLI ring object.
  2763. * @rspiocbp: Pointer to driver response IOCB object.
  2764. *
  2765. * This function is called from the worker thread when there is a slow-path
  2766. * response IOCB to process. This function chains all the response iocbs until
  2767. * seeing the iocb with the LE bit set. The function will call
  2768. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2769. * completion of a command iocb. The function will call the
  2770. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2771. * The function frees the resources or calls the completion handler if this
  2772. * iocb is an abort completion. The function returns NULL when the response
  2773. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2774. * this function shall chain the iocb on to the iocb_continueq and return the
  2775. * response iocb passed in.
  2776. **/
  2777. static struct lpfc_iocbq *
  2778. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2779. struct lpfc_iocbq *rspiocbp)
  2780. {
  2781. struct lpfc_iocbq *saveq;
  2782. struct lpfc_iocbq *cmdiocbp;
  2783. struct lpfc_iocbq *next_iocb;
  2784. IOCB_t *irsp = NULL;
  2785. uint32_t free_saveq;
  2786. uint8_t iocb_cmd_type;
  2787. lpfc_iocb_type type;
  2788. unsigned long iflag;
  2789. int rc;
  2790. spin_lock_irqsave(&phba->hbalock, iflag);
  2791. /* First add the response iocb to the countinueq list */
  2792. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2793. pring->iocb_continueq_cnt++;
  2794. /* Now, determine whetehr the list is completed for processing */
  2795. irsp = &rspiocbp->iocb;
  2796. if (irsp->ulpLe) {
  2797. /*
  2798. * By default, the driver expects to free all resources
  2799. * associated with this iocb completion.
  2800. */
  2801. free_saveq = 1;
  2802. saveq = list_get_first(&pring->iocb_continueq,
  2803. struct lpfc_iocbq, list);
  2804. irsp = &(saveq->iocb);
  2805. list_del_init(&pring->iocb_continueq);
  2806. pring->iocb_continueq_cnt = 0;
  2807. pring->stats.iocb_rsp++;
  2808. /*
  2809. * If resource errors reported from HBA, reduce
  2810. * queuedepths of the SCSI device.
  2811. */
  2812. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2813. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2814. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2815. phba->lpfc_rampdown_queue_depth(phba);
  2816. spin_lock_irqsave(&phba->hbalock, iflag);
  2817. }
  2818. if (irsp->ulpStatus) {
  2819. /* Rsp ring <ringno> error: IOCB */
  2820. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2821. "0328 Rsp Ring %d error: "
  2822. "IOCB Data: "
  2823. "x%x x%x x%x x%x "
  2824. "x%x x%x x%x x%x "
  2825. "x%x x%x x%x x%x "
  2826. "x%x x%x x%x x%x\n",
  2827. pring->ringno,
  2828. irsp->un.ulpWord[0],
  2829. irsp->un.ulpWord[1],
  2830. irsp->un.ulpWord[2],
  2831. irsp->un.ulpWord[3],
  2832. irsp->un.ulpWord[4],
  2833. irsp->un.ulpWord[5],
  2834. *(((uint32_t *) irsp) + 6),
  2835. *(((uint32_t *) irsp) + 7),
  2836. *(((uint32_t *) irsp) + 8),
  2837. *(((uint32_t *) irsp) + 9),
  2838. *(((uint32_t *) irsp) + 10),
  2839. *(((uint32_t *) irsp) + 11),
  2840. *(((uint32_t *) irsp) + 12),
  2841. *(((uint32_t *) irsp) + 13),
  2842. *(((uint32_t *) irsp) + 14),
  2843. *(((uint32_t *) irsp) + 15));
  2844. }
  2845. /*
  2846. * Fetch the IOCB command type and call the correct completion
  2847. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2848. * get freed back to the lpfc_iocb_list by the discovery
  2849. * kernel thread.
  2850. */
  2851. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2852. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2853. switch (type) {
  2854. case LPFC_SOL_IOCB:
  2855. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2856. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2857. spin_lock_irqsave(&phba->hbalock, iflag);
  2858. break;
  2859. case LPFC_UNSOL_IOCB:
  2860. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2861. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2862. spin_lock_irqsave(&phba->hbalock, iflag);
  2863. if (!rc)
  2864. free_saveq = 0;
  2865. break;
  2866. case LPFC_ABORT_IOCB:
  2867. cmdiocbp = NULL;
  2868. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2869. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2870. saveq);
  2871. if (cmdiocbp) {
  2872. /* Call the specified completion routine */
  2873. if (cmdiocbp->iocb_cmpl) {
  2874. spin_unlock_irqrestore(&phba->hbalock,
  2875. iflag);
  2876. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2877. saveq);
  2878. spin_lock_irqsave(&phba->hbalock,
  2879. iflag);
  2880. } else
  2881. __lpfc_sli_release_iocbq(phba,
  2882. cmdiocbp);
  2883. }
  2884. break;
  2885. case LPFC_UNKNOWN_IOCB:
  2886. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2887. char adaptermsg[LPFC_MAX_ADPTMSG];
  2888. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2889. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2890. MAX_MSG_DATA);
  2891. dev_warn(&((phba->pcidev)->dev),
  2892. "lpfc%d: %s\n",
  2893. phba->brd_no, adaptermsg);
  2894. } else {
  2895. /* Unknown IOCB command */
  2896. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2897. "0335 Unknown IOCB "
  2898. "command Data: x%x "
  2899. "x%x x%x x%x\n",
  2900. irsp->ulpCommand,
  2901. irsp->ulpStatus,
  2902. irsp->ulpIoTag,
  2903. irsp->ulpContext);
  2904. }
  2905. break;
  2906. }
  2907. if (free_saveq) {
  2908. list_for_each_entry_safe(rspiocbp, next_iocb,
  2909. &saveq->list, list) {
  2910. list_del(&rspiocbp->list);
  2911. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2912. }
  2913. __lpfc_sli_release_iocbq(phba, saveq);
  2914. }
  2915. rspiocbp = NULL;
  2916. }
  2917. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2918. return rspiocbp;
  2919. }
  2920. /**
  2921. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2922. * @phba: Pointer to HBA context object.
  2923. * @pring: Pointer to driver SLI ring object.
  2924. * @mask: Host attention register mask for this ring.
  2925. *
  2926. * This routine wraps the actual slow_ring event process routine from the
  2927. * API jump table function pointer from the lpfc_hba struct.
  2928. **/
  2929. void
  2930. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2931. struct lpfc_sli_ring *pring, uint32_t mask)
  2932. {
  2933. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2934. }
  2935. /**
  2936. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2937. * @phba: Pointer to HBA context object.
  2938. * @pring: Pointer to driver SLI ring object.
  2939. * @mask: Host attention register mask for this ring.
  2940. *
  2941. * This function is called from the worker thread when there is a ring event
  2942. * for non-fcp rings. The caller does not hold any lock. The function will
  2943. * remove each response iocb in the response ring and calls the handle
  2944. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2945. **/
  2946. static void
  2947. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2948. struct lpfc_sli_ring *pring, uint32_t mask)
  2949. {
  2950. struct lpfc_pgp *pgp;
  2951. IOCB_t *entry;
  2952. IOCB_t *irsp = NULL;
  2953. struct lpfc_iocbq *rspiocbp = NULL;
  2954. uint32_t portRspPut, portRspMax;
  2955. unsigned long iflag;
  2956. uint32_t status;
  2957. pgp = &phba->port_gp[pring->ringno];
  2958. spin_lock_irqsave(&phba->hbalock, iflag);
  2959. pring->stats.iocb_event++;
  2960. /*
  2961. * The next available response entry should never exceed the maximum
  2962. * entries. If it does, treat it as an adapter hardware error.
  2963. */
  2964. portRspMax = pring->numRiocb;
  2965. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2966. if (portRspPut >= portRspMax) {
  2967. /*
  2968. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2969. * rsp ring <portRspMax>
  2970. */
  2971. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2972. "0303 Ring %d handler: portRspPut %d "
  2973. "is bigger than rsp ring %d\n",
  2974. pring->ringno, portRspPut, portRspMax);
  2975. phba->link_state = LPFC_HBA_ERROR;
  2976. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2977. phba->work_hs = HS_FFER3;
  2978. lpfc_handle_eratt(phba);
  2979. return;
  2980. }
  2981. rmb();
  2982. while (pring->rspidx != portRspPut) {
  2983. /*
  2984. * Build a completion list and call the appropriate handler.
  2985. * The process is to get the next available response iocb, get
  2986. * a free iocb from the list, copy the response data into the
  2987. * free iocb, insert to the continuation list, and update the
  2988. * next response index to slim. This process makes response
  2989. * iocb's in the ring available to DMA as fast as possible but
  2990. * pays a penalty for a copy operation. Since the iocb is
  2991. * only 32 bytes, this penalty is considered small relative to
  2992. * the PCI reads for register values and a slim write. When
  2993. * the ulpLe field is set, the entire Command has been
  2994. * received.
  2995. */
  2996. entry = lpfc_resp_iocb(phba, pring);
  2997. phba->last_completion_time = jiffies;
  2998. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2999. if (rspiocbp == NULL) {
  3000. printk(KERN_ERR "%s: out of buffers! Failing "
  3001. "completion.\n", __func__);
  3002. break;
  3003. }
  3004. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3005. phba->iocb_rsp_size);
  3006. irsp = &rspiocbp->iocb;
  3007. if (++pring->rspidx >= portRspMax)
  3008. pring->rspidx = 0;
  3009. if (pring->ringno == LPFC_ELS_RING) {
  3010. lpfc_debugfs_slow_ring_trc(phba,
  3011. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3012. *(((uint32_t *) irsp) + 4),
  3013. *(((uint32_t *) irsp) + 6),
  3014. *(((uint32_t *) irsp) + 7));
  3015. }
  3016. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3018. /* Handle the response IOCB */
  3019. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3020. spin_lock_irqsave(&phba->hbalock, iflag);
  3021. /*
  3022. * If the port response put pointer has not been updated, sync
  3023. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3024. * response put pointer.
  3025. */
  3026. if (pring->rspidx == portRspPut) {
  3027. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3028. }
  3029. } /* while (pring->rspidx != portRspPut) */
  3030. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3031. /* At least one response entry has been freed */
  3032. pring->stats.iocb_rsp_full++;
  3033. /* SET RxRE_RSP in Chip Att register */
  3034. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3035. writel(status, phba->CAregaddr);
  3036. readl(phba->CAregaddr); /* flush */
  3037. }
  3038. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3039. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3040. pring->stats.iocb_cmd_empty++;
  3041. /* Force update of the local copy of cmdGetInx */
  3042. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3043. lpfc_sli_resume_iocb(phba, pring);
  3044. if ((pring->lpfc_sli_cmd_available))
  3045. (pring->lpfc_sli_cmd_available) (phba, pring);
  3046. }
  3047. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3048. return;
  3049. }
  3050. /**
  3051. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3052. * @phba: Pointer to HBA context object.
  3053. * @pring: Pointer to driver SLI ring object.
  3054. * @mask: Host attention register mask for this ring.
  3055. *
  3056. * This function is called from the worker thread when there is a pending
  3057. * ELS response iocb on the driver internal slow-path response iocb worker
  3058. * queue. The caller does not hold any lock. The function will remove each
  3059. * response iocb from the response worker queue and calls the handle
  3060. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3061. **/
  3062. static void
  3063. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3064. struct lpfc_sli_ring *pring, uint32_t mask)
  3065. {
  3066. struct lpfc_iocbq *irspiocbq;
  3067. struct hbq_dmabuf *dmabuf;
  3068. struct lpfc_cq_event *cq_event;
  3069. unsigned long iflag;
  3070. spin_lock_irqsave(&phba->hbalock, iflag);
  3071. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3073. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3074. /* Get the response iocb from the head of work queue */
  3075. spin_lock_irqsave(&phba->hbalock, iflag);
  3076. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3077. cq_event, struct lpfc_cq_event, list);
  3078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3079. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3080. case CQE_CODE_COMPL_WQE:
  3081. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3082. cq_event);
  3083. /* Translate ELS WCQE to response IOCBQ */
  3084. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3085. irspiocbq);
  3086. if (irspiocbq)
  3087. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3088. irspiocbq);
  3089. break;
  3090. case CQE_CODE_RECEIVE:
  3091. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3092. cq_event);
  3093. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3094. break;
  3095. default:
  3096. break;
  3097. }
  3098. }
  3099. }
  3100. /**
  3101. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3102. * @phba: Pointer to HBA context object.
  3103. * @pring: Pointer to driver SLI ring object.
  3104. *
  3105. * This function aborts all iocbs in the given ring and frees all the iocb
  3106. * objects in txq. This function issues an abort iocb for all the iocb commands
  3107. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3108. * the return of this function. The caller is not required to hold any locks.
  3109. **/
  3110. void
  3111. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3112. {
  3113. LIST_HEAD(completions);
  3114. struct lpfc_iocbq *iocb, *next_iocb;
  3115. if (pring->ringno == LPFC_ELS_RING) {
  3116. lpfc_fabric_abort_hba(phba);
  3117. }
  3118. /* Error everything on txq and txcmplq
  3119. * First do the txq.
  3120. */
  3121. spin_lock_irq(&phba->hbalock);
  3122. list_splice_init(&pring->txq, &completions);
  3123. pring->txq_cnt = 0;
  3124. /* Next issue ABTS for everything on the txcmplq */
  3125. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3126. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3127. spin_unlock_irq(&phba->hbalock);
  3128. /* Cancel all the IOCBs from the completions list */
  3129. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3130. IOERR_SLI_ABORTED);
  3131. }
  3132. /**
  3133. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3134. * @phba: Pointer to HBA context object.
  3135. *
  3136. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3137. * objects in txq and txcmplq. This function will not issue abort iocbs
  3138. * for all the iocb commands in txcmplq, they will just be returned with
  3139. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3140. * slot has been permanently disabled.
  3141. **/
  3142. void
  3143. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3144. {
  3145. LIST_HEAD(txq);
  3146. LIST_HEAD(txcmplq);
  3147. struct lpfc_sli *psli = &phba->sli;
  3148. struct lpfc_sli_ring *pring;
  3149. /* Currently, only one fcp ring */
  3150. pring = &psli->ring[psli->fcp_ring];
  3151. spin_lock_irq(&phba->hbalock);
  3152. /* Retrieve everything on txq */
  3153. list_splice_init(&pring->txq, &txq);
  3154. pring->txq_cnt = 0;
  3155. /* Retrieve everything on the txcmplq */
  3156. list_splice_init(&pring->txcmplq, &txcmplq);
  3157. pring->txcmplq_cnt = 0;
  3158. spin_unlock_irq(&phba->hbalock);
  3159. /* Flush the txq */
  3160. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3161. IOERR_SLI_DOWN);
  3162. /* Flush the txcmpq */
  3163. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3164. IOERR_SLI_DOWN);
  3165. }
  3166. /**
  3167. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3168. * @phba: Pointer to HBA context object.
  3169. * @mask: Bit mask to be checked.
  3170. *
  3171. * This function reads the host status register and compares
  3172. * with the provided bit mask to check if HBA completed
  3173. * the restart. This function will wait in a loop for the
  3174. * HBA to complete restart. If the HBA does not restart within
  3175. * 15 iterations, the function will reset the HBA again. The
  3176. * function returns 1 when HBA fail to restart otherwise returns
  3177. * zero.
  3178. **/
  3179. static int
  3180. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3181. {
  3182. uint32_t status;
  3183. int i = 0;
  3184. int retval = 0;
  3185. /* Read the HBA Host Status Register */
  3186. if (lpfc_readl(phba->HSregaddr, &status))
  3187. return 1;
  3188. /*
  3189. * Check status register every 100ms for 5 retries, then every
  3190. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3191. * every 2.5 sec for 4.
  3192. * Break our of the loop if errors occurred during init.
  3193. */
  3194. while (((status & mask) != mask) &&
  3195. !(status & HS_FFERM) &&
  3196. i++ < 20) {
  3197. if (i <= 5)
  3198. msleep(10);
  3199. else if (i <= 10)
  3200. msleep(500);
  3201. else
  3202. msleep(2500);
  3203. if (i == 15) {
  3204. /* Do post */
  3205. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3206. lpfc_sli_brdrestart(phba);
  3207. }
  3208. /* Read the HBA Host Status Register */
  3209. if (lpfc_readl(phba->HSregaddr, &status)) {
  3210. retval = 1;
  3211. break;
  3212. }
  3213. }
  3214. /* Check to see if any errors occurred during init */
  3215. if ((status & HS_FFERM) || (i >= 20)) {
  3216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3217. "2751 Adapter failed to restart, "
  3218. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3219. status,
  3220. readl(phba->MBslimaddr + 0xa8),
  3221. readl(phba->MBslimaddr + 0xac));
  3222. phba->link_state = LPFC_HBA_ERROR;
  3223. retval = 1;
  3224. }
  3225. return retval;
  3226. }
  3227. /**
  3228. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3229. * @phba: Pointer to HBA context object.
  3230. * @mask: Bit mask to be checked.
  3231. *
  3232. * This function checks the host status register to check if HBA is
  3233. * ready. This function will wait in a loop for the HBA to be ready
  3234. * If the HBA is not ready , the function will will reset the HBA PCI
  3235. * function again. The function returns 1 when HBA fail to be ready
  3236. * otherwise returns zero.
  3237. **/
  3238. static int
  3239. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3240. {
  3241. uint32_t status;
  3242. int retval = 0;
  3243. /* Read the HBA Host Status Register */
  3244. status = lpfc_sli4_post_status_check(phba);
  3245. if (status) {
  3246. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3247. lpfc_sli_brdrestart(phba);
  3248. status = lpfc_sli4_post_status_check(phba);
  3249. }
  3250. /* Check to see if any errors occurred during init */
  3251. if (status) {
  3252. phba->link_state = LPFC_HBA_ERROR;
  3253. retval = 1;
  3254. } else
  3255. phba->sli4_hba.intr_enable = 0;
  3256. return retval;
  3257. }
  3258. /**
  3259. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3260. * @phba: Pointer to HBA context object.
  3261. * @mask: Bit mask to be checked.
  3262. *
  3263. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3264. * from the API jump table function pointer from the lpfc_hba struct.
  3265. **/
  3266. int
  3267. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3268. {
  3269. return phba->lpfc_sli_brdready(phba, mask);
  3270. }
  3271. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3272. /**
  3273. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3274. * @phba: Pointer to HBA context object.
  3275. *
  3276. * This function is called before resetting an HBA. This
  3277. * function requests HBA to quiesce DMAs before a reset.
  3278. **/
  3279. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3280. {
  3281. uint32_t __iomem *resp_buf;
  3282. uint32_t __iomem *mbox_buf;
  3283. volatile uint32_t mbox;
  3284. uint32_t hc_copy, ha_copy, resp_data;
  3285. int i;
  3286. uint8_t hdrtype;
  3287. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3288. if (hdrtype != 0x80 ||
  3289. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3290. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3291. return;
  3292. /*
  3293. * Tell the other part of the chip to suspend temporarily all
  3294. * its DMA activity.
  3295. */
  3296. resp_buf = phba->MBslimaddr;
  3297. /* Disable the error attention */
  3298. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3299. return;
  3300. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3301. readl(phba->HCregaddr); /* flush */
  3302. phba->link_flag |= LS_IGNORE_ERATT;
  3303. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3304. return;
  3305. if (ha_copy & HA_ERATT) {
  3306. /* Clear Chip error bit */
  3307. writel(HA_ERATT, phba->HAregaddr);
  3308. phba->pport->stopped = 1;
  3309. }
  3310. mbox = 0;
  3311. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3312. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3313. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3314. mbox_buf = phba->MBslimaddr;
  3315. writel(mbox, mbox_buf);
  3316. for (i = 0; i < 50; i++) {
  3317. if (lpfc_readl((resp_buf + 1), &resp_data))
  3318. return;
  3319. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3320. mdelay(1);
  3321. else
  3322. break;
  3323. }
  3324. resp_data = 0;
  3325. if (lpfc_readl((resp_buf + 1), &resp_data))
  3326. return;
  3327. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3328. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3329. phba->pport->stopped)
  3330. goto restore_hc;
  3331. else
  3332. goto clear_errat;
  3333. }
  3334. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3335. resp_data = 0;
  3336. for (i = 0; i < 500; i++) {
  3337. if (lpfc_readl(resp_buf, &resp_data))
  3338. return;
  3339. if (resp_data != mbox)
  3340. mdelay(1);
  3341. else
  3342. break;
  3343. }
  3344. clear_errat:
  3345. while (++i < 500) {
  3346. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3347. return;
  3348. if (!(ha_copy & HA_ERATT))
  3349. mdelay(1);
  3350. else
  3351. break;
  3352. }
  3353. if (readl(phba->HAregaddr) & HA_ERATT) {
  3354. writel(HA_ERATT, phba->HAregaddr);
  3355. phba->pport->stopped = 1;
  3356. }
  3357. restore_hc:
  3358. phba->link_flag &= ~LS_IGNORE_ERATT;
  3359. writel(hc_copy, phba->HCregaddr);
  3360. readl(phba->HCregaddr); /* flush */
  3361. }
  3362. /**
  3363. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3364. * @phba: Pointer to HBA context object.
  3365. *
  3366. * This function issues a kill_board mailbox command and waits for
  3367. * the error attention interrupt. This function is called for stopping
  3368. * the firmware processing. The caller is not required to hold any
  3369. * locks. This function calls lpfc_hba_down_post function to free
  3370. * any pending commands after the kill. The function will return 1 when it
  3371. * fails to kill the board else will return 0.
  3372. **/
  3373. int
  3374. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3375. {
  3376. struct lpfc_sli *psli;
  3377. LPFC_MBOXQ_t *pmb;
  3378. uint32_t status;
  3379. uint32_t ha_copy;
  3380. int retval;
  3381. int i = 0;
  3382. psli = &phba->sli;
  3383. /* Kill HBA */
  3384. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3385. "0329 Kill HBA Data: x%x x%x\n",
  3386. phba->pport->port_state, psli->sli_flag);
  3387. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3388. if (!pmb)
  3389. return 1;
  3390. /* Disable the error attention */
  3391. spin_lock_irq(&phba->hbalock);
  3392. if (lpfc_readl(phba->HCregaddr, &status)) {
  3393. spin_unlock_irq(&phba->hbalock);
  3394. mempool_free(pmb, phba->mbox_mem_pool);
  3395. return 1;
  3396. }
  3397. status &= ~HC_ERINT_ENA;
  3398. writel(status, phba->HCregaddr);
  3399. readl(phba->HCregaddr); /* flush */
  3400. phba->link_flag |= LS_IGNORE_ERATT;
  3401. spin_unlock_irq(&phba->hbalock);
  3402. lpfc_kill_board(phba, pmb);
  3403. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3404. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3405. if (retval != MBX_SUCCESS) {
  3406. if (retval != MBX_BUSY)
  3407. mempool_free(pmb, phba->mbox_mem_pool);
  3408. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3409. "2752 KILL_BOARD command failed retval %d\n",
  3410. retval);
  3411. spin_lock_irq(&phba->hbalock);
  3412. phba->link_flag &= ~LS_IGNORE_ERATT;
  3413. spin_unlock_irq(&phba->hbalock);
  3414. return 1;
  3415. }
  3416. spin_lock_irq(&phba->hbalock);
  3417. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3418. spin_unlock_irq(&phba->hbalock);
  3419. mempool_free(pmb, phba->mbox_mem_pool);
  3420. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3421. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3422. * 3 seconds we still set HBA_ERROR state because the status of the
  3423. * board is now undefined.
  3424. */
  3425. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3426. return 1;
  3427. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3428. mdelay(100);
  3429. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3430. return 1;
  3431. }
  3432. del_timer_sync(&psli->mbox_tmo);
  3433. if (ha_copy & HA_ERATT) {
  3434. writel(HA_ERATT, phba->HAregaddr);
  3435. phba->pport->stopped = 1;
  3436. }
  3437. spin_lock_irq(&phba->hbalock);
  3438. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3439. psli->mbox_active = NULL;
  3440. phba->link_flag &= ~LS_IGNORE_ERATT;
  3441. spin_unlock_irq(&phba->hbalock);
  3442. lpfc_hba_down_post(phba);
  3443. phba->link_state = LPFC_HBA_ERROR;
  3444. return ha_copy & HA_ERATT ? 0 : 1;
  3445. }
  3446. /**
  3447. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3448. * @phba: Pointer to HBA context object.
  3449. *
  3450. * This function resets the HBA by writing HC_INITFF to the control
  3451. * register. After the HBA resets, this function resets all the iocb ring
  3452. * indices. This function disables PCI layer parity checking during
  3453. * the reset.
  3454. * This function returns 0 always.
  3455. * The caller is not required to hold any locks.
  3456. **/
  3457. int
  3458. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3459. {
  3460. struct lpfc_sli *psli;
  3461. struct lpfc_sli_ring *pring;
  3462. uint16_t cfg_value;
  3463. int i;
  3464. psli = &phba->sli;
  3465. /* Reset HBA */
  3466. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3467. "0325 Reset HBA Data: x%x x%x\n",
  3468. phba->pport->port_state, psli->sli_flag);
  3469. /* perform board reset */
  3470. phba->fc_eventTag = 0;
  3471. phba->link_events = 0;
  3472. phba->pport->fc_myDID = 0;
  3473. phba->pport->fc_prevDID = 0;
  3474. /* Turn off parity checking and serr during the physical reset */
  3475. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3476. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3477. (cfg_value &
  3478. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3479. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3480. /* Now toggle INITFF bit in the Host Control Register */
  3481. writel(HC_INITFF, phba->HCregaddr);
  3482. mdelay(1);
  3483. readl(phba->HCregaddr); /* flush */
  3484. writel(0, phba->HCregaddr);
  3485. readl(phba->HCregaddr); /* flush */
  3486. /* Restore PCI cmd register */
  3487. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3488. /* Initialize relevant SLI info */
  3489. for (i = 0; i < psli->num_rings; i++) {
  3490. pring = &psli->ring[i];
  3491. pring->flag = 0;
  3492. pring->rspidx = 0;
  3493. pring->next_cmdidx = 0;
  3494. pring->local_getidx = 0;
  3495. pring->cmdidx = 0;
  3496. pring->missbufcnt = 0;
  3497. }
  3498. phba->link_state = LPFC_WARM_START;
  3499. return 0;
  3500. }
  3501. /**
  3502. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3503. * @phba: Pointer to HBA context object.
  3504. *
  3505. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3506. * checking during resets the device. The caller is not required to hold
  3507. * any locks.
  3508. *
  3509. * This function returns 0 always.
  3510. **/
  3511. int
  3512. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3513. {
  3514. struct lpfc_sli *psli = &phba->sli;
  3515. uint16_t cfg_value;
  3516. uint8_t qindx;
  3517. /* Reset HBA */
  3518. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3519. "0295 Reset HBA Data: x%x x%x\n",
  3520. phba->pport->port_state, psli->sli_flag);
  3521. /* perform board reset */
  3522. phba->fc_eventTag = 0;
  3523. phba->link_events = 0;
  3524. phba->pport->fc_myDID = 0;
  3525. phba->pport->fc_prevDID = 0;
  3526. spin_lock_irq(&phba->hbalock);
  3527. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3528. phba->fcf.fcf_flag = 0;
  3529. /* Clean up the child queue list for the CQs */
  3530. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3531. list_del_init(&phba->sli4_hba.els_wq->list);
  3532. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3533. list_del_init(&phba->sli4_hba.dat_rq->list);
  3534. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3535. list_del_init(&phba->sli4_hba.els_cq->list);
  3536. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3537. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3538. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3539. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3540. spin_unlock_irq(&phba->hbalock);
  3541. /* Now physically reset the device */
  3542. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3543. "0389 Performing PCI function reset!\n");
  3544. /* Turn off parity checking and serr during the physical reset */
  3545. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3546. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3547. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3548. /* Perform FCoE PCI function reset */
  3549. lpfc_pci_function_reset(phba);
  3550. /* Restore PCI cmd register */
  3551. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3552. return 0;
  3553. }
  3554. /**
  3555. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3556. * @phba: Pointer to HBA context object.
  3557. *
  3558. * This function is called in the SLI initialization code path to
  3559. * restart the HBA. The caller is not required to hold any lock.
  3560. * This function writes MBX_RESTART mailbox command to the SLIM and
  3561. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3562. * function to free any pending commands. The function enables
  3563. * POST only during the first initialization. The function returns zero.
  3564. * The function does not guarantee completion of MBX_RESTART mailbox
  3565. * command before the return of this function.
  3566. **/
  3567. static int
  3568. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3569. {
  3570. MAILBOX_t *mb;
  3571. struct lpfc_sli *psli;
  3572. volatile uint32_t word0;
  3573. void __iomem *to_slim;
  3574. uint32_t hba_aer_enabled;
  3575. spin_lock_irq(&phba->hbalock);
  3576. /* Take PCIe device Advanced Error Reporting (AER) state */
  3577. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3578. psli = &phba->sli;
  3579. /* Restart HBA */
  3580. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3581. "0337 Restart HBA Data: x%x x%x\n",
  3582. phba->pport->port_state, psli->sli_flag);
  3583. word0 = 0;
  3584. mb = (MAILBOX_t *) &word0;
  3585. mb->mbxCommand = MBX_RESTART;
  3586. mb->mbxHc = 1;
  3587. lpfc_reset_barrier(phba);
  3588. to_slim = phba->MBslimaddr;
  3589. writel(*(uint32_t *) mb, to_slim);
  3590. readl(to_slim); /* flush */
  3591. /* Only skip post after fc_ffinit is completed */
  3592. if (phba->pport->port_state)
  3593. word0 = 1; /* This is really setting up word1 */
  3594. else
  3595. word0 = 0; /* This is really setting up word1 */
  3596. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3597. writel(*(uint32_t *) mb, to_slim);
  3598. readl(to_slim); /* flush */
  3599. lpfc_sli_brdreset(phba);
  3600. phba->pport->stopped = 0;
  3601. phba->link_state = LPFC_INIT_START;
  3602. phba->hba_flag = 0;
  3603. spin_unlock_irq(&phba->hbalock);
  3604. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3605. psli->stats_start = get_seconds();
  3606. /* Give the INITFF and Post time to settle. */
  3607. mdelay(100);
  3608. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3609. if (hba_aer_enabled)
  3610. pci_disable_pcie_error_reporting(phba->pcidev);
  3611. lpfc_hba_down_post(phba);
  3612. return 0;
  3613. }
  3614. /**
  3615. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3616. * @phba: Pointer to HBA context object.
  3617. *
  3618. * This function is called in the SLI initialization code path to restart
  3619. * a SLI4 HBA. The caller is not required to hold any lock.
  3620. * At the end of the function, it calls lpfc_hba_down_post function to
  3621. * free any pending commands.
  3622. **/
  3623. static int
  3624. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3625. {
  3626. struct lpfc_sli *psli = &phba->sli;
  3627. uint32_t hba_aer_enabled;
  3628. /* Restart HBA */
  3629. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3630. "0296 Restart HBA Data: x%x x%x\n",
  3631. phba->pport->port_state, psli->sli_flag);
  3632. /* Take PCIe device Advanced Error Reporting (AER) state */
  3633. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3634. lpfc_sli4_brdreset(phba);
  3635. spin_lock_irq(&phba->hbalock);
  3636. phba->pport->stopped = 0;
  3637. phba->link_state = LPFC_INIT_START;
  3638. phba->hba_flag = 0;
  3639. spin_unlock_irq(&phba->hbalock);
  3640. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3641. psli->stats_start = get_seconds();
  3642. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3643. if (hba_aer_enabled)
  3644. pci_disable_pcie_error_reporting(phba->pcidev);
  3645. lpfc_hba_down_post(phba);
  3646. return 0;
  3647. }
  3648. /**
  3649. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3650. * @phba: Pointer to HBA context object.
  3651. *
  3652. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3653. * API jump table function pointer from the lpfc_hba struct.
  3654. **/
  3655. int
  3656. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3657. {
  3658. return phba->lpfc_sli_brdrestart(phba);
  3659. }
  3660. /**
  3661. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3662. * @phba: Pointer to HBA context object.
  3663. *
  3664. * This function is called after a HBA restart to wait for successful
  3665. * restart of the HBA. Successful restart of the HBA is indicated by
  3666. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3667. * iteration, the function will restart the HBA again. The function returns
  3668. * zero if HBA successfully restarted else returns negative error code.
  3669. **/
  3670. static int
  3671. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3672. {
  3673. uint32_t status, i = 0;
  3674. /* Read the HBA Host Status Register */
  3675. if (lpfc_readl(phba->HSregaddr, &status))
  3676. return -EIO;
  3677. /* Check status register to see what current state is */
  3678. i = 0;
  3679. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3680. /* Check every 10ms for 10 retries, then every 100ms for 90
  3681. * retries, then every 1 sec for 50 retires for a total of
  3682. * ~60 seconds before reset the board again and check every
  3683. * 1 sec for 50 retries. The up to 60 seconds before the
  3684. * board ready is required by the Falcon FIPS zeroization
  3685. * complete, and any reset the board in between shall cause
  3686. * restart of zeroization, further delay the board ready.
  3687. */
  3688. if (i++ >= 200) {
  3689. /* Adapter failed to init, timeout, status reg
  3690. <status> */
  3691. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3692. "0436 Adapter failed to init, "
  3693. "timeout, status reg x%x, "
  3694. "FW Data: A8 x%x AC x%x\n", status,
  3695. readl(phba->MBslimaddr + 0xa8),
  3696. readl(phba->MBslimaddr + 0xac));
  3697. phba->link_state = LPFC_HBA_ERROR;
  3698. return -ETIMEDOUT;
  3699. }
  3700. /* Check to see if any errors occurred during init */
  3701. if (status & HS_FFERM) {
  3702. /* ERROR: During chipset initialization */
  3703. /* Adapter failed to init, chipset, status reg
  3704. <status> */
  3705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3706. "0437 Adapter failed to init, "
  3707. "chipset, status reg x%x, "
  3708. "FW Data: A8 x%x AC x%x\n", status,
  3709. readl(phba->MBslimaddr + 0xa8),
  3710. readl(phba->MBslimaddr + 0xac));
  3711. phba->link_state = LPFC_HBA_ERROR;
  3712. return -EIO;
  3713. }
  3714. if (i <= 10)
  3715. msleep(10);
  3716. else if (i <= 100)
  3717. msleep(100);
  3718. else
  3719. msleep(1000);
  3720. if (i == 150) {
  3721. /* Do post */
  3722. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3723. lpfc_sli_brdrestart(phba);
  3724. }
  3725. /* Read the HBA Host Status Register */
  3726. if (lpfc_readl(phba->HSregaddr, &status))
  3727. return -EIO;
  3728. }
  3729. /* Check to see if any errors occurred during init */
  3730. if (status & HS_FFERM) {
  3731. /* ERROR: During chipset initialization */
  3732. /* Adapter failed to init, chipset, status reg <status> */
  3733. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3734. "0438 Adapter failed to init, chipset, "
  3735. "status reg x%x, "
  3736. "FW Data: A8 x%x AC x%x\n", status,
  3737. readl(phba->MBslimaddr + 0xa8),
  3738. readl(phba->MBslimaddr + 0xac));
  3739. phba->link_state = LPFC_HBA_ERROR;
  3740. return -EIO;
  3741. }
  3742. /* Clear all interrupt enable conditions */
  3743. writel(0, phba->HCregaddr);
  3744. readl(phba->HCregaddr); /* flush */
  3745. /* setup host attn register */
  3746. writel(0xffffffff, phba->HAregaddr);
  3747. readl(phba->HAregaddr); /* flush */
  3748. return 0;
  3749. }
  3750. /**
  3751. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3752. *
  3753. * This function calculates and returns the number of HBQs required to be
  3754. * configured.
  3755. **/
  3756. int
  3757. lpfc_sli_hbq_count(void)
  3758. {
  3759. return ARRAY_SIZE(lpfc_hbq_defs);
  3760. }
  3761. /**
  3762. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3763. *
  3764. * This function adds the number of hbq entries in every HBQ to get
  3765. * the total number of hbq entries required for the HBA and returns
  3766. * the total count.
  3767. **/
  3768. static int
  3769. lpfc_sli_hbq_entry_count(void)
  3770. {
  3771. int hbq_count = lpfc_sli_hbq_count();
  3772. int count = 0;
  3773. int i;
  3774. for (i = 0; i < hbq_count; ++i)
  3775. count += lpfc_hbq_defs[i]->entry_count;
  3776. return count;
  3777. }
  3778. /**
  3779. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3780. *
  3781. * This function calculates amount of memory required for all hbq entries
  3782. * to be configured and returns the total memory required.
  3783. **/
  3784. int
  3785. lpfc_sli_hbq_size(void)
  3786. {
  3787. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3788. }
  3789. /**
  3790. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3791. * @phba: Pointer to HBA context object.
  3792. *
  3793. * This function is called during the SLI initialization to configure
  3794. * all the HBQs and post buffers to the HBQ. The caller is not
  3795. * required to hold any locks. This function will return zero if successful
  3796. * else it will return negative error code.
  3797. **/
  3798. static int
  3799. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3800. {
  3801. int hbq_count = lpfc_sli_hbq_count();
  3802. LPFC_MBOXQ_t *pmb;
  3803. MAILBOX_t *pmbox;
  3804. uint32_t hbqno;
  3805. uint32_t hbq_entry_index;
  3806. /* Get a Mailbox buffer to setup mailbox
  3807. * commands for HBA initialization
  3808. */
  3809. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3810. if (!pmb)
  3811. return -ENOMEM;
  3812. pmbox = &pmb->u.mb;
  3813. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3814. phba->link_state = LPFC_INIT_MBX_CMDS;
  3815. phba->hbq_in_use = 1;
  3816. hbq_entry_index = 0;
  3817. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3818. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3819. phba->hbqs[hbqno].hbqPutIdx = 0;
  3820. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3821. phba->hbqs[hbqno].entry_count =
  3822. lpfc_hbq_defs[hbqno]->entry_count;
  3823. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3824. hbq_entry_index, pmb);
  3825. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3826. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3827. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3828. mbxStatus <status>, ring <num> */
  3829. lpfc_printf_log(phba, KERN_ERR,
  3830. LOG_SLI | LOG_VPORT,
  3831. "1805 Adapter failed to init. "
  3832. "Data: x%x x%x x%x\n",
  3833. pmbox->mbxCommand,
  3834. pmbox->mbxStatus, hbqno);
  3835. phba->link_state = LPFC_HBA_ERROR;
  3836. mempool_free(pmb, phba->mbox_mem_pool);
  3837. return -ENXIO;
  3838. }
  3839. }
  3840. phba->hbq_count = hbq_count;
  3841. mempool_free(pmb, phba->mbox_mem_pool);
  3842. /* Initially populate or replenish the HBQs */
  3843. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3844. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3845. return 0;
  3846. }
  3847. /**
  3848. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3849. * @phba: Pointer to HBA context object.
  3850. *
  3851. * This function is called during the SLI initialization to configure
  3852. * all the HBQs and post buffers to the HBQ. The caller is not
  3853. * required to hold any locks. This function will return zero if successful
  3854. * else it will return negative error code.
  3855. **/
  3856. static int
  3857. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3858. {
  3859. phba->hbq_in_use = 1;
  3860. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3861. phba->hbq_count = 1;
  3862. /* Initially populate or replenish the HBQs */
  3863. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3864. return 0;
  3865. }
  3866. /**
  3867. * lpfc_sli_config_port - Issue config port mailbox command
  3868. * @phba: Pointer to HBA context object.
  3869. * @sli_mode: sli mode - 2/3
  3870. *
  3871. * This function is called by the sli intialization code path
  3872. * to issue config_port mailbox command. This function restarts the
  3873. * HBA firmware and issues a config_port mailbox command to configure
  3874. * the SLI interface in the sli mode specified by sli_mode
  3875. * variable. The caller is not required to hold any locks.
  3876. * The function returns 0 if successful, else returns negative error
  3877. * code.
  3878. **/
  3879. int
  3880. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3881. {
  3882. LPFC_MBOXQ_t *pmb;
  3883. uint32_t resetcount = 0, rc = 0, done = 0;
  3884. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3885. if (!pmb) {
  3886. phba->link_state = LPFC_HBA_ERROR;
  3887. return -ENOMEM;
  3888. }
  3889. phba->sli_rev = sli_mode;
  3890. while (resetcount < 2 && !done) {
  3891. spin_lock_irq(&phba->hbalock);
  3892. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3893. spin_unlock_irq(&phba->hbalock);
  3894. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3895. lpfc_sli_brdrestart(phba);
  3896. rc = lpfc_sli_chipset_init(phba);
  3897. if (rc)
  3898. break;
  3899. spin_lock_irq(&phba->hbalock);
  3900. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3901. spin_unlock_irq(&phba->hbalock);
  3902. resetcount++;
  3903. /* Call pre CONFIG_PORT mailbox command initialization. A
  3904. * value of 0 means the call was successful. Any other
  3905. * nonzero value is a failure, but if ERESTART is returned,
  3906. * the driver may reset the HBA and try again.
  3907. */
  3908. rc = lpfc_config_port_prep(phba);
  3909. if (rc == -ERESTART) {
  3910. phba->link_state = LPFC_LINK_UNKNOWN;
  3911. continue;
  3912. } else if (rc)
  3913. break;
  3914. phba->link_state = LPFC_INIT_MBX_CMDS;
  3915. lpfc_config_port(phba, pmb);
  3916. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3917. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3918. LPFC_SLI3_HBQ_ENABLED |
  3919. LPFC_SLI3_CRP_ENABLED |
  3920. LPFC_SLI3_BG_ENABLED |
  3921. LPFC_SLI3_DSS_ENABLED);
  3922. if (rc != MBX_SUCCESS) {
  3923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3924. "0442 Adapter failed to init, mbxCmd x%x "
  3925. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3926. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3927. spin_lock_irq(&phba->hbalock);
  3928. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3929. spin_unlock_irq(&phba->hbalock);
  3930. rc = -ENXIO;
  3931. } else {
  3932. /* Allow asynchronous mailbox command to go through */
  3933. spin_lock_irq(&phba->hbalock);
  3934. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3935. spin_unlock_irq(&phba->hbalock);
  3936. done = 1;
  3937. }
  3938. }
  3939. if (!done) {
  3940. rc = -EINVAL;
  3941. goto do_prep_failed;
  3942. }
  3943. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3944. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3945. rc = -ENXIO;
  3946. goto do_prep_failed;
  3947. }
  3948. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3949. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3950. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3951. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3952. phba->max_vpi : phba->max_vports;
  3953. } else
  3954. phba->max_vpi = 0;
  3955. phba->fips_level = 0;
  3956. phba->fips_spec_rev = 0;
  3957. if (pmb->u.mb.un.varCfgPort.gdss) {
  3958. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3959. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3960. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3961. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3962. "2850 Security Crypto Active. FIPS x%d "
  3963. "(Spec Rev: x%d)",
  3964. phba->fips_level, phba->fips_spec_rev);
  3965. }
  3966. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3968. "2856 Config Port Security Crypto "
  3969. "Error: x%x ",
  3970. pmb->u.mb.un.varCfgPort.sec_err);
  3971. }
  3972. if (pmb->u.mb.un.varCfgPort.gerbm)
  3973. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3974. if (pmb->u.mb.un.varCfgPort.gcrp)
  3975. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3976. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3977. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3978. if (phba->cfg_enable_bg) {
  3979. if (pmb->u.mb.un.varCfgPort.gbg)
  3980. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3981. else
  3982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3983. "0443 Adapter did not grant "
  3984. "BlockGuard\n");
  3985. }
  3986. } else {
  3987. phba->hbq_get = NULL;
  3988. phba->port_gp = phba->mbox->us.s2.port;
  3989. phba->max_vpi = 0;
  3990. }
  3991. do_prep_failed:
  3992. mempool_free(pmb, phba->mbox_mem_pool);
  3993. return rc;
  3994. }
  3995. /**
  3996. * lpfc_sli_hba_setup - SLI intialization function
  3997. * @phba: Pointer to HBA context object.
  3998. *
  3999. * This function is the main SLI intialization function. This function
  4000. * is called by the HBA intialization code, HBA reset code and HBA
  4001. * error attention handler code. Caller is not required to hold any
  4002. * locks. This function issues config_port mailbox command to configure
  4003. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4004. * calls the config_port_post function to issue init_link mailbox
  4005. * command and to start the discovery. The function will return zero
  4006. * if successful, else it will return negative error code.
  4007. **/
  4008. int
  4009. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4010. {
  4011. uint32_t rc;
  4012. int mode = 3;
  4013. switch (lpfc_sli_mode) {
  4014. case 2:
  4015. if (phba->cfg_enable_npiv) {
  4016. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4017. "1824 NPIV enabled: Override lpfc_sli_mode "
  4018. "parameter (%d) to auto (0).\n",
  4019. lpfc_sli_mode);
  4020. break;
  4021. }
  4022. mode = 2;
  4023. break;
  4024. case 0:
  4025. case 3:
  4026. break;
  4027. default:
  4028. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4029. "1819 Unrecognized lpfc_sli_mode "
  4030. "parameter: %d.\n", lpfc_sli_mode);
  4031. break;
  4032. }
  4033. rc = lpfc_sli_config_port(phba, mode);
  4034. if (rc && lpfc_sli_mode == 3)
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4036. "1820 Unable to select SLI-3. "
  4037. "Not supported by adapter.\n");
  4038. if (rc && mode != 2)
  4039. rc = lpfc_sli_config_port(phba, 2);
  4040. if (rc)
  4041. goto lpfc_sli_hba_setup_error;
  4042. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4043. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4044. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4045. if (!rc) {
  4046. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4047. "2709 This device supports "
  4048. "Advanced Error Reporting (AER)\n");
  4049. spin_lock_irq(&phba->hbalock);
  4050. phba->hba_flag |= HBA_AER_ENABLED;
  4051. spin_unlock_irq(&phba->hbalock);
  4052. } else {
  4053. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4054. "2708 This device does not support "
  4055. "Advanced Error Reporting (AER)\n");
  4056. phba->cfg_aer_support = 0;
  4057. }
  4058. }
  4059. if (phba->sli_rev == 3) {
  4060. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4061. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4062. } else {
  4063. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4064. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4065. phba->sli3_options = 0;
  4066. }
  4067. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4068. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4069. phba->sli_rev, phba->max_vpi);
  4070. rc = lpfc_sli_ring_map(phba);
  4071. if (rc)
  4072. goto lpfc_sli_hba_setup_error;
  4073. /* Init HBQs */
  4074. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4075. rc = lpfc_sli_hbq_setup(phba);
  4076. if (rc)
  4077. goto lpfc_sli_hba_setup_error;
  4078. }
  4079. spin_lock_irq(&phba->hbalock);
  4080. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4081. spin_unlock_irq(&phba->hbalock);
  4082. rc = lpfc_config_port_post(phba);
  4083. if (rc)
  4084. goto lpfc_sli_hba_setup_error;
  4085. return rc;
  4086. lpfc_sli_hba_setup_error:
  4087. phba->link_state = LPFC_HBA_ERROR;
  4088. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4089. "0445 Firmware initialization failed\n");
  4090. return rc;
  4091. }
  4092. /**
  4093. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4094. * @phba: Pointer to HBA context object.
  4095. * @mboxq: mailbox pointer.
  4096. * This function issue a dump mailbox command to read config region
  4097. * 23 and parse the records in the region and populate driver
  4098. * data structure.
  4099. **/
  4100. static int
  4101. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  4102. LPFC_MBOXQ_t *mboxq)
  4103. {
  4104. struct lpfc_dmabuf *mp;
  4105. struct lpfc_mqe *mqe;
  4106. uint32_t data_length;
  4107. int rc;
  4108. /* Program the default value of vlan_id and fc_map */
  4109. phba->valid_vlan = 0;
  4110. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4111. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4112. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4113. mqe = &mboxq->u.mqe;
  4114. if (lpfc_dump_fcoe_param(phba, mboxq))
  4115. return -ENOMEM;
  4116. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4117. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4118. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4119. "(%d):2571 Mailbox cmd x%x Status x%x "
  4120. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4121. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4122. "CQ: x%x x%x x%x x%x\n",
  4123. mboxq->vport ? mboxq->vport->vpi : 0,
  4124. bf_get(lpfc_mqe_command, mqe),
  4125. bf_get(lpfc_mqe_status, mqe),
  4126. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4127. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4128. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4129. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4130. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4131. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4132. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4133. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4134. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4135. mboxq->mcqe.word0,
  4136. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4137. mboxq->mcqe.trailer);
  4138. if (rc) {
  4139. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4140. kfree(mp);
  4141. return -EIO;
  4142. }
  4143. data_length = mqe->un.mb_words[5];
  4144. if (data_length > DMP_RGN23_SIZE) {
  4145. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4146. kfree(mp);
  4147. return -EIO;
  4148. }
  4149. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4150. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4151. kfree(mp);
  4152. return 0;
  4153. }
  4154. /**
  4155. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4156. * @phba: pointer to lpfc hba data structure.
  4157. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4158. * @vpd: pointer to the memory to hold resulting port vpd data.
  4159. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4160. * On output, the number of data bytes in @vpd.
  4161. *
  4162. * This routine executes a READ_REV SLI4 mailbox command. In
  4163. * addition, this routine gets the port vpd data.
  4164. *
  4165. * Return codes
  4166. * 0 - successful
  4167. * -ENOMEM - could not allocated memory.
  4168. **/
  4169. static int
  4170. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4171. uint8_t *vpd, uint32_t *vpd_size)
  4172. {
  4173. int rc = 0;
  4174. uint32_t dma_size;
  4175. struct lpfc_dmabuf *dmabuf;
  4176. struct lpfc_mqe *mqe;
  4177. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4178. if (!dmabuf)
  4179. return -ENOMEM;
  4180. /*
  4181. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4182. * mailbox command.
  4183. */
  4184. dma_size = *vpd_size;
  4185. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4186. dma_size,
  4187. &dmabuf->phys,
  4188. GFP_KERNEL);
  4189. if (!dmabuf->virt) {
  4190. kfree(dmabuf);
  4191. return -ENOMEM;
  4192. }
  4193. memset(dmabuf->virt, 0, dma_size);
  4194. /*
  4195. * The SLI4 implementation of READ_REV conflicts at word1,
  4196. * bits 31:16 and SLI4 adds vpd functionality not present
  4197. * in SLI3. This code corrects the conflicts.
  4198. */
  4199. lpfc_read_rev(phba, mboxq);
  4200. mqe = &mboxq->u.mqe;
  4201. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4202. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4203. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4204. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4205. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4206. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4207. if (rc) {
  4208. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4209. dmabuf->virt, dmabuf->phys);
  4210. kfree(dmabuf);
  4211. return -EIO;
  4212. }
  4213. /*
  4214. * The available vpd length cannot be bigger than the
  4215. * DMA buffer passed to the port. Catch the less than
  4216. * case and update the caller's size.
  4217. */
  4218. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4219. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4220. memcpy(vpd, dmabuf->virt, *vpd_size);
  4221. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4222. dmabuf->virt, dmabuf->phys);
  4223. kfree(dmabuf);
  4224. return 0;
  4225. }
  4226. /**
  4227. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4228. * @phba: pointer to lpfc hba data structure.
  4229. *
  4230. * This routine is called to explicitly arm the SLI4 device's completion and
  4231. * event queues
  4232. **/
  4233. static void
  4234. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4235. {
  4236. uint8_t fcp_eqidx;
  4237. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4238. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4239. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4240. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4241. LPFC_QUEUE_REARM);
  4242. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4243. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  4244. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4245. LPFC_QUEUE_REARM);
  4246. }
  4247. /**
  4248. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  4249. * @phba: Pointer to HBA context object.
  4250. *
  4251. * This function is the main SLI4 device intialization PCI function. This
  4252. * function is called by the HBA intialization code, HBA reset code and
  4253. * HBA error attention handler code. Caller is not required to hold any
  4254. * locks.
  4255. **/
  4256. int
  4257. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  4258. {
  4259. int rc;
  4260. LPFC_MBOXQ_t *mboxq;
  4261. struct lpfc_mqe *mqe;
  4262. uint8_t *vpd;
  4263. uint32_t vpd_size;
  4264. uint32_t ftr_rsp = 0;
  4265. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  4266. struct lpfc_vport *vport = phba->pport;
  4267. struct lpfc_dmabuf *mp;
  4268. /*
  4269. * TODO: Why does this routine execute these task in a different
  4270. * order from probe?
  4271. */
  4272. /* Perform a PCI function reset to start from clean */
  4273. rc = lpfc_pci_function_reset(phba);
  4274. if (unlikely(rc))
  4275. return -ENODEV;
  4276. /* Check the HBA Host Status Register for readyness */
  4277. rc = lpfc_sli4_post_status_check(phba);
  4278. if (unlikely(rc))
  4279. return -ENODEV;
  4280. else {
  4281. spin_lock_irq(&phba->hbalock);
  4282. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  4283. spin_unlock_irq(&phba->hbalock);
  4284. }
  4285. /*
  4286. * Allocate a single mailbox container for initializing the
  4287. * port.
  4288. */
  4289. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4290. if (!mboxq)
  4291. return -ENOMEM;
  4292. /*
  4293. * Continue initialization with default values even if driver failed
  4294. * to read FCoE param config regions
  4295. */
  4296. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  4297. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4298. "2570 Failed to read FCoE parameters\n");
  4299. /* Issue READ_REV to collect vpd and FW information. */
  4300. vpd_size = SLI4_PAGE_SIZE;
  4301. vpd = kzalloc(vpd_size, GFP_KERNEL);
  4302. if (!vpd) {
  4303. rc = -ENOMEM;
  4304. goto out_free_mbox;
  4305. }
  4306. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  4307. if (unlikely(rc)) {
  4308. kfree(vpd);
  4309. goto out_free_mbox;
  4310. }
  4311. mqe = &mboxq->u.mqe;
  4312. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  4313. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  4314. phba->hba_flag |= HBA_FCOE_MODE;
  4315. else
  4316. phba->hba_flag &= ~HBA_FCOE_MODE;
  4317. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  4318. LPFC_DCBX_CEE_MODE)
  4319. phba->hba_flag |= HBA_FIP_SUPPORT;
  4320. else
  4321. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  4322. if (phba->sli_rev != LPFC_SLI_REV4 ||
  4323. !(phba->hba_flag & HBA_FCOE_MODE)) {
  4324. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4325. "0376 READ_REV Error. SLI Level %d "
  4326. "FCoE enabled %d\n",
  4327. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  4328. rc = -EIO;
  4329. kfree(vpd);
  4330. goto out_free_mbox;
  4331. }
  4332. /*
  4333. * Evaluate the read rev and vpd data. Populate the driver
  4334. * state with the results. If this routine fails, the failure
  4335. * is not fatal as the driver will use generic values.
  4336. */
  4337. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  4338. if (unlikely(!rc)) {
  4339. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4340. "0377 Error %d parsing vpd. "
  4341. "Using defaults.\n", rc);
  4342. rc = 0;
  4343. }
  4344. kfree(vpd);
  4345. /* Save information as VPD data */
  4346. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  4347. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  4348. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  4349. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  4350. &mqe->un.read_rev);
  4351. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  4352. &mqe->un.read_rev);
  4353. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  4354. &mqe->un.read_rev);
  4355. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  4356. &mqe->un.read_rev);
  4357. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  4358. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  4359. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  4360. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  4361. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  4362. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  4363. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4364. "(%d):0380 READ_REV Status x%x "
  4365. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4366. mboxq->vport ? mboxq->vport->vpi : 0,
  4367. bf_get(lpfc_mqe_status, mqe),
  4368. phba->vpd.rev.opFwName,
  4369. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4370. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4371. /*
  4372. * Discover the port's supported feature set and match it against the
  4373. * hosts requests.
  4374. */
  4375. lpfc_request_features(phba, mboxq);
  4376. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4377. if (unlikely(rc)) {
  4378. rc = -EIO;
  4379. goto out_free_mbox;
  4380. }
  4381. /*
  4382. * The port must support FCP initiator mode as this is the
  4383. * only mode running in the host.
  4384. */
  4385. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4386. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4387. "0378 No support for fcpi mode.\n");
  4388. ftr_rsp++;
  4389. }
  4390. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  4391. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  4392. else
  4393. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  4394. /*
  4395. * If the port cannot support the host's requested features
  4396. * then turn off the global config parameters to disable the
  4397. * feature in the driver. This is not a fatal error.
  4398. */
  4399. if ((phba->cfg_enable_bg) &&
  4400. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4401. ftr_rsp++;
  4402. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4403. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4404. ftr_rsp++;
  4405. if (ftr_rsp) {
  4406. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4407. "0379 Feature Mismatch Data: x%08x %08x "
  4408. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4409. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4410. phba->cfg_enable_npiv, phba->max_vpi);
  4411. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4412. phba->cfg_enable_bg = 0;
  4413. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4414. phba->cfg_enable_npiv = 0;
  4415. }
  4416. /* These SLI3 features are assumed in SLI4 */
  4417. spin_lock_irq(&phba->hbalock);
  4418. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4419. spin_unlock_irq(&phba->hbalock);
  4420. /* Read the port's service parameters. */
  4421. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4422. if (rc) {
  4423. phba->link_state = LPFC_HBA_ERROR;
  4424. rc = -ENOMEM;
  4425. goto out_free_mbox;
  4426. }
  4427. mboxq->vport = vport;
  4428. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4429. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4430. if (rc == MBX_SUCCESS) {
  4431. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4432. rc = 0;
  4433. }
  4434. /*
  4435. * This memory was allocated by the lpfc_read_sparam routine. Release
  4436. * it to the mbuf pool.
  4437. */
  4438. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4439. kfree(mp);
  4440. mboxq->context1 = NULL;
  4441. if (unlikely(rc)) {
  4442. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4443. "0382 READ_SPARAM command failed "
  4444. "status %d, mbxStatus x%x\n",
  4445. rc, bf_get(lpfc_mqe_status, mqe));
  4446. phba->link_state = LPFC_HBA_ERROR;
  4447. rc = -EIO;
  4448. goto out_free_mbox;
  4449. }
  4450. if (phba->cfg_soft_wwnn)
  4451. u64_to_wwn(phba->cfg_soft_wwnn,
  4452. vport->fc_sparam.nodeName.u.wwn);
  4453. if (phba->cfg_soft_wwpn)
  4454. u64_to_wwn(phba->cfg_soft_wwpn,
  4455. vport->fc_sparam.portName.u.wwn);
  4456. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4457. sizeof(struct lpfc_name));
  4458. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4459. sizeof(struct lpfc_name));
  4460. /* Update the fc_host data structures with new wwn. */
  4461. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4462. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4463. /* Register SGL pool to the device using non-embedded mailbox command */
  4464. rc = lpfc_sli4_post_sgl_list(phba);
  4465. if (unlikely(rc)) {
  4466. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4467. "0582 Error %d during sgl post operation\n",
  4468. rc);
  4469. rc = -ENODEV;
  4470. goto out_free_mbox;
  4471. }
  4472. /* Register SCSI SGL pool to the device */
  4473. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4474. if (unlikely(rc)) {
  4475. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4476. "0383 Error %d during scsi sgl post "
  4477. "operation\n", rc);
  4478. /* Some Scsi buffers were moved to the abort scsi list */
  4479. /* A pci function reset will repost them */
  4480. rc = -ENODEV;
  4481. goto out_free_mbox;
  4482. }
  4483. /* Post the rpi header region to the device. */
  4484. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4485. if (unlikely(rc)) {
  4486. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4487. "0393 Error %d during rpi post operation\n",
  4488. rc);
  4489. rc = -ENODEV;
  4490. goto out_free_mbox;
  4491. }
  4492. /* Set up all the queues to the device */
  4493. rc = lpfc_sli4_queue_setup(phba);
  4494. if (unlikely(rc)) {
  4495. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4496. "0381 Error %d during queue setup.\n ", rc);
  4497. goto out_stop_timers;
  4498. }
  4499. /* Arm the CQs and then EQs on device */
  4500. lpfc_sli4_arm_cqeq_intr(phba);
  4501. /* Indicate device interrupt mode */
  4502. phba->sli4_hba.intr_enable = 1;
  4503. /* Allow asynchronous mailbox command to go through */
  4504. spin_lock_irq(&phba->hbalock);
  4505. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4506. spin_unlock_irq(&phba->hbalock);
  4507. /* Post receive buffers to the device */
  4508. lpfc_sli4_rb_setup(phba);
  4509. /* Reset HBA FCF states after HBA reset */
  4510. phba->fcf.fcf_flag = 0;
  4511. phba->fcf.current_rec.flag = 0;
  4512. /* Start the ELS watchdog timer */
  4513. mod_timer(&vport->els_tmofunc,
  4514. jiffies + HZ * (phba->fc_ratov * 2));
  4515. /* Start heart beat timer */
  4516. mod_timer(&phba->hb_tmofunc,
  4517. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4518. phba->hb_outstanding = 0;
  4519. phba->last_completion_time = jiffies;
  4520. /* Start error attention (ERATT) polling timer */
  4521. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4522. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4523. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4524. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4525. if (!rc) {
  4526. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4527. "2829 This device supports "
  4528. "Advanced Error Reporting (AER)\n");
  4529. spin_lock_irq(&phba->hbalock);
  4530. phba->hba_flag |= HBA_AER_ENABLED;
  4531. spin_unlock_irq(&phba->hbalock);
  4532. } else {
  4533. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4534. "2830 This device does not support "
  4535. "Advanced Error Reporting (AER)\n");
  4536. phba->cfg_aer_support = 0;
  4537. }
  4538. }
  4539. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4540. /*
  4541. * The FC Port needs to register FCFI (index 0)
  4542. */
  4543. lpfc_reg_fcfi(phba, mboxq);
  4544. mboxq->vport = phba->pport;
  4545. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4546. if (rc != MBX_SUCCESS)
  4547. goto out_unset_queue;
  4548. rc = 0;
  4549. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  4550. &mboxq->u.mqe.un.reg_fcfi);
  4551. }
  4552. /*
  4553. * The port is ready, set the host's link state to LINK_DOWN
  4554. * in preparation for link interrupts.
  4555. */
  4556. spin_lock_irq(&phba->hbalock);
  4557. phba->link_state = LPFC_LINK_DOWN;
  4558. spin_unlock_irq(&phba->hbalock);
  4559. if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
  4560. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4561. out_unset_queue:
  4562. /* Unset all the queues set up in this routine when error out */
  4563. if (rc)
  4564. lpfc_sli4_queue_unset(phba);
  4565. out_stop_timers:
  4566. if (rc)
  4567. lpfc_stop_hba_timers(phba);
  4568. out_free_mbox:
  4569. mempool_free(mboxq, phba->mbox_mem_pool);
  4570. return rc;
  4571. }
  4572. /**
  4573. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4574. * @ptr: context object - pointer to hba structure.
  4575. *
  4576. * This is the callback function for mailbox timer. The mailbox
  4577. * timer is armed when a new mailbox command is issued and the timer
  4578. * is deleted when the mailbox complete. The function is called by
  4579. * the kernel timer code when a mailbox does not complete within
  4580. * expected time. This function wakes up the worker thread to
  4581. * process the mailbox timeout and returns. All the processing is
  4582. * done by the worker thread function lpfc_mbox_timeout_handler.
  4583. **/
  4584. void
  4585. lpfc_mbox_timeout(unsigned long ptr)
  4586. {
  4587. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4588. unsigned long iflag;
  4589. uint32_t tmo_posted;
  4590. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4591. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4592. if (!tmo_posted)
  4593. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4594. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4595. if (!tmo_posted)
  4596. lpfc_worker_wake_up(phba);
  4597. return;
  4598. }
  4599. /**
  4600. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4601. * @phba: Pointer to HBA context object.
  4602. *
  4603. * This function is called from worker thread when a mailbox command times out.
  4604. * The caller is not required to hold any locks. This function will reset the
  4605. * HBA and recover all the pending commands.
  4606. **/
  4607. void
  4608. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4609. {
  4610. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4611. MAILBOX_t *mb = &pmbox->u.mb;
  4612. struct lpfc_sli *psli = &phba->sli;
  4613. struct lpfc_sli_ring *pring;
  4614. /* Check the pmbox pointer first. There is a race condition
  4615. * between the mbox timeout handler getting executed in the
  4616. * worklist and the mailbox actually completing. When this
  4617. * race condition occurs, the mbox_active will be NULL.
  4618. */
  4619. spin_lock_irq(&phba->hbalock);
  4620. if (pmbox == NULL) {
  4621. lpfc_printf_log(phba, KERN_WARNING,
  4622. LOG_MBOX | LOG_SLI,
  4623. "0353 Active Mailbox cleared - mailbox timeout "
  4624. "exiting\n");
  4625. spin_unlock_irq(&phba->hbalock);
  4626. return;
  4627. }
  4628. /* Mbox cmd <mbxCommand> timeout */
  4629. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4630. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4631. mb->mbxCommand,
  4632. phba->pport->port_state,
  4633. phba->sli.sli_flag,
  4634. phba->sli.mbox_active);
  4635. spin_unlock_irq(&phba->hbalock);
  4636. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4637. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4638. * it to fail all outstanding SCSI IO.
  4639. */
  4640. spin_lock_irq(&phba->pport->work_port_lock);
  4641. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4642. spin_unlock_irq(&phba->pport->work_port_lock);
  4643. spin_lock_irq(&phba->hbalock);
  4644. phba->link_state = LPFC_LINK_UNKNOWN;
  4645. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4646. spin_unlock_irq(&phba->hbalock);
  4647. pring = &psli->ring[psli->fcp_ring];
  4648. lpfc_sli_abort_iocb_ring(phba, pring);
  4649. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4650. "0345 Resetting board due to mailbox timeout\n");
  4651. /* Reset the HBA device */
  4652. lpfc_reset_hba(phba);
  4653. }
  4654. /**
  4655. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4656. * @phba: Pointer to HBA context object.
  4657. * @pmbox: Pointer to mailbox object.
  4658. * @flag: Flag indicating how the mailbox need to be processed.
  4659. *
  4660. * This function is called by discovery code and HBA management code
  4661. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4662. * function gets the hbalock to protect the data structures.
  4663. * The mailbox command can be submitted in polling mode, in which case
  4664. * this function will wait in a polling loop for the completion of the
  4665. * mailbox.
  4666. * If the mailbox is submitted in no_wait mode (not polling) the
  4667. * function will submit the command and returns immediately without waiting
  4668. * for the mailbox completion. The no_wait is supported only when HBA
  4669. * is in SLI2/SLI3 mode - interrupts are enabled.
  4670. * The SLI interface allows only one mailbox pending at a time. If the
  4671. * mailbox is issued in polling mode and there is already a mailbox
  4672. * pending, then the function will return an error. If the mailbox is issued
  4673. * in NO_WAIT mode and there is a mailbox pending already, the function
  4674. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4675. * The sli layer owns the mailbox object until the completion of mailbox
  4676. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4677. * return codes the caller owns the mailbox command after the return of
  4678. * the function.
  4679. **/
  4680. static int
  4681. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4682. uint32_t flag)
  4683. {
  4684. MAILBOX_t *mb;
  4685. struct lpfc_sli *psli = &phba->sli;
  4686. uint32_t status, evtctr;
  4687. uint32_t ha_copy, hc_copy;
  4688. int i;
  4689. unsigned long timeout;
  4690. unsigned long drvr_flag = 0;
  4691. uint32_t word0, ldata;
  4692. void __iomem *to_slim;
  4693. int processing_queue = 0;
  4694. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4695. if (!pmbox) {
  4696. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4697. /* processing mbox queue from intr_handler */
  4698. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4699. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4700. return MBX_SUCCESS;
  4701. }
  4702. processing_queue = 1;
  4703. pmbox = lpfc_mbox_get(phba);
  4704. if (!pmbox) {
  4705. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4706. return MBX_SUCCESS;
  4707. }
  4708. }
  4709. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4710. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4711. if(!pmbox->vport) {
  4712. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4713. lpfc_printf_log(phba, KERN_ERR,
  4714. LOG_MBOX | LOG_VPORT,
  4715. "1806 Mbox x%x failed. No vport\n",
  4716. pmbox->u.mb.mbxCommand);
  4717. dump_stack();
  4718. goto out_not_finished;
  4719. }
  4720. }
  4721. /* If the PCI channel is in offline state, do not post mbox. */
  4722. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4723. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4724. goto out_not_finished;
  4725. }
  4726. /* If HBA has a deferred error attention, fail the iocb. */
  4727. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4728. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4729. goto out_not_finished;
  4730. }
  4731. psli = &phba->sli;
  4732. mb = &pmbox->u.mb;
  4733. status = MBX_SUCCESS;
  4734. if (phba->link_state == LPFC_HBA_ERROR) {
  4735. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4736. /* Mbox command <mbxCommand> cannot issue */
  4737. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4738. "(%d):0311 Mailbox command x%x cannot "
  4739. "issue Data: x%x x%x\n",
  4740. pmbox->vport ? pmbox->vport->vpi : 0,
  4741. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4742. goto out_not_finished;
  4743. }
  4744. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  4745. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  4746. !(hc_copy & HC_MBINT_ENA)) {
  4747. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4748. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4749. "(%d):2528 Mailbox command x%x cannot "
  4750. "issue Data: x%x x%x\n",
  4751. pmbox->vport ? pmbox->vport->vpi : 0,
  4752. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4753. goto out_not_finished;
  4754. }
  4755. }
  4756. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4757. /* Polling for a mbox command when another one is already active
  4758. * is not allowed in SLI. Also, the driver must have established
  4759. * SLI2 mode to queue and process multiple mbox commands.
  4760. */
  4761. if (flag & MBX_POLL) {
  4762. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4763. /* Mbox command <mbxCommand> cannot issue */
  4764. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4765. "(%d):2529 Mailbox command x%x "
  4766. "cannot issue Data: x%x x%x\n",
  4767. pmbox->vport ? pmbox->vport->vpi : 0,
  4768. pmbox->u.mb.mbxCommand,
  4769. psli->sli_flag, flag);
  4770. goto out_not_finished;
  4771. }
  4772. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4773. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4774. /* Mbox command <mbxCommand> cannot issue */
  4775. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4776. "(%d):2530 Mailbox command x%x "
  4777. "cannot issue Data: x%x x%x\n",
  4778. pmbox->vport ? pmbox->vport->vpi : 0,
  4779. pmbox->u.mb.mbxCommand,
  4780. psli->sli_flag, flag);
  4781. goto out_not_finished;
  4782. }
  4783. /* Another mailbox command is still being processed, queue this
  4784. * command to be processed later.
  4785. */
  4786. lpfc_mbox_put(phba, pmbox);
  4787. /* Mbox cmd issue - BUSY */
  4788. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4789. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4790. "x%x x%x x%x x%x\n",
  4791. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4792. mb->mbxCommand, phba->pport->port_state,
  4793. psli->sli_flag, flag);
  4794. psli->slistat.mbox_busy++;
  4795. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4796. if (pmbox->vport) {
  4797. lpfc_debugfs_disc_trc(pmbox->vport,
  4798. LPFC_DISC_TRC_MBOX_VPORT,
  4799. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4800. (uint32_t)mb->mbxCommand,
  4801. mb->un.varWords[0], mb->un.varWords[1]);
  4802. }
  4803. else {
  4804. lpfc_debugfs_disc_trc(phba->pport,
  4805. LPFC_DISC_TRC_MBOX,
  4806. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4807. (uint32_t)mb->mbxCommand,
  4808. mb->un.varWords[0], mb->un.varWords[1]);
  4809. }
  4810. return MBX_BUSY;
  4811. }
  4812. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4813. /* If we are not polling, we MUST be in SLI2 mode */
  4814. if (flag != MBX_POLL) {
  4815. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4816. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4817. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4818. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4819. /* Mbox command <mbxCommand> cannot issue */
  4820. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4821. "(%d):2531 Mailbox command x%x "
  4822. "cannot issue Data: x%x x%x\n",
  4823. pmbox->vport ? pmbox->vport->vpi : 0,
  4824. pmbox->u.mb.mbxCommand,
  4825. psli->sli_flag, flag);
  4826. goto out_not_finished;
  4827. }
  4828. /* timeout active mbox command */
  4829. mod_timer(&psli->mbox_tmo, (jiffies +
  4830. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4831. }
  4832. /* Mailbox cmd <cmd> issue */
  4833. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4834. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4835. "x%x\n",
  4836. pmbox->vport ? pmbox->vport->vpi : 0,
  4837. mb->mbxCommand, phba->pport->port_state,
  4838. psli->sli_flag, flag);
  4839. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4840. if (pmbox->vport) {
  4841. lpfc_debugfs_disc_trc(pmbox->vport,
  4842. LPFC_DISC_TRC_MBOX_VPORT,
  4843. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4844. (uint32_t)mb->mbxCommand,
  4845. mb->un.varWords[0], mb->un.varWords[1]);
  4846. }
  4847. else {
  4848. lpfc_debugfs_disc_trc(phba->pport,
  4849. LPFC_DISC_TRC_MBOX,
  4850. "MBOX Send: cmd:x%x mb:x%x x%x",
  4851. (uint32_t)mb->mbxCommand,
  4852. mb->un.varWords[0], mb->un.varWords[1]);
  4853. }
  4854. }
  4855. psli->slistat.mbox_cmd++;
  4856. evtctr = psli->slistat.mbox_event;
  4857. /* next set own bit for the adapter and copy over command word */
  4858. mb->mbxOwner = OWN_CHIP;
  4859. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4860. /* Populate mbox extension offset word. */
  4861. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4862. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4863. = (uint8_t *)phba->mbox_ext
  4864. - (uint8_t *)phba->mbox;
  4865. }
  4866. /* Copy the mailbox extension data */
  4867. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4868. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4869. (uint8_t *)phba->mbox_ext,
  4870. pmbox->in_ext_byte_len);
  4871. }
  4872. /* Copy command data to host SLIM area */
  4873. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4874. } else {
  4875. /* Populate mbox extension offset word. */
  4876. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4877. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4878. = MAILBOX_HBA_EXT_OFFSET;
  4879. /* Copy the mailbox extension data */
  4880. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4881. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4882. MAILBOX_HBA_EXT_OFFSET,
  4883. pmbox->context2, pmbox->in_ext_byte_len);
  4884. }
  4885. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4886. /* copy command data into host mbox for cmpl */
  4887. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4888. }
  4889. /* First copy mbox command data to HBA SLIM, skip past first
  4890. word */
  4891. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4892. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4893. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4894. /* Next copy over first word, with mbxOwner set */
  4895. ldata = *((uint32_t *)mb);
  4896. to_slim = phba->MBslimaddr;
  4897. writel(ldata, to_slim);
  4898. readl(to_slim); /* flush */
  4899. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4900. /* switch over to host mailbox */
  4901. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4902. }
  4903. }
  4904. wmb();
  4905. switch (flag) {
  4906. case MBX_NOWAIT:
  4907. /* Set up reference to mailbox command */
  4908. psli->mbox_active = pmbox;
  4909. /* Interrupt board to do it */
  4910. writel(CA_MBATT, phba->CAregaddr);
  4911. readl(phba->CAregaddr); /* flush */
  4912. /* Don't wait for it to finish, just return */
  4913. break;
  4914. case MBX_POLL:
  4915. /* Set up null reference to mailbox command */
  4916. psli->mbox_active = NULL;
  4917. /* Interrupt board to do it */
  4918. writel(CA_MBATT, phba->CAregaddr);
  4919. readl(phba->CAregaddr); /* flush */
  4920. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4921. /* First read mbox status word */
  4922. word0 = *((uint32_t *)phba->mbox);
  4923. word0 = le32_to_cpu(word0);
  4924. } else {
  4925. /* First read mbox status word */
  4926. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  4927. spin_unlock_irqrestore(&phba->hbalock,
  4928. drvr_flag);
  4929. goto out_not_finished;
  4930. }
  4931. }
  4932. /* Read the HBA Host Attention Register */
  4933. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4934. spin_unlock_irqrestore(&phba->hbalock,
  4935. drvr_flag);
  4936. goto out_not_finished;
  4937. }
  4938. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4939. mb->mbxCommand) *
  4940. 1000) + jiffies;
  4941. i = 0;
  4942. /* Wait for command to complete */
  4943. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4944. (!(ha_copy & HA_MBATT) &&
  4945. (phba->link_state > LPFC_WARM_START))) {
  4946. if (time_after(jiffies, timeout)) {
  4947. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4948. spin_unlock_irqrestore(&phba->hbalock,
  4949. drvr_flag);
  4950. goto out_not_finished;
  4951. }
  4952. /* Check if we took a mbox interrupt while we were
  4953. polling */
  4954. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4955. && (evtctr != psli->slistat.mbox_event))
  4956. break;
  4957. if (i++ > 10) {
  4958. spin_unlock_irqrestore(&phba->hbalock,
  4959. drvr_flag);
  4960. msleep(1);
  4961. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4962. }
  4963. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4964. /* First copy command data */
  4965. word0 = *((uint32_t *)phba->mbox);
  4966. word0 = le32_to_cpu(word0);
  4967. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4968. MAILBOX_t *slimmb;
  4969. uint32_t slimword0;
  4970. /* Check real SLIM for any errors */
  4971. slimword0 = readl(phba->MBslimaddr);
  4972. slimmb = (MAILBOX_t *) & slimword0;
  4973. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4974. && slimmb->mbxStatus) {
  4975. psli->sli_flag &=
  4976. ~LPFC_SLI_ACTIVE;
  4977. word0 = slimword0;
  4978. }
  4979. }
  4980. } else {
  4981. /* First copy command data */
  4982. word0 = readl(phba->MBslimaddr);
  4983. }
  4984. /* Read the HBA Host Attention Register */
  4985. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  4986. spin_unlock_irqrestore(&phba->hbalock,
  4987. drvr_flag);
  4988. goto out_not_finished;
  4989. }
  4990. }
  4991. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4992. /* copy results back to user */
  4993. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4994. /* Copy the mailbox extension data */
  4995. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4996. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4997. pmbox->context2,
  4998. pmbox->out_ext_byte_len);
  4999. }
  5000. } else {
  5001. /* First copy command data */
  5002. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  5003. MAILBOX_CMD_SIZE);
  5004. /* Copy the mailbox extension data */
  5005. if (pmbox->out_ext_byte_len && pmbox->context2) {
  5006. lpfc_memcpy_from_slim(pmbox->context2,
  5007. phba->MBslimaddr +
  5008. MAILBOX_HBA_EXT_OFFSET,
  5009. pmbox->out_ext_byte_len);
  5010. }
  5011. }
  5012. writel(HA_MBATT, phba->HAregaddr);
  5013. readl(phba->HAregaddr); /* flush */
  5014. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5015. status = mb->mbxStatus;
  5016. }
  5017. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5018. return status;
  5019. out_not_finished:
  5020. if (processing_queue) {
  5021. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5022. lpfc_mbox_cmpl_put(phba, pmbox);
  5023. }
  5024. return MBX_NOT_FINISHED;
  5025. }
  5026. /**
  5027. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  5028. * @phba: Pointer to HBA context object.
  5029. *
  5030. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  5031. * the driver internal pending mailbox queue. It will then try to wait out the
  5032. * possible outstanding mailbox command before return.
  5033. *
  5034. * Returns:
  5035. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  5036. * the outstanding mailbox command timed out.
  5037. **/
  5038. static int
  5039. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  5040. {
  5041. struct lpfc_sli *psli = &phba->sli;
  5042. uint8_t actcmd = MBX_HEARTBEAT;
  5043. int rc = 0;
  5044. unsigned long timeout;
  5045. /* Mark the asynchronous mailbox command posting as blocked */
  5046. spin_lock_irq(&phba->hbalock);
  5047. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  5048. if (phba->sli.mbox_active)
  5049. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  5050. spin_unlock_irq(&phba->hbalock);
  5051. /* Determine how long we might wait for the active mailbox
  5052. * command to be gracefully completed by firmware.
  5053. */
  5054. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  5055. jiffies;
  5056. /* Wait for the outstnading mailbox command to complete */
  5057. while (phba->sli.mbox_active) {
  5058. /* Check active mailbox complete status every 2ms */
  5059. msleep(2);
  5060. if (time_after(jiffies, timeout)) {
  5061. /* Timeout, marked the outstanding cmd not complete */
  5062. rc = 1;
  5063. break;
  5064. }
  5065. }
  5066. /* Can not cleanly block async mailbox command, fails it */
  5067. if (rc) {
  5068. spin_lock_irq(&phba->hbalock);
  5069. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5070. spin_unlock_irq(&phba->hbalock);
  5071. }
  5072. return rc;
  5073. }
  5074. /**
  5075. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  5076. * @phba: Pointer to HBA context object.
  5077. *
  5078. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  5079. * commands from the driver internal pending mailbox queue. It makes sure
  5080. * that there is no outstanding mailbox command before resuming posting
  5081. * asynchronous mailbox commands. If, for any reason, there is outstanding
  5082. * mailbox command, it will try to wait it out before resuming asynchronous
  5083. * mailbox command posting.
  5084. **/
  5085. static void
  5086. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  5087. {
  5088. struct lpfc_sli *psli = &phba->sli;
  5089. spin_lock_irq(&phba->hbalock);
  5090. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5091. /* Asynchronous mailbox posting is not blocked, do nothing */
  5092. spin_unlock_irq(&phba->hbalock);
  5093. return;
  5094. }
  5095. /* Outstanding synchronous mailbox command is guaranteed to be done,
  5096. * successful or timeout, after timing-out the outstanding mailbox
  5097. * command shall always be removed, so just unblock posting async
  5098. * mailbox command and resume
  5099. */
  5100. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5101. spin_unlock_irq(&phba->hbalock);
  5102. /* wake up worker thread to post asynchronlous mailbox command */
  5103. lpfc_worker_wake_up(phba);
  5104. }
  5105. /**
  5106. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  5107. * @phba: Pointer to HBA context object.
  5108. * @mboxq: Pointer to mailbox object.
  5109. *
  5110. * The function posts a mailbox to the port. The mailbox is expected
  5111. * to be comletely filled in and ready for the port to operate on it.
  5112. * This routine executes a synchronous completion operation on the
  5113. * mailbox by polling for its completion.
  5114. *
  5115. * The caller must not be holding any locks when calling this routine.
  5116. *
  5117. * Returns:
  5118. * MBX_SUCCESS - mailbox posted successfully
  5119. * Any of the MBX error values.
  5120. **/
  5121. static int
  5122. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5123. {
  5124. int rc = MBX_SUCCESS;
  5125. unsigned long iflag;
  5126. uint32_t db_ready;
  5127. uint32_t mcqe_status;
  5128. uint32_t mbx_cmnd;
  5129. unsigned long timeout;
  5130. struct lpfc_sli *psli = &phba->sli;
  5131. struct lpfc_mqe *mb = &mboxq->u.mqe;
  5132. struct lpfc_bmbx_create *mbox_rgn;
  5133. struct dma_address *dma_address;
  5134. struct lpfc_register bmbx_reg;
  5135. /*
  5136. * Only one mailbox can be active to the bootstrap mailbox region
  5137. * at a time and there is no queueing provided.
  5138. */
  5139. spin_lock_irqsave(&phba->hbalock, iflag);
  5140. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5141. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5142. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5143. "(%d):2532 Mailbox command x%x (x%x) "
  5144. "cannot issue Data: x%x x%x\n",
  5145. mboxq->vport ? mboxq->vport->vpi : 0,
  5146. mboxq->u.mb.mbxCommand,
  5147. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5148. psli->sli_flag, MBX_POLL);
  5149. return MBXERR_ERROR;
  5150. }
  5151. /* The server grabs the token and owns it until release */
  5152. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5153. phba->sli.mbox_active = mboxq;
  5154. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5155. /*
  5156. * Initialize the bootstrap memory region to avoid stale data areas
  5157. * in the mailbox post. Then copy the caller's mailbox contents to
  5158. * the bmbx mailbox region.
  5159. */
  5160. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  5161. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  5162. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  5163. sizeof(struct lpfc_mqe));
  5164. /* Post the high mailbox dma address to the port and wait for ready. */
  5165. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5166. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  5167. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5168. * 1000) + jiffies;
  5169. do {
  5170. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5171. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5172. if (!db_ready)
  5173. msleep(2);
  5174. if (time_after(jiffies, timeout)) {
  5175. rc = MBXERR_ERROR;
  5176. goto exit;
  5177. }
  5178. } while (!db_ready);
  5179. /* Post the low mailbox dma address to the port. */
  5180. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  5181. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  5182. * 1000) + jiffies;
  5183. do {
  5184. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  5185. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  5186. if (!db_ready)
  5187. msleep(2);
  5188. if (time_after(jiffies, timeout)) {
  5189. rc = MBXERR_ERROR;
  5190. goto exit;
  5191. }
  5192. } while (!db_ready);
  5193. /*
  5194. * Read the CQ to ensure the mailbox has completed.
  5195. * If so, update the mailbox status so that the upper layers
  5196. * can complete the request normally.
  5197. */
  5198. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  5199. sizeof(struct lpfc_mqe));
  5200. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  5201. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  5202. sizeof(struct lpfc_mcqe));
  5203. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  5204. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  5205. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  5206. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  5207. rc = MBXERR_ERROR;
  5208. } else
  5209. lpfc_sli4_swap_str(phba, mboxq);
  5210. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5211. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  5212. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  5213. " x%x x%x CQ: x%x x%x x%x x%x\n",
  5214. mboxq->vport ? mboxq->vport->vpi : 0,
  5215. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5216. bf_get(lpfc_mqe_status, mb),
  5217. mb->un.mb_words[0], mb->un.mb_words[1],
  5218. mb->un.mb_words[2], mb->un.mb_words[3],
  5219. mb->un.mb_words[4], mb->un.mb_words[5],
  5220. mb->un.mb_words[6], mb->un.mb_words[7],
  5221. mb->un.mb_words[8], mb->un.mb_words[9],
  5222. mb->un.mb_words[10], mb->un.mb_words[11],
  5223. mb->un.mb_words[12], mboxq->mcqe.word0,
  5224. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5225. mboxq->mcqe.trailer);
  5226. exit:
  5227. /* We are holding the token, no needed for lock when release */
  5228. spin_lock_irqsave(&phba->hbalock, iflag);
  5229. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5230. phba->sli.mbox_active = NULL;
  5231. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5232. return rc;
  5233. }
  5234. /**
  5235. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  5236. * @phba: Pointer to HBA context object.
  5237. * @pmbox: Pointer to mailbox object.
  5238. * @flag: Flag indicating how the mailbox need to be processed.
  5239. *
  5240. * This function is called by discovery code and HBA management code to submit
  5241. * a mailbox command to firmware with SLI-4 interface spec.
  5242. *
  5243. * Return codes the caller owns the mailbox command after the return of the
  5244. * function.
  5245. **/
  5246. static int
  5247. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5248. uint32_t flag)
  5249. {
  5250. struct lpfc_sli *psli = &phba->sli;
  5251. unsigned long iflags;
  5252. int rc;
  5253. rc = lpfc_mbox_dev_check(phba);
  5254. if (unlikely(rc)) {
  5255. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5256. "(%d):2544 Mailbox command x%x (x%x) "
  5257. "cannot issue Data: x%x x%x\n",
  5258. mboxq->vport ? mboxq->vport->vpi : 0,
  5259. mboxq->u.mb.mbxCommand,
  5260. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5261. psli->sli_flag, flag);
  5262. goto out_not_finished;
  5263. }
  5264. /* Detect polling mode and jump to a handler */
  5265. if (!phba->sli4_hba.intr_enable) {
  5266. if (flag == MBX_POLL)
  5267. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5268. else
  5269. rc = -EIO;
  5270. if (rc != MBX_SUCCESS)
  5271. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5272. "(%d):2541 Mailbox command x%x "
  5273. "(x%x) cannot issue Data: x%x x%x\n",
  5274. mboxq->vport ? mboxq->vport->vpi : 0,
  5275. mboxq->u.mb.mbxCommand,
  5276. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5277. psli->sli_flag, flag);
  5278. return rc;
  5279. } else if (flag == MBX_POLL) {
  5280. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5281. "(%d):2542 Try to issue mailbox command "
  5282. "x%x (x%x) synchronously ahead of async"
  5283. "mailbox command queue: x%x x%x\n",
  5284. mboxq->vport ? mboxq->vport->vpi : 0,
  5285. mboxq->u.mb.mbxCommand,
  5286. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5287. psli->sli_flag, flag);
  5288. /* Try to block the asynchronous mailbox posting */
  5289. rc = lpfc_sli4_async_mbox_block(phba);
  5290. if (!rc) {
  5291. /* Successfully blocked, now issue sync mbox cmd */
  5292. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  5293. if (rc != MBX_SUCCESS)
  5294. lpfc_printf_log(phba, KERN_ERR,
  5295. LOG_MBOX | LOG_SLI,
  5296. "(%d):2597 Mailbox command "
  5297. "x%x (x%x) cannot issue "
  5298. "Data: x%x x%x\n",
  5299. mboxq->vport ?
  5300. mboxq->vport->vpi : 0,
  5301. mboxq->u.mb.mbxCommand,
  5302. lpfc_sli4_mbox_opcode_get(phba,
  5303. mboxq),
  5304. psli->sli_flag, flag);
  5305. /* Unblock the async mailbox posting afterward */
  5306. lpfc_sli4_async_mbox_unblock(phba);
  5307. }
  5308. return rc;
  5309. }
  5310. /* Now, interrupt mode asynchrous mailbox command */
  5311. rc = lpfc_mbox_cmd_check(phba, mboxq);
  5312. if (rc) {
  5313. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5314. "(%d):2543 Mailbox command x%x (x%x) "
  5315. "cannot issue Data: x%x x%x\n",
  5316. mboxq->vport ? mboxq->vport->vpi : 0,
  5317. mboxq->u.mb.mbxCommand,
  5318. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5319. psli->sli_flag, flag);
  5320. goto out_not_finished;
  5321. }
  5322. /* Put the mailbox command to the driver internal FIFO */
  5323. psli->slistat.mbox_busy++;
  5324. spin_lock_irqsave(&phba->hbalock, iflags);
  5325. lpfc_mbox_put(phba, mboxq);
  5326. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5327. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5328. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  5329. "x%x (x%x) x%x x%x x%x\n",
  5330. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  5331. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5332. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5333. phba->pport->port_state,
  5334. psli->sli_flag, MBX_NOWAIT);
  5335. /* Wake up worker thread to transport mailbox command from head */
  5336. lpfc_worker_wake_up(phba);
  5337. return MBX_BUSY;
  5338. out_not_finished:
  5339. return MBX_NOT_FINISHED;
  5340. }
  5341. /**
  5342. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  5343. * @phba: Pointer to HBA context object.
  5344. *
  5345. * This function is called by worker thread to send a mailbox command to
  5346. * SLI4 HBA firmware.
  5347. *
  5348. **/
  5349. int
  5350. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  5351. {
  5352. struct lpfc_sli *psli = &phba->sli;
  5353. LPFC_MBOXQ_t *mboxq;
  5354. int rc = MBX_SUCCESS;
  5355. unsigned long iflags;
  5356. struct lpfc_mqe *mqe;
  5357. uint32_t mbx_cmnd;
  5358. /* Check interrupt mode before post async mailbox command */
  5359. if (unlikely(!phba->sli4_hba.intr_enable))
  5360. return MBX_NOT_FINISHED;
  5361. /* Check for mailbox command service token */
  5362. spin_lock_irqsave(&phba->hbalock, iflags);
  5363. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5364. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5365. return MBX_NOT_FINISHED;
  5366. }
  5367. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5368. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5369. return MBX_NOT_FINISHED;
  5370. }
  5371. if (unlikely(phba->sli.mbox_active)) {
  5372. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5373. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5374. "0384 There is pending active mailbox cmd\n");
  5375. return MBX_NOT_FINISHED;
  5376. }
  5377. /* Take the mailbox command service token */
  5378. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5379. /* Get the next mailbox command from head of queue */
  5380. mboxq = lpfc_mbox_get(phba);
  5381. /* If no more mailbox command waiting for post, we're done */
  5382. if (!mboxq) {
  5383. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5384. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5385. return MBX_SUCCESS;
  5386. }
  5387. phba->sli.mbox_active = mboxq;
  5388. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5389. /* Check device readiness for posting mailbox command */
  5390. rc = lpfc_mbox_dev_check(phba);
  5391. if (unlikely(rc))
  5392. /* Driver clean routine will clean up pending mailbox */
  5393. goto out_not_finished;
  5394. /* Prepare the mbox command to be posted */
  5395. mqe = &mboxq->u.mqe;
  5396. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5397. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5398. mod_timer(&psli->mbox_tmo, (jiffies +
  5399. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5400. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5401. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5402. "x%x x%x\n",
  5403. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5404. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5405. phba->pport->port_state, psli->sli_flag);
  5406. if (mbx_cmnd != MBX_HEARTBEAT) {
  5407. if (mboxq->vport) {
  5408. lpfc_debugfs_disc_trc(mboxq->vport,
  5409. LPFC_DISC_TRC_MBOX_VPORT,
  5410. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5411. mbx_cmnd, mqe->un.mb_words[0],
  5412. mqe->un.mb_words[1]);
  5413. } else {
  5414. lpfc_debugfs_disc_trc(phba->pport,
  5415. LPFC_DISC_TRC_MBOX,
  5416. "MBOX Send: cmd:x%x mb:x%x x%x",
  5417. mbx_cmnd, mqe->un.mb_words[0],
  5418. mqe->un.mb_words[1]);
  5419. }
  5420. }
  5421. psli->slistat.mbox_cmd++;
  5422. /* Post the mailbox command to the port */
  5423. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5424. if (rc != MBX_SUCCESS) {
  5425. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5426. "(%d):2533 Mailbox command x%x (x%x) "
  5427. "cannot issue Data: x%x x%x\n",
  5428. mboxq->vport ? mboxq->vport->vpi : 0,
  5429. mboxq->u.mb.mbxCommand,
  5430. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5431. psli->sli_flag, MBX_NOWAIT);
  5432. goto out_not_finished;
  5433. }
  5434. return rc;
  5435. out_not_finished:
  5436. spin_lock_irqsave(&phba->hbalock, iflags);
  5437. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5438. __lpfc_mbox_cmpl_put(phba, mboxq);
  5439. /* Release the token */
  5440. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5441. phba->sli.mbox_active = NULL;
  5442. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5443. return MBX_NOT_FINISHED;
  5444. }
  5445. /**
  5446. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5447. * @phba: Pointer to HBA context object.
  5448. * @pmbox: Pointer to mailbox object.
  5449. * @flag: Flag indicating how the mailbox need to be processed.
  5450. *
  5451. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5452. * the API jump table function pointer from the lpfc_hba struct.
  5453. *
  5454. * Return codes the caller owns the mailbox command after the return of the
  5455. * function.
  5456. **/
  5457. int
  5458. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5459. {
  5460. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5461. }
  5462. /**
  5463. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  5464. * @phba: The hba struct for which this call is being executed.
  5465. * @dev_grp: The HBA PCI-Device group number.
  5466. *
  5467. * This routine sets up the mbox interface API function jump table in @phba
  5468. * struct.
  5469. * Returns: 0 - success, -ENODEV - failure.
  5470. **/
  5471. int
  5472. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5473. {
  5474. switch (dev_grp) {
  5475. case LPFC_PCI_DEV_LP:
  5476. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5477. phba->lpfc_sli_handle_slow_ring_event =
  5478. lpfc_sli_handle_slow_ring_event_s3;
  5479. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5480. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5481. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5482. break;
  5483. case LPFC_PCI_DEV_OC:
  5484. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5485. phba->lpfc_sli_handle_slow_ring_event =
  5486. lpfc_sli_handle_slow_ring_event_s4;
  5487. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5488. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5489. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5490. break;
  5491. default:
  5492. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5493. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5494. dev_grp);
  5495. return -ENODEV;
  5496. break;
  5497. }
  5498. return 0;
  5499. }
  5500. /**
  5501. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5502. * @phba: Pointer to HBA context object.
  5503. * @pring: Pointer to driver SLI ring object.
  5504. * @piocb: Pointer to address of newly added command iocb.
  5505. *
  5506. * This function is called with hbalock held to add a command
  5507. * iocb to the txq when SLI layer cannot submit the command iocb
  5508. * to the ring.
  5509. **/
  5510. void
  5511. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5512. struct lpfc_iocbq *piocb)
  5513. {
  5514. /* Insert the caller's iocb in the txq tail for later processing. */
  5515. list_add_tail(&piocb->list, &pring->txq);
  5516. pring->txq_cnt++;
  5517. }
  5518. /**
  5519. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5520. * @phba: Pointer to HBA context object.
  5521. * @pring: Pointer to driver SLI ring object.
  5522. * @piocb: Pointer to address of newly added command iocb.
  5523. *
  5524. * This function is called with hbalock held before a new
  5525. * iocb is submitted to the firmware. This function checks
  5526. * txq to flush the iocbs in txq to Firmware before
  5527. * submitting new iocbs to the Firmware.
  5528. * If there are iocbs in the txq which need to be submitted
  5529. * to firmware, lpfc_sli_next_iocb returns the first element
  5530. * of the txq after dequeuing it from txq.
  5531. * If there is no iocb in the txq then the function will return
  5532. * *piocb and *piocb is set to NULL. Caller needs to check
  5533. * *piocb to find if there are more commands in the txq.
  5534. **/
  5535. static struct lpfc_iocbq *
  5536. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5537. struct lpfc_iocbq **piocb)
  5538. {
  5539. struct lpfc_iocbq * nextiocb;
  5540. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5541. if (!nextiocb) {
  5542. nextiocb = *piocb;
  5543. *piocb = NULL;
  5544. }
  5545. return nextiocb;
  5546. }
  5547. /**
  5548. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5549. * @phba: Pointer to HBA context object.
  5550. * @ring_number: SLI ring number to issue iocb on.
  5551. * @piocb: Pointer to command iocb.
  5552. * @flag: Flag indicating if this command can be put into txq.
  5553. *
  5554. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5555. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5556. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5557. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5558. * this function allows only iocbs for posting buffers. This function finds
  5559. * next available slot in the command ring and posts the command to the
  5560. * available slot and writes the port attention register to request HBA start
  5561. * processing new iocb. If there is no slot available in the ring and
  5562. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5563. * the function returns IOCB_BUSY.
  5564. *
  5565. * This function is called with hbalock held. The function will return success
  5566. * after it successfully submit the iocb to firmware or after adding to the
  5567. * txq.
  5568. **/
  5569. static int
  5570. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5571. struct lpfc_iocbq *piocb, uint32_t flag)
  5572. {
  5573. struct lpfc_iocbq *nextiocb;
  5574. IOCB_t *iocb;
  5575. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5576. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5577. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5578. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5579. lpfc_printf_log(phba, KERN_ERR,
  5580. LOG_SLI | LOG_VPORT,
  5581. "1807 IOCB x%x failed. No vport\n",
  5582. piocb->iocb.ulpCommand);
  5583. dump_stack();
  5584. return IOCB_ERROR;
  5585. }
  5586. /* If the PCI channel is in offline state, do not post iocbs. */
  5587. if (unlikely(pci_channel_offline(phba->pcidev)))
  5588. return IOCB_ERROR;
  5589. /* If HBA has a deferred error attention, fail the iocb. */
  5590. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5591. return IOCB_ERROR;
  5592. /*
  5593. * We should never get an IOCB if we are in a < LINK_DOWN state
  5594. */
  5595. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5596. return IOCB_ERROR;
  5597. /*
  5598. * Check to see if we are blocking IOCB processing because of a
  5599. * outstanding event.
  5600. */
  5601. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5602. goto iocb_busy;
  5603. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5604. /*
  5605. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5606. * can be issued if the link is not up.
  5607. */
  5608. switch (piocb->iocb.ulpCommand) {
  5609. case CMD_GEN_REQUEST64_CR:
  5610. case CMD_GEN_REQUEST64_CX:
  5611. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5612. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5613. FC_RCTL_DD_UNSOL_CMD) ||
  5614. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5615. MENLO_TRANSPORT_TYPE))
  5616. goto iocb_busy;
  5617. break;
  5618. case CMD_QUE_RING_BUF_CN:
  5619. case CMD_QUE_RING_BUF64_CN:
  5620. /*
  5621. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5622. * completion, iocb_cmpl MUST be 0.
  5623. */
  5624. if (piocb->iocb_cmpl)
  5625. piocb->iocb_cmpl = NULL;
  5626. /*FALLTHROUGH*/
  5627. case CMD_CREATE_XRI_CR:
  5628. case CMD_CLOSE_XRI_CN:
  5629. case CMD_CLOSE_XRI_CX:
  5630. break;
  5631. default:
  5632. goto iocb_busy;
  5633. }
  5634. /*
  5635. * For FCP commands, we must be in a state where we can process link
  5636. * attention events.
  5637. */
  5638. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5639. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5640. goto iocb_busy;
  5641. }
  5642. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5643. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5644. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5645. if (iocb)
  5646. lpfc_sli_update_ring(phba, pring);
  5647. else
  5648. lpfc_sli_update_full_ring(phba, pring);
  5649. if (!piocb)
  5650. return IOCB_SUCCESS;
  5651. goto out_busy;
  5652. iocb_busy:
  5653. pring->stats.iocb_cmd_delay++;
  5654. out_busy:
  5655. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5656. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5657. return IOCB_SUCCESS;
  5658. }
  5659. return IOCB_BUSY;
  5660. }
  5661. /**
  5662. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5663. * @phba: Pointer to HBA context object.
  5664. * @piocb: Pointer to command iocb.
  5665. * @sglq: Pointer to the scatter gather queue object.
  5666. *
  5667. * This routine converts the bpl or bde that is in the IOCB
  5668. * to a sgl list for the sli4 hardware. The physical address
  5669. * of the bpl/bde is converted back to a virtual address.
  5670. * If the IOCB contains a BPL then the list of BDE's is
  5671. * converted to sli4_sge's. If the IOCB contains a single
  5672. * BDE then it is converted to a single sli_sge.
  5673. * The IOCB is still in cpu endianess so the contents of
  5674. * the bpl can be used without byte swapping.
  5675. *
  5676. * Returns valid XRI = Success, NO_XRI = Failure.
  5677. **/
  5678. static uint16_t
  5679. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5680. struct lpfc_sglq *sglq)
  5681. {
  5682. uint16_t xritag = NO_XRI;
  5683. struct ulp_bde64 *bpl = NULL;
  5684. struct ulp_bde64 bde;
  5685. struct sli4_sge *sgl = NULL;
  5686. IOCB_t *icmd;
  5687. int numBdes = 0;
  5688. int i = 0;
  5689. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5690. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5691. if (!piocbq || !sglq)
  5692. return xritag;
  5693. sgl = (struct sli4_sge *)sglq->sgl;
  5694. icmd = &piocbq->iocb;
  5695. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5696. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5697. sizeof(struct ulp_bde64);
  5698. /* The addrHigh and addrLow fields within the IOCB
  5699. * have not been byteswapped yet so there is no
  5700. * need to swap them back.
  5701. */
  5702. bpl = (struct ulp_bde64 *)
  5703. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5704. if (!bpl)
  5705. return xritag;
  5706. for (i = 0; i < numBdes; i++) {
  5707. /* Should already be byte swapped. */
  5708. sgl->addr_hi = bpl->addrHigh;
  5709. sgl->addr_lo = bpl->addrLow;
  5710. if ((i+1) == numBdes)
  5711. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5712. else
  5713. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5714. /* swap the size field back to the cpu so we
  5715. * can assign it to the sgl.
  5716. */
  5717. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5718. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5719. /* The offsets in the sgl need to be accumulated
  5720. * separately for the request and reply lists.
  5721. * The request is always first, the reply follows.
  5722. */
  5723. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5724. /* add up the reply sg entries */
  5725. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5726. inbound++;
  5727. /* first inbound? reset the offset */
  5728. if (inbound == 1)
  5729. offset = 0;
  5730. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5731. offset += bde.tus.f.bdeSize;
  5732. }
  5733. sgl->word2 = cpu_to_le32(sgl->word2);
  5734. bpl++;
  5735. sgl++;
  5736. }
  5737. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5738. /* The addrHigh and addrLow fields of the BDE have not
  5739. * been byteswapped yet so they need to be swapped
  5740. * before putting them in the sgl.
  5741. */
  5742. sgl->addr_hi =
  5743. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5744. sgl->addr_lo =
  5745. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5746. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5747. sgl->word2 = cpu_to_le32(sgl->word2);
  5748. sgl->sge_len =
  5749. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5750. }
  5751. return sglq->sli4_xritag;
  5752. }
  5753. /**
  5754. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5755. * @phba: Pointer to HBA context object.
  5756. *
  5757. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5758. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5759. * held.
  5760. *
  5761. * Return: index into SLI4 fast-path FCP queue index.
  5762. **/
  5763. static uint32_t
  5764. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5765. {
  5766. ++phba->fcp_qidx;
  5767. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5768. phba->fcp_qidx = 0;
  5769. return phba->fcp_qidx;
  5770. }
  5771. /**
  5772. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5773. * @phba: Pointer to HBA context object.
  5774. * @piocb: Pointer to command iocb.
  5775. * @wqe: Pointer to the work queue entry.
  5776. *
  5777. * This routine converts the iocb command to its Work Queue Entry
  5778. * equivalent. The wqe pointer should not have any fields set when
  5779. * this routine is called because it will memcpy over them.
  5780. * This routine does not set the CQ_ID or the WQEC bits in the
  5781. * wqe.
  5782. *
  5783. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5784. **/
  5785. static int
  5786. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5787. union lpfc_wqe *wqe)
  5788. {
  5789. uint32_t xmit_len = 0, total_len = 0;
  5790. uint8_t ct = 0;
  5791. uint32_t fip;
  5792. uint32_t abort_tag;
  5793. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5794. uint8_t cmnd;
  5795. uint16_t xritag;
  5796. uint16_t abrt_iotag;
  5797. struct lpfc_iocbq *abrtiocbq;
  5798. struct ulp_bde64 *bpl = NULL;
  5799. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5800. int numBdes, i;
  5801. struct ulp_bde64 bde;
  5802. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5803. /* The fcp commands will set command type */
  5804. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5805. command_type = FCP_COMMAND;
  5806. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5807. command_type = ELS_COMMAND_FIP;
  5808. else
  5809. command_type = ELS_COMMAND_NON_FIP;
  5810. /* Some of the fields are in the right position already */
  5811. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5812. abort_tag = (uint32_t) iocbq->iotag;
  5813. xritag = iocbq->sli4_xritag;
  5814. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5815. /* words0-2 bpl convert bde */
  5816. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5817. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5818. sizeof(struct ulp_bde64);
  5819. bpl = (struct ulp_bde64 *)
  5820. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5821. if (!bpl)
  5822. return IOCB_ERROR;
  5823. /* Should already be byte swapped. */
  5824. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5825. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5826. /* swap the size field back to the cpu so we
  5827. * can assign it to the sgl.
  5828. */
  5829. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5830. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5831. total_len = 0;
  5832. for (i = 0; i < numBdes; i++) {
  5833. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5834. total_len += bde.tus.f.bdeSize;
  5835. }
  5836. } else
  5837. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5838. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5839. cmnd = iocbq->iocb.ulpCommand;
  5840. switch (iocbq->iocb.ulpCommand) {
  5841. case CMD_ELS_REQUEST64_CR:
  5842. if (!iocbq->iocb.ulpLe) {
  5843. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5844. "2007 Only Limited Edition cmd Format"
  5845. " supported 0x%x\n",
  5846. iocbq->iocb.ulpCommand);
  5847. return IOCB_ERROR;
  5848. }
  5849. wqe->els_req.payload_len = xmit_len;
  5850. /* Els_reguest64 has a TMO */
  5851. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5852. iocbq->iocb.ulpTimeout);
  5853. /* Need a VF for word 4 set the vf bit*/
  5854. bf_set(els_req64_vf, &wqe->els_req, 0);
  5855. /* And a VFID for word 12 */
  5856. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5857. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5858. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5859. iocbq->iocb.ulpContext);
  5860. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5861. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5862. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5863. if (command_type == ELS_COMMAND_FIP) {
  5864. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5865. >> LPFC_FIP_ELS_ID_SHIFT);
  5866. }
  5867. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5868. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5869. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5870. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5871. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5872. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5873. break;
  5874. case CMD_XMIT_SEQUENCE64_CX:
  5875. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5876. iocbq->iocb.un.ulpWord[3]);
  5877. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5878. iocbq->iocb.ulpContext);
  5879. /* The entire sequence is transmitted for this IOCB */
  5880. xmit_len = total_len;
  5881. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5882. case CMD_XMIT_SEQUENCE64_CR:
  5883. /* word3 iocb=io_tag32 wqe=reserved */
  5884. wqe->xmit_sequence.rsvd3 = 0;
  5885. /* word4 relative_offset memcpy */
  5886. /* word5 r_ctl/df_ctl memcpy */
  5887. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5888. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5889. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5890. LPFC_WQE_IOD_WRITE);
  5891. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5892. LPFC_WQE_LENLOC_WORD12);
  5893. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5894. wqe->xmit_sequence.xmit_len = xmit_len;
  5895. command_type = OTHER_COMMAND;
  5896. break;
  5897. case CMD_XMIT_BCAST64_CN:
  5898. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5899. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5900. /* word4 iocb=rsvd wqe=rsvd */
  5901. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5902. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5903. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5904. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5905. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5906. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5907. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5908. LPFC_WQE_LENLOC_WORD3);
  5909. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5910. break;
  5911. case CMD_FCP_IWRITE64_CR:
  5912. command_type = FCP_COMMAND_DATA_OUT;
  5913. /* word3 iocb=iotag wqe=payload_offset_len */
  5914. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5915. wqe->fcp_iwrite.payload_offset_len =
  5916. xmit_len + sizeof(struct fcp_rsp);
  5917. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5918. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5919. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5920. iocbq->iocb.ulpFCP2Rcvy);
  5921. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5922. /* Always open the exchange */
  5923. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5924. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5925. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5926. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5927. LPFC_WQE_LENLOC_WORD4);
  5928. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5929. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5930. break;
  5931. case CMD_FCP_IREAD64_CR:
  5932. /* word3 iocb=iotag wqe=payload_offset_len */
  5933. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5934. wqe->fcp_iread.payload_offset_len =
  5935. xmit_len + sizeof(struct fcp_rsp);
  5936. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5937. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5938. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5939. iocbq->iocb.ulpFCP2Rcvy);
  5940. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5941. /* Always open the exchange */
  5942. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5943. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5944. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5945. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5946. LPFC_WQE_LENLOC_WORD4);
  5947. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5948. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5949. break;
  5950. case CMD_FCP_ICMND64_CR:
  5951. /* word3 iocb=IO_TAG wqe=reserved */
  5952. wqe->fcp_icmd.rsrvd3 = 0;
  5953. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5954. /* Always open the exchange */
  5955. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5956. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5957. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5958. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5959. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5960. LPFC_WQE_LENLOC_NONE);
  5961. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5962. break;
  5963. case CMD_GEN_REQUEST64_CR:
  5964. /* For this command calculate the xmit length of the
  5965. * request bde.
  5966. */
  5967. xmit_len = 0;
  5968. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5969. sizeof(struct ulp_bde64);
  5970. for (i = 0; i < numBdes; i++) {
  5971. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5972. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5973. break;
  5974. xmit_len += bde.tus.f.bdeSize;
  5975. }
  5976. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5977. wqe->gen_req.request_payload_len = xmit_len;
  5978. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5979. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5980. /* word6 context tag copied in memcpy */
  5981. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5982. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5983. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5984. "2015 Invalid CT %x command 0x%x\n",
  5985. ct, iocbq->iocb.ulpCommand);
  5986. return IOCB_ERROR;
  5987. }
  5988. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5989. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5990. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5991. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5992. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5993. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5994. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5995. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5996. command_type = OTHER_COMMAND;
  5997. break;
  5998. case CMD_XMIT_ELS_RSP64_CX:
  5999. /* words0-2 BDE memcpy */
  6000. /* word3 iocb=iotag32 wqe=response_payload_len */
  6001. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  6002. /* word4 iocb=did wge=rsvd. */
  6003. wqe->xmit_els_rsp.rsvd4 = 0;
  6004. /* word5 iocb=rsvd wge=did */
  6005. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  6006. iocbq->iocb.un.elsreq64.remoteID);
  6007. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  6008. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6009. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  6010. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6011. iocbq->iocb.ulpContext);
  6012. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  6013. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  6014. iocbq->vport->vpi + phba->vpi_base);
  6015. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  6016. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  6017. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  6018. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  6019. LPFC_WQE_LENLOC_WORD3);
  6020. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  6021. command_type = OTHER_COMMAND;
  6022. break;
  6023. case CMD_CLOSE_XRI_CN:
  6024. case CMD_ABORT_XRI_CN:
  6025. case CMD_ABORT_XRI_CX:
  6026. /* words 0-2 memcpy should be 0 rserved */
  6027. /* port will send abts */
  6028. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  6029. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  6030. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  6031. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  6032. } else
  6033. fip = 0;
  6034. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  6035. /*
  6036. * The link is down, or the command was ELS_FIP
  6037. * so the fw does not need to send abts
  6038. * on the wire.
  6039. */
  6040. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  6041. else
  6042. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  6043. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  6044. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  6045. wqe->abort_cmd.rsrvd5 = 0;
  6046. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  6047. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  6048. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  6049. /*
  6050. * The abort handler will send us CMD_ABORT_XRI_CN or
  6051. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  6052. */
  6053. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  6054. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  6055. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  6056. LPFC_WQE_LENLOC_NONE);
  6057. cmnd = CMD_ABORT_XRI_CX;
  6058. command_type = OTHER_COMMAND;
  6059. xritag = 0;
  6060. break;
  6061. case CMD_XMIT_BLS_RSP64_CX:
  6062. /* As BLS ABTS RSP WQE is very different from other WQEs,
  6063. * we re-construct this WQE here based on information in
  6064. * iocbq from scratch.
  6065. */
  6066. memset(wqe, 0, sizeof(union lpfc_wqe));
  6067. /* OX_ID is invariable to who sent ABTS to CT exchange */
  6068. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  6069. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  6070. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  6071. LPFC_ABTS_UNSOL_INT) {
  6072. /* ABTS sent by initiator to CT exchange, the
  6073. * RX_ID field will be filled with the newly
  6074. * allocated responder XRI.
  6075. */
  6076. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6077. iocbq->sli4_xritag);
  6078. } else {
  6079. /* ABTS sent by responder to CT exchange, the
  6080. * RX_ID field will be filled with the responder
  6081. * RX_ID from ABTS.
  6082. */
  6083. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  6084. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  6085. }
  6086. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  6087. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  6088. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  6089. iocbq->iocb.ulpContext);
  6090. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  6091. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  6092. LPFC_WQE_LENLOC_NONE);
  6093. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  6094. command_type = OTHER_COMMAND;
  6095. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  6096. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  6097. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  6098. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  6099. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  6100. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  6101. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  6102. }
  6103. break;
  6104. case CMD_XRI_ABORTED_CX:
  6105. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  6106. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  6107. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  6108. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  6109. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  6110. default:
  6111. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6112. "2014 Invalid command 0x%x\n",
  6113. iocbq->iocb.ulpCommand);
  6114. return IOCB_ERROR;
  6115. break;
  6116. }
  6117. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  6118. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  6119. wqe->generic.wqe_com.abort_tag = abort_tag;
  6120. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  6121. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  6122. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  6123. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  6124. return 0;
  6125. }
  6126. /**
  6127. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  6128. * @phba: Pointer to HBA context object.
  6129. * @ring_number: SLI ring number to issue iocb on.
  6130. * @piocb: Pointer to command iocb.
  6131. * @flag: Flag indicating if this command can be put into txq.
  6132. *
  6133. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  6134. * an iocb command to an HBA with SLI-4 interface spec.
  6135. *
  6136. * This function is called with hbalock held. The function will return success
  6137. * after it successfully submit the iocb to firmware or after adding to the
  6138. * txq.
  6139. **/
  6140. static int
  6141. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  6142. struct lpfc_iocbq *piocb, uint32_t flag)
  6143. {
  6144. struct lpfc_sglq *sglq;
  6145. union lpfc_wqe wqe;
  6146. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6147. if (piocb->sli4_xritag == NO_XRI) {
  6148. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  6149. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
  6150. piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6151. sglq = NULL;
  6152. else {
  6153. if (pring->txq_cnt) {
  6154. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6155. __lpfc_sli_ringtx_put(phba,
  6156. pring, piocb);
  6157. return IOCB_SUCCESS;
  6158. } else {
  6159. return IOCB_BUSY;
  6160. }
  6161. } else {
  6162. sglq = __lpfc_sli_get_sglq(phba, piocb);
  6163. if (!sglq) {
  6164. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6165. __lpfc_sli_ringtx_put(phba,
  6166. pring,
  6167. piocb);
  6168. return IOCB_SUCCESS;
  6169. } else
  6170. return IOCB_BUSY;
  6171. }
  6172. }
  6173. }
  6174. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  6175. sglq = NULL; /* These IO's already have an XRI and
  6176. * a mapped sgl.
  6177. */
  6178. } else {
  6179. /* This is a continuation of a commandi,(CX) so this
  6180. * sglq is on the active list
  6181. */
  6182. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  6183. if (!sglq)
  6184. return IOCB_ERROR;
  6185. }
  6186. if (sglq) {
  6187. piocb->sli4_xritag = sglq->sli4_xritag;
  6188. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  6189. return IOCB_ERROR;
  6190. }
  6191. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  6192. return IOCB_ERROR;
  6193. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  6194. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  6195. /*
  6196. * For FCP command IOCB, get a new WQ index to distribute
  6197. * WQE across the WQsr. On the other hand, for abort IOCB,
  6198. * it carries the same WQ index to the original command
  6199. * IOCB.
  6200. */
  6201. if (piocb->iocb_flag & LPFC_IO_FCP)
  6202. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  6203. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  6204. &wqe))
  6205. return IOCB_ERROR;
  6206. } else {
  6207. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  6208. return IOCB_ERROR;
  6209. }
  6210. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  6211. return 0;
  6212. }
  6213. /**
  6214. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  6215. *
  6216. * This routine wraps the actual lockless version for issusing IOCB function
  6217. * pointer from the lpfc_hba struct.
  6218. *
  6219. * Return codes:
  6220. * IOCB_ERROR - Error
  6221. * IOCB_SUCCESS - Success
  6222. * IOCB_BUSY - Busy
  6223. **/
  6224. int
  6225. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6226. struct lpfc_iocbq *piocb, uint32_t flag)
  6227. {
  6228. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6229. }
  6230. /**
  6231. * lpfc_sli_api_table_setup - Set up sli api function jump table
  6232. * @phba: The hba struct for which this call is being executed.
  6233. * @dev_grp: The HBA PCI-Device group number.
  6234. *
  6235. * This routine sets up the SLI interface API function jump table in @phba
  6236. * struct.
  6237. * Returns: 0 - success, -ENODEV - failure.
  6238. **/
  6239. int
  6240. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6241. {
  6242. switch (dev_grp) {
  6243. case LPFC_PCI_DEV_LP:
  6244. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  6245. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  6246. break;
  6247. case LPFC_PCI_DEV_OC:
  6248. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  6249. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  6250. break;
  6251. default:
  6252. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6253. "1419 Invalid HBA PCI-device group: 0x%x\n",
  6254. dev_grp);
  6255. return -ENODEV;
  6256. break;
  6257. }
  6258. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  6259. return 0;
  6260. }
  6261. /**
  6262. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  6263. * @phba: Pointer to HBA context object.
  6264. * @pring: Pointer to driver SLI ring object.
  6265. * @piocb: Pointer to command iocb.
  6266. * @flag: Flag indicating if this command can be put into txq.
  6267. *
  6268. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  6269. * function. This function gets the hbalock and calls
  6270. * __lpfc_sli_issue_iocb function and will return the error returned
  6271. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  6272. * functions which do not hold hbalock.
  6273. **/
  6274. int
  6275. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  6276. struct lpfc_iocbq *piocb, uint32_t flag)
  6277. {
  6278. unsigned long iflags;
  6279. int rc;
  6280. spin_lock_irqsave(&phba->hbalock, iflags);
  6281. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  6282. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6283. return rc;
  6284. }
  6285. /**
  6286. * lpfc_extra_ring_setup - Extra ring setup function
  6287. * @phba: Pointer to HBA context object.
  6288. *
  6289. * This function is called while driver attaches with the
  6290. * HBA to setup the extra ring. The extra ring is used
  6291. * only when driver needs to support target mode functionality
  6292. * or IP over FC functionalities.
  6293. *
  6294. * This function is called with no lock held.
  6295. **/
  6296. static int
  6297. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  6298. {
  6299. struct lpfc_sli *psli;
  6300. struct lpfc_sli_ring *pring;
  6301. psli = &phba->sli;
  6302. /* Adjust cmd/rsp ring iocb entries more evenly */
  6303. /* Take some away from the FCP ring */
  6304. pring = &psli->ring[psli->fcp_ring];
  6305. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6306. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6307. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6308. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6309. /* and give them to the extra ring */
  6310. pring = &psli->ring[psli->extra_ring];
  6311. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6312. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6313. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6314. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6315. /* Setup default profile for this ring */
  6316. pring->iotag_max = 4096;
  6317. pring->num_mask = 1;
  6318. pring->prt[0].profile = 0; /* Mask 0 */
  6319. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  6320. pring->prt[0].type = phba->cfg_multi_ring_type;
  6321. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  6322. return 0;
  6323. }
  6324. /**
  6325. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  6326. * @phba: Pointer to HBA context object.
  6327. * @pring: Pointer to driver SLI ring object.
  6328. * @iocbq: Pointer to iocb object.
  6329. *
  6330. * This function is called by the slow ring event handler
  6331. * function when there is an ASYNC event iocb in the ring.
  6332. * This function is called with no lock held.
  6333. * Currently this function handles only temperature related
  6334. * ASYNC events. The function decodes the temperature sensor
  6335. * event message and posts events for the management applications.
  6336. **/
  6337. static void
  6338. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  6339. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  6340. {
  6341. IOCB_t *icmd;
  6342. uint16_t evt_code;
  6343. uint16_t temp;
  6344. struct temp_event temp_event_data;
  6345. struct Scsi_Host *shost;
  6346. uint32_t *iocb_w;
  6347. icmd = &iocbq->iocb;
  6348. evt_code = icmd->un.asyncstat.evt_code;
  6349. temp = icmd->ulpContext;
  6350. if ((evt_code != ASYNC_TEMP_WARN) &&
  6351. (evt_code != ASYNC_TEMP_SAFE)) {
  6352. iocb_w = (uint32_t *) icmd;
  6353. lpfc_printf_log(phba,
  6354. KERN_ERR,
  6355. LOG_SLI,
  6356. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  6357. " evt_code 0x%x\n"
  6358. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  6359. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  6360. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  6361. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  6362. pring->ringno,
  6363. icmd->un.asyncstat.evt_code,
  6364. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  6365. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  6366. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  6367. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  6368. return;
  6369. }
  6370. temp_event_data.data = (uint32_t)temp;
  6371. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  6372. if (evt_code == ASYNC_TEMP_WARN) {
  6373. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  6374. lpfc_printf_log(phba,
  6375. KERN_ERR,
  6376. LOG_TEMP,
  6377. "0347 Adapter is very hot, please take "
  6378. "corrective action. temperature : %d Celsius\n",
  6379. temp);
  6380. }
  6381. if (evt_code == ASYNC_TEMP_SAFE) {
  6382. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  6383. lpfc_printf_log(phba,
  6384. KERN_ERR,
  6385. LOG_TEMP,
  6386. "0340 Adapter temperature is OK now. "
  6387. "temperature : %d Celsius\n",
  6388. temp);
  6389. }
  6390. /* Send temperature change event to applications */
  6391. shost = lpfc_shost_from_vport(phba->pport);
  6392. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6393. sizeof(temp_event_data), (char *) &temp_event_data,
  6394. LPFC_NL_VENDOR_ID);
  6395. }
  6396. /**
  6397. * lpfc_sli_setup - SLI ring setup function
  6398. * @phba: Pointer to HBA context object.
  6399. *
  6400. * lpfc_sli_setup sets up rings of the SLI interface with
  6401. * number of iocbs per ring and iotags. This function is
  6402. * called while driver attach to the HBA and before the
  6403. * interrupts are enabled. So there is no need for locking.
  6404. *
  6405. * This function always returns 0.
  6406. **/
  6407. int
  6408. lpfc_sli_setup(struct lpfc_hba *phba)
  6409. {
  6410. int i, totiocbsize = 0;
  6411. struct lpfc_sli *psli = &phba->sli;
  6412. struct lpfc_sli_ring *pring;
  6413. psli->num_rings = MAX_CONFIGURED_RINGS;
  6414. psli->sli_flag = 0;
  6415. psli->fcp_ring = LPFC_FCP_RING;
  6416. psli->next_ring = LPFC_FCP_NEXT_RING;
  6417. psli->extra_ring = LPFC_EXTRA_RING;
  6418. psli->iocbq_lookup = NULL;
  6419. psli->iocbq_lookup_len = 0;
  6420. psli->last_iotag = 0;
  6421. for (i = 0; i < psli->num_rings; i++) {
  6422. pring = &psli->ring[i];
  6423. switch (i) {
  6424. case LPFC_FCP_RING: /* ring 0 - FCP */
  6425. /* numCiocb and numRiocb are used in config_port */
  6426. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6427. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6428. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6429. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6430. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6431. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6432. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6433. SLI3_IOCB_CMD_SIZE :
  6434. SLI2_IOCB_CMD_SIZE;
  6435. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6436. SLI3_IOCB_RSP_SIZE :
  6437. SLI2_IOCB_RSP_SIZE;
  6438. pring->iotag_ctr = 0;
  6439. pring->iotag_max =
  6440. (phba->cfg_hba_queue_depth * 2);
  6441. pring->fast_iotag = pring->iotag_max;
  6442. pring->num_mask = 0;
  6443. break;
  6444. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6445. /* numCiocb and numRiocb are used in config_port */
  6446. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6447. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6448. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6449. SLI3_IOCB_CMD_SIZE :
  6450. SLI2_IOCB_CMD_SIZE;
  6451. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6452. SLI3_IOCB_RSP_SIZE :
  6453. SLI2_IOCB_RSP_SIZE;
  6454. pring->iotag_max = phba->cfg_hba_queue_depth;
  6455. pring->num_mask = 0;
  6456. break;
  6457. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6458. /* numCiocb and numRiocb are used in config_port */
  6459. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6460. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6461. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6462. SLI3_IOCB_CMD_SIZE :
  6463. SLI2_IOCB_CMD_SIZE;
  6464. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6465. SLI3_IOCB_RSP_SIZE :
  6466. SLI2_IOCB_RSP_SIZE;
  6467. pring->fast_iotag = 0;
  6468. pring->iotag_ctr = 0;
  6469. pring->iotag_max = 4096;
  6470. pring->lpfc_sli_rcv_async_status =
  6471. lpfc_sli_async_event_handler;
  6472. pring->num_mask = LPFC_MAX_RING_MASK;
  6473. pring->prt[0].profile = 0; /* Mask 0 */
  6474. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6475. pring->prt[0].type = FC_TYPE_ELS;
  6476. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6477. lpfc_els_unsol_event;
  6478. pring->prt[1].profile = 0; /* Mask 1 */
  6479. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6480. pring->prt[1].type = FC_TYPE_ELS;
  6481. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6482. lpfc_els_unsol_event;
  6483. pring->prt[2].profile = 0; /* Mask 2 */
  6484. /* NameServer Inquiry */
  6485. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6486. /* NameServer */
  6487. pring->prt[2].type = FC_TYPE_CT;
  6488. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6489. lpfc_ct_unsol_event;
  6490. pring->prt[3].profile = 0; /* Mask 3 */
  6491. /* NameServer response */
  6492. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6493. /* NameServer */
  6494. pring->prt[3].type = FC_TYPE_CT;
  6495. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6496. lpfc_ct_unsol_event;
  6497. /* abort unsolicited sequence */
  6498. pring->prt[4].profile = 0; /* Mask 4 */
  6499. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6500. pring->prt[4].type = FC_TYPE_BLS;
  6501. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6502. lpfc_sli4_ct_abort_unsol_event;
  6503. break;
  6504. }
  6505. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6506. (pring->numRiocb * pring->sizeRiocb);
  6507. }
  6508. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6509. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6510. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6511. "SLI2 SLIM Data: x%x x%lx\n",
  6512. phba->brd_no, totiocbsize,
  6513. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6514. }
  6515. if (phba->cfg_multi_ring_support == 2)
  6516. lpfc_extra_ring_setup(phba);
  6517. return 0;
  6518. }
  6519. /**
  6520. * lpfc_sli_queue_setup - Queue initialization function
  6521. * @phba: Pointer to HBA context object.
  6522. *
  6523. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6524. * ring. This function also initializes ring indices of each ring.
  6525. * This function is called during the initialization of the SLI
  6526. * interface of an HBA.
  6527. * This function is called with no lock held and always returns
  6528. * 1.
  6529. **/
  6530. int
  6531. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6532. {
  6533. struct lpfc_sli *psli;
  6534. struct lpfc_sli_ring *pring;
  6535. int i;
  6536. psli = &phba->sli;
  6537. spin_lock_irq(&phba->hbalock);
  6538. INIT_LIST_HEAD(&psli->mboxq);
  6539. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6540. /* Initialize list headers for txq and txcmplq as double linked lists */
  6541. for (i = 0; i < psli->num_rings; i++) {
  6542. pring = &psli->ring[i];
  6543. pring->ringno = i;
  6544. pring->next_cmdidx = 0;
  6545. pring->local_getidx = 0;
  6546. pring->cmdidx = 0;
  6547. INIT_LIST_HEAD(&pring->txq);
  6548. INIT_LIST_HEAD(&pring->txcmplq);
  6549. INIT_LIST_HEAD(&pring->iocb_continueq);
  6550. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6551. INIT_LIST_HEAD(&pring->postbufq);
  6552. }
  6553. spin_unlock_irq(&phba->hbalock);
  6554. return 1;
  6555. }
  6556. /**
  6557. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6558. * @phba: Pointer to HBA context object.
  6559. *
  6560. * This routine flushes the mailbox command subsystem. It will unconditionally
  6561. * flush all the mailbox commands in the three possible stages in the mailbox
  6562. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6563. * command; and completed mailbox command queue. It is caller's responsibility
  6564. * to make sure that the driver is in the proper state to flush the mailbox
  6565. * command sub-system. Namely, the posting of mailbox commands into the
  6566. * pending mailbox command queue from the various clients must be stopped;
  6567. * either the HBA is in a state that it will never works on the outstanding
  6568. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6569. * mailbox command has been completed.
  6570. **/
  6571. static void
  6572. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6573. {
  6574. LIST_HEAD(completions);
  6575. struct lpfc_sli *psli = &phba->sli;
  6576. LPFC_MBOXQ_t *pmb;
  6577. unsigned long iflag;
  6578. /* Flush all the mailbox commands in the mbox system */
  6579. spin_lock_irqsave(&phba->hbalock, iflag);
  6580. /* The pending mailbox command queue */
  6581. list_splice_init(&phba->sli.mboxq, &completions);
  6582. /* The outstanding active mailbox command */
  6583. if (psli->mbox_active) {
  6584. list_add_tail(&psli->mbox_active->list, &completions);
  6585. psli->mbox_active = NULL;
  6586. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6587. }
  6588. /* The completed mailbox command queue */
  6589. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6590. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6591. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6592. while (!list_empty(&completions)) {
  6593. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6594. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6595. if (pmb->mbox_cmpl)
  6596. pmb->mbox_cmpl(phba, pmb);
  6597. }
  6598. }
  6599. /**
  6600. * lpfc_sli_host_down - Vport cleanup function
  6601. * @vport: Pointer to virtual port object.
  6602. *
  6603. * lpfc_sli_host_down is called to clean up the resources
  6604. * associated with a vport before destroying virtual
  6605. * port data structures.
  6606. * This function does following operations:
  6607. * - Free discovery resources associated with this virtual
  6608. * port.
  6609. * - Free iocbs associated with this virtual port in
  6610. * the txq.
  6611. * - Send abort for all iocb commands associated with this
  6612. * vport in txcmplq.
  6613. *
  6614. * This function is called with no lock held and always returns 1.
  6615. **/
  6616. int
  6617. lpfc_sli_host_down(struct lpfc_vport *vport)
  6618. {
  6619. LIST_HEAD(completions);
  6620. struct lpfc_hba *phba = vport->phba;
  6621. struct lpfc_sli *psli = &phba->sli;
  6622. struct lpfc_sli_ring *pring;
  6623. struct lpfc_iocbq *iocb, *next_iocb;
  6624. int i;
  6625. unsigned long flags = 0;
  6626. uint16_t prev_pring_flag;
  6627. lpfc_cleanup_discovery_resources(vport);
  6628. spin_lock_irqsave(&phba->hbalock, flags);
  6629. for (i = 0; i < psli->num_rings; i++) {
  6630. pring = &psli->ring[i];
  6631. prev_pring_flag = pring->flag;
  6632. /* Only slow rings */
  6633. if (pring->ringno == LPFC_ELS_RING) {
  6634. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6635. /* Set the lpfc data pending flag */
  6636. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6637. }
  6638. /*
  6639. * Error everything on the txq since these iocbs have not been
  6640. * given to the FW yet.
  6641. */
  6642. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6643. if (iocb->vport != vport)
  6644. continue;
  6645. list_move_tail(&iocb->list, &completions);
  6646. pring->txq_cnt--;
  6647. }
  6648. /* Next issue ABTS for everything on the txcmplq */
  6649. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6650. list) {
  6651. if (iocb->vport != vport)
  6652. continue;
  6653. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6654. }
  6655. pring->flag = prev_pring_flag;
  6656. }
  6657. spin_unlock_irqrestore(&phba->hbalock, flags);
  6658. /* Cancel all the IOCBs from the completions list */
  6659. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6660. IOERR_SLI_DOWN);
  6661. return 1;
  6662. }
  6663. /**
  6664. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6665. * @phba: Pointer to HBA context object.
  6666. *
  6667. * This function cleans up all iocb, buffers, mailbox commands
  6668. * while shutting down the HBA. This function is called with no
  6669. * lock held and always returns 1.
  6670. * This function does the following to cleanup driver resources:
  6671. * - Free discovery resources for each virtual port
  6672. * - Cleanup any pending fabric iocbs
  6673. * - Iterate through the iocb txq and free each entry
  6674. * in the list.
  6675. * - Free up any buffer posted to the HBA
  6676. * - Free mailbox commands in the mailbox queue.
  6677. **/
  6678. int
  6679. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6680. {
  6681. LIST_HEAD(completions);
  6682. struct lpfc_sli *psli = &phba->sli;
  6683. struct lpfc_sli_ring *pring;
  6684. struct lpfc_dmabuf *buf_ptr;
  6685. unsigned long flags = 0;
  6686. int i;
  6687. /* Shutdown the mailbox command sub-system */
  6688. lpfc_sli_mbox_sys_shutdown(phba);
  6689. lpfc_hba_down_prep(phba);
  6690. lpfc_fabric_abort_hba(phba);
  6691. spin_lock_irqsave(&phba->hbalock, flags);
  6692. for (i = 0; i < psli->num_rings; i++) {
  6693. pring = &psli->ring[i];
  6694. /* Only slow rings */
  6695. if (pring->ringno == LPFC_ELS_RING) {
  6696. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6697. /* Set the lpfc data pending flag */
  6698. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6699. }
  6700. /*
  6701. * Error everything on the txq since these iocbs have not been
  6702. * given to the FW yet.
  6703. */
  6704. list_splice_init(&pring->txq, &completions);
  6705. pring->txq_cnt = 0;
  6706. }
  6707. spin_unlock_irqrestore(&phba->hbalock, flags);
  6708. /* Cancel all the IOCBs from the completions list */
  6709. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6710. IOERR_SLI_DOWN);
  6711. spin_lock_irqsave(&phba->hbalock, flags);
  6712. list_splice_init(&phba->elsbuf, &completions);
  6713. phba->elsbuf_cnt = 0;
  6714. phba->elsbuf_prev_cnt = 0;
  6715. spin_unlock_irqrestore(&phba->hbalock, flags);
  6716. while (!list_empty(&completions)) {
  6717. list_remove_head(&completions, buf_ptr,
  6718. struct lpfc_dmabuf, list);
  6719. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6720. kfree(buf_ptr);
  6721. }
  6722. /* Return any active mbox cmds */
  6723. del_timer_sync(&psli->mbox_tmo);
  6724. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6725. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6726. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6727. return 1;
  6728. }
  6729. /**
  6730. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6731. * @srcp: Source memory pointer.
  6732. * @destp: Destination memory pointer.
  6733. * @cnt: Number of words required to be copied.
  6734. *
  6735. * This function is used for copying data between driver memory
  6736. * and the SLI memory. This function also changes the endianness
  6737. * of each word if native endianness is different from SLI
  6738. * endianness. This function can be called with or without
  6739. * lock.
  6740. **/
  6741. void
  6742. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6743. {
  6744. uint32_t *src = srcp;
  6745. uint32_t *dest = destp;
  6746. uint32_t ldata;
  6747. int i;
  6748. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6749. ldata = *src;
  6750. ldata = le32_to_cpu(ldata);
  6751. *dest = ldata;
  6752. src++;
  6753. dest++;
  6754. }
  6755. }
  6756. /**
  6757. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6758. * @srcp: Source memory pointer.
  6759. * @destp: Destination memory pointer.
  6760. * @cnt: Number of words required to be copied.
  6761. *
  6762. * This function is used for copying data between a data structure
  6763. * with big endian representation to local endianness.
  6764. * This function can be called with or without lock.
  6765. **/
  6766. void
  6767. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6768. {
  6769. uint32_t *src = srcp;
  6770. uint32_t *dest = destp;
  6771. uint32_t ldata;
  6772. int i;
  6773. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6774. ldata = *src;
  6775. ldata = be32_to_cpu(ldata);
  6776. *dest = ldata;
  6777. src++;
  6778. dest++;
  6779. }
  6780. }
  6781. /**
  6782. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6783. * @phba: Pointer to HBA context object.
  6784. * @pring: Pointer to driver SLI ring object.
  6785. * @mp: Pointer to driver buffer object.
  6786. *
  6787. * This function is called with no lock held.
  6788. * It always return zero after adding the buffer to the postbufq
  6789. * buffer list.
  6790. **/
  6791. int
  6792. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6793. struct lpfc_dmabuf *mp)
  6794. {
  6795. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6796. later */
  6797. spin_lock_irq(&phba->hbalock);
  6798. list_add_tail(&mp->list, &pring->postbufq);
  6799. pring->postbufq_cnt++;
  6800. spin_unlock_irq(&phba->hbalock);
  6801. return 0;
  6802. }
  6803. /**
  6804. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6805. * @phba: Pointer to HBA context object.
  6806. *
  6807. * When HBQ is enabled, buffers are searched based on tags. This function
  6808. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6809. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6810. * does not conflict with tags of buffer posted for unsolicited events.
  6811. * The function returns the allocated tag. The function is called with
  6812. * no locks held.
  6813. **/
  6814. uint32_t
  6815. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6816. {
  6817. spin_lock_irq(&phba->hbalock);
  6818. phba->buffer_tag_count++;
  6819. /*
  6820. * Always set the QUE_BUFTAG_BIT to distiguish between
  6821. * a tag assigned by HBQ.
  6822. */
  6823. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6824. spin_unlock_irq(&phba->hbalock);
  6825. return phba->buffer_tag_count;
  6826. }
  6827. /**
  6828. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6829. * @phba: Pointer to HBA context object.
  6830. * @pring: Pointer to driver SLI ring object.
  6831. * @tag: Buffer tag.
  6832. *
  6833. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6834. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6835. * iocb is posted to the response ring with the tag of the buffer.
  6836. * This function searches the pring->postbufq list using the tag
  6837. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6838. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6839. * buffer is returned to the caller else NULL is returned.
  6840. * This function is called with no lock held.
  6841. **/
  6842. struct lpfc_dmabuf *
  6843. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6844. uint32_t tag)
  6845. {
  6846. struct lpfc_dmabuf *mp, *next_mp;
  6847. struct list_head *slp = &pring->postbufq;
  6848. /* Search postbufq, from the beginning, looking for a match on tag */
  6849. spin_lock_irq(&phba->hbalock);
  6850. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6851. if (mp->buffer_tag == tag) {
  6852. list_del_init(&mp->list);
  6853. pring->postbufq_cnt--;
  6854. spin_unlock_irq(&phba->hbalock);
  6855. return mp;
  6856. }
  6857. }
  6858. spin_unlock_irq(&phba->hbalock);
  6859. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6860. "0402 Cannot find virtual addr for buffer tag on "
  6861. "ring %d Data x%lx x%p x%p x%x\n",
  6862. pring->ringno, (unsigned long) tag,
  6863. slp->next, slp->prev, pring->postbufq_cnt);
  6864. return NULL;
  6865. }
  6866. /**
  6867. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6868. * @phba: Pointer to HBA context object.
  6869. * @pring: Pointer to driver SLI ring object.
  6870. * @phys: DMA address of the buffer.
  6871. *
  6872. * This function searches the buffer list using the dma_address
  6873. * of unsolicited event to find the driver's lpfc_dmabuf object
  6874. * corresponding to the dma_address. The function returns the
  6875. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6876. * This function is called by the ct and els unsolicited event
  6877. * handlers to get the buffer associated with the unsolicited
  6878. * event.
  6879. *
  6880. * This function is called with no lock held.
  6881. **/
  6882. struct lpfc_dmabuf *
  6883. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6884. dma_addr_t phys)
  6885. {
  6886. struct lpfc_dmabuf *mp, *next_mp;
  6887. struct list_head *slp = &pring->postbufq;
  6888. /* Search postbufq, from the beginning, looking for a match on phys */
  6889. spin_lock_irq(&phba->hbalock);
  6890. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6891. if (mp->phys == phys) {
  6892. list_del_init(&mp->list);
  6893. pring->postbufq_cnt--;
  6894. spin_unlock_irq(&phba->hbalock);
  6895. return mp;
  6896. }
  6897. }
  6898. spin_unlock_irq(&phba->hbalock);
  6899. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6900. "0410 Cannot find virtual addr for mapped buf on "
  6901. "ring %d Data x%llx x%p x%p x%x\n",
  6902. pring->ringno, (unsigned long long)phys,
  6903. slp->next, slp->prev, pring->postbufq_cnt);
  6904. return NULL;
  6905. }
  6906. /**
  6907. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6908. * @phba: Pointer to HBA context object.
  6909. * @cmdiocb: Pointer to driver command iocb object.
  6910. * @rspiocb: Pointer to driver response iocb object.
  6911. *
  6912. * This function is the completion handler for the abort iocbs for
  6913. * ELS commands. This function is called from the ELS ring event
  6914. * handler with no lock held. This function frees memory resources
  6915. * associated with the abort iocb.
  6916. **/
  6917. static void
  6918. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6919. struct lpfc_iocbq *rspiocb)
  6920. {
  6921. IOCB_t *irsp = &rspiocb->iocb;
  6922. uint16_t abort_iotag, abort_context;
  6923. struct lpfc_iocbq *abort_iocb;
  6924. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6925. abort_iocb = NULL;
  6926. if (irsp->ulpStatus) {
  6927. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6928. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6929. spin_lock_irq(&phba->hbalock);
  6930. if (phba->sli_rev < LPFC_SLI_REV4) {
  6931. if (abort_iotag != 0 &&
  6932. abort_iotag <= phba->sli.last_iotag)
  6933. abort_iocb =
  6934. phba->sli.iocbq_lookup[abort_iotag];
  6935. } else
  6936. /* For sli4 the abort_tag is the XRI,
  6937. * so the abort routine puts the iotag of the iocb
  6938. * being aborted in the context field of the abort
  6939. * IOCB.
  6940. */
  6941. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6942. /*
  6943. * If the iocb is not found in Firmware queue the iocb
  6944. * might have completed already. Do not free it again.
  6945. */
  6946. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6947. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6948. spin_unlock_irq(&phba->hbalock);
  6949. lpfc_sli_release_iocbq(phba, cmdiocb);
  6950. return;
  6951. }
  6952. /* For SLI4 the ulpContext field for abort IOCB
  6953. * holds the iotag of the IOCB being aborted so
  6954. * the local abort_context needs to be reset to
  6955. * match the aborted IOCBs ulpContext.
  6956. */
  6957. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6958. abort_context = abort_iocb->iocb.ulpContext;
  6959. }
  6960. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6961. "0327 Cannot abort els iocb %p "
  6962. "with tag %x context %x, abort status %x, "
  6963. "abort code %x\n",
  6964. abort_iocb, abort_iotag, abort_context,
  6965. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6966. /*
  6967. * make sure we have the right iocbq before taking it
  6968. * off the txcmplq and try to call completion routine.
  6969. */
  6970. if (!abort_iocb ||
  6971. abort_iocb->iocb.ulpContext != abort_context ||
  6972. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6973. spin_unlock_irq(&phba->hbalock);
  6974. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6975. /*
  6976. * leave the SLI4 aborted command on the txcmplq
  6977. * list and the command complete WCQE's XB bit
  6978. * will tell whether the SGL (XRI) can be released
  6979. * immediately or to the aborted SGL list for the
  6980. * following abort XRI from the HBA.
  6981. */
  6982. list_del_init(&abort_iocb->list);
  6983. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6984. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6985. pring->txcmplq_cnt--;
  6986. }
  6987. /* Firmware could still be in progress of DMAing
  6988. * payload, so don't free data buffer till after
  6989. * a hbeat.
  6990. */
  6991. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6992. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6993. spin_unlock_irq(&phba->hbalock);
  6994. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6995. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6996. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6997. } else
  6998. spin_unlock_irq(&phba->hbalock);
  6999. }
  7000. lpfc_sli_release_iocbq(phba, cmdiocb);
  7001. return;
  7002. }
  7003. /**
  7004. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  7005. * @phba: Pointer to HBA context object.
  7006. * @cmdiocb: Pointer to driver command iocb object.
  7007. * @rspiocb: Pointer to driver response iocb object.
  7008. *
  7009. * The function is called from SLI ring event handler with no
  7010. * lock held. This function is the completion handler for ELS commands
  7011. * which are aborted. The function frees memory resources used for
  7012. * the aborted ELS commands.
  7013. **/
  7014. static void
  7015. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7016. struct lpfc_iocbq *rspiocb)
  7017. {
  7018. IOCB_t *irsp = &rspiocb->iocb;
  7019. /* ELS cmd tag <ulpIoTag> completes */
  7020. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  7021. "0139 Ignoring ELS cmd tag x%x completion Data: "
  7022. "x%x x%x x%x\n",
  7023. irsp->ulpIoTag, irsp->ulpStatus,
  7024. irsp->un.ulpWord[4], irsp->ulpTimeout);
  7025. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  7026. lpfc_ct_free_iocb(phba, cmdiocb);
  7027. else
  7028. lpfc_els_free_iocb(phba, cmdiocb);
  7029. return;
  7030. }
  7031. /**
  7032. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  7033. * @phba: Pointer to HBA context object.
  7034. * @pring: Pointer to driver SLI ring object.
  7035. * @cmdiocb: Pointer to driver command iocb object.
  7036. *
  7037. * This function issues an abort iocb for the provided command iocb down to
  7038. * the port. Other than the case the outstanding command iocb is an abort
  7039. * request, this function issues abort out unconditionally. This function is
  7040. * called with hbalock held. The function returns 0 when it fails due to
  7041. * memory allocation failure or when the command iocb is an abort request.
  7042. **/
  7043. static int
  7044. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7045. struct lpfc_iocbq *cmdiocb)
  7046. {
  7047. struct lpfc_vport *vport = cmdiocb->vport;
  7048. struct lpfc_iocbq *abtsiocbp;
  7049. IOCB_t *icmd = NULL;
  7050. IOCB_t *iabt = NULL;
  7051. int retval;
  7052. /*
  7053. * There are certain command types we don't want to abort. And we
  7054. * don't want to abort commands that are already in the process of
  7055. * being aborted.
  7056. */
  7057. icmd = &cmdiocb->iocb;
  7058. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7059. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7060. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7061. return 0;
  7062. /* issue ABTS for this IOCB based on iotag */
  7063. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  7064. if (abtsiocbp == NULL)
  7065. return 0;
  7066. /* This signals the response to set the correct status
  7067. * before calling the completion handler
  7068. */
  7069. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  7070. iabt = &abtsiocbp->iocb;
  7071. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  7072. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  7073. if (phba->sli_rev == LPFC_SLI_REV4) {
  7074. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  7075. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  7076. }
  7077. else
  7078. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  7079. iabt->ulpLe = 1;
  7080. iabt->ulpClass = icmd->ulpClass;
  7081. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7082. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  7083. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  7084. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  7085. if (phba->link_state >= LPFC_LINK_UP)
  7086. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  7087. else
  7088. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  7089. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  7090. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  7091. "0339 Abort xri x%x, original iotag x%x, "
  7092. "abort cmd iotag x%x\n",
  7093. iabt->un.acxri.abortIoTag,
  7094. iabt->un.acxri.abortContextTag,
  7095. abtsiocbp->iotag);
  7096. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  7097. if (retval)
  7098. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  7099. /*
  7100. * Caller to this routine should check for IOCB_ERROR
  7101. * and handle it properly. This routine no longer removes
  7102. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7103. */
  7104. return retval;
  7105. }
  7106. /**
  7107. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  7108. * @phba: Pointer to HBA context object.
  7109. * @pring: Pointer to driver SLI ring object.
  7110. * @cmdiocb: Pointer to driver command iocb object.
  7111. *
  7112. * This function issues an abort iocb for the provided command iocb. In case
  7113. * of unloading, the abort iocb will not be issued to commands on the ELS
  7114. * ring. Instead, the callback function shall be changed to those commands
  7115. * so that nothing happens when them finishes. This function is called with
  7116. * hbalock held. The function returns 0 when the command iocb is an abort
  7117. * request.
  7118. **/
  7119. int
  7120. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7121. struct lpfc_iocbq *cmdiocb)
  7122. {
  7123. struct lpfc_vport *vport = cmdiocb->vport;
  7124. int retval = IOCB_ERROR;
  7125. IOCB_t *icmd = NULL;
  7126. /*
  7127. * There are certain command types we don't want to abort. And we
  7128. * don't want to abort commands that are already in the process of
  7129. * being aborted.
  7130. */
  7131. icmd = &cmdiocb->iocb;
  7132. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  7133. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  7134. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  7135. return 0;
  7136. /*
  7137. * If we're unloading, don't abort iocb on the ELS ring, but change
  7138. * the callback so that nothing happens when it finishes.
  7139. */
  7140. if ((vport->load_flag & FC_UNLOADING) &&
  7141. (pring->ringno == LPFC_ELS_RING)) {
  7142. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  7143. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  7144. else
  7145. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  7146. goto abort_iotag_exit;
  7147. }
  7148. /* Now, we try to issue the abort to the cmdiocb out */
  7149. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  7150. abort_iotag_exit:
  7151. /*
  7152. * Caller to this routine should check for IOCB_ERROR
  7153. * and handle it properly. This routine no longer removes
  7154. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  7155. */
  7156. return retval;
  7157. }
  7158. /**
  7159. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  7160. * @phba: Pointer to HBA context object.
  7161. * @pring: Pointer to driver SLI ring object.
  7162. *
  7163. * This function aborts all iocbs in the given ring and frees all the iocb
  7164. * objects in txq. This function issues abort iocbs unconditionally for all
  7165. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  7166. * to complete before the return of this function. The caller is not required
  7167. * to hold any locks.
  7168. **/
  7169. static void
  7170. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  7171. {
  7172. LIST_HEAD(completions);
  7173. struct lpfc_iocbq *iocb, *next_iocb;
  7174. if (pring->ringno == LPFC_ELS_RING)
  7175. lpfc_fabric_abort_hba(phba);
  7176. spin_lock_irq(&phba->hbalock);
  7177. /* Take off all the iocbs on txq for cancelling */
  7178. list_splice_init(&pring->txq, &completions);
  7179. pring->txq_cnt = 0;
  7180. /* Next issue ABTS for everything on the txcmplq */
  7181. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  7182. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  7183. spin_unlock_irq(&phba->hbalock);
  7184. /* Cancel all the IOCBs from the completions list */
  7185. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7186. IOERR_SLI_ABORTED);
  7187. }
  7188. /**
  7189. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  7190. * @phba: pointer to lpfc HBA data structure.
  7191. *
  7192. * This routine will abort all pending and outstanding iocbs to an HBA.
  7193. **/
  7194. void
  7195. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  7196. {
  7197. struct lpfc_sli *psli = &phba->sli;
  7198. struct lpfc_sli_ring *pring;
  7199. int i;
  7200. for (i = 0; i < psli->num_rings; i++) {
  7201. pring = &psli->ring[i];
  7202. lpfc_sli_iocb_ring_abort(phba, pring);
  7203. }
  7204. }
  7205. /**
  7206. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  7207. * @iocbq: Pointer to driver iocb object.
  7208. * @vport: Pointer to driver virtual port object.
  7209. * @tgt_id: SCSI ID of the target.
  7210. * @lun_id: LUN ID of the scsi device.
  7211. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  7212. *
  7213. * This function acts as an iocb filter for functions which abort or count
  7214. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  7215. * 0 if the filtering criteria is met for the given iocb and will return
  7216. * 1 if the filtering criteria is not met.
  7217. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  7218. * given iocb is for the SCSI device specified by vport, tgt_id and
  7219. * lun_id parameter.
  7220. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  7221. * given iocb is for the SCSI target specified by vport and tgt_id
  7222. * parameters.
  7223. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  7224. * given iocb is for the SCSI host associated with the given vport.
  7225. * This function is called with no locks held.
  7226. **/
  7227. static int
  7228. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  7229. uint16_t tgt_id, uint64_t lun_id,
  7230. lpfc_ctx_cmd ctx_cmd)
  7231. {
  7232. struct lpfc_scsi_buf *lpfc_cmd;
  7233. int rc = 1;
  7234. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  7235. return rc;
  7236. if (iocbq->vport != vport)
  7237. return rc;
  7238. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  7239. if (lpfc_cmd->pCmd == NULL)
  7240. return rc;
  7241. switch (ctx_cmd) {
  7242. case LPFC_CTX_LUN:
  7243. if ((lpfc_cmd->rdata->pnode) &&
  7244. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  7245. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  7246. rc = 0;
  7247. break;
  7248. case LPFC_CTX_TGT:
  7249. if ((lpfc_cmd->rdata->pnode) &&
  7250. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  7251. rc = 0;
  7252. break;
  7253. case LPFC_CTX_HOST:
  7254. rc = 0;
  7255. break;
  7256. default:
  7257. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  7258. __func__, ctx_cmd);
  7259. break;
  7260. }
  7261. return rc;
  7262. }
  7263. /**
  7264. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  7265. * @vport: Pointer to virtual port.
  7266. * @tgt_id: SCSI ID of the target.
  7267. * @lun_id: LUN ID of the scsi device.
  7268. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7269. *
  7270. * This function returns number of FCP commands pending for the vport.
  7271. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  7272. * commands pending on the vport associated with SCSI device specified
  7273. * by tgt_id and lun_id parameters.
  7274. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  7275. * commands pending on the vport associated with SCSI target specified
  7276. * by tgt_id parameter.
  7277. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  7278. * commands pending on the vport.
  7279. * This function returns the number of iocbs which satisfy the filter.
  7280. * This function is called without any lock held.
  7281. **/
  7282. int
  7283. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  7284. lpfc_ctx_cmd ctx_cmd)
  7285. {
  7286. struct lpfc_hba *phba = vport->phba;
  7287. struct lpfc_iocbq *iocbq;
  7288. int sum, i;
  7289. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  7290. iocbq = phba->sli.iocbq_lookup[i];
  7291. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  7292. ctx_cmd) == 0)
  7293. sum++;
  7294. }
  7295. return sum;
  7296. }
  7297. /**
  7298. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  7299. * @phba: Pointer to HBA context object
  7300. * @cmdiocb: Pointer to command iocb object.
  7301. * @rspiocb: Pointer to response iocb object.
  7302. *
  7303. * This function is called when an aborted FCP iocb completes. This
  7304. * function is called by the ring event handler with no lock held.
  7305. * This function frees the iocb.
  7306. **/
  7307. void
  7308. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7309. struct lpfc_iocbq *rspiocb)
  7310. {
  7311. lpfc_sli_release_iocbq(phba, cmdiocb);
  7312. return;
  7313. }
  7314. /**
  7315. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  7316. * @vport: Pointer to virtual port.
  7317. * @pring: Pointer to driver SLI ring object.
  7318. * @tgt_id: SCSI ID of the target.
  7319. * @lun_id: LUN ID of the scsi device.
  7320. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  7321. *
  7322. * This function sends an abort command for every SCSI command
  7323. * associated with the given virtual port pending on the ring
  7324. * filtered by lpfc_sli_validate_fcp_iocb function.
  7325. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  7326. * FCP iocbs associated with lun specified by tgt_id and lun_id
  7327. * parameters
  7328. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  7329. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  7330. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  7331. * FCP iocbs associated with virtual port.
  7332. * This function returns number of iocbs it failed to abort.
  7333. * This function is called with no locks held.
  7334. **/
  7335. int
  7336. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  7337. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  7338. {
  7339. struct lpfc_hba *phba = vport->phba;
  7340. struct lpfc_iocbq *iocbq;
  7341. struct lpfc_iocbq *abtsiocb;
  7342. IOCB_t *cmd = NULL;
  7343. int errcnt = 0, ret_val = 0;
  7344. int i;
  7345. for (i = 1; i <= phba->sli.last_iotag; i++) {
  7346. iocbq = phba->sli.iocbq_lookup[i];
  7347. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  7348. abort_cmd) != 0)
  7349. continue;
  7350. /* issue ABTS for this IOCB based on iotag */
  7351. abtsiocb = lpfc_sli_get_iocbq(phba);
  7352. if (abtsiocb == NULL) {
  7353. errcnt++;
  7354. continue;
  7355. }
  7356. cmd = &iocbq->iocb;
  7357. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  7358. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  7359. if (phba->sli_rev == LPFC_SLI_REV4)
  7360. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  7361. else
  7362. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  7363. abtsiocb->iocb.ulpLe = 1;
  7364. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  7365. abtsiocb->vport = phba->pport;
  7366. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  7367. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  7368. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7369. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  7370. if (lpfc_is_link_up(phba))
  7371. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  7372. else
  7373. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  7374. /* Setup callback routine and issue the command. */
  7375. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  7376. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  7377. abtsiocb, 0);
  7378. if (ret_val == IOCB_ERROR) {
  7379. lpfc_sli_release_iocbq(phba, abtsiocb);
  7380. errcnt++;
  7381. continue;
  7382. }
  7383. }
  7384. return errcnt;
  7385. }
  7386. /**
  7387. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  7388. * @phba: Pointer to HBA context object.
  7389. * @cmdiocbq: Pointer to command iocb.
  7390. * @rspiocbq: Pointer to response iocb.
  7391. *
  7392. * This function is the completion handler for iocbs issued using
  7393. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7394. * ring event handler function without any lock held. This function
  7395. * can be called from both worker thread context and interrupt
  7396. * context. This function also can be called from other thread which
  7397. * cleans up the SLI layer objects.
  7398. * This function copy the contents of the response iocb to the
  7399. * response iocb memory object provided by the caller of
  7400. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7401. * sleeps for the iocb completion.
  7402. **/
  7403. static void
  7404. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7405. struct lpfc_iocbq *cmdiocbq,
  7406. struct lpfc_iocbq *rspiocbq)
  7407. {
  7408. wait_queue_head_t *pdone_q;
  7409. unsigned long iflags;
  7410. struct lpfc_scsi_buf *lpfc_cmd;
  7411. spin_lock_irqsave(&phba->hbalock, iflags);
  7412. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7413. if (cmdiocbq->context2 && rspiocbq)
  7414. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7415. &rspiocbq->iocb, sizeof(IOCB_t));
  7416. /* Set the exchange busy flag for task management commands */
  7417. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7418. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7419. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7420. cur_iocbq);
  7421. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7422. }
  7423. pdone_q = cmdiocbq->context_un.wait_queue;
  7424. if (pdone_q)
  7425. wake_up(pdone_q);
  7426. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7427. return;
  7428. }
  7429. /**
  7430. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7431. * @phba: Pointer to HBA context object..
  7432. * @piocbq: Pointer to command iocb.
  7433. * @flag: Flag to test.
  7434. *
  7435. * This routine grabs the hbalock and then test the iocb_flag to
  7436. * see if the passed in flag is set.
  7437. * Returns:
  7438. * 1 if flag is set.
  7439. * 0 if flag is not set.
  7440. **/
  7441. static int
  7442. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7443. struct lpfc_iocbq *piocbq, uint32_t flag)
  7444. {
  7445. unsigned long iflags;
  7446. int ret;
  7447. spin_lock_irqsave(&phba->hbalock, iflags);
  7448. ret = piocbq->iocb_flag & flag;
  7449. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7450. return ret;
  7451. }
  7452. /**
  7453. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7454. * @phba: Pointer to HBA context object..
  7455. * @pring: Pointer to sli ring.
  7456. * @piocb: Pointer to command iocb.
  7457. * @prspiocbq: Pointer to response iocb.
  7458. * @timeout: Timeout in number of seconds.
  7459. *
  7460. * This function issues the iocb to firmware and waits for the
  7461. * iocb to complete. If the iocb command is not
  7462. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7463. * Caller should not free the iocb resources if this function
  7464. * returns IOCB_TIMEDOUT.
  7465. * The function waits for the iocb completion using an
  7466. * non-interruptible wait.
  7467. * This function will sleep while waiting for iocb completion.
  7468. * So, this function should not be called from any context which
  7469. * does not allow sleeping. Due to the same reason, this function
  7470. * cannot be called with interrupt disabled.
  7471. * This function assumes that the iocb completions occur while
  7472. * this function sleep. So, this function cannot be called from
  7473. * the thread which process iocb completion for this ring.
  7474. * This function clears the iocb_flag of the iocb object before
  7475. * issuing the iocb and the iocb completion handler sets this
  7476. * flag and wakes this thread when the iocb completes.
  7477. * The contents of the response iocb will be copied to prspiocbq
  7478. * by the completion handler when the command completes.
  7479. * This function returns IOCB_SUCCESS when success.
  7480. * This function is called with no lock held.
  7481. **/
  7482. int
  7483. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7484. uint32_t ring_number,
  7485. struct lpfc_iocbq *piocb,
  7486. struct lpfc_iocbq *prspiocbq,
  7487. uint32_t timeout)
  7488. {
  7489. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7490. long timeleft, timeout_req = 0;
  7491. int retval = IOCB_SUCCESS;
  7492. uint32_t creg_val;
  7493. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7494. /*
  7495. * If the caller has provided a response iocbq buffer, then context2
  7496. * is NULL or its an error.
  7497. */
  7498. if (prspiocbq) {
  7499. if (piocb->context2)
  7500. return IOCB_ERROR;
  7501. piocb->context2 = prspiocbq;
  7502. }
  7503. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7504. piocb->context_un.wait_queue = &done_q;
  7505. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7506. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7507. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7508. return IOCB_ERROR;
  7509. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7510. writel(creg_val, phba->HCregaddr);
  7511. readl(phba->HCregaddr); /* flush */
  7512. }
  7513. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7514. SLI_IOCB_RET_IOCB);
  7515. if (retval == IOCB_SUCCESS) {
  7516. timeout_req = timeout * HZ;
  7517. timeleft = wait_event_timeout(done_q,
  7518. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7519. timeout_req);
  7520. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7521. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7522. "0331 IOCB wake signaled\n");
  7523. } else if (timeleft == 0) {
  7524. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7525. "0338 IOCB wait timeout error - no "
  7526. "wake response Data x%x\n", timeout);
  7527. retval = IOCB_TIMEDOUT;
  7528. } else {
  7529. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7530. "0330 IOCB wake NOT set, "
  7531. "Data x%x x%lx\n",
  7532. timeout, (timeleft / jiffies));
  7533. retval = IOCB_TIMEDOUT;
  7534. }
  7535. } else if (retval == IOCB_BUSY) {
  7536. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7537. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7538. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7539. return retval;
  7540. } else {
  7541. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7542. "0332 IOCB wait issue failed, Data x%x\n",
  7543. retval);
  7544. retval = IOCB_ERROR;
  7545. }
  7546. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7547. if (lpfc_readl(phba->HCregaddr, &creg_val))
  7548. return IOCB_ERROR;
  7549. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7550. writel(creg_val, phba->HCregaddr);
  7551. readl(phba->HCregaddr); /* flush */
  7552. }
  7553. if (prspiocbq)
  7554. piocb->context2 = NULL;
  7555. piocb->context_un.wait_queue = NULL;
  7556. piocb->iocb_cmpl = NULL;
  7557. return retval;
  7558. }
  7559. /**
  7560. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7561. * @phba: Pointer to HBA context object.
  7562. * @pmboxq: Pointer to driver mailbox object.
  7563. * @timeout: Timeout in number of seconds.
  7564. *
  7565. * This function issues the mailbox to firmware and waits for the
  7566. * mailbox command to complete. If the mailbox command is not
  7567. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7568. * The function waits for the mailbox completion using an
  7569. * interruptible wait. If the thread is woken up due to a
  7570. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7571. * should not free the mailbox resources, if this function returns
  7572. * MBX_TIMEOUT.
  7573. * This function will sleep while waiting for mailbox completion.
  7574. * So, this function should not be called from any context which
  7575. * does not allow sleeping. Due to the same reason, this function
  7576. * cannot be called with interrupt disabled.
  7577. * This function assumes that the mailbox completion occurs while
  7578. * this function sleep. So, this function cannot be called from
  7579. * the worker thread which processes mailbox completion.
  7580. * This function is called in the context of HBA management
  7581. * applications.
  7582. * This function returns MBX_SUCCESS when successful.
  7583. * This function is called with no lock held.
  7584. **/
  7585. int
  7586. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7587. uint32_t timeout)
  7588. {
  7589. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7590. int retval;
  7591. unsigned long flag;
  7592. /* The caller must leave context1 empty. */
  7593. if (pmboxq->context1)
  7594. return MBX_NOT_FINISHED;
  7595. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7596. /* setup wake call as IOCB callback */
  7597. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7598. /* setup context field to pass wait_queue pointer to wake function */
  7599. pmboxq->context1 = &done_q;
  7600. /* now issue the command */
  7601. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7602. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7603. wait_event_interruptible_timeout(done_q,
  7604. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7605. timeout * HZ);
  7606. spin_lock_irqsave(&phba->hbalock, flag);
  7607. pmboxq->context1 = NULL;
  7608. /*
  7609. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7610. * else do not free the resources.
  7611. */
  7612. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7613. retval = MBX_SUCCESS;
  7614. lpfc_sli4_swap_str(phba, pmboxq);
  7615. } else {
  7616. retval = MBX_TIMEOUT;
  7617. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7618. }
  7619. spin_unlock_irqrestore(&phba->hbalock, flag);
  7620. }
  7621. return retval;
  7622. }
  7623. /**
  7624. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7625. * @phba: Pointer to HBA context.
  7626. *
  7627. * This function is called to shutdown the driver's mailbox sub-system.
  7628. * It first marks the mailbox sub-system is in a block state to prevent
  7629. * the asynchronous mailbox command from issued off the pending mailbox
  7630. * command queue. If the mailbox command sub-system shutdown is due to
  7631. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7632. * the mailbox sub-system flush routine to forcefully bring down the
  7633. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7634. * as with offline or HBA function reset), this routine will wait for the
  7635. * outstanding mailbox command to complete before invoking the mailbox
  7636. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7637. **/
  7638. void
  7639. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7640. {
  7641. struct lpfc_sli *psli = &phba->sli;
  7642. uint8_t actcmd = MBX_HEARTBEAT;
  7643. unsigned long timeout;
  7644. spin_lock_irq(&phba->hbalock);
  7645. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7646. spin_unlock_irq(&phba->hbalock);
  7647. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7648. spin_lock_irq(&phba->hbalock);
  7649. if (phba->sli.mbox_active)
  7650. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7651. spin_unlock_irq(&phba->hbalock);
  7652. /* Determine how long we might wait for the active mailbox
  7653. * command to be gracefully completed by firmware.
  7654. */
  7655. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7656. 1000) + jiffies;
  7657. while (phba->sli.mbox_active) {
  7658. /* Check active mailbox complete status every 2ms */
  7659. msleep(2);
  7660. if (time_after(jiffies, timeout))
  7661. /* Timeout, let the mailbox flush routine to
  7662. * forcefully release active mailbox command
  7663. */
  7664. break;
  7665. }
  7666. }
  7667. lpfc_sli_mbox_sys_flush(phba);
  7668. }
  7669. /**
  7670. * lpfc_sli_eratt_read - read sli-3 error attention events
  7671. * @phba: Pointer to HBA context.
  7672. *
  7673. * This function is called to read the SLI3 device error attention registers
  7674. * for possible error attention events. The caller must hold the hostlock
  7675. * with spin_lock_irq().
  7676. *
  7677. * This function returns 1 when there is Error Attention in the Host Attention
  7678. * Register and returns 0 otherwise.
  7679. **/
  7680. static int
  7681. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7682. {
  7683. uint32_t ha_copy;
  7684. /* Read chip Host Attention (HA) register */
  7685. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7686. goto unplug_err;
  7687. if (ha_copy & HA_ERATT) {
  7688. /* Read host status register to retrieve error event */
  7689. if (lpfc_sli_read_hs(phba))
  7690. goto unplug_err;
  7691. /* Check if there is a deferred error condition is active */
  7692. if ((HS_FFER1 & phba->work_hs) &&
  7693. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7694. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7695. phba->hba_flag |= DEFER_ERATT;
  7696. /* Clear all interrupt enable conditions */
  7697. writel(0, phba->HCregaddr);
  7698. readl(phba->HCregaddr);
  7699. }
  7700. /* Set the driver HA work bitmap */
  7701. phba->work_ha |= HA_ERATT;
  7702. /* Indicate polling handles this ERATT */
  7703. phba->hba_flag |= HBA_ERATT_HANDLED;
  7704. return 1;
  7705. }
  7706. return 0;
  7707. unplug_err:
  7708. /* Set the driver HS work bitmap */
  7709. phba->work_hs |= UNPLUG_ERR;
  7710. /* Set the driver HA work bitmap */
  7711. phba->work_ha |= HA_ERATT;
  7712. /* Indicate polling handles this ERATT */
  7713. phba->hba_flag |= HBA_ERATT_HANDLED;
  7714. return 1;
  7715. }
  7716. /**
  7717. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7718. * @phba: Pointer to HBA context.
  7719. *
  7720. * This function is called to read the SLI4 device error attention registers
  7721. * for possible error attention events. The caller must hold the hostlock
  7722. * with spin_lock_irq().
  7723. *
  7724. * This function returns 1 when there is Error Attention in the Host Attention
  7725. * Register and returns 0 otherwise.
  7726. **/
  7727. static int
  7728. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7729. {
  7730. uint32_t uerr_sta_hi, uerr_sta_lo;
  7731. uint32_t if_type, portsmphr;
  7732. struct lpfc_register portstat_reg;
  7733. /*
  7734. * For now, use the SLI4 device internal unrecoverable error
  7735. * registers for error attention. This can be changed later.
  7736. */
  7737. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7738. switch (if_type) {
  7739. case LPFC_SLI_INTF_IF_TYPE_0:
  7740. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  7741. &uerr_sta_lo) ||
  7742. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  7743. &uerr_sta_hi)) {
  7744. phba->work_hs |= UNPLUG_ERR;
  7745. phba->work_ha |= HA_ERATT;
  7746. phba->hba_flag |= HBA_ERATT_HANDLED;
  7747. return 1;
  7748. }
  7749. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7750. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7751. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7752. "1423 HBA Unrecoverable error: "
  7753. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7754. "ue_mask_lo_reg=0x%x, "
  7755. "ue_mask_hi_reg=0x%x\n",
  7756. uerr_sta_lo, uerr_sta_hi,
  7757. phba->sli4_hba.ue_mask_lo,
  7758. phba->sli4_hba.ue_mask_hi);
  7759. phba->work_status[0] = uerr_sta_lo;
  7760. phba->work_status[1] = uerr_sta_hi;
  7761. phba->work_ha |= HA_ERATT;
  7762. phba->hba_flag |= HBA_ERATT_HANDLED;
  7763. return 1;
  7764. }
  7765. break;
  7766. case LPFC_SLI_INTF_IF_TYPE_2:
  7767. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  7768. &portstat_reg.word0) ||
  7769. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  7770. &portsmphr)){
  7771. phba->work_hs |= UNPLUG_ERR;
  7772. phba->work_ha |= HA_ERATT;
  7773. phba->hba_flag |= HBA_ERATT_HANDLED;
  7774. return 1;
  7775. }
  7776. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  7777. phba->work_status[0] =
  7778. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  7779. phba->work_status[1] =
  7780. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  7781. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7782. "2885 Port Error Detected: "
  7783. "port status reg 0x%x, "
  7784. "port smphr reg 0x%x, "
  7785. "error 1=0x%x, error 2=0x%x\n",
  7786. portstat_reg.word0,
  7787. portsmphr,
  7788. phba->work_status[0],
  7789. phba->work_status[1]);
  7790. phba->work_ha |= HA_ERATT;
  7791. phba->hba_flag |= HBA_ERATT_HANDLED;
  7792. return 1;
  7793. }
  7794. break;
  7795. case LPFC_SLI_INTF_IF_TYPE_1:
  7796. default:
  7797. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7798. "2886 HBA Error Attention on unsupported "
  7799. "if type %d.", if_type);
  7800. return 1;
  7801. }
  7802. return 0;
  7803. }
  7804. /**
  7805. * lpfc_sli_check_eratt - check error attention events
  7806. * @phba: Pointer to HBA context.
  7807. *
  7808. * This function is called from timer soft interrupt context to check HBA's
  7809. * error attention register bit for error attention events.
  7810. *
  7811. * This function returns 1 when there is Error Attention in the Host Attention
  7812. * Register and returns 0 otherwise.
  7813. **/
  7814. int
  7815. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7816. {
  7817. uint32_t ha_copy;
  7818. /* If somebody is waiting to handle an eratt, don't process it
  7819. * here. The brdkill function will do this.
  7820. */
  7821. if (phba->link_flag & LS_IGNORE_ERATT)
  7822. return 0;
  7823. /* Check if interrupt handler handles this ERATT */
  7824. spin_lock_irq(&phba->hbalock);
  7825. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7826. /* Interrupt handler has handled ERATT */
  7827. spin_unlock_irq(&phba->hbalock);
  7828. return 0;
  7829. }
  7830. /*
  7831. * If there is deferred error attention, do not check for error
  7832. * attention
  7833. */
  7834. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7835. spin_unlock_irq(&phba->hbalock);
  7836. return 0;
  7837. }
  7838. /* If PCI channel is offline, don't process it */
  7839. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7840. spin_unlock_irq(&phba->hbalock);
  7841. return 0;
  7842. }
  7843. switch (phba->sli_rev) {
  7844. case LPFC_SLI_REV2:
  7845. case LPFC_SLI_REV3:
  7846. /* Read chip Host Attention (HA) register */
  7847. ha_copy = lpfc_sli_eratt_read(phba);
  7848. break;
  7849. case LPFC_SLI_REV4:
  7850. /* Read device Uncoverable Error (UERR) registers */
  7851. ha_copy = lpfc_sli4_eratt_read(phba);
  7852. break;
  7853. default:
  7854. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7855. "0299 Invalid SLI revision (%d)\n",
  7856. phba->sli_rev);
  7857. ha_copy = 0;
  7858. break;
  7859. }
  7860. spin_unlock_irq(&phba->hbalock);
  7861. return ha_copy;
  7862. }
  7863. /**
  7864. * lpfc_intr_state_check - Check device state for interrupt handling
  7865. * @phba: Pointer to HBA context.
  7866. *
  7867. * This inline routine checks whether a device or its PCI slot is in a state
  7868. * that the interrupt should be handled.
  7869. *
  7870. * This function returns 0 if the device or the PCI slot is in a state that
  7871. * interrupt should be handled, otherwise -EIO.
  7872. */
  7873. static inline int
  7874. lpfc_intr_state_check(struct lpfc_hba *phba)
  7875. {
  7876. /* If the pci channel is offline, ignore all the interrupts */
  7877. if (unlikely(pci_channel_offline(phba->pcidev)))
  7878. return -EIO;
  7879. /* Update device level interrupt statistics */
  7880. phba->sli.slistat.sli_intr++;
  7881. /* Ignore all interrupts during initialization. */
  7882. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7883. return -EIO;
  7884. return 0;
  7885. }
  7886. /**
  7887. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7888. * @irq: Interrupt number.
  7889. * @dev_id: The device context pointer.
  7890. *
  7891. * This function is directly called from the PCI layer as an interrupt
  7892. * service routine when device with SLI-3 interface spec is enabled with
  7893. * MSI-X multi-message interrupt mode and there are slow-path events in
  7894. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7895. * interrupt mode, this function is called as part of the device-level
  7896. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7897. * is undergoing initialization, the interrupt handler will not process
  7898. * the interrupt. The link attention and ELS ring attention events are
  7899. * handled by the worker thread. The interrupt handler signals the worker
  7900. * thread and returns for these events. This function is called without
  7901. * any lock held. It gets the hbalock to access and update SLI data
  7902. * structures.
  7903. *
  7904. * This function returns IRQ_HANDLED when interrupt is handled else it
  7905. * returns IRQ_NONE.
  7906. **/
  7907. irqreturn_t
  7908. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7909. {
  7910. struct lpfc_hba *phba;
  7911. uint32_t ha_copy, hc_copy;
  7912. uint32_t work_ha_copy;
  7913. unsigned long status;
  7914. unsigned long iflag;
  7915. uint32_t control;
  7916. MAILBOX_t *mbox, *pmbox;
  7917. struct lpfc_vport *vport;
  7918. struct lpfc_nodelist *ndlp;
  7919. struct lpfc_dmabuf *mp;
  7920. LPFC_MBOXQ_t *pmb;
  7921. int rc;
  7922. /*
  7923. * Get the driver's phba structure from the dev_id and
  7924. * assume the HBA is not interrupting.
  7925. */
  7926. phba = (struct lpfc_hba *)dev_id;
  7927. if (unlikely(!phba))
  7928. return IRQ_NONE;
  7929. /*
  7930. * Stuff needs to be attented to when this function is invoked as an
  7931. * individual interrupt handler in MSI-X multi-message interrupt mode
  7932. */
  7933. if (phba->intr_type == MSIX) {
  7934. /* Check device state for handling interrupt */
  7935. if (lpfc_intr_state_check(phba))
  7936. return IRQ_NONE;
  7937. /* Need to read HA REG for slow-path events */
  7938. spin_lock_irqsave(&phba->hbalock, iflag);
  7939. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  7940. goto unplug_error;
  7941. /* If somebody is waiting to handle an eratt don't process it
  7942. * here. The brdkill function will do this.
  7943. */
  7944. if (phba->link_flag & LS_IGNORE_ERATT)
  7945. ha_copy &= ~HA_ERATT;
  7946. /* Check the need for handling ERATT in interrupt handler */
  7947. if (ha_copy & HA_ERATT) {
  7948. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7949. /* ERATT polling has handled ERATT */
  7950. ha_copy &= ~HA_ERATT;
  7951. else
  7952. /* Indicate interrupt handler handles ERATT */
  7953. phba->hba_flag |= HBA_ERATT_HANDLED;
  7954. }
  7955. /*
  7956. * If there is deferred error attention, do not check for any
  7957. * interrupt.
  7958. */
  7959. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7960. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7961. return IRQ_NONE;
  7962. }
  7963. /* Clear up only attention source related to slow-path */
  7964. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  7965. goto unplug_error;
  7966. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7967. HC_LAINT_ENA | HC_ERINT_ENA),
  7968. phba->HCregaddr);
  7969. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7970. phba->HAregaddr);
  7971. writel(hc_copy, phba->HCregaddr);
  7972. readl(phba->HAregaddr); /* flush */
  7973. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7974. } else
  7975. ha_copy = phba->ha_copy;
  7976. work_ha_copy = ha_copy & phba->work_ha_mask;
  7977. if (work_ha_copy) {
  7978. if (work_ha_copy & HA_LATT) {
  7979. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7980. /*
  7981. * Turn off Link Attention interrupts
  7982. * until CLEAR_LA done
  7983. */
  7984. spin_lock_irqsave(&phba->hbalock, iflag);
  7985. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7986. if (lpfc_readl(phba->HCregaddr, &control))
  7987. goto unplug_error;
  7988. control &= ~HC_LAINT_ENA;
  7989. writel(control, phba->HCregaddr);
  7990. readl(phba->HCregaddr); /* flush */
  7991. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7992. }
  7993. else
  7994. work_ha_copy &= ~HA_LATT;
  7995. }
  7996. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7997. /*
  7998. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7999. * the only slow ring.
  8000. */
  8001. status = (work_ha_copy &
  8002. (HA_RXMASK << (4*LPFC_ELS_RING)));
  8003. status >>= (4*LPFC_ELS_RING);
  8004. if (status & HA_RXMASK) {
  8005. spin_lock_irqsave(&phba->hbalock, iflag);
  8006. if (lpfc_readl(phba->HCregaddr, &control))
  8007. goto unplug_error;
  8008. lpfc_debugfs_slow_ring_trc(phba,
  8009. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  8010. control, status,
  8011. (uint32_t)phba->sli.slistat.sli_intr);
  8012. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  8013. lpfc_debugfs_slow_ring_trc(phba,
  8014. "ISR Disable ring:"
  8015. "pwork:x%x hawork:x%x wait:x%x",
  8016. phba->work_ha, work_ha_copy,
  8017. (uint32_t)((unsigned long)
  8018. &phba->work_waitq));
  8019. control &=
  8020. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  8021. writel(control, phba->HCregaddr);
  8022. readl(phba->HCregaddr); /* flush */
  8023. }
  8024. else {
  8025. lpfc_debugfs_slow_ring_trc(phba,
  8026. "ISR slow ring: pwork:"
  8027. "x%x hawork:x%x wait:x%x",
  8028. phba->work_ha, work_ha_copy,
  8029. (uint32_t)((unsigned long)
  8030. &phba->work_waitq));
  8031. }
  8032. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8033. }
  8034. }
  8035. spin_lock_irqsave(&phba->hbalock, iflag);
  8036. if (work_ha_copy & HA_ERATT) {
  8037. if (lpfc_sli_read_hs(phba))
  8038. goto unplug_error;
  8039. /*
  8040. * Check if there is a deferred error condition
  8041. * is active
  8042. */
  8043. if ((HS_FFER1 & phba->work_hs) &&
  8044. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  8045. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  8046. phba->work_hs)) {
  8047. phba->hba_flag |= DEFER_ERATT;
  8048. /* Clear all interrupt enable conditions */
  8049. writel(0, phba->HCregaddr);
  8050. readl(phba->HCregaddr);
  8051. }
  8052. }
  8053. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  8054. pmb = phba->sli.mbox_active;
  8055. pmbox = &pmb->u.mb;
  8056. mbox = phba->mbox;
  8057. vport = pmb->vport;
  8058. /* First check out the status word */
  8059. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  8060. if (pmbox->mbxOwner != OWN_HOST) {
  8061. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8062. /*
  8063. * Stray Mailbox Interrupt, mbxCommand <cmd>
  8064. * mbxStatus <status>
  8065. */
  8066. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8067. LOG_SLI,
  8068. "(%d):0304 Stray Mailbox "
  8069. "Interrupt mbxCommand x%x "
  8070. "mbxStatus x%x\n",
  8071. (vport ? vport->vpi : 0),
  8072. pmbox->mbxCommand,
  8073. pmbox->mbxStatus);
  8074. /* clear mailbox attention bit */
  8075. work_ha_copy &= ~HA_MBATT;
  8076. } else {
  8077. phba->sli.mbox_active = NULL;
  8078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8079. phba->last_completion_time = jiffies;
  8080. del_timer(&phba->sli.mbox_tmo);
  8081. if (pmb->mbox_cmpl) {
  8082. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  8083. MAILBOX_CMD_SIZE);
  8084. if (pmb->out_ext_byte_len &&
  8085. pmb->context2)
  8086. lpfc_sli_pcimem_bcopy(
  8087. phba->mbox_ext,
  8088. pmb->context2,
  8089. pmb->out_ext_byte_len);
  8090. }
  8091. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8092. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8093. lpfc_debugfs_disc_trc(vport,
  8094. LPFC_DISC_TRC_MBOX_VPORT,
  8095. "MBOX dflt rpi: : "
  8096. "status:x%x rpi:x%x",
  8097. (uint32_t)pmbox->mbxStatus,
  8098. pmbox->un.varWords[0], 0);
  8099. if (!pmbox->mbxStatus) {
  8100. mp = (struct lpfc_dmabuf *)
  8101. (pmb->context1);
  8102. ndlp = (struct lpfc_nodelist *)
  8103. pmb->context2;
  8104. /* Reg_LOGIN of dflt RPI was
  8105. * successful. new lets get
  8106. * rid of the RPI using the
  8107. * same mbox buffer.
  8108. */
  8109. lpfc_unreg_login(phba,
  8110. vport->vpi,
  8111. pmbox->un.varWords[0],
  8112. pmb);
  8113. pmb->mbox_cmpl =
  8114. lpfc_mbx_cmpl_dflt_rpi;
  8115. pmb->context1 = mp;
  8116. pmb->context2 = ndlp;
  8117. pmb->vport = vport;
  8118. rc = lpfc_sli_issue_mbox(phba,
  8119. pmb,
  8120. MBX_NOWAIT);
  8121. if (rc != MBX_BUSY)
  8122. lpfc_printf_log(phba,
  8123. KERN_ERR,
  8124. LOG_MBOX | LOG_SLI,
  8125. "0350 rc should have"
  8126. "been MBX_BUSY\n");
  8127. if (rc != MBX_NOT_FINISHED)
  8128. goto send_current_mbox;
  8129. }
  8130. }
  8131. spin_lock_irqsave(
  8132. &phba->pport->work_port_lock,
  8133. iflag);
  8134. phba->pport->work_port_events &=
  8135. ~WORKER_MBOX_TMO;
  8136. spin_unlock_irqrestore(
  8137. &phba->pport->work_port_lock,
  8138. iflag);
  8139. lpfc_mbox_cmpl_put(phba, pmb);
  8140. }
  8141. } else
  8142. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8143. if ((work_ha_copy & HA_MBATT) &&
  8144. (phba->sli.mbox_active == NULL)) {
  8145. send_current_mbox:
  8146. /* Process next mailbox command if there is one */
  8147. do {
  8148. rc = lpfc_sli_issue_mbox(phba, NULL,
  8149. MBX_NOWAIT);
  8150. } while (rc == MBX_NOT_FINISHED);
  8151. if (rc != MBX_SUCCESS)
  8152. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8153. LOG_SLI, "0349 rc should be "
  8154. "MBX_SUCCESS\n");
  8155. }
  8156. spin_lock_irqsave(&phba->hbalock, iflag);
  8157. phba->work_ha |= work_ha_copy;
  8158. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8159. lpfc_worker_wake_up(phba);
  8160. }
  8161. return IRQ_HANDLED;
  8162. unplug_error:
  8163. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8164. return IRQ_HANDLED;
  8165. } /* lpfc_sli_sp_intr_handler */
  8166. /**
  8167. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  8168. * @irq: Interrupt number.
  8169. * @dev_id: The device context pointer.
  8170. *
  8171. * This function is directly called from the PCI layer as an interrupt
  8172. * service routine when device with SLI-3 interface spec is enabled with
  8173. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8174. * ring event in the HBA. However, when the device is enabled with either
  8175. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8176. * device-level interrupt handler. When the PCI slot is in error recovery
  8177. * or the HBA is undergoing initialization, the interrupt handler will not
  8178. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8179. * the intrrupt context. This function is called without any lock held.
  8180. * It gets the hbalock to access and update SLI data structures.
  8181. *
  8182. * This function returns IRQ_HANDLED when interrupt is handled else it
  8183. * returns IRQ_NONE.
  8184. **/
  8185. irqreturn_t
  8186. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  8187. {
  8188. struct lpfc_hba *phba;
  8189. uint32_t ha_copy;
  8190. unsigned long status;
  8191. unsigned long iflag;
  8192. /* Get the driver's phba structure from the dev_id and
  8193. * assume the HBA is not interrupting.
  8194. */
  8195. phba = (struct lpfc_hba *) dev_id;
  8196. if (unlikely(!phba))
  8197. return IRQ_NONE;
  8198. /*
  8199. * Stuff needs to be attented to when this function is invoked as an
  8200. * individual interrupt handler in MSI-X multi-message interrupt mode
  8201. */
  8202. if (phba->intr_type == MSIX) {
  8203. /* Check device state for handling interrupt */
  8204. if (lpfc_intr_state_check(phba))
  8205. return IRQ_NONE;
  8206. /* Need to read HA REG for FCP ring and other ring events */
  8207. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  8208. return IRQ_HANDLED;
  8209. /* Clear up only attention source related to fast-path */
  8210. spin_lock_irqsave(&phba->hbalock, iflag);
  8211. /*
  8212. * If there is deferred error attention, do not check for
  8213. * any interrupt.
  8214. */
  8215. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8216. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8217. return IRQ_NONE;
  8218. }
  8219. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  8220. phba->HAregaddr);
  8221. readl(phba->HAregaddr); /* flush */
  8222. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8223. } else
  8224. ha_copy = phba->ha_copy;
  8225. /*
  8226. * Process all events on FCP ring. Take the optimized path for FCP IO.
  8227. */
  8228. ha_copy &= ~(phba->work_ha_mask);
  8229. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8230. status >>= (4*LPFC_FCP_RING);
  8231. if (status & HA_RXMASK)
  8232. lpfc_sli_handle_fast_ring_event(phba,
  8233. &phba->sli.ring[LPFC_FCP_RING],
  8234. status);
  8235. if (phba->cfg_multi_ring_support == 2) {
  8236. /*
  8237. * Process all events on extra ring. Take the optimized path
  8238. * for extra ring IO.
  8239. */
  8240. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8241. status >>= (4*LPFC_EXTRA_RING);
  8242. if (status & HA_RXMASK) {
  8243. lpfc_sli_handle_fast_ring_event(phba,
  8244. &phba->sli.ring[LPFC_EXTRA_RING],
  8245. status);
  8246. }
  8247. }
  8248. return IRQ_HANDLED;
  8249. } /* lpfc_sli_fp_intr_handler */
  8250. /**
  8251. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  8252. * @irq: Interrupt number.
  8253. * @dev_id: The device context pointer.
  8254. *
  8255. * This function is the HBA device-level interrupt handler to device with
  8256. * SLI-3 interface spec, called from the PCI layer when either MSI or
  8257. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  8258. * requires driver attention. This function invokes the slow-path interrupt
  8259. * attention handling function and fast-path interrupt attention handling
  8260. * function in turn to process the relevant HBA attention events. This
  8261. * function is called without any lock held. It gets the hbalock to access
  8262. * and update SLI data structures.
  8263. *
  8264. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8265. * returns IRQ_NONE.
  8266. **/
  8267. irqreturn_t
  8268. lpfc_sli_intr_handler(int irq, void *dev_id)
  8269. {
  8270. struct lpfc_hba *phba;
  8271. irqreturn_t sp_irq_rc, fp_irq_rc;
  8272. unsigned long status1, status2;
  8273. uint32_t hc_copy;
  8274. /*
  8275. * Get the driver's phba structure from the dev_id and
  8276. * assume the HBA is not interrupting.
  8277. */
  8278. phba = (struct lpfc_hba *) dev_id;
  8279. if (unlikely(!phba))
  8280. return IRQ_NONE;
  8281. /* Check device state for handling interrupt */
  8282. if (lpfc_intr_state_check(phba))
  8283. return IRQ_NONE;
  8284. spin_lock(&phba->hbalock);
  8285. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  8286. spin_unlock(&phba->hbalock);
  8287. return IRQ_HANDLED;
  8288. }
  8289. if (unlikely(!phba->ha_copy)) {
  8290. spin_unlock(&phba->hbalock);
  8291. return IRQ_NONE;
  8292. } else if (phba->ha_copy & HA_ERATT) {
  8293. if (phba->hba_flag & HBA_ERATT_HANDLED)
  8294. /* ERATT polling has handled ERATT */
  8295. phba->ha_copy &= ~HA_ERATT;
  8296. else
  8297. /* Indicate interrupt handler handles ERATT */
  8298. phba->hba_flag |= HBA_ERATT_HANDLED;
  8299. }
  8300. /*
  8301. * If there is deferred error attention, do not check for any interrupt.
  8302. */
  8303. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8304. spin_unlock(&phba->hbalock);
  8305. return IRQ_NONE;
  8306. }
  8307. /* Clear attention sources except link and error attentions */
  8308. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  8309. spin_unlock(&phba->hbalock);
  8310. return IRQ_HANDLED;
  8311. }
  8312. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  8313. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  8314. phba->HCregaddr);
  8315. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  8316. writel(hc_copy, phba->HCregaddr);
  8317. readl(phba->HAregaddr); /* flush */
  8318. spin_unlock(&phba->hbalock);
  8319. /*
  8320. * Invokes slow-path host attention interrupt handling as appropriate.
  8321. */
  8322. /* status of events with mailbox and link attention */
  8323. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  8324. /* status of events with ELS ring */
  8325. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  8326. status2 >>= (4*LPFC_ELS_RING);
  8327. if (status1 || (status2 & HA_RXMASK))
  8328. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  8329. else
  8330. sp_irq_rc = IRQ_NONE;
  8331. /*
  8332. * Invoke fast-path host attention interrupt handling as appropriate.
  8333. */
  8334. /* status of events with FCP ring */
  8335. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  8336. status1 >>= (4*LPFC_FCP_RING);
  8337. /* status of events with extra ring */
  8338. if (phba->cfg_multi_ring_support == 2) {
  8339. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  8340. status2 >>= (4*LPFC_EXTRA_RING);
  8341. } else
  8342. status2 = 0;
  8343. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  8344. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  8345. else
  8346. fp_irq_rc = IRQ_NONE;
  8347. /* Return device-level interrupt handling status */
  8348. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  8349. } /* lpfc_sli_intr_handler */
  8350. /**
  8351. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  8352. * @phba: pointer to lpfc hba data structure.
  8353. *
  8354. * This routine is invoked by the worker thread to process all the pending
  8355. * SLI4 FCP abort XRI events.
  8356. **/
  8357. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  8358. {
  8359. struct lpfc_cq_event *cq_event;
  8360. /* First, declare the fcp xri abort event has been handled */
  8361. spin_lock_irq(&phba->hbalock);
  8362. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  8363. spin_unlock_irq(&phba->hbalock);
  8364. /* Now, handle all the fcp xri abort events */
  8365. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  8366. /* Get the first event from the head of the event queue */
  8367. spin_lock_irq(&phba->hbalock);
  8368. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  8369. cq_event, struct lpfc_cq_event, list);
  8370. spin_unlock_irq(&phba->hbalock);
  8371. /* Notify aborted XRI for FCP work queue */
  8372. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8373. /* Free the event processed back to the free pool */
  8374. lpfc_sli4_cq_event_release(phba, cq_event);
  8375. }
  8376. }
  8377. /**
  8378. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  8379. * @phba: pointer to lpfc hba data structure.
  8380. *
  8381. * This routine is invoked by the worker thread to process all the pending
  8382. * SLI4 els abort xri events.
  8383. **/
  8384. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  8385. {
  8386. struct lpfc_cq_event *cq_event;
  8387. /* First, declare the els xri abort event has been handled */
  8388. spin_lock_irq(&phba->hbalock);
  8389. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  8390. spin_unlock_irq(&phba->hbalock);
  8391. /* Now, handle all the els xri abort events */
  8392. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  8393. /* Get the first event from the head of the event queue */
  8394. spin_lock_irq(&phba->hbalock);
  8395. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  8396. cq_event, struct lpfc_cq_event, list);
  8397. spin_unlock_irq(&phba->hbalock);
  8398. /* Notify aborted XRI for ELS work queue */
  8399. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  8400. /* Free the event processed back to the free pool */
  8401. lpfc_sli4_cq_event_release(phba, cq_event);
  8402. }
  8403. }
  8404. /**
  8405. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  8406. * @phba: pointer to lpfc hba data structure
  8407. * @pIocbIn: pointer to the rspiocbq
  8408. * @pIocbOut: pointer to the cmdiocbq
  8409. * @wcqe: pointer to the complete wcqe
  8410. *
  8411. * This routine transfers the fields of a command iocbq to a response iocbq
  8412. * by copying all the IOCB fields from command iocbq and transferring the
  8413. * completion status information from the complete wcqe.
  8414. **/
  8415. static void
  8416. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  8417. struct lpfc_iocbq *pIocbIn,
  8418. struct lpfc_iocbq *pIocbOut,
  8419. struct lpfc_wcqe_complete *wcqe)
  8420. {
  8421. unsigned long iflags;
  8422. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  8423. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  8424. sizeof(struct lpfc_iocbq) - offset);
  8425. /* Map WCQE parameters into irspiocb parameters */
  8426. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  8427. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  8428. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  8429. pIocbIn->iocb.un.fcpi.fcpi_parm =
  8430. pIocbOut->iocb.un.fcpi.fcpi_parm -
  8431. wcqe->total_data_placed;
  8432. else
  8433. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8434. else {
  8435. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  8436. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  8437. }
  8438. /* Pick up HBA exchange busy condition */
  8439. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  8440. spin_lock_irqsave(&phba->hbalock, iflags);
  8441. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  8442. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8443. }
  8444. }
  8445. /**
  8446. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  8447. * @phba: Pointer to HBA context object.
  8448. * @wcqe: Pointer to work-queue completion queue entry.
  8449. *
  8450. * This routine handles an ELS work-queue completion event and construct
  8451. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  8452. * discovery engine to handle.
  8453. *
  8454. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  8455. **/
  8456. static struct lpfc_iocbq *
  8457. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  8458. struct lpfc_iocbq *irspiocbq)
  8459. {
  8460. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8461. struct lpfc_iocbq *cmdiocbq;
  8462. struct lpfc_wcqe_complete *wcqe;
  8463. unsigned long iflags;
  8464. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8465. spin_lock_irqsave(&phba->hbalock, iflags);
  8466. pring->stats.iocb_event++;
  8467. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8468. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8469. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8470. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8471. if (unlikely(!cmdiocbq)) {
  8472. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8473. "0386 ELS complete with no corresponding "
  8474. "cmdiocb: iotag (%d)\n",
  8475. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8476. lpfc_sli_release_iocbq(phba, irspiocbq);
  8477. return NULL;
  8478. }
  8479. /* Fake the irspiocbq and copy necessary response information */
  8480. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8481. return irspiocbq;
  8482. }
  8483. /**
  8484. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8485. * @phba: Pointer to HBA context object.
  8486. * @cqe: Pointer to mailbox completion queue entry.
  8487. *
  8488. * This routine process a mailbox completion queue entry with asynchrous
  8489. * event.
  8490. *
  8491. * Return: true if work posted to worker thread, otherwise false.
  8492. **/
  8493. static bool
  8494. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8495. {
  8496. struct lpfc_cq_event *cq_event;
  8497. unsigned long iflags;
  8498. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8499. "0392 Async Event: word0:x%x, word1:x%x, "
  8500. "word2:x%x, word3:x%x\n", mcqe->word0,
  8501. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8502. /* Allocate a new internal CQ_EVENT entry */
  8503. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8504. if (!cq_event) {
  8505. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8506. "0394 Failed to allocate CQ_EVENT entry\n");
  8507. return false;
  8508. }
  8509. /* Move the CQE into an asynchronous event entry */
  8510. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8511. spin_lock_irqsave(&phba->hbalock, iflags);
  8512. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8513. /* Set the async event flag */
  8514. phba->hba_flag |= ASYNC_EVENT;
  8515. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8516. return true;
  8517. }
  8518. /**
  8519. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8520. * @phba: Pointer to HBA context object.
  8521. * @cqe: Pointer to mailbox completion queue entry.
  8522. *
  8523. * This routine process a mailbox completion queue entry with mailbox
  8524. * completion event.
  8525. *
  8526. * Return: true if work posted to worker thread, otherwise false.
  8527. **/
  8528. static bool
  8529. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8530. {
  8531. uint32_t mcqe_status;
  8532. MAILBOX_t *mbox, *pmbox;
  8533. struct lpfc_mqe *mqe;
  8534. struct lpfc_vport *vport;
  8535. struct lpfc_nodelist *ndlp;
  8536. struct lpfc_dmabuf *mp;
  8537. unsigned long iflags;
  8538. LPFC_MBOXQ_t *pmb;
  8539. bool workposted = false;
  8540. int rc;
  8541. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8542. if (!bf_get(lpfc_trailer_completed, mcqe))
  8543. goto out_no_mqe_complete;
  8544. /* Get the reference to the active mbox command */
  8545. spin_lock_irqsave(&phba->hbalock, iflags);
  8546. pmb = phba->sli.mbox_active;
  8547. if (unlikely(!pmb)) {
  8548. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8549. "1832 No pending MBOX command to handle\n");
  8550. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8551. goto out_no_mqe_complete;
  8552. }
  8553. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8554. mqe = &pmb->u.mqe;
  8555. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8556. mbox = phba->mbox;
  8557. vport = pmb->vport;
  8558. /* Reset heartbeat timer */
  8559. phba->last_completion_time = jiffies;
  8560. del_timer(&phba->sli.mbox_tmo);
  8561. /* Move mbox data to caller's mailbox region, do endian swapping */
  8562. if (pmb->mbox_cmpl && mbox)
  8563. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8564. /* Set the mailbox status with SLI4 range 0x4000 */
  8565. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8566. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8567. bf_set(lpfc_mqe_status, mqe,
  8568. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8569. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8570. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8571. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8572. "MBOX dflt rpi: status:x%x rpi:x%x",
  8573. mcqe_status,
  8574. pmbox->un.varWords[0], 0);
  8575. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8576. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8577. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8578. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8579. * RID of the PPI using the same mbox buffer.
  8580. */
  8581. lpfc_unreg_login(phba, vport->vpi,
  8582. pmbox->un.varWords[0], pmb);
  8583. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8584. pmb->context1 = mp;
  8585. pmb->context2 = ndlp;
  8586. pmb->vport = vport;
  8587. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8588. if (rc != MBX_BUSY)
  8589. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8590. LOG_SLI, "0385 rc should "
  8591. "have been MBX_BUSY\n");
  8592. if (rc != MBX_NOT_FINISHED)
  8593. goto send_current_mbox;
  8594. }
  8595. }
  8596. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8597. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8598. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8599. /* There is mailbox completion work to do */
  8600. spin_lock_irqsave(&phba->hbalock, iflags);
  8601. __lpfc_mbox_cmpl_put(phba, pmb);
  8602. phba->work_ha |= HA_MBATT;
  8603. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8604. workposted = true;
  8605. send_current_mbox:
  8606. spin_lock_irqsave(&phba->hbalock, iflags);
  8607. /* Release the mailbox command posting token */
  8608. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8609. /* Setting active mailbox pointer need to be in sync to flag clear */
  8610. phba->sli.mbox_active = NULL;
  8611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8612. /* Wake up worker thread to post the next pending mailbox command */
  8613. lpfc_worker_wake_up(phba);
  8614. out_no_mqe_complete:
  8615. if (bf_get(lpfc_trailer_consumed, mcqe))
  8616. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8617. return workposted;
  8618. }
  8619. /**
  8620. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8621. * @phba: Pointer to HBA context object.
  8622. * @cqe: Pointer to mailbox completion queue entry.
  8623. *
  8624. * This routine process a mailbox completion queue entry, it invokes the
  8625. * proper mailbox complete handling or asynchrous event handling routine
  8626. * according to the MCQE's async bit.
  8627. *
  8628. * Return: true if work posted to worker thread, otherwise false.
  8629. **/
  8630. static bool
  8631. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8632. {
  8633. struct lpfc_mcqe mcqe;
  8634. bool workposted;
  8635. /* Copy the mailbox MCQE and convert endian order as needed */
  8636. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8637. /* Invoke the proper event handling routine */
  8638. if (!bf_get(lpfc_trailer_async, &mcqe))
  8639. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8640. else
  8641. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8642. return workposted;
  8643. }
  8644. /**
  8645. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8646. * @phba: Pointer to HBA context object.
  8647. * @wcqe: Pointer to work-queue completion queue entry.
  8648. *
  8649. * This routine handles an ELS work-queue completion event.
  8650. *
  8651. * Return: true if work posted to worker thread, otherwise false.
  8652. **/
  8653. static bool
  8654. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8655. struct lpfc_wcqe_complete *wcqe)
  8656. {
  8657. struct lpfc_iocbq *irspiocbq;
  8658. unsigned long iflags;
  8659. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8660. /* Get an irspiocbq for later ELS response processing use */
  8661. irspiocbq = lpfc_sli_get_iocbq(phba);
  8662. if (!irspiocbq) {
  8663. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8664. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8665. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8666. pring->txq_cnt, phba->iocb_cnt,
  8667. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8668. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8669. return false;
  8670. }
  8671. /* Save off the slow-path queue event for work thread to process */
  8672. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8673. spin_lock_irqsave(&phba->hbalock, iflags);
  8674. list_add_tail(&irspiocbq->cq_event.list,
  8675. &phba->sli4_hba.sp_queue_event);
  8676. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8677. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8678. return true;
  8679. }
  8680. /**
  8681. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8682. * @phba: Pointer to HBA context object.
  8683. * @wcqe: Pointer to work-queue completion queue entry.
  8684. *
  8685. * This routine handles slow-path WQ entry comsumed event by invoking the
  8686. * proper WQ release routine to the slow-path WQ.
  8687. **/
  8688. static void
  8689. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8690. struct lpfc_wcqe_release *wcqe)
  8691. {
  8692. /* Check for the slow-path ELS work queue */
  8693. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8694. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8695. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8696. else
  8697. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8698. "2579 Slow-path wqe consume event carries "
  8699. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8700. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8701. phba->sli4_hba.els_wq->queue_id);
  8702. }
  8703. /**
  8704. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8705. * @phba: Pointer to HBA context object.
  8706. * @cq: Pointer to a WQ completion queue.
  8707. * @wcqe: Pointer to work-queue completion queue entry.
  8708. *
  8709. * This routine handles an XRI abort event.
  8710. *
  8711. * Return: true if work posted to worker thread, otherwise false.
  8712. **/
  8713. static bool
  8714. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8715. struct lpfc_queue *cq,
  8716. struct sli4_wcqe_xri_aborted *wcqe)
  8717. {
  8718. bool workposted = false;
  8719. struct lpfc_cq_event *cq_event;
  8720. unsigned long iflags;
  8721. /* Allocate a new internal CQ_EVENT entry */
  8722. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8723. if (!cq_event) {
  8724. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8725. "0602 Failed to allocate CQ_EVENT entry\n");
  8726. return false;
  8727. }
  8728. /* Move the CQE into the proper xri abort event list */
  8729. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8730. switch (cq->subtype) {
  8731. case LPFC_FCP:
  8732. spin_lock_irqsave(&phba->hbalock, iflags);
  8733. list_add_tail(&cq_event->list,
  8734. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8735. /* Set the fcp xri abort event flag */
  8736. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8738. workposted = true;
  8739. break;
  8740. case LPFC_ELS:
  8741. spin_lock_irqsave(&phba->hbalock, iflags);
  8742. list_add_tail(&cq_event->list,
  8743. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8744. /* Set the els xri abort event flag */
  8745. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8746. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8747. workposted = true;
  8748. break;
  8749. default:
  8750. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8751. "0603 Invalid work queue CQE subtype (x%x)\n",
  8752. cq->subtype);
  8753. workposted = false;
  8754. break;
  8755. }
  8756. return workposted;
  8757. }
  8758. /**
  8759. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8760. * @phba: Pointer to HBA context object.
  8761. * @rcqe: Pointer to receive-queue completion queue entry.
  8762. *
  8763. * This routine process a receive-queue completion queue entry.
  8764. *
  8765. * Return: true if work posted to worker thread, otherwise false.
  8766. **/
  8767. static bool
  8768. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8769. {
  8770. bool workposted = false;
  8771. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8772. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8773. struct hbq_dmabuf *dma_buf;
  8774. uint32_t status;
  8775. unsigned long iflags;
  8776. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8777. goto out;
  8778. status = bf_get(lpfc_rcqe_status, rcqe);
  8779. switch (status) {
  8780. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8781. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8782. "2537 Receive Frame Truncated!!\n");
  8783. case FC_STATUS_RQ_SUCCESS:
  8784. lpfc_sli4_rq_release(hrq, drq);
  8785. spin_lock_irqsave(&phba->hbalock, iflags);
  8786. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8787. if (!dma_buf) {
  8788. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8789. goto out;
  8790. }
  8791. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8792. /* save off the frame for the word thread to process */
  8793. list_add_tail(&dma_buf->cq_event.list,
  8794. &phba->sli4_hba.sp_queue_event);
  8795. /* Frame received */
  8796. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8797. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8798. workposted = true;
  8799. break;
  8800. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8801. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8802. /* Post more buffers if possible */
  8803. spin_lock_irqsave(&phba->hbalock, iflags);
  8804. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8805. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8806. workposted = true;
  8807. break;
  8808. }
  8809. out:
  8810. return workposted;
  8811. }
  8812. /**
  8813. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8814. * @phba: Pointer to HBA context object.
  8815. * @cq: Pointer to the completion queue.
  8816. * @wcqe: Pointer to a completion queue entry.
  8817. *
  8818. * This routine process a slow-path work-queue or receive queue completion queue
  8819. * entry.
  8820. *
  8821. * Return: true if work posted to worker thread, otherwise false.
  8822. **/
  8823. static bool
  8824. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8825. struct lpfc_cqe *cqe)
  8826. {
  8827. struct lpfc_cqe cqevt;
  8828. bool workposted = false;
  8829. /* Copy the work queue CQE and convert endian order if needed */
  8830. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8831. /* Check and process for different type of WCQE and dispatch */
  8832. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8833. case CQE_CODE_COMPL_WQE:
  8834. /* Process the WQ/RQ complete event */
  8835. phba->last_completion_time = jiffies;
  8836. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8837. (struct lpfc_wcqe_complete *)&cqevt);
  8838. break;
  8839. case CQE_CODE_RELEASE_WQE:
  8840. /* Process the WQ release event */
  8841. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8842. (struct lpfc_wcqe_release *)&cqevt);
  8843. break;
  8844. case CQE_CODE_XRI_ABORTED:
  8845. /* Process the WQ XRI abort event */
  8846. phba->last_completion_time = jiffies;
  8847. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8848. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8849. break;
  8850. case CQE_CODE_RECEIVE:
  8851. /* Process the RQ event */
  8852. phba->last_completion_time = jiffies;
  8853. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8854. (struct lpfc_rcqe *)&cqevt);
  8855. break;
  8856. default:
  8857. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8858. "0388 Not a valid WCQE code: x%x\n",
  8859. bf_get(lpfc_cqe_code, &cqevt));
  8860. break;
  8861. }
  8862. return workposted;
  8863. }
  8864. /**
  8865. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8866. * @phba: Pointer to HBA context object.
  8867. * @eqe: Pointer to fast-path event queue entry.
  8868. *
  8869. * This routine process a event queue entry from the slow-path event queue.
  8870. * It will check the MajorCode and MinorCode to determine this is for a
  8871. * completion event on a completion queue, if not, an error shall be logged
  8872. * and just return. Otherwise, it will get to the corresponding completion
  8873. * queue and process all the entries on that completion queue, rearm the
  8874. * completion queue, and then return.
  8875. *
  8876. **/
  8877. static void
  8878. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8879. {
  8880. struct lpfc_queue *cq = NULL, *childq, *speq;
  8881. struct lpfc_cqe *cqe;
  8882. bool workposted = false;
  8883. int ecount = 0;
  8884. uint16_t cqid;
  8885. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8886. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8887. "0359 Not a valid slow-path completion "
  8888. "event: majorcode=x%x, minorcode=x%x\n",
  8889. bf_get_le32(lpfc_eqe_major_code, eqe),
  8890. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8891. return;
  8892. }
  8893. /* Get the reference to the corresponding CQ */
  8894. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8895. /* Search for completion queue pointer matching this cqid */
  8896. speq = phba->sli4_hba.sp_eq;
  8897. list_for_each_entry(childq, &speq->child_list, list) {
  8898. if (childq->queue_id == cqid) {
  8899. cq = childq;
  8900. break;
  8901. }
  8902. }
  8903. if (unlikely(!cq)) {
  8904. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8905. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8906. "0365 Slow-path CQ identifier "
  8907. "(%d) does not exist\n", cqid);
  8908. return;
  8909. }
  8910. /* Process all the entries to the CQ */
  8911. switch (cq->type) {
  8912. case LPFC_MCQ:
  8913. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8914. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8915. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8916. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8917. }
  8918. break;
  8919. case LPFC_WCQ:
  8920. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8921. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8922. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8923. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8924. }
  8925. break;
  8926. default:
  8927. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8928. "0370 Invalid completion queue type (%d)\n",
  8929. cq->type);
  8930. return;
  8931. }
  8932. /* Catch the no cq entry condition, log an error */
  8933. if (unlikely(ecount == 0))
  8934. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8935. "0371 No entry from the CQ: identifier "
  8936. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8937. /* In any case, flash and re-arm the RCQ */
  8938. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8939. /* wake up worker thread if there are works to be done */
  8940. if (workposted)
  8941. lpfc_worker_wake_up(phba);
  8942. }
  8943. /**
  8944. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8945. * @eqe: Pointer to fast-path completion queue entry.
  8946. *
  8947. * This routine process a fast-path work queue completion entry from fast-path
  8948. * event queue for FCP command response completion.
  8949. **/
  8950. static void
  8951. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8952. struct lpfc_wcqe_complete *wcqe)
  8953. {
  8954. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8955. struct lpfc_iocbq *cmdiocbq;
  8956. struct lpfc_iocbq irspiocbq;
  8957. unsigned long iflags;
  8958. spin_lock_irqsave(&phba->hbalock, iflags);
  8959. pring->stats.iocb_event++;
  8960. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8961. /* Check for response status */
  8962. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8963. /* If resource errors reported from HBA, reduce queue
  8964. * depth of the SCSI device.
  8965. */
  8966. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8967. IOSTAT_LOCAL_REJECT) &&
  8968. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8969. phba->lpfc_rampdown_queue_depth(phba);
  8970. }
  8971. /* Log the error status */
  8972. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8973. "0373 FCP complete error: status=x%x, "
  8974. "hw_status=x%x, total_data_specified=%d, "
  8975. "parameter=x%x, word3=x%x\n",
  8976. bf_get(lpfc_wcqe_c_status, wcqe),
  8977. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8978. wcqe->total_data_placed, wcqe->parameter,
  8979. wcqe->word3);
  8980. }
  8981. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8982. spin_lock_irqsave(&phba->hbalock, iflags);
  8983. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8984. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8986. if (unlikely(!cmdiocbq)) {
  8987. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8988. "0374 FCP complete with no corresponding "
  8989. "cmdiocb: iotag (%d)\n",
  8990. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8991. return;
  8992. }
  8993. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8994. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8995. "0375 FCP cmdiocb not callback function "
  8996. "iotag: (%d)\n",
  8997. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8998. return;
  8999. }
  9000. /* Fake the irspiocb and copy necessary response information */
  9001. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  9002. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  9003. spin_lock_irqsave(&phba->hbalock, iflags);
  9004. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  9005. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9006. }
  9007. /* Pass the cmd_iocb and the rsp state to the upper layer */
  9008. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  9009. }
  9010. /**
  9011. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  9012. * @phba: Pointer to HBA context object.
  9013. * @cq: Pointer to completion queue.
  9014. * @wcqe: Pointer to work-queue completion queue entry.
  9015. *
  9016. * This routine handles an fast-path WQ entry comsumed event by invoking the
  9017. * proper WQ release routine to the slow-path WQ.
  9018. **/
  9019. static void
  9020. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9021. struct lpfc_wcqe_release *wcqe)
  9022. {
  9023. struct lpfc_queue *childwq;
  9024. bool wqid_matched = false;
  9025. uint16_t fcp_wqid;
  9026. /* Check for fast-path FCP work queue release */
  9027. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  9028. list_for_each_entry(childwq, &cq->child_list, list) {
  9029. if (childwq->queue_id == fcp_wqid) {
  9030. lpfc_sli4_wq_release(childwq,
  9031. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  9032. wqid_matched = true;
  9033. break;
  9034. }
  9035. }
  9036. /* Report warning log message if no match found */
  9037. if (wqid_matched != true)
  9038. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9039. "2580 Fast-path wqe consume event carries "
  9040. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  9041. }
  9042. /**
  9043. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  9044. * @cq: Pointer to the completion queue.
  9045. * @eqe: Pointer to fast-path completion queue entry.
  9046. *
  9047. * This routine process a fast-path work queue completion entry from fast-path
  9048. * event queue for FCP command response completion.
  9049. **/
  9050. static int
  9051. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9052. struct lpfc_cqe *cqe)
  9053. {
  9054. struct lpfc_wcqe_release wcqe;
  9055. bool workposted = false;
  9056. /* Copy the work queue CQE and convert endian order if needed */
  9057. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  9058. /* Check and process for different type of WCQE and dispatch */
  9059. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  9060. case CQE_CODE_COMPL_WQE:
  9061. /* Process the WQ complete event */
  9062. phba->last_completion_time = jiffies;
  9063. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  9064. (struct lpfc_wcqe_complete *)&wcqe);
  9065. break;
  9066. case CQE_CODE_RELEASE_WQE:
  9067. /* Process the WQ release event */
  9068. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  9069. (struct lpfc_wcqe_release *)&wcqe);
  9070. break;
  9071. case CQE_CODE_XRI_ABORTED:
  9072. /* Process the WQ XRI abort event */
  9073. phba->last_completion_time = jiffies;
  9074. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  9075. (struct sli4_wcqe_xri_aborted *)&wcqe);
  9076. break;
  9077. default:
  9078. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9079. "0144 Not a valid WCQE code: x%x\n",
  9080. bf_get(lpfc_wcqe_c_code, &wcqe));
  9081. break;
  9082. }
  9083. return workposted;
  9084. }
  9085. /**
  9086. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  9087. * @phba: Pointer to HBA context object.
  9088. * @eqe: Pointer to fast-path event queue entry.
  9089. *
  9090. * This routine process a event queue entry from the fast-path event queue.
  9091. * It will check the MajorCode and MinorCode to determine this is for a
  9092. * completion event on a completion queue, if not, an error shall be logged
  9093. * and just return. Otherwise, it will get to the corresponding completion
  9094. * queue and process all the entries on the completion queue, rearm the
  9095. * completion queue, and then return.
  9096. **/
  9097. static void
  9098. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  9099. uint32_t fcp_cqidx)
  9100. {
  9101. struct lpfc_queue *cq;
  9102. struct lpfc_cqe *cqe;
  9103. bool workposted = false;
  9104. uint16_t cqid;
  9105. int ecount = 0;
  9106. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  9107. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9108. "0366 Not a valid fast-path completion "
  9109. "event: majorcode=x%x, minorcode=x%x\n",
  9110. bf_get_le32(lpfc_eqe_major_code, eqe),
  9111. bf_get_le32(lpfc_eqe_minor_code, eqe));
  9112. return;
  9113. }
  9114. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  9115. if (unlikely(!cq)) {
  9116. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  9117. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9118. "0367 Fast-path completion queue "
  9119. "does not exist\n");
  9120. return;
  9121. }
  9122. /* Get the reference to the corresponding CQ */
  9123. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  9124. if (unlikely(cqid != cq->queue_id)) {
  9125. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9126. "0368 Miss-matched fast-path completion "
  9127. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  9128. cqid, cq->queue_id);
  9129. return;
  9130. }
  9131. /* Process all the entries to the CQ */
  9132. while ((cqe = lpfc_sli4_cq_get(cq))) {
  9133. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  9134. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9135. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  9136. }
  9137. /* Catch the no cq entry condition */
  9138. if (unlikely(ecount == 0))
  9139. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9140. "0369 No entry from fast-path completion "
  9141. "queue fcpcqid=%d\n", cq->queue_id);
  9142. /* In any case, flash and re-arm the CQ */
  9143. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  9144. /* wake up worker thread if there are works to be done */
  9145. if (workposted)
  9146. lpfc_worker_wake_up(phba);
  9147. }
  9148. static void
  9149. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9150. {
  9151. struct lpfc_eqe *eqe;
  9152. /* walk all the EQ entries and drop on the floor */
  9153. while ((eqe = lpfc_sli4_eq_get(eq)))
  9154. ;
  9155. /* Clear and re-arm the EQ */
  9156. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  9157. }
  9158. /**
  9159. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  9160. * @irq: Interrupt number.
  9161. * @dev_id: The device context pointer.
  9162. *
  9163. * This function is directly called from the PCI layer as an interrupt
  9164. * service routine when device with SLI-4 interface spec is enabled with
  9165. * MSI-X multi-message interrupt mode and there are slow-path events in
  9166. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9167. * interrupt mode, this function is called as part of the device-level
  9168. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  9169. * undergoing initialization, the interrupt handler will not process the
  9170. * interrupt. The link attention and ELS ring attention events are handled
  9171. * by the worker thread. The interrupt handler signals the worker thread
  9172. * and returns for these events. This function is called without any lock
  9173. * held. It gets the hbalock to access and update SLI data structures.
  9174. *
  9175. * This function returns IRQ_HANDLED when interrupt is handled else it
  9176. * returns IRQ_NONE.
  9177. **/
  9178. irqreturn_t
  9179. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  9180. {
  9181. struct lpfc_hba *phba;
  9182. struct lpfc_queue *speq;
  9183. struct lpfc_eqe *eqe;
  9184. unsigned long iflag;
  9185. int ecount = 0;
  9186. /*
  9187. * Get the driver's phba structure from the dev_id
  9188. */
  9189. phba = (struct lpfc_hba *)dev_id;
  9190. if (unlikely(!phba))
  9191. return IRQ_NONE;
  9192. /* Get to the EQ struct associated with this vector */
  9193. speq = phba->sli4_hba.sp_eq;
  9194. /* Check device state for handling interrupt */
  9195. if (unlikely(lpfc_intr_state_check(phba))) {
  9196. /* Check again for link_state with lock held */
  9197. spin_lock_irqsave(&phba->hbalock, iflag);
  9198. if (phba->link_state < LPFC_LINK_DOWN)
  9199. /* Flush, clear interrupt, and rearm the EQ */
  9200. lpfc_sli4_eq_flush(phba, speq);
  9201. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9202. return IRQ_NONE;
  9203. }
  9204. /*
  9205. * Process all the event on FCP slow-path EQ
  9206. */
  9207. while ((eqe = lpfc_sli4_eq_get(speq))) {
  9208. lpfc_sli4_sp_handle_eqe(phba, eqe);
  9209. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9210. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  9211. }
  9212. /* Always clear and re-arm the slow-path EQ */
  9213. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  9214. /* Catch the no cq entry condition */
  9215. if (unlikely(ecount == 0)) {
  9216. if (phba->intr_type == MSIX)
  9217. /* MSI-X treated interrupt served as no EQ share INT */
  9218. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9219. "0357 MSI-X interrupt with no EQE\n");
  9220. else
  9221. /* Non MSI-X treated on interrupt as EQ share INT */
  9222. return IRQ_NONE;
  9223. }
  9224. return IRQ_HANDLED;
  9225. } /* lpfc_sli4_sp_intr_handler */
  9226. /**
  9227. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  9228. * @irq: Interrupt number.
  9229. * @dev_id: The device context pointer.
  9230. *
  9231. * This function is directly called from the PCI layer as an interrupt
  9232. * service routine when device with SLI-4 interface spec is enabled with
  9233. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9234. * ring event in the HBA. However, when the device is enabled with either
  9235. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9236. * device-level interrupt handler. When the PCI slot is in error recovery
  9237. * or the HBA is undergoing initialization, the interrupt handler will not
  9238. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9239. * the intrrupt context. This function is called without any lock held.
  9240. * It gets the hbalock to access and update SLI data structures. Note that,
  9241. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  9242. * equal to that of FCP CQ index.
  9243. *
  9244. * This function returns IRQ_HANDLED when interrupt is handled else it
  9245. * returns IRQ_NONE.
  9246. **/
  9247. irqreturn_t
  9248. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  9249. {
  9250. struct lpfc_hba *phba;
  9251. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  9252. struct lpfc_queue *fpeq;
  9253. struct lpfc_eqe *eqe;
  9254. unsigned long iflag;
  9255. int ecount = 0;
  9256. uint32_t fcp_eqidx;
  9257. /* Get the driver's phba structure from the dev_id */
  9258. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  9259. phba = fcp_eq_hdl->phba;
  9260. fcp_eqidx = fcp_eq_hdl->idx;
  9261. if (unlikely(!phba))
  9262. return IRQ_NONE;
  9263. /* Get to the EQ struct associated with this vector */
  9264. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  9265. /* Check device state for handling interrupt */
  9266. if (unlikely(lpfc_intr_state_check(phba))) {
  9267. /* Check again for link_state with lock held */
  9268. spin_lock_irqsave(&phba->hbalock, iflag);
  9269. if (phba->link_state < LPFC_LINK_DOWN)
  9270. /* Flush, clear interrupt, and rearm the EQ */
  9271. lpfc_sli4_eq_flush(phba, fpeq);
  9272. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9273. return IRQ_NONE;
  9274. }
  9275. /*
  9276. * Process all the event on FCP fast-path EQ
  9277. */
  9278. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  9279. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  9280. if (!(++ecount % LPFC_GET_QE_REL_INT))
  9281. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  9282. }
  9283. /* Always clear and re-arm the fast-path EQ */
  9284. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  9285. if (unlikely(ecount == 0)) {
  9286. if (phba->intr_type == MSIX)
  9287. /* MSI-X treated interrupt served as no EQ share INT */
  9288. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9289. "0358 MSI-X interrupt with no EQE\n");
  9290. else
  9291. /* Non MSI-X treated on interrupt as EQ share INT */
  9292. return IRQ_NONE;
  9293. }
  9294. return IRQ_HANDLED;
  9295. } /* lpfc_sli4_fp_intr_handler */
  9296. /**
  9297. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  9298. * @irq: Interrupt number.
  9299. * @dev_id: The device context pointer.
  9300. *
  9301. * This function is the device-level interrupt handler to device with SLI-4
  9302. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  9303. * interrupt mode is enabled and there is an event in the HBA which requires
  9304. * driver attention. This function invokes the slow-path interrupt attention
  9305. * handling function and fast-path interrupt attention handling function in
  9306. * turn to process the relevant HBA attention events. This function is called
  9307. * without any lock held. It gets the hbalock to access and update SLI data
  9308. * structures.
  9309. *
  9310. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9311. * returns IRQ_NONE.
  9312. **/
  9313. irqreturn_t
  9314. lpfc_sli4_intr_handler(int irq, void *dev_id)
  9315. {
  9316. struct lpfc_hba *phba;
  9317. irqreturn_t sp_irq_rc, fp_irq_rc;
  9318. bool fp_handled = false;
  9319. uint32_t fcp_eqidx;
  9320. /* Get the driver's phba structure from the dev_id */
  9321. phba = (struct lpfc_hba *)dev_id;
  9322. if (unlikely(!phba))
  9323. return IRQ_NONE;
  9324. /*
  9325. * Invokes slow-path host attention interrupt handling as appropriate.
  9326. */
  9327. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  9328. /*
  9329. * Invoke fast-path host attention interrupt handling as appropriate.
  9330. */
  9331. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  9332. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  9333. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  9334. if (fp_irq_rc == IRQ_HANDLED)
  9335. fp_handled |= true;
  9336. }
  9337. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  9338. } /* lpfc_sli4_intr_handler */
  9339. /**
  9340. * lpfc_sli4_queue_free - free a queue structure and associated memory
  9341. * @queue: The queue structure to free.
  9342. *
  9343. * This function frees a queue structure and the DMAable memory used for
  9344. * the host resident queue. This function must be called after destroying the
  9345. * queue on the HBA.
  9346. **/
  9347. void
  9348. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  9349. {
  9350. struct lpfc_dmabuf *dmabuf;
  9351. if (!queue)
  9352. return;
  9353. while (!list_empty(&queue->page_list)) {
  9354. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  9355. list);
  9356. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  9357. dmabuf->virt, dmabuf->phys);
  9358. kfree(dmabuf);
  9359. }
  9360. kfree(queue);
  9361. return;
  9362. }
  9363. /**
  9364. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  9365. * @phba: The HBA that this queue is being created on.
  9366. * @entry_size: The size of each queue entry for this queue.
  9367. * @entry count: The number of entries that this queue will handle.
  9368. *
  9369. * This function allocates a queue structure and the DMAable memory used for
  9370. * the host resident queue. This function must be called before creating the
  9371. * queue on the HBA.
  9372. **/
  9373. struct lpfc_queue *
  9374. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  9375. uint32_t entry_count)
  9376. {
  9377. struct lpfc_queue *queue;
  9378. struct lpfc_dmabuf *dmabuf;
  9379. int x, total_qe_count;
  9380. void *dma_pointer;
  9381. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9382. if (!phba->sli4_hba.pc_sli4_params.supported)
  9383. hw_page_size = SLI4_PAGE_SIZE;
  9384. queue = kzalloc(sizeof(struct lpfc_queue) +
  9385. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  9386. if (!queue)
  9387. return NULL;
  9388. queue->page_count = (ALIGN(entry_size * entry_count,
  9389. hw_page_size))/hw_page_size;
  9390. INIT_LIST_HEAD(&queue->list);
  9391. INIT_LIST_HEAD(&queue->page_list);
  9392. INIT_LIST_HEAD(&queue->child_list);
  9393. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  9394. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  9395. if (!dmabuf)
  9396. goto out_fail;
  9397. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  9398. hw_page_size, &dmabuf->phys,
  9399. GFP_KERNEL);
  9400. if (!dmabuf->virt) {
  9401. kfree(dmabuf);
  9402. goto out_fail;
  9403. }
  9404. memset(dmabuf->virt, 0, hw_page_size);
  9405. dmabuf->buffer_tag = x;
  9406. list_add_tail(&dmabuf->list, &queue->page_list);
  9407. /* initialize queue's entry array */
  9408. dma_pointer = dmabuf->virt;
  9409. for (; total_qe_count < entry_count &&
  9410. dma_pointer < (hw_page_size + dmabuf->virt);
  9411. total_qe_count++, dma_pointer += entry_size) {
  9412. queue->qe[total_qe_count].address = dma_pointer;
  9413. }
  9414. }
  9415. queue->entry_size = entry_size;
  9416. queue->entry_count = entry_count;
  9417. queue->phba = phba;
  9418. return queue;
  9419. out_fail:
  9420. lpfc_sli4_queue_free(queue);
  9421. return NULL;
  9422. }
  9423. /**
  9424. * lpfc_eq_create - Create an Event Queue on the HBA
  9425. * @phba: HBA structure that indicates port to create a queue on.
  9426. * @eq: The queue structure to use to create the event queue.
  9427. * @imax: The maximum interrupt per second limit.
  9428. *
  9429. * This function creates an event queue, as detailed in @eq, on a port,
  9430. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  9431. *
  9432. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  9433. * is used to get the entry count and entry size that are necessary to
  9434. * determine the number of pages to allocate and use for this queue. This
  9435. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  9436. * event queue. This function is asynchronous and will wait for the mailbox
  9437. * command to finish before continuing.
  9438. *
  9439. * On success this function will return a zero. If unable to allocate enough
  9440. * memory this function will return -ENOMEM. If the queue create mailbox command
  9441. * fails this function will return -ENXIO.
  9442. **/
  9443. uint32_t
  9444. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  9445. {
  9446. struct lpfc_mbx_eq_create *eq_create;
  9447. LPFC_MBOXQ_t *mbox;
  9448. int rc, length, status = 0;
  9449. struct lpfc_dmabuf *dmabuf;
  9450. uint32_t shdr_status, shdr_add_status;
  9451. union lpfc_sli4_cfg_shdr *shdr;
  9452. uint16_t dmult;
  9453. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9454. if (!phba->sli4_hba.pc_sli4_params.supported)
  9455. hw_page_size = SLI4_PAGE_SIZE;
  9456. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9457. if (!mbox)
  9458. return -ENOMEM;
  9459. length = (sizeof(struct lpfc_mbx_eq_create) -
  9460. sizeof(struct lpfc_sli4_cfg_mhdr));
  9461. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9462. LPFC_MBOX_OPCODE_EQ_CREATE,
  9463. length, LPFC_SLI4_MBX_EMBED);
  9464. eq_create = &mbox->u.mqe.un.eq_create;
  9465. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9466. eq->page_count);
  9467. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9468. LPFC_EQE_SIZE);
  9469. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9470. /* Calculate delay multiper from maximum interrupt per second */
  9471. dmult = LPFC_DMULT_CONST/imax - 1;
  9472. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9473. dmult);
  9474. switch (eq->entry_count) {
  9475. default:
  9476. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9477. "0360 Unsupported EQ count. (%d)\n",
  9478. eq->entry_count);
  9479. if (eq->entry_count < 256)
  9480. return -EINVAL;
  9481. /* otherwise default to smallest count (drop through) */
  9482. case 256:
  9483. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9484. LPFC_EQ_CNT_256);
  9485. break;
  9486. case 512:
  9487. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9488. LPFC_EQ_CNT_512);
  9489. break;
  9490. case 1024:
  9491. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9492. LPFC_EQ_CNT_1024);
  9493. break;
  9494. case 2048:
  9495. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9496. LPFC_EQ_CNT_2048);
  9497. break;
  9498. case 4096:
  9499. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9500. LPFC_EQ_CNT_4096);
  9501. break;
  9502. }
  9503. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9504. memset(dmabuf->virt, 0, hw_page_size);
  9505. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9506. putPaddrLow(dmabuf->phys);
  9507. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9508. putPaddrHigh(dmabuf->phys);
  9509. }
  9510. mbox->vport = phba->pport;
  9511. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9512. mbox->context1 = NULL;
  9513. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9514. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9515. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9516. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9517. if (shdr_status || shdr_add_status || rc) {
  9518. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9519. "2500 EQ_CREATE mailbox failed with "
  9520. "status x%x add_status x%x, mbx status x%x\n",
  9521. shdr_status, shdr_add_status, rc);
  9522. status = -ENXIO;
  9523. }
  9524. eq->type = LPFC_EQ;
  9525. eq->subtype = LPFC_NONE;
  9526. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9527. if (eq->queue_id == 0xFFFF)
  9528. status = -ENXIO;
  9529. eq->host_index = 0;
  9530. eq->hba_index = 0;
  9531. mempool_free(mbox, phba->mbox_mem_pool);
  9532. return status;
  9533. }
  9534. /**
  9535. * lpfc_cq_create - Create a Completion Queue on the HBA
  9536. * @phba: HBA structure that indicates port to create a queue on.
  9537. * @cq: The queue structure to use to create the completion queue.
  9538. * @eq: The event queue to bind this completion queue to.
  9539. *
  9540. * This function creates a completion queue, as detailed in @wq, on a port,
  9541. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9542. *
  9543. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9544. * is used to get the entry count and entry size that are necessary to
  9545. * determine the number of pages to allocate and use for this queue. The @eq
  9546. * is used to indicate which event queue to bind this completion queue to. This
  9547. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9548. * completion queue. This function is asynchronous and will wait for the mailbox
  9549. * command to finish before continuing.
  9550. *
  9551. * On success this function will return a zero. If unable to allocate enough
  9552. * memory this function will return -ENOMEM. If the queue create mailbox command
  9553. * fails this function will return -ENXIO.
  9554. **/
  9555. uint32_t
  9556. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9557. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9558. {
  9559. struct lpfc_mbx_cq_create *cq_create;
  9560. struct lpfc_dmabuf *dmabuf;
  9561. LPFC_MBOXQ_t *mbox;
  9562. int rc, length, status = 0;
  9563. uint32_t shdr_status, shdr_add_status;
  9564. union lpfc_sli4_cfg_shdr *shdr;
  9565. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9566. if (!phba->sli4_hba.pc_sli4_params.supported)
  9567. hw_page_size = SLI4_PAGE_SIZE;
  9568. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9569. if (!mbox)
  9570. return -ENOMEM;
  9571. length = (sizeof(struct lpfc_mbx_cq_create) -
  9572. sizeof(struct lpfc_sli4_cfg_mhdr));
  9573. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9574. LPFC_MBOX_OPCODE_CQ_CREATE,
  9575. length, LPFC_SLI4_MBX_EMBED);
  9576. cq_create = &mbox->u.mqe.un.cq_create;
  9577. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9578. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9579. cq->page_count);
  9580. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9581. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9582. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9583. phba->sli4_hba.pc_sli4_params.cqv);
  9584. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  9585. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
  9586. (PAGE_SIZE/SLI4_PAGE_SIZE));
  9587. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  9588. eq->queue_id);
  9589. } else {
  9590. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  9591. eq->queue_id);
  9592. }
  9593. switch (cq->entry_count) {
  9594. default:
  9595. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9596. "0361 Unsupported CQ count. (%d)\n",
  9597. cq->entry_count);
  9598. if (cq->entry_count < 256)
  9599. return -EINVAL;
  9600. /* otherwise default to smallest count (drop through) */
  9601. case 256:
  9602. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9603. LPFC_CQ_CNT_256);
  9604. break;
  9605. case 512:
  9606. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9607. LPFC_CQ_CNT_512);
  9608. break;
  9609. case 1024:
  9610. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9611. LPFC_CQ_CNT_1024);
  9612. break;
  9613. }
  9614. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9615. memset(dmabuf->virt, 0, hw_page_size);
  9616. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9617. putPaddrLow(dmabuf->phys);
  9618. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9619. putPaddrHigh(dmabuf->phys);
  9620. }
  9621. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9622. /* The IOCTL status is embedded in the mailbox subheader. */
  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. "2501 CQ_CREATE mailbox failed with "
  9628. "status x%x add_status x%x, mbx status x%x\n",
  9629. shdr_status, shdr_add_status, rc);
  9630. status = -ENXIO;
  9631. goto out;
  9632. }
  9633. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9634. if (cq->queue_id == 0xFFFF) {
  9635. status = -ENXIO;
  9636. goto out;
  9637. }
  9638. /* link the cq onto the parent eq child list */
  9639. list_add_tail(&cq->list, &eq->child_list);
  9640. /* Set up completion queue's type and subtype */
  9641. cq->type = type;
  9642. cq->subtype = subtype;
  9643. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9644. cq->assoc_qid = eq->queue_id;
  9645. cq->host_index = 0;
  9646. cq->hba_index = 0;
  9647. out:
  9648. mempool_free(mbox, phba->mbox_mem_pool);
  9649. return status;
  9650. }
  9651. /**
  9652. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9653. * @phba: HBA structure that indicates port to create a queue on.
  9654. * @mq: The queue structure to use to create the mailbox queue.
  9655. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9656. * @cq: The completion queue to associate with this cq.
  9657. *
  9658. * This function provides failback (fb) functionality when the
  9659. * mq_create_ext fails on older FW generations. It's purpose is identical
  9660. * to mq_create_ext otherwise.
  9661. *
  9662. * This routine cannot fail as all attributes were previously accessed and
  9663. * initialized in mq_create_ext.
  9664. **/
  9665. static void
  9666. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9667. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9668. {
  9669. struct lpfc_mbx_mq_create *mq_create;
  9670. struct lpfc_dmabuf *dmabuf;
  9671. int length;
  9672. length = (sizeof(struct lpfc_mbx_mq_create) -
  9673. sizeof(struct lpfc_sli4_cfg_mhdr));
  9674. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9675. LPFC_MBOX_OPCODE_MQ_CREATE,
  9676. length, LPFC_SLI4_MBX_EMBED);
  9677. mq_create = &mbox->u.mqe.un.mq_create;
  9678. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9679. mq->page_count);
  9680. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9681. cq->queue_id);
  9682. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9683. switch (mq->entry_count) {
  9684. case 16:
  9685. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9686. LPFC_MQ_RING_SIZE_16);
  9687. break;
  9688. case 32:
  9689. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9690. LPFC_MQ_RING_SIZE_32);
  9691. break;
  9692. case 64:
  9693. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9694. LPFC_MQ_RING_SIZE_64);
  9695. break;
  9696. case 128:
  9697. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  9698. LPFC_MQ_RING_SIZE_128);
  9699. break;
  9700. }
  9701. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9702. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9703. putPaddrLow(dmabuf->phys);
  9704. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9705. putPaddrHigh(dmabuf->phys);
  9706. }
  9707. }
  9708. /**
  9709. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9710. * @phba: HBA structure that indicates port to create a queue on.
  9711. * @mq: The queue structure to use to create the mailbox queue.
  9712. * @cq: The completion queue to associate with this cq.
  9713. * @subtype: The queue's subtype.
  9714. *
  9715. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9716. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9717. *
  9718. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9719. * is used to get the entry count and entry size that are necessary to
  9720. * determine the number of pages to allocate and use for this queue. This
  9721. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9722. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9723. * command to finish before continuing.
  9724. *
  9725. * On success this function will return a zero. If unable to allocate enough
  9726. * memory this function will return -ENOMEM. If the queue create mailbox command
  9727. * fails this function will return -ENXIO.
  9728. **/
  9729. int32_t
  9730. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9731. struct lpfc_queue *cq, uint32_t subtype)
  9732. {
  9733. struct lpfc_mbx_mq_create *mq_create;
  9734. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9735. struct lpfc_dmabuf *dmabuf;
  9736. LPFC_MBOXQ_t *mbox;
  9737. int rc, length, status = 0;
  9738. uint32_t shdr_status, shdr_add_status;
  9739. union lpfc_sli4_cfg_shdr *shdr;
  9740. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9741. if (!phba->sli4_hba.pc_sli4_params.supported)
  9742. hw_page_size = SLI4_PAGE_SIZE;
  9743. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9744. if (!mbox)
  9745. return -ENOMEM;
  9746. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9747. sizeof(struct lpfc_sli4_cfg_mhdr));
  9748. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9749. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9750. length, LPFC_SLI4_MBX_EMBED);
  9751. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9752. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9753. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  9754. &mq_create_ext->u.request, mq->page_count);
  9755. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  9756. &mq_create_ext->u.request, 1);
  9757. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  9758. &mq_create_ext->u.request, 1);
  9759. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9760. &mq_create_ext->u.request, 1);
  9761. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  9762. &mq_create_ext->u.request, 1);
  9763. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  9764. &mq_create_ext->u.request, 1);
  9765. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9766. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9767. phba->sli4_hba.pc_sli4_params.mqv);
  9768. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  9769. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  9770. cq->queue_id);
  9771. else
  9772. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9773. cq->queue_id);
  9774. switch (mq->entry_count) {
  9775. default:
  9776. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9777. "0362 Unsupported MQ count. (%d)\n",
  9778. mq->entry_count);
  9779. if (mq->entry_count < 16)
  9780. return -EINVAL;
  9781. /* otherwise default to smallest count (drop through) */
  9782. case 16:
  9783. bf_set(lpfc_mq_context_ring_size,
  9784. &mq_create_ext->u.request.context,
  9785. LPFC_MQ_RING_SIZE_16);
  9786. break;
  9787. case 32:
  9788. bf_set(lpfc_mq_context_ring_size,
  9789. &mq_create_ext->u.request.context,
  9790. LPFC_MQ_RING_SIZE_32);
  9791. break;
  9792. case 64:
  9793. bf_set(lpfc_mq_context_ring_size,
  9794. &mq_create_ext->u.request.context,
  9795. LPFC_MQ_RING_SIZE_64);
  9796. break;
  9797. case 128:
  9798. bf_set(lpfc_mq_context_ring_size,
  9799. &mq_create_ext->u.request.context,
  9800. LPFC_MQ_RING_SIZE_128);
  9801. break;
  9802. }
  9803. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9804. memset(dmabuf->virt, 0, hw_page_size);
  9805. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9806. putPaddrLow(dmabuf->phys);
  9807. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9808. putPaddrHigh(dmabuf->phys);
  9809. }
  9810. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9811. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9812. &mq_create_ext->u.response);
  9813. if (rc != MBX_SUCCESS) {
  9814. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9815. "2795 MQ_CREATE_EXT failed with "
  9816. "status x%x. Failback to MQ_CREATE.\n",
  9817. rc);
  9818. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9819. mq_create = &mbox->u.mqe.un.mq_create;
  9820. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9821. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9822. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9823. &mq_create->u.response);
  9824. }
  9825. /* The IOCTL status is embedded in the mailbox subheader. */
  9826. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9827. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9828. if (shdr_status || shdr_add_status || rc) {
  9829. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9830. "2502 MQ_CREATE mailbox failed with "
  9831. "status x%x add_status x%x, mbx status x%x\n",
  9832. shdr_status, shdr_add_status, rc);
  9833. status = -ENXIO;
  9834. goto out;
  9835. }
  9836. if (mq->queue_id == 0xFFFF) {
  9837. status = -ENXIO;
  9838. goto out;
  9839. }
  9840. mq->type = LPFC_MQ;
  9841. mq->assoc_qid = cq->queue_id;
  9842. mq->subtype = subtype;
  9843. mq->host_index = 0;
  9844. mq->hba_index = 0;
  9845. /* link the mq onto the parent cq child list */
  9846. list_add_tail(&mq->list, &cq->child_list);
  9847. out:
  9848. mempool_free(mbox, phba->mbox_mem_pool);
  9849. return status;
  9850. }
  9851. /**
  9852. * lpfc_wq_create - Create a Work Queue on the HBA
  9853. * @phba: HBA structure that indicates port to create a queue on.
  9854. * @wq: The queue structure to use to create the work queue.
  9855. * @cq: The completion queue to bind this work queue to.
  9856. * @subtype: The subtype of the work queue indicating its functionality.
  9857. *
  9858. * This function creates a work queue, as detailed in @wq, on a port, described
  9859. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9860. *
  9861. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9862. * is used to get the entry count and entry size that are necessary to
  9863. * determine the number of pages to allocate and use for this queue. The @cq
  9864. * is used to indicate which completion queue to bind this work queue to. This
  9865. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9866. * work queue. This function is asynchronous and will wait for the mailbox
  9867. * command to finish before continuing.
  9868. *
  9869. * On success this function will return a zero. If unable to allocate enough
  9870. * memory this function will return -ENOMEM. If the queue create mailbox command
  9871. * fails this function will return -ENXIO.
  9872. **/
  9873. uint32_t
  9874. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9875. struct lpfc_queue *cq, uint32_t subtype)
  9876. {
  9877. struct lpfc_mbx_wq_create *wq_create;
  9878. struct lpfc_dmabuf *dmabuf;
  9879. LPFC_MBOXQ_t *mbox;
  9880. int rc, length, status = 0;
  9881. uint32_t shdr_status, shdr_add_status;
  9882. union lpfc_sli4_cfg_shdr *shdr;
  9883. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9884. struct dma_address *page;
  9885. if (!phba->sli4_hba.pc_sli4_params.supported)
  9886. hw_page_size = SLI4_PAGE_SIZE;
  9887. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9888. if (!mbox)
  9889. return -ENOMEM;
  9890. length = (sizeof(struct lpfc_mbx_wq_create) -
  9891. sizeof(struct lpfc_sli4_cfg_mhdr));
  9892. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9893. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9894. length, LPFC_SLI4_MBX_EMBED);
  9895. wq_create = &mbox->u.mqe.un.wq_create;
  9896. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9897. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9898. wq->page_count);
  9899. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9900. cq->queue_id);
  9901. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  9902. phba->sli4_hba.pc_sli4_params.wqv);
  9903. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  9904. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  9905. wq->entry_count);
  9906. switch (wq->entry_size) {
  9907. default:
  9908. case 64:
  9909. bf_set(lpfc_mbx_wq_create_wqe_size,
  9910. &wq_create->u.request_1,
  9911. LPFC_WQ_WQE_SIZE_64);
  9912. break;
  9913. case 128:
  9914. bf_set(lpfc_mbx_wq_create_wqe_size,
  9915. &wq_create->u.request_1,
  9916. LPFC_WQ_WQE_SIZE_128);
  9917. break;
  9918. }
  9919. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  9920. (PAGE_SIZE/SLI4_PAGE_SIZE));
  9921. page = wq_create->u.request_1.page;
  9922. } else {
  9923. page = wq_create->u.request.page;
  9924. }
  9925. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9926. memset(dmabuf->virt, 0, hw_page_size);
  9927. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  9928. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  9929. }
  9930. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9931. /* The IOCTL status is embedded in the mailbox subheader. */
  9932. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9933. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9934. if (shdr_status || shdr_add_status || rc) {
  9935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9936. "2503 WQ_CREATE mailbox failed with "
  9937. "status x%x add_status x%x, mbx status x%x\n",
  9938. shdr_status, shdr_add_status, rc);
  9939. status = -ENXIO;
  9940. goto out;
  9941. }
  9942. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9943. if (wq->queue_id == 0xFFFF) {
  9944. status = -ENXIO;
  9945. goto out;
  9946. }
  9947. wq->type = LPFC_WQ;
  9948. wq->assoc_qid = cq->queue_id;
  9949. wq->subtype = subtype;
  9950. wq->host_index = 0;
  9951. wq->hba_index = 0;
  9952. /* link the wq onto the parent cq child list */
  9953. list_add_tail(&wq->list, &cq->child_list);
  9954. out:
  9955. mempool_free(mbox, phba->mbox_mem_pool);
  9956. return status;
  9957. }
  9958. /**
  9959. * lpfc_rq_create - Create a Receive Queue on the HBA
  9960. * @phba: HBA structure that indicates port to create a queue on.
  9961. * @hrq: The queue structure to use to create the header receive queue.
  9962. * @drq: The queue structure to use to create the data receive queue.
  9963. * @cq: The completion queue to bind this work queue to.
  9964. *
  9965. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9966. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9967. * to the HBA.
  9968. *
  9969. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9970. * struct is used to get the entry count that is necessary to determine the
  9971. * number of pages to use for this queue. The @cq is used to indicate which
  9972. * completion queue to bind received buffers that are posted to these queues to.
  9973. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9974. * receive queue pair. This function is asynchronous and will wait for the
  9975. * mailbox command to finish before continuing.
  9976. *
  9977. * On success this function will return a zero. If unable to allocate enough
  9978. * memory this function will return -ENOMEM. If the queue create mailbox command
  9979. * fails this function will return -ENXIO.
  9980. **/
  9981. uint32_t
  9982. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9983. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9984. {
  9985. struct lpfc_mbx_rq_create *rq_create;
  9986. struct lpfc_dmabuf *dmabuf;
  9987. LPFC_MBOXQ_t *mbox;
  9988. int rc, length, status = 0;
  9989. uint32_t shdr_status, shdr_add_status;
  9990. union lpfc_sli4_cfg_shdr *shdr;
  9991. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9992. if (!phba->sli4_hba.pc_sli4_params.supported)
  9993. hw_page_size = SLI4_PAGE_SIZE;
  9994. if (hrq->entry_count != drq->entry_count)
  9995. return -EINVAL;
  9996. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9997. if (!mbox)
  9998. return -ENOMEM;
  9999. length = (sizeof(struct lpfc_mbx_rq_create) -
  10000. sizeof(struct lpfc_sli4_cfg_mhdr));
  10001. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10002. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10003. length, LPFC_SLI4_MBX_EMBED);
  10004. rq_create = &mbox->u.mqe.un.rq_create;
  10005. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10006. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10007. phba->sli4_hba.pc_sli4_params.rqv);
  10008. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10009. bf_set(lpfc_rq_context_rqe_count_1,
  10010. &rq_create->u.request.context,
  10011. hrq->entry_count);
  10012. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  10013. } else {
  10014. switch (hrq->entry_count) {
  10015. default:
  10016. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10017. "2535 Unsupported RQ count. (%d)\n",
  10018. hrq->entry_count);
  10019. if (hrq->entry_count < 512)
  10020. return -EINVAL;
  10021. /* otherwise default to smallest count (drop through) */
  10022. case 512:
  10023. bf_set(lpfc_rq_context_rqe_count,
  10024. &rq_create->u.request.context,
  10025. LPFC_RQ_RING_SIZE_512);
  10026. break;
  10027. case 1024:
  10028. bf_set(lpfc_rq_context_rqe_count,
  10029. &rq_create->u.request.context,
  10030. LPFC_RQ_RING_SIZE_1024);
  10031. break;
  10032. case 2048:
  10033. bf_set(lpfc_rq_context_rqe_count,
  10034. &rq_create->u.request.context,
  10035. LPFC_RQ_RING_SIZE_2048);
  10036. break;
  10037. case 4096:
  10038. bf_set(lpfc_rq_context_rqe_count,
  10039. &rq_create->u.request.context,
  10040. LPFC_RQ_RING_SIZE_4096);
  10041. break;
  10042. }
  10043. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10044. LPFC_HDR_BUF_SIZE);
  10045. }
  10046. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10047. cq->queue_id);
  10048. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10049. hrq->page_count);
  10050. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  10051. memset(dmabuf->virt, 0, hw_page_size);
  10052. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10053. putPaddrLow(dmabuf->phys);
  10054. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10055. putPaddrHigh(dmabuf->phys);
  10056. }
  10057. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10058. /* The IOCTL status is embedded in the mailbox subheader. */
  10059. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10060. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10061. if (shdr_status || shdr_add_status || rc) {
  10062. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10063. "2504 RQ_CREATE mailbox failed with "
  10064. "status x%x add_status x%x, mbx status x%x\n",
  10065. shdr_status, shdr_add_status, rc);
  10066. status = -ENXIO;
  10067. goto out;
  10068. }
  10069. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10070. if (hrq->queue_id == 0xFFFF) {
  10071. status = -ENXIO;
  10072. goto out;
  10073. }
  10074. hrq->type = LPFC_HRQ;
  10075. hrq->assoc_qid = cq->queue_id;
  10076. hrq->subtype = subtype;
  10077. hrq->host_index = 0;
  10078. hrq->hba_index = 0;
  10079. /* now create the data queue */
  10080. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10081. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  10082. length, LPFC_SLI4_MBX_EMBED);
  10083. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10084. phba->sli4_hba.pc_sli4_params.rqv);
  10085. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  10086. bf_set(lpfc_rq_context_rqe_count_1,
  10087. &rq_create->u.request.context,
  10088. hrq->entry_count);
  10089. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  10090. } else {
  10091. switch (drq->entry_count) {
  10092. default:
  10093. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10094. "2536 Unsupported RQ count. (%d)\n",
  10095. drq->entry_count);
  10096. if (drq->entry_count < 512)
  10097. return -EINVAL;
  10098. /* otherwise default to smallest count (drop through) */
  10099. case 512:
  10100. bf_set(lpfc_rq_context_rqe_count,
  10101. &rq_create->u.request.context,
  10102. LPFC_RQ_RING_SIZE_512);
  10103. break;
  10104. case 1024:
  10105. bf_set(lpfc_rq_context_rqe_count,
  10106. &rq_create->u.request.context,
  10107. LPFC_RQ_RING_SIZE_1024);
  10108. break;
  10109. case 2048:
  10110. bf_set(lpfc_rq_context_rqe_count,
  10111. &rq_create->u.request.context,
  10112. LPFC_RQ_RING_SIZE_2048);
  10113. break;
  10114. case 4096:
  10115. bf_set(lpfc_rq_context_rqe_count,
  10116. &rq_create->u.request.context,
  10117. LPFC_RQ_RING_SIZE_4096);
  10118. break;
  10119. }
  10120. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  10121. LPFC_DATA_BUF_SIZE);
  10122. }
  10123. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  10124. cq->queue_id);
  10125. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  10126. drq->page_count);
  10127. list_for_each_entry(dmabuf, &drq->page_list, list) {
  10128. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10129. putPaddrLow(dmabuf->phys);
  10130. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10131. putPaddrHigh(dmabuf->phys);
  10132. }
  10133. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10134. /* The IOCTL status is embedded in the mailbox subheader. */
  10135. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  10136. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10137. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10138. if (shdr_status || shdr_add_status || rc) {
  10139. status = -ENXIO;
  10140. goto out;
  10141. }
  10142. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  10143. if (drq->queue_id == 0xFFFF) {
  10144. status = -ENXIO;
  10145. goto out;
  10146. }
  10147. drq->type = LPFC_DRQ;
  10148. drq->assoc_qid = cq->queue_id;
  10149. drq->subtype = subtype;
  10150. drq->host_index = 0;
  10151. drq->hba_index = 0;
  10152. /* link the header and data RQs onto the parent cq child list */
  10153. list_add_tail(&hrq->list, &cq->child_list);
  10154. list_add_tail(&drq->list, &cq->child_list);
  10155. out:
  10156. mempool_free(mbox, phba->mbox_mem_pool);
  10157. return status;
  10158. }
  10159. /**
  10160. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  10161. * @eq: The queue structure associated with the queue to destroy.
  10162. *
  10163. * This function destroys a queue, as detailed in @eq by sending an mailbox
  10164. * command, specific to the type of queue, to the HBA.
  10165. *
  10166. * The @eq struct is used to get the queue ID of the queue to destroy.
  10167. *
  10168. * On success this function will return a zero. If the queue destroy mailbox
  10169. * command fails this function will return -ENXIO.
  10170. **/
  10171. uint32_t
  10172. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10173. {
  10174. LPFC_MBOXQ_t *mbox;
  10175. int rc, length, status = 0;
  10176. uint32_t shdr_status, shdr_add_status;
  10177. union lpfc_sli4_cfg_shdr *shdr;
  10178. if (!eq)
  10179. return -ENODEV;
  10180. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  10181. if (!mbox)
  10182. return -ENOMEM;
  10183. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  10184. sizeof(struct lpfc_sli4_cfg_mhdr));
  10185. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10186. LPFC_MBOX_OPCODE_EQ_DESTROY,
  10187. length, LPFC_SLI4_MBX_EMBED);
  10188. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  10189. eq->queue_id);
  10190. mbox->vport = eq->phba->pport;
  10191. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10192. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  10193. /* The IOCTL status is embedded in the mailbox subheader. */
  10194. shdr = (union lpfc_sli4_cfg_shdr *)
  10195. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  10196. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10197. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10198. if (shdr_status || shdr_add_status || rc) {
  10199. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10200. "2505 EQ_DESTROY mailbox failed with "
  10201. "status x%x add_status x%x, mbx status x%x\n",
  10202. shdr_status, shdr_add_status, rc);
  10203. status = -ENXIO;
  10204. }
  10205. /* Remove eq from any list */
  10206. list_del_init(&eq->list);
  10207. mempool_free(mbox, eq->phba->mbox_mem_pool);
  10208. return status;
  10209. }
  10210. /**
  10211. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  10212. * @cq: The queue structure associated with the queue to destroy.
  10213. *
  10214. * This function destroys a queue, as detailed in @cq by sending an mailbox
  10215. * command, specific to the type of queue, to the HBA.
  10216. *
  10217. * The @cq struct is used to get the queue ID of the queue to destroy.
  10218. *
  10219. * On success this function will return a zero. If the queue destroy mailbox
  10220. * command fails this function will return -ENXIO.
  10221. **/
  10222. uint32_t
  10223. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  10224. {
  10225. LPFC_MBOXQ_t *mbox;
  10226. int rc, length, status = 0;
  10227. uint32_t shdr_status, shdr_add_status;
  10228. union lpfc_sli4_cfg_shdr *shdr;
  10229. if (!cq)
  10230. return -ENODEV;
  10231. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  10232. if (!mbox)
  10233. return -ENOMEM;
  10234. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  10235. sizeof(struct lpfc_sli4_cfg_mhdr));
  10236. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10237. LPFC_MBOX_OPCODE_CQ_DESTROY,
  10238. length, LPFC_SLI4_MBX_EMBED);
  10239. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  10240. cq->queue_id);
  10241. mbox->vport = cq->phba->pport;
  10242. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10243. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  10244. /* The IOCTL status is embedded in the mailbox subheader. */
  10245. shdr = (union lpfc_sli4_cfg_shdr *)
  10246. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  10247. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10248. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10249. if (shdr_status || shdr_add_status || rc) {
  10250. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10251. "2506 CQ_DESTROY mailbox failed with "
  10252. "status x%x add_status x%x, mbx status x%x\n",
  10253. shdr_status, shdr_add_status, rc);
  10254. status = -ENXIO;
  10255. }
  10256. /* Remove cq from any list */
  10257. list_del_init(&cq->list);
  10258. mempool_free(mbox, cq->phba->mbox_mem_pool);
  10259. return status;
  10260. }
  10261. /**
  10262. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  10263. * @qm: The queue structure associated with the queue to destroy.
  10264. *
  10265. * This function destroys a queue, as detailed in @mq by sending an mailbox
  10266. * command, specific to the type of queue, to the HBA.
  10267. *
  10268. * The @mq struct is used to get the queue ID of the queue to destroy.
  10269. *
  10270. * On success this function will return a zero. If the queue destroy mailbox
  10271. * command fails this function will return -ENXIO.
  10272. **/
  10273. uint32_t
  10274. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  10275. {
  10276. LPFC_MBOXQ_t *mbox;
  10277. int rc, length, status = 0;
  10278. uint32_t shdr_status, shdr_add_status;
  10279. union lpfc_sli4_cfg_shdr *shdr;
  10280. if (!mq)
  10281. return -ENODEV;
  10282. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  10283. if (!mbox)
  10284. return -ENOMEM;
  10285. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  10286. sizeof(struct lpfc_sli4_cfg_mhdr));
  10287. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10288. LPFC_MBOX_OPCODE_MQ_DESTROY,
  10289. length, LPFC_SLI4_MBX_EMBED);
  10290. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  10291. mq->queue_id);
  10292. mbox->vport = mq->phba->pport;
  10293. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10294. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  10295. /* The IOCTL status is embedded in the mailbox subheader. */
  10296. shdr = (union lpfc_sli4_cfg_shdr *)
  10297. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  10298. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10299. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10300. if (shdr_status || shdr_add_status || rc) {
  10301. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10302. "2507 MQ_DESTROY mailbox failed with "
  10303. "status x%x add_status x%x, mbx status x%x\n",
  10304. shdr_status, shdr_add_status, rc);
  10305. status = -ENXIO;
  10306. }
  10307. /* Remove mq from any list */
  10308. list_del_init(&mq->list);
  10309. mempool_free(mbox, mq->phba->mbox_mem_pool);
  10310. return status;
  10311. }
  10312. /**
  10313. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  10314. * @wq: The queue structure associated with the queue to destroy.
  10315. *
  10316. * This function destroys a queue, as detailed in @wq by sending an mailbox
  10317. * command, specific to the type of queue, to the HBA.
  10318. *
  10319. * The @wq struct is used to get the queue ID of the queue to destroy.
  10320. *
  10321. * On success this function will return a zero. If the queue destroy mailbox
  10322. * command fails this function will return -ENXIO.
  10323. **/
  10324. uint32_t
  10325. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  10326. {
  10327. LPFC_MBOXQ_t *mbox;
  10328. int rc, length, status = 0;
  10329. uint32_t shdr_status, shdr_add_status;
  10330. union lpfc_sli4_cfg_shdr *shdr;
  10331. if (!wq)
  10332. return -ENODEV;
  10333. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  10334. if (!mbox)
  10335. return -ENOMEM;
  10336. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  10337. sizeof(struct lpfc_sli4_cfg_mhdr));
  10338. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10339. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  10340. length, LPFC_SLI4_MBX_EMBED);
  10341. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  10342. wq->queue_id);
  10343. mbox->vport = wq->phba->pport;
  10344. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10345. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  10346. shdr = (union lpfc_sli4_cfg_shdr *)
  10347. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  10348. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10349. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10350. if (shdr_status || shdr_add_status || rc) {
  10351. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10352. "2508 WQ_DESTROY mailbox failed with "
  10353. "status x%x add_status x%x, mbx status x%x\n",
  10354. shdr_status, shdr_add_status, rc);
  10355. status = -ENXIO;
  10356. }
  10357. /* Remove wq from any list */
  10358. list_del_init(&wq->list);
  10359. mempool_free(mbox, wq->phba->mbox_mem_pool);
  10360. return status;
  10361. }
  10362. /**
  10363. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  10364. * @rq: The queue structure associated with the queue to destroy.
  10365. *
  10366. * This function destroys a queue, as detailed in @rq by sending an mailbox
  10367. * command, specific to the type of queue, to the HBA.
  10368. *
  10369. * The @rq struct is used to get the queue ID of the queue to destroy.
  10370. *
  10371. * On success this function will return a zero. If the queue destroy mailbox
  10372. * command fails this function will return -ENXIO.
  10373. **/
  10374. uint32_t
  10375. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  10376. struct lpfc_queue *drq)
  10377. {
  10378. LPFC_MBOXQ_t *mbox;
  10379. int rc, length, status = 0;
  10380. uint32_t shdr_status, shdr_add_status;
  10381. union lpfc_sli4_cfg_shdr *shdr;
  10382. if (!hrq || !drq)
  10383. return -ENODEV;
  10384. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  10385. if (!mbox)
  10386. return -ENOMEM;
  10387. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  10388. sizeof(struct lpfc_sli4_cfg_mhdr));
  10389. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10390. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  10391. length, LPFC_SLI4_MBX_EMBED);
  10392. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10393. hrq->queue_id);
  10394. mbox->vport = hrq->phba->pport;
  10395. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10396. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  10397. /* The IOCTL status is embedded in the mailbox subheader. */
  10398. shdr = (union lpfc_sli4_cfg_shdr *)
  10399. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10400. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10401. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10402. if (shdr_status || shdr_add_status || rc) {
  10403. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10404. "2509 RQ_DESTROY mailbox failed with "
  10405. "status x%x add_status x%x, mbx status x%x\n",
  10406. shdr_status, shdr_add_status, rc);
  10407. if (rc != MBX_TIMEOUT)
  10408. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10409. return -ENXIO;
  10410. }
  10411. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  10412. drq->queue_id);
  10413. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  10414. shdr = (union lpfc_sli4_cfg_shdr *)
  10415. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  10416. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10417. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10418. if (shdr_status || shdr_add_status || rc) {
  10419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10420. "2510 RQ_DESTROY mailbox failed with "
  10421. "status x%x add_status x%x, mbx status x%x\n",
  10422. shdr_status, shdr_add_status, rc);
  10423. status = -ENXIO;
  10424. }
  10425. list_del_init(&hrq->list);
  10426. list_del_init(&drq->list);
  10427. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  10428. return status;
  10429. }
  10430. /**
  10431. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  10432. * @phba: The virtual port for which this call being executed.
  10433. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  10434. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  10435. * @xritag: the xritag that ties this io to the SGL pages.
  10436. *
  10437. * This routine will post the sgl pages for the IO that has the xritag
  10438. * that is in the iocbq structure. The xritag is assigned during iocbq
  10439. * creation and persists for as long as the driver is loaded.
  10440. * if the caller has fewer than 256 scatter gather segments to map then
  10441. * pdma_phys_addr1 should be 0.
  10442. * If the caller needs to map more than 256 scatter gather segment then
  10443. * pdma_phys_addr1 should be a valid physical address.
  10444. * physical address for SGLs must be 64 byte aligned.
  10445. * If you are going to map 2 SGL's then the first one must have 256 entries
  10446. * the second sgl can have between 1 and 256 entries.
  10447. *
  10448. * Return codes:
  10449. * 0 - Success
  10450. * -ENXIO, -ENOMEM - Failure
  10451. **/
  10452. int
  10453. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  10454. dma_addr_t pdma_phys_addr0,
  10455. dma_addr_t pdma_phys_addr1,
  10456. uint16_t xritag)
  10457. {
  10458. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  10459. LPFC_MBOXQ_t *mbox;
  10460. int rc;
  10461. uint32_t shdr_status, shdr_add_status;
  10462. union lpfc_sli4_cfg_shdr *shdr;
  10463. if (xritag == NO_XRI) {
  10464. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10465. "0364 Invalid param:\n");
  10466. return -EINVAL;
  10467. }
  10468. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10469. if (!mbox)
  10470. return -ENOMEM;
  10471. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10472. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  10473. sizeof(struct lpfc_mbx_post_sgl_pages) -
  10474. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  10475. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  10476. &mbox->u.mqe.un.post_sgl_pages;
  10477. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  10478. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  10479. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  10480. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  10481. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  10482. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  10483. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  10484. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  10485. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  10486. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  10487. if (!phba->sli4_hba.intr_enable)
  10488. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10489. else
  10490. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  10491. /* The IOCTL status is embedded in the mailbox subheader. */
  10492. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  10493. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10494. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10495. if (rc != MBX_TIMEOUT)
  10496. mempool_free(mbox, phba->mbox_mem_pool);
  10497. if (shdr_status || shdr_add_status || rc) {
  10498. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10499. "2511 POST_SGL mailbox failed with "
  10500. "status x%x add_status x%x, mbx status x%x\n",
  10501. shdr_status, shdr_add_status, rc);
  10502. rc = -ENXIO;
  10503. }
  10504. return 0;
  10505. }
  10506. /**
  10507. * lpfc_sli4_next_xritag - Get an xritag for the io
  10508. * @phba: Pointer to HBA context object.
  10509. *
  10510. * This function gets an xritag for the iocb. If there is no unused xritag
  10511. * it will return 0xffff.
  10512. * The function returns the allocated xritag if successful, else returns zero.
  10513. * Zero is not a valid xritag.
  10514. * The caller is not required to hold any lock.
  10515. **/
  10516. uint16_t
  10517. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  10518. {
  10519. uint16_t xritag;
  10520. spin_lock_irq(&phba->hbalock);
  10521. xritag = phba->sli4_hba.next_xri;
  10522. if ((xritag != (uint16_t) -1) && xritag <
  10523. (phba->sli4_hba.max_cfg_param.max_xri
  10524. + phba->sli4_hba.max_cfg_param.xri_base)) {
  10525. phba->sli4_hba.next_xri++;
  10526. phba->sli4_hba.max_cfg_param.xri_used++;
  10527. spin_unlock_irq(&phba->hbalock);
  10528. return xritag;
  10529. }
  10530. spin_unlock_irq(&phba->hbalock);
  10531. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10532. "2004 Failed to allocate XRI.last XRITAG is %d"
  10533. " Max XRI is %d, Used XRI is %d\n",
  10534. phba->sli4_hba.next_xri,
  10535. phba->sli4_hba.max_cfg_param.max_xri,
  10536. phba->sli4_hba.max_cfg_param.xri_used);
  10537. return -1;
  10538. }
  10539. /**
  10540. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  10541. * @phba: pointer to lpfc hba data structure.
  10542. *
  10543. * This routine is invoked to post a block of driver's sgl pages to the
  10544. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10545. * is only called when the driver is loading and after all IO has been
  10546. * stopped.
  10547. **/
  10548. int
  10549. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10550. {
  10551. struct lpfc_sglq *sglq_entry;
  10552. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10553. struct sgl_page_pairs *sgl_pg_pairs;
  10554. void *viraddr;
  10555. LPFC_MBOXQ_t *mbox;
  10556. uint32_t reqlen, alloclen, pg_pairs;
  10557. uint32_t mbox_tmo;
  10558. uint16_t xritag_start = 0;
  10559. int els_xri_cnt, rc = 0;
  10560. uint32_t shdr_status, shdr_add_status;
  10561. union lpfc_sli4_cfg_shdr *shdr;
  10562. /* The number of sgls to be posted */
  10563. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10564. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10565. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10566. if (reqlen > SLI4_PAGE_SIZE) {
  10567. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10568. "2559 Block sgl registration required DMA "
  10569. "size (%d) great than a page\n", reqlen);
  10570. return -ENOMEM;
  10571. }
  10572. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10573. if (!mbox) {
  10574. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10575. "2560 Failed to allocate mbox cmd memory\n");
  10576. return -ENOMEM;
  10577. }
  10578. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10579. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10580. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10581. LPFC_SLI4_MBX_NEMBED);
  10582. if (alloclen < reqlen) {
  10583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10584. "0285 Allocated DMA memory size (%d) is "
  10585. "less than the requested DMA memory "
  10586. "size (%d)\n", alloclen, reqlen);
  10587. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10588. return -ENOMEM;
  10589. }
  10590. /* Get the first SGE entry from the non-embedded DMA memory */
  10591. viraddr = mbox->sge_array->addr[0];
  10592. /* Set up the SGL pages in the non-embedded DMA pages */
  10593. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10594. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10595. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10596. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10597. /* Set up the sge entry */
  10598. sgl_pg_pairs->sgl_pg0_addr_lo =
  10599. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10600. sgl_pg_pairs->sgl_pg0_addr_hi =
  10601. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10602. sgl_pg_pairs->sgl_pg1_addr_lo =
  10603. cpu_to_le32(putPaddrLow(0));
  10604. sgl_pg_pairs->sgl_pg1_addr_hi =
  10605. cpu_to_le32(putPaddrHigh(0));
  10606. /* Keep the first xritag on the list */
  10607. if (pg_pairs == 0)
  10608. xritag_start = sglq_entry->sli4_xritag;
  10609. sgl_pg_pairs++;
  10610. }
  10611. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10612. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10613. /* Perform endian conversion if necessary */
  10614. sgl->word0 = cpu_to_le32(sgl->word0);
  10615. if (!phba->sli4_hba.intr_enable)
  10616. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10617. else {
  10618. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10619. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10620. }
  10621. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10622. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10623. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10624. if (rc != MBX_TIMEOUT)
  10625. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10626. if (shdr_status || shdr_add_status || rc) {
  10627. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10628. "2513 POST_SGL_BLOCK mailbox command failed "
  10629. "status x%x add_status x%x mbx status x%x\n",
  10630. shdr_status, shdr_add_status, rc);
  10631. rc = -ENXIO;
  10632. }
  10633. return rc;
  10634. }
  10635. /**
  10636. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10637. * @phba: pointer to lpfc hba data structure.
  10638. * @sblist: pointer to scsi buffer list.
  10639. * @count: number of scsi buffers on the list.
  10640. *
  10641. * This routine is invoked to post a block of @count scsi sgl pages from a
  10642. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10643. * No Lock is held.
  10644. *
  10645. **/
  10646. int
  10647. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10648. int cnt)
  10649. {
  10650. struct lpfc_scsi_buf *psb;
  10651. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10652. struct sgl_page_pairs *sgl_pg_pairs;
  10653. void *viraddr;
  10654. LPFC_MBOXQ_t *mbox;
  10655. uint32_t reqlen, alloclen, pg_pairs;
  10656. uint32_t mbox_tmo;
  10657. uint16_t xritag_start = 0;
  10658. int rc = 0;
  10659. uint32_t shdr_status, shdr_add_status;
  10660. dma_addr_t pdma_phys_bpl1;
  10661. union lpfc_sli4_cfg_shdr *shdr;
  10662. /* Calculate the requested length of the dma memory */
  10663. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10664. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10665. if (reqlen > SLI4_PAGE_SIZE) {
  10666. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10667. "0217 Block sgl registration required DMA "
  10668. "size (%d) great than a page\n", reqlen);
  10669. return -ENOMEM;
  10670. }
  10671. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10672. if (!mbox) {
  10673. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10674. "0283 Failed to allocate mbox cmd memory\n");
  10675. return -ENOMEM;
  10676. }
  10677. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10678. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10679. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10680. LPFC_SLI4_MBX_NEMBED);
  10681. if (alloclen < reqlen) {
  10682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10683. "2561 Allocated DMA memory size (%d) is "
  10684. "less than the requested DMA memory "
  10685. "size (%d)\n", alloclen, reqlen);
  10686. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10687. return -ENOMEM;
  10688. }
  10689. /* Get the first SGE entry from the non-embedded DMA memory */
  10690. viraddr = mbox->sge_array->addr[0];
  10691. /* Set up the SGL pages in the non-embedded DMA pages */
  10692. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10693. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10694. pg_pairs = 0;
  10695. list_for_each_entry(psb, sblist, list) {
  10696. /* Set up the sge entry */
  10697. sgl_pg_pairs->sgl_pg0_addr_lo =
  10698. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10699. sgl_pg_pairs->sgl_pg0_addr_hi =
  10700. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10701. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10702. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10703. else
  10704. pdma_phys_bpl1 = 0;
  10705. sgl_pg_pairs->sgl_pg1_addr_lo =
  10706. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10707. sgl_pg_pairs->sgl_pg1_addr_hi =
  10708. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10709. /* Keep the first xritag on the list */
  10710. if (pg_pairs == 0)
  10711. xritag_start = psb->cur_iocbq.sli4_xritag;
  10712. sgl_pg_pairs++;
  10713. pg_pairs++;
  10714. }
  10715. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10716. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10717. /* Perform endian conversion if necessary */
  10718. sgl->word0 = cpu_to_le32(sgl->word0);
  10719. if (!phba->sli4_hba.intr_enable)
  10720. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10721. else {
  10722. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10723. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10724. }
  10725. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10726. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10727. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10728. if (rc != MBX_TIMEOUT)
  10729. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10730. if (shdr_status || shdr_add_status || rc) {
  10731. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10732. "2564 POST_SGL_BLOCK mailbox command failed "
  10733. "status x%x add_status x%x mbx status x%x\n",
  10734. shdr_status, shdr_add_status, rc);
  10735. rc = -ENXIO;
  10736. }
  10737. return rc;
  10738. }
  10739. /**
  10740. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10741. * @phba: pointer to lpfc_hba struct that the frame was received on
  10742. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10743. *
  10744. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10745. * valid type of frame that the LPFC driver will handle. This function will
  10746. * return a zero if the frame is a valid frame or a non zero value when the
  10747. * frame does not pass the check.
  10748. **/
  10749. static int
  10750. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10751. {
  10752. /* make rctl_names static to save stack space */
  10753. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10754. char *type_names[] = FC_TYPE_NAMES_INIT;
  10755. struct fc_vft_header *fc_vft_hdr;
  10756. uint32_t *header = (uint32_t *) fc_hdr;
  10757. switch (fc_hdr->fh_r_ctl) {
  10758. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10759. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10760. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10761. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10762. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10763. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10764. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10765. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10766. case FC_RCTL_ELS_REQ: /* extended link services request */
  10767. case FC_RCTL_ELS_REP: /* extended link services reply */
  10768. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10769. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10770. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10771. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10772. case FC_RCTL_BA_RMC: /* remove connection */
  10773. case FC_RCTL_BA_ACC: /* basic accept */
  10774. case FC_RCTL_BA_RJT: /* basic reject */
  10775. case FC_RCTL_BA_PRMT:
  10776. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10777. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10778. case FC_RCTL_P_RJT: /* port reject */
  10779. case FC_RCTL_F_RJT: /* fabric reject */
  10780. case FC_RCTL_P_BSY: /* port busy */
  10781. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10782. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10783. case FC_RCTL_LCR: /* link credit reset */
  10784. case FC_RCTL_END: /* end */
  10785. break;
  10786. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10787. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10788. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10789. return lpfc_fc_frame_check(phba, fc_hdr);
  10790. default:
  10791. goto drop;
  10792. }
  10793. switch (fc_hdr->fh_type) {
  10794. case FC_TYPE_BLS:
  10795. case FC_TYPE_ELS:
  10796. case FC_TYPE_FCP:
  10797. case FC_TYPE_CT:
  10798. break;
  10799. case FC_TYPE_IP:
  10800. case FC_TYPE_ILS:
  10801. default:
  10802. goto drop;
  10803. }
  10804. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10805. "2538 Received frame rctl:%s type:%s "
  10806. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  10807. rctl_names[fc_hdr->fh_r_ctl],
  10808. type_names[fc_hdr->fh_type],
  10809. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  10810. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  10811. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  10812. return 0;
  10813. drop:
  10814. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10815. "2539 Dropped frame rctl:%s type:%s\n",
  10816. rctl_names[fc_hdr->fh_r_ctl],
  10817. type_names[fc_hdr->fh_type]);
  10818. return 1;
  10819. }
  10820. /**
  10821. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10822. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10823. *
  10824. * This function processes the FC header to retrieve the VFI from the VF
  10825. * header, if one exists. This function will return the VFI if one exists
  10826. * or 0 if no VSAN Header exists.
  10827. **/
  10828. static uint32_t
  10829. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10830. {
  10831. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10832. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10833. return 0;
  10834. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10835. }
  10836. /**
  10837. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10838. * @phba: Pointer to the HBA structure to search for the vport on
  10839. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10840. * @fcfi: The FC Fabric ID that the frame came from
  10841. *
  10842. * This function searches the @phba for a vport that matches the content of the
  10843. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10844. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10845. * returns the matching vport pointer or NULL if unable to match frame to a
  10846. * vport.
  10847. **/
  10848. static struct lpfc_vport *
  10849. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10850. uint16_t fcfi)
  10851. {
  10852. struct lpfc_vport **vports;
  10853. struct lpfc_vport *vport = NULL;
  10854. int i;
  10855. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10856. fc_hdr->fh_d_id[1] << 8 |
  10857. fc_hdr->fh_d_id[2]);
  10858. vports = lpfc_create_vport_work_array(phba);
  10859. if (vports != NULL)
  10860. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10861. if (phba->fcf.fcfi == fcfi &&
  10862. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10863. vports[i]->fc_myDID == did) {
  10864. vport = vports[i];
  10865. break;
  10866. }
  10867. }
  10868. lpfc_destroy_vport_work_array(phba, vports);
  10869. return vport;
  10870. }
  10871. /**
  10872. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10873. * @vport: The vport to work on.
  10874. *
  10875. * This function updates the receive sequence time stamp for this vport. The
  10876. * receive sequence time stamp indicates the time that the last frame of the
  10877. * the sequence that has been idle for the longest amount of time was received.
  10878. * the driver uses this time stamp to indicate if any received sequences have
  10879. * timed out.
  10880. **/
  10881. void
  10882. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10883. {
  10884. struct lpfc_dmabuf *h_buf;
  10885. struct hbq_dmabuf *dmabuf = NULL;
  10886. /* get the oldest sequence on the rcv list */
  10887. h_buf = list_get_first(&vport->rcv_buffer_list,
  10888. struct lpfc_dmabuf, list);
  10889. if (!h_buf)
  10890. return;
  10891. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10892. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10893. }
  10894. /**
  10895. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10896. * @vport: The vport that the received sequences were sent to.
  10897. *
  10898. * This function cleans up all outstanding received sequences. This is called
  10899. * by the driver when a link event or user action invalidates all the received
  10900. * sequences.
  10901. **/
  10902. void
  10903. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10904. {
  10905. struct lpfc_dmabuf *h_buf, *hnext;
  10906. struct lpfc_dmabuf *d_buf, *dnext;
  10907. struct hbq_dmabuf *dmabuf = NULL;
  10908. /* start with the oldest sequence on the rcv list */
  10909. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10910. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10911. list_del_init(&dmabuf->hbuf.list);
  10912. list_for_each_entry_safe(d_buf, dnext,
  10913. &dmabuf->dbuf.list, list) {
  10914. list_del_init(&d_buf->list);
  10915. lpfc_in_buf_free(vport->phba, d_buf);
  10916. }
  10917. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10918. }
  10919. }
  10920. /**
  10921. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10922. * @vport: The vport that the received sequences were sent to.
  10923. *
  10924. * This function determines whether any received sequences have timed out by
  10925. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10926. * indicates that there is at least one timed out sequence this routine will
  10927. * go through the received sequences one at a time from most inactive to most
  10928. * active to determine which ones need to be cleaned up. Once it has determined
  10929. * that a sequence needs to be cleaned up it will simply free up the resources
  10930. * without sending an abort.
  10931. **/
  10932. void
  10933. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10934. {
  10935. struct lpfc_dmabuf *h_buf, *hnext;
  10936. struct lpfc_dmabuf *d_buf, *dnext;
  10937. struct hbq_dmabuf *dmabuf = NULL;
  10938. unsigned long timeout;
  10939. int abort_count = 0;
  10940. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10941. vport->rcv_buffer_time_stamp);
  10942. if (list_empty(&vport->rcv_buffer_list) ||
  10943. time_before(jiffies, timeout))
  10944. return;
  10945. /* start with the oldest sequence on the rcv list */
  10946. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10947. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10948. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10949. dmabuf->time_stamp);
  10950. if (time_before(jiffies, timeout))
  10951. break;
  10952. abort_count++;
  10953. list_del_init(&dmabuf->hbuf.list);
  10954. list_for_each_entry_safe(d_buf, dnext,
  10955. &dmabuf->dbuf.list, list) {
  10956. list_del_init(&d_buf->list);
  10957. lpfc_in_buf_free(vport->phba, d_buf);
  10958. }
  10959. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10960. }
  10961. if (abort_count)
  10962. lpfc_update_rcv_time_stamp(vport);
  10963. }
  10964. /**
  10965. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10966. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10967. *
  10968. * This function searches through the existing incomplete sequences that have
  10969. * been sent to this @vport. If the frame matches one of the incomplete
  10970. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10971. * make up that sequence. If no sequence is found that matches this frame then
  10972. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10973. * This function returns a pointer to the first dmabuf in the sequence list that
  10974. * the frame was linked to.
  10975. **/
  10976. static struct hbq_dmabuf *
  10977. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10978. {
  10979. struct fc_frame_header *new_hdr;
  10980. struct fc_frame_header *temp_hdr;
  10981. struct lpfc_dmabuf *d_buf;
  10982. struct lpfc_dmabuf *h_buf;
  10983. struct hbq_dmabuf *seq_dmabuf = NULL;
  10984. struct hbq_dmabuf *temp_dmabuf = NULL;
  10985. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10986. dmabuf->time_stamp = jiffies;
  10987. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10988. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10989. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10990. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10991. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10992. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10993. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10994. continue;
  10995. /* found a pending sequence that matches this frame */
  10996. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10997. break;
  10998. }
  10999. if (!seq_dmabuf) {
  11000. /*
  11001. * This indicates first frame received for this sequence.
  11002. * Queue the buffer on the vport's rcv_buffer_list.
  11003. */
  11004. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11005. lpfc_update_rcv_time_stamp(vport);
  11006. return dmabuf;
  11007. }
  11008. temp_hdr = seq_dmabuf->hbuf.virt;
  11009. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  11010. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11011. list_del_init(&seq_dmabuf->hbuf.list);
  11012. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11013. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11014. lpfc_update_rcv_time_stamp(vport);
  11015. return dmabuf;
  11016. }
  11017. /* move this sequence to the tail to indicate a young sequence */
  11018. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  11019. seq_dmabuf->time_stamp = jiffies;
  11020. lpfc_update_rcv_time_stamp(vport);
  11021. if (list_empty(&seq_dmabuf->dbuf.list)) {
  11022. temp_hdr = dmabuf->hbuf.virt;
  11023. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  11024. return seq_dmabuf;
  11025. }
  11026. /* find the correct place in the sequence to insert this frame */
  11027. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  11028. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11029. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  11030. /*
  11031. * If the frame's sequence count is greater than the frame on
  11032. * the list then insert the frame right after this frame
  11033. */
  11034. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  11035. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  11036. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  11037. return seq_dmabuf;
  11038. }
  11039. }
  11040. return NULL;
  11041. }
  11042. /**
  11043. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  11044. * @vport: pointer to a vitural port
  11045. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11046. *
  11047. * This function tries to abort from the partially assembed sequence, described
  11048. * by the information from basic abbort @dmabuf. It checks to see whether such
  11049. * partially assembled sequence held by the driver. If so, it shall free up all
  11050. * the frames from the partially assembled sequence.
  11051. *
  11052. * Return
  11053. * true -- if there is matching partially assembled sequence present and all
  11054. * the frames freed with the sequence;
  11055. * false -- if there is no matching partially assembled sequence present so
  11056. * nothing got aborted in the lower layer driver
  11057. **/
  11058. static bool
  11059. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  11060. struct hbq_dmabuf *dmabuf)
  11061. {
  11062. struct fc_frame_header *new_hdr;
  11063. struct fc_frame_header *temp_hdr;
  11064. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  11065. struct hbq_dmabuf *seq_dmabuf = NULL;
  11066. /* Use the hdr_buf to find the sequence that matches this frame */
  11067. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  11068. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  11069. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11070. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  11071. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  11072. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  11073. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  11074. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  11075. continue;
  11076. /* found a pending sequence that matches this frame */
  11077. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  11078. break;
  11079. }
  11080. /* Free up all the frames from the partially assembled sequence */
  11081. if (seq_dmabuf) {
  11082. list_for_each_entry_safe(d_buf, n_buf,
  11083. &seq_dmabuf->dbuf.list, list) {
  11084. list_del_init(&d_buf->list);
  11085. lpfc_in_buf_free(vport->phba, d_buf);
  11086. }
  11087. return true;
  11088. }
  11089. return false;
  11090. }
  11091. /**
  11092. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  11093. * @phba: Pointer to HBA context object.
  11094. * @cmd_iocbq: pointer to the command iocbq structure.
  11095. * @rsp_iocbq: pointer to the response iocbq structure.
  11096. *
  11097. * This function handles the sequence abort response iocb command complete
  11098. * event. It properly releases the memory allocated to the sequence abort
  11099. * accept iocb.
  11100. **/
  11101. static void
  11102. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  11103. struct lpfc_iocbq *cmd_iocbq,
  11104. struct lpfc_iocbq *rsp_iocbq)
  11105. {
  11106. if (cmd_iocbq)
  11107. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  11108. }
  11109. /**
  11110. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  11111. * @phba: Pointer to HBA context object.
  11112. * @fc_hdr: pointer to a FC frame header.
  11113. *
  11114. * This function sends a basic response to a previous unsol sequence abort
  11115. * event after aborting the sequence handling.
  11116. **/
  11117. static void
  11118. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  11119. struct fc_frame_header *fc_hdr)
  11120. {
  11121. struct lpfc_iocbq *ctiocb = NULL;
  11122. struct lpfc_nodelist *ndlp;
  11123. uint16_t oxid, rxid;
  11124. uint32_t sid, fctl;
  11125. IOCB_t *icmd;
  11126. int rc;
  11127. if (!lpfc_is_link_up(phba))
  11128. return;
  11129. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11130. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  11131. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  11132. ndlp = lpfc_findnode_did(phba->pport, sid);
  11133. if (!ndlp) {
  11134. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  11135. "1268 Find ndlp returned NULL for oxid:x%x "
  11136. "SID:x%x\n", oxid, sid);
  11137. return;
  11138. }
  11139. if (rxid >= phba->sli4_hba.max_cfg_param.xri_base
  11140. && rxid <= (phba->sli4_hba.max_cfg_param.max_xri
  11141. + phba->sli4_hba.max_cfg_param.xri_base))
  11142. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  11143. /* Allocate buffer for rsp iocb */
  11144. ctiocb = lpfc_sli_get_iocbq(phba);
  11145. if (!ctiocb)
  11146. return;
  11147. /* Extract the F_CTL field from FC_HDR */
  11148. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  11149. icmd = &ctiocb->iocb;
  11150. icmd->un.xseq64.bdl.bdeSize = 0;
  11151. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  11152. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  11153. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  11154. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  11155. /* Fill in the rest of iocb fields */
  11156. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  11157. icmd->ulpBdeCount = 0;
  11158. icmd->ulpLe = 1;
  11159. icmd->ulpClass = CLASS3;
  11160. icmd->ulpContext = ndlp->nlp_rpi;
  11161. ctiocb->context1 = ndlp;
  11162. ctiocb->iocb_cmpl = NULL;
  11163. ctiocb->vport = phba->pport;
  11164. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  11165. ctiocb->sli4_xritag = NO_XRI;
  11166. /* If the oxid maps to the FCP XRI range or if it is out of range,
  11167. * send a BLS_RJT. The driver no longer has that exchange.
  11168. * Override the IOCB for a BA_RJT.
  11169. */
  11170. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  11171. phba->sli4_hba.max_cfg_param.xri_base) ||
  11172. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  11173. phba->sli4_hba.max_cfg_param.xri_base)) {
  11174. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  11175. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  11176. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  11177. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  11178. }
  11179. if (fctl & FC_FC_EX_CTX) {
  11180. /* ABTS sent by responder to CT exchange, construction
  11181. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  11182. * field and RX_ID from ABTS for RX_ID field.
  11183. */
  11184. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  11185. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  11186. } else {
  11187. /* ABTS sent by initiator to CT exchange, construction
  11188. * of BA_ACC will need to allocate a new XRI as for the
  11189. * XRI_TAG and RX_ID fields.
  11190. */
  11191. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  11192. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
  11193. }
  11194. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  11195. /* Xmit CT abts response on exchange <xid> */
  11196. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11197. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  11198. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  11199. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  11200. if (rc == IOCB_ERROR) {
  11201. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  11202. "2925 Failed to issue CT ABTS RSP x%x on "
  11203. "xri x%x, Data x%x\n",
  11204. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  11205. phba->link_state);
  11206. lpfc_sli_release_iocbq(phba, ctiocb);
  11207. }
  11208. }
  11209. /**
  11210. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  11211. * @vport: Pointer to the vport on which this sequence was received
  11212. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11213. *
  11214. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  11215. * receive sequence is only partially assembed by the driver, it shall abort
  11216. * the partially assembled frames for the sequence. Otherwise, if the
  11217. * unsolicited receive sequence has been completely assembled and passed to
  11218. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  11219. * unsolicited sequence has been aborted. After that, it will issue a basic
  11220. * accept to accept the abort.
  11221. **/
  11222. void
  11223. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  11224. struct hbq_dmabuf *dmabuf)
  11225. {
  11226. struct lpfc_hba *phba = vport->phba;
  11227. struct fc_frame_header fc_hdr;
  11228. uint32_t fctl;
  11229. bool abts_par;
  11230. /* Make a copy of fc_hdr before the dmabuf being released */
  11231. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  11232. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  11233. if (fctl & FC_FC_EX_CTX) {
  11234. /*
  11235. * ABTS sent by responder to exchange, just free the buffer
  11236. */
  11237. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11238. } else {
  11239. /*
  11240. * ABTS sent by initiator to exchange, need to do cleanup
  11241. */
  11242. /* Try to abort partially assembled seq */
  11243. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  11244. /* Send abort to ULP if partially seq abort failed */
  11245. if (abts_par == false)
  11246. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  11247. else
  11248. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11249. }
  11250. /* Send basic accept (BA_ACC) to the abort requester */
  11251. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  11252. }
  11253. /**
  11254. * lpfc_seq_complete - Indicates if a sequence is complete
  11255. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11256. *
  11257. * This function checks the sequence, starting with the frame described by
  11258. * @dmabuf, to see if all the frames associated with this sequence are present.
  11259. * the frames associated with this sequence are linked to the @dmabuf using the
  11260. * dbuf list. This function looks for two major things. 1) That the first frame
  11261. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  11262. * set. 3) That there are no holes in the sequence count. The function will
  11263. * return 1 when the sequence is complete, otherwise it will return 0.
  11264. **/
  11265. static int
  11266. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  11267. {
  11268. struct fc_frame_header *hdr;
  11269. struct lpfc_dmabuf *d_buf;
  11270. struct hbq_dmabuf *seq_dmabuf;
  11271. uint32_t fctl;
  11272. int seq_count = 0;
  11273. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11274. /* make sure first fame of sequence has a sequence count of zero */
  11275. if (hdr->fh_seq_cnt != seq_count)
  11276. return 0;
  11277. fctl = (hdr->fh_f_ctl[0] << 16 |
  11278. hdr->fh_f_ctl[1] << 8 |
  11279. hdr->fh_f_ctl[2]);
  11280. /* If last frame of sequence we can return success. */
  11281. if (fctl & FC_FC_END_SEQ)
  11282. return 1;
  11283. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  11284. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  11285. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11286. /* If there is a hole in the sequence count then fail. */
  11287. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  11288. return 0;
  11289. fctl = (hdr->fh_f_ctl[0] << 16 |
  11290. hdr->fh_f_ctl[1] << 8 |
  11291. hdr->fh_f_ctl[2]);
  11292. /* If last frame of sequence we can return success. */
  11293. if (fctl & FC_FC_END_SEQ)
  11294. return 1;
  11295. }
  11296. return 0;
  11297. }
  11298. /**
  11299. * lpfc_prep_seq - Prep sequence for ULP processing
  11300. * @vport: Pointer to the vport on which this sequence was received
  11301. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  11302. *
  11303. * This function takes a sequence, described by a list of frames, and creates
  11304. * a list of iocbq structures to describe the sequence. This iocbq list will be
  11305. * used to issue to the generic unsolicited sequence handler. This routine
  11306. * returns a pointer to the first iocbq in the list. If the function is unable
  11307. * to allocate an iocbq then it throw out the received frames that were not
  11308. * able to be described and return a pointer to the first iocbq. If unable to
  11309. * allocate any iocbqs (including the first) this function will return NULL.
  11310. **/
  11311. static struct lpfc_iocbq *
  11312. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  11313. {
  11314. struct lpfc_dmabuf *d_buf, *n_buf;
  11315. struct lpfc_iocbq *first_iocbq, *iocbq;
  11316. struct fc_frame_header *fc_hdr;
  11317. uint32_t sid;
  11318. struct ulp_bde64 *pbde;
  11319. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11320. /* remove from receive buffer list */
  11321. list_del_init(&seq_dmabuf->hbuf.list);
  11322. lpfc_update_rcv_time_stamp(vport);
  11323. /* get the Remote Port's SID */
  11324. sid = sli4_sid_from_fc_hdr(fc_hdr);
  11325. /* Get an iocbq struct to fill in. */
  11326. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  11327. if (first_iocbq) {
  11328. /* Initialize the first IOCB. */
  11329. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  11330. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  11331. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  11332. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  11333. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  11334. vport->vpi + vport->phba->vpi_base;
  11335. /* put the first buffer into the first IOCBq */
  11336. first_iocbq->context2 = &seq_dmabuf->dbuf;
  11337. first_iocbq->context3 = NULL;
  11338. first_iocbq->iocb.ulpBdeCount = 1;
  11339. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11340. LPFC_DATA_BUF_SIZE;
  11341. first_iocbq->iocb.un.rcvels.remoteID = sid;
  11342. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11343. bf_get(lpfc_rcqe_length,
  11344. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11345. }
  11346. iocbq = first_iocbq;
  11347. /*
  11348. * Each IOCBq can have two Buffers assigned, so go through the list
  11349. * of buffers for this sequence and save two buffers in each IOCBq
  11350. */
  11351. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  11352. if (!iocbq) {
  11353. lpfc_in_buf_free(vport->phba, d_buf);
  11354. continue;
  11355. }
  11356. if (!iocbq->context3) {
  11357. iocbq->context3 = d_buf;
  11358. iocbq->iocb.ulpBdeCount++;
  11359. pbde = (struct ulp_bde64 *)
  11360. &iocbq->iocb.unsli3.sli3Words[4];
  11361. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  11362. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11363. bf_get(lpfc_rcqe_length,
  11364. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11365. } else {
  11366. iocbq = lpfc_sli_get_iocbq(vport->phba);
  11367. if (!iocbq) {
  11368. if (first_iocbq) {
  11369. first_iocbq->iocb.ulpStatus =
  11370. IOSTAT_FCP_RSP_ERROR;
  11371. first_iocbq->iocb.un.ulpWord[4] =
  11372. IOERR_NO_RESOURCES;
  11373. }
  11374. lpfc_in_buf_free(vport->phba, d_buf);
  11375. continue;
  11376. }
  11377. iocbq->context2 = d_buf;
  11378. iocbq->context3 = NULL;
  11379. iocbq->iocb.ulpBdeCount = 1;
  11380. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  11381. LPFC_DATA_BUF_SIZE;
  11382. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  11383. bf_get(lpfc_rcqe_length,
  11384. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  11385. iocbq->iocb.un.rcvels.remoteID = sid;
  11386. list_add_tail(&iocbq->list, &first_iocbq->list);
  11387. }
  11388. }
  11389. return first_iocbq;
  11390. }
  11391. static void
  11392. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  11393. struct hbq_dmabuf *seq_dmabuf)
  11394. {
  11395. struct fc_frame_header *fc_hdr;
  11396. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  11397. struct lpfc_hba *phba = vport->phba;
  11398. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  11399. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  11400. if (!iocbq) {
  11401. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11402. "2707 Ring %d handler: Failed to allocate "
  11403. "iocb Rctl x%x Type x%x received\n",
  11404. LPFC_ELS_RING,
  11405. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11406. return;
  11407. }
  11408. if (!lpfc_complete_unsol_iocb(phba,
  11409. &phba->sli.ring[LPFC_ELS_RING],
  11410. iocbq, fc_hdr->fh_r_ctl,
  11411. fc_hdr->fh_type))
  11412. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11413. "2540 Ring %d handler: unexpected Rctl "
  11414. "x%x Type x%x received\n",
  11415. LPFC_ELS_RING,
  11416. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  11417. /* Free iocb created in lpfc_prep_seq */
  11418. list_for_each_entry_safe(curr_iocb, next_iocb,
  11419. &iocbq->list, list) {
  11420. list_del_init(&curr_iocb->list);
  11421. lpfc_sli_release_iocbq(phba, curr_iocb);
  11422. }
  11423. lpfc_sli_release_iocbq(phba, iocbq);
  11424. }
  11425. /**
  11426. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  11427. * @phba: Pointer to HBA context object.
  11428. *
  11429. * This function is called with no lock held. This function processes all
  11430. * the received buffers and gives it to upper layers when a received buffer
  11431. * indicates that it is the final frame in the sequence. The interrupt
  11432. * service routine processes received buffers at interrupt contexts and adds
  11433. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  11434. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  11435. * appropriate receive function when the final frame in a sequence is received.
  11436. **/
  11437. void
  11438. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  11439. struct hbq_dmabuf *dmabuf)
  11440. {
  11441. struct hbq_dmabuf *seq_dmabuf;
  11442. struct fc_frame_header *fc_hdr;
  11443. struct lpfc_vport *vport;
  11444. uint32_t fcfi;
  11445. /* Process each received buffer */
  11446. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  11447. /* check to see if this a valid type of frame */
  11448. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  11449. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11450. return;
  11451. }
  11452. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  11453. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  11454. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  11455. /* throw out the frame */
  11456. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11457. return;
  11458. }
  11459. /* Handle the basic abort sequence (BA_ABTS) event */
  11460. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  11461. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  11462. return;
  11463. }
  11464. /* Link this frame */
  11465. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  11466. if (!seq_dmabuf) {
  11467. /* unable to add frame to vport - throw it out */
  11468. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  11469. return;
  11470. }
  11471. /* If not last frame in sequence continue processing frames. */
  11472. if (!lpfc_seq_complete(seq_dmabuf))
  11473. return;
  11474. /* Send the complete sequence to the upper layer protocol */
  11475. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  11476. }
  11477. /**
  11478. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  11479. * @phba: pointer to lpfc hba data structure.
  11480. *
  11481. * This routine is invoked to post rpi header templates to the
  11482. * HBA consistent with the SLI-4 interface spec. This routine
  11483. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11484. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11485. *
  11486. * This routine does not require any locks. It's usage is expected
  11487. * to be driver load or reset recovery when the driver is
  11488. * sequential.
  11489. *
  11490. * Return codes
  11491. * 0 - successful
  11492. * -EIO - The mailbox failed to complete successfully.
  11493. * When this error occurs, the driver is not guaranteed
  11494. * to have any rpi regions posted to the device and
  11495. * must either attempt to repost the regions or take a
  11496. * fatal error.
  11497. **/
  11498. int
  11499. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  11500. {
  11501. struct lpfc_rpi_hdr *rpi_page;
  11502. uint32_t rc = 0;
  11503. /* Post all rpi memory regions to the port. */
  11504. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  11505. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  11506. if (rc != MBX_SUCCESS) {
  11507. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11508. "2008 Error %d posting all rpi "
  11509. "headers\n", rc);
  11510. rc = -EIO;
  11511. break;
  11512. }
  11513. }
  11514. return rc;
  11515. }
  11516. /**
  11517. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  11518. * @phba: pointer to lpfc hba data structure.
  11519. * @rpi_page: pointer to the rpi memory region.
  11520. *
  11521. * This routine is invoked to post a single rpi header to the
  11522. * HBA consistent with the SLI-4 interface spec. This memory region
  11523. * maps up to 64 rpi context regions.
  11524. *
  11525. * Return codes
  11526. * 0 - successful
  11527. * -ENOMEM - No available memory
  11528. * -EIO - The mailbox failed to complete successfully.
  11529. **/
  11530. int
  11531. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  11532. {
  11533. LPFC_MBOXQ_t *mboxq;
  11534. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  11535. uint32_t rc = 0;
  11536. uint32_t mbox_tmo;
  11537. uint32_t shdr_status, shdr_add_status;
  11538. union lpfc_sli4_cfg_shdr *shdr;
  11539. /* The port is notified of the header region via a mailbox command. */
  11540. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11541. if (!mboxq) {
  11542. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11543. "2001 Unable to allocate memory for issuing "
  11544. "SLI_CONFIG_SPECIAL mailbox command\n");
  11545. return -ENOMEM;
  11546. }
  11547. /* Post all rpi memory regions to the port. */
  11548. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  11549. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  11550. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11551. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  11552. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  11553. sizeof(struct lpfc_sli4_cfg_mhdr),
  11554. LPFC_SLI4_MBX_EMBED);
  11555. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  11556. hdr_tmpl, rpi_page->page_count);
  11557. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  11558. rpi_page->start_rpi);
  11559. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  11560. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  11561. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  11562. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  11563. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11564. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11565. if (rc != MBX_TIMEOUT)
  11566. mempool_free(mboxq, phba->mbox_mem_pool);
  11567. if (shdr_status || shdr_add_status || rc) {
  11568. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11569. "2514 POST_RPI_HDR mailbox failed with "
  11570. "status x%x add_status x%x, mbx status x%x\n",
  11571. shdr_status, shdr_add_status, rc);
  11572. rc = -ENXIO;
  11573. }
  11574. return rc;
  11575. }
  11576. /**
  11577. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11578. * @phba: pointer to lpfc hba data structure.
  11579. *
  11580. * This routine is invoked to post rpi header templates to the
  11581. * HBA consistent with the SLI-4 interface spec. This routine
  11582. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11583. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11584. *
  11585. * Returns
  11586. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11587. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11588. **/
  11589. int
  11590. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11591. {
  11592. int rpi;
  11593. uint16_t max_rpi, rpi_base, rpi_limit;
  11594. uint16_t rpi_remaining;
  11595. struct lpfc_rpi_hdr *rpi_hdr;
  11596. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11597. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11598. rpi_limit = phba->sli4_hba.next_rpi;
  11599. /*
  11600. * The valid rpi range is not guaranteed to be zero-based. Start
  11601. * the search at the rpi_base as reported by the port.
  11602. */
  11603. spin_lock_irq(&phba->hbalock);
  11604. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11605. if (rpi >= rpi_limit || rpi < rpi_base)
  11606. rpi = LPFC_RPI_ALLOC_ERROR;
  11607. else {
  11608. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11609. phba->sli4_hba.max_cfg_param.rpi_used++;
  11610. phba->sli4_hba.rpi_count++;
  11611. }
  11612. /*
  11613. * Don't try to allocate more rpi header regions if the device limit
  11614. * on available rpis max has been exhausted.
  11615. */
  11616. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11617. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11618. spin_unlock_irq(&phba->hbalock);
  11619. return rpi;
  11620. }
  11621. /*
  11622. * If the driver is running low on rpi resources, allocate another
  11623. * page now. Note that the next_rpi value is used because
  11624. * it represents how many are actually in use whereas max_rpi notes
  11625. * how many are supported max by the device.
  11626. */
  11627. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11628. phba->sli4_hba.rpi_count;
  11629. spin_unlock_irq(&phba->hbalock);
  11630. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11631. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11632. if (!rpi_hdr) {
  11633. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11634. "2002 Error Could not grow rpi "
  11635. "count\n");
  11636. } else {
  11637. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11638. }
  11639. }
  11640. return rpi;
  11641. }
  11642. /**
  11643. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11644. * @phba: pointer to lpfc hba data structure.
  11645. *
  11646. * This routine is invoked to release an rpi to the pool of
  11647. * available rpis maintained by the driver.
  11648. **/
  11649. void
  11650. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11651. {
  11652. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11653. phba->sli4_hba.rpi_count--;
  11654. phba->sli4_hba.max_cfg_param.rpi_used--;
  11655. }
  11656. }
  11657. /**
  11658. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11659. * @phba: pointer to lpfc hba data structure.
  11660. *
  11661. * This routine is invoked to release an rpi to the pool of
  11662. * available rpis maintained by the driver.
  11663. **/
  11664. void
  11665. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11666. {
  11667. spin_lock_irq(&phba->hbalock);
  11668. __lpfc_sli4_free_rpi(phba, rpi);
  11669. spin_unlock_irq(&phba->hbalock);
  11670. }
  11671. /**
  11672. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11673. * @phba: pointer to lpfc hba data structure.
  11674. *
  11675. * This routine is invoked to remove the memory region that
  11676. * provided rpi via a bitmask.
  11677. **/
  11678. void
  11679. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11680. {
  11681. kfree(phba->sli4_hba.rpi_bmask);
  11682. }
  11683. /**
  11684. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11685. * @phba: pointer to lpfc hba data structure.
  11686. *
  11687. * This routine is invoked to remove the memory region that
  11688. * provided rpi via a bitmask.
  11689. **/
  11690. int
  11691. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11692. {
  11693. LPFC_MBOXQ_t *mboxq;
  11694. struct lpfc_hba *phba = ndlp->phba;
  11695. int rc;
  11696. /* The port is notified of the header region via a mailbox command. */
  11697. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11698. if (!mboxq)
  11699. return -ENOMEM;
  11700. /* Post all rpi memory regions to the port. */
  11701. lpfc_resume_rpi(mboxq, ndlp);
  11702. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11703. if (rc == MBX_NOT_FINISHED) {
  11704. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11705. "2010 Resume RPI Mailbox failed "
  11706. "status %d, mbxStatus x%x\n", rc,
  11707. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11708. mempool_free(mboxq, phba->mbox_mem_pool);
  11709. return -EIO;
  11710. }
  11711. return 0;
  11712. }
  11713. /**
  11714. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11715. * @vport: Pointer to the vport for which the vpi is being initialized
  11716. *
  11717. * This routine is invoked to activate a vpi with the port.
  11718. *
  11719. * Returns:
  11720. * 0 success
  11721. * -Evalue otherwise
  11722. **/
  11723. int
  11724. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11725. {
  11726. LPFC_MBOXQ_t *mboxq;
  11727. int rc = 0;
  11728. int retval = MBX_SUCCESS;
  11729. uint32_t mbox_tmo;
  11730. struct lpfc_hba *phba = vport->phba;
  11731. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11732. if (!mboxq)
  11733. return -ENOMEM;
  11734. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11735. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11736. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11737. if (rc != MBX_SUCCESS) {
  11738. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11739. "2022 INIT VPI Mailbox failed "
  11740. "status %d, mbxStatus x%x\n", rc,
  11741. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11742. retval = -EIO;
  11743. }
  11744. if (rc != MBX_TIMEOUT)
  11745. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11746. return retval;
  11747. }
  11748. /**
  11749. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11750. * @phba: pointer to lpfc hba data structure.
  11751. * @mboxq: Pointer to mailbox object.
  11752. *
  11753. * This routine is invoked to manually add a single FCF record. The caller
  11754. * must pass a completely initialized FCF_Record. This routine takes
  11755. * care of the nonembedded mailbox operations.
  11756. **/
  11757. static void
  11758. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11759. {
  11760. void *virt_addr;
  11761. union lpfc_sli4_cfg_shdr *shdr;
  11762. uint32_t shdr_status, shdr_add_status;
  11763. virt_addr = mboxq->sge_array->addr[0];
  11764. /* The IOCTL status is embedded in the mailbox subheader. */
  11765. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11766. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11767. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11768. if ((shdr_status || shdr_add_status) &&
  11769. (shdr_status != STATUS_FCF_IN_USE))
  11770. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11771. "2558 ADD_FCF_RECORD mailbox failed with "
  11772. "status x%x add_status x%x\n",
  11773. shdr_status, shdr_add_status);
  11774. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11775. }
  11776. /**
  11777. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11778. * @phba: pointer to lpfc hba data structure.
  11779. * @fcf_record: pointer to the initialized fcf record to add.
  11780. *
  11781. * This routine is invoked to manually add a single FCF record. The caller
  11782. * must pass a completely initialized FCF_Record. This routine takes
  11783. * care of the nonembedded mailbox operations.
  11784. **/
  11785. int
  11786. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11787. {
  11788. int rc = 0;
  11789. LPFC_MBOXQ_t *mboxq;
  11790. uint8_t *bytep;
  11791. void *virt_addr;
  11792. dma_addr_t phys_addr;
  11793. struct lpfc_mbx_sge sge;
  11794. uint32_t alloc_len, req_len;
  11795. uint32_t fcfindex;
  11796. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11797. if (!mboxq) {
  11798. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11799. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11800. return -ENOMEM;
  11801. }
  11802. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11803. sizeof(uint32_t);
  11804. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11805. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11806. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11807. req_len, LPFC_SLI4_MBX_NEMBED);
  11808. if (alloc_len < req_len) {
  11809. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11810. "2523 Allocated DMA memory size (x%x) is "
  11811. "less than the requested DMA memory "
  11812. "size (x%x)\n", alloc_len, req_len);
  11813. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11814. return -ENOMEM;
  11815. }
  11816. /*
  11817. * Get the first SGE entry from the non-embedded DMA memory. This
  11818. * routine only uses a single SGE.
  11819. */
  11820. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11821. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11822. virt_addr = mboxq->sge_array->addr[0];
  11823. /*
  11824. * Configure the FCF record for FCFI 0. This is the driver's
  11825. * hardcoded default and gets used in nonFIP mode.
  11826. */
  11827. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11828. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11829. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11830. /*
  11831. * Copy the fcf_index and the FCF Record Data. The data starts after
  11832. * the FCoE header plus word10. The data copy needs to be endian
  11833. * correct.
  11834. */
  11835. bytep += sizeof(uint32_t);
  11836. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11837. mboxq->vport = phba->pport;
  11838. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11839. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11840. if (rc == MBX_NOT_FINISHED) {
  11841. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11842. "2515 ADD_FCF_RECORD mailbox failed with "
  11843. "status 0x%x\n", rc);
  11844. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11845. rc = -EIO;
  11846. } else
  11847. rc = 0;
  11848. return rc;
  11849. }
  11850. /**
  11851. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11852. * @phba: pointer to lpfc hba data structure.
  11853. * @fcf_record: pointer to the fcf record to write the default data.
  11854. * @fcf_index: FCF table entry index.
  11855. *
  11856. * This routine is invoked to build the driver's default FCF record. The
  11857. * values used are hardcoded. This routine handles memory initialization.
  11858. *
  11859. **/
  11860. void
  11861. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11862. struct fcf_record *fcf_record,
  11863. uint16_t fcf_index)
  11864. {
  11865. memset(fcf_record, 0, sizeof(struct fcf_record));
  11866. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11867. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11868. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11869. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11870. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11871. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11872. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11873. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11874. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11875. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11876. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11877. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11878. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11879. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11880. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11881. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11882. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11883. /* Set the VLAN bit map */
  11884. if (phba->valid_vlan) {
  11885. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11886. = 1 << (phba->vlan_id % 8);
  11887. }
  11888. }
  11889. /**
  11890. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11891. * @phba: pointer to lpfc hba data structure.
  11892. * @fcf_index: FCF table entry offset.
  11893. *
  11894. * This routine is invoked to scan the entire FCF table by reading FCF
  11895. * record and processing it one at a time starting from the @fcf_index
  11896. * for initial FCF discovery or fast FCF failover rediscovery.
  11897. *
  11898. * Return 0 if the mailbox command is submitted successfully, none 0
  11899. * otherwise.
  11900. **/
  11901. int
  11902. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11903. {
  11904. int rc = 0, error;
  11905. LPFC_MBOXQ_t *mboxq;
  11906. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11907. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11908. if (!mboxq) {
  11909. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11910. "2000 Failed to allocate mbox for "
  11911. "READ_FCF cmd\n");
  11912. error = -ENOMEM;
  11913. goto fail_fcf_scan;
  11914. }
  11915. /* Construct the read FCF record mailbox command */
  11916. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11917. if (rc) {
  11918. error = -EINVAL;
  11919. goto fail_fcf_scan;
  11920. }
  11921. /* Issue the mailbox command asynchronously */
  11922. mboxq->vport = phba->pport;
  11923. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11924. spin_lock_irq(&phba->hbalock);
  11925. phba->hba_flag |= FCF_TS_INPROG;
  11926. spin_unlock_irq(&phba->hbalock);
  11927. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11928. if (rc == MBX_NOT_FINISHED)
  11929. error = -EIO;
  11930. else {
  11931. /* Reset eligible FCF count for new scan */
  11932. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11933. phba->fcf.eligible_fcf_cnt = 0;
  11934. error = 0;
  11935. }
  11936. fail_fcf_scan:
  11937. if (error) {
  11938. if (mboxq)
  11939. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11940. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11941. spin_lock_irq(&phba->hbalock);
  11942. phba->hba_flag &= ~FCF_TS_INPROG;
  11943. spin_unlock_irq(&phba->hbalock);
  11944. }
  11945. return error;
  11946. }
  11947. /**
  11948. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11949. * @phba: pointer to lpfc hba data structure.
  11950. * @fcf_index: FCF table entry offset.
  11951. *
  11952. * This routine is invoked to read an FCF record indicated by @fcf_index
  11953. * and to use it for FLOGI roundrobin FCF failover.
  11954. *
  11955. * Return 0 if the mailbox command is submitted successfully, none 0
  11956. * otherwise.
  11957. **/
  11958. int
  11959. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11960. {
  11961. int rc = 0, error;
  11962. LPFC_MBOXQ_t *mboxq;
  11963. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11964. if (!mboxq) {
  11965. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11966. "2763 Failed to allocate mbox for "
  11967. "READ_FCF cmd\n");
  11968. error = -ENOMEM;
  11969. goto fail_fcf_read;
  11970. }
  11971. /* Construct the read FCF record mailbox command */
  11972. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11973. if (rc) {
  11974. error = -EINVAL;
  11975. goto fail_fcf_read;
  11976. }
  11977. /* Issue the mailbox command asynchronously */
  11978. mboxq->vport = phba->pport;
  11979. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11980. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11981. if (rc == MBX_NOT_FINISHED)
  11982. error = -EIO;
  11983. else
  11984. error = 0;
  11985. fail_fcf_read:
  11986. if (error && mboxq)
  11987. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11988. return error;
  11989. }
  11990. /**
  11991. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11992. * @phba: pointer to lpfc hba data structure.
  11993. * @fcf_index: FCF table entry offset.
  11994. *
  11995. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11996. * determine whether it's eligible for FLOGI roundrobin failover list.
  11997. *
  11998. * Return 0 if the mailbox command is submitted successfully, none 0
  11999. * otherwise.
  12000. **/
  12001. int
  12002. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  12003. {
  12004. int rc = 0, error;
  12005. LPFC_MBOXQ_t *mboxq;
  12006. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12007. if (!mboxq) {
  12008. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  12009. "2758 Failed to allocate mbox for "
  12010. "READ_FCF cmd\n");
  12011. error = -ENOMEM;
  12012. goto fail_fcf_read;
  12013. }
  12014. /* Construct the read FCF record mailbox command */
  12015. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  12016. if (rc) {
  12017. error = -EINVAL;
  12018. goto fail_fcf_read;
  12019. }
  12020. /* Issue the mailbox command asynchronously */
  12021. mboxq->vport = phba->pport;
  12022. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  12023. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  12024. if (rc == MBX_NOT_FINISHED)
  12025. error = -EIO;
  12026. else
  12027. error = 0;
  12028. fail_fcf_read:
  12029. if (error && mboxq)
  12030. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  12031. return error;
  12032. }
  12033. /**
  12034. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  12035. * @phba: pointer to lpfc hba data structure.
  12036. *
  12037. * This routine is to get the next eligible FCF record index in a round
  12038. * robin fashion. If the next eligible FCF record index equals to the
  12039. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  12040. * shall be returned, otherwise, the next eligible FCF record's index
  12041. * shall be returned.
  12042. **/
  12043. uint16_t
  12044. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  12045. {
  12046. uint16_t next_fcf_index;
  12047. /* Search start from next bit of currently registered FCF index */
  12048. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  12049. LPFC_SLI4_FCF_TBL_INDX_MAX;
  12050. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12051. LPFC_SLI4_FCF_TBL_INDX_MAX,
  12052. next_fcf_index);
  12053. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  12054. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  12055. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  12056. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  12057. /* Check roundrobin failover list empty condition */
  12058. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12059. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  12060. "2844 No roundrobin failover FCF available\n");
  12061. return LPFC_FCOE_FCF_NEXT_NONE;
  12062. }
  12063. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12064. "2845 Get next roundrobin failover FCF (x%x)\n",
  12065. next_fcf_index);
  12066. return next_fcf_index;
  12067. }
  12068. /**
  12069. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  12070. * @phba: pointer to lpfc hba data structure.
  12071. *
  12072. * This routine sets the FCF record index in to the eligible bmask for
  12073. * roundrobin failover search. It checks to make sure that the index
  12074. * does not go beyond the range of the driver allocated bmask dimension
  12075. * before setting the bit.
  12076. *
  12077. * Returns 0 if the index bit successfully set, otherwise, it returns
  12078. * -EINVAL.
  12079. **/
  12080. int
  12081. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  12082. {
  12083. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12084. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12085. "2610 FCF (x%x) reached driver's book "
  12086. "keeping dimension:x%x\n",
  12087. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12088. return -EINVAL;
  12089. }
  12090. /* Set the eligible FCF record index bmask */
  12091. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12092. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12093. "2790 Set FCF (x%x) to roundrobin FCF failover "
  12094. "bmask\n", fcf_index);
  12095. return 0;
  12096. }
  12097. /**
  12098. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  12099. * @phba: pointer to lpfc hba data structure.
  12100. *
  12101. * This routine clears the FCF record index from the eligible bmask for
  12102. * roundrobin failover search. It checks to make sure that the index
  12103. * does not go beyond the range of the driver allocated bmask dimension
  12104. * before clearing the bit.
  12105. **/
  12106. void
  12107. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  12108. {
  12109. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  12110. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12111. "2762 FCF (x%x) reached driver's book "
  12112. "keeping dimension:x%x\n",
  12113. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  12114. return;
  12115. }
  12116. /* Clear the eligible FCF record index bmask */
  12117. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  12118. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12119. "2791 Clear FCF (x%x) from roundrobin failover "
  12120. "bmask\n", fcf_index);
  12121. }
  12122. /**
  12123. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  12124. * @phba: pointer to lpfc hba data structure.
  12125. *
  12126. * This routine is the completion routine for the rediscover FCF table mailbox
  12127. * command. If the mailbox command returned failure, it will try to stop the
  12128. * FCF rediscover wait timer.
  12129. **/
  12130. void
  12131. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  12132. {
  12133. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12134. uint32_t shdr_status, shdr_add_status;
  12135. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12136. shdr_status = bf_get(lpfc_mbox_hdr_status,
  12137. &redisc_fcf->header.cfg_shdr.response);
  12138. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12139. &redisc_fcf->header.cfg_shdr.response);
  12140. if (shdr_status || shdr_add_status) {
  12141. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  12142. "2746 Requesting for FCF rediscovery failed "
  12143. "status x%x add_status x%x\n",
  12144. shdr_status, shdr_add_status);
  12145. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  12146. spin_lock_irq(&phba->hbalock);
  12147. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  12148. spin_unlock_irq(&phba->hbalock);
  12149. /*
  12150. * CVL event triggered FCF rediscover request failed,
  12151. * last resort to re-try current registered FCF entry.
  12152. */
  12153. lpfc_retry_pport_discovery(phba);
  12154. } else {
  12155. spin_lock_irq(&phba->hbalock);
  12156. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  12157. spin_unlock_irq(&phba->hbalock);
  12158. /*
  12159. * DEAD FCF event triggered FCF rediscover request
  12160. * failed, last resort to fail over as a link down
  12161. * to FCF registration.
  12162. */
  12163. lpfc_sli4_fcf_dead_failthrough(phba);
  12164. }
  12165. } else {
  12166. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  12167. "2775 Start FCF rediscover quiescent timer\n");
  12168. /*
  12169. * Start FCF rediscovery wait timer for pending FCF
  12170. * before rescan FCF record table.
  12171. */
  12172. lpfc_fcf_redisc_wait_start_timer(phba);
  12173. }
  12174. mempool_free(mbox, phba->mbox_mem_pool);
  12175. }
  12176. /**
  12177. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  12178. * @phba: pointer to lpfc hba data structure.
  12179. *
  12180. * This routine is invoked to request for rediscovery of the entire FCF table
  12181. * by the port.
  12182. **/
  12183. int
  12184. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  12185. {
  12186. LPFC_MBOXQ_t *mbox;
  12187. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  12188. int rc, length;
  12189. /* Cancel retry delay timers to all vports before FCF rediscover */
  12190. lpfc_cancel_all_vport_retry_delay_timer(phba);
  12191. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12192. if (!mbox) {
  12193. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12194. "2745 Failed to allocate mbox for "
  12195. "requesting FCF rediscover.\n");
  12196. return -ENOMEM;
  12197. }
  12198. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  12199. sizeof(struct lpfc_sli4_cfg_mhdr));
  12200. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12201. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  12202. length, LPFC_SLI4_MBX_EMBED);
  12203. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  12204. /* Set count to 0 for invalidating the entire FCF database */
  12205. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  12206. /* Issue the mailbox command asynchronously */
  12207. mbox->vport = phba->pport;
  12208. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  12209. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  12210. if (rc == MBX_NOT_FINISHED) {
  12211. mempool_free(mbox, phba->mbox_mem_pool);
  12212. return -EIO;
  12213. }
  12214. return 0;
  12215. }
  12216. /**
  12217. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  12218. * @phba: pointer to lpfc hba data structure.
  12219. *
  12220. * This function is the failover routine as a last resort to the FCF DEAD
  12221. * event when driver failed to perform fast FCF failover.
  12222. **/
  12223. void
  12224. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  12225. {
  12226. uint32_t link_state;
  12227. /*
  12228. * Last resort as FCF DEAD event failover will treat this as
  12229. * a link down, but save the link state because we don't want
  12230. * it to be changed to Link Down unless it is already down.
  12231. */
  12232. link_state = phba->link_state;
  12233. lpfc_linkdown(phba);
  12234. phba->link_state = link_state;
  12235. /* Unregister FCF if no devices connected to it */
  12236. lpfc_unregister_unused_fcf(phba);
  12237. }
  12238. /**
  12239. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  12240. * @phba: pointer to lpfc hba data structure.
  12241. *
  12242. * This function read region 23 and parse TLV for port status to
  12243. * decide if the user disaled the port. If the TLV indicates the
  12244. * port is disabled, the hba_flag is set accordingly.
  12245. **/
  12246. void
  12247. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  12248. {
  12249. LPFC_MBOXQ_t *pmb = NULL;
  12250. MAILBOX_t *mb;
  12251. uint8_t *rgn23_data = NULL;
  12252. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  12253. int rc;
  12254. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12255. if (!pmb) {
  12256. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12257. "2600 lpfc_sli_read_serdes_param failed to"
  12258. " allocate mailbox memory\n");
  12259. goto out;
  12260. }
  12261. mb = &pmb->u.mb;
  12262. /* Get adapter Region 23 data */
  12263. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  12264. if (!rgn23_data)
  12265. goto out;
  12266. do {
  12267. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  12268. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  12269. if (rc != MBX_SUCCESS) {
  12270. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12271. "2601 lpfc_sli_read_link_ste failed to"
  12272. " read config region 23 rc 0x%x Status 0x%x\n",
  12273. rc, mb->mbxStatus);
  12274. mb->un.varDmp.word_cnt = 0;
  12275. }
  12276. /*
  12277. * dump mem may return a zero when finished or we got a
  12278. * mailbox error, either way we are done.
  12279. */
  12280. if (mb->un.varDmp.word_cnt == 0)
  12281. break;
  12282. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  12283. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  12284. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  12285. rgn23_data + offset,
  12286. mb->un.varDmp.word_cnt);
  12287. offset += mb->un.varDmp.word_cnt;
  12288. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  12289. data_size = offset;
  12290. offset = 0;
  12291. if (!data_size)
  12292. goto out;
  12293. /* Check the region signature first */
  12294. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  12295. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12296. "2619 Config region 23 has bad signature\n");
  12297. goto out;
  12298. }
  12299. offset += 4;
  12300. /* Check the data structure version */
  12301. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  12302. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12303. "2620 Config region 23 has bad version\n");
  12304. goto out;
  12305. }
  12306. offset += 4;
  12307. /* Parse TLV entries in the region */
  12308. while (offset < data_size) {
  12309. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  12310. break;
  12311. /*
  12312. * If the TLV is not driver specific TLV or driver id is
  12313. * not linux driver id, skip the record.
  12314. */
  12315. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  12316. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  12317. (rgn23_data[offset + 3] != 0)) {
  12318. offset += rgn23_data[offset + 1] * 4 + 4;
  12319. continue;
  12320. }
  12321. /* Driver found a driver specific TLV in the config region */
  12322. sub_tlv_len = rgn23_data[offset + 1] * 4;
  12323. offset += 4;
  12324. tlv_offset = 0;
  12325. /*
  12326. * Search for configured port state sub-TLV.
  12327. */
  12328. while ((offset < data_size) &&
  12329. (tlv_offset < sub_tlv_len)) {
  12330. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  12331. offset += 4;
  12332. tlv_offset += 4;
  12333. break;
  12334. }
  12335. if (rgn23_data[offset] != PORT_STE_TYPE) {
  12336. offset += rgn23_data[offset + 1] * 4 + 4;
  12337. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  12338. continue;
  12339. }
  12340. /* This HBA contains PORT_STE configured */
  12341. if (!rgn23_data[offset + 2])
  12342. phba->hba_flag |= LINK_DISABLED;
  12343. goto out;
  12344. }
  12345. }
  12346. out:
  12347. if (pmb)
  12348. mempool_free(pmb, phba->mbox_mem_pool);
  12349. kfree(rgn23_data);
  12350. return;
  12351. }
  12352. /**
  12353. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  12354. * @vport: pointer to vport data structure.
  12355. *
  12356. * This function iterate through the mailboxq and clean up all REG_LOGIN
  12357. * and REG_VPI mailbox commands associated with the vport. This function
  12358. * is called when driver want to restart discovery of the vport due to
  12359. * a Clear Virtual Link event.
  12360. **/
  12361. void
  12362. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  12363. {
  12364. struct lpfc_hba *phba = vport->phba;
  12365. LPFC_MBOXQ_t *mb, *nextmb;
  12366. struct lpfc_dmabuf *mp;
  12367. struct lpfc_nodelist *ndlp;
  12368. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  12369. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  12370. LIST_HEAD(mbox_cmd_list);
  12371. uint8_t restart_loop;
  12372. /* Clean up internally queued mailbox commands with the vport */
  12373. spin_lock_irq(&phba->hbalock);
  12374. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  12375. if (mb->vport != vport)
  12376. continue;
  12377. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12378. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12379. continue;
  12380. list_del(&mb->list);
  12381. list_add_tail(&mb->list, &mbox_cmd_list);
  12382. }
  12383. /* Clean up active mailbox command with the vport */
  12384. mb = phba->sli.mbox_active;
  12385. if (mb && (mb->vport == vport)) {
  12386. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  12387. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  12388. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12389. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12390. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  12391. /* Put reference count for delayed processing */
  12392. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  12393. /* Unregister the RPI when mailbox complete */
  12394. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12395. }
  12396. }
  12397. /* Cleanup any mailbox completions which are not yet processed */
  12398. do {
  12399. restart_loop = 0;
  12400. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  12401. /*
  12402. * If this mailox is already processed or it is
  12403. * for another vport ignore it.
  12404. */
  12405. if ((mb->vport != vport) ||
  12406. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  12407. continue;
  12408. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  12409. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  12410. continue;
  12411. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12412. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12413. ndlp = (struct lpfc_nodelist *)mb->context2;
  12414. /* Unregister the RPI when mailbox complete */
  12415. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  12416. restart_loop = 1;
  12417. spin_unlock_irq(&phba->hbalock);
  12418. spin_lock(shost->host_lock);
  12419. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12420. spin_unlock(shost->host_lock);
  12421. spin_lock_irq(&phba->hbalock);
  12422. break;
  12423. }
  12424. }
  12425. } while (restart_loop);
  12426. spin_unlock_irq(&phba->hbalock);
  12427. /* Release the cleaned-up mailbox commands */
  12428. while (!list_empty(&mbox_cmd_list)) {
  12429. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  12430. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  12431. mp = (struct lpfc_dmabuf *) (mb->context1);
  12432. if (mp) {
  12433. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  12434. kfree(mp);
  12435. }
  12436. ndlp = (struct lpfc_nodelist *) mb->context2;
  12437. mb->context2 = NULL;
  12438. if (ndlp) {
  12439. spin_lock(shost->host_lock);
  12440. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12441. spin_unlock(shost->host_lock);
  12442. lpfc_nlp_put(ndlp);
  12443. }
  12444. }
  12445. mempool_free(mb, phba->mbox_mem_pool);
  12446. }
  12447. /* Release the ndlp with the cleaned-up active mailbox command */
  12448. if (act_mbx_ndlp) {
  12449. spin_lock(shost->host_lock);
  12450. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  12451. spin_unlock(shost->host_lock);
  12452. lpfc_nlp_put(act_mbx_ndlp);
  12453. }
  12454. }
  12455. /**
  12456. * lpfc_drain_txq - Drain the txq
  12457. * @phba: Pointer to HBA context object.
  12458. *
  12459. * This function attempt to submit IOCBs on the txq
  12460. * to the adapter. For SLI4 adapters, the txq contains
  12461. * ELS IOCBs that have been deferred because the there
  12462. * are no SGLs. This congestion can occur with large
  12463. * vport counts during node discovery.
  12464. **/
  12465. uint32_t
  12466. lpfc_drain_txq(struct lpfc_hba *phba)
  12467. {
  12468. LIST_HEAD(completions);
  12469. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  12470. struct lpfc_iocbq *piocbq = 0;
  12471. unsigned long iflags = 0;
  12472. char *fail_msg = NULL;
  12473. struct lpfc_sglq *sglq;
  12474. union lpfc_wqe wqe;
  12475. spin_lock_irqsave(&phba->hbalock, iflags);
  12476. if (pring->txq_cnt > pring->txq_max)
  12477. pring->txq_max = pring->txq_cnt;
  12478. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12479. while (pring->txq_cnt) {
  12480. spin_lock_irqsave(&phba->hbalock, iflags);
  12481. piocbq = lpfc_sli_ringtx_get(phba, pring);
  12482. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  12483. if (!sglq) {
  12484. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  12485. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12486. break;
  12487. } else {
  12488. if (!piocbq) {
  12489. /* The txq_cnt out of sync. This should
  12490. * never happen
  12491. */
  12492. sglq = __lpfc_clear_active_sglq(phba,
  12493. sglq->sli4_xritag);
  12494. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12495. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12496. "2823 txq empty and txq_cnt is %d\n ",
  12497. pring->txq_cnt);
  12498. break;
  12499. }
  12500. }
  12501. /* The xri and iocb resources secured,
  12502. * attempt to issue request
  12503. */
  12504. piocbq->sli4_xritag = sglq->sli4_xritag;
  12505. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  12506. fail_msg = "to convert bpl to sgl";
  12507. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  12508. fail_msg = "to convert iocb to wqe";
  12509. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  12510. fail_msg = " - Wq is full";
  12511. else
  12512. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  12513. if (fail_msg) {
  12514. /* Failed means we can't issue and need to cancel */
  12515. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12516. "2822 IOCB failed %s iotag 0x%x "
  12517. "xri 0x%x\n",
  12518. fail_msg,
  12519. piocbq->iotag, piocbq->sli4_xritag);
  12520. list_add_tail(&piocbq->list, &completions);
  12521. }
  12522. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12523. }
  12524. /* Cancel all the IOCBs that cannot be issued */
  12525. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  12526. IOERR_SLI_ABORTED);
  12527. return pring->txq_cnt;
  12528. }