lpfc_sli.c 353 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_logmsg.h"
  41. #include "lpfc_compat.h"
  42. #include "lpfc_debugfs.h"
  43. #include "lpfc_vport.h"
  44. /* There are only four IOCB completion types. */
  45. typedef enum _lpfc_iocb_type {
  46. LPFC_UNKNOWN_IOCB,
  47. LPFC_UNSOL_IOCB,
  48. LPFC_SOL_IOCB,
  49. LPFC_ABORT_IOCB
  50. } lpfc_iocb_type;
  51. /* Provide function prototypes local to this module. */
  52. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  53. uint32_t);
  54. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint8_t *, uint32_t *);
  56. static IOCB_t *
  57. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  58. {
  59. return &iocbq->iocb;
  60. }
  61. /**
  62. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  63. * @q: The Work Queue to operate on.
  64. * @wqe: The work Queue Entry to put on the Work queue.
  65. *
  66. * This routine will copy the contents of @wqe to the next available entry on
  67. * the @q. This function will then ring the Work Queue Doorbell to signal the
  68. * HBA to start processing the Work Queue Entry. This function returns 0 if
  69. * successful. If no entries are available on @q then this function will return
  70. * -ENOMEM.
  71. * The caller is expected to hold the hbalock when calling this routine.
  72. **/
  73. static uint32_t
  74. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  75. {
  76. union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe;
  77. struct lpfc_register doorbell;
  78. uint32_t host_index;
  79. /* If the host has not yet processed the next entry then we are done */
  80. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  81. return -ENOMEM;
  82. /* set consumption flag every once in a while */
  83. if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
  84. bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1);
  85. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  86. /* Update the host index before invoking device */
  87. host_index = q->host_index;
  88. q->host_index = ((q->host_index + 1) % q->entry_count);
  89. /* Ring Doorbell */
  90. doorbell.word0 = 0;
  91. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  92. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  93. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  94. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  95. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  96. return 0;
  97. }
  98. /**
  99. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  100. * @q: The Work Queue to operate on.
  101. * @index: The index to advance the hba index to.
  102. *
  103. * This routine will update the HBA index of a queue to reflect consumption of
  104. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  105. * an entry the host calls this function to update the queue's internal
  106. * pointers. This routine returns the number of entries that were consumed by
  107. * the HBA.
  108. **/
  109. static uint32_t
  110. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  111. {
  112. uint32_t released = 0;
  113. if (q->hba_index == index)
  114. return 0;
  115. do {
  116. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  117. released++;
  118. } while (q->hba_index != index);
  119. return released;
  120. }
  121. /**
  122. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  123. * @q: The Mailbox Queue to operate on.
  124. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  125. *
  126. * This routine will copy the contents of @mqe to the next available entry on
  127. * the @q. This function will then ring the Work Queue Doorbell to signal the
  128. * HBA to start processing the Work Queue Entry. This function returns 0 if
  129. * successful. If no entries are available on @q then this function will return
  130. * -ENOMEM.
  131. * The caller is expected to hold the hbalock when calling this routine.
  132. **/
  133. static uint32_t
  134. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  135. {
  136. struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe;
  137. struct lpfc_register doorbell;
  138. uint32_t host_index;
  139. /* If the host has not yet processed the next entry then we are done */
  140. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  141. return -ENOMEM;
  142. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  143. /* Save off the mailbox pointer for completion */
  144. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  145. /* Update the host index before invoking device */
  146. host_index = q->host_index;
  147. q->host_index = ((q->host_index + 1) % q->entry_count);
  148. /* Ring Doorbell */
  149. doorbell.word0 = 0;
  150. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  151. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  152. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  153. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  154. return 0;
  155. }
  156. /**
  157. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  158. * @q: The Mailbox Queue to operate on.
  159. *
  160. * This routine will update the HBA index of a queue to reflect consumption of
  161. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  162. * an entry the host calls this function to update the queue's internal
  163. * pointers. This routine returns the number of entries that were consumed by
  164. * the HBA.
  165. **/
  166. static uint32_t
  167. lpfc_sli4_mq_release(struct lpfc_queue *q)
  168. {
  169. /* Clear the mailbox pointer for completion */
  170. q->phba->mbox = NULL;
  171. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  172. return 1;
  173. }
  174. /**
  175. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  176. * @q: The Event Queue to get the first valid EQE from
  177. *
  178. * This routine will get the first valid Event Queue Entry from @q, update
  179. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  180. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  181. * processed, but not popped back to the HBA then this routine will return NULL.
  182. **/
  183. static struct lpfc_eqe *
  184. lpfc_sli4_eq_get(struct lpfc_queue *q)
  185. {
  186. struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe;
  187. /* If the next EQE is not valid then we are done */
  188. if (!bf_get(lpfc_eqe_valid, eqe))
  189. return NULL;
  190. /* If the host has not yet processed the next entry then we are done */
  191. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  192. return NULL;
  193. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  194. return eqe;
  195. }
  196. /**
  197. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  198. * @q: The Event Queue that the host has completed processing for.
  199. * @arm: Indicates whether the host wants to arms this CQ.
  200. *
  201. * This routine will mark all Event Queue Entries on @q, from the last
  202. * known completed entry to the last entry that was processed, as completed
  203. * by clearing the valid bit for each completion queue entry. Then it will
  204. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  205. * The internal host index in the @q will be updated by this routine to indicate
  206. * that the host has finished processing the entries. The @arm parameter
  207. * indicates that the queue should be rearmed when ringing the doorbell.
  208. *
  209. * This function will return the number of EQEs that were popped.
  210. **/
  211. uint32_t
  212. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  213. {
  214. uint32_t released = 0;
  215. struct lpfc_eqe *temp_eqe;
  216. struct lpfc_register doorbell;
  217. /* while there are valid entries */
  218. while (q->hba_index != q->host_index) {
  219. temp_eqe = q->qe[q->host_index].eqe;
  220. bf_set(lpfc_eqe_valid, temp_eqe, 0);
  221. released++;
  222. q->host_index = ((q->host_index + 1) % q->entry_count);
  223. }
  224. if (unlikely(released == 0 && !arm))
  225. return 0;
  226. /* ring doorbell for number popped */
  227. doorbell.word0 = 0;
  228. if (arm) {
  229. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  230. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  231. }
  232. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  233. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  234. bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id);
  235. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  236. return released;
  237. }
  238. /**
  239. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  240. * @q: The Completion Queue to get the first valid CQE from
  241. *
  242. * This routine will get the first valid Completion Queue Entry from @q, update
  243. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  244. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  245. * processed, but not popped back to the HBA then this routine will return NULL.
  246. **/
  247. static struct lpfc_cqe *
  248. lpfc_sli4_cq_get(struct lpfc_queue *q)
  249. {
  250. struct lpfc_cqe *cqe;
  251. /* If the next CQE is not valid then we are done */
  252. if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  253. return NULL;
  254. /* If the host has not yet processed the next entry then we are done */
  255. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  256. return NULL;
  257. cqe = q->qe[q->hba_index].cqe;
  258. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  259. return cqe;
  260. }
  261. /**
  262. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  263. * @q: The Completion Queue that the host has completed processing for.
  264. * @arm: Indicates whether the host wants to arms this CQ.
  265. *
  266. * This routine will mark all Completion queue entries on @q, from the last
  267. * known completed entry to the last entry that was processed, as completed
  268. * by clearing the valid bit for each completion queue entry. Then it will
  269. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  270. * The internal host index in the @q will be updated by this routine to indicate
  271. * that the host has finished processing the entries. The @arm parameter
  272. * indicates that the queue should be rearmed when ringing the doorbell.
  273. *
  274. * This function will return the number of CQEs that were released.
  275. **/
  276. uint32_t
  277. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  278. {
  279. uint32_t released = 0;
  280. struct lpfc_cqe *temp_qe;
  281. struct lpfc_register doorbell;
  282. /* while there are valid entries */
  283. while (q->hba_index != q->host_index) {
  284. temp_qe = q->qe[q->host_index].cqe;
  285. bf_set(lpfc_cqe_valid, temp_qe, 0);
  286. released++;
  287. q->host_index = ((q->host_index + 1) % q->entry_count);
  288. }
  289. if (unlikely(released == 0 && !arm))
  290. return 0;
  291. /* ring doorbell for number popped */
  292. doorbell.word0 = 0;
  293. if (arm)
  294. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  295. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  296. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  297. bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id);
  298. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  299. return released;
  300. }
  301. /**
  302. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  303. * @q: The Header Receive Queue to operate on.
  304. * @wqe: The Receive Queue Entry to put on the Receive queue.
  305. *
  306. * This routine will copy the contents of @wqe to the next available entry on
  307. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  308. * HBA to start processing the Receive Queue Entry. This function returns the
  309. * index that the rqe was copied to if successful. If no entries are available
  310. * on @q then this function will return -ENOMEM.
  311. * The caller is expected to hold the hbalock when calling this routine.
  312. **/
  313. static int
  314. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  315. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  316. {
  317. struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe;
  318. struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe;
  319. struct lpfc_register doorbell;
  320. int put_index = hq->host_index;
  321. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  322. return -EINVAL;
  323. if (hq->host_index != dq->host_index)
  324. return -EINVAL;
  325. /* If the host has not yet processed the next entry then we are done */
  326. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  327. return -EBUSY;
  328. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  329. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  330. /* Update the host index to point to the next slot */
  331. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  332. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  333. /* Ring The Header Receive Queue Doorbell */
  334. if (!(hq->host_index % LPFC_RQ_POST_BATCH)) {
  335. doorbell.word0 = 0;
  336. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  337. LPFC_RQ_POST_BATCH);
  338. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  339. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  340. }
  341. return put_index;
  342. }
  343. /**
  344. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  345. * @q: The Header Receive Queue to operate on.
  346. *
  347. * This routine will update the HBA index of a queue to reflect consumption of
  348. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  349. * consumed an entry the host calls this function to update the queue's
  350. * internal pointers. This routine returns the number of entries that were
  351. * consumed by the HBA.
  352. **/
  353. static uint32_t
  354. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  355. {
  356. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  357. return 0;
  358. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  359. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  360. return 1;
  361. }
  362. /**
  363. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  364. * @phba: Pointer to HBA context object.
  365. * @pring: Pointer to driver SLI ring object.
  366. *
  367. * This function returns pointer to next command iocb entry
  368. * in the command ring. The caller must hold hbalock to prevent
  369. * other threads consume the next command iocb.
  370. * SLI-2/SLI-3 provide different sized iocbs.
  371. **/
  372. static inline IOCB_t *
  373. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  374. {
  375. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  376. pring->cmdidx * phba->iocb_cmd_size);
  377. }
  378. /**
  379. * lpfc_resp_iocb - Get next response iocb entry in the ring
  380. * @phba: Pointer to HBA context object.
  381. * @pring: Pointer to driver SLI ring object.
  382. *
  383. * This function returns pointer to next response iocb entry
  384. * in the response ring. The caller must hold hbalock to make sure
  385. * that no other thread consume the next response iocb.
  386. * SLI-2/SLI-3 provide different sized iocbs.
  387. **/
  388. static inline IOCB_t *
  389. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  390. {
  391. return (IOCB_t *) (((char *) pring->rspringaddr) +
  392. pring->rspidx * phba->iocb_rsp_size);
  393. }
  394. /**
  395. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  396. * @phba: Pointer to HBA context object.
  397. *
  398. * This function is called with hbalock held. This function
  399. * allocates a new driver iocb object from the iocb pool. If the
  400. * allocation is successful, it returns pointer to the newly
  401. * allocated iocb object else it returns NULL.
  402. **/
  403. static struct lpfc_iocbq *
  404. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  405. {
  406. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  407. struct lpfc_iocbq * iocbq = NULL;
  408. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  409. return iocbq;
  410. }
  411. /**
  412. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  413. * @phba: Pointer to HBA context object.
  414. * @xritag: XRI value.
  415. *
  416. * This function clears the sglq pointer from the array of acive
  417. * sglq's. The xritag that is passed in is used to index into the
  418. * array. Before the xritag can be used it needs to be adjusted
  419. * by subtracting the xribase.
  420. *
  421. * Returns sglq ponter = success, NULL = Failure.
  422. **/
  423. static struct lpfc_sglq *
  424. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  425. {
  426. uint16_t adj_xri;
  427. struct lpfc_sglq *sglq;
  428. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  429. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  430. return NULL;
  431. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  432. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL;
  433. return sglq;
  434. }
  435. /**
  436. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  437. * @phba: Pointer to HBA context object.
  438. * @xritag: XRI value.
  439. *
  440. * This function returns the sglq pointer from the array of acive
  441. * sglq's. The xritag that is passed in is used to index into the
  442. * array. Before the xritag can be used it needs to be adjusted
  443. * by subtracting the xribase.
  444. *
  445. * Returns sglq ponter = success, NULL = Failure.
  446. **/
  447. static struct lpfc_sglq *
  448. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  449. {
  450. uint16_t adj_xri;
  451. struct lpfc_sglq *sglq;
  452. adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
  453. if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri)
  454. return NULL;
  455. sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri];
  456. return sglq;
  457. }
  458. /**
  459. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  460. * @phba: Pointer to HBA context object.
  461. *
  462. * This function is called with hbalock held. This function
  463. * Gets a new driver sglq object from the sglq list. If the
  464. * list is not empty then it is successful, it returns pointer to the newly
  465. * allocated sglq object else it returns NULL.
  466. **/
  467. static struct lpfc_sglq *
  468. __lpfc_sli_get_sglq(struct lpfc_hba *phba)
  469. {
  470. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  471. struct lpfc_sglq *sglq = NULL;
  472. uint16_t adj_xri;
  473. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  474. adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base;
  475. phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq;
  476. return sglq;
  477. }
  478. /**
  479. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  480. * @phba: Pointer to HBA context object.
  481. *
  482. * This function is called with no lock held. This function
  483. * allocates a new driver iocb object from the iocb pool. If the
  484. * allocation is successful, it returns pointer to the newly
  485. * allocated iocb object else it returns NULL.
  486. **/
  487. struct lpfc_iocbq *
  488. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  489. {
  490. struct lpfc_iocbq * iocbq = NULL;
  491. unsigned long iflags;
  492. spin_lock_irqsave(&phba->hbalock, iflags);
  493. iocbq = __lpfc_sli_get_iocbq(phba);
  494. spin_unlock_irqrestore(&phba->hbalock, iflags);
  495. return iocbq;
  496. }
  497. /**
  498. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  499. * @phba: Pointer to HBA context object.
  500. * @iocbq: Pointer to driver iocb object.
  501. *
  502. * This function is called with hbalock held to release driver
  503. * iocb object to the iocb pool. The iotag in the iocb object
  504. * does not change for each use of the iocb object. This function
  505. * clears all other fields of the iocb object when it is freed.
  506. * The sqlq structure that holds the xritag and phys and virtual
  507. * mappings for the scatter gather list is retrieved from the
  508. * active array of sglq. The get of the sglq pointer also clears
  509. * the entry in the array. If the status of the IO indiactes that
  510. * this IO was aborted then the sglq entry it put on the
  511. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  512. * IO has good status or fails for any other reason then the sglq
  513. * entry is added to the free list (lpfc_sgl_list).
  514. **/
  515. static void
  516. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  517. {
  518. struct lpfc_sglq *sglq;
  519. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  520. unsigned long iflag;
  521. if (iocbq->sli4_xritag == NO_XRI)
  522. sglq = NULL;
  523. else
  524. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
  525. if (sglq) {
  526. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED
  527. || ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  528. && (iocbq->iocb.un.ulpWord[4]
  529. == IOERR_SLI_ABORTED))) {
  530. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  531. iflag);
  532. list_add(&sglq->list,
  533. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  534. spin_unlock_irqrestore(
  535. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  536. } else
  537. list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list);
  538. }
  539. /*
  540. * Clean all volatile data fields, preserve iotag and node struct.
  541. */
  542. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  543. iocbq->sli4_xritag = NO_XRI;
  544. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  545. }
  546. /**
  547. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  548. * @phba: Pointer to HBA context object.
  549. * @iocbq: Pointer to driver iocb object.
  550. *
  551. * This function is called with hbalock held to release driver
  552. * iocb object to the iocb pool. The iotag in the iocb object
  553. * does not change for each use of the iocb object. This function
  554. * clears all other fields of the iocb object when it is freed.
  555. **/
  556. static void
  557. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  558. {
  559. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  560. /*
  561. * Clean all volatile data fields, preserve iotag and node struct.
  562. */
  563. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  564. iocbq->sli4_xritag = NO_XRI;
  565. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  566. }
  567. /**
  568. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  569. * @phba: Pointer to HBA context object.
  570. * @iocbq: Pointer to driver iocb object.
  571. *
  572. * This function is called with hbalock held to release driver
  573. * iocb object to the iocb pool. The iotag in the iocb object
  574. * does not change for each use of the iocb object. This function
  575. * clears all other fields of the iocb object when it is freed.
  576. **/
  577. static void
  578. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  579. {
  580. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  581. }
  582. /**
  583. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  584. * @phba: Pointer to HBA context object.
  585. * @iocbq: Pointer to driver iocb object.
  586. *
  587. * This function is called with no lock held to release the iocb to
  588. * iocb pool.
  589. **/
  590. void
  591. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  592. {
  593. unsigned long iflags;
  594. /*
  595. * Clean all volatile data fields, preserve iotag and node struct.
  596. */
  597. spin_lock_irqsave(&phba->hbalock, iflags);
  598. __lpfc_sli_release_iocbq(phba, iocbq);
  599. spin_unlock_irqrestore(&phba->hbalock, iflags);
  600. }
  601. /**
  602. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  603. * @phba: Pointer to HBA context object.
  604. * @iocblist: List of IOCBs.
  605. * @ulpstatus: ULP status in IOCB command field.
  606. * @ulpWord4: ULP word-4 in IOCB command field.
  607. *
  608. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  609. * on the list by invoking the complete callback function associated with the
  610. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  611. * fields.
  612. **/
  613. void
  614. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  615. uint32_t ulpstatus, uint32_t ulpWord4)
  616. {
  617. struct lpfc_iocbq *piocb;
  618. while (!list_empty(iocblist)) {
  619. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  620. if (!piocb->iocb_cmpl)
  621. lpfc_sli_release_iocbq(phba, piocb);
  622. else {
  623. piocb->iocb.ulpStatus = ulpstatus;
  624. piocb->iocb.un.ulpWord[4] = ulpWord4;
  625. (piocb->iocb_cmpl) (phba, piocb, piocb);
  626. }
  627. }
  628. return;
  629. }
  630. /**
  631. * lpfc_sli_iocb_cmd_type - Get the iocb type
  632. * @iocb_cmnd: iocb command code.
  633. *
  634. * This function is called by ring event handler function to get the iocb type.
  635. * This function translates the iocb command to an iocb command type used to
  636. * decide the final disposition of each completed IOCB.
  637. * The function returns
  638. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  639. * LPFC_SOL_IOCB if it is a solicited iocb completion
  640. * LPFC_ABORT_IOCB if it is an abort iocb
  641. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  642. *
  643. * The caller is not required to hold any lock.
  644. **/
  645. static lpfc_iocb_type
  646. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  647. {
  648. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  649. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  650. return 0;
  651. switch (iocb_cmnd) {
  652. case CMD_XMIT_SEQUENCE_CR:
  653. case CMD_XMIT_SEQUENCE_CX:
  654. case CMD_XMIT_BCAST_CN:
  655. case CMD_XMIT_BCAST_CX:
  656. case CMD_ELS_REQUEST_CR:
  657. case CMD_ELS_REQUEST_CX:
  658. case CMD_CREATE_XRI_CR:
  659. case CMD_CREATE_XRI_CX:
  660. case CMD_GET_RPI_CN:
  661. case CMD_XMIT_ELS_RSP_CX:
  662. case CMD_GET_RPI_CR:
  663. case CMD_FCP_IWRITE_CR:
  664. case CMD_FCP_IWRITE_CX:
  665. case CMD_FCP_IREAD_CR:
  666. case CMD_FCP_IREAD_CX:
  667. case CMD_FCP_ICMND_CR:
  668. case CMD_FCP_ICMND_CX:
  669. case CMD_FCP_TSEND_CX:
  670. case CMD_FCP_TRSP_CX:
  671. case CMD_FCP_TRECEIVE_CX:
  672. case CMD_FCP_AUTO_TRSP_CX:
  673. case CMD_ADAPTER_MSG:
  674. case CMD_ADAPTER_DUMP:
  675. case CMD_XMIT_SEQUENCE64_CR:
  676. case CMD_XMIT_SEQUENCE64_CX:
  677. case CMD_XMIT_BCAST64_CN:
  678. case CMD_XMIT_BCAST64_CX:
  679. case CMD_ELS_REQUEST64_CR:
  680. case CMD_ELS_REQUEST64_CX:
  681. case CMD_FCP_IWRITE64_CR:
  682. case CMD_FCP_IWRITE64_CX:
  683. case CMD_FCP_IREAD64_CR:
  684. case CMD_FCP_IREAD64_CX:
  685. case CMD_FCP_ICMND64_CR:
  686. case CMD_FCP_ICMND64_CX:
  687. case CMD_FCP_TSEND64_CX:
  688. case CMD_FCP_TRSP64_CX:
  689. case CMD_FCP_TRECEIVE64_CX:
  690. case CMD_GEN_REQUEST64_CR:
  691. case CMD_GEN_REQUEST64_CX:
  692. case CMD_XMIT_ELS_RSP64_CX:
  693. case DSSCMD_IWRITE64_CR:
  694. case DSSCMD_IWRITE64_CX:
  695. case DSSCMD_IREAD64_CR:
  696. case DSSCMD_IREAD64_CX:
  697. case DSSCMD_INVALIDATE_DEK:
  698. case DSSCMD_SET_KEK:
  699. case DSSCMD_GET_KEK_ID:
  700. case DSSCMD_GEN_XFER:
  701. type = LPFC_SOL_IOCB;
  702. break;
  703. case CMD_ABORT_XRI_CN:
  704. case CMD_ABORT_XRI_CX:
  705. case CMD_CLOSE_XRI_CN:
  706. case CMD_CLOSE_XRI_CX:
  707. case CMD_XRI_ABORTED_CX:
  708. case CMD_ABORT_MXRI64_CN:
  709. type = LPFC_ABORT_IOCB;
  710. break;
  711. case CMD_RCV_SEQUENCE_CX:
  712. case CMD_RCV_ELS_REQ_CX:
  713. case CMD_RCV_SEQUENCE64_CX:
  714. case CMD_RCV_ELS_REQ64_CX:
  715. case CMD_ASYNC_STATUS:
  716. case CMD_IOCB_RCV_SEQ64_CX:
  717. case CMD_IOCB_RCV_ELS64_CX:
  718. case CMD_IOCB_RCV_CONT64_CX:
  719. case CMD_IOCB_RET_XRI64_CX:
  720. type = LPFC_UNSOL_IOCB;
  721. break;
  722. case CMD_IOCB_XMIT_MSEQ64_CR:
  723. case CMD_IOCB_XMIT_MSEQ64_CX:
  724. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  725. case CMD_IOCB_RCV_ELS_LIST64_CX:
  726. case CMD_IOCB_CLOSE_EXTENDED_CN:
  727. case CMD_IOCB_ABORT_EXTENDED_CN:
  728. case CMD_IOCB_RET_HBQE64_CN:
  729. case CMD_IOCB_FCP_IBIDIR64_CR:
  730. case CMD_IOCB_FCP_IBIDIR64_CX:
  731. case CMD_IOCB_FCP_ITASKMGT64_CX:
  732. case CMD_IOCB_LOGENTRY_CN:
  733. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  734. printk("%s - Unhandled SLI-3 Command x%x\n",
  735. __func__, iocb_cmnd);
  736. type = LPFC_UNKNOWN_IOCB;
  737. break;
  738. default:
  739. type = LPFC_UNKNOWN_IOCB;
  740. break;
  741. }
  742. return type;
  743. }
  744. /**
  745. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  746. * @phba: Pointer to HBA context object.
  747. *
  748. * This function is called from SLI initialization code
  749. * to configure every ring of the HBA's SLI interface. The
  750. * caller is not required to hold any lock. This function issues
  751. * a config_ring mailbox command for each ring.
  752. * This function returns zero if successful else returns a negative
  753. * error code.
  754. **/
  755. static int
  756. lpfc_sli_ring_map(struct lpfc_hba *phba)
  757. {
  758. struct lpfc_sli *psli = &phba->sli;
  759. LPFC_MBOXQ_t *pmb;
  760. MAILBOX_t *pmbox;
  761. int i, rc, ret = 0;
  762. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  763. if (!pmb)
  764. return -ENOMEM;
  765. pmbox = &pmb->u.mb;
  766. phba->link_state = LPFC_INIT_MBX_CMDS;
  767. for (i = 0; i < psli->num_rings; i++) {
  768. lpfc_config_ring(phba, i, pmb);
  769. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  770. if (rc != MBX_SUCCESS) {
  771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  772. "0446 Adapter failed to init (%d), "
  773. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  774. "ring %d\n",
  775. rc, pmbox->mbxCommand,
  776. pmbox->mbxStatus, i);
  777. phba->link_state = LPFC_HBA_ERROR;
  778. ret = -ENXIO;
  779. break;
  780. }
  781. }
  782. mempool_free(pmb, phba->mbox_mem_pool);
  783. return ret;
  784. }
  785. /**
  786. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  787. * @phba: Pointer to HBA context object.
  788. * @pring: Pointer to driver SLI ring object.
  789. * @piocb: Pointer to the driver iocb object.
  790. *
  791. * This function is called with hbalock held. The function adds the
  792. * new iocb to txcmplq of the given ring. This function always returns
  793. * 0. If this function is called for ELS ring, this function checks if
  794. * there is a vport associated with the ELS command. This function also
  795. * starts els_tmofunc timer if this is an ELS command.
  796. **/
  797. static int
  798. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  799. struct lpfc_iocbq *piocb)
  800. {
  801. list_add_tail(&piocb->list, &pring->txcmplq);
  802. pring->txcmplq_cnt++;
  803. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  804. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  805. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  806. if (!piocb->vport)
  807. BUG();
  808. else
  809. mod_timer(&piocb->vport->els_tmofunc,
  810. jiffies + HZ * (phba->fc_ratov << 1));
  811. }
  812. return 0;
  813. }
  814. /**
  815. * lpfc_sli_ringtx_get - Get first element of the txq
  816. * @phba: Pointer to HBA context object.
  817. * @pring: Pointer to driver SLI ring object.
  818. *
  819. * This function is called with hbalock held to get next
  820. * iocb in txq of the given ring. If there is any iocb in
  821. * the txq, the function returns first iocb in the list after
  822. * removing the iocb from the list, else it returns NULL.
  823. **/
  824. static struct lpfc_iocbq *
  825. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  826. {
  827. struct lpfc_iocbq *cmd_iocb;
  828. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  829. if (cmd_iocb != NULL)
  830. pring->txq_cnt--;
  831. return cmd_iocb;
  832. }
  833. /**
  834. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  835. * @phba: Pointer to HBA context object.
  836. * @pring: Pointer to driver SLI ring object.
  837. *
  838. * This function is called with hbalock held and the caller must post the
  839. * iocb without releasing the lock. If the caller releases the lock,
  840. * iocb slot returned by the function is not guaranteed to be available.
  841. * The function returns pointer to the next available iocb slot if there
  842. * is available slot in the ring, else it returns NULL.
  843. * If the get index of the ring is ahead of the put index, the function
  844. * will post an error attention event to the worker thread to take the
  845. * HBA to offline state.
  846. **/
  847. static IOCB_t *
  848. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  849. {
  850. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  851. uint32_t max_cmd_idx = pring->numCiocb;
  852. if ((pring->next_cmdidx == pring->cmdidx) &&
  853. (++pring->next_cmdidx >= max_cmd_idx))
  854. pring->next_cmdidx = 0;
  855. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  856. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  857. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  859. "0315 Ring %d issue: portCmdGet %d "
  860. "is bigger than cmd ring %d\n",
  861. pring->ringno,
  862. pring->local_getidx, max_cmd_idx);
  863. phba->link_state = LPFC_HBA_ERROR;
  864. /*
  865. * All error attention handlers are posted to
  866. * worker thread
  867. */
  868. phba->work_ha |= HA_ERATT;
  869. phba->work_hs = HS_FFER3;
  870. lpfc_worker_wake_up(phba);
  871. return NULL;
  872. }
  873. if (pring->local_getidx == pring->next_cmdidx)
  874. return NULL;
  875. }
  876. return lpfc_cmd_iocb(phba, pring);
  877. }
  878. /**
  879. * lpfc_sli_next_iotag - Get an iotag for the iocb
  880. * @phba: Pointer to HBA context object.
  881. * @iocbq: Pointer to driver iocb object.
  882. *
  883. * This function gets an iotag for the iocb. If there is no unused iotag and
  884. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  885. * array and assigns a new iotag.
  886. * The function returns the allocated iotag if successful, else returns zero.
  887. * Zero is not a valid iotag.
  888. * The caller is not required to hold any lock.
  889. **/
  890. uint16_t
  891. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  892. {
  893. struct lpfc_iocbq **new_arr;
  894. struct lpfc_iocbq **old_arr;
  895. size_t new_len;
  896. struct lpfc_sli *psli = &phba->sli;
  897. uint16_t iotag;
  898. spin_lock_irq(&phba->hbalock);
  899. iotag = psli->last_iotag;
  900. if(++iotag < psli->iocbq_lookup_len) {
  901. psli->last_iotag = iotag;
  902. psli->iocbq_lookup[iotag] = iocbq;
  903. spin_unlock_irq(&phba->hbalock);
  904. iocbq->iotag = iotag;
  905. return iotag;
  906. } else if (psli->iocbq_lookup_len < (0xffff
  907. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  908. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  909. spin_unlock_irq(&phba->hbalock);
  910. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  911. GFP_KERNEL);
  912. if (new_arr) {
  913. spin_lock_irq(&phba->hbalock);
  914. old_arr = psli->iocbq_lookup;
  915. if (new_len <= psli->iocbq_lookup_len) {
  916. /* highly unprobable case */
  917. kfree(new_arr);
  918. iotag = psli->last_iotag;
  919. if(++iotag < psli->iocbq_lookup_len) {
  920. psli->last_iotag = iotag;
  921. psli->iocbq_lookup[iotag] = iocbq;
  922. spin_unlock_irq(&phba->hbalock);
  923. iocbq->iotag = iotag;
  924. return iotag;
  925. }
  926. spin_unlock_irq(&phba->hbalock);
  927. return 0;
  928. }
  929. if (psli->iocbq_lookup)
  930. memcpy(new_arr, old_arr,
  931. ((psli->last_iotag + 1) *
  932. sizeof (struct lpfc_iocbq *)));
  933. psli->iocbq_lookup = new_arr;
  934. psli->iocbq_lookup_len = new_len;
  935. psli->last_iotag = iotag;
  936. psli->iocbq_lookup[iotag] = iocbq;
  937. spin_unlock_irq(&phba->hbalock);
  938. iocbq->iotag = iotag;
  939. kfree(old_arr);
  940. return iotag;
  941. }
  942. } else
  943. spin_unlock_irq(&phba->hbalock);
  944. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  945. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  946. psli->last_iotag);
  947. return 0;
  948. }
  949. /**
  950. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  951. * @phba: Pointer to HBA context object.
  952. * @pring: Pointer to driver SLI ring object.
  953. * @iocb: Pointer to iocb slot in the ring.
  954. * @nextiocb: Pointer to driver iocb object which need to be
  955. * posted to firmware.
  956. *
  957. * This function is called with hbalock held to post a new iocb to
  958. * the firmware. This function copies the new iocb to ring iocb slot and
  959. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  960. * a completion call back for this iocb else the function will free the
  961. * iocb object.
  962. **/
  963. static void
  964. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  965. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  966. {
  967. /*
  968. * Set up an iotag
  969. */
  970. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  971. if (pring->ringno == LPFC_ELS_RING) {
  972. lpfc_debugfs_slow_ring_trc(phba,
  973. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  974. *(((uint32_t *) &nextiocb->iocb) + 4),
  975. *(((uint32_t *) &nextiocb->iocb) + 6),
  976. *(((uint32_t *) &nextiocb->iocb) + 7));
  977. }
  978. /*
  979. * Issue iocb command to adapter
  980. */
  981. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  982. wmb();
  983. pring->stats.iocb_cmd++;
  984. /*
  985. * If there is no completion routine to call, we can release the
  986. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  987. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  988. */
  989. if (nextiocb->iocb_cmpl)
  990. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  991. else
  992. __lpfc_sli_release_iocbq(phba, nextiocb);
  993. /*
  994. * Let the HBA know what IOCB slot will be the next one the
  995. * driver will put a command into.
  996. */
  997. pring->cmdidx = pring->next_cmdidx;
  998. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  999. }
  1000. /**
  1001. * lpfc_sli_update_full_ring - Update the chip attention register
  1002. * @phba: Pointer to HBA context object.
  1003. * @pring: Pointer to driver SLI ring object.
  1004. *
  1005. * The caller is not required to hold any lock for calling this function.
  1006. * This function updates the chip attention bits for the ring to inform firmware
  1007. * that there are pending work to be done for this ring and requests an
  1008. * interrupt when there is space available in the ring. This function is
  1009. * called when the driver is unable to post more iocbs to the ring due
  1010. * to unavailability of space in the ring.
  1011. **/
  1012. static void
  1013. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1014. {
  1015. int ringno = pring->ringno;
  1016. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1017. wmb();
  1018. /*
  1019. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1020. * The HBA will tell us when an IOCB entry is available.
  1021. */
  1022. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1023. readl(phba->CAregaddr); /* flush */
  1024. pring->stats.iocb_cmd_full++;
  1025. }
  1026. /**
  1027. * lpfc_sli_update_ring - Update chip attention register
  1028. * @phba: Pointer to HBA context object.
  1029. * @pring: Pointer to driver SLI ring object.
  1030. *
  1031. * This function updates the chip attention register bit for the
  1032. * given ring to inform HBA that there is more work to be done
  1033. * in this ring. The caller is not required to hold any lock.
  1034. **/
  1035. static void
  1036. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1037. {
  1038. int ringno = pring->ringno;
  1039. /*
  1040. * Tell the HBA that there is work to do in this ring.
  1041. */
  1042. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1043. wmb();
  1044. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1045. readl(phba->CAregaddr); /* flush */
  1046. }
  1047. }
  1048. /**
  1049. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1050. * @phba: Pointer to HBA context object.
  1051. * @pring: Pointer to driver SLI ring object.
  1052. *
  1053. * This function is called with hbalock held to post pending iocbs
  1054. * in the txq to the firmware. This function is called when driver
  1055. * detects space available in the ring.
  1056. **/
  1057. static void
  1058. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1059. {
  1060. IOCB_t *iocb;
  1061. struct lpfc_iocbq *nextiocb;
  1062. /*
  1063. * Check to see if:
  1064. * (a) there is anything on the txq to send
  1065. * (b) link is up
  1066. * (c) link attention events can be processed (fcp ring only)
  1067. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1068. */
  1069. if (pring->txq_cnt &&
  1070. lpfc_is_link_up(phba) &&
  1071. (pring->ringno != phba->sli.fcp_ring ||
  1072. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1073. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1074. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1075. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1076. if (iocb)
  1077. lpfc_sli_update_ring(phba, pring);
  1078. else
  1079. lpfc_sli_update_full_ring(phba, pring);
  1080. }
  1081. return;
  1082. }
  1083. /**
  1084. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1085. * @phba: Pointer to HBA context object.
  1086. * @hbqno: HBQ number.
  1087. *
  1088. * This function is called with hbalock held to get the next
  1089. * available slot for the given HBQ. If there is free slot
  1090. * available for the HBQ it will return pointer to the next available
  1091. * HBQ entry else it will return NULL.
  1092. **/
  1093. static struct lpfc_hbq_entry *
  1094. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1095. {
  1096. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1097. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1098. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1099. hbqp->next_hbqPutIdx = 0;
  1100. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1101. uint32_t raw_index = phba->hbq_get[hbqno];
  1102. uint32_t getidx = le32_to_cpu(raw_index);
  1103. hbqp->local_hbqGetIdx = getidx;
  1104. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1105. lpfc_printf_log(phba, KERN_ERR,
  1106. LOG_SLI | LOG_VPORT,
  1107. "1802 HBQ %d: local_hbqGetIdx "
  1108. "%u is > than hbqp->entry_count %u\n",
  1109. hbqno, hbqp->local_hbqGetIdx,
  1110. hbqp->entry_count);
  1111. phba->link_state = LPFC_HBA_ERROR;
  1112. return NULL;
  1113. }
  1114. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1115. return NULL;
  1116. }
  1117. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1118. hbqp->hbqPutIdx;
  1119. }
  1120. /**
  1121. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1122. * @phba: Pointer to HBA context object.
  1123. *
  1124. * This function is called with no lock held to free all the
  1125. * hbq buffers while uninitializing the SLI interface. It also
  1126. * frees the HBQ buffers returned by the firmware but not yet
  1127. * processed by the upper layers.
  1128. **/
  1129. void
  1130. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1131. {
  1132. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1133. struct hbq_dmabuf *hbq_buf;
  1134. unsigned long flags;
  1135. int i, hbq_count;
  1136. uint32_t hbqno;
  1137. hbq_count = lpfc_sli_hbq_count();
  1138. /* Return all memory used by all HBQs */
  1139. spin_lock_irqsave(&phba->hbalock, flags);
  1140. for (i = 0; i < hbq_count; ++i) {
  1141. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1142. &phba->hbqs[i].hbq_buffer_list, list) {
  1143. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1144. list_del(&hbq_buf->dbuf.list);
  1145. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1146. }
  1147. phba->hbqs[i].buffer_count = 0;
  1148. }
  1149. /* Return all HBQ buffer that are in-fly */
  1150. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1151. list) {
  1152. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1153. list_del(&hbq_buf->dbuf.list);
  1154. if (hbq_buf->tag == -1) {
  1155. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1156. (phba, hbq_buf);
  1157. } else {
  1158. hbqno = hbq_buf->tag >> 16;
  1159. if (hbqno >= LPFC_MAX_HBQS)
  1160. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1161. (phba, hbq_buf);
  1162. else
  1163. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1164. hbq_buf);
  1165. }
  1166. }
  1167. /* Mark the HBQs not in use */
  1168. phba->hbq_in_use = 0;
  1169. spin_unlock_irqrestore(&phba->hbalock, flags);
  1170. }
  1171. /**
  1172. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1173. * @phba: Pointer to HBA context object.
  1174. * @hbqno: HBQ number.
  1175. * @hbq_buf: Pointer to HBQ buffer.
  1176. *
  1177. * This function is called with the hbalock held to post a
  1178. * hbq buffer to the firmware. If the function finds an empty
  1179. * slot in the HBQ, it will post the buffer. The function will return
  1180. * pointer to the hbq entry if it successfully post the buffer
  1181. * else it will return NULL.
  1182. **/
  1183. static int
  1184. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1185. struct hbq_dmabuf *hbq_buf)
  1186. {
  1187. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1188. }
  1189. /**
  1190. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1191. * @phba: Pointer to HBA context object.
  1192. * @hbqno: HBQ number.
  1193. * @hbq_buf: Pointer to HBQ buffer.
  1194. *
  1195. * This function is called with the hbalock held to post a hbq buffer to the
  1196. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1197. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1198. * it successfully post the buffer else it will return an error.
  1199. **/
  1200. static int
  1201. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1202. struct hbq_dmabuf *hbq_buf)
  1203. {
  1204. struct lpfc_hbq_entry *hbqe;
  1205. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1206. /* Get next HBQ entry slot to use */
  1207. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1208. if (hbqe) {
  1209. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1210. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1211. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1212. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1213. hbqe->bde.tus.f.bdeFlags = 0;
  1214. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1215. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1216. /* Sync SLIM */
  1217. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1218. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1219. /* flush */
  1220. readl(phba->hbq_put + hbqno);
  1221. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1222. return 0;
  1223. } else
  1224. return -ENOMEM;
  1225. }
  1226. /**
  1227. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1228. * @phba: Pointer to HBA context object.
  1229. * @hbqno: HBQ number.
  1230. * @hbq_buf: Pointer to HBQ buffer.
  1231. *
  1232. * This function is called with the hbalock held to post an RQE to the SLI4
  1233. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1234. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1235. **/
  1236. static int
  1237. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1238. struct hbq_dmabuf *hbq_buf)
  1239. {
  1240. int rc;
  1241. struct lpfc_rqe hrqe;
  1242. struct lpfc_rqe drqe;
  1243. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1244. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1245. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1246. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1247. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1248. &hrqe, &drqe);
  1249. if (rc < 0)
  1250. return rc;
  1251. hbq_buf->tag = rc;
  1252. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1253. return 0;
  1254. }
  1255. /* HBQ for ELS and CT traffic. */
  1256. static struct lpfc_hbq_init lpfc_els_hbq = {
  1257. .rn = 1,
  1258. .entry_count = 200,
  1259. .mask_count = 0,
  1260. .profile = 0,
  1261. .ring_mask = (1 << LPFC_ELS_RING),
  1262. .buffer_count = 0,
  1263. .init_count = 40,
  1264. .add_count = 40,
  1265. };
  1266. /* HBQ for the extra ring if needed */
  1267. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1268. .rn = 1,
  1269. .entry_count = 200,
  1270. .mask_count = 0,
  1271. .profile = 0,
  1272. .ring_mask = (1 << LPFC_EXTRA_RING),
  1273. .buffer_count = 0,
  1274. .init_count = 0,
  1275. .add_count = 5,
  1276. };
  1277. /* Array of HBQs */
  1278. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1279. &lpfc_els_hbq,
  1280. &lpfc_extra_hbq,
  1281. };
  1282. /**
  1283. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1284. * @phba: Pointer to HBA context object.
  1285. * @hbqno: HBQ number.
  1286. * @count: Number of HBQ buffers to be posted.
  1287. *
  1288. * This function is called with no lock held to post more hbq buffers to the
  1289. * given HBQ. The function returns the number of HBQ buffers successfully
  1290. * posted.
  1291. **/
  1292. static int
  1293. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1294. {
  1295. uint32_t i, posted = 0;
  1296. unsigned long flags;
  1297. struct hbq_dmabuf *hbq_buffer;
  1298. LIST_HEAD(hbq_buf_list);
  1299. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1300. return 0;
  1301. if ((phba->hbqs[hbqno].buffer_count + count) >
  1302. lpfc_hbq_defs[hbqno]->entry_count)
  1303. count = lpfc_hbq_defs[hbqno]->entry_count -
  1304. phba->hbqs[hbqno].buffer_count;
  1305. if (!count)
  1306. return 0;
  1307. /* Allocate HBQ entries */
  1308. for (i = 0; i < count; i++) {
  1309. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1310. if (!hbq_buffer)
  1311. break;
  1312. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1313. }
  1314. /* Check whether HBQ is still in use */
  1315. spin_lock_irqsave(&phba->hbalock, flags);
  1316. if (!phba->hbq_in_use)
  1317. goto err;
  1318. while (!list_empty(&hbq_buf_list)) {
  1319. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1320. dbuf.list);
  1321. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1322. (hbqno << 16));
  1323. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1324. phba->hbqs[hbqno].buffer_count++;
  1325. posted++;
  1326. } else
  1327. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1328. }
  1329. spin_unlock_irqrestore(&phba->hbalock, flags);
  1330. return posted;
  1331. err:
  1332. spin_unlock_irqrestore(&phba->hbalock, flags);
  1333. while (!list_empty(&hbq_buf_list)) {
  1334. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1335. dbuf.list);
  1336. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1337. }
  1338. return 0;
  1339. }
  1340. /**
  1341. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1342. * @phba: Pointer to HBA context object.
  1343. * @qno: HBQ number.
  1344. *
  1345. * This function posts more buffers to the HBQ. This function
  1346. * is called with no lock held. The function returns the number of HBQ entries
  1347. * successfully allocated.
  1348. **/
  1349. int
  1350. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1351. {
  1352. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1353. lpfc_hbq_defs[qno]->add_count));
  1354. }
  1355. /**
  1356. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1357. * @phba: Pointer to HBA context object.
  1358. * @qno: HBQ queue number.
  1359. *
  1360. * This function is called from SLI initialization code path with
  1361. * no lock held to post initial HBQ buffers to firmware. The
  1362. * function returns the number of HBQ entries successfully allocated.
  1363. **/
  1364. static int
  1365. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1366. {
  1367. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1368. lpfc_hbq_defs[qno]->init_count));
  1369. }
  1370. /**
  1371. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1372. * @phba: Pointer to HBA context object.
  1373. * @hbqno: HBQ number.
  1374. *
  1375. * This function removes the first hbq buffer on an hbq list and returns a
  1376. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1377. **/
  1378. static struct hbq_dmabuf *
  1379. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1380. {
  1381. struct lpfc_dmabuf *d_buf;
  1382. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1383. if (!d_buf)
  1384. return NULL;
  1385. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1386. }
  1387. /**
  1388. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1389. * @phba: Pointer to HBA context object.
  1390. * @tag: Tag of the hbq buffer.
  1391. *
  1392. * This function is called with hbalock held. This function searches
  1393. * for the hbq buffer associated with the given tag in the hbq buffer
  1394. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1395. * it returns NULL.
  1396. **/
  1397. static struct hbq_dmabuf *
  1398. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1399. {
  1400. struct lpfc_dmabuf *d_buf;
  1401. struct hbq_dmabuf *hbq_buf;
  1402. uint32_t hbqno;
  1403. hbqno = tag >> 16;
  1404. if (hbqno >= LPFC_MAX_HBQS)
  1405. return NULL;
  1406. spin_lock_irq(&phba->hbalock);
  1407. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1408. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1409. if (hbq_buf->tag == tag) {
  1410. spin_unlock_irq(&phba->hbalock);
  1411. return hbq_buf;
  1412. }
  1413. }
  1414. spin_unlock_irq(&phba->hbalock);
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1416. "1803 Bad hbq tag. Data: x%x x%x\n",
  1417. tag, phba->hbqs[tag >> 16].buffer_count);
  1418. return NULL;
  1419. }
  1420. /**
  1421. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1422. * @phba: Pointer to HBA context object.
  1423. * @hbq_buffer: Pointer to HBQ buffer.
  1424. *
  1425. * This function is called with hbalock. This function gives back
  1426. * the hbq buffer to firmware. If the HBQ does not have space to
  1427. * post the buffer, it will free the buffer.
  1428. **/
  1429. void
  1430. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1431. {
  1432. uint32_t hbqno;
  1433. if (hbq_buffer) {
  1434. hbqno = hbq_buffer->tag >> 16;
  1435. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1436. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1437. }
  1438. }
  1439. /**
  1440. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1441. * @mbxCommand: mailbox command code.
  1442. *
  1443. * This function is called by the mailbox event handler function to verify
  1444. * that the completed mailbox command is a legitimate mailbox command. If the
  1445. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1446. * and the mailbox event handler will take the HBA offline.
  1447. **/
  1448. static int
  1449. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1450. {
  1451. uint8_t ret;
  1452. switch (mbxCommand) {
  1453. case MBX_LOAD_SM:
  1454. case MBX_READ_NV:
  1455. case MBX_WRITE_NV:
  1456. case MBX_WRITE_VPARMS:
  1457. case MBX_RUN_BIU_DIAG:
  1458. case MBX_INIT_LINK:
  1459. case MBX_DOWN_LINK:
  1460. case MBX_CONFIG_LINK:
  1461. case MBX_CONFIG_RING:
  1462. case MBX_RESET_RING:
  1463. case MBX_READ_CONFIG:
  1464. case MBX_READ_RCONFIG:
  1465. case MBX_READ_SPARM:
  1466. case MBX_READ_STATUS:
  1467. case MBX_READ_RPI:
  1468. case MBX_READ_XRI:
  1469. case MBX_READ_REV:
  1470. case MBX_READ_LNK_STAT:
  1471. case MBX_REG_LOGIN:
  1472. case MBX_UNREG_LOGIN:
  1473. case MBX_READ_LA:
  1474. case MBX_CLEAR_LA:
  1475. case MBX_DUMP_MEMORY:
  1476. case MBX_DUMP_CONTEXT:
  1477. case MBX_RUN_DIAGS:
  1478. case MBX_RESTART:
  1479. case MBX_UPDATE_CFG:
  1480. case MBX_DOWN_LOAD:
  1481. case MBX_DEL_LD_ENTRY:
  1482. case MBX_RUN_PROGRAM:
  1483. case MBX_SET_MASK:
  1484. case MBX_SET_VARIABLE:
  1485. case MBX_UNREG_D_ID:
  1486. case MBX_KILL_BOARD:
  1487. case MBX_CONFIG_FARP:
  1488. case MBX_BEACON:
  1489. case MBX_LOAD_AREA:
  1490. case MBX_RUN_BIU_DIAG64:
  1491. case MBX_CONFIG_PORT:
  1492. case MBX_READ_SPARM64:
  1493. case MBX_READ_RPI64:
  1494. case MBX_REG_LOGIN64:
  1495. case MBX_READ_LA64:
  1496. case MBX_WRITE_WWN:
  1497. case MBX_SET_DEBUG:
  1498. case MBX_LOAD_EXP_ROM:
  1499. case MBX_ASYNCEVT_ENABLE:
  1500. case MBX_REG_VPI:
  1501. case MBX_UNREG_VPI:
  1502. case MBX_HEARTBEAT:
  1503. case MBX_PORT_CAPABILITIES:
  1504. case MBX_PORT_IOV_CONTROL:
  1505. case MBX_SLI4_CONFIG:
  1506. case MBX_SLI4_REQ_FTRS:
  1507. case MBX_REG_FCFI:
  1508. case MBX_UNREG_FCFI:
  1509. case MBX_REG_VFI:
  1510. case MBX_UNREG_VFI:
  1511. case MBX_INIT_VPI:
  1512. case MBX_INIT_VFI:
  1513. case MBX_RESUME_RPI:
  1514. ret = mbxCommand;
  1515. break;
  1516. default:
  1517. ret = MBX_SHUTDOWN;
  1518. break;
  1519. }
  1520. return ret;
  1521. }
  1522. /**
  1523. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1524. * @phba: Pointer to HBA context object.
  1525. * @pmboxq: Pointer to mailbox command.
  1526. *
  1527. * This is completion handler function for mailbox commands issued from
  1528. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1529. * mailbox event handler function with no lock held. This function
  1530. * will wake up thread waiting on the wait queue pointed by context1
  1531. * of the mailbox.
  1532. **/
  1533. void
  1534. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1535. {
  1536. wait_queue_head_t *pdone_q;
  1537. unsigned long drvr_flag;
  1538. /*
  1539. * If pdone_q is empty, the driver thread gave up waiting and
  1540. * continued running.
  1541. */
  1542. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1543. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1544. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1545. if (pdone_q)
  1546. wake_up_interruptible(pdone_q);
  1547. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1548. return;
  1549. }
  1550. /**
  1551. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1552. * @phba: Pointer to HBA context object.
  1553. * @pmb: Pointer to mailbox object.
  1554. *
  1555. * This function is the default mailbox completion handler. It
  1556. * frees the memory resources associated with the completed mailbox
  1557. * command. If the completed command is a REG_LOGIN mailbox command,
  1558. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1559. **/
  1560. void
  1561. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1562. {
  1563. struct lpfc_dmabuf *mp;
  1564. uint16_t rpi, vpi;
  1565. int rc;
  1566. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1567. if (mp) {
  1568. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1569. kfree(mp);
  1570. }
  1571. if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
  1572. (phba->sli_rev == LPFC_SLI_REV4))
  1573. lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
  1574. /*
  1575. * If a REG_LOGIN succeeded after node is destroyed or node
  1576. * is in re-discovery driver need to cleanup the RPI.
  1577. */
  1578. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1579. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1580. !pmb->u.mb.mbxStatus) {
  1581. rpi = pmb->u.mb.un.varWords[0];
  1582. vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base;
  1583. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1584. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1585. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1586. if (rc != MBX_NOT_FINISHED)
  1587. return;
  1588. }
  1589. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1590. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1591. else
  1592. mempool_free(pmb, phba->mbox_mem_pool);
  1593. }
  1594. /**
  1595. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1596. * @phba: Pointer to HBA context object.
  1597. *
  1598. * This function is called with no lock held. This function processes all
  1599. * the completed mailbox commands and gives it to upper layers. The interrupt
  1600. * service routine processes mailbox completion interrupt and adds completed
  1601. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1602. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1603. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1604. * function returns the mailbox commands to the upper layer by calling the
  1605. * completion handler function of each mailbox.
  1606. **/
  1607. int
  1608. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1609. {
  1610. MAILBOX_t *pmbox;
  1611. LPFC_MBOXQ_t *pmb;
  1612. int rc;
  1613. LIST_HEAD(cmplq);
  1614. phba->sli.slistat.mbox_event++;
  1615. /* Get all completed mailboxe buffers into the cmplq */
  1616. spin_lock_irq(&phba->hbalock);
  1617. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  1618. spin_unlock_irq(&phba->hbalock);
  1619. /* Get a Mailbox buffer to setup mailbox commands for callback */
  1620. do {
  1621. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  1622. if (pmb == NULL)
  1623. break;
  1624. pmbox = &pmb->u.mb;
  1625. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  1626. if (pmb->vport) {
  1627. lpfc_debugfs_disc_trc(pmb->vport,
  1628. LPFC_DISC_TRC_MBOX_VPORT,
  1629. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  1630. (uint32_t)pmbox->mbxCommand,
  1631. pmbox->un.varWords[0],
  1632. pmbox->un.varWords[1]);
  1633. }
  1634. else {
  1635. lpfc_debugfs_disc_trc(phba->pport,
  1636. LPFC_DISC_TRC_MBOX,
  1637. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  1638. (uint32_t)pmbox->mbxCommand,
  1639. pmbox->un.varWords[0],
  1640. pmbox->un.varWords[1]);
  1641. }
  1642. }
  1643. /*
  1644. * It is a fatal error if unknown mbox command completion.
  1645. */
  1646. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  1647. MBX_SHUTDOWN) {
  1648. /* Unknow mailbox command compl */
  1649. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1650. "(%d):0323 Unknown Mailbox command "
  1651. "x%x (x%x) Cmpl\n",
  1652. pmb->vport ? pmb->vport->vpi : 0,
  1653. pmbox->mbxCommand,
  1654. lpfc_sli4_mbox_opcode_get(phba, pmb));
  1655. phba->link_state = LPFC_HBA_ERROR;
  1656. phba->work_hs = HS_FFER3;
  1657. lpfc_handle_eratt(phba);
  1658. continue;
  1659. }
  1660. if (pmbox->mbxStatus) {
  1661. phba->sli.slistat.mbox_stat_err++;
  1662. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  1663. /* Mbox cmd cmpl error - RETRYing */
  1664. lpfc_printf_log(phba, KERN_INFO,
  1665. LOG_MBOX | LOG_SLI,
  1666. "(%d):0305 Mbox cmd cmpl "
  1667. "error - RETRYing Data: x%x "
  1668. "(x%x) x%x x%x x%x\n",
  1669. pmb->vport ? pmb->vport->vpi :0,
  1670. pmbox->mbxCommand,
  1671. lpfc_sli4_mbox_opcode_get(phba,
  1672. pmb),
  1673. pmbox->mbxStatus,
  1674. pmbox->un.varWords[0],
  1675. pmb->vport->port_state);
  1676. pmbox->mbxStatus = 0;
  1677. pmbox->mbxOwner = OWN_HOST;
  1678. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1679. if (rc != MBX_NOT_FINISHED)
  1680. continue;
  1681. }
  1682. }
  1683. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  1684. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  1685. "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p "
  1686. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1687. pmb->vport ? pmb->vport->vpi : 0,
  1688. pmbox->mbxCommand,
  1689. lpfc_sli4_mbox_opcode_get(phba, pmb),
  1690. pmb->mbox_cmpl,
  1691. *((uint32_t *) pmbox),
  1692. pmbox->un.varWords[0],
  1693. pmbox->un.varWords[1],
  1694. pmbox->un.varWords[2],
  1695. pmbox->un.varWords[3],
  1696. pmbox->un.varWords[4],
  1697. pmbox->un.varWords[5],
  1698. pmbox->un.varWords[6],
  1699. pmbox->un.varWords[7]);
  1700. if (pmb->mbox_cmpl)
  1701. pmb->mbox_cmpl(phba,pmb);
  1702. } while (1);
  1703. return 0;
  1704. }
  1705. /**
  1706. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  1707. * @phba: Pointer to HBA context object.
  1708. * @pring: Pointer to driver SLI ring object.
  1709. * @tag: buffer tag.
  1710. *
  1711. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  1712. * is set in the tag the buffer is posted for a particular exchange,
  1713. * the function will return the buffer without replacing the buffer.
  1714. * If the buffer is for unsolicited ELS or CT traffic, this function
  1715. * returns the buffer and also posts another buffer to the firmware.
  1716. **/
  1717. static struct lpfc_dmabuf *
  1718. lpfc_sli_get_buff(struct lpfc_hba *phba,
  1719. struct lpfc_sli_ring *pring,
  1720. uint32_t tag)
  1721. {
  1722. struct hbq_dmabuf *hbq_entry;
  1723. if (tag & QUE_BUFTAG_BIT)
  1724. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  1725. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  1726. if (!hbq_entry)
  1727. return NULL;
  1728. return &hbq_entry->dbuf;
  1729. }
  1730. /**
  1731. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  1732. * @phba: Pointer to HBA context object.
  1733. * @pring: Pointer to driver SLI ring object.
  1734. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  1735. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  1736. * @fch_type: the type for the first frame of the sequence.
  1737. *
  1738. * This function is called with no lock held. This function uses the r_ctl and
  1739. * type of the received sequence to find the correct callback function to call
  1740. * to process the sequence.
  1741. **/
  1742. static int
  1743. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1744. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  1745. uint32_t fch_type)
  1746. {
  1747. int i;
  1748. /* unSolicited Responses */
  1749. if (pring->prt[0].profile) {
  1750. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1751. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1752. saveq);
  1753. return 1;
  1754. }
  1755. /* We must search, based on rctl / type
  1756. for the right routine */
  1757. for (i = 0; i < pring->num_mask; i++) {
  1758. if ((pring->prt[i].rctl == fch_r_ctl) &&
  1759. (pring->prt[i].type == fch_type)) {
  1760. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1761. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1762. (phba, pring, saveq);
  1763. return 1;
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. /**
  1769. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  1770. * @phba: Pointer to HBA context object.
  1771. * @pring: Pointer to driver SLI ring object.
  1772. * @saveq: Pointer to the unsolicited iocb.
  1773. *
  1774. * This function is called with no lock held by the ring event handler
  1775. * when there is an unsolicited iocb posted to the response ring by the
  1776. * firmware. This function gets the buffer associated with the iocbs
  1777. * and calls the event handler for the ring. This function handles both
  1778. * qring buffers and hbq buffers.
  1779. * When the function returns 1 the caller can free the iocb object otherwise
  1780. * upper layer functions will free the iocb objects.
  1781. **/
  1782. static int
  1783. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1784. struct lpfc_iocbq *saveq)
  1785. {
  1786. IOCB_t * irsp;
  1787. WORD5 * w5p;
  1788. uint32_t Rctl, Type;
  1789. uint32_t match;
  1790. struct lpfc_iocbq *iocbq;
  1791. struct lpfc_dmabuf *dmzbuf;
  1792. match = 0;
  1793. irsp = &(saveq->iocb);
  1794. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  1795. if (pring->lpfc_sli_rcv_async_status)
  1796. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  1797. else
  1798. lpfc_printf_log(phba,
  1799. KERN_WARNING,
  1800. LOG_SLI,
  1801. "0316 Ring %d handler: unexpected "
  1802. "ASYNC_STATUS iocb received evt_code "
  1803. "0x%x\n",
  1804. pring->ringno,
  1805. irsp->un.asyncstat.evt_code);
  1806. return 1;
  1807. }
  1808. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  1809. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  1810. if (irsp->ulpBdeCount > 0) {
  1811. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1812. irsp->un.ulpWord[3]);
  1813. lpfc_in_buf_free(phba, dmzbuf);
  1814. }
  1815. if (irsp->ulpBdeCount > 1) {
  1816. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1817. irsp->unsli3.sli3Words[3]);
  1818. lpfc_in_buf_free(phba, dmzbuf);
  1819. }
  1820. if (irsp->ulpBdeCount > 2) {
  1821. dmzbuf = lpfc_sli_get_buff(phba, pring,
  1822. irsp->unsli3.sli3Words[7]);
  1823. lpfc_in_buf_free(phba, dmzbuf);
  1824. }
  1825. return 1;
  1826. }
  1827. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  1828. if (irsp->ulpBdeCount != 0) {
  1829. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  1830. irsp->un.ulpWord[3]);
  1831. if (!saveq->context2)
  1832. lpfc_printf_log(phba,
  1833. KERN_ERR,
  1834. LOG_SLI,
  1835. "0341 Ring %d Cannot find buffer for "
  1836. "an unsolicited iocb. tag 0x%x\n",
  1837. pring->ringno,
  1838. irsp->un.ulpWord[3]);
  1839. }
  1840. if (irsp->ulpBdeCount == 2) {
  1841. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  1842. irsp->unsli3.sli3Words[7]);
  1843. if (!saveq->context3)
  1844. lpfc_printf_log(phba,
  1845. KERN_ERR,
  1846. LOG_SLI,
  1847. "0342 Ring %d Cannot find buffer for an"
  1848. " unsolicited iocb. tag 0x%x\n",
  1849. pring->ringno,
  1850. irsp->unsli3.sli3Words[7]);
  1851. }
  1852. list_for_each_entry(iocbq, &saveq->list, list) {
  1853. irsp = &(iocbq->iocb);
  1854. if (irsp->ulpBdeCount != 0) {
  1855. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  1856. irsp->un.ulpWord[3]);
  1857. if (!iocbq->context2)
  1858. lpfc_printf_log(phba,
  1859. KERN_ERR,
  1860. LOG_SLI,
  1861. "0343 Ring %d Cannot find "
  1862. "buffer for an unsolicited iocb"
  1863. ". tag 0x%x\n", pring->ringno,
  1864. irsp->un.ulpWord[3]);
  1865. }
  1866. if (irsp->ulpBdeCount == 2) {
  1867. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  1868. irsp->unsli3.sli3Words[7]);
  1869. if (!iocbq->context3)
  1870. lpfc_printf_log(phba,
  1871. KERN_ERR,
  1872. LOG_SLI,
  1873. "0344 Ring %d Cannot find "
  1874. "buffer for an unsolicited "
  1875. "iocb. tag 0x%x\n",
  1876. pring->ringno,
  1877. irsp->unsli3.sli3Words[7]);
  1878. }
  1879. }
  1880. }
  1881. if (irsp->ulpBdeCount != 0 &&
  1882. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1883. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1884. int found = 0;
  1885. /* search continue save q for same XRI */
  1886. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1887. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1888. list_add_tail(&saveq->list, &iocbq->list);
  1889. found = 1;
  1890. break;
  1891. }
  1892. }
  1893. if (!found)
  1894. list_add_tail(&saveq->clist,
  1895. &pring->iocb_continue_saveq);
  1896. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1897. list_del_init(&iocbq->clist);
  1898. saveq = iocbq;
  1899. irsp = &(saveq->iocb);
  1900. } else
  1901. return 0;
  1902. }
  1903. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1904. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1905. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1906. Rctl = FC_ELS_REQ;
  1907. Type = FC_ELS_DATA;
  1908. } else {
  1909. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1910. Rctl = w5p->hcsw.Rctl;
  1911. Type = w5p->hcsw.Type;
  1912. /* Firmware Workaround */
  1913. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1914. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1915. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1916. Rctl = FC_ELS_REQ;
  1917. Type = FC_ELS_DATA;
  1918. w5p->hcsw.Rctl = Rctl;
  1919. w5p->hcsw.Type = Type;
  1920. }
  1921. }
  1922. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  1923. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1924. "0313 Ring %d handler: unexpected Rctl x%x "
  1925. "Type x%x received\n",
  1926. pring->ringno, Rctl, Type);
  1927. return 1;
  1928. }
  1929. /**
  1930. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  1931. * @phba: Pointer to HBA context object.
  1932. * @pring: Pointer to driver SLI ring object.
  1933. * @prspiocb: Pointer to response iocb object.
  1934. *
  1935. * This function looks up the iocb_lookup table to get the command iocb
  1936. * corresponding to the given response iocb using the iotag of the
  1937. * response iocb. This function is called with the hbalock held.
  1938. * This function returns the command iocb object if it finds the command
  1939. * iocb else returns NULL.
  1940. **/
  1941. static struct lpfc_iocbq *
  1942. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1943. struct lpfc_sli_ring *pring,
  1944. struct lpfc_iocbq *prspiocb)
  1945. {
  1946. struct lpfc_iocbq *cmd_iocb = NULL;
  1947. uint16_t iotag;
  1948. iotag = prspiocb->iocb.ulpIoTag;
  1949. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1950. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1951. list_del_init(&cmd_iocb->list);
  1952. pring->txcmplq_cnt--;
  1953. return cmd_iocb;
  1954. }
  1955. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1956. "0317 iotag x%x is out off "
  1957. "range: max iotag x%x wd0 x%x\n",
  1958. iotag, phba->sli.last_iotag,
  1959. *(((uint32_t *) &prspiocb->iocb) + 7));
  1960. return NULL;
  1961. }
  1962. /**
  1963. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  1964. * @phba: Pointer to HBA context object.
  1965. * @pring: Pointer to driver SLI ring object.
  1966. * @iotag: IOCB tag.
  1967. *
  1968. * This function looks up the iocb_lookup table to get the command iocb
  1969. * corresponding to the given iotag. This function is called with the
  1970. * hbalock held.
  1971. * This function returns the command iocb object if it finds the command
  1972. * iocb else returns NULL.
  1973. **/
  1974. static struct lpfc_iocbq *
  1975. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  1976. struct lpfc_sli_ring *pring, uint16_t iotag)
  1977. {
  1978. struct lpfc_iocbq *cmd_iocb;
  1979. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1980. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1981. list_del_init(&cmd_iocb->list);
  1982. pring->txcmplq_cnt--;
  1983. return cmd_iocb;
  1984. }
  1985. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1986. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  1987. iotag, phba->sli.last_iotag);
  1988. return NULL;
  1989. }
  1990. /**
  1991. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  1992. * @phba: Pointer to HBA context object.
  1993. * @pring: Pointer to driver SLI ring object.
  1994. * @saveq: Pointer to the response iocb to be processed.
  1995. *
  1996. * This function is called by the ring event handler for non-fcp
  1997. * rings when there is a new response iocb in the response ring.
  1998. * The caller is not required to hold any locks. This function
  1999. * gets the command iocb associated with the response iocb and
  2000. * calls the completion handler for the command iocb. If there
  2001. * is no completion handler, the function will free the resources
  2002. * associated with command iocb. If the response iocb is for
  2003. * an already aborted command iocb, the status of the completion
  2004. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2005. * This function always returns 1.
  2006. **/
  2007. static int
  2008. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2009. struct lpfc_iocbq *saveq)
  2010. {
  2011. struct lpfc_iocbq *cmdiocbp;
  2012. int rc = 1;
  2013. unsigned long iflag;
  2014. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2015. spin_lock_irqsave(&phba->hbalock, iflag);
  2016. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2017. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2018. if (cmdiocbp) {
  2019. if (cmdiocbp->iocb_cmpl) {
  2020. /*
  2021. * If an ELS command failed send an event to mgmt
  2022. * application.
  2023. */
  2024. if (saveq->iocb.ulpStatus &&
  2025. (pring->ringno == LPFC_ELS_RING) &&
  2026. (cmdiocbp->iocb.ulpCommand ==
  2027. CMD_ELS_REQUEST64_CR))
  2028. lpfc_send_els_failure_event(phba,
  2029. cmdiocbp, saveq);
  2030. /*
  2031. * Post all ELS completions to the worker thread.
  2032. * All other are passed to the completion callback.
  2033. */
  2034. if (pring->ringno == LPFC_ELS_RING) {
  2035. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  2036. cmdiocbp->iocb_flag &=
  2037. ~LPFC_DRIVER_ABORTED;
  2038. saveq->iocb.ulpStatus =
  2039. IOSTAT_LOCAL_REJECT;
  2040. saveq->iocb.un.ulpWord[4] =
  2041. IOERR_SLI_ABORTED;
  2042. /* Firmware could still be in progress
  2043. * of DMAing payload, so don't free data
  2044. * buffer till after a hbeat.
  2045. */
  2046. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2047. }
  2048. }
  2049. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2050. } else
  2051. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2052. } else {
  2053. /*
  2054. * Unknown initiating command based on the response iotag.
  2055. * This could be the case on the ELS ring because of
  2056. * lpfc_els_abort().
  2057. */
  2058. if (pring->ringno != LPFC_ELS_RING) {
  2059. /*
  2060. * Ring <ringno> handler: unexpected completion IoTag
  2061. * <IoTag>
  2062. */
  2063. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2064. "0322 Ring %d handler: "
  2065. "unexpected completion IoTag x%x "
  2066. "Data: x%x x%x x%x x%x\n",
  2067. pring->ringno,
  2068. saveq->iocb.ulpIoTag,
  2069. saveq->iocb.ulpStatus,
  2070. saveq->iocb.un.ulpWord[4],
  2071. saveq->iocb.ulpCommand,
  2072. saveq->iocb.ulpContext);
  2073. }
  2074. }
  2075. return rc;
  2076. }
  2077. /**
  2078. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2079. * @phba: Pointer to HBA context object.
  2080. * @pring: Pointer to driver SLI ring object.
  2081. *
  2082. * This function is called from the iocb ring event handlers when
  2083. * put pointer is ahead of the get pointer for a ring. This function signal
  2084. * an error attention condition to the worker thread and the worker
  2085. * thread will transition the HBA to offline state.
  2086. **/
  2087. static void
  2088. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2089. {
  2090. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2091. /*
  2092. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2093. * rsp ring <portRspMax>
  2094. */
  2095. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2096. "0312 Ring %d handler: portRspPut %d "
  2097. "is bigger than rsp ring %d\n",
  2098. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2099. pring->numRiocb);
  2100. phba->link_state = LPFC_HBA_ERROR;
  2101. /*
  2102. * All error attention handlers are posted to
  2103. * worker thread
  2104. */
  2105. phba->work_ha |= HA_ERATT;
  2106. phba->work_hs = HS_FFER3;
  2107. lpfc_worker_wake_up(phba);
  2108. return;
  2109. }
  2110. /**
  2111. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2112. * @ptr: Pointer to address of HBA context object.
  2113. *
  2114. * This function is invoked by the Error Attention polling timer when the
  2115. * timer times out. It will check the SLI Error Attention register for
  2116. * possible attention events. If so, it will post an Error Attention event
  2117. * and wake up worker thread to process it. Otherwise, it will set up the
  2118. * Error Attention polling timer for the next poll.
  2119. **/
  2120. void lpfc_poll_eratt(unsigned long ptr)
  2121. {
  2122. struct lpfc_hba *phba;
  2123. uint32_t eratt = 0;
  2124. phba = (struct lpfc_hba *)ptr;
  2125. /* Check chip HA register for error event */
  2126. eratt = lpfc_sli_check_eratt(phba);
  2127. if (eratt)
  2128. /* Tell the worker thread there is work to do */
  2129. lpfc_worker_wake_up(phba);
  2130. else
  2131. /* Restart the timer for next eratt poll */
  2132. mod_timer(&phba->eratt_poll, jiffies +
  2133. HZ * LPFC_ERATT_POLL_INTERVAL);
  2134. return;
  2135. }
  2136. /**
  2137. * lpfc_sli_poll_fcp_ring - Handle FCP ring completion in polling mode
  2138. * @phba: Pointer to HBA context object.
  2139. *
  2140. * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
  2141. * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
  2142. * is enabled.
  2143. *
  2144. * The caller does not hold any lock.
  2145. * The function processes each response iocb in the response ring until it
  2146. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2147. * LE bit set. The function will call the completion handler of the command iocb
  2148. * if the response iocb indicates a completion for a command iocb or it is
  2149. * an abort completion.
  2150. **/
  2151. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  2152. {
  2153. struct lpfc_sli *psli = &phba->sli;
  2154. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  2155. IOCB_t *irsp = NULL;
  2156. IOCB_t *entry = NULL;
  2157. struct lpfc_iocbq *cmdiocbq = NULL;
  2158. struct lpfc_iocbq rspiocbq;
  2159. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2160. uint32_t status;
  2161. uint32_t portRspPut, portRspMax;
  2162. int type;
  2163. uint32_t rsp_cmpl = 0;
  2164. uint32_t ha_copy;
  2165. unsigned long iflags;
  2166. pring->stats.iocb_event++;
  2167. /*
  2168. * The next available response entry should never exceed the maximum
  2169. * entries. If it does, treat it as an adapter hardware error.
  2170. */
  2171. portRspMax = pring->numRiocb;
  2172. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2173. if (unlikely(portRspPut >= portRspMax)) {
  2174. lpfc_sli_rsp_pointers_error(phba, pring);
  2175. return;
  2176. }
  2177. rmb();
  2178. while (pring->rspidx != portRspPut) {
  2179. entry = lpfc_resp_iocb(phba, pring);
  2180. if (++pring->rspidx >= portRspMax)
  2181. pring->rspidx = 0;
  2182. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2183. (uint32_t *) &rspiocbq.iocb,
  2184. phba->iocb_rsp_size);
  2185. irsp = &rspiocbq.iocb;
  2186. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2187. pring->stats.iocb_rsp++;
  2188. rsp_cmpl++;
  2189. if (unlikely(irsp->ulpStatus)) {
  2190. /* Rsp ring <ringno> error: IOCB */
  2191. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2192. "0326 Rsp Ring %d error: IOCB Data: "
  2193. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2194. pring->ringno,
  2195. irsp->un.ulpWord[0],
  2196. irsp->un.ulpWord[1],
  2197. irsp->un.ulpWord[2],
  2198. irsp->un.ulpWord[3],
  2199. irsp->un.ulpWord[4],
  2200. irsp->un.ulpWord[5],
  2201. *(uint32_t *)&irsp->un1,
  2202. *((uint32_t *)&irsp->un1 + 1));
  2203. }
  2204. switch (type) {
  2205. case LPFC_ABORT_IOCB:
  2206. case LPFC_SOL_IOCB:
  2207. /*
  2208. * Idle exchange closed via ABTS from port. No iocb
  2209. * resources need to be recovered.
  2210. */
  2211. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2212. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2213. "0314 IOCB cmd 0x%x "
  2214. "processed. Skipping "
  2215. "completion",
  2216. irsp->ulpCommand);
  2217. break;
  2218. }
  2219. spin_lock_irqsave(&phba->hbalock, iflags);
  2220. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2221. &rspiocbq);
  2222. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2223. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2224. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2225. &rspiocbq);
  2226. }
  2227. break;
  2228. default:
  2229. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2230. char adaptermsg[LPFC_MAX_ADPTMSG];
  2231. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2232. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2233. MAX_MSG_DATA);
  2234. dev_warn(&((phba->pcidev)->dev),
  2235. "lpfc%d: %s\n",
  2236. phba->brd_no, adaptermsg);
  2237. } else {
  2238. /* Unknown IOCB command */
  2239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2240. "0321 Unknown IOCB command "
  2241. "Data: x%x, x%x x%x x%x x%x\n",
  2242. type, irsp->ulpCommand,
  2243. irsp->ulpStatus,
  2244. irsp->ulpIoTag,
  2245. irsp->ulpContext);
  2246. }
  2247. break;
  2248. }
  2249. /*
  2250. * The response IOCB has been processed. Update the ring
  2251. * pointer in SLIM. If the port response put pointer has not
  2252. * been updated, sync the pgp->rspPutInx and fetch the new port
  2253. * response put pointer.
  2254. */
  2255. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2256. if (pring->rspidx == portRspPut)
  2257. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2258. }
  2259. ha_copy = readl(phba->HAregaddr);
  2260. ha_copy >>= (LPFC_FCP_RING * 4);
  2261. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  2262. spin_lock_irqsave(&phba->hbalock, iflags);
  2263. pring->stats.iocb_rsp_full++;
  2264. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  2265. writel(status, phba->CAregaddr);
  2266. readl(phba->CAregaddr);
  2267. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2268. }
  2269. if ((ha_copy & HA_R0CE_RSP) &&
  2270. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2271. spin_lock_irqsave(&phba->hbalock, iflags);
  2272. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2273. pring->stats.iocb_cmd_empty++;
  2274. /* Force update of the local copy of cmdGetInx */
  2275. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2276. lpfc_sli_resume_iocb(phba, pring);
  2277. if ((pring->lpfc_sli_cmd_available))
  2278. (pring->lpfc_sli_cmd_available) (phba, pring);
  2279. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2280. }
  2281. return;
  2282. }
  2283. /**
  2284. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2285. * @phba: Pointer to HBA context object.
  2286. * @pring: Pointer to driver SLI ring object.
  2287. * @mask: Host attention register mask for this ring.
  2288. *
  2289. * This function is called from the interrupt context when there is a ring
  2290. * event for the fcp ring. The caller does not hold any lock.
  2291. * The function processes each response iocb in the response ring until it
  2292. * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
  2293. * LE bit set. The function will call the completion handler of the command iocb
  2294. * if the response iocb indicates a completion for a command iocb or it is
  2295. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2296. * function if this is an unsolicited iocb.
  2297. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2298. * to check it explicitly. This function always returns 1.
  2299. **/
  2300. static int
  2301. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2302. struct lpfc_sli_ring *pring, uint32_t mask)
  2303. {
  2304. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2305. IOCB_t *irsp = NULL;
  2306. IOCB_t *entry = NULL;
  2307. struct lpfc_iocbq *cmdiocbq = NULL;
  2308. struct lpfc_iocbq rspiocbq;
  2309. uint32_t status;
  2310. uint32_t portRspPut, portRspMax;
  2311. int rc = 1;
  2312. lpfc_iocb_type type;
  2313. unsigned long iflag;
  2314. uint32_t rsp_cmpl = 0;
  2315. spin_lock_irqsave(&phba->hbalock, iflag);
  2316. pring->stats.iocb_event++;
  2317. /*
  2318. * The next available response entry should never exceed the maximum
  2319. * entries. If it does, treat it as an adapter hardware error.
  2320. */
  2321. portRspMax = pring->numRiocb;
  2322. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2323. if (unlikely(portRspPut >= portRspMax)) {
  2324. lpfc_sli_rsp_pointers_error(phba, pring);
  2325. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2326. return 1;
  2327. }
  2328. rmb();
  2329. while (pring->rspidx != portRspPut) {
  2330. /*
  2331. * Fetch an entry off the ring and copy it into a local data
  2332. * structure. The copy involves a byte-swap since the
  2333. * network byte order and pci byte orders are different.
  2334. */
  2335. entry = lpfc_resp_iocb(phba, pring);
  2336. phba->last_completion_time = jiffies;
  2337. if (++pring->rspidx >= portRspMax)
  2338. pring->rspidx = 0;
  2339. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2340. (uint32_t *) &rspiocbq.iocb,
  2341. phba->iocb_rsp_size);
  2342. INIT_LIST_HEAD(&(rspiocbq.list));
  2343. irsp = &rspiocbq.iocb;
  2344. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2345. pring->stats.iocb_rsp++;
  2346. rsp_cmpl++;
  2347. if (unlikely(irsp->ulpStatus)) {
  2348. /*
  2349. * If resource errors reported from HBA, reduce
  2350. * queuedepths of the SCSI device.
  2351. */
  2352. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2353. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2354. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2355. phba->lpfc_rampdown_queue_depth(phba);
  2356. spin_lock_irqsave(&phba->hbalock, iflag);
  2357. }
  2358. /* Rsp ring <ringno> error: IOCB */
  2359. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2360. "0336 Rsp Ring %d error: IOCB Data: "
  2361. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2362. pring->ringno,
  2363. irsp->un.ulpWord[0],
  2364. irsp->un.ulpWord[1],
  2365. irsp->un.ulpWord[2],
  2366. irsp->un.ulpWord[3],
  2367. irsp->un.ulpWord[4],
  2368. irsp->un.ulpWord[5],
  2369. *(uint32_t *)&irsp->un1,
  2370. *((uint32_t *)&irsp->un1 + 1));
  2371. }
  2372. switch (type) {
  2373. case LPFC_ABORT_IOCB:
  2374. case LPFC_SOL_IOCB:
  2375. /*
  2376. * Idle exchange closed via ABTS from port. No iocb
  2377. * resources need to be recovered.
  2378. */
  2379. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2380. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2381. "0333 IOCB cmd 0x%x"
  2382. " processed. Skipping"
  2383. " completion\n",
  2384. irsp->ulpCommand);
  2385. break;
  2386. }
  2387. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2388. &rspiocbq);
  2389. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  2390. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2391. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2392. &rspiocbq);
  2393. } else {
  2394. spin_unlock_irqrestore(&phba->hbalock,
  2395. iflag);
  2396. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2397. &rspiocbq);
  2398. spin_lock_irqsave(&phba->hbalock,
  2399. iflag);
  2400. }
  2401. }
  2402. break;
  2403. case LPFC_UNSOL_IOCB:
  2404. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2405. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2406. spin_lock_irqsave(&phba->hbalock, iflag);
  2407. break;
  2408. default:
  2409. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2410. char adaptermsg[LPFC_MAX_ADPTMSG];
  2411. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2412. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2413. MAX_MSG_DATA);
  2414. dev_warn(&((phba->pcidev)->dev),
  2415. "lpfc%d: %s\n",
  2416. phba->brd_no, adaptermsg);
  2417. } else {
  2418. /* Unknown IOCB command */
  2419. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2420. "0334 Unknown IOCB command "
  2421. "Data: x%x, x%x x%x x%x x%x\n",
  2422. type, irsp->ulpCommand,
  2423. irsp->ulpStatus,
  2424. irsp->ulpIoTag,
  2425. irsp->ulpContext);
  2426. }
  2427. break;
  2428. }
  2429. /*
  2430. * The response IOCB has been processed. Update the ring
  2431. * pointer in SLIM. If the port response put pointer has not
  2432. * been updated, sync the pgp->rspPutInx and fetch the new port
  2433. * response put pointer.
  2434. */
  2435. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2436. if (pring->rspidx == portRspPut)
  2437. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2438. }
  2439. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2440. pring->stats.iocb_rsp_full++;
  2441. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2442. writel(status, phba->CAregaddr);
  2443. readl(phba->CAregaddr);
  2444. }
  2445. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2446. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2447. pring->stats.iocb_cmd_empty++;
  2448. /* Force update of the local copy of cmdGetInx */
  2449. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2450. lpfc_sli_resume_iocb(phba, pring);
  2451. if ((pring->lpfc_sli_cmd_available))
  2452. (pring->lpfc_sli_cmd_available) (phba, pring);
  2453. }
  2454. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2455. return rc;
  2456. }
  2457. /**
  2458. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2459. * @phba: Pointer to HBA context object.
  2460. * @pring: Pointer to driver SLI ring object.
  2461. * @rspiocbp: Pointer to driver response IOCB object.
  2462. *
  2463. * This function is called from the worker thread when there is a slow-path
  2464. * response IOCB to process. This function chains all the response iocbs until
  2465. * seeing the iocb with the LE bit set. The function will call
  2466. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2467. * completion of a command iocb. The function will call the
  2468. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2469. * The function frees the resources or calls the completion handler if this
  2470. * iocb is an abort completion. The function returns NULL when the response
  2471. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2472. * this function shall chain the iocb on to the iocb_continueq and return the
  2473. * response iocb passed in.
  2474. **/
  2475. static struct lpfc_iocbq *
  2476. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2477. struct lpfc_iocbq *rspiocbp)
  2478. {
  2479. struct lpfc_iocbq *saveq;
  2480. struct lpfc_iocbq *cmdiocbp;
  2481. struct lpfc_iocbq *next_iocb;
  2482. IOCB_t *irsp = NULL;
  2483. uint32_t free_saveq;
  2484. uint8_t iocb_cmd_type;
  2485. lpfc_iocb_type type;
  2486. unsigned long iflag;
  2487. int rc;
  2488. spin_lock_irqsave(&phba->hbalock, iflag);
  2489. /* First add the response iocb to the countinueq list */
  2490. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2491. pring->iocb_continueq_cnt++;
  2492. /* Now, determine whetehr the list is completed for processing */
  2493. irsp = &rspiocbp->iocb;
  2494. if (irsp->ulpLe) {
  2495. /*
  2496. * By default, the driver expects to free all resources
  2497. * associated with this iocb completion.
  2498. */
  2499. free_saveq = 1;
  2500. saveq = list_get_first(&pring->iocb_continueq,
  2501. struct lpfc_iocbq, list);
  2502. irsp = &(saveq->iocb);
  2503. list_del_init(&pring->iocb_continueq);
  2504. pring->iocb_continueq_cnt = 0;
  2505. pring->stats.iocb_rsp++;
  2506. /*
  2507. * If resource errors reported from HBA, reduce
  2508. * queuedepths of the SCSI device.
  2509. */
  2510. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2511. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2512. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2513. phba->lpfc_rampdown_queue_depth(phba);
  2514. spin_lock_irqsave(&phba->hbalock, iflag);
  2515. }
  2516. if (irsp->ulpStatus) {
  2517. /* Rsp ring <ringno> error: IOCB */
  2518. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2519. "0328 Rsp Ring %d error: "
  2520. "IOCB Data: "
  2521. "x%x x%x x%x x%x "
  2522. "x%x x%x x%x x%x "
  2523. "x%x x%x x%x x%x "
  2524. "x%x x%x x%x x%x\n",
  2525. pring->ringno,
  2526. irsp->un.ulpWord[0],
  2527. irsp->un.ulpWord[1],
  2528. irsp->un.ulpWord[2],
  2529. irsp->un.ulpWord[3],
  2530. irsp->un.ulpWord[4],
  2531. irsp->un.ulpWord[5],
  2532. *(((uint32_t *) irsp) + 6),
  2533. *(((uint32_t *) irsp) + 7),
  2534. *(((uint32_t *) irsp) + 8),
  2535. *(((uint32_t *) irsp) + 9),
  2536. *(((uint32_t *) irsp) + 10),
  2537. *(((uint32_t *) irsp) + 11),
  2538. *(((uint32_t *) irsp) + 12),
  2539. *(((uint32_t *) irsp) + 13),
  2540. *(((uint32_t *) irsp) + 14),
  2541. *(((uint32_t *) irsp) + 15));
  2542. }
  2543. /*
  2544. * Fetch the IOCB command type and call the correct completion
  2545. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2546. * get freed back to the lpfc_iocb_list by the discovery
  2547. * kernel thread.
  2548. */
  2549. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2550. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2551. switch (type) {
  2552. case LPFC_SOL_IOCB:
  2553. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2554. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2555. spin_lock_irqsave(&phba->hbalock, iflag);
  2556. break;
  2557. case LPFC_UNSOL_IOCB:
  2558. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2559. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2560. spin_lock_irqsave(&phba->hbalock, iflag);
  2561. if (!rc)
  2562. free_saveq = 0;
  2563. break;
  2564. case LPFC_ABORT_IOCB:
  2565. cmdiocbp = NULL;
  2566. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2567. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2568. saveq);
  2569. if (cmdiocbp) {
  2570. /* Call the specified completion routine */
  2571. if (cmdiocbp->iocb_cmpl) {
  2572. spin_unlock_irqrestore(&phba->hbalock,
  2573. iflag);
  2574. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2575. saveq);
  2576. spin_lock_irqsave(&phba->hbalock,
  2577. iflag);
  2578. } else
  2579. __lpfc_sli_release_iocbq(phba,
  2580. cmdiocbp);
  2581. }
  2582. break;
  2583. case LPFC_UNKNOWN_IOCB:
  2584. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2585. char adaptermsg[LPFC_MAX_ADPTMSG];
  2586. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2587. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2588. MAX_MSG_DATA);
  2589. dev_warn(&((phba->pcidev)->dev),
  2590. "lpfc%d: %s\n",
  2591. phba->brd_no, adaptermsg);
  2592. } else {
  2593. /* Unknown IOCB command */
  2594. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2595. "0335 Unknown IOCB "
  2596. "command Data: x%x "
  2597. "x%x x%x x%x\n",
  2598. irsp->ulpCommand,
  2599. irsp->ulpStatus,
  2600. irsp->ulpIoTag,
  2601. irsp->ulpContext);
  2602. }
  2603. break;
  2604. }
  2605. if (free_saveq) {
  2606. list_for_each_entry_safe(rspiocbp, next_iocb,
  2607. &saveq->list, list) {
  2608. list_del(&rspiocbp->list);
  2609. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2610. }
  2611. __lpfc_sli_release_iocbq(phba, saveq);
  2612. }
  2613. rspiocbp = NULL;
  2614. }
  2615. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2616. return rspiocbp;
  2617. }
  2618. /**
  2619. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2620. * @phba: Pointer to HBA context object.
  2621. * @pring: Pointer to driver SLI ring object.
  2622. * @mask: Host attention register mask for this ring.
  2623. *
  2624. * This routine wraps the actual slow_ring event process routine from the
  2625. * API jump table function pointer from the lpfc_hba struct.
  2626. **/
  2627. void
  2628. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2629. struct lpfc_sli_ring *pring, uint32_t mask)
  2630. {
  2631. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2632. }
  2633. /**
  2634. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2635. * @phba: Pointer to HBA context object.
  2636. * @pring: Pointer to driver SLI ring object.
  2637. * @mask: Host attention register mask for this ring.
  2638. *
  2639. * This function is called from the worker thread when there is a ring event
  2640. * for non-fcp rings. The caller does not hold any lock. The function will
  2641. * remove each response iocb in the response ring and calls the handle
  2642. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2643. **/
  2644. static void
  2645. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2646. struct lpfc_sli_ring *pring, uint32_t mask)
  2647. {
  2648. struct lpfc_pgp *pgp;
  2649. IOCB_t *entry;
  2650. IOCB_t *irsp = NULL;
  2651. struct lpfc_iocbq *rspiocbp = NULL;
  2652. uint32_t portRspPut, portRspMax;
  2653. unsigned long iflag;
  2654. uint32_t status;
  2655. pgp = &phba->port_gp[pring->ringno];
  2656. spin_lock_irqsave(&phba->hbalock, iflag);
  2657. pring->stats.iocb_event++;
  2658. /*
  2659. * The next available response entry should never exceed the maximum
  2660. * entries. If it does, treat it as an adapter hardware error.
  2661. */
  2662. portRspMax = pring->numRiocb;
  2663. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2664. if (portRspPut >= portRspMax) {
  2665. /*
  2666. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2667. * rsp ring <portRspMax>
  2668. */
  2669. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2670. "0303 Ring %d handler: portRspPut %d "
  2671. "is bigger than rsp ring %d\n",
  2672. pring->ringno, portRspPut, portRspMax);
  2673. phba->link_state = LPFC_HBA_ERROR;
  2674. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2675. phba->work_hs = HS_FFER3;
  2676. lpfc_handle_eratt(phba);
  2677. return;
  2678. }
  2679. rmb();
  2680. while (pring->rspidx != portRspPut) {
  2681. /*
  2682. * Build a completion list and call the appropriate handler.
  2683. * The process is to get the next available response iocb, get
  2684. * a free iocb from the list, copy the response data into the
  2685. * free iocb, insert to the continuation list, and update the
  2686. * next response index to slim. This process makes response
  2687. * iocb's in the ring available to DMA as fast as possible but
  2688. * pays a penalty for a copy operation. Since the iocb is
  2689. * only 32 bytes, this penalty is considered small relative to
  2690. * the PCI reads for register values and a slim write. When
  2691. * the ulpLe field is set, the entire Command has been
  2692. * received.
  2693. */
  2694. entry = lpfc_resp_iocb(phba, pring);
  2695. phba->last_completion_time = jiffies;
  2696. rspiocbp = __lpfc_sli_get_iocbq(phba);
  2697. if (rspiocbp == NULL) {
  2698. printk(KERN_ERR "%s: out of buffers! Failing "
  2699. "completion.\n", __func__);
  2700. break;
  2701. }
  2702. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  2703. phba->iocb_rsp_size);
  2704. irsp = &rspiocbp->iocb;
  2705. if (++pring->rspidx >= portRspMax)
  2706. pring->rspidx = 0;
  2707. if (pring->ringno == LPFC_ELS_RING) {
  2708. lpfc_debugfs_slow_ring_trc(phba,
  2709. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  2710. *(((uint32_t *) irsp) + 4),
  2711. *(((uint32_t *) irsp) + 6),
  2712. *(((uint32_t *) irsp) + 7));
  2713. }
  2714. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2715. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2716. /* Handle the response IOCB */
  2717. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  2718. spin_lock_irqsave(&phba->hbalock, iflag);
  2719. /*
  2720. * If the port response put pointer has not been updated, sync
  2721. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  2722. * response put pointer.
  2723. */
  2724. if (pring->rspidx == portRspPut) {
  2725. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2726. }
  2727. } /* while (pring->rspidx != portRspPut) */
  2728. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  2729. /* At least one response entry has been freed */
  2730. pring->stats.iocb_rsp_full++;
  2731. /* SET RxRE_RSP in Chip Att register */
  2732. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2733. writel(status, phba->CAregaddr);
  2734. readl(phba->CAregaddr); /* flush */
  2735. }
  2736. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2737. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2738. pring->stats.iocb_cmd_empty++;
  2739. /* Force update of the local copy of cmdGetInx */
  2740. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2741. lpfc_sli_resume_iocb(phba, pring);
  2742. if ((pring->lpfc_sli_cmd_available))
  2743. (pring->lpfc_sli_cmd_available) (phba, pring);
  2744. }
  2745. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2746. return;
  2747. }
  2748. /**
  2749. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  2750. * @phba: Pointer to HBA context object.
  2751. * @pring: Pointer to driver SLI ring object.
  2752. * @mask: Host attention register mask for this ring.
  2753. *
  2754. * This function is called from the worker thread when there is a pending
  2755. * ELS response iocb on the driver internal slow-path response iocb worker
  2756. * queue. The caller does not hold any lock. The function will remove each
  2757. * response iocb from the response worker queue and calls the handle
  2758. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2759. **/
  2760. static void
  2761. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  2762. struct lpfc_sli_ring *pring, uint32_t mask)
  2763. {
  2764. struct lpfc_iocbq *irspiocbq;
  2765. unsigned long iflag;
  2766. while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) {
  2767. /* Get the response iocb from the head of work queue */
  2768. spin_lock_irqsave(&phba->hbalock, iflag);
  2769. list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue,
  2770. irspiocbq, struct lpfc_iocbq, list);
  2771. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2772. /* Process the response iocb */
  2773. lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq);
  2774. }
  2775. }
  2776. /**
  2777. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  2778. * @phba: Pointer to HBA context object.
  2779. * @pring: Pointer to driver SLI ring object.
  2780. *
  2781. * This function aborts all iocbs in the given ring and frees all the iocb
  2782. * objects in txq. This function issues an abort iocb for all the iocb commands
  2783. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  2784. * the return of this function. The caller is not required to hold any locks.
  2785. **/
  2786. void
  2787. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2788. {
  2789. LIST_HEAD(completions);
  2790. struct lpfc_iocbq *iocb, *next_iocb;
  2791. if (pring->ringno == LPFC_ELS_RING) {
  2792. lpfc_fabric_abort_hba(phba);
  2793. }
  2794. /* Error everything on txq and txcmplq
  2795. * First do the txq.
  2796. */
  2797. spin_lock_irq(&phba->hbalock);
  2798. list_splice_init(&pring->txq, &completions);
  2799. pring->txq_cnt = 0;
  2800. /* Next issue ABTS for everything on the txcmplq */
  2801. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  2802. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2803. spin_unlock_irq(&phba->hbalock);
  2804. /* Cancel all the IOCBs from the completions list */
  2805. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2806. IOERR_SLI_ABORTED);
  2807. }
  2808. /**
  2809. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  2810. * @phba: Pointer to HBA context object.
  2811. *
  2812. * This function flushes all iocbs in the fcp ring and frees all the iocb
  2813. * objects in txq and txcmplq. This function will not issue abort iocbs
  2814. * for all the iocb commands in txcmplq, they will just be returned with
  2815. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  2816. * slot has been permanently disabled.
  2817. **/
  2818. void
  2819. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  2820. {
  2821. LIST_HEAD(txq);
  2822. LIST_HEAD(txcmplq);
  2823. struct lpfc_sli *psli = &phba->sli;
  2824. struct lpfc_sli_ring *pring;
  2825. /* Currently, only one fcp ring */
  2826. pring = &psli->ring[psli->fcp_ring];
  2827. spin_lock_irq(&phba->hbalock);
  2828. /* Retrieve everything on txq */
  2829. list_splice_init(&pring->txq, &txq);
  2830. pring->txq_cnt = 0;
  2831. /* Retrieve everything on the txcmplq */
  2832. list_splice_init(&pring->txcmplq, &txcmplq);
  2833. pring->txcmplq_cnt = 0;
  2834. spin_unlock_irq(&phba->hbalock);
  2835. /* Flush the txq */
  2836. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  2837. IOERR_SLI_DOWN);
  2838. /* Flush the txcmpq */
  2839. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  2840. IOERR_SLI_DOWN);
  2841. }
  2842. /**
  2843. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  2844. * @phba: Pointer to HBA context object.
  2845. * @mask: Bit mask to be checked.
  2846. *
  2847. * This function reads the host status register and compares
  2848. * with the provided bit mask to check if HBA completed
  2849. * the restart. This function will wait in a loop for the
  2850. * HBA to complete restart. If the HBA does not restart within
  2851. * 15 iterations, the function will reset the HBA again. The
  2852. * function returns 1 when HBA fail to restart otherwise returns
  2853. * zero.
  2854. **/
  2855. static int
  2856. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  2857. {
  2858. uint32_t status;
  2859. int i = 0;
  2860. int retval = 0;
  2861. /* Read the HBA Host Status Register */
  2862. status = readl(phba->HSregaddr);
  2863. /*
  2864. * Check status register every 100ms for 5 retries, then every
  2865. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  2866. * every 2.5 sec for 4.
  2867. * Break our of the loop if errors occurred during init.
  2868. */
  2869. while (((status & mask) != mask) &&
  2870. !(status & HS_FFERM) &&
  2871. i++ < 20) {
  2872. if (i <= 5)
  2873. msleep(10);
  2874. else if (i <= 10)
  2875. msleep(500);
  2876. else
  2877. msleep(2500);
  2878. if (i == 15) {
  2879. /* Do post */
  2880. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2881. lpfc_sli_brdrestart(phba);
  2882. }
  2883. /* Read the HBA Host Status Register */
  2884. status = readl(phba->HSregaddr);
  2885. }
  2886. /* Check to see if any errors occurred during init */
  2887. if ((status & HS_FFERM) || (i >= 20)) {
  2888. phba->link_state = LPFC_HBA_ERROR;
  2889. retval = 1;
  2890. }
  2891. return retval;
  2892. }
  2893. /**
  2894. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  2895. * @phba: Pointer to HBA context object.
  2896. * @mask: Bit mask to be checked.
  2897. *
  2898. * This function checks the host status register to check if HBA is
  2899. * ready. This function will wait in a loop for the HBA to be ready
  2900. * If the HBA is not ready , the function will will reset the HBA PCI
  2901. * function again. The function returns 1 when HBA fail to be ready
  2902. * otherwise returns zero.
  2903. **/
  2904. static int
  2905. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  2906. {
  2907. uint32_t status;
  2908. int retval = 0;
  2909. /* Read the HBA Host Status Register */
  2910. status = lpfc_sli4_post_status_check(phba);
  2911. if (status) {
  2912. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2913. lpfc_sli_brdrestart(phba);
  2914. status = lpfc_sli4_post_status_check(phba);
  2915. }
  2916. /* Check to see if any errors occurred during init */
  2917. if (status) {
  2918. phba->link_state = LPFC_HBA_ERROR;
  2919. retval = 1;
  2920. } else
  2921. phba->sli4_hba.intr_enable = 0;
  2922. return retval;
  2923. }
  2924. /**
  2925. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  2926. * @phba: Pointer to HBA context object.
  2927. * @mask: Bit mask to be checked.
  2928. *
  2929. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  2930. * from the API jump table function pointer from the lpfc_hba struct.
  2931. **/
  2932. int
  2933. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  2934. {
  2935. return phba->lpfc_sli_brdready(phba, mask);
  2936. }
  2937. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  2938. /**
  2939. * lpfc_reset_barrier - Make HBA ready for HBA reset
  2940. * @phba: Pointer to HBA context object.
  2941. *
  2942. * This function is called before resetting an HBA. This
  2943. * function requests HBA to quiesce DMAs before a reset.
  2944. **/
  2945. void lpfc_reset_barrier(struct lpfc_hba *phba)
  2946. {
  2947. uint32_t __iomem *resp_buf;
  2948. uint32_t __iomem *mbox_buf;
  2949. volatile uint32_t mbox;
  2950. uint32_t hc_copy;
  2951. int i;
  2952. uint8_t hdrtype;
  2953. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  2954. if (hdrtype != 0x80 ||
  2955. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  2956. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  2957. return;
  2958. /*
  2959. * Tell the other part of the chip to suspend temporarily all
  2960. * its DMA activity.
  2961. */
  2962. resp_buf = phba->MBslimaddr;
  2963. /* Disable the error attention */
  2964. hc_copy = readl(phba->HCregaddr);
  2965. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  2966. readl(phba->HCregaddr); /* flush */
  2967. phba->link_flag |= LS_IGNORE_ERATT;
  2968. if (readl(phba->HAregaddr) & HA_ERATT) {
  2969. /* Clear Chip error bit */
  2970. writel(HA_ERATT, phba->HAregaddr);
  2971. phba->pport->stopped = 1;
  2972. }
  2973. mbox = 0;
  2974. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  2975. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  2976. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  2977. mbox_buf = phba->MBslimaddr;
  2978. writel(mbox, mbox_buf);
  2979. for (i = 0;
  2980. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  2981. mdelay(1);
  2982. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  2983. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  2984. phba->pport->stopped)
  2985. goto restore_hc;
  2986. else
  2987. goto clear_errat;
  2988. }
  2989. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  2990. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  2991. mdelay(1);
  2992. clear_errat:
  2993. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  2994. mdelay(1);
  2995. if (readl(phba->HAregaddr) & HA_ERATT) {
  2996. writel(HA_ERATT, phba->HAregaddr);
  2997. phba->pport->stopped = 1;
  2998. }
  2999. restore_hc:
  3000. phba->link_flag &= ~LS_IGNORE_ERATT;
  3001. writel(hc_copy, phba->HCregaddr);
  3002. readl(phba->HCregaddr); /* flush */
  3003. }
  3004. /**
  3005. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3006. * @phba: Pointer to HBA context object.
  3007. *
  3008. * This function issues a kill_board mailbox command and waits for
  3009. * the error attention interrupt. This function is called for stopping
  3010. * the firmware processing. The caller is not required to hold any
  3011. * locks. This function calls lpfc_hba_down_post function to free
  3012. * any pending commands after the kill. The function will return 1 when it
  3013. * fails to kill the board else will return 0.
  3014. **/
  3015. int
  3016. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3017. {
  3018. struct lpfc_sli *psli;
  3019. LPFC_MBOXQ_t *pmb;
  3020. uint32_t status;
  3021. uint32_t ha_copy;
  3022. int retval;
  3023. int i = 0;
  3024. psli = &phba->sli;
  3025. /* Kill HBA */
  3026. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3027. "0329 Kill HBA Data: x%x x%x\n",
  3028. phba->pport->port_state, psli->sli_flag);
  3029. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3030. if (!pmb)
  3031. return 1;
  3032. /* Disable the error attention */
  3033. spin_lock_irq(&phba->hbalock);
  3034. status = readl(phba->HCregaddr);
  3035. status &= ~HC_ERINT_ENA;
  3036. writel(status, phba->HCregaddr);
  3037. readl(phba->HCregaddr); /* flush */
  3038. phba->link_flag |= LS_IGNORE_ERATT;
  3039. spin_unlock_irq(&phba->hbalock);
  3040. lpfc_kill_board(phba, pmb);
  3041. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3042. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3043. if (retval != MBX_SUCCESS) {
  3044. if (retval != MBX_BUSY)
  3045. mempool_free(pmb, phba->mbox_mem_pool);
  3046. spin_lock_irq(&phba->hbalock);
  3047. phba->link_flag &= ~LS_IGNORE_ERATT;
  3048. spin_unlock_irq(&phba->hbalock);
  3049. return 1;
  3050. }
  3051. spin_lock_irq(&phba->hbalock);
  3052. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3053. spin_unlock_irq(&phba->hbalock);
  3054. mempool_free(pmb, phba->mbox_mem_pool);
  3055. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3056. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3057. * 3 seconds we still set HBA_ERROR state because the status of the
  3058. * board is now undefined.
  3059. */
  3060. ha_copy = readl(phba->HAregaddr);
  3061. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3062. mdelay(100);
  3063. ha_copy = readl(phba->HAregaddr);
  3064. }
  3065. del_timer_sync(&psli->mbox_tmo);
  3066. if (ha_copy & HA_ERATT) {
  3067. writel(HA_ERATT, phba->HAregaddr);
  3068. phba->pport->stopped = 1;
  3069. }
  3070. spin_lock_irq(&phba->hbalock);
  3071. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3072. psli->mbox_active = NULL;
  3073. phba->link_flag &= ~LS_IGNORE_ERATT;
  3074. spin_unlock_irq(&phba->hbalock);
  3075. lpfc_hba_down_post(phba);
  3076. phba->link_state = LPFC_HBA_ERROR;
  3077. return ha_copy & HA_ERATT ? 0 : 1;
  3078. }
  3079. /**
  3080. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3081. * @phba: Pointer to HBA context object.
  3082. *
  3083. * This function resets the HBA by writing HC_INITFF to the control
  3084. * register. After the HBA resets, this function resets all the iocb ring
  3085. * indices. This function disables PCI layer parity checking during
  3086. * the reset.
  3087. * This function returns 0 always.
  3088. * The caller is not required to hold any locks.
  3089. **/
  3090. int
  3091. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3092. {
  3093. struct lpfc_sli *psli;
  3094. struct lpfc_sli_ring *pring;
  3095. uint16_t cfg_value;
  3096. int i;
  3097. psli = &phba->sli;
  3098. /* Reset HBA */
  3099. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3100. "0325 Reset HBA Data: x%x x%x\n",
  3101. phba->pport->port_state, psli->sli_flag);
  3102. /* perform board reset */
  3103. phba->fc_eventTag = 0;
  3104. phba->pport->fc_myDID = 0;
  3105. phba->pport->fc_prevDID = 0;
  3106. /* Turn off parity checking and serr during the physical reset */
  3107. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3108. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3109. (cfg_value &
  3110. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3111. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3112. /* Now toggle INITFF bit in the Host Control Register */
  3113. writel(HC_INITFF, phba->HCregaddr);
  3114. mdelay(1);
  3115. readl(phba->HCregaddr); /* flush */
  3116. writel(0, phba->HCregaddr);
  3117. readl(phba->HCregaddr); /* flush */
  3118. /* Restore PCI cmd register */
  3119. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3120. /* Initialize relevant SLI info */
  3121. for (i = 0; i < psli->num_rings; i++) {
  3122. pring = &psli->ring[i];
  3123. pring->flag = 0;
  3124. pring->rspidx = 0;
  3125. pring->next_cmdidx = 0;
  3126. pring->local_getidx = 0;
  3127. pring->cmdidx = 0;
  3128. pring->missbufcnt = 0;
  3129. }
  3130. phba->link_state = LPFC_WARM_START;
  3131. return 0;
  3132. }
  3133. /**
  3134. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3135. * @phba: Pointer to HBA context object.
  3136. *
  3137. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3138. * checking during resets the device. The caller is not required to hold
  3139. * any locks.
  3140. *
  3141. * This function returns 0 always.
  3142. **/
  3143. int
  3144. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3145. {
  3146. struct lpfc_sli *psli = &phba->sli;
  3147. uint16_t cfg_value;
  3148. uint8_t qindx;
  3149. /* Reset HBA */
  3150. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3151. "0295 Reset HBA Data: x%x x%x\n",
  3152. phba->pport->port_state, psli->sli_flag);
  3153. /* perform board reset */
  3154. phba->fc_eventTag = 0;
  3155. phba->pport->fc_myDID = 0;
  3156. phba->pport->fc_prevDID = 0;
  3157. /* Turn off parity checking and serr during the physical reset */
  3158. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3159. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3160. (cfg_value &
  3161. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3162. spin_lock_irq(&phba->hbalock);
  3163. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3164. phba->fcf.fcf_flag = 0;
  3165. /* Clean up the child queue list for the CQs */
  3166. list_del_init(&phba->sli4_hba.mbx_wq->list);
  3167. list_del_init(&phba->sli4_hba.els_wq->list);
  3168. list_del_init(&phba->sli4_hba.hdr_rq->list);
  3169. list_del_init(&phba->sli4_hba.dat_rq->list);
  3170. list_del_init(&phba->sli4_hba.mbx_cq->list);
  3171. list_del_init(&phba->sli4_hba.els_cq->list);
  3172. list_del_init(&phba->sli4_hba.rxq_cq->list);
  3173. for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++)
  3174. list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list);
  3175. for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++)
  3176. list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list);
  3177. spin_unlock_irq(&phba->hbalock);
  3178. /* Now physically reset the device */
  3179. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3180. "0389 Performing PCI function reset!\n");
  3181. /* Perform FCoE PCI function reset */
  3182. lpfc_pci_function_reset(phba);
  3183. return 0;
  3184. }
  3185. /**
  3186. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3187. * @phba: Pointer to HBA context object.
  3188. *
  3189. * This function is called in the SLI initialization code path to
  3190. * restart the HBA. The caller is not required to hold any lock.
  3191. * This function writes MBX_RESTART mailbox command to the SLIM and
  3192. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3193. * function to free any pending commands. The function enables
  3194. * POST only during the first initialization. The function returns zero.
  3195. * The function does not guarantee completion of MBX_RESTART mailbox
  3196. * command before the return of this function.
  3197. **/
  3198. static int
  3199. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3200. {
  3201. MAILBOX_t *mb;
  3202. struct lpfc_sli *psli;
  3203. volatile uint32_t word0;
  3204. void __iomem *to_slim;
  3205. spin_lock_irq(&phba->hbalock);
  3206. psli = &phba->sli;
  3207. /* Restart HBA */
  3208. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3209. "0337 Restart HBA Data: x%x x%x\n",
  3210. phba->pport->port_state, psli->sli_flag);
  3211. word0 = 0;
  3212. mb = (MAILBOX_t *) &word0;
  3213. mb->mbxCommand = MBX_RESTART;
  3214. mb->mbxHc = 1;
  3215. lpfc_reset_barrier(phba);
  3216. to_slim = phba->MBslimaddr;
  3217. writel(*(uint32_t *) mb, to_slim);
  3218. readl(to_slim); /* flush */
  3219. /* Only skip post after fc_ffinit is completed */
  3220. if (phba->pport->port_state)
  3221. word0 = 1; /* This is really setting up word1 */
  3222. else
  3223. word0 = 0; /* This is really setting up word1 */
  3224. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3225. writel(*(uint32_t *) mb, to_slim);
  3226. readl(to_slim); /* flush */
  3227. lpfc_sli_brdreset(phba);
  3228. phba->pport->stopped = 0;
  3229. phba->link_state = LPFC_INIT_START;
  3230. phba->hba_flag = 0;
  3231. spin_unlock_irq(&phba->hbalock);
  3232. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3233. psli->stats_start = get_seconds();
  3234. /* Give the INITFF and Post time to settle. */
  3235. mdelay(100);
  3236. lpfc_hba_down_post(phba);
  3237. return 0;
  3238. }
  3239. /**
  3240. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3241. * @phba: Pointer to HBA context object.
  3242. *
  3243. * This function is called in the SLI initialization code path to restart
  3244. * a SLI4 HBA. The caller is not required to hold any lock.
  3245. * At the end of the function, it calls lpfc_hba_down_post function to
  3246. * free any pending commands.
  3247. **/
  3248. static int
  3249. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3250. {
  3251. struct lpfc_sli *psli = &phba->sli;
  3252. /* Restart HBA */
  3253. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3254. "0296 Restart HBA Data: x%x x%x\n",
  3255. phba->pport->port_state, psli->sli_flag);
  3256. lpfc_sli4_brdreset(phba);
  3257. spin_lock_irq(&phba->hbalock);
  3258. phba->pport->stopped = 0;
  3259. phba->link_state = LPFC_INIT_START;
  3260. phba->hba_flag = 0;
  3261. spin_unlock_irq(&phba->hbalock);
  3262. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3263. psli->stats_start = get_seconds();
  3264. lpfc_hba_down_post(phba);
  3265. return 0;
  3266. }
  3267. /**
  3268. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3269. * @phba: Pointer to HBA context object.
  3270. *
  3271. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3272. * API jump table function pointer from the lpfc_hba struct.
  3273. **/
  3274. int
  3275. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3276. {
  3277. return phba->lpfc_sli_brdrestart(phba);
  3278. }
  3279. /**
  3280. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3281. * @phba: Pointer to HBA context object.
  3282. *
  3283. * This function is called after a HBA restart to wait for successful
  3284. * restart of the HBA. Successful restart of the HBA is indicated by
  3285. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3286. * iteration, the function will restart the HBA again. The function returns
  3287. * zero if HBA successfully restarted else returns negative error code.
  3288. **/
  3289. static int
  3290. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3291. {
  3292. uint32_t status, i = 0;
  3293. /* Read the HBA Host Status Register */
  3294. status = readl(phba->HSregaddr);
  3295. /* Check status register to see what current state is */
  3296. i = 0;
  3297. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3298. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  3299. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  3300. * 4.
  3301. */
  3302. if (i++ >= 20) {
  3303. /* Adapter failed to init, timeout, status reg
  3304. <status> */
  3305. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3306. "0436 Adapter failed to init, "
  3307. "timeout, status reg x%x, "
  3308. "FW Data: A8 x%x AC x%x\n", status,
  3309. readl(phba->MBslimaddr + 0xa8),
  3310. readl(phba->MBslimaddr + 0xac));
  3311. phba->link_state = LPFC_HBA_ERROR;
  3312. return -ETIMEDOUT;
  3313. }
  3314. /* Check to see if any errors occurred during init */
  3315. if (status & HS_FFERM) {
  3316. /* ERROR: During chipset initialization */
  3317. /* Adapter failed to init, chipset, status reg
  3318. <status> */
  3319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3320. "0437 Adapter failed to init, "
  3321. "chipset, status reg x%x, "
  3322. "FW Data: A8 x%x AC x%x\n", status,
  3323. readl(phba->MBslimaddr + 0xa8),
  3324. readl(phba->MBslimaddr + 0xac));
  3325. phba->link_state = LPFC_HBA_ERROR;
  3326. return -EIO;
  3327. }
  3328. if (i <= 5) {
  3329. msleep(10);
  3330. } else if (i <= 10) {
  3331. msleep(500);
  3332. } else {
  3333. msleep(2500);
  3334. }
  3335. if (i == 15) {
  3336. /* Do post */
  3337. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3338. lpfc_sli_brdrestart(phba);
  3339. }
  3340. /* Read the HBA Host Status Register */
  3341. status = readl(phba->HSregaddr);
  3342. }
  3343. /* Check to see if any errors occurred during init */
  3344. if (status & HS_FFERM) {
  3345. /* ERROR: During chipset initialization */
  3346. /* Adapter failed to init, chipset, status reg <status> */
  3347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3348. "0438 Adapter failed to init, chipset, "
  3349. "status reg x%x, "
  3350. "FW Data: A8 x%x AC x%x\n", status,
  3351. readl(phba->MBslimaddr + 0xa8),
  3352. readl(phba->MBslimaddr + 0xac));
  3353. phba->link_state = LPFC_HBA_ERROR;
  3354. return -EIO;
  3355. }
  3356. /* Clear all interrupt enable conditions */
  3357. writel(0, phba->HCregaddr);
  3358. readl(phba->HCregaddr); /* flush */
  3359. /* setup host attn register */
  3360. writel(0xffffffff, phba->HAregaddr);
  3361. readl(phba->HAregaddr); /* flush */
  3362. return 0;
  3363. }
  3364. /**
  3365. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3366. *
  3367. * This function calculates and returns the number of HBQs required to be
  3368. * configured.
  3369. **/
  3370. int
  3371. lpfc_sli_hbq_count(void)
  3372. {
  3373. return ARRAY_SIZE(lpfc_hbq_defs);
  3374. }
  3375. /**
  3376. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3377. *
  3378. * This function adds the number of hbq entries in every HBQ to get
  3379. * the total number of hbq entries required for the HBA and returns
  3380. * the total count.
  3381. **/
  3382. static int
  3383. lpfc_sli_hbq_entry_count(void)
  3384. {
  3385. int hbq_count = lpfc_sli_hbq_count();
  3386. int count = 0;
  3387. int i;
  3388. for (i = 0; i < hbq_count; ++i)
  3389. count += lpfc_hbq_defs[i]->entry_count;
  3390. return count;
  3391. }
  3392. /**
  3393. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3394. *
  3395. * This function calculates amount of memory required for all hbq entries
  3396. * to be configured and returns the total memory required.
  3397. **/
  3398. int
  3399. lpfc_sli_hbq_size(void)
  3400. {
  3401. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3402. }
  3403. /**
  3404. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3405. * @phba: Pointer to HBA context object.
  3406. *
  3407. * This function is called during the SLI initialization to configure
  3408. * all the HBQs and post buffers to the HBQ. The caller is not
  3409. * required to hold any locks. This function will return zero if successful
  3410. * else it will return negative error code.
  3411. **/
  3412. static int
  3413. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3414. {
  3415. int hbq_count = lpfc_sli_hbq_count();
  3416. LPFC_MBOXQ_t *pmb;
  3417. MAILBOX_t *pmbox;
  3418. uint32_t hbqno;
  3419. uint32_t hbq_entry_index;
  3420. /* Get a Mailbox buffer to setup mailbox
  3421. * commands for HBA initialization
  3422. */
  3423. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3424. if (!pmb)
  3425. return -ENOMEM;
  3426. pmbox = &pmb->u.mb;
  3427. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3428. phba->link_state = LPFC_INIT_MBX_CMDS;
  3429. phba->hbq_in_use = 1;
  3430. hbq_entry_index = 0;
  3431. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3432. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3433. phba->hbqs[hbqno].hbqPutIdx = 0;
  3434. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3435. phba->hbqs[hbqno].entry_count =
  3436. lpfc_hbq_defs[hbqno]->entry_count;
  3437. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3438. hbq_entry_index, pmb);
  3439. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3440. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3441. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3442. mbxStatus <status>, ring <num> */
  3443. lpfc_printf_log(phba, KERN_ERR,
  3444. LOG_SLI | LOG_VPORT,
  3445. "1805 Adapter failed to init. "
  3446. "Data: x%x x%x x%x\n",
  3447. pmbox->mbxCommand,
  3448. pmbox->mbxStatus, hbqno);
  3449. phba->link_state = LPFC_HBA_ERROR;
  3450. mempool_free(pmb, phba->mbox_mem_pool);
  3451. return ENXIO;
  3452. }
  3453. }
  3454. phba->hbq_count = hbq_count;
  3455. mempool_free(pmb, phba->mbox_mem_pool);
  3456. /* Initially populate or replenish the HBQs */
  3457. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3458. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3459. return 0;
  3460. }
  3461. /**
  3462. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3463. * @phba: Pointer to HBA context object.
  3464. *
  3465. * This function is called during the SLI initialization to configure
  3466. * all the HBQs and post buffers to the HBQ. The caller is not
  3467. * required to hold any locks. This function will return zero if successful
  3468. * else it will return negative error code.
  3469. **/
  3470. static int
  3471. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3472. {
  3473. phba->hbq_in_use = 1;
  3474. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3475. phba->hbq_count = 1;
  3476. /* Initially populate or replenish the HBQs */
  3477. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3478. return 0;
  3479. }
  3480. /**
  3481. * lpfc_sli_config_port - Issue config port mailbox command
  3482. * @phba: Pointer to HBA context object.
  3483. * @sli_mode: sli mode - 2/3
  3484. *
  3485. * This function is called by the sli intialization code path
  3486. * to issue config_port mailbox command. This function restarts the
  3487. * HBA firmware and issues a config_port mailbox command to configure
  3488. * the SLI interface in the sli mode specified by sli_mode
  3489. * variable. The caller is not required to hold any locks.
  3490. * The function returns 0 if successful, else returns negative error
  3491. * code.
  3492. **/
  3493. int
  3494. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3495. {
  3496. LPFC_MBOXQ_t *pmb;
  3497. uint32_t resetcount = 0, rc = 0, done = 0;
  3498. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3499. if (!pmb) {
  3500. phba->link_state = LPFC_HBA_ERROR;
  3501. return -ENOMEM;
  3502. }
  3503. phba->sli_rev = sli_mode;
  3504. while (resetcount < 2 && !done) {
  3505. spin_lock_irq(&phba->hbalock);
  3506. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3507. spin_unlock_irq(&phba->hbalock);
  3508. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3509. lpfc_sli_brdrestart(phba);
  3510. rc = lpfc_sli_chipset_init(phba);
  3511. if (rc)
  3512. break;
  3513. spin_lock_irq(&phba->hbalock);
  3514. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3515. spin_unlock_irq(&phba->hbalock);
  3516. resetcount++;
  3517. /* Call pre CONFIG_PORT mailbox command initialization. A
  3518. * value of 0 means the call was successful. Any other
  3519. * nonzero value is a failure, but if ERESTART is returned,
  3520. * the driver may reset the HBA and try again.
  3521. */
  3522. rc = lpfc_config_port_prep(phba);
  3523. if (rc == -ERESTART) {
  3524. phba->link_state = LPFC_LINK_UNKNOWN;
  3525. continue;
  3526. } else if (rc)
  3527. break;
  3528. phba->link_state = LPFC_INIT_MBX_CMDS;
  3529. lpfc_config_port(phba, pmb);
  3530. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3531. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3532. LPFC_SLI3_HBQ_ENABLED |
  3533. LPFC_SLI3_CRP_ENABLED |
  3534. LPFC_SLI3_INB_ENABLED |
  3535. LPFC_SLI3_BG_ENABLED);
  3536. if (rc != MBX_SUCCESS) {
  3537. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3538. "0442 Adapter failed to init, mbxCmd x%x "
  3539. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3540. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3541. spin_lock_irq(&phba->hbalock);
  3542. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3543. spin_unlock_irq(&phba->hbalock);
  3544. rc = -ENXIO;
  3545. } else {
  3546. /* Allow asynchronous mailbox command to go through */
  3547. spin_lock_irq(&phba->hbalock);
  3548. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3549. spin_unlock_irq(&phba->hbalock);
  3550. done = 1;
  3551. }
  3552. }
  3553. if (!done) {
  3554. rc = -EINVAL;
  3555. goto do_prep_failed;
  3556. }
  3557. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3558. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3559. rc = -ENXIO;
  3560. goto do_prep_failed;
  3561. }
  3562. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3563. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3564. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3565. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3566. phba->max_vpi : phba->max_vports;
  3567. } else
  3568. phba->max_vpi = 0;
  3569. if (pmb->u.mb.un.varCfgPort.gdss)
  3570. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3571. if (pmb->u.mb.un.varCfgPort.gerbm)
  3572. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3573. if (pmb->u.mb.un.varCfgPort.gcrp)
  3574. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3575. if (pmb->u.mb.un.varCfgPort.ginb) {
  3576. phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
  3577. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  3578. phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
  3579. phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
  3580. phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
  3581. phba->inb_last_counter =
  3582. phba->mbox->us.s3_inb_pgp.counter;
  3583. } else {
  3584. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3585. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3586. phba->inb_ha_copy = NULL;
  3587. phba->inb_counter = NULL;
  3588. }
  3589. if (phba->cfg_enable_bg) {
  3590. if (pmb->u.mb.un.varCfgPort.gbg)
  3591. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3592. else
  3593. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3594. "0443 Adapter did not grant "
  3595. "BlockGuard\n");
  3596. }
  3597. } else {
  3598. phba->hbq_get = NULL;
  3599. phba->port_gp = phba->mbox->us.s2.port;
  3600. phba->inb_ha_copy = NULL;
  3601. phba->inb_counter = NULL;
  3602. phba->max_vpi = 0;
  3603. }
  3604. do_prep_failed:
  3605. mempool_free(pmb, phba->mbox_mem_pool);
  3606. return rc;
  3607. }
  3608. /**
  3609. * lpfc_sli_hba_setup - SLI intialization function
  3610. * @phba: Pointer to HBA context object.
  3611. *
  3612. * This function is the main SLI intialization function. This function
  3613. * is called by the HBA intialization code, HBA reset code and HBA
  3614. * error attention handler code. Caller is not required to hold any
  3615. * locks. This function issues config_port mailbox command to configure
  3616. * the SLI, setup iocb rings and HBQ rings. In the end the function
  3617. * calls the config_port_post function to issue init_link mailbox
  3618. * command and to start the discovery. The function will return zero
  3619. * if successful, else it will return negative error code.
  3620. **/
  3621. int
  3622. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  3623. {
  3624. uint32_t rc;
  3625. int mode = 3;
  3626. switch (lpfc_sli_mode) {
  3627. case 2:
  3628. if (phba->cfg_enable_npiv) {
  3629. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3630. "1824 NPIV enabled: Override lpfc_sli_mode "
  3631. "parameter (%d) to auto (0).\n",
  3632. lpfc_sli_mode);
  3633. break;
  3634. }
  3635. mode = 2;
  3636. break;
  3637. case 0:
  3638. case 3:
  3639. break;
  3640. default:
  3641. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3642. "1819 Unrecognized lpfc_sli_mode "
  3643. "parameter: %d.\n", lpfc_sli_mode);
  3644. break;
  3645. }
  3646. rc = lpfc_sli_config_port(phba, mode);
  3647. if (rc && lpfc_sli_mode == 3)
  3648. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  3649. "1820 Unable to select SLI-3. "
  3650. "Not supported by adapter.\n");
  3651. if (rc && mode != 2)
  3652. rc = lpfc_sli_config_port(phba, 2);
  3653. if (rc)
  3654. goto lpfc_sli_hba_setup_error;
  3655. if (phba->sli_rev == 3) {
  3656. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  3657. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  3658. } else {
  3659. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  3660. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  3661. phba->sli3_options = 0;
  3662. }
  3663. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3664. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  3665. phba->sli_rev, phba->max_vpi);
  3666. rc = lpfc_sli_ring_map(phba);
  3667. if (rc)
  3668. goto lpfc_sli_hba_setup_error;
  3669. /* Init HBQs */
  3670. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3671. rc = lpfc_sli_hbq_setup(phba);
  3672. if (rc)
  3673. goto lpfc_sli_hba_setup_error;
  3674. }
  3675. spin_lock_irq(&phba->hbalock);
  3676. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  3677. spin_unlock_irq(&phba->hbalock);
  3678. rc = lpfc_config_port_post(phba);
  3679. if (rc)
  3680. goto lpfc_sli_hba_setup_error;
  3681. return rc;
  3682. lpfc_sli_hba_setup_error:
  3683. phba->link_state = LPFC_HBA_ERROR;
  3684. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3685. "0445 Firmware initialization failed\n");
  3686. return rc;
  3687. }
  3688. /**
  3689. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  3690. * @phba: Pointer to HBA context object.
  3691. * @mboxq: mailbox pointer.
  3692. * This function issue a dump mailbox command to read config region
  3693. * 23 and parse the records in the region and populate driver
  3694. * data structure.
  3695. **/
  3696. static int
  3697. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba,
  3698. LPFC_MBOXQ_t *mboxq)
  3699. {
  3700. struct lpfc_dmabuf *mp;
  3701. struct lpfc_mqe *mqe;
  3702. uint32_t data_length;
  3703. int rc;
  3704. /* Program the default value of vlan_id and fc_map */
  3705. phba->valid_vlan = 0;
  3706. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3707. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3708. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3709. mqe = &mboxq->u.mqe;
  3710. if (lpfc_dump_fcoe_param(phba, mboxq))
  3711. return -ENOMEM;
  3712. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3713. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3714. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3715. "(%d):2571 Mailbox cmd x%x Status x%x "
  3716. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3717. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3718. "CQ: x%x x%x x%x x%x\n",
  3719. mboxq->vport ? mboxq->vport->vpi : 0,
  3720. bf_get(lpfc_mqe_command, mqe),
  3721. bf_get(lpfc_mqe_status, mqe),
  3722. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3723. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3724. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3725. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3726. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3727. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3728. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3729. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3730. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3731. mboxq->mcqe.word0,
  3732. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3733. mboxq->mcqe.trailer);
  3734. if (rc) {
  3735. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3736. kfree(mp);
  3737. return -EIO;
  3738. }
  3739. data_length = mqe->un.mb_words[5];
  3740. if (data_length > DMP_FCOEPARAM_RGN_SIZE)
  3741. return -EIO;
  3742. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  3743. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3744. kfree(mp);
  3745. return 0;
  3746. }
  3747. /**
  3748. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  3749. * @phba: pointer to lpfc hba data structure.
  3750. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  3751. * @vpd: pointer to the memory to hold resulting port vpd data.
  3752. * @vpd_size: On input, the number of bytes allocated to @vpd.
  3753. * On output, the number of data bytes in @vpd.
  3754. *
  3755. * This routine executes a READ_REV SLI4 mailbox command. In
  3756. * addition, this routine gets the port vpd data.
  3757. *
  3758. * Return codes
  3759. * 0 - sucessful
  3760. * ENOMEM - could not allocated memory.
  3761. **/
  3762. static int
  3763. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  3764. uint8_t *vpd, uint32_t *vpd_size)
  3765. {
  3766. int rc = 0;
  3767. uint32_t dma_size;
  3768. struct lpfc_dmabuf *dmabuf;
  3769. struct lpfc_mqe *mqe;
  3770. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3771. if (!dmabuf)
  3772. return -ENOMEM;
  3773. /*
  3774. * Get a DMA buffer for the vpd data resulting from the READ_REV
  3775. * mailbox command.
  3776. */
  3777. dma_size = *vpd_size;
  3778. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3779. dma_size,
  3780. &dmabuf->phys,
  3781. GFP_KERNEL);
  3782. if (!dmabuf->virt) {
  3783. kfree(dmabuf);
  3784. return -ENOMEM;
  3785. }
  3786. memset(dmabuf->virt, 0, dma_size);
  3787. /*
  3788. * The SLI4 implementation of READ_REV conflicts at word1,
  3789. * bits 31:16 and SLI4 adds vpd functionality not present
  3790. * in SLI3. This code corrects the conflicts.
  3791. */
  3792. lpfc_read_rev(phba, mboxq);
  3793. mqe = &mboxq->u.mqe;
  3794. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  3795. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  3796. mqe->un.read_rev.word1 &= 0x0000FFFF;
  3797. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  3798. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  3799. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3800. if (rc) {
  3801. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3802. dmabuf->virt, dmabuf->phys);
  3803. return -EIO;
  3804. }
  3805. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  3806. "(%d):0380 Mailbox cmd x%x Status x%x "
  3807. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3808. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  3809. "CQ: x%x x%x x%x x%x\n",
  3810. mboxq->vport ? mboxq->vport->vpi : 0,
  3811. bf_get(lpfc_mqe_command, mqe),
  3812. bf_get(lpfc_mqe_status, mqe),
  3813. mqe->un.mb_words[0], mqe->un.mb_words[1],
  3814. mqe->un.mb_words[2], mqe->un.mb_words[3],
  3815. mqe->un.mb_words[4], mqe->un.mb_words[5],
  3816. mqe->un.mb_words[6], mqe->un.mb_words[7],
  3817. mqe->un.mb_words[8], mqe->un.mb_words[9],
  3818. mqe->un.mb_words[10], mqe->un.mb_words[11],
  3819. mqe->un.mb_words[12], mqe->un.mb_words[13],
  3820. mqe->un.mb_words[14], mqe->un.mb_words[15],
  3821. mqe->un.mb_words[16], mqe->un.mb_words[50],
  3822. mboxq->mcqe.word0,
  3823. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  3824. mboxq->mcqe.trailer);
  3825. /*
  3826. * The available vpd length cannot be bigger than the
  3827. * DMA buffer passed to the port. Catch the less than
  3828. * case and update the caller's size.
  3829. */
  3830. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  3831. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  3832. lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size);
  3833. dma_free_coherent(&phba->pcidev->dev, dma_size,
  3834. dmabuf->virt, dmabuf->phys);
  3835. kfree(dmabuf);
  3836. return 0;
  3837. }
  3838. /**
  3839. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  3840. * @phba: pointer to lpfc hba data structure.
  3841. *
  3842. * This routine is called to explicitly arm the SLI4 device's completion and
  3843. * event queues
  3844. **/
  3845. static void
  3846. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  3847. {
  3848. uint8_t fcp_eqidx;
  3849. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  3850. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  3851. lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM);
  3852. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3853. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  3854. LPFC_QUEUE_REARM);
  3855. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  3856. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++)
  3857. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  3858. LPFC_QUEUE_REARM);
  3859. }
  3860. /**
  3861. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  3862. * @phba: Pointer to HBA context object.
  3863. *
  3864. * This function is the main SLI4 device intialization PCI function. This
  3865. * function is called by the HBA intialization code, HBA reset code and
  3866. * HBA error attention handler code. Caller is not required to hold any
  3867. * locks.
  3868. **/
  3869. int
  3870. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  3871. {
  3872. int rc;
  3873. LPFC_MBOXQ_t *mboxq;
  3874. struct lpfc_mqe *mqe;
  3875. uint8_t *vpd;
  3876. uint32_t vpd_size;
  3877. uint32_t ftr_rsp = 0;
  3878. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  3879. struct lpfc_vport *vport = phba->pport;
  3880. struct lpfc_dmabuf *mp;
  3881. /* Perform a PCI function reset to start from clean */
  3882. rc = lpfc_pci_function_reset(phba);
  3883. if (unlikely(rc))
  3884. return -ENODEV;
  3885. /* Check the HBA Host Status Register for readyness */
  3886. rc = lpfc_sli4_post_status_check(phba);
  3887. if (unlikely(rc))
  3888. return -ENODEV;
  3889. else {
  3890. spin_lock_irq(&phba->hbalock);
  3891. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  3892. spin_unlock_irq(&phba->hbalock);
  3893. }
  3894. /*
  3895. * Allocate a single mailbox container for initializing the
  3896. * port.
  3897. */
  3898. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3899. if (!mboxq)
  3900. return -ENOMEM;
  3901. /*
  3902. * Continue initialization with default values even if driver failed
  3903. * to read FCoE param config regions
  3904. */
  3905. if (lpfc_sli4_read_fcoe_params(phba, mboxq))
  3906. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  3907. "2570 Failed to read FCoE parameters \n");
  3908. /* Issue READ_REV to collect vpd and FW information. */
  3909. vpd_size = PAGE_SIZE;
  3910. vpd = kzalloc(vpd_size, GFP_KERNEL);
  3911. if (!vpd) {
  3912. rc = -ENOMEM;
  3913. goto out_free_mbox;
  3914. }
  3915. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  3916. if (unlikely(rc))
  3917. goto out_free_vpd;
  3918. mqe = &mboxq->u.mqe;
  3919. if ((bf_get(lpfc_mbx_rd_rev_sli_lvl,
  3920. &mqe->un.read_rev) != LPFC_SLI_REV4) ||
  3921. (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev) == 0)) {
  3922. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3923. "0376 READ_REV Error. SLI Level %d "
  3924. "FCoE enabled %d\n",
  3925. bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev),
  3926. bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev));
  3927. rc = -EIO;
  3928. goto out_free_vpd;
  3929. }
  3930. /* Single threaded at this point, no need for lock */
  3931. spin_lock_irq(&phba->hbalock);
  3932. phba->hba_flag |= HBA_FCOE_SUPPORT;
  3933. spin_unlock_irq(&phba->hbalock);
  3934. /*
  3935. * Evaluate the read rev and vpd data. Populate the driver
  3936. * state with the results. If this routine fails, the failure
  3937. * is not fatal as the driver will use generic values.
  3938. */
  3939. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  3940. if (unlikely(!rc)) {
  3941. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3942. "0377 Error %d parsing vpd. "
  3943. "Using defaults.\n", rc);
  3944. rc = 0;
  3945. }
  3946. /* By now, we should determine the SLI revision, hard code for now */
  3947. phba->sli_rev = LPFC_SLI_REV4;
  3948. /*
  3949. * Discover the port's supported feature set and match it against the
  3950. * hosts requests.
  3951. */
  3952. lpfc_request_features(phba, mboxq);
  3953. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3954. if (unlikely(rc)) {
  3955. rc = -EIO;
  3956. goto out_free_vpd;
  3957. }
  3958. /*
  3959. * The port must support FCP initiator mode as this is the
  3960. * only mode running in the host.
  3961. */
  3962. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  3963. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3964. "0378 No support for fcpi mode.\n");
  3965. ftr_rsp++;
  3966. }
  3967. /*
  3968. * If the port cannot support the host's requested features
  3969. * then turn off the global config parameters to disable the
  3970. * feature in the driver. This is not a fatal error.
  3971. */
  3972. if ((phba->cfg_enable_bg) &&
  3973. !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3974. ftr_rsp++;
  3975. if (phba->max_vpi && phba->cfg_enable_npiv &&
  3976. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3977. ftr_rsp++;
  3978. if (ftr_rsp) {
  3979. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  3980. "0379 Feature Mismatch Data: x%08x %08x "
  3981. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  3982. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  3983. phba->cfg_enable_npiv, phba->max_vpi);
  3984. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  3985. phba->cfg_enable_bg = 0;
  3986. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  3987. phba->cfg_enable_npiv = 0;
  3988. }
  3989. /* These SLI3 features are assumed in SLI4 */
  3990. spin_lock_irq(&phba->hbalock);
  3991. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  3992. spin_unlock_irq(&phba->hbalock);
  3993. /* Read the port's service parameters. */
  3994. lpfc_read_sparam(phba, mboxq, vport->vpi);
  3995. mboxq->vport = vport;
  3996. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3997. mp = (struct lpfc_dmabuf *) mboxq->context1;
  3998. if (rc == MBX_SUCCESS) {
  3999. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  4000. rc = 0;
  4001. }
  4002. /*
  4003. * This memory was allocated by the lpfc_read_sparam routine. Release
  4004. * it to the mbuf pool.
  4005. */
  4006. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4007. kfree(mp);
  4008. mboxq->context1 = NULL;
  4009. if (unlikely(rc)) {
  4010. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4011. "0382 READ_SPARAM command failed "
  4012. "status %d, mbxStatus x%x\n",
  4013. rc, bf_get(lpfc_mqe_status, mqe));
  4014. phba->link_state = LPFC_HBA_ERROR;
  4015. rc = -EIO;
  4016. goto out_free_vpd;
  4017. }
  4018. if (phba->cfg_soft_wwnn)
  4019. u64_to_wwn(phba->cfg_soft_wwnn,
  4020. vport->fc_sparam.nodeName.u.wwn);
  4021. if (phba->cfg_soft_wwpn)
  4022. u64_to_wwn(phba->cfg_soft_wwpn,
  4023. vport->fc_sparam.portName.u.wwn);
  4024. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  4025. sizeof(struct lpfc_name));
  4026. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  4027. sizeof(struct lpfc_name));
  4028. /* Update the fc_host data structures with new wwn. */
  4029. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  4030. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  4031. /* Register SGL pool to the device using non-embedded mailbox command */
  4032. rc = lpfc_sli4_post_sgl_list(phba);
  4033. if (unlikely(rc)) {
  4034. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4035. "0582 Error %d during sgl post operation", rc);
  4036. rc = -ENODEV;
  4037. goto out_free_vpd;
  4038. }
  4039. /* Register SCSI SGL pool to the device */
  4040. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  4041. if (unlikely(rc)) {
  4042. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  4043. "0383 Error %d during scsi sgl post opeation",
  4044. rc);
  4045. /* Some Scsi buffers were moved to the abort scsi list */
  4046. /* A pci function reset will repost them */
  4047. rc = -ENODEV;
  4048. goto out_free_vpd;
  4049. }
  4050. /* Post the rpi header region to the device. */
  4051. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  4052. if (unlikely(rc)) {
  4053. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4054. "0393 Error %d during rpi post operation\n",
  4055. rc);
  4056. rc = -ENODEV;
  4057. goto out_free_vpd;
  4058. }
  4059. /* Temporary initialization of lpfc_fip_flag to non-fip */
  4060. bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0);
  4061. /* Set up all the queues to the device */
  4062. rc = lpfc_sli4_queue_setup(phba);
  4063. if (unlikely(rc)) {
  4064. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4065. "0381 Error %d during queue setup.\n ", rc);
  4066. goto out_stop_timers;
  4067. }
  4068. /* Arm the CQs and then EQs on device */
  4069. lpfc_sli4_arm_cqeq_intr(phba);
  4070. /* Indicate device interrupt mode */
  4071. phba->sli4_hba.intr_enable = 1;
  4072. /* Allow asynchronous mailbox command to go through */
  4073. spin_lock_irq(&phba->hbalock);
  4074. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4075. spin_unlock_irq(&phba->hbalock);
  4076. /* Post receive buffers to the device */
  4077. lpfc_sli4_rb_setup(phba);
  4078. /* Start the ELS watchdog timer */
  4079. /*
  4080. * The driver for SLI4 is not yet ready to process timeouts
  4081. * or interrupts. Once it is, the comment bars can be removed.
  4082. */
  4083. /* mod_timer(&vport->els_tmofunc,
  4084. * jiffies + HZ * (phba->fc_ratov*2)); */
  4085. /* Start heart beat timer */
  4086. mod_timer(&phba->hb_tmofunc,
  4087. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  4088. phba->hb_outstanding = 0;
  4089. phba->last_completion_time = jiffies;
  4090. /* Start error attention (ERATT) polling timer */
  4091. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  4092. /*
  4093. * The port is ready, set the host's link state to LINK_DOWN
  4094. * in preparation for link interrupts.
  4095. */
  4096. lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed);
  4097. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4098. lpfc_set_loopback_flag(phba);
  4099. /* Change driver state to LPFC_LINK_DOWN right before init link */
  4100. spin_lock_irq(&phba->hbalock);
  4101. phba->link_state = LPFC_LINK_DOWN;
  4102. spin_unlock_irq(&phba->hbalock);
  4103. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  4104. if (unlikely(rc != MBX_NOT_FINISHED)) {
  4105. kfree(vpd);
  4106. return 0;
  4107. } else
  4108. rc = -EIO;
  4109. /* Unset all the queues set up in this routine when error out */
  4110. if (rc)
  4111. lpfc_sli4_queue_unset(phba);
  4112. out_stop_timers:
  4113. if (rc)
  4114. lpfc_stop_hba_timers(phba);
  4115. out_free_vpd:
  4116. kfree(vpd);
  4117. out_free_mbox:
  4118. mempool_free(mboxq, phba->mbox_mem_pool);
  4119. return rc;
  4120. }
  4121. /**
  4122. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  4123. * @ptr: context object - pointer to hba structure.
  4124. *
  4125. * This is the callback function for mailbox timer. The mailbox
  4126. * timer is armed when a new mailbox command is issued and the timer
  4127. * is deleted when the mailbox complete. The function is called by
  4128. * the kernel timer code when a mailbox does not complete within
  4129. * expected time. This function wakes up the worker thread to
  4130. * process the mailbox timeout and returns. All the processing is
  4131. * done by the worker thread function lpfc_mbox_timeout_handler.
  4132. **/
  4133. void
  4134. lpfc_mbox_timeout(unsigned long ptr)
  4135. {
  4136. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4137. unsigned long iflag;
  4138. uint32_t tmo_posted;
  4139. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  4140. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  4141. if (!tmo_posted)
  4142. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  4143. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  4144. if (!tmo_posted)
  4145. lpfc_worker_wake_up(phba);
  4146. return;
  4147. }
  4148. /**
  4149. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  4150. * @phba: Pointer to HBA context object.
  4151. *
  4152. * This function is called from worker thread when a mailbox command times out.
  4153. * The caller is not required to hold any locks. This function will reset the
  4154. * HBA and recover all the pending commands.
  4155. **/
  4156. void
  4157. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  4158. {
  4159. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  4160. MAILBOX_t *mb = &pmbox->u.mb;
  4161. struct lpfc_sli *psli = &phba->sli;
  4162. struct lpfc_sli_ring *pring;
  4163. /* Check the pmbox pointer first. There is a race condition
  4164. * between the mbox timeout handler getting executed in the
  4165. * worklist and the mailbox actually completing. When this
  4166. * race condition occurs, the mbox_active will be NULL.
  4167. */
  4168. spin_lock_irq(&phba->hbalock);
  4169. if (pmbox == NULL) {
  4170. lpfc_printf_log(phba, KERN_WARNING,
  4171. LOG_MBOX | LOG_SLI,
  4172. "0353 Active Mailbox cleared - mailbox timeout "
  4173. "exiting\n");
  4174. spin_unlock_irq(&phba->hbalock);
  4175. return;
  4176. }
  4177. /* Mbox cmd <mbxCommand> timeout */
  4178. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4179. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  4180. mb->mbxCommand,
  4181. phba->pport->port_state,
  4182. phba->sli.sli_flag,
  4183. phba->sli.mbox_active);
  4184. spin_unlock_irq(&phba->hbalock);
  4185. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  4186. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  4187. * it to fail all oustanding SCSI IO.
  4188. */
  4189. spin_lock_irq(&phba->pport->work_port_lock);
  4190. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  4191. spin_unlock_irq(&phba->pport->work_port_lock);
  4192. spin_lock_irq(&phba->hbalock);
  4193. phba->link_state = LPFC_LINK_UNKNOWN;
  4194. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4195. spin_unlock_irq(&phba->hbalock);
  4196. pring = &psli->ring[psli->fcp_ring];
  4197. lpfc_sli_abort_iocb_ring(phba, pring);
  4198. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4199. "0345 Resetting board due to mailbox timeout\n");
  4200. /* Reset the HBA device */
  4201. lpfc_reset_hba(phba);
  4202. }
  4203. /**
  4204. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  4205. * @phba: Pointer to HBA context object.
  4206. * @pmbox: Pointer to mailbox object.
  4207. * @flag: Flag indicating how the mailbox need to be processed.
  4208. *
  4209. * This function is called by discovery code and HBA management code
  4210. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  4211. * function gets the hbalock to protect the data structures.
  4212. * The mailbox command can be submitted in polling mode, in which case
  4213. * this function will wait in a polling loop for the completion of the
  4214. * mailbox.
  4215. * If the mailbox is submitted in no_wait mode (not polling) the
  4216. * function will submit the command and returns immediately without waiting
  4217. * for the mailbox completion. The no_wait is supported only when HBA
  4218. * is in SLI2/SLI3 mode - interrupts are enabled.
  4219. * The SLI interface allows only one mailbox pending at a time. If the
  4220. * mailbox is issued in polling mode and there is already a mailbox
  4221. * pending, then the function will return an error. If the mailbox is issued
  4222. * in NO_WAIT mode and there is a mailbox pending already, the function
  4223. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  4224. * The sli layer owns the mailbox object until the completion of mailbox
  4225. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  4226. * return codes the caller owns the mailbox command after the return of
  4227. * the function.
  4228. **/
  4229. static int
  4230. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  4231. uint32_t flag)
  4232. {
  4233. MAILBOX_t *mb;
  4234. struct lpfc_sli *psli = &phba->sli;
  4235. uint32_t status, evtctr;
  4236. uint32_t ha_copy;
  4237. int i;
  4238. unsigned long timeout;
  4239. unsigned long drvr_flag = 0;
  4240. uint32_t word0, ldata;
  4241. void __iomem *to_slim;
  4242. int processing_queue = 0;
  4243. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4244. if (!pmbox) {
  4245. /* processing mbox queue from intr_handler */
  4246. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4247. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4248. return MBX_SUCCESS;
  4249. }
  4250. processing_queue = 1;
  4251. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4252. pmbox = lpfc_mbox_get(phba);
  4253. if (!pmbox) {
  4254. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4255. return MBX_SUCCESS;
  4256. }
  4257. }
  4258. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  4259. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  4260. if(!pmbox->vport) {
  4261. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4262. lpfc_printf_log(phba, KERN_ERR,
  4263. LOG_MBOX | LOG_VPORT,
  4264. "1806 Mbox x%x failed. No vport\n",
  4265. pmbox->u.mb.mbxCommand);
  4266. dump_stack();
  4267. goto out_not_finished;
  4268. }
  4269. }
  4270. /* If the PCI channel is in offline state, do not post mbox. */
  4271. if (unlikely(pci_channel_offline(phba->pcidev))) {
  4272. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4273. goto out_not_finished;
  4274. }
  4275. /* If HBA has a deferred error attention, fail the iocb. */
  4276. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  4277. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4278. goto out_not_finished;
  4279. }
  4280. psli = &phba->sli;
  4281. mb = &pmbox->u.mb;
  4282. status = MBX_SUCCESS;
  4283. if (phba->link_state == LPFC_HBA_ERROR) {
  4284. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4285. /* Mbox command <mbxCommand> cannot issue */
  4286. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4287. "(%d):0311 Mailbox command x%x cannot "
  4288. "issue Data: x%x x%x\n",
  4289. pmbox->vport ? pmbox->vport->vpi : 0,
  4290. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4291. goto out_not_finished;
  4292. }
  4293. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  4294. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  4295. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4296. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4297. "(%d):2528 Mailbox command x%x cannot "
  4298. "issue Data: x%x x%x\n",
  4299. pmbox->vport ? pmbox->vport->vpi : 0,
  4300. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  4301. goto out_not_finished;
  4302. }
  4303. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4304. /* Polling for a mbox command when another one is already active
  4305. * is not allowed in SLI. Also, the driver must have established
  4306. * SLI2 mode to queue and process multiple mbox commands.
  4307. */
  4308. if (flag & MBX_POLL) {
  4309. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4310. /* Mbox command <mbxCommand> cannot issue */
  4311. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4312. "(%d):2529 Mailbox command x%x "
  4313. "cannot issue Data: x%x x%x\n",
  4314. pmbox->vport ? pmbox->vport->vpi : 0,
  4315. pmbox->u.mb.mbxCommand,
  4316. psli->sli_flag, flag);
  4317. goto out_not_finished;
  4318. }
  4319. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  4320. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4321. /* Mbox command <mbxCommand> cannot issue */
  4322. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4323. "(%d):2530 Mailbox command x%x "
  4324. "cannot issue Data: x%x x%x\n",
  4325. pmbox->vport ? pmbox->vport->vpi : 0,
  4326. pmbox->u.mb.mbxCommand,
  4327. psli->sli_flag, flag);
  4328. goto out_not_finished;
  4329. }
  4330. /* Another mailbox command is still being processed, queue this
  4331. * command to be processed later.
  4332. */
  4333. lpfc_mbox_put(phba, pmbox);
  4334. /* Mbox cmd issue - BUSY */
  4335. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4336. "(%d):0308 Mbox cmd issue - BUSY Data: "
  4337. "x%x x%x x%x x%x\n",
  4338. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  4339. mb->mbxCommand, phba->pport->port_state,
  4340. psli->sli_flag, flag);
  4341. psli->slistat.mbox_busy++;
  4342. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4343. if (pmbox->vport) {
  4344. lpfc_debugfs_disc_trc(pmbox->vport,
  4345. LPFC_DISC_TRC_MBOX_VPORT,
  4346. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  4347. (uint32_t)mb->mbxCommand,
  4348. mb->un.varWords[0], mb->un.varWords[1]);
  4349. }
  4350. else {
  4351. lpfc_debugfs_disc_trc(phba->pport,
  4352. LPFC_DISC_TRC_MBOX,
  4353. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  4354. (uint32_t)mb->mbxCommand,
  4355. mb->un.varWords[0], mb->un.varWords[1]);
  4356. }
  4357. return MBX_BUSY;
  4358. }
  4359. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4360. /* If we are not polling, we MUST be in SLI2 mode */
  4361. if (flag != MBX_POLL) {
  4362. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  4363. (mb->mbxCommand != MBX_KILL_BOARD)) {
  4364. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4365. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4366. /* Mbox command <mbxCommand> cannot issue */
  4367. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4368. "(%d):2531 Mailbox command x%x "
  4369. "cannot issue Data: x%x x%x\n",
  4370. pmbox->vport ? pmbox->vport->vpi : 0,
  4371. pmbox->u.mb.mbxCommand,
  4372. psli->sli_flag, flag);
  4373. goto out_not_finished;
  4374. }
  4375. /* timeout active mbox command */
  4376. mod_timer(&psli->mbox_tmo, (jiffies +
  4377. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  4378. }
  4379. /* Mailbox cmd <cmd> issue */
  4380. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4381. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  4382. "x%x\n",
  4383. pmbox->vport ? pmbox->vport->vpi : 0,
  4384. mb->mbxCommand, phba->pport->port_state,
  4385. psli->sli_flag, flag);
  4386. if (mb->mbxCommand != MBX_HEARTBEAT) {
  4387. if (pmbox->vport) {
  4388. lpfc_debugfs_disc_trc(pmbox->vport,
  4389. LPFC_DISC_TRC_MBOX_VPORT,
  4390. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4391. (uint32_t)mb->mbxCommand,
  4392. mb->un.varWords[0], mb->un.varWords[1]);
  4393. }
  4394. else {
  4395. lpfc_debugfs_disc_trc(phba->pport,
  4396. LPFC_DISC_TRC_MBOX,
  4397. "MBOX Send: cmd:x%x mb:x%x x%x",
  4398. (uint32_t)mb->mbxCommand,
  4399. mb->un.varWords[0], mb->un.varWords[1]);
  4400. }
  4401. }
  4402. psli->slistat.mbox_cmd++;
  4403. evtctr = psli->slistat.mbox_event;
  4404. /* next set own bit for the adapter and copy over command word */
  4405. mb->mbxOwner = OWN_CHIP;
  4406. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4407. /* First copy command data to host SLIM area */
  4408. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4409. } else {
  4410. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4411. /* copy command data into host mbox for cmpl */
  4412. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  4413. }
  4414. /* First copy mbox command data to HBA SLIM, skip past first
  4415. word */
  4416. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4417. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  4418. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  4419. /* Next copy over first word, with mbxOwner set */
  4420. ldata = *((uint32_t *)mb);
  4421. to_slim = phba->MBslimaddr;
  4422. writel(ldata, to_slim);
  4423. readl(to_slim); /* flush */
  4424. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4425. /* switch over to host mailbox */
  4426. psli->sli_flag |= LPFC_SLI_ACTIVE;
  4427. }
  4428. }
  4429. wmb();
  4430. switch (flag) {
  4431. case MBX_NOWAIT:
  4432. /* Set up reference to mailbox command */
  4433. psli->mbox_active = pmbox;
  4434. /* Interrupt board to do it */
  4435. writel(CA_MBATT, phba->CAregaddr);
  4436. readl(phba->CAregaddr); /* flush */
  4437. /* Don't wait for it to finish, just return */
  4438. break;
  4439. case MBX_POLL:
  4440. /* Set up null reference to mailbox command */
  4441. psli->mbox_active = NULL;
  4442. /* Interrupt board to do it */
  4443. writel(CA_MBATT, phba->CAregaddr);
  4444. readl(phba->CAregaddr); /* flush */
  4445. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4446. /* First read mbox status word */
  4447. word0 = *((uint32_t *)phba->mbox);
  4448. word0 = le32_to_cpu(word0);
  4449. } else {
  4450. /* First read mbox status word */
  4451. word0 = readl(phba->MBslimaddr);
  4452. }
  4453. /* Read the HBA Host Attention Register */
  4454. ha_copy = readl(phba->HAregaddr);
  4455. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  4456. mb->mbxCommand) *
  4457. 1000) + jiffies;
  4458. i = 0;
  4459. /* Wait for command to complete */
  4460. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  4461. (!(ha_copy & HA_MBATT) &&
  4462. (phba->link_state > LPFC_WARM_START))) {
  4463. if (time_after(jiffies, timeout)) {
  4464. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4465. spin_unlock_irqrestore(&phba->hbalock,
  4466. drvr_flag);
  4467. goto out_not_finished;
  4468. }
  4469. /* Check if we took a mbox interrupt while we were
  4470. polling */
  4471. if (((word0 & OWN_CHIP) != OWN_CHIP)
  4472. && (evtctr != psli->slistat.mbox_event))
  4473. break;
  4474. if (i++ > 10) {
  4475. spin_unlock_irqrestore(&phba->hbalock,
  4476. drvr_flag);
  4477. msleep(1);
  4478. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  4479. }
  4480. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4481. /* First copy command data */
  4482. word0 = *((uint32_t *)phba->mbox);
  4483. word0 = le32_to_cpu(word0);
  4484. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  4485. MAILBOX_t *slimmb;
  4486. uint32_t slimword0;
  4487. /* Check real SLIM for any errors */
  4488. slimword0 = readl(phba->MBslimaddr);
  4489. slimmb = (MAILBOX_t *) & slimword0;
  4490. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  4491. && slimmb->mbxStatus) {
  4492. psli->sli_flag &=
  4493. ~LPFC_SLI_ACTIVE;
  4494. word0 = slimword0;
  4495. }
  4496. }
  4497. } else {
  4498. /* First copy command data */
  4499. word0 = readl(phba->MBslimaddr);
  4500. }
  4501. /* Read the HBA Host Attention Register */
  4502. ha_copy = readl(phba->HAregaddr);
  4503. }
  4504. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  4505. /* copy results back to user */
  4506. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  4507. } else {
  4508. /* First copy command data */
  4509. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  4510. MAILBOX_CMD_SIZE);
  4511. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  4512. pmbox->context2) {
  4513. lpfc_memcpy_from_slim((void *)pmbox->context2,
  4514. phba->MBslimaddr + DMP_RSP_OFFSET,
  4515. mb->un.varDmp.word_cnt);
  4516. }
  4517. }
  4518. writel(HA_MBATT, phba->HAregaddr);
  4519. readl(phba->HAregaddr); /* flush */
  4520. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4521. status = mb->mbxStatus;
  4522. }
  4523. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  4524. return status;
  4525. out_not_finished:
  4526. if (processing_queue) {
  4527. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4528. lpfc_mbox_cmpl_put(phba, pmbox);
  4529. }
  4530. return MBX_NOT_FINISHED;
  4531. }
  4532. /**
  4533. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  4534. * @phba: Pointer to HBA context object.
  4535. * @mboxq: Pointer to mailbox object.
  4536. *
  4537. * The function posts a mailbox to the port. The mailbox is expected
  4538. * to be comletely filled in and ready for the port to operate on it.
  4539. * This routine executes a synchronous completion operation on the
  4540. * mailbox by polling for its completion.
  4541. *
  4542. * The caller must not be holding any locks when calling this routine.
  4543. *
  4544. * Returns:
  4545. * MBX_SUCCESS - mailbox posted successfully
  4546. * Any of the MBX error values.
  4547. **/
  4548. static int
  4549. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4550. {
  4551. int rc = MBX_SUCCESS;
  4552. unsigned long iflag;
  4553. uint32_t db_ready;
  4554. uint32_t mcqe_status;
  4555. uint32_t mbx_cmnd;
  4556. unsigned long timeout;
  4557. struct lpfc_sli *psli = &phba->sli;
  4558. struct lpfc_mqe *mb = &mboxq->u.mqe;
  4559. struct lpfc_bmbx_create *mbox_rgn;
  4560. struct dma_address *dma_address;
  4561. struct lpfc_register bmbx_reg;
  4562. /*
  4563. * Only one mailbox can be active to the bootstrap mailbox region
  4564. * at a time and there is no queueing provided.
  4565. */
  4566. spin_lock_irqsave(&phba->hbalock, iflag);
  4567. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4568. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4569. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4570. "(%d):2532 Mailbox command x%x (x%x) "
  4571. "cannot issue Data: x%x x%x\n",
  4572. mboxq->vport ? mboxq->vport->vpi : 0,
  4573. mboxq->u.mb.mbxCommand,
  4574. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4575. psli->sli_flag, MBX_POLL);
  4576. return MBXERR_ERROR;
  4577. }
  4578. /* The server grabs the token and owns it until release */
  4579. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4580. phba->sli.mbox_active = mboxq;
  4581. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4582. /*
  4583. * Initialize the bootstrap memory region to avoid stale data areas
  4584. * in the mailbox post. Then copy the caller's mailbox contents to
  4585. * the bmbx mailbox region.
  4586. */
  4587. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  4588. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  4589. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  4590. sizeof(struct lpfc_mqe));
  4591. /* Post the high mailbox dma address to the port and wait for ready. */
  4592. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4593. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  4594. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4595. * 1000) + jiffies;
  4596. do {
  4597. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4598. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4599. if (!db_ready)
  4600. msleep(2);
  4601. if (time_after(jiffies, timeout)) {
  4602. rc = MBXERR_ERROR;
  4603. goto exit;
  4604. }
  4605. } while (!db_ready);
  4606. /* Post the low mailbox dma address to the port. */
  4607. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  4608. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd)
  4609. * 1000) + jiffies;
  4610. do {
  4611. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  4612. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  4613. if (!db_ready)
  4614. msleep(2);
  4615. if (time_after(jiffies, timeout)) {
  4616. rc = MBXERR_ERROR;
  4617. goto exit;
  4618. }
  4619. } while (!db_ready);
  4620. /*
  4621. * Read the CQ to ensure the mailbox has completed.
  4622. * If so, update the mailbox status so that the upper layers
  4623. * can complete the request normally.
  4624. */
  4625. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  4626. sizeof(struct lpfc_mqe));
  4627. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  4628. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  4629. sizeof(struct lpfc_mcqe));
  4630. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  4631. /* Prefix the mailbox status with range x4000 to note SLI4 status. */
  4632. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  4633. bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status);
  4634. rc = MBXERR_ERROR;
  4635. }
  4636. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4637. "(%d):0356 Mailbox cmd x%x (x%x) Status x%x "
  4638. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  4639. " x%x x%x CQ: x%x x%x x%x x%x\n",
  4640. mboxq->vport ? mboxq->vport->vpi : 0,
  4641. mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4642. bf_get(lpfc_mqe_status, mb),
  4643. mb->un.mb_words[0], mb->un.mb_words[1],
  4644. mb->un.mb_words[2], mb->un.mb_words[3],
  4645. mb->un.mb_words[4], mb->un.mb_words[5],
  4646. mb->un.mb_words[6], mb->un.mb_words[7],
  4647. mb->un.mb_words[8], mb->un.mb_words[9],
  4648. mb->un.mb_words[10], mb->un.mb_words[11],
  4649. mb->un.mb_words[12], mboxq->mcqe.word0,
  4650. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4651. mboxq->mcqe.trailer);
  4652. exit:
  4653. /* We are holding the token, no needed for lock when release */
  4654. spin_lock_irqsave(&phba->hbalock, iflag);
  4655. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4656. phba->sli.mbox_active = NULL;
  4657. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4658. return rc;
  4659. }
  4660. /**
  4661. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  4662. * @phba: Pointer to HBA context object.
  4663. * @pmbox: Pointer to mailbox object.
  4664. * @flag: Flag indicating how the mailbox need to be processed.
  4665. *
  4666. * This function is called by discovery code and HBA management code to submit
  4667. * a mailbox command to firmware with SLI-4 interface spec.
  4668. *
  4669. * Return codes the caller owns the mailbox command after the return of the
  4670. * function.
  4671. **/
  4672. static int
  4673. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4674. uint32_t flag)
  4675. {
  4676. struct lpfc_sli *psli = &phba->sli;
  4677. unsigned long iflags;
  4678. int rc;
  4679. /* Detect polling mode and jump to a handler */
  4680. if (!phba->sli4_hba.intr_enable) {
  4681. if (flag == MBX_POLL)
  4682. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  4683. else
  4684. rc = -EIO;
  4685. if (rc != MBX_SUCCESS)
  4686. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4687. "(%d):2541 Mailbox command x%x "
  4688. "(x%x) cannot issue Data: x%x x%x\n",
  4689. mboxq->vport ? mboxq->vport->vpi : 0,
  4690. mboxq->u.mb.mbxCommand,
  4691. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4692. psli->sli_flag, flag);
  4693. return rc;
  4694. } else if (flag == MBX_POLL) {
  4695. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4696. "(%d):2542 Mailbox command x%x (x%x) "
  4697. "cannot issue Data: x%x x%x\n",
  4698. mboxq->vport ? mboxq->vport->vpi : 0,
  4699. mboxq->u.mb.mbxCommand,
  4700. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4701. psli->sli_flag, flag);
  4702. return -EIO;
  4703. }
  4704. /* Now, interrupt mode asynchrous mailbox command */
  4705. rc = lpfc_mbox_cmd_check(phba, mboxq);
  4706. if (rc) {
  4707. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4708. "(%d):2543 Mailbox command x%x (x%x) "
  4709. "cannot issue Data: x%x x%x\n",
  4710. mboxq->vport ? mboxq->vport->vpi : 0,
  4711. mboxq->u.mb.mbxCommand,
  4712. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4713. psli->sli_flag, flag);
  4714. goto out_not_finished;
  4715. }
  4716. rc = lpfc_mbox_dev_check(phba);
  4717. if (unlikely(rc)) {
  4718. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4719. "(%d):2544 Mailbox command x%x (x%x) "
  4720. "cannot issue Data: x%x x%x\n",
  4721. mboxq->vport ? mboxq->vport->vpi : 0,
  4722. mboxq->u.mb.mbxCommand,
  4723. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4724. psli->sli_flag, flag);
  4725. goto out_not_finished;
  4726. }
  4727. /* Put the mailbox command to the driver internal FIFO */
  4728. psli->slistat.mbox_busy++;
  4729. spin_lock_irqsave(&phba->hbalock, iflags);
  4730. lpfc_mbox_put(phba, mboxq);
  4731. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4732. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4733. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  4734. "x%x (x%x) x%x x%x x%x\n",
  4735. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  4736. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4737. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4738. phba->pport->port_state,
  4739. psli->sli_flag, MBX_NOWAIT);
  4740. /* Wake up worker thread to transport mailbox command from head */
  4741. lpfc_worker_wake_up(phba);
  4742. return MBX_BUSY;
  4743. out_not_finished:
  4744. return MBX_NOT_FINISHED;
  4745. }
  4746. /**
  4747. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  4748. * @phba: Pointer to HBA context object.
  4749. *
  4750. * This function is called by worker thread to send a mailbox command to
  4751. * SLI4 HBA firmware.
  4752. *
  4753. **/
  4754. int
  4755. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  4756. {
  4757. struct lpfc_sli *psli = &phba->sli;
  4758. LPFC_MBOXQ_t *mboxq;
  4759. int rc = MBX_SUCCESS;
  4760. unsigned long iflags;
  4761. struct lpfc_mqe *mqe;
  4762. uint32_t mbx_cmnd;
  4763. /* Check interrupt mode before post async mailbox command */
  4764. if (unlikely(!phba->sli4_hba.intr_enable))
  4765. return MBX_NOT_FINISHED;
  4766. /* Check for mailbox command service token */
  4767. spin_lock_irqsave(&phba->hbalock, iflags);
  4768. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  4769. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4770. return MBX_NOT_FINISHED;
  4771. }
  4772. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  4773. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4774. return MBX_NOT_FINISHED;
  4775. }
  4776. if (unlikely(phba->sli.mbox_active)) {
  4777. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4778. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4779. "0384 There is pending active mailbox cmd\n");
  4780. return MBX_NOT_FINISHED;
  4781. }
  4782. /* Take the mailbox command service token */
  4783. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4784. /* Get the next mailbox command from head of queue */
  4785. mboxq = lpfc_mbox_get(phba);
  4786. /* If no more mailbox command waiting for post, we're done */
  4787. if (!mboxq) {
  4788. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4789. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4790. return MBX_SUCCESS;
  4791. }
  4792. phba->sli.mbox_active = mboxq;
  4793. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4794. /* Check device readiness for posting mailbox command */
  4795. rc = lpfc_mbox_dev_check(phba);
  4796. if (unlikely(rc))
  4797. /* Driver clean routine will clean up pending mailbox */
  4798. goto out_not_finished;
  4799. /* Prepare the mbox command to be posted */
  4800. mqe = &mboxq->u.mqe;
  4801. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  4802. /* Start timer for the mbox_tmo and log some mailbox post messages */
  4803. mod_timer(&psli->mbox_tmo, (jiffies +
  4804. (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd))));
  4805. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4806. "(%d):0355 Mailbox cmd x%x (x%x) issue Data: "
  4807. "x%x x%x\n",
  4808. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  4809. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4810. phba->pport->port_state, psli->sli_flag);
  4811. if (mbx_cmnd != MBX_HEARTBEAT) {
  4812. if (mboxq->vport) {
  4813. lpfc_debugfs_disc_trc(mboxq->vport,
  4814. LPFC_DISC_TRC_MBOX_VPORT,
  4815. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  4816. mbx_cmnd, mqe->un.mb_words[0],
  4817. mqe->un.mb_words[1]);
  4818. } else {
  4819. lpfc_debugfs_disc_trc(phba->pport,
  4820. LPFC_DISC_TRC_MBOX,
  4821. "MBOX Send: cmd:x%x mb:x%x x%x",
  4822. mbx_cmnd, mqe->un.mb_words[0],
  4823. mqe->un.mb_words[1]);
  4824. }
  4825. }
  4826. psli->slistat.mbox_cmd++;
  4827. /* Post the mailbox command to the port */
  4828. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  4829. if (rc != MBX_SUCCESS) {
  4830. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4831. "(%d):2533 Mailbox command x%x (x%x) "
  4832. "cannot issue Data: x%x x%x\n",
  4833. mboxq->vport ? mboxq->vport->vpi : 0,
  4834. mboxq->u.mb.mbxCommand,
  4835. lpfc_sli4_mbox_opcode_get(phba, mboxq),
  4836. psli->sli_flag, MBX_NOWAIT);
  4837. goto out_not_finished;
  4838. }
  4839. return rc;
  4840. out_not_finished:
  4841. spin_lock_irqsave(&phba->hbalock, iflags);
  4842. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  4843. __lpfc_mbox_cmpl_put(phba, mboxq);
  4844. /* Release the token */
  4845. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4846. phba->sli.mbox_active = NULL;
  4847. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4848. return MBX_NOT_FINISHED;
  4849. }
  4850. /**
  4851. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  4852. * @phba: Pointer to HBA context object.
  4853. * @pmbox: Pointer to mailbox object.
  4854. * @flag: Flag indicating how the mailbox need to be processed.
  4855. *
  4856. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  4857. * the API jump table function pointer from the lpfc_hba struct.
  4858. *
  4859. * Return codes the caller owns the mailbox command after the return of the
  4860. * function.
  4861. **/
  4862. int
  4863. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  4864. {
  4865. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  4866. }
  4867. /**
  4868. * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table
  4869. * @phba: The hba struct for which this call is being executed.
  4870. * @dev_grp: The HBA PCI-Device group number.
  4871. *
  4872. * This routine sets up the mbox interface API function jump table in @phba
  4873. * struct.
  4874. * Returns: 0 - success, -ENODEV - failure.
  4875. **/
  4876. int
  4877. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4878. {
  4879. switch (dev_grp) {
  4880. case LPFC_PCI_DEV_LP:
  4881. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  4882. phba->lpfc_sli_handle_slow_ring_event =
  4883. lpfc_sli_handle_slow_ring_event_s3;
  4884. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  4885. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  4886. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  4887. break;
  4888. case LPFC_PCI_DEV_OC:
  4889. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  4890. phba->lpfc_sli_handle_slow_ring_event =
  4891. lpfc_sli_handle_slow_ring_event_s4;
  4892. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  4893. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  4894. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  4895. break;
  4896. default:
  4897. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4898. "1420 Invalid HBA PCI-device group: 0x%x\n",
  4899. dev_grp);
  4900. return -ENODEV;
  4901. break;
  4902. }
  4903. return 0;
  4904. }
  4905. /**
  4906. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  4907. * @phba: Pointer to HBA context object.
  4908. * @pring: Pointer to driver SLI ring object.
  4909. * @piocb: Pointer to address of newly added command iocb.
  4910. *
  4911. * This function is called with hbalock held to add a command
  4912. * iocb to the txq when SLI layer cannot submit the command iocb
  4913. * to the ring.
  4914. **/
  4915. static void
  4916. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4917. struct lpfc_iocbq *piocb)
  4918. {
  4919. /* Insert the caller's iocb in the txq tail for later processing. */
  4920. list_add_tail(&piocb->list, &pring->txq);
  4921. pring->txq_cnt++;
  4922. }
  4923. /**
  4924. * lpfc_sli_next_iocb - Get the next iocb in the txq
  4925. * @phba: Pointer to HBA context object.
  4926. * @pring: Pointer to driver SLI ring object.
  4927. * @piocb: Pointer to address of newly added command iocb.
  4928. *
  4929. * This function is called with hbalock held before a new
  4930. * iocb is submitted to the firmware. This function checks
  4931. * txq to flush the iocbs in txq to Firmware before
  4932. * submitting new iocbs to the Firmware.
  4933. * If there are iocbs in the txq which need to be submitted
  4934. * to firmware, lpfc_sli_next_iocb returns the first element
  4935. * of the txq after dequeuing it from txq.
  4936. * If there is no iocb in the txq then the function will return
  4937. * *piocb and *piocb is set to NULL. Caller needs to check
  4938. * *piocb to find if there are more commands in the txq.
  4939. **/
  4940. static struct lpfc_iocbq *
  4941. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  4942. struct lpfc_iocbq **piocb)
  4943. {
  4944. struct lpfc_iocbq * nextiocb;
  4945. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  4946. if (!nextiocb) {
  4947. nextiocb = *piocb;
  4948. *piocb = NULL;
  4949. }
  4950. return nextiocb;
  4951. }
  4952. /**
  4953. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  4954. * @phba: Pointer to HBA context object.
  4955. * @ring_number: SLI ring number to issue iocb on.
  4956. * @piocb: Pointer to command iocb.
  4957. * @flag: Flag indicating if this command can be put into txq.
  4958. *
  4959. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  4960. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  4961. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  4962. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  4963. * this function allows only iocbs for posting buffers. This function finds
  4964. * next available slot in the command ring and posts the command to the
  4965. * available slot and writes the port attention register to request HBA start
  4966. * processing new iocb. If there is no slot available in the ring and
  4967. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  4968. * the function returns IOCB_BUSY.
  4969. *
  4970. * This function is called with hbalock held. The function will return success
  4971. * after it successfully submit the iocb to firmware or after adding to the
  4972. * txq.
  4973. **/
  4974. static int
  4975. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  4976. struct lpfc_iocbq *piocb, uint32_t flag)
  4977. {
  4978. struct lpfc_iocbq *nextiocb;
  4979. IOCB_t *iocb;
  4980. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  4981. if (piocb->iocb_cmpl && (!piocb->vport) &&
  4982. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  4983. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  4984. lpfc_printf_log(phba, KERN_ERR,
  4985. LOG_SLI | LOG_VPORT,
  4986. "1807 IOCB x%x failed. No vport\n",
  4987. piocb->iocb.ulpCommand);
  4988. dump_stack();
  4989. return IOCB_ERROR;
  4990. }
  4991. /* If the PCI channel is in offline state, do not post iocbs. */
  4992. if (unlikely(pci_channel_offline(phba->pcidev)))
  4993. return IOCB_ERROR;
  4994. /* If HBA has a deferred error attention, fail the iocb. */
  4995. if (unlikely(phba->hba_flag & DEFER_ERATT))
  4996. return IOCB_ERROR;
  4997. /*
  4998. * We should never get an IOCB if we are in a < LINK_DOWN state
  4999. */
  5000. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  5001. return IOCB_ERROR;
  5002. /*
  5003. * Check to see if we are blocking IOCB processing because of a
  5004. * outstanding event.
  5005. */
  5006. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  5007. goto iocb_busy;
  5008. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  5009. /*
  5010. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  5011. * can be issued if the link is not up.
  5012. */
  5013. switch (piocb->iocb.ulpCommand) {
  5014. case CMD_GEN_REQUEST64_CR:
  5015. case CMD_GEN_REQUEST64_CX:
  5016. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  5017. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  5018. FC_FCP_CMND) ||
  5019. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  5020. MENLO_TRANSPORT_TYPE))
  5021. goto iocb_busy;
  5022. break;
  5023. case CMD_QUE_RING_BUF_CN:
  5024. case CMD_QUE_RING_BUF64_CN:
  5025. /*
  5026. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  5027. * completion, iocb_cmpl MUST be 0.
  5028. */
  5029. if (piocb->iocb_cmpl)
  5030. piocb->iocb_cmpl = NULL;
  5031. /*FALLTHROUGH*/
  5032. case CMD_CREATE_XRI_CR:
  5033. case CMD_CLOSE_XRI_CN:
  5034. case CMD_CLOSE_XRI_CX:
  5035. break;
  5036. default:
  5037. goto iocb_busy;
  5038. }
  5039. /*
  5040. * For FCP commands, we must be in a state where we can process link
  5041. * attention events.
  5042. */
  5043. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  5044. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  5045. goto iocb_busy;
  5046. }
  5047. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  5048. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  5049. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  5050. if (iocb)
  5051. lpfc_sli_update_ring(phba, pring);
  5052. else
  5053. lpfc_sli_update_full_ring(phba, pring);
  5054. if (!piocb)
  5055. return IOCB_SUCCESS;
  5056. goto out_busy;
  5057. iocb_busy:
  5058. pring->stats.iocb_cmd_delay++;
  5059. out_busy:
  5060. if (!(flag & SLI_IOCB_RET_IOCB)) {
  5061. __lpfc_sli_ringtx_put(phba, pring, piocb);
  5062. return IOCB_SUCCESS;
  5063. }
  5064. return IOCB_BUSY;
  5065. }
  5066. /**
  5067. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  5068. * @phba: Pointer to HBA context object.
  5069. * @piocb: Pointer to command iocb.
  5070. * @sglq: Pointer to the scatter gather queue object.
  5071. *
  5072. * This routine converts the bpl or bde that is in the IOCB
  5073. * to a sgl list for the sli4 hardware. The physical address
  5074. * of the bpl/bde is converted back to a virtual address.
  5075. * If the IOCB contains a BPL then the list of BDE's is
  5076. * converted to sli4_sge's. If the IOCB contains a single
  5077. * BDE then it is converted to a single sli_sge.
  5078. * The IOCB is still in cpu endianess so the contents of
  5079. * the bpl can be used without byte swapping.
  5080. *
  5081. * Returns valid XRI = Success, NO_XRI = Failure.
  5082. **/
  5083. static uint16_t
  5084. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  5085. struct lpfc_sglq *sglq)
  5086. {
  5087. uint16_t xritag = NO_XRI;
  5088. struct ulp_bde64 *bpl = NULL;
  5089. struct ulp_bde64 bde;
  5090. struct sli4_sge *sgl = NULL;
  5091. IOCB_t *icmd;
  5092. int numBdes = 0;
  5093. int i = 0;
  5094. if (!piocbq || !sglq)
  5095. return xritag;
  5096. sgl = (struct sli4_sge *)sglq->sgl;
  5097. icmd = &piocbq->iocb;
  5098. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5099. numBdes = icmd->un.genreq64.bdl.bdeSize /
  5100. sizeof(struct ulp_bde64);
  5101. /* The addrHigh and addrLow fields within the IOCB
  5102. * have not been byteswapped yet so there is no
  5103. * need to swap them back.
  5104. */
  5105. bpl = (struct ulp_bde64 *)
  5106. ((struct lpfc_dmabuf *)piocbq->context3)->virt;
  5107. if (!bpl)
  5108. return xritag;
  5109. for (i = 0; i < numBdes; i++) {
  5110. /* Should already be byte swapped. */
  5111. sgl->addr_hi = bpl->addrHigh;
  5112. sgl->addr_lo = bpl->addrLow;
  5113. /* swap the size field back to the cpu so we
  5114. * can assign it to the sgl.
  5115. */
  5116. bde.tus.w = le32_to_cpu(bpl->tus.w);
  5117. bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
  5118. if ((i+1) == numBdes)
  5119. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5120. else
  5121. bf_set(lpfc_sli4_sge_last, sgl, 0);
  5122. sgl->word2 = cpu_to_le32(sgl->word2);
  5123. sgl->word3 = cpu_to_le32(sgl->word3);
  5124. bpl++;
  5125. sgl++;
  5126. }
  5127. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  5128. /* The addrHigh and addrLow fields of the BDE have not
  5129. * been byteswapped yet so they need to be swapped
  5130. * before putting them in the sgl.
  5131. */
  5132. sgl->addr_hi =
  5133. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  5134. sgl->addr_lo =
  5135. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  5136. bf_set(lpfc_sli4_sge_len, sgl,
  5137. icmd->un.genreq64.bdl.bdeSize);
  5138. bf_set(lpfc_sli4_sge_last, sgl, 1);
  5139. sgl->word2 = cpu_to_le32(sgl->word2);
  5140. sgl->word3 = cpu_to_le32(sgl->word3);
  5141. }
  5142. return sglq->sli4_xritag;
  5143. }
  5144. /**
  5145. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  5146. * @phba: Pointer to HBA context object.
  5147. * @piocb: Pointer to command iocb.
  5148. *
  5149. * This routine performs a round robin SCSI command to SLI4 FCP WQ index
  5150. * distribution.
  5151. *
  5152. * Return: index into SLI4 fast-path FCP queue index.
  5153. **/
  5154. static uint32_t
  5155. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  5156. {
  5157. static uint32_t fcp_qidx;
  5158. return fcp_qidx++ % phba->cfg_fcp_wq_count;
  5159. }
  5160. /**
  5161. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  5162. * @phba: Pointer to HBA context object.
  5163. * @piocb: Pointer to command iocb.
  5164. * @wqe: Pointer to the work queue entry.
  5165. *
  5166. * This routine converts the iocb command to its Work Queue Entry
  5167. * equivalent. The wqe pointer should not have any fields set when
  5168. * this routine is called because it will memcpy over them.
  5169. * This routine does not set the CQ_ID or the WQEC bits in the
  5170. * wqe.
  5171. *
  5172. * Returns: 0 = Success, IOCB_ERROR = Failure.
  5173. **/
  5174. static int
  5175. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  5176. union lpfc_wqe *wqe)
  5177. {
  5178. uint32_t payload_len = 0;
  5179. uint8_t ct = 0;
  5180. uint32_t fip;
  5181. uint32_t abort_tag;
  5182. uint8_t command_type = ELS_COMMAND_NON_FIP;
  5183. uint8_t cmnd;
  5184. uint16_t xritag;
  5185. struct ulp_bde64 *bpl = NULL;
  5186. fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags);
  5187. /* The fcp commands will set command type */
  5188. if ((!(iocbq->iocb_flag & LPFC_IO_FCP)) && (!fip))
  5189. command_type = ELS_COMMAND_NON_FIP;
  5190. else if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  5191. command_type = ELS_COMMAND_FIP;
  5192. else if (iocbq->iocb_flag & LPFC_IO_FCP)
  5193. command_type = FCP_COMMAND;
  5194. else {
  5195. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5196. "2019 Invalid cmd 0x%x\n",
  5197. iocbq->iocb.ulpCommand);
  5198. return IOCB_ERROR;
  5199. }
  5200. /* Some of the fields are in the right position already */
  5201. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  5202. abort_tag = (uint32_t) iocbq->iotag;
  5203. xritag = iocbq->sli4_xritag;
  5204. wqe->words[7] = 0; /* The ct field has moved so reset */
  5205. /* words0-2 bpl convert bde */
  5206. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  5207. bpl = (struct ulp_bde64 *)
  5208. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  5209. if (!bpl)
  5210. return IOCB_ERROR;
  5211. /* Should already be byte swapped. */
  5212. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  5213. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  5214. /* swap the size field back to the cpu so we
  5215. * can assign it to the sgl.
  5216. */
  5217. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  5218. payload_len = wqe->generic.bde.tus.f.bdeSize;
  5219. } else
  5220. payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  5221. iocbq->iocb.ulpIoTag = iocbq->iotag;
  5222. cmnd = iocbq->iocb.ulpCommand;
  5223. switch (iocbq->iocb.ulpCommand) {
  5224. case CMD_ELS_REQUEST64_CR:
  5225. if (!iocbq->iocb.ulpLe) {
  5226. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5227. "2007 Only Limited Edition cmd Format"
  5228. " supported 0x%x\n",
  5229. iocbq->iocb.ulpCommand);
  5230. return IOCB_ERROR;
  5231. }
  5232. wqe->els_req.payload_len = payload_len;
  5233. /* Els_reguest64 has a TMO */
  5234. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  5235. iocbq->iocb.ulpTimeout);
  5236. /* Need a VF for word 4 set the vf bit*/
  5237. bf_set(els_req64_vf, &wqe->els_req, 0);
  5238. /* And a VFID for word 12 */
  5239. bf_set(els_req64_vfid, &wqe->els_req, 0);
  5240. /*
  5241. * Set ct field to 3, indicates that the context_tag field
  5242. * contains the FCFI and remote N_Port_ID is
  5243. * in word 5.
  5244. */
  5245. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5246. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5247. iocbq->iocb.ulpContext);
  5248. if (iocbq->vport->fc_myDID != 0) {
  5249. bf_set(els_req64_sid, &wqe->els_req,
  5250. iocbq->vport->fc_myDID);
  5251. bf_set(els_req64_sp, &wqe->els_req, 1);
  5252. }
  5253. bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct);
  5254. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5255. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  5256. break;
  5257. case CMD_XMIT_SEQUENCE64_CR:
  5258. /* word3 iocb=io_tag32 wqe=payload_offset */
  5259. /* payload offset used for multilpe outstanding
  5260. * sequences on the same exchange
  5261. */
  5262. wqe->words[3] = 0;
  5263. /* word4 relative_offset memcpy */
  5264. /* word5 r_ctl/df_ctl memcpy */
  5265. bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0);
  5266. wqe->xmit_sequence.xmit_len = payload_len;
  5267. break;
  5268. case CMD_XMIT_BCAST64_CN:
  5269. /* word3 iocb=iotag32 wqe=payload_len */
  5270. wqe->words[3] = 0; /* no definition for this in wqe */
  5271. /* word4 iocb=rsvd wqe=rsvd */
  5272. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  5273. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  5274. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5275. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5276. break;
  5277. case CMD_FCP_IWRITE64_CR:
  5278. command_type = FCP_COMMAND_DATA_OUT;
  5279. /* The struct for wqe fcp_iwrite has 3 fields that are somewhat
  5280. * confusing.
  5281. * word3 is payload_len: byte offset to the sgl entry for the
  5282. * fcp_command.
  5283. * word4 is total xfer len, same as the IOCB->ulpParameter.
  5284. * word5 is initial xfer len 0 = wait for xfer-ready
  5285. */
  5286. /* Always wait for xfer-ready before sending data */
  5287. wqe->fcp_iwrite.initial_xfer_len = 0;
  5288. /* word 4 (xfer length) should have been set on the memcpy */
  5289. /* allow write to fall through to read */
  5290. case CMD_FCP_IREAD64_CR:
  5291. /* FCP_CMD is always the 1st sgl entry */
  5292. wqe->fcp_iread.payload_len =
  5293. payload_len + sizeof(struct fcp_rsp);
  5294. /* word 4 (xfer length) should have been set on the memcpy */
  5295. bf_set(lpfc_wqe_gen_erp, &wqe->generic,
  5296. iocbq->iocb.ulpFCP2Rcvy);
  5297. bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS);
  5298. /* The XC bit and the XS bit are similar. The driver never
  5299. * tracked whether or not the exchange was previouslly open.
  5300. * XC = Exchange create, 0 is create. 1 is already open.
  5301. * XS = link cmd: 1 do not close the exchange after command.
  5302. * XS = 0 close exchange when command completes.
  5303. * The only time we would not set the XC bit is when the XS bit
  5304. * is set and we are sending our 2nd or greater command on
  5305. * this exchange.
  5306. */
  5307. /* ALLOW read & write to fall through to ICMD64 */
  5308. case CMD_FCP_ICMND64_CR:
  5309. /* Always open the exchange */
  5310. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  5311. wqe->words[10] &= 0xffff0000; /* zero out ebde count */
  5312. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5313. break;
  5314. case CMD_GEN_REQUEST64_CR:
  5315. /* word3 command length is described as byte offset to the
  5316. * rsp_data. Would always be 16, sizeof(struct sli4_sge)
  5317. * sgl[0] = cmnd
  5318. * sgl[1] = rsp.
  5319. *
  5320. */
  5321. wqe->gen_req.command_len = payload_len;
  5322. /* Word4 parameter copied in the memcpy */
  5323. /* Word5 [rctl, type, df_ctl, la] copied in memcpy */
  5324. /* word6 context tag copied in memcpy */
  5325. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  5326. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  5327. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5328. "2015 Invalid CT %x command 0x%x\n",
  5329. ct, iocbq->iocb.ulpCommand);
  5330. return IOCB_ERROR;
  5331. }
  5332. bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0);
  5333. bf_set(wqe_tmo, &wqe->gen_req.wqe_com,
  5334. iocbq->iocb.ulpTimeout);
  5335. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5336. command_type = OTHER_COMMAND;
  5337. break;
  5338. case CMD_XMIT_ELS_RSP64_CX:
  5339. /* words0-2 BDE memcpy */
  5340. /* word3 iocb=iotag32 wqe=rsvd */
  5341. wqe->words[3] = 0;
  5342. /* word4 iocb=did wge=rsvd. */
  5343. wqe->words[4] = 0;
  5344. /* word5 iocb=rsvd wge=did */
  5345. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  5346. iocbq->iocb.un.elsreq64.remoteID);
  5347. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5348. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5349. bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU);
  5350. bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext);
  5351. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  5352. bf_set(lpfc_wqe_gen_context, &wqe->generic,
  5353. iocbq->vport->vpi + phba->vpi_base);
  5354. command_type = OTHER_COMMAND;
  5355. break;
  5356. case CMD_CLOSE_XRI_CN:
  5357. case CMD_ABORT_XRI_CN:
  5358. case CMD_ABORT_XRI_CX:
  5359. /* words 0-2 memcpy should be 0 rserved */
  5360. /* port will send abts */
  5361. if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5362. /*
  5363. * The link is down so the fw does not need to send abts
  5364. * on the wire.
  5365. */
  5366. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  5367. else
  5368. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  5369. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  5370. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5371. wqe->words[5] = 0;
  5372. bf_set(lpfc_wqe_gen_ct, &wqe->generic,
  5373. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  5374. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  5375. wqe->generic.abort_tag = abort_tag;
  5376. /*
  5377. * The abort handler will send us CMD_ABORT_XRI_CN or
  5378. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  5379. */
  5380. bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX);
  5381. cmnd = CMD_ABORT_XRI_CX;
  5382. command_type = OTHER_COMMAND;
  5383. xritag = 0;
  5384. break;
  5385. case CMD_XRI_ABORTED_CX:
  5386. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  5387. /* words0-2 are all 0's no bde */
  5388. /* word3 and word4 are rsvrd */
  5389. wqe->words[3] = 0;
  5390. wqe->words[4] = 0;
  5391. /* word5 iocb=rsvd wge=did */
  5392. /* There is no remote port id in the IOCB? */
  5393. /* Let this fall through and fail */
  5394. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  5395. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  5396. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  5397. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  5398. default:
  5399. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5400. "2014 Invalid command 0x%x\n",
  5401. iocbq->iocb.ulpCommand);
  5402. return IOCB_ERROR;
  5403. break;
  5404. }
  5405. bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag);
  5406. bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag);
  5407. wqe->generic.abort_tag = abort_tag;
  5408. bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type);
  5409. bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd);
  5410. bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass);
  5411. bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT);
  5412. return 0;
  5413. }
  5414. /**
  5415. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  5416. * @phba: Pointer to HBA context object.
  5417. * @ring_number: SLI ring number to issue iocb on.
  5418. * @piocb: Pointer to command iocb.
  5419. * @flag: Flag indicating if this command can be put into txq.
  5420. *
  5421. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  5422. * an iocb command to an HBA with SLI-4 interface spec.
  5423. *
  5424. * This function is called with hbalock held. The function will return success
  5425. * after it successfully submit the iocb to firmware or after adding to the
  5426. * txq.
  5427. **/
  5428. static int
  5429. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  5430. struct lpfc_iocbq *piocb, uint32_t flag)
  5431. {
  5432. struct lpfc_sglq *sglq;
  5433. uint16_t xritag;
  5434. union lpfc_wqe wqe;
  5435. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  5436. uint32_t fcp_wqidx;
  5437. if (piocb->sli4_xritag == NO_XRI) {
  5438. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5439. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5440. sglq = NULL;
  5441. else {
  5442. sglq = __lpfc_sli_get_sglq(phba);
  5443. if (!sglq)
  5444. return IOCB_ERROR;
  5445. piocb->sli4_xritag = sglq->sli4_xritag;
  5446. }
  5447. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  5448. sglq = NULL; /* These IO's already have an XRI and
  5449. * a mapped sgl.
  5450. */
  5451. } else {
  5452. /* This is a continuation of a commandi,(CX) so this
  5453. * sglq is on the active list
  5454. */
  5455. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  5456. if (!sglq)
  5457. return IOCB_ERROR;
  5458. }
  5459. if (sglq) {
  5460. xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq);
  5461. if (xritag != sglq->sli4_xritag)
  5462. return IOCB_ERROR;
  5463. }
  5464. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  5465. return IOCB_ERROR;
  5466. if (piocb->iocb_flag & LPFC_IO_FCP) {
  5467. fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba, piocb);
  5468. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe))
  5469. return IOCB_ERROR;
  5470. } else {
  5471. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  5472. return IOCB_ERROR;
  5473. }
  5474. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  5475. return 0;
  5476. }
  5477. /**
  5478. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  5479. *
  5480. * This routine wraps the actual lockless version for issusing IOCB function
  5481. * pointer from the lpfc_hba struct.
  5482. *
  5483. * Return codes:
  5484. * IOCB_ERROR - Error
  5485. * IOCB_SUCCESS - Success
  5486. * IOCB_BUSY - Busy
  5487. **/
  5488. static inline int
  5489. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5490. struct lpfc_iocbq *piocb, uint32_t flag)
  5491. {
  5492. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5493. }
  5494. /**
  5495. * lpfc_sli_api_table_setup - Set up sli api fucntion jump table
  5496. * @phba: The hba struct for which this call is being executed.
  5497. * @dev_grp: The HBA PCI-Device group number.
  5498. *
  5499. * This routine sets up the SLI interface API function jump table in @phba
  5500. * struct.
  5501. * Returns: 0 - success, -ENODEV - failure.
  5502. **/
  5503. int
  5504. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  5505. {
  5506. switch (dev_grp) {
  5507. case LPFC_PCI_DEV_LP:
  5508. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  5509. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  5510. break;
  5511. case LPFC_PCI_DEV_OC:
  5512. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  5513. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  5514. break;
  5515. default:
  5516. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5517. "1419 Invalid HBA PCI-device group: 0x%x\n",
  5518. dev_grp);
  5519. return -ENODEV;
  5520. break;
  5521. }
  5522. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  5523. return 0;
  5524. }
  5525. /**
  5526. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  5527. * @phba: Pointer to HBA context object.
  5528. * @pring: Pointer to driver SLI ring object.
  5529. * @piocb: Pointer to command iocb.
  5530. * @flag: Flag indicating if this command can be put into txq.
  5531. *
  5532. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  5533. * function. This function gets the hbalock and calls
  5534. * __lpfc_sli_issue_iocb function and will return the error returned
  5535. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  5536. * functions which do not hold hbalock.
  5537. **/
  5538. int
  5539. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  5540. struct lpfc_iocbq *piocb, uint32_t flag)
  5541. {
  5542. unsigned long iflags;
  5543. int rc;
  5544. spin_lock_irqsave(&phba->hbalock, iflags);
  5545. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  5546. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5547. return rc;
  5548. }
  5549. /**
  5550. * lpfc_extra_ring_setup - Extra ring setup function
  5551. * @phba: Pointer to HBA context object.
  5552. *
  5553. * This function is called while driver attaches with the
  5554. * HBA to setup the extra ring. The extra ring is used
  5555. * only when driver needs to support target mode functionality
  5556. * or IP over FC functionalities.
  5557. *
  5558. * This function is called with no lock held.
  5559. **/
  5560. static int
  5561. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  5562. {
  5563. struct lpfc_sli *psli;
  5564. struct lpfc_sli_ring *pring;
  5565. psli = &phba->sli;
  5566. /* Adjust cmd/rsp ring iocb entries more evenly */
  5567. /* Take some away from the FCP ring */
  5568. pring = &psli->ring[psli->fcp_ring];
  5569. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5570. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5571. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5572. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5573. /* and give them to the extra ring */
  5574. pring = &psli->ring[psli->extra_ring];
  5575. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5576. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5577. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5578. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5579. /* Setup default profile for this ring */
  5580. pring->iotag_max = 4096;
  5581. pring->num_mask = 1;
  5582. pring->prt[0].profile = 0; /* Mask 0 */
  5583. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  5584. pring->prt[0].type = phba->cfg_multi_ring_type;
  5585. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  5586. return 0;
  5587. }
  5588. /**
  5589. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  5590. * @phba: Pointer to HBA context object.
  5591. * @pring: Pointer to driver SLI ring object.
  5592. * @iocbq: Pointer to iocb object.
  5593. *
  5594. * This function is called by the slow ring event handler
  5595. * function when there is an ASYNC event iocb in the ring.
  5596. * This function is called with no lock held.
  5597. * Currently this function handles only temperature related
  5598. * ASYNC events. The function decodes the temperature sensor
  5599. * event message and posts events for the management applications.
  5600. **/
  5601. static void
  5602. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  5603. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  5604. {
  5605. IOCB_t *icmd;
  5606. uint16_t evt_code;
  5607. uint16_t temp;
  5608. struct temp_event temp_event_data;
  5609. struct Scsi_Host *shost;
  5610. uint32_t *iocb_w;
  5611. icmd = &iocbq->iocb;
  5612. evt_code = icmd->un.asyncstat.evt_code;
  5613. temp = icmd->ulpContext;
  5614. if ((evt_code != ASYNC_TEMP_WARN) &&
  5615. (evt_code != ASYNC_TEMP_SAFE)) {
  5616. iocb_w = (uint32_t *) icmd;
  5617. lpfc_printf_log(phba,
  5618. KERN_ERR,
  5619. LOG_SLI,
  5620. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  5621. " evt_code 0x%x \n"
  5622. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  5623. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  5624. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  5625. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  5626. pring->ringno,
  5627. icmd->un.asyncstat.evt_code,
  5628. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  5629. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  5630. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  5631. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  5632. return;
  5633. }
  5634. temp_event_data.data = (uint32_t)temp;
  5635. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  5636. if (evt_code == ASYNC_TEMP_WARN) {
  5637. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  5638. lpfc_printf_log(phba,
  5639. KERN_ERR,
  5640. LOG_TEMP,
  5641. "0347 Adapter is very hot, please take "
  5642. "corrective action. temperature : %d Celsius\n",
  5643. temp);
  5644. }
  5645. if (evt_code == ASYNC_TEMP_SAFE) {
  5646. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  5647. lpfc_printf_log(phba,
  5648. KERN_ERR,
  5649. LOG_TEMP,
  5650. "0340 Adapter temperature is OK now. "
  5651. "temperature : %d Celsius\n",
  5652. temp);
  5653. }
  5654. /* Send temperature change event to applications */
  5655. shost = lpfc_shost_from_vport(phba->pport);
  5656. fc_host_post_vendor_event(shost, fc_get_event_number(),
  5657. sizeof(temp_event_data), (char *) &temp_event_data,
  5658. LPFC_NL_VENDOR_ID);
  5659. }
  5660. /**
  5661. * lpfc_sli_setup - SLI ring setup function
  5662. * @phba: Pointer to HBA context object.
  5663. *
  5664. * lpfc_sli_setup sets up rings of the SLI interface with
  5665. * number of iocbs per ring and iotags. This function is
  5666. * called while driver attach to the HBA and before the
  5667. * interrupts are enabled. So there is no need for locking.
  5668. *
  5669. * This function always returns 0.
  5670. **/
  5671. int
  5672. lpfc_sli_setup(struct lpfc_hba *phba)
  5673. {
  5674. int i, totiocbsize = 0;
  5675. struct lpfc_sli *psli = &phba->sli;
  5676. struct lpfc_sli_ring *pring;
  5677. psli->num_rings = MAX_CONFIGURED_RINGS;
  5678. psli->sli_flag = 0;
  5679. psli->fcp_ring = LPFC_FCP_RING;
  5680. psli->next_ring = LPFC_FCP_NEXT_RING;
  5681. psli->extra_ring = LPFC_EXTRA_RING;
  5682. psli->iocbq_lookup = NULL;
  5683. psli->iocbq_lookup_len = 0;
  5684. psli->last_iotag = 0;
  5685. for (i = 0; i < psli->num_rings; i++) {
  5686. pring = &psli->ring[i];
  5687. switch (i) {
  5688. case LPFC_FCP_RING: /* ring 0 - FCP */
  5689. /* numCiocb and numRiocb are used in config_port */
  5690. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  5691. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  5692. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  5693. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  5694. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  5695. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  5696. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5697. SLI3_IOCB_CMD_SIZE :
  5698. SLI2_IOCB_CMD_SIZE;
  5699. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5700. SLI3_IOCB_RSP_SIZE :
  5701. SLI2_IOCB_RSP_SIZE;
  5702. pring->iotag_ctr = 0;
  5703. pring->iotag_max =
  5704. (phba->cfg_hba_queue_depth * 2);
  5705. pring->fast_iotag = pring->iotag_max;
  5706. pring->num_mask = 0;
  5707. break;
  5708. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  5709. /* numCiocb and numRiocb are used in config_port */
  5710. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  5711. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  5712. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5713. SLI3_IOCB_CMD_SIZE :
  5714. SLI2_IOCB_CMD_SIZE;
  5715. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5716. SLI3_IOCB_RSP_SIZE :
  5717. SLI2_IOCB_RSP_SIZE;
  5718. pring->iotag_max = phba->cfg_hba_queue_depth;
  5719. pring->num_mask = 0;
  5720. break;
  5721. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  5722. /* numCiocb and numRiocb are used in config_port */
  5723. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  5724. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  5725. pring->sizeCiocb = (phba->sli_rev == 3) ?
  5726. SLI3_IOCB_CMD_SIZE :
  5727. SLI2_IOCB_CMD_SIZE;
  5728. pring->sizeRiocb = (phba->sli_rev == 3) ?
  5729. SLI3_IOCB_RSP_SIZE :
  5730. SLI2_IOCB_RSP_SIZE;
  5731. pring->fast_iotag = 0;
  5732. pring->iotag_ctr = 0;
  5733. pring->iotag_max = 4096;
  5734. pring->lpfc_sli_rcv_async_status =
  5735. lpfc_sli_async_event_handler;
  5736. pring->num_mask = 4;
  5737. pring->prt[0].profile = 0; /* Mask 0 */
  5738. pring->prt[0].rctl = FC_ELS_REQ;
  5739. pring->prt[0].type = FC_ELS_DATA;
  5740. pring->prt[0].lpfc_sli_rcv_unsol_event =
  5741. lpfc_els_unsol_event;
  5742. pring->prt[1].profile = 0; /* Mask 1 */
  5743. pring->prt[1].rctl = FC_ELS_RSP;
  5744. pring->prt[1].type = FC_ELS_DATA;
  5745. pring->prt[1].lpfc_sli_rcv_unsol_event =
  5746. lpfc_els_unsol_event;
  5747. pring->prt[2].profile = 0; /* Mask 2 */
  5748. /* NameServer Inquiry */
  5749. pring->prt[2].rctl = FC_UNSOL_CTL;
  5750. /* NameServer */
  5751. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  5752. pring->prt[2].lpfc_sli_rcv_unsol_event =
  5753. lpfc_ct_unsol_event;
  5754. pring->prt[3].profile = 0; /* Mask 3 */
  5755. /* NameServer response */
  5756. pring->prt[3].rctl = FC_SOL_CTL;
  5757. /* NameServer */
  5758. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  5759. pring->prt[3].lpfc_sli_rcv_unsol_event =
  5760. lpfc_ct_unsol_event;
  5761. break;
  5762. }
  5763. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  5764. (pring->numRiocb * pring->sizeRiocb);
  5765. }
  5766. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  5767. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  5768. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  5769. "SLI2 SLIM Data: x%x x%lx\n",
  5770. phba->brd_no, totiocbsize,
  5771. (unsigned long) MAX_SLIM_IOCB_SIZE);
  5772. }
  5773. if (phba->cfg_multi_ring_support == 2)
  5774. lpfc_extra_ring_setup(phba);
  5775. return 0;
  5776. }
  5777. /**
  5778. * lpfc_sli_queue_setup - Queue initialization function
  5779. * @phba: Pointer to HBA context object.
  5780. *
  5781. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  5782. * ring. This function also initializes ring indices of each ring.
  5783. * This function is called during the initialization of the SLI
  5784. * interface of an HBA.
  5785. * This function is called with no lock held and always returns
  5786. * 1.
  5787. **/
  5788. int
  5789. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  5790. {
  5791. struct lpfc_sli *psli;
  5792. struct lpfc_sli_ring *pring;
  5793. int i;
  5794. psli = &phba->sli;
  5795. spin_lock_irq(&phba->hbalock);
  5796. INIT_LIST_HEAD(&psli->mboxq);
  5797. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  5798. /* Initialize list headers for txq and txcmplq as double linked lists */
  5799. for (i = 0; i < psli->num_rings; i++) {
  5800. pring = &psli->ring[i];
  5801. pring->ringno = i;
  5802. pring->next_cmdidx = 0;
  5803. pring->local_getidx = 0;
  5804. pring->cmdidx = 0;
  5805. INIT_LIST_HEAD(&pring->txq);
  5806. INIT_LIST_HEAD(&pring->txcmplq);
  5807. INIT_LIST_HEAD(&pring->iocb_continueq);
  5808. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  5809. INIT_LIST_HEAD(&pring->postbufq);
  5810. }
  5811. spin_unlock_irq(&phba->hbalock);
  5812. return 1;
  5813. }
  5814. /**
  5815. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  5816. * @phba: Pointer to HBA context object.
  5817. *
  5818. * This routine flushes the mailbox command subsystem. It will unconditionally
  5819. * flush all the mailbox commands in the three possible stages in the mailbox
  5820. * command sub-system: pending mailbox command queue; the outstanding mailbox
  5821. * command; and completed mailbox command queue. It is caller's responsibility
  5822. * to make sure that the driver is in the proper state to flush the mailbox
  5823. * command sub-system. Namely, the posting of mailbox commands into the
  5824. * pending mailbox command queue from the various clients must be stopped;
  5825. * either the HBA is in a state that it will never works on the outstanding
  5826. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  5827. * mailbox command has been completed.
  5828. **/
  5829. static void
  5830. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  5831. {
  5832. LIST_HEAD(completions);
  5833. struct lpfc_sli *psli = &phba->sli;
  5834. LPFC_MBOXQ_t *pmb;
  5835. unsigned long iflag;
  5836. /* Flush all the mailbox commands in the mbox system */
  5837. spin_lock_irqsave(&phba->hbalock, iflag);
  5838. /* The pending mailbox command queue */
  5839. list_splice_init(&phba->sli.mboxq, &completions);
  5840. /* The outstanding active mailbox command */
  5841. if (psli->mbox_active) {
  5842. list_add_tail(&psli->mbox_active->list, &completions);
  5843. psli->mbox_active = NULL;
  5844. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5845. }
  5846. /* The completed mailbox command queue */
  5847. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  5848. spin_unlock_irqrestore(&phba->hbalock, iflag);
  5849. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  5850. while (!list_empty(&completions)) {
  5851. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  5852. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  5853. if (pmb->mbox_cmpl)
  5854. pmb->mbox_cmpl(phba, pmb);
  5855. }
  5856. }
  5857. /**
  5858. * lpfc_sli_host_down - Vport cleanup function
  5859. * @vport: Pointer to virtual port object.
  5860. *
  5861. * lpfc_sli_host_down is called to clean up the resources
  5862. * associated with a vport before destroying virtual
  5863. * port data structures.
  5864. * This function does following operations:
  5865. * - Free discovery resources associated with this virtual
  5866. * port.
  5867. * - Free iocbs associated with this virtual port in
  5868. * the txq.
  5869. * - Send abort for all iocb commands associated with this
  5870. * vport in txcmplq.
  5871. *
  5872. * This function is called with no lock held and always returns 1.
  5873. **/
  5874. int
  5875. lpfc_sli_host_down(struct lpfc_vport *vport)
  5876. {
  5877. LIST_HEAD(completions);
  5878. struct lpfc_hba *phba = vport->phba;
  5879. struct lpfc_sli *psli = &phba->sli;
  5880. struct lpfc_sli_ring *pring;
  5881. struct lpfc_iocbq *iocb, *next_iocb;
  5882. int i;
  5883. unsigned long flags = 0;
  5884. uint16_t prev_pring_flag;
  5885. lpfc_cleanup_discovery_resources(vport);
  5886. spin_lock_irqsave(&phba->hbalock, flags);
  5887. for (i = 0; i < psli->num_rings; i++) {
  5888. pring = &psli->ring[i];
  5889. prev_pring_flag = pring->flag;
  5890. /* Only slow rings */
  5891. if (pring->ringno == LPFC_ELS_RING) {
  5892. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5893. /* Set the lpfc data pending flag */
  5894. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5895. }
  5896. /*
  5897. * Error everything on the txq since these iocbs have not been
  5898. * given to the FW yet.
  5899. */
  5900. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  5901. if (iocb->vport != vport)
  5902. continue;
  5903. list_move_tail(&iocb->list, &completions);
  5904. pring->txq_cnt--;
  5905. }
  5906. /* Next issue ABTS for everything on the txcmplq */
  5907. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  5908. list) {
  5909. if (iocb->vport != vport)
  5910. continue;
  5911. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  5912. }
  5913. pring->flag = prev_pring_flag;
  5914. }
  5915. spin_unlock_irqrestore(&phba->hbalock, flags);
  5916. /* Cancel all the IOCBs from the completions list */
  5917. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5918. IOERR_SLI_DOWN);
  5919. return 1;
  5920. }
  5921. /**
  5922. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  5923. * @phba: Pointer to HBA context object.
  5924. *
  5925. * This function cleans up all iocb, buffers, mailbox commands
  5926. * while shutting down the HBA. This function is called with no
  5927. * lock held and always returns 1.
  5928. * This function does the following to cleanup driver resources:
  5929. * - Free discovery resources for each virtual port
  5930. * - Cleanup any pending fabric iocbs
  5931. * - Iterate through the iocb txq and free each entry
  5932. * in the list.
  5933. * - Free up any buffer posted to the HBA
  5934. * - Free mailbox commands in the mailbox queue.
  5935. **/
  5936. int
  5937. lpfc_sli_hba_down(struct lpfc_hba *phba)
  5938. {
  5939. LIST_HEAD(completions);
  5940. struct lpfc_sli *psli = &phba->sli;
  5941. struct lpfc_sli_ring *pring;
  5942. struct lpfc_dmabuf *buf_ptr;
  5943. unsigned long flags = 0;
  5944. int i;
  5945. /* Shutdown the mailbox command sub-system */
  5946. lpfc_sli_mbox_sys_shutdown(phba);
  5947. lpfc_hba_down_prep(phba);
  5948. lpfc_fabric_abort_hba(phba);
  5949. spin_lock_irqsave(&phba->hbalock, flags);
  5950. for (i = 0; i < psli->num_rings; i++) {
  5951. pring = &psli->ring[i];
  5952. /* Only slow rings */
  5953. if (pring->ringno == LPFC_ELS_RING) {
  5954. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  5955. /* Set the lpfc data pending flag */
  5956. set_bit(LPFC_DATA_READY, &phba->data_flags);
  5957. }
  5958. /*
  5959. * Error everything on the txq since these iocbs have not been
  5960. * given to the FW yet.
  5961. */
  5962. list_splice_init(&pring->txq, &completions);
  5963. pring->txq_cnt = 0;
  5964. }
  5965. spin_unlock_irqrestore(&phba->hbalock, flags);
  5966. /* Cancel all the IOCBs from the completions list */
  5967. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5968. IOERR_SLI_DOWN);
  5969. spin_lock_irqsave(&phba->hbalock, flags);
  5970. list_splice_init(&phba->elsbuf, &completions);
  5971. phba->elsbuf_cnt = 0;
  5972. phba->elsbuf_prev_cnt = 0;
  5973. spin_unlock_irqrestore(&phba->hbalock, flags);
  5974. while (!list_empty(&completions)) {
  5975. list_remove_head(&completions, buf_ptr,
  5976. struct lpfc_dmabuf, list);
  5977. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  5978. kfree(buf_ptr);
  5979. }
  5980. /* Return any active mbox cmds */
  5981. del_timer_sync(&psli->mbox_tmo);
  5982. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  5983. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5984. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  5985. return 1;
  5986. }
  5987. /**
  5988. * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA
  5989. * @phba: Pointer to HBA context object.
  5990. *
  5991. * This function cleans up all queues, iocb, buffers, mailbox commands while
  5992. * shutting down the SLI4 HBA FCoE function. This function is called with no
  5993. * lock held and always returns 1.
  5994. *
  5995. * This function does the following to cleanup driver FCoE function resources:
  5996. * - Free discovery resources for each virtual port
  5997. * - Cleanup any pending fabric iocbs
  5998. * - Iterate through the iocb txq and free each entry in the list.
  5999. * - Free up any buffer posted to the HBA.
  6000. * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc.
  6001. * - Free mailbox commands in the mailbox queue.
  6002. **/
  6003. int
  6004. lpfc_sli4_hba_down(struct lpfc_hba *phba)
  6005. {
  6006. /* Stop the SLI4 device port */
  6007. lpfc_stop_port(phba);
  6008. /* Tear down the queues in the HBA */
  6009. lpfc_sli4_queue_unset(phba);
  6010. /* unregister default FCFI from the HBA */
  6011. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  6012. return 1;
  6013. }
  6014. /**
  6015. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  6016. * @srcp: Source memory pointer.
  6017. * @destp: Destination memory pointer.
  6018. * @cnt: Number of words required to be copied.
  6019. *
  6020. * This function is used for copying data between driver memory
  6021. * and the SLI memory. This function also changes the endianness
  6022. * of each word if native endianness is different from SLI
  6023. * endianness. This function can be called with or without
  6024. * lock.
  6025. **/
  6026. void
  6027. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  6028. {
  6029. uint32_t *src = srcp;
  6030. uint32_t *dest = destp;
  6031. uint32_t ldata;
  6032. int i;
  6033. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  6034. ldata = *src;
  6035. ldata = le32_to_cpu(ldata);
  6036. *dest = ldata;
  6037. src++;
  6038. dest++;
  6039. }
  6040. }
  6041. /**
  6042. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  6043. * @phba: Pointer to HBA context object.
  6044. * @pring: Pointer to driver SLI ring object.
  6045. * @mp: Pointer to driver buffer object.
  6046. *
  6047. * This function is called with no lock held.
  6048. * It always return zero after adding the buffer to the postbufq
  6049. * buffer list.
  6050. **/
  6051. int
  6052. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6053. struct lpfc_dmabuf *mp)
  6054. {
  6055. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  6056. later */
  6057. spin_lock_irq(&phba->hbalock);
  6058. list_add_tail(&mp->list, &pring->postbufq);
  6059. pring->postbufq_cnt++;
  6060. spin_unlock_irq(&phba->hbalock);
  6061. return 0;
  6062. }
  6063. /**
  6064. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  6065. * @phba: Pointer to HBA context object.
  6066. *
  6067. * When HBQ is enabled, buffers are searched based on tags. This function
  6068. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  6069. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  6070. * does not conflict with tags of buffer posted for unsolicited events.
  6071. * The function returns the allocated tag. The function is called with
  6072. * no locks held.
  6073. **/
  6074. uint32_t
  6075. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  6076. {
  6077. spin_lock_irq(&phba->hbalock);
  6078. phba->buffer_tag_count++;
  6079. /*
  6080. * Always set the QUE_BUFTAG_BIT to distiguish between
  6081. * a tag assigned by HBQ.
  6082. */
  6083. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  6084. spin_unlock_irq(&phba->hbalock);
  6085. return phba->buffer_tag_count;
  6086. }
  6087. /**
  6088. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  6089. * @phba: Pointer to HBA context object.
  6090. * @pring: Pointer to driver SLI ring object.
  6091. * @tag: Buffer tag.
  6092. *
  6093. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  6094. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  6095. * iocb is posted to the response ring with the tag of the buffer.
  6096. * This function searches the pring->postbufq list using the tag
  6097. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  6098. * iocb. If the buffer is found then lpfc_dmabuf object of the
  6099. * buffer is returned to the caller else NULL is returned.
  6100. * This function is called with no lock held.
  6101. **/
  6102. struct lpfc_dmabuf *
  6103. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6104. uint32_t tag)
  6105. {
  6106. struct lpfc_dmabuf *mp, *next_mp;
  6107. struct list_head *slp = &pring->postbufq;
  6108. /* Search postbufq, from the begining, looking for a match on tag */
  6109. spin_lock_irq(&phba->hbalock);
  6110. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6111. if (mp->buffer_tag == tag) {
  6112. list_del_init(&mp->list);
  6113. pring->postbufq_cnt--;
  6114. spin_unlock_irq(&phba->hbalock);
  6115. return mp;
  6116. }
  6117. }
  6118. spin_unlock_irq(&phba->hbalock);
  6119. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6120. "0402 Cannot find virtual addr for buffer tag on "
  6121. "ring %d Data x%lx x%p x%p x%x\n",
  6122. pring->ringno, (unsigned long) tag,
  6123. slp->next, slp->prev, pring->postbufq_cnt);
  6124. return NULL;
  6125. }
  6126. /**
  6127. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  6128. * @phba: Pointer to HBA context object.
  6129. * @pring: Pointer to driver SLI ring object.
  6130. * @phys: DMA address of the buffer.
  6131. *
  6132. * This function searches the buffer list using the dma_address
  6133. * of unsolicited event to find the driver's lpfc_dmabuf object
  6134. * corresponding to the dma_address. The function returns the
  6135. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  6136. * This function is called by the ct and els unsolicited event
  6137. * handlers to get the buffer associated with the unsolicited
  6138. * event.
  6139. *
  6140. * This function is called with no lock held.
  6141. **/
  6142. struct lpfc_dmabuf *
  6143. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6144. dma_addr_t phys)
  6145. {
  6146. struct lpfc_dmabuf *mp, *next_mp;
  6147. struct list_head *slp = &pring->postbufq;
  6148. /* Search postbufq, from the begining, looking for a match on phys */
  6149. spin_lock_irq(&phba->hbalock);
  6150. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  6151. if (mp->phys == phys) {
  6152. list_del_init(&mp->list);
  6153. pring->postbufq_cnt--;
  6154. spin_unlock_irq(&phba->hbalock);
  6155. return mp;
  6156. }
  6157. }
  6158. spin_unlock_irq(&phba->hbalock);
  6159. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6160. "0410 Cannot find virtual addr for mapped buf on "
  6161. "ring %d Data x%llx x%p x%p x%x\n",
  6162. pring->ringno, (unsigned long long)phys,
  6163. slp->next, slp->prev, pring->postbufq_cnt);
  6164. return NULL;
  6165. }
  6166. /**
  6167. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  6168. * @phba: Pointer to HBA context object.
  6169. * @cmdiocb: Pointer to driver command iocb object.
  6170. * @rspiocb: Pointer to driver response iocb object.
  6171. *
  6172. * This function is the completion handler for the abort iocbs for
  6173. * ELS commands. This function is called from the ELS ring event
  6174. * handler with no lock held. This function frees memory resources
  6175. * associated with the abort iocb.
  6176. **/
  6177. static void
  6178. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6179. struct lpfc_iocbq *rspiocb)
  6180. {
  6181. IOCB_t *irsp = &rspiocb->iocb;
  6182. uint16_t abort_iotag, abort_context;
  6183. struct lpfc_iocbq *abort_iocb;
  6184. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  6185. abort_iocb = NULL;
  6186. if (irsp->ulpStatus) {
  6187. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  6188. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  6189. spin_lock_irq(&phba->hbalock);
  6190. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  6191. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  6192. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  6193. "0327 Cannot abort els iocb %p "
  6194. "with tag %x context %x, abort status %x, "
  6195. "abort code %x\n",
  6196. abort_iocb, abort_iotag, abort_context,
  6197. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6198. /*
  6199. * If the iocb is not found in Firmware queue the iocb
  6200. * might have completed already. Do not free it again.
  6201. */
  6202. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  6203. spin_unlock_irq(&phba->hbalock);
  6204. lpfc_sli_release_iocbq(phba, cmdiocb);
  6205. return;
  6206. }
  6207. /*
  6208. * make sure we have the right iocbq before taking it
  6209. * off the txcmplq and try to call completion routine.
  6210. */
  6211. if (!abort_iocb ||
  6212. abort_iocb->iocb.ulpContext != abort_context ||
  6213. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  6214. spin_unlock_irq(&phba->hbalock);
  6215. else {
  6216. list_del_init(&abort_iocb->list);
  6217. pring->txcmplq_cnt--;
  6218. spin_unlock_irq(&phba->hbalock);
  6219. /* Firmware could still be in progress of DMAing
  6220. * payload, so don't free data buffer till after
  6221. * a hbeat.
  6222. */
  6223. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  6224. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  6225. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  6226. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  6227. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  6228. }
  6229. }
  6230. lpfc_sli_release_iocbq(phba, cmdiocb);
  6231. return;
  6232. }
  6233. /**
  6234. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  6235. * @phba: Pointer to HBA context object.
  6236. * @cmdiocb: Pointer to driver command iocb object.
  6237. * @rspiocb: Pointer to driver response iocb object.
  6238. *
  6239. * The function is called from SLI ring event handler with no
  6240. * lock held. This function is the completion handler for ELS commands
  6241. * which are aborted. The function frees memory resources used for
  6242. * the aborted ELS commands.
  6243. **/
  6244. static void
  6245. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6246. struct lpfc_iocbq *rspiocb)
  6247. {
  6248. IOCB_t *irsp = &rspiocb->iocb;
  6249. /* ELS cmd tag <ulpIoTag> completes */
  6250. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  6251. "0139 Ignoring ELS cmd tag x%x completion Data: "
  6252. "x%x x%x x%x\n",
  6253. irsp->ulpIoTag, irsp->ulpStatus,
  6254. irsp->un.ulpWord[4], irsp->ulpTimeout);
  6255. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  6256. lpfc_ct_free_iocb(phba, cmdiocb);
  6257. else
  6258. lpfc_els_free_iocb(phba, cmdiocb);
  6259. return;
  6260. }
  6261. /**
  6262. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  6263. * @phba: Pointer to HBA context object.
  6264. * @pring: Pointer to driver SLI ring object.
  6265. * @cmdiocb: Pointer to driver command iocb object.
  6266. *
  6267. * This function issues an abort iocb for the provided command
  6268. * iocb. This function is called with hbalock held.
  6269. * The function returns 0 when it fails due to memory allocation
  6270. * failure or when the command iocb is an abort request.
  6271. **/
  6272. int
  6273. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6274. struct lpfc_iocbq *cmdiocb)
  6275. {
  6276. struct lpfc_vport *vport = cmdiocb->vport;
  6277. struct lpfc_iocbq *abtsiocbp;
  6278. IOCB_t *icmd = NULL;
  6279. IOCB_t *iabt = NULL;
  6280. int retval = IOCB_ERROR;
  6281. /*
  6282. * There are certain command types we don't want to abort. And we
  6283. * don't want to abort commands that are already in the process of
  6284. * being aborted.
  6285. */
  6286. icmd = &cmdiocb->iocb;
  6287. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  6288. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  6289. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  6290. return 0;
  6291. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  6292. * callback so that nothing happens when it finishes.
  6293. */
  6294. if ((vport->load_flag & FC_UNLOADING) &&
  6295. (pring->ringno == LPFC_ELS_RING)) {
  6296. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  6297. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  6298. else
  6299. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  6300. goto abort_iotag_exit;
  6301. }
  6302. /* issue ABTS for this IOCB based on iotag */
  6303. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  6304. if (abtsiocbp == NULL)
  6305. return 0;
  6306. /* This signals the response to set the correct status
  6307. * before calling the completion handler.
  6308. */
  6309. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  6310. iabt = &abtsiocbp->iocb;
  6311. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  6312. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  6313. if (phba->sli_rev == LPFC_SLI_REV4)
  6314. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  6315. else
  6316. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  6317. iabt->ulpLe = 1;
  6318. iabt->ulpClass = icmd->ulpClass;
  6319. if (phba->link_state >= LPFC_LINK_UP)
  6320. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  6321. else
  6322. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  6323. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  6324. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  6325. "0339 Abort xri x%x, original iotag x%x, "
  6326. "abort cmd iotag x%x\n",
  6327. iabt->un.acxri.abortContextTag,
  6328. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  6329. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  6330. if (retval)
  6331. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  6332. abort_iotag_exit:
  6333. /*
  6334. * Caller to this routine should check for IOCB_ERROR
  6335. * and handle it properly. This routine no longer removes
  6336. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  6337. */
  6338. return retval;
  6339. }
  6340. /**
  6341. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  6342. * @iocbq: Pointer to driver iocb object.
  6343. * @vport: Pointer to driver virtual port object.
  6344. * @tgt_id: SCSI ID of the target.
  6345. * @lun_id: LUN ID of the scsi device.
  6346. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  6347. *
  6348. * This function acts as an iocb filter for functions which abort or count
  6349. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  6350. * 0 if the filtering criteria is met for the given iocb and will return
  6351. * 1 if the filtering criteria is not met.
  6352. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  6353. * given iocb is for the SCSI device specified by vport, tgt_id and
  6354. * lun_id parameter.
  6355. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  6356. * given iocb is for the SCSI target specified by vport and tgt_id
  6357. * parameters.
  6358. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  6359. * given iocb is for the SCSI host associated with the given vport.
  6360. * This function is called with no locks held.
  6361. **/
  6362. static int
  6363. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  6364. uint16_t tgt_id, uint64_t lun_id,
  6365. lpfc_ctx_cmd ctx_cmd)
  6366. {
  6367. struct lpfc_scsi_buf *lpfc_cmd;
  6368. int rc = 1;
  6369. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  6370. return rc;
  6371. if (iocbq->vport != vport)
  6372. return rc;
  6373. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  6374. if (lpfc_cmd->pCmd == NULL)
  6375. return rc;
  6376. switch (ctx_cmd) {
  6377. case LPFC_CTX_LUN:
  6378. if ((lpfc_cmd->rdata->pnode) &&
  6379. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  6380. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  6381. rc = 0;
  6382. break;
  6383. case LPFC_CTX_TGT:
  6384. if ((lpfc_cmd->rdata->pnode) &&
  6385. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  6386. rc = 0;
  6387. break;
  6388. case LPFC_CTX_HOST:
  6389. rc = 0;
  6390. break;
  6391. default:
  6392. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  6393. __func__, ctx_cmd);
  6394. break;
  6395. }
  6396. return rc;
  6397. }
  6398. /**
  6399. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  6400. * @vport: Pointer to virtual port.
  6401. * @tgt_id: SCSI ID of the target.
  6402. * @lun_id: LUN ID of the scsi device.
  6403. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6404. *
  6405. * This function returns number of FCP commands pending for the vport.
  6406. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  6407. * commands pending on the vport associated with SCSI device specified
  6408. * by tgt_id and lun_id parameters.
  6409. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  6410. * commands pending on the vport associated with SCSI target specified
  6411. * by tgt_id parameter.
  6412. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  6413. * commands pending on the vport.
  6414. * This function returns the number of iocbs which satisfy the filter.
  6415. * This function is called without any lock held.
  6416. **/
  6417. int
  6418. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  6419. lpfc_ctx_cmd ctx_cmd)
  6420. {
  6421. struct lpfc_hba *phba = vport->phba;
  6422. struct lpfc_iocbq *iocbq;
  6423. int sum, i;
  6424. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  6425. iocbq = phba->sli.iocbq_lookup[i];
  6426. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  6427. ctx_cmd) == 0)
  6428. sum++;
  6429. }
  6430. return sum;
  6431. }
  6432. /**
  6433. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  6434. * @phba: Pointer to HBA context object
  6435. * @cmdiocb: Pointer to command iocb object.
  6436. * @rspiocb: Pointer to response iocb object.
  6437. *
  6438. * This function is called when an aborted FCP iocb completes. This
  6439. * function is called by the ring event handler with no lock held.
  6440. * This function frees the iocb.
  6441. **/
  6442. void
  6443. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6444. struct lpfc_iocbq *rspiocb)
  6445. {
  6446. lpfc_sli_release_iocbq(phba, cmdiocb);
  6447. return;
  6448. }
  6449. /**
  6450. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  6451. * @vport: Pointer to virtual port.
  6452. * @pring: Pointer to driver SLI ring object.
  6453. * @tgt_id: SCSI ID of the target.
  6454. * @lun_id: LUN ID of the scsi device.
  6455. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  6456. *
  6457. * This function sends an abort command for every SCSI command
  6458. * associated with the given virtual port pending on the ring
  6459. * filtered by lpfc_sli_validate_fcp_iocb function.
  6460. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  6461. * FCP iocbs associated with lun specified by tgt_id and lun_id
  6462. * parameters
  6463. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  6464. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  6465. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  6466. * FCP iocbs associated with virtual port.
  6467. * This function returns number of iocbs it failed to abort.
  6468. * This function is called with no locks held.
  6469. **/
  6470. int
  6471. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  6472. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  6473. {
  6474. struct lpfc_hba *phba = vport->phba;
  6475. struct lpfc_iocbq *iocbq;
  6476. struct lpfc_iocbq *abtsiocb;
  6477. IOCB_t *cmd = NULL;
  6478. int errcnt = 0, ret_val = 0;
  6479. int i;
  6480. for (i = 1; i <= phba->sli.last_iotag; i++) {
  6481. iocbq = phba->sli.iocbq_lookup[i];
  6482. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  6483. abort_cmd) != 0)
  6484. continue;
  6485. /* issue ABTS for this IOCB based on iotag */
  6486. abtsiocb = lpfc_sli_get_iocbq(phba);
  6487. if (abtsiocb == NULL) {
  6488. errcnt++;
  6489. continue;
  6490. }
  6491. cmd = &iocbq->iocb;
  6492. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  6493. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  6494. if (phba->sli_rev == LPFC_SLI_REV4)
  6495. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  6496. else
  6497. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  6498. abtsiocb->iocb.ulpLe = 1;
  6499. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  6500. abtsiocb->vport = phba->pport;
  6501. if (lpfc_is_link_up(phba))
  6502. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  6503. else
  6504. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  6505. /* Setup callback routine and issue the command. */
  6506. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  6507. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  6508. abtsiocb, 0);
  6509. if (ret_val == IOCB_ERROR) {
  6510. lpfc_sli_release_iocbq(phba, abtsiocb);
  6511. errcnt++;
  6512. continue;
  6513. }
  6514. }
  6515. return errcnt;
  6516. }
  6517. /**
  6518. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  6519. * @phba: Pointer to HBA context object.
  6520. * @cmdiocbq: Pointer to command iocb.
  6521. * @rspiocbq: Pointer to response iocb.
  6522. *
  6523. * This function is the completion handler for iocbs issued using
  6524. * lpfc_sli_issue_iocb_wait function. This function is called by the
  6525. * ring event handler function without any lock held. This function
  6526. * can be called from both worker thread context and interrupt
  6527. * context. This function also can be called from other thread which
  6528. * cleans up the SLI layer objects.
  6529. * This function copy the contents of the response iocb to the
  6530. * response iocb memory object provided by the caller of
  6531. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  6532. * sleeps for the iocb completion.
  6533. **/
  6534. static void
  6535. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  6536. struct lpfc_iocbq *cmdiocbq,
  6537. struct lpfc_iocbq *rspiocbq)
  6538. {
  6539. wait_queue_head_t *pdone_q;
  6540. unsigned long iflags;
  6541. spin_lock_irqsave(&phba->hbalock, iflags);
  6542. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  6543. if (cmdiocbq->context2 && rspiocbq)
  6544. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  6545. &rspiocbq->iocb, sizeof(IOCB_t));
  6546. pdone_q = cmdiocbq->context_un.wait_queue;
  6547. if (pdone_q)
  6548. wake_up(pdone_q);
  6549. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6550. return;
  6551. }
  6552. /**
  6553. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  6554. * @phba: Pointer to HBA context object..
  6555. * @pring: Pointer to sli ring.
  6556. * @piocb: Pointer to command iocb.
  6557. * @prspiocbq: Pointer to response iocb.
  6558. * @timeout: Timeout in number of seconds.
  6559. *
  6560. * This function issues the iocb to firmware and waits for the
  6561. * iocb to complete. If the iocb command is not
  6562. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  6563. * Caller should not free the iocb resources if this function
  6564. * returns IOCB_TIMEDOUT.
  6565. * The function waits for the iocb completion using an
  6566. * non-interruptible wait.
  6567. * This function will sleep while waiting for iocb completion.
  6568. * So, this function should not be called from any context which
  6569. * does not allow sleeping. Due to the same reason, this function
  6570. * cannot be called with interrupt disabled.
  6571. * This function assumes that the iocb completions occur while
  6572. * this function sleep. So, this function cannot be called from
  6573. * the thread which process iocb completion for this ring.
  6574. * This function clears the iocb_flag of the iocb object before
  6575. * issuing the iocb and the iocb completion handler sets this
  6576. * flag and wakes this thread when the iocb completes.
  6577. * The contents of the response iocb will be copied to prspiocbq
  6578. * by the completion handler when the command completes.
  6579. * This function returns IOCB_SUCCESS when success.
  6580. * This function is called with no lock held.
  6581. **/
  6582. int
  6583. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  6584. uint32_t ring_number,
  6585. struct lpfc_iocbq *piocb,
  6586. struct lpfc_iocbq *prspiocbq,
  6587. uint32_t timeout)
  6588. {
  6589. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6590. long timeleft, timeout_req = 0;
  6591. int retval = IOCB_SUCCESS;
  6592. uint32_t creg_val;
  6593. /*
  6594. * If the caller has provided a response iocbq buffer, then context2
  6595. * is NULL or its an error.
  6596. */
  6597. if (prspiocbq) {
  6598. if (piocb->context2)
  6599. return IOCB_ERROR;
  6600. piocb->context2 = prspiocbq;
  6601. }
  6602. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  6603. piocb->context_un.wait_queue = &done_q;
  6604. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  6605. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6606. creg_val = readl(phba->HCregaddr);
  6607. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  6608. writel(creg_val, phba->HCregaddr);
  6609. readl(phba->HCregaddr); /* flush */
  6610. }
  6611. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0);
  6612. if (retval == IOCB_SUCCESS) {
  6613. timeout_req = timeout * HZ;
  6614. timeleft = wait_event_timeout(done_q,
  6615. piocb->iocb_flag & LPFC_IO_WAKE,
  6616. timeout_req);
  6617. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  6618. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6619. "0331 IOCB wake signaled\n");
  6620. } else if (timeleft == 0) {
  6621. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6622. "0338 IOCB wait timeout error - no "
  6623. "wake response Data x%x\n", timeout);
  6624. retval = IOCB_TIMEDOUT;
  6625. } else {
  6626. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  6627. "0330 IOCB wake NOT set, "
  6628. "Data x%x x%lx\n",
  6629. timeout, (timeleft / jiffies));
  6630. retval = IOCB_TIMEDOUT;
  6631. }
  6632. } else {
  6633. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  6634. "0332 IOCB wait issue failed, Data x%x\n",
  6635. retval);
  6636. retval = IOCB_ERROR;
  6637. }
  6638. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  6639. creg_val = readl(phba->HCregaddr);
  6640. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  6641. writel(creg_val, phba->HCregaddr);
  6642. readl(phba->HCregaddr); /* flush */
  6643. }
  6644. if (prspiocbq)
  6645. piocb->context2 = NULL;
  6646. piocb->context_un.wait_queue = NULL;
  6647. piocb->iocb_cmpl = NULL;
  6648. return retval;
  6649. }
  6650. /**
  6651. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  6652. * @phba: Pointer to HBA context object.
  6653. * @pmboxq: Pointer to driver mailbox object.
  6654. * @timeout: Timeout in number of seconds.
  6655. *
  6656. * This function issues the mailbox to firmware and waits for the
  6657. * mailbox command to complete. If the mailbox command is not
  6658. * completed within timeout seconds, it returns MBX_TIMEOUT.
  6659. * The function waits for the mailbox completion using an
  6660. * interruptible wait. If the thread is woken up due to a
  6661. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  6662. * should not free the mailbox resources, if this function returns
  6663. * MBX_TIMEOUT.
  6664. * This function will sleep while waiting for mailbox completion.
  6665. * So, this function should not be called from any context which
  6666. * does not allow sleeping. Due to the same reason, this function
  6667. * cannot be called with interrupt disabled.
  6668. * This function assumes that the mailbox completion occurs while
  6669. * this function sleep. So, this function cannot be called from
  6670. * the worker thread which processes mailbox completion.
  6671. * This function is called in the context of HBA management
  6672. * applications.
  6673. * This function returns MBX_SUCCESS when successful.
  6674. * This function is called with no lock held.
  6675. **/
  6676. int
  6677. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  6678. uint32_t timeout)
  6679. {
  6680. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  6681. int retval;
  6682. unsigned long flag;
  6683. /* The caller must leave context1 empty. */
  6684. if (pmboxq->context1)
  6685. return MBX_NOT_FINISHED;
  6686. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  6687. /* setup wake call as IOCB callback */
  6688. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  6689. /* setup context field to pass wait_queue pointer to wake function */
  6690. pmboxq->context1 = &done_q;
  6691. /* now issue the command */
  6692. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  6693. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  6694. wait_event_interruptible_timeout(done_q,
  6695. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  6696. timeout * HZ);
  6697. spin_lock_irqsave(&phba->hbalock, flag);
  6698. pmboxq->context1 = NULL;
  6699. /*
  6700. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  6701. * else do not free the resources.
  6702. */
  6703. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  6704. retval = MBX_SUCCESS;
  6705. else {
  6706. retval = MBX_TIMEOUT;
  6707. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  6708. }
  6709. spin_unlock_irqrestore(&phba->hbalock, flag);
  6710. }
  6711. return retval;
  6712. }
  6713. /**
  6714. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  6715. * @phba: Pointer to HBA context.
  6716. *
  6717. * This function is called to shutdown the driver's mailbox sub-system.
  6718. * It first marks the mailbox sub-system is in a block state to prevent
  6719. * the asynchronous mailbox command from issued off the pending mailbox
  6720. * command queue. If the mailbox command sub-system shutdown is due to
  6721. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  6722. * the mailbox sub-system flush routine to forcefully bring down the
  6723. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  6724. * as with offline or HBA function reset), this routine will wait for the
  6725. * outstanding mailbox command to complete before invoking the mailbox
  6726. * sub-system flush routine to gracefully bring down mailbox sub-system.
  6727. **/
  6728. void
  6729. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  6730. {
  6731. struct lpfc_sli *psli = &phba->sli;
  6732. uint8_t actcmd = MBX_HEARTBEAT;
  6733. unsigned long timeout;
  6734. spin_lock_irq(&phba->hbalock);
  6735. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6736. spin_unlock_irq(&phba->hbalock);
  6737. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6738. spin_lock_irq(&phba->hbalock);
  6739. if (phba->sli.mbox_active)
  6740. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  6741. spin_unlock_irq(&phba->hbalock);
  6742. /* Determine how long we might wait for the active mailbox
  6743. * command to be gracefully completed by firmware.
  6744. */
  6745. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) *
  6746. 1000) + jiffies;
  6747. while (phba->sli.mbox_active) {
  6748. /* Check active mailbox complete status every 2ms */
  6749. msleep(2);
  6750. if (time_after(jiffies, timeout))
  6751. /* Timeout, let the mailbox flush routine to
  6752. * forcefully release active mailbox command
  6753. */
  6754. break;
  6755. }
  6756. }
  6757. lpfc_sli_mbox_sys_flush(phba);
  6758. }
  6759. /**
  6760. * lpfc_sli_eratt_read - read sli-3 error attention events
  6761. * @phba: Pointer to HBA context.
  6762. *
  6763. * This function is called to read the SLI3 device error attention registers
  6764. * for possible error attention events. The caller must hold the hostlock
  6765. * with spin_lock_irq().
  6766. *
  6767. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6768. * Register and returns 0 otherwise.
  6769. **/
  6770. static int
  6771. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  6772. {
  6773. uint32_t ha_copy;
  6774. /* Read chip Host Attention (HA) register */
  6775. ha_copy = readl(phba->HAregaddr);
  6776. if (ha_copy & HA_ERATT) {
  6777. /* Read host status register to retrieve error event */
  6778. lpfc_sli_read_hs(phba);
  6779. /* Check if there is a deferred error condition is active */
  6780. if ((HS_FFER1 & phba->work_hs) &&
  6781. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  6782. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  6783. spin_lock_irq(&phba->hbalock);
  6784. phba->hba_flag |= DEFER_ERATT;
  6785. spin_unlock_irq(&phba->hbalock);
  6786. /* Clear all interrupt enable conditions */
  6787. writel(0, phba->HCregaddr);
  6788. readl(phba->HCregaddr);
  6789. }
  6790. /* Set the driver HA work bitmap */
  6791. spin_lock_irq(&phba->hbalock);
  6792. phba->work_ha |= HA_ERATT;
  6793. /* Indicate polling handles this ERATT */
  6794. phba->hba_flag |= HBA_ERATT_HANDLED;
  6795. spin_unlock_irq(&phba->hbalock);
  6796. return 1;
  6797. }
  6798. return 0;
  6799. }
  6800. /**
  6801. * lpfc_sli4_eratt_read - read sli-4 error attention events
  6802. * @phba: Pointer to HBA context.
  6803. *
  6804. * This function is called to read the SLI4 device error attention registers
  6805. * for possible error attention events. The caller must hold the hostlock
  6806. * with spin_lock_irq().
  6807. *
  6808. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6809. * Register and returns 0 otherwise.
  6810. **/
  6811. static int
  6812. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  6813. {
  6814. uint32_t uerr_sta_hi, uerr_sta_lo;
  6815. uint32_t onlnreg0, onlnreg1;
  6816. /* For now, use the SLI4 device internal unrecoverable error
  6817. * registers for error attention. This can be changed later.
  6818. */
  6819. onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
  6820. onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
  6821. if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
  6822. uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr);
  6823. uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr);
  6824. if (uerr_sta_lo || uerr_sta_hi) {
  6825. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6826. "1423 HBA Unrecoverable error: "
  6827. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  6828. "online0_reg=0x%x, online1_reg=0x%x\n",
  6829. uerr_sta_lo, uerr_sta_hi,
  6830. onlnreg0, onlnreg1);
  6831. /* TEMP: as the driver error recover logic is not
  6832. * fully developed, we just log the error message
  6833. * and the device error attention action is now
  6834. * temporarily disabled.
  6835. */
  6836. return 0;
  6837. phba->work_status[0] = uerr_sta_lo;
  6838. phba->work_status[1] = uerr_sta_hi;
  6839. spin_lock_irq(&phba->hbalock);
  6840. /* Set the driver HA work bitmap */
  6841. phba->work_ha |= HA_ERATT;
  6842. /* Indicate polling handles this ERATT */
  6843. phba->hba_flag |= HBA_ERATT_HANDLED;
  6844. spin_unlock_irq(&phba->hbalock);
  6845. return 1;
  6846. }
  6847. }
  6848. return 0;
  6849. }
  6850. /**
  6851. * lpfc_sli_check_eratt - check error attention events
  6852. * @phba: Pointer to HBA context.
  6853. *
  6854. * This function is called from timer soft interrupt context to check HBA's
  6855. * error attention register bit for error attention events.
  6856. *
  6857. * This fucntion returns 1 when there is Error Attention in the Host Attention
  6858. * Register and returns 0 otherwise.
  6859. **/
  6860. int
  6861. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  6862. {
  6863. uint32_t ha_copy;
  6864. /* If somebody is waiting to handle an eratt, don't process it
  6865. * here. The brdkill function will do this.
  6866. */
  6867. if (phba->link_flag & LS_IGNORE_ERATT)
  6868. return 0;
  6869. /* Check if interrupt handler handles this ERATT */
  6870. spin_lock_irq(&phba->hbalock);
  6871. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  6872. /* Interrupt handler has handled ERATT */
  6873. spin_unlock_irq(&phba->hbalock);
  6874. return 0;
  6875. }
  6876. /*
  6877. * If there is deferred error attention, do not check for error
  6878. * attention
  6879. */
  6880. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6881. spin_unlock_irq(&phba->hbalock);
  6882. return 0;
  6883. }
  6884. /* If PCI channel is offline, don't process it */
  6885. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6886. spin_unlock_irq(&phba->hbalock);
  6887. return 0;
  6888. }
  6889. switch (phba->sli_rev) {
  6890. case LPFC_SLI_REV2:
  6891. case LPFC_SLI_REV3:
  6892. /* Read chip Host Attention (HA) register */
  6893. ha_copy = lpfc_sli_eratt_read(phba);
  6894. break;
  6895. case LPFC_SLI_REV4:
  6896. /* Read devcie Uncoverable Error (UERR) registers */
  6897. ha_copy = lpfc_sli4_eratt_read(phba);
  6898. break;
  6899. default:
  6900. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6901. "0299 Invalid SLI revision (%d)\n",
  6902. phba->sli_rev);
  6903. ha_copy = 0;
  6904. break;
  6905. }
  6906. spin_unlock_irq(&phba->hbalock);
  6907. return ha_copy;
  6908. }
  6909. /**
  6910. * lpfc_intr_state_check - Check device state for interrupt handling
  6911. * @phba: Pointer to HBA context.
  6912. *
  6913. * This inline routine checks whether a device or its PCI slot is in a state
  6914. * that the interrupt should be handled.
  6915. *
  6916. * This function returns 0 if the device or the PCI slot is in a state that
  6917. * interrupt should be handled, otherwise -EIO.
  6918. */
  6919. static inline int
  6920. lpfc_intr_state_check(struct lpfc_hba *phba)
  6921. {
  6922. /* If the pci channel is offline, ignore all the interrupts */
  6923. if (unlikely(pci_channel_offline(phba->pcidev)))
  6924. return -EIO;
  6925. /* Update device level interrupt statistics */
  6926. phba->sli.slistat.sli_intr++;
  6927. /* Ignore all interrupts during initialization. */
  6928. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6929. return -EIO;
  6930. return 0;
  6931. }
  6932. /**
  6933. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  6934. * @irq: Interrupt number.
  6935. * @dev_id: The device context pointer.
  6936. *
  6937. * This function is directly called from the PCI layer as an interrupt
  6938. * service routine when device with SLI-3 interface spec is enabled with
  6939. * MSI-X multi-message interrupt mode and there are slow-path events in
  6940. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  6941. * interrupt mode, this function is called as part of the device-level
  6942. * interrupt handler. When the PCI slot is in error recovery or the HBA
  6943. * is undergoing initialization, the interrupt handler will not process
  6944. * the interrupt. The link attention and ELS ring attention events are
  6945. * handled by the worker thread. The interrupt handler signals the worker
  6946. * thread and returns for these events. This function is called without
  6947. * any lock held. It gets the hbalock to access and update SLI data
  6948. * structures.
  6949. *
  6950. * This function returns IRQ_HANDLED when interrupt is handled else it
  6951. * returns IRQ_NONE.
  6952. **/
  6953. irqreturn_t
  6954. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  6955. {
  6956. struct lpfc_hba *phba;
  6957. uint32_t ha_copy;
  6958. uint32_t work_ha_copy;
  6959. unsigned long status;
  6960. unsigned long iflag;
  6961. uint32_t control;
  6962. MAILBOX_t *mbox, *pmbox;
  6963. struct lpfc_vport *vport;
  6964. struct lpfc_nodelist *ndlp;
  6965. struct lpfc_dmabuf *mp;
  6966. LPFC_MBOXQ_t *pmb;
  6967. int rc;
  6968. /*
  6969. * Get the driver's phba structure from the dev_id and
  6970. * assume the HBA is not interrupting.
  6971. */
  6972. phba = (struct lpfc_hba *)dev_id;
  6973. if (unlikely(!phba))
  6974. return IRQ_NONE;
  6975. /*
  6976. * Stuff needs to be attented to when this function is invoked as an
  6977. * individual interrupt handler in MSI-X multi-message interrupt mode
  6978. */
  6979. if (phba->intr_type == MSIX) {
  6980. /* Check device state for handling interrupt */
  6981. if (lpfc_intr_state_check(phba))
  6982. return IRQ_NONE;
  6983. /* Need to read HA REG for slow-path events */
  6984. spin_lock_irqsave(&phba->hbalock, iflag);
  6985. ha_copy = readl(phba->HAregaddr);
  6986. /* If somebody is waiting to handle an eratt don't process it
  6987. * here. The brdkill function will do this.
  6988. */
  6989. if (phba->link_flag & LS_IGNORE_ERATT)
  6990. ha_copy &= ~HA_ERATT;
  6991. /* Check the need for handling ERATT in interrupt handler */
  6992. if (ha_copy & HA_ERATT) {
  6993. if (phba->hba_flag & HBA_ERATT_HANDLED)
  6994. /* ERATT polling has handled ERATT */
  6995. ha_copy &= ~HA_ERATT;
  6996. else
  6997. /* Indicate interrupt handler handles ERATT */
  6998. phba->hba_flag |= HBA_ERATT_HANDLED;
  6999. }
  7000. /*
  7001. * If there is deferred error attention, do not check for any
  7002. * interrupt.
  7003. */
  7004. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7005. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7006. return IRQ_NONE;
  7007. }
  7008. /* Clear up only attention source related to slow-path */
  7009. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  7010. phba->HAregaddr);
  7011. readl(phba->HAregaddr); /* flush */
  7012. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7013. } else
  7014. ha_copy = phba->ha_copy;
  7015. work_ha_copy = ha_copy & phba->work_ha_mask;
  7016. if (work_ha_copy) {
  7017. if (work_ha_copy & HA_LATT) {
  7018. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  7019. /*
  7020. * Turn off Link Attention interrupts
  7021. * until CLEAR_LA done
  7022. */
  7023. spin_lock_irqsave(&phba->hbalock, iflag);
  7024. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  7025. control = readl(phba->HCregaddr);
  7026. control &= ~HC_LAINT_ENA;
  7027. writel(control, phba->HCregaddr);
  7028. readl(phba->HCregaddr); /* flush */
  7029. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7030. }
  7031. else
  7032. work_ha_copy &= ~HA_LATT;
  7033. }
  7034. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  7035. /*
  7036. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  7037. * the only slow ring.
  7038. */
  7039. status = (work_ha_copy &
  7040. (HA_RXMASK << (4*LPFC_ELS_RING)));
  7041. status >>= (4*LPFC_ELS_RING);
  7042. if (status & HA_RXMASK) {
  7043. spin_lock_irqsave(&phba->hbalock, iflag);
  7044. control = readl(phba->HCregaddr);
  7045. lpfc_debugfs_slow_ring_trc(phba,
  7046. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  7047. control, status,
  7048. (uint32_t)phba->sli.slistat.sli_intr);
  7049. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  7050. lpfc_debugfs_slow_ring_trc(phba,
  7051. "ISR Disable ring:"
  7052. "pwork:x%x hawork:x%x wait:x%x",
  7053. phba->work_ha, work_ha_copy,
  7054. (uint32_t)((unsigned long)
  7055. &phba->work_waitq));
  7056. control &=
  7057. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  7058. writel(control, phba->HCregaddr);
  7059. readl(phba->HCregaddr); /* flush */
  7060. }
  7061. else {
  7062. lpfc_debugfs_slow_ring_trc(phba,
  7063. "ISR slow ring: pwork:"
  7064. "x%x hawork:x%x wait:x%x",
  7065. phba->work_ha, work_ha_copy,
  7066. (uint32_t)((unsigned long)
  7067. &phba->work_waitq));
  7068. }
  7069. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7070. }
  7071. }
  7072. spin_lock_irqsave(&phba->hbalock, iflag);
  7073. if (work_ha_copy & HA_ERATT) {
  7074. lpfc_sli_read_hs(phba);
  7075. /*
  7076. * Check if there is a deferred error condition
  7077. * is active
  7078. */
  7079. if ((HS_FFER1 & phba->work_hs) &&
  7080. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  7081. HS_FFER6 | HS_FFER7) & phba->work_hs)) {
  7082. phba->hba_flag |= DEFER_ERATT;
  7083. /* Clear all interrupt enable conditions */
  7084. writel(0, phba->HCregaddr);
  7085. readl(phba->HCregaddr);
  7086. }
  7087. }
  7088. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  7089. pmb = phba->sli.mbox_active;
  7090. pmbox = &pmb->u.mb;
  7091. mbox = phba->mbox;
  7092. vport = pmb->vport;
  7093. /* First check out the status word */
  7094. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  7095. if (pmbox->mbxOwner != OWN_HOST) {
  7096. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7097. /*
  7098. * Stray Mailbox Interrupt, mbxCommand <cmd>
  7099. * mbxStatus <status>
  7100. */
  7101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7102. LOG_SLI,
  7103. "(%d):0304 Stray Mailbox "
  7104. "Interrupt mbxCommand x%x "
  7105. "mbxStatus x%x\n",
  7106. (vport ? vport->vpi : 0),
  7107. pmbox->mbxCommand,
  7108. pmbox->mbxStatus);
  7109. /* clear mailbox attention bit */
  7110. work_ha_copy &= ~HA_MBATT;
  7111. } else {
  7112. phba->sli.mbox_active = NULL;
  7113. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7114. phba->last_completion_time = jiffies;
  7115. del_timer(&phba->sli.mbox_tmo);
  7116. if (pmb->mbox_cmpl) {
  7117. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  7118. MAILBOX_CMD_SIZE);
  7119. }
  7120. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7121. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7122. lpfc_debugfs_disc_trc(vport,
  7123. LPFC_DISC_TRC_MBOX_VPORT,
  7124. "MBOX dflt rpi: : "
  7125. "status:x%x rpi:x%x",
  7126. (uint32_t)pmbox->mbxStatus,
  7127. pmbox->un.varWords[0], 0);
  7128. if (!pmbox->mbxStatus) {
  7129. mp = (struct lpfc_dmabuf *)
  7130. (pmb->context1);
  7131. ndlp = (struct lpfc_nodelist *)
  7132. pmb->context2;
  7133. /* Reg_LOGIN of dflt RPI was
  7134. * successful. new lets get
  7135. * rid of the RPI using the
  7136. * same mbox buffer.
  7137. */
  7138. lpfc_unreg_login(phba,
  7139. vport->vpi,
  7140. pmbox->un.varWords[0],
  7141. pmb);
  7142. pmb->mbox_cmpl =
  7143. lpfc_mbx_cmpl_dflt_rpi;
  7144. pmb->context1 = mp;
  7145. pmb->context2 = ndlp;
  7146. pmb->vport = vport;
  7147. rc = lpfc_sli_issue_mbox(phba,
  7148. pmb,
  7149. MBX_NOWAIT);
  7150. if (rc != MBX_BUSY)
  7151. lpfc_printf_log(phba,
  7152. KERN_ERR,
  7153. LOG_MBOX | LOG_SLI,
  7154. "0350 rc should have"
  7155. "been MBX_BUSY");
  7156. if (rc != MBX_NOT_FINISHED)
  7157. goto send_current_mbox;
  7158. }
  7159. }
  7160. spin_lock_irqsave(
  7161. &phba->pport->work_port_lock,
  7162. iflag);
  7163. phba->pport->work_port_events &=
  7164. ~WORKER_MBOX_TMO;
  7165. spin_unlock_irqrestore(
  7166. &phba->pport->work_port_lock,
  7167. iflag);
  7168. lpfc_mbox_cmpl_put(phba, pmb);
  7169. }
  7170. } else
  7171. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7172. if ((work_ha_copy & HA_MBATT) &&
  7173. (phba->sli.mbox_active == NULL)) {
  7174. send_current_mbox:
  7175. /* Process next mailbox command if there is one */
  7176. do {
  7177. rc = lpfc_sli_issue_mbox(phba, NULL,
  7178. MBX_NOWAIT);
  7179. } while (rc == MBX_NOT_FINISHED);
  7180. if (rc != MBX_SUCCESS)
  7181. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7182. LOG_SLI, "0349 rc should be "
  7183. "MBX_SUCCESS");
  7184. }
  7185. spin_lock_irqsave(&phba->hbalock, iflag);
  7186. phba->work_ha |= work_ha_copy;
  7187. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7188. lpfc_worker_wake_up(phba);
  7189. }
  7190. return IRQ_HANDLED;
  7191. } /* lpfc_sli_sp_intr_handler */
  7192. /**
  7193. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  7194. * @irq: Interrupt number.
  7195. * @dev_id: The device context pointer.
  7196. *
  7197. * This function is directly called from the PCI layer as an interrupt
  7198. * service routine when device with SLI-3 interface spec is enabled with
  7199. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  7200. * ring event in the HBA. However, when the device is enabled with either
  7201. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  7202. * device-level interrupt handler. When the PCI slot is in error recovery
  7203. * or the HBA is undergoing initialization, the interrupt handler will not
  7204. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  7205. * the intrrupt context. This function is called without any lock held.
  7206. * It gets the hbalock to access and update SLI data structures.
  7207. *
  7208. * This function returns IRQ_HANDLED when interrupt is handled else it
  7209. * returns IRQ_NONE.
  7210. **/
  7211. irqreturn_t
  7212. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  7213. {
  7214. struct lpfc_hba *phba;
  7215. uint32_t ha_copy;
  7216. unsigned long status;
  7217. unsigned long iflag;
  7218. /* Get the driver's phba structure from the dev_id and
  7219. * assume the HBA is not interrupting.
  7220. */
  7221. phba = (struct lpfc_hba *) dev_id;
  7222. if (unlikely(!phba))
  7223. return IRQ_NONE;
  7224. /*
  7225. * Stuff needs to be attented to when this function is invoked as an
  7226. * individual interrupt handler in MSI-X multi-message interrupt mode
  7227. */
  7228. if (phba->intr_type == MSIX) {
  7229. /* Check device state for handling interrupt */
  7230. if (lpfc_intr_state_check(phba))
  7231. return IRQ_NONE;
  7232. /* Need to read HA REG for FCP ring and other ring events */
  7233. ha_copy = readl(phba->HAregaddr);
  7234. /* Clear up only attention source related to fast-path */
  7235. spin_lock_irqsave(&phba->hbalock, iflag);
  7236. /*
  7237. * If there is deferred error attention, do not check for
  7238. * any interrupt.
  7239. */
  7240. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7241. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7242. return IRQ_NONE;
  7243. }
  7244. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  7245. phba->HAregaddr);
  7246. readl(phba->HAregaddr); /* flush */
  7247. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7248. } else
  7249. ha_copy = phba->ha_copy;
  7250. /*
  7251. * Process all events on FCP ring. Take the optimized path for FCP IO.
  7252. */
  7253. ha_copy &= ~(phba->work_ha_mask);
  7254. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7255. status >>= (4*LPFC_FCP_RING);
  7256. if (status & HA_RXMASK)
  7257. lpfc_sli_handle_fast_ring_event(phba,
  7258. &phba->sli.ring[LPFC_FCP_RING],
  7259. status);
  7260. if (phba->cfg_multi_ring_support == 2) {
  7261. /*
  7262. * Process all events on extra ring. Take the optimized path
  7263. * for extra ring IO.
  7264. */
  7265. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7266. status >>= (4*LPFC_EXTRA_RING);
  7267. if (status & HA_RXMASK) {
  7268. lpfc_sli_handle_fast_ring_event(phba,
  7269. &phba->sli.ring[LPFC_EXTRA_RING],
  7270. status);
  7271. }
  7272. }
  7273. return IRQ_HANDLED;
  7274. } /* lpfc_sli_fp_intr_handler */
  7275. /**
  7276. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  7277. * @irq: Interrupt number.
  7278. * @dev_id: The device context pointer.
  7279. *
  7280. * This function is the HBA device-level interrupt handler to device with
  7281. * SLI-3 interface spec, called from the PCI layer when either MSI or
  7282. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  7283. * requires driver attention. This function invokes the slow-path interrupt
  7284. * attention handling function and fast-path interrupt attention handling
  7285. * function in turn to process the relevant HBA attention events. This
  7286. * function is called without any lock held. It gets the hbalock to access
  7287. * and update SLI data structures.
  7288. *
  7289. * This function returns IRQ_HANDLED when interrupt is handled, else it
  7290. * returns IRQ_NONE.
  7291. **/
  7292. irqreturn_t
  7293. lpfc_sli_intr_handler(int irq, void *dev_id)
  7294. {
  7295. struct lpfc_hba *phba;
  7296. irqreturn_t sp_irq_rc, fp_irq_rc;
  7297. unsigned long status1, status2;
  7298. /*
  7299. * Get the driver's phba structure from the dev_id and
  7300. * assume the HBA is not interrupting.
  7301. */
  7302. phba = (struct lpfc_hba *) dev_id;
  7303. if (unlikely(!phba))
  7304. return IRQ_NONE;
  7305. /* Check device state for handling interrupt */
  7306. if (lpfc_intr_state_check(phba))
  7307. return IRQ_NONE;
  7308. spin_lock(&phba->hbalock);
  7309. phba->ha_copy = readl(phba->HAregaddr);
  7310. if (unlikely(!phba->ha_copy)) {
  7311. spin_unlock(&phba->hbalock);
  7312. return IRQ_NONE;
  7313. } else if (phba->ha_copy & HA_ERATT) {
  7314. if (phba->hba_flag & HBA_ERATT_HANDLED)
  7315. /* ERATT polling has handled ERATT */
  7316. phba->ha_copy &= ~HA_ERATT;
  7317. else
  7318. /* Indicate interrupt handler handles ERATT */
  7319. phba->hba_flag |= HBA_ERATT_HANDLED;
  7320. }
  7321. /*
  7322. * If there is deferred error attention, do not check for any interrupt.
  7323. */
  7324. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  7325. spin_unlock_irq(&phba->hbalock);
  7326. return IRQ_NONE;
  7327. }
  7328. /* Clear attention sources except link and error attentions */
  7329. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  7330. readl(phba->HAregaddr); /* flush */
  7331. spin_unlock(&phba->hbalock);
  7332. /*
  7333. * Invokes slow-path host attention interrupt handling as appropriate.
  7334. */
  7335. /* status of events with mailbox and link attention */
  7336. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  7337. /* status of events with ELS ring */
  7338. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  7339. status2 >>= (4*LPFC_ELS_RING);
  7340. if (status1 || (status2 & HA_RXMASK))
  7341. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  7342. else
  7343. sp_irq_rc = IRQ_NONE;
  7344. /*
  7345. * Invoke fast-path host attention interrupt handling as appropriate.
  7346. */
  7347. /* status of events with FCP ring */
  7348. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  7349. status1 >>= (4*LPFC_FCP_RING);
  7350. /* status of events with extra ring */
  7351. if (phba->cfg_multi_ring_support == 2) {
  7352. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  7353. status2 >>= (4*LPFC_EXTRA_RING);
  7354. } else
  7355. status2 = 0;
  7356. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  7357. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  7358. else
  7359. fp_irq_rc = IRQ_NONE;
  7360. /* Return device-level interrupt handling status */
  7361. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  7362. } /* lpfc_sli_intr_handler */
  7363. /**
  7364. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  7365. * @phba: pointer to lpfc hba data structure.
  7366. *
  7367. * This routine is invoked by the worker thread to process all the pending
  7368. * SLI4 FCP abort XRI events.
  7369. **/
  7370. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  7371. {
  7372. struct lpfc_cq_event *cq_event;
  7373. /* First, declare the fcp xri abort event has been handled */
  7374. spin_lock_irq(&phba->hbalock);
  7375. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  7376. spin_unlock_irq(&phba->hbalock);
  7377. /* Now, handle all the fcp xri abort events */
  7378. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  7379. /* Get the first event from the head of the event queue */
  7380. spin_lock_irq(&phba->hbalock);
  7381. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  7382. cq_event, struct lpfc_cq_event, list);
  7383. spin_unlock_irq(&phba->hbalock);
  7384. /* Notify aborted XRI for FCP work queue */
  7385. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7386. /* Free the event processed back to the free pool */
  7387. lpfc_sli4_cq_event_release(phba, cq_event);
  7388. }
  7389. }
  7390. /**
  7391. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  7392. * @phba: pointer to lpfc hba data structure.
  7393. *
  7394. * This routine is invoked by the worker thread to process all the pending
  7395. * SLI4 els abort xri events.
  7396. **/
  7397. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  7398. {
  7399. struct lpfc_cq_event *cq_event;
  7400. /* First, declare the els xri abort event has been handled */
  7401. spin_lock_irq(&phba->hbalock);
  7402. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  7403. spin_unlock_irq(&phba->hbalock);
  7404. /* Now, handle all the els xri abort events */
  7405. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  7406. /* Get the first event from the head of the event queue */
  7407. spin_lock_irq(&phba->hbalock);
  7408. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  7409. cq_event, struct lpfc_cq_event, list);
  7410. spin_unlock_irq(&phba->hbalock);
  7411. /* Notify aborted XRI for ELS work queue */
  7412. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  7413. /* Free the event processed back to the free pool */
  7414. lpfc_sli4_cq_event_release(phba, cq_event);
  7415. }
  7416. }
  7417. static void
  7418. lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
  7419. struct lpfc_iocbq *pIocbOut,
  7420. struct lpfc_wcqe_complete *wcqe)
  7421. {
  7422. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  7423. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  7424. sizeof(struct lpfc_iocbq) - offset);
  7425. memset(&pIocbIn->sli4_info, 0,
  7426. sizeof(struct lpfc_sli4_rspiocb_info));
  7427. /* Map WCQE parameters into irspiocb parameters */
  7428. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  7429. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  7430. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  7431. pIocbIn->iocb.un.fcpi.fcpi_parm =
  7432. pIocbOut->iocb.un.fcpi.fcpi_parm -
  7433. wcqe->total_data_placed;
  7434. else
  7435. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7436. else
  7437. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  7438. /* Load in additional WCQE parameters */
  7439. pIocbIn->sli4_info.hw_status = bf_get(lpfc_wcqe_c_hw_status, wcqe);
  7440. pIocbIn->sli4_info.bfield = 0;
  7441. if (bf_get(lpfc_wcqe_c_xb, wcqe))
  7442. pIocbIn->sli4_info.bfield |= LPFC_XB;
  7443. if (bf_get(lpfc_wcqe_c_pv, wcqe)) {
  7444. pIocbIn->sli4_info.bfield |= LPFC_PV;
  7445. pIocbIn->sli4_info.priority =
  7446. bf_get(lpfc_wcqe_c_priority, wcqe);
  7447. }
  7448. }
  7449. /**
  7450. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  7451. * @phba: Pointer to HBA context object.
  7452. * @cqe: Pointer to mailbox completion queue entry.
  7453. *
  7454. * This routine process a mailbox completion queue entry with asynchrous
  7455. * event.
  7456. *
  7457. * Return: true if work posted to worker thread, otherwise false.
  7458. **/
  7459. static bool
  7460. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7461. {
  7462. struct lpfc_cq_event *cq_event;
  7463. unsigned long iflags;
  7464. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7465. "0392 Async Event: word0:x%x, word1:x%x, "
  7466. "word2:x%x, word3:x%x\n", mcqe->word0,
  7467. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  7468. /* Allocate a new internal CQ_EVENT entry */
  7469. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7470. if (!cq_event) {
  7471. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7472. "0394 Failed to allocate CQ_EVENT entry\n");
  7473. return false;
  7474. }
  7475. /* Move the CQE into an asynchronous event entry */
  7476. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  7477. spin_lock_irqsave(&phba->hbalock, iflags);
  7478. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  7479. /* Set the async event flag */
  7480. phba->hba_flag |= ASYNC_EVENT;
  7481. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7482. return true;
  7483. }
  7484. /**
  7485. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  7486. * @phba: Pointer to HBA context object.
  7487. * @cqe: Pointer to mailbox completion queue entry.
  7488. *
  7489. * This routine process a mailbox completion queue entry with mailbox
  7490. * completion event.
  7491. *
  7492. * Return: true if work posted to worker thread, otherwise false.
  7493. **/
  7494. static bool
  7495. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  7496. {
  7497. uint32_t mcqe_status;
  7498. MAILBOX_t *mbox, *pmbox;
  7499. struct lpfc_mqe *mqe;
  7500. struct lpfc_vport *vport;
  7501. struct lpfc_nodelist *ndlp;
  7502. struct lpfc_dmabuf *mp;
  7503. unsigned long iflags;
  7504. LPFC_MBOXQ_t *pmb;
  7505. bool workposted = false;
  7506. int rc;
  7507. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  7508. if (!bf_get(lpfc_trailer_completed, mcqe))
  7509. goto out_no_mqe_complete;
  7510. /* Get the reference to the active mbox command */
  7511. spin_lock_irqsave(&phba->hbalock, iflags);
  7512. pmb = phba->sli.mbox_active;
  7513. if (unlikely(!pmb)) {
  7514. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  7515. "1832 No pending MBOX command to handle\n");
  7516. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7517. goto out_no_mqe_complete;
  7518. }
  7519. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7520. mqe = &pmb->u.mqe;
  7521. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  7522. mbox = phba->mbox;
  7523. vport = pmb->vport;
  7524. /* Reset heartbeat timer */
  7525. phba->last_completion_time = jiffies;
  7526. del_timer(&phba->sli.mbox_tmo);
  7527. /* Move mbox data to caller's mailbox region, do endian swapping */
  7528. if (pmb->mbox_cmpl && mbox)
  7529. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  7530. /* Set the mailbox status with SLI4 range 0x4000 */
  7531. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  7532. if (mcqe_status != MB_CQE_STATUS_SUCCESS)
  7533. bf_set(lpfc_mqe_status, mqe,
  7534. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  7535. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  7536. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  7537. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  7538. "MBOX dflt rpi: status:x%x rpi:x%x",
  7539. mcqe_status,
  7540. pmbox->un.varWords[0], 0);
  7541. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  7542. mp = (struct lpfc_dmabuf *)(pmb->context1);
  7543. ndlp = (struct lpfc_nodelist *)pmb->context2;
  7544. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  7545. * RID of the PPI using the same mbox buffer.
  7546. */
  7547. lpfc_unreg_login(phba, vport->vpi,
  7548. pmbox->un.varWords[0], pmb);
  7549. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  7550. pmb->context1 = mp;
  7551. pmb->context2 = ndlp;
  7552. pmb->vport = vport;
  7553. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  7554. if (rc != MBX_BUSY)
  7555. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  7556. LOG_SLI, "0385 rc should "
  7557. "have been MBX_BUSY\n");
  7558. if (rc != MBX_NOT_FINISHED)
  7559. goto send_current_mbox;
  7560. }
  7561. }
  7562. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  7563. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  7564. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  7565. /* There is mailbox completion work to do */
  7566. spin_lock_irqsave(&phba->hbalock, iflags);
  7567. __lpfc_mbox_cmpl_put(phba, pmb);
  7568. phba->work_ha |= HA_MBATT;
  7569. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7570. workposted = true;
  7571. send_current_mbox:
  7572. spin_lock_irqsave(&phba->hbalock, iflags);
  7573. /* Release the mailbox command posting token */
  7574. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7575. /* Setting active mailbox pointer need to be in sync to flag clear */
  7576. phba->sli.mbox_active = NULL;
  7577. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7578. /* Wake up worker thread to post the next pending mailbox command */
  7579. lpfc_worker_wake_up(phba);
  7580. out_no_mqe_complete:
  7581. if (bf_get(lpfc_trailer_consumed, mcqe))
  7582. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  7583. return workposted;
  7584. }
  7585. /**
  7586. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  7587. * @phba: Pointer to HBA context object.
  7588. * @cqe: Pointer to mailbox completion queue entry.
  7589. *
  7590. * This routine process a mailbox completion queue entry, it invokes the
  7591. * proper mailbox complete handling or asynchrous event handling routine
  7592. * according to the MCQE's async bit.
  7593. *
  7594. * Return: true if work posted to worker thread, otherwise false.
  7595. **/
  7596. static bool
  7597. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7598. {
  7599. struct lpfc_mcqe mcqe;
  7600. bool workposted;
  7601. /* Copy the mailbox MCQE and convert endian order as needed */
  7602. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  7603. /* Invoke the proper event handling routine */
  7604. if (!bf_get(lpfc_trailer_async, &mcqe))
  7605. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  7606. else
  7607. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  7608. return workposted;
  7609. }
  7610. /**
  7611. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  7612. * @phba: Pointer to HBA context object.
  7613. * @wcqe: Pointer to work-queue completion queue entry.
  7614. *
  7615. * This routine handles an ELS work-queue completion event.
  7616. *
  7617. * Return: true if work posted to worker thread, otherwise false.
  7618. **/
  7619. static bool
  7620. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  7621. struct lpfc_wcqe_complete *wcqe)
  7622. {
  7623. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7624. struct lpfc_iocbq *cmdiocbq;
  7625. struct lpfc_iocbq *irspiocbq;
  7626. unsigned long iflags;
  7627. bool workposted = false;
  7628. spin_lock_irqsave(&phba->hbalock, iflags);
  7629. pring->stats.iocb_event++;
  7630. /* Look up the ELS command IOCB and create pseudo response IOCB */
  7631. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7632. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7633. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7634. if (unlikely(!cmdiocbq)) {
  7635. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7636. "0386 ELS complete with no corresponding "
  7637. "cmdiocb: iotag (%d)\n",
  7638. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7639. return workposted;
  7640. }
  7641. /* Fake the irspiocbq and copy necessary response information */
  7642. irspiocbq = lpfc_sli_get_iocbq(phba);
  7643. if (!irspiocbq) {
  7644. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7645. "0387 Failed to allocate an iocbq\n");
  7646. return workposted;
  7647. }
  7648. lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe);
  7649. /* Add the irspiocb to the response IOCB work list */
  7650. spin_lock_irqsave(&phba->hbalock, iflags);
  7651. list_add_tail(&irspiocbq->list, &phba->sli4_hba.sp_rspiocb_work_queue);
  7652. /* Indicate ELS ring attention */
  7653. phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING));
  7654. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7655. workposted = true;
  7656. return workposted;
  7657. }
  7658. /**
  7659. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  7660. * @phba: Pointer to HBA context object.
  7661. * @wcqe: Pointer to work-queue completion queue entry.
  7662. *
  7663. * This routine handles slow-path WQ entry comsumed event by invoking the
  7664. * proper WQ release routine to the slow-path WQ.
  7665. **/
  7666. static void
  7667. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  7668. struct lpfc_wcqe_release *wcqe)
  7669. {
  7670. /* Check for the slow-path ELS work queue */
  7671. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  7672. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  7673. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  7674. else
  7675. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7676. "2579 Slow-path wqe consume event carries "
  7677. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  7678. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  7679. phba->sli4_hba.els_wq->queue_id);
  7680. }
  7681. /**
  7682. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  7683. * @phba: Pointer to HBA context object.
  7684. * @cq: Pointer to a WQ completion queue.
  7685. * @wcqe: Pointer to work-queue completion queue entry.
  7686. *
  7687. * This routine handles an XRI abort event.
  7688. *
  7689. * Return: true if work posted to worker thread, otherwise false.
  7690. **/
  7691. static bool
  7692. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  7693. struct lpfc_queue *cq,
  7694. struct sli4_wcqe_xri_aborted *wcqe)
  7695. {
  7696. bool workposted = false;
  7697. struct lpfc_cq_event *cq_event;
  7698. unsigned long iflags;
  7699. /* Allocate a new internal CQ_EVENT entry */
  7700. cq_event = lpfc_sli4_cq_event_alloc(phba);
  7701. if (!cq_event) {
  7702. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7703. "0602 Failed to allocate CQ_EVENT entry\n");
  7704. return false;
  7705. }
  7706. /* Move the CQE into the proper xri abort event list */
  7707. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  7708. switch (cq->subtype) {
  7709. case LPFC_FCP:
  7710. spin_lock_irqsave(&phba->hbalock, iflags);
  7711. list_add_tail(&cq_event->list,
  7712. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  7713. /* Set the fcp xri abort event flag */
  7714. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  7715. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7716. workposted = true;
  7717. break;
  7718. case LPFC_ELS:
  7719. spin_lock_irqsave(&phba->hbalock, iflags);
  7720. list_add_tail(&cq_event->list,
  7721. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  7722. /* Set the els xri abort event flag */
  7723. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  7724. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7725. workposted = true;
  7726. break;
  7727. default:
  7728. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7729. "0603 Invalid work queue CQE subtype (x%x)\n",
  7730. cq->subtype);
  7731. workposted = false;
  7732. break;
  7733. }
  7734. return workposted;
  7735. }
  7736. /**
  7737. * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry
  7738. * @phba: Pointer to HBA context object.
  7739. * @cq: Pointer to the completion queue.
  7740. * @wcqe: Pointer to a completion queue entry.
  7741. *
  7742. * This routine process a slow-path work-queue completion queue entry.
  7743. *
  7744. * Return: true if work posted to worker thread, otherwise false.
  7745. **/
  7746. static bool
  7747. lpfc_sli4_sp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7748. struct lpfc_cqe *cqe)
  7749. {
  7750. struct lpfc_wcqe_complete wcqe;
  7751. bool workposted = false;
  7752. /* Copy the work queue CQE and convert endian order if needed */
  7753. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  7754. /* Check and process for different type of WCQE and dispatch */
  7755. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  7756. case CQE_CODE_COMPL_WQE:
  7757. /* Process the WQ complete event */
  7758. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  7759. (struct lpfc_wcqe_complete *)&wcqe);
  7760. break;
  7761. case CQE_CODE_RELEASE_WQE:
  7762. /* Process the WQ release event */
  7763. lpfc_sli4_sp_handle_rel_wcqe(phba,
  7764. (struct lpfc_wcqe_release *)&wcqe);
  7765. break;
  7766. case CQE_CODE_XRI_ABORTED:
  7767. /* Process the WQ XRI abort event */
  7768. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  7769. (struct sli4_wcqe_xri_aborted *)&wcqe);
  7770. break;
  7771. default:
  7772. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7773. "0388 Not a valid WCQE code: x%x\n",
  7774. bf_get(lpfc_wcqe_c_code, &wcqe));
  7775. break;
  7776. }
  7777. return workposted;
  7778. }
  7779. /**
  7780. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  7781. * @phba: Pointer to HBA context object.
  7782. * @rcqe: Pointer to receive-queue completion queue entry.
  7783. *
  7784. * This routine process a receive-queue completion queue entry.
  7785. *
  7786. * Return: true if work posted to worker thread, otherwise false.
  7787. **/
  7788. static bool
  7789. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  7790. {
  7791. struct lpfc_rcqe rcqe;
  7792. bool workposted = false;
  7793. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  7794. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  7795. struct hbq_dmabuf *dma_buf;
  7796. uint32_t status;
  7797. unsigned long iflags;
  7798. /* Copy the receive queue CQE and convert endian order if needed */
  7799. lpfc_sli_pcimem_bcopy(cqe, &rcqe, sizeof(struct lpfc_rcqe));
  7800. lpfc_sli4_rq_release(hrq, drq);
  7801. if (bf_get(lpfc_rcqe_code, &rcqe) != CQE_CODE_RECEIVE)
  7802. goto out;
  7803. if (bf_get(lpfc_rcqe_rq_id, &rcqe) != hrq->queue_id)
  7804. goto out;
  7805. status = bf_get(lpfc_rcqe_status, &rcqe);
  7806. switch (status) {
  7807. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  7808. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7809. "2537 Receive Frame Truncated!!\n");
  7810. case FC_STATUS_RQ_SUCCESS:
  7811. spin_lock_irqsave(&phba->hbalock, iflags);
  7812. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  7813. if (!dma_buf) {
  7814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7815. goto out;
  7816. }
  7817. memcpy(&dma_buf->rcqe, &rcqe, sizeof(rcqe));
  7818. /* save off the frame for the word thread to process */
  7819. list_add_tail(&dma_buf->dbuf.list, &phba->rb_pend_list);
  7820. /* Frame received */
  7821. phba->hba_flag |= HBA_RECEIVE_BUFFER;
  7822. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7823. workposted = true;
  7824. break;
  7825. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  7826. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  7827. /* Post more buffers if possible */
  7828. spin_lock_irqsave(&phba->hbalock, iflags);
  7829. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  7830. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7831. workposted = true;
  7832. break;
  7833. }
  7834. out:
  7835. return workposted;
  7836. }
  7837. /**
  7838. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  7839. * @phba: Pointer to HBA context object.
  7840. * @eqe: Pointer to fast-path event queue entry.
  7841. *
  7842. * This routine process a event queue entry from the slow-path event queue.
  7843. * It will check the MajorCode and MinorCode to determine this is for a
  7844. * completion event on a completion queue, if not, an error shall be logged
  7845. * and just return. Otherwise, it will get to the corresponding completion
  7846. * queue and process all the entries on that completion queue, rearm the
  7847. * completion queue, and then return.
  7848. *
  7849. **/
  7850. static void
  7851. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  7852. {
  7853. struct lpfc_queue *cq = NULL, *childq, *speq;
  7854. struct lpfc_cqe *cqe;
  7855. bool workposted = false;
  7856. int ecount = 0;
  7857. uint16_t cqid;
  7858. if (bf_get(lpfc_eqe_major_code, eqe) != 0 ||
  7859. bf_get(lpfc_eqe_minor_code, eqe) != 0) {
  7860. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7861. "0359 Not a valid slow-path completion "
  7862. "event: majorcode=x%x, minorcode=x%x\n",
  7863. bf_get(lpfc_eqe_major_code, eqe),
  7864. bf_get(lpfc_eqe_minor_code, eqe));
  7865. return;
  7866. }
  7867. /* Get the reference to the corresponding CQ */
  7868. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  7869. /* Search for completion queue pointer matching this cqid */
  7870. speq = phba->sli4_hba.sp_eq;
  7871. list_for_each_entry(childq, &speq->child_list, list) {
  7872. if (childq->queue_id == cqid) {
  7873. cq = childq;
  7874. break;
  7875. }
  7876. }
  7877. if (unlikely(!cq)) {
  7878. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7879. "0365 Slow-path CQ identifier (%d) does "
  7880. "not exist\n", cqid);
  7881. return;
  7882. }
  7883. /* Process all the entries to the CQ */
  7884. switch (cq->type) {
  7885. case LPFC_MCQ:
  7886. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7887. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  7888. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7889. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7890. }
  7891. break;
  7892. case LPFC_WCQ:
  7893. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7894. workposted |= lpfc_sli4_sp_handle_wcqe(phba, cq, cqe);
  7895. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7896. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7897. }
  7898. break;
  7899. case LPFC_RCQ:
  7900. while ((cqe = lpfc_sli4_cq_get(cq))) {
  7901. workposted |= lpfc_sli4_sp_handle_rcqe(phba, cqe);
  7902. if (!(++ecount % LPFC_GET_QE_REL_INT))
  7903. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  7904. }
  7905. break;
  7906. default:
  7907. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7908. "0370 Invalid completion queue type (%d)\n",
  7909. cq->type);
  7910. return;
  7911. }
  7912. /* Catch the no cq entry condition, log an error */
  7913. if (unlikely(ecount == 0))
  7914. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7915. "0371 No entry from the CQ: identifier "
  7916. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  7917. /* In any case, flash and re-arm the RCQ */
  7918. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  7919. /* wake up worker thread if there are works to be done */
  7920. if (workposted)
  7921. lpfc_worker_wake_up(phba);
  7922. }
  7923. /**
  7924. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  7925. * @eqe: Pointer to fast-path completion queue entry.
  7926. *
  7927. * This routine process a fast-path work queue completion entry from fast-path
  7928. * event queue for FCP command response completion.
  7929. **/
  7930. static void
  7931. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  7932. struct lpfc_wcqe_complete *wcqe)
  7933. {
  7934. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  7935. struct lpfc_iocbq *cmdiocbq;
  7936. struct lpfc_iocbq irspiocbq;
  7937. unsigned long iflags;
  7938. spin_lock_irqsave(&phba->hbalock, iflags);
  7939. pring->stats.iocb_event++;
  7940. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7941. /* Check for response status */
  7942. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  7943. /* If resource errors reported from HBA, reduce queue
  7944. * depth of the SCSI device.
  7945. */
  7946. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  7947. IOSTAT_LOCAL_REJECT) &&
  7948. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  7949. phba->lpfc_rampdown_queue_depth(phba);
  7950. }
  7951. /* Log the error status */
  7952. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7953. "0373 FCP complete error: status=x%x, "
  7954. "hw_status=x%x, total_data_specified=%d, "
  7955. "parameter=x%x, word3=x%x\n",
  7956. bf_get(lpfc_wcqe_c_status, wcqe),
  7957. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  7958. wcqe->total_data_placed, wcqe->parameter,
  7959. wcqe->word3);
  7960. }
  7961. /* Look up the FCP command IOCB and create pseudo response IOCB */
  7962. spin_lock_irqsave(&phba->hbalock, iflags);
  7963. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  7964. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7965. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7966. if (unlikely(!cmdiocbq)) {
  7967. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7968. "0374 FCP complete with no corresponding "
  7969. "cmdiocb: iotag (%d)\n",
  7970. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7971. return;
  7972. }
  7973. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  7974. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7975. "0375 FCP cmdiocb not callback function "
  7976. "iotag: (%d)\n",
  7977. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  7978. return;
  7979. }
  7980. /* Fake the irspiocb and copy necessary response information */
  7981. lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe);
  7982. /* Pass the cmd_iocb and the rsp state to the upper layer */
  7983. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  7984. }
  7985. /**
  7986. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  7987. * @phba: Pointer to HBA context object.
  7988. * @cq: Pointer to completion queue.
  7989. * @wcqe: Pointer to work-queue completion queue entry.
  7990. *
  7991. * This routine handles an fast-path WQ entry comsumed event by invoking the
  7992. * proper WQ release routine to the slow-path WQ.
  7993. **/
  7994. static void
  7995. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  7996. struct lpfc_wcqe_release *wcqe)
  7997. {
  7998. struct lpfc_queue *childwq;
  7999. bool wqid_matched = false;
  8000. uint16_t fcp_wqid;
  8001. /* Check for fast-path FCP work queue release */
  8002. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  8003. list_for_each_entry(childwq, &cq->child_list, list) {
  8004. if (childwq->queue_id == fcp_wqid) {
  8005. lpfc_sli4_wq_release(childwq,
  8006. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  8007. wqid_matched = true;
  8008. break;
  8009. }
  8010. }
  8011. /* Report warning log message if no match found */
  8012. if (wqid_matched != true)
  8013. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8014. "2580 Fast-path wqe consume event carries "
  8015. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  8016. }
  8017. /**
  8018. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  8019. * @cq: Pointer to the completion queue.
  8020. * @eqe: Pointer to fast-path completion queue entry.
  8021. *
  8022. * This routine process a fast-path work queue completion entry from fast-path
  8023. * event queue for FCP command response completion.
  8024. **/
  8025. static int
  8026. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8027. struct lpfc_cqe *cqe)
  8028. {
  8029. struct lpfc_wcqe_release wcqe;
  8030. bool workposted = false;
  8031. /* Copy the work queue CQE and convert endian order if needed */
  8032. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  8033. /* Check and process for different type of WCQE and dispatch */
  8034. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  8035. case CQE_CODE_COMPL_WQE:
  8036. /* Process the WQ complete event */
  8037. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  8038. (struct lpfc_wcqe_complete *)&wcqe);
  8039. break;
  8040. case CQE_CODE_RELEASE_WQE:
  8041. /* Process the WQ release event */
  8042. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  8043. (struct lpfc_wcqe_release *)&wcqe);
  8044. break;
  8045. case CQE_CODE_XRI_ABORTED:
  8046. /* Process the WQ XRI abort event */
  8047. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  8048. (struct sli4_wcqe_xri_aborted *)&wcqe);
  8049. break;
  8050. default:
  8051. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8052. "0144 Not a valid WCQE code: x%x\n",
  8053. bf_get(lpfc_wcqe_c_code, &wcqe));
  8054. break;
  8055. }
  8056. return workposted;
  8057. }
  8058. /**
  8059. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  8060. * @phba: Pointer to HBA context object.
  8061. * @eqe: Pointer to fast-path event queue entry.
  8062. *
  8063. * This routine process a event queue entry from the fast-path event queue.
  8064. * It will check the MajorCode and MinorCode to determine this is for a
  8065. * completion event on a completion queue, if not, an error shall be logged
  8066. * and just return. Otherwise, it will get to the corresponding completion
  8067. * queue and process all the entries on the completion queue, rearm the
  8068. * completion queue, and then return.
  8069. **/
  8070. static void
  8071. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  8072. uint32_t fcp_cqidx)
  8073. {
  8074. struct lpfc_queue *cq;
  8075. struct lpfc_cqe *cqe;
  8076. bool workposted = false;
  8077. uint16_t cqid;
  8078. int ecount = 0;
  8079. if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) ||
  8080. unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
  8081. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8082. "0366 Not a valid fast-path completion "
  8083. "event: majorcode=x%x, minorcode=x%x\n",
  8084. bf_get(lpfc_eqe_major_code, eqe),
  8085. bf_get(lpfc_eqe_minor_code, eqe));
  8086. return;
  8087. }
  8088. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  8089. if (unlikely(!cq)) {
  8090. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8091. "0367 Fast-path completion queue does not "
  8092. "exist\n");
  8093. return;
  8094. }
  8095. /* Get the reference to the corresponding CQ */
  8096. cqid = bf_get(lpfc_eqe_resource_id, eqe);
  8097. if (unlikely(cqid != cq->queue_id)) {
  8098. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8099. "0368 Miss-matched fast-path completion "
  8100. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  8101. cqid, cq->queue_id);
  8102. return;
  8103. }
  8104. /* Process all the entries to the CQ */
  8105. while ((cqe = lpfc_sli4_cq_get(cq))) {
  8106. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  8107. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8108. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  8109. }
  8110. /* Catch the no cq entry condition */
  8111. if (unlikely(ecount == 0))
  8112. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8113. "0369 No entry from fast-path completion "
  8114. "queue fcpcqid=%d\n", cq->queue_id);
  8115. /* In any case, flash and re-arm the CQ */
  8116. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  8117. /* wake up worker thread if there are works to be done */
  8118. if (workposted)
  8119. lpfc_worker_wake_up(phba);
  8120. }
  8121. static void
  8122. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8123. {
  8124. struct lpfc_eqe *eqe;
  8125. /* walk all the EQ entries and drop on the floor */
  8126. while ((eqe = lpfc_sli4_eq_get(eq)))
  8127. ;
  8128. /* Clear and re-arm the EQ */
  8129. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  8130. }
  8131. /**
  8132. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  8133. * @irq: Interrupt number.
  8134. * @dev_id: The device context pointer.
  8135. *
  8136. * This function is directly called from the PCI layer as an interrupt
  8137. * service routine when device with SLI-4 interface spec is enabled with
  8138. * MSI-X multi-message interrupt mode and there are slow-path events in
  8139. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  8140. * interrupt mode, this function is called as part of the device-level
  8141. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  8142. * undergoing initialization, the interrupt handler will not process the
  8143. * interrupt. The link attention and ELS ring attention events are handled
  8144. * by the worker thread. The interrupt handler signals the worker thread
  8145. * and returns for these events. This function is called without any lock
  8146. * held. It gets the hbalock to access and update SLI data structures.
  8147. *
  8148. * This function returns IRQ_HANDLED when interrupt is handled else it
  8149. * returns IRQ_NONE.
  8150. **/
  8151. irqreturn_t
  8152. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  8153. {
  8154. struct lpfc_hba *phba;
  8155. struct lpfc_queue *speq;
  8156. struct lpfc_eqe *eqe;
  8157. unsigned long iflag;
  8158. int ecount = 0;
  8159. /*
  8160. * Get the driver's phba structure from the dev_id
  8161. */
  8162. phba = (struct lpfc_hba *)dev_id;
  8163. if (unlikely(!phba))
  8164. return IRQ_NONE;
  8165. /* Get to the EQ struct associated with this vector */
  8166. speq = phba->sli4_hba.sp_eq;
  8167. /* Check device state for handling interrupt */
  8168. if (unlikely(lpfc_intr_state_check(phba))) {
  8169. /* Check again for link_state with lock held */
  8170. spin_lock_irqsave(&phba->hbalock, iflag);
  8171. if (phba->link_state < LPFC_LINK_DOWN)
  8172. /* Flush, clear interrupt, and rearm the EQ */
  8173. lpfc_sli4_eq_flush(phba, speq);
  8174. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8175. return IRQ_NONE;
  8176. }
  8177. /*
  8178. * Process all the event on FCP slow-path EQ
  8179. */
  8180. while ((eqe = lpfc_sli4_eq_get(speq))) {
  8181. lpfc_sli4_sp_handle_eqe(phba, eqe);
  8182. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8183. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  8184. }
  8185. /* Always clear and re-arm the slow-path EQ */
  8186. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  8187. /* Catch the no cq entry condition */
  8188. if (unlikely(ecount == 0)) {
  8189. if (phba->intr_type == MSIX)
  8190. /* MSI-X treated interrupt served as no EQ share INT */
  8191. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8192. "0357 MSI-X interrupt with no EQE\n");
  8193. else
  8194. /* Non MSI-X treated on interrupt as EQ share INT */
  8195. return IRQ_NONE;
  8196. }
  8197. return IRQ_HANDLED;
  8198. } /* lpfc_sli4_sp_intr_handler */
  8199. /**
  8200. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  8201. * @irq: Interrupt number.
  8202. * @dev_id: The device context pointer.
  8203. *
  8204. * This function is directly called from the PCI layer as an interrupt
  8205. * service routine when device with SLI-4 interface spec is enabled with
  8206. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  8207. * ring event in the HBA. However, when the device is enabled with either
  8208. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  8209. * device-level interrupt handler. When the PCI slot is in error recovery
  8210. * or the HBA is undergoing initialization, the interrupt handler will not
  8211. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  8212. * the intrrupt context. This function is called without any lock held.
  8213. * It gets the hbalock to access and update SLI data structures. Note that,
  8214. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  8215. * equal to that of FCP CQ index.
  8216. *
  8217. * This function returns IRQ_HANDLED when interrupt is handled else it
  8218. * returns IRQ_NONE.
  8219. **/
  8220. irqreturn_t
  8221. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  8222. {
  8223. struct lpfc_hba *phba;
  8224. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8225. struct lpfc_queue *fpeq;
  8226. struct lpfc_eqe *eqe;
  8227. unsigned long iflag;
  8228. int ecount = 0;
  8229. uint32_t fcp_eqidx;
  8230. /* Get the driver's phba structure from the dev_id */
  8231. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  8232. phba = fcp_eq_hdl->phba;
  8233. fcp_eqidx = fcp_eq_hdl->idx;
  8234. if (unlikely(!phba))
  8235. return IRQ_NONE;
  8236. /* Get to the EQ struct associated with this vector */
  8237. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  8238. /* Check device state for handling interrupt */
  8239. if (unlikely(lpfc_intr_state_check(phba))) {
  8240. /* Check again for link_state with lock held */
  8241. spin_lock_irqsave(&phba->hbalock, iflag);
  8242. if (phba->link_state < LPFC_LINK_DOWN)
  8243. /* Flush, clear interrupt, and rearm the EQ */
  8244. lpfc_sli4_eq_flush(phba, fpeq);
  8245. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8246. return IRQ_NONE;
  8247. }
  8248. /*
  8249. * Process all the event on FCP fast-path EQ
  8250. */
  8251. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8252. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  8253. if (!(++ecount % LPFC_GET_QE_REL_INT))
  8254. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  8255. }
  8256. /* Always clear and re-arm the fast-path EQ */
  8257. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  8258. if (unlikely(ecount == 0)) {
  8259. if (phba->intr_type == MSIX)
  8260. /* MSI-X treated interrupt served as no EQ share INT */
  8261. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8262. "0358 MSI-X interrupt with no EQE\n");
  8263. else
  8264. /* Non MSI-X treated on interrupt as EQ share INT */
  8265. return IRQ_NONE;
  8266. }
  8267. return IRQ_HANDLED;
  8268. } /* lpfc_sli4_fp_intr_handler */
  8269. /**
  8270. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  8271. * @irq: Interrupt number.
  8272. * @dev_id: The device context pointer.
  8273. *
  8274. * This function is the device-level interrupt handler to device with SLI-4
  8275. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  8276. * interrupt mode is enabled and there is an event in the HBA which requires
  8277. * driver attention. This function invokes the slow-path interrupt attention
  8278. * handling function and fast-path interrupt attention handling function in
  8279. * turn to process the relevant HBA attention events. This function is called
  8280. * without any lock held. It gets the hbalock to access and update SLI data
  8281. * structures.
  8282. *
  8283. * This function returns IRQ_HANDLED when interrupt is handled, else it
  8284. * returns IRQ_NONE.
  8285. **/
  8286. irqreturn_t
  8287. lpfc_sli4_intr_handler(int irq, void *dev_id)
  8288. {
  8289. struct lpfc_hba *phba;
  8290. irqreturn_t sp_irq_rc, fp_irq_rc;
  8291. bool fp_handled = false;
  8292. uint32_t fcp_eqidx;
  8293. /* Get the driver's phba structure from the dev_id */
  8294. phba = (struct lpfc_hba *)dev_id;
  8295. if (unlikely(!phba))
  8296. return IRQ_NONE;
  8297. /*
  8298. * Invokes slow-path host attention interrupt handling as appropriate.
  8299. */
  8300. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  8301. /*
  8302. * Invoke fast-path host attention interrupt handling as appropriate.
  8303. */
  8304. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  8305. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  8306. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  8307. if (fp_irq_rc == IRQ_HANDLED)
  8308. fp_handled |= true;
  8309. }
  8310. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  8311. } /* lpfc_sli4_intr_handler */
  8312. /**
  8313. * lpfc_sli4_queue_free - free a queue structure and associated memory
  8314. * @queue: The queue structure to free.
  8315. *
  8316. * This function frees a queue structure and the DMAable memeory used for
  8317. * the host resident queue. This function must be called after destroying the
  8318. * queue on the HBA.
  8319. **/
  8320. void
  8321. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  8322. {
  8323. struct lpfc_dmabuf *dmabuf;
  8324. if (!queue)
  8325. return;
  8326. while (!list_empty(&queue->page_list)) {
  8327. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  8328. list);
  8329. dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE,
  8330. dmabuf->virt, dmabuf->phys);
  8331. kfree(dmabuf);
  8332. }
  8333. kfree(queue);
  8334. return;
  8335. }
  8336. /**
  8337. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  8338. * @phba: The HBA that this queue is being created on.
  8339. * @entry_size: The size of each queue entry for this queue.
  8340. * @entry count: The number of entries that this queue will handle.
  8341. *
  8342. * This function allocates a queue structure and the DMAable memory used for
  8343. * the host resident queue. This function must be called before creating the
  8344. * queue on the HBA.
  8345. **/
  8346. struct lpfc_queue *
  8347. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  8348. uint32_t entry_count)
  8349. {
  8350. struct lpfc_queue *queue;
  8351. struct lpfc_dmabuf *dmabuf;
  8352. int x, total_qe_count;
  8353. void *dma_pointer;
  8354. queue = kzalloc(sizeof(struct lpfc_queue) +
  8355. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  8356. if (!queue)
  8357. return NULL;
  8358. queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE;
  8359. INIT_LIST_HEAD(&queue->list);
  8360. INIT_LIST_HEAD(&queue->page_list);
  8361. INIT_LIST_HEAD(&queue->child_list);
  8362. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  8363. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  8364. if (!dmabuf)
  8365. goto out_fail;
  8366. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  8367. PAGE_SIZE, &dmabuf->phys,
  8368. GFP_KERNEL);
  8369. if (!dmabuf->virt) {
  8370. kfree(dmabuf);
  8371. goto out_fail;
  8372. }
  8373. dmabuf->buffer_tag = x;
  8374. list_add_tail(&dmabuf->list, &queue->page_list);
  8375. /* initialize queue's entry array */
  8376. dma_pointer = dmabuf->virt;
  8377. for (; total_qe_count < entry_count &&
  8378. dma_pointer < (PAGE_SIZE + dmabuf->virt);
  8379. total_qe_count++, dma_pointer += entry_size) {
  8380. queue->qe[total_qe_count].address = dma_pointer;
  8381. }
  8382. }
  8383. queue->entry_size = entry_size;
  8384. queue->entry_count = entry_count;
  8385. queue->phba = phba;
  8386. return queue;
  8387. out_fail:
  8388. lpfc_sli4_queue_free(queue);
  8389. return NULL;
  8390. }
  8391. /**
  8392. * lpfc_eq_create - Create an Event Queue on the HBA
  8393. * @phba: HBA structure that indicates port to create a queue on.
  8394. * @eq: The queue structure to use to create the event queue.
  8395. * @imax: The maximum interrupt per second limit.
  8396. *
  8397. * This function creates an event queue, as detailed in @eq, on a port,
  8398. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  8399. *
  8400. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  8401. * is used to get the entry count and entry size that are necessary to
  8402. * determine the number of pages to allocate and use for this queue. This
  8403. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  8404. * event queue. This function is asynchronous and will wait for the mailbox
  8405. * command to finish before continuing.
  8406. *
  8407. * On success this function will return a zero. If unable to allocate enough
  8408. * memory this function will return ENOMEM. If the queue create mailbox command
  8409. * fails this function will return ENXIO.
  8410. **/
  8411. uint32_t
  8412. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  8413. {
  8414. struct lpfc_mbx_eq_create *eq_create;
  8415. LPFC_MBOXQ_t *mbox;
  8416. int rc, length, status = 0;
  8417. struct lpfc_dmabuf *dmabuf;
  8418. uint32_t shdr_status, shdr_add_status;
  8419. union lpfc_sli4_cfg_shdr *shdr;
  8420. uint16_t dmult;
  8421. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8422. if (!mbox)
  8423. return -ENOMEM;
  8424. length = (sizeof(struct lpfc_mbx_eq_create) -
  8425. sizeof(struct lpfc_sli4_cfg_mhdr));
  8426. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8427. LPFC_MBOX_OPCODE_EQ_CREATE,
  8428. length, LPFC_SLI4_MBX_EMBED);
  8429. eq_create = &mbox->u.mqe.un.eq_create;
  8430. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  8431. eq->page_count);
  8432. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  8433. LPFC_EQE_SIZE);
  8434. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  8435. /* Calculate delay multiper from maximum interrupt per second */
  8436. dmult = LPFC_DMULT_CONST/imax - 1;
  8437. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  8438. dmult);
  8439. switch (eq->entry_count) {
  8440. default:
  8441. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8442. "0360 Unsupported EQ count. (%d)\n",
  8443. eq->entry_count);
  8444. if (eq->entry_count < 256)
  8445. return -EINVAL;
  8446. /* otherwise default to smallest count (drop through) */
  8447. case 256:
  8448. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8449. LPFC_EQ_CNT_256);
  8450. break;
  8451. case 512:
  8452. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8453. LPFC_EQ_CNT_512);
  8454. break;
  8455. case 1024:
  8456. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8457. LPFC_EQ_CNT_1024);
  8458. break;
  8459. case 2048:
  8460. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8461. LPFC_EQ_CNT_2048);
  8462. break;
  8463. case 4096:
  8464. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  8465. LPFC_EQ_CNT_4096);
  8466. break;
  8467. }
  8468. list_for_each_entry(dmabuf, &eq->page_list, list) {
  8469. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8470. putPaddrLow(dmabuf->phys);
  8471. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8472. putPaddrHigh(dmabuf->phys);
  8473. }
  8474. mbox->vport = phba->pport;
  8475. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8476. mbox->context1 = NULL;
  8477. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8478. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  8479. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8480. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8481. if (shdr_status || shdr_add_status || rc) {
  8482. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8483. "2500 EQ_CREATE mailbox failed with "
  8484. "status x%x add_status x%x, mbx status x%x\n",
  8485. shdr_status, shdr_add_status, rc);
  8486. status = -ENXIO;
  8487. }
  8488. eq->type = LPFC_EQ;
  8489. eq->subtype = LPFC_NONE;
  8490. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  8491. if (eq->queue_id == 0xFFFF)
  8492. status = -ENXIO;
  8493. eq->host_index = 0;
  8494. eq->hba_index = 0;
  8495. if (rc != MBX_TIMEOUT)
  8496. mempool_free(mbox, phba->mbox_mem_pool);
  8497. return status;
  8498. }
  8499. /**
  8500. * lpfc_cq_create - Create a Completion Queue on the HBA
  8501. * @phba: HBA structure that indicates port to create a queue on.
  8502. * @cq: The queue structure to use to create the completion queue.
  8503. * @eq: The event queue to bind this completion queue to.
  8504. *
  8505. * This function creates a completion queue, as detailed in @wq, on a port,
  8506. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  8507. *
  8508. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8509. * is used to get the entry count and entry size that are necessary to
  8510. * determine the number of pages to allocate and use for this queue. The @eq
  8511. * is used to indicate which event queue to bind this completion queue to. This
  8512. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  8513. * completion queue. This function is asynchronous and will wait for the mailbox
  8514. * command to finish before continuing.
  8515. *
  8516. * On success this function will return a zero. If unable to allocate enough
  8517. * memory this function will return ENOMEM. If the queue create mailbox command
  8518. * fails this function will return ENXIO.
  8519. **/
  8520. uint32_t
  8521. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  8522. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  8523. {
  8524. struct lpfc_mbx_cq_create *cq_create;
  8525. struct lpfc_dmabuf *dmabuf;
  8526. LPFC_MBOXQ_t *mbox;
  8527. int rc, length, status = 0;
  8528. uint32_t shdr_status, shdr_add_status;
  8529. union lpfc_sli4_cfg_shdr *shdr;
  8530. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8531. if (!mbox)
  8532. return -ENOMEM;
  8533. length = (sizeof(struct lpfc_mbx_cq_create) -
  8534. sizeof(struct lpfc_sli4_cfg_mhdr));
  8535. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8536. LPFC_MBOX_OPCODE_CQ_CREATE,
  8537. length, LPFC_SLI4_MBX_EMBED);
  8538. cq_create = &mbox->u.mqe.un.cq_create;
  8539. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  8540. cq->page_count);
  8541. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  8542. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  8543. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id);
  8544. switch (cq->entry_count) {
  8545. default:
  8546. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8547. "0361 Unsupported CQ count. (%d)\n",
  8548. cq->entry_count);
  8549. if (cq->entry_count < 256)
  8550. return -EINVAL;
  8551. /* otherwise default to smallest count (drop through) */
  8552. case 256:
  8553. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8554. LPFC_CQ_CNT_256);
  8555. break;
  8556. case 512:
  8557. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8558. LPFC_CQ_CNT_512);
  8559. break;
  8560. case 1024:
  8561. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  8562. LPFC_CQ_CNT_1024);
  8563. break;
  8564. }
  8565. list_for_each_entry(dmabuf, &cq->page_list, list) {
  8566. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8567. putPaddrLow(dmabuf->phys);
  8568. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8569. putPaddrHigh(dmabuf->phys);
  8570. }
  8571. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8572. /* The IOCTL status is embedded in the mailbox subheader. */
  8573. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  8574. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8575. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8576. if (shdr_status || shdr_add_status || rc) {
  8577. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8578. "2501 CQ_CREATE mailbox failed with "
  8579. "status x%x add_status x%x, mbx status x%x\n",
  8580. shdr_status, shdr_add_status, rc);
  8581. status = -ENXIO;
  8582. goto out;
  8583. }
  8584. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8585. if (cq->queue_id == 0xFFFF) {
  8586. status = -ENXIO;
  8587. goto out;
  8588. }
  8589. /* link the cq onto the parent eq child list */
  8590. list_add_tail(&cq->list, &eq->child_list);
  8591. /* Set up completion queue's type and subtype */
  8592. cq->type = type;
  8593. cq->subtype = subtype;
  8594. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  8595. cq->host_index = 0;
  8596. cq->hba_index = 0;
  8597. out:
  8598. if (rc != MBX_TIMEOUT)
  8599. mempool_free(mbox, phba->mbox_mem_pool);
  8600. return status;
  8601. }
  8602. /**
  8603. * lpfc_mq_create - Create a mailbox Queue on the HBA
  8604. * @phba: HBA structure that indicates port to create a queue on.
  8605. * @mq: The queue structure to use to create the mailbox queue.
  8606. *
  8607. * This function creates a mailbox queue, as detailed in @mq, on a port,
  8608. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  8609. *
  8610. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  8611. * is used to get the entry count and entry size that are necessary to
  8612. * determine the number of pages to allocate and use for this queue. This
  8613. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  8614. * mailbox queue. This function is asynchronous and will wait for the mailbox
  8615. * command to finish before continuing.
  8616. *
  8617. * On success this function will return a zero. If unable to allocate enough
  8618. * memory this function will return ENOMEM. If the queue create mailbox command
  8619. * fails this function will return ENXIO.
  8620. **/
  8621. uint32_t
  8622. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  8623. struct lpfc_queue *cq, uint32_t subtype)
  8624. {
  8625. struct lpfc_mbx_mq_create *mq_create;
  8626. struct lpfc_dmabuf *dmabuf;
  8627. LPFC_MBOXQ_t *mbox;
  8628. int rc, length, status = 0;
  8629. uint32_t shdr_status, shdr_add_status;
  8630. union lpfc_sli4_cfg_shdr *shdr;
  8631. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8632. if (!mbox)
  8633. return -ENOMEM;
  8634. length = (sizeof(struct lpfc_mbx_mq_create) -
  8635. sizeof(struct lpfc_sli4_cfg_mhdr));
  8636. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8637. LPFC_MBOX_OPCODE_MQ_CREATE,
  8638. length, LPFC_SLI4_MBX_EMBED);
  8639. mq_create = &mbox->u.mqe.un.mq_create;
  8640. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  8641. mq->page_count);
  8642. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  8643. cq->queue_id);
  8644. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  8645. switch (mq->entry_count) {
  8646. default:
  8647. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8648. "0362 Unsupported MQ count. (%d)\n",
  8649. mq->entry_count);
  8650. if (mq->entry_count < 16)
  8651. return -EINVAL;
  8652. /* otherwise default to smallest count (drop through) */
  8653. case 16:
  8654. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8655. LPFC_MQ_CNT_16);
  8656. break;
  8657. case 32:
  8658. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8659. LPFC_MQ_CNT_32);
  8660. break;
  8661. case 64:
  8662. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8663. LPFC_MQ_CNT_64);
  8664. break;
  8665. case 128:
  8666. bf_set(lpfc_mq_context_count, &mq_create->u.request.context,
  8667. LPFC_MQ_CNT_128);
  8668. break;
  8669. }
  8670. list_for_each_entry(dmabuf, &mq->page_list, list) {
  8671. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8672. putPaddrLow(dmabuf->phys);
  8673. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8674. putPaddrHigh(dmabuf->phys);
  8675. }
  8676. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8677. /* The IOCTL status is embedded in the mailbox subheader. */
  8678. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  8679. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8680. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8681. if (shdr_status || shdr_add_status || rc) {
  8682. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8683. "2502 MQ_CREATE mailbox failed with "
  8684. "status x%x add_status x%x, mbx status x%x\n",
  8685. shdr_status, shdr_add_status, rc);
  8686. status = -ENXIO;
  8687. goto out;
  8688. }
  8689. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response);
  8690. if (mq->queue_id == 0xFFFF) {
  8691. status = -ENXIO;
  8692. goto out;
  8693. }
  8694. mq->type = LPFC_MQ;
  8695. mq->subtype = subtype;
  8696. mq->host_index = 0;
  8697. mq->hba_index = 0;
  8698. /* link the mq onto the parent cq child list */
  8699. list_add_tail(&mq->list, &cq->child_list);
  8700. out:
  8701. if (rc != MBX_TIMEOUT)
  8702. mempool_free(mbox, phba->mbox_mem_pool);
  8703. return status;
  8704. }
  8705. /**
  8706. * lpfc_wq_create - Create a Work Queue on the HBA
  8707. * @phba: HBA structure that indicates port to create a queue on.
  8708. * @wq: The queue structure to use to create the work queue.
  8709. * @cq: The completion queue to bind this work queue to.
  8710. * @subtype: The subtype of the work queue indicating its functionality.
  8711. *
  8712. * This function creates a work queue, as detailed in @wq, on a port, described
  8713. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  8714. *
  8715. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  8716. * is used to get the entry count and entry size that are necessary to
  8717. * determine the number of pages to allocate and use for this queue. The @cq
  8718. * is used to indicate which completion queue to bind this work queue to. This
  8719. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  8720. * work queue. This function is asynchronous and will wait for the mailbox
  8721. * command to finish before continuing.
  8722. *
  8723. * On success this function will return a zero. If unable to allocate enough
  8724. * memory this function will return ENOMEM. If the queue create mailbox command
  8725. * fails this function will return ENXIO.
  8726. **/
  8727. uint32_t
  8728. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  8729. struct lpfc_queue *cq, uint32_t subtype)
  8730. {
  8731. struct lpfc_mbx_wq_create *wq_create;
  8732. struct lpfc_dmabuf *dmabuf;
  8733. LPFC_MBOXQ_t *mbox;
  8734. int rc, length, status = 0;
  8735. uint32_t shdr_status, shdr_add_status;
  8736. union lpfc_sli4_cfg_shdr *shdr;
  8737. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8738. if (!mbox)
  8739. return -ENOMEM;
  8740. length = (sizeof(struct lpfc_mbx_wq_create) -
  8741. sizeof(struct lpfc_sli4_cfg_mhdr));
  8742. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8743. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  8744. length, LPFC_SLI4_MBX_EMBED);
  8745. wq_create = &mbox->u.mqe.un.wq_create;
  8746. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  8747. wq->page_count);
  8748. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  8749. cq->queue_id);
  8750. list_for_each_entry(dmabuf, &wq->page_list, list) {
  8751. wq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8752. putPaddrLow(dmabuf->phys);
  8753. wq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8754. putPaddrHigh(dmabuf->phys);
  8755. }
  8756. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8757. /* The IOCTL status is embedded in the mailbox subheader. */
  8758. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  8759. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8760. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8761. if (shdr_status || shdr_add_status || rc) {
  8762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8763. "2503 WQ_CREATE mailbox failed with "
  8764. "status x%x add_status x%x, mbx status x%x\n",
  8765. shdr_status, shdr_add_status, rc);
  8766. status = -ENXIO;
  8767. goto out;
  8768. }
  8769. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  8770. if (wq->queue_id == 0xFFFF) {
  8771. status = -ENXIO;
  8772. goto out;
  8773. }
  8774. wq->type = LPFC_WQ;
  8775. wq->subtype = subtype;
  8776. wq->host_index = 0;
  8777. wq->hba_index = 0;
  8778. /* link the wq onto the parent cq child list */
  8779. list_add_tail(&wq->list, &cq->child_list);
  8780. out:
  8781. if (rc == MBX_TIMEOUT)
  8782. mempool_free(mbox, phba->mbox_mem_pool);
  8783. return status;
  8784. }
  8785. /**
  8786. * lpfc_rq_create - Create a Receive Queue on the HBA
  8787. * @phba: HBA structure that indicates port to create a queue on.
  8788. * @hrq: The queue structure to use to create the header receive queue.
  8789. * @drq: The queue structure to use to create the data receive queue.
  8790. * @cq: The completion queue to bind this work queue to.
  8791. *
  8792. * This function creates a receive buffer queue pair , as detailed in @hrq and
  8793. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  8794. * to the HBA.
  8795. *
  8796. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  8797. * struct is used to get the entry count that is necessary to determine the
  8798. * number of pages to use for this queue. The @cq is used to indicate which
  8799. * completion queue to bind received buffers that are posted to these queues to.
  8800. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  8801. * receive queue pair. This function is asynchronous and will wait for the
  8802. * mailbox command to finish before continuing.
  8803. *
  8804. * On success this function will return a zero. If unable to allocate enough
  8805. * memory this function will return ENOMEM. If the queue create mailbox command
  8806. * fails this function will return ENXIO.
  8807. **/
  8808. uint32_t
  8809. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  8810. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  8811. {
  8812. struct lpfc_mbx_rq_create *rq_create;
  8813. struct lpfc_dmabuf *dmabuf;
  8814. LPFC_MBOXQ_t *mbox;
  8815. int rc, length, status = 0;
  8816. uint32_t shdr_status, shdr_add_status;
  8817. union lpfc_sli4_cfg_shdr *shdr;
  8818. if (hrq->entry_count != drq->entry_count)
  8819. return -EINVAL;
  8820. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  8821. if (!mbox)
  8822. return -ENOMEM;
  8823. length = (sizeof(struct lpfc_mbx_rq_create) -
  8824. sizeof(struct lpfc_sli4_cfg_mhdr));
  8825. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8826. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8827. length, LPFC_SLI4_MBX_EMBED);
  8828. rq_create = &mbox->u.mqe.un.rq_create;
  8829. switch (hrq->entry_count) {
  8830. default:
  8831. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8832. "2535 Unsupported RQ count. (%d)\n",
  8833. hrq->entry_count);
  8834. if (hrq->entry_count < 512)
  8835. return -EINVAL;
  8836. /* otherwise default to smallest count (drop through) */
  8837. case 512:
  8838. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8839. LPFC_RQ_RING_SIZE_512);
  8840. break;
  8841. case 1024:
  8842. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8843. LPFC_RQ_RING_SIZE_1024);
  8844. break;
  8845. case 2048:
  8846. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8847. LPFC_RQ_RING_SIZE_2048);
  8848. break;
  8849. case 4096:
  8850. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8851. LPFC_RQ_RING_SIZE_4096);
  8852. break;
  8853. }
  8854. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8855. cq->queue_id);
  8856. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8857. hrq->page_count);
  8858. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8859. LPFC_HDR_BUF_SIZE);
  8860. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  8861. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8862. putPaddrLow(dmabuf->phys);
  8863. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8864. putPaddrHigh(dmabuf->phys);
  8865. }
  8866. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8867. /* The IOCTL status is embedded in the mailbox subheader. */
  8868. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  8869. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8870. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8871. if (shdr_status || shdr_add_status || rc) {
  8872. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8873. "2504 RQ_CREATE mailbox failed with "
  8874. "status x%x add_status x%x, mbx status x%x\n",
  8875. shdr_status, shdr_add_status, rc);
  8876. status = -ENXIO;
  8877. goto out;
  8878. }
  8879. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  8880. if (hrq->queue_id == 0xFFFF) {
  8881. status = -ENXIO;
  8882. goto out;
  8883. }
  8884. hrq->type = LPFC_HRQ;
  8885. hrq->subtype = subtype;
  8886. hrq->host_index = 0;
  8887. hrq->hba_index = 0;
  8888. /* now create the data queue */
  8889. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  8890. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  8891. length, LPFC_SLI4_MBX_EMBED);
  8892. switch (drq->entry_count) {
  8893. default:
  8894. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8895. "2536 Unsupported RQ count. (%d)\n",
  8896. drq->entry_count);
  8897. if (drq->entry_count < 512)
  8898. return -EINVAL;
  8899. /* otherwise default to smallest count (drop through) */
  8900. case 512:
  8901. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8902. LPFC_RQ_RING_SIZE_512);
  8903. break;
  8904. case 1024:
  8905. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8906. LPFC_RQ_RING_SIZE_1024);
  8907. break;
  8908. case 2048:
  8909. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8910. LPFC_RQ_RING_SIZE_2048);
  8911. break;
  8912. case 4096:
  8913. bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context,
  8914. LPFC_RQ_RING_SIZE_4096);
  8915. break;
  8916. }
  8917. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  8918. cq->queue_id);
  8919. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  8920. drq->page_count);
  8921. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  8922. LPFC_DATA_BUF_SIZE);
  8923. list_for_each_entry(dmabuf, &drq->page_list, list) {
  8924. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  8925. putPaddrLow(dmabuf->phys);
  8926. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  8927. putPaddrHigh(dmabuf->phys);
  8928. }
  8929. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  8930. /* The IOCTL status is embedded in the mailbox subheader. */
  8931. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  8932. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8933. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8934. if (shdr_status || shdr_add_status || rc) {
  8935. status = -ENXIO;
  8936. goto out;
  8937. }
  8938. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  8939. if (drq->queue_id == 0xFFFF) {
  8940. status = -ENXIO;
  8941. goto out;
  8942. }
  8943. drq->type = LPFC_DRQ;
  8944. drq->subtype = subtype;
  8945. drq->host_index = 0;
  8946. drq->hba_index = 0;
  8947. /* link the header and data RQs onto the parent cq child list */
  8948. list_add_tail(&hrq->list, &cq->child_list);
  8949. list_add_tail(&drq->list, &cq->child_list);
  8950. out:
  8951. if (rc != MBX_TIMEOUT)
  8952. mempool_free(mbox, phba->mbox_mem_pool);
  8953. return status;
  8954. }
  8955. /**
  8956. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  8957. * @eq: The queue structure associated with the queue to destroy.
  8958. *
  8959. * This function destroys a queue, as detailed in @eq by sending an mailbox
  8960. * command, specific to the type of queue, to the HBA.
  8961. *
  8962. * The @eq struct is used to get the queue ID of the queue to destroy.
  8963. *
  8964. * On success this function will return a zero. If the queue destroy mailbox
  8965. * command fails this function will return ENXIO.
  8966. **/
  8967. uint32_t
  8968. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  8969. {
  8970. LPFC_MBOXQ_t *mbox;
  8971. int rc, length, status = 0;
  8972. uint32_t shdr_status, shdr_add_status;
  8973. union lpfc_sli4_cfg_shdr *shdr;
  8974. if (!eq)
  8975. return -ENODEV;
  8976. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  8977. if (!mbox)
  8978. return -ENOMEM;
  8979. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  8980. sizeof(struct lpfc_sli4_cfg_mhdr));
  8981. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  8982. LPFC_MBOX_OPCODE_EQ_DESTROY,
  8983. length, LPFC_SLI4_MBX_EMBED);
  8984. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  8985. eq->queue_id);
  8986. mbox->vport = eq->phba->pport;
  8987. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8988. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  8989. /* The IOCTL status is embedded in the mailbox subheader. */
  8990. shdr = (union lpfc_sli4_cfg_shdr *)
  8991. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  8992. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  8993. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  8994. if (shdr_status || shdr_add_status || rc) {
  8995. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8996. "2505 EQ_DESTROY mailbox failed with "
  8997. "status x%x add_status x%x, mbx status x%x\n",
  8998. shdr_status, shdr_add_status, rc);
  8999. status = -ENXIO;
  9000. }
  9001. /* Remove eq from any list */
  9002. list_del_init(&eq->list);
  9003. if (rc != MBX_TIMEOUT)
  9004. mempool_free(mbox, eq->phba->mbox_mem_pool);
  9005. return status;
  9006. }
  9007. /**
  9008. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  9009. * @cq: The queue structure associated with the queue to destroy.
  9010. *
  9011. * This function destroys a queue, as detailed in @cq by sending an mailbox
  9012. * command, specific to the type of queue, to the HBA.
  9013. *
  9014. * The @cq struct is used to get the queue ID of the queue to destroy.
  9015. *
  9016. * On success this function will return a zero. If the queue destroy mailbox
  9017. * command fails this function will return ENXIO.
  9018. **/
  9019. uint32_t
  9020. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  9021. {
  9022. LPFC_MBOXQ_t *mbox;
  9023. int rc, length, status = 0;
  9024. uint32_t shdr_status, shdr_add_status;
  9025. union lpfc_sli4_cfg_shdr *shdr;
  9026. if (!cq)
  9027. return -ENODEV;
  9028. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  9029. if (!mbox)
  9030. return -ENOMEM;
  9031. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  9032. sizeof(struct lpfc_sli4_cfg_mhdr));
  9033. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9034. LPFC_MBOX_OPCODE_CQ_DESTROY,
  9035. length, LPFC_SLI4_MBX_EMBED);
  9036. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  9037. cq->queue_id);
  9038. mbox->vport = cq->phba->pport;
  9039. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9040. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  9041. /* The IOCTL status is embedded in the mailbox subheader. */
  9042. shdr = (union lpfc_sli4_cfg_shdr *)
  9043. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  9044. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9045. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9046. if (shdr_status || shdr_add_status || rc) {
  9047. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9048. "2506 CQ_DESTROY mailbox failed with "
  9049. "status x%x add_status x%x, mbx status x%x\n",
  9050. shdr_status, shdr_add_status, rc);
  9051. status = -ENXIO;
  9052. }
  9053. /* Remove cq from any list */
  9054. list_del_init(&cq->list);
  9055. if (rc != MBX_TIMEOUT)
  9056. mempool_free(mbox, cq->phba->mbox_mem_pool);
  9057. return status;
  9058. }
  9059. /**
  9060. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  9061. * @qm: The queue structure associated with the queue to destroy.
  9062. *
  9063. * This function destroys a queue, as detailed in @mq by sending an mailbox
  9064. * command, specific to the type of queue, to the HBA.
  9065. *
  9066. * The @mq struct is used to get the queue ID of the queue to destroy.
  9067. *
  9068. * On success this function will return a zero. If the queue destroy mailbox
  9069. * command fails this function will return ENXIO.
  9070. **/
  9071. uint32_t
  9072. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  9073. {
  9074. LPFC_MBOXQ_t *mbox;
  9075. int rc, length, status = 0;
  9076. uint32_t shdr_status, shdr_add_status;
  9077. union lpfc_sli4_cfg_shdr *shdr;
  9078. if (!mq)
  9079. return -ENODEV;
  9080. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  9081. if (!mbox)
  9082. return -ENOMEM;
  9083. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  9084. sizeof(struct lpfc_sli4_cfg_mhdr));
  9085. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  9086. LPFC_MBOX_OPCODE_MQ_DESTROY,
  9087. length, LPFC_SLI4_MBX_EMBED);
  9088. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  9089. mq->queue_id);
  9090. mbox->vport = mq->phba->pport;
  9091. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9092. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  9093. /* The IOCTL status is embedded in the mailbox subheader. */
  9094. shdr = (union lpfc_sli4_cfg_shdr *)
  9095. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  9096. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9097. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9098. if (shdr_status || shdr_add_status || rc) {
  9099. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9100. "2507 MQ_DESTROY mailbox failed with "
  9101. "status x%x add_status x%x, mbx status x%x\n",
  9102. shdr_status, shdr_add_status, rc);
  9103. status = -ENXIO;
  9104. }
  9105. /* Remove mq from any list */
  9106. list_del_init(&mq->list);
  9107. if (rc != MBX_TIMEOUT)
  9108. mempool_free(mbox, mq->phba->mbox_mem_pool);
  9109. return status;
  9110. }
  9111. /**
  9112. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  9113. * @wq: The queue structure associated with the queue to destroy.
  9114. *
  9115. * This function destroys a queue, as detailed in @wq by sending an mailbox
  9116. * command, specific to the type of queue, to the HBA.
  9117. *
  9118. * The @wq struct is used to get the queue ID of the queue to destroy.
  9119. *
  9120. * On success this function will return a zero. If the queue destroy mailbox
  9121. * command fails this function will return ENXIO.
  9122. **/
  9123. uint32_t
  9124. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  9125. {
  9126. LPFC_MBOXQ_t *mbox;
  9127. int rc, length, status = 0;
  9128. uint32_t shdr_status, shdr_add_status;
  9129. union lpfc_sli4_cfg_shdr *shdr;
  9130. if (!wq)
  9131. return -ENODEV;
  9132. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  9133. if (!mbox)
  9134. return -ENOMEM;
  9135. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  9136. sizeof(struct lpfc_sli4_cfg_mhdr));
  9137. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9138. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  9139. length, LPFC_SLI4_MBX_EMBED);
  9140. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  9141. wq->queue_id);
  9142. mbox->vport = wq->phba->pport;
  9143. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9144. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  9145. shdr = (union lpfc_sli4_cfg_shdr *)
  9146. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  9147. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9148. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9149. if (shdr_status || shdr_add_status || rc) {
  9150. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9151. "2508 WQ_DESTROY mailbox failed with "
  9152. "status x%x add_status x%x, mbx status x%x\n",
  9153. shdr_status, shdr_add_status, rc);
  9154. status = -ENXIO;
  9155. }
  9156. /* Remove wq from any list */
  9157. list_del_init(&wq->list);
  9158. if (rc != MBX_TIMEOUT)
  9159. mempool_free(mbox, wq->phba->mbox_mem_pool);
  9160. return status;
  9161. }
  9162. /**
  9163. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  9164. * @rq: The queue structure associated with the queue to destroy.
  9165. *
  9166. * This function destroys a queue, as detailed in @rq by sending an mailbox
  9167. * command, specific to the type of queue, to the HBA.
  9168. *
  9169. * The @rq struct is used to get the queue ID of the queue to destroy.
  9170. *
  9171. * On success this function will return a zero. If the queue destroy mailbox
  9172. * command fails this function will return ENXIO.
  9173. **/
  9174. uint32_t
  9175. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  9176. struct lpfc_queue *drq)
  9177. {
  9178. LPFC_MBOXQ_t *mbox;
  9179. int rc, length, status = 0;
  9180. uint32_t shdr_status, shdr_add_status;
  9181. union lpfc_sli4_cfg_shdr *shdr;
  9182. if (!hrq || !drq)
  9183. return -ENODEV;
  9184. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  9185. if (!mbox)
  9186. return -ENOMEM;
  9187. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  9188. sizeof(struct mbox_header));
  9189. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9190. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  9191. length, LPFC_SLI4_MBX_EMBED);
  9192. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9193. hrq->queue_id);
  9194. mbox->vport = hrq->phba->pport;
  9195. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9196. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  9197. /* The IOCTL status is embedded in the mailbox subheader. */
  9198. shdr = (union lpfc_sli4_cfg_shdr *)
  9199. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9200. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9201. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9202. if (shdr_status || shdr_add_status || rc) {
  9203. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9204. "2509 RQ_DESTROY mailbox failed with "
  9205. "status x%x add_status x%x, mbx status x%x\n",
  9206. shdr_status, shdr_add_status, rc);
  9207. if (rc != MBX_TIMEOUT)
  9208. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9209. return -ENXIO;
  9210. }
  9211. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  9212. drq->queue_id);
  9213. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  9214. shdr = (union lpfc_sli4_cfg_shdr *)
  9215. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  9216. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9217. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9218. if (shdr_status || shdr_add_status || rc) {
  9219. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9220. "2510 RQ_DESTROY mailbox failed with "
  9221. "status x%x add_status x%x, mbx status x%x\n",
  9222. shdr_status, shdr_add_status, rc);
  9223. status = -ENXIO;
  9224. }
  9225. list_del_init(&hrq->list);
  9226. list_del_init(&drq->list);
  9227. if (rc != MBX_TIMEOUT)
  9228. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  9229. return status;
  9230. }
  9231. /**
  9232. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  9233. * @phba: The virtual port for which this call being executed.
  9234. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  9235. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  9236. * @xritag: the xritag that ties this io to the SGL pages.
  9237. *
  9238. * This routine will post the sgl pages for the IO that has the xritag
  9239. * that is in the iocbq structure. The xritag is assigned during iocbq
  9240. * creation and persists for as long as the driver is loaded.
  9241. * if the caller has fewer than 256 scatter gather segments to map then
  9242. * pdma_phys_addr1 should be 0.
  9243. * If the caller needs to map more than 256 scatter gather segment then
  9244. * pdma_phys_addr1 should be a valid physical address.
  9245. * physical address for SGLs must be 64 byte aligned.
  9246. * If you are going to map 2 SGL's then the first one must have 256 entries
  9247. * the second sgl can have between 1 and 256 entries.
  9248. *
  9249. * Return codes:
  9250. * 0 - Success
  9251. * -ENXIO, -ENOMEM - Failure
  9252. **/
  9253. int
  9254. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  9255. dma_addr_t pdma_phys_addr0,
  9256. dma_addr_t pdma_phys_addr1,
  9257. uint16_t xritag)
  9258. {
  9259. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  9260. LPFC_MBOXQ_t *mbox;
  9261. int rc;
  9262. uint32_t shdr_status, shdr_add_status;
  9263. union lpfc_sli4_cfg_shdr *shdr;
  9264. if (xritag == NO_XRI) {
  9265. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9266. "0364 Invalid param:\n");
  9267. return -EINVAL;
  9268. }
  9269. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9270. if (!mbox)
  9271. return -ENOMEM;
  9272. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9273. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  9274. sizeof(struct lpfc_mbx_post_sgl_pages) -
  9275. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  9276. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  9277. &mbox->u.mqe.un.post_sgl_pages;
  9278. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  9279. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  9280. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  9281. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  9282. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  9283. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  9284. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  9285. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  9286. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  9287. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  9288. if (!phba->sli4_hba.intr_enable)
  9289. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9290. else
  9291. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9292. /* The IOCTL status is embedded in the mailbox subheader. */
  9293. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  9294. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9295. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9296. if (rc != MBX_TIMEOUT)
  9297. mempool_free(mbox, phba->mbox_mem_pool);
  9298. if (shdr_status || shdr_add_status || rc) {
  9299. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9300. "2511 POST_SGL mailbox failed with "
  9301. "status x%x add_status x%x, mbx status x%x\n",
  9302. shdr_status, shdr_add_status, rc);
  9303. rc = -ENXIO;
  9304. }
  9305. return 0;
  9306. }
  9307. /**
  9308. * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA
  9309. * @phba: The virtual port for which this call being executed.
  9310. *
  9311. * This routine will remove all of the sgl pages registered with the hba.
  9312. *
  9313. * Return codes:
  9314. * 0 - Success
  9315. * -ENXIO, -ENOMEM - Failure
  9316. **/
  9317. int
  9318. lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba)
  9319. {
  9320. LPFC_MBOXQ_t *mbox;
  9321. int rc;
  9322. uint32_t shdr_status, shdr_add_status;
  9323. union lpfc_sli4_cfg_shdr *shdr;
  9324. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9325. if (!mbox)
  9326. return -ENOMEM;
  9327. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9328. LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0,
  9329. LPFC_SLI4_MBX_EMBED);
  9330. if (!phba->sli4_hba.intr_enable)
  9331. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9332. else
  9333. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  9334. /* The IOCTL status is embedded in the mailbox subheader. */
  9335. shdr = (union lpfc_sli4_cfg_shdr *)
  9336. &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  9337. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9338. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9339. if (rc != MBX_TIMEOUT)
  9340. mempool_free(mbox, phba->mbox_mem_pool);
  9341. if (shdr_status || shdr_add_status || rc) {
  9342. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9343. "2512 REMOVE_ALL_SGL_PAGES mailbox failed with "
  9344. "status x%x add_status x%x, mbx status x%x\n",
  9345. shdr_status, shdr_add_status, rc);
  9346. rc = -ENXIO;
  9347. }
  9348. return rc;
  9349. }
  9350. /**
  9351. * lpfc_sli4_next_xritag - Get an xritag for the io
  9352. * @phba: Pointer to HBA context object.
  9353. *
  9354. * This function gets an xritag for the iocb. If there is no unused xritag
  9355. * it will return 0xffff.
  9356. * The function returns the allocated xritag if successful, else returns zero.
  9357. * Zero is not a valid xritag.
  9358. * The caller is not required to hold any lock.
  9359. **/
  9360. uint16_t
  9361. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  9362. {
  9363. uint16_t xritag;
  9364. spin_lock_irq(&phba->hbalock);
  9365. xritag = phba->sli4_hba.next_xri;
  9366. if ((xritag != (uint16_t) -1) && xritag <
  9367. (phba->sli4_hba.max_cfg_param.max_xri
  9368. + phba->sli4_hba.max_cfg_param.xri_base)) {
  9369. phba->sli4_hba.next_xri++;
  9370. phba->sli4_hba.max_cfg_param.xri_used++;
  9371. spin_unlock_irq(&phba->hbalock);
  9372. return xritag;
  9373. }
  9374. spin_unlock_irq(&phba->hbalock);
  9375. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9376. "2004 Failed to allocate XRI.last XRITAG is %d"
  9377. " Max XRI is %d, Used XRI is %d\n",
  9378. phba->sli4_hba.next_xri,
  9379. phba->sli4_hba.max_cfg_param.max_xri,
  9380. phba->sli4_hba.max_cfg_param.xri_used);
  9381. return -1;
  9382. }
  9383. /**
  9384. * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware.
  9385. * @phba: pointer to lpfc hba data structure.
  9386. *
  9387. * This routine is invoked to post a block of driver's sgl pages to the
  9388. * HBA using non-embedded mailbox command. No Lock is held. This routine
  9389. * is only called when the driver is loading and after all IO has been
  9390. * stopped.
  9391. **/
  9392. int
  9393. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba)
  9394. {
  9395. struct lpfc_sglq *sglq_entry;
  9396. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9397. struct sgl_page_pairs *sgl_pg_pairs;
  9398. void *viraddr;
  9399. LPFC_MBOXQ_t *mbox;
  9400. uint32_t reqlen, alloclen, pg_pairs;
  9401. uint32_t mbox_tmo;
  9402. uint16_t xritag_start = 0;
  9403. int els_xri_cnt, rc = 0;
  9404. uint32_t shdr_status, shdr_add_status;
  9405. union lpfc_sli4_cfg_shdr *shdr;
  9406. /* The number of sgls to be posted */
  9407. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  9408. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  9409. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9410. if (reqlen > PAGE_SIZE) {
  9411. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9412. "2559 Block sgl registration required DMA "
  9413. "size (%d) great than a page\n", reqlen);
  9414. return -ENOMEM;
  9415. }
  9416. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9417. if (!mbox) {
  9418. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9419. "2560 Failed to allocate mbox cmd memory\n");
  9420. return -ENOMEM;
  9421. }
  9422. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9423. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9424. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9425. LPFC_SLI4_MBX_NEMBED);
  9426. if (alloclen < reqlen) {
  9427. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9428. "0285 Allocated DMA memory size (%d) is "
  9429. "less than the requested DMA memory "
  9430. "size (%d)\n", alloclen, reqlen);
  9431. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9432. return -ENOMEM;
  9433. }
  9434. /* Get the first SGE entry from the non-embedded DMA memory */
  9435. if (unlikely(!mbox->sge_array)) {
  9436. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9437. "2525 Failed to get the non-embedded SGE "
  9438. "virtual address\n");
  9439. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9440. return -ENOMEM;
  9441. }
  9442. viraddr = mbox->sge_array->addr[0];
  9443. /* Set up the SGL pages in the non-embedded DMA pages */
  9444. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9445. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9446. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  9447. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  9448. /* Set up the sge entry */
  9449. sgl_pg_pairs->sgl_pg0_addr_lo =
  9450. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  9451. sgl_pg_pairs->sgl_pg0_addr_hi =
  9452. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  9453. sgl_pg_pairs->sgl_pg1_addr_lo =
  9454. cpu_to_le32(putPaddrLow(0));
  9455. sgl_pg_pairs->sgl_pg1_addr_hi =
  9456. cpu_to_le32(putPaddrHigh(0));
  9457. /* Keep the first xritag on the list */
  9458. if (pg_pairs == 0)
  9459. xritag_start = sglq_entry->sli4_xritag;
  9460. sgl_pg_pairs++;
  9461. }
  9462. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9463. pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs;
  9464. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9465. /* Perform endian conversion if necessary */
  9466. sgl->word0 = cpu_to_le32(sgl->word0);
  9467. if (!phba->sli4_hba.intr_enable)
  9468. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9469. else {
  9470. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9471. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9472. }
  9473. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9474. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9475. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9476. if (rc != MBX_TIMEOUT)
  9477. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9478. if (shdr_status || shdr_add_status || rc) {
  9479. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9480. "2513 POST_SGL_BLOCK mailbox command failed "
  9481. "status x%x add_status x%x mbx status x%x\n",
  9482. shdr_status, shdr_add_status, rc);
  9483. rc = -ENXIO;
  9484. }
  9485. return rc;
  9486. }
  9487. /**
  9488. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  9489. * @phba: pointer to lpfc hba data structure.
  9490. * @sblist: pointer to scsi buffer list.
  9491. * @count: number of scsi buffers on the list.
  9492. *
  9493. * This routine is invoked to post a block of @count scsi sgl pages from a
  9494. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  9495. * No Lock is held.
  9496. *
  9497. **/
  9498. int
  9499. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  9500. int cnt)
  9501. {
  9502. struct lpfc_scsi_buf *psb;
  9503. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  9504. struct sgl_page_pairs *sgl_pg_pairs;
  9505. void *viraddr;
  9506. LPFC_MBOXQ_t *mbox;
  9507. uint32_t reqlen, alloclen, pg_pairs;
  9508. uint32_t mbox_tmo;
  9509. uint16_t xritag_start = 0;
  9510. int rc = 0;
  9511. uint32_t shdr_status, shdr_add_status;
  9512. dma_addr_t pdma_phys_bpl1;
  9513. union lpfc_sli4_cfg_shdr *shdr;
  9514. /* Calculate the requested length of the dma memory */
  9515. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  9516. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  9517. if (reqlen > PAGE_SIZE) {
  9518. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  9519. "0217 Block sgl registration required DMA "
  9520. "size (%d) great than a page\n", reqlen);
  9521. return -ENOMEM;
  9522. }
  9523. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9524. if (!mbox) {
  9525. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9526. "0283 Failed to allocate mbox cmd memory\n");
  9527. return -ENOMEM;
  9528. }
  9529. /* Allocate DMA memory and set up the non-embedded mailbox command */
  9530. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  9531. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  9532. LPFC_SLI4_MBX_NEMBED);
  9533. if (alloclen < reqlen) {
  9534. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9535. "2561 Allocated DMA memory size (%d) is "
  9536. "less than the requested DMA memory "
  9537. "size (%d)\n", alloclen, reqlen);
  9538. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9539. return -ENOMEM;
  9540. }
  9541. /* Get the first SGE entry from the non-embedded DMA memory */
  9542. if (unlikely(!mbox->sge_array)) {
  9543. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9544. "2565 Failed to get the non-embedded SGE "
  9545. "virtual address\n");
  9546. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9547. return -ENOMEM;
  9548. }
  9549. viraddr = mbox->sge_array->addr[0];
  9550. /* Set up the SGL pages in the non-embedded DMA pages */
  9551. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  9552. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  9553. pg_pairs = 0;
  9554. list_for_each_entry(psb, sblist, list) {
  9555. /* Set up the sge entry */
  9556. sgl_pg_pairs->sgl_pg0_addr_lo =
  9557. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  9558. sgl_pg_pairs->sgl_pg0_addr_hi =
  9559. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  9560. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  9561. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  9562. else
  9563. pdma_phys_bpl1 = 0;
  9564. sgl_pg_pairs->sgl_pg1_addr_lo =
  9565. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  9566. sgl_pg_pairs->sgl_pg1_addr_hi =
  9567. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  9568. /* Keep the first xritag on the list */
  9569. if (pg_pairs == 0)
  9570. xritag_start = psb->cur_iocbq.sli4_xritag;
  9571. sgl_pg_pairs++;
  9572. pg_pairs++;
  9573. }
  9574. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  9575. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  9576. /* Perform endian conversion if necessary */
  9577. sgl->word0 = cpu_to_le32(sgl->word0);
  9578. if (!phba->sli4_hba.intr_enable)
  9579. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  9580. else {
  9581. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  9582. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  9583. }
  9584. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  9585. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  9586. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  9587. if (rc != MBX_TIMEOUT)
  9588. lpfc_sli4_mbox_cmd_free(phba, mbox);
  9589. if (shdr_status || shdr_add_status || rc) {
  9590. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9591. "2564 POST_SGL_BLOCK mailbox command failed "
  9592. "status x%x add_status x%x mbx status x%x\n",
  9593. shdr_status, shdr_add_status, rc);
  9594. rc = -ENXIO;
  9595. }
  9596. return rc;
  9597. }
  9598. /**
  9599. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  9600. * @phba: pointer to lpfc_hba struct that the frame was received on
  9601. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9602. *
  9603. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  9604. * valid type of frame that the LPFC driver will handle. This function will
  9605. * return a zero if the frame is a valid frame or a non zero value when the
  9606. * frame does not pass the check.
  9607. **/
  9608. static int
  9609. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  9610. {
  9611. char *rctl_names[] = FC_RCTL_NAMES_INIT;
  9612. char *type_names[] = FC_TYPE_NAMES_INIT;
  9613. struct fc_vft_header *fc_vft_hdr;
  9614. switch (fc_hdr->fh_r_ctl) {
  9615. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  9616. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  9617. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  9618. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  9619. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  9620. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  9621. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  9622. case FC_RCTL_DD_CMD_STATUS: /* command status */
  9623. case FC_RCTL_ELS_REQ: /* extended link services request */
  9624. case FC_RCTL_ELS_REP: /* extended link services reply */
  9625. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  9626. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  9627. case FC_RCTL_BA_NOP: /* basic link service NOP */
  9628. case FC_RCTL_BA_ABTS: /* basic link service abort */
  9629. case FC_RCTL_BA_RMC: /* remove connection */
  9630. case FC_RCTL_BA_ACC: /* basic accept */
  9631. case FC_RCTL_BA_RJT: /* basic reject */
  9632. case FC_RCTL_BA_PRMT:
  9633. case FC_RCTL_ACK_1: /* acknowledge_1 */
  9634. case FC_RCTL_ACK_0: /* acknowledge_0 */
  9635. case FC_RCTL_P_RJT: /* port reject */
  9636. case FC_RCTL_F_RJT: /* fabric reject */
  9637. case FC_RCTL_P_BSY: /* port busy */
  9638. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  9639. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  9640. case FC_RCTL_LCR: /* link credit reset */
  9641. case FC_RCTL_END: /* end */
  9642. break;
  9643. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  9644. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9645. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  9646. return lpfc_fc_frame_check(phba, fc_hdr);
  9647. default:
  9648. goto drop;
  9649. }
  9650. switch (fc_hdr->fh_type) {
  9651. case FC_TYPE_BLS:
  9652. case FC_TYPE_ELS:
  9653. case FC_TYPE_FCP:
  9654. case FC_TYPE_CT:
  9655. break;
  9656. case FC_TYPE_IP:
  9657. case FC_TYPE_ILS:
  9658. default:
  9659. goto drop;
  9660. }
  9661. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9662. "2538 Received frame rctl:%s type:%s\n",
  9663. rctl_names[fc_hdr->fh_r_ctl],
  9664. type_names[fc_hdr->fh_type]);
  9665. return 0;
  9666. drop:
  9667. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  9668. "2539 Dropped frame rctl:%s type:%s\n",
  9669. rctl_names[fc_hdr->fh_r_ctl],
  9670. type_names[fc_hdr->fh_type]);
  9671. return 1;
  9672. }
  9673. /**
  9674. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  9675. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9676. *
  9677. * This function processes the FC header to retrieve the VFI from the VF
  9678. * header, if one exists. This function will return the VFI if one exists
  9679. * or 0 if no VSAN Header exists.
  9680. **/
  9681. static uint32_t
  9682. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  9683. {
  9684. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  9685. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  9686. return 0;
  9687. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  9688. }
  9689. /**
  9690. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  9691. * @phba: Pointer to the HBA structure to search for the vport on
  9692. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  9693. * @fcfi: The FC Fabric ID that the frame came from
  9694. *
  9695. * This function searches the @phba for a vport that matches the content of the
  9696. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  9697. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  9698. * returns the matching vport pointer or NULL if unable to match frame to a
  9699. * vport.
  9700. **/
  9701. static struct lpfc_vport *
  9702. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  9703. uint16_t fcfi)
  9704. {
  9705. struct lpfc_vport **vports;
  9706. struct lpfc_vport *vport = NULL;
  9707. int i;
  9708. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  9709. fc_hdr->fh_d_id[1] << 8 |
  9710. fc_hdr->fh_d_id[2]);
  9711. vports = lpfc_create_vport_work_array(phba);
  9712. if (vports != NULL)
  9713. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  9714. if (phba->fcf.fcfi == fcfi &&
  9715. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  9716. vports[i]->fc_myDID == did) {
  9717. vport = vports[i];
  9718. break;
  9719. }
  9720. }
  9721. lpfc_destroy_vport_work_array(phba, vports);
  9722. return vport;
  9723. }
  9724. /**
  9725. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  9726. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  9727. *
  9728. * This function searches through the existing incomplete sequences that have
  9729. * been sent to this @vport. If the frame matches one of the incomplete
  9730. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  9731. * make up that sequence. If no sequence is found that matches this frame then
  9732. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  9733. * This function returns a pointer to the first dmabuf in the sequence list that
  9734. * the frame was linked to.
  9735. **/
  9736. static struct hbq_dmabuf *
  9737. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  9738. {
  9739. struct fc_frame_header *new_hdr;
  9740. struct fc_frame_header *temp_hdr;
  9741. struct lpfc_dmabuf *d_buf;
  9742. struct lpfc_dmabuf *h_buf;
  9743. struct hbq_dmabuf *seq_dmabuf = NULL;
  9744. struct hbq_dmabuf *temp_dmabuf = NULL;
  9745. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9746. /* Use the hdr_buf to find the sequence that this frame belongs to */
  9747. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  9748. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  9749. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  9750. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  9751. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  9752. continue;
  9753. /* found a pending sequence that matches this frame */
  9754. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  9755. break;
  9756. }
  9757. if (!seq_dmabuf) {
  9758. /*
  9759. * This indicates first frame received for this sequence.
  9760. * Queue the buffer on the vport's rcv_buffer_list.
  9761. */
  9762. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  9763. return dmabuf;
  9764. }
  9765. temp_hdr = seq_dmabuf->hbuf.virt;
  9766. if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) {
  9767. list_add(&seq_dmabuf->dbuf.list, &dmabuf->dbuf.list);
  9768. return dmabuf;
  9769. }
  9770. /* find the correct place in the sequence to insert this frame */
  9771. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  9772. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9773. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  9774. /*
  9775. * If the frame's sequence count is greater than the frame on
  9776. * the list then insert the frame right after this frame
  9777. */
  9778. if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) {
  9779. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  9780. return seq_dmabuf;
  9781. }
  9782. }
  9783. return NULL;
  9784. }
  9785. /**
  9786. * lpfc_seq_complete - Indicates if a sequence is complete
  9787. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9788. *
  9789. * This function checks the sequence, starting with the frame described by
  9790. * @dmabuf, to see if all the frames associated with this sequence are present.
  9791. * the frames associated with this sequence are linked to the @dmabuf using the
  9792. * dbuf list. This function looks for two major things. 1) That the first frame
  9793. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  9794. * set. 3) That there are no holes in the sequence count. The function will
  9795. * return 1 when the sequence is complete, otherwise it will return 0.
  9796. **/
  9797. static int
  9798. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  9799. {
  9800. struct fc_frame_header *hdr;
  9801. struct lpfc_dmabuf *d_buf;
  9802. struct hbq_dmabuf *seq_dmabuf;
  9803. uint32_t fctl;
  9804. int seq_count = 0;
  9805. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9806. /* make sure first fame of sequence has a sequence count of zero */
  9807. if (hdr->fh_seq_cnt != seq_count)
  9808. return 0;
  9809. fctl = (hdr->fh_f_ctl[0] << 16 |
  9810. hdr->fh_f_ctl[1] << 8 |
  9811. hdr->fh_f_ctl[2]);
  9812. /* If last frame of sequence we can return success. */
  9813. if (fctl & FC_FC_END_SEQ)
  9814. return 1;
  9815. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  9816. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  9817. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9818. /* If there is a hole in the sequence count then fail. */
  9819. if (++seq_count != hdr->fh_seq_cnt)
  9820. return 0;
  9821. fctl = (hdr->fh_f_ctl[0] << 16 |
  9822. hdr->fh_f_ctl[1] << 8 |
  9823. hdr->fh_f_ctl[2]);
  9824. /* If last frame of sequence we can return success. */
  9825. if (fctl & FC_FC_END_SEQ)
  9826. return 1;
  9827. }
  9828. return 0;
  9829. }
  9830. /**
  9831. * lpfc_prep_seq - Prep sequence for ULP processing
  9832. * @vport: Pointer to the vport on which this sequence was received
  9833. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  9834. *
  9835. * This function takes a sequence, described by a list of frames, and creates
  9836. * a list of iocbq structures to describe the sequence. This iocbq list will be
  9837. * used to issue to the generic unsolicited sequence handler. This routine
  9838. * returns a pointer to the first iocbq in the list. If the function is unable
  9839. * to allocate an iocbq then it throw out the received frames that were not
  9840. * able to be described and return a pointer to the first iocbq. If unable to
  9841. * allocate any iocbqs (including the first) this function will return NULL.
  9842. **/
  9843. static struct lpfc_iocbq *
  9844. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  9845. {
  9846. struct lpfc_dmabuf *d_buf, *n_buf;
  9847. struct lpfc_iocbq *first_iocbq, *iocbq;
  9848. struct fc_frame_header *fc_hdr;
  9849. uint32_t sid;
  9850. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9851. /* remove from receive buffer list */
  9852. list_del_init(&seq_dmabuf->hbuf.list);
  9853. /* get the Remote Port's SID */
  9854. sid = (fc_hdr->fh_s_id[0] << 16 |
  9855. fc_hdr->fh_s_id[1] << 8 |
  9856. fc_hdr->fh_s_id[2]);
  9857. /* Get an iocbq struct to fill in. */
  9858. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  9859. if (first_iocbq) {
  9860. /* Initialize the first IOCB. */
  9861. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  9862. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  9863. first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id);
  9864. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  9865. vport->vpi + vport->phba->vpi_base;
  9866. /* put the first buffer into the first IOCBq */
  9867. first_iocbq->context2 = &seq_dmabuf->dbuf;
  9868. first_iocbq->context3 = NULL;
  9869. first_iocbq->iocb.ulpBdeCount = 1;
  9870. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  9871. LPFC_DATA_BUF_SIZE;
  9872. first_iocbq->iocb.un.rcvels.remoteID = sid;
  9873. }
  9874. iocbq = first_iocbq;
  9875. /*
  9876. * Each IOCBq can have two Buffers assigned, so go through the list
  9877. * of buffers for this sequence and save two buffers in each IOCBq
  9878. */
  9879. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  9880. if (!iocbq) {
  9881. lpfc_in_buf_free(vport->phba, d_buf);
  9882. continue;
  9883. }
  9884. if (!iocbq->context3) {
  9885. iocbq->context3 = d_buf;
  9886. iocbq->iocb.ulpBdeCount++;
  9887. iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize =
  9888. LPFC_DATA_BUF_SIZE;
  9889. } else {
  9890. iocbq = lpfc_sli_get_iocbq(vport->phba);
  9891. if (!iocbq) {
  9892. if (first_iocbq) {
  9893. first_iocbq->iocb.ulpStatus =
  9894. IOSTAT_FCP_RSP_ERROR;
  9895. first_iocbq->iocb.un.ulpWord[4] =
  9896. IOERR_NO_RESOURCES;
  9897. }
  9898. lpfc_in_buf_free(vport->phba, d_buf);
  9899. continue;
  9900. }
  9901. iocbq->context2 = d_buf;
  9902. iocbq->context3 = NULL;
  9903. iocbq->iocb.ulpBdeCount = 1;
  9904. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  9905. LPFC_DATA_BUF_SIZE;
  9906. iocbq->iocb.un.rcvels.remoteID = sid;
  9907. list_add_tail(&iocbq->list, &first_iocbq->list);
  9908. }
  9909. }
  9910. return first_iocbq;
  9911. }
  9912. /**
  9913. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  9914. * @phba: Pointer to HBA context object.
  9915. *
  9916. * This function is called with no lock held. This function processes all
  9917. * the received buffers and gives it to upper layers when a received buffer
  9918. * indicates that it is the final frame in the sequence. The interrupt
  9919. * service routine processes received buffers at interrupt contexts and adds
  9920. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  9921. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  9922. * appropriate receive function when the final frame in a sequence is received.
  9923. **/
  9924. int
  9925. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba)
  9926. {
  9927. LIST_HEAD(cmplq);
  9928. struct hbq_dmabuf *dmabuf, *seq_dmabuf;
  9929. struct fc_frame_header *fc_hdr;
  9930. struct lpfc_vport *vport;
  9931. uint32_t fcfi;
  9932. struct lpfc_iocbq *iocbq;
  9933. /* Clear hba flag and get all received buffers into the cmplq */
  9934. spin_lock_irq(&phba->hbalock);
  9935. phba->hba_flag &= ~HBA_RECEIVE_BUFFER;
  9936. list_splice_init(&phba->rb_pend_list, &cmplq);
  9937. spin_unlock_irq(&phba->hbalock);
  9938. /* Process each received buffer */
  9939. while ((dmabuf = lpfc_sli_hbqbuf_get(&cmplq)) != NULL) {
  9940. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  9941. /* check to see if this a valid type of frame */
  9942. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  9943. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  9944. continue;
  9945. }
  9946. fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->rcqe);
  9947. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  9948. if (!vport) {
  9949. /* throw out the frame */
  9950. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  9951. continue;
  9952. }
  9953. /* Link this frame */
  9954. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  9955. if (!seq_dmabuf) {
  9956. /* unable to add frame to vport - throw it out */
  9957. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  9958. continue;
  9959. }
  9960. /* If not last frame in sequence continue processing frames. */
  9961. if (!lpfc_seq_complete(seq_dmabuf)) {
  9962. /*
  9963. * When saving off frames post a new one and mark this
  9964. * frame to be freed when it is finished.
  9965. **/
  9966. lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1);
  9967. dmabuf->tag = -1;
  9968. continue;
  9969. }
  9970. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  9971. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  9972. if (!lpfc_complete_unsol_iocb(phba,
  9973. &phba->sli.ring[LPFC_ELS_RING],
  9974. iocbq, fc_hdr->fh_r_ctl,
  9975. fc_hdr->fh_type))
  9976. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9977. "2540 Ring %d handler: unexpected Rctl "
  9978. "x%x Type x%x received\n",
  9979. LPFC_ELS_RING,
  9980. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  9981. };
  9982. return 0;
  9983. }
  9984. /**
  9985. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  9986. * @phba: pointer to lpfc hba data structure.
  9987. *
  9988. * This routine is invoked to post rpi header templates to the
  9989. * HBA consistent with the SLI-4 interface spec. This routine
  9990. * posts a PAGE_SIZE memory region to the port to hold up to
  9991. * PAGE_SIZE modulo 64 rpi context headers.
  9992. *
  9993. * This routine does not require any locks. It's usage is expected
  9994. * to be driver load or reset recovery when the driver is
  9995. * sequential.
  9996. *
  9997. * Return codes
  9998. * 0 - sucessful
  9999. * EIO - The mailbox failed to complete successfully.
  10000. * When this error occurs, the driver is not guaranteed
  10001. * to have any rpi regions posted to the device and
  10002. * must either attempt to repost the regions or take a
  10003. * fatal error.
  10004. **/
  10005. int
  10006. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  10007. {
  10008. struct lpfc_rpi_hdr *rpi_page;
  10009. uint32_t rc = 0;
  10010. /* Post all rpi memory regions to the port. */
  10011. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  10012. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  10013. if (rc != MBX_SUCCESS) {
  10014. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10015. "2008 Error %d posting all rpi "
  10016. "headers\n", rc);
  10017. rc = -EIO;
  10018. break;
  10019. }
  10020. }
  10021. return rc;
  10022. }
  10023. /**
  10024. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  10025. * @phba: pointer to lpfc hba data structure.
  10026. * @rpi_page: pointer to the rpi memory region.
  10027. *
  10028. * This routine is invoked to post a single rpi header to the
  10029. * HBA consistent with the SLI-4 interface spec. This memory region
  10030. * maps up to 64 rpi context regions.
  10031. *
  10032. * Return codes
  10033. * 0 - sucessful
  10034. * ENOMEM - No available memory
  10035. * EIO - The mailbox failed to complete successfully.
  10036. **/
  10037. int
  10038. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  10039. {
  10040. LPFC_MBOXQ_t *mboxq;
  10041. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  10042. uint32_t rc = 0;
  10043. uint32_t mbox_tmo;
  10044. uint32_t shdr_status, shdr_add_status;
  10045. union lpfc_sli4_cfg_shdr *shdr;
  10046. /* The port is notified of the header region via a mailbox command. */
  10047. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10048. if (!mboxq) {
  10049. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10050. "2001 Unable to allocate memory for issuing "
  10051. "SLI_CONFIG_SPECIAL mailbox command\n");
  10052. return -ENOMEM;
  10053. }
  10054. /* Post all rpi memory regions to the port. */
  10055. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  10056. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  10057. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10058. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  10059. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  10060. sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED);
  10061. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  10062. hdr_tmpl, rpi_page->page_count);
  10063. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  10064. rpi_page->start_rpi);
  10065. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  10066. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  10067. if (!phba->sli4_hba.intr_enable)
  10068. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  10069. else
  10070. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10071. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  10072. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10073. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10074. if (rc != MBX_TIMEOUT)
  10075. mempool_free(mboxq, phba->mbox_mem_pool);
  10076. if (shdr_status || shdr_add_status || rc) {
  10077. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10078. "2514 POST_RPI_HDR mailbox failed with "
  10079. "status x%x add_status x%x, mbx status x%x\n",
  10080. shdr_status, shdr_add_status, rc);
  10081. rc = -ENXIO;
  10082. }
  10083. return rc;
  10084. }
  10085. /**
  10086. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  10087. * @phba: pointer to lpfc hba data structure.
  10088. *
  10089. * This routine is invoked to post rpi header templates to the
  10090. * HBA consistent with the SLI-4 interface spec. This routine
  10091. * posts a PAGE_SIZE memory region to the port to hold up to
  10092. * PAGE_SIZE modulo 64 rpi context headers.
  10093. *
  10094. * Returns
  10095. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful
  10096. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  10097. **/
  10098. int
  10099. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  10100. {
  10101. int rpi;
  10102. uint16_t max_rpi, rpi_base, rpi_limit;
  10103. uint16_t rpi_remaining;
  10104. struct lpfc_rpi_hdr *rpi_hdr;
  10105. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  10106. rpi_base = phba->sli4_hba.max_cfg_param.rpi_base;
  10107. rpi_limit = phba->sli4_hba.next_rpi;
  10108. /*
  10109. * The valid rpi range is not guaranteed to be zero-based. Start
  10110. * the search at the rpi_base as reported by the port.
  10111. */
  10112. spin_lock_irq(&phba->hbalock);
  10113. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base);
  10114. if (rpi >= rpi_limit || rpi < rpi_base)
  10115. rpi = LPFC_RPI_ALLOC_ERROR;
  10116. else {
  10117. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  10118. phba->sli4_hba.max_cfg_param.rpi_used++;
  10119. phba->sli4_hba.rpi_count++;
  10120. }
  10121. /*
  10122. * Don't try to allocate more rpi header regions if the device limit
  10123. * on available rpis max has been exhausted.
  10124. */
  10125. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  10126. (phba->sli4_hba.rpi_count >= max_rpi)) {
  10127. spin_unlock_irq(&phba->hbalock);
  10128. return rpi;
  10129. }
  10130. /*
  10131. * If the driver is running low on rpi resources, allocate another
  10132. * page now. Note that the next_rpi value is used because
  10133. * it represents how many are actually in use whereas max_rpi notes
  10134. * how many are supported max by the device.
  10135. */
  10136. rpi_remaining = phba->sli4_hba.next_rpi - rpi_base -
  10137. phba->sli4_hba.rpi_count;
  10138. spin_unlock_irq(&phba->hbalock);
  10139. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  10140. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  10141. if (!rpi_hdr) {
  10142. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10143. "2002 Error Could not grow rpi "
  10144. "count\n");
  10145. } else {
  10146. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  10147. }
  10148. }
  10149. return rpi;
  10150. }
  10151. /**
  10152. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  10153. * @phba: pointer to lpfc hba data structure.
  10154. *
  10155. * This routine is invoked to release an rpi to the pool of
  10156. * available rpis maintained by the driver.
  10157. **/
  10158. void
  10159. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  10160. {
  10161. spin_lock_irq(&phba->hbalock);
  10162. clear_bit(rpi, phba->sli4_hba.rpi_bmask);
  10163. phba->sli4_hba.rpi_count--;
  10164. phba->sli4_hba.max_cfg_param.rpi_used--;
  10165. spin_unlock_irq(&phba->hbalock);
  10166. }
  10167. /**
  10168. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  10169. * @phba: pointer to lpfc hba data structure.
  10170. *
  10171. * This routine is invoked to remove the memory region that
  10172. * provided rpi via a bitmask.
  10173. **/
  10174. void
  10175. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  10176. {
  10177. kfree(phba->sli4_hba.rpi_bmask);
  10178. }
  10179. /**
  10180. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  10181. * @phba: pointer to lpfc hba data structure.
  10182. *
  10183. * This routine is invoked to remove the memory region that
  10184. * provided rpi via a bitmask.
  10185. **/
  10186. int
  10187. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp)
  10188. {
  10189. LPFC_MBOXQ_t *mboxq;
  10190. struct lpfc_hba *phba = ndlp->phba;
  10191. int rc;
  10192. /* The port is notified of the header region via a mailbox command. */
  10193. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10194. if (!mboxq)
  10195. return -ENOMEM;
  10196. /* Post all rpi memory regions to the port. */
  10197. lpfc_resume_rpi(mboxq, ndlp);
  10198. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10199. if (rc == MBX_NOT_FINISHED) {
  10200. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10201. "2010 Resume RPI Mailbox failed "
  10202. "status %d, mbxStatus x%x\n", rc,
  10203. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10204. mempool_free(mboxq, phba->mbox_mem_pool);
  10205. return -EIO;
  10206. }
  10207. return 0;
  10208. }
  10209. /**
  10210. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  10211. * @phba: pointer to lpfc hba data structure.
  10212. * @vpi: vpi value to activate with the port.
  10213. *
  10214. * This routine is invoked to activate a vpi with the
  10215. * port when the host intends to use vports with a
  10216. * nonzero vpi.
  10217. *
  10218. * Returns:
  10219. * 0 success
  10220. * -Evalue otherwise
  10221. **/
  10222. int
  10223. lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi)
  10224. {
  10225. LPFC_MBOXQ_t *mboxq;
  10226. int rc = 0;
  10227. uint32_t mbox_tmo;
  10228. if (vpi == 0)
  10229. return -EINVAL;
  10230. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10231. if (!mboxq)
  10232. return -ENOMEM;
  10233. lpfc_init_vpi(mboxq, vpi);
  10234. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI);
  10235. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  10236. if (rc != MBX_TIMEOUT)
  10237. mempool_free(mboxq, phba->mbox_mem_pool);
  10238. if (rc != MBX_SUCCESS) {
  10239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10240. "2022 INIT VPI Mailbox failed "
  10241. "status %d, mbxStatus x%x\n", rc,
  10242. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  10243. rc = -EIO;
  10244. }
  10245. return rc;
  10246. }
  10247. /**
  10248. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  10249. * @phba: pointer to lpfc hba data structure.
  10250. * @mboxq: Pointer to mailbox object.
  10251. *
  10252. * This routine is invoked to manually add a single FCF record. The caller
  10253. * must pass a completely initialized FCF_Record. This routine takes
  10254. * care of the nonembedded mailbox operations.
  10255. **/
  10256. static void
  10257. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  10258. {
  10259. void *virt_addr;
  10260. union lpfc_sli4_cfg_shdr *shdr;
  10261. uint32_t shdr_status, shdr_add_status;
  10262. virt_addr = mboxq->sge_array->addr[0];
  10263. /* The IOCTL status is embedded in the mailbox subheader. */
  10264. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  10265. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10266. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10267. if ((shdr_status || shdr_add_status) &&
  10268. (shdr_status != STATUS_FCF_IN_USE))
  10269. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10270. "2558 ADD_FCF_RECORD mailbox failed with "
  10271. "status x%x add_status x%x\n",
  10272. shdr_status, shdr_add_status);
  10273. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10274. }
  10275. /**
  10276. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  10277. * @phba: pointer to lpfc hba data structure.
  10278. * @fcf_record: pointer to the initialized fcf record to add.
  10279. *
  10280. * This routine is invoked to manually add a single FCF record. The caller
  10281. * must pass a completely initialized FCF_Record. This routine takes
  10282. * care of the nonembedded mailbox operations.
  10283. **/
  10284. int
  10285. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  10286. {
  10287. int rc = 0;
  10288. LPFC_MBOXQ_t *mboxq;
  10289. uint8_t *bytep;
  10290. void *virt_addr;
  10291. dma_addr_t phys_addr;
  10292. struct lpfc_mbx_sge sge;
  10293. uint32_t alloc_len, req_len;
  10294. uint32_t fcfindex;
  10295. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10296. if (!mboxq) {
  10297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10298. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  10299. return -ENOMEM;
  10300. }
  10301. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  10302. sizeof(uint32_t);
  10303. /* Allocate DMA memory and set up the non-embedded mailbox command */
  10304. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10305. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  10306. req_len, LPFC_SLI4_MBX_NEMBED);
  10307. if (alloc_len < req_len) {
  10308. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10309. "2523 Allocated DMA memory size (x%x) is "
  10310. "less than the requested DMA memory "
  10311. "size (x%x)\n", alloc_len, req_len);
  10312. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10313. return -ENOMEM;
  10314. }
  10315. /*
  10316. * Get the first SGE entry from the non-embedded DMA memory. This
  10317. * routine only uses a single SGE.
  10318. */
  10319. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10320. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10321. if (unlikely(!mboxq->sge_array)) {
  10322. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10323. "2526 Failed to get the non-embedded SGE "
  10324. "virtual address\n");
  10325. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10326. return -ENOMEM;
  10327. }
  10328. virt_addr = mboxq->sge_array->addr[0];
  10329. /*
  10330. * Configure the FCF record for FCFI 0. This is the driver's
  10331. * hardcoded default and gets used in nonFIP mode.
  10332. */
  10333. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  10334. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10335. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  10336. /*
  10337. * Copy the fcf_index and the FCF Record Data. The data starts after
  10338. * the FCoE header plus word10. The data copy needs to be endian
  10339. * correct.
  10340. */
  10341. bytep += sizeof(uint32_t);
  10342. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  10343. mboxq->vport = phba->pport;
  10344. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  10345. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10346. if (rc == MBX_NOT_FINISHED) {
  10347. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10348. "2515 ADD_FCF_RECORD mailbox failed with "
  10349. "status 0x%x\n", rc);
  10350. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10351. rc = -EIO;
  10352. } else
  10353. rc = 0;
  10354. return rc;
  10355. }
  10356. /**
  10357. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  10358. * @phba: pointer to lpfc hba data structure.
  10359. * @fcf_record: pointer to the fcf record to write the default data.
  10360. * @fcf_index: FCF table entry index.
  10361. *
  10362. * This routine is invoked to build the driver's default FCF record. The
  10363. * values used are hardcoded. This routine handles memory initialization.
  10364. *
  10365. **/
  10366. void
  10367. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  10368. struct fcf_record *fcf_record,
  10369. uint16_t fcf_index)
  10370. {
  10371. memset(fcf_record, 0, sizeof(struct fcf_record));
  10372. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  10373. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  10374. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  10375. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  10376. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  10377. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  10378. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  10379. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  10380. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  10381. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  10382. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  10383. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  10384. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  10385. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  10386. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  10387. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  10388. /* Set the VLAN bit map */
  10389. if (phba->valid_vlan) {
  10390. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  10391. = 1 << (phba->vlan_id % 8);
  10392. }
  10393. }
  10394. /**
  10395. * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record.
  10396. * @phba: pointer to lpfc hba data structure.
  10397. * @fcf_index: FCF table entry offset.
  10398. *
  10399. * This routine is invoked to read up to @fcf_num of FCF record from the
  10400. * device starting with the given @fcf_index.
  10401. **/
  10402. int
  10403. lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
  10404. {
  10405. int rc = 0, error;
  10406. LPFC_MBOXQ_t *mboxq;
  10407. void *virt_addr;
  10408. dma_addr_t phys_addr;
  10409. uint8_t *bytep;
  10410. struct lpfc_mbx_sge sge;
  10411. uint32_t alloc_len, req_len;
  10412. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  10413. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10414. if (!mboxq) {
  10415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10416. "2000 Failed to allocate mbox for "
  10417. "READ_FCF cmd\n");
  10418. return -ENOMEM;
  10419. }
  10420. req_len = sizeof(struct fcf_record) +
  10421. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  10422. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  10423. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  10424. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  10425. LPFC_SLI4_MBX_NEMBED);
  10426. if (alloc_len < req_len) {
  10427. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10428. "0291 Allocated DMA memory size (x%x) is "
  10429. "less than the requested DMA memory "
  10430. "size (x%x)\n", alloc_len, req_len);
  10431. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10432. return -ENOMEM;
  10433. }
  10434. /* Get the first SGE entry from the non-embedded DMA memory. This
  10435. * routine only uses a single SGE.
  10436. */
  10437. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  10438. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  10439. if (unlikely(!mboxq->sge_array)) {
  10440. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10441. "2527 Failed to get the non-embedded SGE "
  10442. "virtual address\n");
  10443. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10444. return -ENOMEM;
  10445. }
  10446. virt_addr = mboxq->sge_array->addr[0];
  10447. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  10448. /* Set up command fields */
  10449. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  10450. /* Perform necessary endian conversion */
  10451. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  10452. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  10453. mboxq->vport = phba->pport;
  10454. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
  10455. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  10456. if (rc == MBX_NOT_FINISHED) {
  10457. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  10458. error = -EIO;
  10459. } else
  10460. error = 0;
  10461. return error;
  10462. }