lpfc_sli.c 356 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552
  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. return -EIO;
  3742. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3743. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3744. kfree(mp);
  3745. return 0;
  3746. }
  3747. /**
  3748. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3749. * @phba: pointer to lpfc hba data structure.
  3750. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3751. * @vpd: pointer to the memory to hold resulting port vpd data.
  3752. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3753. * On output, the number of data bytes in @vpd.
  3754. *
  3755. * This routine executes a READ_REV SLI4 mailbox command. In
  3756. * addition, this routine gets the port vpd data.
  3757. *
  3758. * Return codes
  3759. * 0 - sucessful
  3760. * ENOMEM - could not allocated memory.
  3761. **/
  3762. static int
  3763. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3764. uint8_t *vpd, uint32_t *vpd_size)
  3765. {
  3766. int rc = 0;
  3767. uint32_t dma_size;
  3768. struct lpfc_dmabuf *dmabuf;
  3769. struct lpfc_mqe *mqe;
  3770. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3771. if (!dmabuf)
  3772. return -ENOMEM;
  3773. /*
  3774. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3775. * mailbox command.
  3776. */
  3777. dma_size = *vpd_size;
  3778. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3779. dma_size,
  3780. &dmabuf->phys,
  3781. GFP_KERNEL);
  3782. if (!dmabuf->virt) {
  3783. kfree(dmabuf);
  3784. return -ENOMEM;
  3785. }
  3786. memset(dmabuf->virt, 0, dma_size);
  3787. /*
  3788. * The SLI4 implementation of READ_REV conflicts at word1,
  3789. * bits 31:16 and SLI4 adds vpd functionality not present
  3790. * in SLI3. This code corrects the conflicts.
  3791. */
  3792. lpfc_read_rev(phba, mboxq);
  3793. mqe = &mboxq->u.mqe;
  3794. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3795. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3796. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3797. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3798. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3799. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3800. if (rc) {
  3801. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3802. dmabuf->virt, dmabuf->phys);
  3803. return -EIO;
  3804. }
  3805. /*
  3806. * The available vpd length cannot be bigger than the
  3807. * DMA buffer passed to the port. Catch the less than
  3808. * case and update the caller's size.
  3809. */
  3810. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3811. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3812. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3813. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3814. dmabuf->virt, dmabuf->phys);
  3815. kfree(dmabuf);
  3816. return 0;
  3817. }
  3818. /**
  3819. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3820. * @phba: pointer to lpfc hba data structure.
  3821. *
  3822. * This routine is called to explicitly arm the SLI4 device's completion and
  3823. * event queues
  3824. **/
  3825. static void
  3826. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3827. {
  3828. uint8_t fcp_eqidx;
  3829. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3830. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3831. lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM);
  3832. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3833. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3834. LPFC_QUEUE_REARM);
  3835. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3836. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3837. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3838. LPFC_QUEUE_REARM);
  3839. }
  3840. /**
  3841. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3842. * @phba: Pointer to HBA context object.
  3843. *
  3844. * This function is the main SLI4 device intialization PCI function. This
  3845. * function is called by the HBA intialization code, HBA reset code and
  3846. * HBA error attention handler code. Caller is not required to hold any
  3847. * locks.
  3848. **/
  3849. int
  3850. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3851. {
  3852. int rc;
  3853. LPFC_MBOXQ_t *mboxq;
  3854. struct lpfc_mqe *mqe;
  3855. uint8_t *vpd;
  3856. uint32_t vpd_size;
  3857. uint32_t ftr_rsp = 0;
  3858. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3859. struct lpfc_vport *vport = phba->pport;
  3860. struct lpfc_dmabuf *mp;
  3861. /* Perform a PCI function reset to start from clean */
  3862. rc = lpfc_pci_function_reset(phba);
  3863. if (unlikely(rc))
  3864. return -ENODEV;
  3865. /* Check the HBA Host Status Register for readyness */
  3866. rc = lpfc_sli4_post_status_check(phba);
  3867. if (unlikely(rc))
  3868. return -ENODEV;
  3869. else {
  3870. spin_lock_irq(&phba->hbalock);
  3871. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3872. spin_unlock_irq(&phba->hbalock);
  3873. }
  3874. /*
  3875. * Allocate a single mailbox container for initializing the
  3876. * port.
  3877. */
  3878. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3879. if (!mboxq)
  3880. return -ENOMEM;
  3881. /*
  3882. * Continue initialization with default values even if driver failed
  3883. * to read FCoE param config regions
  3884. */
  3885. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3886. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3887. "2570 Failed to read FCoE parameters \n");
  3888. /* Issue READ_REV to collect vpd and FW information. */
  3889. vpd_size = PAGE_SIZE;
  3890. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3891. if (!vpd) {
  3892. rc = -ENOMEM;
  3893. goto out_free_mbox;
  3894. }
  3895. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3896. if (unlikely(rc))
  3897. goto out_free_vpd;
  3898. mqe = &mboxq->u.mqe;
  3899. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3900. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3901. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3902. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3903. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3904. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3905. "0376 READ_REV Error. SLI Level %d "
  3906. "FCoE enabled %d\n",
  3907. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3908. rc = -EIO;
  3909. goto out_free_vpd;
  3910. }
  3911. /*
  3912. * Evaluate the read rev and vpd data. Populate the driver
  3913. * state with the results. If this routine fails, the failure
  3914. * is not fatal as the driver will use generic values.
  3915. */
  3916. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3917. if (unlikely(!rc)) {
  3918. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3919. "0377 Error %d parsing vpd. "
  3920. "Using defaults.\n", rc);
  3921. rc = 0;
  3922. }
  3923. /* Save information as VPD data */
  3924. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3925. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3926. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3927. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3928. &mqe->un.read_rev);
  3929. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3930. &mqe->un.read_rev);
  3931. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3932. &mqe->un.read_rev);
  3933. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3934. &mqe->un.read_rev);
  3935. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3936. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3937. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3938. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3939. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3940. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3941. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3942. "(%d):0380 READ_REV Status x%x "
  3943. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3944. mboxq->vport ? mboxq->vport->vpi : 0,
  3945. bf_get(lpfc_mqe_status, mqe),
  3946. phba->vpd.rev.opFwName,
  3947. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  3948. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  3949. /*
  3950. * Discover the port's supported feature set and match it against the
  3951. * hosts requests.
  3952. */
  3953. lpfc_request_features(phba, mboxq);
  3954. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3955. if (unlikely(rc)) {
  3956. rc = -EIO;
  3957. goto out_free_vpd;
  3958. }
  3959. /*
  3960. * The port must support FCP initiator mode as this is the
  3961. * only mode running in the host.
  3962. */
  3963. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3964. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3965. "0378 No support for fcpi mode.\n");
  3966. ftr_rsp++;
  3967. }
  3968. /*
  3969. * If the port cannot support the host's requested features
  3970. * then turn off the global config parameters to disable the
  3971. * feature in the driver. This is not a fatal error.
  3972. */
  3973. if ((phba->cfg_enable_bg) &&
  3974. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3975. ftr_rsp++;
  3976. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3977. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3978. ftr_rsp++;
  3979. if (ftr_rsp) {
  3980. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3981. "0379 Feature Mismatch Data: x%08x %08x "
  3982. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3983. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3984. phba->cfg_enable_npiv, phba->max_vpi);
  3985. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3986. phba->cfg_enable_bg = 0;
  3987. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3988. phba->cfg_enable_npiv = 0;
  3989. }
  3990. /* These SLI3 features are assumed in SLI4 */
  3991. spin_lock_irq(&phba->hbalock);
  3992. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3993. spin_unlock_irq(&phba->hbalock);
  3994. /* Read the port's service parameters. */
  3995. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3996. mboxq->vport = vport;
  3997. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3998. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3999. if (rc == MBX_SUCCESS) {
  4000. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4001. rc = 0;
  4002. }
  4003. /*
  4004. * This memory was allocated by the lpfc_read_sparam routine. Release
  4005. * it to the mbuf pool.
  4006. */
  4007. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4008. kfree(mp);
  4009. mboxq->context1 = NULL;
  4010. if (unlikely(rc)) {
  4011. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4012. "0382 READ_SPARAM command failed "
  4013. "status %d, mbxStatus x%x\n",
  4014. rc, bf_get(lpfc_mqe_status, mqe));
  4015. phba->link_state = LPFC_HBA_ERROR;
  4016. rc = -EIO;
  4017. goto out_free_vpd;
  4018. }
  4019. if (phba->cfg_soft_wwnn)
  4020. u64_to_wwn(phba->cfg_soft_wwnn,
  4021. vport->fc_sparam.nodeName.u.wwn);
  4022. if (phba->cfg_soft_wwpn)
  4023. u64_to_wwn(phba->cfg_soft_wwpn,
  4024. vport->fc_sparam.portName.u.wwn);
  4025. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4026. sizeof(struct lpfc_name));
  4027. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4028. sizeof(struct lpfc_name));
  4029. /* Update the fc_host data structures with new wwn. */
  4030. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4031. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4032. /* Register SGL pool to the device using non-embedded mailbox command */
  4033. rc = lpfc_sli4_post_sgl_list(phba);
  4034. if (unlikely(rc)) {
  4035. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4036. "0582 Error %d during sgl post operation", rc);
  4037. rc = -ENODEV;
  4038. goto out_free_vpd;
  4039. }
  4040. /* Register SCSI SGL pool to the device */
  4041. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4042. if (unlikely(rc)) {
  4043. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4044. "0383 Error %d during scsi sgl post opeation",
  4045. rc);
  4046. /* Some Scsi buffers were moved to the abort scsi list */
  4047. /* A pci function reset will repost them */
  4048. rc = -ENODEV;
  4049. goto out_free_vpd;
  4050. }
  4051. /* Post the rpi header region to the device. */
  4052. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4053. if (unlikely(rc)) {
  4054. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4055. "0393 Error %d during rpi post operation\n",
  4056. rc);
  4057. rc = -ENODEV;
  4058. goto out_free_vpd;
  4059. }
  4060. if (phba->cfg_enable_fip)
  4061. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1);
  4062. else
  4063. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
  4064. /* Set up all the queues to the device */
  4065. rc = lpfc_sli4_queue_setup(phba);
  4066. if (unlikely(rc)) {
  4067. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4068. "0381 Error %d during queue setup.\n ", rc);
  4069. goto out_stop_timers;
  4070. }
  4071. /* Arm the CQs and then EQs on device */
  4072. lpfc_sli4_arm_cqeq_intr(phba);
  4073. /* Indicate device interrupt mode */
  4074. phba->sli4_hba.intr_enable = 1;
  4075. /* Allow asynchronous mailbox command to go through */
  4076. spin_lock_irq(&phba->hbalock);
  4077. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4078. spin_unlock_irq(&phba->hbalock);
  4079. /* Post receive buffers to the device */
  4080. lpfc_sli4_rb_setup(phba);
  4081. /* Start the ELS watchdog timer */
  4082. /*
  4083. * The driver for SLI4 is not yet ready to process timeouts
  4084. * or interrupts. Once it is, the comment bars can be removed.
  4085. */
  4086. /* mod_timer(&vport->els_tmofunc,
  4087. * jiffies + HZ * (phba->fc_ratov*2)); */
  4088. /* Start heart beat timer */
  4089. mod_timer(&phba->hb_tmofunc,
  4090. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4091. phba->hb_outstanding = 0;
  4092. phba->last_completion_time = jiffies;
  4093. /* Start error attention (ERATT) polling timer */
  4094. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4095. /*
  4096. * The port is ready, set the host's link state to LINK_DOWN
  4097. * in preparation for link interrupts.
  4098. */
  4099. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4100. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4101. lpfc_set_loopback_flag(phba);
  4102. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4103. spin_lock_irq(&phba->hbalock);
  4104. phba->link_state = LPFC_LINK_DOWN;
  4105. spin_unlock_irq(&phba->hbalock);
  4106. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4107. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4108. kfree(vpd);
  4109. return 0;
  4110. } else
  4111. rc = -EIO;
  4112. /* Unset all the queues set up in this routine when error out */
  4113. if (rc)
  4114. lpfc_sli4_queue_unset(phba);
  4115. out_stop_timers:
  4116. if (rc)
  4117. lpfc_stop_hba_timers(phba);
  4118. out_free_vpd:
  4119. kfree(vpd);
  4120. out_free_mbox:
  4121. mempool_free(mboxq, phba->mbox_mem_pool);
  4122. return rc;
  4123. }
  4124. /**
  4125. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4126. * @ptr: context object - pointer to hba structure.
  4127. *
  4128. * This is the callback function for mailbox timer. The mailbox
  4129. * timer is armed when a new mailbox command is issued and the timer
  4130. * is deleted when the mailbox complete. The function is called by
  4131. * the kernel timer code when a mailbox does not complete within
  4132. * expected time. This function wakes up the worker thread to
  4133. * process the mailbox timeout and returns. All the processing is
  4134. * done by the worker thread function lpfc_mbox_timeout_handler.
  4135. **/
  4136. void
  4137. lpfc_mbox_timeout(unsigned long ptr)
  4138. {
  4139. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4140. unsigned long iflag;
  4141. uint32_t tmo_posted;
  4142. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4143. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4144. if (!tmo_posted)
  4145. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4146. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4147. if (!tmo_posted)
  4148. lpfc_worker_wake_up(phba);
  4149. return;
  4150. }
  4151. /**
  4152. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4153. * @phba: Pointer to HBA context object.
  4154. *
  4155. * This function is called from worker thread when a mailbox command times out.
  4156. * The caller is not required to hold any locks. This function will reset the
  4157. * HBA and recover all the pending commands.
  4158. **/
  4159. void
  4160. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4161. {
  4162. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4163. MAILBOX_t *mb = &pmbox->u.mb;
  4164. struct lpfc_sli *psli = &phba->sli;
  4165. struct lpfc_sli_ring *pring;
  4166. /* Check the pmbox pointer first. There is a race condition
  4167. * between the mbox timeout handler getting executed in the
  4168. * worklist and the mailbox actually completing. When this
  4169. * race condition occurs, the mbox_active will be NULL.
  4170. */
  4171. spin_lock_irq(&phba->hbalock);
  4172. if (pmbox == NULL) {
  4173. lpfc_printf_log(phba, KERN_WARNING,
  4174. LOG_MBOX | LOG_SLI,
  4175. "0353 Active Mailbox cleared - mailbox timeout "
  4176. "exiting\n");
  4177. spin_unlock_irq(&phba->hbalock);
  4178. return;
  4179. }
  4180. /* Mbox cmd <mbxCommand> timeout */
  4181. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4182. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4183. mb->mbxCommand,
  4184. phba->pport->port_state,
  4185. phba->sli.sli_flag,
  4186. phba->sli.mbox_active);
  4187. spin_unlock_irq(&phba->hbalock);
  4188. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4189. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4190. * it to fail all oustanding SCSI IO.
  4191. */
  4192. spin_lock_irq(&phba->pport->work_port_lock);
  4193. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4194. spin_unlock_irq(&phba->pport->work_port_lock);
  4195. spin_lock_irq(&phba->hbalock);
  4196. phba->link_state = LPFC_LINK_UNKNOWN;
  4197. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4198. spin_unlock_irq(&phba->hbalock);
  4199. pring = &psli->ring[psli->fcp_ring];
  4200. lpfc_sli_abort_iocb_ring(phba, pring);
  4201. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4202. "0345 Resetting board due to mailbox timeout\n");
  4203. /* Reset the HBA device */
  4204. lpfc_reset_hba(phba);
  4205. }
  4206. /**
  4207. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4208. * @phba: Pointer to HBA context object.
  4209. * @pmbox: Pointer to mailbox object.
  4210. * @flag: Flag indicating how the mailbox need to be processed.
  4211. *
  4212. * This function is called by discovery code and HBA management code
  4213. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4214. * function gets the hbalock to protect the data structures.
  4215. * The mailbox command can be submitted in polling mode, in which case
  4216. * this function will wait in a polling loop for the completion of the
  4217. * mailbox.
  4218. * If the mailbox is submitted in no_wait mode (not polling) the
  4219. * function will submit the command and returns immediately without waiting
  4220. * for the mailbox completion. The no_wait is supported only when HBA
  4221. * is in SLI2/SLI3 mode - interrupts are enabled.
  4222. * The SLI interface allows only one mailbox pending at a time. If the
  4223. * mailbox is issued in polling mode and there is already a mailbox
  4224. * pending, then the function will return an error. If the mailbox is issued
  4225. * in NO_WAIT mode and there is a mailbox pending already, the function
  4226. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4227. * The sli layer owns the mailbox object until the completion of mailbox
  4228. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4229. * return codes the caller owns the mailbox command after the return of
  4230. * the function.
  4231. **/
  4232. static int
  4233. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4234. uint32_t flag)
  4235. {
  4236. MAILBOX_t *mb;
  4237. struct lpfc_sli *psli = &phba->sli;
  4238. uint32_t status, evtctr;
  4239. uint32_t ha_copy;
  4240. int i;
  4241. unsigned long timeout;
  4242. unsigned long drvr_flag = 0;
  4243. uint32_t word0, ldata;
  4244. void __iomem *to_slim;
  4245. int processing_queue = 0;
  4246. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4247. if (!pmbox) {
  4248. /* processing mbox queue from intr_handler */
  4249. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4250. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4251. return MBX_SUCCESS;
  4252. }
  4253. processing_queue = 1;
  4254. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4255. pmbox = lpfc_mbox_get(phba);
  4256. if (!pmbox) {
  4257. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4258. return MBX_SUCCESS;
  4259. }
  4260. }
  4261. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4262. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4263. if(!pmbox->vport) {
  4264. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4265. lpfc_printf_log(phba, KERN_ERR,
  4266. LOG_MBOX | LOG_VPORT,
  4267. "1806 Mbox x%x failed. No vport\n",
  4268. pmbox->u.mb.mbxCommand);
  4269. dump_stack();
  4270. goto out_not_finished;
  4271. }
  4272. }
  4273. /* If the PCI channel is in offline state, do not post mbox. */
  4274. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4275. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4276. goto out_not_finished;
  4277. }
  4278. /* If HBA has a deferred error attention, fail the iocb. */
  4279. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4280. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4281. goto out_not_finished;
  4282. }
  4283. psli = &phba->sli;
  4284. mb = &pmbox->u.mb;
  4285. status = MBX_SUCCESS;
  4286. if (phba->link_state == LPFC_HBA_ERROR) {
  4287. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4288. /* Mbox command <mbxCommand> cannot issue */
  4289. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4290. "(%d):0311 Mailbox command x%x cannot "
  4291. "issue Data: x%x x%x\n",
  4292. pmbox->vport ? pmbox->vport->vpi : 0,
  4293. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4294. goto out_not_finished;
  4295. }
  4296. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4297. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4298. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4299. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4300. "(%d):2528 Mailbox command x%x cannot "
  4301. "issue Data: x%x x%x\n",
  4302. pmbox->vport ? pmbox->vport->vpi : 0,
  4303. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4304. goto out_not_finished;
  4305. }
  4306. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4307. /* Polling for a mbox command when another one is already active
  4308. * is not allowed in SLI. Also, the driver must have established
  4309. * SLI2 mode to queue and process multiple mbox commands.
  4310. */
  4311. if (flag & MBX_POLL) {
  4312. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4313. /* Mbox command <mbxCommand> cannot issue */
  4314. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4315. "(%d):2529 Mailbox command x%x "
  4316. "cannot issue Data: x%x x%x\n",
  4317. pmbox->vport ? pmbox->vport->vpi : 0,
  4318. pmbox->u.mb.mbxCommand,
  4319. psli->sli_flag, flag);
  4320. goto out_not_finished;
  4321. }
  4322. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4323. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4324. /* Mbox command <mbxCommand> cannot issue */
  4325. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4326. "(%d):2530 Mailbox command x%x "
  4327. "cannot issue Data: x%x x%x\n",
  4328. pmbox->vport ? pmbox->vport->vpi : 0,
  4329. pmbox->u.mb.mbxCommand,
  4330. psli->sli_flag, flag);
  4331. goto out_not_finished;
  4332. }
  4333. /* Another mailbox command is still being processed, queue this
  4334. * command to be processed later.
  4335. */
  4336. lpfc_mbox_put(phba, pmbox);
  4337. /* Mbox cmd issue - BUSY */
  4338. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4339. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4340. "x%x x%x x%x x%x\n",
  4341. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4342. mb->mbxCommand, phba->pport->port_state,
  4343. psli->sli_flag, flag);
  4344. psli->slistat.mbox_busy++;
  4345. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4346. if (pmbox->vport) {
  4347. lpfc_debugfs_disc_trc(pmbox->vport,
  4348. LPFC_DISC_TRC_MBOX_VPORT,
  4349. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4350. (uint32_t)mb->mbxCommand,
  4351. mb->un.varWords[0], mb->un.varWords[1]);
  4352. }
  4353. else {
  4354. lpfc_debugfs_disc_trc(phba->pport,
  4355. LPFC_DISC_TRC_MBOX,
  4356. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4357. (uint32_t)mb->mbxCommand,
  4358. mb->un.varWords[0], mb->un.varWords[1]);
  4359. }
  4360. return MBX_BUSY;
  4361. }
  4362. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4363. /* If we are not polling, we MUST be in SLI2 mode */
  4364. if (flag != MBX_POLL) {
  4365. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4366. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4367. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4368. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4369. /* Mbox command <mbxCommand> cannot issue */
  4370. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4371. "(%d):2531 Mailbox command x%x "
  4372. "cannot issue Data: x%x x%x\n",
  4373. pmbox->vport ? pmbox->vport->vpi : 0,
  4374. pmbox->u.mb.mbxCommand,
  4375. psli->sli_flag, flag);
  4376. goto out_not_finished;
  4377. }
  4378. /* timeout active mbox command */
  4379. mod_timer(&psli->mbox_tmo, (jiffies +
  4380. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4381. }
  4382. /* Mailbox cmd <cmd> issue */
  4383. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4384. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4385. "x%x\n",
  4386. pmbox->vport ? pmbox->vport->vpi : 0,
  4387. mb->mbxCommand, phba->pport->port_state,
  4388. psli->sli_flag, flag);
  4389. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4390. if (pmbox->vport) {
  4391. lpfc_debugfs_disc_trc(pmbox->vport,
  4392. LPFC_DISC_TRC_MBOX_VPORT,
  4393. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4394. (uint32_t)mb->mbxCommand,
  4395. mb->un.varWords[0], mb->un.varWords[1]);
  4396. }
  4397. else {
  4398. lpfc_debugfs_disc_trc(phba->pport,
  4399. LPFC_DISC_TRC_MBOX,
  4400. "MBOX Send: cmd:x%x mb:x%x x%x",
  4401. (uint32_t)mb->mbxCommand,
  4402. mb->un.varWords[0], mb->un.varWords[1]);
  4403. }
  4404. }
  4405. psli->slistat.mbox_cmd++;
  4406. evtctr = psli->slistat.mbox_event;
  4407. /* next set own bit for the adapter and copy over command word */
  4408. mb->mbxOwner = OWN_CHIP;
  4409. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4410. /* First copy command data to host SLIM area */
  4411. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4412. } else {
  4413. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4414. /* copy command data into host mbox for cmpl */
  4415. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4416. }
  4417. /* First copy mbox command data to HBA SLIM, skip past first
  4418. word */
  4419. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4420. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4421. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4422. /* Next copy over first word, with mbxOwner set */
  4423. ldata = *((uint32_t *)mb);
  4424. to_slim = phba->MBslimaddr;
  4425. writel(ldata, to_slim);
  4426. readl(to_slim); /* flush */
  4427. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4428. /* switch over to host mailbox */
  4429. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4430. }
  4431. }
  4432. wmb();
  4433. switch (flag) {
  4434. case MBX_NOWAIT:
  4435. /* Set up reference to mailbox command */
  4436. psli->mbox_active = pmbox;
  4437. /* Interrupt board to do it */
  4438. writel(CA_MBATT, phba->CAregaddr);
  4439. readl(phba->CAregaddr); /* flush */
  4440. /* Don't wait for it to finish, just return */
  4441. break;
  4442. case MBX_POLL:
  4443. /* Set up null reference to mailbox command */
  4444. psli->mbox_active = NULL;
  4445. /* Interrupt board to do it */
  4446. writel(CA_MBATT, phba->CAregaddr);
  4447. readl(phba->CAregaddr); /* flush */
  4448. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4449. /* First read mbox status word */
  4450. word0 = *((uint32_t *)phba->mbox);
  4451. word0 = le32_to_cpu(word0);
  4452. } else {
  4453. /* First read mbox status word */
  4454. word0 = readl(phba->MBslimaddr);
  4455. }
  4456. /* Read the HBA Host Attention Register */
  4457. ha_copy = readl(phba->HAregaddr);
  4458. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4459. mb->mbxCommand) *
  4460. 1000) + jiffies;
  4461. i = 0;
  4462. /* Wait for command to complete */
  4463. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4464. (!(ha_copy & HA_MBATT) &&
  4465. (phba->link_state > LPFC_WARM_START))) {
  4466. if (time_after(jiffies, timeout)) {
  4467. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4468. spin_unlock_irqrestore(&phba->hbalock,
  4469. drvr_flag);
  4470. goto out_not_finished;
  4471. }
  4472. /* Check if we took a mbox interrupt while we were
  4473. polling */
  4474. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4475. && (evtctr != psli->slistat.mbox_event))
  4476. break;
  4477. if (i++ > 10) {
  4478. spin_unlock_irqrestore(&phba->hbalock,
  4479. drvr_flag);
  4480. msleep(1);
  4481. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4482. }
  4483. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4484. /* First copy command data */
  4485. word0 = *((uint32_t *)phba->mbox);
  4486. word0 = le32_to_cpu(word0);
  4487. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4488. MAILBOX_t *slimmb;
  4489. uint32_t slimword0;
  4490. /* Check real SLIM for any errors */
  4491. slimword0 = readl(phba->MBslimaddr);
  4492. slimmb = (MAILBOX_t *) & slimword0;
  4493. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4494. && slimmb->mbxStatus) {
  4495. psli->sli_flag &=
  4496. ~LPFC_SLI_ACTIVE;
  4497. word0 = slimword0;
  4498. }
  4499. }
  4500. } else {
  4501. /* First copy command data */
  4502. word0 = readl(phba->MBslimaddr);
  4503. }
  4504. /* Read the HBA Host Attention Register */
  4505. ha_copy = readl(phba->HAregaddr);
  4506. }
  4507. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4508. /* copy results back to user */
  4509. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4510. } else {
  4511. /* First copy command data */
  4512. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4513. MAILBOX_CMD_SIZE);
  4514. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4515. pmbox->context2) {
  4516. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4517. phba->MBslimaddr + DMP_RSP_OFFSET,
  4518. mb->un.varDmp.word_cnt);
  4519. }
  4520. }
  4521. writel(HA_MBATT, phba->HAregaddr);
  4522. readl(phba->HAregaddr); /* flush */
  4523. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4524. status = mb->mbxStatus;
  4525. }
  4526. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4527. return status;
  4528. out_not_finished:
  4529. if (processing_queue) {
  4530. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4531. lpfc_mbox_cmpl_put(phba, pmbox);
  4532. }
  4533. return MBX_NOT_FINISHED;
  4534. }
  4535. /**
  4536. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4537. * @phba: Pointer to HBA context object.
  4538. *
  4539. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4540. * the driver internal pending mailbox queue. It will then try to wait out the
  4541. * possible outstanding mailbox command before return.
  4542. *
  4543. * Returns:
  4544. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4545. * the outstanding mailbox command timed out.
  4546. **/
  4547. static int
  4548. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4549. {
  4550. struct lpfc_sli *psli = &phba->sli;
  4551. uint8_t actcmd = MBX_HEARTBEAT;
  4552. int rc = 0;
  4553. unsigned long timeout;
  4554. /* Mark the asynchronous mailbox command posting as blocked */
  4555. spin_lock_irq(&phba->hbalock);
  4556. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4557. if (phba->sli.mbox_active)
  4558. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4559. spin_unlock_irq(&phba->hbalock);
  4560. /* Determine how long we might wait for the active mailbox
  4561. * command to be gracefully completed by firmware.
  4562. */
  4563. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4564. jiffies;
  4565. /* Wait for the outstnading mailbox command to complete */
  4566. while (phba->sli.mbox_active) {
  4567. /* Check active mailbox complete status every 2ms */
  4568. msleep(2);
  4569. if (time_after(jiffies, timeout)) {
  4570. /* Timeout, marked the outstanding cmd not complete */
  4571. rc = 1;
  4572. break;
  4573. }
  4574. }
  4575. /* Can not cleanly block async mailbox command, fails it */
  4576. if (rc) {
  4577. spin_lock_irq(&phba->hbalock);
  4578. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4579. spin_unlock_irq(&phba->hbalock);
  4580. }
  4581. return rc;
  4582. }
  4583. /**
  4584. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4585. * @phba: Pointer to HBA context object.
  4586. *
  4587. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4588. * commands from the driver internal pending mailbox queue. It makes sure
  4589. * that there is no outstanding mailbox command before resuming posting
  4590. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4591. * mailbox command, it will try to wait it out before resuming asynchronous
  4592. * mailbox command posting.
  4593. **/
  4594. static void
  4595. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4596. {
  4597. struct lpfc_sli *psli = &phba->sli;
  4598. spin_lock_irq(&phba->hbalock);
  4599. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4600. /* Asynchronous mailbox posting is not blocked, do nothing */
  4601. spin_unlock_irq(&phba->hbalock);
  4602. return;
  4603. }
  4604. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4605. * successful or timeout, after timing-out the outstanding mailbox
  4606. * command shall always be removed, so just unblock posting async
  4607. * mailbox command and resume
  4608. */
  4609. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4610. spin_unlock_irq(&phba->hbalock);
  4611. /* wake up worker thread to post asynchronlous mailbox command */
  4612. lpfc_worker_wake_up(phba);
  4613. }
  4614. /**
  4615. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4616. * @phba: Pointer to HBA context object.
  4617. * @mboxq: Pointer to mailbox object.
  4618. *
  4619. * The function posts a mailbox to the port. The mailbox is expected
  4620. * to be comletely filled in and ready for the port to operate on it.
  4621. * This routine executes a synchronous completion operation on the
  4622. * mailbox by polling for its completion.
  4623. *
  4624. * The caller must not be holding any locks when calling this routine.
  4625. *
  4626. * Returns:
  4627. * MBX_SUCCESS - mailbox posted successfully
  4628. * Any of the MBX error values.
  4629. **/
  4630. static int
  4631. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4632. {
  4633. int rc = MBX_SUCCESS;
  4634. unsigned long iflag;
  4635. uint32_t db_ready;
  4636. uint32_t mcqe_status;
  4637. uint32_t mbx_cmnd;
  4638. unsigned long timeout;
  4639. struct lpfc_sli *psli = &phba->sli;
  4640. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4641. struct lpfc_bmbx_create *mbox_rgn;
  4642. struct dma_address *dma_address;
  4643. struct lpfc_register bmbx_reg;
  4644. /*
  4645. * Only one mailbox can be active to the bootstrap mailbox region
  4646. * at a time and there is no queueing provided.
  4647. */
  4648. spin_lock_irqsave(&phba->hbalock, iflag);
  4649. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4650. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4651. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4652. "(%d):2532 Mailbox command x%x (x%x) "
  4653. "cannot issue Data: x%x x%x\n",
  4654. mboxq->vport ? mboxq->vport->vpi : 0,
  4655. mboxq->u.mb.mbxCommand,
  4656. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4657. psli->sli_flag, MBX_POLL);
  4658. return MBXERR_ERROR;
  4659. }
  4660. /* The server grabs the token and owns it until release */
  4661. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4662. phba->sli.mbox_active = mboxq;
  4663. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4664. /*
  4665. * Initialize the bootstrap memory region to avoid stale data areas
  4666. * in the mailbox post. Then copy the caller's mailbox contents to
  4667. * the bmbx mailbox region.
  4668. */
  4669. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4670. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4671. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4672. sizeof(struct lpfc_mqe));
  4673. /* Post the high mailbox dma address to the port and wait for ready. */
  4674. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4675. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4676. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4677. * 1000) + jiffies;
  4678. do {
  4679. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4680. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4681. if (!db_ready)
  4682. msleep(2);
  4683. if (time_after(jiffies, timeout)) {
  4684. rc = MBXERR_ERROR;
  4685. goto exit;
  4686. }
  4687. } while (!db_ready);
  4688. /* Post the low mailbox dma address to the port. */
  4689. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4690. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4691. * 1000) + jiffies;
  4692. do {
  4693. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4694. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4695. if (!db_ready)
  4696. msleep(2);
  4697. if (time_after(jiffies, timeout)) {
  4698. rc = MBXERR_ERROR;
  4699. goto exit;
  4700. }
  4701. } while (!db_ready);
  4702. /*
  4703. * Read the CQ to ensure the mailbox has completed.
  4704. * If so, update the mailbox status so that the upper layers
  4705. * can complete the request normally.
  4706. */
  4707. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4708. sizeof(struct lpfc_mqe));
  4709. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4710. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4711. sizeof(struct lpfc_mcqe));
  4712. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4713. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4714. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4715. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4716. rc = MBXERR_ERROR;
  4717. }
  4718. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4719. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4720. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4721. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4722. mboxq->vport ? mboxq->vport->vpi : 0,
  4723. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4724. bf_get(lpfc_mqe_status, mb),
  4725. mb->un.mb_words[0], mb->un.mb_words[1],
  4726. mb->un.mb_words[2], mb->un.mb_words[3],
  4727. mb->un.mb_words[4], mb->un.mb_words[5],
  4728. mb->un.mb_words[6], mb->un.mb_words[7],
  4729. mb->un.mb_words[8], mb->un.mb_words[9],
  4730. mb->un.mb_words[10], mb->un.mb_words[11],
  4731. mb->un.mb_words[12], mboxq->mcqe.word0,
  4732. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4733. mboxq->mcqe.trailer);
  4734. exit:
  4735. /* We are holding the token, no needed for lock when release */
  4736. spin_lock_irqsave(&phba->hbalock, iflag);
  4737. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4738. phba->sli.mbox_active = NULL;
  4739. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4740. return rc;
  4741. }
  4742. /**
  4743. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4744. * @phba: Pointer to HBA context object.
  4745. * @pmbox: Pointer to mailbox object.
  4746. * @flag: Flag indicating how the mailbox need to be processed.
  4747. *
  4748. * This function is called by discovery code and HBA management code to submit
  4749. * a mailbox command to firmware with SLI-4 interface spec.
  4750. *
  4751. * Return codes the caller owns the mailbox command after the return of the
  4752. * function.
  4753. **/
  4754. static int
  4755. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4756. uint32_t flag)
  4757. {
  4758. struct lpfc_sli *psli = &phba->sli;
  4759. unsigned long iflags;
  4760. int rc;
  4761. /* Detect polling mode and jump to a handler */
  4762. if (!phba->sli4_hba.intr_enable) {
  4763. if (flag == MBX_POLL)
  4764. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4765. else
  4766. rc = -EIO;
  4767. if (rc != MBX_SUCCESS)
  4768. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4769. "(%d):2541 Mailbox command x%x "
  4770. "(x%x) cannot issue Data: x%x x%x\n",
  4771. mboxq->vport ? mboxq->vport->vpi : 0,
  4772. mboxq->u.mb.mbxCommand,
  4773. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4774. psli->sli_flag, flag);
  4775. return rc;
  4776. } else if (flag == MBX_POLL) {
  4777. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4778. "(%d):2542 Try to issue mailbox command "
  4779. "x%x (x%x) synchronously ahead of async"
  4780. "mailbox command queue: x%x x%x\n",
  4781. mboxq->vport ? mboxq->vport->vpi : 0,
  4782. mboxq->u.mb.mbxCommand,
  4783. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4784. psli->sli_flag, flag);
  4785. /* Try to block the asynchronous mailbox posting */
  4786. rc = lpfc_sli4_async_mbox_block(phba);
  4787. if (!rc) {
  4788. /* Successfully blocked, now issue sync mbox cmd */
  4789. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4790. if (rc != MBX_SUCCESS)
  4791. lpfc_printf_log(phba, KERN_ERR,
  4792. LOG_MBOX | LOG_SLI,
  4793. "(%d):2597 Mailbox command "
  4794. "x%x (x%x) cannot issue "
  4795. "Data: x%x x%x\n",
  4796. mboxq->vport ?
  4797. mboxq->vport->vpi : 0,
  4798. mboxq->u.mb.mbxCommand,
  4799. lpfc_sli4_mbox_opcode_get(phba,
  4800. mboxq),
  4801. psli->sli_flag, flag);
  4802. /* Unblock the async mailbox posting afterward */
  4803. lpfc_sli4_async_mbox_unblock(phba);
  4804. }
  4805. return rc;
  4806. }
  4807. /* Now, interrupt mode asynchrous mailbox command */
  4808. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4809. if (rc) {
  4810. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4811. "(%d):2543 Mailbox command x%x (x%x) "
  4812. "cannot issue Data: x%x x%x\n",
  4813. mboxq->vport ? mboxq->vport->vpi : 0,
  4814. mboxq->u.mb.mbxCommand,
  4815. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4816. psli->sli_flag, flag);
  4817. goto out_not_finished;
  4818. }
  4819. rc = lpfc_mbox_dev_check(phba);
  4820. if (unlikely(rc)) {
  4821. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4822. "(%d):2544 Mailbox command x%x (x%x) "
  4823. "cannot issue Data: x%x x%x\n",
  4824. mboxq->vport ? mboxq->vport->vpi : 0,
  4825. mboxq->u.mb.mbxCommand,
  4826. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4827. psli->sli_flag, flag);
  4828. goto out_not_finished;
  4829. }
  4830. /* Put the mailbox command to the driver internal FIFO */
  4831. psli->slistat.mbox_busy++;
  4832. spin_lock_irqsave(&phba->hbalock, iflags);
  4833. lpfc_mbox_put(phba, mboxq);
  4834. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4835. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4836. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4837. "x%x (x%x) x%x x%x x%x\n",
  4838. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4839. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4840. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4841. phba->pport->port_state,
  4842. psli->sli_flag, MBX_NOWAIT);
  4843. /* Wake up worker thread to transport mailbox command from head */
  4844. lpfc_worker_wake_up(phba);
  4845. return MBX_BUSY;
  4846. out_not_finished:
  4847. return MBX_NOT_FINISHED;
  4848. }
  4849. /**
  4850. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4851. * @phba: Pointer to HBA context object.
  4852. *
  4853. * This function is called by worker thread to send a mailbox command to
  4854. * SLI4 HBA firmware.
  4855. *
  4856. **/
  4857. int
  4858. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4859. {
  4860. struct lpfc_sli *psli = &phba->sli;
  4861. LPFC_MBOXQ_t *mboxq;
  4862. int rc = MBX_SUCCESS;
  4863. unsigned long iflags;
  4864. struct lpfc_mqe *mqe;
  4865. uint32_t mbx_cmnd;
  4866. /* Check interrupt mode before post async mailbox command */
  4867. if (unlikely(!phba->sli4_hba.intr_enable))
  4868. return MBX_NOT_FINISHED;
  4869. /* Check for mailbox command service token */
  4870. spin_lock_irqsave(&phba->hbalock, iflags);
  4871. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4872. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4873. return MBX_NOT_FINISHED;
  4874. }
  4875. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4876. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4877. return MBX_NOT_FINISHED;
  4878. }
  4879. if (unlikely(phba->sli.mbox_active)) {
  4880. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4881. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4882. "0384 There is pending active mailbox cmd\n");
  4883. return MBX_NOT_FINISHED;
  4884. }
  4885. /* Take the mailbox command service token */
  4886. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4887. /* Get the next mailbox command from head of queue */
  4888. mboxq = lpfc_mbox_get(phba);
  4889. /* If no more mailbox command waiting for post, we're done */
  4890. if (!mboxq) {
  4891. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4892. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4893. return MBX_SUCCESS;
  4894. }
  4895. phba->sli.mbox_active = mboxq;
  4896. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4897. /* Check device readiness for posting mailbox command */
  4898. rc = lpfc_mbox_dev_check(phba);
  4899. if (unlikely(rc))
  4900. /* Driver clean routine will clean up pending mailbox */
  4901. goto out_not_finished;
  4902. /* Prepare the mbox command to be posted */
  4903. mqe = &mboxq->u.mqe;
  4904. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4905. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4906. mod_timer(&psli->mbox_tmo, (jiffies +
  4907. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4908. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4909. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4910. "x%x x%x\n",
  4911. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4912. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4913. phba->pport->port_state, psli->sli_flag);
  4914. if (mbx_cmnd != MBX_HEARTBEAT) {
  4915. if (mboxq->vport) {
  4916. lpfc_debugfs_disc_trc(mboxq->vport,
  4917. LPFC_DISC_TRC_MBOX_VPORT,
  4918. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4919. mbx_cmnd, mqe->un.mb_words[0],
  4920. mqe->un.mb_words[1]);
  4921. } else {
  4922. lpfc_debugfs_disc_trc(phba->pport,
  4923. LPFC_DISC_TRC_MBOX,
  4924. "MBOX Send: cmd:x%x mb:x%x x%x",
  4925. mbx_cmnd, mqe->un.mb_words[0],
  4926. mqe->un.mb_words[1]);
  4927. }
  4928. }
  4929. psli->slistat.mbox_cmd++;
  4930. /* Post the mailbox command to the port */
  4931. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4932. if (rc != MBX_SUCCESS) {
  4933. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4934. "(%d):2533 Mailbox command x%x (x%x) "
  4935. "cannot issue Data: x%x x%x\n",
  4936. mboxq->vport ? mboxq->vport->vpi : 0,
  4937. mboxq->u.mb.mbxCommand,
  4938. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4939. psli->sli_flag, MBX_NOWAIT);
  4940. goto out_not_finished;
  4941. }
  4942. return rc;
  4943. out_not_finished:
  4944. spin_lock_irqsave(&phba->hbalock, iflags);
  4945. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4946. __lpfc_mbox_cmpl_put(phba, mboxq);
  4947. /* Release the token */
  4948. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4949. phba->sli.mbox_active = NULL;
  4950. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4951. return MBX_NOT_FINISHED;
  4952. }
  4953. /**
  4954. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4955. * @phba: Pointer to HBA context object.
  4956. * @pmbox: Pointer to mailbox object.
  4957. * @flag: Flag indicating how the mailbox need to be processed.
  4958. *
  4959. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4960. * the API jump table function pointer from the lpfc_hba struct.
  4961. *
  4962. * Return codes the caller owns the mailbox command after the return of the
  4963. * function.
  4964. **/
  4965. int
  4966. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4967. {
  4968. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4969. }
  4970. /**
  4971. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4972. * @phba: The hba struct for which this call is being executed.
  4973. * @dev_grp: The HBA PCI-Device group number.
  4974. *
  4975. * This routine sets up the mbox interface API function jump table in @phba
  4976. * struct.
  4977. * Returns: 0 - success, -ENODEV - failure.
  4978. **/
  4979. int
  4980. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4981. {
  4982. switch (dev_grp) {
  4983. case LPFC_PCI_DEV_LP:
  4984. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4985. phba->lpfc_sli_handle_slow_ring_event =
  4986. lpfc_sli_handle_slow_ring_event_s3;
  4987. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4988. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4989. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4990. break;
  4991. case LPFC_PCI_DEV_OC:
  4992. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4993. phba->lpfc_sli_handle_slow_ring_event =
  4994. lpfc_sli_handle_slow_ring_event_s4;
  4995. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4996. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4997. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4998. break;
  4999. default:
  5000. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5001. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5002. dev_grp);
  5003. return -ENODEV;
  5004. break;
  5005. }
  5006. return 0;
  5007. }
  5008. /**
  5009. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5010. * @phba: Pointer to HBA context object.
  5011. * @pring: Pointer to driver SLI ring object.
  5012. * @piocb: Pointer to address of newly added command iocb.
  5013. *
  5014. * This function is called with hbalock held to add a command
  5015. * iocb to the txq when SLI layer cannot submit the command iocb
  5016. * to the ring.
  5017. **/
  5018. static void
  5019. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5020. struct lpfc_iocbq *piocb)
  5021. {
  5022. /* Insert the caller's iocb in the txq tail for later processing. */
  5023. list_add_tail(&piocb->list, &pring->txq);
  5024. pring->txq_cnt++;
  5025. }
  5026. /**
  5027. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5028. * @phba: Pointer to HBA context object.
  5029. * @pring: Pointer to driver SLI ring object.
  5030. * @piocb: Pointer to address of newly added command iocb.
  5031. *
  5032. * This function is called with hbalock held before a new
  5033. * iocb is submitted to the firmware. This function checks
  5034. * txq to flush the iocbs in txq to Firmware before
  5035. * submitting new iocbs to the Firmware.
  5036. * If there are iocbs in the txq which need to be submitted
  5037. * to firmware, lpfc_sli_next_iocb returns the first element
  5038. * of the txq after dequeuing it from txq.
  5039. * If there is no iocb in the txq then the function will return
  5040. * *piocb and *piocb is set to NULL. Caller needs to check
  5041. * *piocb to find if there are more commands in the txq.
  5042. **/
  5043. static struct lpfc_iocbq *
  5044. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5045. struct lpfc_iocbq **piocb)
  5046. {
  5047. struct lpfc_iocbq * nextiocb;
  5048. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5049. if (!nextiocb) {
  5050. nextiocb = *piocb;
  5051. *piocb = NULL;
  5052. }
  5053. return nextiocb;
  5054. }
  5055. /**
  5056. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5057. * @phba: Pointer to HBA context object.
  5058. * @ring_number: SLI ring number to issue iocb on.
  5059. * @piocb: Pointer to command iocb.
  5060. * @flag: Flag indicating if this command can be put into txq.
  5061. *
  5062. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5063. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5064. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5065. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5066. * this function allows only iocbs for posting buffers. This function finds
  5067. * next available slot in the command ring and posts the command to the
  5068. * available slot and writes the port attention register to request HBA start
  5069. * processing new iocb. If there is no slot available in the ring and
  5070. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5071. * the function returns IOCB_BUSY.
  5072. *
  5073. * This function is called with hbalock held. The function will return success
  5074. * after it successfully submit the iocb to firmware or after adding to the
  5075. * txq.
  5076. **/
  5077. static int
  5078. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5079. struct lpfc_iocbq *piocb, uint32_t flag)
  5080. {
  5081. struct lpfc_iocbq *nextiocb;
  5082. IOCB_t *iocb;
  5083. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5084. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5085. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5086. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5087. lpfc_printf_log(phba, KERN_ERR,
  5088. LOG_SLI | LOG_VPORT,
  5089. "1807 IOCB x%x failed. No vport\n",
  5090. piocb->iocb.ulpCommand);
  5091. dump_stack();
  5092. return IOCB_ERROR;
  5093. }
  5094. /* If the PCI channel is in offline state, do not post iocbs. */
  5095. if (unlikely(pci_channel_offline(phba->pcidev)))
  5096. return IOCB_ERROR;
  5097. /* If HBA has a deferred error attention, fail the iocb. */
  5098. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5099. return IOCB_ERROR;
  5100. /*
  5101. * We should never get an IOCB if we are in a < LINK_DOWN state
  5102. */
  5103. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5104. return IOCB_ERROR;
  5105. /*
  5106. * Check to see if we are blocking IOCB processing because of a
  5107. * outstanding event.
  5108. */
  5109. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5110. goto iocb_busy;
  5111. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5112. /*
  5113. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5114. * can be issued if the link is not up.
  5115. */
  5116. switch (piocb->iocb.ulpCommand) {
  5117. case CMD_GEN_REQUEST64_CR:
  5118. case CMD_GEN_REQUEST64_CX:
  5119. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5120. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5121. FC_FCP_CMND) ||
  5122. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5123. MENLO_TRANSPORT_TYPE))
  5124. goto iocb_busy;
  5125. break;
  5126. case CMD_QUE_RING_BUF_CN:
  5127. case CMD_QUE_RING_BUF64_CN:
  5128. /*
  5129. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5130. * completion, iocb_cmpl MUST be 0.
  5131. */
  5132. if (piocb->iocb_cmpl)
  5133. piocb->iocb_cmpl = NULL;
  5134. /*FALLTHROUGH*/
  5135. case CMD_CREATE_XRI_CR:
  5136. case CMD_CLOSE_XRI_CN:
  5137. case CMD_CLOSE_XRI_CX:
  5138. break;
  5139. default:
  5140. goto iocb_busy;
  5141. }
  5142. /*
  5143. * For FCP commands, we must be in a state where we can process link
  5144. * attention events.
  5145. */
  5146. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5147. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5148. goto iocb_busy;
  5149. }
  5150. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5151. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5152. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5153. if (iocb)
  5154. lpfc_sli_update_ring(phba, pring);
  5155. else
  5156. lpfc_sli_update_full_ring(phba, pring);
  5157. if (!piocb)
  5158. return IOCB_SUCCESS;
  5159. goto out_busy;
  5160. iocb_busy:
  5161. pring->stats.iocb_cmd_delay++;
  5162. out_busy:
  5163. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5164. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5165. return IOCB_SUCCESS;
  5166. }
  5167. return IOCB_BUSY;
  5168. }
  5169. /**
  5170. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5171. * @phba: Pointer to HBA context object.
  5172. * @piocb: Pointer to command iocb.
  5173. * @sglq: Pointer to the scatter gather queue object.
  5174. *
  5175. * This routine converts the bpl or bde that is in the IOCB
  5176. * to a sgl list for the sli4 hardware. The physical address
  5177. * of the bpl/bde is converted back to a virtual address.
  5178. * If the IOCB contains a BPL then the list of BDE's is
  5179. * converted to sli4_sge's. If the IOCB contains a single
  5180. * BDE then it is converted to a single sli_sge.
  5181. * The IOCB is still in cpu endianess so the contents of
  5182. * the bpl can be used without byte swapping.
  5183. *
  5184. * Returns valid XRI = Success, NO_XRI = Failure.
  5185. **/
  5186. static uint16_t
  5187. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5188. struct lpfc_sglq *sglq)
  5189. {
  5190. uint16_t xritag = NO_XRI;
  5191. struct ulp_bde64 *bpl = NULL;
  5192. struct ulp_bde64 bde;
  5193. struct sli4_sge *sgl = NULL;
  5194. IOCB_t *icmd;
  5195. int numBdes = 0;
  5196. int i = 0;
  5197. if (!piocbq || !sglq)
  5198. return xritag;
  5199. sgl = (struct sli4_sge *)sglq->sgl;
  5200. icmd = &piocbq->iocb;
  5201. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5202. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5203. sizeof(struct ulp_bde64);
  5204. /* The addrHigh and addrLow fields within the IOCB
  5205. * have not been byteswapped yet so there is no
  5206. * need to swap them back.
  5207. */
  5208. bpl = (struct ulp_bde64 *)
  5209. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5210. if (!bpl)
  5211. return xritag;
  5212. for (i = 0; i < numBdes; i++) {
  5213. /* Should already be byte swapped. */
  5214. sgl->addr_hi = bpl->addrHigh;
  5215. sgl->addr_lo = bpl->addrLow;
  5216. /* swap the size field back to the cpu so we
  5217. * can assign it to the sgl.
  5218. */
  5219. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5220. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5221. if ((i+1) == numBdes)
  5222. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5223. else
  5224. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5225. sgl->word2 = cpu_to_le32(sgl->word2);
  5226. sgl->word3 = cpu_to_le32(sgl->word3);
  5227. bpl++;
  5228. sgl++;
  5229. }
  5230. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5231. /* The addrHigh and addrLow fields of the BDE have not
  5232. * been byteswapped yet so they need to be swapped
  5233. * before putting them in the sgl.
  5234. */
  5235. sgl->addr_hi =
  5236. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5237. sgl->addr_lo =
  5238. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5239. bf_set(lpfc_sli4_sge_len, sgl,
  5240. icmd->un.genreq64.bdl.bdeSize);
  5241. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5242. sgl->word2 = cpu_to_le32(sgl->word2);
  5243. sgl->word3 = cpu_to_le32(sgl->word3);
  5244. }
  5245. return sglq->sli4_xritag;
  5246. }
  5247. /**
  5248. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5249. * @phba: Pointer to HBA context object.
  5250. * @piocb: Pointer to command iocb.
  5251. *
  5252. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5253. * distribution.
  5254. *
  5255. * Return: index into SLI4 fast-path FCP queue index.
  5256. **/
  5257. static uint32_t
  5258. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  5259. {
  5260. static uint32_t fcp_qidx;
  5261. return fcp_qidx++ % phba->cfg_fcp_wq_count;
  5262. }
  5263. /**
  5264. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5265. * @phba: Pointer to HBA context object.
  5266. * @piocb: Pointer to command iocb.
  5267. * @wqe: Pointer to the work queue entry.
  5268. *
  5269. * This routine converts the iocb command to its Work Queue Entry
  5270. * equivalent. The wqe pointer should not have any fields set when
  5271. * this routine is called because it will memcpy over them.
  5272. * This routine does not set the CQ_ID or the WQEC bits in the
  5273. * wqe.
  5274. *
  5275. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5276. **/
  5277. static int
  5278. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5279. union lpfc_wqe *wqe)
  5280. {
  5281. uint32_t payload_len = 0;
  5282. uint8_t ct = 0;
  5283. uint32_t fip;
  5284. uint32_t abort_tag;
  5285. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5286. uint8_t cmnd;
  5287. uint16_t xritag;
  5288. struct ulp_bde64 *bpl = NULL;
  5289. fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
  5290. /* The fcp commands will set command type */
  5291. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5292. command_type = FCP_COMMAND;
  5293. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS))
  5294. command_type = ELS_COMMAND_FIP;
  5295. else
  5296. command_type = ELS_COMMAND_NON_FIP;
  5297. /* Some of the fields are in the right position already */
  5298. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5299. abort_tag = (uint32_t) iocbq->iotag;
  5300. xritag = iocbq->sli4_xritag;
  5301. wqe->words[7] = 0; /* The ct field has moved so reset */
  5302. /* words0-2 bpl convert bde */
  5303. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5304. bpl = (struct ulp_bde64 *)
  5305. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5306. if (!bpl)
  5307. return IOCB_ERROR;
  5308. /* Should already be byte swapped. */
  5309. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5310. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5311. /* swap the size field back to the cpu so we
  5312. * can assign it to the sgl.
  5313. */
  5314. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5315. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5316. } else
  5317. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5318. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5319. cmnd = iocbq->iocb.ulpCommand;
  5320. switch (iocbq->iocb.ulpCommand) {
  5321. case CMD_ELS_REQUEST64_CR:
  5322. if (!iocbq->iocb.ulpLe) {
  5323. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5324. "2007 Only Limited Edition cmd Format"
  5325. " supported 0x%x\n",
  5326. iocbq->iocb.ulpCommand);
  5327. return IOCB_ERROR;
  5328. }
  5329. wqe->els_req.payload_len = payload_len;
  5330. /* Els_reguest64 has a TMO */
  5331. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5332. iocbq->iocb.ulpTimeout);
  5333. /* Need a VF for word 4 set the vf bit*/
  5334. bf_set(els_req64_vf, &wqe->els_req, 0);
  5335. /* And a VFID for word 12 */
  5336. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5337. /*
  5338. * Set ct field to 3, indicates that the context_tag field
  5339. * contains the FCFI and remote N_Port_ID is
  5340. * in word 5.
  5341. */
  5342. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5343. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5344. iocbq->iocb.ulpContext);
  5345. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5346. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5347. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5348. break;
  5349. case CMD_XMIT_SEQUENCE64_CR:
  5350. /* word3 iocb=io_tag32 wqe=payload_offset */
  5351. /* payload offset used for multilpe outstanding
  5352. * sequences on the same exchange
  5353. */
  5354. wqe->words[3] = 0;
  5355. /* word4 relative_offset memcpy */
  5356. /* word5 r_ctl/df_ctl memcpy */
  5357. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5358. wqe->xmit_sequence.xmit_len = payload_len;
  5359. break;
  5360. case CMD_XMIT_BCAST64_CN:
  5361. /* word3 iocb=iotag32 wqe=payload_len */
  5362. wqe->words[3] = 0; /* no definition for this in wqe */
  5363. /* word4 iocb=rsvd wqe=rsvd */
  5364. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5365. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5366. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5367. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5368. break;
  5369. case CMD_FCP_IWRITE64_CR:
  5370. command_type = FCP_COMMAND_DATA_OUT;
  5371. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5372. * confusing.
  5373. * word3 is payload_len: byte offset to the sgl entry for the
  5374. * fcp_command.
  5375. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5376. * word5 is initial xfer len 0 = wait for xfer-ready
  5377. */
  5378. /* Always wait for xfer-ready before sending data */
  5379. wqe->fcp_iwrite.initial_xfer_len = 0;
  5380. /* word 4 (xfer length) should have been set on the memcpy */
  5381. /* allow write to fall through to read */
  5382. case CMD_FCP_IREAD64_CR:
  5383. /* FCP_CMD is always the 1st sgl entry */
  5384. wqe->fcp_iread.payload_len =
  5385. payload_len + sizeof(struct fcp_rsp);
  5386. /* word 4 (xfer length) should have been set on the memcpy */
  5387. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5388. iocbq->iocb.ulpFCP2Rcvy);
  5389. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5390. /* The XC bit and the XS bit are similar. The driver never
  5391. * tracked whether or not the exchange was previouslly open.
  5392. * XC = Exchange create, 0 is create. 1 is already open.
  5393. * XS = link cmd: 1 do not close the exchange after command.
  5394. * XS = 0 close exchange when command completes.
  5395. * The only time we would not set the XC bit is when the XS bit
  5396. * is set and we are sending our 2nd or greater command on
  5397. * this exchange.
  5398. */
  5399. /* Always open the exchange */
  5400. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5401. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5402. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5403. break;
  5404. case CMD_FCP_ICMND64_CR:
  5405. /* Always open the exchange */
  5406. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5407. wqe->words[4] = 0;
  5408. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5409. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5410. break;
  5411. case CMD_GEN_REQUEST64_CR:
  5412. /* word3 command length is described as byte offset to the
  5413. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5414. * sgl[0] = cmnd
  5415. * sgl[1] = rsp.
  5416. *
  5417. */
  5418. wqe->gen_req.command_len = payload_len;
  5419. /* Word4 parameter copied in the memcpy */
  5420. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5421. /* word6 context tag copied in memcpy */
  5422. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5423. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5424. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5425. "2015 Invalid CT %x command 0x%x\n",
  5426. ct, iocbq->iocb.ulpCommand);
  5427. return IOCB_ERROR;
  5428. }
  5429. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5430. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5431. iocbq->iocb.ulpTimeout);
  5432. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5433. command_type = OTHER_COMMAND;
  5434. break;
  5435. case CMD_XMIT_ELS_RSP64_CX:
  5436. /* words0-2 BDE memcpy */
  5437. /* word3 iocb=iotag32 wqe=rsvd */
  5438. wqe->words[3] = 0;
  5439. /* word4 iocb=did wge=rsvd. */
  5440. wqe->words[4] = 0;
  5441. /* word5 iocb=rsvd wge=did */
  5442. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5443. iocbq->iocb.un.elsreq64.remoteID);
  5444. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5445. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5446. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5447. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5448. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5449. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5450. iocbq->vport->vpi + phba->vpi_base);
  5451. command_type = OTHER_COMMAND;
  5452. break;
  5453. case CMD_CLOSE_XRI_CN:
  5454. case CMD_ABORT_XRI_CN:
  5455. case CMD_ABORT_XRI_CX:
  5456. /* words 0-2 memcpy should be 0 rserved */
  5457. /* port will send abts */
  5458. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5459. /*
  5460. * The link is down so the fw does not need to send abts
  5461. * on the wire.
  5462. */
  5463. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5464. else
  5465. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5466. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5467. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5468. wqe->words[5] = 0;
  5469. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5470. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5471. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5472. wqe->generic.abort_tag = abort_tag;
  5473. /*
  5474. * The abort handler will send us CMD_ABORT_XRI_CN or
  5475. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5476. */
  5477. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5478. cmnd = CMD_ABORT_XRI_CX;
  5479. command_type = OTHER_COMMAND;
  5480. xritag = 0;
  5481. break;
  5482. case CMD_XRI_ABORTED_CX:
  5483. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5484. /* words0-2 are all 0's no bde */
  5485. /* word3 and word4 are rsvrd */
  5486. wqe->words[3] = 0;
  5487. wqe->words[4] = 0;
  5488. /* word5 iocb=rsvd wge=did */
  5489. /* There is no remote port id in the IOCB? */
  5490. /* Let this fall through and fail */
  5491. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5492. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5493. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5494. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5495. default:
  5496. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5497. "2014 Invalid command 0x%x\n",
  5498. iocbq->iocb.ulpCommand);
  5499. return IOCB_ERROR;
  5500. break;
  5501. }
  5502. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5503. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5504. wqe->generic.abort_tag = abort_tag;
  5505. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5506. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5507. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5508. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5509. return 0;
  5510. }
  5511. /**
  5512. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5513. * @phba: Pointer to HBA context object.
  5514. * @ring_number: SLI ring number to issue iocb on.
  5515. * @piocb: Pointer to command iocb.
  5516. * @flag: Flag indicating if this command can be put into txq.
  5517. *
  5518. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5519. * an iocb command to an HBA with SLI-4 interface spec.
  5520. *
  5521. * This function is called with hbalock held. The function will return success
  5522. * after it successfully submit the iocb to firmware or after adding to the
  5523. * txq.
  5524. **/
  5525. static int
  5526. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5527. struct lpfc_iocbq *piocb, uint32_t flag)
  5528. {
  5529. struct lpfc_sglq *sglq;
  5530. uint16_t xritag;
  5531. union lpfc_wqe wqe;
  5532. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5533. uint32_t fcp_wqidx;
  5534. if (piocb->sli4_xritag == NO_XRI) {
  5535. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5536. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5537. sglq = NULL;
  5538. else {
  5539. sglq = __lpfc_sli_get_sglq(phba);
  5540. if (!sglq)
  5541. return IOCB_ERROR;
  5542. piocb->sli4_xritag = sglq->sli4_xritag;
  5543. }
  5544. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5545. sglq = NULL; /* These IO's already have an XRI and
  5546. * a mapped sgl.
  5547. */
  5548. } else {
  5549. /* This is a continuation of a commandi,(CX) so this
  5550. * sglq is on the active list
  5551. */
  5552. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5553. if (!sglq)
  5554. return IOCB_ERROR;
  5555. }
  5556. if (sglq) {
  5557. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5558. if (xritag != sglq->sli4_xritag)
  5559. return IOCB_ERROR;
  5560. }
  5561. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5562. return IOCB_ERROR;
  5563. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5564. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba, piocb);
  5565. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5566. return IOCB_ERROR;
  5567. } else {
  5568. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5569. return IOCB_ERROR;
  5570. }
  5571. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5572. return 0;
  5573. }
  5574. /**
  5575. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5576. *
  5577. * This routine wraps the actual lockless version for issusing IOCB function
  5578. * pointer from the lpfc_hba struct.
  5579. *
  5580. * Return codes:
  5581. * IOCB_ERROR - Error
  5582. * IOCB_SUCCESS - Success
  5583. * IOCB_BUSY - Busy
  5584. **/
  5585. static inline int
  5586. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5587. struct lpfc_iocbq *piocb, uint32_t flag)
  5588. {
  5589. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5590. }
  5591. /**
  5592. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5593. * @phba: The hba struct for which this call is being executed.
  5594. * @dev_grp: The HBA PCI-Device group number.
  5595. *
  5596. * This routine sets up the SLI interface API function jump table in @phba
  5597. * struct.
  5598. * Returns: 0 - success, -ENODEV - failure.
  5599. **/
  5600. int
  5601. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5602. {
  5603. switch (dev_grp) {
  5604. case LPFC_PCI_DEV_LP:
  5605. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5606. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5607. break;
  5608. case LPFC_PCI_DEV_OC:
  5609. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5610. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5611. break;
  5612. default:
  5613. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5614. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5615. dev_grp);
  5616. return -ENODEV;
  5617. break;
  5618. }
  5619. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5620. return 0;
  5621. }
  5622. /**
  5623. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5624. * @phba: Pointer to HBA context object.
  5625. * @pring: Pointer to driver SLI ring object.
  5626. * @piocb: Pointer to command iocb.
  5627. * @flag: Flag indicating if this command can be put into txq.
  5628. *
  5629. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5630. * function. This function gets the hbalock and calls
  5631. * __lpfc_sli_issue_iocb function and will return the error returned
  5632. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5633. * functions which do not hold hbalock.
  5634. **/
  5635. int
  5636. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5637. struct lpfc_iocbq *piocb, uint32_t flag)
  5638. {
  5639. unsigned long iflags;
  5640. int rc;
  5641. spin_lock_irqsave(&phba->hbalock, iflags);
  5642. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5643. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5644. return rc;
  5645. }
  5646. /**
  5647. * lpfc_extra_ring_setup - Extra ring setup function
  5648. * @phba: Pointer to HBA context object.
  5649. *
  5650. * This function is called while driver attaches with the
  5651. * HBA to setup the extra ring. The extra ring is used
  5652. * only when driver needs to support target mode functionality
  5653. * or IP over FC functionalities.
  5654. *
  5655. * This function is called with no lock held.
  5656. **/
  5657. static int
  5658. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5659. {
  5660. struct lpfc_sli *psli;
  5661. struct lpfc_sli_ring *pring;
  5662. psli = &phba->sli;
  5663. /* Adjust cmd/rsp ring iocb entries more evenly */
  5664. /* Take some away from the FCP ring */
  5665. pring = &psli->ring[psli->fcp_ring];
  5666. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5667. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5668. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5669. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5670. /* and give them to the extra ring */
  5671. pring = &psli->ring[psli->extra_ring];
  5672. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5673. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5674. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5675. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5676. /* Setup default profile for this ring */
  5677. pring->iotag_max = 4096;
  5678. pring->num_mask = 1;
  5679. pring->prt[0].profile = 0; /* Mask 0 */
  5680. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5681. pring->prt[0].type = phba->cfg_multi_ring_type;
  5682. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5683. return 0;
  5684. }
  5685. /**
  5686. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5687. * @phba: Pointer to HBA context object.
  5688. * @pring: Pointer to driver SLI ring object.
  5689. * @iocbq: Pointer to iocb object.
  5690. *
  5691. * This function is called by the slow ring event handler
  5692. * function when there is an ASYNC event iocb in the ring.
  5693. * This function is called with no lock held.
  5694. * Currently this function handles only temperature related
  5695. * ASYNC events. The function decodes the temperature sensor
  5696. * event message and posts events for the management applications.
  5697. **/
  5698. static void
  5699. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5700. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5701. {
  5702. IOCB_t *icmd;
  5703. uint16_t evt_code;
  5704. uint16_t temp;
  5705. struct temp_event temp_event_data;
  5706. struct Scsi_Host *shost;
  5707. uint32_t *iocb_w;
  5708. icmd = &iocbq->iocb;
  5709. evt_code = icmd->un.asyncstat.evt_code;
  5710. temp = icmd->ulpContext;
  5711. if ((evt_code != ASYNC_TEMP_WARN) &&
  5712. (evt_code != ASYNC_TEMP_SAFE)) {
  5713. iocb_w = (uint32_t *) icmd;
  5714. lpfc_printf_log(phba,
  5715. KERN_ERR,
  5716. LOG_SLI,
  5717. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5718. " evt_code 0x%x \n"
  5719. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5720. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5721. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5722. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5723. pring->ringno,
  5724. icmd->un.asyncstat.evt_code,
  5725. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5726. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5727. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5728. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5729. return;
  5730. }
  5731. temp_event_data.data = (uint32_t)temp;
  5732. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5733. if (evt_code == ASYNC_TEMP_WARN) {
  5734. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5735. lpfc_printf_log(phba,
  5736. KERN_ERR,
  5737. LOG_TEMP,
  5738. "0347 Adapter is very hot, please take "
  5739. "corrective action. temperature : %d Celsius\n",
  5740. temp);
  5741. }
  5742. if (evt_code == ASYNC_TEMP_SAFE) {
  5743. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5744. lpfc_printf_log(phba,
  5745. KERN_ERR,
  5746. LOG_TEMP,
  5747. "0340 Adapter temperature is OK now. "
  5748. "temperature : %d Celsius\n",
  5749. temp);
  5750. }
  5751. /* Send temperature change event to applications */
  5752. shost = lpfc_shost_from_vport(phba->pport);
  5753. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5754. sizeof(temp_event_data), (char *) &temp_event_data,
  5755. LPFC_NL_VENDOR_ID);
  5756. }
  5757. /**
  5758. * lpfc_sli_setup - SLI ring setup function
  5759. * @phba: Pointer to HBA context object.
  5760. *
  5761. * lpfc_sli_setup sets up rings of the SLI interface with
  5762. * number of iocbs per ring and iotags. This function is
  5763. * called while driver attach to the HBA and before the
  5764. * interrupts are enabled. So there is no need for locking.
  5765. *
  5766. * This function always returns 0.
  5767. **/
  5768. int
  5769. lpfc_sli_setup(struct lpfc_hba *phba)
  5770. {
  5771. int i, totiocbsize = 0;
  5772. struct lpfc_sli *psli = &phba->sli;
  5773. struct lpfc_sli_ring *pring;
  5774. psli->num_rings = MAX_CONFIGURED_RINGS;
  5775. psli->sli_flag = 0;
  5776. psli->fcp_ring = LPFC_FCP_RING;
  5777. psli->next_ring = LPFC_FCP_NEXT_RING;
  5778. psli->extra_ring = LPFC_EXTRA_RING;
  5779. psli->iocbq_lookup = NULL;
  5780. psli->iocbq_lookup_len = 0;
  5781. psli->last_iotag = 0;
  5782. for (i = 0; i < psli->num_rings; i++) {
  5783. pring = &psli->ring[i];
  5784. switch (i) {
  5785. case LPFC_FCP_RING: /* ring 0 - FCP */
  5786. /* numCiocb and numRiocb are used in config_port */
  5787. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5788. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5789. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5790. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5791. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5792. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5793. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5794. SLI3_IOCB_CMD_SIZE :
  5795. SLI2_IOCB_CMD_SIZE;
  5796. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5797. SLI3_IOCB_RSP_SIZE :
  5798. SLI2_IOCB_RSP_SIZE;
  5799. pring->iotag_ctr = 0;
  5800. pring->iotag_max =
  5801. (phba->cfg_hba_queue_depth * 2);
  5802. pring->fast_iotag = pring->iotag_max;
  5803. pring->num_mask = 0;
  5804. break;
  5805. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5806. /* numCiocb and numRiocb are used in config_port */
  5807. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5808. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5809. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5810. SLI3_IOCB_CMD_SIZE :
  5811. SLI2_IOCB_CMD_SIZE;
  5812. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5813. SLI3_IOCB_RSP_SIZE :
  5814. SLI2_IOCB_RSP_SIZE;
  5815. pring->iotag_max = phba->cfg_hba_queue_depth;
  5816. pring->num_mask = 0;
  5817. break;
  5818. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5819. /* numCiocb and numRiocb are used in config_port */
  5820. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5821. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5822. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5823. SLI3_IOCB_CMD_SIZE :
  5824. SLI2_IOCB_CMD_SIZE;
  5825. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5826. SLI3_IOCB_RSP_SIZE :
  5827. SLI2_IOCB_RSP_SIZE;
  5828. pring->fast_iotag = 0;
  5829. pring->iotag_ctr = 0;
  5830. pring->iotag_max = 4096;
  5831. pring->lpfc_sli_rcv_async_status =
  5832. lpfc_sli_async_event_handler;
  5833. pring->num_mask = 4;
  5834. pring->prt[0].profile = 0; /* Mask 0 */
  5835. pring->prt[0].rctl = FC_ELS_REQ;
  5836. pring->prt[0].type = FC_ELS_DATA;
  5837. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5838. lpfc_els_unsol_event;
  5839. pring->prt[1].profile = 0; /* Mask 1 */
  5840. pring->prt[1].rctl = FC_ELS_RSP;
  5841. pring->prt[1].type = FC_ELS_DATA;
  5842. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5843. lpfc_els_unsol_event;
  5844. pring->prt[2].profile = 0; /* Mask 2 */
  5845. /* NameServer Inquiry */
  5846. pring->prt[2].rctl = FC_UNSOL_CTL;
  5847. /* NameServer */
  5848. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  5849. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5850. lpfc_ct_unsol_event;
  5851. pring->prt[3].profile = 0; /* Mask 3 */
  5852. /* NameServer response */
  5853. pring->prt[3].rctl = FC_SOL_CTL;
  5854. /* NameServer */
  5855. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  5856. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5857. lpfc_ct_unsol_event;
  5858. break;
  5859. }
  5860. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5861. (pring->numRiocb * pring->sizeRiocb);
  5862. }
  5863. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5864. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5865. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5866. "SLI2 SLIM Data: x%x x%lx\n",
  5867. phba->brd_no, totiocbsize,
  5868. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5869. }
  5870. if (phba->cfg_multi_ring_support == 2)
  5871. lpfc_extra_ring_setup(phba);
  5872. return 0;
  5873. }
  5874. /**
  5875. * lpfc_sli_queue_setup - Queue initialization function
  5876. * @phba: Pointer to HBA context object.
  5877. *
  5878. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5879. * ring. This function also initializes ring indices of each ring.
  5880. * This function is called during the initialization of the SLI
  5881. * interface of an HBA.
  5882. * This function is called with no lock held and always returns
  5883. * 1.
  5884. **/
  5885. int
  5886. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5887. {
  5888. struct lpfc_sli *psli;
  5889. struct lpfc_sli_ring *pring;
  5890. int i;
  5891. psli = &phba->sli;
  5892. spin_lock_irq(&phba->hbalock);
  5893. INIT_LIST_HEAD(&psli->mboxq);
  5894. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5895. /* Initialize list headers for txq and txcmplq as double linked lists */
  5896. for (i = 0; i < psli->num_rings; i++) {
  5897. pring = &psli->ring[i];
  5898. pring->ringno = i;
  5899. pring->next_cmdidx = 0;
  5900. pring->local_getidx = 0;
  5901. pring->cmdidx = 0;
  5902. INIT_LIST_HEAD(&pring->txq);
  5903. INIT_LIST_HEAD(&pring->txcmplq);
  5904. INIT_LIST_HEAD(&pring->iocb_continueq);
  5905. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5906. INIT_LIST_HEAD(&pring->postbufq);
  5907. }
  5908. spin_unlock_irq(&phba->hbalock);
  5909. return 1;
  5910. }
  5911. /**
  5912. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5913. * @phba: Pointer to HBA context object.
  5914. *
  5915. * This routine flushes the mailbox command subsystem. It will unconditionally
  5916. * flush all the mailbox commands in the three possible stages in the mailbox
  5917. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5918. * command; and completed mailbox command queue. It is caller's responsibility
  5919. * to make sure that the driver is in the proper state to flush the mailbox
  5920. * command sub-system. Namely, the posting of mailbox commands into the
  5921. * pending mailbox command queue from the various clients must be stopped;
  5922. * either the HBA is in a state that it will never works on the outstanding
  5923. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5924. * mailbox command has been completed.
  5925. **/
  5926. static void
  5927. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5928. {
  5929. LIST_HEAD(completions);
  5930. struct lpfc_sli *psli = &phba->sli;
  5931. LPFC_MBOXQ_t *pmb;
  5932. unsigned long iflag;
  5933. /* Flush all the mailbox commands in the mbox system */
  5934. spin_lock_irqsave(&phba->hbalock, iflag);
  5935. /* The pending mailbox command queue */
  5936. list_splice_init(&phba->sli.mboxq, &completions);
  5937. /* The outstanding active mailbox command */
  5938. if (psli->mbox_active) {
  5939. list_add_tail(&psli->mbox_active->list, &completions);
  5940. psli->mbox_active = NULL;
  5941. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5942. }
  5943. /* The completed mailbox command queue */
  5944. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5945. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5946. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5947. while (!list_empty(&completions)) {
  5948. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5949. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5950. if (pmb->mbox_cmpl)
  5951. pmb->mbox_cmpl(phba, pmb);
  5952. }
  5953. }
  5954. /**
  5955. * lpfc_sli_host_down - Vport cleanup function
  5956. * @vport: Pointer to virtual port object.
  5957. *
  5958. * lpfc_sli_host_down is called to clean up the resources
  5959. * associated with a vport before destroying virtual
  5960. * port data structures.
  5961. * This function does following operations:
  5962. * - Free discovery resources associated with this virtual
  5963. * port.
  5964. * - Free iocbs associated with this virtual port in
  5965. * the txq.
  5966. * - Send abort for all iocb commands associated with this
  5967. * vport in txcmplq.
  5968. *
  5969. * This function is called with no lock held and always returns 1.
  5970. **/
  5971. int
  5972. lpfc_sli_host_down(struct lpfc_vport *vport)
  5973. {
  5974. LIST_HEAD(completions);
  5975. struct lpfc_hba *phba = vport->phba;
  5976. struct lpfc_sli *psli = &phba->sli;
  5977. struct lpfc_sli_ring *pring;
  5978. struct lpfc_iocbq *iocb, *next_iocb;
  5979. int i;
  5980. unsigned long flags = 0;
  5981. uint16_t prev_pring_flag;
  5982. lpfc_cleanup_discovery_resources(vport);
  5983. spin_lock_irqsave(&phba->hbalock, flags);
  5984. for (i = 0; i < psli->num_rings; i++) {
  5985. pring = &psli->ring[i];
  5986. prev_pring_flag = pring->flag;
  5987. /* Only slow rings */
  5988. if (pring->ringno == LPFC_ELS_RING) {
  5989. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5990. /* Set the lpfc data pending flag */
  5991. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5992. }
  5993. /*
  5994. * Error everything on the txq since these iocbs have not been
  5995. * given to the FW yet.
  5996. */
  5997. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  5998. if (iocb->vport != vport)
  5999. continue;
  6000. list_move_tail(&iocb->list, &completions);
  6001. pring->txq_cnt--;
  6002. }
  6003. /* Next issue ABTS for everything on the txcmplq */
  6004. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6005. list) {
  6006. if (iocb->vport != vport)
  6007. continue;
  6008. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6009. }
  6010. pring->flag = prev_pring_flag;
  6011. }
  6012. spin_unlock_irqrestore(&phba->hbalock, flags);
  6013. /* Cancel all the IOCBs from the completions list */
  6014. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6015. IOERR_SLI_DOWN);
  6016. return 1;
  6017. }
  6018. /**
  6019. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6020. * @phba: Pointer to HBA context object.
  6021. *
  6022. * This function cleans up all iocb, buffers, mailbox commands
  6023. * while shutting down the HBA. This function is called with no
  6024. * lock held and always returns 1.
  6025. * This function does the following to cleanup driver resources:
  6026. * - Free discovery resources for each virtual port
  6027. * - Cleanup any pending fabric iocbs
  6028. * - Iterate through the iocb txq and free each entry
  6029. * in the list.
  6030. * - Free up any buffer posted to the HBA
  6031. * - Free mailbox commands in the mailbox queue.
  6032. **/
  6033. int
  6034. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6035. {
  6036. LIST_HEAD(completions);
  6037. struct lpfc_sli *psli = &phba->sli;
  6038. struct lpfc_sli_ring *pring;
  6039. struct lpfc_dmabuf *buf_ptr;
  6040. unsigned long flags = 0;
  6041. int i;
  6042. /* Shutdown the mailbox command sub-system */
  6043. lpfc_sli_mbox_sys_shutdown(phba);
  6044. lpfc_hba_down_prep(phba);
  6045. lpfc_fabric_abort_hba(phba);
  6046. spin_lock_irqsave(&phba->hbalock, flags);
  6047. for (i = 0; i < psli->num_rings; i++) {
  6048. pring = &psli->ring[i];
  6049. /* Only slow rings */
  6050. if (pring->ringno == LPFC_ELS_RING) {
  6051. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6052. /* Set the lpfc data pending flag */
  6053. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6054. }
  6055. /*
  6056. * Error everything on the txq since these iocbs have not been
  6057. * given to the FW yet.
  6058. */
  6059. list_splice_init(&pring->txq, &completions);
  6060. pring->txq_cnt = 0;
  6061. }
  6062. spin_unlock_irqrestore(&phba->hbalock, flags);
  6063. /* Cancel all the IOCBs from the completions list */
  6064. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6065. IOERR_SLI_DOWN);
  6066. spin_lock_irqsave(&phba->hbalock, flags);
  6067. list_splice_init(&phba->elsbuf, &completions);
  6068. phba->elsbuf_cnt = 0;
  6069. phba->elsbuf_prev_cnt = 0;
  6070. spin_unlock_irqrestore(&phba->hbalock, flags);
  6071. while (!list_empty(&completions)) {
  6072. list_remove_head(&completions, buf_ptr,
  6073. struct lpfc_dmabuf, list);
  6074. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6075. kfree(buf_ptr);
  6076. }
  6077. /* Return any active mbox cmds */
  6078. del_timer_sync(&psli->mbox_tmo);
  6079. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6080. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6081. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6082. return 1;
  6083. }
  6084. /**
  6085. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  6086. * @phba: Pointer to HBA context object.
  6087. *
  6088. * This function cleans up all queues, iocb, buffers, mailbox commands while
  6089. * shutting down the SLI4 HBA FCoE function. This function is called with no
  6090. * lock held and always returns 1.
  6091. *
  6092. * This function does the following to cleanup driver FCoE function resources:
  6093. * - Free discovery resources for each virtual port
  6094. * - Cleanup any pending fabric iocbs
  6095. * - Iterate through the iocb txq and free each entry in the list.
  6096. * - Free up any buffer posted to the HBA.
  6097. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6098. * - Free mailbox commands in the mailbox queue.
  6099. **/
  6100. int
  6101. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6102. {
  6103. /* Stop the SLI4 device port */
  6104. lpfc_stop_port(phba);
  6105. /* Tear down the queues in the HBA */
  6106. lpfc_sli4_queue_unset(phba);
  6107. /* unregister default FCFI from the HBA */
  6108. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6109. return 1;
  6110. }
  6111. /**
  6112. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6113. * @srcp: Source memory pointer.
  6114. * @destp: Destination memory pointer.
  6115. * @cnt: Number of words required to be copied.
  6116. *
  6117. * This function is used for copying data between driver memory
  6118. * and the SLI memory. This function also changes the endianness
  6119. * of each word if native endianness is different from SLI
  6120. * endianness. This function can be called with or without
  6121. * lock.
  6122. **/
  6123. void
  6124. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6125. {
  6126. uint32_t *src = srcp;
  6127. uint32_t *dest = destp;
  6128. uint32_t ldata;
  6129. int i;
  6130. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6131. ldata = *src;
  6132. ldata = le32_to_cpu(ldata);
  6133. *dest = ldata;
  6134. src++;
  6135. dest++;
  6136. }
  6137. }
  6138. /**
  6139. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6140. * @phba: Pointer to HBA context object.
  6141. * @pring: Pointer to driver SLI ring object.
  6142. * @mp: Pointer to driver buffer object.
  6143. *
  6144. * This function is called with no lock held.
  6145. * It always return zero after adding the buffer to the postbufq
  6146. * buffer list.
  6147. **/
  6148. int
  6149. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6150. struct lpfc_dmabuf *mp)
  6151. {
  6152. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6153. later */
  6154. spin_lock_irq(&phba->hbalock);
  6155. list_add_tail(&mp->list, &pring->postbufq);
  6156. pring->postbufq_cnt++;
  6157. spin_unlock_irq(&phba->hbalock);
  6158. return 0;
  6159. }
  6160. /**
  6161. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6162. * @phba: Pointer to HBA context object.
  6163. *
  6164. * When HBQ is enabled, buffers are searched based on tags. This function
  6165. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6166. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6167. * does not conflict with tags of buffer posted for unsolicited events.
  6168. * The function returns the allocated tag. The function is called with
  6169. * no locks held.
  6170. **/
  6171. uint32_t
  6172. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6173. {
  6174. spin_lock_irq(&phba->hbalock);
  6175. phba->buffer_tag_count++;
  6176. /*
  6177. * Always set the QUE_BUFTAG_BIT to distiguish between
  6178. * a tag assigned by HBQ.
  6179. */
  6180. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6181. spin_unlock_irq(&phba->hbalock);
  6182. return phba->buffer_tag_count;
  6183. }
  6184. /**
  6185. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6186. * @phba: Pointer to HBA context object.
  6187. * @pring: Pointer to driver SLI ring object.
  6188. * @tag: Buffer tag.
  6189. *
  6190. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6191. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6192. * iocb is posted to the response ring with the tag of the buffer.
  6193. * This function searches the pring->postbufq list using the tag
  6194. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6195. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6196. * buffer is returned to the caller else NULL is returned.
  6197. * This function is called with no lock held.
  6198. **/
  6199. struct lpfc_dmabuf *
  6200. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6201. uint32_t tag)
  6202. {
  6203. struct lpfc_dmabuf *mp, *next_mp;
  6204. struct list_head *slp = &pring->postbufq;
  6205. /* Search postbufq, from the begining, looking for a match on tag */
  6206. spin_lock_irq(&phba->hbalock);
  6207. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6208. if (mp->buffer_tag == tag) {
  6209. list_del_init(&mp->list);
  6210. pring->postbufq_cnt--;
  6211. spin_unlock_irq(&phba->hbalock);
  6212. return mp;
  6213. }
  6214. }
  6215. spin_unlock_irq(&phba->hbalock);
  6216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6217. "0402 Cannot find virtual addr for buffer tag on "
  6218. "ring %d Data x%lx x%p x%p x%x\n",
  6219. pring->ringno, (unsigned long) tag,
  6220. slp->next, slp->prev, pring->postbufq_cnt);
  6221. return NULL;
  6222. }
  6223. /**
  6224. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6225. * @phba: Pointer to HBA context object.
  6226. * @pring: Pointer to driver SLI ring object.
  6227. * @phys: DMA address of the buffer.
  6228. *
  6229. * This function searches the buffer list using the dma_address
  6230. * of unsolicited event to find the driver's lpfc_dmabuf object
  6231. * corresponding to the dma_address. The function returns the
  6232. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6233. * This function is called by the ct and els unsolicited event
  6234. * handlers to get the buffer associated with the unsolicited
  6235. * event.
  6236. *
  6237. * This function is called with no lock held.
  6238. **/
  6239. struct lpfc_dmabuf *
  6240. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6241. dma_addr_t phys)
  6242. {
  6243. struct lpfc_dmabuf *mp, *next_mp;
  6244. struct list_head *slp = &pring->postbufq;
  6245. /* Search postbufq, from the begining, looking for a match on phys */
  6246. spin_lock_irq(&phba->hbalock);
  6247. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6248. if (mp->phys == phys) {
  6249. list_del_init(&mp->list);
  6250. pring->postbufq_cnt--;
  6251. spin_unlock_irq(&phba->hbalock);
  6252. return mp;
  6253. }
  6254. }
  6255. spin_unlock_irq(&phba->hbalock);
  6256. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6257. "0410 Cannot find virtual addr for mapped buf on "
  6258. "ring %d Data x%llx x%p x%p x%x\n",
  6259. pring->ringno, (unsigned long long)phys,
  6260. slp->next, slp->prev, pring->postbufq_cnt);
  6261. return NULL;
  6262. }
  6263. /**
  6264. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6265. * @phba: Pointer to HBA context object.
  6266. * @cmdiocb: Pointer to driver command iocb object.
  6267. * @rspiocb: Pointer to driver response iocb object.
  6268. *
  6269. * This function is the completion handler for the abort iocbs for
  6270. * ELS commands. This function is called from the ELS ring event
  6271. * handler with no lock held. This function frees memory resources
  6272. * associated with the abort iocb.
  6273. **/
  6274. static void
  6275. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6276. struct lpfc_iocbq *rspiocb)
  6277. {
  6278. IOCB_t *irsp = &rspiocb->iocb;
  6279. uint16_t abort_iotag, abort_context;
  6280. struct lpfc_iocbq *abort_iocb;
  6281. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6282. abort_iocb = NULL;
  6283. if (irsp->ulpStatus) {
  6284. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6285. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6286. spin_lock_irq(&phba->hbalock);
  6287. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  6288. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  6289. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6290. "0327 Cannot abort els iocb %p "
  6291. "with tag %x context %x, abort status %x, "
  6292. "abort code %x\n",
  6293. abort_iocb, abort_iotag, abort_context,
  6294. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6295. /*
  6296. * If the iocb is not found in Firmware queue the iocb
  6297. * might have completed already. Do not free it again.
  6298. */
  6299. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6300. spin_unlock_irq(&phba->hbalock);
  6301. lpfc_sli_release_iocbq(phba, cmdiocb);
  6302. return;
  6303. }
  6304. /*
  6305. * make sure we have the right iocbq before taking it
  6306. * off the txcmplq and try to call completion routine.
  6307. */
  6308. if (!abort_iocb ||
  6309. abort_iocb->iocb.ulpContext != abort_context ||
  6310. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6311. spin_unlock_irq(&phba->hbalock);
  6312. else {
  6313. list_del_init(&abort_iocb->list);
  6314. pring->txcmplq_cnt--;
  6315. spin_unlock_irq(&phba->hbalock);
  6316. /* Firmware could still be in progress of DMAing
  6317. * payload, so don't free data buffer till after
  6318. * a hbeat.
  6319. */
  6320. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6321. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6322. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6323. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6324. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6325. }
  6326. }
  6327. lpfc_sli_release_iocbq(phba, cmdiocb);
  6328. return;
  6329. }
  6330. /**
  6331. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6332. * @phba: Pointer to HBA context object.
  6333. * @cmdiocb: Pointer to driver command iocb object.
  6334. * @rspiocb: Pointer to driver response iocb object.
  6335. *
  6336. * The function is called from SLI ring event handler with no
  6337. * lock held. This function is the completion handler for ELS commands
  6338. * which are aborted. The function frees memory resources used for
  6339. * the aborted ELS commands.
  6340. **/
  6341. static void
  6342. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6343. struct lpfc_iocbq *rspiocb)
  6344. {
  6345. IOCB_t *irsp = &rspiocb->iocb;
  6346. /* ELS cmd tag <ulpIoTag> completes */
  6347. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6348. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6349. "x%x x%x x%x\n",
  6350. irsp->ulpIoTag, irsp->ulpStatus,
  6351. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6352. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6353. lpfc_ct_free_iocb(phba, cmdiocb);
  6354. else
  6355. lpfc_els_free_iocb(phba, cmdiocb);
  6356. return;
  6357. }
  6358. /**
  6359. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6360. * @phba: Pointer to HBA context object.
  6361. * @pring: Pointer to driver SLI ring object.
  6362. * @cmdiocb: Pointer to driver command iocb object.
  6363. *
  6364. * This function issues an abort iocb for the provided command
  6365. * iocb. This function is called with hbalock held.
  6366. * The function returns 0 when it fails due to memory allocation
  6367. * failure or when the command iocb is an abort request.
  6368. **/
  6369. int
  6370. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6371. struct lpfc_iocbq *cmdiocb)
  6372. {
  6373. struct lpfc_vport *vport = cmdiocb->vport;
  6374. struct lpfc_iocbq *abtsiocbp;
  6375. IOCB_t *icmd = NULL;
  6376. IOCB_t *iabt = NULL;
  6377. int retval = IOCB_ERROR;
  6378. /*
  6379. * There are certain command types we don't want to abort. And we
  6380. * don't want to abort commands that are already in the process of
  6381. * being aborted.
  6382. */
  6383. icmd = &cmdiocb->iocb;
  6384. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6385. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6386. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6387. return 0;
  6388. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6389. * callback so that nothing happens when it finishes.
  6390. */
  6391. if ((vport->load_flag & FC_UNLOADING) &&
  6392. (pring->ringno == LPFC_ELS_RING)) {
  6393. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6394. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6395. else
  6396. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6397. goto abort_iotag_exit;
  6398. }
  6399. /* issue ABTS for this IOCB based on iotag */
  6400. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6401. if (abtsiocbp == NULL)
  6402. return 0;
  6403. /* This signals the response to set the correct status
  6404. * before calling the completion handler.
  6405. */
  6406. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6407. iabt = &abtsiocbp->iocb;
  6408. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6409. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6410. if (phba->sli_rev == LPFC_SLI_REV4)
  6411. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6412. else
  6413. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6414. iabt->ulpLe = 1;
  6415. iabt->ulpClass = icmd->ulpClass;
  6416. if (phba->link_state >= LPFC_LINK_UP)
  6417. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6418. else
  6419. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6420. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6421. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6422. "0339 Abort xri x%x, original iotag x%x, "
  6423. "abort cmd iotag x%x\n",
  6424. iabt->un.acxri.abortContextTag,
  6425. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6426. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6427. if (retval)
  6428. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6429. abort_iotag_exit:
  6430. /*
  6431. * Caller to this routine should check for IOCB_ERROR
  6432. * and handle it properly. This routine no longer removes
  6433. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6434. */
  6435. return retval;
  6436. }
  6437. /**
  6438. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6439. * @iocbq: Pointer to driver iocb object.
  6440. * @vport: Pointer to driver virtual port object.
  6441. * @tgt_id: SCSI ID of the target.
  6442. * @lun_id: LUN ID of the scsi device.
  6443. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6444. *
  6445. * This function acts as an iocb filter for functions which abort or count
  6446. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6447. * 0 if the filtering criteria is met for the given iocb and will return
  6448. * 1 if the filtering criteria is not met.
  6449. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6450. * given iocb is for the SCSI device specified by vport, tgt_id and
  6451. * lun_id parameter.
  6452. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6453. * given iocb is for the SCSI target specified by vport and tgt_id
  6454. * parameters.
  6455. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6456. * given iocb is for the SCSI host associated with the given vport.
  6457. * This function is called with no locks held.
  6458. **/
  6459. static int
  6460. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6461. uint16_t tgt_id, uint64_t lun_id,
  6462. lpfc_ctx_cmd ctx_cmd)
  6463. {
  6464. struct lpfc_scsi_buf *lpfc_cmd;
  6465. int rc = 1;
  6466. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6467. return rc;
  6468. if (iocbq->vport != vport)
  6469. return rc;
  6470. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6471. if (lpfc_cmd->pCmd == NULL)
  6472. return rc;
  6473. switch (ctx_cmd) {
  6474. case LPFC_CTX_LUN:
  6475. if ((lpfc_cmd->rdata->pnode) &&
  6476. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6477. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6478. rc = 0;
  6479. break;
  6480. case LPFC_CTX_TGT:
  6481. if ((lpfc_cmd->rdata->pnode) &&
  6482. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6483. rc = 0;
  6484. break;
  6485. case LPFC_CTX_HOST:
  6486. rc = 0;
  6487. break;
  6488. default:
  6489. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6490. __func__, ctx_cmd);
  6491. break;
  6492. }
  6493. return rc;
  6494. }
  6495. /**
  6496. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6497. * @vport: Pointer to virtual port.
  6498. * @tgt_id: SCSI ID of the target.
  6499. * @lun_id: LUN ID of the scsi device.
  6500. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6501. *
  6502. * This function returns number of FCP commands pending for the vport.
  6503. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6504. * commands pending on the vport associated with SCSI device specified
  6505. * by tgt_id and lun_id parameters.
  6506. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6507. * commands pending on the vport associated with SCSI target specified
  6508. * by tgt_id parameter.
  6509. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6510. * commands pending on the vport.
  6511. * This function returns the number of iocbs which satisfy the filter.
  6512. * This function is called without any lock held.
  6513. **/
  6514. int
  6515. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6516. lpfc_ctx_cmd ctx_cmd)
  6517. {
  6518. struct lpfc_hba *phba = vport->phba;
  6519. struct lpfc_iocbq *iocbq;
  6520. int sum, i;
  6521. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6522. iocbq = phba->sli.iocbq_lookup[i];
  6523. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6524. ctx_cmd) == 0)
  6525. sum++;
  6526. }
  6527. return sum;
  6528. }
  6529. /**
  6530. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6531. * @phba: Pointer to HBA context object
  6532. * @cmdiocb: Pointer to command iocb object.
  6533. * @rspiocb: Pointer to response iocb object.
  6534. *
  6535. * This function is called when an aborted FCP iocb completes. This
  6536. * function is called by the ring event handler with no lock held.
  6537. * This function frees the iocb.
  6538. **/
  6539. void
  6540. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6541. struct lpfc_iocbq *rspiocb)
  6542. {
  6543. lpfc_sli_release_iocbq(phba, cmdiocb);
  6544. return;
  6545. }
  6546. /**
  6547. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6548. * @vport: Pointer to virtual port.
  6549. * @pring: Pointer to driver SLI ring object.
  6550. * @tgt_id: SCSI ID of the target.
  6551. * @lun_id: LUN ID of the scsi device.
  6552. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6553. *
  6554. * This function sends an abort command for every SCSI command
  6555. * associated with the given virtual port pending on the ring
  6556. * filtered by lpfc_sli_validate_fcp_iocb function.
  6557. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6558. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6559. * parameters
  6560. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6561. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6562. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6563. * FCP iocbs associated with virtual port.
  6564. * This function returns number of iocbs it failed to abort.
  6565. * This function is called with no locks held.
  6566. **/
  6567. int
  6568. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6569. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6570. {
  6571. struct lpfc_hba *phba = vport->phba;
  6572. struct lpfc_iocbq *iocbq;
  6573. struct lpfc_iocbq *abtsiocb;
  6574. IOCB_t *cmd = NULL;
  6575. int errcnt = 0, ret_val = 0;
  6576. int i;
  6577. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6578. iocbq = phba->sli.iocbq_lookup[i];
  6579. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6580. abort_cmd) != 0)
  6581. continue;
  6582. /* issue ABTS for this IOCB based on iotag */
  6583. abtsiocb = lpfc_sli_get_iocbq(phba);
  6584. if (abtsiocb == NULL) {
  6585. errcnt++;
  6586. continue;
  6587. }
  6588. cmd = &iocbq->iocb;
  6589. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6590. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6591. if (phba->sli_rev == LPFC_SLI_REV4)
  6592. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6593. else
  6594. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6595. abtsiocb->iocb.ulpLe = 1;
  6596. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6597. abtsiocb->vport = phba->pport;
  6598. if (lpfc_is_link_up(phba))
  6599. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6600. else
  6601. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6602. /* Setup callback routine and issue the command. */
  6603. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6604. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6605. abtsiocb, 0);
  6606. if (ret_val == IOCB_ERROR) {
  6607. lpfc_sli_release_iocbq(phba, abtsiocb);
  6608. errcnt++;
  6609. continue;
  6610. }
  6611. }
  6612. return errcnt;
  6613. }
  6614. /**
  6615. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6616. * @phba: Pointer to HBA context object.
  6617. * @cmdiocbq: Pointer to command iocb.
  6618. * @rspiocbq: Pointer to response iocb.
  6619. *
  6620. * This function is the completion handler for iocbs issued using
  6621. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6622. * ring event handler function without any lock held. This function
  6623. * can be called from both worker thread context and interrupt
  6624. * context. This function also can be called from other thread which
  6625. * cleans up the SLI layer objects.
  6626. * This function copy the contents of the response iocb to the
  6627. * response iocb memory object provided by the caller of
  6628. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6629. * sleeps for the iocb completion.
  6630. **/
  6631. static void
  6632. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6633. struct lpfc_iocbq *cmdiocbq,
  6634. struct lpfc_iocbq *rspiocbq)
  6635. {
  6636. wait_queue_head_t *pdone_q;
  6637. unsigned long iflags;
  6638. spin_lock_irqsave(&phba->hbalock, iflags);
  6639. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6640. if (cmdiocbq->context2 && rspiocbq)
  6641. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6642. &rspiocbq->iocb, sizeof(IOCB_t));
  6643. pdone_q = cmdiocbq->context_un.wait_queue;
  6644. if (pdone_q)
  6645. wake_up(pdone_q);
  6646. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6647. return;
  6648. }
  6649. /**
  6650. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6651. * @phba: Pointer to HBA context object..
  6652. * @pring: Pointer to sli ring.
  6653. * @piocb: Pointer to command iocb.
  6654. * @prspiocbq: Pointer to response iocb.
  6655. * @timeout: Timeout in number of seconds.
  6656. *
  6657. * This function issues the iocb to firmware and waits for the
  6658. * iocb to complete. If the iocb command is not
  6659. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6660. * Caller should not free the iocb resources if this function
  6661. * returns IOCB_TIMEDOUT.
  6662. * The function waits for the iocb completion using an
  6663. * non-interruptible wait.
  6664. * This function will sleep while waiting for iocb completion.
  6665. * So, this function should not be called from any context which
  6666. * does not allow sleeping. Due to the same reason, this function
  6667. * cannot be called with interrupt disabled.
  6668. * This function assumes that the iocb completions occur while
  6669. * this function sleep. So, this function cannot be called from
  6670. * the thread which process iocb completion for this ring.
  6671. * This function clears the iocb_flag of the iocb object before
  6672. * issuing the iocb and the iocb completion handler sets this
  6673. * flag and wakes this thread when the iocb completes.
  6674. * The contents of the response iocb will be copied to prspiocbq
  6675. * by the completion handler when the command completes.
  6676. * This function returns IOCB_SUCCESS when success.
  6677. * This function is called with no lock held.
  6678. **/
  6679. int
  6680. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6681. uint32_t ring_number,
  6682. struct lpfc_iocbq *piocb,
  6683. struct lpfc_iocbq *prspiocbq,
  6684. uint32_t timeout)
  6685. {
  6686. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6687. long timeleft, timeout_req = 0;
  6688. int retval = IOCB_SUCCESS;
  6689. uint32_t creg_val;
  6690. /*
  6691. * If the caller has provided a response iocbq buffer, then context2
  6692. * is NULL or its an error.
  6693. */
  6694. if (prspiocbq) {
  6695. if (piocb->context2)
  6696. return IOCB_ERROR;
  6697. piocb->context2 = prspiocbq;
  6698. }
  6699. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6700. piocb->context_un.wait_queue = &done_q;
  6701. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6702. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6703. creg_val = readl(phba->HCregaddr);
  6704. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6705. writel(creg_val, phba->HCregaddr);
  6706. readl(phba->HCregaddr); /* flush */
  6707. }
  6708. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6709. if (retval == IOCB_SUCCESS) {
  6710. timeout_req = timeout * HZ;
  6711. timeleft = wait_event_timeout(done_q,
  6712. piocb->iocb_flag & LPFC_IO_WAKE,
  6713. timeout_req);
  6714. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6715. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6716. "0331 IOCB wake signaled\n");
  6717. } else if (timeleft == 0) {
  6718. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6719. "0338 IOCB wait timeout error - no "
  6720. "wake response Data x%x\n", timeout);
  6721. retval = IOCB_TIMEDOUT;
  6722. } else {
  6723. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6724. "0330 IOCB wake NOT set, "
  6725. "Data x%x x%lx\n",
  6726. timeout, (timeleft / jiffies));
  6727. retval = IOCB_TIMEDOUT;
  6728. }
  6729. } else {
  6730. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6731. "0332 IOCB wait issue failed, Data x%x\n",
  6732. retval);
  6733. retval = IOCB_ERROR;
  6734. }
  6735. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6736. creg_val = readl(phba->HCregaddr);
  6737. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6738. writel(creg_val, phba->HCregaddr);
  6739. readl(phba->HCregaddr); /* flush */
  6740. }
  6741. if (prspiocbq)
  6742. piocb->context2 = NULL;
  6743. piocb->context_un.wait_queue = NULL;
  6744. piocb->iocb_cmpl = NULL;
  6745. return retval;
  6746. }
  6747. /**
  6748. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6749. * @phba: Pointer to HBA context object.
  6750. * @pmboxq: Pointer to driver mailbox object.
  6751. * @timeout: Timeout in number of seconds.
  6752. *
  6753. * This function issues the mailbox to firmware and waits for the
  6754. * mailbox command to complete. If the mailbox command is not
  6755. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6756. * The function waits for the mailbox completion using an
  6757. * interruptible wait. If the thread is woken up due to a
  6758. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6759. * should not free the mailbox resources, if this function returns
  6760. * MBX_TIMEOUT.
  6761. * This function will sleep while waiting for mailbox completion.
  6762. * So, this function should not be called from any context which
  6763. * does not allow sleeping. Due to the same reason, this function
  6764. * cannot be called with interrupt disabled.
  6765. * This function assumes that the mailbox completion occurs while
  6766. * this function sleep. So, this function cannot be called from
  6767. * the worker thread which processes mailbox completion.
  6768. * This function is called in the context of HBA management
  6769. * applications.
  6770. * This function returns MBX_SUCCESS when successful.
  6771. * This function is called with no lock held.
  6772. **/
  6773. int
  6774. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6775. uint32_t timeout)
  6776. {
  6777. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6778. int retval;
  6779. unsigned long flag;
  6780. /* The caller must leave context1 empty. */
  6781. if (pmboxq->context1)
  6782. return MBX_NOT_FINISHED;
  6783. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6784. /* setup wake call as IOCB callback */
  6785. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6786. /* setup context field to pass wait_queue pointer to wake function */
  6787. pmboxq->context1 = &done_q;
  6788. /* now issue the command */
  6789. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6790. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6791. wait_event_interruptible_timeout(done_q,
  6792. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6793. timeout * HZ);
  6794. spin_lock_irqsave(&phba->hbalock, flag);
  6795. pmboxq->context1 = NULL;
  6796. /*
  6797. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6798. * else do not free the resources.
  6799. */
  6800. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6801. retval = MBX_SUCCESS;
  6802. else {
  6803. retval = MBX_TIMEOUT;
  6804. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6805. }
  6806. spin_unlock_irqrestore(&phba->hbalock, flag);
  6807. }
  6808. return retval;
  6809. }
  6810. /**
  6811. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6812. * @phba: Pointer to HBA context.
  6813. *
  6814. * This function is called to shutdown the driver's mailbox sub-system.
  6815. * It first marks the mailbox sub-system is in a block state to prevent
  6816. * the asynchronous mailbox command from issued off the pending mailbox
  6817. * command queue. If the mailbox command sub-system shutdown is due to
  6818. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6819. * the mailbox sub-system flush routine to forcefully bring down the
  6820. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6821. * as with offline or HBA function reset), this routine will wait for the
  6822. * outstanding mailbox command to complete before invoking the mailbox
  6823. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6824. **/
  6825. void
  6826. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6827. {
  6828. struct lpfc_sli *psli = &phba->sli;
  6829. uint8_t actcmd = MBX_HEARTBEAT;
  6830. unsigned long timeout;
  6831. spin_lock_irq(&phba->hbalock);
  6832. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6833. spin_unlock_irq(&phba->hbalock);
  6834. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6835. spin_lock_irq(&phba->hbalock);
  6836. if (phba->sli.mbox_active)
  6837. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6838. spin_unlock_irq(&phba->hbalock);
  6839. /* Determine how long we might wait for the active mailbox
  6840. * command to be gracefully completed by firmware.
  6841. */
  6842. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6843. 1000) + jiffies;
  6844. while (phba->sli.mbox_active) {
  6845. /* Check active mailbox complete status every 2ms */
  6846. msleep(2);
  6847. if (time_after(jiffies, timeout))
  6848. /* Timeout, let the mailbox flush routine to
  6849. * forcefully release active mailbox command
  6850. */
  6851. break;
  6852. }
  6853. }
  6854. lpfc_sli_mbox_sys_flush(phba);
  6855. }
  6856. /**
  6857. * lpfc_sli_eratt_read - read sli-3 error attention events
  6858. * @phba: Pointer to HBA context.
  6859. *
  6860. * This function is called to read the SLI3 device error attention registers
  6861. * for possible error attention events. The caller must hold the hostlock
  6862. * with spin_lock_irq().
  6863. *
  6864. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6865. * Register and returns 0 otherwise.
  6866. **/
  6867. static int
  6868. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6869. {
  6870. uint32_t ha_copy;
  6871. /* Read chip Host Attention (HA) register */
  6872. ha_copy = readl(phba->HAregaddr);
  6873. if (ha_copy & HA_ERATT) {
  6874. /* Read host status register to retrieve error event */
  6875. lpfc_sli_read_hs(phba);
  6876. /* Check if there is a deferred error condition is active */
  6877. if ((HS_FFER1 & phba->work_hs) &&
  6878. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6879. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6880. spin_lock_irq(&phba->hbalock);
  6881. phba->hba_flag |= DEFER_ERATT;
  6882. spin_unlock_irq(&phba->hbalock);
  6883. /* Clear all interrupt enable conditions */
  6884. writel(0, phba->HCregaddr);
  6885. readl(phba->HCregaddr);
  6886. }
  6887. /* Set the driver HA work bitmap */
  6888. spin_lock_irq(&phba->hbalock);
  6889. phba->work_ha |= HA_ERATT;
  6890. /* Indicate polling handles this ERATT */
  6891. phba->hba_flag |= HBA_ERATT_HANDLED;
  6892. spin_unlock_irq(&phba->hbalock);
  6893. return 1;
  6894. }
  6895. return 0;
  6896. }
  6897. /**
  6898. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6899. * @phba: Pointer to HBA context.
  6900. *
  6901. * This function is called to read the SLI4 device error attention registers
  6902. * for possible error attention events. The caller must hold the hostlock
  6903. * with spin_lock_irq().
  6904. *
  6905. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6906. * Register and returns 0 otherwise.
  6907. **/
  6908. static int
  6909. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6910. {
  6911. uint32_t uerr_sta_hi, uerr_sta_lo;
  6912. uint32_t onlnreg0, onlnreg1;
  6913. /* For now, use the SLI4 device internal unrecoverable error
  6914. * registers for error attention. This can be changed later.
  6915. */
  6916. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  6917. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  6918. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  6919. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6920. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6921. if (uerr_sta_lo || uerr_sta_hi) {
  6922. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6923. "1423 HBA Unrecoverable error: "
  6924. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6925. "online0_reg=0x%x, online1_reg=0x%x\n",
  6926. uerr_sta_lo, uerr_sta_hi,
  6927. onlnreg0, onlnreg1);
  6928. /* TEMP: as the driver error recover logic is not
  6929. * fully developed, we just log the error message
  6930. * and the device error attention action is now
  6931. * temporarily disabled.
  6932. */
  6933. return 0;
  6934. phba->work_status[0] = uerr_sta_lo;
  6935. phba->work_status[1] = uerr_sta_hi;
  6936. spin_lock_irq(&phba->hbalock);
  6937. /* Set the driver HA work bitmap */
  6938. phba->work_ha |= HA_ERATT;
  6939. /* Indicate polling handles this ERATT */
  6940. phba->hba_flag |= HBA_ERATT_HANDLED;
  6941. spin_unlock_irq(&phba->hbalock);
  6942. return 1;
  6943. }
  6944. }
  6945. return 0;
  6946. }
  6947. /**
  6948. * lpfc_sli_check_eratt - check error attention events
  6949. * @phba: Pointer to HBA context.
  6950. *
  6951. * This function is called from timer soft interrupt context to check HBA's
  6952. * error attention register bit for error attention events.
  6953. *
  6954. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6955. * Register and returns 0 otherwise.
  6956. **/
  6957. int
  6958. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  6959. {
  6960. uint32_t ha_copy;
  6961. /* If somebody is waiting to handle an eratt, don't process it
  6962. * here. The brdkill function will do this.
  6963. */
  6964. if (phba->link_flag & LS_IGNORE_ERATT)
  6965. return 0;
  6966. /* Check if interrupt handler handles this ERATT */
  6967. spin_lock_irq(&phba->hbalock);
  6968. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  6969. /* Interrupt handler has handled ERATT */
  6970. spin_unlock_irq(&phba->hbalock);
  6971. return 0;
  6972. }
  6973. /*
  6974. * If there is deferred error attention, do not check for error
  6975. * attention
  6976. */
  6977. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6978. spin_unlock_irq(&phba->hbalock);
  6979. return 0;
  6980. }
  6981. /* If PCI channel is offline, don't process it */
  6982. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6983. spin_unlock_irq(&phba->hbalock);
  6984. return 0;
  6985. }
  6986. switch (phba->sli_rev) {
  6987. case LPFC_SLI_REV2:
  6988. case LPFC_SLI_REV3:
  6989. /* Read chip Host Attention (HA) register */
  6990. ha_copy = lpfc_sli_eratt_read(phba);
  6991. break;
  6992. case LPFC_SLI_REV4:
  6993. /* Read devcie Uncoverable Error (UERR) registers */
  6994. ha_copy = lpfc_sli4_eratt_read(phba);
  6995. break;
  6996. default:
  6997. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6998. "0299 Invalid SLI revision (%d)\n",
  6999. phba->sli_rev);
  7000. ha_copy = 0;
  7001. break;
  7002. }
  7003. spin_unlock_irq(&phba->hbalock);
  7004. return ha_copy;
  7005. }
  7006. /**
  7007. * lpfc_intr_state_check - Check device state for interrupt handling
  7008. * @phba: Pointer to HBA context.
  7009. *
  7010. * This inline routine checks whether a device or its PCI slot is in a state
  7011. * that the interrupt should be handled.
  7012. *
  7013. * This function returns 0 if the device or the PCI slot is in a state that
  7014. * interrupt should be handled, otherwise -EIO.
  7015. */
  7016. static inline int
  7017. lpfc_intr_state_check(struct lpfc_hba *phba)
  7018. {
  7019. /* If the pci channel is offline, ignore all the interrupts */
  7020. if (unlikely(pci_channel_offline(phba->pcidev)))
  7021. return -EIO;
  7022. /* Update device level interrupt statistics */
  7023. phba->sli.slistat.sli_intr++;
  7024. /* Ignore all interrupts during initialization. */
  7025. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7026. return -EIO;
  7027. return 0;
  7028. }
  7029. /**
  7030. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7031. * @irq: Interrupt number.
  7032. * @dev_id: The device context pointer.
  7033. *
  7034. * This function is directly called from the PCI layer as an interrupt
  7035. * service routine when device with SLI-3 interface spec is enabled with
  7036. * MSI-X multi-message interrupt mode and there are slow-path events in
  7037. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7038. * interrupt mode, this function is called as part of the device-level
  7039. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7040. * is undergoing initialization, the interrupt handler will not process
  7041. * the interrupt. The link attention and ELS ring attention events are
  7042. * handled by the worker thread. The interrupt handler signals the worker
  7043. * thread and returns for these events. This function is called without
  7044. * any lock held. It gets the hbalock to access and update SLI data
  7045. * structures.
  7046. *
  7047. * This function returns IRQ_HANDLED when interrupt is handled else it
  7048. * returns IRQ_NONE.
  7049. **/
  7050. irqreturn_t
  7051. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7052. {
  7053. struct lpfc_hba *phba;
  7054. uint32_t ha_copy;
  7055. uint32_t work_ha_copy;
  7056. unsigned long status;
  7057. unsigned long iflag;
  7058. uint32_t control;
  7059. MAILBOX_t *mbox, *pmbox;
  7060. struct lpfc_vport *vport;
  7061. struct lpfc_nodelist *ndlp;
  7062. struct lpfc_dmabuf *mp;
  7063. LPFC_MBOXQ_t *pmb;
  7064. int rc;
  7065. /*
  7066. * Get the driver's phba structure from the dev_id and
  7067. * assume the HBA is not interrupting.
  7068. */
  7069. phba = (struct lpfc_hba *)dev_id;
  7070. if (unlikely(!phba))
  7071. return IRQ_NONE;
  7072. /*
  7073. * Stuff needs to be attented to when this function is invoked as an
  7074. * individual interrupt handler in MSI-X multi-message interrupt mode
  7075. */
  7076. if (phba->intr_type == MSIX) {
  7077. /* Check device state for handling interrupt */
  7078. if (lpfc_intr_state_check(phba))
  7079. return IRQ_NONE;
  7080. /* Need to read HA REG for slow-path events */
  7081. spin_lock_irqsave(&phba->hbalock, iflag);
  7082. ha_copy = readl(phba->HAregaddr);
  7083. /* If somebody is waiting to handle an eratt don't process it
  7084. * here. The brdkill function will do this.
  7085. */
  7086. if (phba->link_flag & LS_IGNORE_ERATT)
  7087. ha_copy &= ~HA_ERATT;
  7088. /* Check the need for handling ERATT in interrupt handler */
  7089. if (ha_copy & HA_ERATT) {
  7090. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7091. /* ERATT polling has handled ERATT */
  7092. ha_copy &= ~HA_ERATT;
  7093. else
  7094. /* Indicate interrupt handler handles ERATT */
  7095. phba->hba_flag |= HBA_ERATT_HANDLED;
  7096. }
  7097. /*
  7098. * If there is deferred error attention, do not check for any
  7099. * interrupt.
  7100. */
  7101. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7102. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7103. return IRQ_NONE;
  7104. }
  7105. /* Clear up only attention source related to slow-path */
  7106. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7107. phba->HAregaddr);
  7108. readl(phba->HAregaddr); /* flush */
  7109. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7110. } else
  7111. ha_copy = phba->ha_copy;
  7112. work_ha_copy = ha_copy & phba->work_ha_mask;
  7113. if (work_ha_copy) {
  7114. if (work_ha_copy & HA_LATT) {
  7115. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7116. /*
  7117. * Turn off Link Attention interrupts
  7118. * until CLEAR_LA done
  7119. */
  7120. spin_lock_irqsave(&phba->hbalock, iflag);
  7121. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7122. control = readl(phba->HCregaddr);
  7123. control &= ~HC_LAINT_ENA;
  7124. writel(control, phba->HCregaddr);
  7125. readl(phba->HCregaddr); /* flush */
  7126. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7127. }
  7128. else
  7129. work_ha_copy &= ~HA_LATT;
  7130. }
  7131. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7132. /*
  7133. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7134. * the only slow ring.
  7135. */
  7136. status = (work_ha_copy &
  7137. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7138. status >>= (4*LPFC_ELS_RING);
  7139. if (status & HA_RXMASK) {
  7140. spin_lock_irqsave(&phba->hbalock, iflag);
  7141. control = readl(phba->HCregaddr);
  7142. lpfc_debugfs_slow_ring_trc(phba,
  7143. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7144. control, status,
  7145. (uint32_t)phba->sli.slistat.sli_intr);
  7146. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7147. lpfc_debugfs_slow_ring_trc(phba,
  7148. "ISR Disable ring:"
  7149. "pwork:x%x hawork:x%x wait:x%x",
  7150. phba->work_ha, work_ha_copy,
  7151. (uint32_t)((unsigned long)
  7152. &phba->work_waitq));
  7153. control &=
  7154. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7155. writel(control, phba->HCregaddr);
  7156. readl(phba->HCregaddr); /* flush */
  7157. }
  7158. else {
  7159. lpfc_debugfs_slow_ring_trc(phba,
  7160. "ISR slow ring: pwork:"
  7161. "x%x hawork:x%x wait:x%x",
  7162. phba->work_ha, work_ha_copy,
  7163. (uint32_t)((unsigned long)
  7164. &phba->work_waitq));
  7165. }
  7166. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7167. }
  7168. }
  7169. spin_lock_irqsave(&phba->hbalock, iflag);
  7170. if (work_ha_copy & HA_ERATT) {
  7171. lpfc_sli_read_hs(phba);
  7172. /*
  7173. * Check if there is a deferred error condition
  7174. * is active
  7175. */
  7176. if ((HS_FFER1 & phba->work_hs) &&
  7177. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7178. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7179. phba->hba_flag |= DEFER_ERATT;
  7180. /* Clear all interrupt enable conditions */
  7181. writel(0, phba->HCregaddr);
  7182. readl(phba->HCregaddr);
  7183. }
  7184. }
  7185. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7186. pmb = phba->sli.mbox_active;
  7187. pmbox = &pmb->u.mb;
  7188. mbox = phba->mbox;
  7189. vport = pmb->vport;
  7190. /* First check out the status word */
  7191. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7192. if (pmbox->mbxOwner != OWN_HOST) {
  7193. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7194. /*
  7195. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7196. * mbxStatus <status>
  7197. */
  7198. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7199. LOG_SLI,
  7200. "(%d):0304 Stray Mailbox "
  7201. "Interrupt mbxCommand x%x "
  7202. "mbxStatus x%x\n",
  7203. (vport ? vport->vpi : 0),
  7204. pmbox->mbxCommand,
  7205. pmbox->mbxStatus);
  7206. /* clear mailbox attention bit */
  7207. work_ha_copy &= ~HA_MBATT;
  7208. } else {
  7209. phba->sli.mbox_active = NULL;
  7210. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7211. phba->last_completion_time = jiffies;
  7212. del_timer(&phba->sli.mbox_tmo);
  7213. if (pmb->mbox_cmpl) {
  7214. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7215. MAILBOX_CMD_SIZE);
  7216. }
  7217. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7218. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7219. lpfc_debugfs_disc_trc(vport,
  7220. LPFC_DISC_TRC_MBOX_VPORT,
  7221. "MBOX dflt rpi: : "
  7222. "status:x%x rpi:x%x",
  7223. (uint32_t)pmbox->mbxStatus,
  7224. pmbox->un.varWords[0], 0);
  7225. if (!pmbox->mbxStatus) {
  7226. mp = (struct lpfc_dmabuf *)
  7227. (pmb->context1);
  7228. ndlp = (struct lpfc_nodelist *)
  7229. pmb->context2;
  7230. /* Reg_LOGIN of dflt RPI was
  7231. * successful. new lets get
  7232. * rid of the RPI using the
  7233. * same mbox buffer.
  7234. */
  7235. lpfc_unreg_login(phba,
  7236. vport->vpi,
  7237. pmbox->un.varWords[0],
  7238. pmb);
  7239. pmb->mbox_cmpl =
  7240. lpfc_mbx_cmpl_dflt_rpi;
  7241. pmb->context1 = mp;
  7242. pmb->context2 = ndlp;
  7243. pmb->vport = vport;
  7244. rc = lpfc_sli_issue_mbox(phba,
  7245. pmb,
  7246. MBX_NOWAIT);
  7247. if (rc != MBX_BUSY)
  7248. lpfc_printf_log(phba,
  7249. KERN_ERR,
  7250. LOG_MBOX | LOG_SLI,
  7251. "0350 rc should have"
  7252. "been MBX_BUSY");
  7253. if (rc != MBX_NOT_FINISHED)
  7254. goto send_current_mbox;
  7255. }
  7256. }
  7257. spin_lock_irqsave(
  7258. &phba->pport->work_port_lock,
  7259. iflag);
  7260. phba->pport->work_port_events &=
  7261. ~WORKER_MBOX_TMO;
  7262. spin_unlock_irqrestore(
  7263. &phba->pport->work_port_lock,
  7264. iflag);
  7265. lpfc_mbox_cmpl_put(phba, pmb);
  7266. }
  7267. } else
  7268. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7269. if ((work_ha_copy & HA_MBATT) &&
  7270. (phba->sli.mbox_active == NULL)) {
  7271. send_current_mbox:
  7272. /* Process next mailbox command if there is one */
  7273. do {
  7274. rc = lpfc_sli_issue_mbox(phba, NULL,
  7275. MBX_NOWAIT);
  7276. } while (rc == MBX_NOT_FINISHED);
  7277. if (rc != MBX_SUCCESS)
  7278. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7279. LOG_SLI, "0349 rc should be "
  7280. "MBX_SUCCESS");
  7281. }
  7282. spin_lock_irqsave(&phba->hbalock, iflag);
  7283. phba->work_ha |= work_ha_copy;
  7284. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7285. lpfc_worker_wake_up(phba);
  7286. }
  7287. return IRQ_HANDLED;
  7288. } /* lpfc_sli_sp_intr_handler */
  7289. /**
  7290. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7291. * @irq: Interrupt number.
  7292. * @dev_id: The device context pointer.
  7293. *
  7294. * This function is directly called from the PCI layer as an interrupt
  7295. * service routine when device with SLI-3 interface spec is enabled with
  7296. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7297. * ring event in the HBA. However, when the device is enabled with either
  7298. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7299. * device-level interrupt handler. When the PCI slot is in error recovery
  7300. * or the HBA is undergoing initialization, the interrupt handler will not
  7301. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7302. * the intrrupt context. This function is called without any lock held.
  7303. * It gets the hbalock to access and update SLI data structures.
  7304. *
  7305. * This function returns IRQ_HANDLED when interrupt is handled else it
  7306. * returns IRQ_NONE.
  7307. **/
  7308. irqreturn_t
  7309. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7310. {
  7311. struct lpfc_hba *phba;
  7312. uint32_t ha_copy;
  7313. unsigned long status;
  7314. unsigned long iflag;
  7315. /* Get the driver's phba structure from the dev_id and
  7316. * assume the HBA is not interrupting.
  7317. */
  7318. phba = (struct lpfc_hba *) dev_id;
  7319. if (unlikely(!phba))
  7320. return IRQ_NONE;
  7321. /*
  7322. * Stuff needs to be attented to when this function is invoked as an
  7323. * individual interrupt handler in MSI-X multi-message interrupt mode
  7324. */
  7325. if (phba->intr_type == MSIX) {
  7326. /* Check device state for handling interrupt */
  7327. if (lpfc_intr_state_check(phba))
  7328. return IRQ_NONE;
  7329. /* Need to read HA REG for FCP ring and other ring events */
  7330. ha_copy = readl(phba->HAregaddr);
  7331. /* Clear up only attention source related to fast-path */
  7332. spin_lock_irqsave(&phba->hbalock, iflag);
  7333. /*
  7334. * If there is deferred error attention, do not check for
  7335. * any interrupt.
  7336. */
  7337. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7338. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7339. return IRQ_NONE;
  7340. }
  7341. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7342. phba->HAregaddr);
  7343. readl(phba->HAregaddr); /* flush */
  7344. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7345. } else
  7346. ha_copy = phba->ha_copy;
  7347. /*
  7348. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7349. */
  7350. ha_copy &= ~(phba->work_ha_mask);
  7351. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7352. status >>= (4*LPFC_FCP_RING);
  7353. if (status & HA_RXMASK)
  7354. lpfc_sli_handle_fast_ring_event(phba,
  7355. &phba->sli.ring[LPFC_FCP_RING],
  7356. status);
  7357. if (phba->cfg_multi_ring_support == 2) {
  7358. /*
  7359. * Process all events on extra ring. Take the optimized path
  7360. * for extra ring IO.
  7361. */
  7362. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7363. status >>= (4*LPFC_EXTRA_RING);
  7364. if (status & HA_RXMASK) {
  7365. lpfc_sli_handle_fast_ring_event(phba,
  7366. &phba->sli.ring[LPFC_EXTRA_RING],
  7367. status);
  7368. }
  7369. }
  7370. return IRQ_HANDLED;
  7371. } /* lpfc_sli_fp_intr_handler */
  7372. /**
  7373. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7374. * @irq: Interrupt number.
  7375. * @dev_id: The device context pointer.
  7376. *
  7377. * This function is the HBA device-level interrupt handler to device with
  7378. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7379. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7380. * requires driver attention. This function invokes the slow-path interrupt
  7381. * attention handling function and fast-path interrupt attention handling
  7382. * function in turn to process the relevant HBA attention events. This
  7383. * function is called without any lock held. It gets the hbalock to access
  7384. * and update SLI data structures.
  7385. *
  7386. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7387. * returns IRQ_NONE.
  7388. **/
  7389. irqreturn_t
  7390. lpfc_sli_intr_handler(int irq, void *dev_id)
  7391. {
  7392. struct lpfc_hba *phba;
  7393. irqreturn_t sp_irq_rc, fp_irq_rc;
  7394. unsigned long status1, status2;
  7395. /*
  7396. * Get the driver's phba structure from the dev_id and
  7397. * assume the HBA is not interrupting.
  7398. */
  7399. phba = (struct lpfc_hba *) dev_id;
  7400. if (unlikely(!phba))
  7401. return IRQ_NONE;
  7402. /* Check device state for handling interrupt */
  7403. if (lpfc_intr_state_check(phba))
  7404. return IRQ_NONE;
  7405. spin_lock(&phba->hbalock);
  7406. phba->ha_copy = readl(phba->HAregaddr);
  7407. if (unlikely(!phba->ha_copy)) {
  7408. spin_unlock(&phba->hbalock);
  7409. return IRQ_NONE;
  7410. } else if (phba->ha_copy & HA_ERATT) {
  7411. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7412. /* ERATT polling has handled ERATT */
  7413. phba->ha_copy &= ~HA_ERATT;
  7414. else
  7415. /* Indicate interrupt handler handles ERATT */
  7416. phba->hba_flag |= HBA_ERATT_HANDLED;
  7417. }
  7418. /*
  7419. * If there is deferred error attention, do not check for any interrupt.
  7420. */
  7421. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7422. spin_unlock_irq(&phba->hbalock);
  7423. return IRQ_NONE;
  7424. }
  7425. /* Clear attention sources except link and error attentions */
  7426. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7427. readl(phba->HAregaddr); /* flush */
  7428. spin_unlock(&phba->hbalock);
  7429. /*
  7430. * Invokes slow-path host attention interrupt handling as appropriate.
  7431. */
  7432. /* status of events with mailbox and link attention */
  7433. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7434. /* status of events with ELS ring */
  7435. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7436. status2 >>= (4*LPFC_ELS_RING);
  7437. if (status1 || (status2 & HA_RXMASK))
  7438. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7439. else
  7440. sp_irq_rc = IRQ_NONE;
  7441. /*
  7442. * Invoke fast-path host attention interrupt handling as appropriate.
  7443. */
  7444. /* status of events with FCP ring */
  7445. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7446. status1 >>= (4*LPFC_FCP_RING);
  7447. /* status of events with extra ring */
  7448. if (phba->cfg_multi_ring_support == 2) {
  7449. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7450. status2 >>= (4*LPFC_EXTRA_RING);
  7451. } else
  7452. status2 = 0;
  7453. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7454. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7455. else
  7456. fp_irq_rc = IRQ_NONE;
  7457. /* Return device-level interrupt handling status */
  7458. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7459. } /* lpfc_sli_intr_handler */
  7460. /**
  7461. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7462. * @phba: pointer to lpfc hba data structure.
  7463. *
  7464. * This routine is invoked by the worker thread to process all the pending
  7465. * SLI4 FCP abort XRI events.
  7466. **/
  7467. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7468. {
  7469. struct lpfc_cq_event *cq_event;
  7470. /* First, declare the fcp xri abort event has been handled */
  7471. spin_lock_irq(&phba->hbalock);
  7472. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7473. spin_unlock_irq(&phba->hbalock);
  7474. /* Now, handle all the fcp xri abort events */
  7475. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7476. /* Get the first event from the head of the event queue */
  7477. spin_lock_irq(&phba->hbalock);
  7478. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7479. cq_event, struct lpfc_cq_event, list);
  7480. spin_unlock_irq(&phba->hbalock);
  7481. /* Notify aborted XRI for FCP work queue */
  7482. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7483. /* Free the event processed back to the free pool */
  7484. lpfc_sli4_cq_event_release(phba, cq_event);
  7485. }
  7486. }
  7487. /**
  7488. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7489. * @phba: pointer to lpfc hba data structure.
  7490. *
  7491. * This routine is invoked by the worker thread to process all the pending
  7492. * SLI4 els abort xri events.
  7493. **/
  7494. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7495. {
  7496. struct lpfc_cq_event *cq_event;
  7497. /* First, declare the els xri abort event has been handled */
  7498. spin_lock_irq(&phba->hbalock);
  7499. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7500. spin_unlock_irq(&phba->hbalock);
  7501. /* Now, handle all the els xri abort events */
  7502. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7503. /* Get the first event from the head of the event queue */
  7504. spin_lock_irq(&phba->hbalock);
  7505. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7506. cq_event, struct lpfc_cq_event, list);
  7507. spin_unlock_irq(&phba->hbalock);
  7508. /* Notify aborted XRI for ELS work queue */
  7509. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7510. /* Free the event processed back to the free pool */
  7511. lpfc_sli4_cq_event_release(phba, cq_event);
  7512. }
  7513. }
  7514. static void
  7515. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7516. struct lpfc_iocbq *pIocbOut,
  7517. struct lpfc_wcqe_complete *wcqe)
  7518. {
  7519. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7520. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7521. sizeof(struct lpfc_iocbq) - offset);
  7522. memset(&pIocbIn->sli4_info, 0,
  7523. sizeof(struct lpfc_sli4_rspiocb_info));
  7524. /* Map WCQE parameters into irspiocb parameters */
  7525. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7526. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7527. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7528. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7529. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7530. wcqe->total_data_placed;
  7531. else
  7532. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7533. else
  7534. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7535. /* Load in additional WCQE parameters */
  7536. pIocbIn->sli4_info.hw_status = bf_get(lpfc_wcqe_c_hw_status, wcqe);
  7537. pIocbIn->sli4_info.bfield = 0;
  7538. if (bf_get(lpfc_wcqe_c_xb, wcqe))
  7539. pIocbIn->sli4_info.bfield |= LPFC_XB;
  7540. if (bf_get(lpfc_wcqe_c_pv, wcqe)) {
  7541. pIocbIn->sli4_info.bfield |= LPFC_PV;
  7542. pIocbIn->sli4_info.priority =
  7543. bf_get(lpfc_wcqe_c_priority, wcqe);
  7544. }
  7545. }
  7546. /**
  7547. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7548. * @phba: Pointer to HBA context object.
  7549. * @cqe: Pointer to mailbox completion queue entry.
  7550. *
  7551. * This routine process a mailbox completion queue entry with asynchrous
  7552. * event.
  7553. *
  7554. * Return: true if work posted to worker thread, otherwise false.
  7555. **/
  7556. static bool
  7557. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7558. {
  7559. struct lpfc_cq_event *cq_event;
  7560. unsigned long iflags;
  7561. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7562. "0392 Async Event: word0:x%x, word1:x%x, "
  7563. "word2:x%x, word3:x%x\n", mcqe->word0,
  7564. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7565. /* Allocate a new internal CQ_EVENT entry */
  7566. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7567. if (!cq_event) {
  7568. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7569. "0394 Failed to allocate CQ_EVENT entry\n");
  7570. return false;
  7571. }
  7572. /* Move the CQE into an asynchronous event entry */
  7573. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7574. spin_lock_irqsave(&phba->hbalock, iflags);
  7575. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7576. /* Set the async event flag */
  7577. phba->hba_flag |= ASYNC_EVENT;
  7578. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7579. return true;
  7580. }
  7581. /**
  7582. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7583. * @phba: Pointer to HBA context object.
  7584. * @cqe: Pointer to mailbox completion queue entry.
  7585. *
  7586. * This routine process a mailbox completion queue entry with mailbox
  7587. * completion event.
  7588. *
  7589. * Return: true if work posted to worker thread, otherwise false.
  7590. **/
  7591. static bool
  7592. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7593. {
  7594. uint32_t mcqe_status;
  7595. MAILBOX_t *mbox, *pmbox;
  7596. struct lpfc_mqe *mqe;
  7597. struct lpfc_vport *vport;
  7598. struct lpfc_nodelist *ndlp;
  7599. struct lpfc_dmabuf *mp;
  7600. unsigned long iflags;
  7601. LPFC_MBOXQ_t *pmb;
  7602. bool workposted = false;
  7603. int rc;
  7604. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7605. if (!bf_get(lpfc_trailer_completed, mcqe))
  7606. goto out_no_mqe_complete;
  7607. /* Get the reference to the active mbox command */
  7608. spin_lock_irqsave(&phba->hbalock, iflags);
  7609. pmb = phba->sli.mbox_active;
  7610. if (unlikely(!pmb)) {
  7611. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7612. "1832 No pending MBOX command to handle\n");
  7613. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7614. goto out_no_mqe_complete;
  7615. }
  7616. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7617. mqe = &pmb->u.mqe;
  7618. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7619. mbox = phba->mbox;
  7620. vport = pmb->vport;
  7621. /* Reset heartbeat timer */
  7622. phba->last_completion_time = jiffies;
  7623. del_timer(&phba->sli.mbox_tmo);
  7624. /* Move mbox data to caller's mailbox region, do endian swapping */
  7625. if (pmb->mbox_cmpl && mbox)
  7626. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7627. /* Set the mailbox status with SLI4 range 0x4000 */
  7628. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7629. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7630. bf_set(lpfc_mqe_status, mqe,
  7631. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7632. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7633. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7634. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7635. "MBOX dflt rpi: status:x%x rpi:x%x",
  7636. mcqe_status,
  7637. pmbox->un.varWords[0], 0);
  7638. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7639. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7640. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7641. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7642. * RID of the PPI using the same mbox buffer.
  7643. */
  7644. lpfc_unreg_login(phba, vport->vpi,
  7645. pmbox->un.varWords[0], pmb);
  7646. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7647. pmb->context1 = mp;
  7648. pmb->context2 = ndlp;
  7649. pmb->vport = vport;
  7650. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7651. if (rc != MBX_BUSY)
  7652. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7653. LOG_SLI, "0385 rc should "
  7654. "have been MBX_BUSY\n");
  7655. if (rc != MBX_NOT_FINISHED)
  7656. goto send_current_mbox;
  7657. }
  7658. }
  7659. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7660. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7661. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7662. /* There is mailbox completion work to do */
  7663. spin_lock_irqsave(&phba->hbalock, iflags);
  7664. __lpfc_mbox_cmpl_put(phba, pmb);
  7665. phba->work_ha |= HA_MBATT;
  7666. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7667. workposted = true;
  7668. send_current_mbox:
  7669. spin_lock_irqsave(&phba->hbalock, iflags);
  7670. /* Release the mailbox command posting token */
  7671. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7672. /* Setting active mailbox pointer need to be in sync to flag clear */
  7673. phba->sli.mbox_active = NULL;
  7674. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7675. /* Wake up worker thread to post the next pending mailbox command */
  7676. lpfc_worker_wake_up(phba);
  7677. out_no_mqe_complete:
  7678. if (bf_get(lpfc_trailer_consumed, mcqe))
  7679. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7680. return workposted;
  7681. }
  7682. /**
  7683. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7684. * @phba: Pointer to HBA context object.
  7685. * @cqe: Pointer to mailbox completion queue entry.
  7686. *
  7687. * This routine process a mailbox completion queue entry, it invokes the
  7688. * proper mailbox complete handling or asynchrous event handling routine
  7689. * according to the MCQE's async bit.
  7690. *
  7691. * Return: true if work posted to worker thread, otherwise false.
  7692. **/
  7693. static bool
  7694. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7695. {
  7696. struct lpfc_mcqe mcqe;
  7697. bool workposted;
  7698. /* Copy the mailbox MCQE and convert endian order as needed */
  7699. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7700. /* Invoke the proper event handling routine */
  7701. if (!bf_get(lpfc_trailer_async, &mcqe))
  7702. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7703. else
  7704. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7705. return workposted;
  7706. }
  7707. /**
  7708. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7709. * @phba: Pointer to HBA context object.
  7710. * @wcqe: Pointer to work-queue completion queue entry.
  7711. *
  7712. * This routine handles an ELS work-queue completion event.
  7713. *
  7714. * Return: true if work posted to worker thread, otherwise false.
  7715. **/
  7716. static bool
  7717. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7718. struct lpfc_wcqe_complete *wcqe)
  7719. {
  7720. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7721. struct lpfc_iocbq *cmdiocbq;
  7722. struct lpfc_iocbq *irspiocbq;
  7723. unsigned long iflags;
  7724. bool workposted = false;
  7725. spin_lock_irqsave(&phba->hbalock, iflags);
  7726. pring->stats.iocb_event++;
  7727. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7728. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7729. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7730. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7731. if (unlikely(!cmdiocbq)) {
  7732. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7733. "0386 ELS complete with no corresponding "
  7734. "cmdiocb: iotag (%d)\n",
  7735. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7736. return workposted;
  7737. }
  7738. /* Fake the irspiocbq and copy necessary response information */
  7739. irspiocbq = lpfc_sli_get_iocbq(phba);
  7740. if (!irspiocbq) {
  7741. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7742. "0387 Failed to allocate an iocbq\n");
  7743. return workposted;
  7744. }
  7745. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7746. /* Add the irspiocb to the response IOCB work list */
  7747. spin_lock_irqsave(&phba->hbalock, iflags);
  7748. list_add_tail(&irspiocbq->list, &phba->sli4_hba.sp_rspiocb_work_queue);
  7749. /* Indicate ELS ring attention */
  7750. phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
  7751. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7752. workposted = true;
  7753. return workposted;
  7754. }
  7755. /**
  7756. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7757. * @phba: Pointer to HBA context object.
  7758. * @wcqe: Pointer to work-queue completion queue entry.
  7759. *
  7760. * This routine handles slow-path WQ entry comsumed event by invoking the
  7761. * proper WQ release routine to the slow-path WQ.
  7762. **/
  7763. static void
  7764. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7765. struct lpfc_wcqe_release *wcqe)
  7766. {
  7767. /* Check for the slow-path ELS work queue */
  7768. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7769. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7770. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7771. else
  7772. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7773. "2579 Slow-path wqe consume event carries "
  7774. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7775. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7776. phba->sli4_hba.els_wq->queue_id);
  7777. }
  7778. /**
  7779. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7780. * @phba: Pointer to HBA context object.
  7781. * @cq: Pointer to a WQ completion queue.
  7782. * @wcqe: Pointer to work-queue completion queue entry.
  7783. *
  7784. * This routine handles an XRI abort event.
  7785. *
  7786. * Return: true if work posted to worker thread, otherwise false.
  7787. **/
  7788. static bool
  7789. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7790. struct lpfc_queue *cq,
  7791. struct sli4_wcqe_xri_aborted *wcqe)
  7792. {
  7793. bool workposted = false;
  7794. struct lpfc_cq_event *cq_event;
  7795. unsigned long iflags;
  7796. /* Allocate a new internal CQ_EVENT entry */
  7797. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7798. if (!cq_event) {
  7799. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7800. "0602 Failed to allocate CQ_EVENT entry\n");
  7801. return false;
  7802. }
  7803. /* Move the CQE into the proper xri abort event list */
  7804. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7805. switch (cq->subtype) {
  7806. case LPFC_FCP:
  7807. spin_lock_irqsave(&phba->hbalock, iflags);
  7808. list_add_tail(&cq_event->list,
  7809. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7810. /* Set the fcp xri abort event flag */
  7811. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7812. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7813. workposted = true;
  7814. break;
  7815. case LPFC_ELS:
  7816. spin_lock_irqsave(&phba->hbalock, iflags);
  7817. list_add_tail(&cq_event->list,
  7818. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7819. /* Set the els xri abort event flag */
  7820. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7821. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7822. workposted = true;
  7823. break;
  7824. default:
  7825. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7826. "0603 Invalid work queue CQE subtype (x%x)\n",
  7827. cq->subtype);
  7828. workposted = false;
  7829. break;
  7830. }
  7831. return workposted;
  7832. }
  7833. /**
  7834. * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry
  7835. * @phba: Pointer to HBA context object.
  7836. * @cq: Pointer to the completion queue.
  7837. * @wcqe: Pointer to a completion queue entry.
  7838. *
  7839. * This routine process a slow-path work-queue completion queue entry.
  7840. *
  7841. * Return: true if work posted to worker thread, otherwise false.
  7842. **/
  7843. static bool
  7844. lpfc_sli4_sp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7845. struct lpfc_cqe *cqe)
  7846. {
  7847. struct lpfc_wcqe_complete wcqe;
  7848. bool workposted = false;
  7849. /* Copy the work queue CQE and convert endian order if needed */
  7850. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  7851. /* Check and process for different type of WCQE and dispatch */
  7852. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  7853. case CQE_CODE_COMPL_WQE:
  7854. /* Process the WQ complete event */
  7855. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7856. (struct lpfc_wcqe_complete *)&wcqe);
  7857. break;
  7858. case CQE_CODE_RELEASE_WQE:
  7859. /* Process the WQ release event */
  7860. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7861. (struct lpfc_wcqe_release *)&wcqe);
  7862. break;
  7863. case CQE_CODE_XRI_ABORTED:
  7864. /* Process the WQ XRI abort event */
  7865. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7866. (struct sli4_wcqe_xri_aborted *)&wcqe);
  7867. break;
  7868. default:
  7869. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7870. "0388 Not a valid WCQE code: x%x\n",
  7871. bf_get(lpfc_wcqe_c_code, &wcqe));
  7872. break;
  7873. }
  7874. return workposted;
  7875. }
  7876. /**
  7877. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7878. * @phba: Pointer to HBA context object.
  7879. * @rcqe: Pointer to receive-queue completion queue entry.
  7880. *
  7881. * This routine process a receive-queue completion queue entry.
  7882. *
  7883. * Return: true if work posted to worker thread, otherwise false.
  7884. **/
  7885. static bool
  7886. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7887. {
  7888. struct lpfc_rcqe rcqe;
  7889. bool workposted = false;
  7890. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7891. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7892. struct hbq_dmabuf *dma_buf;
  7893. uint32_t status;
  7894. unsigned long iflags;
  7895. /* Copy the receive queue CQE and convert endian order if needed */
  7896. lpfc_sli_pcimem_bcopy(cqe, &rcqe, sizeof(struct lpfc_rcqe));
  7897. lpfc_sli4_rq_release(hrq, drq);
  7898. if (bf_get(lpfc_rcqe_code, &rcqe) != CQE_CODE_RECEIVE)
  7899. goto out;
  7900. if (bf_get(lpfc_rcqe_rq_id, &rcqe) != hrq->queue_id)
  7901. goto out;
  7902. status = bf_get(lpfc_rcqe_status, &rcqe);
  7903. switch (status) {
  7904. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7905. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7906. "2537 Receive Frame Truncated!!\n");
  7907. case FC_STATUS_RQ_SUCCESS:
  7908. spin_lock_irqsave(&phba->hbalock, iflags);
  7909. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7910. if (!dma_buf) {
  7911. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7912. goto out;
  7913. }
  7914. memcpy(&dma_buf->rcqe, &rcqe, sizeof(rcqe));
  7915. /* save off the frame for the word thread to process */
  7916. list_add_tail(&dma_buf->dbuf.list, &phba->rb_pend_list);
  7917. /* Frame received */
  7918. phba->hba_flag |= HBA_RECEIVE_BUFFER;
  7919. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7920. workposted = true;
  7921. break;
  7922. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7923. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7924. /* Post more buffers if possible */
  7925. spin_lock_irqsave(&phba->hbalock, iflags);
  7926. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7927. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7928. workposted = true;
  7929. break;
  7930. }
  7931. out:
  7932. return workposted;
  7933. }
  7934. /**
  7935. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  7936. * @phba: Pointer to HBA context object.
  7937. * @eqe: Pointer to fast-path event queue entry.
  7938. *
  7939. * This routine process a event queue entry from the slow-path event queue.
  7940. * It will check the MajorCode and MinorCode to determine this is for a
  7941. * completion event on a completion queue, if not, an error shall be logged
  7942. * and just return. Otherwise, it will get to the corresponding completion
  7943. * queue and process all the entries on that completion queue, rearm the
  7944. * completion queue, and then return.
  7945. *
  7946. **/
  7947. static void
  7948. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  7949. {
  7950. struct lpfc_queue *cq = NULL, *childq, *speq;
  7951. struct lpfc_cqe *cqe;
  7952. bool workposted = false;
  7953. int ecount = 0;
  7954. uint16_t cqid;
  7955. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  7956. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  7957. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7958. "0359 Not a valid slow-path completion "
  7959. "event: majorcode=x%x, minorcode=x%x\n",
  7960. bf_get(lpfc_eqe_major_code, eqe),
  7961. bf_get(lpfc_eqe_minor_code, eqe));
  7962. return;
  7963. }
  7964. /* Get the reference to the corresponding CQ */
  7965. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  7966. /* Search for completion queue pointer matching this cqid */
  7967. speq = phba->sli4_hba.sp_eq;
  7968. list_for_each_entry(childq, &speq->child_list, list) {
  7969. if (childq->queue_id == cqid) {
  7970. cq = childq;
  7971. break;
  7972. }
  7973. }
  7974. if (unlikely(!cq)) {
  7975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7976. "0365 Slow-path CQ identifier (%d) does "
  7977. "not exist\n", cqid);
  7978. return;
  7979. }
  7980. /* Process all the entries to the CQ */
  7981. switch (cq->type) {
  7982. case LPFC_MCQ:
  7983. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7984. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  7985. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7986. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7987. }
  7988. break;
  7989. case LPFC_WCQ:
  7990. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7991. workposted |= lpfc_sli4_sp_handle_wcqe(phba, cq, cqe);
  7992. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7993. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7994. }
  7995. break;
  7996. case LPFC_RCQ:
  7997. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7998. workposted |= lpfc_sli4_sp_handle_rcqe(phba, cqe);
  7999. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8000. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8001. }
  8002. break;
  8003. default:
  8004. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8005. "0370 Invalid completion queue type (%d)\n",
  8006. cq->type);
  8007. return;
  8008. }
  8009. /* Catch the no cq entry condition, log an error */
  8010. if (unlikely(ecount == 0))
  8011. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8012. "0371 No entry from the CQ: identifier "
  8013. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8014. /* In any case, flash and re-arm the RCQ */
  8015. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8016. /* wake up worker thread if there are works to be done */
  8017. if (workposted)
  8018. lpfc_worker_wake_up(phba);
  8019. }
  8020. /**
  8021. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8022. * @eqe: Pointer to fast-path completion queue entry.
  8023. *
  8024. * This routine process a fast-path work queue completion entry from fast-path
  8025. * event queue for FCP command response completion.
  8026. **/
  8027. static void
  8028. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8029. struct lpfc_wcqe_complete *wcqe)
  8030. {
  8031. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8032. struct lpfc_iocbq *cmdiocbq;
  8033. struct lpfc_iocbq irspiocbq;
  8034. unsigned long iflags;
  8035. spin_lock_irqsave(&phba->hbalock, iflags);
  8036. pring->stats.iocb_event++;
  8037. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8038. /* Check for response status */
  8039. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8040. /* If resource errors reported from HBA, reduce queue
  8041. * depth of the SCSI device.
  8042. */
  8043. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8044. IOSTAT_LOCAL_REJECT) &&
  8045. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8046. phba->lpfc_rampdown_queue_depth(phba);
  8047. }
  8048. /* Log the error status */
  8049. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8050. "0373 FCP complete error: status=x%x, "
  8051. "hw_status=x%x, total_data_specified=%d, "
  8052. "parameter=x%x, word3=x%x\n",
  8053. bf_get(lpfc_wcqe_c_status, wcqe),
  8054. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8055. wcqe->total_data_placed, wcqe->parameter,
  8056. wcqe->word3);
  8057. }
  8058. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8059. spin_lock_irqsave(&phba->hbalock, iflags);
  8060. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8061. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8062. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8063. if (unlikely(!cmdiocbq)) {
  8064. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8065. "0374 FCP complete with no corresponding "
  8066. "cmdiocb: iotag (%d)\n",
  8067. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8068. return;
  8069. }
  8070. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8071. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8072. "0375 FCP cmdiocb not callback function "
  8073. "iotag: (%d)\n",
  8074. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8075. return;
  8076. }
  8077. /* Fake the irspiocb and copy necessary response information */
  8078. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  8079. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8080. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8081. }
  8082. /**
  8083. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8084. * @phba: Pointer to HBA context object.
  8085. * @cq: Pointer to completion queue.
  8086. * @wcqe: Pointer to work-queue completion queue entry.
  8087. *
  8088. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8089. * proper WQ release routine to the slow-path WQ.
  8090. **/
  8091. static void
  8092. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8093. struct lpfc_wcqe_release *wcqe)
  8094. {
  8095. struct lpfc_queue *childwq;
  8096. bool wqid_matched = false;
  8097. uint16_t fcp_wqid;
  8098. /* Check for fast-path FCP work queue release */
  8099. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8100. list_for_each_entry(childwq, &cq->child_list, list) {
  8101. if (childwq->queue_id == fcp_wqid) {
  8102. lpfc_sli4_wq_release(childwq,
  8103. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8104. wqid_matched = true;
  8105. break;
  8106. }
  8107. }
  8108. /* Report warning log message if no match found */
  8109. if (wqid_matched != true)
  8110. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8111. "2580 Fast-path wqe consume event carries "
  8112. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8113. }
  8114. /**
  8115. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8116. * @cq: Pointer to the completion queue.
  8117. * @eqe: Pointer to fast-path completion queue entry.
  8118. *
  8119. * This routine process a fast-path work queue completion entry from fast-path
  8120. * event queue for FCP command response completion.
  8121. **/
  8122. static int
  8123. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8124. struct lpfc_cqe *cqe)
  8125. {
  8126. struct lpfc_wcqe_release wcqe;
  8127. bool workposted = false;
  8128. /* Copy the work queue CQE and convert endian order if needed */
  8129. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8130. /* Check and process for different type of WCQE and dispatch */
  8131. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8132. case CQE_CODE_COMPL_WQE:
  8133. /* Process the WQ complete event */
  8134. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8135. (struct lpfc_wcqe_complete *)&wcqe);
  8136. break;
  8137. case CQE_CODE_RELEASE_WQE:
  8138. /* Process the WQ release event */
  8139. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8140. (struct lpfc_wcqe_release *)&wcqe);
  8141. break;
  8142. case CQE_CODE_XRI_ABORTED:
  8143. /* Process the WQ XRI abort event */
  8144. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8145. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8146. break;
  8147. default:
  8148. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8149. "0144 Not a valid WCQE code: x%x\n",
  8150. bf_get(lpfc_wcqe_c_code, &wcqe));
  8151. break;
  8152. }
  8153. return workposted;
  8154. }
  8155. /**
  8156. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8157. * @phba: Pointer to HBA context object.
  8158. * @eqe: Pointer to fast-path event queue entry.
  8159. *
  8160. * This routine process a event queue entry from the fast-path event queue.
  8161. * It will check the MajorCode and MinorCode to determine this is for a
  8162. * completion event on a completion queue, if not, an error shall be logged
  8163. * and just return. Otherwise, it will get to the corresponding completion
  8164. * queue and process all the entries on the completion queue, rearm the
  8165. * completion queue, and then return.
  8166. **/
  8167. static void
  8168. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8169. uint32_t fcp_cqidx)
  8170. {
  8171. struct lpfc_queue *cq;
  8172. struct lpfc_cqe *cqe;
  8173. bool workposted = false;
  8174. uint16_t cqid;
  8175. int ecount = 0;
  8176. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8177. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8178. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8179. "0366 Not a valid fast-path completion "
  8180. "event: majorcode=x%x, minorcode=x%x\n",
  8181. bf_get(lpfc_eqe_major_code, eqe),
  8182. bf_get(lpfc_eqe_minor_code, eqe));
  8183. return;
  8184. }
  8185. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8186. if (unlikely(!cq)) {
  8187. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8188. "0367 Fast-path completion queue does not "
  8189. "exist\n");
  8190. return;
  8191. }
  8192. /* Get the reference to the corresponding CQ */
  8193. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8194. if (unlikely(cqid != cq->queue_id)) {
  8195. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8196. "0368 Miss-matched fast-path completion "
  8197. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8198. cqid, cq->queue_id);
  8199. return;
  8200. }
  8201. /* Process all the entries to the CQ */
  8202. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8203. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8204. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8205. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8206. }
  8207. /* Catch the no cq entry condition */
  8208. if (unlikely(ecount == 0))
  8209. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8210. "0369 No entry from fast-path completion "
  8211. "queue fcpcqid=%d\n", cq->queue_id);
  8212. /* In any case, flash and re-arm the CQ */
  8213. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8214. /* wake up worker thread if there are works to be done */
  8215. if (workposted)
  8216. lpfc_worker_wake_up(phba);
  8217. }
  8218. static void
  8219. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8220. {
  8221. struct lpfc_eqe *eqe;
  8222. /* walk all the EQ entries and drop on the floor */
  8223. while ((eqe = lpfc_sli4_eq_get(eq)))
  8224. ;
  8225. /* Clear and re-arm the EQ */
  8226. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8227. }
  8228. /**
  8229. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8230. * @irq: Interrupt number.
  8231. * @dev_id: The device context pointer.
  8232. *
  8233. * This function is directly called from the PCI layer as an interrupt
  8234. * service routine when device with SLI-4 interface spec is enabled with
  8235. * MSI-X multi-message interrupt mode and there are slow-path events in
  8236. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8237. * interrupt mode, this function is called as part of the device-level
  8238. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8239. * undergoing initialization, the interrupt handler will not process the
  8240. * interrupt. The link attention and ELS ring attention events are handled
  8241. * by the worker thread. The interrupt handler signals the worker thread
  8242. * and returns for these events. This function is called without any lock
  8243. * held. It gets the hbalock to access and update SLI data structures.
  8244. *
  8245. * This function returns IRQ_HANDLED when interrupt is handled else it
  8246. * returns IRQ_NONE.
  8247. **/
  8248. irqreturn_t
  8249. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8250. {
  8251. struct lpfc_hba *phba;
  8252. struct lpfc_queue *speq;
  8253. struct lpfc_eqe *eqe;
  8254. unsigned long iflag;
  8255. int ecount = 0;
  8256. /*
  8257. * Get the driver's phba structure from the dev_id
  8258. */
  8259. phba = (struct lpfc_hba *)dev_id;
  8260. if (unlikely(!phba))
  8261. return IRQ_NONE;
  8262. /* Get to the EQ struct associated with this vector */
  8263. speq = phba->sli4_hba.sp_eq;
  8264. /* Check device state for handling interrupt */
  8265. if (unlikely(lpfc_intr_state_check(phba))) {
  8266. /* Check again for link_state with lock held */
  8267. spin_lock_irqsave(&phba->hbalock, iflag);
  8268. if (phba->link_state < LPFC_LINK_DOWN)
  8269. /* Flush, clear interrupt, and rearm the EQ */
  8270. lpfc_sli4_eq_flush(phba, speq);
  8271. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8272. return IRQ_NONE;
  8273. }
  8274. /*
  8275. * Process all the event on FCP slow-path EQ
  8276. */
  8277. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8278. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8279. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8280. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8281. }
  8282. /* Always clear and re-arm the slow-path EQ */
  8283. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8284. /* Catch the no cq entry condition */
  8285. if (unlikely(ecount == 0)) {
  8286. if (phba->intr_type == MSIX)
  8287. /* MSI-X treated interrupt served as no EQ share INT */
  8288. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8289. "0357 MSI-X interrupt with no EQE\n");
  8290. else
  8291. /* Non MSI-X treated on interrupt as EQ share INT */
  8292. return IRQ_NONE;
  8293. }
  8294. return IRQ_HANDLED;
  8295. } /* lpfc_sli4_sp_intr_handler */
  8296. /**
  8297. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8298. * @irq: Interrupt number.
  8299. * @dev_id: The device context pointer.
  8300. *
  8301. * This function is directly called from the PCI layer as an interrupt
  8302. * service routine when device with SLI-4 interface spec is enabled with
  8303. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8304. * ring event in the HBA. However, when the device is enabled with either
  8305. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8306. * device-level interrupt handler. When the PCI slot is in error recovery
  8307. * or the HBA is undergoing initialization, the interrupt handler will not
  8308. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8309. * the intrrupt context. This function is called without any lock held.
  8310. * It gets the hbalock to access and update SLI data structures. Note that,
  8311. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8312. * equal to that of FCP CQ index.
  8313. *
  8314. * This function returns IRQ_HANDLED when interrupt is handled else it
  8315. * returns IRQ_NONE.
  8316. **/
  8317. irqreturn_t
  8318. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8319. {
  8320. struct lpfc_hba *phba;
  8321. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8322. struct lpfc_queue *fpeq;
  8323. struct lpfc_eqe *eqe;
  8324. unsigned long iflag;
  8325. int ecount = 0;
  8326. uint32_t fcp_eqidx;
  8327. /* Get the driver's phba structure from the dev_id */
  8328. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8329. phba = fcp_eq_hdl->phba;
  8330. fcp_eqidx = fcp_eq_hdl->idx;
  8331. if (unlikely(!phba))
  8332. return IRQ_NONE;
  8333. /* Get to the EQ struct associated with this vector */
  8334. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8335. /* Check device state for handling interrupt */
  8336. if (unlikely(lpfc_intr_state_check(phba))) {
  8337. /* Check again for link_state with lock held */
  8338. spin_lock_irqsave(&phba->hbalock, iflag);
  8339. if (phba->link_state < LPFC_LINK_DOWN)
  8340. /* Flush, clear interrupt, and rearm the EQ */
  8341. lpfc_sli4_eq_flush(phba, fpeq);
  8342. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8343. return IRQ_NONE;
  8344. }
  8345. /*
  8346. * Process all the event on FCP fast-path EQ
  8347. */
  8348. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8349. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8350. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8351. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8352. }
  8353. /* Always clear and re-arm the fast-path EQ */
  8354. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8355. if (unlikely(ecount == 0)) {
  8356. if (phba->intr_type == MSIX)
  8357. /* MSI-X treated interrupt served as no EQ share INT */
  8358. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8359. "0358 MSI-X interrupt with no EQE\n");
  8360. else
  8361. /* Non MSI-X treated on interrupt as EQ share INT */
  8362. return IRQ_NONE;
  8363. }
  8364. return IRQ_HANDLED;
  8365. } /* lpfc_sli4_fp_intr_handler */
  8366. /**
  8367. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8368. * @irq: Interrupt number.
  8369. * @dev_id: The device context pointer.
  8370. *
  8371. * This function is the device-level interrupt handler to device with SLI-4
  8372. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8373. * interrupt mode is enabled and there is an event in the HBA which requires
  8374. * driver attention. This function invokes the slow-path interrupt attention
  8375. * handling function and fast-path interrupt attention handling function in
  8376. * turn to process the relevant HBA attention events. This function is called
  8377. * without any lock held. It gets the hbalock to access and update SLI data
  8378. * structures.
  8379. *
  8380. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8381. * returns IRQ_NONE.
  8382. **/
  8383. irqreturn_t
  8384. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8385. {
  8386. struct lpfc_hba *phba;
  8387. irqreturn_t sp_irq_rc, fp_irq_rc;
  8388. bool fp_handled = false;
  8389. uint32_t fcp_eqidx;
  8390. /* Get the driver's phba structure from the dev_id */
  8391. phba = (struct lpfc_hba *)dev_id;
  8392. if (unlikely(!phba))
  8393. return IRQ_NONE;
  8394. /*
  8395. * Invokes slow-path host attention interrupt handling as appropriate.
  8396. */
  8397. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8398. /*
  8399. * Invoke fast-path host attention interrupt handling as appropriate.
  8400. */
  8401. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8402. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8403. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8404. if (fp_irq_rc == IRQ_HANDLED)
  8405. fp_handled |= true;
  8406. }
  8407. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8408. } /* lpfc_sli4_intr_handler */
  8409. /**
  8410. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8411. * @queue: The queue structure to free.
  8412. *
  8413. * This function frees a queue structure and the DMAable memeory used for
  8414. * the host resident queue. This function must be called after destroying the
  8415. * queue on the HBA.
  8416. **/
  8417. void
  8418. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8419. {
  8420. struct lpfc_dmabuf *dmabuf;
  8421. if (!queue)
  8422. return;
  8423. while (!list_empty(&queue->page_list)) {
  8424. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8425. list);
  8426. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8427. dmabuf->virt, dmabuf->phys);
  8428. kfree(dmabuf);
  8429. }
  8430. kfree(queue);
  8431. return;
  8432. }
  8433. /**
  8434. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8435. * @phba: The HBA that this queue is being created on.
  8436. * @entry_size: The size of each queue entry for this queue.
  8437. * @entry count: The number of entries that this queue will handle.
  8438. *
  8439. * This function allocates a queue structure and the DMAable memory used for
  8440. * the host resident queue. This function must be called before creating the
  8441. * queue on the HBA.
  8442. **/
  8443. struct lpfc_queue *
  8444. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8445. uint32_t entry_count)
  8446. {
  8447. struct lpfc_queue *queue;
  8448. struct lpfc_dmabuf *dmabuf;
  8449. int x, total_qe_count;
  8450. void *dma_pointer;
  8451. queue = kzalloc(sizeof(struct lpfc_queue) +
  8452. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8453. if (!queue)
  8454. return NULL;
  8455. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8456. INIT_LIST_HEAD(&queue->list);
  8457. INIT_LIST_HEAD(&queue->page_list);
  8458. INIT_LIST_HEAD(&queue->child_list);
  8459. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8460. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8461. if (!dmabuf)
  8462. goto out_fail;
  8463. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8464. PAGE_SIZE, &dmabuf->phys,
  8465. GFP_KERNEL);
  8466. if (!dmabuf->virt) {
  8467. kfree(dmabuf);
  8468. goto out_fail;
  8469. }
  8470. dmabuf->buffer_tag = x;
  8471. list_add_tail(&dmabuf->list, &queue->page_list);
  8472. /* initialize queue's entry array */
  8473. dma_pointer = dmabuf->virt;
  8474. for (; total_qe_count < entry_count &&
  8475. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8476. total_qe_count++, dma_pointer += entry_size) {
  8477. queue->qe[total_qe_count].address = dma_pointer;
  8478. }
  8479. }
  8480. queue->entry_size = entry_size;
  8481. queue->entry_count = entry_count;
  8482. queue->phba = phba;
  8483. return queue;
  8484. out_fail:
  8485. lpfc_sli4_queue_free(queue);
  8486. return NULL;
  8487. }
  8488. /**
  8489. * lpfc_eq_create - Create an Event Queue on the HBA
  8490. * @phba: HBA structure that indicates port to create a queue on.
  8491. * @eq: The queue structure to use to create the event queue.
  8492. * @imax: The maximum interrupt per second limit.
  8493. *
  8494. * This function creates an event queue, as detailed in @eq, on a port,
  8495. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8496. *
  8497. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8498. * is used to get the entry count and entry size that are necessary to
  8499. * determine the number of pages to allocate and use for this queue. This
  8500. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8501. * event queue. This function is asynchronous and will wait for the mailbox
  8502. * command to finish before continuing.
  8503. *
  8504. * On success this function will return a zero. If unable to allocate enough
  8505. * memory this function will return ENOMEM. If the queue create mailbox command
  8506. * fails this function will return ENXIO.
  8507. **/
  8508. uint32_t
  8509. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8510. {
  8511. struct lpfc_mbx_eq_create *eq_create;
  8512. LPFC_MBOXQ_t *mbox;
  8513. int rc, length, status = 0;
  8514. struct lpfc_dmabuf *dmabuf;
  8515. uint32_t shdr_status, shdr_add_status;
  8516. union lpfc_sli4_cfg_shdr *shdr;
  8517. uint16_t dmult;
  8518. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8519. if (!mbox)
  8520. return -ENOMEM;
  8521. length = (sizeof(struct lpfc_mbx_eq_create) -
  8522. sizeof(struct lpfc_sli4_cfg_mhdr));
  8523. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8524. LPFC_MBOX_OPCODE_EQ_CREATE,
  8525. length, LPFC_SLI4_MBX_EMBED);
  8526. eq_create = &mbox->u.mqe.un.eq_create;
  8527. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8528. eq->page_count);
  8529. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8530. LPFC_EQE_SIZE);
  8531. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8532. /* Calculate delay multiper from maximum interrupt per second */
  8533. dmult = LPFC_DMULT_CONST/imax - 1;
  8534. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8535. dmult);
  8536. switch (eq->entry_count) {
  8537. default:
  8538. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8539. "0360 Unsupported EQ count. (%d)\n",
  8540. eq->entry_count);
  8541. if (eq->entry_count < 256)
  8542. return -EINVAL;
  8543. /* otherwise default to smallest count (drop through) */
  8544. case 256:
  8545. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8546. LPFC_EQ_CNT_256);
  8547. break;
  8548. case 512:
  8549. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8550. LPFC_EQ_CNT_512);
  8551. break;
  8552. case 1024:
  8553. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8554. LPFC_EQ_CNT_1024);
  8555. break;
  8556. case 2048:
  8557. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8558. LPFC_EQ_CNT_2048);
  8559. break;
  8560. case 4096:
  8561. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8562. LPFC_EQ_CNT_4096);
  8563. break;
  8564. }
  8565. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8566. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8567. putPaddrLow(dmabuf->phys);
  8568. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8569. putPaddrHigh(dmabuf->phys);
  8570. }
  8571. mbox->vport = phba->pport;
  8572. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8573. mbox->context1 = NULL;
  8574. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8575. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8576. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8577. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8578. if (shdr_status || shdr_add_status || rc) {
  8579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8580. "2500 EQ_CREATE mailbox failed with "
  8581. "status x%x add_status x%x, mbx status x%x\n",
  8582. shdr_status, shdr_add_status, rc);
  8583. status = -ENXIO;
  8584. }
  8585. eq->type = LPFC_EQ;
  8586. eq->subtype = LPFC_NONE;
  8587. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8588. if (eq->queue_id == 0xFFFF)
  8589. status = -ENXIO;
  8590. eq->host_index = 0;
  8591. eq->hba_index = 0;
  8592. if (rc != MBX_TIMEOUT)
  8593. mempool_free(mbox, phba->mbox_mem_pool);
  8594. return status;
  8595. }
  8596. /**
  8597. * lpfc_cq_create - Create a Completion Queue on the HBA
  8598. * @phba: HBA structure that indicates port to create a queue on.
  8599. * @cq: The queue structure to use to create the completion queue.
  8600. * @eq: The event queue to bind this completion queue to.
  8601. *
  8602. * This function creates a completion queue, as detailed in @wq, on a port,
  8603. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8604. *
  8605. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8606. * is used to get the entry count and entry size that are necessary to
  8607. * determine the number of pages to allocate and use for this queue. The @eq
  8608. * is used to indicate which event queue to bind this completion queue to. This
  8609. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8610. * completion queue. This function is asynchronous and will wait for the mailbox
  8611. * command to finish before continuing.
  8612. *
  8613. * On success this function will return a zero. If unable to allocate enough
  8614. * memory this function will return ENOMEM. If the queue create mailbox command
  8615. * fails this function will return ENXIO.
  8616. **/
  8617. uint32_t
  8618. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8619. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8620. {
  8621. struct lpfc_mbx_cq_create *cq_create;
  8622. struct lpfc_dmabuf *dmabuf;
  8623. LPFC_MBOXQ_t *mbox;
  8624. int rc, length, status = 0;
  8625. uint32_t shdr_status, shdr_add_status;
  8626. union lpfc_sli4_cfg_shdr *shdr;
  8627. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8628. if (!mbox)
  8629. return -ENOMEM;
  8630. length = (sizeof(struct lpfc_mbx_cq_create) -
  8631. sizeof(struct lpfc_sli4_cfg_mhdr));
  8632. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8633. LPFC_MBOX_OPCODE_CQ_CREATE,
  8634. length, LPFC_SLI4_MBX_EMBED);
  8635. cq_create = &mbox->u.mqe.un.cq_create;
  8636. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8637. cq->page_count);
  8638. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8639. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8640. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8641. switch (cq->entry_count) {
  8642. default:
  8643. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8644. "0361 Unsupported CQ count. (%d)\n",
  8645. cq->entry_count);
  8646. if (cq->entry_count < 256)
  8647. return -EINVAL;
  8648. /* otherwise default to smallest count (drop through) */
  8649. case 256:
  8650. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8651. LPFC_CQ_CNT_256);
  8652. break;
  8653. case 512:
  8654. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8655. LPFC_CQ_CNT_512);
  8656. break;
  8657. case 1024:
  8658. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8659. LPFC_CQ_CNT_1024);
  8660. break;
  8661. }
  8662. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8663. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8664. putPaddrLow(dmabuf->phys);
  8665. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8666. putPaddrHigh(dmabuf->phys);
  8667. }
  8668. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8669. /* The IOCTL status is embedded in the mailbox subheader. */
  8670. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8671. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8672. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8673. if (shdr_status || shdr_add_status || rc) {
  8674. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8675. "2501 CQ_CREATE mailbox failed with "
  8676. "status x%x add_status x%x, mbx status x%x\n",
  8677. shdr_status, shdr_add_status, rc);
  8678. status = -ENXIO;
  8679. goto out;
  8680. }
  8681. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8682. if (cq->queue_id == 0xFFFF) {
  8683. status = -ENXIO;
  8684. goto out;
  8685. }
  8686. /* link the cq onto the parent eq child list */
  8687. list_add_tail(&cq->list, &eq->child_list);
  8688. /* Set up completion queue's type and subtype */
  8689. cq->type = type;
  8690. cq->subtype = subtype;
  8691. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8692. cq->host_index = 0;
  8693. cq->hba_index = 0;
  8694. out:
  8695. if (rc != MBX_TIMEOUT)
  8696. mempool_free(mbox, phba->mbox_mem_pool);
  8697. return status;
  8698. }
  8699. /**
  8700. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8701. * @phba: HBA structure that indicates port to create a queue on.
  8702. * @mq: The queue structure to use to create the mailbox queue.
  8703. *
  8704. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8705. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8706. *
  8707. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8708. * is used to get the entry count and entry size that are necessary to
  8709. * determine the number of pages to allocate and use for this queue. This
  8710. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8711. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8712. * command to finish before continuing.
  8713. *
  8714. * On success this function will return a zero. If unable to allocate enough
  8715. * memory this function will return ENOMEM. If the queue create mailbox command
  8716. * fails this function will return ENXIO.
  8717. **/
  8718. uint32_t
  8719. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8720. struct lpfc_queue *cq, uint32_t subtype)
  8721. {
  8722. struct lpfc_mbx_mq_create *mq_create;
  8723. struct lpfc_dmabuf *dmabuf;
  8724. LPFC_MBOXQ_t *mbox;
  8725. int rc, length, status = 0;
  8726. uint32_t shdr_status, shdr_add_status;
  8727. union lpfc_sli4_cfg_shdr *shdr;
  8728. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8729. if (!mbox)
  8730. return -ENOMEM;
  8731. length = (sizeof(struct lpfc_mbx_mq_create) -
  8732. sizeof(struct lpfc_sli4_cfg_mhdr));
  8733. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8734. LPFC_MBOX_OPCODE_MQ_CREATE,
  8735. length, LPFC_SLI4_MBX_EMBED);
  8736. mq_create = &mbox->u.mqe.un.mq_create;
  8737. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8738. mq->page_count);
  8739. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8740. cq->queue_id);
  8741. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8742. switch (mq->entry_count) {
  8743. default:
  8744. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8745. "0362 Unsupported MQ count. (%d)\n",
  8746. mq->entry_count);
  8747. if (mq->entry_count < 16)
  8748. return -EINVAL;
  8749. /* otherwise default to smallest count (drop through) */
  8750. case 16:
  8751. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8752. LPFC_MQ_CNT_16);
  8753. break;
  8754. case 32:
  8755. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8756. LPFC_MQ_CNT_32);
  8757. break;
  8758. case 64:
  8759. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8760. LPFC_MQ_CNT_64);
  8761. break;
  8762. case 128:
  8763. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8764. LPFC_MQ_CNT_128);
  8765. break;
  8766. }
  8767. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8768. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8769. putPaddrLow(dmabuf->phys);
  8770. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8771. putPaddrHigh(dmabuf->phys);
  8772. }
  8773. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8774. /* The IOCTL status is embedded in the mailbox subheader. */
  8775. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8776. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8777. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8778. if (shdr_status || shdr_add_status || rc) {
  8779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8780. "2502 MQ_CREATE mailbox failed with "
  8781. "status x%x add_status x%x, mbx status x%x\n",
  8782. shdr_status, shdr_add_status, rc);
  8783. status = -ENXIO;
  8784. goto out;
  8785. }
  8786. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8787. if (mq->queue_id == 0xFFFF) {
  8788. status = -ENXIO;
  8789. goto out;
  8790. }
  8791. mq->type = LPFC_MQ;
  8792. mq->subtype = subtype;
  8793. mq->host_index = 0;
  8794. mq->hba_index = 0;
  8795. /* link the mq onto the parent cq child list */
  8796. list_add_tail(&mq->list, &cq->child_list);
  8797. out:
  8798. if (rc != MBX_TIMEOUT)
  8799. mempool_free(mbox, phba->mbox_mem_pool);
  8800. return status;
  8801. }
  8802. /**
  8803. * lpfc_wq_create - Create a Work Queue on the HBA
  8804. * @phba: HBA structure that indicates port to create a queue on.
  8805. * @wq: The queue structure to use to create the work queue.
  8806. * @cq: The completion queue to bind this work queue to.
  8807. * @subtype: The subtype of the work queue indicating its functionality.
  8808. *
  8809. * This function creates a work queue, as detailed in @wq, on a port, described
  8810. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8811. *
  8812. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8813. * is used to get the entry count and entry size that are necessary to
  8814. * determine the number of pages to allocate and use for this queue. The @cq
  8815. * is used to indicate which completion queue to bind this work queue to. This
  8816. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8817. * work queue. This function is asynchronous and will wait for the mailbox
  8818. * command to finish before continuing.
  8819. *
  8820. * On success this function will return a zero. If unable to allocate enough
  8821. * memory this function will return ENOMEM. If the queue create mailbox command
  8822. * fails this function will return ENXIO.
  8823. **/
  8824. uint32_t
  8825. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8826. struct lpfc_queue *cq, uint32_t subtype)
  8827. {
  8828. struct lpfc_mbx_wq_create *wq_create;
  8829. struct lpfc_dmabuf *dmabuf;
  8830. LPFC_MBOXQ_t *mbox;
  8831. int rc, length, status = 0;
  8832. uint32_t shdr_status, shdr_add_status;
  8833. union lpfc_sli4_cfg_shdr *shdr;
  8834. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8835. if (!mbox)
  8836. return -ENOMEM;
  8837. length = (sizeof(struct lpfc_mbx_wq_create) -
  8838. sizeof(struct lpfc_sli4_cfg_mhdr));
  8839. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8840. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8841. length, LPFC_SLI4_MBX_EMBED);
  8842. wq_create = &mbox->u.mqe.un.wq_create;
  8843. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8844. wq->page_count);
  8845. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8846. cq->queue_id);
  8847. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8848. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8849. putPaddrLow(dmabuf->phys);
  8850. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8851. putPaddrHigh(dmabuf->phys);
  8852. }
  8853. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8854. /* The IOCTL status is embedded in the mailbox subheader. */
  8855. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8856. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8857. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8858. if (shdr_status || shdr_add_status || rc) {
  8859. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8860. "2503 WQ_CREATE mailbox failed with "
  8861. "status x%x add_status x%x, mbx status x%x\n",
  8862. shdr_status, shdr_add_status, rc);
  8863. status = -ENXIO;
  8864. goto out;
  8865. }
  8866. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8867. if (wq->queue_id == 0xFFFF) {
  8868. status = -ENXIO;
  8869. goto out;
  8870. }
  8871. wq->type = LPFC_WQ;
  8872. wq->subtype = subtype;
  8873. wq->host_index = 0;
  8874. wq->hba_index = 0;
  8875. /* link the wq onto the parent cq child list */
  8876. list_add_tail(&wq->list, &cq->child_list);
  8877. out:
  8878. if (rc == MBX_TIMEOUT)
  8879. mempool_free(mbox, phba->mbox_mem_pool);
  8880. return status;
  8881. }
  8882. /**
  8883. * lpfc_rq_create - Create a Receive Queue on the HBA
  8884. * @phba: HBA structure that indicates port to create a queue on.
  8885. * @hrq: The queue structure to use to create the header receive queue.
  8886. * @drq: The queue structure to use to create the data receive queue.
  8887. * @cq: The completion queue to bind this work queue to.
  8888. *
  8889. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8890. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8891. * to the HBA.
  8892. *
  8893. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8894. * struct is used to get the entry count that is necessary to determine the
  8895. * number of pages to use for this queue. The @cq is used to indicate which
  8896. * completion queue to bind received buffers that are posted to these queues to.
  8897. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8898. * receive queue pair. This function is asynchronous and will wait for the
  8899. * mailbox command to finish before continuing.
  8900. *
  8901. * On success this function will return a zero. If unable to allocate enough
  8902. * memory this function will return ENOMEM. If the queue create mailbox command
  8903. * fails this function will return ENXIO.
  8904. **/
  8905. uint32_t
  8906. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8907. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8908. {
  8909. struct lpfc_mbx_rq_create *rq_create;
  8910. struct lpfc_dmabuf *dmabuf;
  8911. LPFC_MBOXQ_t *mbox;
  8912. int rc, length, status = 0;
  8913. uint32_t shdr_status, shdr_add_status;
  8914. union lpfc_sli4_cfg_shdr *shdr;
  8915. if (hrq->entry_count != drq->entry_count)
  8916. return -EINVAL;
  8917. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8918. if (!mbox)
  8919. return -ENOMEM;
  8920. length = (sizeof(struct lpfc_mbx_rq_create) -
  8921. sizeof(struct lpfc_sli4_cfg_mhdr));
  8922. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8923. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8924. length, LPFC_SLI4_MBX_EMBED);
  8925. rq_create = &mbox->u.mqe.un.rq_create;
  8926. switch (hrq->entry_count) {
  8927. default:
  8928. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8929. "2535 Unsupported RQ count. (%d)\n",
  8930. hrq->entry_count);
  8931. if (hrq->entry_count < 512)
  8932. return -EINVAL;
  8933. /* otherwise default to smallest count (drop through) */
  8934. case 512:
  8935. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8936. LPFC_RQ_RING_SIZE_512);
  8937. break;
  8938. case 1024:
  8939. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8940. LPFC_RQ_RING_SIZE_1024);
  8941. break;
  8942. case 2048:
  8943. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8944. LPFC_RQ_RING_SIZE_2048);
  8945. break;
  8946. case 4096:
  8947. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8948. LPFC_RQ_RING_SIZE_4096);
  8949. break;
  8950. }
  8951. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8952. cq->queue_id);
  8953. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8954. hrq->page_count);
  8955. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8956. LPFC_HDR_BUF_SIZE);
  8957. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  8958. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8959. putPaddrLow(dmabuf->phys);
  8960. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8961. putPaddrHigh(dmabuf->phys);
  8962. }
  8963. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8964. /* The IOCTL status is embedded in the mailbox subheader. */
  8965. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  8966. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8967. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8968. if (shdr_status || shdr_add_status || rc) {
  8969. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8970. "2504 RQ_CREATE mailbox failed with "
  8971. "status x%x add_status x%x, mbx status x%x\n",
  8972. shdr_status, shdr_add_status, rc);
  8973. status = -ENXIO;
  8974. goto out;
  8975. }
  8976. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  8977. if (hrq->queue_id == 0xFFFF) {
  8978. status = -ENXIO;
  8979. goto out;
  8980. }
  8981. hrq->type = LPFC_HRQ;
  8982. hrq->subtype = subtype;
  8983. hrq->host_index = 0;
  8984. hrq->hba_index = 0;
  8985. /* now create the data queue */
  8986. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8987. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8988. length, LPFC_SLI4_MBX_EMBED);
  8989. switch (drq->entry_count) {
  8990. default:
  8991. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8992. "2536 Unsupported RQ count. (%d)\n",
  8993. drq->entry_count);
  8994. if (drq->entry_count < 512)
  8995. return -EINVAL;
  8996. /* otherwise default to smallest count (drop through) */
  8997. case 512:
  8998. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8999. LPFC_RQ_RING_SIZE_512);
  9000. break;
  9001. case 1024:
  9002. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9003. LPFC_RQ_RING_SIZE_1024);
  9004. break;
  9005. case 2048:
  9006. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9007. LPFC_RQ_RING_SIZE_2048);
  9008. break;
  9009. case 4096:
  9010. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9011. LPFC_RQ_RING_SIZE_4096);
  9012. break;
  9013. }
  9014. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9015. cq->queue_id);
  9016. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9017. drq->page_count);
  9018. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9019. LPFC_DATA_BUF_SIZE);
  9020. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9021. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9022. putPaddrLow(dmabuf->phys);
  9023. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9024. putPaddrHigh(dmabuf->phys);
  9025. }
  9026. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9027. /* The IOCTL status is embedded in the mailbox subheader. */
  9028. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9029. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9030. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9031. if (shdr_status || shdr_add_status || rc) {
  9032. status = -ENXIO;
  9033. goto out;
  9034. }
  9035. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9036. if (drq->queue_id == 0xFFFF) {
  9037. status = -ENXIO;
  9038. goto out;
  9039. }
  9040. drq->type = LPFC_DRQ;
  9041. drq->subtype = subtype;
  9042. drq->host_index = 0;
  9043. drq->hba_index = 0;
  9044. /* link the header and data RQs onto the parent cq child list */
  9045. list_add_tail(&hrq->list, &cq->child_list);
  9046. list_add_tail(&drq->list, &cq->child_list);
  9047. out:
  9048. if (rc != MBX_TIMEOUT)
  9049. mempool_free(mbox, phba->mbox_mem_pool);
  9050. return status;
  9051. }
  9052. /**
  9053. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9054. * @eq: The queue structure associated with the queue to destroy.
  9055. *
  9056. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9057. * command, specific to the type of queue, to the HBA.
  9058. *
  9059. * The @eq struct is used to get the queue ID of the queue to destroy.
  9060. *
  9061. * On success this function will return a zero. If the queue destroy mailbox
  9062. * command fails this function will return ENXIO.
  9063. **/
  9064. uint32_t
  9065. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9066. {
  9067. LPFC_MBOXQ_t *mbox;
  9068. int rc, length, status = 0;
  9069. uint32_t shdr_status, shdr_add_status;
  9070. union lpfc_sli4_cfg_shdr *shdr;
  9071. if (!eq)
  9072. return -ENODEV;
  9073. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9074. if (!mbox)
  9075. return -ENOMEM;
  9076. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9077. sizeof(struct lpfc_sli4_cfg_mhdr));
  9078. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9079. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9080. length, LPFC_SLI4_MBX_EMBED);
  9081. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9082. eq->queue_id);
  9083. mbox->vport = eq->phba->pport;
  9084. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9085. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9086. /* The IOCTL status is embedded in the mailbox subheader. */
  9087. shdr = (union lpfc_sli4_cfg_shdr *)
  9088. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9089. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9090. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9091. if (shdr_status || shdr_add_status || rc) {
  9092. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9093. "2505 EQ_DESTROY mailbox failed with "
  9094. "status x%x add_status x%x, mbx status x%x\n",
  9095. shdr_status, shdr_add_status, rc);
  9096. status = -ENXIO;
  9097. }
  9098. /* Remove eq from any list */
  9099. list_del_init(&eq->list);
  9100. if (rc != MBX_TIMEOUT)
  9101. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9102. return status;
  9103. }
  9104. /**
  9105. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9106. * @cq: The queue structure associated with the queue to destroy.
  9107. *
  9108. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9109. * command, specific to the type of queue, to the HBA.
  9110. *
  9111. * The @cq struct is used to get the queue ID of the queue to destroy.
  9112. *
  9113. * On success this function will return a zero. If the queue destroy mailbox
  9114. * command fails this function will return ENXIO.
  9115. **/
  9116. uint32_t
  9117. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9118. {
  9119. LPFC_MBOXQ_t *mbox;
  9120. int rc, length, status = 0;
  9121. uint32_t shdr_status, shdr_add_status;
  9122. union lpfc_sli4_cfg_shdr *shdr;
  9123. if (!cq)
  9124. return -ENODEV;
  9125. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9126. if (!mbox)
  9127. return -ENOMEM;
  9128. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9129. sizeof(struct lpfc_sli4_cfg_mhdr));
  9130. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9131. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9132. length, LPFC_SLI4_MBX_EMBED);
  9133. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9134. cq->queue_id);
  9135. mbox->vport = cq->phba->pport;
  9136. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9137. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9138. /* The IOCTL status is embedded in the mailbox subheader. */
  9139. shdr = (union lpfc_sli4_cfg_shdr *)
  9140. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9141. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9142. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9143. if (shdr_status || shdr_add_status || rc) {
  9144. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9145. "2506 CQ_DESTROY mailbox failed with "
  9146. "status x%x add_status x%x, mbx status x%x\n",
  9147. shdr_status, shdr_add_status, rc);
  9148. status = -ENXIO;
  9149. }
  9150. /* Remove cq from any list */
  9151. list_del_init(&cq->list);
  9152. if (rc != MBX_TIMEOUT)
  9153. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9154. return status;
  9155. }
  9156. /**
  9157. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9158. * @qm: The queue structure associated with the queue to destroy.
  9159. *
  9160. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9161. * command, specific to the type of queue, to the HBA.
  9162. *
  9163. * The @mq struct is used to get the queue ID of the queue to destroy.
  9164. *
  9165. * On success this function will return a zero. If the queue destroy mailbox
  9166. * command fails this function will return ENXIO.
  9167. **/
  9168. uint32_t
  9169. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9170. {
  9171. LPFC_MBOXQ_t *mbox;
  9172. int rc, length, status = 0;
  9173. uint32_t shdr_status, shdr_add_status;
  9174. union lpfc_sli4_cfg_shdr *shdr;
  9175. if (!mq)
  9176. return -ENODEV;
  9177. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9178. if (!mbox)
  9179. return -ENOMEM;
  9180. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9181. sizeof(struct lpfc_sli4_cfg_mhdr));
  9182. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9183. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9184. length, LPFC_SLI4_MBX_EMBED);
  9185. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9186. mq->queue_id);
  9187. mbox->vport = mq->phba->pport;
  9188. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9189. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9190. /* The IOCTL status is embedded in the mailbox subheader. */
  9191. shdr = (union lpfc_sli4_cfg_shdr *)
  9192. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9193. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9194. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9195. if (shdr_status || shdr_add_status || rc) {
  9196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9197. "2507 MQ_DESTROY mailbox failed with "
  9198. "status x%x add_status x%x, mbx status x%x\n",
  9199. shdr_status, shdr_add_status, rc);
  9200. status = -ENXIO;
  9201. }
  9202. /* Remove mq from any list */
  9203. list_del_init(&mq->list);
  9204. if (rc != MBX_TIMEOUT)
  9205. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9206. return status;
  9207. }
  9208. /**
  9209. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9210. * @wq: The queue structure associated with the queue to destroy.
  9211. *
  9212. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9213. * command, specific to the type of queue, to the HBA.
  9214. *
  9215. * The @wq struct is used to get the queue ID of the queue to destroy.
  9216. *
  9217. * On success this function will return a zero. If the queue destroy mailbox
  9218. * command fails this function will return ENXIO.
  9219. **/
  9220. uint32_t
  9221. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9222. {
  9223. LPFC_MBOXQ_t *mbox;
  9224. int rc, length, status = 0;
  9225. uint32_t shdr_status, shdr_add_status;
  9226. union lpfc_sli4_cfg_shdr *shdr;
  9227. if (!wq)
  9228. return -ENODEV;
  9229. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9230. if (!mbox)
  9231. return -ENOMEM;
  9232. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9233. sizeof(struct lpfc_sli4_cfg_mhdr));
  9234. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9235. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9236. length, LPFC_SLI4_MBX_EMBED);
  9237. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9238. wq->queue_id);
  9239. mbox->vport = wq->phba->pport;
  9240. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9241. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9242. shdr = (union lpfc_sli4_cfg_shdr *)
  9243. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9244. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9245. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9246. if (shdr_status || shdr_add_status || rc) {
  9247. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9248. "2508 WQ_DESTROY mailbox failed with "
  9249. "status x%x add_status x%x, mbx status x%x\n",
  9250. shdr_status, shdr_add_status, rc);
  9251. status = -ENXIO;
  9252. }
  9253. /* Remove wq from any list */
  9254. list_del_init(&wq->list);
  9255. if (rc != MBX_TIMEOUT)
  9256. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9257. return status;
  9258. }
  9259. /**
  9260. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9261. * @rq: The queue structure associated with the queue to destroy.
  9262. *
  9263. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9264. * command, specific to the type of queue, to the HBA.
  9265. *
  9266. * The @rq struct is used to get the queue ID of the queue to destroy.
  9267. *
  9268. * On success this function will return a zero. If the queue destroy mailbox
  9269. * command fails this function will return ENXIO.
  9270. **/
  9271. uint32_t
  9272. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9273. struct lpfc_queue *drq)
  9274. {
  9275. LPFC_MBOXQ_t *mbox;
  9276. int rc, length, status = 0;
  9277. uint32_t shdr_status, shdr_add_status;
  9278. union lpfc_sli4_cfg_shdr *shdr;
  9279. if (!hrq || !drq)
  9280. return -ENODEV;
  9281. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9282. if (!mbox)
  9283. return -ENOMEM;
  9284. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9285. sizeof(struct mbox_header));
  9286. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9287. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9288. length, LPFC_SLI4_MBX_EMBED);
  9289. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9290. hrq->queue_id);
  9291. mbox->vport = hrq->phba->pport;
  9292. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9293. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9294. /* The IOCTL status is embedded in the mailbox subheader. */
  9295. shdr = (union lpfc_sli4_cfg_shdr *)
  9296. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9297. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9298. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9299. if (shdr_status || shdr_add_status || rc) {
  9300. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9301. "2509 RQ_DESTROY mailbox failed with "
  9302. "status x%x add_status x%x, mbx status x%x\n",
  9303. shdr_status, shdr_add_status, rc);
  9304. if (rc != MBX_TIMEOUT)
  9305. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9306. return -ENXIO;
  9307. }
  9308. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9309. drq->queue_id);
  9310. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9311. shdr = (union lpfc_sli4_cfg_shdr *)
  9312. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9313. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9314. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9315. if (shdr_status || shdr_add_status || rc) {
  9316. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9317. "2510 RQ_DESTROY mailbox failed with "
  9318. "status x%x add_status x%x, mbx status x%x\n",
  9319. shdr_status, shdr_add_status, rc);
  9320. status = -ENXIO;
  9321. }
  9322. list_del_init(&hrq->list);
  9323. list_del_init(&drq->list);
  9324. if (rc != MBX_TIMEOUT)
  9325. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9326. return status;
  9327. }
  9328. /**
  9329. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9330. * @phba: The virtual port for which this call being executed.
  9331. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9332. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9333. * @xritag: the xritag that ties this io to the SGL pages.
  9334. *
  9335. * This routine will post the sgl pages for the IO that has the xritag
  9336. * that is in the iocbq structure. The xritag is assigned during iocbq
  9337. * creation and persists for as long as the driver is loaded.
  9338. * if the caller has fewer than 256 scatter gather segments to map then
  9339. * pdma_phys_addr1 should be 0.
  9340. * If the caller needs to map more than 256 scatter gather segment then
  9341. * pdma_phys_addr1 should be a valid physical address.
  9342. * physical address for SGLs must be 64 byte aligned.
  9343. * If you are going to map 2 SGL's then the first one must have 256 entries
  9344. * the second sgl can have between 1 and 256 entries.
  9345. *
  9346. * Return codes:
  9347. * 0 - Success
  9348. * -ENXIO, -ENOMEM - Failure
  9349. **/
  9350. int
  9351. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9352. dma_addr_t pdma_phys_addr0,
  9353. dma_addr_t pdma_phys_addr1,
  9354. uint16_t xritag)
  9355. {
  9356. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9357. LPFC_MBOXQ_t *mbox;
  9358. int rc;
  9359. uint32_t shdr_status, shdr_add_status;
  9360. union lpfc_sli4_cfg_shdr *shdr;
  9361. if (xritag == NO_XRI) {
  9362. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9363. "0364 Invalid param:\n");
  9364. return -EINVAL;
  9365. }
  9366. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9367. if (!mbox)
  9368. return -ENOMEM;
  9369. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9370. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9371. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9372. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9373. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9374. &mbox->u.mqe.un.post_sgl_pages;
  9375. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9376. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9377. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9378. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9379. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9380. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9381. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9382. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9383. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9384. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9385. if (!phba->sli4_hba.intr_enable)
  9386. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9387. else
  9388. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9389. /* The IOCTL status is embedded in the mailbox subheader. */
  9390. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9391. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9392. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9393. if (rc != MBX_TIMEOUT)
  9394. mempool_free(mbox, phba->mbox_mem_pool);
  9395. if (shdr_status || shdr_add_status || rc) {
  9396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9397. "2511 POST_SGL mailbox failed with "
  9398. "status x%x add_status x%x, mbx status x%x\n",
  9399. shdr_status, shdr_add_status, rc);
  9400. rc = -ENXIO;
  9401. }
  9402. return 0;
  9403. }
  9404. /**
  9405. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9406. * @phba: The virtual port for which this call being executed.
  9407. *
  9408. * This routine will remove all of the sgl pages registered with the hba.
  9409. *
  9410. * Return codes:
  9411. * 0 - Success
  9412. * -ENXIO, -ENOMEM - Failure
  9413. **/
  9414. int
  9415. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9416. {
  9417. LPFC_MBOXQ_t *mbox;
  9418. int rc;
  9419. uint32_t shdr_status, shdr_add_status;
  9420. union lpfc_sli4_cfg_shdr *shdr;
  9421. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9422. if (!mbox)
  9423. return -ENOMEM;
  9424. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9425. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9426. LPFC_SLI4_MBX_EMBED);
  9427. if (!phba->sli4_hba.intr_enable)
  9428. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9429. else
  9430. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9431. /* The IOCTL status is embedded in the mailbox subheader. */
  9432. shdr = (union lpfc_sli4_cfg_shdr *)
  9433. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9434. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9435. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9436. if (rc != MBX_TIMEOUT)
  9437. mempool_free(mbox, phba->mbox_mem_pool);
  9438. if (shdr_status || shdr_add_status || rc) {
  9439. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9440. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9441. "status x%x add_status x%x, mbx status x%x\n",
  9442. shdr_status, shdr_add_status, rc);
  9443. rc = -ENXIO;
  9444. }
  9445. return rc;
  9446. }
  9447. /**
  9448. * lpfc_sli4_next_xritag - Get an xritag for the io
  9449. * @phba: Pointer to HBA context object.
  9450. *
  9451. * This function gets an xritag for the iocb. If there is no unused xritag
  9452. * it will return 0xffff.
  9453. * The function returns the allocated xritag if successful, else returns zero.
  9454. * Zero is not a valid xritag.
  9455. * The caller is not required to hold any lock.
  9456. **/
  9457. uint16_t
  9458. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9459. {
  9460. uint16_t xritag;
  9461. spin_lock_irq(&phba->hbalock);
  9462. xritag = phba->sli4_hba.next_xri;
  9463. if ((xritag != (uint16_t) -1) && xritag <
  9464. (phba->sli4_hba.max_cfg_param.max_xri
  9465. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9466. phba->sli4_hba.next_xri++;
  9467. phba->sli4_hba.max_cfg_param.xri_used++;
  9468. spin_unlock_irq(&phba->hbalock);
  9469. return xritag;
  9470. }
  9471. spin_unlock_irq(&phba->hbalock);
  9472. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9473. "2004 Failed to allocate XRI.last XRITAG is %d"
  9474. " Max XRI is %d, Used XRI is %d\n",
  9475. phba->sli4_hba.next_xri,
  9476. phba->sli4_hba.max_cfg_param.max_xri,
  9477. phba->sli4_hba.max_cfg_param.xri_used);
  9478. return -1;
  9479. }
  9480. /**
  9481. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9482. * @phba: pointer to lpfc hba data structure.
  9483. *
  9484. * This routine is invoked to post a block of driver's sgl pages to the
  9485. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9486. * is only called when the driver is loading and after all IO has been
  9487. * stopped.
  9488. **/
  9489. int
  9490. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9491. {
  9492. struct lpfc_sglq *sglq_entry;
  9493. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9494. struct sgl_page_pairs *sgl_pg_pairs;
  9495. void *viraddr;
  9496. LPFC_MBOXQ_t *mbox;
  9497. uint32_t reqlen, alloclen, pg_pairs;
  9498. uint32_t mbox_tmo;
  9499. uint16_t xritag_start = 0;
  9500. int els_xri_cnt, rc = 0;
  9501. uint32_t shdr_status, shdr_add_status;
  9502. union lpfc_sli4_cfg_shdr *shdr;
  9503. /* The number of sgls to be posted */
  9504. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9505. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9506. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9507. if (reqlen > PAGE_SIZE) {
  9508. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9509. "2559 Block sgl registration required DMA "
  9510. "size (%d) great than a page\n", reqlen);
  9511. return -ENOMEM;
  9512. }
  9513. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9514. if (!mbox) {
  9515. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9516. "2560 Failed to allocate mbox cmd memory\n");
  9517. return -ENOMEM;
  9518. }
  9519. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9520. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9521. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9522. LPFC_SLI4_MBX_NEMBED);
  9523. if (alloclen < reqlen) {
  9524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9525. "0285 Allocated DMA memory size (%d) is "
  9526. "less than the requested DMA memory "
  9527. "size (%d)\n", alloclen, reqlen);
  9528. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9529. return -ENOMEM;
  9530. }
  9531. /* Get the first SGE entry from the non-embedded DMA memory */
  9532. if (unlikely(!mbox->sge_array)) {
  9533. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9534. "2525 Failed to get the non-embedded SGE "
  9535. "virtual address\n");
  9536. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9537. return -ENOMEM;
  9538. }
  9539. viraddr = mbox->sge_array->addr[0];
  9540. /* Set up the SGL pages in the non-embedded DMA pages */
  9541. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9542. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9543. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9544. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9545. /* Set up the sge entry */
  9546. sgl_pg_pairs->sgl_pg0_addr_lo =
  9547. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9548. sgl_pg_pairs->sgl_pg0_addr_hi =
  9549. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9550. sgl_pg_pairs->sgl_pg1_addr_lo =
  9551. cpu_to_le32(putPaddrLow(0));
  9552. sgl_pg_pairs->sgl_pg1_addr_hi =
  9553. cpu_to_le32(putPaddrHigh(0));
  9554. /* Keep the first xritag on the list */
  9555. if (pg_pairs == 0)
  9556. xritag_start = sglq_entry->sli4_xritag;
  9557. sgl_pg_pairs++;
  9558. }
  9559. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9560. pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
  9561. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9562. /* Perform endian conversion if necessary */
  9563. sgl->word0 = cpu_to_le32(sgl->word0);
  9564. if (!phba->sli4_hba.intr_enable)
  9565. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9566. else {
  9567. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9568. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9569. }
  9570. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9571. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9572. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9573. if (rc != MBX_TIMEOUT)
  9574. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9575. if (shdr_status || shdr_add_status || rc) {
  9576. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9577. "2513 POST_SGL_BLOCK mailbox command failed "
  9578. "status x%x add_status x%x mbx status x%x\n",
  9579. shdr_status, shdr_add_status, rc);
  9580. rc = -ENXIO;
  9581. }
  9582. return rc;
  9583. }
  9584. /**
  9585. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9586. * @phba: pointer to lpfc hba data structure.
  9587. * @sblist: pointer to scsi buffer list.
  9588. * @count: number of scsi buffers on the list.
  9589. *
  9590. * This routine is invoked to post a block of @count scsi sgl pages from a
  9591. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9592. * No Lock is held.
  9593. *
  9594. **/
  9595. int
  9596. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9597. int cnt)
  9598. {
  9599. struct lpfc_scsi_buf *psb;
  9600. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9601. struct sgl_page_pairs *sgl_pg_pairs;
  9602. void *viraddr;
  9603. LPFC_MBOXQ_t *mbox;
  9604. uint32_t reqlen, alloclen, pg_pairs;
  9605. uint32_t mbox_tmo;
  9606. uint16_t xritag_start = 0;
  9607. int rc = 0;
  9608. uint32_t shdr_status, shdr_add_status;
  9609. dma_addr_t pdma_phys_bpl1;
  9610. union lpfc_sli4_cfg_shdr *shdr;
  9611. /* Calculate the requested length of the dma memory */
  9612. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9613. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9614. if (reqlen > PAGE_SIZE) {
  9615. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9616. "0217 Block sgl registration required DMA "
  9617. "size (%d) great than a page\n", reqlen);
  9618. return -ENOMEM;
  9619. }
  9620. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9621. if (!mbox) {
  9622. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9623. "0283 Failed to allocate mbox cmd memory\n");
  9624. return -ENOMEM;
  9625. }
  9626. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9627. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9628. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9629. LPFC_SLI4_MBX_NEMBED);
  9630. if (alloclen < reqlen) {
  9631. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9632. "2561 Allocated DMA memory size (%d) is "
  9633. "less than the requested DMA memory "
  9634. "size (%d)\n", alloclen, reqlen);
  9635. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9636. return -ENOMEM;
  9637. }
  9638. /* Get the first SGE entry from the non-embedded DMA memory */
  9639. if (unlikely(!mbox->sge_array)) {
  9640. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9641. "2565 Failed to get the non-embedded SGE "
  9642. "virtual address\n");
  9643. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9644. return -ENOMEM;
  9645. }
  9646. viraddr = mbox->sge_array->addr[0];
  9647. /* Set up the SGL pages in the non-embedded DMA pages */
  9648. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9649. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9650. pg_pairs = 0;
  9651. list_for_each_entry(psb, sblist, list) {
  9652. /* Set up the sge entry */
  9653. sgl_pg_pairs->sgl_pg0_addr_lo =
  9654. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9655. sgl_pg_pairs->sgl_pg0_addr_hi =
  9656. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9657. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9658. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9659. else
  9660. pdma_phys_bpl1 = 0;
  9661. sgl_pg_pairs->sgl_pg1_addr_lo =
  9662. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9663. sgl_pg_pairs->sgl_pg1_addr_hi =
  9664. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9665. /* Keep the first xritag on the list */
  9666. if (pg_pairs == 0)
  9667. xritag_start = psb->cur_iocbq.sli4_xritag;
  9668. sgl_pg_pairs++;
  9669. pg_pairs++;
  9670. }
  9671. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9672. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9673. /* Perform endian conversion if necessary */
  9674. sgl->word0 = cpu_to_le32(sgl->word0);
  9675. if (!phba->sli4_hba.intr_enable)
  9676. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9677. else {
  9678. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9679. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9680. }
  9681. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9682. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9683. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9684. if (rc != MBX_TIMEOUT)
  9685. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9686. if (shdr_status || shdr_add_status || rc) {
  9687. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9688. "2564 POST_SGL_BLOCK mailbox command failed "
  9689. "status x%x add_status x%x mbx status x%x\n",
  9690. shdr_status, shdr_add_status, rc);
  9691. rc = -ENXIO;
  9692. }
  9693. return rc;
  9694. }
  9695. /**
  9696. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9697. * @phba: pointer to lpfc_hba struct that the frame was received on
  9698. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9699. *
  9700. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9701. * valid type of frame that the LPFC driver will handle. This function will
  9702. * return a zero if the frame is a valid frame or a non zero value when the
  9703. * frame does not pass the check.
  9704. **/
  9705. static int
  9706. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9707. {
  9708. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9709. char *type_names[] = FC_TYPE_NAMES_INIT;
  9710. struct fc_vft_header *fc_vft_hdr;
  9711. switch (fc_hdr->fh_r_ctl) {
  9712. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9713. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9714. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9715. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9716. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9717. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9718. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9719. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9720. case FC_RCTL_ELS_REQ: /* extended link services request */
  9721. case FC_RCTL_ELS_REP: /* extended link services reply */
  9722. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9723. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9724. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9725. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9726. case FC_RCTL_BA_RMC: /* remove connection */
  9727. case FC_RCTL_BA_ACC: /* basic accept */
  9728. case FC_RCTL_BA_RJT: /* basic reject */
  9729. case FC_RCTL_BA_PRMT:
  9730. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9731. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9732. case FC_RCTL_P_RJT: /* port reject */
  9733. case FC_RCTL_F_RJT: /* fabric reject */
  9734. case FC_RCTL_P_BSY: /* port busy */
  9735. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9736. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9737. case FC_RCTL_LCR: /* link credit reset */
  9738. case FC_RCTL_END: /* end */
  9739. break;
  9740. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9741. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9742. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9743. return lpfc_fc_frame_check(phba, fc_hdr);
  9744. default:
  9745. goto drop;
  9746. }
  9747. switch (fc_hdr->fh_type) {
  9748. case FC_TYPE_BLS:
  9749. case FC_TYPE_ELS:
  9750. case FC_TYPE_FCP:
  9751. case FC_TYPE_CT:
  9752. break;
  9753. case FC_TYPE_IP:
  9754. case FC_TYPE_ILS:
  9755. default:
  9756. goto drop;
  9757. }
  9758. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9759. "2538 Received frame rctl:%s type:%s\n",
  9760. rctl_names[fc_hdr->fh_r_ctl],
  9761. type_names[fc_hdr->fh_type]);
  9762. return 0;
  9763. drop:
  9764. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9765. "2539 Dropped frame rctl:%s type:%s\n",
  9766. rctl_names[fc_hdr->fh_r_ctl],
  9767. type_names[fc_hdr->fh_type]);
  9768. return 1;
  9769. }
  9770. /**
  9771. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9772. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9773. *
  9774. * This function processes the FC header to retrieve the VFI from the VF
  9775. * header, if one exists. This function will return the VFI if one exists
  9776. * or 0 if no VSAN Header exists.
  9777. **/
  9778. static uint32_t
  9779. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9780. {
  9781. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9782. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9783. return 0;
  9784. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9785. }
  9786. /**
  9787. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9788. * @phba: Pointer to the HBA structure to search for the vport on
  9789. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9790. * @fcfi: The FC Fabric ID that the frame came from
  9791. *
  9792. * This function searches the @phba for a vport that matches the content of the
  9793. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9794. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9795. * returns the matching vport pointer or NULL if unable to match frame to a
  9796. * vport.
  9797. **/
  9798. static struct lpfc_vport *
  9799. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9800. uint16_t fcfi)
  9801. {
  9802. struct lpfc_vport **vports;
  9803. struct lpfc_vport *vport = NULL;
  9804. int i;
  9805. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9806. fc_hdr->fh_d_id[1] << 8 |
  9807. fc_hdr->fh_d_id[2]);
  9808. vports = lpfc_create_vport_work_array(phba);
  9809. if (vports != NULL)
  9810. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9811. if (phba->fcf.fcfi == fcfi &&
  9812. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9813. vports[i]->fc_myDID == did) {
  9814. vport = vports[i];
  9815. break;
  9816. }
  9817. }
  9818. lpfc_destroy_vport_work_array(phba, vports);
  9819. return vport;
  9820. }
  9821. /**
  9822. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9823. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9824. *
  9825. * This function searches through the existing incomplete sequences that have
  9826. * been sent to this @vport. If the frame matches one of the incomplete
  9827. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9828. * make up that sequence. If no sequence is found that matches this frame then
  9829. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9830. * This function returns a pointer to the first dmabuf in the sequence list that
  9831. * the frame was linked to.
  9832. **/
  9833. static struct hbq_dmabuf *
  9834. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9835. {
  9836. struct fc_frame_header *new_hdr;
  9837. struct fc_frame_header *temp_hdr;
  9838. struct lpfc_dmabuf *d_buf;
  9839. struct lpfc_dmabuf *h_buf;
  9840. struct hbq_dmabuf *seq_dmabuf = NULL;
  9841. struct hbq_dmabuf *temp_dmabuf = NULL;
  9842. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9843. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9844. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9845. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9846. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9847. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9848. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9849. continue;
  9850. /* found a pending sequence that matches this frame */
  9851. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9852. break;
  9853. }
  9854. if (!seq_dmabuf) {
  9855. /*
  9856. * This indicates first frame received for this sequence.
  9857. * Queue the buffer on the vport's rcv_buffer_list.
  9858. */
  9859. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9860. return dmabuf;
  9861. }
  9862. temp_hdr = seq_dmabuf->hbuf.virt;
  9863. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9864. list_add(&seq_dmabuf->dbuf.list, &dmabuf->dbuf.list);
  9865. return dmabuf;
  9866. }
  9867. /* find the correct place in the sequence to insert this frame */
  9868. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9869. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9870. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9871. /*
  9872. * If the frame's sequence count is greater than the frame on
  9873. * the list then insert the frame right after this frame
  9874. */
  9875. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9876. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9877. return seq_dmabuf;
  9878. }
  9879. }
  9880. return NULL;
  9881. }
  9882. /**
  9883. * lpfc_seq_complete - Indicates if a sequence is complete
  9884. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9885. *
  9886. * This function checks the sequence, starting with the frame described by
  9887. * @dmabuf, to see if all the frames associated with this sequence are present.
  9888. * the frames associated with this sequence are linked to the @dmabuf using the
  9889. * dbuf list. This function looks for two major things. 1) That the first frame
  9890. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  9891. * set. 3) That there are no holes in the sequence count. The function will
  9892. * return 1 when the sequence is complete, otherwise it will return 0.
  9893. **/
  9894. static int
  9895. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  9896. {
  9897. struct fc_frame_header *hdr;
  9898. struct lpfc_dmabuf *d_buf;
  9899. struct hbq_dmabuf *seq_dmabuf;
  9900. uint32_t fctl;
  9901. int seq_count = 0;
  9902. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9903. /* make sure first fame of sequence has a sequence count of zero */
  9904. if (hdr->fh_seq_cnt != seq_count)
  9905. return 0;
  9906. fctl = (hdr->fh_f_ctl[0] << 16 |
  9907. hdr->fh_f_ctl[1] << 8 |
  9908. hdr->fh_f_ctl[2]);
  9909. /* If last frame of sequence we can return success. */
  9910. if (fctl & FC_FC_END_SEQ)
  9911. return 1;
  9912. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  9913. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9914. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9915. /* If there is a hole in the sequence count then fail. */
  9916. if (++seq_count != hdr->fh_seq_cnt)
  9917. return 0;
  9918. fctl = (hdr->fh_f_ctl[0] << 16 |
  9919. hdr->fh_f_ctl[1] << 8 |
  9920. hdr->fh_f_ctl[2]);
  9921. /* If last frame of sequence we can return success. */
  9922. if (fctl & FC_FC_END_SEQ)
  9923. return 1;
  9924. }
  9925. return 0;
  9926. }
  9927. /**
  9928. * lpfc_prep_seq - Prep sequence for ULP processing
  9929. * @vport: Pointer to the vport on which this sequence was received
  9930. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9931. *
  9932. * This function takes a sequence, described by a list of frames, and creates
  9933. * a list of iocbq structures to describe the sequence. This iocbq list will be
  9934. * used to issue to the generic unsolicited sequence handler. This routine
  9935. * returns a pointer to the first iocbq in the list. If the function is unable
  9936. * to allocate an iocbq then it throw out the received frames that were not
  9937. * able to be described and return a pointer to the first iocbq. If unable to
  9938. * allocate any iocbqs (including the first) this function will return NULL.
  9939. **/
  9940. static struct lpfc_iocbq *
  9941. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  9942. {
  9943. struct lpfc_dmabuf *d_buf, *n_buf;
  9944. struct lpfc_iocbq *first_iocbq, *iocbq;
  9945. struct fc_frame_header *fc_hdr;
  9946. uint32_t sid;
  9947. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9948. /* remove from receive buffer list */
  9949. list_del_init(&seq_dmabuf->hbuf.list);
  9950. /* get the Remote Port's SID */
  9951. sid = (fc_hdr->fh_s_id[0] << 16 |
  9952. fc_hdr->fh_s_id[1] << 8 |
  9953. fc_hdr->fh_s_id[2]);
  9954. /* Get an iocbq struct to fill in. */
  9955. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  9956. if (first_iocbq) {
  9957. /* Initialize the first IOCB. */
  9958. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  9959. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  9960. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  9961. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  9962. vport->vpi + vport->phba->vpi_base;
  9963. /* put the first buffer into the first IOCBq */
  9964. first_iocbq->context2 = &seq_dmabuf->dbuf;
  9965. first_iocbq->context3 = NULL;
  9966. first_iocbq->iocb.ulpBdeCount = 1;
  9967. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  9968. LPFC_DATA_BUF_SIZE;
  9969. first_iocbq->iocb.un.rcvels.remoteID = sid;
  9970. }
  9971. iocbq = first_iocbq;
  9972. /*
  9973. * Each IOCBq can have two Buffers assigned, so go through the list
  9974. * of buffers for this sequence and save two buffers in each IOCBq
  9975. */
  9976. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  9977. if (!iocbq) {
  9978. lpfc_in_buf_free(vport->phba, d_buf);
  9979. continue;
  9980. }
  9981. if (!iocbq->context3) {
  9982. iocbq->context3 = d_buf;
  9983. iocbq->iocb.ulpBdeCount++;
  9984. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  9985. LPFC_DATA_BUF_SIZE;
  9986. } else {
  9987. iocbq = lpfc_sli_get_iocbq(vport->phba);
  9988. if (!iocbq) {
  9989. if (first_iocbq) {
  9990. first_iocbq->iocb.ulpStatus =
  9991. IOSTAT_FCP_RSP_ERROR;
  9992. first_iocbq->iocb.un.ulpWord[4] =
  9993. IOERR_NO_RESOURCES;
  9994. }
  9995. lpfc_in_buf_free(vport->phba, d_buf);
  9996. continue;
  9997. }
  9998. iocbq->context2 = d_buf;
  9999. iocbq->context3 = NULL;
  10000. iocbq->iocb.ulpBdeCount = 1;
  10001. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10002. LPFC_DATA_BUF_SIZE;
  10003. iocbq->iocb.un.rcvels.remoteID = sid;
  10004. list_add_tail(&iocbq->list, &first_iocbq->list);
  10005. }
  10006. }
  10007. return first_iocbq;
  10008. }
  10009. /**
  10010. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10011. * @phba: Pointer to HBA context object.
  10012. *
  10013. * This function is called with no lock held. This function processes all
  10014. * the received buffers and gives it to upper layers when a received buffer
  10015. * indicates that it is the final frame in the sequence. The interrupt
  10016. * service routine processes received buffers at interrupt contexts and adds
  10017. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10018. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10019. * appropriate receive function when the final frame in a sequence is received.
  10020. **/
  10021. int
  10022. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba)
  10023. {
  10024. LIST_HEAD(cmplq);
  10025. struct hbq_dmabuf *dmabuf, *seq_dmabuf;
  10026. struct fc_frame_header *fc_hdr;
  10027. struct lpfc_vport *vport;
  10028. uint32_t fcfi;
  10029. struct lpfc_iocbq *iocbq;
  10030. /* Clear hba flag and get all received buffers into the cmplq */
  10031. spin_lock_irq(&phba->hbalock);
  10032. phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
  10033. list_splice_init(&phba->rb_pend_list, &cmplq);
  10034. spin_unlock_irq(&phba->hbalock);
  10035. /* Process each received buffer */
  10036. while ((dmabuf = lpfc_sli_hbqbuf_get(&cmplq)) != NULL) {
  10037. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10038. /* check to see if this a valid type of frame */
  10039. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10040. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10041. continue;
  10042. }
  10043. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->rcqe);
  10044. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10045. if (!vport) {
  10046. /* throw out the frame */
  10047. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10048. continue;
  10049. }
  10050. /* Link this frame */
  10051. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10052. if (!seq_dmabuf) {
  10053. /* unable to add frame to vport - throw it out */
  10054. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10055. continue;
  10056. }
  10057. /* If not last frame in sequence continue processing frames. */
  10058. if (!lpfc_seq_complete(seq_dmabuf)) {
  10059. /*
  10060. * When saving off frames post a new one and mark this
  10061. * frame to be freed when it is finished.
  10062. **/
  10063. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  10064. dmabuf->tag = -1;
  10065. continue;
  10066. }
  10067. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10068. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10069. if (!lpfc_complete_unsol_iocb(phba,
  10070. &phba->sli.ring[LPFC_ELS_RING],
  10071. iocbq, fc_hdr->fh_r_ctl,
  10072. fc_hdr->fh_type))
  10073. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10074. "2540 Ring %d handler: unexpected Rctl "
  10075. "x%x Type x%x received\n",
  10076. LPFC_ELS_RING,
  10077. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10078. };
  10079. return 0;
  10080. }
  10081. /**
  10082. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10083. * @phba: pointer to lpfc hba data structure.
  10084. *
  10085. * This routine is invoked to post rpi header templates to the
  10086. * HBA consistent with the SLI-4 interface spec. This routine
  10087. * posts a PAGE_SIZE memory region to the port to hold up to
  10088. * PAGE_SIZE modulo 64 rpi context headers.
  10089. *
  10090. * This routine does not require any locks. It's usage is expected
  10091. * to be driver load or reset recovery when the driver is
  10092. * sequential.
  10093. *
  10094. * Return codes
  10095. * 0 - sucessful
  10096. * EIO - The mailbox failed to complete successfully.
  10097. * When this error occurs, the driver is not guaranteed
  10098. * to have any rpi regions posted to the device and
  10099. * must either attempt to repost the regions or take a
  10100. * fatal error.
  10101. **/
  10102. int
  10103. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10104. {
  10105. struct lpfc_rpi_hdr *rpi_page;
  10106. uint32_t rc = 0;
  10107. /* Post all rpi memory regions to the port. */
  10108. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10109. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10110. if (rc != MBX_SUCCESS) {
  10111. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10112. "2008 Error %d posting all rpi "
  10113. "headers\n", rc);
  10114. rc = -EIO;
  10115. break;
  10116. }
  10117. }
  10118. return rc;
  10119. }
  10120. /**
  10121. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10122. * @phba: pointer to lpfc hba data structure.
  10123. * @rpi_page: pointer to the rpi memory region.
  10124. *
  10125. * This routine is invoked to post a single rpi header to the
  10126. * HBA consistent with the SLI-4 interface spec. This memory region
  10127. * maps up to 64 rpi context regions.
  10128. *
  10129. * Return codes
  10130. * 0 - sucessful
  10131. * ENOMEM - No available memory
  10132. * EIO - The mailbox failed to complete successfully.
  10133. **/
  10134. int
  10135. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10136. {
  10137. LPFC_MBOXQ_t *mboxq;
  10138. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10139. uint32_t rc = 0;
  10140. uint32_t mbox_tmo;
  10141. uint32_t shdr_status, shdr_add_status;
  10142. union lpfc_sli4_cfg_shdr *shdr;
  10143. /* The port is notified of the header region via a mailbox command. */
  10144. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10145. if (!mboxq) {
  10146. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10147. "2001 Unable to allocate memory for issuing "
  10148. "SLI_CONFIG_SPECIAL mailbox command\n");
  10149. return -ENOMEM;
  10150. }
  10151. /* Post all rpi memory regions to the port. */
  10152. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10153. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10154. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10155. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10156. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10157. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10158. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10159. hdr_tmpl, rpi_page->page_count);
  10160. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10161. rpi_page->start_rpi);
  10162. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10163. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10164. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10165. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10166. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10167. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10168. if (rc != MBX_TIMEOUT)
  10169. mempool_free(mboxq, phba->mbox_mem_pool);
  10170. if (shdr_status || shdr_add_status || rc) {
  10171. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10172. "2514 POST_RPI_HDR mailbox failed with "
  10173. "status x%x add_status x%x, mbx status x%x\n",
  10174. shdr_status, shdr_add_status, rc);
  10175. rc = -ENXIO;
  10176. }
  10177. return rc;
  10178. }
  10179. /**
  10180. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10181. * @phba: pointer to lpfc hba data structure.
  10182. *
  10183. * This routine is invoked to post rpi header templates to the
  10184. * HBA consistent with the SLI-4 interface spec. This routine
  10185. * posts a PAGE_SIZE memory region to the port to hold up to
  10186. * PAGE_SIZE modulo 64 rpi context headers.
  10187. *
  10188. * Returns
  10189. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10190. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10191. **/
  10192. int
  10193. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10194. {
  10195. int rpi;
  10196. uint16_t max_rpi, rpi_base, rpi_limit;
  10197. uint16_t rpi_remaining;
  10198. struct lpfc_rpi_hdr *rpi_hdr;
  10199. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10200. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10201. rpi_limit = phba->sli4_hba.next_rpi;
  10202. /*
  10203. * The valid rpi range is not guaranteed to be zero-based. Start
  10204. * the search at the rpi_base as reported by the port.
  10205. */
  10206. spin_lock_irq(&phba->hbalock);
  10207. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10208. if (rpi >= rpi_limit || rpi < rpi_base)
  10209. rpi = LPFC_RPI_ALLOC_ERROR;
  10210. else {
  10211. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10212. phba->sli4_hba.max_cfg_param.rpi_used++;
  10213. phba->sli4_hba.rpi_count++;
  10214. }
  10215. /*
  10216. * Don't try to allocate more rpi header regions if the device limit
  10217. * on available rpis max has been exhausted.
  10218. */
  10219. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10220. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10221. spin_unlock_irq(&phba->hbalock);
  10222. return rpi;
  10223. }
  10224. /*
  10225. * If the driver is running low on rpi resources, allocate another
  10226. * page now. Note that the next_rpi value is used because
  10227. * it represents how many are actually in use whereas max_rpi notes
  10228. * how many are supported max by the device.
  10229. */
  10230. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10231. phba->sli4_hba.rpi_count;
  10232. spin_unlock_irq(&phba->hbalock);
  10233. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10234. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10235. if (!rpi_hdr) {
  10236. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10237. "2002 Error Could not grow rpi "
  10238. "count\n");
  10239. } else {
  10240. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10241. }
  10242. }
  10243. return rpi;
  10244. }
  10245. /**
  10246. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10247. * @phba: pointer to lpfc hba data structure.
  10248. *
  10249. * This routine is invoked to release an rpi to the pool of
  10250. * available rpis maintained by the driver.
  10251. **/
  10252. void
  10253. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10254. {
  10255. spin_lock_irq(&phba->hbalock);
  10256. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10257. phba->sli4_hba.rpi_count--;
  10258. phba->sli4_hba.max_cfg_param.rpi_used--;
  10259. spin_unlock_irq(&phba->hbalock);
  10260. }
  10261. /**
  10262. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10263. * @phba: pointer to lpfc hba data structure.
  10264. *
  10265. * This routine is invoked to remove the memory region that
  10266. * provided rpi via a bitmask.
  10267. **/
  10268. void
  10269. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10270. {
  10271. kfree(phba->sli4_hba.rpi_bmask);
  10272. }
  10273. /**
  10274. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10275. * @phba: pointer to lpfc hba data structure.
  10276. *
  10277. * This routine is invoked to remove the memory region that
  10278. * provided rpi via a bitmask.
  10279. **/
  10280. int
  10281. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10282. {
  10283. LPFC_MBOXQ_t *mboxq;
  10284. struct lpfc_hba *phba = ndlp->phba;
  10285. int rc;
  10286. /* The port is notified of the header region via a mailbox command. */
  10287. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10288. if (!mboxq)
  10289. return -ENOMEM;
  10290. /* Post all rpi memory regions to the port. */
  10291. lpfc_resume_rpi(mboxq, ndlp);
  10292. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10293. if (rc == MBX_NOT_FINISHED) {
  10294. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10295. "2010 Resume RPI Mailbox failed "
  10296. "status %d, mbxStatus x%x\n", rc,
  10297. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10298. mempool_free(mboxq, phba->mbox_mem_pool);
  10299. return -EIO;
  10300. }
  10301. return 0;
  10302. }
  10303. /**
  10304. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10305. * @phba: pointer to lpfc hba data structure.
  10306. * @vpi: vpi value to activate with the port.
  10307. *
  10308. * This routine is invoked to activate a vpi with the
  10309. * port when the host intends to use vports with a
  10310. * nonzero vpi.
  10311. *
  10312. * Returns:
  10313. * 0 success
  10314. * -Evalue otherwise
  10315. **/
  10316. int
  10317. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10318. {
  10319. LPFC_MBOXQ_t *mboxq;
  10320. int rc = 0;
  10321. uint32_t mbox_tmo;
  10322. if (vpi == 0)
  10323. return -EINVAL;
  10324. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10325. if (!mboxq)
  10326. return -ENOMEM;
  10327. lpfc_init_vpi(mboxq, vpi);
  10328. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10329. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10330. if (rc != MBX_TIMEOUT)
  10331. mempool_free(mboxq, phba->mbox_mem_pool);
  10332. if (rc != MBX_SUCCESS) {
  10333. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10334. "2022 INIT VPI Mailbox failed "
  10335. "status %d, mbxStatus x%x\n", rc,
  10336. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10337. rc = -EIO;
  10338. }
  10339. return rc;
  10340. }
  10341. /**
  10342. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10343. * @phba: pointer to lpfc hba data structure.
  10344. * @mboxq: Pointer to mailbox object.
  10345. *
  10346. * This routine is invoked to manually add a single FCF record. The caller
  10347. * must pass a completely initialized FCF_Record. This routine takes
  10348. * care of the nonembedded mailbox operations.
  10349. **/
  10350. static void
  10351. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10352. {
  10353. void *virt_addr;
  10354. union lpfc_sli4_cfg_shdr *shdr;
  10355. uint32_t shdr_status, shdr_add_status;
  10356. virt_addr = mboxq->sge_array->addr[0];
  10357. /* The IOCTL status is embedded in the mailbox subheader. */
  10358. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10359. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10360. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10361. if ((shdr_status || shdr_add_status) &&
  10362. (shdr_status != STATUS_FCF_IN_USE))
  10363. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10364. "2558 ADD_FCF_RECORD mailbox failed with "
  10365. "status x%x add_status x%x\n",
  10366. shdr_status, shdr_add_status);
  10367. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10368. }
  10369. /**
  10370. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10371. * @phba: pointer to lpfc hba data structure.
  10372. * @fcf_record: pointer to the initialized fcf record to add.
  10373. *
  10374. * This routine is invoked to manually add a single FCF record. The caller
  10375. * must pass a completely initialized FCF_Record. This routine takes
  10376. * care of the nonembedded mailbox operations.
  10377. **/
  10378. int
  10379. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10380. {
  10381. int rc = 0;
  10382. LPFC_MBOXQ_t *mboxq;
  10383. uint8_t *bytep;
  10384. void *virt_addr;
  10385. dma_addr_t phys_addr;
  10386. struct lpfc_mbx_sge sge;
  10387. uint32_t alloc_len, req_len;
  10388. uint32_t fcfindex;
  10389. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10390. if (!mboxq) {
  10391. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10392. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10393. return -ENOMEM;
  10394. }
  10395. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10396. sizeof(uint32_t);
  10397. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10398. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10399. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10400. req_len, LPFC_SLI4_MBX_NEMBED);
  10401. if (alloc_len < req_len) {
  10402. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10403. "2523 Allocated DMA memory size (x%x) is "
  10404. "less than the requested DMA memory "
  10405. "size (x%x)\n", alloc_len, req_len);
  10406. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10407. return -ENOMEM;
  10408. }
  10409. /*
  10410. * Get the first SGE entry from the non-embedded DMA memory. This
  10411. * routine only uses a single SGE.
  10412. */
  10413. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10414. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10415. if (unlikely(!mboxq->sge_array)) {
  10416. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10417. "2526 Failed to get the non-embedded SGE "
  10418. "virtual address\n");
  10419. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10420. return -ENOMEM;
  10421. }
  10422. virt_addr = mboxq->sge_array->addr[0];
  10423. /*
  10424. * Configure the FCF record for FCFI 0. This is the driver's
  10425. * hardcoded default and gets used in nonFIP mode.
  10426. */
  10427. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10428. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10429. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10430. /*
  10431. * Copy the fcf_index and the FCF Record Data. The data starts after
  10432. * the FCoE header plus word10. The data copy needs to be endian
  10433. * correct.
  10434. */
  10435. bytep += sizeof(uint32_t);
  10436. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10437. mboxq->vport = phba->pport;
  10438. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10439. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10440. if (rc == MBX_NOT_FINISHED) {
  10441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10442. "2515 ADD_FCF_RECORD mailbox failed with "
  10443. "status 0x%x\n", rc);
  10444. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10445. rc = -EIO;
  10446. } else
  10447. rc = 0;
  10448. return rc;
  10449. }
  10450. /**
  10451. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10452. * @phba: pointer to lpfc hba data structure.
  10453. * @fcf_record: pointer to the fcf record to write the default data.
  10454. * @fcf_index: FCF table entry index.
  10455. *
  10456. * This routine is invoked to build the driver's default FCF record. The
  10457. * values used are hardcoded. This routine handles memory initialization.
  10458. *
  10459. **/
  10460. void
  10461. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10462. struct fcf_record *fcf_record,
  10463. uint16_t fcf_index)
  10464. {
  10465. memset(fcf_record, 0, sizeof(struct fcf_record));
  10466. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10467. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10468. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10469. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10470. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10471. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10472. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10473. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10474. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10475. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10476. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10477. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10478. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10479. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  10480. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10481. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10482. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10483. /* Set the VLAN bit map */
  10484. if (phba->valid_vlan) {
  10485. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10486. = 1 << (phba->vlan_id % 8);
  10487. }
  10488. }
  10489. /**
  10490. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10491. * @phba: pointer to lpfc hba data structure.
  10492. * @fcf_index: FCF table entry offset.
  10493. *
  10494. * This routine is invoked to read up to @fcf_num of FCF record from the
  10495. * device starting with the given @fcf_index.
  10496. **/
  10497. int
  10498. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10499. {
  10500. int rc = 0, error;
  10501. LPFC_MBOXQ_t *mboxq;
  10502. void *virt_addr;
  10503. dma_addr_t phys_addr;
  10504. uint8_t *bytep;
  10505. struct lpfc_mbx_sge sge;
  10506. uint32_t alloc_len, req_len;
  10507. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10508. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10509. if (!mboxq) {
  10510. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10511. "2000 Failed to allocate mbox for "
  10512. "READ_FCF cmd\n");
  10513. return -ENOMEM;
  10514. }
  10515. req_len = sizeof(struct fcf_record) +
  10516. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10517. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10518. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10519. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10520. LPFC_SLI4_MBX_NEMBED);
  10521. if (alloc_len < req_len) {
  10522. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10523. "0291 Allocated DMA memory size (x%x) is "
  10524. "less than the requested DMA memory "
  10525. "size (x%x)\n", alloc_len, req_len);
  10526. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10527. return -ENOMEM;
  10528. }
  10529. /* Get the first SGE entry from the non-embedded DMA memory. This
  10530. * routine only uses a single SGE.
  10531. */
  10532. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10533. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10534. if (unlikely(!mboxq->sge_array)) {
  10535. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10536. "2527 Failed to get the non-embedded SGE "
  10537. "virtual address\n");
  10538. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10539. return -ENOMEM;
  10540. }
  10541. virt_addr = mboxq->sge_array->addr[0];
  10542. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10543. /* Set up command fields */
  10544. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10545. /* Perform necessary endian conversion */
  10546. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10547. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10548. mboxq->vport = phba->pport;
  10549. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10550. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10551. if (rc == MBX_NOT_FINISHED) {
  10552. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10553. error = -EIO;
  10554. } else
  10555. error = 0;
  10556. return error;
  10557. }