lpfc_sli.c 357 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576
  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 "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_logmsg.h"
  41. #include "lpfc_compat.h"
  42. #include "lpfc_debugfs.h"
  43. #include "lpfc_vport.h"
  44. /* There are only four IOCB completion types. */
  45. typedef enum _lpfc_iocb_type {
  46. LPFC_UNKNOWN_IOCB,
  47. LPFC_UNSOL_IOCB,
  48. LPFC_SOL_IOCB,
  49. LPFC_ABORT_IOCB
  50. } lpfc_iocb_type;
  51. /* Provide function prototypes local to this module. */
  52. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  53. uint32_t);
  54. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint8_t *, uint32_t *);
  56. static IOCB_t *
  57. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  58. {
  59. return &iocbq->iocb;
  60. }
  61. /**
  62. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  63. * @q: The Work Queue to operate on.
  64. * @wqe: The work Queue Entry to put on the Work queue.
  65. *
  66. * This routine will copy the contents of @wqe to the next available entry on
  67. * the @q. This function will then ring the Work Queue Doorbell to signal the
  68. * HBA to start processing the Work Queue Entry. This function returns 0 if
  69. * successful. If no entries are available on @q then this function will return
  70. * -ENOMEM.
  71. * The caller is expected to hold the hbalock when calling this routine.
  72. **/
  73. static uint32_t
  74. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  75. {
  76. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  77. struct lpfc_register doorbell;
  78. uint32_t host_index;
  79. /* If the host has not yet processed the next entry then we are done */
  80. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  81. return -ENOMEM;
  82. /* set consumption flag every once in a while */
  83. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  84. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  85. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  86. /* Update the host index before invoking device */
  87. host_index = q->host_index;
  88. q->host_index = ((q->host_index + 1) % q->entry_count);
  89. /* Ring Doorbell */
  90. doorbell.word0 = 0;
  91. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  92. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  93. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  94. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  95. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  96. return 0;
  97. }
  98. /**
  99. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  100. * @q: The Work Queue to operate on.
  101. * @index: The index to advance the hba index to.
  102. *
  103. * This routine will update the HBA index of a queue to reflect consumption of
  104. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  105. * an entry the host calls this function to update the queue's internal
  106. * pointers. This routine returns the number of entries that were consumed by
  107. * the HBA.
  108. **/
  109. static uint32_t
  110. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  111. {
  112. uint32_t released = 0;
  113. if (q->hba_index == index)
  114. return 0;
  115. do {
  116. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  117. released++;
  118. } while (q->hba_index != index);
  119. return released;
  120. }
  121. /**
  122. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  123. * @q: The Mailbox Queue to operate on.
  124. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  125. *
  126. * This routine will copy the contents of @mqe to the next available entry on
  127. * the @q. This function will then ring the Work Queue Doorbell to signal the
  128. * HBA to start processing the Work Queue Entry. This function returns 0 if
  129. * successful. If no entries are available on @q then this function will return
  130. * -ENOMEM.
  131. * The caller is expected to hold the hbalock when calling this routine.
  132. **/
  133. static uint32_t
  134. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  135. {
  136. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  137. struct lpfc_register doorbell;
  138. uint32_t host_index;
  139. /* If the host has not yet processed the next entry then we are done */
  140. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  141. return -ENOMEM;
  142. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  143. /* Save off the mailbox pointer for completion */
  144. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  145. /* Update the host index before invoking device */
  146. host_index = q->host_index;
  147. q->host_index = ((q->host_index + 1) % q->entry_count);
  148. /* Ring Doorbell */
  149. doorbell.word0 = 0;
  150. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  151. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  152. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  153. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  154. return 0;
  155. }
  156. /**
  157. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  158. * @q: The Mailbox Queue to operate on.
  159. *
  160. * This routine will update the HBA index of a queue to reflect consumption of
  161. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  162. * an entry the host calls this function to update the queue's internal
  163. * pointers. This routine returns the number of entries that were consumed by
  164. * the HBA.
  165. **/
  166. static uint32_t
  167. lpfc_sli4_mq_release(struct lpfc_queue *q)
  168. {
  169. /* Clear the mailbox pointer for completion */
  170. q->phba->mbox = NULL;
  171. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  172. return 1;
  173. }
  174. /**
  175. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  176. * @q: The Event Queue to get the first valid EQE from
  177. *
  178. * This routine will get the first valid Event Queue Entry from @q, update
  179. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  180. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  181. * processed, but not popped back to the HBA then this routine will return NULL.
  182. **/
  183. static struct lpfc_eqe *
  184. lpfc_sli4_eq_get(struct lpfc_queue *q)
  185. {
  186. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  187. /* If the next EQE is not valid then we are done */
  188. if (!bf_get(lpfc_eqe_valid, eqe))
  189. return NULL;
  190. /* If the host has not yet processed the next entry then we are done */
  191. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  192. return NULL;
  193. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  194. return eqe;
  195. }
  196. /**
  197. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  198. * @q: The Event Queue that the host has completed processing for.
  199. * @arm: Indicates whether the host wants to arms this CQ.
  200. *
  201. * This routine will mark all Event Queue Entries on @q, from the last
  202. * known completed entry to the last entry that was processed, as completed
  203. * by clearing the valid bit for each completion queue entry. Then it will
  204. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  205. * The internal host index in the @q will be updated by this routine to indicate
  206. * that the host has finished processing the entries. The @arm parameter
  207. * indicates that the queue should be rearmed when ringing the doorbell.
  208. *
  209. * This function will return the number of EQEs that were popped.
  210. **/
  211. uint32_t
  212. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  213. {
  214. uint32_t released = 0;
  215. struct lpfc_eqe *temp_eqe;
  216. struct lpfc_register doorbell;
  217. /* while there are valid entries */
  218. while (q->hba_index != q->host_index) {
  219. temp_eqe = q->qe[q->host_index].eqe;
  220. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  221. released++;
  222. q->host_index = ((q->host_index + 1) % q->entry_count);
  223. }
  224. if (unlikely(released == 0 && !arm))
  225. return 0;
  226. /* ring doorbell for number popped */
  227. doorbell.word0 = 0;
  228. if (arm) {
  229. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  230. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  231. }
  232. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  233. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  234. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  235. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  236. return released;
  237. }
  238. /**
  239. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  240. * @q: The Completion Queue to get the first valid CQE from
  241. *
  242. * This routine will get the first valid Completion Queue Entry from @q, update
  243. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  244. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  245. * processed, but not popped back to the HBA then this routine will return NULL.
  246. **/
  247. static struct lpfc_cqe *
  248. lpfc_sli4_cq_get(struct lpfc_queue *q)
  249. {
  250. struct lpfc_cqe *cqe;
  251. /* If the next CQE is not valid then we are done */
  252. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  253. return NULL;
  254. /* If the host has not yet processed the next entry then we are done */
  255. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  256. return NULL;
  257. cqe = q->qe[q->hba_index].cqe;
  258. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  259. return cqe;
  260. }
  261. /**
  262. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  263. * @q: The Completion Queue that the host has completed processing for.
  264. * @arm: Indicates whether the host wants to arms this CQ.
  265. *
  266. * This routine will mark all Completion queue entries on @q, from the last
  267. * known completed entry to the last entry that was processed, as completed
  268. * by clearing the valid bit for each completion queue entry. Then it will
  269. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  270. * The internal host index in the @q will be updated by this routine to indicate
  271. * that the host has finished processing the entries. The @arm parameter
  272. * indicates that the queue should be rearmed when ringing the doorbell.
  273. *
  274. * This function will return the number of CQEs that were released.
  275. **/
  276. uint32_t
  277. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  278. {
  279. uint32_t released = 0;
  280. struct lpfc_cqe *temp_qe;
  281. struct lpfc_register doorbell;
  282. /* while there are valid entries */
  283. while (q->hba_index != q->host_index) {
  284. temp_qe = q->qe[q->host_index].cqe;
  285. bf_set(lpfc_cqe_valid, temp_qe, 0);
  286. released++;
  287. q->host_index = ((q->host_index + 1) % q->entry_count);
  288. }
  289. if (unlikely(released == 0 && !arm))
  290. return 0;
  291. /* ring doorbell for number popped */
  292. doorbell.word0 = 0;
  293. if (arm)
  294. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  295. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  296. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  297. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  298. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  299. return released;
  300. }
  301. /**
  302. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  303. * @q: The Header Receive Queue to operate on.
  304. * @wqe: The Receive Queue Entry to put on the Receive queue.
  305. *
  306. * This routine will copy the contents of @wqe to the next available entry on
  307. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  308. * HBA to start processing the Receive Queue Entry. This function returns the
  309. * index that the rqe was copied to if successful. If no entries are available
  310. * on @q then this function will return -ENOMEM.
  311. * The caller is expected to hold the hbalock when calling this routine.
  312. **/
  313. static int
  314. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  315. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  316. {
  317. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  318. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  319. struct lpfc_register doorbell;
  320. int put_index = hq->host_index;
  321. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  322. return -EINVAL;
  323. if (hq->host_index != dq->host_index)
  324. return -EINVAL;
  325. /* If the host has not yet processed the next entry then we are done */
  326. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  327. return -EBUSY;
  328. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  329. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  330. /* Update the host index to point to the next slot */
  331. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  332. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  333. /* Ring The Header Receive Queue Doorbell */
  334. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  335. doorbell.word0 = 0;
  336. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  337. LPFC_RQ_POST_BATCH);
  338. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  339. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  340. }
  341. return put_index;
  342. }
  343. /**
  344. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  345. * @q: The Header Receive Queue to operate on.
  346. *
  347. * This routine will update the HBA index of a queue to reflect consumption of
  348. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  349. * consumed an entry the host calls this function to update the queue's
  350. * internal pointers. This routine returns the number of entries that were
  351. * consumed by the HBA.
  352. **/
  353. static uint32_t
  354. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  355. {
  356. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  357. return 0;
  358. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  359. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  360. return 1;
  361. }
  362. /**
  363. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  364. * @phba: Pointer to HBA context object.
  365. * @pring: Pointer to driver SLI ring object.
  366. *
  367. * This function returns pointer to next command iocb entry
  368. * in the command ring. The caller must hold hbalock to prevent
  369. * other threads consume the next command iocb.
  370. * SLI-2/SLI-3 provide different sized iocbs.
  371. **/
  372. static inline IOCB_t *
  373. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  374. {
  375. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  376. pring->cmdidx * phba->iocb_cmd_size);
  377. }
  378. /**
  379. * lpfc_resp_iocb - Get next response iocb entry in the ring
  380. * @phba: Pointer to HBA context object.
  381. * @pring: Pointer to driver SLI ring object.
  382. *
  383. * This function returns pointer to next response iocb entry
  384. * in the response ring. The caller must hold hbalock to make sure
  385. * that no other thread consume the next response iocb.
  386. * SLI-2/SLI-3 provide different sized iocbs.
  387. **/
  388. static inline IOCB_t *
  389. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  390. {
  391. return (IOCB_t *) (((char *) pring->rspringaddr) +
  392. pring->rspidx * phba->iocb_rsp_size);
  393. }
  394. /**
  395. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  396. * @phba: Pointer to HBA context object.
  397. *
  398. * This function is called with hbalock held. This function
  399. * allocates a new driver iocb object from the iocb pool. If the
  400. * allocation is successful, it returns pointer to the newly
  401. * allocated iocb object else it returns NULL.
  402. **/
  403. static struct lpfc_iocbq *
  404. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  405. {
  406. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  407. struct lpfc_iocbq * iocbq = NULL;
  408. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  409. return iocbq;
  410. }
  411. /**
  412. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  413. * @phba: Pointer to HBA context object.
  414. * @xritag: XRI value.
  415. *
  416. * This function clears the sglq pointer from the array of acive
  417. * sglq's. The xritag that is passed in is used to index into the
  418. * array. Before the xritag can be used it needs to be adjusted
  419. * by subtracting the xribase.
  420. *
  421. * Returns sglq ponter = success, NULL = Failure.
  422. **/
  423. static struct lpfc_sglq *
  424. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  425. {
  426. uint16_t adj_xri;
  427. struct lpfc_sglq *sglq;
  428. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  429. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  430. return NULL;
  431. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  432. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  433. return sglq;
  434. }
  435. /**
  436. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  437. * @phba: Pointer to HBA context object.
  438. * @xritag: XRI value.
  439. *
  440. * This function returns the sglq pointer from the array of acive
  441. * sglq's. The xritag that is passed in is used to index into the
  442. * array. Before the xritag can be used it needs to be adjusted
  443. * by subtracting the xribase.
  444. *
  445. * Returns sglq ponter = success, NULL = Failure.
  446. **/
  447. static struct lpfc_sglq *
  448. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  449. {
  450. uint16_t adj_xri;
  451. struct lpfc_sglq *sglq;
  452. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  453. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  454. return NULL;
  455. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  456. return sglq;
  457. }
  458. /**
  459. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  460. * @phba: Pointer to HBA context object.
  461. *
  462. * This function is called with hbalock held. This function
  463. * Gets a new driver sglq object from the sglq list. If the
  464. * list is not empty then it is successful, it returns pointer to the newly
  465. * allocated sglq object else it returns NULL.
  466. **/
  467. static struct lpfc_sglq *
  468. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  469. {
  470. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  471. struct lpfc_sglq *sglq = NULL;
  472. uint16_t adj_xri;
  473. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  474. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  475. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  476. return sglq;
  477. }
  478. /**
  479. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  480. * @phba: Pointer to HBA context object.
  481. *
  482. * This function is called with no lock held. This function
  483. * allocates a new driver iocb object from the iocb pool. If the
  484. * allocation is successful, it returns pointer to the newly
  485. * allocated iocb object else it returns NULL.
  486. **/
  487. struct lpfc_iocbq *
  488. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  489. {
  490. struct lpfc_iocbq * iocbq = NULL;
  491. unsigned long iflags;
  492. spin_lock_irqsave(&phba->hbalock, iflags);
  493. iocbq = __lpfc_sli_get_iocbq(phba);
  494. spin_unlock_irqrestore(&phba->hbalock, iflags);
  495. return iocbq;
  496. }
  497. /**
  498. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  499. * @phba: Pointer to HBA context object.
  500. * @iocbq: Pointer to driver iocb object.
  501. *
  502. * This function is called with hbalock held to release driver
  503. * iocb object to the iocb pool. The iotag in the iocb object
  504. * does not change for each use of the iocb object. This function
  505. * clears all other fields of the iocb object when it is freed.
  506. * The sqlq structure that holds the xritag and phys and virtual
  507. * mappings for the scatter gather list is retrieved from the
  508. * active array of sglq. The get of the sglq pointer also clears
  509. * the entry in the array. If the status of the IO indiactes that
  510. * this IO was aborted then the sglq entry it put on the
  511. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  512. * IO has good status or fails for any other reason then the sglq
  513. * entry is added to the free list (lpfc_sgl_list).
  514. **/
  515. static void
  516. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  517. {
  518. struct lpfc_sglq *sglq;
  519. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  520. unsigned long iflag;
  521. if (iocbq->sli4_xritag == NO_XRI)
  522. sglq = NULL;
  523. else
  524. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  525. if (sglq) {
  526. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  527. || ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  528. && (iocbq->iocb.un.ulpWord[4]
  529. == IOERR_SLI_ABORTED))) {
  530. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  531. iflag);
  532. list_add(&sglq->list,
  533. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  534. spin_unlock_irqrestore(
  535. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  536. } else
  537. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  538. }
  539. /*
  540. * Clean all volatile data fields, preserve iotag and node struct.
  541. */
  542. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  543. iocbq->sli4_xritag = NO_XRI;
  544. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  545. }
  546. /**
  547. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  548. * @phba: Pointer to HBA context object.
  549. * @iocbq: Pointer to driver iocb object.
  550. *
  551. * This function is called with hbalock held to release driver
  552. * iocb object to the iocb pool. The iotag in the iocb object
  553. * does not change for each use of the iocb object. This function
  554. * clears all other fields of the iocb object when it is freed.
  555. **/
  556. static void
  557. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  558. {
  559. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  560. /*
  561. * Clean all volatile data fields, preserve iotag and node struct.
  562. */
  563. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  564. iocbq->sli4_xritag = NO_XRI;
  565. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  566. }
  567. /**
  568. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  569. * @phba: Pointer to HBA context object.
  570. * @iocbq: Pointer to driver iocb object.
  571. *
  572. * This function is called with hbalock held to release driver
  573. * iocb object to the iocb pool. The iotag in the iocb object
  574. * does not change for each use of the iocb object. This function
  575. * clears all other fields of the iocb object when it is freed.
  576. **/
  577. static void
  578. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  579. {
  580. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  581. }
  582. /**
  583. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  584. * @phba: Pointer to HBA context object.
  585. * @iocbq: Pointer to driver iocb object.
  586. *
  587. * This function is called with no lock held to release the iocb to
  588. * iocb pool.
  589. **/
  590. void
  591. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  592. {
  593. unsigned long iflags;
  594. /*
  595. * Clean all volatile data fields, preserve iotag and node struct.
  596. */
  597. spin_lock_irqsave(&phba->hbalock, iflags);
  598. __lpfc_sli_release_iocbq(phba, iocbq);
  599. spin_unlock_irqrestore(&phba->hbalock, iflags);
  600. }
  601. /**
  602. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  603. * @phba: Pointer to HBA context object.
  604. * @iocblist: List of IOCBs.
  605. * @ulpstatus: ULP status in IOCB command field.
  606. * @ulpWord4: ULP word-4 in IOCB command field.
  607. *
  608. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  609. * on the list by invoking the complete callback function associated with the
  610. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  611. * fields.
  612. **/
  613. void
  614. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  615. uint32_t ulpstatus, uint32_t ulpWord4)
  616. {
  617. struct lpfc_iocbq *piocb;
  618. while (!list_empty(iocblist)) {
  619. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  620. if (!piocb->iocb_cmpl)
  621. lpfc_sli_release_iocbq(phba, piocb);
  622. else {
  623. piocb->iocb.ulpStatus = ulpstatus;
  624. piocb->iocb.un.ulpWord[4] = ulpWord4;
  625. (piocb->iocb_cmpl) (phba, piocb, piocb);
  626. }
  627. }
  628. return;
  629. }
  630. /**
  631. * lpfc_sli_iocb_cmd_type - Get the iocb type
  632. * @iocb_cmnd: iocb command code.
  633. *
  634. * This function is called by ring event handler function to get the iocb type.
  635. * This function translates the iocb command to an iocb command type used to
  636. * decide the final disposition of each completed IOCB.
  637. * The function returns
  638. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  639. * LPFC_SOL_IOCB if it is a solicited iocb completion
  640. * LPFC_ABORT_IOCB if it is an abort iocb
  641. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  642. *
  643. * The caller is not required to hold any lock.
  644. **/
  645. static lpfc_iocb_type
  646. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  647. {
  648. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  649. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  650. return 0;
  651. switch (iocb_cmnd) {
  652. case CMD_XMIT_SEQUENCE_CR:
  653. case CMD_XMIT_SEQUENCE_CX:
  654. case CMD_XMIT_BCAST_CN:
  655. case CMD_XMIT_BCAST_CX:
  656. case CMD_ELS_REQUEST_CR:
  657. case CMD_ELS_REQUEST_CX:
  658. case CMD_CREATE_XRI_CR:
  659. case CMD_CREATE_XRI_CX:
  660. case CMD_GET_RPI_CN:
  661. case CMD_XMIT_ELS_RSP_CX:
  662. case CMD_GET_RPI_CR:
  663. case CMD_FCP_IWRITE_CR:
  664. case CMD_FCP_IWRITE_CX:
  665. case CMD_FCP_IREAD_CR:
  666. case CMD_FCP_IREAD_CX:
  667. case CMD_FCP_ICMND_CR:
  668. case CMD_FCP_ICMND_CX:
  669. case CMD_FCP_TSEND_CX:
  670. case CMD_FCP_TRSP_CX:
  671. case CMD_FCP_TRECEIVE_CX:
  672. case CMD_FCP_AUTO_TRSP_CX:
  673. case CMD_ADAPTER_MSG:
  674. case CMD_ADAPTER_DUMP:
  675. case CMD_XMIT_SEQUENCE64_CR:
  676. case CMD_XMIT_SEQUENCE64_CX:
  677. case CMD_XMIT_BCAST64_CN:
  678. case CMD_XMIT_BCAST64_CX:
  679. case CMD_ELS_REQUEST64_CR:
  680. case CMD_ELS_REQUEST64_CX:
  681. case CMD_FCP_IWRITE64_CR:
  682. case CMD_FCP_IWRITE64_CX:
  683. case CMD_FCP_IREAD64_CR:
  684. case CMD_FCP_IREAD64_CX:
  685. case CMD_FCP_ICMND64_CR:
  686. case CMD_FCP_ICMND64_CX:
  687. case CMD_FCP_TSEND64_CX:
  688. case CMD_FCP_TRSP64_CX:
  689. case CMD_FCP_TRECEIVE64_CX:
  690. case CMD_GEN_REQUEST64_CR:
  691. case CMD_GEN_REQUEST64_CX:
  692. case CMD_XMIT_ELS_RSP64_CX:
  693. case DSSCMD_IWRITE64_CR:
  694. case DSSCMD_IWRITE64_CX:
  695. case DSSCMD_IREAD64_CR:
  696. case DSSCMD_IREAD64_CX:
  697. case DSSCMD_INVALIDATE_DEK:
  698. case DSSCMD_SET_KEK:
  699. case DSSCMD_GET_KEK_ID:
  700. case DSSCMD_GEN_XFER:
  701. type = LPFC_SOL_IOCB;
  702. break;
  703. case CMD_ABORT_XRI_CN:
  704. case CMD_ABORT_XRI_CX:
  705. case CMD_CLOSE_XRI_CN:
  706. case CMD_CLOSE_XRI_CX:
  707. case CMD_XRI_ABORTED_CX:
  708. case CMD_ABORT_MXRI64_CN:
  709. type = LPFC_ABORT_IOCB;
  710. break;
  711. case CMD_RCV_SEQUENCE_CX:
  712. case CMD_RCV_ELS_REQ_CX:
  713. case CMD_RCV_SEQUENCE64_CX:
  714. case CMD_RCV_ELS_REQ64_CX:
  715. case CMD_ASYNC_STATUS:
  716. case CMD_IOCB_RCV_SEQ64_CX:
  717. case CMD_IOCB_RCV_ELS64_CX:
  718. case CMD_IOCB_RCV_CONT64_CX:
  719. case CMD_IOCB_RET_XRI64_CX:
  720. type = LPFC_UNSOL_IOCB;
  721. break;
  722. case CMD_IOCB_XMIT_MSEQ64_CR:
  723. case CMD_IOCB_XMIT_MSEQ64_CX:
  724. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  725. case CMD_IOCB_RCV_ELS_LIST64_CX:
  726. case CMD_IOCB_CLOSE_EXTENDED_CN:
  727. case CMD_IOCB_ABORT_EXTENDED_CN:
  728. case CMD_IOCB_RET_HBQE64_CN:
  729. case CMD_IOCB_FCP_IBIDIR64_CR:
  730. case CMD_IOCB_FCP_IBIDIR64_CX:
  731. case CMD_IOCB_FCP_ITASKMGT64_CX:
  732. case CMD_IOCB_LOGENTRY_CN:
  733. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  734. printk("%s - Unhandled SLI-3 Command x%x\n",
  735. __func__, iocb_cmnd);
  736. type = LPFC_UNKNOWN_IOCB;
  737. break;
  738. default:
  739. type = LPFC_UNKNOWN_IOCB;
  740. break;
  741. }
  742. return type;
  743. }
  744. /**
  745. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  746. * @phba: Pointer to HBA context object.
  747. *
  748. * This function is called from SLI initialization code
  749. * to configure every ring of the HBA's SLI interface. The
  750. * caller is not required to hold any lock. This function issues
  751. * a config_ring mailbox command for each ring.
  752. * This function returns zero if successful else returns a negative
  753. * error code.
  754. **/
  755. static int
  756. lpfc_sli_ring_map(struct lpfc_hba *phba)
  757. {
  758. struct lpfc_sli *psli = &phba->sli;
  759. LPFC_MBOXQ_t *pmb;
  760. MAILBOX_t *pmbox;
  761. int i, rc, ret = 0;
  762. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  763. if (!pmb)
  764. return -ENOMEM;
  765. pmbox = &pmb->u.mb;
  766. phba->link_state = LPFC_INIT_MBX_CMDS;
  767. for (i = 0; i < psli->num_rings; i++) {
  768. lpfc_config_ring(phba, i, pmb);
  769. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  770. if (rc != MBX_SUCCESS) {
  771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  772. "0446 Adapter failed to init (%d), "
  773. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  774. "ring %d\n",
  775. rc, pmbox->mbxCommand,
  776. pmbox->mbxStatus, i);
  777. phba->link_state = LPFC_HBA_ERROR;
  778. ret = -ENXIO;
  779. break;
  780. }
  781. }
  782. mempool_free(pmb, phba->mbox_mem_pool);
  783. return ret;
  784. }
  785. /**
  786. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  787. * @phba: Pointer to HBA context object.
  788. * @pring: Pointer to driver SLI ring object.
  789. * @piocb: Pointer to the driver iocb object.
  790. *
  791. * This function is called with hbalock held. The function adds the
  792. * new iocb to txcmplq of the given ring. This function always returns
  793. * 0. If this function is called for ELS ring, this function checks if
  794. * there is a vport associated with the ELS command. This function also
  795. * starts els_tmofunc timer if this is an ELS command.
  796. **/
  797. static int
  798. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  799. struct lpfc_iocbq *piocb)
  800. {
  801. list_add_tail(&piocb->list, &pring->txcmplq);
  802. pring->txcmplq_cnt++;
  803. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  804. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  805. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  806. if (!piocb->vport)
  807. BUG();
  808. else
  809. mod_timer(&piocb->vport->els_tmofunc,
  810. jiffies + HZ * (phba->fc_ratov << 1));
  811. }
  812. return 0;
  813. }
  814. /**
  815. * lpfc_sli_ringtx_get - Get first element of the txq
  816. * @phba: Pointer to HBA context object.
  817. * @pring: Pointer to driver SLI ring object.
  818. *
  819. * This function is called with hbalock held to get next
  820. * iocb in txq of the given ring. If there is any iocb in
  821. * the txq, the function returns first iocb in the list after
  822. * removing the iocb from the list, else it returns NULL.
  823. **/
  824. static struct lpfc_iocbq *
  825. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  826. {
  827. struct lpfc_iocbq *cmd_iocb;
  828. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  829. if (cmd_iocb != NULL)
  830. pring->txq_cnt--;
  831. return cmd_iocb;
  832. }
  833. /**
  834. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  835. * @phba: Pointer to HBA context object.
  836. * @pring: Pointer to driver SLI ring object.
  837. *
  838. * This function is called with hbalock held and the caller must post the
  839. * iocb without releasing the lock. If the caller releases the lock,
  840. * iocb slot returned by the function is not guaranteed to be available.
  841. * The function returns pointer to the next available iocb slot if there
  842. * is available slot in the ring, else it returns NULL.
  843. * If the get index of the ring is ahead of the put index, the function
  844. * will post an error attention event to the worker thread to take the
  845. * HBA to offline state.
  846. **/
  847. static IOCB_t *
  848. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  849. {
  850. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  851. uint32_t max_cmd_idx = pring->numCiocb;
  852. if ((pring->next_cmdidx == pring->cmdidx) &&
  853. (++pring->next_cmdidx >= max_cmd_idx))
  854. pring->next_cmdidx = 0;
  855. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  856. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  857. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  859. "0315 Ring %d issue: portCmdGet %d "
  860. "is bigger than cmd ring %d\n",
  861. pring->ringno,
  862. pring->local_getidx, max_cmd_idx);
  863. phba->link_state = LPFC_HBA_ERROR;
  864. /*
  865. * All error attention handlers are posted to
  866. * worker thread
  867. */
  868. phba->work_ha |= HA_ERATT;
  869. phba->work_hs = HS_FFER3;
  870. lpfc_worker_wake_up(phba);
  871. return NULL;
  872. }
  873. if (pring->local_getidx == pring->next_cmdidx)
  874. return NULL;
  875. }
  876. return lpfc_cmd_iocb(phba, pring);
  877. }
  878. /**
  879. * lpfc_sli_next_iotag - Get an iotag for the iocb
  880. * @phba: Pointer to HBA context object.
  881. * @iocbq: Pointer to driver iocb object.
  882. *
  883. * This function gets an iotag for the iocb. If there is no unused iotag and
  884. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  885. * array and assigns a new iotag.
  886. * The function returns the allocated iotag if successful, else returns zero.
  887. * Zero is not a valid iotag.
  888. * The caller is not required to hold any lock.
  889. **/
  890. uint16_t
  891. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  892. {
  893. struct lpfc_iocbq **new_arr;
  894. struct lpfc_iocbq **old_arr;
  895. size_t new_len;
  896. struct lpfc_sli *psli = &phba->sli;
  897. uint16_t iotag;
  898. spin_lock_irq(&phba->hbalock);
  899. iotag = psli->last_iotag;
  900. if(++iotag < psli->iocbq_lookup_len) {
  901. psli->last_iotag = iotag;
  902. psli->iocbq_lookup[iotag] = iocbq;
  903. spin_unlock_irq(&phba->hbalock);
  904. iocbq->iotag = iotag;
  905. return iotag;
  906. } else if (psli->iocbq_lookup_len < (0xffff
  907. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  908. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  909. spin_unlock_irq(&phba->hbalock);
  910. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  911. GFP_KERNEL);
  912. if (new_arr) {
  913. spin_lock_irq(&phba->hbalock);
  914. old_arr = psli->iocbq_lookup;
  915. if (new_len <= psli->iocbq_lookup_len) {
  916. /* highly unprobable case */
  917. kfree(new_arr);
  918. iotag = psli->last_iotag;
  919. if(++iotag < psli->iocbq_lookup_len) {
  920. psli->last_iotag = iotag;
  921. psli->iocbq_lookup[iotag] = iocbq;
  922. spin_unlock_irq(&phba->hbalock);
  923. iocbq->iotag = iotag;
  924. return iotag;
  925. }
  926. spin_unlock_irq(&phba->hbalock);
  927. return 0;
  928. }
  929. if (psli->iocbq_lookup)
  930. memcpy(new_arr, old_arr,
  931. ((psli->last_iotag + 1) *
  932. sizeof (struct lpfc_iocbq *)));
  933. psli->iocbq_lookup = new_arr;
  934. psli->iocbq_lookup_len = new_len;
  935. psli->last_iotag = iotag;
  936. psli->iocbq_lookup[iotag] = iocbq;
  937. spin_unlock_irq(&phba->hbalock);
  938. iocbq->iotag = iotag;
  939. kfree(old_arr);
  940. return iotag;
  941. }
  942. } else
  943. spin_unlock_irq(&phba->hbalock);
  944. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  945. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  946. psli->last_iotag);
  947. return 0;
  948. }
  949. /**
  950. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  951. * @phba: Pointer to HBA context object.
  952. * @pring: Pointer to driver SLI ring object.
  953. * @iocb: Pointer to iocb slot in the ring.
  954. * @nextiocb: Pointer to driver iocb object which need to be
  955. * posted to firmware.
  956. *
  957. * This function is called with hbalock held to post a new iocb to
  958. * the firmware. This function copies the new iocb to ring iocb slot and
  959. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  960. * a completion call back for this iocb else the function will free the
  961. * iocb object.
  962. **/
  963. static void
  964. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  965. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  966. {
  967. /*
  968. * Set up an iotag
  969. */
  970. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  971. if (pring->ringno == LPFC_ELS_RING) {
  972. lpfc_debugfs_slow_ring_trc(phba,
  973. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  974. *(((uint32_t *) &nextiocb->iocb) + 4),
  975. *(((uint32_t *) &nextiocb->iocb) + 6),
  976. *(((uint32_t *) &nextiocb->iocb) + 7));
  977. }
  978. /*
  979. * Issue iocb command to adapter
  980. */
  981. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  982. wmb();
  983. pring->stats.iocb_cmd++;
  984. /*
  985. * If there is no completion routine to call, we can release the
  986. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  987. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  988. */
  989. if (nextiocb->iocb_cmpl)
  990. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  991. else
  992. __lpfc_sli_release_iocbq(phba, nextiocb);
  993. /*
  994. * Let the HBA know what IOCB slot will be the next one the
  995. * driver will put a command into.
  996. */
  997. pring->cmdidx = pring->next_cmdidx;
  998. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  999. }
  1000. /**
  1001. * lpfc_sli_update_full_ring - Update the chip attention register
  1002. * @phba: Pointer to HBA context object.
  1003. * @pring: Pointer to driver SLI ring object.
  1004. *
  1005. * The caller is not required to hold any lock for calling this function.
  1006. * This function updates the chip attention bits for the ring to inform firmware
  1007. * that there are pending work to be done for this ring and requests an
  1008. * interrupt when there is space available in the ring. This function is
  1009. * called when the driver is unable to post more iocbs to the ring due
  1010. * to unavailability of space in the ring.
  1011. **/
  1012. static void
  1013. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1014. {
  1015. int ringno = pring->ringno;
  1016. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1017. wmb();
  1018. /*
  1019. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1020. * The HBA will tell us when an IOCB entry is available.
  1021. */
  1022. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1023. readl(phba->CAregaddr); /* flush */
  1024. pring->stats.iocb_cmd_full++;
  1025. }
  1026. /**
  1027. * lpfc_sli_update_ring - Update chip attention register
  1028. * @phba: Pointer to HBA context object.
  1029. * @pring: Pointer to driver SLI ring object.
  1030. *
  1031. * This function updates the chip attention register bit for the
  1032. * given ring to inform HBA that there is more work to be done
  1033. * in this ring. The caller is not required to hold any lock.
  1034. **/
  1035. static void
  1036. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1037. {
  1038. int ringno = pring->ringno;
  1039. /*
  1040. * Tell the HBA that there is work to do in this ring.
  1041. */
  1042. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1043. wmb();
  1044. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1045. readl(phba->CAregaddr); /* flush */
  1046. }
  1047. }
  1048. /**
  1049. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1050. * @phba: Pointer to HBA context object.
  1051. * @pring: Pointer to driver SLI ring object.
  1052. *
  1053. * This function is called with hbalock held to post pending iocbs
  1054. * in the txq to the firmware. This function is called when driver
  1055. * detects space available in the ring.
  1056. **/
  1057. static void
  1058. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1059. {
  1060. IOCB_t *iocb;
  1061. struct lpfc_iocbq *nextiocb;
  1062. /*
  1063. * Check to see if:
  1064. * (a) there is anything on the txq to send
  1065. * (b) link is up
  1066. * (c) link attention events can be processed (fcp ring only)
  1067. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1068. */
  1069. if (pring->txq_cnt &&
  1070. lpfc_is_link_up(phba) &&
  1071. (pring->ringno != phba->sli.fcp_ring ||
  1072. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1073. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1074. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1075. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1076. if (iocb)
  1077. lpfc_sli_update_ring(phba, pring);
  1078. else
  1079. lpfc_sli_update_full_ring(phba, pring);
  1080. }
  1081. return;
  1082. }
  1083. /**
  1084. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1085. * @phba: Pointer to HBA context object.
  1086. * @hbqno: HBQ number.
  1087. *
  1088. * This function is called with hbalock held to get the next
  1089. * available slot for the given HBQ. If there is free slot
  1090. * available for the HBQ it will return pointer to the next available
  1091. * HBQ entry else it will return NULL.
  1092. **/
  1093. static struct lpfc_hbq_entry *
  1094. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1095. {
  1096. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1097. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1098. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1099. hbqp->next_hbqPutIdx = 0;
  1100. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1101. uint32_t raw_index = phba->hbq_get[hbqno];
  1102. uint32_t getidx = le32_to_cpu(raw_index);
  1103. hbqp->local_hbqGetIdx = getidx;
  1104. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1105. lpfc_printf_log(phba, KERN_ERR,
  1106. LOG_SLI | LOG_VPORT,
  1107. "1802 HBQ %d: local_hbqGetIdx "
  1108. "%u is > than hbqp->entry_count %u\n",
  1109. hbqno, hbqp->local_hbqGetIdx,
  1110. hbqp->entry_count);
  1111. phba->link_state = LPFC_HBA_ERROR;
  1112. return NULL;
  1113. }
  1114. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1115. return NULL;
  1116. }
  1117. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1118. hbqp->hbqPutIdx;
  1119. }
  1120. /**
  1121. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1122. * @phba: Pointer to HBA context object.
  1123. *
  1124. * This function is called with no lock held to free all the
  1125. * hbq buffers while uninitializing the SLI interface. It also
  1126. * frees the HBQ buffers returned by the firmware but not yet
  1127. * processed by the upper layers.
  1128. **/
  1129. void
  1130. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1131. {
  1132. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1133. struct hbq_dmabuf *hbq_buf;
  1134. unsigned long flags;
  1135. int i, hbq_count;
  1136. uint32_t hbqno;
  1137. hbq_count = lpfc_sli_hbq_count();
  1138. /* Return all memory used by all HBQs */
  1139. spin_lock_irqsave(&phba->hbalock, flags);
  1140. for (i = 0; i < hbq_count; ++i) {
  1141. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1142. &phba->hbqs[i].hbq_buffer_list, list) {
  1143. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1144. list_del(&hbq_buf->dbuf.list);
  1145. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1146. }
  1147. phba->hbqs[i].buffer_count = 0;
  1148. }
  1149. /* Return all HBQ buffer that are in-fly */
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1151. list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. if (hbq_buf->tag == -1) {
  1155. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1156. (phba, hbq_buf);
  1157. } else {
  1158. hbqno = hbq_buf->tag >> 16;
  1159. if (hbqno >= LPFC_MAX_HBQS)
  1160. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1161. (phba, hbq_buf);
  1162. else
  1163. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1164. hbq_buf);
  1165. }
  1166. }
  1167. /* Mark the HBQs not in use */
  1168. phba->hbq_in_use = 0;
  1169. spin_unlock_irqrestore(&phba->hbalock, flags);
  1170. }
  1171. /**
  1172. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1173. * @phba: Pointer to HBA context object.
  1174. * @hbqno: HBQ number.
  1175. * @hbq_buf: Pointer to HBQ buffer.
  1176. *
  1177. * This function is called with the hbalock held to post a
  1178. * hbq buffer to the firmware. If the function finds an empty
  1179. * slot in the HBQ, it will post the buffer. The function will return
  1180. * pointer to the hbq entry if it successfully post the buffer
  1181. * else it will return NULL.
  1182. **/
  1183. static int
  1184. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1185. struct hbq_dmabuf *hbq_buf)
  1186. {
  1187. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1188. }
  1189. /**
  1190. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1191. * @phba: Pointer to HBA context object.
  1192. * @hbqno: HBQ number.
  1193. * @hbq_buf: Pointer to HBQ buffer.
  1194. *
  1195. * This function is called with the hbalock held to post a hbq buffer to the
  1196. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1197. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1198. * it successfully post the buffer else it will return an error.
  1199. **/
  1200. static int
  1201. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1202. struct hbq_dmabuf *hbq_buf)
  1203. {
  1204. struct lpfc_hbq_entry *hbqe;
  1205. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1206. /* Get next HBQ entry slot to use */
  1207. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1208. if (hbqe) {
  1209. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1210. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1211. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1212. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1213. hbqe->bde.tus.f.bdeFlags = 0;
  1214. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1215. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1216. /* Sync SLIM */
  1217. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1218. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1219. /* flush */
  1220. readl(phba->hbq_put + hbqno);
  1221. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1222. return 0;
  1223. } else
  1224. return -ENOMEM;
  1225. }
  1226. /**
  1227. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1228. * @phba: Pointer to HBA context object.
  1229. * @hbqno: HBQ number.
  1230. * @hbq_buf: Pointer to HBQ buffer.
  1231. *
  1232. * This function is called with the hbalock held to post an RQE to the SLI4
  1233. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1234. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1235. **/
  1236. static int
  1237. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1238. struct hbq_dmabuf *hbq_buf)
  1239. {
  1240. int rc;
  1241. struct lpfc_rqe hrqe;
  1242. struct lpfc_rqe drqe;
  1243. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1244. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1245. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1246. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1247. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1248. &hrqe, &drqe);
  1249. if (rc < 0)
  1250. return rc;
  1251. hbq_buf->tag = rc;
  1252. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1253. return 0;
  1254. }
  1255. /* HBQ for ELS and CT traffic. */
  1256. static struct lpfc_hbq_init lpfc_els_hbq = {
  1257. .rn = 1,
  1258. .entry_count = 200,
  1259. .mask_count = 0,
  1260. .profile = 0,
  1261. .ring_mask = (1 << LPFC_ELS_RING),
  1262. .buffer_count = 0,
  1263. .init_count = 40,
  1264. .add_count = 40,
  1265. };
  1266. /* HBQ for the extra ring if needed */
  1267. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1268. .rn = 1,
  1269. .entry_count = 200,
  1270. .mask_count = 0,
  1271. .profile = 0,
  1272. .ring_mask = (1 << LPFC_EXTRA_RING),
  1273. .buffer_count = 0,
  1274. .init_count = 0,
  1275. .add_count = 5,
  1276. };
  1277. /* Array of HBQs */
  1278. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1279. &lpfc_els_hbq,
  1280. &lpfc_extra_hbq,
  1281. };
  1282. /**
  1283. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1284. * @phba: Pointer to HBA context object.
  1285. * @hbqno: HBQ number.
  1286. * @count: Number of HBQ buffers to be posted.
  1287. *
  1288. * This function is called with no lock held to post more hbq buffers to the
  1289. * given HBQ. The function returns the number of HBQ buffers successfully
  1290. * posted.
  1291. **/
  1292. static int
  1293. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1294. {
  1295. uint32_t i, posted = 0;
  1296. unsigned long flags;
  1297. struct hbq_dmabuf *hbq_buffer;
  1298. LIST_HEAD(hbq_buf_list);
  1299. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1300. return 0;
  1301. if ((phba->hbqs[hbqno].buffer_count + count) >
  1302. lpfc_hbq_defs[hbqno]->entry_count)
  1303. count = lpfc_hbq_defs[hbqno]->entry_count -
  1304. phba->hbqs[hbqno].buffer_count;
  1305. if (!count)
  1306. return 0;
  1307. /* Allocate HBQ entries */
  1308. for (i = 0; i < count; i++) {
  1309. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1310. if (!hbq_buffer)
  1311. break;
  1312. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1313. }
  1314. /* Check whether HBQ is still in use */
  1315. spin_lock_irqsave(&phba->hbalock, flags);
  1316. if (!phba->hbq_in_use)
  1317. goto err;
  1318. while (!list_empty(&hbq_buf_list)) {
  1319. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1320. dbuf.list);
  1321. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1322. (hbqno << 16));
  1323. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1324. phba->hbqs[hbqno].buffer_count++;
  1325. posted++;
  1326. } else
  1327. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1328. }
  1329. spin_unlock_irqrestore(&phba->hbalock, flags);
  1330. return posted;
  1331. err:
  1332. spin_unlock_irqrestore(&phba->hbalock, flags);
  1333. while (!list_empty(&hbq_buf_list)) {
  1334. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1335. dbuf.list);
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. return 0;
  1339. }
  1340. /**
  1341. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1342. * @phba: Pointer to HBA context object.
  1343. * @qno: HBQ number.
  1344. *
  1345. * This function posts more buffers to the HBQ. This function
  1346. * is called with no lock held. The function returns the number of HBQ entries
  1347. * successfully allocated.
  1348. **/
  1349. int
  1350. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1351. {
  1352. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1353. lpfc_hbq_defs[qno]->add_count));
  1354. }
  1355. /**
  1356. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1357. * @phba: Pointer to HBA context object.
  1358. * @qno: HBQ queue number.
  1359. *
  1360. * This function is called from SLI initialization code path with
  1361. * no lock held to post initial HBQ buffers to firmware. The
  1362. * function returns the number of HBQ entries successfully allocated.
  1363. **/
  1364. static int
  1365. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1366. {
  1367. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1368. lpfc_hbq_defs[qno]->init_count));
  1369. }
  1370. /**
  1371. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1372. * @phba: Pointer to HBA context object.
  1373. * @hbqno: HBQ number.
  1374. *
  1375. * This function removes the first hbq buffer on an hbq list and returns a
  1376. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1377. **/
  1378. static struct hbq_dmabuf *
  1379. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1380. {
  1381. struct lpfc_dmabuf *d_buf;
  1382. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1383. if (!d_buf)
  1384. return NULL;
  1385. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1386. }
  1387. /**
  1388. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1389. * @phba: Pointer to HBA context object.
  1390. * @tag: Tag of the hbq buffer.
  1391. *
  1392. * This function is called with hbalock held. This function searches
  1393. * for the hbq buffer associated with the given tag in the hbq buffer
  1394. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1395. * it returns NULL.
  1396. **/
  1397. static struct hbq_dmabuf *
  1398. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1399. {
  1400. struct lpfc_dmabuf *d_buf;
  1401. struct hbq_dmabuf *hbq_buf;
  1402. uint32_t hbqno;
  1403. hbqno = tag >> 16;
  1404. if (hbqno >= LPFC_MAX_HBQS)
  1405. return NULL;
  1406. spin_lock_irq(&phba->hbalock);
  1407. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1408. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1409. if (hbq_buf->tag == tag) {
  1410. spin_unlock_irq(&phba->hbalock);
  1411. return hbq_buf;
  1412. }
  1413. }
  1414. spin_unlock_irq(&phba->hbalock);
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1416. "1803 Bad hbq tag. Data: x%x x%x\n",
  1417. tag, phba->hbqs[tag >> 16].buffer_count);
  1418. return NULL;
  1419. }
  1420. /**
  1421. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1422. * @phba: Pointer to HBA context object.
  1423. * @hbq_buffer: Pointer to HBQ buffer.
  1424. *
  1425. * This function is called with hbalock. This function gives back
  1426. * the hbq buffer to firmware. If the HBQ does not have space to
  1427. * post the buffer, it will free the buffer.
  1428. **/
  1429. void
  1430. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1431. {
  1432. uint32_t hbqno;
  1433. if (hbq_buffer) {
  1434. hbqno = hbq_buffer->tag >> 16;
  1435. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1436. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1437. }
  1438. }
  1439. /**
  1440. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1441. * @mbxCommand: mailbox command code.
  1442. *
  1443. * This function is called by the mailbox event handler function to verify
  1444. * that the completed mailbox command is a legitimate mailbox command. If the
  1445. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1446. * and the mailbox event handler will take the HBA offline.
  1447. **/
  1448. static int
  1449. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1450. {
  1451. uint8_t ret;
  1452. switch (mbxCommand) {
  1453. case MBX_LOAD_SM:
  1454. case MBX_READ_NV:
  1455. case MBX_WRITE_NV:
  1456. case MBX_WRITE_VPARMS:
  1457. case MBX_RUN_BIU_DIAG:
  1458. case MBX_INIT_LINK:
  1459. case MBX_DOWN_LINK:
  1460. case MBX_CONFIG_LINK:
  1461. case MBX_CONFIG_RING:
  1462. case MBX_RESET_RING:
  1463. case MBX_READ_CONFIG:
  1464. case MBX_READ_RCONFIG:
  1465. case MBX_READ_SPARM:
  1466. case MBX_READ_STATUS:
  1467. case MBX_READ_RPI:
  1468. case MBX_READ_XRI:
  1469. case MBX_READ_REV:
  1470. case MBX_READ_LNK_STAT:
  1471. case MBX_REG_LOGIN:
  1472. case MBX_UNREG_LOGIN:
  1473. case MBX_READ_LA:
  1474. case MBX_CLEAR_LA:
  1475. case MBX_DUMP_MEMORY:
  1476. case MBX_DUMP_CONTEXT:
  1477. case MBX_RUN_DIAGS:
  1478. case MBX_RESTART:
  1479. case MBX_UPDATE_CFG:
  1480. case MBX_DOWN_LOAD:
  1481. case MBX_DEL_LD_ENTRY:
  1482. case MBX_RUN_PROGRAM:
  1483. case MBX_SET_MASK:
  1484. case MBX_SET_VARIABLE:
  1485. case MBX_UNREG_D_ID:
  1486. case MBX_KILL_BOARD:
  1487. case MBX_CONFIG_FARP:
  1488. case MBX_BEACON:
  1489. case MBX_LOAD_AREA:
  1490. case MBX_RUN_BIU_DIAG64:
  1491. case MBX_CONFIG_PORT:
  1492. case MBX_READ_SPARM64:
  1493. case MBX_READ_RPI64:
  1494. case MBX_REG_LOGIN64:
  1495. case MBX_READ_LA64:
  1496. case MBX_WRITE_WWN:
  1497. case MBX_SET_DEBUG:
  1498. case MBX_LOAD_EXP_ROM:
  1499. case MBX_ASYNCEVT_ENABLE:
  1500. case MBX_REG_VPI:
  1501. case MBX_UNREG_VPI:
  1502. case MBX_HEARTBEAT:
  1503. case MBX_PORT_CAPABILITIES:
  1504. case MBX_PORT_IOV_CONTROL:
  1505. case MBX_SLI4_CONFIG:
  1506. case MBX_SLI4_REQ_FTRS:
  1507. case MBX_REG_FCFI:
  1508. case MBX_UNREG_FCFI:
  1509. case MBX_REG_VFI:
  1510. case MBX_UNREG_VFI:
  1511. case MBX_INIT_VPI:
  1512. case MBX_INIT_VFI:
  1513. case MBX_RESUME_RPI:
  1514. ret = mbxCommand;
  1515. break;
  1516. default:
  1517. ret = MBX_SHUTDOWN;
  1518. break;
  1519. }
  1520. return ret;
  1521. }
  1522. /**
  1523. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1524. * @phba: Pointer to HBA context object.
  1525. * @pmboxq: Pointer to mailbox command.
  1526. *
  1527. * This is completion handler function for mailbox commands issued from
  1528. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1529. * mailbox event handler function with no lock held. This function
  1530. * will wake up thread waiting on the wait queue pointed by context1
  1531. * of the mailbox.
  1532. **/
  1533. void
  1534. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1535. {
  1536. wait_queue_head_t *pdone_q;
  1537. unsigned long drvr_flag;
  1538. /*
  1539. * If pdone_q is empty, the driver thread gave up waiting and
  1540. * continued running.
  1541. */
  1542. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1543. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1544. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1545. if (pdone_q)
  1546. wake_up_interruptible(pdone_q);
  1547. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1548. return;
  1549. }
  1550. /**
  1551. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1552. * @phba: Pointer to HBA context object.
  1553. * @pmb: Pointer to mailbox object.
  1554. *
  1555. * This function is the default mailbox completion handler. It
  1556. * frees the memory resources associated with the completed mailbox
  1557. * command. If the completed command is a REG_LOGIN mailbox command,
  1558. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1559. **/
  1560. void
  1561. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1562. {
  1563. struct lpfc_dmabuf *mp;
  1564. uint16_t rpi, vpi;
  1565. int rc;
  1566. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1567. if (mp) {
  1568. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1569. kfree(mp);
  1570. }
  1571. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1572. (phba->sli_rev == LPFC_SLI_REV4))
  1573. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1574. /*
  1575. * If a REG_LOGIN succeeded after node is destroyed or node
  1576. * is in re-discovery driver need to cleanup the RPI.
  1577. */
  1578. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1579. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1580. !pmb->u.mb.mbxStatus) {
  1581. rpi = pmb->u.mb.un.varWords[0];
  1582. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1583. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1584. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1585. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1586. if (rc != MBX_NOT_FINISHED)
  1587. return;
  1588. }
  1589. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1590. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1591. else
  1592. mempool_free(pmb, phba->mbox_mem_pool);
  1593. }
  1594. /**
  1595. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1596. * @phba: Pointer to HBA context object.
  1597. *
  1598. * This function is called with no lock held. This function processes all
  1599. * the completed mailbox commands and gives it to upper layers. The interrupt
  1600. * service routine processes mailbox completion interrupt and adds completed
  1601. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1602. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1603. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1604. * function returns the mailbox commands to the upper layer by calling the
  1605. * completion handler function of each mailbox.
  1606. **/
  1607. int
  1608. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1609. {
  1610. MAILBOX_t *pmbox;
  1611. LPFC_MBOXQ_t *pmb;
  1612. int rc;
  1613. LIST_HEAD(cmplq);
  1614. phba->sli.slistat.mbox_event++;
  1615. /* Get all completed mailboxe buffers into the cmplq */
  1616. spin_lock_irq(&phba->hbalock);
  1617. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1618. spin_unlock_irq(&phba->hbalock);
  1619. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1620. do {
  1621. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1622. if (pmb == NULL)
  1623. break;
  1624. pmbox = &pmb->u.mb;
  1625. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1626. if (pmb->vport) {
  1627. lpfc_debugfs_disc_trc(pmb->vport,
  1628. LPFC_DISC_TRC_MBOX_VPORT,
  1629. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1630. (uint32_t)pmbox->mbxCommand,
  1631. pmbox->un.varWords[0],
  1632. pmbox->un.varWords[1]);
  1633. }
  1634. else {
  1635. lpfc_debugfs_disc_trc(phba->pport,
  1636. LPFC_DISC_TRC_MBOX,
  1637. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1638. (uint32_t)pmbox->mbxCommand,
  1639. pmbox->un.varWords[0],
  1640. pmbox->un.varWords[1]);
  1641. }
  1642. }
  1643. /*
  1644. * It is a fatal error if unknown mbox command completion.
  1645. */
  1646. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1647. MBX_SHUTDOWN) {
  1648. /* Unknow mailbox command compl */
  1649. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1650. "(%d):0323 Unknown Mailbox command "
  1651. "x%x (x%x) Cmpl\n",
  1652. pmb->vport ? pmb->vport->vpi : 0,
  1653. pmbox->mbxCommand,
  1654. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1655. phba->link_state = LPFC_HBA_ERROR;
  1656. phba->work_hs = HS_FFER3;
  1657. lpfc_handle_eratt(phba);
  1658. continue;
  1659. }
  1660. if (pmbox->mbxStatus) {
  1661. phba->sli.slistat.mbox_stat_err++;
  1662. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1663. /* Mbox cmd cmpl error - RETRYing */
  1664. lpfc_printf_log(phba, KERN_INFO,
  1665. LOG_MBOX | LOG_SLI,
  1666. "(%d):0305 Mbox cmd cmpl "
  1667. "error - RETRYing Data: x%x "
  1668. "(x%x) x%x x%x x%x\n",
  1669. pmb->vport ? pmb->vport->vpi :0,
  1670. pmbox->mbxCommand,
  1671. lpfc_sli4_mbox_opcode_get(phba,
  1672. pmb),
  1673. pmbox->mbxStatus,
  1674. pmbox->un.varWords[0],
  1675. pmb->vport->port_state);
  1676. pmbox->mbxStatus = 0;
  1677. pmbox->mbxOwner = OWN_HOST;
  1678. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1679. if (rc != MBX_NOT_FINISHED)
  1680. continue;
  1681. }
  1682. }
  1683. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1684. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1685. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1686. "Data: x%x x%x x%x x%x x%x 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, pmb),
  1690. pmb->mbox_cmpl,
  1691. *((uint32_t *) pmbox),
  1692. pmbox->un.varWords[0],
  1693. pmbox->un.varWords[1],
  1694. pmbox->un.varWords[2],
  1695. pmbox->un.varWords[3],
  1696. pmbox->un.varWords[4],
  1697. pmbox->un.varWords[5],
  1698. pmbox->un.varWords[6],
  1699. pmbox->un.varWords[7]);
  1700. if (pmb->mbox_cmpl)
  1701. pmb->mbox_cmpl(phba,pmb);
  1702. } while (1);
  1703. return 0;
  1704. }
  1705. /**
  1706. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1707. * @phba: Pointer to HBA context object.
  1708. * @pring: Pointer to driver SLI ring object.
  1709. * @tag: buffer tag.
  1710. *
  1711. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1712. * is set in the tag the buffer is posted for a particular exchange,
  1713. * the function will return the buffer without replacing the buffer.
  1714. * If the buffer is for unsolicited ELS or CT traffic, this function
  1715. * returns the buffer and also posts another buffer to the firmware.
  1716. **/
  1717. static struct lpfc_dmabuf *
  1718. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1719. struct lpfc_sli_ring *pring,
  1720. uint32_t tag)
  1721. {
  1722. struct hbq_dmabuf *hbq_entry;
  1723. if (tag & QUE_BUFTAG_BIT)
  1724. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1725. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1726. if (!hbq_entry)
  1727. return NULL;
  1728. return &hbq_entry->dbuf;
  1729. }
  1730. /**
  1731. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1732. * @phba: Pointer to HBA context object.
  1733. * @pring: Pointer to driver SLI ring object.
  1734. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1735. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1736. * @fch_type: the type for the first frame of the sequence.
  1737. *
  1738. * This function is called with no lock held. This function uses the r_ctl and
  1739. * type of the received sequence to find the correct callback function to call
  1740. * to process the sequence.
  1741. **/
  1742. static int
  1743. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1744. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1745. uint32_t fch_type)
  1746. {
  1747. int i;
  1748. /* unSolicited Responses */
  1749. if (pring->prt[0].profile) {
  1750. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1751. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1752. saveq);
  1753. return 1;
  1754. }
  1755. /* We must search, based on rctl / type
  1756. for the right routine */
  1757. for (i = 0; i < pring->num_mask; i++) {
  1758. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1759. (pring->prt[i].type == fch_type)) {
  1760. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1761. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1762. (phba, pring, saveq);
  1763. return 1;
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. /**
  1769. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1770. * @phba: Pointer to HBA context object.
  1771. * @pring: Pointer to driver SLI ring object.
  1772. * @saveq: Pointer to the unsolicited iocb.
  1773. *
  1774. * This function is called with no lock held by the ring event handler
  1775. * when there is an unsolicited iocb posted to the response ring by the
  1776. * firmware. This function gets the buffer associated with the iocbs
  1777. * and calls the event handler for the ring. This function handles both
  1778. * qring buffers and hbq buffers.
  1779. * When the function returns 1 the caller can free the iocb object otherwise
  1780. * upper layer functions will free the iocb objects.
  1781. **/
  1782. static int
  1783. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1784. struct lpfc_iocbq *saveq)
  1785. {
  1786. IOCB_t * irsp;
  1787. WORD5 * w5p;
  1788. uint32_t Rctl, Type;
  1789. uint32_t match;
  1790. struct lpfc_iocbq *iocbq;
  1791. struct lpfc_dmabuf *dmzbuf;
  1792. match = 0;
  1793. irsp = &(saveq->iocb);
  1794. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1795. if (pring->lpfc_sli_rcv_async_status)
  1796. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1797. else
  1798. lpfc_printf_log(phba,
  1799. KERN_WARNING,
  1800. LOG_SLI,
  1801. "0316 Ring %d handler: unexpected "
  1802. "ASYNC_STATUS iocb received evt_code "
  1803. "0x%x\n",
  1804. pring->ringno,
  1805. irsp->un.asyncstat.evt_code);
  1806. return 1;
  1807. }
  1808. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1809. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1810. if (irsp->ulpBdeCount > 0) {
  1811. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1812. irsp->un.ulpWord[3]);
  1813. lpfc_in_buf_free(phba, dmzbuf);
  1814. }
  1815. if (irsp->ulpBdeCount > 1) {
  1816. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1817. irsp->unsli3.sli3Words[3]);
  1818. lpfc_in_buf_free(phba, dmzbuf);
  1819. }
  1820. if (irsp->ulpBdeCount > 2) {
  1821. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1822. irsp->unsli3.sli3Words[7]);
  1823. lpfc_in_buf_free(phba, dmzbuf);
  1824. }
  1825. return 1;
  1826. }
  1827. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1828. if (irsp->ulpBdeCount != 0) {
  1829. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1830. irsp->un.ulpWord[3]);
  1831. if (!saveq->context2)
  1832. lpfc_printf_log(phba,
  1833. KERN_ERR,
  1834. LOG_SLI,
  1835. "0341 Ring %d Cannot find buffer for "
  1836. "an unsolicited iocb. tag 0x%x\n",
  1837. pring->ringno,
  1838. irsp->un.ulpWord[3]);
  1839. }
  1840. if (irsp->ulpBdeCount == 2) {
  1841. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1842. irsp->unsli3.sli3Words[7]);
  1843. if (!saveq->context3)
  1844. lpfc_printf_log(phba,
  1845. KERN_ERR,
  1846. LOG_SLI,
  1847. "0342 Ring %d Cannot find buffer for an"
  1848. " unsolicited iocb. tag 0x%x\n",
  1849. pring->ringno,
  1850. irsp->unsli3.sli3Words[7]);
  1851. }
  1852. list_for_each_entry(iocbq, &saveq->list, list) {
  1853. irsp = &(iocbq->iocb);
  1854. if (irsp->ulpBdeCount != 0) {
  1855. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1856. irsp->un.ulpWord[3]);
  1857. if (!iocbq->context2)
  1858. lpfc_printf_log(phba,
  1859. KERN_ERR,
  1860. LOG_SLI,
  1861. "0343 Ring %d Cannot find "
  1862. "buffer for an unsolicited iocb"
  1863. ". tag 0x%x\n", pring->ringno,
  1864. irsp->un.ulpWord[3]);
  1865. }
  1866. if (irsp->ulpBdeCount == 2) {
  1867. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1868. irsp->unsli3.sli3Words[7]);
  1869. if (!iocbq->context3)
  1870. lpfc_printf_log(phba,
  1871. KERN_ERR,
  1872. LOG_SLI,
  1873. "0344 Ring %d Cannot find "
  1874. "buffer for an unsolicited "
  1875. "iocb. tag 0x%x\n",
  1876. pring->ringno,
  1877. irsp->unsli3.sli3Words[7]);
  1878. }
  1879. }
  1880. }
  1881. if (irsp->ulpBdeCount != 0 &&
  1882. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1883. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1884. int found = 0;
  1885. /* search continue save q for same XRI */
  1886. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1887. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1888. list_add_tail(&saveq->list, &iocbq->list);
  1889. found = 1;
  1890. break;
  1891. }
  1892. }
  1893. if (!found)
  1894. list_add_tail(&saveq->clist,
  1895. &pring->iocb_continue_saveq);
  1896. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1897. list_del_init(&iocbq->clist);
  1898. saveq = iocbq;
  1899. irsp = &(saveq->iocb);
  1900. } else
  1901. return 0;
  1902. }
  1903. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1904. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1905. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1906. Rctl = FC_ELS_REQ;
  1907. Type = FC_ELS_DATA;
  1908. } else {
  1909. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1910. Rctl = w5p->hcsw.Rctl;
  1911. Type = w5p->hcsw.Type;
  1912. /* Firmware Workaround */
  1913. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1914. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1915. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1916. Rctl = FC_ELS_REQ;
  1917. Type = FC_ELS_DATA;
  1918. w5p->hcsw.Rctl = Rctl;
  1919. w5p->hcsw.Type = Type;
  1920. }
  1921. }
  1922. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1923. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1924. "0313 Ring %d handler: unexpected Rctl x%x "
  1925. "Type x%x received\n",
  1926. pring->ringno, Rctl, Type);
  1927. return 1;
  1928. }
  1929. /**
  1930. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1931. * @phba: Pointer to HBA context object.
  1932. * @pring: Pointer to driver SLI ring object.
  1933. * @prspiocb: Pointer to response iocb object.
  1934. *
  1935. * This function looks up the iocb_lookup table to get the command iocb
  1936. * corresponding to the given response iocb using the iotag of the
  1937. * response iocb. This function is called with the hbalock held.
  1938. * This function returns the command iocb object if it finds the command
  1939. * iocb else returns NULL.
  1940. **/
  1941. static struct lpfc_iocbq *
  1942. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1943. struct lpfc_sli_ring *pring,
  1944. struct lpfc_iocbq *prspiocb)
  1945. {
  1946. struct lpfc_iocbq *cmd_iocb = NULL;
  1947. uint16_t iotag;
  1948. iotag = prspiocb->iocb.ulpIoTag;
  1949. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1950. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1951. list_del_init(&cmd_iocb->list);
  1952. pring->txcmplq_cnt--;
  1953. return cmd_iocb;
  1954. }
  1955. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1956. "0317 iotag x%x is out off "
  1957. "range: max iotag x%x wd0 x%x\n",
  1958. iotag, phba->sli.last_iotag,
  1959. *(((uint32_t *) &prspiocb->iocb) + 7));
  1960. return NULL;
  1961. }
  1962. /**
  1963. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1964. * @phba: Pointer to HBA context object.
  1965. * @pring: Pointer to driver SLI ring object.
  1966. * @iotag: IOCB tag.
  1967. *
  1968. * This function looks up the iocb_lookup table to get the command iocb
  1969. * corresponding to the given iotag. This function is called with the
  1970. * hbalock held.
  1971. * This function returns the command iocb object if it finds the command
  1972. * iocb else returns NULL.
  1973. **/
  1974. static struct lpfc_iocbq *
  1975. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1976. struct lpfc_sli_ring *pring, uint16_t iotag)
  1977. {
  1978. struct lpfc_iocbq *cmd_iocb;
  1979. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1980. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1981. list_del_init(&cmd_iocb->list);
  1982. pring->txcmplq_cnt--;
  1983. return cmd_iocb;
  1984. }
  1985. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1986. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1987. iotag, phba->sli.last_iotag);
  1988. return NULL;
  1989. }
  1990. /**
  1991. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  1992. * @phba: Pointer to HBA context object.
  1993. * @pring: Pointer to driver SLI ring object.
  1994. * @saveq: Pointer to the response iocb to be processed.
  1995. *
  1996. * This function is called by the ring event handler for non-fcp
  1997. * rings when there is a new response iocb in the response ring.
  1998. * The caller is not required to hold any locks. This function
  1999. * gets the command iocb associated with the response iocb and
  2000. * calls the completion handler for the command iocb. If there
  2001. * is no completion handler, the function will free the resources
  2002. * associated with command iocb. If the response iocb is for
  2003. * an already aborted command iocb, the status of the completion
  2004. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2005. * This function always returns 1.
  2006. **/
  2007. static int
  2008. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2009. struct lpfc_iocbq *saveq)
  2010. {
  2011. struct lpfc_iocbq *cmdiocbp;
  2012. int rc = 1;
  2013. unsigned long iflag;
  2014. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2015. spin_lock_irqsave(&phba->hbalock, iflag);
  2016. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2018. if (cmdiocbp) {
  2019. if (cmdiocbp->iocb_cmpl) {
  2020. /*
  2021. * If an ELS command failed send an event to mgmt
  2022. * application.
  2023. */
  2024. if (saveq->iocb.ulpStatus &&
  2025. (pring->ringno == LPFC_ELS_RING) &&
  2026. (cmdiocbp->iocb.ulpCommand ==
  2027. CMD_ELS_REQUEST64_CR))
  2028. lpfc_send_els_failure_event(phba,
  2029. cmdiocbp, saveq);
  2030. /*
  2031. * Post all ELS completions to the worker thread.
  2032. * All other are passed to the completion callback.
  2033. */
  2034. if (pring->ringno == LPFC_ELS_RING) {
  2035. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2036. cmdiocbp->iocb_flag &=
  2037. ~LPFC_DRIVER_ABORTED;
  2038. saveq->iocb.ulpStatus =
  2039. IOSTAT_LOCAL_REJECT;
  2040. saveq->iocb.un.ulpWord[4] =
  2041. IOERR_SLI_ABORTED;
  2042. /* Firmware could still be in progress
  2043. * of DMAing payload, so don't free data
  2044. * buffer till after a hbeat.
  2045. */
  2046. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2047. }
  2048. }
  2049. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2050. } else
  2051. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2052. } else {
  2053. /*
  2054. * Unknown initiating command based on the response iotag.
  2055. * This could be the case on the ELS ring because of
  2056. * lpfc_els_abort().
  2057. */
  2058. if (pring->ringno != LPFC_ELS_RING) {
  2059. /*
  2060. * Ring <ringno> handler: unexpected completion IoTag
  2061. * <IoTag>
  2062. */
  2063. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2064. "0322 Ring %d handler: "
  2065. "unexpected completion IoTag x%x "
  2066. "Data: x%x x%x x%x x%x\n",
  2067. pring->ringno,
  2068. saveq->iocb.ulpIoTag,
  2069. saveq->iocb.ulpStatus,
  2070. saveq->iocb.un.ulpWord[4],
  2071. saveq->iocb.ulpCommand,
  2072. saveq->iocb.ulpContext);
  2073. }
  2074. }
  2075. return rc;
  2076. }
  2077. /**
  2078. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2079. * @phba: Pointer to HBA context object.
  2080. * @pring: Pointer to driver SLI ring object.
  2081. *
  2082. * This function is called from the iocb ring event handlers when
  2083. * put pointer is ahead of the get pointer for a ring. This function signal
  2084. * an error attention condition to the worker thread and the worker
  2085. * thread will transition the HBA to offline state.
  2086. **/
  2087. static void
  2088. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2089. {
  2090. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2091. /*
  2092. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2093. * rsp ring <portRspMax>
  2094. */
  2095. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2096. "0312 Ring %d handler: portRspPut %d "
  2097. "is bigger than rsp ring %d\n",
  2098. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2099. pring->numRiocb);
  2100. phba->link_state = LPFC_HBA_ERROR;
  2101. /*
  2102. * All error attention handlers are posted to
  2103. * worker thread
  2104. */
  2105. phba->work_ha |= HA_ERATT;
  2106. phba->work_hs = HS_FFER3;
  2107. lpfc_worker_wake_up(phba);
  2108. return;
  2109. }
  2110. /**
  2111. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2112. * @ptr: Pointer to address of HBA context object.
  2113. *
  2114. * This function is invoked by the Error Attention polling timer when the
  2115. * timer times out. It will check the SLI Error Attention register for
  2116. * possible attention events. If so, it will post an Error Attention event
  2117. * and wake up worker thread to process it. Otherwise, it will set up the
  2118. * Error Attention polling timer for the next poll.
  2119. **/
  2120. void lpfc_poll_eratt(unsigned long ptr)
  2121. {
  2122. struct lpfc_hba *phba;
  2123. uint32_t eratt = 0;
  2124. phba = (struct lpfc_hba *)ptr;
  2125. /* Check chip HA register for error event */
  2126. eratt = lpfc_sli_check_eratt(phba);
  2127. if (eratt)
  2128. /* Tell the worker thread there is work to do */
  2129. lpfc_worker_wake_up(phba);
  2130. else
  2131. /* Restart the timer for next eratt poll */
  2132. mod_timer(&phba->eratt_poll, jiffies +
  2133. HZ * LPFC_ERATT_POLL_INTERVAL);
  2134. return;
  2135. }
  2136. /**
  2137. * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
  2138. * @phba: Pointer to HBA context object.
  2139. *
  2140. * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
  2141. * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
  2142. * is enabled.
  2143. *
  2144. * The caller does not hold any lock.
  2145. * The function processes each response iocb in the response ring until it
  2146. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2147. * LE bit set. The function will call the completion handler of the command iocb
  2148. * if the response iocb indicates a completion for a command iocb or it is
  2149. * an abort completion.
  2150. **/
  2151. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  2152. {
  2153. struct lpfc_sli *psli = &phba->sli;
  2154. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  2155. IOCB_t *irsp = NULL;
  2156. IOCB_t *entry = NULL;
  2157. struct lpfc_iocbq *cmdiocbq = NULL;
  2158. struct lpfc_iocbq rspiocbq;
  2159. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2160. uint32_t status;
  2161. uint32_t portRspPut, portRspMax;
  2162. int type;
  2163. uint32_t rsp_cmpl = 0;
  2164. uint32_t ha_copy;
  2165. unsigned long iflags;
  2166. pring->stats.iocb_event++;
  2167. /*
  2168. * The next available response entry should never exceed the maximum
  2169. * entries. If it does, treat it as an adapter hardware error.
  2170. */
  2171. portRspMax = pring->numRiocb;
  2172. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2173. if (unlikely(portRspPut >= portRspMax)) {
  2174. lpfc_sli_rsp_pointers_error(phba, pring);
  2175. return;
  2176. }
  2177. rmb();
  2178. while (pring->rspidx != portRspPut) {
  2179. entry = lpfc_resp_iocb(phba, pring);
  2180. if (++pring->rspidx >= portRspMax)
  2181. pring->rspidx = 0;
  2182. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2183. (uint32_t *) &rspiocbq.iocb,
  2184. phba->iocb_rsp_size);
  2185. irsp = &rspiocbq.iocb;
  2186. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2187. pring->stats.iocb_rsp++;
  2188. rsp_cmpl++;
  2189. if (unlikely(irsp->ulpStatus)) {
  2190. /* Rsp ring <ringno> error: IOCB */
  2191. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2192. "0326 Rsp Ring %d error: IOCB Data: "
  2193. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2194. pring->ringno,
  2195. irsp->un.ulpWord[0],
  2196. irsp->un.ulpWord[1],
  2197. irsp->un.ulpWord[2],
  2198. irsp->un.ulpWord[3],
  2199. irsp->un.ulpWord[4],
  2200. irsp->un.ulpWord[5],
  2201. *(uint32_t *)&irsp->un1,
  2202. *((uint32_t *)&irsp->un1 + 1));
  2203. }
  2204. switch (type) {
  2205. case LPFC_ABORT_IOCB:
  2206. case LPFC_SOL_IOCB:
  2207. /*
  2208. * Idle exchange closed via ABTS from port. No iocb
  2209. * resources need to be recovered.
  2210. */
  2211. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2212. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2213. "0314 IOCB cmd 0x%x "
  2214. "processed. Skipping "
  2215. "completion",
  2216. irsp->ulpCommand);
  2217. break;
  2218. }
  2219. spin_lock_irqsave(&phba->hbalock, iflags);
  2220. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2221. &rspiocbq);
  2222. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2223. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2224. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2225. &rspiocbq);
  2226. }
  2227. break;
  2228. default:
  2229. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2230. char adaptermsg[LPFC_MAX_ADPTMSG];
  2231. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2232. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2233. MAX_MSG_DATA);
  2234. dev_warn(&((phba->pcidev)->dev),
  2235. "lpfc%d: %s\n",
  2236. phba->brd_no, adaptermsg);
  2237. } else {
  2238. /* Unknown IOCB command */
  2239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2240. "0321 Unknown IOCB command "
  2241. "Data: x%x, x%x x%x x%x x%x\n",
  2242. type, irsp->ulpCommand,
  2243. irsp->ulpStatus,
  2244. irsp->ulpIoTag,
  2245. irsp->ulpContext);
  2246. }
  2247. break;
  2248. }
  2249. /*
  2250. * The response IOCB has been processed. Update the ring
  2251. * pointer in SLIM. If the port response put pointer has not
  2252. * been updated, sync the pgp->rspPutInx and fetch the new port
  2253. * response put pointer.
  2254. */
  2255. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2256. if (pring->rspidx == portRspPut)
  2257. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2258. }
  2259. ha_copy = readl(phba->HAregaddr);
  2260. ha_copy >>= (LPFC_FCP_RING * 4);
  2261. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  2262. spin_lock_irqsave(&phba->hbalock, iflags);
  2263. pring->stats.iocb_rsp_full++;
  2264. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  2265. writel(status, phba->CAregaddr);
  2266. readl(phba->CAregaddr);
  2267. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2268. }
  2269. if ((ha_copy & HA_R0CE_RSP) &&
  2270. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2271. spin_lock_irqsave(&phba->hbalock, iflags);
  2272. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2273. pring->stats.iocb_cmd_empty++;
  2274. /* Force update of the local copy of cmdGetInx */
  2275. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2276. lpfc_sli_resume_iocb(phba, pring);
  2277. if ((pring->lpfc_sli_cmd_available))
  2278. (pring->lpfc_sli_cmd_available) (phba, pring);
  2279. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2280. }
  2281. return;
  2282. }
  2283. /**
  2284. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2285. * @phba: Pointer to HBA context object.
  2286. * @pring: Pointer to driver SLI ring object.
  2287. * @mask: Host attention register mask for this ring.
  2288. *
  2289. * This function is called from the interrupt context when there is a ring
  2290. * event for the fcp ring. The caller does not hold any lock.
  2291. * The function processes each response iocb in the response ring until it
  2292. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2293. * LE bit set. The function will call the completion handler of the command iocb
  2294. * if the response iocb indicates a completion for a command iocb or it is
  2295. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2296. * function if this is an unsolicited iocb.
  2297. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2298. * to check it explicitly. This function always returns 1.
  2299. **/
  2300. static int
  2301. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2302. struct lpfc_sli_ring *pring, uint32_t mask)
  2303. {
  2304. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2305. IOCB_t *irsp = NULL;
  2306. IOCB_t *entry = NULL;
  2307. struct lpfc_iocbq *cmdiocbq = NULL;
  2308. struct lpfc_iocbq rspiocbq;
  2309. uint32_t status;
  2310. uint32_t portRspPut, portRspMax;
  2311. int rc = 1;
  2312. lpfc_iocb_type type;
  2313. unsigned long iflag;
  2314. uint32_t rsp_cmpl = 0;
  2315. spin_lock_irqsave(&phba->hbalock, iflag);
  2316. pring->stats.iocb_event++;
  2317. /*
  2318. * The next available response entry should never exceed the maximum
  2319. * entries. If it does, treat it as an adapter hardware error.
  2320. */
  2321. portRspMax = pring->numRiocb;
  2322. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2323. if (unlikely(portRspPut >= portRspMax)) {
  2324. lpfc_sli_rsp_pointers_error(phba, pring);
  2325. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2326. return 1;
  2327. }
  2328. rmb();
  2329. while (pring->rspidx != portRspPut) {
  2330. /*
  2331. * Fetch an entry off the ring and copy it into a local data
  2332. * structure. The copy involves a byte-swap since the
  2333. * network byte order and pci byte orders are different.
  2334. */
  2335. entry = lpfc_resp_iocb(phba, pring);
  2336. phba->last_completion_time = jiffies;
  2337. if (++pring->rspidx >= portRspMax)
  2338. pring->rspidx = 0;
  2339. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2340. (uint32_t *) &rspiocbq.iocb,
  2341. phba->iocb_rsp_size);
  2342. INIT_LIST_HEAD(&(rspiocbq.list));
  2343. irsp = &rspiocbq.iocb;
  2344. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2345. pring->stats.iocb_rsp++;
  2346. rsp_cmpl++;
  2347. if (unlikely(irsp->ulpStatus)) {
  2348. /*
  2349. * If resource errors reported from HBA, reduce
  2350. * queuedepths of the SCSI device.
  2351. */
  2352. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2353. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2355. phba->lpfc_rampdown_queue_depth(phba);
  2356. spin_lock_irqsave(&phba->hbalock, iflag);
  2357. }
  2358. /* Rsp ring <ringno> error: IOCB */
  2359. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2360. "0336 Rsp Ring %d error: IOCB Data: "
  2361. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2362. pring->ringno,
  2363. irsp->un.ulpWord[0],
  2364. irsp->un.ulpWord[1],
  2365. irsp->un.ulpWord[2],
  2366. irsp->un.ulpWord[3],
  2367. irsp->un.ulpWord[4],
  2368. irsp->un.ulpWord[5],
  2369. *(uint32_t *)&irsp->un1,
  2370. *((uint32_t *)&irsp->un1 + 1));
  2371. }
  2372. switch (type) {
  2373. case LPFC_ABORT_IOCB:
  2374. case LPFC_SOL_IOCB:
  2375. /*
  2376. * Idle exchange closed via ABTS from port. No iocb
  2377. * resources need to be recovered.
  2378. */
  2379. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2380. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2381. "0333 IOCB cmd 0x%x"
  2382. " processed. Skipping"
  2383. " completion\n",
  2384. irsp->ulpCommand);
  2385. break;
  2386. }
  2387. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2388. &rspiocbq);
  2389. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2390. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2391. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2392. &rspiocbq);
  2393. } else {
  2394. spin_unlock_irqrestore(&phba->hbalock,
  2395. iflag);
  2396. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2397. &rspiocbq);
  2398. spin_lock_irqsave(&phba->hbalock,
  2399. iflag);
  2400. }
  2401. }
  2402. break;
  2403. case LPFC_UNSOL_IOCB:
  2404. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2405. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2406. spin_lock_irqsave(&phba->hbalock, iflag);
  2407. break;
  2408. default:
  2409. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2410. char adaptermsg[LPFC_MAX_ADPTMSG];
  2411. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2412. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2413. MAX_MSG_DATA);
  2414. dev_warn(&((phba->pcidev)->dev),
  2415. "lpfc%d: %s\n",
  2416. phba->brd_no, adaptermsg);
  2417. } else {
  2418. /* Unknown IOCB command */
  2419. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2420. "0334 Unknown IOCB command "
  2421. "Data: x%x, x%x x%x x%x x%x\n",
  2422. type, irsp->ulpCommand,
  2423. irsp->ulpStatus,
  2424. irsp->ulpIoTag,
  2425. irsp->ulpContext);
  2426. }
  2427. break;
  2428. }
  2429. /*
  2430. * The response IOCB has been processed. Update the ring
  2431. * pointer in SLIM. If the port response put pointer has not
  2432. * been updated, sync the pgp->rspPutInx and fetch the new port
  2433. * response put pointer.
  2434. */
  2435. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2436. if (pring->rspidx == portRspPut)
  2437. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2438. }
  2439. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2440. pring->stats.iocb_rsp_full++;
  2441. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2442. writel(status, phba->CAregaddr);
  2443. readl(phba->CAregaddr);
  2444. }
  2445. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2446. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2447. pring->stats.iocb_cmd_empty++;
  2448. /* Force update of the local copy of cmdGetInx */
  2449. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2450. lpfc_sli_resume_iocb(phba, pring);
  2451. if ((pring->lpfc_sli_cmd_available))
  2452. (pring->lpfc_sli_cmd_available) (phba, pring);
  2453. }
  2454. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2455. return rc;
  2456. }
  2457. /**
  2458. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2459. * @phba: Pointer to HBA context object.
  2460. * @pring: Pointer to driver SLI ring object.
  2461. * @rspiocbp: Pointer to driver response IOCB object.
  2462. *
  2463. * This function is called from the worker thread when there is a slow-path
  2464. * response IOCB to process. This function chains all the response iocbs until
  2465. * seeing the iocb with the LE bit set. The function will call
  2466. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2467. * completion of a command iocb. The function will call the
  2468. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2469. * The function frees the resources or calls the completion handler if this
  2470. * iocb is an abort completion. The function returns NULL when the response
  2471. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2472. * this function shall chain the iocb on to the iocb_continueq and return the
  2473. * response iocb passed in.
  2474. **/
  2475. static struct lpfc_iocbq *
  2476. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2477. struct lpfc_iocbq *rspiocbp)
  2478. {
  2479. struct lpfc_iocbq *saveq;
  2480. struct lpfc_iocbq *cmdiocbp;
  2481. struct lpfc_iocbq *next_iocb;
  2482. IOCB_t *irsp = NULL;
  2483. uint32_t free_saveq;
  2484. uint8_t iocb_cmd_type;
  2485. lpfc_iocb_type type;
  2486. unsigned long iflag;
  2487. int rc;
  2488. spin_lock_irqsave(&phba->hbalock, iflag);
  2489. /* First add the response iocb to the countinueq list */
  2490. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2491. pring->iocb_continueq_cnt++;
  2492. /* Now, determine whetehr the list is completed for processing */
  2493. irsp = &rspiocbp->iocb;
  2494. if (irsp->ulpLe) {
  2495. /*
  2496. * By default, the driver expects to free all resources
  2497. * associated with this iocb completion.
  2498. */
  2499. free_saveq = 1;
  2500. saveq = list_get_first(&pring->iocb_continueq,
  2501. struct lpfc_iocbq, list);
  2502. irsp = &(saveq->iocb);
  2503. list_del_init(&pring->iocb_continueq);
  2504. pring->iocb_continueq_cnt = 0;
  2505. pring->stats.iocb_rsp++;
  2506. /*
  2507. * If resource errors reported from HBA, reduce
  2508. * queuedepths of the SCSI device.
  2509. */
  2510. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2511. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2512. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2513. phba->lpfc_rampdown_queue_depth(phba);
  2514. spin_lock_irqsave(&phba->hbalock, iflag);
  2515. }
  2516. if (irsp->ulpStatus) {
  2517. /* Rsp ring <ringno> error: IOCB */
  2518. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2519. "0328 Rsp Ring %d error: "
  2520. "IOCB Data: "
  2521. "x%x x%x x%x x%x "
  2522. "x%x x%x x%x x%x "
  2523. "x%x x%x x%x x%x "
  2524. "x%x x%x x%x x%x\n",
  2525. pring->ringno,
  2526. irsp->un.ulpWord[0],
  2527. irsp->un.ulpWord[1],
  2528. irsp->un.ulpWord[2],
  2529. irsp->un.ulpWord[3],
  2530. irsp->un.ulpWord[4],
  2531. irsp->un.ulpWord[5],
  2532. *(((uint32_t *) irsp) + 6),
  2533. *(((uint32_t *) irsp) + 7),
  2534. *(((uint32_t *) irsp) + 8),
  2535. *(((uint32_t *) irsp) + 9),
  2536. *(((uint32_t *) irsp) + 10),
  2537. *(((uint32_t *) irsp) + 11),
  2538. *(((uint32_t *) irsp) + 12),
  2539. *(((uint32_t *) irsp) + 13),
  2540. *(((uint32_t *) irsp) + 14),
  2541. *(((uint32_t *) irsp) + 15));
  2542. }
  2543. /*
  2544. * Fetch the IOCB command type and call the correct completion
  2545. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2546. * get freed back to the lpfc_iocb_list by the discovery
  2547. * kernel thread.
  2548. */
  2549. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2550. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2551. switch (type) {
  2552. case LPFC_SOL_IOCB:
  2553. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2554. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2555. spin_lock_irqsave(&phba->hbalock, iflag);
  2556. break;
  2557. case LPFC_UNSOL_IOCB:
  2558. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2559. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2560. spin_lock_irqsave(&phba->hbalock, iflag);
  2561. if (!rc)
  2562. free_saveq = 0;
  2563. break;
  2564. case LPFC_ABORT_IOCB:
  2565. cmdiocbp = NULL;
  2566. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2567. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2568. saveq);
  2569. if (cmdiocbp) {
  2570. /* Call the specified completion routine */
  2571. if (cmdiocbp->iocb_cmpl) {
  2572. spin_unlock_irqrestore(&phba->hbalock,
  2573. iflag);
  2574. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2575. saveq);
  2576. spin_lock_irqsave(&phba->hbalock,
  2577. iflag);
  2578. } else
  2579. __lpfc_sli_release_iocbq(phba,
  2580. cmdiocbp);
  2581. }
  2582. break;
  2583. case LPFC_UNKNOWN_IOCB:
  2584. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2585. char adaptermsg[LPFC_MAX_ADPTMSG];
  2586. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2587. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2588. MAX_MSG_DATA);
  2589. dev_warn(&((phba->pcidev)->dev),
  2590. "lpfc%d: %s\n",
  2591. phba->brd_no, adaptermsg);
  2592. } else {
  2593. /* Unknown IOCB command */
  2594. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2595. "0335 Unknown IOCB "
  2596. "command Data: x%x "
  2597. "x%x x%x x%x\n",
  2598. irsp->ulpCommand,
  2599. irsp->ulpStatus,
  2600. irsp->ulpIoTag,
  2601. irsp->ulpContext);
  2602. }
  2603. break;
  2604. }
  2605. if (free_saveq) {
  2606. list_for_each_entry_safe(rspiocbp, next_iocb,
  2607. &saveq->list, list) {
  2608. list_del(&rspiocbp->list);
  2609. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2610. }
  2611. __lpfc_sli_release_iocbq(phba, saveq);
  2612. }
  2613. rspiocbp = NULL;
  2614. }
  2615. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2616. return rspiocbp;
  2617. }
  2618. /**
  2619. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2620. * @phba: Pointer to HBA context object.
  2621. * @pring: Pointer to driver SLI ring object.
  2622. * @mask: Host attention register mask for this ring.
  2623. *
  2624. * This routine wraps the actual slow_ring event process routine from the
  2625. * API jump table function pointer from the lpfc_hba struct.
  2626. **/
  2627. void
  2628. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2629. struct lpfc_sli_ring *pring, uint32_t mask)
  2630. {
  2631. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2632. }
  2633. /**
  2634. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2635. * @phba: Pointer to HBA context object.
  2636. * @pring: Pointer to driver SLI ring object.
  2637. * @mask: Host attention register mask for this ring.
  2638. *
  2639. * This function is called from the worker thread when there is a ring event
  2640. * for non-fcp rings. The caller does not hold any lock. The function will
  2641. * remove each response iocb in the response ring and calls the handle
  2642. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2643. **/
  2644. static void
  2645. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2646. struct lpfc_sli_ring *pring, uint32_t mask)
  2647. {
  2648. struct lpfc_pgp *pgp;
  2649. IOCB_t *entry;
  2650. IOCB_t *irsp = NULL;
  2651. struct lpfc_iocbq *rspiocbp = NULL;
  2652. uint32_t portRspPut, portRspMax;
  2653. unsigned long iflag;
  2654. uint32_t status;
  2655. pgp = &phba->port_gp[pring->ringno];
  2656. spin_lock_irqsave(&phba->hbalock, iflag);
  2657. pring->stats.iocb_event++;
  2658. /*
  2659. * The next available response entry should never exceed the maximum
  2660. * entries. If it does, treat it as an adapter hardware error.
  2661. */
  2662. portRspMax = pring->numRiocb;
  2663. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2664. if (portRspPut >= portRspMax) {
  2665. /*
  2666. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2667. * rsp ring <portRspMax>
  2668. */
  2669. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2670. "0303 Ring %d handler: portRspPut %d "
  2671. "is bigger than rsp ring %d\n",
  2672. pring->ringno, portRspPut, portRspMax);
  2673. phba->link_state = LPFC_HBA_ERROR;
  2674. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2675. phba->work_hs = HS_FFER3;
  2676. lpfc_handle_eratt(phba);
  2677. return;
  2678. }
  2679. rmb();
  2680. while (pring->rspidx != portRspPut) {
  2681. /*
  2682. * Build a completion list and call the appropriate handler.
  2683. * The process is to get the next available response iocb, get
  2684. * a free iocb from the list, copy the response data into the
  2685. * free iocb, insert to the continuation list, and update the
  2686. * next response index to slim. This process makes response
  2687. * iocb's in the ring available to DMA as fast as possible but
  2688. * pays a penalty for a copy operation. Since the iocb is
  2689. * only 32 bytes, this penalty is considered small relative to
  2690. * the PCI reads for register values and a slim write. When
  2691. * the ulpLe field is set, the entire Command has been
  2692. * received.
  2693. */
  2694. entry = lpfc_resp_iocb(phba, pring);
  2695. phba->last_completion_time = jiffies;
  2696. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2697. if (rspiocbp == NULL) {
  2698. printk(KERN_ERR "%s: out of buffers! Failing "
  2699. "completion.\n", __func__);
  2700. break;
  2701. }
  2702. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2703. phba->iocb_rsp_size);
  2704. irsp = &rspiocbp->iocb;
  2705. if (++pring->rspidx >= portRspMax)
  2706. pring->rspidx = 0;
  2707. if (pring->ringno == LPFC_ELS_RING) {
  2708. lpfc_debugfs_slow_ring_trc(phba,
  2709. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2710. *(((uint32_t *) irsp) + 4),
  2711. *(((uint32_t *) irsp) + 6),
  2712. *(((uint32_t *) irsp) + 7));
  2713. }
  2714. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2715. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2716. /* Handle the response IOCB */
  2717. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2718. spin_lock_irqsave(&phba->hbalock, iflag);
  2719. /*
  2720. * If the port response put pointer has not been updated, sync
  2721. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2722. * response put pointer.
  2723. */
  2724. if (pring->rspidx == portRspPut) {
  2725. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2726. }
  2727. } /* while (pring->rspidx != portRspPut) */
  2728. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2729. /* At least one response entry has been freed */
  2730. pring->stats.iocb_rsp_full++;
  2731. /* SET RxRE_RSP in Chip Att register */
  2732. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2733. writel(status, phba->CAregaddr);
  2734. readl(phba->CAregaddr); /* flush */
  2735. }
  2736. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2737. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2738. pring->stats.iocb_cmd_empty++;
  2739. /* Force update of the local copy of cmdGetInx */
  2740. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2741. lpfc_sli_resume_iocb(phba, pring);
  2742. if ((pring->lpfc_sli_cmd_available))
  2743. (pring->lpfc_sli_cmd_available) (phba, pring);
  2744. }
  2745. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2746. return;
  2747. }
  2748. /**
  2749. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2750. * @phba: Pointer to HBA context object.
  2751. * @pring: Pointer to driver SLI ring object.
  2752. * @mask: Host attention register mask for this ring.
  2753. *
  2754. * This function is called from the worker thread when there is a pending
  2755. * ELS response iocb on the driver internal slow-path response iocb worker
  2756. * queue. The caller does not hold any lock. The function will remove each
  2757. * response iocb from the response worker queue and calls the handle
  2758. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2759. **/
  2760. static void
  2761. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2762. struct lpfc_sli_ring *pring, uint32_t mask)
  2763. {
  2764. struct lpfc_iocbq *irspiocbq;
  2765. unsigned long iflag;
  2766. while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
  2767. /* Get the response iocb from the head of work queue */
  2768. spin_lock_irqsave(&phba->hbalock, iflag);
  2769. list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
  2770. irspiocbq, struct lpfc_iocbq, list);
  2771. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2772. /* Process the response iocb */
  2773. lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
  2774. }
  2775. }
  2776. /**
  2777. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2778. * @phba: Pointer to HBA context object.
  2779. * @pring: Pointer to driver SLI ring object.
  2780. *
  2781. * This function aborts all iocbs in the given ring and frees all the iocb
  2782. * objects in txq. This function issues an abort iocb for all the iocb commands
  2783. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2784. * the return of this function. The caller is not required to hold any locks.
  2785. **/
  2786. void
  2787. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2788. {
  2789. LIST_HEAD(completions);
  2790. struct lpfc_iocbq *iocb, *next_iocb;
  2791. if (pring->ringno == LPFC_ELS_RING) {
  2792. lpfc_fabric_abort_hba(phba);
  2793. }
  2794. /* Error everything on txq and txcmplq
  2795. * First do the txq.
  2796. */
  2797. spin_lock_irq(&phba->hbalock);
  2798. list_splice_init(&pring->txq, &completions);
  2799. pring->txq_cnt = 0;
  2800. /* Next issue ABTS for everything on the txcmplq */
  2801. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2802. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2803. spin_unlock_irq(&phba->hbalock);
  2804. /* Cancel all the IOCBs from the completions list */
  2805. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_ABORTED);
  2807. }
  2808. /**
  2809. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2810. * @phba: Pointer to HBA context object.
  2811. *
  2812. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2813. * objects in txq and txcmplq. This function will not issue abort iocbs
  2814. * for all the iocb commands in txcmplq, they will just be returned with
  2815. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2816. * slot has been permanently disabled.
  2817. **/
  2818. void
  2819. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2820. {
  2821. LIST_HEAD(txq);
  2822. LIST_HEAD(txcmplq);
  2823. struct lpfc_sli *psli = &phba->sli;
  2824. struct lpfc_sli_ring *pring;
  2825. /* Currently, only one fcp ring */
  2826. pring = &psli->ring[psli->fcp_ring];
  2827. spin_lock_irq(&phba->hbalock);
  2828. /* Retrieve everything on txq */
  2829. list_splice_init(&pring->txq, &txq);
  2830. pring->txq_cnt = 0;
  2831. /* Retrieve everything on the txcmplq */
  2832. list_splice_init(&pring->txcmplq, &txcmplq);
  2833. pring->txcmplq_cnt = 0;
  2834. spin_unlock_irq(&phba->hbalock);
  2835. /* Flush the txq */
  2836. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2837. IOERR_SLI_DOWN);
  2838. /* Flush the txcmpq */
  2839. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2840. IOERR_SLI_DOWN);
  2841. }
  2842. /**
  2843. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2844. * @phba: Pointer to HBA context object.
  2845. * @mask: Bit mask to be checked.
  2846. *
  2847. * This function reads the host status register and compares
  2848. * with the provided bit mask to check if HBA completed
  2849. * the restart. This function will wait in a loop for the
  2850. * HBA to complete restart. If the HBA does not restart within
  2851. * 15 iterations, the function will reset the HBA again. The
  2852. * function returns 1 when HBA fail to restart otherwise returns
  2853. * zero.
  2854. **/
  2855. static int
  2856. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2857. {
  2858. uint32_t status;
  2859. int i = 0;
  2860. int retval = 0;
  2861. /* Read the HBA Host Status Register */
  2862. status = readl(phba->HSregaddr);
  2863. /*
  2864. * Check status register every 100ms for 5 retries, then every
  2865. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2866. * every 2.5 sec for 4.
  2867. * Break our of the loop if errors occurred during init.
  2868. */
  2869. while (((status & mask) != mask) &&
  2870. !(status & HS_FFERM) &&
  2871. i++ < 20) {
  2872. if (i <= 5)
  2873. msleep(10);
  2874. else if (i <= 10)
  2875. msleep(500);
  2876. else
  2877. msleep(2500);
  2878. if (i == 15) {
  2879. /* Do post */
  2880. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2881. lpfc_sli_brdrestart(phba);
  2882. }
  2883. /* Read the HBA Host Status Register */
  2884. status = readl(phba->HSregaddr);
  2885. }
  2886. /* Check to see if any errors occurred during init */
  2887. if ((status & HS_FFERM) || (i >= 20)) {
  2888. phba->link_state = LPFC_HBA_ERROR;
  2889. retval = 1;
  2890. }
  2891. return retval;
  2892. }
  2893. /**
  2894. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2895. * @phba: Pointer to HBA context object.
  2896. * @mask: Bit mask to be checked.
  2897. *
  2898. * This function checks the host status register to check if HBA is
  2899. * ready. This function will wait in a loop for the HBA to be ready
  2900. * If the HBA is not ready , the function will will reset the HBA PCI
  2901. * function again. The function returns 1 when HBA fail to be ready
  2902. * otherwise returns zero.
  2903. **/
  2904. static int
  2905. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2906. {
  2907. uint32_t status;
  2908. int retval = 0;
  2909. /* Read the HBA Host Status Register */
  2910. status = lpfc_sli4_post_status_check(phba);
  2911. if (status) {
  2912. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2913. lpfc_sli_brdrestart(phba);
  2914. status = lpfc_sli4_post_status_check(phba);
  2915. }
  2916. /* Check to see if any errors occurred during init */
  2917. if (status) {
  2918. phba->link_state = LPFC_HBA_ERROR;
  2919. retval = 1;
  2920. } else
  2921. phba->sli4_hba.intr_enable = 0;
  2922. return retval;
  2923. }
  2924. /**
  2925. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2926. * @phba: Pointer to HBA context object.
  2927. * @mask: Bit mask to be checked.
  2928. *
  2929. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2930. * from the API jump table function pointer from the lpfc_hba struct.
  2931. **/
  2932. int
  2933. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2934. {
  2935. return phba->lpfc_sli_brdready(phba, mask);
  2936. }
  2937. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2938. /**
  2939. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2940. * @phba: Pointer to HBA context object.
  2941. *
  2942. * This function is called before resetting an HBA. This
  2943. * function requests HBA to quiesce DMAs before a reset.
  2944. **/
  2945. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2946. {
  2947. uint32_t __iomem *resp_buf;
  2948. uint32_t __iomem *mbox_buf;
  2949. volatile uint32_t mbox;
  2950. uint32_t hc_copy;
  2951. int i;
  2952. uint8_t hdrtype;
  2953. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2954. if (hdrtype != 0x80 ||
  2955. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2956. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2957. return;
  2958. /*
  2959. * Tell the other part of the chip to suspend temporarily all
  2960. * its DMA activity.
  2961. */
  2962. resp_buf = phba->MBslimaddr;
  2963. /* Disable the error attention */
  2964. hc_copy = readl(phba->HCregaddr);
  2965. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2966. readl(phba->HCregaddr); /* flush */
  2967. phba->link_flag |= LS_IGNORE_ERATT;
  2968. if (readl(phba->HAregaddr) & HA_ERATT) {
  2969. /* Clear Chip error bit */
  2970. writel(HA_ERATT, phba->HAregaddr);
  2971. phba->pport->stopped = 1;
  2972. }
  2973. mbox = 0;
  2974. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2975. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2976. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2977. mbox_buf = phba->MBslimaddr;
  2978. writel(mbox, mbox_buf);
  2979. for (i = 0;
  2980. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2981. mdelay(1);
  2982. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2983. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2984. phba->pport->stopped)
  2985. goto restore_hc;
  2986. else
  2987. goto clear_errat;
  2988. }
  2989. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2990. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2991. mdelay(1);
  2992. clear_errat:
  2993. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2994. mdelay(1);
  2995. if (readl(phba->HAregaddr) & HA_ERATT) {
  2996. writel(HA_ERATT, phba->HAregaddr);
  2997. phba->pport->stopped = 1;
  2998. }
  2999. restore_hc:
  3000. phba->link_flag &= ~LS_IGNORE_ERATT;
  3001. writel(hc_copy, phba->HCregaddr);
  3002. readl(phba->HCregaddr); /* flush */
  3003. }
  3004. /**
  3005. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3006. * @phba: Pointer to HBA context object.
  3007. *
  3008. * This function issues a kill_board mailbox command and waits for
  3009. * the error attention interrupt. This function is called for stopping
  3010. * the firmware processing. The caller is not required to hold any
  3011. * locks. This function calls lpfc_hba_down_post function to free
  3012. * any pending commands after the kill. The function will return 1 when it
  3013. * fails to kill the board else will return 0.
  3014. **/
  3015. int
  3016. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3017. {
  3018. struct lpfc_sli *psli;
  3019. LPFC_MBOXQ_t *pmb;
  3020. uint32_t status;
  3021. uint32_t ha_copy;
  3022. int retval;
  3023. int i = 0;
  3024. psli = &phba->sli;
  3025. /* Kill HBA */
  3026. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3027. "0329 Kill HBA Data: x%x x%x\n",
  3028. phba->pport->port_state, psli->sli_flag);
  3029. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3030. if (!pmb)
  3031. return 1;
  3032. /* Disable the error attention */
  3033. spin_lock_irq(&phba->hbalock);
  3034. status = readl(phba->HCregaddr);
  3035. status &= ~HC_ERINT_ENA;
  3036. writel(status, phba->HCregaddr);
  3037. readl(phba->HCregaddr); /* flush */
  3038. phba->link_flag |= LS_IGNORE_ERATT;
  3039. spin_unlock_irq(&phba->hbalock);
  3040. lpfc_kill_board(phba, pmb);
  3041. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3042. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3043. if (retval != MBX_SUCCESS) {
  3044. if (retval != MBX_BUSY)
  3045. mempool_free(pmb, phba->mbox_mem_pool);
  3046. spin_lock_irq(&phba->hbalock);
  3047. phba->link_flag &= ~LS_IGNORE_ERATT;
  3048. spin_unlock_irq(&phba->hbalock);
  3049. return 1;
  3050. }
  3051. spin_lock_irq(&phba->hbalock);
  3052. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3053. spin_unlock_irq(&phba->hbalock);
  3054. mempool_free(pmb, phba->mbox_mem_pool);
  3055. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3056. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3057. * 3 seconds we still set HBA_ERROR state because the status of the
  3058. * board is now undefined.
  3059. */
  3060. ha_copy = readl(phba->HAregaddr);
  3061. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3062. mdelay(100);
  3063. ha_copy = readl(phba->HAregaddr);
  3064. }
  3065. del_timer_sync(&psli->mbox_tmo);
  3066. if (ha_copy & HA_ERATT) {
  3067. writel(HA_ERATT, phba->HAregaddr);
  3068. phba->pport->stopped = 1;
  3069. }
  3070. spin_lock_irq(&phba->hbalock);
  3071. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3072. psli->mbox_active = NULL;
  3073. phba->link_flag &= ~LS_IGNORE_ERATT;
  3074. spin_unlock_irq(&phba->hbalock);
  3075. lpfc_hba_down_post(phba);
  3076. phba->link_state = LPFC_HBA_ERROR;
  3077. return ha_copy & HA_ERATT ? 0 : 1;
  3078. }
  3079. /**
  3080. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3081. * @phba: Pointer to HBA context object.
  3082. *
  3083. * This function resets the HBA by writing HC_INITFF to the control
  3084. * register. After the HBA resets, this function resets all the iocb ring
  3085. * indices. This function disables PCI layer parity checking during
  3086. * the reset.
  3087. * This function returns 0 always.
  3088. * The caller is not required to hold any locks.
  3089. **/
  3090. int
  3091. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3092. {
  3093. struct lpfc_sli *psli;
  3094. struct lpfc_sli_ring *pring;
  3095. uint16_t cfg_value;
  3096. int i;
  3097. psli = &phba->sli;
  3098. /* Reset HBA */
  3099. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3100. "0325 Reset HBA Data: x%x x%x\n",
  3101. phba->pport->port_state, psli->sli_flag);
  3102. /* perform board reset */
  3103. phba->fc_eventTag = 0;
  3104. phba->pport->fc_myDID = 0;
  3105. phba->pport->fc_prevDID = 0;
  3106. /* Turn off parity checking and serr during the physical reset */
  3107. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3108. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3109. (cfg_value &
  3110. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3111. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3112. /* Now toggle INITFF bit in the Host Control Register */
  3113. writel(HC_INITFF, phba->HCregaddr);
  3114. mdelay(1);
  3115. readl(phba->HCregaddr); /* flush */
  3116. writel(0, phba->HCregaddr);
  3117. readl(phba->HCregaddr); /* flush */
  3118. /* Restore PCI cmd register */
  3119. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3120. /* Initialize relevant SLI info */
  3121. for (i = 0; i < psli->num_rings; i++) {
  3122. pring = &psli->ring[i];
  3123. pring->flag = 0;
  3124. pring->rspidx = 0;
  3125. pring->next_cmdidx = 0;
  3126. pring->local_getidx = 0;
  3127. pring->cmdidx = 0;
  3128. pring->missbufcnt = 0;
  3129. }
  3130. phba->link_state = LPFC_WARM_START;
  3131. return 0;
  3132. }
  3133. /**
  3134. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3135. * @phba: Pointer to HBA context object.
  3136. *
  3137. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3138. * checking during resets the device. The caller is not required to hold
  3139. * any locks.
  3140. *
  3141. * This function returns 0 always.
  3142. **/
  3143. int
  3144. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3145. {
  3146. struct lpfc_sli *psli = &phba->sli;
  3147. uint16_t cfg_value;
  3148. uint8_t qindx;
  3149. /* Reset HBA */
  3150. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3151. "0295 Reset HBA Data: x%x x%x\n",
  3152. phba->pport->port_state, psli->sli_flag);
  3153. /* perform board reset */
  3154. phba->fc_eventTag = 0;
  3155. phba->pport->fc_myDID = 0;
  3156. phba->pport->fc_prevDID = 0;
  3157. /* Turn off parity checking and serr during the physical reset */
  3158. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3159. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3160. (cfg_value &
  3161. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3162. spin_lock_irq(&phba->hbalock);
  3163. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3164. phba->fcf.fcf_flag = 0;
  3165. /* Clean up the child queue list for the CQs */
  3166. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3167. list_del_init(&phba->sli4_hba.els_wq->list);
  3168. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3169. list_del_init(&phba->sli4_hba.dat_rq->list);
  3170. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3171. list_del_init(&phba->sli4_hba.els_cq->list);
  3172. list_del_init(&phba->sli4_hba.rxq_cq->list);
  3173. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3174. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3175. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3176. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3177. spin_unlock_irq(&phba->hbalock);
  3178. /* Now physically reset the device */
  3179. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3180. "0389 Performing PCI function reset!\n");
  3181. /* Perform FCoE PCI function reset */
  3182. lpfc_pci_function_reset(phba);
  3183. return 0;
  3184. }
  3185. /**
  3186. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3187. * @phba: Pointer to HBA context object.
  3188. *
  3189. * This function is called in the SLI initialization code path to
  3190. * restart the HBA. The caller is not required to hold any lock.
  3191. * This function writes MBX_RESTART mailbox command to the SLIM and
  3192. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3193. * function to free any pending commands. The function enables
  3194. * POST only during the first initialization. The function returns zero.
  3195. * The function does not guarantee completion of MBX_RESTART mailbox
  3196. * command before the return of this function.
  3197. **/
  3198. static int
  3199. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3200. {
  3201. MAILBOX_t *mb;
  3202. struct lpfc_sli *psli;
  3203. volatile uint32_t word0;
  3204. void __iomem *to_slim;
  3205. spin_lock_irq(&phba->hbalock);
  3206. psli = &phba->sli;
  3207. /* Restart HBA */
  3208. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3209. "0337 Restart HBA Data: x%x x%x\n",
  3210. phba->pport->port_state, psli->sli_flag);
  3211. word0 = 0;
  3212. mb = (MAILBOX_t *) &word0;
  3213. mb->mbxCommand = MBX_RESTART;
  3214. mb->mbxHc = 1;
  3215. lpfc_reset_barrier(phba);
  3216. to_slim = phba->MBslimaddr;
  3217. writel(*(uint32_t *) mb, to_slim);
  3218. readl(to_slim); /* flush */
  3219. /* Only skip post after fc_ffinit is completed */
  3220. if (phba->pport->port_state)
  3221. word0 = 1; /* This is really setting up word1 */
  3222. else
  3223. word0 = 0; /* This is really setting up word1 */
  3224. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3225. writel(*(uint32_t *) mb, to_slim);
  3226. readl(to_slim); /* flush */
  3227. lpfc_sli_brdreset(phba);
  3228. phba->pport->stopped = 0;
  3229. phba->link_state = LPFC_INIT_START;
  3230. phba->hba_flag = 0;
  3231. spin_unlock_irq(&phba->hbalock);
  3232. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3233. psli->stats_start = get_seconds();
  3234. /* Give the INITFF and Post time to settle. */
  3235. mdelay(100);
  3236. lpfc_hba_down_post(phba);
  3237. return 0;
  3238. }
  3239. /**
  3240. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3241. * @phba: Pointer to HBA context object.
  3242. *
  3243. * This function is called in the SLI initialization code path to restart
  3244. * a SLI4 HBA. The caller is not required to hold any lock.
  3245. * At the end of the function, it calls lpfc_hba_down_post function to
  3246. * free any pending commands.
  3247. **/
  3248. static int
  3249. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3250. {
  3251. struct lpfc_sli *psli = &phba->sli;
  3252. /* Restart HBA */
  3253. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3254. "0296 Restart HBA Data: x%x x%x\n",
  3255. phba->pport->port_state, psli->sli_flag);
  3256. lpfc_sli4_brdreset(phba);
  3257. spin_lock_irq(&phba->hbalock);
  3258. phba->pport->stopped = 0;
  3259. phba->link_state = LPFC_INIT_START;
  3260. phba->hba_flag = 0;
  3261. spin_unlock_irq(&phba->hbalock);
  3262. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3263. psli->stats_start = get_seconds();
  3264. lpfc_hba_down_post(phba);
  3265. return 0;
  3266. }
  3267. /**
  3268. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3269. * @phba: Pointer to HBA context object.
  3270. *
  3271. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3272. * API jump table function pointer from the lpfc_hba struct.
  3273. **/
  3274. int
  3275. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3276. {
  3277. return phba->lpfc_sli_brdrestart(phba);
  3278. }
  3279. /**
  3280. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3281. * @phba: Pointer to HBA context object.
  3282. *
  3283. * This function is called after a HBA restart to wait for successful
  3284. * restart of the HBA. Successful restart of the HBA is indicated by
  3285. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3286. * iteration, the function will restart the HBA again. The function returns
  3287. * zero if HBA successfully restarted else returns negative error code.
  3288. **/
  3289. static int
  3290. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3291. {
  3292. uint32_t status, i = 0;
  3293. /* Read the HBA Host Status Register */
  3294. status = readl(phba->HSregaddr);
  3295. /* Check status register to see what current state is */
  3296. i = 0;
  3297. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3298. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3299. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3300. * 4.
  3301. */
  3302. if (i++ >= 20) {
  3303. /* Adapter failed to init, timeout, status reg
  3304. <status> */
  3305. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3306. "0436 Adapter failed to init, "
  3307. "timeout, status reg x%x, "
  3308. "FW Data: A8 x%x AC x%x\n", status,
  3309. readl(phba->MBslimaddr + 0xa8),
  3310. readl(phba->MBslimaddr + 0xac));
  3311. phba->link_state = LPFC_HBA_ERROR;
  3312. return -ETIMEDOUT;
  3313. }
  3314. /* Check to see if any errors occurred during init */
  3315. if (status & HS_FFERM) {
  3316. /* ERROR: During chipset initialization */
  3317. /* Adapter failed to init, chipset, status reg
  3318. <status> */
  3319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3320. "0437 Adapter failed to init, "
  3321. "chipset, status reg x%x, "
  3322. "FW Data: A8 x%x AC x%x\n", status,
  3323. readl(phba->MBslimaddr + 0xa8),
  3324. readl(phba->MBslimaddr + 0xac));
  3325. phba->link_state = LPFC_HBA_ERROR;
  3326. return -EIO;
  3327. }
  3328. if (i <= 5) {
  3329. msleep(10);
  3330. } else if (i <= 10) {
  3331. msleep(500);
  3332. } else {
  3333. msleep(2500);
  3334. }
  3335. if (i == 15) {
  3336. /* Do post */
  3337. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3338. lpfc_sli_brdrestart(phba);
  3339. }
  3340. /* Read the HBA Host Status Register */
  3341. status = readl(phba->HSregaddr);
  3342. }
  3343. /* Check to see if any errors occurred during init */
  3344. if (status & HS_FFERM) {
  3345. /* ERROR: During chipset initialization */
  3346. /* Adapter failed to init, chipset, status reg <status> */
  3347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3348. "0438 Adapter failed to init, chipset, "
  3349. "status reg x%x, "
  3350. "FW Data: A8 x%x AC x%x\n", status,
  3351. readl(phba->MBslimaddr + 0xa8),
  3352. readl(phba->MBslimaddr + 0xac));
  3353. phba->link_state = LPFC_HBA_ERROR;
  3354. return -EIO;
  3355. }
  3356. /* Clear all interrupt enable conditions */
  3357. writel(0, phba->HCregaddr);
  3358. readl(phba->HCregaddr); /* flush */
  3359. /* setup host attn register */
  3360. writel(0xffffffff, phba->HAregaddr);
  3361. readl(phba->HAregaddr); /* flush */
  3362. return 0;
  3363. }
  3364. /**
  3365. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3366. *
  3367. * This function calculates and returns the number of HBQs required to be
  3368. * configured.
  3369. **/
  3370. int
  3371. lpfc_sli_hbq_count(void)
  3372. {
  3373. return ARRAY_SIZE(lpfc_hbq_defs);
  3374. }
  3375. /**
  3376. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3377. *
  3378. * This function adds the number of hbq entries in every HBQ to get
  3379. * the total number of hbq entries required for the HBA and returns
  3380. * the total count.
  3381. **/
  3382. static int
  3383. lpfc_sli_hbq_entry_count(void)
  3384. {
  3385. int hbq_count = lpfc_sli_hbq_count();
  3386. int count = 0;
  3387. int i;
  3388. for (i = 0; i < hbq_count; ++i)
  3389. count += lpfc_hbq_defs[i]->entry_count;
  3390. return count;
  3391. }
  3392. /**
  3393. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3394. *
  3395. * This function calculates amount of memory required for all hbq entries
  3396. * to be configured and returns the total memory required.
  3397. **/
  3398. int
  3399. lpfc_sli_hbq_size(void)
  3400. {
  3401. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3402. }
  3403. /**
  3404. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3405. * @phba: Pointer to HBA context object.
  3406. *
  3407. * This function is called during the SLI initialization to configure
  3408. * all the HBQs and post buffers to the HBQ. The caller is not
  3409. * required to hold any locks. This function will return zero if successful
  3410. * else it will return negative error code.
  3411. **/
  3412. static int
  3413. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3414. {
  3415. int hbq_count = lpfc_sli_hbq_count();
  3416. LPFC_MBOXQ_t *pmb;
  3417. MAILBOX_t *pmbox;
  3418. uint32_t hbqno;
  3419. uint32_t hbq_entry_index;
  3420. /* Get a Mailbox buffer to setup mailbox
  3421. * commands for HBA initialization
  3422. */
  3423. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3424. if (!pmb)
  3425. return -ENOMEM;
  3426. pmbox = &pmb->u.mb;
  3427. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3428. phba->link_state = LPFC_INIT_MBX_CMDS;
  3429. phba->hbq_in_use = 1;
  3430. hbq_entry_index = 0;
  3431. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3432. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3433. phba->hbqs[hbqno].hbqPutIdx = 0;
  3434. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3435. phba->hbqs[hbqno].entry_count =
  3436. lpfc_hbq_defs[hbqno]->entry_count;
  3437. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3438. hbq_entry_index, pmb);
  3439. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3440. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3441. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3442. mbxStatus <status>, ring <num> */
  3443. lpfc_printf_log(phba, KERN_ERR,
  3444. LOG_SLI | LOG_VPORT,
  3445. "1805 Adapter failed to init. "
  3446. "Data: x%x x%x x%x\n",
  3447. pmbox->mbxCommand,
  3448. pmbox->mbxStatus, hbqno);
  3449. phba->link_state = LPFC_HBA_ERROR;
  3450. mempool_free(pmb, phba->mbox_mem_pool);
  3451. return ENXIO;
  3452. }
  3453. }
  3454. phba->hbq_count = hbq_count;
  3455. mempool_free(pmb, phba->mbox_mem_pool);
  3456. /* Initially populate or replenish the HBQs */
  3457. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3458. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3459. return 0;
  3460. }
  3461. /**
  3462. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3463. * @phba: Pointer to HBA context object.
  3464. *
  3465. * This function is called during the SLI initialization to configure
  3466. * all the HBQs and post buffers to the HBQ. The caller is not
  3467. * required to hold any locks. This function will return zero if successful
  3468. * else it will return negative error code.
  3469. **/
  3470. static int
  3471. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3472. {
  3473. phba->hbq_in_use = 1;
  3474. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3475. phba->hbq_count = 1;
  3476. /* Initially populate or replenish the HBQs */
  3477. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3478. return 0;
  3479. }
  3480. /**
  3481. * lpfc_sli_config_port - Issue config port mailbox command
  3482. * @phba: Pointer to HBA context object.
  3483. * @sli_mode: sli mode - 2/3
  3484. *
  3485. * This function is called by the sli intialization code path
  3486. * to issue config_port mailbox command. This function restarts the
  3487. * HBA firmware and issues a config_port mailbox command to configure
  3488. * the SLI interface in the sli mode specified by sli_mode
  3489. * variable. The caller is not required to hold any locks.
  3490. * The function returns 0 if successful, else returns negative error
  3491. * code.
  3492. **/
  3493. int
  3494. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3495. {
  3496. LPFC_MBOXQ_t *pmb;
  3497. uint32_t resetcount = 0, rc = 0, done = 0;
  3498. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3499. if (!pmb) {
  3500. phba->link_state = LPFC_HBA_ERROR;
  3501. return -ENOMEM;
  3502. }
  3503. phba->sli_rev = sli_mode;
  3504. while (resetcount < 2 && !done) {
  3505. spin_lock_irq(&phba->hbalock);
  3506. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3507. spin_unlock_irq(&phba->hbalock);
  3508. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3509. lpfc_sli_brdrestart(phba);
  3510. rc = lpfc_sli_chipset_init(phba);
  3511. if (rc)
  3512. break;
  3513. spin_lock_irq(&phba->hbalock);
  3514. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3515. spin_unlock_irq(&phba->hbalock);
  3516. resetcount++;
  3517. /* Call pre CONFIG_PORT mailbox command initialization. A
  3518. * value of 0 means the call was successful. Any other
  3519. * nonzero value is a failure, but if ERESTART is returned,
  3520. * the driver may reset the HBA and try again.
  3521. */
  3522. rc = lpfc_config_port_prep(phba);
  3523. if (rc == -ERESTART) {
  3524. phba->link_state = LPFC_LINK_UNKNOWN;
  3525. continue;
  3526. } else if (rc)
  3527. break;
  3528. phba->link_state = LPFC_INIT_MBX_CMDS;
  3529. lpfc_config_port(phba, pmb);
  3530. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3531. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3532. LPFC_SLI3_HBQ_ENABLED |
  3533. LPFC_SLI3_CRP_ENABLED |
  3534. LPFC_SLI3_INB_ENABLED |
  3535. LPFC_SLI3_BG_ENABLED);
  3536. if (rc != MBX_SUCCESS) {
  3537. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3538. "0442 Adapter failed to init, mbxCmd x%x "
  3539. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3540. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3541. spin_lock_irq(&phba->hbalock);
  3542. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3543. spin_unlock_irq(&phba->hbalock);
  3544. rc = -ENXIO;
  3545. } else {
  3546. /* Allow asynchronous mailbox command to go through */
  3547. spin_lock_irq(&phba->hbalock);
  3548. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3549. spin_unlock_irq(&phba->hbalock);
  3550. done = 1;
  3551. }
  3552. }
  3553. if (!done) {
  3554. rc = -EINVAL;
  3555. goto do_prep_failed;
  3556. }
  3557. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3558. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3559. rc = -ENXIO;
  3560. goto do_prep_failed;
  3561. }
  3562. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3563. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3564. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3565. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3566. phba->max_vpi : phba->max_vports;
  3567. } else
  3568. phba->max_vpi = 0;
  3569. if (pmb->u.mb.un.varCfgPort.gdss)
  3570. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3571. if (pmb->u.mb.un.varCfgPort.gerbm)
  3572. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3573. if (pmb->u.mb.un.varCfgPort.gcrp)
  3574. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3575. if (pmb->u.mb.un.varCfgPort.ginb) {
  3576. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3577. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3578. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3579. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3580. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3581. phba->inb_last_counter =
  3582. phba->mbox->us.s3_inb_pgp.counter;
  3583. } else {
  3584. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3585. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3586. phba->inb_ha_copy = NULL;
  3587. phba->inb_counter = NULL;
  3588. }
  3589. if (phba->cfg_enable_bg) {
  3590. if (pmb->u.mb.un.varCfgPort.gbg)
  3591. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3592. else
  3593. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3594. "0443 Adapter did not grant "
  3595. "BlockGuard\n");
  3596. }
  3597. } else {
  3598. phba->hbq_get = NULL;
  3599. phba->port_gp = phba->mbox->us.s2.port;
  3600. phba->inb_ha_copy = NULL;
  3601. phba->inb_counter = NULL;
  3602. phba->max_vpi = 0;
  3603. }
  3604. do_prep_failed:
  3605. mempool_free(pmb, phba->mbox_mem_pool);
  3606. return rc;
  3607. }
  3608. /**
  3609. * lpfc_sli_hba_setup - SLI intialization function
  3610. * @phba: Pointer to HBA context object.
  3611. *
  3612. * This function is the main SLI intialization function. This function
  3613. * is called by the HBA intialization code, HBA reset code and HBA
  3614. * error attention handler code. Caller is not required to hold any
  3615. * locks. This function issues config_port mailbox command to configure
  3616. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3617. * calls the config_port_post function to issue init_link mailbox
  3618. * command and to start the discovery. The function will return zero
  3619. * if successful, else it will return negative error code.
  3620. **/
  3621. int
  3622. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3623. {
  3624. uint32_t rc;
  3625. int mode = 3;
  3626. switch (lpfc_sli_mode) {
  3627. case 2:
  3628. if (phba->cfg_enable_npiv) {
  3629. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3630. "1824 NPIV enabled: Override lpfc_sli_mode "
  3631. "parameter (%d) to auto (0).\n",
  3632. lpfc_sli_mode);
  3633. break;
  3634. }
  3635. mode = 2;
  3636. break;
  3637. case 0:
  3638. case 3:
  3639. break;
  3640. default:
  3641. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3642. "1819 Unrecognized lpfc_sli_mode "
  3643. "parameter: %d.\n", lpfc_sli_mode);
  3644. break;
  3645. }
  3646. rc = lpfc_sli_config_port(phba, mode);
  3647. if (rc && lpfc_sli_mode == 3)
  3648. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3649. "1820 Unable to select SLI-3. "
  3650. "Not supported by adapter.\n");
  3651. if (rc && mode != 2)
  3652. rc = lpfc_sli_config_port(phba, 2);
  3653. if (rc)
  3654. goto lpfc_sli_hba_setup_error;
  3655. if (phba->sli_rev == 3) {
  3656. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3657. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3658. } else {
  3659. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3660. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3661. phba->sli3_options = 0;
  3662. }
  3663. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3664. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3665. phba->sli_rev, phba->max_vpi);
  3666. rc = lpfc_sli_ring_map(phba);
  3667. if (rc)
  3668. goto lpfc_sli_hba_setup_error;
  3669. /* Init HBQs */
  3670. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3671. rc = lpfc_sli_hbq_setup(phba);
  3672. if (rc)
  3673. goto lpfc_sli_hba_setup_error;
  3674. }
  3675. spin_lock_irq(&phba->hbalock);
  3676. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3677. spin_unlock_irq(&phba->hbalock);
  3678. rc = lpfc_config_port_post(phba);
  3679. if (rc)
  3680. goto lpfc_sli_hba_setup_error;
  3681. return rc;
  3682. lpfc_sli_hba_setup_error:
  3683. phba->link_state = LPFC_HBA_ERROR;
  3684. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3685. "0445 Firmware initialization failed\n");
  3686. return rc;
  3687. }
  3688. /**
  3689. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3690. * @phba: Pointer to HBA context object.
  3691. * @mboxq: mailbox pointer.
  3692. * This function issue a dump mailbox command to read config region
  3693. * 23 and parse the records in the region and populate driver
  3694. * data structure.
  3695. **/
  3696. static int
  3697. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3698. LPFC_MBOXQ_t *mboxq)
  3699. {
  3700. struct lpfc_dmabuf *mp;
  3701. struct lpfc_mqe *mqe;
  3702. uint32_t data_length;
  3703. int rc;
  3704. /* Program the default value of vlan_id and fc_map */
  3705. phba->valid_vlan = 0;
  3706. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3707. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3708. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3709. mqe = &mboxq->u.mqe;
  3710. if (lpfc_dump_fcoe_param(phba, mboxq))
  3711. return -ENOMEM;
  3712. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3713. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3714. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3715. "(%d):2571 Mailbox cmd x%x Status x%x "
  3716. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3717. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3718. "CQ: x%x x%x x%x x%x\n",
  3719. mboxq->vport ? mboxq->vport->vpi : 0,
  3720. bf_get(lpfc_mqe_command, mqe),
  3721. bf_get(lpfc_mqe_status, mqe),
  3722. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3723. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3724. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3725. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3726. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3727. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3728. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3729. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3730. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3731. mboxq->mcqe.word0,
  3732. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3733. mboxq->mcqe.trailer);
  3734. if (rc) {
  3735. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3736. kfree(mp);
  3737. return -EIO;
  3738. }
  3739. data_length = mqe->un.mb_words[5];
  3740. if (data_length > DMP_FCOEPARAM_RGN_SIZE) {
  3741. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3742. kfree(mp);
  3743. return -EIO;
  3744. }
  3745. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3746. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3747. kfree(mp);
  3748. return 0;
  3749. }
  3750. /**
  3751. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3752. * @phba: pointer to lpfc hba data structure.
  3753. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3754. * @vpd: pointer to the memory to hold resulting port vpd data.
  3755. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3756. * On output, the number of data bytes in @vpd.
  3757. *
  3758. * This routine executes a READ_REV SLI4 mailbox command. In
  3759. * addition, this routine gets the port vpd data.
  3760. *
  3761. * Return codes
  3762. * 0 - sucessful
  3763. * ENOMEM - could not allocated memory.
  3764. **/
  3765. static int
  3766. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3767. uint8_t *vpd, uint32_t *vpd_size)
  3768. {
  3769. int rc = 0;
  3770. uint32_t dma_size;
  3771. struct lpfc_dmabuf *dmabuf;
  3772. struct lpfc_mqe *mqe;
  3773. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3774. if (!dmabuf)
  3775. return -ENOMEM;
  3776. /*
  3777. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3778. * mailbox command.
  3779. */
  3780. dma_size = *vpd_size;
  3781. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3782. dma_size,
  3783. &dmabuf->phys,
  3784. GFP_KERNEL);
  3785. if (!dmabuf->virt) {
  3786. kfree(dmabuf);
  3787. return -ENOMEM;
  3788. }
  3789. memset(dmabuf->virt, 0, dma_size);
  3790. /*
  3791. * The SLI4 implementation of READ_REV conflicts at word1,
  3792. * bits 31:16 and SLI4 adds vpd functionality not present
  3793. * in SLI3. This code corrects the conflicts.
  3794. */
  3795. lpfc_read_rev(phba, mboxq);
  3796. mqe = &mboxq->u.mqe;
  3797. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3798. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3799. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3800. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3801. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3802. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3803. if (rc) {
  3804. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3805. dmabuf->virt, dmabuf->phys);
  3806. return -EIO;
  3807. }
  3808. /*
  3809. * The available vpd length cannot be bigger than the
  3810. * DMA buffer passed to the port. Catch the less than
  3811. * case and update the caller's size.
  3812. */
  3813. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3814. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3815. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3816. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3817. dmabuf->virt, dmabuf->phys);
  3818. kfree(dmabuf);
  3819. return 0;
  3820. }
  3821. /**
  3822. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3823. * @phba: pointer to lpfc hba data structure.
  3824. *
  3825. * This routine is called to explicitly arm the SLI4 device's completion and
  3826. * event queues
  3827. **/
  3828. static void
  3829. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3830. {
  3831. uint8_t fcp_eqidx;
  3832. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3833. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3834. lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM);
  3835. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3836. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3837. LPFC_QUEUE_REARM);
  3838. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3839. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3840. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3841. LPFC_QUEUE_REARM);
  3842. }
  3843. /**
  3844. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3845. * @phba: Pointer to HBA context object.
  3846. *
  3847. * This function is the main SLI4 device intialization PCI function. This
  3848. * function is called by the HBA intialization code, HBA reset code and
  3849. * HBA error attention handler code. Caller is not required to hold any
  3850. * locks.
  3851. **/
  3852. int
  3853. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3854. {
  3855. int rc;
  3856. LPFC_MBOXQ_t *mboxq;
  3857. struct lpfc_mqe *mqe;
  3858. uint8_t *vpd;
  3859. uint32_t vpd_size;
  3860. uint32_t ftr_rsp = 0;
  3861. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3862. struct lpfc_vport *vport = phba->pport;
  3863. struct lpfc_dmabuf *mp;
  3864. /* Perform a PCI function reset to start from clean */
  3865. rc = lpfc_pci_function_reset(phba);
  3866. if (unlikely(rc))
  3867. return -ENODEV;
  3868. /* Check the HBA Host Status Register for readyness */
  3869. rc = lpfc_sli4_post_status_check(phba);
  3870. if (unlikely(rc))
  3871. return -ENODEV;
  3872. else {
  3873. spin_lock_irq(&phba->hbalock);
  3874. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3875. spin_unlock_irq(&phba->hbalock);
  3876. }
  3877. /*
  3878. * Allocate a single mailbox container for initializing the
  3879. * port.
  3880. */
  3881. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3882. if (!mboxq)
  3883. return -ENOMEM;
  3884. /*
  3885. * Continue initialization with default values even if driver failed
  3886. * to read FCoE param config regions
  3887. */
  3888. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3889. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3890. "2570 Failed to read FCoE parameters \n");
  3891. /* Issue READ_REV to collect vpd and FW information. */
  3892. vpd_size = PAGE_SIZE;
  3893. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3894. if (!vpd) {
  3895. rc = -ENOMEM;
  3896. goto out_free_mbox;
  3897. }
  3898. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3899. if (unlikely(rc))
  3900. goto out_free_vpd;
  3901. mqe = &mboxq->u.mqe;
  3902. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3903. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3904. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3905. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3906. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3907. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3908. "0376 READ_REV Error. SLI Level %d "
  3909. "FCoE enabled %d\n",
  3910. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3911. rc = -EIO;
  3912. goto out_free_vpd;
  3913. }
  3914. /*
  3915. * Evaluate the read rev and vpd data. Populate the driver
  3916. * state with the results. If this routine fails, the failure
  3917. * is not fatal as the driver will use generic values.
  3918. */
  3919. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3920. if (unlikely(!rc)) {
  3921. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3922. "0377 Error %d parsing vpd. "
  3923. "Using defaults.\n", rc);
  3924. rc = 0;
  3925. }
  3926. /* Save information as VPD data */
  3927. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3928. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3929. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3930. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3931. &mqe->un.read_rev);
  3932. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3933. &mqe->un.read_rev);
  3934. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3935. &mqe->un.read_rev);
  3936. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3937. &mqe->un.read_rev);
  3938. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3939. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3940. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3941. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3942. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3943. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3944. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3945. "(%d):0380 READ_REV Status x%x "
  3946. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3947. mboxq->vport ? mboxq->vport->vpi : 0,
  3948. bf_get(lpfc_mqe_status, mqe),
  3949. phba->vpd.rev.opFwName,
  3950. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3951. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3952. /*
  3953. * Discover the port's supported feature set and match it against the
  3954. * hosts requests.
  3955. */
  3956. lpfc_request_features(phba, mboxq);
  3957. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3958. if (unlikely(rc)) {
  3959. rc = -EIO;
  3960. goto out_free_vpd;
  3961. }
  3962. /*
  3963. * The port must support FCP initiator mode as this is the
  3964. * only mode running in the host.
  3965. */
  3966. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3967. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3968. "0378 No support for fcpi mode.\n");
  3969. ftr_rsp++;
  3970. }
  3971. /*
  3972. * If the port cannot support the host's requested features
  3973. * then turn off the global config parameters to disable the
  3974. * feature in the driver. This is not a fatal error.
  3975. */
  3976. if ((phba->cfg_enable_bg) &&
  3977. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3978. ftr_rsp++;
  3979. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3980. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3981. ftr_rsp++;
  3982. if (ftr_rsp) {
  3983. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3984. "0379 Feature Mismatch Data: x%08x %08x "
  3985. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3986. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3987. phba->cfg_enable_npiv, phba->max_vpi);
  3988. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3989. phba->cfg_enable_bg = 0;
  3990. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3991. phba->cfg_enable_npiv = 0;
  3992. }
  3993. /* These SLI3 features are assumed in SLI4 */
  3994. spin_lock_irq(&phba->hbalock);
  3995. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3996. spin_unlock_irq(&phba->hbalock);
  3997. /* Read the port's service parameters. */
  3998. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3999. mboxq->vport = vport;
  4000. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4001. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4002. if (rc == MBX_SUCCESS) {
  4003. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4004. rc = 0;
  4005. }
  4006. /*
  4007. * This memory was allocated by the lpfc_read_sparam routine. Release
  4008. * it to the mbuf pool.
  4009. */
  4010. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4011. kfree(mp);
  4012. mboxq->context1 = NULL;
  4013. if (unlikely(rc)) {
  4014. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4015. "0382 READ_SPARAM command failed "
  4016. "status %d, mbxStatus x%x\n",
  4017. rc, bf_get(lpfc_mqe_status, mqe));
  4018. phba->link_state = LPFC_HBA_ERROR;
  4019. rc = -EIO;
  4020. goto out_free_vpd;
  4021. }
  4022. if (phba->cfg_soft_wwnn)
  4023. u64_to_wwn(phba->cfg_soft_wwnn,
  4024. vport->fc_sparam.nodeName.u.wwn);
  4025. if (phba->cfg_soft_wwpn)
  4026. u64_to_wwn(phba->cfg_soft_wwpn,
  4027. vport->fc_sparam.portName.u.wwn);
  4028. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4029. sizeof(struct lpfc_name));
  4030. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4031. sizeof(struct lpfc_name));
  4032. /* Update the fc_host data structures with new wwn. */
  4033. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4034. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4035. /* Register SGL pool to the device using non-embedded mailbox command */
  4036. rc = lpfc_sli4_post_sgl_list(phba);
  4037. if (unlikely(rc)) {
  4038. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4039. "0582 Error %d during sgl post operation", rc);
  4040. rc = -ENODEV;
  4041. goto out_free_vpd;
  4042. }
  4043. /* Register SCSI SGL pool to the device */
  4044. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4045. if (unlikely(rc)) {
  4046. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4047. "0383 Error %d during scsi sgl post opeation",
  4048. rc);
  4049. /* Some Scsi buffers were moved to the abort scsi list */
  4050. /* A pci function reset will repost them */
  4051. rc = -ENODEV;
  4052. goto out_free_vpd;
  4053. }
  4054. /* Post the rpi header region to the device. */
  4055. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4056. if (unlikely(rc)) {
  4057. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4058. "0393 Error %d during rpi post operation\n",
  4059. rc);
  4060. rc = -ENODEV;
  4061. goto out_free_vpd;
  4062. }
  4063. if (phba->cfg_enable_fip)
  4064. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1);
  4065. else
  4066. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
  4067. /* Set up all the queues to the device */
  4068. rc = lpfc_sli4_queue_setup(phba);
  4069. if (unlikely(rc)) {
  4070. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4071. "0381 Error %d during queue setup.\n ", rc);
  4072. goto out_stop_timers;
  4073. }
  4074. /* Arm the CQs and then EQs on device */
  4075. lpfc_sli4_arm_cqeq_intr(phba);
  4076. /* Indicate device interrupt mode */
  4077. phba->sli4_hba.intr_enable = 1;
  4078. /* Allow asynchronous mailbox command to go through */
  4079. spin_lock_irq(&phba->hbalock);
  4080. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4081. spin_unlock_irq(&phba->hbalock);
  4082. /* Post receive buffers to the device */
  4083. lpfc_sli4_rb_setup(phba);
  4084. /* Start the ELS watchdog timer */
  4085. /*
  4086. * The driver for SLI4 is not yet ready to process timeouts
  4087. * or interrupts. Once it is, the comment bars can be removed.
  4088. */
  4089. /* mod_timer(&vport->els_tmofunc,
  4090. * jiffies + HZ * (phba->fc_ratov*2)); */
  4091. /* Start heart beat timer */
  4092. mod_timer(&phba->hb_tmofunc,
  4093. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4094. phba->hb_outstanding = 0;
  4095. phba->last_completion_time = jiffies;
  4096. /* Start error attention (ERATT) polling timer */
  4097. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4098. /*
  4099. * The port is ready, set the host's link state to LINK_DOWN
  4100. * in preparation for link interrupts.
  4101. */
  4102. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4103. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4104. lpfc_set_loopback_flag(phba);
  4105. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4106. spin_lock_irq(&phba->hbalock);
  4107. phba->link_state = LPFC_LINK_DOWN;
  4108. spin_unlock_irq(&phba->hbalock);
  4109. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4110. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4111. kfree(vpd);
  4112. return 0;
  4113. } else
  4114. rc = -EIO;
  4115. /* Unset all the queues set up in this routine when error out */
  4116. if (rc)
  4117. lpfc_sli4_queue_unset(phba);
  4118. out_stop_timers:
  4119. if (rc)
  4120. lpfc_stop_hba_timers(phba);
  4121. out_free_vpd:
  4122. kfree(vpd);
  4123. out_free_mbox:
  4124. mempool_free(mboxq, phba->mbox_mem_pool);
  4125. return rc;
  4126. }
  4127. /**
  4128. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4129. * @ptr: context object - pointer to hba structure.
  4130. *
  4131. * This is the callback function for mailbox timer. The mailbox
  4132. * timer is armed when a new mailbox command is issued and the timer
  4133. * is deleted when the mailbox complete. The function is called by
  4134. * the kernel timer code when a mailbox does not complete within
  4135. * expected time. This function wakes up the worker thread to
  4136. * process the mailbox timeout and returns. All the processing is
  4137. * done by the worker thread function lpfc_mbox_timeout_handler.
  4138. **/
  4139. void
  4140. lpfc_mbox_timeout(unsigned long ptr)
  4141. {
  4142. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4143. unsigned long iflag;
  4144. uint32_t tmo_posted;
  4145. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4146. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4147. if (!tmo_posted)
  4148. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4149. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4150. if (!tmo_posted)
  4151. lpfc_worker_wake_up(phba);
  4152. return;
  4153. }
  4154. /**
  4155. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4156. * @phba: Pointer to HBA context object.
  4157. *
  4158. * This function is called from worker thread when a mailbox command times out.
  4159. * The caller is not required to hold any locks. This function will reset the
  4160. * HBA and recover all the pending commands.
  4161. **/
  4162. void
  4163. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4164. {
  4165. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4166. MAILBOX_t *mb = &pmbox->u.mb;
  4167. struct lpfc_sli *psli = &phba->sli;
  4168. struct lpfc_sli_ring *pring;
  4169. /* Check the pmbox pointer first. There is a race condition
  4170. * between the mbox timeout handler getting executed in the
  4171. * worklist and the mailbox actually completing. When this
  4172. * race condition occurs, the mbox_active will be NULL.
  4173. */
  4174. spin_lock_irq(&phba->hbalock);
  4175. if (pmbox == NULL) {
  4176. lpfc_printf_log(phba, KERN_WARNING,
  4177. LOG_MBOX | LOG_SLI,
  4178. "0353 Active Mailbox cleared - mailbox timeout "
  4179. "exiting\n");
  4180. spin_unlock_irq(&phba->hbalock);
  4181. return;
  4182. }
  4183. /* Mbox cmd <mbxCommand> timeout */
  4184. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4185. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4186. mb->mbxCommand,
  4187. phba->pport->port_state,
  4188. phba->sli.sli_flag,
  4189. phba->sli.mbox_active);
  4190. spin_unlock_irq(&phba->hbalock);
  4191. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4192. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4193. * it to fail all oustanding SCSI IO.
  4194. */
  4195. spin_lock_irq(&phba->pport->work_port_lock);
  4196. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4197. spin_unlock_irq(&phba->pport->work_port_lock);
  4198. spin_lock_irq(&phba->hbalock);
  4199. phba->link_state = LPFC_LINK_UNKNOWN;
  4200. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4201. spin_unlock_irq(&phba->hbalock);
  4202. pring = &psli->ring[psli->fcp_ring];
  4203. lpfc_sli_abort_iocb_ring(phba, pring);
  4204. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4205. "0345 Resetting board due to mailbox timeout\n");
  4206. /* Reset the HBA device */
  4207. lpfc_reset_hba(phba);
  4208. }
  4209. /**
  4210. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4211. * @phba: Pointer to HBA context object.
  4212. * @pmbox: Pointer to mailbox object.
  4213. * @flag: Flag indicating how the mailbox need to be processed.
  4214. *
  4215. * This function is called by discovery code and HBA management code
  4216. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4217. * function gets the hbalock to protect the data structures.
  4218. * The mailbox command can be submitted in polling mode, in which case
  4219. * this function will wait in a polling loop for the completion of the
  4220. * mailbox.
  4221. * If the mailbox is submitted in no_wait mode (not polling) the
  4222. * function will submit the command and returns immediately without waiting
  4223. * for the mailbox completion. The no_wait is supported only when HBA
  4224. * is in SLI2/SLI3 mode - interrupts are enabled.
  4225. * The SLI interface allows only one mailbox pending at a time. If the
  4226. * mailbox is issued in polling mode and there is already a mailbox
  4227. * pending, then the function will return an error. If the mailbox is issued
  4228. * in NO_WAIT mode and there is a mailbox pending already, the function
  4229. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4230. * The sli layer owns the mailbox object until the completion of mailbox
  4231. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4232. * return codes the caller owns the mailbox command after the return of
  4233. * the function.
  4234. **/
  4235. static int
  4236. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4237. uint32_t flag)
  4238. {
  4239. MAILBOX_t *mb;
  4240. struct lpfc_sli *psli = &phba->sli;
  4241. uint32_t status, evtctr;
  4242. uint32_t ha_copy;
  4243. int i;
  4244. unsigned long timeout;
  4245. unsigned long drvr_flag = 0;
  4246. uint32_t word0, ldata;
  4247. void __iomem *to_slim;
  4248. int processing_queue = 0;
  4249. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4250. if (!pmbox) {
  4251. /* processing mbox queue from intr_handler */
  4252. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4253. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4254. return MBX_SUCCESS;
  4255. }
  4256. processing_queue = 1;
  4257. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4258. pmbox = lpfc_mbox_get(phba);
  4259. if (!pmbox) {
  4260. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4261. return MBX_SUCCESS;
  4262. }
  4263. }
  4264. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4265. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4266. if(!pmbox->vport) {
  4267. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4268. lpfc_printf_log(phba, KERN_ERR,
  4269. LOG_MBOX | LOG_VPORT,
  4270. "1806 Mbox x%x failed. No vport\n",
  4271. pmbox->u.mb.mbxCommand);
  4272. dump_stack();
  4273. goto out_not_finished;
  4274. }
  4275. }
  4276. /* If the PCI channel is in offline state, do not post mbox. */
  4277. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4278. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4279. goto out_not_finished;
  4280. }
  4281. /* If HBA has a deferred error attention, fail the iocb. */
  4282. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4283. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4284. goto out_not_finished;
  4285. }
  4286. psli = &phba->sli;
  4287. mb = &pmbox->u.mb;
  4288. status = MBX_SUCCESS;
  4289. if (phba->link_state == LPFC_HBA_ERROR) {
  4290. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4291. /* Mbox command <mbxCommand> cannot issue */
  4292. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4293. "(%d):0311 Mailbox command x%x cannot "
  4294. "issue Data: x%x x%x\n",
  4295. pmbox->vport ? pmbox->vport->vpi : 0,
  4296. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4297. goto out_not_finished;
  4298. }
  4299. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4300. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4301. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4302. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4303. "(%d):2528 Mailbox command x%x cannot "
  4304. "issue Data: x%x x%x\n",
  4305. pmbox->vport ? pmbox->vport->vpi : 0,
  4306. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4307. goto out_not_finished;
  4308. }
  4309. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4310. /* Polling for a mbox command when another one is already active
  4311. * is not allowed in SLI. Also, the driver must have established
  4312. * SLI2 mode to queue and process multiple mbox commands.
  4313. */
  4314. if (flag & MBX_POLL) {
  4315. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4316. /* Mbox command <mbxCommand> cannot issue */
  4317. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4318. "(%d):2529 Mailbox command x%x "
  4319. "cannot issue Data: x%x x%x\n",
  4320. pmbox->vport ? pmbox->vport->vpi : 0,
  4321. pmbox->u.mb.mbxCommand,
  4322. psli->sli_flag, flag);
  4323. goto out_not_finished;
  4324. }
  4325. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4326. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4327. /* Mbox command <mbxCommand> cannot issue */
  4328. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4329. "(%d):2530 Mailbox command x%x "
  4330. "cannot issue Data: x%x x%x\n",
  4331. pmbox->vport ? pmbox->vport->vpi : 0,
  4332. pmbox->u.mb.mbxCommand,
  4333. psli->sli_flag, flag);
  4334. goto out_not_finished;
  4335. }
  4336. /* Another mailbox command is still being processed, queue this
  4337. * command to be processed later.
  4338. */
  4339. lpfc_mbox_put(phba, pmbox);
  4340. /* Mbox cmd issue - BUSY */
  4341. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4342. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4343. "x%x x%x x%x x%x\n",
  4344. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4345. mb->mbxCommand, phba->pport->port_state,
  4346. psli->sli_flag, flag);
  4347. psli->slistat.mbox_busy++;
  4348. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4349. if (pmbox->vport) {
  4350. lpfc_debugfs_disc_trc(pmbox->vport,
  4351. LPFC_DISC_TRC_MBOX_VPORT,
  4352. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4353. (uint32_t)mb->mbxCommand,
  4354. mb->un.varWords[0], mb->un.varWords[1]);
  4355. }
  4356. else {
  4357. lpfc_debugfs_disc_trc(phba->pport,
  4358. LPFC_DISC_TRC_MBOX,
  4359. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4360. (uint32_t)mb->mbxCommand,
  4361. mb->un.varWords[0], mb->un.varWords[1]);
  4362. }
  4363. return MBX_BUSY;
  4364. }
  4365. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4366. /* If we are not polling, we MUST be in SLI2 mode */
  4367. if (flag != MBX_POLL) {
  4368. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4369. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4370. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4371. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4372. /* Mbox command <mbxCommand> cannot issue */
  4373. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4374. "(%d):2531 Mailbox command x%x "
  4375. "cannot issue Data: x%x x%x\n",
  4376. pmbox->vport ? pmbox->vport->vpi : 0,
  4377. pmbox->u.mb.mbxCommand,
  4378. psli->sli_flag, flag);
  4379. goto out_not_finished;
  4380. }
  4381. /* timeout active mbox command */
  4382. mod_timer(&psli->mbox_tmo, (jiffies +
  4383. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4384. }
  4385. /* Mailbox cmd <cmd> issue */
  4386. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4387. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4388. "x%x\n",
  4389. pmbox->vport ? pmbox->vport->vpi : 0,
  4390. mb->mbxCommand, phba->pport->port_state,
  4391. psli->sli_flag, flag);
  4392. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4393. if (pmbox->vport) {
  4394. lpfc_debugfs_disc_trc(pmbox->vport,
  4395. LPFC_DISC_TRC_MBOX_VPORT,
  4396. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4397. (uint32_t)mb->mbxCommand,
  4398. mb->un.varWords[0], mb->un.varWords[1]);
  4399. }
  4400. else {
  4401. lpfc_debugfs_disc_trc(phba->pport,
  4402. LPFC_DISC_TRC_MBOX,
  4403. "MBOX Send: cmd:x%x mb:x%x x%x",
  4404. (uint32_t)mb->mbxCommand,
  4405. mb->un.varWords[0], mb->un.varWords[1]);
  4406. }
  4407. }
  4408. psli->slistat.mbox_cmd++;
  4409. evtctr = psli->slistat.mbox_event;
  4410. /* next set own bit for the adapter and copy over command word */
  4411. mb->mbxOwner = OWN_CHIP;
  4412. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4413. /* First copy command data to host SLIM area */
  4414. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4415. } else {
  4416. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4417. /* copy command data into host mbox for cmpl */
  4418. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4419. }
  4420. /* First copy mbox command data to HBA SLIM, skip past first
  4421. word */
  4422. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4423. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4424. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4425. /* Next copy over first word, with mbxOwner set */
  4426. ldata = *((uint32_t *)mb);
  4427. to_slim = phba->MBslimaddr;
  4428. writel(ldata, to_slim);
  4429. readl(to_slim); /* flush */
  4430. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4431. /* switch over to host mailbox */
  4432. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4433. }
  4434. }
  4435. wmb();
  4436. switch (flag) {
  4437. case MBX_NOWAIT:
  4438. /* Set up reference to mailbox command */
  4439. psli->mbox_active = pmbox;
  4440. /* Interrupt board to do it */
  4441. writel(CA_MBATT, phba->CAregaddr);
  4442. readl(phba->CAregaddr); /* flush */
  4443. /* Don't wait for it to finish, just return */
  4444. break;
  4445. case MBX_POLL:
  4446. /* Set up null reference to mailbox command */
  4447. psli->mbox_active = NULL;
  4448. /* Interrupt board to do it */
  4449. writel(CA_MBATT, phba->CAregaddr);
  4450. readl(phba->CAregaddr); /* flush */
  4451. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4452. /* First read mbox status word */
  4453. word0 = *((uint32_t *)phba->mbox);
  4454. word0 = le32_to_cpu(word0);
  4455. } else {
  4456. /* First read mbox status word */
  4457. word0 = readl(phba->MBslimaddr);
  4458. }
  4459. /* Read the HBA Host Attention Register */
  4460. ha_copy = readl(phba->HAregaddr);
  4461. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4462. mb->mbxCommand) *
  4463. 1000) + jiffies;
  4464. i = 0;
  4465. /* Wait for command to complete */
  4466. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4467. (!(ha_copy & HA_MBATT) &&
  4468. (phba->link_state > LPFC_WARM_START))) {
  4469. if (time_after(jiffies, timeout)) {
  4470. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4471. spin_unlock_irqrestore(&phba->hbalock,
  4472. drvr_flag);
  4473. goto out_not_finished;
  4474. }
  4475. /* Check if we took a mbox interrupt while we were
  4476. polling */
  4477. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4478. && (evtctr != psli->slistat.mbox_event))
  4479. break;
  4480. if (i++ > 10) {
  4481. spin_unlock_irqrestore(&phba->hbalock,
  4482. drvr_flag);
  4483. msleep(1);
  4484. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4485. }
  4486. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4487. /* First copy command data */
  4488. word0 = *((uint32_t *)phba->mbox);
  4489. word0 = le32_to_cpu(word0);
  4490. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4491. MAILBOX_t *slimmb;
  4492. uint32_t slimword0;
  4493. /* Check real SLIM for any errors */
  4494. slimword0 = readl(phba->MBslimaddr);
  4495. slimmb = (MAILBOX_t *) & slimword0;
  4496. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4497. && slimmb->mbxStatus) {
  4498. psli->sli_flag &=
  4499. ~LPFC_SLI_ACTIVE;
  4500. word0 = slimword0;
  4501. }
  4502. }
  4503. } else {
  4504. /* First copy command data */
  4505. word0 = readl(phba->MBslimaddr);
  4506. }
  4507. /* Read the HBA Host Attention Register */
  4508. ha_copy = readl(phba->HAregaddr);
  4509. }
  4510. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4511. /* copy results back to user */
  4512. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4513. } else {
  4514. /* First copy command data */
  4515. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4516. MAILBOX_CMD_SIZE);
  4517. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4518. pmbox->context2) {
  4519. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4520. phba->MBslimaddr + DMP_RSP_OFFSET,
  4521. mb->un.varDmp.word_cnt);
  4522. }
  4523. }
  4524. writel(HA_MBATT, phba->HAregaddr);
  4525. readl(phba->HAregaddr); /* flush */
  4526. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4527. status = mb->mbxStatus;
  4528. }
  4529. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4530. return status;
  4531. out_not_finished:
  4532. if (processing_queue) {
  4533. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4534. lpfc_mbox_cmpl_put(phba, pmbox);
  4535. }
  4536. return MBX_NOT_FINISHED;
  4537. }
  4538. /**
  4539. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4540. * @phba: Pointer to HBA context object.
  4541. *
  4542. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4543. * the driver internal pending mailbox queue. It will then try to wait out the
  4544. * possible outstanding mailbox command before return.
  4545. *
  4546. * Returns:
  4547. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4548. * the outstanding mailbox command timed out.
  4549. **/
  4550. static int
  4551. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4552. {
  4553. struct lpfc_sli *psli = &phba->sli;
  4554. uint8_t actcmd = MBX_HEARTBEAT;
  4555. int rc = 0;
  4556. unsigned long timeout;
  4557. /* Mark the asynchronous mailbox command posting as blocked */
  4558. spin_lock_irq(&phba->hbalock);
  4559. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4560. if (phba->sli.mbox_active)
  4561. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4562. spin_unlock_irq(&phba->hbalock);
  4563. /* Determine how long we might wait for the active mailbox
  4564. * command to be gracefully completed by firmware.
  4565. */
  4566. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4567. jiffies;
  4568. /* Wait for the outstnading mailbox command to complete */
  4569. while (phba->sli.mbox_active) {
  4570. /* Check active mailbox complete status every 2ms */
  4571. msleep(2);
  4572. if (time_after(jiffies, timeout)) {
  4573. /* Timeout, marked the outstanding cmd not complete */
  4574. rc = 1;
  4575. break;
  4576. }
  4577. }
  4578. /* Can not cleanly block async mailbox command, fails it */
  4579. if (rc) {
  4580. spin_lock_irq(&phba->hbalock);
  4581. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4582. spin_unlock_irq(&phba->hbalock);
  4583. }
  4584. return rc;
  4585. }
  4586. /**
  4587. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4588. * @phba: Pointer to HBA context object.
  4589. *
  4590. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4591. * commands from the driver internal pending mailbox queue. It makes sure
  4592. * that there is no outstanding mailbox command before resuming posting
  4593. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4594. * mailbox command, it will try to wait it out before resuming asynchronous
  4595. * mailbox command posting.
  4596. **/
  4597. static void
  4598. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4599. {
  4600. struct lpfc_sli *psli = &phba->sli;
  4601. spin_lock_irq(&phba->hbalock);
  4602. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4603. /* Asynchronous mailbox posting is not blocked, do nothing */
  4604. spin_unlock_irq(&phba->hbalock);
  4605. return;
  4606. }
  4607. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4608. * successful or timeout, after timing-out the outstanding mailbox
  4609. * command shall always be removed, so just unblock posting async
  4610. * mailbox command and resume
  4611. */
  4612. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4613. spin_unlock_irq(&phba->hbalock);
  4614. /* wake up worker thread to post asynchronlous mailbox command */
  4615. lpfc_worker_wake_up(phba);
  4616. }
  4617. /**
  4618. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4619. * @phba: Pointer to HBA context object.
  4620. * @mboxq: Pointer to mailbox object.
  4621. *
  4622. * The function posts a mailbox to the port. The mailbox is expected
  4623. * to be comletely filled in and ready for the port to operate on it.
  4624. * This routine executes a synchronous completion operation on the
  4625. * mailbox by polling for its completion.
  4626. *
  4627. * The caller must not be holding any locks when calling this routine.
  4628. *
  4629. * Returns:
  4630. * MBX_SUCCESS - mailbox posted successfully
  4631. * Any of the MBX error values.
  4632. **/
  4633. static int
  4634. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4635. {
  4636. int rc = MBX_SUCCESS;
  4637. unsigned long iflag;
  4638. uint32_t db_ready;
  4639. uint32_t mcqe_status;
  4640. uint32_t mbx_cmnd;
  4641. unsigned long timeout;
  4642. struct lpfc_sli *psli = &phba->sli;
  4643. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4644. struct lpfc_bmbx_create *mbox_rgn;
  4645. struct dma_address *dma_address;
  4646. struct lpfc_register bmbx_reg;
  4647. /*
  4648. * Only one mailbox can be active to the bootstrap mailbox region
  4649. * at a time and there is no queueing provided.
  4650. */
  4651. spin_lock_irqsave(&phba->hbalock, iflag);
  4652. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4653. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4654. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4655. "(%d):2532 Mailbox command x%x (x%x) "
  4656. "cannot issue Data: x%x x%x\n",
  4657. mboxq->vport ? mboxq->vport->vpi : 0,
  4658. mboxq->u.mb.mbxCommand,
  4659. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4660. psli->sli_flag, MBX_POLL);
  4661. return MBXERR_ERROR;
  4662. }
  4663. /* The server grabs the token and owns it until release */
  4664. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4665. phba->sli.mbox_active = mboxq;
  4666. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4667. /*
  4668. * Initialize the bootstrap memory region to avoid stale data areas
  4669. * in the mailbox post. Then copy the caller's mailbox contents to
  4670. * the bmbx mailbox region.
  4671. */
  4672. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4673. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4674. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4675. sizeof(struct lpfc_mqe));
  4676. /* Post the high mailbox dma address to the port and wait for ready. */
  4677. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4678. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4679. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4680. * 1000) + jiffies;
  4681. do {
  4682. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4683. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4684. if (!db_ready)
  4685. msleep(2);
  4686. if (time_after(jiffies, timeout)) {
  4687. rc = MBXERR_ERROR;
  4688. goto exit;
  4689. }
  4690. } while (!db_ready);
  4691. /* Post the low mailbox dma address to the port. */
  4692. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4693. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4694. * 1000) + jiffies;
  4695. do {
  4696. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4697. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4698. if (!db_ready)
  4699. msleep(2);
  4700. if (time_after(jiffies, timeout)) {
  4701. rc = MBXERR_ERROR;
  4702. goto exit;
  4703. }
  4704. } while (!db_ready);
  4705. /*
  4706. * Read the CQ to ensure the mailbox has completed.
  4707. * If so, update the mailbox status so that the upper layers
  4708. * can complete the request normally.
  4709. */
  4710. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4711. sizeof(struct lpfc_mqe));
  4712. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4713. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4714. sizeof(struct lpfc_mcqe));
  4715. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4716. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4717. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4718. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4719. rc = MBXERR_ERROR;
  4720. }
  4721. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4722. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4723. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4724. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4725. mboxq->vport ? mboxq->vport->vpi : 0,
  4726. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4727. bf_get(lpfc_mqe_status, mb),
  4728. mb->un.mb_words[0], mb->un.mb_words[1],
  4729. mb->un.mb_words[2], mb->un.mb_words[3],
  4730. mb->un.mb_words[4], mb->un.mb_words[5],
  4731. mb->un.mb_words[6], mb->un.mb_words[7],
  4732. mb->un.mb_words[8], mb->un.mb_words[9],
  4733. mb->un.mb_words[10], mb->un.mb_words[11],
  4734. mb->un.mb_words[12], mboxq->mcqe.word0,
  4735. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4736. mboxq->mcqe.trailer);
  4737. exit:
  4738. /* We are holding the token, no needed for lock when release */
  4739. spin_lock_irqsave(&phba->hbalock, iflag);
  4740. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4741. phba->sli.mbox_active = NULL;
  4742. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4743. return rc;
  4744. }
  4745. /**
  4746. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4747. * @phba: Pointer to HBA context object.
  4748. * @pmbox: Pointer to mailbox object.
  4749. * @flag: Flag indicating how the mailbox need to be processed.
  4750. *
  4751. * This function is called by discovery code and HBA management code to submit
  4752. * a mailbox command to firmware with SLI-4 interface spec.
  4753. *
  4754. * Return codes the caller owns the mailbox command after the return of the
  4755. * function.
  4756. **/
  4757. static int
  4758. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4759. uint32_t flag)
  4760. {
  4761. struct lpfc_sli *psli = &phba->sli;
  4762. unsigned long iflags;
  4763. int rc;
  4764. /* Detect polling mode and jump to a handler */
  4765. if (!phba->sli4_hba.intr_enable) {
  4766. if (flag == MBX_POLL)
  4767. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4768. else
  4769. rc = -EIO;
  4770. if (rc != MBX_SUCCESS)
  4771. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4772. "(%d):2541 Mailbox command x%x "
  4773. "(x%x) cannot issue Data: x%x x%x\n",
  4774. mboxq->vport ? mboxq->vport->vpi : 0,
  4775. mboxq->u.mb.mbxCommand,
  4776. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4777. psli->sli_flag, flag);
  4778. return rc;
  4779. } else if (flag == MBX_POLL) {
  4780. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4781. "(%d):2542 Try to issue mailbox command "
  4782. "x%x (x%x) synchronously ahead of async"
  4783. "mailbox command queue: x%x x%x\n",
  4784. mboxq->vport ? mboxq->vport->vpi : 0,
  4785. mboxq->u.mb.mbxCommand,
  4786. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4787. psli->sli_flag, flag);
  4788. /* Try to block the asynchronous mailbox posting */
  4789. rc = lpfc_sli4_async_mbox_block(phba);
  4790. if (!rc) {
  4791. /* Successfully blocked, now issue sync mbox cmd */
  4792. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4793. if (rc != MBX_SUCCESS)
  4794. lpfc_printf_log(phba, KERN_ERR,
  4795. LOG_MBOX | LOG_SLI,
  4796. "(%d):2597 Mailbox command "
  4797. "x%x (x%x) cannot issue "
  4798. "Data: x%x x%x\n",
  4799. mboxq->vport ?
  4800. mboxq->vport->vpi : 0,
  4801. mboxq->u.mb.mbxCommand,
  4802. lpfc_sli4_mbox_opcode_get(phba,
  4803. mboxq),
  4804. psli->sli_flag, flag);
  4805. /* Unblock the async mailbox posting afterward */
  4806. lpfc_sli4_async_mbox_unblock(phba);
  4807. }
  4808. return rc;
  4809. }
  4810. /* Now, interrupt mode asynchrous mailbox command */
  4811. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4812. if (rc) {
  4813. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4814. "(%d):2543 Mailbox command x%x (x%x) "
  4815. "cannot issue Data: x%x x%x\n",
  4816. mboxq->vport ? mboxq->vport->vpi : 0,
  4817. mboxq->u.mb.mbxCommand,
  4818. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4819. psli->sli_flag, flag);
  4820. goto out_not_finished;
  4821. }
  4822. rc = lpfc_mbox_dev_check(phba);
  4823. if (unlikely(rc)) {
  4824. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4825. "(%d):2544 Mailbox command x%x (x%x) "
  4826. "cannot issue Data: x%x x%x\n",
  4827. mboxq->vport ? mboxq->vport->vpi : 0,
  4828. mboxq->u.mb.mbxCommand,
  4829. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4830. psli->sli_flag, flag);
  4831. goto out_not_finished;
  4832. }
  4833. /* Put the mailbox command to the driver internal FIFO */
  4834. psli->slistat.mbox_busy++;
  4835. spin_lock_irqsave(&phba->hbalock, iflags);
  4836. lpfc_mbox_put(phba, mboxq);
  4837. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4838. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4839. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4840. "x%x (x%x) x%x x%x x%x\n",
  4841. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4842. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4843. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4844. phba->pport->port_state,
  4845. psli->sli_flag, MBX_NOWAIT);
  4846. /* Wake up worker thread to transport mailbox command from head */
  4847. lpfc_worker_wake_up(phba);
  4848. return MBX_BUSY;
  4849. out_not_finished:
  4850. return MBX_NOT_FINISHED;
  4851. }
  4852. /**
  4853. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4854. * @phba: Pointer to HBA context object.
  4855. *
  4856. * This function is called by worker thread to send a mailbox command to
  4857. * SLI4 HBA firmware.
  4858. *
  4859. **/
  4860. int
  4861. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4862. {
  4863. struct lpfc_sli *psli = &phba->sli;
  4864. LPFC_MBOXQ_t *mboxq;
  4865. int rc = MBX_SUCCESS;
  4866. unsigned long iflags;
  4867. struct lpfc_mqe *mqe;
  4868. uint32_t mbx_cmnd;
  4869. /* Check interrupt mode before post async mailbox command */
  4870. if (unlikely(!phba->sli4_hba.intr_enable))
  4871. return MBX_NOT_FINISHED;
  4872. /* Check for mailbox command service token */
  4873. spin_lock_irqsave(&phba->hbalock, iflags);
  4874. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4875. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4876. return MBX_NOT_FINISHED;
  4877. }
  4878. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4879. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4880. return MBX_NOT_FINISHED;
  4881. }
  4882. if (unlikely(phba->sli.mbox_active)) {
  4883. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4884. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4885. "0384 There is pending active mailbox cmd\n");
  4886. return MBX_NOT_FINISHED;
  4887. }
  4888. /* Take the mailbox command service token */
  4889. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4890. /* Get the next mailbox command from head of queue */
  4891. mboxq = lpfc_mbox_get(phba);
  4892. /* If no more mailbox command waiting for post, we're done */
  4893. if (!mboxq) {
  4894. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4895. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4896. return MBX_SUCCESS;
  4897. }
  4898. phba->sli.mbox_active = mboxq;
  4899. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4900. /* Check device readiness for posting mailbox command */
  4901. rc = lpfc_mbox_dev_check(phba);
  4902. if (unlikely(rc))
  4903. /* Driver clean routine will clean up pending mailbox */
  4904. goto out_not_finished;
  4905. /* Prepare the mbox command to be posted */
  4906. mqe = &mboxq->u.mqe;
  4907. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4908. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4909. mod_timer(&psli->mbox_tmo, (jiffies +
  4910. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4911. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4912. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4913. "x%x x%x\n",
  4914. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4915. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4916. phba->pport->port_state, psli->sli_flag);
  4917. if (mbx_cmnd != MBX_HEARTBEAT) {
  4918. if (mboxq->vport) {
  4919. lpfc_debugfs_disc_trc(mboxq->vport,
  4920. LPFC_DISC_TRC_MBOX_VPORT,
  4921. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4922. mbx_cmnd, mqe->un.mb_words[0],
  4923. mqe->un.mb_words[1]);
  4924. } else {
  4925. lpfc_debugfs_disc_trc(phba->pport,
  4926. LPFC_DISC_TRC_MBOX,
  4927. "MBOX Send: cmd:x%x mb:x%x x%x",
  4928. mbx_cmnd, mqe->un.mb_words[0],
  4929. mqe->un.mb_words[1]);
  4930. }
  4931. }
  4932. psli->slistat.mbox_cmd++;
  4933. /* Post the mailbox command to the port */
  4934. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4935. if (rc != MBX_SUCCESS) {
  4936. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4937. "(%d):2533 Mailbox command x%x (x%x) "
  4938. "cannot issue Data: x%x x%x\n",
  4939. mboxq->vport ? mboxq->vport->vpi : 0,
  4940. mboxq->u.mb.mbxCommand,
  4941. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4942. psli->sli_flag, MBX_NOWAIT);
  4943. goto out_not_finished;
  4944. }
  4945. return rc;
  4946. out_not_finished:
  4947. spin_lock_irqsave(&phba->hbalock, iflags);
  4948. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4949. __lpfc_mbox_cmpl_put(phba, mboxq);
  4950. /* Release the token */
  4951. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4952. phba->sli.mbox_active = NULL;
  4953. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4954. return MBX_NOT_FINISHED;
  4955. }
  4956. /**
  4957. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4958. * @phba: Pointer to HBA context object.
  4959. * @pmbox: Pointer to mailbox object.
  4960. * @flag: Flag indicating how the mailbox need to be processed.
  4961. *
  4962. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4963. * the API jump table function pointer from the lpfc_hba struct.
  4964. *
  4965. * Return codes the caller owns the mailbox command after the return of the
  4966. * function.
  4967. **/
  4968. int
  4969. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4970. {
  4971. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4972. }
  4973. /**
  4974. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4975. * @phba: The hba struct for which this call is being executed.
  4976. * @dev_grp: The HBA PCI-Device group number.
  4977. *
  4978. * This routine sets up the mbox interface API function jump table in @phba
  4979. * struct.
  4980. * Returns: 0 - success, -ENODEV - failure.
  4981. **/
  4982. int
  4983. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4984. {
  4985. switch (dev_grp) {
  4986. case LPFC_PCI_DEV_LP:
  4987. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4988. phba->lpfc_sli_handle_slow_ring_event =
  4989. lpfc_sli_handle_slow_ring_event_s3;
  4990. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4991. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4992. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4993. break;
  4994. case LPFC_PCI_DEV_OC:
  4995. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4996. phba->lpfc_sli_handle_slow_ring_event =
  4997. lpfc_sli_handle_slow_ring_event_s4;
  4998. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4999. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5000. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5001. break;
  5002. default:
  5003. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5004. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5005. dev_grp);
  5006. return -ENODEV;
  5007. break;
  5008. }
  5009. return 0;
  5010. }
  5011. /**
  5012. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5013. * @phba: Pointer to HBA context object.
  5014. * @pring: Pointer to driver SLI ring object.
  5015. * @piocb: Pointer to address of newly added command iocb.
  5016. *
  5017. * This function is called with hbalock held to add a command
  5018. * iocb to the txq when SLI layer cannot submit the command iocb
  5019. * to the ring.
  5020. **/
  5021. static void
  5022. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5023. struct lpfc_iocbq *piocb)
  5024. {
  5025. /* Insert the caller's iocb in the txq tail for later processing. */
  5026. list_add_tail(&piocb->list, &pring->txq);
  5027. pring->txq_cnt++;
  5028. }
  5029. /**
  5030. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5031. * @phba: Pointer to HBA context object.
  5032. * @pring: Pointer to driver SLI ring object.
  5033. * @piocb: Pointer to address of newly added command iocb.
  5034. *
  5035. * This function is called with hbalock held before a new
  5036. * iocb is submitted to the firmware. This function checks
  5037. * txq to flush the iocbs in txq to Firmware before
  5038. * submitting new iocbs to the Firmware.
  5039. * If there are iocbs in the txq which need to be submitted
  5040. * to firmware, lpfc_sli_next_iocb returns the first element
  5041. * of the txq after dequeuing it from txq.
  5042. * If there is no iocb in the txq then the function will return
  5043. * *piocb and *piocb is set to NULL. Caller needs to check
  5044. * *piocb to find if there are more commands in the txq.
  5045. **/
  5046. static struct lpfc_iocbq *
  5047. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5048. struct lpfc_iocbq **piocb)
  5049. {
  5050. struct lpfc_iocbq * nextiocb;
  5051. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5052. if (!nextiocb) {
  5053. nextiocb = *piocb;
  5054. *piocb = NULL;
  5055. }
  5056. return nextiocb;
  5057. }
  5058. /**
  5059. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5060. * @phba: Pointer to HBA context object.
  5061. * @ring_number: SLI ring number to issue iocb on.
  5062. * @piocb: Pointer to command iocb.
  5063. * @flag: Flag indicating if this command can be put into txq.
  5064. *
  5065. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5066. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5067. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5068. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5069. * this function allows only iocbs for posting buffers. This function finds
  5070. * next available slot in the command ring and posts the command to the
  5071. * available slot and writes the port attention register to request HBA start
  5072. * processing new iocb. If there is no slot available in the ring and
  5073. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5074. * the function returns IOCB_BUSY.
  5075. *
  5076. * This function is called with hbalock held. The function will return success
  5077. * after it successfully submit the iocb to firmware or after adding to the
  5078. * txq.
  5079. **/
  5080. static int
  5081. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5082. struct lpfc_iocbq *piocb, uint32_t flag)
  5083. {
  5084. struct lpfc_iocbq *nextiocb;
  5085. IOCB_t *iocb;
  5086. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5087. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5088. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5089. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5090. lpfc_printf_log(phba, KERN_ERR,
  5091. LOG_SLI | LOG_VPORT,
  5092. "1807 IOCB x%x failed. No vport\n",
  5093. piocb->iocb.ulpCommand);
  5094. dump_stack();
  5095. return IOCB_ERROR;
  5096. }
  5097. /* If the PCI channel is in offline state, do not post iocbs. */
  5098. if (unlikely(pci_channel_offline(phba->pcidev)))
  5099. return IOCB_ERROR;
  5100. /* If HBA has a deferred error attention, fail the iocb. */
  5101. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5102. return IOCB_ERROR;
  5103. /*
  5104. * We should never get an IOCB if we are in a < LINK_DOWN state
  5105. */
  5106. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5107. return IOCB_ERROR;
  5108. /*
  5109. * Check to see if we are blocking IOCB processing because of a
  5110. * outstanding event.
  5111. */
  5112. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5113. goto iocb_busy;
  5114. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5115. /*
  5116. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5117. * can be issued if the link is not up.
  5118. */
  5119. switch (piocb->iocb.ulpCommand) {
  5120. case CMD_GEN_REQUEST64_CR:
  5121. case CMD_GEN_REQUEST64_CX:
  5122. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5123. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5124. FC_FCP_CMND) ||
  5125. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5126. MENLO_TRANSPORT_TYPE))
  5127. goto iocb_busy;
  5128. break;
  5129. case CMD_QUE_RING_BUF_CN:
  5130. case CMD_QUE_RING_BUF64_CN:
  5131. /*
  5132. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5133. * completion, iocb_cmpl MUST be 0.
  5134. */
  5135. if (piocb->iocb_cmpl)
  5136. piocb->iocb_cmpl = NULL;
  5137. /*FALLTHROUGH*/
  5138. case CMD_CREATE_XRI_CR:
  5139. case CMD_CLOSE_XRI_CN:
  5140. case CMD_CLOSE_XRI_CX:
  5141. break;
  5142. default:
  5143. goto iocb_busy;
  5144. }
  5145. /*
  5146. * For FCP commands, we must be in a state where we can process link
  5147. * attention events.
  5148. */
  5149. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5150. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5151. goto iocb_busy;
  5152. }
  5153. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5154. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5155. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5156. if (iocb)
  5157. lpfc_sli_update_ring(phba, pring);
  5158. else
  5159. lpfc_sli_update_full_ring(phba, pring);
  5160. if (!piocb)
  5161. return IOCB_SUCCESS;
  5162. goto out_busy;
  5163. iocb_busy:
  5164. pring->stats.iocb_cmd_delay++;
  5165. out_busy:
  5166. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5167. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5168. return IOCB_SUCCESS;
  5169. }
  5170. return IOCB_BUSY;
  5171. }
  5172. /**
  5173. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5174. * @phba: Pointer to HBA context object.
  5175. * @piocb: Pointer to command iocb.
  5176. * @sglq: Pointer to the scatter gather queue object.
  5177. *
  5178. * This routine converts the bpl or bde that is in the IOCB
  5179. * to a sgl list for the sli4 hardware. The physical address
  5180. * of the bpl/bde is converted back to a virtual address.
  5181. * If the IOCB contains a BPL then the list of BDE's is
  5182. * converted to sli4_sge's. If the IOCB contains a single
  5183. * BDE then it is converted to a single sli_sge.
  5184. * The IOCB is still in cpu endianess so the contents of
  5185. * the bpl can be used without byte swapping.
  5186. *
  5187. * Returns valid XRI = Success, NO_XRI = Failure.
  5188. **/
  5189. static uint16_t
  5190. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5191. struct lpfc_sglq *sglq)
  5192. {
  5193. uint16_t xritag = NO_XRI;
  5194. struct ulp_bde64 *bpl = NULL;
  5195. struct ulp_bde64 bde;
  5196. struct sli4_sge *sgl = NULL;
  5197. IOCB_t *icmd;
  5198. int numBdes = 0;
  5199. int i = 0;
  5200. if (!piocbq || !sglq)
  5201. return xritag;
  5202. sgl = (struct sli4_sge *)sglq->sgl;
  5203. icmd = &piocbq->iocb;
  5204. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5205. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5206. sizeof(struct ulp_bde64);
  5207. /* The addrHigh and addrLow fields within the IOCB
  5208. * have not been byteswapped yet so there is no
  5209. * need to swap them back.
  5210. */
  5211. bpl = (struct ulp_bde64 *)
  5212. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5213. if (!bpl)
  5214. return xritag;
  5215. for (i = 0; i < numBdes; i++) {
  5216. /* Should already be byte swapped. */
  5217. sgl->addr_hi = bpl->addrHigh;
  5218. sgl->addr_lo = bpl->addrLow;
  5219. /* swap the size field back to the cpu so we
  5220. * can assign it to the sgl.
  5221. */
  5222. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5223. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5224. if ((i+1) == numBdes)
  5225. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5226. else
  5227. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5228. sgl->word2 = cpu_to_le32(sgl->word2);
  5229. sgl->word3 = cpu_to_le32(sgl->word3);
  5230. bpl++;
  5231. sgl++;
  5232. }
  5233. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5234. /* The addrHigh and addrLow fields of the BDE have not
  5235. * been byteswapped yet so they need to be swapped
  5236. * before putting them in the sgl.
  5237. */
  5238. sgl->addr_hi =
  5239. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5240. sgl->addr_lo =
  5241. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5242. bf_set(lpfc_sli4_sge_len, sgl,
  5243. icmd->un.genreq64.bdl.bdeSize);
  5244. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5245. sgl->word2 = cpu_to_le32(sgl->word2);
  5246. sgl->word3 = cpu_to_le32(sgl->word3);
  5247. }
  5248. return sglq->sli4_xritag;
  5249. }
  5250. /**
  5251. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5252. * @phba: Pointer to HBA context object.
  5253. * @piocb: Pointer to command iocb.
  5254. *
  5255. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5256. * distribution.
  5257. *
  5258. * Return: index into SLI4 fast-path FCP queue index.
  5259. **/
  5260. static uint32_t
  5261. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  5262. {
  5263. static uint32_t fcp_qidx;
  5264. return fcp_qidx++ % phba->cfg_fcp_wq_count;
  5265. }
  5266. /**
  5267. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5268. * @phba: Pointer to HBA context object.
  5269. * @piocb: Pointer to command iocb.
  5270. * @wqe: Pointer to the work queue entry.
  5271. *
  5272. * This routine converts the iocb command to its Work Queue Entry
  5273. * equivalent. The wqe pointer should not have any fields set when
  5274. * this routine is called because it will memcpy over them.
  5275. * This routine does not set the CQ_ID or the WQEC bits in the
  5276. * wqe.
  5277. *
  5278. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5279. **/
  5280. static int
  5281. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5282. union lpfc_wqe *wqe)
  5283. {
  5284. uint32_t payload_len = 0;
  5285. uint8_t ct = 0;
  5286. uint32_t fip;
  5287. uint32_t abort_tag;
  5288. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5289. uint8_t cmnd;
  5290. uint16_t xritag;
  5291. struct ulp_bde64 *bpl = NULL;
  5292. fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
  5293. /* The fcp commands will set command type */
  5294. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5295. command_type = FCP_COMMAND;
  5296. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
  5297. command_type = ELS_COMMAND_FIP;
  5298. else
  5299. command_type = ELS_COMMAND_NON_FIP;
  5300. /* Some of the fields are in the right position already */
  5301. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5302. abort_tag = (uint32_t) iocbq->iotag;
  5303. xritag = iocbq->sli4_xritag;
  5304. wqe->words[7] = 0; /* The ct field has moved so reset */
  5305. /* words0-2 bpl convert bde */
  5306. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5307. bpl = (struct ulp_bde64 *)
  5308. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5309. if (!bpl)
  5310. return IOCB_ERROR;
  5311. /* Should already be byte swapped. */
  5312. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5313. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5314. /* swap the size field back to the cpu so we
  5315. * can assign it to the sgl.
  5316. */
  5317. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5318. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5319. } else
  5320. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5321. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5322. cmnd = iocbq->iocb.ulpCommand;
  5323. switch (iocbq->iocb.ulpCommand) {
  5324. case CMD_ELS_REQUEST64_CR:
  5325. if (!iocbq->iocb.ulpLe) {
  5326. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5327. "2007 Only Limited Edition cmd Format"
  5328. " supported 0x%x\n",
  5329. iocbq->iocb.ulpCommand);
  5330. return IOCB_ERROR;
  5331. }
  5332. wqe->els_req.payload_len = payload_len;
  5333. /* Els_reguest64 has a TMO */
  5334. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5335. iocbq->iocb.ulpTimeout);
  5336. /* Need a VF for word 4 set the vf bit*/
  5337. bf_set(els_req64_vf, &wqe->els_req, 0);
  5338. /* And a VFID for word 12 */
  5339. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5340. /*
  5341. * Set ct field to 3, indicates that the context_tag field
  5342. * contains the FCFI and remote N_Port_ID is
  5343. * in word 5.
  5344. */
  5345. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5346. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5347. iocbq->iocb.ulpContext);
  5348. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5349. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5350. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5351. break;
  5352. case CMD_XMIT_SEQUENCE64_CR:
  5353. /* word3 iocb=io_tag32 wqe=payload_offset */
  5354. /* payload offset used for multilpe outstanding
  5355. * sequences on the same exchange
  5356. */
  5357. wqe->words[3] = 0;
  5358. /* word4 relative_offset memcpy */
  5359. /* word5 r_ctl/df_ctl memcpy */
  5360. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5361. wqe->xmit_sequence.xmit_len = payload_len;
  5362. break;
  5363. case CMD_XMIT_BCAST64_CN:
  5364. /* word3 iocb=iotag32 wqe=payload_len */
  5365. wqe->words[3] = 0; /* no definition for this in wqe */
  5366. /* word4 iocb=rsvd wqe=rsvd */
  5367. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5368. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5369. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5370. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5371. break;
  5372. case CMD_FCP_IWRITE64_CR:
  5373. command_type = FCP_COMMAND_DATA_OUT;
  5374. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5375. * confusing.
  5376. * word3 is payload_len: byte offset to the sgl entry for the
  5377. * fcp_command.
  5378. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5379. * word5 is initial xfer len 0 = wait for xfer-ready
  5380. */
  5381. /* Always wait for xfer-ready before sending data */
  5382. wqe->fcp_iwrite.initial_xfer_len = 0;
  5383. /* word 4 (xfer length) should have been set on the memcpy */
  5384. /* allow write to fall through to read */
  5385. case CMD_FCP_IREAD64_CR:
  5386. /* FCP_CMD is always the 1st sgl entry */
  5387. wqe->fcp_iread.payload_len =
  5388. payload_len + sizeof(struct fcp_rsp);
  5389. /* word 4 (xfer length) should have been set on the memcpy */
  5390. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5391. iocbq->iocb.ulpFCP2Rcvy);
  5392. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5393. /* The XC bit and the XS bit are similar. The driver never
  5394. * tracked whether or not the exchange was previouslly open.
  5395. * XC = Exchange create, 0 is create. 1 is already open.
  5396. * XS = link cmd: 1 do not close the exchange after command.
  5397. * XS = 0 close exchange when command completes.
  5398. * The only time we would not set the XC bit is when the XS bit
  5399. * is set and we are sending our 2nd or greater command on
  5400. * this exchange.
  5401. */
  5402. /* Always open the exchange */
  5403. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5404. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5405. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5406. break;
  5407. case CMD_FCP_ICMND64_CR:
  5408. /* Always open the exchange */
  5409. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5410. wqe->words[4] = 0;
  5411. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5412. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5413. break;
  5414. case CMD_GEN_REQUEST64_CR:
  5415. /* word3 command length is described as byte offset to the
  5416. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5417. * sgl[0] = cmnd
  5418. * sgl[1] = rsp.
  5419. *
  5420. */
  5421. wqe->gen_req.command_len = payload_len;
  5422. /* Word4 parameter copied in the memcpy */
  5423. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5424. /* word6 context tag copied in memcpy */
  5425. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5426. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5427. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5428. "2015 Invalid CT %x command 0x%x\n",
  5429. ct, iocbq->iocb.ulpCommand);
  5430. return IOCB_ERROR;
  5431. }
  5432. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5433. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5434. iocbq->iocb.ulpTimeout);
  5435. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5436. command_type = OTHER_COMMAND;
  5437. break;
  5438. case CMD_XMIT_ELS_RSP64_CX:
  5439. /* words0-2 BDE memcpy */
  5440. /* word3 iocb=iotag32 wqe=rsvd */
  5441. wqe->words[3] = 0;
  5442. /* word4 iocb=did wge=rsvd. */
  5443. wqe->words[4] = 0;
  5444. /* word5 iocb=rsvd wge=did */
  5445. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5446. iocbq->iocb.un.elsreq64.remoteID);
  5447. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5448. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5449. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5450. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5451. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5452. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5453. iocbq->vport->vpi + phba->vpi_base);
  5454. command_type = OTHER_COMMAND;
  5455. break;
  5456. case CMD_CLOSE_XRI_CN:
  5457. case CMD_ABORT_XRI_CN:
  5458. case CMD_ABORT_XRI_CX:
  5459. /* words 0-2 memcpy should be 0 rserved */
  5460. /* port will send abts */
  5461. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5462. /*
  5463. * The link is down so the fw does not need to send abts
  5464. * on the wire.
  5465. */
  5466. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5467. else
  5468. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5469. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5470. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5471. wqe->words[5] = 0;
  5472. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5473. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5474. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5475. wqe->generic.abort_tag = abort_tag;
  5476. /*
  5477. * The abort handler will send us CMD_ABORT_XRI_CN or
  5478. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5479. */
  5480. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5481. cmnd = CMD_ABORT_XRI_CX;
  5482. command_type = OTHER_COMMAND;
  5483. xritag = 0;
  5484. break;
  5485. case CMD_XRI_ABORTED_CX:
  5486. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5487. /* words0-2 are all 0's no bde */
  5488. /* word3 and word4 are rsvrd */
  5489. wqe->words[3] = 0;
  5490. wqe->words[4] = 0;
  5491. /* word5 iocb=rsvd wge=did */
  5492. /* There is no remote port id in the IOCB? */
  5493. /* Let this fall through and fail */
  5494. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5495. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5496. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5497. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5498. default:
  5499. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5500. "2014 Invalid command 0x%x\n",
  5501. iocbq->iocb.ulpCommand);
  5502. return IOCB_ERROR;
  5503. break;
  5504. }
  5505. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5506. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5507. wqe->generic.abort_tag = abort_tag;
  5508. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5509. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5510. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5511. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5512. return 0;
  5513. }
  5514. /**
  5515. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5516. * @phba: Pointer to HBA context object.
  5517. * @ring_number: SLI ring number to issue iocb on.
  5518. * @piocb: Pointer to command iocb.
  5519. * @flag: Flag indicating if this command can be put into txq.
  5520. *
  5521. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5522. * an iocb command to an HBA with SLI-4 interface spec.
  5523. *
  5524. * This function is called with hbalock held. The function will return success
  5525. * after it successfully submit the iocb to firmware or after adding to the
  5526. * txq.
  5527. **/
  5528. static int
  5529. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5530. struct lpfc_iocbq *piocb, uint32_t flag)
  5531. {
  5532. struct lpfc_sglq *sglq;
  5533. uint16_t xritag;
  5534. union lpfc_wqe wqe;
  5535. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5536. uint32_t fcp_wqidx;
  5537. if (piocb->sli4_xritag == NO_XRI) {
  5538. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5539. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5540. sglq = NULL;
  5541. else {
  5542. sglq = __lpfc_sli_get_sglq(phba);
  5543. if (!sglq)
  5544. return IOCB_ERROR;
  5545. piocb->sli4_xritag = sglq->sli4_xritag;
  5546. }
  5547. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5548. sglq = NULL; /* These IO's already have an XRI and
  5549. * a mapped sgl.
  5550. */
  5551. } else {
  5552. /* This is a continuation of a commandi,(CX) so this
  5553. * sglq is on the active list
  5554. */
  5555. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5556. if (!sglq)
  5557. return IOCB_ERROR;
  5558. }
  5559. if (sglq) {
  5560. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5561. if (xritag != sglq->sli4_xritag)
  5562. return IOCB_ERROR;
  5563. }
  5564. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5565. return IOCB_ERROR;
  5566. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5567. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba, piocb);
  5568. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5569. return IOCB_ERROR;
  5570. } else {
  5571. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5572. return IOCB_ERROR;
  5573. }
  5574. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5575. return 0;
  5576. }
  5577. /**
  5578. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5579. *
  5580. * This routine wraps the actual lockless version for issusing IOCB function
  5581. * pointer from the lpfc_hba struct.
  5582. *
  5583. * Return codes:
  5584. * IOCB_ERROR - Error
  5585. * IOCB_SUCCESS - Success
  5586. * IOCB_BUSY - Busy
  5587. **/
  5588. static inline int
  5589. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5590. struct lpfc_iocbq *piocb, uint32_t flag)
  5591. {
  5592. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5593. }
  5594. /**
  5595. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5596. * @phba: The hba struct for which this call is being executed.
  5597. * @dev_grp: The HBA PCI-Device group number.
  5598. *
  5599. * This routine sets up the SLI interface API function jump table in @phba
  5600. * struct.
  5601. * Returns: 0 - success, -ENODEV - failure.
  5602. **/
  5603. int
  5604. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5605. {
  5606. switch (dev_grp) {
  5607. case LPFC_PCI_DEV_LP:
  5608. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5609. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5610. break;
  5611. case LPFC_PCI_DEV_OC:
  5612. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5613. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5614. break;
  5615. default:
  5616. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5617. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5618. dev_grp);
  5619. return -ENODEV;
  5620. break;
  5621. }
  5622. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5623. return 0;
  5624. }
  5625. /**
  5626. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5627. * @phba: Pointer to HBA context object.
  5628. * @pring: Pointer to driver SLI ring object.
  5629. * @piocb: Pointer to command iocb.
  5630. * @flag: Flag indicating if this command can be put into txq.
  5631. *
  5632. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5633. * function. This function gets the hbalock and calls
  5634. * __lpfc_sli_issue_iocb function and will return the error returned
  5635. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5636. * functions which do not hold hbalock.
  5637. **/
  5638. int
  5639. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5640. struct lpfc_iocbq *piocb, uint32_t flag)
  5641. {
  5642. unsigned long iflags;
  5643. int rc;
  5644. spin_lock_irqsave(&phba->hbalock, iflags);
  5645. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5647. return rc;
  5648. }
  5649. /**
  5650. * lpfc_extra_ring_setup - Extra ring setup function
  5651. * @phba: Pointer to HBA context object.
  5652. *
  5653. * This function is called while driver attaches with the
  5654. * HBA to setup the extra ring. The extra ring is used
  5655. * only when driver needs to support target mode functionality
  5656. * or IP over FC functionalities.
  5657. *
  5658. * This function is called with no lock held.
  5659. **/
  5660. static int
  5661. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5662. {
  5663. struct lpfc_sli *psli;
  5664. struct lpfc_sli_ring *pring;
  5665. psli = &phba->sli;
  5666. /* Adjust cmd/rsp ring iocb entries more evenly */
  5667. /* Take some away from the FCP ring */
  5668. pring = &psli->ring[psli->fcp_ring];
  5669. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5670. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5671. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5672. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5673. /* and give them to the extra ring */
  5674. pring = &psli->ring[psli->extra_ring];
  5675. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5676. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5677. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5678. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5679. /* Setup default profile for this ring */
  5680. pring->iotag_max = 4096;
  5681. pring->num_mask = 1;
  5682. pring->prt[0].profile = 0; /* Mask 0 */
  5683. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5684. pring->prt[0].type = phba->cfg_multi_ring_type;
  5685. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5686. return 0;
  5687. }
  5688. /**
  5689. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5690. * @phba: Pointer to HBA context object.
  5691. * @pring: Pointer to driver SLI ring object.
  5692. * @iocbq: Pointer to iocb object.
  5693. *
  5694. * This function is called by the slow ring event handler
  5695. * function when there is an ASYNC event iocb in the ring.
  5696. * This function is called with no lock held.
  5697. * Currently this function handles only temperature related
  5698. * ASYNC events. The function decodes the temperature sensor
  5699. * event message and posts events for the management applications.
  5700. **/
  5701. static void
  5702. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5703. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5704. {
  5705. IOCB_t *icmd;
  5706. uint16_t evt_code;
  5707. uint16_t temp;
  5708. struct temp_event temp_event_data;
  5709. struct Scsi_Host *shost;
  5710. uint32_t *iocb_w;
  5711. icmd = &iocbq->iocb;
  5712. evt_code = icmd->un.asyncstat.evt_code;
  5713. temp = icmd->ulpContext;
  5714. if ((evt_code != ASYNC_TEMP_WARN) &&
  5715. (evt_code != ASYNC_TEMP_SAFE)) {
  5716. iocb_w = (uint32_t *) icmd;
  5717. lpfc_printf_log(phba,
  5718. KERN_ERR,
  5719. LOG_SLI,
  5720. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5721. " evt_code 0x%x \n"
  5722. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5723. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5724. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5725. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5726. pring->ringno,
  5727. icmd->un.asyncstat.evt_code,
  5728. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5729. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5730. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5731. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5732. return;
  5733. }
  5734. temp_event_data.data = (uint32_t)temp;
  5735. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5736. if (evt_code == ASYNC_TEMP_WARN) {
  5737. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5738. lpfc_printf_log(phba,
  5739. KERN_ERR,
  5740. LOG_TEMP,
  5741. "0347 Adapter is very hot, please take "
  5742. "corrective action. temperature : %d Celsius\n",
  5743. temp);
  5744. }
  5745. if (evt_code == ASYNC_TEMP_SAFE) {
  5746. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5747. lpfc_printf_log(phba,
  5748. KERN_ERR,
  5749. LOG_TEMP,
  5750. "0340 Adapter temperature is OK now. "
  5751. "temperature : %d Celsius\n",
  5752. temp);
  5753. }
  5754. /* Send temperature change event to applications */
  5755. shost = lpfc_shost_from_vport(phba->pport);
  5756. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5757. sizeof(temp_event_data), (char *) &temp_event_data,
  5758. LPFC_NL_VENDOR_ID);
  5759. }
  5760. /**
  5761. * lpfc_sli_setup - SLI ring setup function
  5762. * @phba: Pointer to HBA context object.
  5763. *
  5764. * lpfc_sli_setup sets up rings of the SLI interface with
  5765. * number of iocbs per ring and iotags. This function is
  5766. * called while driver attach to the HBA and before the
  5767. * interrupts are enabled. So there is no need for locking.
  5768. *
  5769. * This function always returns 0.
  5770. **/
  5771. int
  5772. lpfc_sli_setup(struct lpfc_hba *phba)
  5773. {
  5774. int i, totiocbsize = 0;
  5775. struct lpfc_sli *psli = &phba->sli;
  5776. struct lpfc_sli_ring *pring;
  5777. psli->num_rings = MAX_CONFIGURED_RINGS;
  5778. psli->sli_flag = 0;
  5779. psli->fcp_ring = LPFC_FCP_RING;
  5780. psli->next_ring = LPFC_FCP_NEXT_RING;
  5781. psli->extra_ring = LPFC_EXTRA_RING;
  5782. psli->iocbq_lookup = NULL;
  5783. psli->iocbq_lookup_len = 0;
  5784. psli->last_iotag = 0;
  5785. for (i = 0; i < psli->num_rings; i++) {
  5786. pring = &psli->ring[i];
  5787. switch (i) {
  5788. case LPFC_FCP_RING: /* ring 0 - FCP */
  5789. /* numCiocb and numRiocb are used in config_port */
  5790. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5791. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5792. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5793. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5794. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5795. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5796. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5797. SLI3_IOCB_CMD_SIZE :
  5798. SLI2_IOCB_CMD_SIZE;
  5799. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5800. SLI3_IOCB_RSP_SIZE :
  5801. SLI2_IOCB_RSP_SIZE;
  5802. pring->iotag_ctr = 0;
  5803. pring->iotag_max =
  5804. (phba->cfg_hba_queue_depth * 2);
  5805. pring->fast_iotag = pring->iotag_max;
  5806. pring->num_mask = 0;
  5807. break;
  5808. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5809. /* numCiocb and numRiocb are used in config_port */
  5810. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5811. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5812. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5813. SLI3_IOCB_CMD_SIZE :
  5814. SLI2_IOCB_CMD_SIZE;
  5815. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5816. SLI3_IOCB_RSP_SIZE :
  5817. SLI2_IOCB_RSP_SIZE;
  5818. pring->iotag_max = phba->cfg_hba_queue_depth;
  5819. pring->num_mask = 0;
  5820. break;
  5821. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5822. /* numCiocb and numRiocb are used in config_port */
  5823. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5824. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5825. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5826. SLI3_IOCB_CMD_SIZE :
  5827. SLI2_IOCB_CMD_SIZE;
  5828. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5829. SLI3_IOCB_RSP_SIZE :
  5830. SLI2_IOCB_RSP_SIZE;
  5831. pring->fast_iotag = 0;
  5832. pring->iotag_ctr = 0;
  5833. pring->iotag_max = 4096;
  5834. pring->lpfc_sli_rcv_async_status =
  5835. lpfc_sli_async_event_handler;
  5836. pring->num_mask = 4;
  5837. pring->prt[0].profile = 0; /* Mask 0 */
  5838. pring->prt[0].rctl = FC_ELS_REQ;
  5839. pring->prt[0].type = FC_ELS_DATA;
  5840. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5841. lpfc_els_unsol_event;
  5842. pring->prt[1].profile = 0; /* Mask 1 */
  5843. pring->prt[1].rctl = FC_ELS_RSP;
  5844. pring->prt[1].type = FC_ELS_DATA;
  5845. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5846. lpfc_els_unsol_event;
  5847. pring->prt[2].profile = 0; /* Mask 2 */
  5848. /* NameServer Inquiry */
  5849. pring->prt[2].rctl = FC_UNSOL_CTL;
  5850. /* NameServer */
  5851. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  5852. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5853. lpfc_ct_unsol_event;
  5854. pring->prt[3].profile = 0; /* Mask 3 */
  5855. /* NameServer response */
  5856. pring->prt[3].rctl = FC_SOL_CTL;
  5857. /* NameServer */
  5858. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  5859. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5860. lpfc_ct_unsol_event;
  5861. break;
  5862. }
  5863. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5864. (pring->numRiocb * pring->sizeRiocb);
  5865. }
  5866. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5867. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5868. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5869. "SLI2 SLIM Data: x%x x%lx\n",
  5870. phba->brd_no, totiocbsize,
  5871. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5872. }
  5873. if (phba->cfg_multi_ring_support == 2)
  5874. lpfc_extra_ring_setup(phba);
  5875. return 0;
  5876. }
  5877. /**
  5878. * lpfc_sli_queue_setup - Queue initialization function
  5879. * @phba: Pointer to HBA context object.
  5880. *
  5881. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5882. * ring. This function also initializes ring indices of each ring.
  5883. * This function is called during the initialization of the SLI
  5884. * interface of an HBA.
  5885. * This function is called with no lock held and always returns
  5886. * 1.
  5887. **/
  5888. int
  5889. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5890. {
  5891. struct lpfc_sli *psli;
  5892. struct lpfc_sli_ring *pring;
  5893. int i;
  5894. psli = &phba->sli;
  5895. spin_lock_irq(&phba->hbalock);
  5896. INIT_LIST_HEAD(&psli->mboxq);
  5897. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5898. /* Initialize list headers for txq and txcmplq as double linked lists */
  5899. for (i = 0; i < psli->num_rings; i++) {
  5900. pring = &psli->ring[i];
  5901. pring->ringno = i;
  5902. pring->next_cmdidx = 0;
  5903. pring->local_getidx = 0;
  5904. pring->cmdidx = 0;
  5905. INIT_LIST_HEAD(&pring->txq);
  5906. INIT_LIST_HEAD(&pring->txcmplq);
  5907. INIT_LIST_HEAD(&pring->iocb_continueq);
  5908. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5909. INIT_LIST_HEAD(&pring->postbufq);
  5910. }
  5911. spin_unlock_irq(&phba->hbalock);
  5912. return 1;
  5913. }
  5914. /**
  5915. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5916. * @phba: Pointer to HBA context object.
  5917. *
  5918. * This routine flushes the mailbox command subsystem. It will unconditionally
  5919. * flush all the mailbox commands in the three possible stages in the mailbox
  5920. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5921. * command; and completed mailbox command queue. It is caller's responsibility
  5922. * to make sure that the driver is in the proper state to flush the mailbox
  5923. * command sub-system. Namely, the posting of mailbox commands into the
  5924. * pending mailbox command queue from the various clients must be stopped;
  5925. * either the HBA is in a state that it will never works on the outstanding
  5926. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5927. * mailbox command has been completed.
  5928. **/
  5929. static void
  5930. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5931. {
  5932. LIST_HEAD(completions);
  5933. struct lpfc_sli *psli = &phba->sli;
  5934. LPFC_MBOXQ_t *pmb;
  5935. unsigned long iflag;
  5936. /* Flush all the mailbox commands in the mbox system */
  5937. spin_lock_irqsave(&phba->hbalock, iflag);
  5938. /* The pending mailbox command queue */
  5939. list_splice_init(&phba->sli.mboxq, &completions);
  5940. /* The outstanding active mailbox command */
  5941. if (psli->mbox_active) {
  5942. list_add_tail(&psli->mbox_active->list, &completions);
  5943. psli->mbox_active = NULL;
  5944. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5945. }
  5946. /* The completed mailbox command queue */
  5947. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5948. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5949. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5950. while (!list_empty(&completions)) {
  5951. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5952. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5953. if (pmb->mbox_cmpl)
  5954. pmb->mbox_cmpl(phba, pmb);
  5955. }
  5956. }
  5957. /**
  5958. * lpfc_sli_host_down - Vport cleanup function
  5959. * @vport: Pointer to virtual port object.
  5960. *
  5961. * lpfc_sli_host_down is called to clean up the resources
  5962. * associated with a vport before destroying virtual
  5963. * port data structures.
  5964. * This function does following operations:
  5965. * - Free discovery resources associated with this virtual
  5966. * port.
  5967. * - Free iocbs associated with this virtual port in
  5968. * the txq.
  5969. * - Send abort for all iocb commands associated with this
  5970. * vport in txcmplq.
  5971. *
  5972. * This function is called with no lock held and always returns 1.
  5973. **/
  5974. int
  5975. lpfc_sli_host_down(struct lpfc_vport *vport)
  5976. {
  5977. LIST_HEAD(completions);
  5978. struct lpfc_hba *phba = vport->phba;
  5979. struct lpfc_sli *psli = &phba->sli;
  5980. struct lpfc_sli_ring *pring;
  5981. struct lpfc_iocbq *iocb, *next_iocb;
  5982. int i;
  5983. unsigned long flags = 0;
  5984. uint16_t prev_pring_flag;
  5985. lpfc_cleanup_discovery_resources(vport);
  5986. spin_lock_irqsave(&phba->hbalock, flags);
  5987. for (i = 0; i < psli->num_rings; i++) {
  5988. pring = &psli->ring[i];
  5989. prev_pring_flag = pring->flag;
  5990. /* Only slow rings */
  5991. if (pring->ringno == LPFC_ELS_RING) {
  5992. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5993. /* Set the lpfc data pending flag */
  5994. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5995. }
  5996. /*
  5997. * Error everything on the txq since these iocbs have not been
  5998. * given to the FW yet.
  5999. */
  6000. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6001. if (iocb->vport != vport)
  6002. continue;
  6003. list_move_tail(&iocb->list, &completions);
  6004. pring->txq_cnt--;
  6005. }
  6006. /* Next issue ABTS for everything on the txcmplq */
  6007. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6008. list) {
  6009. if (iocb->vport != vport)
  6010. continue;
  6011. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6012. }
  6013. pring->flag = prev_pring_flag;
  6014. }
  6015. spin_unlock_irqrestore(&phba->hbalock, flags);
  6016. /* Cancel all the IOCBs from the completions list */
  6017. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6018. IOERR_SLI_DOWN);
  6019. return 1;
  6020. }
  6021. /**
  6022. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6023. * @phba: Pointer to HBA context object.
  6024. *
  6025. * This function cleans up all iocb, buffers, mailbox commands
  6026. * while shutting down the HBA. This function is called with no
  6027. * lock held and always returns 1.
  6028. * This function does the following to cleanup driver resources:
  6029. * - Free discovery resources for each virtual port
  6030. * - Cleanup any pending fabric iocbs
  6031. * - Iterate through the iocb txq and free each entry
  6032. * in the list.
  6033. * - Free up any buffer posted to the HBA
  6034. * - Free mailbox commands in the mailbox queue.
  6035. **/
  6036. int
  6037. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6038. {
  6039. LIST_HEAD(completions);
  6040. struct lpfc_sli *psli = &phba->sli;
  6041. struct lpfc_sli_ring *pring;
  6042. struct lpfc_dmabuf *buf_ptr;
  6043. unsigned long flags = 0;
  6044. int i;
  6045. /* Shutdown the mailbox command sub-system */
  6046. lpfc_sli_mbox_sys_shutdown(phba);
  6047. lpfc_hba_down_prep(phba);
  6048. lpfc_fabric_abort_hba(phba);
  6049. spin_lock_irqsave(&phba->hbalock, flags);
  6050. for (i = 0; i < psli->num_rings; i++) {
  6051. pring = &psli->ring[i];
  6052. /* Only slow rings */
  6053. if (pring->ringno == LPFC_ELS_RING) {
  6054. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6055. /* Set the lpfc data pending flag */
  6056. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6057. }
  6058. /*
  6059. * Error everything on the txq since these iocbs have not been
  6060. * given to the FW yet.
  6061. */
  6062. list_splice_init(&pring->txq, &completions);
  6063. pring->txq_cnt = 0;
  6064. }
  6065. spin_unlock_irqrestore(&phba->hbalock, flags);
  6066. /* Cancel all the IOCBs from the completions list */
  6067. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6068. IOERR_SLI_DOWN);
  6069. spin_lock_irqsave(&phba->hbalock, flags);
  6070. list_splice_init(&phba->elsbuf, &completions);
  6071. phba->elsbuf_cnt = 0;
  6072. phba->elsbuf_prev_cnt = 0;
  6073. spin_unlock_irqrestore(&phba->hbalock, flags);
  6074. while (!list_empty(&completions)) {
  6075. list_remove_head(&completions, buf_ptr,
  6076. struct lpfc_dmabuf, list);
  6077. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6078. kfree(buf_ptr);
  6079. }
  6080. /* Return any active mbox cmds */
  6081. del_timer_sync(&psli->mbox_tmo);
  6082. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6083. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6084. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6085. return 1;
  6086. }
  6087. /**
  6088. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6089. * @phba: Pointer to HBA context object.
  6090. *
  6091. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6092. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6093. * lock held and always returns 1.
  6094. *
  6095. * This function does the following to cleanup driver FCoE function resources:
  6096. * - Free discovery resources for each virtual port
  6097. * - Cleanup any pending fabric iocbs
  6098. * - Iterate through the iocb txq and free each entry in the list.
  6099. * - Free up any buffer posted to the HBA.
  6100. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6101. * - Free mailbox commands in the mailbox queue.
  6102. **/
  6103. int
  6104. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6105. {
  6106. /* Stop the SLI4 device port */
  6107. lpfc_stop_port(phba);
  6108. /* Tear down the queues in the HBA */
  6109. lpfc_sli4_queue_unset(phba);
  6110. /* unregister default FCFI from the HBA */
  6111. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6112. return 1;
  6113. }
  6114. /**
  6115. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6116. * @srcp: Source memory pointer.
  6117. * @destp: Destination memory pointer.
  6118. * @cnt: Number of words required to be copied.
  6119. *
  6120. * This function is used for copying data between driver memory
  6121. * and the SLI memory. This function also changes the endianness
  6122. * of each word if native endianness is different from SLI
  6123. * endianness. This function can be called with or without
  6124. * lock.
  6125. **/
  6126. void
  6127. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6128. {
  6129. uint32_t *src = srcp;
  6130. uint32_t *dest = destp;
  6131. uint32_t ldata;
  6132. int i;
  6133. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6134. ldata = *src;
  6135. ldata = le32_to_cpu(ldata);
  6136. *dest = ldata;
  6137. src++;
  6138. dest++;
  6139. }
  6140. }
  6141. /**
  6142. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6143. * @phba: Pointer to HBA context object.
  6144. * @pring: Pointer to driver SLI ring object.
  6145. * @mp: Pointer to driver buffer object.
  6146. *
  6147. * This function is called with no lock held.
  6148. * It always return zero after adding the buffer to the postbufq
  6149. * buffer list.
  6150. **/
  6151. int
  6152. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6153. struct lpfc_dmabuf *mp)
  6154. {
  6155. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6156. later */
  6157. spin_lock_irq(&phba->hbalock);
  6158. list_add_tail(&mp->list, &pring->postbufq);
  6159. pring->postbufq_cnt++;
  6160. spin_unlock_irq(&phba->hbalock);
  6161. return 0;
  6162. }
  6163. /**
  6164. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6165. * @phba: Pointer to HBA context object.
  6166. *
  6167. * When HBQ is enabled, buffers are searched based on tags. This function
  6168. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6169. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6170. * does not conflict with tags of buffer posted for unsolicited events.
  6171. * The function returns the allocated tag. The function is called with
  6172. * no locks held.
  6173. **/
  6174. uint32_t
  6175. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6176. {
  6177. spin_lock_irq(&phba->hbalock);
  6178. phba->buffer_tag_count++;
  6179. /*
  6180. * Always set the QUE_BUFTAG_BIT to distiguish between
  6181. * a tag assigned by HBQ.
  6182. */
  6183. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6184. spin_unlock_irq(&phba->hbalock);
  6185. return phba->buffer_tag_count;
  6186. }
  6187. /**
  6188. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6189. * @phba: Pointer to HBA context object.
  6190. * @pring: Pointer to driver SLI ring object.
  6191. * @tag: Buffer tag.
  6192. *
  6193. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6194. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6195. * iocb is posted to the response ring with the tag of the buffer.
  6196. * This function searches the pring->postbufq list using the tag
  6197. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6198. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6199. * buffer is returned to the caller else NULL is returned.
  6200. * This function is called with no lock held.
  6201. **/
  6202. struct lpfc_dmabuf *
  6203. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6204. uint32_t tag)
  6205. {
  6206. struct lpfc_dmabuf *mp, *next_mp;
  6207. struct list_head *slp = &pring->postbufq;
  6208. /* Search postbufq, from the begining, looking for a match on tag */
  6209. spin_lock_irq(&phba->hbalock);
  6210. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6211. if (mp->buffer_tag == tag) {
  6212. list_del_init(&mp->list);
  6213. pring->postbufq_cnt--;
  6214. spin_unlock_irq(&phba->hbalock);
  6215. return mp;
  6216. }
  6217. }
  6218. spin_unlock_irq(&phba->hbalock);
  6219. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6220. "0402 Cannot find virtual addr for buffer tag on "
  6221. "ring %d Data x%lx x%p x%p x%x\n",
  6222. pring->ringno, (unsigned long) tag,
  6223. slp->next, slp->prev, pring->postbufq_cnt);
  6224. return NULL;
  6225. }
  6226. /**
  6227. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6228. * @phba: Pointer to HBA context object.
  6229. * @pring: Pointer to driver SLI ring object.
  6230. * @phys: DMA address of the buffer.
  6231. *
  6232. * This function searches the buffer list using the dma_address
  6233. * of unsolicited event to find the driver's lpfc_dmabuf object
  6234. * corresponding to the dma_address. The function returns the
  6235. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6236. * This function is called by the ct and els unsolicited event
  6237. * handlers to get the buffer associated with the unsolicited
  6238. * event.
  6239. *
  6240. * This function is called with no lock held.
  6241. **/
  6242. struct lpfc_dmabuf *
  6243. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6244. dma_addr_t phys)
  6245. {
  6246. struct lpfc_dmabuf *mp, *next_mp;
  6247. struct list_head *slp = &pring->postbufq;
  6248. /* Search postbufq, from the begining, looking for a match on phys */
  6249. spin_lock_irq(&phba->hbalock);
  6250. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6251. if (mp->phys == phys) {
  6252. list_del_init(&mp->list);
  6253. pring->postbufq_cnt--;
  6254. spin_unlock_irq(&phba->hbalock);
  6255. return mp;
  6256. }
  6257. }
  6258. spin_unlock_irq(&phba->hbalock);
  6259. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6260. "0410 Cannot find virtual addr for mapped buf on "
  6261. "ring %d Data x%llx x%p x%p x%x\n",
  6262. pring->ringno, (unsigned long long)phys,
  6263. slp->next, slp->prev, pring->postbufq_cnt);
  6264. return NULL;
  6265. }
  6266. /**
  6267. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6268. * @phba: Pointer to HBA context object.
  6269. * @cmdiocb: Pointer to driver command iocb object.
  6270. * @rspiocb: Pointer to driver response iocb object.
  6271. *
  6272. * This function is the completion handler for the abort iocbs for
  6273. * ELS commands. This function is called from the ELS ring event
  6274. * handler with no lock held. This function frees memory resources
  6275. * associated with the abort iocb.
  6276. **/
  6277. static void
  6278. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6279. struct lpfc_iocbq *rspiocb)
  6280. {
  6281. IOCB_t *irsp = &rspiocb->iocb;
  6282. uint16_t abort_iotag, abort_context;
  6283. struct lpfc_iocbq *abort_iocb;
  6284. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6285. abort_iocb = NULL;
  6286. if (irsp->ulpStatus) {
  6287. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6288. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6289. spin_lock_irq(&phba->hbalock);
  6290. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  6291. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  6292. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6293. "0327 Cannot abort els iocb %p "
  6294. "with tag %x context %x, abort status %x, "
  6295. "abort code %x\n",
  6296. abort_iocb, abort_iotag, abort_context,
  6297. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6298. /*
  6299. * If the iocb is not found in Firmware queue the iocb
  6300. * might have completed already. Do not free it again.
  6301. */
  6302. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6303. spin_unlock_irq(&phba->hbalock);
  6304. lpfc_sli_release_iocbq(phba, cmdiocb);
  6305. return;
  6306. }
  6307. /*
  6308. * make sure we have the right iocbq before taking it
  6309. * off the txcmplq and try to call completion routine.
  6310. */
  6311. if (!abort_iocb ||
  6312. abort_iocb->iocb.ulpContext != abort_context ||
  6313. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6314. spin_unlock_irq(&phba->hbalock);
  6315. else {
  6316. list_del_init(&abort_iocb->list);
  6317. pring->txcmplq_cnt--;
  6318. spin_unlock_irq(&phba->hbalock);
  6319. /* Firmware could still be in progress of DMAing
  6320. * payload, so don't free data buffer till after
  6321. * a hbeat.
  6322. */
  6323. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6324. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6325. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6326. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6327. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6328. }
  6329. }
  6330. lpfc_sli_release_iocbq(phba, cmdiocb);
  6331. return;
  6332. }
  6333. /**
  6334. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6335. * @phba: Pointer to HBA context object.
  6336. * @cmdiocb: Pointer to driver command iocb object.
  6337. * @rspiocb: Pointer to driver response iocb object.
  6338. *
  6339. * The function is called from SLI ring event handler with no
  6340. * lock held. This function is the completion handler for ELS commands
  6341. * which are aborted. The function frees memory resources used for
  6342. * the aborted ELS commands.
  6343. **/
  6344. static void
  6345. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6346. struct lpfc_iocbq *rspiocb)
  6347. {
  6348. IOCB_t *irsp = &rspiocb->iocb;
  6349. /* ELS cmd tag <ulpIoTag> completes */
  6350. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6351. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6352. "x%x x%x x%x\n",
  6353. irsp->ulpIoTag, irsp->ulpStatus,
  6354. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6355. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6356. lpfc_ct_free_iocb(phba, cmdiocb);
  6357. else
  6358. lpfc_els_free_iocb(phba, cmdiocb);
  6359. return;
  6360. }
  6361. /**
  6362. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6363. * @phba: Pointer to HBA context object.
  6364. * @pring: Pointer to driver SLI ring object.
  6365. * @cmdiocb: Pointer to driver command iocb object.
  6366. *
  6367. * This function issues an abort iocb for the provided command
  6368. * iocb. This function is called with hbalock held.
  6369. * The function returns 0 when it fails due to memory allocation
  6370. * failure or when the command iocb is an abort request.
  6371. **/
  6372. int
  6373. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6374. struct lpfc_iocbq *cmdiocb)
  6375. {
  6376. struct lpfc_vport *vport = cmdiocb->vport;
  6377. struct lpfc_iocbq *abtsiocbp;
  6378. IOCB_t *icmd = NULL;
  6379. IOCB_t *iabt = NULL;
  6380. int retval = IOCB_ERROR;
  6381. /*
  6382. * There are certain command types we don't want to abort. And we
  6383. * don't want to abort commands that are already in the process of
  6384. * being aborted.
  6385. */
  6386. icmd = &cmdiocb->iocb;
  6387. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6388. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6389. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6390. return 0;
  6391. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6392. * callback so that nothing happens when it finishes.
  6393. */
  6394. if ((vport->load_flag & FC_UNLOADING) &&
  6395. (pring->ringno == LPFC_ELS_RING)) {
  6396. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6397. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6398. else
  6399. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6400. goto abort_iotag_exit;
  6401. }
  6402. /* issue ABTS for this IOCB based on iotag */
  6403. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6404. if (abtsiocbp == NULL)
  6405. return 0;
  6406. /* This signals the response to set the correct status
  6407. * before calling the completion handler.
  6408. */
  6409. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6410. iabt = &abtsiocbp->iocb;
  6411. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6412. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6413. if (phba->sli_rev == LPFC_SLI_REV4)
  6414. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6415. else
  6416. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6417. iabt->ulpLe = 1;
  6418. iabt->ulpClass = icmd->ulpClass;
  6419. if (phba->link_state >= LPFC_LINK_UP)
  6420. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6421. else
  6422. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6423. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6424. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6425. "0339 Abort xri x%x, original iotag x%x, "
  6426. "abort cmd iotag x%x\n",
  6427. iabt->un.acxri.abortContextTag,
  6428. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6429. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6430. if (retval)
  6431. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6432. abort_iotag_exit:
  6433. /*
  6434. * Caller to this routine should check for IOCB_ERROR
  6435. * and handle it properly. This routine no longer removes
  6436. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6437. */
  6438. return retval;
  6439. }
  6440. /**
  6441. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6442. * @iocbq: Pointer to driver iocb object.
  6443. * @vport: Pointer to driver virtual port object.
  6444. * @tgt_id: SCSI ID of the target.
  6445. * @lun_id: LUN ID of the scsi device.
  6446. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6447. *
  6448. * This function acts as an iocb filter for functions which abort or count
  6449. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6450. * 0 if the filtering criteria is met for the given iocb and will return
  6451. * 1 if the filtering criteria is not met.
  6452. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6453. * given iocb is for the SCSI device specified by vport, tgt_id and
  6454. * lun_id parameter.
  6455. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6456. * given iocb is for the SCSI target specified by vport and tgt_id
  6457. * parameters.
  6458. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6459. * given iocb is for the SCSI host associated with the given vport.
  6460. * This function is called with no locks held.
  6461. **/
  6462. static int
  6463. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6464. uint16_t tgt_id, uint64_t lun_id,
  6465. lpfc_ctx_cmd ctx_cmd)
  6466. {
  6467. struct lpfc_scsi_buf *lpfc_cmd;
  6468. int rc = 1;
  6469. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6470. return rc;
  6471. if (iocbq->vport != vport)
  6472. return rc;
  6473. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6474. if (lpfc_cmd->pCmd == NULL)
  6475. return rc;
  6476. switch (ctx_cmd) {
  6477. case LPFC_CTX_LUN:
  6478. if ((lpfc_cmd->rdata->pnode) &&
  6479. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6480. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6481. rc = 0;
  6482. break;
  6483. case LPFC_CTX_TGT:
  6484. if ((lpfc_cmd->rdata->pnode) &&
  6485. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6486. rc = 0;
  6487. break;
  6488. case LPFC_CTX_HOST:
  6489. rc = 0;
  6490. break;
  6491. default:
  6492. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6493. __func__, ctx_cmd);
  6494. break;
  6495. }
  6496. return rc;
  6497. }
  6498. /**
  6499. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6500. * @vport: Pointer to virtual port.
  6501. * @tgt_id: SCSI ID of the target.
  6502. * @lun_id: LUN ID of the scsi device.
  6503. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6504. *
  6505. * This function returns number of FCP commands pending for the vport.
  6506. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6507. * commands pending on the vport associated with SCSI device specified
  6508. * by tgt_id and lun_id parameters.
  6509. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6510. * commands pending on the vport associated with SCSI target specified
  6511. * by tgt_id parameter.
  6512. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6513. * commands pending on the vport.
  6514. * This function returns the number of iocbs which satisfy the filter.
  6515. * This function is called without any lock held.
  6516. **/
  6517. int
  6518. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6519. lpfc_ctx_cmd ctx_cmd)
  6520. {
  6521. struct lpfc_hba *phba = vport->phba;
  6522. struct lpfc_iocbq *iocbq;
  6523. int sum, i;
  6524. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6525. iocbq = phba->sli.iocbq_lookup[i];
  6526. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6527. ctx_cmd) == 0)
  6528. sum++;
  6529. }
  6530. return sum;
  6531. }
  6532. /**
  6533. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6534. * @phba: Pointer to HBA context object
  6535. * @cmdiocb: Pointer to command iocb object.
  6536. * @rspiocb: Pointer to response iocb object.
  6537. *
  6538. * This function is called when an aborted FCP iocb completes. This
  6539. * function is called by the ring event handler with no lock held.
  6540. * This function frees the iocb.
  6541. **/
  6542. void
  6543. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6544. struct lpfc_iocbq *rspiocb)
  6545. {
  6546. lpfc_sli_release_iocbq(phba, cmdiocb);
  6547. return;
  6548. }
  6549. /**
  6550. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6551. * @vport: Pointer to virtual port.
  6552. * @pring: Pointer to driver SLI ring object.
  6553. * @tgt_id: SCSI ID of the target.
  6554. * @lun_id: LUN ID of the scsi device.
  6555. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6556. *
  6557. * This function sends an abort command for every SCSI command
  6558. * associated with the given virtual port pending on the ring
  6559. * filtered by lpfc_sli_validate_fcp_iocb function.
  6560. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6561. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6562. * parameters
  6563. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6564. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6565. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6566. * FCP iocbs associated with virtual port.
  6567. * This function returns number of iocbs it failed to abort.
  6568. * This function is called with no locks held.
  6569. **/
  6570. int
  6571. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6572. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6573. {
  6574. struct lpfc_hba *phba = vport->phba;
  6575. struct lpfc_iocbq *iocbq;
  6576. struct lpfc_iocbq *abtsiocb;
  6577. IOCB_t *cmd = NULL;
  6578. int errcnt = 0, ret_val = 0;
  6579. int i;
  6580. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6581. iocbq = phba->sli.iocbq_lookup[i];
  6582. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6583. abort_cmd) != 0)
  6584. continue;
  6585. /* issue ABTS for this IOCB based on iotag */
  6586. abtsiocb = lpfc_sli_get_iocbq(phba);
  6587. if (abtsiocb == NULL) {
  6588. errcnt++;
  6589. continue;
  6590. }
  6591. cmd = &iocbq->iocb;
  6592. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6593. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6594. if (phba->sli_rev == LPFC_SLI_REV4)
  6595. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6596. else
  6597. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6598. abtsiocb->iocb.ulpLe = 1;
  6599. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6600. abtsiocb->vport = phba->pport;
  6601. if (lpfc_is_link_up(phba))
  6602. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6603. else
  6604. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6605. /* Setup callback routine and issue the command. */
  6606. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6607. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6608. abtsiocb, 0);
  6609. if (ret_val == IOCB_ERROR) {
  6610. lpfc_sli_release_iocbq(phba, abtsiocb);
  6611. errcnt++;
  6612. continue;
  6613. }
  6614. }
  6615. return errcnt;
  6616. }
  6617. /**
  6618. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6619. * @phba: Pointer to HBA context object.
  6620. * @cmdiocbq: Pointer to command iocb.
  6621. * @rspiocbq: Pointer to response iocb.
  6622. *
  6623. * This function is the completion handler for iocbs issued using
  6624. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6625. * ring event handler function without any lock held. This function
  6626. * can be called from both worker thread context and interrupt
  6627. * context. This function also can be called from other thread which
  6628. * cleans up the SLI layer objects.
  6629. * This function copy the contents of the response iocb to the
  6630. * response iocb memory object provided by the caller of
  6631. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6632. * sleeps for the iocb completion.
  6633. **/
  6634. static void
  6635. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6636. struct lpfc_iocbq *cmdiocbq,
  6637. struct lpfc_iocbq *rspiocbq)
  6638. {
  6639. wait_queue_head_t *pdone_q;
  6640. unsigned long iflags;
  6641. spin_lock_irqsave(&phba->hbalock, iflags);
  6642. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6643. if (cmdiocbq->context2 && rspiocbq)
  6644. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6645. &rspiocbq->iocb, sizeof(IOCB_t));
  6646. pdone_q = cmdiocbq->context_un.wait_queue;
  6647. if (pdone_q)
  6648. wake_up(pdone_q);
  6649. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6650. return;
  6651. }
  6652. /**
  6653. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  6654. * @phba: Pointer to HBA context object..
  6655. * @piocbq: Pointer to command iocb.
  6656. * @flag: Flag to test.
  6657. *
  6658. * This routine grabs the hbalock and then test the iocb_flag to
  6659. * see if the passed in flag is set.
  6660. * Returns:
  6661. * 1 if flag is set.
  6662. * 0 if flag is not set.
  6663. **/
  6664. static int
  6665. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  6666. struct lpfc_iocbq *piocbq, uint32_t flag)
  6667. {
  6668. unsigned long iflags;
  6669. int ret;
  6670. spin_lock_irqsave(&phba->hbalock, iflags);
  6671. ret = piocbq->iocb_flag & flag;
  6672. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6673. return ret;
  6674. }
  6675. /**
  6676. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6677. * @phba: Pointer to HBA context object..
  6678. * @pring: Pointer to sli ring.
  6679. * @piocb: Pointer to command iocb.
  6680. * @prspiocbq: Pointer to response iocb.
  6681. * @timeout: Timeout in number of seconds.
  6682. *
  6683. * This function issues the iocb to firmware and waits for the
  6684. * iocb to complete. If the iocb command is not
  6685. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6686. * Caller should not free the iocb resources if this function
  6687. * returns IOCB_TIMEDOUT.
  6688. * The function waits for the iocb completion using an
  6689. * non-interruptible wait.
  6690. * This function will sleep while waiting for iocb completion.
  6691. * So, this function should not be called from any context which
  6692. * does not allow sleeping. Due to the same reason, this function
  6693. * cannot be called with interrupt disabled.
  6694. * This function assumes that the iocb completions occur while
  6695. * this function sleep. So, this function cannot be called from
  6696. * the thread which process iocb completion for this ring.
  6697. * This function clears the iocb_flag of the iocb object before
  6698. * issuing the iocb and the iocb completion handler sets this
  6699. * flag and wakes this thread when the iocb completes.
  6700. * The contents of the response iocb will be copied to prspiocbq
  6701. * by the completion handler when the command completes.
  6702. * This function returns IOCB_SUCCESS when success.
  6703. * This function is called with no lock held.
  6704. **/
  6705. int
  6706. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6707. uint32_t ring_number,
  6708. struct lpfc_iocbq *piocb,
  6709. struct lpfc_iocbq *prspiocbq,
  6710. uint32_t timeout)
  6711. {
  6712. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6713. long timeleft, timeout_req = 0;
  6714. int retval = IOCB_SUCCESS;
  6715. uint32_t creg_val;
  6716. /*
  6717. * If the caller has provided a response iocbq buffer, then context2
  6718. * is NULL or its an error.
  6719. */
  6720. if (prspiocbq) {
  6721. if (piocb->context2)
  6722. return IOCB_ERROR;
  6723. piocb->context2 = prspiocbq;
  6724. }
  6725. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6726. piocb->context_un.wait_queue = &done_q;
  6727. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6728. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6729. creg_val = readl(phba->HCregaddr);
  6730. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6731. writel(creg_val, phba->HCregaddr);
  6732. readl(phba->HCregaddr); /* flush */
  6733. }
  6734. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6735. if (retval == IOCB_SUCCESS) {
  6736. timeout_req = timeout * HZ;
  6737. timeleft = wait_event_timeout(done_q,
  6738. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  6739. timeout_req);
  6740. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6741. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6742. "0331 IOCB wake signaled\n");
  6743. } else if (timeleft == 0) {
  6744. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6745. "0338 IOCB wait timeout error - no "
  6746. "wake response Data x%x\n", timeout);
  6747. retval = IOCB_TIMEDOUT;
  6748. } else {
  6749. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6750. "0330 IOCB wake NOT set, "
  6751. "Data x%x x%lx\n",
  6752. timeout, (timeleft / jiffies));
  6753. retval = IOCB_TIMEDOUT;
  6754. }
  6755. } else {
  6756. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6757. "0332 IOCB wait issue failed, Data x%x\n",
  6758. retval);
  6759. retval = IOCB_ERROR;
  6760. }
  6761. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6762. creg_val = readl(phba->HCregaddr);
  6763. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6764. writel(creg_val, phba->HCregaddr);
  6765. readl(phba->HCregaddr); /* flush */
  6766. }
  6767. if (prspiocbq)
  6768. piocb->context2 = NULL;
  6769. piocb->context_un.wait_queue = NULL;
  6770. piocb->iocb_cmpl = NULL;
  6771. return retval;
  6772. }
  6773. /**
  6774. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6775. * @phba: Pointer to HBA context object.
  6776. * @pmboxq: Pointer to driver mailbox object.
  6777. * @timeout: Timeout in number of seconds.
  6778. *
  6779. * This function issues the mailbox to firmware and waits for the
  6780. * mailbox command to complete. If the mailbox command is not
  6781. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6782. * The function waits for the mailbox completion using an
  6783. * interruptible wait. If the thread is woken up due to a
  6784. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6785. * should not free the mailbox resources, if this function returns
  6786. * MBX_TIMEOUT.
  6787. * This function will sleep while waiting for mailbox completion.
  6788. * So, this function should not be called from any context which
  6789. * does not allow sleeping. Due to the same reason, this function
  6790. * cannot be called with interrupt disabled.
  6791. * This function assumes that the mailbox completion occurs while
  6792. * this function sleep. So, this function cannot be called from
  6793. * the worker thread which processes mailbox completion.
  6794. * This function is called in the context of HBA management
  6795. * applications.
  6796. * This function returns MBX_SUCCESS when successful.
  6797. * This function is called with no lock held.
  6798. **/
  6799. int
  6800. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6801. uint32_t timeout)
  6802. {
  6803. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6804. int retval;
  6805. unsigned long flag;
  6806. /* The caller must leave context1 empty. */
  6807. if (pmboxq->context1)
  6808. return MBX_NOT_FINISHED;
  6809. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6810. /* setup wake call as IOCB callback */
  6811. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6812. /* setup context field to pass wait_queue pointer to wake function */
  6813. pmboxq->context1 = &done_q;
  6814. /* now issue the command */
  6815. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6816. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6817. wait_event_interruptible_timeout(done_q,
  6818. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6819. timeout * HZ);
  6820. spin_lock_irqsave(&phba->hbalock, flag);
  6821. pmboxq->context1 = NULL;
  6822. /*
  6823. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6824. * else do not free the resources.
  6825. */
  6826. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6827. retval = MBX_SUCCESS;
  6828. else {
  6829. retval = MBX_TIMEOUT;
  6830. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6831. }
  6832. spin_unlock_irqrestore(&phba->hbalock, flag);
  6833. }
  6834. return retval;
  6835. }
  6836. /**
  6837. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6838. * @phba: Pointer to HBA context.
  6839. *
  6840. * This function is called to shutdown the driver's mailbox sub-system.
  6841. * It first marks the mailbox sub-system is in a block state to prevent
  6842. * the asynchronous mailbox command from issued off the pending mailbox
  6843. * command queue. If the mailbox command sub-system shutdown is due to
  6844. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6845. * the mailbox sub-system flush routine to forcefully bring down the
  6846. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6847. * as with offline or HBA function reset), this routine will wait for the
  6848. * outstanding mailbox command to complete before invoking the mailbox
  6849. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6850. **/
  6851. void
  6852. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6853. {
  6854. struct lpfc_sli *psli = &phba->sli;
  6855. uint8_t actcmd = MBX_HEARTBEAT;
  6856. unsigned long timeout;
  6857. spin_lock_irq(&phba->hbalock);
  6858. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6859. spin_unlock_irq(&phba->hbalock);
  6860. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6861. spin_lock_irq(&phba->hbalock);
  6862. if (phba->sli.mbox_active)
  6863. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6864. spin_unlock_irq(&phba->hbalock);
  6865. /* Determine how long we might wait for the active mailbox
  6866. * command to be gracefully completed by firmware.
  6867. */
  6868. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6869. 1000) + jiffies;
  6870. while (phba->sli.mbox_active) {
  6871. /* Check active mailbox complete status every 2ms */
  6872. msleep(2);
  6873. if (time_after(jiffies, timeout))
  6874. /* Timeout, let the mailbox flush routine to
  6875. * forcefully release active mailbox command
  6876. */
  6877. break;
  6878. }
  6879. }
  6880. lpfc_sli_mbox_sys_flush(phba);
  6881. }
  6882. /**
  6883. * lpfc_sli_eratt_read - read sli-3 error attention events
  6884. * @phba: Pointer to HBA context.
  6885. *
  6886. * This function is called to read the SLI3 device error attention registers
  6887. * for possible error attention events. The caller must hold the hostlock
  6888. * with spin_lock_irq().
  6889. *
  6890. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6891. * Register and returns 0 otherwise.
  6892. **/
  6893. static int
  6894. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6895. {
  6896. uint32_t ha_copy;
  6897. /* Read chip Host Attention (HA) register */
  6898. ha_copy = readl(phba->HAregaddr);
  6899. if (ha_copy & HA_ERATT) {
  6900. /* Read host status register to retrieve error event */
  6901. lpfc_sli_read_hs(phba);
  6902. /* Check if there is a deferred error condition is active */
  6903. if ((HS_FFER1 & phba->work_hs) &&
  6904. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6905. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6906. phba->hba_flag |= DEFER_ERATT;
  6907. /* Clear all interrupt enable conditions */
  6908. writel(0, phba->HCregaddr);
  6909. readl(phba->HCregaddr);
  6910. }
  6911. /* Set the driver HA work bitmap */
  6912. phba->work_ha |= HA_ERATT;
  6913. /* Indicate polling handles this ERATT */
  6914. phba->hba_flag |= HBA_ERATT_HANDLED;
  6915. return 1;
  6916. }
  6917. return 0;
  6918. }
  6919. /**
  6920. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6921. * @phba: Pointer to HBA context.
  6922. *
  6923. * This function is called to read the SLI4 device error attention registers
  6924. * for possible error attention events. The caller must hold the hostlock
  6925. * with spin_lock_irq().
  6926. *
  6927. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6928. * Register and returns 0 otherwise.
  6929. **/
  6930. static int
  6931. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6932. {
  6933. uint32_t uerr_sta_hi, uerr_sta_lo;
  6934. uint32_t onlnreg0, onlnreg1;
  6935. /* For now, use the SLI4 device internal unrecoverable error
  6936. * registers for error attention. This can be changed later.
  6937. */
  6938. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  6939. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  6940. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  6941. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6942. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6943. if (uerr_sta_lo || uerr_sta_hi) {
  6944. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6945. "1423 HBA Unrecoverable error: "
  6946. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6947. "online0_reg=0x%x, online1_reg=0x%x\n",
  6948. uerr_sta_lo, uerr_sta_hi,
  6949. onlnreg0, onlnreg1);
  6950. /* TEMP: as the driver error recover logic is not
  6951. * fully developed, we just log the error message
  6952. * and the device error attention action is now
  6953. * temporarily disabled.
  6954. */
  6955. return 0;
  6956. phba->work_status[0] = uerr_sta_lo;
  6957. phba->work_status[1] = uerr_sta_hi;
  6958. /* Set the driver HA work bitmap */
  6959. phba->work_ha |= HA_ERATT;
  6960. /* Indicate polling handles this ERATT */
  6961. phba->hba_flag |= HBA_ERATT_HANDLED;
  6962. return 1;
  6963. }
  6964. }
  6965. return 0;
  6966. }
  6967. /**
  6968. * lpfc_sli_check_eratt - check error attention events
  6969. * @phba: Pointer to HBA context.
  6970. *
  6971. * This function is called from timer soft interrupt context to check HBA's
  6972. * error attention register bit for error attention events.
  6973. *
  6974. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6975. * Register and returns 0 otherwise.
  6976. **/
  6977. int
  6978. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  6979. {
  6980. uint32_t ha_copy;
  6981. /* If somebody is waiting to handle an eratt, don't process it
  6982. * here. The brdkill function will do this.
  6983. */
  6984. if (phba->link_flag & LS_IGNORE_ERATT)
  6985. return 0;
  6986. /* Check if interrupt handler handles this ERATT */
  6987. spin_lock_irq(&phba->hbalock);
  6988. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  6989. /* Interrupt handler has handled ERATT */
  6990. spin_unlock_irq(&phba->hbalock);
  6991. return 0;
  6992. }
  6993. /*
  6994. * If there is deferred error attention, do not check for error
  6995. * attention
  6996. */
  6997. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6998. spin_unlock_irq(&phba->hbalock);
  6999. return 0;
  7000. }
  7001. /* If PCI channel is offline, don't process it */
  7002. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7003. spin_unlock_irq(&phba->hbalock);
  7004. return 0;
  7005. }
  7006. switch (phba->sli_rev) {
  7007. case LPFC_SLI_REV2:
  7008. case LPFC_SLI_REV3:
  7009. /* Read chip Host Attention (HA) register */
  7010. ha_copy = lpfc_sli_eratt_read(phba);
  7011. break;
  7012. case LPFC_SLI_REV4:
  7013. /* Read devcie Uncoverable Error (UERR) registers */
  7014. ha_copy = lpfc_sli4_eratt_read(phba);
  7015. break;
  7016. default:
  7017. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7018. "0299 Invalid SLI revision (%d)\n",
  7019. phba->sli_rev);
  7020. ha_copy = 0;
  7021. break;
  7022. }
  7023. spin_unlock_irq(&phba->hbalock);
  7024. return ha_copy;
  7025. }
  7026. /**
  7027. * lpfc_intr_state_check - Check device state for interrupt handling
  7028. * @phba: Pointer to HBA context.
  7029. *
  7030. * This inline routine checks whether a device or its PCI slot is in a state
  7031. * that the interrupt should be handled.
  7032. *
  7033. * This function returns 0 if the device or the PCI slot is in a state that
  7034. * interrupt should be handled, otherwise -EIO.
  7035. */
  7036. static inline int
  7037. lpfc_intr_state_check(struct lpfc_hba *phba)
  7038. {
  7039. /* If the pci channel is offline, ignore all the interrupts */
  7040. if (unlikely(pci_channel_offline(phba->pcidev)))
  7041. return -EIO;
  7042. /* Update device level interrupt statistics */
  7043. phba->sli.slistat.sli_intr++;
  7044. /* Ignore all interrupts during initialization. */
  7045. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7046. return -EIO;
  7047. return 0;
  7048. }
  7049. /**
  7050. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7051. * @irq: Interrupt number.
  7052. * @dev_id: The device context pointer.
  7053. *
  7054. * This function is directly called from the PCI layer as an interrupt
  7055. * service routine when device with SLI-3 interface spec is enabled with
  7056. * MSI-X multi-message interrupt mode and there are slow-path events in
  7057. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7058. * interrupt mode, this function is called as part of the device-level
  7059. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7060. * is undergoing initialization, the interrupt handler will not process
  7061. * the interrupt. The link attention and ELS ring attention events are
  7062. * handled by the worker thread. The interrupt handler signals the worker
  7063. * thread and returns for these events. This function is called without
  7064. * any lock held. It gets the hbalock to access and update SLI data
  7065. * structures.
  7066. *
  7067. * This function returns IRQ_HANDLED when interrupt is handled else it
  7068. * returns IRQ_NONE.
  7069. **/
  7070. irqreturn_t
  7071. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7072. {
  7073. struct lpfc_hba *phba;
  7074. uint32_t ha_copy;
  7075. uint32_t work_ha_copy;
  7076. unsigned long status;
  7077. unsigned long iflag;
  7078. uint32_t control;
  7079. MAILBOX_t *mbox, *pmbox;
  7080. struct lpfc_vport *vport;
  7081. struct lpfc_nodelist *ndlp;
  7082. struct lpfc_dmabuf *mp;
  7083. LPFC_MBOXQ_t *pmb;
  7084. int rc;
  7085. /*
  7086. * Get the driver's phba structure from the dev_id and
  7087. * assume the HBA is not interrupting.
  7088. */
  7089. phba = (struct lpfc_hba *)dev_id;
  7090. if (unlikely(!phba))
  7091. return IRQ_NONE;
  7092. /*
  7093. * Stuff needs to be attented to when this function is invoked as an
  7094. * individual interrupt handler in MSI-X multi-message interrupt mode
  7095. */
  7096. if (phba->intr_type == MSIX) {
  7097. /* Check device state for handling interrupt */
  7098. if (lpfc_intr_state_check(phba))
  7099. return IRQ_NONE;
  7100. /* Need to read HA REG for slow-path events */
  7101. spin_lock_irqsave(&phba->hbalock, iflag);
  7102. ha_copy = readl(phba->HAregaddr);
  7103. /* If somebody is waiting to handle an eratt don't process it
  7104. * here. The brdkill function will do this.
  7105. */
  7106. if (phba->link_flag & LS_IGNORE_ERATT)
  7107. ha_copy &= ~HA_ERATT;
  7108. /* Check the need for handling ERATT in interrupt handler */
  7109. if (ha_copy & HA_ERATT) {
  7110. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7111. /* ERATT polling has handled ERATT */
  7112. ha_copy &= ~HA_ERATT;
  7113. else
  7114. /* Indicate interrupt handler handles ERATT */
  7115. phba->hba_flag |= HBA_ERATT_HANDLED;
  7116. }
  7117. /*
  7118. * If there is deferred error attention, do not check for any
  7119. * interrupt.
  7120. */
  7121. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7122. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7123. return IRQ_NONE;
  7124. }
  7125. /* Clear up only attention source related to slow-path */
  7126. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7127. phba->HAregaddr);
  7128. readl(phba->HAregaddr); /* flush */
  7129. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7130. } else
  7131. ha_copy = phba->ha_copy;
  7132. work_ha_copy = ha_copy & phba->work_ha_mask;
  7133. if (work_ha_copy) {
  7134. if (work_ha_copy & HA_LATT) {
  7135. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7136. /*
  7137. * Turn off Link Attention interrupts
  7138. * until CLEAR_LA done
  7139. */
  7140. spin_lock_irqsave(&phba->hbalock, iflag);
  7141. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7142. control = readl(phba->HCregaddr);
  7143. control &= ~HC_LAINT_ENA;
  7144. writel(control, phba->HCregaddr);
  7145. readl(phba->HCregaddr); /* flush */
  7146. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7147. }
  7148. else
  7149. work_ha_copy &= ~HA_LATT;
  7150. }
  7151. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7152. /*
  7153. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7154. * the only slow ring.
  7155. */
  7156. status = (work_ha_copy &
  7157. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7158. status >>= (4*LPFC_ELS_RING);
  7159. if (status & HA_RXMASK) {
  7160. spin_lock_irqsave(&phba->hbalock, iflag);
  7161. control = readl(phba->HCregaddr);
  7162. lpfc_debugfs_slow_ring_trc(phba,
  7163. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7164. control, status,
  7165. (uint32_t)phba->sli.slistat.sli_intr);
  7166. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7167. lpfc_debugfs_slow_ring_trc(phba,
  7168. "ISR Disable ring:"
  7169. "pwork:x%x hawork:x%x wait:x%x",
  7170. phba->work_ha, work_ha_copy,
  7171. (uint32_t)((unsigned long)
  7172. &phba->work_waitq));
  7173. control &=
  7174. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7175. writel(control, phba->HCregaddr);
  7176. readl(phba->HCregaddr); /* flush */
  7177. }
  7178. else {
  7179. lpfc_debugfs_slow_ring_trc(phba,
  7180. "ISR slow ring: pwork:"
  7181. "x%x hawork:x%x wait:x%x",
  7182. phba->work_ha, work_ha_copy,
  7183. (uint32_t)((unsigned long)
  7184. &phba->work_waitq));
  7185. }
  7186. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7187. }
  7188. }
  7189. spin_lock_irqsave(&phba->hbalock, iflag);
  7190. if (work_ha_copy & HA_ERATT) {
  7191. lpfc_sli_read_hs(phba);
  7192. /*
  7193. * Check if there is a deferred error condition
  7194. * is active
  7195. */
  7196. if ((HS_FFER1 & phba->work_hs) &&
  7197. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7198. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7199. phba->hba_flag |= DEFER_ERATT;
  7200. /* Clear all interrupt enable conditions */
  7201. writel(0, phba->HCregaddr);
  7202. readl(phba->HCregaddr);
  7203. }
  7204. }
  7205. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7206. pmb = phba->sli.mbox_active;
  7207. pmbox = &pmb->u.mb;
  7208. mbox = phba->mbox;
  7209. vport = pmb->vport;
  7210. /* First check out the status word */
  7211. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7212. if (pmbox->mbxOwner != OWN_HOST) {
  7213. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7214. /*
  7215. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7216. * mbxStatus <status>
  7217. */
  7218. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7219. LOG_SLI,
  7220. "(%d):0304 Stray Mailbox "
  7221. "Interrupt mbxCommand x%x "
  7222. "mbxStatus x%x\n",
  7223. (vport ? vport->vpi : 0),
  7224. pmbox->mbxCommand,
  7225. pmbox->mbxStatus);
  7226. /* clear mailbox attention bit */
  7227. work_ha_copy &= ~HA_MBATT;
  7228. } else {
  7229. phba->sli.mbox_active = NULL;
  7230. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7231. phba->last_completion_time = jiffies;
  7232. del_timer(&phba->sli.mbox_tmo);
  7233. if (pmb->mbox_cmpl) {
  7234. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7235. MAILBOX_CMD_SIZE);
  7236. }
  7237. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7238. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7239. lpfc_debugfs_disc_trc(vport,
  7240. LPFC_DISC_TRC_MBOX_VPORT,
  7241. "MBOX dflt rpi: : "
  7242. "status:x%x rpi:x%x",
  7243. (uint32_t)pmbox->mbxStatus,
  7244. pmbox->un.varWords[0], 0);
  7245. if (!pmbox->mbxStatus) {
  7246. mp = (struct lpfc_dmabuf *)
  7247. (pmb->context1);
  7248. ndlp = (struct lpfc_nodelist *)
  7249. pmb->context2;
  7250. /* Reg_LOGIN of dflt RPI was
  7251. * successful. new lets get
  7252. * rid of the RPI using the
  7253. * same mbox buffer.
  7254. */
  7255. lpfc_unreg_login(phba,
  7256. vport->vpi,
  7257. pmbox->un.varWords[0],
  7258. pmb);
  7259. pmb->mbox_cmpl =
  7260. lpfc_mbx_cmpl_dflt_rpi;
  7261. pmb->context1 = mp;
  7262. pmb->context2 = ndlp;
  7263. pmb->vport = vport;
  7264. rc = lpfc_sli_issue_mbox(phba,
  7265. pmb,
  7266. MBX_NOWAIT);
  7267. if (rc != MBX_BUSY)
  7268. lpfc_printf_log(phba,
  7269. KERN_ERR,
  7270. LOG_MBOX | LOG_SLI,
  7271. "0350 rc should have"
  7272. "been MBX_BUSY");
  7273. if (rc != MBX_NOT_FINISHED)
  7274. goto send_current_mbox;
  7275. }
  7276. }
  7277. spin_lock_irqsave(
  7278. &phba->pport->work_port_lock,
  7279. iflag);
  7280. phba->pport->work_port_events &=
  7281. ~WORKER_MBOX_TMO;
  7282. spin_unlock_irqrestore(
  7283. &phba->pport->work_port_lock,
  7284. iflag);
  7285. lpfc_mbox_cmpl_put(phba, pmb);
  7286. }
  7287. } else
  7288. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7289. if ((work_ha_copy & HA_MBATT) &&
  7290. (phba->sli.mbox_active == NULL)) {
  7291. send_current_mbox:
  7292. /* Process next mailbox command if there is one */
  7293. do {
  7294. rc = lpfc_sli_issue_mbox(phba, NULL,
  7295. MBX_NOWAIT);
  7296. } while (rc == MBX_NOT_FINISHED);
  7297. if (rc != MBX_SUCCESS)
  7298. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7299. LOG_SLI, "0349 rc should be "
  7300. "MBX_SUCCESS");
  7301. }
  7302. spin_lock_irqsave(&phba->hbalock, iflag);
  7303. phba->work_ha |= work_ha_copy;
  7304. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7305. lpfc_worker_wake_up(phba);
  7306. }
  7307. return IRQ_HANDLED;
  7308. } /* lpfc_sli_sp_intr_handler */
  7309. /**
  7310. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7311. * @irq: Interrupt number.
  7312. * @dev_id: The device context pointer.
  7313. *
  7314. * This function is directly called from the PCI layer as an interrupt
  7315. * service routine when device with SLI-3 interface spec is enabled with
  7316. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7317. * ring event in the HBA. However, when the device is enabled with either
  7318. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7319. * device-level interrupt handler. When the PCI slot is in error recovery
  7320. * or the HBA is undergoing initialization, the interrupt handler will not
  7321. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7322. * the intrrupt context. This function is called without any lock held.
  7323. * It gets the hbalock to access and update SLI data structures.
  7324. *
  7325. * This function returns IRQ_HANDLED when interrupt is handled else it
  7326. * returns IRQ_NONE.
  7327. **/
  7328. irqreturn_t
  7329. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7330. {
  7331. struct lpfc_hba *phba;
  7332. uint32_t ha_copy;
  7333. unsigned long status;
  7334. unsigned long iflag;
  7335. /* Get the driver's phba structure from the dev_id and
  7336. * assume the HBA is not interrupting.
  7337. */
  7338. phba = (struct lpfc_hba *) dev_id;
  7339. if (unlikely(!phba))
  7340. return IRQ_NONE;
  7341. /*
  7342. * Stuff needs to be attented to when this function is invoked as an
  7343. * individual interrupt handler in MSI-X multi-message interrupt mode
  7344. */
  7345. if (phba->intr_type == MSIX) {
  7346. /* Check device state for handling interrupt */
  7347. if (lpfc_intr_state_check(phba))
  7348. return IRQ_NONE;
  7349. /* Need to read HA REG for FCP ring and other ring events */
  7350. ha_copy = readl(phba->HAregaddr);
  7351. /* Clear up only attention source related to fast-path */
  7352. spin_lock_irqsave(&phba->hbalock, iflag);
  7353. /*
  7354. * If there is deferred error attention, do not check for
  7355. * any interrupt.
  7356. */
  7357. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7358. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7359. return IRQ_NONE;
  7360. }
  7361. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7362. phba->HAregaddr);
  7363. readl(phba->HAregaddr); /* flush */
  7364. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7365. } else
  7366. ha_copy = phba->ha_copy;
  7367. /*
  7368. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7369. */
  7370. ha_copy &= ~(phba->work_ha_mask);
  7371. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7372. status >>= (4*LPFC_FCP_RING);
  7373. if (status & HA_RXMASK)
  7374. lpfc_sli_handle_fast_ring_event(phba,
  7375. &phba->sli.ring[LPFC_FCP_RING],
  7376. status);
  7377. if (phba->cfg_multi_ring_support == 2) {
  7378. /*
  7379. * Process all events on extra ring. Take the optimized path
  7380. * for extra ring IO.
  7381. */
  7382. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7383. status >>= (4*LPFC_EXTRA_RING);
  7384. if (status & HA_RXMASK) {
  7385. lpfc_sli_handle_fast_ring_event(phba,
  7386. &phba->sli.ring[LPFC_EXTRA_RING],
  7387. status);
  7388. }
  7389. }
  7390. return IRQ_HANDLED;
  7391. } /* lpfc_sli_fp_intr_handler */
  7392. /**
  7393. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7394. * @irq: Interrupt number.
  7395. * @dev_id: The device context pointer.
  7396. *
  7397. * This function is the HBA device-level interrupt handler to device with
  7398. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7399. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7400. * requires driver attention. This function invokes the slow-path interrupt
  7401. * attention handling function and fast-path interrupt attention handling
  7402. * function in turn to process the relevant HBA attention events. This
  7403. * function is called without any lock held. It gets the hbalock to access
  7404. * and update SLI data structures.
  7405. *
  7406. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7407. * returns IRQ_NONE.
  7408. **/
  7409. irqreturn_t
  7410. lpfc_sli_intr_handler(int irq, void *dev_id)
  7411. {
  7412. struct lpfc_hba *phba;
  7413. irqreturn_t sp_irq_rc, fp_irq_rc;
  7414. unsigned long status1, status2;
  7415. /*
  7416. * Get the driver's phba structure from the dev_id and
  7417. * assume the HBA is not interrupting.
  7418. */
  7419. phba = (struct lpfc_hba *) dev_id;
  7420. if (unlikely(!phba))
  7421. return IRQ_NONE;
  7422. /* Check device state for handling interrupt */
  7423. if (lpfc_intr_state_check(phba))
  7424. return IRQ_NONE;
  7425. spin_lock(&phba->hbalock);
  7426. phba->ha_copy = readl(phba->HAregaddr);
  7427. if (unlikely(!phba->ha_copy)) {
  7428. spin_unlock(&phba->hbalock);
  7429. return IRQ_NONE;
  7430. } else if (phba->ha_copy & HA_ERATT) {
  7431. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7432. /* ERATT polling has handled ERATT */
  7433. phba->ha_copy &= ~HA_ERATT;
  7434. else
  7435. /* Indicate interrupt handler handles ERATT */
  7436. phba->hba_flag |= HBA_ERATT_HANDLED;
  7437. }
  7438. /*
  7439. * If there is deferred error attention, do not check for any interrupt.
  7440. */
  7441. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7442. spin_unlock_irq(&phba->hbalock);
  7443. return IRQ_NONE;
  7444. }
  7445. /* Clear attention sources except link and error attentions */
  7446. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7447. readl(phba->HAregaddr); /* flush */
  7448. spin_unlock(&phba->hbalock);
  7449. /*
  7450. * Invokes slow-path host attention interrupt handling as appropriate.
  7451. */
  7452. /* status of events with mailbox and link attention */
  7453. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7454. /* status of events with ELS ring */
  7455. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7456. status2 >>= (4*LPFC_ELS_RING);
  7457. if (status1 || (status2 & HA_RXMASK))
  7458. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7459. else
  7460. sp_irq_rc = IRQ_NONE;
  7461. /*
  7462. * Invoke fast-path host attention interrupt handling as appropriate.
  7463. */
  7464. /* status of events with FCP ring */
  7465. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7466. status1 >>= (4*LPFC_FCP_RING);
  7467. /* status of events with extra ring */
  7468. if (phba->cfg_multi_ring_support == 2) {
  7469. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7470. status2 >>= (4*LPFC_EXTRA_RING);
  7471. } else
  7472. status2 = 0;
  7473. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7474. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7475. else
  7476. fp_irq_rc = IRQ_NONE;
  7477. /* Return device-level interrupt handling status */
  7478. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7479. } /* lpfc_sli_intr_handler */
  7480. /**
  7481. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7482. * @phba: pointer to lpfc hba data structure.
  7483. *
  7484. * This routine is invoked by the worker thread to process all the pending
  7485. * SLI4 FCP abort XRI events.
  7486. **/
  7487. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7488. {
  7489. struct lpfc_cq_event *cq_event;
  7490. /* First, declare the fcp xri abort event has been handled */
  7491. spin_lock_irq(&phba->hbalock);
  7492. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7493. spin_unlock_irq(&phba->hbalock);
  7494. /* Now, handle all the fcp xri abort events */
  7495. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7496. /* Get the first event from the head of the event queue */
  7497. spin_lock_irq(&phba->hbalock);
  7498. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7499. cq_event, struct lpfc_cq_event, list);
  7500. spin_unlock_irq(&phba->hbalock);
  7501. /* Notify aborted XRI for FCP work queue */
  7502. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7503. /* Free the event processed back to the free pool */
  7504. lpfc_sli4_cq_event_release(phba, cq_event);
  7505. }
  7506. }
  7507. /**
  7508. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7509. * @phba: pointer to lpfc hba data structure.
  7510. *
  7511. * This routine is invoked by the worker thread to process all the pending
  7512. * SLI4 els abort xri events.
  7513. **/
  7514. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7515. {
  7516. struct lpfc_cq_event *cq_event;
  7517. /* First, declare the els xri abort event has been handled */
  7518. spin_lock_irq(&phba->hbalock);
  7519. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7520. spin_unlock_irq(&phba->hbalock);
  7521. /* Now, handle all the els xri abort events */
  7522. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7523. /* Get the first event from the head of the event queue */
  7524. spin_lock_irq(&phba->hbalock);
  7525. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7526. cq_event, struct lpfc_cq_event, list);
  7527. spin_unlock_irq(&phba->hbalock);
  7528. /* Notify aborted XRI for ELS work queue */
  7529. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7530. /* Free the event processed back to the free pool */
  7531. lpfc_sli4_cq_event_release(phba, cq_event);
  7532. }
  7533. }
  7534. static void
  7535. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7536. struct lpfc_iocbq *pIocbOut,
  7537. struct lpfc_wcqe_complete *wcqe)
  7538. {
  7539. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7540. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7541. sizeof(struct lpfc_iocbq) - offset);
  7542. memset(&pIocbIn->sli4_info, 0,
  7543. sizeof(struct lpfc_sli4_rspiocb_info));
  7544. /* Map WCQE parameters into irspiocb parameters */
  7545. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7546. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7547. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7548. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7549. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7550. wcqe->total_data_placed;
  7551. else
  7552. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7553. else
  7554. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7555. /* Load in additional WCQE parameters */
  7556. pIocbIn->sli4_info.hw_status = bf_get(lpfc_wcqe_c_hw_status, wcqe);
  7557. pIocbIn->sli4_info.bfield = 0;
  7558. if (bf_get(lpfc_wcqe_c_xb, wcqe))
  7559. pIocbIn->sli4_info.bfield |= LPFC_XB;
  7560. if (bf_get(lpfc_wcqe_c_pv, wcqe)) {
  7561. pIocbIn->sli4_info.bfield |= LPFC_PV;
  7562. pIocbIn->sli4_info.priority =
  7563. bf_get(lpfc_wcqe_c_priority, wcqe);
  7564. }
  7565. }
  7566. /**
  7567. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7568. * @phba: Pointer to HBA context object.
  7569. * @cqe: Pointer to mailbox completion queue entry.
  7570. *
  7571. * This routine process a mailbox completion queue entry with asynchrous
  7572. * event.
  7573. *
  7574. * Return: true if work posted to worker thread, otherwise false.
  7575. **/
  7576. static bool
  7577. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7578. {
  7579. struct lpfc_cq_event *cq_event;
  7580. unsigned long iflags;
  7581. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7582. "0392 Async Event: word0:x%x, word1:x%x, "
  7583. "word2:x%x, word3:x%x\n", mcqe->word0,
  7584. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7585. /* Allocate a new internal CQ_EVENT entry */
  7586. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7587. if (!cq_event) {
  7588. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7589. "0394 Failed to allocate CQ_EVENT entry\n");
  7590. return false;
  7591. }
  7592. /* Move the CQE into an asynchronous event entry */
  7593. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7594. spin_lock_irqsave(&phba->hbalock, iflags);
  7595. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7596. /* Set the async event flag */
  7597. phba->hba_flag |= ASYNC_EVENT;
  7598. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7599. return true;
  7600. }
  7601. /**
  7602. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7603. * @phba: Pointer to HBA context object.
  7604. * @cqe: Pointer to mailbox completion queue entry.
  7605. *
  7606. * This routine process a mailbox completion queue entry with mailbox
  7607. * completion event.
  7608. *
  7609. * Return: true if work posted to worker thread, otherwise false.
  7610. **/
  7611. static bool
  7612. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7613. {
  7614. uint32_t mcqe_status;
  7615. MAILBOX_t *mbox, *pmbox;
  7616. struct lpfc_mqe *mqe;
  7617. struct lpfc_vport *vport;
  7618. struct lpfc_nodelist *ndlp;
  7619. struct lpfc_dmabuf *mp;
  7620. unsigned long iflags;
  7621. LPFC_MBOXQ_t *pmb;
  7622. bool workposted = false;
  7623. int rc;
  7624. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7625. if (!bf_get(lpfc_trailer_completed, mcqe))
  7626. goto out_no_mqe_complete;
  7627. /* Get the reference to the active mbox command */
  7628. spin_lock_irqsave(&phba->hbalock, iflags);
  7629. pmb = phba->sli.mbox_active;
  7630. if (unlikely(!pmb)) {
  7631. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7632. "1832 No pending MBOX command to handle\n");
  7633. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7634. goto out_no_mqe_complete;
  7635. }
  7636. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7637. mqe = &pmb->u.mqe;
  7638. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7639. mbox = phba->mbox;
  7640. vport = pmb->vport;
  7641. /* Reset heartbeat timer */
  7642. phba->last_completion_time = jiffies;
  7643. del_timer(&phba->sli.mbox_tmo);
  7644. /* Move mbox data to caller's mailbox region, do endian swapping */
  7645. if (pmb->mbox_cmpl && mbox)
  7646. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7647. /* Set the mailbox status with SLI4 range 0x4000 */
  7648. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7649. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7650. bf_set(lpfc_mqe_status, mqe,
  7651. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7652. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7653. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7654. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7655. "MBOX dflt rpi: status:x%x rpi:x%x",
  7656. mcqe_status,
  7657. pmbox->un.varWords[0], 0);
  7658. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7659. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7660. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7661. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7662. * RID of the PPI using the same mbox buffer.
  7663. */
  7664. lpfc_unreg_login(phba, vport->vpi,
  7665. pmbox->un.varWords[0], pmb);
  7666. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7667. pmb->context1 = mp;
  7668. pmb->context2 = ndlp;
  7669. pmb->vport = vport;
  7670. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7671. if (rc != MBX_BUSY)
  7672. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7673. LOG_SLI, "0385 rc should "
  7674. "have been MBX_BUSY\n");
  7675. if (rc != MBX_NOT_FINISHED)
  7676. goto send_current_mbox;
  7677. }
  7678. }
  7679. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7680. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7681. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7682. /* There is mailbox completion work to do */
  7683. spin_lock_irqsave(&phba->hbalock, iflags);
  7684. __lpfc_mbox_cmpl_put(phba, pmb);
  7685. phba->work_ha |= HA_MBATT;
  7686. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7687. workposted = true;
  7688. send_current_mbox:
  7689. spin_lock_irqsave(&phba->hbalock, iflags);
  7690. /* Release the mailbox command posting token */
  7691. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7692. /* Setting active mailbox pointer need to be in sync to flag clear */
  7693. phba->sli.mbox_active = NULL;
  7694. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7695. /* Wake up worker thread to post the next pending mailbox command */
  7696. lpfc_worker_wake_up(phba);
  7697. out_no_mqe_complete:
  7698. if (bf_get(lpfc_trailer_consumed, mcqe))
  7699. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7700. return workposted;
  7701. }
  7702. /**
  7703. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7704. * @phba: Pointer to HBA context object.
  7705. * @cqe: Pointer to mailbox completion queue entry.
  7706. *
  7707. * This routine process a mailbox completion queue entry, it invokes the
  7708. * proper mailbox complete handling or asynchrous event handling routine
  7709. * according to the MCQE's async bit.
  7710. *
  7711. * Return: true if work posted to worker thread, otherwise false.
  7712. **/
  7713. static bool
  7714. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7715. {
  7716. struct lpfc_mcqe mcqe;
  7717. bool workposted;
  7718. /* Copy the mailbox MCQE and convert endian order as needed */
  7719. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7720. /* Invoke the proper event handling routine */
  7721. if (!bf_get(lpfc_trailer_async, &mcqe))
  7722. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7723. else
  7724. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7725. return workposted;
  7726. }
  7727. /**
  7728. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7729. * @phba: Pointer to HBA context object.
  7730. * @wcqe: Pointer to work-queue completion queue entry.
  7731. *
  7732. * This routine handles an ELS work-queue completion event.
  7733. *
  7734. * Return: true if work posted to worker thread, otherwise false.
  7735. **/
  7736. static bool
  7737. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7738. struct lpfc_wcqe_complete *wcqe)
  7739. {
  7740. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7741. struct lpfc_iocbq *cmdiocbq;
  7742. struct lpfc_iocbq *irspiocbq;
  7743. unsigned long iflags;
  7744. bool workposted = false;
  7745. spin_lock_irqsave(&phba->hbalock, iflags);
  7746. pring->stats.iocb_event++;
  7747. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7748. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7749. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7750. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7751. if (unlikely(!cmdiocbq)) {
  7752. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7753. "0386 ELS complete with no corresponding "
  7754. "cmdiocb: iotag (%d)\n",
  7755. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7756. return workposted;
  7757. }
  7758. /* Fake the irspiocbq and copy necessary response information */
  7759. irspiocbq = lpfc_sli_get_iocbq(phba);
  7760. if (!irspiocbq) {
  7761. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7762. "0387 Failed to allocate an iocbq\n");
  7763. return workposted;
  7764. }
  7765. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7766. /* Add the irspiocb to the response IOCB work list */
  7767. spin_lock_irqsave(&phba->hbalock, iflags);
  7768. list_add_tail(&irspiocbq->list, &phba->sli4_hba.sp_rspiocb_work_queue);
  7769. /* Indicate ELS ring attention */
  7770. phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
  7771. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7772. workposted = true;
  7773. return workposted;
  7774. }
  7775. /**
  7776. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7777. * @phba: Pointer to HBA context object.
  7778. * @wcqe: Pointer to work-queue completion queue entry.
  7779. *
  7780. * This routine handles slow-path WQ entry comsumed event by invoking the
  7781. * proper WQ release routine to the slow-path WQ.
  7782. **/
  7783. static void
  7784. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7785. struct lpfc_wcqe_release *wcqe)
  7786. {
  7787. /* Check for the slow-path ELS work queue */
  7788. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7789. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7790. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7791. else
  7792. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7793. "2579 Slow-path wqe consume event carries "
  7794. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7795. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7796. phba->sli4_hba.els_wq->queue_id);
  7797. }
  7798. /**
  7799. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7800. * @phba: Pointer to HBA context object.
  7801. * @cq: Pointer to a WQ completion queue.
  7802. * @wcqe: Pointer to work-queue completion queue entry.
  7803. *
  7804. * This routine handles an XRI abort event.
  7805. *
  7806. * Return: true if work posted to worker thread, otherwise false.
  7807. **/
  7808. static bool
  7809. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7810. struct lpfc_queue *cq,
  7811. struct sli4_wcqe_xri_aborted *wcqe)
  7812. {
  7813. bool workposted = false;
  7814. struct lpfc_cq_event *cq_event;
  7815. unsigned long iflags;
  7816. /* Allocate a new internal CQ_EVENT entry */
  7817. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7818. if (!cq_event) {
  7819. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7820. "0602 Failed to allocate CQ_EVENT entry\n");
  7821. return false;
  7822. }
  7823. /* Move the CQE into the proper xri abort event list */
  7824. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7825. switch (cq->subtype) {
  7826. case LPFC_FCP:
  7827. spin_lock_irqsave(&phba->hbalock, iflags);
  7828. list_add_tail(&cq_event->list,
  7829. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7830. /* Set the fcp xri abort event flag */
  7831. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7832. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7833. workposted = true;
  7834. break;
  7835. case LPFC_ELS:
  7836. spin_lock_irqsave(&phba->hbalock, iflags);
  7837. list_add_tail(&cq_event->list,
  7838. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7839. /* Set the els xri abort event flag */
  7840. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7841. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7842. workposted = true;
  7843. break;
  7844. default:
  7845. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7846. "0603 Invalid work queue CQE subtype (x%x)\n",
  7847. cq->subtype);
  7848. workposted = false;
  7849. break;
  7850. }
  7851. return workposted;
  7852. }
  7853. /**
  7854. * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry
  7855. * @phba: Pointer to HBA context object.
  7856. * @cq: Pointer to the completion queue.
  7857. * @wcqe: Pointer to a completion queue entry.
  7858. *
  7859. * This routine process a slow-path work-queue completion queue entry.
  7860. *
  7861. * Return: true if work posted to worker thread, otherwise false.
  7862. **/
  7863. static bool
  7864. lpfc_sli4_sp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7865. struct lpfc_cqe *cqe)
  7866. {
  7867. struct lpfc_wcqe_complete wcqe;
  7868. bool workposted = false;
  7869. /* Copy the work queue CQE and convert endian order if needed */
  7870. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  7871. /* Check and process for different type of WCQE and dispatch */
  7872. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  7873. case CQE_CODE_COMPL_WQE:
  7874. /* Process the WQ complete event */
  7875. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7876. (struct lpfc_wcqe_complete *)&wcqe);
  7877. break;
  7878. case CQE_CODE_RELEASE_WQE:
  7879. /* Process the WQ release event */
  7880. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7881. (struct lpfc_wcqe_release *)&wcqe);
  7882. break;
  7883. case CQE_CODE_XRI_ABORTED:
  7884. /* Process the WQ XRI abort event */
  7885. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7886. (struct sli4_wcqe_xri_aborted *)&wcqe);
  7887. break;
  7888. default:
  7889. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7890. "0388 Not a valid WCQE code: x%x\n",
  7891. bf_get(lpfc_wcqe_c_code, &wcqe));
  7892. break;
  7893. }
  7894. return workposted;
  7895. }
  7896. /**
  7897. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7898. * @phba: Pointer to HBA context object.
  7899. * @rcqe: Pointer to receive-queue completion queue entry.
  7900. *
  7901. * This routine process a receive-queue completion queue entry.
  7902. *
  7903. * Return: true if work posted to worker thread, otherwise false.
  7904. **/
  7905. static bool
  7906. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7907. {
  7908. struct lpfc_rcqe rcqe;
  7909. bool workposted = false;
  7910. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7911. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7912. struct hbq_dmabuf *dma_buf;
  7913. uint32_t status;
  7914. unsigned long iflags;
  7915. /* Copy the receive queue CQE and convert endian order if needed */
  7916. lpfc_sli_pcimem_bcopy(cqe, &rcqe, sizeof(struct lpfc_rcqe));
  7917. lpfc_sli4_rq_release(hrq, drq);
  7918. if (bf_get(lpfc_rcqe_code, &rcqe) != CQE_CODE_RECEIVE)
  7919. goto out;
  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. spin_lock_irqsave(&phba->hbalock, iflags);
  7929. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7930. if (!dma_buf) {
  7931. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7932. goto out;
  7933. }
  7934. memcpy(&dma_buf->rcqe, &rcqe, sizeof(rcqe));
  7935. /* save off the frame for the word thread to process */
  7936. list_add_tail(&dma_buf->dbuf.list, &phba->rb_pend_list);
  7937. /* Frame received */
  7938. phba->hba_flag |= HBA_RECEIVE_BUFFER;
  7939. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7940. workposted = true;
  7941. break;
  7942. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7943. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7944. /* Post more buffers if possible */
  7945. spin_lock_irqsave(&phba->hbalock, iflags);
  7946. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7947. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7948. workposted = true;
  7949. break;
  7950. }
  7951. out:
  7952. return workposted;
  7953. }
  7954. /**
  7955. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  7956. * @phba: Pointer to HBA context object.
  7957. * @eqe: Pointer to fast-path event queue entry.
  7958. *
  7959. * This routine process a event queue entry from the slow-path event queue.
  7960. * It will check the MajorCode and MinorCode to determine this is for a
  7961. * completion event on a completion queue, if not, an error shall be logged
  7962. * and just return. Otherwise, it will get to the corresponding completion
  7963. * queue and process all the entries on that completion queue, rearm the
  7964. * completion queue, and then return.
  7965. *
  7966. **/
  7967. static void
  7968. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  7969. {
  7970. struct lpfc_queue *cq = NULL, *childq, *speq;
  7971. struct lpfc_cqe *cqe;
  7972. bool workposted = false;
  7973. int ecount = 0;
  7974. uint16_t cqid;
  7975. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  7976. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  7977. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7978. "0359 Not a valid slow-path completion "
  7979. "event: majorcode=x%x, minorcode=x%x\n",
  7980. bf_get(lpfc_eqe_major_code, eqe),
  7981. bf_get(lpfc_eqe_minor_code, eqe));
  7982. return;
  7983. }
  7984. /* Get the reference to the corresponding CQ */
  7985. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  7986. /* Search for completion queue pointer matching this cqid */
  7987. speq = phba->sli4_hba.sp_eq;
  7988. list_for_each_entry(childq, &speq->child_list, list) {
  7989. if (childq->queue_id == cqid) {
  7990. cq = childq;
  7991. break;
  7992. }
  7993. }
  7994. if (unlikely(!cq)) {
  7995. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7996. "0365 Slow-path CQ identifier (%d) does "
  7997. "not exist\n", cqid);
  7998. return;
  7999. }
  8000. /* Process all the entries to the CQ */
  8001. switch (cq->type) {
  8002. case LPFC_MCQ:
  8003. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8004. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8005. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8006. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8007. }
  8008. break;
  8009. case LPFC_WCQ:
  8010. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8011. workposted |= lpfc_sli4_sp_handle_wcqe(phba, cq, cqe);
  8012. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8013. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8014. }
  8015. break;
  8016. case LPFC_RCQ:
  8017. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8018. workposted |= lpfc_sli4_sp_handle_rcqe(phba, cqe);
  8019. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8020. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8021. }
  8022. break;
  8023. default:
  8024. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8025. "0370 Invalid completion queue type (%d)\n",
  8026. cq->type);
  8027. return;
  8028. }
  8029. /* Catch the no cq entry condition, log an error */
  8030. if (unlikely(ecount == 0))
  8031. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8032. "0371 No entry from the CQ: identifier "
  8033. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8034. /* In any case, flash and re-arm the RCQ */
  8035. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8036. /* wake up worker thread if there are works to be done */
  8037. if (workposted)
  8038. lpfc_worker_wake_up(phba);
  8039. }
  8040. /**
  8041. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8042. * @eqe: Pointer to fast-path completion queue entry.
  8043. *
  8044. * This routine process a fast-path work queue completion entry from fast-path
  8045. * event queue for FCP command response completion.
  8046. **/
  8047. static void
  8048. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8049. struct lpfc_wcqe_complete *wcqe)
  8050. {
  8051. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8052. struct lpfc_iocbq *cmdiocbq;
  8053. struct lpfc_iocbq irspiocbq;
  8054. unsigned long iflags;
  8055. spin_lock_irqsave(&phba->hbalock, iflags);
  8056. pring->stats.iocb_event++;
  8057. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8058. /* Check for response status */
  8059. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8060. /* If resource errors reported from HBA, reduce queue
  8061. * depth of the SCSI device.
  8062. */
  8063. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8064. IOSTAT_LOCAL_REJECT) &&
  8065. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8066. phba->lpfc_rampdown_queue_depth(phba);
  8067. }
  8068. /* Log the error status */
  8069. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8070. "0373 FCP complete error: status=x%x, "
  8071. "hw_status=x%x, total_data_specified=%d, "
  8072. "parameter=x%x, word3=x%x\n",
  8073. bf_get(lpfc_wcqe_c_status, wcqe),
  8074. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8075. wcqe->total_data_placed, wcqe->parameter,
  8076. wcqe->word3);
  8077. }
  8078. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8079. spin_lock_irqsave(&phba->hbalock, iflags);
  8080. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8081. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8082. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8083. if (unlikely(!cmdiocbq)) {
  8084. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8085. "0374 FCP complete with no corresponding "
  8086. "cmdiocb: iotag (%d)\n",
  8087. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8088. return;
  8089. }
  8090. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8091. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8092. "0375 FCP cmdiocb not callback function "
  8093. "iotag: (%d)\n",
  8094. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8095. return;
  8096. }
  8097. /* Fake the irspiocb and copy necessary response information */
  8098. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8099. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8100. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8101. }
  8102. /**
  8103. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8104. * @phba: Pointer to HBA context object.
  8105. * @cq: Pointer to completion queue.
  8106. * @wcqe: Pointer to work-queue completion queue entry.
  8107. *
  8108. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8109. * proper WQ release routine to the slow-path WQ.
  8110. **/
  8111. static void
  8112. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8113. struct lpfc_wcqe_release *wcqe)
  8114. {
  8115. struct lpfc_queue *childwq;
  8116. bool wqid_matched = false;
  8117. uint16_t fcp_wqid;
  8118. /* Check for fast-path FCP work queue release */
  8119. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8120. list_for_each_entry(childwq, &cq->child_list, list) {
  8121. if (childwq->queue_id == fcp_wqid) {
  8122. lpfc_sli4_wq_release(childwq,
  8123. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8124. wqid_matched = true;
  8125. break;
  8126. }
  8127. }
  8128. /* Report warning log message if no match found */
  8129. if (wqid_matched != true)
  8130. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8131. "2580 Fast-path wqe consume event carries "
  8132. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8133. }
  8134. /**
  8135. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8136. * @cq: Pointer to the completion queue.
  8137. * @eqe: Pointer to fast-path completion queue entry.
  8138. *
  8139. * This routine process a fast-path work queue completion entry from fast-path
  8140. * event queue for FCP command response completion.
  8141. **/
  8142. static int
  8143. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8144. struct lpfc_cqe *cqe)
  8145. {
  8146. struct lpfc_wcqe_release wcqe;
  8147. bool workposted = false;
  8148. /* Copy the work queue CQE and convert endian order if needed */
  8149. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8150. /* Check and process for different type of WCQE and dispatch */
  8151. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8152. case CQE_CODE_COMPL_WQE:
  8153. /* Process the WQ complete event */
  8154. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8155. (struct lpfc_wcqe_complete *)&wcqe);
  8156. break;
  8157. case CQE_CODE_RELEASE_WQE:
  8158. /* Process the WQ release event */
  8159. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8160. (struct lpfc_wcqe_release *)&wcqe);
  8161. break;
  8162. case CQE_CODE_XRI_ABORTED:
  8163. /* Process the WQ XRI abort event */
  8164. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8165. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8166. break;
  8167. default:
  8168. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8169. "0144 Not a valid WCQE code: x%x\n",
  8170. bf_get(lpfc_wcqe_c_code, &wcqe));
  8171. break;
  8172. }
  8173. return workposted;
  8174. }
  8175. /**
  8176. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8177. * @phba: Pointer to HBA context object.
  8178. * @eqe: Pointer to fast-path event queue entry.
  8179. *
  8180. * This routine process a event queue entry from the fast-path event queue.
  8181. * It will check the MajorCode and MinorCode to determine this is for a
  8182. * completion event on a completion queue, if not, an error shall be logged
  8183. * and just return. Otherwise, it will get to the corresponding completion
  8184. * queue and process all the entries on the completion queue, rearm the
  8185. * completion queue, and then return.
  8186. **/
  8187. static void
  8188. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8189. uint32_t fcp_cqidx)
  8190. {
  8191. struct lpfc_queue *cq;
  8192. struct lpfc_cqe *cqe;
  8193. bool workposted = false;
  8194. uint16_t cqid;
  8195. int ecount = 0;
  8196. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8197. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8198. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8199. "0366 Not a valid fast-path completion "
  8200. "event: majorcode=x%x, minorcode=x%x\n",
  8201. bf_get(lpfc_eqe_major_code, eqe),
  8202. bf_get(lpfc_eqe_minor_code, eqe));
  8203. return;
  8204. }
  8205. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8206. if (unlikely(!cq)) {
  8207. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8208. "0367 Fast-path completion queue does not "
  8209. "exist\n");
  8210. return;
  8211. }
  8212. /* Get the reference to the corresponding CQ */
  8213. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8214. if (unlikely(cqid != cq->queue_id)) {
  8215. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8216. "0368 Miss-matched fast-path completion "
  8217. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8218. cqid, cq->queue_id);
  8219. return;
  8220. }
  8221. /* Process all the entries to the CQ */
  8222. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8223. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8224. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8225. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8226. }
  8227. /* Catch the no cq entry condition */
  8228. if (unlikely(ecount == 0))
  8229. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8230. "0369 No entry from fast-path completion "
  8231. "queue fcpcqid=%d\n", cq->queue_id);
  8232. /* In any case, flash and re-arm the CQ */
  8233. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8234. /* wake up worker thread if there are works to be done */
  8235. if (workposted)
  8236. lpfc_worker_wake_up(phba);
  8237. }
  8238. static void
  8239. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8240. {
  8241. struct lpfc_eqe *eqe;
  8242. /* walk all the EQ entries and drop on the floor */
  8243. while ((eqe = lpfc_sli4_eq_get(eq)))
  8244. ;
  8245. /* Clear and re-arm the EQ */
  8246. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8247. }
  8248. /**
  8249. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8250. * @irq: Interrupt number.
  8251. * @dev_id: The device context pointer.
  8252. *
  8253. * This function is directly called from the PCI layer as an interrupt
  8254. * service routine when device with SLI-4 interface spec is enabled with
  8255. * MSI-X multi-message interrupt mode and there are slow-path events in
  8256. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8257. * interrupt mode, this function is called as part of the device-level
  8258. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8259. * undergoing initialization, the interrupt handler will not process the
  8260. * interrupt. The link attention and ELS ring attention events are handled
  8261. * by the worker thread. The interrupt handler signals the worker thread
  8262. * and returns for these events. This function is called without any lock
  8263. * held. It gets the hbalock to access and update SLI data structures.
  8264. *
  8265. * This function returns IRQ_HANDLED when interrupt is handled else it
  8266. * returns IRQ_NONE.
  8267. **/
  8268. irqreturn_t
  8269. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8270. {
  8271. struct lpfc_hba *phba;
  8272. struct lpfc_queue *speq;
  8273. struct lpfc_eqe *eqe;
  8274. unsigned long iflag;
  8275. int ecount = 0;
  8276. /*
  8277. * Get the driver's phba structure from the dev_id
  8278. */
  8279. phba = (struct lpfc_hba *)dev_id;
  8280. if (unlikely(!phba))
  8281. return IRQ_NONE;
  8282. /* Get to the EQ struct associated with this vector */
  8283. speq = phba->sli4_hba.sp_eq;
  8284. /* Check device state for handling interrupt */
  8285. if (unlikely(lpfc_intr_state_check(phba))) {
  8286. /* Check again for link_state with lock held */
  8287. spin_lock_irqsave(&phba->hbalock, iflag);
  8288. if (phba->link_state < LPFC_LINK_DOWN)
  8289. /* Flush, clear interrupt, and rearm the EQ */
  8290. lpfc_sli4_eq_flush(phba, speq);
  8291. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8292. return IRQ_NONE;
  8293. }
  8294. /*
  8295. * Process all the event on FCP slow-path EQ
  8296. */
  8297. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8298. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8299. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8300. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8301. }
  8302. /* Always clear and re-arm the slow-path EQ */
  8303. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8304. /* Catch the no cq entry condition */
  8305. if (unlikely(ecount == 0)) {
  8306. if (phba->intr_type == MSIX)
  8307. /* MSI-X treated interrupt served as no EQ share INT */
  8308. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8309. "0357 MSI-X interrupt with no EQE\n");
  8310. else
  8311. /* Non MSI-X treated on interrupt as EQ share INT */
  8312. return IRQ_NONE;
  8313. }
  8314. return IRQ_HANDLED;
  8315. } /* lpfc_sli4_sp_intr_handler */
  8316. /**
  8317. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8318. * @irq: Interrupt number.
  8319. * @dev_id: The device context pointer.
  8320. *
  8321. * This function is directly called from the PCI layer as an interrupt
  8322. * service routine when device with SLI-4 interface spec is enabled with
  8323. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8324. * ring event in the HBA. However, when the device is enabled with either
  8325. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8326. * device-level interrupt handler. When the PCI slot is in error recovery
  8327. * or the HBA is undergoing initialization, the interrupt handler will not
  8328. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8329. * the intrrupt context. This function is called without any lock held.
  8330. * It gets the hbalock to access and update SLI data structures. Note that,
  8331. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8332. * equal to that of FCP CQ index.
  8333. *
  8334. * This function returns IRQ_HANDLED when interrupt is handled else it
  8335. * returns IRQ_NONE.
  8336. **/
  8337. irqreturn_t
  8338. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8339. {
  8340. struct lpfc_hba *phba;
  8341. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8342. struct lpfc_queue *fpeq;
  8343. struct lpfc_eqe *eqe;
  8344. unsigned long iflag;
  8345. int ecount = 0;
  8346. uint32_t fcp_eqidx;
  8347. /* Get the driver's phba structure from the dev_id */
  8348. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8349. phba = fcp_eq_hdl->phba;
  8350. fcp_eqidx = fcp_eq_hdl->idx;
  8351. if (unlikely(!phba))
  8352. return IRQ_NONE;
  8353. /* Get to the EQ struct associated with this vector */
  8354. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8355. /* Check device state for handling interrupt */
  8356. if (unlikely(lpfc_intr_state_check(phba))) {
  8357. /* Check again for link_state with lock held */
  8358. spin_lock_irqsave(&phba->hbalock, iflag);
  8359. if (phba->link_state < LPFC_LINK_DOWN)
  8360. /* Flush, clear interrupt, and rearm the EQ */
  8361. lpfc_sli4_eq_flush(phba, fpeq);
  8362. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8363. return IRQ_NONE;
  8364. }
  8365. /*
  8366. * Process all the event on FCP fast-path EQ
  8367. */
  8368. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8369. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8370. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8371. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8372. }
  8373. /* Always clear and re-arm the fast-path EQ */
  8374. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8375. if (unlikely(ecount == 0)) {
  8376. if (phba->intr_type == MSIX)
  8377. /* MSI-X treated interrupt served as no EQ share INT */
  8378. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8379. "0358 MSI-X interrupt with no EQE\n");
  8380. else
  8381. /* Non MSI-X treated on interrupt as EQ share INT */
  8382. return IRQ_NONE;
  8383. }
  8384. return IRQ_HANDLED;
  8385. } /* lpfc_sli4_fp_intr_handler */
  8386. /**
  8387. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8388. * @irq: Interrupt number.
  8389. * @dev_id: The device context pointer.
  8390. *
  8391. * This function is the device-level interrupt handler to device with SLI-4
  8392. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8393. * interrupt mode is enabled and there is an event in the HBA which requires
  8394. * driver attention. This function invokes the slow-path interrupt attention
  8395. * handling function and fast-path interrupt attention handling function in
  8396. * turn to process the relevant HBA attention events. This function is called
  8397. * without any lock held. It gets the hbalock to access and update SLI data
  8398. * structures.
  8399. *
  8400. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8401. * returns IRQ_NONE.
  8402. **/
  8403. irqreturn_t
  8404. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8405. {
  8406. struct lpfc_hba *phba;
  8407. irqreturn_t sp_irq_rc, fp_irq_rc;
  8408. bool fp_handled = false;
  8409. uint32_t fcp_eqidx;
  8410. /* Get the driver's phba structure from the dev_id */
  8411. phba = (struct lpfc_hba *)dev_id;
  8412. if (unlikely(!phba))
  8413. return IRQ_NONE;
  8414. /*
  8415. * Invokes slow-path host attention interrupt handling as appropriate.
  8416. */
  8417. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8418. /*
  8419. * Invoke fast-path host attention interrupt handling as appropriate.
  8420. */
  8421. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8422. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8423. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8424. if (fp_irq_rc == IRQ_HANDLED)
  8425. fp_handled |= true;
  8426. }
  8427. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8428. } /* lpfc_sli4_intr_handler */
  8429. /**
  8430. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8431. * @queue: The queue structure to free.
  8432. *
  8433. * This function frees a queue structure and the DMAable memeory used for
  8434. * the host resident queue. This function must be called after destroying the
  8435. * queue on the HBA.
  8436. **/
  8437. void
  8438. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8439. {
  8440. struct lpfc_dmabuf *dmabuf;
  8441. if (!queue)
  8442. return;
  8443. while (!list_empty(&queue->page_list)) {
  8444. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8445. list);
  8446. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8447. dmabuf->virt, dmabuf->phys);
  8448. kfree(dmabuf);
  8449. }
  8450. kfree(queue);
  8451. return;
  8452. }
  8453. /**
  8454. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8455. * @phba: The HBA that this queue is being created on.
  8456. * @entry_size: The size of each queue entry for this queue.
  8457. * @entry count: The number of entries that this queue will handle.
  8458. *
  8459. * This function allocates a queue structure and the DMAable memory used for
  8460. * the host resident queue. This function must be called before creating the
  8461. * queue on the HBA.
  8462. **/
  8463. struct lpfc_queue *
  8464. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8465. uint32_t entry_count)
  8466. {
  8467. struct lpfc_queue *queue;
  8468. struct lpfc_dmabuf *dmabuf;
  8469. int x, total_qe_count;
  8470. void *dma_pointer;
  8471. queue = kzalloc(sizeof(struct lpfc_queue) +
  8472. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8473. if (!queue)
  8474. return NULL;
  8475. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8476. INIT_LIST_HEAD(&queue->list);
  8477. INIT_LIST_HEAD(&queue->page_list);
  8478. INIT_LIST_HEAD(&queue->child_list);
  8479. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8480. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8481. if (!dmabuf)
  8482. goto out_fail;
  8483. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8484. PAGE_SIZE, &dmabuf->phys,
  8485. GFP_KERNEL);
  8486. if (!dmabuf->virt) {
  8487. kfree(dmabuf);
  8488. goto out_fail;
  8489. }
  8490. memset(dmabuf->virt, 0, PAGE_SIZE);
  8491. dmabuf->buffer_tag = x;
  8492. list_add_tail(&dmabuf->list, &queue->page_list);
  8493. /* initialize queue's entry array */
  8494. dma_pointer = dmabuf->virt;
  8495. for (; total_qe_count < entry_count &&
  8496. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8497. total_qe_count++, dma_pointer += entry_size) {
  8498. queue->qe[total_qe_count].address = dma_pointer;
  8499. }
  8500. }
  8501. queue->entry_size = entry_size;
  8502. queue->entry_count = entry_count;
  8503. queue->phba = phba;
  8504. return queue;
  8505. out_fail:
  8506. lpfc_sli4_queue_free(queue);
  8507. return NULL;
  8508. }
  8509. /**
  8510. * lpfc_eq_create - Create an Event Queue on the HBA
  8511. * @phba: HBA structure that indicates port to create a queue on.
  8512. * @eq: The queue structure to use to create the event queue.
  8513. * @imax: The maximum interrupt per second limit.
  8514. *
  8515. * This function creates an event queue, as detailed in @eq, on a port,
  8516. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8517. *
  8518. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8519. * is used to get the entry count and entry size that are necessary to
  8520. * determine the number of pages to allocate and use for this queue. This
  8521. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8522. * event queue. This function is asynchronous and will wait for the mailbox
  8523. * command to finish before continuing.
  8524. *
  8525. * On success this function will return a zero. If unable to allocate enough
  8526. * memory this function will return ENOMEM. If the queue create mailbox command
  8527. * fails this function will return ENXIO.
  8528. **/
  8529. uint32_t
  8530. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8531. {
  8532. struct lpfc_mbx_eq_create *eq_create;
  8533. LPFC_MBOXQ_t *mbox;
  8534. int rc, length, status = 0;
  8535. struct lpfc_dmabuf *dmabuf;
  8536. uint32_t shdr_status, shdr_add_status;
  8537. union lpfc_sli4_cfg_shdr *shdr;
  8538. uint16_t dmult;
  8539. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8540. if (!mbox)
  8541. return -ENOMEM;
  8542. length = (sizeof(struct lpfc_mbx_eq_create) -
  8543. sizeof(struct lpfc_sli4_cfg_mhdr));
  8544. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8545. LPFC_MBOX_OPCODE_EQ_CREATE,
  8546. length, LPFC_SLI4_MBX_EMBED);
  8547. eq_create = &mbox->u.mqe.un.eq_create;
  8548. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8549. eq->page_count);
  8550. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8551. LPFC_EQE_SIZE);
  8552. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8553. /* Calculate delay multiper from maximum interrupt per second */
  8554. dmult = LPFC_DMULT_CONST/imax - 1;
  8555. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8556. dmult);
  8557. switch (eq->entry_count) {
  8558. default:
  8559. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8560. "0360 Unsupported EQ count. (%d)\n",
  8561. eq->entry_count);
  8562. if (eq->entry_count < 256)
  8563. return -EINVAL;
  8564. /* otherwise default to smallest count (drop through) */
  8565. case 256:
  8566. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8567. LPFC_EQ_CNT_256);
  8568. break;
  8569. case 512:
  8570. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8571. LPFC_EQ_CNT_512);
  8572. break;
  8573. case 1024:
  8574. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8575. LPFC_EQ_CNT_1024);
  8576. break;
  8577. case 2048:
  8578. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8579. LPFC_EQ_CNT_2048);
  8580. break;
  8581. case 4096:
  8582. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8583. LPFC_EQ_CNT_4096);
  8584. break;
  8585. }
  8586. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8587. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8588. putPaddrLow(dmabuf->phys);
  8589. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8590. putPaddrHigh(dmabuf->phys);
  8591. }
  8592. mbox->vport = phba->pport;
  8593. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8594. mbox->context1 = NULL;
  8595. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8596. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8597. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8598. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8599. if (shdr_status || shdr_add_status || rc) {
  8600. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8601. "2500 EQ_CREATE mailbox failed with "
  8602. "status x%x add_status x%x, mbx status x%x\n",
  8603. shdr_status, shdr_add_status, rc);
  8604. status = -ENXIO;
  8605. }
  8606. eq->type = LPFC_EQ;
  8607. eq->subtype = LPFC_NONE;
  8608. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8609. if (eq->queue_id == 0xFFFF)
  8610. status = -ENXIO;
  8611. eq->host_index = 0;
  8612. eq->hba_index = 0;
  8613. if (rc != MBX_TIMEOUT)
  8614. mempool_free(mbox, phba->mbox_mem_pool);
  8615. return status;
  8616. }
  8617. /**
  8618. * lpfc_cq_create - Create a Completion Queue on the HBA
  8619. * @phba: HBA structure that indicates port to create a queue on.
  8620. * @cq: The queue structure to use to create the completion queue.
  8621. * @eq: The event queue to bind this completion queue to.
  8622. *
  8623. * This function creates a completion queue, as detailed in @wq, on a port,
  8624. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8625. *
  8626. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8627. * is used to get the entry count and entry size that are necessary to
  8628. * determine the number of pages to allocate and use for this queue. The @eq
  8629. * is used to indicate which event queue to bind this completion queue to. This
  8630. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8631. * completion queue. This function is asynchronous and will wait for the mailbox
  8632. * command to finish before continuing.
  8633. *
  8634. * On success this function will return a zero. If unable to allocate enough
  8635. * memory this function will return ENOMEM. If the queue create mailbox command
  8636. * fails this function will return ENXIO.
  8637. **/
  8638. uint32_t
  8639. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8640. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8641. {
  8642. struct lpfc_mbx_cq_create *cq_create;
  8643. struct lpfc_dmabuf *dmabuf;
  8644. LPFC_MBOXQ_t *mbox;
  8645. int rc, length, status = 0;
  8646. uint32_t shdr_status, shdr_add_status;
  8647. union lpfc_sli4_cfg_shdr *shdr;
  8648. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8649. if (!mbox)
  8650. return -ENOMEM;
  8651. length = (sizeof(struct lpfc_mbx_cq_create) -
  8652. sizeof(struct lpfc_sli4_cfg_mhdr));
  8653. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8654. LPFC_MBOX_OPCODE_CQ_CREATE,
  8655. length, LPFC_SLI4_MBX_EMBED);
  8656. cq_create = &mbox->u.mqe.un.cq_create;
  8657. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8658. cq->page_count);
  8659. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8660. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8661. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8662. switch (cq->entry_count) {
  8663. default:
  8664. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8665. "0361 Unsupported CQ count. (%d)\n",
  8666. cq->entry_count);
  8667. if (cq->entry_count < 256)
  8668. return -EINVAL;
  8669. /* otherwise default to smallest count (drop through) */
  8670. case 256:
  8671. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8672. LPFC_CQ_CNT_256);
  8673. break;
  8674. case 512:
  8675. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8676. LPFC_CQ_CNT_512);
  8677. break;
  8678. case 1024:
  8679. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8680. LPFC_CQ_CNT_1024);
  8681. break;
  8682. }
  8683. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8684. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8685. putPaddrLow(dmabuf->phys);
  8686. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8687. putPaddrHigh(dmabuf->phys);
  8688. }
  8689. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8690. /* The IOCTL status is embedded in the mailbox subheader. */
  8691. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8692. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8693. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8694. if (shdr_status || shdr_add_status || rc) {
  8695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8696. "2501 CQ_CREATE mailbox failed with "
  8697. "status x%x add_status x%x, mbx status x%x\n",
  8698. shdr_status, shdr_add_status, rc);
  8699. status = -ENXIO;
  8700. goto out;
  8701. }
  8702. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8703. if (cq->queue_id == 0xFFFF) {
  8704. status = -ENXIO;
  8705. goto out;
  8706. }
  8707. /* link the cq onto the parent eq child list */
  8708. list_add_tail(&cq->list, &eq->child_list);
  8709. /* Set up completion queue's type and subtype */
  8710. cq->type = type;
  8711. cq->subtype = subtype;
  8712. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8713. cq->host_index = 0;
  8714. cq->hba_index = 0;
  8715. out:
  8716. if (rc != MBX_TIMEOUT)
  8717. mempool_free(mbox, phba->mbox_mem_pool);
  8718. return status;
  8719. }
  8720. /**
  8721. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8722. * @phba: HBA structure that indicates port to create a queue on.
  8723. * @mq: The queue structure to use to create the mailbox queue.
  8724. *
  8725. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8726. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8727. *
  8728. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8729. * is used to get the entry count and entry size that are necessary to
  8730. * determine the number of pages to allocate and use for this queue. This
  8731. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8732. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8733. * command to finish before continuing.
  8734. *
  8735. * On success this function will return a zero. If unable to allocate enough
  8736. * memory this function will return ENOMEM. If the queue create mailbox command
  8737. * fails this function will return ENXIO.
  8738. **/
  8739. uint32_t
  8740. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8741. struct lpfc_queue *cq, uint32_t subtype)
  8742. {
  8743. struct lpfc_mbx_mq_create *mq_create;
  8744. struct lpfc_dmabuf *dmabuf;
  8745. LPFC_MBOXQ_t *mbox;
  8746. int rc, length, status = 0;
  8747. uint32_t shdr_status, shdr_add_status;
  8748. union lpfc_sli4_cfg_shdr *shdr;
  8749. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8750. if (!mbox)
  8751. return -ENOMEM;
  8752. length = (sizeof(struct lpfc_mbx_mq_create) -
  8753. sizeof(struct lpfc_sli4_cfg_mhdr));
  8754. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8755. LPFC_MBOX_OPCODE_MQ_CREATE,
  8756. length, LPFC_SLI4_MBX_EMBED);
  8757. mq_create = &mbox->u.mqe.un.mq_create;
  8758. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8759. mq->page_count);
  8760. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8761. cq->queue_id);
  8762. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8763. switch (mq->entry_count) {
  8764. default:
  8765. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8766. "0362 Unsupported MQ count. (%d)\n",
  8767. mq->entry_count);
  8768. if (mq->entry_count < 16)
  8769. return -EINVAL;
  8770. /* otherwise default to smallest count (drop through) */
  8771. case 16:
  8772. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8773. LPFC_MQ_CNT_16);
  8774. break;
  8775. case 32:
  8776. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8777. LPFC_MQ_CNT_32);
  8778. break;
  8779. case 64:
  8780. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8781. LPFC_MQ_CNT_64);
  8782. break;
  8783. case 128:
  8784. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8785. LPFC_MQ_CNT_128);
  8786. break;
  8787. }
  8788. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8789. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8790. putPaddrLow(dmabuf->phys);
  8791. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8792. putPaddrHigh(dmabuf->phys);
  8793. }
  8794. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8795. /* The IOCTL status is embedded in the mailbox subheader. */
  8796. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8797. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8798. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8799. if (shdr_status || shdr_add_status || rc) {
  8800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8801. "2502 MQ_CREATE mailbox failed with "
  8802. "status x%x add_status x%x, mbx status x%x\n",
  8803. shdr_status, shdr_add_status, rc);
  8804. status = -ENXIO;
  8805. goto out;
  8806. }
  8807. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8808. if (mq->queue_id == 0xFFFF) {
  8809. status = -ENXIO;
  8810. goto out;
  8811. }
  8812. mq->type = LPFC_MQ;
  8813. mq->subtype = subtype;
  8814. mq->host_index = 0;
  8815. mq->hba_index = 0;
  8816. /* link the mq onto the parent cq child list */
  8817. list_add_tail(&mq->list, &cq->child_list);
  8818. out:
  8819. if (rc != MBX_TIMEOUT)
  8820. mempool_free(mbox, phba->mbox_mem_pool);
  8821. return status;
  8822. }
  8823. /**
  8824. * lpfc_wq_create - Create a Work Queue on the HBA
  8825. * @phba: HBA structure that indicates port to create a queue on.
  8826. * @wq: The queue structure to use to create the work queue.
  8827. * @cq: The completion queue to bind this work queue to.
  8828. * @subtype: The subtype of the work queue indicating its functionality.
  8829. *
  8830. * This function creates a work queue, as detailed in @wq, on a port, described
  8831. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8832. *
  8833. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8834. * is used to get the entry count and entry size that are necessary to
  8835. * determine the number of pages to allocate and use for this queue. The @cq
  8836. * is used to indicate which completion queue to bind this work queue to. This
  8837. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8838. * work queue. This function is asynchronous and will wait for the mailbox
  8839. * command to finish before continuing.
  8840. *
  8841. * On success this function will return a zero. If unable to allocate enough
  8842. * memory this function will return ENOMEM. If the queue create mailbox command
  8843. * fails this function will return ENXIO.
  8844. **/
  8845. uint32_t
  8846. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8847. struct lpfc_queue *cq, uint32_t subtype)
  8848. {
  8849. struct lpfc_mbx_wq_create *wq_create;
  8850. struct lpfc_dmabuf *dmabuf;
  8851. LPFC_MBOXQ_t *mbox;
  8852. int rc, length, status = 0;
  8853. uint32_t shdr_status, shdr_add_status;
  8854. union lpfc_sli4_cfg_shdr *shdr;
  8855. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8856. if (!mbox)
  8857. return -ENOMEM;
  8858. length = (sizeof(struct lpfc_mbx_wq_create) -
  8859. sizeof(struct lpfc_sli4_cfg_mhdr));
  8860. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8861. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8862. length, LPFC_SLI4_MBX_EMBED);
  8863. wq_create = &mbox->u.mqe.un.wq_create;
  8864. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8865. wq->page_count);
  8866. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8867. cq->queue_id);
  8868. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8869. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8870. putPaddrLow(dmabuf->phys);
  8871. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8872. putPaddrHigh(dmabuf->phys);
  8873. }
  8874. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8875. /* The IOCTL status is embedded in the mailbox subheader. */
  8876. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8877. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8878. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8879. if (shdr_status || shdr_add_status || rc) {
  8880. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8881. "2503 WQ_CREATE mailbox failed with "
  8882. "status x%x add_status x%x, mbx status x%x\n",
  8883. shdr_status, shdr_add_status, rc);
  8884. status = -ENXIO;
  8885. goto out;
  8886. }
  8887. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8888. if (wq->queue_id == 0xFFFF) {
  8889. status = -ENXIO;
  8890. goto out;
  8891. }
  8892. wq->type = LPFC_WQ;
  8893. wq->subtype = subtype;
  8894. wq->host_index = 0;
  8895. wq->hba_index = 0;
  8896. /* link the wq onto the parent cq child list */
  8897. list_add_tail(&wq->list, &cq->child_list);
  8898. out:
  8899. if (rc != MBX_TIMEOUT)
  8900. mempool_free(mbox, phba->mbox_mem_pool);
  8901. return status;
  8902. }
  8903. /**
  8904. * lpfc_rq_create - Create a Receive Queue on the HBA
  8905. * @phba: HBA structure that indicates port to create a queue on.
  8906. * @hrq: The queue structure to use to create the header receive queue.
  8907. * @drq: The queue structure to use to create the data receive queue.
  8908. * @cq: The completion queue to bind this work queue to.
  8909. *
  8910. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8911. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8912. * to the HBA.
  8913. *
  8914. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8915. * struct is used to get the entry count that is necessary to determine the
  8916. * number of pages to use for this queue. The @cq is used to indicate which
  8917. * completion queue to bind received buffers that are posted to these queues to.
  8918. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8919. * receive queue pair. This function is asynchronous and will wait for the
  8920. * mailbox command to finish before continuing.
  8921. *
  8922. * On success this function will return a zero. If unable to allocate enough
  8923. * memory this function will return ENOMEM. If the queue create mailbox command
  8924. * fails this function will return ENXIO.
  8925. **/
  8926. uint32_t
  8927. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8928. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8929. {
  8930. struct lpfc_mbx_rq_create *rq_create;
  8931. struct lpfc_dmabuf *dmabuf;
  8932. LPFC_MBOXQ_t *mbox;
  8933. int rc, length, status = 0;
  8934. uint32_t shdr_status, shdr_add_status;
  8935. union lpfc_sli4_cfg_shdr *shdr;
  8936. if (hrq->entry_count != drq->entry_count)
  8937. return -EINVAL;
  8938. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8939. if (!mbox)
  8940. return -ENOMEM;
  8941. length = (sizeof(struct lpfc_mbx_rq_create) -
  8942. sizeof(struct lpfc_sli4_cfg_mhdr));
  8943. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8944. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8945. length, LPFC_SLI4_MBX_EMBED);
  8946. rq_create = &mbox->u.mqe.un.rq_create;
  8947. switch (hrq->entry_count) {
  8948. default:
  8949. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8950. "2535 Unsupported RQ count. (%d)\n",
  8951. hrq->entry_count);
  8952. if (hrq->entry_count < 512)
  8953. return -EINVAL;
  8954. /* otherwise default to smallest count (drop through) */
  8955. case 512:
  8956. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8957. LPFC_RQ_RING_SIZE_512);
  8958. break;
  8959. case 1024:
  8960. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8961. LPFC_RQ_RING_SIZE_1024);
  8962. break;
  8963. case 2048:
  8964. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8965. LPFC_RQ_RING_SIZE_2048);
  8966. break;
  8967. case 4096:
  8968. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8969. LPFC_RQ_RING_SIZE_4096);
  8970. break;
  8971. }
  8972. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8973. cq->queue_id);
  8974. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8975. hrq->page_count);
  8976. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8977. LPFC_HDR_BUF_SIZE);
  8978. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  8979. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8980. putPaddrLow(dmabuf->phys);
  8981. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8982. putPaddrHigh(dmabuf->phys);
  8983. }
  8984. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8985. /* The IOCTL status is embedded in the mailbox subheader. */
  8986. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  8987. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8988. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8989. if (shdr_status || shdr_add_status || rc) {
  8990. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8991. "2504 RQ_CREATE mailbox failed with "
  8992. "status x%x add_status x%x, mbx status x%x\n",
  8993. shdr_status, shdr_add_status, rc);
  8994. status = -ENXIO;
  8995. goto out;
  8996. }
  8997. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  8998. if (hrq->queue_id == 0xFFFF) {
  8999. status = -ENXIO;
  9000. goto out;
  9001. }
  9002. hrq->type = LPFC_HRQ;
  9003. hrq->subtype = subtype;
  9004. hrq->host_index = 0;
  9005. hrq->hba_index = 0;
  9006. /* now create the data queue */
  9007. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9008. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9009. length, LPFC_SLI4_MBX_EMBED);
  9010. switch (drq->entry_count) {
  9011. default:
  9012. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9013. "2536 Unsupported RQ count. (%d)\n",
  9014. drq->entry_count);
  9015. if (drq->entry_count < 512)
  9016. return -EINVAL;
  9017. /* otherwise default to smallest count (drop through) */
  9018. case 512:
  9019. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9020. LPFC_RQ_RING_SIZE_512);
  9021. break;
  9022. case 1024:
  9023. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9024. LPFC_RQ_RING_SIZE_1024);
  9025. break;
  9026. case 2048:
  9027. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9028. LPFC_RQ_RING_SIZE_2048);
  9029. break;
  9030. case 4096:
  9031. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9032. LPFC_RQ_RING_SIZE_4096);
  9033. break;
  9034. }
  9035. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9036. cq->queue_id);
  9037. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9038. drq->page_count);
  9039. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9040. LPFC_DATA_BUF_SIZE);
  9041. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9042. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9043. putPaddrLow(dmabuf->phys);
  9044. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9045. putPaddrHigh(dmabuf->phys);
  9046. }
  9047. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9048. /* The IOCTL status is embedded in the mailbox subheader. */
  9049. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9050. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9051. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9052. if (shdr_status || shdr_add_status || rc) {
  9053. status = -ENXIO;
  9054. goto out;
  9055. }
  9056. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9057. if (drq->queue_id == 0xFFFF) {
  9058. status = -ENXIO;
  9059. goto out;
  9060. }
  9061. drq->type = LPFC_DRQ;
  9062. drq->subtype = subtype;
  9063. drq->host_index = 0;
  9064. drq->hba_index = 0;
  9065. /* link the header and data RQs onto the parent cq child list */
  9066. list_add_tail(&hrq->list, &cq->child_list);
  9067. list_add_tail(&drq->list, &cq->child_list);
  9068. out:
  9069. if (rc != MBX_TIMEOUT)
  9070. mempool_free(mbox, phba->mbox_mem_pool);
  9071. return status;
  9072. }
  9073. /**
  9074. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9075. * @eq: The queue structure associated with the queue to destroy.
  9076. *
  9077. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9078. * command, specific to the type of queue, to the HBA.
  9079. *
  9080. * The @eq struct is used to get the queue ID of the queue to destroy.
  9081. *
  9082. * On success this function will return a zero. If the queue destroy mailbox
  9083. * command fails this function will return ENXIO.
  9084. **/
  9085. uint32_t
  9086. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9087. {
  9088. LPFC_MBOXQ_t *mbox;
  9089. int rc, length, status = 0;
  9090. uint32_t shdr_status, shdr_add_status;
  9091. union lpfc_sli4_cfg_shdr *shdr;
  9092. if (!eq)
  9093. return -ENODEV;
  9094. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9095. if (!mbox)
  9096. return -ENOMEM;
  9097. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9098. sizeof(struct lpfc_sli4_cfg_mhdr));
  9099. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9100. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9101. length, LPFC_SLI4_MBX_EMBED);
  9102. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9103. eq->queue_id);
  9104. mbox->vport = eq->phba->pport;
  9105. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9106. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9107. /* The IOCTL status is embedded in the mailbox subheader. */
  9108. shdr = (union lpfc_sli4_cfg_shdr *)
  9109. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9110. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9111. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9112. if (shdr_status || shdr_add_status || rc) {
  9113. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9114. "2505 EQ_DESTROY mailbox failed with "
  9115. "status x%x add_status x%x, mbx status x%x\n",
  9116. shdr_status, shdr_add_status, rc);
  9117. status = -ENXIO;
  9118. }
  9119. /* Remove eq from any list */
  9120. list_del_init(&eq->list);
  9121. if (rc != MBX_TIMEOUT)
  9122. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9123. return status;
  9124. }
  9125. /**
  9126. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9127. * @cq: The queue structure associated with the queue to destroy.
  9128. *
  9129. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9130. * command, specific to the type of queue, to the HBA.
  9131. *
  9132. * The @cq struct is used to get the queue ID of the queue to destroy.
  9133. *
  9134. * On success this function will return a zero. If the queue destroy mailbox
  9135. * command fails this function will return ENXIO.
  9136. **/
  9137. uint32_t
  9138. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9139. {
  9140. LPFC_MBOXQ_t *mbox;
  9141. int rc, length, status = 0;
  9142. uint32_t shdr_status, shdr_add_status;
  9143. union lpfc_sli4_cfg_shdr *shdr;
  9144. if (!cq)
  9145. return -ENODEV;
  9146. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9147. if (!mbox)
  9148. return -ENOMEM;
  9149. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9150. sizeof(struct lpfc_sli4_cfg_mhdr));
  9151. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9152. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9153. length, LPFC_SLI4_MBX_EMBED);
  9154. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9155. cq->queue_id);
  9156. mbox->vport = cq->phba->pport;
  9157. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9158. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9159. /* The IOCTL status is embedded in the mailbox subheader. */
  9160. shdr = (union lpfc_sli4_cfg_shdr *)
  9161. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9162. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9163. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9164. if (shdr_status || shdr_add_status || rc) {
  9165. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9166. "2506 CQ_DESTROY mailbox failed with "
  9167. "status x%x add_status x%x, mbx status x%x\n",
  9168. shdr_status, shdr_add_status, rc);
  9169. status = -ENXIO;
  9170. }
  9171. /* Remove cq from any list */
  9172. list_del_init(&cq->list);
  9173. if (rc != MBX_TIMEOUT)
  9174. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9175. return status;
  9176. }
  9177. /**
  9178. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9179. * @qm: The queue structure associated with the queue to destroy.
  9180. *
  9181. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9182. * command, specific to the type of queue, to the HBA.
  9183. *
  9184. * The @mq struct is used to get the queue ID of the queue to destroy.
  9185. *
  9186. * On success this function will return a zero. If the queue destroy mailbox
  9187. * command fails this function will return ENXIO.
  9188. **/
  9189. uint32_t
  9190. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9191. {
  9192. LPFC_MBOXQ_t *mbox;
  9193. int rc, length, status = 0;
  9194. uint32_t shdr_status, shdr_add_status;
  9195. union lpfc_sli4_cfg_shdr *shdr;
  9196. if (!mq)
  9197. return -ENODEV;
  9198. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9199. if (!mbox)
  9200. return -ENOMEM;
  9201. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9202. sizeof(struct lpfc_sli4_cfg_mhdr));
  9203. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9204. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9205. length, LPFC_SLI4_MBX_EMBED);
  9206. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9207. mq->queue_id);
  9208. mbox->vport = mq->phba->pport;
  9209. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9210. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9211. /* The IOCTL status is embedded in the mailbox subheader. */
  9212. shdr = (union lpfc_sli4_cfg_shdr *)
  9213. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9214. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9215. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9216. if (shdr_status || shdr_add_status || rc) {
  9217. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9218. "2507 MQ_DESTROY mailbox failed with "
  9219. "status x%x add_status x%x, mbx status x%x\n",
  9220. shdr_status, shdr_add_status, rc);
  9221. status = -ENXIO;
  9222. }
  9223. /* Remove mq from any list */
  9224. list_del_init(&mq->list);
  9225. if (rc != MBX_TIMEOUT)
  9226. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9227. return status;
  9228. }
  9229. /**
  9230. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9231. * @wq: The queue structure associated with the queue to destroy.
  9232. *
  9233. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9234. * command, specific to the type of queue, to the HBA.
  9235. *
  9236. * The @wq struct is used to get the queue ID of the queue to destroy.
  9237. *
  9238. * On success this function will return a zero. If the queue destroy mailbox
  9239. * command fails this function will return ENXIO.
  9240. **/
  9241. uint32_t
  9242. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9243. {
  9244. LPFC_MBOXQ_t *mbox;
  9245. int rc, length, status = 0;
  9246. uint32_t shdr_status, shdr_add_status;
  9247. union lpfc_sli4_cfg_shdr *shdr;
  9248. if (!wq)
  9249. return -ENODEV;
  9250. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9251. if (!mbox)
  9252. return -ENOMEM;
  9253. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9254. sizeof(struct lpfc_sli4_cfg_mhdr));
  9255. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9256. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9257. length, LPFC_SLI4_MBX_EMBED);
  9258. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9259. wq->queue_id);
  9260. mbox->vport = wq->phba->pport;
  9261. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9262. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9263. shdr = (union lpfc_sli4_cfg_shdr *)
  9264. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9265. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9266. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9267. if (shdr_status || shdr_add_status || rc) {
  9268. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9269. "2508 WQ_DESTROY mailbox failed with "
  9270. "status x%x add_status x%x, mbx status x%x\n",
  9271. shdr_status, shdr_add_status, rc);
  9272. status = -ENXIO;
  9273. }
  9274. /* Remove wq from any list */
  9275. list_del_init(&wq->list);
  9276. if (rc != MBX_TIMEOUT)
  9277. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9278. return status;
  9279. }
  9280. /**
  9281. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9282. * @rq: The queue structure associated with the queue to destroy.
  9283. *
  9284. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9285. * command, specific to the type of queue, to the HBA.
  9286. *
  9287. * The @rq struct is used to get the queue ID of the queue to destroy.
  9288. *
  9289. * On success this function will return a zero. If the queue destroy mailbox
  9290. * command fails this function will return ENXIO.
  9291. **/
  9292. uint32_t
  9293. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9294. struct lpfc_queue *drq)
  9295. {
  9296. LPFC_MBOXQ_t *mbox;
  9297. int rc, length, status = 0;
  9298. uint32_t shdr_status, shdr_add_status;
  9299. union lpfc_sli4_cfg_shdr *shdr;
  9300. if (!hrq || !drq)
  9301. return -ENODEV;
  9302. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9303. if (!mbox)
  9304. return -ENOMEM;
  9305. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9306. sizeof(struct mbox_header));
  9307. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9308. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9309. length, LPFC_SLI4_MBX_EMBED);
  9310. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9311. hrq->queue_id);
  9312. mbox->vport = hrq->phba->pport;
  9313. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9314. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9315. /* The IOCTL status is embedded in the mailbox subheader. */
  9316. shdr = (union lpfc_sli4_cfg_shdr *)
  9317. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9318. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9319. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9320. if (shdr_status || shdr_add_status || rc) {
  9321. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9322. "2509 RQ_DESTROY mailbox failed with "
  9323. "status x%x add_status x%x, mbx status x%x\n",
  9324. shdr_status, shdr_add_status, rc);
  9325. if (rc != MBX_TIMEOUT)
  9326. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9327. return -ENXIO;
  9328. }
  9329. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9330. drq->queue_id);
  9331. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9332. shdr = (union lpfc_sli4_cfg_shdr *)
  9333. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9334. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9335. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9336. if (shdr_status || shdr_add_status || rc) {
  9337. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9338. "2510 RQ_DESTROY mailbox failed with "
  9339. "status x%x add_status x%x, mbx status x%x\n",
  9340. shdr_status, shdr_add_status, rc);
  9341. status = -ENXIO;
  9342. }
  9343. list_del_init(&hrq->list);
  9344. list_del_init(&drq->list);
  9345. if (rc != MBX_TIMEOUT)
  9346. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9347. return status;
  9348. }
  9349. /**
  9350. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9351. * @phba: The virtual port for which this call being executed.
  9352. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9353. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9354. * @xritag: the xritag that ties this io to the SGL pages.
  9355. *
  9356. * This routine will post the sgl pages for the IO that has the xritag
  9357. * that is in the iocbq structure. The xritag is assigned during iocbq
  9358. * creation and persists for as long as the driver is loaded.
  9359. * if the caller has fewer than 256 scatter gather segments to map then
  9360. * pdma_phys_addr1 should be 0.
  9361. * If the caller needs to map more than 256 scatter gather segment then
  9362. * pdma_phys_addr1 should be a valid physical address.
  9363. * physical address for SGLs must be 64 byte aligned.
  9364. * If you are going to map 2 SGL's then the first one must have 256 entries
  9365. * the second sgl can have between 1 and 256 entries.
  9366. *
  9367. * Return codes:
  9368. * 0 - Success
  9369. * -ENXIO, -ENOMEM - Failure
  9370. **/
  9371. int
  9372. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9373. dma_addr_t pdma_phys_addr0,
  9374. dma_addr_t pdma_phys_addr1,
  9375. uint16_t xritag)
  9376. {
  9377. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9378. LPFC_MBOXQ_t *mbox;
  9379. int rc;
  9380. uint32_t shdr_status, shdr_add_status;
  9381. union lpfc_sli4_cfg_shdr *shdr;
  9382. if (xritag == NO_XRI) {
  9383. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9384. "0364 Invalid param:\n");
  9385. return -EINVAL;
  9386. }
  9387. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9388. if (!mbox)
  9389. return -ENOMEM;
  9390. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9391. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9392. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9393. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9394. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9395. &mbox->u.mqe.un.post_sgl_pages;
  9396. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9397. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9398. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9399. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9400. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9401. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9402. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9403. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9404. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9405. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9406. if (!phba->sli4_hba.intr_enable)
  9407. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9408. else
  9409. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9410. /* The IOCTL status is embedded in the mailbox subheader. */
  9411. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9412. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9413. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9414. if (rc != MBX_TIMEOUT)
  9415. mempool_free(mbox, phba->mbox_mem_pool);
  9416. if (shdr_status || shdr_add_status || rc) {
  9417. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9418. "2511 POST_SGL mailbox failed with "
  9419. "status x%x add_status x%x, mbx status x%x\n",
  9420. shdr_status, shdr_add_status, rc);
  9421. rc = -ENXIO;
  9422. }
  9423. return 0;
  9424. }
  9425. /**
  9426. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9427. * @phba: The virtual port for which this call being executed.
  9428. *
  9429. * This routine will remove all of the sgl pages registered with the hba.
  9430. *
  9431. * Return codes:
  9432. * 0 - Success
  9433. * -ENXIO, -ENOMEM - Failure
  9434. **/
  9435. int
  9436. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9437. {
  9438. LPFC_MBOXQ_t *mbox;
  9439. int rc;
  9440. uint32_t shdr_status, shdr_add_status;
  9441. union lpfc_sli4_cfg_shdr *shdr;
  9442. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9443. if (!mbox)
  9444. return -ENOMEM;
  9445. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9446. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9447. LPFC_SLI4_MBX_EMBED);
  9448. if (!phba->sli4_hba.intr_enable)
  9449. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9450. else
  9451. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9452. /* The IOCTL status is embedded in the mailbox subheader. */
  9453. shdr = (union lpfc_sli4_cfg_shdr *)
  9454. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9455. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9456. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9457. if (rc != MBX_TIMEOUT)
  9458. mempool_free(mbox, phba->mbox_mem_pool);
  9459. if (shdr_status || shdr_add_status || rc) {
  9460. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9461. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9462. "status x%x add_status x%x, mbx status x%x\n",
  9463. shdr_status, shdr_add_status, rc);
  9464. rc = -ENXIO;
  9465. }
  9466. return rc;
  9467. }
  9468. /**
  9469. * lpfc_sli4_next_xritag - Get an xritag for the io
  9470. * @phba: Pointer to HBA context object.
  9471. *
  9472. * This function gets an xritag for the iocb. If there is no unused xritag
  9473. * it will return 0xffff.
  9474. * The function returns the allocated xritag if successful, else returns zero.
  9475. * Zero is not a valid xritag.
  9476. * The caller is not required to hold any lock.
  9477. **/
  9478. uint16_t
  9479. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9480. {
  9481. uint16_t xritag;
  9482. spin_lock_irq(&phba->hbalock);
  9483. xritag = phba->sli4_hba.next_xri;
  9484. if ((xritag != (uint16_t) -1) && xritag <
  9485. (phba->sli4_hba.max_cfg_param.max_xri
  9486. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9487. phba->sli4_hba.next_xri++;
  9488. phba->sli4_hba.max_cfg_param.xri_used++;
  9489. spin_unlock_irq(&phba->hbalock);
  9490. return xritag;
  9491. }
  9492. spin_unlock_irq(&phba->hbalock);
  9493. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9494. "2004 Failed to allocate XRI.last XRITAG is %d"
  9495. " Max XRI is %d, Used XRI is %d\n",
  9496. phba->sli4_hba.next_xri,
  9497. phba->sli4_hba.max_cfg_param.max_xri,
  9498. phba->sli4_hba.max_cfg_param.xri_used);
  9499. return -1;
  9500. }
  9501. /**
  9502. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9503. * @phba: pointer to lpfc hba data structure.
  9504. *
  9505. * This routine is invoked to post a block of driver's sgl pages to the
  9506. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9507. * is only called when the driver is loading and after all IO has been
  9508. * stopped.
  9509. **/
  9510. int
  9511. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9512. {
  9513. struct lpfc_sglq *sglq_entry;
  9514. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9515. struct sgl_page_pairs *sgl_pg_pairs;
  9516. void *viraddr;
  9517. LPFC_MBOXQ_t *mbox;
  9518. uint32_t reqlen, alloclen, pg_pairs;
  9519. uint32_t mbox_tmo;
  9520. uint16_t xritag_start = 0;
  9521. int els_xri_cnt, rc = 0;
  9522. uint32_t shdr_status, shdr_add_status;
  9523. union lpfc_sli4_cfg_shdr *shdr;
  9524. /* The number of sgls to be posted */
  9525. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9526. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9527. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9528. if (reqlen > PAGE_SIZE) {
  9529. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9530. "2559 Block sgl registration required DMA "
  9531. "size (%d) great than a page\n", reqlen);
  9532. return -ENOMEM;
  9533. }
  9534. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9535. if (!mbox) {
  9536. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9537. "2560 Failed to allocate mbox cmd memory\n");
  9538. return -ENOMEM;
  9539. }
  9540. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9541. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9542. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9543. LPFC_SLI4_MBX_NEMBED);
  9544. if (alloclen < reqlen) {
  9545. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9546. "0285 Allocated DMA memory size (%d) is "
  9547. "less than the requested DMA memory "
  9548. "size (%d)\n", alloclen, reqlen);
  9549. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9550. return -ENOMEM;
  9551. }
  9552. /* Get the first SGE entry from the non-embedded DMA memory */
  9553. if (unlikely(!mbox->sge_array)) {
  9554. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9555. "2525 Failed to get the non-embedded SGE "
  9556. "virtual address\n");
  9557. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9558. return -ENOMEM;
  9559. }
  9560. viraddr = mbox->sge_array->addr[0];
  9561. /* Set up the SGL pages in the non-embedded DMA pages */
  9562. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9563. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9564. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9565. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9566. /* Set up the sge entry */
  9567. sgl_pg_pairs->sgl_pg0_addr_lo =
  9568. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9569. sgl_pg_pairs->sgl_pg0_addr_hi =
  9570. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9571. sgl_pg_pairs->sgl_pg1_addr_lo =
  9572. cpu_to_le32(putPaddrLow(0));
  9573. sgl_pg_pairs->sgl_pg1_addr_hi =
  9574. cpu_to_le32(putPaddrHigh(0));
  9575. /* Keep the first xritag on the list */
  9576. if (pg_pairs == 0)
  9577. xritag_start = sglq_entry->sli4_xritag;
  9578. sgl_pg_pairs++;
  9579. }
  9580. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9581. pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
  9582. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9583. /* Perform endian conversion if necessary */
  9584. sgl->word0 = cpu_to_le32(sgl->word0);
  9585. if (!phba->sli4_hba.intr_enable)
  9586. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9587. else {
  9588. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9589. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9590. }
  9591. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9592. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9593. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9594. if (rc != MBX_TIMEOUT)
  9595. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9596. if (shdr_status || shdr_add_status || rc) {
  9597. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9598. "2513 POST_SGL_BLOCK mailbox command failed "
  9599. "status x%x add_status x%x mbx status x%x\n",
  9600. shdr_status, shdr_add_status, rc);
  9601. rc = -ENXIO;
  9602. }
  9603. return rc;
  9604. }
  9605. /**
  9606. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9607. * @phba: pointer to lpfc hba data structure.
  9608. * @sblist: pointer to scsi buffer list.
  9609. * @count: number of scsi buffers on the list.
  9610. *
  9611. * This routine is invoked to post a block of @count scsi sgl pages from a
  9612. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9613. * No Lock is held.
  9614. *
  9615. **/
  9616. int
  9617. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9618. int cnt)
  9619. {
  9620. struct lpfc_scsi_buf *psb;
  9621. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9622. struct sgl_page_pairs *sgl_pg_pairs;
  9623. void *viraddr;
  9624. LPFC_MBOXQ_t *mbox;
  9625. uint32_t reqlen, alloclen, pg_pairs;
  9626. uint32_t mbox_tmo;
  9627. uint16_t xritag_start = 0;
  9628. int rc = 0;
  9629. uint32_t shdr_status, shdr_add_status;
  9630. dma_addr_t pdma_phys_bpl1;
  9631. union lpfc_sli4_cfg_shdr *shdr;
  9632. /* Calculate the requested length of the dma memory */
  9633. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9634. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9635. if (reqlen > PAGE_SIZE) {
  9636. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9637. "0217 Block sgl registration required DMA "
  9638. "size (%d) great than a page\n", reqlen);
  9639. return -ENOMEM;
  9640. }
  9641. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9642. if (!mbox) {
  9643. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9644. "0283 Failed to allocate mbox cmd memory\n");
  9645. return -ENOMEM;
  9646. }
  9647. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9648. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9649. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9650. LPFC_SLI4_MBX_NEMBED);
  9651. if (alloclen < reqlen) {
  9652. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9653. "2561 Allocated DMA memory size (%d) is "
  9654. "less than the requested DMA memory "
  9655. "size (%d)\n", alloclen, reqlen);
  9656. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9657. return -ENOMEM;
  9658. }
  9659. /* Get the first SGE entry from the non-embedded DMA memory */
  9660. if (unlikely(!mbox->sge_array)) {
  9661. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9662. "2565 Failed to get the non-embedded SGE "
  9663. "virtual address\n");
  9664. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9665. return -ENOMEM;
  9666. }
  9667. viraddr = mbox->sge_array->addr[0];
  9668. /* Set up the SGL pages in the non-embedded DMA pages */
  9669. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9670. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9671. pg_pairs = 0;
  9672. list_for_each_entry(psb, sblist, list) {
  9673. /* Set up the sge entry */
  9674. sgl_pg_pairs->sgl_pg0_addr_lo =
  9675. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9676. sgl_pg_pairs->sgl_pg0_addr_hi =
  9677. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9678. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9679. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9680. else
  9681. pdma_phys_bpl1 = 0;
  9682. sgl_pg_pairs->sgl_pg1_addr_lo =
  9683. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9684. sgl_pg_pairs->sgl_pg1_addr_hi =
  9685. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9686. /* Keep the first xritag on the list */
  9687. if (pg_pairs == 0)
  9688. xritag_start = psb->cur_iocbq.sli4_xritag;
  9689. sgl_pg_pairs++;
  9690. pg_pairs++;
  9691. }
  9692. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9693. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9694. /* Perform endian conversion if necessary */
  9695. sgl->word0 = cpu_to_le32(sgl->word0);
  9696. if (!phba->sli4_hba.intr_enable)
  9697. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9698. else {
  9699. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9700. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9701. }
  9702. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9703. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9704. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9705. if (rc != MBX_TIMEOUT)
  9706. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9707. if (shdr_status || shdr_add_status || rc) {
  9708. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9709. "2564 POST_SGL_BLOCK mailbox command failed "
  9710. "status x%x add_status x%x mbx status x%x\n",
  9711. shdr_status, shdr_add_status, rc);
  9712. rc = -ENXIO;
  9713. }
  9714. return rc;
  9715. }
  9716. /**
  9717. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9718. * @phba: pointer to lpfc_hba struct that the frame was received on
  9719. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9720. *
  9721. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9722. * valid type of frame that the LPFC driver will handle. This function will
  9723. * return a zero if the frame is a valid frame or a non zero value when the
  9724. * frame does not pass the check.
  9725. **/
  9726. static int
  9727. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9728. {
  9729. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9730. char *type_names[] = FC_TYPE_NAMES_INIT;
  9731. struct fc_vft_header *fc_vft_hdr;
  9732. switch (fc_hdr->fh_r_ctl) {
  9733. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9734. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9735. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9736. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9737. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9738. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9739. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9740. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9741. case FC_RCTL_ELS_REQ: /* extended link services request */
  9742. case FC_RCTL_ELS_REP: /* extended link services reply */
  9743. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9744. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9745. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9746. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9747. case FC_RCTL_BA_RMC: /* remove connection */
  9748. case FC_RCTL_BA_ACC: /* basic accept */
  9749. case FC_RCTL_BA_RJT: /* basic reject */
  9750. case FC_RCTL_BA_PRMT:
  9751. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9752. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9753. case FC_RCTL_P_RJT: /* port reject */
  9754. case FC_RCTL_F_RJT: /* fabric reject */
  9755. case FC_RCTL_P_BSY: /* port busy */
  9756. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9757. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9758. case FC_RCTL_LCR: /* link credit reset */
  9759. case FC_RCTL_END: /* end */
  9760. break;
  9761. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9762. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9763. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9764. return lpfc_fc_frame_check(phba, fc_hdr);
  9765. default:
  9766. goto drop;
  9767. }
  9768. switch (fc_hdr->fh_type) {
  9769. case FC_TYPE_BLS:
  9770. case FC_TYPE_ELS:
  9771. case FC_TYPE_FCP:
  9772. case FC_TYPE_CT:
  9773. break;
  9774. case FC_TYPE_IP:
  9775. case FC_TYPE_ILS:
  9776. default:
  9777. goto drop;
  9778. }
  9779. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9780. "2538 Received frame rctl:%s type:%s\n",
  9781. rctl_names[fc_hdr->fh_r_ctl],
  9782. type_names[fc_hdr->fh_type]);
  9783. return 0;
  9784. drop:
  9785. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9786. "2539 Dropped frame rctl:%s type:%s\n",
  9787. rctl_names[fc_hdr->fh_r_ctl],
  9788. type_names[fc_hdr->fh_type]);
  9789. return 1;
  9790. }
  9791. /**
  9792. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9793. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9794. *
  9795. * This function processes the FC header to retrieve the VFI from the VF
  9796. * header, if one exists. This function will return the VFI if one exists
  9797. * or 0 if no VSAN Header exists.
  9798. **/
  9799. static uint32_t
  9800. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9801. {
  9802. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9803. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9804. return 0;
  9805. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9806. }
  9807. /**
  9808. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9809. * @phba: Pointer to the HBA structure to search for the vport on
  9810. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9811. * @fcfi: The FC Fabric ID that the frame came from
  9812. *
  9813. * This function searches the @phba for a vport that matches the content of the
  9814. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9815. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9816. * returns the matching vport pointer or NULL if unable to match frame to a
  9817. * vport.
  9818. **/
  9819. static struct lpfc_vport *
  9820. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9821. uint16_t fcfi)
  9822. {
  9823. struct lpfc_vport **vports;
  9824. struct lpfc_vport *vport = NULL;
  9825. int i;
  9826. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9827. fc_hdr->fh_d_id[1] << 8 |
  9828. fc_hdr->fh_d_id[2]);
  9829. vports = lpfc_create_vport_work_array(phba);
  9830. if (vports != NULL)
  9831. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9832. if (phba->fcf.fcfi == fcfi &&
  9833. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9834. vports[i]->fc_myDID == did) {
  9835. vport = vports[i];
  9836. break;
  9837. }
  9838. }
  9839. lpfc_destroy_vport_work_array(phba, vports);
  9840. return vport;
  9841. }
  9842. /**
  9843. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9844. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9845. *
  9846. * This function searches through the existing incomplete sequences that have
  9847. * been sent to this @vport. If the frame matches one of the incomplete
  9848. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9849. * make up that sequence. If no sequence is found that matches this frame then
  9850. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9851. * This function returns a pointer to the first dmabuf in the sequence list that
  9852. * the frame was linked to.
  9853. **/
  9854. static struct hbq_dmabuf *
  9855. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9856. {
  9857. struct fc_frame_header *new_hdr;
  9858. struct fc_frame_header *temp_hdr;
  9859. struct lpfc_dmabuf *d_buf;
  9860. struct lpfc_dmabuf *h_buf;
  9861. struct hbq_dmabuf *seq_dmabuf = NULL;
  9862. struct hbq_dmabuf *temp_dmabuf = NULL;
  9863. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9864. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9865. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9866. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9867. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9868. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9869. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9870. continue;
  9871. /* found a pending sequence that matches this frame */
  9872. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9873. break;
  9874. }
  9875. if (!seq_dmabuf) {
  9876. /*
  9877. * This indicates first frame received for this sequence.
  9878. * Queue the buffer on the vport's rcv_buffer_list.
  9879. */
  9880. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9881. return dmabuf;
  9882. }
  9883. temp_hdr = seq_dmabuf->hbuf.virt;
  9884. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9885. list_add(&seq_dmabuf->dbuf.list, &dmabuf->dbuf.list);
  9886. return dmabuf;
  9887. }
  9888. /* find the correct place in the sequence to insert this frame */
  9889. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9890. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9891. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9892. /*
  9893. * If the frame's sequence count is greater than the frame on
  9894. * the list then insert the frame right after this frame
  9895. */
  9896. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9897. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9898. return seq_dmabuf;
  9899. }
  9900. }
  9901. return NULL;
  9902. }
  9903. /**
  9904. * lpfc_seq_complete - Indicates if a sequence is complete
  9905. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9906. *
  9907. * This function checks the sequence, starting with the frame described by
  9908. * @dmabuf, to see if all the frames associated with this sequence are present.
  9909. * the frames associated with this sequence are linked to the @dmabuf using the
  9910. * dbuf list. This function looks for two major things. 1) That the first frame
  9911. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  9912. * set. 3) That there are no holes in the sequence count. The function will
  9913. * return 1 when the sequence is complete, otherwise it will return 0.
  9914. **/
  9915. static int
  9916. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  9917. {
  9918. struct fc_frame_header *hdr;
  9919. struct lpfc_dmabuf *d_buf;
  9920. struct hbq_dmabuf *seq_dmabuf;
  9921. uint32_t fctl;
  9922. int seq_count = 0;
  9923. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9924. /* make sure first fame of sequence has a sequence count of zero */
  9925. if (hdr->fh_seq_cnt != seq_count)
  9926. return 0;
  9927. fctl = (hdr->fh_f_ctl[0] << 16 |
  9928. hdr->fh_f_ctl[1] << 8 |
  9929. hdr->fh_f_ctl[2]);
  9930. /* If last frame of sequence we can return success. */
  9931. if (fctl & FC_FC_END_SEQ)
  9932. return 1;
  9933. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  9934. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9935. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9936. /* If there is a hole in the sequence count then fail. */
  9937. if (++seq_count != hdr->fh_seq_cnt)
  9938. return 0;
  9939. fctl = (hdr->fh_f_ctl[0] << 16 |
  9940. hdr->fh_f_ctl[1] << 8 |
  9941. hdr->fh_f_ctl[2]);
  9942. /* If last frame of sequence we can return success. */
  9943. if (fctl & FC_FC_END_SEQ)
  9944. return 1;
  9945. }
  9946. return 0;
  9947. }
  9948. /**
  9949. * lpfc_prep_seq - Prep sequence for ULP processing
  9950. * @vport: Pointer to the vport on which this sequence was received
  9951. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9952. *
  9953. * This function takes a sequence, described by a list of frames, and creates
  9954. * a list of iocbq structures to describe the sequence. This iocbq list will be
  9955. * used to issue to the generic unsolicited sequence handler. This routine
  9956. * returns a pointer to the first iocbq in the list. If the function is unable
  9957. * to allocate an iocbq then it throw out the received frames that were not
  9958. * able to be described and return a pointer to the first iocbq. If unable to
  9959. * allocate any iocbqs (including the first) this function will return NULL.
  9960. **/
  9961. static struct lpfc_iocbq *
  9962. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  9963. {
  9964. struct lpfc_dmabuf *d_buf, *n_buf;
  9965. struct lpfc_iocbq *first_iocbq, *iocbq;
  9966. struct fc_frame_header *fc_hdr;
  9967. uint32_t sid;
  9968. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9969. /* remove from receive buffer list */
  9970. list_del_init(&seq_dmabuf->hbuf.list);
  9971. /* get the Remote Port's SID */
  9972. sid = (fc_hdr->fh_s_id[0] << 16 |
  9973. fc_hdr->fh_s_id[1] << 8 |
  9974. fc_hdr->fh_s_id[2]);
  9975. /* Get an iocbq struct to fill in. */
  9976. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  9977. if (first_iocbq) {
  9978. /* Initialize the first IOCB. */
  9979. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  9980. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  9981. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  9982. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  9983. vport->vpi + vport->phba->vpi_base;
  9984. /* put the first buffer into the first IOCBq */
  9985. first_iocbq->context2 = &seq_dmabuf->dbuf;
  9986. first_iocbq->context3 = NULL;
  9987. first_iocbq->iocb.ulpBdeCount = 1;
  9988. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  9989. LPFC_DATA_BUF_SIZE;
  9990. first_iocbq->iocb.un.rcvels.remoteID = sid;
  9991. }
  9992. iocbq = first_iocbq;
  9993. /*
  9994. * Each IOCBq can have two Buffers assigned, so go through the list
  9995. * of buffers for this sequence and save two buffers in each IOCBq
  9996. */
  9997. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  9998. if (!iocbq) {
  9999. lpfc_in_buf_free(vport->phba, d_buf);
  10000. continue;
  10001. }
  10002. if (!iocbq->context3) {
  10003. iocbq->context3 = d_buf;
  10004. iocbq->iocb.ulpBdeCount++;
  10005. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  10006. LPFC_DATA_BUF_SIZE;
  10007. } else {
  10008. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10009. if (!iocbq) {
  10010. if (first_iocbq) {
  10011. first_iocbq->iocb.ulpStatus =
  10012. IOSTAT_FCP_RSP_ERROR;
  10013. first_iocbq->iocb.un.ulpWord[4] =
  10014. IOERR_NO_RESOURCES;
  10015. }
  10016. lpfc_in_buf_free(vport->phba, d_buf);
  10017. continue;
  10018. }
  10019. iocbq->context2 = d_buf;
  10020. iocbq->context3 = NULL;
  10021. iocbq->iocb.ulpBdeCount = 1;
  10022. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10023. LPFC_DATA_BUF_SIZE;
  10024. iocbq->iocb.un.rcvels.remoteID = sid;
  10025. list_add_tail(&iocbq->list, &first_iocbq->list);
  10026. }
  10027. }
  10028. return first_iocbq;
  10029. }
  10030. /**
  10031. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10032. * @phba: Pointer to HBA context object.
  10033. *
  10034. * This function is called with no lock held. This function processes all
  10035. * the received buffers and gives it to upper layers when a received buffer
  10036. * indicates that it is the final frame in the sequence. The interrupt
  10037. * service routine processes received buffers at interrupt contexts and adds
  10038. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10039. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10040. * appropriate receive function when the final frame in a sequence is received.
  10041. **/
  10042. int
  10043. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba)
  10044. {
  10045. LIST_HEAD(cmplq);
  10046. struct hbq_dmabuf *dmabuf, *seq_dmabuf;
  10047. struct fc_frame_header *fc_hdr;
  10048. struct lpfc_vport *vport;
  10049. uint32_t fcfi;
  10050. struct lpfc_iocbq *iocbq;
  10051. /* Clear hba flag and get all received buffers into the cmplq */
  10052. spin_lock_irq(&phba->hbalock);
  10053. phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
  10054. list_splice_init(&phba->rb_pend_list, &cmplq);
  10055. spin_unlock_irq(&phba->hbalock);
  10056. /* Process each received buffer */
  10057. while ((dmabuf = lpfc_sli_hbqbuf_get(&cmplq)) != NULL) {
  10058. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10059. /* check to see if this a valid type of frame */
  10060. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10061. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10062. continue;
  10063. }
  10064. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->rcqe);
  10065. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10066. if (!vport) {
  10067. /* throw out the frame */
  10068. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10069. continue;
  10070. }
  10071. /* Link this frame */
  10072. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10073. if (!seq_dmabuf) {
  10074. /* unable to add frame to vport - throw it out */
  10075. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10076. continue;
  10077. }
  10078. /* If not last frame in sequence continue processing frames. */
  10079. if (!lpfc_seq_complete(seq_dmabuf)) {
  10080. /*
  10081. * When saving off frames post a new one and mark this
  10082. * frame to be freed when it is finished.
  10083. **/
  10084. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10085. dmabuf->tag = -1;
  10086. continue;
  10087. }
  10088. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10089. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10090. if (!lpfc_complete_unsol_iocb(phba,
  10091. &phba->sli.ring[LPFC_ELS_RING],
  10092. iocbq, fc_hdr->fh_r_ctl,
  10093. fc_hdr->fh_type))
  10094. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10095. "2540 Ring %d handler: unexpected Rctl "
  10096. "x%x Type x%x received\n",
  10097. LPFC_ELS_RING,
  10098. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10099. };
  10100. return 0;
  10101. }
  10102. /**
  10103. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10104. * @phba: pointer to lpfc hba data structure.
  10105. *
  10106. * This routine is invoked to post rpi header templates to the
  10107. * HBA consistent with the SLI-4 interface spec. This routine
  10108. * posts a PAGE_SIZE memory region to the port to hold up to
  10109. * PAGE_SIZE modulo 64 rpi context headers.
  10110. *
  10111. * This routine does not require any locks. It's usage is expected
  10112. * to be driver load or reset recovery when the driver is
  10113. * sequential.
  10114. *
  10115. * Return codes
  10116. * 0 - sucessful
  10117. * EIO - The mailbox failed to complete successfully.
  10118. * When this error occurs, the driver is not guaranteed
  10119. * to have any rpi regions posted to the device and
  10120. * must either attempt to repost the regions or take a
  10121. * fatal error.
  10122. **/
  10123. int
  10124. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10125. {
  10126. struct lpfc_rpi_hdr *rpi_page;
  10127. uint32_t rc = 0;
  10128. /* Post all rpi memory regions to the port. */
  10129. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10130. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10131. if (rc != MBX_SUCCESS) {
  10132. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10133. "2008 Error %d posting all rpi "
  10134. "headers\n", rc);
  10135. rc = -EIO;
  10136. break;
  10137. }
  10138. }
  10139. return rc;
  10140. }
  10141. /**
  10142. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10143. * @phba: pointer to lpfc hba data structure.
  10144. * @rpi_page: pointer to the rpi memory region.
  10145. *
  10146. * This routine is invoked to post a single rpi header to the
  10147. * HBA consistent with the SLI-4 interface spec. This memory region
  10148. * maps up to 64 rpi context regions.
  10149. *
  10150. * Return codes
  10151. * 0 - sucessful
  10152. * ENOMEM - No available memory
  10153. * EIO - The mailbox failed to complete successfully.
  10154. **/
  10155. int
  10156. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10157. {
  10158. LPFC_MBOXQ_t *mboxq;
  10159. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10160. uint32_t rc = 0;
  10161. uint32_t mbox_tmo;
  10162. uint32_t shdr_status, shdr_add_status;
  10163. union lpfc_sli4_cfg_shdr *shdr;
  10164. /* The port is notified of the header region via a mailbox command. */
  10165. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10166. if (!mboxq) {
  10167. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10168. "2001 Unable to allocate memory for issuing "
  10169. "SLI_CONFIG_SPECIAL mailbox command\n");
  10170. return -ENOMEM;
  10171. }
  10172. /* Post all rpi memory regions to the port. */
  10173. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10174. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10175. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10176. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10177. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10178. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10179. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10180. hdr_tmpl, rpi_page->page_count);
  10181. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10182. rpi_page->start_rpi);
  10183. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10184. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10185. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10186. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10187. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10188. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10189. if (rc != MBX_TIMEOUT)
  10190. mempool_free(mboxq, phba->mbox_mem_pool);
  10191. if (shdr_status || shdr_add_status || rc) {
  10192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10193. "2514 POST_RPI_HDR mailbox failed with "
  10194. "status x%x add_status x%x, mbx status x%x\n",
  10195. shdr_status, shdr_add_status, rc);
  10196. rc = -ENXIO;
  10197. }
  10198. return rc;
  10199. }
  10200. /**
  10201. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10202. * @phba: pointer to lpfc hba data structure.
  10203. *
  10204. * This routine is invoked to post rpi header templates to the
  10205. * HBA consistent with the SLI-4 interface spec. This routine
  10206. * posts a PAGE_SIZE memory region to the port to hold up to
  10207. * PAGE_SIZE modulo 64 rpi context headers.
  10208. *
  10209. * Returns
  10210. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10211. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10212. **/
  10213. int
  10214. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10215. {
  10216. int rpi;
  10217. uint16_t max_rpi, rpi_base, rpi_limit;
  10218. uint16_t rpi_remaining;
  10219. struct lpfc_rpi_hdr *rpi_hdr;
  10220. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10221. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10222. rpi_limit = phba->sli4_hba.next_rpi;
  10223. /*
  10224. * The valid rpi range is not guaranteed to be zero-based. Start
  10225. * the search at the rpi_base as reported by the port.
  10226. */
  10227. spin_lock_irq(&phba->hbalock);
  10228. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10229. if (rpi >= rpi_limit || rpi < rpi_base)
  10230. rpi = LPFC_RPI_ALLOC_ERROR;
  10231. else {
  10232. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10233. phba->sli4_hba.max_cfg_param.rpi_used++;
  10234. phba->sli4_hba.rpi_count++;
  10235. }
  10236. /*
  10237. * Don't try to allocate more rpi header regions if the device limit
  10238. * on available rpis max has been exhausted.
  10239. */
  10240. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10241. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10242. spin_unlock_irq(&phba->hbalock);
  10243. return rpi;
  10244. }
  10245. /*
  10246. * If the driver is running low on rpi resources, allocate another
  10247. * page now. Note that the next_rpi value is used because
  10248. * it represents how many are actually in use whereas max_rpi notes
  10249. * how many are supported max by the device.
  10250. */
  10251. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10252. phba->sli4_hba.rpi_count;
  10253. spin_unlock_irq(&phba->hbalock);
  10254. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10255. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10256. if (!rpi_hdr) {
  10257. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10258. "2002 Error Could not grow rpi "
  10259. "count\n");
  10260. } else {
  10261. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10262. }
  10263. }
  10264. return rpi;
  10265. }
  10266. /**
  10267. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10268. * @phba: pointer to lpfc hba data structure.
  10269. *
  10270. * This routine is invoked to release an rpi to the pool of
  10271. * available rpis maintained by the driver.
  10272. **/
  10273. void
  10274. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10275. {
  10276. spin_lock_irq(&phba->hbalock);
  10277. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10278. phba->sli4_hba.rpi_count--;
  10279. phba->sli4_hba.max_cfg_param.rpi_used--;
  10280. spin_unlock_irq(&phba->hbalock);
  10281. }
  10282. /**
  10283. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10284. * @phba: pointer to lpfc hba data structure.
  10285. *
  10286. * This routine is invoked to remove the memory region that
  10287. * provided rpi via a bitmask.
  10288. **/
  10289. void
  10290. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10291. {
  10292. kfree(phba->sli4_hba.rpi_bmask);
  10293. }
  10294. /**
  10295. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10296. * @phba: pointer to lpfc hba data structure.
  10297. *
  10298. * This routine is invoked to remove the memory region that
  10299. * provided rpi via a bitmask.
  10300. **/
  10301. int
  10302. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10303. {
  10304. LPFC_MBOXQ_t *mboxq;
  10305. struct lpfc_hba *phba = ndlp->phba;
  10306. int rc;
  10307. /* The port is notified of the header region via a mailbox command. */
  10308. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10309. if (!mboxq)
  10310. return -ENOMEM;
  10311. /* Post all rpi memory regions to the port. */
  10312. lpfc_resume_rpi(mboxq, ndlp);
  10313. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10314. if (rc == MBX_NOT_FINISHED) {
  10315. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10316. "2010 Resume RPI Mailbox failed "
  10317. "status %d, mbxStatus x%x\n", rc,
  10318. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10319. mempool_free(mboxq, phba->mbox_mem_pool);
  10320. return -EIO;
  10321. }
  10322. return 0;
  10323. }
  10324. /**
  10325. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10326. * @phba: pointer to lpfc hba data structure.
  10327. * @vpi: vpi value to activate with the port.
  10328. *
  10329. * This routine is invoked to activate a vpi with the
  10330. * port when the host intends to use vports with a
  10331. * nonzero vpi.
  10332. *
  10333. * Returns:
  10334. * 0 success
  10335. * -Evalue otherwise
  10336. **/
  10337. int
  10338. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10339. {
  10340. LPFC_MBOXQ_t *mboxq;
  10341. int rc = 0;
  10342. uint32_t mbox_tmo;
  10343. if (vpi == 0)
  10344. return -EINVAL;
  10345. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10346. if (!mboxq)
  10347. return -ENOMEM;
  10348. lpfc_init_vpi(mboxq, vpi);
  10349. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10350. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10351. if (rc != MBX_TIMEOUT)
  10352. mempool_free(mboxq, phba->mbox_mem_pool);
  10353. if (rc != MBX_SUCCESS) {
  10354. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10355. "2022 INIT VPI Mailbox failed "
  10356. "status %d, mbxStatus x%x\n", rc,
  10357. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10358. rc = -EIO;
  10359. }
  10360. return rc;
  10361. }
  10362. /**
  10363. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10364. * @phba: pointer to lpfc hba data structure.
  10365. * @mboxq: Pointer to mailbox object.
  10366. *
  10367. * This routine is invoked to manually add a single FCF record. The caller
  10368. * must pass a completely initialized FCF_Record. This routine takes
  10369. * care of the nonembedded mailbox operations.
  10370. **/
  10371. static void
  10372. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10373. {
  10374. void *virt_addr;
  10375. union lpfc_sli4_cfg_shdr *shdr;
  10376. uint32_t shdr_status, shdr_add_status;
  10377. virt_addr = mboxq->sge_array->addr[0];
  10378. /* The IOCTL status is embedded in the mailbox subheader. */
  10379. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10380. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10381. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10382. if ((shdr_status || shdr_add_status) &&
  10383. (shdr_status != STATUS_FCF_IN_USE))
  10384. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10385. "2558 ADD_FCF_RECORD mailbox failed with "
  10386. "status x%x add_status x%x\n",
  10387. shdr_status, shdr_add_status);
  10388. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10389. }
  10390. /**
  10391. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10392. * @phba: pointer to lpfc hba data structure.
  10393. * @fcf_record: pointer to the initialized fcf record to add.
  10394. *
  10395. * This routine is invoked to manually add a single FCF record. The caller
  10396. * must pass a completely initialized FCF_Record. This routine takes
  10397. * care of the nonembedded mailbox operations.
  10398. **/
  10399. int
  10400. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10401. {
  10402. int rc = 0;
  10403. LPFC_MBOXQ_t *mboxq;
  10404. uint8_t *bytep;
  10405. void *virt_addr;
  10406. dma_addr_t phys_addr;
  10407. struct lpfc_mbx_sge sge;
  10408. uint32_t alloc_len, req_len;
  10409. uint32_t fcfindex;
  10410. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10411. if (!mboxq) {
  10412. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10413. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10414. return -ENOMEM;
  10415. }
  10416. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10417. sizeof(uint32_t);
  10418. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10419. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10420. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10421. req_len, LPFC_SLI4_MBX_NEMBED);
  10422. if (alloc_len < req_len) {
  10423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10424. "2523 Allocated DMA memory size (x%x) is "
  10425. "less than the requested DMA memory "
  10426. "size (x%x)\n", alloc_len, req_len);
  10427. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10428. return -ENOMEM;
  10429. }
  10430. /*
  10431. * Get the first SGE entry from the non-embedded DMA memory. This
  10432. * routine only uses a single SGE.
  10433. */
  10434. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10435. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10436. if (unlikely(!mboxq->sge_array)) {
  10437. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10438. "2526 Failed to get the non-embedded SGE "
  10439. "virtual address\n");
  10440. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10441. return -ENOMEM;
  10442. }
  10443. virt_addr = mboxq->sge_array->addr[0];
  10444. /*
  10445. * Configure the FCF record for FCFI 0. This is the driver's
  10446. * hardcoded default and gets used in nonFIP mode.
  10447. */
  10448. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10449. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10450. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10451. /*
  10452. * Copy the fcf_index and the FCF Record Data. The data starts after
  10453. * the FCoE header plus word10. The data copy needs to be endian
  10454. * correct.
  10455. */
  10456. bytep += sizeof(uint32_t);
  10457. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10458. mboxq->vport = phba->pport;
  10459. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10460. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10461. if (rc == MBX_NOT_FINISHED) {
  10462. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10463. "2515 ADD_FCF_RECORD mailbox failed with "
  10464. "status 0x%x\n", rc);
  10465. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10466. rc = -EIO;
  10467. } else
  10468. rc = 0;
  10469. return rc;
  10470. }
  10471. /**
  10472. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10473. * @phba: pointer to lpfc hba data structure.
  10474. * @fcf_record: pointer to the fcf record to write the default data.
  10475. * @fcf_index: FCF table entry index.
  10476. *
  10477. * This routine is invoked to build the driver's default FCF record. The
  10478. * values used are hardcoded. This routine handles memory initialization.
  10479. *
  10480. **/
  10481. void
  10482. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10483. struct fcf_record *fcf_record,
  10484. uint16_t fcf_index)
  10485. {
  10486. memset(fcf_record, 0, sizeof(struct fcf_record));
  10487. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10488. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10489. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10490. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10491. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10492. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10493. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10494. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10495. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10496. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10497. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10498. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10499. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10500. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10501. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10502. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10503. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10504. /* Set the VLAN bit map */
  10505. if (phba->valid_vlan) {
  10506. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10507. = 1 << (phba->vlan_id % 8);
  10508. }
  10509. }
  10510. /**
  10511. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10512. * @phba: pointer to lpfc hba data structure.
  10513. * @fcf_index: FCF table entry offset.
  10514. *
  10515. * This routine is invoked to read up to @fcf_num of FCF record from the
  10516. * device starting with the given @fcf_index.
  10517. **/
  10518. int
  10519. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10520. {
  10521. int rc = 0, error;
  10522. LPFC_MBOXQ_t *mboxq;
  10523. void *virt_addr;
  10524. dma_addr_t phys_addr;
  10525. uint8_t *bytep;
  10526. struct lpfc_mbx_sge sge;
  10527. uint32_t alloc_len, req_len;
  10528. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10529. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10530. if (!mboxq) {
  10531. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10532. "2000 Failed to allocate mbox for "
  10533. "READ_FCF cmd\n");
  10534. return -ENOMEM;
  10535. }
  10536. req_len = sizeof(struct fcf_record) +
  10537. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10538. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10539. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10540. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10541. LPFC_SLI4_MBX_NEMBED);
  10542. if (alloc_len < req_len) {
  10543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10544. "0291 Allocated DMA memory size (x%x) is "
  10545. "less than the requested DMA memory "
  10546. "size (x%x)\n", alloc_len, req_len);
  10547. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10548. return -ENOMEM;
  10549. }
  10550. /* Get the first SGE entry from the non-embedded DMA memory. This
  10551. * routine only uses a single SGE.
  10552. */
  10553. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10554. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10555. if (unlikely(!mboxq->sge_array)) {
  10556. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10557. "2527 Failed to get the non-embedded SGE "
  10558. "virtual address\n");
  10559. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10560. return -ENOMEM;
  10561. }
  10562. virt_addr = mboxq->sge_array->addr[0];
  10563. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10564. /* Set up command fields */
  10565. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10566. /* Perform necessary endian conversion */
  10567. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10568. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10569. mboxq->vport = phba->pport;
  10570. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10571. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10572. if (rc == MBX_NOT_FINISHED) {
  10573. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10574. error = -EIO;
  10575. } else
  10576. error = 0;
  10577. return error;
  10578. }