lpfc_sli.c 372 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071
  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 <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include <linux/aer.h>
  32. #include "lpfc_hw4.h"
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.h"
  36. #include "lpfc_nl.h"
  37. #include "lpfc_disc.h"
  38. #include "lpfc_scsi.h"
  39. #include "lpfc.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_compat.h"
  43. #include "lpfc_debugfs.h"
  44. #include "lpfc_vport.h"
  45. /* There are only four IOCB completion types. */
  46. typedef enum _lpfc_iocb_type {
  47. LPFC_UNKNOWN_IOCB,
  48. LPFC_UNSOL_IOCB,
  49. LPFC_SOL_IOCB,
  50. LPFC_ABORT_IOCB
  51. } lpfc_iocb_type;
  52. /* Provide function prototypes local to this module. */
  53. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  54. uint32_t);
  55. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint8_t *, uint32_t *);
  57. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  58. struct lpfc_iocbq *);
  59. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  60. struct hbq_dmabuf *);
  61. static IOCB_t *
  62. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  63. {
  64. return &iocbq->iocb;
  65. }
  66. /**
  67. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  68. * @q: The Work Queue to operate on.
  69. * @wqe: The work Queue Entry to put on the Work queue.
  70. *
  71. * This routine will copy the contents of @wqe to the next available entry on
  72. * the @q. This function will then ring the Work Queue Doorbell to signal the
  73. * HBA to start processing the Work Queue Entry. This function returns 0 if
  74. * successful. If no entries are available on @q then this function will return
  75. * -ENOMEM.
  76. * The caller is expected to hold the hbalock when calling this routine.
  77. **/
  78. static uint32_t
  79. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  80. {
  81. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  82. struct lpfc_register doorbell;
  83. uint32_t host_index;
  84. /* If the host has not yet processed the next entry then we are done */
  85. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  86. return -ENOMEM;
  87. /* set consumption flag every once in a while */
  88. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  89. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  90. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  91. /* Update the host index before invoking device */
  92. host_index = q->host_index;
  93. q->host_index = ((q->host_index + 1) % q->entry_count);
  94. /* Ring Doorbell */
  95. doorbell.word0 = 0;
  96. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  97. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  98. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  99. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  100. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  101. return 0;
  102. }
  103. /**
  104. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  105. * @q: The Work Queue to operate on.
  106. * @index: The index to advance the hba index to.
  107. *
  108. * This routine will update the HBA index of a queue to reflect consumption of
  109. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  110. * an entry the host calls this function to update the queue's internal
  111. * pointers. This routine returns the number of entries that were consumed by
  112. * the HBA.
  113. **/
  114. static uint32_t
  115. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  116. {
  117. uint32_t released = 0;
  118. if (q->hba_index == index)
  119. return 0;
  120. do {
  121. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  122. released++;
  123. } while (q->hba_index != index);
  124. return released;
  125. }
  126. /**
  127. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  128. * @q: The Mailbox Queue to operate on.
  129. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  130. *
  131. * This routine will copy the contents of @mqe to the next available entry on
  132. * the @q. This function will then ring the Work Queue Doorbell to signal the
  133. * HBA to start processing the Work Queue Entry. This function returns 0 if
  134. * successful. If no entries are available on @q then this function will return
  135. * -ENOMEM.
  136. * The caller is expected to hold the hbalock when calling this routine.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  140. {
  141. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  142. struct lpfc_register doorbell;
  143. uint32_t host_index;
  144. /* If the host has not yet processed the next entry then we are done */
  145. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  146. return -ENOMEM;
  147. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  148. /* Save off the mailbox pointer for completion */
  149. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  150. /* Update the host index before invoking device */
  151. host_index = q->host_index;
  152. q->host_index = ((q->host_index + 1) % q->entry_count);
  153. /* Ring Doorbell */
  154. doorbell.word0 = 0;
  155. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  156. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  157. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  158. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  159. return 0;
  160. }
  161. /**
  162. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  163. * @q: The Mailbox Queue to operate on.
  164. *
  165. * This routine will update the HBA index of a queue to reflect consumption of
  166. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  167. * an entry the host calls this function to update the queue's internal
  168. * pointers. This routine returns the number of entries that were consumed by
  169. * the HBA.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_release(struct lpfc_queue *q)
  173. {
  174. /* Clear the mailbox pointer for completion */
  175. q->phba->mbox = NULL;
  176. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  177. return 1;
  178. }
  179. /**
  180. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  181. * @q: The Event Queue to get the first valid EQE from
  182. *
  183. * This routine will get the first valid Event Queue Entry from @q, update
  184. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  185. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  186. * processed, but not popped back to the HBA then this routine will return NULL.
  187. **/
  188. static struct lpfc_eqe *
  189. lpfc_sli4_eq_get(struct lpfc_queue *q)
  190. {
  191. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  192. /* If the next EQE is not valid then we are done */
  193. if (!bf_get(lpfc_eqe_valid, eqe))
  194. return NULL;
  195. /* If the host has not yet processed the next entry then we are done */
  196. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  197. return NULL;
  198. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  199. return eqe;
  200. }
  201. /**
  202. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  203. * @q: The Event Queue that the host has completed processing for.
  204. * @arm: Indicates whether the host wants to arms this CQ.
  205. *
  206. * This routine will mark all Event Queue Entries on @q, from the last
  207. * known completed entry to the last entry that was processed, as completed
  208. * by clearing the valid bit for each completion queue entry. Then it will
  209. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  210. * The internal host index in the @q will be updated by this routine to indicate
  211. * that the host has finished processing the entries. The @arm parameter
  212. * indicates that the queue should be rearmed when ringing the doorbell.
  213. *
  214. * This function will return the number of EQEs that were popped.
  215. **/
  216. uint32_t
  217. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  218. {
  219. uint32_t released = 0;
  220. struct lpfc_eqe *temp_eqe;
  221. struct lpfc_register doorbell;
  222. /* while there are valid entries */
  223. while (q->hba_index != q->host_index) {
  224. temp_eqe = q->qe[q->host_index].eqe;
  225. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  226. released++;
  227. q->host_index = ((q->host_index + 1) % q->entry_count);
  228. }
  229. if (unlikely(released == 0 && !arm))
  230. return 0;
  231. /* ring doorbell for number popped */
  232. doorbell.word0 = 0;
  233. if (arm) {
  234. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  235. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  236. }
  237. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  238. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  239. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  240. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  241. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  242. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  243. readl(q->phba->sli4_hba.EQCQDBregaddr);
  244. return released;
  245. }
  246. /**
  247. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  248. * @q: The Completion Queue to get the first valid CQE from
  249. *
  250. * This routine will get the first valid Completion Queue Entry from @q, update
  251. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  252. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  253. * processed, but not popped back to the HBA then this routine will return NULL.
  254. **/
  255. static struct lpfc_cqe *
  256. lpfc_sli4_cq_get(struct lpfc_queue *q)
  257. {
  258. struct lpfc_cqe *cqe;
  259. /* If the next CQE is not valid then we are done */
  260. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  261. return NULL;
  262. /* If the host has not yet processed the next entry then we are done */
  263. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  264. return NULL;
  265. cqe = q->qe[q->hba_index].cqe;
  266. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  267. return cqe;
  268. }
  269. /**
  270. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  271. * @q: The Completion Queue that the host has completed processing for.
  272. * @arm: Indicates whether the host wants to arms this CQ.
  273. *
  274. * This routine will mark all Completion queue entries on @q, from the last
  275. * known completed entry to the last entry that was processed, as completed
  276. * by clearing the valid bit for each completion queue entry. Then it will
  277. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  278. * The internal host index in the @q will be updated by this routine to indicate
  279. * that the host has finished processing the entries. The @arm parameter
  280. * indicates that the queue should be rearmed when ringing the doorbell.
  281. *
  282. * This function will return the number of CQEs that were released.
  283. **/
  284. uint32_t
  285. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  286. {
  287. uint32_t released = 0;
  288. struct lpfc_cqe *temp_qe;
  289. struct lpfc_register doorbell;
  290. /* while there are valid entries */
  291. while (q->hba_index != q->host_index) {
  292. temp_qe = q->qe[q->host_index].cqe;
  293. bf_set(lpfc_cqe_valid, temp_qe, 0);
  294. released++;
  295. q->host_index = ((q->host_index + 1) % q->entry_count);
  296. }
  297. if (unlikely(released == 0 && !arm))
  298. return 0;
  299. /* ring doorbell for number popped */
  300. doorbell.word0 = 0;
  301. if (arm)
  302. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  303. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  304. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  305. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  306. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  307. return released;
  308. }
  309. /**
  310. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  311. * @q: The Header Receive Queue to operate on.
  312. * @wqe: The Receive Queue Entry to put on the Receive queue.
  313. *
  314. * This routine will copy the contents of @wqe to the next available entry on
  315. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  316. * HBA to start processing the Receive Queue Entry. This function returns the
  317. * index that the rqe was copied to if successful. If no entries are available
  318. * on @q then this function will return -ENOMEM.
  319. * The caller is expected to hold the hbalock when calling this routine.
  320. **/
  321. static int
  322. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  323. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  324. {
  325. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  326. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  327. struct lpfc_register doorbell;
  328. int put_index = hq->host_index;
  329. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  330. return -EINVAL;
  331. if (hq->host_index != dq->host_index)
  332. return -EINVAL;
  333. /* If the host has not yet processed the next entry then we are done */
  334. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  335. return -EBUSY;
  336. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  337. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  338. /* Update the host index to point to the next slot */
  339. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  340. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  341. /* Ring The Header Receive Queue Doorbell */
  342. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  343. doorbell.word0 = 0;
  344. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  345. LPFC_RQ_POST_BATCH);
  346. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  347. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  348. }
  349. return put_index;
  350. }
  351. /**
  352. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  353. * @q: The Header Receive Queue to operate on.
  354. *
  355. * This routine will update the HBA index of a queue to reflect consumption of
  356. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  357. * consumed an entry the host calls this function to update the queue's
  358. * internal pointers. This routine returns the number of entries that were
  359. * consumed by the HBA.
  360. **/
  361. static uint32_t
  362. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  363. {
  364. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  365. return 0;
  366. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  367. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  368. return 1;
  369. }
  370. /**
  371. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  372. * @phba: Pointer to HBA context object.
  373. * @pring: Pointer to driver SLI ring object.
  374. *
  375. * This function returns pointer to next command iocb entry
  376. * in the command ring. The caller must hold hbalock to prevent
  377. * other threads consume the next command iocb.
  378. * SLI-2/SLI-3 provide different sized iocbs.
  379. **/
  380. static inline IOCB_t *
  381. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  382. {
  383. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  384. pring->cmdidx * phba->iocb_cmd_size);
  385. }
  386. /**
  387. * lpfc_resp_iocb - Get next response iocb entry in the ring
  388. * @phba: Pointer to HBA context object.
  389. * @pring: Pointer to driver SLI ring object.
  390. *
  391. * This function returns pointer to next response iocb entry
  392. * in the response ring. The caller must hold hbalock to make sure
  393. * that no other thread consume the next response iocb.
  394. * SLI-2/SLI-3 provide different sized iocbs.
  395. **/
  396. static inline IOCB_t *
  397. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  398. {
  399. return (IOCB_t *) (((char *) pring->rspringaddr) +
  400. pring->rspidx * phba->iocb_rsp_size);
  401. }
  402. /**
  403. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  404. * @phba: Pointer to HBA context object.
  405. *
  406. * This function is called with hbalock held. This function
  407. * allocates a new driver iocb object from the iocb pool. If the
  408. * allocation is successful, it returns pointer to the newly
  409. * allocated iocb object else it returns NULL.
  410. **/
  411. static struct lpfc_iocbq *
  412. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  413. {
  414. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  415. struct lpfc_iocbq * iocbq = NULL;
  416. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  417. return iocbq;
  418. }
  419. /**
  420. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  421. * @phba: Pointer to HBA context object.
  422. * @xritag: XRI value.
  423. *
  424. * This function clears the sglq pointer from the array of acive
  425. * sglq's. The xritag that is passed in is used to index into the
  426. * array. Before the xritag can be used it needs to be adjusted
  427. * by subtracting the xribase.
  428. *
  429. * Returns sglq ponter = success, NULL = Failure.
  430. **/
  431. static struct lpfc_sglq *
  432. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  433. {
  434. uint16_t adj_xri;
  435. struct lpfc_sglq *sglq;
  436. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  437. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  438. return NULL;
  439. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  440. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  441. return sglq;
  442. }
  443. /**
  444. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  445. * @phba: Pointer to HBA context object.
  446. * @xritag: XRI value.
  447. *
  448. * This function returns the sglq pointer from the array of acive
  449. * sglq's. The xritag that is passed in is used to index into the
  450. * array. Before the xritag can be used it needs to be adjusted
  451. * by subtracting the xribase.
  452. *
  453. * Returns sglq ponter = success, NULL = Failure.
  454. **/
  455. static struct lpfc_sglq *
  456. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  457. {
  458. uint16_t adj_xri;
  459. struct lpfc_sglq *sglq;
  460. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  461. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  462. return NULL;
  463. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  464. return sglq;
  465. }
  466. /**
  467. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  468. * @phba: Pointer to HBA context object.
  469. *
  470. * This function is called with hbalock held. This function
  471. * Gets a new driver sglq object from the sglq list. If the
  472. * list is not empty then it is successful, it returns pointer to the newly
  473. * allocated sglq object else it returns NULL.
  474. **/
  475. static struct lpfc_sglq *
  476. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  477. {
  478. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  479. struct lpfc_sglq *sglq = NULL;
  480. uint16_t adj_xri;
  481. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  482. if (!sglq)
  483. return NULL;
  484. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  485. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  486. return sglq;
  487. }
  488. /**
  489. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  490. * @phba: Pointer to HBA context object.
  491. *
  492. * This function is called with no lock held. This function
  493. * allocates a new driver iocb object from the iocb pool. If the
  494. * allocation is successful, it returns pointer to the newly
  495. * allocated iocb object else it returns NULL.
  496. **/
  497. struct lpfc_iocbq *
  498. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  499. {
  500. struct lpfc_iocbq * iocbq = NULL;
  501. unsigned long iflags;
  502. spin_lock_irqsave(&phba->hbalock, iflags);
  503. iocbq = __lpfc_sli_get_iocbq(phba);
  504. spin_unlock_irqrestore(&phba->hbalock, iflags);
  505. return iocbq;
  506. }
  507. /**
  508. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  509. * @phba: Pointer to HBA context object.
  510. * @iocbq: Pointer to driver iocb object.
  511. *
  512. * This function is called with hbalock held to release driver
  513. * iocb object to the iocb pool. The iotag in the iocb object
  514. * does not change for each use of the iocb object. This function
  515. * clears all other fields of the iocb object when it is freed.
  516. * The sqlq structure that holds the xritag and phys and virtual
  517. * mappings for the scatter gather list is retrieved from the
  518. * active array of sglq. The get of the sglq pointer also clears
  519. * the entry in the array. If the status of the IO indiactes that
  520. * this IO was aborted then the sglq entry it put on the
  521. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  522. * IO has good status or fails for any other reason then the sglq
  523. * entry is added to the free list (lpfc_sgl_list).
  524. **/
  525. static void
  526. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  527. {
  528. struct lpfc_sglq *sglq;
  529. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  530. unsigned long iflag;
  531. if (iocbq->sli4_xritag == NO_XRI)
  532. sglq = NULL;
  533. else
  534. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  535. if (sglq) {
  536. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  537. && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  538. && (iocbq->iocb.un.ulpWord[4]
  539. == IOERR_ABORT_REQUESTED))) {
  540. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  541. iflag);
  542. list_add(&sglq->list,
  543. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  544. spin_unlock_irqrestore(
  545. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  546. } else
  547. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  548. }
  549. /*
  550. * Clean all volatile data fields, preserve iotag and node struct.
  551. */
  552. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  553. iocbq->sli4_xritag = NO_XRI;
  554. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  555. }
  556. /**
  557. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  558. * @phba: Pointer to HBA context object.
  559. * @iocbq: Pointer to driver iocb object.
  560. *
  561. * This function is called with hbalock held to release driver
  562. * iocb object to the iocb pool. The iotag in the iocb object
  563. * does not change for each use of the iocb object. This function
  564. * clears all other fields of the iocb object when it is freed.
  565. **/
  566. static void
  567. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  568. {
  569. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  570. /*
  571. * Clean all volatile data fields, preserve iotag and node struct.
  572. */
  573. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  574. iocbq->sli4_xritag = NO_XRI;
  575. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  576. }
  577. /**
  578. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  579. * @phba: Pointer to HBA context object.
  580. * @iocbq: Pointer to driver iocb object.
  581. *
  582. * This function is called with hbalock held to release driver
  583. * iocb object to the iocb pool. The iotag in the iocb object
  584. * does not change for each use of the iocb object. This function
  585. * clears all other fields of the iocb object when it is freed.
  586. **/
  587. static void
  588. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  589. {
  590. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  591. }
  592. /**
  593. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  594. * @phba: Pointer to HBA context object.
  595. * @iocbq: Pointer to driver iocb object.
  596. *
  597. * This function is called with no lock held to release the iocb to
  598. * iocb pool.
  599. **/
  600. void
  601. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  602. {
  603. unsigned long iflags;
  604. /*
  605. * Clean all volatile data fields, preserve iotag and node struct.
  606. */
  607. spin_lock_irqsave(&phba->hbalock, iflags);
  608. __lpfc_sli_release_iocbq(phba, iocbq);
  609. spin_unlock_irqrestore(&phba->hbalock, iflags);
  610. }
  611. /**
  612. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  613. * @phba: Pointer to HBA context object.
  614. * @iocblist: List of IOCBs.
  615. * @ulpstatus: ULP status in IOCB command field.
  616. * @ulpWord4: ULP word-4 in IOCB command field.
  617. *
  618. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  619. * on the list by invoking the complete callback function associated with the
  620. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  621. * fields.
  622. **/
  623. void
  624. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  625. uint32_t ulpstatus, uint32_t ulpWord4)
  626. {
  627. struct lpfc_iocbq *piocb;
  628. while (!list_empty(iocblist)) {
  629. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  630. if (!piocb->iocb_cmpl)
  631. lpfc_sli_release_iocbq(phba, piocb);
  632. else {
  633. piocb->iocb.ulpStatus = ulpstatus;
  634. piocb->iocb.un.ulpWord[4] = ulpWord4;
  635. (piocb->iocb_cmpl) (phba, piocb, piocb);
  636. }
  637. }
  638. return;
  639. }
  640. /**
  641. * lpfc_sli_iocb_cmd_type - Get the iocb type
  642. * @iocb_cmnd: iocb command code.
  643. *
  644. * This function is called by ring event handler function to get the iocb type.
  645. * This function translates the iocb command to an iocb command type used to
  646. * decide the final disposition of each completed IOCB.
  647. * The function returns
  648. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  649. * LPFC_SOL_IOCB if it is a solicited iocb completion
  650. * LPFC_ABORT_IOCB if it is an abort iocb
  651. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  652. *
  653. * The caller is not required to hold any lock.
  654. **/
  655. static lpfc_iocb_type
  656. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  657. {
  658. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  659. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  660. return 0;
  661. switch (iocb_cmnd) {
  662. case CMD_XMIT_SEQUENCE_CR:
  663. case CMD_XMIT_SEQUENCE_CX:
  664. case CMD_XMIT_BCAST_CN:
  665. case CMD_XMIT_BCAST_CX:
  666. case CMD_ELS_REQUEST_CR:
  667. case CMD_ELS_REQUEST_CX:
  668. case CMD_CREATE_XRI_CR:
  669. case CMD_CREATE_XRI_CX:
  670. case CMD_GET_RPI_CN:
  671. case CMD_XMIT_ELS_RSP_CX:
  672. case CMD_GET_RPI_CR:
  673. case CMD_FCP_IWRITE_CR:
  674. case CMD_FCP_IWRITE_CX:
  675. case CMD_FCP_IREAD_CR:
  676. case CMD_FCP_IREAD_CX:
  677. case CMD_FCP_ICMND_CR:
  678. case CMD_FCP_ICMND_CX:
  679. case CMD_FCP_TSEND_CX:
  680. case CMD_FCP_TRSP_CX:
  681. case CMD_FCP_TRECEIVE_CX:
  682. case CMD_FCP_AUTO_TRSP_CX:
  683. case CMD_ADAPTER_MSG:
  684. case CMD_ADAPTER_DUMP:
  685. case CMD_XMIT_SEQUENCE64_CR:
  686. case CMD_XMIT_SEQUENCE64_CX:
  687. case CMD_XMIT_BCAST64_CN:
  688. case CMD_XMIT_BCAST64_CX:
  689. case CMD_ELS_REQUEST64_CR:
  690. case CMD_ELS_REQUEST64_CX:
  691. case CMD_FCP_IWRITE64_CR:
  692. case CMD_FCP_IWRITE64_CX:
  693. case CMD_FCP_IREAD64_CR:
  694. case CMD_FCP_IREAD64_CX:
  695. case CMD_FCP_ICMND64_CR:
  696. case CMD_FCP_ICMND64_CX:
  697. case CMD_FCP_TSEND64_CX:
  698. case CMD_FCP_TRSP64_CX:
  699. case CMD_FCP_TRECEIVE64_CX:
  700. case CMD_GEN_REQUEST64_CR:
  701. case CMD_GEN_REQUEST64_CX:
  702. case CMD_XMIT_ELS_RSP64_CX:
  703. case DSSCMD_IWRITE64_CR:
  704. case DSSCMD_IWRITE64_CX:
  705. case DSSCMD_IREAD64_CR:
  706. case DSSCMD_IREAD64_CX:
  707. case DSSCMD_INVALIDATE_DEK:
  708. case DSSCMD_SET_KEK:
  709. case DSSCMD_GET_KEK_ID:
  710. case DSSCMD_GEN_XFER:
  711. type = LPFC_SOL_IOCB;
  712. break;
  713. case CMD_ABORT_XRI_CN:
  714. case CMD_ABORT_XRI_CX:
  715. case CMD_CLOSE_XRI_CN:
  716. case CMD_CLOSE_XRI_CX:
  717. case CMD_XRI_ABORTED_CX:
  718. case CMD_ABORT_MXRI64_CN:
  719. case CMD_XMIT_BLS_RSP64_CX:
  720. type = LPFC_ABORT_IOCB;
  721. break;
  722. case CMD_RCV_SEQUENCE_CX:
  723. case CMD_RCV_ELS_REQ_CX:
  724. case CMD_RCV_SEQUENCE64_CX:
  725. case CMD_RCV_ELS_REQ64_CX:
  726. case CMD_ASYNC_STATUS:
  727. case CMD_IOCB_RCV_SEQ64_CX:
  728. case CMD_IOCB_RCV_ELS64_CX:
  729. case CMD_IOCB_RCV_CONT64_CX:
  730. case CMD_IOCB_RET_XRI64_CX:
  731. type = LPFC_UNSOL_IOCB;
  732. break;
  733. case CMD_IOCB_XMIT_MSEQ64_CR:
  734. case CMD_IOCB_XMIT_MSEQ64_CX:
  735. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  736. case CMD_IOCB_RCV_ELS_LIST64_CX:
  737. case CMD_IOCB_CLOSE_EXTENDED_CN:
  738. case CMD_IOCB_ABORT_EXTENDED_CN:
  739. case CMD_IOCB_RET_HBQE64_CN:
  740. case CMD_IOCB_FCP_IBIDIR64_CR:
  741. case CMD_IOCB_FCP_IBIDIR64_CX:
  742. case CMD_IOCB_FCP_ITASKMGT64_CX:
  743. case CMD_IOCB_LOGENTRY_CN:
  744. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  745. printk("%s - Unhandled SLI-3 Command x%x\n",
  746. __func__, iocb_cmnd);
  747. type = LPFC_UNKNOWN_IOCB;
  748. break;
  749. default:
  750. type = LPFC_UNKNOWN_IOCB;
  751. break;
  752. }
  753. return type;
  754. }
  755. /**
  756. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  757. * @phba: Pointer to HBA context object.
  758. *
  759. * This function is called from SLI initialization code
  760. * to configure every ring of the HBA's SLI interface. The
  761. * caller is not required to hold any lock. This function issues
  762. * a config_ring mailbox command for each ring.
  763. * This function returns zero if successful else returns a negative
  764. * error code.
  765. **/
  766. static int
  767. lpfc_sli_ring_map(struct lpfc_hba *phba)
  768. {
  769. struct lpfc_sli *psli = &phba->sli;
  770. LPFC_MBOXQ_t *pmb;
  771. MAILBOX_t *pmbox;
  772. int i, rc, ret = 0;
  773. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  774. if (!pmb)
  775. return -ENOMEM;
  776. pmbox = &pmb->u.mb;
  777. phba->link_state = LPFC_INIT_MBX_CMDS;
  778. for (i = 0; i < psli->num_rings; i++) {
  779. lpfc_config_ring(phba, i, pmb);
  780. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  781. if (rc != MBX_SUCCESS) {
  782. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  783. "0446 Adapter failed to init (%d), "
  784. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  785. "ring %d\n",
  786. rc, pmbox->mbxCommand,
  787. pmbox->mbxStatus, i);
  788. phba->link_state = LPFC_HBA_ERROR;
  789. ret = -ENXIO;
  790. break;
  791. }
  792. }
  793. mempool_free(pmb, phba->mbox_mem_pool);
  794. return ret;
  795. }
  796. /**
  797. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  798. * @phba: Pointer to HBA context object.
  799. * @pring: Pointer to driver SLI ring object.
  800. * @piocb: Pointer to the driver iocb object.
  801. *
  802. * This function is called with hbalock held. The function adds the
  803. * new iocb to txcmplq of the given ring. This function always returns
  804. * 0. If this function is called for ELS ring, this function checks if
  805. * there is a vport associated with the ELS command. This function also
  806. * starts els_tmofunc timer if this is an ELS command.
  807. **/
  808. static int
  809. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  810. struct lpfc_iocbq *piocb)
  811. {
  812. list_add_tail(&piocb->list, &pring->txcmplq);
  813. pring->txcmplq_cnt++;
  814. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  815. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  816. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  817. if (!piocb->vport)
  818. BUG();
  819. else
  820. mod_timer(&piocb->vport->els_tmofunc,
  821. jiffies + HZ * (phba->fc_ratov << 1));
  822. }
  823. return 0;
  824. }
  825. /**
  826. * lpfc_sli_ringtx_get - Get first element of the txq
  827. * @phba: Pointer to HBA context object.
  828. * @pring: Pointer to driver SLI ring object.
  829. *
  830. * This function is called with hbalock held to get next
  831. * iocb in txq of the given ring. If there is any iocb in
  832. * the txq, the function returns first iocb in the list after
  833. * removing the iocb from the list, else it returns NULL.
  834. **/
  835. static struct lpfc_iocbq *
  836. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  837. {
  838. struct lpfc_iocbq *cmd_iocb;
  839. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  840. if (cmd_iocb != NULL)
  841. pring->txq_cnt--;
  842. return cmd_iocb;
  843. }
  844. /**
  845. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  846. * @phba: Pointer to HBA context object.
  847. * @pring: Pointer to driver SLI ring object.
  848. *
  849. * This function is called with hbalock held and the caller must post the
  850. * iocb without releasing the lock. If the caller releases the lock,
  851. * iocb slot returned by the function is not guaranteed to be available.
  852. * The function returns pointer to the next available iocb slot if there
  853. * is available slot in the ring, else it returns NULL.
  854. * If the get index of the ring is ahead of the put index, the function
  855. * will post an error attention event to the worker thread to take the
  856. * HBA to offline state.
  857. **/
  858. static IOCB_t *
  859. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  860. {
  861. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  862. uint32_t max_cmd_idx = pring->numCiocb;
  863. if ((pring->next_cmdidx == pring->cmdidx) &&
  864. (++pring->next_cmdidx >= max_cmd_idx))
  865. pring->next_cmdidx = 0;
  866. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  867. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  868. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  869. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  870. "0315 Ring %d issue: portCmdGet %d "
  871. "is bigger than cmd ring %d\n",
  872. pring->ringno,
  873. pring->local_getidx, max_cmd_idx);
  874. phba->link_state = LPFC_HBA_ERROR;
  875. /*
  876. * All error attention handlers are posted to
  877. * worker thread
  878. */
  879. phba->work_ha |= HA_ERATT;
  880. phba->work_hs = HS_FFER3;
  881. lpfc_worker_wake_up(phba);
  882. return NULL;
  883. }
  884. if (pring->local_getidx == pring->next_cmdidx)
  885. return NULL;
  886. }
  887. return lpfc_cmd_iocb(phba, pring);
  888. }
  889. /**
  890. * lpfc_sli_next_iotag - Get an iotag for the iocb
  891. * @phba: Pointer to HBA context object.
  892. * @iocbq: Pointer to driver iocb object.
  893. *
  894. * This function gets an iotag for the iocb. If there is no unused iotag and
  895. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  896. * array and assigns a new iotag.
  897. * The function returns the allocated iotag if successful, else returns zero.
  898. * Zero is not a valid iotag.
  899. * The caller is not required to hold any lock.
  900. **/
  901. uint16_t
  902. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  903. {
  904. struct lpfc_iocbq **new_arr;
  905. struct lpfc_iocbq **old_arr;
  906. size_t new_len;
  907. struct lpfc_sli *psli = &phba->sli;
  908. uint16_t iotag;
  909. spin_lock_irq(&phba->hbalock);
  910. iotag = psli->last_iotag;
  911. if(++iotag < psli->iocbq_lookup_len) {
  912. psli->last_iotag = iotag;
  913. psli->iocbq_lookup[iotag] = iocbq;
  914. spin_unlock_irq(&phba->hbalock);
  915. iocbq->iotag = iotag;
  916. return iotag;
  917. } else if (psli->iocbq_lookup_len < (0xffff
  918. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  919. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  920. spin_unlock_irq(&phba->hbalock);
  921. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  922. GFP_KERNEL);
  923. if (new_arr) {
  924. spin_lock_irq(&phba->hbalock);
  925. old_arr = psli->iocbq_lookup;
  926. if (new_len <= psli->iocbq_lookup_len) {
  927. /* highly unprobable case */
  928. kfree(new_arr);
  929. iotag = psli->last_iotag;
  930. if(++iotag < psli->iocbq_lookup_len) {
  931. psli->last_iotag = iotag;
  932. psli->iocbq_lookup[iotag] = iocbq;
  933. spin_unlock_irq(&phba->hbalock);
  934. iocbq->iotag = iotag;
  935. return iotag;
  936. }
  937. spin_unlock_irq(&phba->hbalock);
  938. return 0;
  939. }
  940. if (psli->iocbq_lookup)
  941. memcpy(new_arr, old_arr,
  942. ((psli->last_iotag + 1) *
  943. sizeof (struct lpfc_iocbq *)));
  944. psli->iocbq_lookup = new_arr;
  945. psli->iocbq_lookup_len = new_len;
  946. psli->last_iotag = iotag;
  947. psli->iocbq_lookup[iotag] = iocbq;
  948. spin_unlock_irq(&phba->hbalock);
  949. iocbq->iotag = iotag;
  950. kfree(old_arr);
  951. return iotag;
  952. }
  953. } else
  954. spin_unlock_irq(&phba->hbalock);
  955. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  956. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  957. psli->last_iotag);
  958. return 0;
  959. }
  960. /**
  961. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  962. * @phba: Pointer to HBA context object.
  963. * @pring: Pointer to driver SLI ring object.
  964. * @iocb: Pointer to iocb slot in the ring.
  965. * @nextiocb: Pointer to driver iocb object which need to be
  966. * posted to firmware.
  967. *
  968. * This function is called with hbalock held to post a new iocb to
  969. * the firmware. This function copies the new iocb to ring iocb slot and
  970. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  971. * a completion call back for this iocb else the function will free the
  972. * iocb object.
  973. **/
  974. static void
  975. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  976. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  977. {
  978. /*
  979. * Set up an iotag
  980. */
  981. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  982. if (pring->ringno == LPFC_ELS_RING) {
  983. lpfc_debugfs_slow_ring_trc(phba,
  984. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  985. *(((uint32_t *) &nextiocb->iocb) + 4),
  986. *(((uint32_t *) &nextiocb->iocb) + 6),
  987. *(((uint32_t *) &nextiocb->iocb) + 7));
  988. }
  989. /*
  990. * Issue iocb command to adapter
  991. */
  992. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  993. wmb();
  994. pring->stats.iocb_cmd++;
  995. /*
  996. * If there is no completion routine to call, we can release the
  997. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  998. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  999. */
  1000. if (nextiocb->iocb_cmpl)
  1001. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1002. else
  1003. __lpfc_sli_release_iocbq(phba, nextiocb);
  1004. /*
  1005. * Let the HBA know what IOCB slot will be the next one the
  1006. * driver will put a command into.
  1007. */
  1008. pring->cmdidx = pring->next_cmdidx;
  1009. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1010. }
  1011. /**
  1012. * lpfc_sli_update_full_ring - Update the chip attention register
  1013. * @phba: Pointer to HBA context object.
  1014. * @pring: Pointer to driver SLI ring object.
  1015. *
  1016. * The caller is not required to hold any lock for calling this function.
  1017. * This function updates the chip attention bits for the ring to inform firmware
  1018. * that there are pending work to be done for this ring and requests an
  1019. * interrupt when there is space available in the ring. This function is
  1020. * called when the driver is unable to post more iocbs to the ring due
  1021. * to unavailability of space in the ring.
  1022. **/
  1023. static void
  1024. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1025. {
  1026. int ringno = pring->ringno;
  1027. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1028. wmb();
  1029. /*
  1030. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1031. * The HBA will tell us when an IOCB entry is available.
  1032. */
  1033. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1034. readl(phba->CAregaddr); /* flush */
  1035. pring->stats.iocb_cmd_full++;
  1036. }
  1037. /**
  1038. * lpfc_sli_update_ring - Update chip attention register
  1039. * @phba: Pointer to HBA context object.
  1040. * @pring: Pointer to driver SLI ring object.
  1041. *
  1042. * This function updates the chip attention register bit for the
  1043. * given ring to inform HBA that there is more work to be done
  1044. * in this ring. The caller is not required to hold any lock.
  1045. **/
  1046. static void
  1047. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1048. {
  1049. int ringno = pring->ringno;
  1050. /*
  1051. * Tell the HBA that there is work to do in this ring.
  1052. */
  1053. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1054. wmb();
  1055. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1056. readl(phba->CAregaddr); /* flush */
  1057. }
  1058. }
  1059. /**
  1060. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1061. * @phba: Pointer to HBA context object.
  1062. * @pring: Pointer to driver SLI ring object.
  1063. *
  1064. * This function is called with hbalock held to post pending iocbs
  1065. * in the txq to the firmware. This function is called when driver
  1066. * detects space available in the ring.
  1067. **/
  1068. static void
  1069. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1070. {
  1071. IOCB_t *iocb;
  1072. struct lpfc_iocbq *nextiocb;
  1073. /*
  1074. * Check to see if:
  1075. * (a) there is anything on the txq to send
  1076. * (b) link is up
  1077. * (c) link attention events can be processed (fcp ring only)
  1078. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1079. */
  1080. if (pring->txq_cnt &&
  1081. lpfc_is_link_up(phba) &&
  1082. (pring->ringno != phba->sli.fcp_ring ||
  1083. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1084. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1085. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1086. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1087. if (iocb)
  1088. lpfc_sli_update_ring(phba, pring);
  1089. else
  1090. lpfc_sli_update_full_ring(phba, pring);
  1091. }
  1092. return;
  1093. }
  1094. /**
  1095. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1096. * @phba: Pointer to HBA context object.
  1097. * @hbqno: HBQ number.
  1098. *
  1099. * This function is called with hbalock held to get the next
  1100. * available slot for the given HBQ. If there is free slot
  1101. * available for the HBQ it will return pointer to the next available
  1102. * HBQ entry else it will return NULL.
  1103. **/
  1104. static struct lpfc_hbq_entry *
  1105. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1106. {
  1107. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1108. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1109. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1110. hbqp->next_hbqPutIdx = 0;
  1111. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1112. uint32_t raw_index = phba->hbq_get[hbqno];
  1113. uint32_t getidx = le32_to_cpu(raw_index);
  1114. hbqp->local_hbqGetIdx = getidx;
  1115. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1116. lpfc_printf_log(phba, KERN_ERR,
  1117. LOG_SLI | LOG_VPORT,
  1118. "1802 HBQ %d: local_hbqGetIdx "
  1119. "%u is > than hbqp->entry_count %u\n",
  1120. hbqno, hbqp->local_hbqGetIdx,
  1121. hbqp->entry_count);
  1122. phba->link_state = LPFC_HBA_ERROR;
  1123. return NULL;
  1124. }
  1125. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1126. return NULL;
  1127. }
  1128. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1129. hbqp->hbqPutIdx;
  1130. }
  1131. /**
  1132. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1133. * @phba: Pointer to HBA context object.
  1134. *
  1135. * This function is called with no lock held to free all the
  1136. * hbq buffers while uninitializing the SLI interface. It also
  1137. * frees the HBQ buffers returned by the firmware but not yet
  1138. * processed by the upper layers.
  1139. **/
  1140. void
  1141. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1142. {
  1143. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1144. struct hbq_dmabuf *hbq_buf;
  1145. unsigned long flags;
  1146. int i, hbq_count;
  1147. uint32_t hbqno;
  1148. hbq_count = lpfc_sli_hbq_count();
  1149. /* Return all memory used by all HBQs */
  1150. spin_lock_irqsave(&phba->hbalock, flags);
  1151. for (i = 0; i < hbq_count; ++i) {
  1152. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1153. &phba->hbqs[i].hbq_buffer_list, list) {
  1154. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1155. list_del(&hbq_buf->dbuf.list);
  1156. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1157. }
  1158. phba->hbqs[i].buffer_count = 0;
  1159. }
  1160. /* Return all HBQ buffer that are in-fly */
  1161. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1162. list) {
  1163. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1164. list_del(&hbq_buf->dbuf.list);
  1165. if (hbq_buf->tag == -1) {
  1166. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1167. (phba, hbq_buf);
  1168. } else {
  1169. hbqno = hbq_buf->tag >> 16;
  1170. if (hbqno >= LPFC_MAX_HBQS)
  1171. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1172. (phba, hbq_buf);
  1173. else
  1174. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1175. hbq_buf);
  1176. }
  1177. }
  1178. /* Mark the HBQs not in use */
  1179. phba->hbq_in_use = 0;
  1180. spin_unlock_irqrestore(&phba->hbalock, flags);
  1181. }
  1182. /**
  1183. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1184. * @phba: Pointer to HBA context object.
  1185. * @hbqno: HBQ number.
  1186. * @hbq_buf: Pointer to HBQ buffer.
  1187. *
  1188. * This function is called with the hbalock held to post a
  1189. * hbq buffer to the firmware. If the function finds an empty
  1190. * slot in the HBQ, it will post the buffer. The function will return
  1191. * pointer to the hbq entry if it successfully post the buffer
  1192. * else it will return NULL.
  1193. **/
  1194. static int
  1195. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1196. struct hbq_dmabuf *hbq_buf)
  1197. {
  1198. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1199. }
  1200. /**
  1201. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1202. * @phba: Pointer to HBA context object.
  1203. * @hbqno: HBQ number.
  1204. * @hbq_buf: Pointer to HBQ buffer.
  1205. *
  1206. * This function is called with the hbalock held to post a hbq buffer to the
  1207. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1208. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1209. * it successfully post the buffer else it will return an error.
  1210. **/
  1211. static int
  1212. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1213. struct hbq_dmabuf *hbq_buf)
  1214. {
  1215. struct lpfc_hbq_entry *hbqe;
  1216. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1217. /* Get next HBQ entry slot to use */
  1218. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1219. if (hbqe) {
  1220. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1221. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1222. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1223. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1224. hbqe->bde.tus.f.bdeFlags = 0;
  1225. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1226. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1227. /* Sync SLIM */
  1228. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1229. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1230. /* flush */
  1231. readl(phba->hbq_put + hbqno);
  1232. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1233. return 0;
  1234. } else
  1235. return -ENOMEM;
  1236. }
  1237. /**
  1238. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1239. * @phba: Pointer to HBA context object.
  1240. * @hbqno: HBQ number.
  1241. * @hbq_buf: Pointer to HBQ buffer.
  1242. *
  1243. * This function is called with the hbalock held to post an RQE to the SLI4
  1244. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1245. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1246. **/
  1247. static int
  1248. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1249. struct hbq_dmabuf *hbq_buf)
  1250. {
  1251. int rc;
  1252. struct lpfc_rqe hrqe;
  1253. struct lpfc_rqe drqe;
  1254. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1255. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1256. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1257. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1258. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1259. &hrqe, &drqe);
  1260. if (rc < 0)
  1261. return rc;
  1262. hbq_buf->tag = rc;
  1263. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1264. return 0;
  1265. }
  1266. /* HBQ for ELS and CT traffic. */
  1267. static struct lpfc_hbq_init lpfc_els_hbq = {
  1268. .rn = 1,
  1269. .entry_count = 256,
  1270. .mask_count = 0,
  1271. .profile = 0,
  1272. .ring_mask = (1 << LPFC_ELS_RING),
  1273. .buffer_count = 0,
  1274. .init_count = 40,
  1275. .add_count = 40,
  1276. };
  1277. /* HBQ for the extra ring if needed */
  1278. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1279. .rn = 1,
  1280. .entry_count = 200,
  1281. .mask_count = 0,
  1282. .profile = 0,
  1283. .ring_mask = (1 << LPFC_EXTRA_RING),
  1284. .buffer_count = 0,
  1285. .init_count = 0,
  1286. .add_count = 5,
  1287. };
  1288. /* Array of HBQs */
  1289. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1290. &lpfc_els_hbq,
  1291. &lpfc_extra_hbq,
  1292. };
  1293. /**
  1294. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1295. * @phba: Pointer to HBA context object.
  1296. * @hbqno: HBQ number.
  1297. * @count: Number of HBQ buffers to be posted.
  1298. *
  1299. * This function is called with no lock held to post more hbq buffers to the
  1300. * given HBQ. The function returns the number of HBQ buffers successfully
  1301. * posted.
  1302. **/
  1303. static int
  1304. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1305. {
  1306. uint32_t i, posted = 0;
  1307. unsigned long flags;
  1308. struct hbq_dmabuf *hbq_buffer;
  1309. LIST_HEAD(hbq_buf_list);
  1310. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1311. return 0;
  1312. if ((phba->hbqs[hbqno].buffer_count + count) >
  1313. lpfc_hbq_defs[hbqno]->entry_count)
  1314. count = lpfc_hbq_defs[hbqno]->entry_count -
  1315. phba->hbqs[hbqno].buffer_count;
  1316. if (!count)
  1317. return 0;
  1318. /* Allocate HBQ entries */
  1319. for (i = 0; i < count; i++) {
  1320. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1321. if (!hbq_buffer)
  1322. break;
  1323. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1324. }
  1325. /* Check whether HBQ is still in use */
  1326. spin_lock_irqsave(&phba->hbalock, flags);
  1327. if (!phba->hbq_in_use)
  1328. goto err;
  1329. while (!list_empty(&hbq_buf_list)) {
  1330. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1331. dbuf.list);
  1332. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1333. (hbqno << 16));
  1334. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1335. phba->hbqs[hbqno].buffer_count++;
  1336. posted++;
  1337. } else
  1338. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1339. }
  1340. spin_unlock_irqrestore(&phba->hbalock, flags);
  1341. return posted;
  1342. err:
  1343. spin_unlock_irqrestore(&phba->hbalock, flags);
  1344. while (!list_empty(&hbq_buf_list)) {
  1345. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1346. dbuf.list);
  1347. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1348. }
  1349. return 0;
  1350. }
  1351. /**
  1352. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1353. * @phba: Pointer to HBA context object.
  1354. * @qno: HBQ number.
  1355. *
  1356. * This function posts more buffers to the HBQ. This function
  1357. * is called with no lock held. The function returns the number of HBQ entries
  1358. * successfully allocated.
  1359. **/
  1360. int
  1361. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1362. {
  1363. if (phba->sli_rev == LPFC_SLI_REV4)
  1364. return 0;
  1365. else
  1366. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1367. lpfc_hbq_defs[qno]->add_count);
  1368. }
  1369. /**
  1370. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1371. * @phba: Pointer to HBA context object.
  1372. * @qno: HBQ queue number.
  1373. *
  1374. * This function is called from SLI initialization code path with
  1375. * no lock held to post initial HBQ buffers to firmware. The
  1376. * function returns the number of HBQ entries successfully allocated.
  1377. **/
  1378. static int
  1379. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1380. {
  1381. if (phba->sli_rev == LPFC_SLI_REV4)
  1382. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1383. lpfc_hbq_defs[qno]->entry_count);
  1384. else
  1385. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1386. lpfc_hbq_defs[qno]->init_count);
  1387. }
  1388. /**
  1389. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1390. * @phba: Pointer to HBA context object.
  1391. * @hbqno: HBQ number.
  1392. *
  1393. * This function removes the first hbq buffer on an hbq list and returns a
  1394. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1395. **/
  1396. static struct hbq_dmabuf *
  1397. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1398. {
  1399. struct lpfc_dmabuf *d_buf;
  1400. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1401. if (!d_buf)
  1402. return NULL;
  1403. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1404. }
  1405. /**
  1406. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1407. * @phba: Pointer to HBA context object.
  1408. * @tag: Tag of the hbq buffer.
  1409. *
  1410. * This function is called with hbalock held. This function searches
  1411. * for the hbq buffer associated with the given tag in the hbq buffer
  1412. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1413. * it returns NULL.
  1414. **/
  1415. static struct hbq_dmabuf *
  1416. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1417. {
  1418. struct lpfc_dmabuf *d_buf;
  1419. struct hbq_dmabuf *hbq_buf;
  1420. uint32_t hbqno;
  1421. hbqno = tag >> 16;
  1422. if (hbqno >= LPFC_MAX_HBQS)
  1423. return NULL;
  1424. spin_lock_irq(&phba->hbalock);
  1425. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1426. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1427. if (hbq_buf->tag == tag) {
  1428. spin_unlock_irq(&phba->hbalock);
  1429. return hbq_buf;
  1430. }
  1431. }
  1432. spin_unlock_irq(&phba->hbalock);
  1433. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1434. "1803 Bad hbq tag. Data: x%x x%x\n",
  1435. tag, phba->hbqs[tag >> 16].buffer_count);
  1436. return NULL;
  1437. }
  1438. /**
  1439. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1440. * @phba: Pointer to HBA context object.
  1441. * @hbq_buffer: Pointer to HBQ buffer.
  1442. *
  1443. * This function is called with hbalock. This function gives back
  1444. * the hbq buffer to firmware. If the HBQ does not have space to
  1445. * post the buffer, it will free the buffer.
  1446. **/
  1447. void
  1448. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1449. {
  1450. uint32_t hbqno;
  1451. if (hbq_buffer) {
  1452. hbqno = hbq_buffer->tag >> 16;
  1453. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1454. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1455. }
  1456. }
  1457. /**
  1458. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1459. * @mbxCommand: mailbox command code.
  1460. *
  1461. * This function is called by the mailbox event handler function to verify
  1462. * that the completed mailbox command is a legitimate mailbox command. If the
  1463. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1464. * and the mailbox event handler will take the HBA offline.
  1465. **/
  1466. static int
  1467. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1468. {
  1469. uint8_t ret;
  1470. switch (mbxCommand) {
  1471. case MBX_LOAD_SM:
  1472. case MBX_READ_NV:
  1473. case MBX_WRITE_NV:
  1474. case MBX_WRITE_VPARMS:
  1475. case MBX_RUN_BIU_DIAG:
  1476. case MBX_INIT_LINK:
  1477. case MBX_DOWN_LINK:
  1478. case MBX_CONFIG_LINK:
  1479. case MBX_CONFIG_RING:
  1480. case MBX_RESET_RING:
  1481. case MBX_READ_CONFIG:
  1482. case MBX_READ_RCONFIG:
  1483. case MBX_READ_SPARM:
  1484. case MBX_READ_STATUS:
  1485. case MBX_READ_RPI:
  1486. case MBX_READ_XRI:
  1487. case MBX_READ_REV:
  1488. case MBX_READ_LNK_STAT:
  1489. case MBX_REG_LOGIN:
  1490. case MBX_UNREG_LOGIN:
  1491. case MBX_READ_LA:
  1492. case MBX_CLEAR_LA:
  1493. case MBX_DUMP_MEMORY:
  1494. case MBX_DUMP_CONTEXT:
  1495. case MBX_RUN_DIAGS:
  1496. case MBX_RESTART:
  1497. case MBX_UPDATE_CFG:
  1498. case MBX_DOWN_LOAD:
  1499. case MBX_DEL_LD_ENTRY:
  1500. case MBX_RUN_PROGRAM:
  1501. case MBX_SET_MASK:
  1502. case MBX_SET_VARIABLE:
  1503. case MBX_UNREG_D_ID:
  1504. case MBX_KILL_BOARD:
  1505. case MBX_CONFIG_FARP:
  1506. case MBX_BEACON:
  1507. case MBX_LOAD_AREA:
  1508. case MBX_RUN_BIU_DIAG64:
  1509. case MBX_CONFIG_PORT:
  1510. case MBX_READ_SPARM64:
  1511. case MBX_READ_RPI64:
  1512. case MBX_REG_LOGIN64:
  1513. case MBX_READ_LA64:
  1514. case MBX_WRITE_WWN:
  1515. case MBX_SET_DEBUG:
  1516. case MBX_LOAD_EXP_ROM:
  1517. case MBX_ASYNCEVT_ENABLE:
  1518. case MBX_REG_VPI:
  1519. case MBX_UNREG_VPI:
  1520. case MBX_HEARTBEAT:
  1521. case MBX_PORT_CAPABILITIES:
  1522. case MBX_PORT_IOV_CONTROL:
  1523. case MBX_SLI4_CONFIG:
  1524. case MBX_SLI4_REQ_FTRS:
  1525. case MBX_REG_FCFI:
  1526. case MBX_UNREG_FCFI:
  1527. case MBX_REG_VFI:
  1528. case MBX_UNREG_VFI:
  1529. case MBX_INIT_VPI:
  1530. case MBX_INIT_VFI:
  1531. case MBX_RESUME_RPI:
  1532. ret = mbxCommand;
  1533. break;
  1534. default:
  1535. ret = MBX_SHUTDOWN;
  1536. break;
  1537. }
  1538. return ret;
  1539. }
  1540. /**
  1541. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1542. * @phba: Pointer to HBA context object.
  1543. * @pmboxq: Pointer to mailbox command.
  1544. *
  1545. * This is completion handler function for mailbox commands issued from
  1546. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1547. * mailbox event handler function with no lock held. This function
  1548. * will wake up thread waiting on the wait queue pointed by context1
  1549. * of the mailbox.
  1550. **/
  1551. void
  1552. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1553. {
  1554. wait_queue_head_t *pdone_q;
  1555. unsigned long drvr_flag;
  1556. /*
  1557. * If pdone_q is empty, the driver thread gave up waiting and
  1558. * continued running.
  1559. */
  1560. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1561. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1562. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1563. if (pdone_q)
  1564. wake_up_interruptible(pdone_q);
  1565. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1566. return;
  1567. }
  1568. /**
  1569. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1570. * @phba: Pointer to HBA context object.
  1571. * @pmb: Pointer to mailbox object.
  1572. *
  1573. * This function is the default mailbox completion handler. It
  1574. * frees the memory resources associated with the completed mailbox
  1575. * command. If the completed command is a REG_LOGIN mailbox command,
  1576. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1577. **/
  1578. void
  1579. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1580. {
  1581. struct lpfc_dmabuf *mp;
  1582. uint16_t rpi, vpi;
  1583. int rc;
  1584. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1585. if (mp) {
  1586. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1587. kfree(mp);
  1588. }
  1589. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1590. (phba->sli_rev == LPFC_SLI_REV4))
  1591. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1592. /*
  1593. * If a REG_LOGIN succeeded after node is destroyed or node
  1594. * is in re-discovery driver need to cleanup the RPI.
  1595. */
  1596. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1597. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1598. !pmb->u.mb.mbxStatus) {
  1599. rpi = pmb->u.mb.un.varWords[0];
  1600. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1601. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1602. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1603. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1604. if (rc != MBX_NOT_FINISHED)
  1605. return;
  1606. }
  1607. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1608. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1609. else
  1610. mempool_free(pmb, phba->mbox_mem_pool);
  1611. }
  1612. /**
  1613. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1614. * @phba: Pointer to HBA context object.
  1615. *
  1616. * This function is called with no lock held. This function processes all
  1617. * the completed mailbox commands and gives it to upper layers. The interrupt
  1618. * service routine processes mailbox completion interrupt and adds completed
  1619. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1620. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1621. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1622. * function returns the mailbox commands to the upper layer by calling the
  1623. * completion handler function of each mailbox.
  1624. **/
  1625. int
  1626. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1627. {
  1628. MAILBOX_t *pmbox;
  1629. LPFC_MBOXQ_t *pmb;
  1630. int rc;
  1631. LIST_HEAD(cmplq);
  1632. phba->sli.slistat.mbox_event++;
  1633. /* Get all completed mailboxe buffers into the cmplq */
  1634. spin_lock_irq(&phba->hbalock);
  1635. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1636. spin_unlock_irq(&phba->hbalock);
  1637. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1638. do {
  1639. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1640. if (pmb == NULL)
  1641. break;
  1642. pmbox = &pmb->u.mb;
  1643. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1644. if (pmb->vport) {
  1645. lpfc_debugfs_disc_trc(pmb->vport,
  1646. LPFC_DISC_TRC_MBOX_VPORT,
  1647. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1648. (uint32_t)pmbox->mbxCommand,
  1649. pmbox->un.varWords[0],
  1650. pmbox->un.varWords[1]);
  1651. }
  1652. else {
  1653. lpfc_debugfs_disc_trc(phba->pport,
  1654. LPFC_DISC_TRC_MBOX,
  1655. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1656. (uint32_t)pmbox->mbxCommand,
  1657. pmbox->un.varWords[0],
  1658. pmbox->un.varWords[1]);
  1659. }
  1660. }
  1661. /*
  1662. * It is a fatal error if unknown mbox command completion.
  1663. */
  1664. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1665. MBX_SHUTDOWN) {
  1666. /* Unknown mailbox command compl */
  1667. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1668. "(%d):0323 Unknown Mailbox command "
  1669. "x%x (x%x) Cmpl\n",
  1670. pmb->vport ? pmb->vport->vpi : 0,
  1671. pmbox->mbxCommand,
  1672. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1673. phba->link_state = LPFC_HBA_ERROR;
  1674. phba->work_hs = HS_FFER3;
  1675. lpfc_handle_eratt(phba);
  1676. continue;
  1677. }
  1678. if (pmbox->mbxStatus) {
  1679. phba->sli.slistat.mbox_stat_err++;
  1680. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1681. /* Mbox cmd cmpl error - RETRYing */
  1682. lpfc_printf_log(phba, KERN_INFO,
  1683. LOG_MBOX | LOG_SLI,
  1684. "(%d):0305 Mbox cmd cmpl "
  1685. "error - RETRYing Data: x%x "
  1686. "(x%x) x%x x%x x%x\n",
  1687. pmb->vport ? pmb->vport->vpi :0,
  1688. pmbox->mbxCommand,
  1689. lpfc_sli4_mbox_opcode_get(phba,
  1690. pmb),
  1691. pmbox->mbxStatus,
  1692. pmbox->un.varWords[0],
  1693. pmb->vport->port_state);
  1694. pmbox->mbxStatus = 0;
  1695. pmbox->mbxOwner = OWN_HOST;
  1696. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1697. if (rc != MBX_NOT_FINISHED)
  1698. continue;
  1699. }
  1700. }
  1701. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1702. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1703. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1704. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1705. pmb->vport ? pmb->vport->vpi : 0,
  1706. pmbox->mbxCommand,
  1707. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1708. pmb->mbox_cmpl,
  1709. *((uint32_t *) pmbox),
  1710. pmbox->un.varWords[0],
  1711. pmbox->un.varWords[1],
  1712. pmbox->un.varWords[2],
  1713. pmbox->un.varWords[3],
  1714. pmbox->un.varWords[4],
  1715. pmbox->un.varWords[5],
  1716. pmbox->un.varWords[6],
  1717. pmbox->un.varWords[7]);
  1718. if (pmb->mbox_cmpl)
  1719. pmb->mbox_cmpl(phba,pmb);
  1720. } while (1);
  1721. return 0;
  1722. }
  1723. /**
  1724. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1725. * @phba: Pointer to HBA context object.
  1726. * @pring: Pointer to driver SLI ring object.
  1727. * @tag: buffer tag.
  1728. *
  1729. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1730. * is set in the tag the buffer is posted for a particular exchange,
  1731. * the function will return the buffer without replacing the buffer.
  1732. * If the buffer is for unsolicited ELS or CT traffic, this function
  1733. * returns the buffer and also posts another buffer to the firmware.
  1734. **/
  1735. static struct lpfc_dmabuf *
  1736. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1737. struct lpfc_sli_ring *pring,
  1738. uint32_t tag)
  1739. {
  1740. struct hbq_dmabuf *hbq_entry;
  1741. if (tag & QUE_BUFTAG_BIT)
  1742. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1743. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1744. if (!hbq_entry)
  1745. return NULL;
  1746. return &hbq_entry->dbuf;
  1747. }
  1748. /**
  1749. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1750. * @phba: Pointer to HBA context object.
  1751. * @pring: Pointer to driver SLI ring object.
  1752. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1753. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1754. * @fch_type: the type for the first frame of the sequence.
  1755. *
  1756. * This function is called with no lock held. This function uses the r_ctl and
  1757. * type of the received sequence to find the correct callback function to call
  1758. * to process the sequence.
  1759. **/
  1760. static int
  1761. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1762. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1763. uint32_t fch_type)
  1764. {
  1765. int i;
  1766. /* unSolicited Responses */
  1767. if (pring->prt[0].profile) {
  1768. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1769. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1770. saveq);
  1771. return 1;
  1772. }
  1773. /* We must search, based on rctl / type
  1774. for the right routine */
  1775. for (i = 0; i < pring->num_mask; i++) {
  1776. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1777. (pring->prt[i].type == fch_type)) {
  1778. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1779. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1780. (phba, pring, saveq);
  1781. return 1;
  1782. }
  1783. }
  1784. return 0;
  1785. }
  1786. /**
  1787. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1788. * @phba: Pointer to HBA context object.
  1789. * @pring: Pointer to driver SLI ring object.
  1790. * @saveq: Pointer to the unsolicited iocb.
  1791. *
  1792. * This function is called with no lock held by the ring event handler
  1793. * when there is an unsolicited iocb posted to the response ring by the
  1794. * firmware. This function gets the buffer associated with the iocbs
  1795. * and calls the event handler for the ring. This function handles both
  1796. * qring buffers and hbq buffers.
  1797. * When the function returns 1 the caller can free the iocb object otherwise
  1798. * upper layer functions will free the iocb objects.
  1799. **/
  1800. static int
  1801. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1802. struct lpfc_iocbq *saveq)
  1803. {
  1804. IOCB_t * irsp;
  1805. WORD5 * w5p;
  1806. uint32_t Rctl, Type;
  1807. uint32_t match;
  1808. struct lpfc_iocbq *iocbq;
  1809. struct lpfc_dmabuf *dmzbuf;
  1810. match = 0;
  1811. irsp = &(saveq->iocb);
  1812. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1813. if (pring->lpfc_sli_rcv_async_status)
  1814. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1815. else
  1816. lpfc_printf_log(phba,
  1817. KERN_WARNING,
  1818. LOG_SLI,
  1819. "0316 Ring %d handler: unexpected "
  1820. "ASYNC_STATUS iocb received evt_code "
  1821. "0x%x\n",
  1822. pring->ringno,
  1823. irsp->un.asyncstat.evt_code);
  1824. return 1;
  1825. }
  1826. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1827. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1828. if (irsp->ulpBdeCount > 0) {
  1829. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1830. irsp->un.ulpWord[3]);
  1831. lpfc_in_buf_free(phba, dmzbuf);
  1832. }
  1833. if (irsp->ulpBdeCount > 1) {
  1834. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1835. irsp->unsli3.sli3Words[3]);
  1836. lpfc_in_buf_free(phba, dmzbuf);
  1837. }
  1838. if (irsp->ulpBdeCount > 2) {
  1839. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1840. irsp->unsli3.sli3Words[7]);
  1841. lpfc_in_buf_free(phba, dmzbuf);
  1842. }
  1843. return 1;
  1844. }
  1845. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1846. if (irsp->ulpBdeCount != 0) {
  1847. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1848. irsp->un.ulpWord[3]);
  1849. if (!saveq->context2)
  1850. lpfc_printf_log(phba,
  1851. KERN_ERR,
  1852. LOG_SLI,
  1853. "0341 Ring %d Cannot find buffer for "
  1854. "an unsolicited iocb. tag 0x%x\n",
  1855. pring->ringno,
  1856. irsp->un.ulpWord[3]);
  1857. }
  1858. if (irsp->ulpBdeCount == 2) {
  1859. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1860. irsp->unsli3.sli3Words[7]);
  1861. if (!saveq->context3)
  1862. lpfc_printf_log(phba,
  1863. KERN_ERR,
  1864. LOG_SLI,
  1865. "0342 Ring %d Cannot find buffer for an"
  1866. " unsolicited iocb. tag 0x%x\n",
  1867. pring->ringno,
  1868. irsp->unsli3.sli3Words[7]);
  1869. }
  1870. list_for_each_entry(iocbq, &saveq->list, list) {
  1871. irsp = &(iocbq->iocb);
  1872. if (irsp->ulpBdeCount != 0) {
  1873. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1874. irsp->un.ulpWord[3]);
  1875. if (!iocbq->context2)
  1876. lpfc_printf_log(phba,
  1877. KERN_ERR,
  1878. LOG_SLI,
  1879. "0343 Ring %d Cannot find "
  1880. "buffer for an unsolicited iocb"
  1881. ". tag 0x%x\n", pring->ringno,
  1882. irsp->un.ulpWord[3]);
  1883. }
  1884. if (irsp->ulpBdeCount == 2) {
  1885. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1886. irsp->unsli3.sli3Words[7]);
  1887. if (!iocbq->context3)
  1888. lpfc_printf_log(phba,
  1889. KERN_ERR,
  1890. LOG_SLI,
  1891. "0344 Ring %d Cannot find "
  1892. "buffer for an unsolicited "
  1893. "iocb. tag 0x%x\n",
  1894. pring->ringno,
  1895. irsp->unsli3.sli3Words[7]);
  1896. }
  1897. }
  1898. }
  1899. if (irsp->ulpBdeCount != 0 &&
  1900. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1901. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1902. int found = 0;
  1903. /* search continue save q for same XRI */
  1904. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1905. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1906. list_add_tail(&saveq->list, &iocbq->list);
  1907. found = 1;
  1908. break;
  1909. }
  1910. }
  1911. if (!found)
  1912. list_add_tail(&saveq->clist,
  1913. &pring->iocb_continue_saveq);
  1914. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1915. list_del_init(&iocbq->clist);
  1916. saveq = iocbq;
  1917. irsp = &(saveq->iocb);
  1918. } else
  1919. return 0;
  1920. }
  1921. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1922. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1923. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1924. Rctl = FC_RCTL_ELS_REQ;
  1925. Type = FC_TYPE_ELS;
  1926. } else {
  1927. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1928. Rctl = w5p->hcsw.Rctl;
  1929. Type = w5p->hcsw.Type;
  1930. /* Firmware Workaround */
  1931. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1932. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1933. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1934. Rctl = FC_RCTL_ELS_REQ;
  1935. Type = FC_TYPE_ELS;
  1936. w5p->hcsw.Rctl = Rctl;
  1937. w5p->hcsw.Type = Type;
  1938. }
  1939. }
  1940. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1941. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1942. "0313 Ring %d handler: unexpected Rctl x%x "
  1943. "Type x%x received\n",
  1944. pring->ringno, Rctl, Type);
  1945. return 1;
  1946. }
  1947. /**
  1948. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1949. * @phba: Pointer to HBA context object.
  1950. * @pring: Pointer to driver SLI ring object.
  1951. * @prspiocb: Pointer to response iocb object.
  1952. *
  1953. * This function looks up the iocb_lookup table to get the command iocb
  1954. * corresponding to the given response iocb using the iotag of the
  1955. * response iocb. This function is called with the hbalock held.
  1956. * This function returns the command iocb object if it finds the command
  1957. * iocb else returns NULL.
  1958. **/
  1959. static struct lpfc_iocbq *
  1960. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1961. struct lpfc_sli_ring *pring,
  1962. struct lpfc_iocbq *prspiocb)
  1963. {
  1964. struct lpfc_iocbq *cmd_iocb = NULL;
  1965. uint16_t iotag;
  1966. iotag = prspiocb->iocb.ulpIoTag;
  1967. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1968. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1969. list_del_init(&cmd_iocb->list);
  1970. pring->txcmplq_cnt--;
  1971. return cmd_iocb;
  1972. }
  1973. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1974. "0317 iotag x%x is out off "
  1975. "range: max iotag x%x wd0 x%x\n",
  1976. iotag, phba->sli.last_iotag,
  1977. *(((uint32_t *) &prspiocb->iocb) + 7));
  1978. return NULL;
  1979. }
  1980. /**
  1981. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1982. * @phba: Pointer to HBA context object.
  1983. * @pring: Pointer to driver SLI ring object.
  1984. * @iotag: IOCB tag.
  1985. *
  1986. * This function looks up the iocb_lookup table to get the command iocb
  1987. * corresponding to the given iotag. This function is called with the
  1988. * hbalock held.
  1989. * This function returns the command iocb object if it finds the command
  1990. * iocb else returns NULL.
  1991. **/
  1992. static struct lpfc_iocbq *
  1993. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1994. struct lpfc_sli_ring *pring, uint16_t iotag)
  1995. {
  1996. struct lpfc_iocbq *cmd_iocb;
  1997. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1998. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1999. list_del_init(&cmd_iocb->list);
  2000. pring->txcmplq_cnt--;
  2001. return cmd_iocb;
  2002. }
  2003. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2004. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2005. iotag, phba->sli.last_iotag);
  2006. return NULL;
  2007. }
  2008. /**
  2009. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2010. * @phba: Pointer to HBA context object.
  2011. * @pring: Pointer to driver SLI ring object.
  2012. * @saveq: Pointer to the response iocb to be processed.
  2013. *
  2014. * This function is called by the ring event handler for non-fcp
  2015. * rings when there is a new response iocb in the response ring.
  2016. * The caller is not required to hold any locks. This function
  2017. * gets the command iocb associated with the response iocb and
  2018. * calls the completion handler for the command iocb. If there
  2019. * is no completion handler, the function will free the resources
  2020. * associated with command iocb. If the response iocb is for
  2021. * an already aborted command iocb, the status of the completion
  2022. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2023. * This function always returns 1.
  2024. **/
  2025. static int
  2026. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2027. struct lpfc_iocbq *saveq)
  2028. {
  2029. struct lpfc_iocbq *cmdiocbp;
  2030. int rc = 1;
  2031. unsigned long iflag;
  2032. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2033. spin_lock_irqsave(&phba->hbalock, iflag);
  2034. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2035. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2036. if (cmdiocbp) {
  2037. if (cmdiocbp->iocb_cmpl) {
  2038. /*
  2039. * If an ELS command failed send an event to mgmt
  2040. * application.
  2041. */
  2042. if (saveq->iocb.ulpStatus &&
  2043. (pring->ringno == LPFC_ELS_RING) &&
  2044. (cmdiocbp->iocb.ulpCommand ==
  2045. CMD_ELS_REQUEST64_CR))
  2046. lpfc_send_els_failure_event(phba,
  2047. cmdiocbp, saveq);
  2048. /*
  2049. * Post all ELS completions to the worker thread.
  2050. * All other are passed to the completion callback.
  2051. */
  2052. if (pring->ringno == LPFC_ELS_RING) {
  2053. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2054. cmdiocbp->iocb_flag &=
  2055. ~LPFC_DRIVER_ABORTED;
  2056. saveq->iocb.ulpStatus =
  2057. IOSTAT_LOCAL_REJECT;
  2058. saveq->iocb.un.ulpWord[4] =
  2059. IOERR_SLI_ABORTED;
  2060. /* Firmware could still be in progress
  2061. * of DMAing payload, so don't free data
  2062. * buffer till after a hbeat.
  2063. */
  2064. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2065. }
  2066. }
  2067. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2068. } else
  2069. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2070. } else {
  2071. /*
  2072. * Unknown initiating command based on the response iotag.
  2073. * This could be the case on the ELS ring because of
  2074. * lpfc_els_abort().
  2075. */
  2076. if (pring->ringno != LPFC_ELS_RING) {
  2077. /*
  2078. * Ring <ringno> handler: unexpected completion IoTag
  2079. * <IoTag>
  2080. */
  2081. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2082. "0322 Ring %d handler: "
  2083. "unexpected completion IoTag x%x "
  2084. "Data: x%x x%x x%x x%x\n",
  2085. pring->ringno,
  2086. saveq->iocb.ulpIoTag,
  2087. saveq->iocb.ulpStatus,
  2088. saveq->iocb.un.ulpWord[4],
  2089. saveq->iocb.ulpCommand,
  2090. saveq->iocb.ulpContext);
  2091. }
  2092. }
  2093. return rc;
  2094. }
  2095. /**
  2096. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2097. * @phba: Pointer to HBA context object.
  2098. * @pring: Pointer to driver SLI ring object.
  2099. *
  2100. * This function is called from the iocb ring event handlers when
  2101. * put pointer is ahead of the get pointer for a ring. This function signal
  2102. * an error attention condition to the worker thread and the worker
  2103. * thread will transition the HBA to offline state.
  2104. **/
  2105. static void
  2106. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2107. {
  2108. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2109. /*
  2110. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2111. * rsp ring <portRspMax>
  2112. */
  2113. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2114. "0312 Ring %d handler: portRspPut %d "
  2115. "is bigger than rsp ring %d\n",
  2116. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2117. pring->numRiocb);
  2118. phba->link_state = LPFC_HBA_ERROR;
  2119. /*
  2120. * All error attention handlers are posted to
  2121. * worker thread
  2122. */
  2123. phba->work_ha |= HA_ERATT;
  2124. phba->work_hs = HS_FFER3;
  2125. lpfc_worker_wake_up(phba);
  2126. return;
  2127. }
  2128. /**
  2129. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2130. * @ptr: Pointer to address of HBA context object.
  2131. *
  2132. * This function is invoked by the Error Attention polling timer when the
  2133. * timer times out. It will check the SLI Error Attention register for
  2134. * possible attention events. If so, it will post an Error Attention event
  2135. * and wake up worker thread to process it. Otherwise, it will set up the
  2136. * Error Attention polling timer for the next poll.
  2137. **/
  2138. void lpfc_poll_eratt(unsigned long ptr)
  2139. {
  2140. struct lpfc_hba *phba;
  2141. uint32_t eratt = 0;
  2142. phba = (struct lpfc_hba *)ptr;
  2143. /* Check chip HA register for error event */
  2144. eratt = lpfc_sli_check_eratt(phba);
  2145. if (eratt)
  2146. /* Tell the worker thread there is work to do */
  2147. lpfc_worker_wake_up(phba);
  2148. else
  2149. /* Restart the timer for next eratt poll */
  2150. mod_timer(&phba->eratt_poll, jiffies +
  2151. HZ * LPFC_ERATT_POLL_INTERVAL);
  2152. return;
  2153. }
  2154. /**
  2155. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2156. * @phba: Pointer to HBA context object.
  2157. * @pring: Pointer to driver SLI ring object.
  2158. * @mask: Host attention register mask for this ring.
  2159. *
  2160. * This function is called from the interrupt context when there is a ring
  2161. * event for the fcp ring. The caller does not hold any lock.
  2162. * The function processes each response iocb in the response ring until it
  2163. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2164. * LE bit set. The function will call the completion handler of the command iocb
  2165. * if the response iocb indicates a completion for a command iocb or it is
  2166. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2167. * function if this is an unsolicited iocb.
  2168. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2169. * to check it explicitly.
  2170. */
  2171. int
  2172. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2173. struct lpfc_sli_ring *pring, uint32_t mask)
  2174. {
  2175. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2176. IOCB_t *irsp = NULL;
  2177. IOCB_t *entry = NULL;
  2178. struct lpfc_iocbq *cmdiocbq = NULL;
  2179. struct lpfc_iocbq rspiocbq;
  2180. uint32_t status;
  2181. uint32_t portRspPut, portRspMax;
  2182. int rc = 1;
  2183. lpfc_iocb_type type;
  2184. unsigned long iflag;
  2185. uint32_t rsp_cmpl = 0;
  2186. spin_lock_irqsave(&phba->hbalock, iflag);
  2187. pring->stats.iocb_event++;
  2188. /*
  2189. * The next available response entry should never exceed the maximum
  2190. * entries. If it does, treat it as an adapter hardware error.
  2191. */
  2192. portRspMax = pring->numRiocb;
  2193. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2194. if (unlikely(portRspPut >= portRspMax)) {
  2195. lpfc_sli_rsp_pointers_error(phba, pring);
  2196. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2197. return 1;
  2198. }
  2199. if (phba->fcp_ring_in_use) {
  2200. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2201. return 1;
  2202. } else
  2203. phba->fcp_ring_in_use = 1;
  2204. rmb();
  2205. while (pring->rspidx != portRspPut) {
  2206. /*
  2207. * Fetch an entry off the ring and copy it into a local data
  2208. * structure. The copy involves a byte-swap since the
  2209. * network byte order and pci byte orders are different.
  2210. */
  2211. entry = lpfc_resp_iocb(phba, pring);
  2212. phba->last_completion_time = jiffies;
  2213. if (++pring->rspidx >= portRspMax)
  2214. pring->rspidx = 0;
  2215. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2216. (uint32_t *) &rspiocbq.iocb,
  2217. phba->iocb_rsp_size);
  2218. INIT_LIST_HEAD(&(rspiocbq.list));
  2219. irsp = &rspiocbq.iocb;
  2220. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2221. pring->stats.iocb_rsp++;
  2222. rsp_cmpl++;
  2223. if (unlikely(irsp->ulpStatus)) {
  2224. /*
  2225. * If resource errors reported from HBA, reduce
  2226. * queuedepths of the SCSI device.
  2227. */
  2228. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2229. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2230. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2231. phba->lpfc_rampdown_queue_depth(phba);
  2232. spin_lock_irqsave(&phba->hbalock, iflag);
  2233. }
  2234. /* Rsp ring <ringno> error: IOCB */
  2235. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2236. "0336 Rsp Ring %d error: IOCB Data: "
  2237. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2238. pring->ringno,
  2239. irsp->un.ulpWord[0],
  2240. irsp->un.ulpWord[1],
  2241. irsp->un.ulpWord[2],
  2242. irsp->un.ulpWord[3],
  2243. irsp->un.ulpWord[4],
  2244. irsp->un.ulpWord[5],
  2245. *(uint32_t *)&irsp->un1,
  2246. *((uint32_t *)&irsp->un1 + 1));
  2247. }
  2248. switch (type) {
  2249. case LPFC_ABORT_IOCB:
  2250. case LPFC_SOL_IOCB:
  2251. /*
  2252. * Idle exchange closed via ABTS from port. No iocb
  2253. * resources need to be recovered.
  2254. */
  2255. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2256. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2257. "0333 IOCB cmd 0x%x"
  2258. " processed. Skipping"
  2259. " completion\n",
  2260. irsp->ulpCommand);
  2261. break;
  2262. }
  2263. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2264. &rspiocbq);
  2265. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2266. spin_unlock_irqrestore(&phba->hbalock,
  2267. iflag);
  2268. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2269. &rspiocbq);
  2270. spin_lock_irqsave(&phba->hbalock,
  2271. iflag);
  2272. }
  2273. break;
  2274. case LPFC_UNSOL_IOCB:
  2275. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2276. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2277. spin_lock_irqsave(&phba->hbalock, iflag);
  2278. break;
  2279. default:
  2280. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2281. char adaptermsg[LPFC_MAX_ADPTMSG];
  2282. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2283. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2284. MAX_MSG_DATA);
  2285. dev_warn(&((phba->pcidev)->dev),
  2286. "lpfc%d: %s\n",
  2287. phba->brd_no, adaptermsg);
  2288. } else {
  2289. /* Unknown IOCB command */
  2290. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2291. "0334 Unknown IOCB command "
  2292. "Data: x%x, x%x x%x x%x x%x\n",
  2293. type, irsp->ulpCommand,
  2294. irsp->ulpStatus,
  2295. irsp->ulpIoTag,
  2296. irsp->ulpContext);
  2297. }
  2298. break;
  2299. }
  2300. /*
  2301. * The response IOCB has been processed. Update the ring
  2302. * pointer in SLIM. If the port response put pointer has not
  2303. * been updated, sync the pgp->rspPutInx and fetch the new port
  2304. * response put pointer.
  2305. */
  2306. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2307. if (pring->rspidx == portRspPut)
  2308. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2309. }
  2310. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2311. pring->stats.iocb_rsp_full++;
  2312. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2313. writel(status, phba->CAregaddr);
  2314. readl(phba->CAregaddr);
  2315. }
  2316. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2317. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2318. pring->stats.iocb_cmd_empty++;
  2319. /* Force update of the local copy of cmdGetInx */
  2320. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2321. lpfc_sli_resume_iocb(phba, pring);
  2322. if ((pring->lpfc_sli_cmd_available))
  2323. (pring->lpfc_sli_cmd_available) (phba, pring);
  2324. }
  2325. phba->fcp_ring_in_use = 0;
  2326. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2327. return rc;
  2328. }
  2329. /**
  2330. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2331. * @phba: Pointer to HBA context object.
  2332. * @pring: Pointer to driver SLI ring object.
  2333. * @rspiocbp: Pointer to driver response IOCB object.
  2334. *
  2335. * This function is called from the worker thread when there is a slow-path
  2336. * response IOCB to process. This function chains all the response iocbs until
  2337. * seeing the iocb with the LE bit set. The function will call
  2338. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2339. * completion of a command iocb. The function will call the
  2340. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2341. * The function frees the resources or calls the completion handler if this
  2342. * iocb is an abort completion. The function returns NULL when the response
  2343. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2344. * this function shall chain the iocb on to the iocb_continueq and return the
  2345. * response iocb passed in.
  2346. **/
  2347. static struct lpfc_iocbq *
  2348. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2349. struct lpfc_iocbq *rspiocbp)
  2350. {
  2351. struct lpfc_iocbq *saveq;
  2352. struct lpfc_iocbq *cmdiocbp;
  2353. struct lpfc_iocbq *next_iocb;
  2354. IOCB_t *irsp = NULL;
  2355. uint32_t free_saveq;
  2356. uint8_t iocb_cmd_type;
  2357. lpfc_iocb_type type;
  2358. unsigned long iflag;
  2359. int rc;
  2360. spin_lock_irqsave(&phba->hbalock, iflag);
  2361. /* First add the response iocb to the countinueq list */
  2362. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2363. pring->iocb_continueq_cnt++;
  2364. /* Now, determine whetehr the list is completed for processing */
  2365. irsp = &rspiocbp->iocb;
  2366. if (irsp->ulpLe) {
  2367. /*
  2368. * By default, the driver expects to free all resources
  2369. * associated with this iocb completion.
  2370. */
  2371. free_saveq = 1;
  2372. saveq = list_get_first(&pring->iocb_continueq,
  2373. struct lpfc_iocbq, list);
  2374. irsp = &(saveq->iocb);
  2375. list_del_init(&pring->iocb_continueq);
  2376. pring->iocb_continueq_cnt = 0;
  2377. pring->stats.iocb_rsp++;
  2378. /*
  2379. * If resource errors reported from HBA, reduce
  2380. * queuedepths of the SCSI device.
  2381. */
  2382. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2383. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2384. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2385. phba->lpfc_rampdown_queue_depth(phba);
  2386. spin_lock_irqsave(&phba->hbalock, iflag);
  2387. }
  2388. if (irsp->ulpStatus) {
  2389. /* Rsp ring <ringno> error: IOCB */
  2390. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2391. "0328 Rsp Ring %d error: "
  2392. "IOCB Data: "
  2393. "x%x x%x x%x x%x "
  2394. "x%x x%x x%x x%x "
  2395. "x%x x%x x%x x%x "
  2396. "x%x x%x x%x x%x\n",
  2397. pring->ringno,
  2398. irsp->un.ulpWord[0],
  2399. irsp->un.ulpWord[1],
  2400. irsp->un.ulpWord[2],
  2401. irsp->un.ulpWord[3],
  2402. irsp->un.ulpWord[4],
  2403. irsp->un.ulpWord[5],
  2404. *(((uint32_t *) irsp) + 6),
  2405. *(((uint32_t *) irsp) + 7),
  2406. *(((uint32_t *) irsp) + 8),
  2407. *(((uint32_t *) irsp) + 9),
  2408. *(((uint32_t *) irsp) + 10),
  2409. *(((uint32_t *) irsp) + 11),
  2410. *(((uint32_t *) irsp) + 12),
  2411. *(((uint32_t *) irsp) + 13),
  2412. *(((uint32_t *) irsp) + 14),
  2413. *(((uint32_t *) irsp) + 15));
  2414. }
  2415. /*
  2416. * Fetch the IOCB command type and call the correct completion
  2417. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2418. * get freed back to the lpfc_iocb_list by the discovery
  2419. * kernel thread.
  2420. */
  2421. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2422. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2423. switch (type) {
  2424. case LPFC_SOL_IOCB:
  2425. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2426. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2427. spin_lock_irqsave(&phba->hbalock, iflag);
  2428. break;
  2429. case LPFC_UNSOL_IOCB:
  2430. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2431. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2432. spin_lock_irqsave(&phba->hbalock, iflag);
  2433. if (!rc)
  2434. free_saveq = 0;
  2435. break;
  2436. case LPFC_ABORT_IOCB:
  2437. cmdiocbp = NULL;
  2438. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2439. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2440. saveq);
  2441. if (cmdiocbp) {
  2442. /* Call the specified completion routine */
  2443. if (cmdiocbp->iocb_cmpl) {
  2444. spin_unlock_irqrestore(&phba->hbalock,
  2445. iflag);
  2446. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2447. saveq);
  2448. spin_lock_irqsave(&phba->hbalock,
  2449. iflag);
  2450. } else
  2451. __lpfc_sli_release_iocbq(phba,
  2452. cmdiocbp);
  2453. }
  2454. break;
  2455. case LPFC_UNKNOWN_IOCB:
  2456. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2457. char adaptermsg[LPFC_MAX_ADPTMSG];
  2458. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2459. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2460. MAX_MSG_DATA);
  2461. dev_warn(&((phba->pcidev)->dev),
  2462. "lpfc%d: %s\n",
  2463. phba->brd_no, adaptermsg);
  2464. } else {
  2465. /* Unknown IOCB command */
  2466. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2467. "0335 Unknown IOCB "
  2468. "command Data: x%x "
  2469. "x%x x%x x%x\n",
  2470. irsp->ulpCommand,
  2471. irsp->ulpStatus,
  2472. irsp->ulpIoTag,
  2473. irsp->ulpContext);
  2474. }
  2475. break;
  2476. }
  2477. if (free_saveq) {
  2478. list_for_each_entry_safe(rspiocbp, next_iocb,
  2479. &saveq->list, list) {
  2480. list_del(&rspiocbp->list);
  2481. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2482. }
  2483. __lpfc_sli_release_iocbq(phba, saveq);
  2484. }
  2485. rspiocbp = NULL;
  2486. }
  2487. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2488. return rspiocbp;
  2489. }
  2490. /**
  2491. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2492. * @phba: Pointer to HBA context object.
  2493. * @pring: Pointer to driver SLI ring object.
  2494. * @mask: Host attention register mask for this ring.
  2495. *
  2496. * This routine wraps the actual slow_ring event process routine from the
  2497. * API jump table function pointer from the lpfc_hba struct.
  2498. **/
  2499. void
  2500. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2501. struct lpfc_sli_ring *pring, uint32_t mask)
  2502. {
  2503. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2504. }
  2505. /**
  2506. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2507. * @phba: Pointer to HBA context object.
  2508. * @pring: Pointer to driver SLI ring object.
  2509. * @mask: Host attention register mask for this ring.
  2510. *
  2511. * This function is called from the worker thread when there is a ring event
  2512. * for non-fcp rings. The caller does not hold any lock. The function will
  2513. * remove each response iocb in the response ring and calls the handle
  2514. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2515. **/
  2516. static void
  2517. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2518. struct lpfc_sli_ring *pring, uint32_t mask)
  2519. {
  2520. struct lpfc_pgp *pgp;
  2521. IOCB_t *entry;
  2522. IOCB_t *irsp = NULL;
  2523. struct lpfc_iocbq *rspiocbp = NULL;
  2524. uint32_t portRspPut, portRspMax;
  2525. unsigned long iflag;
  2526. uint32_t status;
  2527. pgp = &phba->port_gp[pring->ringno];
  2528. spin_lock_irqsave(&phba->hbalock, iflag);
  2529. pring->stats.iocb_event++;
  2530. /*
  2531. * The next available response entry should never exceed the maximum
  2532. * entries. If it does, treat it as an adapter hardware error.
  2533. */
  2534. portRspMax = pring->numRiocb;
  2535. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2536. if (portRspPut >= portRspMax) {
  2537. /*
  2538. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2539. * rsp ring <portRspMax>
  2540. */
  2541. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2542. "0303 Ring %d handler: portRspPut %d "
  2543. "is bigger than rsp ring %d\n",
  2544. pring->ringno, portRspPut, portRspMax);
  2545. phba->link_state = LPFC_HBA_ERROR;
  2546. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2547. phba->work_hs = HS_FFER3;
  2548. lpfc_handle_eratt(phba);
  2549. return;
  2550. }
  2551. rmb();
  2552. while (pring->rspidx != portRspPut) {
  2553. /*
  2554. * Build a completion list and call the appropriate handler.
  2555. * The process is to get the next available response iocb, get
  2556. * a free iocb from the list, copy the response data into the
  2557. * free iocb, insert to the continuation list, and update the
  2558. * next response index to slim. This process makes response
  2559. * iocb's in the ring available to DMA as fast as possible but
  2560. * pays a penalty for a copy operation. Since the iocb is
  2561. * only 32 bytes, this penalty is considered small relative to
  2562. * the PCI reads for register values and a slim write. When
  2563. * the ulpLe field is set, the entire Command has been
  2564. * received.
  2565. */
  2566. entry = lpfc_resp_iocb(phba, pring);
  2567. phba->last_completion_time = jiffies;
  2568. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2569. if (rspiocbp == NULL) {
  2570. printk(KERN_ERR "%s: out of buffers! Failing "
  2571. "completion.\n", __func__);
  2572. break;
  2573. }
  2574. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2575. phba->iocb_rsp_size);
  2576. irsp = &rspiocbp->iocb;
  2577. if (++pring->rspidx >= portRspMax)
  2578. pring->rspidx = 0;
  2579. if (pring->ringno == LPFC_ELS_RING) {
  2580. lpfc_debugfs_slow_ring_trc(phba,
  2581. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2582. *(((uint32_t *) irsp) + 4),
  2583. *(((uint32_t *) irsp) + 6),
  2584. *(((uint32_t *) irsp) + 7));
  2585. }
  2586. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2587. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2588. /* Handle the response IOCB */
  2589. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2590. spin_lock_irqsave(&phba->hbalock, iflag);
  2591. /*
  2592. * If the port response put pointer has not been updated, sync
  2593. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2594. * response put pointer.
  2595. */
  2596. if (pring->rspidx == portRspPut) {
  2597. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2598. }
  2599. } /* while (pring->rspidx != portRspPut) */
  2600. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2601. /* At least one response entry has been freed */
  2602. pring->stats.iocb_rsp_full++;
  2603. /* SET RxRE_RSP in Chip Att register */
  2604. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2605. writel(status, phba->CAregaddr);
  2606. readl(phba->CAregaddr); /* flush */
  2607. }
  2608. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2609. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2610. pring->stats.iocb_cmd_empty++;
  2611. /* Force update of the local copy of cmdGetInx */
  2612. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2613. lpfc_sli_resume_iocb(phba, pring);
  2614. if ((pring->lpfc_sli_cmd_available))
  2615. (pring->lpfc_sli_cmd_available) (phba, pring);
  2616. }
  2617. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2618. return;
  2619. }
  2620. /**
  2621. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2622. * @phba: Pointer to HBA context object.
  2623. * @pring: Pointer to driver SLI ring object.
  2624. * @mask: Host attention register mask for this ring.
  2625. *
  2626. * This function is called from the worker thread when there is a pending
  2627. * ELS response iocb on the driver internal slow-path response iocb worker
  2628. * queue. The caller does not hold any lock. The function will remove each
  2629. * response iocb from the response worker queue and calls the handle
  2630. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2631. **/
  2632. static void
  2633. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2634. struct lpfc_sli_ring *pring, uint32_t mask)
  2635. {
  2636. struct lpfc_iocbq *irspiocbq;
  2637. struct hbq_dmabuf *dmabuf;
  2638. struct lpfc_cq_event *cq_event;
  2639. unsigned long iflag;
  2640. spin_lock_irqsave(&phba->hbalock, iflag);
  2641. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2642. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2643. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2644. /* Get the response iocb from the head of work queue */
  2645. spin_lock_irqsave(&phba->hbalock, iflag);
  2646. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2647. cq_event, struct lpfc_cq_event, list);
  2648. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2649. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2650. case CQE_CODE_COMPL_WQE:
  2651. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2652. cq_event);
  2653. /* Translate ELS WCQE to response IOCBQ */
  2654. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2655. irspiocbq);
  2656. if (irspiocbq)
  2657. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2658. irspiocbq);
  2659. break;
  2660. case CQE_CODE_RECEIVE:
  2661. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2662. cq_event);
  2663. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2664. break;
  2665. default:
  2666. break;
  2667. }
  2668. }
  2669. }
  2670. /**
  2671. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2672. * @phba: Pointer to HBA context object.
  2673. * @pring: Pointer to driver SLI ring object.
  2674. *
  2675. * This function aborts all iocbs in the given ring and frees all the iocb
  2676. * objects in txq. This function issues an abort iocb for all the iocb commands
  2677. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2678. * the return of this function. The caller is not required to hold any locks.
  2679. **/
  2680. void
  2681. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2682. {
  2683. LIST_HEAD(completions);
  2684. struct lpfc_iocbq *iocb, *next_iocb;
  2685. if (pring->ringno == LPFC_ELS_RING) {
  2686. lpfc_fabric_abort_hba(phba);
  2687. }
  2688. /* Error everything on txq and txcmplq
  2689. * First do the txq.
  2690. */
  2691. spin_lock_irq(&phba->hbalock);
  2692. list_splice_init(&pring->txq, &completions);
  2693. pring->txq_cnt = 0;
  2694. /* Next issue ABTS for everything on the txcmplq */
  2695. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2696. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2697. spin_unlock_irq(&phba->hbalock);
  2698. /* Cancel all the IOCBs from the completions list */
  2699. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2700. IOERR_SLI_ABORTED);
  2701. }
  2702. /**
  2703. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2704. * @phba: Pointer to HBA context object.
  2705. *
  2706. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2707. * objects in txq and txcmplq. This function will not issue abort iocbs
  2708. * for all the iocb commands in txcmplq, they will just be returned with
  2709. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2710. * slot has been permanently disabled.
  2711. **/
  2712. void
  2713. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2714. {
  2715. LIST_HEAD(txq);
  2716. LIST_HEAD(txcmplq);
  2717. struct lpfc_sli *psli = &phba->sli;
  2718. struct lpfc_sli_ring *pring;
  2719. /* Currently, only one fcp ring */
  2720. pring = &psli->ring[psli->fcp_ring];
  2721. spin_lock_irq(&phba->hbalock);
  2722. /* Retrieve everything on txq */
  2723. list_splice_init(&pring->txq, &txq);
  2724. pring->txq_cnt = 0;
  2725. /* Retrieve everything on the txcmplq */
  2726. list_splice_init(&pring->txcmplq, &txcmplq);
  2727. pring->txcmplq_cnt = 0;
  2728. spin_unlock_irq(&phba->hbalock);
  2729. /* Flush the txq */
  2730. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2731. IOERR_SLI_DOWN);
  2732. /* Flush the txcmpq */
  2733. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2734. IOERR_SLI_DOWN);
  2735. }
  2736. /**
  2737. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2738. * @phba: Pointer to HBA context object.
  2739. * @mask: Bit mask to be checked.
  2740. *
  2741. * This function reads the host status register and compares
  2742. * with the provided bit mask to check if HBA completed
  2743. * the restart. This function will wait in a loop for the
  2744. * HBA to complete restart. If the HBA does not restart within
  2745. * 15 iterations, the function will reset the HBA again. The
  2746. * function returns 1 when HBA fail to restart otherwise returns
  2747. * zero.
  2748. **/
  2749. static int
  2750. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2751. {
  2752. uint32_t status;
  2753. int i = 0;
  2754. int retval = 0;
  2755. /* Read the HBA Host Status Register */
  2756. status = readl(phba->HSregaddr);
  2757. /*
  2758. * Check status register every 100ms for 5 retries, then every
  2759. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2760. * every 2.5 sec for 4.
  2761. * Break our of the loop if errors occurred during init.
  2762. */
  2763. while (((status & mask) != mask) &&
  2764. !(status & HS_FFERM) &&
  2765. i++ < 20) {
  2766. if (i <= 5)
  2767. msleep(10);
  2768. else if (i <= 10)
  2769. msleep(500);
  2770. else
  2771. msleep(2500);
  2772. if (i == 15) {
  2773. /* Do post */
  2774. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2775. lpfc_sli_brdrestart(phba);
  2776. }
  2777. /* Read the HBA Host Status Register */
  2778. status = readl(phba->HSregaddr);
  2779. }
  2780. /* Check to see if any errors occurred during init */
  2781. if ((status & HS_FFERM) || (i >= 20)) {
  2782. phba->link_state = LPFC_HBA_ERROR;
  2783. retval = 1;
  2784. }
  2785. return retval;
  2786. }
  2787. /**
  2788. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2789. * @phba: Pointer to HBA context object.
  2790. * @mask: Bit mask to be checked.
  2791. *
  2792. * This function checks the host status register to check if HBA is
  2793. * ready. This function will wait in a loop for the HBA to be ready
  2794. * If the HBA is not ready , the function will will reset the HBA PCI
  2795. * function again. The function returns 1 when HBA fail to be ready
  2796. * otherwise returns zero.
  2797. **/
  2798. static int
  2799. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2800. {
  2801. uint32_t status;
  2802. int retval = 0;
  2803. /* Read the HBA Host Status Register */
  2804. status = lpfc_sli4_post_status_check(phba);
  2805. if (status) {
  2806. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2807. lpfc_sli_brdrestart(phba);
  2808. status = lpfc_sli4_post_status_check(phba);
  2809. }
  2810. /* Check to see if any errors occurred during init */
  2811. if (status) {
  2812. phba->link_state = LPFC_HBA_ERROR;
  2813. retval = 1;
  2814. } else
  2815. phba->sli4_hba.intr_enable = 0;
  2816. return retval;
  2817. }
  2818. /**
  2819. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2820. * @phba: Pointer to HBA context object.
  2821. * @mask: Bit mask to be checked.
  2822. *
  2823. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2824. * from the API jump table function pointer from the lpfc_hba struct.
  2825. **/
  2826. int
  2827. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2828. {
  2829. return phba->lpfc_sli_brdready(phba, mask);
  2830. }
  2831. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2832. /**
  2833. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2834. * @phba: Pointer to HBA context object.
  2835. *
  2836. * This function is called before resetting an HBA. This
  2837. * function requests HBA to quiesce DMAs before a reset.
  2838. **/
  2839. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2840. {
  2841. uint32_t __iomem *resp_buf;
  2842. uint32_t __iomem *mbox_buf;
  2843. volatile uint32_t mbox;
  2844. uint32_t hc_copy;
  2845. int i;
  2846. uint8_t hdrtype;
  2847. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2848. if (hdrtype != 0x80 ||
  2849. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2850. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2851. return;
  2852. /*
  2853. * Tell the other part of the chip to suspend temporarily all
  2854. * its DMA activity.
  2855. */
  2856. resp_buf = phba->MBslimaddr;
  2857. /* Disable the error attention */
  2858. hc_copy = readl(phba->HCregaddr);
  2859. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2860. readl(phba->HCregaddr); /* flush */
  2861. phba->link_flag |= LS_IGNORE_ERATT;
  2862. if (readl(phba->HAregaddr) & HA_ERATT) {
  2863. /* Clear Chip error bit */
  2864. writel(HA_ERATT, phba->HAregaddr);
  2865. phba->pport->stopped = 1;
  2866. }
  2867. mbox = 0;
  2868. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2869. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2870. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2871. mbox_buf = phba->MBslimaddr;
  2872. writel(mbox, mbox_buf);
  2873. for (i = 0;
  2874. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2875. mdelay(1);
  2876. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2877. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2878. phba->pport->stopped)
  2879. goto restore_hc;
  2880. else
  2881. goto clear_errat;
  2882. }
  2883. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2884. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2885. mdelay(1);
  2886. clear_errat:
  2887. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2888. mdelay(1);
  2889. if (readl(phba->HAregaddr) & HA_ERATT) {
  2890. writel(HA_ERATT, phba->HAregaddr);
  2891. phba->pport->stopped = 1;
  2892. }
  2893. restore_hc:
  2894. phba->link_flag &= ~LS_IGNORE_ERATT;
  2895. writel(hc_copy, phba->HCregaddr);
  2896. readl(phba->HCregaddr); /* flush */
  2897. }
  2898. /**
  2899. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  2900. * @phba: Pointer to HBA context object.
  2901. *
  2902. * This function issues a kill_board mailbox command and waits for
  2903. * the error attention interrupt. This function is called for stopping
  2904. * the firmware processing. The caller is not required to hold any
  2905. * locks. This function calls lpfc_hba_down_post function to free
  2906. * any pending commands after the kill. The function will return 1 when it
  2907. * fails to kill the board else will return 0.
  2908. **/
  2909. int
  2910. lpfc_sli_brdkill(struct lpfc_hba *phba)
  2911. {
  2912. struct lpfc_sli *psli;
  2913. LPFC_MBOXQ_t *pmb;
  2914. uint32_t status;
  2915. uint32_t ha_copy;
  2916. int retval;
  2917. int i = 0;
  2918. psli = &phba->sli;
  2919. /* Kill HBA */
  2920. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2921. "0329 Kill HBA Data: x%x x%x\n",
  2922. phba->pport->port_state, psli->sli_flag);
  2923. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2924. if (!pmb)
  2925. return 1;
  2926. /* Disable the error attention */
  2927. spin_lock_irq(&phba->hbalock);
  2928. status = readl(phba->HCregaddr);
  2929. status &= ~HC_ERINT_ENA;
  2930. writel(status, phba->HCregaddr);
  2931. readl(phba->HCregaddr); /* flush */
  2932. phba->link_flag |= LS_IGNORE_ERATT;
  2933. spin_unlock_irq(&phba->hbalock);
  2934. lpfc_kill_board(phba, pmb);
  2935. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2936. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2937. if (retval != MBX_SUCCESS) {
  2938. if (retval != MBX_BUSY)
  2939. mempool_free(pmb, phba->mbox_mem_pool);
  2940. spin_lock_irq(&phba->hbalock);
  2941. phba->link_flag &= ~LS_IGNORE_ERATT;
  2942. spin_unlock_irq(&phba->hbalock);
  2943. return 1;
  2944. }
  2945. spin_lock_irq(&phba->hbalock);
  2946. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  2947. spin_unlock_irq(&phba->hbalock);
  2948. mempool_free(pmb, phba->mbox_mem_pool);
  2949. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  2950. * attention every 100ms for 3 seconds. If we don't get ERATT after
  2951. * 3 seconds we still set HBA_ERROR state because the status of the
  2952. * board is now undefined.
  2953. */
  2954. ha_copy = readl(phba->HAregaddr);
  2955. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  2956. mdelay(100);
  2957. ha_copy = readl(phba->HAregaddr);
  2958. }
  2959. del_timer_sync(&psli->mbox_tmo);
  2960. if (ha_copy & HA_ERATT) {
  2961. writel(HA_ERATT, phba->HAregaddr);
  2962. phba->pport->stopped = 1;
  2963. }
  2964. spin_lock_irq(&phba->hbalock);
  2965. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2966. psli->mbox_active = NULL;
  2967. phba->link_flag &= ~LS_IGNORE_ERATT;
  2968. spin_unlock_irq(&phba->hbalock);
  2969. lpfc_hba_down_post(phba);
  2970. phba->link_state = LPFC_HBA_ERROR;
  2971. return ha_copy & HA_ERATT ? 0 : 1;
  2972. }
  2973. /**
  2974. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  2975. * @phba: Pointer to HBA context object.
  2976. *
  2977. * This function resets the HBA by writing HC_INITFF to the control
  2978. * register. After the HBA resets, this function resets all the iocb ring
  2979. * indices. This function disables PCI layer parity checking during
  2980. * the reset.
  2981. * This function returns 0 always.
  2982. * The caller is not required to hold any locks.
  2983. **/
  2984. int
  2985. lpfc_sli_brdreset(struct lpfc_hba *phba)
  2986. {
  2987. struct lpfc_sli *psli;
  2988. struct lpfc_sli_ring *pring;
  2989. uint16_t cfg_value;
  2990. int i;
  2991. psli = &phba->sli;
  2992. /* Reset HBA */
  2993. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2994. "0325 Reset HBA Data: x%x x%x\n",
  2995. phba->pport->port_state, psli->sli_flag);
  2996. /* perform board reset */
  2997. phba->fc_eventTag = 0;
  2998. phba->link_events = 0;
  2999. phba->pport->fc_myDID = 0;
  3000. phba->pport->fc_prevDID = 0;
  3001. /* Turn off parity checking and serr during the physical reset */
  3002. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3003. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3004. (cfg_value &
  3005. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3006. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3007. /* Now toggle INITFF bit in the Host Control Register */
  3008. writel(HC_INITFF, phba->HCregaddr);
  3009. mdelay(1);
  3010. readl(phba->HCregaddr); /* flush */
  3011. writel(0, phba->HCregaddr);
  3012. readl(phba->HCregaddr); /* flush */
  3013. /* Restore PCI cmd register */
  3014. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3015. /* Initialize relevant SLI info */
  3016. for (i = 0; i < psli->num_rings; i++) {
  3017. pring = &psli->ring[i];
  3018. pring->flag = 0;
  3019. pring->rspidx = 0;
  3020. pring->next_cmdidx = 0;
  3021. pring->local_getidx = 0;
  3022. pring->cmdidx = 0;
  3023. pring->missbufcnt = 0;
  3024. }
  3025. phba->link_state = LPFC_WARM_START;
  3026. return 0;
  3027. }
  3028. /**
  3029. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3030. * @phba: Pointer to HBA context object.
  3031. *
  3032. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3033. * checking during resets the device. The caller is not required to hold
  3034. * any locks.
  3035. *
  3036. * This function returns 0 always.
  3037. **/
  3038. int
  3039. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3040. {
  3041. struct lpfc_sli *psli = &phba->sli;
  3042. uint16_t cfg_value;
  3043. uint8_t qindx;
  3044. /* Reset HBA */
  3045. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3046. "0295 Reset HBA Data: x%x x%x\n",
  3047. phba->pport->port_state, psli->sli_flag);
  3048. /* perform board reset */
  3049. phba->fc_eventTag = 0;
  3050. phba->link_events = 0;
  3051. phba->pport->fc_myDID = 0;
  3052. phba->pport->fc_prevDID = 0;
  3053. /* Turn off parity checking and serr during the physical reset */
  3054. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3055. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3056. (cfg_value &
  3057. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3058. spin_lock_irq(&phba->hbalock);
  3059. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3060. phba->fcf.fcf_flag = 0;
  3061. /* Clean up the child queue list for the CQs */
  3062. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3063. list_del_init(&phba->sli4_hba.els_wq->list);
  3064. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3065. list_del_init(&phba->sli4_hba.dat_rq->list);
  3066. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3067. list_del_init(&phba->sli4_hba.els_cq->list);
  3068. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3069. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3070. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3071. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3072. spin_unlock_irq(&phba->hbalock);
  3073. /* Now physically reset the device */
  3074. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3075. "0389 Performing PCI function reset!\n");
  3076. /* Perform FCoE PCI function reset */
  3077. lpfc_pci_function_reset(phba);
  3078. return 0;
  3079. }
  3080. /**
  3081. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3082. * @phba: Pointer to HBA context object.
  3083. *
  3084. * This function is called in the SLI initialization code path to
  3085. * restart the HBA. The caller is not required to hold any lock.
  3086. * This function writes MBX_RESTART mailbox command to the SLIM and
  3087. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3088. * function to free any pending commands. The function enables
  3089. * POST only during the first initialization. The function returns zero.
  3090. * The function does not guarantee completion of MBX_RESTART mailbox
  3091. * command before the return of this function.
  3092. **/
  3093. static int
  3094. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3095. {
  3096. MAILBOX_t *mb;
  3097. struct lpfc_sli *psli;
  3098. volatile uint32_t word0;
  3099. void __iomem *to_slim;
  3100. uint32_t hba_aer_enabled;
  3101. spin_lock_irq(&phba->hbalock);
  3102. /* Take PCIe device Advanced Error Reporting (AER) state */
  3103. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3104. psli = &phba->sli;
  3105. /* Restart HBA */
  3106. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3107. "0337 Restart HBA Data: x%x x%x\n",
  3108. phba->pport->port_state, psli->sli_flag);
  3109. word0 = 0;
  3110. mb = (MAILBOX_t *) &word0;
  3111. mb->mbxCommand = MBX_RESTART;
  3112. mb->mbxHc = 1;
  3113. lpfc_reset_barrier(phba);
  3114. to_slim = phba->MBslimaddr;
  3115. writel(*(uint32_t *) mb, to_slim);
  3116. readl(to_slim); /* flush */
  3117. /* Only skip post after fc_ffinit is completed */
  3118. if (phba->pport->port_state)
  3119. word0 = 1; /* This is really setting up word1 */
  3120. else
  3121. word0 = 0; /* This is really setting up word1 */
  3122. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3123. writel(*(uint32_t *) mb, to_slim);
  3124. readl(to_slim); /* flush */
  3125. lpfc_sli_brdreset(phba);
  3126. phba->pport->stopped = 0;
  3127. phba->link_state = LPFC_INIT_START;
  3128. phba->hba_flag = 0;
  3129. spin_unlock_irq(&phba->hbalock);
  3130. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3131. psli->stats_start = get_seconds();
  3132. /* Give the INITFF and Post time to settle. */
  3133. mdelay(100);
  3134. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3135. if (hba_aer_enabled)
  3136. pci_disable_pcie_error_reporting(phba->pcidev);
  3137. lpfc_hba_down_post(phba);
  3138. return 0;
  3139. }
  3140. /**
  3141. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3142. * @phba: Pointer to HBA context object.
  3143. *
  3144. * This function is called in the SLI initialization code path to restart
  3145. * a SLI4 HBA. The caller is not required to hold any lock.
  3146. * At the end of the function, it calls lpfc_hba_down_post function to
  3147. * free any pending commands.
  3148. **/
  3149. static int
  3150. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3151. {
  3152. struct lpfc_sli *psli = &phba->sli;
  3153. /* Restart HBA */
  3154. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3155. "0296 Restart HBA Data: x%x x%x\n",
  3156. phba->pport->port_state, psli->sli_flag);
  3157. lpfc_sli4_brdreset(phba);
  3158. spin_lock_irq(&phba->hbalock);
  3159. phba->pport->stopped = 0;
  3160. phba->link_state = LPFC_INIT_START;
  3161. phba->hba_flag = 0;
  3162. spin_unlock_irq(&phba->hbalock);
  3163. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3164. psli->stats_start = get_seconds();
  3165. lpfc_hba_down_post(phba);
  3166. return 0;
  3167. }
  3168. /**
  3169. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3170. * @phba: Pointer to HBA context object.
  3171. *
  3172. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3173. * API jump table function pointer from the lpfc_hba struct.
  3174. **/
  3175. int
  3176. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3177. {
  3178. return phba->lpfc_sli_brdrestart(phba);
  3179. }
  3180. /**
  3181. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3182. * @phba: Pointer to HBA context object.
  3183. *
  3184. * This function is called after a HBA restart to wait for successful
  3185. * restart of the HBA. Successful restart of the HBA is indicated by
  3186. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3187. * iteration, the function will restart the HBA again. The function returns
  3188. * zero if HBA successfully restarted else returns negative error code.
  3189. **/
  3190. static int
  3191. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3192. {
  3193. uint32_t status, i = 0;
  3194. /* Read the HBA Host Status Register */
  3195. status = readl(phba->HSregaddr);
  3196. /* Check status register to see what current state is */
  3197. i = 0;
  3198. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3199. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3200. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3201. * 4.
  3202. */
  3203. if (i++ >= 20) {
  3204. /* Adapter failed to init, timeout, status reg
  3205. <status> */
  3206. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3207. "0436 Adapter failed to init, "
  3208. "timeout, status reg x%x, "
  3209. "FW Data: A8 x%x AC x%x\n", status,
  3210. readl(phba->MBslimaddr + 0xa8),
  3211. readl(phba->MBslimaddr + 0xac));
  3212. phba->link_state = LPFC_HBA_ERROR;
  3213. return -ETIMEDOUT;
  3214. }
  3215. /* Check to see if any errors occurred during init */
  3216. if (status & HS_FFERM) {
  3217. /* ERROR: During chipset initialization */
  3218. /* Adapter failed to init, chipset, status reg
  3219. <status> */
  3220. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3221. "0437 Adapter failed to init, "
  3222. "chipset, status reg x%x, "
  3223. "FW Data: A8 x%x AC x%x\n", status,
  3224. readl(phba->MBslimaddr + 0xa8),
  3225. readl(phba->MBslimaddr + 0xac));
  3226. phba->link_state = LPFC_HBA_ERROR;
  3227. return -EIO;
  3228. }
  3229. if (i <= 5) {
  3230. msleep(10);
  3231. } else if (i <= 10) {
  3232. msleep(500);
  3233. } else {
  3234. msleep(2500);
  3235. }
  3236. if (i == 15) {
  3237. /* Do post */
  3238. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3239. lpfc_sli_brdrestart(phba);
  3240. }
  3241. /* Read the HBA Host Status Register */
  3242. status = readl(phba->HSregaddr);
  3243. }
  3244. /* Check to see if any errors occurred during init */
  3245. if (status & HS_FFERM) {
  3246. /* ERROR: During chipset initialization */
  3247. /* Adapter failed to init, chipset, status reg <status> */
  3248. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3249. "0438 Adapter failed to init, chipset, "
  3250. "status reg x%x, "
  3251. "FW Data: A8 x%x AC x%x\n", status,
  3252. readl(phba->MBslimaddr + 0xa8),
  3253. readl(phba->MBslimaddr + 0xac));
  3254. phba->link_state = LPFC_HBA_ERROR;
  3255. return -EIO;
  3256. }
  3257. /* Clear all interrupt enable conditions */
  3258. writel(0, phba->HCregaddr);
  3259. readl(phba->HCregaddr); /* flush */
  3260. /* setup host attn register */
  3261. writel(0xffffffff, phba->HAregaddr);
  3262. readl(phba->HAregaddr); /* flush */
  3263. return 0;
  3264. }
  3265. /**
  3266. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3267. *
  3268. * This function calculates and returns the number of HBQs required to be
  3269. * configured.
  3270. **/
  3271. int
  3272. lpfc_sli_hbq_count(void)
  3273. {
  3274. return ARRAY_SIZE(lpfc_hbq_defs);
  3275. }
  3276. /**
  3277. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3278. *
  3279. * This function adds the number of hbq entries in every HBQ to get
  3280. * the total number of hbq entries required for the HBA and returns
  3281. * the total count.
  3282. **/
  3283. static int
  3284. lpfc_sli_hbq_entry_count(void)
  3285. {
  3286. int hbq_count = lpfc_sli_hbq_count();
  3287. int count = 0;
  3288. int i;
  3289. for (i = 0; i < hbq_count; ++i)
  3290. count += lpfc_hbq_defs[i]->entry_count;
  3291. return count;
  3292. }
  3293. /**
  3294. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3295. *
  3296. * This function calculates amount of memory required for all hbq entries
  3297. * to be configured and returns the total memory required.
  3298. **/
  3299. int
  3300. lpfc_sli_hbq_size(void)
  3301. {
  3302. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3303. }
  3304. /**
  3305. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3306. * @phba: Pointer to HBA context object.
  3307. *
  3308. * This function is called during the SLI initialization to configure
  3309. * all the HBQs and post buffers to the HBQ. The caller is not
  3310. * required to hold any locks. This function will return zero if successful
  3311. * else it will return negative error code.
  3312. **/
  3313. static int
  3314. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3315. {
  3316. int hbq_count = lpfc_sli_hbq_count();
  3317. LPFC_MBOXQ_t *pmb;
  3318. MAILBOX_t *pmbox;
  3319. uint32_t hbqno;
  3320. uint32_t hbq_entry_index;
  3321. /* Get a Mailbox buffer to setup mailbox
  3322. * commands for HBA initialization
  3323. */
  3324. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3325. if (!pmb)
  3326. return -ENOMEM;
  3327. pmbox = &pmb->u.mb;
  3328. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3329. phba->link_state = LPFC_INIT_MBX_CMDS;
  3330. phba->hbq_in_use = 1;
  3331. hbq_entry_index = 0;
  3332. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3333. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3334. phba->hbqs[hbqno].hbqPutIdx = 0;
  3335. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3336. phba->hbqs[hbqno].entry_count =
  3337. lpfc_hbq_defs[hbqno]->entry_count;
  3338. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3339. hbq_entry_index, pmb);
  3340. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3341. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3342. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3343. mbxStatus <status>, ring <num> */
  3344. lpfc_printf_log(phba, KERN_ERR,
  3345. LOG_SLI | LOG_VPORT,
  3346. "1805 Adapter failed to init. "
  3347. "Data: x%x x%x x%x\n",
  3348. pmbox->mbxCommand,
  3349. pmbox->mbxStatus, hbqno);
  3350. phba->link_state = LPFC_HBA_ERROR;
  3351. mempool_free(pmb, phba->mbox_mem_pool);
  3352. return ENXIO;
  3353. }
  3354. }
  3355. phba->hbq_count = hbq_count;
  3356. mempool_free(pmb, phba->mbox_mem_pool);
  3357. /* Initially populate or replenish the HBQs */
  3358. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3359. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3360. return 0;
  3361. }
  3362. /**
  3363. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3364. * @phba: Pointer to HBA context object.
  3365. *
  3366. * This function is called during the SLI initialization to configure
  3367. * all the HBQs and post buffers to the HBQ. The caller is not
  3368. * required to hold any locks. This function will return zero if successful
  3369. * else it will return negative error code.
  3370. **/
  3371. static int
  3372. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3373. {
  3374. phba->hbq_in_use = 1;
  3375. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3376. phba->hbq_count = 1;
  3377. /* Initially populate or replenish the HBQs */
  3378. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3379. return 0;
  3380. }
  3381. /**
  3382. * lpfc_sli_config_port - Issue config port mailbox command
  3383. * @phba: Pointer to HBA context object.
  3384. * @sli_mode: sli mode - 2/3
  3385. *
  3386. * This function is called by the sli intialization code path
  3387. * to issue config_port mailbox command. This function restarts the
  3388. * HBA firmware and issues a config_port mailbox command to configure
  3389. * the SLI interface in the sli mode specified by sli_mode
  3390. * variable. The caller is not required to hold any locks.
  3391. * The function returns 0 if successful, else returns negative error
  3392. * code.
  3393. **/
  3394. int
  3395. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3396. {
  3397. LPFC_MBOXQ_t *pmb;
  3398. uint32_t resetcount = 0, rc = 0, done = 0;
  3399. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3400. if (!pmb) {
  3401. phba->link_state = LPFC_HBA_ERROR;
  3402. return -ENOMEM;
  3403. }
  3404. phba->sli_rev = sli_mode;
  3405. while (resetcount < 2 && !done) {
  3406. spin_lock_irq(&phba->hbalock);
  3407. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3408. spin_unlock_irq(&phba->hbalock);
  3409. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3410. lpfc_sli_brdrestart(phba);
  3411. rc = lpfc_sli_chipset_init(phba);
  3412. if (rc)
  3413. break;
  3414. spin_lock_irq(&phba->hbalock);
  3415. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3416. spin_unlock_irq(&phba->hbalock);
  3417. resetcount++;
  3418. /* Call pre CONFIG_PORT mailbox command initialization. A
  3419. * value of 0 means the call was successful. Any other
  3420. * nonzero value is a failure, but if ERESTART is returned,
  3421. * the driver may reset the HBA and try again.
  3422. */
  3423. rc = lpfc_config_port_prep(phba);
  3424. if (rc == -ERESTART) {
  3425. phba->link_state = LPFC_LINK_UNKNOWN;
  3426. continue;
  3427. } else if (rc)
  3428. break;
  3429. phba->link_state = LPFC_INIT_MBX_CMDS;
  3430. lpfc_config_port(phba, pmb);
  3431. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3432. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3433. LPFC_SLI3_HBQ_ENABLED |
  3434. LPFC_SLI3_CRP_ENABLED |
  3435. LPFC_SLI3_INB_ENABLED |
  3436. LPFC_SLI3_BG_ENABLED);
  3437. if (rc != MBX_SUCCESS) {
  3438. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3439. "0442 Adapter failed to init, mbxCmd x%x "
  3440. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3441. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3442. spin_lock_irq(&phba->hbalock);
  3443. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3444. spin_unlock_irq(&phba->hbalock);
  3445. rc = -ENXIO;
  3446. } else {
  3447. /* Allow asynchronous mailbox command to go through */
  3448. spin_lock_irq(&phba->hbalock);
  3449. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3450. spin_unlock_irq(&phba->hbalock);
  3451. done = 1;
  3452. }
  3453. }
  3454. if (!done) {
  3455. rc = -EINVAL;
  3456. goto do_prep_failed;
  3457. }
  3458. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3459. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3460. rc = -ENXIO;
  3461. goto do_prep_failed;
  3462. }
  3463. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3464. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3465. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3466. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3467. phba->max_vpi : phba->max_vports;
  3468. } else
  3469. phba->max_vpi = 0;
  3470. if (pmb->u.mb.un.varCfgPort.gdss)
  3471. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3472. if (pmb->u.mb.un.varCfgPort.gerbm)
  3473. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3474. if (pmb->u.mb.un.varCfgPort.gcrp)
  3475. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3476. if (pmb->u.mb.un.varCfgPort.ginb) {
  3477. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3478. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3479. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3480. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3481. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3482. phba->inb_last_counter =
  3483. phba->mbox->us.s3_inb_pgp.counter;
  3484. } else {
  3485. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3486. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3487. phba->inb_ha_copy = NULL;
  3488. phba->inb_counter = NULL;
  3489. }
  3490. if (phba->cfg_enable_bg) {
  3491. if (pmb->u.mb.un.varCfgPort.gbg)
  3492. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3493. else
  3494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3495. "0443 Adapter did not grant "
  3496. "BlockGuard\n");
  3497. }
  3498. } else {
  3499. phba->hbq_get = NULL;
  3500. phba->port_gp = phba->mbox->us.s2.port;
  3501. phba->inb_ha_copy = NULL;
  3502. phba->inb_counter = NULL;
  3503. phba->max_vpi = 0;
  3504. }
  3505. do_prep_failed:
  3506. mempool_free(pmb, phba->mbox_mem_pool);
  3507. return rc;
  3508. }
  3509. /**
  3510. * lpfc_sli_hba_setup - SLI intialization function
  3511. * @phba: Pointer to HBA context object.
  3512. *
  3513. * This function is the main SLI intialization function. This function
  3514. * is called by the HBA intialization code, HBA reset code and HBA
  3515. * error attention handler code. Caller is not required to hold any
  3516. * locks. This function issues config_port mailbox command to configure
  3517. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3518. * calls the config_port_post function to issue init_link mailbox
  3519. * command and to start the discovery. The function will return zero
  3520. * if successful, else it will return negative error code.
  3521. **/
  3522. int
  3523. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3524. {
  3525. uint32_t rc;
  3526. int mode = 3;
  3527. switch (lpfc_sli_mode) {
  3528. case 2:
  3529. if (phba->cfg_enable_npiv) {
  3530. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3531. "1824 NPIV enabled: Override lpfc_sli_mode "
  3532. "parameter (%d) to auto (0).\n",
  3533. lpfc_sli_mode);
  3534. break;
  3535. }
  3536. mode = 2;
  3537. break;
  3538. case 0:
  3539. case 3:
  3540. break;
  3541. default:
  3542. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3543. "1819 Unrecognized lpfc_sli_mode "
  3544. "parameter: %d.\n", lpfc_sli_mode);
  3545. break;
  3546. }
  3547. rc = lpfc_sli_config_port(phba, mode);
  3548. if (rc && lpfc_sli_mode == 3)
  3549. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3550. "1820 Unable to select SLI-3. "
  3551. "Not supported by adapter.\n");
  3552. if (rc && mode != 2)
  3553. rc = lpfc_sli_config_port(phba, 2);
  3554. if (rc)
  3555. goto lpfc_sli_hba_setup_error;
  3556. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3557. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3558. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3559. if (!rc) {
  3560. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3561. "2709 This device supports "
  3562. "Advanced Error Reporting (AER)\n");
  3563. spin_lock_irq(&phba->hbalock);
  3564. phba->hba_flag |= HBA_AER_ENABLED;
  3565. spin_unlock_irq(&phba->hbalock);
  3566. } else {
  3567. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3568. "2708 This device does not support "
  3569. "Advanced Error Reporting (AER)\n");
  3570. phba->cfg_aer_support = 0;
  3571. }
  3572. }
  3573. if (phba->sli_rev == 3) {
  3574. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3575. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3576. } else {
  3577. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3578. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3579. phba->sli3_options = 0;
  3580. }
  3581. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3582. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3583. phba->sli_rev, phba->max_vpi);
  3584. rc = lpfc_sli_ring_map(phba);
  3585. if (rc)
  3586. goto lpfc_sli_hba_setup_error;
  3587. /* Init HBQs */
  3588. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3589. rc = lpfc_sli_hbq_setup(phba);
  3590. if (rc)
  3591. goto lpfc_sli_hba_setup_error;
  3592. }
  3593. spin_lock_irq(&phba->hbalock);
  3594. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3595. spin_unlock_irq(&phba->hbalock);
  3596. rc = lpfc_config_port_post(phba);
  3597. if (rc)
  3598. goto lpfc_sli_hba_setup_error;
  3599. return rc;
  3600. lpfc_sli_hba_setup_error:
  3601. phba->link_state = LPFC_HBA_ERROR;
  3602. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3603. "0445 Firmware initialization failed\n");
  3604. return rc;
  3605. }
  3606. /**
  3607. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3608. * @phba: Pointer to HBA context object.
  3609. * @mboxq: mailbox pointer.
  3610. * This function issue a dump mailbox command to read config region
  3611. * 23 and parse the records in the region and populate driver
  3612. * data structure.
  3613. **/
  3614. static int
  3615. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3616. LPFC_MBOXQ_t *mboxq)
  3617. {
  3618. struct lpfc_dmabuf *mp;
  3619. struct lpfc_mqe *mqe;
  3620. uint32_t data_length;
  3621. int rc;
  3622. /* Program the default value of vlan_id and fc_map */
  3623. phba->valid_vlan = 0;
  3624. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3625. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3626. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3627. mqe = &mboxq->u.mqe;
  3628. if (lpfc_dump_fcoe_param(phba, mboxq))
  3629. return -ENOMEM;
  3630. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3631. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3632. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3633. "(%d):2571 Mailbox cmd x%x Status x%x "
  3634. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3635. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3636. "CQ: x%x x%x x%x x%x\n",
  3637. mboxq->vport ? mboxq->vport->vpi : 0,
  3638. bf_get(lpfc_mqe_command, mqe),
  3639. bf_get(lpfc_mqe_status, mqe),
  3640. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3641. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3642. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3643. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3644. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3645. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3646. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3647. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3648. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3649. mboxq->mcqe.word0,
  3650. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3651. mboxq->mcqe.trailer);
  3652. if (rc) {
  3653. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3654. kfree(mp);
  3655. return -EIO;
  3656. }
  3657. data_length = mqe->un.mb_words[5];
  3658. if (data_length > DMP_RGN23_SIZE) {
  3659. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3660. kfree(mp);
  3661. return -EIO;
  3662. }
  3663. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3664. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3665. kfree(mp);
  3666. return 0;
  3667. }
  3668. /**
  3669. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3670. * @phba: pointer to lpfc hba data structure.
  3671. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3672. * @vpd: pointer to the memory to hold resulting port vpd data.
  3673. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3674. * On output, the number of data bytes in @vpd.
  3675. *
  3676. * This routine executes a READ_REV SLI4 mailbox command. In
  3677. * addition, this routine gets the port vpd data.
  3678. *
  3679. * Return codes
  3680. * 0 - successful
  3681. * ENOMEM - could not allocated memory.
  3682. **/
  3683. static int
  3684. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3685. uint8_t *vpd, uint32_t *vpd_size)
  3686. {
  3687. int rc = 0;
  3688. uint32_t dma_size;
  3689. struct lpfc_dmabuf *dmabuf;
  3690. struct lpfc_mqe *mqe;
  3691. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3692. if (!dmabuf)
  3693. return -ENOMEM;
  3694. /*
  3695. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3696. * mailbox command.
  3697. */
  3698. dma_size = *vpd_size;
  3699. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3700. dma_size,
  3701. &dmabuf->phys,
  3702. GFP_KERNEL);
  3703. if (!dmabuf->virt) {
  3704. kfree(dmabuf);
  3705. return -ENOMEM;
  3706. }
  3707. memset(dmabuf->virt, 0, dma_size);
  3708. /*
  3709. * The SLI4 implementation of READ_REV conflicts at word1,
  3710. * bits 31:16 and SLI4 adds vpd functionality not present
  3711. * in SLI3. This code corrects the conflicts.
  3712. */
  3713. lpfc_read_rev(phba, mboxq);
  3714. mqe = &mboxq->u.mqe;
  3715. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3716. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3717. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3718. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3719. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3720. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3721. if (rc) {
  3722. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3723. dmabuf->virt, dmabuf->phys);
  3724. kfree(dmabuf);
  3725. return -EIO;
  3726. }
  3727. /*
  3728. * The available vpd length cannot be bigger than the
  3729. * DMA buffer passed to the port. Catch the less than
  3730. * case and update the caller's size.
  3731. */
  3732. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3733. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3734. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3735. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3736. dmabuf->virt, dmabuf->phys);
  3737. kfree(dmabuf);
  3738. return 0;
  3739. }
  3740. /**
  3741. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3742. * @phba: pointer to lpfc hba data structure.
  3743. *
  3744. * This routine is called to explicitly arm the SLI4 device's completion and
  3745. * event queues
  3746. **/
  3747. static void
  3748. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3749. {
  3750. uint8_t fcp_eqidx;
  3751. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3752. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3753. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3754. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3755. LPFC_QUEUE_REARM);
  3756. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3757. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3758. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3759. LPFC_QUEUE_REARM);
  3760. }
  3761. /**
  3762. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3763. * @phba: Pointer to HBA context object.
  3764. *
  3765. * This function is the main SLI4 device intialization PCI function. This
  3766. * function is called by the HBA intialization code, HBA reset code and
  3767. * HBA error attention handler code. Caller is not required to hold any
  3768. * locks.
  3769. **/
  3770. int
  3771. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3772. {
  3773. int rc;
  3774. LPFC_MBOXQ_t *mboxq;
  3775. struct lpfc_mqe *mqe;
  3776. uint8_t *vpd;
  3777. uint32_t vpd_size;
  3778. uint32_t ftr_rsp = 0;
  3779. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3780. struct lpfc_vport *vport = phba->pport;
  3781. struct lpfc_dmabuf *mp;
  3782. /* Perform a PCI function reset to start from clean */
  3783. rc = lpfc_pci_function_reset(phba);
  3784. if (unlikely(rc))
  3785. return -ENODEV;
  3786. /* Check the HBA Host Status Register for readyness */
  3787. rc = lpfc_sli4_post_status_check(phba);
  3788. if (unlikely(rc))
  3789. return -ENODEV;
  3790. else {
  3791. spin_lock_irq(&phba->hbalock);
  3792. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3793. spin_unlock_irq(&phba->hbalock);
  3794. }
  3795. /*
  3796. * Allocate a single mailbox container for initializing the
  3797. * port.
  3798. */
  3799. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3800. if (!mboxq)
  3801. return -ENOMEM;
  3802. /*
  3803. * Continue initialization with default values even if driver failed
  3804. * to read FCoE param config regions
  3805. */
  3806. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3807. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3808. "2570 Failed to read FCoE parameters\n");
  3809. /* Issue READ_REV to collect vpd and FW information. */
  3810. vpd_size = PAGE_SIZE;
  3811. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3812. if (!vpd) {
  3813. rc = -ENOMEM;
  3814. goto out_free_mbox;
  3815. }
  3816. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3817. if (unlikely(rc))
  3818. goto out_free_vpd;
  3819. mqe = &mboxq->u.mqe;
  3820. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3821. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3822. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3823. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3824. LPFC_DCBX_CEE_MODE)
  3825. phba->hba_flag |= HBA_FIP_SUPPORT;
  3826. else
  3827. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3828. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3829. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3830. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3831. "0376 READ_REV Error. SLI Level %d "
  3832. "FCoE enabled %d\n",
  3833. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3834. rc = -EIO;
  3835. goto out_free_vpd;
  3836. }
  3837. /*
  3838. * Evaluate the read rev and vpd data. Populate the driver
  3839. * state with the results. If this routine fails, the failure
  3840. * is not fatal as the driver will use generic values.
  3841. */
  3842. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3843. if (unlikely(!rc)) {
  3844. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3845. "0377 Error %d parsing vpd. "
  3846. "Using defaults.\n", rc);
  3847. rc = 0;
  3848. }
  3849. /* Save information as VPD data */
  3850. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3851. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3852. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3853. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3854. &mqe->un.read_rev);
  3855. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3856. &mqe->un.read_rev);
  3857. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3858. &mqe->un.read_rev);
  3859. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3860. &mqe->un.read_rev);
  3861. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3862. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3863. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3864. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3865. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3866. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3867. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3868. "(%d):0380 READ_REV Status x%x "
  3869. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3870. mboxq->vport ? mboxq->vport->vpi : 0,
  3871. bf_get(lpfc_mqe_status, mqe),
  3872. phba->vpd.rev.opFwName,
  3873. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3874. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3875. /*
  3876. * Discover the port's supported feature set and match it against the
  3877. * hosts requests.
  3878. */
  3879. lpfc_request_features(phba, mboxq);
  3880. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3881. if (unlikely(rc)) {
  3882. rc = -EIO;
  3883. goto out_free_vpd;
  3884. }
  3885. /*
  3886. * The port must support FCP initiator mode as this is the
  3887. * only mode running in the host.
  3888. */
  3889. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3890. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3891. "0378 No support for fcpi mode.\n");
  3892. ftr_rsp++;
  3893. }
  3894. /*
  3895. * If the port cannot support the host's requested features
  3896. * then turn off the global config parameters to disable the
  3897. * feature in the driver. This is not a fatal error.
  3898. */
  3899. if ((phba->cfg_enable_bg) &&
  3900. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3901. ftr_rsp++;
  3902. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3903. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3904. ftr_rsp++;
  3905. if (ftr_rsp) {
  3906. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3907. "0379 Feature Mismatch Data: x%08x %08x "
  3908. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3909. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3910. phba->cfg_enable_npiv, phba->max_vpi);
  3911. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3912. phba->cfg_enable_bg = 0;
  3913. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3914. phba->cfg_enable_npiv = 0;
  3915. }
  3916. /* These SLI3 features are assumed in SLI4 */
  3917. spin_lock_irq(&phba->hbalock);
  3918. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3919. spin_unlock_irq(&phba->hbalock);
  3920. /* Read the port's service parameters. */
  3921. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3922. mboxq->vport = vport;
  3923. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3924. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3925. if (rc == MBX_SUCCESS) {
  3926. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  3927. rc = 0;
  3928. }
  3929. /*
  3930. * This memory was allocated by the lpfc_read_sparam routine. Release
  3931. * it to the mbuf pool.
  3932. */
  3933. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3934. kfree(mp);
  3935. mboxq->context1 = NULL;
  3936. if (unlikely(rc)) {
  3937. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3938. "0382 READ_SPARAM command failed "
  3939. "status %d, mbxStatus x%x\n",
  3940. rc, bf_get(lpfc_mqe_status, mqe));
  3941. phba->link_state = LPFC_HBA_ERROR;
  3942. rc = -EIO;
  3943. goto out_free_vpd;
  3944. }
  3945. if (phba->cfg_soft_wwnn)
  3946. u64_to_wwn(phba->cfg_soft_wwnn,
  3947. vport->fc_sparam.nodeName.u.wwn);
  3948. if (phba->cfg_soft_wwpn)
  3949. u64_to_wwn(phba->cfg_soft_wwpn,
  3950. vport->fc_sparam.portName.u.wwn);
  3951. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  3952. sizeof(struct lpfc_name));
  3953. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  3954. sizeof(struct lpfc_name));
  3955. /* Update the fc_host data structures with new wwn. */
  3956. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  3957. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  3958. /* Register SGL pool to the device using non-embedded mailbox command */
  3959. rc = lpfc_sli4_post_sgl_list(phba);
  3960. if (unlikely(rc)) {
  3961. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3962. "0582 Error %d during sgl post operation\n",
  3963. rc);
  3964. rc = -ENODEV;
  3965. goto out_free_vpd;
  3966. }
  3967. /* Register SCSI SGL pool to the device */
  3968. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  3969. if (unlikely(rc)) {
  3970. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3971. "0383 Error %d during scsi sgl post "
  3972. "operation\n", rc);
  3973. /* Some Scsi buffers were moved to the abort scsi list */
  3974. /* A pci function reset will repost them */
  3975. rc = -ENODEV;
  3976. goto out_free_vpd;
  3977. }
  3978. /* Post the rpi header region to the device. */
  3979. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  3980. if (unlikely(rc)) {
  3981. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3982. "0393 Error %d during rpi post operation\n",
  3983. rc);
  3984. rc = -ENODEV;
  3985. goto out_free_vpd;
  3986. }
  3987. /* Set up all the queues to the device */
  3988. rc = lpfc_sli4_queue_setup(phba);
  3989. if (unlikely(rc)) {
  3990. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3991. "0381 Error %d during queue setup.\n ", rc);
  3992. goto out_stop_timers;
  3993. }
  3994. /* Arm the CQs and then EQs on device */
  3995. lpfc_sli4_arm_cqeq_intr(phba);
  3996. /* Indicate device interrupt mode */
  3997. phba->sli4_hba.intr_enable = 1;
  3998. /* Allow asynchronous mailbox command to go through */
  3999. spin_lock_irq(&phba->hbalock);
  4000. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4001. spin_unlock_irq(&phba->hbalock);
  4002. /* Post receive buffers to the device */
  4003. lpfc_sli4_rb_setup(phba);
  4004. /* Start the ELS watchdog timer */
  4005. mod_timer(&vport->els_tmofunc,
  4006. jiffies + HZ * (phba->fc_ratov * 2));
  4007. /* Start heart beat timer */
  4008. mod_timer(&phba->hb_tmofunc,
  4009. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4010. phba->hb_outstanding = 0;
  4011. phba->last_completion_time = jiffies;
  4012. /* Start error attention (ERATT) polling timer */
  4013. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4014. /*
  4015. * The port is ready, set the host's link state to LINK_DOWN
  4016. * in preparation for link interrupts.
  4017. */
  4018. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4019. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4020. lpfc_set_loopback_flag(phba);
  4021. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4022. spin_lock_irq(&phba->hbalock);
  4023. phba->link_state = LPFC_LINK_DOWN;
  4024. spin_unlock_irq(&phba->hbalock);
  4025. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4026. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4027. kfree(vpd);
  4028. return 0;
  4029. } else
  4030. rc = -EIO;
  4031. /* Unset all the queues set up in this routine when error out */
  4032. if (rc)
  4033. lpfc_sli4_queue_unset(phba);
  4034. out_stop_timers:
  4035. if (rc)
  4036. lpfc_stop_hba_timers(phba);
  4037. out_free_vpd:
  4038. kfree(vpd);
  4039. out_free_mbox:
  4040. mempool_free(mboxq, phba->mbox_mem_pool);
  4041. return rc;
  4042. }
  4043. /**
  4044. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4045. * @ptr: context object - pointer to hba structure.
  4046. *
  4047. * This is the callback function for mailbox timer. The mailbox
  4048. * timer is armed when a new mailbox command is issued and the timer
  4049. * is deleted when the mailbox complete. The function is called by
  4050. * the kernel timer code when a mailbox does not complete within
  4051. * expected time. This function wakes up the worker thread to
  4052. * process the mailbox timeout and returns. All the processing is
  4053. * done by the worker thread function lpfc_mbox_timeout_handler.
  4054. **/
  4055. void
  4056. lpfc_mbox_timeout(unsigned long ptr)
  4057. {
  4058. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4059. unsigned long iflag;
  4060. uint32_t tmo_posted;
  4061. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4062. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4063. if (!tmo_posted)
  4064. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4065. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4066. if (!tmo_posted)
  4067. lpfc_worker_wake_up(phba);
  4068. return;
  4069. }
  4070. /**
  4071. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4072. * @phba: Pointer to HBA context object.
  4073. *
  4074. * This function is called from worker thread when a mailbox command times out.
  4075. * The caller is not required to hold any locks. This function will reset the
  4076. * HBA and recover all the pending commands.
  4077. **/
  4078. void
  4079. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4080. {
  4081. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4082. MAILBOX_t *mb = &pmbox->u.mb;
  4083. struct lpfc_sli *psli = &phba->sli;
  4084. struct lpfc_sli_ring *pring;
  4085. /* Check the pmbox pointer first. There is a race condition
  4086. * between the mbox timeout handler getting executed in the
  4087. * worklist and the mailbox actually completing. When this
  4088. * race condition occurs, the mbox_active will be NULL.
  4089. */
  4090. spin_lock_irq(&phba->hbalock);
  4091. if (pmbox == NULL) {
  4092. lpfc_printf_log(phba, KERN_WARNING,
  4093. LOG_MBOX | LOG_SLI,
  4094. "0353 Active Mailbox cleared - mailbox timeout "
  4095. "exiting\n");
  4096. spin_unlock_irq(&phba->hbalock);
  4097. return;
  4098. }
  4099. /* Mbox cmd <mbxCommand> timeout */
  4100. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4101. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4102. mb->mbxCommand,
  4103. phba->pport->port_state,
  4104. phba->sli.sli_flag,
  4105. phba->sli.mbox_active);
  4106. spin_unlock_irq(&phba->hbalock);
  4107. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4108. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4109. * it to fail all oustanding SCSI IO.
  4110. */
  4111. spin_lock_irq(&phba->pport->work_port_lock);
  4112. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4113. spin_unlock_irq(&phba->pport->work_port_lock);
  4114. spin_lock_irq(&phba->hbalock);
  4115. phba->link_state = LPFC_LINK_UNKNOWN;
  4116. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4117. spin_unlock_irq(&phba->hbalock);
  4118. pring = &psli->ring[psli->fcp_ring];
  4119. lpfc_sli_abort_iocb_ring(phba, pring);
  4120. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4121. "0345 Resetting board due to mailbox timeout\n");
  4122. /* Reset the HBA device */
  4123. lpfc_reset_hba(phba);
  4124. }
  4125. /**
  4126. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4127. * @phba: Pointer to HBA context object.
  4128. * @pmbox: Pointer to mailbox object.
  4129. * @flag: Flag indicating how the mailbox need to be processed.
  4130. *
  4131. * This function is called by discovery code and HBA management code
  4132. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4133. * function gets the hbalock to protect the data structures.
  4134. * The mailbox command can be submitted in polling mode, in which case
  4135. * this function will wait in a polling loop for the completion of the
  4136. * mailbox.
  4137. * If the mailbox is submitted in no_wait mode (not polling) the
  4138. * function will submit the command and returns immediately without waiting
  4139. * for the mailbox completion. The no_wait is supported only when HBA
  4140. * is in SLI2/SLI3 mode - interrupts are enabled.
  4141. * The SLI interface allows only one mailbox pending at a time. If the
  4142. * mailbox is issued in polling mode and there is already a mailbox
  4143. * pending, then the function will return an error. If the mailbox is issued
  4144. * in NO_WAIT mode and there is a mailbox pending already, the function
  4145. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4146. * The sli layer owns the mailbox object until the completion of mailbox
  4147. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4148. * return codes the caller owns the mailbox command after the return of
  4149. * the function.
  4150. **/
  4151. static int
  4152. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4153. uint32_t flag)
  4154. {
  4155. MAILBOX_t *mb;
  4156. struct lpfc_sli *psli = &phba->sli;
  4157. uint32_t status, evtctr;
  4158. uint32_t ha_copy;
  4159. int i;
  4160. unsigned long timeout;
  4161. unsigned long drvr_flag = 0;
  4162. uint32_t word0, ldata;
  4163. void __iomem *to_slim;
  4164. int processing_queue = 0;
  4165. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4166. if (!pmbox) {
  4167. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4168. /* processing mbox queue from intr_handler */
  4169. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4170. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4171. return MBX_SUCCESS;
  4172. }
  4173. processing_queue = 1;
  4174. pmbox = lpfc_mbox_get(phba);
  4175. if (!pmbox) {
  4176. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4177. return MBX_SUCCESS;
  4178. }
  4179. }
  4180. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4181. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4182. if(!pmbox->vport) {
  4183. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4184. lpfc_printf_log(phba, KERN_ERR,
  4185. LOG_MBOX | LOG_VPORT,
  4186. "1806 Mbox x%x failed. No vport\n",
  4187. pmbox->u.mb.mbxCommand);
  4188. dump_stack();
  4189. goto out_not_finished;
  4190. }
  4191. }
  4192. /* If the PCI channel is in offline state, do not post mbox. */
  4193. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4194. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4195. goto out_not_finished;
  4196. }
  4197. /* If HBA has a deferred error attention, fail the iocb. */
  4198. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4199. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4200. goto out_not_finished;
  4201. }
  4202. psli = &phba->sli;
  4203. mb = &pmbox->u.mb;
  4204. status = MBX_SUCCESS;
  4205. if (phba->link_state == LPFC_HBA_ERROR) {
  4206. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4207. /* Mbox command <mbxCommand> cannot issue */
  4208. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4209. "(%d):0311 Mailbox command x%x cannot "
  4210. "issue Data: x%x x%x\n",
  4211. pmbox->vport ? pmbox->vport->vpi : 0,
  4212. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4213. goto out_not_finished;
  4214. }
  4215. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4216. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4217. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4218. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4219. "(%d):2528 Mailbox command x%x cannot "
  4220. "issue Data: x%x x%x\n",
  4221. pmbox->vport ? pmbox->vport->vpi : 0,
  4222. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4223. goto out_not_finished;
  4224. }
  4225. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4226. /* Polling for a mbox command when another one is already active
  4227. * is not allowed in SLI. Also, the driver must have established
  4228. * SLI2 mode to queue and process multiple mbox commands.
  4229. */
  4230. if (flag & MBX_POLL) {
  4231. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4232. /* Mbox command <mbxCommand> cannot issue */
  4233. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4234. "(%d):2529 Mailbox command x%x "
  4235. "cannot issue Data: x%x x%x\n",
  4236. pmbox->vport ? pmbox->vport->vpi : 0,
  4237. pmbox->u.mb.mbxCommand,
  4238. psli->sli_flag, flag);
  4239. goto out_not_finished;
  4240. }
  4241. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4242. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4243. /* Mbox command <mbxCommand> cannot issue */
  4244. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4245. "(%d):2530 Mailbox command x%x "
  4246. "cannot issue Data: x%x x%x\n",
  4247. pmbox->vport ? pmbox->vport->vpi : 0,
  4248. pmbox->u.mb.mbxCommand,
  4249. psli->sli_flag, flag);
  4250. goto out_not_finished;
  4251. }
  4252. /* Another mailbox command is still being processed, queue this
  4253. * command to be processed later.
  4254. */
  4255. lpfc_mbox_put(phba, pmbox);
  4256. /* Mbox cmd issue - BUSY */
  4257. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4258. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4259. "x%x x%x x%x x%x\n",
  4260. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4261. mb->mbxCommand, phba->pport->port_state,
  4262. psli->sli_flag, flag);
  4263. psli->slistat.mbox_busy++;
  4264. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4265. if (pmbox->vport) {
  4266. lpfc_debugfs_disc_trc(pmbox->vport,
  4267. LPFC_DISC_TRC_MBOX_VPORT,
  4268. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4269. (uint32_t)mb->mbxCommand,
  4270. mb->un.varWords[0], mb->un.varWords[1]);
  4271. }
  4272. else {
  4273. lpfc_debugfs_disc_trc(phba->pport,
  4274. LPFC_DISC_TRC_MBOX,
  4275. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4276. (uint32_t)mb->mbxCommand,
  4277. mb->un.varWords[0], mb->un.varWords[1]);
  4278. }
  4279. return MBX_BUSY;
  4280. }
  4281. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4282. /* If we are not polling, we MUST be in SLI2 mode */
  4283. if (flag != MBX_POLL) {
  4284. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4285. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4286. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4287. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4288. /* Mbox command <mbxCommand> cannot issue */
  4289. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4290. "(%d):2531 Mailbox command x%x "
  4291. "cannot issue Data: x%x x%x\n",
  4292. pmbox->vport ? pmbox->vport->vpi : 0,
  4293. pmbox->u.mb.mbxCommand,
  4294. psli->sli_flag, flag);
  4295. goto out_not_finished;
  4296. }
  4297. /* timeout active mbox command */
  4298. mod_timer(&psli->mbox_tmo, (jiffies +
  4299. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4300. }
  4301. /* Mailbox cmd <cmd> issue */
  4302. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4303. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4304. "x%x\n",
  4305. pmbox->vport ? pmbox->vport->vpi : 0,
  4306. mb->mbxCommand, phba->pport->port_state,
  4307. psli->sli_flag, flag);
  4308. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4309. if (pmbox->vport) {
  4310. lpfc_debugfs_disc_trc(pmbox->vport,
  4311. LPFC_DISC_TRC_MBOX_VPORT,
  4312. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4313. (uint32_t)mb->mbxCommand,
  4314. mb->un.varWords[0], mb->un.varWords[1]);
  4315. }
  4316. else {
  4317. lpfc_debugfs_disc_trc(phba->pport,
  4318. LPFC_DISC_TRC_MBOX,
  4319. "MBOX Send: cmd:x%x mb:x%x x%x",
  4320. (uint32_t)mb->mbxCommand,
  4321. mb->un.varWords[0], mb->un.varWords[1]);
  4322. }
  4323. }
  4324. psli->slistat.mbox_cmd++;
  4325. evtctr = psli->slistat.mbox_event;
  4326. /* next set own bit for the adapter and copy over command word */
  4327. mb->mbxOwner = OWN_CHIP;
  4328. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4329. /* First copy command data to host SLIM area */
  4330. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4331. } else {
  4332. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4333. /* copy command data into host mbox for cmpl */
  4334. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4335. }
  4336. /* First copy mbox command data to HBA SLIM, skip past first
  4337. word */
  4338. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4339. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4340. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4341. /* Next copy over first word, with mbxOwner set */
  4342. ldata = *((uint32_t *)mb);
  4343. to_slim = phba->MBslimaddr;
  4344. writel(ldata, to_slim);
  4345. readl(to_slim); /* flush */
  4346. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4347. /* switch over to host mailbox */
  4348. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4349. }
  4350. }
  4351. wmb();
  4352. switch (flag) {
  4353. case MBX_NOWAIT:
  4354. /* Set up reference to mailbox command */
  4355. psli->mbox_active = pmbox;
  4356. /* Interrupt board to do it */
  4357. writel(CA_MBATT, phba->CAregaddr);
  4358. readl(phba->CAregaddr); /* flush */
  4359. /* Don't wait for it to finish, just return */
  4360. break;
  4361. case MBX_POLL:
  4362. /* Set up null reference to mailbox command */
  4363. psli->mbox_active = NULL;
  4364. /* Interrupt board to do it */
  4365. writel(CA_MBATT, phba->CAregaddr);
  4366. readl(phba->CAregaddr); /* flush */
  4367. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4368. /* First read mbox status word */
  4369. word0 = *((uint32_t *)phba->mbox);
  4370. word0 = le32_to_cpu(word0);
  4371. } else {
  4372. /* First read mbox status word */
  4373. word0 = readl(phba->MBslimaddr);
  4374. }
  4375. /* Read the HBA Host Attention Register */
  4376. ha_copy = readl(phba->HAregaddr);
  4377. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4378. mb->mbxCommand) *
  4379. 1000) + jiffies;
  4380. i = 0;
  4381. /* Wait for command to complete */
  4382. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4383. (!(ha_copy & HA_MBATT) &&
  4384. (phba->link_state > LPFC_WARM_START))) {
  4385. if (time_after(jiffies, timeout)) {
  4386. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4387. spin_unlock_irqrestore(&phba->hbalock,
  4388. drvr_flag);
  4389. goto out_not_finished;
  4390. }
  4391. /* Check if we took a mbox interrupt while we were
  4392. polling */
  4393. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4394. && (evtctr != psli->slistat.mbox_event))
  4395. break;
  4396. if (i++ > 10) {
  4397. spin_unlock_irqrestore(&phba->hbalock,
  4398. drvr_flag);
  4399. msleep(1);
  4400. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4401. }
  4402. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4403. /* First copy command data */
  4404. word0 = *((uint32_t *)phba->mbox);
  4405. word0 = le32_to_cpu(word0);
  4406. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4407. MAILBOX_t *slimmb;
  4408. uint32_t slimword0;
  4409. /* Check real SLIM for any errors */
  4410. slimword0 = readl(phba->MBslimaddr);
  4411. slimmb = (MAILBOX_t *) & slimword0;
  4412. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4413. && slimmb->mbxStatus) {
  4414. psli->sli_flag &=
  4415. ~LPFC_SLI_ACTIVE;
  4416. word0 = slimword0;
  4417. }
  4418. }
  4419. } else {
  4420. /* First copy command data */
  4421. word0 = readl(phba->MBslimaddr);
  4422. }
  4423. /* Read the HBA Host Attention Register */
  4424. ha_copy = readl(phba->HAregaddr);
  4425. }
  4426. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4427. /* copy results back to user */
  4428. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4429. } else {
  4430. /* First copy command data */
  4431. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4432. MAILBOX_CMD_SIZE);
  4433. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4434. pmbox->context2) {
  4435. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4436. phba->MBslimaddr + DMP_RSP_OFFSET,
  4437. mb->un.varDmp.word_cnt);
  4438. }
  4439. }
  4440. writel(HA_MBATT, phba->HAregaddr);
  4441. readl(phba->HAregaddr); /* flush */
  4442. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4443. status = mb->mbxStatus;
  4444. }
  4445. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4446. return status;
  4447. out_not_finished:
  4448. if (processing_queue) {
  4449. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4450. lpfc_mbox_cmpl_put(phba, pmbox);
  4451. }
  4452. return MBX_NOT_FINISHED;
  4453. }
  4454. /**
  4455. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4456. * @phba: Pointer to HBA context object.
  4457. *
  4458. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4459. * the driver internal pending mailbox queue. It will then try to wait out the
  4460. * possible outstanding mailbox command before return.
  4461. *
  4462. * Returns:
  4463. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4464. * the outstanding mailbox command timed out.
  4465. **/
  4466. static int
  4467. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4468. {
  4469. struct lpfc_sli *psli = &phba->sli;
  4470. uint8_t actcmd = MBX_HEARTBEAT;
  4471. int rc = 0;
  4472. unsigned long timeout;
  4473. /* Mark the asynchronous mailbox command posting as blocked */
  4474. spin_lock_irq(&phba->hbalock);
  4475. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4476. if (phba->sli.mbox_active)
  4477. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4478. spin_unlock_irq(&phba->hbalock);
  4479. /* Determine how long we might wait for the active mailbox
  4480. * command to be gracefully completed by firmware.
  4481. */
  4482. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4483. jiffies;
  4484. /* Wait for the outstnading mailbox command to complete */
  4485. while (phba->sli.mbox_active) {
  4486. /* Check active mailbox complete status every 2ms */
  4487. msleep(2);
  4488. if (time_after(jiffies, timeout)) {
  4489. /* Timeout, marked the outstanding cmd not complete */
  4490. rc = 1;
  4491. break;
  4492. }
  4493. }
  4494. /* Can not cleanly block async mailbox command, fails it */
  4495. if (rc) {
  4496. spin_lock_irq(&phba->hbalock);
  4497. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4498. spin_unlock_irq(&phba->hbalock);
  4499. }
  4500. return rc;
  4501. }
  4502. /**
  4503. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4504. * @phba: Pointer to HBA context object.
  4505. *
  4506. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4507. * commands from the driver internal pending mailbox queue. It makes sure
  4508. * that there is no outstanding mailbox command before resuming posting
  4509. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4510. * mailbox command, it will try to wait it out before resuming asynchronous
  4511. * mailbox command posting.
  4512. **/
  4513. static void
  4514. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4515. {
  4516. struct lpfc_sli *psli = &phba->sli;
  4517. spin_lock_irq(&phba->hbalock);
  4518. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4519. /* Asynchronous mailbox posting is not blocked, do nothing */
  4520. spin_unlock_irq(&phba->hbalock);
  4521. return;
  4522. }
  4523. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4524. * successful or timeout, after timing-out the outstanding mailbox
  4525. * command shall always be removed, so just unblock posting async
  4526. * mailbox command and resume
  4527. */
  4528. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4529. spin_unlock_irq(&phba->hbalock);
  4530. /* wake up worker thread to post asynchronlous mailbox command */
  4531. lpfc_worker_wake_up(phba);
  4532. }
  4533. /**
  4534. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4535. * @phba: Pointer to HBA context object.
  4536. * @mboxq: Pointer to mailbox object.
  4537. *
  4538. * The function posts a mailbox to the port. The mailbox is expected
  4539. * to be comletely filled in and ready for the port to operate on it.
  4540. * This routine executes a synchronous completion operation on the
  4541. * mailbox by polling for its completion.
  4542. *
  4543. * The caller must not be holding any locks when calling this routine.
  4544. *
  4545. * Returns:
  4546. * MBX_SUCCESS - mailbox posted successfully
  4547. * Any of the MBX error values.
  4548. **/
  4549. static int
  4550. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4551. {
  4552. int rc = MBX_SUCCESS;
  4553. unsigned long iflag;
  4554. uint32_t db_ready;
  4555. uint32_t mcqe_status;
  4556. uint32_t mbx_cmnd;
  4557. unsigned long timeout;
  4558. struct lpfc_sli *psli = &phba->sli;
  4559. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4560. struct lpfc_bmbx_create *mbox_rgn;
  4561. struct dma_address *dma_address;
  4562. struct lpfc_register bmbx_reg;
  4563. /*
  4564. * Only one mailbox can be active to the bootstrap mailbox region
  4565. * at a time and there is no queueing provided.
  4566. */
  4567. spin_lock_irqsave(&phba->hbalock, iflag);
  4568. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4569. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4570. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4571. "(%d):2532 Mailbox command x%x (x%x) "
  4572. "cannot issue Data: x%x x%x\n",
  4573. mboxq->vport ? mboxq->vport->vpi : 0,
  4574. mboxq->u.mb.mbxCommand,
  4575. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4576. psli->sli_flag, MBX_POLL);
  4577. return MBXERR_ERROR;
  4578. }
  4579. /* The server grabs the token and owns it until release */
  4580. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4581. phba->sli.mbox_active = mboxq;
  4582. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4583. /*
  4584. * Initialize the bootstrap memory region to avoid stale data areas
  4585. * in the mailbox post. Then copy the caller's mailbox contents to
  4586. * the bmbx mailbox region.
  4587. */
  4588. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4589. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4590. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4591. sizeof(struct lpfc_mqe));
  4592. /* Post the high mailbox dma address to the port and wait for ready. */
  4593. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4594. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4595. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4596. * 1000) + jiffies;
  4597. do {
  4598. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4599. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4600. if (!db_ready)
  4601. msleep(2);
  4602. if (time_after(jiffies, timeout)) {
  4603. rc = MBXERR_ERROR;
  4604. goto exit;
  4605. }
  4606. } while (!db_ready);
  4607. /* Post the low mailbox dma address to the port. */
  4608. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4609. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4610. * 1000) + jiffies;
  4611. do {
  4612. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4613. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4614. if (!db_ready)
  4615. msleep(2);
  4616. if (time_after(jiffies, timeout)) {
  4617. rc = MBXERR_ERROR;
  4618. goto exit;
  4619. }
  4620. } while (!db_ready);
  4621. /*
  4622. * Read the CQ to ensure the mailbox has completed.
  4623. * If so, update the mailbox status so that the upper layers
  4624. * can complete the request normally.
  4625. */
  4626. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4627. sizeof(struct lpfc_mqe));
  4628. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4629. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4630. sizeof(struct lpfc_mcqe));
  4631. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4632. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4633. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4634. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4635. rc = MBXERR_ERROR;
  4636. }
  4637. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4638. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4639. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4640. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4641. mboxq->vport ? mboxq->vport->vpi : 0,
  4642. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4643. bf_get(lpfc_mqe_status, mb),
  4644. mb->un.mb_words[0], mb->un.mb_words[1],
  4645. mb->un.mb_words[2], mb->un.mb_words[3],
  4646. mb->un.mb_words[4], mb->un.mb_words[5],
  4647. mb->un.mb_words[6], mb->un.mb_words[7],
  4648. mb->un.mb_words[8], mb->un.mb_words[9],
  4649. mb->un.mb_words[10], mb->un.mb_words[11],
  4650. mb->un.mb_words[12], mboxq->mcqe.word0,
  4651. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4652. mboxq->mcqe.trailer);
  4653. exit:
  4654. /* We are holding the token, no needed for lock when release */
  4655. spin_lock_irqsave(&phba->hbalock, iflag);
  4656. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4657. phba->sli.mbox_active = NULL;
  4658. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4659. return rc;
  4660. }
  4661. /**
  4662. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4663. * @phba: Pointer to HBA context object.
  4664. * @pmbox: Pointer to mailbox object.
  4665. * @flag: Flag indicating how the mailbox need to be processed.
  4666. *
  4667. * This function is called by discovery code and HBA management code to submit
  4668. * a mailbox command to firmware with SLI-4 interface spec.
  4669. *
  4670. * Return codes the caller owns the mailbox command after the return of the
  4671. * function.
  4672. **/
  4673. static int
  4674. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4675. uint32_t flag)
  4676. {
  4677. struct lpfc_sli *psli = &phba->sli;
  4678. unsigned long iflags;
  4679. int rc;
  4680. rc = lpfc_mbox_dev_check(phba);
  4681. if (unlikely(rc)) {
  4682. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4683. "(%d):2544 Mailbox command x%x (x%x) "
  4684. "cannot issue Data: x%x x%x\n",
  4685. mboxq->vport ? mboxq->vport->vpi : 0,
  4686. mboxq->u.mb.mbxCommand,
  4687. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4688. psli->sli_flag, flag);
  4689. goto out_not_finished;
  4690. }
  4691. /* Detect polling mode and jump to a handler */
  4692. if (!phba->sli4_hba.intr_enable) {
  4693. if (flag == MBX_POLL)
  4694. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4695. else
  4696. rc = -EIO;
  4697. if (rc != MBX_SUCCESS)
  4698. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4699. "(%d):2541 Mailbox command x%x "
  4700. "(x%x) cannot issue Data: x%x x%x\n",
  4701. mboxq->vport ? mboxq->vport->vpi : 0,
  4702. mboxq->u.mb.mbxCommand,
  4703. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4704. psli->sli_flag, flag);
  4705. return rc;
  4706. } else if (flag == MBX_POLL) {
  4707. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4708. "(%d):2542 Try to issue mailbox command "
  4709. "x%x (x%x) synchronously ahead of async"
  4710. "mailbox command queue: x%x x%x\n",
  4711. mboxq->vport ? mboxq->vport->vpi : 0,
  4712. mboxq->u.mb.mbxCommand,
  4713. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4714. psli->sli_flag, flag);
  4715. /* Try to block the asynchronous mailbox posting */
  4716. rc = lpfc_sli4_async_mbox_block(phba);
  4717. if (!rc) {
  4718. /* Successfully blocked, now issue sync mbox cmd */
  4719. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4720. if (rc != MBX_SUCCESS)
  4721. lpfc_printf_log(phba, KERN_ERR,
  4722. LOG_MBOX | LOG_SLI,
  4723. "(%d):2597 Mailbox command "
  4724. "x%x (x%x) cannot issue "
  4725. "Data: x%x x%x\n",
  4726. mboxq->vport ?
  4727. mboxq->vport->vpi : 0,
  4728. mboxq->u.mb.mbxCommand,
  4729. lpfc_sli4_mbox_opcode_get(phba,
  4730. mboxq),
  4731. psli->sli_flag, flag);
  4732. /* Unblock the async mailbox posting afterward */
  4733. lpfc_sli4_async_mbox_unblock(phba);
  4734. }
  4735. return rc;
  4736. }
  4737. /* Now, interrupt mode asynchrous mailbox command */
  4738. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4739. if (rc) {
  4740. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4741. "(%d):2543 Mailbox command x%x (x%x) "
  4742. "cannot issue Data: x%x x%x\n",
  4743. mboxq->vport ? mboxq->vport->vpi : 0,
  4744. mboxq->u.mb.mbxCommand,
  4745. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4746. psli->sli_flag, flag);
  4747. goto out_not_finished;
  4748. }
  4749. /* Put the mailbox command to the driver internal FIFO */
  4750. psli->slistat.mbox_busy++;
  4751. spin_lock_irqsave(&phba->hbalock, iflags);
  4752. lpfc_mbox_put(phba, mboxq);
  4753. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4754. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4755. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4756. "x%x (x%x) x%x x%x x%x\n",
  4757. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4758. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4759. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4760. phba->pport->port_state,
  4761. psli->sli_flag, MBX_NOWAIT);
  4762. /* Wake up worker thread to transport mailbox command from head */
  4763. lpfc_worker_wake_up(phba);
  4764. return MBX_BUSY;
  4765. out_not_finished:
  4766. return MBX_NOT_FINISHED;
  4767. }
  4768. /**
  4769. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4770. * @phba: Pointer to HBA context object.
  4771. *
  4772. * This function is called by worker thread to send a mailbox command to
  4773. * SLI4 HBA firmware.
  4774. *
  4775. **/
  4776. int
  4777. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4778. {
  4779. struct lpfc_sli *psli = &phba->sli;
  4780. LPFC_MBOXQ_t *mboxq;
  4781. int rc = MBX_SUCCESS;
  4782. unsigned long iflags;
  4783. struct lpfc_mqe *mqe;
  4784. uint32_t mbx_cmnd;
  4785. /* Check interrupt mode before post async mailbox command */
  4786. if (unlikely(!phba->sli4_hba.intr_enable))
  4787. return MBX_NOT_FINISHED;
  4788. /* Check for mailbox command service token */
  4789. spin_lock_irqsave(&phba->hbalock, iflags);
  4790. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4791. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4792. return MBX_NOT_FINISHED;
  4793. }
  4794. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4795. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4796. return MBX_NOT_FINISHED;
  4797. }
  4798. if (unlikely(phba->sli.mbox_active)) {
  4799. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4800. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4801. "0384 There is pending active mailbox cmd\n");
  4802. return MBX_NOT_FINISHED;
  4803. }
  4804. /* Take the mailbox command service token */
  4805. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4806. /* Get the next mailbox command from head of queue */
  4807. mboxq = lpfc_mbox_get(phba);
  4808. /* If no more mailbox command waiting for post, we're done */
  4809. if (!mboxq) {
  4810. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4811. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4812. return MBX_SUCCESS;
  4813. }
  4814. phba->sli.mbox_active = mboxq;
  4815. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4816. /* Check device readiness for posting mailbox command */
  4817. rc = lpfc_mbox_dev_check(phba);
  4818. if (unlikely(rc))
  4819. /* Driver clean routine will clean up pending mailbox */
  4820. goto out_not_finished;
  4821. /* Prepare the mbox command to be posted */
  4822. mqe = &mboxq->u.mqe;
  4823. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4824. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4825. mod_timer(&psli->mbox_tmo, (jiffies +
  4826. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4827. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4828. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4829. "x%x x%x\n",
  4830. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4831. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4832. phba->pport->port_state, psli->sli_flag);
  4833. if (mbx_cmnd != MBX_HEARTBEAT) {
  4834. if (mboxq->vport) {
  4835. lpfc_debugfs_disc_trc(mboxq->vport,
  4836. LPFC_DISC_TRC_MBOX_VPORT,
  4837. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4838. mbx_cmnd, mqe->un.mb_words[0],
  4839. mqe->un.mb_words[1]);
  4840. } else {
  4841. lpfc_debugfs_disc_trc(phba->pport,
  4842. LPFC_DISC_TRC_MBOX,
  4843. "MBOX Send: cmd:x%x mb:x%x x%x",
  4844. mbx_cmnd, mqe->un.mb_words[0],
  4845. mqe->un.mb_words[1]);
  4846. }
  4847. }
  4848. psli->slistat.mbox_cmd++;
  4849. /* Post the mailbox command to the port */
  4850. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4851. if (rc != MBX_SUCCESS) {
  4852. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4853. "(%d):2533 Mailbox command x%x (x%x) "
  4854. "cannot issue Data: x%x x%x\n",
  4855. mboxq->vport ? mboxq->vport->vpi : 0,
  4856. mboxq->u.mb.mbxCommand,
  4857. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4858. psli->sli_flag, MBX_NOWAIT);
  4859. goto out_not_finished;
  4860. }
  4861. return rc;
  4862. out_not_finished:
  4863. spin_lock_irqsave(&phba->hbalock, iflags);
  4864. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4865. __lpfc_mbox_cmpl_put(phba, mboxq);
  4866. /* Release the token */
  4867. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4868. phba->sli.mbox_active = NULL;
  4869. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4870. return MBX_NOT_FINISHED;
  4871. }
  4872. /**
  4873. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4874. * @phba: Pointer to HBA context object.
  4875. * @pmbox: Pointer to mailbox object.
  4876. * @flag: Flag indicating how the mailbox need to be processed.
  4877. *
  4878. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4879. * the API jump table function pointer from the lpfc_hba struct.
  4880. *
  4881. * Return codes the caller owns the mailbox command after the return of the
  4882. * function.
  4883. **/
  4884. int
  4885. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4886. {
  4887. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4888. }
  4889. /**
  4890. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4891. * @phba: The hba struct for which this call is being executed.
  4892. * @dev_grp: The HBA PCI-Device group number.
  4893. *
  4894. * This routine sets up the mbox interface API function jump table in @phba
  4895. * struct.
  4896. * Returns: 0 - success, -ENODEV - failure.
  4897. **/
  4898. int
  4899. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4900. {
  4901. switch (dev_grp) {
  4902. case LPFC_PCI_DEV_LP:
  4903. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4904. phba->lpfc_sli_handle_slow_ring_event =
  4905. lpfc_sli_handle_slow_ring_event_s3;
  4906. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4907. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4908. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4909. break;
  4910. case LPFC_PCI_DEV_OC:
  4911. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4912. phba->lpfc_sli_handle_slow_ring_event =
  4913. lpfc_sli_handle_slow_ring_event_s4;
  4914. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4915. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4916. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4917. break;
  4918. default:
  4919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4920. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4921. dev_grp);
  4922. return -ENODEV;
  4923. break;
  4924. }
  4925. return 0;
  4926. }
  4927. /**
  4928. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4929. * @phba: Pointer to HBA context object.
  4930. * @pring: Pointer to driver SLI ring object.
  4931. * @piocb: Pointer to address of newly added command iocb.
  4932. *
  4933. * This function is called with hbalock held to add a command
  4934. * iocb to the txq when SLI layer cannot submit the command iocb
  4935. * to the ring.
  4936. **/
  4937. static void
  4938. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4939. struct lpfc_iocbq *piocb)
  4940. {
  4941. /* Insert the caller's iocb in the txq tail for later processing. */
  4942. list_add_tail(&piocb->list, &pring->txq);
  4943. pring->txq_cnt++;
  4944. }
  4945. /**
  4946. * lpfc_sli_next_iocb - Get the next iocb in the txq
  4947. * @phba: Pointer to HBA context object.
  4948. * @pring: Pointer to driver SLI ring object.
  4949. * @piocb: Pointer to address of newly added command iocb.
  4950. *
  4951. * This function is called with hbalock held before a new
  4952. * iocb is submitted to the firmware. This function checks
  4953. * txq to flush the iocbs in txq to Firmware before
  4954. * submitting new iocbs to the Firmware.
  4955. * If there are iocbs in the txq which need to be submitted
  4956. * to firmware, lpfc_sli_next_iocb returns the first element
  4957. * of the txq after dequeuing it from txq.
  4958. * If there is no iocb in the txq then the function will return
  4959. * *piocb and *piocb is set to NULL. Caller needs to check
  4960. * *piocb to find if there are more commands in the txq.
  4961. **/
  4962. static struct lpfc_iocbq *
  4963. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4964. struct lpfc_iocbq **piocb)
  4965. {
  4966. struct lpfc_iocbq * nextiocb;
  4967. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  4968. if (!nextiocb) {
  4969. nextiocb = *piocb;
  4970. *piocb = NULL;
  4971. }
  4972. return nextiocb;
  4973. }
  4974. /**
  4975. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  4976. * @phba: Pointer to HBA context object.
  4977. * @ring_number: SLI ring number to issue iocb on.
  4978. * @piocb: Pointer to command iocb.
  4979. * @flag: Flag indicating if this command can be put into txq.
  4980. *
  4981. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  4982. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  4983. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  4984. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  4985. * this function allows only iocbs for posting buffers. This function finds
  4986. * next available slot in the command ring and posts the command to the
  4987. * available slot and writes the port attention register to request HBA start
  4988. * processing new iocb. If there is no slot available in the ring and
  4989. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  4990. * the function returns IOCB_BUSY.
  4991. *
  4992. * This function is called with hbalock held. The function will return success
  4993. * after it successfully submit the iocb to firmware or after adding to the
  4994. * txq.
  4995. **/
  4996. static int
  4997. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  4998. struct lpfc_iocbq *piocb, uint32_t flag)
  4999. {
  5000. struct lpfc_iocbq *nextiocb;
  5001. IOCB_t *iocb;
  5002. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5003. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5004. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5005. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5006. lpfc_printf_log(phba, KERN_ERR,
  5007. LOG_SLI | LOG_VPORT,
  5008. "1807 IOCB x%x failed. No vport\n",
  5009. piocb->iocb.ulpCommand);
  5010. dump_stack();
  5011. return IOCB_ERROR;
  5012. }
  5013. /* If the PCI channel is in offline state, do not post iocbs. */
  5014. if (unlikely(pci_channel_offline(phba->pcidev)))
  5015. return IOCB_ERROR;
  5016. /* If HBA has a deferred error attention, fail the iocb. */
  5017. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5018. return IOCB_ERROR;
  5019. /*
  5020. * We should never get an IOCB if we are in a < LINK_DOWN state
  5021. */
  5022. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5023. return IOCB_ERROR;
  5024. /*
  5025. * Check to see if we are blocking IOCB processing because of a
  5026. * outstanding event.
  5027. */
  5028. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5029. goto iocb_busy;
  5030. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5031. /*
  5032. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5033. * can be issued if the link is not up.
  5034. */
  5035. switch (piocb->iocb.ulpCommand) {
  5036. case CMD_GEN_REQUEST64_CR:
  5037. case CMD_GEN_REQUEST64_CX:
  5038. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5039. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5040. FC_RCTL_DD_UNSOL_CMD) ||
  5041. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5042. MENLO_TRANSPORT_TYPE))
  5043. goto iocb_busy;
  5044. break;
  5045. case CMD_QUE_RING_BUF_CN:
  5046. case CMD_QUE_RING_BUF64_CN:
  5047. /*
  5048. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5049. * completion, iocb_cmpl MUST be 0.
  5050. */
  5051. if (piocb->iocb_cmpl)
  5052. piocb->iocb_cmpl = NULL;
  5053. /*FALLTHROUGH*/
  5054. case CMD_CREATE_XRI_CR:
  5055. case CMD_CLOSE_XRI_CN:
  5056. case CMD_CLOSE_XRI_CX:
  5057. break;
  5058. default:
  5059. goto iocb_busy;
  5060. }
  5061. /*
  5062. * For FCP commands, we must be in a state where we can process link
  5063. * attention events.
  5064. */
  5065. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5066. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5067. goto iocb_busy;
  5068. }
  5069. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5070. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5071. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5072. if (iocb)
  5073. lpfc_sli_update_ring(phba, pring);
  5074. else
  5075. lpfc_sli_update_full_ring(phba, pring);
  5076. if (!piocb)
  5077. return IOCB_SUCCESS;
  5078. goto out_busy;
  5079. iocb_busy:
  5080. pring->stats.iocb_cmd_delay++;
  5081. out_busy:
  5082. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5083. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5084. return IOCB_SUCCESS;
  5085. }
  5086. return IOCB_BUSY;
  5087. }
  5088. /**
  5089. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5090. * @phba: Pointer to HBA context object.
  5091. * @piocb: Pointer to command iocb.
  5092. * @sglq: Pointer to the scatter gather queue object.
  5093. *
  5094. * This routine converts the bpl or bde that is in the IOCB
  5095. * to a sgl list for the sli4 hardware. The physical address
  5096. * of the bpl/bde is converted back to a virtual address.
  5097. * If the IOCB contains a BPL then the list of BDE's is
  5098. * converted to sli4_sge's. If the IOCB contains a single
  5099. * BDE then it is converted to a single sli_sge.
  5100. * The IOCB is still in cpu endianess so the contents of
  5101. * the bpl can be used without byte swapping.
  5102. *
  5103. * Returns valid XRI = Success, NO_XRI = Failure.
  5104. **/
  5105. static uint16_t
  5106. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5107. struct lpfc_sglq *sglq)
  5108. {
  5109. uint16_t xritag = NO_XRI;
  5110. struct ulp_bde64 *bpl = NULL;
  5111. struct ulp_bde64 bde;
  5112. struct sli4_sge *sgl = NULL;
  5113. IOCB_t *icmd;
  5114. int numBdes = 0;
  5115. int i = 0;
  5116. if (!piocbq || !sglq)
  5117. return xritag;
  5118. sgl = (struct sli4_sge *)sglq->sgl;
  5119. icmd = &piocbq->iocb;
  5120. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5121. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5122. sizeof(struct ulp_bde64);
  5123. /* The addrHigh and addrLow fields within the IOCB
  5124. * have not been byteswapped yet so there is no
  5125. * need to swap them back.
  5126. */
  5127. bpl = (struct ulp_bde64 *)
  5128. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5129. if (!bpl)
  5130. return xritag;
  5131. for (i = 0; i < numBdes; i++) {
  5132. /* Should already be byte swapped. */
  5133. sgl->addr_hi = bpl->addrHigh;
  5134. sgl->addr_lo = bpl->addrLow;
  5135. /* swap the size field back to the cpu so we
  5136. * can assign it to the sgl.
  5137. */
  5138. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5139. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5140. if ((i+1) == numBdes)
  5141. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5142. else
  5143. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5144. sgl->word2 = cpu_to_le32(sgl->word2);
  5145. sgl->word3 = cpu_to_le32(sgl->word3);
  5146. bpl++;
  5147. sgl++;
  5148. }
  5149. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5150. /* The addrHigh and addrLow fields of the BDE have not
  5151. * been byteswapped yet so they need to be swapped
  5152. * before putting them in the sgl.
  5153. */
  5154. sgl->addr_hi =
  5155. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5156. sgl->addr_lo =
  5157. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5158. bf_set(lpfc_sli4_sge_len, sgl,
  5159. icmd->un.genreq64.bdl.bdeSize);
  5160. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5161. sgl->word2 = cpu_to_le32(sgl->word2);
  5162. sgl->word3 = cpu_to_le32(sgl->word3);
  5163. }
  5164. return sglq->sli4_xritag;
  5165. }
  5166. /**
  5167. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5168. * @phba: Pointer to HBA context object.
  5169. *
  5170. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5171. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5172. * held.
  5173. *
  5174. * Return: index into SLI4 fast-path FCP queue index.
  5175. **/
  5176. static uint32_t
  5177. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5178. {
  5179. ++phba->fcp_qidx;
  5180. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5181. phba->fcp_qidx = 0;
  5182. return phba->fcp_qidx;
  5183. }
  5184. /**
  5185. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5186. * @phba: Pointer to HBA context object.
  5187. * @piocb: Pointer to command iocb.
  5188. * @wqe: Pointer to the work queue entry.
  5189. *
  5190. * This routine converts the iocb command to its Work Queue Entry
  5191. * equivalent. The wqe pointer should not have any fields set when
  5192. * this routine is called because it will memcpy over them.
  5193. * This routine does not set the CQ_ID or the WQEC bits in the
  5194. * wqe.
  5195. *
  5196. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5197. **/
  5198. static int
  5199. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5200. union lpfc_wqe *wqe)
  5201. {
  5202. uint32_t xmit_len = 0, total_len = 0;
  5203. uint8_t ct = 0;
  5204. uint32_t fip;
  5205. uint32_t abort_tag;
  5206. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5207. uint8_t cmnd;
  5208. uint16_t xritag;
  5209. struct ulp_bde64 *bpl = NULL;
  5210. uint32_t els_id = ELS_ID_DEFAULT;
  5211. int numBdes, i;
  5212. struct ulp_bde64 bde;
  5213. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5214. /* The fcp commands will set command type */
  5215. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5216. command_type = FCP_COMMAND;
  5217. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5218. command_type = ELS_COMMAND_FIP;
  5219. else
  5220. command_type = ELS_COMMAND_NON_FIP;
  5221. /* Some of the fields are in the right position already */
  5222. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5223. abort_tag = (uint32_t) iocbq->iotag;
  5224. xritag = iocbq->sli4_xritag;
  5225. wqe->words[7] = 0; /* The ct field has moved so reset */
  5226. /* words0-2 bpl convert bde */
  5227. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5228. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5229. sizeof(struct ulp_bde64);
  5230. bpl = (struct ulp_bde64 *)
  5231. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5232. if (!bpl)
  5233. return IOCB_ERROR;
  5234. /* Should already be byte swapped. */
  5235. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5236. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5237. /* swap the size field back to the cpu so we
  5238. * can assign it to the sgl.
  5239. */
  5240. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5241. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5242. total_len = 0;
  5243. for (i = 0; i < numBdes; i++) {
  5244. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5245. total_len += bde.tus.f.bdeSize;
  5246. }
  5247. } else
  5248. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5249. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5250. cmnd = iocbq->iocb.ulpCommand;
  5251. switch (iocbq->iocb.ulpCommand) {
  5252. case CMD_ELS_REQUEST64_CR:
  5253. if (!iocbq->iocb.ulpLe) {
  5254. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5255. "2007 Only Limited Edition cmd Format"
  5256. " supported 0x%x\n",
  5257. iocbq->iocb.ulpCommand);
  5258. return IOCB_ERROR;
  5259. }
  5260. wqe->els_req.payload_len = xmit_len;
  5261. /* Els_reguest64 has a TMO */
  5262. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5263. iocbq->iocb.ulpTimeout);
  5264. /* Need a VF for word 4 set the vf bit*/
  5265. bf_set(els_req64_vf, &wqe->els_req, 0);
  5266. /* And a VFID for word 12 */
  5267. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5268. /*
  5269. * Set ct field to 3, indicates that the context_tag field
  5270. * contains the FCFI and remote N_Port_ID is
  5271. * in word 5.
  5272. */
  5273. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5274. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5275. iocbq->iocb.ulpContext);
  5276. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5277. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5278. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5279. if (command_type == ELS_COMMAND_FIP) {
  5280. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5281. >> LPFC_FIP_ELS_ID_SHIFT);
  5282. }
  5283. bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id);
  5284. break;
  5285. case CMD_XMIT_SEQUENCE64_CX:
  5286. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5287. iocbq->iocb.un.ulpWord[3]);
  5288. wqe->generic.word3 = 0;
  5289. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5290. /* The entire sequence is transmitted for this IOCB */
  5291. xmit_len = total_len;
  5292. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5293. case CMD_XMIT_SEQUENCE64_CR:
  5294. /* word3 iocb=io_tag32 wqe=payload_offset */
  5295. /* payload offset used for multilpe outstanding
  5296. * sequences on the same exchange
  5297. */
  5298. wqe->words[3] = 0;
  5299. /* word4 relative_offset memcpy */
  5300. /* word5 r_ctl/df_ctl memcpy */
  5301. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5302. wqe->xmit_sequence.xmit_len = xmit_len;
  5303. command_type = OTHER_COMMAND;
  5304. break;
  5305. case CMD_XMIT_BCAST64_CN:
  5306. /* word3 iocb=iotag32 wqe=payload_len */
  5307. wqe->words[3] = 0; /* no definition for this in wqe */
  5308. /* word4 iocb=rsvd wqe=rsvd */
  5309. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5310. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5311. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5312. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5313. break;
  5314. case CMD_FCP_IWRITE64_CR:
  5315. command_type = FCP_COMMAND_DATA_OUT;
  5316. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5317. * confusing.
  5318. * word3 is payload_len: byte offset to the sgl entry for the
  5319. * fcp_command.
  5320. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5321. * word5 is initial xfer len 0 = wait for xfer-ready
  5322. */
  5323. /* Always wait for xfer-ready before sending data */
  5324. wqe->fcp_iwrite.initial_xfer_len = 0;
  5325. /* word 4 (xfer length) should have been set on the memcpy */
  5326. /* allow write to fall through to read */
  5327. case CMD_FCP_IREAD64_CR:
  5328. /* FCP_CMD is always the 1st sgl entry */
  5329. wqe->fcp_iread.payload_len =
  5330. xmit_len + sizeof(struct fcp_rsp);
  5331. /* word 4 (xfer length) should have been set on the memcpy */
  5332. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5333. iocbq->iocb.ulpFCP2Rcvy);
  5334. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5335. /* The XC bit and the XS bit are similar. The driver never
  5336. * tracked whether or not the exchange was previouslly open.
  5337. * XC = Exchange create, 0 is create. 1 is already open.
  5338. * XS = link cmd: 1 do not close the exchange after command.
  5339. * XS = 0 close exchange when command completes.
  5340. * The only time we would not set the XC bit is when the XS bit
  5341. * is set and we are sending our 2nd or greater command on
  5342. * this exchange.
  5343. */
  5344. /* Always open the exchange */
  5345. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5346. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5347. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5348. break;
  5349. case CMD_FCP_ICMND64_CR:
  5350. /* Always open the exchange */
  5351. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5352. wqe->words[4] = 0;
  5353. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5354. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5355. break;
  5356. case CMD_GEN_REQUEST64_CR:
  5357. /* word3 command length is described as byte offset to the
  5358. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5359. * sgl[0] = cmnd
  5360. * sgl[1] = rsp.
  5361. *
  5362. */
  5363. wqe->gen_req.command_len = xmit_len;
  5364. /* Word4 parameter copied in the memcpy */
  5365. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5366. /* word6 context tag copied in memcpy */
  5367. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5368. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5369. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5370. "2015 Invalid CT %x command 0x%x\n",
  5371. ct, iocbq->iocb.ulpCommand);
  5372. return IOCB_ERROR;
  5373. }
  5374. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5375. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5376. iocbq->iocb.ulpTimeout);
  5377. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5378. command_type = OTHER_COMMAND;
  5379. break;
  5380. case CMD_XMIT_ELS_RSP64_CX:
  5381. /* words0-2 BDE memcpy */
  5382. /* word3 iocb=iotag32 wqe=rsvd */
  5383. wqe->words[3] = 0;
  5384. /* word4 iocb=did wge=rsvd. */
  5385. wqe->words[4] = 0;
  5386. /* word5 iocb=rsvd wge=did */
  5387. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5388. iocbq->iocb.un.elsreq64.remoteID);
  5389. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5390. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5391. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5392. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5393. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5394. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5395. iocbq->vport->vpi + phba->vpi_base);
  5396. command_type = OTHER_COMMAND;
  5397. break;
  5398. case CMD_CLOSE_XRI_CN:
  5399. case CMD_ABORT_XRI_CN:
  5400. case CMD_ABORT_XRI_CX:
  5401. /* words 0-2 memcpy should be 0 rserved */
  5402. /* port will send abts */
  5403. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5404. /*
  5405. * The link is down so the fw does not need to send abts
  5406. * on the wire.
  5407. */
  5408. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5409. else
  5410. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5411. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5412. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5413. wqe->words[5] = 0;
  5414. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5415. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5416. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5417. wqe->generic.abort_tag = abort_tag;
  5418. /*
  5419. * The abort handler will send us CMD_ABORT_XRI_CN or
  5420. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5421. */
  5422. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5423. cmnd = CMD_ABORT_XRI_CX;
  5424. command_type = OTHER_COMMAND;
  5425. xritag = 0;
  5426. break;
  5427. case CMD_XMIT_BLS_RSP64_CX:
  5428. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5429. * we re-construct this WQE here based on information in
  5430. * iocbq from scratch.
  5431. */
  5432. memset(wqe, 0, sizeof(union lpfc_wqe));
  5433. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5434. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5435. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5436. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5437. LPFC_ABTS_UNSOL_INT) {
  5438. /* ABTS sent by initiator to CT exchange, the
  5439. * RX_ID field will be filled with the newly
  5440. * allocated responder XRI.
  5441. */
  5442. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5443. iocbq->sli4_xritag);
  5444. } else {
  5445. /* ABTS sent by responder to CT exchange, the
  5446. * RX_ID field will be filled with the responder
  5447. * RX_ID from ABTS.
  5448. */
  5449. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5450. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5451. }
  5452. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5453. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5454. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5455. iocbq->iocb.ulpContext);
  5456. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5457. command_type = OTHER_COMMAND;
  5458. break;
  5459. case CMD_XRI_ABORTED_CX:
  5460. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5461. /* words0-2 are all 0's no bde */
  5462. /* word3 and word4 are rsvrd */
  5463. wqe->words[3] = 0;
  5464. wqe->words[4] = 0;
  5465. /* word5 iocb=rsvd wge=did */
  5466. /* There is no remote port id in the IOCB? */
  5467. /* Let this fall through and fail */
  5468. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5469. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5470. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5471. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5472. default:
  5473. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5474. "2014 Invalid command 0x%x\n",
  5475. iocbq->iocb.ulpCommand);
  5476. return IOCB_ERROR;
  5477. break;
  5478. }
  5479. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5480. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5481. wqe->generic.abort_tag = abort_tag;
  5482. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5483. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5484. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5485. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5486. return 0;
  5487. }
  5488. /**
  5489. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5490. * @phba: Pointer to HBA context object.
  5491. * @ring_number: SLI ring number to issue iocb on.
  5492. * @piocb: Pointer to command iocb.
  5493. * @flag: Flag indicating if this command can be put into txq.
  5494. *
  5495. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5496. * an iocb command to an HBA with SLI-4 interface spec.
  5497. *
  5498. * This function is called with hbalock held. The function will return success
  5499. * after it successfully submit the iocb to firmware or after adding to the
  5500. * txq.
  5501. **/
  5502. static int
  5503. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5504. struct lpfc_iocbq *piocb, uint32_t flag)
  5505. {
  5506. struct lpfc_sglq *sglq;
  5507. uint16_t xritag;
  5508. union lpfc_wqe wqe;
  5509. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5510. if (piocb->sli4_xritag == NO_XRI) {
  5511. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5512. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5513. sglq = NULL;
  5514. else {
  5515. sglq = __lpfc_sli_get_sglq(phba);
  5516. if (!sglq)
  5517. return IOCB_ERROR;
  5518. piocb->sli4_xritag = sglq->sli4_xritag;
  5519. }
  5520. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5521. sglq = NULL; /* These IO's already have an XRI and
  5522. * a mapped sgl.
  5523. */
  5524. } else {
  5525. /* This is a continuation of a commandi,(CX) so this
  5526. * sglq is on the active list
  5527. */
  5528. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5529. if (!sglq)
  5530. return IOCB_ERROR;
  5531. }
  5532. if (sglq) {
  5533. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5534. if (xritag != sglq->sli4_xritag)
  5535. return IOCB_ERROR;
  5536. }
  5537. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5538. return IOCB_ERROR;
  5539. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5540. /*
  5541. * For FCP command IOCB, get a new WQ index to distribute
  5542. * WQE across the WQsr. On the other hand, for abort IOCB,
  5543. * it carries the same WQ index to the original command
  5544. * IOCB.
  5545. */
  5546. if ((piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5547. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN))
  5548. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5549. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5550. &wqe))
  5551. return IOCB_ERROR;
  5552. } else {
  5553. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5554. return IOCB_ERROR;
  5555. }
  5556. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5557. return 0;
  5558. }
  5559. /**
  5560. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5561. *
  5562. * This routine wraps the actual lockless version for issusing IOCB function
  5563. * pointer from the lpfc_hba struct.
  5564. *
  5565. * Return codes:
  5566. * IOCB_ERROR - Error
  5567. * IOCB_SUCCESS - Success
  5568. * IOCB_BUSY - Busy
  5569. **/
  5570. static inline int
  5571. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5572. struct lpfc_iocbq *piocb, uint32_t flag)
  5573. {
  5574. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5575. }
  5576. /**
  5577. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5578. * @phba: The hba struct for which this call is being executed.
  5579. * @dev_grp: The HBA PCI-Device group number.
  5580. *
  5581. * This routine sets up the SLI interface API function jump table in @phba
  5582. * struct.
  5583. * Returns: 0 - success, -ENODEV - failure.
  5584. **/
  5585. int
  5586. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5587. {
  5588. switch (dev_grp) {
  5589. case LPFC_PCI_DEV_LP:
  5590. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5591. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5592. break;
  5593. case LPFC_PCI_DEV_OC:
  5594. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5595. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5596. break;
  5597. default:
  5598. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5599. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5600. dev_grp);
  5601. return -ENODEV;
  5602. break;
  5603. }
  5604. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5605. return 0;
  5606. }
  5607. /**
  5608. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5609. * @phba: Pointer to HBA context object.
  5610. * @pring: Pointer to driver SLI ring object.
  5611. * @piocb: Pointer to command iocb.
  5612. * @flag: Flag indicating if this command can be put into txq.
  5613. *
  5614. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5615. * function. This function gets the hbalock and calls
  5616. * __lpfc_sli_issue_iocb function and will return the error returned
  5617. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5618. * functions which do not hold hbalock.
  5619. **/
  5620. int
  5621. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5622. struct lpfc_iocbq *piocb, uint32_t flag)
  5623. {
  5624. unsigned long iflags;
  5625. int rc;
  5626. spin_lock_irqsave(&phba->hbalock, iflags);
  5627. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5628. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5629. return rc;
  5630. }
  5631. /**
  5632. * lpfc_extra_ring_setup - Extra ring setup function
  5633. * @phba: Pointer to HBA context object.
  5634. *
  5635. * This function is called while driver attaches with the
  5636. * HBA to setup the extra ring. The extra ring is used
  5637. * only when driver needs to support target mode functionality
  5638. * or IP over FC functionalities.
  5639. *
  5640. * This function is called with no lock held.
  5641. **/
  5642. static int
  5643. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5644. {
  5645. struct lpfc_sli *psli;
  5646. struct lpfc_sli_ring *pring;
  5647. psli = &phba->sli;
  5648. /* Adjust cmd/rsp ring iocb entries more evenly */
  5649. /* Take some away from the FCP ring */
  5650. pring = &psli->ring[psli->fcp_ring];
  5651. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5652. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5653. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5654. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5655. /* and give them to the extra ring */
  5656. pring = &psli->ring[psli->extra_ring];
  5657. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5658. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5659. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5660. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5661. /* Setup default profile for this ring */
  5662. pring->iotag_max = 4096;
  5663. pring->num_mask = 1;
  5664. pring->prt[0].profile = 0; /* Mask 0 */
  5665. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5666. pring->prt[0].type = phba->cfg_multi_ring_type;
  5667. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5668. return 0;
  5669. }
  5670. /**
  5671. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5672. * @phba: Pointer to HBA context object.
  5673. * @pring: Pointer to driver SLI ring object.
  5674. * @iocbq: Pointer to iocb object.
  5675. *
  5676. * This function is called by the slow ring event handler
  5677. * function when there is an ASYNC event iocb in the ring.
  5678. * This function is called with no lock held.
  5679. * Currently this function handles only temperature related
  5680. * ASYNC events. The function decodes the temperature sensor
  5681. * event message and posts events for the management applications.
  5682. **/
  5683. static void
  5684. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5685. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5686. {
  5687. IOCB_t *icmd;
  5688. uint16_t evt_code;
  5689. uint16_t temp;
  5690. struct temp_event temp_event_data;
  5691. struct Scsi_Host *shost;
  5692. uint32_t *iocb_w;
  5693. icmd = &iocbq->iocb;
  5694. evt_code = icmd->un.asyncstat.evt_code;
  5695. temp = icmd->ulpContext;
  5696. if ((evt_code != ASYNC_TEMP_WARN) &&
  5697. (evt_code != ASYNC_TEMP_SAFE)) {
  5698. iocb_w = (uint32_t *) icmd;
  5699. lpfc_printf_log(phba,
  5700. KERN_ERR,
  5701. LOG_SLI,
  5702. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5703. " evt_code 0x%x\n"
  5704. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5705. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5706. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5707. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5708. pring->ringno,
  5709. icmd->un.asyncstat.evt_code,
  5710. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5711. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5712. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5713. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5714. return;
  5715. }
  5716. temp_event_data.data = (uint32_t)temp;
  5717. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5718. if (evt_code == ASYNC_TEMP_WARN) {
  5719. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5720. lpfc_printf_log(phba,
  5721. KERN_ERR,
  5722. LOG_TEMP,
  5723. "0347 Adapter is very hot, please take "
  5724. "corrective action. temperature : %d Celsius\n",
  5725. temp);
  5726. }
  5727. if (evt_code == ASYNC_TEMP_SAFE) {
  5728. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5729. lpfc_printf_log(phba,
  5730. KERN_ERR,
  5731. LOG_TEMP,
  5732. "0340 Adapter temperature is OK now. "
  5733. "temperature : %d Celsius\n",
  5734. temp);
  5735. }
  5736. /* Send temperature change event to applications */
  5737. shost = lpfc_shost_from_vport(phba->pport);
  5738. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5739. sizeof(temp_event_data), (char *) &temp_event_data,
  5740. LPFC_NL_VENDOR_ID);
  5741. }
  5742. /**
  5743. * lpfc_sli_setup - SLI ring setup function
  5744. * @phba: Pointer to HBA context object.
  5745. *
  5746. * lpfc_sli_setup sets up rings of the SLI interface with
  5747. * number of iocbs per ring and iotags. This function is
  5748. * called while driver attach to the HBA and before the
  5749. * interrupts are enabled. So there is no need for locking.
  5750. *
  5751. * This function always returns 0.
  5752. **/
  5753. int
  5754. lpfc_sli_setup(struct lpfc_hba *phba)
  5755. {
  5756. int i, totiocbsize = 0;
  5757. struct lpfc_sli *psli = &phba->sli;
  5758. struct lpfc_sli_ring *pring;
  5759. psli->num_rings = MAX_CONFIGURED_RINGS;
  5760. psli->sli_flag = 0;
  5761. psli->fcp_ring = LPFC_FCP_RING;
  5762. psli->next_ring = LPFC_FCP_NEXT_RING;
  5763. psli->extra_ring = LPFC_EXTRA_RING;
  5764. psli->iocbq_lookup = NULL;
  5765. psli->iocbq_lookup_len = 0;
  5766. psli->last_iotag = 0;
  5767. for (i = 0; i < psli->num_rings; i++) {
  5768. pring = &psli->ring[i];
  5769. switch (i) {
  5770. case LPFC_FCP_RING: /* ring 0 - FCP */
  5771. /* numCiocb and numRiocb are used in config_port */
  5772. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5773. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5774. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5775. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5776. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5777. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5778. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5779. SLI3_IOCB_CMD_SIZE :
  5780. SLI2_IOCB_CMD_SIZE;
  5781. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5782. SLI3_IOCB_RSP_SIZE :
  5783. SLI2_IOCB_RSP_SIZE;
  5784. pring->iotag_ctr = 0;
  5785. pring->iotag_max =
  5786. (phba->cfg_hba_queue_depth * 2);
  5787. pring->fast_iotag = pring->iotag_max;
  5788. pring->num_mask = 0;
  5789. break;
  5790. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5791. /* numCiocb and numRiocb are used in config_port */
  5792. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5793. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5794. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5795. SLI3_IOCB_CMD_SIZE :
  5796. SLI2_IOCB_CMD_SIZE;
  5797. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5798. SLI3_IOCB_RSP_SIZE :
  5799. SLI2_IOCB_RSP_SIZE;
  5800. pring->iotag_max = phba->cfg_hba_queue_depth;
  5801. pring->num_mask = 0;
  5802. break;
  5803. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5804. /* numCiocb and numRiocb are used in config_port */
  5805. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5806. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5807. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5808. SLI3_IOCB_CMD_SIZE :
  5809. SLI2_IOCB_CMD_SIZE;
  5810. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5811. SLI3_IOCB_RSP_SIZE :
  5812. SLI2_IOCB_RSP_SIZE;
  5813. pring->fast_iotag = 0;
  5814. pring->iotag_ctr = 0;
  5815. pring->iotag_max = 4096;
  5816. pring->lpfc_sli_rcv_async_status =
  5817. lpfc_sli_async_event_handler;
  5818. pring->num_mask = LPFC_MAX_RING_MASK;
  5819. pring->prt[0].profile = 0; /* Mask 0 */
  5820. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  5821. pring->prt[0].type = FC_TYPE_ELS;
  5822. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5823. lpfc_els_unsol_event;
  5824. pring->prt[1].profile = 0; /* Mask 1 */
  5825. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  5826. pring->prt[1].type = FC_TYPE_ELS;
  5827. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5828. lpfc_els_unsol_event;
  5829. pring->prt[2].profile = 0; /* Mask 2 */
  5830. /* NameServer Inquiry */
  5831. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  5832. /* NameServer */
  5833. pring->prt[2].type = FC_TYPE_CT;
  5834. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5835. lpfc_ct_unsol_event;
  5836. pring->prt[3].profile = 0; /* Mask 3 */
  5837. /* NameServer response */
  5838. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  5839. /* NameServer */
  5840. pring->prt[3].type = FC_TYPE_CT;
  5841. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5842. lpfc_ct_unsol_event;
  5843. /* abort unsolicited sequence */
  5844. pring->prt[4].profile = 0; /* Mask 4 */
  5845. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  5846. pring->prt[4].type = FC_TYPE_BLS;
  5847. pring->prt[4].lpfc_sli_rcv_unsol_event =
  5848. lpfc_sli4_ct_abort_unsol_event;
  5849. break;
  5850. }
  5851. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5852. (pring->numRiocb * pring->sizeRiocb);
  5853. }
  5854. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5855. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5856. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5857. "SLI2 SLIM Data: x%x x%lx\n",
  5858. phba->brd_no, totiocbsize,
  5859. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5860. }
  5861. if (phba->cfg_multi_ring_support == 2)
  5862. lpfc_extra_ring_setup(phba);
  5863. return 0;
  5864. }
  5865. /**
  5866. * lpfc_sli_queue_setup - Queue initialization function
  5867. * @phba: Pointer to HBA context object.
  5868. *
  5869. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5870. * ring. This function also initializes ring indices of each ring.
  5871. * This function is called during the initialization of the SLI
  5872. * interface of an HBA.
  5873. * This function is called with no lock held and always returns
  5874. * 1.
  5875. **/
  5876. int
  5877. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5878. {
  5879. struct lpfc_sli *psli;
  5880. struct lpfc_sli_ring *pring;
  5881. int i;
  5882. psli = &phba->sli;
  5883. spin_lock_irq(&phba->hbalock);
  5884. INIT_LIST_HEAD(&psli->mboxq);
  5885. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5886. /* Initialize list headers for txq and txcmplq as double linked lists */
  5887. for (i = 0; i < psli->num_rings; i++) {
  5888. pring = &psli->ring[i];
  5889. pring->ringno = i;
  5890. pring->next_cmdidx = 0;
  5891. pring->local_getidx = 0;
  5892. pring->cmdidx = 0;
  5893. INIT_LIST_HEAD(&pring->txq);
  5894. INIT_LIST_HEAD(&pring->txcmplq);
  5895. INIT_LIST_HEAD(&pring->iocb_continueq);
  5896. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5897. INIT_LIST_HEAD(&pring->postbufq);
  5898. }
  5899. spin_unlock_irq(&phba->hbalock);
  5900. return 1;
  5901. }
  5902. /**
  5903. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5904. * @phba: Pointer to HBA context object.
  5905. *
  5906. * This routine flushes the mailbox command subsystem. It will unconditionally
  5907. * flush all the mailbox commands in the three possible stages in the mailbox
  5908. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5909. * command; and completed mailbox command queue. It is caller's responsibility
  5910. * to make sure that the driver is in the proper state to flush the mailbox
  5911. * command sub-system. Namely, the posting of mailbox commands into the
  5912. * pending mailbox command queue from the various clients must be stopped;
  5913. * either the HBA is in a state that it will never works on the outstanding
  5914. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5915. * mailbox command has been completed.
  5916. **/
  5917. static void
  5918. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5919. {
  5920. LIST_HEAD(completions);
  5921. struct lpfc_sli *psli = &phba->sli;
  5922. LPFC_MBOXQ_t *pmb;
  5923. unsigned long iflag;
  5924. /* Flush all the mailbox commands in the mbox system */
  5925. spin_lock_irqsave(&phba->hbalock, iflag);
  5926. /* The pending mailbox command queue */
  5927. list_splice_init(&phba->sli.mboxq, &completions);
  5928. /* The outstanding active mailbox command */
  5929. if (psli->mbox_active) {
  5930. list_add_tail(&psli->mbox_active->list, &completions);
  5931. psli->mbox_active = NULL;
  5932. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5933. }
  5934. /* The completed mailbox command queue */
  5935. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5936. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5937. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5938. while (!list_empty(&completions)) {
  5939. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5940. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5941. if (pmb->mbox_cmpl)
  5942. pmb->mbox_cmpl(phba, pmb);
  5943. }
  5944. }
  5945. /**
  5946. * lpfc_sli_host_down - Vport cleanup function
  5947. * @vport: Pointer to virtual port object.
  5948. *
  5949. * lpfc_sli_host_down is called to clean up the resources
  5950. * associated with a vport before destroying virtual
  5951. * port data structures.
  5952. * This function does following operations:
  5953. * - Free discovery resources associated with this virtual
  5954. * port.
  5955. * - Free iocbs associated with this virtual port in
  5956. * the txq.
  5957. * - Send abort for all iocb commands associated with this
  5958. * vport in txcmplq.
  5959. *
  5960. * This function is called with no lock held and always returns 1.
  5961. **/
  5962. int
  5963. lpfc_sli_host_down(struct lpfc_vport *vport)
  5964. {
  5965. LIST_HEAD(completions);
  5966. struct lpfc_hba *phba = vport->phba;
  5967. struct lpfc_sli *psli = &phba->sli;
  5968. struct lpfc_sli_ring *pring;
  5969. struct lpfc_iocbq *iocb, *next_iocb;
  5970. int i;
  5971. unsigned long flags = 0;
  5972. uint16_t prev_pring_flag;
  5973. lpfc_cleanup_discovery_resources(vport);
  5974. spin_lock_irqsave(&phba->hbalock, flags);
  5975. for (i = 0; i < psli->num_rings; i++) {
  5976. pring = &psli->ring[i];
  5977. prev_pring_flag = pring->flag;
  5978. /* Only slow rings */
  5979. if (pring->ringno == LPFC_ELS_RING) {
  5980. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5981. /* Set the lpfc data pending flag */
  5982. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5983. }
  5984. /*
  5985. * Error everything on the txq since these iocbs have not been
  5986. * given to the FW yet.
  5987. */
  5988. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  5989. if (iocb->vport != vport)
  5990. continue;
  5991. list_move_tail(&iocb->list, &completions);
  5992. pring->txq_cnt--;
  5993. }
  5994. /* Next issue ABTS for everything on the txcmplq */
  5995. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  5996. list) {
  5997. if (iocb->vport != vport)
  5998. continue;
  5999. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6000. }
  6001. pring->flag = prev_pring_flag;
  6002. }
  6003. spin_unlock_irqrestore(&phba->hbalock, flags);
  6004. /* Cancel all the IOCBs from the completions list */
  6005. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6006. IOERR_SLI_DOWN);
  6007. return 1;
  6008. }
  6009. /**
  6010. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6011. * @phba: Pointer to HBA context object.
  6012. *
  6013. * This function cleans up all iocb, buffers, mailbox commands
  6014. * while shutting down the HBA. This function is called with no
  6015. * lock held and always returns 1.
  6016. * This function does the following to cleanup driver resources:
  6017. * - Free discovery resources for each virtual port
  6018. * - Cleanup any pending fabric iocbs
  6019. * - Iterate through the iocb txq and free each entry
  6020. * in the list.
  6021. * - Free up any buffer posted to the HBA
  6022. * - Free mailbox commands in the mailbox queue.
  6023. **/
  6024. int
  6025. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6026. {
  6027. LIST_HEAD(completions);
  6028. struct lpfc_sli *psli = &phba->sli;
  6029. struct lpfc_sli_ring *pring;
  6030. struct lpfc_dmabuf *buf_ptr;
  6031. unsigned long flags = 0;
  6032. int i;
  6033. /* Shutdown the mailbox command sub-system */
  6034. lpfc_sli_mbox_sys_shutdown(phba);
  6035. lpfc_hba_down_prep(phba);
  6036. lpfc_fabric_abort_hba(phba);
  6037. spin_lock_irqsave(&phba->hbalock, flags);
  6038. for (i = 0; i < psli->num_rings; i++) {
  6039. pring = &psli->ring[i];
  6040. /* Only slow rings */
  6041. if (pring->ringno == LPFC_ELS_RING) {
  6042. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6043. /* Set the lpfc data pending flag */
  6044. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6045. }
  6046. /*
  6047. * Error everything on the txq since these iocbs have not been
  6048. * given to the FW yet.
  6049. */
  6050. list_splice_init(&pring->txq, &completions);
  6051. pring->txq_cnt = 0;
  6052. }
  6053. spin_unlock_irqrestore(&phba->hbalock, flags);
  6054. /* Cancel all the IOCBs from the completions list */
  6055. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6056. IOERR_SLI_DOWN);
  6057. spin_lock_irqsave(&phba->hbalock, flags);
  6058. list_splice_init(&phba->elsbuf, &completions);
  6059. phba->elsbuf_cnt = 0;
  6060. phba->elsbuf_prev_cnt = 0;
  6061. spin_unlock_irqrestore(&phba->hbalock, flags);
  6062. while (!list_empty(&completions)) {
  6063. list_remove_head(&completions, buf_ptr,
  6064. struct lpfc_dmabuf, list);
  6065. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6066. kfree(buf_ptr);
  6067. }
  6068. /* Return any active mbox cmds */
  6069. del_timer_sync(&psli->mbox_tmo);
  6070. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6071. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6072. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6073. return 1;
  6074. }
  6075. /**
  6076. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6077. * @phba: Pointer to HBA context object.
  6078. *
  6079. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6080. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6081. * lock held and always returns 1.
  6082. *
  6083. * This function does the following to cleanup driver FCoE function resources:
  6084. * - Free discovery resources for each virtual port
  6085. * - Cleanup any pending fabric iocbs
  6086. * - Iterate through the iocb txq and free each entry in the list.
  6087. * - Free up any buffer posted to the HBA.
  6088. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6089. * - Free mailbox commands in the mailbox queue.
  6090. **/
  6091. int
  6092. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6093. {
  6094. /* Stop the SLI4 device port */
  6095. lpfc_stop_port(phba);
  6096. /* Tear down the queues in the HBA */
  6097. lpfc_sli4_queue_unset(phba);
  6098. /* unregister default FCFI from the HBA */
  6099. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6100. return 1;
  6101. }
  6102. /**
  6103. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6104. * @srcp: Source memory pointer.
  6105. * @destp: Destination memory pointer.
  6106. * @cnt: Number of words required to be copied.
  6107. *
  6108. * This function is used for copying data between driver memory
  6109. * and the SLI memory. This function also changes the endianness
  6110. * of each word if native endianness is different from SLI
  6111. * endianness. This function can be called with or without
  6112. * lock.
  6113. **/
  6114. void
  6115. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6116. {
  6117. uint32_t *src = srcp;
  6118. uint32_t *dest = destp;
  6119. uint32_t ldata;
  6120. int i;
  6121. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6122. ldata = *src;
  6123. ldata = le32_to_cpu(ldata);
  6124. *dest = ldata;
  6125. src++;
  6126. dest++;
  6127. }
  6128. }
  6129. /**
  6130. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6131. * @srcp: Source memory pointer.
  6132. * @destp: Destination memory pointer.
  6133. * @cnt: Number of words required to be copied.
  6134. *
  6135. * This function is used for copying data between a data structure
  6136. * with big endian representation to local endianness.
  6137. * This function can be called with or without lock.
  6138. **/
  6139. void
  6140. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6141. {
  6142. uint32_t *src = srcp;
  6143. uint32_t *dest = destp;
  6144. uint32_t ldata;
  6145. int i;
  6146. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6147. ldata = *src;
  6148. ldata = be32_to_cpu(ldata);
  6149. *dest = ldata;
  6150. src++;
  6151. dest++;
  6152. }
  6153. }
  6154. /**
  6155. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6156. * @phba: Pointer to HBA context object.
  6157. * @pring: Pointer to driver SLI ring object.
  6158. * @mp: Pointer to driver buffer object.
  6159. *
  6160. * This function is called with no lock held.
  6161. * It always return zero after adding the buffer to the postbufq
  6162. * buffer list.
  6163. **/
  6164. int
  6165. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6166. struct lpfc_dmabuf *mp)
  6167. {
  6168. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6169. later */
  6170. spin_lock_irq(&phba->hbalock);
  6171. list_add_tail(&mp->list, &pring->postbufq);
  6172. pring->postbufq_cnt++;
  6173. spin_unlock_irq(&phba->hbalock);
  6174. return 0;
  6175. }
  6176. /**
  6177. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6178. * @phba: Pointer to HBA context object.
  6179. *
  6180. * When HBQ is enabled, buffers are searched based on tags. This function
  6181. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6182. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6183. * does not conflict with tags of buffer posted for unsolicited events.
  6184. * The function returns the allocated tag. The function is called with
  6185. * no locks held.
  6186. **/
  6187. uint32_t
  6188. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6189. {
  6190. spin_lock_irq(&phba->hbalock);
  6191. phba->buffer_tag_count++;
  6192. /*
  6193. * Always set the QUE_BUFTAG_BIT to distiguish between
  6194. * a tag assigned by HBQ.
  6195. */
  6196. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6197. spin_unlock_irq(&phba->hbalock);
  6198. return phba->buffer_tag_count;
  6199. }
  6200. /**
  6201. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6202. * @phba: Pointer to HBA context object.
  6203. * @pring: Pointer to driver SLI ring object.
  6204. * @tag: Buffer tag.
  6205. *
  6206. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6207. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6208. * iocb is posted to the response ring with the tag of the buffer.
  6209. * This function searches the pring->postbufq list using the tag
  6210. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6211. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6212. * buffer is returned to the caller else NULL is returned.
  6213. * This function is called with no lock held.
  6214. **/
  6215. struct lpfc_dmabuf *
  6216. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6217. uint32_t tag)
  6218. {
  6219. struct lpfc_dmabuf *mp, *next_mp;
  6220. struct list_head *slp = &pring->postbufq;
  6221. /* Search postbufq, from the begining, looking for a match on tag */
  6222. spin_lock_irq(&phba->hbalock);
  6223. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6224. if (mp->buffer_tag == tag) {
  6225. list_del_init(&mp->list);
  6226. pring->postbufq_cnt--;
  6227. spin_unlock_irq(&phba->hbalock);
  6228. return mp;
  6229. }
  6230. }
  6231. spin_unlock_irq(&phba->hbalock);
  6232. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6233. "0402 Cannot find virtual addr for buffer tag on "
  6234. "ring %d Data x%lx x%p x%p x%x\n",
  6235. pring->ringno, (unsigned long) tag,
  6236. slp->next, slp->prev, pring->postbufq_cnt);
  6237. return NULL;
  6238. }
  6239. /**
  6240. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6241. * @phba: Pointer to HBA context object.
  6242. * @pring: Pointer to driver SLI ring object.
  6243. * @phys: DMA address of the buffer.
  6244. *
  6245. * This function searches the buffer list using the dma_address
  6246. * of unsolicited event to find the driver's lpfc_dmabuf object
  6247. * corresponding to the dma_address. The function returns the
  6248. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6249. * This function is called by the ct and els unsolicited event
  6250. * handlers to get the buffer associated with the unsolicited
  6251. * event.
  6252. *
  6253. * This function is called with no lock held.
  6254. **/
  6255. struct lpfc_dmabuf *
  6256. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6257. dma_addr_t phys)
  6258. {
  6259. struct lpfc_dmabuf *mp, *next_mp;
  6260. struct list_head *slp = &pring->postbufq;
  6261. /* Search postbufq, from the begining, looking for a match on phys */
  6262. spin_lock_irq(&phba->hbalock);
  6263. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6264. if (mp->phys == phys) {
  6265. list_del_init(&mp->list);
  6266. pring->postbufq_cnt--;
  6267. spin_unlock_irq(&phba->hbalock);
  6268. return mp;
  6269. }
  6270. }
  6271. spin_unlock_irq(&phba->hbalock);
  6272. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6273. "0410 Cannot find virtual addr for mapped buf on "
  6274. "ring %d Data x%llx x%p x%p x%x\n",
  6275. pring->ringno, (unsigned long long)phys,
  6276. slp->next, slp->prev, pring->postbufq_cnt);
  6277. return NULL;
  6278. }
  6279. /**
  6280. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6281. * @phba: Pointer to HBA context object.
  6282. * @cmdiocb: Pointer to driver command iocb object.
  6283. * @rspiocb: Pointer to driver response iocb object.
  6284. *
  6285. * This function is the completion handler for the abort iocbs for
  6286. * ELS commands. This function is called from the ELS ring event
  6287. * handler with no lock held. This function frees memory resources
  6288. * associated with the abort iocb.
  6289. **/
  6290. static void
  6291. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6292. struct lpfc_iocbq *rspiocb)
  6293. {
  6294. IOCB_t *irsp = &rspiocb->iocb;
  6295. uint16_t abort_iotag, abort_context;
  6296. struct lpfc_iocbq *abort_iocb;
  6297. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6298. abort_iocb = NULL;
  6299. if (irsp->ulpStatus) {
  6300. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6301. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6302. spin_lock_irq(&phba->hbalock);
  6303. if (phba->sli_rev < LPFC_SLI_REV4) {
  6304. if (abort_iotag != 0 &&
  6305. abort_iotag <= phba->sli.last_iotag)
  6306. abort_iocb =
  6307. phba->sli.iocbq_lookup[abort_iotag];
  6308. } else
  6309. /* For sli4 the abort_tag is the XRI,
  6310. * so the abort routine puts the iotag of the iocb
  6311. * being aborted in the context field of the abort
  6312. * IOCB.
  6313. */
  6314. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6315. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6316. "0327 Cannot abort els iocb %p "
  6317. "with tag %x context %x, abort status %x, "
  6318. "abort code %x\n",
  6319. abort_iocb, abort_iotag, abort_context,
  6320. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6321. /*
  6322. * If the iocb is not found in Firmware queue the iocb
  6323. * might have completed already. Do not free it again.
  6324. */
  6325. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6326. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6327. spin_unlock_irq(&phba->hbalock);
  6328. lpfc_sli_release_iocbq(phba, cmdiocb);
  6329. return;
  6330. }
  6331. /* For SLI4 the ulpContext field for abort IOCB
  6332. * holds the iotag of the IOCB being aborted so
  6333. * the local abort_context needs to be reset to
  6334. * match the aborted IOCBs ulpContext.
  6335. */
  6336. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6337. abort_context = abort_iocb->iocb.ulpContext;
  6338. }
  6339. /*
  6340. * make sure we have the right iocbq before taking it
  6341. * off the txcmplq and try to call completion routine.
  6342. */
  6343. if (!abort_iocb ||
  6344. abort_iocb->iocb.ulpContext != abort_context ||
  6345. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6346. spin_unlock_irq(&phba->hbalock);
  6347. else {
  6348. list_del_init(&abort_iocb->list);
  6349. pring->txcmplq_cnt--;
  6350. spin_unlock_irq(&phba->hbalock);
  6351. /* Firmware could still be in progress of DMAing
  6352. * payload, so don't free data buffer till after
  6353. * a hbeat.
  6354. */
  6355. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6356. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6357. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6358. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6359. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6360. }
  6361. }
  6362. lpfc_sli_release_iocbq(phba, cmdiocb);
  6363. return;
  6364. }
  6365. /**
  6366. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6367. * @phba: Pointer to HBA context object.
  6368. * @cmdiocb: Pointer to driver command iocb object.
  6369. * @rspiocb: Pointer to driver response iocb object.
  6370. *
  6371. * The function is called from SLI ring event handler with no
  6372. * lock held. This function is the completion handler for ELS commands
  6373. * which are aborted. The function frees memory resources used for
  6374. * the aborted ELS commands.
  6375. **/
  6376. static void
  6377. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6378. struct lpfc_iocbq *rspiocb)
  6379. {
  6380. IOCB_t *irsp = &rspiocb->iocb;
  6381. /* ELS cmd tag <ulpIoTag> completes */
  6382. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6383. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6384. "x%x x%x x%x\n",
  6385. irsp->ulpIoTag, irsp->ulpStatus,
  6386. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6387. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6388. lpfc_ct_free_iocb(phba, cmdiocb);
  6389. else
  6390. lpfc_els_free_iocb(phba, cmdiocb);
  6391. return;
  6392. }
  6393. /**
  6394. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6395. * @phba: Pointer to HBA context object.
  6396. * @pring: Pointer to driver SLI ring object.
  6397. * @cmdiocb: Pointer to driver command iocb object.
  6398. *
  6399. * This function issues an abort iocb for the provided command
  6400. * iocb. This function is called with hbalock held.
  6401. * The function returns 0 when it fails due to memory allocation
  6402. * failure or when the command iocb is an abort request.
  6403. **/
  6404. int
  6405. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6406. struct lpfc_iocbq *cmdiocb)
  6407. {
  6408. struct lpfc_vport *vport = cmdiocb->vport;
  6409. struct lpfc_iocbq *abtsiocbp;
  6410. IOCB_t *icmd = NULL;
  6411. IOCB_t *iabt = NULL;
  6412. int retval = IOCB_ERROR;
  6413. /*
  6414. * There are certain command types we don't want to abort. And we
  6415. * don't want to abort commands that are already in the process of
  6416. * being aborted.
  6417. */
  6418. icmd = &cmdiocb->iocb;
  6419. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6420. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6421. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6422. return 0;
  6423. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6424. * callback so that nothing happens when it finishes.
  6425. */
  6426. if ((vport->load_flag & FC_UNLOADING) &&
  6427. (pring->ringno == LPFC_ELS_RING)) {
  6428. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6429. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6430. else
  6431. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6432. goto abort_iotag_exit;
  6433. }
  6434. /* issue ABTS for this IOCB based on iotag */
  6435. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6436. if (abtsiocbp == NULL)
  6437. return 0;
  6438. /* This signals the response to set the correct status
  6439. * before calling the completion handler.
  6440. */
  6441. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6442. iabt = &abtsiocbp->iocb;
  6443. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6444. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6445. if (phba->sli_rev == LPFC_SLI_REV4) {
  6446. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6447. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6448. }
  6449. else
  6450. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6451. iabt->ulpLe = 1;
  6452. iabt->ulpClass = icmd->ulpClass;
  6453. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6454. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6455. if (phba->link_state >= LPFC_LINK_UP)
  6456. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6457. else
  6458. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6459. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6460. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6461. "0339 Abort xri x%x, original iotag x%x, "
  6462. "abort cmd iotag x%x\n",
  6463. iabt->un.acxri.abortContextTag,
  6464. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6465. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6466. if (retval)
  6467. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6468. abort_iotag_exit:
  6469. /*
  6470. * Caller to this routine should check for IOCB_ERROR
  6471. * and handle it properly. This routine no longer removes
  6472. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6473. */
  6474. return retval;
  6475. }
  6476. /**
  6477. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6478. * @iocbq: Pointer to driver iocb object.
  6479. * @vport: Pointer to driver virtual port object.
  6480. * @tgt_id: SCSI ID of the target.
  6481. * @lun_id: LUN ID of the scsi device.
  6482. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6483. *
  6484. * This function acts as an iocb filter for functions which abort or count
  6485. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6486. * 0 if the filtering criteria is met for the given iocb and will return
  6487. * 1 if the filtering criteria is not met.
  6488. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6489. * given iocb is for the SCSI device specified by vport, tgt_id and
  6490. * lun_id parameter.
  6491. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6492. * given iocb is for the SCSI target specified by vport and tgt_id
  6493. * parameters.
  6494. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6495. * given iocb is for the SCSI host associated with the given vport.
  6496. * This function is called with no locks held.
  6497. **/
  6498. static int
  6499. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6500. uint16_t tgt_id, uint64_t lun_id,
  6501. lpfc_ctx_cmd ctx_cmd)
  6502. {
  6503. struct lpfc_scsi_buf *lpfc_cmd;
  6504. int rc = 1;
  6505. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6506. return rc;
  6507. if (iocbq->vport != vport)
  6508. return rc;
  6509. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6510. if (lpfc_cmd->pCmd == NULL)
  6511. return rc;
  6512. switch (ctx_cmd) {
  6513. case LPFC_CTX_LUN:
  6514. if ((lpfc_cmd->rdata->pnode) &&
  6515. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6516. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6517. rc = 0;
  6518. break;
  6519. case LPFC_CTX_TGT:
  6520. if ((lpfc_cmd->rdata->pnode) &&
  6521. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6522. rc = 0;
  6523. break;
  6524. case LPFC_CTX_HOST:
  6525. rc = 0;
  6526. break;
  6527. default:
  6528. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6529. __func__, ctx_cmd);
  6530. break;
  6531. }
  6532. return rc;
  6533. }
  6534. /**
  6535. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6536. * @vport: Pointer to virtual port.
  6537. * @tgt_id: SCSI ID of the target.
  6538. * @lun_id: LUN ID of the scsi device.
  6539. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6540. *
  6541. * This function returns number of FCP commands pending for the vport.
  6542. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6543. * commands pending on the vport associated with SCSI device specified
  6544. * by tgt_id and lun_id parameters.
  6545. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6546. * commands pending on the vport associated with SCSI target specified
  6547. * by tgt_id parameter.
  6548. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6549. * commands pending on the vport.
  6550. * This function returns the number of iocbs which satisfy the filter.
  6551. * This function is called without any lock held.
  6552. **/
  6553. int
  6554. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6555. lpfc_ctx_cmd ctx_cmd)
  6556. {
  6557. struct lpfc_hba *phba = vport->phba;
  6558. struct lpfc_iocbq *iocbq;
  6559. int sum, i;
  6560. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6561. iocbq = phba->sli.iocbq_lookup[i];
  6562. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6563. ctx_cmd) == 0)
  6564. sum++;
  6565. }
  6566. return sum;
  6567. }
  6568. /**
  6569. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6570. * @phba: Pointer to HBA context object
  6571. * @cmdiocb: Pointer to command iocb object.
  6572. * @rspiocb: Pointer to response iocb object.
  6573. *
  6574. * This function is called when an aborted FCP iocb completes. This
  6575. * function is called by the ring event handler with no lock held.
  6576. * This function frees the iocb.
  6577. **/
  6578. void
  6579. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6580. struct lpfc_iocbq *rspiocb)
  6581. {
  6582. lpfc_sli_release_iocbq(phba, cmdiocb);
  6583. return;
  6584. }
  6585. /**
  6586. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6587. * @vport: Pointer to virtual port.
  6588. * @pring: Pointer to driver SLI ring object.
  6589. * @tgt_id: SCSI ID of the target.
  6590. * @lun_id: LUN ID of the scsi device.
  6591. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6592. *
  6593. * This function sends an abort command for every SCSI command
  6594. * associated with the given virtual port pending on the ring
  6595. * filtered by lpfc_sli_validate_fcp_iocb function.
  6596. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6597. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6598. * parameters
  6599. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6600. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6601. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6602. * FCP iocbs associated with virtual port.
  6603. * This function returns number of iocbs it failed to abort.
  6604. * This function is called with no locks held.
  6605. **/
  6606. int
  6607. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6608. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6609. {
  6610. struct lpfc_hba *phba = vport->phba;
  6611. struct lpfc_iocbq *iocbq;
  6612. struct lpfc_iocbq *abtsiocb;
  6613. IOCB_t *cmd = NULL;
  6614. int errcnt = 0, ret_val = 0;
  6615. int i;
  6616. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6617. iocbq = phba->sli.iocbq_lookup[i];
  6618. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6619. abort_cmd) != 0)
  6620. continue;
  6621. /* issue ABTS for this IOCB based on iotag */
  6622. abtsiocb = lpfc_sli_get_iocbq(phba);
  6623. if (abtsiocb == NULL) {
  6624. errcnt++;
  6625. continue;
  6626. }
  6627. cmd = &iocbq->iocb;
  6628. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6629. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6630. if (phba->sli_rev == LPFC_SLI_REV4)
  6631. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6632. else
  6633. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6634. abtsiocb->iocb.ulpLe = 1;
  6635. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6636. abtsiocb->vport = phba->pport;
  6637. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6638. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6639. if (lpfc_is_link_up(phba))
  6640. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6641. else
  6642. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6643. /* Setup callback routine and issue the command. */
  6644. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6645. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6646. abtsiocb, 0);
  6647. if (ret_val == IOCB_ERROR) {
  6648. lpfc_sli_release_iocbq(phba, abtsiocb);
  6649. errcnt++;
  6650. continue;
  6651. }
  6652. }
  6653. return errcnt;
  6654. }
  6655. /**
  6656. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6657. * @phba: Pointer to HBA context object.
  6658. * @cmdiocbq: Pointer to command iocb.
  6659. * @rspiocbq: Pointer to response iocb.
  6660. *
  6661. * This function is the completion handler for iocbs issued using
  6662. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6663. * ring event handler function without any lock held. This function
  6664. * can be called from both worker thread context and interrupt
  6665. * context. This function also can be called from other thread which
  6666. * cleans up the SLI layer objects.
  6667. * This function copy the contents of the response iocb to the
  6668. * response iocb memory object provided by the caller of
  6669. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6670. * sleeps for the iocb completion.
  6671. **/
  6672. static void
  6673. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6674. struct lpfc_iocbq *cmdiocbq,
  6675. struct lpfc_iocbq *rspiocbq)
  6676. {
  6677. wait_queue_head_t *pdone_q;
  6678. unsigned long iflags;
  6679. spin_lock_irqsave(&phba->hbalock, iflags);
  6680. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6681. if (cmdiocbq->context2 && rspiocbq)
  6682. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6683. &rspiocbq->iocb, sizeof(IOCB_t));
  6684. pdone_q = cmdiocbq->context_un.wait_queue;
  6685. if (pdone_q)
  6686. wake_up(pdone_q);
  6687. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6688. return;
  6689. }
  6690. /**
  6691. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6692. * @phba: Pointer to HBA context object..
  6693. * @piocbq: Pointer to command iocb.
  6694. * @flag: Flag to test.
  6695. *
  6696. * This routine grabs the hbalock and then test the iocb_flag to
  6697. * see if the passed in flag is set.
  6698. * Returns:
  6699. * 1 if flag is set.
  6700. * 0 if flag is not set.
  6701. **/
  6702. static int
  6703. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6704. struct lpfc_iocbq *piocbq, uint32_t flag)
  6705. {
  6706. unsigned long iflags;
  6707. int ret;
  6708. spin_lock_irqsave(&phba->hbalock, iflags);
  6709. ret = piocbq->iocb_flag & flag;
  6710. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6711. return ret;
  6712. }
  6713. /**
  6714. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6715. * @phba: Pointer to HBA context object..
  6716. * @pring: Pointer to sli ring.
  6717. * @piocb: Pointer to command iocb.
  6718. * @prspiocbq: Pointer to response iocb.
  6719. * @timeout: Timeout in number of seconds.
  6720. *
  6721. * This function issues the iocb to firmware and waits for the
  6722. * iocb to complete. If the iocb command is not
  6723. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6724. * Caller should not free the iocb resources if this function
  6725. * returns IOCB_TIMEDOUT.
  6726. * The function waits for the iocb completion using an
  6727. * non-interruptible wait.
  6728. * This function will sleep while waiting for iocb completion.
  6729. * So, this function should not be called from any context which
  6730. * does not allow sleeping. Due to the same reason, this function
  6731. * cannot be called with interrupt disabled.
  6732. * This function assumes that the iocb completions occur while
  6733. * this function sleep. So, this function cannot be called from
  6734. * the thread which process iocb completion for this ring.
  6735. * This function clears the iocb_flag of the iocb object before
  6736. * issuing the iocb and the iocb completion handler sets this
  6737. * flag and wakes this thread when the iocb completes.
  6738. * The contents of the response iocb will be copied to prspiocbq
  6739. * by the completion handler when the command completes.
  6740. * This function returns IOCB_SUCCESS when success.
  6741. * This function is called with no lock held.
  6742. **/
  6743. int
  6744. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6745. uint32_t ring_number,
  6746. struct lpfc_iocbq *piocb,
  6747. struct lpfc_iocbq *prspiocbq,
  6748. uint32_t timeout)
  6749. {
  6750. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6751. long timeleft, timeout_req = 0;
  6752. int retval = IOCB_SUCCESS;
  6753. uint32_t creg_val;
  6754. /*
  6755. * If the caller has provided a response iocbq buffer, then context2
  6756. * is NULL or its an error.
  6757. */
  6758. if (prspiocbq) {
  6759. if (piocb->context2)
  6760. return IOCB_ERROR;
  6761. piocb->context2 = prspiocbq;
  6762. }
  6763. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6764. piocb->context_un.wait_queue = &done_q;
  6765. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6766. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6767. creg_val = readl(phba->HCregaddr);
  6768. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6769. writel(creg_val, phba->HCregaddr);
  6770. readl(phba->HCregaddr); /* flush */
  6771. }
  6772. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6773. if (retval == IOCB_SUCCESS) {
  6774. timeout_req = timeout * HZ;
  6775. timeleft = wait_event_timeout(done_q,
  6776. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6777. timeout_req);
  6778. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6779. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6780. "0331 IOCB wake signaled\n");
  6781. } else if (timeleft == 0) {
  6782. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6783. "0338 IOCB wait timeout error - no "
  6784. "wake response Data x%x\n", timeout);
  6785. retval = IOCB_TIMEDOUT;
  6786. } else {
  6787. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6788. "0330 IOCB wake NOT set, "
  6789. "Data x%x x%lx\n",
  6790. timeout, (timeleft / jiffies));
  6791. retval = IOCB_TIMEDOUT;
  6792. }
  6793. } else {
  6794. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6795. "0332 IOCB wait issue failed, Data x%x\n",
  6796. retval);
  6797. retval = IOCB_ERROR;
  6798. }
  6799. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6800. creg_val = readl(phba->HCregaddr);
  6801. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6802. writel(creg_val, phba->HCregaddr);
  6803. readl(phba->HCregaddr); /* flush */
  6804. }
  6805. if (prspiocbq)
  6806. piocb->context2 = NULL;
  6807. piocb->context_un.wait_queue = NULL;
  6808. piocb->iocb_cmpl = NULL;
  6809. return retval;
  6810. }
  6811. /**
  6812. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6813. * @phba: Pointer to HBA context object.
  6814. * @pmboxq: Pointer to driver mailbox object.
  6815. * @timeout: Timeout in number of seconds.
  6816. *
  6817. * This function issues the mailbox to firmware and waits for the
  6818. * mailbox command to complete. If the mailbox command is not
  6819. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6820. * The function waits for the mailbox completion using an
  6821. * interruptible wait. If the thread is woken up due to a
  6822. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6823. * should not free the mailbox resources, if this function returns
  6824. * MBX_TIMEOUT.
  6825. * This function will sleep while waiting for mailbox completion.
  6826. * So, this function should not be called from any context which
  6827. * does not allow sleeping. Due to the same reason, this function
  6828. * cannot be called with interrupt disabled.
  6829. * This function assumes that the mailbox completion occurs while
  6830. * this function sleep. So, this function cannot be called from
  6831. * the worker thread which processes mailbox completion.
  6832. * This function is called in the context of HBA management
  6833. * applications.
  6834. * This function returns MBX_SUCCESS when successful.
  6835. * This function is called with no lock held.
  6836. **/
  6837. int
  6838. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6839. uint32_t timeout)
  6840. {
  6841. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6842. int retval;
  6843. unsigned long flag;
  6844. /* The caller must leave context1 empty. */
  6845. if (pmboxq->context1)
  6846. return MBX_NOT_FINISHED;
  6847. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6848. /* setup wake call as IOCB callback */
  6849. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6850. /* setup context field to pass wait_queue pointer to wake function */
  6851. pmboxq->context1 = &done_q;
  6852. /* now issue the command */
  6853. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6854. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6855. wait_event_interruptible_timeout(done_q,
  6856. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6857. timeout * HZ);
  6858. spin_lock_irqsave(&phba->hbalock, flag);
  6859. pmboxq->context1 = NULL;
  6860. /*
  6861. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6862. * else do not free the resources.
  6863. */
  6864. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6865. retval = MBX_SUCCESS;
  6866. else {
  6867. retval = MBX_TIMEOUT;
  6868. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6869. }
  6870. spin_unlock_irqrestore(&phba->hbalock, flag);
  6871. }
  6872. return retval;
  6873. }
  6874. /**
  6875. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6876. * @phba: Pointer to HBA context.
  6877. *
  6878. * This function is called to shutdown the driver's mailbox sub-system.
  6879. * It first marks the mailbox sub-system is in a block state to prevent
  6880. * the asynchronous mailbox command from issued off the pending mailbox
  6881. * command queue. If the mailbox command sub-system shutdown is due to
  6882. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6883. * the mailbox sub-system flush routine to forcefully bring down the
  6884. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6885. * as with offline or HBA function reset), this routine will wait for the
  6886. * outstanding mailbox command to complete before invoking the mailbox
  6887. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6888. **/
  6889. void
  6890. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6891. {
  6892. struct lpfc_sli *psli = &phba->sli;
  6893. uint8_t actcmd = MBX_HEARTBEAT;
  6894. unsigned long timeout;
  6895. spin_lock_irq(&phba->hbalock);
  6896. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6897. spin_unlock_irq(&phba->hbalock);
  6898. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6899. spin_lock_irq(&phba->hbalock);
  6900. if (phba->sli.mbox_active)
  6901. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6902. spin_unlock_irq(&phba->hbalock);
  6903. /* Determine how long we might wait for the active mailbox
  6904. * command to be gracefully completed by firmware.
  6905. */
  6906. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6907. 1000) + jiffies;
  6908. while (phba->sli.mbox_active) {
  6909. /* Check active mailbox complete status every 2ms */
  6910. msleep(2);
  6911. if (time_after(jiffies, timeout))
  6912. /* Timeout, let the mailbox flush routine to
  6913. * forcefully release active mailbox command
  6914. */
  6915. break;
  6916. }
  6917. }
  6918. lpfc_sli_mbox_sys_flush(phba);
  6919. }
  6920. /**
  6921. * lpfc_sli_eratt_read - read sli-3 error attention events
  6922. * @phba: Pointer to HBA context.
  6923. *
  6924. * This function is called to read the SLI3 device error attention registers
  6925. * for possible error attention events. The caller must hold the hostlock
  6926. * with spin_lock_irq().
  6927. *
  6928. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6929. * Register and returns 0 otherwise.
  6930. **/
  6931. static int
  6932. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6933. {
  6934. uint32_t ha_copy;
  6935. /* Read chip Host Attention (HA) register */
  6936. ha_copy = readl(phba->HAregaddr);
  6937. if (ha_copy & HA_ERATT) {
  6938. /* Read host status register to retrieve error event */
  6939. lpfc_sli_read_hs(phba);
  6940. /* Check if there is a deferred error condition is active */
  6941. if ((HS_FFER1 & phba->work_hs) &&
  6942. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6943. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6944. phba->hba_flag |= DEFER_ERATT;
  6945. /* Clear all interrupt enable conditions */
  6946. writel(0, phba->HCregaddr);
  6947. readl(phba->HCregaddr);
  6948. }
  6949. /* Set the driver HA work bitmap */
  6950. phba->work_ha |= HA_ERATT;
  6951. /* Indicate polling handles this ERATT */
  6952. phba->hba_flag |= HBA_ERATT_HANDLED;
  6953. return 1;
  6954. }
  6955. return 0;
  6956. }
  6957. /**
  6958. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6959. * @phba: Pointer to HBA context.
  6960. *
  6961. * This function is called to read the SLI4 device error attention registers
  6962. * for possible error attention events. The caller must hold the hostlock
  6963. * with spin_lock_irq().
  6964. *
  6965. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6966. * Register and returns 0 otherwise.
  6967. **/
  6968. static int
  6969. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6970. {
  6971. uint32_t uerr_sta_hi, uerr_sta_lo;
  6972. /* For now, use the SLI4 device internal unrecoverable error
  6973. * registers for error attention. This can be changed later.
  6974. */
  6975. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6976. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6977. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  6978. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  6979. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6980. "1423 HBA Unrecoverable error: "
  6981. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6982. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  6983. uerr_sta_lo, uerr_sta_hi,
  6984. phba->sli4_hba.ue_mask_lo,
  6985. phba->sli4_hba.ue_mask_hi);
  6986. phba->work_status[0] = uerr_sta_lo;
  6987. phba->work_status[1] = uerr_sta_hi;
  6988. /* Set the driver HA work bitmap */
  6989. phba->work_ha |= HA_ERATT;
  6990. /* Indicate polling handles this ERATT */
  6991. phba->hba_flag |= HBA_ERATT_HANDLED;
  6992. return 1;
  6993. }
  6994. return 0;
  6995. }
  6996. /**
  6997. * lpfc_sli_check_eratt - check error attention events
  6998. * @phba: Pointer to HBA context.
  6999. *
  7000. * This function is called from timer soft interrupt context to check HBA's
  7001. * error attention register bit for error attention events.
  7002. *
  7003. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7004. * Register and returns 0 otherwise.
  7005. **/
  7006. int
  7007. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7008. {
  7009. uint32_t ha_copy;
  7010. /* If somebody is waiting to handle an eratt, don't process it
  7011. * here. The brdkill function will do this.
  7012. */
  7013. if (phba->link_flag & LS_IGNORE_ERATT)
  7014. return 0;
  7015. /* Check if interrupt handler handles this ERATT */
  7016. spin_lock_irq(&phba->hbalock);
  7017. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7018. /* Interrupt handler has handled ERATT */
  7019. spin_unlock_irq(&phba->hbalock);
  7020. return 0;
  7021. }
  7022. /*
  7023. * If there is deferred error attention, do not check for error
  7024. * attention
  7025. */
  7026. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7027. spin_unlock_irq(&phba->hbalock);
  7028. return 0;
  7029. }
  7030. /* If PCI channel is offline, don't process it */
  7031. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7032. spin_unlock_irq(&phba->hbalock);
  7033. return 0;
  7034. }
  7035. switch (phba->sli_rev) {
  7036. case LPFC_SLI_REV2:
  7037. case LPFC_SLI_REV3:
  7038. /* Read chip Host Attention (HA) register */
  7039. ha_copy = lpfc_sli_eratt_read(phba);
  7040. break;
  7041. case LPFC_SLI_REV4:
  7042. /* Read devcie Uncoverable Error (UERR) registers */
  7043. ha_copy = lpfc_sli4_eratt_read(phba);
  7044. break;
  7045. default:
  7046. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7047. "0299 Invalid SLI revision (%d)\n",
  7048. phba->sli_rev);
  7049. ha_copy = 0;
  7050. break;
  7051. }
  7052. spin_unlock_irq(&phba->hbalock);
  7053. return ha_copy;
  7054. }
  7055. /**
  7056. * lpfc_intr_state_check - Check device state for interrupt handling
  7057. * @phba: Pointer to HBA context.
  7058. *
  7059. * This inline routine checks whether a device or its PCI slot is in a state
  7060. * that the interrupt should be handled.
  7061. *
  7062. * This function returns 0 if the device or the PCI slot is in a state that
  7063. * interrupt should be handled, otherwise -EIO.
  7064. */
  7065. static inline int
  7066. lpfc_intr_state_check(struct lpfc_hba *phba)
  7067. {
  7068. /* If the pci channel is offline, ignore all the interrupts */
  7069. if (unlikely(pci_channel_offline(phba->pcidev)))
  7070. return -EIO;
  7071. /* Update device level interrupt statistics */
  7072. phba->sli.slistat.sli_intr++;
  7073. /* Ignore all interrupts during initialization. */
  7074. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7075. return -EIO;
  7076. return 0;
  7077. }
  7078. /**
  7079. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7080. * @irq: Interrupt number.
  7081. * @dev_id: The device context pointer.
  7082. *
  7083. * This function is directly called from the PCI layer as an interrupt
  7084. * service routine when device with SLI-3 interface spec is enabled with
  7085. * MSI-X multi-message interrupt mode and there are slow-path events in
  7086. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7087. * interrupt mode, this function is called as part of the device-level
  7088. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7089. * is undergoing initialization, the interrupt handler will not process
  7090. * the interrupt. The link attention and ELS ring attention events are
  7091. * handled by the worker thread. The interrupt handler signals the worker
  7092. * thread and returns for these events. This function is called without
  7093. * any lock held. It gets the hbalock to access and update SLI data
  7094. * structures.
  7095. *
  7096. * This function returns IRQ_HANDLED when interrupt is handled else it
  7097. * returns IRQ_NONE.
  7098. **/
  7099. irqreturn_t
  7100. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7101. {
  7102. struct lpfc_hba *phba;
  7103. uint32_t ha_copy, hc_copy;
  7104. uint32_t work_ha_copy;
  7105. unsigned long status;
  7106. unsigned long iflag;
  7107. uint32_t control;
  7108. MAILBOX_t *mbox, *pmbox;
  7109. struct lpfc_vport *vport;
  7110. struct lpfc_nodelist *ndlp;
  7111. struct lpfc_dmabuf *mp;
  7112. LPFC_MBOXQ_t *pmb;
  7113. int rc;
  7114. /*
  7115. * Get the driver's phba structure from the dev_id and
  7116. * assume the HBA is not interrupting.
  7117. */
  7118. phba = (struct lpfc_hba *)dev_id;
  7119. if (unlikely(!phba))
  7120. return IRQ_NONE;
  7121. /*
  7122. * Stuff needs to be attented to when this function is invoked as an
  7123. * individual interrupt handler in MSI-X multi-message interrupt mode
  7124. */
  7125. if (phba->intr_type == MSIX) {
  7126. /* Check device state for handling interrupt */
  7127. if (lpfc_intr_state_check(phba))
  7128. return IRQ_NONE;
  7129. /* Need to read HA REG for slow-path events */
  7130. spin_lock_irqsave(&phba->hbalock, iflag);
  7131. ha_copy = readl(phba->HAregaddr);
  7132. /* If somebody is waiting to handle an eratt don't process it
  7133. * here. The brdkill function will do this.
  7134. */
  7135. if (phba->link_flag & LS_IGNORE_ERATT)
  7136. ha_copy &= ~HA_ERATT;
  7137. /* Check the need for handling ERATT in interrupt handler */
  7138. if (ha_copy & HA_ERATT) {
  7139. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7140. /* ERATT polling has handled ERATT */
  7141. ha_copy &= ~HA_ERATT;
  7142. else
  7143. /* Indicate interrupt handler handles ERATT */
  7144. phba->hba_flag |= HBA_ERATT_HANDLED;
  7145. }
  7146. /*
  7147. * If there is deferred error attention, do not check for any
  7148. * interrupt.
  7149. */
  7150. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7151. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7152. return IRQ_NONE;
  7153. }
  7154. /* Clear up only attention source related to slow-path */
  7155. hc_copy = readl(phba->HCregaddr);
  7156. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7157. HC_LAINT_ENA | HC_ERINT_ENA),
  7158. phba->HCregaddr);
  7159. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7160. phba->HAregaddr);
  7161. writel(hc_copy, phba->HCregaddr);
  7162. readl(phba->HAregaddr); /* flush */
  7163. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7164. } else
  7165. ha_copy = phba->ha_copy;
  7166. work_ha_copy = ha_copy & phba->work_ha_mask;
  7167. if (work_ha_copy) {
  7168. if (work_ha_copy & HA_LATT) {
  7169. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7170. /*
  7171. * Turn off Link Attention interrupts
  7172. * until CLEAR_LA done
  7173. */
  7174. spin_lock_irqsave(&phba->hbalock, iflag);
  7175. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7176. control = readl(phba->HCregaddr);
  7177. control &= ~HC_LAINT_ENA;
  7178. writel(control, phba->HCregaddr);
  7179. readl(phba->HCregaddr); /* flush */
  7180. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7181. }
  7182. else
  7183. work_ha_copy &= ~HA_LATT;
  7184. }
  7185. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7186. /*
  7187. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7188. * the only slow ring.
  7189. */
  7190. status = (work_ha_copy &
  7191. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7192. status >>= (4*LPFC_ELS_RING);
  7193. if (status & HA_RXMASK) {
  7194. spin_lock_irqsave(&phba->hbalock, iflag);
  7195. control = readl(phba->HCregaddr);
  7196. lpfc_debugfs_slow_ring_trc(phba,
  7197. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7198. control, status,
  7199. (uint32_t)phba->sli.slistat.sli_intr);
  7200. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7201. lpfc_debugfs_slow_ring_trc(phba,
  7202. "ISR Disable ring:"
  7203. "pwork:x%x hawork:x%x wait:x%x",
  7204. phba->work_ha, work_ha_copy,
  7205. (uint32_t)((unsigned long)
  7206. &phba->work_waitq));
  7207. control &=
  7208. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7209. writel(control, phba->HCregaddr);
  7210. readl(phba->HCregaddr); /* flush */
  7211. }
  7212. else {
  7213. lpfc_debugfs_slow_ring_trc(phba,
  7214. "ISR slow ring: pwork:"
  7215. "x%x hawork:x%x wait:x%x",
  7216. phba->work_ha, work_ha_copy,
  7217. (uint32_t)((unsigned long)
  7218. &phba->work_waitq));
  7219. }
  7220. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7221. }
  7222. }
  7223. spin_lock_irqsave(&phba->hbalock, iflag);
  7224. if (work_ha_copy & HA_ERATT) {
  7225. lpfc_sli_read_hs(phba);
  7226. /*
  7227. * Check if there is a deferred error condition
  7228. * is active
  7229. */
  7230. if ((HS_FFER1 & phba->work_hs) &&
  7231. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7232. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7233. phba->hba_flag |= DEFER_ERATT;
  7234. /* Clear all interrupt enable conditions */
  7235. writel(0, phba->HCregaddr);
  7236. readl(phba->HCregaddr);
  7237. }
  7238. }
  7239. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7240. pmb = phba->sli.mbox_active;
  7241. pmbox = &pmb->u.mb;
  7242. mbox = phba->mbox;
  7243. vport = pmb->vport;
  7244. /* First check out the status word */
  7245. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7246. if (pmbox->mbxOwner != OWN_HOST) {
  7247. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7248. /*
  7249. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7250. * mbxStatus <status>
  7251. */
  7252. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7253. LOG_SLI,
  7254. "(%d):0304 Stray Mailbox "
  7255. "Interrupt mbxCommand x%x "
  7256. "mbxStatus x%x\n",
  7257. (vport ? vport->vpi : 0),
  7258. pmbox->mbxCommand,
  7259. pmbox->mbxStatus);
  7260. /* clear mailbox attention bit */
  7261. work_ha_copy &= ~HA_MBATT;
  7262. } else {
  7263. phba->sli.mbox_active = NULL;
  7264. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7265. phba->last_completion_time = jiffies;
  7266. del_timer(&phba->sli.mbox_tmo);
  7267. if (pmb->mbox_cmpl) {
  7268. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7269. MAILBOX_CMD_SIZE);
  7270. }
  7271. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7272. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7273. lpfc_debugfs_disc_trc(vport,
  7274. LPFC_DISC_TRC_MBOX_VPORT,
  7275. "MBOX dflt rpi: : "
  7276. "status:x%x rpi:x%x",
  7277. (uint32_t)pmbox->mbxStatus,
  7278. pmbox->un.varWords[0], 0);
  7279. if (!pmbox->mbxStatus) {
  7280. mp = (struct lpfc_dmabuf *)
  7281. (pmb->context1);
  7282. ndlp = (struct lpfc_nodelist *)
  7283. pmb->context2;
  7284. /* Reg_LOGIN of dflt RPI was
  7285. * successful. new lets get
  7286. * rid of the RPI using the
  7287. * same mbox buffer.
  7288. */
  7289. lpfc_unreg_login(phba,
  7290. vport->vpi,
  7291. pmbox->un.varWords[0],
  7292. pmb);
  7293. pmb->mbox_cmpl =
  7294. lpfc_mbx_cmpl_dflt_rpi;
  7295. pmb->context1 = mp;
  7296. pmb->context2 = ndlp;
  7297. pmb->vport = vport;
  7298. rc = lpfc_sli_issue_mbox(phba,
  7299. pmb,
  7300. MBX_NOWAIT);
  7301. if (rc != MBX_BUSY)
  7302. lpfc_printf_log(phba,
  7303. KERN_ERR,
  7304. LOG_MBOX | LOG_SLI,
  7305. "0350 rc should have"
  7306. "been MBX_BUSY\n");
  7307. if (rc != MBX_NOT_FINISHED)
  7308. goto send_current_mbox;
  7309. }
  7310. }
  7311. spin_lock_irqsave(
  7312. &phba->pport->work_port_lock,
  7313. iflag);
  7314. phba->pport->work_port_events &=
  7315. ~WORKER_MBOX_TMO;
  7316. spin_unlock_irqrestore(
  7317. &phba->pport->work_port_lock,
  7318. iflag);
  7319. lpfc_mbox_cmpl_put(phba, pmb);
  7320. }
  7321. } else
  7322. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7323. if ((work_ha_copy & HA_MBATT) &&
  7324. (phba->sli.mbox_active == NULL)) {
  7325. send_current_mbox:
  7326. /* Process next mailbox command if there is one */
  7327. do {
  7328. rc = lpfc_sli_issue_mbox(phba, NULL,
  7329. MBX_NOWAIT);
  7330. } while (rc == MBX_NOT_FINISHED);
  7331. if (rc != MBX_SUCCESS)
  7332. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7333. LOG_SLI, "0349 rc should be "
  7334. "MBX_SUCCESS\n");
  7335. }
  7336. spin_lock_irqsave(&phba->hbalock, iflag);
  7337. phba->work_ha |= work_ha_copy;
  7338. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7339. lpfc_worker_wake_up(phba);
  7340. }
  7341. return IRQ_HANDLED;
  7342. } /* lpfc_sli_sp_intr_handler */
  7343. /**
  7344. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7345. * @irq: Interrupt number.
  7346. * @dev_id: The device context pointer.
  7347. *
  7348. * This function is directly called from the PCI layer as an interrupt
  7349. * service routine when device with SLI-3 interface spec is enabled with
  7350. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7351. * ring event in the HBA. However, when the device is enabled with either
  7352. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7353. * device-level interrupt handler. When the PCI slot is in error recovery
  7354. * or the HBA is undergoing initialization, the interrupt handler will not
  7355. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7356. * the intrrupt context. This function is called without any lock held.
  7357. * It gets the hbalock to access and update SLI data structures.
  7358. *
  7359. * This function returns IRQ_HANDLED when interrupt is handled else it
  7360. * returns IRQ_NONE.
  7361. **/
  7362. irqreturn_t
  7363. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7364. {
  7365. struct lpfc_hba *phba;
  7366. uint32_t ha_copy;
  7367. unsigned long status;
  7368. unsigned long iflag;
  7369. /* Get the driver's phba structure from the dev_id and
  7370. * assume the HBA is not interrupting.
  7371. */
  7372. phba = (struct lpfc_hba *) dev_id;
  7373. if (unlikely(!phba))
  7374. return IRQ_NONE;
  7375. /*
  7376. * Stuff needs to be attented to when this function is invoked as an
  7377. * individual interrupt handler in MSI-X multi-message interrupt mode
  7378. */
  7379. if (phba->intr_type == MSIX) {
  7380. /* Check device state for handling interrupt */
  7381. if (lpfc_intr_state_check(phba))
  7382. return IRQ_NONE;
  7383. /* Need to read HA REG for FCP ring and other ring events */
  7384. ha_copy = readl(phba->HAregaddr);
  7385. /* Clear up only attention source related to fast-path */
  7386. spin_lock_irqsave(&phba->hbalock, iflag);
  7387. /*
  7388. * If there is deferred error attention, do not check for
  7389. * any interrupt.
  7390. */
  7391. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7392. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7393. return IRQ_NONE;
  7394. }
  7395. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7396. phba->HAregaddr);
  7397. readl(phba->HAregaddr); /* flush */
  7398. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7399. } else
  7400. ha_copy = phba->ha_copy;
  7401. /*
  7402. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7403. */
  7404. ha_copy &= ~(phba->work_ha_mask);
  7405. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7406. status >>= (4*LPFC_FCP_RING);
  7407. if (status & HA_RXMASK)
  7408. lpfc_sli_handle_fast_ring_event(phba,
  7409. &phba->sli.ring[LPFC_FCP_RING],
  7410. status);
  7411. if (phba->cfg_multi_ring_support == 2) {
  7412. /*
  7413. * Process all events on extra ring. Take the optimized path
  7414. * for extra ring IO.
  7415. */
  7416. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7417. status >>= (4*LPFC_EXTRA_RING);
  7418. if (status & HA_RXMASK) {
  7419. lpfc_sli_handle_fast_ring_event(phba,
  7420. &phba->sli.ring[LPFC_EXTRA_RING],
  7421. status);
  7422. }
  7423. }
  7424. return IRQ_HANDLED;
  7425. } /* lpfc_sli_fp_intr_handler */
  7426. /**
  7427. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7428. * @irq: Interrupt number.
  7429. * @dev_id: The device context pointer.
  7430. *
  7431. * This function is the HBA device-level interrupt handler to device with
  7432. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7433. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7434. * requires driver attention. This function invokes the slow-path interrupt
  7435. * attention handling function and fast-path interrupt attention handling
  7436. * function in turn to process the relevant HBA attention events. This
  7437. * function is called without any lock held. It gets the hbalock to access
  7438. * and update SLI data structures.
  7439. *
  7440. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7441. * returns IRQ_NONE.
  7442. **/
  7443. irqreturn_t
  7444. lpfc_sli_intr_handler(int irq, void *dev_id)
  7445. {
  7446. struct lpfc_hba *phba;
  7447. irqreturn_t sp_irq_rc, fp_irq_rc;
  7448. unsigned long status1, status2;
  7449. uint32_t hc_copy;
  7450. /*
  7451. * Get the driver's phba structure from the dev_id and
  7452. * assume the HBA is not interrupting.
  7453. */
  7454. phba = (struct lpfc_hba *) dev_id;
  7455. if (unlikely(!phba))
  7456. return IRQ_NONE;
  7457. /* Check device state for handling interrupt */
  7458. if (lpfc_intr_state_check(phba))
  7459. return IRQ_NONE;
  7460. spin_lock(&phba->hbalock);
  7461. phba->ha_copy = readl(phba->HAregaddr);
  7462. if (unlikely(!phba->ha_copy)) {
  7463. spin_unlock(&phba->hbalock);
  7464. return IRQ_NONE;
  7465. } else if (phba->ha_copy & HA_ERATT) {
  7466. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7467. /* ERATT polling has handled ERATT */
  7468. phba->ha_copy &= ~HA_ERATT;
  7469. else
  7470. /* Indicate interrupt handler handles ERATT */
  7471. phba->hba_flag |= HBA_ERATT_HANDLED;
  7472. }
  7473. /*
  7474. * If there is deferred error attention, do not check for any interrupt.
  7475. */
  7476. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7477. spin_unlock_irq(&phba->hbalock);
  7478. return IRQ_NONE;
  7479. }
  7480. /* Clear attention sources except link and error attentions */
  7481. hc_copy = readl(phba->HCregaddr);
  7482. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7483. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7484. phba->HCregaddr);
  7485. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7486. writel(hc_copy, phba->HCregaddr);
  7487. readl(phba->HAregaddr); /* flush */
  7488. spin_unlock(&phba->hbalock);
  7489. /*
  7490. * Invokes slow-path host attention interrupt handling as appropriate.
  7491. */
  7492. /* status of events with mailbox and link attention */
  7493. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7494. /* status of events with ELS ring */
  7495. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7496. status2 >>= (4*LPFC_ELS_RING);
  7497. if (status1 || (status2 & HA_RXMASK))
  7498. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7499. else
  7500. sp_irq_rc = IRQ_NONE;
  7501. /*
  7502. * Invoke fast-path host attention interrupt handling as appropriate.
  7503. */
  7504. /* status of events with FCP ring */
  7505. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7506. status1 >>= (4*LPFC_FCP_RING);
  7507. /* status of events with extra ring */
  7508. if (phba->cfg_multi_ring_support == 2) {
  7509. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7510. status2 >>= (4*LPFC_EXTRA_RING);
  7511. } else
  7512. status2 = 0;
  7513. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7514. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7515. else
  7516. fp_irq_rc = IRQ_NONE;
  7517. /* Return device-level interrupt handling status */
  7518. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7519. } /* lpfc_sli_intr_handler */
  7520. /**
  7521. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7522. * @phba: pointer to lpfc hba data structure.
  7523. *
  7524. * This routine is invoked by the worker thread to process all the pending
  7525. * SLI4 FCP abort XRI events.
  7526. **/
  7527. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7528. {
  7529. struct lpfc_cq_event *cq_event;
  7530. /* First, declare the fcp xri abort event has been handled */
  7531. spin_lock_irq(&phba->hbalock);
  7532. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7533. spin_unlock_irq(&phba->hbalock);
  7534. /* Now, handle all the fcp xri abort events */
  7535. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7536. /* Get the first event from the head of the event queue */
  7537. spin_lock_irq(&phba->hbalock);
  7538. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7539. cq_event, struct lpfc_cq_event, list);
  7540. spin_unlock_irq(&phba->hbalock);
  7541. /* Notify aborted XRI for FCP work queue */
  7542. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7543. /* Free the event processed back to the free pool */
  7544. lpfc_sli4_cq_event_release(phba, cq_event);
  7545. }
  7546. }
  7547. /**
  7548. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7549. * @phba: pointer to lpfc hba data structure.
  7550. *
  7551. * This routine is invoked by the worker thread to process all the pending
  7552. * SLI4 els abort xri events.
  7553. **/
  7554. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7555. {
  7556. struct lpfc_cq_event *cq_event;
  7557. /* First, declare the els xri abort event has been handled */
  7558. spin_lock_irq(&phba->hbalock);
  7559. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7560. spin_unlock_irq(&phba->hbalock);
  7561. /* Now, handle all the els xri abort events */
  7562. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7563. /* Get the first event from the head of the event queue */
  7564. spin_lock_irq(&phba->hbalock);
  7565. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7566. cq_event, struct lpfc_cq_event, list);
  7567. spin_unlock_irq(&phba->hbalock);
  7568. /* Notify aborted XRI for ELS work queue */
  7569. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7570. /* Free the event processed back to the free pool */
  7571. lpfc_sli4_cq_event_release(phba, cq_event);
  7572. }
  7573. }
  7574. static void
  7575. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7576. struct lpfc_iocbq *pIocbOut,
  7577. struct lpfc_wcqe_complete *wcqe)
  7578. {
  7579. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7580. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7581. sizeof(struct lpfc_iocbq) - offset);
  7582. /* Map WCQE parameters into irspiocb parameters */
  7583. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7584. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7585. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7586. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7587. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7588. wcqe->total_data_placed;
  7589. else
  7590. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7591. else
  7592. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7593. }
  7594. /**
  7595. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7596. * @phba: Pointer to HBA context object.
  7597. * @wcqe: Pointer to work-queue completion queue entry.
  7598. *
  7599. * This routine handles an ELS work-queue completion event and construct
  7600. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7601. * discovery engine to handle.
  7602. *
  7603. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7604. **/
  7605. static struct lpfc_iocbq *
  7606. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7607. struct lpfc_iocbq *irspiocbq)
  7608. {
  7609. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7610. struct lpfc_iocbq *cmdiocbq;
  7611. struct lpfc_wcqe_complete *wcqe;
  7612. unsigned long iflags;
  7613. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7614. spin_lock_irqsave(&phba->hbalock, iflags);
  7615. pring->stats.iocb_event++;
  7616. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7617. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7618. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7619. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7620. if (unlikely(!cmdiocbq)) {
  7621. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7622. "0386 ELS complete with no corresponding "
  7623. "cmdiocb: iotag (%d)\n",
  7624. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7625. lpfc_sli_release_iocbq(phba, irspiocbq);
  7626. return NULL;
  7627. }
  7628. /* Fake the irspiocbq and copy necessary response information */
  7629. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7630. return irspiocbq;
  7631. }
  7632. /**
  7633. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7634. * @phba: Pointer to HBA context object.
  7635. * @cqe: Pointer to mailbox completion queue entry.
  7636. *
  7637. * This routine process a mailbox completion queue entry with asynchrous
  7638. * event.
  7639. *
  7640. * Return: true if work posted to worker thread, otherwise false.
  7641. **/
  7642. static bool
  7643. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7644. {
  7645. struct lpfc_cq_event *cq_event;
  7646. unsigned long iflags;
  7647. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7648. "0392 Async Event: word0:x%x, word1:x%x, "
  7649. "word2:x%x, word3:x%x\n", mcqe->word0,
  7650. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7651. /* Allocate a new internal CQ_EVENT entry */
  7652. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7653. if (!cq_event) {
  7654. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7655. "0394 Failed to allocate CQ_EVENT entry\n");
  7656. return false;
  7657. }
  7658. /* Move the CQE into an asynchronous event entry */
  7659. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7660. spin_lock_irqsave(&phba->hbalock, iflags);
  7661. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7662. /* Set the async event flag */
  7663. phba->hba_flag |= ASYNC_EVENT;
  7664. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7665. return true;
  7666. }
  7667. /**
  7668. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7669. * @phba: Pointer to HBA context object.
  7670. * @cqe: Pointer to mailbox completion queue entry.
  7671. *
  7672. * This routine process a mailbox completion queue entry with mailbox
  7673. * completion event.
  7674. *
  7675. * Return: true if work posted to worker thread, otherwise false.
  7676. **/
  7677. static bool
  7678. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7679. {
  7680. uint32_t mcqe_status;
  7681. MAILBOX_t *mbox, *pmbox;
  7682. struct lpfc_mqe *mqe;
  7683. struct lpfc_vport *vport;
  7684. struct lpfc_nodelist *ndlp;
  7685. struct lpfc_dmabuf *mp;
  7686. unsigned long iflags;
  7687. LPFC_MBOXQ_t *pmb;
  7688. bool workposted = false;
  7689. int rc;
  7690. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7691. if (!bf_get(lpfc_trailer_completed, mcqe))
  7692. goto out_no_mqe_complete;
  7693. /* Get the reference to the active mbox command */
  7694. spin_lock_irqsave(&phba->hbalock, iflags);
  7695. pmb = phba->sli.mbox_active;
  7696. if (unlikely(!pmb)) {
  7697. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7698. "1832 No pending MBOX command to handle\n");
  7699. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7700. goto out_no_mqe_complete;
  7701. }
  7702. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7703. mqe = &pmb->u.mqe;
  7704. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7705. mbox = phba->mbox;
  7706. vport = pmb->vport;
  7707. /* Reset heartbeat timer */
  7708. phba->last_completion_time = jiffies;
  7709. del_timer(&phba->sli.mbox_tmo);
  7710. /* Move mbox data to caller's mailbox region, do endian swapping */
  7711. if (pmb->mbox_cmpl && mbox)
  7712. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7713. /* Set the mailbox status with SLI4 range 0x4000 */
  7714. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7715. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7716. bf_set(lpfc_mqe_status, mqe,
  7717. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7718. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7719. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7720. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7721. "MBOX dflt rpi: status:x%x rpi:x%x",
  7722. mcqe_status,
  7723. pmbox->un.varWords[0], 0);
  7724. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7725. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7726. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7727. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7728. * RID of the PPI using the same mbox buffer.
  7729. */
  7730. lpfc_unreg_login(phba, vport->vpi,
  7731. pmbox->un.varWords[0], pmb);
  7732. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7733. pmb->context1 = mp;
  7734. pmb->context2 = ndlp;
  7735. pmb->vport = vport;
  7736. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7737. if (rc != MBX_BUSY)
  7738. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7739. LOG_SLI, "0385 rc should "
  7740. "have been MBX_BUSY\n");
  7741. if (rc != MBX_NOT_FINISHED)
  7742. goto send_current_mbox;
  7743. }
  7744. }
  7745. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7746. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7747. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7748. /* There is mailbox completion work to do */
  7749. spin_lock_irqsave(&phba->hbalock, iflags);
  7750. __lpfc_mbox_cmpl_put(phba, pmb);
  7751. phba->work_ha |= HA_MBATT;
  7752. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7753. workposted = true;
  7754. send_current_mbox:
  7755. spin_lock_irqsave(&phba->hbalock, iflags);
  7756. /* Release the mailbox command posting token */
  7757. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7758. /* Setting active mailbox pointer need to be in sync to flag clear */
  7759. phba->sli.mbox_active = NULL;
  7760. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7761. /* Wake up worker thread to post the next pending mailbox command */
  7762. lpfc_worker_wake_up(phba);
  7763. out_no_mqe_complete:
  7764. if (bf_get(lpfc_trailer_consumed, mcqe))
  7765. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7766. return workposted;
  7767. }
  7768. /**
  7769. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7770. * @phba: Pointer to HBA context object.
  7771. * @cqe: Pointer to mailbox completion queue entry.
  7772. *
  7773. * This routine process a mailbox completion queue entry, it invokes the
  7774. * proper mailbox complete handling or asynchrous event handling routine
  7775. * according to the MCQE's async bit.
  7776. *
  7777. * Return: true if work posted to worker thread, otherwise false.
  7778. **/
  7779. static bool
  7780. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7781. {
  7782. struct lpfc_mcqe mcqe;
  7783. bool workposted;
  7784. /* Copy the mailbox MCQE and convert endian order as needed */
  7785. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7786. /* Invoke the proper event handling routine */
  7787. if (!bf_get(lpfc_trailer_async, &mcqe))
  7788. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7789. else
  7790. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7791. return workposted;
  7792. }
  7793. /**
  7794. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7795. * @phba: Pointer to HBA context object.
  7796. * @wcqe: Pointer to work-queue completion queue entry.
  7797. *
  7798. * This routine handles an ELS work-queue completion event.
  7799. *
  7800. * Return: true if work posted to worker thread, otherwise false.
  7801. **/
  7802. static bool
  7803. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7804. struct lpfc_wcqe_complete *wcqe)
  7805. {
  7806. struct lpfc_iocbq *irspiocbq;
  7807. unsigned long iflags;
  7808. /* Get an irspiocbq for later ELS response processing use */
  7809. irspiocbq = lpfc_sli_get_iocbq(phba);
  7810. if (!irspiocbq) {
  7811. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7812. "0387 Failed to allocate an iocbq\n");
  7813. return false;
  7814. }
  7815. /* Save off the slow-path queue event for work thread to process */
  7816. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  7817. spin_lock_irqsave(&phba->hbalock, iflags);
  7818. list_add_tail(&irspiocbq->cq_event.list,
  7819. &phba->sli4_hba.sp_queue_event);
  7820. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7821. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7822. return true;
  7823. }
  7824. /**
  7825. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7826. * @phba: Pointer to HBA context object.
  7827. * @wcqe: Pointer to work-queue completion queue entry.
  7828. *
  7829. * This routine handles slow-path WQ entry comsumed event by invoking the
  7830. * proper WQ release routine to the slow-path WQ.
  7831. **/
  7832. static void
  7833. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7834. struct lpfc_wcqe_release *wcqe)
  7835. {
  7836. /* Check for the slow-path ELS work queue */
  7837. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7838. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7839. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7840. else
  7841. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7842. "2579 Slow-path wqe consume event carries "
  7843. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7844. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7845. phba->sli4_hba.els_wq->queue_id);
  7846. }
  7847. /**
  7848. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7849. * @phba: Pointer to HBA context object.
  7850. * @cq: Pointer to a WQ completion queue.
  7851. * @wcqe: Pointer to work-queue completion queue entry.
  7852. *
  7853. * This routine handles an XRI abort event.
  7854. *
  7855. * Return: true if work posted to worker thread, otherwise false.
  7856. **/
  7857. static bool
  7858. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7859. struct lpfc_queue *cq,
  7860. struct sli4_wcqe_xri_aborted *wcqe)
  7861. {
  7862. bool workposted = false;
  7863. struct lpfc_cq_event *cq_event;
  7864. unsigned long iflags;
  7865. /* Allocate a new internal CQ_EVENT entry */
  7866. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7867. if (!cq_event) {
  7868. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7869. "0602 Failed to allocate CQ_EVENT entry\n");
  7870. return false;
  7871. }
  7872. /* Move the CQE into the proper xri abort event list */
  7873. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7874. switch (cq->subtype) {
  7875. case LPFC_FCP:
  7876. spin_lock_irqsave(&phba->hbalock, iflags);
  7877. list_add_tail(&cq_event->list,
  7878. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7879. /* Set the fcp xri abort event flag */
  7880. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7881. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7882. workposted = true;
  7883. break;
  7884. case LPFC_ELS:
  7885. spin_lock_irqsave(&phba->hbalock, iflags);
  7886. list_add_tail(&cq_event->list,
  7887. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7888. /* Set the els xri abort event flag */
  7889. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7890. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7891. workposted = true;
  7892. break;
  7893. default:
  7894. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7895. "0603 Invalid work queue CQE subtype (x%x)\n",
  7896. cq->subtype);
  7897. workposted = false;
  7898. break;
  7899. }
  7900. return workposted;
  7901. }
  7902. /**
  7903. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7904. * @phba: Pointer to HBA context object.
  7905. * @rcqe: Pointer to receive-queue completion queue entry.
  7906. *
  7907. * This routine process a receive-queue completion queue entry.
  7908. *
  7909. * Return: true if work posted to worker thread, otherwise false.
  7910. **/
  7911. static bool
  7912. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  7913. {
  7914. bool workposted = false;
  7915. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7916. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7917. struct hbq_dmabuf *dma_buf;
  7918. uint32_t status;
  7919. unsigned long iflags;
  7920. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  7921. goto out;
  7922. status = bf_get(lpfc_rcqe_status, rcqe);
  7923. switch (status) {
  7924. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7925. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7926. "2537 Receive Frame Truncated!!\n");
  7927. case FC_STATUS_RQ_SUCCESS:
  7928. lpfc_sli4_rq_release(hrq, drq);
  7929. spin_lock_irqsave(&phba->hbalock, iflags);
  7930. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7931. if (!dma_buf) {
  7932. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7933. goto out;
  7934. }
  7935. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  7936. /* save off the frame for the word thread to process */
  7937. list_add_tail(&dma_buf->cq_event.list,
  7938. &phba->sli4_hba.sp_queue_event);
  7939. /* Frame received */
  7940. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  7941. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7942. workposted = true;
  7943. break;
  7944. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7945. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7946. /* Post more buffers if possible */
  7947. spin_lock_irqsave(&phba->hbalock, iflags);
  7948. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7949. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7950. workposted = true;
  7951. break;
  7952. }
  7953. out:
  7954. return workposted;
  7955. }
  7956. /**
  7957. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  7958. * @phba: Pointer to HBA context object.
  7959. * @cq: Pointer to the completion queue.
  7960. * @wcqe: Pointer to a completion queue entry.
  7961. *
  7962. * This routine process a slow-path work-queue or recieve queue completion queue
  7963. * entry.
  7964. *
  7965. * Return: true if work posted to worker thread, otherwise false.
  7966. **/
  7967. static bool
  7968. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7969. struct lpfc_cqe *cqe)
  7970. {
  7971. struct lpfc_cqe cqevt;
  7972. bool workposted = false;
  7973. /* Copy the work queue CQE and convert endian order if needed */
  7974. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  7975. /* Check and process for different type of WCQE and dispatch */
  7976. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  7977. case CQE_CODE_COMPL_WQE:
  7978. /* Process the WQ/RQ complete event */
  7979. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7980. (struct lpfc_wcqe_complete *)&cqevt);
  7981. break;
  7982. case CQE_CODE_RELEASE_WQE:
  7983. /* Process the WQ release event */
  7984. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7985. (struct lpfc_wcqe_release *)&cqevt);
  7986. break;
  7987. case CQE_CODE_XRI_ABORTED:
  7988. /* Process the WQ XRI abort event */
  7989. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7990. (struct sli4_wcqe_xri_aborted *)&cqevt);
  7991. break;
  7992. case CQE_CODE_RECEIVE:
  7993. /* Process the RQ event */
  7994. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  7995. (struct lpfc_rcqe *)&cqevt);
  7996. break;
  7997. default:
  7998. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7999. "0388 Not a valid WCQE code: x%x\n",
  8000. bf_get(lpfc_cqe_code, &cqevt));
  8001. break;
  8002. }
  8003. return workposted;
  8004. }
  8005. /**
  8006. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8007. * @phba: Pointer to HBA context object.
  8008. * @eqe: Pointer to fast-path event queue entry.
  8009. *
  8010. * This routine process a event queue entry from the slow-path event queue.
  8011. * It will check the MajorCode and MinorCode to determine this is for a
  8012. * completion event on a completion queue, if not, an error shall be logged
  8013. * and just return. Otherwise, it will get to the corresponding completion
  8014. * queue and process all the entries on that completion queue, rearm the
  8015. * completion queue, and then return.
  8016. *
  8017. **/
  8018. static void
  8019. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8020. {
  8021. struct lpfc_queue *cq = NULL, *childq, *speq;
  8022. struct lpfc_cqe *cqe;
  8023. bool workposted = false;
  8024. int ecount = 0;
  8025. uint16_t cqid;
  8026. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  8027. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  8028. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8029. "0359 Not a valid slow-path completion "
  8030. "event: majorcode=x%x, minorcode=x%x\n",
  8031. bf_get(lpfc_eqe_major_code, eqe),
  8032. bf_get(lpfc_eqe_minor_code, eqe));
  8033. return;
  8034. }
  8035. /* Get the reference to the corresponding CQ */
  8036. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8037. /* Search for completion queue pointer matching this cqid */
  8038. speq = phba->sli4_hba.sp_eq;
  8039. list_for_each_entry(childq, &speq->child_list, list) {
  8040. if (childq->queue_id == cqid) {
  8041. cq = childq;
  8042. break;
  8043. }
  8044. }
  8045. if (unlikely(!cq)) {
  8046. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8047. "0365 Slow-path CQ identifier (%d) does "
  8048. "not exist\n", cqid);
  8049. return;
  8050. }
  8051. /* Process all the entries to the CQ */
  8052. switch (cq->type) {
  8053. case LPFC_MCQ:
  8054. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8055. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8056. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8057. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8058. }
  8059. break;
  8060. case LPFC_WCQ:
  8061. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8062. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8063. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8064. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8065. }
  8066. break;
  8067. default:
  8068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8069. "0370 Invalid completion queue type (%d)\n",
  8070. cq->type);
  8071. return;
  8072. }
  8073. /* Catch the no cq entry condition, log an error */
  8074. if (unlikely(ecount == 0))
  8075. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8076. "0371 No entry from the CQ: identifier "
  8077. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8078. /* In any case, flash and re-arm the RCQ */
  8079. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8080. /* wake up worker thread if there are works to be done */
  8081. if (workposted)
  8082. lpfc_worker_wake_up(phba);
  8083. }
  8084. /**
  8085. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8086. * @eqe: Pointer to fast-path completion queue entry.
  8087. *
  8088. * This routine process a fast-path work queue completion entry from fast-path
  8089. * event queue for FCP command response completion.
  8090. **/
  8091. static void
  8092. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8093. struct lpfc_wcqe_complete *wcqe)
  8094. {
  8095. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8096. struct lpfc_iocbq *cmdiocbq;
  8097. struct lpfc_iocbq irspiocbq;
  8098. unsigned long iflags;
  8099. spin_lock_irqsave(&phba->hbalock, iflags);
  8100. pring->stats.iocb_event++;
  8101. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8102. /* Check for response status */
  8103. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8104. /* If resource errors reported from HBA, reduce queue
  8105. * depth of the SCSI device.
  8106. */
  8107. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8108. IOSTAT_LOCAL_REJECT) &&
  8109. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8110. phba->lpfc_rampdown_queue_depth(phba);
  8111. }
  8112. /* Log the error status */
  8113. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8114. "0373 FCP complete error: status=x%x, "
  8115. "hw_status=x%x, total_data_specified=%d, "
  8116. "parameter=x%x, word3=x%x\n",
  8117. bf_get(lpfc_wcqe_c_status, wcqe),
  8118. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8119. wcqe->total_data_placed, wcqe->parameter,
  8120. wcqe->word3);
  8121. }
  8122. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8123. spin_lock_irqsave(&phba->hbalock, iflags);
  8124. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8125. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8126. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8127. if (unlikely(!cmdiocbq)) {
  8128. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8129. "0374 FCP complete with no corresponding "
  8130. "cmdiocb: iotag (%d)\n",
  8131. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8132. return;
  8133. }
  8134. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8135. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8136. "0375 FCP cmdiocb not callback function "
  8137. "iotag: (%d)\n",
  8138. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8139. return;
  8140. }
  8141. /* Fake the irspiocb and copy necessary response information */
  8142. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8143. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8144. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8145. }
  8146. /**
  8147. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8148. * @phba: Pointer to HBA context object.
  8149. * @cq: Pointer to completion queue.
  8150. * @wcqe: Pointer to work-queue completion queue entry.
  8151. *
  8152. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8153. * proper WQ release routine to the slow-path WQ.
  8154. **/
  8155. static void
  8156. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8157. struct lpfc_wcqe_release *wcqe)
  8158. {
  8159. struct lpfc_queue *childwq;
  8160. bool wqid_matched = false;
  8161. uint16_t fcp_wqid;
  8162. /* Check for fast-path FCP work queue release */
  8163. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8164. list_for_each_entry(childwq, &cq->child_list, list) {
  8165. if (childwq->queue_id == fcp_wqid) {
  8166. lpfc_sli4_wq_release(childwq,
  8167. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8168. wqid_matched = true;
  8169. break;
  8170. }
  8171. }
  8172. /* Report warning log message if no match found */
  8173. if (wqid_matched != true)
  8174. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8175. "2580 Fast-path wqe consume event carries "
  8176. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8177. }
  8178. /**
  8179. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8180. * @cq: Pointer to the completion queue.
  8181. * @eqe: Pointer to fast-path completion queue entry.
  8182. *
  8183. * This routine process a fast-path work queue completion entry from fast-path
  8184. * event queue for FCP command response completion.
  8185. **/
  8186. static int
  8187. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8188. struct lpfc_cqe *cqe)
  8189. {
  8190. struct lpfc_wcqe_release wcqe;
  8191. bool workposted = false;
  8192. /* Copy the work queue CQE and convert endian order if needed */
  8193. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8194. /* Check and process for different type of WCQE and dispatch */
  8195. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8196. case CQE_CODE_COMPL_WQE:
  8197. /* Process the WQ complete event */
  8198. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8199. (struct lpfc_wcqe_complete *)&wcqe);
  8200. break;
  8201. case CQE_CODE_RELEASE_WQE:
  8202. /* Process the WQ release event */
  8203. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8204. (struct lpfc_wcqe_release *)&wcqe);
  8205. break;
  8206. case CQE_CODE_XRI_ABORTED:
  8207. /* Process the WQ XRI abort event */
  8208. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8209. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8210. break;
  8211. default:
  8212. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8213. "0144 Not a valid WCQE code: x%x\n",
  8214. bf_get(lpfc_wcqe_c_code, &wcqe));
  8215. break;
  8216. }
  8217. return workposted;
  8218. }
  8219. /**
  8220. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8221. * @phba: Pointer to HBA context object.
  8222. * @eqe: Pointer to fast-path event queue entry.
  8223. *
  8224. * This routine process a event queue entry from the fast-path event queue.
  8225. * It will check the MajorCode and MinorCode to determine this is for a
  8226. * completion event on a completion queue, if not, an error shall be logged
  8227. * and just return. Otherwise, it will get to the corresponding completion
  8228. * queue and process all the entries on the completion queue, rearm the
  8229. * completion queue, and then return.
  8230. **/
  8231. static void
  8232. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8233. uint32_t fcp_cqidx)
  8234. {
  8235. struct lpfc_queue *cq;
  8236. struct lpfc_cqe *cqe;
  8237. bool workposted = false;
  8238. uint16_t cqid;
  8239. int ecount = 0;
  8240. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8241. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8242. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8243. "0366 Not a valid fast-path completion "
  8244. "event: majorcode=x%x, minorcode=x%x\n",
  8245. bf_get(lpfc_eqe_major_code, eqe),
  8246. bf_get(lpfc_eqe_minor_code, eqe));
  8247. return;
  8248. }
  8249. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8250. if (unlikely(!cq)) {
  8251. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8252. "0367 Fast-path completion queue does not "
  8253. "exist\n");
  8254. return;
  8255. }
  8256. /* Get the reference to the corresponding CQ */
  8257. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8258. if (unlikely(cqid != cq->queue_id)) {
  8259. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8260. "0368 Miss-matched fast-path completion "
  8261. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8262. cqid, cq->queue_id);
  8263. return;
  8264. }
  8265. /* Process all the entries to the CQ */
  8266. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8267. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8268. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8269. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8270. }
  8271. /* Catch the no cq entry condition */
  8272. if (unlikely(ecount == 0))
  8273. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8274. "0369 No entry from fast-path completion "
  8275. "queue fcpcqid=%d\n", cq->queue_id);
  8276. /* In any case, flash and re-arm the CQ */
  8277. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8278. /* wake up worker thread if there are works to be done */
  8279. if (workposted)
  8280. lpfc_worker_wake_up(phba);
  8281. }
  8282. static void
  8283. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8284. {
  8285. struct lpfc_eqe *eqe;
  8286. /* walk all the EQ entries and drop on the floor */
  8287. while ((eqe = lpfc_sli4_eq_get(eq)))
  8288. ;
  8289. /* Clear and re-arm the EQ */
  8290. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8291. }
  8292. /**
  8293. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8294. * @irq: Interrupt number.
  8295. * @dev_id: The device context pointer.
  8296. *
  8297. * This function is directly called from the PCI layer as an interrupt
  8298. * service routine when device with SLI-4 interface spec is enabled with
  8299. * MSI-X multi-message interrupt mode and there are slow-path events in
  8300. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8301. * interrupt mode, this function is called as part of the device-level
  8302. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8303. * undergoing initialization, the interrupt handler will not process the
  8304. * interrupt. The link attention and ELS ring attention events are handled
  8305. * by the worker thread. The interrupt handler signals the worker thread
  8306. * and returns for these events. This function is called without any lock
  8307. * held. It gets the hbalock to access and update SLI data structures.
  8308. *
  8309. * This function returns IRQ_HANDLED when interrupt is handled else it
  8310. * returns IRQ_NONE.
  8311. **/
  8312. irqreturn_t
  8313. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8314. {
  8315. struct lpfc_hba *phba;
  8316. struct lpfc_queue *speq;
  8317. struct lpfc_eqe *eqe;
  8318. unsigned long iflag;
  8319. int ecount = 0;
  8320. /*
  8321. * Get the driver's phba structure from the dev_id
  8322. */
  8323. phba = (struct lpfc_hba *)dev_id;
  8324. if (unlikely(!phba))
  8325. return IRQ_NONE;
  8326. /* Get to the EQ struct associated with this vector */
  8327. speq = phba->sli4_hba.sp_eq;
  8328. /* Check device state for handling interrupt */
  8329. if (unlikely(lpfc_intr_state_check(phba))) {
  8330. /* Check again for link_state with lock held */
  8331. spin_lock_irqsave(&phba->hbalock, iflag);
  8332. if (phba->link_state < LPFC_LINK_DOWN)
  8333. /* Flush, clear interrupt, and rearm the EQ */
  8334. lpfc_sli4_eq_flush(phba, speq);
  8335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8336. return IRQ_NONE;
  8337. }
  8338. /*
  8339. * Process all the event on FCP slow-path EQ
  8340. */
  8341. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8342. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8343. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8344. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8345. }
  8346. /* Always clear and re-arm the slow-path EQ */
  8347. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8348. /* Catch the no cq entry condition */
  8349. if (unlikely(ecount == 0)) {
  8350. if (phba->intr_type == MSIX)
  8351. /* MSI-X treated interrupt served as no EQ share INT */
  8352. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8353. "0357 MSI-X interrupt with no EQE\n");
  8354. else
  8355. /* Non MSI-X treated on interrupt as EQ share INT */
  8356. return IRQ_NONE;
  8357. }
  8358. return IRQ_HANDLED;
  8359. } /* lpfc_sli4_sp_intr_handler */
  8360. /**
  8361. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8362. * @irq: Interrupt number.
  8363. * @dev_id: The device context pointer.
  8364. *
  8365. * This function is directly called from the PCI layer as an interrupt
  8366. * service routine when device with SLI-4 interface spec is enabled with
  8367. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8368. * ring event in the HBA. However, when the device is enabled with either
  8369. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8370. * device-level interrupt handler. When the PCI slot is in error recovery
  8371. * or the HBA is undergoing initialization, the interrupt handler will not
  8372. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8373. * the intrrupt context. This function is called without any lock held.
  8374. * It gets the hbalock to access and update SLI data structures. Note that,
  8375. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8376. * equal to that of FCP CQ index.
  8377. *
  8378. * This function returns IRQ_HANDLED when interrupt is handled else it
  8379. * returns IRQ_NONE.
  8380. **/
  8381. irqreturn_t
  8382. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8383. {
  8384. struct lpfc_hba *phba;
  8385. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8386. struct lpfc_queue *fpeq;
  8387. struct lpfc_eqe *eqe;
  8388. unsigned long iflag;
  8389. int ecount = 0;
  8390. uint32_t fcp_eqidx;
  8391. /* Get the driver's phba structure from the dev_id */
  8392. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8393. phba = fcp_eq_hdl->phba;
  8394. fcp_eqidx = fcp_eq_hdl->idx;
  8395. if (unlikely(!phba))
  8396. return IRQ_NONE;
  8397. /* Get to the EQ struct associated with this vector */
  8398. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8399. /* Check device state for handling interrupt */
  8400. if (unlikely(lpfc_intr_state_check(phba))) {
  8401. /* Check again for link_state with lock held */
  8402. spin_lock_irqsave(&phba->hbalock, iflag);
  8403. if (phba->link_state < LPFC_LINK_DOWN)
  8404. /* Flush, clear interrupt, and rearm the EQ */
  8405. lpfc_sli4_eq_flush(phba, fpeq);
  8406. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8407. return IRQ_NONE;
  8408. }
  8409. /*
  8410. * Process all the event on FCP fast-path EQ
  8411. */
  8412. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8413. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8414. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8415. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8416. }
  8417. /* Always clear and re-arm the fast-path EQ */
  8418. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8419. if (unlikely(ecount == 0)) {
  8420. if (phba->intr_type == MSIX)
  8421. /* MSI-X treated interrupt served as no EQ share INT */
  8422. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8423. "0358 MSI-X interrupt with no EQE\n");
  8424. else
  8425. /* Non MSI-X treated on interrupt as EQ share INT */
  8426. return IRQ_NONE;
  8427. }
  8428. return IRQ_HANDLED;
  8429. } /* lpfc_sli4_fp_intr_handler */
  8430. /**
  8431. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8432. * @irq: Interrupt number.
  8433. * @dev_id: The device context pointer.
  8434. *
  8435. * This function is the device-level interrupt handler to device with SLI-4
  8436. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8437. * interrupt mode is enabled and there is an event in the HBA which requires
  8438. * driver attention. This function invokes the slow-path interrupt attention
  8439. * handling function and fast-path interrupt attention handling function in
  8440. * turn to process the relevant HBA attention events. This function is called
  8441. * without any lock held. It gets the hbalock to access and update SLI data
  8442. * structures.
  8443. *
  8444. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8445. * returns IRQ_NONE.
  8446. **/
  8447. irqreturn_t
  8448. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8449. {
  8450. struct lpfc_hba *phba;
  8451. irqreturn_t sp_irq_rc, fp_irq_rc;
  8452. bool fp_handled = false;
  8453. uint32_t fcp_eqidx;
  8454. /* Get the driver's phba structure from the dev_id */
  8455. phba = (struct lpfc_hba *)dev_id;
  8456. if (unlikely(!phba))
  8457. return IRQ_NONE;
  8458. /*
  8459. * Invokes slow-path host attention interrupt handling as appropriate.
  8460. */
  8461. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8462. /*
  8463. * Invoke fast-path host attention interrupt handling as appropriate.
  8464. */
  8465. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8466. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8467. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8468. if (fp_irq_rc == IRQ_HANDLED)
  8469. fp_handled |= true;
  8470. }
  8471. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8472. } /* lpfc_sli4_intr_handler */
  8473. /**
  8474. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8475. * @queue: The queue structure to free.
  8476. *
  8477. * This function frees a queue structure and the DMAable memeory used for
  8478. * the host resident queue. This function must be called after destroying the
  8479. * queue on the HBA.
  8480. **/
  8481. void
  8482. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8483. {
  8484. struct lpfc_dmabuf *dmabuf;
  8485. if (!queue)
  8486. return;
  8487. while (!list_empty(&queue->page_list)) {
  8488. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8489. list);
  8490. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8491. dmabuf->virt, dmabuf->phys);
  8492. kfree(dmabuf);
  8493. }
  8494. kfree(queue);
  8495. return;
  8496. }
  8497. /**
  8498. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8499. * @phba: The HBA that this queue is being created on.
  8500. * @entry_size: The size of each queue entry for this queue.
  8501. * @entry count: The number of entries that this queue will handle.
  8502. *
  8503. * This function allocates a queue structure and the DMAable memory used for
  8504. * the host resident queue. This function must be called before creating the
  8505. * queue on the HBA.
  8506. **/
  8507. struct lpfc_queue *
  8508. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8509. uint32_t entry_count)
  8510. {
  8511. struct lpfc_queue *queue;
  8512. struct lpfc_dmabuf *dmabuf;
  8513. int x, total_qe_count;
  8514. void *dma_pointer;
  8515. queue = kzalloc(sizeof(struct lpfc_queue) +
  8516. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8517. if (!queue)
  8518. return NULL;
  8519. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8520. INIT_LIST_HEAD(&queue->list);
  8521. INIT_LIST_HEAD(&queue->page_list);
  8522. INIT_LIST_HEAD(&queue->child_list);
  8523. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8524. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8525. if (!dmabuf)
  8526. goto out_fail;
  8527. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8528. PAGE_SIZE, &dmabuf->phys,
  8529. GFP_KERNEL);
  8530. if (!dmabuf->virt) {
  8531. kfree(dmabuf);
  8532. goto out_fail;
  8533. }
  8534. memset(dmabuf->virt, 0, PAGE_SIZE);
  8535. dmabuf->buffer_tag = x;
  8536. list_add_tail(&dmabuf->list, &queue->page_list);
  8537. /* initialize queue's entry array */
  8538. dma_pointer = dmabuf->virt;
  8539. for (; total_qe_count < entry_count &&
  8540. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8541. total_qe_count++, dma_pointer += entry_size) {
  8542. queue->qe[total_qe_count].address = dma_pointer;
  8543. }
  8544. }
  8545. queue->entry_size = entry_size;
  8546. queue->entry_count = entry_count;
  8547. queue->phba = phba;
  8548. return queue;
  8549. out_fail:
  8550. lpfc_sli4_queue_free(queue);
  8551. return NULL;
  8552. }
  8553. /**
  8554. * lpfc_eq_create - Create an Event Queue on the HBA
  8555. * @phba: HBA structure that indicates port to create a queue on.
  8556. * @eq: The queue structure to use to create the event queue.
  8557. * @imax: The maximum interrupt per second limit.
  8558. *
  8559. * This function creates an event queue, as detailed in @eq, on a port,
  8560. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8561. *
  8562. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8563. * is used to get the entry count and entry size that are necessary to
  8564. * determine the number of pages to allocate and use for this queue. This
  8565. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8566. * event queue. This function is asynchronous and will wait for the mailbox
  8567. * command to finish before continuing.
  8568. *
  8569. * On success this function will return a zero. If unable to allocate enough
  8570. * memory this function will return ENOMEM. If the queue create mailbox command
  8571. * fails this function will return ENXIO.
  8572. **/
  8573. uint32_t
  8574. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8575. {
  8576. struct lpfc_mbx_eq_create *eq_create;
  8577. LPFC_MBOXQ_t *mbox;
  8578. int rc, length, status = 0;
  8579. struct lpfc_dmabuf *dmabuf;
  8580. uint32_t shdr_status, shdr_add_status;
  8581. union lpfc_sli4_cfg_shdr *shdr;
  8582. uint16_t dmult;
  8583. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8584. if (!mbox)
  8585. return -ENOMEM;
  8586. length = (sizeof(struct lpfc_mbx_eq_create) -
  8587. sizeof(struct lpfc_sli4_cfg_mhdr));
  8588. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8589. LPFC_MBOX_OPCODE_EQ_CREATE,
  8590. length, LPFC_SLI4_MBX_EMBED);
  8591. eq_create = &mbox->u.mqe.un.eq_create;
  8592. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8593. eq->page_count);
  8594. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8595. LPFC_EQE_SIZE);
  8596. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8597. /* Calculate delay multiper from maximum interrupt per second */
  8598. dmult = LPFC_DMULT_CONST/imax - 1;
  8599. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8600. dmult);
  8601. switch (eq->entry_count) {
  8602. default:
  8603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8604. "0360 Unsupported EQ count. (%d)\n",
  8605. eq->entry_count);
  8606. if (eq->entry_count < 256)
  8607. return -EINVAL;
  8608. /* otherwise default to smallest count (drop through) */
  8609. case 256:
  8610. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8611. LPFC_EQ_CNT_256);
  8612. break;
  8613. case 512:
  8614. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8615. LPFC_EQ_CNT_512);
  8616. break;
  8617. case 1024:
  8618. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8619. LPFC_EQ_CNT_1024);
  8620. break;
  8621. case 2048:
  8622. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8623. LPFC_EQ_CNT_2048);
  8624. break;
  8625. case 4096:
  8626. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8627. LPFC_EQ_CNT_4096);
  8628. break;
  8629. }
  8630. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8631. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8632. putPaddrLow(dmabuf->phys);
  8633. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8634. putPaddrHigh(dmabuf->phys);
  8635. }
  8636. mbox->vport = phba->pport;
  8637. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8638. mbox->context1 = NULL;
  8639. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8640. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8641. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8642. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8643. if (shdr_status || shdr_add_status || rc) {
  8644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8645. "2500 EQ_CREATE mailbox failed with "
  8646. "status x%x add_status x%x, mbx status x%x\n",
  8647. shdr_status, shdr_add_status, rc);
  8648. status = -ENXIO;
  8649. }
  8650. eq->type = LPFC_EQ;
  8651. eq->subtype = LPFC_NONE;
  8652. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8653. if (eq->queue_id == 0xFFFF)
  8654. status = -ENXIO;
  8655. eq->host_index = 0;
  8656. eq->hba_index = 0;
  8657. mempool_free(mbox, phba->mbox_mem_pool);
  8658. return status;
  8659. }
  8660. /**
  8661. * lpfc_cq_create - Create a Completion Queue on the HBA
  8662. * @phba: HBA structure that indicates port to create a queue on.
  8663. * @cq: The queue structure to use to create the completion queue.
  8664. * @eq: The event queue to bind this completion queue to.
  8665. *
  8666. * This function creates a completion queue, as detailed in @wq, on a port,
  8667. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8668. *
  8669. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8670. * is used to get the entry count and entry size that are necessary to
  8671. * determine the number of pages to allocate and use for this queue. The @eq
  8672. * is used to indicate which event queue to bind this completion queue to. This
  8673. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8674. * completion queue. This function is asynchronous and will wait for the mailbox
  8675. * command to finish before continuing.
  8676. *
  8677. * On success this function will return a zero. If unable to allocate enough
  8678. * memory this function will return ENOMEM. If the queue create mailbox command
  8679. * fails this function will return ENXIO.
  8680. **/
  8681. uint32_t
  8682. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8683. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8684. {
  8685. struct lpfc_mbx_cq_create *cq_create;
  8686. struct lpfc_dmabuf *dmabuf;
  8687. LPFC_MBOXQ_t *mbox;
  8688. int rc, length, status = 0;
  8689. uint32_t shdr_status, shdr_add_status;
  8690. union lpfc_sli4_cfg_shdr *shdr;
  8691. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8692. if (!mbox)
  8693. return -ENOMEM;
  8694. length = (sizeof(struct lpfc_mbx_cq_create) -
  8695. sizeof(struct lpfc_sli4_cfg_mhdr));
  8696. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8697. LPFC_MBOX_OPCODE_CQ_CREATE,
  8698. length, LPFC_SLI4_MBX_EMBED);
  8699. cq_create = &mbox->u.mqe.un.cq_create;
  8700. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8701. cq->page_count);
  8702. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8703. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8704. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8705. switch (cq->entry_count) {
  8706. default:
  8707. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8708. "0361 Unsupported CQ count. (%d)\n",
  8709. cq->entry_count);
  8710. if (cq->entry_count < 256)
  8711. return -EINVAL;
  8712. /* otherwise default to smallest count (drop through) */
  8713. case 256:
  8714. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8715. LPFC_CQ_CNT_256);
  8716. break;
  8717. case 512:
  8718. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8719. LPFC_CQ_CNT_512);
  8720. break;
  8721. case 1024:
  8722. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8723. LPFC_CQ_CNT_1024);
  8724. break;
  8725. }
  8726. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8727. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8728. putPaddrLow(dmabuf->phys);
  8729. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8730. putPaddrHigh(dmabuf->phys);
  8731. }
  8732. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8733. /* The IOCTL status is embedded in the mailbox subheader. */
  8734. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8735. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8736. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8737. if (shdr_status || shdr_add_status || rc) {
  8738. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8739. "2501 CQ_CREATE mailbox failed with "
  8740. "status x%x add_status x%x, mbx status x%x\n",
  8741. shdr_status, shdr_add_status, rc);
  8742. status = -ENXIO;
  8743. goto out;
  8744. }
  8745. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8746. if (cq->queue_id == 0xFFFF) {
  8747. status = -ENXIO;
  8748. goto out;
  8749. }
  8750. /* link the cq onto the parent eq child list */
  8751. list_add_tail(&cq->list, &eq->child_list);
  8752. /* Set up completion queue's type and subtype */
  8753. cq->type = type;
  8754. cq->subtype = subtype;
  8755. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8756. cq->host_index = 0;
  8757. cq->hba_index = 0;
  8758. out:
  8759. mempool_free(mbox, phba->mbox_mem_pool);
  8760. return status;
  8761. }
  8762. /**
  8763. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8764. * @phba: HBA structure that indicates port to create a queue on.
  8765. * @mq: The queue structure to use to create the mailbox queue.
  8766. *
  8767. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8768. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8769. *
  8770. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8771. * is used to get the entry count and entry size that are necessary to
  8772. * determine the number of pages to allocate and use for this queue. This
  8773. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8774. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8775. * command to finish before continuing.
  8776. *
  8777. * On success this function will return a zero. If unable to allocate enough
  8778. * memory this function will return ENOMEM. If the queue create mailbox command
  8779. * fails this function will return ENXIO.
  8780. **/
  8781. uint32_t
  8782. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8783. struct lpfc_queue *cq, uint32_t subtype)
  8784. {
  8785. struct lpfc_mbx_mq_create *mq_create;
  8786. struct lpfc_dmabuf *dmabuf;
  8787. LPFC_MBOXQ_t *mbox;
  8788. int rc, length, status = 0;
  8789. uint32_t shdr_status, shdr_add_status;
  8790. union lpfc_sli4_cfg_shdr *shdr;
  8791. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8792. if (!mbox)
  8793. return -ENOMEM;
  8794. length = (sizeof(struct lpfc_mbx_mq_create) -
  8795. sizeof(struct lpfc_sli4_cfg_mhdr));
  8796. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8797. LPFC_MBOX_OPCODE_MQ_CREATE,
  8798. length, LPFC_SLI4_MBX_EMBED);
  8799. mq_create = &mbox->u.mqe.un.mq_create;
  8800. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8801. mq->page_count);
  8802. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8803. cq->queue_id);
  8804. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8805. switch (mq->entry_count) {
  8806. default:
  8807. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8808. "0362 Unsupported MQ count. (%d)\n",
  8809. mq->entry_count);
  8810. if (mq->entry_count < 16)
  8811. return -EINVAL;
  8812. /* otherwise default to smallest count (drop through) */
  8813. case 16:
  8814. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8815. LPFC_MQ_CNT_16);
  8816. break;
  8817. case 32:
  8818. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8819. LPFC_MQ_CNT_32);
  8820. break;
  8821. case 64:
  8822. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8823. LPFC_MQ_CNT_64);
  8824. break;
  8825. case 128:
  8826. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8827. LPFC_MQ_CNT_128);
  8828. break;
  8829. }
  8830. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8831. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8832. putPaddrLow(dmabuf->phys);
  8833. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8834. putPaddrHigh(dmabuf->phys);
  8835. }
  8836. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8837. /* The IOCTL status is embedded in the mailbox subheader. */
  8838. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8839. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8840. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8841. if (shdr_status || shdr_add_status || rc) {
  8842. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8843. "2502 MQ_CREATE mailbox failed with "
  8844. "status x%x add_status x%x, mbx status x%x\n",
  8845. shdr_status, shdr_add_status, rc);
  8846. status = -ENXIO;
  8847. goto out;
  8848. }
  8849. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8850. if (mq->queue_id == 0xFFFF) {
  8851. status = -ENXIO;
  8852. goto out;
  8853. }
  8854. mq->type = LPFC_MQ;
  8855. mq->subtype = subtype;
  8856. mq->host_index = 0;
  8857. mq->hba_index = 0;
  8858. /* link the mq onto the parent cq child list */
  8859. list_add_tail(&mq->list, &cq->child_list);
  8860. out:
  8861. mempool_free(mbox, phba->mbox_mem_pool);
  8862. return status;
  8863. }
  8864. /**
  8865. * lpfc_wq_create - Create a Work Queue on the HBA
  8866. * @phba: HBA structure that indicates port to create a queue on.
  8867. * @wq: The queue structure to use to create the work queue.
  8868. * @cq: The completion queue to bind this work queue to.
  8869. * @subtype: The subtype of the work queue indicating its functionality.
  8870. *
  8871. * This function creates a work queue, as detailed in @wq, on a port, described
  8872. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8873. *
  8874. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8875. * is used to get the entry count and entry size that are necessary to
  8876. * determine the number of pages to allocate and use for this queue. The @cq
  8877. * is used to indicate which completion queue to bind this work queue to. This
  8878. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8879. * work queue. This function is asynchronous and will wait for the mailbox
  8880. * command to finish before continuing.
  8881. *
  8882. * On success this function will return a zero. If unable to allocate enough
  8883. * memory this function will return ENOMEM. If the queue create mailbox command
  8884. * fails this function will return ENXIO.
  8885. **/
  8886. uint32_t
  8887. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8888. struct lpfc_queue *cq, uint32_t subtype)
  8889. {
  8890. struct lpfc_mbx_wq_create *wq_create;
  8891. struct lpfc_dmabuf *dmabuf;
  8892. LPFC_MBOXQ_t *mbox;
  8893. int rc, length, status = 0;
  8894. uint32_t shdr_status, shdr_add_status;
  8895. union lpfc_sli4_cfg_shdr *shdr;
  8896. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8897. if (!mbox)
  8898. return -ENOMEM;
  8899. length = (sizeof(struct lpfc_mbx_wq_create) -
  8900. sizeof(struct lpfc_sli4_cfg_mhdr));
  8901. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8902. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8903. length, LPFC_SLI4_MBX_EMBED);
  8904. wq_create = &mbox->u.mqe.un.wq_create;
  8905. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8906. wq->page_count);
  8907. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8908. cq->queue_id);
  8909. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8910. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8911. putPaddrLow(dmabuf->phys);
  8912. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8913. putPaddrHigh(dmabuf->phys);
  8914. }
  8915. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8916. /* The IOCTL status is embedded in the mailbox subheader. */
  8917. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8918. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8919. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8920. if (shdr_status || shdr_add_status || rc) {
  8921. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8922. "2503 WQ_CREATE mailbox failed with "
  8923. "status x%x add_status x%x, mbx status x%x\n",
  8924. shdr_status, shdr_add_status, rc);
  8925. status = -ENXIO;
  8926. goto out;
  8927. }
  8928. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8929. if (wq->queue_id == 0xFFFF) {
  8930. status = -ENXIO;
  8931. goto out;
  8932. }
  8933. wq->type = LPFC_WQ;
  8934. wq->subtype = subtype;
  8935. wq->host_index = 0;
  8936. wq->hba_index = 0;
  8937. /* link the wq onto the parent cq child list */
  8938. list_add_tail(&wq->list, &cq->child_list);
  8939. out:
  8940. mempool_free(mbox, phba->mbox_mem_pool);
  8941. return status;
  8942. }
  8943. /**
  8944. * lpfc_rq_create - Create a Receive Queue on the HBA
  8945. * @phba: HBA structure that indicates port to create a queue on.
  8946. * @hrq: The queue structure to use to create the header receive queue.
  8947. * @drq: The queue structure to use to create the data receive queue.
  8948. * @cq: The completion queue to bind this work queue to.
  8949. *
  8950. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8951. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8952. * to the HBA.
  8953. *
  8954. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8955. * struct is used to get the entry count that is necessary to determine the
  8956. * number of pages to use for this queue. The @cq is used to indicate which
  8957. * completion queue to bind received buffers that are posted to these queues to.
  8958. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8959. * receive queue pair. This function is asynchronous and will wait for the
  8960. * mailbox command to finish before continuing.
  8961. *
  8962. * On success this function will return a zero. If unable to allocate enough
  8963. * memory this function will return ENOMEM. If the queue create mailbox command
  8964. * fails this function will return ENXIO.
  8965. **/
  8966. uint32_t
  8967. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8968. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8969. {
  8970. struct lpfc_mbx_rq_create *rq_create;
  8971. struct lpfc_dmabuf *dmabuf;
  8972. LPFC_MBOXQ_t *mbox;
  8973. int rc, length, status = 0;
  8974. uint32_t shdr_status, shdr_add_status;
  8975. union lpfc_sli4_cfg_shdr *shdr;
  8976. if (hrq->entry_count != drq->entry_count)
  8977. return -EINVAL;
  8978. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8979. if (!mbox)
  8980. return -ENOMEM;
  8981. length = (sizeof(struct lpfc_mbx_rq_create) -
  8982. sizeof(struct lpfc_sli4_cfg_mhdr));
  8983. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8984. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8985. length, LPFC_SLI4_MBX_EMBED);
  8986. rq_create = &mbox->u.mqe.un.rq_create;
  8987. switch (hrq->entry_count) {
  8988. default:
  8989. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8990. "2535 Unsupported RQ count. (%d)\n",
  8991. hrq->entry_count);
  8992. if (hrq->entry_count < 512)
  8993. return -EINVAL;
  8994. /* otherwise default to smallest count (drop through) */
  8995. case 512:
  8996. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8997. LPFC_RQ_RING_SIZE_512);
  8998. break;
  8999. case 1024:
  9000. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9001. LPFC_RQ_RING_SIZE_1024);
  9002. break;
  9003. case 2048:
  9004. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9005. LPFC_RQ_RING_SIZE_2048);
  9006. break;
  9007. case 4096:
  9008. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9009. LPFC_RQ_RING_SIZE_4096);
  9010. break;
  9011. }
  9012. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9013. cq->queue_id);
  9014. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9015. hrq->page_count);
  9016. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9017. LPFC_HDR_BUF_SIZE);
  9018. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9019. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9020. putPaddrLow(dmabuf->phys);
  9021. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9022. putPaddrHigh(dmabuf->phys);
  9023. }
  9024. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9025. /* The IOCTL status is embedded in the mailbox subheader. */
  9026. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9027. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9028. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9029. if (shdr_status || shdr_add_status || rc) {
  9030. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9031. "2504 RQ_CREATE mailbox failed with "
  9032. "status x%x add_status x%x, mbx status x%x\n",
  9033. shdr_status, shdr_add_status, rc);
  9034. status = -ENXIO;
  9035. goto out;
  9036. }
  9037. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9038. if (hrq->queue_id == 0xFFFF) {
  9039. status = -ENXIO;
  9040. goto out;
  9041. }
  9042. hrq->type = LPFC_HRQ;
  9043. hrq->subtype = subtype;
  9044. hrq->host_index = 0;
  9045. hrq->hba_index = 0;
  9046. /* now create the data queue */
  9047. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9048. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9049. length, LPFC_SLI4_MBX_EMBED);
  9050. switch (drq->entry_count) {
  9051. default:
  9052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9053. "2536 Unsupported RQ count. (%d)\n",
  9054. drq->entry_count);
  9055. if (drq->entry_count < 512)
  9056. return -EINVAL;
  9057. /* otherwise default to smallest count (drop through) */
  9058. case 512:
  9059. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9060. LPFC_RQ_RING_SIZE_512);
  9061. break;
  9062. case 1024:
  9063. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9064. LPFC_RQ_RING_SIZE_1024);
  9065. break;
  9066. case 2048:
  9067. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9068. LPFC_RQ_RING_SIZE_2048);
  9069. break;
  9070. case 4096:
  9071. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9072. LPFC_RQ_RING_SIZE_4096);
  9073. break;
  9074. }
  9075. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9076. cq->queue_id);
  9077. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9078. drq->page_count);
  9079. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9080. LPFC_DATA_BUF_SIZE);
  9081. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9082. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9083. putPaddrLow(dmabuf->phys);
  9084. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9085. putPaddrHigh(dmabuf->phys);
  9086. }
  9087. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9088. /* The IOCTL status is embedded in the mailbox subheader. */
  9089. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9090. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9091. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9092. if (shdr_status || shdr_add_status || rc) {
  9093. status = -ENXIO;
  9094. goto out;
  9095. }
  9096. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9097. if (drq->queue_id == 0xFFFF) {
  9098. status = -ENXIO;
  9099. goto out;
  9100. }
  9101. drq->type = LPFC_DRQ;
  9102. drq->subtype = subtype;
  9103. drq->host_index = 0;
  9104. drq->hba_index = 0;
  9105. /* link the header and data RQs onto the parent cq child list */
  9106. list_add_tail(&hrq->list, &cq->child_list);
  9107. list_add_tail(&drq->list, &cq->child_list);
  9108. out:
  9109. mempool_free(mbox, phba->mbox_mem_pool);
  9110. return status;
  9111. }
  9112. /**
  9113. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9114. * @eq: The queue structure associated with the queue to destroy.
  9115. *
  9116. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9117. * command, specific to the type of queue, to the HBA.
  9118. *
  9119. * The @eq struct is used to get the queue ID of the queue to destroy.
  9120. *
  9121. * On success this function will return a zero. If the queue destroy mailbox
  9122. * command fails this function will return ENXIO.
  9123. **/
  9124. uint32_t
  9125. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9126. {
  9127. LPFC_MBOXQ_t *mbox;
  9128. int rc, length, status = 0;
  9129. uint32_t shdr_status, shdr_add_status;
  9130. union lpfc_sli4_cfg_shdr *shdr;
  9131. if (!eq)
  9132. return -ENODEV;
  9133. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9134. if (!mbox)
  9135. return -ENOMEM;
  9136. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9137. sizeof(struct lpfc_sli4_cfg_mhdr));
  9138. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9139. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9140. length, LPFC_SLI4_MBX_EMBED);
  9141. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9142. eq->queue_id);
  9143. mbox->vport = eq->phba->pport;
  9144. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9145. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9146. /* The IOCTL status is embedded in the mailbox subheader. */
  9147. shdr = (union lpfc_sli4_cfg_shdr *)
  9148. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9149. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9150. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9151. if (shdr_status || shdr_add_status || rc) {
  9152. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9153. "2505 EQ_DESTROY mailbox failed with "
  9154. "status x%x add_status x%x, mbx status x%x\n",
  9155. shdr_status, shdr_add_status, rc);
  9156. status = -ENXIO;
  9157. }
  9158. /* Remove eq from any list */
  9159. list_del_init(&eq->list);
  9160. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9161. return status;
  9162. }
  9163. /**
  9164. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9165. * @cq: The queue structure associated with the queue to destroy.
  9166. *
  9167. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9168. * command, specific to the type of queue, to the HBA.
  9169. *
  9170. * The @cq struct is used to get the queue ID of the queue to destroy.
  9171. *
  9172. * On success this function will return a zero. If the queue destroy mailbox
  9173. * command fails this function will return ENXIO.
  9174. **/
  9175. uint32_t
  9176. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9177. {
  9178. LPFC_MBOXQ_t *mbox;
  9179. int rc, length, status = 0;
  9180. uint32_t shdr_status, shdr_add_status;
  9181. union lpfc_sli4_cfg_shdr *shdr;
  9182. if (!cq)
  9183. return -ENODEV;
  9184. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9185. if (!mbox)
  9186. return -ENOMEM;
  9187. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9188. sizeof(struct lpfc_sli4_cfg_mhdr));
  9189. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9190. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9191. length, LPFC_SLI4_MBX_EMBED);
  9192. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9193. cq->queue_id);
  9194. mbox->vport = cq->phba->pport;
  9195. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9196. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9197. /* The IOCTL status is embedded in the mailbox subheader. */
  9198. shdr = (union lpfc_sli4_cfg_shdr *)
  9199. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9200. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9201. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9202. if (shdr_status || shdr_add_status || rc) {
  9203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9204. "2506 CQ_DESTROY mailbox failed with "
  9205. "status x%x add_status x%x, mbx status x%x\n",
  9206. shdr_status, shdr_add_status, rc);
  9207. status = -ENXIO;
  9208. }
  9209. /* Remove cq from any list */
  9210. list_del_init(&cq->list);
  9211. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9212. return status;
  9213. }
  9214. /**
  9215. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9216. * @qm: The queue structure associated with the queue to destroy.
  9217. *
  9218. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9219. * command, specific to the type of queue, to the HBA.
  9220. *
  9221. * The @mq struct is used to get the queue ID of the queue to destroy.
  9222. *
  9223. * On success this function will return a zero. If the queue destroy mailbox
  9224. * command fails this function will return ENXIO.
  9225. **/
  9226. uint32_t
  9227. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9228. {
  9229. LPFC_MBOXQ_t *mbox;
  9230. int rc, length, status = 0;
  9231. uint32_t shdr_status, shdr_add_status;
  9232. union lpfc_sli4_cfg_shdr *shdr;
  9233. if (!mq)
  9234. return -ENODEV;
  9235. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9236. if (!mbox)
  9237. return -ENOMEM;
  9238. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9239. sizeof(struct lpfc_sli4_cfg_mhdr));
  9240. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9241. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9242. length, LPFC_SLI4_MBX_EMBED);
  9243. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9244. mq->queue_id);
  9245. mbox->vport = mq->phba->pport;
  9246. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9247. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9248. /* The IOCTL status is embedded in the mailbox subheader. */
  9249. shdr = (union lpfc_sli4_cfg_shdr *)
  9250. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9251. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9252. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9253. if (shdr_status || shdr_add_status || rc) {
  9254. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9255. "2507 MQ_DESTROY mailbox failed with "
  9256. "status x%x add_status x%x, mbx status x%x\n",
  9257. shdr_status, shdr_add_status, rc);
  9258. status = -ENXIO;
  9259. }
  9260. /* Remove mq from any list */
  9261. list_del_init(&mq->list);
  9262. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9263. return status;
  9264. }
  9265. /**
  9266. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9267. * @wq: The queue structure associated with the queue to destroy.
  9268. *
  9269. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9270. * command, specific to the type of queue, to the HBA.
  9271. *
  9272. * The @wq struct is used to get the queue ID of the queue to destroy.
  9273. *
  9274. * On success this function will return a zero. If the queue destroy mailbox
  9275. * command fails this function will return ENXIO.
  9276. **/
  9277. uint32_t
  9278. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9279. {
  9280. LPFC_MBOXQ_t *mbox;
  9281. int rc, length, status = 0;
  9282. uint32_t shdr_status, shdr_add_status;
  9283. union lpfc_sli4_cfg_shdr *shdr;
  9284. if (!wq)
  9285. return -ENODEV;
  9286. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9287. if (!mbox)
  9288. return -ENOMEM;
  9289. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9290. sizeof(struct lpfc_sli4_cfg_mhdr));
  9291. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9292. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9293. length, LPFC_SLI4_MBX_EMBED);
  9294. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9295. wq->queue_id);
  9296. mbox->vport = wq->phba->pport;
  9297. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9298. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9299. shdr = (union lpfc_sli4_cfg_shdr *)
  9300. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9301. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9302. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9303. if (shdr_status || shdr_add_status || rc) {
  9304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9305. "2508 WQ_DESTROY mailbox failed with "
  9306. "status x%x add_status x%x, mbx status x%x\n",
  9307. shdr_status, shdr_add_status, rc);
  9308. status = -ENXIO;
  9309. }
  9310. /* Remove wq from any list */
  9311. list_del_init(&wq->list);
  9312. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9313. return status;
  9314. }
  9315. /**
  9316. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9317. * @rq: The queue structure associated with the queue to destroy.
  9318. *
  9319. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9320. * command, specific to the type of queue, to the HBA.
  9321. *
  9322. * The @rq struct is used to get the queue ID of the queue to destroy.
  9323. *
  9324. * On success this function will return a zero. If the queue destroy mailbox
  9325. * command fails this function will return ENXIO.
  9326. **/
  9327. uint32_t
  9328. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9329. struct lpfc_queue *drq)
  9330. {
  9331. LPFC_MBOXQ_t *mbox;
  9332. int rc, length, status = 0;
  9333. uint32_t shdr_status, shdr_add_status;
  9334. union lpfc_sli4_cfg_shdr *shdr;
  9335. if (!hrq || !drq)
  9336. return -ENODEV;
  9337. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9338. if (!mbox)
  9339. return -ENOMEM;
  9340. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9341. sizeof(struct mbox_header));
  9342. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9343. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9344. length, LPFC_SLI4_MBX_EMBED);
  9345. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9346. hrq->queue_id);
  9347. mbox->vport = hrq->phba->pport;
  9348. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9349. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9350. /* The IOCTL status is embedded in the mailbox subheader. */
  9351. shdr = (union lpfc_sli4_cfg_shdr *)
  9352. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9353. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9354. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9355. if (shdr_status || shdr_add_status || rc) {
  9356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9357. "2509 RQ_DESTROY mailbox failed with "
  9358. "status x%x add_status x%x, mbx status x%x\n",
  9359. shdr_status, shdr_add_status, rc);
  9360. if (rc != MBX_TIMEOUT)
  9361. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9362. return -ENXIO;
  9363. }
  9364. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9365. drq->queue_id);
  9366. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9367. shdr = (union lpfc_sli4_cfg_shdr *)
  9368. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9369. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9370. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9371. if (shdr_status || shdr_add_status || rc) {
  9372. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9373. "2510 RQ_DESTROY mailbox failed with "
  9374. "status x%x add_status x%x, mbx status x%x\n",
  9375. shdr_status, shdr_add_status, rc);
  9376. status = -ENXIO;
  9377. }
  9378. list_del_init(&hrq->list);
  9379. list_del_init(&drq->list);
  9380. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9381. return status;
  9382. }
  9383. /**
  9384. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9385. * @phba: The virtual port for which this call being executed.
  9386. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9387. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9388. * @xritag: the xritag that ties this io to the SGL pages.
  9389. *
  9390. * This routine will post the sgl pages for the IO that has the xritag
  9391. * that is in the iocbq structure. The xritag is assigned during iocbq
  9392. * creation and persists for as long as the driver is loaded.
  9393. * if the caller has fewer than 256 scatter gather segments to map then
  9394. * pdma_phys_addr1 should be 0.
  9395. * If the caller needs to map more than 256 scatter gather segment then
  9396. * pdma_phys_addr1 should be a valid physical address.
  9397. * physical address for SGLs must be 64 byte aligned.
  9398. * If you are going to map 2 SGL's then the first one must have 256 entries
  9399. * the second sgl can have between 1 and 256 entries.
  9400. *
  9401. * Return codes:
  9402. * 0 - Success
  9403. * -ENXIO, -ENOMEM - Failure
  9404. **/
  9405. int
  9406. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9407. dma_addr_t pdma_phys_addr0,
  9408. dma_addr_t pdma_phys_addr1,
  9409. uint16_t xritag)
  9410. {
  9411. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9412. LPFC_MBOXQ_t *mbox;
  9413. int rc;
  9414. uint32_t shdr_status, shdr_add_status;
  9415. union lpfc_sli4_cfg_shdr *shdr;
  9416. if (xritag == NO_XRI) {
  9417. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9418. "0364 Invalid param:\n");
  9419. return -EINVAL;
  9420. }
  9421. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9422. if (!mbox)
  9423. return -ENOMEM;
  9424. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9425. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9426. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9427. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9428. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9429. &mbox->u.mqe.un.post_sgl_pages;
  9430. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9431. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9432. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9433. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9434. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9435. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9436. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9437. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9438. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9439. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9440. if (!phba->sli4_hba.intr_enable)
  9441. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9442. else
  9443. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9444. /* The IOCTL status is embedded in the mailbox subheader. */
  9445. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9446. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9447. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9448. if (rc != MBX_TIMEOUT)
  9449. mempool_free(mbox, phba->mbox_mem_pool);
  9450. if (shdr_status || shdr_add_status || rc) {
  9451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9452. "2511 POST_SGL mailbox failed with "
  9453. "status x%x add_status x%x, mbx status x%x\n",
  9454. shdr_status, shdr_add_status, rc);
  9455. rc = -ENXIO;
  9456. }
  9457. return 0;
  9458. }
  9459. /**
  9460. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9461. * @phba: The virtual port for which this call being executed.
  9462. *
  9463. * This routine will remove all of the sgl pages registered with the hba.
  9464. *
  9465. * Return codes:
  9466. * 0 - Success
  9467. * -ENXIO, -ENOMEM - Failure
  9468. **/
  9469. int
  9470. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9471. {
  9472. LPFC_MBOXQ_t *mbox;
  9473. int rc;
  9474. uint32_t shdr_status, shdr_add_status;
  9475. union lpfc_sli4_cfg_shdr *shdr;
  9476. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9477. if (!mbox)
  9478. return -ENOMEM;
  9479. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9480. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9481. LPFC_SLI4_MBX_EMBED);
  9482. if (!phba->sli4_hba.intr_enable)
  9483. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9484. else
  9485. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9486. /* The IOCTL status is embedded in the mailbox subheader. */
  9487. shdr = (union lpfc_sli4_cfg_shdr *)
  9488. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9489. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9490. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9491. if (rc != MBX_TIMEOUT)
  9492. mempool_free(mbox, phba->mbox_mem_pool);
  9493. if (shdr_status || shdr_add_status || rc) {
  9494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9495. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9496. "status x%x add_status x%x, mbx status x%x\n",
  9497. shdr_status, shdr_add_status, rc);
  9498. rc = -ENXIO;
  9499. }
  9500. return rc;
  9501. }
  9502. /**
  9503. * lpfc_sli4_next_xritag - Get an xritag for the io
  9504. * @phba: Pointer to HBA context object.
  9505. *
  9506. * This function gets an xritag for the iocb. If there is no unused xritag
  9507. * it will return 0xffff.
  9508. * The function returns the allocated xritag if successful, else returns zero.
  9509. * Zero is not a valid xritag.
  9510. * The caller is not required to hold any lock.
  9511. **/
  9512. uint16_t
  9513. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9514. {
  9515. uint16_t xritag;
  9516. spin_lock_irq(&phba->hbalock);
  9517. xritag = phba->sli4_hba.next_xri;
  9518. if ((xritag != (uint16_t) -1) && xritag <
  9519. (phba->sli4_hba.max_cfg_param.max_xri
  9520. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9521. phba->sli4_hba.next_xri++;
  9522. phba->sli4_hba.max_cfg_param.xri_used++;
  9523. spin_unlock_irq(&phba->hbalock);
  9524. return xritag;
  9525. }
  9526. spin_unlock_irq(&phba->hbalock);
  9527. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9528. "2004 Failed to allocate XRI.last XRITAG is %d"
  9529. " Max XRI is %d, Used XRI is %d\n",
  9530. phba->sli4_hba.next_xri,
  9531. phba->sli4_hba.max_cfg_param.max_xri,
  9532. phba->sli4_hba.max_cfg_param.xri_used);
  9533. return -1;
  9534. }
  9535. /**
  9536. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9537. * @phba: pointer to lpfc hba data structure.
  9538. *
  9539. * This routine is invoked to post a block of driver's sgl pages to the
  9540. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9541. * is only called when the driver is loading and after all IO has been
  9542. * stopped.
  9543. **/
  9544. int
  9545. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9546. {
  9547. struct lpfc_sglq *sglq_entry;
  9548. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9549. struct sgl_page_pairs *sgl_pg_pairs;
  9550. void *viraddr;
  9551. LPFC_MBOXQ_t *mbox;
  9552. uint32_t reqlen, alloclen, pg_pairs;
  9553. uint32_t mbox_tmo;
  9554. uint16_t xritag_start = 0;
  9555. int els_xri_cnt, rc = 0;
  9556. uint32_t shdr_status, shdr_add_status;
  9557. union lpfc_sli4_cfg_shdr *shdr;
  9558. /* The number of sgls to be posted */
  9559. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9560. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9561. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9562. if (reqlen > PAGE_SIZE) {
  9563. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9564. "2559 Block sgl registration required DMA "
  9565. "size (%d) great than a page\n", reqlen);
  9566. return -ENOMEM;
  9567. }
  9568. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9569. if (!mbox) {
  9570. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9571. "2560 Failed to allocate mbox cmd memory\n");
  9572. return -ENOMEM;
  9573. }
  9574. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9575. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9576. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9577. LPFC_SLI4_MBX_NEMBED);
  9578. if (alloclen < reqlen) {
  9579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9580. "0285 Allocated DMA memory size (%d) is "
  9581. "less than the requested DMA memory "
  9582. "size (%d)\n", alloclen, reqlen);
  9583. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9584. return -ENOMEM;
  9585. }
  9586. /* Get the first SGE entry from the non-embedded DMA memory */
  9587. viraddr = mbox->sge_array->addr[0];
  9588. /* Set up the SGL pages in the non-embedded DMA pages */
  9589. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9590. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9591. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9592. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9593. /* Set up the sge entry */
  9594. sgl_pg_pairs->sgl_pg0_addr_lo =
  9595. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9596. sgl_pg_pairs->sgl_pg0_addr_hi =
  9597. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9598. sgl_pg_pairs->sgl_pg1_addr_lo =
  9599. cpu_to_le32(putPaddrLow(0));
  9600. sgl_pg_pairs->sgl_pg1_addr_hi =
  9601. cpu_to_le32(putPaddrHigh(0));
  9602. /* Keep the first xritag on the list */
  9603. if (pg_pairs == 0)
  9604. xritag_start = sglq_entry->sli4_xritag;
  9605. sgl_pg_pairs++;
  9606. }
  9607. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9608. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  9609. /* Perform endian conversion if necessary */
  9610. sgl->word0 = cpu_to_le32(sgl->word0);
  9611. if (!phba->sli4_hba.intr_enable)
  9612. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9613. else {
  9614. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9615. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9616. }
  9617. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9618. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9619. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9620. if (rc != MBX_TIMEOUT)
  9621. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9622. if (shdr_status || shdr_add_status || rc) {
  9623. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9624. "2513 POST_SGL_BLOCK mailbox command failed "
  9625. "status x%x add_status x%x mbx status x%x\n",
  9626. shdr_status, shdr_add_status, rc);
  9627. rc = -ENXIO;
  9628. }
  9629. return rc;
  9630. }
  9631. /**
  9632. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9633. * @phba: pointer to lpfc hba data structure.
  9634. * @sblist: pointer to scsi buffer list.
  9635. * @count: number of scsi buffers on the list.
  9636. *
  9637. * This routine is invoked to post a block of @count scsi sgl pages from a
  9638. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9639. * No Lock is held.
  9640. *
  9641. **/
  9642. int
  9643. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9644. int cnt)
  9645. {
  9646. struct lpfc_scsi_buf *psb;
  9647. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9648. struct sgl_page_pairs *sgl_pg_pairs;
  9649. void *viraddr;
  9650. LPFC_MBOXQ_t *mbox;
  9651. uint32_t reqlen, alloclen, pg_pairs;
  9652. uint32_t mbox_tmo;
  9653. uint16_t xritag_start = 0;
  9654. int rc = 0;
  9655. uint32_t shdr_status, shdr_add_status;
  9656. dma_addr_t pdma_phys_bpl1;
  9657. union lpfc_sli4_cfg_shdr *shdr;
  9658. /* Calculate the requested length of the dma memory */
  9659. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9660. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9661. if (reqlen > PAGE_SIZE) {
  9662. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9663. "0217 Block sgl registration required DMA "
  9664. "size (%d) great than a page\n", reqlen);
  9665. return -ENOMEM;
  9666. }
  9667. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9668. if (!mbox) {
  9669. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9670. "0283 Failed to allocate mbox cmd memory\n");
  9671. return -ENOMEM;
  9672. }
  9673. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9674. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9675. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9676. LPFC_SLI4_MBX_NEMBED);
  9677. if (alloclen < reqlen) {
  9678. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9679. "2561 Allocated DMA memory size (%d) is "
  9680. "less than the requested DMA memory "
  9681. "size (%d)\n", alloclen, reqlen);
  9682. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9683. return -ENOMEM;
  9684. }
  9685. /* Get the first SGE entry from the non-embedded DMA memory */
  9686. viraddr = mbox->sge_array->addr[0];
  9687. /* Set up the SGL pages in the non-embedded DMA pages */
  9688. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9689. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9690. pg_pairs = 0;
  9691. list_for_each_entry(psb, sblist, list) {
  9692. /* Set up the sge entry */
  9693. sgl_pg_pairs->sgl_pg0_addr_lo =
  9694. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9695. sgl_pg_pairs->sgl_pg0_addr_hi =
  9696. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9697. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9698. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9699. else
  9700. pdma_phys_bpl1 = 0;
  9701. sgl_pg_pairs->sgl_pg1_addr_lo =
  9702. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9703. sgl_pg_pairs->sgl_pg1_addr_hi =
  9704. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9705. /* Keep the first xritag on the list */
  9706. if (pg_pairs == 0)
  9707. xritag_start = psb->cur_iocbq.sli4_xritag;
  9708. sgl_pg_pairs++;
  9709. pg_pairs++;
  9710. }
  9711. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9712. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9713. /* Perform endian conversion if necessary */
  9714. sgl->word0 = cpu_to_le32(sgl->word0);
  9715. if (!phba->sli4_hba.intr_enable)
  9716. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9717. else {
  9718. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9719. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9720. }
  9721. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9722. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9723. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9724. if (rc != MBX_TIMEOUT)
  9725. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9726. if (shdr_status || shdr_add_status || rc) {
  9727. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9728. "2564 POST_SGL_BLOCK mailbox command failed "
  9729. "status x%x add_status x%x mbx status x%x\n",
  9730. shdr_status, shdr_add_status, rc);
  9731. rc = -ENXIO;
  9732. }
  9733. return rc;
  9734. }
  9735. /**
  9736. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9737. * @phba: pointer to lpfc_hba struct that the frame was received on
  9738. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9739. *
  9740. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9741. * valid type of frame that the LPFC driver will handle. This function will
  9742. * return a zero if the frame is a valid frame or a non zero value when the
  9743. * frame does not pass the check.
  9744. **/
  9745. static int
  9746. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9747. {
  9748. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9749. char *type_names[] = FC_TYPE_NAMES_INIT;
  9750. struct fc_vft_header *fc_vft_hdr;
  9751. switch (fc_hdr->fh_r_ctl) {
  9752. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9753. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9754. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9755. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9756. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9757. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9758. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9759. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9760. case FC_RCTL_ELS_REQ: /* extended link services request */
  9761. case FC_RCTL_ELS_REP: /* extended link services reply */
  9762. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9763. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9764. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9765. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9766. case FC_RCTL_BA_RMC: /* remove connection */
  9767. case FC_RCTL_BA_ACC: /* basic accept */
  9768. case FC_RCTL_BA_RJT: /* basic reject */
  9769. case FC_RCTL_BA_PRMT:
  9770. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9771. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9772. case FC_RCTL_P_RJT: /* port reject */
  9773. case FC_RCTL_F_RJT: /* fabric reject */
  9774. case FC_RCTL_P_BSY: /* port busy */
  9775. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9776. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9777. case FC_RCTL_LCR: /* link credit reset */
  9778. case FC_RCTL_END: /* end */
  9779. break;
  9780. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9781. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9782. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9783. return lpfc_fc_frame_check(phba, fc_hdr);
  9784. default:
  9785. goto drop;
  9786. }
  9787. switch (fc_hdr->fh_type) {
  9788. case FC_TYPE_BLS:
  9789. case FC_TYPE_ELS:
  9790. case FC_TYPE_FCP:
  9791. case FC_TYPE_CT:
  9792. break;
  9793. case FC_TYPE_IP:
  9794. case FC_TYPE_ILS:
  9795. default:
  9796. goto drop;
  9797. }
  9798. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9799. "2538 Received frame rctl:%s type:%s\n",
  9800. rctl_names[fc_hdr->fh_r_ctl],
  9801. type_names[fc_hdr->fh_type]);
  9802. return 0;
  9803. drop:
  9804. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9805. "2539 Dropped frame rctl:%s type:%s\n",
  9806. rctl_names[fc_hdr->fh_r_ctl],
  9807. type_names[fc_hdr->fh_type]);
  9808. return 1;
  9809. }
  9810. /**
  9811. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9812. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9813. *
  9814. * This function processes the FC header to retrieve the VFI from the VF
  9815. * header, if one exists. This function will return the VFI if one exists
  9816. * or 0 if no VSAN Header exists.
  9817. **/
  9818. static uint32_t
  9819. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9820. {
  9821. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9822. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9823. return 0;
  9824. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9825. }
  9826. /**
  9827. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9828. * @phba: Pointer to the HBA structure to search for the vport on
  9829. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9830. * @fcfi: The FC Fabric ID that the frame came from
  9831. *
  9832. * This function searches the @phba for a vport that matches the content of the
  9833. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9834. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9835. * returns the matching vport pointer or NULL if unable to match frame to a
  9836. * vport.
  9837. **/
  9838. static struct lpfc_vport *
  9839. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9840. uint16_t fcfi)
  9841. {
  9842. struct lpfc_vport **vports;
  9843. struct lpfc_vport *vport = NULL;
  9844. int i;
  9845. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9846. fc_hdr->fh_d_id[1] << 8 |
  9847. fc_hdr->fh_d_id[2]);
  9848. vports = lpfc_create_vport_work_array(phba);
  9849. if (vports != NULL)
  9850. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9851. if (phba->fcf.fcfi == fcfi &&
  9852. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9853. vports[i]->fc_myDID == did) {
  9854. vport = vports[i];
  9855. break;
  9856. }
  9857. }
  9858. lpfc_destroy_vport_work_array(phba, vports);
  9859. return vport;
  9860. }
  9861. /**
  9862. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  9863. * @vport: The vport to work on.
  9864. *
  9865. * This function updates the receive sequence time stamp for this vport. The
  9866. * receive sequence time stamp indicates the time that the last frame of the
  9867. * the sequence that has been idle for the longest amount of time was received.
  9868. * the driver uses this time stamp to indicate if any received sequences have
  9869. * timed out.
  9870. **/
  9871. void
  9872. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  9873. {
  9874. struct lpfc_dmabuf *h_buf;
  9875. struct hbq_dmabuf *dmabuf = NULL;
  9876. /* get the oldest sequence on the rcv list */
  9877. h_buf = list_get_first(&vport->rcv_buffer_list,
  9878. struct lpfc_dmabuf, list);
  9879. if (!h_buf)
  9880. return;
  9881. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9882. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  9883. }
  9884. /**
  9885. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  9886. * @vport: The vport that the received sequences were sent to.
  9887. *
  9888. * This function cleans up all outstanding received sequences. This is called
  9889. * by the driver when a link event or user action invalidates all the received
  9890. * sequences.
  9891. **/
  9892. void
  9893. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  9894. {
  9895. struct lpfc_dmabuf *h_buf, *hnext;
  9896. struct lpfc_dmabuf *d_buf, *dnext;
  9897. struct hbq_dmabuf *dmabuf = NULL;
  9898. /* start with the oldest sequence on the rcv list */
  9899. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9900. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9901. list_del_init(&dmabuf->hbuf.list);
  9902. list_for_each_entry_safe(d_buf, dnext,
  9903. &dmabuf->dbuf.list, list) {
  9904. list_del_init(&d_buf->list);
  9905. lpfc_in_buf_free(vport->phba, d_buf);
  9906. }
  9907. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9908. }
  9909. }
  9910. /**
  9911. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  9912. * @vport: The vport that the received sequences were sent to.
  9913. *
  9914. * This function determines whether any received sequences have timed out by
  9915. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  9916. * indicates that there is at least one timed out sequence this routine will
  9917. * go through the received sequences one at a time from most inactive to most
  9918. * active to determine which ones need to be cleaned up. Once it has determined
  9919. * that a sequence needs to be cleaned up it will simply free up the resources
  9920. * without sending an abort.
  9921. **/
  9922. void
  9923. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  9924. {
  9925. struct lpfc_dmabuf *h_buf, *hnext;
  9926. struct lpfc_dmabuf *d_buf, *dnext;
  9927. struct hbq_dmabuf *dmabuf = NULL;
  9928. unsigned long timeout;
  9929. int abort_count = 0;
  9930. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9931. vport->rcv_buffer_time_stamp);
  9932. if (list_empty(&vport->rcv_buffer_list) ||
  9933. time_before(jiffies, timeout))
  9934. return;
  9935. /* start with the oldest sequence on the rcv list */
  9936. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  9937. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9938. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  9939. dmabuf->time_stamp);
  9940. if (time_before(jiffies, timeout))
  9941. break;
  9942. abort_count++;
  9943. list_del_init(&dmabuf->hbuf.list);
  9944. list_for_each_entry_safe(d_buf, dnext,
  9945. &dmabuf->dbuf.list, list) {
  9946. list_del_init(&d_buf->list);
  9947. lpfc_in_buf_free(vport->phba, d_buf);
  9948. }
  9949. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  9950. }
  9951. if (abort_count)
  9952. lpfc_update_rcv_time_stamp(vport);
  9953. }
  9954. /**
  9955. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9956. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9957. *
  9958. * This function searches through the existing incomplete sequences that have
  9959. * been sent to this @vport. If the frame matches one of the incomplete
  9960. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9961. * make up that sequence. If no sequence is found that matches this frame then
  9962. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9963. * This function returns a pointer to the first dmabuf in the sequence list that
  9964. * the frame was linked to.
  9965. **/
  9966. static struct hbq_dmabuf *
  9967. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9968. {
  9969. struct fc_frame_header *new_hdr;
  9970. struct fc_frame_header *temp_hdr;
  9971. struct lpfc_dmabuf *d_buf;
  9972. struct lpfc_dmabuf *h_buf;
  9973. struct hbq_dmabuf *seq_dmabuf = NULL;
  9974. struct hbq_dmabuf *temp_dmabuf = NULL;
  9975. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  9976. dmabuf->time_stamp = jiffies;
  9977. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9978. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9979. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9980. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9981. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9982. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9983. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9984. continue;
  9985. /* found a pending sequence that matches this frame */
  9986. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9987. break;
  9988. }
  9989. if (!seq_dmabuf) {
  9990. /*
  9991. * This indicates first frame received for this sequence.
  9992. * Queue the buffer on the vport's rcv_buffer_list.
  9993. */
  9994. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9995. lpfc_update_rcv_time_stamp(vport);
  9996. return dmabuf;
  9997. }
  9998. temp_hdr = seq_dmabuf->hbuf.virt;
  9999. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10000. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10001. list_del_init(&seq_dmabuf->hbuf.list);
  10002. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10003. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10004. lpfc_update_rcv_time_stamp(vport);
  10005. return dmabuf;
  10006. }
  10007. /* move this sequence to the tail to indicate a young sequence */
  10008. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10009. seq_dmabuf->time_stamp = jiffies;
  10010. lpfc_update_rcv_time_stamp(vport);
  10011. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10012. temp_hdr = dmabuf->hbuf.virt;
  10013. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10014. return seq_dmabuf;
  10015. }
  10016. /* find the correct place in the sequence to insert this frame */
  10017. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10018. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10019. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10020. /*
  10021. * If the frame's sequence count is greater than the frame on
  10022. * the list then insert the frame right after this frame
  10023. */
  10024. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10025. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10026. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10027. return seq_dmabuf;
  10028. }
  10029. }
  10030. return NULL;
  10031. }
  10032. /**
  10033. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10034. * @vport: pointer to a vitural port
  10035. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10036. *
  10037. * This function tries to abort from the partially assembed sequence, described
  10038. * by the information from basic abbort @dmabuf. It checks to see whether such
  10039. * partially assembled sequence held by the driver. If so, it shall free up all
  10040. * the frames from the partially assembled sequence.
  10041. *
  10042. * Return
  10043. * true -- if there is matching partially assembled sequence present and all
  10044. * the frames freed with the sequence;
  10045. * false -- if there is no matching partially assembled sequence present so
  10046. * nothing got aborted in the lower layer driver
  10047. **/
  10048. static bool
  10049. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10050. struct hbq_dmabuf *dmabuf)
  10051. {
  10052. struct fc_frame_header *new_hdr;
  10053. struct fc_frame_header *temp_hdr;
  10054. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10055. struct hbq_dmabuf *seq_dmabuf = NULL;
  10056. /* Use the hdr_buf to find the sequence that matches this frame */
  10057. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10058. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10059. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10060. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10061. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10062. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10063. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10064. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10065. continue;
  10066. /* found a pending sequence that matches this frame */
  10067. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10068. break;
  10069. }
  10070. /* Free up all the frames from the partially assembled sequence */
  10071. if (seq_dmabuf) {
  10072. list_for_each_entry_safe(d_buf, n_buf,
  10073. &seq_dmabuf->dbuf.list, list) {
  10074. list_del_init(&d_buf->list);
  10075. lpfc_in_buf_free(vport->phba, d_buf);
  10076. }
  10077. return true;
  10078. }
  10079. return false;
  10080. }
  10081. /**
  10082. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10083. * @phba: Pointer to HBA context object.
  10084. * @cmd_iocbq: pointer to the command iocbq structure.
  10085. * @rsp_iocbq: pointer to the response iocbq structure.
  10086. *
  10087. * This function handles the sequence abort accept iocb command complete
  10088. * event. It properly releases the memory allocated to the sequence abort
  10089. * accept iocb.
  10090. **/
  10091. static void
  10092. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10093. struct lpfc_iocbq *cmd_iocbq,
  10094. struct lpfc_iocbq *rsp_iocbq)
  10095. {
  10096. if (cmd_iocbq)
  10097. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10098. }
  10099. /**
  10100. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10101. * @phba: Pointer to HBA context object.
  10102. * @fc_hdr: pointer to a FC frame header.
  10103. *
  10104. * This function sends a basic accept to a previous unsol sequence abort
  10105. * event after aborting the sequence handling.
  10106. **/
  10107. static void
  10108. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10109. struct fc_frame_header *fc_hdr)
  10110. {
  10111. struct lpfc_iocbq *ctiocb = NULL;
  10112. struct lpfc_nodelist *ndlp;
  10113. uint16_t oxid, rxid;
  10114. uint32_t sid, fctl;
  10115. IOCB_t *icmd;
  10116. if (!lpfc_is_link_up(phba))
  10117. return;
  10118. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10119. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10120. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10121. ndlp = lpfc_findnode_did(phba->pport, sid);
  10122. if (!ndlp) {
  10123. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10124. "1268 Find ndlp returned NULL for oxid:x%x "
  10125. "SID:x%x\n", oxid, sid);
  10126. return;
  10127. }
  10128. /* Allocate buffer for acc iocb */
  10129. ctiocb = lpfc_sli_get_iocbq(phba);
  10130. if (!ctiocb)
  10131. return;
  10132. /* Extract the F_CTL field from FC_HDR */
  10133. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10134. icmd = &ctiocb->iocb;
  10135. icmd->un.xseq64.bdl.bdeSize = 0;
  10136. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10137. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10138. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10139. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10140. /* Fill in the rest of iocb fields */
  10141. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10142. icmd->ulpBdeCount = 0;
  10143. icmd->ulpLe = 1;
  10144. icmd->ulpClass = CLASS3;
  10145. icmd->ulpContext = ndlp->nlp_rpi;
  10146. ctiocb->iocb_cmpl = NULL;
  10147. ctiocb->vport = phba->pport;
  10148. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10149. if (fctl & FC_FC_EX_CTX) {
  10150. /* ABTS sent by responder to CT exchange, construction
  10151. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10152. * field and RX_ID from ABTS for RX_ID field.
  10153. */
  10154. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10155. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10156. ctiocb->sli4_xritag = oxid;
  10157. } else {
  10158. /* ABTS sent by initiator to CT exchange, construction
  10159. * of BA_ACC will need to allocate a new XRI as for the
  10160. * XRI_TAG and RX_ID fields.
  10161. */
  10162. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10163. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10164. ctiocb->sli4_xritag = NO_XRI;
  10165. }
  10166. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10167. /* Xmit CT abts accept on exchange <xid> */
  10168. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10169. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10170. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10171. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10172. }
  10173. /**
  10174. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10175. * @vport: Pointer to the vport on which this sequence was received
  10176. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10177. *
  10178. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10179. * receive sequence is only partially assembed by the driver, it shall abort
  10180. * the partially assembled frames for the sequence. Otherwise, if the
  10181. * unsolicited receive sequence has been completely assembled and passed to
  10182. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10183. * unsolicited sequence has been aborted. After that, it will issue a basic
  10184. * accept to accept the abort.
  10185. **/
  10186. void
  10187. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10188. struct hbq_dmabuf *dmabuf)
  10189. {
  10190. struct lpfc_hba *phba = vport->phba;
  10191. struct fc_frame_header fc_hdr;
  10192. uint32_t fctl;
  10193. bool abts_par;
  10194. /* Make a copy of fc_hdr before the dmabuf being released */
  10195. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10196. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10197. if (fctl & FC_FC_EX_CTX) {
  10198. /*
  10199. * ABTS sent by responder to exchange, just free the buffer
  10200. */
  10201. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10202. } else {
  10203. /*
  10204. * ABTS sent by initiator to exchange, need to do cleanup
  10205. */
  10206. /* Try to abort partially assembled seq */
  10207. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10208. /* Send abort to ULP if partially seq abort failed */
  10209. if (abts_par == false)
  10210. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10211. else
  10212. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10213. }
  10214. /* Send basic accept (BA_ACC) to the abort requester */
  10215. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10216. }
  10217. /**
  10218. * lpfc_seq_complete - Indicates if a sequence is complete
  10219. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10220. *
  10221. * This function checks the sequence, starting with the frame described by
  10222. * @dmabuf, to see if all the frames associated with this sequence are present.
  10223. * the frames associated with this sequence are linked to the @dmabuf using the
  10224. * dbuf list. This function looks for two major things. 1) That the first frame
  10225. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10226. * set. 3) That there are no holes in the sequence count. The function will
  10227. * return 1 when the sequence is complete, otherwise it will return 0.
  10228. **/
  10229. static int
  10230. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10231. {
  10232. struct fc_frame_header *hdr;
  10233. struct lpfc_dmabuf *d_buf;
  10234. struct hbq_dmabuf *seq_dmabuf;
  10235. uint32_t fctl;
  10236. int seq_count = 0;
  10237. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10238. /* make sure first fame of sequence has a sequence count of zero */
  10239. if (hdr->fh_seq_cnt != seq_count)
  10240. return 0;
  10241. fctl = (hdr->fh_f_ctl[0] << 16 |
  10242. hdr->fh_f_ctl[1] << 8 |
  10243. hdr->fh_f_ctl[2]);
  10244. /* If last frame of sequence we can return success. */
  10245. if (fctl & FC_FC_END_SEQ)
  10246. return 1;
  10247. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10248. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10249. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10250. /* If there is a hole in the sequence count then fail. */
  10251. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10252. return 0;
  10253. fctl = (hdr->fh_f_ctl[0] << 16 |
  10254. hdr->fh_f_ctl[1] << 8 |
  10255. hdr->fh_f_ctl[2]);
  10256. /* If last frame of sequence we can return success. */
  10257. if (fctl & FC_FC_END_SEQ)
  10258. return 1;
  10259. }
  10260. return 0;
  10261. }
  10262. /**
  10263. * lpfc_prep_seq - Prep sequence for ULP processing
  10264. * @vport: Pointer to the vport on which this sequence was received
  10265. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10266. *
  10267. * This function takes a sequence, described by a list of frames, and creates
  10268. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10269. * used to issue to the generic unsolicited sequence handler. This routine
  10270. * returns a pointer to the first iocbq in the list. If the function is unable
  10271. * to allocate an iocbq then it throw out the received frames that were not
  10272. * able to be described and return a pointer to the first iocbq. If unable to
  10273. * allocate any iocbqs (including the first) this function will return NULL.
  10274. **/
  10275. static struct lpfc_iocbq *
  10276. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10277. {
  10278. struct lpfc_dmabuf *d_buf, *n_buf;
  10279. struct lpfc_iocbq *first_iocbq, *iocbq;
  10280. struct fc_frame_header *fc_hdr;
  10281. uint32_t sid;
  10282. struct ulp_bde64 *pbde;
  10283. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10284. /* remove from receive buffer list */
  10285. list_del_init(&seq_dmabuf->hbuf.list);
  10286. lpfc_update_rcv_time_stamp(vport);
  10287. /* get the Remote Port's SID */
  10288. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10289. /* Get an iocbq struct to fill in. */
  10290. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10291. if (first_iocbq) {
  10292. /* Initialize the first IOCB. */
  10293. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10294. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10295. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10296. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10297. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10298. vport->vpi + vport->phba->vpi_base;
  10299. /* put the first buffer into the first IOCBq */
  10300. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10301. first_iocbq->context3 = NULL;
  10302. first_iocbq->iocb.ulpBdeCount = 1;
  10303. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10304. LPFC_DATA_BUF_SIZE;
  10305. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10306. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10307. bf_get(lpfc_rcqe_length,
  10308. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10309. }
  10310. iocbq = first_iocbq;
  10311. /*
  10312. * Each IOCBq can have two Buffers assigned, so go through the list
  10313. * of buffers for this sequence and save two buffers in each IOCBq
  10314. */
  10315. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10316. if (!iocbq) {
  10317. lpfc_in_buf_free(vport->phba, d_buf);
  10318. continue;
  10319. }
  10320. if (!iocbq->context3) {
  10321. iocbq->context3 = d_buf;
  10322. iocbq->iocb.ulpBdeCount++;
  10323. pbde = (struct ulp_bde64 *)
  10324. &iocbq->iocb.unsli3.sli3Words[4];
  10325. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10326. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10327. bf_get(lpfc_rcqe_length,
  10328. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10329. } else {
  10330. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10331. if (!iocbq) {
  10332. if (first_iocbq) {
  10333. first_iocbq->iocb.ulpStatus =
  10334. IOSTAT_FCP_RSP_ERROR;
  10335. first_iocbq->iocb.un.ulpWord[4] =
  10336. IOERR_NO_RESOURCES;
  10337. }
  10338. lpfc_in_buf_free(vport->phba, d_buf);
  10339. continue;
  10340. }
  10341. iocbq->context2 = d_buf;
  10342. iocbq->context3 = NULL;
  10343. iocbq->iocb.ulpBdeCount = 1;
  10344. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10345. LPFC_DATA_BUF_SIZE;
  10346. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10347. bf_get(lpfc_rcqe_length,
  10348. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10349. iocbq->iocb.un.rcvels.remoteID = sid;
  10350. list_add_tail(&iocbq->list, &first_iocbq->list);
  10351. }
  10352. }
  10353. return first_iocbq;
  10354. }
  10355. static void
  10356. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10357. struct hbq_dmabuf *seq_dmabuf)
  10358. {
  10359. struct fc_frame_header *fc_hdr;
  10360. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10361. struct lpfc_hba *phba = vport->phba;
  10362. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10363. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10364. if (!iocbq) {
  10365. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10366. "2707 Ring %d handler: Failed to allocate "
  10367. "iocb Rctl x%x Type x%x received\n",
  10368. LPFC_ELS_RING,
  10369. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10370. return;
  10371. }
  10372. if (!lpfc_complete_unsol_iocb(phba,
  10373. &phba->sli.ring[LPFC_ELS_RING],
  10374. iocbq, fc_hdr->fh_r_ctl,
  10375. fc_hdr->fh_type))
  10376. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10377. "2540 Ring %d handler: unexpected Rctl "
  10378. "x%x Type x%x received\n",
  10379. LPFC_ELS_RING,
  10380. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10381. /* Free iocb created in lpfc_prep_seq */
  10382. list_for_each_entry_safe(curr_iocb, next_iocb,
  10383. &iocbq->list, list) {
  10384. list_del_init(&curr_iocb->list);
  10385. lpfc_sli_release_iocbq(phba, curr_iocb);
  10386. }
  10387. lpfc_sli_release_iocbq(phba, iocbq);
  10388. }
  10389. /**
  10390. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10391. * @phba: Pointer to HBA context object.
  10392. *
  10393. * This function is called with no lock held. This function processes all
  10394. * the received buffers and gives it to upper layers when a received buffer
  10395. * indicates that it is the final frame in the sequence. The interrupt
  10396. * service routine processes received buffers at interrupt contexts and adds
  10397. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10398. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10399. * appropriate receive function when the final frame in a sequence is received.
  10400. **/
  10401. void
  10402. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10403. struct hbq_dmabuf *dmabuf)
  10404. {
  10405. struct hbq_dmabuf *seq_dmabuf;
  10406. struct fc_frame_header *fc_hdr;
  10407. struct lpfc_vport *vport;
  10408. uint32_t fcfi;
  10409. /* Process each received buffer */
  10410. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10411. /* check to see if this a valid type of frame */
  10412. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10413. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10414. return;
  10415. }
  10416. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10417. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10418. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10419. /* throw out the frame */
  10420. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10421. return;
  10422. }
  10423. /* Handle the basic abort sequence (BA_ABTS) event */
  10424. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10425. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10426. return;
  10427. }
  10428. /* Link this frame */
  10429. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10430. if (!seq_dmabuf) {
  10431. /* unable to add frame to vport - throw it out */
  10432. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10433. return;
  10434. }
  10435. /* If not last frame in sequence continue processing frames. */
  10436. if (!lpfc_seq_complete(seq_dmabuf))
  10437. return;
  10438. /* Send the complete sequence to the upper layer protocol */
  10439. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10440. }
  10441. /**
  10442. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10443. * @phba: pointer to lpfc hba data structure.
  10444. *
  10445. * This routine is invoked to post rpi header templates to the
  10446. * HBA consistent with the SLI-4 interface spec. This routine
  10447. * posts a PAGE_SIZE memory region to the port to hold up to
  10448. * PAGE_SIZE modulo 64 rpi context headers.
  10449. *
  10450. * This routine does not require any locks. It's usage is expected
  10451. * to be driver load or reset recovery when the driver is
  10452. * sequential.
  10453. *
  10454. * Return codes
  10455. * 0 - successful
  10456. * EIO - The mailbox failed to complete successfully.
  10457. * When this error occurs, the driver is not guaranteed
  10458. * to have any rpi regions posted to the device and
  10459. * must either attempt to repost the regions or take a
  10460. * fatal error.
  10461. **/
  10462. int
  10463. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10464. {
  10465. struct lpfc_rpi_hdr *rpi_page;
  10466. uint32_t rc = 0;
  10467. /* Post all rpi memory regions to the port. */
  10468. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10469. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10470. if (rc != MBX_SUCCESS) {
  10471. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10472. "2008 Error %d posting all rpi "
  10473. "headers\n", rc);
  10474. rc = -EIO;
  10475. break;
  10476. }
  10477. }
  10478. return rc;
  10479. }
  10480. /**
  10481. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10482. * @phba: pointer to lpfc hba data structure.
  10483. * @rpi_page: pointer to the rpi memory region.
  10484. *
  10485. * This routine is invoked to post a single rpi header to the
  10486. * HBA consistent with the SLI-4 interface spec. This memory region
  10487. * maps up to 64 rpi context regions.
  10488. *
  10489. * Return codes
  10490. * 0 - successful
  10491. * ENOMEM - No available memory
  10492. * EIO - The mailbox failed to complete successfully.
  10493. **/
  10494. int
  10495. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10496. {
  10497. LPFC_MBOXQ_t *mboxq;
  10498. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10499. uint32_t rc = 0;
  10500. uint32_t mbox_tmo;
  10501. uint32_t shdr_status, shdr_add_status;
  10502. union lpfc_sli4_cfg_shdr *shdr;
  10503. /* The port is notified of the header region via a mailbox command. */
  10504. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10505. if (!mboxq) {
  10506. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10507. "2001 Unable to allocate memory for issuing "
  10508. "SLI_CONFIG_SPECIAL mailbox command\n");
  10509. return -ENOMEM;
  10510. }
  10511. /* Post all rpi memory regions to the port. */
  10512. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10513. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10514. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10515. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10516. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10517. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10518. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10519. hdr_tmpl, rpi_page->page_count);
  10520. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10521. rpi_page->start_rpi);
  10522. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10523. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10524. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10525. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10526. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10527. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10528. if (rc != MBX_TIMEOUT)
  10529. mempool_free(mboxq, phba->mbox_mem_pool);
  10530. if (shdr_status || shdr_add_status || rc) {
  10531. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10532. "2514 POST_RPI_HDR mailbox failed with "
  10533. "status x%x add_status x%x, mbx status x%x\n",
  10534. shdr_status, shdr_add_status, rc);
  10535. rc = -ENXIO;
  10536. }
  10537. return rc;
  10538. }
  10539. /**
  10540. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10541. * @phba: pointer to lpfc hba data structure.
  10542. *
  10543. * This routine is invoked to post rpi header templates to the
  10544. * HBA consistent with the SLI-4 interface spec. This routine
  10545. * posts a PAGE_SIZE memory region to the port to hold up to
  10546. * PAGE_SIZE modulo 64 rpi context headers.
  10547. *
  10548. * Returns
  10549. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10550. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10551. **/
  10552. int
  10553. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10554. {
  10555. int rpi;
  10556. uint16_t max_rpi, rpi_base, rpi_limit;
  10557. uint16_t rpi_remaining;
  10558. struct lpfc_rpi_hdr *rpi_hdr;
  10559. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10560. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10561. rpi_limit = phba->sli4_hba.next_rpi;
  10562. /*
  10563. * The valid rpi range is not guaranteed to be zero-based. Start
  10564. * the search at the rpi_base as reported by the port.
  10565. */
  10566. spin_lock_irq(&phba->hbalock);
  10567. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10568. if (rpi >= rpi_limit || rpi < rpi_base)
  10569. rpi = LPFC_RPI_ALLOC_ERROR;
  10570. else {
  10571. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10572. phba->sli4_hba.max_cfg_param.rpi_used++;
  10573. phba->sli4_hba.rpi_count++;
  10574. }
  10575. /*
  10576. * Don't try to allocate more rpi header regions if the device limit
  10577. * on available rpis max has been exhausted.
  10578. */
  10579. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10580. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10581. spin_unlock_irq(&phba->hbalock);
  10582. return rpi;
  10583. }
  10584. /*
  10585. * If the driver is running low on rpi resources, allocate another
  10586. * page now. Note that the next_rpi value is used because
  10587. * it represents how many are actually in use whereas max_rpi notes
  10588. * how many are supported max by the device.
  10589. */
  10590. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10591. phba->sli4_hba.rpi_count;
  10592. spin_unlock_irq(&phba->hbalock);
  10593. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10594. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10595. if (!rpi_hdr) {
  10596. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10597. "2002 Error Could not grow rpi "
  10598. "count\n");
  10599. } else {
  10600. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10601. }
  10602. }
  10603. return rpi;
  10604. }
  10605. /**
  10606. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10607. * @phba: pointer to lpfc hba data structure.
  10608. *
  10609. * This routine is invoked to release an rpi to the pool of
  10610. * available rpis maintained by the driver.
  10611. **/
  10612. void
  10613. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10614. {
  10615. spin_lock_irq(&phba->hbalock);
  10616. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10617. phba->sli4_hba.rpi_count--;
  10618. phba->sli4_hba.max_cfg_param.rpi_used--;
  10619. spin_unlock_irq(&phba->hbalock);
  10620. }
  10621. /**
  10622. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10623. * @phba: pointer to lpfc hba data structure.
  10624. *
  10625. * This routine is invoked to remove the memory region that
  10626. * provided rpi via a bitmask.
  10627. **/
  10628. void
  10629. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10630. {
  10631. kfree(phba->sli4_hba.rpi_bmask);
  10632. }
  10633. /**
  10634. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10635. * @phba: pointer to lpfc hba data structure.
  10636. *
  10637. * This routine is invoked to remove the memory region that
  10638. * provided rpi via a bitmask.
  10639. **/
  10640. int
  10641. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10642. {
  10643. LPFC_MBOXQ_t *mboxq;
  10644. struct lpfc_hba *phba = ndlp->phba;
  10645. int rc;
  10646. /* The port is notified of the header region via a mailbox command. */
  10647. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10648. if (!mboxq)
  10649. return -ENOMEM;
  10650. /* Post all rpi memory regions to the port. */
  10651. lpfc_resume_rpi(mboxq, ndlp);
  10652. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10653. if (rc == MBX_NOT_FINISHED) {
  10654. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10655. "2010 Resume RPI Mailbox failed "
  10656. "status %d, mbxStatus x%x\n", rc,
  10657. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10658. mempool_free(mboxq, phba->mbox_mem_pool);
  10659. return -EIO;
  10660. }
  10661. return 0;
  10662. }
  10663. /**
  10664. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10665. * @phba: pointer to lpfc hba data structure.
  10666. * @vpi: vpi value to activate with the port.
  10667. *
  10668. * This routine is invoked to activate a vpi with the
  10669. * port when the host intends to use vports with a
  10670. * nonzero vpi.
  10671. *
  10672. * Returns:
  10673. * 0 success
  10674. * -Evalue otherwise
  10675. **/
  10676. int
  10677. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10678. {
  10679. LPFC_MBOXQ_t *mboxq;
  10680. int rc = 0;
  10681. int retval = MBX_SUCCESS;
  10682. uint32_t mbox_tmo;
  10683. if (vpi == 0)
  10684. return -EINVAL;
  10685. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10686. if (!mboxq)
  10687. return -ENOMEM;
  10688. lpfc_init_vpi(phba, mboxq, vpi);
  10689. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10690. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10691. if (rc != MBX_SUCCESS) {
  10692. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10693. "2022 INIT VPI Mailbox failed "
  10694. "status %d, mbxStatus x%x\n", rc,
  10695. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10696. retval = -EIO;
  10697. }
  10698. if (rc != MBX_TIMEOUT)
  10699. mempool_free(mboxq, phba->mbox_mem_pool);
  10700. return retval;
  10701. }
  10702. /**
  10703. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10704. * @phba: pointer to lpfc hba data structure.
  10705. * @mboxq: Pointer to mailbox object.
  10706. *
  10707. * This routine is invoked to manually add a single FCF record. The caller
  10708. * must pass a completely initialized FCF_Record. This routine takes
  10709. * care of the nonembedded mailbox operations.
  10710. **/
  10711. static void
  10712. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10713. {
  10714. void *virt_addr;
  10715. union lpfc_sli4_cfg_shdr *shdr;
  10716. uint32_t shdr_status, shdr_add_status;
  10717. virt_addr = mboxq->sge_array->addr[0];
  10718. /* The IOCTL status is embedded in the mailbox subheader. */
  10719. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10720. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10721. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10722. if ((shdr_status || shdr_add_status) &&
  10723. (shdr_status != STATUS_FCF_IN_USE))
  10724. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10725. "2558 ADD_FCF_RECORD mailbox failed with "
  10726. "status x%x add_status x%x\n",
  10727. shdr_status, shdr_add_status);
  10728. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10729. }
  10730. /**
  10731. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10732. * @phba: pointer to lpfc hba data structure.
  10733. * @fcf_record: pointer to the initialized fcf record to add.
  10734. *
  10735. * This routine is invoked to manually add a single FCF record. The caller
  10736. * must pass a completely initialized FCF_Record. This routine takes
  10737. * care of the nonembedded mailbox operations.
  10738. **/
  10739. int
  10740. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10741. {
  10742. int rc = 0;
  10743. LPFC_MBOXQ_t *mboxq;
  10744. uint8_t *bytep;
  10745. void *virt_addr;
  10746. dma_addr_t phys_addr;
  10747. struct lpfc_mbx_sge sge;
  10748. uint32_t alloc_len, req_len;
  10749. uint32_t fcfindex;
  10750. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10751. if (!mboxq) {
  10752. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10753. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10754. return -ENOMEM;
  10755. }
  10756. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10757. sizeof(uint32_t);
  10758. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10759. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10760. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10761. req_len, LPFC_SLI4_MBX_NEMBED);
  10762. if (alloc_len < req_len) {
  10763. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10764. "2523 Allocated DMA memory size (x%x) is "
  10765. "less than the requested DMA memory "
  10766. "size (x%x)\n", alloc_len, req_len);
  10767. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10768. return -ENOMEM;
  10769. }
  10770. /*
  10771. * Get the first SGE entry from the non-embedded DMA memory. This
  10772. * routine only uses a single SGE.
  10773. */
  10774. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10775. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10776. virt_addr = mboxq->sge_array->addr[0];
  10777. /*
  10778. * Configure the FCF record for FCFI 0. This is the driver's
  10779. * hardcoded default and gets used in nonFIP mode.
  10780. */
  10781. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10782. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10783. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10784. /*
  10785. * Copy the fcf_index and the FCF Record Data. The data starts after
  10786. * the FCoE header plus word10. The data copy needs to be endian
  10787. * correct.
  10788. */
  10789. bytep += sizeof(uint32_t);
  10790. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10791. mboxq->vport = phba->pport;
  10792. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10793. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10794. if (rc == MBX_NOT_FINISHED) {
  10795. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10796. "2515 ADD_FCF_RECORD mailbox failed with "
  10797. "status 0x%x\n", rc);
  10798. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10799. rc = -EIO;
  10800. } else
  10801. rc = 0;
  10802. return rc;
  10803. }
  10804. /**
  10805. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10806. * @phba: pointer to lpfc hba data structure.
  10807. * @fcf_record: pointer to the fcf record to write the default data.
  10808. * @fcf_index: FCF table entry index.
  10809. *
  10810. * This routine is invoked to build the driver's default FCF record. The
  10811. * values used are hardcoded. This routine handles memory initialization.
  10812. *
  10813. **/
  10814. void
  10815. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10816. struct fcf_record *fcf_record,
  10817. uint16_t fcf_index)
  10818. {
  10819. memset(fcf_record, 0, sizeof(struct fcf_record));
  10820. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10821. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10822. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10823. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10824. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10825. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10826. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10827. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10828. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10829. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10830. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10831. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10832. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10833. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10834. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10835. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10836. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10837. /* Set the VLAN bit map */
  10838. if (phba->valid_vlan) {
  10839. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10840. = 1 << (phba->vlan_id % 8);
  10841. }
  10842. }
  10843. /**
  10844. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10845. * @phba: pointer to lpfc hba data structure.
  10846. * @fcf_index: FCF table entry offset.
  10847. *
  10848. * This routine is invoked to read up to @fcf_num of FCF record from the
  10849. * device starting with the given @fcf_index.
  10850. **/
  10851. int
  10852. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10853. {
  10854. int rc = 0, error;
  10855. LPFC_MBOXQ_t *mboxq;
  10856. void *virt_addr;
  10857. dma_addr_t phys_addr;
  10858. uint8_t *bytep;
  10859. struct lpfc_mbx_sge sge;
  10860. uint32_t alloc_len, req_len;
  10861. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10862. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  10863. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10864. if (!mboxq) {
  10865. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10866. "2000 Failed to allocate mbox for "
  10867. "READ_FCF cmd\n");
  10868. error = -ENOMEM;
  10869. goto fail_fcfscan;
  10870. }
  10871. req_len = sizeof(struct fcf_record) +
  10872. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10873. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10874. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10875. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10876. LPFC_SLI4_MBX_NEMBED);
  10877. if (alloc_len < req_len) {
  10878. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10879. "0291 Allocated DMA memory size (x%x) is "
  10880. "less than the requested DMA memory "
  10881. "size (x%x)\n", alloc_len, req_len);
  10882. error = -ENOMEM;
  10883. goto fail_fcfscan;
  10884. }
  10885. /* Get the first SGE entry from the non-embedded DMA memory. This
  10886. * routine only uses a single SGE.
  10887. */
  10888. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10889. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10890. virt_addr = mboxq->sge_array->addr[0];
  10891. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10892. /* Set up command fields */
  10893. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10894. /* Perform necessary endian conversion */
  10895. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10896. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10897. mboxq->vport = phba->pport;
  10898. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10899. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10900. if (rc == MBX_NOT_FINISHED) {
  10901. error = -EIO;
  10902. } else {
  10903. spin_lock_irq(&phba->hbalock);
  10904. phba->hba_flag |= FCF_DISC_INPROGRESS;
  10905. spin_unlock_irq(&phba->hbalock);
  10906. error = 0;
  10907. }
  10908. fail_fcfscan:
  10909. if (error) {
  10910. if (mboxq)
  10911. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10912. /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */
  10913. spin_lock_irq(&phba->hbalock);
  10914. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  10915. spin_unlock_irq(&phba->hbalock);
  10916. }
  10917. return error;
  10918. }
  10919. /**
  10920. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  10921. * @phba: pointer to lpfc hba data structure.
  10922. *
  10923. * This function read region 23 and parse TLV for port status to
  10924. * decide if the user disaled the port. If the TLV indicates the
  10925. * port is disabled, the hba_flag is set accordingly.
  10926. **/
  10927. void
  10928. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  10929. {
  10930. LPFC_MBOXQ_t *pmb = NULL;
  10931. MAILBOX_t *mb;
  10932. uint8_t *rgn23_data = NULL;
  10933. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  10934. int rc;
  10935. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10936. if (!pmb) {
  10937. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10938. "2600 lpfc_sli_read_serdes_param failed to"
  10939. " allocate mailbox memory\n");
  10940. goto out;
  10941. }
  10942. mb = &pmb->u.mb;
  10943. /* Get adapter Region 23 data */
  10944. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  10945. if (!rgn23_data)
  10946. goto out;
  10947. do {
  10948. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  10949. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  10950. if (rc != MBX_SUCCESS) {
  10951. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  10952. "2601 lpfc_sli_read_link_ste failed to"
  10953. " read config region 23 rc 0x%x Status 0x%x\n",
  10954. rc, mb->mbxStatus);
  10955. mb->un.varDmp.word_cnt = 0;
  10956. }
  10957. /*
  10958. * dump mem may return a zero when finished or we got a
  10959. * mailbox error, either way we are done.
  10960. */
  10961. if (mb->un.varDmp.word_cnt == 0)
  10962. break;
  10963. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  10964. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  10965. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  10966. rgn23_data + offset,
  10967. mb->un.varDmp.word_cnt);
  10968. offset += mb->un.varDmp.word_cnt;
  10969. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  10970. data_size = offset;
  10971. offset = 0;
  10972. if (!data_size)
  10973. goto out;
  10974. /* Check the region signature first */
  10975. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  10976. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10977. "2619 Config region 23 has bad signature\n");
  10978. goto out;
  10979. }
  10980. offset += 4;
  10981. /* Check the data structure version */
  10982. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  10983. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10984. "2620 Config region 23 has bad version\n");
  10985. goto out;
  10986. }
  10987. offset += 4;
  10988. /* Parse TLV entries in the region */
  10989. while (offset < data_size) {
  10990. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  10991. break;
  10992. /*
  10993. * If the TLV is not driver specific TLV or driver id is
  10994. * not linux driver id, skip the record.
  10995. */
  10996. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  10997. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  10998. (rgn23_data[offset + 3] != 0)) {
  10999. offset += rgn23_data[offset + 1] * 4 + 4;
  11000. continue;
  11001. }
  11002. /* Driver found a driver specific TLV in the config region */
  11003. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11004. offset += 4;
  11005. tlv_offset = 0;
  11006. /*
  11007. * Search for configured port state sub-TLV.
  11008. */
  11009. while ((offset < data_size) &&
  11010. (tlv_offset < sub_tlv_len)) {
  11011. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11012. offset += 4;
  11013. tlv_offset += 4;
  11014. break;
  11015. }
  11016. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11017. offset += rgn23_data[offset + 1] * 4 + 4;
  11018. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11019. continue;
  11020. }
  11021. /* This HBA contains PORT_STE configured */
  11022. if (!rgn23_data[offset + 2])
  11023. phba->hba_flag |= LINK_DISABLED;
  11024. goto out;
  11025. }
  11026. }
  11027. out:
  11028. if (pmb)
  11029. mempool_free(pmb, phba->mbox_mem_pool);
  11030. kfree(rgn23_data);
  11031. return;
  11032. }