lpfc_sli.c 402 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static IOCB_t *
  63. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  64. {
  65. return &iocbq->iocb;
  66. }
  67. /**
  68. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  69. * @q: The Work Queue to operate on.
  70. * @wqe: The work Queue Entry to put on the Work queue.
  71. *
  72. * This routine will copy the contents of @wqe to the next available entry on
  73. * the @q. This function will then ring the Work Queue Doorbell to signal the
  74. * HBA to start processing the Work Queue Entry. This function returns 0 if
  75. * successful. If no entries are available on @q then this function will return
  76. * -ENOMEM.
  77. * The caller is expected to hold the hbalock when calling this routine.
  78. **/
  79. static uint32_t
  80. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  81. {
  82. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  83. struct lpfc_register doorbell;
  84. uint32_t host_index;
  85. /* If the host has not yet processed the next entry then we are done */
  86. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  87. return -ENOMEM;
  88. /* set consumption flag every once in a while */
  89. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  90. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  91. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  92. /* Update the host index before invoking device */
  93. host_index = q->host_index;
  94. q->host_index = ((q->host_index + 1) % q->entry_count);
  95. /* Ring Doorbell */
  96. doorbell.word0 = 0;
  97. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  98. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  99. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  100. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  101. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  102. return 0;
  103. }
  104. /**
  105. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  106. * @q: The Work Queue to operate on.
  107. * @index: The index to advance the hba index to.
  108. *
  109. * This routine will update the HBA index of a queue to reflect consumption of
  110. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  111. * an entry the host calls this function to update the queue's internal
  112. * pointers. This routine returns the number of entries that were consumed by
  113. * the HBA.
  114. **/
  115. static uint32_t
  116. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  117. {
  118. uint32_t released = 0;
  119. if (q->hba_index == index)
  120. return 0;
  121. do {
  122. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  123. released++;
  124. } while (q->hba_index != index);
  125. return released;
  126. }
  127. /**
  128. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  129. * @q: The Mailbox Queue to operate on.
  130. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  131. *
  132. * This routine will copy the contents of @mqe to the next available entry on
  133. * the @q. This function will then ring the Work Queue Doorbell to signal the
  134. * HBA to start processing the Work Queue Entry. This function returns 0 if
  135. * successful. If no entries are available on @q then this function will return
  136. * -ENOMEM.
  137. * The caller is expected to hold the hbalock when calling this routine.
  138. **/
  139. static uint32_t
  140. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  141. {
  142. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  143. struct lpfc_register doorbell;
  144. uint32_t host_index;
  145. /* If the host has not yet processed the next entry then we are done */
  146. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  147. return -ENOMEM;
  148. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  149. /* Save off the mailbox pointer for completion */
  150. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  151. /* Update the host index before invoking device */
  152. host_index = q->host_index;
  153. q->host_index = ((q->host_index + 1) % q->entry_count);
  154. /* Ring Doorbell */
  155. doorbell.word0 = 0;
  156. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  157. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  158. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  159. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  160. return 0;
  161. }
  162. /**
  163. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  164. * @q: The Mailbox Queue to operate on.
  165. *
  166. * This routine will update the HBA index of a queue to reflect consumption of
  167. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  168. * an entry the host calls this function to update the queue's internal
  169. * pointers. This routine returns the number of entries that were consumed by
  170. * the HBA.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_release(struct lpfc_queue *q)
  174. {
  175. /* Clear the mailbox pointer for completion */
  176. q->phba->mbox = NULL;
  177. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  178. return 1;
  179. }
  180. /**
  181. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  182. * @q: The Event Queue to get the first valid EQE from
  183. *
  184. * This routine will get the first valid Event Queue Entry from @q, update
  185. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  186. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  187. * processed, but not popped back to the HBA then this routine will return NULL.
  188. **/
  189. static struct lpfc_eqe *
  190. lpfc_sli4_eq_get(struct lpfc_queue *q)
  191. {
  192. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  193. /* If the next EQE is not valid then we are done */
  194. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  195. return NULL;
  196. /* If the host has not yet processed the next entry then we are done */
  197. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  198. return NULL;
  199. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  200. return eqe;
  201. }
  202. /**
  203. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  204. * @q: The Event Queue that the host has completed processing for.
  205. * @arm: Indicates whether the host wants to arms this CQ.
  206. *
  207. * This routine will mark all Event Queue Entries on @q, from the last
  208. * known completed entry to the last entry that was processed, as completed
  209. * by clearing the valid bit for each completion queue entry. Then it will
  210. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  211. * The internal host index in the @q will be updated by this routine to indicate
  212. * that the host has finished processing the entries. The @arm parameter
  213. * indicates that the queue should be rearmed when ringing the doorbell.
  214. *
  215. * This function will return the number of EQEs that were popped.
  216. **/
  217. uint32_t
  218. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  219. {
  220. uint32_t released = 0;
  221. struct lpfc_eqe *temp_eqe;
  222. struct lpfc_register doorbell;
  223. /* while there are valid entries */
  224. while (q->hba_index != q->host_index) {
  225. temp_eqe = q->qe[q->host_index].eqe;
  226. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  227. released++;
  228. q->host_index = ((q->host_index + 1) % q->entry_count);
  229. }
  230. if (unlikely(released == 0 && !arm))
  231. return 0;
  232. /* ring doorbell for number popped */
  233. doorbell.word0 = 0;
  234. if (arm) {
  235. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  236. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  237. }
  238. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  239. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  240. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  241. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  242. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  243. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  244. readl(q->phba->sli4_hba.EQCQDBregaddr);
  245. return released;
  246. }
  247. /**
  248. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  249. * @q: The Completion Queue to get the first valid CQE from
  250. *
  251. * This routine will get the first valid Completion Queue Entry from @q, update
  252. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  253. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  254. * processed, but not popped back to the HBA then this routine will return NULL.
  255. **/
  256. static struct lpfc_cqe *
  257. lpfc_sli4_cq_get(struct lpfc_queue *q)
  258. {
  259. struct lpfc_cqe *cqe;
  260. /* If the next CQE is not valid then we are done */
  261. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  262. return NULL;
  263. /* If the host has not yet processed the next entry then we are done */
  264. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  265. return NULL;
  266. cqe = q->qe[q->hba_index].cqe;
  267. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  268. return cqe;
  269. }
  270. /**
  271. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  272. * @q: The Completion Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Completion queue entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of CQEs that were released.
  284. **/
  285. uint32_t
  286. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_cqe *temp_qe;
  290. struct lpfc_register doorbell;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_qe = q->qe[q->host_index].cqe;
  294. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm)
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  305. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  306. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  307. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  308. return released;
  309. }
  310. /**
  311. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  312. * @q: The Header Receive Queue to operate on.
  313. * @wqe: The Receive Queue Entry to put on the Receive queue.
  314. *
  315. * This routine will copy the contents of @wqe to the next available entry on
  316. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  317. * HBA to start processing the Receive Queue Entry. This function returns the
  318. * index that the rqe was copied to if successful. If no entries are available
  319. * on @q then this function will return -ENOMEM.
  320. * The caller is expected to hold the hbalock when calling this routine.
  321. **/
  322. static int
  323. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  324. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  325. {
  326. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  327. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  328. struct lpfc_register doorbell;
  329. int put_index = hq->host_index;
  330. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  331. return -EINVAL;
  332. if (hq->host_index != dq->host_index)
  333. return -EINVAL;
  334. /* If the host has not yet processed the next entry then we are done */
  335. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  336. return -EBUSY;
  337. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  338. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  339. /* Update the host index to point to the next slot */
  340. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  341. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  342. /* Ring The Header Receive Queue Doorbell */
  343. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  344. doorbell.word0 = 0;
  345. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  346. LPFC_RQ_POST_BATCH);
  347. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  348. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  349. }
  350. return put_index;
  351. }
  352. /**
  353. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  354. * @q: The Header Receive Queue to operate on.
  355. *
  356. * This routine will update the HBA index of a queue to reflect consumption of
  357. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  358. * consumed an entry the host calls this function to update the queue's
  359. * internal pointers. This routine returns the number of entries that were
  360. * consumed by the HBA.
  361. **/
  362. static uint32_t
  363. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  364. {
  365. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  366. return 0;
  367. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  368. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  369. return 1;
  370. }
  371. /**
  372. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  373. * @phba: Pointer to HBA context object.
  374. * @pring: Pointer to driver SLI ring object.
  375. *
  376. * This function returns pointer to next command iocb entry
  377. * in the command ring. The caller must hold hbalock to prevent
  378. * other threads consume the next command iocb.
  379. * SLI-2/SLI-3 provide different sized iocbs.
  380. **/
  381. static inline IOCB_t *
  382. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  383. {
  384. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  385. pring->cmdidx * phba->iocb_cmd_size);
  386. }
  387. /**
  388. * lpfc_resp_iocb - Get next response iocb entry in the ring
  389. * @phba: Pointer to HBA context object.
  390. * @pring: Pointer to driver SLI ring object.
  391. *
  392. * This function returns pointer to next response iocb entry
  393. * in the response ring. The caller must hold hbalock to make sure
  394. * that no other thread consume the next response iocb.
  395. * SLI-2/SLI-3 provide different sized iocbs.
  396. **/
  397. static inline IOCB_t *
  398. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. return (IOCB_t *) (((char *) pring->rspringaddr) +
  401. pring->rspidx * phba->iocb_rsp_size);
  402. }
  403. /**
  404. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  405. * @phba: Pointer to HBA context object.
  406. *
  407. * This function is called with hbalock held. This function
  408. * allocates a new driver iocb object from the iocb pool. If the
  409. * allocation is successful, it returns pointer to the newly
  410. * allocated iocb object else it returns NULL.
  411. **/
  412. static struct lpfc_iocbq *
  413. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  414. {
  415. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  416. struct lpfc_iocbq * iocbq = NULL;
  417. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  418. if (iocbq)
  419. phba->iocb_cnt++;
  420. if (phba->iocb_cnt > phba->iocb_max)
  421. phba->iocb_max = phba->iocb_cnt;
  422. return iocbq;
  423. }
  424. /**
  425. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  426. * @phba: Pointer to HBA context object.
  427. * @xritag: XRI value.
  428. *
  429. * This function clears the sglq pointer from the array of acive
  430. * sglq's. The xritag that is passed in is used to index into the
  431. * array. Before the xritag can be used it needs to be adjusted
  432. * by subtracting the xribase.
  433. *
  434. * Returns sglq ponter = success, NULL = Failure.
  435. **/
  436. static struct lpfc_sglq *
  437. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  438. {
  439. uint16_t adj_xri;
  440. struct lpfc_sglq *sglq;
  441. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  442. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  443. return NULL;
  444. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  445. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  446. return sglq;
  447. }
  448. /**
  449. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  450. * @phba: Pointer to HBA context object.
  451. * @xritag: XRI value.
  452. *
  453. * This function returns the sglq pointer from the array of acive
  454. * sglq's. The xritag that is passed in is used to index into the
  455. * array. Before the xritag can be used it needs to be adjusted
  456. * by subtracting the xribase.
  457. *
  458. * Returns sglq ponter = success, NULL = Failure.
  459. **/
  460. struct lpfc_sglq *
  461. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  462. {
  463. uint16_t adj_xri;
  464. struct lpfc_sglq *sglq;
  465. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  466. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  467. return NULL;
  468. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  469. return sglq;
  470. }
  471. /**
  472. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  473. * @phba: Pointer to HBA context object.
  474. *
  475. * This function is called with hbalock held. This function
  476. * Gets a new driver sglq object from the sglq list. If the
  477. * list is not empty then it is successful, it returns pointer to the newly
  478. * allocated sglq object else it returns NULL.
  479. **/
  480. static struct lpfc_sglq *
  481. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  482. {
  483. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  484. struct lpfc_sglq *sglq = NULL;
  485. uint16_t adj_xri;
  486. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  487. if (!sglq)
  488. return NULL;
  489. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  490. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  491. sglq->state = SGL_ALLOCATED;
  492. return sglq;
  493. }
  494. /**
  495. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  496. * @phba: Pointer to HBA context object.
  497. *
  498. * This function is called with no lock held. This function
  499. * allocates a new driver iocb object from the iocb pool. If the
  500. * allocation is successful, it returns pointer to the newly
  501. * allocated iocb object else it returns NULL.
  502. **/
  503. struct lpfc_iocbq *
  504. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  505. {
  506. struct lpfc_iocbq * iocbq = NULL;
  507. unsigned long iflags;
  508. spin_lock_irqsave(&phba->hbalock, iflags);
  509. iocbq = __lpfc_sli_get_iocbq(phba);
  510. spin_unlock_irqrestore(&phba->hbalock, iflags);
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  515. * @phba: Pointer to HBA context object.
  516. * @iocbq: Pointer to driver iocb object.
  517. *
  518. * This function is called with hbalock held to release driver
  519. * iocb object to the iocb pool. The iotag in the iocb object
  520. * does not change for each use of the iocb object. This function
  521. * clears all other fields of the iocb object when it is freed.
  522. * The sqlq structure that holds the xritag and phys and virtual
  523. * mappings for the scatter gather list is retrieved from the
  524. * active array of sglq. The get of the sglq pointer also clears
  525. * the entry in the array. If the status of the IO indiactes that
  526. * this IO was aborted then the sglq entry it put on the
  527. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  528. * IO has good status or fails for any other reason then the sglq
  529. * entry is added to the free list (lpfc_sgl_list).
  530. **/
  531. static void
  532. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  533. {
  534. struct lpfc_sglq *sglq;
  535. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  536. unsigned long iflag = 0;
  537. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  538. if (iocbq->sli4_xritag == NO_XRI)
  539. sglq = NULL;
  540. else
  541. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  542. if (sglq) {
  543. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  544. (sglq->state != SGL_XRI_ABORTED)) {
  545. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  546. iflag);
  547. list_add(&sglq->list,
  548. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  549. spin_unlock_irqrestore(
  550. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  551. } else {
  552. sglq->state = SGL_FREED;
  553. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  554. /* Check if TXQ queue needs to be serviced */
  555. if (pring->txq_cnt)
  556. lpfc_worker_wake_up(phba);
  557. }
  558. }
  559. /*
  560. * Clean all volatile data fields, preserve iotag and node struct.
  561. */
  562. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  563. iocbq->sli4_xritag = NO_XRI;
  564. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  565. }
  566. /**
  567. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  568. * @phba: Pointer to HBA context object.
  569. * @iocbq: Pointer to driver iocb object.
  570. *
  571. * This function is called with hbalock held to release driver
  572. * iocb object to the iocb pool. The iotag in the iocb object
  573. * does not change for each use of the iocb object. This function
  574. * clears all other fields of the iocb object when it is freed.
  575. **/
  576. static void
  577. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  578. {
  579. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  580. /*
  581. * Clean all volatile data fields, preserve iotag and node struct.
  582. */
  583. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  584. iocbq->sli4_xritag = NO_XRI;
  585. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  586. }
  587. /**
  588. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  589. * @phba: Pointer to HBA context object.
  590. * @iocbq: Pointer to driver iocb object.
  591. *
  592. * This function is called with hbalock held to release driver
  593. * iocb object to the iocb pool. The iotag in the iocb object
  594. * does not change for each use of the iocb object. This function
  595. * clears all other fields of the iocb object when it is freed.
  596. **/
  597. static void
  598. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  599. {
  600. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  601. phba->iocb_cnt--;
  602. }
  603. /**
  604. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  605. * @phba: Pointer to HBA context object.
  606. * @iocbq: Pointer to driver iocb object.
  607. *
  608. * This function is called with no lock held to release the iocb to
  609. * iocb pool.
  610. **/
  611. void
  612. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  613. {
  614. unsigned long iflags;
  615. /*
  616. * Clean all volatile data fields, preserve iotag and node struct.
  617. */
  618. spin_lock_irqsave(&phba->hbalock, iflags);
  619. __lpfc_sli_release_iocbq(phba, iocbq);
  620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  621. }
  622. /**
  623. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  624. * @phba: Pointer to HBA context object.
  625. * @iocblist: List of IOCBs.
  626. * @ulpstatus: ULP status in IOCB command field.
  627. * @ulpWord4: ULP word-4 in IOCB command field.
  628. *
  629. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  630. * on the list by invoking the complete callback function associated with the
  631. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  632. * fields.
  633. **/
  634. void
  635. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  636. uint32_t ulpstatus, uint32_t ulpWord4)
  637. {
  638. struct lpfc_iocbq *piocb;
  639. while (!list_empty(iocblist)) {
  640. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  641. if (!piocb->iocb_cmpl)
  642. lpfc_sli_release_iocbq(phba, piocb);
  643. else {
  644. piocb->iocb.ulpStatus = ulpstatus;
  645. piocb->iocb.un.ulpWord[4] = ulpWord4;
  646. (piocb->iocb_cmpl) (phba, piocb, piocb);
  647. }
  648. }
  649. return;
  650. }
  651. /**
  652. * lpfc_sli_iocb_cmd_type - Get the iocb type
  653. * @iocb_cmnd: iocb command code.
  654. *
  655. * This function is called by ring event handler function to get the iocb type.
  656. * This function translates the iocb command to an iocb command type used to
  657. * decide the final disposition of each completed IOCB.
  658. * The function returns
  659. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  660. * LPFC_SOL_IOCB if it is a solicited iocb completion
  661. * LPFC_ABORT_IOCB if it is an abort iocb
  662. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  663. *
  664. * The caller is not required to hold any lock.
  665. **/
  666. static lpfc_iocb_type
  667. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  668. {
  669. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  670. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  671. return 0;
  672. switch (iocb_cmnd) {
  673. case CMD_XMIT_SEQUENCE_CR:
  674. case CMD_XMIT_SEQUENCE_CX:
  675. case CMD_XMIT_BCAST_CN:
  676. case CMD_XMIT_BCAST_CX:
  677. case CMD_ELS_REQUEST_CR:
  678. case CMD_ELS_REQUEST_CX:
  679. case CMD_CREATE_XRI_CR:
  680. case CMD_CREATE_XRI_CX:
  681. case CMD_GET_RPI_CN:
  682. case CMD_XMIT_ELS_RSP_CX:
  683. case CMD_GET_RPI_CR:
  684. case CMD_FCP_IWRITE_CR:
  685. case CMD_FCP_IWRITE_CX:
  686. case CMD_FCP_IREAD_CR:
  687. case CMD_FCP_IREAD_CX:
  688. case CMD_FCP_ICMND_CR:
  689. case CMD_FCP_ICMND_CX:
  690. case CMD_FCP_TSEND_CX:
  691. case CMD_FCP_TRSP_CX:
  692. case CMD_FCP_TRECEIVE_CX:
  693. case CMD_FCP_AUTO_TRSP_CX:
  694. case CMD_ADAPTER_MSG:
  695. case CMD_ADAPTER_DUMP:
  696. case CMD_XMIT_SEQUENCE64_CR:
  697. case CMD_XMIT_SEQUENCE64_CX:
  698. case CMD_XMIT_BCAST64_CN:
  699. case CMD_XMIT_BCAST64_CX:
  700. case CMD_ELS_REQUEST64_CR:
  701. case CMD_ELS_REQUEST64_CX:
  702. case CMD_FCP_IWRITE64_CR:
  703. case CMD_FCP_IWRITE64_CX:
  704. case CMD_FCP_IREAD64_CR:
  705. case CMD_FCP_IREAD64_CX:
  706. case CMD_FCP_ICMND64_CR:
  707. case CMD_FCP_ICMND64_CX:
  708. case CMD_FCP_TSEND64_CX:
  709. case CMD_FCP_TRSP64_CX:
  710. case CMD_FCP_TRECEIVE64_CX:
  711. case CMD_GEN_REQUEST64_CR:
  712. case CMD_GEN_REQUEST64_CX:
  713. case CMD_XMIT_ELS_RSP64_CX:
  714. case DSSCMD_IWRITE64_CR:
  715. case DSSCMD_IWRITE64_CX:
  716. case DSSCMD_IREAD64_CR:
  717. case DSSCMD_IREAD64_CX:
  718. type = LPFC_SOL_IOCB;
  719. break;
  720. case CMD_ABORT_XRI_CN:
  721. case CMD_ABORT_XRI_CX:
  722. case CMD_CLOSE_XRI_CN:
  723. case CMD_CLOSE_XRI_CX:
  724. case CMD_XRI_ABORTED_CX:
  725. case CMD_ABORT_MXRI64_CN:
  726. case CMD_XMIT_BLS_RSP64_CX:
  727. type = LPFC_ABORT_IOCB;
  728. break;
  729. case CMD_RCV_SEQUENCE_CX:
  730. case CMD_RCV_ELS_REQ_CX:
  731. case CMD_RCV_SEQUENCE64_CX:
  732. case CMD_RCV_ELS_REQ64_CX:
  733. case CMD_ASYNC_STATUS:
  734. case CMD_IOCB_RCV_SEQ64_CX:
  735. case CMD_IOCB_RCV_ELS64_CX:
  736. case CMD_IOCB_RCV_CONT64_CX:
  737. case CMD_IOCB_RET_XRI64_CX:
  738. type = LPFC_UNSOL_IOCB;
  739. break;
  740. case CMD_IOCB_XMIT_MSEQ64_CR:
  741. case CMD_IOCB_XMIT_MSEQ64_CX:
  742. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  743. case CMD_IOCB_RCV_ELS_LIST64_CX:
  744. case CMD_IOCB_CLOSE_EXTENDED_CN:
  745. case CMD_IOCB_ABORT_EXTENDED_CN:
  746. case CMD_IOCB_RET_HBQE64_CN:
  747. case CMD_IOCB_FCP_IBIDIR64_CR:
  748. case CMD_IOCB_FCP_IBIDIR64_CX:
  749. case CMD_IOCB_FCP_ITASKMGT64_CX:
  750. case CMD_IOCB_LOGENTRY_CN:
  751. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  752. printk("%s - Unhandled SLI-3 Command x%x\n",
  753. __func__, iocb_cmnd);
  754. type = LPFC_UNKNOWN_IOCB;
  755. break;
  756. default:
  757. type = LPFC_UNKNOWN_IOCB;
  758. break;
  759. }
  760. return type;
  761. }
  762. /**
  763. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  764. * @phba: Pointer to HBA context object.
  765. *
  766. * This function is called from SLI initialization code
  767. * to configure every ring of the HBA's SLI interface. The
  768. * caller is not required to hold any lock. This function issues
  769. * a config_ring mailbox command for each ring.
  770. * This function returns zero if successful else returns a negative
  771. * error code.
  772. **/
  773. static int
  774. lpfc_sli_ring_map(struct lpfc_hba *phba)
  775. {
  776. struct lpfc_sli *psli = &phba->sli;
  777. LPFC_MBOXQ_t *pmb;
  778. MAILBOX_t *pmbox;
  779. int i, rc, ret = 0;
  780. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  781. if (!pmb)
  782. return -ENOMEM;
  783. pmbox = &pmb->u.mb;
  784. phba->link_state = LPFC_INIT_MBX_CMDS;
  785. for (i = 0; i < psli->num_rings; i++) {
  786. lpfc_config_ring(phba, i, pmb);
  787. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  788. if (rc != MBX_SUCCESS) {
  789. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  790. "0446 Adapter failed to init (%d), "
  791. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  792. "ring %d\n",
  793. rc, pmbox->mbxCommand,
  794. pmbox->mbxStatus, i);
  795. phba->link_state = LPFC_HBA_ERROR;
  796. ret = -ENXIO;
  797. break;
  798. }
  799. }
  800. mempool_free(pmb, phba->mbox_mem_pool);
  801. return ret;
  802. }
  803. /**
  804. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  805. * @phba: Pointer to HBA context object.
  806. * @pring: Pointer to driver SLI ring object.
  807. * @piocb: Pointer to the driver iocb object.
  808. *
  809. * This function is called with hbalock held. The function adds the
  810. * new iocb to txcmplq of the given ring. This function always returns
  811. * 0. If this function is called for ELS ring, this function checks if
  812. * there is a vport associated with the ELS command. This function also
  813. * starts els_tmofunc timer if this is an ELS command.
  814. **/
  815. static int
  816. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  817. struct lpfc_iocbq *piocb)
  818. {
  819. list_add_tail(&piocb->list, &pring->txcmplq);
  820. piocb->iocb_flag |= LPFC_IO_ON_Q;
  821. pring->txcmplq_cnt++;
  822. if (pring->txcmplq_cnt > pring->txcmplq_max)
  823. pring->txcmplq_max = pring->txcmplq_cnt;
  824. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  825. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  826. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  827. if (!piocb->vport)
  828. BUG();
  829. else
  830. mod_timer(&piocb->vport->els_tmofunc,
  831. jiffies + HZ * (phba->fc_ratov << 1));
  832. }
  833. return 0;
  834. }
  835. /**
  836. * lpfc_sli_ringtx_get - Get first element of the txq
  837. * @phba: Pointer to HBA context object.
  838. * @pring: Pointer to driver SLI ring object.
  839. *
  840. * This function is called with hbalock held to get next
  841. * iocb in txq of the given ring. If there is any iocb in
  842. * the txq, the function returns first iocb in the list after
  843. * removing the iocb from the list, else it returns NULL.
  844. **/
  845. struct lpfc_iocbq *
  846. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  847. {
  848. struct lpfc_iocbq *cmd_iocb;
  849. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  850. if (cmd_iocb != NULL)
  851. pring->txq_cnt--;
  852. return cmd_iocb;
  853. }
  854. /**
  855. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  856. * @phba: Pointer to HBA context object.
  857. * @pring: Pointer to driver SLI ring object.
  858. *
  859. * This function is called with hbalock held and the caller must post the
  860. * iocb without releasing the lock. If the caller releases the lock,
  861. * iocb slot returned by the function is not guaranteed to be available.
  862. * The function returns pointer to the next available iocb slot if there
  863. * is available slot in the ring, else it returns NULL.
  864. * If the get index of the ring is ahead of the put index, the function
  865. * will post an error attention event to the worker thread to take the
  866. * HBA to offline state.
  867. **/
  868. static IOCB_t *
  869. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  870. {
  871. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  872. uint32_t max_cmd_idx = pring->numCiocb;
  873. if ((pring->next_cmdidx == pring->cmdidx) &&
  874. (++pring->next_cmdidx >= max_cmd_idx))
  875. pring->next_cmdidx = 0;
  876. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  877. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  878. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  879. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  880. "0315 Ring %d issue: portCmdGet %d "
  881. "is bigger than cmd ring %d\n",
  882. pring->ringno,
  883. pring->local_getidx, max_cmd_idx);
  884. phba->link_state = LPFC_HBA_ERROR;
  885. /*
  886. * All error attention handlers are posted to
  887. * worker thread
  888. */
  889. phba->work_ha |= HA_ERATT;
  890. phba->work_hs = HS_FFER3;
  891. lpfc_worker_wake_up(phba);
  892. return NULL;
  893. }
  894. if (pring->local_getidx == pring->next_cmdidx)
  895. return NULL;
  896. }
  897. return lpfc_cmd_iocb(phba, pring);
  898. }
  899. /**
  900. * lpfc_sli_next_iotag - Get an iotag for the iocb
  901. * @phba: Pointer to HBA context object.
  902. * @iocbq: Pointer to driver iocb object.
  903. *
  904. * This function gets an iotag for the iocb. If there is no unused iotag and
  905. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  906. * array and assigns a new iotag.
  907. * The function returns the allocated iotag if successful, else returns zero.
  908. * Zero is not a valid iotag.
  909. * The caller is not required to hold any lock.
  910. **/
  911. uint16_t
  912. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  913. {
  914. struct lpfc_iocbq **new_arr;
  915. struct lpfc_iocbq **old_arr;
  916. size_t new_len;
  917. struct lpfc_sli *psli = &phba->sli;
  918. uint16_t iotag;
  919. spin_lock_irq(&phba->hbalock);
  920. iotag = psli->last_iotag;
  921. if(++iotag < psli->iocbq_lookup_len) {
  922. psli->last_iotag = iotag;
  923. psli->iocbq_lookup[iotag] = iocbq;
  924. spin_unlock_irq(&phba->hbalock);
  925. iocbq->iotag = iotag;
  926. return iotag;
  927. } else if (psli->iocbq_lookup_len < (0xffff
  928. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  929. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  930. spin_unlock_irq(&phba->hbalock);
  931. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  932. GFP_KERNEL);
  933. if (new_arr) {
  934. spin_lock_irq(&phba->hbalock);
  935. old_arr = psli->iocbq_lookup;
  936. if (new_len <= psli->iocbq_lookup_len) {
  937. /* highly unprobable case */
  938. kfree(new_arr);
  939. iotag = psli->last_iotag;
  940. if(++iotag < psli->iocbq_lookup_len) {
  941. psli->last_iotag = iotag;
  942. psli->iocbq_lookup[iotag] = iocbq;
  943. spin_unlock_irq(&phba->hbalock);
  944. iocbq->iotag = iotag;
  945. return iotag;
  946. }
  947. spin_unlock_irq(&phba->hbalock);
  948. return 0;
  949. }
  950. if (psli->iocbq_lookup)
  951. memcpy(new_arr, old_arr,
  952. ((psli->last_iotag + 1) *
  953. sizeof (struct lpfc_iocbq *)));
  954. psli->iocbq_lookup = new_arr;
  955. psli->iocbq_lookup_len = new_len;
  956. psli->last_iotag = iotag;
  957. psli->iocbq_lookup[iotag] = iocbq;
  958. spin_unlock_irq(&phba->hbalock);
  959. iocbq->iotag = iotag;
  960. kfree(old_arr);
  961. return iotag;
  962. }
  963. } else
  964. spin_unlock_irq(&phba->hbalock);
  965. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  966. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  967. psli->last_iotag);
  968. return 0;
  969. }
  970. /**
  971. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  972. * @phba: Pointer to HBA context object.
  973. * @pring: Pointer to driver SLI ring object.
  974. * @iocb: Pointer to iocb slot in the ring.
  975. * @nextiocb: Pointer to driver iocb object which need to be
  976. * posted to firmware.
  977. *
  978. * This function is called with hbalock held to post a new iocb to
  979. * the firmware. This function copies the new iocb to ring iocb slot and
  980. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  981. * a completion call back for this iocb else the function will free the
  982. * iocb object.
  983. **/
  984. static void
  985. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  986. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  987. {
  988. /*
  989. * Set up an iotag
  990. */
  991. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  992. if (pring->ringno == LPFC_ELS_RING) {
  993. lpfc_debugfs_slow_ring_trc(phba,
  994. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  995. *(((uint32_t *) &nextiocb->iocb) + 4),
  996. *(((uint32_t *) &nextiocb->iocb) + 6),
  997. *(((uint32_t *) &nextiocb->iocb) + 7));
  998. }
  999. /*
  1000. * Issue iocb command to adapter
  1001. */
  1002. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1003. wmb();
  1004. pring->stats.iocb_cmd++;
  1005. /*
  1006. * If there is no completion routine to call, we can release the
  1007. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1008. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1009. */
  1010. if (nextiocb->iocb_cmpl)
  1011. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1012. else
  1013. __lpfc_sli_release_iocbq(phba, nextiocb);
  1014. /*
  1015. * Let the HBA know what IOCB slot will be the next one the
  1016. * driver will put a command into.
  1017. */
  1018. pring->cmdidx = pring->next_cmdidx;
  1019. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1020. }
  1021. /**
  1022. * lpfc_sli_update_full_ring - Update the chip attention register
  1023. * @phba: Pointer to HBA context object.
  1024. * @pring: Pointer to driver SLI ring object.
  1025. *
  1026. * The caller is not required to hold any lock for calling this function.
  1027. * This function updates the chip attention bits for the ring to inform firmware
  1028. * that there are pending work to be done for this ring and requests an
  1029. * interrupt when there is space available in the ring. This function is
  1030. * called when the driver is unable to post more iocbs to the ring due
  1031. * to unavailability of space in the ring.
  1032. **/
  1033. static void
  1034. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1035. {
  1036. int ringno = pring->ringno;
  1037. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1038. wmb();
  1039. /*
  1040. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1041. * The HBA will tell us when an IOCB entry is available.
  1042. */
  1043. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1044. readl(phba->CAregaddr); /* flush */
  1045. pring->stats.iocb_cmd_full++;
  1046. }
  1047. /**
  1048. * lpfc_sli_update_ring - Update chip attention register
  1049. * @phba: Pointer to HBA context object.
  1050. * @pring: Pointer to driver SLI ring object.
  1051. *
  1052. * This function updates the chip attention register bit for the
  1053. * given ring to inform HBA that there is more work to be done
  1054. * in this ring. The caller is not required to hold any lock.
  1055. **/
  1056. static void
  1057. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1058. {
  1059. int ringno = pring->ringno;
  1060. /*
  1061. * Tell the HBA that there is work to do in this ring.
  1062. */
  1063. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1064. wmb();
  1065. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1066. readl(phba->CAregaddr); /* flush */
  1067. }
  1068. }
  1069. /**
  1070. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1071. * @phba: Pointer to HBA context object.
  1072. * @pring: Pointer to driver SLI ring object.
  1073. *
  1074. * This function is called with hbalock held to post pending iocbs
  1075. * in the txq to the firmware. This function is called when driver
  1076. * detects space available in the ring.
  1077. **/
  1078. static void
  1079. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1080. {
  1081. IOCB_t *iocb;
  1082. struct lpfc_iocbq *nextiocb;
  1083. /*
  1084. * Check to see if:
  1085. * (a) there is anything on the txq to send
  1086. * (b) link is up
  1087. * (c) link attention events can be processed (fcp ring only)
  1088. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1089. */
  1090. if (pring->txq_cnt &&
  1091. lpfc_is_link_up(phba) &&
  1092. (pring->ringno != phba->sli.fcp_ring ||
  1093. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1094. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1095. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1096. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1097. if (iocb)
  1098. lpfc_sli_update_ring(phba, pring);
  1099. else
  1100. lpfc_sli_update_full_ring(phba, pring);
  1101. }
  1102. return;
  1103. }
  1104. /**
  1105. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1106. * @phba: Pointer to HBA context object.
  1107. * @hbqno: HBQ number.
  1108. *
  1109. * This function is called with hbalock held to get the next
  1110. * available slot for the given HBQ. If there is free slot
  1111. * available for the HBQ it will return pointer to the next available
  1112. * HBQ entry else it will return NULL.
  1113. **/
  1114. static struct lpfc_hbq_entry *
  1115. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1116. {
  1117. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1118. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1119. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1120. hbqp->next_hbqPutIdx = 0;
  1121. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1122. uint32_t raw_index = phba->hbq_get[hbqno];
  1123. uint32_t getidx = le32_to_cpu(raw_index);
  1124. hbqp->local_hbqGetIdx = getidx;
  1125. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1126. lpfc_printf_log(phba, KERN_ERR,
  1127. LOG_SLI | LOG_VPORT,
  1128. "1802 HBQ %d: local_hbqGetIdx "
  1129. "%u is > than hbqp->entry_count %u\n",
  1130. hbqno, hbqp->local_hbqGetIdx,
  1131. hbqp->entry_count);
  1132. phba->link_state = LPFC_HBA_ERROR;
  1133. return NULL;
  1134. }
  1135. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1136. return NULL;
  1137. }
  1138. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1139. hbqp->hbqPutIdx;
  1140. }
  1141. /**
  1142. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1143. * @phba: Pointer to HBA context object.
  1144. *
  1145. * This function is called with no lock held to free all the
  1146. * hbq buffers while uninitializing the SLI interface. It also
  1147. * frees the HBQ buffers returned by the firmware but not yet
  1148. * processed by the upper layers.
  1149. **/
  1150. void
  1151. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1152. {
  1153. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1154. struct hbq_dmabuf *hbq_buf;
  1155. unsigned long flags;
  1156. int i, hbq_count;
  1157. uint32_t hbqno;
  1158. hbq_count = lpfc_sli_hbq_count();
  1159. /* Return all memory used by all HBQs */
  1160. spin_lock_irqsave(&phba->hbalock, flags);
  1161. for (i = 0; i < hbq_count; ++i) {
  1162. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1163. &phba->hbqs[i].hbq_buffer_list, list) {
  1164. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1165. list_del(&hbq_buf->dbuf.list);
  1166. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1167. }
  1168. phba->hbqs[i].buffer_count = 0;
  1169. }
  1170. /* Return all HBQ buffer that are in-fly */
  1171. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1172. list) {
  1173. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1174. list_del(&hbq_buf->dbuf.list);
  1175. if (hbq_buf->tag == -1) {
  1176. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1177. (phba, hbq_buf);
  1178. } else {
  1179. hbqno = hbq_buf->tag >> 16;
  1180. if (hbqno >= LPFC_MAX_HBQS)
  1181. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1182. (phba, hbq_buf);
  1183. else
  1184. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1185. hbq_buf);
  1186. }
  1187. }
  1188. /* Mark the HBQs not in use */
  1189. phba->hbq_in_use = 0;
  1190. spin_unlock_irqrestore(&phba->hbalock, flags);
  1191. }
  1192. /**
  1193. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1194. * @phba: Pointer to HBA context object.
  1195. * @hbqno: HBQ number.
  1196. * @hbq_buf: Pointer to HBQ buffer.
  1197. *
  1198. * This function is called with the hbalock held to post a
  1199. * hbq buffer to the firmware. If the function finds an empty
  1200. * slot in the HBQ, it will post the buffer. The function will return
  1201. * pointer to the hbq entry if it successfully post the buffer
  1202. * else it will return NULL.
  1203. **/
  1204. static int
  1205. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1206. struct hbq_dmabuf *hbq_buf)
  1207. {
  1208. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1209. }
  1210. /**
  1211. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1212. * @phba: Pointer to HBA context object.
  1213. * @hbqno: HBQ number.
  1214. * @hbq_buf: Pointer to HBQ buffer.
  1215. *
  1216. * This function is called with the hbalock held to post a hbq buffer to the
  1217. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1218. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1219. * it successfully post the buffer else it will return an error.
  1220. **/
  1221. static int
  1222. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1223. struct hbq_dmabuf *hbq_buf)
  1224. {
  1225. struct lpfc_hbq_entry *hbqe;
  1226. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1227. /* Get next HBQ entry slot to use */
  1228. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1229. if (hbqe) {
  1230. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1231. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1232. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1233. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1234. hbqe->bde.tus.f.bdeFlags = 0;
  1235. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1236. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1237. /* Sync SLIM */
  1238. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1239. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1240. /* flush */
  1241. readl(phba->hbq_put + hbqno);
  1242. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1243. return 0;
  1244. } else
  1245. return -ENOMEM;
  1246. }
  1247. /**
  1248. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1249. * @phba: Pointer to HBA context object.
  1250. * @hbqno: HBQ number.
  1251. * @hbq_buf: Pointer to HBQ buffer.
  1252. *
  1253. * This function is called with the hbalock held to post an RQE to the SLI4
  1254. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1255. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1256. **/
  1257. static int
  1258. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1259. struct hbq_dmabuf *hbq_buf)
  1260. {
  1261. int rc;
  1262. struct lpfc_rqe hrqe;
  1263. struct lpfc_rqe drqe;
  1264. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1265. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1266. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1267. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1268. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1269. &hrqe, &drqe);
  1270. if (rc < 0)
  1271. return rc;
  1272. hbq_buf->tag = rc;
  1273. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1274. return 0;
  1275. }
  1276. /* HBQ for ELS and CT traffic. */
  1277. static struct lpfc_hbq_init lpfc_els_hbq = {
  1278. .rn = 1,
  1279. .entry_count = 256,
  1280. .mask_count = 0,
  1281. .profile = 0,
  1282. .ring_mask = (1 << LPFC_ELS_RING),
  1283. .buffer_count = 0,
  1284. .init_count = 40,
  1285. .add_count = 40,
  1286. };
  1287. /* HBQ for the extra ring if needed */
  1288. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1289. .rn = 1,
  1290. .entry_count = 200,
  1291. .mask_count = 0,
  1292. .profile = 0,
  1293. .ring_mask = (1 << LPFC_EXTRA_RING),
  1294. .buffer_count = 0,
  1295. .init_count = 0,
  1296. .add_count = 5,
  1297. };
  1298. /* Array of HBQs */
  1299. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1300. &lpfc_els_hbq,
  1301. &lpfc_extra_hbq,
  1302. };
  1303. /**
  1304. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1305. * @phba: Pointer to HBA context object.
  1306. * @hbqno: HBQ number.
  1307. * @count: Number of HBQ buffers to be posted.
  1308. *
  1309. * This function is called with no lock held to post more hbq buffers to the
  1310. * given HBQ. The function returns the number of HBQ buffers successfully
  1311. * posted.
  1312. **/
  1313. static int
  1314. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1315. {
  1316. uint32_t i, posted = 0;
  1317. unsigned long flags;
  1318. struct hbq_dmabuf *hbq_buffer;
  1319. LIST_HEAD(hbq_buf_list);
  1320. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1321. return 0;
  1322. if ((phba->hbqs[hbqno].buffer_count + count) >
  1323. lpfc_hbq_defs[hbqno]->entry_count)
  1324. count = lpfc_hbq_defs[hbqno]->entry_count -
  1325. phba->hbqs[hbqno].buffer_count;
  1326. if (!count)
  1327. return 0;
  1328. /* Allocate HBQ entries */
  1329. for (i = 0; i < count; i++) {
  1330. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1331. if (!hbq_buffer)
  1332. break;
  1333. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1334. }
  1335. /* Check whether HBQ is still in use */
  1336. spin_lock_irqsave(&phba->hbalock, flags);
  1337. if (!phba->hbq_in_use)
  1338. goto err;
  1339. while (!list_empty(&hbq_buf_list)) {
  1340. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1341. dbuf.list);
  1342. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1343. (hbqno << 16));
  1344. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1345. phba->hbqs[hbqno].buffer_count++;
  1346. posted++;
  1347. } else
  1348. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1349. }
  1350. spin_unlock_irqrestore(&phba->hbalock, flags);
  1351. return posted;
  1352. err:
  1353. spin_unlock_irqrestore(&phba->hbalock, flags);
  1354. while (!list_empty(&hbq_buf_list)) {
  1355. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1356. dbuf.list);
  1357. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1358. }
  1359. return 0;
  1360. }
  1361. /**
  1362. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1363. * @phba: Pointer to HBA context object.
  1364. * @qno: HBQ number.
  1365. *
  1366. * This function posts more buffers to the HBQ. This function
  1367. * is called with no lock held. The function returns the number of HBQ entries
  1368. * successfully allocated.
  1369. **/
  1370. int
  1371. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1372. {
  1373. if (phba->sli_rev == LPFC_SLI_REV4)
  1374. return 0;
  1375. else
  1376. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1377. lpfc_hbq_defs[qno]->add_count);
  1378. }
  1379. /**
  1380. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1381. * @phba: Pointer to HBA context object.
  1382. * @qno: HBQ queue number.
  1383. *
  1384. * This function is called from SLI initialization code path with
  1385. * no lock held to post initial HBQ buffers to firmware. The
  1386. * function returns the number of HBQ entries successfully allocated.
  1387. **/
  1388. static int
  1389. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1390. {
  1391. if (phba->sli_rev == LPFC_SLI_REV4)
  1392. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1393. lpfc_hbq_defs[qno]->entry_count);
  1394. else
  1395. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1396. lpfc_hbq_defs[qno]->init_count);
  1397. }
  1398. /**
  1399. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1400. * @phba: Pointer to HBA context object.
  1401. * @hbqno: HBQ number.
  1402. *
  1403. * This function removes the first hbq buffer on an hbq list and returns a
  1404. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1405. **/
  1406. static struct hbq_dmabuf *
  1407. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1408. {
  1409. struct lpfc_dmabuf *d_buf;
  1410. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1411. if (!d_buf)
  1412. return NULL;
  1413. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1414. }
  1415. /**
  1416. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1417. * @phba: Pointer to HBA context object.
  1418. * @tag: Tag of the hbq buffer.
  1419. *
  1420. * This function is called with hbalock held. This function searches
  1421. * for the hbq buffer associated with the given tag in the hbq buffer
  1422. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1423. * it returns NULL.
  1424. **/
  1425. static struct hbq_dmabuf *
  1426. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1427. {
  1428. struct lpfc_dmabuf *d_buf;
  1429. struct hbq_dmabuf *hbq_buf;
  1430. uint32_t hbqno;
  1431. hbqno = tag >> 16;
  1432. if (hbqno >= LPFC_MAX_HBQS)
  1433. return NULL;
  1434. spin_lock_irq(&phba->hbalock);
  1435. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1436. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1437. if (hbq_buf->tag == tag) {
  1438. spin_unlock_irq(&phba->hbalock);
  1439. return hbq_buf;
  1440. }
  1441. }
  1442. spin_unlock_irq(&phba->hbalock);
  1443. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1444. "1803 Bad hbq tag. Data: x%x x%x\n",
  1445. tag, phba->hbqs[tag >> 16].buffer_count);
  1446. return NULL;
  1447. }
  1448. /**
  1449. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1450. * @phba: Pointer to HBA context object.
  1451. * @hbq_buffer: Pointer to HBQ buffer.
  1452. *
  1453. * This function is called with hbalock. This function gives back
  1454. * the hbq buffer to firmware. If the HBQ does not have space to
  1455. * post the buffer, it will free the buffer.
  1456. **/
  1457. void
  1458. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1459. {
  1460. uint32_t hbqno;
  1461. if (hbq_buffer) {
  1462. hbqno = hbq_buffer->tag >> 16;
  1463. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1464. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1465. }
  1466. }
  1467. /**
  1468. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1469. * @mbxCommand: mailbox command code.
  1470. *
  1471. * This function is called by the mailbox event handler function to verify
  1472. * that the completed mailbox command is a legitimate mailbox command. If the
  1473. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1474. * and the mailbox event handler will take the HBA offline.
  1475. **/
  1476. static int
  1477. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1478. {
  1479. uint8_t ret;
  1480. switch (mbxCommand) {
  1481. case MBX_LOAD_SM:
  1482. case MBX_READ_NV:
  1483. case MBX_WRITE_NV:
  1484. case MBX_WRITE_VPARMS:
  1485. case MBX_RUN_BIU_DIAG:
  1486. case MBX_INIT_LINK:
  1487. case MBX_DOWN_LINK:
  1488. case MBX_CONFIG_LINK:
  1489. case MBX_CONFIG_RING:
  1490. case MBX_RESET_RING:
  1491. case MBX_READ_CONFIG:
  1492. case MBX_READ_RCONFIG:
  1493. case MBX_READ_SPARM:
  1494. case MBX_READ_STATUS:
  1495. case MBX_READ_RPI:
  1496. case MBX_READ_XRI:
  1497. case MBX_READ_REV:
  1498. case MBX_READ_LNK_STAT:
  1499. case MBX_REG_LOGIN:
  1500. case MBX_UNREG_LOGIN:
  1501. case MBX_READ_LA:
  1502. case MBX_CLEAR_LA:
  1503. case MBX_DUMP_MEMORY:
  1504. case MBX_DUMP_CONTEXT:
  1505. case MBX_RUN_DIAGS:
  1506. case MBX_RESTART:
  1507. case MBX_UPDATE_CFG:
  1508. case MBX_DOWN_LOAD:
  1509. case MBX_DEL_LD_ENTRY:
  1510. case MBX_RUN_PROGRAM:
  1511. case MBX_SET_MASK:
  1512. case MBX_SET_VARIABLE:
  1513. case MBX_UNREG_D_ID:
  1514. case MBX_KILL_BOARD:
  1515. case MBX_CONFIG_FARP:
  1516. case MBX_BEACON:
  1517. case MBX_LOAD_AREA:
  1518. case MBX_RUN_BIU_DIAG64:
  1519. case MBX_CONFIG_PORT:
  1520. case MBX_READ_SPARM64:
  1521. case MBX_READ_RPI64:
  1522. case MBX_REG_LOGIN64:
  1523. case MBX_READ_LA64:
  1524. case MBX_WRITE_WWN:
  1525. case MBX_SET_DEBUG:
  1526. case MBX_LOAD_EXP_ROM:
  1527. case MBX_ASYNCEVT_ENABLE:
  1528. case MBX_REG_VPI:
  1529. case MBX_UNREG_VPI:
  1530. case MBX_HEARTBEAT:
  1531. case MBX_PORT_CAPABILITIES:
  1532. case MBX_PORT_IOV_CONTROL:
  1533. case MBX_SLI4_CONFIG:
  1534. case MBX_SLI4_REQ_FTRS:
  1535. case MBX_REG_FCFI:
  1536. case MBX_UNREG_FCFI:
  1537. case MBX_REG_VFI:
  1538. case MBX_UNREG_VFI:
  1539. case MBX_INIT_VPI:
  1540. case MBX_INIT_VFI:
  1541. case MBX_RESUME_RPI:
  1542. case MBX_READ_EVENT_LOG_STATUS:
  1543. case MBX_READ_EVENT_LOG:
  1544. case MBX_SECURITY_MGMT:
  1545. case MBX_AUTH_PORT:
  1546. ret = mbxCommand;
  1547. break;
  1548. default:
  1549. ret = MBX_SHUTDOWN;
  1550. break;
  1551. }
  1552. return ret;
  1553. }
  1554. /**
  1555. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1556. * @phba: Pointer to HBA context object.
  1557. * @pmboxq: Pointer to mailbox command.
  1558. *
  1559. * This is completion handler function for mailbox commands issued from
  1560. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1561. * mailbox event handler function with no lock held. This function
  1562. * will wake up thread waiting on the wait queue pointed by context1
  1563. * of the mailbox.
  1564. **/
  1565. void
  1566. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1567. {
  1568. wait_queue_head_t *pdone_q;
  1569. unsigned long drvr_flag;
  1570. /*
  1571. * If pdone_q is empty, the driver thread gave up waiting and
  1572. * continued running.
  1573. */
  1574. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1575. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1576. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1577. if (pdone_q)
  1578. wake_up_interruptible(pdone_q);
  1579. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1580. return;
  1581. }
  1582. /**
  1583. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1584. * @phba: Pointer to HBA context object.
  1585. * @pmb: Pointer to mailbox object.
  1586. *
  1587. * This function is the default mailbox completion handler. It
  1588. * frees the memory resources associated with the completed mailbox
  1589. * command. If the completed command is a REG_LOGIN mailbox command,
  1590. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1591. **/
  1592. void
  1593. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1594. {
  1595. struct lpfc_vport *vport = pmb->vport;
  1596. struct lpfc_dmabuf *mp;
  1597. struct lpfc_nodelist *ndlp;
  1598. struct Scsi_Host *shost;
  1599. uint16_t rpi, vpi;
  1600. int rc;
  1601. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1602. if (mp) {
  1603. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1604. kfree(mp);
  1605. }
  1606. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1607. (phba->sli_rev == LPFC_SLI_REV4) &&
  1608. (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0))
  1609. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1610. /*
  1611. * If a REG_LOGIN succeeded after node is destroyed or node
  1612. * is in re-discovery driver need to cleanup the RPI.
  1613. */
  1614. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1615. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1616. !pmb->u.mb.mbxStatus) {
  1617. rpi = pmb->u.mb.un.varWords[0];
  1618. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1619. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1620. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1621. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1622. if (rc != MBX_NOT_FINISHED)
  1623. return;
  1624. }
  1625. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1626. !(phba->pport->load_flag & FC_UNLOADING) &&
  1627. !pmb->u.mb.mbxStatus) {
  1628. shost = lpfc_shost_from_vport(vport);
  1629. spin_lock_irq(shost->host_lock);
  1630. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1631. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1632. spin_unlock_irq(shost->host_lock);
  1633. }
  1634. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1635. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1636. lpfc_nlp_put(ndlp);
  1637. pmb->context2 = NULL;
  1638. }
  1639. /* Check security permission status on INIT_LINK mailbox command */
  1640. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1641. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1642. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1643. "2860 SLI authentication is required "
  1644. "for INIT_LINK but has not done yet\n");
  1645. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1646. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1647. else
  1648. mempool_free(pmb, phba->mbox_mem_pool);
  1649. }
  1650. /**
  1651. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1652. * @phba: Pointer to HBA context object.
  1653. *
  1654. * This function is called with no lock held. This function processes all
  1655. * the completed mailbox commands and gives it to upper layers. The interrupt
  1656. * service routine processes mailbox completion interrupt and adds completed
  1657. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1658. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1659. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1660. * function returns the mailbox commands to the upper layer by calling the
  1661. * completion handler function of each mailbox.
  1662. **/
  1663. int
  1664. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1665. {
  1666. MAILBOX_t *pmbox;
  1667. LPFC_MBOXQ_t *pmb;
  1668. int rc;
  1669. LIST_HEAD(cmplq);
  1670. phba->sli.slistat.mbox_event++;
  1671. /* Get all completed mailboxe buffers into the cmplq */
  1672. spin_lock_irq(&phba->hbalock);
  1673. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1674. spin_unlock_irq(&phba->hbalock);
  1675. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1676. do {
  1677. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1678. if (pmb == NULL)
  1679. break;
  1680. pmbox = &pmb->u.mb;
  1681. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1682. if (pmb->vport) {
  1683. lpfc_debugfs_disc_trc(pmb->vport,
  1684. LPFC_DISC_TRC_MBOX_VPORT,
  1685. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1686. (uint32_t)pmbox->mbxCommand,
  1687. pmbox->un.varWords[0],
  1688. pmbox->un.varWords[1]);
  1689. }
  1690. else {
  1691. lpfc_debugfs_disc_trc(phba->pport,
  1692. LPFC_DISC_TRC_MBOX,
  1693. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1694. (uint32_t)pmbox->mbxCommand,
  1695. pmbox->un.varWords[0],
  1696. pmbox->un.varWords[1]);
  1697. }
  1698. }
  1699. /*
  1700. * It is a fatal error if unknown mbox command completion.
  1701. */
  1702. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1703. MBX_SHUTDOWN) {
  1704. /* Unknown mailbox command compl */
  1705. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1706. "(%d):0323 Unknown Mailbox command "
  1707. "x%x (x%x) Cmpl\n",
  1708. pmb->vport ? pmb->vport->vpi : 0,
  1709. pmbox->mbxCommand,
  1710. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1711. phba->link_state = LPFC_HBA_ERROR;
  1712. phba->work_hs = HS_FFER3;
  1713. lpfc_handle_eratt(phba);
  1714. continue;
  1715. }
  1716. if (pmbox->mbxStatus) {
  1717. phba->sli.slistat.mbox_stat_err++;
  1718. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1719. /* Mbox cmd cmpl error - RETRYing */
  1720. lpfc_printf_log(phba, KERN_INFO,
  1721. LOG_MBOX | LOG_SLI,
  1722. "(%d):0305 Mbox cmd cmpl "
  1723. "error - RETRYing Data: x%x "
  1724. "(x%x) x%x x%x x%x\n",
  1725. pmb->vport ? pmb->vport->vpi :0,
  1726. pmbox->mbxCommand,
  1727. lpfc_sli4_mbox_opcode_get(phba,
  1728. pmb),
  1729. pmbox->mbxStatus,
  1730. pmbox->un.varWords[0],
  1731. pmb->vport->port_state);
  1732. pmbox->mbxStatus = 0;
  1733. pmbox->mbxOwner = OWN_HOST;
  1734. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1735. if (rc != MBX_NOT_FINISHED)
  1736. continue;
  1737. }
  1738. }
  1739. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1740. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1741. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1742. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1743. pmb->vport ? pmb->vport->vpi : 0,
  1744. pmbox->mbxCommand,
  1745. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1746. pmb->mbox_cmpl,
  1747. *((uint32_t *) pmbox),
  1748. pmbox->un.varWords[0],
  1749. pmbox->un.varWords[1],
  1750. pmbox->un.varWords[2],
  1751. pmbox->un.varWords[3],
  1752. pmbox->un.varWords[4],
  1753. pmbox->un.varWords[5],
  1754. pmbox->un.varWords[6],
  1755. pmbox->un.varWords[7]);
  1756. if (pmb->mbox_cmpl)
  1757. pmb->mbox_cmpl(phba,pmb);
  1758. } while (1);
  1759. return 0;
  1760. }
  1761. /**
  1762. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1763. * @phba: Pointer to HBA context object.
  1764. * @pring: Pointer to driver SLI ring object.
  1765. * @tag: buffer tag.
  1766. *
  1767. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1768. * is set in the tag the buffer is posted for a particular exchange,
  1769. * the function will return the buffer without replacing the buffer.
  1770. * If the buffer is for unsolicited ELS or CT traffic, this function
  1771. * returns the buffer and also posts another buffer to the firmware.
  1772. **/
  1773. static struct lpfc_dmabuf *
  1774. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1775. struct lpfc_sli_ring *pring,
  1776. uint32_t tag)
  1777. {
  1778. struct hbq_dmabuf *hbq_entry;
  1779. if (tag & QUE_BUFTAG_BIT)
  1780. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1781. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1782. if (!hbq_entry)
  1783. return NULL;
  1784. return &hbq_entry->dbuf;
  1785. }
  1786. /**
  1787. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1788. * @phba: Pointer to HBA context object.
  1789. * @pring: Pointer to driver SLI ring object.
  1790. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1791. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1792. * @fch_type: the type for the first frame of the sequence.
  1793. *
  1794. * This function is called with no lock held. This function uses the r_ctl and
  1795. * type of the received sequence to find the correct callback function to call
  1796. * to process the sequence.
  1797. **/
  1798. static int
  1799. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1800. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1801. uint32_t fch_type)
  1802. {
  1803. int i;
  1804. /* unSolicited Responses */
  1805. if (pring->prt[0].profile) {
  1806. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1807. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1808. saveq);
  1809. return 1;
  1810. }
  1811. /* We must search, based on rctl / type
  1812. for the right routine */
  1813. for (i = 0; i < pring->num_mask; i++) {
  1814. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1815. (pring->prt[i].type == fch_type)) {
  1816. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1817. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1818. (phba, pring, saveq);
  1819. return 1;
  1820. }
  1821. }
  1822. return 0;
  1823. }
  1824. /**
  1825. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1826. * @phba: Pointer to HBA context object.
  1827. * @pring: Pointer to driver SLI ring object.
  1828. * @saveq: Pointer to the unsolicited iocb.
  1829. *
  1830. * This function is called with no lock held by the ring event handler
  1831. * when there is an unsolicited iocb posted to the response ring by the
  1832. * firmware. This function gets the buffer associated with the iocbs
  1833. * and calls the event handler for the ring. This function handles both
  1834. * qring buffers and hbq buffers.
  1835. * When the function returns 1 the caller can free the iocb object otherwise
  1836. * upper layer functions will free the iocb objects.
  1837. **/
  1838. static int
  1839. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1840. struct lpfc_iocbq *saveq)
  1841. {
  1842. IOCB_t * irsp;
  1843. WORD5 * w5p;
  1844. uint32_t Rctl, Type;
  1845. uint32_t match;
  1846. struct lpfc_iocbq *iocbq;
  1847. struct lpfc_dmabuf *dmzbuf;
  1848. match = 0;
  1849. irsp = &(saveq->iocb);
  1850. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1851. if (pring->lpfc_sli_rcv_async_status)
  1852. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1853. else
  1854. lpfc_printf_log(phba,
  1855. KERN_WARNING,
  1856. LOG_SLI,
  1857. "0316 Ring %d handler: unexpected "
  1858. "ASYNC_STATUS iocb received evt_code "
  1859. "0x%x\n",
  1860. pring->ringno,
  1861. irsp->un.asyncstat.evt_code);
  1862. return 1;
  1863. }
  1864. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1865. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1866. if (irsp->ulpBdeCount > 0) {
  1867. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1868. irsp->un.ulpWord[3]);
  1869. lpfc_in_buf_free(phba, dmzbuf);
  1870. }
  1871. if (irsp->ulpBdeCount > 1) {
  1872. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1873. irsp->unsli3.sli3Words[3]);
  1874. lpfc_in_buf_free(phba, dmzbuf);
  1875. }
  1876. if (irsp->ulpBdeCount > 2) {
  1877. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1878. irsp->unsli3.sli3Words[7]);
  1879. lpfc_in_buf_free(phba, dmzbuf);
  1880. }
  1881. return 1;
  1882. }
  1883. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1884. if (irsp->ulpBdeCount != 0) {
  1885. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1886. irsp->un.ulpWord[3]);
  1887. if (!saveq->context2)
  1888. lpfc_printf_log(phba,
  1889. KERN_ERR,
  1890. LOG_SLI,
  1891. "0341 Ring %d Cannot find buffer for "
  1892. "an unsolicited iocb. tag 0x%x\n",
  1893. pring->ringno,
  1894. irsp->un.ulpWord[3]);
  1895. }
  1896. if (irsp->ulpBdeCount == 2) {
  1897. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1898. irsp->unsli3.sli3Words[7]);
  1899. if (!saveq->context3)
  1900. lpfc_printf_log(phba,
  1901. KERN_ERR,
  1902. LOG_SLI,
  1903. "0342 Ring %d Cannot find buffer for an"
  1904. " unsolicited iocb. tag 0x%x\n",
  1905. pring->ringno,
  1906. irsp->unsli3.sli3Words[7]);
  1907. }
  1908. list_for_each_entry(iocbq, &saveq->list, list) {
  1909. irsp = &(iocbq->iocb);
  1910. if (irsp->ulpBdeCount != 0) {
  1911. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1912. irsp->un.ulpWord[3]);
  1913. if (!iocbq->context2)
  1914. lpfc_printf_log(phba,
  1915. KERN_ERR,
  1916. LOG_SLI,
  1917. "0343 Ring %d Cannot find "
  1918. "buffer for an unsolicited iocb"
  1919. ". tag 0x%x\n", pring->ringno,
  1920. irsp->un.ulpWord[3]);
  1921. }
  1922. if (irsp->ulpBdeCount == 2) {
  1923. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1924. irsp->unsli3.sli3Words[7]);
  1925. if (!iocbq->context3)
  1926. lpfc_printf_log(phba,
  1927. KERN_ERR,
  1928. LOG_SLI,
  1929. "0344 Ring %d Cannot find "
  1930. "buffer for an unsolicited "
  1931. "iocb. tag 0x%x\n",
  1932. pring->ringno,
  1933. irsp->unsli3.sli3Words[7]);
  1934. }
  1935. }
  1936. }
  1937. if (irsp->ulpBdeCount != 0 &&
  1938. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1939. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1940. int found = 0;
  1941. /* search continue save q for same XRI */
  1942. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1943. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1944. list_add_tail(&saveq->list, &iocbq->list);
  1945. found = 1;
  1946. break;
  1947. }
  1948. }
  1949. if (!found)
  1950. list_add_tail(&saveq->clist,
  1951. &pring->iocb_continue_saveq);
  1952. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1953. list_del_init(&iocbq->clist);
  1954. saveq = iocbq;
  1955. irsp = &(saveq->iocb);
  1956. } else
  1957. return 0;
  1958. }
  1959. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1960. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1961. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1962. Rctl = FC_RCTL_ELS_REQ;
  1963. Type = FC_TYPE_ELS;
  1964. } else {
  1965. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1966. Rctl = w5p->hcsw.Rctl;
  1967. Type = w5p->hcsw.Type;
  1968. /* Firmware Workaround */
  1969. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1970. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1971. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1972. Rctl = FC_RCTL_ELS_REQ;
  1973. Type = FC_TYPE_ELS;
  1974. w5p->hcsw.Rctl = Rctl;
  1975. w5p->hcsw.Type = Type;
  1976. }
  1977. }
  1978. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1979. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1980. "0313 Ring %d handler: unexpected Rctl x%x "
  1981. "Type x%x received\n",
  1982. pring->ringno, Rctl, Type);
  1983. return 1;
  1984. }
  1985. /**
  1986. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1987. * @phba: Pointer to HBA context object.
  1988. * @pring: Pointer to driver SLI ring object.
  1989. * @prspiocb: Pointer to response iocb object.
  1990. *
  1991. * This function looks up the iocb_lookup table to get the command iocb
  1992. * corresponding to the given response iocb using the iotag of the
  1993. * response iocb. This function is called with the hbalock held.
  1994. * This function returns the command iocb object if it finds the command
  1995. * iocb else returns NULL.
  1996. **/
  1997. static struct lpfc_iocbq *
  1998. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1999. struct lpfc_sli_ring *pring,
  2000. struct lpfc_iocbq *prspiocb)
  2001. {
  2002. struct lpfc_iocbq *cmd_iocb = NULL;
  2003. uint16_t iotag;
  2004. iotag = prspiocb->iocb.ulpIoTag;
  2005. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2006. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2007. list_del_init(&cmd_iocb->list);
  2008. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2009. pring->txcmplq_cnt--;
  2010. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2011. }
  2012. return cmd_iocb;
  2013. }
  2014. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2015. "0317 iotag x%x is out off "
  2016. "range: max iotag x%x wd0 x%x\n",
  2017. iotag, phba->sli.last_iotag,
  2018. *(((uint32_t *) &prspiocb->iocb) + 7));
  2019. return NULL;
  2020. }
  2021. /**
  2022. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2023. * @phba: Pointer to HBA context object.
  2024. * @pring: Pointer to driver SLI ring object.
  2025. * @iotag: IOCB tag.
  2026. *
  2027. * This function looks up the iocb_lookup table to get the command iocb
  2028. * corresponding to the given iotag. This function is called with the
  2029. * hbalock held.
  2030. * This function returns the command iocb object if it finds the command
  2031. * iocb else returns NULL.
  2032. **/
  2033. static struct lpfc_iocbq *
  2034. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2035. struct lpfc_sli_ring *pring, uint16_t iotag)
  2036. {
  2037. struct lpfc_iocbq *cmd_iocb;
  2038. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2039. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2040. list_del_init(&cmd_iocb->list);
  2041. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2042. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2043. pring->txcmplq_cnt--;
  2044. }
  2045. return cmd_iocb;
  2046. }
  2047. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2048. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2049. iotag, phba->sli.last_iotag);
  2050. return NULL;
  2051. }
  2052. /**
  2053. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2054. * @phba: Pointer to HBA context object.
  2055. * @pring: Pointer to driver SLI ring object.
  2056. * @saveq: Pointer to the response iocb to be processed.
  2057. *
  2058. * This function is called by the ring event handler for non-fcp
  2059. * rings when there is a new response iocb in the response ring.
  2060. * The caller is not required to hold any locks. This function
  2061. * gets the command iocb associated with the response iocb and
  2062. * calls the completion handler for the command iocb. If there
  2063. * is no completion handler, the function will free the resources
  2064. * associated with command iocb. If the response iocb is for
  2065. * an already aborted command iocb, the status of the completion
  2066. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2067. * This function always returns 1.
  2068. **/
  2069. static int
  2070. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2071. struct lpfc_iocbq *saveq)
  2072. {
  2073. struct lpfc_iocbq *cmdiocbp;
  2074. int rc = 1;
  2075. unsigned long iflag;
  2076. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2077. spin_lock_irqsave(&phba->hbalock, iflag);
  2078. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2079. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2080. if (cmdiocbp) {
  2081. if (cmdiocbp->iocb_cmpl) {
  2082. /*
  2083. * If an ELS command failed send an event to mgmt
  2084. * application.
  2085. */
  2086. if (saveq->iocb.ulpStatus &&
  2087. (pring->ringno == LPFC_ELS_RING) &&
  2088. (cmdiocbp->iocb.ulpCommand ==
  2089. CMD_ELS_REQUEST64_CR))
  2090. lpfc_send_els_failure_event(phba,
  2091. cmdiocbp, saveq);
  2092. /*
  2093. * Post all ELS completions to the worker thread.
  2094. * All other are passed to the completion callback.
  2095. */
  2096. if (pring->ringno == LPFC_ELS_RING) {
  2097. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2098. (cmdiocbp->iocb_flag &
  2099. LPFC_DRIVER_ABORTED)) {
  2100. spin_lock_irqsave(&phba->hbalock,
  2101. iflag);
  2102. cmdiocbp->iocb_flag &=
  2103. ~LPFC_DRIVER_ABORTED;
  2104. spin_unlock_irqrestore(&phba->hbalock,
  2105. iflag);
  2106. saveq->iocb.ulpStatus =
  2107. IOSTAT_LOCAL_REJECT;
  2108. saveq->iocb.un.ulpWord[4] =
  2109. IOERR_SLI_ABORTED;
  2110. /* Firmware could still be in progress
  2111. * of DMAing payload, so don't free data
  2112. * buffer till after a hbeat.
  2113. */
  2114. spin_lock_irqsave(&phba->hbalock,
  2115. iflag);
  2116. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2117. spin_unlock_irqrestore(&phba->hbalock,
  2118. iflag);
  2119. }
  2120. if (phba->sli_rev == LPFC_SLI_REV4) {
  2121. if (saveq->iocb_flag &
  2122. LPFC_EXCHANGE_BUSY) {
  2123. /* Set cmdiocb flag for the
  2124. * exchange busy so sgl (xri)
  2125. * will not be released until
  2126. * the abort xri is received
  2127. * from hba.
  2128. */
  2129. spin_lock_irqsave(
  2130. &phba->hbalock, iflag);
  2131. cmdiocbp->iocb_flag |=
  2132. LPFC_EXCHANGE_BUSY;
  2133. spin_unlock_irqrestore(
  2134. &phba->hbalock, iflag);
  2135. }
  2136. if (cmdiocbp->iocb_flag &
  2137. LPFC_DRIVER_ABORTED) {
  2138. /*
  2139. * Clear LPFC_DRIVER_ABORTED
  2140. * bit in case it was driver
  2141. * initiated abort.
  2142. */
  2143. spin_lock_irqsave(
  2144. &phba->hbalock, iflag);
  2145. cmdiocbp->iocb_flag &=
  2146. ~LPFC_DRIVER_ABORTED;
  2147. spin_unlock_irqrestore(
  2148. &phba->hbalock, iflag);
  2149. cmdiocbp->iocb.ulpStatus =
  2150. IOSTAT_LOCAL_REJECT;
  2151. cmdiocbp->iocb.un.ulpWord[4] =
  2152. IOERR_ABORT_REQUESTED;
  2153. /*
  2154. * For SLI4, irsiocb contains
  2155. * NO_XRI in sli_xritag, it
  2156. * shall not affect releasing
  2157. * sgl (xri) process.
  2158. */
  2159. saveq->iocb.ulpStatus =
  2160. IOSTAT_LOCAL_REJECT;
  2161. saveq->iocb.un.ulpWord[4] =
  2162. IOERR_SLI_ABORTED;
  2163. spin_lock_irqsave(
  2164. &phba->hbalock, iflag);
  2165. saveq->iocb_flag |=
  2166. LPFC_DELAY_MEM_FREE;
  2167. spin_unlock_irqrestore(
  2168. &phba->hbalock, iflag);
  2169. }
  2170. }
  2171. }
  2172. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2173. } else
  2174. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2175. } else {
  2176. /*
  2177. * Unknown initiating command based on the response iotag.
  2178. * This could be the case on the ELS ring because of
  2179. * lpfc_els_abort().
  2180. */
  2181. if (pring->ringno != LPFC_ELS_RING) {
  2182. /*
  2183. * Ring <ringno> handler: unexpected completion IoTag
  2184. * <IoTag>
  2185. */
  2186. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2187. "0322 Ring %d handler: "
  2188. "unexpected completion IoTag x%x "
  2189. "Data: x%x x%x x%x x%x\n",
  2190. pring->ringno,
  2191. saveq->iocb.ulpIoTag,
  2192. saveq->iocb.ulpStatus,
  2193. saveq->iocb.un.ulpWord[4],
  2194. saveq->iocb.ulpCommand,
  2195. saveq->iocb.ulpContext);
  2196. }
  2197. }
  2198. return rc;
  2199. }
  2200. /**
  2201. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2202. * @phba: Pointer to HBA context object.
  2203. * @pring: Pointer to driver SLI ring object.
  2204. *
  2205. * This function is called from the iocb ring event handlers when
  2206. * put pointer is ahead of the get pointer for a ring. This function signal
  2207. * an error attention condition to the worker thread and the worker
  2208. * thread will transition the HBA to offline state.
  2209. **/
  2210. static void
  2211. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2212. {
  2213. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2214. /*
  2215. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2216. * rsp ring <portRspMax>
  2217. */
  2218. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2219. "0312 Ring %d handler: portRspPut %d "
  2220. "is bigger than rsp ring %d\n",
  2221. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2222. pring->numRiocb);
  2223. phba->link_state = LPFC_HBA_ERROR;
  2224. /*
  2225. * All error attention handlers are posted to
  2226. * worker thread
  2227. */
  2228. phba->work_ha |= HA_ERATT;
  2229. phba->work_hs = HS_FFER3;
  2230. lpfc_worker_wake_up(phba);
  2231. return;
  2232. }
  2233. /**
  2234. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2235. * @ptr: Pointer to address of HBA context object.
  2236. *
  2237. * This function is invoked by the Error Attention polling timer when the
  2238. * timer times out. It will check the SLI Error Attention register for
  2239. * possible attention events. If so, it will post an Error Attention event
  2240. * and wake up worker thread to process it. Otherwise, it will set up the
  2241. * Error Attention polling timer for the next poll.
  2242. **/
  2243. void lpfc_poll_eratt(unsigned long ptr)
  2244. {
  2245. struct lpfc_hba *phba;
  2246. uint32_t eratt = 0;
  2247. phba = (struct lpfc_hba *)ptr;
  2248. /* Check chip HA register for error event */
  2249. eratt = lpfc_sli_check_eratt(phba);
  2250. if (eratt)
  2251. /* Tell the worker thread there is work to do */
  2252. lpfc_worker_wake_up(phba);
  2253. else
  2254. /* Restart the timer for next eratt poll */
  2255. mod_timer(&phba->eratt_poll, jiffies +
  2256. HZ * LPFC_ERATT_POLL_INTERVAL);
  2257. return;
  2258. }
  2259. /**
  2260. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2261. * @phba: Pointer to HBA context object.
  2262. * @pring: Pointer to driver SLI ring object.
  2263. * @mask: Host attention register mask for this ring.
  2264. *
  2265. * This function is called from the interrupt context when there is a ring
  2266. * event for the fcp ring. The caller does not hold any lock.
  2267. * The function processes each response iocb in the response ring until it
  2268. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2269. * LE bit set. The function will call the completion handler of the command iocb
  2270. * if the response iocb indicates a completion for a command iocb or it is
  2271. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2272. * function if this is an unsolicited iocb.
  2273. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2274. * to check it explicitly.
  2275. */
  2276. int
  2277. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2278. struct lpfc_sli_ring *pring, uint32_t mask)
  2279. {
  2280. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2281. IOCB_t *irsp = NULL;
  2282. IOCB_t *entry = NULL;
  2283. struct lpfc_iocbq *cmdiocbq = NULL;
  2284. struct lpfc_iocbq rspiocbq;
  2285. uint32_t status;
  2286. uint32_t portRspPut, portRspMax;
  2287. int rc = 1;
  2288. lpfc_iocb_type type;
  2289. unsigned long iflag;
  2290. uint32_t rsp_cmpl = 0;
  2291. spin_lock_irqsave(&phba->hbalock, iflag);
  2292. pring->stats.iocb_event++;
  2293. /*
  2294. * The next available response entry should never exceed the maximum
  2295. * entries. If it does, treat it as an adapter hardware error.
  2296. */
  2297. portRspMax = pring->numRiocb;
  2298. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2299. if (unlikely(portRspPut >= portRspMax)) {
  2300. lpfc_sli_rsp_pointers_error(phba, pring);
  2301. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2302. return 1;
  2303. }
  2304. if (phba->fcp_ring_in_use) {
  2305. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2306. return 1;
  2307. } else
  2308. phba->fcp_ring_in_use = 1;
  2309. rmb();
  2310. while (pring->rspidx != portRspPut) {
  2311. /*
  2312. * Fetch an entry off the ring and copy it into a local data
  2313. * structure. The copy involves a byte-swap since the
  2314. * network byte order and pci byte orders are different.
  2315. */
  2316. entry = lpfc_resp_iocb(phba, pring);
  2317. phba->last_completion_time = jiffies;
  2318. if (++pring->rspidx >= portRspMax)
  2319. pring->rspidx = 0;
  2320. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2321. (uint32_t *) &rspiocbq.iocb,
  2322. phba->iocb_rsp_size);
  2323. INIT_LIST_HEAD(&(rspiocbq.list));
  2324. irsp = &rspiocbq.iocb;
  2325. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2326. pring->stats.iocb_rsp++;
  2327. rsp_cmpl++;
  2328. if (unlikely(irsp->ulpStatus)) {
  2329. /*
  2330. * If resource errors reported from HBA, reduce
  2331. * queuedepths of the SCSI device.
  2332. */
  2333. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2334. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2336. phba->lpfc_rampdown_queue_depth(phba);
  2337. spin_lock_irqsave(&phba->hbalock, iflag);
  2338. }
  2339. /* Rsp ring <ringno> error: IOCB */
  2340. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2341. "0336 Rsp Ring %d error: IOCB Data: "
  2342. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2343. pring->ringno,
  2344. irsp->un.ulpWord[0],
  2345. irsp->un.ulpWord[1],
  2346. irsp->un.ulpWord[2],
  2347. irsp->un.ulpWord[3],
  2348. irsp->un.ulpWord[4],
  2349. irsp->un.ulpWord[5],
  2350. *(uint32_t *)&irsp->un1,
  2351. *((uint32_t *)&irsp->un1 + 1));
  2352. }
  2353. switch (type) {
  2354. case LPFC_ABORT_IOCB:
  2355. case LPFC_SOL_IOCB:
  2356. /*
  2357. * Idle exchange closed via ABTS from port. No iocb
  2358. * resources need to be recovered.
  2359. */
  2360. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2361. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2362. "0333 IOCB cmd 0x%x"
  2363. " processed. Skipping"
  2364. " completion\n",
  2365. irsp->ulpCommand);
  2366. break;
  2367. }
  2368. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2369. &rspiocbq);
  2370. if (unlikely(!cmdiocbq))
  2371. break;
  2372. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2373. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2374. if (cmdiocbq->iocb_cmpl) {
  2375. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2376. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2377. &rspiocbq);
  2378. spin_lock_irqsave(&phba->hbalock, iflag);
  2379. }
  2380. break;
  2381. case LPFC_UNSOL_IOCB:
  2382. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2383. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2384. spin_lock_irqsave(&phba->hbalock, iflag);
  2385. break;
  2386. default:
  2387. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2388. char adaptermsg[LPFC_MAX_ADPTMSG];
  2389. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2390. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2391. MAX_MSG_DATA);
  2392. dev_warn(&((phba->pcidev)->dev),
  2393. "lpfc%d: %s\n",
  2394. phba->brd_no, adaptermsg);
  2395. } else {
  2396. /* Unknown IOCB command */
  2397. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2398. "0334 Unknown IOCB command "
  2399. "Data: x%x, x%x x%x x%x x%x\n",
  2400. type, irsp->ulpCommand,
  2401. irsp->ulpStatus,
  2402. irsp->ulpIoTag,
  2403. irsp->ulpContext);
  2404. }
  2405. break;
  2406. }
  2407. /*
  2408. * The response IOCB has been processed. Update the ring
  2409. * pointer in SLIM. If the port response put pointer has not
  2410. * been updated, sync the pgp->rspPutInx and fetch the new port
  2411. * response put pointer.
  2412. */
  2413. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2414. if (pring->rspidx == portRspPut)
  2415. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2416. }
  2417. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2418. pring->stats.iocb_rsp_full++;
  2419. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2420. writel(status, phba->CAregaddr);
  2421. readl(phba->CAregaddr);
  2422. }
  2423. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2424. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2425. pring->stats.iocb_cmd_empty++;
  2426. /* Force update of the local copy of cmdGetInx */
  2427. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2428. lpfc_sli_resume_iocb(phba, pring);
  2429. if ((pring->lpfc_sli_cmd_available))
  2430. (pring->lpfc_sli_cmd_available) (phba, pring);
  2431. }
  2432. phba->fcp_ring_in_use = 0;
  2433. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2434. return rc;
  2435. }
  2436. /**
  2437. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2438. * @phba: Pointer to HBA context object.
  2439. * @pring: Pointer to driver SLI ring object.
  2440. * @rspiocbp: Pointer to driver response IOCB object.
  2441. *
  2442. * This function is called from the worker thread when there is a slow-path
  2443. * response IOCB to process. This function chains all the response iocbs until
  2444. * seeing the iocb with the LE bit set. The function will call
  2445. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2446. * completion of a command iocb. The function will call the
  2447. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2448. * The function frees the resources or calls the completion handler if this
  2449. * iocb is an abort completion. The function returns NULL when the response
  2450. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2451. * this function shall chain the iocb on to the iocb_continueq and return the
  2452. * response iocb passed in.
  2453. **/
  2454. static struct lpfc_iocbq *
  2455. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2456. struct lpfc_iocbq *rspiocbp)
  2457. {
  2458. struct lpfc_iocbq *saveq;
  2459. struct lpfc_iocbq *cmdiocbp;
  2460. struct lpfc_iocbq *next_iocb;
  2461. IOCB_t *irsp = NULL;
  2462. uint32_t free_saveq;
  2463. uint8_t iocb_cmd_type;
  2464. lpfc_iocb_type type;
  2465. unsigned long iflag;
  2466. int rc;
  2467. spin_lock_irqsave(&phba->hbalock, iflag);
  2468. /* First add the response iocb to the countinueq list */
  2469. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2470. pring->iocb_continueq_cnt++;
  2471. /* Now, determine whetehr the list is completed for processing */
  2472. irsp = &rspiocbp->iocb;
  2473. if (irsp->ulpLe) {
  2474. /*
  2475. * By default, the driver expects to free all resources
  2476. * associated with this iocb completion.
  2477. */
  2478. free_saveq = 1;
  2479. saveq = list_get_first(&pring->iocb_continueq,
  2480. struct lpfc_iocbq, list);
  2481. irsp = &(saveq->iocb);
  2482. list_del_init(&pring->iocb_continueq);
  2483. pring->iocb_continueq_cnt = 0;
  2484. pring->stats.iocb_rsp++;
  2485. /*
  2486. * If resource errors reported from HBA, reduce
  2487. * queuedepths of the SCSI device.
  2488. */
  2489. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2490. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2491. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2492. phba->lpfc_rampdown_queue_depth(phba);
  2493. spin_lock_irqsave(&phba->hbalock, iflag);
  2494. }
  2495. if (irsp->ulpStatus) {
  2496. /* Rsp ring <ringno> error: IOCB */
  2497. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2498. "0328 Rsp Ring %d error: "
  2499. "IOCB Data: "
  2500. "x%x x%x x%x x%x "
  2501. "x%x x%x x%x x%x "
  2502. "x%x x%x x%x x%x "
  2503. "x%x x%x x%x x%x\n",
  2504. pring->ringno,
  2505. irsp->un.ulpWord[0],
  2506. irsp->un.ulpWord[1],
  2507. irsp->un.ulpWord[2],
  2508. irsp->un.ulpWord[3],
  2509. irsp->un.ulpWord[4],
  2510. irsp->un.ulpWord[5],
  2511. *(((uint32_t *) irsp) + 6),
  2512. *(((uint32_t *) irsp) + 7),
  2513. *(((uint32_t *) irsp) + 8),
  2514. *(((uint32_t *) irsp) + 9),
  2515. *(((uint32_t *) irsp) + 10),
  2516. *(((uint32_t *) irsp) + 11),
  2517. *(((uint32_t *) irsp) + 12),
  2518. *(((uint32_t *) irsp) + 13),
  2519. *(((uint32_t *) irsp) + 14),
  2520. *(((uint32_t *) irsp) + 15));
  2521. }
  2522. /*
  2523. * Fetch the IOCB command type and call the correct completion
  2524. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2525. * get freed back to the lpfc_iocb_list by the discovery
  2526. * kernel thread.
  2527. */
  2528. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2529. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2530. switch (type) {
  2531. case LPFC_SOL_IOCB:
  2532. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2533. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2534. spin_lock_irqsave(&phba->hbalock, iflag);
  2535. break;
  2536. case LPFC_UNSOL_IOCB:
  2537. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2538. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2539. spin_lock_irqsave(&phba->hbalock, iflag);
  2540. if (!rc)
  2541. free_saveq = 0;
  2542. break;
  2543. case LPFC_ABORT_IOCB:
  2544. cmdiocbp = NULL;
  2545. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2546. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2547. saveq);
  2548. if (cmdiocbp) {
  2549. /* Call the specified completion routine */
  2550. if (cmdiocbp->iocb_cmpl) {
  2551. spin_unlock_irqrestore(&phba->hbalock,
  2552. iflag);
  2553. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2554. saveq);
  2555. spin_lock_irqsave(&phba->hbalock,
  2556. iflag);
  2557. } else
  2558. __lpfc_sli_release_iocbq(phba,
  2559. cmdiocbp);
  2560. }
  2561. break;
  2562. case LPFC_UNKNOWN_IOCB:
  2563. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2564. char adaptermsg[LPFC_MAX_ADPTMSG];
  2565. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2566. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2567. MAX_MSG_DATA);
  2568. dev_warn(&((phba->pcidev)->dev),
  2569. "lpfc%d: %s\n",
  2570. phba->brd_no, adaptermsg);
  2571. } else {
  2572. /* Unknown IOCB command */
  2573. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2574. "0335 Unknown IOCB "
  2575. "command Data: x%x "
  2576. "x%x x%x x%x\n",
  2577. irsp->ulpCommand,
  2578. irsp->ulpStatus,
  2579. irsp->ulpIoTag,
  2580. irsp->ulpContext);
  2581. }
  2582. break;
  2583. }
  2584. if (free_saveq) {
  2585. list_for_each_entry_safe(rspiocbp, next_iocb,
  2586. &saveq->list, list) {
  2587. list_del(&rspiocbp->list);
  2588. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2589. }
  2590. __lpfc_sli_release_iocbq(phba, saveq);
  2591. }
  2592. rspiocbp = NULL;
  2593. }
  2594. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2595. return rspiocbp;
  2596. }
  2597. /**
  2598. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2599. * @phba: Pointer to HBA context object.
  2600. * @pring: Pointer to driver SLI ring object.
  2601. * @mask: Host attention register mask for this ring.
  2602. *
  2603. * This routine wraps the actual slow_ring event process routine from the
  2604. * API jump table function pointer from the lpfc_hba struct.
  2605. **/
  2606. void
  2607. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2608. struct lpfc_sli_ring *pring, uint32_t mask)
  2609. {
  2610. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2611. }
  2612. /**
  2613. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2614. * @phba: Pointer to HBA context object.
  2615. * @pring: Pointer to driver SLI ring object.
  2616. * @mask: Host attention register mask for this ring.
  2617. *
  2618. * This function is called from the worker thread when there is a ring event
  2619. * for non-fcp rings. The caller does not hold any lock. The function will
  2620. * remove each response iocb in the response ring and calls the handle
  2621. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2622. **/
  2623. static void
  2624. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2625. struct lpfc_sli_ring *pring, uint32_t mask)
  2626. {
  2627. struct lpfc_pgp *pgp;
  2628. IOCB_t *entry;
  2629. IOCB_t *irsp = NULL;
  2630. struct lpfc_iocbq *rspiocbp = NULL;
  2631. uint32_t portRspPut, portRspMax;
  2632. unsigned long iflag;
  2633. uint32_t status;
  2634. pgp = &phba->port_gp[pring->ringno];
  2635. spin_lock_irqsave(&phba->hbalock, iflag);
  2636. pring->stats.iocb_event++;
  2637. /*
  2638. * The next available response entry should never exceed the maximum
  2639. * entries. If it does, treat it as an adapter hardware error.
  2640. */
  2641. portRspMax = pring->numRiocb;
  2642. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2643. if (portRspPut >= portRspMax) {
  2644. /*
  2645. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2646. * rsp ring <portRspMax>
  2647. */
  2648. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2649. "0303 Ring %d handler: portRspPut %d "
  2650. "is bigger than rsp ring %d\n",
  2651. pring->ringno, portRspPut, portRspMax);
  2652. phba->link_state = LPFC_HBA_ERROR;
  2653. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2654. phba->work_hs = HS_FFER3;
  2655. lpfc_handle_eratt(phba);
  2656. return;
  2657. }
  2658. rmb();
  2659. while (pring->rspidx != portRspPut) {
  2660. /*
  2661. * Build a completion list and call the appropriate handler.
  2662. * The process is to get the next available response iocb, get
  2663. * a free iocb from the list, copy the response data into the
  2664. * free iocb, insert to the continuation list, and update the
  2665. * next response index to slim. This process makes response
  2666. * iocb's in the ring available to DMA as fast as possible but
  2667. * pays a penalty for a copy operation. Since the iocb is
  2668. * only 32 bytes, this penalty is considered small relative to
  2669. * the PCI reads for register values and a slim write. When
  2670. * the ulpLe field is set, the entire Command has been
  2671. * received.
  2672. */
  2673. entry = lpfc_resp_iocb(phba, pring);
  2674. phba->last_completion_time = jiffies;
  2675. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2676. if (rspiocbp == NULL) {
  2677. printk(KERN_ERR "%s: out of buffers! Failing "
  2678. "completion.\n", __func__);
  2679. break;
  2680. }
  2681. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2682. phba->iocb_rsp_size);
  2683. irsp = &rspiocbp->iocb;
  2684. if (++pring->rspidx >= portRspMax)
  2685. pring->rspidx = 0;
  2686. if (pring->ringno == LPFC_ELS_RING) {
  2687. lpfc_debugfs_slow_ring_trc(phba,
  2688. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2689. *(((uint32_t *) irsp) + 4),
  2690. *(((uint32_t *) irsp) + 6),
  2691. *(((uint32_t *) irsp) + 7));
  2692. }
  2693. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2694. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2695. /* Handle the response IOCB */
  2696. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2697. spin_lock_irqsave(&phba->hbalock, iflag);
  2698. /*
  2699. * If the port response put pointer has not been updated, sync
  2700. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2701. * response put pointer.
  2702. */
  2703. if (pring->rspidx == portRspPut) {
  2704. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2705. }
  2706. } /* while (pring->rspidx != portRspPut) */
  2707. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2708. /* At least one response entry has been freed */
  2709. pring->stats.iocb_rsp_full++;
  2710. /* SET RxRE_RSP in Chip Att register */
  2711. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2712. writel(status, phba->CAregaddr);
  2713. readl(phba->CAregaddr); /* flush */
  2714. }
  2715. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2716. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2717. pring->stats.iocb_cmd_empty++;
  2718. /* Force update of the local copy of cmdGetInx */
  2719. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2720. lpfc_sli_resume_iocb(phba, pring);
  2721. if ((pring->lpfc_sli_cmd_available))
  2722. (pring->lpfc_sli_cmd_available) (phba, pring);
  2723. }
  2724. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2725. return;
  2726. }
  2727. /**
  2728. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2729. * @phba: Pointer to HBA context object.
  2730. * @pring: Pointer to driver SLI ring object.
  2731. * @mask: Host attention register mask for this ring.
  2732. *
  2733. * This function is called from the worker thread when there is a pending
  2734. * ELS response iocb on the driver internal slow-path response iocb worker
  2735. * queue. The caller does not hold any lock. The function will remove each
  2736. * response iocb from the response worker queue and calls the handle
  2737. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2738. **/
  2739. static void
  2740. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2741. struct lpfc_sli_ring *pring, uint32_t mask)
  2742. {
  2743. struct lpfc_iocbq *irspiocbq;
  2744. struct hbq_dmabuf *dmabuf;
  2745. struct lpfc_cq_event *cq_event;
  2746. unsigned long iflag;
  2747. spin_lock_irqsave(&phba->hbalock, iflag);
  2748. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  2749. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2750. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  2751. /* Get the response iocb from the head of work queue */
  2752. spin_lock_irqsave(&phba->hbalock, iflag);
  2753. list_remove_head(&phba->sli4_hba.sp_queue_event,
  2754. cq_event, struct lpfc_cq_event, list);
  2755. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2756. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  2757. case CQE_CODE_COMPL_WQE:
  2758. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  2759. cq_event);
  2760. /* Translate ELS WCQE to response IOCBQ */
  2761. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  2762. irspiocbq);
  2763. if (irspiocbq)
  2764. lpfc_sli_sp_handle_rspiocb(phba, pring,
  2765. irspiocbq);
  2766. break;
  2767. case CQE_CODE_RECEIVE:
  2768. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  2769. cq_event);
  2770. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  2771. break;
  2772. default:
  2773. break;
  2774. }
  2775. }
  2776. }
  2777. /**
  2778. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2779. * @phba: Pointer to HBA context object.
  2780. * @pring: Pointer to driver SLI ring object.
  2781. *
  2782. * This function aborts all iocbs in the given ring and frees all the iocb
  2783. * objects in txq. This function issues an abort iocb for all the iocb commands
  2784. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2785. * the return of this function. The caller is not required to hold any locks.
  2786. **/
  2787. void
  2788. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2789. {
  2790. LIST_HEAD(completions);
  2791. struct lpfc_iocbq *iocb, *next_iocb;
  2792. if (pring->ringno == LPFC_ELS_RING) {
  2793. lpfc_fabric_abort_hba(phba);
  2794. }
  2795. /* Error everything on txq and txcmplq
  2796. * First do the txq.
  2797. */
  2798. spin_lock_irq(&phba->hbalock);
  2799. list_splice_init(&pring->txq, &completions);
  2800. pring->txq_cnt = 0;
  2801. /* Next issue ABTS for everything on the txcmplq */
  2802. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2803. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2804. spin_unlock_irq(&phba->hbalock);
  2805. /* Cancel all the IOCBs from the completions list */
  2806. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2807. IOERR_SLI_ABORTED);
  2808. }
  2809. /**
  2810. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2811. * @phba: Pointer to HBA context object.
  2812. *
  2813. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2814. * objects in txq and txcmplq. This function will not issue abort iocbs
  2815. * for all the iocb commands in txcmplq, they will just be returned with
  2816. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2817. * slot has been permanently disabled.
  2818. **/
  2819. void
  2820. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2821. {
  2822. LIST_HEAD(txq);
  2823. LIST_HEAD(txcmplq);
  2824. struct lpfc_sli *psli = &phba->sli;
  2825. struct lpfc_sli_ring *pring;
  2826. /* Currently, only one fcp ring */
  2827. pring = &psli->ring[psli->fcp_ring];
  2828. spin_lock_irq(&phba->hbalock);
  2829. /* Retrieve everything on txq */
  2830. list_splice_init(&pring->txq, &txq);
  2831. pring->txq_cnt = 0;
  2832. /* Retrieve everything on the txcmplq */
  2833. list_splice_init(&pring->txcmplq, &txcmplq);
  2834. pring->txcmplq_cnt = 0;
  2835. spin_unlock_irq(&phba->hbalock);
  2836. /* Flush the txq */
  2837. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2838. IOERR_SLI_DOWN);
  2839. /* Flush the txcmpq */
  2840. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2841. IOERR_SLI_DOWN);
  2842. }
  2843. /**
  2844. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2845. * @phba: Pointer to HBA context object.
  2846. * @mask: Bit mask to be checked.
  2847. *
  2848. * This function reads the host status register and compares
  2849. * with the provided bit mask to check if HBA completed
  2850. * the restart. This function will wait in a loop for the
  2851. * HBA to complete restart. If the HBA does not restart within
  2852. * 15 iterations, the function will reset the HBA again. The
  2853. * function returns 1 when HBA fail to restart otherwise returns
  2854. * zero.
  2855. **/
  2856. static int
  2857. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2858. {
  2859. uint32_t status;
  2860. int i = 0;
  2861. int retval = 0;
  2862. /* Read the HBA Host Status Register */
  2863. status = readl(phba->HSregaddr);
  2864. /*
  2865. * Check status register every 100ms for 5 retries, then every
  2866. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2867. * every 2.5 sec for 4.
  2868. * Break our of the loop if errors occurred during init.
  2869. */
  2870. while (((status & mask) != mask) &&
  2871. !(status & HS_FFERM) &&
  2872. i++ < 20) {
  2873. if (i <= 5)
  2874. msleep(10);
  2875. else if (i <= 10)
  2876. msleep(500);
  2877. else
  2878. msleep(2500);
  2879. if (i == 15) {
  2880. /* Do post */
  2881. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2882. lpfc_sli_brdrestart(phba);
  2883. }
  2884. /* Read the HBA Host Status Register */
  2885. status = readl(phba->HSregaddr);
  2886. }
  2887. /* Check to see if any errors occurred during init */
  2888. if ((status & HS_FFERM) || (i >= 20)) {
  2889. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2890. "2751 Adapter failed to restart, "
  2891. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  2892. status,
  2893. readl(phba->MBslimaddr + 0xa8),
  2894. readl(phba->MBslimaddr + 0xac));
  2895. phba->link_state = LPFC_HBA_ERROR;
  2896. retval = 1;
  2897. }
  2898. return retval;
  2899. }
  2900. /**
  2901. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2902. * @phba: Pointer to HBA context object.
  2903. * @mask: Bit mask to be checked.
  2904. *
  2905. * This function checks the host status register to check if HBA is
  2906. * ready. This function will wait in a loop for the HBA to be ready
  2907. * If the HBA is not ready , the function will will reset the HBA PCI
  2908. * function again. The function returns 1 when HBA fail to be ready
  2909. * otherwise returns zero.
  2910. **/
  2911. static int
  2912. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2913. {
  2914. uint32_t status;
  2915. int retval = 0;
  2916. /* Read the HBA Host Status Register */
  2917. status = lpfc_sli4_post_status_check(phba);
  2918. if (status) {
  2919. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2920. lpfc_sli_brdrestart(phba);
  2921. status = lpfc_sli4_post_status_check(phba);
  2922. }
  2923. /* Check to see if any errors occurred during init */
  2924. if (status) {
  2925. phba->link_state = LPFC_HBA_ERROR;
  2926. retval = 1;
  2927. } else
  2928. phba->sli4_hba.intr_enable = 0;
  2929. return retval;
  2930. }
  2931. /**
  2932. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2933. * @phba: Pointer to HBA context object.
  2934. * @mask: Bit mask to be checked.
  2935. *
  2936. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2937. * from the API jump table function pointer from the lpfc_hba struct.
  2938. **/
  2939. int
  2940. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2941. {
  2942. return phba->lpfc_sli_brdready(phba, mask);
  2943. }
  2944. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2945. /**
  2946. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2947. * @phba: Pointer to HBA context object.
  2948. *
  2949. * This function is called before resetting an HBA. This
  2950. * function requests HBA to quiesce DMAs before a reset.
  2951. **/
  2952. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2953. {
  2954. uint32_t __iomem *resp_buf;
  2955. uint32_t __iomem *mbox_buf;
  2956. volatile uint32_t mbox;
  2957. uint32_t hc_copy;
  2958. int i;
  2959. uint8_t hdrtype;
  2960. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2961. if (hdrtype != 0x80 ||
  2962. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2963. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2964. return;
  2965. /*
  2966. * Tell the other part of the chip to suspend temporarily all
  2967. * its DMA activity.
  2968. */
  2969. resp_buf = phba->MBslimaddr;
  2970. /* Disable the error attention */
  2971. hc_copy = readl(phba->HCregaddr);
  2972. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2973. readl(phba->HCregaddr); /* flush */
  2974. phba->link_flag |= LS_IGNORE_ERATT;
  2975. if (readl(phba->HAregaddr) & HA_ERATT) {
  2976. /* Clear Chip error bit */
  2977. writel(HA_ERATT, phba->HAregaddr);
  2978. phba->pport->stopped = 1;
  2979. }
  2980. mbox = 0;
  2981. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2982. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2983. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2984. mbox_buf = phba->MBslimaddr;
  2985. writel(mbox, mbox_buf);
  2986. for (i = 0;
  2987. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2988. mdelay(1);
  2989. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2990. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2991. phba->pport->stopped)
  2992. goto restore_hc;
  2993. else
  2994. goto clear_errat;
  2995. }
  2996. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2997. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2998. mdelay(1);
  2999. clear_errat:
  3000. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  3001. mdelay(1);
  3002. if (readl(phba->HAregaddr) & HA_ERATT) {
  3003. writel(HA_ERATT, phba->HAregaddr);
  3004. phba->pport->stopped = 1;
  3005. }
  3006. restore_hc:
  3007. phba->link_flag &= ~LS_IGNORE_ERATT;
  3008. writel(hc_copy, phba->HCregaddr);
  3009. readl(phba->HCregaddr); /* flush */
  3010. }
  3011. /**
  3012. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3013. * @phba: Pointer to HBA context object.
  3014. *
  3015. * This function issues a kill_board mailbox command and waits for
  3016. * the error attention interrupt. This function is called for stopping
  3017. * the firmware processing. The caller is not required to hold any
  3018. * locks. This function calls lpfc_hba_down_post function to free
  3019. * any pending commands after the kill. The function will return 1 when it
  3020. * fails to kill the board else will return 0.
  3021. **/
  3022. int
  3023. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3024. {
  3025. struct lpfc_sli *psli;
  3026. LPFC_MBOXQ_t *pmb;
  3027. uint32_t status;
  3028. uint32_t ha_copy;
  3029. int retval;
  3030. int i = 0;
  3031. psli = &phba->sli;
  3032. /* Kill HBA */
  3033. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3034. "0329 Kill HBA Data: x%x x%x\n",
  3035. phba->pport->port_state, psli->sli_flag);
  3036. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3037. if (!pmb)
  3038. return 1;
  3039. /* Disable the error attention */
  3040. spin_lock_irq(&phba->hbalock);
  3041. status = readl(phba->HCregaddr);
  3042. status &= ~HC_ERINT_ENA;
  3043. writel(status, phba->HCregaddr);
  3044. readl(phba->HCregaddr); /* flush */
  3045. phba->link_flag |= LS_IGNORE_ERATT;
  3046. spin_unlock_irq(&phba->hbalock);
  3047. lpfc_kill_board(phba, pmb);
  3048. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3049. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3050. if (retval != MBX_SUCCESS) {
  3051. if (retval != MBX_BUSY)
  3052. mempool_free(pmb, phba->mbox_mem_pool);
  3053. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3054. "2752 KILL_BOARD command failed retval %d\n",
  3055. retval);
  3056. spin_lock_irq(&phba->hbalock);
  3057. phba->link_flag &= ~LS_IGNORE_ERATT;
  3058. spin_unlock_irq(&phba->hbalock);
  3059. return 1;
  3060. }
  3061. spin_lock_irq(&phba->hbalock);
  3062. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3063. spin_unlock_irq(&phba->hbalock);
  3064. mempool_free(pmb, phba->mbox_mem_pool);
  3065. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3066. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3067. * 3 seconds we still set HBA_ERROR state because the status of the
  3068. * board is now undefined.
  3069. */
  3070. ha_copy = readl(phba->HAregaddr);
  3071. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3072. mdelay(100);
  3073. ha_copy = readl(phba->HAregaddr);
  3074. }
  3075. del_timer_sync(&psli->mbox_tmo);
  3076. if (ha_copy & HA_ERATT) {
  3077. writel(HA_ERATT, phba->HAregaddr);
  3078. phba->pport->stopped = 1;
  3079. }
  3080. spin_lock_irq(&phba->hbalock);
  3081. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3082. psli->mbox_active = NULL;
  3083. phba->link_flag &= ~LS_IGNORE_ERATT;
  3084. spin_unlock_irq(&phba->hbalock);
  3085. lpfc_hba_down_post(phba);
  3086. phba->link_state = LPFC_HBA_ERROR;
  3087. return ha_copy & HA_ERATT ? 0 : 1;
  3088. }
  3089. /**
  3090. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3091. * @phba: Pointer to HBA context object.
  3092. *
  3093. * This function resets the HBA by writing HC_INITFF to the control
  3094. * register. After the HBA resets, this function resets all the iocb ring
  3095. * indices. This function disables PCI layer parity checking during
  3096. * the reset.
  3097. * This function returns 0 always.
  3098. * The caller is not required to hold any locks.
  3099. **/
  3100. int
  3101. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3102. {
  3103. struct lpfc_sli *psli;
  3104. struct lpfc_sli_ring *pring;
  3105. uint16_t cfg_value;
  3106. int i;
  3107. psli = &phba->sli;
  3108. /* Reset HBA */
  3109. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3110. "0325 Reset HBA Data: x%x x%x\n",
  3111. phba->pport->port_state, psli->sli_flag);
  3112. /* perform board reset */
  3113. phba->fc_eventTag = 0;
  3114. phba->link_events = 0;
  3115. phba->pport->fc_myDID = 0;
  3116. phba->pport->fc_prevDID = 0;
  3117. /* Turn off parity checking and serr during the physical reset */
  3118. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3119. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3120. (cfg_value &
  3121. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3122. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3123. /* Now toggle INITFF bit in the Host Control Register */
  3124. writel(HC_INITFF, phba->HCregaddr);
  3125. mdelay(1);
  3126. readl(phba->HCregaddr); /* flush */
  3127. writel(0, phba->HCregaddr);
  3128. readl(phba->HCregaddr); /* flush */
  3129. /* Restore PCI cmd register */
  3130. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3131. /* Initialize relevant SLI info */
  3132. for (i = 0; i < psli->num_rings; i++) {
  3133. pring = &psli->ring[i];
  3134. pring->flag = 0;
  3135. pring->rspidx = 0;
  3136. pring->next_cmdidx = 0;
  3137. pring->local_getidx = 0;
  3138. pring->cmdidx = 0;
  3139. pring->missbufcnt = 0;
  3140. }
  3141. phba->link_state = LPFC_WARM_START;
  3142. return 0;
  3143. }
  3144. /**
  3145. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3146. * @phba: Pointer to HBA context object.
  3147. *
  3148. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3149. * checking during resets the device. The caller is not required to hold
  3150. * any locks.
  3151. *
  3152. * This function returns 0 always.
  3153. **/
  3154. int
  3155. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3156. {
  3157. struct lpfc_sli *psli = &phba->sli;
  3158. uint16_t cfg_value;
  3159. uint8_t qindx;
  3160. /* Reset HBA */
  3161. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3162. "0295 Reset HBA Data: x%x x%x\n",
  3163. phba->pport->port_state, psli->sli_flag);
  3164. /* perform board reset */
  3165. phba->fc_eventTag = 0;
  3166. phba->link_events = 0;
  3167. phba->pport->fc_myDID = 0;
  3168. phba->pport->fc_prevDID = 0;
  3169. /* Turn off parity checking and serr during the physical reset */
  3170. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3171. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3172. (cfg_value &
  3173. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3174. spin_lock_irq(&phba->hbalock);
  3175. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3176. phba->fcf.fcf_flag = 0;
  3177. /* Clean up the child queue list for the CQs */
  3178. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3179. list_del_init(&phba->sli4_hba.els_wq->list);
  3180. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3181. list_del_init(&phba->sli4_hba.dat_rq->list);
  3182. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3183. list_del_init(&phba->sli4_hba.els_cq->list);
  3184. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3185. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3186. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3187. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3188. spin_unlock_irq(&phba->hbalock);
  3189. /* Now physically reset the device */
  3190. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3191. "0389 Performing PCI function reset!\n");
  3192. /* Perform FCoE PCI function reset */
  3193. lpfc_pci_function_reset(phba);
  3194. return 0;
  3195. }
  3196. /**
  3197. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3198. * @phba: Pointer to HBA context object.
  3199. *
  3200. * This function is called in the SLI initialization code path to
  3201. * restart the HBA. The caller is not required to hold any lock.
  3202. * This function writes MBX_RESTART mailbox command to the SLIM and
  3203. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3204. * function to free any pending commands. The function enables
  3205. * POST only during the first initialization. The function returns zero.
  3206. * The function does not guarantee completion of MBX_RESTART mailbox
  3207. * command before the return of this function.
  3208. **/
  3209. static int
  3210. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3211. {
  3212. MAILBOX_t *mb;
  3213. struct lpfc_sli *psli;
  3214. volatile uint32_t word0;
  3215. void __iomem *to_slim;
  3216. uint32_t hba_aer_enabled;
  3217. spin_lock_irq(&phba->hbalock);
  3218. /* Take PCIe device Advanced Error Reporting (AER) state */
  3219. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3220. psli = &phba->sli;
  3221. /* Restart HBA */
  3222. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3223. "0337 Restart HBA Data: x%x x%x\n",
  3224. phba->pport->port_state, psli->sli_flag);
  3225. word0 = 0;
  3226. mb = (MAILBOX_t *) &word0;
  3227. mb->mbxCommand = MBX_RESTART;
  3228. mb->mbxHc = 1;
  3229. lpfc_reset_barrier(phba);
  3230. to_slim = phba->MBslimaddr;
  3231. writel(*(uint32_t *) mb, to_slim);
  3232. readl(to_slim); /* flush */
  3233. /* Only skip post after fc_ffinit is completed */
  3234. if (phba->pport->port_state)
  3235. word0 = 1; /* This is really setting up word1 */
  3236. else
  3237. word0 = 0; /* This is really setting up word1 */
  3238. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3239. writel(*(uint32_t *) mb, to_slim);
  3240. readl(to_slim); /* flush */
  3241. lpfc_sli_brdreset(phba);
  3242. phba->pport->stopped = 0;
  3243. phba->link_state = LPFC_INIT_START;
  3244. phba->hba_flag = 0;
  3245. spin_unlock_irq(&phba->hbalock);
  3246. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3247. psli->stats_start = get_seconds();
  3248. /* Give the INITFF and Post time to settle. */
  3249. mdelay(100);
  3250. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3251. if (hba_aer_enabled)
  3252. pci_disable_pcie_error_reporting(phba->pcidev);
  3253. lpfc_hba_down_post(phba);
  3254. return 0;
  3255. }
  3256. /**
  3257. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3258. * @phba: Pointer to HBA context object.
  3259. *
  3260. * This function is called in the SLI initialization code path to restart
  3261. * a SLI4 HBA. The caller is not required to hold any lock.
  3262. * At the end of the function, it calls lpfc_hba_down_post function to
  3263. * free any pending commands.
  3264. **/
  3265. static int
  3266. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3267. {
  3268. struct lpfc_sli *psli = &phba->sli;
  3269. uint32_t hba_aer_enabled;
  3270. /* Restart HBA */
  3271. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3272. "0296 Restart HBA Data: x%x x%x\n",
  3273. phba->pport->port_state, psli->sli_flag);
  3274. /* Take PCIe device Advanced Error Reporting (AER) state */
  3275. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3276. lpfc_sli4_brdreset(phba);
  3277. spin_lock_irq(&phba->hbalock);
  3278. phba->pport->stopped = 0;
  3279. phba->link_state = LPFC_INIT_START;
  3280. phba->hba_flag = 0;
  3281. spin_unlock_irq(&phba->hbalock);
  3282. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3283. psli->stats_start = get_seconds();
  3284. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3285. if (hba_aer_enabled)
  3286. pci_disable_pcie_error_reporting(phba->pcidev);
  3287. lpfc_hba_down_post(phba);
  3288. return 0;
  3289. }
  3290. /**
  3291. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3292. * @phba: Pointer to HBA context object.
  3293. *
  3294. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3295. * API jump table function pointer from the lpfc_hba struct.
  3296. **/
  3297. int
  3298. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3299. {
  3300. return phba->lpfc_sli_brdrestart(phba);
  3301. }
  3302. /**
  3303. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3304. * @phba: Pointer to HBA context object.
  3305. *
  3306. * This function is called after a HBA restart to wait for successful
  3307. * restart of the HBA. Successful restart of the HBA is indicated by
  3308. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3309. * iteration, the function will restart the HBA again. The function returns
  3310. * zero if HBA successfully restarted else returns negative error code.
  3311. **/
  3312. static int
  3313. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3314. {
  3315. uint32_t status, i = 0;
  3316. /* Read the HBA Host Status Register */
  3317. status = readl(phba->HSregaddr);
  3318. /* Check status register to see what current state is */
  3319. i = 0;
  3320. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3321. /* Check every 10ms for 10 retries, then every 100ms for 90
  3322. * retries, then every 1 sec for 50 retires for a total of
  3323. * ~60 seconds before reset the board again and check every
  3324. * 1 sec for 50 retries. The up to 60 seconds before the
  3325. * board ready is required by the Falcon FIPS zeroization
  3326. * complete, and any reset the board in between shall cause
  3327. * restart of zeroization, further delay the board ready.
  3328. */
  3329. if (i++ >= 200) {
  3330. /* Adapter failed to init, timeout, status reg
  3331. <status> */
  3332. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3333. "0436 Adapter failed to init, "
  3334. "timeout, status reg x%x, "
  3335. "FW Data: A8 x%x AC x%x\n", status,
  3336. readl(phba->MBslimaddr + 0xa8),
  3337. readl(phba->MBslimaddr + 0xac));
  3338. phba->link_state = LPFC_HBA_ERROR;
  3339. return -ETIMEDOUT;
  3340. }
  3341. /* Check to see if any errors occurred during init */
  3342. if (status & HS_FFERM) {
  3343. /* ERROR: During chipset initialization */
  3344. /* Adapter failed to init, chipset, status reg
  3345. <status> */
  3346. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3347. "0437 Adapter failed to init, "
  3348. "chipset, status reg x%x, "
  3349. "FW Data: A8 x%x AC x%x\n", status,
  3350. readl(phba->MBslimaddr + 0xa8),
  3351. readl(phba->MBslimaddr + 0xac));
  3352. phba->link_state = LPFC_HBA_ERROR;
  3353. return -EIO;
  3354. }
  3355. if (i <= 10)
  3356. msleep(10);
  3357. else if (i <= 100)
  3358. msleep(100);
  3359. else
  3360. msleep(1000);
  3361. if (i == 150) {
  3362. /* Do post */
  3363. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3364. lpfc_sli_brdrestart(phba);
  3365. }
  3366. /* Read the HBA Host Status Register */
  3367. status = readl(phba->HSregaddr);
  3368. }
  3369. /* Check to see if any errors occurred during init */
  3370. if (status & HS_FFERM) {
  3371. /* ERROR: During chipset initialization */
  3372. /* Adapter failed to init, chipset, status reg <status> */
  3373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3374. "0438 Adapter failed to init, chipset, "
  3375. "status reg x%x, "
  3376. "FW Data: A8 x%x AC x%x\n", status,
  3377. readl(phba->MBslimaddr + 0xa8),
  3378. readl(phba->MBslimaddr + 0xac));
  3379. phba->link_state = LPFC_HBA_ERROR;
  3380. return -EIO;
  3381. }
  3382. /* Clear all interrupt enable conditions */
  3383. writel(0, phba->HCregaddr);
  3384. readl(phba->HCregaddr); /* flush */
  3385. /* setup host attn register */
  3386. writel(0xffffffff, phba->HAregaddr);
  3387. readl(phba->HAregaddr); /* flush */
  3388. return 0;
  3389. }
  3390. /**
  3391. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3392. *
  3393. * This function calculates and returns the number of HBQs required to be
  3394. * configured.
  3395. **/
  3396. int
  3397. lpfc_sli_hbq_count(void)
  3398. {
  3399. return ARRAY_SIZE(lpfc_hbq_defs);
  3400. }
  3401. /**
  3402. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3403. *
  3404. * This function adds the number of hbq entries in every HBQ to get
  3405. * the total number of hbq entries required for the HBA and returns
  3406. * the total count.
  3407. **/
  3408. static int
  3409. lpfc_sli_hbq_entry_count(void)
  3410. {
  3411. int hbq_count = lpfc_sli_hbq_count();
  3412. int count = 0;
  3413. int i;
  3414. for (i = 0; i < hbq_count; ++i)
  3415. count += lpfc_hbq_defs[i]->entry_count;
  3416. return count;
  3417. }
  3418. /**
  3419. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3420. *
  3421. * This function calculates amount of memory required for all hbq entries
  3422. * to be configured and returns the total memory required.
  3423. **/
  3424. int
  3425. lpfc_sli_hbq_size(void)
  3426. {
  3427. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3428. }
  3429. /**
  3430. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3431. * @phba: Pointer to HBA context object.
  3432. *
  3433. * This function is called during the SLI initialization to configure
  3434. * all the HBQs and post buffers to the HBQ. The caller is not
  3435. * required to hold any locks. This function will return zero if successful
  3436. * else it will return negative error code.
  3437. **/
  3438. static int
  3439. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3440. {
  3441. int hbq_count = lpfc_sli_hbq_count();
  3442. LPFC_MBOXQ_t *pmb;
  3443. MAILBOX_t *pmbox;
  3444. uint32_t hbqno;
  3445. uint32_t hbq_entry_index;
  3446. /* Get a Mailbox buffer to setup mailbox
  3447. * commands for HBA initialization
  3448. */
  3449. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3450. if (!pmb)
  3451. return -ENOMEM;
  3452. pmbox = &pmb->u.mb;
  3453. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3454. phba->link_state = LPFC_INIT_MBX_CMDS;
  3455. phba->hbq_in_use = 1;
  3456. hbq_entry_index = 0;
  3457. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3458. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3459. phba->hbqs[hbqno].hbqPutIdx = 0;
  3460. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3461. phba->hbqs[hbqno].entry_count =
  3462. lpfc_hbq_defs[hbqno]->entry_count;
  3463. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3464. hbq_entry_index, pmb);
  3465. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3466. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3467. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3468. mbxStatus <status>, ring <num> */
  3469. lpfc_printf_log(phba, KERN_ERR,
  3470. LOG_SLI | LOG_VPORT,
  3471. "1805 Adapter failed to init. "
  3472. "Data: x%x x%x x%x\n",
  3473. pmbox->mbxCommand,
  3474. pmbox->mbxStatus, hbqno);
  3475. phba->link_state = LPFC_HBA_ERROR;
  3476. mempool_free(pmb, phba->mbox_mem_pool);
  3477. return -ENXIO;
  3478. }
  3479. }
  3480. phba->hbq_count = hbq_count;
  3481. mempool_free(pmb, phba->mbox_mem_pool);
  3482. /* Initially populate or replenish the HBQs */
  3483. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3484. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3485. return 0;
  3486. }
  3487. /**
  3488. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3489. * @phba: Pointer to HBA context object.
  3490. *
  3491. * This function is called during the SLI initialization to configure
  3492. * all the HBQs and post buffers to the HBQ. The caller is not
  3493. * required to hold any locks. This function will return zero if successful
  3494. * else it will return negative error code.
  3495. **/
  3496. static int
  3497. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3498. {
  3499. phba->hbq_in_use = 1;
  3500. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3501. phba->hbq_count = 1;
  3502. /* Initially populate or replenish the HBQs */
  3503. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3504. return 0;
  3505. }
  3506. /**
  3507. * lpfc_sli_config_port - Issue config port mailbox command
  3508. * @phba: Pointer to HBA context object.
  3509. * @sli_mode: sli mode - 2/3
  3510. *
  3511. * This function is called by the sli intialization code path
  3512. * to issue config_port mailbox command. This function restarts the
  3513. * HBA firmware and issues a config_port mailbox command to configure
  3514. * the SLI interface in the sli mode specified by sli_mode
  3515. * variable. The caller is not required to hold any locks.
  3516. * The function returns 0 if successful, else returns negative error
  3517. * code.
  3518. **/
  3519. int
  3520. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3521. {
  3522. LPFC_MBOXQ_t *pmb;
  3523. uint32_t resetcount = 0, rc = 0, done = 0;
  3524. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3525. if (!pmb) {
  3526. phba->link_state = LPFC_HBA_ERROR;
  3527. return -ENOMEM;
  3528. }
  3529. phba->sli_rev = sli_mode;
  3530. while (resetcount < 2 && !done) {
  3531. spin_lock_irq(&phba->hbalock);
  3532. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3533. spin_unlock_irq(&phba->hbalock);
  3534. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3535. lpfc_sli_brdrestart(phba);
  3536. rc = lpfc_sli_chipset_init(phba);
  3537. if (rc)
  3538. break;
  3539. spin_lock_irq(&phba->hbalock);
  3540. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3541. spin_unlock_irq(&phba->hbalock);
  3542. resetcount++;
  3543. /* Call pre CONFIG_PORT mailbox command initialization. A
  3544. * value of 0 means the call was successful. Any other
  3545. * nonzero value is a failure, but if ERESTART is returned,
  3546. * the driver may reset the HBA and try again.
  3547. */
  3548. rc = lpfc_config_port_prep(phba);
  3549. if (rc == -ERESTART) {
  3550. phba->link_state = LPFC_LINK_UNKNOWN;
  3551. continue;
  3552. } else if (rc)
  3553. break;
  3554. phba->link_state = LPFC_INIT_MBX_CMDS;
  3555. lpfc_config_port(phba, pmb);
  3556. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3557. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3558. LPFC_SLI3_HBQ_ENABLED |
  3559. LPFC_SLI3_CRP_ENABLED |
  3560. LPFC_SLI3_BG_ENABLED |
  3561. LPFC_SLI3_DSS_ENABLED);
  3562. if (rc != MBX_SUCCESS) {
  3563. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3564. "0442 Adapter failed to init, mbxCmd x%x "
  3565. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3566. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3567. spin_lock_irq(&phba->hbalock);
  3568. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3569. spin_unlock_irq(&phba->hbalock);
  3570. rc = -ENXIO;
  3571. } else {
  3572. /* Allow asynchronous mailbox command to go through */
  3573. spin_lock_irq(&phba->hbalock);
  3574. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3575. spin_unlock_irq(&phba->hbalock);
  3576. done = 1;
  3577. }
  3578. }
  3579. if (!done) {
  3580. rc = -EINVAL;
  3581. goto do_prep_failed;
  3582. }
  3583. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3584. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3585. rc = -ENXIO;
  3586. goto do_prep_failed;
  3587. }
  3588. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3589. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3590. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3591. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3592. phba->max_vpi : phba->max_vports;
  3593. } else
  3594. phba->max_vpi = 0;
  3595. phba->fips_level = 0;
  3596. phba->fips_spec_rev = 0;
  3597. if (pmb->u.mb.un.varCfgPort.gdss) {
  3598. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3599. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3600. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3601. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3602. "2850 Security Crypto Active. FIPS x%d "
  3603. "(Spec Rev: x%d)",
  3604. phba->fips_level, phba->fips_spec_rev);
  3605. }
  3606. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3607. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3608. "2856 Config Port Security Crypto "
  3609. "Error: x%x ",
  3610. pmb->u.mb.un.varCfgPort.sec_err);
  3611. }
  3612. if (pmb->u.mb.un.varCfgPort.gerbm)
  3613. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3614. if (pmb->u.mb.un.varCfgPort.gcrp)
  3615. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3616. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3617. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3618. if (phba->cfg_enable_bg) {
  3619. if (pmb->u.mb.un.varCfgPort.gbg)
  3620. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3621. else
  3622. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3623. "0443 Adapter did not grant "
  3624. "BlockGuard\n");
  3625. }
  3626. } else {
  3627. phba->hbq_get = NULL;
  3628. phba->port_gp = phba->mbox->us.s2.port;
  3629. phba->max_vpi = 0;
  3630. }
  3631. do_prep_failed:
  3632. mempool_free(pmb, phba->mbox_mem_pool);
  3633. return rc;
  3634. }
  3635. /**
  3636. * lpfc_sli_hba_setup - SLI intialization function
  3637. * @phba: Pointer to HBA context object.
  3638. *
  3639. * This function is the main SLI intialization function. This function
  3640. * is called by the HBA intialization code, HBA reset code and HBA
  3641. * error attention handler code. Caller is not required to hold any
  3642. * locks. This function issues config_port mailbox command to configure
  3643. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3644. * calls the config_port_post function to issue init_link mailbox
  3645. * command and to start the discovery. The function will return zero
  3646. * if successful, else it will return negative error code.
  3647. **/
  3648. int
  3649. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3650. {
  3651. uint32_t rc;
  3652. int mode = 3;
  3653. switch (lpfc_sli_mode) {
  3654. case 2:
  3655. if (phba->cfg_enable_npiv) {
  3656. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3657. "1824 NPIV enabled: Override lpfc_sli_mode "
  3658. "parameter (%d) to auto (0).\n",
  3659. lpfc_sli_mode);
  3660. break;
  3661. }
  3662. mode = 2;
  3663. break;
  3664. case 0:
  3665. case 3:
  3666. break;
  3667. default:
  3668. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3669. "1819 Unrecognized lpfc_sli_mode "
  3670. "parameter: %d.\n", lpfc_sli_mode);
  3671. break;
  3672. }
  3673. rc = lpfc_sli_config_port(phba, mode);
  3674. if (rc && lpfc_sli_mode == 3)
  3675. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3676. "1820 Unable to select SLI-3. "
  3677. "Not supported by adapter.\n");
  3678. if (rc && mode != 2)
  3679. rc = lpfc_sli_config_port(phba, 2);
  3680. if (rc)
  3681. goto lpfc_sli_hba_setup_error;
  3682. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  3683. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  3684. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  3685. if (!rc) {
  3686. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3687. "2709 This device supports "
  3688. "Advanced Error Reporting (AER)\n");
  3689. spin_lock_irq(&phba->hbalock);
  3690. phba->hba_flag |= HBA_AER_ENABLED;
  3691. spin_unlock_irq(&phba->hbalock);
  3692. } else {
  3693. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3694. "2708 This device does not support "
  3695. "Advanced Error Reporting (AER)\n");
  3696. phba->cfg_aer_support = 0;
  3697. }
  3698. }
  3699. if (phba->sli_rev == 3) {
  3700. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3701. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3702. } else {
  3703. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3704. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3705. phba->sli3_options = 0;
  3706. }
  3707. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3708. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3709. phba->sli_rev, phba->max_vpi);
  3710. rc = lpfc_sli_ring_map(phba);
  3711. if (rc)
  3712. goto lpfc_sli_hba_setup_error;
  3713. /* Init HBQs */
  3714. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3715. rc = lpfc_sli_hbq_setup(phba);
  3716. if (rc)
  3717. goto lpfc_sli_hba_setup_error;
  3718. }
  3719. spin_lock_irq(&phba->hbalock);
  3720. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3721. spin_unlock_irq(&phba->hbalock);
  3722. rc = lpfc_config_port_post(phba);
  3723. if (rc)
  3724. goto lpfc_sli_hba_setup_error;
  3725. return rc;
  3726. lpfc_sli_hba_setup_error:
  3727. phba->link_state = LPFC_HBA_ERROR;
  3728. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3729. "0445 Firmware initialization failed\n");
  3730. return rc;
  3731. }
  3732. /**
  3733. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3734. * @phba: Pointer to HBA context object.
  3735. * @mboxq: mailbox pointer.
  3736. * This function issue a dump mailbox command to read config region
  3737. * 23 and parse the records in the region and populate driver
  3738. * data structure.
  3739. **/
  3740. static int
  3741. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3742. LPFC_MBOXQ_t *mboxq)
  3743. {
  3744. struct lpfc_dmabuf *mp;
  3745. struct lpfc_mqe *mqe;
  3746. uint32_t data_length;
  3747. int rc;
  3748. /* Program the default value of vlan_id and fc_map */
  3749. phba->valid_vlan = 0;
  3750. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3751. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3752. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3753. mqe = &mboxq->u.mqe;
  3754. if (lpfc_dump_fcoe_param(phba, mboxq))
  3755. return -ENOMEM;
  3756. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3757. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3758. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3759. "(%d):2571 Mailbox cmd x%x Status x%x "
  3760. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3761. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3762. "CQ: x%x x%x x%x x%x\n",
  3763. mboxq->vport ? mboxq->vport->vpi : 0,
  3764. bf_get(lpfc_mqe_command, mqe),
  3765. bf_get(lpfc_mqe_status, mqe),
  3766. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3767. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3768. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3769. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3770. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3771. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3772. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3773. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3774. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3775. mboxq->mcqe.word0,
  3776. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3777. mboxq->mcqe.trailer);
  3778. if (rc) {
  3779. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3780. kfree(mp);
  3781. return -EIO;
  3782. }
  3783. data_length = mqe->un.mb_words[5];
  3784. if (data_length > DMP_RGN23_SIZE) {
  3785. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3786. kfree(mp);
  3787. return -EIO;
  3788. }
  3789. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3790. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3791. kfree(mp);
  3792. return 0;
  3793. }
  3794. /**
  3795. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3796. * @phba: pointer to lpfc hba data structure.
  3797. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3798. * @vpd: pointer to the memory to hold resulting port vpd data.
  3799. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3800. * On output, the number of data bytes in @vpd.
  3801. *
  3802. * This routine executes a READ_REV SLI4 mailbox command. In
  3803. * addition, this routine gets the port vpd data.
  3804. *
  3805. * Return codes
  3806. * 0 - successful
  3807. * -ENOMEM - could not allocated memory.
  3808. **/
  3809. static int
  3810. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3811. uint8_t *vpd, uint32_t *vpd_size)
  3812. {
  3813. int rc = 0;
  3814. uint32_t dma_size;
  3815. struct lpfc_dmabuf *dmabuf;
  3816. struct lpfc_mqe *mqe;
  3817. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3818. if (!dmabuf)
  3819. return -ENOMEM;
  3820. /*
  3821. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3822. * mailbox command.
  3823. */
  3824. dma_size = *vpd_size;
  3825. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3826. dma_size,
  3827. &dmabuf->phys,
  3828. GFP_KERNEL);
  3829. if (!dmabuf->virt) {
  3830. kfree(dmabuf);
  3831. return -ENOMEM;
  3832. }
  3833. memset(dmabuf->virt, 0, dma_size);
  3834. /*
  3835. * The SLI4 implementation of READ_REV conflicts at word1,
  3836. * bits 31:16 and SLI4 adds vpd functionality not present
  3837. * in SLI3. This code corrects the conflicts.
  3838. */
  3839. lpfc_read_rev(phba, mboxq);
  3840. mqe = &mboxq->u.mqe;
  3841. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3842. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3843. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3844. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3845. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3846. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3847. if (rc) {
  3848. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3849. dmabuf->virt, dmabuf->phys);
  3850. kfree(dmabuf);
  3851. return -EIO;
  3852. }
  3853. /*
  3854. * The available vpd length cannot be bigger than the
  3855. * DMA buffer passed to the port. Catch the less than
  3856. * case and update the caller's size.
  3857. */
  3858. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3859. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3860. memcpy(vpd, dmabuf->virt, *vpd_size);
  3861. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3862. dmabuf->virt, dmabuf->phys);
  3863. kfree(dmabuf);
  3864. return 0;
  3865. }
  3866. /**
  3867. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3868. * @phba: pointer to lpfc hba data structure.
  3869. *
  3870. * This routine is called to explicitly arm the SLI4 device's completion and
  3871. * event queues
  3872. **/
  3873. static void
  3874. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3875. {
  3876. uint8_t fcp_eqidx;
  3877. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3878. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3879. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3880. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3881. LPFC_QUEUE_REARM);
  3882. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3883. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3884. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3885. LPFC_QUEUE_REARM);
  3886. }
  3887. /**
  3888. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3889. * @phba: Pointer to HBA context object.
  3890. *
  3891. * This function is the main SLI4 device intialization PCI function. This
  3892. * function is called by the HBA intialization code, HBA reset code and
  3893. * HBA error attention handler code. Caller is not required to hold any
  3894. * locks.
  3895. **/
  3896. int
  3897. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3898. {
  3899. int rc;
  3900. LPFC_MBOXQ_t *mboxq;
  3901. struct lpfc_mqe *mqe;
  3902. uint8_t *vpd;
  3903. uint32_t vpd_size;
  3904. uint32_t ftr_rsp = 0;
  3905. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3906. struct lpfc_vport *vport = phba->pport;
  3907. struct lpfc_dmabuf *mp;
  3908. /* Perform a PCI function reset to start from clean */
  3909. rc = lpfc_pci_function_reset(phba);
  3910. if (unlikely(rc))
  3911. return -ENODEV;
  3912. /* Check the HBA Host Status Register for readyness */
  3913. rc = lpfc_sli4_post_status_check(phba);
  3914. if (unlikely(rc))
  3915. return -ENODEV;
  3916. else {
  3917. spin_lock_irq(&phba->hbalock);
  3918. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3919. spin_unlock_irq(&phba->hbalock);
  3920. }
  3921. /*
  3922. * Allocate a single mailbox container for initializing the
  3923. * port.
  3924. */
  3925. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3926. if (!mboxq)
  3927. return -ENOMEM;
  3928. /*
  3929. * Continue initialization with default values even if driver failed
  3930. * to read FCoE param config regions
  3931. */
  3932. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3933. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3934. "2570 Failed to read FCoE parameters\n");
  3935. /* Issue READ_REV to collect vpd and FW information. */
  3936. vpd_size = SLI4_PAGE_SIZE;
  3937. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3938. if (!vpd) {
  3939. rc = -ENOMEM;
  3940. goto out_free_mbox;
  3941. }
  3942. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3943. if (unlikely(rc))
  3944. goto out_free_vpd;
  3945. mqe = &mboxq->u.mqe;
  3946. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  3947. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  3948. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3949. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  3950. LPFC_DCBX_CEE_MODE)
  3951. phba->hba_flag |= HBA_FIP_SUPPORT;
  3952. else
  3953. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  3954. if (phba->sli_rev != LPFC_SLI_REV4 ||
  3955. !(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  3956. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3957. "0376 READ_REV Error. SLI Level %d "
  3958. "FCoE enabled %d\n",
  3959. phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT);
  3960. rc = -EIO;
  3961. goto out_free_vpd;
  3962. }
  3963. /*
  3964. * Evaluate the read rev and vpd data. Populate the driver
  3965. * state with the results. If this routine fails, the failure
  3966. * is not fatal as the driver will use generic values.
  3967. */
  3968. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3969. if (unlikely(!rc)) {
  3970. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3971. "0377 Error %d parsing vpd. "
  3972. "Using defaults.\n", rc);
  3973. rc = 0;
  3974. }
  3975. /* Save information as VPD data */
  3976. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  3977. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  3978. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  3979. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  3980. &mqe->un.read_rev);
  3981. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  3982. &mqe->un.read_rev);
  3983. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  3984. &mqe->un.read_rev);
  3985. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  3986. &mqe->un.read_rev);
  3987. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  3988. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  3989. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  3990. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  3991. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  3992. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  3993. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3994. "(%d):0380 READ_REV Status x%x "
  3995. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  3996. mboxq->vport ? mboxq->vport->vpi : 0,
  3997. bf_get(lpfc_mqe_status, mqe),
  3998. phba->vpd.rev.opFwName,
  3999. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  4000. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  4001. /*
  4002. * Discover the port's supported feature set and match it against the
  4003. * hosts requests.
  4004. */
  4005. lpfc_request_features(phba, mboxq);
  4006. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4007. if (unlikely(rc)) {
  4008. rc = -EIO;
  4009. goto out_free_vpd;
  4010. }
  4011. /*
  4012. * The port must support FCP initiator mode as this is the
  4013. * only mode running in the host.
  4014. */
  4015. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  4016. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4017. "0378 No support for fcpi mode.\n");
  4018. ftr_rsp++;
  4019. }
  4020. /*
  4021. * If the port cannot support the host's requested features
  4022. * then turn off the global config parameters to disable the
  4023. * feature in the driver. This is not a fatal error.
  4024. */
  4025. if ((phba->cfg_enable_bg) &&
  4026. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4027. ftr_rsp++;
  4028. if (phba->max_vpi && phba->cfg_enable_npiv &&
  4029. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4030. ftr_rsp++;
  4031. if (ftr_rsp) {
  4032. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4033. "0379 Feature Mismatch Data: x%08x %08x "
  4034. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  4035. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  4036. phba->cfg_enable_npiv, phba->max_vpi);
  4037. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  4038. phba->cfg_enable_bg = 0;
  4039. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  4040. phba->cfg_enable_npiv = 0;
  4041. }
  4042. /* These SLI3 features are assumed in SLI4 */
  4043. spin_lock_irq(&phba->hbalock);
  4044. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  4045. spin_unlock_irq(&phba->hbalock);
  4046. /* Read the port's service parameters. */
  4047. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  4048. if (rc) {
  4049. phba->link_state = LPFC_HBA_ERROR;
  4050. rc = -ENOMEM;
  4051. goto out_free_vpd;
  4052. }
  4053. mboxq->vport = vport;
  4054. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4055. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4056. if (rc == MBX_SUCCESS) {
  4057. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4058. rc = 0;
  4059. }
  4060. /*
  4061. * This memory was allocated by the lpfc_read_sparam routine. Release
  4062. * it to the mbuf pool.
  4063. */
  4064. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4065. kfree(mp);
  4066. mboxq->context1 = NULL;
  4067. if (unlikely(rc)) {
  4068. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4069. "0382 READ_SPARAM command failed "
  4070. "status %d, mbxStatus x%x\n",
  4071. rc, bf_get(lpfc_mqe_status, mqe));
  4072. phba->link_state = LPFC_HBA_ERROR;
  4073. rc = -EIO;
  4074. goto out_free_vpd;
  4075. }
  4076. if (phba->cfg_soft_wwnn)
  4077. u64_to_wwn(phba->cfg_soft_wwnn,
  4078. vport->fc_sparam.nodeName.u.wwn);
  4079. if (phba->cfg_soft_wwpn)
  4080. u64_to_wwn(phba->cfg_soft_wwpn,
  4081. vport->fc_sparam.portName.u.wwn);
  4082. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4083. sizeof(struct lpfc_name));
  4084. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4085. sizeof(struct lpfc_name));
  4086. /* Update the fc_host data structures with new wwn. */
  4087. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4088. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4089. /* Register SGL pool to the device using non-embedded mailbox command */
  4090. rc = lpfc_sli4_post_sgl_list(phba);
  4091. if (unlikely(rc)) {
  4092. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4093. "0582 Error %d during sgl post operation\n",
  4094. rc);
  4095. rc = -ENODEV;
  4096. goto out_free_vpd;
  4097. }
  4098. /* Register SCSI SGL pool to the device */
  4099. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4100. if (unlikely(rc)) {
  4101. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4102. "0383 Error %d during scsi sgl post "
  4103. "operation\n", rc);
  4104. /* Some Scsi buffers were moved to the abort scsi list */
  4105. /* A pci function reset will repost them */
  4106. rc = -ENODEV;
  4107. goto out_free_vpd;
  4108. }
  4109. /* Post the rpi header region to the device. */
  4110. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4111. if (unlikely(rc)) {
  4112. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4113. "0393 Error %d during rpi post operation\n",
  4114. rc);
  4115. rc = -ENODEV;
  4116. goto out_free_vpd;
  4117. }
  4118. /* Set up all the queues to the device */
  4119. rc = lpfc_sli4_queue_setup(phba);
  4120. if (unlikely(rc)) {
  4121. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4122. "0381 Error %d during queue setup.\n ", rc);
  4123. goto out_stop_timers;
  4124. }
  4125. /* Arm the CQs and then EQs on device */
  4126. lpfc_sli4_arm_cqeq_intr(phba);
  4127. /* Indicate device interrupt mode */
  4128. phba->sli4_hba.intr_enable = 1;
  4129. /* Allow asynchronous mailbox command to go through */
  4130. spin_lock_irq(&phba->hbalock);
  4131. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4132. spin_unlock_irq(&phba->hbalock);
  4133. /* Post receive buffers to the device */
  4134. lpfc_sli4_rb_setup(phba);
  4135. /* Reset HBA FCF states after HBA reset */
  4136. phba->fcf.fcf_flag = 0;
  4137. phba->fcf.current_rec.flag = 0;
  4138. /* Start the ELS watchdog timer */
  4139. mod_timer(&vport->els_tmofunc,
  4140. jiffies + HZ * (phba->fc_ratov * 2));
  4141. /* Start heart beat timer */
  4142. mod_timer(&phba->hb_tmofunc,
  4143. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4144. phba->hb_outstanding = 0;
  4145. phba->last_completion_time = jiffies;
  4146. /* Start error attention (ERATT) polling timer */
  4147. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4148. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4149. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4150. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4151. if (!rc) {
  4152. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4153. "2829 This device supports "
  4154. "Advanced Error Reporting (AER)\n");
  4155. spin_lock_irq(&phba->hbalock);
  4156. phba->hba_flag |= HBA_AER_ENABLED;
  4157. spin_unlock_irq(&phba->hbalock);
  4158. } else {
  4159. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4160. "2830 This device does not support "
  4161. "Advanced Error Reporting (AER)\n");
  4162. phba->cfg_aer_support = 0;
  4163. }
  4164. }
  4165. /*
  4166. * The port is ready, set the host's link state to LINK_DOWN
  4167. * in preparation for link interrupts.
  4168. */
  4169. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4170. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4171. lpfc_set_loopback_flag(phba);
  4172. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4173. spin_lock_irq(&phba->hbalock);
  4174. phba->link_state = LPFC_LINK_DOWN;
  4175. spin_unlock_irq(&phba->hbalock);
  4176. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4177. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4178. kfree(vpd);
  4179. return 0;
  4180. } else
  4181. rc = -EIO;
  4182. /* Unset all the queues set up in this routine when error out */
  4183. if (rc)
  4184. lpfc_sli4_queue_unset(phba);
  4185. out_stop_timers:
  4186. if (rc)
  4187. lpfc_stop_hba_timers(phba);
  4188. out_free_vpd:
  4189. kfree(vpd);
  4190. out_free_mbox:
  4191. mempool_free(mboxq, phba->mbox_mem_pool);
  4192. return rc;
  4193. }
  4194. /**
  4195. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4196. * @ptr: context object - pointer to hba structure.
  4197. *
  4198. * This is the callback function for mailbox timer. The mailbox
  4199. * timer is armed when a new mailbox command is issued and the timer
  4200. * is deleted when the mailbox complete. The function is called by
  4201. * the kernel timer code when a mailbox does not complete within
  4202. * expected time. This function wakes up the worker thread to
  4203. * process the mailbox timeout and returns. All the processing is
  4204. * done by the worker thread function lpfc_mbox_timeout_handler.
  4205. **/
  4206. void
  4207. lpfc_mbox_timeout(unsigned long ptr)
  4208. {
  4209. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4210. unsigned long iflag;
  4211. uint32_t tmo_posted;
  4212. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4213. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4214. if (!tmo_posted)
  4215. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4216. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4217. if (!tmo_posted)
  4218. lpfc_worker_wake_up(phba);
  4219. return;
  4220. }
  4221. /**
  4222. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4223. * @phba: Pointer to HBA context object.
  4224. *
  4225. * This function is called from worker thread when a mailbox command times out.
  4226. * The caller is not required to hold any locks. This function will reset the
  4227. * HBA and recover all the pending commands.
  4228. **/
  4229. void
  4230. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4231. {
  4232. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4233. MAILBOX_t *mb = &pmbox->u.mb;
  4234. struct lpfc_sli *psli = &phba->sli;
  4235. struct lpfc_sli_ring *pring;
  4236. /* Check the pmbox pointer first. There is a race condition
  4237. * between the mbox timeout handler getting executed in the
  4238. * worklist and the mailbox actually completing. When this
  4239. * race condition occurs, the mbox_active will be NULL.
  4240. */
  4241. spin_lock_irq(&phba->hbalock);
  4242. if (pmbox == NULL) {
  4243. lpfc_printf_log(phba, KERN_WARNING,
  4244. LOG_MBOX | LOG_SLI,
  4245. "0353 Active Mailbox cleared - mailbox timeout "
  4246. "exiting\n");
  4247. spin_unlock_irq(&phba->hbalock);
  4248. return;
  4249. }
  4250. /* Mbox cmd <mbxCommand> timeout */
  4251. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4252. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4253. mb->mbxCommand,
  4254. phba->pport->port_state,
  4255. phba->sli.sli_flag,
  4256. phba->sli.mbox_active);
  4257. spin_unlock_irq(&phba->hbalock);
  4258. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4259. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4260. * it to fail all oustanding SCSI IO.
  4261. */
  4262. spin_lock_irq(&phba->pport->work_port_lock);
  4263. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4264. spin_unlock_irq(&phba->pport->work_port_lock);
  4265. spin_lock_irq(&phba->hbalock);
  4266. phba->link_state = LPFC_LINK_UNKNOWN;
  4267. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4268. spin_unlock_irq(&phba->hbalock);
  4269. pring = &psli->ring[psli->fcp_ring];
  4270. lpfc_sli_abort_iocb_ring(phba, pring);
  4271. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4272. "0345 Resetting board due to mailbox timeout\n");
  4273. /* Reset the HBA device */
  4274. lpfc_reset_hba(phba);
  4275. }
  4276. /**
  4277. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4278. * @phba: Pointer to HBA context object.
  4279. * @pmbox: Pointer to mailbox object.
  4280. * @flag: Flag indicating how the mailbox need to be processed.
  4281. *
  4282. * This function is called by discovery code and HBA management code
  4283. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4284. * function gets the hbalock to protect the data structures.
  4285. * The mailbox command can be submitted in polling mode, in which case
  4286. * this function will wait in a polling loop for the completion of the
  4287. * mailbox.
  4288. * If the mailbox is submitted in no_wait mode (not polling) the
  4289. * function will submit the command and returns immediately without waiting
  4290. * for the mailbox completion. The no_wait is supported only when HBA
  4291. * is in SLI2/SLI3 mode - interrupts are enabled.
  4292. * The SLI interface allows only one mailbox pending at a time. If the
  4293. * mailbox is issued in polling mode and there is already a mailbox
  4294. * pending, then the function will return an error. If the mailbox is issued
  4295. * in NO_WAIT mode and there is a mailbox pending already, the function
  4296. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4297. * The sli layer owns the mailbox object until the completion of mailbox
  4298. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4299. * return codes the caller owns the mailbox command after the return of
  4300. * the function.
  4301. **/
  4302. static int
  4303. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4304. uint32_t flag)
  4305. {
  4306. MAILBOX_t *mb;
  4307. struct lpfc_sli *psli = &phba->sli;
  4308. uint32_t status, evtctr;
  4309. uint32_t ha_copy;
  4310. int i;
  4311. unsigned long timeout;
  4312. unsigned long drvr_flag = 0;
  4313. uint32_t word0, ldata;
  4314. void __iomem *to_slim;
  4315. int processing_queue = 0;
  4316. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4317. if (!pmbox) {
  4318. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4319. /* processing mbox queue from intr_handler */
  4320. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4321. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4322. return MBX_SUCCESS;
  4323. }
  4324. processing_queue = 1;
  4325. pmbox = lpfc_mbox_get(phba);
  4326. if (!pmbox) {
  4327. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4328. return MBX_SUCCESS;
  4329. }
  4330. }
  4331. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4332. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4333. if(!pmbox->vport) {
  4334. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4335. lpfc_printf_log(phba, KERN_ERR,
  4336. LOG_MBOX | LOG_VPORT,
  4337. "1806 Mbox x%x failed. No vport\n",
  4338. pmbox->u.mb.mbxCommand);
  4339. dump_stack();
  4340. goto out_not_finished;
  4341. }
  4342. }
  4343. /* If the PCI channel is in offline state, do not post mbox. */
  4344. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4345. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4346. goto out_not_finished;
  4347. }
  4348. /* If HBA has a deferred error attention, fail the iocb. */
  4349. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4350. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4351. goto out_not_finished;
  4352. }
  4353. psli = &phba->sli;
  4354. mb = &pmbox->u.mb;
  4355. status = MBX_SUCCESS;
  4356. if (phba->link_state == LPFC_HBA_ERROR) {
  4357. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4358. /* Mbox command <mbxCommand> cannot issue */
  4359. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4360. "(%d):0311 Mailbox command x%x cannot "
  4361. "issue Data: x%x x%x\n",
  4362. pmbox->vport ? pmbox->vport->vpi : 0,
  4363. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4364. goto out_not_finished;
  4365. }
  4366. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4367. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4368. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4369. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4370. "(%d):2528 Mailbox command x%x cannot "
  4371. "issue Data: x%x x%x\n",
  4372. pmbox->vport ? pmbox->vport->vpi : 0,
  4373. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4374. goto out_not_finished;
  4375. }
  4376. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4377. /* Polling for a mbox command when another one is already active
  4378. * is not allowed in SLI. Also, the driver must have established
  4379. * SLI2 mode to queue and process multiple mbox commands.
  4380. */
  4381. if (flag & MBX_POLL) {
  4382. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4383. /* Mbox command <mbxCommand> cannot issue */
  4384. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4385. "(%d):2529 Mailbox command x%x "
  4386. "cannot issue Data: x%x x%x\n",
  4387. pmbox->vport ? pmbox->vport->vpi : 0,
  4388. pmbox->u.mb.mbxCommand,
  4389. psli->sli_flag, flag);
  4390. goto out_not_finished;
  4391. }
  4392. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4393. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4394. /* Mbox command <mbxCommand> cannot issue */
  4395. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4396. "(%d):2530 Mailbox command x%x "
  4397. "cannot issue Data: x%x x%x\n",
  4398. pmbox->vport ? pmbox->vport->vpi : 0,
  4399. pmbox->u.mb.mbxCommand,
  4400. psli->sli_flag, flag);
  4401. goto out_not_finished;
  4402. }
  4403. /* Another mailbox command is still being processed, queue this
  4404. * command to be processed later.
  4405. */
  4406. lpfc_mbox_put(phba, pmbox);
  4407. /* Mbox cmd issue - BUSY */
  4408. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4409. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4410. "x%x x%x x%x x%x\n",
  4411. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4412. mb->mbxCommand, phba->pport->port_state,
  4413. psli->sli_flag, flag);
  4414. psli->slistat.mbox_busy++;
  4415. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4416. if (pmbox->vport) {
  4417. lpfc_debugfs_disc_trc(pmbox->vport,
  4418. LPFC_DISC_TRC_MBOX_VPORT,
  4419. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4420. (uint32_t)mb->mbxCommand,
  4421. mb->un.varWords[0], mb->un.varWords[1]);
  4422. }
  4423. else {
  4424. lpfc_debugfs_disc_trc(phba->pport,
  4425. LPFC_DISC_TRC_MBOX,
  4426. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4427. (uint32_t)mb->mbxCommand,
  4428. mb->un.varWords[0], mb->un.varWords[1]);
  4429. }
  4430. return MBX_BUSY;
  4431. }
  4432. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4433. /* If we are not polling, we MUST be in SLI2 mode */
  4434. if (flag != MBX_POLL) {
  4435. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4436. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4437. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4438. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4439. /* Mbox command <mbxCommand> cannot issue */
  4440. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4441. "(%d):2531 Mailbox command x%x "
  4442. "cannot issue Data: x%x x%x\n",
  4443. pmbox->vport ? pmbox->vport->vpi : 0,
  4444. pmbox->u.mb.mbxCommand,
  4445. psli->sli_flag, flag);
  4446. goto out_not_finished;
  4447. }
  4448. /* timeout active mbox command */
  4449. mod_timer(&psli->mbox_tmo, (jiffies +
  4450. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4451. }
  4452. /* Mailbox cmd <cmd> issue */
  4453. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4454. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4455. "x%x\n",
  4456. pmbox->vport ? pmbox->vport->vpi : 0,
  4457. mb->mbxCommand, phba->pport->port_state,
  4458. psli->sli_flag, flag);
  4459. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4460. if (pmbox->vport) {
  4461. lpfc_debugfs_disc_trc(pmbox->vport,
  4462. LPFC_DISC_TRC_MBOX_VPORT,
  4463. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4464. (uint32_t)mb->mbxCommand,
  4465. mb->un.varWords[0], mb->un.varWords[1]);
  4466. }
  4467. else {
  4468. lpfc_debugfs_disc_trc(phba->pport,
  4469. LPFC_DISC_TRC_MBOX,
  4470. "MBOX Send: cmd:x%x mb:x%x x%x",
  4471. (uint32_t)mb->mbxCommand,
  4472. mb->un.varWords[0], mb->un.varWords[1]);
  4473. }
  4474. }
  4475. psli->slistat.mbox_cmd++;
  4476. evtctr = psli->slistat.mbox_event;
  4477. /* next set own bit for the adapter and copy over command word */
  4478. mb->mbxOwner = OWN_CHIP;
  4479. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4480. /* Populate mbox extension offset word. */
  4481. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  4482. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4483. = (uint8_t *)phba->mbox_ext
  4484. - (uint8_t *)phba->mbox;
  4485. }
  4486. /* Copy the mailbox extension data */
  4487. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4488. lpfc_sli_pcimem_bcopy(pmbox->context2,
  4489. (uint8_t *)phba->mbox_ext,
  4490. pmbox->in_ext_byte_len);
  4491. }
  4492. /* Copy command data to host SLIM area */
  4493. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4494. } else {
  4495. /* Populate mbox extension offset word. */
  4496. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  4497. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  4498. = MAILBOX_HBA_EXT_OFFSET;
  4499. /* Copy the mailbox extension data */
  4500. if (pmbox->in_ext_byte_len && pmbox->context2) {
  4501. lpfc_memcpy_to_slim(phba->MBslimaddr +
  4502. MAILBOX_HBA_EXT_OFFSET,
  4503. pmbox->context2, pmbox->in_ext_byte_len);
  4504. }
  4505. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4506. /* copy command data into host mbox for cmpl */
  4507. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4508. }
  4509. /* First copy mbox command data to HBA SLIM, skip past first
  4510. word */
  4511. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4512. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4513. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4514. /* Next copy over first word, with mbxOwner set */
  4515. ldata = *((uint32_t *)mb);
  4516. to_slim = phba->MBslimaddr;
  4517. writel(ldata, to_slim);
  4518. readl(to_slim); /* flush */
  4519. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4520. /* switch over to host mailbox */
  4521. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4522. }
  4523. }
  4524. wmb();
  4525. switch (flag) {
  4526. case MBX_NOWAIT:
  4527. /* Set up reference to mailbox command */
  4528. psli->mbox_active = pmbox;
  4529. /* Interrupt board to do it */
  4530. writel(CA_MBATT, phba->CAregaddr);
  4531. readl(phba->CAregaddr); /* flush */
  4532. /* Don't wait for it to finish, just return */
  4533. break;
  4534. case MBX_POLL:
  4535. /* Set up null reference to mailbox command */
  4536. psli->mbox_active = NULL;
  4537. /* Interrupt board to do it */
  4538. writel(CA_MBATT, phba->CAregaddr);
  4539. readl(phba->CAregaddr); /* flush */
  4540. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4541. /* First read mbox status word */
  4542. word0 = *((uint32_t *)phba->mbox);
  4543. word0 = le32_to_cpu(word0);
  4544. } else {
  4545. /* First read mbox status word */
  4546. word0 = readl(phba->MBslimaddr);
  4547. }
  4548. /* Read the HBA Host Attention Register */
  4549. ha_copy = readl(phba->HAregaddr);
  4550. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4551. mb->mbxCommand) *
  4552. 1000) + jiffies;
  4553. i = 0;
  4554. /* Wait for command to complete */
  4555. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4556. (!(ha_copy & HA_MBATT) &&
  4557. (phba->link_state > LPFC_WARM_START))) {
  4558. if (time_after(jiffies, timeout)) {
  4559. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4560. spin_unlock_irqrestore(&phba->hbalock,
  4561. drvr_flag);
  4562. goto out_not_finished;
  4563. }
  4564. /* Check if we took a mbox interrupt while we were
  4565. polling */
  4566. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4567. && (evtctr != psli->slistat.mbox_event))
  4568. break;
  4569. if (i++ > 10) {
  4570. spin_unlock_irqrestore(&phba->hbalock,
  4571. drvr_flag);
  4572. msleep(1);
  4573. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4574. }
  4575. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4576. /* First copy command data */
  4577. word0 = *((uint32_t *)phba->mbox);
  4578. word0 = le32_to_cpu(word0);
  4579. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4580. MAILBOX_t *slimmb;
  4581. uint32_t slimword0;
  4582. /* Check real SLIM for any errors */
  4583. slimword0 = readl(phba->MBslimaddr);
  4584. slimmb = (MAILBOX_t *) & slimword0;
  4585. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4586. && slimmb->mbxStatus) {
  4587. psli->sli_flag &=
  4588. ~LPFC_SLI_ACTIVE;
  4589. word0 = slimword0;
  4590. }
  4591. }
  4592. } else {
  4593. /* First copy command data */
  4594. word0 = readl(phba->MBslimaddr);
  4595. }
  4596. /* Read the HBA Host Attention Register */
  4597. ha_copy = readl(phba->HAregaddr);
  4598. }
  4599. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4600. /* copy results back to user */
  4601. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4602. /* Copy the mailbox extension data */
  4603. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4604. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  4605. pmbox->context2,
  4606. pmbox->out_ext_byte_len);
  4607. }
  4608. } else {
  4609. /* First copy command data */
  4610. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4611. MAILBOX_CMD_SIZE);
  4612. /* Copy the mailbox extension data */
  4613. if (pmbox->out_ext_byte_len && pmbox->context2) {
  4614. lpfc_memcpy_from_slim(pmbox->context2,
  4615. phba->MBslimaddr +
  4616. MAILBOX_HBA_EXT_OFFSET,
  4617. pmbox->out_ext_byte_len);
  4618. }
  4619. }
  4620. writel(HA_MBATT, phba->HAregaddr);
  4621. readl(phba->HAregaddr); /* flush */
  4622. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4623. status = mb->mbxStatus;
  4624. }
  4625. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4626. return status;
  4627. out_not_finished:
  4628. if (processing_queue) {
  4629. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4630. lpfc_mbox_cmpl_put(phba, pmbox);
  4631. }
  4632. return MBX_NOT_FINISHED;
  4633. }
  4634. /**
  4635. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  4636. * @phba: Pointer to HBA context object.
  4637. *
  4638. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  4639. * the driver internal pending mailbox queue. It will then try to wait out the
  4640. * possible outstanding mailbox command before return.
  4641. *
  4642. * Returns:
  4643. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  4644. * the outstanding mailbox command timed out.
  4645. **/
  4646. static int
  4647. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  4648. {
  4649. struct lpfc_sli *psli = &phba->sli;
  4650. uint8_t actcmd = MBX_HEARTBEAT;
  4651. int rc = 0;
  4652. unsigned long timeout;
  4653. /* Mark the asynchronous mailbox command posting as blocked */
  4654. spin_lock_irq(&phba->hbalock);
  4655. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  4656. if (phba->sli.mbox_active)
  4657. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  4658. spin_unlock_irq(&phba->hbalock);
  4659. /* Determine how long we might wait for the active mailbox
  4660. * command to be gracefully completed by firmware.
  4661. */
  4662. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  4663. jiffies;
  4664. /* Wait for the outstnading mailbox command to complete */
  4665. while (phba->sli.mbox_active) {
  4666. /* Check active mailbox complete status every 2ms */
  4667. msleep(2);
  4668. if (time_after(jiffies, timeout)) {
  4669. /* Timeout, marked the outstanding cmd not complete */
  4670. rc = 1;
  4671. break;
  4672. }
  4673. }
  4674. /* Can not cleanly block async mailbox command, fails it */
  4675. if (rc) {
  4676. spin_lock_irq(&phba->hbalock);
  4677. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4678. spin_unlock_irq(&phba->hbalock);
  4679. }
  4680. return rc;
  4681. }
  4682. /**
  4683. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  4684. * @phba: Pointer to HBA context object.
  4685. *
  4686. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  4687. * commands from the driver internal pending mailbox queue. It makes sure
  4688. * that there is no outstanding mailbox command before resuming posting
  4689. * asynchronous mailbox commands. If, for any reason, there is outstanding
  4690. * mailbox command, it will try to wait it out before resuming asynchronous
  4691. * mailbox command posting.
  4692. **/
  4693. static void
  4694. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  4695. {
  4696. struct lpfc_sli *psli = &phba->sli;
  4697. spin_lock_irq(&phba->hbalock);
  4698. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4699. /* Asynchronous mailbox posting is not blocked, do nothing */
  4700. spin_unlock_irq(&phba->hbalock);
  4701. return;
  4702. }
  4703. /* Outstanding synchronous mailbox command is guaranteed to be done,
  4704. * successful or timeout, after timing-out the outstanding mailbox
  4705. * command shall always be removed, so just unblock posting async
  4706. * mailbox command and resume
  4707. */
  4708. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4709. spin_unlock_irq(&phba->hbalock);
  4710. /* wake up worker thread to post asynchronlous mailbox command */
  4711. lpfc_worker_wake_up(phba);
  4712. }
  4713. /**
  4714. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4715. * @phba: Pointer to HBA context object.
  4716. * @mboxq: Pointer to mailbox object.
  4717. *
  4718. * The function posts a mailbox to the port. The mailbox is expected
  4719. * to be comletely filled in and ready for the port to operate on it.
  4720. * This routine executes a synchronous completion operation on the
  4721. * mailbox by polling for its completion.
  4722. *
  4723. * The caller must not be holding any locks when calling this routine.
  4724. *
  4725. * Returns:
  4726. * MBX_SUCCESS - mailbox posted successfully
  4727. * Any of the MBX error values.
  4728. **/
  4729. static int
  4730. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4731. {
  4732. int rc = MBX_SUCCESS;
  4733. unsigned long iflag;
  4734. uint32_t db_ready;
  4735. uint32_t mcqe_status;
  4736. uint32_t mbx_cmnd;
  4737. unsigned long timeout;
  4738. struct lpfc_sli *psli = &phba->sli;
  4739. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4740. struct lpfc_bmbx_create *mbox_rgn;
  4741. struct dma_address *dma_address;
  4742. struct lpfc_register bmbx_reg;
  4743. /*
  4744. * Only one mailbox can be active to the bootstrap mailbox region
  4745. * at a time and there is no queueing provided.
  4746. */
  4747. spin_lock_irqsave(&phba->hbalock, iflag);
  4748. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4749. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4750. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4751. "(%d):2532 Mailbox command x%x (x%x) "
  4752. "cannot issue Data: x%x x%x\n",
  4753. mboxq->vport ? mboxq->vport->vpi : 0,
  4754. mboxq->u.mb.mbxCommand,
  4755. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4756. psli->sli_flag, MBX_POLL);
  4757. return MBXERR_ERROR;
  4758. }
  4759. /* The server grabs the token and owns it until release */
  4760. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4761. phba->sli.mbox_active = mboxq;
  4762. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4763. /*
  4764. * Initialize the bootstrap memory region to avoid stale data areas
  4765. * in the mailbox post. Then copy the caller's mailbox contents to
  4766. * the bmbx mailbox region.
  4767. */
  4768. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4769. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4770. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4771. sizeof(struct lpfc_mqe));
  4772. /* Post the high mailbox dma address to the port and wait for ready. */
  4773. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4774. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4775. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4776. * 1000) + jiffies;
  4777. do {
  4778. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4779. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4780. if (!db_ready)
  4781. msleep(2);
  4782. if (time_after(jiffies, timeout)) {
  4783. rc = MBXERR_ERROR;
  4784. goto exit;
  4785. }
  4786. } while (!db_ready);
  4787. /* Post the low mailbox dma address to the port. */
  4788. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4789. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4790. * 1000) + jiffies;
  4791. do {
  4792. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4793. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4794. if (!db_ready)
  4795. msleep(2);
  4796. if (time_after(jiffies, timeout)) {
  4797. rc = MBXERR_ERROR;
  4798. goto exit;
  4799. }
  4800. } while (!db_ready);
  4801. /*
  4802. * Read the CQ to ensure the mailbox has completed.
  4803. * If so, update the mailbox status so that the upper layers
  4804. * can complete the request normally.
  4805. */
  4806. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4807. sizeof(struct lpfc_mqe));
  4808. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4809. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4810. sizeof(struct lpfc_mcqe));
  4811. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4812. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4813. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4814. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4815. rc = MBXERR_ERROR;
  4816. } else
  4817. lpfc_sli4_swap_str(phba, mboxq);
  4818. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4819. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4820. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4821. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4822. mboxq->vport ? mboxq->vport->vpi : 0,
  4823. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4824. bf_get(lpfc_mqe_status, mb),
  4825. mb->un.mb_words[0], mb->un.mb_words[1],
  4826. mb->un.mb_words[2], mb->un.mb_words[3],
  4827. mb->un.mb_words[4], mb->un.mb_words[5],
  4828. mb->un.mb_words[6], mb->un.mb_words[7],
  4829. mb->un.mb_words[8], mb->un.mb_words[9],
  4830. mb->un.mb_words[10], mb->un.mb_words[11],
  4831. mb->un.mb_words[12], mboxq->mcqe.word0,
  4832. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4833. mboxq->mcqe.trailer);
  4834. exit:
  4835. /* We are holding the token, no needed for lock when release */
  4836. spin_lock_irqsave(&phba->hbalock, iflag);
  4837. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4838. phba->sli.mbox_active = NULL;
  4839. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4840. return rc;
  4841. }
  4842. /**
  4843. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4844. * @phba: Pointer to HBA context object.
  4845. * @pmbox: Pointer to mailbox object.
  4846. * @flag: Flag indicating how the mailbox need to be processed.
  4847. *
  4848. * This function is called by discovery code and HBA management code to submit
  4849. * a mailbox command to firmware with SLI-4 interface spec.
  4850. *
  4851. * Return codes the caller owns the mailbox command after the return of the
  4852. * function.
  4853. **/
  4854. static int
  4855. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4856. uint32_t flag)
  4857. {
  4858. struct lpfc_sli *psli = &phba->sli;
  4859. unsigned long iflags;
  4860. int rc;
  4861. rc = lpfc_mbox_dev_check(phba);
  4862. if (unlikely(rc)) {
  4863. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4864. "(%d):2544 Mailbox command x%x (x%x) "
  4865. "cannot issue Data: x%x x%x\n",
  4866. mboxq->vport ? mboxq->vport->vpi : 0,
  4867. mboxq->u.mb.mbxCommand,
  4868. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4869. psli->sli_flag, flag);
  4870. goto out_not_finished;
  4871. }
  4872. /* Detect polling mode and jump to a handler */
  4873. if (!phba->sli4_hba.intr_enable) {
  4874. if (flag == MBX_POLL)
  4875. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4876. else
  4877. rc = -EIO;
  4878. if (rc != MBX_SUCCESS)
  4879. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4880. "(%d):2541 Mailbox command x%x "
  4881. "(x%x) cannot issue Data: x%x x%x\n",
  4882. mboxq->vport ? mboxq->vport->vpi : 0,
  4883. mboxq->u.mb.mbxCommand,
  4884. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4885. psli->sli_flag, flag);
  4886. return rc;
  4887. } else if (flag == MBX_POLL) {
  4888. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4889. "(%d):2542 Try to issue mailbox command "
  4890. "x%x (x%x) synchronously ahead of async"
  4891. "mailbox command queue: x%x x%x\n",
  4892. mboxq->vport ? mboxq->vport->vpi : 0,
  4893. mboxq->u.mb.mbxCommand,
  4894. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4895. psli->sli_flag, flag);
  4896. /* Try to block the asynchronous mailbox posting */
  4897. rc = lpfc_sli4_async_mbox_block(phba);
  4898. if (!rc) {
  4899. /* Successfully blocked, now issue sync mbox cmd */
  4900. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4901. if (rc != MBX_SUCCESS)
  4902. lpfc_printf_log(phba, KERN_ERR,
  4903. LOG_MBOX | LOG_SLI,
  4904. "(%d):2597 Mailbox command "
  4905. "x%x (x%x) cannot issue "
  4906. "Data: x%x x%x\n",
  4907. mboxq->vport ?
  4908. mboxq->vport->vpi : 0,
  4909. mboxq->u.mb.mbxCommand,
  4910. lpfc_sli4_mbox_opcode_get(phba,
  4911. mboxq),
  4912. psli->sli_flag, flag);
  4913. /* Unblock the async mailbox posting afterward */
  4914. lpfc_sli4_async_mbox_unblock(phba);
  4915. }
  4916. return rc;
  4917. }
  4918. /* Now, interrupt mode asynchrous mailbox command */
  4919. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4920. if (rc) {
  4921. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4922. "(%d):2543 Mailbox command x%x (x%x) "
  4923. "cannot issue Data: x%x x%x\n",
  4924. mboxq->vport ? mboxq->vport->vpi : 0,
  4925. mboxq->u.mb.mbxCommand,
  4926. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4927. psli->sli_flag, flag);
  4928. goto out_not_finished;
  4929. }
  4930. /* Put the mailbox command to the driver internal FIFO */
  4931. psli->slistat.mbox_busy++;
  4932. spin_lock_irqsave(&phba->hbalock, iflags);
  4933. lpfc_mbox_put(phba, mboxq);
  4934. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4935. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4936. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4937. "x%x (x%x) x%x x%x x%x\n",
  4938. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4939. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4940. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4941. phba->pport->port_state,
  4942. psli->sli_flag, MBX_NOWAIT);
  4943. /* Wake up worker thread to transport mailbox command from head */
  4944. lpfc_worker_wake_up(phba);
  4945. return MBX_BUSY;
  4946. out_not_finished:
  4947. return MBX_NOT_FINISHED;
  4948. }
  4949. /**
  4950. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4951. * @phba: Pointer to HBA context object.
  4952. *
  4953. * This function is called by worker thread to send a mailbox command to
  4954. * SLI4 HBA firmware.
  4955. *
  4956. **/
  4957. int
  4958. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4959. {
  4960. struct lpfc_sli *psli = &phba->sli;
  4961. LPFC_MBOXQ_t *mboxq;
  4962. int rc = MBX_SUCCESS;
  4963. unsigned long iflags;
  4964. struct lpfc_mqe *mqe;
  4965. uint32_t mbx_cmnd;
  4966. /* Check interrupt mode before post async mailbox command */
  4967. if (unlikely(!phba->sli4_hba.intr_enable))
  4968. return MBX_NOT_FINISHED;
  4969. /* Check for mailbox command service token */
  4970. spin_lock_irqsave(&phba->hbalock, iflags);
  4971. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4972. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4973. return MBX_NOT_FINISHED;
  4974. }
  4975. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4976. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4977. return MBX_NOT_FINISHED;
  4978. }
  4979. if (unlikely(phba->sli.mbox_active)) {
  4980. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4981. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4982. "0384 There is pending active mailbox cmd\n");
  4983. return MBX_NOT_FINISHED;
  4984. }
  4985. /* Take the mailbox command service token */
  4986. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4987. /* Get the next mailbox command from head of queue */
  4988. mboxq = lpfc_mbox_get(phba);
  4989. /* If no more mailbox command waiting for post, we're done */
  4990. if (!mboxq) {
  4991. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4992. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4993. return MBX_SUCCESS;
  4994. }
  4995. phba->sli.mbox_active = mboxq;
  4996. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4997. /* Check device readiness for posting mailbox command */
  4998. rc = lpfc_mbox_dev_check(phba);
  4999. if (unlikely(rc))
  5000. /* Driver clean routine will clean up pending mailbox */
  5001. goto out_not_finished;
  5002. /* Prepare the mbox command to be posted */
  5003. mqe = &mboxq->u.mqe;
  5004. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  5005. /* Start timer for the mbox_tmo and log some mailbox post messages */
  5006. mod_timer(&psli->mbox_tmo, (jiffies +
  5007. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  5008. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5009. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  5010. "x%x x%x\n",
  5011. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  5012. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5013. phba->pport->port_state, psli->sli_flag);
  5014. if (mbx_cmnd != MBX_HEARTBEAT) {
  5015. if (mboxq->vport) {
  5016. lpfc_debugfs_disc_trc(mboxq->vport,
  5017. LPFC_DISC_TRC_MBOX_VPORT,
  5018. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5019. mbx_cmnd, mqe->un.mb_words[0],
  5020. mqe->un.mb_words[1]);
  5021. } else {
  5022. lpfc_debugfs_disc_trc(phba->pport,
  5023. LPFC_DISC_TRC_MBOX,
  5024. "MBOX Send: cmd:x%x mb:x%x x%x",
  5025. mbx_cmnd, mqe->un.mb_words[0],
  5026. mqe->un.mb_words[1]);
  5027. }
  5028. }
  5029. psli->slistat.mbox_cmd++;
  5030. /* Post the mailbox command to the port */
  5031. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  5032. if (rc != MBX_SUCCESS) {
  5033. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5034. "(%d):2533 Mailbox command x%x (x%x) "
  5035. "cannot issue Data: x%x x%x\n",
  5036. mboxq->vport ? mboxq->vport->vpi : 0,
  5037. mboxq->u.mb.mbxCommand,
  5038. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  5039. psli->sli_flag, MBX_NOWAIT);
  5040. goto out_not_finished;
  5041. }
  5042. return rc;
  5043. out_not_finished:
  5044. spin_lock_irqsave(&phba->hbalock, iflags);
  5045. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5046. __lpfc_mbox_cmpl_put(phba, mboxq);
  5047. /* Release the token */
  5048. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5049. phba->sli.mbox_active = NULL;
  5050. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5051. return MBX_NOT_FINISHED;
  5052. }
  5053. /**
  5054. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  5055. * @phba: Pointer to HBA context object.
  5056. * @pmbox: Pointer to mailbox object.
  5057. * @flag: Flag indicating how the mailbox need to be processed.
  5058. *
  5059. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  5060. * the API jump table function pointer from the lpfc_hba struct.
  5061. *
  5062. * Return codes the caller owns the mailbox command after the return of the
  5063. * function.
  5064. **/
  5065. int
  5066. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  5067. {
  5068. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  5069. }
  5070. /**
  5071. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  5072. * @phba: The hba struct for which this call is being executed.
  5073. * @dev_grp: The HBA PCI-Device group number.
  5074. *
  5075. * This routine sets up the mbox interface API function jump table in @phba
  5076. * struct.
  5077. * Returns: 0 - success, -ENODEV - failure.
  5078. **/
  5079. int
  5080. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5081. {
  5082. switch (dev_grp) {
  5083. case LPFC_PCI_DEV_LP:
  5084. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  5085. phba->lpfc_sli_handle_slow_ring_event =
  5086. lpfc_sli_handle_slow_ring_event_s3;
  5087. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  5088. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  5089. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  5090. break;
  5091. case LPFC_PCI_DEV_OC:
  5092. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  5093. phba->lpfc_sli_handle_slow_ring_event =
  5094. lpfc_sli_handle_slow_ring_event_s4;
  5095. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  5096. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  5097. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  5098. break;
  5099. default:
  5100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5101. "1420 Invalid HBA PCI-device group: 0x%x\n",
  5102. dev_grp);
  5103. return -ENODEV;
  5104. break;
  5105. }
  5106. return 0;
  5107. }
  5108. /**
  5109. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  5110. * @phba: Pointer to HBA context object.
  5111. * @pring: Pointer to driver SLI ring object.
  5112. * @piocb: Pointer to address of newly added command iocb.
  5113. *
  5114. * This function is called with hbalock held to add a command
  5115. * iocb to the txq when SLI layer cannot submit the command iocb
  5116. * to the ring.
  5117. **/
  5118. void
  5119. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5120. struct lpfc_iocbq *piocb)
  5121. {
  5122. /* Insert the caller's iocb in the txq tail for later processing. */
  5123. list_add_tail(&piocb->list, &pring->txq);
  5124. pring->txq_cnt++;
  5125. }
  5126. /**
  5127. * lpfc_sli_next_iocb - Get the next iocb in the txq
  5128. * @phba: Pointer to HBA context object.
  5129. * @pring: Pointer to driver SLI ring object.
  5130. * @piocb: Pointer to address of newly added command iocb.
  5131. *
  5132. * This function is called with hbalock held before a new
  5133. * iocb is submitted to the firmware. This function checks
  5134. * txq to flush the iocbs in txq to Firmware before
  5135. * submitting new iocbs to the Firmware.
  5136. * If there are iocbs in the txq which need to be submitted
  5137. * to firmware, lpfc_sli_next_iocb returns the first element
  5138. * of the txq after dequeuing it from txq.
  5139. * If there is no iocb in the txq then the function will return
  5140. * *piocb and *piocb is set to NULL. Caller needs to check
  5141. * *piocb to find if there are more commands in the txq.
  5142. **/
  5143. static struct lpfc_iocbq *
  5144. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5145. struct lpfc_iocbq **piocb)
  5146. {
  5147. struct lpfc_iocbq * nextiocb;
  5148. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  5149. if (!nextiocb) {
  5150. nextiocb = *piocb;
  5151. *piocb = NULL;
  5152. }
  5153. return nextiocb;
  5154. }
  5155. /**
  5156. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  5157. * @phba: Pointer to HBA context object.
  5158. * @ring_number: SLI ring number to issue iocb on.
  5159. * @piocb: Pointer to command iocb.
  5160. * @flag: Flag indicating if this command can be put into txq.
  5161. *
  5162. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  5163. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  5164. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  5165. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  5166. * this function allows only iocbs for posting buffers. This function finds
  5167. * next available slot in the command ring and posts the command to the
  5168. * available slot and writes the port attention register to request HBA start
  5169. * processing new iocb. If there is no slot available in the ring and
  5170. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  5171. * the function returns IOCB_BUSY.
  5172. *
  5173. * This function is called with hbalock held. The function will return success
  5174. * after it successfully submit the iocb to firmware or after adding to the
  5175. * txq.
  5176. **/
  5177. static int
  5178. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  5179. struct lpfc_iocbq *piocb, uint32_t flag)
  5180. {
  5181. struct lpfc_iocbq *nextiocb;
  5182. IOCB_t *iocb;
  5183. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5184. if (piocb->iocb_cmpl && (!piocb->vport) &&
  5185. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  5186. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  5187. lpfc_printf_log(phba, KERN_ERR,
  5188. LOG_SLI | LOG_VPORT,
  5189. "1807 IOCB x%x failed. No vport\n",
  5190. piocb->iocb.ulpCommand);
  5191. dump_stack();
  5192. return IOCB_ERROR;
  5193. }
  5194. /* If the PCI channel is in offline state, do not post iocbs. */
  5195. if (unlikely(pci_channel_offline(phba->pcidev)))
  5196. return IOCB_ERROR;
  5197. /* If HBA has a deferred error attention, fail the iocb. */
  5198. if (unlikely(phba->hba_flag & DEFER_ERATT))
  5199. return IOCB_ERROR;
  5200. /*
  5201. * We should never get an IOCB if we are in a < LINK_DOWN state
  5202. */
  5203. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5204. return IOCB_ERROR;
  5205. /*
  5206. * Check to see if we are blocking IOCB processing because of a
  5207. * outstanding event.
  5208. */
  5209. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5210. goto iocb_busy;
  5211. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5212. /*
  5213. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5214. * can be issued if the link is not up.
  5215. */
  5216. switch (piocb->iocb.ulpCommand) {
  5217. case CMD_GEN_REQUEST64_CR:
  5218. case CMD_GEN_REQUEST64_CX:
  5219. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5220. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5221. FC_RCTL_DD_UNSOL_CMD) ||
  5222. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5223. MENLO_TRANSPORT_TYPE))
  5224. goto iocb_busy;
  5225. break;
  5226. case CMD_QUE_RING_BUF_CN:
  5227. case CMD_QUE_RING_BUF64_CN:
  5228. /*
  5229. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5230. * completion, iocb_cmpl MUST be 0.
  5231. */
  5232. if (piocb->iocb_cmpl)
  5233. piocb->iocb_cmpl = NULL;
  5234. /*FALLTHROUGH*/
  5235. case CMD_CREATE_XRI_CR:
  5236. case CMD_CLOSE_XRI_CN:
  5237. case CMD_CLOSE_XRI_CX:
  5238. break;
  5239. default:
  5240. goto iocb_busy;
  5241. }
  5242. /*
  5243. * For FCP commands, we must be in a state where we can process link
  5244. * attention events.
  5245. */
  5246. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5247. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5248. goto iocb_busy;
  5249. }
  5250. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5251. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5252. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5253. if (iocb)
  5254. lpfc_sli_update_ring(phba, pring);
  5255. else
  5256. lpfc_sli_update_full_ring(phba, pring);
  5257. if (!piocb)
  5258. return IOCB_SUCCESS;
  5259. goto out_busy;
  5260. iocb_busy:
  5261. pring->stats.iocb_cmd_delay++;
  5262. out_busy:
  5263. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5264. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5265. return IOCB_SUCCESS;
  5266. }
  5267. return IOCB_BUSY;
  5268. }
  5269. /**
  5270. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5271. * @phba: Pointer to HBA context object.
  5272. * @piocb: Pointer to command iocb.
  5273. * @sglq: Pointer to the scatter gather queue object.
  5274. *
  5275. * This routine converts the bpl or bde that is in the IOCB
  5276. * to a sgl list for the sli4 hardware. The physical address
  5277. * of the bpl/bde is converted back to a virtual address.
  5278. * If the IOCB contains a BPL then the list of BDE's is
  5279. * converted to sli4_sge's. If the IOCB contains a single
  5280. * BDE then it is converted to a single sli_sge.
  5281. * The IOCB is still in cpu endianess so the contents of
  5282. * the bpl can be used without byte swapping.
  5283. *
  5284. * Returns valid XRI = Success, NO_XRI = Failure.
  5285. **/
  5286. static uint16_t
  5287. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5288. struct lpfc_sglq *sglq)
  5289. {
  5290. uint16_t xritag = NO_XRI;
  5291. struct ulp_bde64 *bpl = NULL;
  5292. struct ulp_bde64 bde;
  5293. struct sli4_sge *sgl = NULL;
  5294. IOCB_t *icmd;
  5295. int numBdes = 0;
  5296. int i = 0;
  5297. if (!piocbq || !sglq)
  5298. return xritag;
  5299. sgl = (struct sli4_sge *)sglq->sgl;
  5300. icmd = &piocbq->iocb;
  5301. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5302. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5303. sizeof(struct ulp_bde64);
  5304. /* The addrHigh and addrLow fields within the IOCB
  5305. * have not been byteswapped yet so there is no
  5306. * need to swap them back.
  5307. */
  5308. bpl = (struct ulp_bde64 *)
  5309. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5310. if (!bpl)
  5311. return xritag;
  5312. for (i = 0; i < numBdes; i++) {
  5313. /* Should already be byte swapped. */
  5314. sgl->addr_hi = bpl->addrHigh;
  5315. sgl->addr_lo = bpl->addrLow;
  5316. if ((i+1) == numBdes)
  5317. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5318. else
  5319. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5320. sgl->word2 = cpu_to_le32(sgl->word2);
  5321. /* swap the size field back to the cpu so we
  5322. * can assign it to the sgl.
  5323. */
  5324. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5325. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  5326. bpl++;
  5327. sgl++;
  5328. }
  5329. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5330. /* The addrHigh and addrLow fields of the BDE have not
  5331. * been byteswapped yet so they need to be swapped
  5332. * before putting them in the sgl.
  5333. */
  5334. sgl->addr_hi =
  5335. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5336. sgl->addr_lo =
  5337. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5338. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5339. sgl->word2 = cpu_to_le32(sgl->word2);
  5340. sgl->sge_len =
  5341. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  5342. }
  5343. return sglq->sli4_xritag;
  5344. }
  5345. /**
  5346. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5347. * @phba: Pointer to HBA context object.
  5348. *
  5349. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  5350. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  5351. * held.
  5352. *
  5353. * Return: index into SLI4 fast-path FCP queue index.
  5354. **/
  5355. static uint32_t
  5356. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  5357. {
  5358. ++phba->fcp_qidx;
  5359. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  5360. phba->fcp_qidx = 0;
  5361. return phba->fcp_qidx;
  5362. }
  5363. /**
  5364. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5365. * @phba: Pointer to HBA context object.
  5366. * @piocb: Pointer to command iocb.
  5367. * @wqe: Pointer to the work queue entry.
  5368. *
  5369. * This routine converts the iocb command to its Work Queue Entry
  5370. * equivalent. The wqe pointer should not have any fields set when
  5371. * this routine is called because it will memcpy over them.
  5372. * This routine does not set the CQ_ID or the WQEC bits in the
  5373. * wqe.
  5374. *
  5375. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5376. **/
  5377. static int
  5378. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5379. union lpfc_wqe *wqe)
  5380. {
  5381. uint32_t xmit_len = 0, total_len = 0;
  5382. uint8_t ct = 0;
  5383. uint32_t fip;
  5384. uint32_t abort_tag;
  5385. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5386. uint8_t cmnd;
  5387. uint16_t xritag;
  5388. uint16_t abrt_iotag;
  5389. struct lpfc_iocbq *abrtiocbq;
  5390. struct ulp_bde64 *bpl = NULL;
  5391. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  5392. int numBdes, i;
  5393. struct ulp_bde64 bde;
  5394. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  5395. /* The fcp commands will set command type */
  5396. if (iocbq->iocb_flag & LPFC_IO_FCP)
  5397. command_type = FCP_COMMAND;
  5398. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  5399. command_type = ELS_COMMAND_FIP;
  5400. else
  5401. command_type = ELS_COMMAND_NON_FIP;
  5402. /* Some of the fields are in the right position already */
  5403. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5404. abort_tag = (uint32_t) iocbq->iotag;
  5405. xritag = iocbq->sli4_xritag;
  5406. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  5407. /* words0-2 bpl convert bde */
  5408. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5409. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  5410. sizeof(struct ulp_bde64);
  5411. bpl = (struct ulp_bde64 *)
  5412. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5413. if (!bpl)
  5414. return IOCB_ERROR;
  5415. /* Should already be byte swapped. */
  5416. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5417. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5418. /* swap the size field back to the cpu so we
  5419. * can assign it to the sgl.
  5420. */
  5421. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5422. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  5423. total_len = 0;
  5424. for (i = 0; i < numBdes; i++) {
  5425. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  5426. total_len += bde.tus.f.bdeSize;
  5427. }
  5428. } else
  5429. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5430. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5431. cmnd = iocbq->iocb.ulpCommand;
  5432. switch (iocbq->iocb.ulpCommand) {
  5433. case CMD_ELS_REQUEST64_CR:
  5434. if (!iocbq->iocb.ulpLe) {
  5435. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5436. "2007 Only Limited Edition cmd Format"
  5437. " supported 0x%x\n",
  5438. iocbq->iocb.ulpCommand);
  5439. return IOCB_ERROR;
  5440. }
  5441. wqe->els_req.payload_len = xmit_len;
  5442. /* Els_reguest64 has a TMO */
  5443. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5444. iocbq->iocb.ulpTimeout);
  5445. /* Need a VF for word 4 set the vf bit*/
  5446. bf_set(els_req64_vf, &wqe->els_req, 0);
  5447. /* And a VFID for word 12 */
  5448. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5449. /*
  5450. * Set ct field to 3, indicates that the context_tag field
  5451. * contains the FCFI and remote N_Port_ID is
  5452. * in word 5.
  5453. */
  5454. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5455. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  5456. iocbq->iocb.ulpContext);
  5457. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  5458. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  5459. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5460. if (command_type == ELS_COMMAND_FIP) {
  5461. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  5462. >> LPFC_FIP_ELS_ID_SHIFT);
  5463. }
  5464. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  5465. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  5466. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  5467. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  5468. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5469. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  5470. break;
  5471. case CMD_XMIT_SEQUENCE64_CX:
  5472. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  5473. iocbq->iocb.un.ulpWord[3]);
  5474. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  5475. iocbq->iocb.ulpContext);
  5476. /* The entire sequence is transmitted for this IOCB */
  5477. xmit_len = total_len;
  5478. cmnd = CMD_XMIT_SEQUENCE64_CR;
  5479. case CMD_XMIT_SEQUENCE64_CR:
  5480. /* word3 iocb=io_tag32 wqe=reserved */
  5481. wqe->xmit_sequence.rsvd3 = 0;
  5482. /* word4 relative_offset memcpy */
  5483. /* word5 r_ctl/df_ctl memcpy */
  5484. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  5485. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  5486. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  5487. LPFC_WQE_IOD_WRITE);
  5488. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  5489. LPFC_WQE_LENLOC_WORD12);
  5490. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  5491. wqe->xmit_sequence.xmit_len = xmit_len;
  5492. command_type = OTHER_COMMAND;
  5493. break;
  5494. case CMD_XMIT_BCAST64_CN:
  5495. /* word3 iocb=iotag32 wqe=seq_payload_len */
  5496. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  5497. /* word4 iocb=rsvd wqe=rsvd */
  5498. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5499. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5500. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  5501. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5502. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  5503. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  5504. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  5505. LPFC_WQE_LENLOC_WORD3);
  5506. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  5507. break;
  5508. case CMD_FCP_IWRITE64_CR:
  5509. command_type = FCP_COMMAND_DATA_OUT;
  5510. /* word3 iocb=iotag wqe=payload_offset_len */
  5511. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5512. wqe->fcp_iwrite.payload_offset_len =
  5513. xmit_len + sizeof(struct fcp_rsp);
  5514. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5515. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5516. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  5517. iocbq->iocb.ulpFCP2Rcvy);
  5518. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  5519. /* Always open the exchange */
  5520. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  5521. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  5522. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  5523. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  5524. LPFC_WQE_LENLOC_WORD4);
  5525. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  5526. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  5527. break;
  5528. case CMD_FCP_IREAD64_CR:
  5529. /* word3 iocb=iotag wqe=payload_offset_len */
  5530. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  5531. wqe->fcp_iread.payload_offset_len =
  5532. xmit_len + sizeof(struct fcp_rsp);
  5533. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  5534. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  5535. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  5536. iocbq->iocb.ulpFCP2Rcvy);
  5537. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  5538. /* Always open the exchange */
  5539. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5540. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  5541. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  5542. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  5543. LPFC_WQE_LENLOC_WORD4);
  5544. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  5545. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  5546. break;
  5547. case CMD_FCP_ICMND64_CR:
  5548. /* word3 iocb=IO_TAG wqe=reserved */
  5549. wqe->fcp_icmd.rsrvd3 = 0;
  5550. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  5551. /* Always open the exchange */
  5552. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  5553. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  5554. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  5555. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  5556. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  5557. LPFC_WQE_LENLOC_NONE);
  5558. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  5559. break;
  5560. case CMD_GEN_REQUEST64_CR:
  5561. /* word3 iocb=IO_TAG wqe=request_payload_len */
  5562. wqe->gen_req.request_payload_len = xmit_len;
  5563. /* word4 iocb=parameter wqe=relative_offset memcpy */
  5564. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  5565. /* word6 context tag copied in memcpy */
  5566. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5567. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5568. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5569. "2015 Invalid CT %x command 0x%x\n",
  5570. ct, iocbq->iocb.ulpCommand);
  5571. return IOCB_ERROR;
  5572. }
  5573. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  5574. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  5575. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  5576. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  5577. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  5578. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  5579. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  5580. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  5581. command_type = OTHER_COMMAND;
  5582. break;
  5583. case CMD_XMIT_ELS_RSP64_CX:
  5584. /* words0-2 BDE memcpy */
  5585. /* word3 iocb=iotag32 wqe=response_payload_len */
  5586. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  5587. /* word4 iocb=did wge=rsvd. */
  5588. wqe->xmit_els_rsp.rsvd4 = 0;
  5589. /* word5 iocb=rsvd wge=did */
  5590. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5591. iocbq->iocb.un.elsreq64.remoteID);
  5592. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  5593. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5594. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  5595. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5596. iocbq->iocb.ulpContext);
  5597. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5598. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5599. iocbq->vport->vpi + phba->vpi_base);
  5600. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  5601. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  5602. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  5603. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  5604. LPFC_WQE_LENLOC_WORD3);
  5605. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  5606. command_type = OTHER_COMMAND;
  5607. break;
  5608. case CMD_CLOSE_XRI_CN:
  5609. case CMD_ABORT_XRI_CN:
  5610. case CMD_ABORT_XRI_CX:
  5611. /* words 0-2 memcpy should be 0 rserved */
  5612. /* port will send abts */
  5613. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  5614. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  5615. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  5616. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  5617. } else
  5618. fip = 0;
  5619. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  5620. /*
  5621. * The link is down, or the command was ELS_FIP
  5622. * so the fw does not need to send abts
  5623. * on the wire.
  5624. */
  5625. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5626. else
  5627. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5628. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5629. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  5630. wqe->abort_cmd.rsrvd5 = 0;
  5631. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  5632. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5633. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5634. /*
  5635. * The abort handler will send us CMD_ABORT_XRI_CN or
  5636. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5637. */
  5638. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  5639. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  5640. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  5641. LPFC_WQE_LENLOC_NONE);
  5642. cmnd = CMD_ABORT_XRI_CX;
  5643. command_type = OTHER_COMMAND;
  5644. xritag = 0;
  5645. break;
  5646. case CMD_XMIT_BLS_RSP64_CX:
  5647. /* As BLS ABTS-ACC WQE is very different from other WQEs,
  5648. * we re-construct this WQE here based on information in
  5649. * iocbq from scratch.
  5650. */
  5651. memset(wqe, 0, sizeof(union lpfc_wqe));
  5652. /* OX_ID is invariable to who sent ABTS to CT exchange */
  5653. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  5654. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc));
  5655. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) ==
  5656. LPFC_ABTS_UNSOL_INT) {
  5657. /* ABTS sent by initiator to CT exchange, the
  5658. * RX_ID field will be filled with the newly
  5659. * allocated responder XRI.
  5660. */
  5661. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5662. iocbq->sli4_xritag);
  5663. } else {
  5664. /* ABTS sent by responder to CT exchange, the
  5665. * RX_ID field will be filled with the responder
  5666. * RX_ID from ABTS.
  5667. */
  5668. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  5669. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc));
  5670. }
  5671. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  5672. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  5673. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  5674. iocbq->iocb.ulpContext);
  5675. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  5676. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  5677. LPFC_WQE_LENLOC_NONE);
  5678. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  5679. command_type = OTHER_COMMAND;
  5680. break;
  5681. case CMD_XRI_ABORTED_CX:
  5682. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5683. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5684. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5685. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5686. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5687. default:
  5688. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5689. "2014 Invalid command 0x%x\n",
  5690. iocbq->iocb.ulpCommand);
  5691. return IOCB_ERROR;
  5692. break;
  5693. }
  5694. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  5695. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  5696. wqe->generic.wqe_com.abort_tag = abort_tag;
  5697. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  5698. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  5699. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  5700. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  5701. return 0;
  5702. }
  5703. /**
  5704. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5705. * @phba: Pointer to HBA context object.
  5706. * @ring_number: SLI ring number to issue iocb on.
  5707. * @piocb: Pointer to command iocb.
  5708. * @flag: Flag indicating if this command can be put into txq.
  5709. *
  5710. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5711. * an iocb command to an HBA with SLI-4 interface spec.
  5712. *
  5713. * This function is called with hbalock held. The function will return success
  5714. * after it successfully submit the iocb to firmware or after adding to the
  5715. * txq.
  5716. **/
  5717. static int
  5718. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5719. struct lpfc_iocbq *piocb, uint32_t flag)
  5720. {
  5721. struct lpfc_sglq *sglq;
  5722. union lpfc_wqe wqe;
  5723. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5724. if (piocb->sli4_xritag == NO_XRI) {
  5725. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5726. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5727. sglq = NULL;
  5728. else {
  5729. if (pring->txq_cnt) {
  5730. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5731. __lpfc_sli_ringtx_put(phba,
  5732. pring, piocb);
  5733. return IOCB_SUCCESS;
  5734. } else {
  5735. return IOCB_BUSY;
  5736. }
  5737. } else {
  5738. sglq = __lpfc_sli_get_sglq(phba);
  5739. if (!sglq) {
  5740. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5741. __lpfc_sli_ringtx_put(phba,
  5742. pring,
  5743. piocb);
  5744. return IOCB_SUCCESS;
  5745. } else
  5746. return IOCB_BUSY;
  5747. }
  5748. }
  5749. }
  5750. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5751. sglq = NULL; /* These IO's already have an XRI and
  5752. * a mapped sgl.
  5753. */
  5754. } else {
  5755. /* This is a continuation of a commandi,(CX) so this
  5756. * sglq is on the active list
  5757. */
  5758. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5759. if (!sglq)
  5760. return IOCB_ERROR;
  5761. }
  5762. if (sglq) {
  5763. piocb->sli4_xritag = sglq->sli4_xritag;
  5764. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  5765. return IOCB_ERROR;
  5766. }
  5767. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5768. return IOCB_ERROR;
  5769. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  5770. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  5771. /*
  5772. * For FCP command IOCB, get a new WQ index to distribute
  5773. * WQE across the WQsr. On the other hand, for abort IOCB,
  5774. * it carries the same WQ index to the original command
  5775. * IOCB.
  5776. */
  5777. if (piocb->iocb_flag & LPFC_IO_FCP)
  5778. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  5779. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  5780. &wqe))
  5781. return IOCB_ERROR;
  5782. } else {
  5783. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5784. return IOCB_ERROR;
  5785. }
  5786. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5787. return 0;
  5788. }
  5789. /**
  5790. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5791. *
  5792. * This routine wraps the actual lockless version for issusing IOCB function
  5793. * pointer from the lpfc_hba struct.
  5794. *
  5795. * Return codes:
  5796. * IOCB_ERROR - Error
  5797. * IOCB_SUCCESS - Success
  5798. * IOCB_BUSY - Busy
  5799. **/
  5800. int
  5801. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5802. struct lpfc_iocbq *piocb, uint32_t flag)
  5803. {
  5804. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5805. }
  5806. /**
  5807. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5808. * @phba: The hba struct for which this call is being executed.
  5809. * @dev_grp: The HBA PCI-Device group number.
  5810. *
  5811. * This routine sets up the SLI interface API function jump table in @phba
  5812. * struct.
  5813. * Returns: 0 - success, -ENODEV - failure.
  5814. **/
  5815. int
  5816. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5817. {
  5818. switch (dev_grp) {
  5819. case LPFC_PCI_DEV_LP:
  5820. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5821. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5822. break;
  5823. case LPFC_PCI_DEV_OC:
  5824. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5825. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5826. break;
  5827. default:
  5828. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5829. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5830. dev_grp);
  5831. return -ENODEV;
  5832. break;
  5833. }
  5834. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5835. return 0;
  5836. }
  5837. /**
  5838. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5839. * @phba: Pointer to HBA context object.
  5840. * @pring: Pointer to driver SLI ring object.
  5841. * @piocb: Pointer to command iocb.
  5842. * @flag: Flag indicating if this command can be put into txq.
  5843. *
  5844. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5845. * function. This function gets the hbalock and calls
  5846. * __lpfc_sli_issue_iocb function and will return the error returned
  5847. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5848. * functions which do not hold hbalock.
  5849. **/
  5850. int
  5851. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5852. struct lpfc_iocbq *piocb, uint32_t flag)
  5853. {
  5854. unsigned long iflags;
  5855. int rc;
  5856. spin_lock_irqsave(&phba->hbalock, iflags);
  5857. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5858. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5859. return rc;
  5860. }
  5861. /**
  5862. * lpfc_extra_ring_setup - Extra ring setup function
  5863. * @phba: Pointer to HBA context object.
  5864. *
  5865. * This function is called while driver attaches with the
  5866. * HBA to setup the extra ring. The extra ring is used
  5867. * only when driver needs to support target mode functionality
  5868. * or IP over FC functionalities.
  5869. *
  5870. * This function is called with no lock held.
  5871. **/
  5872. static int
  5873. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5874. {
  5875. struct lpfc_sli *psli;
  5876. struct lpfc_sli_ring *pring;
  5877. psli = &phba->sli;
  5878. /* Adjust cmd/rsp ring iocb entries more evenly */
  5879. /* Take some away from the FCP ring */
  5880. pring = &psli->ring[psli->fcp_ring];
  5881. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5882. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5883. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5884. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5885. /* and give them to the extra ring */
  5886. pring = &psli->ring[psli->extra_ring];
  5887. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5888. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5889. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5890. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5891. /* Setup default profile for this ring */
  5892. pring->iotag_max = 4096;
  5893. pring->num_mask = 1;
  5894. pring->prt[0].profile = 0; /* Mask 0 */
  5895. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5896. pring->prt[0].type = phba->cfg_multi_ring_type;
  5897. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5898. return 0;
  5899. }
  5900. /**
  5901. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5902. * @phba: Pointer to HBA context object.
  5903. * @pring: Pointer to driver SLI ring object.
  5904. * @iocbq: Pointer to iocb object.
  5905. *
  5906. * This function is called by the slow ring event handler
  5907. * function when there is an ASYNC event iocb in the ring.
  5908. * This function is called with no lock held.
  5909. * Currently this function handles only temperature related
  5910. * ASYNC events. The function decodes the temperature sensor
  5911. * event message and posts events for the management applications.
  5912. **/
  5913. static void
  5914. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5915. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5916. {
  5917. IOCB_t *icmd;
  5918. uint16_t evt_code;
  5919. uint16_t temp;
  5920. struct temp_event temp_event_data;
  5921. struct Scsi_Host *shost;
  5922. uint32_t *iocb_w;
  5923. icmd = &iocbq->iocb;
  5924. evt_code = icmd->un.asyncstat.evt_code;
  5925. temp = icmd->ulpContext;
  5926. if ((evt_code != ASYNC_TEMP_WARN) &&
  5927. (evt_code != ASYNC_TEMP_SAFE)) {
  5928. iocb_w = (uint32_t *) icmd;
  5929. lpfc_printf_log(phba,
  5930. KERN_ERR,
  5931. LOG_SLI,
  5932. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5933. " evt_code 0x%x\n"
  5934. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5935. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5936. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5937. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5938. pring->ringno,
  5939. icmd->un.asyncstat.evt_code,
  5940. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5941. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5942. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5943. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5944. return;
  5945. }
  5946. temp_event_data.data = (uint32_t)temp;
  5947. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5948. if (evt_code == ASYNC_TEMP_WARN) {
  5949. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5950. lpfc_printf_log(phba,
  5951. KERN_ERR,
  5952. LOG_TEMP,
  5953. "0347 Adapter is very hot, please take "
  5954. "corrective action. temperature : %d Celsius\n",
  5955. temp);
  5956. }
  5957. if (evt_code == ASYNC_TEMP_SAFE) {
  5958. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5959. lpfc_printf_log(phba,
  5960. KERN_ERR,
  5961. LOG_TEMP,
  5962. "0340 Adapter temperature is OK now. "
  5963. "temperature : %d Celsius\n",
  5964. temp);
  5965. }
  5966. /* Send temperature change event to applications */
  5967. shost = lpfc_shost_from_vport(phba->pport);
  5968. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5969. sizeof(temp_event_data), (char *) &temp_event_data,
  5970. LPFC_NL_VENDOR_ID);
  5971. }
  5972. /**
  5973. * lpfc_sli_setup - SLI ring setup function
  5974. * @phba: Pointer to HBA context object.
  5975. *
  5976. * lpfc_sli_setup sets up rings of the SLI interface with
  5977. * number of iocbs per ring and iotags. This function is
  5978. * called while driver attach to the HBA and before the
  5979. * interrupts are enabled. So there is no need for locking.
  5980. *
  5981. * This function always returns 0.
  5982. **/
  5983. int
  5984. lpfc_sli_setup(struct lpfc_hba *phba)
  5985. {
  5986. int i, totiocbsize = 0;
  5987. struct lpfc_sli *psli = &phba->sli;
  5988. struct lpfc_sli_ring *pring;
  5989. psli->num_rings = MAX_CONFIGURED_RINGS;
  5990. psli->sli_flag = 0;
  5991. psli->fcp_ring = LPFC_FCP_RING;
  5992. psli->next_ring = LPFC_FCP_NEXT_RING;
  5993. psli->extra_ring = LPFC_EXTRA_RING;
  5994. psli->iocbq_lookup = NULL;
  5995. psli->iocbq_lookup_len = 0;
  5996. psli->last_iotag = 0;
  5997. for (i = 0; i < psli->num_rings; i++) {
  5998. pring = &psli->ring[i];
  5999. switch (i) {
  6000. case LPFC_FCP_RING: /* ring 0 - FCP */
  6001. /* numCiocb and numRiocb are used in config_port */
  6002. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  6003. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  6004. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  6005. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  6006. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  6007. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  6008. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6009. SLI3_IOCB_CMD_SIZE :
  6010. SLI2_IOCB_CMD_SIZE;
  6011. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6012. SLI3_IOCB_RSP_SIZE :
  6013. SLI2_IOCB_RSP_SIZE;
  6014. pring->iotag_ctr = 0;
  6015. pring->iotag_max =
  6016. (phba->cfg_hba_queue_depth * 2);
  6017. pring->fast_iotag = pring->iotag_max;
  6018. pring->num_mask = 0;
  6019. break;
  6020. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  6021. /* numCiocb and numRiocb are used in config_port */
  6022. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  6023. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  6024. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6025. SLI3_IOCB_CMD_SIZE :
  6026. SLI2_IOCB_CMD_SIZE;
  6027. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6028. SLI3_IOCB_RSP_SIZE :
  6029. SLI2_IOCB_RSP_SIZE;
  6030. pring->iotag_max = phba->cfg_hba_queue_depth;
  6031. pring->num_mask = 0;
  6032. break;
  6033. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  6034. /* numCiocb and numRiocb are used in config_port */
  6035. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  6036. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  6037. pring->sizeCiocb = (phba->sli_rev == 3) ?
  6038. SLI3_IOCB_CMD_SIZE :
  6039. SLI2_IOCB_CMD_SIZE;
  6040. pring->sizeRiocb = (phba->sli_rev == 3) ?
  6041. SLI3_IOCB_RSP_SIZE :
  6042. SLI2_IOCB_RSP_SIZE;
  6043. pring->fast_iotag = 0;
  6044. pring->iotag_ctr = 0;
  6045. pring->iotag_max = 4096;
  6046. pring->lpfc_sli_rcv_async_status =
  6047. lpfc_sli_async_event_handler;
  6048. pring->num_mask = LPFC_MAX_RING_MASK;
  6049. pring->prt[0].profile = 0; /* Mask 0 */
  6050. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  6051. pring->prt[0].type = FC_TYPE_ELS;
  6052. pring->prt[0].lpfc_sli_rcv_unsol_event =
  6053. lpfc_els_unsol_event;
  6054. pring->prt[1].profile = 0; /* Mask 1 */
  6055. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  6056. pring->prt[1].type = FC_TYPE_ELS;
  6057. pring->prt[1].lpfc_sli_rcv_unsol_event =
  6058. lpfc_els_unsol_event;
  6059. pring->prt[2].profile = 0; /* Mask 2 */
  6060. /* NameServer Inquiry */
  6061. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  6062. /* NameServer */
  6063. pring->prt[2].type = FC_TYPE_CT;
  6064. pring->prt[2].lpfc_sli_rcv_unsol_event =
  6065. lpfc_ct_unsol_event;
  6066. pring->prt[3].profile = 0; /* Mask 3 */
  6067. /* NameServer response */
  6068. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  6069. /* NameServer */
  6070. pring->prt[3].type = FC_TYPE_CT;
  6071. pring->prt[3].lpfc_sli_rcv_unsol_event =
  6072. lpfc_ct_unsol_event;
  6073. /* abort unsolicited sequence */
  6074. pring->prt[4].profile = 0; /* Mask 4 */
  6075. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  6076. pring->prt[4].type = FC_TYPE_BLS;
  6077. pring->prt[4].lpfc_sli_rcv_unsol_event =
  6078. lpfc_sli4_ct_abort_unsol_event;
  6079. break;
  6080. }
  6081. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  6082. (pring->numRiocb * pring->sizeRiocb);
  6083. }
  6084. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  6085. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  6086. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  6087. "SLI2 SLIM Data: x%x x%lx\n",
  6088. phba->brd_no, totiocbsize,
  6089. (unsigned long) MAX_SLIM_IOCB_SIZE);
  6090. }
  6091. if (phba->cfg_multi_ring_support == 2)
  6092. lpfc_extra_ring_setup(phba);
  6093. return 0;
  6094. }
  6095. /**
  6096. * lpfc_sli_queue_setup - Queue initialization function
  6097. * @phba: Pointer to HBA context object.
  6098. *
  6099. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  6100. * ring. This function also initializes ring indices of each ring.
  6101. * This function is called during the initialization of the SLI
  6102. * interface of an HBA.
  6103. * This function is called with no lock held and always returns
  6104. * 1.
  6105. **/
  6106. int
  6107. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  6108. {
  6109. struct lpfc_sli *psli;
  6110. struct lpfc_sli_ring *pring;
  6111. int i;
  6112. psli = &phba->sli;
  6113. spin_lock_irq(&phba->hbalock);
  6114. INIT_LIST_HEAD(&psli->mboxq);
  6115. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  6116. /* Initialize list headers for txq and txcmplq as double linked lists */
  6117. for (i = 0; i < psli->num_rings; i++) {
  6118. pring = &psli->ring[i];
  6119. pring->ringno = i;
  6120. pring->next_cmdidx = 0;
  6121. pring->local_getidx = 0;
  6122. pring->cmdidx = 0;
  6123. INIT_LIST_HEAD(&pring->txq);
  6124. INIT_LIST_HEAD(&pring->txcmplq);
  6125. INIT_LIST_HEAD(&pring->iocb_continueq);
  6126. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  6127. INIT_LIST_HEAD(&pring->postbufq);
  6128. }
  6129. spin_unlock_irq(&phba->hbalock);
  6130. return 1;
  6131. }
  6132. /**
  6133. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  6134. * @phba: Pointer to HBA context object.
  6135. *
  6136. * This routine flushes the mailbox command subsystem. It will unconditionally
  6137. * flush all the mailbox commands in the three possible stages in the mailbox
  6138. * command sub-system: pending mailbox command queue; the outstanding mailbox
  6139. * command; and completed mailbox command queue. It is caller's responsibility
  6140. * to make sure that the driver is in the proper state to flush the mailbox
  6141. * command sub-system. Namely, the posting of mailbox commands into the
  6142. * pending mailbox command queue from the various clients must be stopped;
  6143. * either the HBA is in a state that it will never works on the outstanding
  6144. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  6145. * mailbox command has been completed.
  6146. **/
  6147. static void
  6148. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  6149. {
  6150. LIST_HEAD(completions);
  6151. struct lpfc_sli *psli = &phba->sli;
  6152. LPFC_MBOXQ_t *pmb;
  6153. unsigned long iflag;
  6154. /* Flush all the mailbox commands in the mbox system */
  6155. spin_lock_irqsave(&phba->hbalock, iflag);
  6156. /* The pending mailbox command queue */
  6157. list_splice_init(&phba->sli.mboxq, &completions);
  6158. /* The outstanding active mailbox command */
  6159. if (psli->mbox_active) {
  6160. list_add_tail(&psli->mbox_active->list, &completions);
  6161. psli->mbox_active = NULL;
  6162. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6163. }
  6164. /* The completed mailbox command queue */
  6165. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  6166. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6167. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  6168. while (!list_empty(&completions)) {
  6169. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  6170. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6171. if (pmb->mbox_cmpl)
  6172. pmb->mbox_cmpl(phba, pmb);
  6173. }
  6174. }
  6175. /**
  6176. * lpfc_sli_host_down - Vport cleanup function
  6177. * @vport: Pointer to virtual port object.
  6178. *
  6179. * lpfc_sli_host_down is called to clean up the resources
  6180. * associated with a vport before destroying virtual
  6181. * port data structures.
  6182. * This function does following operations:
  6183. * - Free discovery resources associated with this virtual
  6184. * port.
  6185. * - Free iocbs associated with this virtual port in
  6186. * the txq.
  6187. * - Send abort for all iocb commands associated with this
  6188. * vport in txcmplq.
  6189. *
  6190. * This function is called with no lock held and always returns 1.
  6191. **/
  6192. int
  6193. lpfc_sli_host_down(struct lpfc_vport *vport)
  6194. {
  6195. LIST_HEAD(completions);
  6196. struct lpfc_hba *phba = vport->phba;
  6197. struct lpfc_sli *psli = &phba->sli;
  6198. struct lpfc_sli_ring *pring;
  6199. struct lpfc_iocbq *iocb, *next_iocb;
  6200. int i;
  6201. unsigned long flags = 0;
  6202. uint16_t prev_pring_flag;
  6203. lpfc_cleanup_discovery_resources(vport);
  6204. spin_lock_irqsave(&phba->hbalock, flags);
  6205. for (i = 0; i < psli->num_rings; i++) {
  6206. pring = &psli->ring[i];
  6207. prev_pring_flag = pring->flag;
  6208. /* Only slow rings */
  6209. if (pring->ringno == LPFC_ELS_RING) {
  6210. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6211. /* Set the lpfc data pending flag */
  6212. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6213. }
  6214. /*
  6215. * Error everything on the txq since these iocbs have not been
  6216. * given to the FW yet.
  6217. */
  6218. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  6219. if (iocb->vport != vport)
  6220. continue;
  6221. list_move_tail(&iocb->list, &completions);
  6222. pring->txq_cnt--;
  6223. }
  6224. /* Next issue ABTS for everything on the txcmplq */
  6225. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  6226. list) {
  6227. if (iocb->vport != vport)
  6228. continue;
  6229. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  6230. }
  6231. pring->flag = prev_pring_flag;
  6232. }
  6233. spin_unlock_irqrestore(&phba->hbalock, flags);
  6234. /* Cancel all the IOCBs from the completions list */
  6235. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6236. IOERR_SLI_DOWN);
  6237. return 1;
  6238. }
  6239. /**
  6240. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  6241. * @phba: Pointer to HBA context object.
  6242. *
  6243. * This function cleans up all iocb, buffers, mailbox commands
  6244. * while shutting down the HBA. This function is called with no
  6245. * lock held and always returns 1.
  6246. * This function does the following to cleanup driver resources:
  6247. * - Free discovery resources for each virtual port
  6248. * - Cleanup any pending fabric iocbs
  6249. * - Iterate through the iocb txq and free each entry
  6250. * in the list.
  6251. * - Free up any buffer posted to the HBA
  6252. * - Free mailbox commands in the mailbox queue.
  6253. **/
  6254. int
  6255. lpfc_sli_hba_down(struct lpfc_hba *phba)
  6256. {
  6257. LIST_HEAD(completions);
  6258. struct lpfc_sli *psli = &phba->sli;
  6259. struct lpfc_sli_ring *pring;
  6260. struct lpfc_dmabuf *buf_ptr;
  6261. unsigned long flags = 0;
  6262. int i;
  6263. /* Shutdown the mailbox command sub-system */
  6264. lpfc_sli_mbox_sys_shutdown(phba);
  6265. lpfc_hba_down_prep(phba);
  6266. lpfc_fabric_abort_hba(phba);
  6267. spin_lock_irqsave(&phba->hbalock, flags);
  6268. for (i = 0; i < psli->num_rings; i++) {
  6269. pring = &psli->ring[i];
  6270. /* Only slow rings */
  6271. if (pring->ringno == LPFC_ELS_RING) {
  6272. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  6273. /* Set the lpfc data pending flag */
  6274. set_bit(LPFC_DATA_READY, &phba->data_flags);
  6275. }
  6276. /*
  6277. * Error everything on the txq since these iocbs have not been
  6278. * given to the FW yet.
  6279. */
  6280. list_splice_init(&pring->txq, &completions);
  6281. pring->txq_cnt = 0;
  6282. }
  6283. spin_unlock_irqrestore(&phba->hbalock, flags);
  6284. /* Cancel all the IOCBs from the completions list */
  6285. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6286. IOERR_SLI_DOWN);
  6287. spin_lock_irqsave(&phba->hbalock, flags);
  6288. list_splice_init(&phba->elsbuf, &completions);
  6289. phba->elsbuf_cnt = 0;
  6290. phba->elsbuf_prev_cnt = 0;
  6291. spin_unlock_irqrestore(&phba->hbalock, flags);
  6292. while (!list_empty(&completions)) {
  6293. list_remove_head(&completions, buf_ptr,
  6294. struct lpfc_dmabuf, list);
  6295. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  6296. kfree(buf_ptr);
  6297. }
  6298. /* Return any active mbox cmds */
  6299. del_timer_sync(&psli->mbox_tmo);
  6300. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  6301. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6302. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  6303. return 1;
  6304. }
  6305. /**
  6306. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6307. * @srcp: Source memory pointer.
  6308. * @destp: Destination memory pointer.
  6309. * @cnt: Number of words required to be copied.
  6310. *
  6311. * This function is used for copying data between driver memory
  6312. * and the SLI memory. This function also changes the endianness
  6313. * of each word if native endianness is different from SLI
  6314. * endianness. This function can be called with or without
  6315. * lock.
  6316. **/
  6317. void
  6318. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6319. {
  6320. uint32_t *src = srcp;
  6321. uint32_t *dest = destp;
  6322. uint32_t ldata;
  6323. int i;
  6324. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6325. ldata = *src;
  6326. ldata = le32_to_cpu(ldata);
  6327. *dest = ldata;
  6328. src++;
  6329. dest++;
  6330. }
  6331. }
  6332. /**
  6333. * lpfc_sli_bemem_bcopy - SLI memory copy function
  6334. * @srcp: Source memory pointer.
  6335. * @destp: Destination memory pointer.
  6336. * @cnt: Number of words required to be copied.
  6337. *
  6338. * This function is used for copying data between a data structure
  6339. * with big endian representation to local endianness.
  6340. * This function can be called with or without lock.
  6341. **/
  6342. void
  6343. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6344. {
  6345. uint32_t *src = srcp;
  6346. uint32_t *dest = destp;
  6347. uint32_t ldata;
  6348. int i;
  6349. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  6350. ldata = *src;
  6351. ldata = be32_to_cpu(ldata);
  6352. *dest = ldata;
  6353. src++;
  6354. dest++;
  6355. }
  6356. }
  6357. /**
  6358. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6359. * @phba: Pointer to HBA context object.
  6360. * @pring: Pointer to driver SLI ring object.
  6361. * @mp: Pointer to driver buffer object.
  6362. *
  6363. * This function is called with no lock held.
  6364. * It always return zero after adding the buffer to the postbufq
  6365. * buffer list.
  6366. **/
  6367. int
  6368. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6369. struct lpfc_dmabuf *mp)
  6370. {
  6371. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6372. later */
  6373. spin_lock_irq(&phba->hbalock);
  6374. list_add_tail(&mp->list, &pring->postbufq);
  6375. pring->postbufq_cnt++;
  6376. spin_unlock_irq(&phba->hbalock);
  6377. return 0;
  6378. }
  6379. /**
  6380. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6381. * @phba: Pointer to HBA context object.
  6382. *
  6383. * When HBQ is enabled, buffers are searched based on tags. This function
  6384. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6385. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6386. * does not conflict with tags of buffer posted for unsolicited events.
  6387. * The function returns the allocated tag. The function is called with
  6388. * no locks held.
  6389. **/
  6390. uint32_t
  6391. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6392. {
  6393. spin_lock_irq(&phba->hbalock);
  6394. phba->buffer_tag_count++;
  6395. /*
  6396. * Always set the QUE_BUFTAG_BIT to distiguish between
  6397. * a tag assigned by HBQ.
  6398. */
  6399. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6400. spin_unlock_irq(&phba->hbalock);
  6401. return phba->buffer_tag_count;
  6402. }
  6403. /**
  6404. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6405. * @phba: Pointer to HBA context object.
  6406. * @pring: Pointer to driver SLI ring object.
  6407. * @tag: Buffer tag.
  6408. *
  6409. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6410. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6411. * iocb is posted to the response ring with the tag of the buffer.
  6412. * This function searches the pring->postbufq list using the tag
  6413. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6414. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6415. * buffer is returned to the caller else NULL is returned.
  6416. * This function is called with no lock held.
  6417. **/
  6418. struct lpfc_dmabuf *
  6419. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6420. uint32_t tag)
  6421. {
  6422. struct lpfc_dmabuf *mp, *next_mp;
  6423. struct list_head *slp = &pring->postbufq;
  6424. /* Search postbufq, from the begining, looking for a match on tag */
  6425. spin_lock_irq(&phba->hbalock);
  6426. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6427. if (mp->buffer_tag == tag) {
  6428. list_del_init(&mp->list);
  6429. pring->postbufq_cnt--;
  6430. spin_unlock_irq(&phba->hbalock);
  6431. return mp;
  6432. }
  6433. }
  6434. spin_unlock_irq(&phba->hbalock);
  6435. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6436. "0402 Cannot find virtual addr for buffer tag on "
  6437. "ring %d Data x%lx x%p x%p x%x\n",
  6438. pring->ringno, (unsigned long) tag,
  6439. slp->next, slp->prev, pring->postbufq_cnt);
  6440. return NULL;
  6441. }
  6442. /**
  6443. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6444. * @phba: Pointer to HBA context object.
  6445. * @pring: Pointer to driver SLI ring object.
  6446. * @phys: DMA address of the buffer.
  6447. *
  6448. * This function searches the buffer list using the dma_address
  6449. * of unsolicited event to find the driver's lpfc_dmabuf object
  6450. * corresponding to the dma_address. The function returns the
  6451. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6452. * This function is called by the ct and els unsolicited event
  6453. * handlers to get the buffer associated with the unsolicited
  6454. * event.
  6455. *
  6456. * This function is called with no lock held.
  6457. **/
  6458. struct lpfc_dmabuf *
  6459. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6460. dma_addr_t phys)
  6461. {
  6462. struct lpfc_dmabuf *mp, *next_mp;
  6463. struct list_head *slp = &pring->postbufq;
  6464. /* Search postbufq, from the begining, looking for a match on phys */
  6465. spin_lock_irq(&phba->hbalock);
  6466. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6467. if (mp->phys == phys) {
  6468. list_del_init(&mp->list);
  6469. pring->postbufq_cnt--;
  6470. spin_unlock_irq(&phba->hbalock);
  6471. return mp;
  6472. }
  6473. }
  6474. spin_unlock_irq(&phba->hbalock);
  6475. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6476. "0410 Cannot find virtual addr for mapped buf on "
  6477. "ring %d Data x%llx x%p x%p x%x\n",
  6478. pring->ringno, (unsigned long long)phys,
  6479. slp->next, slp->prev, pring->postbufq_cnt);
  6480. return NULL;
  6481. }
  6482. /**
  6483. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6484. * @phba: Pointer to HBA context object.
  6485. * @cmdiocb: Pointer to driver command iocb object.
  6486. * @rspiocb: Pointer to driver response iocb object.
  6487. *
  6488. * This function is the completion handler for the abort iocbs for
  6489. * ELS commands. This function is called from the ELS ring event
  6490. * handler with no lock held. This function frees memory resources
  6491. * associated with the abort iocb.
  6492. **/
  6493. static void
  6494. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6495. struct lpfc_iocbq *rspiocb)
  6496. {
  6497. IOCB_t *irsp = &rspiocb->iocb;
  6498. uint16_t abort_iotag, abort_context;
  6499. struct lpfc_iocbq *abort_iocb;
  6500. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6501. abort_iocb = NULL;
  6502. if (irsp->ulpStatus) {
  6503. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6504. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6505. spin_lock_irq(&phba->hbalock);
  6506. if (phba->sli_rev < LPFC_SLI_REV4) {
  6507. if (abort_iotag != 0 &&
  6508. abort_iotag <= phba->sli.last_iotag)
  6509. abort_iocb =
  6510. phba->sli.iocbq_lookup[abort_iotag];
  6511. } else
  6512. /* For sli4 the abort_tag is the XRI,
  6513. * so the abort routine puts the iotag of the iocb
  6514. * being aborted in the context field of the abort
  6515. * IOCB.
  6516. */
  6517. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  6518. /*
  6519. * If the iocb is not found in Firmware queue the iocb
  6520. * might have completed already. Do not free it again.
  6521. */
  6522. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6523. if (irsp->un.ulpWord[4] != IOERR_NO_XRI) {
  6524. spin_unlock_irq(&phba->hbalock);
  6525. lpfc_sli_release_iocbq(phba, cmdiocb);
  6526. return;
  6527. }
  6528. /* For SLI4 the ulpContext field for abort IOCB
  6529. * holds the iotag of the IOCB being aborted so
  6530. * the local abort_context needs to be reset to
  6531. * match the aborted IOCBs ulpContext.
  6532. */
  6533. if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4)
  6534. abort_context = abort_iocb->iocb.ulpContext;
  6535. }
  6536. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  6537. "0327 Cannot abort els iocb %p "
  6538. "with tag %x context %x, abort status %x, "
  6539. "abort code %x\n",
  6540. abort_iocb, abort_iotag, abort_context,
  6541. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6542. /*
  6543. * make sure we have the right iocbq before taking it
  6544. * off the txcmplq and try to call completion routine.
  6545. */
  6546. if (!abort_iocb ||
  6547. abort_iocb->iocb.ulpContext != abort_context ||
  6548. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6549. spin_unlock_irq(&phba->hbalock);
  6550. else if (phba->sli_rev < LPFC_SLI_REV4) {
  6551. /*
  6552. * leave the SLI4 aborted command on the txcmplq
  6553. * list and the command complete WCQE's XB bit
  6554. * will tell whether the SGL (XRI) can be released
  6555. * immediately or to the aborted SGL list for the
  6556. * following abort XRI from the HBA.
  6557. */
  6558. list_del_init(&abort_iocb->list);
  6559. if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) {
  6560. abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  6561. pring->txcmplq_cnt--;
  6562. }
  6563. /* Firmware could still be in progress of DMAing
  6564. * payload, so don't free data buffer till after
  6565. * a hbeat.
  6566. */
  6567. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6568. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6569. spin_unlock_irq(&phba->hbalock);
  6570. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6571. abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
  6572. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6573. } else
  6574. spin_unlock_irq(&phba->hbalock);
  6575. }
  6576. lpfc_sli_release_iocbq(phba, cmdiocb);
  6577. return;
  6578. }
  6579. /**
  6580. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6581. * @phba: Pointer to HBA context object.
  6582. * @cmdiocb: Pointer to driver command iocb object.
  6583. * @rspiocb: Pointer to driver response iocb object.
  6584. *
  6585. * The function is called from SLI ring event handler with no
  6586. * lock held. This function is the completion handler for ELS commands
  6587. * which are aborted. The function frees memory resources used for
  6588. * the aborted ELS commands.
  6589. **/
  6590. static void
  6591. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6592. struct lpfc_iocbq *rspiocb)
  6593. {
  6594. IOCB_t *irsp = &rspiocb->iocb;
  6595. /* ELS cmd tag <ulpIoTag> completes */
  6596. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6597. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6598. "x%x x%x x%x\n",
  6599. irsp->ulpIoTag, irsp->ulpStatus,
  6600. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6601. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6602. lpfc_ct_free_iocb(phba, cmdiocb);
  6603. else
  6604. lpfc_els_free_iocb(phba, cmdiocb);
  6605. return;
  6606. }
  6607. /**
  6608. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  6609. * @phba: Pointer to HBA context object.
  6610. * @pring: Pointer to driver SLI ring object.
  6611. * @cmdiocb: Pointer to driver command iocb object.
  6612. *
  6613. * This function issues an abort iocb for the provided command iocb down to
  6614. * the port. Other than the case the outstanding command iocb is an abort
  6615. * request, this function issues abort out unconditionally. This function is
  6616. * called with hbalock held. The function returns 0 when it fails due to
  6617. * memory allocation failure or when the command iocb is an abort request.
  6618. **/
  6619. static int
  6620. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6621. struct lpfc_iocbq *cmdiocb)
  6622. {
  6623. struct lpfc_vport *vport = cmdiocb->vport;
  6624. struct lpfc_iocbq *abtsiocbp;
  6625. IOCB_t *icmd = NULL;
  6626. IOCB_t *iabt = NULL;
  6627. int retval;
  6628. /*
  6629. * There are certain command types we don't want to abort. And we
  6630. * don't want to abort commands that are already in the process of
  6631. * being aborted.
  6632. */
  6633. icmd = &cmdiocb->iocb;
  6634. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6635. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6636. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6637. return 0;
  6638. /* issue ABTS for this IOCB based on iotag */
  6639. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6640. if (abtsiocbp == NULL)
  6641. return 0;
  6642. /* This signals the response to set the correct status
  6643. * before calling the completion handler
  6644. */
  6645. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6646. iabt = &abtsiocbp->iocb;
  6647. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6648. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6649. if (phba->sli_rev == LPFC_SLI_REV4) {
  6650. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6651. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  6652. }
  6653. else
  6654. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6655. iabt->ulpLe = 1;
  6656. iabt->ulpClass = icmd->ulpClass;
  6657. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6658. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  6659. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  6660. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  6661. if (phba->link_state >= LPFC_LINK_UP)
  6662. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6663. else
  6664. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6665. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6666. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6667. "0339 Abort xri x%x, original iotag x%x, "
  6668. "abort cmd iotag x%x\n",
  6669. iabt->un.acxri.abortIoTag,
  6670. iabt->un.acxri.abortContextTag,
  6671. abtsiocbp->iotag);
  6672. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6673. if (retval)
  6674. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6675. /*
  6676. * Caller to this routine should check for IOCB_ERROR
  6677. * and handle it properly. This routine no longer removes
  6678. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6679. */
  6680. return retval;
  6681. }
  6682. /**
  6683. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6684. * @phba: Pointer to HBA context object.
  6685. * @pring: Pointer to driver SLI ring object.
  6686. * @cmdiocb: Pointer to driver command iocb object.
  6687. *
  6688. * This function issues an abort iocb for the provided command iocb. In case
  6689. * of unloading, the abort iocb will not be issued to commands on the ELS
  6690. * ring. Instead, the callback function shall be changed to those commands
  6691. * so that nothing happens when them finishes. This function is called with
  6692. * hbalock held. The function returns 0 when the command iocb is an abort
  6693. * request.
  6694. **/
  6695. int
  6696. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6697. struct lpfc_iocbq *cmdiocb)
  6698. {
  6699. struct lpfc_vport *vport = cmdiocb->vport;
  6700. int retval = IOCB_ERROR;
  6701. IOCB_t *icmd = NULL;
  6702. /*
  6703. * There are certain command types we don't want to abort. And we
  6704. * don't want to abort commands that are already in the process of
  6705. * being aborted.
  6706. */
  6707. icmd = &cmdiocb->iocb;
  6708. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6709. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6710. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6711. return 0;
  6712. /*
  6713. * If we're unloading, don't abort iocb on the ELS ring, but change
  6714. * the callback so that nothing happens when it finishes.
  6715. */
  6716. if ((vport->load_flag & FC_UNLOADING) &&
  6717. (pring->ringno == LPFC_ELS_RING)) {
  6718. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6719. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6720. else
  6721. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6722. goto abort_iotag_exit;
  6723. }
  6724. /* Now, we try to issue the abort to the cmdiocb out */
  6725. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  6726. abort_iotag_exit:
  6727. /*
  6728. * Caller to this routine should check for IOCB_ERROR
  6729. * and handle it properly. This routine no longer removes
  6730. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6731. */
  6732. return retval;
  6733. }
  6734. /**
  6735. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  6736. * @phba: Pointer to HBA context object.
  6737. * @pring: Pointer to driver SLI ring object.
  6738. *
  6739. * This function aborts all iocbs in the given ring and frees all the iocb
  6740. * objects in txq. This function issues abort iocbs unconditionally for all
  6741. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  6742. * to complete before the return of this function. The caller is not required
  6743. * to hold any locks.
  6744. **/
  6745. static void
  6746. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  6747. {
  6748. LIST_HEAD(completions);
  6749. struct lpfc_iocbq *iocb, *next_iocb;
  6750. if (pring->ringno == LPFC_ELS_RING)
  6751. lpfc_fabric_abort_hba(phba);
  6752. spin_lock_irq(&phba->hbalock);
  6753. /* Take off all the iocbs on txq for cancelling */
  6754. list_splice_init(&pring->txq, &completions);
  6755. pring->txq_cnt = 0;
  6756. /* Next issue ABTS for everything on the txcmplq */
  6757. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  6758. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  6759. spin_unlock_irq(&phba->hbalock);
  6760. /* Cancel all the IOCBs from the completions list */
  6761. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  6762. IOERR_SLI_ABORTED);
  6763. }
  6764. /**
  6765. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  6766. * @phba: pointer to lpfc HBA data structure.
  6767. *
  6768. * This routine will abort all pending and outstanding iocbs to an HBA.
  6769. **/
  6770. void
  6771. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  6772. {
  6773. struct lpfc_sli *psli = &phba->sli;
  6774. struct lpfc_sli_ring *pring;
  6775. int i;
  6776. for (i = 0; i < psli->num_rings; i++) {
  6777. pring = &psli->ring[i];
  6778. lpfc_sli_iocb_ring_abort(phba, pring);
  6779. }
  6780. }
  6781. /**
  6782. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6783. * @iocbq: Pointer to driver iocb object.
  6784. * @vport: Pointer to driver virtual port object.
  6785. * @tgt_id: SCSI ID of the target.
  6786. * @lun_id: LUN ID of the scsi device.
  6787. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6788. *
  6789. * This function acts as an iocb filter for functions which abort or count
  6790. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6791. * 0 if the filtering criteria is met for the given iocb and will return
  6792. * 1 if the filtering criteria is not met.
  6793. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6794. * given iocb is for the SCSI device specified by vport, tgt_id and
  6795. * lun_id parameter.
  6796. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6797. * given iocb is for the SCSI target specified by vport and tgt_id
  6798. * parameters.
  6799. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6800. * given iocb is for the SCSI host associated with the given vport.
  6801. * This function is called with no locks held.
  6802. **/
  6803. static int
  6804. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6805. uint16_t tgt_id, uint64_t lun_id,
  6806. lpfc_ctx_cmd ctx_cmd)
  6807. {
  6808. struct lpfc_scsi_buf *lpfc_cmd;
  6809. int rc = 1;
  6810. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6811. return rc;
  6812. if (iocbq->vport != vport)
  6813. return rc;
  6814. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6815. if (lpfc_cmd->pCmd == NULL)
  6816. return rc;
  6817. switch (ctx_cmd) {
  6818. case LPFC_CTX_LUN:
  6819. if ((lpfc_cmd->rdata->pnode) &&
  6820. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6821. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6822. rc = 0;
  6823. break;
  6824. case LPFC_CTX_TGT:
  6825. if ((lpfc_cmd->rdata->pnode) &&
  6826. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6827. rc = 0;
  6828. break;
  6829. case LPFC_CTX_HOST:
  6830. rc = 0;
  6831. break;
  6832. default:
  6833. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6834. __func__, ctx_cmd);
  6835. break;
  6836. }
  6837. return rc;
  6838. }
  6839. /**
  6840. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6841. * @vport: Pointer to virtual port.
  6842. * @tgt_id: SCSI ID of the target.
  6843. * @lun_id: LUN ID of the scsi device.
  6844. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6845. *
  6846. * This function returns number of FCP commands pending for the vport.
  6847. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6848. * commands pending on the vport associated with SCSI device specified
  6849. * by tgt_id and lun_id parameters.
  6850. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6851. * commands pending on the vport associated with SCSI target specified
  6852. * by tgt_id parameter.
  6853. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6854. * commands pending on the vport.
  6855. * This function returns the number of iocbs which satisfy the filter.
  6856. * This function is called without any lock held.
  6857. **/
  6858. int
  6859. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6860. lpfc_ctx_cmd ctx_cmd)
  6861. {
  6862. struct lpfc_hba *phba = vport->phba;
  6863. struct lpfc_iocbq *iocbq;
  6864. int sum, i;
  6865. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6866. iocbq = phba->sli.iocbq_lookup[i];
  6867. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6868. ctx_cmd) == 0)
  6869. sum++;
  6870. }
  6871. return sum;
  6872. }
  6873. /**
  6874. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6875. * @phba: Pointer to HBA context object
  6876. * @cmdiocb: Pointer to command iocb object.
  6877. * @rspiocb: Pointer to response iocb object.
  6878. *
  6879. * This function is called when an aborted FCP iocb completes. This
  6880. * function is called by the ring event handler with no lock held.
  6881. * This function frees the iocb.
  6882. **/
  6883. void
  6884. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6885. struct lpfc_iocbq *rspiocb)
  6886. {
  6887. lpfc_sli_release_iocbq(phba, cmdiocb);
  6888. return;
  6889. }
  6890. /**
  6891. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6892. * @vport: Pointer to virtual port.
  6893. * @pring: Pointer to driver SLI ring object.
  6894. * @tgt_id: SCSI ID of the target.
  6895. * @lun_id: LUN ID of the scsi device.
  6896. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6897. *
  6898. * This function sends an abort command for every SCSI command
  6899. * associated with the given virtual port pending on the ring
  6900. * filtered by lpfc_sli_validate_fcp_iocb function.
  6901. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6902. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6903. * parameters
  6904. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6905. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6906. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6907. * FCP iocbs associated with virtual port.
  6908. * This function returns number of iocbs it failed to abort.
  6909. * This function is called with no locks held.
  6910. **/
  6911. int
  6912. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6913. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6914. {
  6915. struct lpfc_hba *phba = vport->phba;
  6916. struct lpfc_iocbq *iocbq;
  6917. struct lpfc_iocbq *abtsiocb;
  6918. IOCB_t *cmd = NULL;
  6919. int errcnt = 0, ret_val = 0;
  6920. int i;
  6921. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6922. iocbq = phba->sli.iocbq_lookup[i];
  6923. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6924. abort_cmd) != 0)
  6925. continue;
  6926. /* issue ABTS for this IOCB based on iotag */
  6927. abtsiocb = lpfc_sli_get_iocbq(phba);
  6928. if (abtsiocb == NULL) {
  6929. errcnt++;
  6930. continue;
  6931. }
  6932. cmd = &iocbq->iocb;
  6933. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6934. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6935. if (phba->sli_rev == LPFC_SLI_REV4)
  6936. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6937. else
  6938. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6939. abtsiocb->iocb.ulpLe = 1;
  6940. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6941. abtsiocb->vport = phba->pport;
  6942. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  6943. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  6944. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6945. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  6946. if (lpfc_is_link_up(phba))
  6947. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6948. else
  6949. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6950. /* Setup callback routine and issue the command. */
  6951. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6952. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6953. abtsiocb, 0);
  6954. if (ret_val == IOCB_ERROR) {
  6955. lpfc_sli_release_iocbq(phba, abtsiocb);
  6956. errcnt++;
  6957. continue;
  6958. }
  6959. }
  6960. return errcnt;
  6961. }
  6962. /**
  6963. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6964. * @phba: Pointer to HBA context object.
  6965. * @cmdiocbq: Pointer to command iocb.
  6966. * @rspiocbq: Pointer to response iocb.
  6967. *
  6968. * This function is the completion handler for iocbs issued using
  6969. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6970. * ring event handler function without any lock held. This function
  6971. * can be called from both worker thread context and interrupt
  6972. * context. This function also can be called from other thread which
  6973. * cleans up the SLI layer objects.
  6974. * This function copy the contents of the response iocb to the
  6975. * response iocb memory object provided by the caller of
  6976. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6977. * sleeps for the iocb completion.
  6978. **/
  6979. static void
  6980. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6981. struct lpfc_iocbq *cmdiocbq,
  6982. struct lpfc_iocbq *rspiocbq)
  6983. {
  6984. wait_queue_head_t *pdone_q;
  6985. unsigned long iflags;
  6986. struct lpfc_scsi_buf *lpfc_cmd;
  6987. spin_lock_irqsave(&phba->hbalock, iflags);
  6988. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6989. if (cmdiocbq->context2 && rspiocbq)
  6990. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6991. &rspiocbq->iocb, sizeof(IOCB_t));
  6992. /* Set the exchange busy flag for task management commands */
  6993. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  6994. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  6995. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  6996. cur_iocbq);
  6997. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  6998. }
  6999. pdone_q = cmdiocbq->context_un.wait_queue;
  7000. if (pdone_q)
  7001. wake_up(pdone_q);
  7002. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7003. return;
  7004. }
  7005. /**
  7006. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  7007. * @phba: Pointer to HBA context object..
  7008. * @piocbq: Pointer to command iocb.
  7009. * @flag: Flag to test.
  7010. *
  7011. * This routine grabs the hbalock and then test the iocb_flag to
  7012. * see if the passed in flag is set.
  7013. * Returns:
  7014. * 1 if flag is set.
  7015. * 0 if flag is not set.
  7016. **/
  7017. static int
  7018. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  7019. struct lpfc_iocbq *piocbq, uint32_t flag)
  7020. {
  7021. unsigned long iflags;
  7022. int ret;
  7023. spin_lock_irqsave(&phba->hbalock, iflags);
  7024. ret = piocbq->iocb_flag & flag;
  7025. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7026. return ret;
  7027. }
  7028. /**
  7029. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  7030. * @phba: Pointer to HBA context object..
  7031. * @pring: Pointer to sli ring.
  7032. * @piocb: Pointer to command iocb.
  7033. * @prspiocbq: Pointer to response iocb.
  7034. * @timeout: Timeout in number of seconds.
  7035. *
  7036. * This function issues the iocb to firmware and waits for the
  7037. * iocb to complete. If the iocb command is not
  7038. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  7039. * Caller should not free the iocb resources if this function
  7040. * returns IOCB_TIMEDOUT.
  7041. * The function waits for the iocb completion using an
  7042. * non-interruptible wait.
  7043. * This function will sleep while waiting for iocb completion.
  7044. * So, this function should not be called from any context which
  7045. * does not allow sleeping. Due to the same reason, this function
  7046. * cannot be called with interrupt disabled.
  7047. * This function assumes that the iocb completions occur while
  7048. * this function sleep. So, this function cannot be called from
  7049. * the thread which process iocb completion for this ring.
  7050. * This function clears the iocb_flag of the iocb object before
  7051. * issuing the iocb and the iocb completion handler sets this
  7052. * flag and wakes this thread when the iocb completes.
  7053. * The contents of the response iocb will be copied to prspiocbq
  7054. * by the completion handler when the command completes.
  7055. * This function returns IOCB_SUCCESS when success.
  7056. * This function is called with no lock held.
  7057. **/
  7058. int
  7059. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  7060. uint32_t ring_number,
  7061. struct lpfc_iocbq *piocb,
  7062. struct lpfc_iocbq *prspiocbq,
  7063. uint32_t timeout)
  7064. {
  7065. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7066. long timeleft, timeout_req = 0;
  7067. int retval = IOCB_SUCCESS;
  7068. uint32_t creg_val;
  7069. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7070. /*
  7071. * If the caller has provided a response iocbq buffer, then context2
  7072. * is NULL or its an error.
  7073. */
  7074. if (prspiocbq) {
  7075. if (piocb->context2)
  7076. return IOCB_ERROR;
  7077. piocb->context2 = prspiocbq;
  7078. }
  7079. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  7080. piocb->context_un.wait_queue = &done_q;
  7081. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  7082. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7083. creg_val = readl(phba->HCregaddr);
  7084. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  7085. writel(creg_val, phba->HCregaddr);
  7086. readl(phba->HCregaddr); /* flush */
  7087. }
  7088. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7089. SLI_IOCB_RET_IOCB);
  7090. if (retval == IOCB_SUCCESS) {
  7091. timeout_req = timeout * HZ;
  7092. timeleft = wait_event_timeout(done_q,
  7093. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  7094. timeout_req);
  7095. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  7096. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7097. "0331 IOCB wake signaled\n");
  7098. } else if (timeleft == 0) {
  7099. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7100. "0338 IOCB wait timeout error - no "
  7101. "wake response Data x%x\n", timeout);
  7102. retval = IOCB_TIMEDOUT;
  7103. } else {
  7104. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7105. "0330 IOCB wake NOT set, "
  7106. "Data x%x x%lx\n",
  7107. timeout, (timeleft / jiffies));
  7108. retval = IOCB_TIMEDOUT;
  7109. }
  7110. } else if (retval == IOCB_BUSY) {
  7111. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7112. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  7113. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  7114. return retval;
  7115. } else {
  7116. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7117. "0332 IOCB wait issue failed, Data x%x\n",
  7118. retval);
  7119. retval = IOCB_ERROR;
  7120. }
  7121. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  7122. creg_val = readl(phba->HCregaddr);
  7123. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  7124. writel(creg_val, phba->HCregaddr);
  7125. readl(phba->HCregaddr); /* flush */
  7126. }
  7127. if (prspiocbq)
  7128. piocb->context2 = NULL;
  7129. piocb->context_un.wait_queue = NULL;
  7130. piocb->iocb_cmpl = NULL;
  7131. return retval;
  7132. }
  7133. /**
  7134. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  7135. * @phba: Pointer to HBA context object.
  7136. * @pmboxq: Pointer to driver mailbox object.
  7137. * @timeout: Timeout in number of seconds.
  7138. *
  7139. * This function issues the mailbox to firmware and waits for the
  7140. * mailbox command to complete. If the mailbox command is not
  7141. * completed within timeout seconds, it returns MBX_TIMEOUT.
  7142. * The function waits for the mailbox completion using an
  7143. * interruptible wait. If the thread is woken up due to a
  7144. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  7145. * should not free the mailbox resources, if this function returns
  7146. * MBX_TIMEOUT.
  7147. * This function will sleep while waiting for mailbox completion.
  7148. * So, this function should not be called from any context which
  7149. * does not allow sleeping. Due to the same reason, this function
  7150. * cannot be called with interrupt disabled.
  7151. * This function assumes that the mailbox completion occurs while
  7152. * this function sleep. So, this function cannot be called from
  7153. * the worker thread which processes mailbox completion.
  7154. * This function is called in the context of HBA management
  7155. * applications.
  7156. * This function returns MBX_SUCCESS when successful.
  7157. * This function is called with no lock held.
  7158. **/
  7159. int
  7160. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  7161. uint32_t timeout)
  7162. {
  7163. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  7164. int retval;
  7165. unsigned long flag;
  7166. /* The caller must leave context1 empty. */
  7167. if (pmboxq->context1)
  7168. return MBX_NOT_FINISHED;
  7169. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  7170. /* setup wake call as IOCB callback */
  7171. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  7172. /* setup context field to pass wait_queue pointer to wake function */
  7173. pmboxq->context1 = &done_q;
  7174. /* now issue the command */
  7175. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  7176. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  7177. wait_event_interruptible_timeout(done_q,
  7178. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  7179. timeout * HZ);
  7180. spin_lock_irqsave(&phba->hbalock, flag);
  7181. pmboxq->context1 = NULL;
  7182. /*
  7183. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  7184. * else do not free the resources.
  7185. */
  7186. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  7187. retval = MBX_SUCCESS;
  7188. lpfc_sli4_swap_str(phba, pmboxq);
  7189. } else {
  7190. retval = MBX_TIMEOUT;
  7191. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7192. }
  7193. spin_unlock_irqrestore(&phba->hbalock, flag);
  7194. }
  7195. return retval;
  7196. }
  7197. /**
  7198. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  7199. * @phba: Pointer to HBA context.
  7200. *
  7201. * This function is called to shutdown the driver's mailbox sub-system.
  7202. * It first marks the mailbox sub-system is in a block state to prevent
  7203. * the asynchronous mailbox command from issued off the pending mailbox
  7204. * command queue. If the mailbox command sub-system shutdown is due to
  7205. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  7206. * the mailbox sub-system flush routine to forcefully bring down the
  7207. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  7208. * as with offline or HBA function reset), this routine will wait for the
  7209. * outstanding mailbox command to complete before invoking the mailbox
  7210. * sub-system flush routine to gracefully bring down mailbox sub-system.
  7211. **/
  7212. void
  7213. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  7214. {
  7215. struct lpfc_sli *psli = &phba->sli;
  7216. uint8_t actcmd = MBX_HEARTBEAT;
  7217. unsigned long timeout;
  7218. spin_lock_irq(&phba->hbalock);
  7219. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7220. spin_unlock_irq(&phba->hbalock);
  7221. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  7222. spin_lock_irq(&phba->hbalock);
  7223. if (phba->sli.mbox_active)
  7224. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  7225. spin_unlock_irq(&phba->hbalock);
  7226. /* Determine how long we might wait for the active mailbox
  7227. * command to be gracefully completed by firmware.
  7228. */
  7229. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  7230. 1000) + jiffies;
  7231. while (phba->sli.mbox_active) {
  7232. /* Check active mailbox complete status every 2ms */
  7233. msleep(2);
  7234. if (time_after(jiffies, timeout))
  7235. /* Timeout, let the mailbox flush routine to
  7236. * forcefully release active mailbox command
  7237. */
  7238. break;
  7239. }
  7240. }
  7241. lpfc_sli_mbox_sys_flush(phba);
  7242. }
  7243. /**
  7244. * lpfc_sli_eratt_read - read sli-3 error attention events
  7245. * @phba: Pointer to HBA context.
  7246. *
  7247. * This function is called to read the SLI3 device error attention registers
  7248. * for possible error attention events. The caller must hold the hostlock
  7249. * with spin_lock_irq().
  7250. *
  7251. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7252. * Register and returns 0 otherwise.
  7253. **/
  7254. static int
  7255. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  7256. {
  7257. uint32_t ha_copy;
  7258. /* Read chip Host Attention (HA) register */
  7259. ha_copy = readl(phba->HAregaddr);
  7260. if (ha_copy & HA_ERATT) {
  7261. /* Read host status register to retrieve error event */
  7262. lpfc_sli_read_hs(phba);
  7263. /* Check if there is a deferred error condition is active */
  7264. if ((HS_FFER1 & phba->work_hs) &&
  7265. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7266. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  7267. phba->hba_flag |= DEFER_ERATT;
  7268. /* Clear all interrupt enable conditions */
  7269. writel(0, phba->HCregaddr);
  7270. readl(phba->HCregaddr);
  7271. }
  7272. /* Set the driver HA work bitmap */
  7273. phba->work_ha |= HA_ERATT;
  7274. /* Indicate polling handles this ERATT */
  7275. phba->hba_flag |= HBA_ERATT_HANDLED;
  7276. return 1;
  7277. }
  7278. return 0;
  7279. }
  7280. /**
  7281. * lpfc_sli4_eratt_read - read sli-4 error attention events
  7282. * @phba: Pointer to HBA context.
  7283. *
  7284. * This function is called to read the SLI4 device error attention registers
  7285. * for possible error attention events. The caller must hold the hostlock
  7286. * with spin_lock_irq().
  7287. *
  7288. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7289. * Register and returns 0 otherwise.
  7290. **/
  7291. static int
  7292. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  7293. {
  7294. uint32_t uerr_sta_hi, uerr_sta_lo;
  7295. /* For now, use the SLI4 device internal unrecoverable error
  7296. * registers for error attention. This can be changed later.
  7297. */
  7298. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  7299. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  7300. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  7301. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  7302. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7303. "1423 HBA Unrecoverable error: "
  7304. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  7305. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  7306. uerr_sta_lo, uerr_sta_hi,
  7307. phba->sli4_hba.ue_mask_lo,
  7308. phba->sli4_hba.ue_mask_hi);
  7309. phba->work_status[0] = uerr_sta_lo;
  7310. phba->work_status[1] = uerr_sta_hi;
  7311. /* Set the driver HA work bitmap */
  7312. phba->work_ha |= HA_ERATT;
  7313. /* Indicate polling handles this ERATT */
  7314. phba->hba_flag |= HBA_ERATT_HANDLED;
  7315. return 1;
  7316. }
  7317. return 0;
  7318. }
  7319. /**
  7320. * lpfc_sli_check_eratt - check error attention events
  7321. * @phba: Pointer to HBA context.
  7322. *
  7323. * This function is called from timer soft interrupt context to check HBA's
  7324. * error attention register bit for error attention events.
  7325. *
  7326. * This fucntion returns 1 when there is Error Attention in the Host Attention
  7327. * Register and returns 0 otherwise.
  7328. **/
  7329. int
  7330. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  7331. {
  7332. uint32_t ha_copy;
  7333. /* If somebody is waiting to handle an eratt, don't process it
  7334. * here. The brdkill function will do this.
  7335. */
  7336. if (phba->link_flag & LS_IGNORE_ERATT)
  7337. return 0;
  7338. /* Check if interrupt handler handles this ERATT */
  7339. spin_lock_irq(&phba->hbalock);
  7340. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  7341. /* Interrupt handler has handled ERATT */
  7342. spin_unlock_irq(&phba->hbalock);
  7343. return 0;
  7344. }
  7345. /*
  7346. * If there is deferred error attention, do not check for error
  7347. * attention
  7348. */
  7349. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7350. spin_unlock_irq(&phba->hbalock);
  7351. return 0;
  7352. }
  7353. /* If PCI channel is offline, don't process it */
  7354. if (unlikely(pci_channel_offline(phba->pcidev))) {
  7355. spin_unlock_irq(&phba->hbalock);
  7356. return 0;
  7357. }
  7358. switch (phba->sli_rev) {
  7359. case LPFC_SLI_REV2:
  7360. case LPFC_SLI_REV3:
  7361. /* Read chip Host Attention (HA) register */
  7362. ha_copy = lpfc_sli_eratt_read(phba);
  7363. break;
  7364. case LPFC_SLI_REV4:
  7365. /* Read devcie Uncoverable Error (UERR) registers */
  7366. ha_copy = lpfc_sli4_eratt_read(phba);
  7367. break;
  7368. default:
  7369. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7370. "0299 Invalid SLI revision (%d)\n",
  7371. phba->sli_rev);
  7372. ha_copy = 0;
  7373. break;
  7374. }
  7375. spin_unlock_irq(&phba->hbalock);
  7376. return ha_copy;
  7377. }
  7378. /**
  7379. * lpfc_intr_state_check - Check device state for interrupt handling
  7380. * @phba: Pointer to HBA context.
  7381. *
  7382. * This inline routine checks whether a device or its PCI slot is in a state
  7383. * that the interrupt should be handled.
  7384. *
  7385. * This function returns 0 if the device or the PCI slot is in a state that
  7386. * interrupt should be handled, otherwise -EIO.
  7387. */
  7388. static inline int
  7389. lpfc_intr_state_check(struct lpfc_hba *phba)
  7390. {
  7391. /* If the pci channel is offline, ignore all the interrupts */
  7392. if (unlikely(pci_channel_offline(phba->pcidev)))
  7393. return -EIO;
  7394. /* Update device level interrupt statistics */
  7395. phba->sli.slistat.sli_intr++;
  7396. /* Ignore all interrupts during initialization. */
  7397. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7398. return -EIO;
  7399. return 0;
  7400. }
  7401. /**
  7402. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  7403. * @irq: Interrupt number.
  7404. * @dev_id: The device context pointer.
  7405. *
  7406. * This function is directly called from the PCI layer as an interrupt
  7407. * service routine when device with SLI-3 interface spec is enabled with
  7408. * MSI-X multi-message interrupt mode and there are slow-path events in
  7409. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  7410. * interrupt mode, this function is called as part of the device-level
  7411. * interrupt handler. When the PCI slot is in error recovery or the HBA
  7412. * is undergoing initialization, the interrupt handler will not process
  7413. * the interrupt. The link attention and ELS ring attention events are
  7414. * handled by the worker thread. The interrupt handler signals the worker
  7415. * thread and returns for these events. This function is called without
  7416. * any lock held. It gets the hbalock to access and update SLI data
  7417. * structures.
  7418. *
  7419. * This function returns IRQ_HANDLED when interrupt is handled else it
  7420. * returns IRQ_NONE.
  7421. **/
  7422. irqreturn_t
  7423. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  7424. {
  7425. struct lpfc_hba *phba;
  7426. uint32_t ha_copy, hc_copy;
  7427. uint32_t work_ha_copy;
  7428. unsigned long status;
  7429. unsigned long iflag;
  7430. uint32_t control;
  7431. MAILBOX_t *mbox, *pmbox;
  7432. struct lpfc_vport *vport;
  7433. struct lpfc_nodelist *ndlp;
  7434. struct lpfc_dmabuf *mp;
  7435. LPFC_MBOXQ_t *pmb;
  7436. int rc;
  7437. /*
  7438. * Get the driver's phba structure from the dev_id and
  7439. * assume the HBA is not interrupting.
  7440. */
  7441. phba = (struct lpfc_hba *)dev_id;
  7442. if (unlikely(!phba))
  7443. return IRQ_NONE;
  7444. /*
  7445. * Stuff needs to be attented to when this function is invoked as an
  7446. * individual interrupt handler in MSI-X multi-message interrupt mode
  7447. */
  7448. if (phba->intr_type == MSIX) {
  7449. /* Check device state for handling interrupt */
  7450. if (lpfc_intr_state_check(phba))
  7451. return IRQ_NONE;
  7452. /* Need to read HA REG for slow-path events */
  7453. spin_lock_irqsave(&phba->hbalock, iflag);
  7454. ha_copy = readl(phba->HAregaddr);
  7455. /* If somebody is waiting to handle an eratt don't process it
  7456. * here. The brdkill function will do this.
  7457. */
  7458. if (phba->link_flag & LS_IGNORE_ERATT)
  7459. ha_copy &= ~HA_ERATT;
  7460. /* Check the need for handling ERATT in interrupt handler */
  7461. if (ha_copy & HA_ERATT) {
  7462. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7463. /* ERATT polling has handled ERATT */
  7464. ha_copy &= ~HA_ERATT;
  7465. else
  7466. /* Indicate interrupt handler handles ERATT */
  7467. phba->hba_flag |= HBA_ERATT_HANDLED;
  7468. }
  7469. /*
  7470. * If there is deferred error attention, do not check for any
  7471. * interrupt.
  7472. */
  7473. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7474. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7475. return IRQ_NONE;
  7476. }
  7477. /* Clear up only attention source related to slow-path */
  7478. hc_copy = readl(phba->HCregaddr);
  7479. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  7480. HC_LAINT_ENA | HC_ERINT_ENA),
  7481. phba->HCregaddr);
  7482. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7483. phba->HAregaddr);
  7484. writel(hc_copy, phba->HCregaddr);
  7485. readl(phba->HAregaddr); /* flush */
  7486. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7487. } else
  7488. ha_copy = phba->ha_copy;
  7489. work_ha_copy = ha_copy & phba->work_ha_mask;
  7490. if (work_ha_copy) {
  7491. if (work_ha_copy & HA_LATT) {
  7492. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7493. /*
  7494. * Turn off Link Attention interrupts
  7495. * until CLEAR_LA done
  7496. */
  7497. spin_lock_irqsave(&phba->hbalock, iflag);
  7498. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7499. control = readl(phba->HCregaddr);
  7500. control &= ~HC_LAINT_ENA;
  7501. writel(control, phba->HCregaddr);
  7502. readl(phba->HCregaddr); /* flush */
  7503. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7504. }
  7505. else
  7506. work_ha_copy &= ~HA_LATT;
  7507. }
  7508. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7509. /*
  7510. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7511. * the only slow ring.
  7512. */
  7513. status = (work_ha_copy &
  7514. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7515. status >>= (4*LPFC_ELS_RING);
  7516. if (status & HA_RXMASK) {
  7517. spin_lock_irqsave(&phba->hbalock, iflag);
  7518. control = readl(phba->HCregaddr);
  7519. lpfc_debugfs_slow_ring_trc(phba,
  7520. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7521. control, status,
  7522. (uint32_t)phba->sli.slistat.sli_intr);
  7523. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7524. lpfc_debugfs_slow_ring_trc(phba,
  7525. "ISR Disable ring:"
  7526. "pwork:x%x hawork:x%x wait:x%x",
  7527. phba->work_ha, work_ha_copy,
  7528. (uint32_t)((unsigned long)
  7529. &phba->work_waitq));
  7530. control &=
  7531. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7532. writel(control, phba->HCregaddr);
  7533. readl(phba->HCregaddr); /* flush */
  7534. }
  7535. else {
  7536. lpfc_debugfs_slow_ring_trc(phba,
  7537. "ISR slow ring: pwork:"
  7538. "x%x hawork:x%x wait:x%x",
  7539. phba->work_ha, work_ha_copy,
  7540. (uint32_t)((unsigned long)
  7541. &phba->work_waitq));
  7542. }
  7543. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7544. }
  7545. }
  7546. spin_lock_irqsave(&phba->hbalock, iflag);
  7547. if (work_ha_copy & HA_ERATT) {
  7548. lpfc_sli_read_hs(phba);
  7549. /*
  7550. * Check if there is a deferred error condition
  7551. * is active
  7552. */
  7553. if ((HS_FFER1 & phba->work_hs) &&
  7554. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7555. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  7556. phba->work_hs)) {
  7557. phba->hba_flag |= DEFER_ERATT;
  7558. /* Clear all interrupt enable conditions */
  7559. writel(0, phba->HCregaddr);
  7560. readl(phba->HCregaddr);
  7561. }
  7562. }
  7563. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7564. pmb = phba->sli.mbox_active;
  7565. pmbox = &pmb->u.mb;
  7566. mbox = phba->mbox;
  7567. vport = pmb->vport;
  7568. /* First check out the status word */
  7569. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7570. if (pmbox->mbxOwner != OWN_HOST) {
  7571. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7572. /*
  7573. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7574. * mbxStatus <status>
  7575. */
  7576. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7577. LOG_SLI,
  7578. "(%d):0304 Stray Mailbox "
  7579. "Interrupt mbxCommand x%x "
  7580. "mbxStatus x%x\n",
  7581. (vport ? vport->vpi : 0),
  7582. pmbox->mbxCommand,
  7583. pmbox->mbxStatus);
  7584. /* clear mailbox attention bit */
  7585. work_ha_copy &= ~HA_MBATT;
  7586. } else {
  7587. phba->sli.mbox_active = NULL;
  7588. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7589. phba->last_completion_time = jiffies;
  7590. del_timer(&phba->sli.mbox_tmo);
  7591. if (pmb->mbox_cmpl) {
  7592. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7593. MAILBOX_CMD_SIZE);
  7594. if (pmb->out_ext_byte_len &&
  7595. pmb->context2)
  7596. lpfc_sli_pcimem_bcopy(
  7597. phba->mbox_ext,
  7598. pmb->context2,
  7599. pmb->out_ext_byte_len);
  7600. }
  7601. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7602. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7603. lpfc_debugfs_disc_trc(vport,
  7604. LPFC_DISC_TRC_MBOX_VPORT,
  7605. "MBOX dflt rpi: : "
  7606. "status:x%x rpi:x%x",
  7607. (uint32_t)pmbox->mbxStatus,
  7608. pmbox->un.varWords[0], 0);
  7609. if (!pmbox->mbxStatus) {
  7610. mp = (struct lpfc_dmabuf *)
  7611. (pmb->context1);
  7612. ndlp = (struct lpfc_nodelist *)
  7613. pmb->context2;
  7614. /* Reg_LOGIN of dflt RPI was
  7615. * successful. new lets get
  7616. * rid of the RPI using the
  7617. * same mbox buffer.
  7618. */
  7619. lpfc_unreg_login(phba,
  7620. vport->vpi,
  7621. pmbox->un.varWords[0],
  7622. pmb);
  7623. pmb->mbox_cmpl =
  7624. lpfc_mbx_cmpl_dflt_rpi;
  7625. pmb->context1 = mp;
  7626. pmb->context2 = ndlp;
  7627. pmb->vport = vport;
  7628. rc = lpfc_sli_issue_mbox(phba,
  7629. pmb,
  7630. MBX_NOWAIT);
  7631. if (rc != MBX_BUSY)
  7632. lpfc_printf_log(phba,
  7633. KERN_ERR,
  7634. LOG_MBOX | LOG_SLI,
  7635. "0350 rc should have"
  7636. "been MBX_BUSY\n");
  7637. if (rc != MBX_NOT_FINISHED)
  7638. goto send_current_mbox;
  7639. }
  7640. }
  7641. spin_lock_irqsave(
  7642. &phba->pport->work_port_lock,
  7643. iflag);
  7644. phba->pport->work_port_events &=
  7645. ~WORKER_MBOX_TMO;
  7646. spin_unlock_irqrestore(
  7647. &phba->pport->work_port_lock,
  7648. iflag);
  7649. lpfc_mbox_cmpl_put(phba, pmb);
  7650. }
  7651. } else
  7652. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7653. if ((work_ha_copy & HA_MBATT) &&
  7654. (phba->sli.mbox_active == NULL)) {
  7655. send_current_mbox:
  7656. /* Process next mailbox command if there is one */
  7657. do {
  7658. rc = lpfc_sli_issue_mbox(phba, NULL,
  7659. MBX_NOWAIT);
  7660. } while (rc == MBX_NOT_FINISHED);
  7661. if (rc != MBX_SUCCESS)
  7662. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7663. LOG_SLI, "0349 rc should be "
  7664. "MBX_SUCCESS\n");
  7665. }
  7666. spin_lock_irqsave(&phba->hbalock, iflag);
  7667. phba->work_ha |= work_ha_copy;
  7668. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7669. lpfc_worker_wake_up(phba);
  7670. }
  7671. return IRQ_HANDLED;
  7672. } /* lpfc_sli_sp_intr_handler */
  7673. /**
  7674. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7675. * @irq: Interrupt number.
  7676. * @dev_id: The device context pointer.
  7677. *
  7678. * This function is directly called from the PCI layer as an interrupt
  7679. * service routine when device with SLI-3 interface spec is enabled with
  7680. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7681. * ring event in the HBA. However, when the device is enabled with either
  7682. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7683. * device-level interrupt handler. When the PCI slot is in error recovery
  7684. * or the HBA is undergoing initialization, the interrupt handler will not
  7685. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7686. * the intrrupt context. This function is called without any lock held.
  7687. * It gets the hbalock to access and update SLI data structures.
  7688. *
  7689. * This function returns IRQ_HANDLED when interrupt is handled else it
  7690. * returns IRQ_NONE.
  7691. **/
  7692. irqreturn_t
  7693. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7694. {
  7695. struct lpfc_hba *phba;
  7696. uint32_t ha_copy;
  7697. unsigned long status;
  7698. unsigned long iflag;
  7699. /* Get the driver's phba structure from the dev_id and
  7700. * assume the HBA is not interrupting.
  7701. */
  7702. phba = (struct lpfc_hba *) dev_id;
  7703. if (unlikely(!phba))
  7704. return IRQ_NONE;
  7705. /*
  7706. * Stuff needs to be attented to when this function is invoked as an
  7707. * individual interrupt handler in MSI-X multi-message interrupt mode
  7708. */
  7709. if (phba->intr_type == MSIX) {
  7710. /* Check device state for handling interrupt */
  7711. if (lpfc_intr_state_check(phba))
  7712. return IRQ_NONE;
  7713. /* Need to read HA REG for FCP ring and other ring events */
  7714. ha_copy = readl(phba->HAregaddr);
  7715. /* Clear up only attention source related to fast-path */
  7716. spin_lock_irqsave(&phba->hbalock, iflag);
  7717. /*
  7718. * If there is deferred error attention, do not check for
  7719. * any interrupt.
  7720. */
  7721. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7722. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7723. return IRQ_NONE;
  7724. }
  7725. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7726. phba->HAregaddr);
  7727. readl(phba->HAregaddr); /* flush */
  7728. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7729. } else
  7730. ha_copy = phba->ha_copy;
  7731. /*
  7732. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7733. */
  7734. ha_copy &= ~(phba->work_ha_mask);
  7735. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7736. status >>= (4*LPFC_FCP_RING);
  7737. if (status & HA_RXMASK)
  7738. lpfc_sli_handle_fast_ring_event(phba,
  7739. &phba->sli.ring[LPFC_FCP_RING],
  7740. status);
  7741. if (phba->cfg_multi_ring_support == 2) {
  7742. /*
  7743. * Process all events on extra ring. Take the optimized path
  7744. * for extra ring IO.
  7745. */
  7746. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7747. status >>= (4*LPFC_EXTRA_RING);
  7748. if (status & HA_RXMASK) {
  7749. lpfc_sli_handle_fast_ring_event(phba,
  7750. &phba->sli.ring[LPFC_EXTRA_RING],
  7751. status);
  7752. }
  7753. }
  7754. return IRQ_HANDLED;
  7755. } /* lpfc_sli_fp_intr_handler */
  7756. /**
  7757. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7758. * @irq: Interrupt number.
  7759. * @dev_id: The device context pointer.
  7760. *
  7761. * This function is the HBA device-level interrupt handler to device with
  7762. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7763. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7764. * requires driver attention. This function invokes the slow-path interrupt
  7765. * attention handling function and fast-path interrupt attention handling
  7766. * function in turn to process the relevant HBA attention events. This
  7767. * function is called without any lock held. It gets the hbalock to access
  7768. * and update SLI data structures.
  7769. *
  7770. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7771. * returns IRQ_NONE.
  7772. **/
  7773. irqreturn_t
  7774. lpfc_sli_intr_handler(int irq, void *dev_id)
  7775. {
  7776. struct lpfc_hba *phba;
  7777. irqreturn_t sp_irq_rc, fp_irq_rc;
  7778. unsigned long status1, status2;
  7779. uint32_t hc_copy;
  7780. /*
  7781. * Get the driver's phba structure from the dev_id and
  7782. * assume the HBA is not interrupting.
  7783. */
  7784. phba = (struct lpfc_hba *) dev_id;
  7785. if (unlikely(!phba))
  7786. return IRQ_NONE;
  7787. /* Check device state for handling interrupt */
  7788. if (lpfc_intr_state_check(phba))
  7789. return IRQ_NONE;
  7790. spin_lock(&phba->hbalock);
  7791. phba->ha_copy = readl(phba->HAregaddr);
  7792. if (unlikely(!phba->ha_copy)) {
  7793. spin_unlock(&phba->hbalock);
  7794. return IRQ_NONE;
  7795. } else if (phba->ha_copy & HA_ERATT) {
  7796. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7797. /* ERATT polling has handled ERATT */
  7798. phba->ha_copy &= ~HA_ERATT;
  7799. else
  7800. /* Indicate interrupt handler handles ERATT */
  7801. phba->hba_flag |= HBA_ERATT_HANDLED;
  7802. }
  7803. /*
  7804. * If there is deferred error attention, do not check for any interrupt.
  7805. */
  7806. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7807. spin_unlock(&phba->hbalock);
  7808. return IRQ_NONE;
  7809. }
  7810. /* Clear attention sources except link and error attentions */
  7811. hc_copy = readl(phba->HCregaddr);
  7812. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  7813. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  7814. phba->HCregaddr);
  7815. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7816. writel(hc_copy, phba->HCregaddr);
  7817. readl(phba->HAregaddr); /* flush */
  7818. spin_unlock(&phba->hbalock);
  7819. /*
  7820. * Invokes slow-path host attention interrupt handling as appropriate.
  7821. */
  7822. /* status of events with mailbox and link attention */
  7823. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7824. /* status of events with ELS ring */
  7825. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7826. status2 >>= (4*LPFC_ELS_RING);
  7827. if (status1 || (status2 & HA_RXMASK))
  7828. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7829. else
  7830. sp_irq_rc = IRQ_NONE;
  7831. /*
  7832. * Invoke fast-path host attention interrupt handling as appropriate.
  7833. */
  7834. /* status of events with FCP ring */
  7835. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7836. status1 >>= (4*LPFC_FCP_RING);
  7837. /* status of events with extra ring */
  7838. if (phba->cfg_multi_ring_support == 2) {
  7839. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7840. status2 >>= (4*LPFC_EXTRA_RING);
  7841. } else
  7842. status2 = 0;
  7843. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7844. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7845. else
  7846. fp_irq_rc = IRQ_NONE;
  7847. /* Return device-level interrupt handling status */
  7848. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7849. } /* lpfc_sli_intr_handler */
  7850. /**
  7851. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7852. * @phba: pointer to lpfc hba data structure.
  7853. *
  7854. * This routine is invoked by the worker thread to process all the pending
  7855. * SLI4 FCP abort XRI events.
  7856. **/
  7857. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7858. {
  7859. struct lpfc_cq_event *cq_event;
  7860. /* First, declare the fcp xri abort event has been handled */
  7861. spin_lock_irq(&phba->hbalock);
  7862. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7863. spin_unlock_irq(&phba->hbalock);
  7864. /* Now, handle all the fcp xri abort events */
  7865. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7866. /* Get the first event from the head of the event queue */
  7867. spin_lock_irq(&phba->hbalock);
  7868. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7869. cq_event, struct lpfc_cq_event, list);
  7870. spin_unlock_irq(&phba->hbalock);
  7871. /* Notify aborted XRI for FCP work queue */
  7872. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7873. /* Free the event processed back to the free pool */
  7874. lpfc_sli4_cq_event_release(phba, cq_event);
  7875. }
  7876. }
  7877. /**
  7878. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7879. * @phba: pointer to lpfc hba data structure.
  7880. *
  7881. * This routine is invoked by the worker thread to process all the pending
  7882. * SLI4 els abort xri events.
  7883. **/
  7884. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7885. {
  7886. struct lpfc_cq_event *cq_event;
  7887. /* First, declare the els xri abort event has been handled */
  7888. spin_lock_irq(&phba->hbalock);
  7889. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7890. spin_unlock_irq(&phba->hbalock);
  7891. /* Now, handle all the els xri abort events */
  7892. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7893. /* Get the first event from the head of the event queue */
  7894. spin_lock_irq(&phba->hbalock);
  7895. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7896. cq_event, struct lpfc_cq_event, list);
  7897. spin_unlock_irq(&phba->hbalock);
  7898. /* Notify aborted XRI for ELS work queue */
  7899. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7900. /* Free the event processed back to the free pool */
  7901. lpfc_sli4_cq_event_release(phba, cq_event);
  7902. }
  7903. }
  7904. /**
  7905. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  7906. * @phba: pointer to lpfc hba data structure
  7907. * @pIocbIn: pointer to the rspiocbq
  7908. * @pIocbOut: pointer to the cmdiocbq
  7909. * @wcqe: pointer to the complete wcqe
  7910. *
  7911. * This routine transfers the fields of a command iocbq to a response iocbq
  7912. * by copying all the IOCB fields from command iocbq and transferring the
  7913. * completion status information from the complete wcqe.
  7914. **/
  7915. static void
  7916. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  7917. struct lpfc_iocbq *pIocbIn,
  7918. struct lpfc_iocbq *pIocbOut,
  7919. struct lpfc_wcqe_complete *wcqe)
  7920. {
  7921. unsigned long iflags;
  7922. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7923. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7924. sizeof(struct lpfc_iocbq) - offset);
  7925. /* Map WCQE parameters into irspiocb parameters */
  7926. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7927. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7928. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7929. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7930. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7931. wcqe->total_data_placed;
  7932. else
  7933. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7934. else {
  7935. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7936. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  7937. }
  7938. /* Pick up HBA exchange busy condition */
  7939. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  7940. spin_lock_irqsave(&phba->hbalock, iflags);
  7941. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  7942. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7943. }
  7944. }
  7945. /**
  7946. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  7947. * @phba: Pointer to HBA context object.
  7948. * @wcqe: Pointer to work-queue completion queue entry.
  7949. *
  7950. * This routine handles an ELS work-queue completion event and construct
  7951. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  7952. * discovery engine to handle.
  7953. *
  7954. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  7955. **/
  7956. static struct lpfc_iocbq *
  7957. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  7958. struct lpfc_iocbq *irspiocbq)
  7959. {
  7960. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7961. struct lpfc_iocbq *cmdiocbq;
  7962. struct lpfc_wcqe_complete *wcqe;
  7963. unsigned long iflags;
  7964. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  7965. spin_lock_irqsave(&phba->hbalock, iflags);
  7966. pring->stats.iocb_event++;
  7967. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7968. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7969. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7970. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7971. if (unlikely(!cmdiocbq)) {
  7972. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7973. "0386 ELS complete with no corresponding "
  7974. "cmdiocb: iotag (%d)\n",
  7975. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7976. lpfc_sli_release_iocbq(phba, irspiocbq);
  7977. return NULL;
  7978. }
  7979. /* Fake the irspiocbq and copy necessary response information */
  7980. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  7981. return irspiocbq;
  7982. }
  7983. /**
  7984. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7985. * @phba: Pointer to HBA context object.
  7986. * @cqe: Pointer to mailbox completion queue entry.
  7987. *
  7988. * This routine process a mailbox completion queue entry with asynchrous
  7989. * event.
  7990. *
  7991. * Return: true if work posted to worker thread, otherwise false.
  7992. **/
  7993. static bool
  7994. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7995. {
  7996. struct lpfc_cq_event *cq_event;
  7997. unsigned long iflags;
  7998. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7999. "0392 Async Event: word0:x%x, word1:x%x, "
  8000. "word2:x%x, word3:x%x\n", mcqe->word0,
  8001. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  8002. /* Allocate a new internal CQ_EVENT entry */
  8003. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8004. if (!cq_event) {
  8005. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8006. "0394 Failed to allocate CQ_EVENT entry\n");
  8007. return false;
  8008. }
  8009. /* Move the CQE into an asynchronous event entry */
  8010. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  8011. spin_lock_irqsave(&phba->hbalock, iflags);
  8012. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  8013. /* Set the async event flag */
  8014. phba->hba_flag |= ASYNC_EVENT;
  8015. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8016. return true;
  8017. }
  8018. /**
  8019. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  8020. * @phba: Pointer to HBA context object.
  8021. * @cqe: Pointer to mailbox completion queue entry.
  8022. *
  8023. * This routine process a mailbox completion queue entry with mailbox
  8024. * completion event.
  8025. *
  8026. * Return: true if work posted to worker thread, otherwise false.
  8027. **/
  8028. static bool
  8029. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  8030. {
  8031. uint32_t mcqe_status;
  8032. MAILBOX_t *mbox, *pmbox;
  8033. struct lpfc_mqe *mqe;
  8034. struct lpfc_vport *vport;
  8035. struct lpfc_nodelist *ndlp;
  8036. struct lpfc_dmabuf *mp;
  8037. unsigned long iflags;
  8038. LPFC_MBOXQ_t *pmb;
  8039. bool workposted = false;
  8040. int rc;
  8041. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  8042. if (!bf_get(lpfc_trailer_completed, mcqe))
  8043. goto out_no_mqe_complete;
  8044. /* Get the reference to the active mbox command */
  8045. spin_lock_irqsave(&phba->hbalock, iflags);
  8046. pmb = phba->sli.mbox_active;
  8047. if (unlikely(!pmb)) {
  8048. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  8049. "1832 No pending MBOX command to handle\n");
  8050. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8051. goto out_no_mqe_complete;
  8052. }
  8053. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8054. mqe = &pmb->u.mqe;
  8055. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  8056. mbox = phba->mbox;
  8057. vport = pmb->vport;
  8058. /* Reset heartbeat timer */
  8059. phba->last_completion_time = jiffies;
  8060. del_timer(&phba->sli.mbox_tmo);
  8061. /* Move mbox data to caller's mailbox region, do endian swapping */
  8062. if (pmb->mbox_cmpl && mbox)
  8063. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  8064. /* Set the mailbox status with SLI4 range 0x4000 */
  8065. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  8066. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  8067. bf_set(lpfc_mqe_status, mqe,
  8068. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8069. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  8070. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  8071. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  8072. "MBOX dflt rpi: status:x%x rpi:x%x",
  8073. mcqe_status,
  8074. pmbox->un.varWords[0], 0);
  8075. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  8076. mp = (struct lpfc_dmabuf *)(pmb->context1);
  8077. ndlp = (struct lpfc_nodelist *)pmb->context2;
  8078. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  8079. * RID of the PPI using the same mbox buffer.
  8080. */
  8081. lpfc_unreg_login(phba, vport->vpi,
  8082. pmbox->un.varWords[0], pmb);
  8083. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  8084. pmb->context1 = mp;
  8085. pmb->context2 = ndlp;
  8086. pmb->vport = vport;
  8087. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  8088. if (rc != MBX_BUSY)
  8089. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  8090. LOG_SLI, "0385 rc should "
  8091. "have been MBX_BUSY\n");
  8092. if (rc != MBX_NOT_FINISHED)
  8093. goto send_current_mbox;
  8094. }
  8095. }
  8096. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  8097. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8098. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  8099. /* There is mailbox completion work to do */
  8100. spin_lock_irqsave(&phba->hbalock, iflags);
  8101. __lpfc_mbox_cmpl_put(phba, pmb);
  8102. phba->work_ha |= HA_MBATT;
  8103. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8104. workposted = true;
  8105. send_current_mbox:
  8106. spin_lock_irqsave(&phba->hbalock, iflags);
  8107. /* Release the mailbox command posting token */
  8108. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8109. /* Setting active mailbox pointer need to be in sync to flag clear */
  8110. phba->sli.mbox_active = NULL;
  8111. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8112. /* Wake up worker thread to post the next pending mailbox command */
  8113. lpfc_worker_wake_up(phba);
  8114. out_no_mqe_complete:
  8115. if (bf_get(lpfc_trailer_consumed, mcqe))
  8116. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  8117. return workposted;
  8118. }
  8119. /**
  8120. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  8121. * @phba: Pointer to HBA context object.
  8122. * @cqe: Pointer to mailbox completion queue entry.
  8123. *
  8124. * This routine process a mailbox completion queue entry, it invokes the
  8125. * proper mailbox complete handling or asynchrous event handling routine
  8126. * according to the MCQE's async bit.
  8127. *
  8128. * Return: true if work posted to worker thread, otherwise false.
  8129. **/
  8130. static bool
  8131. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  8132. {
  8133. struct lpfc_mcqe mcqe;
  8134. bool workposted;
  8135. /* Copy the mailbox MCQE and convert endian order as needed */
  8136. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  8137. /* Invoke the proper event handling routine */
  8138. if (!bf_get(lpfc_trailer_async, &mcqe))
  8139. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  8140. else
  8141. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  8142. return workposted;
  8143. }
  8144. /**
  8145. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  8146. * @phba: Pointer to HBA context object.
  8147. * @wcqe: Pointer to work-queue completion queue entry.
  8148. *
  8149. * This routine handles an ELS work-queue completion event.
  8150. *
  8151. * Return: true if work posted to worker thread, otherwise false.
  8152. **/
  8153. static bool
  8154. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  8155. struct lpfc_wcqe_complete *wcqe)
  8156. {
  8157. struct lpfc_iocbq *irspiocbq;
  8158. unsigned long iflags;
  8159. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8160. /* Get an irspiocbq for later ELS response processing use */
  8161. irspiocbq = lpfc_sli_get_iocbq(phba);
  8162. if (!irspiocbq) {
  8163. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8164. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  8165. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  8166. pring->txq_cnt, phba->iocb_cnt,
  8167. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  8168. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  8169. return false;
  8170. }
  8171. /* Save off the slow-path queue event for work thread to process */
  8172. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  8173. spin_lock_irqsave(&phba->hbalock, iflags);
  8174. list_add_tail(&irspiocbq->cq_event.list,
  8175. &phba->sli4_hba.sp_queue_event);
  8176. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8177. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8178. return true;
  8179. }
  8180. /**
  8181. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  8182. * @phba: Pointer to HBA context object.
  8183. * @wcqe: Pointer to work-queue completion queue entry.
  8184. *
  8185. * This routine handles slow-path WQ entry comsumed event by invoking the
  8186. * proper WQ release routine to the slow-path WQ.
  8187. **/
  8188. static void
  8189. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  8190. struct lpfc_wcqe_release *wcqe)
  8191. {
  8192. /* Check for the slow-path ELS work queue */
  8193. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  8194. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  8195. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8196. else
  8197. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8198. "2579 Slow-path wqe consume event carries "
  8199. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  8200. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  8201. phba->sli4_hba.els_wq->queue_id);
  8202. }
  8203. /**
  8204. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  8205. * @phba: Pointer to HBA context object.
  8206. * @cq: Pointer to a WQ completion queue.
  8207. * @wcqe: Pointer to work-queue completion queue entry.
  8208. *
  8209. * This routine handles an XRI abort event.
  8210. *
  8211. * Return: true if work posted to worker thread, otherwise false.
  8212. **/
  8213. static bool
  8214. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  8215. struct lpfc_queue *cq,
  8216. struct sli4_wcqe_xri_aborted *wcqe)
  8217. {
  8218. bool workposted = false;
  8219. struct lpfc_cq_event *cq_event;
  8220. unsigned long iflags;
  8221. /* Allocate a new internal CQ_EVENT entry */
  8222. cq_event = lpfc_sli4_cq_event_alloc(phba);
  8223. if (!cq_event) {
  8224. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8225. "0602 Failed to allocate CQ_EVENT entry\n");
  8226. return false;
  8227. }
  8228. /* Move the CQE into the proper xri abort event list */
  8229. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  8230. switch (cq->subtype) {
  8231. case LPFC_FCP:
  8232. spin_lock_irqsave(&phba->hbalock, iflags);
  8233. list_add_tail(&cq_event->list,
  8234. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  8235. /* Set the fcp xri abort event flag */
  8236. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  8237. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8238. workposted = true;
  8239. break;
  8240. case LPFC_ELS:
  8241. spin_lock_irqsave(&phba->hbalock, iflags);
  8242. list_add_tail(&cq_event->list,
  8243. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  8244. /* Set the els xri abort event flag */
  8245. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  8246. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8247. workposted = true;
  8248. break;
  8249. default:
  8250. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8251. "0603 Invalid work queue CQE subtype (x%x)\n",
  8252. cq->subtype);
  8253. workposted = false;
  8254. break;
  8255. }
  8256. return workposted;
  8257. }
  8258. /**
  8259. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  8260. * @phba: Pointer to HBA context object.
  8261. * @rcqe: Pointer to receive-queue completion queue entry.
  8262. *
  8263. * This routine process a receive-queue completion queue entry.
  8264. *
  8265. * Return: true if work posted to worker thread, otherwise false.
  8266. **/
  8267. static bool
  8268. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  8269. {
  8270. bool workposted = false;
  8271. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  8272. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  8273. struct hbq_dmabuf *dma_buf;
  8274. uint32_t status;
  8275. unsigned long iflags;
  8276. if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id)
  8277. goto out;
  8278. status = bf_get(lpfc_rcqe_status, rcqe);
  8279. switch (status) {
  8280. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  8281. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8282. "2537 Receive Frame Truncated!!\n");
  8283. case FC_STATUS_RQ_SUCCESS:
  8284. lpfc_sli4_rq_release(hrq, drq);
  8285. spin_lock_irqsave(&phba->hbalock, iflags);
  8286. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  8287. if (!dma_buf) {
  8288. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8289. goto out;
  8290. }
  8291. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  8292. /* save off the frame for the word thread to process */
  8293. list_add_tail(&dma_buf->cq_event.list,
  8294. &phba->sli4_hba.sp_queue_event);
  8295. /* Frame received */
  8296. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  8297. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8298. workposted = true;
  8299. break;
  8300. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  8301. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  8302. /* Post more buffers if possible */
  8303. spin_lock_irqsave(&phba->hbalock, iflags);
  8304. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  8305. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8306. workposted = true;
  8307. break;
  8308. }
  8309. out:
  8310. return workposted;
  8311. }
  8312. /**
  8313. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  8314. * @phba: Pointer to HBA context object.
  8315. * @cq: Pointer to the completion queue.
  8316. * @wcqe: Pointer to a completion queue entry.
  8317. *
  8318. * This routine process a slow-path work-queue or recieve queue completion queue
  8319. * entry.
  8320. *
  8321. * Return: true if work posted to worker thread, otherwise false.
  8322. **/
  8323. static bool
  8324. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8325. struct lpfc_cqe *cqe)
  8326. {
  8327. struct lpfc_cqe cqevt;
  8328. bool workposted = false;
  8329. /* Copy the work queue CQE and convert endian order if needed */
  8330. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  8331. /* Check and process for different type of WCQE and dispatch */
  8332. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  8333. case CQE_CODE_COMPL_WQE:
  8334. /* Process the WQ/RQ complete event */
  8335. phba->last_completion_time = jiffies;
  8336. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  8337. (struct lpfc_wcqe_complete *)&cqevt);
  8338. break;
  8339. case CQE_CODE_RELEASE_WQE:
  8340. /* Process the WQ release event */
  8341. lpfc_sli4_sp_handle_rel_wcqe(phba,
  8342. (struct lpfc_wcqe_release *)&cqevt);
  8343. break;
  8344. case CQE_CODE_XRI_ABORTED:
  8345. /* Process the WQ XRI abort event */
  8346. phba->last_completion_time = jiffies;
  8347. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8348. (struct sli4_wcqe_xri_aborted *)&cqevt);
  8349. break;
  8350. case CQE_CODE_RECEIVE:
  8351. /* Process the RQ event */
  8352. phba->last_completion_time = jiffies;
  8353. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  8354. (struct lpfc_rcqe *)&cqevt);
  8355. break;
  8356. default:
  8357. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8358. "0388 Not a valid WCQE code: x%x\n",
  8359. bf_get(lpfc_cqe_code, &cqevt));
  8360. break;
  8361. }
  8362. return workposted;
  8363. }
  8364. /**
  8365. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  8366. * @phba: Pointer to HBA context object.
  8367. * @eqe: Pointer to fast-path event queue entry.
  8368. *
  8369. * This routine process a event queue entry from the slow-path event queue.
  8370. * It will check the MajorCode and MinorCode to determine this is for a
  8371. * completion event on a completion queue, if not, an error shall be logged
  8372. * and just return. Otherwise, it will get to the corresponding completion
  8373. * queue and process all the entries on that completion queue, rearm the
  8374. * completion queue, and then return.
  8375. *
  8376. **/
  8377. static void
  8378. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  8379. {
  8380. struct lpfc_queue *cq = NULL, *childq, *speq;
  8381. struct lpfc_cqe *cqe;
  8382. bool workposted = false;
  8383. int ecount = 0;
  8384. uint16_t cqid;
  8385. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  8386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8387. "0359 Not a valid slow-path completion "
  8388. "event: majorcode=x%x, minorcode=x%x\n",
  8389. bf_get_le32(lpfc_eqe_major_code, eqe),
  8390. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8391. return;
  8392. }
  8393. /* Get the reference to the corresponding CQ */
  8394. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8395. /* Search for completion queue pointer matching this cqid */
  8396. speq = phba->sli4_hba.sp_eq;
  8397. list_for_each_entry(childq, &speq->child_list, list) {
  8398. if (childq->queue_id == cqid) {
  8399. cq = childq;
  8400. break;
  8401. }
  8402. }
  8403. if (unlikely(!cq)) {
  8404. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8405. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8406. "0365 Slow-path CQ identifier "
  8407. "(%d) does not exist\n", cqid);
  8408. return;
  8409. }
  8410. /* Process all the entries to the CQ */
  8411. switch (cq->type) {
  8412. case LPFC_MCQ:
  8413. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8414. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  8415. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8416. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8417. }
  8418. break;
  8419. case LPFC_WCQ:
  8420. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8421. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe);
  8422. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8423. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8424. }
  8425. break;
  8426. default:
  8427. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8428. "0370 Invalid completion queue type (%d)\n",
  8429. cq->type);
  8430. return;
  8431. }
  8432. /* Catch the no cq entry condition, log an error */
  8433. if (unlikely(ecount == 0))
  8434. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8435. "0371 No entry from the CQ: identifier "
  8436. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  8437. /* In any case, flash and re-arm the RCQ */
  8438. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8439. /* wake up worker thread if there are works to be done */
  8440. if (workposted)
  8441. lpfc_worker_wake_up(phba);
  8442. }
  8443. /**
  8444. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  8445. * @eqe: Pointer to fast-path completion queue entry.
  8446. *
  8447. * This routine process a fast-path work queue completion entry from fast-path
  8448. * event queue for FCP command response completion.
  8449. **/
  8450. static void
  8451. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  8452. struct lpfc_wcqe_complete *wcqe)
  8453. {
  8454. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  8455. struct lpfc_iocbq *cmdiocbq;
  8456. struct lpfc_iocbq irspiocbq;
  8457. unsigned long iflags;
  8458. spin_lock_irqsave(&phba->hbalock, iflags);
  8459. pring->stats.iocb_event++;
  8460. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8461. /* Check for response status */
  8462. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  8463. /* If resource errors reported from HBA, reduce queue
  8464. * depth of the SCSI device.
  8465. */
  8466. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  8467. IOSTAT_LOCAL_REJECT) &&
  8468. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  8469. phba->lpfc_rampdown_queue_depth(phba);
  8470. }
  8471. /* Log the error status */
  8472. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8473. "0373 FCP complete error: status=x%x, "
  8474. "hw_status=x%x, total_data_specified=%d, "
  8475. "parameter=x%x, word3=x%x\n",
  8476. bf_get(lpfc_wcqe_c_status, wcqe),
  8477. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  8478. wcqe->total_data_placed, wcqe->parameter,
  8479. wcqe->word3);
  8480. }
  8481. /* Look up the FCP command IOCB and create pseudo response IOCB */
  8482. spin_lock_irqsave(&phba->hbalock, iflags);
  8483. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  8484. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8485. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8486. if (unlikely(!cmdiocbq)) {
  8487. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8488. "0374 FCP complete with no corresponding "
  8489. "cmdiocb: iotag (%d)\n",
  8490. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8491. return;
  8492. }
  8493. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  8494. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8495. "0375 FCP cmdiocb not callback function "
  8496. "iotag: (%d)\n",
  8497. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  8498. return;
  8499. }
  8500. /* Fake the irspiocb and copy necessary response information */
  8501. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  8502. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  8503. spin_lock_irqsave(&phba->hbalock, iflags);
  8504. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  8505. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8506. }
  8507. /* Pass the cmd_iocb and the rsp state to the upper layer */
  8508. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  8509. }
  8510. /**
  8511. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  8512. * @phba: Pointer to HBA context object.
  8513. * @cq: Pointer to completion queue.
  8514. * @wcqe: Pointer to work-queue completion queue entry.
  8515. *
  8516. * This routine handles an fast-path WQ entry comsumed event by invoking the
  8517. * proper WQ release routine to the slow-path WQ.
  8518. **/
  8519. static void
  8520. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8521. struct lpfc_wcqe_release *wcqe)
  8522. {
  8523. struct lpfc_queue *childwq;
  8524. bool wqid_matched = false;
  8525. uint16_t fcp_wqid;
  8526. /* Check for fast-path FCP work queue release */
  8527. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8528. list_for_each_entry(childwq, &cq->child_list, list) {
  8529. if (childwq->queue_id == fcp_wqid) {
  8530. lpfc_sli4_wq_release(childwq,
  8531. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8532. wqid_matched = true;
  8533. break;
  8534. }
  8535. }
  8536. /* Report warning log message if no match found */
  8537. if (wqid_matched != true)
  8538. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8539. "2580 Fast-path wqe consume event carries "
  8540. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8541. }
  8542. /**
  8543. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8544. * @cq: Pointer to the completion queue.
  8545. * @eqe: Pointer to fast-path completion queue entry.
  8546. *
  8547. * This routine process a fast-path work queue completion entry from fast-path
  8548. * event queue for FCP command response completion.
  8549. **/
  8550. static int
  8551. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8552. struct lpfc_cqe *cqe)
  8553. {
  8554. struct lpfc_wcqe_release wcqe;
  8555. bool workposted = false;
  8556. /* Copy the work queue CQE and convert endian order if needed */
  8557. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8558. /* Check and process for different type of WCQE and dispatch */
  8559. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8560. case CQE_CODE_COMPL_WQE:
  8561. /* Process the WQ complete event */
  8562. phba->last_completion_time = jiffies;
  8563. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8564. (struct lpfc_wcqe_complete *)&wcqe);
  8565. break;
  8566. case CQE_CODE_RELEASE_WQE:
  8567. /* Process the WQ release event */
  8568. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8569. (struct lpfc_wcqe_release *)&wcqe);
  8570. break;
  8571. case CQE_CODE_XRI_ABORTED:
  8572. /* Process the WQ XRI abort event */
  8573. phba->last_completion_time = jiffies;
  8574. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8575. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8576. break;
  8577. default:
  8578. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8579. "0144 Not a valid WCQE code: x%x\n",
  8580. bf_get(lpfc_wcqe_c_code, &wcqe));
  8581. break;
  8582. }
  8583. return workposted;
  8584. }
  8585. /**
  8586. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8587. * @phba: Pointer to HBA context object.
  8588. * @eqe: Pointer to fast-path event queue entry.
  8589. *
  8590. * This routine process a event queue entry from the fast-path event queue.
  8591. * It will check the MajorCode and MinorCode to determine this is for a
  8592. * completion event on a completion queue, if not, an error shall be logged
  8593. * and just return. Otherwise, it will get to the corresponding completion
  8594. * queue and process all the entries on the completion queue, rearm the
  8595. * completion queue, and then return.
  8596. **/
  8597. static void
  8598. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8599. uint32_t fcp_cqidx)
  8600. {
  8601. struct lpfc_queue *cq;
  8602. struct lpfc_cqe *cqe;
  8603. bool workposted = false;
  8604. uint16_t cqid;
  8605. int ecount = 0;
  8606. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  8607. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8608. "0366 Not a valid fast-path completion "
  8609. "event: majorcode=x%x, minorcode=x%x\n",
  8610. bf_get_le32(lpfc_eqe_major_code, eqe),
  8611. bf_get_le32(lpfc_eqe_minor_code, eqe));
  8612. return;
  8613. }
  8614. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8615. if (unlikely(!cq)) {
  8616. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  8617. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8618. "0367 Fast-path completion queue "
  8619. "does not exist\n");
  8620. return;
  8621. }
  8622. /* Get the reference to the corresponding CQ */
  8623. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  8624. if (unlikely(cqid != cq->queue_id)) {
  8625. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8626. "0368 Miss-matched fast-path completion "
  8627. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8628. cqid, cq->queue_id);
  8629. return;
  8630. }
  8631. /* Process all the entries to the CQ */
  8632. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8633. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8634. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8635. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8636. }
  8637. /* Catch the no cq entry condition */
  8638. if (unlikely(ecount == 0))
  8639. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8640. "0369 No entry from fast-path completion "
  8641. "queue fcpcqid=%d\n", cq->queue_id);
  8642. /* In any case, flash and re-arm the CQ */
  8643. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8644. /* wake up worker thread if there are works to be done */
  8645. if (workposted)
  8646. lpfc_worker_wake_up(phba);
  8647. }
  8648. static void
  8649. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8650. {
  8651. struct lpfc_eqe *eqe;
  8652. /* walk all the EQ entries and drop on the floor */
  8653. while ((eqe = lpfc_sli4_eq_get(eq)))
  8654. ;
  8655. /* Clear and re-arm the EQ */
  8656. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8657. }
  8658. /**
  8659. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8660. * @irq: Interrupt number.
  8661. * @dev_id: The device context pointer.
  8662. *
  8663. * This function is directly called from the PCI layer as an interrupt
  8664. * service routine when device with SLI-4 interface spec is enabled with
  8665. * MSI-X multi-message interrupt mode and there are slow-path events in
  8666. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8667. * interrupt mode, this function is called as part of the device-level
  8668. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8669. * undergoing initialization, the interrupt handler will not process the
  8670. * interrupt. The link attention and ELS ring attention events are handled
  8671. * by the worker thread. The interrupt handler signals the worker thread
  8672. * and returns for these events. This function is called without any lock
  8673. * held. It gets the hbalock to access and update SLI data structures.
  8674. *
  8675. * This function returns IRQ_HANDLED when interrupt is handled else it
  8676. * returns IRQ_NONE.
  8677. **/
  8678. irqreturn_t
  8679. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8680. {
  8681. struct lpfc_hba *phba;
  8682. struct lpfc_queue *speq;
  8683. struct lpfc_eqe *eqe;
  8684. unsigned long iflag;
  8685. int ecount = 0;
  8686. /*
  8687. * Get the driver's phba structure from the dev_id
  8688. */
  8689. phba = (struct lpfc_hba *)dev_id;
  8690. if (unlikely(!phba))
  8691. return IRQ_NONE;
  8692. /* Get to the EQ struct associated with this vector */
  8693. speq = phba->sli4_hba.sp_eq;
  8694. /* Check device state for handling interrupt */
  8695. if (unlikely(lpfc_intr_state_check(phba))) {
  8696. /* Check again for link_state with lock held */
  8697. spin_lock_irqsave(&phba->hbalock, iflag);
  8698. if (phba->link_state < LPFC_LINK_DOWN)
  8699. /* Flush, clear interrupt, and rearm the EQ */
  8700. lpfc_sli4_eq_flush(phba, speq);
  8701. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8702. return IRQ_NONE;
  8703. }
  8704. /*
  8705. * Process all the event on FCP slow-path EQ
  8706. */
  8707. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8708. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8709. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8710. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8711. }
  8712. /* Always clear and re-arm the slow-path EQ */
  8713. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8714. /* Catch the no cq entry condition */
  8715. if (unlikely(ecount == 0)) {
  8716. if (phba->intr_type == MSIX)
  8717. /* MSI-X treated interrupt served as no EQ share INT */
  8718. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8719. "0357 MSI-X interrupt with no EQE\n");
  8720. else
  8721. /* Non MSI-X treated on interrupt as EQ share INT */
  8722. return IRQ_NONE;
  8723. }
  8724. return IRQ_HANDLED;
  8725. } /* lpfc_sli4_sp_intr_handler */
  8726. /**
  8727. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8728. * @irq: Interrupt number.
  8729. * @dev_id: The device context pointer.
  8730. *
  8731. * This function is directly called from the PCI layer as an interrupt
  8732. * service routine when device with SLI-4 interface spec is enabled with
  8733. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8734. * ring event in the HBA. However, when the device is enabled with either
  8735. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8736. * device-level interrupt handler. When the PCI slot is in error recovery
  8737. * or the HBA is undergoing initialization, the interrupt handler will not
  8738. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8739. * the intrrupt context. This function is called without any lock held.
  8740. * It gets the hbalock to access and update SLI data structures. Note that,
  8741. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8742. * equal to that of FCP CQ index.
  8743. *
  8744. * This function returns IRQ_HANDLED when interrupt is handled else it
  8745. * returns IRQ_NONE.
  8746. **/
  8747. irqreturn_t
  8748. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8749. {
  8750. struct lpfc_hba *phba;
  8751. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8752. struct lpfc_queue *fpeq;
  8753. struct lpfc_eqe *eqe;
  8754. unsigned long iflag;
  8755. int ecount = 0;
  8756. uint32_t fcp_eqidx;
  8757. /* Get the driver's phba structure from the dev_id */
  8758. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8759. phba = fcp_eq_hdl->phba;
  8760. fcp_eqidx = fcp_eq_hdl->idx;
  8761. if (unlikely(!phba))
  8762. return IRQ_NONE;
  8763. /* Get to the EQ struct associated with this vector */
  8764. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8765. /* Check device state for handling interrupt */
  8766. if (unlikely(lpfc_intr_state_check(phba))) {
  8767. /* Check again for link_state with lock held */
  8768. spin_lock_irqsave(&phba->hbalock, iflag);
  8769. if (phba->link_state < LPFC_LINK_DOWN)
  8770. /* Flush, clear interrupt, and rearm the EQ */
  8771. lpfc_sli4_eq_flush(phba, fpeq);
  8772. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8773. return IRQ_NONE;
  8774. }
  8775. /*
  8776. * Process all the event on FCP fast-path EQ
  8777. */
  8778. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8779. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8780. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8781. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8782. }
  8783. /* Always clear and re-arm the fast-path EQ */
  8784. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8785. if (unlikely(ecount == 0)) {
  8786. if (phba->intr_type == MSIX)
  8787. /* MSI-X treated interrupt served as no EQ share INT */
  8788. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8789. "0358 MSI-X interrupt with no EQE\n");
  8790. else
  8791. /* Non MSI-X treated on interrupt as EQ share INT */
  8792. return IRQ_NONE;
  8793. }
  8794. return IRQ_HANDLED;
  8795. } /* lpfc_sli4_fp_intr_handler */
  8796. /**
  8797. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8798. * @irq: Interrupt number.
  8799. * @dev_id: The device context pointer.
  8800. *
  8801. * This function is the device-level interrupt handler to device with SLI-4
  8802. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8803. * interrupt mode is enabled and there is an event in the HBA which requires
  8804. * driver attention. This function invokes the slow-path interrupt attention
  8805. * handling function and fast-path interrupt attention handling function in
  8806. * turn to process the relevant HBA attention events. This function is called
  8807. * without any lock held. It gets the hbalock to access and update SLI data
  8808. * structures.
  8809. *
  8810. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8811. * returns IRQ_NONE.
  8812. **/
  8813. irqreturn_t
  8814. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8815. {
  8816. struct lpfc_hba *phba;
  8817. irqreturn_t sp_irq_rc, fp_irq_rc;
  8818. bool fp_handled = false;
  8819. uint32_t fcp_eqidx;
  8820. /* Get the driver's phba structure from the dev_id */
  8821. phba = (struct lpfc_hba *)dev_id;
  8822. if (unlikely(!phba))
  8823. return IRQ_NONE;
  8824. /*
  8825. * Invokes slow-path host attention interrupt handling as appropriate.
  8826. */
  8827. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8828. /*
  8829. * Invoke fast-path host attention interrupt handling as appropriate.
  8830. */
  8831. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8832. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8833. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8834. if (fp_irq_rc == IRQ_HANDLED)
  8835. fp_handled |= true;
  8836. }
  8837. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8838. } /* lpfc_sli4_intr_handler */
  8839. /**
  8840. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8841. * @queue: The queue structure to free.
  8842. *
  8843. * This function frees a queue structure and the DMAable memeory used for
  8844. * the host resident queue. This function must be called after destroying the
  8845. * queue on the HBA.
  8846. **/
  8847. void
  8848. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8849. {
  8850. struct lpfc_dmabuf *dmabuf;
  8851. if (!queue)
  8852. return;
  8853. while (!list_empty(&queue->page_list)) {
  8854. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8855. list);
  8856. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  8857. dmabuf->virt, dmabuf->phys);
  8858. kfree(dmabuf);
  8859. }
  8860. kfree(queue);
  8861. return;
  8862. }
  8863. /**
  8864. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8865. * @phba: The HBA that this queue is being created on.
  8866. * @entry_size: The size of each queue entry for this queue.
  8867. * @entry count: The number of entries that this queue will handle.
  8868. *
  8869. * This function allocates a queue structure and the DMAable memory used for
  8870. * the host resident queue. This function must be called before creating the
  8871. * queue on the HBA.
  8872. **/
  8873. struct lpfc_queue *
  8874. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8875. uint32_t entry_count)
  8876. {
  8877. struct lpfc_queue *queue;
  8878. struct lpfc_dmabuf *dmabuf;
  8879. int x, total_qe_count;
  8880. void *dma_pointer;
  8881. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8882. if (!phba->sli4_hba.pc_sli4_params.supported)
  8883. hw_page_size = SLI4_PAGE_SIZE;
  8884. queue = kzalloc(sizeof(struct lpfc_queue) +
  8885. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8886. if (!queue)
  8887. return NULL;
  8888. queue->page_count = (ALIGN(entry_size * entry_count,
  8889. hw_page_size))/hw_page_size;
  8890. INIT_LIST_HEAD(&queue->list);
  8891. INIT_LIST_HEAD(&queue->page_list);
  8892. INIT_LIST_HEAD(&queue->child_list);
  8893. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8894. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8895. if (!dmabuf)
  8896. goto out_fail;
  8897. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8898. hw_page_size, &dmabuf->phys,
  8899. GFP_KERNEL);
  8900. if (!dmabuf->virt) {
  8901. kfree(dmabuf);
  8902. goto out_fail;
  8903. }
  8904. memset(dmabuf->virt, 0, hw_page_size);
  8905. dmabuf->buffer_tag = x;
  8906. list_add_tail(&dmabuf->list, &queue->page_list);
  8907. /* initialize queue's entry array */
  8908. dma_pointer = dmabuf->virt;
  8909. for (; total_qe_count < entry_count &&
  8910. dma_pointer < (hw_page_size + dmabuf->virt);
  8911. total_qe_count++, dma_pointer += entry_size) {
  8912. queue->qe[total_qe_count].address = dma_pointer;
  8913. }
  8914. }
  8915. queue->entry_size = entry_size;
  8916. queue->entry_count = entry_count;
  8917. queue->phba = phba;
  8918. return queue;
  8919. out_fail:
  8920. lpfc_sli4_queue_free(queue);
  8921. return NULL;
  8922. }
  8923. /**
  8924. * lpfc_eq_create - Create an Event Queue on the HBA
  8925. * @phba: HBA structure that indicates port to create a queue on.
  8926. * @eq: The queue structure to use to create the event queue.
  8927. * @imax: The maximum interrupt per second limit.
  8928. *
  8929. * This function creates an event queue, as detailed in @eq, on a port,
  8930. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8931. *
  8932. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8933. * is used to get the entry count and entry size that are necessary to
  8934. * determine the number of pages to allocate and use for this queue. This
  8935. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8936. * event queue. This function is asynchronous and will wait for the mailbox
  8937. * command to finish before continuing.
  8938. *
  8939. * On success this function will return a zero. If unable to allocate enough
  8940. * memory this function will return -ENOMEM. If the queue create mailbox command
  8941. * fails this function will return -ENXIO.
  8942. **/
  8943. uint32_t
  8944. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8945. {
  8946. struct lpfc_mbx_eq_create *eq_create;
  8947. LPFC_MBOXQ_t *mbox;
  8948. int rc, length, status = 0;
  8949. struct lpfc_dmabuf *dmabuf;
  8950. uint32_t shdr_status, shdr_add_status;
  8951. union lpfc_sli4_cfg_shdr *shdr;
  8952. uint16_t dmult;
  8953. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  8954. if (!phba->sli4_hba.pc_sli4_params.supported)
  8955. hw_page_size = SLI4_PAGE_SIZE;
  8956. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8957. if (!mbox)
  8958. return -ENOMEM;
  8959. length = (sizeof(struct lpfc_mbx_eq_create) -
  8960. sizeof(struct lpfc_sli4_cfg_mhdr));
  8961. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8962. LPFC_MBOX_OPCODE_EQ_CREATE,
  8963. length, LPFC_SLI4_MBX_EMBED);
  8964. eq_create = &mbox->u.mqe.un.eq_create;
  8965. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8966. eq->page_count);
  8967. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8968. LPFC_EQE_SIZE);
  8969. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8970. /* Calculate delay multiper from maximum interrupt per second */
  8971. dmult = LPFC_DMULT_CONST/imax - 1;
  8972. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8973. dmult);
  8974. switch (eq->entry_count) {
  8975. default:
  8976. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8977. "0360 Unsupported EQ count. (%d)\n",
  8978. eq->entry_count);
  8979. if (eq->entry_count < 256)
  8980. return -EINVAL;
  8981. /* otherwise default to smallest count (drop through) */
  8982. case 256:
  8983. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8984. LPFC_EQ_CNT_256);
  8985. break;
  8986. case 512:
  8987. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8988. LPFC_EQ_CNT_512);
  8989. break;
  8990. case 1024:
  8991. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8992. LPFC_EQ_CNT_1024);
  8993. break;
  8994. case 2048:
  8995. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8996. LPFC_EQ_CNT_2048);
  8997. break;
  8998. case 4096:
  8999. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  9000. LPFC_EQ_CNT_4096);
  9001. break;
  9002. }
  9003. list_for_each_entry(dmabuf, &eq->page_list, list) {
  9004. memset(dmabuf->virt, 0, hw_page_size);
  9005. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9006. putPaddrLow(dmabuf->phys);
  9007. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9008. putPaddrHigh(dmabuf->phys);
  9009. }
  9010. mbox->vport = phba->pport;
  9011. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9012. mbox->context1 = NULL;
  9013. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9014. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  9015. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9016. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9017. if (shdr_status || shdr_add_status || rc) {
  9018. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9019. "2500 EQ_CREATE mailbox failed with "
  9020. "status x%x add_status x%x, mbx status x%x\n",
  9021. shdr_status, shdr_add_status, rc);
  9022. status = -ENXIO;
  9023. }
  9024. eq->type = LPFC_EQ;
  9025. eq->subtype = LPFC_NONE;
  9026. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  9027. if (eq->queue_id == 0xFFFF)
  9028. status = -ENXIO;
  9029. eq->host_index = 0;
  9030. eq->hba_index = 0;
  9031. mempool_free(mbox, phba->mbox_mem_pool);
  9032. return status;
  9033. }
  9034. /**
  9035. * lpfc_cq_create - Create a Completion Queue on the HBA
  9036. * @phba: HBA structure that indicates port to create a queue on.
  9037. * @cq: The queue structure to use to create the completion queue.
  9038. * @eq: The event queue to bind this completion queue to.
  9039. *
  9040. * This function creates a completion queue, as detailed in @wq, on a port,
  9041. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  9042. *
  9043. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9044. * is used to get the entry count and entry size that are necessary to
  9045. * determine the number of pages to allocate and use for this queue. The @eq
  9046. * is used to indicate which event queue to bind this completion queue to. This
  9047. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  9048. * completion queue. This function is asynchronous and will wait for the mailbox
  9049. * command to finish before continuing.
  9050. *
  9051. * On success this function will return a zero. If unable to allocate enough
  9052. * memory this function will return -ENOMEM. If the queue create mailbox command
  9053. * fails this function will return -ENXIO.
  9054. **/
  9055. uint32_t
  9056. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  9057. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  9058. {
  9059. struct lpfc_mbx_cq_create *cq_create;
  9060. struct lpfc_dmabuf *dmabuf;
  9061. LPFC_MBOXQ_t *mbox;
  9062. int rc, length, status = 0;
  9063. uint32_t shdr_status, shdr_add_status;
  9064. union lpfc_sli4_cfg_shdr *shdr;
  9065. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9066. if (!phba->sli4_hba.pc_sli4_params.supported)
  9067. hw_page_size = SLI4_PAGE_SIZE;
  9068. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9069. if (!mbox)
  9070. return -ENOMEM;
  9071. length = (sizeof(struct lpfc_mbx_cq_create) -
  9072. sizeof(struct lpfc_sli4_cfg_mhdr));
  9073. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9074. LPFC_MBOX_OPCODE_CQ_CREATE,
  9075. length, LPFC_SLI4_MBX_EMBED);
  9076. cq_create = &mbox->u.mqe.un.cq_create;
  9077. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  9078. cq->page_count);
  9079. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  9080. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  9081. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  9082. switch (cq->entry_count) {
  9083. default:
  9084. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9085. "0361 Unsupported CQ count. (%d)\n",
  9086. cq->entry_count);
  9087. if (cq->entry_count < 256)
  9088. return -EINVAL;
  9089. /* otherwise default to smallest count (drop through) */
  9090. case 256:
  9091. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9092. LPFC_CQ_CNT_256);
  9093. break;
  9094. case 512:
  9095. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9096. LPFC_CQ_CNT_512);
  9097. break;
  9098. case 1024:
  9099. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  9100. LPFC_CQ_CNT_1024);
  9101. break;
  9102. }
  9103. list_for_each_entry(dmabuf, &cq->page_list, list) {
  9104. memset(dmabuf->virt, 0, hw_page_size);
  9105. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9106. putPaddrLow(dmabuf->phys);
  9107. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9108. putPaddrHigh(dmabuf->phys);
  9109. }
  9110. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9111. /* The IOCTL status is embedded in the mailbox subheader. */
  9112. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  9113. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9114. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9115. if (shdr_status || shdr_add_status || rc) {
  9116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9117. "2501 CQ_CREATE mailbox failed with "
  9118. "status x%x add_status x%x, mbx status x%x\n",
  9119. shdr_status, shdr_add_status, rc);
  9120. status = -ENXIO;
  9121. goto out;
  9122. }
  9123. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9124. if (cq->queue_id == 0xFFFF) {
  9125. status = -ENXIO;
  9126. goto out;
  9127. }
  9128. /* link the cq onto the parent eq child list */
  9129. list_add_tail(&cq->list, &eq->child_list);
  9130. /* Set up completion queue's type and subtype */
  9131. cq->type = type;
  9132. cq->subtype = subtype;
  9133. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  9134. cq->host_index = 0;
  9135. cq->hba_index = 0;
  9136. out:
  9137. mempool_free(mbox, phba->mbox_mem_pool);
  9138. return status;
  9139. }
  9140. /**
  9141. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  9142. * @phba: HBA structure that indicates port to create a queue on.
  9143. * @mq: The queue structure to use to create the mailbox queue.
  9144. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  9145. * @cq: The completion queue to associate with this cq.
  9146. *
  9147. * This function provides failback (fb) functionality when the
  9148. * mq_create_ext fails on older FW generations. It's purpose is identical
  9149. * to mq_create_ext otherwise.
  9150. *
  9151. * This routine cannot fail as all attributes were previously accessed and
  9152. * initialized in mq_create_ext.
  9153. **/
  9154. static void
  9155. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9156. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  9157. {
  9158. struct lpfc_mbx_mq_create *mq_create;
  9159. struct lpfc_dmabuf *dmabuf;
  9160. int length;
  9161. length = (sizeof(struct lpfc_mbx_mq_create) -
  9162. sizeof(struct lpfc_sli4_cfg_mhdr));
  9163. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9164. LPFC_MBOX_OPCODE_MQ_CREATE,
  9165. length, LPFC_SLI4_MBX_EMBED);
  9166. mq_create = &mbox->u.mqe.un.mq_create;
  9167. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  9168. mq->page_count);
  9169. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  9170. cq->queue_id);
  9171. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  9172. switch (mq->entry_count) {
  9173. case 16:
  9174. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9175. LPFC_MQ_CNT_16);
  9176. break;
  9177. case 32:
  9178. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9179. LPFC_MQ_CNT_32);
  9180. break;
  9181. case 64:
  9182. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9183. LPFC_MQ_CNT_64);
  9184. break;
  9185. case 128:
  9186. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  9187. LPFC_MQ_CNT_128);
  9188. break;
  9189. }
  9190. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9191. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9192. putPaddrLow(dmabuf->phys);
  9193. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9194. putPaddrHigh(dmabuf->phys);
  9195. }
  9196. }
  9197. /**
  9198. * lpfc_mq_create - Create a mailbox Queue on the HBA
  9199. * @phba: HBA structure that indicates port to create a queue on.
  9200. * @mq: The queue structure to use to create the mailbox queue.
  9201. * @cq: The completion queue to associate with this cq.
  9202. * @subtype: The queue's subtype.
  9203. *
  9204. * This function creates a mailbox queue, as detailed in @mq, on a port,
  9205. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  9206. *
  9207. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  9208. * is used to get the entry count and entry size that are necessary to
  9209. * determine the number of pages to allocate and use for this queue. This
  9210. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  9211. * mailbox queue. This function is asynchronous and will wait for the mailbox
  9212. * command to finish before continuing.
  9213. *
  9214. * On success this function will return a zero. If unable to allocate enough
  9215. * memory this function will return -ENOMEM. If the queue create mailbox command
  9216. * fails this function will return -ENXIO.
  9217. **/
  9218. int32_t
  9219. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  9220. struct lpfc_queue *cq, uint32_t subtype)
  9221. {
  9222. struct lpfc_mbx_mq_create *mq_create;
  9223. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  9224. struct lpfc_dmabuf *dmabuf;
  9225. LPFC_MBOXQ_t *mbox;
  9226. int rc, length, status = 0;
  9227. uint32_t shdr_status, shdr_add_status;
  9228. union lpfc_sli4_cfg_shdr *shdr;
  9229. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9230. if (!phba->sli4_hba.pc_sli4_params.supported)
  9231. hw_page_size = SLI4_PAGE_SIZE;
  9232. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9233. if (!mbox)
  9234. return -ENOMEM;
  9235. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  9236. sizeof(struct lpfc_sli4_cfg_mhdr));
  9237. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9238. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  9239. length, LPFC_SLI4_MBX_EMBED);
  9240. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  9241. bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request,
  9242. mq->page_count);
  9243. bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request,
  9244. 1);
  9245. bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste,
  9246. &mq_create_ext->u.request, 1);
  9247. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  9248. &mq_create_ext->u.request, 1);
  9249. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  9250. cq->queue_id);
  9251. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  9252. switch (mq->entry_count) {
  9253. default:
  9254. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9255. "0362 Unsupported MQ count. (%d)\n",
  9256. mq->entry_count);
  9257. if (mq->entry_count < 16)
  9258. return -EINVAL;
  9259. /* otherwise default to smallest count (drop through) */
  9260. case 16:
  9261. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9262. LPFC_MQ_CNT_16);
  9263. break;
  9264. case 32:
  9265. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9266. LPFC_MQ_CNT_32);
  9267. break;
  9268. case 64:
  9269. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9270. LPFC_MQ_CNT_64);
  9271. break;
  9272. case 128:
  9273. bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context,
  9274. LPFC_MQ_CNT_128);
  9275. break;
  9276. }
  9277. list_for_each_entry(dmabuf, &mq->page_list, list) {
  9278. memset(dmabuf->virt, 0, hw_page_size);
  9279. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  9280. putPaddrLow(dmabuf->phys);
  9281. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  9282. putPaddrHigh(dmabuf->phys);
  9283. }
  9284. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9285. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  9286. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9287. &mq_create_ext->u.response);
  9288. if (rc != MBX_SUCCESS) {
  9289. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  9290. "2795 MQ_CREATE_EXT failed with "
  9291. "status x%x. Failback to MQ_CREATE.\n",
  9292. rc);
  9293. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  9294. mq_create = &mbox->u.mqe.un.mq_create;
  9295. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9296. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  9297. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  9298. &mq_create->u.response);
  9299. }
  9300. /* The IOCTL status is embedded in the mailbox subheader. */
  9301. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9302. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9303. if (shdr_status || shdr_add_status || rc) {
  9304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9305. "2502 MQ_CREATE mailbox failed with "
  9306. "status x%x add_status x%x, mbx status x%x\n",
  9307. shdr_status, shdr_add_status, rc);
  9308. status = -ENXIO;
  9309. goto out;
  9310. }
  9311. if (mq->queue_id == 0xFFFF) {
  9312. status = -ENXIO;
  9313. goto out;
  9314. }
  9315. mq->type = LPFC_MQ;
  9316. mq->subtype = subtype;
  9317. mq->host_index = 0;
  9318. mq->hba_index = 0;
  9319. /* link the mq onto the parent cq child list */
  9320. list_add_tail(&mq->list, &cq->child_list);
  9321. out:
  9322. mempool_free(mbox, phba->mbox_mem_pool);
  9323. return status;
  9324. }
  9325. /**
  9326. * lpfc_wq_create - Create a Work Queue on the HBA
  9327. * @phba: HBA structure that indicates port to create a queue on.
  9328. * @wq: The queue structure to use to create the work queue.
  9329. * @cq: The completion queue to bind this work queue to.
  9330. * @subtype: The subtype of the work queue indicating its functionality.
  9331. *
  9332. * This function creates a work queue, as detailed in @wq, on a port, described
  9333. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  9334. *
  9335. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  9336. * is used to get the entry count and entry size that are necessary to
  9337. * determine the number of pages to allocate and use for this queue. The @cq
  9338. * is used to indicate which completion queue to bind this work queue to. This
  9339. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  9340. * work queue. This function is asynchronous and will wait for the mailbox
  9341. * command to finish before continuing.
  9342. *
  9343. * On success this function will return a zero. If unable to allocate enough
  9344. * memory this function will return -ENOMEM. If the queue create mailbox command
  9345. * fails this function will return -ENXIO.
  9346. **/
  9347. uint32_t
  9348. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  9349. struct lpfc_queue *cq, uint32_t subtype)
  9350. {
  9351. struct lpfc_mbx_wq_create *wq_create;
  9352. struct lpfc_dmabuf *dmabuf;
  9353. LPFC_MBOXQ_t *mbox;
  9354. int rc, length, status = 0;
  9355. uint32_t shdr_status, shdr_add_status;
  9356. union lpfc_sli4_cfg_shdr *shdr;
  9357. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9358. if (!phba->sli4_hba.pc_sli4_params.supported)
  9359. hw_page_size = SLI4_PAGE_SIZE;
  9360. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9361. if (!mbox)
  9362. return -ENOMEM;
  9363. length = (sizeof(struct lpfc_mbx_wq_create) -
  9364. sizeof(struct lpfc_sli4_cfg_mhdr));
  9365. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9366. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  9367. length, LPFC_SLI4_MBX_EMBED);
  9368. wq_create = &mbox->u.mqe.un.wq_create;
  9369. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  9370. wq->page_count);
  9371. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  9372. cq->queue_id);
  9373. list_for_each_entry(dmabuf, &wq->page_list, list) {
  9374. memset(dmabuf->virt, 0, hw_page_size);
  9375. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9376. putPaddrLow(dmabuf->phys);
  9377. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9378. putPaddrHigh(dmabuf->phys);
  9379. }
  9380. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9381. /* The IOCTL status is embedded in the mailbox subheader. */
  9382. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  9383. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9384. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9385. if (shdr_status || shdr_add_status || rc) {
  9386. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9387. "2503 WQ_CREATE mailbox failed with "
  9388. "status x%x add_status x%x, mbx status x%x\n",
  9389. shdr_status, shdr_add_status, rc);
  9390. status = -ENXIO;
  9391. goto out;
  9392. }
  9393. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  9394. if (wq->queue_id == 0xFFFF) {
  9395. status = -ENXIO;
  9396. goto out;
  9397. }
  9398. wq->type = LPFC_WQ;
  9399. wq->subtype = subtype;
  9400. wq->host_index = 0;
  9401. wq->hba_index = 0;
  9402. /* link the wq onto the parent cq child list */
  9403. list_add_tail(&wq->list, &cq->child_list);
  9404. out:
  9405. mempool_free(mbox, phba->mbox_mem_pool);
  9406. return status;
  9407. }
  9408. /**
  9409. * lpfc_rq_create - Create a Receive Queue on the HBA
  9410. * @phba: HBA structure that indicates port to create a queue on.
  9411. * @hrq: The queue structure to use to create the header receive queue.
  9412. * @drq: The queue structure to use to create the data receive queue.
  9413. * @cq: The completion queue to bind this work queue to.
  9414. *
  9415. * This function creates a receive buffer queue pair , as detailed in @hrq and
  9416. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  9417. * to the HBA.
  9418. *
  9419. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  9420. * struct is used to get the entry count that is necessary to determine the
  9421. * number of pages to use for this queue. The @cq is used to indicate which
  9422. * completion queue to bind received buffers that are posted to these queues to.
  9423. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  9424. * receive queue pair. This function is asynchronous and will wait for the
  9425. * mailbox command to finish before continuing.
  9426. *
  9427. * On success this function will return a zero. If unable to allocate enough
  9428. * memory this function will return -ENOMEM. If the queue create mailbox command
  9429. * fails this function will return -ENXIO.
  9430. **/
  9431. uint32_t
  9432. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9433. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  9434. {
  9435. struct lpfc_mbx_rq_create *rq_create;
  9436. struct lpfc_dmabuf *dmabuf;
  9437. LPFC_MBOXQ_t *mbox;
  9438. int rc, length, status = 0;
  9439. uint32_t shdr_status, shdr_add_status;
  9440. union lpfc_sli4_cfg_shdr *shdr;
  9441. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  9442. if (!phba->sli4_hba.pc_sli4_params.supported)
  9443. hw_page_size = SLI4_PAGE_SIZE;
  9444. if (hrq->entry_count != drq->entry_count)
  9445. return -EINVAL;
  9446. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9447. if (!mbox)
  9448. return -ENOMEM;
  9449. length = (sizeof(struct lpfc_mbx_rq_create) -
  9450. sizeof(struct lpfc_sli4_cfg_mhdr));
  9451. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9452. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9453. length, LPFC_SLI4_MBX_EMBED);
  9454. rq_create = &mbox->u.mqe.un.rq_create;
  9455. switch (hrq->entry_count) {
  9456. default:
  9457. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9458. "2535 Unsupported RQ count. (%d)\n",
  9459. hrq->entry_count);
  9460. if (hrq->entry_count < 512)
  9461. return -EINVAL;
  9462. /* otherwise default to smallest count (drop through) */
  9463. case 512:
  9464. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9465. LPFC_RQ_RING_SIZE_512);
  9466. break;
  9467. case 1024:
  9468. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9469. LPFC_RQ_RING_SIZE_1024);
  9470. break;
  9471. case 2048:
  9472. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9473. LPFC_RQ_RING_SIZE_2048);
  9474. break;
  9475. case 4096:
  9476. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9477. LPFC_RQ_RING_SIZE_4096);
  9478. break;
  9479. }
  9480. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9481. cq->queue_id);
  9482. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9483. hrq->page_count);
  9484. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9485. LPFC_HDR_BUF_SIZE);
  9486. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  9487. memset(dmabuf->virt, 0, hw_page_size);
  9488. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9489. putPaddrLow(dmabuf->phys);
  9490. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9491. putPaddrHigh(dmabuf->phys);
  9492. }
  9493. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9494. /* The IOCTL status is embedded in the mailbox subheader. */
  9495. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9496. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9497. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9498. if (shdr_status || shdr_add_status || rc) {
  9499. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9500. "2504 RQ_CREATE mailbox failed with "
  9501. "status x%x add_status x%x, mbx status x%x\n",
  9502. shdr_status, shdr_add_status, rc);
  9503. status = -ENXIO;
  9504. goto out;
  9505. }
  9506. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9507. if (hrq->queue_id == 0xFFFF) {
  9508. status = -ENXIO;
  9509. goto out;
  9510. }
  9511. hrq->type = LPFC_HRQ;
  9512. hrq->subtype = subtype;
  9513. hrq->host_index = 0;
  9514. hrq->hba_index = 0;
  9515. /* now create the data queue */
  9516. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9517. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  9518. length, LPFC_SLI4_MBX_EMBED);
  9519. switch (drq->entry_count) {
  9520. default:
  9521. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9522. "2536 Unsupported RQ count. (%d)\n",
  9523. drq->entry_count);
  9524. if (drq->entry_count < 512)
  9525. return -EINVAL;
  9526. /* otherwise default to smallest count (drop through) */
  9527. case 512:
  9528. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9529. LPFC_RQ_RING_SIZE_512);
  9530. break;
  9531. case 1024:
  9532. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9533. LPFC_RQ_RING_SIZE_1024);
  9534. break;
  9535. case 2048:
  9536. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9537. LPFC_RQ_RING_SIZE_2048);
  9538. break;
  9539. case 4096:
  9540. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  9541. LPFC_RQ_RING_SIZE_4096);
  9542. break;
  9543. }
  9544. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  9545. cq->queue_id);
  9546. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  9547. drq->page_count);
  9548. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  9549. LPFC_DATA_BUF_SIZE);
  9550. list_for_each_entry(dmabuf, &drq->page_list, list) {
  9551. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  9552. putPaddrLow(dmabuf->phys);
  9553. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  9554. putPaddrHigh(dmabuf->phys);
  9555. }
  9556. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9557. /* The IOCTL status is embedded in the mailbox subheader. */
  9558. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  9559. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9560. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9561. if (shdr_status || shdr_add_status || rc) {
  9562. status = -ENXIO;
  9563. goto out;
  9564. }
  9565. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  9566. if (drq->queue_id == 0xFFFF) {
  9567. status = -ENXIO;
  9568. goto out;
  9569. }
  9570. drq->type = LPFC_DRQ;
  9571. drq->subtype = subtype;
  9572. drq->host_index = 0;
  9573. drq->hba_index = 0;
  9574. /* link the header and data RQs onto the parent cq child list */
  9575. list_add_tail(&hrq->list, &cq->child_list);
  9576. list_add_tail(&drq->list, &cq->child_list);
  9577. out:
  9578. mempool_free(mbox, phba->mbox_mem_pool);
  9579. return status;
  9580. }
  9581. /**
  9582. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  9583. * @eq: The queue structure associated with the queue to destroy.
  9584. *
  9585. * This function destroys a queue, as detailed in @eq by sending an mailbox
  9586. * command, specific to the type of queue, to the HBA.
  9587. *
  9588. * The @eq struct is used to get the queue ID of the queue to destroy.
  9589. *
  9590. * On success this function will return a zero. If the queue destroy mailbox
  9591. * command fails this function will return -ENXIO.
  9592. **/
  9593. uint32_t
  9594. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  9595. {
  9596. LPFC_MBOXQ_t *mbox;
  9597. int rc, length, status = 0;
  9598. uint32_t shdr_status, shdr_add_status;
  9599. union lpfc_sli4_cfg_shdr *shdr;
  9600. if (!eq)
  9601. return -ENODEV;
  9602. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  9603. if (!mbox)
  9604. return -ENOMEM;
  9605. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  9606. sizeof(struct lpfc_sli4_cfg_mhdr));
  9607. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9608. LPFC_MBOX_OPCODE_EQ_DESTROY,
  9609. length, LPFC_SLI4_MBX_EMBED);
  9610. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  9611. eq->queue_id);
  9612. mbox->vport = eq->phba->pport;
  9613. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9614. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  9615. /* The IOCTL status is embedded in the mailbox subheader. */
  9616. shdr = (union lpfc_sli4_cfg_shdr *)
  9617. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  9618. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9619. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9620. if (shdr_status || shdr_add_status || rc) {
  9621. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9622. "2505 EQ_DESTROY mailbox failed with "
  9623. "status x%x add_status x%x, mbx status x%x\n",
  9624. shdr_status, shdr_add_status, rc);
  9625. status = -ENXIO;
  9626. }
  9627. /* Remove eq from any list */
  9628. list_del_init(&eq->list);
  9629. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9630. return status;
  9631. }
  9632. /**
  9633. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9634. * @cq: The queue structure associated with the queue to destroy.
  9635. *
  9636. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9637. * command, specific to the type of queue, to the HBA.
  9638. *
  9639. * The @cq struct is used to get the queue ID of the queue to destroy.
  9640. *
  9641. * On success this function will return a zero. If the queue destroy mailbox
  9642. * command fails this function will return -ENXIO.
  9643. **/
  9644. uint32_t
  9645. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9646. {
  9647. LPFC_MBOXQ_t *mbox;
  9648. int rc, length, status = 0;
  9649. uint32_t shdr_status, shdr_add_status;
  9650. union lpfc_sli4_cfg_shdr *shdr;
  9651. if (!cq)
  9652. return -ENODEV;
  9653. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9654. if (!mbox)
  9655. return -ENOMEM;
  9656. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9657. sizeof(struct lpfc_sli4_cfg_mhdr));
  9658. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9659. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9660. length, LPFC_SLI4_MBX_EMBED);
  9661. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9662. cq->queue_id);
  9663. mbox->vport = cq->phba->pport;
  9664. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9665. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9666. /* The IOCTL status is embedded in the mailbox subheader. */
  9667. shdr = (union lpfc_sli4_cfg_shdr *)
  9668. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9669. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9670. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9671. if (shdr_status || shdr_add_status || rc) {
  9672. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9673. "2506 CQ_DESTROY mailbox failed with "
  9674. "status x%x add_status x%x, mbx status x%x\n",
  9675. shdr_status, shdr_add_status, rc);
  9676. status = -ENXIO;
  9677. }
  9678. /* Remove cq from any list */
  9679. list_del_init(&cq->list);
  9680. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9681. return status;
  9682. }
  9683. /**
  9684. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9685. * @qm: The queue structure associated with the queue to destroy.
  9686. *
  9687. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9688. * command, specific to the type of queue, to the HBA.
  9689. *
  9690. * The @mq struct is used to get the queue ID of the queue to destroy.
  9691. *
  9692. * On success this function will return a zero. If the queue destroy mailbox
  9693. * command fails this function will return -ENXIO.
  9694. **/
  9695. uint32_t
  9696. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9697. {
  9698. LPFC_MBOXQ_t *mbox;
  9699. int rc, length, status = 0;
  9700. uint32_t shdr_status, shdr_add_status;
  9701. union lpfc_sli4_cfg_shdr *shdr;
  9702. if (!mq)
  9703. return -ENODEV;
  9704. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9705. if (!mbox)
  9706. return -ENOMEM;
  9707. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9708. sizeof(struct lpfc_sli4_cfg_mhdr));
  9709. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9710. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9711. length, LPFC_SLI4_MBX_EMBED);
  9712. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9713. mq->queue_id);
  9714. mbox->vport = mq->phba->pport;
  9715. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9716. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9717. /* The IOCTL status is embedded in the mailbox subheader. */
  9718. shdr = (union lpfc_sli4_cfg_shdr *)
  9719. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9720. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9721. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9722. if (shdr_status || shdr_add_status || rc) {
  9723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9724. "2507 MQ_DESTROY mailbox failed with "
  9725. "status x%x add_status x%x, mbx status x%x\n",
  9726. shdr_status, shdr_add_status, rc);
  9727. status = -ENXIO;
  9728. }
  9729. /* Remove mq from any list */
  9730. list_del_init(&mq->list);
  9731. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9732. return status;
  9733. }
  9734. /**
  9735. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9736. * @wq: The queue structure associated with the queue to destroy.
  9737. *
  9738. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9739. * command, specific to the type of queue, to the HBA.
  9740. *
  9741. * The @wq struct is used to get the queue ID of the queue to destroy.
  9742. *
  9743. * On success this function will return a zero. If the queue destroy mailbox
  9744. * command fails this function will return -ENXIO.
  9745. **/
  9746. uint32_t
  9747. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9748. {
  9749. LPFC_MBOXQ_t *mbox;
  9750. int rc, length, status = 0;
  9751. uint32_t shdr_status, shdr_add_status;
  9752. union lpfc_sli4_cfg_shdr *shdr;
  9753. if (!wq)
  9754. return -ENODEV;
  9755. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9756. if (!mbox)
  9757. return -ENOMEM;
  9758. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9759. sizeof(struct lpfc_sli4_cfg_mhdr));
  9760. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9761. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9762. length, LPFC_SLI4_MBX_EMBED);
  9763. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9764. wq->queue_id);
  9765. mbox->vport = wq->phba->pport;
  9766. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9767. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9768. shdr = (union lpfc_sli4_cfg_shdr *)
  9769. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9770. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9771. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9772. if (shdr_status || shdr_add_status || rc) {
  9773. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9774. "2508 WQ_DESTROY mailbox failed with "
  9775. "status x%x add_status x%x, mbx status x%x\n",
  9776. shdr_status, shdr_add_status, rc);
  9777. status = -ENXIO;
  9778. }
  9779. /* Remove wq from any list */
  9780. list_del_init(&wq->list);
  9781. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9782. return status;
  9783. }
  9784. /**
  9785. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9786. * @rq: The queue structure associated with the queue to destroy.
  9787. *
  9788. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9789. * command, specific to the type of queue, to the HBA.
  9790. *
  9791. * The @rq struct is used to get the queue ID of the queue to destroy.
  9792. *
  9793. * On success this function will return a zero. If the queue destroy mailbox
  9794. * command fails this function will return -ENXIO.
  9795. **/
  9796. uint32_t
  9797. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9798. struct lpfc_queue *drq)
  9799. {
  9800. LPFC_MBOXQ_t *mbox;
  9801. int rc, length, status = 0;
  9802. uint32_t shdr_status, shdr_add_status;
  9803. union lpfc_sli4_cfg_shdr *shdr;
  9804. if (!hrq || !drq)
  9805. return -ENODEV;
  9806. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9807. if (!mbox)
  9808. return -ENOMEM;
  9809. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9810. sizeof(struct mbox_header));
  9811. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9812. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9813. length, LPFC_SLI4_MBX_EMBED);
  9814. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9815. hrq->queue_id);
  9816. mbox->vport = hrq->phba->pport;
  9817. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9818. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9819. /* The IOCTL status is embedded in the mailbox subheader. */
  9820. shdr = (union lpfc_sli4_cfg_shdr *)
  9821. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9822. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9823. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9824. if (shdr_status || shdr_add_status || rc) {
  9825. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9826. "2509 RQ_DESTROY mailbox failed with "
  9827. "status x%x add_status x%x, mbx status x%x\n",
  9828. shdr_status, shdr_add_status, rc);
  9829. if (rc != MBX_TIMEOUT)
  9830. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9831. return -ENXIO;
  9832. }
  9833. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9834. drq->queue_id);
  9835. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9836. shdr = (union lpfc_sli4_cfg_shdr *)
  9837. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9838. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9839. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9840. if (shdr_status || shdr_add_status || rc) {
  9841. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9842. "2510 RQ_DESTROY mailbox failed with "
  9843. "status x%x add_status x%x, mbx status x%x\n",
  9844. shdr_status, shdr_add_status, rc);
  9845. status = -ENXIO;
  9846. }
  9847. list_del_init(&hrq->list);
  9848. list_del_init(&drq->list);
  9849. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9850. return status;
  9851. }
  9852. /**
  9853. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9854. * @phba: The virtual port for which this call being executed.
  9855. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9856. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9857. * @xritag: the xritag that ties this io to the SGL pages.
  9858. *
  9859. * This routine will post the sgl pages for the IO that has the xritag
  9860. * that is in the iocbq structure. The xritag is assigned during iocbq
  9861. * creation and persists for as long as the driver is loaded.
  9862. * if the caller has fewer than 256 scatter gather segments to map then
  9863. * pdma_phys_addr1 should be 0.
  9864. * If the caller needs to map more than 256 scatter gather segment then
  9865. * pdma_phys_addr1 should be a valid physical address.
  9866. * physical address for SGLs must be 64 byte aligned.
  9867. * If you are going to map 2 SGL's then the first one must have 256 entries
  9868. * the second sgl can have between 1 and 256 entries.
  9869. *
  9870. * Return codes:
  9871. * 0 - Success
  9872. * -ENXIO, -ENOMEM - Failure
  9873. **/
  9874. int
  9875. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9876. dma_addr_t pdma_phys_addr0,
  9877. dma_addr_t pdma_phys_addr1,
  9878. uint16_t xritag)
  9879. {
  9880. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9881. LPFC_MBOXQ_t *mbox;
  9882. int rc;
  9883. uint32_t shdr_status, shdr_add_status;
  9884. union lpfc_sli4_cfg_shdr *shdr;
  9885. if (xritag == NO_XRI) {
  9886. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9887. "0364 Invalid param:\n");
  9888. return -EINVAL;
  9889. }
  9890. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9891. if (!mbox)
  9892. return -ENOMEM;
  9893. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9894. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9895. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9896. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9897. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9898. &mbox->u.mqe.un.post_sgl_pages;
  9899. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9900. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9901. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9902. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9903. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9904. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9905. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9906. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9907. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9908. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9909. if (!phba->sli4_hba.intr_enable)
  9910. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9911. else
  9912. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9913. /* The IOCTL status is embedded in the mailbox subheader. */
  9914. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9915. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9916. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9917. if (rc != MBX_TIMEOUT)
  9918. mempool_free(mbox, phba->mbox_mem_pool);
  9919. if (shdr_status || shdr_add_status || rc) {
  9920. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9921. "2511 POST_SGL mailbox failed with "
  9922. "status x%x add_status x%x, mbx status x%x\n",
  9923. shdr_status, shdr_add_status, rc);
  9924. rc = -ENXIO;
  9925. }
  9926. return 0;
  9927. }
  9928. /**
  9929. * lpfc_sli4_next_xritag - Get an xritag for the io
  9930. * @phba: Pointer to HBA context object.
  9931. *
  9932. * This function gets an xritag for the iocb. If there is no unused xritag
  9933. * it will return 0xffff.
  9934. * The function returns the allocated xritag if successful, else returns zero.
  9935. * Zero is not a valid xritag.
  9936. * The caller is not required to hold any lock.
  9937. **/
  9938. uint16_t
  9939. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9940. {
  9941. uint16_t xritag;
  9942. spin_lock_irq(&phba->hbalock);
  9943. xritag = phba->sli4_hba.next_xri;
  9944. if ((xritag != (uint16_t) -1) && xritag <
  9945. (phba->sli4_hba.max_cfg_param.max_xri
  9946. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9947. phba->sli4_hba.next_xri++;
  9948. phba->sli4_hba.max_cfg_param.xri_used++;
  9949. spin_unlock_irq(&phba->hbalock);
  9950. return xritag;
  9951. }
  9952. spin_unlock_irq(&phba->hbalock);
  9953. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9954. "2004 Failed to allocate XRI.last XRITAG is %d"
  9955. " Max XRI is %d, Used XRI is %d\n",
  9956. phba->sli4_hba.next_xri,
  9957. phba->sli4_hba.max_cfg_param.max_xri,
  9958. phba->sli4_hba.max_cfg_param.xri_used);
  9959. return -1;
  9960. }
  9961. /**
  9962. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9963. * @phba: pointer to lpfc hba data structure.
  9964. *
  9965. * This routine is invoked to post a block of driver's sgl pages to the
  9966. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9967. * is only called when the driver is loading and after all IO has been
  9968. * stopped.
  9969. **/
  9970. int
  9971. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9972. {
  9973. struct lpfc_sglq *sglq_entry;
  9974. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9975. struct sgl_page_pairs *sgl_pg_pairs;
  9976. void *viraddr;
  9977. LPFC_MBOXQ_t *mbox;
  9978. uint32_t reqlen, alloclen, pg_pairs;
  9979. uint32_t mbox_tmo;
  9980. uint16_t xritag_start = 0;
  9981. int els_xri_cnt, rc = 0;
  9982. uint32_t shdr_status, shdr_add_status;
  9983. union lpfc_sli4_cfg_shdr *shdr;
  9984. /* The number of sgls to be posted */
  9985. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9986. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9987. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9988. if (reqlen > SLI4_PAGE_SIZE) {
  9989. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9990. "2559 Block sgl registration required DMA "
  9991. "size (%d) great than a page\n", reqlen);
  9992. return -ENOMEM;
  9993. }
  9994. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9995. if (!mbox) {
  9996. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9997. "2560 Failed to allocate mbox cmd memory\n");
  9998. return -ENOMEM;
  9999. }
  10000. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10001. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10002. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10003. LPFC_SLI4_MBX_NEMBED);
  10004. if (alloclen < reqlen) {
  10005. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10006. "0285 Allocated DMA memory size (%d) is "
  10007. "less than the requested DMA memory "
  10008. "size (%d)\n", alloclen, reqlen);
  10009. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10010. return -ENOMEM;
  10011. }
  10012. /* Get the first SGE entry from the non-embedded DMA memory */
  10013. viraddr = mbox->sge_array->addr[0];
  10014. /* Set up the SGL pages in the non-embedded DMA pages */
  10015. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10016. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10017. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  10018. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  10019. /* Set up the sge entry */
  10020. sgl_pg_pairs->sgl_pg0_addr_lo =
  10021. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  10022. sgl_pg_pairs->sgl_pg0_addr_hi =
  10023. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  10024. sgl_pg_pairs->sgl_pg1_addr_lo =
  10025. cpu_to_le32(putPaddrLow(0));
  10026. sgl_pg_pairs->sgl_pg1_addr_hi =
  10027. cpu_to_le32(putPaddrHigh(0));
  10028. /* Keep the first xritag on the list */
  10029. if (pg_pairs == 0)
  10030. xritag_start = sglq_entry->sli4_xritag;
  10031. sgl_pg_pairs++;
  10032. }
  10033. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10034. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  10035. /* Perform endian conversion if necessary */
  10036. sgl->word0 = cpu_to_le32(sgl->word0);
  10037. if (!phba->sli4_hba.intr_enable)
  10038. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10039. else {
  10040. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10041. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10042. }
  10043. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10044. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10045. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10046. if (rc != MBX_TIMEOUT)
  10047. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10048. if (shdr_status || shdr_add_status || rc) {
  10049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10050. "2513 POST_SGL_BLOCK mailbox command failed "
  10051. "status x%x add_status x%x mbx status x%x\n",
  10052. shdr_status, shdr_add_status, rc);
  10053. rc = -ENXIO;
  10054. }
  10055. return rc;
  10056. }
  10057. /**
  10058. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  10059. * @phba: pointer to lpfc hba data structure.
  10060. * @sblist: pointer to scsi buffer list.
  10061. * @count: number of scsi buffers on the list.
  10062. *
  10063. * This routine is invoked to post a block of @count scsi sgl pages from a
  10064. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  10065. * No Lock is held.
  10066. *
  10067. **/
  10068. int
  10069. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  10070. int cnt)
  10071. {
  10072. struct lpfc_scsi_buf *psb;
  10073. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  10074. struct sgl_page_pairs *sgl_pg_pairs;
  10075. void *viraddr;
  10076. LPFC_MBOXQ_t *mbox;
  10077. uint32_t reqlen, alloclen, pg_pairs;
  10078. uint32_t mbox_tmo;
  10079. uint16_t xritag_start = 0;
  10080. int rc = 0;
  10081. uint32_t shdr_status, shdr_add_status;
  10082. dma_addr_t pdma_phys_bpl1;
  10083. union lpfc_sli4_cfg_shdr *shdr;
  10084. /* Calculate the requested length of the dma memory */
  10085. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  10086. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  10087. if (reqlen > SLI4_PAGE_SIZE) {
  10088. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  10089. "0217 Block sgl registration required DMA "
  10090. "size (%d) great than a page\n", reqlen);
  10091. return -ENOMEM;
  10092. }
  10093. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10094. if (!mbox) {
  10095. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10096. "0283 Failed to allocate mbox cmd memory\n");
  10097. return -ENOMEM;
  10098. }
  10099. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10100. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  10101. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  10102. LPFC_SLI4_MBX_NEMBED);
  10103. if (alloclen < reqlen) {
  10104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10105. "2561 Allocated DMA memory size (%d) is "
  10106. "less than the requested DMA memory "
  10107. "size (%d)\n", alloclen, reqlen);
  10108. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10109. return -ENOMEM;
  10110. }
  10111. /* Get the first SGE entry from the non-embedded DMA memory */
  10112. viraddr = mbox->sge_array->addr[0];
  10113. /* Set up the SGL pages in the non-embedded DMA pages */
  10114. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  10115. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  10116. pg_pairs = 0;
  10117. list_for_each_entry(psb, sblist, list) {
  10118. /* Set up the sge entry */
  10119. sgl_pg_pairs->sgl_pg0_addr_lo =
  10120. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  10121. sgl_pg_pairs->sgl_pg0_addr_hi =
  10122. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  10123. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  10124. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  10125. else
  10126. pdma_phys_bpl1 = 0;
  10127. sgl_pg_pairs->sgl_pg1_addr_lo =
  10128. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  10129. sgl_pg_pairs->sgl_pg1_addr_hi =
  10130. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  10131. /* Keep the first xritag on the list */
  10132. if (pg_pairs == 0)
  10133. xritag_start = psb->cur_iocbq.sli4_xritag;
  10134. sgl_pg_pairs++;
  10135. pg_pairs++;
  10136. }
  10137. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  10138. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  10139. /* Perform endian conversion if necessary */
  10140. sgl->word0 = cpu_to_le32(sgl->word0);
  10141. if (!phba->sli4_hba.intr_enable)
  10142. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10143. else {
  10144. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10145. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  10146. }
  10147. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  10148. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10149. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10150. if (rc != MBX_TIMEOUT)
  10151. lpfc_sli4_mbox_cmd_free(phba, mbox);
  10152. if (shdr_status || shdr_add_status || rc) {
  10153. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10154. "2564 POST_SGL_BLOCK mailbox command failed "
  10155. "status x%x add_status x%x mbx status x%x\n",
  10156. shdr_status, shdr_add_status, rc);
  10157. rc = -ENXIO;
  10158. }
  10159. return rc;
  10160. }
  10161. /**
  10162. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  10163. * @phba: pointer to lpfc_hba struct that the frame was received on
  10164. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10165. *
  10166. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  10167. * valid type of frame that the LPFC driver will handle. This function will
  10168. * return a zero if the frame is a valid frame or a non zero value when the
  10169. * frame does not pass the check.
  10170. **/
  10171. static int
  10172. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  10173. {
  10174. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  10175. char *type_names[] = FC_TYPE_NAMES_INIT;
  10176. struct fc_vft_header *fc_vft_hdr;
  10177. switch (fc_hdr->fh_r_ctl) {
  10178. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  10179. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  10180. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  10181. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  10182. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  10183. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  10184. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  10185. case FC_RCTL_DD_CMD_STATUS: /* command status */
  10186. case FC_RCTL_ELS_REQ: /* extended link services request */
  10187. case FC_RCTL_ELS_REP: /* extended link services reply */
  10188. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  10189. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  10190. case FC_RCTL_BA_NOP: /* basic link service NOP */
  10191. case FC_RCTL_BA_ABTS: /* basic link service abort */
  10192. case FC_RCTL_BA_RMC: /* remove connection */
  10193. case FC_RCTL_BA_ACC: /* basic accept */
  10194. case FC_RCTL_BA_RJT: /* basic reject */
  10195. case FC_RCTL_BA_PRMT:
  10196. case FC_RCTL_ACK_1: /* acknowledge_1 */
  10197. case FC_RCTL_ACK_0: /* acknowledge_0 */
  10198. case FC_RCTL_P_RJT: /* port reject */
  10199. case FC_RCTL_F_RJT: /* fabric reject */
  10200. case FC_RCTL_P_BSY: /* port busy */
  10201. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  10202. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  10203. case FC_RCTL_LCR: /* link credit reset */
  10204. case FC_RCTL_END: /* end */
  10205. break;
  10206. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  10207. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10208. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  10209. return lpfc_fc_frame_check(phba, fc_hdr);
  10210. default:
  10211. goto drop;
  10212. }
  10213. switch (fc_hdr->fh_type) {
  10214. case FC_TYPE_BLS:
  10215. case FC_TYPE_ELS:
  10216. case FC_TYPE_FCP:
  10217. case FC_TYPE_CT:
  10218. break;
  10219. case FC_TYPE_IP:
  10220. case FC_TYPE_ILS:
  10221. default:
  10222. goto drop;
  10223. }
  10224. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10225. "2538 Received frame rctl:%s type:%s\n",
  10226. rctl_names[fc_hdr->fh_r_ctl],
  10227. type_names[fc_hdr->fh_type]);
  10228. return 0;
  10229. drop:
  10230. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10231. "2539 Dropped frame rctl:%s type:%s\n",
  10232. rctl_names[fc_hdr->fh_r_ctl],
  10233. type_names[fc_hdr->fh_type]);
  10234. return 1;
  10235. }
  10236. /**
  10237. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  10238. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10239. *
  10240. * This function processes the FC header to retrieve the VFI from the VF
  10241. * header, if one exists. This function will return the VFI if one exists
  10242. * or 0 if no VSAN Header exists.
  10243. **/
  10244. static uint32_t
  10245. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  10246. {
  10247. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  10248. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  10249. return 0;
  10250. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  10251. }
  10252. /**
  10253. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  10254. * @phba: Pointer to the HBA structure to search for the vport on
  10255. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  10256. * @fcfi: The FC Fabric ID that the frame came from
  10257. *
  10258. * This function searches the @phba for a vport that matches the content of the
  10259. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  10260. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  10261. * returns the matching vport pointer or NULL if unable to match frame to a
  10262. * vport.
  10263. **/
  10264. static struct lpfc_vport *
  10265. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  10266. uint16_t fcfi)
  10267. {
  10268. struct lpfc_vport **vports;
  10269. struct lpfc_vport *vport = NULL;
  10270. int i;
  10271. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  10272. fc_hdr->fh_d_id[1] << 8 |
  10273. fc_hdr->fh_d_id[2]);
  10274. vports = lpfc_create_vport_work_array(phba);
  10275. if (vports != NULL)
  10276. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  10277. if (phba->fcf.fcfi == fcfi &&
  10278. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  10279. vports[i]->fc_myDID == did) {
  10280. vport = vports[i];
  10281. break;
  10282. }
  10283. }
  10284. lpfc_destroy_vport_work_array(phba, vports);
  10285. return vport;
  10286. }
  10287. /**
  10288. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  10289. * @vport: The vport to work on.
  10290. *
  10291. * This function updates the receive sequence time stamp for this vport. The
  10292. * receive sequence time stamp indicates the time that the last frame of the
  10293. * the sequence that has been idle for the longest amount of time was received.
  10294. * the driver uses this time stamp to indicate if any received sequences have
  10295. * timed out.
  10296. **/
  10297. void
  10298. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  10299. {
  10300. struct lpfc_dmabuf *h_buf;
  10301. struct hbq_dmabuf *dmabuf = NULL;
  10302. /* get the oldest sequence on the rcv list */
  10303. h_buf = list_get_first(&vport->rcv_buffer_list,
  10304. struct lpfc_dmabuf, list);
  10305. if (!h_buf)
  10306. return;
  10307. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10308. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  10309. }
  10310. /**
  10311. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  10312. * @vport: The vport that the received sequences were sent to.
  10313. *
  10314. * This function cleans up all outstanding received sequences. This is called
  10315. * by the driver when a link event or user action invalidates all the received
  10316. * sequences.
  10317. **/
  10318. void
  10319. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  10320. {
  10321. struct lpfc_dmabuf *h_buf, *hnext;
  10322. struct lpfc_dmabuf *d_buf, *dnext;
  10323. struct hbq_dmabuf *dmabuf = NULL;
  10324. /* start with the oldest sequence on the rcv list */
  10325. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10326. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10327. list_del_init(&dmabuf->hbuf.list);
  10328. list_for_each_entry_safe(d_buf, dnext,
  10329. &dmabuf->dbuf.list, list) {
  10330. list_del_init(&d_buf->list);
  10331. lpfc_in_buf_free(vport->phba, d_buf);
  10332. }
  10333. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10334. }
  10335. }
  10336. /**
  10337. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  10338. * @vport: The vport that the received sequences were sent to.
  10339. *
  10340. * This function determines whether any received sequences have timed out by
  10341. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  10342. * indicates that there is at least one timed out sequence this routine will
  10343. * go through the received sequences one at a time from most inactive to most
  10344. * active to determine which ones need to be cleaned up. Once it has determined
  10345. * that a sequence needs to be cleaned up it will simply free up the resources
  10346. * without sending an abort.
  10347. **/
  10348. void
  10349. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  10350. {
  10351. struct lpfc_dmabuf *h_buf, *hnext;
  10352. struct lpfc_dmabuf *d_buf, *dnext;
  10353. struct hbq_dmabuf *dmabuf = NULL;
  10354. unsigned long timeout;
  10355. int abort_count = 0;
  10356. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10357. vport->rcv_buffer_time_stamp);
  10358. if (list_empty(&vport->rcv_buffer_list) ||
  10359. time_before(jiffies, timeout))
  10360. return;
  10361. /* start with the oldest sequence on the rcv list */
  10362. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  10363. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10364. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  10365. dmabuf->time_stamp);
  10366. if (time_before(jiffies, timeout))
  10367. break;
  10368. abort_count++;
  10369. list_del_init(&dmabuf->hbuf.list);
  10370. list_for_each_entry_safe(d_buf, dnext,
  10371. &dmabuf->dbuf.list, list) {
  10372. list_del_init(&d_buf->list);
  10373. lpfc_in_buf_free(vport->phba, d_buf);
  10374. }
  10375. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  10376. }
  10377. if (abort_count)
  10378. lpfc_update_rcv_time_stamp(vport);
  10379. }
  10380. /**
  10381. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  10382. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  10383. *
  10384. * This function searches through the existing incomplete sequences that have
  10385. * been sent to this @vport. If the frame matches one of the incomplete
  10386. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  10387. * make up that sequence. If no sequence is found that matches this frame then
  10388. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  10389. * This function returns a pointer to the first dmabuf in the sequence list that
  10390. * the frame was linked to.
  10391. **/
  10392. static struct hbq_dmabuf *
  10393. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  10394. {
  10395. struct fc_frame_header *new_hdr;
  10396. struct fc_frame_header *temp_hdr;
  10397. struct lpfc_dmabuf *d_buf;
  10398. struct lpfc_dmabuf *h_buf;
  10399. struct hbq_dmabuf *seq_dmabuf = NULL;
  10400. struct hbq_dmabuf *temp_dmabuf = NULL;
  10401. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10402. dmabuf->time_stamp = jiffies;
  10403. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10404. /* Use the hdr_buf to find the sequence that this frame belongs to */
  10405. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10406. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10407. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10408. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10409. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10410. continue;
  10411. /* found a pending sequence that matches this frame */
  10412. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10413. break;
  10414. }
  10415. if (!seq_dmabuf) {
  10416. /*
  10417. * This indicates first frame received for this sequence.
  10418. * Queue the buffer on the vport's rcv_buffer_list.
  10419. */
  10420. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10421. lpfc_update_rcv_time_stamp(vport);
  10422. return dmabuf;
  10423. }
  10424. temp_hdr = seq_dmabuf->hbuf.virt;
  10425. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  10426. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10427. list_del_init(&seq_dmabuf->hbuf.list);
  10428. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10429. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10430. lpfc_update_rcv_time_stamp(vport);
  10431. return dmabuf;
  10432. }
  10433. /* move this sequence to the tail to indicate a young sequence */
  10434. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  10435. seq_dmabuf->time_stamp = jiffies;
  10436. lpfc_update_rcv_time_stamp(vport);
  10437. if (list_empty(&seq_dmabuf->dbuf.list)) {
  10438. temp_hdr = dmabuf->hbuf.virt;
  10439. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  10440. return seq_dmabuf;
  10441. }
  10442. /* find the correct place in the sequence to insert this frame */
  10443. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  10444. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10445. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  10446. /*
  10447. * If the frame's sequence count is greater than the frame on
  10448. * the list then insert the frame right after this frame
  10449. */
  10450. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  10451. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  10452. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  10453. return seq_dmabuf;
  10454. }
  10455. }
  10456. return NULL;
  10457. }
  10458. /**
  10459. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  10460. * @vport: pointer to a vitural port
  10461. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10462. *
  10463. * This function tries to abort from the partially assembed sequence, described
  10464. * by the information from basic abbort @dmabuf. It checks to see whether such
  10465. * partially assembled sequence held by the driver. If so, it shall free up all
  10466. * the frames from the partially assembled sequence.
  10467. *
  10468. * Return
  10469. * true -- if there is matching partially assembled sequence present and all
  10470. * the frames freed with the sequence;
  10471. * false -- if there is no matching partially assembled sequence present so
  10472. * nothing got aborted in the lower layer driver
  10473. **/
  10474. static bool
  10475. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  10476. struct hbq_dmabuf *dmabuf)
  10477. {
  10478. struct fc_frame_header *new_hdr;
  10479. struct fc_frame_header *temp_hdr;
  10480. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  10481. struct hbq_dmabuf *seq_dmabuf = NULL;
  10482. /* Use the hdr_buf to find the sequence that matches this frame */
  10483. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  10484. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  10485. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10486. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  10487. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  10488. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  10489. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  10490. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  10491. continue;
  10492. /* found a pending sequence that matches this frame */
  10493. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  10494. break;
  10495. }
  10496. /* Free up all the frames from the partially assembled sequence */
  10497. if (seq_dmabuf) {
  10498. list_for_each_entry_safe(d_buf, n_buf,
  10499. &seq_dmabuf->dbuf.list, list) {
  10500. list_del_init(&d_buf->list);
  10501. lpfc_in_buf_free(vport->phba, d_buf);
  10502. }
  10503. return true;
  10504. }
  10505. return false;
  10506. }
  10507. /**
  10508. * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler
  10509. * @phba: Pointer to HBA context object.
  10510. * @cmd_iocbq: pointer to the command iocbq structure.
  10511. * @rsp_iocbq: pointer to the response iocbq structure.
  10512. *
  10513. * This function handles the sequence abort accept iocb command complete
  10514. * event. It properly releases the memory allocated to the sequence abort
  10515. * accept iocb.
  10516. **/
  10517. static void
  10518. lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba,
  10519. struct lpfc_iocbq *cmd_iocbq,
  10520. struct lpfc_iocbq *rsp_iocbq)
  10521. {
  10522. if (cmd_iocbq)
  10523. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  10524. }
  10525. /**
  10526. * lpfc_sli4_seq_abort_acc - Accept sequence abort
  10527. * @phba: Pointer to HBA context object.
  10528. * @fc_hdr: pointer to a FC frame header.
  10529. *
  10530. * This function sends a basic accept to a previous unsol sequence abort
  10531. * event after aborting the sequence handling.
  10532. **/
  10533. static void
  10534. lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba,
  10535. struct fc_frame_header *fc_hdr)
  10536. {
  10537. struct lpfc_iocbq *ctiocb = NULL;
  10538. struct lpfc_nodelist *ndlp;
  10539. uint16_t oxid, rxid;
  10540. uint32_t sid, fctl;
  10541. IOCB_t *icmd;
  10542. if (!lpfc_is_link_up(phba))
  10543. return;
  10544. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10545. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  10546. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  10547. ndlp = lpfc_findnode_did(phba->pport, sid);
  10548. if (!ndlp) {
  10549. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  10550. "1268 Find ndlp returned NULL for oxid:x%x "
  10551. "SID:x%x\n", oxid, sid);
  10552. return;
  10553. }
  10554. /* Allocate buffer for acc iocb */
  10555. ctiocb = lpfc_sli_get_iocbq(phba);
  10556. if (!ctiocb)
  10557. return;
  10558. /* Extract the F_CTL field from FC_HDR */
  10559. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  10560. icmd = &ctiocb->iocb;
  10561. icmd->un.xseq64.bdl.bdeSize = 0;
  10562. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  10563. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  10564. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  10565. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  10566. /* Fill in the rest of iocb fields */
  10567. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  10568. icmd->ulpBdeCount = 0;
  10569. icmd->ulpLe = 1;
  10570. icmd->ulpClass = CLASS3;
  10571. icmd->ulpContext = ndlp->nlp_rpi;
  10572. ctiocb->iocb_cmpl = NULL;
  10573. ctiocb->vport = phba->pport;
  10574. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl;
  10575. if (fctl & FC_FC_EX_CTX) {
  10576. /* ABTS sent by responder to CT exchange, construction
  10577. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  10578. * field and RX_ID from ABTS for RX_ID field.
  10579. */
  10580. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP);
  10581. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid);
  10582. ctiocb->sli4_xritag = oxid;
  10583. } else {
  10584. /* ABTS sent by initiator to CT exchange, construction
  10585. * of BA_ACC will need to allocate a new XRI as for the
  10586. * XRI_TAG and RX_ID fields.
  10587. */
  10588. bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT);
  10589. bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI);
  10590. ctiocb->sli4_xritag = NO_XRI;
  10591. }
  10592. bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid);
  10593. /* Xmit CT abts accept on exchange <xid> */
  10594. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  10595. "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n",
  10596. CMD_XMIT_BLS_RSP64_CX, phba->link_state);
  10597. lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  10598. }
  10599. /**
  10600. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  10601. * @vport: Pointer to the vport on which this sequence was received
  10602. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10603. *
  10604. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  10605. * receive sequence is only partially assembed by the driver, it shall abort
  10606. * the partially assembled frames for the sequence. Otherwise, if the
  10607. * unsolicited receive sequence has been completely assembled and passed to
  10608. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  10609. * unsolicited sequence has been aborted. After that, it will issue a basic
  10610. * accept to accept the abort.
  10611. **/
  10612. void
  10613. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  10614. struct hbq_dmabuf *dmabuf)
  10615. {
  10616. struct lpfc_hba *phba = vport->phba;
  10617. struct fc_frame_header fc_hdr;
  10618. uint32_t fctl;
  10619. bool abts_par;
  10620. /* Make a copy of fc_hdr before the dmabuf being released */
  10621. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  10622. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  10623. if (fctl & FC_FC_EX_CTX) {
  10624. /*
  10625. * ABTS sent by responder to exchange, just free the buffer
  10626. */
  10627. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10628. } else {
  10629. /*
  10630. * ABTS sent by initiator to exchange, need to do cleanup
  10631. */
  10632. /* Try to abort partially assembled seq */
  10633. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  10634. /* Send abort to ULP if partially seq abort failed */
  10635. if (abts_par == false)
  10636. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  10637. else
  10638. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10639. }
  10640. /* Send basic accept (BA_ACC) to the abort requester */
  10641. lpfc_sli4_seq_abort_acc(phba, &fc_hdr);
  10642. }
  10643. /**
  10644. * lpfc_seq_complete - Indicates if a sequence is complete
  10645. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10646. *
  10647. * This function checks the sequence, starting with the frame described by
  10648. * @dmabuf, to see if all the frames associated with this sequence are present.
  10649. * the frames associated with this sequence are linked to the @dmabuf using the
  10650. * dbuf list. This function looks for two major things. 1) That the first frame
  10651. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  10652. * set. 3) That there are no holes in the sequence count. The function will
  10653. * return 1 when the sequence is complete, otherwise it will return 0.
  10654. **/
  10655. static int
  10656. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  10657. {
  10658. struct fc_frame_header *hdr;
  10659. struct lpfc_dmabuf *d_buf;
  10660. struct hbq_dmabuf *seq_dmabuf;
  10661. uint32_t fctl;
  10662. int seq_count = 0;
  10663. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10664. /* make sure first fame of sequence has a sequence count of zero */
  10665. if (hdr->fh_seq_cnt != seq_count)
  10666. return 0;
  10667. fctl = (hdr->fh_f_ctl[0] << 16 |
  10668. hdr->fh_f_ctl[1] << 8 |
  10669. hdr->fh_f_ctl[2]);
  10670. /* If last frame of sequence we can return success. */
  10671. if (fctl & FC_FC_END_SEQ)
  10672. return 1;
  10673. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  10674. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  10675. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10676. /* If there is a hole in the sequence count then fail. */
  10677. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  10678. return 0;
  10679. fctl = (hdr->fh_f_ctl[0] << 16 |
  10680. hdr->fh_f_ctl[1] << 8 |
  10681. hdr->fh_f_ctl[2]);
  10682. /* If last frame of sequence we can return success. */
  10683. if (fctl & FC_FC_END_SEQ)
  10684. return 1;
  10685. }
  10686. return 0;
  10687. }
  10688. /**
  10689. * lpfc_prep_seq - Prep sequence for ULP processing
  10690. * @vport: Pointer to the vport on which this sequence was received
  10691. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  10692. *
  10693. * This function takes a sequence, described by a list of frames, and creates
  10694. * a list of iocbq structures to describe the sequence. This iocbq list will be
  10695. * used to issue to the generic unsolicited sequence handler. This routine
  10696. * returns a pointer to the first iocbq in the list. If the function is unable
  10697. * to allocate an iocbq then it throw out the received frames that were not
  10698. * able to be described and return a pointer to the first iocbq. If unable to
  10699. * allocate any iocbqs (including the first) this function will return NULL.
  10700. **/
  10701. static struct lpfc_iocbq *
  10702. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  10703. {
  10704. struct lpfc_dmabuf *d_buf, *n_buf;
  10705. struct lpfc_iocbq *first_iocbq, *iocbq;
  10706. struct fc_frame_header *fc_hdr;
  10707. uint32_t sid;
  10708. struct ulp_bde64 *pbde;
  10709. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10710. /* remove from receive buffer list */
  10711. list_del_init(&seq_dmabuf->hbuf.list);
  10712. lpfc_update_rcv_time_stamp(vport);
  10713. /* get the Remote Port's SID */
  10714. sid = sli4_sid_from_fc_hdr(fc_hdr);
  10715. /* Get an iocbq struct to fill in. */
  10716. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  10717. if (first_iocbq) {
  10718. /* Initialize the first IOCB. */
  10719. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  10720. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  10721. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  10722. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  10723. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  10724. vport->vpi + vport->phba->vpi_base;
  10725. /* put the first buffer into the first IOCBq */
  10726. first_iocbq->context2 = &seq_dmabuf->dbuf;
  10727. first_iocbq->context3 = NULL;
  10728. first_iocbq->iocb.ulpBdeCount = 1;
  10729. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10730. LPFC_DATA_BUF_SIZE;
  10731. first_iocbq->iocb.un.rcvels.remoteID = sid;
  10732. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10733. bf_get(lpfc_rcqe_length,
  10734. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10735. }
  10736. iocbq = first_iocbq;
  10737. /*
  10738. * Each IOCBq can have two Buffers assigned, so go through the list
  10739. * of buffers for this sequence and save two buffers in each IOCBq
  10740. */
  10741. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  10742. if (!iocbq) {
  10743. lpfc_in_buf_free(vport->phba, d_buf);
  10744. continue;
  10745. }
  10746. if (!iocbq->context3) {
  10747. iocbq->context3 = d_buf;
  10748. iocbq->iocb.ulpBdeCount++;
  10749. pbde = (struct ulp_bde64 *)
  10750. &iocbq->iocb.unsli3.sli3Words[4];
  10751. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  10752. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10753. bf_get(lpfc_rcqe_length,
  10754. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10755. } else {
  10756. iocbq = lpfc_sli_get_iocbq(vport->phba);
  10757. if (!iocbq) {
  10758. if (first_iocbq) {
  10759. first_iocbq->iocb.ulpStatus =
  10760. IOSTAT_FCP_RSP_ERROR;
  10761. first_iocbq->iocb.un.ulpWord[4] =
  10762. IOERR_NO_RESOURCES;
  10763. }
  10764. lpfc_in_buf_free(vport->phba, d_buf);
  10765. continue;
  10766. }
  10767. iocbq->context2 = d_buf;
  10768. iocbq->context3 = NULL;
  10769. iocbq->iocb.ulpBdeCount = 1;
  10770. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  10771. LPFC_DATA_BUF_SIZE;
  10772. first_iocbq->iocb.unsli3.rcvsli3.acc_len +=
  10773. bf_get(lpfc_rcqe_length,
  10774. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  10775. iocbq->iocb.un.rcvels.remoteID = sid;
  10776. list_add_tail(&iocbq->list, &first_iocbq->list);
  10777. }
  10778. }
  10779. return first_iocbq;
  10780. }
  10781. static void
  10782. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  10783. struct hbq_dmabuf *seq_dmabuf)
  10784. {
  10785. struct fc_frame_header *fc_hdr;
  10786. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  10787. struct lpfc_hba *phba = vport->phba;
  10788. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  10789. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  10790. if (!iocbq) {
  10791. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10792. "2707 Ring %d handler: Failed to allocate "
  10793. "iocb Rctl x%x Type x%x received\n",
  10794. LPFC_ELS_RING,
  10795. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10796. return;
  10797. }
  10798. if (!lpfc_complete_unsol_iocb(phba,
  10799. &phba->sli.ring[LPFC_ELS_RING],
  10800. iocbq, fc_hdr->fh_r_ctl,
  10801. fc_hdr->fh_type))
  10802. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10803. "2540 Ring %d handler: unexpected Rctl "
  10804. "x%x Type x%x received\n",
  10805. LPFC_ELS_RING,
  10806. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  10807. /* Free iocb created in lpfc_prep_seq */
  10808. list_for_each_entry_safe(curr_iocb, next_iocb,
  10809. &iocbq->list, list) {
  10810. list_del_init(&curr_iocb->list);
  10811. lpfc_sli_release_iocbq(phba, curr_iocb);
  10812. }
  10813. lpfc_sli_release_iocbq(phba, iocbq);
  10814. }
  10815. /**
  10816. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  10817. * @phba: Pointer to HBA context object.
  10818. *
  10819. * This function is called with no lock held. This function processes all
  10820. * the received buffers and gives it to upper layers when a received buffer
  10821. * indicates that it is the final frame in the sequence. The interrupt
  10822. * service routine processes received buffers at interrupt contexts and adds
  10823. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  10824. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  10825. * appropriate receive function when the final frame in a sequence is received.
  10826. **/
  10827. void
  10828. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  10829. struct hbq_dmabuf *dmabuf)
  10830. {
  10831. struct hbq_dmabuf *seq_dmabuf;
  10832. struct fc_frame_header *fc_hdr;
  10833. struct lpfc_vport *vport;
  10834. uint32_t fcfi;
  10835. /* Process each received buffer */
  10836. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  10837. /* check to see if this a valid type of frame */
  10838. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  10839. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10840. return;
  10841. }
  10842. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl);
  10843. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  10844. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  10845. /* throw out the frame */
  10846. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10847. return;
  10848. }
  10849. /* Handle the basic abort sequence (BA_ABTS) event */
  10850. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  10851. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  10852. return;
  10853. }
  10854. /* Link this frame */
  10855. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  10856. if (!seq_dmabuf) {
  10857. /* unable to add frame to vport - throw it out */
  10858. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  10859. return;
  10860. }
  10861. /* If not last frame in sequence continue processing frames. */
  10862. if (!lpfc_seq_complete(seq_dmabuf))
  10863. return;
  10864. /* Send the complete sequence to the upper layer protocol */
  10865. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  10866. }
  10867. /**
  10868. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  10869. * @phba: pointer to lpfc hba data structure.
  10870. *
  10871. * This routine is invoked to post rpi header templates to the
  10872. * HBA consistent with the SLI-4 interface spec. This routine
  10873. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10874. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10875. *
  10876. * This routine does not require any locks. It's usage is expected
  10877. * to be driver load or reset recovery when the driver is
  10878. * sequential.
  10879. *
  10880. * Return codes
  10881. * 0 - successful
  10882. * -EIO - The mailbox failed to complete successfully.
  10883. * When this error occurs, the driver is not guaranteed
  10884. * to have any rpi regions posted to the device and
  10885. * must either attempt to repost the regions or take a
  10886. * fatal error.
  10887. **/
  10888. int
  10889. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10890. {
  10891. struct lpfc_rpi_hdr *rpi_page;
  10892. uint32_t rc = 0;
  10893. /* Post all rpi memory regions to the port. */
  10894. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10895. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10896. if (rc != MBX_SUCCESS) {
  10897. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10898. "2008 Error %d posting all rpi "
  10899. "headers\n", rc);
  10900. rc = -EIO;
  10901. break;
  10902. }
  10903. }
  10904. return rc;
  10905. }
  10906. /**
  10907. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10908. * @phba: pointer to lpfc hba data structure.
  10909. * @rpi_page: pointer to the rpi memory region.
  10910. *
  10911. * This routine is invoked to post a single rpi header to the
  10912. * HBA consistent with the SLI-4 interface spec. This memory region
  10913. * maps up to 64 rpi context regions.
  10914. *
  10915. * Return codes
  10916. * 0 - successful
  10917. * -ENOMEM - No available memory
  10918. * -EIO - The mailbox failed to complete successfully.
  10919. **/
  10920. int
  10921. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10922. {
  10923. LPFC_MBOXQ_t *mboxq;
  10924. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10925. uint32_t rc = 0;
  10926. uint32_t mbox_tmo;
  10927. uint32_t shdr_status, shdr_add_status;
  10928. union lpfc_sli4_cfg_shdr *shdr;
  10929. /* The port is notified of the header region via a mailbox command. */
  10930. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10931. if (!mboxq) {
  10932. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10933. "2001 Unable to allocate memory for issuing "
  10934. "SLI_CONFIG_SPECIAL mailbox command\n");
  10935. return -ENOMEM;
  10936. }
  10937. /* Post all rpi memory regions to the port. */
  10938. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10939. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10940. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10941. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10942. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10943. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10944. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10945. hdr_tmpl, rpi_page->page_count);
  10946. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10947. rpi_page->start_rpi);
  10948. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10949. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10950. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10951. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10952. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10953. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10954. if (rc != MBX_TIMEOUT)
  10955. mempool_free(mboxq, phba->mbox_mem_pool);
  10956. if (shdr_status || shdr_add_status || rc) {
  10957. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10958. "2514 POST_RPI_HDR mailbox failed with "
  10959. "status x%x add_status x%x, mbx status x%x\n",
  10960. shdr_status, shdr_add_status, rc);
  10961. rc = -ENXIO;
  10962. }
  10963. return rc;
  10964. }
  10965. /**
  10966. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10967. * @phba: pointer to lpfc hba data structure.
  10968. *
  10969. * This routine is invoked to post rpi header templates to the
  10970. * HBA consistent with the SLI-4 interface spec. This routine
  10971. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  10972. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  10973. *
  10974. * Returns
  10975. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  10976. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10977. **/
  10978. int
  10979. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10980. {
  10981. int rpi;
  10982. uint16_t max_rpi, rpi_base, rpi_limit;
  10983. uint16_t rpi_remaining;
  10984. struct lpfc_rpi_hdr *rpi_hdr;
  10985. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10986. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10987. rpi_limit = phba->sli4_hba.next_rpi;
  10988. /*
  10989. * The valid rpi range is not guaranteed to be zero-based. Start
  10990. * the search at the rpi_base as reported by the port.
  10991. */
  10992. spin_lock_irq(&phba->hbalock);
  10993. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10994. if (rpi >= rpi_limit || rpi < rpi_base)
  10995. rpi = LPFC_RPI_ALLOC_ERROR;
  10996. else {
  10997. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10998. phba->sli4_hba.max_cfg_param.rpi_used++;
  10999. phba->sli4_hba.rpi_count++;
  11000. }
  11001. /*
  11002. * Don't try to allocate more rpi header regions if the device limit
  11003. * on available rpis max has been exhausted.
  11004. */
  11005. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  11006. (phba->sli4_hba.rpi_count >= max_rpi)) {
  11007. spin_unlock_irq(&phba->hbalock);
  11008. return rpi;
  11009. }
  11010. /*
  11011. * If the driver is running low on rpi resources, allocate another
  11012. * page now. Note that the next_rpi value is used because
  11013. * it represents how many are actually in use whereas max_rpi notes
  11014. * how many are supported max by the device.
  11015. */
  11016. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  11017. phba->sli4_hba.rpi_count;
  11018. spin_unlock_irq(&phba->hbalock);
  11019. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  11020. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  11021. if (!rpi_hdr) {
  11022. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11023. "2002 Error Could not grow rpi "
  11024. "count\n");
  11025. } else {
  11026. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  11027. }
  11028. }
  11029. return rpi;
  11030. }
  11031. /**
  11032. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11033. * @phba: pointer to lpfc hba data structure.
  11034. *
  11035. * This routine is invoked to release an rpi to the pool of
  11036. * available rpis maintained by the driver.
  11037. **/
  11038. void
  11039. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11040. {
  11041. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  11042. phba->sli4_hba.rpi_count--;
  11043. phba->sli4_hba.max_cfg_param.rpi_used--;
  11044. }
  11045. }
  11046. /**
  11047. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  11048. * @phba: pointer to lpfc hba data structure.
  11049. *
  11050. * This routine is invoked to release an rpi to the pool of
  11051. * available rpis maintained by the driver.
  11052. **/
  11053. void
  11054. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  11055. {
  11056. spin_lock_irq(&phba->hbalock);
  11057. __lpfc_sli4_free_rpi(phba, rpi);
  11058. spin_unlock_irq(&phba->hbalock);
  11059. }
  11060. /**
  11061. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  11062. * @phba: pointer to lpfc hba data structure.
  11063. *
  11064. * This routine is invoked to remove the memory region that
  11065. * provided rpi via a bitmask.
  11066. **/
  11067. void
  11068. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  11069. {
  11070. kfree(phba->sli4_hba.rpi_bmask);
  11071. }
  11072. /**
  11073. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  11074. * @phba: pointer to lpfc hba data structure.
  11075. *
  11076. * This routine is invoked to remove the memory region that
  11077. * provided rpi via a bitmask.
  11078. **/
  11079. int
  11080. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  11081. {
  11082. LPFC_MBOXQ_t *mboxq;
  11083. struct lpfc_hba *phba = ndlp->phba;
  11084. int rc;
  11085. /* The port is notified of the header region via a mailbox command. */
  11086. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11087. if (!mboxq)
  11088. return -ENOMEM;
  11089. /* Post all rpi memory regions to the port. */
  11090. lpfc_resume_rpi(mboxq, ndlp);
  11091. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11092. if (rc == MBX_NOT_FINISHED) {
  11093. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11094. "2010 Resume RPI Mailbox failed "
  11095. "status %d, mbxStatus x%x\n", rc,
  11096. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11097. mempool_free(mboxq, phba->mbox_mem_pool);
  11098. return -EIO;
  11099. }
  11100. return 0;
  11101. }
  11102. /**
  11103. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  11104. * @phba: pointer to lpfc hba data structure.
  11105. * @vpi: vpi value to activate with the port.
  11106. *
  11107. * This routine is invoked to activate a vpi with the
  11108. * port when the host intends to use vports with a
  11109. * nonzero vpi.
  11110. *
  11111. * Returns:
  11112. * 0 success
  11113. * -Evalue otherwise
  11114. **/
  11115. int
  11116. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  11117. {
  11118. LPFC_MBOXQ_t *mboxq;
  11119. int rc = 0;
  11120. int retval = MBX_SUCCESS;
  11121. uint32_t mbox_tmo;
  11122. if (vpi == 0)
  11123. return -EINVAL;
  11124. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11125. if (!mboxq)
  11126. return -ENOMEM;
  11127. lpfc_init_vpi(phba, mboxq, vpi);
  11128. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  11129. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  11130. if (rc != MBX_SUCCESS) {
  11131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11132. "2022 INIT VPI Mailbox failed "
  11133. "status %d, mbxStatus x%x\n", rc,
  11134. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  11135. retval = -EIO;
  11136. }
  11137. if (rc != MBX_TIMEOUT)
  11138. mempool_free(mboxq, phba->mbox_mem_pool);
  11139. return retval;
  11140. }
  11141. /**
  11142. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  11143. * @phba: pointer to lpfc hba data structure.
  11144. * @mboxq: Pointer to mailbox object.
  11145. *
  11146. * This routine is invoked to manually add a single FCF record. The caller
  11147. * must pass a completely initialized FCF_Record. This routine takes
  11148. * care of the nonembedded mailbox operations.
  11149. **/
  11150. static void
  11151. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  11152. {
  11153. void *virt_addr;
  11154. union lpfc_sli4_cfg_shdr *shdr;
  11155. uint32_t shdr_status, shdr_add_status;
  11156. virt_addr = mboxq->sge_array->addr[0];
  11157. /* The IOCTL status is embedded in the mailbox subheader. */
  11158. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  11159. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11160. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11161. if ((shdr_status || shdr_add_status) &&
  11162. (shdr_status != STATUS_FCF_IN_USE))
  11163. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11164. "2558 ADD_FCF_RECORD mailbox failed with "
  11165. "status x%x add_status x%x\n",
  11166. shdr_status, shdr_add_status);
  11167. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11168. }
  11169. /**
  11170. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  11171. * @phba: pointer to lpfc hba data structure.
  11172. * @fcf_record: pointer to the initialized fcf record to add.
  11173. *
  11174. * This routine is invoked to manually add a single FCF record. The caller
  11175. * must pass a completely initialized FCF_Record. This routine takes
  11176. * care of the nonembedded mailbox operations.
  11177. **/
  11178. int
  11179. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  11180. {
  11181. int rc = 0;
  11182. LPFC_MBOXQ_t *mboxq;
  11183. uint8_t *bytep;
  11184. void *virt_addr;
  11185. dma_addr_t phys_addr;
  11186. struct lpfc_mbx_sge sge;
  11187. uint32_t alloc_len, req_len;
  11188. uint32_t fcfindex;
  11189. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11190. if (!mboxq) {
  11191. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11192. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  11193. return -ENOMEM;
  11194. }
  11195. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  11196. sizeof(uint32_t);
  11197. /* Allocate DMA memory and set up the non-embedded mailbox command */
  11198. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  11199. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  11200. req_len, LPFC_SLI4_MBX_NEMBED);
  11201. if (alloc_len < req_len) {
  11202. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11203. "2523 Allocated DMA memory size (x%x) is "
  11204. "less than the requested DMA memory "
  11205. "size (x%x)\n", alloc_len, req_len);
  11206. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11207. return -ENOMEM;
  11208. }
  11209. /*
  11210. * Get the first SGE entry from the non-embedded DMA memory. This
  11211. * routine only uses a single SGE.
  11212. */
  11213. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  11214. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  11215. virt_addr = mboxq->sge_array->addr[0];
  11216. /*
  11217. * Configure the FCF record for FCFI 0. This is the driver's
  11218. * hardcoded default and gets used in nonFIP mode.
  11219. */
  11220. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  11221. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  11222. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  11223. /*
  11224. * Copy the fcf_index and the FCF Record Data. The data starts after
  11225. * the FCoE header plus word10. The data copy needs to be endian
  11226. * correct.
  11227. */
  11228. bytep += sizeof(uint32_t);
  11229. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  11230. mboxq->vport = phba->pport;
  11231. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  11232. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11233. if (rc == MBX_NOT_FINISHED) {
  11234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11235. "2515 ADD_FCF_RECORD mailbox failed with "
  11236. "status 0x%x\n", rc);
  11237. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11238. rc = -EIO;
  11239. } else
  11240. rc = 0;
  11241. return rc;
  11242. }
  11243. /**
  11244. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  11245. * @phba: pointer to lpfc hba data structure.
  11246. * @fcf_record: pointer to the fcf record to write the default data.
  11247. * @fcf_index: FCF table entry index.
  11248. *
  11249. * This routine is invoked to build the driver's default FCF record. The
  11250. * values used are hardcoded. This routine handles memory initialization.
  11251. *
  11252. **/
  11253. void
  11254. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  11255. struct fcf_record *fcf_record,
  11256. uint16_t fcf_index)
  11257. {
  11258. memset(fcf_record, 0, sizeof(struct fcf_record));
  11259. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  11260. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  11261. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  11262. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  11263. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  11264. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  11265. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  11266. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  11267. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  11268. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  11269. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  11270. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  11271. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  11272. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  11273. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  11274. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  11275. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  11276. /* Set the VLAN bit map */
  11277. if (phba->valid_vlan) {
  11278. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  11279. = 1 << (phba->vlan_id % 8);
  11280. }
  11281. }
  11282. /**
  11283. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  11284. * @phba: pointer to lpfc hba data structure.
  11285. * @fcf_index: FCF table entry offset.
  11286. *
  11287. * This routine is invoked to scan the entire FCF table by reading FCF
  11288. * record and processing it one at a time starting from the @fcf_index
  11289. * for initial FCF discovery or fast FCF failover rediscovery.
  11290. *
  11291. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11292. * otherwise.
  11293. **/
  11294. int
  11295. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11296. {
  11297. int rc = 0, error;
  11298. LPFC_MBOXQ_t *mboxq;
  11299. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  11300. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11301. if (!mboxq) {
  11302. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11303. "2000 Failed to allocate mbox for "
  11304. "READ_FCF cmd\n");
  11305. error = -ENOMEM;
  11306. goto fail_fcf_scan;
  11307. }
  11308. /* Construct the read FCF record mailbox command */
  11309. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11310. if (rc) {
  11311. error = -EINVAL;
  11312. goto fail_fcf_scan;
  11313. }
  11314. /* Issue the mailbox command asynchronously */
  11315. mboxq->vport = phba->pport;
  11316. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  11317. spin_lock_irq(&phba->hbalock);
  11318. phba->hba_flag |= FCF_TS_INPROG;
  11319. spin_unlock_irq(&phba->hbalock);
  11320. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11321. if (rc == MBX_NOT_FINISHED)
  11322. error = -EIO;
  11323. else {
  11324. /* Reset eligible FCF count for new scan */
  11325. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  11326. phba->fcf.eligible_fcf_cnt = 0;
  11327. error = 0;
  11328. }
  11329. fail_fcf_scan:
  11330. if (error) {
  11331. if (mboxq)
  11332. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11333. /* FCF scan failed, clear FCF_TS_INPROG flag */
  11334. spin_lock_irq(&phba->hbalock);
  11335. phba->hba_flag &= ~FCF_TS_INPROG;
  11336. spin_unlock_irq(&phba->hbalock);
  11337. }
  11338. return error;
  11339. }
  11340. /**
  11341. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  11342. * @phba: pointer to lpfc hba data structure.
  11343. * @fcf_index: FCF table entry offset.
  11344. *
  11345. * This routine is invoked to read an FCF record indicated by @fcf_index
  11346. * and to use it for FLOGI roundrobin FCF failover.
  11347. *
  11348. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11349. * otherwise.
  11350. **/
  11351. int
  11352. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11353. {
  11354. int rc = 0, error;
  11355. LPFC_MBOXQ_t *mboxq;
  11356. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11357. if (!mboxq) {
  11358. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11359. "2763 Failed to allocate mbox for "
  11360. "READ_FCF cmd\n");
  11361. error = -ENOMEM;
  11362. goto fail_fcf_read;
  11363. }
  11364. /* Construct the read FCF record mailbox command */
  11365. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11366. if (rc) {
  11367. error = -EINVAL;
  11368. goto fail_fcf_read;
  11369. }
  11370. /* Issue the mailbox command asynchronously */
  11371. mboxq->vport = phba->pport;
  11372. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  11373. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11374. if (rc == MBX_NOT_FINISHED)
  11375. error = -EIO;
  11376. else
  11377. error = 0;
  11378. fail_fcf_read:
  11379. if (error && mboxq)
  11380. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11381. return error;
  11382. }
  11383. /**
  11384. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  11385. * @phba: pointer to lpfc hba data structure.
  11386. * @fcf_index: FCF table entry offset.
  11387. *
  11388. * This routine is invoked to read an FCF record indicated by @fcf_index to
  11389. * determine whether it's eligible for FLOGI roundrobin failover list.
  11390. *
  11391. * Return 0 if the mailbox command is submitted sucessfully, none 0
  11392. * otherwise.
  11393. **/
  11394. int
  11395. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  11396. {
  11397. int rc = 0, error;
  11398. LPFC_MBOXQ_t *mboxq;
  11399. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11400. if (!mboxq) {
  11401. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  11402. "2758 Failed to allocate mbox for "
  11403. "READ_FCF cmd\n");
  11404. error = -ENOMEM;
  11405. goto fail_fcf_read;
  11406. }
  11407. /* Construct the read FCF record mailbox command */
  11408. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  11409. if (rc) {
  11410. error = -EINVAL;
  11411. goto fail_fcf_read;
  11412. }
  11413. /* Issue the mailbox command asynchronously */
  11414. mboxq->vport = phba->pport;
  11415. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  11416. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  11417. if (rc == MBX_NOT_FINISHED)
  11418. error = -EIO;
  11419. else
  11420. error = 0;
  11421. fail_fcf_read:
  11422. if (error && mboxq)
  11423. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  11424. return error;
  11425. }
  11426. /**
  11427. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  11428. * @phba: pointer to lpfc hba data structure.
  11429. *
  11430. * This routine is to get the next eligible FCF record index in a round
  11431. * robin fashion. If the next eligible FCF record index equals to the
  11432. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  11433. * shall be returned, otherwise, the next eligible FCF record's index
  11434. * shall be returned.
  11435. **/
  11436. uint16_t
  11437. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  11438. {
  11439. uint16_t next_fcf_index;
  11440. /* Search start from next bit of currently registered FCF index */
  11441. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  11442. LPFC_SLI4_FCF_TBL_INDX_MAX;
  11443. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11444. LPFC_SLI4_FCF_TBL_INDX_MAX,
  11445. next_fcf_index);
  11446. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  11447. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  11448. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  11449. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  11450. /* Check roundrobin failover list empty condition */
  11451. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11452. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  11453. "2844 No roundrobin failover FCF available\n");
  11454. return LPFC_FCOE_FCF_NEXT_NONE;
  11455. }
  11456. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11457. "2845 Get next roundrobin failover FCF (x%x)\n",
  11458. next_fcf_index);
  11459. return next_fcf_index;
  11460. }
  11461. /**
  11462. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  11463. * @phba: pointer to lpfc hba data structure.
  11464. *
  11465. * This routine sets the FCF record index in to the eligible bmask for
  11466. * roundrobin failover search. It checks to make sure that the index
  11467. * does not go beyond the range of the driver allocated bmask dimension
  11468. * before setting the bit.
  11469. *
  11470. * Returns 0 if the index bit successfully set, otherwise, it returns
  11471. * -EINVAL.
  11472. **/
  11473. int
  11474. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  11475. {
  11476. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11477. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11478. "2610 FCF (x%x) reached driver's book "
  11479. "keeping dimension:x%x\n",
  11480. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11481. return -EINVAL;
  11482. }
  11483. /* Set the eligible FCF record index bmask */
  11484. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11485. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11486. "2790 Set FCF (x%x) to roundrobin FCF failover "
  11487. "bmask\n", fcf_index);
  11488. return 0;
  11489. }
  11490. /**
  11491. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  11492. * @phba: pointer to lpfc hba data structure.
  11493. *
  11494. * This routine clears the FCF record index from the eligible bmask for
  11495. * roundrobin failover search. It checks to make sure that the index
  11496. * does not go beyond the range of the driver allocated bmask dimension
  11497. * before clearing the bit.
  11498. **/
  11499. void
  11500. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  11501. {
  11502. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  11503. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11504. "2762 FCF (x%x) reached driver's book "
  11505. "keeping dimension:x%x\n",
  11506. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  11507. return;
  11508. }
  11509. /* Clear the eligible FCF record index bmask */
  11510. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  11511. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11512. "2791 Clear FCF (x%x) from roundrobin failover "
  11513. "bmask\n", fcf_index);
  11514. }
  11515. /**
  11516. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  11517. * @phba: pointer to lpfc hba data structure.
  11518. *
  11519. * This routine is the completion routine for the rediscover FCF table mailbox
  11520. * command. If the mailbox command returned failure, it will try to stop the
  11521. * FCF rediscover wait timer.
  11522. **/
  11523. void
  11524. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  11525. {
  11526. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11527. uint32_t shdr_status, shdr_add_status;
  11528. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11529. shdr_status = bf_get(lpfc_mbox_hdr_status,
  11530. &redisc_fcf->header.cfg_shdr.response);
  11531. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  11532. &redisc_fcf->header.cfg_shdr.response);
  11533. if (shdr_status || shdr_add_status) {
  11534. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  11535. "2746 Requesting for FCF rediscovery failed "
  11536. "status x%x add_status x%x\n",
  11537. shdr_status, shdr_add_status);
  11538. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  11539. spin_lock_irq(&phba->hbalock);
  11540. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  11541. spin_unlock_irq(&phba->hbalock);
  11542. /*
  11543. * CVL event triggered FCF rediscover request failed,
  11544. * last resort to re-try current registered FCF entry.
  11545. */
  11546. lpfc_retry_pport_discovery(phba);
  11547. } else {
  11548. spin_lock_irq(&phba->hbalock);
  11549. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  11550. spin_unlock_irq(&phba->hbalock);
  11551. /*
  11552. * DEAD FCF event triggered FCF rediscover request
  11553. * failed, last resort to fail over as a link down
  11554. * to FCF registration.
  11555. */
  11556. lpfc_sli4_fcf_dead_failthrough(phba);
  11557. }
  11558. } else {
  11559. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  11560. "2775 Start FCF rediscover quiescent timer\n");
  11561. /*
  11562. * Start FCF rediscovery wait timer for pending FCF
  11563. * before rescan FCF record table.
  11564. */
  11565. lpfc_fcf_redisc_wait_start_timer(phba);
  11566. }
  11567. mempool_free(mbox, phba->mbox_mem_pool);
  11568. }
  11569. /**
  11570. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  11571. * @phba: pointer to lpfc hba data structure.
  11572. *
  11573. * This routine is invoked to request for rediscovery of the entire FCF table
  11574. * by the port.
  11575. **/
  11576. int
  11577. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  11578. {
  11579. LPFC_MBOXQ_t *mbox;
  11580. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  11581. int rc, length;
  11582. /* Cancel retry delay timers to all vports before FCF rediscover */
  11583. lpfc_cancel_all_vport_retry_delay_timer(phba);
  11584. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11585. if (!mbox) {
  11586. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11587. "2745 Failed to allocate mbox for "
  11588. "requesting FCF rediscover.\n");
  11589. return -ENOMEM;
  11590. }
  11591. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  11592. sizeof(struct lpfc_sli4_cfg_mhdr));
  11593. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11594. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  11595. length, LPFC_SLI4_MBX_EMBED);
  11596. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  11597. /* Set count to 0 for invalidating the entire FCF database */
  11598. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  11599. /* Issue the mailbox command asynchronously */
  11600. mbox->vport = phba->pport;
  11601. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  11602. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  11603. if (rc == MBX_NOT_FINISHED) {
  11604. mempool_free(mbox, phba->mbox_mem_pool);
  11605. return -EIO;
  11606. }
  11607. return 0;
  11608. }
  11609. /**
  11610. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  11611. * @phba: pointer to lpfc hba data structure.
  11612. *
  11613. * This function is the failover routine as a last resort to the FCF DEAD
  11614. * event when driver failed to perform fast FCF failover.
  11615. **/
  11616. void
  11617. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  11618. {
  11619. uint32_t link_state;
  11620. /*
  11621. * Last resort as FCF DEAD event failover will treat this as
  11622. * a link down, but save the link state because we don't want
  11623. * it to be changed to Link Down unless it is already down.
  11624. */
  11625. link_state = phba->link_state;
  11626. lpfc_linkdown(phba);
  11627. phba->link_state = link_state;
  11628. /* Unregister FCF if no devices connected to it */
  11629. lpfc_unregister_unused_fcf(phba);
  11630. }
  11631. /**
  11632. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  11633. * @phba: pointer to lpfc hba data structure.
  11634. *
  11635. * This function read region 23 and parse TLV for port status to
  11636. * decide if the user disaled the port. If the TLV indicates the
  11637. * port is disabled, the hba_flag is set accordingly.
  11638. **/
  11639. void
  11640. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  11641. {
  11642. LPFC_MBOXQ_t *pmb = NULL;
  11643. MAILBOX_t *mb;
  11644. uint8_t *rgn23_data = NULL;
  11645. uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset;
  11646. int rc;
  11647. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11648. if (!pmb) {
  11649. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11650. "2600 lpfc_sli_read_serdes_param failed to"
  11651. " allocate mailbox memory\n");
  11652. goto out;
  11653. }
  11654. mb = &pmb->u.mb;
  11655. /* Get adapter Region 23 data */
  11656. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  11657. if (!rgn23_data)
  11658. goto out;
  11659. do {
  11660. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  11661. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  11662. if (rc != MBX_SUCCESS) {
  11663. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11664. "2601 lpfc_sli_read_link_ste failed to"
  11665. " read config region 23 rc 0x%x Status 0x%x\n",
  11666. rc, mb->mbxStatus);
  11667. mb->un.varDmp.word_cnt = 0;
  11668. }
  11669. /*
  11670. * dump mem may return a zero when finished or we got a
  11671. * mailbox error, either way we are done.
  11672. */
  11673. if (mb->un.varDmp.word_cnt == 0)
  11674. break;
  11675. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  11676. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  11677. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  11678. rgn23_data + offset,
  11679. mb->un.varDmp.word_cnt);
  11680. offset += mb->un.varDmp.word_cnt;
  11681. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  11682. data_size = offset;
  11683. offset = 0;
  11684. if (!data_size)
  11685. goto out;
  11686. /* Check the region signature first */
  11687. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  11688. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11689. "2619 Config region 23 has bad signature\n");
  11690. goto out;
  11691. }
  11692. offset += 4;
  11693. /* Check the data structure version */
  11694. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  11695. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11696. "2620 Config region 23 has bad version\n");
  11697. goto out;
  11698. }
  11699. offset += 4;
  11700. /* Parse TLV entries in the region */
  11701. while (offset < data_size) {
  11702. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  11703. break;
  11704. /*
  11705. * If the TLV is not driver specific TLV or driver id is
  11706. * not linux driver id, skip the record.
  11707. */
  11708. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  11709. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  11710. (rgn23_data[offset + 3] != 0)) {
  11711. offset += rgn23_data[offset + 1] * 4 + 4;
  11712. continue;
  11713. }
  11714. /* Driver found a driver specific TLV in the config region */
  11715. sub_tlv_len = rgn23_data[offset + 1] * 4;
  11716. offset += 4;
  11717. tlv_offset = 0;
  11718. /*
  11719. * Search for configured port state sub-TLV.
  11720. */
  11721. while ((offset < data_size) &&
  11722. (tlv_offset < sub_tlv_len)) {
  11723. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  11724. offset += 4;
  11725. tlv_offset += 4;
  11726. break;
  11727. }
  11728. if (rgn23_data[offset] != PORT_STE_TYPE) {
  11729. offset += rgn23_data[offset + 1] * 4 + 4;
  11730. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  11731. continue;
  11732. }
  11733. /* This HBA contains PORT_STE configured */
  11734. if (!rgn23_data[offset + 2])
  11735. phba->hba_flag |= LINK_DISABLED;
  11736. goto out;
  11737. }
  11738. }
  11739. out:
  11740. if (pmb)
  11741. mempool_free(pmb, phba->mbox_mem_pool);
  11742. kfree(rgn23_data);
  11743. return;
  11744. }
  11745. /**
  11746. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  11747. * @vport: pointer to vport data structure.
  11748. *
  11749. * This function iterate through the mailboxq and clean up all REG_LOGIN
  11750. * and REG_VPI mailbox commands associated with the vport. This function
  11751. * is called when driver want to restart discovery of the vport due to
  11752. * a Clear Virtual Link event.
  11753. **/
  11754. void
  11755. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  11756. {
  11757. struct lpfc_hba *phba = vport->phba;
  11758. LPFC_MBOXQ_t *mb, *nextmb;
  11759. struct lpfc_dmabuf *mp;
  11760. struct lpfc_nodelist *ndlp;
  11761. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  11762. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  11763. LIST_HEAD(mbox_cmd_list);
  11764. /* Clean up internally queued mailbox commands with the vport */
  11765. spin_lock_irq(&phba->hbalock);
  11766. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  11767. if (mb->vport != vport)
  11768. continue;
  11769. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  11770. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  11771. continue;
  11772. list_del(&mb->list);
  11773. list_add_tail(&mb->list, &mbox_cmd_list);
  11774. }
  11775. /* Clean up active mailbox command with the vport */
  11776. mb = phba->sli.mbox_active;
  11777. if (mb && (mb->vport == vport)) {
  11778. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  11779. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  11780. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11781. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11782. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  11783. /* Put reference count for delayed processing */
  11784. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  11785. /* Unregister the RPI when mailbox complete */
  11786. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  11787. }
  11788. }
  11789. spin_unlock_irq(&phba->hbalock);
  11790. /* Release the cleaned-up mailbox commands */
  11791. while (!list_empty(&mbox_cmd_list)) {
  11792. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  11793. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  11794. if (phba->sli_rev == LPFC_SLI_REV4)
  11795. __lpfc_sli4_free_rpi(phba,
  11796. mb->u.mb.un.varRegLogin.rpi);
  11797. mp = (struct lpfc_dmabuf *) (mb->context1);
  11798. if (mp) {
  11799. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  11800. kfree(mp);
  11801. }
  11802. ndlp = (struct lpfc_nodelist *) mb->context2;
  11803. mb->context2 = NULL;
  11804. if (ndlp) {
  11805. spin_lock(shost->host_lock);
  11806. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11807. spin_unlock(shost->host_lock);
  11808. lpfc_nlp_put(ndlp);
  11809. }
  11810. }
  11811. mempool_free(mb, phba->mbox_mem_pool);
  11812. }
  11813. /* Release the ndlp with the cleaned-up active mailbox command */
  11814. if (act_mbx_ndlp) {
  11815. spin_lock(shost->host_lock);
  11816. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  11817. spin_unlock(shost->host_lock);
  11818. lpfc_nlp_put(act_mbx_ndlp);
  11819. }
  11820. }
  11821. /**
  11822. * lpfc_drain_txq - Drain the txq
  11823. * @phba: Pointer to HBA context object.
  11824. *
  11825. * This function attempt to submit IOCBs on the txq
  11826. * to the adapter. For SLI4 adapters, the txq contains
  11827. * ELS IOCBs that have been deferred because the there
  11828. * are no SGLs. This congestion can occur with large
  11829. * vport counts during node discovery.
  11830. **/
  11831. uint32_t
  11832. lpfc_drain_txq(struct lpfc_hba *phba)
  11833. {
  11834. LIST_HEAD(completions);
  11835. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  11836. struct lpfc_iocbq *piocbq = 0;
  11837. unsigned long iflags = 0;
  11838. char *fail_msg = NULL;
  11839. struct lpfc_sglq *sglq;
  11840. union lpfc_wqe wqe;
  11841. spin_lock_irqsave(&phba->hbalock, iflags);
  11842. if (pring->txq_cnt > pring->txq_max)
  11843. pring->txq_max = pring->txq_cnt;
  11844. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11845. while (pring->txq_cnt) {
  11846. spin_lock_irqsave(&phba->hbalock, iflags);
  11847. sglq = __lpfc_sli_get_sglq(phba);
  11848. if (!sglq) {
  11849. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11850. break;
  11851. } else {
  11852. piocbq = lpfc_sli_ringtx_get(phba, pring);
  11853. if (!piocbq) {
  11854. /* The txq_cnt out of sync. This should
  11855. * never happen
  11856. */
  11857. sglq = __lpfc_clear_active_sglq(phba,
  11858. sglq->sli4_xritag);
  11859. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11860. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11861. "2823 txq empty and txq_cnt is %d\n ",
  11862. pring->txq_cnt);
  11863. break;
  11864. }
  11865. }
  11866. /* The xri and iocb resources secured,
  11867. * attempt to issue request
  11868. */
  11869. piocbq->sli4_xritag = sglq->sli4_xritag;
  11870. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  11871. fail_msg = "to convert bpl to sgl";
  11872. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  11873. fail_msg = "to convert iocb to wqe";
  11874. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  11875. fail_msg = " - Wq is full";
  11876. else
  11877. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  11878. if (fail_msg) {
  11879. /* Failed means we can't issue and need to cancel */
  11880. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11881. "2822 IOCB failed %s iotag 0x%x "
  11882. "xri 0x%x\n",
  11883. fail_msg,
  11884. piocbq->iotag, piocbq->sli4_xritag);
  11885. list_add_tail(&piocbq->list, &completions);
  11886. }
  11887. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11888. }
  11889. /* Cancel all the IOCBs that cannot be issued */
  11890. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  11891. IOERR_SLI_ABORTED);
  11892. return pring->txq_cnt;
  11893. }