lpfc_scsi.c 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2014 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/pci.h>
  22. #include <linux/slab.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/export.h>
  25. #include <linux/delay.h>
  26. #include <asm/unaligned.h>
  27. #include <linux/crc-t10dif.h>
  28. #include <net/checksum.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_eh.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_tcq.h>
  34. #include <scsi/scsi_transport_fc.h>
  35. #include "lpfc_version.h"
  36. #include "lpfc_hw4.h"
  37. #include "lpfc_hw.h"
  38. #include "lpfc_sli.h"
  39. #include "lpfc_sli4.h"
  40. #include "lpfc_nl.h"
  41. #include "lpfc_disc.h"
  42. #include "lpfc.h"
  43. #include "lpfc_scsi.h"
  44. #include "lpfc_logmsg.h"
  45. #include "lpfc_crtn.h"
  46. #include "lpfc_vport.h"
  47. #define LPFC_RESET_WAIT 2
  48. #define LPFC_ABORT_WAIT 2
  49. int _dump_buf_done = 1;
  50. static char *dif_op_str[] = {
  51. "PROT_NORMAL",
  52. "PROT_READ_INSERT",
  53. "PROT_WRITE_STRIP",
  54. "PROT_READ_STRIP",
  55. "PROT_WRITE_INSERT",
  56. "PROT_READ_PASS",
  57. "PROT_WRITE_PASS",
  58. };
  59. struct scsi_dif_tuple {
  60. __be16 guard_tag; /* Checksum */
  61. __be16 app_tag; /* Opaque storage */
  62. __be32 ref_tag; /* Target LBA or indirect LBA */
  63. };
  64. static struct lpfc_rport_data *
  65. lpfc_rport_data_from_scsi_device(struct scsi_device *sdev)
  66. {
  67. struct lpfc_vport *vport = (struct lpfc_vport *)sdev->host->hostdata;
  68. if (vport->phba->cfg_fof)
  69. return ((struct lpfc_device_data *)sdev->hostdata)->rport_data;
  70. else
  71. return (struct lpfc_rport_data *)sdev->hostdata;
  72. }
  73. static void
  74. lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
  75. static void
  76. lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
  77. static int
  78. lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc);
  79. static void
  80. lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
  81. {
  82. void *src, *dst;
  83. struct scatterlist *sgde = scsi_sglist(cmnd);
  84. if (!_dump_buf_data) {
  85. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  86. "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
  87. __func__);
  88. return;
  89. }
  90. if (!sgde) {
  91. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  92. "9051 BLKGRD: ERROR: data scatterlist is null\n");
  93. return;
  94. }
  95. dst = (void *) _dump_buf_data;
  96. while (sgde) {
  97. src = sg_virt(sgde);
  98. memcpy(dst, src, sgde->length);
  99. dst += sgde->length;
  100. sgde = sg_next(sgde);
  101. }
  102. }
  103. static void
  104. lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
  105. {
  106. void *src, *dst;
  107. struct scatterlist *sgde = scsi_prot_sglist(cmnd);
  108. if (!_dump_buf_dif) {
  109. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  110. "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
  111. __func__);
  112. return;
  113. }
  114. if (!sgde) {
  115. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  116. "9053 BLKGRD: ERROR: prot scatterlist is null\n");
  117. return;
  118. }
  119. dst = _dump_buf_dif;
  120. while (sgde) {
  121. src = sg_virt(sgde);
  122. memcpy(dst, src, sgde->length);
  123. dst += sgde->length;
  124. sgde = sg_next(sgde);
  125. }
  126. }
  127. static inline unsigned
  128. lpfc_cmd_blksize(struct scsi_cmnd *sc)
  129. {
  130. return sc->device->sector_size;
  131. }
  132. #define LPFC_CHECK_PROTECT_GUARD 1
  133. #define LPFC_CHECK_PROTECT_REF 2
  134. static inline unsigned
  135. lpfc_cmd_protect(struct scsi_cmnd *sc, int flag)
  136. {
  137. return 1;
  138. }
  139. static inline unsigned
  140. lpfc_cmd_guard_csum(struct scsi_cmnd *sc)
  141. {
  142. if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF)
  143. return 0;
  144. if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP)
  145. return 1;
  146. return 0;
  147. }
  148. /**
  149. * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
  150. * @phba: Pointer to HBA object.
  151. * @lpfc_cmd: lpfc scsi command object pointer.
  152. *
  153. * This function is called from the lpfc_prep_task_mgmt_cmd function to
  154. * set the last bit in the response sge entry.
  155. **/
  156. static void
  157. lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
  158. struct lpfc_scsi_buf *lpfc_cmd)
  159. {
  160. struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  161. if (sgl) {
  162. sgl += 1;
  163. sgl->word2 = le32_to_cpu(sgl->word2);
  164. bf_set(lpfc_sli4_sge_last, sgl, 1);
  165. sgl->word2 = cpu_to_le32(sgl->word2);
  166. }
  167. }
  168. /**
  169. * lpfc_update_stats - Update statistical data for the command completion
  170. * @phba: Pointer to HBA object.
  171. * @lpfc_cmd: lpfc scsi command object pointer.
  172. *
  173. * This function is called when there is a command completion and this
  174. * function updates the statistical data for the command completion.
  175. **/
  176. static void
  177. lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  178. {
  179. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  180. struct lpfc_nodelist *pnode = rdata->pnode;
  181. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  182. unsigned long flags;
  183. struct Scsi_Host *shost = cmd->device->host;
  184. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  185. unsigned long latency;
  186. int i;
  187. if (cmd->result)
  188. return;
  189. latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
  190. spin_lock_irqsave(shost->host_lock, flags);
  191. if (!vport->stat_data_enabled ||
  192. vport->stat_data_blocked ||
  193. !pnode ||
  194. !pnode->lat_data ||
  195. (phba->bucket_type == LPFC_NO_BUCKET)) {
  196. spin_unlock_irqrestore(shost->host_lock, flags);
  197. return;
  198. }
  199. if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
  200. i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
  201. phba->bucket_step;
  202. /* check array subscript bounds */
  203. if (i < 0)
  204. i = 0;
  205. else if (i >= LPFC_MAX_BUCKET_COUNT)
  206. i = LPFC_MAX_BUCKET_COUNT - 1;
  207. } else {
  208. for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
  209. if (latency <= (phba->bucket_base +
  210. ((1<<i)*phba->bucket_step)))
  211. break;
  212. }
  213. pnode->lat_data[i].cmd_count++;
  214. spin_unlock_irqrestore(shost->host_lock, flags);
  215. }
  216. /**
  217. * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
  218. * @phba: Pointer to HBA context object.
  219. * @vport: Pointer to vport object.
  220. * @ndlp: Pointer to FC node associated with the target.
  221. * @lun: Lun number of the scsi device.
  222. * @old_val: Old value of the queue depth.
  223. * @new_val: New value of the queue depth.
  224. *
  225. * This function sends an event to the mgmt application indicating
  226. * there is a change in the scsi device queue depth.
  227. **/
  228. static void
  229. lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba,
  230. struct lpfc_vport *vport,
  231. struct lpfc_nodelist *ndlp,
  232. uint64_t lun,
  233. uint32_t old_val,
  234. uint32_t new_val)
  235. {
  236. struct lpfc_fast_path_event *fast_path_evt;
  237. unsigned long flags;
  238. fast_path_evt = lpfc_alloc_fast_evt(phba);
  239. if (!fast_path_evt)
  240. return;
  241. fast_path_evt->un.queue_depth_evt.scsi_event.event_type =
  242. FC_REG_SCSI_EVENT;
  243. fast_path_evt->un.queue_depth_evt.scsi_event.subcategory =
  244. LPFC_EVENT_VARQUEDEPTH;
  245. /* Report all luns with change in queue depth */
  246. fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun;
  247. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  248. memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn,
  249. &ndlp->nlp_portname, sizeof(struct lpfc_name));
  250. memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn,
  251. &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  252. }
  253. fast_path_evt->un.queue_depth_evt.oldval = old_val;
  254. fast_path_evt->un.queue_depth_evt.newval = new_val;
  255. fast_path_evt->vport = vport;
  256. fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  257. spin_lock_irqsave(&phba->hbalock, flags);
  258. list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
  259. spin_unlock_irqrestore(&phba->hbalock, flags);
  260. lpfc_worker_wake_up(phba);
  261. return;
  262. }
  263. /**
  264. * lpfc_change_queue_depth - Alter scsi device queue depth
  265. * @sdev: Pointer the scsi device on which to change the queue depth.
  266. * @qdepth: New queue depth to set the sdev to.
  267. * @reason: The reason for the queue depth change.
  268. *
  269. * This function is called by the midlayer and the LLD to alter the queue
  270. * depth for a scsi device. This function sets the queue depth to the new
  271. * value and sends an event out to log the queue depth change.
  272. **/
  273. static int
  274. lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  275. {
  276. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  277. struct lpfc_hba *phba = vport->phba;
  278. struct lpfc_rport_data *rdata;
  279. unsigned long new_queue_depth, old_queue_depth;
  280. old_queue_depth = sdev->queue_depth;
  281. switch (reason) {
  282. case SCSI_QDEPTH_DEFAULT:
  283. /* change request from sysfs, fall through */
  284. case SCSI_QDEPTH_RAMP_UP:
  285. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  286. break;
  287. case SCSI_QDEPTH_QFULL:
  288. if (scsi_track_queue_full(sdev, qdepth) == 0)
  289. return sdev->queue_depth;
  290. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  291. "0711 detected queue full - lun queue "
  292. "depth adjusted to %d.\n", sdev->queue_depth);
  293. break;
  294. default:
  295. return -EOPNOTSUPP;
  296. }
  297. new_queue_depth = sdev->queue_depth;
  298. rdata = lpfc_rport_data_from_scsi_device(sdev);
  299. if (rdata)
  300. lpfc_send_sdev_queuedepth_change_event(phba, vport,
  301. rdata->pnode, sdev->lun,
  302. old_queue_depth,
  303. new_queue_depth);
  304. return sdev->queue_depth;
  305. }
  306. /**
  307. * lpfc_change_queue_type() - Change a device's scsi tag queuing type
  308. * @sdev: Pointer the scsi device whose queue depth is to change
  309. * @tag_type: Identifier for queue tag type
  310. */
  311. static int
  312. lpfc_change_queue_type(struct scsi_device *sdev, int tag_type)
  313. {
  314. if (sdev->tagged_supported) {
  315. scsi_set_tag_type(sdev, tag_type);
  316. if (tag_type)
  317. scsi_activate_tcq(sdev, sdev->queue_depth);
  318. else
  319. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  320. } else
  321. tag_type = 0;
  322. return tag_type;
  323. }
  324. /**
  325. * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
  326. * @phba: The Hba for which this call is being executed.
  327. *
  328. * This routine is called when there is resource error in driver or firmware.
  329. * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
  330. * posts at most 1 event each second. This routine wakes up worker thread of
  331. * @phba to process WORKER_RAM_DOWN_EVENT event.
  332. *
  333. * This routine should be called with no lock held.
  334. **/
  335. void
  336. lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
  337. {
  338. unsigned long flags;
  339. uint32_t evt_posted;
  340. unsigned long expires;
  341. spin_lock_irqsave(&phba->hbalock, flags);
  342. atomic_inc(&phba->num_rsrc_err);
  343. phba->last_rsrc_error_time = jiffies;
  344. expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
  345. if (time_after(expires, jiffies)) {
  346. spin_unlock_irqrestore(&phba->hbalock, flags);
  347. return;
  348. }
  349. phba->last_ramp_down_time = jiffies;
  350. spin_unlock_irqrestore(&phba->hbalock, flags);
  351. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  352. evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
  353. if (!evt_posted)
  354. phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
  355. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  356. if (!evt_posted)
  357. lpfc_worker_wake_up(phba);
  358. return;
  359. }
  360. /**
  361. * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
  362. * @phba: The Hba for which this call is being executed.
  363. *
  364. * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
  365. * thread.This routine reduces queue depth for all scsi device on each vport
  366. * associated with @phba.
  367. **/
  368. void
  369. lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
  370. {
  371. struct lpfc_vport **vports;
  372. struct Scsi_Host *shost;
  373. struct scsi_device *sdev;
  374. unsigned long new_queue_depth;
  375. unsigned long num_rsrc_err, num_cmd_success;
  376. int i;
  377. num_rsrc_err = atomic_read(&phba->num_rsrc_err);
  378. num_cmd_success = atomic_read(&phba->num_cmd_success);
  379. /*
  380. * The error and success command counters are global per
  381. * driver instance. If another handler has already
  382. * operated on this error event, just exit.
  383. */
  384. if (num_rsrc_err == 0)
  385. return;
  386. vports = lpfc_create_vport_work_array(phba);
  387. if (vports != NULL)
  388. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  389. shost = lpfc_shost_from_vport(vports[i]);
  390. shost_for_each_device(sdev, shost) {
  391. new_queue_depth =
  392. sdev->queue_depth * num_rsrc_err /
  393. (num_rsrc_err + num_cmd_success);
  394. if (!new_queue_depth)
  395. new_queue_depth = sdev->queue_depth - 1;
  396. else
  397. new_queue_depth = sdev->queue_depth -
  398. new_queue_depth;
  399. lpfc_change_queue_depth(sdev, new_queue_depth,
  400. SCSI_QDEPTH_DEFAULT);
  401. }
  402. }
  403. lpfc_destroy_vport_work_array(phba, vports);
  404. atomic_set(&phba->num_rsrc_err, 0);
  405. atomic_set(&phba->num_cmd_success, 0);
  406. }
  407. /**
  408. * lpfc_scsi_dev_block - set all scsi hosts to block state
  409. * @phba: Pointer to HBA context object.
  410. *
  411. * This function walks vport list and set each SCSI host to block state
  412. * by invoking fc_remote_port_delete() routine. This function is invoked
  413. * with EEH when device's PCI slot has been permanently disabled.
  414. **/
  415. void
  416. lpfc_scsi_dev_block(struct lpfc_hba *phba)
  417. {
  418. struct lpfc_vport **vports;
  419. struct Scsi_Host *shost;
  420. struct scsi_device *sdev;
  421. struct fc_rport *rport;
  422. int i;
  423. vports = lpfc_create_vport_work_array(phba);
  424. if (vports != NULL)
  425. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  426. shost = lpfc_shost_from_vport(vports[i]);
  427. shost_for_each_device(sdev, shost) {
  428. rport = starget_to_rport(scsi_target(sdev));
  429. fc_remote_port_delete(rport);
  430. }
  431. }
  432. lpfc_destroy_vport_work_array(phba, vports);
  433. }
  434. /**
  435. * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
  436. * @vport: The virtual port for which this call being executed.
  437. * @num_to_allocate: The requested number of buffers to allocate.
  438. *
  439. * This routine allocates a scsi buffer for device with SLI-3 interface spec,
  440. * the scsi buffer contains all the necessary information needed to initiate
  441. * a SCSI I/O. The non-DMAable buffer region contains information to build
  442. * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
  443. * and the initial BPL. In addition to allocating memory, the FCP CMND and
  444. * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
  445. *
  446. * Return codes:
  447. * int - number of scsi buffers that were allocated.
  448. * 0 = failure, less than num_to_alloc is a partial failure.
  449. **/
  450. static int
  451. lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
  452. {
  453. struct lpfc_hba *phba = vport->phba;
  454. struct lpfc_scsi_buf *psb;
  455. struct ulp_bde64 *bpl;
  456. IOCB_t *iocb;
  457. dma_addr_t pdma_phys_fcp_cmd;
  458. dma_addr_t pdma_phys_fcp_rsp;
  459. dma_addr_t pdma_phys_bpl;
  460. uint16_t iotag;
  461. int bcnt, bpl_size;
  462. bpl_size = phba->cfg_sg_dma_buf_size -
  463. (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
  464. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  465. "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
  466. num_to_alloc, phba->cfg_sg_dma_buf_size,
  467. (int)sizeof(struct fcp_cmnd),
  468. (int)sizeof(struct fcp_rsp), bpl_size);
  469. for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
  470. psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
  471. if (!psb)
  472. break;
  473. /*
  474. * Get memory from the pci pool to map the virt space to pci
  475. * bus space for an I/O. The DMA buffer includes space for the
  476. * struct fcp_cmnd, struct fcp_rsp and the number of bde's
  477. * necessary to support the sg_tablesize.
  478. */
  479. psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
  480. GFP_KERNEL, &psb->dma_handle);
  481. if (!psb->data) {
  482. kfree(psb);
  483. break;
  484. }
  485. /* Initialize virtual ptrs to dma_buf region. */
  486. memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
  487. /* Allocate iotag for psb->cur_iocbq. */
  488. iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
  489. if (iotag == 0) {
  490. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  491. psb->data, psb->dma_handle);
  492. kfree(psb);
  493. break;
  494. }
  495. psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
  496. psb->fcp_cmnd = psb->data;
  497. psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
  498. psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
  499. sizeof(struct fcp_rsp);
  500. /* Initialize local short-hand pointers. */
  501. bpl = psb->fcp_bpl;
  502. pdma_phys_fcp_cmd = psb->dma_handle;
  503. pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
  504. pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
  505. sizeof(struct fcp_rsp);
  506. /*
  507. * The first two bdes are the FCP_CMD and FCP_RSP. The balance
  508. * are sg list bdes. Initialize the first two and leave the
  509. * rest for queuecommand.
  510. */
  511. bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
  512. bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
  513. bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
  514. bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  515. bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
  516. /* Setup the physical region for the FCP RSP */
  517. bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
  518. bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
  519. bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
  520. bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  521. bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
  522. /*
  523. * Since the IOCB for the FCP I/O is built into this
  524. * lpfc_scsi_buf, initialize it with all known data now.
  525. */
  526. iocb = &psb->cur_iocbq.iocb;
  527. iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
  528. if ((phba->sli_rev == 3) &&
  529. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
  530. /* fill in immediate fcp command BDE */
  531. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
  532. iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
  533. iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
  534. unsli3.fcp_ext.icd);
  535. iocb->un.fcpi64.bdl.addrHigh = 0;
  536. iocb->ulpBdeCount = 0;
  537. iocb->ulpLe = 0;
  538. /* fill in response BDE */
  539. iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
  540. BUFF_TYPE_BDE_64;
  541. iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
  542. sizeof(struct fcp_rsp);
  543. iocb->unsli3.fcp_ext.rbde.addrLow =
  544. putPaddrLow(pdma_phys_fcp_rsp);
  545. iocb->unsli3.fcp_ext.rbde.addrHigh =
  546. putPaddrHigh(pdma_phys_fcp_rsp);
  547. } else {
  548. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  549. iocb->un.fcpi64.bdl.bdeSize =
  550. (2 * sizeof(struct ulp_bde64));
  551. iocb->un.fcpi64.bdl.addrLow =
  552. putPaddrLow(pdma_phys_bpl);
  553. iocb->un.fcpi64.bdl.addrHigh =
  554. putPaddrHigh(pdma_phys_bpl);
  555. iocb->ulpBdeCount = 1;
  556. iocb->ulpLe = 1;
  557. }
  558. iocb->ulpClass = CLASS3;
  559. psb->status = IOSTAT_SUCCESS;
  560. /* Put it back into the SCSI buffer list */
  561. psb->cur_iocbq.context1 = psb;
  562. lpfc_release_scsi_buf_s3(phba, psb);
  563. }
  564. return bcnt;
  565. }
  566. /**
  567. * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
  568. * @vport: pointer to lpfc vport data structure.
  569. *
  570. * This routine is invoked by the vport cleanup for deletions and the cleanup
  571. * for an ndlp on removal.
  572. **/
  573. void
  574. lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
  575. {
  576. struct lpfc_hba *phba = vport->phba;
  577. struct lpfc_scsi_buf *psb, *next_psb;
  578. unsigned long iflag = 0;
  579. spin_lock_irqsave(&phba->hbalock, iflag);
  580. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  581. list_for_each_entry_safe(psb, next_psb,
  582. &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
  583. if (psb->rdata && psb->rdata->pnode
  584. && psb->rdata->pnode->vport == vport)
  585. psb->rdata = NULL;
  586. }
  587. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  588. spin_unlock_irqrestore(&phba->hbalock, iflag);
  589. }
  590. /**
  591. * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
  592. * @phba: pointer to lpfc hba data structure.
  593. * @axri: pointer to the fcp xri abort wcqe structure.
  594. *
  595. * This routine is invoked by the worker thread to process a SLI4 fast-path
  596. * FCP aborted xri.
  597. **/
  598. void
  599. lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
  600. struct sli4_wcqe_xri_aborted *axri)
  601. {
  602. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  603. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  604. struct lpfc_scsi_buf *psb, *next_psb;
  605. unsigned long iflag = 0;
  606. struct lpfc_iocbq *iocbq;
  607. int i;
  608. struct lpfc_nodelist *ndlp;
  609. int rrq_empty = 0;
  610. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  611. spin_lock_irqsave(&phba->hbalock, iflag);
  612. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  613. list_for_each_entry_safe(psb, next_psb,
  614. &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
  615. if (psb->cur_iocbq.sli4_xritag == xri) {
  616. list_del(&psb->list);
  617. psb->exch_busy = 0;
  618. psb->status = IOSTAT_SUCCESS;
  619. spin_unlock(
  620. &phba->sli4_hba.abts_scsi_buf_list_lock);
  621. if (psb->rdata && psb->rdata->pnode)
  622. ndlp = psb->rdata->pnode;
  623. else
  624. ndlp = NULL;
  625. rrq_empty = list_empty(&phba->active_rrq_list);
  626. spin_unlock_irqrestore(&phba->hbalock, iflag);
  627. if (ndlp) {
  628. lpfc_set_rrq_active(phba, ndlp,
  629. psb->cur_iocbq.sli4_lxritag, rxid, 1);
  630. lpfc_sli4_abts_err_handler(phba, ndlp, axri);
  631. }
  632. lpfc_release_scsi_buf_s4(phba, psb);
  633. if (rrq_empty)
  634. lpfc_worker_wake_up(phba);
  635. return;
  636. }
  637. }
  638. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  639. for (i = 1; i <= phba->sli.last_iotag; i++) {
  640. iocbq = phba->sli.iocbq_lookup[i];
  641. if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
  642. (iocbq->iocb_flag & LPFC_IO_LIBDFC))
  643. continue;
  644. if (iocbq->sli4_xritag != xri)
  645. continue;
  646. psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  647. psb->exch_busy = 0;
  648. spin_unlock_irqrestore(&phba->hbalock, iflag);
  649. if (!list_empty(&pring->txq))
  650. lpfc_worker_wake_up(phba);
  651. return;
  652. }
  653. spin_unlock_irqrestore(&phba->hbalock, iflag);
  654. }
  655. /**
  656. * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list
  657. * @phba: pointer to lpfc hba data structure.
  658. * @post_sblist: pointer to the scsi buffer list.
  659. *
  660. * This routine walks a list of scsi buffers that was passed in. It attempts
  661. * to construct blocks of scsi buffer sgls which contains contiguous xris and
  662. * uses the non-embedded SGL block post mailbox commands to post to the port.
  663. * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use
  664. * embedded SGL post mailbox command for posting. The @post_sblist passed in
  665. * must be local list, thus no lock is needed when manipulate the list.
  666. *
  667. * Returns: 0 = failure, non-zero number of successfully posted buffers.
  668. **/
  669. static int
  670. lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba,
  671. struct list_head *post_sblist, int sb_count)
  672. {
  673. struct lpfc_scsi_buf *psb, *psb_next;
  674. int status, sgl_size;
  675. int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
  676. dma_addr_t pdma_phys_bpl1;
  677. int last_xritag = NO_XRI;
  678. LIST_HEAD(prep_sblist);
  679. LIST_HEAD(blck_sblist);
  680. LIST_HEAD(scsi_sblist);
  681. /* sanity check */
  682. if (sb_count <= 0)
  683. return -EINVAL;
  684. sgl_size = phba->cfg_sg_dma_buf_size -
  685. (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
  686. list_for_each_entry_safe(psb, psb_next, post_sblist, list) {
  687. list_del_init(&psb->list);
  688. block_cnt++;
  689. if ((last_xritag != NO_XRI) &&
  690. (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) {
  691. /* a hole in xri block, form a sgl posting block */
  692. list_splice_init(&prep_sblist, &blck_sblist);
  693. post_cnt = block_cnt - 1;
  694. /* prepare list for next posting block */
  695. list_add_tail(&psb->list, &prep_sblist);
  696. block_cnt = 1;
  697. } else {
  698. /* prepare list for next posting block */
  699. list_add_tail(&psb->list, &prep_sblist);
  700. /* enough sgls for non-embed sgl mbox command */
  701. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  702. list_splice_init(&prep_sblist, &blck_sblist);
  703. post_cnt = block_cnt;
  704. block_cnt = 0;
  705. }
  706. }
  707. num_posting++;
  708. last_xritag = psb->cur_iocbq.sli4_xritag;
  709. /* end of repost sgl list condition for SCSI buffers */
  710. if (num_posting == sb_count) {
  711. if (post_cnt == 0) {
  712. /* last sgl posting block */
  713. list_splice_init(&prep_sblist, &blck_sblist);
  714. post_cnt = block_cnt;
  715. } else if (block_cnt == 1) {
  716. /* last single sgl with non-contiguous xri */
  717. if (sgl_size > SGL_PAGE_SIZE)
  718. pdma_phys_bpl1 = psb->dma_phys_bpl +
  719. SGL_PAGE_SIZE;
  720. else
  721. pdma_phys_bpl1 = 0;
  722. status = lpfc_sli4_post_sgl(phba,
  723. psb->dma_phys_bpl,
  724. pdma_phys_bpl1,
  725. psb->cur_iocbq.sli4_xritag);
  726. if (status) {
  727. /* failure, put on abort scsi list */
  728. psb->exch_busy = 1;
  729. } else {
  730. /* success, put on SCSI buffer list */
  731. psb->exch_busy = 0;
  732. psb->status = IOSTAT_SUCCESS;
  733. num_posted++;
  734. }
  735. /* success, put on SCSI buffer sgl list */
  736. list_add_tail(&psb->list, &scsi_sblist);
  737. }
  738. }
  739. /* continue until a nembed page worth of sgls */
  740. if (post_cnt == 0)
  741. continue;
  742. /* post block of SCSI buffer list sgls */
  743. status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist,
  744. post_cnt);
  745. /* don't reset xirtag due to hole in xri block */
  746. if (block_cnt == 0)
  747. last_xritag = NO_XRI;
  748. /* reset SCSI buffer post count for next round of posting */
  749. post_cnt = 0;
  750. /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */
  751. while (!list_empty(&blck_sblist)) {
  752. list_remove_head(&blck_sblist, psb,
  753. struct lpfc_scsi_buf, list);
  754. if (status) {
  755. /* failure, put on abort scsi list */
  756. psb->exch_busy = 1;
  757. } else {
  758. /* success, put on SCSI buffer list */
  759. psb->exch_busy = 0;
  760. psb->status = IOSTAT_SUCCESS;
  761. num_posted++;
  762. }
  763. list_add_tail(&psb->list, &scsi_sblist);
  764. }
  765. }
  766. /* Push SCSI buffers with sgl posted to the availble list */
  767. while (!list_empty(&scsi_sblist)) {
  768. list_remove_head(&scsi_sblist, psb,
  769. struct lpfc_scsi_buf, list);
  770. lpfc_release_scsi_buf_s4(phba, psb);
  771. }
  772. return num_posted;
  773. }
  774. /**
  775. * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls
  776. * @phba: pointer to lpfc hba data structure.
  777. *
  778. * This routine walks the list of scsi buffers that have been allocated and
  779. * repost them to the port by using SGL block post. This is needed after a
  780. * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
  781. * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
  782. * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
  783. *
  784. * Returns: 0 = success, non-zero failure.
  785. **/
  786. int
  787. lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
  788. {
  789. LIST_HEAD(post_sblist);
  790. int num_posted, rc = 0;
  791. /* get all SCSI buffers need to repost to a local list */
  792. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  793. spin_lock(&phba->scsi_buf_list_put_lock);
  794. list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist);
  795. list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist);
  796. spin_unlock(&phba->scsi_buf_list_put_lock);
  797. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  798. /* post the list of scsi buffer sgls to port if available */
  799. if (!list_empty(&post_sblist)) {
  800. num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist,
  801. phba->sli4_hba.scsi_xri_cnt);
  802. /* failed to post any scsi buffer, return error */
  803. if (num_posted == 0)
  804. rc = -EIO;
  805. }
  806. return rc;
  807. }
  808. /**
  809. * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
  810. * @vport: The virtual port for which this call being executed.
  811. * @num_to_allocate: The requested number of buffers to allocate.
  812. *
  813. * This routine allocates scsi buffers for device with SLI-4 interface spec,
  814. * the scsi buffer contains all the necessary information needed to initiate
  815. * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put
  816. * them on a list, it post them to the port by using SGL block post.
  817. *
  818. * Return codes:
  819. * int - number of scsi buffers that were allocated and posted.
  820. * 0 = failure, less than num_to_alloc is a partial failure.
  821. **/
  822. static int
  823. lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
  824. {
  825. struct lpfc_hba *phba = vport->phba;
  826. struct lpfc_scsi_buf *psb;
  827. struct sli4_sge *sgl;
  828. IOCB_t *iocb;
  829. dma_addr_t pdma_phys_fcp_cmd;
  830. dma_addr_t pdma_phys_fcp_rsp;
  831. dma_addr_t pdma_phys_bpl;
  832. uint16_t iotag, lxri = 0;
  833. int bcnt, num_posted, sgl_size;
  834. LIST_HEAD(prep_sblist);
  835. LIST_HEAD(post_sblist);
  836. LIST_HEAD(scsi_sblist);
  837. sgl_size = phba->cfg_sg_dma_buf_size -
  838. (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
  839. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  840. "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n",
  841. num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size,
  842. (int)sizeof(struct fcp_cmnd),
  843. (int)sizeof(struct fcp_rsp));
  844. for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
  845. psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
  846. if (!psb)
  847. break;
  848. /*
  849. * Get memory from the pci pool to map the virt space to
  850. * pci bus space for an I/O. The DMA buffer includes space
  851. * for the struct fcp_cmnd, struct fcp_rsp and the number
  852. * of bde's necessary to support the sg_tablesize.
  853. */
  854. psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
  855. GFP_KERNEL, &psb->dma_handle);
  856. if (!psb->data) {
  857. kfree(psb);
  858. break;
  859. }
  860. memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
  861. /*
  862. * 4K Page alignment is CRITICAL to BlockGuard, double check
  863. * to be sure.
  864. */
  865. if (phba->cfg_enable_bg && (((unsigned long)(psb->data) &
  866. (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) {
  867. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  868. psb->data, psb->dma_handle);
  869. kfree(psb);
  870. break;
  871. }
  872. lxri = lpfc_sli4_next_xritag(phba);
  873. if (lxri == NO_XRI) {
  874. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  875. psb->data, psb->dma_handle);
  876. kfree(psb);
  877. break;
  878. }
  879. /* Allocate iotag for psb->cur_iocbq. */
  880. iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
  881. if (iotag == 0) {
  882. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  883. psb->data, psb->dma_handle);
  884. kfree(psb);
  885. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  886. "3368 Failed to allocated IOTAG for"
  887. " XRI:0x%x\n", lxri);
  888. lpfc_sli4_free_xri(phba, lxri);
  889. break;
  890. }
  891. psb->cur_iocbq.sli4_lxritag = lxri;
  892. psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  893. psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
  894. psb->fcp_bpl = psb->data;
  895. psb->fcp_cmnd = (psb->data + sgl_size);
  896. psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
  897. sizeof(struct fcp_cmnd));
  898. /* Initialize local short-hand pointers. */
  899. sgl = (struct sli4_sge *)psb->fcp_bpl;
  900. pdma_phys_bpl = psb->dma_handle;
  901. pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size);
  902. pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
  903. /*
  904. * The first two bdes are the FCP_CMD and FCP_RSP.
  905. * The balance are sg list bdes. Initialize the
  906. * first two and leave the rest for queuecommand.
  907. */
  908. sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
  909. sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
  910. sgl->word2 = le32_to_cpu(sgl->word2);
  911. bf_set(lpfc_sli4_sge_last, sgl, 0);
  912. sgl->word2 = cpu_to_le32(sgl->word2);
  913. sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
  914. sgl++;
  915. /* Setup the physical region for the FCP RSP */
  916. sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
  917. sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
  918. sgl->word2 = le32_to_cpu(sgl->word2);
  919. bf_set(lpfc_sli4_sge_last, sgl, 1);
  920. sgl->word2 = cpu_to_le32(sgl->word2);
  921. sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
  922. /*
  923. * Since the IOCB for the FCP I/O is built into this
  924. * lpfc_scsi_buf, initialize it with all known data now.
  925. */
  926. iocb = &psb->cur_iocbq.iocb;
  927. iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
  928. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
  929. /* setting the BLP size to 2 * sizeof BDE may not be correct.
  930. * We are setting the bpl to point to out sgl. An sgl's
  931. * entries are 16 bytes, a bpl entries are 12 bytes.
  932. */
  933. iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
  934. iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
  935. iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
  936. iocb->ulpBdeCount = 1;
  937. iocb->ulpLe = 1;
  938. iocb->ulpClass = CLASS3;
  939. psb->cur_iocbq.context1 = psb;
  940. psb->dma_phys_bpl = pdma_phys_bpl;
  941. /* add the scsi buffer to a post list */
  942. list_add_tail(&psb->list, &post_sblist);
  943. spin_lock_irq(&phba->scsi_buf_list_get_lock);
  944. phba->sli4_hba.scsi_xri_cnt++;
  945. spin_unlock_irq(&phba->scsi_buf_list_get_lock);
  946. }
  947. lpfc_printf_log(phba, KERN_INFO, LOG_BG,
  948. "3021 Allocate %d out of %d requested new SCSI "
  949. "buffers\n", bcnt, num_to_alloc);
  950. /* post the list of scsi buffer sgls to port if available */
  951. if (!list_empty(&post_sblist))
  952. num_posted = lpfc_sli4_post_scsi_sgl_list(phba,
  953. &post_sblist, bcnt);
  954. else
  955. num_posted = 0;
  956. return num_posted;
  957. }
  958. /**
  959. * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
  960. * @vport: The virtual port for which this call being executed.
  961. * @num_to_allocate: The requested number of buffers to allocate.
  962. *
  963. * This routine wraps the actual SCSI buffer allocator function pointer from
  964. * the lpfc_hba struct.
  965. *
  966. * Return codes:
  967. * int - number of scsi buffers that were allocated.
  968. * 0 = failure, less than num_to_alloc is a partial failure.
  969. **/
  970. static inline int
  971. lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
  972. {
  973. return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
  974. }
  975. /**
  976. * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  977. * @phba: The HBA for which this call is being executed.
  978. *
  979. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  980. * and returns to caller.
  981. *
  982. * Return codes:
  983. * NULL - Error
  984. * Pointer to lpfc_scsi_buf - Success
  985. **/
  986. static struct lpfc_scsi_buf*
  987. lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  988. {
  989. struct lpfc_scsi_buf * lpfc_cmd = NULL;
  990. struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get;
  991. unsigned long iflag = 0;
  992. spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
  993. list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf,
  994. list);
  995. if (!lpfc_cmd) {
  996. spin_lock(&phba->scsi_buf_list_put_lock);
  997. list_splice(&phba->lpfc_scsi_buf_list_put,
  998. &phba->lpfc_scsi_buf_list_get);
  999. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  1000. list_remove_head(scsi_buf_list_get, lpfc_cmd,
  1001. struct lpfc_scsi_buf, list);
  1002. spin_unlock(&phba->scsi_buf_list_put_lock);
  1003. }
  1004. spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
  1005. return lpfc_cmd;
  1006. }
  1007. /**
  1008. * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  1009. * @phba: The HBA for which this call is being executed.
  1010. *
  1011. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  1012. * and returns to caller.
  1013. *
  1014. * Return codes:
  1015. * NULL - Error
  1016. * Pointer to lpfc_scsi_buf - Success
  1017. **/
  1018. static struct lpfc_scsi_buf*
  1019. lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1020. {
  1021. struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next;
  1022. unsigned long iflag = 0;
  1023. int found = 0;
  1024. spin_lock_irqsave(&phba->scsi_buf_list_get_lock, iflag);
  1025. list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
  1026. &phba->lpfc_scsi_buf_list_get, list) {
  1027. if (lpfc_test_rrq_active(phba, ndlp,
  1028. lpfc_cmd->cur_iocbq.sli4_lxritag))
  1029. continue;
  1030. list_del(&lpfc_cmd->list);
  1031. found = 1;
  1032. break;
  1033. }
  1034. if (!found) {
  1035. spin_lock(&phba->scsi_buf_list_put_lock);
  1036. list_splice(&phba->lpfc_scsi_buf_list_put,
  1037. &phba->lpfc_scsi_buf_list_get);
  1038. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
  1039. spin_unlock(&phba->scsi_buf_list_put_lock);
  1040. list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
  1041. &phba->lpfc_scsi_buf_list_get, list) {
  1042. if (lpfc_test_rrq_active(
  1043. phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag))
  1044. continue;
  1045. list_del(&lpfc_cmd->list);
  1046. found = 1;
  1047. break;
  1048. }
  1049. }
  1050. spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, iflag);
  1051. if (!found)
  1052. return NULL;
  1053. return lpfc_cmd;
  1054. }
  1055. /**
  1056. * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  1057. * @phba: The HBA for which this call is being executed.
  1058. *
  1059. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  1060. * and returns to caller.
  1061. *
  1062. * Return codes:
  1063. * NULL - Error
  1064. * Pointer to lpfc_scsi_buf - Success
  1065. **/
  1066. static struct lpfc_scsi_buf*
  1067. lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1068. {
  1069. return phba->lpfc_get_scsi_buf(phba, ndlp);
  1070. }
  1071. /**
  1072. * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
  1073. * @phba: The Hba for which this call is being executed.
  1074. * @psb: The scsi buffer which is being released.
  1075. *
  1076. * This routine releases @psb scsi buffer by adding it to tail of @phba
  1077. * lpfc_scsi_buf_list list.
  1078. **/
  1079. static void
  1080. lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  1081. {
  1082. unsigned long iflag = 0;
  1083. psb->seg_cnt = 0;
  1084. psb->nonsg_phys = 0;
  1085. psb->prot_seg_cnt = 0;
  1086. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  1087. psb->pCmd = NULL;
  1088. psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
  1089. list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
  1090. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  1091. }
  1092. /**
  1093. * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
  1094. * @phba: The Hba for which this call is being executed.
  1095. * @psb: The scsi buffer which is being released.
  1096. *
  1097. * This routine releases @psb scsi buffer by adding it to tail of @phba
  1098. * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
  1099. * and cannot be reused for at least RA_TOV amount of time if it was
  1100. * aborted.
  1101. **/
  1102. static void
  1103. lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  1104. {
  1105. unsigned long iflag = 0;
  1106. psb->seg_cnt = 0;
  1107. psb->nonsg_phys = 0;
  1108. psb->prot_seg_cnt = 0;
  1109. if (psb->exch_busy) {
  1110. spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
  1111. iflag);
  1112. psb->pCmd = NULL;
  1113. list_add_tail(&psb->list,
  1114. &phba->sli4_hba.lpfc_abts_scsi_buf_list);
  1115. spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
  1116. iflag);
  1117. } else {
  1118. psb->pCmd = NULL;
  1119. psb->cur_iocbq.iocb_flag = LPFC_IO_FCP;
  1120. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  1121. list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put);
  1122. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  1123. }
  1124. }
  1125. /**
  1126. * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
  1127. * @phba: The Hba for which this call is being executed.
  1128. * @psb: The scsi buffer which is being released.
  1129. *
  1130. * This routine releases @psb scsi buffer by adding it to tail of @phba
  1131. * lpfc_scsi_buf_list list.
  1132. **/
  1133. static void
  1134. lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  1135. {
  1136. phba->lpfc_release_scsi_buf(phba, psb);
  1137. }
  1138. /**
  1139. * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
  1140. * @phba: The Hba for which this call is being executed.
  1141. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  1142. *
  1143. * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
  1144. * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
  1145. * through sg elements and format the bdea. This routine also initializes all
  1146. * IOCB fields which are dependent on scsi command request buffer.
  1147. *
  1148. * Return codes:
  1149. * 1 - Error
  1150. * 0 - Success
  1151. **/
  1152. static int
  1153. lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  1154. {
  1155. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  1156. struct scatterlist *sgel = NULL;
  1157. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  1158. struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
  1159. struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
  1160. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  1161. struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
  1162. dma_addr_t physaddr;
  1163. uint32_t num_bde = 0;
  1164. int nseg, datadir = scsi_cmnd->sc_data_direction;
  1165. /*
  1166. * There are three possibilities here - use scatter-gather segment, use
  1167. * the single mapping, or neither. Start the lpfc command prep by
  1168. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  1169. * data bde entry.
  1170. */
  1171. bpl += 2;
  1172. if (scsi_sg_count(scsi_cmnd)) {
  1173. /*
  1174. * The driver stores the segment count returned from pci_map_sg
  1175. * because this a count of dma-mappings used to map the use_sg
  1176. * pages. They are not guaranteed to be the same for those
  1177. * architectures that implement an IOMMU.
  1178. */
  1179. nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
  1180. scsi_sg_count(scsi_cmnd), datadir);
  1181. if (unlikely(!nseg))
  1182. return 1;
  1183. lpfc_cmd->seg_cnt = nseg;
  1184. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  1185. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1186. "9064 BLKGRD: %s: Too many sg segments from "
  1187. "dma_map_sg. Config %d, seg_cnt %d\n",
  1188. __func__, phba->cfg_sg_seg_cnt,
  1189. lpfc_cmd->seg_cnt);
  1190. lpfc_cmd->seg_cnt = 0;
  1191. scsi_dma_unmap(scsi_cmnd);
  1192. return 1;
  1193. }
  1194. /*
  1195. * The driver established a maximum scatter-gather segment count
  1196. * during probe that limits the number of sg elements in any
  1197. * single scsi command. Just run through the seg_cnt and format
  1198. * the bde's.
  1199. * When using SLI-3 the driver will try to fit all the BDEs into
  1200. * the IOCB. If it can't then the BDEs get added to a BPL as it
  1201. * does for SLI-2 mode.
  1202. */
  1203. scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
  1204. physaddr = sg_dma_address(sgel);
  1205. if (phba->sli_rev == 3 &&
  1206. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  1207. !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
  1208. nseg <= LPFC_EXT_DATA_BDE_COUNT) {
  1209. data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1210. data_bde->tus.f.bdeSize = sg_dma_len(sgel);
  1211. data_bde->addrLow = putPaddrLow(physaddr);
  1212. data_bde->addrHigh = putPaddrHigh(physaddr);
  1213. data_bde++;
  1214. } else {
  1215. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1216. bpl->tus.f.bdeSize = sg_dma_len(sgel);
  1217. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1218. bpl->addrLow =
  1219. le32_to_cpu(putPaddrLow(physaddr));
  1220. bpl->addrHigh =
  1221. le32_to_cpu(putPaddrHigh(physaddr));
  1222. bpl++;
  1223. }
  1224. }
  1225. }
  1226. /*
  1227. * Finish initializing those IOCB fields that are dependent on the
  1228. * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
  1229. * explicitly reinitialized and for SLI-3 the extended bde count is
  1230. * explicitly reinitialized since all iocb memory resources are reused.
  1231. */
  1232. if (phba->sli_rev == 3 &&
  1233. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  1234. !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
  1235. if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
  1236. /*
  1237. * The extended IOCB format can only fit 3 BDE or a BPL.
  1238. * This I/O has more than 3 BDE so the 1st data bde will
  1239. * be a BPL that is filled in here.
  1240. */
  1241. physaddr = lpfc_cmd->dma_handle;
  1242. data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
  1243. data_bde->tus.f.bdeSize = (num_bde *
  1244. sizeof(struct ulp_bde64));
  1245. physaddr += (sizeof(struct fcp_cmnd) +
  1246. sizeof(struct fcp_rsp) +
  1247. (2 * sizeof(struct ulp_bde64)));
  1248. data_bde->addrHigh = putPaddrHigh(physaddr);
  1249. data_bde->addrLow = putPaddrLow(physaddr);
  1250. /* ebde count includes the response bde and data bpl */
  1251. iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
  1252. } else {
  1253. /* ebde count includes the response bde and data bdes */
  1254. iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
  1255. }
  1256. } else {
  1257. iocb_cmd->un.fcpi64.bdl.bdeSize =
  1258. ((num_bde + 2) * sizeof(struct ulp_bde64));
  1259. iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
  1260. }
  1261. fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
  1262. /*
  1263. * Due to difference in data length between DIF/non-DIF paths,
  1264. * we need to set word 4 of IOCB here
  1265. */
  1266. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  1267. return 0;
  1268. }
  1269. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1270. /* Return if if error injection is detected by Initiator */
  1271. #define BG_ERR_INIT 0x1
  1272. /* Return if if error injection is detected by Target */
  1273. #define BG_ERR_TGT 0x2
  1274. /* Return if if swapping CSUM<-->CRC is required for error injection */
  1275. #define BG_ERR_SWAP 0x10
  1276. /* Return if disabling Guard/Ref/App checking is required for error injection */
  1277. #define BG_ERR_CHECK 0x20
  1278. /**
  1279. * lpfc_bg_err_inject - Determine if we should inject an error
  1280. * @phba: The Hba for which this call is being executed.
  1281. * @sc: The SCSI command to examine
  1282. * @reftag: (out) BlockGuard reference tag for transmitted data
  1283. * @apptag: (out) BlockGuard application tag for transmitted data
  1284. * @new_guard (in) Value to replace CRC with if needed
  1285. *
  1286. * Returns BG_ERR_* bit mask or 0 if request ignored
  1287. **/
  1288. static int
  1289. lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1290. uint32_t *reftag, uint16_t *apptag, uint32_t new_guard)
  1291. {
  1292. struct scatterlist *sgpe; /* s/g prot entry */
  1293. struct scatterlist *sgde; /* s/g data entry */
  1294. struct lpfc_scsi_buf *lpfc_cmd = NULL;
  1295. struct scsi_dif_tuple *src = NULL;
  1296. struct lpfc_nodelist *ndlp;
  1297. struct lpfc_rport_data *rdata;
  1298. uint32_t op = scsi_get_prot_op(sc);
  1299. uint32_t blksize;
  1300. uint32_t numblks;
  1301. sector_t lba;
  1302. int rc = 0;
  1303. int blockoff = 0;
  1304. if (op == SCSI_PROT_NORMAL)
  1305. return 0;
  1306. sgpe = scsi_prot_sglist(sc);
  1307. sgde = scsi_sglist(sc);
  1308. lba = scsi_get_lba(sc);
  1309. /* First check if we need to match the LBA */
  1310. if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
  1311. blksize = lpfc_cmd_blksize(sc);
  1312. numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
  1313. /* Make sure we have the right LBA if one is specified */
  1314. if ((phba->lpfc_injerr_lba < lba) ||
  1315. (phba->lpfc_injerr_lba >= (lba + numblks)))
  1316. return 0;
  1317. if (sgpe) {
  1318. blockoff = phba->lpfc_injerr_lba - lba;
  1319. numblks = sg_dma_len(sgpe) /
  1320. sizeof(struct scsi_dif_tuple);
  1321. if (numblks < blockoff)
  1322. blockoff = numblks;
  1323. }
  1324. }
  1325. /* Next check if we need to match the remote NPortID or WWPN */
  1326. rdata = lpfc_rport_data_from_scsi_device(sc->device);
  1327. if (rdata && rdata->pnode) {
  1328. ndlp = rdata->pnode;
  1329. /* Make sure we have the right NPortID if one is specified */
  1330. if (phba->lpfc_injerr_nportid &&
  1331. (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
  1332. return 0;
  1333. /*
  1334. * Make sure we have the right WWPN if one is specified.
  1335. * wwn[0] should be a non-zero NAA in a good WWPN.
  1336. */
  1337. if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
  1338. (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
  1339. sizeof(struct lpfc_name)) != 0))
  1340. return 0;
  1341. }
  1342. /* Setup a ptr to the protection data if the SCSI host provides it */
  1343. if (sgpe) {
  1344. src = (struct scsi_dif_tuple *)sg_virt(sgpe);
  1345. src += blockoff;
  1346. lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
  1347. }
  1348. /* Should we change the Reference Tag */
  1349. if (reftag) {
  1350. if (phba->lpfc_injerr_wref_cnt) {
  1351. switch (op) {
  1352. case SCSI_PROT_WRITE_PASS:
  1353. if (src) {
  1354. /*
  1355. * For WRITE_PASS, force the error
  1356. * to be sent on the wire. It should
  1357. * be detected by the Target.
  1358. * If blockoff != 0 error will be
  1359. * inserted in middle of the IO.
  1360. */
  1361. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1362. "9076 BLKGRD: Injecting reftag error: "
  1363. "write lba x%lx + x%x oldrefTag x%x\n",
  1364. (unsigned long)lba, blockoff,
  1365. be32_to_cpu(src->ref_tag));
  1366. /*
  1367. * Save the old ref_tag so we can
  1368. * restore it on completion.
  1369. */
  1370. if (lpfc_cmd) {
  1371. lpfc_cmd->prot_data_type =
  1372. LPFC_INJERR_REFTAG;
  1373. lpfc_cmd->prot_data_segment =
  1374. src;
  1375. lpfc_cmd->prot_data =
  1376. src->ref_tag;
  1377. }
  1378. src->ref_tag = cpu_to_be32(0xDEADBEEF);
  1379. phba->lpfc_injerr_wref_cnt--;
  1380. if (phba->lpfc_injerr_wref_cnt == 0) {
  1381. phba->lpfc_injerr_nportid = 0;
  1382. phba->lpfc_injerr_lba =
  1383. LPFC_INJERR_LBA_OFF;
  1384. memset(&phba->lpfc_injerr_wwpn,
  1385. 0, sizeof(struct lpfc_name));
  1386. }
  1387. rc = BG_ERR_TGT | BG_ERR_CHECK;
  1388. break;
  1389. }
  1390. /* Drop thru */
  1391. case SCSI_PROT_WRITE_INSERT:
  1392. /*
  1393. * For WRITE_INSERT, force the error
  1394. * to be sent on the wire. It should be
  1395. * detected by the Target.
  1396. */
  1397. /* DEADBEEF will be the reftag on the wire */
  1398. *reftag = 0xDEADBEEF;
  1399. phba->lpfc_injerr_wref_cnt--;
  1400. if (phba->lpfc_injerr_wref_cnt == 0) {
  1401. phba->lpfc_injerr_nportid = 0;
  1402. phba->lpfc_injerr_lba =
  1403. LPFC_INJERR_LBA_OFF;
  1404. memset(&phba->lpfc_injerr_wwpn,
  1405. 0, sizeof(struct lpfc_name));
  1406. }
  1407. rc = BG_ERR_TGT | BG_ERR_CHECK;
  1408. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1409. "9078 BLKGRD: Injecting reftag error: "
  1410. "write lba x%lx\n", (unsigned long)lba);
  1411. break;
  1412. case SCSI_PROT_WRITE_STRIP:
  1413. /*
  1414. * For WRITE_STRIP and WRITE_PASS,
  1415. * force the error on data
  1416. * being copied from SLI-Host to SLI-Port.
  1417. */
  1418. *reftag = 0xDEADBEEF;
  1419. phba->lpfc_injerr_wref_cnt--;
  1420. if (phba->lpfc_injerr_wref_cnt == 0) {
  1421. phba->lpfc_injerr_nportid = 0;
  1422. phba->lpfc_injerr_lba =
  1423. LPFC_INJERR_LBA_OFF;
  1424. memset(&phba->lpfc_injerr_wwpn,
  1425. 0, sizeof(struct lpfc_name));
  1426. }
  1427. rc = BG_ERR_INIT;
  1428. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1429. "9077 BLKGRD: Injecting reftag error: "
  1430. "write lba x%lx\n", (unsigned long)lba);
  1431. break;
  1432. }
  1433. }
  1434. if (phba->lpfc_injerr_rref_cnt) {
  1435. switch (op) {
  1436. case SCSI_PROT_READ_INSERT:
  1437. case SCSI_PROT_READ_STRIP:
  1438. case SCSI_PROT_READ_PASS:
  1439. /*
  1440. * For READ_STRIP and READ_PASS, force the
  1441. * error on data being read off the wire. It
  1442. * should force an IO error to the driver.
  1443. */
  1444. *reftag = 0xDEADBEEF;
  1445. phba->lpfc_injerr_rref_cnt--;
  1446. if (phba->lpfc_injerr_rref_cnt == 0) {
  1447. phba->lpfc_injerr_nportid = 0;
  1448. phba->lpfc_injerr_lba =
  1449. LPFC_INJERR_LBA_OFF;
  1450. memset(&phba->lpfc_injerr_wwpn,
  1451. 0, sizeof(struct lpfc_name));
  1452. }
  1453. rc = BG_ERR_INIT;
  1454. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1455. "9079 BLKGRD: Injecting reftag error: "
  1456. "read lba x%lx\n", (unsigned long)lba);
  1457. break;
  1458. }
  1459. }
  1460. }
  1461. /* Should we change the Application Tag */
  1462. if (apptag) {
  1463. if (phba->lpfc_injerr_wapp_cnt) {
  1464. switch (op) {
  1465. case SCSI_PROT_WRITE_PASS:
  1466. if (src) {
  1467. /*
  1468. * For WRITE_PASS, force the error
  1469. * to be sent on the wire. It should
  1470. * be detected by the Target.
  1471. * If blockoff != 0 error will be
  1472. * inserted in middle of the IO.
  1473. */
  1474. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1475. "9080 BLKGRD: Injecting apptag error: "
  1476. "write lba x%lx + x%x oldappTag x%x\n",
  1477. (unsigned long)lba, blockoff,
  1478. be16_to_cpu(src->app_tag));
  1479. /*
  1480. * Save the old app_tag so we can
  1481. * restore it on completion.
  1482. */
  1483. if (lpfc_cmd) {
  1484. lpfc_cmd->prot_data_type =
  1485. LPFC_INJERR_APPTAG;
  1486. lpfc_cmd->prot_data_segment =
  1487. src;
  1488. lpfc_cmd->prot_data =
  1489. src->app_tag;
  1490. }
  1491. src->app_tag = cpu_to_be16(0xDEAD);
  1492. phba->lpfc_injerr_wapp_cnt--;
  1493. if (phba->lpfc_injerr_wapp_cnt == 0) {
  1494. phba->lpfc_injerr_nportid = 0;
  1495. phba->lpfc_injerr_lba =
  1496. LPFC_INJERR_LBA_OFF;
  1497. memset(&phba->lpfc_injerr_wwpn,
  1498. 0, sizeof(struct lpfc_name));
  1499. }
  1500. rc = BG_ERR_TGT | BG_ERR_CHECK;
  1501. break;
  1502. }
  1503. /* Drop thru */
  1504. case SCSI_PROT_WRITE_INSERT:
  1505. /*
  1506. * For WRITE_INSERT, force the
  1507. * error to be sent on the wire. It should be
  1508. * detected by the Target.
  1509. */
  1510. /* DEAD will be the apptag on the wire */
  1511. *apptag = 0xDEAD;
  1512. phba->lpfc_injerr_wapp_cnt--;
  1513. if (phba->lpfc_injerr_wapp_cnt == 0) {
  1514. phba->lpfc_injerr_nportid = 0;
  1515. phba->lpfc_injerr_lba =
  1516. LPFC_INJERR_LBA_OFF;
  1517. memset(&phba->lpfc_injerr_wwpn,
  1518. 0, sizeof(struct lpfc_name));
  1519. }
  1520. rc = BG_ERR_TGT | BG_ERR_CHECK;
  1521. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1522. "0813 BLKGRD: Injecting apptag error: "
  1523. "write lba x%lx\n", (unsigned long)lba);
  1524. break;
  1525. case SCSI_PROT_WRITE_STRIP:
  1526. /*
  1527. * For WRITE_STRIP and WRITE_PASS,
  1528. * force the error on data
  1529. * being copied from SLI-Host to SLI-Port.
  1530. */
  1531. *apptag = 0xDEAD;
  1532. phba->lpfc_injerr_wapp_cnt--;
  1533. if (phba->lpfc_injerr_wapp_cnt == 0) {
  1534. phba->lpfc_injerr_nportid = 0;
  1535. phba->lpfc_injerr_lba =
  1536. LPFC_INJERR_LBA_OFF;
  1537. memset(&phba->lpfc_injerr_wwpn,
  1538. 0, sizeof(struct lpfc_name));
  1539. }
  1540. rc = BG_ERR_INIT;
  1541. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1542. "0812 BLKGRD: Injecting apptag error: "
  1543. "write lba x%lx\n", (unsigned long)lba);
  1544. break;
  1545. }
  1546. }
  1547. if (phba->lpfc_injerr_rapp_cnt) {
  1548. switch (op) {
  1549. case SCSI_PROT_READ_INSERT:
  1550. case SCSI_PROT_READ_STRIP:
  1551. case SCSI_PROT_READ_PASS:
  1552. /*
  1553. * For READ_STRIP and READ_PASS, force the
  1554. * error on data being read off the wire. It
  1555. * should force an IO error to the driver.
  1556. */
  1557. *apptag = 0xDEAD;
  1558. phba->lpfc_injerr_rapp_cnt--;
  1559. if (phba->lpfc_injerr_rapp_cnt == 0) {
  1560. phba->lpfc_injerr_nportid = 0;
  1561. phba->lpfc_injerr_lba =
  1562. LPFC_INJERR_LBA_OFF;
  1563. memset(&phba->lpfc_injerr_wwpn,
  1564. 0, sizeof(struct lpfc_name));
  1565. }
  1566. rc = BG_ERR_INIT;
  1567. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1568. "0814 BLKGRD: Injecting apptag error: "
  1569. "read lba x%lx\n", (unsigned long)lba);
  1570. break;
  1571. }
  1572. }
  1573. }
  1574. /* Should we change the Guard Tag */
  1575. if (new_guard) {
  1576. if (phba->lpfc_injerr_wgrd_cnt) {
  1577. switch (op) {
  1578. case SCSI_PROT_WRITE_PASS:
  1579. rc = BG_ERR_CHECK;
  1580. /* Drop thru */
  1581. case SCSI_PROT_WRITE_INSERT:
  1582. /*
  1583. * For WRITE_INSERT, force the
  1584. * error to be sent on the wire. It should be
  1585. * detected by the Target.
  1586. */
  1587. phba->lpfc_injerr_wgrd_cnt--;
  1588. if (phba->lpfc_injerr_wgrd_cnt == 0) {
  1589. phba->lpfc_injerr_nportid = 0;
  1590. phba->lpfc_injerr_lba =
  1591. LPFC_INJERR_LBA_OFF;
  1592. memset(&phba->lpfc_injerr_wwpn,
  1593. 0, sizeof(struct lpfc_name));
  1594. }
  1595. rc |= BG_ERR_TGT | BG_ERR_SWAP;
  1596. /* Signals the caller to swap CRC->CSUM */
  1597. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1598. "0817 BLKGRD: Injecting guard error: "
  1599. "write lba x%lx\n", (unsigned long)lba);
  1600. break;
  1601. case SCSI_PROT_WRITE_STRIP:
  1602. /*
  1603. * For WRITE_STRIP and WRITE_PASS,
  1604. * force the error on data
  1605. * being copied from SLI-Host to SLI-Port.
  1606. */
  1607. phba->lpfc_injerr_wgrd_cnt--;
  1608. if (phba->lpfc_injerr_wgrd_cnt == 0) {
  1609. phba->lpfc_injerr_nportid = 0;
  1610. phba->lpfc_injerr_lba =
  1611. LPFC_INJERR_LBA_OFF;
  1612. memset(&phba->lpfc_injerr_wwpn,
  1613. 0, sizeof(struct lpfc_name));
  1614. }
  1615. rc = BG_ERR_INIT | BG_ERR_SWAP;
  1616. /* Signals the caller to swap CRC->CSUM */
  1617. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1618. "0816 BLKGRD: Injecting guard error: "
  1619. "write lba x%lx\n", (unsigned long)lba);
  1620. break;
  1621. }
  1622. }
  1623. if (phba->lpfc_injerr_rgrd_cnt) {
  1624. switch (op) {
  1625. case SCSI_PROT_READ_INSERT:
  1626. case SCSI_PROT_READ_STRIP:
  1627. case SCSI_PROT_READ_PASS:
  1628. /*
  1629. * For READ_STRIP and READ_PASS, force the
  1630. * error on data being read off the wire. It
  1631. * should force an IO error to the driver.
  1632. */
  1633. phba->lpfc_injerr_rgrd_cnt--;
  1634. if (phba->lpfc_injerr_rgrd_cnt == 0) {
  1635. phba->lpfc_injerr_nportid = 0;
  1636. phba->lpfc_injerr_lba =
  1637. LPFC_INJERR_LBA_OFF;
  1638. memset(&phba->lpfc_injerr_wwpn,
  1639. 0, sizeof(struct lpfc_name));
  1640. }
  1641. rc = BG_ERR_INIT | BG_ERR_SWAP;
  1642. /* Signals the caller to swap CRC->CSUM */
  1643. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1644. "0818 BLKGRD: Injecting guard error: "
  1645. "read lba x%lx\n", (unsigned long)lba);
  1646. }
  1647. }
  1648. }
  1649. return rc;
  1650. }
  1651. #endif
  1652. /**
  1653. * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with
  1654. * the specified SCSI command.
  1655. * @phba: The Hba for which this call is being executed.
  1656. * @sc: The SCSI command to examine
  1657. * @txopt: (out) BlockGuard operation for transmitted data
  1658. * @rxopt: (out) BlockGuard operation for received data
  1659. *
  1660. * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
  1661. *
  1662. **/
  1663. static int
  1664. lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1665. uint8_t *txop, uint8_t *rxop)
  1666. {
  1667. uint8_t ret = 0;
  1668. if (lpfc_cmd_guard_csum(sc)) {
  1669. switch (scsi_get_prot_op(sc)) {
  1670. case SCSI_PROT_READ_INSERT:
  1671. case SCSI_PROT_WRITE_STRIP:
  1672. *rxop = BG_OP_IN_NODIF_OUT_CSUM;
  1673. *txop = BG_OP_IN_CSUM_OUT_NODIF;
  1674. break;
  1675. case SCSI_PROT_READ_STRIP:
  1676. case SCSI_PROT_WRITE_INSERT:
  1677. *rxop = BG_OP_IN_CRC_OUT_NODIF;
  1678. *txop = BG_OP_IN_NODIF_OUT_CRC;
  1679. break;
  1680. case SCSI_PROT_READ_PASS:
  1681. case SCSI_PROT_WRITE_PASS:
  1682. *rxop = BG_OP_IN_CRC_OUT_CSUM;
  1683. *txop = BG_OP_IN_CSUM_OUT_CRC;
  1684. break;
  1685. case SCSI_PROT_NORMAL:
  1686. default:
  1687. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1688. "9063 BLKGRD: Bad op/guard:%d/IP combination\n",
  1689. scsi_get_prot_op(sc));
  1690. ret = 1;
  1691. break;
  1692. }
  1693. } else {
  1694. switch (scsi_get_prot_op(sc)) {
  1695. case SCSI_PROT_READ_STRIP:
  1696. case SCSI_PROT_WRITE_INSERT:
  1697. *rxop = BG_OP_IN_CRC_OUT_NODIF;
  1698. *txop = BG_OP_IN_NODIF_OUT_CRC;
  1699. break;
  1700. case SCSI_PROT_READ_PASS:
  1701. case SCSI_PROT_WRITE_PASS:
  1702. *rxop = BG_OP_IN_CRC_OUT_CRC;
  1703. *txop = BG_OP_IN_CRC_OUT_CRC;
  1704. break;
  1705. case SCSI_PROT_READ_INSERT:
  1706. case SCSI_PROT_WRITE_STRIP:
  1707. *rxop = BG_OP_IN_NODIF_OUT_CRC;
  1708. *txop = BG_OP_IN_CRC_OUT_NODIF;
  1709. break;
  1710. case SCSI_PROT_NORMAL:
  1711. default:
  1712. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1713. "9075 BLKGRD: Bad op/guard:%d/CRC combination\n",
  1714. scsi_get_prot_op(sc));
  1715. ret = 1;
  1716. break;
  1717. }
  1718. }
  1719. return ret;
  1720. }
  1721. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1722. /**
  1723. * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with
  1724. * the specified SCSI command in order to force a guard tag error.
  1725. * @phba: The Hba for which this call is being executed.
  1726. * @sc: The SCSI command to examine
  1727. * @txopt: (out) BlockGuard operation for transmitted data
  1728. * @rxopt: (out) BlockGuard operation for received data
  1729. *
  1730. * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
  1731. *
  1732. **/
  1733. static int
  1734. lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1735. uint8_t *txop, uint8_t *rxop)
  1736. {
  1737. uint8_t ret = 0;
  1738. if (lpfc_cmd_guard_csum(sc)) {
  1739. switch (scsi_get_prot_op(sc)) {
  1740. case SCSI_PROT_READ_INSERT:
  1741. case SCSI_PROT_WRITE_STRIP:
  1742. *rxop = BG_OP_IN_NODIF_OUT_CRC;
  1743. *txop = BG_OP_IN_CRC_OUT_NODIF;
  1744. break;
  1745. case SCSI_PROT_READ_STRIP:
  1746. case SCSI_PROT_WRITE_INSERT:
  1747. *rxop = BG_OP_IN_CSUM_OUT_NODIF;
  1748. *txop = BG_OP_IN_NODIF_OUT_CSUM;
  1749. break;
  1750. case SCSI_PROT_READ_PASS:
  1751. case SCSI_PROT_WRITE_PASS:
  1752. *rxop = BG_OP_IN_CSUM_OUT_CRC;
  1753. *txop = BG_OP_IN_CRC_OUT_CSUM;
  1754. break;
  1755. case SCSI_PROT_NORMAL:
  1756. default:
  1757. break;
  1758. }
  1759. } else {
  1760. switch (scsi_get_prot_op(sc)) {
  1761. case SCSI_PROT_READ_STRIP:
  1762. case SCSI_PROT_WRITE_INSERT:
  1763. *rxop = BG_OP_IN_CSUM_OUT_NODIF;
  1764. *txop = BG_OP_IN_NODIF_OUT_CSUM;
  1765. break;
  1766. case SCSI_PROT_READ_PASS:
  1767. case SCSI_PROT_WRITE_PASS:
  1768. *rxop = BG_OP_IN_CSUM_OUT_CSUM;
  1769. *txop = BG_OP_IN_CSUM_OUT_CSUM;
  1770. break;
  1771. case SCSI_PROT_READ_INSERT:
  1772. case SCSI_PROT_WRITE_STRIP:
  1773. *rxop = BG_OP_IN_NODIF_OUT_CSUM;
  1774. *txop = BG_OP_IN_CSUM_OUT_NODIF;
  1775. break;
  1776. case SCSI_PROT_NORMAL:
  1777. default:
  1778. break;
  1779. }
  1780. }
  1781. return ret;
  1782. }
  1783. #endif
  1784. /**
  1785. * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data
  1786. * @phba: The Hba for which this call is being executed.
  1787. * @sc: pointer to scsi command we're working on
  1788. * @bpl: pointer to buffer list for protection groups
  1789. * @datacnt: number of segments of data that have been dma mapped
  1790. *
  1791. * This function sets up BPL buffer list for protection groups of
  1792. * type LPFC_PG_TYPE_NO_DIF
  1793. *
  1794. * This is usually used when the HBA is instructed to generate
  1795. * DIFs and insert them into data stream (or strip DIF from
  1796. * incoming data stream)
  1797. *
  1798. * The buffer list consists of just one protection group described
  1799. * below:
  1800. * +-------------------------+
  1801. * start of prot group --> | PDE_5 |
  1802. * +-------------------------+
  1803. * | PDE_6 |
  1804. * +-------------------------+
  1805. * | Data BDE |
  1806. * +-------------------------+
  1807. * |more Data BDE's ... (opt)|
  1808. * +-------------------------+
  1809. *
  1810. *
  1811. * Note: Data s/g buffers have been dma mapped
  1812. *
  1813. * Returns the number of BDEs added to the BPL.
  1814. **/
  1815. static int
  1816. lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1817. struct ulp_bde64 *bpl, int datasegcnt)
  1818. {
  1819. struct scatterlist *sgde = NULL; /* s/g data entry */
  1820. struct lpfc_pde5 *pde5 = NULL;
  1821. struct lpfc_pde6 *pde6 = NULL;
  1822. dma_addr_t physaddr;
  1823. int i = 0, num_bde = 0, status;
  1824. int datadir = sc->sc_data_direction;
  1825. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1826. uint32_t rc;
  1827. #endif
  1828. uint32_t checking = 1;
  1829. uint32_t reftag;
  1830. unsigned blksize;
  1831. uint8_t txop, rxop;
  1832. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  1833. if (status)
  1834. goto out;
  1835. /* extract some info from the scsi command for pde*/
  1836. blksize = lpfc_cmd_blksize(sc);
  1837. reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
  1838. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1839. rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
  1840. if (rc) {
  1841. if (rc & BG_ERR_SWAP)
  1842. lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
  1843. if (rc & BG_ERR_CHECK)
  1844. checking = 0;
  1845. }
  1846. #endif
  1847. /* setup PDE5 with what we have */
  1848. pde5 = (struct lpfc_pde5 *) bpl;
  1849. memset(pde5, 0, sizeof(struct lpfc_pde5));
  1850. bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
  1851. /* Endianness conversion if necessary for PDE5 */
  1852. pde5->word0 = cpu_to_le32(pde5->word0);
  1853. pde5->reftag = cpu_to_le32(reftag);
  1854. /* advance bpl and increment bde count */
  1855. num_bde++;
  1856. bpl++;
  1857. pde6 = (struct lpfc_pde6 *) bpl;
  1858. /* setup PDE6 with the rest of the info */
  1859. memset(pde6, 0, sizeof(struct lpfc_pde6));
  1860. bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
  1861. bf_set(pde6_optx, pde6, txop);
  1862. bf_set(pde6_oprx, pde6, rxop);
  1863. /*
  1864. * We only need to check the data on READs, for WRITEs
  1865. * protection data is automatically generated, not checked.
  1866. */
  1867. if (datadir == DMA_FROM_DEVICE) {
  1868. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
  1869. bf_set(pde6_ce, pde6, checking);
  1870. else
  1871. bf_set(pde6_ce, pde6, 0);
  1872. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
  1873. bf_set(pde6_re, pde6, checking);
  1874. else
  1875. bf_set(pde6_re, pde6, 0);
  1876. }
  1877. bf_set(pde6_ai, pde6, 1);
  1878. bf_set(pde6_ae, pde6, 0);
  1879. bf_set(pde6_apptagval, pde6, 0);
  1880. /* Endianness conversion if necessary for PDE6 */
  1881. pde6->word0 = cpu_to_le32(pde6->word0);
  1882. pde6->word1 = cpu_to_le32(pde6->word1);
  1883. pde6->word2 = cpu_to_le32(pde6->word2);
  1884. /* advance bpl and increment bde count */
  1885. num_bde++;
  1886. bpl++;
  1887. /* assumption: caller has already run dma_map_sg on command data */
  1888. scsi_for_each_sg(sc, sgde, datasegcnt, i) {
  1889. physaddr = sg_dma_address(sgde);
  1890. bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1891. bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1892. bpl->tus.f.bdeSize = sg_dma_len(sgde);
  1893. if (datadir == DMA_TO_DEVICE)
  1894. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1895. else
  1896. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  1897. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1898. bpl++;
  1899. num_bde++;
  1900. }
  1901. out:
  1902. return num_bde;
  1903. }
  1904. /**
  1905. * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data
  1906. * @phba: The Hba for which this call is being executed.
  1907. * @sc: pointer to scsi command we're working on
  1908. * @bpl: pointer to buffer list for protection groups
  1909. * @datacnt: number of segments of data that have been dma mapped
  1910. * @protcnt: number of segment of protection data that have been dma mapped
  1911. *
  1912. * This function sets up BPL buffer list for protection groups of
  1913. * type LPFC_PG_TYPE_DIF
  1914. *
  1915. * This is usually used when DIFs are in their own buffers,
  1916. * separate from the data. The HBA can then by instructed
  1917. * to place the DIFs in the outgoing stream. For read operations,
  1918. * The HBA could extract the DIFs and place it in DIF buffers.
  1919. *
  1920. * The buffer list for this type consists of one or more of the
  1921. * protection groups described below:
  1922. * +-------------------------+
  1923. * start of first prot group --> | PDE_5 |
  1924. * +-------------------------+
  1925. * | PDE_6 |
  1926. * +-------------------------+
  1927. * | PDE_7 (Prot BDE) |
  1928. * +-------------------------+
  1929. * | Data BDE |
  1930. * +-------------------------+
  1931. * |more Data BDE's ... (opt)|
  1932. * +-------------------------+
  1933. * start of new prot group --> | PDE_5 |
  1934. * +-------------------------+
  1935. * | ... |
  1936. * +-------------------------+
  1937. *
  1938. * Note: It is assumed that both data and protection s/g buffers have been
  1939. * mapped for DMA
  1940. *
  1941. * Returns the number of BDEs added to the BPL.
  1942. **/
  1943. static int
  1944. lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1945. struct ulp_bde64 *bpl, int datacnt, int protcnt)
  1946. {
  1947. struct scatterlist *sgde = NULL; /* s/g data entry */
  1948. struct scatterlist *sgpe = NULL; /* s/g prot entry */
  1949. struct lpfc_pde5 *pde5 = NULL;
  1950. struct lpfc_pde6 *pde6 = NULL;
  1951. struct lpfc_pde7 *pde7 = NULL;
  1952. dma_addr_t dataphysaddr, protphysaddr;
  1953. unsigned short curr_data = 0, curr_prot = 0;
  1954. unsigned int split_offset;
  1955. unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
  1956. unsigned int protgrp_blks, protgrp_bytes;
  1957. unsigned int remainder, subtotal;
  1958. int status;
  1959. int datadir = sc->sc_data_direction;
  1960. unsigned char pgdone = 0, alldone = 0;
  1961. unsigned blksize;
  1962. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1963. uint32_t rc;
  1964. #endif
  1965. uint32_t checking = 1;
  1966. uint32_t reftag;
  1967. uint8_t txop, rxop;
  1968. int num_bde = 0;
  1969. sgpe = scsi_prot_sglist(sc);
  1970. sgde = scsi_sglist(sc);
  1971. if (!sgpe || !sgde) {
  1972. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  1973. "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
  1974. sgpe, sgde);
  1975. return 0;
  1976. }
  1977. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  1978. if (status)
  1979. goto out;
  1980. /* extract some info from the scsi command */
  1981. blksize = lpfc_cmd_blksize(sc);
  1982. reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
  1983. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1984. rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
  1985. if (rc) {
  1986. if (rc & BG_ERR_SWAP)
  1987. lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
  1988. if (rc & BG_ERR_CHECK)
  1989. checking = 0;
  1990. }
  1991. #endif
  1992. split_offset = 0;
  1993. do {
  1994. /* Check to see if we ran out of space */
  1995. if (num_bde >= (phba->cfg_total_seg_cnt - 2))
  1996. return num_bde + 3;
  1997. /* setup PDE5 with what we have */
  1998. pde5 = (struct lpfc_pde5 *) bpl;
  1999. memset(pde5, 0, sizeof(struct lpfc_pde5));
  2000. bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
  2001. /* Endianness conversion if necessary for PDE5 */
  2002. pde5->word0 = cpu_to_le32(pde5->word0);
  2003. pde5->reftag = cpu_to_le32(reftag);
  2004. /* advance bpl and increment bde count */
  2005. num_bde++;
  2006. bpl++;
  2007. pde6 = (struct lpfc_pde6 *) bpl;
  2008. /* setup PDE6 with the rest of the info */
  2009. memset(pde6, 0, sizeof(struct lpfc_pde6));
  2010. bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
  2011. bf_set(pde6_optx, pde6, txop);
  2012. bf_set(pde6_oprx, pde6, rxop);
  2013. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
  2014. bf_set(pde6_ce, pde6, checking);
  2015. else
  2016. bf_set(pde6_ce, pde6, 0);
  2017. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
  2018. bf_set(pde6_re, pde6, checking);
  2019. else
  2020. bf_set(pde6_re, pde6, 0);
  2021. bf_set(pde6_ai, pde6, 1);
  2022. bf_set(pde6_ae, pde6, 0);
  2023. bf_set(pde6_apptagval, pde6, 0);
  2024. /* Endianness conversion if necessary for PDE6 */
  2025. pde6->word0 = cpu_to_le32(pde6->word0);
  2026. pde6->word1 = cpu_to_le32(pde6->word1);
  2027. pde6->word2 = cpu_to_le32(pde6->word2);
  2028. /* advance bpl and increment bde count */
  2029. num_bde++;
  2030. bpl++;
  2031. /* setup the first BDE that points to protection buffer */
  2032. protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
  2033. protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
  2034. /* must be integer multiple of the DIF block length */
  2035. BUG_ON(protgroup_len % 8);
  2036. pde7 = (struct lpfc_pde7 *) bpl;
  2037. memset(pde7, 0, sizeof(struct lpfc_pde7));
  2038. bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
  2039. pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr));
  2040. pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr));
  2041. protgrp_blks = protgroup_len / 8;
  2042. protgrp_bytes = protgrp_blks * blksize;
  2043. /* check if this pde is crossing the 4K boundary; if so split */
  2044. if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
  2045. protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
  2046. protgroup_offset += protgroup_remainder;
  2047. protgrp_blks = protgroup_remainder / 8;
  2048. protgrp_bytes = protgrp_blks * blksize;
  2049. } else {
  2050. protgroup_offset = 0;
  2051. curr_prot++;
  2052. }
  2053. num_bde++;
  2054. /* setup BDE's for data blocks associated with DIF data */
  2055. pgdone = 0;
  2056. subtotal = 0; /* total bytes processed for current prot grp */
  2057. while (!pgdone) {
  2058. /* Check to see if we ran out of space */
  2059. if (num_bde >= phba->cfg_total_seg_cnt)
  2060. return num_bde + 1;
  2061. if (!sgde) {
  2062. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  2063. "9065 BLKGRD:%s Invalid data segment\n",
  2064. __func__);
  2065. return 0;
  2066. }
  2067. bpl++;
  2068. dataphysaddr = sg_dma_address(sgde) + split_offset;
  2069. bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
  2070. bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
  2071. remainder = sg_dma_len(sgde) - split_offset;
  2072. if ((subtotal + remainder) <= protgrp_bytes) {
  2073. /* we can use this whole buffer */
  2074. bpl->tus.f.bdeSize = remainder;
  2075. split_offset = 0;
  2076. if ((subtotal + remainder) == protgrp_bytes)
  2077. pgdone = 1;
  2078. } else {
  2079. /* must split this buffer with next prot grp */
  2080. bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
  2081. split_offset += bpl->tus.f.bdeSize;
  2082. }
  2083. subtotal += bpl->tus.f.bdeSize;
  2084. if (datadir == DMA_TO_DEVICE)
  2085. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  2086. else
  2087. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  2088. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  2089. num_bde++;
  2090. curr_data++;
  2091. if (split_offset)
  2092. break;
  2093. /* Move to the next s/g segment if possible */
  2094. sgde = sg_next(sgde);
  2095. }
  2096. if (protgroup_offset) {
  2097. /* update the reference tag */
  2098. reftag += protgrp_blks;
  2099. bpl++;
  2100. continue;
  2101. }
  2102. /* are we done ? */
  2103. if (curr_prot == protcnt) {
  2104. alldone = 1;
  2105. } else if (curr_prot < protcnt) {
  2106. /* advance to next prot buffer */
  2107. sgpe = sg_next(sgpe);
  2108. bpl++;
  2109. /* update the reference tag */
  2110. reftag += protgrp_blks;
  2111. } else {
  2112. /* if we're here, we have a bug */
  2113. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  2114. "9054 BLKGRD: bug in %s\n", __func__);
  2115. }
  2116. } while (!alldone);
  2117. out:
  2118. return num_bde;
  2119. }
  2120. /**
  2121. * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data
  2122. * @phba: The Hba for which this call is being executed.
  2123. * @sc: pointer to scsi command we're working on
  2124. * @sgl: pointer to buffer list for protection groups
  2125. * @datacnt: number of segments of data that have been dma mapped
  2126. *
  2127. * This function sets up SGL buffer list for protection groups of
  2128. * type LPFC_PG_TYPE_NO_DIF
  2129. *
  2130. * This is usually used when the HBA is instructed to generate
  2131. * DIFs and insert them into data stream (or strip DIF from
  2132. * incoming data stream)
  2133. *
  2134. * The buffer list consists of just one protection group described
  2135. * below:
  2136. * +-------------------------+
  2137. * start of prot group --> | DI_SEED |
  2138. * +-------------------------+
  2139. * | Data SGE |
  2140. * +-------------------------+
  2141. * |more Data SGE's ... (opt)|
  2142. * +-------------------------+
  2143. *
  2144. *
  2145. * Note: Data s/g buffers have been dma mapped
  2146. *
  2147. * Returns the number of SGEs added to the SGL.
  2148. **/
  2149. static int
  2150. lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  2151. struct sli4_sge *sgl, int datasegcnt)
  2152. {
  2153. struct scatterlist *sgde = NULL; /* s/g data entry */
  2154. struct sli4_sge_diseed *diseed = NULL;
  2155. dma_addr_t physaddr;
  2156. int i = 0, num_sge = 0, status;
  2157. uint32_t reftag;
  2158. unsigned blksize;
  2159. uint8_t txop, rxop;
  2160. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2161. uint32_t rc;
  2162. #endif
  2163. uint32_t checking = 1;
  2164. uint32_t dma_len;
  2165. uint32_t dma_offset = 0;
  2166. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  2167. if (status)
  2168. goto out;
  2169. /* extract some info from the scsi command for pde*/
  2170. blksize = lpfc_cmd_blksize(sc);
  2171. reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
  2172. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2173. rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
  2174. if (rc) {
  2175. if (rc & BG_ERR_SWAP)
  2176. lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
  2177. if (rc & BG_ERR_CHECK)
  2178. checking = 0;
  2179. }
  2180. #endif
  2181. /* setup DISEED with what we have */
  2182. diseed = (struct sli4_sge_diseed *) sgl;
  2183. memset(diseed, 0, sizeof(struct sli4_sge_diseed));
  2184. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
  2185. /* Endianness conversion if necessary */
  2186. diseed->ref_tag = cpu_to_le32(reftag);
  2187. diseed->ref_tag_tran = diseed->ref_tag;
  2188. /*
  2189. * We only need to check the data on READs, for WRITEs
  2190. * protection data is automatically generated, not checked.
  2191. */
  2192. if (sc->sc_data_direction == DMA_FROM_DEVICE) {
  2193. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD))
  2194. bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
  2195. else
  2196. bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
  2197. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
  2198. bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
  2199. else
  2200. bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
  2201. }
  2202. /* setup DISEED with the rest of the info */
  2203. bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
  2204. bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
  2205. bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
  2206. bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
  2207. /* Endianness conversion if necessary for DISEED */
  2208. diseed->word2 = cpu_to_le32(diseed->word2);
  2209. diseed->word3 = cpu_to_le32(diseed->word3);
  2210. /* advance bpl and increment sge count */
  2211. num_sge++;
  2212. sgl++;
  2213. /* assumption: caller has already run dma_map_sg on command data */
  2214. scsi_for_each_sg(sc, sgde, datasegcnt, i) {
  2215. physaddr = sg_dma_address(sgde);
  2216. dma_len = sg_dma_len(sgde);
  2217. sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
  2218. sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
  2219. if ((i + 1) == datasegcnt)
  2220. bf_set(lpfc_sli4_sge_last, sgl, 1);
  2221. else
  2222. bf_set(lpfc_sli4_sge_last, sgl, 0);
  2223. bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
  2224. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
  2225. sgl->sge_len = cpu_to_le32(dma_len);
  2226. dma_offset += dma_len;
  2227. sgl++;
  2228. num_sge++;
  2229. }
  2230. out:
  2231. return num_sge;
  2232. }
  2233. /**
  2234. * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data
  2235. * @phba: The Hba for which this call is being executed.
  2236. * @sc: pointer to scsi command we're working on
  2237. * @sgl: pointer to buffer list for protection groups
  2238. * @datacnt: number of segments of data that have been dma mapped
  2239. * @protcnt: number of segment of protection data that have been dma mapped
  2240. *
  2241. * This function sets up SGL buffer list for protection groups of
  2242. * type LPFC_PG_TYPE_DIF
  2243. *
  2244. * This is usually used when DIFs are in their own buffers,
  2245. * separate from the data. The HBA can then by instructed
  2246. * to place the DIFs in the outgoing stream. For read operations,
  2247. * The HBA could extract the DIFs and place it in DIF buffers.
  2248. *
  2249. * The buffer list for this type consists of one or more of the
  2250. * protection groups described below:
  2251. * +-------------------------+
  2252. * start of first prot group --> | DISEED |
  2253. * +-------------------------+
  2254. * | DIF (Prot SGE) |
  2255. * +-------------------------+
  2256. * | Data SGE |
  2257. * +-------------------------+
  2258. * |more Data SGE's ... (opt)|
  2259. * +-------------------------+
  2260. * start of new prot group --> | DISEED |
  2261. * +-------------------------+
  2262. * | ... |
  2263. * +-------------------------+
  2264. *
  2265. * Note: It is assumed that both data and protection s/g buffers have been
  2266. * mapped for DMA
  2267. *
  2268. * Returns the number of SGEs added to the SGL.
  2269. **/
  2270. static int
  2271. lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  2272. struct sli4_sge *sgl, int datacnt, int protcnt)
  2273. {
  2274. struct scatterlist *sgde = NULL; /* s/g data entry */
  2275. struct scatterlist *sgpe = NULL; /* s/g prot entry */
  2276. struct sli4_sge_diseed *diseed = NULL;
  2277. dma_addr_t dataphysaddr, protphysaddr;
  2278. unsigned short curr_data = 0, curr_prot = 0;
  2279. unsigned int split_offset;
  2280. unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
  2281. unsigned int protgrp_blks, protgrp_bytes;
  2282. unsigned int remainder, subtotal;
  2283. int status;
  2284. unsigned char pgdone = 0, alldone = 0;
  2285. unsigned blksize;
  2286. uint32_t reftag;
  2287. uint8_t txop, rxop;
  2288. uint32_t dma_len;
  2289. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2290. uint32_t rc;
  2291. #endif
  2292. uint32_t checking = 1;
  2293. uint32_t dma_offset = 0;
  2294. int num_sge = 0;
  2295. sgpe = scsi_prot_sglist(sc);
  2296. sgde = scsi_sglist(sc);
  2297. if (!sgpe || !sgde) {
  2298. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  2299. "9082 Invalid s/g entry: data=0x%p prot=0x%p\n",
  2300. sgpe, sgde);
  2301. return 0;
  2302. }
  2303. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  2304. if (status)
  2305. goto out;
  2306. /* extract some info from the scsi command */
  2307. blksize = lpfc_cmd_blksize(sc);
  2308. reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
  2309. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2310. rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
  2311. if (rc) {
  2312. if (rc & BG_ERR_SWAP)
  2313. lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
  2314. if (rc & BG_ERR_CHECK)
  2315. checking = 0;
  2316. }
  2317. #endif
  2318. split_offset = 0;
  2319. do {
  2320. /* Check to see if we ran out of space */
  2321. if (num_sge >= (phba->cfg_total_seg_cnt - 2))
  2322. return num_sge + 3;
  2323. /* setup DISEED with what we have */
  2324. diseed = (struct sli4_sge_diseed *) sgl;
  2325. memset(diseed, 0, sizeof(struct sli4_sge_diseed));
  2326. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED);
  2327. /* Endianness conversion if necessary */
  2328. diseed->ref_tag = cpu_to_le32(reftag);
  2329. diseed->ref_tag_tran = diseed->ref_tag;
  2330. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) {
  2331. bf_set(lpfc_sli4_sge_dif_ce, diseed, checking);
  2332. } else {
  2333. bf_set(lpfc_sli4_sge_dif_ce, diseed, 0);
  2334. /*
  2335. * When in this mode, the hardware will replace
  2336. * the guard tag from the host with a
  2337. * newly generated good CRC for the wire.
  2338. * Switch to raw mode here to avoid this
  2339. * behavior. What the host sends gets put on the wire.
  2340. */
  2341. if (txop == BG_OP_IN_CRC_OUT_CRC) {
  2342. txop = BG_OP_RAW_MODE;
  2343. rxop = BG_OP_RAW_MODE;
  2344. }
  2345. }
  2346. if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF))
  2347. bf_set(lpfc_sli4_sge_dif_re, diseed, checking);
  2348. else
  2349. bf_set(lpfc_sli4_sge_dif_re, diseed, 0);
  2350. /* setup DISEED with the rest of the info */
  2351. bf_set(lpfc_sli4_sge_dif_optx, diseed, txop);
  2352. bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop);
  2353. bf_set(lpfc_sli4_sge_dif_ai, diseed, 1);
  2354. bf_set(lpfc_sli4_sge_dif_me, diseed, 0);
  2355. /* Endianness conversion if necessary for DISEED */
  2356. diseed->word2 = cpu_to_le32(diseed->word2);
  2357. diseed->word3 = cpu_to_le32(diseed->word3);
  2358. /* advance sgl and increment bde count */
  2359. num_sge++;
  2360. sgl++;
  2361. /* setup the first BDE that points to protection buffer */
  2362. protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
  2363. protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
  2364. /* must be integer multiple of the DIF block length */
  2365. BUG_ON(protgroup_len % 8);
  2366. /* Now setup DIF SGE */
  2367. sgl->word2 = 0;
  2368. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF);
  2369. sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr));
  2370. sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr));
  2371. sgl->word2 = cpu_to_le32(sgl->word2);
  2372. protgrp_blks = protgroup_len / 8;
  2373. protgrp_bytes = protgrp_blks * blksize;
  2374. /* check if DIF SGE is crossing the 4K boundary; if so split */
  2375. if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) {
  2376. protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff);
  2377. protgroup_offset += protgroup_remainder;
  2378. protgrp_blks = protgroup_remainder / 8;
  2379. protgrp_bytes = protgrp_blks * blksize;
  2380. } else {
  2381. protgroup_offset = 0;
  2382. curr_prot++;
  2383. }
  2384. num_sge++;
  2385. /* setup SGE's for data blocks associated with DIF data */
  2386. pgdone = 0;
  2387. subtotal = 0; /* total bytes processed for current prot grp */
  2388. while (!pgdone) {
  2389. /* Check to see if we ran out of space */
  2390. if (num_sge >= phba->cfg_total_seg_cnt)
  2391. return num_sge + 1;
  2392. if (!sgde) {
  2393. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  2394. "9086 BLKGRD:%s Invalid data segment\n",
  2395. __func__);
  2396. return 0;
  2397. }
  2398. sgl++;
  2399. dataphysaddr = sg_dma_address(sgde) + split_offset;
  2400. remainder = sg_dma_len(sgde) - split_offset;
  2401. if ((subtotal + remainder) <= protgrp_bytes) {
  2402. /* we can use this whole buffer */
  2403. dma_len = remainder;
  2404. split_offset = 0;
  2405. if ((subtotal + remainder) == protgrp_bytes)
  2406. pgdone = 1;
  2407. } else {
  2408. /* must split this buffer with next prot grp */
  2409. dma_len = protgrp_bytes - subtotal;
  2410. split_offset += dma_len;
  2411. }
  2412. subtotal += dma_len;
  2413. sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr));
  2414. sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr));
  2415. bf_set(lpfc_sli4_sge_last, sgl, 0);
  2416. bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
  2417. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
  2418. sgl->sge_len = cpu_to_le32(dma_len);
  2419. dma_offset += dma_len;
  2420. num_sge++;
  2421. curr_data++;
  2422. if (split_offset)
  2423. break;
  2424. /* Move to the next s/g segment if possible */
  2425. sgde = sg_next(sgde);
  2426. }
  2427. if (protgroup_offset) {
  2428. /* update the reference tag */
  2429. reftag += protgrp_blks;
  2430. sgl++;
  2431. continue;
  2432. }
  2433. /* are we done ? */
  2434. if (curr_prot == protcnt) {
  2435. bf_set(lpfc_sli4_sge_last, sgl, 1);
  2436. alldone = 1;
  2437. } else if (curr_prot < protcnt) {
  2438. /* advance to next prot buffer */
  2439. sgpe = sg_next(sgpe);
  2440. sgl++;
  2441. /* update the reference tag */
  2442. reftag += protgrp_blks;
  2443. } else {
  2444. /* if we're here, we have a bug */
  2445. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  2446. "9085 BLKGRD: bug in %s\n", __func__);
  2447. }
  2448. } while (!alldone);
  2449. out:
  2450. return num_sge;
  2451. }
  2452. /**
  2453. * lpfc_prot_group_type - Get prtotection group type of SCSI command
  2454. * @phba: The Hba for which this call is being executed.
  2455. * @sc: pointer to scsi command we're working on
  2456. *
  2457. * Given a SCSI command that supports DIF, determine composition of protection
  2458. * groups involved in setting up buffer lists
  2459. *
  2460. * Returns: Protection group type (with or without DIF)
  2461. *
  2462. **/
  2463. static int
  2464. lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
  2465. {
  2466. int ret = LPFC_PG_TYPE_INVALID;
  2467. unsigned char op = scsi_get_prot_op(sc);
  2468. switch (op) {
  2469. case SCSI_PROT_READ_STRIP:
  2470. case SCSI_PROT_WRITE_INSERT:
  2471. ret = LPFC_PG_TYPE_NO_DIF;
  2472. break;
  2473. case SCSI_PROT_READ_INSERT:
  2474. case SCSI_PROT_WRITE_STRIP:
  2475. case SCSI_PROT_READ_PASS:
  2476. case SCSI_PROT_WRITE_PASS:
  2477. ret = LPFC_PG_TYPE_DIF_BUF;
  2478. break;
  2479. default:
  2480. if (phba)
  2481. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  2482. "9021 Unsupported protection op:%d\n",
  2483. op);
  2484. break;
  2485. }
  2486. return ret;
  2487. }
  2488. /**
  2489. * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard
  2490. * @phba: The Hba for which this call is being executed.
  2491. * @lpfc_cmd: The scsi buffer which is going to be adjusted.
  2492. *
  2493. * Adjust the data length to account for how much data
  2494. * is actually on the wire.
  2495. *
  2496. * returns the adjusted data length
  2497. **/
  2498. static int
  2499. lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba,
  2500. struct lpfc_scsi_buf *lpfc_cmd)
  2501. {
  2502. struct scsi_cmnd *sc = lpfc_cmd->pCmd;
  2503. int fcpdl;
  2504. fcpdl = scsi_bufflen(sc);
  2505. /* Check if there is protection data on the wire */
  2506. if (sc->sc_data_direction == DMA_FROM_DEVICE) {
  2507. /* Read check for protection data */
  2508. if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT)
  2509. return fcpdl;
  2510. } else {
  2511. /* Write check for protection data */
  2512. if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP)
  2513. return fcpdl;
  2514. }
  2515. /*
  2516. * If we are in DIF Type 1 mode every data block has a 8 byte
  2517. * DIF (trailer) attached to it. Must ajust FCP data length
  2518. * to account for the protection data.
  2519. */
  2520. fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8;
  2521. return fcpdl;
  2522. }
  2523. /**
  2524. * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
  2525. * @phba: The Hba for which this call is being executed.
  2526. * @lpfc_cmd: The scsi buffer which is going to be prep'ed.
  2527. *
  2528. * This is the protection/DIF aware version of
  2529. * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
  2530. * two functions eventually, but for now, it's here
  2531. **/
  2532. static int
  2533. lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba,
  2534. struct lpfc_scsi_buf *lpfc_cmd)
  2535. {
  2536. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  2537. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  2538. struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
  2539. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  2540. uint32_t num_bde = 0;
  2541. int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
  2542. int prot_group_type = 0;
  2543. int fcpdl;
  2544. /*
  2545. * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
  2546. * fcp_rsp regions to the first data bde entry
  2547. */
  2548. bpl += 2;
  2549. if (scsi_sg_count(scsi_cmnd)) {
  2550. /*
  2551. * The driver stores the segment count returned from pci_map_sg
  2552. * because this a count of dma-mappings used to map the use_sg
  2553. * pages. They are not guaranteed to be the same for those
  2554. * architectures that implement an IOMMU.
  2555. */
  2556. datasegcnt = dma_map_sg(&phba->pcidev->dev,
  2557. scsi_sglist(scsi_cmnd),
  2558. scsi_sg_count(scsi_cmnd), datadir);
  2559. if (unlikely(!datasegcnt))
  2560. return 1;
  2561. lpfc_cmd->seg_cnt = datasegcnt;
  2562. /* First check if data segment count from SCSI Layer is good */
  2563. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
  2564. goto err;
  2565. prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
  2566. switch (prot_group_type) {
  2567. case LPFC_PG_TYPE_NO_DIF:
  2568. /* Here we need to add a PDE5 and PDE6 to the count */
  2569. if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt)
  2570. goto err;
  2571. num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
  2572. datasegcnt);
  2573. /* we should have 2 or more entries in buffer list */
  2574. if (num_bde < 2)
  2575. goto err;
  2576. break;
  2577. case LPFC_PG_TYPE_DIF_BUF:
  2578. /*
  2579. * This type indicates that protection buffers are
  2580. * passed to the driver, so that needs to be prepared
  2581. * for DMA
  2582. */
  2583. protsegcnt = dma_map_sg(&phba->pcidev->dev,
  2584. scsi_prot_sglist(scsi_cmnd),
  2585. scsi_prot_sg_count(scsi_cmnd), datadir);
  2586. if (unlikely(!protsegcnt)) {
  2587. scsi_dma_unmap(scsi_cmnd);
  2588. return 1;
  2589. }
  2590. lpfc_cmd->prot_seg_cnt = protsegcnt;
  2591. /*
  2592. * There is a minimun of 4 BPLs used for every
  2593. * protection data segment.
  2594. */
  2595. if ((lpfc_cmd->prot_seg_cnt * 4) >
  2596. (phba->cfg_total_seg_cnt - 2))
  2597. goto err;
  2598. num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
  2599. datasegcnt, protsegcnt);
  2600. /* we should have 3 or more entries in buffer list */
  2601. if ((num_bde < 3) ||
  2602. (num_bde > phba->cfg_total_seg_cnt))
  2603. goto err;
  2604. break;
  2605. case LPFC_PG_TYPE_INVALID:
  2606. default:
  2607. scsi_dma_unmap(scsi_cmnd);
  2608. lpfc_cmd->seg_cnt = 0;
  2609. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  2610. "9022 Unexpected protection group %i\n",
  2611. prot_group_type);
  2612. return 1;
  2613. }
  2614. }
  2615. /*
  2616. * Finish initializing those IOCB fields that are dependent on the
  2617. * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
  2618. * reinitialized since all iocb memory resources are used many times
  2619. * for transmit, receive, and continuation bpl's.
  2620. */
  2621. iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  2622. iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
  2623. iocb_cmd->ulpBdeCount = 1;
  2624. iocb_cmd->ulpLe = 1;
  2625. fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
  2626. fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
  2627. /*
  2628. * Due to difference in data length between DIF/non-DIF paths,
  2629. * we need to set word 4 of IOCB here
  2630. */
  2631. iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
  2632. return 0;
  2633. err:
  2634. if (lpfc_cmd->seg_cnt)
  2635. scsi_dma_unmap(scsi_cmnd);
  2636. if (lpfc_cmd->prot_seg_cnt)
  2637. dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
  2638. scsi_prot_sg_count(scsi_cmnd),
  2639. scsi_cmnd->sc_data_direction);
  2640. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  2641. "9023 Cannot setup S/G List for HBA"
  2642. "IO segs %d/%d BPL %d SCSI %d: %d %d\n",
  2643. lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
  2644. phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
  2645. prot_group_type, num_bde);
  2646. lpfc_cmd->seg_cnt = 0;
  2647. lpfc_cmd->prot_seg_cnt = 0;
  2648. return 1;
  2649. }
  2650. /*
  2651. * This function calcuates the T10 DIF guard tag
  2652. * on the specified data using a CRC algorithmn
  2653. * using crc_t10dif.
  2654. */
  2655. static uint16_t
  2656. lpfc_bg_crc(uint8_t *data, int count)
  2657. {
  2658. uint16_t crc = 0;
  2659. uint16_t x;
  2660. crc = crc_t10dif(data, count);
  2661. x = cpu_to_be16(crc);
  2662. return x;
  2663. }
  2664. /*
  2665. * This function calcuates the T10 DIF guard tag
  2666. * on the specified data using a CSUM algorithmn
  2667. * using ip_compute_csum.
  2668. */
  2669. static uint16_t
  2670. lpfc_bg_csum(uint8_t *data, int count)
  2671. {
  2672. uint16_t ret;
  2673. ret = ip_compute_csum(data, count);
  2674. return ret;
  2675. }
  2676. /*
  2677. * This function examines the protection data to try to determine
  2678. * what type of T10-DIF error occurred.
  2679. */
  2680. static void
  2681. lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  2682. {
  2683. struct scatterlist *sgpe; /* s/g prot entry */
  2684. struct scatterlist *sgde; /* s/g data entry */
  2685. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  2686. struct scsi_dif_tuple *src = NULL;
  2687. uint8_t *data_src = NULL;
  2688. uint16_t guard_tag, guard_type;
  2689. uint16_t start_app_tag, app_tag;
  2690. uint32_t start_ref_tag, ref_tag;
  2691. int prot, protsegcnt;
  2692. int err_type, len, data_len;
  2693. int chk_ref, chk_app, chk_guard;
  2694. uint16_t sum;
  2695. unsigned blksize;
  2696. err_type = BGS_GUARD_ERR_MASK;
  2697. sum = 0;
  2698. guard_tag = 0;
  2699. /* First check to see if there is protection data to examine */
  2700. prot = scsi_get_prot_op(cmd);
  2701. if ((prot == SCSI_PROT_READ_STRIP) ||
  2702. (prot == SCSI_PROT_WRITE_INSERT) ||
  2703. (prot == SCSI_PROT_NORMAL))
  2704. goto out;
  2705. /* Currently the driver just supports ref_tag and guard_tag checking */
  2706. chk_ref = 1;
  2707. chk_app = 0;
  2708. chk_guard = 0;
  2709. /* Setup a ptr to the protection data provided by the SCSI host */
  2710. sgpe = scsi_prot_sglist(cmd);
  2711. protsegcnt = lpfc_cmd->prot_seg_cnt;
  2712. if (sgpe && protsegcnt) {
  2713. /*
  2714. * We will only try to verify guard tag if the segment
  2715. * data length is a multiple of the blksize.
  2716. */
  2717. sgde = scsi_sglist(cmd);
  2718. blksize = lpfc_cmd_blksize(cmd);
  2719. data_src = (uint8_t *)sg_virt(sgde);
  2720. data_len = sgde->length;
  2721. if ((data_len & (blksize - 1)) == 0)
  2722. chk_guard = 1;
  2723. guard_type = scsi_host_get_guard(cmd->device->host);
  2724. src = (struct scsi_dif_tuple *)sg_virt(sgpe);
  2725. start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */
  2726. start_app_tag = src->app_tag;
  2727. len = sgpe->length;
  2728. while (src && protsegcnt) {
  2729. while (len) {
  2730. /*
  2731. * First check to see if a protection data
  2732. * check is valid
  2733. */
  2734. if ((src->ref_tag == 0xffffffff) ||
  2735. (src->app_tag == 0xffff)) {
  2736. start_ref_tag++;
  2737. goto skipit;
  2738. }
  2739. /* First Guard Tag checking */
  2740. if (chk_guard) {
  2741. guard_tag = src->guard_tag;
  2742. if (lpfc_cmd_guard_csum(cmd))
  2743. sum = lpfc_bg_csum(data_src,
  2744. blksize);
  2745. else
  2746. sum = lpfc_bg_crc(data_src,
  2747. blksize);
  2748. if ((guard_tag != sum)) {
  2749. err_type = BGS_GUARD_ERR_MASK;
  2750. goto out;
  2751. }
  2752. }
  2753. /* Reference Tag checking */
  2754. ref_tag = be32_to_cpu(src->ref_tag);
  2755. if (chk_ref && (ref_tag != start_ref_tag)) {
  2756. err_type = BGS_REFTAG_ERR_MASK;
  2757. goto out;
  2758. }
  2759. start_ref_tag++;
  2760. /* App Tag checking */
  2761. app_tag = src->app_tag;
  2762. if (chk_app && (app_tag != start_app_tag)) {
  2763. err_type = BGS_APPTAG_ERR_MASK;
  2764. goto out;
  2765. }
  2766. skipit:
  2767. len -= sizeof(struct scsi_dif_tuple);
  2768. if (len < 0)
  2769. len = 0;
  2770. src++;
  2771. data_src += blksize;
  2772. data_len -= blksize;
  2773. /*
  2774. * Are we at the end of the Data segment?
  2775. * The data segment is only used for Guard
  2776. * tag checking.
  2777. */
  2778. if (chk_guard && (data_len == 0)) {
  2779. chk_guard = 0;
  2780. sgde = sg_next(sgde);
  2781. if (!sgde)
  2782. goto out;
  2783. data_src = (uint8_t *)sg_virt(sgde);
  2784. data_len = sgde->length;
  2785. if ((data_len & (blksize - 1)) == 0)
  2786. chk_guard = 1;
  2787. }
  2788. }
  2789. /* Goto the next Protection data segment */
  2790. sgpe = sg_next(sgpe);
  2791. if (sgpe) {
  2792. src = (struct scsi_dif_tuple *)sg_virt(sgpe);
  2793. len = sgpe->length;
  2794. } else {
  2795. src = NULL;
  2796. }
  2797. protsegcnt--;
  2798. }
  2799. }
  2800. out:
  2801. if (err_type == BGS_GUARD_ERR_MASK) {
  2802. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2803. 0x10, 0x1);
  2804. cmd->result = DRIVER_SENSE << 24
  2805. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2806. phba->bg_guard_err_cnt++;
  2807. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2808. "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
  2809. (unsigned long)scsi_get_lba(cmd),
  2810. sum, guard_tag);
  2811. } else if (err_type == BGS_REFTAG_ERR_MASK) {
  2812. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2813. 0x10, 0x3);
  2814. cmd->result = DRIVER_SENSE << 24
  2815. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2816. phba->bg_reftag_err_cnt++;
  2817. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2818. "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n",
  2819. (unsigned long)scsi_get_lba(cmd),
  2820. ref_tag, start_ref_tag);
  2821. } else if (err_type == BGS_APPTAG_ERR_MASK) {
  2822. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2823. 0x10, 0x2);
  2824. cmd->result = DRIVER_SENSE << 24
  2825. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2826. phba->bg_apptag_err_cnt++;
  2827. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2828. "9041 BLKGRD: LBA %lx app_tag error %x != %x\n",
  2829. (unsigned long)scsi_get_lba(cmd),
  2830. app_tag, start_app_tag);
  2831. }
  2832. }
  2833. /*
  2834. * This function checks for BlockGuard errors detected by
  2835. * the HBA. In case of errors, the ASC/ASCQ fields in the
  2836. * sense buffer will be set accordingly, paired with
  2837. * ILLEGAL_REQUEST to signal to the kernel that the HBA
  2838. * detected corruption.
  2839. *
  2840. * Returns:
  2841. * 0 - No error found
  2842. * 1 - BlockGuard error found
  2843. * -1 - Internal error (bad profile, ...etc)
  2844. */
  2845. static int
  2846. lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
  2847. struct lpfc_iocbq *pIocbOut)
  2848. {
  2849. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  2850. struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
  2851. int ret = 0;
  2852. uint32_t bghm = bgf->bghm;
  2853. uint32_t bgstat = bgf->bgstat;
  2854. uint64_t failing_sector = 0;
  2855. spin_lock(&_dump_buf_lock);
  2856. if (!_dump_buf_done) {
  2857. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
  2858. " Data for %u blocks to debugfs\n",
  2859. (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
  2860. lpfc_debug_save_data(phba, cmd);
  2861. /* If we have a prot sgl, save the DIF buffer */
  2862. if (lpfc_prot_group_type(phba, cmd) ==
  2863. LPFC_PG_TYPE_DIF_BUF) {
  2864. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
  2865. "Saving DIF for %u blocks to debugfs\n",
  2866. (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
  2867. lpfc_debug_save_dif(phba, cmd);
  2868. }
  2869. _dump_buf_done = 1;
  2870. }
  2871. spin_unlock(&_dump_buf_lock);
  2872. if (lpfc_bgs_get_invalid_prof(bgstat)) {
  2873. cmd->result = ScsiResult(DID_ERROR, 0);
  2874. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2875. "9072 BLKGRD: Invalid BG Profile in cmd"
  2876. " 0x%x lba 0x%llx blk cnt 0x%x "
  2877. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2878. (unsigned long long)scsi_get_lba(cmd),
  2879. blk_rq_sectors(cmd->request), bgstat, bghm);
  2880. ret = (-1);
  2881. goto out;
  2882. }
  2883. if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
  2884. cmd->result = ScsiResult(DID_ERROR, 0);
  2885. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2886. "9073 BLKGRD: Invalid BG PDIF Block in cmd"
  2887. " 0x%x lba 0x%llx blk cnt 0x%x "
  2888. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2889. (unsigned long long)scsi_get_lba(cmd),
  2890. blk_rq_sectors(cmd->request), bgstat, bghm);
  2891. ret = (-1);
  2892. goto out;
  2893. }
  2894. if (lpfc_bgs_get_guard_err(bgstat)) {
  2895. ret = 1;
  2896. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2897. 0x10, 0x1);
  2898. cmd->result = DRIVER_SENSE << 24
  2899. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2900. phba->bg_guard_err_cnt++;
  2901. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2902. "9055 BLKGRD: Guard Tag error in cmd"
  2903. " 0x%x lba 0x%llx blk cnt 0x%x "
  2904. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2905. (unsigned long long)scsi_get_lba(cmd),
  2906. blk_rq_sectors(cmd->request), bgstat, bghm);
  2907. }
  2908. if (lpfc_bgs_get_reftag_err(bgstat)) {
  2909. ret = 1;
  2910. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2911. 0x10, 0x3);
  2912. cmd->result = DRIVER_SENSE << 24
  2913. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2914. phba->bg_reftag_err_cnt++;
  2915. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2916. "9056 BLKGRD: Ref Tag error in cmd"
  2917. " 0x%x lba 0x%llx blk cnt 0x%x "
  2918. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2919. (unsigned long long)scsi_get_lba(cmd),
  2920. blk_rq_sectors(cmd->request), bgstat, bghm);
  2921. }
  2922. if (lpfc_bgs_get_apptag_err(bgstat)) {
  2923. ret = 1;
  2924. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  2925. 0x10, 0x2);
  2926. cmd->result = DRIVER_SENSE << 24
  2927. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  2928. phba->bg_apptag_err_cnt++;
  2929. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2930. "9061 BLKGRD: App Tag error in cmd"
  2931. " 0x%x lba 0x%llx blk cnt 0x%x "
  2932. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2933. (unsigned long long)scsi_get_lba(cmd),
  2934. blk_rq_sectors(cmd->request), bgstat, bghm);
  2935. }
  2936. if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
  2937. /*
  2938. * setup sense data descriptor 0 per SPC-4 as an information
  2939. * field, and put the failing LBA in it.
  2940. * This code assumes there was also a guard/app/ref tag error
  2941. * indication.
  2942. */
  2943. cmd->sense_buffer[7] = 0xc; /* Additional sense length */
  2944. cmd->sense_buffer[8] = 0; /* Information descriptor type */
  2945. cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */
  2946. cmd->sense_buffer[10] = 0x80; /* Validity bit */
  2947. /* bghm is a "on the wire" FC frame based count */
  2948. switch (scsi_get_prot_op(cmd)) {
  2949. case SCSI_PROT_READ_INSERT:
  2950. case SCSI_PROT_WRITE_STRIP:
  2951. bghm /= cmd->device->sector_size;
  2952. break;
  2953. case SCSI_PROT_READ_STRIP:
  2954. case SCSI_PROT_WRITE_INSERT:
  2955. case SCSI_PROT_READ_PASS:
  2956. case SCSI_PROT_WRITE_PASS:
  2957. bghm /= (cmd->device->sector_size +
  2958. sizeof(struct scsi_dif_tuple));
  2959. break;
  2960. }
  2961. failing_sector = scsi_get_lba(cmd);
  2962. failing_sector += bghm;
  2963. /* Descriptor Information */
  2964. put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]);
  2965. }
  2966. if (!ret) {
  2967. /* No error was reported - problem in FW? */
  2968. lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
  2969. "9057 BLKGRD: Unknown error in cmd"
  2970. " 0x%x lba 0x%llx blk cnt 0x%x "
  2971. "bgstat=x%x bghm=x%x\n", cmd->cmnd[0],
  2972. (unsigned long long)scsi_get_lba(cmd),
  2973. blk_rq_sectors(cmd->request), bgstat, bghm);
  2974. /* Calcuate what type of error it was */
  2975. lpfc_calc_bg_err(phba, lpfc_cmd);
  2976. }
  2977. out:
  2978. return ret;
  2979. }
  2980. /**
  2981. * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
  2982. * @phba: The Hba for which this call is being executed.
  2983. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  2984. *
  2985. * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
  2986. * field of @lpfc_cmd for device with SLI-4 interface spec.
  2987. *
  2988. * Return codes:
  2989. * 1 - Error
  2990. * 0 - Success
  2991. **/
  2992. static int
  2993. lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  2994. {
  2995. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  2996. struct scatterlist *sgel = NULL;
  2997. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  2998. struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  2999. struct sli4_sge *first_data_sgl;
  3000. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  3001. dma_addr_t physaddr;
  3002. uint32_t num_bde = 0;
  3003. uint32_t dma_len;
  3004. uint32_t dma_offset = 0;
  3005. int nseg;
  3006. struct ulp_bde64 *bde;
  3007. /*
  3008. * There are three possibilities here - use scatter-gather segment, use
  3009. * the single mapping, or neither. Start the lpfc command prep by
  3010. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  3011. * data bde entry.
  3012. */
  3013. if (scsi_sg_count(scsi_cmnd)) {
  3014. /*
  3015. * The driver stores the segment count returned from pci_map_sg
  3016. * because this a count of dma-mappings used to map the use_sg
  3017. * pages. They are not guaranteed to be the same for those
  3018. * architectures that implement an IOMMU.
  3019. */
  3020. nseg = scsi_dma_map(scsi_cmnd);
  3021. if (unlikely(!nseg))
  3022. return 1;
  3023. sgl += 1;
  3024. /* clear the last flag in the fcp_rsp map entry */
  3025. sgl->word2 = le32_to_cpu(sgl->word2);
  3026. bf_set(lpfc_sli4_sge_last, sgl, 0);
  3027. sgl->word2 = cpu_to_le32(sgl->word2);
  3028. sgl += 1;
  3029. first_data_sgl = sgl;
  3030. lpfc_cmd->seg_cnt = nseg;
  3031. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  3032. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
  3033. " %s: Too many sg segments from "
  3034. "dma_map_sg. Config %d, seg_cnt %d\n",
  3035. __func__, phba->cfg_sg_seg_cnt,
  3036. lpfc_cmd->seg_cnt);
  3037. lpfc_cmd->seg_cnt = 0;
  3038. scsi_dma_unmap(scsi_cmnd);
  3039. return 1;
  3040. }
  3041. /*
  3042. * The driver established a maximum scatter-gather segment count
  3043. * during probe that limits the number of sg elements in any
  3044. * single scsi command. Just run through the seg_cnt and format
  3045. * the sge's.
  3046. * When using SLI-3 the driver will try to fit all the BDEs into
  3047. * the IOCB. If it can't then the BDEs get added to a BPL as it
  3048. * does for SLI-2 mode.
  3049. */
  3050. scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
  3051. physaddr = sg_dma_address(sgel);
  3052. dma_len = sg_dma_len(sgel);
  3053. sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
  3054. sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
  3055. sgl->word2 = le32_to_cpu(sgl->word2);
  3056. if ((num_bde + 1) == nseg)
  3057. bf_set(lpfc_sli4_sge_last, sgl, 1);
  3058. else
  3059. bf_set(lpfc_sli4_sge_last, sgl, 0);
  3060. bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
  3061. bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA);
  3062. sgl->word2 = cpu_to_le32(sgl->word2);
  3063. sgl->sge_len = cpu_to_le32(dma_len);
  3064. dma_offset += dma_len;
  3065. sgl++;
  3066. }
  3067. /* setup the performance hint (first data BDE) if enabled */
  3068. if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
  3069. bde = (struct ulp_bde64 *)
  3070. &(iocb_cmd->unsli3.sli3Words[5]);
  3071. bde->addrLow = first_data_sgl->addr_lo;
  3072. bde->addrHigh = first_data_sgl->addr_hi;
  3073. bde->tus.f.bdeSize =
  3074. le32_to_cpu(first_data_sgl->sge_len);
  3075. bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  3076. bde->tus.w = cpu_to_le32(bde->tus.w);
  3077. }
  3078. } else {
  3079. sgl += 1;
  3080. /* clear the last flag in the fcp_rsp map entry */
  3081. sgl->word2 = le32_to_cpu(sgl->word2);
  3082. bf_set(lpfc_sli4_sge_last, sgl, 1);
  3083. sgl->word2 = cpu_to_le32(sgl->word2);
  3084. }
  3085. /*
  3086. * Finish initializing those IOCB fields that are dependent on the
  3087. * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
  3088. * explicitly reinitialized.
  3089. * all iocb memory resources are reused.
  3090. */
  3091. fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
  3092. /*
  3093. * Due to difference in data length between DIF/non-DIF paths,
  3094. * we need to set word 4 of IOCB here
  3095. */
  3096. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  3097. /*
  3098. * If the OAS driver feature is enabled and the lun is enabled for
  3099. * OAS, set the oas iocb related flags.
  3100. */
  3101. if ((phba->cfg_fof) && ((struct lpfc_device_data *)
  3102. scsi_cmnd->device->hostdata)->oas_enabled)
  3103. lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
  3104. return 0;
  3105. }
  3106. /**
  3107. * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
  3108. * @phba: The Hba for which this call is being executed.
  3109. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  3110. *
  3111. * This is the protection/DIF aware version of
  3112. * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
  3113. * two functions eventually, but for now, it's here
  3114. **/
  3115. static int
  3116. lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba,
  3117. struct lpfc_scsi_buf *lpfc_cmd)
  3118. {
  3119. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  3120. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  3121. struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl);
  3122. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  3123. uint32_t num_sge = 0;
  3124. int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
  3125. int prot_group_type = 0;
  3126. int fcpdl;
  3127. /*
  3128. * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd
  3129. * fcp_rsp regions to the first data sge entry
  3130. */
  3131. if (scsi_sg_count(scsi_cmnd)) {
  3132. /*
  3133. * The driver stores the segment count returned from pci_map_sg
  3134. * because this a count of dma-mappings used to map the use_sg
  3135. * pages. They are not guaranteed to be the same for those
  3136. * architectures that implement an IOMMU.
  3137. */
  3138. datasegcnt = dma_map_sg(&phba->pcidev->dev,
  3139. scsi_sglist(scsi_cmnd),
  3140. scsi_sg_count(scsi_cmnd), datadir);
  3141. if (unlikely(!datasegcnt))
  3142. return 1;
  3143. sgl += 1;
  3144. /* clear the last flag in the fcp_rsp map entry */
  3145. sgl->word2 = le32_to_cpu(sgl->word2);
  3146. bf_set(lpfc_sli4_sge_last, sgl, 0);
  3147. sgl->word2 = cpu_to_le32(sgl->word2);
  3148. sgl += 1;
  3149. lpfc_cmd->seg_cnt = datasegcnt;
  3150. /* First check if data segment count from SCSI Layer is good */
  3151. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt)
  3152. goto err;
  3153. prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
  3154. switch (prot_group_type) {
  3155. case LPFC_PG_TYPE_NO_DIF:
  3156. /* Here we need to add a DISEED to the count */
  3157. if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt)
  3158. goto err;
  3159. num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl,
  3160. datasegcnt);
  3161. /* we should have 2 or more entries in buffer list */
  3162. if (num_sge < 2)
  3163. goto err;
  3164. break;
  3165. case LPFC_PG_TYPE_DIF_BUF:
  3166. /*
  3167. * This type indicates that protection buffers are
  3168. * passed to the driver, so that needs to be prepared
  3169. * for DMA
  3170. */
  3171. protsegcnt = dma_map_sg(&phba->pcidev->dev,
  3172. scsi_prot_sglist(scsi_cmnd),
  3173. scsi_prot_sg_count(scsi_cmnd), datadir);
  3174. if (unlikely(!protsegcnt)) {
  3175. scsi_dma_unmap(scsi_cmnd);
  3176. return 1;
  3177. }
  3178. lpfc_cmd->prot_seg_cnt = protsegcnt;
  3179. /*
  3180. * There is a minimun of 3 SGEs used for every
  3181. * protection data segment.
  3182. */
  3183. if ((lpfc_cmd->prot_seg_cnt * 3) >
  3184. (phba->cfg_total_seg_cnt - 2))
  3185. goto err;
  3186. num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl,
  3187. datasegcnt, protsegcnt);
  3188. /* we should have 3 or more entries in buffer list */
  3189. if ((num_sge < 3) ||
  3190. (num_sge > phba->cfg_total_seg_cnt))
  3191. goto err;
  3192. break;
  3193. case LPFC_PG_TYPE_INVALID:
  3194. default:
  3195. scsi_dma_unmap(scsi_cmnd);
  3196. lpfc_cmd->seg_cnt = 0;
  3197. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  3198. "9083 Unexpected protection group %i\n",
  3199. prot_group_type);
  3200. return 1;
  3201. }
  3202. }
  3203. switch (scsi_get_prot_op(scsi_cmnd)) {
  3204. case SCSI_PROT_WRITE_STRIP:
  3205. case SCSI_PROT_READ_STRIP:
  3206. lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP;
  3207. break;
  3208. case SCSI_PROT_WRITE_INSERT:
  3209. case SCSI_PROT_READ_INSERT:
  3210. lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT;
  3211. break;
  3212. case SCSI_PROT_WRITE_PASS:
  3213. case SCSI_PROT_READ_PASS:
  3214. lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS;
  3215. break;
  3216. }
  3217. fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd);
  3218. fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
  3219. /*
  3220. * Due to difference in data length between DIF/non-DIF paths,
  3221. * we need to set word 4 of IOCB here
  3222. */
  3223. iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
  3224. /*
  3225. * If the OAS driver feature is enabled and the lun is enabled for
  3226. * OAS, set the oas iocb related flags.
  3227. */
  3228. if ((phba->cfg_fof) && ((struct lpfc_device_data *)
  3229. scsi_cmnd->device->hostdata)->oas_enabled)
  3230. lpfc_cmd->cur_iocbq.iocb_flag |= (LPFC_IO_OAS | LPFC_IO_FOF);
  3231. return 0;
  3232. err:
  3233. if (lpfc_cmd->seg_cnt)
  3234. scsi_dma_unmap(scsi_cmnd);
  3235. if (lpfc_cmd->prot_seg_cnt)
  3236. dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd),
  3237. scsi_prot_sg_count(scsi_cmnd),
  3238. scsi_cmnd->sc_data_direction);
  3239. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  3240. "9084 Cannot setup S/G List for HBA"
  3241. "IO segs %d/%d SGL %d SCSI %d: %d %d\n",
  3242. lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt,
  3243. phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt,
  3244. prot_group_type, num_sge);
  3245. lpfc_cmd->seg_cnt = 0;
  3246. lpfc_cmd->prot_seg_cnt = 0;
  3247. return 1;
  3248. }
  3249. /**
  3250. * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
  3251. * @phba: The Hba for which this call is being executed.
  3252. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  3253. *
  3254. * This routine wraps the actual DMA mapping function pointer from the
  3255. * lpfc_hba struct.
  3256. *
  3257. * Return codes:
  3258. * 1 - Error
  3259. * 0 - Success
  3260. **/
  3261. static inline int
  3262. lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  3263. {
  3264. return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  3265. }
  3266. /**
  3267. * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
  3268. * using BlockGuard.
  3269. * @phba: The Hba for which this call is being executed.
  3270. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  3271. *
  3272. * This routine wraps the actual DMA mapping function pointer from the
  3273. * lpfc_hba struct.
  3274. *
  3275. * Return codes:
  3276. * 1 - Error
  3277. * 0 - Success
  3278. **/
  3279. static inline int
  3280. lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  3281. {
  3282. return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
  3283. }
  3284. /**
  3285. * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
  3286. * @phba: Pointer to hba context object.
  3287. * @vport: Pointer to vport object.
  3288. * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
  3289. * @rsp_iocb: Pointer to response iocb object which reported error.
  3290. *
  3291. * This function posts an event when there is a SCSI command reporting
  3292. * error from the scsi device.
  3293. **/
  3294. static void
  3295. lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
  3296. struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
  3297. struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
  3298. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  3299. uint32_t resp_info = fcprsp->rspStatus2;
  3300. uint32_t scsi_status = fcprsp->rspStatus3;
  3301. uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
  3302. struct lpfc_fast_path_event *fast_path_evt = NULL;
  3303. struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
  3304. unsigned long flags;
  3305. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  3306. return;
  3307. /* If there is queuefull or busy condition send a scsi event */
  3308. if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
  3309. (cmnd->result == SAM_STAT_BUSY)) {
  3310. fast_path_evt = lpfc_alloc_fast_evt(phba);
  3311. if (!fast_path_evt)
  3312. return;
  3313. fast_path_evt->un.scsi_evt.event_type =
  3314. FC_REG_SCSI_EVENT;
  3315. fast_path_evt->un.scsi_evt.subcategory =
  3316. (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
  3317. LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
  3318. fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
  3319. memcpy(&fast_path_evt->un.scsi_evt.wwpn,
  3320. &pnode->nlp_portname, sizeof(struct lpfc_name));
  3321. memcpy(&fast_path_evt->un.scsi_evt.wwnn,
  3322. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  3323. } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
  3324. ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
  3325. fast_path_evt = lpfc_alloc_fast_evt(phba);
  3326. if (!fast_path_evt)
  3327. return;
  3328. fast_path_evt->un.check_cond_evt.scsi_event.event_type =
  3329. FC_REG_SCSI_EVENT;
  3330. fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
  3331. LPFC_EVENT_CHECK_COND;
  3332. fast_path_evt->un.check_cond_evt.scsi_event.lun =
  3333. cmnd->device->lun;
  3334. memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
  3335. &pnode->nlp_portname, sizeof(struct lpfc_name));
  3336. memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
  3337. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  3338. fast_path_evt->un.check_cond_evt.sense_key =
  3339. cmnd->sense_buffer[2] & 0xf;
  3340. fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
  3341. fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
  3342. } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
  3343. fcpi_parm &&
  3344. ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
  3345. ((scsi_status == SAM_STAT_GOOD) &&
  3346. !(resp_info & (RESID_UNDER | RESID_OVER))))) {
  3347. /*
  3348. * If status is good or resid does not match with fcp_param and
  3349. * there is valid fcpi_parm, then there is a read_check error
  3350. */
  3351. fast_path_evt = lpfc_alloc_fast_evt(phba);
  3352. if (!fast_path_evt)
  3353. return;
  3354. fast_path_evt->un.read_check_error.header.event_type =
  3355. FC_REG_FABRIC_EVENT;
  3356. fast_path_evt->un.read_check_error.header.subcategory =
  3357. LPFC_EVENT_FCPRDCHKERR;
  3358. memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
  3359. &pnode->nlp_portname, sizeof(struct lpfc_name));
  3360. memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
  3361. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  3362. fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
  3363. fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
  3364. fast_path_evt->un.read_check_error.fcpiparam =
  3365. fcpi_parm;
  3366. } else
  3367. return;
  3368. fast_path_evt->vport = vport;
  3369. spin_lock_irqsave(&phba->hbalock, flags);
  3370. list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
  3371. spin_unlock_irqrestore(&phba->hbalock, flags);
  3372. lpfc_worker_wake_up(phba);
  3373. return;
  3374. }
  3375. /**
  3376. * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
  3377. * @phba: The HBA for which this call is being executed.
  3378. * @psb: The scsi buffer which is going to be un-mapped.
  3379. *
  3380. * This routine does DMA un-mapping of scatter gather list of scsi command
  3381. * field of @lpfc_cmd for device with SLI-3 interface spec.
  3382. **/
  3383. static void
  3384. lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  3385. {
  3386. /*
  3387. * There are only two special cases to consider. (1) the scsi command
  3388. * requested scatter-gather usage or (2) the scsi command allocated
  3389. * a request buffer, but did not request use_sg. There is a third
  3390. * case, but it does not require resource deallocation.
  3391. */
  3392. if (psb->seg_cnt > 0)
  3393. scsi_dma_unmap(psb->pCmd);
  3394. if (psb->prot_seg_cnt > 0)
  3395. dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
  3396. scsi_prot_sg_count(psb->pCmd),
  3397. psb->pCmd->sc_data_direction);
  3398. }
  3399. /**
  3400. * lpfc_handler_fcp_err - FCP response handler
  3401. * @vport: The virtual port for which this call is being executed.
  3402. * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
  3403. * @rsp_iocb: The response IOCB which contains FCP error.
  3404. *
  3405. * This routine is called to process response IOCB with status field
  3406. * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
  3407. * based upon SCSI and FCP error.
  3408. **/
  3409. static void
  3410. lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  3411. struct lpfc_iocbq *rsp_iocb)
  3412. {
  3413. struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
  3414. struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
  3415. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  3416. uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
  3417. uint32_t resp_info = fcprsp->rspStatus2;
  3418. uint32_t scsi_status = fcprsp->rspStatus3;
  3419. uint32_t *lp;
  3420. uint32_t host_status = DID_OK;
  3421. uint32_t rsplen = 0;
  3422. uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
  3423. /*
  3424. * If this is a task management command, there is no
  3425. * scsi packet associated with this lpfc_cmd. The driver
  3426. * consumes it.
  3427. */
  3428. if (fcpcmd->fcpCntl2) {
  3429. scsi_status = 0;
  3430. goto out;
  3431. }
  3432. if (resp_info & RSP_LEN_VALID) {
  3433. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  3434. if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
  3435. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3436. "2719 Invalid response length: "
  3437. "tgt x%x lun x%llx cmnd x%x rsplen x%x\n",
  3438. cmnd->device->id,
  3439. cmnd->device->lun, cmnd->cmnd[0],
  3440. rsplen);
  3441. host_status = DID_ERROR;
  3442. goto out;
  3443. }
  3444. if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
  3445. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3446. "2757 Protocol failure detected during "
  3447. "processing of FCP I/O op: "
  3448. "tgt x%x lun x%llx cmnd x%x rspInfo3 x%x\n",
  3449. cmnd->device->id,
  3450. cmnd->device->lun, cmnd->cmnd[0],
  3451. fcprsp->rspInfo3);
  3452. host_status = DID_ERROR;
  3453. goto out;
  3454. }
  3455. }
  3456. if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
  3457. uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
  3458. if (snslen > SCSI_SENSE_BUFFERSIZE)
  3459. snslen = SCSI_SENSE_BUFFERSIZE;
  3460. if (resp_info & RSP_LEN_VALID)
  3461. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  3462. memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
  3463. }
  3464. lp = (uint32_t *)cmnd->sense_buffer;
  3465. /* special handling for under run conditions */
  3466. if (!scsi_status && (resp_info & RESID_UNDER)) {
  3467. /* don't log under runs if fcp set... */
  3468. if (vport->cfg_log_verbose & LOG_FCP)
  3469. logit = LOG_FCP_ERROR;
  3470. /* unless operator says so */
  3471. if (vport->cfg_log_verbose & LOG_FCP_UNDER)
  3472. logit = LOG_FCP_UNDER;
  3473. }
  3474. lpfc_printf_vlog(vport, KERN_WARNING, logit,
  3475. "9024 FCP command x%x failed: x%x SNS x%x x%x "
  3476. "Data: x%x x%x x%x x%x x%x\n",
  3477. cmnd->cmnd[0], scsi_status,
  3478. be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
  3479. be32_to_cpu(fcprsp->rspResId),
  3480. be32_to_cpu(fcprsp->rspSnsLen),
  3481. be32_to_cpu(fcprsp->rspRspLen),
  3482. fcprsp->rspInfo3);
  3483. scsi_set_resid(cmnd, 0);
  3484. if (resp_info & RESID_UNDER) {
  3485. scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
  3486. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER,
  3487. "9025 FCP Read Underrun, expected %d, "
  3488. "residual %d Data: x%x x%x x%x\n",
  3489. be32_to_cpu(fcpcmd->fcpDl),
  3490. scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
  3491. cmnd->underflow);
  3492. /*
  3493. * If there is an under run check if under run reported by
  3494. * storage array is same as the under run reported by HBA.
  3495. * If this is not same, there is a dropped frame.
  3496. */
  3497. if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
  3498. fcpi_parm &&
  3499. (scsi_get_resid(cmnd) != fcpi_parm)) {
  3500. lpfc_printf_vlog(vport, KERN_WARNING,
  3501. LOG_FCP | LOG_FCP_ERROR,
  3502. "9026 FCP Read Check Error "
  3503. "and Underrun Data: x%x x%x x%x x%x\n",
  3504. be32_to_cpu(fcpcmd->fcpDl),
  3505. scsi_get_resid(cmnd), fcpi_parm,
  3506. cmnd->cmnd[0]);
  3507. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  3508. host_status = DID_ERROR;
  3509. }
  3510. /*
  3511. * The cmnd->underflow is the minimum number of bytes that must
  3512. * be transferred for this command. Provided a sense condition
  3513. * is not present, make sure the actual amount transferred is at
  3514. * least the underflow value or fail.
  3515. */
  3516. if (!(resp_info & SNS_LEN_VALID) &&
  3517. (scsi_status == SAM_STAT_GOOD) &&
  3518. (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
  3519. < cmnd->underflow)) {
  3520. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  3521. "9027 FCP command x%x residual "
  3522. "underrun converted to error "
  3523. "Data: x%x x%x x%x\n",
  3524. cmnd->cmnd[0], scsi_bufflen(cmnd),
  3525. scsi_get_resid(cmnd), cmnd->underflow);
  3526. host_status = DID_ERROR;
  3527. }
  3528. } else if (resp_info & RESID_OVER) {
  3529. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  3530. "9028 FCP command x%x residual overrun error. "
  3531. "Data: x%x x%x\n", cmnd->cmnd[0],
  3532. scsi_bufflen(cmnd), scsi_get_resid(cmnd));
  3533. host_status = DID_ERROR;
  3534. /*
  3535. * Check SLI validation that all the transfer was actually done
  3536. * (fcpi_parm should be zero). Apply check only to reads.
  3537. */
  3538. } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
  3539. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
  3540. "9029 FCP Read Check Error Data: "
  3541. "x%x x%x x%x x%x x%x\n",
  3542. be32_to_cpu(fcpcmd->fcpDl),
  3543. be32_to_cpu(fcprsp->rspResId),
  3544. fcpi_parm, cmnd->cmnd[0], scsi_status);
  3545. switch (scsi_status) {
  3546. case SAM_STAT_GOOD:
  3547. case SAM_STAT_CHECK_CONDITION:
  3548. /* Fabric dropped a data frame. Fail any successful
  3549. * command in which we detected dropped frames.
  3550. * A status of good or some check conditions could
  3551. * be considered a successful command.
  3552. */
  3553. host_status = DID_ERROR;
  3554. break;
  3555. }
  3556. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  3557. }
  3558. out:
  3559. cmnd->result = ScsiResult(host_status, scsi_status);
  3560. lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
  3561. }
  3562. /**
  3563. * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
  3564. * @phba: The Hba for which this call is being executed.
  3565. * @pIocbIn: The command IOCBQ for the scsi cmnd.
  3566. * @pIocbOut: The response IOCBQ for the scsi cmnd.
  3567. *
  3568. * This routine assigns scsi command result by looking into response IOCB
  3569. * status field appropriately. This routine handles QUEUE FULL condition as
  3570. * well by ramping down device queue depth.
  3571. **/
  3572. static void
  3573. lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
  3574. struct lpfc_iocbq *pIocbOut)
  3575. {
  3576. struct lpfc_scsi_buf *lpfc_cmd =
  3577. (struct lpfc_scsi_buf *) pIocbIn->context1;
  3578. struct lpfc_vport *vport = pIocbIn->vport;
  3579. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  3580. struct lpfc_nodelist *pnode = rdata->pnode;
  3581. struct scsi_cmnd *cmd;
  3582. int result;
  3583. int depth;
  3584. unsigned long flags;
  3585. struct lpfc_fast_path_event *fast_path_evt;
  3586. struct Scsi_Host *shost;
  3587. uint32_t queue_depth, scsi_id;
  3588. uint32_t logit = LOG_FCP;
  3589. /* Sanity check on return of outstanding command */
  3590. if (!(lpfc_cmd->pCmd))
  3591. return;
  3592. cmd = lpfc_cmd->pCmd;
  3593. shost = cmd->device->host;
  3594. lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK);
  3595. lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
  3596. /* pick up SLI4 exhange busy status from HBA */
  3597. lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
  3598. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3599. if (lpfc_cmd->prot_data_type) {
  3600. struct scsi_dif_tuple *src = NULL;
  3601. src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
  3602. /*
  3603. * Used to restore any changes to protection
  3604. * data for error injection.
  3605. */
  3606. switch (lpfc_cmd->prot_data_type) {
  3607. case LPFC_INJERR_REFTAG:
  3608. src->ref_tag =
  3609. lpfc_cmd->prot_data;
  3610. break;
  3611. case LPFC_INJERR_APPTAG:
  3612. src->app_tag =
  3613. (uint16_t)lpfc_cmd->prot_data;
  3614. break;
  3615. case LPFC_INJERR_GUARD:
  3616. src->guard_tag =
  3617. (uint16_t)lpfc_cmd->prot_data;
  3618. break;
  3619. default:
  3620. break;
  3621. }
  3622. lpfc_cmd->prot_data = 0;
  3623. lpfc_cmd->prot_data_type = 0;
  3624. lpfc_cmd->prot_data_segment = NULL;
  3625. }
  3626. #endif
  3627. if (pnode && NLP_CHK_NODE_ACT(pnode))
  3628. atomic_dec(&pnode->cmd_pending);
  3629. if (lpfc_cmd->status) {
  3630. if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
  3631. (lpfc_cmd->result & IOERR_DRVR_MASK))
  3632. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  3633. else if (lpfc_cmd->status >= IOSTAT_CNT)
  3634. lpfc_cmd->status = IOSTAT_DEFAULT;
  3635. if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR &&
  3636. !lpfc_cmd->fcp_rsp->rspStatus3 &&
  3637. (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) &&
  3638. !(vport->cfg_log_verbose & LOG_FCP_UNDER))
  3639. logit = 0;
  3640. else
  3641. logit = LOG_FCP | LOG_FCP_UNDER;
  3642. lpfc_printf_vlog(vport, KERN_WARNING, logit,
  3643. "9030 FCP cmd x%x failed <%d/%lld> "
  3644. "status: x%x result: x%x "
  3645. "sid: x%x did: x%x oxid: x%x "
  3646. "Data: x%x x%x\n",
  3647. cmd->cmnd[0],
  3648. cmd->device ? cmd->device->id : 0xffff,
  3649. cmd->device ? cmd->device->lun : 0xffff,
  3650. lpfc_cmd->status, lpfc_cmd->result,
  3651. vport->fc_myDID,
  3652. (pnode) ? pnode->nlp_DID : 0,
  3653. phba->sli_rev == LPFC_SLI_REV4 ?
  3654. lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
  3655. pIocbOut->iocb.ulpContext,
  3656. lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
  3657. switch (lpfc_cmd->status) {
  3658. case IOSTAT_FCP_RSP_ERROR:
  3659. /* Call FCP RSP handler to determine result */
  3660. lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
  3661. break;
  3662. case IOSTAT_NPORT_BSY:
  3663. case IOSTAT_FABRIC_BSY:
  3664. cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
  3665. fast_path_evt = lpfc_alloc_fast_evt(phba);
  3666. if (!fast_path_evt)
  3667. break;
  3668. fast_path_evt->un.fabric_evt.event_type =
  3669. FC_REG_FABRIC_EVENT;
  3670. fast_path_evt->un.fabric_evt.subcategory =
  3671. (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
  3672. LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
  3673. if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  3674. memcpy(&fast_path_evt->un.fabric_evt.wwpn,
  3675. &pnode->nlp_portname,
  3676. sizeof(struct lpfc_name));
  3677. memcpy(&fast_path_evt->un.fabric_evt.wwnn,
  3678. &pnode->nlp_nodename,
  3679. sizeof(struct lpfc_name));
  3680. }
  3681. fast_path_evt->vport = vport;
  3682. fast_path_evt->work_evt.evt =
  3683. LPFC_EVT_FASTPATH_MGMT_EVT;
  3684. spin_lock_irqsave(&phba->hbalock, flags);
  3685. list_add_tail(&fast_path_evt->work_evt.evt_listp,
  3686. &phba->work_list);
  3687. spin_unlock_irqrestore(&phba->hbalock, flags);
  3688. lpfc_worker_wake_up(phba);
  3689. break;
  3690. case IOSTAT_LOCAL_REJECT:
  3691. case IOSTAT_REMOTE_STOP:
  3692. if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
  3693. lpfc_cmd->result ==
  3694. IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
  3695. lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
  3696. lpfc_cmd->result ==
  3697. IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
  3698. cmd->result = ScsiResult(DID_NO_CONNECT, 0);
  3699. break;
  3700. }
  3701. if (lpfc_cmd->result == IOERR_INVALID_RPI ||
  3702. lpfc_cmd->result == IOERR_NO_RESOURCES ||
  3703. lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
  3704. lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
  3705. cmd->result = ScsiResult(DID_REQUEUE, 0);
  3706. break;
  3707. }
  3708. if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
  3709. lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
  3710. pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
  3711. if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  3712. /*
  3713. * This is a response for a BG enabled
  3714. * cmd. Parse BG error
  3715. */
  3716. lpfc_parse_bg_err(phba, lpfc_cmd,
  3717. pIocbOut);
  3718. break;
  3719. } else {
  3720. lpfc_printf_vlog(vport, KERN_WARNING,
  3721. LOG_BG,
  3722. "9031 non-zero BGSTAT "
  3723. "on unprotected cmd\n");
  3724. }
  3725. }
  3726. if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
  3727. && (phba->sli_rev == LPFC_SLI_REV4)
  3728. && (pnode && NLP_CHK_NODE_ACT(pnode))) {
  3729. /* This IO was aborted by the target, we don't
  3730. * know the rxid and because we did not send the
  3731. * ABTS we cannot generate and RRQ.
  3732. */
  3733. lpfc_set_rrq_active(phba, pnode,
  3734. lpfc_cmd->cur_iocbq.sli4_lxritag,
  3735. 0, 0);
  3736. }
  3737. /* else: fall through */
  3738. default:
  3739. cmd->result = ScsiResult(DID_ERROR, 0);
  3740. break;
  3741. }
  3742. if (!pnode || !NLP_CHK_NODE_ACT(pnode)
  3743. || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
  3744. cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
  3745. SAM_STAT_BUSY);
  3746. } else
  3747. cmd->result = ScsiResult(DID_OK, 0);
  3748. if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
  3749. uint32_t *lp = (uint32_t *)cmd->sense_buffer;
  3750. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  3751. "0710 Iodone <%d/%llu> cmd %p, error "
  3752. "x%x SNS x%x x%x Data: x%x x%x\n",
  3753. cmd->device->id, cmd->device->lun, cmd,
  3754. cmd->result, *lp, *(lp + 3), cmd->retries,
  3755. scsi_get_resid(cmd));
  3756. }
  3757. lpfc_update_stats(phba, lpfc_cmd);
  3758. result = cmd->result;
  3759. if (vport->cfg_max_scsicmpl_time &&
  3760. time_after(jiffies, lpfc_cmd->start_time +
  3761. msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
  3762. spin_lock_irqsave(shost->host_lock, flags);
  3763. if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  3764. if (pnode->cmd_qdepth >
  3765. atomic_read(&pnode->cmd_pending) &&
  3766. (atomic_read(&pnode->cmd_pending) >
  3767. LPFC_MIN_TGT_QDEPTH) &&
  3768. ((cmd->cmnd[0] == READ_10) ||
  3769. (cmd->cmnd[0] == WRITE_10)))
  3770. pnode->cmd_qdepth =
  3771. atomic_read(&pnode->cmd_pending);
  3772. pnode->last_change_time = jiffies;
  3773. }
  3774. spin_unlock_irqrestore(shost->host_lock, flags);
  3775. } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  3776. if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) &&
  3777. time_after(jiffies, pnode->last_change_time +
  3778. msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
  3779. spin_lock_irqsave(shost->host_lock, flags);
  3780. depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT
  3781. / 100;
  3782. depth = depth ? depth : 1;
  3783. pnode->cmd_qdepth += depth;
  3784. if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth)
  3785. pnode->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3786. pnode->last_change_time = jiffies;
  3787. spin_unlock_irqrestore(shost->host_lock, flags);
  3788. }
  3789. }
  3790. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  3791. /* The sdev is not guaranteed to be valid post scsi_done upcall. */
  3792. queue_depth = cmd->device->queue_depth;
  3793. scsi_id = cmd->device->id;
  3794. cmd->scsi_done(cmd);
  3795. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  3796. spin_lock_irqsave(&phba->hbalock, flags);
  3797. lpfc_cmd->pCmd = NULL;
  3798. spin_unlock_irqrestore(&phba->hbalock, flags);
  3799. /*
  3800. * If there is a thread waiting for command completion
  3801. * wake up the thread.
  3802. */
  3803. spin_lock_irqsave(shost->host_lock, flags);
  3804. if (lpfc_cmd->waitq)
  3805. wake_up(lpfc_cmd->waitq);
  3806. spin_unlock_irqrestore(shost->host_lock, flags);
  3807. lpfc_release_scsi_buf(phba, lpfc_cmd);
  3808. return;
  3809. }
  3810. spin_lock_irqsave(&phba->hbalock, flags);
  3811. lpfc_cmd->pCmd = NULL;
  3812. spin_unlock_irqrestore(&phba->hbalock, flags);
  3813. /*
  3814. * If there is a thread waiting for command completion
  3815. * wake up the thread.
  3816. */
  3817. spin_lock_irqsave(shost->host_lock, flags);
  3818. if (lpfc_cmd->waitq)
  3819. wake_up(lpfc_cmd->waitq);
  3820. spin_unlock_irqrestore(shost->host_lock, flags);
  3821. lpfc_release_scsi_buf(phba, lpfc_cmd);
  3822. }
  3823. /**
  3824. * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
  3825. * @data: A pointer to the immediate command data portion of the IOCB.
  3826. * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
  3827. *
  3828. * The routine copies the entire FCP command from @fcp_cmnd to @data while
  3829. * byte swapping the data to big endian format for transmission on the wire.
  3830. **/
  3831. static void
  3832. lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
  3833. {
  3834. int i, j;
  3835. for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
  3836. i += sizeof(uint32_t), j++) {
  3837. ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
  3838. }
  3839. }
  3840. /**
  3841. * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
  3842. * @vport: The virtual port for which this call is being executed.
  3843. * @lpfc_cmd: The scsi command which needs to send.
  3844. * @pnode: Pointer to lpfc_nodelist.
  3845. *
  3846. * This routine initializes fcp_cmnd and iocb data structure from scsi command
  3847. * to transfer for device with SLI3 interface spec.
  3848. **/
  3849. static void
  3850. lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  3851. struct lpfc_nodelist *pnode)
  3852. {
  3853. struct lpfc_hba *phba = vport->phba;
  3854. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  3855. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  3856. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  3857. struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
  3858. int datadir = scsi_cmnd->sc_data_direction;
  3859. char tag[2];
  3860. uint8_t *ptr;
  3861. bool sli4;
  3862. uint32_t fcpdl;
  3863. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  3864. return;
  3865. lpfc_cmd->fcp_rsp->rspSnsLen = 0;
  3866. /* clear task management bits */
  3867. lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
  3868. int_to_scsilun(lpfc_cmd->pCmd->device->lun,
  3869. &lpfc_cmd->fcp_cmnd->fcp_lun);
  3870. ptr = &fcp_cmnd->fcpCdb[0];
  3871. memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3872. if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) {
  3873. ptr += scsi_cmnd->cmd_len;
  3874. memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
  3875. }
  3876. if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
  3877. switch (tag[0]) {
  3878. case HEAD_OF_QUEUE_TAG:
  3879. fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
  3880. break;
  3881. case ORDERED_QUEUE_TAG:
  3882. fcp_cmnd->fcpCntl1 = ORDERED_Q;
  3883. break;
  3884. default:
  3885. fcp_cmnd->fcpCntl1 = SIMPLE_Q;
  3886. break;
  3887. }
  3888. } else
  3889. fcp_cmnd->fcpCntl1 = SIMPLE_Q;
  3890. sli4 = (phba->sli_rev == LPFC_SLI_REV4);
  3891. piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
  3892. /*
  3893. * There are three possibilities here - use scatter-gather segment, use
  3894. * the single mapping, or neither. Start the lpfc command prep by
  3895. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  3896. * data bde entry.
  3897. */
  3898. if (scsi_sg_count(scsi_cmnd)) {
  3899. if (datadir == DMA_TO_DEVICE) {
  3900. iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
  3901. iocb_cmd->ulpPU = PARM_READ_CHECK;
  3902. if (vport->cfg_first_burst_size &&
  3903. (pnode->nlp_flag & NLP_FIRSTBURST)) {
  3904. fcpdl = scsi_bufflen(scsi_cmnd);
  3905. if (fcpdl < vport->cfg_first_burst_size)
  3906. piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl;
  3907. else
  3908. piocbq->iocb.un.fcpi.fcpi_XRdy =
  3909. vport->cfg_first_burst_size;
  3910. }
  3911. fcp_cmnd->fcpCntl3 = WRITE_DATA;
  3912. phba->fc4OutputRequests++;
  3913. } else {
  3914. iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
  3915. iocb_cmd->ulpPU = PARM_READ_CHECK;
  3916. fcp_cmnd->fcpCntl3 = READ_DATA;
  3917. phba->fc4InputRequests++;
  3918. }
  3919. } else {
  3920. iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
  3921. iocb_cmd->un.fcpi.fcpi_parm = 0;
  3922. iocb_cmd->ulpPU = 0;
  3923. fcp_cmnd->fcpCntl3 = 0;
  3924. phba->fc4ControlRequests++;
  3925. }
  3926. if (phba->sli_rev == 3 &&
  3927. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
  3928. lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
  3929. /*
  3930. * Finish initializing those IOCB fields that are independent
  3931. * of the scsi_cmnd request_buffer
  3932. */
  3933. piocbq->iocb.ulpContext = pnode->nlp_rpi;
  3934. if (sli4)
  3935. piocbq->iocb.ulpContext =
  3936. phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
  3937. if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
  3938. piocbq->iocb.ulpFCP2Rcvy = 1;
  3939. else
  3940. piocbq->iocb.ulpFCP2Rcvy = 0;
  3941. piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
  3942. piocbq->context1 = lpfc_cmd;
  3943. piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  3944. piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
  3945. piocbq->vport = vport;
  3946. }
  3947. /**
  3948. * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
  3949. * @vport: The virtual port for which this call is being executed.
  3950. * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
  3951. * @lun: Logical unit number.
  3952. * @task_mgmt_cmd: SCSI task management command.
  3953. *
  3954. * This routine creates FCP information unit corresponding to @task_mgmt_cmd
  3955. * for device with SLI-3 interface spec.
  3956. *
  3957. * Return codes:
  3958. * 0 - Error
  3959. * 1 - Success
  3960. **/
  3961. static int
  3962. lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
  3963. struct lpfc_scsi_buf *lpfc_cmd,
  3964. uint64_t lun,
  3965. uint8_t task_mgmt_cmd)
  3966. {
  3967. struct lpfc_iocbq *piocbq;
  3968. IOCB_t *piocb;
  3969. struct fcp_cmnd *fcp_cmnd;
  3970. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  3971. struct lpfc_nodelist *ndlp = rdata->pnode;
  3972. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
  3973. ndlp->nlp_state != NLP_STE_MAPPED_NODE)
  3974. return 0;
  3975. piocbq = &(lpfc_cmd->cur_iocbq);
  3976. piocbq->vport = vport;
  3977. piocb = &piocbq->iocb;
  3978. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  3979. /* Clear out any old data in the FCP command area */
  3980. memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
  3981. int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
  3982. fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
  3983. if (vport->phba->sli_rev == 3 &&
  3984. !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
  3985. lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
  3986. piocb->ulpCommand = CMD_FCP_ICMND64_CR;
  3987. piocb->ulpContext = ndlp->nlp_rpi;
  3988. if (vport->phba->sli_rev == LPFC_SLI_REV4) {
  3989. piocb->ulpContext =
  3990. vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  3991. }
  3992. piocb->ulpFCP2Rcvy = (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) ? 1 : 0;
  3993. piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
  3994. piocb->ulpPU = 0;
  3995. piocb->un.fcpi.fcpi_parm = 0;
  3996. /* ulpTimeout is only one byte */
  3997. if (lpfc_cmd->timeout > 0xff) {
  3998. /*
  3999. * Do not timeout the command at the firmware level.
  4000. * The driver will provide the timeout mechanism.
  4001. */
  4002. piocb->ulpTimeout = 0;
  4003. } else
  4004. piocb->ulpTimeout = lpfc_cmd->timeout;
  4005. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  4006. lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
  4007. return 1;
  4008. }
  4009. /**
  4010. * lpfc_scsi_api_table_setup - Set up scsi api function jump table
  4011. * @phba: The hba struct for which this call is being executed.
  4012. * @dev_grp: The HBA PCI-Device group number.
  4013. *
  4014. * This routine sets up the SCSI interface API function jump table in @phba
  4015. * struct.
  4016. * Returns: 0 - success, -ENODEV - failure.
  4017. **/
  4018. int
  4019. lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4020. {
  4021. phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
  4022. phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
  4023. switch (dev_grp) {
  4024. case LPFC_PCI_DEV_LP:
  4025. phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
  4026. phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
  4027. phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3;
  4028. phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
  4029. phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
  4030. break;
  4031. case LPFC_PCI_DEV_OC:
  4032. phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
  4033. phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
  4034. phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4;
  4035. phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
  4036. phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
  4037. break;
  4038. default:
  4039. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4040. "1418 Invalid HBA PCI-device group: 0x%x\n",
  4041. dev_grp);
  4042. return -ENODEV;
  4043. break;
  4044. }
  4045. phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
  4046. phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  4047. return 0;
  4048. }
  4049. /**
  4050. * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
  4051. * @phba: The Hba for which this call is being executed.
  4052. * @cmdiocbq: Pointer to lpfc_iocbq data structure.
  4053. * @rspiocbq: Pointer to lpfc_iocbq data structure.
  4054. *
  4055. * This routine is IOCB completion routine for device reset and target reset
  4056. * routine. This routine release scsi buffer associated with lpfc_cmd.
  4057. **/
  4058. static void
  4059. lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
  4060. struct lpfc_iocbq *cmdiocbq,
  4061. struct lpfc_iocbq *rspiocbq)
  4062. {
  4063. struct lpfc_scsi_buf *lpfc_cmd =
  4064. (struct lpfc_scsi_buf *) cmdiocbq->context1;
  4065. if (lpfc_cmd)
  4066. lpfc_release_scsi_buf(phba, lpfc_cmd);
  4067. return;
  4068. }
  4069. /**
  4070. * lpfc_info - Info entry point of scsi_host_template data structure
  4071. * @host: The scsi host for which this call is being executed.
  4072. *
  4073. * This routine provides module information about hba.
  4074. *
  4075. * Reutrn code:
  4076. * Pointer to char - Success.
  4077. **/
  4078. const char *
  4079. lpfc_info(struct Scsi_Host *host)
  4080. {
  4081. struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
  4082. struct lpfc_hba *phba = vport->phba;
  4083. int len, link_speed = 0;
  4084. static char lpfcinfobuf[384];
  4085. memset(lpfcinfobuf,0,384);
  4086. if (phba && phba->pcidev){
  4087. strncpy(lpfcinfobuf, phba->ModelDesc, 256);
  4088. len = strlen(lpfcinfobuf);
  4089. snprintf(lpfcinfobuf + len,
  4090. 384-len,
  4091. " on PCI bus %02x device %02x irq %d",
  4092. phba->pcidev->bus->number,
  4093. phba->pcidev->devfn,
  4094. phba->pcidev->irq);
  4095. len = strlen(lpfcinfobuf);
  4096. if (phba->Port[0]) {
  4097. snprintf(lpfcinfobuf + len,
  4098. 384-len,
  4099. " port %s",
  4100. phba->Port);
  4101. }
  4102. len = strlen(lpfcinfobuf);
  4103. if (phba->sli_rev <= LPFC_SLI_REV3) {
  4104. link_speed = lpfc_sli_port_speed_get(phba);
  4105. } else {
  4106. if (phba->sli4_hba.link_state.logical_speed)
  4107. link_speed =
  4108. phba->sli4_hba.link_state.logical_speed;
  4109. else
  4110. link_speed = phba->sli4_hba.link_state.speed;
  4111. }
  4112. if (link_speed != 0)
  4113. snprintf(lpfcinfobuf + len, 384-len,
  4114. " Logical Link Speed: %d Mbps", link_speed);
  4115. }
  4116. return lpfcinfobuf;
  4117. }
  4118. /**
  4119. * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
  4120. * @phba: The Hba for which this call is being executed.
  4121. *
  4122. * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
  4123. * The default value of cfg_poll_tmo is 10 milliseconds.
  4124. **/
  4125. static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
  4126. {
  4127. unsigned long poll_tmo_expires =
  4128. (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
  4129. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  4130. mod_timer(&phba->fcp_poll_timer,
  4131. poll_tmo_expires);
  4132. }
  4133. /**
  4134. * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
  4135. * @phba: The Hba for which this call is being executed.
  4136. *
  4137. * This routine starts the fcp_poll_timer of @phba.
  4138. **/
  4139. void lpfc_poll_start_timer(struct lpfc_hba * phba)
  4140. {
  4141. lpfc_poll_rearm_timer(phba);
  4142. }
  4143. /**
  4144. * lpfc_poll_timeout - Restart polling timer
  4145. * @ptr: Map to lpfc_hba data structure pointer.
  4146. *
  4147. * This routine restarts fcp_poll timer, when FCP ring polling is enable
  4148. * and FCP Ring interrupt is disable.
  4149. **/
  4150. void lpfc_poll_timeout(unsigned long ptr)
  4151. {
  4152. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4153. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  4154. lpfc_sli_handle_fast_ring_event(phba,
  4155. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  4156. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  4157. lpfc_poll_rearm_timer(phba);
  4158. }
  4159. }
  4160. /**
  4161. * lpfc_queuecommand - scsi_host_template queuecommand entry point
  4162. * @cmnd: Pointer to scsi_cmnd data structure.
  4163. * @done: Pointer to done routine.
  4164. *
  4165. * Driver registers this routine to scsi midlayer to submit a @cmd to process.
  4166. * This routine prepares an IOCB from scsi command and provides to firmware.
  4167. * The @done callback is invoked after driver finished processing the command.
  4168. *
  4169. * Return value :
  4170. * 0 - Success
  4171. * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
  4172. **/
  4173. static int
  4174. lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd)
  4175. {
  4176. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4177. struct lpfc_hba *phba = vport->phba;
  4178. struct lpfc_rport_data *rdata;
  4179. struct lpfc_nodelist *ndlp;
  4180. struct lpfc_scsi_buf *lpfc_cmd;
  4181. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  4182. int err;
  4183. rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
  4184. err = fc_remote_port_chkready(rport);
  4185. if (err) {
  4186. cmnd->result = err;
  4187. goto out_fail_command;
  4188. }
  4189. ndlp = rdata->pnode;
  4190. if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
  4191. (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) {
  4192. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4193. "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
  4194. " op:%02x str=%s without registering for"
  4195. " BlockGuard - Rejecting command\n",
  4196. cmnd->cmnd[0], scsi_get_prot_op(cmnd),
  4197. dif_op_str[scsi_get_prot_op(cmnd)]);
  4198. goto out_fail_command;
  4199. }
  4200. /*
  4201. * Catch race where our node has transitioned, but the
  4202. * transport is still transitioning.
  4203. */
  4204. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  4205. goto out_tgt_busy;
  4206. if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
  4207. goto out_tgt_busy;
  4208. lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
  4209. if (lpfc_cmd == NULL) {
  4210. lpfc_rampdown_queue_depth(phba);
  4211. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4212. "0707 driver's buffer pool is empty, "
  4213. "IO busied\n");
  4214. goto out_host_busy;
  4215. }
  4216. /*
  4217. * Store the midlayer's command structure for the completion phase
  4218. * and complete the command initialization.
  4219. */
  4220. lpfc_cmd->pCmd = cmnd;
  4221. lpfc_cmd->rdata = rdata;
  4222. lpfc_cmd->timeout = 0;
  4223. lpfc_cmd->start_time = jiffies;
  4224. cmnd->host_scribble = (unsigned char *)lpfc_cmd;
  4225. if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
  4226. if (vport->phba->cfg_enable_bg) {
  4227. lpfc_printf_vlog(vport,
  4228. KERN_INFO, LOG_SCSI_CMD,
  4229. "9033 BLKGRD: rcvd %s cmd:x%x "
  4230. "sector x%llx cnt %u pt %x\n",
  4231. dif_op_str[scsi_get_prot_op(cmnd)],
  4232. cmnd->cmnd[0],
  4233. (unsigned long long)scsi_get_lba(cmnd),
  4234. blk_rq_sectors(cmnd->request),
  4235. (cmnd->cmnd[1]>>5));
  4236. }
  4237. err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
  4238. } else {
  4239. if (vport->phba->cfg_enable_bg) {
  4240. lpfc_printf_vlog(vport,
  4241. KERN_INFO, LOG_SCSI_CMD,
  4242. "9038 BLKGRD: rcvd PROT_NORMAL cmd: "
  4243. "x%x sector x%llx cnt %u pt %x\n",
  4244. cmnd->cmnd[0],
  4245. (unsigned long long)scsi_get_lba(cmnd),
  4246. blk_rq_sectors(cmnd->request),
  4247. (cmnd->cmnd[1]>>5));
  4248. }
  4249. err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  4250. }
  4251. if (err)
  4252. goto out_host_busy_free_buf;
  4253. lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
  4254. atomic_inc(&ndlp->cmd_pending);
  4255. err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
  4256. &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
  4257. if (err) {
  4258. atomic_dec(&ndlp->cmd_pending);
  4259. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4260. "3376 FCP could not issue IOCB err %x"
  4261. "FCP cmd x%x <%d/%llu> "
  4262. "sid: x%x did: x%x oxid: x%x "
  4263. "Data: x%x x%x x%x x%x\n",
  4264. err, cmnd->cmnd[0],
  4265. cmnd->device ? cmnd->device->id : 0xffff,
  4266. cmnd->device ? cmnd->device->lun : (u64) -1,
  4267. vport->fc_myDID, ndlp->nlp_DID,
  4268. phba->sli_rev == LPFC_SLI_REV4 ?
  4269. lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff,
  4270. lpfc_cmd->cur_iocbq.iocb.ulpContext,
  4271. lpfc_cmd->cur_iocbq.iocb.ulpIoTag,
  4272. lpfc_cmd->cur_iocbq.iocb.ulpTimeout,
  4273. (uint32_t)
  4274. (cmnd->request->timeout / 1000));
  4275. goto out_host_busy_free_buf;
  4276. }
  4277. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  4278. lpfc_sli_handle_fast_ring_event(phba,
  4279. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  4280. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  4281. lpfc_poll_rearm_timer(phba);
  4282. }
  4283. return 0;
  4284. out_host_busy_free_buf:
  4285. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  4286. lpfc_release_scsi_buf(phba, lpfc_cmd);
  4287. out_host_busy:
  4288. return SCSI_MLQUEUE_HOST_BUSY;
  4289. out_tgt_busy:
  4290. return SCSI_MLQUEUE_TARGET_BUSY;
  4291. out_fail_command:
  4292. cmnd->scsi_done(cmnd);
  4293. return 0;
  4294. }
  4295. /**
  4296. * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
  4297. * @cmnd: Pointer to scsi_cmnd data structure.
  4298. *
  4299. * This routine aborts @cmnd pending in base driver.
  4300. *
  4301. * Return code :
  4302. * 0x2003 - Error
  4303. * 0x2002 - Success
  4304. **/
  4305. static int
  4306. lpfc_abort_handler(struct scsi_cmnd *cmnd)
  4307. {
  4308. struct Scsi_Host *shost = cmnd->device->host;
  4309. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4310. struct lpfc_hba *phba = vport->phba;
  4311. struct lpfc_iocbq *iocb;
  4312. struct lpfc_iocbq *abtsiocb;
  4313. struct lpfc_scsi_buf *lpfc_cmd;
  4314. IOCB_t *cmd, *icmd;
  4315. int ret = SUCCESS, status = 0;
  4316. struct lpfc_sli_ring *pring_s4;
  4317. int ring_number, ret_val;
  4318. unsigned long flags, iflags;
  4319. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
  4320. status = fc_block_scsi_eh(cmnd);
  4321. if (status != 0 && status != SUCCESS)
  4322. return status;
  4323. spin_lock_irqsave(&phba->hbalock, flags);
  4324. /* driver queued commands are in process of being flushed */
  4325. if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
  4326. spin_unlock_irqrestore(&phba->hbalock, flags);
  4327. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4328. "3168 SCSI Layer abort requested I/O has been "
  4329. "flushed by LLD.\n");
  4330. return FAILED;
  4331. }
  4332. lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
  4333. if (!lpfc_cmd || !lpfc_cmd->pCmd) {
  4334. spin_unlock_irqrestore(&phba->hbalock, flags);
  4335. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4336. "2873 SCSI Layer I/O Abort Request IO CMPL Status "
  4337. "x%x ID %d LUN %llu\n",
  4338. SUCCESS, cmnd->device->id, cmnd->device->lun);
  4339. return SUCCESS;
  4340. }
  4341. iocb = &lpfc_cmd->cur_iocbq;
  4342. /* the command is in process of being cancelled */
  4343. if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
  4344. spin_unlock_irqrestore(&phba->hbalock, flags);
  4345. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4346. "3169 SCSI Layer abort requested I/O has been "
  4347. "cancelled by LLD.\n");
  4348. return FAILED;
  4349. }
  4350. /*
  4351. * If pCmd field of the corresponding lpfc_scsi_buf structure
  4352. * points to a different SCSI command, then the driver has
  4353. * already completed this command, but the midlayer did not
  4354. * see the completion before the eh fired. Just return SUCCESS.
  4355. */
  4356. if (lpfc_cmd->pCmd != cmnd) {
  4357. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4358. "3170 SCSI Layer abort requested I/O has been "
  4359. "completed by LLD.\n");
  4360. goto out_unlock;
  4361. }
  4362. BUG_ON(iocb->context1 != lpfc_cmd);
  4363. /* abort issued in recovery is still in progress */
  4364. if (iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
  4365. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4366. "3389 SCSI Layer I/O Abort Request is pending\n");
  4367. spin_unlock_irqrestore(&phba->hbalock, flags);
  4368. goto wait_for_cmpl;
  4369. }
  4370. abtsiocb = __lpfc_sli_get_iocbq(phba);
  4371. if (abtsiocb == NULL) {
  4372. ret = FAILED;
  4373. goto out_unlock;
  4374. }
  4375. /* Indicate the IO is being aborted by the driver. */
  4376. iocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  4377. /*
  4378. * The scsi command can not be in txq and it is in flight because the
  4379. * pCmd is still pointig at the SCSI command we have to abort. There
  4380. * is no need to search the txcmplq. Just send an abort to the FW.
  4381. */
  4382. cmd = &iocb->iocb;
  4383. icmd = &abtsiocb->iocb;
  4384. icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
  4385. icmd->un.acxri.abortContextTag = cmd->ulpContext;
  4386. if (phba->sli_rev == LPFC_SLI_REV4)
  4387. icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
  4388. else
  4389. icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
  4390. icmd->ulpLe = 1;
  4391. icmd->ulpClass = cmd->ulpClass;
  4392. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  4393. abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
  4394. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  4395. if (iocb->iocb_flag & LPFC_IO_FOF)
  4396. abtsiocb->iocb_flag |= LPFC_IO_FOF;
  4397. if (lpfc_is_link_up(phba))
  4398. icmd->ulpCommand = CMD_ABORT_XRI_CN;
  4399. else
  4400. icmd->ulpCommand = CMD_CLOSE_XRI_CN;
  4401. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  4402. abtsiocb->vport = vport;
  4403. if (phba->sli_rev == LPFC_SLI_REV4) {
  4404. ring_number = MAX_SLI3_CONFIGURED_RINGS + iocb->fcp_wqidx;
  4405. pring_s4 = &phba->sli.ring[ring_number];
  4406. /* Note: both hbalock and ring_lock must be set here */
  4407. spin_lock_irqsave(&pring_s4->ring_lock, iflags);
  4408. ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
  4409. abtsiocb, 0);
  4410. spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
  4411. } else {
  4412. ret_val = __lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
  4413. abtsiocb, 0);
  4414. }
  4415. /* no longer need the lock after this point */
  4416. spin_unlock_irqrestore(&phba->hbalock, flags);
  4417. if (ret_val == IOCB_ERROR) {
  4418. lpfc_sli_release_iocbq(phba, abtsiocb);
  4419. ret = FAILED;
  4420. goto out;
  4421. }
  4422. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  4423. lpfc_sli_handle_fast_ring_event(phba,
  4424. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  4425. wait_for_cmpl:
  4426. lpfc_cmd->waitq = &waitq;
  4427. /* Wait for abort to complete */
  4428. wait_event_timeout(waitq,
  4429. (lpfc_cmd->pCmd != cmnd),
  4430. msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000));
  4431. spin_lock_irqsave(shost->host_lock, flags);
  4432. lpfc_cmd->waitq = NULL;
  4433. spin_unlock_irqrestore(shost->host_lock, flags);
  4434. if (lpfc_cmd->pCmd == cmnd) {
  4435. ret = FAILED;
  4436. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4437. "0748 abort handler timed out waiting "
  4438. "for abortng I/O (xri:x%x) to complete: "
  4439. "ret %#x, ID %d, LUN %llu\n",
  4440. iocb->sli4_xritag, ret,
  4441. cmnd->device->id, cmnd->device->lun);
  4442. }
  4443. goto out;
  4444. out_unlock:
  4445. spin_unlock_irqrestore(&phba->hbalock, flags);
  4446. out:
  4447. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  4448. "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
  4449. "LUN %llu\n", ret, cmnd->device->id,
  4450. cmnd->device->lun);
  4451. return ret;
  4452. }
  4453. static char *
  4454. lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
  4455. {
  4456. switch (task_mgmt_cmd) {
  4457. case FCP_ABORT_TASK_SET:
  4458. return "ABORT_TASK_SET";
  4459. case FCP_CLEAR_TASK_SET:
  4460. return "FCP_CLEAR_TASK_SET";
  4461. case FCP_BUS_RESET:
  4462. return "FCP_BUS_RESET";
  4463. case FCP_LUN_RESET:
  4464. return "FCP_LUN_RESET";
  4465. case FCP_TARGET_RESET:
  4466. return "FCP_TARGET_RESET";
  4467. case FCP_CLEAR_ACA:
  4468. return "FCP_CLEAR_ACA";
  4469. case FCP_TERMINATE_TASK:
  4470. return "FCP_TERMINATE_TASK";
  4471. default:
  4472. return "unknown";
  4473. }
  4474. }
  4475. /**
  4476. * lpfc_check_fcp_rsp - check the returned fcp_rsp to see if task failed
  4477. * @vport: The virtual port for which this call is being executed.
  4478. * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
  4479. *
  4480. * This routine checks the FCP RSP INFO to see if the tsk mgmt command succeded
  4481. *
  4482. * Return code :
  4483. * 0x2003 - Error
  4484. * 0x2002 - Success
  4485. **/
  4486. static int
  4487. lpfc_check_fcp_rsp(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd)
  4488. {
  4489. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  4490. uint32_t rsp_info;
  4491. uint32_t rsp_len;
  4492. uint8_t rsp_info_code;
  4493. int ret = FAILED;
  4494. if (fcprsp == NULL)
  4495. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4496. "0703 fcp_rsp is missing\n");
  4497. else {
  4498. rsp_info = fcprsp->rspStatus2;
  4499. rsp_len = be32_to_cpu(fcprsp->rspRspLen);
  4500. rsp_info_code = fcprsp->rspInfo3;
  4501. lpfc_printf_vlog(vport, KERN_INFO,
  4502. LOG_FCP,
  4503. "0706 fcp_rsp valid 0x%x,"
  4504. " rsp len=%d code 0x%x\n",
  4505. rsp_info,
  4506. rsp_len, rsp_info_code);
  4507. if ((fcprsp->rspStatus2&RSP_LEN_VALID) && (rsp_len == 8)) {
  4508. switch (rsp_info_code) {
  4509. case RSP_NO_FAILURE:
  4510. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4511. "0715 Task Mgmt No Failure\n");
  4512. ret = SUCCESS;
  4513. break;
  4514. case RSP_TM_NOT_SUPPORTED: /* TM rejected */
  4515. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4516. "0716 Task Mgmt Target "
  4517. "reject\n");
  4518. break;
  4519. case RSP_TM_NOT_COMPLETED: /* TM failed */
  4520. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4521. "0717 Task Mgmt Target "
  4522. "failed TM\n");
  4523. break;
  4524. case RSP_TM_INVALID_LU: /* TM to invalid LU! */
  4525. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4526. "0718 Task Mgmt to invalid "
  4527. "LUN\n");
  4528. break;
  4529. }
  4530. }
  4531. }
  4532. return ret;
  4533. }
  4534. /**
  4535. * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
  4536. * @vport: The virtual port for which this call is being executed.
  4537. * @rdata: Pointer to remote port local data
  4538. * @tgt_id: Target ID of remote device.
  4539. * @lun_id: Lun number for the TMF
  4540. * @task_mgmt_cmd: type of TMF to send
  4541. *
  4542. * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
  4543. * a remote port.
  4544. *
  4545. * Return Code:
  4546. * 0x2003 - Error
  4547. * 0x2002 - Success.
  4548. **/
  4549. static int
  4550. lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
  4551. unsigned tgt_id, uint64_t lun_id,
  4552. uint8_t task_mgmt_cmd)
  4553. {
  4554. struct lpfc_hba *phba = vport->phba;
  4555. struct lpfc_scsi_buf *lpfc_cmd;
  4556. struct lpfc_iocbq *iocbq;
  4557. struct lpfc_iocbq *iocbqrsp;
  4558. struct lpfc_nodelist *pnode = rdata->pnode;
  4559. int ret;
  4560. int status;
  4561. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  4562. return FAILED;
  4563. lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode);
  4564. if (lpfc_cmd == NULL)
  4565. return FAILED;
  4566. lpfc_cmd->timeout = phba->cfg_task_mgmt_tmo;
  4567. lpfc_cmd->rdata = rdata;
  4568. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
  4569. task_mgmt_cmd);
  4570. if (!status) {
  4571. lpfc_release_scsi_buf(phba, lpfc_cmd);
  4572. return FAILED;
  4573. }
  4574. iocbq = &lpfc_cmd->cur_iocbq;
  4575. iocbqrsp = lpfc_sli_get_iocbq(phba);
  4576. if (iocbqrsp == NULL) {
  4577. lpfc_release_scsi_buf(phba, lpfc_cmd);
  4578. return FAILED;
  4579. }
  4580. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  4581. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4582. "0702 Issue %s to TGT %d LUN %llu "
  4583. "rpi x%x nlp_flag x%x Data: x%x x%x\n",
  4584. lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
  4585. pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
  4586. iocbq->iocb_flag);
  4587. status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
  4588. iocbq, iocbqrsp, lpfc_cmd->timeout);
  4589. if ((status != IOCB_SUCCESS) ||
  4590. (iocbqrsp->iocb.ulpStatus != IOSTAT_SUCCESS)) {
  4591. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4592. "0727 TMF %s to TGT %d LUN %llu failed (%d, %d) "
  4593. "iocb_flag x%x\n",
  4594. lpfc_taskmgmt_name(task_mgmt_cmd),
  4595. tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
  4596. iocbqrsp->iocb.un.ulpWord[4],
  4597. iocbq->iocb_flag);
  4598. /* if ulpStatus != IOCB_SUCCESS, then status == IOCB_SUCCESS */
  4599. if (status == IOCB_SUCCESS) {
  4600. if (iocbqrsp->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  4601. /* Something in the FCP_RSP was invalid.
  4602. * Check conditions */
  4603. ret = lpfc_check_fcp_rsp(vport, lpfc_cmd);
  4604. else
  4605. ret = FAILED;
  4606. } else if (status == IOCB_TIMEDOUT) {
  4607. ret = TIMEOUT_ERROR;
  4608. } else {
  4609. ret = FAILED;
  4610. }
  4611. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  4612. } else
  4613. ret = SUCCESS;
  4614. lpfc_sli_release_iocbq(phba, iocbqrsp);
  4615. if (ret != TIMEOUT_ERROR)
  4616. lpfc_release_scsi_buf(phba, lpfc_cmd);
  4617. return ret;
  4618. }
  4619. /**
  4620. * lpfc_chk_tgt_mapped -
  4621. * @vport: The virtual port to check on
  4622. * @cmnd: Pointer to scsi_cmnd data structure.
  4623. *
  4624. * This routine delays until the scsi target (aka rport) for the
  4625. * command exists (is present and logged in) or we declare it non-existent.
  4626. *
  4627. * Return code :
  4628. * 0x2003 - Error
  4629. * 0x2002 - Success
  4630. **/
  4631. static int
  4632. lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
  4633. {
  4634. struct lpfc_rport_data *rdata;
  4635. struct lpfc_nodelist *pnode;
  4636. unsigned long later;
  4637. rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
  4638. if (!rdata) {
  4639. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  4640. "0797 Tgt Map rport failure: rdata x%p\n", rdata);
  4641. return FAILED;
  4642. }
  4643. pnode = rdata->pnode;
  4644. /*
  4645. * If target is not in a MAPPED state, delay until
  4646. * target is rediscovered or devloss timeout expires.
  4647. */
  4648. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  4649. while (time_after(later, jiffies)) {
  4650. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  4651. return FAILED;
  4652. if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
  4653. return SUCCESS;
  4654. schedule_timeout_uninterruptible(msecs_to_jiffies(500));
  4655. rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
  4656. if (!rdata)
  4657. return FAILED;
  4658. pnode = rdata->pnode;
  4659. }
  4660. if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
  4661. (pnode->nlp_state != NLP_STE_MAPPED_NODE))
  4662. return FAILED;
  4663. return SUCCESS;
  4664. }
  4665. /**
  4666. * lpfc_reset_flush_io_context -
  4667. * @vport: The virtual port (scsi_host) for the flush context
  4668. * @tgt_id: If aborting by Target contect - specifies the target id
  4669. * @lun_id: If aborting by Lun context - specifies the lun id
  4670. * @context: specifies the context level to flush at.
  4671. *
  4672. * After a reset condition via TMF, we need to flush orphaned i/o
  4673. * contexts from the adapter. This routine aborts any contexts
  4674. * outstanding, then waits for their completions. The wait is
  4675. * bounded by devloss_tmo though.
  4676. *
  4677. * Return code :
  4678. * 0x2003 - Error
  4679. * 0x2002 - Success
  4680. **/
  4681. static int
  4682. lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
  4683. uint64_t lun_id, lpfc_ctx_cmd context)
  4684. {
  4685. struct lpfc_hba *phba = vport->phba;
  4686. unsigned long later;
  4687. int cnt;
  4688. cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
  4689. if (cnt)
  4690. lpfc_sli_abort_taskmgmt(vport,
  4691. &phba->sli.ring[phba->sli.fcp_ring],
  4692. tgt_id, lun_id, context);
  4693. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  4694. while (time_after(later, jiffies) && cnt) {
  4695. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  4696. cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
  4697. }
  4698. if (cnt) {
  4699. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4700. "0724 I/O flush failure for context %s : cnt x%x\n",
  4701. ((context == LPFC_CTX_LUN) ? "LUN" :
  4702. ((context == LPFC_CTX_TGT) ? "TGT" :
  4703. ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
  4704. cnt);
  4705. return FAILED;
  4706. }
  4707. return SUCCESS;
  4708. }
  4709. /**
  4710. * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
  4711. * @cmnd: Pointer to scsi_cmnd data structure.
  4712. *
  4713. * This routine does a device reset by sending a LUN_RESET task management
  4714. * command.
  4715. *
  4716. * Return code :
  4717. * 0x2003 - Error
  4718. * 0x2002 - Success
  4719. **/
  4720. static int
  4721. lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
  4722. {
  4723. struct Scsi_Host *shost = cmnd->device->host;
  4724. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4725. struct lpfc_rport_data *rdata;
  4726. struct lpfc_nodelist *pnode;
  4727. unsigned tgt_id = cmnd->device->id;
  4728. uint64_t lun_id = cmnd->device->lun;
  4729. struct lpfc_scsi_event_header scsi_event;
  4730. int status;
  4731. rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
  4732. if (!rdata) {
  4733. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4734. "0798 Device Reset rport failure: rdata x%p\n", rdata);
  4735. return FAILED;
  4736. }
  4737. pnode = rdata->pnode;
  4738. status = fc_block_scsi_eh(cmnd);
  4739. if (status != 0 && status != SUCCESS)
  4740. return status;
  4741. status = lpfc_chk_tgt_mapped(vport, cmnd);
  4742. if (status == FAILED) {
  4743. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4744. "0721 Device Reset rport failure: rdata x%p\n", rdata);
  4745. return FAILED;
  4746. }
  4747. scsi_event.event_type = FC_REG_SCSI_EVENT;
  4748. scsi_event.subcategory = LPFC_EVENT_LUNRESET;
  4749. scsi_event.lun = lun_id;
  4750. memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
  4751. memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
  4752. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4753. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  4754. status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
  4755. FCP_LUN_RESET);
  4756. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4757. "0713 SCSI layer issued Device Reset (%d, %llu) "
  4758. "return x%x\n", tgt_id, lun_id, status);
  4759. /*
  4760. * We have to clean up i/o as : they may be orphaned by the TMF;
  4761. * or if the TMF failed, they may be in an indeterminate state.
  4762. * So, continue on.
  4763. * We will report success if all the i/o aborts successfully.
  4764. */
  4765. if (status == SUCCESS)
  4766. status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
  4767. LPFC_CTX_LUN);
  4768. return status;
  4769. }
  4770. /**
  4771. * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
  4772. * @cmnd: Pointer to scsi_cmnd data structure.
  4773. *
  4774. * This routine does a target reset by sending a TARGET_RESET task management
  4775. * command.
  4776. *
  4777. * Return code :
  4778. * 0x2003 - Error
  4779. * 0x2002 - Success
  4780. **/
  4781. static int
  4782. lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
  4783. {
  4784. struct Scsi_Host *shost = cmnd->device->host;
  4785. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4786. struct lpfc_rport_data *rdata;
  4787. struct lpfc_nodelist *pnode;
  4788. unsigned tgt_id = cmnd->device->id;
  4789. uint64_t lun_id = cmnd->device->lun;
  4790. struct lpfc_scsi_event_header scsi_event;
  4791. int status;
  4792. rdata = lpfc_rport_data_from_scsi_device(cmnd->device);
  4793. if (!rdata) {
  4794. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4795. "0799 Target Reset rport failure: rdata x%p\n", rdata);
  4796. return FAILED;
  4797. }
  4798. pnode = rdata->pnode;
  4799. status = fc_block_scsi_eh(cmnd);
  4800. if (status != 0 && status != SUCCESS)
  4801. return status;
  4802. status = lpfc_chk_tgt_mapped(vport, cmnd);
  4803. if (status == FAILED) {
  4804. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4805. "0722 Target Reset rport failure: rdata x%p\n", rdata);
  4806. spin_lock_irq(shost->host_lock);
  4807. pnode->nlp_flag &= ~NLP_NPR_ADISC;
  4808. pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  4809. spin_unlock_irq(shost->host_lock);
  4810. lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
  4811. LPFC_CTX_TGT);
  4812. return FAST_IO_FAIL;
  4813. }
  4814. scsi_event.event_type = FC_REG_SCSI_EVENT;
  4815. scsi_event.subcategory = LPFC_EVENT_TGTRESET;
  4816. scsi_event.lun = 0;
  4817. memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
  4818. memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
  4819. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4820. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  4821. status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
  4822. FCP_TARGET_RESET);
  4823. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4824. "0723 SCSI layer issued Target Reset (%d, %llu) "
  4825. "return x%x\n", tgt_id, lun_id, status);
  4826. /*
  4827. * We have to clean up i/o as : they may be orphaned by the TMF;
  4828. * or if the TMF failed, they may be in an indeterminate state.
  4829. * So, continue on.
  4830. * We will report success if all the i/o aborts successfully.
  4831. */
  4832. if (status == SUCCESS)
  4833. status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
  4834. LPFC_CTX_TGT);
  4835. return status;
  4836. }
  4837. /**
  4838. * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
  4839. * @cmnd: Pointer to scsi_cmnd data structure.
  4840. *
  4841. * This routine does target reset to all targets on @cmnd->device->host.
  4842. * This emulates Parallel SCSI Bus Reset Semantics.
  4843. *
  4844. * Return code :
  4845. * 0x2003 - Error
  4846. * 0x2002 - Success
  4847. **/
  4848. static int
  4849. lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
  4850. {
  4851. struct Scsi_Host *shost = cmnd->device->host;
  4852. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4853. struct lpfc_nodelist *ndlp = NULL;
  4854. struct lpfc_scsi_event_header scsi_event;
  4855. int match;
  4856. int ret = SUCCESS, status, i;
  4857. scsi_event.event_type = FC_REG_SCSI_EVENT;
  4858. scsi_event.subcategory = LPFC_EVENT_BUSRESET;
  4859. scsi_event.lun = 0;
  4860. memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
  4861. memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
  4862. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4863. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  4864. status = fc_block_scsi_eh(cmnd);
  4865. if (status != 0 && status != SUCCESS)
  4866. return status;
  4867. /*
  4868. * Since the driver manages a single bus device, reset all
  4869. * targets known to the driver. Should any target reset
  4870. * fail, this routine returns failure to the midlayer.
  4871. */
  4872. for (i = 0; i < LPFC_MAX_TARGET; i++) {
  4873. /* Search for mapped node by target ID */
  4874. match = 0;
  4875. spin_lock_irq(shost->host_lock);
  4876. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4877. if (!NLP_CHK_NODE_ACT(ndlp))
  4878. continue;
  4879. if (vport->phba->cfg_fcp2_no_tgt_reset &&
  4880. (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
  4881. continue;
  4882. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  4883. ndlp->nlp_sid == i &&
  4884. ndlp->rport) {
  4885. match = 1;
  4886. break;
  4887. }
  4888. }
  4889. spin_unlock_irq(shost->host_lock);
  4890. if (!match)
  4891. continue;
  4892. status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
  4893. i, 0, FCP_TARGET_RESET);
  4894. if (status != SUCCESS) {
  4895. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4896. "0700 Bus Reset on target %d failed\n",
  4897. i);
  4898. ret = FAILED;
  4899. }
  4900. }
  4901. /*
  4902. * We have to clean up i/o as : they may be orphaned by the TMFs
  4903. * above; or if any of the TMFs failed, they may be in an
  4904. * indeterminate state.
  4905. * We will report success if all the i/o aborts successfully.
  4906. */
  4907. status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
  4908. if (status != SUCCESS)
  4909. ret = FAILED;
  4910. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4911. "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
  4912. return ret;
  4913. }
  4914. /**
  4915. * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt
  4916. * @cmnd: Pointer to scsi_cmnd data structure.
  4917. *
  4918. * This routine does host reset to the adaptor port. It brings the HBA
  4919. * offline, performs a board restart, and then brings the board back online.
  4920. * The lpfc_offline calls lpfc_sli_hba_down which will abort and local
  4921. * reject all outstanding SCSI commands to the host and error returned
  4922. * back to SCSI mid-level. As this will be SCSI mid-level's last resort
  4923. * of error handling, it will only return error if resetting of the adapter
  4924. * is not successful; in all other cases, will return success.
  4925. *
  4926. * Return code :
  4927. * 0x2003 - Error
  4928. * 0x2002 - Success
  4929. **/
  4930. static int
  4931. lpfc_host_reset_handler(struct scsi_cmnd *cmnd)
  4932. {
  4933. struct Scsi_Host *shost = cmnd->device->host;
  4934. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4935. struct lpfc_hba *phba = vport->phba;
  4936. int rc, ret = SUCCESS;
  4937. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4938. "3172 SCSI layer issued Host Reset Data:\n");
  4939. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  4940. lpfc_offline(phba);
  4941. rc = lpfc_sli_brdrestart(phba);
  4942. if (rc)
  4943. ret = FAILED;
  4944. rc = lpfc_online(phba);
  4945. if (rc)
  4946. ret = FAILED;
  4947. lpfc_unblock_mgmt_io(phba);
  4948. if (ret == FAILED) {
  4949. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  4950. "3323 Failed host reset, bring it offline\n");
  4951. lpfc_sli4_offline_eratt(phba);
  4952. }
  4953. return ret;
  4954. }
  4955. /**
  4956. * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
  4957. * @sdev: Pointer to scsi_device.
  4958. *
  4959. * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
  4960. * globally available list of scsi buffers. This routine also makes sure scsi
  4961. * buffer is not allocated more than HBA limit conveyed to midlayer. This list
  4962. * of scsi buffer exists for the lifetime of the driver.
  4963. *
  4964. * Return codes:
  4965. * non-0 - Error
  4966. * 0 - Success
  4967. **/
  4968. static int
  4969. lpfc_slave_alloc(struct scsi_device *sdev)
  4970. {
  4971. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  4972. struct lpfc_hba *phba = vport->phba;
  4973. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  4974. uint32_t total = 0;
  4975. uint32_t num_to_alloc = 0;
  4976. int num_allocated = 0;
  4977. uint32_t sdev_cnt;
  4978. struct lpfc_device_data *device_data;
  4979. unsigned long flags;
  4980. struct lpfc_name target_wwpn;
  4981. if (!rport || fc_remote_port_chkready(rport))
  4982. return -ENXIO;
  4983. if (phba->cfg_fof) {
  4984. /*
  4985. * Check to see if the device data structure for the lun
  4986. * exists. If not, create one.
  4987. */
  4988. u64_to_wwn(rport->port_name, target_wwpn.u.wwn);
  4989. spin_lock_irqsave(&phba->devicelock, flags);
  4990. device_data = __lpfc_get_device_data(phba,
  4991. &phba->luns,
  4992. &vport->fc_portname,
  4993. &target_wwpn,
  4994. sdev->lun);
  4995. if (!device_data) {
  4996. spin_unlock_irqrestore(&phba->devicelock, flags);
  4997. device_data = lpfc_create_device_data(phba,
  4998. &vport->fc_portname,
  4999. &target_wwpn,
  5000. sdev->lun, true);
  5001. if (!device_data)
  5002. return -ENOMEM;
  5003. spin_lock_irqsave(&phba->devicelock, flags);
  5004. list_add_tail(&device_data->listentry, &phba->luns);
  5005. }
  5006. device_data->rport_data = rport->dd_data;
  5007. device_data->available = true;
  5008. spin_unlock_irqrestore(&phba->devicelock, flags);
  5009. sdev->hostdata = device_data;
  5010. } else {
  5011. sdev->hostdata = rport->dd_data;
  5012. }
  5013. sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
  5014. /*
  5015. * Populate the cmds_per_lun count scsi_bufs into this host's globally
  5016. * available list of scsi buffers. Don't allocate more than the
  5017. * HBA limit conveyed to the midlayer via the host structure. The
  5018. * formula accounts for the lun_queue_depth + error handlers + 1
  5019. * extra. This list of scsi bufs exists for the lifetime of the driver.
  5020. */
  5021. total = phba->total_scsi_bufs;
  5022. num_to_alloc = vport->cfg_lun_queue_depth + 2;
  5023. /* If allocated buffers are enough do nothing */
  5024. if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
  5025. return 0;
  5026. /* Allow some exchanges to be available always to complete discovery */
  5027. if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  5028. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  5029. "0704 At limitation of %d preallocated "
  5030. "command buffers\n", total);
  5031. return 0;
  5032. /* Allow some exchanges to be available always to complete discovery */
  5033. } else if (total + num_to_alloc >
  5034. phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  5035. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  5036. "0705 Allocation request of %d "
  5037. "command buffers will exceed max of %d. "
  5038. "Reducing allocation request to %d.\n",
  5039. num_to_alloc, phba->cfg_hba_queue_depth,
  5040. (phba->cfg_hba_queue_depth - total));
  5041. num_to_alloc = phba->cfg_hba_queue_depth - total;
  5042. }
  5043. num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
  5044. if (num_to_alloc != num_allocated) {
  5045. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  5046. "0708 Allocation request of %d "
  5047. "command buffers did not succeed. "
  5048. "Allocated %d buffers.\n",
  5049. num_to_alloc, num_allocated);
  5050. }
  5051. if (num_allocated > 0)
  5052. phba->total_scsi_bufs += num_allocated;
  5053. return 0;
  5054. }
  5055. /**
  5056. * lpfc_slave_configure - scsi_host_template slave_configure entry point
  5057. * @sdev: Pointer to scsi_device.
  5058. *
  5059. * This routine configures following items
  5060. * - Tag command queuing support for @sdev if supported.
  5061. * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
  5062. *
  5063. * Return codes:
  5064. * 0 - Success
  5065. **/
  5066. static int
  5067. lpfc_slave_configure(struct scsi_device *sdev)
  5068. {
  5069. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  5070. struct lpfc_hba *phba = vport->phba;
  5071. if (sdev->tagged_supported)
  5072. scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
  5073. else
  5074. scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
  5075. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  5076. lpfc_sli_handle_fast_ring_event(phba,
  5077. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  5078. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  5079. lpfc_poll_rearm_timer(phba);
  5080. }
  5081. return 0;
  5082. }
  5083. /**
  5084. * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
  5085. * @sdev: Pointer to scsi_device.
  5086. *
  5087. * This routine sets @sdev hostatdata filed to null.
  5088. **/
  5089. static void
  5090. lpfc_slave_destroy(struct scsi_device *sdev)
  5091. {
  5092. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  5093. struct lpfc_hba *phba = vport->phba;
  5094. unsigned long flags;
  5095. struct lpfc_device_data *device_data = sdev->hostdata;
  5096. atomic_dec(&phba->sdev_cnt);
  5097. if ((phba->cfg_fof) && (device_data)) {
  5098. spin_lock_irqsave(&phba->devicelock, flags);
  5099. device_data->available = false;
  5100. if (!device_data->oas_enabled)
  5101. lpfc_delete_device_data(phba, device_data);
  5102. spin_unlock_irqrestore(&phba->devicelock, flags);
  5103. }
  5104. sdev->hostdata = NULL;
  5105. return;
  5106. }
  5107. /**
  5108. * lpfc_create_device_data - creates and initializes device data structure for OAS
  5109. * @pha: Pointer to host bus adapter structure.
  5110. * @vport_wwpn: Pointer to vport's wwpn information
  5111. * @target_wwpn: Pointer to target's wwpn information
  5112. * @lun: Lun on target
  5113. * @atomic_create: Flag to indicate if memory should be allocated using the
  5114. * GFP_ATOMIC flag or not.
  5115. *
  5116. * This routine creates a device data structure which will contain identifying
  5117. * information for the device (host wwpn, target wwpn, lun), state of OAS,
  5118. * whether or not the corresponding lun is available by the system,
  5119. * and pointer to the rport data.
  5120. *
  5121. * Return codes:
  5122. * NULL - Error
  5123. * Pointer to lpfc_device_data - Success
  5124. **/
  5125. struct lpfc_device_data*
  5126. lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
  5127. struct lpfc_name *target_wwpn, uint64_t lun,
  5128. bool atomic_create)
  5129. {
  5130. struct lpfc_device_data *lun_info;
  5131. int memory_flags;
  5132. if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
  5133. !(phba->cfg_fof))
  5134. return NULL;
  5135. /* Attempt to create the device data to contain lun info */
  5136. if (atomic_create)
  5137. memory_flags = GFP_ATOMIC;
  5138. else
  5139. memory_flags = GFP_KERNEL;
  5140. lun_info = mempool_alloc(phba->device_data_mem_pool, memory_flags);
  5141. if (!lun_info)
  5142. return NULL;
  5143. INIT_LIST_HEAD(&lun_info->listentry);
  5144. lun_info->rport_data = NULL;
  5145. memcpy(&lun_info->device_id.vport_wwpn, vport_wwpn,
  5146. sizeof(struct lpfc_name));
  5147. memcpy(&lun_info->device_id.target_wwpn, target_wwpn,
  5148. sizeof(struct lpfc_name));
  5149. lun_info->device_id.lun = lun;
  5150. lun_info->oas_enabled = false;
  5151. lun_info->available = false;
  5152. return lun_info;
  5153. }
  5154. /**
  5155. * lpfc_delete_device_data - frees a device data structure for OAS
  5156. * @pha: Pointer to host bus adapter structure.
  5157. * @lun_info: Pointer to device data structure to free.
  5158. *
  5159. * This routine frees the previously allocated device data structure passed.
  5160. *
  5161. **/
  5162. void
  5163. lpfc_delete_device_data(struct lpfc_hba *phba,
  5164. struct lpfc_device_data *lun_info)
  5165. {
  5166. if (unlikely(!phba) || !lun_info ||
  5167. !(phba->cfg_fof))
  5168. return;
  5169. if (!list_empty(&lun_info->listentry))
  5170. list_del(&lun_info->listentry);
  5171. mempool_free(lun_info, phba->device_data_mem_pool);
  5172. return;
  5173. }
  5174. /**
  5175. * __lpfc_get_device_data - returns the device data for the specified lun
  5176. * @pha: Pointer to host bus adapter structure.
  5177. * @list: Point to list to search.
  5178. * @vport_wwpn: Pointer to vport's wwpn information
  5179. * @target_wwpn: Pointer to target's wwpn information
  5180. * @lun: Lun on target
  5181. *
  5182. * This routine searches the list passed for the specified lun's device data.
  5183. * This function does not hold locks, it is the responsibility of the caller
  5184. * to ensure the proper lock is held before calling the function.
  5185. *
  5186. * Return codes:
  5187. * NULL - Error
  5188. * Pointer to lpfc_device_data - Success
  5189. **/
  5190. struct lpfc_device_data*
  5191. __lpfc_get_device_data(struct lpfc_hba *phba, struct list_head *list,
  5192. struct lpfc_name *vport_wwpn,
  5193. struct lpfc_name *target_wwpn, uint64_t lun)
  5194. {
  5195. struct lpfc_device_data *lun_info;
  5196. if (unlikely(!phba) || !list || !vport_wwpn || !target_wwpn ||
  5197. !phba->cfg_fof)
  5198. return NULL;
  5199. /* Check to see if the lun is already enabled for OAS. */
  5200. list_for_each_entry(lun_info, list, listentry) {
  5201. if ((memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
  5202. sizeof(struct lpfc_name)) == 0) &&
  5203. (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
  5204. sizeof(struct lpfc_name)) == 0) &&
  5205. (lun_info->device_id.lun == lun))
  5206. return lun_info;
  5207. }
  5208. return NULL;
  5209. }
  5210. /**
  5211. * lpfc_find_next_oas_lun - searches for the next oas lun
  5212. * @pha: Pointer to host bus adapter structure.
  5213. * @vport_wwpn: Pointer to vport's wwpn information
  5214. * @target_wwpn: Pointer to target's wwpn information
  5215. * @starting_lun: Pointer to the lun to start searching for
  5216. * @found_vport_wwpn: Pointer to the found lun's vport wwpn information
  5217. * @found_target_wwpn: Pointer to the found lun's target wwpn information
  5218. * @found_lun: Pointer to the found lun.
  5219. * @found_lun_status: Pointer to status of the found lun.
  5220. *
  5221. * This routine searches the luns list for the specified lun
  5222. * or the first lun for the vport/target. If the vport wwpn contains
  5223. * a zero value then a specific vport is not specified. In this case
  5224. * any vport which contains the lun will be considered a match. If the
  5225. * target wwpn contains a zero value then a specific target is not specified.
  5226. * In this case any target which contains the lun will be considered a
  5227. * match. If the lun is found, the lun, vport wwpn, target wwpn and lun status
  5228. * are returned. The function will also return the next lun if available.
  5229. * If the next lun is not found, starting_lun parameter will be set to
  5230. * NO_MORE_OAS_LUN.
  5231. *
  5232. * Return codes:
  5233. * non-0 - Error
  5234. * 0 - Success
  5235. **/
  5236. bool
  5237. lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
  5238. struct lpfc_name *target_wwpn, uint64_t *starting_lun,
  5239. struct lpfc_name *found_vport_wwpn,
  5240. struct lpfc_name *found_target_wwpn,
  5241. uint64_t *found_lun,
  5242. uint32_t *found_lun_status)
  5243. {
  5244. unsigned long flags;
  5245. struct lpfc_device_data *lun_info;
  5246. struct lpfc_device_id *device_id;
  5247. uint64_t lun;
  5248. bool found = false;
  5249. if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
  5250. !starting_lun || !found_vport_wwpn ||
  5251. !found_target_wwpn || !found_lun || !found_lun_status ||
  5252. (*starting_lun == NO_MORE_OAS_LUN) ||
  5253. !phba->cfg_fof)
  5254. return false;
  5255. lun = *starting_lun;
  5256. *found_lun = NO_MORE_OAS_LUN;
  5257. *starting_lun = NO_MORE_OAS_LUN;
  5258. /* Search for lun or the lun closet in value */
  5259. spin_lock_irqsave(&phba->devicelock, flags);
  5260. list_for_each_entry(lun_info, &phba->luns, listentry) {
  5261. if (((wwn_to_u64(vport_wwpn->u.wwn) == 0) ||
  5262. (memcmp(&lun_info->device_id.vport_wwpn, vport_wwpn,
  5263. sizeof(struct lpfc_name)) == 0)) &&
  5264. ((wwn_to_u64(target_wwpn->u.wwn) == 0) ||
  5265. (memcmp(&lun_info->device_id.target_wwpn, target_wwpn,
  5266. sizeof(struct lpfc_name)) == 0)) &&
  5267. (lun_info->oas_enabled)) {
  5268. device_id = &lun_info->device_id;
  5269. if ((!found) &&
  5270. ((lun == FIND_FIRST_OAS_LUN) ||
  5271. (device_id->lun == lun))) {
  5272. *found_lun = device_id->lun;
  5273. memcpy(found_vport_wwpn,
  5274. &device_id->vport_wwpn,
  5275. sizeof(struct lpfc_name));
  5276. memcpy(found_target_wwpn,
  5277. &device_id->target_wwpn,
  5278. sizeof(struct lpfc_name));
  5279. if (lun_info->available)
  5280. *found_lun_status =
  5281. OAS_LUN_STATUS_EXISTS;
  5282. else
  5283. *found_lun_status = 0;
  5284. if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
  5285. memset(vport_wwpn, 0x0,
  5286. sizeof(struct lpfc_name));
  5287. if (phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)
  5288. memset(target_wwpn, 0x0,
  5289. sizeof(struct lpfc_name));
  5290. found = true;
  5291. } else if (found) {
  5292. *starting_lun = device_id->lun;
  5293. memcpy(vport_wwpn, &device_id->vport_wwpn,
  5294. sizeof(struct lpfc_name));
  5295. memcpy(target_wwpn, &device_id->target_wwpn,
  5296. sizeof(struct lpfc_name));
  5297. break;
  5298. }
  5299. }
  5300. }
  5301. spin_unlock_irqrestore(&phba->devicelock, flags);
  5302. return found;
  5303. }
  5304. /**
  5305. * lpfc_enable_oas_lun - enables a lun for OAS operations
  5306. * @pha: Pointer to host bus adapter structure.
  5307. * @vport_wwpn: Pointer to vport's wwpn information
  5308. * @target_wwpn: Pointer to target's wwpn information
  5309. * @lun: Lun
  5310. *
  5311. * This routine enables a lun for oas operations. The routines does so by
  5312. * doing the following :
  5313. *
  5314. * 1) Checks to see if the device data for the lun has been created.
  5315. * 2) If found, sets the OAS enabled flag if not set and returns.
  5316. * 3) Otherwise, creates a device data structure.
  5317. * 4) If successfully created, indicates the device data is for an OAS lun,
  5318. * indicates the lun is not available and add to the list of luns.
  5319. *
  5320. * Return codes:
  5321. * false - Error
  5322. * true - Success
  5323. **/
  5324. bool
  5325. lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
  5326. struct lpfc_name *target_wwpn, uint64_t lun)
  5327. {
  5328. struct lpfc_device_data *lun_info;
  5329. unsigned long flags;
  5330. if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
  5331. !phba->cfg_fof)
  5332. return false;
  5333. spin_lock_irqsave(&phba->devicelock, flags);
  5334. /* Check to see if the device data for the lun has been created */
  5335. lun_info = __lpfc_get_device_data(phba, &phba->luns, vport_wwpn,
  5336. target_wwpn, lun);
  5337. if (lun_info) {
  5338. if (!lun_info->oas_enabled)
  5339. lun_info->oas_enabled = true;
  5340. spin_unlock_irqrestore(&phba->devicelock, flags);
  5341. return true;
  5342. }
  5343. /* Create an lun info structure and add to list of luns */
  5344. lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
  5345. false);
  5346. if (lun_info) {
  5347. lun_info->oas_enabled = true;
  5348. lun_info->available = false;
  5349. list_add_tail(&lun_info->listentry, &phba->luns);
  5350. spin_unlock_irqrestore(&phba->devicelock, flags);
  5351. return true;
  5352. }
  5353. spin_unlock_irqrestore(&phba->devicelock, flags);
  5354. return false;
  5355. }
  5356. /**
  5357. * lpfc_disable_oas_lun - disables a lun for OAS operations
  5358. * @pha: Pointer to host bus adapter structure.
  5359. * @vport_wwpn: Pointer to vport's wwpn information
  5360. * @target_wwpn: Pointer to target's wwpn information
  5361. * @lun: Lun
  5362. *
  5363. * This routine disables a lun for oas operations. The routines does so by
  5364. * doing the following :
  5365. *
  5366. * 1) Checks to see if the device data for the lun is created.
  5367. * 2) If present, clears the flag indicating this lun is for OAS.
  5368. * 3) If the lun is not available by the system, the device data is
  5369. * freed.
  5370. *
  5371. * Return codes:
  5372. * false - Error
  5373. * true - Success
  5374. **/
  5375. bool
  5376. lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
  5377. struct lpfc_name *target_wwpn, uint64_t lun)
  5378. {
  5379. struct lpfc_device_data *lun_info;
  5380. unsigned long flags;
  5381. if (unlikely(!phba) || !vport_wwpn || !target_wwpn ||
  5382. !phba->cfg_fof)
  5383. return false;
  5384. spin_lock_irqsave(&phba->devicelock, flags);
  5385. /* Check to see if the lun is available. */
  5386. lun_info = __lpfc_get_device_data(phba,
  5387. &phba->luns, vport_wwpn,
  5388. target_wwpn, lun);
  5389. if (lun_info) {
  5390. lun_info->oas_enabled = false;
  5391. if (!lun_info->available)
  5392. lpfc_delete_device_data(phba, lun_info);
  5393. spin_unlock_irqrestore(&phba->devicelock, flags);
  5394. return true;
  5395. }
  5396. spin_unlock_irqrestore(&phba->devicelock, flags);
  5397. return false;
  5398. }
  5399. struct scsi_host_template lpfc_template = {
  5400. .module = THIS_MODULE,
  5401. .name = LPFC_DRIVER_NAME,
  5402. .info = lpfc_info,
  5403. .queuecommand = lpfc_queuecommand,
  5404. .eh_abort_handler = lpfc_abort_handler,
  5405. .eh_device_reset_handler = lpfc_device_reset_handler,
  5406. .eh_target_reset_handler = lpfc_target_reset_handler,
  5407. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  5408. .eh_host_reset_handler = lpfc_host_reset_handler,
  5409. .slave_alloc = lpfc_slave_alloc,
  5410. .slave_configure = lpfc_slave_configure,
  5411. .slave_destroy = lpfc_slave_destroy,
  5412. .scan_finished = lpfc_scan_finished,
  5413. .this_id = -1,
  5414. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  5415. .cmd_per_lun = LPFC_CMD_PER_LUN,
  5416. .use_clustering = ENABLE_CLUSTERING,
  5417. .shost_attrs = lpfc_hba_attrs,
  5418. .max_sectors = 0xFFFF,
  5419. .vendor_id = LPFC_NL_VENDOR_ID,
  5420. .change_queue_depth = lpfc_change_queue_depth,
  5421. .change_queue_type = lpfc_change_queue_type,
  5422. };
  5423. struct scsi_host_template lpfc_vport_template = {
  5424. .module = THIS_MODULE,
  5425. .name = LPFC_DRIVER_NAME,
  5426. .info = lpfc_info,
  5427. .queuecommand = lpfc_queuecommand,
  5428. .eh_abort_handler = lpfc_abort_handler,
  5429. .eh_device_reset_handler = lpfc_device_reset_handler,
  5430. .eh_target_reset_handler = lpfc_target_reset_handler,
  5431. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  5432. .slave_alloc = lpfc_slave_alloc,
  5433. .slave_configure = lpfc_slave_configure,
  5434. .slave_destroy = lpfc_slave_destroy,
  5435. .scan_finished = lpfc_scan_finished,
  5436. .this_id = -1,
  5437. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  5438. .cmd_per_lun = LPFC_CMD_PER_LUN,
  5439. .use_clustering = ENABLE_CLUSTERING,
  5440. .shost_attrs = lpfc_vport_attrs,
  5441. .max_sectors = 0xFFFF,
  5442. .change_queue_depth = lpfc_change_queue_depth,
  5443. .change_queue_type = lpfc_change_queue_type,
  5444. };