lpfc_sli.c 404 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt)
  556. lpfc_worker_wake_up(phba);
  557. }
  558. }
  559. /*
  560. * Clean all volatile data fields, preserve iotag and node struct.
  561. */
  562. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  563. iocbq->sli4_xritag = NO_XRI;
  564. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  565. }
  566. /**
  567. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  568. * @phba: Pointer to HBA context object.
  569. * @iocbq: Pointer to driver iocb object.
  570. *
  571. * This function is called with hbalock held to release driver
  572. * iocb object to the iocb pool. The iotag in the iocb object
  573. * does not change for each use of the iocb object. This function
  574. * clears all other fields of the iocb object when it is freed.
  575. **/
  576. static void
  577. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  578. {
  579. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  580. /*
  581. * Clean all volatile data fields, preserve iotag and node struct.
  582. */
  583. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  584. iocbq->sli4_xritag = NO_XRI;
  585. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  586. }
  587. /**
  588. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  589. * @phba: Pointer to HBA context object.
  590. * @iocbq: Pointer to driver iocb object.
  591. *
  592. * This function is called with hbalock held to release driver
  593. * iocb object to the iocb pool. The iotag in the iocb object
  594. * does not change for each use of the iocb object. This function
  595. * clears all other fields of the iocb object when it is freed.
  596. **/
  597. static void
  598. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  601. phba->iocb_cnt--;
  602. }
  603. /**
  604. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  605. * @phba: Pointer to HBA context object.
  606. * @iocbq: Pointer to driver iocb object.
  607. *
  608. * This function is called with no lock held to release the iocb to
  609. * iocb pool.
  610. **/
  611. void
  612. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  613. {
  614. unsigned long iflags;
  615. /*
  616. * Clean all volatile data fields, preserve iotag and node struct.
  617. */
  618. spin_lock_irqsave(&phba->hbalock, iflags);
  619. __lpfc_sli_release_iocbq(phba, iocbq);
  620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  621. }
  622. /**
  623. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  624. * @phba: Pointer to HBA context object.
  625. * @iocblist: List of IOCBs.
  626. * @ulpstatus: ULP status in IOCB command field.
  627. * @ulpWord4: ULP word-4 in IOCB command field.
  628. *
  629. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  630. * on the list by invoking the complete callback function associated with the
  631. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  632. * fields.
  633. **/
  634. void
  635. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  636. uint32_t ulpstatus, uint32_t ulpWord4)
  637. {
  638. struct lpfc_iocbq *piocb;
  639. while (!list_empty(iocblist)) {
  640. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  641. if (!piocb->iocb_cmpl)
  642. lpfc_sli_release_iocbq(phba, piocb);
  643. else {
  644. piocb->iocb.ulpStatus = ulpstatus;
  645. piocb->iocb.un.ulpWord[4] = ulpWord4;
  646. (piocb->iocb_cmpl) (phba, piocb, piocb);
  647. }
  648. }
  649. return;
  650. }
  651. /**
  652. * lpfc_sli_iocb_cmd_type - Get the iocb type
  653. * @iocb_cmnd: iocb command code.
  654. *
  655. * This function is called by ring event handler function to get the iocb type.
  656. * This function translates the iocb command to an iocb command type used to
  657. * decide the final disposition of each completed IOCB.
  658. * The function returns
  659. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  660. * LPFC_SOL_IOCB if it is a solicited iocb completion
  661. * LPFC_ABORT_IOCB if it is an abort iocb
  662. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  663. *
  664. * The caller is not required to hold any lock.
  665. **/
  666. static lpfc_iocb_type
  667. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  668. {
  669. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  670. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  671. return 0;
  672. switch (iocb_cmnd) {
  673. case CMD_XMIT_SEQUENCE_CR:
  674. case CMD_XMIT_SEQUENCE_CX:
  675. case CMD_XMIT_BCAST_CN:
  676. case CMD_XMIT_BCAST_CX:
  677. case CMD_ELS_REQUEST_CR:
  678. case CMD_ELS_REQUEST_CX:
  679. case CMD_CREATE_XRI_CR:
  680. case CMD_CREATE_XRI_CX:
  681. case CMD_GET_RPI_CN:
  682. case CMD_XMIT_ELS_RSP_CX:
  683. case CMD_GET_RPI_CR:
  684. case CMD_FCP_IWRITE_CR:
  685. case CMD_FCP_IWRITE_CX:
  686. case CMD_FCP_IREAD_CR:
  687. case CMD_FCP_IREAD_CX:
  688. case CMD_FCP_ICMND_CR:
  689. case CMD_FCP_ICMND_CX:
  690. case CMD_FCP_TSEND_CX:
  691. case CMD_FCP_TRSP_CX:
  692. case CMD_FCP_TRECEIVE_CX:
  693. case CMD_FCP_AUTO_TRSP_CX:
  694. case CMD_ADAPTER_MSG:
  695. case CMD_ADAPTER_DUMP:
  696. case CMD_XMIT_SEQUENCE64_CR:
  697. case CMD_XMIT_SEQUENCE64_CX:
  698. case CMD_XMIT_BCAST64_CN:
  699. case CMD_XMIT_BCAST64_CX:
  700. case CMD_ELS_REQUEST64_CR:
  701. case CMD_ELS_REQUEST64_CX:
  702. case CMD_FCP_IWRITE64_CR:
  703. case CMD_FCP_IWRITE64_CX:
  704. case CMD_FCP_IREAD64_CR:
  705. case CMD_FCP_IREAD64_CX:
  706. case CMD_FCP_ICMND64_CR:
  707. case CMD_FCP_ICMND64_CX:
  708. case CMD_FCP_TSEND64_CX:
  709. case CMD_FCP_TRSP64_CX:
  710. case CMD_FCP_TRECEIVE64_CX:
  711. case CMD_GEN_REQUEST64_CR:
  712. case CMD_GEN_REQUEST64_CX:
  713. case CMD_XMIT_ELS_RSP64_CX:
  714. case DSSCMD_IWRITE64_CR:
  715. case DSSCMD_IWRITE64_CX:
  716. case DSSCMD_IREAD64_CR:
  717. case DSSCMD_IREAD64_CX:
  718. type = LPFC_SOL_IOCB;
  719. break;
  720. case CMD_ABORT_XRI_CN:
  721. case CMD_ABORT_XRI_CX:
  722. case CMD_CLOSE_XRI_CN:
  723. case CMD_CLOSE_XRI_CX:
  724. case CMD_XRI_ABORTED_CX:
  725. case CMD_ABORT_MXRI64_CN:
  726. case CMD_XMIT_BLS_RSP64_CX:
  727. type = LPFC_ABORT_IOCB;
  728. break;
  729. case CMD_RCV_SEQUENCE_CX:
  730. case CMD_RCV_ELS_REQ_CX:
  731. case CMD_RCV_SEQUENCE64_CX:
  732. case CMD_RCV_ELS_REQ64_CX:
  733. case CMD_ASYNC_STATUS:
  734. case CMD_IOCB_RCV_SEQ64_CX:
  735. case CMD_IOCB_RCV_ELS64_CX:
  736. case CMD_IOCB_RCV_CONT64_CX:
  737. case CMD_IOCB_RET_XRI64_CX:
  738. type = LPFC_UNSOL_IOCB;
  739. break;
  740. case CMD_IOCB_XMIT_MSEQ64_CR:
  741. case CMD_IOCB_XMIT_MSEQ64_CX:
  742. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  743. case CMD_IOCB_RCV_ELS_LIST64_CX:
  744. case CMD_IOCB_CLOSE_EXTENDED_CN:
  745. case CMD_IOCB_ABORT_EXTENDED_CN:
  746. case CMD_IOCB_RET_HBQE64_CN:
  747. case CMD_IOCB_FCP_IBIDIR64_CR:
  748. case CMD_IOCB_FCP_IBIDIR64_CX:
  749. case CMD_IOCB_FCP_ITASKMGT64_CX:
  750. case CMD_IOCB_LOGENTRY_CN:
  751. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  752. printk("%s - Unhandled SLI-3 Command x%x\n",
  753. __func__, iocb_cmnd);
  754. type = LPFC_UNKNOWN_IOCB;
  755. break;
  756. default:
  757. type = LPFC_UNKNOWN_IOCB;
  758. break;
  759. }
  760. return type;
  761. }
  762. /**
  763. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  764. * @phba: Pointer to HBA context object.
  765. *
  766. * This function is called from SLI initialization code
  767. * to configure every ring of the HBA's SLI interface. The
  768. * caller is not required to hold any lock. This function issues
  769. * a config_ring mailbox command for each ring.
  770. * This function returns zero if successful else returns a negative
  771. * error code.
  772. **/
  773. static int
  774. lpfc_sli_ring_map(struct lpfc_hba *phba)
  775. {
  776. struct lpfc_sli *psli = &phba->sli;
  777. LPFC_MBOXQ_t *pmb;
  778. MAILBOX_t *pmbox;
  779. int i, rc, ret = 0;
  780. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  781. if (!pmb)
  782. return -ENOMEM;
  783. pmbox = &pmb->u.mb;
  784. phba->link_state = LPFC_INIT_MBX_CMDS;
  785. for (i = 0; i < psli->num_rings; i++) {
  786. lpfc_config_ring(phba, i, pmb);
  787. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  788. if (rc != MBX_SUCCESS) {
  789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  790. "0446 Adapter failed to init (%d), "
  791. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  792. "ring %d\n",
  793. rc, pmbox->mbxCommand,
  794. pmbox->mbxStatus, i);
  795. phba->link_state = LPFC_HBA_ERROR;
  796. ret = -ENXIO;
  797. break;
  798. }
  799. }
  800. mempool_free(pmb, phba->mbox_mem_pool);
  801. return ret;
  802. }
  803. /**
  804. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  805. * @phba: Pointer to HBA context object.
  806. * @pring: Pointer to driver SLI ring object.
  807. * @piocb: Pointer to the driver iocb object.
  808. *
  809. * This function is called with hbalock held. The function adds the
  810. * new iocb to txcmplq of the given ring. This function always returns
  811. * 0. If this function is called for ELS ring, this function checks if
  812. * there is a vport associated with the ELS command. This function also
  813. * starts els_tmofunc timer if this is an ELS command.
  814. **/
  815. static int
  816. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  817. struct lpfc_iocbq *piocb)
  818. {
  819. list_add_tail(&piocb->list, &pring->txcmplq);
  820. piocb->iocb_flag |= LPFC_IO_ON_Q;
  821. pring->txcmplq_cnt++;
  822. if (pring->txcmplq_cnt > pring->txcmplq_max)
  823. pring->txcmplq_max = pring->txcmplq_cnt;
  824. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  825. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  826. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  827. if (!piocb->vport)
  828. BUG();
  829. else
  830. mod_timer(&piocb->vport->els_tmofunc,
  831. jiffies + HZ * (phba->fc_ratov << 1));
  832. }
  833. return 0;
  834. }
  835. /**
  836. * lpfc_sli_ringtx_get - Get first element of the txq
  837. * @phba: Pointer to HBA context object.
  838. * @pring: Pointer to driver SLI ring object.
  839. *
  840. * This function is called with hbalock held to get next
  841. * iocb in txq of the given ring. If there is any iocb in
  842. * the txq, the function returns first iocb in the list after
  843. * removing the iocb from the list, else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  847. {
  848. struct lpfc_iocbq *cmd_iocb;
  849. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  850. if (cmd_iocb != NULL)
  851. pring->txq_cnt--;
  852. return cmd_iocb;
  853. }
  854. /**
  855. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  856. * @phba: Pointer to HBA context object.
  857. * @pring: Pointer to driver SLI ring object.
  858. *
  859. * This function is called with hbalock held and the caller must post the
  860. * iocb without releasing the lock. If the caller releases the lock,
  861. * iocb slot returned by the function is not guaranteed to be available.
  862. * The function returns pointer to the next available iocb slot if there
  863. * is available slot in the ring, else it returns NULL.
  864. * If the get index of the ring is ahead of the put index, the function
  865. * will post an error attention event to the worker thread to take the
  866. * HBA to offline state.
  867. **/
  868. static IOCB_t *
  869. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  870. {
  871. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  872. uint32_t max_cmd_idx = pring->numCiocb;
  873. if ((pring->next_cmdidx == pring->cmdidx) &&
  874. (++pring->next_cmdidx >= max_cmd_idx))
  875. pring->next_cmdidx = 0;
  876. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  877. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  878. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  879. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  880. "0315 Ring %d issue: portCmdGet %d "
  881. "is bigger than cmd ring %d\n",
  882. pring->ringno,
  883. pring->local_getidx, max_cmd_idx);
  884. phba->link_state = LPFC_HBA_ERROR;
  885. /*
  886. * All error attention handlers are posted to
  887. * worker thread
  888. */
  889. phba->work_ha |= HA_ERATT;
  890. phba->work_hs = HS_FFER3;
  891. lpfc_worker_wake_up(phba);
  892. return NULL;
  893. }
  894. if (pring->local_getidx == pring->next_cmdidx)
  895. return NULL;
  896. }
  897. return lpfc_cmd_iocb(phba, pring);
  898. }
  899. /**
  900. * lpfc_sli_next_iotag - Get an iotag for the iocb
  901. * @phba: Pointer to HBA context object.
  902. * @iocbq: Pointer to driver iocb object.
  903. *
  904. * This function gets an iotag for the iocb. If there is no unused iotag and
  905. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  906. * array and assigns a new iotag.
  907. * The function returns the allocated iotag if successful, else returns zero.
  908. * Zero is not a valid iotag.
  909. * The caller is not required to hold any lock.
  910. **/
  911. uint16_t
  912. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  913. {
  914. struct lpfc_iocbq **new_arr;
  915. struct lpfc_iocbq **old_arr;
  916. size_t new_len;
  917. struct lpfc_sli *psli = &phba->sli;
  918. uint16_t iotag;
  919. spin_lock_irq(&phba->hbalock);
  920. iotag = psli->last_iotag;
  921. if(++iotag < psli->iocbq_lookup_len) {
  922. psli->last_iotag = iotag;
  923. psli->iocbq_lookup[iotag] = iocbq;
  924. spin_unlock_irq(&phba->hbalock);
  925. iocbq->iotag = iotag;
  926. return iotag;
  927. } else if (psli->iocbq_lookup_len < (0xffff
  928. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  929. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  930. spin_unlock_irq(&phba->hbalock);
  931. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  932. GFP_KERNEL);
  933. if (new_arr) {
  934. spin_lock_irq(&phba->hbalock);
  935. old_arr = psli->iocbq_lookup;
  936. if (new_len <= psli->iocbq_lookup_len) {
  937. /* highly unprobable case */
  938. kfree(new_arr);
  939. iotag = psli->last_iotag;
  940. if(++iotag < psli->iocbq_lookup_len) {
  941. psli->last_iotag = iotag;
  942. psli->iocbq_lookup[iotag] = iocbq;
  943. spin_unlock_irq(&phba->hbalock);
  944. iocbq->iotag = iotag;
  945. return iotag;
  946. }
  947. spin_unlock_irq(&phba->hbalock);
  948. return 0;
  949. }
  950. if (psli->iocbq_lookup)
  951. memcpy(new_arr, old_arr,
  952. ((psli->last_iotag + 1) *
  953. sizeof (struct lpfc_iocbq *)));
  954. psli->iocbq_lookup = new_arr;
  955. psli->iocbq_lookup_len = new_len;
  956. psli->last_iotag = iotag;
  957. psli->iocbq_lookup[iotag] = iocbq;
  958. spin_unlock_irq(&phba->hbalock);
  959. iocbq->iotag = iotag;
  960. kfree(old_arr);
  961. return iotag;
  962. }
  963. } else
  964. spin_unlock_irq(&phba->hbalock);
  965. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  966. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  967. psli->last_iotag);
  968. return 0;
  969. }
  970. /**
  971. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  972. * @phba: Pointer to HBA context object.
  973. * @pring: Pointer to driver SLI ring object.
  974. * @iocb: Pointer to iocb slot in the ring.
  975. * @nextiocb: Pointer to driver iocb object which need to be
  976. * posted to firmware.
  977. *
  978. * This function is called with hbalock held to post a new iocb to
  979. * the firmware. This function copies the new iocb to ring iocb slot and
  980. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  981. * a completion call back for this iocb else the function will free the
  982. * iocb object.
  983. **/
  984. static void
  985. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  986. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  987. {
  988. /*
  989. * Set up an iotag
  990. */
  991. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  992. if (pring->ringno == LPFC_ELS_RING) {
  993. lpfc_debugfs_slow_ring_trc(phba,
  994. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  995. *(((uint32_t *) &nextiocb->iocb) + 4),
  996. *(((uint32_t *) &nextiocb->iocb) + 6),
  997. *(((uint32_t *) &nextiocb->iocb) + 7));
  998. }
  999. /*
  1000. * Issue iocb command to adapter
  1001. */
  1002. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1003. wmb();
  1004. pring->stats.iocb_cmd++;
  1005. /*
  1006. * If there is no completion routine to call, we can release the
  1007. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1008. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1009. */
  1010. if (nextiocb->iocb_cmpl)
  1011. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1012. else
  1013. __lpfc_sli_release_iocbq(phba, nextiocb);
  1014. /*
  1015. * Let the HBA know what IOCB slot will be the next one the
  1016. * driver will put a command into.
  1017. */
  1018. pring->cmdidx = pring->next_cmdidx;
  1019. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1020. }
  1021. /**
  1022. * lpfc_sli_update_full_ring - Update the chip attention register
  1023. * @phba: Pointer to HBA context object.
  1024. * @pring: Pointer to driver SLI ring object.
  1025. *
  1026. * The caller is not required to hold any lock for calling this function.
  1027. * This function updates the chip attention bits for the ring to inform firmware
  1028. * that there are pending work to be done for this ring and requests an
  1029. * interrupt when there is space available in the ring. This function is
  1030. * called when the driver is unable to post more iocbs to the ring due
  1031. * to unavailability of space in the ring.
  1032. **/
  1033. static void
  1034. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1035. {
  1036. int ringno = pring->ringno;
  1037. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1038. wmb();
  1039. /*
  1040. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1041. * The HBA will tell us when an IOCB entry is available.
  1042. */
  1043. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1044. readl(phba->CAregaddr); /* flush */
  1045. pring->stats.iocb_cmd_full++;
  1046. }
  1047. /**
  1048. * lpfc_sli_update_ring - Update chip attention register
  1049. * @phba: Pointer to HBA context object.
  1050. * @pring: Pointer to driver SLI ring object.
  1051. *
  1052. * This function updates the chip attention register bit for the
  1053. * given ring to inform HBA that there is more work to be done
  1054. * in this ring. The caller is not required to hold any lock.
  1055. **/
  1056. static void
  1057. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1058. {
  1059. int ringno = pring->ringno;
  1060. /*
  1061. * Tell the HBA that there is work to do in this ring.
  1062. */
  1063. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1064. wmb();
  1065. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1066. readl(phba->CAregaddr); /* flush */
  1067. }
  1068. }
  1069. /**
  1070. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1071. * @phba: Pointer to HBA context object.
  1072. * @pring: Pointer to driver SLI ring object.
  1073. *
  1074. * This function is called with hbalock held to post pending iocbs
  1075. * in the txq to the firmware. This function is called when driver
  1076. * detects space available in the ring.
  1077. **/
  1078. static void
  1079. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1080. {
  1081. IOCB_t *iocb;
  1082. struct lpfc_iocbq *nextiocb;
  1083. /*
  1084. * Check to see if:
  1085. * (a) there is anything on the txq to send
  1086. * (b) link is up
  1087. * (c) link attention events can be processed (fcp ring only)
  1088. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1089. */
  1090. if (pring->txq_cnt &&
  1091. lpfc_is_link_up(phba) &&
  1092. (pring->ringno != phba->sli.fcp_ring ||
  1093. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1094. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1095. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1096. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1097. if (iocb)
  1098. lpfc_sli_update_ring(phba, pring);
  1099. else
  1100. lpfc_sli_update_full_ring(phba, pring);
  1101. }
  1102. return;
  1103. }
  1104. /**
  1105. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1106. * @phba: Pointer to HBA context object.
  1107. * @hbqno: HBQ number.
  1108. *
  1109. * This function is called with hbalock held to get the next
  1110. * available slot for the given HBQ. If there is free slot
  1111. * available for the HBQ it will return pointer to the next available
  1112. * HBQ entry else it will return NULL.
  1113. **/
  1114. static struct lpfc_hbq_entry *
  1115. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1116. {
  1117. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1118. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1119. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1120. hbqp->next_hbqPutIdx = 0;
  1121. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1122. uint32_t raw_index = phba->hbq_get[hbqno];
  1123. uint32_t getidx = le32_to_cpu(raw_index);
  1124. hbqp->local_hbqGetIdx = getidx;
  1125. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1126. lpfc_printf_log(phba, KERN_ERR,
  1127. LOG_SLI | LOG_VPORT,
  1128. "1802 HBQ %d: local_hbqGetIdx "
  1129. "%u is > than hbqp->entry_count %u\n",
  1130. hbqno, hbqp->local_hbqGetIdx,
  1131. hbqp->entry_count);
  1132. phba->link_state = LPFC_HBA_ERROR;
  1133. return NULL;
  1134. }
  1135. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1136. return NULL;
  1137. }
  1138. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1139. hbqp->hbqPutIdx;
  1140. }
  1141. /**
  1142. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1143. * @phba: Pointer to HBA context object.
  1144. *
  1145. * This function is called with no lock held to free all the
  1146. * hbq buffers while uninitializing the SLI interface. It also
  1147. * frees the HBQ buffers returned by the firmware but not yet
  1148. * processed by the upper layers.
  1149. **/
  1150. void
  1151. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1152. {
  1153. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1154. struct hbq_dmabuf *hbq_buf;
  1155. unsigned long flags;
  1156. int i, hbq_count;
  1157. uint32_t hbqno;
  1158. hbq_count = lpfc_sli_hbq_count();
  1159. /* Return all memory used by all HBQs */
  1160. spin_lock_irqsave(&phba->hbalock, flags);
  1161. for (i = 0; i < hbq_count; ++i) {
  1162. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1163. &phba->hbqs[i].hbq_buffer_list, list) {
  1164. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1165. list_del(&hbq_buf->dbuf.list);
  1166. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1167. }
  1168. phba->hbqs[i].buffer_count = 0;
  1169. }
  1170. /* Return all HBQ buffer that are in-fly */
  1171. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1172. list) {
  1173. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1174. list_del(&hbq_buf->dbuf.list);
  1175. if (hbq_buf->tag == -1) {
  1176. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1177. (phba, hbq_buf);
  1178. } else {
  1179. hbqno = hbq_buf->tag >> 16;
  1180. if (hbqno >= LPFC_MAX_HBQS)
  1181. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1182. (phba, hbq_buf);
  1183. else
  1184. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1185. hbq_buf);
  1186. }
  1187. }
  1188. /* Mark the HBQs not in use */
  1189. phba->hbq_in_use = 0;
  1190. spin_unlock_irqrestore(&phba->hbalock, flags);
  1191. }
  1192. /**
  1193. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1194. * @phba: Pointer to HBA context object.
  1195. * @hbqno: HBQ number.
  1196. * @hbq_buf: Pointer to HBQ buffer.
  1197. *
  1198. * This function is called with the hbalock held to post a
  1199. * hbq buffer to the firmware. If the function finds an empty
  1200. * slot in the HBQ, it will post the buffer. The function will return
  1201. * pointer to the hbq entry if it successfully post the buffer
  1202. * else it will return NULL.
  1203. **/
  1204. static int
  1205. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1206. struct hbq_dmabuf *hbq_buf)
  1207. {
  1208. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1209. }
  1210. /**
  1211. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1212. * @phba: Pointer to HBA context object.
  1213. * @hbqno: HBQ number.
  1214. * @hbq_buf: Pointer to HBQ buffer.
  1215. *
  1216. * This function is called with the hbalock held to post a hbq buffer to the
  1217. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1218. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1219. * it successfully post the buffer else it will return an error.
  1220. **/
  1221. static int
  1222. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1223. struct hbq_dmabuf *hbq_buf)
  1224. {
  1225. struct lpfc_hbq_entry *hbqe;
  1226. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1227. /* Get next HBQ entry slot to use */
  1228. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1229. if (hbqe) {
  1230. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1231. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1232. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1233. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1234. hbqe->bde.tus.f.bdeFlags = 0;
  1235. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1236. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1237. /* Sync SLIM */
  1238. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1239. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1240. /* flush */
  1241. readl(phba->hbq_put + hbqno);
  1242. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1243. return 0;
  1244. } else
  1245. return -ENOMEM;
  1246. }
  1247. /**
  1248. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1249. * @phba: Pointer to HBA context object.
  1250. * @hbqno: HBQ number.
  1251. * @hbq_buf: Pointer to HBQ buffer.
  1252. *
  1253. * This function is called with the hbalock held to post an RQE to the SLI4
  1254. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1255. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1256. **/
  1257. static int
  1258. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1259. struct hbq_dmabuf *hbq_buf)
  1260. {
  1261. int rc;
  1262. struct lpfc_rqe hrqe;
  1263. struct lpfc_rqe drqe;
  1264. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1265. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1266. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1267. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1268. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1269. &hrqe, &drqe);
  1270. if (rc < 0)
  1271. return rc;
  1272. hbq_buf->tag = rc;
  1273. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1274. return 0;
  1275. }
  1276. /* HBQ for ELS and CT traffic. */
  1277. static struct lpfc_hbq_init lpfc_els_hbq = {
  1278. .rn = 1,
  1279. .entry_count = 256,
  1280. .mask_count = 0,
  1281. .profile = 0,
  1282. .ring_mask = (1 << LPFC_ELS_RING),
  1283. .buffer_count = 0,
  1284. .init_count = 40,
  1285. .add_count = 40,
  1286. };
  1287. /* HBQ for the extra ring if needed */
  1288. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1289. .rn = 1,
  1290. .entry_count = 200,
  1291. .mask_count = 0,
  1292. .profile = 0,
  1293. .ring_mask = (1 << LPFC_EXTRA_RING),
  1294. .buffer_count = 0,
  1295. .init_count = 0,
  1296. .add_count = 5,
  1297. };
  1298. /* Array of HBQs */
  1299. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1300. &lpfc_els_hbq,
  1301. &lpfc_extra_hbq,
  1302. };
  1303. /**
  1304. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1305. * @phba: Pointer to HBA context object.
  1306. * @hbqno: HBQ number.
  1307. * @count: Number of HBQ buffers to be posted.
  1308. *
  1309. * This function is called with no lock held to post more hbq buffers to the
  1310. * given HBQ. The function returns the number of HBQ buffers successfully
  1311. * posted.
  1312. **/
  1313. static int
  1314. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1315. {
  1316. uint32_t i, posted = 0;
  1317. unsigned long flags;
  1318. struct hbq_dmabuf *hbq_buffer;
  1319. LIST_HEAD(hbq_buf_list);
  1320. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1321. return 0;
  1322. if ((phba->hbqs[hbqno].buffer_count + count) >
  1323. lpfc_hbq_defs[hbqno]->entry_count)
  1324. count = lpfc_hbq_defs[hbqno]->entry_count -
  1325. phba->hbqs[hbqno].buffer_count;
  1326. if (!count)
  1327. return 0;
  1328. /* Allocate HBQ entries */
  1329. for (i = 0; i < count; i++) {
  1330. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1331. if (!hbq_buffer)
  1332. break;
  1333. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1334. }
  1335. /* Check whether HBQ is still in use */
  1336. spin_lock_irqsave(&phba->hbalock, flags);
  1337. if (!phba->hbq_in_use)
  1338. goto err;
  1339. while (!list_empty(&hbq_buf_list)) {
  1340. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1341. dbuf.list);
  1342. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1343. (hbqno << 16));
  1344. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1345. phba->hbqs[hbqno].buffer_count++;
  1346. posted++;
  1347. } else
  1348. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1349. }
  1350. spin_unlock_irqrestore(&phba->hbalock, flags);
  1351. return posted;
  1352. err:
  1353. spin_unlock_irqrestore(&phba->hbalock, flags);
  1354. while (!list_empty(&hbq_buf_list)) {
  1355. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1356. dbuf.list);
  1357. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1358. }
  1359. return 0;
  1360. }
  1361. /**
  1362. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1363. * @phba: Pointer to HBA context object.
  1364. * @qno: HBQ number.
  1365. *
  1366. * This function posts more buffers to the HBQ. This function
  1367. * is called with no lock held. The function returns the number of HBQ entries
  1368. * successfully allocated.
  1369. **/
  1370. int
  1371. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1372. {
  1373. if (phba->sli_rev == LPFC_SLI_REV4)
  1374. return 0;
  1375. else
  1376. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1377. lpfc_hbq_defs[qno]->add_count);
  1378. }
  1379. /**
  1380. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1381. * @phba: Pointer to HBA context object.
  1382. * @qno: HBQ queue number.
  1383. *
  1384. * This function is called from SLI initialization code path with
  1385. * no lock held to post initial HBQ buffers to firmware. The
  1386. * function returns the number of HBQ entries successfully allocated.
  1387. **/
  1388. static int
  1389. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1390. {
  1391. if (phba->sli_rev == LPFC_SLI_REV4)
  1392. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1393. lpfc_hbq_defs[qno]->entry_count);
  1394. else
  1395. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1396. lpfc_hbq_defs[qno]->init_count);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1400. * @phba: Pointer to HBA context object.
  1401. * @hbqno: HBQ number.
  1402. *
  1403. * This function removes the first hbq buffer on an hbq list and returns a
  1404. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1405. **/
  1406. static struct hbq_dmabuf *
  1407. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1408. {
  1409. struct lpfc_dmabuf *d_buf;
  1410. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1411. if (!d_buf)
  1412. return NULL;
  1413. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1414. }
  1415. /**
  1416. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1417. * @phba: Pointer to HBA context object.
  1418. * @tag: Tag of the hbq buffer.
  1419. *
  1420. * This function is called with hbalock held. This function searches
  1421. * for the hbq buffer associated with the given tag in the hbq buffer
  1422. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1423. * it returns NULL.
  1424. **/
  1425. static struct hbq_dmabuf *
  1426. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1427. {
  1428. struct lpfc_dmabuf *d_buf;
  1429. struct hbq_dmabuf *hbq_buf;
  1430. uint32_t hbqno;
  1431. hbqno = tag >> 16;
  1432. if (hbqno >= LPFC_MAX_HBQS)
  1433. return NULL;
  1434. spin_lock_irq(&phba->hbalock);
  1435. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1436. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1437. if (hbq_buf->tag == tag) {
  1438. spin_unlock_irq(&phba->hbalock);
  1439. return hbq_buf;
  1440. }
  1441. }
  1442. spin_unlock_irq(&phba->hbalock);
  1443. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1444. "1803 Bad hbq tag. Data: x%x x%x\n",
  1445. tag, phba->hbqs[tag >> 16].buffer_count);
  1446. return NULL;
  1447. }
  1448. /**
  1449. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1450. * @phba: Pointer to HBA context object.
  1451. * @hbq_buffer: Pointer to HBQ buffer.
  1452. *
  1453. * This function is called with hbalock. This function gives back
  1454. * the hbq buffer to firmware. If the HBQ does not have space to
  1455. * post the buffer, it will free the buffer.
  1456. **/
  1457. void
  1458. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1459. {
  1460. uint32_t hbqno;
  1461. if (hbq_buffer) {
  1462. hbqno = hbq_buffer->tag >> 16;
  1463. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1464. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1465. }
  1466. }
  1467. /**
  1468. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1469. * @mbxCommand: mailbox command code.
  1470. *
  1471. * This function is called by the mailbox event handler function to verify
  1472. * that the completed mailbox command is a legitimate mailbox command. If the
  1473. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1474. * and the mailbox event handler will take the HBA offline.
  1475. **/
  1476. static int
  1477. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1478. {
  1479. uint8_t ret;
  1480. switch (mbxCommand) {
  1481. case MBX_LOAD_SM:
  1482. case MBX_READ_NV:
  1483. case MBX_WRITE_NV:
  1484. case MBX_WRITE_VPARMS:
  1485. case MBX_RUN_BIU_DIAG:
  1486. case MBX_INIT_LINK:
  1487. case MBX_DOWN_LINK:
  1488. case MBX_CONFIG_LINK:
  1489. case MBX_CONFIG_RING:
  1490. case MBX_RESET_RING:
  1491. case MBX_READ_CONFIG:
  1492. case MBX_READ_RCONFIG:
  1493. case MBX_READ_SPARM:
  1494. case MBX_READ_STATUS:
  1495. case MBX_READ_RPI:
  1496. case MBX_READ_XRI:
  1497. case MBX_READ_REV:
  1498. case MBX_READ_LNK_STAT:
  1499. case MBX_REG_LOGIN:
  1500. case MBX_UNREG_LOGIN:
  1501. case MBX_CLEAR_LA:
  1502. case MBX_DUMP_MEMORY:
  1503. case MBX_DUMP_CONTEXT:
  1504. case MBX_RUN_DIAGS:
  1505. case MBX_RESTART:
  1506. case MBX_UPDATE_CFG:
  1507. case MBX_DOWN_LOAD:
  1508. case MBX_DEL_LD_ENTRY:
  1509. case MBX_RUN_PROGRAM:
  1510. case MBX_SET_MASK:
  1511. case MBX_SET_VARIABLE:
  1512. case MBX_UNREG_D_ID:
  1513. case MBX_KILL_BOARD:
  1514. case MBX_CONFIG_FARP:
  1515. case MBX_BEACON:
  1516. case MBX_LOAD_AREA:
  1517. case MBX_RUN_BIU_DIAG64:
  1518. case MBX_CONFIG_PORT:
  1519. case MBX_READ_SPARM64:
  1520. case MBX_READ_RPI64:
  1521. case MBX_REG_LOGIN64:
  1522. case MBX_READ_TOPOLOGY:
  1523. case MBX_WRITE_WWN:
  1524. case MBX_SET_DEBUG:
  1525. case MBX_LOAD_EXP_ROM:
  1526. case MBX_ASYNCEVT_ENABLE:
  1527. case MBX_REG_VPI:
  1528. case MBX_UNREG_VPI:
  1529. case MBX_HEARTBEAT:
  1530. case MBX_PORT_CAPABILITIES:
  1531. case MBX_PORT_IOV_CONTROL:
  1532. case MBX_SLI4_CONFIG:
  1533. case MBX_SLI4_REQ_FTRS:
  1534. case MBX_REG_FCFI:
  1535. case MBX_UNREG_FCFI:
  1536. case MBX_REG_VFI:
  1537. case MBX_UNREG_VFI:
  1538. case MBX_INIT_VPI:
  1539. case MBX_INIT_VFI:
  1540. case MBX_RESUME_RPI:
  1541. case MBX_READ_EVENT_LOG_STATUS:
  1542. case MBX_READ_EVENT_LOG:
  1543. case MBX_SECURITY_MGMT:
  1544. case MBX_AUTH_PORT:
  1545. ret = mbxCommand;
  1546. break;
  1547. default:
  1548. ret = MBX_SHUTDOWN;
  1549. break;
  1550. }
  1551. return ret;
  1552. }
  1553. /**
  1554. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1555. * @phba: Pointer to HBA context object.
  1556. * @pmboxq: Pointer to mailbox command.
  1557. *
  1558. * This is completion handler function for mailbox commands issued from
  1559. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1560. * mailbox event handler function with no lock held. This function
  1561. * will wake up thread waiting on the wait queue pointed by context1
  1562. * of the mailbox.
  1563. **/
  1564. void
  1565. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1566. {
  1567. wait_queue_head_t *pdone_q;
  1568. unsigned long drvr_flag;
  1569. /*
  1570. * If pdone_q is empty, the driver thread gave up waiting and
  1571. * continued running.
  1572. */
  1573. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1574. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1575. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1576. if (pdone_q)
  1577. wake_up_interruptible(pdone_q);
  1578. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1579. return;
  1580. }
  1581. /**
  1582. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1583. * @phba: Pointer to HBA context object.
  1584. * @pmb: Pointer to mailbox object.
  1585. *
  1586. * This function is the default mailbox completion handler. It
  1587. * frees the memory resources associated with the completed mailbox
  1588. * command. If the completed command is a REG_LOGIN mailbox command,
  1589. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1590. **/
  1591. void
  1592. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1593. {
  1594. struct lpfc_vport *vport = pmb->vport;
  1595. struct lpfc_dmabuf *mp;
  1596. struct lpfc_nodelist *ndlp;
  1597. struct Scsi_Host *shost;
  1598. uint16_t rpi, vpi;
  1599. int rc;
  1600. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1601. if (mp) {
  1602. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1603. kfree(mp);
  1604. }
  1605. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1606. (phba->sli_rev == LPFC_SLI_REV4) &&
  1607. (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0))
  1608. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1609. /*
  1610. * If a REG_LOGIN succeeded after node is destroyed or node
  1611. * is in re-discovery driver need to cleanup the RPI.
  1612. */
  1613. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1614. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1615. !pmb->u.mb.mbxStatus) {
  1616. rpi = pmb->u.mb.un.varWords[0];
  1617. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1618. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1619. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1620. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1621. if (rc != MBX_NOT_FINISHED)
  1622. return;
  1623. }
  1624. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1625. !(phba->pport->load_flag & FC_UNLOADING) &&
  1626. !pmb->u.mb.mbxStatus) {
  1627. shost = lpfc_shost_from_vport(vport);
  1628. spin_lock_irq(shost->host_lock);
  1629. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1630. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1631. spin_unlock_irq(shost->host_lock);
  1632. }
  1633. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1634. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1635. lpfc_nlp_put(ndlp);
  1636. pmb->context2 = NULL;
  1637. }
  1638. /* Check security permission status on INIT_LINK mailbox command */
  1639. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1640. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1641. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1642. "2860 SLI authentication is required "
  1643. "for INIT_LINK but has not done yet\n");
  1644. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1645. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1646. else
  1647. mempool_free(pmb, phba->mbox_mem_pool);
  1648. }
  1649. /**
  1650. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1651. * @phba: Pointer to HBA context object.
  1652. *
  1653. * This function is called with no lock held. This function processes all
  1654. * the completed mailbox commands and gives it to upper layers. The interrupt
  1655. * service routine processes mailbox completion interrupt and adds completed
  1656. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1657. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1658. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1659. * function returns the mailbox commands to the upper layer by calling the
  1660. * completion handler function of each mailbox.
  1661. **/
  1662. int
  1663. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1664. {
  1665. MAILBOX_t *pmbox;
  1666. LPFC_MBOXQ_t *pmb;
  1667. int rc;
  1668. LIST_HEAD(cmplq);
  1669. phba->sli.slistat.mbox_event++;
  1670. /* Get all completed mailboxe buffers into the cmplq */
  1671. spin_lock_irq(&phba->hbalock);
  1672. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1673. spin_unlock_irq(&phba->hbalock);
  1674. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1675. do {
  1676. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1677. if (pmb == NULL)
  1678. break;
  1679. pmbox = &pmb->u.mb;
  1680. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1681. if (pmb->vport) {
  1682. lpfc_debugfs_disc_trc(pmb->vport,
  1683. LPFC_DISC_TRC_MBOX_VPORT,
  1684. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1685. (uint32_t)pmbox->mbxCommand,
  1686. pmbox->un.varWords[0],
  1687. pmbox->un.varWords[1]);
  1688. }
  1689. else {
  1690. lpfc_debugfs_disc_trc(phba->pport,
  1691. LPFC_DISC_TRC_MBOX,
  1692. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1693. (uint32_t)pmbox->mbxCommand,
  1694. pmbox->un.varWords[0],
  1695. pmbox->un.varWords[1]);
  1696. }
  1697. }
  1698. /*
  1699. * It is a fatal error if unknown mbox command completion.
  1700. */
  1701. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1702. MBX_SHUTDOWN) {
  1703. /* Unknown mailbox command compl */
  1704. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1705. "(%d):0323 Unknown Mailbox command "
  1706. "x%x (x%x) Cmpl\n",
  1707. pmb->vport ? pmb->vport->vpi : 0,
  1708. pmbox->mbxCommand,
  1709. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1710. phba->link_state = LPFC_HBA_ERROR;
  1711. phba->work_hs = HS_FFER3;
  1712. lpfc_handle_eratt(phba);
  1713. continue;
  1714. }
  1715. if (pmbox->mbxStatus) {
  1716. phba->sli.slistat.mbox_stat_err++;
  1717. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1718. /* Mbox cmd cmpl error - RETRYing */
  1719. lpfc_printf_log(phba, KERN_INFO,
  1720. LOG_MBOX | LOG_SLI,
  1721. "(%d):0305 Mbox cmd cmpl "
  1722. "error - RETRYing Data: x%x "
  1723. "(x%x) x%x x%x x%x\n",
  1724. pmb->vport ? pmb->vport->vpi :0,
  1725. pmbox->mbxCommand,
  1726. lpfc_sli4_mbox_opcode_get(phba,
  1727. pmb),
  1728. pmbox->mbxStatus,
  1729. pmbox->un.varWords[0],
  1730. pmb->vport->port_state);
  1731. pmbox->mbxStatus = 0;
  1732. pmbox->mbxOwner = OWN_HOST;
  1733. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1734. if (rc != MBX_NOT_FINISHED)
  1735. continue;
  1736. }
  1737. }
  1738. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1739. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1740. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1741. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1742. pmb->vport ? pmb->vport->vpi : 0,
  1743. pmbox->mbxCommand,
  1744. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1745. pmb->mbox_cmpl,
  1746. *((uint32_t *) pmbox),
  1747. pmbox->un.varWords[0],
  1748. pmbox->un.varWords[1],
  1749. pmbox->un.varWords[2],
  1750. pmbox->un.varWords[3],
  1751. pmbox->un.varWords[4],
  1752. pmbox->un.varWords[5],
  1753. pmbox->un.varWords[6],
  1754. pmbox->un.varWords[7]);
  1755. if (pmb->mbox_cmpl)
  1756. pmb->mbox_cmpl(phba,pmb);
  1757. } while (1);
  1758. return 0;
  1759. }
  1760. /**
  1761. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1762. * @phba: Pointer to HBA context object.
  1763. * @pring: Pointer to driver SLI ring object.
  1764. * @tag: buffer tag.
  1765. *
  1766. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1767. * is set in the tag the buffer is posted for a particular exchange,
  1768. * the function will return the buffer without replacing the buffer.
  1769. * If the buffer is for unsolicited ELS or CT traffic, this function
  1770. * returns the buffer and also posts another buffer to the firmware.
  1771. **/
  1772. static struct lpfc_dmabuf *
  1773. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1774. struct lpfc_sli_ring *pring,
  1775. uint32_t tag)
  1776. {
  1777. struct hbq_dmabuf *hbq_entry;
  1778. if (tag & QUE_BUFTAG_BIT)
  1779. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1780. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1781. if (!hbq_entry)
  1782. return NULL;
  1783. return &hbq_entry->dbuf;
  1784. }
  1785. /**
  1786. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1787. * @phba: Pointer to HBA context object.
  1788. * @pring: Pointer to driver SLI ring object.
  1789. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1790. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1791. * @fch_type: the type for the first frame of the sequence.
  1792. *
  1793. * This function is called with no lock held. This function uses the r_ctl and
  1794. * type of the received sequence to find the correct callback function to call
  1795. * to process the sequence.
  1796. **/
  1797. static int
  1798. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1799. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1800. uint32_t fch_type)
  1801. {
  1802. int i;
  1803. /* unSolicited Responses */
  1804. if (pring->prt[0].profile) {
  1805. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1806. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1807. saveq);
  1808. return 1;
  1809. }
  1810. /* We must search, based on rctl / type
  1811. for the right routine */
  1812. for (i = 0; i < pring->num_mask; i++) {
  1813. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1814. (pring->prt[i].type == fch_type)) {
  1815. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1816. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1817. (phba, pring, saveq);
  1818. return 1;
  1819. }
  1820. }
  1821. return 0;
  1822. }
  1823. /**
  1824. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1825. * @phba: Pointer to HBA context object.
  1826. * @pring: Pointer to driver SLI ring object.
  1827. * @saveq: Pointer to the unsolicited iocb.
  1828. *
  1829. * This function is called with no lock held by the ring event handler
  1830. * when there is an unsolicited iocb posted to the response ring by the
  1831. * firmware. This function gets the buffer associated with the iocbs
  1832. * and calls the event handler for the ring. This function handles both
  1833. * qring buffers and hbq buffers.
  1834. * When the function returns 1 the caller can free the iocb object otherwise
  1835. * upper layer functions will free the iocb objects.
  1836. **/
  1837. static int
  1838. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1839. struct lpfc_iocbq *saveq)
  1840. {
  1841. IOCB_t * irsp;
  1842. WORD5 * w5p;
  1843. uint32_t Rctl, Type;
  1844. uint32_t match;
  1845. struct lpfc_iocbq *iocbq;
  1846. struct lpfc_dmabuf *dmzbuf;
  1847. match = 0;
  1848. irsp = &(saveq->iocb);
  1849. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1850. if (pring->lpfc_sli_rcv_async_status)
  1851. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1852. else
  1853. lpfc_printf_log(phba,
  1854. KERN_WARNING,
  1855. LOG_SLI,
  1856. "0316 Ring %d handler: unexpected "
  1857. "ASYNC_STATUS iocb received evt_code "
  1858. "0x%x\n",
  1859. pring->ringno,
  1860. irsp->un.asyncstat.evt_code);
  1861. return 1;
  1862. }
  1863. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1864. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1865. if (irsp->ulpBdeCount > 0) {
  1866. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1867. irsp->un.ulpWord[3]);
  1868. lpfc_in_buf_free(phba, dmzbuf);
  1869. }
  1870. if (irsp->ulpBdeCount > 1) {
  1871. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1872. irsp->unsli3.sli3Words[3]);
  1873. lpfc_in_buf_free(phba, dmzbuf);
  1874. }
  1875. if (irsp->ulpBdeCount > 2) {
  1876. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1877. irsp->unsli3.sli3Words[7]);
  1878. lpfc_in_buf_free(phba, dmzbuf);
  1879. }
  1880. return 1;
  1881. }
  1882. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1883. if (irsp->ulpBdeCount != 0) {
  1884. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1885. irsp->un.ulpWord[3]);
  1886. if (!saveq->context2)
  1887. lpfc_printf_log(phba,
  1888. KERN_ERR,
  1889. LOG_SLI,
  1890. "0341 Ring %d Cannot find buffer for "
  1891. "an unsolicited iocb. tag 0x%x\n",
  1892. pring->ringno,
  1893. irsp->un.ulpWord[3]);
  1894. }
  1895. if (irsp->ulpBdeCount == 2) {
  1896. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1897. irsp->unsli3.sli3Words[7]);
  1898. if (!saveq->context3)
  1899. lpfc_printf_log(phba,
  1900. KERN_ERR,
  1901. LOG_SLI,
  1902. "0342 Ring %d Cannot find buffer for an"
  1903. " unsolicited iocb. tag 0x%x\n",
  1904. pring->ringno,
  1905. irsp->unsli3.sli3Words[7]);
  1906. }
  1907. list_for_each_entry(iocbq, &saveq->list, list) {
  1908. irsp = &(iocbq->iocb);
  1909. if (irsp->ulpBdeCount != 0) {
  1910. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1911. irsp->un.ulpWord[3]);
  1912. if (!iocbq->context2)
  1913. lpfc_printf_log(phba,
  1914. KERN_ERR,
  1915. LOG_SLI,
  1916. "0343 Ring %d Cannot find "
  1917. "buffer for an unsolicited iocb"
  1918. ". tag 0x%x\n", pring->ringno,
  1919. irsp->un.ulpWord[3]);
  1920. }
  1921. if (irsp->ulpBdeCount == 2) {
  1922. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1923. irsp->unsli3.sli3Words[7]);
  1924. if (!iocbq->context3)
  1925. lpfc_printf_log(phba,
  1926. KERN_ERR,
  1927. LOG_SLI,
  1928. "0344 Ring %d Cannot find "
  1929. "buffer for an unsolicited "
  1930. "iocb. tag 0x%x\n",
  1931. pring->ringno,
  1932. irsp->unsli3.sli3Words[7]);
  1933. }
  1934. }
  1935. }
  1936. if (irsp->ulpBdeCount != 0 &&
  1937. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1938. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1939. int found = 0;
  1940. /* search continue save q for same XRI */
  1941. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1942. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1943. list_add_tail(&saveq->list, &iocbq->list);
  1944. found = 1;
  1945. break;
  1946. }
  1947. }
  1948. if (!found)
  1949. list_add_tail(&saveq->clist,
  1950. &pring->iocb_continue_saveq);
  1951. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1952. list_del_init(&iocbq->clist);
  1953. saveq = iocbq;
  1954. irsp = &(saveq->iocb);
  1955. } else
  1956. return 0;
  1957. }
  1958. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1959. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1960. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1961. Rctl = FC_RCTL_ELS_REQ;
  1962. Type = FC_TYPE_ELS;
  1963. } else {
  1964. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1965. Rctl = w5p->hcsw.Rctl;
  1966. Type = w5p->hcsw.Type;
  1967. /* Firmware Workaround */
  1968. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1969. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1970. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1971. Rctl = FC_RCTL_ELS_REQ;
  1972. Type = FC_TYPE_ELS;
  1973. w5p->hcsw.Rctl = Rctl;
  1974. w5p->hcsw.Type = Type;
  1975. }
  1976. }
  1977. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1978. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1979. "0313 Ring %d handler: unexpected Rctl x%x "
  1980. "Type x%x received\n",
  1981. pring->ringno, Rctl, Type);
  1982. return 1;
  1983. }
  1984. /**
  1985. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1986. * @phba: Pointer to HBA context object.
  1987. * @pring: Pointer to driver SLI ring object.
  1988. * @prspiocb: Pointer to response iocb object.
  1989. *
  1990. * This function looks up the iocb_lookup table to get the command iocb
  1991. * corresponding to the given response iocb using the iotag of the
  1992. * response iocb. This function is called with the hbalock held.
  1993. * This function returns the command iocb object if it finds the command
  1994. * iocb else returns NULL.
  1995. **/
  1996. static struct lpfc_iocbq *
  1997. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1998. struct lpfc_sli_ring *pring,
  1999. struct lpfc_iocbq *prspiocb)
  2000. {
  2001. struct lpfc_iocbq *cmd_iocb = NULL;
  2002. uint16_t iotag;
  2003. iotag = prspiocb->iocb.ulpIoTag;
  2004. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2005. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2006. list_del_init(&cmd_iocb->list);
  2007. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2008. pring->txcmplq_cnt--;
  2009. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2010. }
  2011. return cmd_iocb;
  2012. }
  2013. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2014. "0317 iotag x%x is out off "
  2015. "range: max iotag x%x wd0 x%x\n",
  2016. iotag, phba->sli.last_iotag,
  2017. *(((uint32_t *) &prspiocb->iocb) + 7));
  2018. return NULL;
  2019. }
  2020. /**
  2021. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2022. * @phba: Pointer to HBA context object.
  2023. * @pring: Pointer to driver SLI ring object.
  2024. * @iotag: IOCB tag.
  2025. *
  2026. * This function looks up the iocb_lookup table to get the command iocb
  2027. * corresponding to the given iotag. This function is called with the
  2028. * hbalock held.
  2029. * This function returns the command iocb object if it finds the command
  2030. * iocb else returns NULL.
  2031. **/
  2032. static struct lpfc_iocbq *
  2033. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2034. struct lpfc_sli_ring *pring, uint16_t iotag)
  2035. {
  2036. struct lpfc_iocbq *cmd_iocb;
  2037. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2038. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2039. list_del_init(&cmd_iocb->list);
  2040. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2041. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2042. pring->txcmplq_cnt--;
  2043. }
  2044. return cmd_iocb;
  2045. }
  2046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2047. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2048. iotag, phba->sli.last_iotag);
  2049. return NULL;
  2050. }
  2051. /**
  2052. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2053. * @phba: Pointer to HBA context object.
  2054. * @pring: Pointer to driver SLI ring object.
  2055. * @saveq: Pointer to the response iocb to be processed.
  2056. *
  2057. * This function is called by the ring event handler for non-fcp
  2058. * rings when there is a new response iocb in the response ring.
  2059. * The caller is not required to hold any locks. This function
  2060. * gets the command iocb associated with the response iocb and
  2061. * calls the completion handler for the command iocb. If there
  2062. * is no completion handler, the function will free the resources
  2063. * associated with command iocb. If the response iocb is for
  2064. * an already aborted command iocb, the status of the completion
  2065. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2066. * This function always returns 1.
  2067. **/
  2068. static int
  2069. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2070. struct lpfc_iocbq *saveq)
  2071. {
  2072. struct lpfc_iocbq *cmdiocbp;
  2073. int rc = 1;
  2074. unsigned long iflag;
  2075. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2076. spin_lock_irqsave(&phba->hbalock, iflag);
  2077. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2078. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2079. if (cmdiocbp) {
  2080. if (cmdiocbp->iocb_cmpl) {
  2081. /*
  2082. * If an ELS command failed send an event to mgmt
  2083. * application.
  2084. */
  2085. if (saveq->iocb.ulpStatus &&
  2086. (pring->ringno == LPFC_ELS_RING) &&
  2087. (cmdiocbp->iocb.ulpCommand ==
  2088. CMD_ELS_REQUEST64_CR))
  2089. lpfc_send_els_failure_event(phba,
  2090. cmdiocbp, saveq);
  2091. /*
  2092. * Post all ELS completions to the worker thread.
  2093. * All other are passed to the completion callback.
  2094. */
  2095. if (pring->ringno == LPFC_ELS_RING) {
  2096. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2097. (cmdiocbp->iocb_flag &
  2098. LPFC_DRIVER_ABORTED)) {
  2099. spin_lock_irqsave(&phba->hbalock,
  2100. iflag);
  2101. cmdiocbp->iocb_flag &=
  2102. ~LPFC_DRIVER_ABORTED;
  2103. spin_unlock_irqrestore(&phba->hbalock,
  2104. iflag);
  2105. saveq->iocb.ulpStatus =
  2106. IOSTAT_LOCAL_REJECT;
  2107. saveq->iocb.un.ulpWord[4] =
  2108. IOERR_SLI_ABORTED;
  2109. /* Firmware could still be in progress
  2110. * of DMAing payload, so don't free data
  2111. * buffer till after a hbeat.
  2112. */
  2113. spin_lock_irqsave(&phba->hbalock,
  2114. iflag);
  2115. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2116. spin_unlock_irqrestore(&phba->hbalock,
  2117. iflag);
  2118. }
  2119. if (phba->sli_rev == LPFC_SLI_REV4) {
  2120. if (saveq->iocb_flag &
  2121. LPFC_EXCHANGE_BUSY) {
  2122. /* Set cmdiocb flag for the
  2123. * exchange busy so sgl (xri)
  2124. * will not be released until
  2125. * the abort xri is received
  2126. * from hba.
  2127. */
  2128. spin_lock_irqsave(
  2129. &phba->hbalock, iflag);
  2130. cmdiocbp->iocb_flag |=
  2131. LPFC_EXCHANGE_BUSY;
  2132. spin_unlock_irqrestore(
  2133. &phba->hbalock, iflag);
  2134. }
  2135. if (cmdiocbp->iocb_flag &
  2136. LPFC_DRIVER_ABORTED) {
  2137. /*
  2138. * Clear LPFC_DRIVER_ABORTED
  2139. * bit in case it was driver
  2140. * initiated abort.
  2141. */
  2142. spin_lock_irqsave(
  2143. &phba->hbalock, iflag);
  2144. cmdiocbp->iocb_flag &=
  2145. ~LPFC_DRIVER_ABORTED;
  2146. spin_unlock_irqrestore(
  2147. &phba->hbalock, iflag);
  2148. cmdiocbp->iocb.ulpStatus =
  2149. IOSTAT_LOCAL_REJECT;
  2150. cmdiocbp->iocb.un.ulpWord[4] =
  2151. IOERR_ABORT_REQUESTED;
  2152. /*
  2153. * For SLI4, irsiocb contains
  2154. * NO_XRI in sli_xritag, it
  2155. * shall not affect releasing
  2156. * sgl (xri) process.
  2157. */
  2158. saveq->iocb.ulpStatus =
  2159. IOSTAT_LOCAL_REJECT;
  2160. saveq->iocb.un.ulpWord[4] =
  2161. IOERR_SLI_ABORTED;
  2162. spin_lock_irqsave(
  2163. &phba->hbalock, iflag);
  2164. saveq->iocb_flag |=
  2165. LPFC_DELAY_MEM_FREE;
  2166. spin_unlock_irqrestore(
  2167. &phba->hbalock, iflag);
  2168. }
  2169. }
  2170. }
  2171. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2172. } else
  2173. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2174. } else {
  2175. /*
  2176. * Unknown initiating command based on the response iotag.
  2177. * This could be the case on the ELS ring because of
  2178. * lpfc_els_abort().
  2179. */
  2180. if (pring->ringno != LPFC_ELS_RING) {
  2181. /*
  2182. * Ring <ringno> handler: unexpected completion IoTag
  2183. * <IoTag>
  2184. */
  2185. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2186. "0322 Ring %d handler: "
  2187. "unexpected completion IoTag x%x "
  2188. "Data: x%x x%x x%x x%x\n",
  2189. pring->ringno,
  2190. saveq->iocb.ulpIoTag,
  2191. saveq->iocb.ulpStatus,
  2192. saveq->iocb.un.ulpWord[4],
  2193. saveq->iocb.ulpCommand,
  2194. saveq->iocb.ulpContext);
  2195. }
  2196. }
  2197. return rc;
  2198. }
  2199. /**
  2200. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2201. * @phba: Pointer to HBA context object.
  2202. * @pring: Pointer to driver SLI ring object.
  2203. *
  2204. * This function is called from the iocb ring event handlers when
  2205. * put pointer is ahead of the get pointer for a ring. This function signal
  2206. * an error attention condition to the worker thread and the worker
  2207. * thread will transition the HBA to offline state.
  2208. **/
  2209. static void
  2210. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2211. {
  2212. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2213. /*
  2214. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2215. * rsp ring <portRspMax>
  2216. */
  2217. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2218. "0312 Ring %d handler: portRspPut %d "
  2219. "is bigger than rsp ring %d\n",
  2220. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2221. pring->numRiocb);
  2222. phba->link_state = LPFC_HBA_ERROR;
  2223. /*
  2224. * All error attention handlers are posted to
  2225. * worker thread
  2226. */
  2227. phba->work_ha |= HA_ERATT;
  2228. phba->work_hs = HS_FFER3;
  2229. lpfc_worker_wake_up(phba);
  2230. return;
  2231. }
  2232. /**
  2233. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2234. * @ptr: Pointer to address of HBA context object.
  2235. *
  2236. * This function is invoked by the Error Attention polling timer when the
  2237. * timer times out. It will check the SLI Error Attention register for
  2238. * possible attention events. If so, it will post an Error Attention event
  2239. * and wake up worker thread to process it. Otherwise, it will set up the
  2240. * Error Attention polling timer for the next poll.
  2241. **/
  2242. void lpfc_poll_eratt(unsigned long ptr)
  2243. {
  2244. struct lpfc_hba *phba;
  2245. uint32_t eratt = 0;
  2246. phba = (struct lpfc_hba *)ptr;
  2247. /* Check chip HA register for error event */
  2248. eratt = lpfc_sli_check_eratt(phba);
  2249. if (eratt)
  2250. /* Tell the worker thread there is work to do */
  2251. lpfc_worker_wake_up(phba);
  2252. else
  2253. /* Restart the timer for next eratt poll */
  2254. mod_timer(&phba->eratt_poll, jiffies +
  2255. HZ * LPFC_ERATT_POLL_INTERVAL);
  2256. return;
  2257. }
  2258. /**
  2259. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2260. * @phba: Pointer to HBA context object.
  2261. * @pring: Pointer to driver SLI ring object.
  2262. * @mask: Host attention register mask for this ring.
  2263. *
  2264. * This function is called from the interrupt context when there is a ring
  2265. * event for the fcp ring. The caller does not hold any lock.
  2266. * The function processes each response iocb in the response ring until it
  2267. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2268. * LE bit set. The function will call the completion handler of the command iocb
  2269. * if the response iocb indicates a completion for a command iocb or it is
  2270. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2271. * function if this is an unsolicited iocb.
  2272. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2273. * to check it explicitly.
  2274. */
  2275. int
  2276. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2277. struct lpfc_sli_ring *pring, uint32_t mask)
  2278. {
  2279. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2280. IOCB_t *irsp = NULL;
  2281. IOCB_t *entry = NULL;
  2282. struct lpfc_iocbq *cmdiocbq = NULL;
  2283. struct lpfc_iocbq rspiocbq;
  2284. uint32_t status;
  2285. uint32_t portRspPut, portRspMax;
  2286. int rc = 1;
  2287. lpfc_iocb_type type;
  2288. unsigned long iflag;
  2289. uint32_t rsp_cmpl = 0;
  2290. spin_lock_irqsave(&phba->hbalock, iflag);
  2291. pring->stats.iocb_event++;
  2292. /*
  2293. * The next available response entry should never exceed the maximum
  2294. * entries. If it does, treat it as an adapter hardware error.
  2295. */
  2296. portRspMax = pring->numRiocb;
  2297. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2298. if (unlikely(portRspPut >= portRspMax)) {
  2299. lpfc_sli_rsp_pointers_error(phba, pring);
  2300. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2301. return 1;
  2302. }
  2303. if (phba->fcp_ring_in_use) {
  2304. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2305. return 1;
  2306. } else
  2307. phba->fcp_ring_in_use = 1;
  2308. rmb();
  2309. while (pring->rspidx != portRspPut) {
  2310. /*
  2311. * Fetch an entry off the ring and copy it into a local data
  2312. * structure. The copy involves a byte-swap since the
  2313. * network byte order and pci byte orders are different.
  2314. */
  2315. entry = lpfc_resp_iocb(phba, pring);
  2316. phba->last_completion_time = jiffies;
  2317. if (++pring->rspidx >= portRspMax)
  2318. pring->rspidx = 0;
  2319. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2320. (uint32_t *) &rspiocbq.iocb,
  2321. phba->iocb_rsp_size);
  2322. INIT_LIST_HEAD(&(rspiocbq.list));
  2323. irsp = &rspiocbq.iocb;
  2324. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2325. pring->stats.iocb_rsp++;
  2326. rsp_cmpl++;
  2327. if (unlikely(irsp->ulpStatus)) {
  2328. /*
  2329. * If resource errors reported from HBA, reduce
  2330. * queuedepths of the SCSI device.
  2331. */
  2332. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2333. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2334. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2335. phba->lpfc_rampdown_queue_depth(phba);
  2336. spin_lock_irqsave(&phba->hbalock, iflag);
  2337. }
  2338. /* Rsp ring <ringno> error: IOCB */
  2339. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2340. "0336 Rsp Ring %d error: IOCB Data: "
  2341. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2342. pring->ringno,
  2343. irsp->un.ulpWord[0],
  2344. irsp->un.ulpWord[1],
  2345. irsp->un.ulpWord[2],
  2346. irsp->un.ulpWord[3],
  2347. irsp->un.ulpWord[4],
  2348. irsp->un.ulpWord[5],
  2349. *(uint32_t *)&irsp->un1,
  2350. *((uint32_t *)&irsp->un1 + 1));
  2351. }
  2352. switch (type) {
  2353. case LPFC_ABORT_IOCB:
  2354. case LPFC_SOL_IOCB:
  2355. /*
  2356. * Idle exchange closed via ABTS from port. No iocb
  2357. * resources need to be recovered.
  2358. */
  2359. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2360. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2361. "0333 IOCB cmd 0x%x"
  2362. " processed. Skipping"
  2363. " completion\n",
  2364. irsp->ulpCommand);
  2365. break;
  2366. }
  2367. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2368. &rspiocbq);
  2369. if (unlikely(!cmdiocbq))
  2370. break;
  2371. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2372. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2373. if (cmdiocbq->iocb_cmpl) {
  2374. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2375. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2376. &rspiocbq);
  2377. spin_lock_irqsave(&phba->hbalock, iflag);
  2378. }
  2379. break;
  2380. case LPFC_UNSOL_IOCB:
  2381. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2382. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2383. spin_lock_irqsave(&phba->hbalock, iflag);
  2384. break;
  2385. default:
  2386. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2387. char adaptermsg[LPFC_MAX_ADPTMSG];
  2388. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2389. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2390. MAX_MSG_DATA);
  2391. dev_warn(&((phba->pcidev)->dev),
  2392. "lpfc%d: %s\n",
  2393. phba->brd_no, adaptermsg);
  2394. } else {
  2395. /* Unknown IOCB command */
  2396. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2397. "0334 Unknown IOCB command "
  2398. "Data: x%x, x%x x%x x%x x%x\n",
  2399. type, irsp->ulpCommand,
  2400. irsp->ulpStatus,
  2401. irsp->ulpIoTag,
  2402. irsp->ulpContext);
  2403. }
  2404. break;
  2405. }
  2406. /*
  2407. * The response IOCB has been processed. Update the ring
  2408. * pointer in SLIM. If the port response put pointer has not
  2409. * been updated, sync the pgp->rspPutInx and fetch the new port
  2410. * response put pointer.
  2411. */
  2412. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2413. if (pring->rspidx == portRspPut)
  2414. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2415. }
  2416. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2417. pring->stats.iocb_rsp_full++;
  2418. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2419. writel(status, phba->CAregaddr);
  2420. readl(phba->CAregaddr);
  2421. }
  2422. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2423. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2424. pring->stats.iocb_cmd_empty++;
  2425. /* Force update of the local copy of cmdGetInx */
  2426. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2427. lpfc_sli_resume_iocb(phba, pring);
  2428. if ((pring->lpfc_sli_cmd_available))
  2429. (pring->lpfc_sli_cmd_available) (phba, pring);
  2430. }
  2431. phba->fcp_ring_in_use = 0;
  2432. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2433. return rc;
  2434. }
  2435. /**
  2436. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2437. * @phba: Pointer to HBA context object.
  2438. * @pring: Pointer to driver SLI ring object.
  2439. * @rspiocbp: Pointer to driver response IOCB object.
  2440. *
  2441. * This function is called from the worker thread when there is a slow-path
  2442. * response IOCB to process. This function chains all the response iocbs until
  2443. * seeing the iocb with the LE bit set. The function will call
  2444. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2445. * completion of a command iocb. The function will call the
  2446. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2447. * The function frees the resources or calls the completion handler if this
  2448. * iocb is an abort completion. The function returns NULL when the response
  2449. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2450. * this function shall chain the iocb on to the iocb_continueq and return the
  2451. * response iocb passed in.
  2452. **/
  2453. static struct lpfc_iocbq *
  2454. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2455. struct lpfc_iocbq *rspiocbp)
  2456. {
  2457. struct lpfc_iocbq *saveq;
  2458. struct lpfc_iocbq *cmdiocbp;
  2459. struct lpfc_iocbq *next_iocb;
  2460. IOCB_t *irsp = NULL;
  2461. uint32_t free_saveq;
  2462. uint8_t iocb_cmd_type;
  2463. lpfc_iocb_type type;
  2464. unsigned long iflag;
  2465. int rc;
  2466. spin_lock_irqsave(&phba->hbalock, iflag);
  2467. /* First add the response iocb to the countinueq list */
  2468. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2469. pring->iocb_continueq_cnt++;
  2470. /* Now, determine whetehr the list is completed for processing */
  2471. irsp = &rspiocbp->iocb;
  2472. if (irsp->ulpLe) {
  2473. /*
  2474. * By default, the driver expects to free all resources
  2475. * associated with this iocb completion.
  2476. */
  2477. free_saveq = 1;
  2478. saveq = list_get_first(&pring->iocb_continueq,
  2479. struct lpfc_iocbq, list);
  2480. irsp = &(saveq->iocb);
  2481. list_del_init(&pring->iocb_continueq);
  2482. pring->iocb_continueq_cnt = 0;
  2483. pring->stats.iocb_rsp++;
  2484. /*
  2485. * If resource errors reported from HBA, reduce
  2486. * queuedepths of the SCSI device.
  2487. */
  2488. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2489. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2490. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2491. phba->lpfc_rampdown_queue_depth(phba);
  2492. spin_lock_irqsave(&phba->hbalock, iflag);
  2493. }
  2494. if (irsp->ulpStatus) {
  2495. /* Rsp ring <ringno> error: IOCB */
  2496. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2497. "0328 Rsp Ring %d error: "
  2498. "IOCB Data: "
  2499. "x%x x%x x%x x%x "
  2500. "x%x x%x x%x x%x "
  2501. "x%x x%x x%x x%x "
  2502. "x%x x%x x%x x%x\n",
  2503. pring->ringno,
  2504. irsp->un.ulpWord[0],
  2505. irsp->un.ulpWord[1],
  2506. irsp->un.ulpWord[2],
  2507. irsp->un.ulpWord[3],
  2508. irsp->un.ulpWord[4],
  2509. irsp->un.ulpWord[5],
  2510. *(((uint32_t *) irsp) + 6),
  2511. *(((uint32_t *) irsp) + 7),
  2512. *(((uint32_t *) irsp) + 8),
  2513. *(((uint32_t *) irsp) + 9),
  2514. *(((uint32_t *) irsp) + 10),
  2515. *(((uint32_t *) irsp) + 11),
  2516. *(((uint32_t *) irsp) + 12),
  2517. *(((uint32_t *) irsp) + 13),
  2518. *(((uint32_t *) irsp) + 14),
  2519. *(((uint32_t *) irsp) + 15));
  2520. }
  2521. /*
  2522. * Fetch the IOCB command type and call the correct completion
  2523. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2524. * get freed back to the lpfc_iocb_list by the discovery
  2525. * kernel thread.
  2526. */
  2527. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2528. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2529. switch (type) {
  2530. case LPFC_SOL_IOCB:
  2531. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2532. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2533. spin_lock_irqsave(&phba->hbalock, iflag);
  2534. break;
  2535. case LPFC_UNSOL_IOCB:
  2536. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2537. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2538. spin_lock_irqsave(&phba->hbalock, iflag);
  2539. if (!rc)
  2540. free_saveq = 0;
  2541. break;
  2542. case LPFC_ABORT_IOCB:
  2543. cmdiocbp = NULL;
  2544. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2545. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2546. saveq);
  2547. if (cmdiocbp) {
  2548. /* Call the specified completion routine */
  2549. if (cmdiocbp->iocb_cmpl) {
  2550. spin_unlock_irqrestore(&phba->hbalock,
  2551. iflag);
  2552. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2553. saveq);
  2554. spin_lock_irqsave(&phba->hbalock,
  2555. iflag);
  2556. } else
  2557. __lpfc_sli_release_iocbq(phba,
  2558. cmdiocbp);
  2559. }
  2560. break;
  2561. case LPFC_UNKNOWN_IOCB:
  2562. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2563. char adaptermsg[LPFC_MAX_ADPTMSG];
  2564. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2565. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2566. MAX_MSG_DATA);
  2567. dev_warn(&((phba->pcidev)->dev),
  2568. "lpfc%d: %s\n",
  2569. phba->brd_no, adaptermsg);
  2570. } else {
  2571. /* Unknown IOCB command */
  2572. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2573. "0335 Unknown IOCB "
  2574. "command Data: x%x "
  2575. "x%x x%x x%x\n",
  2576. irsp->ulpCommand,
  2577. irsp->ulpStatus,
  2578. irsp->ulpIoTag,
  2579. irsp->ulpContext);
  2580. }
  2581. break;
  2582. }
  2583. if (free_saveq) {
  2584. list_for_each_entry_safe(rspiocbp, next_iocb,
  2585. &saveq->list, list) {
  2586. list_del(&rspiocbp->list);
  2587. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2588. }
  2589. __lpfc_sli_release_iocbq(phba, saveq);
  2590. }
  2591. rspiocbp = NULL;
  2592. }
  2593. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2594. return rspiocbp;
  2595. }
  2596. /**
  2597. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2598. * @phba: Pointer to HBA context object.
  2599. * @pring: Pointer to driver SLI ring object.
  2600. * @mask: Host attention register mask for this ring.
  2601. *
  2602. * This routine wraps the actual slow_ring event process routine from the
  2603. * API jump table function pointer from the lpfc_hba struct.
  2604. **/
  2605. void
  2606. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2607. struct lpfc_sli_ring *pring, uint32_t mask)
  2608. {
  2609. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2610. }
  2611. /**
  2612. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2613. * @phba: Pointer to HBA context object.
  2614. * @pring: Pointer to driver SLI ring object.
  2615. * @mask: Host attention register mask for this ring.
  2616. *
  2617. * This function is called from the worker thread when there is a ring event
  2618. * for non-fcp rings. The caller does not hold any lock. The function will
  2619. * remove each response iocb in the response ring and calls the handle
  2620. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2621. **/
  2622. static void
  2623. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2624. struct lpfc_sli_ring *pring, uint32_t mask)
  2625. {
  2626. struct lpfc_pgp *pgp;
  2627. IOCB_t *entry;
  2628. IOCB_t *irsp = NULL;
  2629. struct lpfc_iocbq *rspiocbp = NULL;
  2630. uint32_t portRspPut, portRspMax;
  2631. unsigned long iflag;
  2632. uint32_t status;
  2633. pgp = &phba->port_gp[pring->ringno];
  2634. spin_lock_irqsave(&phba->hbalock, iflag);
  2635. pring->stats.iocb_event++;
  2636. /*
  2637. * The next available response entry should never exceed the maximum
  2638. * entries. If it does, treat it as an adapter hardware error.
  2639. */
  2640. portRspMax = pring->numRiocb;
  2641. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2642. if (portRspPut >= portRspMax) {
  2643. /*
  2644. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2645. * rsp ring <portRspMax>
  2646. */
  2647. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2648. "0303 Ring %d handler: portRspPut %d "
  2649. "is bigger than rsp ring %d\n",
  2650. pring->ringno, portRspPut, portRspMax);
  2651. phba->link_state = LPFC_HBA_ERROR;
  2652. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2653. phba->work_hs = HS_FFER3;
  2654. lpfc_handle_eratt(phba);
  2655. return;
  2656. }
  2657. rmb();
  2658. while (pring->rspidx != portRspPut) {
  2659. /*
  2660. * Build a completion list and call the appropriate handler.
  2661. * The process is to get the next available response iocb, get
  2662. * a free iocb from the list, copy the response data into the
  2663. * free iocb, insert to the continuation list, and update the
  2664. * next response index to slim. This process makes response
  2665. * iocb's in the ring available to DMA as fast as possible but
  2666. * pays a penalty for a copy operation. Since the iocb is
  2667. * only 32 bytes, this penalty is considered small relative to
  2668. * the PCI reads for register values and a slim write. When
  2669. * the ulpLe field is set, the entire Command has been
  2670. * received.
  2671. */
  2672. entry = lpfc_resp_iocb(phba, pring);
  2673. phba->last_completion_time = jiffies;
  2674. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2675. if (rspiocbp == NULL) {
  2676. printk(KERN_ERR "%s: out of buffers! Failing "
  2677. "completion.\n", __func__);
  2678. break;
  2679. }
  2680. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2681. phba->iocb_rsp_size);
  2682. irsp = &rspiocbp->iocb;
  2683. if (++pring->rspidx >= portRspMax)
  2684. pring->rspidx = 0;
  2685. if (pring->ringno == LPFC_ELS_RING) {
  2686. lpfc_debugfs_slow_ring_trc(phba,
  2687. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2688. *(((uint32_t *) irsp) + 4),
  2689. *(((uint32_t *) irsp) + 6),
  2690. *(((uint32_t *) irsp) + 7));
  2691. }
  2692. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2693. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2694. /* Handle the response IOCB */
  2695. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2696. spin_lock_irqsave(&phba->hbalock, iflag);
  2697. /*
  2698. * If the port response put pointer has not been updated, sync
  2699. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2700. * response put pointer.
  2701. */
  2702. if (pring->rspidx == portRspPut) {
  2703. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2704. }
  2705. } /* while (pring->rspidx != portRspPut) */
  2706. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2707. /* At least one response entry has been freed */
  2708. pring->stats.iocb_rsp_full++;
  2709. /* SET RxRE_RSP in Chip Att register */
  2710. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2711. writel(status, phba->CAregaddr);
  2712. readl(phba->CAregaddr); /* flush */
  2713. }
  2714. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2715. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2716. pring->stats.iocb_cmd_empty++;
  2717. /* Force update of the local copy of cmdGetInx */
  2718. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2719. lpfc_sli_resume_iocb(phba, pring);
  2720. if ((pring->lpfc_sli_cmd_available))
  2721. (pring->lpfc_sli_cmd_available) (phba, pring);
  2722. }
  2723. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2724. return;
  2725. }
  2726. /**
  2727. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2728. * @phba: Pointer to HBA context object.
  2729. * @pring: Pointer to driver SLI ring object.
  2730. * @mask: Host attention register mask for this ring.
  2731. *
  2732. * This function is called from the worker thread when there is a pending
  2733. * ELS response iocb on the driver internal slow-path response iocb worker
  2734. * queue. The caller does not hold any lock. The function will remove each
  2735. * response iocb from the response worker queue and calls the handle
  2736. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2737. **/
  2738. static void
  2739. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2740. struct lpfc_sli_ring *pring, uint32_t mask)
  2741. {
  2742. struct lpfc_iocbq *irspiocbq;
  2743. struct hbq_dmabuf *dmabuf;
  2744. struct lpfc_cq_event *cq_event;
  2745. unsigned long iflag;
  2746. spin_lock_irqsave(&phba->hbalock, iflag);
  2747. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2749. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2750. /* Get the response iocb from the head of work queue */
  2751. spin_lock_irqsave(&phba->hbalock, iflag);
  2752. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2753. cq_event, struct lpfc_cq_event, list);
  2754. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2755. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2756. case CQE_CODE_COMPL_WQE:
  2757. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2758. cq_event);
  2759. /* Translate ELS WCQE to response IOCBQ */
  2760. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2761. irspiocbq);
  2762. if (irspiocbq)
  2763. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2764. irspiocbq);
  2765. break;
  2766. case CQE_CODE_RECEIVE:
  2767. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2768. cq_event);
  2769. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2770. break;
  2771. default:
  2772. break;
  2773. }
  2774. }
  2775. }
  2776. /**
  2777. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2778. * @phba: Pointer to HBA context object.
  2779. * @pring: Pointer to driver SLI ring object.
  2780. *
  2781. * This function aborts all iocbs in the given ring and frees all the iocb
  2782. * objects in txq. This function issues an abort iocb for all the iocb commands
  2783. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2784. * the return of this function. The caller is not required to hold any locks.
  2785. **/
  2786. void
  2787. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2788. {
  2789. LIST_HEAD(completions);
  2790. struct lpfc_iocbq *iocb, *next_iocb;
  2791. if (pring->ringno == LPFC_ELS_RING) {
  2792. lpfc_fabric_abort_hba(phba);
  2793. }
  2794. /* Error everything on txq and txcmplq
  2795. * First do the txq.
  2796. */
  2797. spin_lock_irq(&phba->hbalock);
  2798. list_splice_init(&pring->txq, &completions);
  2799. pring->txq_cnt = 0;
  2800. /* Next issue ABTS for everything on the txcmplq */
  2801. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2802. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2803. spin_unlock_irq(&phba->hbalock);
  2804. /* Cancel all the IOCBs from the completions list */
  2805. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_ABORTED);
  2807. }
  2808. /**
  2809. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2810. * @phba: Pointer to HBA context object.
  2811. *
  2812. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2813. * objects in txq and txcmplq. This function will not issue abort iocbs
  2814. * for all the iocb commands in txcmplq, they will just be returned with
  2815. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2816. * slot has been permanently disabled.
  2817. **/
  2818. void
  2819. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2820. {
  2821. LIST_HEAD(txq);
  2822. LIST_HEAD(txcmplq);
  2823. struct lpfc_sli *psli = &phba->sli;
  2824. struct lpfc_sli_ring *pring;
  2825. /* Currently, only one fcp ring */
  2826. pring = &psli->ring[psli->fcp_ring];
  2827. spin_lock_irq(&phba->hbalock);
  2828. /* Retrieve everything on txq */
  2829. list_splice_init(&pring->txq, &txq);
  2830. pring->txq_cnt = 0;
  2831. /* Retrieve everything on the txcmplq */
  2832. list_splice_init(&pring->txcmplq, &txcmplq);
  2833. pring->txcmplq_cnt = 0;
  2834. spin_unlock_irq(&phba->hbalock);
  2835. /* Flush the txq */
  2836. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2837. IOERR_SLI_DOWN);
  2838. /* Flush the txcmpq */
  2839. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2840. IOERR_SLI_DOWN);
  2841. }
  2842. /**
  2843. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2844. * @phba: Pointer to HBA context object.
  2845. * @mask: Bit mask to be checked.
  2846. *
  2847. * This function reads the host status register and compares
  2848. * with the provided bit mask to check if HBA completed
  2849. * the restart. This function will wait in a loop for the
  2850. * HBA to complete restart. If the HBA does not restart within
  2851. * 15 iterations, the function will reset the HBA again. The
  2852. * function returns 1 when HBA fail to restart otherwise returns
  2853. * zero.
  2854. **/
  2855. static int
  2856. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2857. {
  2858. uint32_t status;
  2859. int i = 0;
  2860. int retval = 0;
  2861. /* Read the HBA Host Status Register */
  2862. status = readl(phba->HSregaddr);
  2863. /*
  2864. * Check status register every 100ms for 5 retries, then every
  2865. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2866. * every 2.5 sec for 4.
  2867. * Break our of the loop if errors occurred during init.
  2868. */
  2869. while (((status & mask) != mask) &&
  2870. !(status & HS_FFERM) &&
  2871. i++ < 20) {
  2872. if (i <= 5)
  2873. msleep(10);
  2874. else if (i <= 10)
  2875. msleep(500);
  2876. else
  2877. msleep(2500);
  2878. if (i == 15) {
  2879. /* Do post */
  2880. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2881. lpfc_sli_brdrestart(phba);
  2882. }
  2883. /* Read the HBA Host Status Register */
  2884. status = readl(phba->HSregaddr);
  2885. }
  2886. /* Check to see if any errors occurred during init */
  2887. if ((status & HS_FFERM) || (i >= 20)) {
  2888. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2889. "2751 Adapter failed to restart, "
  2890. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2891. status,
  2892. readl(phba->MBslimaddr + 0xa8),
  2893. readl(phba->MBslimaddr + 0xac));
  2894. phba->link_state = LPFC_HBA_ERROR;
  2895. retval = 1;
  2896. }
  2897. return retval;
  2898. }
  2899. /**
  2900. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2901. * @phba: Pointer to HBA context object.
  2902. * @mask: Bit mask to be checked.
  2903. *
  2904. * This function checks the host status register to check if HBA is
  2905. * ready. This function will wait in a loop for the HBA to be ready
  2906. * If the HBA is not ready , the function will will reset the HBA PCI
  2907. * function again. The function returns 1 when HBA fail to be ready
  2908. * otherwise returns zero.
  2909. **/
  2910. static int
  2911. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2912. {
  2913. uint32_t status;
  2914. int retval = 0;
  2915. /* Read the HBA Host Status Register */
  2916. status = lpfc_sli4_post_status_check(phba);
  2917. if (status) {
  2918. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2919. lpfc_sli_brdrestart(phba);
  2920. status = lpfc_sli4_post_status_check(phba);
  2921. }
  2922. /* Check to see if any errors occurred during init */
  2923. if (status) {
  2924. phba->link_state = LPFC_HBA_ERROR;
  2925. retval = 1;
  2926. } else
  2927. phba->sli4_hba.intr_enable = 0;
  2928. return retval;
  2929. }
  2930. /**
  2931. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2932. * @phba: Pointer to HBA context object.
  2933. * @mask: Bit mask to be checked.
  2934. *
  2935. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2936. * from the API jump table function pointer from the lpfc_hba struct.
  2937. **/
  2938. int
  2939. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2940. {
  2941. return phba->lpfc_sli_brdready(phba, mask);
  2942. }
  2943. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2944. /**
  2945. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2946. * @phba: Pointer to HBA context object.
  2947. *
  2948. * This function is called before resetting an HBA. This
  2949. * function requests HBA to quiesce DMAs before a reset.
  2950. **/
  2951. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2952. {
  2953. uint32_t __iomem *resp_buf;
  2954. uint32_t __iomem *mbox_buf;
  2955. volatile uint32_t mbox;
  2956. uint32_t hc_copy;
  2957. int i;
  2958. uint8_t hdrtype;
  2959. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2960. if (hdrtype != 0x80 ||
  2961. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2962. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2963. return;
  2964. /*
  2965. * Tell the other part of the chip to suspend temporarily all
  2966. * its DMA activity.
  2967. */
  2968. resp_buf = phba->MBslimaddr;
  2969. /* Disable the error attention */
  2970. hc_copy = readl(phba->HCregaddr);
  2971. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2972. readl(phba->HCregaddr); /* flush */
  2973. phba->link_flag |= LS_IGNORE_ERATT;
  2974. if (readl(phba->HAregaddr) & HA_ERATT) {
  2975. /* Clear Chip error bit */
  2976. writel(HA_ERATT, phba->HAregaddr);
  2977. phba->pport->stopped = 1;
  2978. }
  2979. mbox = 0;
  2980. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2981. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2982. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2983. mbox_buf = phba->MBslimaddr;
  2984. writel(mbox, mbox_buf);
  2985. for (i = 0;
  2986. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2987. mdelay(1);
  2988. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2989. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2990. phba->pport->stopped)
  2991. goto restore_hc;
  2992. else
  2993. goto clear_errat;
  2994. }
  2995. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2996. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2997. mdelay(1);
  2998. clear_errat:
  2999. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3000. mdelay(1);
  3001. if (readl(phba->HAregaddr) & HA_ERATT) {
  3002. writel(HA_ERATT, phba->HAregaddr);
  3003. phba->pport->stopped = 1;
  3004. }
  3005. restore_hc:
  3006. phba->link_flag &= ~LS_IGNORE_ERATT;
  3007. writel(hc_copy, phba->HCregaddr);
  3008. readl(phba->HCregaddr); /* flush */
  3009. }
  3010. /**
  3011. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3012. * @phba: Pointer to HBA context object.
  3013. *
  3014. * This function issues a kill_board mailbox command and waits for
  3015. * the error attention interrupt. This function is called for stopping
  3016. * the firmware processing. The caller is not required to hold any
  3017. * locks. This function calls lpfc_hba_down_post function to free
  3018. * any pending commands after the kill. The function will return 1 when it
  3019. * fails to kill the board else will return 0.
  3020. **/
  3021. int
  3022. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3023. {
  3024. struct lpfc_sli *psli;
  3025. LPFC_MBOXQ_t *pmb;
  3026. uint32_t status;
  3027. uint32_t ha_copy;
  3028. int retval;
  3029. int i = 0;
  3030. psli = &phba->sli;
  3031. /* Kill HBA */
  3032. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3033. "0329 Kill HBA Data: x%x x%x\n",
  3034. phba->pport->port_state, psli->sli_flag);
  3035. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3036. if (!pmb)
  3037. return 1;
  3038. /* Disable the error attention */
  3039. spin_lock_irq(&phba->hbalock);
  3040. status = readl(phba->HCregaddr);
  3041. status &= ~HC_ERINT_ENA;
  3042. writel(status, phba->HCregaddr);
  3043. readl(phba->HCregaddr); /* flush */
  3044. phba->link_flag |= LS_IGNORE_ERATT;
  3045. spin_unlock_irq(&phba->hbalock);
  3046. lpfc_kill_board(phba, pmb);
  3047. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3048. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3049. if (retval != MBX_SUCCESS) {
  3050. if (retval != MBX_BUSY)
  3051. mempool_free(pmb, phba->mbox_mem_pool);
  3052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3053. "2752 KILL_BOARD command failed retval %d\n",
  3054. retval);
  3055. spin_lock_irq(&phba->hbalock);
  3056. phba->link_flag &= ~LS_IGNORE_ERATT;
  3057. spin_unlock_irq(&phba->hbalock);
  3058. return 1;
  3059. }
  3060. spin_lock_irq(&phba->hbalock);
  3061. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3062. spin_unlock_irq(&phba->hbalock);
  3063. mempool_free(pmb, phba->mbox_mem_pool);
  3064. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3065. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3066. * 3 seconds we still set HBA_ERROR state because the status of the
  3067. * board is now undefined.
  3068. */
  3069. ha_copy = readl(phba->HAregaddr);
  3070. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3071. mdelay(100);
  3072. ha_copy = readl(phba->HAregaddr);
  3073. }
  3074. del_timer_sync(&psli->mbox_tmo);
  3075. if (ha_copy & HA_ERATT) {
  3076. writel(HA_ERATT, phba->HAregaddr);
  3077. phba->pport->stopped = 1;
  3078. }
  3079. spin_lock_irq(&phba->hbalock);
  3080. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3081. psli->mbox_active = NULL;
  3082. phba->link_flag &= ~LS_IGNORE_ERATT;
  3083. spin_unlock_irq(&phba->hbalock);
  3084. lpfc_hba_down_post(phba);
  3085. phba->link_state = LPFC_HBA_ERROR;
  3086. return ha_copy & HA_ERATT ? 0 : 1;
  3087. }
  3088. /**
  3089. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3090. * @phba: Pointer to HBA context object.
  3091. *
  3092. * This function resets the HBA by writing HC_INITFF to the control
  3093. * register. After the HBA resets, this function resets all the iocb ring
  3094. * indices. This function disables PCI layer parity checking during
  3095. * the reset.
  3096. * This function returns 0 always.
  3097. * The caller is not required to hold any locks.
  3098. **/
  3099. int
  3100. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3101. {
  3102. struct lpfc_sli *psli;
  3103. struct lpfc_sli_ring *pring;
  3104. uint16_t cfg_value;
  3105. int i;
  3106. psli = &phba->sli;
  3107. /* Reset HBA */
  3108. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3109. "0325 Reset HBA Data: x%x x%x\n",
  3110. phba->pport->port_state, psli->sli_flag);
  3111. /* perform board reset */
  3112. phba->fc_eventTag = 0;
  3113. phba->link_events = 0;
  3114. phba->pport->fc_myDID = 0;
  3115. phba->pport->fc_prevDID = 0;
  3116. /* Turn off parity checking and serr during the physical reset */
  3117. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3118. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3119. (cfg_value &
  3120. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3121. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3122. /* Now toggle INITFF bit in the Host Control Register */
  3123. writel(HC_INITFF, phba->HCregaddr);
  3124. mdelay(1);
  3125. readl(phba->HCregaddr); /* flush */
  3126. writel(0, phba->HCregaddr);
  3127. readl(phba->HCregaddr); /* flush */
  3128. /* Restore PCI cmd register */
  3129. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3130. /* Initialize relevant SLI info */
  3131. for (i = 0; i < psli->num_rings; i++) {
  3132. pring = &psli->ring[i];
  3133. pring->flag = 0;
  3134. pring->rspidx = 0;
  3135. pring->next_cmdidx = 0;
  3136. pring->local_getidx = 0;
  3137. pring->cmdidx = 0;
  3138. pring->missbufcnt = 0;
  3139. }
  3140. phba->link_state = LPFC_WARM_START;
  3141. return 0;
  3142. }
  3143. /**
  3144. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3145. * @phba: Pointer to HBA context object.
  3146. *
  3147. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3148. * checking during resets the device. The caller is not required to hold
  3149. * any locks.
  3150. *
  3151. * This function returns 0 always.
  3152. **/
  3153. int
  3154. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3155. {
  3156. struct lpfc_sli *psli = &phba->sli;
  3157. uint16_t cfg_value;
  3158. uint8_t qindx;
  3159. /* Reset HBA */
  3160. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3161. "0295 Reset HBA Data: x%x x%x\n",
  3162. phba->pport->port_state, psli->sli_flag);
  3163. /* perform board reset */
  3164. phba->fc_eventTag = 0;
  3165. phba->link_events = 0;
  3166. phba->pport->fc_myDID = 0;
  3167. phba->pport->fc_prevDID = 0;
  3168. /* Turn off parity checking and serr during the physical reset */
  3169. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3170. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3171. (cfg_value &
  3172. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3173. spin_lock_irq(&phba->hbalock);
  3174. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3175. phba->fcf.fcf_flag = 0;
  3176. /* Clean up the child queue list for the CQs */
  3177. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3178. list_del_init(&phba->sli4_hba.els_wq->list);
  3179. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3180. list_del_init(&phba->sli4_hba.dat_rq->list);
  3181. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3182. list_del_init(&phba->sli4_hba.els_cq->list);
  3183. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3184. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3185. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3186. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3187. spin_unlock_irq(&phba->hbalock);
  3188. /* Now physically reset the device */
  3189. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3190. "0389 Performing PCI function reset!\n");
  3191. /* Perform FCoE PCI function reset */
  3192. lpfc_pci_function_reset(phba);
  3193. return 0;
  3194. }
  3195. /**
  3196. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3197. * @phba: Pointer to HBA context object.
  3198. *
  3199. * This function is called in the SLI initialization code path to
  3200. * restart the HBA. The caller is not required to hold any lock.
  3201. * This function writes MBX_RESTART mailbox command to the SLIM and
  3202. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3203. * function to free any pending commands. The function enables
  3204. * POST only during the first initialization. The function returns zero.
  3205. * The function does not guarantee completion of MBX_RESTART mailbox
  3206. * command before the return of this function.
  3207. **/
  3208. static int
  3209. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3210. {
  3211. MAILBOX_t *mb;
  3212. struct lpfc_sli *psli;
  3213. volatile uint32_t word0;
  3214. void __iomem *to_slim;
  3215. uint32_t hba_aer_enabled;
  3216. spin_lock_irq(&phba->hbalock);
  3217. /* Take PCIe device Advanced Error Reporting (AER) state */
  3218. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3219. psli = &phba->sli;
  3220. /* Restart HBA */
  3221. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3222. "0337 Restart HBA Data: x%x x%x\n",
  3223. phba->pport->port_state, psli->sli_flag);
  3224. word0 = 0;
  3225. mb = (MAILBOX_t *) &word0;
  3226. mb->mbxCommand = MBX_RESTART;
  3227. mb->mbxHc = 1;
  3228. lpfc_reset_barrier(phba);
  3229. to_slim = phba->MBslimaddr;
  3230. writel(*(uint32_t *) mb, to_slim);
  3231. readl(to_slim); /* flush */
  3232. /* Only skip post after fc_ffinit is completed */
  3233. if (phba->pport->port_state)
  3234. word0 = 1; /* This is really setting up word1 */
  3235. else
  3236. word0 = 0; /* This is really setting up word1 */
  3237. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3238. writel(*(uint32_t *) mb, to_slim);
  3239. readl(to_slim); /* flush */
  3240. lpfc_sli_brdreset(phba);
  3241. phba->pport->stopped = 0;
  3242. phba->link_state = LPFC_INIT_START;
  3243. phba->hba_flag = 0;
  3244. spin_unlock_irq(&phba->hbalock);
  3245. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3246. psli->stats_start = get_seconds();
  3247. /* Give the INITFF and Post time to settle. */
  3248. mdelay(100);
  3249. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3250. if (hba_aer_enabled)
  3251. pci_disable_pcie_error_reporting(phba->pcidev);
  3252. lpfc_hba_down_post(phba);
  3253. return 0;
  3254. }
  3255. /**
  3256. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3257. * @phba: Pointer to HBA context object.
  3258. *
  3259. * This function is called in the SLI initialization code path to restart
  3260. * a SLI4 HBA. The caller is not required to hold any lock.
  3261. * At the end of the function, it calls lpfc_hba_down_post function to
  3262. * free any pending commands.
  3263. **/
  3264. static int
  3265. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3266. {
  3267. struct lpfc_sli *psli = &phba->sli;
  3268. uint32_t hba_aer_enabled;
  3269. /* Restart HBA */
  3270. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3271. "0296 Restart HBA Data: x%x x%x\n",
  3272. phba->pport->port_state, psli->sli_flag);
  3273. /* Take PCIe device Advanced Error Reporting (AER) state */
  3274. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3275. lpfc_sli4_brdreset(phba);
  3276. spin_lock_irq(&phba->hbalock);
  3277. phba->pport->stopped = 0;
  3278. phba->link_state = LPFC_INIT_START;
  3279. phba->hba_flag = 0;
  3280. spin_unlock_irq(&phba->hbalock);
  3281. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3282. psli->stats_start = get_seconds();
  3283. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3284. if (hba_aer_enabled)
  3285. pci_disable_pcie_error_reporting(phba->pcidev);
  3286. lpfc_hba_down_post(phba);
  3287. return 0;
  3288. }
  3289. /**
  3290. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3291. * @phba: Pointer to HBA context object.
  3292. *
  3293. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3294. * API jump table function pointer from the lpfc_hba struct.
  3295. **/
  3296. int
  3297. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3298. {
  3299. return phba->lpfc_sli_brdrestart(phba);
  3300. }
  3301. /**
  3302. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3303. * @phba: Pointer to HBA context object.
  3304. *
  3305. * This function is called after a HBA restart to wait for successful
  3306. * restart of the HBA. Successful restart of the HBA is indicated by
  3307. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3308. * iteration, the function will restart the HBA again. The function returns
  3309. * zero if HBA successfully restarted else returns negative error code.
  3310. **/
  3311. static int
  3312. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3313. {
  3314. uint32_t status, i = 0;
  3315. /* Read the HBA Host Status Register */
  3316. status = readl(phba->HSregaddr);
  3317. /* Check status register to see what current state is */
  3318. i = 0;
  3319. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3320. /* Check every 10ms for 10 retries, then every 100ms for 90
  3321. * retries, then every 1 sec for 50 retires for a total of
  3322. * ~60 seconds before reset the board again and check every
  3323. * 1 sec for 50 retries. The up to 60 seconds before the
  3324. * board ready is required by the Falcon FIPS zeroization
  3325. * complete, and any reset the board in between shall cause
  3326. * restart of zeroization, further delay the board ready.
  3327. */
  3328. if (i++ >= 200) {
  3329. /* Adapter failed to init, timeout, status reg
  3330. <status> */
  3331. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3332. "0436 Adapter failed to init, "
  3333. "timeout, status reg x%x, "
  3334. "FW Data: A8 x%x AC x%x\n", status,
  3335. readl(phba->MBslimaddr + 0xa8),
  3336. readl(phba->MBslimaddr + 0xac));
  3337. phba->link_state = LPFC_HBA_ERROR;
  3338. return -ETIMEDOUT;
  3339. }
  3340. /* Check to see if any errors occurred during init */
  3341. if (status & HS_FFERM) {
  3342. /* ERROR: During chipset initialization */
  3343. /* Adapter failed to init, chipset, status reg
  3344. <status> */
  3345. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3346. "0437 Adapter failed to init, "
  3347. "chipset, status reg x%x, "
  3348. "FW Data: A8 x%x AC x%x\n", status,
  3349. readl(phba->MBslimaddr + 0xa8),
  3350. readl(phba->MBslimaddr + 0xac));
  3351. phba->link_state = LPFC_HBA_ERROR;
  3352. return -EIO;
  3353. }
  3354. if (i <= 10)
  3355. msleep(10);
  3356. else if (i <= 100)
  3357. msleep(100);
  3358. else
  3359. msleep(1000);
  3360. if (i == 150) {
  3361. /* Do post */
  3362. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3363. lpfc_sli_brdrestart(phba);
  3364. }
  3365. /* Read the HBA Host Status Register */
  3366. status = readl(phba->HSregaddr);
  3367. }
  3368. /* Check to see if any errors occurred during init */
  3369. if (status & HS_FFERM) {
  3370. /* ERROR: During chipset initialization */
  3371. /* Adapter failed to init, chipset, status reg <status> */
  3372. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3373. "0438 Adapter failed to init, chipset, "
  3374. "status reg x%x, "
  3375. "FW Data: A8 x%x AC x%x\n", status,
  3376. readl(phba->MBslimaddr + 0xa8),
  3377. readl(phba->MBslimaddr + 0xac));
  3378. phba->link_state = LPFC_HBA_ERROR;
  3379. return -EIO;
  3380. }
  3381. /* Clear all interrupt enable conditions */
  3382. writel(0, phba->HCregaddr);
  3383. readl(phba->HCregaddr); /* flush */
  3384. /* setup host attn register */
  3385. writel(0xffffffff, phba->HAregaddr);
  3386. readl(phba->HAregaddr); /* flush */
  3387. return 0;
  3388. }
  3389. /**
  3390. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3391. *
  3392. * This function calculates and returns the number of HBQs required to be
  3393. * configured.
  3394. **/
  3395. int
  3396. lpfc_sli_hbq_count(void)
  3397. {
  3398. return ARRAY_SIZE(lpfc_hbq_defs);
  3399. }
  3400. /**
  3401. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3402. *
  3403. * This function adds the number of hbq entries in every HBQ to get
  3404. * the total number of hbq entries required for the HBA and returns
  3405. * the total count.
  3406. **/
  3407. static int
  3408. lpfc_sli_hbq_entry_count(void)
  3409. {
  3410. int hbq_count = lpfc_sli_hbq_count();
  3411. int count = 0;
  3412. int i;
  3413. for (i = 0; i < hbq_count; ++i)
  3414. count += lpfc_hbq_defs[i]->entry_count;
  3415. return count;
  3416. }
  3417. /**
  3418. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3419. *
  3420. * This function calculates amount of memory required for all hbq entries
  3421. * to be configured and returns the total memory required.
  3422. **/
  3423. int
  3424. lpfc_sli_hbq_size(void)
  3425. {
  3426. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3427. }
  3428. /**
  3429. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3430. * @phba: Pointer to HBA context object.
  3431. *
  3432. * This function is called during the SLI initialization to configure
  3433. * all the HBQs and post buffers to the HBQ. The caller is not
  3434. * required to hold any locks. This function will return zero if successful
  3435. * else it will return negative error code.
  3436. **/
  3437. static int
  3438. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3439. {
  3440. int hbq_count = lpfc_sli_hbq_count();
  3441. LPFC_MBOXQ_t *pmb;
  3442. MAILBOX_t *pmbox;
  3443. uint32_t hbqno;
  3444. uint32_t hbq_entry_index;
  3445. /* Get a Mailbox buffer to setup mailbox
  3446. * commands for HBA initialization
  3447. */
  3448. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3449. if (!pmb)
  3450. return -ENOMEM;
  3451. pmbox = &pmb->u.mb;
  3452. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3453. phba->link_state = LPFC_INIT_MBX_CMDS;
  3454. phba->hbq_in_use = 1;
  3455. hbq_entry_index = 0;
  3456. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3457. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3458. phba->hbqs[hbqno].hbqPutIdx = 0;
  3459. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3460. phba->hbqs[hbqno].entry_count =
  3461. lpfc_hbq_defs[hbqno]->entry_count;
  3462. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3463. hbq_entry_index, pmb);
  3464. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3465. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3466. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3467. mbxStatus <status>, ring <num> */
  3468. lpfc_printf_log(phba, KERN_ERR,
  3469. LOG_SLI | LOG_VPORT,
  3470. "1805 Adapter failed to init. "
  3471. "Data: x%x x%x x%x\n",
  3472. pmbox->mbxCommand,
  3473. pmbox->mbxStatus, hbqno);
  3474. phba->link_state = LPFC_HBA_ERROR;
  3475. mempool_free(pmb, phba->mbox_mem_pool);
  3476. return -ENXIO;
  3477. }
  3478. }
  3479. phba->hbq_count = hbq_count;
  3480. mempool_free(pmb, phba->mbox_mem_pool);
  3481. /* Initially populate or replenish the HBQs */
  3482. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3483. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3484. return 0;
  3485. }
  3486. /**
  3487. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3488. * @phba: Pointer to HBA context object.
  3489. *
  3490. * This function is called during the SLI initialization to configure
  3491. * all the HBQs and post buffers to the HBQ. The caller is not
  3492. * required to hold any locks. This function will return zero if successful
  3493. * else it will return negative error code.
  3494. **/
  3495. static int
  3496. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3497. {
  3498. phba->hbq_in_use = 1;
  3499. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3500. phba->hbq_count = 1;
  3501. /* Initially populate or replenish the HBQs */
  3502. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3503. return 0;
  3504. }
  3505. /**
  3506. * lpfc_sli_config_port - Issue config port mailbox command
  3507. * @phba: Pointer to HBA context object.
  3508. * @sli_mode: sli mode - 2/3
  3509. *
  3510. * This function is called by the sli intialization code path
  3511. * to issue config_port mailbox command. This function restarts the
  3512. * HBA firmware and issues a config_port mailbox command to configure
  3513. * the SLI interface in the sli mode specified by sli_mode
  3514. * variable. The caller is not required to hold any locks.
  3515. * The function returns 0 if successful, else returns negative error
  3516. * code.
  3517. **/
  3518. int
  3519. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3520. {
  3521. LPFC_MBOXQ_t *pmb;
  3522. uint32_t resetcount = 0, rc = 0, done = 0;
  3523. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3524. if (!pmb) {
  3525. phba->link_state = LPFC_HBA_ERROR;
  3526. return -ENOMEM;
  3527. }
  3528. phba->sli_rev = sli_mode;
  3529. while (resetcount < 2 && !done) {
  3530. spin_lock_irq(&phba->hbalock);
  3531. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3532. spin_unlock_irq(&phba->hbalock);
  3533. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3534. lpfc_sli_brdrestart(phba);
  3535. rc = lpfc_sli_chipset_init(phba);
  3536. if (rc)
  3537. break;
  3538. spin_lock_irq(&phba->hbalock);
  3539. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3540. spin_unlock_irq(&phba->hbalock);
  3541. resetcount++;
  3542. /* Call pre CONFIG_PORT mailbox command initialization. A
  3543. * value of 0 means the call was successful. Any other
  3544. * nonzero value is a failure, but if ERESTART is returned,
  3545. * the driver may reset the HBA and try again.
  3546. */
  3547. rc = lpfc_config_port_prep(phba);
  3548. if (rc == -ERESTART) {
  3549. phba->link_state = LPFC_LINK_UNKNOWN;
  3550. continue;
  3551. } else if (rc)
  3552. break;
  3553. phba->link_state = LPFC_INIT_MBX_CMDS;
  3554. lpfc_config_port(phba, pmb);
  3555. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3556. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3557. LPFC_SLI3_HBQ_ENABLED |
  3558. LPFC_SLI3_CRP_ENABLED |
  3559. LPFC_SLI3_BG_ENABLED |
  3560. LPFC_SLI3_DSS_ENABLED);
  3561. if (rc != MBX_SUCCESS) {
  3562. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3563. "0442 Adapter failed to init, mbxCmd x%x "
  3564. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3565. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3566. spin_lock_irq(&phba->hbalock);
  3567. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3568. spin_unlock_irq(&phba->hbalock);
  3569. rc = -ENXIO;
  3570. } else {
  3571. /* Allow asynchronous mailbox command to go through */
  3572. spin_lock_irq(&phba->hbalock);
  3573. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3574. spin_unlock_irq(&phba->hbalock);
  3575. done = 1;
  3576. }
  3577. }
  3578. if (!done) {
  3579. rc = -EINVAL;
  3580. goto do_prep_failed;
  3581. }
  3582. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3583. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3584. rc = -ENXIO;
  3585. goto do_prep_failed;
  3586. }
  3587. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3588. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3589. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3590. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3591. phba->max_vpi : phba->max_vports;
  3592. } else
  3593. phba->max_vpi = 0;
  3594. phba->fips_level = 0;
  3595. phba->fips_spec_rev = 0;
  3596. if (pmb->u.mb.un.varCfgPort.gdss) {
  3597. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3598. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3599. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3600. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3601. "2850 Security Crypto Active. FIPS x%d "
  3602. "(Spec Rev: x%d)",
  3603. phba->fips_level, phba->fips_spec_rev);
  3604. }
  3605. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3606. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3607. "2856 Config Port Security Crypto "
  3608. "Error: x%x ",
  3609. pmb->u.mb.un.varCfgPort.sec_err);
  3610. }
  3611. if (pmb->u.mb.un.varCfgPort.gerbm)
  3612. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3613. if (pmb->u.mb.un.varCfgPort.gcrp)
  3614. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3615. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3616. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3617. if (phba->cfg_enable_bg) {
  3618. if (pmb->u.mb.un.varCfgPort.gbg)
  3619. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3620. else
  3621. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3622. "0443 Adapter did not grant "
  3623. "BlockGuard\n");
  3624. }
  3625. } else {
  3626. phba->hbq_get = NULL;
  3627. phba->port_gp = phba->mbox->us.s2.port;
  3628. phba->max_vpi = 0;
  3629. }
  3630. do_prep_failed:
  3631. mempool_free(pmb, phba->mbox_mem_pool);
  3632. return rc;
  3633. }
  3634. /**
  3635. * lpfc_sli_hba_setup - SLI intialization function
  3636. * @phba: Pointer to HBA context object.
  3637. *
  3638. * This function is the main SLI intialization function. This function
  3639. * is called by the HBA intialization code, HBA reset code and HBA
  3640. * error attention handler code. Caller is not required to hold any
  3641. * locks. This function issues config_port mailbox command to configure
  3642. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3643. * calls the config_port_post function to issue init_link mailbox
  3644. * command and to start the discovery. The function will return zero
  3645. * if successful, else it will return negative error code.
  3646. **/
  3647. int
  3648. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3649. {
  3650. uint32_t rc;
  3651. int mode = 3;
  3652. switch (lpfc_sli_mode) {
  3653. case 2:
  3654. if (phba->cfg_enable_npiv) {
  3655. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3656. "1824 NPIV enabled: Override lpfc_sli_mode "
  3657. "parameter (%d) to auto (0).\n",
  3658. lpfc_sli_mode);
  3659. break;
  3660. }
  3661. mode = 2;
  3662. break;
  3663. case 0:
  3664. case 3:
  3665. break;
  3666. default:
  3667. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3668. "1819 Unrecognized lpfc_sli_mode "
  3669. "parameter: %d.\n", lpfc_sli_mode);
  3670. break;
  3671. }
  3672. rc = lpfc_sli_config_port(phba, mode);
  3673. if (rc && lpfc_sli_mode == 3)
  3674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3675. "1820 Unable to select SLI-3. "
  3676. "Not supported by adapter.\n");
  3677. if (rc && mode != 2)
  3678. rc = lpfc_sli_config_port(phba, 2);
  3679. if (rc)
  3680. goto lpfc_sli_hba_setup_error;
  3681. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3682. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3683. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3684. if (!rc) {
  3685. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3686. "2709 This device supports "
  3687. "Advanced Error Reporting (AER)\n");
  3688. spin_lock_irq(&phba->hbalock);
  3689. phba->hba_flag |= HBA_AER_ENABLED;
  3690. spin_unlock_irq(&phba->hbalock);
  3691. } else {
  3692. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3693. "2708 This device does not support "
  3694. "Advanced Error Reporting (AER)\n");
  3695. phba->cfg_aer_support = 0;
  3696. }
  3697. }
  3698. if (phba->sli_rev == 3) {
  3699. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3700. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3701. } else {
  3702. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3703. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3704. phba->sli3_options = 0;
  3705. }
  3706. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3707. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3708. phba->sli_rev, phba->max_vpi);
  3709. rc = lpfc_sli_ring_map(phba);
  3710. if (rc)
  3711. goto lpfc_sli_hba_setup_error;
  3712. /* Init HBQs */
  3713. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3714. rc = lpfc_sli_hbq_setup(phba);
  3715. if (rc)
  3716. goto lpfc_sli_hba_setup_error;
  3717. }
  3718. spin_lock_irq(&phba->hbalock);
  3719. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3720. spin_unlock_irq(&phba->hbalock);
  3721. rc = lpfc_config_port_post(phba);
  3722. if (rc)
  3723. goto lpfc_sli_hba_setup_error;
  3724. return rc;
  3725. lpfc_sli_hba_setup_error:
  3726. phba->link_state = LPFC_HBA_ERROR;
  3727. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3728. "0445 Firmware initialization failed\n");
  3729. return rc;
  3730. }
  3731. /**
  3732. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3733. * @phba: Pointer to HBA context object.
  3734. * @mboxq: mailbox pointer.
  3735. * This function issue a dump mailbox command to read config region
  3736. * 23 and parse the records in the region and populate driver
  3737. * data structure.
  3738. **/
  3739. static int
  3740. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3741. LPFC_MBOXQ_t *mboxq)
  3742. {
  3743. struct lpfc_dmabuf *mp;
  3744. struct lpfc_mqe *mqe;
  3745. uint32_t data_length;
  3746. int rc;
  3747. /* Program the default value of vlan_id and fc_map */
  3748. phba->valid_vlan = 0;
  3749. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3750. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3751. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3752. mqe = &mboxq->u.mqe;
  3753. if (lpfc_dump_fcoe_param(phba, mboxq))
  3754. return -ENOMEM;
  3755. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3756. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3757. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3758. "(%d):2571 Mailbox cmd x%x Status x%x "
  3759. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3760. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3761. "CQ: x%x x%x x%x x%x\n",
  3762. mboxq->vport ? mboxq->vport->vpi : 0,
  3763. bf_get(lpfc_mqe_command, mqe),
  3764. bf_get(lpfc_mqe_status, mqe),
  3765. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3766. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3767. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3768. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3769. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3770. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3771. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3772. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3773. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3774. mboxq->mcqe.word0,
  3775. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3776. mboxq->mcqe.trailer);
  3777. if (rc) {
  3778. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3779. kfree(mp);
  3780. return -EIO;
  3781. }
  3782. data_length = mqe->un.mb_words[5];
  3783. if (data_length > DMP_RGN23_SIZE) {
  3784. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3785. kfree(mp);
  3786. return -EIO;
  3787. }
  3788. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3789. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3790. kfree(mp);
  3791. return 0;
  3792. }
  3793. /**
  3794. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3795. * @phba: pointer to lpfc hba data structure.
  3796. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3797. * @vpd: pointer to the memory to hold resulting port vpd data.
  3798. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3799. * On output, the number of data bytes in @vpd.
  3800. *
  3801. * This routine executes a READ_REV SLI4 mailbox command. In
  3802. * addition, this routine gets the port vpd data.
  3803. *
  3804. * Return codes
  3805. * 0 - successful
  3806. * -ENOMEM - could not allocated memory.
  3807. **/
  3808. static int
  3809. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3810. uint8_t *vpd, uint32_t *vpd_size)
  3811. {
  3812. int rc = 0;
  3813. uint32_t dma_size;
  3814. struct lpfc_dmabuf *dmabuf;
  3815. struct lpfc_mqe *mqe;
  3816. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3817. if (!dmabuf)
  3818. return -ENOMEM;
  3819. /*
  3820. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3821. * mailbox command.
  3822. */
  3823. dma_size = *vpd_size;
  3824. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3825. dma_size,
  3826. &dmabuf->phys,
  3827. GFP_KERNEL);
  3828. if (!dmabuf->virt) {
  3829. kfree(dmabuf);
  3830. return -ENOMEM;
  3831. }
  3832. memset(dmabuf->virt, 0, dma_size);
  3833. /*
  3834. * The SLI4 implementation of READ_REV conflicts at word1,
  3835. * bits 31:16 and SLI4 adds vpd functionality not present
  3836. * in SLI3. This code corrects the conflicts.
  3837. */
  3838. lpfc_read_rev(phba, mboxq);
  3839. mqe = &mboxq->u.mqe;
  3840. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3841. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3842. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3843. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3844. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3845. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3846. if (rc) {
  3847. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3848. dmabuf->virt, dmabuf->phys);
  3849. kfree(dmabuf);
  3850. return -EIO;
  3851. }
  3852. /*
  3853. * The available vpd length cannot be bigger than the
  3854. * DMA buffer passed to the port. Catch the less than
  3855. * case and update the caller's size.
  3856. */
  3857. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3858. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3859. memcpy(vpd, dmabuf->virt, *vpd_size);
  3860. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3861. dmabuf->virt, dmabuf->phys);
  3862. kfree(dmabuf);
  3863. return 0;
  3864. }
  3865. /**
  3866. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3867. * @phba: pointer to lpfc hba data structure.
  3868. *
  3869. * This routine is called to explicitly arm the SLI4 device's completion and
  3870. * event queues
  3871. **/
  3872. static void
  3873. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3874. {
  3875. uint8_t fcp_eqidx;
  3876. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3877. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3878. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3879. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3880. LPFC_QUEUE_REARM);
  3881. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3882. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3883. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3884. LPFC_QUEUE_REARM);
  3885. }
  3886. /**
  3887. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3888. * @phba: Pointer to HBA context object.
  3889. *
  3890. * This function is the main SLI4 device intialization PCI function. This
  3891. * function is called by the HBA intialization code, HBA reset code and
  3892. * HBA error attention handler code. Caller is not required to hold any
  3893. * locks.
  3894. **/
  3895. int
  3896. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3897. {
  3898. int rc;
  3899. LPFC_MBOXQ_t *mboxq;
  3900. struct lpfc_mqe *mqe;
  3901. uint8_t *vpd;
  3902. uint32_t vpd_size;
  3903. uint32_t ftr_rsp = 0;
  3904. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3905. struct lpfc_vport *vport = phba->pport;
  3906. struct lpfc_dmabuf *mp;
  3907. /* Perform a PCI function reset to start from clean */
  3908. rc = lpfc_pci_function_reset(phba);
  3909. if (unlikely(rc))
  3910. return -ENODEV;
  3911. /* Check the HBA Host Status Register for readyness */
  3912. rc = lpfc_sli4_post_status_check(phba);
  3913. if (unlikely(rc))
  3914. return -ENODEV;
  3915. else {
  3916. spin_lock_irq(&phba->hbalock);
  3917. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3918. spin_unlock_irq(&phba->hbalock);
  3919. }
  3920. /*
  3921. * Allocate a single mailbox container for initializing the
  3922. * port.
  3923. */
  3924. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3925. if (!mboxq)
  3926. return -ENOMEM;
  3927. /*
  3928. * Continue initialization with default values even if driver failed
  3929. * to read FCoE param config regions
  3930. */
  3931. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3932. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3933. "2570 Failed to read FCoE parameters\n");
  3934. /* Issue READ_REV to collect vpd and FW information. */
  3935. vpd_size = SLI4_PAGE_SIZE;
  3936. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3937. if (!vpd) {
  3938. rc = -ENOMEM;
  3939. goto out_free_mbox;
  3940. }
  3941. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3942. if (unlikely(rc)) {
  3943. kfree(vpd);
  3944. goto out_free_mbox;
  3945. }
  3946. mqe = &mboxq->u.mqe;
  3947. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3948. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3949. phba->hba_flag |= HBA_FCOE_MODE;
  3950. else
  3951. phba->hba_flag &= ~HBA_FCOE_MODE;
  3952. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3953. LPFC_DCBX_CEE_MODE)
  3954. phba->hba_flag |= HBA_FIP_SUPPORT;
  3955. else
  3956. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3957. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3958. !(phba->hba_flag & HBA_FCOE_MODE)) {
  3959. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3960. "0376 READ_REV Error. SLI Level %d "
  3961. "FCoE enabled %d\n",
  3962. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  3963. rc = -EIO;
  3964. kfree(vpd);
  3965. goto out_free_mbox;
  3966. }
  3967. /*
  3968. * Evaluate the read rev and vpd data. Populate the driver
  3969. * state with the results. If this routine fails, the failure
  3970. * is not fatal as the driver will use generic values.
  3971. */
  3972. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3973. if (unlikely(!rc)) {
  3974. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3975. "0377 Error %d parsing vpd. "
  3976. "Using defaults.\n", rc);
  3977. rc = 0;
  3978. }
  3979. kfree(vpd);
  3980. /* Save information as VPD data */
  3981. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3982. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3983. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3984. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3985. &mqe->un.read_rev);
  3986. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3987. &mqe->un.read_rev);
  3988. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3989. &mqe->un.read_rev);
  3990. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3991. &mqe->un.read_rev);
  3992. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3993. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3994. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3995. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3996. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3997. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3998. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3999. "(%d):0380 READ_REV Status x%x "
  4000. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  4001. mboxq->vport ? mboxq->vport->vpi : 0,
  4002. bf_get(lpfc_mqe_status, mqe),
  4003. phba->vpd.rev.opFwName,
  4004. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4005. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4006. /*
  4007. * Discover the port's supported feature set and match it against the
  4008. * hosts requests.
  4009. */
  4010. lpfc_request_features(phba, mboxq);
  4011. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4012. if (unlikely(rc)) {
  4013. rc = -EIO;
  4014. goto out_free_mbox;
  4015. }
  4016. /*
  4017. * The port must support FCP initiator mode as this is the
  4018. * only mode running in the host.
  4019. */
  4020. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4021. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4022. "0378 No support for fcpi mode.\n");
  4023. ftr_rsp++;
  4024. }
  4025. /*
  4026. * If the port cannot support the host's requested features
  4027. * then turn off the global config parameters to disable the
  4028. * feature in the driver. This is not a fatal error.
  4029. */
  4030. if ((phba->cfg_enable_bg) &&
  4031. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4032. ftr_rsp++;
  4033. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4034. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4035. ftr_rsp++;
  4036. if (ftr_rsp) {
  4037. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4038. "0379 Feature Mismatch Data: x%08x %08x "
  4039. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4040. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4041. phba->cfg_enable_npiv, phba->max_vpi);
  4042. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4043. phba->cfg_enable_bg = 0;
  4044. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4045. phba->cfg_enable_npiv = 0;
  4046. }
  4047. /* These SLI3 features are assumed in SLI4 */
  4048. spin_lock_irq(&phba->hbalock);
  4049. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4050. spin_unlock_irq(&phba->hbalock);
  4051. /* Read the port's service parameters. */
  4052. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4053. if (rc) {
  4054. phba->link_state = LPFC_HBA_ERROR;
  4055. rc = -ENOMEM;
  4056. goto out_free_mbox;
  4057. }
  4058. mboxq->vport = vport;
  4059. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4060. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4061. if (rc == MBX_SUCCESS) {
  4062. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4063. rc = 0;
  4064. }
  4065. /*
  4066. * This memory was allocated by the lpfc_read_sparam routine. Release
  4067. * it to the mbuf pool.
  4068. */
  4069. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4070. kfree(mp);
  4071. mboxq->context1 = NULL;
  4072. if (unlikely(rc)) {
  4073. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4074. "0382 READ_SPARAM command failed "
  4075. "status %d, mbxStatus x%x\n",
  4076. rc, bf_get(lpfc_mqe_status, mqe));
  4077. phba->link_state = LPFC_HBA_ERROR;
  4078. rc = -EIO;
  4079. goto out_free_mbox;
  4080. }
  4081. if (phba->cfg_soft_wwnn)
  4082. u64_to_wwn(phba->cfg_soft_wwnn,
  4083. vport->fc_sparam.nodeName.u.wwn);
  4084. if (phba->cfg_soft_wwpn)
  4085. u64_to_wwn(phba->cfg_soft_wwpn,
  4086. vport->fc_sparam.portName.u.wwn);
  4087. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4088. sizeof(struct lpfc_name));
  4089. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4090. sizeof(struct lpfc_name));
  4091. /* Update the fc_host data structures with new wwn. */
  4092. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4093. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4094. /* Register SGL pool to the device using non-embedded mailbox command */
  4095. rc = lpfc_sli4_post_sgl_list(phba);
  4096. if (unlikely(rc)) {
  4097. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4098. "0582 Error %d during sgl post operation\n",
  4099. rc);
  4100. rc = -ENODEV;
  4101. goto out_free_mbox;
  4102. }
  4103. /* Register SCSI SGL pool to the device */
  4104. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4105. if (unlikely(rc)) {
  4106. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4107. "0383 Error %d during scsi sgl post "
  4108. "operation\n", rc);
  4109. /* Some Scsi buffers were moved to the abort scsi list */
  4110. /* A pci function reset will repost them */
  4111. rc = -ENODEV;
  4112. goto out_free_mbox;
  4113. }
  4114. /* Post the rpi header region to the device. */
  4115. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4116. if (unlikely(rc)) {
  4117. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4118. "0393 Error %d during rpi post operation\n",
  4119. rc);
  4120. rc = -ENODEV;
  4121. goto out_free_mbox;
  4122. }
  4123. /* Set up all the queues to the device */
  4124. rc = lpfc_sli4_queue_setup(phba);
  4125. if (unlikely(rc)) {
  4126. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4127. "0381 Error %d during queue setup.\n ", rc);
  4128. goto out_stop_timers;
  4129. }
  4130. /* Arm the CQs and then EQs on device */
  4131. lpfc_sli4_arm_cqeq_intr(phba);
  4132. /* Indicate device interrupt mode */
  4133. phba->sli4_hba.intr_enable = 1;
  4134. /* Allow asynchronous mailbox command to go through */
  4135. spin_lock_irq(&phba->hbalock);
  4136. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4137. spin_unlock_irq(&phba->hbalock);
  4138. /* Post receive buffers to the device */
  4139. lpfc_sli4_rb_setup(phba);
  4140. /* Reset HBA FCF states after HBA reset */
  4141. phba->fcf.fcf_flag = 0;
  4142. phba->fcf.current_rec.flag = 0;
  4143. /* Start the ELS watchdog timer */
  4144. mod_timer(&vport->els_tmofunc,
  4145. jiffies + HZ * (phba->fc_ratov * 2));
  4146. /* Start heart beat timer */
  4147. mod_timer(&phba->hb_tmofunc,
  4148. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4149. phba->hb_outstanding = 0;
  4150. phba->last_completion_time = jiffies;
  4151. /* Start error attention (ERATT) polling timer */
  4152. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4153. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4154. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4155. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4156. if (!rc) {
  4157. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4158. "2829 This device supports "
  4159. "Advanced Error Reporting (AER)\n");
  4160. spin_lock_irq(&phba->hbalock);
  4161. phba->hba_flag |= HBA_AER_ENABLED;
  4162. spin_unlock_irq(&phba->hbalock);
  4163. } else {
  4164. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4165. "2830 This device does not support "
  4166. "Advanced Error Reporting (AER)\n");
  4167. phba->cfg_aer_support = 0;
  4168. }
  4169. }
  4170. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  4171. /*
  4172. * The FC Port needs to register FCFI (index 0)
  4173. */
  4174. lpfc_reg_fcfi(phba, mboxq);
  4175. mboxq->vport = phba->pport;
  4176. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4177. if (rc == MBX_SUCCESS)
  4178. rc = 0;
  4179. else
  4180. goto out_unset_queue;
  4181. }
  4182. /*
  4183. * The port is ready, set the host's link state to LINK_DOWN
  4184. * in preparation for link interrupts.
  4185. */
  4186. spin_lock_irq(&phba->hbalock);
  4187. phba->link_state = LPFC_LINK_DOWN;
  4188. spin_unlock_irq(&phba->hbalock);
  4189. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  4190. out_unset_queue:
  4191. /* Unset all the queues set up in this routine when error out */
  4192. if (rc)
  4193. lpfc_sli4_queue_unset(phba);
  4194. out_stop_timers:
  4195. if (rc)
  4196. lpfc_stop_hba_timers(phba);
  4197. out_free_mbox:
  4198. mempool_free(mboxq, phba->mbox_mem_pool);
  4199. return rc;
  4200. }
  4201. /**
  4202. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4203. * @ptr: context object - pointer to hba structure.
  4204. *
  4205. * This is the callback function for mailbox timer. The mailbox
  4206. * timer is armed when a new mailbox command is issued and the timer
  4207. * is deleted when the mailbox complete. The function is called by
  4208. * the kernel timer code when a mailbox does not complete within
  4209. * expected time. This function wakes up the worker thread to
  4210. * process the mailbox timeout and returns. All the processing is
  4211. * done by the worker thread function lpfc_mbox_timeout_handler.
  4212. **/
  4213. void
  4214. lpfc_mbox_timeout(unsigned long ptr)
  4215. {
  4216. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4217. unsigned long iflag;
  4218. uint32_t tmo_posted;
  4219. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4220. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4221. if (!tmo_posted)
  4222. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4223. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4224. if (!tmo_posted)
  4225. lpfc_worker_wake_up(phba);
  4226. return;
  4227. }
  4228. /**
  4229. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4230. * @phba: Pointer to HBA context object.
  4231. *
  4232. * This function is called from worker thread when a mailbox command times out.
  4233. * The caller is not required to hold any locks. This function will reset the
  4234. * HBA and recover all the pending commands.
  4235. **/
  4236. void
  4237. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4238. {
  4239. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4240. MAILBOX_t *mb = &pmbox->u.mb;
  4241. struct lpfc_sli *psli = &phba->sli;
  4242. struct lpfc_sli_ring *pring;
  4243. /* Check the pmbox pointer first. There is a race condition
  4244. * between the mbox timeout handler getting executed in the
  4245. * worklist and the mailbox actually completing. When this
  4246. * race condition occurs, the mbox_active will be NULL.
  4247. */
  4248. spin_lock_irq(&phba->hbalock);
  4249. if (pmbox == NULL) {
  4250. lpfc_printf_log(phba, KERN_WARNING,
  4251. LOG_MBOX | LOG_SLI,
  4252. "0353 Active Mailbox cleared - mailbox timeout "
  4253. "exiting\n");
  4254. spin_unlock_irq(&phba->hbalock);
  4255. return;
  4256. }
  4257. /* Mbox cmd <mbxCommand> timeout */
  4258. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4259. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4260. mb->mbxCommand,
  4261. phba->pport->port_state,
  4262. phba->sli.sli_flag,
  4263. phba->sli.mbox_active);
  4264. spin_unlock_irq(&phba->hbalock);
  4265. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4266. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4267. * it to fail all oustanding SCSI IO.
  4268. */
  4269. spin_lock_irq(&phba->pport->work_port_lock);
  4270. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4271. spin_unlock_irq(&phba->pport->work_port_lock);
  4272. spin_lock_irq(&phba->hbalock);
  4273. phba->link_state = LPFC_LINK_UNKNOWN;
  4274. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4275. spin_unlock_irq(&phba->hbalock);
  4276. pring = &psli->ring[psli->fcp_ring];
  4277. lpfc_sli_abort_iocb_ring(phba, pring);
  4278. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4279. "0345 Resetting board due to mailbox timeout\n");
  4280. /* Reset the HBA device */
  4281. lpfc_reset_hba(phba);
  4282. }
  4283. /**
  4284. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4285. * @phba: Pointer to HBA context object.
  4286. * @pmbox: Pointer to mailbox object.
  4287. * @flag: Flag indicating how the mailbox need to be processed.
  4288. *
  4289. * This function is called by discovery code and HBA management code
  4290. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4291. * function gets the hbalock to protect the data structures.
  4292. * The mailbox command can be submitted in polling mode, in which case
  4293. * this function will wait in a polling loop for the completion of the
  4294. * mailbox.
  4295. * If the mailbox is submitted in no_wait mode (not polling) the
  4296. * function will submit the command and returns immediately without waiting
  4297. * for the mailbox completion. The no_wait is supported only when HBA
  4298. * is in SLI2/SLI3 mode - interrupts are enabled.
  4299. * The SLI interface allows only one mailbox pending at a time. If the
  4300. * mailbox is issued in polling mode and there is already a mailbox
  4301. * pending, then the function will return an error. If the mailbox is issued
  4302. * in NO_WAIT mode and there is a mailbox pending already, the function
  4303. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4304. * The sli layer owns the mailbox object until the completion of mailbox
  4305. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4306. * return codes the caller owns the mailbox command after the return of
  4307. * the function.
  4308. **/
  4309. static int
  4310. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4311. uint32_t flag)
  4312. {
  4313. MAILBOX_t *mb;
  4314. struct lpfc_sli *psli = &phba->sli;
  4315. uint32_t status, evtctr;
  4316. uint32_t ha_copy;
  4317. int i;
  4318. unsigned long timeout;
  4319. unsigned long drvr_flag = 0;
  4320. uint32_t word0, ldata;
  4321. void __iomem *to_slim;
  4322. int processing_queue = 0;
  4323. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4324. if (!pmbox) {
  4325. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4326. /* processing mbox queue from intr_handler */
  4327. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4328. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4329. return MBX_SUCCESS;
  4330. }
  4331. processing_queue = 1;
  4332. pmbox = lpfc_mbox_get(phba);
  4333. if (!pmbox) {
  4334. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4335. return MBX_SUCCESS;
  4336. }
  4337. }
  4338. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4339. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4340. if(!pmbox->vport) {
  4341. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4342. lpfc_printf_log(phba, KERN_ERR,
  4343. LOG_MBOX | LOG_VPORT,
  4344. "1806 Mbox x%x failed. No vport\n",
  4345. pmbox->u.mb.mbxCommand);
  4346. dump_stack();
  4347. goto out_not_finished;
  4348. }
  4349. }
  4350. /* If the PCI channel is in offline state, do not post mbox. */
  4351. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4352. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4353. goto out_not_finished;
  4354. }
  4355. /* If HBA has a deferred error attention, fail the iocb. */
  4356. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4357. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4358. goto out_not_finished;
  4359. }
  4360. psli = &phba->sli;
  4361. mb = &pmbox->u.mb;
  4362. status = MBX_SUCCESS;
  4363. if (phba->link_state == LPFC_HBA_ERROR) {
  4364. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4365. /* Mbox command <mbxCommand> cannot issue */
  4366. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4367. "(%d):0311 Mailbox command x%x cannot "
  4368. "issue Data: x%x x%x\n",
  4369. pmbox->vport ? pmbox->vport->vpi : 0,
  4370. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4371. goto out_not_finished;
  4372. }
  4373. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4374. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4375. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4376. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4377. "(%d):2528 Mailbox command x%x cannot "
  4378. "issue Data: x%x x%x\n",
  4379. pmbox->vport ? pmbox->vport->vpi : 0,
  4380. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4381. goto out_not_finished;
  4382. }
  4383. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4384. /* Polling for a mbox command when another one is already active
  4385. * is not allowed in SLI. Also, the driver must have established
  4386. * SLI2 mode to queue and process multiple mbox commands.
  4387. */
  4388. if (flag & MBX_POLL) {
  4389. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4390. /* Mbox command <mbxCommand> cannot issue */
  4391. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4392. "(%d):2529 Mailbox command x%x "
  4393. "cannot issue Data: x%x x%x\n",
  4394. pmbox->vport ? pmbox->vport->vpi : 0,
  4395. pmbox->u.mb.mbxCommand,
  4396. psli->sli_flag, flag);
  4397. goto out_not_finished;
  4398. }
  4399. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4400. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4401. /* Mbox command <mbxCommand> cannot issue */
  4402. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4403. "(%d):2530 Mailbox command x%x "
  4404. "cannot issue Data: x%x x%x\n",
  4405. pmbox->vport ? pmbox->vport->vpi : 0,
  4406. pmbox->u.mb.mbxCommand,
  4407. psli->sli_flag, flag);
  4408. goto out_not_finished;
  4409. }
  4410. /* Another mailbox command is still being processed, queue this
  4411. * command to be processed later.
  4412. */
  4413. lpfc_mbox_put(phba, pmbox);
  4414. /* Mbox cmd issue - BUSY */
  4415. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4416. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4417. "x%x x%x x%x x%x\n",
  4418. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4419. mb->mbxCommand, phba->pport->port_state,
  4420. psli->sli_flag, flag);
  4421. psli->slistat.mbox_busy++;
  4422. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4423. if (pmbox->vport) {
  4424. lpfc_debugfs_disc_trc(pmbox->vport,
  4425. LPFC_DISC_TRC_MBOX_VPORT,
  4426. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4427. (uint32_t)mb->mbxCommand,
  4428. mb->un.varWords[0], mb->un.varWords[1]);
  4429. }
  4430. else {
  4431. lpfc_debugfs_disc_trc(phba->pport,
  4432. LPFC_DISC_TRC_MBOX,
  4433. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4434. (uint32_t)mb->mbxCommand,
  4435. mb->un.varWords[0], mb->un.varWords[1]);
  4436. }
  4437. return MBX_BUSY;
  4438. }
  4439. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4440. /* If we are not polling, we MUST be in SLI2 mode */
  4441. if (flag != MBX_POLL) {
  4442. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4443. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4444. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4445. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4446. /* Mbox command <mbxCommand> cannot issue */
  4447. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4448. "(%d):2531 Mailbox command x%x "
  4449. "cannot issue Data: x%x x%x\n",
  4450. pmbox->vport ? pmbox->vport->vpi : 0,
  4451. pmbox->u.mb.mbxCommand,
  4452. psli->sli_flag, flag);
  4453. goto out_not_finished;
  4454. }
  4455. /* timeout active mbox command */
  4456. mod_timer(&psli->mbox_tmo, (jiffies +
  4457. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4458. }
  4459. /* Mailbox cmd <cmd> issue */
  4460. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4461. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4462. "x%x\n",
  4463. pmbox->vport ? pmbox->vport->vpi : 0,
  4464. mb->mbxCommand, phba->pport->port_state,
  4465. psli->sli_flag, flag);
  4466. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4467. if (pmbox->vport) {
  4468. lpfc_debugfs_disc_trc(pmbox->vport,
  4469. LPFC_DISC_TRC_MBOX_VPORT,
  4470. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4471. (uint32_t)mb->mbxCommand,
  4472. mb->un.varWords[0], mb->un.varWords[1]);
  4473. }
  4474. else {
  4475. lpfc_debugfs_disc_trc(phba->pport,
  4476. LPFC_DISC_TRC_MBOX,
  4477. "MBOX Send: cmd:x%x mb:x%x x%x",
  4478. (uint32_t)mb->mbxCommand,
  4479. mb->un.varWords[0], mb->un.varWords[1]);
  4480. }
  4481. }
  4482. psli->slistat.mbox_cmd++;
  4483. evtctr = psli->slistat.mbox_event;
  4484. /* next set own bit for the adapter and copy over command word */
  4485. mb->mbxOwner = OWN_CHIP;
  4486. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4487. /* Populate mbox extension offset word. */
  4488. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4489. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4490. = (uint8_t *)phba->mbox_ext
  4491. - (uint8_t *)phba->mbox;
  4492. }
  4493. /* Copy the mailbox extension data */
  4494. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4495. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4496. (uint8_t *)phba->mbox_ext,
  4497. pmbox->in_ext_byte_len);
  4498. }
  4499. /* Copy command data to host SLIM area */
  4500. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4501. } else {
  4502. /* Populate mbox extension offset word. */
  4503. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4504. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4505. = MAILBOX_HBA_EXT_OFFSET;
  4506. /* Copy the mailbox extension data */
  4507. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4508. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4509. MAILBOX_HBA_EXT_OFFSET,
  4510. pmbox->context2, pmbox->in_ext_byte_len);
  4511. }
  4512. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4513. /* copy command data into host mbox for cmpl */
  4514. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4515. }
  4516. /* First copy mbox command data to HBA SLIM, skip past first
  4517. word */
  4518. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4519. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4520. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4521. /* Next copy over first word, with mbxOwner set */
  4522. ldata = *((uint32_t *)mb);
  4523. to_slim = phba->MBslimaddr;
  4524. writel(ldata, to_slim);
  4525. readl(to_slim); /* flush */
  4526. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4527. /* switch over to host mailbox */
  4528. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4529. }
  4530. }
  4531. wmb();
  4532. switch (flag) {
  4533. case MBX_NOWAIT:
  4534. /* Set up reference to mailbox command */
  4535. psli->mbox_active = pmbox;
  4536. /* Interrupt board to do it */
  4537. writel(CA_MBATT, phba->CAregaddr);
  4538. readl(phba->CAregaddr); /* flush */
  4539. /* Don't wait for it to finish, just return */
  4540. break;
  4541. case MBX_POLL:
  4542. /* Set up null reference to mailbox command */
  4543. psli->mbox_active = NULL;
  4544. /* Interrupt board to do it */
  4545. writel(CA_MBATT, phba->CAregaddr);
  4546. readl(phba->CAregaddr); /* flush */
  4547. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4548. /* First read mbox status word */
  4549. word0 = *((uint32_t *)phba->mbox);
  4550. word0 = le32_to_cpu(word0);
  4551. } else {
  4552. /* First read mbox status word */
  4553. word0 = readl(phba->MBslimaddr);
  4554. }
  4555. /* Read the HBA Host Attention Register */
  4556. ha_copy = readl(phba->HAregaddr);
  4557. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4558. mb->mbxCommand) *
  4559. 1000) + jiffies;
  4560. i = 0;
  4561. /* Wait for command to complete */
  4562. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4563. (!(ha_copy & HA_MBATT) &&
  4564. (phba->link_state > LPFC_WARM_START))) {
  4565. if (time_after(jiffies, timeout)) {
  4566. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4567. spin_unlock_irqrestore(&phba->hbalock,
  4568. drvr_flag);
  4569. goto out_not_finished;
  4570. }
  4571. /* Check if we took a mbox interrupt while we were
  4572. polling */
  4573. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4574. && (evtctr != psli->slistat.mbox_event))
  4575. break;
  4576. if (i++ > 10) {
  4577. spin_unlock_irqrestore(&phba->hbalock,
  4578. drvr_flag);
  4579. msleep(1);
  4580. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4581. }
  4582. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4583. /* First copy command data */
  4584. word0 = *((uint32_t *)phba->mbox);
  4585. word0 = le32_to_cpu(word0);
  4586. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4587. MAILBOX_t *slimmb;
  4588. uint32_t slimword0;
  4589. /* Check real SLIM for any errors */
  4590. slimword0 = readl(phba->MBslimaddr);
  4591. slimmb = (MAILBOX_t *) & slimword0;
  4592. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4593. && slimmb->mbxStatus) {
  4594. psli->sli_flag &=
  4595. ~LPFC_SLI_ACTIVE;
  4596. word0 = slimword0;
  4597. }
  4598. }
  4599. } else {
  4600. /* First copy command data */
  4601. word0 = readl(phba->MBslimaddr);
  4602. }
  4603. /* Read the HBA Host Attention Register */
  4604. ha_copy = readl(phba->HAregaddr);
  4605. }
  4606. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4607. /* copy results back to user */
  4608. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4609. /* Copy the mailbox extension data */
  4610. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4611. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4612. pmbox->context2,
  4613. pmbox->out_ext_byte_len);
  4614. }
  4615. } else {
  4616. /* First copy command data */
  4617. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4618. MAILBOX_CMD_SIZE);
  4619. /* Copy the mailbox extension data */
  4620. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4621. lpfc_memcpy_from_slim(pmbox->context2,
  4622. phba->MBslimaddr +
  4623. MAILBOX_HBA_EXT_OFFSET,
  4624. pmbox->out_ext_byte_len);
  4625. }
  4626. }
  4627. writel(HA_MBATT, phba->HAregaddr);
  4628. readl(phba->HAregaddr); /* flush */
  4629. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4630. status = mb->mbxStatus;
  4631. }
  4632. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4633. return status;
  4634. out_not_finished:
  4635. if (processing_queue) {
  4636. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4637. lpfc_mbox_cmpl_put(phba, pmbox);
  4638. }
  4639. return MBX_NOT_FINISHED;
  4640. }
  4641. /**
  4642. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4643. * @phba: Pointer to HBA context object.
  4644. *
  4645. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4646. * the driver internal pending mailbox queue. It will then try to wait out the
  4647. * possible outstanding mailbox command before return.
  4648. *
  4649. * Returns:
  4650. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4651. * the outstanding mailbox command timed out.
  4652. **/
  4653. static int
  4654. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4655. {
  4656. struct lpfc_sli *psli = &phba->sli;
  4657. uint8_t actcmd = MBX_HEARTBEAT;
  4658. int rc = 0;
  4659. unsigned long timeout;
  4660. /* Mark the asynchronous mailbox command posting as blocked */
  4661. spin_lock_irq(&phba->hbalock);
  4662. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4663. if (phba->sli.mbox_active)
  4664. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4665. spin_unlock_irq(&phba->hbalock);
  4666. /* Determine how long we might wait for the active mailbox
  4667. * command to be gracefully completed by firmware.
  4668. */
  4669. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4670. jiffies;
  4671. /* Wait for the outstnading mailbox command to complete */
  4672. while (phba->sli.mbox_active) {
  4673. /* Check active mailbox complete status every 2ms */
  4674. msleep(2);
  4675. if (time_after(jiffies, timeout)) {
  4676. /* Timeout, marked the outstanding cmd not complete */
  4677. rc = 1;
  4678. break;
  4679. }
  4680. }
  4681. /* Can not cleanly block async mailbox command, fails it */
  4682. if (rc) {
  4683. spin_lock_irq(&phba->hbalock);
  4684. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4685. spin_unlock_irq(&phba->hbalock);
  4686. }
  4687. return rc;
  4688. }
  4689. /**
  4690. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4691. * @phba: Pointer to HBA context object.
  4692. *
  4693. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4694. * commands from the driver internal pending mailbox queue. It makes sure
  4695. * that there is no outstanding mailbox command before resuming posting
  4696. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4697. * mailbox command, it will try to wait it out before resuming asynchronous
  4698. * mailbox command posting.
  4699. **/
  4700. static void
  4701. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4702. {
  4703. struct lpfc_sli *psli = &phba->sli;
  4704. spin_lock_irq(&phba->hbalock);
  4705. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4706. /* Asynchronous mailbox posting is not blocked, do nothing */
  4707. spin_unlock_irq(&phba->hbalock);
  4708. return;
  4709. }
  4710. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4711. * successful or timeout, after timing-out the outstanding mailbox
  4712. * command shall always be removed, so just unblock posting async
  4713. * mailbox command and resume
  4714. */
  4715. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4716. spin_unlock_irq(&phba->hbalock);
  4717. /* wake up worker thread to post asynchronlous mailbox command */
  4718. lpfc_worker_wake_up(phba);
  4719. }
  4720. /**
  4721. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4722. * @phba: Pointer to HBA context object.
  4723. * @mboxq: Pointer to mailbox object.
  4724. *
  4725. * The function posts a mailbox to the port. The mailbox is expected
  4726. * to be comletely filled in and ready for the port to operate on it.
  4727. * This routine executes a synchronous completion operation on the
  4728. * mailbox by polling for its completion.
  4729. *
  4730. * The caller must not be holding any locks when calling this routine.
  4731. *
  4732. * Returns:
  4733. * MBX_SUCCESS - mailbox posted successfully
  4734. * Any of the MBX error values.
  4735. **/
  4736. static int
  4737. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4738. {
  4739. int rc = MBX_SUCCESS;
  4740. unsigned long iflag;
  4741. uint32_t db_ready;
  4742. uint32_t mcqe_status;
  4743. uint32_t mbx_cmnd;
  4744. unsigned long timeout;
  4745. struct lpfc_sli *psli = &phba->sli;
  4746. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4747. struct lpfc_bmbx_create *mbox_rgn;
  4748. struct dma_address *dma_address;
  4749. struct lpfc_register bmbx_reg;
  4750. /*
  4751. * Only one mailbox can be active to the bootstrap mailbox region
  4752. * at a time and there is no queueing provided.
  4753. */
  4754. spin_lock_irqsave(&phba->hbalock, iflag);
  4755. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4756. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4757. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4758. "(%d):2532 Mailbox command x%x (x%x) "
  4759. "cannot issue Data: x%x x%x\n",
  4760. mboxq->vport ? mboxq->vport->vpi : 0,
  4761. mboxq->u.mb.mbxCommand,
  4762. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4763. psli->sli_flag, MBX_POLL);
  4764. return MBXERR_ERROR;
  4765. }
  4766. /* The server grabs the token and owns it until release */
  4767. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4768. phba->sli.mbox_active = mboxq;
  4769. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4770. /*
  4771. * Initialize the bootstrap memory region to avoid stale data areas
  4772. * in the mailbox post. Then copy the caller's mailbox contents to
  4773. * the bmbx mailbox region.
  4774. */
  4775. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4776. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4777. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4778. sizeof(struct lpfc_mqe));
  4779. /* Post the high mailbox dma address to the port and wait for ready. */
  4780. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4781. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4782. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4783. * 1000) + jiffies;
  4784. do {
  4785. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4786. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4787. if (!db_ready)
  4788. msleep(2);
  4789. if (time_after(jiffies, timeout)) {
  4790. rc = MBXERR_ERROR;
  4791. goto exit;
  4792. }
  4793. } while (!db_ready);
  4794. /* Post the low mailbox dma address to the port. */
  4795. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4796. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4797. * 1000) + jiffies;
  4798. do {
  4799. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4800. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4801. if (!db_ready)
  4802. msleep(2);
  4803. if (time_after(jiffies, timeout)) {
  4804. rc = MBXERR_ERROR;
  4805. goto exit;
  4806. }
  4807. } while (!db_ready);
  4808. /*
  4809. * Read the CQ to ensure the mailbox has completed.
  4810. * If so, update the mailbox status so that the upper layers
  4811. * can complete the request normally.
  4812. */
  4813. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4814. sizeof(struct lpfc_mqe));
  4815. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4816. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4817. sizeof(struct lpfc_mcqe));
  4818. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4819. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4820. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4821. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4822. rc = MBXERR_ERROR;
  4823. } else
  4824. lpfc_sli4_swap_str(phba, mboxq);
  4825. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4826. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4827. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4828. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4829. mboxq->vport ? mboxq->vport->vpi : 0,
  4830. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4831. bf_get(lpfc_mqe_status, mb),
  4832. mb->un.mb_words[0], mb->un.mb_words[1],
  4833. mb->un.mb_words[2], mb->un.mb_words[3],
  4834. mb->un.mb_words[4], mb->un.mb_words[5],
  4835. mb->un.mb_words[6], mb->un.mb_words[7],
  4836. mb->un.mb_words[8], mb->un.mb_words[9],
  4837. mb->un.mb_words[10], mb->un.mb_words[11],
  4838. mb->un.mb_words[12], mboxq->mcqe.word0,
  4839. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4840. mboxq->mcqe.trailer);
  4841. exit:
  4842. /* We are holding the token, no needed for lock when release */
  4843. spin_lock_irqsave(&phba->hbalock, iflag);
  4844. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4845. phba->sli.mbox_active = NULL;
  4846. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4847. return rc;
  4848. }
  4849. /**
  4850. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4851. * @phba: Pointer to HBA context object.
  4852. * @pmbox: Pointer to mailbox object.
  4853. * @flag: Flag indicating how the mailbox need to be processed.
  4854. *
  4855. * This function is called by discovery code and HBA management code to submit
  4856. * a mailbox command to firmware with SLI-4 interface spec.
  4857. *
  4858. * Return codes the caller owns the mailbox command after the return of the
  4859. * function.
  4860. **/
  4861. static int
  4862. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4863. uint32_t flag)
  4864. {
  4865. struct lpfc_sli *psli = &phba->sli;
  4866. unsigned long iflags;
  4867. int rc;
  4868. rc = lpfc_mbox_dev_check(phba);
  4869. if (unlikely(rc)) {
  4870. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4871. "(%d):2544 Mailbox command x%x (x%x) "
  4872. "cannot issue Data: x%x x%x\n",
  4873. mboxq->vport ? mboxq->vport->vpi : 0,
  4874. mboxq->u.mb.mbxCommand,
  4875. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4876. psli->sli_flag, flag);
  4877. goto out_not_finished;
  4878. }
  4879. /* Detect polling mode and jump to a handler */
  4880. if (!phba->sli4_hba.intr_enable) {
  4881. if (flag == MBX_POLL)
  4882. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4883. else
  4884. rc = -EIO;
  4885. if (rc != MBX_SUCCESS)
  4886. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4887. "(%d):2541 Mailbox command x%x "
  4888. "(x%x) cannot issue Data: x%x x%x\n",
  4889. mboxq->vport ? mboxq->vport->vpi : 0,
  4890. mboxq->u.mb.mbxCommand,
  4891. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4892. psli->sli_flag, flag);
  4893. return rc;
  4894. } else if (flag == MBX_POLL) {
  4895. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4896. "(%d):2542 Try to issue mailbox command "
  4897. "x%x (x%x) synchronously ahead of async"
  4898. "mailbox command queue: x%x x%x\n",
  4899. mboxq->vport ? mboxq->vport->vpi : 0,
  4900. mboxq->u.mb.mbxCommand,
  4901. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4902. psli->sli_flag, flag);
  4903. /* Try to block the asynchronous mailbox posting */
  4904. rc = lpfc_sli4_async_mbox_block(phba);
  4905. if (!rc) {
  4906. /* Successfully blocked, now issue sync mbox cmd */
  4907. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4908. if (rc != MBX_SUCCESS)
  4909. lpfc_printf_log(phba, KERN_ERR,
  4910. LOG_MBOX | LOG_SLI,
  4911. "(%d):2597 Mailbox command "
  4912. "x%x (x%x) cannot issue "
  4913. "Data: x%x x%x\n",
  4914. mboxq->vport ?
  4915. mboxq->vport->vpi : 0,
  4916. mboxq->u.mb.mbxCommand,
  4917. lpfc_sli4_mbox_opcode_get(phba,
  4918. mboxq),
  4919. psli->sli_flag, flag);
  4920. /* Unblock the async mailbox posting afterward */
  4921. lpfc_sli4_async_mbox_unblock(phba);
  4922. }
  4923. return rc;
  4924. }
  4925. /* Now, interrupt mode asynchrous mailbox command */
  4926. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4927. if (rc) {
  4928. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4929. "(%d):2543 Mailbox command x%x (x%x) "
  4930. "cannot issue Data: x%x x%x\n",
  4931. mboxq->vport ? mboxq->vport->vpi : 0,
  4932. mboxq->u.mb.mbxCommand,
  4933. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4934. psli->sli_flag, flag);
  4935. goto out_not_finished;
  4936. }
  4937. /* Put the mailbox command to the driver internal FIFO */
  4938. psli->slistat.mbox_busy++;
  4939. spin_lock_irqsave(&phba->hbalock, iflags);
  4940. lpfc_mbox_put(phba, mboxq);
  4941. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4942. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4943. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4944. "x%x (x%x) x%x x%x x%x\n",
  4945. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4946. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4947. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4948. phba->pport->port_state,
  4949. psli->sli_flag, MBX_NOWAIT);
  4950. /* Wake up worker thread to transport mailbox command from head */
  4951. lpfc_worker_wake_up(phba);
  4952. return MBX_BUSY;
  4953. out_not_finished:
  4954. return MBX_NOT_FINISHED;
  4955. }
  4956. /**
  4957. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4958. * @phba: Pointer to HBA context object.
  4959. *
  4960. * This function is called by worker thread to send a mailbox command to
  4961. * SLI4 HBA firmware.
  4962. *
  4963. **/
  4964. int
  4965. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4966. {
  4967. struct lpfc_sli *psli = &phba->sli;
  4968. LPFC_MBOXQ_t *mboxq;
  4969. int rc = MBX_SUCCESS;
  4970. unsigned long iflags;
  4971. struct lpfc_mqe *mqe;
  4972. uint32_t mbx_cmnd;
  4973. /* Check interrupt mode before post async mailbox command */
  4974. if (unlikely(!phba->sli4_hba.intr_enable))
  4975. return MBX_NOT_FINISHED;
  4976. /* Check for mailbox command service token */
  4977. spin_lock_irqsave(&phba->hbalock, iflags);
  4978. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4979. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4980. return MBX_NOT_FINISHED;
  4981. }
  4982. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4983. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4984. return MBX_NOT_FINISHED;
  4985. }
  4986. if (unlikely(phba->sli.mbox_active)) {
  4987. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4988. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4989. "0384 There is pending active mailbox cmd\n");
  4990. return MBX_NOT_FINISHED;
  4991. }
  4992. /* Take the mailbox command service token */
  4993. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4994. /* Get the next mailbox command from head of queue */
  4995. mboxq = lpfc_mbox_get(phba);
  4996. /* If no more mailbox command waiting for post, we're done */
  4997. if (!mboxq) {
  4998. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4999. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5000. return MBX_SUCCESS;
  5001. }
  5002. phba->sli.mbox_active = mboxq;
  5003. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5004. /* Check device readiness for posting mailbox command */
  5005. rc = lpfc_mbox_dev_check(phba);
  5006. if (unlikely(rc))
  5007. /* Driver clean routine will clean up pending mailbox */
  5008. goto out_not_finished;
  5009. /* Prepare the mbox command to be posted */
  5010. mqe = &mboxq->u.mqe;
  5011. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5012. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5013. mod_timer(&psli->mbox_tmo, (jiffies +
  5014. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5015. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5016. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5017. "x%x x%x\n",
  5018. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5019. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5020. phba->pport->port_state, psli->sli_flag);
  5021. if (mbx_cmnd != MBX_HEARTBEAT) {
  5022. if (mboxq->vport) {
  5023. lpfc_debugfs_disc_trc(mboxq->vport,
  5024. LPFC_DISC_TRC_MBOX_VPORT,
  5025. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5026. mbx_cmnd, mqe->un.mb_words[0],
  5027. mqe->un.mb_words[1]);
  5028. } else {
  5029. lpfc_debugfs_disc_trc(phba->pport,
  5030. LPFC_DISC_TRC_MBOX,
  5031. "MBOX Send: cmd:x%x mb:x%x x%x",
  5032. mbx_cmnd, mqe->un.mb_words[0],
  5033. mqe->un.mb_words[1]);
  5034. }
  5035. }
  5036. psli->slistat.mbox_cmd++;
  5037. /* Post the mailbox command to the port */
  5038. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5039. if (rc != MBX_SUCCESS) {
  5040. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5041. "(%d):2533 Mailbox command x%x (x%x) "
  5042. "cannot issue Data: x%x x%x\n",
  5043. mboxq->vport ? mboxq->vport->vpi : 0,
  5044. mboxq->u.mb.mbxCommand,
  5045. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5046. psli->sli_flag, MBX_NOWAIT);
  5047. goto out_not_finished;
  5048. }
  5049. return rc;
  5050. out_not_finished:
  5051. spin_lock_irqsave(&phba->hbalock, iflags);
  5052. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5053. __lpfc_mbox_cmpl_put(phba, mboxq);
  5054. /* Release the token */
  5055. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5056. phba->sli.mbox_active = NULL;
  5057. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5058. return MBX_NOT_FINISHED;
  5059. }
  5060. /**
  5061. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5062. * @phba: Pointer to HBA context object.
  5063. * @pmbox: Pointer to mailbox object.
  5064. * @flag: Flag indicating how the mailbox need to be processed.
  5065. *
  5066. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5067. * the API jump table function pointer from the lpfc_hba struct.
  5068. *
  5069. * Return codes the caller owns the mailbox command after the return of the
  5070. * function.
  5071. **/
  5072. int
  5073. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5074. {
  5075. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5076. }
  5077. /**
  5078. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5079. * @phba: The hba struct for which this call is being executed.
  5080. * @dev_grp: The HBA PCI-Device group number.
  5081. *
  5082. * This routine sets up the mbox interface API function jump table in @phba
  5083. * struct.
  5084. * Returns: 0 - success, -ENODEV - failure.
  5085. **/
  5086. int
  5087. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5088. {
  5089. switch (dev_grp) {
  5090. case LPFC_PCI_DEV_LP:
  5091. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5092. phba->lpfc_sli_handle_slow_ring_event =
  5093. lpfc_sli_handle_slow_ring_event_s3;
  5094. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5095. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5096. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5097. break;
  5098. case LPFC_PCI_DEV_OC:
  5099. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5100. phba->lpfc_sli_handle_slow_ring_event =
  5101. lpfc_sli_handle_slow_ring_event_s4;
  5102. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5103. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5104. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5105. break;
  5106. default:
  5107. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5108. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5109. dev_grp);
  5110. return -ENODEV;
  5111. break;
  5112. }
  5113. return 0;
  5114. }
  5115. /**
  5116. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5117. * @phba: Pointer to HBA context object.
  5118. * @pring: Pointer to driver SLI ring object.
  5119. * @piocb: Pointer to address of newly added command iocb.
  5120. *
  5121. * This function is called with hbalock held to add a command
  5122. * iocb to the txq when SLI layer cannot submit the command iocb
  5123. * to the ring.
  5124. **/
  5125. void
  5126. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5127. struct lpfc_iocbq *piocb)
  5128. {
  5129. /* Insert the caller's iocb in the txq tail for later processing. */
  5130. list_add_tail(&piocb->list, &pring->txq);
  5131. pring->txq_cnt++;
  5132. }
  5133. /**
  5134. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5135. * @phba: Pointer to HBA context object.
  5136. * @pring: Pointer to driver SLI ring object.
  5137. * @piocb: Pointer to address of newly added command iocb.
  5138. *
  5139. * This function is called with hbalock held before a new
  5140. * iocb is submitted to the firmware. This function checks
  5141. * txq to flush the iocbs in txq to Firmware before
  5142. * submitting new iocbs to the Firmware.
  5143. * If there are iocbs in the txq which need to be submitted
  5144. * to firmware, lpfc_sli_next_iocb returns the first element
  5145. * of the txq after dequeuing it from txq.
  5146. * If there is no iocb in the txq then the function will return
  5147. * *piocb and *piocb is set to NULL. Caller needs to check
  5148. * *piocb to find if there are more commands in the txq.
  5149. **/
  5150. static struct lpfc_iocbq *
  5151. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5152. struct lpfc_iocbq **piocb)
  5153. {
  5154. struct lpfc_iocbq * nextiocb;
  5155. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5156. if (!nextiocb) {
  5157. nextiocb = *piocb;
  5158. *piocb = NULL;
  5159. }
  5160. return nextiocb;
  5161. }
  5162. /**
  5163. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5164. * @phba: Pointer to HBA context object.
  5165. * @ring_number: SLI ring number to issue iocb on.
  5166. * @piocb: Pointer to command iocb.
  5167. * @flag: Flag indicating if this command can be put into txq.
  5168. *
  5169. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5170. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5171. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5172. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5173. * this function allows only iocbs for posting buffers. This function finds
  5174. * next available slot in the command ring and posts the command to the
  5175. * available slot and writes the port attention register to request HBA start
  5176. * processing new iocb. If there is no slot available in the ring and
  5177. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5178. * the function returns IOCB_BUSY.
  5179. *
  5180. * This function is called with hbalock held. The function will return success
  5181. * after it successfully submit the iocb to firmware or after adding to the
  5182. * txq.
  5183. **/
  5184. static int
  5185. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5186. struct lpfc_iocbq *piocb, uint32_t flag)
  5187. {
  5188. struct lpfc_iocbq *nextiocb;
  5189. IOCB_t *iocb;
  5190. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5191. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5192. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5193. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5194. lpfc_printf_log(phba, KERN_ERR,
  5195. LOG_SLI | LOG_VPORT,
  5196. "1807 IOCB x%x failed. No vport\n",
  5197. piocb->iocb.ulpCommand);
  5198. dump_stack();
  5199. return IOCB_ERROR;
  5200. }
  5201. /* If the PCI channel is in offline state, do not post iocbs. */
  5202. if (unlikely(pci_channel_offline(phba->pcidev)))
  5203. return IOCB_ERROR;
  5204. /* If HBA has a deferred error attention, fail the iocb. */
  5205. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5206. return IOCB_ERROR;
  5207. /*
  5208. * We should never get an IOCB if we are in a < LINK_DOWN state
  5209. */
  5210. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5211. return IOCB_ERROR;
  5212. /*
  5213. * Check to see if we are blocking IOCB processing because of a
  5214. * outstanding event.
  5215. */
  5216. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5217. goto iocb_busy;
  5218. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5219. /*
  5220. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5221. * can be issued if the link is not up.
  5222. */
  5223. switch (piocb->iocb.ulpCommand) {
  5224. case CMD_GEN_REQUEST64_CR:
  5225. case CMD_GEN_REQUEST64_CX:
  5226. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5227. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5228. FC_RCTL_DD_UNSOL_CMD) ||
  5229. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5230. MENLO_TRANSPORT_TYPE))
  5231. goto iocb_busy;
  5232. break;
  5233. case CMD_QUE_RING_BUF_CN:
  5234. case CMD_QUE_RING_BUF64_CN:
  5235. /*
  5236. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5237. * completion, iocb_cmpl MUST be 0.
  5238. */
  5239. if (piocb->iocb_cmpl)
  5240. piocb->iocb_cmpl = NULL;
  5241. /*FALLTHROUGH*/
  5242. case CMD_CREATE_XRI_CR:
  5243. case CMD_CLOSE_XRI_CN:
  5244. case CMD_CLOSE_XRI_CX:
  5245. break;
  5246. default:
  5247. goto iocb_busy;
  5248. }
  5249. /*
  5250. * For FCP commands, we must be in a state where we can process link
  5251. * attention events.
  5252. */
  5253. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5254. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5255. goto iocb_busy;
  5256. }
  5257. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5258. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5259. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5260. if (iocb)
  5261. lpfc_sli_update_ring(phba, pring);
  5262. else
  5263. lpfc_sli_update_full_ring(phba, pring);
  5264. if (!piocb)
  5265. return IOCB_SUCCESS;
  5266. goto out_busy;
  5267. iocb_busy:
  5268. pring->stats.iocb_cmd_delay++;
  5269. out_busy:
  5270. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5271. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5272. return IOCB_SUCCESS;
  5273. }
  5274. return IOCB_BUSY;
  5275. }
  5276. /**
  5277. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5278. * @phba: Pointer to HBA context object.
  5279. * @piocb: Pointer to command iocb.
  5280. * @sglq: Pointer to the scatter gather queue object.
  5281. *
  5282. * This routine converts the bpl or bde that is in the IOCB
  5283. * to a sgl list for the sli4 hardware. The physical address
  5284. * of the bpl/bde is converted back to a virtual address.
  5285. * If the IOCB contains a BPL then the list of BDE's is
  5286. * converted to sli4_sge's. If the IOCB contains a single
  5287. * BDE then it is converted to a single sli_sge.
  5288. * The IOCB is still in cpu endianess so the contents of
  5289. * the bpl can be used without byte swapping.
  5290. *
  5291. * Returns valid XRI = Success, NO_XRI = Failure.
  5292. **/
  5293. static uint16_t
  5294. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5295. struct lpfc_sglq *sglq)
  5296. {
  5297. uint16_t xritag = NO_XRI;
  5298. struct ulp_bde64 *bpl = NULL;
  5299. struct ulp_bde64 bde;
  5300. struct sli4_sge *sgl = NULL;
  5301. IOCB_t *icmd;
  5302. int numBdes = 0;
  5303. int i = 0;
  5304. uint32_t offset = 0; /* accumulated offset in the sg request list */
  5305. int inbound = 0; /* number of sg reply entries inbound from firmware */
  5306. if (!piocbq || !sglq)
  5307. return xritag;
  5308. sgl = (struct sli4_sge *)sglq->sgl;
  5309. icmd = &piocbq->iocb;
  5310. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5311. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5312. sizeof(struct ulp_bde64);
  5313. /* The addrHigh and addrLow fields within the IOCB
  5314. * have not been byteswapped yet so there is no
  5315. * need to swap them back.
  5316. */
  5317. bpl = (struct ulp_bde64 *)
  5318. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5319. if (!bpl)
  5320. return xritag;
  5321. for (i = 0; i < numBdes; i++) {
  5322. /* Should already be byte swapped. */
  5323. sgl->addr_hi = bpl->addrHigh;
  5324. sgl->addr_lo = bpl->addrLow;
  5325. if ((i+1) == numBdes)
  5326. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5327. else
  5328. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5329. sgl->word2 = cpu_to_le32(sgl->word2);
  5330. /* swap the size field back to the cpu so we
  5331. * can assign it to the sgl.
  5332. */
  5333. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5334. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5335. /* The offsets in the sgl need to be accumulated
  5336. * separately for the request and reply lists.
  5337. * The request is always first, the reply follows.
  5338. */
  5339. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  5340. /* add up the reply sg entries */
  5341. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  5342. inbound++;
  5343. /* first inbound? reset the offset */
  5344. if (inbound == 1)
  5345. offset = 0;
  5346. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  5347. offset += bde.tus.f.bdeSize;
  5348. }
  5349. bpl++;
  5350. sgl++;
  5351. }
  5352. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5353. /* The addrHigh and addrLow fields of the BDE have not
  5354. * been byteswapped yet so they need to be swapped
  5355. * before putting them in the sgl.
  5356. */
  5357. sgl->addr_hi =
  5358. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5359. sgl->addr_lo =
  5360. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5361. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5362. sgl->word2 = cpu_to_le32(sgl->word2);
  5363. sgl->sge_len =
  5364. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5365. }
  5366. return sglq->sli4_xritag;
  5367. }
  5368. /**
  5369. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5370. * @phba: Pointer to HBA context object.
  5371. *
  5372. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5373. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5374. * held.
  5375. *
  5376. * Return: index into SLI4 fast-path FCP queue index.
  5377. **/
  5378. static uint32_t
  5379. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5380. {
  5381. ++phba->fcp_qidx;
  5382. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5383. phba->fcp_qidx = 0;
  5384. return phba->fcp_qidx;
  5385. }
  5386. /**
  5387. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5388. * @phba: Pointer to HBA context object.
  5389. * @piocb: Pointer to command iocb.
  5390. * @wqe: Pointer to the work queue entry.
  5391. *
  5392. * This routine converts the iocb command to its Work Queue Entry
  5393. * equivalent. The wqe pointer should not have any fields set when
  5394. * this routine is called because it will memcpy over them.
  5395. * This routine does not set the CQ_ID or the WQEC bits in the
  5396. * wqe.
  5397. *
  5398. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5399. **/
  5400. static int
  5401. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5402. union lpfc_wqe *wqe)
  5403. {
  5404. uint32_t xmit_len = 0, total_len = 0;
  5405. uint8_t ct = 0;
  5406. uint32_t fip;
  5407. uint32_t abort_tag;
  5408. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5409. uint8_t cmnd;
  5410. uint16_t xritag;
  5411. uint16_t abrt_iotag;
  5412. struct lpfc_iocbq *abrtiocbq;
  5413. struct ulp_bde64 *bpl = NULL;
  5414. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5415. int numBdes, i;
  5416. struct ulp_bde64 bde;
  5417. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5418. /* The fcp commands will set command type */
  5419. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5420. command_type = FCP_COMMAND;
  5421. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5422. command_type = ELS_COMMAND_FIP;
  5423. else
  5424. command_type = ELS_COMMAND_NON_FIP;
  5425. /* Some of the fields are in the right position already */
  5426. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5427. abort_tag = (uint32_t) iocbq->iotag;
  5428. xritag = iocbq->sli4_xritag;
  5429. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5430. /* words0-2 bpl convert bde */
  5431. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5432. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5433. sizeof(struct ulp_bde64);
  5434. bpl = (struct ulp_bde64 *)
  5435. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5436. if (!bpl)
  5437. return IOCB_ERROR;
  5438. /* Should already be byte swapped. */
  5439. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5440. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5441. /* swap the size field back to the cpu so we
  5442. * can assign it to the sgl.
  5443. */
  5444. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5445. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5446. total_len = 0;
  5447. for (i = 0; i < numBdes; i++) {
  5448. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5449. total_len += bde.tus.f.bdeSize;
  5450. }
  5451. } else
  5452. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5453. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5454. cmnd = iocbq->iocb.ulpCommand;
  5455. switch (iocbq->iocb.ulpCommand) {
  5456. case CMD_ELS_REQUEST64_CR:
  5457. if (!iocbq->iocb.ulpLe) {
  5458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5459. "2007 Only Limited Edition cmd Format"
  5460. " supported 0x%x\n",
  5461. iocbq->iocb.ulpCommand);
  5462. return IOCB_ERROR;
  5463. }
  5464. wqe->els_req.payload_len = xmit_len;
  5465. /* Els_reguest64 has a TMO */
  5466. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5467. iocbq->iocb.ulpTimeout);
  5468. /* Need a VF for word 4 set the vf bit*/
  5469. bf_set(els_req64_vf, &wqe->els_req, 0);
  5470. /* And a VFID for word 12 */
  5471. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5472. /*
  5473. * Set ct field to 3, indicates that the context_tag field
  5474. * contains the FCFI and remote N_Port_ID is
  5475. * in word 5.
  5476. */
  5477. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5478. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5479. iocbq->iocb.ulpContext);
  5480. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5481. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5482. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5483. if (command_type == ELS_COMMAND_FIP) {
  5484. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5485. >> LPFC_FIP_ELS_ID_SHIFT);
  5486. }
  5487. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5488. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5489. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5490. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5491. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5492. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5493. break;
  5494. case CMD_XMIT_SEQUENCE64_CX:
  5495. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5496. iocbq->iocb.un.ulpWord[3]);
  5497. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5498. iocbq->iocb.ulpContext);
  5499. /* The entire sequence is transmitted for this IOCB */
  5500. xmit_len = total_len;
  5501. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5502. case CMD_XMIT_SEQUENCE64_CR:
  5503. /* word3 iocb=io_tag32 wqe=reserved */
  5504. wqe->xmit_sequence.rsvd3 = 0;
  5505. /* word4 relative_offset memcpy */
  5506. /* word5 r_ctl/df_ctl memcpy */
  5507. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5508. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5509. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5510. LPFC_WQE_IOD_WRITE);
  5511. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5512. LPFC_WQE_LENLOC_WORD12);
  5513. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5514. wqe->xmit_sequence.xmit_len = xmit_len;
  5515. command_type = OTHER_COMMAND;
  5516. break;
  5517. case CMD_XMIT_BCAST64_CN:
  5518. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5519. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5520. /* word4 iocb=rsvd wqe=rsvd */
  5521. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5522. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5523. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5524. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5525. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5526. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5527. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5528. LPFC_WQE_LENLOC_WORD3);
  5529. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5530. break;
  5531. case CMD_FCP_IWRITE64_CR:
  5532. command_type = FCP_COMMAND_DATA_OUT;
  5533. /* word3 iocb=iotag wqe=payload_offset_len */
  5534. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5535. wqe->fcp_iwrite.payload_offset_len =
  5536. xmit_len + sizeof(struct fcp_rsp);
  5537. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5538. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5539. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5540. iocbq->iocb.ulpFCP2Rcvy);
  5541. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5542. /* Always open the exchange */
  5543. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5544. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5545. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5546. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5547. LPFC_WQE_LENLOC_WORD4);
  5548. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5549. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5550. break;
  5551. case CMD_FCP_IREAD64_CR:
  5552. /* word3 iocb=iotag wqe=payload_offset_len */
  5553. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5554. wqe->fcp_iread.payload_offset_len =
  5555. xmit_len + sizeof(struct fcp_rsp);
  5556. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5557. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5558. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5559. iocbq->iocb.ulpFCP2Rcvy);
  5560. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5561. /* Always open the exchange */
  5562. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5563. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5564. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5565. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5566. LPFC_WQE_LENLOC_WORD4);
  5567. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5568. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5569. break;
  5570. case CMD_FCP_ICMND64_CR:
  5571. /* word3 iocb=IO_TAG wqe=reserved */
  5572. wqe->fcp_icmd.rsrvd3 = 0;
  5573. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5574. /* Always open the exchange */
  5575. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5576. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5577. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5578. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5579. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5580. LPFC_WQE_LENLOC_NONE);
  5581. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5582. break;
  5583. case CMD_GEN_REQUEST64_CR:
  5584. /* For this command calculate the xmit length of the
  5585. * request bde.
  5586. */
  5587. xmit_len = 0;
  5588. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5589. sizeof(struct ulp_bde64);
  5590. for (i = 0; i < numBdes; i++) {
  5591. if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  5592. break;
  5593. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5594. xmit_len += bde.tus.f.bdeSize;
  5595. }
  5596. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5597. wqe->gen_req.request_payload_len = xmit_len;
  5598. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5599. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5600. /* word6 context tag copied in memcpy */
  5601. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5602. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5604. "2015 Invalid CT %x command 0x%x\n",
  5605. ct, iocbq->iocb.ulpCommand);
  5606. return IOCB_ERROR;
  5607. }
  5608. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5609. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5610. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5611. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5612. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5613. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5614. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5615. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5616. command_type = OTHER_COMMAND;
  5617. break;
  5618. case CMD_XMIT_ELS_RSP64_CX:
  5619. /* words0-2 BDE memcpy */
  5620. /* word3 iocb=iotag32 wqe=response_payload_len */
  5621. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5622. /* word4 iocb=did wge=rsvd. */
  5623. wqe->xmit_els_rsp.rsvd4 = 0;
  5624. /* word5 iocb=rsvd wge=did */
  5625. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5626. iocbq->iocb.un.elsreq64.remoteID);
  5627. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5628. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5629. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5630. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5631. iocbq->iocb.ulpContext);
  5632. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5633. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5634. iocbq->vport->vpi + phba->vpi_base);
  5635. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5636. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5637. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5638. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5639. LPFC_WQE_LENLOC_WORD3);
  5640. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5641. command_type = OTHER_COMMAND;
  5642. break;
  5643. case CMD_CLOSE_XRI_CN:
  5644. case CMD_ABORT_XRI_CN:
  5645. case CMD_ABORT_XRI_CX:
  5646. /* words 0-2 memcpy should be 0 rserved */
  5647. /* port will send abts */
  5648. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5649. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5650. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5651. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5652. } else
  5653. fip = 0;
  5654. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5655. /*
  5656. * The link is down, or the command was ELS_FIP
  5657. * so the fw does not need to send abts
  5658. * on the wire.
  5659. */
  5660. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5661. else
  5662. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5663. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5664. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  5665. wqe->abort_cmd.rsrvd5 = 0;
  5666. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  5667. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5668. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5669. /*
  5670. * The abort handler will send us CMD_ABORT_XRI_CN or
  5671. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5672. */
  5673. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  5674. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  5675. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  5676. LPFC_WQE_LENLOC_NONE);
  5677. cmnd = CMD_ABORT_XRI_CX;
  5678. command_type = OTHER_COMMAND;
  5679. xritag = 0;
  5680. break;
  5681. case CMD_XMIT_BLS_RSP64_CX:
  5682. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5683. * we re-construct this WQE here based on information in
  5684. * iocbq from scratch.
  5685. */
  5686. memset(wqe, 0, sizeof(union lpfc_wqe));
  5687. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5688. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5689. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5690. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5691. LPFC_ABTS_UNSOL_INT) {
  5692. /* ABTS sent by initiator to CT exchange, the
  5693. * RX_ID field will be filled with the newly
  5694. * allocated responder XRI.
  5695. */
  5696. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5697. iocbq->sli4_xritag);
  5698. } else {
  5699. /* ABTS sent by responder to CT exchange, the
  5700. * RX_ID field will be filled with the responder
  5701. * RX_ID from ABTS.
  5702. */
  5703. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5704. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5705. }
  5706. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5707. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5708. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5709. iocbq->iocb.ulpContext);
  5710. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  5711. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  5712. LPFC_WQE_LENLOC_NONE);
  5713. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5714. command_type = OTHER_COMMAND;
  5715. break;
  5716. case CMD_XRI_ABORTED_CX:
  5717. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5718. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5719. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5720. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5721. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5722. default:
  5723. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5724. "2014 Invalid command 0x%x\n",
  5725. iocbq->iocb.ulpCommand);
  5726. return IOCB_ERROR;
  5727. break;
  5728. }
  5729. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  5730. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  5731. wqe->generic.wqe_com.abort_tag = abort_tag;
  5732. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  5733. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  5734. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  5735. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  5736. return 0;
  5737. }
  5738. /**
  5739. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5740. * @phba: Pointer to HBA context object.
  5741. * @ring_number: SLI ring number to issue iocb on.
  5742. * @piocb: Pointer to command iocb.
  5743. * @flag: Flag indicating if this command can be put into txq.
  5744. *
  5745. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5746. * an iocb command to an HBA with SLI-4 interface spec.
  5747. *
  5748. * This function is called with hbalock held. The function will return success
  5749. * after it successfully submit the iocb to firmware or after adding to the
  5750. * txq.
  5751. **/
  5752. static int
  5753. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5754. struct lpfc_iocbq *piocb, uint32_t flag)
  5755. {
  5756. struct lpfc_sglq *sglq;
  5757. union lpfc_wqe wqe;
  5758. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5759. if (piocb->sli4_xritag == NO_XRI) {
  5760. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5761. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5762. sglq = NULL;
  5763. else {
  5764. if (pring->txq_cnt) {
  5765. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5766. __lpfc_sli_ringtx_put(phba,
  5767. pring, piocb);
  5768. return IOCB_SUCCESS;
  5769. } else {
  5770. return IOCB_BUSY;
  5771. }
  5772. } else {
  5773. sglq = __lpfc_sli_get_sglq(phba);
  5774. if (!sglq) {
  5775. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5776. __lpfc_sli_ringtx_put(phba,
  5777. pring,
  5778. piocb);
  5779. return IOCB_SUCCESS;
  5780. } else
  5781. return IOCB_BUSY;
  5782. }
  5783. }
  5784. }
  5785. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5786. sglq = NULL; /* These IO's already have an XRI and
  5787. * a mapped sgl.
  5788. */
  5789. } else {
  5790. /* This is a continuation of a commandi,(CX) so this
  5791. * sglq is on the active list
  5792. */
  5793. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5794. if (!sglq)
  5795. return IOCB_ERROR;
  5796. }
  5797. if (sglq) {
  5798. piocb->sli4_xritag = sglq->sli4_xritag;
  5799. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5800. return IOCB_ERROR;
  5801. }
  5802. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5803. return IOCB_ERROR;
  5804. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5805. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5806. /*
  5807. * For FCP command IOCB, get a new WQ index to distribute
  5808. * WQE across the WQsr. On the other hand, for abort IOCB,
  5809. * it carries the same WQ index to the original command
  5810. * IOCB.
  5811. */
  5812. if (piocb->iocb_flag & LPFC_IO_FCP)
  5813. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5814. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5815. &wqe))
  5816. return IOCB_ERROR;
  5817. } else {
  5818. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5819. return IOCB_ERROR;
  5820. }
  5821. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5822. return 0;
  5823. }
  5824. /**
  5825. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5826. *
  5827. * This routine wraps the actual lockless version for issusing IOCB function
  5828. * pointer from the lpfc_hba struct.
  5829. *
  5830. * Return codes:
  5831. * IOCB_ERROR - Error
  5832. * IOCB_SUCCESS - Success
  5833. * IOCB_BUSY - Busy
  5834. **/
  5835. int
  5836. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5837. struct lpfc_iocbq *piocb, uint32_t flag)
  5838. {
  5839. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5840. }
  5841. /**
  5842. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5843. * @phba: The hba struct for which this call is being executed.
  5844. * @dev_grp: The HBA PCI-Device group number.
  5845. *
  5846. * This routine sets up the SLI interface API function jump table in @phba
  5847. * struct.
  5848. * Returns: 0 - success, -ENODEV - failure.
  5849. **/
  5850. int
  5851. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5852. {
  5853. switch (dev_grp) {
  5854. case LPFC_PCI_DEV_LP:
  5855. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5856. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5857. break;
  5858. case LPFC_PCI_DEV_OC:
  5859. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5860. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5861. break;
  5862. default:
  5863. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5864. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5865. dev_grp);
  5866. return -ENODEV;
  5867. break;
  5868. }
  5869. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5870. return 0;
  5871. }
  5872. /**
  5873. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5874. * @phba: Pointer to HBA context object.
  5875. * @pring: Pointer to driver SLI ring object.
  5876. * @piocb: Pointer to command iocb.
  5877. * @flag: Flag indicating if this command can be put into txq.
  5878. *
  5879. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5880. * function. This function gets the hbalock and calls
  5881. * __lpfc_sli_issue_iocb function and will return the error returned
  5882. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5883. * functions which do not hold hbalock.
  5884. **/
  5885. int
  5886. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5887. struct lpfc_iocbq *piocb, uint32_t flag)
  5888. {
  5889. unsigned long iflags;
  5890. int rc;
  5891. spin_lock_irqsave(&phba->hbalock, iflags);
  5892. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5893. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5894. return rc;
  5895. }
  5896. /**
  5897. * lpfc_extra_ring_setup - Extra ring setup function
  5898. * @phba: Pointer to HBA context object.
  5899. *
  5900. * This function is called while driver attaches with the
  5901. * HBA to setup the extra ring. The extra ring is used
  5902. * only when driver needs to support target mode functionality
  5903. * or IP over FC functionalities.
  5904. *
  5905. * This function is called with no lock held.
  5906. **/
  5907. static int
  5908. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5909. {
  5910. struct lpfc_sli *psli;
  5911. struct lpfc_sli_ring *pring;
  5912. psli = &phba->sli;
  5913. /* Adjust cmd/rsp ring iocb entries more evenly */
  5914. /* Take some away from the FCP ring */
  5915. pring = &psli->ring[psli->fcp_ring];
  5916. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5917. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5918. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5919. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5920. /* and give them to the extra ring */
  5921. pring = &psli->ring[psli->extra_ring];
  5922. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5923. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5924. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5925. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5926. /* Setup default profile for this ring */
  5927. pring->iotag_max = 4096;
  5928. pring->num_mask = 1;
  5929. pring->prt[0].profile = 0; /* Mask 0 */
  5930. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5931. pring->prt[0].type = phba->cfg_multi_ring_type;
  5932. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5933. return 0;
  5934. }
  5935. /**
  5936. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5937. * @phba: Pointer to HBA context object.
  5938. * @pring: Pointer to driver SLI ring object.
  5939. * @iocbq: Pointer to iocb object.
  5940. *
  5941. * This function is called by the slow ring event handler
  5942. * function when there is an ASYNC event iocb in the ring.
  5943. * This function is called with no lock held.
  5944. * Currently this function handles only temperature related
  5945. * ASYNC events. The function decodes the temperature sensor
  5946. * event message and posts events for the management applications.
  5947. **/
  5948. static void
  5949. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5950. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5951. {
  5952. IOCB_t *icmd;
  5953. uint16_t evt_code;
  5954. uint16_t temp;
  5955. struct temp_event temp_event_data;
  5956. struct Scsi_Host *shost;
  5957. uint32_t *iocb_w;
  5958. icmd = &iocbq->iocb;
  5959. evt_code = icmd->un.asyncstat.evt_code;
  5960. temp = icmd->ulpContext;
  5961. if ((evt_code != ASYNC_TEMP_WARN) &&
  5962. (evt_code != ASYNC_TEMP_SAFE)) {
  5963. iocb_w = (uint32_t *) icmd;
  5964. lpfc_printf_log(phba,
  5965. KERN_ERR,
  5966. LOG_SLI,
  5967. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5968. " evt_code 0x%x\n"
  5969. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5970. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5971. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5972. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5973. pring->ringno,
  5974. icmd->un.asyncstat.evt_code,
  5975. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5976. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5977. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5978. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5979. return;
  5980. }
  5981. temp_event_data.data = (uint32_t)temp;
  5982. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5983. if (evt_code == ASYNC_TEMP_WARN) {
  5984. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5985. lpfc_printf_log(phba,
  5986. KERN_ERR,
  5987. LOG_TEMP,
  5988. "0347 Adapter is very hot, please take "
  5989. "corrective action. temperature : %d Celsius\n",
  5990. temp);
  5991. }
  5992. if (evt_code == ASYNC_TEMP_SAFE) {
  5993. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5994. lpfc_printf_log(phba,
  5995. KERN_ERR,
  5996. LOG_TEMP,
  5997. "0340 Adapter temperature is OK now. "
  5998. "temperature : %d Celsius\n",
  5999. temp);
  6000. }
  6001. /* Send temperature change event to applications */
  6002. shost = lpfc_shost_from_vport(phba->pport);
  6003. fc_host_post_vendor_event(shost, fc_get_event_number(),
  6004. sizeof(temp_event_data), (char *) &temp_event_data,
  6005. LPFC_NL_VENDOR_ID);
  6006. }
  6007. /**
  6008. * lpfc_sli_setup - SLI ring setup function
  6009. * @phba: Pointer to HBA context object.
  6010. *
  6011. * lpfc_sli_setup sets up rings of the SLI interface with
  6012. * number of iocbs per ring and iotags. This function is
  6013. * called while driver attach to the HBA and before the
  6014. * interrupts are enabled. So there is no need for locking.
  6015. *
  6016. * This function always returns 0.
  6017. **/
  6018. int
  6019. lpfc_sli_setup(struct lpfc_hba *phba)
  6020. {
  6021. int i, totiocbsize = 0;
  6022. struct lpfc_sli *psli = &phba->sli;
  6023. struct lpfc_sli_ring *pring;
  6024. psli->num_rings = MAX_CONFIGURED_RINGS;
  6025. psli->sli_flag = 0;
  6026. psli->fcp_ring = LPFC_FCP_RING;
  6027. psli->next_ring = LPFC_FCP_NEXT_RING;
  6028. psli->extra_ring = LPFC_EXTRA_RING;
  6029. psli->iocbq_lookup = NULL;
  6030. psli->iocbq_lookup_len = 0;
  6031. psli->last_iotag = 0;
  6032. for (i = 0; i < psli->num_rings; i++) {
  6033. pring = &psli->ring[i];
  6034. switch (i) {
  6035. case LPFC_FCP_RING: /* ring 0 - FCP */
  6036. /* numCiocb and numRiocb are used in config_port */
  6037. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6038. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6039. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6040. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6041. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6042. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6043. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6044. SLI3_IOCB_CMD_SIZE :
  6045. SLI2_IOCB_CMD_SIZE;
  6046. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6047. SLI3_IOCB_RSP_SIZE :
  6048. SLI2_IOCB_RSP_SIZE;
  6049. pring->iotag_ctr = 0;
  6050. pring->iotag_max =
  6051. (phba->cfg_hba_queue_depth * 2);
  6052. pring->fast_iotag = pring->iotag_max;
  6053. pring->num_mask = 0;
  6054. break;
  6055. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6056. /* numCiocb and numRiocb are used in config_port */
  6057. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6058. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6059. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6060. SLI3_IOCB_CMD_SIZE :
  6061. SLI2_IOCB_CMD_SIZE;
  6062. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6063. SLI3_IOCB_RSP_SIZE :
  6064. SLI2_IOCB_RSP_SIZE;
  6065. pring->iotag_max = phba->cfg_hba_queue_depth;
  6066. pring->num_mask = 0;
  6067. break;
  6068. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6069. /* numCiocb and numRiocb are used in config_port */
  6070. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6071. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6072. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6073. SLI3_IOCB_CMD_SIZE :
  6074. SLI2_IOCB_CMD_SIZE;
  6075. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6076. SLI3_IOCB_RSP_SIZE :
  6077. SLI2_IOCB_RSP_SIZE;
  6078. pring->fast_iotag = 0;
  6079. pring->iotag_ctr = 0;
  6080. pring->iotag_max = 4096;
  6081. pring->lpfc_sli_rcv_async_status =
  6082. lpfc_sli_async_event_handler;
  6083. pring->num_mask = LPFC_MAX_RING_MASK;
  6084. pring->prt[0].profile = 0; /* Mask 0 */
  6085. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6086. pring->prt[0].type = FC_TYPE_ELS;
  6087. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6088. lpfc_els_unsol_event;
  6089. pring->prt[1].profile = 0; /* Mask 1 */
  6090. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6091. pring->prt[1].type = FC_TYPE_ELS;
  6092. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6093. lpfc_els_unsol_event;
  6094. pring->prt[2].profile = 0; /* Mask 2 */
  6095. /* NameServer Inquiry */
  6096. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6097. /* NameServer */
  6098. pring->prt[2].type = FC_TYPE_CT;
  6099. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6100. lpfc_ct_unsol_event;
  6101. pring->prt[3].profile = 0; /* Mask 3 */
  6102. /* NameServer response */
  6103. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6104. /* NameServer */
  6105. pring->prt[3].type = FC_TYPE_CT;
  6106. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6107. lpfc_ct_unsol_event;
  6108. /* abort unsolicited sequence */
  6109. pring->prt[4].profile = 0; /* Mask 4 */
  6110. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6111. pring->prt[4].type = FC_TYPE_BLS;
  6112. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6113. lpfc_sli4_ct_abort_unsol_event;
  6114. break;
  6115. }
  6116. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6117. (pring->numRiocb * pring->sizeRiocb);
  6118. }
  6119. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6120. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6121. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6122. "SLI2 SLIM Data: x%x x%lx\n",
  6123. phba->brd_no, totiocbsize,
  6124. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6125. }
  6126. if (phba->cfg_multi_ring_support == 2)
  6127. lpfc_extra_ring_setup(phba);
  6128. return 0;
  6129. }
  6130. /**
  6131. * lpfc_sli_queue_setup - Queue initialization function
  6132. * @phba: Pointer to HBA context object.
  6133. *
  6134. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6135. * ring. This function also initializes ring indices of each ring.
  6136. * This function is called during the initialization of the SLI
  6137. * interface of an HBA.
  6138. * This function is called with no lock held and always returns
  6139. * 1.
  6140. **/
  6141. int
  6142. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6143. {
  6144. struct lpfc_sli *psli;
  6145. struct lpfc_sli_ring *pring;
  6146. int i;
  6147. psli = &phba->sli;
  6148. spin_lock_irq(&phba->hbalock);
  6149. INIT_LIST_HEAD(&psli->mboxq);
  6150. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6151. /* Initialize list headers for txq and txcmplq as double linked lists */
  6152. for (i = 0; i < psli->num_rings; i++) {
  6153. pring = &psli->ring[i];
  6154. pring->ringno = i;
  6155. pring->next_cmdidx = 0;
  6156. pring->local_getidx = 0;
  6157. pring->cmdidx = 0;
  6158. INIT_LIST_HEAD(&pring->txq);
  6159. INIT_LIST_HEAD(&pring->txcmplq);
  6160. INIT_LIST_HEAD(&pring->iocb_continueq);
  6161. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6162. INIT_LIST_HEAD(&pring->postbufq);
  6163. }
  6164. spin_unlock_irq(&phba->hbalock);
  6165. return 1;
  6166. }
  6167. /**
  6168. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6169. * @phba: Pointer to HBA context object.
  6170. *
  6171. * This routine flushes the mailbox command subsystem. It will unconditionally
  6172. * flush all the mailbox commands in the three possible stages in the mailbox
  6173. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6174. * command; and completed mailbox command queue. It is caller's responsibility
  6175. * to make sure that the driver is in the proper state to flush the mailbox
  6176. * command sub-system. Namely, the posting of mailbox commands into the
  6177. * pending mailbox command queue from the various clients must be stopped;
  6178. * either the HBA is in a state that it will never works on the outstanding
  6179. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6180. * mailbox command has been completed.
  6181. **/
  6182. static void
  6183. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6184. {
  6185. LIST_HEAD(completions);
  6186. struct lpfc_sli *psli = &phba->sli;
  6187. LPFC_MBOXQ_t *pmb;
  6188. unsigned long iflag;
  6189. /* Flush all the mailbox commands in the mbox system */
  6190. spin_lock_irqsave(&phba->hbalock, iflag);
  6191. /* The pending mailbox command queue */
  6192. list_splice_init(&phba->sli.mboxq, &completions);
  6193. /* The outstanding active mailbox command */
  6194. if (psli->mbox_active) {
  6195. list_add_tail(&psli->mbox_active->list, &completions);
  6196. psli->mbox_active = NULL;
  6197. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6198. }
  6199. /* The completed mailbox command queue */
  6200. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6201. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6202. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6203. while (!list_empty(&completions)) {
  6204. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6205. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6206. if (pmb->mbox_cmpl)
  6207. pmb->mbox_cmpl(phba, pmb);
  6208. }
  6209. }
  6210. /**
  6211. * lpfc_sli_host_down - Vport cleanup function
  6212. * @vport: Pointer to virtual port object.
  6213. *
  6214. * lpfc_sli_host_down is called to clean up the resources
  6215. * associated with a vport before destroying virtual
  6216. * port data structures.
  6217. * This function does following operations:
  6218. * - Free discovery resources associated with this virtual
  6219. * port.
  6220. * - Free iocbs associated with this virtual port in
  6221. * the txq.
  6222. * - Send abort for all iocb commands associated with this
  6223. * vport in txcmplq.
  6224. *
  6225. * This function is called with no lock held and always returns 1.
  6226. **/
  6227. int
  6228. lpfc_sli_host_down(struct lpfc_vport *vport)
  6229. {
  6230. LIST_HEAD(completions);
  6231. struct lpfc_hba *phba = vport->phba;
  6232. struct lpfc_sli *psli = &phba->sli;
  6233. struct lpfc_sli_ring *pring;
  6234. struct lpfc_iocbq *iocb, *next_iocb;
  6235. int i;
  6236. unsigned long flags = 0;
  6237. uint16_t prev_pring_flag;
  6238. lpfc_cleanup_discovery_resources(vport);
  6239. spin_lock_irqsave(&phba->hbalock, flags);
  6240. for (i = 0; i < psli->num_rings; i++) {
  6241. pring = &psli->ring[i];
  6242. prev_pring_flag = pring->flag;
  6243. /* Only slow rings */
  6244. if (pring->ringno == LPFC_ELS_RING) {
  6245. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6246. /* Set the lpfc data pending flag */
  6247. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6248. }
  6249. /*
  6250. * Error everything on the txq since these iocbs have not been
  6251. * given to the FW yet.
  6252. */
  6253. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6254. if (iocb->vport != vport)
  6255. continue;
  6256. list_move_tail(&iocb->list, &completions);
  6257. pring->txq_cnt--;
  6258. }
  6259. /* Next issue ABTS for everything on the txcmplq */
  6260. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6261. list) {
  6262. if (iocb->vport != vport)
  6263. continue;
  6264. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6265. }
  6266. pring->flag = prev_pring_flag;
  6267. }
  6268. spin_unlock_irqrestore(&phba->hbalock, flags);
  6269. /* Cancel all the IOCBs from the completions list */
  6270. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6271. IOERR_SLI_DOWN);
  6272. return 1;
  6273. }
  6274. /**
  6275. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6276. * @phba: Pointer to HBA context object.
  6277. *
  6278. * This function cleans up all iocb, buffers, mailbox commands
  6279. * while shutting down the HBA. This function is called with no
  6280. * lock held and always returns 1.
  6281. * This function does the following to cleanup driver resources:
  6282. * - Free discovery resources for each virtual port
  6283. * - Cleanup any pending fabric iocbs
  6284. * - Iterate through the iocb txq and free each entry
  6285. * in the list.
  6286. * - Free up any buffer posted to the HBA
  6287. * - Free mailbox commands in the mailbox queue.
  6288. **/
  6289. int
  6290. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6291. {
  6292. LIST_HEAD(completions);
  6293. struct lpfc_sli *psli = &phba->sli;
  6294. struct lpfc_sli_ring *pring;
  6295. struct lpfc_dmabuf *buf_ptr;
  6296. unsigned long flags = 0;
  6297. int i;
  6298. /* Shutdown the mailbox command sub-system */
  6299. lpfc_sli_mbox_sys_shutdown(phba);
  6300. lpfc_hba_down_prep(phba);
  6301. lpfc_fabric_abort_hba(phba);
  6302. spin_lock_irqsave(&phba->hbalock, flags);
  6303. for (i = 0; i < psli->num_rings; i++) {
  6304. pring = &psli->ring[i];
  6305. /* Only slow rings */
  6306. if (pring->ringno == LPFC_ELS_RING) {
  6307. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6308. /* Set the lpfc data pending flag */
  6309. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6310. }
  6311. /*
  6312. * Error everything on the txq since these iocbs have not been
  6313. * given to the FW yet.
  6314. */
  6315. list_splice_init(&pring->txq, &completions);
  6316. pring->txq_cnt = 0;
  6317. }
  6318. spin_unlock_irqrestore(&phba->hbalock, flags);
  6319. /* Cancel all the IOCBs from the completions list */
  6320. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6321. IOERR_SLI_DOWN);
  6322. spin_lock_irqsave(&phba->hbalock, flags);
  6323. list_splice_init(&phba->elsbuf, &completions);
  6324. phba->elsbuf_cnt = 0;
  6325. phba->elsbuf_prev_cnt = 0;
  6326. spin_unlock_irqrestore(&phba->hbalock, flags);
  6327. while (!list_empty(&completions)) {
  6328. list_remove_head(&completions, buf_ptr,
  6329. struct lpfc_dmabuf, list);
  6330. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6331. kfree(buf_ptr);
  6332. }
  6333. /* Return any active mbox cmds */
  6334. del_timer_sync(&psli->mbox_tmo);
  6335. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6336. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6337. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6338. return 1;
  6339. }
  6340. /**
  6341. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6342. * @srcp: Source memory pointer.
  6343. * @destp: Destination memory pointer.
  6344. * @cnt: Number of words required to be copied.
  6345. *
  6346. * This function is used for copying data between driver memory
  6347. * and the SLI memory. This function also changes the endianness
  6348. * of each word if native endianness is different from SLI
  6349. * endianness. This function can be called with or without
  6350. * lock.
  6351. **/
  6352. void
  6353. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6354. {
  6355. uint32_t *src = srcp;
  6356. uint32_t *dest = destp;
  6357. uint32_t ldata;
  6358. int i;
  6359. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6360. ldata = *src;
  6361. ldata = le32_to_cpu(ldata);
  6362. *dest = ldata;
  6363. src++;
  6364. dest++;
  6365. }
  6366. }
  6367. /**
  6368. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6369. * @srcp: Source memory pointer.
  6370. * @destp: Destination memory pointer.
  6371. * @cnt: Number of words required to be copied.
  6372. *
  6373. * This function is used for copying data between a data structure
  6374. * with big endian representation to local endianness.
  6375. * This function can be called with or without lock.
  6376. **/
  6377. void
  6378. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6379. {
  6380. uint32_t *src = srcp;
  6381. uint32_t *dest = destp;
  6382. uint32_t ldata;
  6383. int i;
  6384. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6385. ldata = *src;
  6386. ldata = be32_to_cpu(ldata);
  6387. *dest = ldata;
  6388. src++;
  6389. dest++;
  6390. }
  6391. }
  6392. /**
  6393. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6394. * @phba: Pointer to HBA context object.
  6395. * @pring: Pointer to driver SLI ring object.
  6396. * @mp: Pointer to driver buffer object.
  6397. *
  6398. * This function is called with no lock held.
  6399. * It always return zero after adding the buffer to the postbufq
  6400. * buffer list.
  6401. **/
  6402. int
  6403. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6404. struct lpfc_dmabuf *mp)
  6405. {
  6406. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6407. later */
  6408. spin_lock_irq(&phba->hbalock);
  6409. list_add_tail(&mp->list, &pring->postbufq);
  6410. pring->postbufq_cnt++;
  6411. spin_unlock_irq(&phba->hbalock);
  6412. return 0;
  6413. }
  6414. /**
  6415. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6416. * @phba: Pointer to HBA context object.
  6417. *
  6418. * When HBQ is enabled, buffers are searched based on tags. This function
  6419. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6420. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6421. * does not conflict with tags of buffer posted for unsolicited events.
  6422. * The function returns the allocated tag. The function is called with
  6423. * no locks held.
  6424. **/
  6425. uint32_t
  6426. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6427. {
  6428. spin_lock_irq(&phba->hbalock);
  6429. phba->buffer_tag_count++;
  6430. /*
  6431. * Always set the QUE_BUFTAG_BIT to distiguish between
  6432. * a tag assigned by HBQ.
  6433. */
  6434. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6435. spin_unlock_irq(&phba->hbalock);
  6436. return phba->buffer_tag_count;
  6437. }
  6438. /**
  6439. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6440. * @phba: Pointer to HBA context object.
  6441. * @pring: Pointer to driver SLI ring object.
  6442. * @tag: Buffer tag.
  6443. *
  6444. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6445. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6446. * iocb is posted to the response ring with the tag of the buffer.
  6447. * This function searches the pring->postbufq list using the tag
  6448. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6449. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6450. * buffer is returned to the caller else NULL is returned.
  6451. * This function is called with no lock held.
  6452. **/
  6453. struct lpfc_dmabuf *
  6454. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6455. uint32_t tag)
  6456. {
  6457. struct lpfc_dmabuf *mp, *next_mp;
  6458. struct list_head *slp = &pring->postbufq;
  6459. /* Search postbufq, from the begining, looking for a match on tag */
  6460. spin_lock_irq(&phba->hbalock);
  6461. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6462. if (mp->buffer_tag == tag) {
  6463. list_del_init(&mp->list);
  6464. pring->postbufq_cnt--;
  6465. spin_unlock_irq(&phba->hbalock);
  6466. return mp;
  6467. }
  6468. }
  6469. spin_unlock_irq(&phba->hbalock);
  6470. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6471. "0402 Cannot find virtual addr for buffer tag on "
  6472. "ring %d Data x%lx x%p x%p x%x\n",
  6473. pring->ringno, (unsigned long) tag,
  6474. slp->next, slp->prev, pring->postbufq_cnt);
  6475. return NULL;
  6476. }
  6477. /**
  6478. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6479. * @phba: Pointer to HBA context object.
  6480. * @pring: Pointer to driver SLI ring object.
  6481. * @phys: DMA address of the buffer.
  6482. *
  6483. * This function searches the buffer list using the dma_address
  6484. * of unsolicited event to find the driver's lpfc_dmabuf object
  6485. * corresponding to the dma_address. The function returns the
  6486. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6487. * This function is called by the ct and els unsolicited event
  6488. * handlers to get the buffer associated with the unsolicited
  6489. * event.
  6490. *
  6491. * This function is called with no lock held.
  6492. **/
  6493. struct lpfc_dmabuf *
  6494. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6495. dma_addr_t phys)
  6496. {
  6497. struct lpfc_dmabuf *mp, *next_mp;
  6498. struct list_head *slp = &pring->postbufq;
  6499. /* Search postbufq, from the begining, looking for a match on phys */
  6500. spin_lock_irq(&phba->hbalock);
  6501. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6502. if (mp->phys == phys) {
  6503. list_del_init(&mp->list);
  6504. pring->postbufq_cnt--;
  6505. spin_unlock_irq(&phba->hbalock);
  6506. return mp;
  6507. }
  6508. }
  6509. spin_unlock_irq(&phba->hbalock);
  6510. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6511. "0410 Cannot find virtual addr for mapped buf on "
  6512. "ring %d Data x%llx x%p x%p x%x\n",
  6513. pring->ringno, (unsigned long long)phys,
  6514. slp->next, slp->prev, pring->postbufq_cnt);
  6515. return NULL;
  6516. }
  6517. /**
  6518. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6519. * @phba: Pointer to HBA context object.
  6520. * @cmdiocb: Pointer to driver command iocb object.
  6521. * @rspiocb: Pointer to driver response iocb object.
  6522. *
  6523. * This function is the completion handler for the abort iocbs for
  6524. * ELS commands. This function is called from the ELS ring event
  6525. * handler with no lock held. This function frees memory resources
  6526. * associated with the abort iocb.
  6527. **/
  6528. static void
  6529. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6530. struct lpfc_iocbq *rspiocb)
  6531. {
  6532. IOCB_t *irsp = &rspiocb->iocb;
  6533. uint16_t abort_iotag, abort_context;
  6534. struct lpfc_iocbq *abort_iocb;
  6535. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6536. abort_iocb = NULL;
  6537. if (irsp->ulpStatus) {
  6538. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6539. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6540. spin_lock_irq(&phba->hbalock);
  6541. if (phba->sli_rev < LPFC_SLI_REV4) {
  6542. if (abort_iotag != 0 &&
  6543. abort_iotag <= phba->sli.last_iotag)
  6544. abort_iocb =
  6545. phba->sli.iocbq_lookup[abort_iotag];
  6546. } else
  6547. /* For sli4 the abort_tag is the XRI,
  6548. * so the abort routine puts the iotag of the iocb
  6549. * being aborted in the context field of the abort
  6550. * IOCB.
  6551. */
  6552. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6553. /*
  6554. * If the iocb is not found in Firmware queue the iocb
  6555. * might have completed already. Do not free it again.
  6556. */
  6557. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6558. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6559. spin_unlock_irq(&phba->hbalock);
  6560. lpfc_sli_release_iocbq(phba, cmdiocb);
  6561. return;
  6562. }
  6563. /* For SLI4 the ulpContext field for abort IOCB
  6564. * holds the iotag of the IOCB being aborted so
  6565. * the local abort_context needs to be reset to
  6566. * match the aborted IOCBs ulpContext.
  6567. */
  6568. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6569. abort_context = abort_iocb->iocb.ulpContext;
  6570. }
  6571. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6572. "0327 Cannot abort els iocb %p "
  6573. "with tag %x context %x, abort status %x, "
  6574. "abort code %x\n",
  6575. abort_iocb, abort_iotag, abort_context,
  6576. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6577. /*
  6578. * make sure we have the right iocbq before taking it
  6579. * off the txcmplq and try to call completion routine.
  6580. */
  6581. if (!abort_iocb ||
  6582. abort_iocb->iocb.ulpContext != abort_context ||
  6583. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6584. spin_unlock_irq(&phba->hbalock);
  6585. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6586. /*
  6587. * leave the SLI4 aborted command on the txcmplq
  6588. * list and the command complete WCQE's XB bit
  6589. * will tell whether the SGL (XRI) can be released
  6590. * immediately or to the aborted SGL list for the
  6591. * following abort XRI from the HBA.
  6592. */
  6593. list_del_init(&abort_iocb->list);
  6594. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6595. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6596. pring->txcmplq_cnt--;
  6597. }
  6598. /* Firmware could still be in progress of DMAing
  6599. * payload, so don't free data buffer till after
  6600. * a hbeat.
  6601. */
  6602. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6603. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6604. spin_unlock_irq(&phba->hbalock);
  6605. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6606. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6607. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6608. } else
  6609. spin_unlock_irq(&phba->hbalock);
  6610. }
  6611. lpfc_sli_release_iocbq(phba, cmdiocb);
  6612. return;
  6613. }
  6614. /**
  6615. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6616. * @phba: Pointer to HBA context object.
  6617. * @cmdiocb: Pointer to driver command iocb object.
  6618. * @rspiocb: Pointer to driver response iocb object.
  6619. *
  6620. * The function is called from SLI ring event handler with no
  6621. * lock held. This function is the completion handler for ELS commands
  6622. * which are aborted. The function frees memory resources used for
  6623. * the aborted ELS commands.
  6624. **/
  6625. static void
  6626. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6627. struct lpfc_iocbq *rspiocb)
  6628. {
  6629. IOCB_t *irsp = &rspiocb->iocb;
  6630. /* ELS cmd tag <ulpIoTag> completes */
  6631. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6632. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6633. "x%x x%x x%x\n",
  6634. irsp->ulpIoTag, irsp->ulpStatus,
  6635. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6636. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6637. lpfc_ct_free_iocb(phba, cmdiocb);
  6638. else
  6639. lpfc_els_free_iocb(phba, cmdiocb);
  6640. return;
  6641. }
  6642. /**
  6643. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6644. * @phba: Pointer to HBA context object.
  6645. * @pring: Pointer to driver SLI ring object.
  6646. * @cmdiocb: Pointer to driver command iocb object.
  6647. *
  6648. * This function issues an abort iocb for the provided command iocb down to
  6649. * the port. Other than the case the outstanding command iocb is an abort
  6650. * request, this function issues abort out unconditionally. This function is
  6651. * called with hbalock held. The function returns 0 when it fails due to
  6652. * memory allocation failure or when the command iocb is an abort request.
  6653. **/
  6654. static int
  6655. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6656. struct lpfc_iocbq *cmdiocb)
  6657. {
  6658. struct lpfc_vport *vport = cmdiocb->vport;
  6659. struct lpfc_iocbq *abtsiocbp;
  6660. IOCB_t *icmd = NULL;
  6661. IOCB_t *iabt = NULL;
  6662. int retval;
  6663. /*
  6664. * There are certain command types we don't want to abort. And we
  6665. * don't want to abort commands that are already in the process of
  6666. * being aborted.
  6667. */
  6668. icmd = &cmdiocb->iocb;
  6669. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6670. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6671. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6672. return 0;
  6673. /* issue ABTS for this IOCB based on iotag */
  6674. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6675. if (abtsiocbp == NULL)
  6676. return 0;
  6677. /* This signals the response to set the correct status
  6678. * before calling the completion handler
  6679. */
  6680. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6681. iabt = &abtsiocbp->iocb;
  6682. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6683. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6684. if (phba->sli_rev == LPFC_SLI_REV4) {
  6685. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6686. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6687. }
  6688. else
  6689. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6690. iabt->ulpLe = 1;
  6691. iabt->ulpClass = icmd->ulpClass;
  6692. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6693. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6694. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6695. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6696. if (phba->link_state >= LPFC_LINK_UP)
  6697. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6698. else
  6699. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6700. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6701. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6702. "0339 Abort xri x%x, original iotag x%x, "
  6703. "abort cmd iotag x%x\n",
  6704. iabt->un.acxri.abortIoTag,
  6705. iabt->un.acxri.abortContextTag,
  6706. abtsiocbp->iotag);
  6707. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6708. if (retval)
  6709. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6710. /*
  6711. * Caller to this routine should check for IOCB_ERROR
  6712. * and handle it properly. This routine no longer removes
  6713. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6714. */
  6715. return retval;
  6716. }
  6717. /**
  6718. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6719. * @phba: Pointer to HBA context object.
  6720. * @pring: Pointer to driver SLI ring object.
  6721. * @cmdiocb: Pointer to driver command iocb object.
  6722. *
  6723. * This function issues an abort iocb for the provided command iocb. In case
  6724. * of unloading, the abort iocb will not be issued to commands on the ELS
  6725. * ring. Instead, the callback function shall be changed to those commands
  6726. * so that nothing happens when them finishes. This function is called with
  6727. * hbalock held. The function returns 0 when the command iocb is an abort
  6728. * request.
  6729. **/
  6730. int
  6731. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6732. struct lpfc_iocbq *cmdiocb)
  6733. {
  6734. struct lpfc_vport *vport = cmdiocb->vport;
  6735. int retval = IOCB_ERROR;
  6736. IOCB_t *icmd = NULL;
  6737. /*
  6738. * There are certain command types we don't want to abort. And we
  6739. * don't want to abort commands that are already in the process of
  6740. * being aborted.
  6741. */
  6742. icmd = &cmdiocb->iocb;
  6743. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6744. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6745. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6746. return 0;
  6747. /*
  6748. * If we're unloading, don't abort iocb on the ELS ring, but change
  6749. * the callback so that nothing happens when it finishes.
  6750. */
  6751. if ((vport->load_flag & FC_UNLOADING) &&
  6752. (pring->ringno == LPFC_ELS_RING)) {
  6753. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6754. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6755. else
  6756. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6757. goto abort_iotag_exit;
  6758. }
  6759. /* Now, we try to issue the abort to the cmdiocb out */
  6760. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  6761. abort_iotag_exit:
  6762. /*
  6763. * Caller to this routine should check for IOCB_ERROR
  6764. * and handle it properly. This routine no longer removes
  6765. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6766. */
  6767. return retval;
  6768. }
  6769. /**
  6770. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  6771. * @phba: Pointer to HBA context object.
  6772. * @pring: Pointer to driver SLI ring object.
  6773. *
  6774. * This function aborts all iocbs in the given ring and frees all the iocb
  6775. * objects in txq. This function issues abort iocbs unconditionally for all
  6776. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  6777. * to complete before the return of this function. The caller is not required
  6778. * to hold any locks.
  6779. **/
  6780. static void
  6781. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  6782. {
  6783. LIST_HEAD(completions);
  6784. struct lpfc_iocbq *iocb, *next_iocb;
  6785. if (pring->ringno == LPFC_ELS_RING)
  6786. lpfc_fabric_abort_hba(phba);
  6787. spin_lock_irq(&phba->hbalock);
  6788. /* Take off all the iocbs on txq for cancelling */
  6789. list_splice_init(&pring->txq, &completions);
  6790. pring->txq_cnt = 0;
  6791. /* Next issue ABTS for everything on the txcmplq */
  6792. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  6793. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  6794. spin_unlock_irq(&phba->hbalock);
  6795. /* Cancel all the IOCBs from the completions list */
  6796. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6797. IOERR_SLI_ABORTED);
  6798. }
  6799. /**
  6800. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  6801. * @phba: pointer to lpfc HBA data structure.
  6802. *
  6803. * This routine will abort all pending and outstanding iocbs to an HBA.
  6804. **/
  6805. void
  6806. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  6807. {
  6808. struct lpfc_sli *psli = &phba->sli;
  6809. struct lpfc_sli_ring *pring;
  6810. int i;
  6811. for (i = 0; i < psli->num_rings; i++) {
  6812. pring = &psli->ring[i];
  6813. lpfc_sli_iocb_ring_abort(phba, pring);
  6814. }
  6815. }
  6816. /**
  6817. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6818. * @iocbq: Pointer to driver iocb object.
  6819. * @vport: Pointer to driver virtual port object.
  6820. * @tgt_id: SCSI ID of the target.
  6821. * @lun_id: LUN ID of the scsi device.
  6822. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6823. *
  6824. * This function acts as an iocb filter for functions which abort or count
  6825. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6826. * 0 if the filtering criteria is met for the given iocb and will return
  6827. * 1 if the filtering criteria is not met.
  6828. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6829. * given iocb is for the SCSI device specified by vport, tgt_id and
  6830. * lun_id parameter.
  6831. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6832. * given iocb is for the SCSI target specified by vport and tgt_id
  6833. * parameters.
  6834. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6835. * given iocb is for the SCSI host associated with the given vport.
  6836. * This function is called with no locks held.
  6837. **/
  6838. static int
  6839. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6840. uint16_t tgt_id, uint64_t lun_id,
  6841. lpfc_ctx_cmd ctx_cmd)
  6842. {
  6843. struct lpfc_scsi_buf *lpfc_cmd;
  6844. int rc = 1;
  6845. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6846. return rc;
  6847. if (iocbq->vport != vport)
  6848. return rc;
  6849. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6850. if (lpfc_cmd->pCmd == NULL)
  6851. return rc;
  6852. switch (ctx_cmd) {
  6853. case LPFC_CTX_LUN:
  6854. if ((lpfc_cmd->rdata->pnode) &&
  6855. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6856. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6857. rc = 0;
  6858. break;
  6859. case LPFC_CTX_TGT:
  6860. if ((lpfc_cmd->rdata->pnode) &&
  6861. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6862. rc = 0;
  6863. break;
  6864. case LPFC_CTX_HOST:
  6865. rc = 0;
  6866. break;
  6867. default:
  6868. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6869. __func__, ctx_cmd);
  6870. break;
  6871. }
  6872. return rc;
  6873. }
  6874. /**
  6875. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6876. * @vport: Pointer to virtual port.
  6877. * @tgt_id: SCSI ID of the target.
  6878. * @lun_id: LUN ID of the scsi device.
  6879. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6880. *
  6881. * This function returns number of FCP commands pending for the vport.
  6882. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6883. * commands pending on the vport associated with SCSI device specified
  6884. * by tgt_id and lun_id parameters.
  6885. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6886. * commands pending on the vport associated with SCSI target specified
  6887. * by tgt_id parameter.
  6888. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6889. * commands pending on the vport.
  6890. * This function returns the number of iocbs which satisfy the filter.
  6891. * This function is called without any lock held.
  6892. **/
  6893. int
  6894. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6895. lpfc_ctx_cmd ctx_cmd)
  6896. {
  6897. struct lpfc_hba *phba = vport->phba;
  6898. struct lpfc_iocbq *iocbq;
  6899. int sum, i;
  6900. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6901. iocbq = phba->sli.iocbq_lookup[i];
  6902. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6903. ctx_cmd) == 0)
  6904. sum++;
  6905. }
  6906. return sum;
  6907. }
  6908. /**
  6909. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6910. * @phba: Pointer to HBA context object
  6911. * @cmdiocb: Pointer to command iocb object.
  6912. * @rspiocb: Pointer to response iocb object.
  6913. *
  6914. * This function is called when an aborted FCP iocb completes. This
  6915. * function is called by the ring event handler with no lock held.
  6916. * This function frees the iocb.
  6917. **/
  6918. void
  6919. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6920. struct lpfc_iocbq *rspiocb)
  6921. {
  6922. lpfc_sli_release_iocbq(phba, cmdiocb);
  6923. return;
  6924. }
  6925. /**
  6926. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6927. * @vport: Pointer to virtual port.
  6928. * @pring: Pointer to driver SLI ring object.
  6929. * @tgt_id: SCSI ID of the target.
  6930. * @lun_id: LUN ID of the scsi device.
  6931. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6932. *
  6933. * This function sends an abort command for every SCSI command
  6934. * associated with the given virtual port pending on the ring
  6935. * filtered by lpfc_sli_validate_fcp_iocb function.
  6936. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6937. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6938. * parameters
  6939. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6940. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6941. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6942. * FCP iocbs associated with virtual port.
  6943. * This function returns number of iocbs it failed to abort.
  6944. * This function is called with no locks held.
  6945. **/
  6946. int
  6947. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6948. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6949. {
  6950. struct lpfc_hba *phba = vport->phba;
  6951. struct lpfc_iocbq *iocbq;
  6952. struct lpfc_iocbq *abtsiocb;
  6953. IOCB_t *cmd = NULL;
  6954. int errcnt = 0, ret_val = 0;
  6955. int i;
  6956. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6957. iocbq = phba->sli.iocbq_lookup[i];
  6958. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6959. abort_cmd) != 0)
  6960. continue;
  6961. /* issue ABTS for this IOCB based on iotag */
  6962. abtsiocb = lpfc_sli_get_iocbq(phba);
  6963. if (abtsiocb == NULL) {
  6964. errcnt++;
  6965. continue;
  6966. }
  6967. cmd = &iocbq->iocb;
  6968. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6969. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6970. if (phba->sli_rev == LPFC_SLI_REV4)
  6971. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6972. else
  6973. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6974. abtsiocb->iocb.ulpLe = 1;
  6975. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6976. abtsiocb->vport = phba->pport;
  6977. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6978. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6979. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6980. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6981. if (lpfc_is_link_up(phba))
  6982. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6983. else
  6984. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6985. /* Setup callback routine and issue the command. */
  6986. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6987. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6988. abtsiocb, 0);
  6989. if (ret_val == IOCB_ERROR) {
  6990. lpfc_sli_release_iocbq(phba, abtsiocb);
  6991. errcnt++;
  6992. continue;
  6993. }
  6994. }
  6995. return errcnt;
  6996. }
  6997. /**
  6998. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6999. * @phba: Pointer to HBA context object.
  7000. * @cmdiocbq: Pointer to command iocb.
  7001. * @rspiocbq: Pointer to response iocb.
  7002. *
  7003. * This function is the completion handler for iocbs issued using
  7004. * lpfc_sli_issue_iocb_wait function. This function is called by the
  7005. * ring event handler function without any lock held. This function
  7006. * can be called from both worker thread context and interrupt
  7007. * context. This function also can be called from other thread which
  7008. * cleans up the SLI layer objects.
  7009. * This function copy the contents of the response iocb to the
  7010. * response iocb memory object provided by the caller of
  7011. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  7012. * sleeps for the iocb completion.
  7013. **/
  7014. static void
  7015. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  7016. struct lpfc_iocbq *cmdiocbq,
  7017. struct lpfc_iocbq *rspiocbq)
  7018. {
  7019. wait_queue_head_t *pdone_q;
  7020. unsigned long iflags;
  7021. struct lpfc_scsi_buf *lpfc_cmd;
  7022. spin_lock_irqsave(&phba->hbalock, iflags);
  7023. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  7024. if (cmdiocbq->context2 && rspiocbq)
  7025. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  7026. &rspiocbq->iocb, sizeof(IOCB_t));
  7027. /* Set the exchange busy flag for task management commands */
  7028. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  7029. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  7030. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  7031. cur_iocbq);
  7032. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  7033. }
  7034. pdone_q = cmdiocbq->context_un.wait_queue;
  7035. if (pdone_q)
  7036. wake_up(pdone_q);
  7037. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7038. return;
  7039. }
  7040. /**
  7041. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7042. * @phba: Pointer to HBA context object..
  7043. * @piocbq: Pointer to command iocb.
  7044. * @flag: Flag to test.
  7045. *
  7046. * This routine grabs the hbalock and then test the iocb_flag to
  7047. * see if the passed in flag is set.
  7048. * Returns:
  7049. * 1 if flag is set.
  7050. * 0 if flag is not set.
  7051. **/
  7052. static int
  7053. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7054. struct lpfc_iocbq *piocbq, uint32_t flag)
  7055. {
  7056. unsigned long iflags;
  7057. int ret;
  7058. spin_lock_irqsave(&phba->hbalock, iflags);
  7059. ret = piocbq->iocb_flag & flag;
  7060. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7061. return ret;
  7062. }
  7063. /**
  7064. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7065. * @phba: Pointer to HBA context object..
  7066. * @pring: Pointer to sli ring.
  7067. * @piocb: Pointer to command iocb.
  7068. * @prspiocbq: Pointer to response iocb.
  7069. * @timeout: Timeout in number of seconds.
  7070. *
  7071. * This function issues the iocb to firmware and waits for the
  7072. * iocb to complete. If the iocb command is not
  7073. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7074. * Caller should not free the iocb resources if this function
  7075. * returns IOCB_TIMEDOUT.
  7076. * The function waits for the iocb completion using an
  7077. * non-interruptible wait.
  7078. * This function will sleep while waiting for iocb completion.
  7079. * So, this function should not be called from any context which
  7080. * does not allow sleeping. Due to the same reason, this function
  7081. * cannot be called with interrupt disabled.
  7082. * This function assumes that the iocb completions occur while
  7083. * this function sleep. So, this function cannot be called from
  7084. * the thread which process iocb completion for this ring.
  7085. * This function clears the iocb_flag of the iocb object before
  7086. * issuing the iocb and the iocb completion handler sets this
  7087. * flag and wakes this thread when the iocb completes.
  7088. * The contents of the response iocb will be copied to prspiocbq
  7089. * by the completion handler when the command completes.
  7090. * This function returns IOCB_SUCCESS when success.
  7091. * This function is called with no lock held.
  7092. **/
  7093. int
  7094. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7095. uint32_t ring_number,
  7096. struct lpfc_iocbq *piocb,
  7097. struct lpfc_iocbq *prspiocbq,
  7098. uint32_t timeout)
  7099. {
  7100. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7101. long timeleft, timeout_req = 0;
  7102. int retval = IOCB_SUCCESS;
  7103. uint32_t creg_val;
  7104. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7105. /*
  7106. * If the caller has provided a response iocbq buffer, then context2
  7107. * is NULL or its an error.
  7108. */
  7109. if (prspiocbq) {
  7110. if (piocb->context2)
  7111. return IOCB_ERROR;
  7112. piocb->context2 = prspiocbq;
  7113. }
  7114. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7115. piocb->context_un.wait_queue = &done_q;
  7116. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7117. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7118. creg_val = readl(phba->HCregaddr);
  7119. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7120. writel(creg_val, phba->HCregaddr);
  7121. readl(phba->HCregaddr); /* flush */
  7122. }
  7123. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7124. SLI_IOCB_RET_IOCB);
  7125. if (retval == IOCB_SUCCESS) {
  7126. timeout_req = timeout * HZ;
  7127. timeleft = wait_event_timeout(done_q,
  7128. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7129. timeout_req);
  7130. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7131. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7132. "0331 IOCB wake signaled\n");
  7133. } else if (timeleft == 0) {
  7134. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7135. "0338 IOCB wait timeout error - no "
  7136. "wake response Data x%x\n", timeout);
  7137. retval = IOCB_TIMEDOUT;
  7138. } else {
  7139. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7140. "0330 IOCB wake NOT set, "
  7141. "Data x%x x%lx\n",
  7142. timeout, (timeleft / jiffies));
  7143. retval = IOCB_TIMEDOUT;
  7144. }
  7145. } else if (retval == IOCB_BUSY) {
  7146. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7147. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7148. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7149. return retval;
  7150. } else {
  7151. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7152. "0332 IOCB wait issue failed, Data x%x\n",
  7153. retval);
  7154. retval = IOCB_ERROR;
  7155. }
  7156. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7157. creg_val = readl(phba->HCregaddr);
  7158. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7159. writel(creg_val, phba->HCregaddr);
  7160. readl(phba->HCregaddr); /* flush */
  7161. }
  7162. if (prspiocbq)
  7163. piocb->context2 = NULL;
  7164. piocb->context_un.wait_queue = NULL;
  7165. piocb->iocb_cmpl = NULL;
  7166. return retval;
  7167. }
  7168. /**
  7169. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7170. * @phba: Pointer to HBA context object.
  7171. * @pmboxq: Pointer to driver mailbox object.
  7172. * @timeout: Timeout in number of seconds.
  7173. *
  7174. * This function issues the mailbox to firmware and waits for the
  7175. * mailbox command to complete. If the mailbox command is not
  7176. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7177. * The function waits for the mailbox completion using an
  7178. * interruptible wait. If the thread is woken up due to a
  7179. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7180. * should not free the mailbox resources, if this function returns
  7181. * MBX_TIMEOUT.
  7182. * This function will sleep while waiting for mailbox completion.
  7183. * So, this function should not be called from any context which
  7184. * does not allow sleeping. Due to the same reason, this function
  7185. * cannot be called with interrupt disabled.
  7186. * This function assumes that the mailbox completion occurs while
  7187. * this function sleep. So, this function cannot be called from
  7188. * the worker thread which processes mailbox completion.
  7189. * This function is called in the context of HBA management
  7190. * applications.
  7191. * This function returns MBX_SUCCESS when successful.
  7192. * This function is called with no lock held.
  7193. **/
  7194. int
  7195. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7196. uint32_t timeout)
  7197. {
  7198. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7199. int retval;
  7200. unsigned long flag;
  7201. /* The caller must leave context1 empty. */
  7202. if (pmboxq->context1)
  7203. return MBX_NOT_FINISHED;
  7204. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7205. /* setup wake call as IOCB callback */
  7206. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7207. /* setup context field to pass wait_queue pointer to wake function */
  7208. pmboxq->context1 = &done_q;
  7209. /* now issue the command */
  7210. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7211. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7212. wait_event_interruptible_timeout(done_q,
  7213. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7214. timeout * HZ);
  7215. spin_lock_irqsave(&phba->hbalock, flag);
  7216. pmboxq->context1 = NULL;
  7217. /*
  7218. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7219. * else do not free the resources.
  7220. */
  7221. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7222. retval = MBX_SUCCESS;
  7223. lpfc_sli4_swap_str(phba, pmboxq);
  7224. } else {
  7225. retval = MBX_TIMEOUT;
  7226. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7227. }
  7228. spin_unlock_irqrestore(&phba->hbalock, flag);
  7229. }
  7230. return retval;
  7231. }
  7232. /**
  7233. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7234. * @phba: Pointer to HBA context.
  7235. *
  7236. * This function is called to shutdown the driver's mailbox sub-system.
  7237. * It first marks the mailbox sub-system is in a block state to prevent
  7238. * the asynchronous mailbox command from issued off the pending mailbox
  7239. * command queue. If the mailbox command sub-system shutdown is due to
  7240. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7241. * the mailbox sub-system flush routine to forcefully bring down the
  7242. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7243. * as with offline or HBA function reset), this routine will wait for the
  7244. * outstanding mailbox command to complete before invoking the mailbox
  7245. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7246. **/
  7247. void
  7248. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7249. {
  7250. struct lpfc_sli *psli = &phba->sli;
  7251. uint8_t actcmd = MBX_HEARTBEAT;
  7252. unsigned long timeout;
  7253. spin_lock_irq(&phba->hbalock);
  7254. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7255. spin_unlock_irq(&phba->hbalock);
  7256. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7257. spin_lock_irq(&phba->hbalock);
  7258. if (phba->sli.mbox_active)
  7259. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7260. spin_unlock_irq(&phba->hbalock);
  7261. /* Determine how long we might wait for the active mailbox
  7262. * command to be gracefully completed by firmware.
  7263. */
  7264. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7265. 1000) + jiffies;
  7266. while (phba->sli.mbox_active) {
  7267. /* Check active mailbox complete status every 2ms */
  7268. msleep(2);
  7269. if (time_after(jiffies, timeout))
  7270. /* Timeout, let the mailbox flush routine to
  7271. * forcefully release active mailbox command
  7272. */
  7273. break;
  7274. }
  7275. }
  7276. lpfc_sli_mbox_sys_flush(phba);
  7277. }
  7278. /**
  7279. * lpfc_sli_eratt_read - read sli-3 error attention events
  7280. * @phba: Pointer to HBA context.
  7281. *
  7282. * This function is called to read the SLI3 device error attention registers
  7283. * for possible error attention events. The caller must hold the hostlock
  7284. * with spin_lock_irq().
  7285. *
  7286. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7287. * Register and returns 0 otherwise.
  7288. **/
  7289. static int
  7290. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7291. {
  7292. uint32_t ha_copy;
  7293. /* Read chip Host Attention (HA) register */
  7294. ha_copy = readl(phba->HAregaddr);
  7295. if (ha_copy & HA_ERATT) {
  7296. /* Read host status register to retrieve error event */
  7297. lpfc_sli_read_hs(phba);
  7298. /* Check if there is a deferred error condition is active */
  7299. if ((HS_FFER1 & phba->work_hs) &&
  7300. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7301. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7302. phba->hba_flag |= DEFER_ERATT;
  7303. /* Clear all interrupt enable conditions */
  7304. writel(0, phba->HCregaddr);
  7305. readl(phba->HCregaddr);
  7306. }
  7307. /* Set the driver HA work bitmap */
  7308. phba->work_ha |= HA_ERATT;
  7309. /* Indicate polling handles this ERATT */
  7310. phba->hba_flag |= HBA_ERATT_HANDLED;
  7311. return 1;
  7312. }
  7313. return 0;
  7314. }
  7315. /**
  7316. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7317. * @phba: Pointer to HBA context.
  7318. *
  7319. * This function is called to read the SLI4 device error attention registers
  7320. * for possible error attention events. The caller must hold the hostlock
  7321. * with spin_lock_irq().
  7322. *
  7323. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7324. * Register and returns 0 otherwise.
  7325. **/
  7326. static int
  7327. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7328. {
  7329. uint32_t uerr_sta_hi, uerr_sta_lo;
  7330. /* For now, use the SLI4 device internal unrecoverable error
  7331. * registers for error attention. This can be changed later.
  7332. */
  7333. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7334. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7335. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7336. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7337. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7338. "1423 HBA Unrecoverable error: "
  7339. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7340. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7341. uerr_sta_lo, uerr_sta_hi,
  7342. phba->sli4_hba.ue_mask_lo,
  7343. phba->sli4_hba.ue_mask_hi);
  7344. phba->work_status[0] = uerr_sta_lo;
  7345. phba->work_status[1] = uerr_sta_hi;
  7346. /* Set the driver HA work bitmap */
  7347. phba->work_ha |= HA_ERATT;
  7348. /* Indicate polling handles this ERATT */
  7349. phba->hba_flag |= HBA_ERATT_HANDLED;
  7350. return 1;
  7351. }
  7352. return 0;
  7353. }
  7354. /**
  7355. * lpfc_sli_check_eratt - check error attention events
  7356. * @phba: Pointer to HBA context.
  7357. *
  7358. * This function is called from timer soft interrupt context to check HBA's
  7359. * error attention register bit for error attention events.
  7360. *
  7361. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7362. * Register and returns 0 otherwise.
  7363. **/
  7364. int
  7365. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7366. {
  7367. uint32_t ha_copy;
  7368. /* If somebody is waiting to handle an eratt, don't process it
  7369. * here. The brdkill function will do this.
  7370. */
  7371. if (phba->link_flag & LS_IGNORE_ERATT)
  7372. return 0;
  7373. /* Check if interrupt handler handles this ERATT */
  7374. spin_lock_irq(&phba->hbalock);
  7375. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7376. /* Interrupt handler has handled ERATT */
  7377. spin_unlock_irq(&phba->hbalock);
  7378. return 0;
  7379. }
  7380. /*
  7381. * If there is deferred error attention, do not check for error
  7382. * attention
  7383. */
  7384. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7385. spin_unlock_irq(&phba->hbalock);
  7386. return 0;
  7387. }
  7388. /* If PCI channel is offline, don't process it */
  7389. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7390. spin_unlock_irq(&phba->hbalock);
  7391. return 0;
  7392. }
  7393. switch (phba->sli_rev) {
  7394. case LPFC_SLI_REV2:
  7395. case LPFC_SLI_REV3:
  7396. /* Read chip Host Attention (HA) register */
  7397. ha_copy = lpfc_sli_eratt_read(phba);
  7398. break;
  7399. case LPFC_SLI_REV4:
  7400. /* Read devcie Uncoverable Error (UERR) registers */
  7401. ha_copy = lpfc_sli4_eratt_read(phba);
  7402. break;
  7403. default:
  7404. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7405. "0299 Invalid SLI revision (%d)\n",
  7406. phba->sli_rev);
  7407. ha_copy = 0;
  7408. break;
  7409. }
  7410. spin_unlock_irq(&phba->hbalock);
  7411. return ha_copy;
  7412. }
  7413. /**
  7414. * lpfc_intr_state_check - Check device state for interrupt handling
  7415. * @phba: Pointer to HBA context.
  7416. *
  7417. * This inline routine checks whether a device or its PCI slot is in a state
  7418. * that the interrupt should be handled.
  7419. *
  7420. * This function returns 0 if the device or the PCI slot is in a state that
  7421. * interrupt should be handled, otherwise -EIO.
  7422. */
  7423. static inline int
  7424. lpfc_intr_state_check(struct lpfc_hba *phba)
  7425. {
  7426. /* If the pci channel is offline, ignore all the interrupts */
  7427. if (unlikely(pci_channel_offline(phba->pcidev)))
  7428. return -EIO;
  7429. /* Update device level interrupt statistics */
  7430. phba->sli.slistat.sli_intr++;
  7431. /* Ignore all interrupts during initialization. */
  7432. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7433. return -EIO;
  7434. return 0;
  7435. }
  7436. /**
  7437. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7438. * @irq: Interrupt number.
  7439. * @dev_id: The device context pointer.
  7440. *
  7441. * This function is directly called from the PCI layer as an interrupt
  7442. * service routine when device with SLI-3 interface spec is enabled with
  7443. * MSI-X multi-message interrupt mode and there are slow-path events in
  7444. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7445. * interrupt mode, this function is called as part of the device-level
  7446. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7447. * is undergoing initialization, the interrupt handler will not process
  7448. * the interrupt. The link attention and ELS ring attention events are
  7449. * handled by the worker thread. The interrupt handler signals the worker
  7450. * thread and returns for these events. This function is called without
  7451. * any lock held. It gets the hbalock to access and update SLI data
  7452. * structures.
  7453. *
  7454. * This function returns IRQ_HANDLED when interrupt is handled else it
  7455. * returns IRQ_NONE.
  7456. **/
  7457. irqreturn_t
  7458. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7459. {
  7460. struct lpfc_hba *phba;
  7461. uint32_t ha_copy, hc_copy;
  7462. uint32_t work_ha_copy;
  7463. unsigned long status;
  7464. unsigned long iflag;
  7465. uint32_t control;
  7466. MAILBOX_t *mbox, *pmbox;
  7467. struct lpfc_vport *vport;
  7468. struct lpfc_nodelist *ndlp;
  7469. struct lpfc_dmabuf *mp;
  7470. LPFC_MBOXQ_t *pmb;
  7471. int rc;
  7472. /*
  7473. * Get the driver's phba structure from the dev_id and
  7474. * assume the HBA is not interrupting.
  7475. */
  7476. phba = (struct lpfc_hba *)dev_id;
  7477. if (unlikely(!phba))
  7478. return IRQ_NONE;
  7479. /*
  7480. * Stuff needs to be attented to when this function is invoked as an
  7481. * individual interrupt handler in MSI-X multi-message interrupt mode
  7482. */
  7483. if (phba->intr_type == MSIX) {
  7484. /* Check device state for handling interrupt */
  7485. if (lpfc_intr_state_check(phba))
  7486. return IRQ_NONE;
  7487. /* Need to read HA REG for slow-path events */
  7488. spin_lock_irqsave(&phba->hbalock, iflag);
  7489. ha_copy = readl(phba->HAregaddr);
  7490. /* If somebody is waiting to handle an eratt don't process it
  7491. * here. The brdkill function will do this.
  7492. */
  7493. if (phba->link_flag & LS_IGNORE_ERATT)
  7494. ha_copy &= ~HA_ERATT;
  7495. /* Check the need for handling ERATT in interrupt handler */
  7496. if (ha_copy & HA_ERATT) {
  7497. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7498. /* ERATT polling has handled ERATT */
  7499. ha_copy &= ~HA_ERATT;
  7500. else
  7501. /* Indicate interrupt handler handles ERATT */
  7502. phba->hba_flag |= HBA_ERATT_HANDLED;
  7503. }
  7504. /*
  7505. * If there is deferred error attention, do not check for any
  7506. * interrupt.
  7507. */
  7508. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7509. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7510. return IRQ_NONE;
  7511. }
  7512. /* Clear up only attention source related to slow-path */
  7513. hc_copy = readl(phba->HCregaddr);
  7514. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7515. HC_LAINT_ENA | HC_ERINT_ENA),
  7516. phba->HCregaddr);
  7517. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7518. phba->HAregaddr);
  7519. writel(hc_copy, phba->HCregaddr);
  7520. readl(phba->HAregaddr); /* flush */
  7521. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7522. } else
  7523. ha_copy = phba->ha_copy;
  7524. work_ha_copy = ha_copy & phba->work_ha_mask;
  7525. if (work_ha_copy) {
  7526. if (work_ha_copy & HA_LATT) {
  7527. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7528. /*
  7529. * Turn off Link Attention interrupts
  7530. * until CLEAR_LA done
  7531. */
  7532. spin_lock_irqsave(&phba->hbalock, iflag);
  7533. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7534. control = readl(phba->HCregaddr);
  7535. control &= ~HC_LAINT_ENA;
  7536. writel(control, phba->HCregaddr);
  7537. readl(phba->HCregaddr); /* flush */
  7538. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7539. }
  7540. else
  7541. work_ha_copy &= ~HA_LATT;
  7542. }
  7543. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7544. /*
  7545. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7546. * the only slow ring.
  7547. */
  7548. status = (work_ha_copy &
  7549. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7550. status >>= (4*LPFC_ELS_RING);
  7551. if (status & HA_RXMASK) {
  7552. spin_lock_irqsave(&phba->hbalock, iflag);
  7553. control = readl(phba->HCregaddr);
  7554. lpfc_debugfs_slow_ring_trc(phba,
  7555. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7556. control, status,
  7557. (uint32_t)phba->sli.slistat.sli_intr);
  7558. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7559. lpfc_debugfs_slow_ring_trc(phba,
  7560. "ISR Disable ring:"
  7561. "pwork:x%x hawork:x%x wait:x%x",
  7562. phba->work_ha, work_ha_copy,
  7563. (uint32_t)((unsigned long)
  7564. &phba->work_waitq));
  7565. control &=
  7566. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7567. writel(control, phba->HCregaddr);
  7568. readl(phba->HCregaddr); /* flush */
  7569. }
  7570. else {
  7571. lpfc_debugfs_slow_ring_trc(phba,
  7572. "ISR slow ring: pwork:"
  7573. "x%x hawork:x%x wait:x%x",
  7574. phba->work_ha, work_ha_copy,
  7575. (uint32_t)((unsigned long)
  7576. &phba->work_waitq));
  7577. }
  7578. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7579. }
  7580. }
  7581. spin_lock_irqsave(&phba->hbalock, iflag);
  7582. if (work_ha_copy & HA_ERATT) {
  7583. lpfc_sli_read_hs(phba);
  7584. /*
  7585. * Check if there is a deferred error condition
  7586. * is active
  7587. */
  7588. if ((HS_FFER1 & phba->work_hs) &&
  7589. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7590. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7591. phba->work_hs)) {
  7592. phba->hba_flag |= DEFER_ERATT;
  7593. /* Clear all interrupt enable conditions */
  7594. writel(0, phba->HCregaddr);
  7595. readl(phba->HCregaddr);
  7596. }
  7597. }
  7598. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7599. pmb = phba->sli.mbox_active;
  7600. pmbox = &pmb->u.mb;
  7601. mbox = phba->mbox;
  7602. vport = pmb->vport;
  7603. /* First check out the status word */
  7604. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7605. if (pmbox->mbxOwner != OWN_HOST) {
  7606. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7607. /*
  7608. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7609. * mbxStatus <status>
  7610. */
  7611. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7612. LOG_SLI,
  7613. "(%d):0304 Stray Mailbox "
  7614. "Interrupt mbxCommand x%x "
  7615. "mbxStatus x%x\n",
  7616. (vport ? vport->vpi : 0),
  7617. pmbox->mbxCommand,
  7618. pmbox->mbxStatus);
  7619. /* clear mailbox attention bit */
  7620. work_ha_copy &= ~HA_MBATT;
  7621. } else {
  7622. phba->sli.mbox_active = NULL;
  7623. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7624. phba->last_completion_time = jiffies;
  7625. del_timer(&phba->sli.mbox_tmo);
  7626. if (pmb->mbox_cmpl) {
  7627. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7628. MAILBOX_CMD_SIZE);
  7629. if (pmb->out_ext_byte_len &&
  7630. pmb->context2)
  7631. lpfc_sli_pcimem_bcopy(
  7632. phba->mbox_ext,
  7633. pmb->context2,
  7634. pmb->out_ext_byte_len);
  7635. }
  7636. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7637. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7638. lpfc_debugfs_disc_trc(vport,
  7639. LPFC_DISC_TRC_MBOX_VPORT,
  7640. "MBOX dflt rpi: : "
  7641. "status:x%x rpi:x%x",
  7642. (uint32_t)pmbox->mbxStatus,
  7643. pmbox->un.varWords[0], 0);
  7644. if (!pmbox->mbxStatus) {
  7645. mp = (struct lpfc_dmabuf *)
  7646. (pmb->context1);
  7647. ndlp = (struct lpfc_nodelist *)
  7648. pmb->context2;
  7649. /* Reg_LOGIN of dflt RPI was
  7650. * successful. new lets get
  7651. * rid of the RPI using the
  7652. * same mbox buffer.
  7653. */
  7654. lpfc_unreg_login(phba,
  7655. vport->vpi,
  7656. pmbox->un.varWords[0],
  7657. pmb);
  7658. pmb->mbox_cmpl =
  7659. lpfc_mbx_cmpl_dflt_rpi;
  7660. pmb->context1 = mp;
  7661. pmb->context2 = ndlp;
  7662. pmb->vport = vport;
  7663. rc = lpfc_sli_issue_mbox(phba,
  7664. pmb,
  7665. MBX_NOWAIT);
  7666. if (rc != MBX_BUSY)
  7667. lpfc_printf_log(phba,
  7668. KERN_ERR,
  7669. LOG_MBOX | LOG_SLI,
  7670. "0350 rc should have"
  7671. "been MBX_BUSY\n");
  7672. if (rc != MBX_NOT_FINISHED)
  7673. goto send_current_mbox;
  7674. }
  7675. }
  7676. spin_lock_irqsave(
  7677. &phba->pport->work_port_lock,
  7678. iflag);
  7679. phba->pport->work_port_events &=
  7680. ~WORKER_MBOX_TMO;
  7681. spin_unlock_irqrestore(
  7682. &phba->pport->work_port_lock,
  7683. iflag);
  7684. lpfc_mbox_cmpl_put(phba, pmb);
  7685. }
  7686. } else
  7687. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7688. if ((work_ha_copy & HA_MBATT) &&
  7689. (phba->sli.mbox_active == NULL)) {
  7690. send_current_mbox:
  7691. /* Process next mailbox command if there is one */
  7692. do {
  7693. rc = lpfc_sli_issue_mbox(phba, NULL,
  7694. MBX_NOWAIT);
  7695. } while (rc == MBX_NOT_FINISHED);
  7696. if (rc != MBX_SUCCESS)
  7697. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7698. LOG_SLI, "0349 rc should be "
  7699. "MBX_SUCCESS\n");
  7700. }
  7701. spin_lock_irqsave(&phba->hbalock, iflag);
  7702. phba->work_ha |= work_ha_copy;
  7703. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7704. lpfc_worker_wake_up(phba);
  7705. }
  7706. return IRQ_HANDLED;
  7707. } /* lpfc_sli_sp_intr_handler */
  7708. /**
  7709. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7710. * @irq: Interrupt number.
  7711. * @dev_id: The device context pointer.
  7712. *
  7713. * This function is directly called from the PCI layer as an interrupt
  7714. * service routine when device with SLI-3 interface spec is enabled with
  7715. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7716. * ring event in the HBA. However, when the device is enabled with either
  7717. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7718. * device-level interrupt handler. When the PCI slot is in error recovery
  7719. * or the HBA is undergoing initialization, the interrupt handler will not
  7720. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7721. * the intrrupt context. This function is called without any lock held.
  7722. * It gets the hbalock to access and update SLI data structures.
  7723. *
  7724. * This function returns IRQ_HANDLED when interrupt is handled else it
  7725. * returns IRQ_NONE.
  7726. **/
  7727. irqreturn_t
  7728. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7729. {
  7730. struct lpfc_hba *phba;
  7731. uint32_t ha_copy;
  7732. unsigned long status;
  7733. unsigned long iflag;
  7734. /* Get the driver's phba structure from the dev_id and
  7735. * assume the HBA is not interrupting.
  7736. */
  7737. phba = (struct lpfc_hba *) dev_id;
  7738. if (unlikely(!phba))
  7739. return IRQ_NONE;
  7740. /*
  7741. * Stuff needs to be attented to when this function is invoked as an
  7742. * individual interrupt handler in MSI-X multi-message interrupt mode
  7743. */
  7744. if (phba->intr_type == MSIX) {
  7745. /* Check device state for handling interrupt */
  7746. if (lpfc_intr_state_check(phba))
  7747. return IRQ_NONE;
  7748. /* Need to read HA REG for FCP ring and other ring events */
  7749. ha_copy = readl(phba->HAregaddr);
  7750. /* Clear up only attention source related to fast-path */
  7751. spin_lock_irqsave(&phba->hbalock, iflag);
  7752. /*
  7753. * If there is deferred error attention, do not check for
  7754. * any interrupt.
  7755. */
  7756. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7757. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7758. return IRQ_NONE;
  7759. }
  7760. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7761. phba->HAregaddr);
  7762. readl(phba->HAregaddr); /* flush */
  7763. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7764. } else
  7765. ha_copy = phba->ha_copy;
  7766. /*
  7767. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7768. */
  7769. ha_copy &= ~(phba->work_ha_mask);
  7770. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7771. status >>= (4*LPFC_FCP_RING);
  7772. if (status & HA_RXMASK)
  7773. lpfc_sli_handle_fast_ring_event(phba,
  7774. &phba->sli.ring[LPFC_FCP_RING],
  7775. status);
  7776. if (phba->cfg_multi_ring_support == 2) {
  7777. /*
  7778. * Process all events on extra ring. Take the optimized path
  7779. * for extra ring IO.
  7780. */
  7781. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7782. status >>= (4*LPFC_EXTRA_RING);
  7783. if (status & HA_RXMASK) {
  7784. lpfc_sli_handle_fast_ring_event(phba,
  7785. &phba->sli.ring[LPFC_EXTRA_RING],
  7786. status);
  7787. }
  7788. }
  7789. return IRQ_HANDLED;
  7790. } /* lpfc_sli_fp_intr_handler */
  7791. /**
  7792. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7793. * @irq: Interrupt number.
  7794. * @dev_id: The device context pointer.
  7795. *
  7796. * This function is the HBA device-level interrupt handler to device with
  7797. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7798. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7799. * requires driver attention. This function invokes the slow-path interrupt
  7800. * attention handling function and fast-path interrupt attention handling
  7801. * function in turn to process the relevant HBA attention events. This
  7802. * function is called without any lock held. It gets the hbalock to access
  7803. * and update SLI data structures.
  7804. *
  7805. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7806. * returns IRQ_NONE.
  7807. **/
  7808. irqreturn_t
  7809. lpfc_sli_intr_handler(int irq, void *dev_id)
  7810. {
  7811. struct lpfc_hba *phba;
  7812. irqreturn_t sp_irq_rc, fp_irq_rc;
  7813. unsigned long status1, status2;
  7814. uint32_t hc_copy;
  7815. /*
  7816. * Get the driver's phba structure from the dev_id and
  7817. * assume the HBA is not interrupting.
  7818. */
  7819. phba = (struct lpfc_hba *) dev_id;
  7820. if (unlikely(!phba))
  7821. return IRQ_NONE;
  7822. /* Check device state for handling interrupt */
  7823. if (lpfc_intr_state_check(phba))
  7824. return IRQ_NONE;
  7825. spin_lock(&phba->hbalock);
  7826. phba->ha_copy = readl(phba->HAregaddr);
  7827. if (unlikely(!phba->ha_copy)) {
  7828. spin_unlock(&phba->hbalock);
  7829. return IRQ_NONE;
  7830. } else if (phba->ha_copy & HA_ERATT) {
  7831. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7832. /* ERATT polling has handled ERATT */
  7833. phba->ha_copy &= ~HA_ERATT;
  7834. else
  7835. /* Indicate interrupt handler handles ERATT */
  7836. phba->hba_flag |= HBA_ERATT_HANDLED;
  7837. }
  7838. /*
  7839. * If there is deferred error attention, do not check for any interrupt.
  7840. */
  7841. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7842. spin_unlock(&phba->hbalock);
  7843. return IRQ_NONE;
  7844. }
  7845. /* Clear attention sources except link and error attentions */
  7846. hc_copy = readl(phba->HCregaddr);
  7847. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7848. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7849. phba->HCregaddr);
  7850. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7851. writel(hc_copy, phba->HCregaddr);
  7852. readl(phba->HAregaddr); /* flush */
  7853. spin_unlock(&phba->hbalock);
  7854. /*
  7855. * Invokes slow-path host attention interrupt handling as appropriate.
  7856. */
  7857. /* status of events with mailbox and link attention */
  7858. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7859. /* status of events with ELS ring */
  7860. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7861. status2 >>= (4*LPFC_ELS_RING);
  7862. if (status1 || (status2 & HA_RXMASK))
  7863. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7864. else
  7865. sp_irq_rc = IRQ_NONE;
  7866. /*
  7867. * Invoke fast-path host attention interrupt handling as appropriate.
  7868. */
  7869. /* status of events with FCP ring */
  7870. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7871. status1 >>= (4*LPFC_FCP_RING);
  7872. /* status of events with extra ring */
  7873. if (phba->cfg_multi_ring_support == 2) {
  7874. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7875. status2 >>= (4*LPFC_EXTRA_RING);
  7876. } else
  7877. status2 = 0;
  7878. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7879. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7880. else
  7881. fp_irq_rc = IRQ_NONE;
  7882. /* Return device-level interrupt handling status */
  7883. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7884. } /* lpfc_sli_intr_handler */
  7885. /**
  7886. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7887. * @phba: pointer to lpfc hba data structure.
  7888. *
  7889. * This routine is invoked by the worker thread to process all the pending
  7890. * SLI4 FCP abort XRI events.
  7891. **/
  7892. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7893. {
  7894. struct lpfc_cq_event *cq_event;
  7895. /* First, declare the fcp xri abort event has been handled */
  7896. spin_lock_irq(&phba->hbalock);
  7897. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7898. spin_unlock_irq(&phba->hbalock);
  7899. /* Now, handle all the fcp xri abort events */
  7900. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7901. /* Get the first event from the head of the event queue */
  7902. spin_lock_irq(&phba->hbalock);
  7903. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7904. cq_event, struct lpfc_cq_event, list);
  7905. spin_unlock_irq(&phba->hbalock);
  7906. /* Notify aborted XRI for FCP work queue */
  7907. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7908. /* Free the event processed back to the free pool */
  7909. lpfc_sli4_cq_event_release(phba, cq_event);
  7910. }
  7911. }
  7912. /**
  7913. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7914. * @phba: pointer to lpfc hba data structure.
  7915. *
  7916. * This routine is invoked by the worker thread to process all the pending
  7917. * SLI4 els abort xri events.
  7918. **/
  7919. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7920. {
  7921. struct lpfc_cq_event *cq_event;
  7922. /* First, declare the els xri abort event has been handled */
  7923. spin_lock_irq(&phba->hbalock);
  7924. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7925. spin_unlock_irq(&phba->hbalock);
  7926. /* Now, handle all the els xri abort events */
  7927. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7928. /* Get the first event from the head of the event queue */
  7929. spin_lock_irq(&phba->hbalock);
  7930. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7931. cq_event, struct lpfc_cq_event, list);
  7932. spin_unlock_irq(&phba->hbalock);
  7933. /* Notify aborted XRI for ELS work queue */
  7934. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7935. /* Free the event processed back to the free pool */
  7936. lpfc_sli4_cq_event_release(phba, cq_event);
  7937. }
  7938. }
  7939. /**
  7940. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7941. * @phba: pointer to lpfc hba data structure
  7942. * @pIocbIn: pointer to the rspiocbq
  7943. * @pIocbOut: pointer to the cmdiocbq
  7944. * @wcqe: pointer to the complete wcqe
  7945. *
  7946. * This routine transfers the fields of a command iocbq to a response iocbq
  7947. * by copying all the IOCB fields from command iocbq and transferring the
  7948. * completion status information from the complete wcqe.
  7949. **/
  7950. static void
  7951. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7952. struct lpfc_iocbq *pIocbIn,
  7953. struct lpfc_iocbq *pIocbOut,
  7954. struct lpfc_wcqe_complete *wcqe)
  7955. {
  7956. unsigned long iflags;
  7957. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7958. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7959. sizeof(struct lpfc_iocbq) - offset);
  7960. /* Map WCQE parameters into irspiocb parameters */
  7961. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7962. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7963. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7964. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7965. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7966. wcqe->total_data_placed;
  7967. else
  7968. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7969. else {
  7970. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7971. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7972. }
  7973. /* Pick up HBA exchange busy condition */
  7974. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7975. spin_lock_irqsave(&phba->hbalock, iflags);
  7976. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7977. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7978. }
  7979. }
  7980. /**
  7981. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7982. * @phba: Pointer to HBA context object.
  7983. * @wcqe: Pointer to work-queue completion queue entry.
  7984. *
  7985. * This routine handles an ELS work-queue completion event and construct
  7986. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7987. * discovery engine to handle.
  7988. *
  7989. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7990. **/
  7991. static struct lpfc_iocbq *
  7992. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7993. struct lpfc_iocbq *irspiocbq)
  7994. {
  7995. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7996. struct lpfc_iocbq *cmdiocbq;
  7997. struct lpfc_wcqe_complete *wcqe;
  7998. unsigned long iflags;
  7999. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  8000. spin_lock_irqsave(&phba->hbalock, iflags);
  8001. pring->stats.iocb_event++;
  8002. /* Look up the ELS command IOCB and create pseudo response IOCB */
  8003. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8004. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8005. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8006. if (unlikely(!cmdiocbq)) {
  8007. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8008. "0386 ELS complete with no corresponding "
  8009. "cmdiocb: iotag (%d)\n",
  8010. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8011. lpfc_sli_release_iocbq(phba, irspiocbq);
  8012. return NULL;
  8013. }
  8014. /* Fake the irspiocbq and copy necessary response information */
  8015. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  8016. return irspiocbq;
  8017. }
  8018. /**
  8019. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  8020. * @phba: Pointer to HBA context object.
  8021. * @cqe: Pointer to mailbox completion queue entry.
  8022. *
  8023. * This routine process a mailbox completion queue entry with asynchrous
  8024. * event.
  8025. *
  8026. * Return: true if work posted to worker thread, otherwise false.
  8027. **/
  8028. static bool
  8029. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8030. {
  8031. struct lpfc_cq_event *cq_event;
  8032. unsigned long iflags;
  8033. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8034. "0392 Async Event: word0:x%x, word1:x%x, "
  8035. "word2:x%x, word3:x%x\n", mcqe->word0,
  8036. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8037. /* Allocate a new internal CQ_EVENT entry */
  8038. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8039. if (!cq_event) {
  8040. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8041. "0394 Failed to allocate CQ_EVENT entry\n");
  8042. return false;
  8043. }
  8044. /* Move the CQE into an asynchronous event entry */
  8045. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8046. spin_lock_irqsave(&phba->hbalock, iflags);
  8047. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8048. /* Set the async event flag */
  8049. phba->hba_flag |= ASYNC_EVENT;
  8050. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8051. return true;
  8052. }
  8053. /**
  8054. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8055. * @phba: Pointer to HBA context object.
  8056. * @cqe: Pointer to mailbox completion queue entry.
  8057. *
  8058. * This routine process a mailbox completion queue entry with mailbox
  8059. * completion event.
  8060. *
  8061. * Return: true if work posted to worker thread, otherwise false.
  8062. **/
  8063. static bool
  8064. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8065. {
  8066. uint32_t mcqe_status;
  8067. MAILBOX_t *mbox, *pmbox;
  8068. struct lpfc_mqe *mqe;
  8069. struct lpfc_vport *vport;
  8070. struct lpfc_nodelist *ndlp;
  8071. struct lpfc_dmabuf *mp;
  8072. unsigned long iflags;
  8073. LPFC_MBOXQ_t *pmb;
  8074. bool workposted = false;
  8075. int rc;
  8076. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8077. if (!bf_get(lpfc_trailer_completed, mcqe))
  8078. goto out_no_mqe_complete;
  8079. /* Get the reference to the active mbox command */
  8080. spin_lock_irqsave(&phba->hbalock, iflags);
  8081. pmb = phba->sli.mbox_active;
  8082. if (unlikely(!pmb)) {
  8083. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8084. "1832 No pending MBOX command to handle\n");
  8085. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8086. goto out_no_mqe_complete;
  8087. }
  8088. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8089. mqe = &pmb->u.mqe;
  8090. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8091. mbox = phba->mbox;
  8092. vport = pmb->vport;
  8093. /* Reset heartbeat timer */
  8094. phba->last_completion_time = jiffies;
  8095. del_timer(&phba->sli.mbox_tmo);
  8096. /* Move mbox data to caller's mailbox region, do endian swapping */
  8097. if (pmb->mbox_cmpl && mbox)
  8098. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8099. /* Set the mailbox status with SLI4 range 0x4000 */
  8100. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8101. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8102. bf_set(lpfc_mqe_status, mqe,
  8103. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8104. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8105. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8106. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8107. "MBOX dflt rpi: status:x%x rpi:x%x",
  8108. mcqe_status,
  8109. pmbox->un.varWords[0], 0);
  8110. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8111. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8112. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8113. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8114. * RID of the PPI using the same mbox buffer.
  8115. */
  8116. lpfc_unreg_login(phba, vport->vpi,
  8117. pmbox->un.varWords[0], pmb);
  8118. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8119. pmb->context1 = mp;
  8120. pmb->context2 = ndlp;
  8121. pmb->vport = vport;
  8122. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8123. if (rc != MBX_BUSY)
  8124. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8125. LOG_SLI, "0385 rc should "
  8126. "have been MBX_BUSY\n");
  8127. if (rc != MBX_NOT_FINISHED)
  8128. goto send_current_mbox;
  8129. }
  8130. }
  8131. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8132. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8133. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8134. /* There is mailbox completion work to do */
  8135. spin_lock_irqsave(&phba->hbalock, iflags);
  8136. __lpfc_mbox_cmpl_put(phba, pmb);
  8137. phba->work_ha |= HA_MBATT;
  8138. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8139. workposted = true;
  8140. send_current_mbox:
  8141. spin_lock_irqsave(&phba->hbalock, iflags);
  8142. /* Release the mailbox command posting token */
  8143. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8144. /* Setting active mailbox pointer need to be in sync to flag clear */
  8145. phba->sli.mbox_active = NULL;
  8146. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8147. /* Wake up worker thread to post the next pending mailbox command */
  8148. lpfc_worker_wake_up(phba);
  8149. out_no_mqe_complete:
  8150. if (bf_get(lpfc_trailer_consumed, mcqe))
  8151. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8152. return workposted;
  8153. }
  8154. /**
  8155. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8156. * @phba: Pointer to HBA context object.
  8157. * @cqe: Pointer to mailbox completion queue entry.
  8158. *
  8159. * This routine process a mailbox completion queue entry, it invokes the
  8160. * proper mailbox complete handling or asynchrous event handling routine
  8161. * according to the MCQE's async bit.
  8162. *
  8163. * Return: true if work posted to worker thread, otherwise false.
  8164. **/
  8165. static bool
  8166. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8167. {
  8168. struct lpfc_mcqe mcqe;
  8169. bool workposted;
  8170. /* Copy the mailbox MCQE and convert endian order as needed */
  8171. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8172. /* Invoke the proper event handling routine */
  8173. if (!bf_get(lpfc_trailer_async, &mcqe))
  8174. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8175. else
  8176. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8177. return workposted;
  8178. }
  8179. /**
  8180. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8181. * @phba: Pointer to HBA context object.
  8182. * @wcqe: Pointer to work-queue completion queue entry.
  8183. *
  8184. * This routine handles an ELS work-queue completion event.
  8185. *
  8186. * Return: true if work posted to worker thread, otherwise false.
  8187. **/
  8188. static bool
  8189. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8190. struct lpfc_wcqe_complete *wcqe)
  8191. {
  8192. struct lpfc_iocbq *irspiocbq;
  8193. unsigned long iflags;
  8194. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8195. /* Get an irspiocbq for later ELS response processing use */
  8196. irspiocbq = lpfc_sli_get_iocbq(phba);
  8197. if (!irspiocbq) {
  8198. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8199. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8200. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8201. pring->txq_cnt, phba->iocb_cnt,
  8202. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8203. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8204. return false;
  8205. }
  8206. /* Save off the slow-path queue event for work thread to process */
  8207. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8208. spin_lock_irqsave(&phba->hbalock, iflags);
  8209. list_add_tail(&irspiocbq->cq_event.list,
  8210. &phba->sli4_hba.sp_queue_event);
  8211. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8212. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8213. return true;
  8214. }
  8215. /**
  8216. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8217. * @phba: Pointer to HBA context object.
  8218. * @wcqe: Pointer to work-queue completion queue entry.
  8219. *
  8220. * This routine handles slow-path WQ entry comsumed event by invoking the
  8221. * proper WQ release routine to the slow-path WQ.
  8222. **/
  8223. static void
  8224. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8225. struct lpfc_wcqe_release *wcqe)
  8226. {
  8227. /* Check for the slow-path ELS work queue */
  8228. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8229. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8230. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8231. else
  8232. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8233. "2579 Slow-path wqe consume event carries "
  8234. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8235. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8236. phba->sli4_hba.els_wq->queue_id);
  8237. }
  8238. /**
  8239. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8240. * @phba: Pointer to HBA context object.
  8241. * @cq: Pointer to a WQ completion queue.
  8242. * @wcqe: Pointer to work-queue completion queue entry.
  8243. *
  8244. * This routine handles an XRI abort event.
  8245. *
  8246. * Return: true if work posted to worker thread, otherwise false.
  8247. **/
  8248. static bool
  8249. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8250. struct lpfc_queue *cq,
  8251. struct sli4_wcqe_xri_aborted *wcqe)
  8252. {
  8253. bool workposted = false;
  8254. struct lpfc_cq_event *cq_event;
  8255. unsigned long iflags;
  8256. /* Allocate a new internal CQ_EVENT entry */
  8257. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8258. if (!cq_event) {
  8259. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8260. "0602 Failed to allocate CQ_EVENT entry\n");
  8261. return false;
  8262. }
  8263. /* Move the CQE into the proper xri abort event list */
  8264. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8265. switch (cq->subtype) {
  8266. case LPFC_FCP:
  8267. spin_lock_irqsave(&phba->hbalock, iflags);
  8268. list_add_tail(&cq_event->list,
  8269. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8270. /* Set the fcp xri abort event flag */
  8271. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8272. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8273. workposted = true;
  8274. break;
  8275. case LPFC_ELS:
  8276. spin_lock_irqsave(&phba->hbalock, iflags);
  8277. list_add_tail(&cq_event->list,
  8278. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8279. /* Set the els xri abort event flag */
  8280. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8281. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8282. workposted = true;
  8283. break;
  8284. default:
  8285. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8286. "0603 Invalid work queue CQE subtype (x%x)\n",
  8287. cq->subtype);
  8288. workposted = false;
  8289. break;
  8290. }
  8291. return workposted;
  8292. }
  8293. /**
  8294. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8295. * @phba: Pointer to HBA context object.
  8296. * @rcqe: Pointer to receive-queue completion queue entry.
  8297. *
  8298. * This routine process a receive-queue completion queue entry.
  8299. *
  8300. * Return: true if work posted to worker thread, otherwise false.
  8301. **/
  8302. static bool
  8303. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8304. {
  8305. bool workposted = false;
  8306. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8307. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8308. struct hbq_dmabuf *dma_buf;
  8309. uint32_t status;
  8310. unsigned long iflags;
  8311. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8312. goto out;
  8313. status = bf_get(lpfc_rcqe_status, rcqe);
  8314. switch (status) {
  8315. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8316. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8317. "2537 Receive Frame Truncated!!\n");
  8318. case FC_STATUS_RQ_SUCCESS:
  8319. lpfc_sli4_rq_release(hrq, drq);
  8320. spin_lock_irqsave(&phba->hbalock, iflags);
  8321. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8322. if (!dma_buf) {
  8323. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8324. goto out;
  8325. }
  8326. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8327. /* save off the frame for the word thread to process */
  8328. list_add_tail(&dma_buf->cq_event.list,
  8329. &phba->sli4_hba.sp_queue_event);
  8330. /* Frame received */
  8331. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8332. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8333. workposted = true;
  8334. break;
  8335. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8336. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8337. /* Post more buffers if possible */
  8338. spin_lock_irqsave(&phba->hbalock, iflags);
  8339. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8340. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8341. workposted = true;
  8342. break;
  8343. }
  8344. out:
  8345. return workposted;
  8346. }
  8347. /**
  8348. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8349. * @phba: Pointer to HBA context object.
  8350. * @cq: Pointer to the completion queue.
  8351. * @wcqe: Pointer to a completion queue entry.
  8352. *
  8353. * This routine process a slow-path work-queue or recieve queue completion queue
  8354. * entry.
  8355. *
  8356. * Return: true if work posted to worker thread, otherwise false.
  8357. **/
  8358. static bool
  8359. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8360. struct lpfc_cqe *cqe)
  8361. {
  8362. struct lpfc_cqe cqevt;
  8363. bool workposted = false;
  8364. /* Copy the work queue CQE and convert endian order if needed */
  8365. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8366. /* Check and process for different type of WCQE and dispatch */
  8367. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8368. case CQE_CODE_COMPL_WQE:
  8369. /* Process the WQ/RQ complete event */
  8370. phba->last_completion_time = jiffies;
  8371. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8372. (struct lpfc_wcqe_complete *)&cqevt);
  8373. break;
  8374. case CQE_CODE_RELEASE_WQE:
  8375. /* Process the WQ release event */
  8376. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8377. (struct lpfc_wcqe_release *)&cqevt);
  8378. break;
  8379. case CQE_CODE_XRI_ABORTED:
  8380. /* Process the WQ XRI abort event */
  8381. phba->last_completion_time = jiffies;
  8382. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8383. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8384. break;
  8385. case CQE_CODE_RECEIVE:
  8386. /* Process the RQ event */
  8387. phba->last_completion_time = jiffies;
  8388. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8389. (struct lpfc_rcqe *)&cqevt);
  8390. break;
  8391. default:
  8392. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8393. "0388 Not a valid WCQE code: x%x\n",
  8394. bf_get(lpfc_cqe_code, &cqevt));
  8395. break;
  8396. }
  8397. return workposted;
  8398. }
  8399. /**
  8400. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8401. * @phba: Pointer to HBA context object.
  8402. * @eqe: Pointer to fast-path event queue entry.
  8403. *
  8404. * This routine process a event queue entry from the slow-path event queue.
  8405. * It will check the MajorCode and MinorCode to determine this is for a
  8406. * completion event on a completion queue, if not, an error shall be logged
  8407. * and just return. Otherwise, it will get to the corresponding completion
  8408. * queue and process all the entries on that completion queue, rearm the
  8409. * completion queue, and then return.
  8410. *
  8411. **/
  8412. static void
  8413. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8414. {
  8415. struct lpfc_queue *cq = NULL, *childq, *speq;
  8416. struct lpfc_cqe *cqe;
  8417. bool workposted = false;
  8418. int ecount = 0;
  8419. uint16_t cqid;
  8420. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8421. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8422. "0359 Not a valid slow-path completion "
  8423. "event: majorcode=x%x, minorcode=x%x\n",
  8424. bf_get_le32(lpfc_eqe_major_code, eqe),
  8425. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8426. return;
  8427. }
  8428. /* Get the reference to the corresponding CQ */
  8429. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8430. /* Search for completion queue pointer matching this cqid */
  8431. speq = phba->sli4_hba.sp_eq;
  8432. list_for_each_entry(childq, &speq->child_list, list) {
  8433. if (childq->queue_id == cqid) {
  8434. cq = childq;
  8435. break;
  8436. }
  8437. }
  8438. if (unlikely(!cq)) {
  8439. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8440. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8441. "0365 Slow-path CQ identifier "
  8442. "(%d) does not exist\n", cqid);
  8443. return;
  8444. }
  8445. /* Process all the entries to the CQ */
  8446. switch (cq->type) {
  8447. case LPFC_MCQ:
  8448. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8449. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8450. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8451. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8452. }
  8453. break;
  8454. case LPFC_WCQ:
  8455. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8456. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8457. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8458. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8459. }
  8460. break;
  8461. default:
  8462. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8463. "0370 Invalid completion queue type (%d)\n",
  8464. cq->type);
  8465. return;
  8466. }
  8467. /* Catch the no cq entry condition, log an error */
  8468. if (unlikely(ecount == 0))
  8469. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8470. "0371 No entry from the CQ: identifier "
  8471. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8472. /* In any case, flash and re-arm the RCQ */
  8473. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8474. /* wake up worker thread if there are works to be done */
  8475. if (workposted)
  8476. lpfc_worker_wake_up(phba);
  8477. }
  8478. /**
  8479. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8480. * @eqe: Pointer to fast-path completion queue entry.
  8481. *
  8482. * This routine process a fast-path work queue completion entry from fast-path
  8483. * event queue for FCP command response completion.
  8484. **/
  8485. static void
  8486. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8487. struct lpfc_wcqe_complete *wcqe)
  8488. {
  8489. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8490. struct lpfc_iocbq *cmdiocbq;
  8491. struct lpfc_iocbq irspiocbq;
  8492. unsigned long iflags;
  8493. spin_lock_irqsave(&phba->hbalock, iflags);
  8494. pring->stats.iocb_event++;
  8495. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8496. /* Check for response status */
  8497. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8498. /* If resource errors reported from HBA, reduce queue
  8499. * depth of the SCSI device.
  8500. */
  8501. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8502. IOSTAT_LOCAL_REJECT) &&
  8503. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8504. phba->lpfc_rampdown_queue_depth(phba);
  8505. }
  8506. /* Log the error status */
  8507. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8508. "0373 FCP complete error: status=x%x, "
  8509. "hw_status=x%x, total_data_specified=%d, "
  8510. "parameter=x%x, word3=x%x\n",
  8511. bf_get(lpfc_wcqe_c_status, wcqe),
  8512. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8513. wcqe->total_data_placed, wcqe->parameter,
  8514. wcqe->word3);
  8515. }
  8516. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8517. spin_lock_irqsave(&phba->hbalock, iflags);
  8518. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8519. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8520. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8521. if (unlikely(!cmdiocbq)) {
  8522. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8523. "0374 FCP complete with no corresponding "
  8524. "cmdiocb: iotag (%d)\n",
  8525. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8526. return;
  8527. }
  8528. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8529. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8530. "0375 FCP cmdiocb not callback function "
  8531. "iotag: (%d)\n",
  8532. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8533. return;
  8534. }
  8535. /* Fake the irspiocb and copy necessary response information */
  8536. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8537. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8538. spin_lock_irqsave(&phba->hbalock, iflags);
  8539. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8540. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8541. }
  8542. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8543. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8544. }
  8545. /**
  8546. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8547. * @phba: Pointer to HBA context object.
  8548. * @cq: Pointer to completion queue.
  8549. * @wcqe: Pointer to work-queue completion queue entry.
  8550. *
  8551. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8552. * proper WQ release routine to the slow-path WQ.
  8553. **/
  8554. static void
  8555. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8556. struct lpfc_wcqe_release *wcqe)
  8557. {
  8558. struct lpfc_queue *childwq;
  8559. bool wqid_matched = false;
  8560. uint16_t fcp_wqid;
  8561. /* Check for fast-path FCP work queue release */
  8562. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8563. list_for_each_entry(childwq, &cq->child_list, list) {
  8564. if (childwq->queue_id == fcp_wqid) {
  8565. lpfc_sli4_wq_release(childwq,
  8566. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8567. wqid_matched = true;
  8568. break;
  8569. }
  8570. }
  8571. /* Report warning log message if no match found */
  8572. if (wqid_matched != true)
  8573. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8574. "2580 Fast-path wqe consume event carries "
  8575. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8576. }
  8577. /**
  8578. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8579. * @cq: Pointer to the completion queue.
  8580. * @eqe: Pointer to fast-path completion queue entry.
  8581. *
  8582. * This routine process a fast-path work queue completion entry from fast-path
  8583. * event queue for FCP command response completion.
  8584. **/
  8585. static int
  8586. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8587. struct lpfc_cqe *cqe)
  8588. {
  8589. struct lpfc_wcqe_release wcqe;
  8590. bool workposted = false;
  8591. /* Copy the work queue CQE and convert endian order if needed */
  8592. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8593. /* Check and process for different type of WCQE and dispatch */
  8594. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8595. case CQE_CODE_COMPL_WQE:
  8596. /* Process the WQ complete event */
  8597. phba->last_completion_time = jiffies;
  8598. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8599. (struct lpfc_wcqe_complete *)&wcqe);
  8600. break;
  8601. case CQE_CODE_RELEASE_WQE:
  8602. /* Process the WQ release event */
  8603. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8604. (struct lpfc_wcqe_release *)&wcqe);
  8605. break;
  8606. case CQE_CODE_XRI_ABORTED:
  8607. /* Process the WQ XRI abort event */
  8608. phba->last_completion_time = jiffies;
  8609. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8610. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8611. break;
  8612. default:
  8613. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8614. "0144 Not a valid WCQE code: x%x\n",
  8615. bf_get(lpfc_wcqe_c_code, &wcqe));
  8616. break;
  8617. }
  8618. return workposted;
  8619. }
  8620. /**
  8621. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8622. * @phba: Pointer to HBA context object.
  8623. * @eqe: Pointer to fast-path event queue entry.
  8624. *
  8625. * This routine process a event queue entry from the fast-path event queue.
  8626. * It will check the MajorCode and MinorCode to determine this is for a
  8627. * completion event on a completion queue, if not, an error shall be logged
  8628. * and just return. Otherwise, it will get to the corresponding completion
  8629. * queue and process all the entries on the completion queue, rearm the
  8630. * completion queue, and then return.
  8631. **/
  8632. static void
  8633. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8634. uint32_t fcp_cqidx)
  8635. {
  8636. struct lpfc_queue *cq;
  8637. struct lpfc_cqe *cqe;
  8638. bool workposted = false;
  8639. uint16_t cqid;
  8640. int ecount = 0;
  8641. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8642. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8643. "0366 Not a valid fast-path completion "
  8644. "event: majorcode=x%x, minorcode=x%x\n",
  8645. bf_get_le32(lpfc_eqe_major_code, eqe),
  8646. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8647. return;
  8648. }
  8649. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8650. if (unlikely(!cq)) {
  8651. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8652. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8653. "0367 Fast-path completion queue "
  8654. "does not exist\n");
  8655. return;
  8656. }
  8657. /* Get the reference to the corresponding CQ */
  8658. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8659. if (unlikely(cqid != cq->queue_id)) {
  8660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8661. "0368 Miss-matched fast-path completion "
  8662. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8663. cqid, cq->queue_id);
  8664. return;
  8665. }
  8666. /* Process all the entries to the CQ */
  8667. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8668. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8669. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8670. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8671. }
  8672. /* Catch the no cq entry condition */
  8673. if (unlikely(ecount == 0))
  8674. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8675. "0369 No entry from fast-path completion "
  8676. "queue fcpcqid=%d\n", cq->queue_id);
  8677. /* In any case, flash and re-arm the CQ */
  8678. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8679. /* wake up worker thread if there are works to be done */
  8680. if (workposted)
  8681. lpfc_worker_wake_up(phba);
  8682. }
  8683. static void
  8684. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8685. {
  8686. struct lpfc_eqe *eqe;
  8687. /* walk all the EQ entries and drop on the floor */
  8688. while ((eqe = lpfc_sli4_eq_get(eq)))
  8689. ;
  8690. /* Clear and re-arm the EQ */
  8691. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8692. }
  8693. /**
  8694. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8695. * @irq: Interrupt number.
  8696. * @dev_id: The device context pointer.
  8697. *
  8698. * This function is directly called from the PCI layer as an interrupt
  8699. * service routine when device with SLI-4 interface spec is enabled with
  8700. * MSI-X multi-message interrupt mode and there are slow-path events in
  8701. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8702. * interrupt mode, this function is called as part of the device-level
  8703. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8704. * undergoing initialization, the interrupt handler will not process the
  8705. * interrupt. The link attention and ELS ring attention events are handled
  8706. * by the worker thread. The interrupt handler signals the worker thread
  8707. * and returns for these events. This function is called without any lock
  8708. * held. It gets the hbalock to access and update SLI data structures.
  8709. *
  8710. * This function returns IRQ_HANDLED when interrupt is handled else it
  8711. * returns IRQ_NONE.
  8712. **/
  8713. irqreturn_t
  8714. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8715. {
  8716. struct lpfc_hba *phba;
  8717. struct lpfc_queue *speq;
  8718. struct lpfc_eqe *eqe;
  8719. unsigned long iflag;
  8720. int ecount = 0;
  8721. /*
  8722. * Get the driver's phba structure from the dev_id
  8723. */
  8724. phba = (struct lpfc_hba *)dev_id;
  8725. if (unlikely(!phba))
  8726. return IRQ_NONE;
  8727. /* Get to the EQ struct associated with this vector */
  8728. speq = phba->sli4_hba.sp_eq;
  8729. /* Check device state for handling interrupt */
  8730. if (unlikely(lpfc_intr_state_check(phba))) {
  8731. /* Check again for link_state with lock held */
  8732. spin_lock_irqsave(&phba->hbalock, iflag);
  8733. if (phba->link_state < LPFC_LINK_DOWN)
  8734. /* Flush, clear interrupt, and rearm the EQ */
  8735. lpfc_sli4_eq_flush(phba, speq);
  8736. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8737. return IRQ_NONE;
  8738. }
  8739. /*
  8740. * Process all the event on FCP slow-path EQ
  8741. */
  8742. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8743. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8744. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8745. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8746. }
  8747. /* Always clear and re-arm the slow-path EQ */
  8748. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8749. /* Catch the no cq entry condition */
  8750. if (unlikely(ecount == 0)) {
  8751. if (phba->intr_type == MSIX)
  8752. /* MSI-X treated interrupt served as no EQ share INT */
  8753. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8754. "0357 MSI-X interrupt with no EQE\n");
  8755. else
  8756. /* Non MSI-X treated on interrupt as EQ share INT */
  8757. return IRQ_NONE;
  8758. }
  8759. return IRQ_HANDLED;
  8760. } /* lpfc_sli4_sp_intr_handler */
  8761. /**
  8762. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8763. * @irq: Interrupt number.
  8764. * @dev_id: The device context pointer.
  8765. *
  8766. * This function is directly called from the PCI layer as an interrupt
  8767. * service routine when device with SLI-4 interface spec is enabled with
  8768. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8769. * ring event in the HBA. However, when the device is enabled with either
  8770. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8771. * device-level interrupt handler. When the PCI slot is in error recovery
  8772. * or the HBA is undergoing initialization, the interrupt handler will not
  8773. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8774. * the intrrupt context. This function is called without any lock held.
  8775. * It gets the hbalock to access and update SLI data structures. Note that,
  8776. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8777. * equal to that of FCP CQ index.
  8778. *
  8779. * This function returns IRQ_HANDLED when interrupt is handled else it
  8780. * returns IRQ_NONE.
  8781. **/
  8782. irqreturn_t
  8783. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8784. {
  8785. struct lpfc_hba *phba;
  8786. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8787. struct lpfc_queue *fpeq;
  8788. struct lpfc_eqe *eqe;
  8789. unsigned long iflag;
  8790. int ecount = 0;
  8791. uint32_t fcp_eqidx;
  8792. /* Get the driver's phba structure from the dev_id */
  8793. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8794. phba = fcp_eq_hdl->phba;
  8795. fcp_eqidx = fcp_eq_hdl->idx;
  8796. if (unlikely(!phba))
  8797. return IRQ_NONE;
  8798. /* Get to the EQ struct associated with this vector */
  8799. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8800. /* Check device state for handling interrupt */
  8801. if (unlikely(lpfc_intr_state_check(phba))) {
  8802. /* Check again for link_state with lock held */
  8803. spin_lock_irqsave(&phba->hbalock, iflag);
  8804. if (phba->link_state < LPFC_LINK_DOWN)
  8805. /* Flush, clear interrupt, and rearm the EQ */
  8806. lpfc_sli4_eq_flush(phba, fpeq);
  8807. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8808. return IRQ_NONE;
  8809. }
  8810. /*
  8811. * Process all the event on FCP fast-path EQ
  8812. */
  8813. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8814. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8815. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8816. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8817. }
  8818. /* Always clear and re-arm the fast-path EQ */
  8819. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8820. if (unlikely(ecount == 0)) {
  8821. if (phba->intr_type == MSIX)
  8822. /* MSI-X treated interrupt served as no EQ share INT */
  8823. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8824. "0358 MSI-X interrupt with no EQE\n");
  8825. else
  8826. /* Non MSI-X treated on interrupt as EQ share INT */
  8827. return IRQ_NONE;
  8828. }
  8829. return IRQ_HANDLED;
  8830. } /* lpfc_sli4_fp_intr_handler */
  8831. /**
  8832. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8833. * @irq: Interrupt number.
  8834. * @dev_id: The device context pointer.
  8835. *
  8836. * This function is the device-level interrupt handler to device with SLI-4
  8837. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8838. * interrupt mode is enabled and there is an event in the HBA which requires
  8839. * driver attention. This function invokes the slow-path interrupt attention
  8840. * handling function and fast-path interrupt attention handling function in
  8841. * turn to process the relevant HBA attention events. This function is called
  8842. * without any lock held. It gets the hbalock to access and update SLI data
  8843. * structures.
  8844. *
  8845. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8846. * returns IRQ_NONE.
  8847. **/
  8848. irqreturn_t
  8849. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8850. {
  8851. struct lpfc_hba *phba;
  8852. irqreturn_t sp_irq_rc, fp_irq_rc;
  8853. bool fp_handled = false;
  8854. uint32_t fcp_eqidx;
  8855. /* Get the driver's phba structure from the dev_id */
  8856. phba = (struct lpfc_hba *)dev_id;
  8857. if (unlikely(!phba))
  8858. return IRQ_NONE;
  8859. /*
  8860. * Invokes slow-path host attention interrupt handling as appropriate.
  8861. */
  8862. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8863. /*
  8864. * Invoke fast-path host attention interrupt handling as appropriate.
  8865. */
  8866. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8867. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8868. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8869. if (fp_irq_rc == IRQ_HANDLED)
  8870. fp_handled |= true;
  8871. }
  8872. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8873. } /* lpfc_sli4_intr_handler */
  8874. /**
  8875. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8876. * @queue: The queue structure to free.
  8877. *
  8878. * This function frees a queue structure and the DMAable memeory used for
  8879. * the host resident queue. This function must be called after destroying the
  8880. * queue on the HBA.
  8881. **/
  8882. void
  8883. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8884. {
  8885. struct lpfc_dmabuf *dmabuf;
  8886. if (!queue)
  8887. return;
  8888. while (!list_empty(&queue->page_list)) {
  8889. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8890. list);
  8891. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8892. dmabuf->virt, dmabuf->phys);
  8893. kfree(dmabuf);
  8894. }
  8895. kfree(queue);
  8896. return;
  8897. }
  8898. /**
  8899. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8900. * @phba: The HBA that this queue is being created on.
  8901. * @entry_size: The size of each queue entry for this queue.
  8902. * @entry count: The number of entries that this queue will handle.
  8903. *
  8904. * This function allocates a queue structure and the DMAable memory used for
  8905. * the host resident queue. This function must be called before creating the
  8906. * queue on the HBA.
  8907. **/
  8908. struct lpfc_queue *
  8909. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8910. uint32_t entry_count)
  8911. {
  8912. struct lpfc_queue *queue;
  8913. struct lpfc_dmabuf *dmabuf;
  8914. int x, total_qe_count;
  8915. void *dma_pointer;
  8916. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8917. if (!phba->sli4_hba.pc_sli4_params.supported)
  8918. hw_page_size = SLI4_PAGE_SIZE;
  8919. queue = kzalloc(sizeof(struct lpfc_queue) +
  8920. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8921. if (!queue)
  8922. return NULL;
  8923. queue->page_count = (ALIGN(entry_size * entry_count,
  8924. hw_page_size))/hw_page_size;
  8925. INIT_LIST_HEAD(&queue->list);
  8926. INIT_LIST_HEAD(&queue->page_list);
  8927. INIT_LIST_HEAD(&queue->child_list);
  8928. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8929. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8930. if (!dmabuf)
  8931. goto out_fail;
  8932. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8933. hw_page_size, &dmabuf->phys,
  8934. GFP_KERNEL);
  8935. if (!dmabuf->virt) {
  8936. kfree(dmabuf);
  8937. goto out_fail;
  8938. }
  8939. memset(dmabuf->virt, 0, hw_page_size);
  8940. dmabuf->buffer_tag = x;
  8941. list_add_tail(&dmabuf->list, &queue->page_list);
  8942. /* initialize queue's entry array */
  8943. dma_pointer = dmabuf->virt;
  8944. for (; total_qe_count < entry_count &&
  8945. dma_pointer < (hw_page_size + dmabuf->virt);
  8946. total_qe_count++, dma_pointer += entry_size) {
  8947. queue->qe[total_qe_count].address = dma_pointer;
  8948. }
  8949. }
  8950. queue->entry_size = entry_size;
  8951. queue->entry_count = entry_count;
  8952. queue->phba = phba;
  8953. return queue;
  8954. out_fail:
  8955. lpfc_sli4_queue_free(queue);
  8956. return NULL;
  8957. }
  8958. /**
  8959. * lpfc_eq_create - Create an Event Queue on the HBA
  8960. * @phba: HBA structure that indicates port to create a queue on.
  8961. * @eq: The queue structure to use to create the event queue.
  8962. * @imax: The maximum interrupt per second limit.
  8963. *
  8964. * This function creates an event queue, as detailed in @eq, on a port,
  8965. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8966. *
  8967. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8968. * is used to get the entry count and entry size that are necessary to
  8969. * determine the number of pages to allocate and use for this queue. This
  8970. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8971. * event queue. This function is asynchronous and will wait for the mailbox
  8972. * command to finish before continuing.
  8973. *
  8974. * On success this function will return a zero. If unable to allocate enough
  8975. * memory this function will return -ENOMEM. If the queue create mailbox command
  8976. * fails this function will return -ENXIO.
  8977. **/
  8978. uint32_t
  8979. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8980. {
  8981. struct lpfc_mbx_eq_create *eq_create;
  8982. LPFC_MBOXQ_t *mbox;
  8983. int rc, length, status = 0;
  8984. struct lpfc_dmabuf *dmabuf;
  8985. uint32_t shdr_status, shdr_add_status;
  8986. union lpfc_sli4_cfg_shdr *shdr;
  8987. uint16_t dmult;
  8988. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8989. if (!phba->sli4_hba.pc_sli4_params.supported)
  8990. hw_page_size = SLI4_PAGE_SIZE;
  8991. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8992. if (!mbox)
  8993. return -ENOMEM;
  8994. length = (sizeof(struct lpfc_mbx_eq_create) -
  8995. sizeof(struct lpfc_sli4_cfg_mhdr));
  8996. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8997. LPFC_MBOX_OPCODE_EQ_CREATE,
  8998. length, LPFC_SLI4_MBX_EMBED);
  8999. eq_create = &mbox->u.mqe.un.eq_create;
  9000. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  9001. eq->page_count);
  9002. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  9003. LPFC_EQE_SIZE);
  9004. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  9005. /* Calculate delay multiper from maximum interrupt per second */
  9006. dmult = LPFC_DMULT_CONST/imax - 1;
  9007. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  9008. dmult);
  9009. switch (eq->entry_count) {
  9010. default:
  9011. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9012. "0360 Unsupported EQ count. (%d)\n",
  9013. eq->entry_count);
  9014. if (eq->entry_count < 256)
  9015. return -EINVAL;
  9016. /* otherwise default to smallest count (drop through) */
  9017. case 256:
  9018. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9019. LPFC_EQ_CNT_256);
  9020. break;
  9021. case 512:
  9022. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9023. LPFC_EQ_CNT_512);
  9024. break;
  9025. case 1024:
  9026. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9027. LPFC_EQ_CNT_1024);
  9028. break;
  9029. case 2048:
  9030. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9031. LPFC_EQ_CNT_2048);
  9032. break;
  9033. case 4096:
  9034. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9035. LPFC_EQ_CNT_4096);
  9036. break;
  9037. }
  9038. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9039. memset(dmabuf->virt, 0, hw_page_size);
  9040. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9041. putPaddrLow(dmabuf->phys);
  9042. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9043. putPaddrHigh(dmabuf->phys);
  9044. }
  9045. mbox->vport = phba->pport;
  9046. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9047. mbox->context1 = NULL;
  9048. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9049. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9050. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9051. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9052. if (shdr_status || shdr_add_status || rc) {
  9053. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9054. "2500 EQ_CREATE mailbox failed with "
  9055. "status x%x add_status x%x, mbx status x%x\n",
  9056. shdr_status, shdr_add_status, rc);
  9057. status = -ENXIO;
  9058. }
  9059. eq->type = LPFC_EQ;
  9060. eq->subtype = LPFC_NONE;
  9061. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9062. if (eq->queue_id == 0xFFFF)
  9063. status = -ENXIO;
  9064. eq->host_index = 0;
  9065. eq->hba_index = 0;
  9066. mempool_free(mbox, phba->mbox_mem_pool);
  9067. return status;
  9068. }
  9069. /**
  9070. * lpfc_cq_create - Create a Completion Queue on the HBA
  9071. * @phba: HBA structure that indicates port to create a queue on.
  9072. * @cq: The queue structure to use to create the completion queue.
  9073. * @eq: The event queue to bind this completion queue to.
  9074. *
  9075. * This function creates a completion queue, as detailed in @wq, on a port,
  9076. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9077. *
  9078. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9079. * is used to get the entry count and entry size that are necessary to
  9080. * determine the number of pages to allocate and use for this queue. The @eq
  9081. * is used to indicate which event queue to bind this completion queue to. This
  9082. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9083. * completion queue. This function is asynchronous and will wait for the mailbox
  9084. * command to finish before continuing.
  9085. *
  9086. * On success this function will return a zero. If unable to allocate enough
  9087. * memory this function will return -ENOMEM. If the queue create mailbox command
  9088. * fails this function will return -ENXIO.
  9089. **/
  9090. uint32_t
  9091. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9092. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9093. {
  9094. struct lpfc_mbx_cq_create *cq_create;
  9095. struct lpfc_dmabuf *dmabuf;
  9096. LPFC_MBOXQ_t *mbox;
  9097. int rc, length, status = 0;
  9098. uint32_t shdr_status, shdr_add_status;
  9099. union lpfc_sli4_cfg_shdr *shdr;
  9100. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9101. if (!phba->sli4_hba.pc_sli4_params.supported)
  9102. hw_page_size = SLI4_PAGE_SIZE;
  9103. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9104. if (!mbox)
  9105. return -ENOMEM;
  9106. length = (sizeof(struct lpfc_mbx_cq_create) -
  9107. sizeof(struct lpfc_sli4_cfg_mhdr));
  9108. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9109. LPFC_MBOX_OPCODE_CQ_CREATE,
  9110. length, LPFC_SLI4_MBX_EMBED);
  9111. cq_create = &mbox->u.mqe.un.cq_create;
  9112. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9113. cq->page_count);
  9114. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9115. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9116. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9117. switch (cq->entry_count) {
  9118. default:
  9119. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9120. "0361 Unsupported CQ count. (%d)\n",
  9121. cq->entry_count);
  9122. if (cq->entry_count < 256)
  9123. return -EINVAL;
  9124. /* otherwise default to smallest count (drop through) */
  9125. case 256:
  9126. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9127. LPFC_CQ_CNT_256);
  9128. break;
  9129. case 512:
  9130. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9131. LPFC_CQ_CNT_512);
  9132. break;
  9133. case 1024:
  9134. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9135. LPFC_CQ_CNT_1024);
  9136. break;
  9137. }
  9138. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9139. memset(dmabuf->virt, 0, hw_page_size);
  9140. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9141. putPaddrLow(dmabuf->phys);
  9142. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9143. putPaddrHigh(dmabuf->phys);
  9144. }
  9145. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9146. /* The IOCTL status is embedded in the mailbox subheader. */
  9147. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9148. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9149. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9150. if (shdr_status || shdr_add_status || rc) {
  9151. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9152. "2501 CQ_CREATE mailbox failed with "
  9153. "status x%x add_status x%x, mbx status x%x\n",
  9154. shdr_status, shdr_add_status, rc);
  9155. status = -ENXIO;
  9156. goto out;
  9157. }
  9158. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9159. if (cq->queue_id == 0xFFFF) {
  9160. status = -ENXIO;
  9161. goto out;
  9162. }
  9163. /* link the cq onto the parent eq child list */
  9164. list_add_tail(&cq->list, &eq->child_list);
  9165. /* Set up completion queue's type and subtype */
  9166. cq->type = type;
  9167. cq->subtype = subtype;
  9168. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9169. cq->host_index = 0;
  9170. cq->hba_index = 0;
  9171. out:
  9172. mempool_free(mbox, phba->mbox_mem_pool);
  9173. return status;
  9174. }
  9175. /**
  9176. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9177. * @phba: HBA structure that indicates port to create a queue on.
  9178. * @mq: The queue structure to use to create the mailbox queue.
  9179. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9180. * @cq: The completion queue to associate with this cq.
  9181. *
  9182. * This function provides failback (fb) functionality when the
  9183. * mq_create_ext fails on older FW generations. It's purpose is identical
  9184. * to mq_create_ext otherwise.
  9185. *
  9186. * This routine cannot fail as all attributes were previously accessed and
  9187. * initialized in mq_create_ext.
  9188. **/
  9189. static void
  9190. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9191. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9192. {
  9193. struct lpfc_mbx_mq_create *mq_create;
  9194. struct lpfc_dmabuf *dmabuf;
  9195. int length;
  9196. length = (sizeof(struct lpfc_mbx_mq_create) -
  9197. sizeof(struct lpfc_sli4_cfg_mhdr));
  9198. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9199. LPFC_MBOX_OPCODE_MQ_CREATE,
  9200. length, LPFC_SLI4_MBX_EMBED);
  9201. mq_create = &mbox->u.mqe.un.mq_create;
  9202. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9203. mq->page_count);
  9204. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9205. cq->queue_id);
  9206. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9207. switch (mq->entry_count) {
  9208. case 16:
  9209. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9210. LPFC_MQ_CNT_16);
  9211. break;
  9212. case 32:
  9213. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9214. LPFC_MQ_CNT_32);
  9215. break;
  9216. case 64:
  9217. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9218. LPFC_MQ_CNT_64);
  9219. break;
  9220. case 128:
  9221. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9222. LPFC_MQ_CNT_128);
  9223. break;
  9224. }
  9225. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9226. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9227. putPaddrLow(dmabuf->phys);
  9228. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9229. putPaddrHigh(dmabuf->phys);
  9230. }
  9231. }
  9232. /**
  9233. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9234. * @phba: HBA structure that indicates port to create a queue on.
  9235. * @mq: The queue structure to use to create the mailbox queue.
  9236. * @cq: The completion queue to associate with this cq.
  9237. * @subtype: The queue's subtype.
  9238. *
  9239. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9240. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9241. *
  9242. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9243. * is used to get the entry count and entry size that are necessary to
  9244. * determine the number of pages to allocate and use for this queue. This
  9245. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9246. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9247. * command to finish before continuing.
  9248. *
  9249. * On success this function will return a zero. If unable to allocate enough
  9250. * memory this function will return -ENOMEM. If the queue create mailbox command
  9251. * fails this function will return -ENXIO.
  9252. **/
  9253. int32_t
  9254. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9255. struct lpfc_queue *cq, uint32_t subtype)
  9256. {
  9257. struct lpfc_mbx_mq_create *mq_create;
  9258. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9259. struct lpfc_dmabuf *dmabuf;
  9260. LPFC_MBOXQ_t *mbox;
  9261. int rc, length, status = 0;
  9262. uint32_t shdr_status, shdr_add_status;
  9263. union lpfc_sli4_cfg_shdr *shdr;
  9264. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9265. if (!phba->sli4_hba.pc_sli4_params.supported)
  9266. hw_page_size = SLI4_PAGE_SIZE;
  9267. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9268. if (!mbox)
  9269. return -ENOMEM;
  9270. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9271. sizeof(struct lpfc_sli4_cfg_mhdr));
  9272. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9273. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9274. length, LPFC_SLI4_MBX_EMBED);
  9275. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9276. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9277. mq->page_count);
  9278. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9279. 1);
  9280. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9281. &mq_create_ext->u.request, 1);
  9282. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9283. &mq_create_ext->u.request, 1);
  9284. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9285. cq->queue_id);
  9286. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9287. switch (mq->entry_count) {
  9288. default:
  9289. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9290. "0362 Unsupported MQ count. (%d)\n",
  9291. mq->entry_count);
  9292. if (mq->entry_count < 16)
  9293. return -EINVAL;
  9294. /* otherwise default to smallest count (drop through) */
  9295. case 16:
  9296. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9297. LPFC_MQ_CNT_16);
  9298. break;
  9299. case 32:
  9300. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9301. LPFC_MQ_CNT_32);
  9302. break;
  9303. case 64:
  9304. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9305. LPFC_MQ_CNT_64);
  9306. break;
  9307. case 128:
  9308. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9309. LPFC_MQ_CNT_128);
  9310. break;
  9311. }
  9312. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9313. memset(dmabuf->virt, 0, hw_page_size);
  9314. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9315. putPaddrLow(dmabuf->phys);
  9316. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9317. putPaddrHigh(dmabuf->phys);
  9318. }
  9319. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9320. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9321. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9322. &mq_create_ext->u.response);
  9323. if (rc != MBX_SUCCESS) {
  9324. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9325. "2795 MQ_CREATE_EXT failed with "
  9326. "status x%x. Failback to MQ_CREATE.\n",
  9327. rc);
  9328. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9329. mq_create = &mbox->u.mqe.un.mq_create;
  9330. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9331. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9332. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9333. &mq_create->u.response);
  9334. }
  9335. /* The IOCTL status is embedded in the mailbox subheader. */
  9336. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9337. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9338. if (shdr_status || shdr_add_status || rc) {
  9339. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9340. "2502 MQ_CREATE mailbox failed with "
  9341. "status x%x add_status x%x, mbx status x%x\n",
  9342. shdr_status, shdr_add_status, rc);
  9343. status = -ENXIO;
  9344. goto out;
  9345. }
  9346. if (mq->queue_id == 0xFFFF) {
  9347. status = -ENXIO;
  9348. goto out;
  9349. }
  9350. mq->type = LPFC_MQ;
  9351. mq->subtype = subtype;
  9352. mq->host_index = 0;
  9353. mq->hba_index = 0;
  9354. /* link the mq onto the parent cq child list */
  9355. list_add_tail(&mq->list, &cq->child_list);
  9356. out:
  9357. mempool_free(mbox, phba->mbox_mem_pool);
  9358. return status;
  9359. }
  9360. /**
  9361. * lpfc_wq_create - Create a Work Queue on the HBA
  9362. * @phba: HBA structure that indicates port to create a queue on.
  9363. * @wq: The queue structure to use to create the work queue.
  9364. * @cq: The completion queue to bind this work queue to.
  9365. * @subtype: The subtype of the work queue indicating its functionality.
  9366. *
  9367. * This function creates a work queue, as detailed in @wq, on a port, described
  9368. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9369. *
  9370. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9371. * is used to get the entry count and entry size that are necessary to
  9372. * determine the number of pages to allocate and use for this queue. The @cq
  9373. * is used to indicate which completion queue to bind this work queue to. This
  9374. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9375. * work queue. This function is asynchronous and will wait for the mailbox
  9376. * command to finish before continuing.
  9377. *
  9378. * On success this function will return a zero. If unable to allocate enough
  9379. * memory this function will return -ENOMEM. If the queue create mailbox command
  9380. * fails this function will return -ENXIO.
  9381. **/
  9382. uint32_t
  9383. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9384. struct lpfc_queue *cq, uint32_t subtype)
  9385. {
  9386. struct lpfc_mbx_wq_create *wq_create;
  9387. struct lpfc_dmabuf *dmabuf;
  9388. LPFC_MBOXQ_t *mbox;
  9389. int rc, length, status = 0;
  9390. uint32_t shdr_status, shdr_add_status;
  9391. union lpfc_sli4_cfg_shdr *shdr;
  9392. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9393. if (!phba->sli4_hba.pc_sli4_params.supported)
  9394. hw_page_size = SLI4_PAGE_SIZE;
  9395. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9396. if (!mbox)
  9397. return -ENOMEM;
  9398. length = (sizeof(struct lpfc_mbx_wq_create) -
  9399. sizeof(struct lpfc_sli4_cfg_mhdr));
  9400. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9401. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9402. length, LPFC_SLI4_MBX_EMBED);
  9403. wq_create = &mbox->u.mqe.un.wq_create;
  9404. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9405. wq->page_count);
  9406. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9407. cq->queue_id);
  9408. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9409. memset(dmabuf->virt, 0, hw_page_size);
  9410. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9411. putPaddrLow(dmabuf->phys);
  9412. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9413. putPaddrHigh(dmabuf->phys);
  9414. }
  9415. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9416. /* The IOCTL status is embedded in the mailbox subheader. */
  9417. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9418. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9419. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9420. if (shdr_status || shdr_add_status || rc) {
  9421. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9422. "2503 WQ_CREATE mailbox failed with "
  9423. "status x%x add_status x%x, mbx status x%x\n",
  9424. shdr_status, shdr_add_status, rc);
  9425. status = -ENXIO;
  9426. goto out;
  9427. }
  9428. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9429. if (wq->queue_id == 0xFFFF) {
  9430. status = -ENXIO;
  9431. goto out;
  9432. }
  9433. wq->type = LPFC_WQ;
  9434. wq->subtype = subtype;
  9435. wq->host_index = 0;
  9436. wq->hba_index = 0;
  9437. /* link the wq onto the parent cq child list */
  9438. list_add_tail(&wq->list, &cq->child_list);
  9439. out:
  9440. mempool_free(mbox, phba->mbox_mem_pool);
  9441. return status;
  9442. }
  9443. /**
  9444. * lpfc_rq_create - Create a Receive Queue on the HBA
  9445. * @phba: HBA structure that indicates port to create a queue on.
  9446. * @hrq: The queue structure to use to create the header receive queue.
  9447. * @drq: The queue structure to use to create the data receive queue.
  9448. * @cq: The completion queue to bind this work queue to.
  9449. *
  9450. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9451. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9452. * to the HBA.
  9453. *
  9454. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9455. * struct is used to get the entry count that is necessary to determine the
  9456. * number of pages to use for this queue. The @cq is used to indicate which
  9457. * completion queue to bind received buffers that are posted to these queues to.
  9458. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9459. * receive queue pair. This function is asynchronous and will wait for the
  9460. * mailbox command to finish before continuing.
  9461. *
  9462. * On success this function will return a zero. If unable to allocate enough
  9463. * memory this function will return -ENOMEM. If the queue create mailbox command
  9464. * fails this function will return -ENXIO.
  9465. **/
  9466. uint32_t
  9467. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9468. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9469. {
  9470. struct lpfc_mbx_rq_create *rq_create;
  9471. struct lpfc_dmabuf *dmabuf;
  9472. LPFC_MBOXQ_t *mbox;
  9473. int rc, length, status = 0;
  9474. uint32_t shdr_status, shdr_add_status;
  9475. union lpfc_sli4_cfg_shdr *shdr;
  9476. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9477. if (!phba->sli4_hba.pc_sli4_params.supported)
  9478. hw_page_size = SLI4_PAGE_SIZE;
  9479. if (hrq->entry_count != drq->entry_count)
  9480. return -EINVAL;
  9481. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9482. if (!mbox)
  9483. return -ENOMEM;
  9484. length = (sizeof(struct lpfc_mbx_rq_create) -
  9485. sizeof(struct lpfc_sli4_cfg_mhdr));
  9486. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9487. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9488. length, LPFC_SLI4_MBX_EMBED);
  9489. rq_create = &mbox->u.mqe.un.rq_create;
  9490. switch (hrq->entry_count) {
  9491. default:
  9492. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9493. "2535 Unsupported RQ count. (%d)\n",
  9494. hrq->entry_count);
  9495. if (hrq->entry_count < 512)
  9496. return -EINVAL;
  9497. /* otherwise default to smallest count (drop through) */
  9498. case 512:
  9499. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9500. LPFC_RQ_RING_SIZE_512);
  9501. break;
  9502. case 1024:
  9503. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9504. LPFC_RQ_RING_SIZE_1024);
  9505. break;
  9506. case 2048:
  9507. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9508. LPFC_RQ_RING_SIZE_2048);
  9509. break;
  9510. case 4096:
  9511. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9512. LPFC_RQ_RING_SIZE_4096);
  9513. break;
  9514. }
  9515. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9516. cq->queue_id);
  9517. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9518. hrq->page_count);
  9519. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9520. LPFC_HDR_BUF_SIZE);
  9521. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9522. memset(dmabuf->virt, 0, hw_page_size);
  9523. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9524. putPaddrLow(dmabuf->phys);
  9525. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9526. putPaddrHigh(dmabuf->phys);
  9527. }
  9528. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9529. /* The IOCTL status is embedded in the mailbox subheader. */
  9530. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9531. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9532. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9533. if (shdr_status || shdr_add_status || rc) {
  9534. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9535. "2504 RQ_CREATE mailbox failed with "
  9536. "status x%x add_status x%x, mbx status x%x\n",
  9537. shdr_status, shdr_add_status, rc);
  9538. status = -ENXIO;
  9539. goto out;
  9540. }
  9541. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9542. if (hrq->queue_id == 0xFFFF) {
  9543. status = -ENXIO;
  9544. goto out;
  9545. }
  9546. hrq->type = LPFC_HRQ;
  9547. hrq->subtype = subtype;
  9548. hrq->host_index = 0;
  9549. hrq->hba_index = 0;
  9550. /* now create the data queue */
  9551. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9552. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9553. length, LPFC_SLI4_MBX_EMBED);
  9554. switch (drq->entry_count) {
  9555. default:
  9556. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9557. "2536 Unsupported RQ count. (%d)\n",
  9558. drq->entry_count);
  9559. if (drq->entry_count < 512)
  9560. return -EINVAL;
  9561. /* otherwise default to smallest count (drop through) */
  9562. case 512:
  9563. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9564. LPFC_RQ_RING_SIZE_512);
  9565. break;
  9566. case 1024:
  9567. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9568. LPFC_RQ_RING_SIZE_1024);
  9569. break;
  9570. case 2048:
  9571. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9572. LPFC_RQ_RING_SIZE_2048);
  9573. break;
  9574. case 4096:
  9575. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9576. LPFC_RQ_RING_SIZE_4096);
  9577. break;
  9578. }
  9579. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9580. cq->queue_id);
  9581. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9582. drq->page_count);
  9583. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9584. LPFC_DATA_BUF_SIZE);
  9585. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9586. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9587. putPaddrLow(dmabuf->phys);
  9588. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9589. putPaddrHigh(dmabuf->phys);
  9590. }
  9591. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9592. /* The IOCTL status is embedded in the mailbox subheader. */
  9593. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9594. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9595. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9596. if (shdr_status || shdr_add_status || rc) {
  9597. status = -ENXIO;
  9598. goto out;
  9599. }
  9600. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9601. if (drq->queue_id == 0xFFFF) {
  9602. status = -ENXIO;
  9603. goto out;
  9604. }
  9605. drq->type = LPFC_DRQ;
  9606. drq->subtype = subtype;
  9607. drq->host_index = 0;
  9608. drq->hba_index = 0;
  9609. /* link the header and data RQs onto the parent cq child list */
  9610. list_add_tail(&hrq->list, &cq->child_list);
  9611. list_add_tail(&drq->list, &cq->child_list);
  9612. out:
  9613. mempool_free(mbox, phba->mbox_mem_pool);
  9614. return status;
  9615. }
  9616. /**
  9617. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9618. * @eq: The queue structure associated with the queue to destroy.
  9619. *
  9620. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9621. * command, specific to the type of queue, to the HBA.
  9622. *
  9623. * The @eq struct is used to get the queue ID of the queue to destroy.
  9624. *
  9625. * On success this function will return a zero. If the queue destroy mailbox
  9626. * command fails this function will return -ENXIO.
  9627. **/
  9628. uint32_t
  9629. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9630. {
  9631. LPFC_MBOXQ_t *mbox;
  9632. int rc, length, status = 0;
  9633. uint32_t shdr_status, shdr_add_status;
  9634. union lpfc_sli4_cfg_shdr *shdr;
  9635. if (!eq)
  9636. return -ENODEV;
  9637. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9638. if (!mbox)
  9639. return -ENOMEM;
  9640. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9641. sizeof(struct lpfc_sli4_cfg_mhdr));
  9642. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9643. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9644. length, LPFC_SLI4_MBX_EMBED);
  9645. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9646. eq->queue_id);
  9647. mbox->vport = eq->phba->pport;
  9648. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9649. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9650. /* The IOCTL status is embedded in the mailbox subheader. */
  9651. shdr = (union lpfc_sli4_cfg_shdr *)
  9652. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9653. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9654. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9655. if (shdr_status || shdr_add_status || rc) {
  9656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9657. "2505 EQ_DESTROY mailbox failed with "
  9658. "status x%x add_status x%x, mbx status x%x\n",
  9659. shdr_status, shdr_add_status, rc);
  9660. status = -ENXIO;
  9661. }
  9662. /* Remove eq from any list */
  9663. list_del_init(&eq->list);
  9664. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9665. return status;
  9666. }
  9667. /**
  9668. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9669. * @cq: The queue structure associated with the queue to destroy.
  9670. *
  9671. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9672. * command, specific to the type of queue, to the HBA.
  9673. *
  9674. * The @cq struct is used to get the queue ID of the queue to destroy.
  9675. *
  9676. * On success this function will return a zero. If the queue destroy mailbox
  9677. * command fails this function will return -ENXIO.
  9678. **/
  9679. uint32_t
  9680. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9681. {
  9682. LPFC_MBOXQ_t *mbox;
  9683. int rc, length, status = 0;
  9684. uint32_t shdr_status, shdr_add_status;
  9685. union lpfc_sli4_cfg_shdr *shdr;
  9686. if (!cq)
  9687. return -ENODEV;
  9688. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9689. if (!mbox)
  9690. return -ENOMEM;
  9691. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9692. sizeof(struct lpfc_sli4_cfg_mhdr));
  9693. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9694. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9695. length, LPFC_SLI4_MBX_EMBED);
  9696. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9697. cq->queue_id);
  9698. mbox->vport = cq->phba->pport;
  9699. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9700. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9701. /* The IOCTL status is embedded in the mailbox subheader. */
  9702. shdr = (union lpfc_sli4_cfg_shdr *)
  9703. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9704. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9705. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9706. if (shdr_status || shdr_add_status || rc) {
  9707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9708. "2506 CQ_DESTROY mailbox failed with "
  9709. "status x%x add_status x%x, mbx status x%x\n",
  9710. shdr_status, shdr_add_status, rc);
  9711. status = -ENXIO;
  9712. }
  9713. /* Remove cq from any list */
  9714. list_del_init(&cq->list);
  9715. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9716. return status;
  9717. }
  9718. /**
  9719. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9720. * @qm: The queue structure associated with the queue to destroy.
  9721. *
  9722. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9723. * command, specific to the type of queue, to the HBA.
  9724. *
  9725. * The @mq struct is used to get the queue ID of the queue to destroy.
  9726. *
  9727. * On success this function will return a zero. If the queue destroy mailbox
  9728. * command fails this function will return -ENXIO.
  9729. **/
  9730. uint32_t
  9731. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9732. {
  9733. LPFC_MBOXQ_t *mbox;
  9734. int rc, length, status = 0;
  9735. uint32_t shdr_status, shdr_add_status;
  9736. union lpfc_sli4_cfg_shdr *shdr;
  9737. if (!mq)
  9738. return -ENODEV;
  9739. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9740. if (!mbox)
  9741. return -ENOMEM;
  9742. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9743. sizeof(struct lpfc_sli4_cfg_mhdr));
  9744. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9745. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9746. length, LPFC_SLI4_MBX_EMBED);
  9747. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9748. mq->queue_id);
  9749. mbox->vport = mq->phba->pport;
  9750. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9751. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9752. /* The IOCTL status is embedded in the mailbox subheader. */
  9753. shdr = (union lpfc_sli4_cfg_shdr *)
  9754. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9755. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9756. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9757. if (shdr_status || shdr_add_status || rc) {
  9758. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9759. "2507 MQ_DESTROY mailbox failed with "
  9760. "status x%x add_status x%x, mbx status x%x\n",
  9761. shdr_status, shdr_add_status, rc);
  9762. status = -ENXIO;
  9763. }
  9764. /* Remove mq from any list */
  9765. list_del_init(&mq->list);
  9766. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9767. return status;
  9768. }
  9769. /**
  9770. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9771. * @wq: The queue structure associated with the queue to destroy.
  9772. *
  9773. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9774. * command, specific to the type of queue, to the HBA.
  9775. *
  9776. * The @wq struct is used to get the queue ID of the queue to destroy.
  9777. *
  9778. * On success this function will return a zero. If the queue destroy mailbox
  9779. * command fails this function will return -ENXIO.
  9780. **/
  9781. uint32_t
  9782. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9783. {
  9784. LPFC_MBOXQ_t *mbox;
  9785. int rc, length, status = 0;
  9786. uint32_t shdr_status, shdr_add_status;
  9787. union lpfc_sli4_cfg_shdr *shdr;
  9788. if (!wq)
  9789. return -ENODEV;
  9790. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9791. if (!mbox)
  9792. return -ENOMEM;
  9793. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9794. sizeof(struct lpfc_sli4_cfg_mhdr));
  9795. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9796. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9797. length, LPFC_SLI4_MBX_EMBED);
  9798. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9799. wq->queue_id);
  9800. mbox->vport = wq->phba->pport;
  9801. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9802. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9803. shdr = (union lpfc_sli4_cfg_shdr *)
  9804. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9805. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9806. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9807. if (shdr_status || shdr_add_status || rc) {
  9808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9809. "2508 WQ_DESTROY mailbox failed with "
  9810. "status x%x add_status x%x, mbx status x%x\n",
  9811. shdr_status, shdr_add_status, rc);
  9812. status = -ENXIO;
  9813. }
  9814. /* Remove wq from any list */
  9815. list_del_init(&wq->list);
  9816. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9817. return status;
  9818. }
  9819. /**
  9820. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9821. * @rq: The queue structure associated with the queue to destroy.
  9822. *
  9823. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9824. * command, specific to the type of queue, to the HBA.
  9825. *
  9826. * The @rq struct is used to get the queue ID of the queue to destroy.
  9827. *
  9828. * On success this function will return a zero. If the queue destroy mailbox
  9829. * command fails this function will return -ENXIO.
  9830. **/
  9831. uint32_t
  9832. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9833. struct lpfc_queue *drq)
  9834. {
  9835. LPFC_MBOXQ_t *mbox;
  9836. int rc, length, status = 0;
  9837. uint32_t shdr_status, shdr_add_status;
  9838. union lpfc_sli4_cfg_shdr *shdr;
  9839. if (!hrq || !drq)
  9840. return -ENODEV;
  9841. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9842. if (!mbox)
  9843. return -ENOMEM;
  9844. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9845. sizeof(struct mbox_header));
  9846. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9847. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9848. length, LPFC_SLI4_MBX_EMBED);
  9849. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9850. hrq->queue_id);
  9851. mbox->vport = hrq->phba->pport;
  9852. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9853. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9854. /* The IOCTL status is embedded in the mailbox subheader. */
  9855. shdr = (union lpfc_sli4_cfg_shdr *)
  9856. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9857. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9858. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9859. if (shdr_status || shdr_add_status || rc) {
  9860. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9861. "2509 RQ_DESTROY mailbox failed with "
  9862. "status x%x add_status x%x, mbx status x%x\n",
  9863. shdr_status, shdr_add_status, rc);
  9864. if (rc != MBX_TIMEOUT)
  9865. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9866. return -ENXIO;
  9867. }
  9868. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9869. drq->queue_id);
  9870. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9871. shdr = (union lpfc_sli4_cfg_shdr *)
  9872. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9873. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9874. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9875. if (shdr_status || shdr_add_status || rc) {
  9876. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9877. "2510 RQ_DESTROY mailbox failed with "
  9878. "status x%x add_status x%x, mbx status x%x\n",
  9879. shdr_status, shdr_add_status, rc);
  9880. status = -ENXIO;
  9881. }
  9882. list_del_init(&hrq->list);
  9883. list_del_init(&drq->list);
  9884. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9885. return status;
  9886. }
  9887. /**
  9888. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9889. * @phba: The virtual port for which this call being executed.
  9890. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9891. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9892. * @xritag: the xritag that ties this io to the SGL pages.
  9893. *
  9894. * This routine will post the sgl pages for the IO that has the xritag
  9895. * that is in the iocbq structure. The xritag is assigned during iocbq
  9896. * creation and persists for as long as the driver is loaded.
  9897. * if the caller has fewer than 256 scatter gather segments to map then
  9898. * pdma_phys_addr1 should be 0.
  9899. * If the caller needs to map more than 256 scatter gather segment then
  9900. * pdma_phys_addr1 should be a valid physical address.
  9901. * physical address for SGLs must be 64 byte aligned.
  9902. * If you are going to map 2 SGL's then the first one must have 256 entries
  9903. * the second sgl can have between 1 and 256 entries.
  9904. *
  9905. * Return codes:
  9906. * 0 - Success
  9907. * -ENXIO, -ENOMEM - Failure
  9908. **/
  9909. int
  9910. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9911. dma_addr_t pdma_phys_addr0,
  9912. dma_addr_t pdma_phys_addr1,
  9913. uint16_t xritag)
  9914. {
  9915. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9916. LPFC_MBOXQ_t *mbox;
  9917. int rc;
  9918. uint32_t shdr_status, shdr_add_status;
  9919. union lpfc_sli4_cfg_shdr *shdr;
  9920. if (xritag == NO_XRI) {
  9921. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9922. "0364 Invalid param:\n");
  9923. return -EINVAL;
  9924. }
  9925. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9926. if (!mbox)
  9927. return -ENOMEM;
  9928. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9929. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9930. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9931. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9932. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9933. &mbox->u.mqe.un.post_sgl_pages;
  9934. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9935. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9936. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9937. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9938. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9939. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9940. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9941. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9942. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9943. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9944. if (!phba->sli4_hba.intr_enable)
  9945. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9946. else
  9947. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9948. /* The IOCTL status is embedded in the mailbox subheader. */
  9949. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9950. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9951. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9952. if (rc != MBX_TIMEOUT)
  9953. mempool_free(mbox, phba->mbox_mem_pool);
  9954. if (shdr_status || shdr_add_status || rc) {
  9955. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9956. "2511 POST_SGL mailbox failed with "
  9957. "status x%x add_status x%x, mbx status x%x\n",
  9958. shdr_status, shdr_add_status, rc);
  9959. rc = -ENXIO;
  9960. }
  9961. return 0;
  9962. }
  9963. /**
  9964. * lpfc_sli4_next_xritag - Get an xritag for the io
  9965. * @phba: Pointer to HBA context object.
  9966. *
  9967. * This function gets an xritag for the iocb. If there is no unused xritag
  9968. * it will return 0xffff.
  9969. * The function returns the allocated xritag if successful, else returns zero.
  9970. * Zero is not a valid xritag.
  9971. * The caller is not required to hold any lock.
  9972. **/
  9973. uint16_t
  9974. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9975. {
  9976. uint16_t xritag;
  9977. spin_lock_irq(&phba->hbalock);
  9978. xritag = phba->sli4_hba.next_xri;
  9979. if ((xritag != (uint16_t) -1) && xritag <
  9980. (phba->sli4_hba.max_cfg_param.max_xri
  9981. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9982. phba->sli4_hba.next_xri++;
  9983. phba->sli4_hba.max_cfg_param.xri_used++;
  9984. spin_unlock_irq(&phba->hbalock);
  9985. return xritag;
  9986. }
  9987. spin_unlock_irq(&phba->hbalock);
  9988. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9989. "2004 Failed to allocate XRI.last XRITAG is %d"
  9990. " Max XRI is %d, Used XRI is %d\n",
  9991. phba->sli4_hba.next_xri,
  9992. phba->sli4_hba.max_cfg_param.max_xri,
  9993. phba->sli4_hba.max_cfg_param.xri_used);
  9994. return -1;
  9995. }
  9996. /**
  9997. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9998. * @phba: pointer to lpfc hba data structure.
  9999. *
  10000. * This routine is invoked to post a block of driver's sgl pages to the
  10001. * HBA using non-embedded mailbox command. No Lock is held. This routine
  10002. * is only called when the driver is loading and after all IO has been
  10003. * stopped.
  10004. **/
  10005. int
  10006. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  10007. {
  10008. struct lpfc_sglq *sglq_entry;
  10009. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10010. struct sgl_page_pairs *sgl_pg_pairs;
  10011. void *viraddr;
  10012. LPFC_MBOXQ_t *mbox;
  10013. uint32_t reqlen, alloclen, pg_pairs;
  10014. uint32_t mbox_tmo;
  10015. uint16_t xritag_start = 0;
  10016. int els_xri_cnt, rc = 0;
  10017. uint32_t shdr_status, shdr_add_status;
  10018. union lpfc_sli4_cfg_shdr *shdr;
  10019. /* The number of sgls to be posted */
  10020. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  10021. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  10022. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10023. if (reqlen > SLI4_PAGE_SIZE) {
  10024. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10025. "2559 Block sgl registration required DMA "
  10026. "size (%d) great than a page\n", reqlen);
  10027. return -ENOMEM;
  10028. }
  10029. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10030. if (!mbox) {
  10031. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10032. "2560 Failed to allocate mbox cmd memory\n");
  10033. return -ENOMEM;
  10034. }
  10035. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10036. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10037. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10038. LPFC_SLI4_MBX_NEMBED);
  10039. if (alloclen < reqlen) {
  10040. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10041. "0285 Allocated DMA memory size (%d) is "
  10042. "less than the requested DMA memory "
  10043. "size (%d)\n", alloclen, reqlen);
  10044. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10045. return -ENOMEM;
  10046. }
  10047. /* Get the first SGE entry from the non-embedded DMA memory */
  10048. viraddr = mbox->sge_array->addr[0];
  10049. /* Set up the SGL pages in the non-embedded DMA pages */
  10050. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10051. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10052. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10053. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10054. /* Set up the sge entry */
  10055. sgl_pg_pairs->sgl_pg0_addr_lo =
  10056. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10057. sgl_pg_pairs->sgl_pg0_addr_hi =
  10058. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10059. sgl_pg_pairs->sgl_pg1_addr_lo =
  10060. cpu_to_le32(putPaddrLow(0));
  10061. sgl_pg_pairs->sgl_pg1_addr_hi =
  10062. cpu_to_le32(putPaddrHigh(0));
  10063. /* Keep the first xritag on the list */
  10064. if (pg_pairs == 0)
  10065. xritag_start = sglq_entry->sli4_xritag;
  10066. sgl_pg_pairs++;
  10067. }
  10068. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10069. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10070. /* Perform endian conversion if necessary */
  10071. sgl->word0 = cpu_to_le32(sgl->word0);
  10072. if (!phba->sli4_hba.intr_enable)
  10073. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10074. else {
  10075. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10076. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10077. }
  10078. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10079. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10080. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10081. if (rc != MBX_TIMEOUT)
  10082. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10083. if (shdr_status || shdr_add_status || rc) {
  10084. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10085. "2513 POST_SGL_BLOCK mailbox command failed "
  10086. "status x%x add_status x%x mbx status x%x\n",
  10087. shdr_status, shdr_add_status, rc);
  10088. rc = -ENXIO;
  10089. }
  10090. return rc;
  10091. }
  10092. /**
  10093. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10094. * @phba: pointer to lpfc hba data structure.
  10095. * @sblist: pointer to scsi buffer list.
  10096. * @count: number of scsi buffers on the list.
  10097. *
  10098. * This routine is invoked to post a block of @count scsi sgl pages from a
  10099. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10100. * No Lock is held.
  10101. *
  10102. **/
  10103. int
  10104. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10105. int cnt)
  10106. {
  10107. struct lpfc_scsi_buf *psb;
  10108. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10109. struct sgl_page_pairs *sgl_pg_pairs;
  10110. void *viraddr;
  10111. LPFC_MBOXQ_t *mbox;
  10112. uint32_t reqlen, alloclen, pg_pairs;
  10113. uint32_t mbox_tmo;
  10114. uint16_t xritag_start = 0;
  10115. int rc = 0;
  10116. uint32_t shdr_status, shdr_add_status;
  10117. dma_addr_t pdma_phys_bpl1;
  10118. union lpfc_sli4_cfg_shdr *shdr;
  10119. /* Calculate the requested length of the dma memory */
  10120. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10121. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10122. if (reqlen > SLI4_PAGE_SIZE) {
  10123. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10124. "0217 Block sgl registration required DMA "
  10125. "size (%d) great than a page\n", reqlen);
  10126. return -ENOMEM;
  10127. }
  10128. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10129. if (!mbox) {
  10130. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10131. "0283 Failed to allocate mbox cmd memory\n");
  10132. return -ENOMEM;
  10133. }
  10134. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10135. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10136. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10137. LPFC_SLI4_MBX_NEMBED);
  10138. if (alloclen < reqlen) {
  10139. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10140. "2561 Allocated DMA memory size (%d) is "
  10141. "less than the requested DMA memory "
  10142. "size (%d)\n", alloclen, reqlen);
  10143. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10144. return -ENOMEM;
  10145. }
  10146. /* Get the first SGE entry from the non-embedded DMA memory */
  10147. viraddr = mbox->sge_array->addr[0];
  10148. /* Set up the SGL pages in the non-embedded DMA pages */
  10149. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10150. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10151. pg_pairs = 0;
  10152. list_for_each_entry(psb, sblist, list) {
  10153. /* Set up the sge entry */
  10154. sgl_pg_pairs->sgl_pg0_addr_lo =
  10155. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10156. sgl_pg_pairs->sgl_pg0_addr_hi =
  10157. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10158. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10159. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10160. else
  10161. pdma_phys_bpl1 = 0;
  10162. sgl_pg_pairs->sgl_pg1_addr_lo =
  10163. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10164. sgl_pg_pairs->sgl_pg1_addr_hi =
  10165. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10166. /* Keep the first xritag on the list */
  10167. if (pg_pairs == 0)
  10168. xritag_start = psb->cur_iocbq.sli4_xritag;
  10169. sgl_pg_pairs++;
  10170. pg_pairs++;
  10171. }
  10172. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10173. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10174. /* Perform endian conversion if necessary */
  10175. sgl->word0 = cpu_to_le32(sgl->word0);
  10176. if (!phba->sli4_hba.intr_enable)
  10177. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10178. else {
  10179. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10180. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10181. }
  10182. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10183. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10184. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10185. if (rc != MBX_TIMEOUT)
  10186. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10187. if (shdr_status || shdr_add_status || rc) {
  10188. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10189. "2564 POST_SGL_BLOCK mailbox command failed "
  10190. "status x%x add_status x%x mbx status x%x\n",
  10191. shdr_status, shdr_add_status, rc);
  10192. rc = -ENXIO;
  10193. }
  10194. return rc;
  10195. }
  10196. /**
  10197. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10198. * @phba: pointer to lpfc_hba struct that the frame was received on
  10199. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10200. *
  10201. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10202. * valid type of frame that the LPFC driver will handle. This function will
  10203. * return a zero if the frame is a valid frame or a non zero value when the
  10204. * frame does not pass the check.
  10205. **/
  10206. static int
  10207. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10208. {
  10209. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10210. char *type_names[] = FC_TYPE_NAMES_INIT;
  10211. struct fc_vft_header *fc_vft_hdr;
  10212. switch (fc_hdr->fh_r_ctl) {
  10213. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10214. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10215. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10216. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10217. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10218. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10219. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10220. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10221. case FC_RCTL_ELS_REQ: /* extended link services request */
  10222. case FC_RCTL_ELS_REP: /* extended link services reply */
  10223. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10224. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10225. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10226. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10227. case FC_RCTL_BA_RMC: /* remove connection */
  10228. case FC_RCTL_BA_ACC: /* basic accept */
  10229. case FC_RCTL_BA_RJT: /* basic reject */
  10230. case FC_RCTL_BA_PRMT:
  10231. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10232. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10233. case FC_RCTL_P_RJT: /* port reject */
  10234. case FC_RCTL_F_RJT: /* fabric reject */
  10235. case FC_RCTL_P_BSY: /* port busy */
  10236. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10237. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10238. case FC_RCTL_LCR: /* link credit reset */
  10239. case FC_RCTL_END: /* end */
  10240. break;
  10241. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10242. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10243. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10244. return lpfc_fc_frame_check(phba, fc_hdr);
  10245. default:
  10246. goto drop;
  10247. }
  10248. switch (fc_hdr->fh_type) {
  10249. case FC_TYPE_BLS:
  10250. case FC_TYPE_ELS:
  10251. case FC_TYPE_FCP:
  10252. case FC_TYPE_CT:
  10253. break;
  10254. case FC_TYPE_IP:
  10255. case FC_TYPE_ILS:
  10256. default:
  10257. goto drop;
  10258. }
  10259. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10260. "2538 Received frame rctl:%s type:%s\n",
  10261. rctl_names[fc_hdr->fh_r_ctl],
  10262. type_names[fc_hdr->fh_type]);
  10263. return 0;
  10264. drop:
  10265. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10266. "2539 Dropped frame rctl:%s type:%s\n",
  10267. rctl_names[fc_hdr->fh_r_ctl],
  10268. type_names[fc_hdr->fh_type]);
  10269. return 1;
  10270. }
  10271. /**
  10272. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10273. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10274. *
  10275. * This function processes the FC header to retrieve the VFI from the VF
  10276. * header, if one exists. This function will return the VFI if one exists
  10277. * or 0 if no VSAN Header exists.
  10278. **/
  10279. static uint32_t
  10280. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10281. {
  10282. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10283. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10284. return 0;
  10285. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10286. }
  10287. /**
  10288. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10289. * @phba: Pointer to the HBA structure to search for the vport on
  10290. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10291. * @fcfi: The FC Fabric ID that the frame came from
  10292. *
  10293. * This function searches the @phba for a vport that matches the content of the
  10294. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10295. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10296. * returns the matching vport pointer or NULL if unable to match frame to a
  10297. * vport.
  10298. **/
  10299. static struct lpfc_vport *
  10300. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10301. uint16_t fcfi)
  10302. {
  10303. struct lpfc_vport **vports;
  10304. struct lpfc_vport *vport = NULL;
  10305. int i;
  10306. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10307. fc_hdr->fh_d_id[1] << 8 |
  10308. fc_hdr->fh_d_id[2]);
  10309. vports = lpfc_create_vport_work_array(phba);
  10310. if (vports != NULL)
  10311. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10312. if (phba->fcf.fcfi == fcfi &&
  10313. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10314. vports[i]->fc_myDID == did) {
  10315. vport = vports[i];
  10316. break;
  10317. }
  10318. }
  10319. lpfc_destroy_vport_work_array(phba, vports);
  10320. return vport;
  10321. }
  10322. /**
  10323. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10324. * @vport: The vport to work on.
  10325. *
  10326. * This function updates the receive sequence time stamp for this vport. The
  10327. * receive sequence time stamp indicates the time that the last frame of the
  10328. * the sequence that has been idle for the longest amount of time was received.
  10329. * the driver uses this time stamp to indicate if any received sequences have
  10330. * timed out.
  10331. **/
  10332. void
  10333. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10334. {
  10335. struct lpfc_dmabuf *h_buf;
  10336. struct hbq_dmabuf *dmabuf = NULL;
  10337. /* get the oldest sequence on the rcv list */
  10338. h_buf = list_get_first(&vport->rcv_buffer_list,
  10339. struct lpfc_dmabuf, list);
  10340. if (!h_buf)
  10341. return;
  10342. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10343. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10344. }
  10345. /**
  10346. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10347. * @vport: The vport that the received sequences were sent to.
  10348. *
  10349. * This function cleans up all outstanding received sequences. This is called
  10350. * by the driver when a link event or user action invalidates all the received
  10351. * sequences.
  10352. **/
  10353. void
  10354. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10355. {
  10356. struct lpfc_dmabuf *h_buf, *hnext;
  10357. struct lpfc_dmabuf *d_buf, *dnext;
  10358. struct hbq_dmabuf *dmabuf = NULL;
  10359. /* start with the oldest sequence on the rcv list */
  10360. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10361. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10362. list_del_init(&dmabuf->hbuf.list);
  10363. list_for_each_entry_safe(d_buf, dnext,
  10364. &dmabuf->dbuf.list, list) {
  10365. list_del_init(&d_buf->list);
  10366. lpfc_in_buf_free(vport->phba, d_buf);
  10367. }
  10368. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10369. }
  10370. }
  10371. /**
  10372. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10373. * @vport: The vport that the received sequences were sent to.
  10374. *
  10375. * This function determines whether any received sequences have timed out by
  10376. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10377. * indicates that there is at least one timed out sequence this routine will
  10378. * go through the received sequences one at a time from most inactive to most
  10379. * active to determine which ones need to be cleaned up. Once it has determined
  10380. * that a sequence needs to be cleaned up it will simply free up the resources
  10381. * without sending an abort.
  10382. **/
  10383. void
  10384. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10385. {
  10386. struct lpfc_dmabuf *h_buf, *hnext;
  10387. struct lpfc_dmabuf *d_buf, *dnext;
  10388. struct hbq_dmabuf *dmabuf = NULL;
  10389. unsigned long timeout;
  10390. int abort_count = 0;
  10391. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10392. vport->rcv_buffer_time_stamp);
  10393. if (list_empty(&vport->rcv_buffer_list) ||
  10394. time_before(jiffies, timeout))
  10395. return;
  10396. /* start with the oldest sequence on the rcv list */
  10397. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10398. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10399. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10400. dmabuf->time_stamp);
  10401. if (time_before(jiffies, timeout))
  10402. break;
  10403. abort_count++;
  10404. list_del_init(&dmabuf->hbuf.list);
  10405. list_for_each_entry_safe(d_buf, dnext,
  10406. &dmabuf->dbuf.list, list) {
  10407. list_del_init(&d_buf->list);
  10408. lpfc_in_buf_free(vport->phba, d_buf);
  10409. }
  10410. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10411. }
  10412. if (abort_count)
  10413. lpfc_update_rcv_time_stamp(vport);
  10414. }
  10415. /**
  10416. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10417. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10418. *
  10419. * This function searches through the existing incomplete sequences that have
  10420. * been sent to this @vport. If the frame matches one of the incomplete
  10421. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10422. * make up that sequence. If no sequence is found that matches this frame then
  10423. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10424. * This function returns a pointer to the first dmabuf in the sequence list that
  10425. * the frame was linked to.
  10426. **/
  10427. static struct hbq_dmabuf *
  10428. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10429. {
  10430. struct fc_frame_header *new_hdr;
  10431. struct fc_frame_header *temp_hdr;
  10432. struct lpfc_dmabuf *d_buf;
  10433. struct lpfc_dmabuf *h_buf;
  10434. struct hbq_dmabuf *seq_dmabuf = NULL;
  10435. struct hbq_dmabuf *temp_dmabuf = NULL;
  10436. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10437. dmabuf->time_stamp = jiffies;
  10438. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10439. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10440. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10441. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10442. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10443. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10444. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10445. continue;
  10446. /* found a pending sequence that matches this frame */
  10447. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10448. break;
  10449. }
  10450. if (!seq_dmabuf) {
  10451. /*
  10452. * This indicates first frame received for this sequence.
  10453. * Queue the buffer on the vport's rcv_buffer_list.
  10454. */
  10455. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10456. lpfc_update_rcv_time_stamp(vport);
  10457. return dmabuf;
  10458. }
  10459. temp_hdr = seq_dmabuf->hbuf.virt;
  10460. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10461. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10462. list_del_init(&seq_dmabuf->hbuf.list);
  10463. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10464. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10465. lpfc_update_rcv_time_stamp(vport);
  10466. return dmabuf;
  10467. }
  10468. /* move this sequence to the tail to indicate a young sequence */
  10469. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10470. seq_dmabuf->time_stamp = jiffies;
  10471. lpfc_update_rcv_time_stamp(vport);
  10472. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10473. temp_hdr = dmabuf->hbuf.virt;
  10474. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10475. return seq_dmabuf;
  10476. }
  10477. /* find the correct place in the sequence to insert this frame */
  10478. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10479. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10480. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10481. /*
  10482. * If the frame's sequence count is greater than the frame on
  10483. * the list then insert the frame right after this frame
  10484. */
  10485. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10486. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10487. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10488. return seq_dmabuf;
  10489. }
  10490. }
  10491. return NULL;
  10492. }
  10493. /**
  10494. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10495. * @vport: pointer to a vitural port
  10496. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10497. *
  10498. * This function tries to abort from the partially assembed sequence, described
  10499. * by the information from basic abbort @dmabuf. It checks to see whether such
  10500. * partially assembled sequence held by the driver. If so, it shall free up all
  10501. * the frames from the partially assembled sequence.
  10502. *
  10503. * Return
  10504. * true -- if there is matching partially assembled sequence present and all
  10505. * the frames freed with the sequence;
  10506. * false -- if there is no matching partially assembled sequence present so
  10507. * nothing got aborted in the lower layer driver
  10508. **/
  10509. static bool
  10510. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10511. struct hbq_dmabuf *dmabuf)
  10512. {
  10513. struct fc_frame_header *new_hdr;
  10514. struct fc_frame_header *temp_hdr;
  10515. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10516. struct hbq_dmabuf *seq_dmabuf = NULL;
  10517. /* Use the hdr_buf to find the sequence that matches this frame */
  10518. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10519. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10520. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10521. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10522. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10523. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10524. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10525. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10526. continue;
  10527. /* found a pending sequence that matches this frame */
  10528. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10529. break;
  10530. }
  10531. /* Free up all the frames from the partially assembled sequence */
  10532. if (seq_dmabuf) {
  10533. list_for_each_entry_safe(d_buf, n_buf,
  10534. &seq_dmabuf->dbuf.list, list) {
  10535. list_del_init(&d_buf->list);
  10536. lpfc_in_buf_free(vport->phba, d_buf);
  10537. }
  10538. return true;
  10539. }
  10540. return false;
  10541. }
  10542. /**
  10543. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10544. * @phba: Pointer to HBA context object.
  10545. * @cmd_iocbq: pointer to the command iocbq structure.
  10546. * @rsp_iocbq: pointer to the response iocbq structure.
  10547. *
  10548. * This function handles the sequence abort accept iocb command complete
  10549. * event. It properly releases the memory allocated to the sequence abort
  10550. * accept iocb.
  10551. **/
  10552. static void
  10553. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10554. struct lpfc_iocbq *cmd_iocbq,
  10555. struct lpfc_iocbq *rsp_iocbq)
  10556. {
  10557. if (cmd_iocbq)
  10558. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10559. }
  10560. /**
  10561. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10562. * @phba: Pointer to HBA context object.
  10563. * @fc_hdr: pointer to a FC frame header.
  10564. *
  10565. * This function sends a basic accept to a previous unsol sequence abort
  10566. * event after aborting the sequence handling.
  10567. **/
  10568. static void
  10569. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10570. struct fc_frame_header *fc_hdr)
  10571. {
  10572. struct lpfc_iocbq *ctiocb = NULL;
  10573. struct lpfc_nodelist *ndlp;
  10574. uint16_t oxid, rxid;
  10575. uint32_t sid, fctl;
  10576. IOCB_t *icmd;
  10577. if (!lpfc_is_link_up(phba))
  10578. return;
  10579. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10580. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10581. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10582. ndlp = lpfc_findnode_did(phba->pport, sid);
  10583. if (!ndlp) {
  10584. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10585. "1268 Find ndlp returned NULL for oxid:x%x "
  10586. "SID:x%x\n", oxid, sid);
  10587. return;
  10588. }
  10589. /* Allocate buffer for acc iocb */
  10590. ctiocb = lpfc_sli_get_iocbq(phba);
  10591. if (!ctiocb)
  10592. return;
  10593. /* Extract the F_CTL field from FC_HDR */
  10594. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10595. icmd = &ctiocb->iocb;
  10596. icmd->un.xseq64.bdl.bdeSize = 0;
  10597. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10598. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10599. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10600. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10601. /* Fill in the rest of iocb fields */
  10602. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10603. icmd->ulpBdeCount = 0;
  10604. icmd->ulpLe = 1;
  10605. icmd->ulpClass = CLASS3;
  10606. icmd->ulpContext = ndlp->nlp_rpi;
  10607. ctiocb->iocb_cmpl = NULL;
  10608. ctiocb->vport = phba->pport;
  10609. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10610. if (fctl & FC_FC_EX_CTX) {
  10611. /* ABTS sent by responder to CT exchange, construction
  10612. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10613. * field and RX_ID from ABTS for RX_ID field.
  10614. */
  10615. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10616. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10617. ctiocb->sli4_xritag = oxid;
  10618. } else {
  10619. /* ABTS sent by initiator to CT exchange, construction
  10620. * of BA_ACC will need to allocate a new XRI as for the
  10621. * XRI_TAG and RX_ID fields.
  10622. */
  10623. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10624. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10625. ctiocb->sli4_xritag = NO_XRI;
  10626. }
  10627. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10628. /* Xmit CT abts accept on exchange <xid> */
  10629. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10630. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10631. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10632. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10633. }
  10634. /**
  10635. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10636. * @vport: Pointer to the vport on which this sequence was received
  10637. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10638. *
  10639. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10640. * receive sequence is only partially assembed by the driver, it shall abort
  10641. * the partially assembled frames for the sequence. Otherwise, if the
  10642. * unsolicited receive sequence has been completely assembled and passed to
  10643. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10644. * unsolicited sequence has been aborted. After that, it will issue a basic
  10645. * accept to accept the abort.
  10646. **/
  10647. void
  10648. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10649. struct hbq_dmabuf *dmabuf)
  10650. {
  10651. struct lpfc_hba *phba = vport->phba;
  10652. struct fc_frame_header fc_hdr;
  10653. uint32_t fctl;
  10654. bool abts_par;
  10655. /* Make a copy of fc_hdr before the dmabuf being released */
  10656. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10657. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10658. if (fctl & FC_FC_EX_CTX) {
  10659. /*
  10660. * ABTS sent by responder to exchange, just free the buffer
  10661. */
  10662. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10663. } else {
  10664. /*
  10665. * ABTS sent by initiator to exchange, need to do cleanup
  10666. */
  10667. /* Try to abort partially assembled seq */
  10668. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10669. /* Send abort to ULP if partially seq abort failed */
  10670. if (abts_par == false)
  10671. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10672. else
  10673. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10674. }
  10675. /* Send basic accept (BA_ACC) to the abort requester */
  10676. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10677. }
  10678. /**
  10679. * lpfc_seq_complete - Indicates if a sequence is complete
  10680. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10681. *
  10682. * This function checks the sequence, starting with the frame described by
  10683. * @dmabuf, to see if all the frames associated with this sequence are present.
  10684. * the frames associated with this sequence are linked to the @dmabuf using the
  10685. * dbuf list. This function looks for two major things. 1) That the first frame
  10686. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10687. * set. 3) That there are no holes in the sequence count. The function will
  10688. * return 1 when the sequence is complete, otherwise it will return 0.
  10689. **/
  10690. static int
  10691. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10692. {
  10693. struct fc_frame_header *hdr;
  10694. struct lpfc_dmabuf *d_buf;
  10695. struct hbq_dmabuf *seq_dmabuf;
  10696. uint32_t fctl;
  10697. int seq_count = 0;
  10698. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10699. /* make sure first fame of sequence has a sequence count of zero */
  10700. if (hdr->fh_seq_cnt != seq_count)
  10701. return 0;
  10702. fctl = (hdr->fh_f_ctl[0] << 16 |
  10703. hdr->fh_f_ctl[1] << 8 |
  10704. hdr->fh_f_ctl[2]);
  10705. /* If last frame of sequence we can return success. */
  10706. if (fctl & FC_FC_END_SEQ)
  10707. return 1;
  10708. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10709. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10710. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10711. /* If there is a hole in the sequence count then fail. */
  10712. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10713. return 0;
  10714. fctl = (hdr->fh_f_ctl[0] << 16 |
  10715. hdr->fh_f_ctl[1] << 8 |
  10716. hdr->fh_f_ctl[2]);
  10717. /* If last frame of sequence we can return success. */
  10718. if (fctl & FC_FC_END_SEQ)
  10719. return 1;
  10720. }
  10721. return 0;
  10722. }
  10723. /**
  10724. * lpfc_prep_seq - Prep sequence for ULP processing
  10725. * @vport: Pointer to the vport on which this sequence was received
  10726. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10727. *
  10728. * This function takes a sequence, described by a list of frames, and creates
  10729. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10730. * used to issue to the generic unsolicited sequence handler. This routine
  10731. * returns a pointer to the first iocbq in the list. If the function is unable
  10732. * to allocate an iocbq then it throw out the received frames that were not
  10733. * able to be described and return a pointer to the first iocbq. If unable to
  10734. * allocate any iocbqs (including the first) this function will return NULL.
  10735. **/
  10736. static struct lpfc_iocbq *
  10737. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10738. {
  10739. struct lpfc_dmabuf *d_buf, *n_buf;
  10740. struct lpfc_iocbq *first_iocbq, *iocbq;
  10741. struct fc_frame_header *fc_hdr;
  10742. uint32_t sid;
  10743. struct ulp_bde64 *pbde;
  10744. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10745. /* remove from receive buffer list */
  10746. list_del_init(&seq_dmabuf->hbuf.list);
  10747. lpfc_update_rcv_time_stamp(vport);
  10748. /* get the Remote Port's SID */
  10749. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10750. /* Get an iocbq struct to fill in. */
  10751. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10752. if (first_iocbq) {
  10753. /* Initialize the first IOCB. */
  10754. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10755. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10756. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10757. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10758. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10759. vport->vpi + vport->phba->vpi_base;
  10760. /* put the first buffer into the first IOCBq */
  10761. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10762. first_iocbq->context3 = NULL;
  10763. first_iocbq->iocb.ulpBdeCount = 1;
  10764. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10765. LPFC_DATA_BUF_SIZE;
  10766. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10767. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10768. bf_get(lpfc_rcqe_length,
  10769. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10770. }
  10771. iocbq = first_iocbq;
  10772. /*
  10773. * Each IOCBq can have two Buffers assigned, so go through the list
  10774. * of buffers for this sequence and save two buffers in each IOCBq
  10775. */
  10776. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10777. if (!iocbq) {
  10778. lpfc_in_buf_free(vport->phba, d_buf);
  10779. continue;
  10780. }
  10781. if (!iocbq->context3) {
  10782. iocbq->context3 = d_buf;
  10783. iocbq->iocb.ulpBdeCount++;
  10784. pbde = (struct ulp_bde64 *)
  10785. &iocbq->iocb.unsli3.sli3Words[4];
  10786. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10787. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10788. bf_get(lpfc_rcqe_length,
  10789. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10790. } else {
  10791. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10792. if (!iocbq) {
  10793. if (first_iocbq) {
  10794. first_iocbq->iocb.ulpStatus =
  10795. IOSTAT_FCP_RSP_ERROR;
  10796. first_iocbq->iocb.un.ulpWord[4] =
  10797. IOERR_NO_RESOURCES;
  10798. }
  10799. lpfc_in_buf_free(vport->phba, d_buf);
  10800. continue;
  10801. }
  10802. iocbq->context2 = d_buf;
  10803. iocbq->context3 = NULL;
  10804. iocbq->iocb.ulpBdeCount = 1;
  10805. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10806. LPFC_DATA_BUF_SIZE;
  10807. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10808. bf_get(lpfc_rcqe_length,
  10809. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10810. iocbq->iocb.un.rcvels.remoteID = sid;
  10811. list_add_tail(&iocbq->list, &first_iocbq->list);
  10812. }
  10813. }
  10814. return first_iocbq;
  10815. }
  10816. static void
  10817. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10818. struct hbq_dmabuf *seq_dmabuf)
  10819. {
  10820. struct fc_frame_header *fc_hdr;
  10821. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10822. struct lpfc_hba *phba = vport->phba;
  10823. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10824. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10825. if (!iocbq) {
  10826. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10827. "2707 Ring %d handler: Failed to allocate "
  10828. "iocb Rctl x%x Type x%x received\n",
  10829. LPFC_ELS_RING,
  10830. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10831. return;
  10832. }
  10833. if (!lpfc_complete_unsol_iocb(phba,
  10834. &phba->sli.ring[LPFC_ELS_RING],
  10835. iocbq, fc_hdr->fh_r_ctl,
  10836. fc_hdr->fh_type))
  10837. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10838. "2540 Ring %d handler: unexpected Rctl "
  10839. "x%x Type x%x received\n",
  10840. LPFC_ELS_RING,
  10841. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10842. /* Free iocb created in lpfc_prep_seq */
  10843. list_for_each_entry_safe(curr_iocb, next_iocb,
  10844. &iocbq->list, list) {
  10845. list_del_init(&curr_iocb->list);
  10846. lpfc_sli_release_iocbq(phba, curr_iocb);
  10847. }
  10848. lpfc_sli_release_iocbq(phba, iocbq);
  10849. }
  10850. /**
  10851. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10852. * @phba: Pointer to HBA context object.
  10853. *
  10854. * This function is called with no lock held. This function processes all
  10855. * the received buffers and gives it to upper layers when a received buffer
  10856. * indicates that it is the final frame in the sequence. The interrupt
  10857. * service routine processes received buffers at interrupt contexts and adds
  10858. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10859. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10860. * appropriate receive function when the final frame in a sequence is received.
  10861. **/
  10862. void
  10863. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10864. struct hbq_dmabuf *dmabuf)
  10865. {
  10866. struct hbq_dmabuf *seq_dmabuf;
  10867. struct fc_frame_header *fc_hdr;
  10868. struct lpfc_vport *vport;
  10869. uint32_t fcfi;
  10870. /* Process each received buffer */
  10871. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10872. /* check to see if this a valid type of frame */
  10873. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10874. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10875. return;
  10876. }
  10877. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10878. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10879. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10880. /* throw out the frame */
  10881. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10882. return;
  10883. }
  10884. /* Handle the basic abort sequence (BA_ABTS) event */
  10885. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10886. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10887. return;
  10888. }
  10889. /* Link this frame */
  10890. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10891. if (!seq_dmabuf) {
  10892. /* unable to add frame to vport - throw it out */
  10893. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10894. return;
  10895. }
  10896. /* If not last frame in sequence continue processing frames. */
  10897. if (!lpfc_seq_complete(seq_dmabuf))
  10898. return;
  10899. /* Send the complete sequence to the upper layer protocol */
  10900. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10901. }
  10902. /**
  10903. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10904. * @phba: pointer to lpfc hba data structure.
  10905. *
  10906. * This routine is invoked to post rpi header templates to the
  10907. * HBA consistent with the SLI-4 interface spec. This routine
  10908. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10909. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10910. *
  10911. * This routine does not require any locks. It's usage is expected
  10912. * to be driver load or reset recovery when the driver is
  10913. * sequential.
  10914. *
  10915. * Return codes
  10916. * 0 - successful
  10917. * -EIO - The mailbox failed to complete successfully.
  10918. * When this error occurs, the driver is not guaranteed
  10919. * to have any rpi regions posted to the device and
  10920. * must either attempt to repost the regions or take a
  10921. * fatal error.
  10922. **/
  10923. int
  10924. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10925. {
  10926. struct lpfc_rpi_hdr *rpi_page;
  10927. uint32_t rc = 0;
  10928. /* Post all rpi memory regions to the port. */
  10929. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10930. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10931. if (rc != MBX_SUCCESS) {
  10932. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10933. "2008 Error %d posting all rpi "
  10934. "headers\n", rc);
  10935. rc = -EIO;
  10936. break;
  10937. }
  10938. }
  10939. return rc;
  10940. }
  10941. /**
  10942. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10943. * @phba: pointer to lpfc hba data structure.
  10944. * @rpi_page: pointer to the rpi memory region.
  10945. *
  10946. * This routine is invoked to post a single rpi header to the
  10947. * HBA consistent with the SLI-4 interface spec. This memory region
  10948. * maps up to 64 rpi context regions.
  10949. *
  10950. * Return codes
  10951. * 0 - successful
  10952. * -ENOMEM - No available memory
  10953. * -EIO - The mailbox failed to complete successfully.
  10954. **/
  10955. int
  10956. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10957. {
  10958. LPFC_MBOXQ_t *mboxq;
  10959. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10960. uint32_t rc = 0;
  10961. uint32_t mbox_tmo;
  10962. uint32_t shdr_status, shdr_add_status;
  10963. union lpfc_sli4_cfg_shdr *shdr;
  10964. /* The port is notified of the header region via a mailbox command. */
  10965. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10966. if (!mboxq) {
  10967. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10968. "2001 Unable to allocate memory for issuing "
  10969. "SLI_CONFIG_SPECIAL mailbox command\n");
  10970. return -ENOMEM;
  10971. }
  10972. /* Post all rpi memory regions to the port. */
  10973. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10974. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10975. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10976. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10977. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10978. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10979. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10980. hdr_tmpl, rpi_page->page_count);
  10981. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10982. rpi_page->start_rpi);
  10983. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10984. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10985. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10986. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10987. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10988. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10989. if (rc != MBX_TIMEOUT)
  10990. mempool_free(mboxq, phba->mbox_mem_pool);
  10991. if (shdr_status || shdr_add_status || rc) {
  10992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10993. "2514 POST_RPI_HDR mailbox failed with "
  10994. "status x%x add_status x%x, mbx status x%x\n",
  10995. shdr_status, shdr_add_status, rc);
  10996. rc = -ENXIO;
  10997. }
  10998. return rc;
  10999. }
  11000. /**
  11001. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  11002. * @phba: pointer to lpfc hba data structure.
  11003. *
  11004. * This routine is invoked to post rpi header templates to the
  11005. * HBA consistent with the SLI-4 interface spec. This routine
  11006. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11007. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11008. *
  11009. * Returns
  11010. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11011. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11012. **/
  11013. int
  11014. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  11015. {
  11016. int rpi;
  11017. uint16_t max_rpi, rpi_base, rpi_limit;
  11018. uint16_t rpi_remaining;
  11019. struct lpfc_rpi_hdr *rpi_hdr;
  11020. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  11021. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  11022. rpi_limit = phba->sli4_hba.next_rpi;
  11023. /*
  11024. * The valid rpi range is not guaranteed to be zero-based. Start
  11025. * the search at the rpi_base as reported by the port.
  11026. */
  11027. spin_lock_irq(&phba->hbalock);
  11028. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  11029. if (rpi >= rpi_limit || rpi < rpi_base)
  11030. rpi = LPFC_RPI_ALLOC_ERROR;
  11031. else {
  11032. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  11033. phba->sli4_hba.max_cfg_param.rpi_used++;
  11034. phba->sli4_hba.rpi_count++;
  11035. }
  11036. /*
  11037. * Don't try to allocate more rpi header regions if the device limit
  11038. * on available rpis max has been exhausted.
  11039. */
  11040. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11041. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11042. spin_unlock_irq(&phba->hbalock);
  11043. return rpi;
  11044. }
  11045. /*
  11046. * If the driver is running low on rpi resources, allocate another
  11047. * page now. Note that the next_rpi value is used because
  11048. * it represents how many are actually in use whereas max_rpi notes
  11049. * how many are supported max by the device.
  11050. */
  11051. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11052. phba->sli4_hba.rpi_count;
  11053. spin_unlock_irq(&phba->hbalock);
  11054. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11055. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11056. if (!rpi_hdr) {
  11057. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11058. "2002 Error Could not grow rpi "
  11059. "count\n");
  11060. } else {
  11061. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11062. }
  11063. }
  11064. return rpi;
  11065. }
  11066. /**
  11067. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11068. * @phba: pointer to lpfc hba data structure.
  11069. *
  11070. * This routine is invoked to release an rpi to the pool of
  11071. * available rpis maintained by the driver.
  11072. **/
  11073. void
  11074. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11075. {
  11076. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11077. phba->sli4_hba.rpi_count--;
  11078. phba->sli4_hba.max_cfg_param.rpi_used--;
  11079. }
  11080. }
  11081. /**
  11082. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11083. * @phba: pointer to lpfc hba data structure.
  11084. *
  11085. * This routine is invoked to release an rpi to the pool of
  11086. * available rpis maintained by the driver.
  11087. **/
  11088. void
  11089. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11090. {
  11091. spin_lock_irq(&phba->hbalock);
  11092. __lpfc_sli4_free_rpi(phba, rpi);
  11093. spin_unlock_irq(&phba->hbalock);
  11094. }
  11095. /**
  11096. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11097. * @phba: pointer to lpfc hba data structure.
  11098. *
  11099. * This routine is invoked to remove the memory region that
  11100. * provided rpi via a bitmask.
  11101. **/
  11102. void
  11103. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11104. {
  11105. kfree(phba->sli4_hba.rpi_bmask);
  11106. }
  11107. /**
  11108. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11109. * @phba: pointer to lpfc hba data structure.
  11110. *
  11111. * This routine is invoked to remove the memory region that
  11112. * provided rpi via a bitmask.
  11113. **/
  11114. int
  11115. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11116. {
  11117. LPFC_MBOXQ_t *mboxq;
  11118. struct lpfc_hba *phba = ndlp->phba;
  11119. int rc;
  11120. /* The port is notified of the header region via a mailbox command. */
  11121. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11122. if (!mboxq)
  11123. return -ENOMEM;
  11124. /* Post all rpi memory regions to the port. */
  11125. lpfc_resume_rpi(mboxq, ndlp);
  11126. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11127. if (rc == MBX_NOT_FINISHED) {
  11128. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11129. "2010 Resume RPI Mailbox failed "
  11130. "status %d, mbxStatus x%x\n", rc,
  11131. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11132. mempool_free(mboxq, phba->mbox_mem_pool);
  11133. return -EIO;
  11134. }
  11135. return 0;
  11136. }
  11137. /**
  11138. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11139. * @vport: Pointer to the vport for which the vpi is being initialized
  11140. *
  11141. * This routine is invoked to activate a vpi with the port.
  11142. *
  11143. * Returns:
  11144. * 0 success
  11145. * -Evalue otherwise
  11146. **/
  11147. int
  11148. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  11149. {
  11150. LPFC_MBOXQ_t *mboxq;
  11151. int rc = 0;
  11152. int retval = MBX_SUCCESS;
  11153. uint32_t mbox_tmo;
  11154. struct lpfc_hba *phba = vport->phba;
  11155. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11156. if (!mboxq)
  11157. return -ENOMEM;
  11158. lpfc_init_vpi(phba, mboxq, vport->vpi);
  11159. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11160. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11161. if (rc != MBX_SUCCESS) {
  11162. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  11163. "2022 INIT VPI Mailbox failed "
  11164. "status %d, mbxStatus x%x\n", rc,
  11165. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11166. retval = -EIO;
  11167. }
  11168. if (rc != MBX_TIMEOUT)
  11169. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  11170. return retval;
  11171. }
  11172. /**
  11173. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11174. * @phba: pointer to lpfc hba data structure.
  11175. * @mboxq: Pointer to mailbox object.
  11176. *
  11177. * This routine is invoked to manually add a single FCF record. The caller
  11178. * must pass a completely initialized FCF_Record. This routine takes
  11179. * care of the nonembedded mailbox operations.
  11180. **/
  11181. static void
  11182. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11183. {
  11184. void *virt_addr;
  11185. union lpfc_sli4_cfg_shdr *shdr;
  11186. uint32_t shdr_status, shdr_add_status;
  11187. virt_addr = mboxq->sge_array->addr[0];
  11188. /* The IOCTL status is embedded in the mailbox subheader. */
  11189. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11190. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11191. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11192. if ((shdr_status || shdr_add_status) &&
  11193. (shdr_status != STATUS_FCF_IN_USE))
  11194. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11195. "2558 ADD_FCF_RECORD mailbox failed with "
  11196. "status x%x add_status x%x\n",
  11197. shdr_status, shdr_add_status);
  11198. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11199. }
  11200. /**
  11201. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11202. * @phba: pointer to lpfc hba data structure.
  11203. * @fcf_record: pointer to the initialized fcf record to add.
  11204. *
  11205. * This routine is invoked to manually add a single FCF record. The caller
  11206. * must pass a completely initialized FCF_Record. This routine takes
  11207. * care of the nonembedded mailbox operations.
  11208. **/
  11209. int
  11210. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11211. {
  11212. int rc = 0;
  11213. LPFC_MBOXQ_t *mboxq;
  11214. uint8_t *bytep;
  11215. void *virt_addr;
  11216. dma_addr_t phys_addr;
  11217. struct lpfc_mbx_sge sge;
  11218. uint32_t alloc_len, req_len;
  11219. uint32_t fcfindex;
  11220. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11221. if (!mboxq) {
  11222. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11223. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11224. return -ENOMEM;
  11225. }
  11226. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11227. sizeof(uint32_t);
  11228. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11229. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11230. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11231. req_len, LPFC_SLI4_MBX_NEMBED);
  11232. if (alloc_len < req_len) {
  11233. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11234. "2523 Allocated DMA memory size (x%x) is "
  11235. "less than the requested DMA memory "
  11236. "size (x%x)\n", alloc_len, req_len);
  11237. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11238. return -ENOMEM;
  11239. }
  11240. /*
  11241. * Get the first SGE entry from the non-embedded DMA memory. This
  11242. * routine only uses a single SGE.
  11243. */
  11244. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11245. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11246. virt_addr = mboxq->sge_array->addr[0];
  11247. /*
  11248. * Configure the FCF record for FCFI 0. This is the driver's
  11249. * hardcoded default and gets used in nonFIP mode.
  11250. */
  11251. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11252. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11253. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11254. /*
  11255. * Copy the fcf_index and the FCF Record Data. The data starts after
  11256. * the FCoE header plus word10. The data copy needs to be endian
  11257. * correct.
  11258. */
  11259. bytep += sizeof(uint32_t);
  11260. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11261. mboxq->vport = phba->pport;
  11262. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11263. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11264. if (rc == MBX_NOT_FINISHED) {
  11265. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11266. "2515 ADD_FCF_RECORD mailbox failed with "
  11267. "status 0x%x\n", rc);
  11268. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11269. rc = -EIO;
  11270. } else
  11271. rc = 0;
  11272. return rc;
  11273. }
  11274. /**
  11275. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11276. * @phba: pointer to lpfc hba data structure.
  11277. * @fcf_record: pointer to the fcf record to write the default data.
  11278. * @fcf_index: FCF table entry index.
  11279. *
  11280. * This routine is invoked to build the driver's default FCF record. The
  11281. * values used are hardcoded. This routine handles memory initialization.
  11282. *
  11283. **/
  11284. void
  11285. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11286. struct fcf_record *fcf_record,
  11287. uint16_t fcf_index)
  11288. {
  11289. memset(fcf_record, 0, sizeof(struct fcf_record));
  11290. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11291. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11292. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11293. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11294. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11295. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11296. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11297. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11298. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11299. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11300. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11301. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11302. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11303. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11304. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11305. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11306. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11307. /* Set the VLAN bit map */
  11308. if (phba->valid_vlan) {
  11309. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11310. = 1 << (phba->vlan_id % 8);
  11311. }
  11312. }
  11313. /**
  11314. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11315. * @phba: pointer to lpfc hba data structure.
  11316. * @fcf_index: FCF table entry offset.
  11317. *
  11318. * This routine is invoked to scan the entire FCF table by reading FCF
  11319. * record and processing it one at a time starting from the @fcf_index
  11320. * for initial FCF discovery or fast FCF failover rediscovery.
  11321. *
  11322. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11323. * otherwise.
  11324. **/
  11325. int
  11326. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11327. {
  11328. int rc = 0, error;
  11329. LPFC_MBOXQ_t *mboxq;
  11330. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11331. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11332. if (!mboxq) {
  11333. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11334. "2000 Failed to allocate mbox for "
  11335. "READ_FCF cmd\n");
  11336. error = -ENOMEM;
  11337. goto fail_fcf_scan;
  11338. }
  11339. /* Construct the read FCF record mailbox command */
  11340. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11341. if (rc) {
  11342. error = -EINVAL;
  11343. goto fail_fcf_scan;
  11344. }
  11345. /* Issue the mailbox command asynchronously */
  11346. mboxq->vport = phba->pport;
  11347. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11348. spin_lock_irq(&phba->hbalock);
  11349. phba->hba_flag |= FCF_TS_INPROG;
  11350. spin_unlock_irq(&phba->hbalock);
  11351. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11352. if (rc == MBX_NOT_FINISHED)
  11353. error = -EIO;
  11354. else {
  11355. /* Reset eligible FCF count for new scan */
  11356. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11357. phba->fcf.eligible_fcf_cnt = 0;
  11358. error = 0;
  11359. }
  11360. fail_fcf_scan:
  11361. if (error) {
  11362. if (mboxq)
  11363. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11364. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11365. spin_lock_irq(&phba->hbalock);
  11366. phba->hba_flag &= ~FCF_TS_INPROG;
  11367. spin_unlock_irq(&phba->hbalock);
  11368. }
  11369. return error;
  11370. }
  11371. /**
  11372. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11373. * @phba: pointer to lpfc hba data structure.
  11374. * @fcf_index: FCF table entry offset.
  11375. *
  11376. * This routine is invoked to read an FCF record indicated by @fcf_index
  11377. * and to use it for FLOGI roundrobin FCF failover.
  11378. *
  11379. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11380. * otherwise.
  11381. **/
  11382. int
  11383. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11384. {
  11385. int rc = 0, error;
  11386. LPFC_MBOXQ_t *mboxq;
  11387. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11388. if (!mboxq) {
  11389. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11390. "2763 Failed to allocate mbox for "
  11391. "READ_FCF cmd\n");
  11392. error = -ENOMEM;
  11393. goto fail_fcf_read;
  11394. }
  11395. /* Construct the read FCF record mailbox command */
  11396. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11397. if (rc) {
  11398. error = -EINVAL;
  11399. goto fail_fcf_read;
  11400. }
  11401. /* Issue the mailbox command asynchronously */
  11402. mboxq->vport = phba->pport;
  11403. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11404. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11405. if (rc == MBX_NOT_FINISHED)
  11406. error = -EIO;
  11407. else
  11408. error = 0;
  11409. fail_fcf_read:
  11410. if (error && mboxq)
  11411. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11412. return error;
  11413. }
  11414. /**
  11415. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11416. * @phba: pointer to lpfc hba data structure.
  11417. * @fcf_index: FCF table entry offset.
  11418. *
  11419. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11420. * determine whether it's eligible for FLOGI roundrobin failover list.
  11421. *
  11422. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11423. * otherwise.
  11424. **/
  11425. int
  11426. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11427. {
  11428. int rc = 0, error;
  11429. LPFC_MBOXQ_t *mboxq;
  11430. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11431. if (!mboxq) {
  11432. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11433. "2758 Failed to allocate mbox for "
  11434. "READ_FCF cmd\n");
  11435. error = -ENOMEM;
  11436. goto fail_fcf_read;
  11437. }
  11438. /* Construct the read FCF record mailbox command */
  11439. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11440. if (rc) {
  11441. error = -EINVAL;
  11442. goto fail_fcf_read;
  11443. }
  11444. /* Issue the mailbox command asynchronously */
  11445. mboxq->vport = phba->pport;
  11446. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11447. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11448. if (rc == MBX_NOT_FINISHED)
  11449. error = -EIO;
  11450. else
  11451. error = 0;
  11452. fail_fcf_read:
  11453. if (error && mboxq)
  11454. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11455. return error;
  11456. }
  11457. /**
  11458. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11459. * @phba: pointer to lpfc hba data structure.
  11460. *
  11461. * This routine is to get the next eligible FCF record index in a round
  11462. * robin fashion. If the next eligible FCF record index equals to the
  11463. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11464. * shall be returned, otherwise, the next eligible FCF record's index
  11465. * shall be returned.
  11466. **/
  11467. uint16_t
  11468. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11469. {
  11470. uint16_t next_fcf_index;
  11471. /* Search start from next bit of currently registered FCF index */
  11472. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11473. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11474. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11475. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11476. next_fcf_index);
  11477. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11478. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11479. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11480. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11481. /* Check roundrobin failover list empty condition */
  11482. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11483. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11484. "2844 No roundrobin failover FCF available\n");
  11485. return LPFC_FCOE_FCF_NEXT_NONE;
  11486. }
  11487. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11488. "2845 Get next roundrobin failover FCF (x%x)\n",
  11489. next_fcf_index);
  11490. return next_fcf_index;
  11491. }
  11492. /**
  11493. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11494. * @phba: pointer to lpfc hba data structure.
  11495. *
  11496. * This routine sets the FCF record index in to the eligible bmask for
  11497. * roundrobin failover search. It checks to make sure that the index
  11498. * does not go beyond the range of the driver allocated bmask dimension
  11499. * before setting the bit.
  11500. *
  11501. * Returns 0 if the index bit successfully set, otherwise, it returns
  11502. * -EINVAL.
  11503. **/
  11504. int
  11505. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11506. {
  11507. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11508. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11509. "2610 FCF (x%x) reached driver's book "
  11510. "keeping dimension:x%x\n",
  11511. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11512. return -EINVAL;
  11513. }
  11514. /* Set the eligible FCF record index bmask */
  11515. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11516. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11517. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11518. "bmask\n", fcf_index);
  11519. return 0;
  11520. }
  11521. /**
  11522. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11523. * @phba: pointer to lpfc hba data structure.
  11524. *
  11525. * This routine clears the FCF record index from the eligible bmask for
  11526. * roundrobin failover search. It checks to make sure that the index
  11527. * does not go beyond the range of the driver allocated bmask dimension
  11528. * before clearing the bit.
  11529. **/
  11530. void
  11531. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11532. {
  11533. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11534. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11535. "2762 FCF (x%x) reached driver's book "
  11536. "keeping dimension:x%x\n",
  11537. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11538. return;
  11539. }
  11540. /* Clear the eligible FCF record index bmask */
  11541. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11542. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11543. "2791 Clear FCF (x%x) from roundrobin failover "
  11544. "bmask\n", fcf_index);
  11545. }
  11546. /**
  11547. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11548. * @phba: pointer to lpfc hba data structure.
  11549. *
  11550. * This routine is the completion routine for the rediscover FCF table mailbox
  11551. * command. If the mailbox command returned failure, it will try to stop the
  11552. * FCF rediscover wait timer.
  11553. **/
  11554. void
  11555. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11556. {
  11557. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11558. uint32_t shdr_status, shdr_add_status;
  11559. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11560. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11561. &redisc_fcf->header.cfg_shdr.response);
  11562. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11563. &redisc_fcf->header.cfg_shdr.response);
  11564. if (shdr_status || shdr_add_status) {
  11565. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11566. "2746 Requesting for FCF rediscovery failed "
  11567. "status x%x add_status x%x\n",
  11568. shdr_status, shdr_add_status);
  11569. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11570. spin_lock_irq(&phba->hbalock);
  11571. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11572. spin_unlock_irq(&phba->hbalock);
  11573. /*
  11574. * CVL event triggered FCF rediscover request failed,
  11575. * last resort to re-try current registered FCF entry.
  11576. */
  11577. lpfc_retry_pport_discovery(phba);
  11578. } else {
  11579. spin_lock_irq(&phba->hbalock);
  11580. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11581. spin_unlock_irq(&phba->hbalock);
  11582. /*
  11583. * DEAD FCF event triggered FCF rediscover request
  11584. * failed, last resort to fail over as a link down
  11585. * to FCF registration.
  11586. */
  11587. lpfc_sli4_fcf_dead_failthrough(phba);
  11588. }
  11589. } else {
  11590. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11591. "2775 Start FCF rediscover quiescent timer\n");
  11592. /*
  11593. * Start FCF rediscovery wait timer for pending FCF
  11594. * before rescan FCF record table.
  11595. */
  11596. lpfc_fcf_redisc_wait_start_timer(phba);
  11597. }
  11598. mempool_free(mbox, phba->mbox_mem_pool);
  11599. }
  11600. /**
  11601. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11602. * @phba: pointer to lpfc hba data structure.
  11603. *
  11604. * This routine is invoked to request for rediscovery of the entire FCF table
  11605. * by the port.
  11606. **/
  11607. int
  11608. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11609. {
  11610. LPFC_MBOXQ_t *mbox;
  11611. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11612. int rc, length;
  11613. /* Cancel retry delay timers to all vports before FCF rediscover */
  11614. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11615. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11616. if (!mbox) {
  11617. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11618. "2745 Failed to allocate mbox for "
  11619. "requesting FCF rediscover.\n");
  11620. return -ENOMEM;
  11621. }
  11622. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11623. sizeof(struct lpfc_sli4_cfg_mhdr));
  11624. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11625. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11626. length, LPFC_SLI4_MBX_EMBED);
  11627. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11628. /* Set count to 0 for invalidating the entire FCF database */
  11629. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11630. /* Issue the mailbox command asynchronously */
  11631. mbox->vport = phba->pport;
  11632. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11633. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11634. if (rc == MBX_NOT_FINISHED) {
  11635. mempool_free(mbox, phba->mbox_mem_pool);
  11636. return -EIO;
  11637. }
  11638. return 0;
  11639. }
  11640. /**
  11641. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11642. * @phba: pointer to lpfc hba data structure.
  11643. *
  11644. * This function is the failover routine as a last resort to the FCF DEAD
  11645. * event when driver failed to perform fast FCF failover.
  11646. **/
  11647. void
  11648. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11649. {
  11650. uint32_t link_state;
  11651. /*
  11652. * Last resort as FCF DEAD event failover will treat this as
  11653. * a link down, but save the link state because we don't want
  11654. * it to be changed to Link Down unless it is already down.
  11655. */
  11656. link_state = phba->link_state;
  11657. lpfc_linkdown(phba);
  11658. phba->link_state = link_state;
  11659. /* Unregister FCF if no devices connected to it */
  11660. lpfc_unregister_unused_fcf(phba);
  11661. }
  11662. /**
  11663. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11664. * @phba: pointer to lpfc hba data structure.
  11665. *
  11666. * This function read region 23 and parse TLV for port status to
  11667. * decide if the user disaled the port. If the TLV indicates the
  11668. * port is disabled, the hba_flag is set accordingly.
  11669. **/
  11670. void
  11671. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11672. {
  11673. LPFC_MBOXQ_t *pmb = NULL;
  11674. MAILBOX_t *mb;
  11675. uint8_t *rgn23_data = NULL;
  11676. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11677. int rc;
  11678. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11679. if (!pmb) {
  11680. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11681. "2600 lpfc_sli_read_serdes_param failed to"
  11682. " allocate mailbox memory\n");
  11683. goto out;
  11684. }
  11685. mb = &pmb->u.mb;
  11686. /* Get adapter Region 23 data */
  11687. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11688. if (!rgn23_data)
  11689. goto out;
  11690. do {
  11691. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11692. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11693. if (rc != MBX_SUCCESS) {
  11694. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11695. "2601 lpfc_sli_read_link_ste failed to"
  11696. " read config region 23 rc 0x%x Status 0x%x\n",
  11697. rc, mb->mbxStatus);
  11698. mb->un.varDmp.word_cnt = 0;
  11699. }
  11700. /*
  11701. * dump mem may return a zero when finished or we got a
  11702. * mailbox error, either way we are done.
  11703. */
  11704. if (mb->un.varDmp.word_cnt == 0)
  11705. break;
  11706. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11707. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11708. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11709. rgn23_data + offset,
  11710. mb->un.varDmp.word_cnt);
  11711. offset += mb->un.varDmp.word_cnt;
  11712. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11713. data_size = offset;
  11714. offset = 0;
  11715. if (!data_size)
  11716. goto out;
  11717. /* Check the region signature first */
  11718. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11719. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11720. "2619 Config region 23 has bad signature\n");
  11721. goto out;
  11722. }
  11723. offset += 4;
  11724. /* Check the data structure version */
  11725. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11727. "2620 Config region 23 has bad version\n");
  11728. goto out;
  11729. }
  11730. offset += 4;
  11731. /* Parse TLV entries in the region */
  11732. while (offset < data_size) {
  11733. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11734. break;
  11735. /*
  11736. * If the TLV is not driver specific TLV or driver id is
  11737. * not linux driver id, skip the record.
  11738. */
  11739. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11740. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11741. (rgn23_data[offset + 3] != 0)) {
  11742. offset += rgn23_data[offset + 1] * 4 + 4;
  11743. continue;
  11744. }
  11745. /* Driver found a driver specific TLV in the config region */
  11746. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11747. offset += 4;
  11748. tlv_offset = 0;
  11749. /*
  11750. * Search for configured port state sub-TLV.
  11751. */
  11752. while ((offset < data_size) &&
  11753. (tlv_offset < sub_tlv_len)) {
  11754. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11755. offset += 4;
  11756. tlv_offset += 4;
  11757. break;
  11758. }
  11759. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11760. offset += rgn23_data[offset + 1] * 4 + 4;
  11761. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11762. continue;
  11763. }
  11764. /* This HBA contains PORT_STE configured */
  11765. if (!rgn23_data[offset + 2])
  11766. phba->hba_flag |= LINK_DISABLED;
  11767. goto out;
  11768. }
  11769. }
  11770. out:
  11771. if (pmb)
  11772. mempool_free(pmb, phba->mbox_mem_pool);
  11773. kfree(rgn23_data);
  11774. return;
  11775. }
  11776. /**
  11777. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11778. * @vport: pointer to vport data structure.
  11779. *
  11780. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11781. * and REG_VPI mailbox commands associated with the vport. This function
  11782. * is called when driver want to restart discovery of the vport due to
  11783. * a Clear Virtual Link event.
  11784. **/
  11785. void
  11786. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11787. {
  11788. struct lpfc_hba *phba = vport->phba;
  11789. LPFC_MBOXQ_t *mb, *nextmb;
  11790. struct lpfc_dmabuf *mp;
  11791. struct lpfc_nodelist *ndlp;
  11792. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  11793. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  11794. LIST_HEAD(mbox_cmd_list);
  11795. uint8_t restart_loop;
  11796. /* Clean up internally queued mailbox commands with the vport */
  11797. spin_lock_irq(&phba->hbalock);
  11798. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11799. if (mb->vport != vport)
  11800. continue;
  11801. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11802. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11803. continue;
  11804. list_del(&mb->list);
  11805. list_add_tail(&mb->list, &mbox_cmd_list);
  11806. }
  11807. /* Clean up active mailbox command with the vport */
  11808. mb = phba->sli.mbox_active;
  11809. if (mb && (mb->vport == vport)) {
  11810. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11811. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11812. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11813. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11814. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  11815. /* Put reference count for delayed processing */
  11816. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  11817. /* Unregister the RPI when mailbox complete */
  11818. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11819. }
  11820. }
  11821. /* Cleanup any mailbox completions which are not yet processed */
  11822. do {
  11823. restart_loop = 0;
  11824. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  11825. /*
  11826. * If this mailox is already processed or it is
  11827. * for another vport ignore it.
  11828. */
  11829. if ((mb->vport != vport) ||
  11830. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  11831. continue;
  11832. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11833. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11834. continue;
  11835. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11836. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11837. ndlp = (struct lpfc_nodelist *)mb->context2;
  11838. /* Unregister the RPI when mailbox complete */
  11839. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11840. restart_loop = 1;
  11841. spin_unlock_irq(&phba->hbalock);
  11842. spin_lock(shost->host_lock);
  11843. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11844. spin_unlock(shost->host_lock);
  11845. spin_lock_irq(&phba->hbalock);
  11846. break;
  11847. }
  11848. }
  11849. } while (restart_loop);
  11850. spin_unlock_irq(&phba->hbalock);
  11851. /* Release the cleaned-up mailbox commands */
  11852. while (!list_empty(&mbox_cmd_list)) {
  11853. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  11854. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11855. if (phba->sli_rev == LPFC_SLI_REV4)
  11856. __lpfc_sli4_free_rpi(phba,
  11857. mb->u.mb.un.varRegLogin.rpi);
  11858. mp = (struct lpfc_dmabuf *) (mb->context1);
  11859. if (mp) {
  11860. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11861. kfree(mp);
  11862. }
  11863. ndlp = (struct lpfc_nodelist *) mb->context2;
  11864. mb->context2 = NULL;
  11865. if (ndlp) {
  11866. spin_lock(shost->host_lock);
  11867. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11868. spin_unlock(shost->host_lock);
  11869. lpfc_nlp_put(ndlp);
  11870. }
  11871. }
  11872. mempool_free(mb, phba->mbox_mem_pool);
  11873. }
  11874. /* Release the ndlp with the cleaned-up active mailbox command */
  11875. if (act_mbx_ndlp) {
  11876. spin_lock(shost->host_lock);
  11877. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11878. spin_unlock(shost->host_lock);
  11879. lpfc_nlp_put(act_mbx_ndlp);
  11880. }
  11881. }
  11882. /**
  11883. * lpfc_drain_txq - Drain the txq
  11884. * @phba: Pointer to HBA context object.
  11885. *
  11886. * This function attempt to submit IOCBs on the txq
  11887. * to the adapter. For SLI4 adapters, the txq contains
  11888. * ELS IOCBs that have been deferred because the there
  11889. * are no SGLs. This congestion can occur with large
  11890. * vport counts during node discovery.
  11891. **/
  11892. uint32_t
  11893. lpfc_drain_txq(struct lpfc_hba *phba)
  11894. {
  11895. LIST_HEAD(completions);
  11896. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11897. struct lpfc_iocbq *piocbq = 0;
  11898. unsigned long iflags = 0;
  11899. char *fail_msg = NULL;
  11900. struct lpfc_sglq *sglq;
  11901. union lpfc_wqe wqe;
  11902. spin_lock_irqsave(&phba->hbalock, iflags);
  11903. if (pring->txq_cnt > pring->txq_max)
  11904. pring->txq_max = pring->txq_cnt;
  11905. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11906. while (pring->txq_cnt) {
  11907. spin_lock_irqsave(&phba->hbalock, iflags);
  11908. sglq = __lpfc_sli_get_sglq(phba);
  11909. if (!sglq) {
  11910. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11911. break;
  11912. } else {
  11913. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11914. if (!piocbq) {
  11915. /* The txq_cnt out of sync. This should
  11916. * never happen
  11917. */
  11918. sglq = __lpfc_clear_active_sglq(phba,
  11919. sglq->sli4_xritag);
  11920. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11921. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11922. "2823 txq empty and txq_cnt is %d\n ",
  11923. pring->txq_cnt);
  11924. break;
  11925. }
  11926. }
  11927. /* The xri and iocb resources secured,
  11928. * attempt to issue request
  11929. */
  11930. piocbq->sli4_xritag = sglq->sli4_xritag;
  11931. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11932. fail_msg = "to convert bpl to sgl";
  11933. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11934. fail_msg = "to convert iocb to wqe";
  11935. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11936. fail_msg = " - Wq is full";
  11937. else
  11938. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11939. if (fail_msg) {
  11940. /* Failed means we can't issue and need to cancel */
  11941. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11942. "2822 IOCB failed %s iotag 0x%x "
  11943. "xri 0x%x\n",
  11944. fail_msg,
  11945. piocbq->iotag, piocbq->sli4_xritag);
  11946. list_add_tail(&piocbq->list, &completions);
  11947. }
  11948. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11949. }
  11950. /* Cancel all the IOCBs that cannot be issued */
  11951. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11952. IOERR_SLI_ABORTED);
  11953. return pring->txq_cnt;
  11954. }