mpt3sas_scsih.c 321 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207
  1. /*
  2. * Scsi Host Layer for MPT (Message Passing Technology) based controllers
  3. *
  4. * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
  5. * Copyright (C) 2012-2014 LSI Corporation
  6. * Copyright (C) 2013-2014 Avago Technologies
  7. * (mailto: MPT-FusionLinux.pdl@avagotech.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * NO WARRANTY
  20. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. * solely responsible for determining the appropriateness of using and
  25. * distributing the Program and assumes all risks associated with its
  26. * exercise of rights under this Agreement, including but not limited to
  27. * the risks and costs of program errors, damage to or loss of data,
  28. * programs or equipment, and unavailability or interruption of operations.
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  40. * USA.
  41. */
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/sched.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include <linux/pci-aspm.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/aer.h>
  54. #include <linux/raid_class.h>
  55. #include <asm/unaligned.h>
  56. #include "mpt3sas_base.h"
  57. #define RAID_CHANNEL 1
  58. #define PCIE_CHANNEL 2
  59. /* forward proto's */
  60. static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
  61. struct _sas_node *sas_expander);
  62. static void _firmware_event_work(struct work_struct *work);
  63. static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
  64. struct _sas_device *sas_device);
  65. static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
  66. u8 retry_count, u8 is_pd);
  67. static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
  68. static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
  69. struct _pcie_device *pcie_device);
  70. static void
  71. _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
  72. static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
  73. /* global parameters */
  74. LIST_HEAD(mpt3sas_ioc_list);
  75. /* global ioc lock for list operations */
  76. DEFINE_SPINLOCK(gioc_lock);
  77. MODULE_AUTHOR(MPT3SAS_AUTHOR);
  78. MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
  79. MODULE_LICENSE("GPL");
  80. MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
  81. MODULE_ALIAS("mpt2sas");
  82. /* local parameters */
  83. static u8 scsi_io_cb_idx = -1;
  84. static u8 tm_cb_idx = -1;
  85. static u8 ctl_cb_idx = -1;
  86. static u8 base_cb_idx = -1;
  87. static u8 port_enable_cb_idx = -1;
  88. static u8 transport_cb_idx = -1;
  89. static u8 scsih_cb_idx = -1;
  90. static u8 config_cb_idx = -1;
  91. static int mpt2_ids;
  92. static int mpt3_ids;
  93. static u8 tm_tr_cb_idx = -1 ;
  94. static u8 tm_tr_volume_cb_idx = -1 ;
  95. static u8 tm_sas_control_cb_idx = -1;
  96. /* command line options */
  97. static u32 logging_level;
  98. MODULE_PARM_DESC(logging_level,
  99. " bits for enabling additional logging info (default=0)");
  100. static ushort max_sectors = 0xFFFF;
  101. module_param(max_sectors, ushort, 0);
  102. MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
  103. static int missing_delay[2] = {-1, -1};
  104. module_param_array(missing_delay, int, NULL, 0);
  105. MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
  106. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  107. #define MPT3SAS_MAX_LUN (16895)
  108. static u64 max_lun = MPT3SAS_MAX_LUN;
  109. module_param(max_lun, ullong, 0);
  110. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  111. static ushort hbas_to_enumerate;
  112. module_param(hbas_to_enumerate, ushort, 0);
  113. MODULE_PARM_DESC(hbas_to_enumerate,
  114. " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
  115. 1 - enumerates only SAS 2.0 generation HBAs\n \
  116. 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
  117. /* diag_buffer_enable is bitwise
  118. * bit 0 set = TRACE
  119. * bit 1 set = SNAPSHOT
  120. * bit 2 set = EXTENDED
  121. *
  122. * Either bit can be set, or both
  123. */
  124. static int diag_buffer_enable = -1;
  125. module_param(diag_buffer_enable, int, 0);
  126. MODULE_PARM_DESC(diag_buffer_enable,
  127. " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
  128. static int disable_discovery = -1;
  129. module_param(disable_discovery, int, 0);
  130. MODULE_PARM_DESC(disable_discovery, " disable discovery ");
  131. /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
  132. static int prot_mask = -1;
  133. module_param(prot_mask, int, 0);
  134. MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
  135. /* raid transport support */
  136. static struct raid_template *mpt3sas_raid_template;
  137. static struct raid_template *mpt2sas_raid_template;
  138. /**
  139. * struct sense_info - common structure for obtaining sense keys
  140. * @skey: sense key
  141. * @asc: additional sense code
  142. * @ascq: additional sense code qualifier
  143. */
  144. struct sense_info {
  145. u8 skey;
  146. u8 asc;
  147. u8 ascq;
  148. };
  149. #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
  150. #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
  151. #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
  152. #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
  153. #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
  154. /**
  155. * struct fw_event_work - firmware event struct
  156. * @list: link list framework
  157. * @work: work object (ioc->fault_reset_work_q)
  158. * @ioc: per adapter object
  159. * @device_handle: device handle
  160. * @VF_ID: virtual function id
  161. * @VP_ID: virtual port id
  162. * @ignore: flag meaning this event has been marked to ignore
  163. * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
  164. * @refcount: kref for this event
  165. * @event_data: reply event data payload follows
  166. *
  167. * This object stored on ioc->fw_event_list.
  168. */
  169. struct fw_event_work {
  170. struct list_head list;
  171. struct work_struct work;
  172. struct MPT3SAS_ADAPTER *ioc;
  173. u16 device_handle;
  174. u8 VF_ID;
  175. u8 VP_ID;
  176. u8 ignore;
  177. u16 event;
  178. struct kref refcount;
  179. char event_data[0] __aligned(4);
  180. };
  181. static void fw_event_work_free(struct kref *r)
  182. {
  183. kfree(container_of(r, struct fw_event_work, refcount));
  184. }
  185. static void fw_event_work_get(struct fw_event_work *fw_work)
  186. {
  187. kref_get(&fw_work->refcount);
  188. }
  189. static void fw_event_work_put(struct fw_event_work *fw_work)
  190. {
  191. kref_put(&fw_work->refcount, fw_event_work_free);
  192. }
  193. static struct fw_event_work *alloc_fw_event_work(int len)
  194. {
  195. struct fw_event_work *fw_event;
  196. fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
  197. if (!fw_event)
  198. return NULL;
  199. kref_init(&fw_event->refcount);
  200. return fw_event;
  201. }
  202. /**
  203. * struct _scsi_io_transfer - scsi io transfer
  204. * @handle: sas device handle (assigned by firmware)
  205. * @is_raid: flag set for hidden raid components
  206. * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
  207. * @data_length: data transfer length
  208. * @data_dma: dma pointer to data
  209. * @sense: sense data
  210. * @lun: lun number
  211. * @cdb_length: cdb length
  212. * @cdb: cdb contents
  213. * @timeout: timeout for this command
  214. * @VF_ID: virtual function id
  215. * @VP_ID: virtual port id
  216. * @valid_reply: flag set for reply message
  217. * @sense_length: sense length
  218. * @ioc_status: ioc status
  219. * @scsi_state: scsi state
  220. * @scsi_status: scsi staus
  221. * @log_info: log information
  222. * @transfer_length: data length transfer when there is a reply message
  223. *
  224. * Used for sending internal scsi commands to devices within this module.
  225. * Refer to _scsi_send_scsi_io().
  226. */
  227. struct _scsi_io_transfer {
  228. u16 handle;
  229. u8 is_raid;
  230. enum dma_data_direction dir;
  231. u32 data_length;
  232. dma_addr_t data_dma;
  233. u8 sense[SCSI_SENSE_BUFFERSIZE];
  234. u32 lun;
  235. u8 cdb_length;
  236. u8 cdb[32];
  237. u8 timeout;
  238. u8 VF_ID;
  239. u8 VP_ID;
  240. u8 valid_reply;
  241. /* the following bits are only valid when 'valid_reply = 1' */
  242. u32 sense_length;
  243. u16 ioc_status;
  244. u8 scsi_state;
  245. u8 scsi_status;
  246. u32 log_info;
  247. u32 transfer_length;
  248. };
  249. /**
  250. * _scsih_set_debug_level - global setting of ioc->logging_level.
  251. * @val: ?
  252. * @kp: ?
  253. *
  254. * Note: The logging levels are defined in mpt3sas_debug.h.
  255. */
  256. static int
  257. _scsih_set_debug_level(const char *val, const struct kernel_param *kp)
  258. {
  259. int ret = param_set_int(val, kp);
  260. struct MPT3SAS_ADAPTER *ioc;
  261. if (ret)
  262. return ret;
  263. pr_info("setting logging_level(0x%08x)\n", logging_level);
  264. spin_lock(&gioc_lock);
  265. list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
  266. ioc->logging_level = logging_level;
  267. spin_unlock(&gioc_lock);
  268. return 0;
  269. }
  270. module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
  271. &logging_level, 0644);
  272. /**
  273. * _scsih_srch_boot_sas_address - search based on sas_address
  274. * @sas_address: sas address
  275. * @boot_device: boot device object from bios page 2
  276. *
  277. * Return: 1 when there's a match, 0 means no match.
  278. */
  279. static inline int
  280. _scsih_srch_boot_sas_address(u64 sas_address,
  281. Mpi2BootDeviceSasWwid_t *boot_device)
  282. {
  283. return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
  284. }
  285. /**
  286. * _scsih_srch_boot_device_name - search based on device name
  287. * @device_name: device name specified in INDENTIFY fram
  288. * @boot_device: boot device object from bios page 2
  289. *
  290. * Return: 1 when there's a match, 0 means no match.
  291. */
  292. static inline int
  293. _scsih_srch_boot_device_name(u64 device_name,
  294. Mpi2BootDeviceDeviceName_t *boot_device)
  295. {
  296. return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
  297. }
  298. /**
  299. * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
  300. * @enclosure_logical_id: enclosure logical id
  301. * @slot_number: slot number
  302. * @boot_device: boot device object from bios page 2
  303. *
  304. * Return: 1 when there's a match, 0 means no match.
  305. */
  306. static inline int
  307. _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
  308. Mpi2BootDeviceEnclosureSlot_t *boot_device)
  309. {
  310. return (enclosure_logical_id == le64_to_cpu(boot_device->
  311. EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
  312. SlotNumber)) ? 1 : 0;
  313. }
  314. /**
  315. * _scsih_is_boot_device - search for matching boot device.
  316. * @sas_address: sas address
  317. * @device_name: device name specified in INDENTIFY fram
  318. * @enclosure_logical_id: enclosure logical id
  319. * @slot: slot number
  320. * @form: specifies boot device form
  321. * @boot_device: boot device object from bios page 2
  322. *
  323. * Return: 1 when there's a match, 0 means no match.
  324. */
  325. static int
  326. _scsih_is_boot_device(u64 sas_address, u64 device_name,
  327. u64 enclosure_logical_id, u16 slot, u8 form,
  328. Mpi2BiosPage2BootDevice_t *boot_device)
  329. {
  330. int rc = 0;
  331. switch (form) {
  332. case MPI2_BIOSPAGE2_FORM_SAS_WWID:
  333. if (!sas_address)
  334. break;
  335. rc = _scsih_srch_boot_sas_address(
  336. sas_address, &boot_device->SasWwid);
  337. break;
  338. case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
  339. if (!enclosure_logical_id)
  340. break;
  341. rc = _scsih_srch_boot_encl_slot(
  342. enclosure_logical_id,
  343. slot, &boot_device->EnclosureSlot);
  344. break;
  345. case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
  346. if (!device_name)
  347. break;
  348. rc = _scsih_srch_boot_device_name(
  349. device_name, &boot_device->DeviceName);
  350. break;
  351. case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
  352. break;
  353. }
  354. return rc;
  355. }
  356. /**
  357. * _scsih_get_sas_address - set the sas_address for given device handle
  358. * @ioc: ?
  359. * @handle: device handle
  360. * @sas_address: sas address
  361. *
  362. * Return: 0 success, non-zero when failure
  363. */
  364. static int
  365. _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
  366. u64 *sas_address)
  367. {
  368. Mpi2SasDevicePage0_t sas_device_pg0;
  369. Mpi2ConfigReply_t mpi_reply;
  370. u32 ioc_status;
  371. *sas_address = 0;
  372. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  373. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  374. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
  375. __FILE__, __LINE__, __func__);
  376. return -ENXIO;
  377. }
  378. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  379. if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
  380. /* For HBA, vSES doesn't return HBA SAS address. Instead return
  381. * vSES's sas address.
  382. */
  383. if ((handle <= ioc->sas_hba.num_phys) &&
  384. (!(le32_to_cpu(sas_device_pg0.DeviceInfo) &
  385. MPI2_SAS_DEVICE_INFO_SEP)))
  386. *sas_address = ioc->sas_hba.sas_address;
  387. else
  388. *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  389. return 0;
  390. }
  391. /* we hit this because the given parent handle doesn't exist */
  392. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  393. return -ENXIO;
  394. /* else error case */
  395. pr_err(MPT3SAS_FMT
  396. "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
  397. ioc->name, handle, ioc_status,
  398. __FILE__, __LINE__, __func__);
  399. return -EIO;
  400. }
  401. /**
  402. * _scsih_determine_boot_device - determine boot device.
  403. * @ioc: per adapter object
  404. * @device: sas_device or pcie_device object
  405. * @channel: SAS or PCIe channel
  406. *
  407. * Determines whether this device should be first reported device to
  408. * to scsi-ml or sas transport, this purpose is for persistent boot device.
  409. * There are primary, alternate, and current entries in bios page 2. The order
  410. * priority is primary, alternate, then current. This routine saves
  411. * the corresponding device object.
  412. * The saved data to be used later in _scsih_probe_boot_devices().
  413. */
  414. static void
  415. _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device,
  416. u32 channel)
  417. {
  418. struct _sas_device *sas_device;
  419. struct _pcie_device *pcie_device;
  420. struct _raid_device *raid_device;
  421. u64 sas_address;
  422. u64 device_name;
  423. u64 enclosure_logical_id;
  424. u16 slot;
  425. /* only process this function when driver loads */
  426. if (!ioc->is_driver_loading)
  427. return;
  428. /* no Bios, return immediately */
  429. if (!ioc->bios_pg3.BiosVersion)
  430. return;
  431. if (channel == RAID_CHANNEL) {
  432. raid_device = device;
  433. sas_address = raid_device->wwid;
  434. device_name = 0;
  435. enclosure_logical_id = 0;
  436. slot = 0;
  437. } else if (channel == PCIE_CHANNEL) {
  438. pcie_device = device;
  439. sas_address = pcie_device->wwid;
  440. device_name = 0;
  441. enclosure_logical_id = 0;
  442. slot = 0;
  443. } else {
  444. sas_device = device;
  445. sas_address = sas_device->sas_address;
  446. device_name = sas_device->device_name;
  447. enclosure_logical_id = sas_device->enclosure_logical_id;
  448. slot = sas_device->slot;
  449. }
  450. if (!ioc->req_boot_device.device) {
  451. if (_scsih_is_boot_device(sas_address, device_name,
  452. enclosure_logical_id, slot,
  453. (ioc->bios_pg2.ReqBootDeviceForm &
  454. MPI2_BIOSPAGE2_FORM_MASK),
  455. &ioc->bios_pg2.RequestedBootDevice)) {
  456. dinitprintk(ioc, pr_info(MPT3SAS_FMT
  457. "%s: req_boot_device(0x%016llx)\n",
  458. ioc->name, __func__,
  459. (unsigned long long)sas_address));
  460. ioc->req_boot_device.device = device;
  461. ioc->req_boot_device.channel = channel;
  462. }
  463. }
  464. if (!ioc->req_alt_boot_device.device) {
  465. if (_scsih_is_boot_device(sas_address, device_name,
  466. enclosure_logical_id, slot,
  467. (ioc->bios_pg2.ReqAltBootDeviceForm &
  468. MPI2_BIOSPAGE2_FORM_MASK),
  469. &ioc->bios_pg2.RequestedAltBootDevice)) {
  470. dinitprintk(ioc, pr_info(MPT3SAS_FMT
  471. "%s: req_alt_boot_device(0x%016llx)\n",
  472. ioc->name, __func__,
  473. (unsigned long long)sas_address));
  474. ioc->req_alt_boot_device.device = device;
  475. ioc->req_alt_boot_device.channel = channel;
  476. }
  477. }
  478. if (!ioc->current_boot_device.device) {
  479. if (_scsih_is_boot_device(sas_address, device_name,
  480. enclosure_logical_id, slot,
  481. (ioc->bios_pg2.CurrentBootDeviceForm &
  482. MPI2_BIOSPAGE2_FORM_MASK),
  483. &ioc->bios_pg2.CurrentBootDevice)) {
  484. dinitprintk(ioc, pr_info(MPT3SAS_FMT
  485. "%s: current_boot_device(0x%016llx)\n",
  486. ioc->name, __func__,
  487. (unsigned long long)sas_address));
  488. ioc->current_boot_device.device = device;
  489. ioc->current_boot_device.channel = channel;
  490. }
  491. }
  492. }
  493. static struct _sas_device *
  494. __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
  495. struct MPT3SAS_TARGET *tgt_priv)
  496. {
  497. struct _sas_device *ret;
  498. assert_spin_locked(&ioc->sas_device_lock);
  499. ret = tgt_priv->sas_dev;
  500. if (ret)
  501. sas_device_get(ret);
  502. return ret;
  503. }
  504. static struct _sas_device *
  505. mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
  506. struct MPT3SAS_TARGET *tgt_priv)
  507. {
  508. struct _sas_device *ret;
  509. unsigned long flags;
  510. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  511. ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
  512. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  513. return ret;
  514. }
  515. static struct _pcie_device *
  516. __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
  517. struct MPT3SAS_TARGET *tgt_priv)
  518. {
  519. struct _pcie_device *ret;
  520. assert_spin_locked(&ioc->pcie_device_lock);
  521. ret = tgt_priv->pcie_dev;
  522. if (ret)
  523. pcie_device_get(ret);
  524. return ret;
  525. }
  526. /**
  527. * mpt3sas_get_pdev_from_target - pcie device search
  528. * @ioc: per adapter object
  529. * @tgt_priv: starget private object
  530. *
  531. * Context: This function will acquire ioc->pcie_device_lock and will release
  532. * before returning the pcie_device object.
  533. *
  534. * This searches for pcie_device from target, then return pcie_device object.
  535. */
  536. static struct _pcie_device *
  537. mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
  538. struct MPT3SAS_TARGET *tgt_priv)
  539. {
  540. struct _pcie_device *ret;
  541. unsigned long flags;
  542. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  543. ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv);
  544. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  545. return ret;
  546. }
  547. struct _sas_device *
  548. __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
  549. u64 sas_address)
  550. {
  551. struct _sas_device *sas_device;
  552. assert_spin_locked(&ioc->sas_device_lock);
  553. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  554. if (sas_device->sas_address == sas_address)
  555. goto found_device;
  556. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  557. if (sas_device->sas_address == sas_address)
  558. goto found_device;
  559. return NULL;
  560. found_device:
  561. sas_device_get(sas_device);
  562. return sas_device;
  563. }
  564. /**
  565. * mpt3sas_get_sdev_by_addr - sas device search
  566. * @ioc: per adapter object
  567. * @sas_address: sas address
  568. * Context: Calling function should acquire ioc->sas_device_lock
  569. *
  570. * This searches for sas_device based on sas_address, then return sas_device
  571. * object.
  572. */
  573. struct _sas_device *
  574. mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
  575. u64 sas_address)
  576. {
  577. struct _sas_device *sas_device;
  578. unsigned long flags;
  579. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  580. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  581. sas_address);
  582. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  583. return sas_device;
  584. }
  585. static struct _sas_device *
  586. __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  587. {
  588. struct _sas_device *sas_device;
  589. assert_spin_locked(&ioc->sas_device_lock);
  590. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  591. if (sas_device->handle == handle)
  592. goto found_device;
  593. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  594. if (sas_device->handle == handle)
  595. goto found_device;
  596. return NULL;
  597. found_device:
  598. sas_device_get(sas_device);
  599. return sas_device;
  600. }
  601. /**
  602. * mpt3sas_get_sdev_by_handle - sas device search
  603. * @ioc: per adapter object
  604. * @handle: sas device handle (assigned by firmware)
  605. * Context: Calling function should acquire ioc->sas_device_lock
  606. *
  607. * This searches for sas_device based on sas_address, then return sas_device
  608. * object.
  609. */
  610. struct _sas_device *
  611. mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  612. {
  613. struct _sas_device *sas_device;
  614. unsigned long flags;
  615. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  616. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  617. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  618. return sas_device;
  619. }
  620. /**
  621. * _scsih_display_enclosure_chassis_info - display device location info
  622. * @ioc: per adapter object
  623. * @sas_device: per sas device object
  624. * @sdev: scsi device struct
  625. * @starget: scsi target struct
  626. */
  627. static void
  628. _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc,
  629. struct _sas_device *sas_device, struct scsi_device *sdev,
  630. struct scsi_target *starget)
  631. {
  632. if (sdev) {
  633. if (sas_device->enclosure_handle != 0)
  634. sdev_printk(KERN_INFO, sdev,
  635. "enclosure logical id (0x%016llx), slot(%d) \n",
  636. (unsigned long long)
  637. sas_device->enclosure_logical_id,
  638. sas_device->slot);
  639. if (sas_device->connector_name[0] != '\0')
  640. sdev_printk(KERN_INFO, sdev,
  641. "enclosure level(0x%04x), connector name( %s)\n",
  642. sas_device->enclosure_level,
  643. sas_device->connector_name);
  644. if (sas_device->is_chassis_slot_valid)
  645. sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n",
  646. sas_device->chassis_slot);
  647. } else if (starget) {
  648. if (sas_device->enclosure_handle != 0)
  649. starget_printk(KERN_INFO, starget,
  650. "enclosure logical id(0x%016llx), slot(%d) \n",
  651. (unsigned long long)
  652. sas_device->enclosure_logical_id,
  653. sas_device->slot);
  654. if (sas_device->connector_name[0] != '\0')
  655. starget_printk(KERN_INFO, starget,
  656. "enclosure level(0x%04x), connector name( %s)\n",
  657. sas_device->enclosure_level,
  658. sas_device->connector_name);
  659. if (sas_device->is_chassis_slot_valid)
  660. starget_printk(KERN_INFO, starget,
  661. "chassis slot(0x%04x)\n",
  662. sas_device->chassis_slot);
  663. } else {
  664. if (sas_device->enclosure_handle != 0)
  665. pr_info(MPT3SAS_FMT
  666. "enclosure logical id(0x%016llx), slot(%d) \n",
  667. ioc->name, (unsigned long long)
  668. sas_device->enclosure_logical_id,
  669. sas_device->slot);
  670. if (sas_device->connector_name[0] != '\0')
  671. pr_info(MPT3SAS_FMT
  672. "enclosure level(0x%04x), connector name( %s)\n",
  673. ioc->name, sas_device->enclosure_level,
  674. sas_device->connector_name);
  675. if (sas_device->is_chassis_slot_valid)
  676. pr_info(MPT3SAS_FMT "chassis slot(0x%04x)\n",
  677. ioc->name, sas_device->chassis_slot);
  678. }
  679. }
  680. /**
  681. * _scsih_sas_device_remove - remove sas_device from list.
  682. * @ioc: per adapter object
  683. * @sas_device: the sas_device object
  684. * Context: This function will acquire ioc->sas_device_lock.
  685. *
  686. * If sas_device is on the list, remove it and decrement its reference count.
  687. */
  688. static void
  689. _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
  690. struct _sas_device *sas_device)
  691. {
  692. unsigned long flags;
  693. if (!sas_device)
  694. return;
  695. pr_info(MPT3SAS_FMT
  696. "removing handle(0x%04x), sas_addr(0x%016llx)\n",
  697. ioc->name, sas_device->handle,
  698. (unsigned long long) sas_device->sas_address);
  699. _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
  700. /*
  701. * The lock serializes access to the list, but we still need to verify
  702. * that nobody removed the entry while we were waiting on the lock.
  703. */
  704. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  705. if (!list_empty(&sas_device->list)) {
  706. list_del_init(&sas_device->list);
  707. sas_device_put(sas_device);
  708. }
  709. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  710. }
  711. /**
  712. * _scsih_device_remove_by_handle - removing device object by handle
  713. * @ioc: per adapter object
  714. * @handle: device handle
  715. */
  716. static void
  717. _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  718. {
  719. struct _sas_device *sas_device;
  720. unsigned long flags;
  721. if (ioc->shost_recovery)
  722. return;
  723. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  724. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  725. if (sas_device) {
  726. list_del_init(&sas_device->list);
  727. sas_device_put(sas_device);
  728. }
  729. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  730. if (sas_device) {
  731. _scsih_remove_device(ioc, sas_device);
  732. sas_device_put(sas_device);
  733. }
  734. }
  735. /**
  736. * mpt3sas_device_remove_by_sas_address - removing device object by sas address
  737. * @ioc: per adapter object
  738. * @sas_address: device sas_address
  739. */
  740. void
  741. mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
  742. u64 sas_address)
  743. {
  744. struct _sas_device *sas_device;
  745. unsigned long flags;
  746. if (ioc->shost_recovery)
  747. return;
  748. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  749. sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
  750. if (sas_device) {
  751. list_del_init(&sas_device->list);
  752. sas_device_put(sas_device);
  753. }
  754. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  755. if (sas_device) {
  756. _scsih_remove_device(ioc, sas_device);
  757. sas_device_put(sas_device);
  758. }
  759. }
  760. /**
  761. * _scsih_sas_device_add - insert sas_device to the list.
  762. * @ioc: per adapter object
  763. * @sas_device: the sas_device object
  764. * Context: This function will acquire ioc->sas_device_lock.
  765. *
  766. * Adding new object to the ioc->sas_device_list.
  767. */
  768. static void
  769. _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
  770. struct _sas_device *sas_device)
  771. {
  772. unsigned long flags;
  773. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  774. "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
  775. ioc->name, __func__, sas_device->handle,
  776. (unsigned long long)sas_device->sas_address));
  777. dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
  778. NULL, NULL));
  779. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  780. sas_device_get(sas_device);
  781. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  782. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  783. if (ioc->hide_drives) {
  784. clear_bit(sas_device->handle, ioc->pend_os_device_add);
  785. return;
  786. }
  787. if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
  788. sas_device->sas_address_parent)) {
  789. _scsih_sas_device_remove(ioc, sas_device);
  790. } else if (!sas_device->starget) {
  791. /*
  792. * When asyn scanning is enabled, its not possible to remove
  793. * devices while scanning is turned on due to an oops in
  794. * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
  795. */
  796. if (!ioc->is_driver_loading) {
  797. mpt3sas_transport_port_remove(ioc,
  798. sas_device->sas_address,
  799. sas_device->sas_address_parent);
  800. _scsih_sas_device_remove(ioc, sas_device);
  801. }
  802. } else
  803. clear_bit(sas_device->handle, ioc->pend_os_device_add);
  804. }
  805. /**
  806. * _scsih_sas_device_init_add - insert sas_device to the list.
  807. * @ioc: per adapter object
  808. * @sas_device: the sas_device object
  809. * Context: This function will acquire ioc->sas_device_lock.
  810. *
  811. * Adding new object at driver load time to the ioc->sas_device_init_list.
  812. */
  813. static void
  814. _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
  815. struct _sas_device *sas_device)
  816. {
  817. unsigned long flags;
  818. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  819. "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  820. __func__, sas_device->handle,
  821. (unsigned long long)sas_device->sas_address));
  822. dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
  823. NULL, NULL));
  824. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  825. sas_device_get(sas_device);
  826. list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
  827. _scsih_determine_boot_device(ioc, sas_device, 0);
  828. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  829. }
  830. static struct _pcie_device *
  831. __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
  832. {
  833. struct _pcie_device *pcie_device;
  834. assert_spin_locked(&ioc->pcie_device_lock);
  835. list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
  836. if (pcie_device->wwid == wwid)
  837. goto found_device;
  838. list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
  839. if (pcie_device->wwid == wwid)
  840. goto found_device;
  841. return NULL;
  842. found_device:
  843. pcie_device_get(pcie_device);
  844. return pcie_device;
  845. }
  846. /**
  847. * mpt3sas_get_pdev_by_wwid - pcie device search
  848. * @ioc: per adapter object
  849. * @wwid: wwid
  850. *
  851. * Context: This function will acquire ioc->pcie_device_lock and will release
  852. * before returning the pcie_device object.
  853. *
  854. * This searches for pcie_device based on wwid, then return pcie_device object.
  855. */
  856. static struct _pcie_device *
  857. mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
  858. {
  859. struct _pcie_device *pcie_device;
  860. unsigned long flags;
  861. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  862. pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
  863. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  864. return pcie_device;
  865. }
  866. static struct _pcie_device *
  867. __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id,
  868. int channel)
  869. {
  870. struct _pcie_device *pcie_device;
  871. assert_spin_locked(&ioc->pcie_device_lock);
  872. list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
  873. if (pcie_device->id == id && pcie_device->channel == channel)
  874. goto found_device;
  875. list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
  876. if (pcie_device->id == id && pcie_device->channel == channel)
  877. goto found_device;
  878. return NULL;
  879. found_device:
  880. pcie_device_get(pcie_device);
  881. return pcie_device;
  882. }
  883. static struct _pcie_device *
  884. __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  885. {
  886. struct _pcie_device *pcie_device;
  887. assert_spin_locked(&ioc->pcie_device_lock);
  888. list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
  889. if (pcie_device->handle == handle)
  890. goto found_device;
  891. list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
  892. if (pcie_device->handle == handle)
  893. goto found_device;
  894. return NULL;
  895. found_device:
  896. pcie_device_get(pcie_device);
  897. return pcie_device;
  898. }
  899. /**
  900. * mpt3sas_get_pdev_by_handle - pcie device search
  901. * @ioc: per adapter object
  902. * @handle: Firmware device handle
  903. *
  904. * Context: This function will acquire ioc->pcie_device_lock and will release
  905. * before returning the pcie_device object.
  906. *
  907. * This searches for pcie_device based on handle, then return pcie_device
  908. * object.
  909. */
  910. struct _pcie_device *
  911. mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  912. {
  913. struct _pcie_device *pcie_device;
  914. unsigned long flags;
  915. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  916. pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
  917. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  918. return pcie_device;
  919. }
  920. /**
  921. * _scsih_pcie_device_remove - remove pcie_device from list.
  922. * @ioc: per adapter object
  923. * @pcie_device: the pcie_device object
  924. * Context: This function will acquire ioc->pcie_device_lock.
  925. *
  926. * If pcie_device is on the list, remove it and decrement its reference count.
  927. */
  928. static void
  929. _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc,
  930. struct _pcie_device *pcie_device)
  931. {
  932. unsigned long flags;
  933. int was_on_pcie_device_list = 0;
  934. if (!pcie_device)
  935. return;
  936. pr_info(MPT3SAS_FMT
  937. "removing handle(0x%04x), wwid(0x%016llx)\n",
  938. ioc->name, pcie_device->handle,
  939. (unsigned long long) pcie_device->wwid);
  940. if (pcie_device->enclosure_handle != 0)
  941. pr_info(MPT3SAS_FMT
  942. "removing enclosure logical id(0x%016llx), slot(%d)\n",
  943. ioc->name,
  944. (unsigned long long)pcie_device->enclosure_logical_id,
  945. pcie_device->slot);
  946. if (pcie_device->connector_name[0] != '\0')
  947. pr_info(MPT3SAS_FMT
  948. "removing enclosure level(0x%04x), connector name( %s)\n",
  949. ioc->name, pcie_device->enclosure_level,
  950. pcie_device->connector_name);
  951. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  952. if (!list_empty(&pcie_device->list)) {
  953. list_del_init(&pcie_device->list);
  954. was_on_pcie_device_list = 1;
  955. }
  956. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  957. if (was_on_pcie_device_list) {
  958. kfree(pcie_device->serial_number);
  959. pcie_device_put(pcie_device);
  960. }
  961. }
  962. /**
  963. * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
  964. * @ioc: per adapter object
  965. * @handle: device handle
  966. */
  967. static void
  968. _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  969. {
  970. struct _pcie_device *pcie_device;
  971. unsigned long flags;
  972. int was_on_pcie_device_list = 0;
  973. if (ioc->shost_recovery)
  974. return;
  975. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  976. pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
  977. if (pcie_device) {
  978. if (!list_empty(&pcie_device->list)) {
  979. list_del_init(&pcie_device->list);
  980. was_on_pcie_device_list = 1;
  981. pcie_device_put(pcie_device);
  982. }
  983. }
  984. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  985. if (was_on_pcie_device_list) {
  986. _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
  987. pcie_device_put(pcie_device);
  988. }
  989. }
  990. /**
  991. * _scsih_pcie_device_add - add pcie_device object
  992. * @ioc: per adapter object
  993. * @pcie_device: pcie_device object
  994. *
  995. * This is added to the pcie_device_list link list.
  996. */
  997. static void
  998. _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc,
  999. struct _pcie_device *pcie_device)
  1000. {
  1001. unsigned long flags;
  1002. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1003. "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  1004. pcie_device->handle, (unsigned long long)pcie_device->wwid));
  1005. if (pcie_device->enclosure_handle != 0)
  1006. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1007. "%s: enclosure logical id(0x%016llx), slot( %d)\n",
  1008. ioc->name, __func__,
  1009. (unsigned long long)pcie_device->enclosure_logical_id,
  1010. pcie_device->slot));
  1011. if (pcie_device->connector_name[0] != '\0')
  1012. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1013. "%s: enclosure level(0x%04x), connector name( %s)\n",
  1014. ioc->name, __func__, pcie_device->enclosure_level,
  1015. pcie_device->connector_name));
  1016. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1017. pcie_device_get(pcie_device);
  1018. list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
  1019. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1020. if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) {
  1021. _scsih_pcie_device_remove(ioc, pcie_device);
  1022. } else if (!pcie_device->starget) {
  1023. if (!ioc->is_driver_loading) {
  1024. /*TODO-- Need to find out whether this condition will occur or not*/
  1025. clear_bit(pcie_device->handle, ioc->pend_os_device_add);
  1026. }
  1027. } else
  1028. clear_bit(pcie_device->handle, ioc->pend_os_device_add);
  1029. }
  1030. /*
  1031. * _scsih_pcie_device_init_add - insert pcie_device to the init list.
  1032. * @ioc: per adapter object
  1033. * @pcie_device: the pcie_device object
  1034. * Context: This function will acquire ioc->pcie_device_lock.
  1035. *
  1036. * Adding new object at driver load time to the ioc->pcie_device_init_list.
  1037. */
  1038. static void
  1039. _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc,
  1040. struct _pcie_device *pcie_device)
  1041. {
  1042. unsigned long flags;
  1043. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1044. "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  1045. pcie_device->handle, (unsigned long long)pcie_device->wwid));
  1046. if (pcie_device->enclosure_handle != 0)
  1047. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1048. "%s: enclosure logical id(0x%016llx), slot( %d)\n",
  1049. ioc->name, __func__,
  1050. (unsigned long long)pcie_device->enclosure_logical_id,
  1051. pcie_device->slot));
  1052. if (pcie_device->connector_name[0] != '\0')
  1053. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1054. "%s: enclosure level(0x%04x), connector name( %s)\n",
  1055. ioc->name, __func__, pcie_device->enclosure_level,
  1056. pcie_device->connector_name));
  1057. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1058. pcie_device_get(pcie_device);
  1059. list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list);
  1060. _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL);
  1061. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1062. }
  1063. /**
  1064. * _scsih_raid_device_find_by_id - raid device search
  1065. * @ioc: per adapter object
  1066. * @id: sas device target id
  1067. * @channel: sas device channel
  1068. * Context: Calling function should acquire ioc->raid_device_lock
  1069. *
  1070. * This searches for raid_device based on target id, then return raid_device
  1071. * object.
  1072. */
  1073. static struct _raid_device *
  1074. _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
  1075. {
  1076. struct _raid_device *raid_device, *r;
  1077. r = NULL;
  1078. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  1079. if (raid_device->id == id && raid_device->channel == channel) {
  1080. r = raid_device;
  1081. goto out;
  1082. }
  1083. }
  1084. out:
  1085. return r;
  1086. }
  1087. /**
  1088. * mpt3sas_raid_device_find_by_handle - raid device search
  1089. * @ioc: per adapter object
  1090. * @handle: sas device handle (assigned by firmware)
  1091. * Context: Calling function should acquire ioc->raid_device_lock
  1092. *
  1093. * This searches for raid_device based on handle, then return raid_device
  1094. * object.
  1095. */
  1096. struct _raid_device *
  1097. mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  1098. {
  1099. struct _raid_device *raid_device, *r;
  1100. r = NULL;
  1101. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  1102. if (raid_device->handle != handle)
  1103. continue;
  1104. r = raid_device;
  1105. goto out;
  1106. }
  1107. out:
  1108. return r;
  1109. }
  1110. /**
  1111. * _scsih_raid_device_find_by_wwid - raid device search
  1112. * @ioc: per adapter object
  1113. * @wwid: ?
  1114. * Context: Calling function should acquire ioc->raid_device_lock
  1115. *
  1116. * This searches for raid_device based on wwid, then return raid_device
  1117. * object.
  1118. */
  1119. static struct _raid_device *
  1120. _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
  1121. {
  1122. struct _raid_device *raid_device, *r;
  1123. r = NULL;
  1124. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  1125. if (raid_device->wwid != wwid)
  1126. continue;
  1127. r = raid_device;
  1128. goto out;
  1129. }
  1130. out:
  1131. return r;
  1132. }
  1133. /**
  1134. * _scsih_raid_device_add - add raid_device object
  1135. * @ioc: per adapter object
  1136. * @raid_device: raid_device object
  1137. *
  1138. * This is added to the raid_device_list link list.
  1139. */
  1140. static void
  1141. _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
  1142. struct _raid_device *raid_device)
  1143. {
  1144. unsigned long flags;
  1145. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  1146. "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  1147. raid_device->handle, (unsigned long long)raid_device->wwid));
  1148. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1149. list_add_tail(&raid_device->list, &ioc->raid_device_list);
  1150. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1151. }
  1152. /**
  1153. * _scsih_raid_device_remove - delete raid_device object
  1154. * @ioc: per adapter object
  1155. * @raid_device: raid_device object
  1156. *
  1157. */
  1158. static void
  1159. _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
  1160. struct _raid_device *raid_device)
  1161. {
  1162. unsigned long flags;
  1163. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1164. list_del(&raid_device->list);
  1165. kfree(raid_device);
  1166. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1167. }
  1168. /**
  1169. * mpt3sas_scsih_expander_find_by_handle - expander device search
  1170. * @ioc: per adapter object
  1171. * @handle: expander handle (assigned by firmware)
  1172. * Context: Calling function should acquire ioc->sas_device_lock
  1173. *
  1174. * This searches for expander device based on handle, then returns the
  1175. * sas_node object.
  1176. */
  1177. struct _sas_node *
  1178. mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  1179. {
  1180. struct _sas_node *sas_expander, *r;
  1181. r = NULL;
  1182. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  1183. if (sas_expander->handle != handle)
  1184. continue;
  1185. r = sas_expander;
  1186. goto out;
  1187. }
  1188. out:
  1189. return r;
  1190. }
  1191. /**
  1192. * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
  1193. * @ioc: per adapter object
  1194. * @handle: enclosure handle (assigned by firmware)
  1195. * Context: Calling function should acquire ioc->sas_device_lock
  1196. *
  1197. * This searches for enclosure device based on handle, then returns the
  1198. * enclosure object.
  1199. */
  1200. static struct _enclosure_node *
  1201. mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  1202. {
  1203. struct _enclosure_node *enclosure_dev, *r;
  1204. r = NULL;
  1205. list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) {
  1206. if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle)
  1207. continue;
  1208. r = enclosure_dev;
  1209. goto out;
  1210. }
  1211. out:
  1212. return r;
  1213. }
  1214. /**
  1215. * mpt3sas_scsih_expander_find_by_sas_address - expander device search
  1216. * @ioc: per adapter object
  1217. * @sas_address: sas address
  1218. * Context: Calling function should acquire ioc->sas_node_lock.
  1219. *
  1220. * This searches for expander device based on sas_address, then returns the
  1221. * sas_node object.
  1222. */
  1223. struct _sas_node *
  1224. mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
  1225. u64 sas_address)
  1226. {
  1227. struct _sas_node *sas_expander, *r;
  1228. r = NULL;
  1229. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  1230. if (sas_expander->sas_address != sas_address)
  1231. continue;
  1232. r = sas_expander;
  1233. goto out;
  1234. }
  1235. out:
  1236. return r;
  1237. }
  1238. /**
  1239. * _scsih_expander_node_add - insert expander device to the list.
  1240. * @ioc: per adapter object
  1241. * @sas_expander: the sas_device object
  1242. * Context: This function will acquire ioc->sas_node_lock.
  1243. *
  1244. * Adding new object to the ioc->sas_expander_list.
  1245. */
  1246. static void
  1247. _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
  1248. struct _sas_node *sas_expander)
  1249. {
  1250. unsigned long flags;
  1251. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  1252. list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
  1253. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  1254. }
  1255. /**
  1256. * _scsih_is_end_device - determines if device is an end device
  1257. * @device_info: bitfield providing information about the device.
  1258. * Context: none
  1259. *
  1260. * Return: 1 if end device.
  1261. */
  1262. static int
  1263. _scsih_is_end_device(u32 device_info)
  1264. {
  1265. if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
  1266. ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
  1267. (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
  1268. (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
  1269. return 1;
  1270. else
  1271. return 0;
  1272. }
  1273. /**
  1274. * _scsih_is_nvme_device - determines if device is an nvme device
  1275. * @device_info: bitfield providing information about the device.
  1276. * Context: none
  1277. *
  1278. * Return: 1 if nvme device.
  1279. */
  1280. static int
  1281. _scsih_is_nvme_device(u32 device_info)
  1282. {
  1283. if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE)
  1284. == MPI26_PCIE_DEVINFO_NVME)
  1285. return 1;
  1286. else
  1287. return 0;
  1288. }
  1289. /**
  1290. * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
  1291. * @ioc: per adapter object
  1292. * @smid: system request message index
  1293. *
  1294. * Return: the smid stored scmd pointer.
  1295. * Then will dereference the stored scmd pointer.
  1296. */
  1297. struct scsi_cmnd *
  1298. mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
  1299. {
  1300. struct scsi_cmnd *scmd = NULL;
  1301. struct scsiio_tracker *st;
  1302. Mpi25SCSIIORequest_t *mpi_request;
  1303. if (smid > 0 &&
  1304. smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
  1305. u32 unique_tag = smid - 1;
  1306. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  1307. /*
  1308. * If SCSI IO request is outstanding at driver level then
  1309. * DevHandle filed must be non-zero. If DevHandle is zero
  1310. * then it means that this smid is free at driver level,
  1311. * so return NULL.
  1312. */
  1313. if (!mpi_request->DevHandle)
  1314. return scmd;
  1315. scmd = scsi_host_find_tag(ioc->shost, unique_tag);
  1316. if (scmd) {
  1317. st = scsi_cmd_priv(scmd);
  1318. if (st->cb_idx == 0xFF || st->smid == 0)
  1319. scmd = NULL;
  1320. }
  1321. }
  1322. return scmd;
  1323. }
  1324. /**
  1325. * scsih_change_queue_depth - setting device queue depth
  1326. * @sdev: scsi device struct
  1327. * @qdepth: requested queue depth
  1328. *
  1329. * Return: queue depth.
  1330. */
  1331. static int
  1332. scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1333. {
  1334. struct Scsi_Host *shost = sdev->host;
  1335. int max_depth;
  1336. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  1337. struct MPT3SAS_DEVICE *sas_device_priv_data;
  1338. struct MPT3SAS_TARGET *sas_target_priv_data;
  1339. struct _sas_device *sas_device;
  1340. unsigned long flags;
  1341. max_depth = shost->can_queue;
  1342. /* limit max device queue for SATA to 32 */
  1343. sas_device_priv_data = sdev->hostdata;
  1344. if (!sas_device_priv_data)
  1345. goto not_sata;
  1346. sas_target_priv_data = sas_device_priv_data->sas_target;
  1347. if (!sas_target_priv_data)
  1348. goto not_sata;
  1349. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
  1350. goto not_sata;
  1351. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1352. sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
  1353. if (sas_device) {
  1354. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1355. max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
  1356. sas_device_put(sas_device);
  1357. }
  1358. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1359. not_sata:
  1360. if (!sdev->tagged_supported)
  1361. max_depth = 1;
  1362. if (qdepth > max_depth)
  1363. qdepth = max_depth;
  1364. return scsi_change_queue_depth(sdev, qdepth);
  1365. }
  1366. /**
  1367. * scsih_target_alloc - target add routine
  1368. * @starget: scsi target struct
  1369. *
  1370. * Return: 0 if ok. Any other return is assumed to be an error and
  1371. * the device is ignored.
  1372. */
  1373. static int
  1374. scsih_target_alloc(struct scsi_target *starget)
  1375. {
  1376. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1377. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  1378. struct MPT3SAS_TARGET *sas_target_priv_data;
  1379. struct _sas_device *sas_device;
  1380. struct _raid_device *raid_device;
  1381. struct _pcie_device *pcie_device;
  1382. unsigned long flags;
  1383. struct sas_rphy *rphy;
  1384. sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
  1385. GFP_KERNEL);
  1386. if (!sas_target_priv_data)
  1387. return -ENOMEM;
  1388. starget->hostdata = sas_target_priv_data;
  1389. sas_target_priv_data->starget = starget;
  1390. sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
  1391. /* RAID volumes */
  1392. if (starget->channel == RAID_CHANNEL) {
  1393. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1394. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1395. starget->channel);
  1396. if (raid_device) {
  1397. sas_target_priv_data->handle = raid_device->handle;
  1398. sas_target_priv_data->sas_address = raid_device->wwid;
  1399. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
  1400. if (ioc->is_warpdrive)
  1401. sas_target_priv_data->raid_device = raid_device;
  1402. raid_device->starget = starget;
  1403. }
  1404. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1405. return 0;
  1406. }
  1407. /* PCIe devices */
  1408. if (starget->channel == PCIE_CHANNEL) {
  1409. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1410. pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id,
  1411. starget->channel);
  1412. if (pcie_device) {
  1413. sas_target_priv_data->handle = pcie_device->handle;
  1414. sas_target_priv_data->sas_address = pcie_device->wwid;
  1415. sas_target_priv_data->pcie_dev = pcie_device;
  1416. pcie_device->starget = starget;
  1417. pcie_device->id = starget->id;
  1418. pcie_device->channel = starget->channel;
  1419. sas_target_priv_data->flags |=
  1420. MPT_TARGET_FLAGS_PCIE_DEVICE;
  1421. if (pcie_device->fast_path)
  1422. sas_target_priv_data->flags |=
  1423. MPT_TARGET_FASTPATH_IO;
  1424. }
  1425. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1426. return 0;
  1427. }
  1428. /* sas/sata devices */
  1429. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1430. rphy = dev_to_rphy(starget->dev.parent);
  1431. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  1432. rphy->identify.sas_address);
  1433. if (sas_device) {
  1434. sas_target_priv_data->handle = sas_device->handle;
  1435. sas_target_priv_data->sas_address = sas_device->sas_address;
  1436. sas_target_priv_data->sas_dev = sas_device;
  1437. sas_device->starget = starget;
  1438. sas_device->id = starget->id;
  1439. sas_device->channel = starget->channel;
  1440. if (test_bit(sas_device->handle, ioc->pd_handles))
  1441. sas_target_priv_data->flags |=
  1442. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1443. if (sas_device->fast_path)
  1444. sas_target_priv_data->flags |=
  1445. MPT_TARGET_FASTPATH_IO;
  1446. }
  1447. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1448. return 0;
  1449. }
  1450. /**
  1451. * scsih_target_destroy - target destroy routine
  1452. * @starget: scsi target struct
  1453. */
  1454. static void
  1455. scsih_target_destroy(struct scsi_target *starget)
  1456. {
  1457. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1458. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  1459. struct MPT3SAS_TARGET *sas_target_priv_data;
  1460. struct _sas_device *sas_device;
  1461. struct _raid_device *raid_device;
  1462. struct _pcie_device *pcie_device;
  1463. unsigned long flags;
  1464. sas_target_priv_data = starget->hostdata;
  1465. if (!sas_target_priv_data)
  1466. return;
  1467. if (starget->channel == RAID_CHANNEL) {
  1468. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1469. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1470. starget->channel);
  1471. if (raid_device) {
  1472. raid_device->starget = NULL;
  1473. raid_device->sdev = NULL;
  1474. }
  1475. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1476. goto out;
  1477. }
  1478. if (starget->channel == PCIE_CHANNEL) {
  1479. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1480. pcie_device = __mpt3sas_get_pdev_from_target(ioc,
  1481. sas_target_priv_data);
  1482. if (pcie_device && (pcie_device->starget == starget) &&
  1483. (pcie_device->id == starget->id) &&
  1484. (pcie_device->channel == starget->channel))
  1485. pcie_device->starget = NULL;
  1486. if (pcie_device) {
  1487. /*
  1488. * Corresponding get() is in _scsih_target_alloc()
  1489. */
  1490. sas_target_priv_data->pcie_dev = NULL;
  1491. pcie_device_put(pcie_device);
  1492. pcie_device_put(pcie_device);
  1493. }
  1494. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1495. goto out;
  1496. }
  1497. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1498. sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
  1499. if (sas_device && (sas_device->starget == starget) &&
  1500. (sas_device->id == starget->id) &&
  1501. (sas_device->channel == starget->channel))
  1502. sas_device->starget = NULL;
  1503. if (sas_device) {
  1504. /*
  1505. * Corresponding get() is in _scsih_target_alloc()
  1506. */
  1507. sas_target_priv_data->sas_dev = NULL;
  1508. sas_device_put(sas_device);
  1509. sas_device_put(sas_device);
  1510. }
  1511. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1512. out:
  1513. kfree(sas_target_priv_data);
  1514. starget->hostdata = NULL;
  1515. }
  1516. /**
  1517. * scsih_slave_alloc - device add routine
  1518. * @sdev: scsi device struct
  1519. *
  1520. * Return: 0 if ok. Any other return is assumed to be an error and
  1521. * the device is ignored.
  1522. */
  1523. static int
  1524. scsih_slave_alloc(struct scsi_device *sdev)
  1525. {
  1526. struct Scsi_Host *shost;
  1527. struct MPT3SAS_ADAPTER *ioc;
  1528. struct MPT3SAS_TARGET *sas_target_priv_data;
  1529. struct MPT3SAS_DEVICE *sas_device_priv_data;
  1530. struct scsi_target *starget;
  1531. struct _raid_device *raid_device;
  1532. struct _sas_device *sas_device;
  1533. struct _pcie_device *pcie_device;
  1534. unsigned long flags;
  1535. sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
  1536. GFP_KERNEL);
  1537. if (!sas_device_priv_data)
  1538. return -ENOMEM;
  1539. sas_device_priv_data->lun = sdev->lun;
  1540. sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
  1541. starget = scsi_target(sdev);
  1542. sas_target_priv_data = starget->hostdata;
  1543. sas_target_priv_data->num_luns++;
  1544. sas_device_priv_data->sas_target = sas_target_priv_data;
  1545. sdev->hostdata = sas_device_priv_data;
  1546. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
  1547. sdev->no_uld_attach = 1;
  1548. shost = dev_to_shost(&starget->dev);
  1549. ioc = shost_priv(shost);
  1550. if (starget->channel == RAID_CHANNEL) {
  1551. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1552. raid_device = _scsih_raid_device_find_by_id(ioc,
  1553. starget->id, starget->channel);
  1554. if (raid_device)
  1555. raid_device->sdev = sdev; /* raid is single lun */
  1556. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1557. }
  1558. if (starget->channel == PCIE_CHANNEL) {
  1559. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1560. pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
  1561. sas_target_priv_data->sas_address);
  1562. if (pcie_device && (pcie_device->starget == NULL)) {
  1563. sdev_printk(KERN_INFO, sdev,
  1564. "%s : pcie_device->starget set to starget @ %d\n",
  1565. __func__, __LINE__);
  1566. pcie_device->starget = starget;
  1567. }
  1568. if (pcie_device)
  1569. pcie_device_put(pcie_device);
  1570. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1571. } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
  1572. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1573. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  1574. sas_target_priv_data->sas_address);
  1575. if (sas_device && (sas_device->starget == NULL)) {
  1576. sdev_printk(KERN_INFO, sdev,
  1577. "%s : sas_device->starget set to starget @ %d\n",
  1578. __func__, __LINE__);
  1579. sas_device->starget = starget;
  1580. }
  1581. if (sas_device)
  1582. sas_device_put(sas_device);
  1583. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1584. }
  1585. return 0;
  1586. }
  1587. /**
  1588. * scsih_slave_destroy - device destroy routine
  1589. * @sdev: scsi device struct
  1590. */
  1591. static void
  1592. scsih_slave_destroy(struct scsi_device *sdev)
  1593. {
  1594. struct MPT3SAS_TARGET *sas_target_priv_data;
  1595. struct scsi_target *starget;
  1596. struct Scsi_Host *shost;
  1597. struct MPT3SAS_ADAPTER *ioc;
  1598. struct _sas_device *sas_device;
  1599. struct _pcie_device *pcie_device;
  1600. unsigned long flags;
  1601. if (!sdev->hostdata)
  1602. return;
  1603. starget = scsi_target(sdev);
  1604. sas_target_priv_data = starget->hostdata;
  1605. sas_target_priv_data->num_luns--;
  1606. shost = dev_to_shost(&starget->dev);
  1607. ioc = shost_priv(shost);
  1608. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
  1609. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  1610. pcie_device = __mpt3sas_get_pdev_from_target(ioc,
  1611. sas_target_priv_data);
  1612. if (pcie_device && !sas_target_priv_data->num_luns)
  1613. pcie_device->starget = NULL;
  1614. if (pcie_device)
  1615. pcie_device_put(pcie_device);
  1616. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  1617. } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
  1618. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1619. sas_device = __mpt3sas_get_sdev_from_target(ioc,
  1620. sas_target_priv_data);
  1621. if (sas_device && !sas_target_priv_data->num_luns)
  1622. sas_device->starget = NULL;
  1623. if (sas_device)
  1624. sas_device_put(sas_device);
  1625. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1626. }
  1627. kfree(sdev->hostdata);
  1628. sdev->hostdata = NULL;
  1629. }
  1630. /**
  1631. * _scsih_display_sata_capabilities - sata capabilities
  1632. * @ioc: per adapter object
  1633. * @handle: device handle
  1634. * @sdev: scsi device struct
  1635. */
  1636. static void
  1637. _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
  1638. u16 handle, struct scsi_device *sdev)
  1639. {
  1640. Mpi2ConfigReply_t mpi_reply;
  1641. Mpi2SasDevicePage0_t sas_device_pg0;
  1642. u32 ioc_status;
  1643. u16 flags;
  1644. u32 device_info;
  1645. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  1646. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  1647. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  1648. ioc->name, __FILE__, __LINE__, __func__);
  1649. return;
  1650. }
  1651. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1652. MPI2_IOCSTATUS_MASK;
  1653. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1654. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  1655. ioc->name, __FILE__, __LINE__, __func__);
  1656. return;
  1657. }
  1658. flags = le16_to_cpu(sas_device_pg0.Flags);
  1659. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  1660. sdev_printk(KERN_INFO, sdev,
  1661. "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
  1662. "sw_preserve(%s)\n",
  1663. (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
  1664. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
  1665. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
  1666. "n",
  1667. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
  1668. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
  1669. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
  1670. }
  1671. /*
  1672. * raid transport support -
  1673. * Enabled for SLES11 and newer, in older kernels the driver will panic when
  1674. * unloading the driver followed by a load - I believe that the subroutine
  1675. * raid_class_release() is not cleaning up properly.
  1676. */
  1677. /**
  1678. * scsih_is_raid - return boolean indicating device is raid volume
  1679. * @dev: the device struct object
  1680. */
  1681. static int
  1682. scsih_is_raid(struct device *dev)
  1683. {
  1684. struct scsi_device *sdev = to_scsi_device(dev);
  1685. struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1686. if (ioc->is_warpdrive)
  1687. return 0;
  1688. return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
  1689. }
  1690. static int
  1691. scsih_is_nvme(struct device *dev)
  1692. {
  1693. struct scsi_device *sdev = to_scsi_device(dev);
  1694. return (sdev->channel == PCIE_CHANNEL) ? 1 : 0;
  1695. }
  1696. /**
  1697. * scsih_get_resync - get raid volume resync percent complete
  1698. * @dev: the device struct object
  1699. */
  1700. static void
  1701. scsih_get_resync(struct device *dev)
  1702. {
  1703. struct scsi_device *sdev = to_scsi_device(dev);
  1704. struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1705. static struct _raid_device *raid_device;
  1706. unsigned long flags;
  1707. Mpi2RaidVolPage0_t vol_pg0;
  1708. Mpi2ConfigReply_t mpi_reply;
  1709. u32 volume_status_flags;
  1710. u8 percent_complete;
  1711. u16 handle;
  1712. percent_complete = 0;
  1713. handle = 0;
  1714. if (ioc->is_warpdrive)
  1715. goto out;
  1716. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1717. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1718. sdev->channel);
  1719. if (raid_device) {
  1720. handle = raid_device->handle;
  1721. percent_complete = raid_device->percent_complete;
  1722. }
  1723. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1724. if (!handle)
  1725. goto out;
  1726. if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1727. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  1728. sizeof(Mpi2RaidVolPage0_t))) {
  1729. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  1730. ioc->name, __FILE__, __LINE__, __func__);
  1731. percent_complete = 0;
  1732. goto out;
  1733. }
  1734. volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1735. if (!(volume_status_flags &
  1736. MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
  1737. percent_complete = 0;
  1738. out:
  1739. switch (ioc->hba_mpi_version_belonged) {
  1740. case MPI2_VERSION:
  1741. raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
  1742. break;
  1743. case MPI25_VERSION:
  1744. case MPI26_VERSION:
  1745. raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
  1746. break;
  1747. }
  1748. }
  1749. /**
  1750. * scsih_get_state - get raid volume level
  1751. * @dev: the device struct object
  1752. */
  1753. static void
  1754. scsih_get_state(struct device *dev)
  1755. {
  1756. struct scsi_device *sdev = to_scsi_device(dev);
  1757. struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1758. static struct _raid_device *raid_device;
  1759. unsigned long flags;
  1760. Mpi2RaidVolPage0_t vol_pg0;
  1761. Mpi2ConfigReply_t mpi_reply;
  1762. u32 volstate;
  1763. enum raid_state state = RAID_STATE_UNKNOWN;
  1764. u16 handle = 0;
  1765. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1766. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1767. sdev->channel);
  1768. if (raid_device)
  1769. handle = raid_device->handle;
  1770. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1771. if (!raid_device)
  1772. goto out;
  1773. if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1774. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  1775. sizeof(Mpi2RaidVolPage0_t))) {
  1776. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  1777. ioc->name, __FILE__, __LINE__, __func__);
  1778. goto out;
  1779. }
  1780. volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1781. if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
  1782. state = RAID_STATE_RESYNCING;
  1783. goto out;
  1784. }
  1785. switch (vol_pg0.VolumeState) {
  1786. case MPI2_RAID_VOL_STATE_OPTIMAL:
  1787. case MPI2_RAID_VOL_STATE_ONLINE:
  1788. state = RAID_STATE_ACTIVE;
  1789. break;
  1790. case MPI2_RAID_VOL_STATE_DEGRADED:
  1791. state = RAID_STATE_DEGRADED;
  1792. break;
  1793. case MPI2_RAID_VOL_STATE_FAILED:
  1794. case MPI2_RAID_VOL_STATE_MISSING:
  1795. state = RAID_STATE_OFFLINE;
  1796. break;
  1797. }
  1798. out:
  1799. switch (ioc->hba_mpi_version_belonged) {
  1800. case MPI2_VERSION:
  1801. raid_set_state(mpt2sas_raid_template, dev, state);
  1802. break;
  1803. case MPI25_VERSION:
  1804. case MPI26_VERSION:
  1805. raid_set_state(mpt3sas_raid_template, dev, state);
  1806. break;
  1807. }
  1808. }
  1809. /**
  1810. * _scsih_set_level - set raid level
  1811. * @ioc: ?
  1812. * @sdev: scsi device struct
  1813. * @volume_type: volume type
  1814. */
  1815. static void
  1816. _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
  1817. struct scsi_device *sdev, u8 volume_type)
  1818. {
  1819. enum raid_level level = RAID_LEVEL_UNKNOWN;
  1820. switch (volume_type) {
  1821. case MPI2_RAID_VOL_TYPE_RAID0:
  1822. level = RAID_LEVEL_0;
  1823. break;
  1824. case MPI2_RAID_VOL_TYPE_RAID10:
  1825. level = RAID_LEVEL_10;
  1826. break;
  1827. case MPI2_RAID_VOL_TYPE_RAID1E:
  1828. level = RAID_LEVEL_1E;
  1829. break;
  1830. case MPI2_RAID_VOL_TYPE_RAID1:
  1831. level = RAID_LEVEL_1;
  1832. break;
  1833. }
  1834. switch (ioc->hba_mpi_version_belonged) {
  1835. case MPI2_VERSION:
  1836. raid_set_level(mpt2sas_raid_template,
  1837. &sdev->sdev_gendev, level);
  1838. break;
  1839. case MPI25_VERSION:
  1840. case MPI26_VERSION:
  1841. raid_set_level(mpt3sas_raid_template,
  1842. &sdev->sdev_gendev, level);
  1843. break;
  1844. }
  1845. }
  1846. /**
  1847. * _scsih_get_volume_capabilities - volume capabilities
  1848. * @ioc: per adapter object
  1849. * @raid_device: the raid_device object
  1850. *
  1851. * Return: 0 for success, else 1
  1852. */
  1853. static int
  1854. _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
  1855. struct _raid_device *raid_device)
  1856. {
  1857. Mpi2RaidVolPage0_t *vol_pg0;
  1858. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1859. Mpi2SasDevicePage0_t sas_device_pg0;
  1860. Mpi2ConfigReply_t mpi_reply;
  1861. u16 sz;
  1862. u8 num_pds;
  1863. if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
  1864. &num_pds)) || !num_pds) {
  1865. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  1866. "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
  1867. __func__));
  1868. return 1;
  1869. }
  1870. raid_device->num_pds = num_pds;
  1871. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1872. sizeof(Mpi2RaidVol0PhysDisk_t));
  1873. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1874. if (!vol_pg0) {
  1875. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  1876. "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
  1877. __func__));
  1878. return 1;
  1879. }
  1880. if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1881. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1882. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  1883. "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
  1884. __func__));
  1885. kfree(vol_pg0);
  1886. return 1;
  1887. }
  1888. raid_device->volume_type = vol_pg0->VolumeType;
  1889. /* figure out what the underlying devices are by
  1890. * obtaining the device_info bits for the 1st device
  1891. */
  1892. if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1893. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1894. vol_pg0->PhysDisk[0].PhysDiskNum))) {
  1895. if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  1896. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  1897. le16_to_cpu(pd_pg0.DevHandle)))) {
  1898. raid_device->device_info =
  1899. le32_to_cpu(sas_device_pg0.DeviceInfo);
  1900. }
  1901. }
  1902. kfree(vol_pg0);
  1903. return 0;
  1904. }
  1905. /**
  1906. * _scsih_enable_tlr - setting TLR flags
  1907. * @ioc: per adapter object
  1908. * @sdev: scsi device struct
  1909. *
  1910. * Enabling Transaction Layer Retries for tape devices when
  1911. * vpd page 0x90 is present
  1912. *
  1913. */
  1914. static void
  1915. _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
  1916. {
  1917. /* only for TAPE */
  1918. if (sdev->type != TYPE_TAPE)
  1919. return;
  1920. if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
  1921. return;
  1922. sas_enable_tlr(sdev);
  1923. sdev_printk(KERN_INFO, sdev, "TLR %s\n",
  1924. sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
  1925. return;
  1926. }
  1927. /**
  1928. * scsih_slave_configure - device configure routine.
  1929. * @sdev: scsi device struct
  1930. *
  1931. * Return: 0 if ok. Any other return is assumed to be an error and
  1932. * the device is ignored.
  1933. */
  1934. static int
  1935. scsih_slave_configure(struct scsi_device *sdev)
  1936. {
  1937. struct Scsi_Host *shost = sdev->host;
  1938. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  1939. struct MPT3SAS_DEVICE *sas_device_priv_data;
  1940. struct MPT3SAS_TARGET *sas_target_priv_data;
  1941. struct _sas_device *sas_device;
  1942. struct _pcie_device *pcie_device;
  1943. struct _raid_device *raid_device;
  1944. unsigned long flags;
  1945. int qdepth;
  1946. u8 ssp_target = 0;
  1947. char *ds = "";
  1948. char *r_level = "";
  1949. u16 handle, volume_handle = 0;
  1950. u64 volume_wwid = 0;
  1951. qdepth = 1;
  1952. sas_device_priv_data = sdev->hostdata;
  1953. sas_device_priv_data->configured_lun = 1;
  1954. sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
  1955. sas_target_priv_data = sas_device_priv_data->sas_target;
  1956. handle = sas_target_priv_data->handle;
  1957. /* raid volume handling */
  1958. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
  1959. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1960. raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
  1961. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1962. if (!raid_device) {
  1963. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  1964. "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
  1965. __LINE__, __func__));
  1966. return 1;
  1967. }
  1968. if (_scsih_get_volume_capabilities(ioc, raid_device)) {
  1969. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  1970. "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
  1971. __LINE__, __func__));
  1972. return 1;
  1973. }
  1974. /*
  1975. * WARPDRIVE: Initialize the required data for Direct IO
  1976. */
  1977. mpt3sas_init_warpdrive_properties(ioc, raid_device);
  1978. /* RAID Queue Depth Support
  1979. * IS volume = underlying qdepth of drive type, either
  1980. * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
  1981. * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
  1982. */
  1983. if (raid_device->device_info &
  1984. MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1985. qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
  1986. ds = "SSP";
  1987. } else {
  1988. qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
  1989. if (raid_device->device_info &
  1990. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1991. ds = "SATA";
  1992. else
  1993. ds = "STP";
  1994. }
  1995. switch (raid_device->volume_type) {
  1996. case MPI2_RAID_VOL_TYPE_RAID0:
  1997. r_level = "RAID0";
  1998. break;
  1999. case MPI2_RAID_VOL_TYPE_RAID1E:
  2000. qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
  2001. if (ioc->manu_pg10.OEMIdentifier &&
  2002. (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
  2003. MFG10_GF0_R10_DISPLAY) &&
  2004. !(raid_device->num_pds % 2))
  2005. r_level = "RAID10";
  2006. else
  2007. r_level = "RAID1E";
  2008. break;
  2009. case MPI2_RAID_VOL_TYPE_RAID1:
  2010. qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
  2011. r_level = "RAID1";
  2012. break;
  2013. case MPI2_RAID_VOL_TYPE_RAID10:
  2014. qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
  2015. r_level = "RAID10";
  2016. break;
  2017. case MPI2_RAID_VOL_TYPE_UNKNOWN:
  2018. default:
  2019. qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
  2020. r_level = "RAIDX";
  2021. break;
  2022. }
  2023. if (!ioc->hide_ir_msg)
  2024. sdev_printk(KERN_INFO, sdev,
  2025. "%s: handle(0x%04x), wwid(0x%016llx),"
  2026. " pd_count(%d), type(%s)\n",
  2027. r_level, raid_device->handle,
  2028. (unsigned long long)raid_device->wwid,
  2029. raid_device->num_pds, ds);
  2030. if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
  2031. blk_queue_max_hw_sectors(sdev->request_queue,
  2032. MPT3SAS_RAID_MAX_SECTORS);
  2033. sdev_printk(KERN_INFO, sdev,
  2034. "Set queue's max_sector to: %u\n",
  2035. MPT3SAS_RAID_MAX_SECTORS);
  2036. }
  2037. scsih_change_queue_depth(sdev, qdepth);
  2038. /* raid transport support */
  2039. if (!ioc->is_warpdrive)
  2040. _scsih_set_level(ioc, sdev, raid_device->volume_type);
  2041. return 0;
  2042. }
  2043. /* non-raid handling */
  2044. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2045. if (mpt3sas_config_get_volume_handle(ioc, handle,
  2046. &volume_handle)) {
  2047. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  2048. "failure at %s:%d/%s()!\n", ioc->name,
  2049. __FILE__, __LINE__, __func__));
  2050. return 1;
  2051. }
  2052. if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
  2053. volume_handle, &volume_wwid)) {
  2054. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  2055. "failure at %s:%d/%s()!\n", ioc->name,
  2056. __FILE__, __LINE__, __func__));
  2057. return 1;
  2058. }
  2059. }
  2060. /* PCIe handling */
  2061. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
  2062. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  2063. pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
  2064. sas_device_priv_data->sas_target->sas_address);
  2065. if (!pcie_device) {
  2066. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  2067. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  2068. "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
  2069. __LINE__, __func__));
  2070. return 1;
  2071. }
  2072. qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
  2073. ds = "NVMe";
  2074. sdev_printk(KERN_INFO, sdev,
  2075. "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
  2076. ds, handle, (unsigned long long)pcie_device->wwid,
  2077. pcie_device->port_num);
  2078. if (pcie_device->enclosure_handle != 0)
  2079. sdev_printk(KERN_INFO, sdev,
  2080. "%s: enclosure logical id(0x%016llx), slot(%d)\n",
  2081. ds,
  2082. (unsigned long long)pcie_device->enclosure_logical_id,
  2083. pcie_device->slot);
  2084. if (pcie_device->connector_name[0] != '\0')
  2085. sdev_printk(KERN_INFO, sdev,
  2086. "%s: enclosure level(0x%04x),"
  2087. "connector name( %s)\n", ds,
  2088. pcie_device->enclosure_level,
  2089. pcie_device->connector_name);
  2090. if (pcie_device->nvme_mdts)
  2091. blk_queue_max_hw_sectors(sdev->request_queue,
  2092. pcie_device->nvme_mdts/512);
  2093. pcie_device_put(pcie_device);
  2094. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  2095. scsih_change_queue_depth(sdev, qdepth);
  2096. /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
  2097. ** merged and can eliminate holes created during merging
  2098. ** operation.
  2099. **/
  2100. blk_queue_flag_set(QUEUE_FLAG_NOMERGES,
  2101. sdev->request_queue);
  2102. blk_queue_virt_boundary(sdev->request_queue,
  2103. ioc->page_size - 1);
  2104. return 0;
  2105. }
  2106. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2107. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  2108. sas_device_priv_data->sas_target->sas_address);
  2109. if (!sas_device) {
  2110. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2111. dfailprintk(ioc, pr_warn(MPT3SAS_FMT
  2112. "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
  2113. __func__));
  2114. return 1;
  2115. }
  2116. sas_device->volume_handle = volume_handle;
  2117. sas_device->volume_wwid = volume_wwid;
  2118. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  2119. qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
  2120. ssp_target = 1;
  2121. if (sas_device->device_info &
  2122. MPI2_SAS_DEVICE_INFO_SEP) {
  2123. sdev_printk(KERN_WARNING, sdev,
  2124. "set ignore_delay_remove for handle(0x%04x)\n",
  2125. sas_device_priv_data->sas_target->handle);
  2126. sas_device_priv_data->ignore_delay_remove = 1;
  2127. ds = "SES";
  2128. } else
  2129. ds = "SSP";
  2130. } else {
  2131. qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
  2132. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
  2133. ds = "STP";
  2134. else if (sas_device->device_info &
  2135. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  2136. ds = "SATA";
  2137. }
  2138. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
  2139. "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
  2140. ds, handle, (unsigned long long)sas_device->sas_address,
  2141. sas_device->phy, (unsigned long long)sas_device->device_name);
  2142. _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL);
  2143. sas_device_put(sas_device);
  2144. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2145. if (!ssp_target)
  2146. _scsih_display_sata_capabilities(ioc, handle, sdev);
  2147. scsih_change_queue_depth(sdev, qdepth);
  2148. if (ssp_target) {
  2149. sas_read_port_mode_page(sdev);
  2150. _scsih_enable_tlr(ioc, sdev);
  2151. }
  2152. return 0;
  2153. }
  2154. /**
  2155. * scsih_bios_param - fetch head, sector, cylinder info for a disk
  2156. * @sdev: scsi device struct
  2157. * @bdev: pointer to block device context
  2158. * @capacity: device size (in 512 byte sectors)
  2159. * @params: three element array to place output:
  2160. * params[0] number of heads (max 255)
  2161. * params[1] number of sectors (max 63)
  2162. * params[2] number of cylinders
  2163. */
  2164. static int
  2165. scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  2166. sector_t capacity, int params[])
  2167. {
  2168. int heads;
  2169. int sectors;
  2170. sector_t cylinders;
  2171. ulong dummy;
  2172. heads = 64;
  2173. sectors = 32;
  2174. dummy = heads * sectors;
  2175. cylinders = capacity;
  2176. sector_div(cylinders, dummy);
  2177. /*
  2178. * Handle extended translation size for logical drives
  2179. * > 1Gb
  2180. */
  2181. if ((ulong)capacity >= 0x200000) {
  2182. heads = 255;
  2183. sectors = 63;
  2184. dummy = heads * sectors;
  2185. cylinders = capacity;
  2186. sector_div(cylinders, dummy);
  2187. }
  2188. /* return result */
  2189. params[0] = heads;
  2190. params[1] = sectors;
  2191. params[2] = cylinders;
  2192. return 0;
  2193. }
  2194. /**
  2195. * _scsih_response_code - translation of device response code
  2196. * @ioc: per adapter object
  2197. * @response_code: response code returned by the device
  2198. */
  2199. static void
  2200. _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
  2201. {
  2202. char *desc;
  2203. switch (response_code) {
  2204. case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
  2205. desc = "task management request completed";
  2206. break;
  2207. case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
  2208. desc = "invalid frame";
  2209. break;
  2210. case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  2211. desc = "task management request not supported";
  2212. break;
  2213. case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
  2214. desc = "task management request failed";
  2215. break;
  2216. case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  2217. desc = "task management request succeeded";
  2218. break;
  2219. case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  2220. desc = "invalid lun";
  2221. break;
  2222. case 0xA:
  2223. desc = "overlapped tag attempted";
  2224. break;
  2225. case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  2226. desc = "task queued, however not sent to target";
  2227. break;
  2228. default:
  2229. desc = "unknown";
  2230. break;
  2231. }
  2232. pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
  2233. ioc->name, response_code, desc);
  2234. }
  2235. /**
  2236. * _scsih_tm_done - tm completion routine
  2237. * @ioc: per adapter object
  2238. * @smid: system request message index
  2239. * @msix_index: MSIX table index supplied by the OS
  2240. * @reply: reply message frame(lower 32bit addr)
  2241. * Context: none.
  2242. *
  2243. * The callback handler when using scsih_issue_tm.
  2244. *
  2245. * Return: 1 meaning mf should be freed from _base_interrupt
  2246. * 0 means the mf is freed from this function.
  2247. */
  2248. static u8
  2249. _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  2250. {
  2251. MPI2DefaultReply_t *mpi_reply;
  2252. if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
  2253. return 1;
  2254. if (ioc->tm_cmds.smid != smid)
  2255. return 1;
  2256. ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
  2257. mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
  2258. if (mpi_reply) {
  2259. memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  2260. ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
  2261. }
  2262. ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
  2263. complete(&ioc->tm_cmds.done);
  2264. return 1;
  2265. }
  2266. /**
  2267. * mpt3sas_scsih_set_tm_flag - set per target tm_busy
  2268. * @ioc: per adapter object
  2269. * @handle: device handle
  2270. *
  2271. * During taskmangement request, we need to freeze the device queue.
  2272. */
  2273. void
  2274. mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  2275. {
  2276. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2277. struct scsi_device *sdev;
  2278. u8 skip = 0;
  2279. shost_for_each_device(sdev, ioc->shost) {
  2280. if (skip)
  2281. continue;
  2282. sas_device_priv_data = sdev->hostdata;
  2283. if (!sas_device_priv_data)
  2284. continue;
  2285. if (sas_device_priv_data->sas_target->handle == handle) {
  2286. sas_device_priv_data->sas_target->tm_busy = 1;
  2287. skip = 1;
  2288. ioc->ignore_loginfos = 1;
  2289. }
  2290. }
  2291. }
  2292. /**
  2293. * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
  2294. * @ioc: per adapter object
  2295. * @handle: device handle
  2296. *
  2297. * During taskmangement request, we need to freeze the device queue.
  2298. */
  2299. void
  2300. mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  2301. {
  2302. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2303. struct scsi_device *sdev;
  2304. u8 skip = 0;
  2305. shost_for_each_device(sdev, ioc->shost) {
  2306. if (skip)
  2307. continue;
  2308. sas_device_priv_data = sdev->hostdata;
  2309. if (!sas_device_priv_data)
  2310. continue;
  2311. if (sas_device_priv_data->sas_target->handle == handle) {
  2312. sas_device_priv_data->sas_target->tm_busy = 0;
  2313. skip = 1;
  2314. ioc->ignore_loginfos = 0;
  2315. }
  2316. }
  2317. }
  2318. /**
  2319. * mpt3sas_scsih_issue_tm - main routine for sending tm requests
  2320. * @ioc: per adapter struct
  2321. * @handle: device handle
  2322. * @lun: lun number
  2323. * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  2324. * @smid_task: smid assigned to the task
  2325. * @msix_task: MSIX table index supplied by the OS
  2326. * @timeout: timeout in seconds
  2327. * @tr_method: Target Reset Method
  2328. * Context: user
  2329. *
  2330. * A generic API for sending task management requests to firmware.
  2331. *
  2332. * The callback index is set inside `ioc->tm_cb_idx`.
  2333. * The caller is responsible to check for outstanding commands.
  2334. *
  2335. * Return: SUCCESS or FAILED.
  2336. */
  2337. int
  2338. mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun,
  2339. u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method)
  2340. {
  2341. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2342. Mpi2SCSITaskManagementReply_t *mpi_reply;
  2343. u16 smid = 0;
  2344. u32 ioc_state;
  2345. int rc;
  2346. lockdep_assert_held(&ioc->tm_cmds.mutex);
  2347. if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
  2348. pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
  2349. __func__, ioc->name);
  2350. return FAILED;
  2351. }
  2352. if (ioc->shost_recovery || ioc->remove_host ||
  2353. ioc->pci_error_recovery) {
  2354. pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
  2355. __func__, ioc->name);
  2356. return FAILED;
  2357. }
  2358. ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
  2359. if (ioc_state & MPI2_DOORBELL_USED) {
  2360. dhsprintk(ioc, pr_info(MPT3SAS_FMT
  2361. "unexpected doorbell active!\n", ioc->name));
  2362. rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  2363. return (!rc) ? SUCCESS : FAILED;
  2364. }
  2365. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  2366. mpt3sas_base_fault_info(ioc, ioc_state &
  2367. MPI2_DOORBELL_DATA_MASK);
  2368. rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  2369. return (!rc) ? SUCCESS : FAILED;
  2370. }
  2371. smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
  2372. if (!smid) {
  2373. pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
  2374. ioc->name, __func__);
  2375. return FAILED;
  2376. }
  2377. dtmprintk(ioc, pr_info(MPT3SAS_FMT
  2378. "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
  2379. ioc->name, handle, type, smid_task, timeout, tr_method));
  2380. ioc->tm_cmds.status = MPT3_CMD_PENDING;
  2381. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  2382. ioc->tm_cmds.smid = smid;
  2383. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2384. memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
  2385. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2386. mpi_request->DevHandle = cpu_to_le16(handle);
  2387. mpi_request->TaskType = type;
  2388. mpi_request->MsgFlags = tr_method;
  2389. mpi_request->TaskMID = cpu_to_le16(smid_task);
  2390. int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
  2391. mpt3sas_scsih_set_tm_flag(ioc, handle);
  2392. init_completion(&ioc->tm_cmds.done);
  2393. mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
  2394. wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
  2395. if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
  2396. if (mpt3sas_base_check_cmd_timeout(ioc,
  2397. ioc->tm_cmds.status, mpi_request,
  2398. sizeof(Mpi2SCSITaskManagementRequest_t)/4)) {
  2399. rc = mpt3sas_base_hard_reset_handler(ioc,
  2400. FORCE_BIG_HAMMER);
  2401. rc = (!rc) ? SUCCESS : FAILED;
  2402. goto out;
  2403. }
  2404. }
  2405. /* sync IRQs in case those were busy during flush. */
  2406. mpt3sas_base_sync_reply_irqs(ioc);
  2407. if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
  2408. mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
  2409. mpi_reply = ioc->tm_cmds.reply;
  2410. dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
  2411. "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
  2412. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  2413. le32_to_cpu(mpi_reply->IOCLogInfo),
  2414. le32_to_cpu(mpi_reply->TerminationCount)));
  2415. if (ioc->logging_level & MPT_DEBUG_TM) {
  2416. _scsih_response_code(ioc, mpi_reply->ResponseCode);
  2417. if (mpi_reply->IOCStatus)
  2418. _debug_dump_mf(mpi_request,
  2419. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  2420. }
  2421. }
  2422. rc = SUCCESS;
  2423. out:
  2424. mpt3sas_scsih_clear_tm_flag(ioc, handle);
  2425. ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
  2426. return rc;
  2427. }
  2428. int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
  2429. u64 lun, u8 type, u16 smid_task, u16 msix_task,
  2430. u8 timeout, u8 tr_method)
  2431. {
  2432. int ret;
  2433. mutex_lock(&ioc->tm_cmds.mutex);
  2434. ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task,
  2435. msix_task, timeout, tr_method);
  2436. mutex_unlock(&ioc->tm_cmds.mutex);
  2437. return ret;
  2438. }
  2439. /**
  2440. * _scsih_tm_display_info - displays info about the device
  2441. * @ioc: per adapter struct
  2442. * @scmd: pointer to scsi command object
  2443. *
  2444. * Called by task management callback handlers.
  2445. */
  2446. static void
  2447. _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
  2448. {
  2449. struct scsi_target *starget = scmd->device->sdev_target;
  2450. struct MPT3SAS_TARGET *priv_target = starget->hostdata;
  2451. struct _sas_device *sas_device = NULL;
  2452. struct _pcie_device *pcie_device = NULL;
  2453. unsigned long flags;
  2454. char *device_str = NULL;
  2455. if (!priv_target)
  2456. return;
  2457. if (ioc->hide_ir_msg)
  2458. device_str = "WarpDrive";
  2459. else
  2460. device_str = "volume";
  2461. scsi_print_command(scmd);
  2462. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  2463. starget_printk(KERN_INFO, starget,
  2464. "%s handle(0x%04x), %s wwid(0x%016llx)\n",
  2465. device_str, priv_target->handle,
  2466. device_str, (unsigned long long)priv_target->sas_address);
  2467. } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
  2468. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  2469. pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target);
  2470. if (pcie_device) {
  2471. starget_printk(KERN_INFO, starget,
  2472. "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
  2473. pcie_device->handle,
  2474. (unsigned long long)pcie_device->wwid,
  2475. pcie_device->port_num);
  2476. if (pcie_device->enclosure_handle != 0)
  2477. starget_printk(KERN_INFO, starget,
  2478. "enclosure logical id(0x%016llx), slot(%d)\n",
  2479. (unsigned long long)
  2480. pcie_device->enclosure_logical_id,
  2481. pcie_device->slot);
  2482. if (pcie_device->connector_name[0] != '\0')
  2483. starget_printk(KERN_INFO, starget,
  2484. "enclosure level(0x%04x), connector name( %s)\n",
  2485. pcie_device->enclosure_level,
  2486. pcie_device->connector_name);
  2487. pcie_device_put(pcie_device);
  2488. }
  2489. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  2490. } else {
  2491. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2492. sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
  2493. if (sas_device) {
  2494. if (priv_target->flags &
  2495. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2496. starget_printk(KERN_INFO, starget,
  2497. "volume handle(0x%04x), "
  2498. "volume wwid(0x%016llx)\n",
  2499. sas_device->volume_handle,
  2500. (unsigned long long)sas_device->volume_wwid);
  2501. }
  2502. starget_printk(KERN_INFO, starget,
  2503. "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
  2504. sas_device->handle,
  2505. (unsigned long long)sas_device->sas_address,
  2506. sas_device->phy);
  2507. _scsih_display_enclosure_chassis_info(NULL, sas_device,
  2508. NULL, starget);
  2509. sas_device_put(sas_device);
  2510. }
  2511. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2512. }
  2513. }
  2514. /**
  2515. * scsih_abort - eh threads main abort routine
  2516. * @scmd: pointer to scsi command object
  2517. *
  2518. * Return: SUCCESS if command aborted else FAILED
  2519. */
  2520. static int
  2521. scsih_abort(struct scsi_cmnd *scmd)
  2522. {
  2523. struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2524. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2525. struct scsiio_tracker *st = scsi_cmd_priv(scmd);
  2526. u16 handle;
  2527. int r;
  2528. u8 timeout = 30;
  2529. struct _pcie_device *pcie_device = NULL;
  2530. sdev_printk(KERN_INFO, scmd->device,
  2531. "attempting task abort! scmd(%p)\n", scmd);
  2532. _scsih_tm_display_info(ioc, scmd);
  2533. sas_device_priv_data = scmd->device->hostdata;
  2534. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  2535. ioc->remove_host) {
  2536. sdev_printk(KERN_INFO, scmd->device,
  2537. "device been deleted! scmd(%p)\n", scmd);
  2538. scmd->result = DID_NO_CONNECT << 16;
  2539. scmd->scsi_done(scmd);
  2540. r = SUCCESS;
  2541. goto out;
  2542. }
  2543. /* check for completed command */
  2544. if (st == NULL || st->cb_idx == 0xFF) {
  2545. scmd->result = DID_RESET << 16;
  2546. r = SUCCESS;
  2547. goto out;
  2548. }
  2549. /* for hidden raid components and volumes this is not supported */
  2550. if (sas_device_priv_data->sas_target->flags &
  2551. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  2552. sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  2553. scmd->result = DID_RESET << 16;
  2554. r = FAILED;
  2555. goto out;
  2556. }
  2557. mpt3sas_halt_firmware(ioc);
  2558. handle = sas_device_priv_data->sas_target->handle;
  2559. pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
  2560. if (pcie_device && (!ioc->tm_custom_handling))
  2561. timeout = ioc->nvme_abort_timeout;
  2562. r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
  2563. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  2564. st->smid, st->msix_io, timeout, 0);
  2565. /* Command must be cleared after abort */
  2566. if (r == SUCCESS && st->cb_idx != 0xFF)
  2567. r = FAILED;
  2568. out:
  2569. sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
  2570. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2571. if (pcie_device)
  2572. pcie_device_put(pcie_device);
  2573. return r;
  2574. }
  2575. /**
  2576. * scsih_dev_reset - eh threads main device reset routine
  2577. * @scmd: pointer to scsi command object
  2578. *
  2579. * Return: SUCCESS if command aborted else FAILED
  2580. */
  2581. static int
  2582. scsih_dev_reset(struct scsi_cmnd *scmd)
  2583. {
  2584. struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2585. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2586. struct _sas_device *sas_device = NULL;
  2587. struct _pcie_device *pcie_device = NULL;
  2588. u16 handle;
  2589. u8 tr_method = 0;
  2590. u8 tr_timeout = 30;
  2591. int r;
  2592. struct scsi_target *starget = scmd->device->sdev_target;
  2593. struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
  2594. sdev_printk(KERN_INFO, scmd->device,
  2595. "attempting device reset! scmd(%p)\n", scmd);
  2596. _scsih_tm_display_info(ioc, scmd);
  2597. sas_device_priv_data = scmd->device->hostdata;
  2598. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  2599. ioc->remove_host) {
  2600. sdev_printk(KERN_INFO, scmd->device,
  2601. "device been deleted! scmd(%p)\n", scmd);
  2602. scmd->result = DID_NO_CONNECT << 16;
  2603. scmd->scsi_done(scmd);
  2604. r = SUCCESS;
  2605. goto out;
  2606. }
  2607. /* for hidden raid components obtain the volume_handle */
  2608. handle = 0;
  2609. if (sas_device_priv_data->sas_target->flags &
  2610. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2611. sas_device = mpt3sas_get_sdev_from_target(ioc,
  2612. target_priv_data);
  2613. if (sas_device)
  2614. handle = sas_device->volume_handle;
  2615. } else
  2616. handle = sas_device_priv_data->sas_target->handle;
  2617. if (!handle) {
  2618. scmd->result = DID_RESET << 16;
  2619. r = FAILED;
  2620. goto out;
  2621. }
  2622. pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
  2623. if (pcie_device && (!ioc->tm_custom_handling)) {
  2624. tr_timeout = pcie_device->reset_timeout;
  2625. tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
  2626. } else
  2627. tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
  2628. r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
  2629. MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0,
  2630. tr_timeout, tr_method);
  2631. /* Check for busy commands after reset */
  2632. if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
  2633. r = FAILED;
  2634. out:
  2635. sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
  2636. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2637. if (sas_device)
  2638. sas_device_put(sas_device);
  2639. if (pcie_device)
  2640. pcie_device_put(pcie_device);
  2641. return r;
  2642. }
  2643. /**
  2644. * scsih_target_reset - eh threads main target reset routine
  2645. * @scmd: pointer to scsi command object
  2646. *
  2647. * Return: SUCCESS if command aborted else FAILED
  2648. */
  2649. static int
  2650. scsih_target_reset(struct scsi_cmnd *scmd)
  2651. {
  2652. struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2653. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2654. struct _sas_device *sas_device = NULL;
  2655. struct _pcie_device *pcie_device = NULL;
  2656. u16 handle;
  2657. u8 tr_method = 0;
  2658. u8 tr_timeout = 30;
  2659. int r;
  2660. struct scsi_target *starget = scmd->device->sdev_target;
  2661. struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
  2662. starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
  2663. scmd);
  2664. _scsih_tm_display_info(ioc, scmd);
  2665. sas_device_priv_data = scmd->device->hostdata;
  2666. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  2667. ioc->remove_host) {
  2668. starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
  2669. scmd);
  2670. scmd->result = DID_NO_CONNECT << 16;
  2671. scmd->scsi_done(scmd);
  2672. r = SUCCESS;
  2673. goto out;
  2674. }
  2675. /* for hidden raid components obtain the volume_handle */
  2676. handle = 0;
  2677. if (sas_device_priv_data->sas_target->flags &
  2678. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2679. sas_device = mpt3sas_get_sdev_from_target(ioc,
  2680. target_priv_data);
  2681. if (sas_device)
  2682. handle = sas_device->volume_handle;
  2683. } else
  2684. handle = sas_device_priv_data->sas_target->handle;
  2685. if (!handle) {
  2686. scmd->result = DID_RESET << 16;
  2687. r = FAILED;
  2688. goto out;
  2689. }
  2690. pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
  2691. if (pcie_device && (!ioc->tm_custom_handling)) {
  2692. tr_timeout = pcie_device->reset_timeout;
  2693. tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
  2694. } else
  2695. tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
  2696. r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0,
  2697. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0,
  2698. tr_timeout, tr_method);
  2699. /* Check for busy commands after reset */
  2700. if (r == SUCCESS && atomic_read(&starget->target_busy))
  2701. r = FAILED;
  2702. out:
  2703. starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
  2704. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2705. if (sas_device)
  2706. sas_device_put(sas_device);
  2707. if (pcie_device)
  2708. pcie_device_put(pcie_device);
  2709. return r;
  2710. }
  2711. /**
  2712. * scsih_host_reset - eh threads main host reset routine
  2713. * @scmd: pointer to scsi command object
  2714. *
  2715. * Return: SUCCESS if command aborted else FAILED
  2716. */
  2717. static int
  2718. scsih_host_reset(struct scsi_cmnd *scmd)
  2719. {
  2720. struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2721. int r, retval;
  2722. pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
  2723. ioc->name, scmd);
  2724. scsi_print_command(scmd);
  2725. if (ioc->is_driver_loading || ioc->remove_host) {
  2726. pr_info(MPT3SAS_FMT "Blocking the host reset\n",
  2727. ioc->name);
  2728. r = FAILED;
  2729. goto out;
  2730. }
  2731. retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  2732. r = (retval < 0) ? FAILED : SUCCESS;
  2733. out:
  2734. pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
  2735. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2736. return r;
  2737. }
  2738. /**
  2739. * _scsih_fw_event_add - insert and queue up fw_event
  2740. * @ioc: per adapter object
  2741. * @fw_event: object describing the event
  2742. * Context: This function will acquire ioc->fw_event_lock.
  2743. *
  2744. * This adds the firmware event object into link list, then queues it up to
  2745. * be processed from user context.
  2746. */
  2747. static void
  2748. _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  2749. {
  2750. unsigned long flags;
  2751. if (ioc->firmware_event_thread == NULL)
  2752. return;
  2753. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2754. fw_event_work_get(fw_event);
  2755. INIT_LIST_HEAD(&fw_event->list);
  2756. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  2757. INIT_WORK(&fw_event->work, _firmware_event_work);
  2758. fw_event_work_get(fw_event);
  2759. queue_work(ioc->firmware_event_thread, &fw_event->work);
  2760. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2761. }
  2762. /**
  2763. * _scsih_fw_event_del_from_list - delete fw_event from the list
  2764. * @ioc: per adapter object
  2765. * @fw_event: object describing the event
  2766. * Context: This function will acquire ioc->fw_event_lock.
  2767. *
  2768. * If the fw_event is on the fw_event_list, remove it and do a put.
  2769. */
  2770. static void
  2771. _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
  2772. *fw_event)
  2773. {
  2774. unsigned long flags;
  2775. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2776. if (!list_empty(&fw_event->list)) {
  2777. list_del_init(&fw_event->list);
  2778. fw_event_work_put(fw_event);
  2779. }
  2780. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2781. }
  2782. /**
  2783. * mpt3sas_send_trigger_data_event - send event for processing trigger data
  2784. * @ioc: per adapter object
  2785. * @event_data: trigger event data
  2786. */
  2787. void
  2788. mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
  2789. struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
  2790. {
  2791. struct fw_event_work *fw_event;
  2792. u16 sz;
  2793. if (ioc->is_driver_loading)
  2794. return;
  2795. sz = sizeof(*event_data);
  2796. fw_event = alloc_fw_event_work(sz);
  2797. if (!fw_event)
  2798. return;
  2799. fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
  2800. fw_event->ioc = ioc;
  2801. memcpy(fw_event->event_data, event_data, sizeof(*event_data));
  2802. _scsih_fw_event_add(ioc, fw_event);
  2803. fw_event_work_put(fw_event);
  2804. }
  2805. /**
  2806. * _scsih_error_recovery_delete_devices - remove devices not responding
  2807. * @ioc: per adapter object
  2808. */
  2809. static void
  2810. _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
  2811. {
  2812. struct fw_event_work *fw_event;
  2813. if (ioc->is_driver_loading)
  2814. return;
  2815. fw_event = alloc_fw_event_work(0);
  2816. if (!fw_event)
  2817. return;
  2818. fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
  2819. fw_event->ioc = ioc;
  2820. _scsih_fw_event_add(ioc, fw_event);
  2821. fw_event_work_put(fw_event);
  2822. }
  2823. /**
  2824. * mpt3sas_port_enable_complete - port enable completed (fake event)
  2825. * @ioc: per adapter object
  2826. */
  2827. void
  2828. mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
  2829. {
  2830. struct fw_event_work *fw_event;
  2831. fw_event = alloc_fw_event_work(0);
  2832. if (!fw_event)
  2833. return;
  2834. fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
  2835. fw_event->ioc = ioc;
  2836. _scsih_fw_event_add(ioc, fw_event);
  2837. fw_event_work_put(fw_event);
  2838. }
  2839. static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
  2840. {
  2841. unsigned long flags;
  2842. struct fw_event_work *fw_event = NULL;
  2843. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2844. if (!list_empty(&ioc->fw_event_list)) {
  2845. fw_event = list_first_entry(&ioc->fw_event_list,
  2846. struct fw_event_work, list);
  2847. list_del_init(&fw_event->list);
  2848. }
  2849. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2850. return fw_event;
  2851. }
  2852. /**
  2853. * _scsih_fw_event_cleanup_queue - cleanup event queue
  2854. * @ioc: per adapter object
  2855. *
  2856. * Walk the firmware event queue, either killing timers, or waiting
  2857. * for outstanding events to complete
  2858. */
  2859. static void
  2860. _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
  2861. {
  2862. struct fw_event_work *fw_event;
  2863. if (list_empty(&ioc->fw_event_list) ||
  2864. !ioc->firmware_event_thread || in_interrupt())
  2865. return;
  2866. while ((fw_event = dequeue_next_fw_event(ioc))) {
  2867. /*
  2868. * Wait on the fw_event to complete. If this returns 1, then
  2869. * the event was never executed, and we need a put for the
  2870. * reference the work had on the fw_event.
  2871. *
  2872. * If it did execute, we wait for it to finish, and the put will
  2873. * happen from _firmware_event_work()
  2874. */
  2875. if (cancel_work_sync(&fw_event->work))
  2876. fw_event_work_put(fw_event);
  2877. fw_event_work_put(fw_event);
  2878. }
  2879. }
  2880. /**
  2881. * _scsih_internal_device_block - block the sdev device
  2882. * @sdev: per device object
  2883. * @sas_device_priv_data : per device driver private data
  2884. *
  2885. * make sure device is blocked without error, if not
  2886. * print an error
  2887. */
  2888. static void
  2889. _scsih_internal_device_block(struct scsi_device *sdev,
  2890. struct MPT3SAS_DEVICE *sas_device_priv_data)
  2891. {
  2892. int r = 0;
  2893. sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
  2894. sas_device_priv_data->sas_target->handle);
  2895. sas_device_priv_data->block = 1;
  2896. r = scsi_internal_device_block_nowait(sdev);
  2897. if (r == -EINVAL)
  2898. sdev_printk(KERN_WARNING, sdev,
  2899. "device_block failed with return(%d) for handle(0x%04x)\n",
  2900. r, sas_device_priv_data->sas_target->handle);
  2901. }
  2902. /**
  2903. * _scsih_internal_device_unblock - unblock the sdev device
  2904. * @sdev: per device object
  2905. * @sas_device_priv_data : per device driver private data
  2906. * make sure device is unblocked without error, if not retry
  2907. * by blocking and then unblocking
  2908. */
  2909. static void
  2910. _scsih_internal_device_unblock(struct scsi_device *sdev,
  2911. struct MPT3SAS_DEVICE *sas_device_priv_data)
  2912. {
  2913. int r = 0;
  2914. sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
  2915. "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
  2916. sas_device_priv_data->block = 0;
  2917. r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
  2918. if (r == -EINVAL) {
  2919. /* The device has been set to SDEV_RUNNING by SD layer during
  2920. * device addition but the request queue is still stopped by
  2921. * our earlier block call. We need to perform a block again
  2922. * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
  2923. sdev_printk(KERN_WARNING, sdev,
  2924. "device_unblock failed with return(%d) for handle(0x%04x) "
  2925. "performing a block followed by an unblock\n",
  2926. r, sas_device_priv_data->sas_target->handle);
  2927. sas_device_priv_data->block = 1;
  2928. r = scsi_internal_device_block_nowait(sdev);
  2929. if (r)
  2930. sdev_printk(KERN_WARNING, sdev, "retried device_block "
  2931. "failed with return(%d) for handle(0x%04x)\n",
  2932. r, sas_device_priv_data->sas_target->handle);
  2933. sas_device_priv_data->block = 0;
  2934. r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
  2935. if (r)
  2936. sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
  2937. " failed with return(%d) for handle(0x%04x)\n",
  2938. r, sas_device_priv_data->sas_target->handle);
  2939. }
  2940. }
  2941. /**
  2942. * _scsih_ublock_io_all_device - unblock every device
  2943. * @ioc: per adapter object
  2944. *
  2945. * change the device state from block to running
  2946. */
  2947. static void
  2948. _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
  2949. {
  2950. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2951. struct scsi_device *sdev;
  2952. shost_for_each_device(sdev, ioc->shost) {
  2953. sas_device_priv_data = sdev->hostdata;
  2954. if (!sas_device_priv_data)
  2955. continue;
  2956. if (!sas_device_priv_data->block)
  2957. continue;
  2958. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2959. "device_running, handle(0x%04x)\n",
  2960. sas_device_priv_data->sas_target->handle));
  2961. _scsih_internal_device_unblock(sdev, sas_device_priv_data);
  2962. }
  2963. }
  2964. /**
  2965. * _scsih_ublock_io_device - prepare device to be deleted
  2966. * @ioc: per adapter object
  2967. * @sas_address: sas address
  2968. *
  2969. * unblock then put device in offline state
  2970. */
  2971. static void
  2972. _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
  2973. {
  2974. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2975. struct scsi_device *sdev;
  2976. shost_for_each_device(sdev, ioc->shost) {
  2977. sas_device_priv_data = sdev->hostdata;
  2978. if (!sas_device_priv_data)
  2979. continue;
  2980. if (sas_device_priv_data->sas_target->sas_address
  2981. != sas_address)
  2982. continue;
  2983. if (sas_device_priv_data->block)
  2984. _scsih_internal_device_unblock(sdev,
  2985. sas_device_priv_data);
  2986. }
  2987. }
  2988. /**
  2989. * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
  2990. * @ioc: per adapter object
  2991. *
  2992. * During device pull we need to appropriately set the sdev state.
  2993. */
  2994. static void
  2995. _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
  2996. {
  2997. struct MPT3SAS_DEVICE *sas_device_priv_data;
  2998. struct scsi_device *sdev;
  2999. shost_for_each_device(sdev, ioc->shost) {
  3000. sas_device_priv_data = sdev->hostdata;
  3001. if (!sas_device_priv_data)
  3002. continue;
  3003. if (sas_device_priv_data->block)
  3004. continue;
  3005. if (sas_device_priv_data->ignore_delay_remove) {
  3006. sdev_printk(KERN_INFO, sdev,
  3007. "%s skip device_block for SES handle(0x%04x)\n",
  3008. __func__, sas_device_priv_data->sas_target->handle);
  3009. continue;
  3010. }
  3011. _scsih_internal_device_block(sdev, sas_device_priv_data);
  3012. }
  3013. }
  3014. /**
  3015. * _scsih_block_io_device - set the device state to SDEV_BLOCK
  3016. * @ioc: per adapter object
  3017. * @handle: device handle
  3018. *
  3019. * During device pull we need to appropriately set the sdev state.
  3020. */
  3021. static void
  3022. _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  3023. {
  3024. struct MPT3SAS_DEVICE *sas_device_priv_data;
  3025. struct scsi_device *sdev;
  3026. struct _sas_device *sas_device;
  3027. sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
  3028. shost_for_each_device(sdev, ioc->shost) {
  3029. sas_device_priv_data = sdev->hostdata;
  3030. if (!sas_device_priv_data)
  3031. continue;
  3032. if (sas_device_priv_data->sas_target->handle != handle)
  3033. continue;
  3034. if (sas_device_priv_data->block)
  3035. continue;
  3036. if (sas_device && sas_device->pend_sas_rphy_add)
  3037. continue;
  3038. if (sas_device_priv_data->ignore_delay_remove) {
  3039. sdev_printk(KERN_INFO, sdev,
  3040. "%s skip device_block for SES handle(0x%04x)\n",
  3041. __func__, sas_device_priv_data->sas_target->handle);
  3042. continue;
  3043. }
  3044. _scsih_internal_device_block(sdev, sas_device_priv_data);
  3045. }
  3046. if (sas_device)
  3047. sas_device_put(sas_device);
  3048. }
  3049. /**
  3050. * _scsih_block_io_to_children_attached_to_ex
  3051. * @ioc: per adapter object
  3052. * @sas_expander: the sas_device object
  3053. *
  3054. * This routine set sdev state to SDEV_BLOCK for all devices
  3055. * attached to this expander. This function called when expander is
  3056. * pulled.
  3057. */
  3058. static void
  3059. _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
  3060. struct _sas_node *sas_expander)
  3061. {
  3062. struct _sas_port *mpt3sas_port;
  3063. struct _sas_device *sas_device;
  3064. struct _sas_node *expander_sibling;
  3065. unsigned long flags;
  3066. if (!sas_expander)
  3067. return;
  3068. list_for_each_entry(mpt3sas_port,
  3069. &sas_expander->sas_port_list, port_list) {
  3070. if (mpt3sas_port->remote_identify.device_type ==
  3071. SAS_END_DEVICE) {
  3072. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3073. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  3074. mpt3sas_port->remote_identify.sas_address);
  3075. if (sas_device) {
  3076. set_bit(sas_device->handle,
  3077. ioc->blocking_handles);
  3078. sas_device_put(sas_device);
  3079. }
  3080. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3081. }
  3082. }
  3083. list_for_each_entry(mpt3sas_port,
  3084. &sas_expander->sas_port_list, port_list) {
  3085. if (mpt3sas_port->remote_identify.device_type ==
  3086. SAS_EDGE_EXPANDER_DEVICE ||
  3087. mpt3sas_port->remote_identify.device_type ==
  3088. SAS_FANOUT_EXPANDER_DEVICE) {
  3089. expander_sibling =
  3090. mpt3sas_scsih_expander_find_by_sas_address(
  3091. ioc, mpt3sas_port->remote_identify.sas_address);
  3092. _scsih_block_io_to_children_attached_to_ex(ioc,
  3093. expander_sibling);
  3094. }
  3095. }
  3096. }
  3097. /**
  3098. * _scsih_block_io_to_children_attached_directly
  3099. * @ioc: per adapter object
  3100. * @event_data: topology change event data
  3101. *
  3102. * This routine set sdev state to SDEV_BLOCK for all devices
  3103. * direct attached during device pull.
  3104. */
  3105. static void
  3106. _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
  3107. Mpi2EventDataSasTopologyChangeList_t *event_data)
  3108. {
  3109. int i;
  3110. u16 handle;
  3111. u16 reason_code;
  3112. for (i = 0; i < event_data->NumEntries; i++) {
  3113. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3114. if (!handle)
  3115. continue;
  3116. reason_code = event_data->PHY[i].PhyStatus &
  3117. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3118. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
  3119. _scsih_block_io_device(ioc, handle);
  3120. }
  3121. }
  3122. /**
  3123. * _scsih_block_io_to_pcie_children_attached_directly
  3124. * @ioc: per adapter object
  3125. * @event_data: topology change event data
  3126. *
  3127. * This routine set sdev state to SDEV_BLOCK for all devices
  3128. * direct attached during device pull/reconnect.
  3129. */
  3130. static void
  3131. _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
  3132. Mpi26EventDataPCIeTopologyChangeList_t *event_data)
  3133. {
  3134. int i;
  3135. u16 handle;
  3136. u16 reason_code;
  3137. for (i = 0; i < event_data->NumEntries; i++) {
  3138. handle =
  3139. le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
  3140. if (!handle)
  3141. continue;
  3142. reason_code = event_data->PortEntry[i].PortStatus;
  3143. if (reason_code ==
  3144. MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING)
  3145. _scsih_block_io_device(ioc, handle);
  3146. }
  3147. }
  3148. /**
  3149. * _scsih_tm_tr_send - send task management request
  3150. * @ioc: per adapter object
  3151. * @handle: device handle
  3152. * Context: interrupt time.
  3153. *
  3154. * This code is to initiate the device removal handshake protocol
  3155. * with controller firmware. This function will issue target reset
  3156. * using high priority request queue. It will send a sas iounit
  3157. * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
  3158. *
  3159. * This is designed to send muliple task management request at the same
  3160. * time to the fifo. If the fifo is full, we will append the request,
  3161. * and process it in a future completion.
  3162. */
  3163. static void
  3164. _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  3165. {
  3166. Mpi2SCSITaskManagementRequest_t *mpi_request;
  3167. u16 smid;
  3168. struct _sas_device *sas_device = NULL;
  3169. struct _pcie_device *pcie_device = NULL;
  3170. struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
  3171. u64 sas_address = 0;
  3172. unsigned long flags;
  3173. struct _tr_list *delayed_tr;
  3174. u32 ioc_state;
  3175. u8 tr_method = 0;
  3176. if (ioc->pci_error_recovery) {
  3177. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3178. "%s: host in pci error recovery: handle(0x%04x)\n",
  3179. __func__, ioc->name,
  3180. handle));
  3181. return;
  3182. }
  3183. ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
  3184. if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  3185. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3186. "%s: host is not operational: handle(0x%04x)\n",
  3187. __func__, ioc->name,
  3188. handle));
  3189. return;
  3190. }
  3191. /* if PD, then return */
  3192. if (test_bit(handle, ioc->pd_handles))
  3193. return;
  3194. clear_bit(handle, ioc->pend_os_device_add);
  3195. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3196. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  3197. if (sas_device && sas_device->starget &&
  3198. sas_device->starget->hostdata) {
  3199. sas_target_priv_data = sas_device->starget->hostdata;
  3200. sas_target_priv_data->deleted = 1;
  3201. sas_address = sas_device->sas_address;
  3202. }
  3203. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3204. if (!sas_device) {
  3205. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  3206. pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
  3207. if (pcie_device && pcie_device->starget &&
  3208. pcie_device->starget->hostdata) {
  3209. sas_target_priv_data = pcie_device->starget->hostdata;
  3210. sas_target_priv_data->deleted = 1;
  3211. sas_address = pcie_device->wwid;
  3212. }
  3213. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  3214. if (pcie_device && (!ioc->tm_custom_handling))
  3215. tr_method =
  3216. MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
  3217. else
  3218. tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
  3219. }
  3220. if (sas_target_priv_data) {
  3221. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3222. "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
  3223. ioc->name, handle,
  3224. (unsigned long long)sas_address));
  3225. if (sas_device) {
  3226. if (sas_device->enclosure_handle != 0)
  3227. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3228. "setting delete flag:enclosure logical "
  3229. "id(0x%016llx), slot(%d)\n", ioc->name,
  3230. (unsigned long long)
  3231. sas_device->enclosure_logical_id,
  3232. sas_device->slot));
  3233. if (sas_device->connector_name[0] != '\0')
  3234. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3235. "setting delete flag: enclosure "
  3236. "level(0x%04x), connector name( %s)\n",
  3237. ioc->name, sas_device->enclosure_level,
  3238. sas_device->connector_name));
  3239. } else if (pcie_device) {
  3240. if (pcie_device->enclosure_handle != 0)
  3241. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3242. "setting delete flag: logical "
  3243. "id(0x%016llx), slot(%d)\n", ioc->name,
  3244. (unsigned long long)
  3245. pcie_device->enclosure_logical_id,
  3246. pcie_device->slot));
  3247. if (pcie_device->connector_name[0] != '\0')
  3248. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3249. "setting delete flag:, enclosure "
  3250. "level(0x%04x), "
  3251. "connector name( %s)\n", ioc->name,
  3252. pcie_device->enclosure_level,
  3253. pcie_device->connector_name));
  3254. }
  3255. _scsih_ublock_io_device(ioc, sas_address);
  3256. sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
  3257. }
  3258. smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
  3259. if (!smid) {
  3260. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  3261. if (!delayed_tr)
  3262. goto out;
  3263. INIT_LIST_HEAD(&delayed_tr->list);
  3264. delayed_tr->handle = handle;
  3265. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  3266. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3267. "DELAYED:tr:handle(0x%04x), (open)\n",
  3268. ioc->name, handle));
  3269. goto out;
  3270. }
  3271. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3272. "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
  3273. ioc->name, handle, smid,
  3274. ioc->tm_tr_cb_idx));
  3275. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  3276. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  3277. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  3278. mpi_request->DevHandle = cpu_to_le16(handle);
  3279. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  3280. mpi_request->MsgFlags = tr_method;
  3281. set_bit(handle, ioc->device_remove_in_progress);
  3282. mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
  3283. mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
  3284. out:
  3285. if (sas_device)
  3286. sas_device_put(sas_device);
  3287. if (pcie_device)
  3288. pcie_device_put(pcie_device);
  3289. }
  3290. /**
  3291. * _scsih_tm_tr_complete -
  3292. * @ioc: per adapter object
  3293. * @smid: system request message index
  3294. * @msix_index: MSIX table index supplied by the OS
  3295. * @reply: reply message frame(lower 32bit addr)
  3296. * Context: interrupt time.
  3297. *
  3298. * This is the target reset completion routine.
  3299. * This code is part of the code to initiate the device removal
  3300. * handshake protocol with controller firmware.
  3301. * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
  3302. *
  3303. * Return: 1 meaning mf should be freed from _base_interrupt
  3304. * 0 means the mf is freed from this function.
  3305. */
  3306. static u8
  3307. _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  3308. u32 reply)
  3309. {
  3310. u16 handle;
  3311. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  3312. Mpi2SCSITaskManagementReply_t *mpi_reply =
  3313. mpt3sas_base_get_reply_virt_addr(ioc, reply);
  3314. Mpi2SasIoUnitControlRequest_t *mpi_request;
  3315. u16 smid_sas_ctrl;
  3316. u32 ioc_state;
  3317. struct _sc_list *delayed_sc;
  3318. if (ioc->pci_error_recovery) {
  3319. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3320. "%s: host in pci error recovery\n", __func__,
  3321. ioc->name));
  3322. return 1;
  3323. }
  3324. ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
  3325. if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  3326. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3327. "%s: host is not operational\n", __func__, ioc->name));
  3328. return 1;
  3329. }
  3330. if (unlikely(!mpi_reply)) {
  3331. pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
  3332. ioc->name, __FILE__, __LINE__, __func__);
  3333. return 1;
  3334. }
  3335. mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
  3336. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  3337. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  3338. dewtprintk(ioc, pr_err(MPT3SAS_FMT
  3339. "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
  3340. ioc->name, handle,
  3341. le16_to_cpu(mpi_reply->DevHandle), smid));
  3342. return 0;
  3343. }
  3344. mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
  3345. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3346. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  3347. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  3348. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  3349. le32_to_cpu(mpi_reply->IOCLogInfo),
  3350. le32_to_cpu(mpi_reply->TerminationCount)));
  3351. smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
  3352. if (!smid_sas_ctrl) {
  3353. delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
  3354. if (!delayed_sc)
  3355. return _scsih_check_for_pending_tm(ioc, smid);
  3356. INIT_LIST_HEAD(&delayed_sc->list);
  3357. delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle);
  3358. list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
  3359. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3360. "DELAYED:sc:handle(0x%04x), (open)\n",
  3361. ioc->name, handle));
  3362. return _scsih_check_for_pending_tm(ioc, smid);
  3363. }
  3364. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3365. "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
  3366. ioc->name, handle, smid_sas_ctrl,
  3367. ioc->tm_sas_control_cb_idx));
  3368. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
  3369. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  3370. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  3371. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  3372. mpi_request->DevHandle = mpi_request_tm->DevHandle;
  3373. mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
  3374. return _scsih_check_for_pending_tm(ioc, smid);
  3375. }
  3376. /** _scsih_allow_scmd_to_device - check whether scmd needs to
  3377. * issue to IOC or not.
  3378. * @ioc: per adapter object
  3379. * @scmd: pointer to scsi command object
  3380. *
  3381. * Returns true if scmd can be issued to IOC otherwise returns false.
  3382. */
  3383. inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
  3384. struct scsi_cmnd *scmd)
  3385. {
  3386. if (ioc->pci_error_recovery)
  3387. return false;
  3388. if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
  3389. if (ioc->remove_host)
  3390. return false;
  3391. return true;
  3392. }
  3393. if (ioc->remove_host) {
  3394. switch (scmd->cmnd[0]) {
  3395. case SYNCHRONIZE_CACHE:
  3396. case START_STOP:
  3397. return true;
  3398. default:
  3399. return false;
  3400. }
  3401. }
  3402. return true;
  3403. }
  3404. /**
  3405. * _scsih_sas_control_complete - completion routine
  3406. * @ioc: per adapter object
  3407. * @smid: system request message index
  3408. * @msix_index: MSIX table index supplied by the OS
  3409. * @reply: reply message frame(lower 32bit addr)
  3410. * Context: interrupt time.
  3411. *
  3412. * This is the sas iounit control completion routine.
  3413. * This code is part of the code to initiate the device removal
  3414. * handshake protocol with controller firmware.
  3415. *
  3416. * Return: 1 meaning mf should be freed from _base_interrupt
  3417. * 0 means the mf is freed from this function.
  3418. */
  3419. static u8
  3420. _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
  3421. u8 msix_index, u32 reply)
  3422. {
  3423. Mpi2SasIoUnitControlReply_t *mpi_reply =
  3424. mpt3sas_base_get_reply_virt_addr(ioc, reply);
  3425. if (likely(mpi_reply)) {
  3426. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3427. "sc_complete:handle(0x%04x), (open) "
  3428. "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
  3429. ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
  3430. le16_to_cpu(mpi_reply->IOCStatus),
  3431. le32_to_cpu(mpi_reply->IOCLogInfo)));
  3432. if (le16_to_cpu(mpi_reply->IOCStatus) ==
  3433. MPI2_IOCSTATUS_SUCCESS) {
  3434. clear_bit(le16_to_cpu(mpi_reply->DevHandle),
  3435. ioc->device_remove_in_progress);
  3436. }
  3437. } else {
  3438. pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
  3439. ioc->name, __FILE__, __LINE__, __func__);
  3440. }
  3441. return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
  3442. }
  3443. /**
  3444. * _scsih_tm_tr_volume_send - send target reset request for volumes
  3445. * @ioc: per adapter object
  3446. * @handle: device handle
  3447. * Context: interrupt time.
  3448. *
  3449. * This is designed to send muliple task management request at the same
  3450. * time to the fifo. If the fifo is full, we will append the request,
  3451. * and process it in a future completion.
  3452. */
  3453. static void
  3454. _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  3455. {
  3456. Mpi2SCSITaskManagementRequest_t *mpi_request;
  3457. u16 smid;
  3458. struct _tr_list *delayed_tr;
  3459. if (ioc->pci_error_recovery) {
  3460. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3461. "%s: host reset in progress!\n",
  3462. __func__, ioc->name));
  3463. return;
  3464. }
  3465. smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
  3466. if (!smid) {
  3467. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  3468. if (!delayed_tr)
  3469. return;
  3470. INIT_LIST_HEAD(&delayed_tr->list);
  3471. delayed_tr->handle = handle;
  3472. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
  3473. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3474. "DELAYED:tr:handle(0x%04x), (open)\n",
  3475. ioc->name, handle));
  3476. return;
  3477. }
  3478. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3479. "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
  3480. ioc->name, handle, smid,
  3481. ioc->tm_tr_volume_cb_idx));
  3482. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  3483. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  3484. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  3485. mpi_request->DevHandle = cpu_to_le16(handle);
  3486. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  3487. mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
  3488. }
  3489. /**
  3490. * _scsih_tm_volume_tr_complete - target reset completion
  3491. * @ioc: per adapter object
  3492. * @smid: system request message index
  3493. * @msix_index: MSIX table index supplied by the OS
  3494. * @reply: reply message frame(lower 32bit addr)
  3495. * Context: interrupt time.
  3496. *
  3497. * Return: 1 meaning mf should be freed from _base_interrupt
  3498. * 0 means the mf is freed from this function.
  3499. */
  3500. static u8
  3501. _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
  3502. u8 msix_index, u32 reply)
  3503. {
  3504. u16 handle;
  3505. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  3506. Mpi2SCSITaskManagementReply_t *mpi_reply =
  3507. mpt3sas_base_get_reply_virt_addr(ioc, reply);
  3508. if (ioc->shost_recovery || ioc->pci_error_recovery) {
  3509. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3510. "%s: host reset in progress!\n",
  3511. __func__, ioc->name));
  3512. return 1;
  3513. }
  3514. if (unlikely(!mpi_reply)) {
  3515. pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
  3516. ioc->name, __FILE__, __LINE__, __func__);
  3517. return 1;
  3518. }
  3519. mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
  3520. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  3521. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  3522. dewtprintk(ioc, pr_err(MPT3SAS_FMT
  3523. "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
  3524. ioc->name, handle,
  3525. le16_to_cpu(mpi_reply->DevHandle), smid));
  3526. return 0;
  3527. }
  3528. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3529. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  3530. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  3531. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  3532. le32_to_cpu(mpi_reply->IOCLogInfo),
  3533. le32_to_cpu(mpi_reply->TerminationCount)));
  3534. return _scsih_check_for_pending_tm(ioc, smid);
  3535. }
  3536. /**
  3537. * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
  3538. * @ioc: per adapter object
  3539. * @smid: system request message index
  3540. * @event: Event ID
  3541. * @event_context: used to track events uniquely
  3542. *
  3543. * Context - processed in interrupt context.
  3544. */
  3545. static void
  3546. _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event,
  3547. U32 event_context)
  3548. {
  3549. Mpi2EventAckRequest_t *ack_request;
  3550. int i = smid - ioc->internal_smid;
  3551. unsigned long flags;
  3552. /* Without releasing the smid just update the
  3553. * call back index and reuse the same smid for
  3554. * processing this delayed request
  3555. */
  3556. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  3557. ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
  3558. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  3559. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3560. "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
  3561. ioc->name, le16_to_cpu(event), smid,
  3562. ioc->base_cb_idx));
  3563. ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
  3564. memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
  3565. ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
  3566. ack_request->Event = event;
  3567. ack_request->EventContext = event_context;
  3568. ack_request->VF_ID = 0; /* TODO */
  3569. ack_request->VP_ID = 0;
  3570. mpt3sas_base_put_smid_default(ioc, smid);
  3571. }
  3572. /**
  3573. * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
  3574. * sas_io_unit_ctrl messages
  3575. * @ioc: per adapter object
  3576. * @smid: system request message index
  3577. * @handle: device handle
  3578. *
  3579. * Context - processed in interrupt context.
  3580. */
  3581. static void
  3582. _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
  3583. u16 smid, u16 handle)
  3584. {
  3585. Mpi2SasIoUnitControlRequest_t *mpi_request;
  3586. u32 ioc_state;
  3587. int i = smid - ioc->internal_smid;
  3588. unsigned long flags;
  3589. if (ioc->remove_host) {
  3590. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3591. "%s: host has been removed\n",
  3592. __func__, ioc->name));
  3593. return;
  3594. } else if (ioc->pci_error_recovery) {
  3595. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3596. "%s: host in pci error recovery\n",
  3597. __func__, ioc->name));
  3598. return;
  3599. }
  3600. ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
  3601. if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
  3602. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3603. "%s: host is not operational\n",
  3604. __func__, ioc->name));
  3605. return;
  3606. }
  3607. /* Without releasing the smid just update the
  3608. * call back index and reuse the same smid for
  3609. * processing this delayed request
  3610. */
  3611. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  3612. ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
  3613. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  3614. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3615. "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
  3616. ioc->name, handle, smid,
  3617. ioc->tm_sas_control_cb_idx));
  3618. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  3619. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  3620. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  3621. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  3622. mpi_request->DevHandle = cpu_to_le16(handle);
  3623. mpt3sas_base_put_smid_default(ioc, smid);
  3624. }
  3625. /**
  3626. * _scsih_check_for_pending_internal_cmds - check for pending internal messages
  3627. * @ioc: per adapter object
  3628. * @smid: system request message index
  3629. *
  3630. * Context: Executed in interrupt context
  3631. *
  3632. * This will check delayed internal messages list, and process the
  3633. * next request.
  3634. *
  3635. * Return: 1 meaning mf should be freed from _base_interrupt
  3636. * 0 means the mf is freed from this function.
  3637. */
  3638. u8
  3639. mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
  3640. {
  3641. struct _sc_list *delayed_sc;
  3642. struct _event_ack_list *delayed_event_ack;
  3643. if (!list_empty(&ioc->delayed_event_ack_list)) {
  3644. delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
  3645. struct _event_ack_list, list);
  3646. _scsih_issue_delayed_event_ack(ioc, smid,
  3647. delayed_event_ack->Event, delayed_event_ack->EventContext);
  3648. list_del(&delayed_event_ack->list);
  3649. kfree(delayed_event_ack);
  3650. return 0;
  3651. }
  3652. if (!list_empty(&ioc->delayed_sc_list)) {
  3653. delayed_sc = list_entry(ioc->delayed_sc_list.next,
  3654. struct _sc_list, list);
  3655. _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
  3656. delayed_sc->handle);
  3657. list_del(&delayed_sc->list);
  3658. kfree(delayed_sc);
  3659. return 0;
  3660. }
  3661. return 1;
  3662. }
  3663. /**
  3664. * _scsih_check_for_pending_tm - check for pending task management
  3665. * @ioc: per adapter object
  3666. * @smid: system request message index
  3667. *
  3668. * This will check delayed target reset list, and feed the
  3669. * next reqeust.
  3670. *
  3671. * Return: 1 meaning mf should be freed from _base_interrupt
  3672. * 0 means the mf is freed from this function.
  3673. */
  3674. static u8
  3675. _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
  3676. {
  3677. struct _tr_list *delayed_tr;
  3678. if (!list_empty(&ioc->delayed_tr_volume_list)) {
  3679. delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
  3680. struct _tr_list, list);
  3681. mpt3sas_base_free_smid(ioc, smid);
  3682. _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
  3683. list_del(&delayed_tr->list);
  3684. kfree(delayed_tr);
  3685. return 0;
  3686. }
  3687. if (!list_empty(&ioc->delayed_tr_list)) {
  3688. delayed_tr = list_entry(ioc->delayed_tr_list.next,
  3689. struct _tr_list, list);
  3690. mpt3sas_base_free_smid(ioc, smid);
  3691. _scsih_tm_tr_send(ioc, delayed_tr->handle);
  3692. list_del(&delayed_tr->list);
  3693. kfree(delayed_tr);
  3694. return 0;
  3695. }
  3696. return 1;
  3697. }
  3698. /**
  3699. * _scsih_check_topo_delete_events - sanity check on topo events
  3700. * @ioc: per adapter object
  3701. * @event_data: the event data payload
  3702. *
  3703. * This routine added to better handle cable breaker.
  3704. *
  3705. * This handles the case where driver receives multiple expander
  3706. * add and delete events in a single shot. When there is a delete event
  3707. * the routine will void any pending add events waiting in the event queue.
  3708. */
  3709. static void
  3710. _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
  3711. Mpi2EventDataSasTopologyChangeList_t *event_data)
  3712. {
  3713. struct fw_event_work *fw_event;
  3714. Mpi2EventDataSasTopologyChangeList_t *local_event_data;
  3715. u16 expander_handle;
  3716. struct _sas_node *sas_expander;
  3717. unsigned long flags;
  3718. int i, reason_code;
  3719. u16 handle;
  3720. for (i = 0 ; i < event_data->NumEntries; i++) {
  3721. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3722. if (!handle)
  3723. continue;
  3724. reason_code = event_data->PHY[i].PhyStatus &
  3725. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3726. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
  3727. _scsih_tm_tr_send(ioc, handle);
  3728. }
  3729. expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  3730. if (expander_handle < ioc->sas_hba.num_phys) {
  3731. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  3732. return;
  3733. }
  3734. if (event_data->ExpStatus ==
  3735. MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
  3736. /* put expander attached devices into blocking state */
  3737. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3738. sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
  3739. expander_handle);
  3740. _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
  3741. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3742. do {
  3743. handle = find_first_bit(ioc->blocking_handles,
  3744. ioc->facts.MaxDevHandle);
  3745. if (handle < ioc->facts.MaxDevHandle)
  3746. _scsih_block_io_device(ioc, handle);
  3747. } while (test_and_clear_bit(handle, ioc->blocking_handles));
  3748. } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
  3749. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  3750. if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  3751. return;
  3752. /* mark ignore flag for pending events */
  3753. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  3754. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  3755. if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
  3756. fw_event->ignore)
  3757. continue;
  3758. local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
  3759. fw_event->event_data;
  3760. if (local_event_data->ExpStatus ==
  3761. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  3762. local_event_data->ExpStatus ==
  3763. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  3764. if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
  3765. expander_handle) {
  3766. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3767. "setting ignoring flag\n", ioc->name));
  3768. fw_event->ignore = 1;
  3769. }
  3770. }
  3771. }
  3772. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  3773. }
  3774. /**
  3775. * _scsih_check_pcie_topo_remove_events - sanity check on topo
  3776. * events
  3777. * @ioc: per adapter object
  3778. * @event_data: the event data payload
  3779. *
  3780. * This handles the case where driver receives multiple switch
  3781. * or device add and delete events in a single shot. When there
  3782. * is a delete event the routine will void any pending add
  3783. * events waiting in the event queue.
  3784. */
  3785. static void
  3786. _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc,
  3787. Mpi26EventDataPCIeTopologyChangeList_t *event_data)
  3788. {
  3789. struct fw_event_work *fw_event;
  3790. Mpi26EventDataPCIeTopologyChangeList_t *local_event_data;
  3791. unsigned long flags;
  3792. int i, reason_code;
  3793. u16 handle, switch_handle;
  3794. for (i = 0; i < event_data->NumEntries; i++) {
  3795. handle =
  3796. le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
  3797. if (!handle)
  3798. continue;
  3799. reason_code = event_data->PortEntry[i].PortStatus;
  3800. if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING)
  3801. _scsih_tm_tr_send(ioc, handle);
  3802. }
  3803. switch_handle = le16_to_cpu(event_data->SwitchDevHandle);
  3804. if (!switch_handle) {
  3805. _scsih_block_io_to_pcie_children_attached_directly(
  3806. ioc, event_data);
  3807. return;
  3808. }
  3809. /* TODO We are not supporting cascaded PCIe Switch removal yet*/
  3810. if ((event_data->SwitchStatus
  3811. == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) ||
  3812. (event_data->SwitchStatus ==
  3813. MPI26_EVENT_PCIE_TOPO_SS_RESPONDING))
  3814. _scsih_block_io_to_pcie_children_attached_directly(
  3815. ioc, event_data);
  3816. if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  3817. return;
  3818. /* mark ignore flag for pending events */
  3819. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  3820. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  3821. if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
  3822. fw_event->ignore)
  3823. continue;
  3824. local_event_data =
  3825. (Mpi26EventDataPCIeTopologyChangeList_t *)
  3826. fw_event->event_data;
  3827. if (local_event_data->SwitchStatus ==
  3828. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  3829. local_event_data->SwitchStatus ==
  3830. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  3831. if (le16_to_cpu(local_event_data->SwitchDevHandle) ==
  3832. switch_handle) {
  3833. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3834. "setting ignoring flag for switch event\n",
  3835. ioc->name));
  3836. fw_event->ignore = 1;
  3837. }
  3838. }
  3839. }
  3840. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  3841. }
  3842. /**
  3843. * _scsih_set_volume_delete_flag - setting volume delete flag
  3844. * @ioc: per adapter object
  3845. * @handle: device handle
  3846. *
  3847. * This returns nothing.
  3848. */
  3849. static void
  3850. _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  3851. {
  3852. struct _raid_device *raid_device;
  3853. struct MPT3SAS_TARGET *sas_target_priv_data;
  3854. unsigned long flags;
  3855. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  3856. raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
  3857. if (raid_device && raid_device->starget &&
  3858. raid_device->starget->hostdata) {
  3859. sas_target_priv_data =
  3860. raid_device->starget->hostdata;
  3861. sas_target_priv_data->deleted = 1;
  3862. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3863. "setting delete flag: handle(0x%04x), "
  3864. "wwid(0x%016llx)\n", ioc->name, handle,
  3865. (unsigned long long) raid_device->wwid));
  3866. }
  3867. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  3868. }
  3869. /**
  3870. * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
  3871. * @handle: input handle
  3872. * @a: handle for volume a
  3873. * @b: handle for volume b
  3874. *
  3875. * IR firmware only supports two raid volumes. The purpose of this
  3876. * routine is to set the volume handle in either a or b. When the given
  3877. * input handle is non-zero, or when a and b have not been set before.
  3878. */
  3879. static void
  3880. _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
  3881. {
  3882. if (!handle || handle == *a || handle == *b)
  3883. return;
  3884. if (!*a)
  3885. *a = handle;
  3886. else if (!*b)
  3887. *b = handle;
  3888. }
  3889. /**
  3890. * _scsih_check_ir_config_unhide_events - check for UNHIDE events
  3891. * @ioc: per adapter object
  3892. * @event_data: the event data payload
  3893. * Context: interrupt time.
  3894. *
  3895. * This routine will send target reset to volume, followed by target
  3896. * resets to the PDs. This is called when a PD has been removed, or
  3897. * volume has been deleted or removed. When the target reset is sent
  3898. * to volume, the PD target resets need to be queued to start upon
  3899. * completion of the volume target reset.
  3900. */
  3901. static void
  3902. _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
  3903. Mpi2EventDataIrConfigChangeList_t *event_data)
  3904. {
  3905. Mpi2EventIrConfigElement_t *element;
  3906. int i;
  3907. u16 handle, volume_handle, a, b;
  3908. struct _tr_list *delayed_tr;
  3909. a = 0;
  3910. b = 0;
  3911. if (ioc->is_warpdrive)
  3912. return;
  3913. /* Volume Resets for Deleted or Removed */
  3914. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3915. for (i = 0; i < event_data->NumElements; i++, element++) {
  3916. if (le32_to_cpu(event_data->Flags) &
  3917. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
  3918. continue;
  3919. if (element->ReasonCode ==
  3920. MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
  3921. element->ReasonCode ==
  3922. MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
  3923. volume_handle = le16_to_cpu(element->VolDevHandle);
  3924. _scsih_set_volume_delete_flag(ioc, volume_handle);
  3925. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  3926. }
  3927. }
  3928. /* Volume Resets for UNHIDE events */
  3929. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3930. for (i = 0; i < event_data->NumElements; i++, element++) {
  3931. if (le32_to_cpu(event_data->Flags) &
  3932. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
  3933. continue;
  3934. if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
  3935. volume_handle = le16_to_cpu(element->VolDevHandle);
  3936. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  3937. }
  3938. }
  3939. if (a)
  3940. _scsih_tm_tr_volume_send(ioc, a);
  3941. if (b)
  3942. _scsih_tm_tr_volume_send(ioc, b);
  3943. /* PD target resets */
  3944. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3945. for (i = 0; i < event_data->NumElements; i++, element++) {
  3946. if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
  3947. continue;
  3948. handle = le16_to_cpu(element->PhysDiskDevHandle);
  3949. volume_handle = le16_to_cpu(element->VolDevHandle);
  3950. clear_bit(handle, ioc->pd_handles);
  3951. if (!volume_handle)
  3952. _scsih_tm_tr_send(ioc, handle);
  3953. else if (volume_handle == a || volume_handle == b) {
  3954. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  3955. BUG_ON(!delayed_tr);
  3956. INIT_LIST_HEAD(&delayed_tr->list);
  3957. delayed_tr->handle = handle;
  3958. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  3959. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  3960. "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
  3961. handle));
  3962. } else
  3963. _scsih_tm_tr_send(ioc, handle);
  3964. }
  3965. }
  3966. /**
  3967. * _scsih_check_volume_delete_events - set delete flag for volumes
  3968. * @ioc: per adapter object
  3969. * @event_data: the event data payload
  3970. * Context: interrupt time.
  3971. *
  3972. * This will handle the case when the cable connected to entire volume is
  3973. * pulled. We will take care of setting the deleted flag so normal IO will
  3974. * not be sent.
  3975. */
  3976. static void
  3977. _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
  3978. Mpi2EventDataIrVolume_t *event_data)
  3979. {
  3980. u32 state;
  3981. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  3982. return;
  3983. state = le32_to_cpu(event_data->NewValue);
  3984. if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
  3985. MPI2_RAID_VOL_STATE_FAILED)
  3986. _scsih_set_volume_delete_flag(ioc,
  3987. le16_to_cpu(event_data->VolDevHandle));
  3988. }
  3989. /**
  3990. * _scsih_temp_threshold_events - display temperature threshold exceeded events
  3991. * @ioc: per adapter object
  3992. * @event_data: the temp threshold event data
  3993. * Context: interrupt time.
  3994. */
  3995. static void
  3996. _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
  3997. Mpi2EventDataTemperature_t *event_data)
  3998. {
  3999. if (ioc->temp_sensors_count >= event_data->SensorNum) {
  4000. pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
  4001. " exceeded for Sensor: %d !!!\n", ioc->name,
  4002. ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
  4003. ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
  4004. ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
  4005. ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
  4006. event_data->SensorNum);
  4007. pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
  4008. ioc->name, event_data->CurrentTemperature);
  4009. }
  4010. }
  4011. static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
  4012. {
  4013. struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
  4014. if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
  4015. return 0;
  4016. if (pending)
  4017. return test_and_set_bit(0, &priv->ata_command_pending);
  4018. clear_bit(0, &priv->ata_command_pending);
  4019. return 0;
  4020. }
  4021. /**
  4022. * _scsih_flush_running_cmds - completing outstanding commands.
  4023. * @ioc: per adapter object
  4024. *
  4025. * The flushing out of all pending scmd commands following host reset,
  4026. * where all IO is dropped to the floor.
  4027. */
  4028. static void
  4029. _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
  4030. {
  4031. struct scsi_cmnd *scmd;
  4032. struct scsiio_tracker *st;
  4033. u16 smid;
  4034. int count = 0;
  4035. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  4036. scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
  4037. if (!scmd)
  4038. continue;
  4039. count++;
  4040. _scsih_set_satl_pending(scmd, false);
  4041. st = scsi_cmd_priv(scmd);
  4042. mpt3sas_base_clear_st(ioc, st);
  4043. scsi_dma_unmap(scmd);
  4044. if (ioc->pci_error_recovery || ioc->remove_host)
  4045. scmd->result = DID_NO_CONNECT << 16;
  4046. else
  4047. scmd->result = DID_RESET << 16;
  4048. scmd->scsi_done(scmd);
  4049. }
  4050. dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
  4051. ioc->name, count));
  4052. }
  4053. /**
  4054. * _scsih_setup_eedp - setup MPI request for EEDP transfer
  4055. * @ioc: per adapter object
  4056. * @scmd: pointer to scsi command object
  4057. * @mpi_request: pointer to the SCSI_IO request message frame
  4058. *
  4059. * Supporting protection 1 and 3.
  4060. */
  4061. static void
  4062. _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  4063. Mpi25SCSIIORequest_t *mpi_request)
  4064. {
  4065. u16 eedp_flags;
  4066. unsigned char prot_op = scsi_get_prot_op(scmd);
  4067. unsigned char prot_type = scsi_get_prot_type(scmd);
  4068. Mpi25SCSIIORequest_t *mpi_request_3v =
  4069. (Mpi25SCSIIORequest_t *)mpi_request;
  4070. if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
  4071. return;
  4072. if (prot_op == SCSI_PROT_READ_STRIP)
  4073. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
  4074. else if (prot_op == SCSI_PROT_WRITE_INSERT)
  4075. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  4076. else
  4077. return;
  4078. switch (prot_type) {
  4079. case SCSI_PROT_DIF_TYPE1:
  4080. case SCSI_PROT_DIF_TYPE2:
  4081. /*
  4082. * enable ref/guard checking
  4083. * auto increment ref tag
  4084. */
  4085. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  4086. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  4087. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  4088. mpi_request->CDB.EEDP32.PrimaryReferenceTag =
  4089. cpu_to_be32(t10_pi_ref_tag(scmd->request));
  4090. break;
  4091. case SCSI_PROT_DIF_TYPE3:
  4092. /*
  4093. * enable guard checking
  4094. */
  4095. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  4096. break;
  4097. }
  4098. mpi_request_3v->EEDPBlockSize =
  4099. cpu_to_le16(scmd->device->sector_size);
  4100. if (ioc->is_gen35_ioc)
  4101. eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
  4102. mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
  4103. }
  4104. /**
  4105. * _scsih_eedp_error_handling - return sense code for EEDP errors
  4106. * @scmd: pointer to scsi command object
  4107. * @ioc_status: ioc status
  4108. */
  4109. static void
  4110. _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
  4111. {
  4112. u8 ascq;
  4113. switch (ioc_status) {
  4114. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  4115. ascq = 0x01;
  4116. break;
  4117. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  4118. ascq = 0x02;
  4119. break;
  4120. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  4121. ascq = 0x03;
  4122. break;
  4123. default:
  4124. ascq = 0x00;
  4125. break;
  4126. }
  4127. scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
  4128. ascq);
  4129. scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
  4130. SAM_STAT_CHECK_CONDITION;
  4131. }
  4132. /**
  4133. * scsih_qcmd - main scsi request entry point
  4134. * @shost: SCSI host pointer
  4135. * @scmd: pointer to scsi command object
  4136. *
  4137. * The callback index is set inside `ioc->scsi_io_cb_idx`.
  4138. *
  4139. * Return: 0 on success. If there's a failure, return either:
  4140. * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
  4141. * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  4142. */
  4143. static int
  4144. scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
  4145. {
  4146. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  4147. struct MPT3SAS_DEVICE *sas_device_priv_data;
  4148. struct MPT3SAS_TARGET *sas_target_priv_data;
  4149. struct _raid_device *raid_device;
  4150. struct request *rq = scmd->request;
  4151. int class;
  4152. Mpi25SCSIIORequest_t *mpi_request;
  4153. struct _pcie_device *pcie_device = NULL;
  4154. u32 mpi_control;
  4155. u16 smid;
  4156. u16 handle;
  4157. if (ioc->logging_level & MPT_DEBUG_SCSI)
  4158. scsi_print_command(scmd);
  4159. sas_device_priv_data = scmd->device->hostdata;
  4160. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  4161. scmd->result = DID_NO_CONNECT << 16;
  4162. scmd->scsi_done(scmd);
  4163. return 0;
  4164. }
  4165. if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
  4166. scmd->result = DID_NO_CONNECT << 16;
  4167. scmd->scsi_done(scmd);
  4168. return 0;
  4169. }
  4170. sas_target_priv_data = sas_device_priv_data->sas_target;
  4171. /* invalid device handle */
  4172. handle = sas_target_priv_data->handle;
  4173. if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
  4174. scmd->result = DID_NO_CONNECT << 16;
  4175. scmd->scsi_done(scmd);
  4176. return 0;
  4177. }
  4178. if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
  4179. /* host recovery or link resets sent via IOCTLs */
  4180. return SCSI_MLQUEUE_HOST_BUSY;
  4181. } else if (sas_target_priv_data->deleted) {
  4182. /* device has been deleted */
  4183. scmd->result = DID_NO_CONNECT << 16;
  4184. scmd->scsi_done(scmd);
  4185. return 0;
  4186. } else if (sas_target_priv_data->tm_busy ||
  4187. sas_device_priv_data->block) {
  4188. /* device busy with task management */
  4189. return SCSI_MLQUEUE_DEVICE_BUSY;
  4190. }
  4191. /*
  4192. * Bug work around for firmware SATL handling. The loop
  4193. * is based on atomic operations and ensures consistency
  4194. * since we're lockless at this point
  4195. */
  4196. do {
  4197. if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
  4198. scmd->result = SAM_STAT_BUSY;
  4199. scmd->scsi_done(scmd);
  4200. return 0;
  4201. }
  4202. } while (_scsih_set_satl_pending(scmd, true));
  4203. if (scmd->sc_data_direction == DMA_FROM_DEVICE)
  4204. mpi_control = MPI2_SCSIIO_CONTROL_READ;
  4205. else if (scmd->sc_data_direction == DMA_TO_DEVICE)
  4206. mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
  4207. else
  4208. mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
  4209. /* set tags */
  4210. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  4211. /* NCQ Prio supported, make sure control indicated high priority */
  4212. if (sas_device_priv_data->ncq_prio_enable) {
  4213. class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
  4214. if (class == IOPRIO_CLASS_RT)
  4215. mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
  4216. }
  4217. /* Make sure Device is not raid volume.
  4218. * We do not expose raid functionality to upper layer for warpdrive.
  4219. */
  4220. if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev))
  4221. && !scsih_is_nvme(&scmd->device->sdev_gendev))
  4222. && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
  4223. mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
  4224. smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
  4225. if (!smid) {
  4226. pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
  4227. ioc->name, __func__);
  4228. _scsih_set_satl_pending(scmd, false);
  4229. goto out;
  4230. }
  4231. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  4232. memset(mpi_request, 0, ioc->request_sz);
  4233. _scsih_setup_eedp(ioc, scmd, mpi_request);
  4234. if (scmd->cmd_len == 32)
  4235. mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
  4236. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  4237. if (sas_device_priv_data->sas_target->flags &
  4238. MPT_TARGET_FLAGS_RAID_COMPONENT)
  4239. mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  4240. else
  4241. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  4242. mpi_request->DevHandle = cpu_to_le16(handle);
  4243. mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
  4244. mpi_request->Control = cpu_to_le32(mpi_control);
  4245. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
  4246. mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
  4247. mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  4248. mpi_request->SenseBufferLowAddress =
  4249. mpt3sas_base_get_sense_buffer_dma(ioc, smid);
  4250. mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4;
  4251. int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
  4252. mpi_request->LUN);
  4253. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  4254. if (mpi_request->DataLength) {
  4255. pcie_device = sas_target_priv_data->pcie_dev;
  4256. if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) {
  4257. mpt3sas_base_free_smid(ioc, smid);
  4258. _scsih_set_satl_pending(scmd, false);
  4259. goto out;
  4260. }
  4261. } else
  4262. ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
  4263. raid_device = sas_target_priv_data->raid_device;
  4264. if (raid_device && raid_device->direct_io_enabled)
  4265. mpt3sas_setup_direct_io(ioc, scmd,
  4266. raid_device, mpi_request);
  4267. if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
  4268. if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
  4269. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
  4270. MPI25_SCSIIO_IOFLAGS_FAST_PATH);
  4271. mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
  4272. } else
  4273. ioc->put_smid_scsi_io(ioc, smid,
  4274. le16_to_cpu(mpi_request->DevHandle));
  4275. } else
  4276. mpt3sas_base_put_smid_default(ioc, smid);
  4277. return 0;
  4278. out:
  4279. return SCSI_MLQUEUE_HOST_BUSY;
  4280. }
  4281. /**
  4282. * _scsih_normalize_sense - normalize descriptor and fixed format sense data
  4283. * @sense_buffer: sense data returned by target
  4284. * @data: normalized skey/asc/ascq
  4285. */
  4286. static void
  4287. _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
  4288. {
  4289. if ((sense_buffer[0] & 0x7F) >= 0x72) {
  4290. /* descriptor format */
  4291. data->skey = sense_buffer[1] & 0x0F;
  4292. data->asc = sense_buffer[2];
  4293. data->ascq = sense_buffer[3];
  4294. } else {
  4295. /* fixed format */
  4296. data->skey = sense_buffer[2] & 0x0F;
  4297. data->asc = sense_buffer[12];
  4298. data->ascq = sense_buffer[13];
  4299. }
  4300. }
  4301. /**
  4302. * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
  4303. * @ioc: per adapter object
  4304. * @scmd: pointer to scsi command object
  4305. * @mpi_reply: reply mf payload returned from firmware
  4306. * @smid: ?
  4307. *
  4308. * scsi_status - SCSI Status code returned from target device
  4309. * scsi_state - state info associated with SCSI_IO determined by ioc
  4310. * ioc_status - ioc supplied status info
  4311. */
  4312. static void
  4313. _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  4314. Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
  4315. {
  4316. u32 response_info;
  4317. u8 *response_bytes;
  4318. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  4319. MPI2_IOCSTATUS_MASK;
  4320. u8 scsi_state = mpi_reply->SCSIState;
  4321. u8 scsi_status = mpi_reply->SCSIStatus;
  4322. char *desc_ioc_state = NULL;
  4323. char *desc_scsi_status = NULL;
  4324. char *desc_scsi_state = ioc->tmp_string;
  4325. u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  4326. struct _sas_device *sas_device = NULL;
  4327. struct _pcie_device *pcie_device = NULL;
  4328. struct scsi_target *starget = scmd->device->sdev_target;
  4329. struct MPT3SAS_TARGET *priv_target = starget->hostdata;
  4330. char *device_str = NULL;
  4331. if (!priv_target)
  4332. return;
  4333. if (ioc->hide_ir_msg)
  4334. device_str = "WarpDrive";
  4335. else
  4336. device_str = "volume";
  4337. if (log_info == 0x31170000)
  4338. return;
  4339. switch (ioc_status) {
  4340. case MPI2_IOCSTATUS_SUCCESS:
  4341. desc_ioc_state = "success";
  4342. break;
  4343. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  4344. desc_ioc_state = "invalid function";
  4345. break;
  4346. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  4347. desc_ioc_state = "scsi recovered error";
  4348. break;
  4349. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  4350. desc_ioc_state = "scsi invalid dev handle";
  4351. break;
  4352. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  4353. desc_ioc_state = "scsi device not there";
  4354. break;
  4355. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  4356. desc_ioc_state = "scsi data overrun";
  4357. break;
  4358. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  4359. desc_ioc_state = "scsi data underrun";
  4360. break;
  4361. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  4362. desc_ioc_state = "scsi io data error";
  4363. break;
  4364. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  4365. desc_ioc_state = "scsi protocol error";
  4366. break;
  4367. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  4368. desc_ioc_state = "scsi task terminated";
  4369. break;
  4370. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  4371. desc_ioc_state = "scsi residual mismatch";
  4372. break;
  4373. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  4374. desc_ioc_state = "scsi task mgmt failed";
  4375. break;
  4376. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  4377. desc_ioc_state = "scsi ioc terminated";
  4378. break;
  4379. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  4380. desc_ioc_state = "scsi ext terminated";
  4381. break;
  4382. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  4383. desc_ioc_state = "eedp guard error";
  4384. break;
  4385. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  4386. desc_ioc_state = "eedp ref tag error";
  4387. break;
  4388. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  4389. desc_ioc_state = "eedp app tag error";
  4390. break;
  4391. case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
  4392. desc_ioc_state = "insufficient power";
  4393. break;
  4394. default:
  4395. desc_ioc_state = "unknown";
  4396. break;
  4397. }
  4398. switch (scsi_status) {
  4399. case MPI2_SCSI_STATUS_GOOD:
  4400. desc_scsi_status = "good";
  4401. break;
  4402. case MPI2_SCSI_STATUS_CHECK_CONDITION:
  4403. desc_scsi_status = "check condition";
  4404. break;
  4405. case MPI2_SCSI_STATUS_CONDITION_MET:
  4406. desc_scsi_status = "condition met";
  4407. break;
  4408. case MPI2_SCSI_STATUS_BUSY:
  4409. desc_scsi_status = "busy";
  4410. break;
  4411. case MPI2_SCSI_STATUS_INTERMEDIATE:
  4412. desc_scsi_status = "intermediate";
  4413. break;
  4414. case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
  4415. desc_scsi_status = "intermediate condmet";
  4416. break;
  4417. case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
  4418. desc_scsi_status = "reservation conflict";
  4419. break;
  4420. case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
  4421. desc_scsi_status = "command terminated";
  4422. break;
  4423. case MPI2_SCSI_STATUS_TASK_SET_FULL:
  4424. desc_scsi_status = "task set full";
  4425. break;
  4426. case MPI2_SCSI_STATUS_ACA_ACTIVE:
  4427. desc_scsi_status = "aca active";
  4428. break;
  4429. case MPI2_SCSI_STATUS_TASK_ABORTED:
  4430. desc_scsi_status = "task aborted";
  4431. break;
  4432. default:
  4433. desc_scsi_status = "unknown";
  4434. break;
  4435. }
  4436. desc_scsi_state[0] = '\0';
  4437. if (!scsi_state)
  4438. desc_scsi_state = " ";
  4439. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  4440. strcat(desc_scsi_state, "response info ");
  4441. if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  4442. strcat(desc_scsi_state, "state terminated ");
  4443. if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
  4444. strcat(desc_scsi_state, "no status ");
  4445. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
  4446. strcat(desc_scsi_state, "autosense failed ");
  4447. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
  4448. strcat(desc_scsi_state, "autosense valid ");
  4449. scsi_print_command(scmd);
  4450. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  4451. pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
  4452. device_str, (unsigned long long)priv_target->sas_address);
  4453. } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
  4454. pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target);
  4455. if (pcie_device) {
  4456. pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n",
  4457. ioc->name,
  4458. (unsigned long long)pcie_device->wwid,
  4459. pcie_device->port_num);
  4460. if (pcie_device->enclosure_handle != 0)
  4461. pr_info(MPT3SAS_FMT
  4462. "\tenclosure logical id(0x%016llx), "
  4463. "slot(%d)\n", ioc->name,
  4464. (unsigned long long)
  4465. pcie_device->enclosure_logical_id,
  4466. pcie_device->slot);
  4467. if (pcie_device->connector_name[0])
  4468. pr_info(MPT3SAS_FMT
  4469. "\tenclosure level(0x%04x),"
  4470. "connector name( %s)\n",
  4471. ioc->name, pcie_device->enclosure_level,
  4472. pcie_device->connector_name);
  4473. pcie_device_put(pcie_device);
  4474. }
  4475. } else {
  4476. sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
  4477. if (sas_device) {
  4478. pr_warn(MPT3SAS_FMT
  4479. "\tsas_address(0x%016llx), phy(%d)\n",
  4480. ioc->name, (unsigned long long)
  4481. sas_device->sas_address, sas_device->phy);
  4482. _scsih_display_enclosure_chassis_info(ioc, sas_device,
  4483. NULL, NULL);
  4484. sas_device_put(sas_device);
  4485. }
  4486. }
  4487. pr_warn(MPT3SAS_FMT
  4488. "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
  4489. ioc->name, le16_to_cpu(mpi_reply->DevHandle),
  4490. desc_ioc_state, ioc_status, smid);
  4491. pr_warn(MPT3SAS_FMT
  4492. "\trequest_len(%d), underflow(%d), resid(%d)\n",
  4493. ioc->name, scsi_bufflen(scmd), scmd->underflow,
  4494. scsi_get_resid(scmd));
  4495. pr_warn(MPT3SAS_FMT
  4496. "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
  4497. ioc->name, le16_to_cpu(mpi_reply->TaskTag),
  4498. le32_to_cpu(mpi_reply->TransferCount), scmd->result);
  4499. pr_warn(MPT3SAS_FMT
  4500. "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
  4501. ioc->name, desc_scsi_status,
  4502. scsi_status, desc_scsi_state, scsi_state);
  4503. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  4504. struct sense_info data;
  4505. _scsih_normalize_sense(scmd->sense_buffer, &data);
  4506. pr_warn(MPT3SAS_FMT
  4507. "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
  4508. ioc->name, data.skey,
  4509. data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
  4510. }
  4511. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
  4512. response_info = le32_to_cpu(mpi_reply->ResponseInfo);
  4513. response_bytes = (u8 *)&response_info;
  4514. _scsih_response_code(ioc, response_bytes[0]);
  4515. }
  4516. }
  4517. /**
  4518. * _scsih_turn_on_pfa_led - illuminate PFA LED
  4519. * @ioc: per adapter object
  4520. * @handle: device handle
  4521. * Context: process
  4522. */
  4523. static void
  4524. _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  4525. {
  4526. Mpi2SepReply_t mpi_reply;
  4527. Mpi2SepRequest_t mpi_request;
  4528. struct _sas_device *sas_device;
  4529. sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
  4530. if (!sas_device)
  4531. return;
  4532. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  4533. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  4534. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  4535. mpi_request.SlotStatus =
  4536. cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  4537. mpi_request.DevHandle = cpu_to_le16(handle);
  4538. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
  4539. if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  4540. &mpi_request)) != 0) {
  4541. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
  4542. __FILE__, __LINE__, __func__);
  4543. goto out;
  4544. }
  4545. sas_device->pfa_led_on = 1;
  4546. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  4547. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  4548. "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
  4549. ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
  4550. le32_to_cpu(mpi_reply.IOCLogInfo)));
  4551. goto out;
  4552. }
  4553. out:
  4554. sas_device_put(sas_device);
  4555. }
  4556. /**
  4557. * _scsih_turn_off_pfa_led - turn off Fault LED
  4558. * @ioc: per adapter object
  4559. * @sas_device: sas device whose PFA LED has to turned off
  4560. * Context: process
  4561. */
  4562. static void
  4563. _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
  4564. struct _sas_device *sas_device)
  4565. {
  4566. Mpi2SepReply_t mpi_reply;
  4567. Mpi2SepRequest_t mpi_request;
  4568. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  4569. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  4570. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  4571. mpi_request.SlotStatus = 0;
  4572. mpi_request.Slot = cpu_to_le16(sas_device->slot);
  4573. mpi_request.DevHandle = 0;
  4574. mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
  4575. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
  4576. if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  4577. &mpi_request)) != 0) {
  4578. printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
  4579. __FILE__, __LINE__, __func__);
  4580. return;
  4581. }
  4582. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  4583. dewtprintk(ioc, printk(MPT3SAS_FMT
  4584. "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
  4585. ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
  4586. le32_to_cpu(mpi_reply.IOCLogInfo)));
  4587. return;
  4588. }
  4589. }
  4590. /**
  4591. * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
  4592. * @ioc: per adapter object
  4593. * @handle: device handle
  4594. * Context: interrupt.
  4595. */
  4596. static void
  4597. _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  4598. {
  4599. struct fw_event_work *fw_event;
  4600. fw_event = alloc_fw_event_work(0);
  4601. if (!fw_event)
  4602. return;
  4603. fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
  4604. fw_event->device_handle = handle;
  4605. fw_event->ioc = ioc;
  4606. _scsih_fw_event_add(ioc, fw_event);
  4607. fw_event_work_put(fw_event);
  4608. }
  4609. /**
  4610. * _scsih_smart_predicted_fault - process smart errors
  4611. * @ioc: per adapter object
  4612. * @handle: device handle
  4613. * Context: interrupt.
  4614. */
  4615. static void
  4616. _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  4617. {
  4618. struct scsi_target *starget;
  4619. struct MPT3SAS_TARGET *sas_target_priv_data;
  4620. Mpi2EventNotificationReply_t *event_reply;
  4621. Mpi2EventDataSasDeviceStatusChange_t *event_data;
  4622. struct _sas_device *sas_device;
  4623. ssize_t sz;
  4624. unsigned long flags;
  4625. /* only handle non-raid devices */
  4626. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4627. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  4628. if (!sas_device)
  4629. goto out_unlock;
  4630. starget = sas_device->starget;
  4631. sas_target_priv_data = starget->hostdata;
  4632. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
  4633. ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
  4634. goto out_unlock;
  4635. _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget);
  4636. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4637. if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
  4638. _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
  4639. /* insert into event log */
  4640. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  4641. sizeof(Mpi2EventDataSasDeviceStatusChange_t);
  4642. event_reply = kzalloc(sz, GFP_KERNEL);
  4643. if (!event_reply) {
  4644. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4645. ioc->name, __FILE__, __LINE__, __func__);
  4646. goto out;
  4647. }
  4648. event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  4649. event_reply->Event =
  4650. cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  4651. event_reply->MsgLength = sz/4;
  4652. event_reply->EventDataLength =
  4653. cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
  4654. event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
  4655. event_reply->EventData;
  4656. event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
  4657. event_data->ASC = 0x5D;
  4658. event_data->DevHandle = cpu_to_le16(handle);
  4659. event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
  4660. mpt3sas_ctl_add_to_event_log(ioc, event_reply);
  4661. kfree(event_reply);
  4662. out:
  4663. if (sas_device)
  4664. sas_device_put(sas_device);
  4665. return;
  4666. out_unlock:
  4667. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4668. goto out;
  4669. }
  4670. /**
  4671. * _scsih_io_done - scsi request callback
  4672. * @ioc: per adapter object
  4673. * @smid: system request message index
  4674. * @msix_index: MSIX table index supplied by the OS
  4675. * @reply: reply message frame(lower 32bit addr)
  4676. *
  4677. * Callback handler when using _scsih_qcmd.
  4678. *
  4679. * Return: 1 meaning mf should be freed from _base_interrupt
  4680. * 0 means the mf is freed from this function.
  4681. */
  4682. static u8
  4683. _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  4684. {
  4685. Mpi25SCSIIORequest_t *mpi_request;
  4686. Mpi2SCSIIOReply_t *mpi_reply;
  4687. struct scsi_cmnd *scmd;
  4688. struct scsiio_tracker *st;
  4689. u16 ioc_status;
  4690. u32 xfer_cnt;
  4691. u8 scsi_state;
  4692. u8 scsi_status;
  4693. u32 log_info;
  4694. struct MPT3SAS_DEVICE *sas_device_priv_data;
  4695. u32 response_code = 0;
  4696. mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
  4697. scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
  4698. if (scmd == NULL)
  4699. return 1;
  4700. _scsih_set_satl_pending(scmd, false);
  4701. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  4702. if (mpi_reply == NULL) {
  4703. scmd->result = DID_OK << 16;
  4704. goto out;
  4705. }
  4706. sas_device_priv_data = scmd->device->hostdata;
  4707. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  4708. sas_device_priv_data->sas_target->deleted) {
  4709. scmd->result = DID_NO_CONNECT << 16;
  4710. goto out;
  4711. }
  4712. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  4713. /*
  4714. * WARPDRIVE: If direct_io is set then it is directIO,
  4715. * the failed direct I/O should be redirected to volume
  4716. */
  4717. st = scsi_cmd_priv(scmd);
  4718. if (st->direct_io &&
  4719. ((ioc_status & MPI2_IOCSTATUS_MASK)
  4720. != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
  4721. st->direct_io = 0;
  4722. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  4723. mpi_request->DevHandle =
  4724. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  4725. ioc->put_smid_scsi_io(ioc, smid,
  4726. sas_device_priv_data->sas_target->handle);
  4727. return 0;
  4728. }
  4729. /* turning off TLR */
  4730. scsi_state = mpi_reply->SCSIState;
  4731. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  4732. response_code =
  4733. le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
  4734. if (!sas_device_priv_data->tlr_snoop_check) {
  4735. sas_device_priv_data->tlr_snoop_check++;
  4736. if ((!ioc->is_warpdrive &&
  4737. !scsih_is_raid(&scmd->device->sdev_gendev) &&
  4738. !scsih_is_nvme(&scmd->device->sdev_gendev))
  4739. && sas_is_tlr_enabled(scmd->device) &&
  4740. response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
  4741. sas_disable_tlr(scmd->device);
  4742. sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
  4743. }
  4744. }
  4745. xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
  4746. scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
  4747. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  4748. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  4749. else
  4750. log_info = 0;
  4751. ioc_status &= MPI2_IOCSTATUS_MASK;
  4752. scsi_status = mpi_reply->SCSIStatus;
  4753. if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  4754. (scsi_status == MPI2_SCSI_STATUS_BUSY ||
  4755. scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
  4756. scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
  4757. ioc_status = MPI2_IOCSTATUS_SUCCESS;
  4758. }
  4759. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  4760. struct sense_info data;
  4761. const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
  4762. smid);
  4763. u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
  4764. le32_to_cpu(mpi_reply->SenseCount));
  4765. memcpy(scmd->sense_buffer, sense_data, sz);
  4766. _scsih_normalize_sense(scmd->sense_buffer, &data);
  4767. /* failure prediction threshold exceeded */
  4768. if (data.asc == 0x5D)
  4769. _scsih_smart_predicted_fault(ioc,
  4770. le16_to_cpu(mpi_reply->DevHandle));
  4771. mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
  4772. if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
  4773. ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
  4774. (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
  4775. (scmd->sense_buffer[2] == HARDWARE_ERROR)))
  4776. _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
  4777. }
  4778. switch (ioc_status) {
  4779. case MPI2_IOCSTATUS_BUSY:
  4780. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  4781. scmd->result = SAM_STAT_BUSY;
  4782. break;
  4783. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  4784. scmd->result = DID_NO_CONNECT << 16;
  4785. break;
  4786. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  4787. if (sas_device_priv_data->block) {
  4788. scmd->result = DID_TRANSPORT_DISRUPTED << 16;
  4789. goto out;
  4790. }
  4791. if (log_info == 0x31110630) {
  4792. if (scmd->retries > 2) {
  4793. scmd->result = DID_NO_CONNECT << 16;
  4794. scsi_device_set_state(scmd->device,
  4795. SDEV_OFFLINE);
  4796. } else {
  4797. scmd->result = DID_SOFT_ERROR << 16;
  4798. scmd->device->expecting_cc_ua = 1;
  4799. }
  4800. break;
  4801. } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
  4802. scmd->result = DID_RESET << 16;
  4803. break;
  4804. } else if ((scmd->device->channel == RAID_CHANNEL) &&
  4805. (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
  4806. MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
  4807. scmd->result = DID_RESET << 16;
  4808. break;
  4809. }
  4810. scmd->result = DID_SOFT_ERROR << 16;
  4811. break;
  4812. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  4813. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  4814. scmd->result = DID_RESET << 16;
  4815. break;
  4816. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  4817. if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
  4818. scmd->result = DID_SOFT_ERROR << 16;
  4819. else
  4820. scmd->result = (DID_OK << 16) | scsi_status;
  4821. break;
  4822. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  4823. scmd->result = (DID_OK << 16) | scsi_status;
  4824. if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
  4825. break;
  4826. if (xfer_cnt < scmd->underflow) {
  4827. if (scsi_status == SAM_STAT_BUSY)
  4828. scmd->result = SAM_STAT_BUSY;
  4829. else
  4830. scmd->result = DID_SOFT_ERROR << 16;
  4831. } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  4832. MPI2_SCSI_STATE_NO_SCSI_STATUS))
  4833. scmd->result = DID_SOFT_ERROR << 16;
  4834. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  4835. scmd->result = DID_RESET << 16;
  4836. else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
  4837. mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
  4838. mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
  4839. scmd->result = (DRIVER_SENSE << 24) |
  4840. SAM_STAT_CHECK_CONDITION;
  4841. scmd->sense_buffer[0] = 0x70;
  4842. scmd->sense_buffer[2] = ILLEGAL_REQUEST;
  4843. scmd->sense_buffer[12] = 0x20;
  4844. scmd->sense_buffer[13] = 0;
  4845. }
  4846. break;
  4847. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  4848. scsi_set_resid(scmd, 0);
  4849. /* fall through */
  4850. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  4851. case MPI2_IOCSTATUS_SUCCESS:
  4852. scmd->result = (DID_OK << 16) | scsi_status;
  4853. if (response_code ==
  4854. MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
  4855. (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  4856. MPI2_SCSI_STATE_NO_SCSI_STATUS)))
  4857. scmd->result = DID_SOFT_ERROR << 16;
  4858. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  4859. scmd->result = DID_RESET << 16;
  4860. break;
  4861. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  4862. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  4863. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  4864. _scsih_eedp_error_handling(scmd, ioc_status);
  4865. break;
  4866. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  4867. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  4868. case MPI2_IOCSTATUS_INVALID_SGL:
  4869. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  4870. case MPI2_IOCSTATUS_INVALID_FIELD:
  4871. case MPI2_IOCSTATUS_INVALID_STATE:
  4872. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  4873. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  4874. case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
  4875. default:
  4876. scmd->result = DID_SOFT_ERROR << 16;
  4877. break;
  4878. }
  4879. if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
  4880. _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
  4881. out:
  4882. scsi_dma_unmap(scmd);
  4883. mpt3sas_base_free_smid(ioc, smid);
  4884. scmd->scsi_done(scmd);
  4885. return 0;
  4886. }
  4887. /**
  4888. * _scsih_sas_host_refresh - refreshing sas host object contents
  4889. * @ioc: per adapter object
  4890. * Context: user
  4891. *
  4892. * During port enable, fw will send topology events for every device. Its
  4893. * possible that the handles may change from the previous setting, so this
  4894. * code keeping handles updating if changed.
  4895. */
  4896. static void
  4897. _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
  4898. {
  4899. u16 sz;
  4900. u16 ioc_status;
  4901. int i;
  4902. Mpi2ConfigReply_t mpi_reply;
  4903. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  4904. u16 attached_handle;
  4905. u8 link_rate;
  4906. dtmprintk(ioc, pr_info(MPT3SAS_FMT
  4907. "updating handles for sas_host(0x%016llx)\n",
  4908. ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
  4909. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
  4910. * sizeof(Mpi2SasIOUnit0PhyData_t));
  4911. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  4912. if (!sas_iounit_pg0) {
  4913. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4914. ioc->name, __FILE__, __LINE__, __func__);
  4915. return;
  4916. }
  4917. if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  4918. sas_iounit_pg0, sz)) != 0)
  4919. goto out;
  4920. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  4921. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  4922. goto out;
  4923. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  4924. link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
  4925. if (i == 0)
  4926. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  4927. PhyData[0].ControllerDevHandle);
  4928. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  4929. attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
  4930. AttachedDevHandle);
  4931. if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  4932. link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
  4933. mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
  4934. attached_handle, i, link_rate);
  4935. }
  4936. out:
  4937. kfree(sas_iounit_pg0);
  4938. }
  4939. /**
  4940. * _scsih_sas_host_add - create sas host object
  4941. * @ioc: per adapter object
  4942. *
  4943. * Creating host side data object, stored in ioc->sas_hba
  4944. */
  4945. static void
  4946. _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
  4947. {
  4948. int i;
  4949. Mpi2ConfigReply_t mpi_reply;
  4950. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  4951. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  4952. Mpi2SasPhyPage0_t phy_pg0;
  4953. Mpi2SasDevicePage0_t sas_device_pg0;
  4954. Mpi2SasEnclosurePage0_t enclosure_pg0;
  4955. u16 ioc_status;
  4956. u16 sz;
  4957. u8 device_missing_delay;
  4958. u8 num_phys;
  4959. mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
  4960. if (!num_phys) {
  4961. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4962. ioc->name, __FILE__, __LINE__, __func__);
  4963. return;
  4964. }
  4965. ioc->sas_hba.phy = kcalloc(num_phys,
  4966. sizeof(struct _sas_phy), GFP_KERNEL);
  4967. if (!ioc->sas_hba.phy) {
  4968. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4969. ioc->name, __FILE__, __LINE__, __func__);
  4970. goto out;
  4971. }
  4972. ioc->sas_hba.num_phys = num_phys;
  4973. /* sas_iounit page 0 */
  4974. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
  4975. sizeof(Mpi2SasIOUnit0PhyData_t));
  4976. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  4977. if (!sas_iounit_pg0) {
  4978. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4979. ioc->name, __FILE__, __LINE__, __func__);
  4980. return;
  4981. }
  4982. if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  4983. sas_iounit_pg0, sz))) {
  4984. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4985. ioc->name, __FILE__, __LINE__, __func__);
  4986. goto out;
  4987. }
  4988. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4989. MPI2_IOCSTATUS_MASK;
  4990. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4991. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  4992. ioc->name, __FILE__, __LINE__, __func__);
  4993. goto out;
  4994. }
  4995. /* sas_iounit page 1 */
  4996. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  4997. sizeof(Mpi2SasIOUnit1PhyData_t));
  4998. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  4999. if (!sas_iounit_pg1) {
  5000. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5001. ioc->name, __FILE__, __LINE__, __func__);
  5002. goto out;
  5003. }
  5004. if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  5005. sas_iounit_pg1, sz))) {
  5006. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5007. ioc->name, __FILE__, __LINE__, __func__);
  5008. goto out;
  5009. }
  5010. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5011. MPI2_IOCSTATUS_MASK;
  5012. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5013. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5014. ioc->name, __FILE__, __LINE__, __func__);
  5015. goto out;
  5016. }
  5017. ioc->io_missing_delay =
  5018. sas_iounit_pg1->IODeviceMissingDelay;
  5019. device_missing_delay =
  5020. sas_iounit_pg1->ReportDeviceMissingDelay;
  5021. if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  5022. ioc->device_missing_delay = (device_missing_delay &
  5023. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  5024. else
  5025. ioc->device_missing_delay = device_missing_delay &
  5026. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  5027. ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
  5028. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  5029. if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  5030. i))) {
  5031. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5032. ioc->name, __FILE__, __LINE__, __func__);
  5033. goto out;
  5034. }
  5035. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5036. MPI2_IOCSTATUS_MASK;
  5037. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5038. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5039. ioc->name, __FILE__, __LINE__, __func__);
  5040. goto out;
  5041. }
  5042. if (i == 0)
  5043. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  5044. PhyData[0].ControllerDevHandle);
  5045. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  5046. ioc->sas_hba.phy[i].phy_id = i;
  5047. mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
  5048. phy_pg0, ioc->sas_hba.parent_dev);
  5049. }
  5050. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  5051. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
  5052. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5053. ioc->name, __FILE__, __LINE__, __func__);
  5054. goto out;
  5055. }
  5056. ioc->sas_hba.enclosure_handle =
  5057. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  5058. ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  5059. pr_info(MPT3SAS_FMT
  5060. "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
  5061. ioc->name, ioc->sas_hba.handle,
  5062. (unsigned long long) ioc->sas_hba.sas_address,
  5063. ioc->sas_hba.num_phys) ;
  5064. if (ioc->sas_hba.enclosure_handle) {
  5065. if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  5066. &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  5067. ioc->sas_hba.enclosure_handle)))
  5068. ioc->sas_hba.enclosure_logical_id =
  5069. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  5070. }
  5071. out:
  5072. kfree(sas_iounit_pg1);
  5073. kfree(sas_iounit_pg0);
  5074. }
  5075. /**
  5076. * _scsih_expander_add - creating expander object
  5077. * @ioc: per adapter object
  5078. * @handle: expander handle
  5079. *
  5080. * Creating expander object, stored in ioc->sas_expander_list.
  5081. *
  5082. * Return: 0 for success, else error.
  5083. */
  5084. static int
  5085. _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  5086. {
  5087. struct _sas_node *sas_expander;
  5088. struct _enclosure_node *enclosure_dev;
  5089. Mpi2ConfigReply_t mpi_reply;
  5090. Mpi2ExpanderPage0_t expander_pg0;
  5091. Mpi2ExpanderPage1_t expander_pg1;
  5092. u32 ioc_status;
  5093. u16 parent_handle;
  5094. u64 sas_address, sas_address_parent = 0;
  5095. int i;
  5096. unsigned long flags;
  5097. struct _sas_port *mpt3sas_port = NULL;
  5098. int rc = 0;
  5099. if (!handle)
  5100. return -1;
  5101. if (ioc->shost_recovery || ioc->pci_error_recovery)
  5102. return -1;
  5103. if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  5104. MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
  5105. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5106. ioc->name, __FILE__, __LINE__, __func__);
  5107. return -1;
  5108. }
  5109. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5110. MPI2_IOCSTATUS_MASK;
  5111. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5112. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5113. ioc->name, __FILE__, __LINE__, __func__);
  5114. return -1;
  5115. }
  5116. /* handle out of order topology events */
  5117. parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
  5118. if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
  5119. != 0) {
  5120. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5121. ioc->name, __FILE__, __LINE__, __func__);
  5122. return -1;
  5123. }
  5124. if (sas_address_parent != ioc->sas_hba.sas_address) {
  5125. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5126. sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
  5127. sas_address_parent);
  5128. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5129. if (!sas_expander) {
  5130. rc = _scsih_expander_add(ioc, parent_handle);
  5131. if (rc != 0)
  5132. return rc;
  5133. }
  5134. }
  5135. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5136. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  5137. sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
  5138. sas_address);
  5139. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5140. if (sas_expander)
  5141. return 0;
  5142. sas_expander = kzalloc(sizeof(struct _sas_node),
  5143. GFP_KERNEL);
  5144. if (!sas_expander) {
  5145. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5146. ioc->name, __FILE__, __LINE__, __func__);
  5147. return -1;
  5148. }
  5149. sas_expander->handle = handle;
  5150. sas_expander->num_phys = expander_pg0.NumPhys;
  5151. sas_expander->sas_address_parent = sas_address_parent;
  5152. sas_expander->sas_address = sas_address;
  5153. pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
  5154. " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
  5155. handle, parent_handle, (unsigned long long)
  5156. sas_expander->sas_address, sas_expander->num_phys);
  5157. if (!sas_expander->num_phys)
  5158. goto out_fail;
  5159. sas_expander->phy = kcalloc(sas_expander->num_phys,
  5160. sizeof(struct _sas_phy), GFP_KERNEL);
  5161. if (!sas_expander->phy) {
  5162. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5163. ioc->name, __FILE__, __LINE__, __func__);
  5164. rc = -1;
  5165. goto out_fail;
  5166. }
  5167. INIT_LIST_HEAD(&sas_expander->sas_port_list);
  5168. mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
  5169. sas_address_parent);
  5170. if (!mpt3sas_port) {
  5171. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5172. ioc->name, __FILE__, __LINE__, __func__);
  5173. rc = -1;
  5174. goto out_fail;
  5175. }
  5176. sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
  5177. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  5178. if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
  5179. &expander_pg1, i, handle))) {
  5180. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5181. ioc->name, __FILE__, __LINE__, __func__);
  5182. rc = -1;
  5183. goto out_fail;
  5184. }
  5185. sas_expander->phy[i].handle = handle;
  5186. sas_expander->phy[i].phy_id = i;
  5187. if ((mpt3sas_transport_add_expander_phy(ioc,
  5188. &sas_expander->phy[i], expander_pg1,
  5189. sas_expander->parent_dev))) {
  5190. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5191. ioc->name, __FILE__, __LINE__, __func__);
  5192. rc = -1;
  5193. goto out_fail;
  5194. }
  5195. }
  5196. if (sas_expander->enclosure_handle) {
  5197. enclosure_dev =
  5198. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  5199. sas_expander->enclosure_handle);
  5200. if (enclosure_dev)
  5201. sas_expander->enclosure_logical_id =
  5202. le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
  5203. }
  5204. _scsih_expander_node_add(ioc, sas_expander);
  5205. return 0;
  5206. out_fail:
  5207. if (mpt3sas_port)
  5208. mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
  5209. sas_address_parent);
  5210. kfree(sas_expander);
  5211. return rc;
  5212. }
  5213. /**
  5214. * mpt3sas_expander_remove - removing expander object
  5215. * @ioc: per adapter object
  5216. * @sas_address: expander sas_address
  5217. */
  5218. void
  5219. mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
  5220. {
  5221. struct _sas_node *sas_expander;
  5222. unsigned long flags;
  5223. if (ioc->shost_recovery)
  5224. return;
  5225. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5226. sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
  5227. sas_address);
  5228. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5229. if (sas_expander)
  5230. _scsih_expander_node_remove(ioc, sas_expander);
  5231. }
  5232. /**
  5233. * _scsih_done - internal SCSI_IO callback handler.
  5234. * @ioc: per adapter object
  5235. * @smid: system request message index
  5236. * @msix_index: MSIX table index supplied by the OS
  5237. * @reply: reply message frame(lower 32bit addr)
  5238. *
  5239. * Callback handler when sending internal generated SCSI_IO.
  5240. * The callback index passed is `ioc->scsih_cb_idx`
  5241. *
  5242. * Return: 1 meaning mf should be freed from _base_interrupt
  5243. * 0 means the mf is freed from this function.
  5244. */
  5245. static u8
  5246. _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  5247. {
  5248. MPI2DefaultReply_t *mpi_reply;
  5249. mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
  5250. if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
  5251. return 1;
  5252. if (ioc->scsih_cmds.smid != smid)
  5253. return 1;
  5254. ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
  5255. if (mpi_reply) {
  5256. memcpy(ioc->scsih_cmds.reply, mpi_reply,
  5257. mpi_reply->MsgLength*4);
  5258. ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
  5259. }
  5260. ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
  5261. complete(&ioc->scsih_cmds.done);
  5262. return 1;
  5263. }
  5264. #define MPT3_MAX_LUNS (255)
  5265. /**
  5266. * _scsih_check_access_status - check access flags
  5267. * @ioc: per adapter object
  5268. * @sas_address: sas address
  5269. * @handle: sas device handle
  5270. * @access_status: errors returned during discovery of the device
  5271. *
  5272. * Return: 0 for success, else failure
  5273. */
  5274. static u8
  5275. _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
  5276. u16 handle, u8 access_status)
  5277. {
  5278. u8 rc = 1;
  5279. char *desc = NULL;
  5280. switch (access_status) {
  5281. case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
  5282. case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
  5283. rc = 0;
  5284. break;
  5285. case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
  5286. desc = "sata capability failed";
  5287. break;
  5288. case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
  5289. desc = "sata affiliation conflict";
  5290. break;
  5291. case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
  5292. desc = "route not addressable";
  5293. break;
  5294. case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
  5295. desc = "smp error not addressable";
  5296. break;
  5297. case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
  5298. desc = "device blocked";
  5299. break;
  5300. case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
  5301. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
  5302. case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
  5303. case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
  5304. case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
  5305. case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
  5306. case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
  5307. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
  5308. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
  5309. case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
  5310. case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
  5311. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
  5312. desc = "sata initialization failed";
  5313. break;
  5314. default:
  5315. desc = "unknown";
  5316. break;
  5317. }
  5318. if (!rc)
  5319. return 0;
  5320. pr_err(MPT3SAS_FMT
  5321. "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
  5322. ioc->name, desc, (unsigned long long)sas_address, handle);
  5323. return rc;
  5324. }
  5325. /**
  5326. * _scsih_check_device - checking device responsiveness
  5327. * @ioc: per adapter object
  5328. * @parent_sas_address: sas address of parent expander or sas host
  5329. * @handle: attached device handle
  5330. * @phy_number: phy number
  5331. * @link_rate: new link rate
  5332. */
  5333. static void
  5334. _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
  5335. u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
  5336. {
  5337. Mpi2ConfigReply_t mpi_reply;
  5338. Mpi2SasDevicePage0_t sas_device_pg0;
  5339. struct _sas_device *sas_device;
  5340. struct _enclosure_node *enclosure_dev = NULL;
  5341. u32 ioc_status;
  5342. unsigned long flags;
  5343. u64 sas_address;
  5344. struct scsi_target *starget;
  5345. struct MPT3SAS_TARGET *sas_target_priv_data;
  5346. u32 device_info;
  5347. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  5348. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
  5349. return;
  5350. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  5351. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  5352. return;
  5353. /* wide port handling ~ we need only handle device once for the phy that
  5354. * is matched in sas device page zero
  5355. */
  5356. if (phy_number != sas_device_pg0.PhyNum)
  5357. return;
  5358. /* check if this is end device */
  5359. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  5360. if (!(_scsih_is_end_device(device_info)))
  5361. return;
  5362. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5363. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  5364. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  5365. sas_address);
  5366. if (!sas_device)
  5367. goto out_unlock;
  5368. if (unlikely(sas_device->handle != handle)) {
  5369. starget = sas_device->starget;
  5370. sas_target_priv_data = starget->hostdata;
  5371. starget_printk(KERN_INFO, starget,
  5372. "handle changed from(0x%04x) to (0x%04x)!!!\n",
  5373. sas_device->handle, handle);
  5374. sas_target_priv_data->handle = handle;
  5375. sas_device->handle = handle;
  5376. if (le16_to_cpu(sas_device_pg0.Flags) &
  5377. MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
  5378. sas_device->enclosure_level =
  5379. sas_device_pg0.EnclosureLevel;
  5380. memcpy(sas_device->connector_name,
  5381. sas_device_pg0.ConnectorName, 4);
  5382. sas_device->connector_name[4] = '\0';
  5383. } else {
  5384. sas_device->enclosure_level = 0;
  5385. sas_device->connector_name[0] = '\0';
  5386. }
  5387. sas_device->enclosure_handle =
  5388. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  5389. sas_device->is_chassis_slot_valid = 0;
  5390. enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc,
  5391. sas_device->enclosure_handle);
  5392. if (enclosure_dev) {
  5393. sas_device->enclosure_logical_id =
  5394. le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
  5395. if (le16_to_cpu(enclosure_dev->pg0.Flags) &
  5396. MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
  5397. sas_device->is_chassis_slot_valid = 1;
  5398. sas_device->chassis_slot =
  5399. enclosure_dev->pg0.ChassisSlot;
  5400. }
  5401. }
  5402. }
  5403. /* check if device is present */
  5404. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  5405. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  5406. pr_err(MPT3SAS_FMT
  5407. "device is not present handle(0x%04x), flags!!!\n",
  5408. ioc->name, handle);
  5409. goto out_unlock;
  5410. }
  5411. /* check if there were any issues with discovery */
  5412. if (_scsih_check_access_status(ioc, sas_address, handle,
  5413. sas_device_pg0.AccessStatus))
  5414. goto out_unlock;
  5415. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5416. _scsih_ublock_io_device(ioc, sas_address);
  5417. if (sas_device)
  5418. sas_device_put(sas_device);
  5419. return;
  5420. out_unlock:
  5421. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5422. if (sas_device)
  5423. sas_device_put(sas_device);
  5424. }
  5425. /**
  5426. * _scsih_add_device - creating sas device object
  5427. * @ioc: per adapter object
  5428. * @handle: sas device handle
  5429. * @phy_num: phy number end device attached to
  5430. * @is_pd: is this hidden raid component
  5431. *
  5432. * Creating end device object, stored in ioc->sas_device_list.
  5433. *
  5434. * Return: 0 for success, non-zero for failure.
  5435. */
  5436. static int
  5437. _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
  5438. u8 is_pd)
  5439. {
  5440. Mpi2ConfigReply_t mpi_reply;
  5441. Mpi2SasDevicePage0_t sas_device_pg0;
  5442. struct _sas_device *sas_device;
  5443. struct _enclosure_node *enclosure_dev = NULL;
  5444. u32 ioc_status;
  5445. u64 sas_address;
  5446. u32 device_info;
  5447. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  5448. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  5449. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5450. ioc->name, __FILE__, __LINE__, __func__);
  5451. return -1;
  5452. }
  5453. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5454. MPI2_IOCSTATUS_MASK;
  5455. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5456. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5457. ioc->name, __FILE__, __LINE__, __func__);
  5458. return -1;
  5459. }
  5460. /* check if this is end device */
  5461. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  5462. if (!(_scsih_is_end_device(device_info)))
  5463. return -1;
  5464. set_bit(handle, ioc->pend_os_device_add);
  5465. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  5466. /* check if device is present */
  5467. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  5468. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  5469. pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
  5470. ioc->name, handle);
  5471. return -1;
  5472. }
  5473. /* check if there were any issues with discovery */
  5474. if (_scsih_check_access_status(ioc, sas_address, handle,
  5475. sas_device_pg0.AccessStatus))
  5476. return -1;
  5477. sas_device = mpt3sas_get_sdev_by_addr(ioc,
  5478. sas_address);
  5479. if (sas_device) {
  5480. clear_bit(handle, ioc->pend_os_device_add);
  5481. sas_device_put(sas_device);
  5482. return -1;
  5483. }
  5484. if (sas_device_pg0.EnclosureHandle) {
  5485. enclosure_dev =
  5486. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  5487. le16_to_cpu(sas_device_pg0.EnclosureHandle));
  5488. if (enclosure_dev == NULL)
  5489. pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
  5490. "doesn't match with enclosure device!\n",
  5491. ioc->name, sas_device_pg0.EnclosureHandle);
  5492. }
  5493. sas_device = kzalloc(sizeof(struct _sas_device),
  5494. GFP_KERNEL);
  5495. if (!sas_device) {
  5496. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5497. ioc->name, __FILE__, __LINE__, __func__);
  5498. return 0;
  5499. }
  5500. kref_init(&sas_device->refcount);
  5501. sas_device->handle = handle;
  5502. if (_scsih_get_sas_address(ioc,
  5503. le16_to_cpu(sas_device_pg0.ParentDevHandle),
  5504. &sas_device->sas_address_parent) != 0)
  5505. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  5506. ioc->name, __FILE__, __LINE__, __func__);
  5507. sas_device->enclosure_handle =
  5508. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  5509. if (sas_device->enclosure_handle != 0)
  5510. sas_device->slot =
  5511. le16_to_cpu(sas_device_pg0.Slot);
  5512. sas_device->device_info = device_info;
  5513. sas_device->sas_address = sas_address;
  5514. sas_device->phy = sas_device_pg0.PhyNum;
  5515. sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
  5516. MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
  5517. if (le16_to_cpu(sas_device_pg0.Flags)
  5518. & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
  5519. sas_device->enclosure_level =
  5520. sas_device_pg0.EnclosureLevel;
  5521. memcpy(sas_device->connector_name,
  5522. sas_device_pg0.ConnectorName, 4);
  5523. sas_device->connector_name[4] = '\0';
  5524. } else {
  5525. sas_device->enclosure_level = 0;
  5526. sas_device->connector_name[0] = '\0';
  5527. }
  5528. /* get enclosure_logical_id & chassis_slot*/
  5529. sas_device->is_chassis_slot_valid = 0;
  5530. if (enclosure_dev) {
  5531. sas_device->enclosure_logical_id =
  5532. le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
  5533. if (le16_to_cpu(enclosure_dev->pg0.Flags) &
  5534. MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
  5535. sas_device->is_chassis_slot_valid = 1;
  5536. sas_device->chassis_slot =
  5537. enclosure_dev->pg0.ChassisSlot;
  5538. }
  5539. }
  5540. /* get device name */
  5541. sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
  5542. if (ioc->wait_for_discovery_to_complete)
  5543. _scsih_sas_device_init_add(ioc, sas_device);
  5544. else
  5545. _scsih_sas_device_add(ioc, sas_device);
  5546. sas_device_put(sas_device);
  5547. return 0;
  5548. }
  5549. /**
  5550. * _scsih_remove_device - removing sas device object
  5551. * @ioc: per adapter object
  5552. * @sas_device: the sas_device object
  5553. */
  5554. static void
  5555. _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
  5556. struct _sas_device *sas_device)
  5557. {
  5558. struct MPT3SAS_TARGET *sas_target_priv_data;
  5559. if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
  5560. (sas_device->pfa_led_on)) {
  5561. _scsih_turn_off_pfa_led(ioc, sas_device);
  5562. sas_device->pfa_led_on = 0;
  5563. }
  5564. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5565. "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
  5566. ioc->name, __func__,
  5567. sas_device->handle, (unsigned long long)
  5568. sas_device->sas_address));
  5569. dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
  5570. NULL, NULL));
  5571. if (sas_device->starget && sas_device->starget->hostdata) {
  5572. sas_target_priv_data = sas_device->starget->hostdata;
  5573. sas_target_priv_data->deleted = 1;
  5574. _scsih_ublock_io_device(ioc, sas_device->sas_address);
  5575. sas_target_priv_data->handle =
  5576. MPT3SAS_INVALID_DEVICE_HANDLE;
  5577. }
  5578. if (!ioc->hide_drives)
  5579. mpt3sas_transport_port_remove(ioc,
  5580. sas_device->sas_address,
  5581. sas_device->sas_address_parent);
  5582. pr_info(MPT3SAS_FMT
  5583. "removing handle(0x%04x), sas_addr(0x%016llx)\n",
  5584. ioc->name, sas_device->handle,
  5585. (unsigned long long) sas_device->sas_address);
  5586. _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
  5587. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5588. "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
  5589. ioc->name, __func__,
  5590. sas_device->handle, (unsigned long long)
  5591. sas_device->sas_address));
  5592. dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
  5593. NULL, NULL));
  5594. }
  5595. /**
  5596. * _scsih_sas_topology_change_event_debug - debug for topology event
  5597. * @ioc: per adapter object
  5598. * @event_data: event data payload
  5599. * Context: user.
  5600. */
  5601. static void
  5602. _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  5603. Mpi2EventDataSasTopologyChangeList_t *event_data)
  5604. {
  5605. int i;
  5606. u16 handle;
  5607. u16 reason_code;
  5608. u8 phy_number;
  5609. char *status_str = NULL;
  5610. u8 link_rate, prev_link_rate;
  5611. switch (event_data->ExpStatus) {
  5612. case MPI2_EVENT_SAS_TOPO_ES_ADDED:
  5613. status_str = "add";
  5614. break;
  5615. case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
  5616. status_str = "remove";
  5617. break;
  5618. case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
  5619. case 0:
  5620. status_str = "responding";
  5621. break;
  5622. case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
  5623. status_str = "remove delay";
  5624. break;
  5625. default:
  5626. status_str = "unknown status";
  5627. break;
  5628. }
  5629. pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
  5630. ioc->name, status_str);
  5631. pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
  5632. "start_phy(%02d), count(%d)\n",
  5633. le16_to_cpu(event_data->ExpanderDevHandle),
  5634. le16_to_cpu(event_data->EnclosureHandle),
  5635. event_data->StartPhyNum, event_data->NumEntries);
  5636. for (i = 0; i < event_data->NumEntries; i++) {
  5637. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  5638. if (!handle)
  5639. continue;
  5640. phy_number = event_data->StartPhyNum + i;
  5641. reason_code = event_data->PHY[i].PhyStatus &
  5642. MPI2_EVENT_SAS_TOPO_RC_MASK;
  5643. switch (reason_code) {
  5644. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  5645. status_str = "target add";
  5646. break;
  5647. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  5648. status_str = "target remove";
  5649. break;
  5650. case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
  5651. status_str = "delay target remove";
  5652. break;
  5653. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  5654. status_str = "link rate change";
  5655. break;
  5656. case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
  5657. status_str = "target responding";
  5658. break;
  5659. default:
  5660. status_str = "unknown";
  5661. break;
  5662. }
  5663. link_rate = event_data->PHY[i].LinkRate >> 4;
  5664. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  5665. pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
  5666. " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
  5667. handle, status_str, link_rate, prev_link_rate);
  5668. }
  5669. }
  5670. /**
  5671. * _scsih_sas_topology_change_event - handle topology changes
  5672. * @ioc: per adapter object
  5673. * @fw_event: The fw_event_work object
  5674. * Context: user.
  5675. *
  5676. */
  5677. static int
  5678. _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
  5679. struct fw_event_work *fw_event)
  5680. {
  5681. int i;
  5682. u16 parent_handle, handle;
  5683. u16 reason_code;
  5684. u8 phy_number, max_phys;
  5685. struct _sas_node *sas_expander;
  5686. u64 sas_address;
  5687. unsigned long flags;
  5688. u8 link_rate, prev_link_rate;
  5689. Mpi2EventDataSasTopologyChangeList_t *event_data =
  5690. (Mpi2EventDataSasTopologyChangeList_t *)
  5691. fw_event->event_data;
  5692. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5693. _scsih_sas_topology_change_event_debug(ioc, event_data);
  5694. if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
  5695. return 0;
  5696. if (!ioc->sas_hba.num_phys)
  5697. _scsih_sas_host_add(ioc);
  5698. else
  5699. _scsih_sas_host_refresh(ioc);
  5700. if (fw_event->ignore) {
  5701. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5702. "ignoring expander event\n", ioc->name));
  5703. return 0;
  5704. }
  5705. parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  5706. /* handle expander add */
  5707. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
  5708. if (_scsih_expander_add(ioc, parent_handle) != 0)
  5709. return 0;
  5710. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5711. sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
  5712. parent_handle);
  5713. if (sas_expander) {
  5714. sas_address = sas_expander->sas_address;
  5715. max_phys = sas_expander->num_phys;
  5716. } else if (parent_handle < ioc->sas_hba.num_phys) {
  5717. sas_address = ioc->sas_hba.sas_address;
  5718. max_phys = ioc->sas_hba.num_phys;
  5719. } else {
  5720. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5721. return 0;
  5722. }
  5723. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5724. /* handle siblings events */
  5725. for (i = 0; i < event_data->NumEntries; i++) {
  5726. if (fw_event->ignore) {
  5727. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5728. "ignoring expander event\n", ioc->name));
  5729. return 0;
  5730. }
  5731. if (ioc->remove_host || ioc->pci_error_recovery)
  5732. return 0;
  5733. phy_number = event_data->StartPhyNum + i;
  5734. if (phy_number >= max_phys)
  5735. continue;
  5736. reason_code = event_data->PHY[i].PhyStatus &
  5737. MPI2_EVENT_SAS_TOPO_RC_MASK;
  5738. if ((event_data->PHY[i].PhyStatus &
  5739. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
  5740. MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
  5741. continue;
  5742. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  5743. if (!handle)
  5744. continue;
  5745. link_rate = event_data->PHY[i].LinkRate >> 4;
  5746. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  5747. switch (reason_code) {
  5748. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  5749. if (ioc->shost_recovery)
  5750. break;
  5751. if (link_rate == prev_link_rate)
  5752. break;
  5753. mpt3sas_transport_update_links(ioc, sas_address,
  5754. handle, phy_number, link_rate);
  5755. if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  5756. break;
  5757. _scsih_check_device(ioc, sas_address, handle,
  5758. phy_number, link_rate);
  5759. if (!test_bit(handle, ioc->pend_os_device_add))
  5760. break;
  5761. /* fall through */
  5762. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  5763. if (ioc->shost_recovery)
  5764. break;
  5765. mpt3sas_transport_update_links(ioc, sas_address,
  5766. handle, phy_number, link_rate);
  5767. _scsih_add_device(ioc, handle, phy_number, 0);
  5768. break;
  5769. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  5770. _scsih_device_remove_by_handle(ioc, handle);
  5771. break;
  5772. }
  5773. }
  5774. /* handle expander removal */
  5775. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
  5776. sas_expander)
  5777. mpt3sas_expander_remove(ioc, sas_address);
  5778. return 0;
  5779. }
  5780. /**
  5781. * _scsih_sas_device_status_change_event_debug - debug for device event
  5782. * @ioc: ?
  5783. * @event_data: event data payload
  5784. * Context: user.
  5785. */
  5786. static void
  5787. _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  5788. Mpi2EventDataSasDeviceStatusChange_t *event_data)
  5789. {
  5790. char *reason_str = NULL;
  5791. switch (event_data->ReasonCode) {
  5792. case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  5793. reason_str = "smart data";
  5794. break;
  5795. case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  5796. reason_str = "unsupported device discovered";
  5797. break;
  5798. case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  5799. reason_str = "internal device reset";
  5800. break;
  5801. case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  5802. reason_str = "internal task abort";
  5803. break;
  5804. case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  5805. reason_str = "internal task abort set";
  5806. break;
  5807. case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  5808. reason_str = "internal clear task set";
  5809. break;
  5810. case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  5811. reason_str = "internal query task";
  5812. break;
  5813. case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
  5814. reason_str = "sata init failure";
  5815. break;
  5816. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  5817. reason_str = "internal device reset complete";
  5818. break;
  5819. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  5820. reason_str = "internal task abort complete";
  5821. break;
  5822. case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
  5823. reason_str = "internal async notification";
  5824. break;
  5825. case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
  5826. reason_str = "expander reduced functionality";
  5827. break;
  5828. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
  5829. reason_str = "expander reduced functionality complete";
  5830. break;
  5831. default:
  5832. reason_str = "unknown reason";
  5833. break;
  5834. }
  5835. pr_info(MPT3SAS_FMT "device status change: (%s)\n"
  5836. "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
  5837. ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
  5838. (unsigned long long)le64_to_cpu(event_data->SASAddress),
  5839. le16_to_cpu(event_data->TaskTag));
  5840. if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
  5841. pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  5842. event_data->ASC, event_data->ASCQ);
  5843. pr_info("\n");
  5844. }
  5845. /**
  5846. * _scsih_sas_device_status_change_event - handle device status change
  5847. * @ioc: per adapter object
  5848. * @fw_event: The fw_event_work object
  5849. * Context: user.
  5850. */
  5851. static void
  5852. _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
  5853. struct fw_event_work *fw_event)
  5854. {
  5855. struct MPT3SAS_TARGET *target_priv_data;
  5856. struct _sas_device *sas_device;
  5857. u64 sas_address;
  5858. unsigned long flags;
  5859. Mpi2EventDataSasDeviceStatusChange_t *event_data =
  5860. (Mpi2EventDataSasDeviceStatusChange_t *)
  5861. fw_event->event_data;
  5862. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5863. _scsih_sas_device_status_change_event_debug(ioc,
  5864. event_data);
  5865. /* In MPI Revision K (0xC), the internal device reset complete was
  5866. * implemented, so avoid setting tm_busy flag for older firmware.
  5867. */
  5868. if ((ioc->facts.HeaderVersion >> 8) < 0xC)
  5869. return;
  5870. if (event_data->ReasonCode !=
  5871. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
  5872. event_data->ReasonCode !=
  5873. MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
  5874. return;
  5875. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5876. sas_address = le64_to_cpu(event_data->SASAddress);
  5877. sas_device = __mpt3sas_get_sdev_by_addr(ioc,
  5878. sas_address);
  5879. if (!sas_device || !sas_device->starget)
  5880. goto out;
  5881. target_priv_data = sas_device->starget->hostdata;
  5882. if (!target_priv_data)
  5883. goto out;
  5884. if (event_data->ReasonCode ==
  5885. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
  5886. target_priv_data->tm_busy = 1;
  5887. else
  5888. target_priv_data->tm_busy = 0;
  5889. out:
  5890. if (sas_device)
  5891. sas_device_put(sas_device);
  5892. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5893. }
  5894. /**
  5895. * _scsih_check_pcie_access_status - check access flags
  5896. * @ioc: per adapter object
  5897. * @wwid: wwid
  5898. * @handle: sas device handle
  5899. * @access_status: errors returned during discovery of the device
  5900. *
  5901. * Return: 0 for success, else failure
  5902. */
  5903. static u8
  5904. _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
  5905. u16 handle, u8 access_status)
  5906. {
  5907. u8 rc = 1;
  5908. char *desc = NULL;
  5909. switch (access_status) {
  5910. case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS:
  5911. case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION:
  5912. rc = 0;
  5913. break;
  5914. case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED:
  5915. desc = "PCIe device capability failed";
  5916. break;
  5917. case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED:
  5918. desc = "PCIe device blocked";
  5919. break;
  5920. case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED:
  5921. desc = "PCIe device mem space access failed";
  5922. break;
  5923. case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE:
  5924. desc = "PCIe device unsupported";
  5925. break;
  5926. case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED:
  5927. desc = "PCIe device MSIx Required";
  5928. break;
  5929. case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX:
  5930. desc = "PCIe device init fail max";
  5931. break;
  5932. case MPI26_PCIEDEV0_ASTATUS_UNKNOWN:
  5933. desc = "PCIe device status unknown";
  5934. break;
  5935. case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT:
  5936. desc = "nvme ready timeout";
  5937. break;
  5938. case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED:
  5939. desc = "nvme device configuration unsupported";
  5940. break;
  5941. case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED:
  5942. desc = "nvme identify failed";
  5943. break;
  5944. case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED:
  5945. desc = "nvme qconfig failed";
  5946. break;
  5947. case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED:
  5948. desc = "nvme qcreation failed";
  5949. break;
  5950. case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED:
  5951. desc = "nvme eventcfg failed";
  5952. break;
  5953. case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED:
  5954. desc = "nvme get feature stat failed";
  5955. break;
  5956. case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT:
  5957. desc = "nvme idle timeout";
  5958. break;
  5959. case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS:
  5960. desc = "nvme failure status";
  5961. break;
  5962. default:
  5963. pr_err(MPT3SAS_FMT
  5964. " NVMe discovery error(0x%02x): wwid(0x%016llx),"
  5965. "handle(0x%04x)\n", ioc->name, access_status,
  5966. (unsigned long long)wwid, handle);
  5967. return rc;
  5968. }
  5969. if (!rc)
  5970. return rc;
  5971. pr_info(MPT3SAS_FMT
  5972. "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
  5973. ioc->name, desc,
  5974. (unsigned long long)wwid, handle);
  5975. return rc;
  5976. }
  5977. /**
  5978. * _scsih_pcie_device_remove_from_sml - removing pcie device
  5979. * from SML and free up associated memory
  5980. * @ioc: per adapter object
  5981. * @pcie_device: the pcie_device object
  5982. */
  5983. static void
  5984. _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
  5985. struct _pcie_device *pcie_device)
  5986. {
  5987. struct MPT3SAS_TARGET *sas_target_priv_data;
  5988. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5989. "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  5990. pcie_device->handle, (unsigned long long)
  5991. pcie_device->wwid));
  5992. if (pcie_device->enclosure_handle != 0)
  5993. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  5994. "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
  5995. ioc->name, __func__,
  5996. (unsigned long long)pcie_device->enclosure_logical_id,
  5997. pcie_device->slot));
  5998. if (pcie_device->connector_name[0] != '\0')
  5999. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6000. "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
  6001. ioc->name, __func__,
  6002. pcie_device->enclosure_level,
  6003. pcie_device->connector_name));
  6004. if (pcie_device->starget && pcie_device->starget->hostdata) {
  6005. sas_target_priv_data = pcie_device->starget->hostdata;
  6006. sas_target_priv_data->deleted = 1;
  6007. _scsih_ublock_io_device(ioc, pcie_device->wwid);
  6008. sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
  6009. }
  6010. pr_info(MPT3SAS_FMT
  6011. "removing handle(0x%04x), wwid (0x%016llx)\n",
  6012. ioc->name, pcie_device->handle,
  6013. (unsigned long long) pcie_device->wwid);
  6014. if (pcie_device->enclosure_handle != 0)
  6015. pr_info(MPT3SAS_FMT
  6016. "removing : enclosure logical id(0x%016llx), slot(%d)\n",
  6017. ioc->name,
  6018. (unsigned long long)pcie_device->enclosure_logical_id,
  6019. pcie_device->slot);
  6020. if (pcie_device->connector_name[0] != '\0')
  6021. pr_info(MPT3SAS_FMT
  6022. "removing: enclosure level(0x%04x), connector name( %s)\n",
  6023. ioc->name, pcie_device->enclosure_level,
  6024. pcie_device->connector_name);
  6025. if (pcie_device->starget)
  6026. scsi_remove_target(&pcie_device->starget->dev);
  6027. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6028. "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  6029. pcie_device->handle, (unsigned long long)
  6030. pcie_device->wwid));
  6031. if (pcie_device->enclosure_handle != 0)
  6032. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6033. "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
  6034. ioc->name, __func__,
  6035. (unsigned long long)pcie_device->enclosure_logical_id,
  6036. pcie_device->slot));
  6037. if (pcie_device->connector_name[0] != '\0')
  6038. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6039. "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
  6040. ioc->name, __func__, pcie_device->enclosure_level,
  6041. pcie_device->connector_name));
  6042. kfree(pcie_device->serial_number);
  6043. }
  6044. /**
  6045. * _scsih_pcie_check_device - checking device responsiveness
  6046. * @ioc: per adapter object
  6047. * @handle: attached device handle
  6048. */
  6049. static void
  6050. _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  6051. {
  6052. Mpi2ConfigReply_t mpi_reply;
  6053. Mpi26PCIeDevicePage0_t pcie_device_pg0;
  6054. u32 ioc_status;
  6055. struct _pcie_device *pcie_device;
  6056. u64 wwid;
  6057. unsigned long flags;
  6058. struct scsi_target *starget;
  6059. struct MPT3SAS_TARGET *sas_target_priv_data;
  6060. u32 device_info;
  6061. if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
  6062. &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
  6063. return;
  6064. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  6065. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  6066. return;
  6067. /* check if this is end device */
  6068. device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
  6069. if (!(_scsih_is_nvme_device(device_info)))
  6070. return;
  6071. wwid = le64_to_cpu(pcie_device_pg0.WWID);
  6072. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  6073. pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
  6074. if (!pcie_device) {
  6075. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6076. return;
  6077. }
  6078. if (unlikely(pcie_device->handle != handle)) {
  6079. starget = pcie_device->starget;
  6080. sas_target_priv_data = starget->hostdata;
  6081. starget_printk(KERN_INFO, starget,
  6082. "handle changed from(0x%04x) to (0x%04x)!!!\n",
  6083. pcie_device->handle, handle);
  6084. sas_target_priv_data->handle = handle;
  6085. pcie_device->handle = handle;
  6086. if (le32_to_cpu(pcie_device_pg0.Flags) &
  6087. MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
  6088. pcie_device->enclosure_level =
  6089. pcie_device_pg0.EnclosureLevel;
  6090. memcpy(&pcie_device->connector_name[0],
  6091. &pcie_device_pg0.ConnectorName[0], 4);
  6092. } else {
  6093. pcie_device->enclosure_level = 0;
  6094. pcie_device->connector_name[0] = '\0';
  6095. }
  6096. }
  6097. /* check if device is present */
  6098. if (!(le32_to_cpu(pcie_device_pg0.Flags) &
  6099. MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
  6100. pr_info(MPT3SAS_FMT
  6101. "device is not present handle(0x%04x), flags!!!\n",
  6102. ioc->name, handle);
  6103. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6104. pcie_device_put(pcie_device);
  6105. return;
  6106. }
  6107. /* check if there were any issues with discovery */
  6108. if (_scsih_check_pcie_access_status(ioc, wwid, handle,
  6109. pcie_device_pg0.AccessStatus)) {
  6110. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6111. pcie_device_put(pcie_device);
  6112. return;
  6113. }
  6114. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6115. pcie_device_put(pcie_device);
  6116. _scsih_ublock_io_device(ioc, wwid);
  6117. return;
  6118. }
  6119. /**
  6120. * _scsih_pcie_add_device - creating pcie device object
  6121. * @ioc: per adapter object
  6122. * @handle: pcie device handle
  6123. *
  6124. * Creating end device object, stored in ioc->pcie_device_list.
  6125. *
  6126. * Return: 1 means queue the event later, 0 means complete the event
  6127. */
  6128. static int
  6129. _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  6130. {
  6131. Mpi26PCIeDevicePage0_t pcie_device_pg0;
  6132. Mpi26PCIeDevicePage2_t pcie_device_pg2;
  6133. Mpi2ConfigReply_t mpi_reply;
  6134. struct _pcie_device *pcie_device;
  6135. struct _enclosure_node *enclosure_dev;
  6136. u32 ioc_status;
  6137. u64 wwid;
  6138. if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
  6139. &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
  6140. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  6141. ioc->name, __FILE__, __LINE__, __func__);
  6142. return 0;
  6143. }
  6144. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6145. MPI2_IOCSTATUS_MASK;
  6146. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  6147. pr_err(MPT3SAS_FMT
  6148. "failure at %s:%d/%s()!\n",
  6149. ioc->name, __FILE__, __LINE__, __func__);
  6150. return 0;
  6151. }
  6152. set_bit(handle, ioc->pend_os_device_add);
  6153. wwid = le64_to_cpu(pcie_device_pg0.WWID);
  6154. /* check if device is present */
  6155. if (!(le32_to_cpu(pcie_device_pg0.Flags) &
  6156. MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
  6157. pr_err(MPT3SAS_FMT
  6158. "device is not present handle(0x04%x)!!!\n",
  6159. ioc->name, handle);
  6160. return 0;
  6161. }
  6162. /* check if there were any issues with discovery */
  6163. if (_scsih_check_pcie_access_status(ioc, wwid, handle,
  6164. pcie_device_pg0.AccessStatus))
  6165. return 0;
  6166. if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo))))
  6167. return 0;
  6168. pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid);
  6169. if (pcie_device) {
  6170. clear_bit(handle, ioc->pend_os_device_add);
  6171. pcie_device_put(pcie_device);
  6172. return 0;
  6173. }
  6174. pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL);
  6175. if (!pcie_device) {
  6176. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  6177. ioc->name, __FILE__, __LINE__, __func__);
  6178. return 0;
  6179. }
  6180. kref_init(&pcie_device->refcount);
  6181. pcie_device->id = ioc->pcie_target_id++;
  6182. pcie_device->channel = PCIE_CHANNEL;
  6183. pcie_device->handle = handle;
  6184. pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
  6185. pcie_device->wwid = wwid;
  6186. pcie_device->port_num = pcie_device_pg0.PortNum;
  6187. pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) &
  6188. MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
  6189. pcie_device->enclosure_handle =
  6190. le16_to_cpu(pcie_device_pg0.EnclosureHandle);
  6191. if (pcie_device->enclosure_handle != 0)
  6192. pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot);
  6193. if (le32_to_cpu(pcie_device_pg0.Flags) &
  6194. MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
  6195. pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel;
  6196. memcpy(&pcie_device->connector_name[0],
  6197. &pcie_device_pg0.ConnectorName[0], 4);
  6198. } else {
  6199. pcie_device->enclosure_level = 0;
  6200. pcie_device->connector_name[0] = '\0';
  6201. }
  6202. /* get enclosure_logical_id */
  6203. if (pcie_device->enclosure_handle) {
  6204. enclosure_dev =
  6205. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  6206. pcie_device->enclosure_handle);
  6207. if (enclosure_dev)
  6208. pcie_device->enclosure_logical_id =
  6209. le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
  6210. }
  6211. /* TODO -- Add device name once FW supports it */
  6212. if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply,
  6213. &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) {
  6214. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  6215. ioc->name, __FILE__, __LINE__, __func__);
  6216. kfree(pcie_device);
  6217. return 0;
  6218. }
  6219. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  6220. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  6221. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  6222. ioc->name, __FILE__, __LINE__, __func__);
  6223. kfree(pcie_device);
  6224. return 0;
  6225. }
  6226. pcie_device->nvme_mdts =
  6227. le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize);
  6228. if (pcie_device_pg2.ControllerResetTO)
  6229. pcie_device->reset_timeout =
  6230. pcie_device_pg2.ControllerResetTO;
  6231. else
  6232. pcie_device->reset_timeout = 30;
  6233. if (ioc->wait_for_discovery_to_complete)
  6234. _scsih_pcie_device_init_add(ioc, pcie_device);
  6235. else
  6236. _scsih_pcie_device_add(ioc, pcie_device);
  6237. pcie_device_put(pcie_device);
  6238. return 0;
  6239. }
  6240. /**
  6241. * _scsih_pcie_topology_change_event_debug - debug for topology
  6242. * event
  6243. * @ioc: per adapter object
  6244. * @event_data: event data payload
  6245. * Context: user.
  6246. */
  6247. static void
  6248. _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  6249. Mpi26EventDataPCIeTopologyChangeList_t *event_data)
  6250. {
  6251. int i;
  6252. u16 handle;
  6253. u16 reason_code;
  6254. u8 port_number;
  6255. char *status_str = NULL;
  6256. u8 link_rate, prev_link_rate;
  6257. switch (event_data->SwitchStatus) {
  6258. case MPI26_EVENT_PCIE_TOPO_SS_ADDED:
  6259. status_str = "add";
  6260. break;
  6261. case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
  6262. status_str = "remove";
  6263. break;
  6264. case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING:
  6265. case 0:
  6266. status_str = "responding";
  6267. break;
  6268. case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
  6269. status_str = "remove delay";
  6270. break;
  6271. default:
  6272. status_str = "unknown status";
  6273. break;
  6274. }
  6275. pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n",
  6276. ioc->name, status_str);
  6277. pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
  6278. "start_port(%02d), count(%d)\n",
  6279. le16_to_cpu(event_data->SwitchDevHandle),
  6280. le16_to_cpu(event_data->EnclosureHandle),
  6281. event_data->StartPortNum, event_data->NumEntries);
  6282. for (i = 0; i < event_data->NumEntries; i++) {
  6283. handle =
  6284. le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
  6285. if (!handle)
  6286. continue;
  6287. port_number = event_data->StartPortNum + i;
  6288. reason_code = event_data->PortEntry[i].PortStatus;
  6289. switch (reason_code) {
  6290. case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
  6291. status_str = "target add";
  6292. break;
  6293. case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
  6294. status_str = "target remove";
  6295. break;
  6296. case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
  6297. status_str = "delay target remove";
  6298. break;
  6299. case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
  6300. status_str = "link rate change";
  6301. break;
  6302. case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
  6303. status_str = "target responding";
  6304. break;
  6305. default:
  6306. status_str = "unknown";
  6307. break;
  6308. }
  6309. link_rate = event_data->PortEntry[i].CurrentPortInfo &
  6310. MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
  6311. prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
  6312. MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
  6313. pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
  6314. " link rate: new(0x%02x), old(0x%02x)\n", port_number,
  6315. handle, status_str, link_rate, prev_link_rate);
  6316. }
  6317. }
  6318. /**
  6319. * _scsih_pcie_topology_change_event - handle PCIe topology
  6320. * changes
  6321. * @ioc: per adapter object
  6322. * @fw_event: The fw_event_work object
  6323. * Context: user.
  6324. *
  6325. */
  6326. static void
  6327. _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
  6328. struct fw_event_work *fw_event)
  6329. {
  6330. int i;
  6331. u16 handle;
  6332. u16 reason_code;
  6333. u8 link_rate, prev_link_rate;
  6334. unsigned long flags;
  6335. int rc;
  6336. Mpi26EventDataPCIeTopologyChangeList_t *event_data =
  6337. (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data;
  6338. struct _pcie_device *pcie_device;
  6339. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  6340. _scsih_pcie_topology_change_event_debug(ioc, event_data);
  6341. if (ioc->shost_recovery || ioc->remove_host ||
  6342. ioc->pci_error_recovery)
  6343. return;
  6344. if (fw_event->ignore) {
  6345. dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n",
  6346. ioc->name));
  6347. return;
  6348. }
  6349. /* handle siblings events */
  6350. for (i = 0; i < event_data->NumEntries; i++) {
  6351. if (fw_event->ignore) {
  6352. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6353. "ignoring switch event\n", ioc->name));
  6354. return;
  6355. }
  6356. if (ioc->remove_host || ioc->pci_error_recovery)
  6357. return;
  6358. reason_code = event_data->PortEntry[i].PortStatus;
  6359. handle =
  6360. le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
  6361. if (!handle)
  6362. continue;
  6363. link_rate = event_data->PortEntry[i].CurrentPortInfo
  6364. & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
  6365. prev_link_rate = event_data->PortEntry[i].PreviousPortInfo
  6366. & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
  6367. switch (reason_code) {
  6368. case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
  6369. if (ioc->shost_recovery)
  6370. break;
  6371. if (link_rate == prev_link_rate)
  6372. break;
  6373. if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
  6374. break;
  6375. _scsih_pcie_check_device(ioc, handle);
  6376. /* This code after this point handles the test case
  6377. * where a device has been added, however its returning
  6378. * BUSY for sometime. Then before the Device Missing
  6379. * Delay expires and the device becomes READY, the
  6380. * device is removed and added back.
  6381. */
  6382. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  6383. pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
  6384. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6385. if (pcie_device) {
  6386. pcie_device_put(pcie_device);
  6387. break;
  6388. }
  6389. if (!test_bit(handle, ioc->pend_os_device_add))
  6390. break;
  6391. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6392. "handle(0x%04x) device not found: convert "
  6393. "event to a device add\n", ioc->name, handle));
  6394. event_data->PortEntry[i].PortStatus &= 0xF0;
  6395. event_data->PortEntry[i].PortStatus |=
  6396. MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED;
  6397. /* fall through */
  6398. case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
  6399. if (ioc->shost_recovery)
  6400. break;
  6401. if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
  6402. break;
  6403. rc = _scsih_pcie_add_device(ioc, handle);
  6404. if (!rc) {
  6405. /* mark entry vacant */
  6406. /* TODO This needs to be reviewed and fixed,
  6407. * we dont have an entry
  6408. * to make an event void like vacant
  6409. */
  6410. event_data->PortEntry[i].PortStatus |=
  6411. MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE;
  6412. }
  6413. break;
  6414. case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
  6415. _scsih_pcie_device_remove_by_handle(ioc, handle);
  6416. break;
  6417. }
  6418. }
  6419. }
  6420. /**
  6421. * _scsih_pcie_device_status_change_event_debug - debug for device event
  6422. * @ioc: ?
  6423. * @event_data: event data payload
  6424. * Context: user.
  6425. */
  6426. static void
  6427. _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  6428. Mpi26EventDataPCIeDeviceStatusChange_t *event_data)
  6429. {
  6430. char *reason_str = NULL;
  6431. switch (event_data->ReasonCode) {
  6432. case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA:
  6433. reason_str = "smart data";
  6434. break;
  6435. case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED:
  6436. reason_str = "unsupported device discovered";
  6437. break;
  6438. case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET:
  6439. reason_str = "internal device reset";
  6440. break;
  6441. case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL:
  6442. reason_str = "internal task abort";
  6443. break;
  6444. case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  6445. reason_str = "internal task abort set";
  6446. break;
  6447. case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  6448. reason_str = "internal clear task set";
  6449. break;
  6450. case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL:
  6451. reason_str = "internal query task";
  6452. break;
  6453. case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE:
  6454. reason_str = "device init failure";
  6455. break;
  6456. case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  6457. reason_str = "internal device reset complete";
  6458. break;
  6459. case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  6460. reason_str = "internal task abort complete";
  6461. break;
  6462. case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION:
  6463. reason_str = "internal async notification";
  6464. break;
  6465. case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
  6466. reason_str = "pcie hot reset failed";
  6467. break;
  6468. default:
  6469. reason_str = "unknown reason";
  6470. break;
  6471. }
  6472. pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n"
  6473. "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
  6474. ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
  6475. (unsigned long long)le64_to_cpu(event_data->WWID),
  6476. le16_to_cpu(event_data->TaskTag));
  6477. if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA)
  6478. pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  6479. event_data->ASC, event_data->ASCQ);
  6480. pr_info("\n");
  6481. }
  6482. /**
  6483. * _scsih_pcie_device_status_change_event - handle device status
  6484. * change
  6485. * @ioc: per adapter object
  6486. * @fw_event: The fw_event_work object
  6487. * Context: user.
  6488. */
  6489. static void
  6490. _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
  6491. struct fw_event_work *fw_event)
  6492. {
  6493. struct MPT3SAS_TARGET *target_priv_data;
  6494. struct _pcie_device *pcie_device;
  6495. u64 wwid;
  6496. unsigned long flags;
  6497. Mpi26EventDataPCIeDeviceStatusChange_t *event_data =
  6498. (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data;
  6499. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  6500. _scsih_pcie_device_status_change_event_debug(ioc,
  6501. event_data);
  6502. if (event_data->ReasonCode !=
  6503. MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET &&
  6504. event_data->ReasonCode !=
  6505. MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
  6506. return;
  6507. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  6508. wwid = le64_to_cpu(event_data->WWID);
  6509. pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
  6510. if (!pcie_device || !pcie_device->starget)
  6511. goto out;
  6512. target_priv_data = pcie_device->starget->hostdata;
  6513. if (!target_priv_data)
  6514. goto out;
  6515. if (event_data->ReasonCode ==
  6516. MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET)
  6517. target_priv_data->tm_busy = 1;
  6518. else
  6519. target_priv_data->tm_busy = 0;
  6520. out:
  6521. if (pcie_device)
  6522. pcie_device_put(pcie_device);
  6523. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  6524. }
  6525. /**
  6526. * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
  6527. * event
  6528. * @ioc: per adapter object
  6529. * @event_data: event data payload
  6530. * Context: user.
  6531. */
  6532. static void
  6533. _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  6534. Mpi2EventDataSasEnclDevStatusChange_t *event_data)
  6535. {
  6536. char *reason_str = NULL;
  6537. switch (event_data->ReasonCode) {
  6538. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  6539. reason_str = "enclosure add";
  6540. break;
  6541. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  6542. reason_str = "enclosure remove";
  6543. break;
  6544. default:
  6545. reason_str = "unknown reason";
  6546. break;
  6547. }
  6548. pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
  6549. "\thandle(0x%04x), enclosure logical id(0x%016llx)"
  6550. " number slots(%d)\n", ioc->name, reason_str,
  6551. le16_to_cpu(event_data->EnclosureHandle),
  6552. (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
  6553. le16_to_cpu(event_data->StartSlot));
  6554. }
  6555. /**
  6556. * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
  6557. * @ioc: per adapter object
  6558. * @fw_event: The fw_event_work object
  6559. * Context: user.
  6560. */
  6561. static void
  6562. _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
  6563. struct fw_event_work *fw_event)
  6564. {
  6565. Mpi2ConfigReply_t mpi_reply;
  6566. struct _enclosure_node *enclosure_dev = NULL;
  6567. Mpi2EventDataSasEnclDevStatusChange_t *event_data =
  6568. (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data;
  6569. int rc;
  6570. u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle);
  6571. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  6572. _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
  6573. (Mpi2EventDataSasEnclDevStatusChange_t *)
  6574. fw_event->event_data);
  6575. if (ioc->shost_recovery)
  6576. return;
  6577. if (enclosure_handle)
  6578. enclosure_dev =
  6579. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  6580. enclosure_handle);
  6581. switch (event_data->ReasonCode) {
  6582. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  6583. if (!enclosure_dev) {
  6584. enclosure_dev =
  6585. kzalloc(sizeof(struct _enclosure_node),
  6586. GFP_KERNEL);
  6587. if (!enclosure_dev) {
  6588. pr_info(MPT3SAS_FMT
  6589. "failure at %s:%d/%s()!\n", ioc->name,
  6590. __FILE__, __LINE__, __func__);
  6591. return;
  6592. }
  6593. rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  6594. &enclosure_dev->pg0,
  6595. MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  6596. enclosure_handle);
  6597. if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
  6598. MPI2_IOCSTATUS_MASK)) {
  6599. kfree(enclosure_dev);
  6600. return;
  6601. }
  6602. list_add_tail(&enclosure_dev->list,
  6603. &ioc->enclosure_list);
  6604. }
  6605. break;
  6606. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  6607. if (enclosure_dev) {
  6608. list_del(&enclosure_dev->list);
  6609. kfree(enclosure_dev);
  6610. }
  6611. break;
  6612. default:
  6613. break;
  6614. }
  6615. }
  6616. /**
  6617. * _scsih_sas_broadcast_primitive_event - handle broadcast events
  6618. * @ioc: per adapter object
  6619. * @fw_event: The fw_event_work object
  6620. * Context: user.
  6621. */
  6622. static void
  6623. _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
  6624. struct fw_event_work *fw_event)
  6625. {
  6626. struct scsi_cmnd *scmd;
  6627. struct scsi_device *sdev;
  6628. struct scsiio_tracker *st;
  6629. u16 smid, handle;
  6630. u32 lun;
  6631. struct MPT3SAS_DEVICE *sas_device_priv_data;
  6632. u32 termination_count;
  6633. u32 query_count;
  6634. Mpi2SCSITaskManagementReply_t *mpi_reply;
  6635. Mpi2EventDataSasBroadcastPrimitive_t *event_data =
  6636. (Mpi2EventDataSasBroadcastPrimitive_t *)
  6637. fw_event->event_data;
  6638. u16 ioc_status;
  6639. unsigned long flags;
  6640. int r;
  6641. u8 max_retries = 0;
  6642. u8 task_abort_retries;
  6643. mutex_lock(&ioc->tm_cmds.mutex);
  6644. pr_info(MPT3SAS_FMT
  6645. "%s: enter: phy number(%d), width(%d)\n",
  6646. ioc->name, __func__, event_data->PhyNum,
  6647. event_data->PortWidth);
  6648. _scsih_block_io_all_device(ioc);
  6649. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6650. mpi_reply = ioc->tm_cmds.reply;
  6651. broadcast_aen_retry:
  6652. /* sanity checks for retrying this loop */
  6653. if (max_retries++ == 5) {
  6654. dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
  6655. ioc->name, __func__));
  6656. goto out;
  6657. } else if (max_retries > 1)
  6658. dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
  6659. ioc->name, __func__, max_retries - 1));
  6660. termination_count = 0;
  6661. query_count = 0;
  6662. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  6663. if (ioc->shost_recovery)
  6664. goto out;
  6665. scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
  6666. if (!scmd)
  6667. continue;
  6668. st = scsi_cmd_priv(scmd);
  6669. sdev = scmd->device;
  6670. sas_device_priv_data = sdev->hostdata;
  6671. if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
  6672. continue;
  6673. /* skip hidden raid components */
  6674. if (sas_device_priv_data->sas_target->flags &
  6675. MPT_TARGET_FLAGS_RAID_COMPONENT)
  6676. continue;
  6677. /* skip volumes */
  6678. if (sas_device_priv_data->sas_target->flags &
  6679. MPT_TARGET_FLAGS_VOLUME)
  6680. continue;
  6681. /* skip PCIe devices */
  6682. if (sas_device_priv_data->sas_target->flags &
  6683. MPT_TARGET_FLAGS_PCIE_DEVICE)
  6684. continue;
  6685. handle = sas_device_priv_data->sas_target->handle;
  6686. lun = sas_device_priv_data->lun;
  6687. query_count++;
  6688. if (ioc->shost_recovery)
  6689. goto out;
  6690. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  6691. r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
  6692. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
  6693. st->msix_io, 30, 0);
  6694. if (r == FAILED) {
  6695. sdev_printk(KERN_WARNING, sdev,
  6696. "mpt3sas_scsih_issue_tm: FAILED when sending "
  6697. "QUERY_TASK: scmd(%p)\n", scmd);
  6698. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6699. goto broadcast_aen_retry;
  6700. }
  6701. ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
  6702. & MPI2_IOCSTATUS_MASK;
  6703. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  6704. sdev_printk(KERN_WARNING, sdev,
  6705. "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
  6706. ioc_status, scmd);
  6707. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6708. goto broadcast_aen_retry;
  6709. }
  6710. /* see if IO is still owned by IOC and target */
  6711. if (mpi_reply->ResponseCode ==
  6712. MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
  6713. mpi_reply->ResponseCode ==
  6714. MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
  6715. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6716. continue;
  6717. }
  6718. task_abort_retries = 0;
  6719. tm_retry:
  6720. if (task_abort_retries++ == 60) {
  6721. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6722. "%s: ABORT_TASK: giving up\n", ioc->name,
  6723. __func__));
  6724. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6725. goto broadcast_aen_retry;
  6726. }
  6727. if (ioc->shost_recovery)
  6728. goto out_no_lock;
  6729. r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
  6730. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
  6731. st->msix_io, 30, 0);
  6732. if (r == FAILED || st->cb_idx != 0xFF) {
  6733. sdev_printk(KERN_WARNING, sdev,
  6734. "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
  6735. "scmd(%p)\n", scmd);
  6736. goto tm_retry;
  6737. }
  6738. if (task_abort_retries > 1)
  6739. sdev_printk(KERN_WARNING, sdev,
  6740. "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
  6741. " scmd(%p)\n",
  6742. task_abort_retries - 1, scmd);
  6743. termination_count += le32_to_cpu(mpi_reply->TerminationCount);
  6744. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  6745. }
  6746. if (ioc->broadcast_aen_pending) {
  6747. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6748. "%s: loop back due to pending AEN\n",
  6749. ioc->name, __func__));
  6750. ioc->broadcast_aen_pending = 0;
  6751. goto broadcast_aen_retry;
  6752. }
  6753. out:
  6754. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  6755. out_no_lock:
  6756. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6757. "%s - exit, query_count = %d termination_count = %d\n",
  6758. ioc->name, __func__, query_count, termination_count));
  6759. ioc->broadcast_aen_busy = 0;
  6760. if (!ioc->shost_recovery)
  6761. _scsih_ublock_io_all_device(ioc);
  6762. mutex_unlock(&ioc->tm_cmds.mutex);
  6763. }
  6764. /**
  6765. * _scsih_sas_discovery_event - handle discovery events
  6766. * @ioc: per adapter object
  6767. * @fw_event: The fw_event_work object
  6768. * Context: user.
  6769. */
  6770. static void
  6771. _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
  6772. struct fw_event_work *fw_event)
  6773. {
  6774. Mpi2EventDataSasDiscovery_t *event_data =
  6775. (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
  6776. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
  6777. pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
  6778. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  6779. "start" : "stop");
  6780. if (event_data->DiscoveryStatus)
  6781. pr_info("discovery_status(0x%08x)",
  6782. le32_to_cpu(event_data->DiscoveryStatus));
  6783. pr_info("\n");
  6784. }
  6785. if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
  6786. !ioc->sas_hba.num_phys) {
  6787. if (disable_discovery > 0 && ioc->shost_recovery) {
  6788. /* Wait for the reset to complete */
  6789. while (ioc->shost_recovery)
  6790. ssleep(1);
  6791. }
  6792. _scsih_sas_host_add(ioc);
  6793. }
  6794. }
  6795. /**
  6796. * _scsih_sas_device_discovery_error_event - display SAS device discovery error
  6797. * events
  6798. * @ioc: per adapter object
  6799. * @fw_event: The fw_event_work object
  6800. * Context: user.
  6801. */
  6802. static void
  6803. _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc,
  6804. struct fw_event_work *fw_event)
  6805. {
  6806. Mpi25EventDataSasDeviceDiscoveryError_t *event_data =
  6807. (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data;
  6808. switch (event_data->ReasonCode) {
  6809. case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
  6810. pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
  6811. "(handle:0x%04x, sas_address:0x%016llx,"
  6812. "physical_port:0x%02x) has failed",
  6813. ioc->name, le16_to_cpu(event_data->DevHandle),
  6814. (unsigned long long)le64_to_cpu(event_data->SASAddress),
  6815. event_data->PhysicalPort);
  6816. break;
  6817. case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
  6818. pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
  6819. "(handle:0x%04x, sas_address:0x%016llx,"
  6820. "physical_port:0x%02x) has timed out",
  6821. ioc->name, le16_to_cpu(event_data->DevHandle),
  6822. (unsigned long long)le64_to_cpu(event_data->SASAddress),
  6823. event_data->PhysicalPort);
  6824. break;
  6825. default:
  6826. break;
  6827. }
  6828. }
  6829. /**
  6830. * _scsih_pcie_enumeration_event - handle enumeration events
  6831. * @ioc: per adapter object
  6832. * @fw_event: The fw_event_work object
  6833. * Context: user.
  6834. */
  6835. static void
  6836. _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc,
  6837. struct fw_event_work *fw_event)
  6838. {
  6839. Mpi26EventDataPCIeEnumeration_t *event_data =
  6840. (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data;
  6841. if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK))
  6842. return;
  6843. pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x",
  6844. ioc->name,
  6845. (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ?
  6846. "started" : "completed",
  6847. event_data->Flags);
  6848. if (event_data->EnumerationStatus)
  6849. pr_cont("enumeration_status(0x%08x)",
  6850. le32_to_cpu(event_data->EnumerationStatus));
  6851. pr_cont("\n");
  6852. }
  6853. /**
  6854. * _scsih_ir_fastpath - turn on fastpath for IR physdisk
  6855. * @ioc: per adapter object
  6856. * @handle: device handle for physical disk
  6857. * @phys_disk_num: physical disk number
  6858. *
  6859. * Return: 0 for success, else failure.
  6860. */
  6861. static int
  6862. _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
  6863. {
  6864. Mpi2RaidActionRequest_t *mpi_request;
  6865. Mpi2RaidActionReply_t *mpi_reply;
  6866. u16 smid;
  6867. u8 issue_reset = 0;
  6868. int rc = 0;
  6869. u16 ioc_status;
  6870. u32 log_info;
  6871. if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
  6872. return rc;
  6873. mutex_lock(&ioc->scsih_cmds.mutex);
  6874. if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
  6875. pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
  6876. ioc->name, __func__);
  6877. rc = -EAGAIN;
  6878. goto out;
  6879. }
  6880. ioc->scsih_cmds.status = MPT3_CMD_PENDING;
  6881. smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
  6882. if (!smid) {
  6883. pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
  6884. ioc->name, __func__);
  6885. ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
  6886. rc = -EAGAIN;
  6887. goto out;
  6888. }
  6889. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  6890. ioc->scsih_cmds.smid = smid;
  6891. memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
  6892. mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
  6893. mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
  6894. mpi_request->PhysDiskNum = phys_disk_num;
  6895. dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
  6896. "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
  6897. handle, phys_disk_num));
  6898. init_completion(&ioc->scsih_cmds.done);
  6899. mpt3sas_base_put_smid_default(ioc, smid);
  6900. wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
  6901. if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
  6902. issue_reset =
  6903. mpt3sas_base_check_cmd_timeout(ioc,
  6904. ioc->scsih_cmds.status, mpi_request,
  6905. sizeof(Mpi2RaidActionRequest_t)/4);
  6906. rc = -EFAULT;
  6907. goto out;
  6908. }
  6909. if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
  6910. mpi_reply = ioc->scsih_cmds.reply;
  6911. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  6912. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  6913. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  6914. else
  6915. log_info = 0;
  6916. ioc_status &= MPI2_IOCSTATUS_MASK;
  6917. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  6918. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6919. "IR RAID_ACTION: failed: ioc_status(0x%04x), "
  6920. "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
  6921. log_info));
  6922. rc = -EFAULT;
  6923. } else
  6924. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  6925. "IR RAID_ACTION: completed successfully\n",
  6926. ioc->name));
  6927. }
  6928. out:
  6929. ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
  6930. mutex_unlock(&ioc->scsih_cmds.mutex);
  6931. if (issue_reset)
  6932. mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  6933. return rc;
  6934. }
  6935. /**
  6936. * _scsih_reprobe_lun - reprobing lun
  6937. * @sdev: scsi device struct
  6938. * @no_uld_attach: sdev->no_uld_attach flag setting
  6939. *
  6940. **/
  6941. static void
  6942. _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
  6943. {
  6944. sdev->no_uld_attach = no_uld_attach ? 1 : 0;
  6945. sdev_printk(KERN_INFO, sdev, "%s raid component\n",
  6946. sdev->no_uld_attach ? "hiding" : "exposing");
  6947. WARN_ON(scsi_device_reprobe(sdev));
  6948. }
  6949. /**
  6950. * _scsih_sas_volume_add - add new volume
  6951. * @ioc: per adapter object
  6952. * @element: IR config element data
  6953. * Context: user.
  6954. */
  6955. static void
  6956. _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
  6957. Mpi2EventIrConfigElement_t *element)
  6958. {
  6959. struct _raid_device *raid_device;
  6960. unsigned long flags;
  6961. u64 wwid;
  6962. u16 handle = le16_to_cpu(element->VolDevHandle);
  6963. int rc;
  6964. mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
  6965. if (!wwid) {
  6966. pr_err(MPT3SAS_FMT
  6967. "failure at %s:%d/%s()!\n", ioc->name,
  6968. __FILE__, __LINE__, __func__);
  6969. return;
  6970. }
  6971. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  6972. raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
  6973. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  6974. if (raid_device)
  6975. return;
  6976. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  6977. if (!raid_device) {
  6978. pr_err(MPT3SAS_FMT
  6979. "failure at %s:%d/%s()!\n", ioc->name,
  6980. __FILE__, __LINE__, __func__);
  6981. return;
  6982. }
  6983. raid_device->id = ioc->sas_id++;
  6984. raid_device->channel = RAID_CHANNEL;
  6985. raid_device->handle = handle;
  6986. raid_device->wwid = wwid;
  6987. _scsih_raid_device_add(ioc, raid_device);
  6988. if (!ioc->wait_for_discovery_to_complete) {
  6989. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  6990. raid_device->id, 0);
  6991. if (rc)
  6992. _scsih_raid_device_remove(ioc, raid_device);
  6993. } else {
  6994. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  6995. _scsih_determine_boot_device(ioc, raid_device, 1);
  6996. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  6997. }
  6998. }
  6999. /**
  7000. * _scsih_sas_volume_delete - delete volume
  7001. * @ioc: per adapter object
  7002. * @handle: volume device handle
  7003. * Context: user.
  7004. */
  7005. static void
  7006. _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
  7007. {
  7008. struct _raid_device *raid_device;
  7009. unsigned long flags;
  7010. struct MPT3SAS_TARGET *sas_target_priv_data;
  7011. struct scsi_target *starget = NULL;
  7012. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  7013. raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
  7014. if (raid_device) {
  7015. if (raid_device->starget) {
  7016. starget = raid_device->starget;
  7017. sas_target_priv_data = starget->hostdata;
  7018. sas_target_priv_data->deleted = 1;
  7019. }
  7020. pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
  7021. ioc->name, raid_device->handle,
  7022. (unsigned long long) raid_device->wwid);
  7023. list_del(&raid_device->list);
  7024. kfree(raid_device);
  7025. }
  7026. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7027. if (starget)
  7028. scsi_remove_target(&starget->dev);
  7029. }
  7030. /**
  7031. * _scsih_sas_pd_expose - expose pd component to /dev/sdX
  7032. * @ioc: per adapter object
  7033. * @element: IR config element data
  7034. * Context: user.
  7035. */
  7036. static void
  7037. _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
  7038. Mpi2EventIrConfigElement_t *element)
  7039. {
  7040. struct _sas_device *sas_device;
  7041. struct scsi_target *starget = NULL;
  7042. struct MPT3SAS_TARGET *sas_target_priv_data;
  7043. unsigned long flags;
  7044. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  7045. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  7046. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  7047. if (sas_device) {
  7048. sas_device->volume_handle = 0;
  7049. sas_device->volume_wwid = 0;
  7050. clear_bit(handle, ioc->pd_handles);
  7051. if (sas_device->starget && sas_device->starget->hostdata) {
  7052. starget = sas_device->starget;
  7053. sas_target_priv_data = starget->hostdata;
  7054. sas_target_priv_data->flags &=
  7055. ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  7056. }
  7057. }
  7058. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  7059. if (!sas_device)
  7060. return;
  7061. /* exposing raid component */
  7062. if (starget)
  7063. starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
  7064. sas_device_put(sas_device);
  7065. }
  7066. /**
  7067. * _scsih_sas_pd_hide - hide pd component from /dev/sdX
  7068. * @ioc: per adapter object
  7069. * @element: IR config element data
  7070. * Context: user.
  7071. */
  7072. static void
  7073. _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
  7074. Mpi2EventIrConfigElement_t *element)
  7075. {
  7076. struct _sas_device *sas_device;
  7077. struct scsi_target *starget = NULL;
  7078. struct MPT3SAS_TARGET *sas_target_priv_data;
  7079. unsigned long flags;
  7080. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  7081. u16 volume_handle = 0;
  7082. u64 volume_wwid = 0;
  7083. mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
  7084. if (volume_handle)
  7085. mpt3sas_config_get_volume_wwid(ioc, volume_handle,
  7086. &volume_wwid);
  7087. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  7088. sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
  7089. if (sas_device) {
  7090. set_bit(handle, ioc->pd_handles);
  7091. if (sas_device->starget && sas_device->starget->hostdata) {
  7092. starget = sas_device->starget;
  7093. sas_target_priv_data = starget->hostdata;
  7094. sas_target_priv_data->flags |=
  7095. MPT_TARGET_FLAGS_RAID_COMPONENT;
  7096. sas_device->volume_handle = volume_handle;
  7097. sas_device->volume_wwid = volume_wwid;
  7098. }
  7099. }
  7100. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  7101. if (!sas_device)
  7102. return;
  7103. /* hiding raid component */
  7104. _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
  7105. if (starget)
  7106. starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
  7107. sas_device_put(sas_device);
  7108. }
  7109. /**
  7110. * _scsih_sas_pd_delete - delete pd component
  7111. * @ioc: per adapter object
  7112. * @element: IR config element data
  7113. * Context: user.
  7114. */
  7115. static void
  7116. _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
  7117. Mpi2EventIrConfigElement_t *element)
  7118. {
  7119. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  7120. _scsih_device_remove_by_handle(ioc, handle);
  7121. }
  7122. /**
  7123. * _scsih_sas_pd_add - remove pd component
  7124. * @ioc: per adapter object
  7125. * @element: IR config element data
  7126. * Context: user.
  7127. */
  7128. static void
  7129. _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
  7130. Mpi2EventIrConfigElement_t *element)
  7131. {
  7132. struct _sas_device *sas_device;
  7133. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  7134. Mpi2ConfigReply_t mpi_reply;
  7135. Mpi2SasDevicePage0_t sas_device_pg0;
  7136. u32 ioc_status;
  7137. u64 sas_address;
  7138. u16 parent_handle;
  7139. set_bit(handle, ioc->pd_handles);
  7140. sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
  7141. if (sas_device) {
  7142. _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
  7143. sas_device_put(sas_device);
  7144. return;
  7145. }
  7146. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  7147. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  7148. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  7149. ioc->name, __FILE__, __LINE__, __func__);
  7150. return;
  7151. }
  7152. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7153. MPI2_IOCSTATUS_MASK;
  7154. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  7155. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  7156. ioc->name, __FILE__, __LINE__, __func__);
  7157. return;
  7158. }
  7159. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  7160. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  7161. mpt3sas_transport_update_links(ioc, sas_address, handle,
  7162. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  7163. _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
  7164. _scsih_add_device(ioc, handle, 0, 1);
  7165. }
  7166. /**
  7167. * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
  7168. * @ioc: per adapter object
  7169. * @event_data: event data payload
  7170. * Context: user.
  7171. */
  7172. static void
  7173. _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
  7174. Mpi2EventDataIrConfigChangeList_t *event_data)
  7175. {
  7176. Mpi2EventIrConfigElement_t *element;
  7177. u8 element_type;
  7178. int i;
  7179. char *reason_str = NULL, *element_str = NULL;
  7180. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  7181. pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
  7182. ioc->name, (le32_to_cpu(event_data->Flags) &
  7183. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
  7184. "foreign" : "native", event_data->NumElements);
  7185. for (i = 0; i < event_data->NumElements; i++, element++) {
  7186. switch (element->ReasonCode) {
  7187. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  7188. reason_str = "add";
  7189. break;
  7190. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  7191. reason_str = "remove";
  7192. break;
  7193. case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
  7194. reason_str = "no change";
  7195. break;
  7196. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  7197. reason_str = "hide";
  7198. break;
  7199. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  7200. reason_str = "unhide";
  7201. break;
  7202. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  7203. reason_str = "volume_created";
  7204. break;
  7205. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  7206. reason_str = "volume_deleted";
  7207. break;
  7208. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  7209. reason_str = "pd_created";
  7210. break;
  7211. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  7212. reason_str = "pd_deleted";
  7213. break;
  7214. default:
  7215. reason_str = "unknown reason";
  7216. break;
  7217. }
  7218. element_type = le16_to_cpu(element->ElementFlags) &
  7219. MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
  7220. switch (element_type) {
  7221. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
  7222. element_str = "volume";
  7223. break;
  7224. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
  7225. element_str = "phys disk";
  7226. break;
  7227. case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
  7228. element_str = "hot spare";
  7229. break;
  7230. default:
  7231. element_str = "unknown element";
  7232. break;
  7233. }
  7234. pr_info("\t(%s:%s), vol handle(0x%04x), " \
  7235. "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
  7236. reason_str, le16_to_cpu(element->VolDevHandle),
  7237. le16_to_cpu(element->PhysDiskDevHandle),
  7238. element->PhysDiskNum);
  7239. }
  7240. }
  7241. /**
  7242. * _scsih_sas_ir_config_change_event - handle ir configuration change events
  7243. * @ioc: per adapter object
  7244. * @fw_event: The fw_event_work object
  7245. * Context: user.
  7246. */
  7247. static void
  7248. _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
  7249. struct fw_event_work *fw_event)
  7250. {
  7251. Mpi2EventIrConfigElement_t *element;
  7252. int i;
  7253. u8 foreign_config;
  7254. Mpi2EventDataIrConfigChangeList_t *event_data =
  7255. (Mpi2EventDataIrConfigChangeList_t *)
  7256. fw_event->event_data;
  7257. if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
  7258. (!ioc->hide_ir_msg))
  7259. _scsih_sas_ir_config_change_event_debug(ioc, event_data);
  7260. foreign_config = (le32_to_cpu(event_data->Flags) &
  7261. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
  7262. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  7263. if (ioc->shost_recovery &&
  7264. ioc->hba_mpi_version_belonged != MPI2_VERSION) {
  7265. for (i = 0; i < event_data->NumElements; i++, element++) {
  7266. if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
  7267. _scsih_ir_fastpath(ioc,
  7268. le16_to_cpu(element->PhysDiskDevHandle),
  7269. element->PhysDiskNum);
  7270. }
  7271. return;
  7272. }
  7273. for (i = 0; i < event_data->NumElements; i++, element++) {
  7274. switch (element->ReasonCode) {
  7275. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  7276. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  7277. if (!foreign_config)
  7278. _scsih_sas_volume_add(ioc, element);
  7279. break;
  7280. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  7281. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  7282. if (!foreign_config)
  7283. _scsih_sas_volume_delete(ioc,
  7284. le16_to_cpu(element->VolDevHandle));
  7285. break;
  7286. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  7287. if (!ioc->is_warpdrive)
  7288. _scsih_sas_pd_hide(ioc, element);
  7289. break;
  7290. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  7291. if (!ioc->is_warpdrive)
  7292. _scsih_sas_pd_expose(ioc, element);
  7293. break;
  7294. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  7295. if (!ioc->is_warpdrive)
  7296. _scsih_sas_pd_add(ioc, element);
  7297. break;
  7298. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  7299. if (!ioc->is_warpdrive)
  7300. _scsih_sas_pd_delete(ioc, element);
  7301. break;
  7302. }
  7303. }
  7304. }
  7305. /**
  7306. * _scsih_sas_ir_volume_event - IR volume event
  7307. * @ioc: per adapter object
  7308. * @fw_event: The fw_event_work object
  7309. * Context: user.
  7310. */
  7311. static void
  7312. _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
  7313. struct fw_event_work *fw_event)
  7314. {
  7315. u64 wwid;
  7316. unsigned long flags;
  7317. struct _raid_device *raid_device;
  7318. u16 handle;
  7319. u32 state;
  7320. int rc;
  7321. Mpi2EventDataIrVolume_t *event_data =
  7322. (Mpi2EventDataIrVolume_t *) fw_event->event_data;
  7323. if (ioc->shost_recovery)
  7324. return;
  7325. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  7326. return;
  7327. handle = le16_to_cpu(event_data->VolDevHandle);
  7328. state = le32_to_cpu(event_data->NewValue);
  7329. if (!ioc->hide_ir_msg)
  7330. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  7331. "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
  7332. ioc->name, __func__, handle,
  7333. le32_to_cpu(event_data->PreviousValue), state));
  7334. switch (state) {
  7335. case MPI2_RAID_VOL_STATE_MISSING:
  7336. case MPI2_RAID_VOL_STATE_FAILED:
  7337. _scsih_sas_volume_delete(ioc, handle);
  7338. break;
  7339. case MPI2_RAID_VOL_STATE_ONLINE:
  7340. case MPI2_RAID_VOL_STATE_DEGRADED:
  7341. case MPI2_RAID_VOL_STATE_OPTIMAL:
  7342. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  7343. raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
  7344. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7345. if (raid_device)
  7346. break;
  7347. mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
  7348. if (!wwid) {
  7349. pr_err(MPT3SAS_FMT
  7350. "failure at %s:%d/%s()!\n", ioc->name,
  7351. __FILE__, __LINE__, __func__);
  7352. break;
  7353. }
  7354. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  7355. if (!raid_device) {
  7356. pr_err(MPT3SAS_FMT
  7357. "failure at %s:%d/%s()!\n", ioc->name,
  7358. __FILE__, __LINE__, __func__);
  7359. break;
  7360. }
  7361. raid_device->id = ioc->sas_id++;
  7362. raid_device->channel = RAID_CHANNEL;
  7363. raid_device->handle = handle;
  7364. raid_device->wwid = wwid;
  7365. _scsih_raid_device_add(ioc, raid_device);
  7366. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  7367. raid_device->id, 0);
  7368. if (rc)
  7369. _scsih_raid_device_remove(ioc, raid_device);
  7370. break;
  7371. case MPI2_RAID_VOL_STATE_INITIALIZING:
  7372. default:
  7373. break;
  7374. }
  7375. }
  7376. /**
  7377. * _scsih_sas_ir_physical_disk_event - PD event
  7378. * @ioc: per adapter object
  7379. * @fw_event: The fw_event_work object
  7380. * Context: user.
  7381. */
  7382. static void
  7383. _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
  7384. struct fw_event_work *fw_event)
  7385. {
  7386. u16 handle, parent_handle;
  7387. u32 state;
  7388. struct _sas_device *sas_device;
  7389. Mpi2ConfigReply_t mpi_reply;
  7390. Mpi2SasDevicePage0_t sas_device_pg0;
  7391. u32 ioc_status;
  7392. Mpi2EventDataIrPhysicalDisk_t *event_data =
  7393. (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
  7394. u64 sas_address;
  7395. if (ioc->shost_recovery)
  7396. return;
  7397. if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
  7398. return;
  7399. handle = le16_to_cpu(event_data->PhysDiskDevHandle);
  7400. state = le32_to_cpu(event_data->NewValue);
  7401. if (!ioc->hide_ir_msg)
  7402. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  7403. "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
  7404. ioc->name, __func__, handle,
  7405. le32_to_cpu(event_data->PreviousValue), state));
  7406. switch (state) {
  7407. case MPI2_RAID_PD_STATE_ONLINE:
  7408. case MPI2_RAID_PD_STATE_DEGRADED:
  7409. case MPI2_RAID_PD_STATE_REBUILDING:
  7410. case MPI2_RAID_PD_STATE_OPTIMAL:
  7411. case MPI2_RAID_PD_STATE_HOT_SPARE:
  7412. if (!ioc->is_warpdrive)
  7413. set_bit(handle, ioc->pd_handles);
  7414. sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
  7415. if (sas_device) {
  7416. sas_device_put(sas_device);
  7417. return;
  7418. }
  7419. if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  7420. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  7421. handle))) {
  7422. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  7423. ioc->name, __FILE__, __LINE__, __func__);
  7424. return;
  7425. }
  7426. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7427. MPI2_IOCSTATUS_MASK;
  7428. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  7429. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  7430. ioc->name, __FILE__, __LINE__, __func__);
  7431. return;
  7432. }
  7433. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  7434. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  7435. mpt3sas_transport_update_links(ioc, sas_address, handle,
  7436. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  7437. _scsih_add_device(ioc, handle, 0, 1);
  7438. break;
  7439. case MPI2_RAID_PD_STATE_OFFLINE:
  7440. case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
  7441. case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
  7442. default:
  7443. break;
  7444. }
  7445. }
  7446. /**
  7447. * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
  7448. * @ioc: per adapter object
  7449. * @event_data: event data payload
  7450. * Context: user.
  7451. */
  7452. static void
  7453. _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
  7454. Mpi2EventDataIrOperationStatus_t *event_data)
  7455. {
  7456. char *reason_str = NULL;
  7457. switch (event_data->RAIDOperation) {
  7458. case MPI2_EVENT_IR_RAIDOP_RESYNC:
  7459. reason_str = "resync";
  7460. break;
  7461. case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
  7462. reason_str = "online capacity expansion";
  7463. break;
  7464. case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
  7465. reason_str = "consistency check";
  7466. break;
  7467. case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
  7468. reason_str = "background init";
  7469. break;
  7470. case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
  7471. reason_str = "make data consistent";
  7472. break;
  7473. }
  7474. if (!reason_str)
  7475. return;
  7476. pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
  7477. "\thandle(0x%04x), percent complete(%d)\n",
  7478. ioc->name, reason_str,
  7479. le16_to_cpu(event_data->VolDevHandle),
  7480. event_data->PercentComplete);
  7481. }
  7482. /**
  7483. * _scsih_sas_ir_operation_status_event - handle RAID operation events
  7484. * @ioc: per adapter object
  7485. * @fw_event: The fw_event_work object
  7486. * Context: user.
  7487. */
  7488. static void
  7489. _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
  7490. struct fw_event_work *fw_event)
  7491. {
  7492. Mpi2EventDataIrOperationStatus_t *event_data =
  7493. (Mpi2EventDataIrOperationStatus_t *)
  7494. fw_event->event_data;
  7495. static struct _raid_device *raid_device;
  7496. unsigned long flags;
  7497. u16 handle;
  7498. if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
  7499. (!ioc->hide_ir_msg))
  7500. _scsih_sas_ir_operation_status_event_debug(ioc,
  7501. event_data);
  7502. /* code added for raid transport support */
  7503. if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
  7504. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  7505. handle = le16_to_cpu(event_data->VolDevHandle);
  7506. raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
  7507. if (raid_device)
  7508. raid_device->percent_complete =
  7509. event_data->PercentComplete;
  7510. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7511. }
  7512. }
  7513. /**
  7514. * _scsih_prep_device_scan - initialize parameters prior to device scan
  7515. * @ioc: per adapter object
  7516. *
  7517. * Set the deleted flag prior to device scan. If the device is found during
  7518. * the scan, then we clear the deleted flag.
  7519. */
  7520. static void
  7521. _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
  7522. {
  7523. struct MPT3SAS_DEVICE *sas_device_priv_data;
  7524. struct scsi_device *sdev;
  7525. shost_for_each_device(sdev, ioc->shost) {
  7526. sas_device_priv_data = sdev->hostdata;
  7527. if (sas_device_priv_data && sas_device_priv_data->sas_target)
  7528. sas_device_priv_data->sas_target->deleted = 1;
  7529. }
  7530. }
  7531. /**
  7532. * _scsih_mark_responding_sas_device - mark a sas_devices as responding
  7533. * @ioc: per adapter object
  7534. * @sas_device_pg0: SAS Device page 0
  7535. *
  7536. * After host reset, find out whether devices are still responding.
  7537. * Used in _scsih_remove_unresponsive_sas_devices.
  7538. */
  7539. static void
  7540. _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
  7541. Mpi2SasDevicePage0_t *sas_device_pg0)
  7542. {
  7543. struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
  7544. struct scsi_target *starget;
  7545. struct _sas_device *sas_device = NULL;
  7546. struct _enclosure_node *enclosure_dev = NULL;
  7547. unsigned long flags;
  7548. if (sas_device_pg0->EnclosureHandle) {
  7549. enclosure_dev =
  7550. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  7551. le16_to_cpu(sas_device_pg0->EnclosureHandle));
  7552. if (enclosure_dev == NULL)
  7553. pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
  7554. "doesn't match with enclosure device!\n",
  7555. ioc->name, sas_device_pg0->EnclosureHandle);
  7556. }
  7557. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  7558. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  7559. if ((sas_device->sas_address == le64_to_cpu(
  7560. sas_device_pg0->SASAddress)) && (sas_device->slot ==
  7561. le16_to_cpu(sas_device_pg0->Slot))) {
  7562. sas_device->responding = 1;
  7563. starget = sas_device->starget;
  7564. if (starget && starget->hostdata) {
  7565. sas_target_priv_data = starget->hostdata;
  7566. sas_target_priv_data->tm_busy = 0;
  7567. sas_target_priv_data->deleted = 0;
  7568. } else
  7569. sas_target_priv_data = NULL;
  7570. if (starget) {
  7571. starget_printk(KERN_INFO, starget,
  7572. "handle(0x%04x), sas_addr(0x%016llx)\n",
  7573. le16_to_cpu(sas_device_pg0->DevHandle),
  7574. (unsigned long long)
  7575. sas_device->sas_address);
  7576. if (sas_device->enclosure_handle != 0)
  7577. starget_printk(KERN_INFO, starget,
  7578. "enclosure logical id(0x%016llx),"
  7579. " slot(%d)\n",
  7580. (unsigned long long)
  7581. sas_device->enclosure_logical_id,
  7582. sas_device->slot);
  7583. }
  7584. if (le16_to_cpu(sas_device_pg0->Flags) &
  7585. MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
  7586. sas_device->enclosure_level =
  7587. sas_device_pg0->EnclosureLevel;
  7588. memcpy(&sas_device->connector_name[0],
  7589. &sas_device_pg0->ConnectorName[0], 4);
  7590. } else {
  7591. sas_device->enclosure_level = 0;
  7592. sas_device->connector_name[0] = '\0';
  7593. }
  7594. sas_device->enclosure_handle =
  7595. le16_to_cpu(sas_device_pg0->EnclosureHandle);
  7596. sas_device->is_chassis_slot_valid = 0;
  7597. if (enclosure_dev) {
  7598. sas_device->enclosure_logical_id = le64_to_cpu(
  7599. enclosure_dev->pg0.EnclosureLogicalID);
  7600. if (le16_to_cpu(enclosure_dev->pg0.Flags) &
  7601. MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
  7602. sas_device->is_chassis_slot_valid = 1;
  7603. sas_device->chassis_slot =
  7604. enclosure_dev->pg0.ChassisSlot;
  7605. }
  7606. }
  7607. if (sas_device->handle == le16_to_cpu(
  7608. sas_device_pg0->DevHandle))
  7609. goto out;
  7610. pr_info("\thandle changed from(0x%04x)!!!\n",
  7611. sas_device->handle);
  7612. sas_device->handle = le16_to_cpu(
  7613. sas_device_pg0->DevHandle);
  7614. if (sas_target_priv_data)
  7615. sas_target_priv_data->handle =
  7616. le16_to_cpu(sas_device_pg0->DevHandle);
  7617. goto out;
  7618. }
  7619. }
  7620. out:
  7621. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  7622. }
  7623. /**
  7624. * _scsih_create_enclosure_list_after_reset - Free Existing list,
  7625. * And create enclosure list by scanning all Enclosure Page(0)s
  7626. * @ioc: per adapter object
  7627. */
  7628. static void
  7629. _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc)
  7630. {
  7631. struct _enclosure_node *enclosure_dev;
  7632. Mpi2ConfigReply_t mpi_reply;
  7633. u16 enclosure_handle;
  7634. int rc;
  7635. /* Free existing enclosure list */
  7636. mpt3sas_free_enclosure_list(ioc);
  7637. /* Re constructing enclosure list after reset*/
  7638. enclosure_handle = 0xFFFF;
  7639. do {
  7640. enclosure_dev =
  7641. kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL);
  7642. if (!enclosure_dev) {
  7643. pr_err(MPT3SAS_FMT
  7644. "failure at %s:%d/%s()!\n", ioc->name,
  7645. __FILE__, __LINE__, __func__);
  7646. return;
  7647. }
  7648. rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  7649. &enclosure_dev->pg0,
  7650. MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE,
  7651. enclosure_handle);
  7652. if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
  7653. MPI2_IOCSTATUS_MASK)) {
  7654. kfree(enclosure_dev);
  7655. return;
  7656. }
  7657. list_add_tail(&enclosure_dev->list,
  7658. &ioc->enclosure_list);
  7659. enclosure_handle =
  7660. le16_to_cpu(enclosure_dev->pg0.EnclosureHandle);
  7661. } while (1);
  7662. }
  7663. /**
  7664. * _scsih_search_responding_sas_devices -
  7665. * @ioc: per adapter object
  7666. *
  7667. * After host reset, find out whether devices are still responding.
  7668. * If not remove.
  7669. */
  7670. static void
  7671. _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
  7672. {
  7673. Mpi2SasDevicePage0_t sas_device_pg0;
  7674. Mpi2ConfigReply_t mpi_reply;
  7675. u16 ioc_status;
  7676. u16 handle;
  7677. u32 device_info;
  7678. pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
  7679. if (list_empty(&ioc->sas_device_list))
  7680. goto out;
  7681. handle = 0xFFFF;
  7682. while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  7683. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  7684. handle))) {
  7685. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7686. MPI2_IOCSTATUS_MASK;
  7687. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  7688. break;
  7689. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  7690. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  7691. if (!(_scsih_is_end_device(device_info)))
  7692. continue;
  7693. _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
  7694. }
  7695. out:
  7696. pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
  7697. ioc->name);
  7698. }
  7699. /**
  7700. * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
  7701. * @ioc: per adapter object
  7702. * @pcie_device_pg0: PCIe Device page 0
  7703. *
  7704. * After host reset, find out whether devices are still responding.
  7705. * Used in _scsih_remove_unresponding_devices.
  7706. */
  7707. static void
  7708. _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc,
  7709. Mpi26PCIeDevicePage0_t *pcie_device_pg0)
  7710. {
  7711. struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
  7712. struct scsi_target *starget;
  7713. struct _pcie_device *pcie_device;
  7714. unsigned long flags;
  7715. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  7716. list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
  7717. if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID))
  7718. && (pcie_device->slot == le16_to_cpu(
  7719. pcie_device_pg0->Slot))) {
  7720. pcie_device->responding = 1;
  7721. starget = pcie_device->starget;
  7722. if (starget && starget->hostdata) {
  7723. sas_target_priv_data = starget->hostdata;
  7724. sas_target_priv_data->tm_busy = 0;
  7725. sas_target_priv_data->deleted = 0;
  7726. } else
  7727. sas_target_priv_data = NULL;
  7728. if (starget) {
  7729. starget_printk(KERN_INFO, starget,
  7730. "handle(0x%04x), wwid(0x%016llx) ",
  7731. pcie_device->handle,
  7732. (unsigned long long)pcie_device->wwid);
  7733. if (pcie_device->enclosure_handle != 0)
  7734. starget_printk(KERN_INFO, starget,
  7735. "enclosure logical id(0x%016llx), "
  7736. "slot(%d)\n",
  7737. (unsigned long long)
  7738. pcie_device->enclosure_logical_id,
  7739. pcie_device->slot);
  7740. }
  7741. if (((le32_to_cpu(pcie_device_pg0->Flags)) &
  7742. MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) &&
  7743. (ioc->hba_mpi_version_belonged != MPI2_VERSION)) {
  7744. pcie_device->enclosure_level =
  7745. pcie_device_pg0->EnclosureLevel;
  7746. memcpy(&pcie_device->connector_name[0],
  7747. &pcie_device_pg0->ConnectorName[0], 4);
  7748. } else {
  7749. pcie_device->enclosure_level = 0;
  7750. pcie_device->connector_name[0] = '\0';
  7751. }
  7752. if (pcie_device->handle == le16_to_cpu(
  7753. pcie_device_pg0->DevHandle))
  7754. goto out;
  7755. pr_info("\thandle changed from(0x%04x)!!!\n",
  7756. pcie_device->handle);
  7757. pcie_device->handle = le16_to_cpu(
  7758. pcie_device_pg0->DevHandle);
  7759. if (sas_target_priv_data)
  7760. sas_target_priv_data->handle =
  7761. le16_to_cpu(pcie_device_pg0->DevHandle);
  7762. goto out;
  7763. }
  7764. }
  7765. out:
  7766. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  7767. }
  7768. /**
  7769. * _scsih_search_responding_pcie_devices -
  7770. * @ioc: per adapter object
  7771. *
  7772. * After host reset, find out whether devices are still responding.
  7773. * If not remove.
  7774. */
  7775. static void
  7776. _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
  7777. {
  7778. Mpi26PCIeDevicePage0_t pcie_device_pg0;
  7779. Mpi2ConfigReply_t mpi_reply;
  7780. u16 ioc_status;
  7781. u16 handle;
  7782. u32 device_info;
  7783. pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
  7784. if (list_empty(&ioc->pcie_device_list))
  7785. goto out;
  7786. handle = 0xFFFF;
  7787. while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
  7788. &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  7789. handle))) {
  7790. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7791. MPI2_IOCSTATUS_MASK;
  7792. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  7793. pr_info(MPT3SAS_FMT "\tbreak from %s: "
  7794. "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name,
  7795. __func__, ioc_status,
  7796. le32_to_cpu(mpi_reply.IOCLogInfo));
  7797. break;
  7798. }
  7799. handle = le16_to_cpu(pcie_device_pg0.DevHandle);
  7800. device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
  7801. if (!(_scsih_is_nvme_device(device_info)))
  7802. continue;
  7803. _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0);
  7804. }
  7805. out:
  7806. pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n",
  7807. ioc->name);
  7808. }
  7809. /**
  7810. * _scsih_mark_responding_raid_device - mark a raid_device as responding
  7811. * @ioc: per adapter object
  7812. * @wwid: world wide identifier for raid volume
  7813. * @handle: device handle
  7814. *
  7815. * After host reset, find out whether devices are still responding.
  7816. * Used in _scsih_remove_unresponsive_raid_devices.
  7817. */
  7818. static void
  7819. _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
  7820. u16 handle)
  7821. {
  7822. struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
  7823. struct scsi_target *starget;
  7824. struct _raid_device *raid_device;
  7825. unsigned long flags;
  7826. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  7827. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  7828. if (raid_device->wwid == wwid && raid_device->starget) {
  7829. starget = raid_device->starget;
  7830. if (starget && starget->hostdata) {
  7831. sas_target_priv_data = starget->hostdata;
  7832. sas_target_priv_data->deleted = 0;
  7833. } else
  7834. sas_target_priv_data = NULL;
  7835. raid_device->responding = 1;
  7836. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7837. starget_printk(KERN_INFO, raid_device->starget,
  7838. "handle(0x%04x), wwid(0x%016llx)\n", handle,
  7839. (unsigned long long)raid_device->wwid);
  7840. /*
  7841. * WARPDRIVE: The handles of the PDs might have changed
  7842. * across the host reset so re-initialize the
  7843. * required data for Direct IO
  7844. */
  7845. mpt3sas_init_warpdrive_properties(ioc, raid_device);
  7846. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  7847. if (raid_device->handle == handle) {
  7848. spin_unlock_irqrestore(&ioc->raid_device_lock,
  7849. flags);
  7850. return;
  7851. }
  7852. pr_info("\thandle changed from(0x%04x)!!!\n",
  7853. raid_device->handle);
  7854. raid_device->handle = handle;
  7855. if (sas_target_priv_data)
  7856. sas_target_priv_data->handle = handle;
  7857. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7858. return;
  7859. }
  7860. }
  7861. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  7862. }
  7863. /**
  7864. * _scsih_search_responding_raid_devices -
  7865. * @ioc: per adapter object
  7866. *
  7867. * After host reset, find out whether devices are still responding.
  7868. * If not remove.
  7869. */
  7870. static void
  7871. _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
  7872. {
  7873. Mpi2RaidVolPage1_t volume_pg1;
  7874. Mpi2RaidVolPage0_t volume_pg0;
  7875. Mpi2RaidPhysDiskPage0_t pd_pg0;
  7876. Mpi2ConfigReply_t mpi_reply;
  7877. u16 ioc_status;
  7878. u16 handle;
  7879. u8 phys_disk_num;
  7880. if (!ioc->ir_firmware)
  7881. return;
  7882. pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
  7883. ioc->name);
  7884. if (list_empty(&ioc->raid_device_list))
  7885. goto out;
  7886. handle = 0xFFFF;
  7887. while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  7888. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  7889. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7890. MPI2_IOCSTATUS_MASK;
  7891. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  7892. break;
  7893. handle = le16_to_cpu(volume_pg1.DevHandle);
  7894. if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
  7895. &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  7896. sizeof(Mpi2RaidVolPage0_t)))
  7897. continue;
  7898. if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
  7899. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
  7900. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
  7901. _scsih_mark_responding_raid_device(ioc,
  7902. le64_to_cpu(volume_pg1.WWID), handle);
  7903. }
  7904. /* refresh the pd_handles */
  7905. if (!ioc->is_warpdrive) {
  7906. phys_disk_num = 0xFF;
  7907. memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
  7908. while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  7909. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
  7910. phys_disk_num))) {
  7911. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7912. MPI2_IOCSTATUS_MASK;
  7913. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  7914. break;
  7915. phys_disk_num = pd_pg0.PhysDiskNum;
  7916. handle = le16_to_cpu(pd_pg0.DevHandle);
  7917. set_bit(handle, ioc->pd_handles);
  7918. }
  7919. }
  7920. out:
  7921. pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
  7922. ioc->name);
  7923. }
  7924. /**
  7925. * _scsih_mark_responding_expander - mark a expander as responding
  7926. * @ioc: per adapter object
  7927. * @expander_pg0:SAS Expander Config Page0
  7928. *
  7929. * After host reset, find out whether devices are still responding.
  7930. * Used in _scsih_remove_unresponsive_expanders.
  7931. */
  7932. static void
  7933. _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc,
  7934. Mpi2ExpanderPage0_t *expander_pg0)
  7935. {
  7936. struct _sas_node *sas_expander = NULL;
  7937. unsigned long flags;
  7938. int i;
  7939. struct _enclosure_node *enclosure_dev = NULL;
  7940. u16 handle = le16_to_cpu(expander_pg0->DevHandle);
  7941. u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle);
  7942. u64 sas_address = le64_to_cpu(expander_pg0->SASAddress);
  7943. if (enclosure_handle)
  7944. enclosure_dev =
  7945. mpt3sas_scsih_enclosure_find_by_handle(ioc,
  7946. enclosure_handle);
  7947. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  7948. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  7949. if (sas_expander->sas_address != sas_address)
  7950. continue;
  7951. sas_expander->responding = 1;
  7952. if (enclosure_dev) {
  7953. sas_expander->enclosure_logical_id =
  7954. le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
  7955. sas_expander->enclosure_handle =
  7956. le16_to_cpu(expander_pg0->EnclosureHandle);
  7957. }
  7958. if (sas_expander->handle == handle)
  7959. goto out;
  7960. pr_info("\texpander(0x%016llx): handle changed" \
  7961. " from(0x%04x) to (0x%04x)!!!\n",
  7962. (unsigned long long)sas_expander->sas_address,
  7963. sas_expander->handle, handle);
  7964. sas_expander->handle = handle;
  7965. for (i = 0 ; i < sas_expander->num_phys ; i++)
  7966. sas_expander->phy[i].handle = handle;
  7967. goto out;
  7968. }
  7969. out:
  7970. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  7971. }
  7972. /**
  7973. * _scsih_search_responding_expanders -
  7974. * @ioc: per adapter object
  7975. *
  7976. * After host reset, find out whether devices are still responding.
  7977. * If not remove.
  7978. */
  7979. static void
  7980. _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
  7981. {
  7982. Mpi2ExpanderPage0_t expander_pg0;
  7983. Mpi2ConfigReply_t mpi_reply;
  7984. u16 ioc_status;
  7985. u64 sas_address;
  7986. u16 handle;
  7987. pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
  7988. if (list_empty(&ioc->sas_expander_list))
  7989. goto out;
  7990. handle = 0xFFFF;
  7991. while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  7992. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  7993. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  7994. MPI2_IOCSTATUS_MASK;
  7995. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  7996. break;
  7997. handle = le16_to_cpu(expander_pg0.DevHandle);
  7998. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  7999. pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
  8000. handle,
  8001. (unsigned long long)sas_address);
  8002. _scsih_mark_responding_expander(ioc, &expander_pg0);
  8003. }
  8004. out:
  8005. pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
  8006. }
  8007. /**
  8008. * _scsih_remove_unresponding_devices - removing unresponding devices
  8009. * @ioc: per adapter object
  8010. */
  8011. static void
  8012. _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc)
  8013. {
  8014. struct _sas_device *sas_device, *sas_device_next;
  8015. struct _sas_node *sas_expander, *sas_expander_next;
  8016. struct _raid_device *raid_device, *raid_device_next;
  8017. struct _pcie_device *pcie_device, *pcie_device_next;
  8018. struct list_head tmp_list;
  8019. unsigned long flags;
  8020. LIST_HEAD(head);
  8021. pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
  8022. ioc->name);
  8023. /* removing unresponding end devices */
  8024. pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
  8025. ioc->name);
  8026. /*
  8027. * Iterate, pulling off devices marked as non-responding. We become the
  8028. * owner for the reference the list had on any object we prune.
  8029. */
  8030. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  8031. list_for_each_entry_safe(sas_device, sas_device_next,
  8032. &ioc->sas_device_list, list) {
  8033. if (!sas_device->responding)
  8034. list_move_tail(&sas_device->list, &head);
  8035. else
  8036. sas_device->responding = 0;
  8037. }
  8038. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  8039. /*
  8040. * Now, uninitialize and remove the unresponding devices we pruned.
  8041. */
  8042. list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
  8043. _scsih_remove_device(ioc, sas_device);
  8044. list_del_init(&sas_device->list);
  8045. sas_device_put(sas_device);
  8046. }
  8047. pr_info(MPT3SAS_FMT
  8048. " Removing unresponding devices: pcie end-devices\n"
  8049. , ioc->name);
  8050. INIT_LIST_HEAD(&head);
  8051. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  8052. list_for_each_entry_safe(pcie_device, pcie_device_next,
  8053. &ioc->pcie_device_list, list) {
  8054. if (!pcie_device->responding)
  8055. list_move_tail(&pcie_device->list, &head);
  8056. else
  8057. pcie_device->responding = 0;
  8058. }
  8059. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  8060. list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) {
  8061. _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
  8062. list_del_init(&pcie_device->list);
  8063. pcie_device_put(pcie_device);
  8064. }
  8065. /* removing unresponding volumes */
  8066. if (ioc->ir_firmware) {
  8067. pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
  8068. ioc->name);
  8069. list_for_each_entry_safe(raid_device, raid_device_next,
  8070. &ioc->raid_device_list, list) {
  8071. if (!raid_device->responding)
  8072. _scsih_sas_volume_delete(ioc,
  8073. raid_device->handle);
  8074. else
  8075. raid_device->responding = 0;
  8076. }
  8077. }
  8078. /* removing unresponding expanders */
  8079. pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
  8080. ioc->name);
  8081. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  8082. INIT_LIST_HEAD(&tmp_list);
  8083. list_for_each_entry_safe(sas_expander, sas_expander_next,
  8084. &ioc->sas_expander_list, list) {
  8085. if (!sas_expander->responding)
  8086. list_move_tail(&sas_expander->list, &tmp_list);
  8087. else
  8088. sas_expander->responding = 0;
  8089. }
  8090. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  8091. list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
  8092. list) {
  8093. _scsih_expander_node_remove(ioc, sas_expander);
  8094. }
  8095. pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
  8096. ioc->name);
  8097. /* unblock devices */
  8098. _scsih_ublock_io_all_device(ioc);
  8099. }
  8100. static void
  8101. _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
  8102. struct _sas_node *sas_expander, u16 handle)
  8103. {
  8104. Mpi2ExpanderPage1_t expander_pg1;
  8105. Mpi2ConfigReply_t mpi_reply;
  8106. int i;
  8107. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  8108. if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
  8109. &expander_pg1, i, handle))) {
  8110. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  8111. ioc->name, __FILE__, __LINE__, __func__);
  8112. return;
  8113. }
  8114. mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
  8115. le16_to_cpu(expander_pg1.AttachedDevHandle), i,
  8116. expander_pg1.NegotiatedLinkRate >> 4);
  8117. }
  8118. }
  8119. /**
  8120. * _scsih_scan_for_devices_after_reset - scan for devices after host reset
  8121. * @ioc: per adapter object
  8122. */
  8123. static void
  8124. _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
  8125. {
  8126. Mpi2ExpanderPage0_t expander_pg0;
  8127. Mpi2SasDevicePage0_t sas_device_pg0;
  8128. Mpi26PCIeDevicePage0_t pcie_device_pg0;
  8129. Mpi2RaidVolPage1_t volume_pg1;
  8130. Mpi2RaidVolPage0_t volume_pg0;
  8131. Mpi2RaidPhysDiskPage0_t pd_pg0;
  8132. Mpi2EventIrConfigElement_t element;
  8133. Mpi2ConfigReply_t mpi_reply;
  8134. u8 phys_disk_num;
  8135. u16 ioc_status;
  8136. u16 handle, parent_handle;
  8137. u64 sas_address;
  8138. struct _sas_device *sas_device;
  8139. struct _pcie_device *pcie_device;
  8140. struct _sas_node *expander_device;
  8141. static struct _raid_device *raid_device;
  8142. u8 retry_count;
  8143. unsigned long flags;
  8144. pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
  8145. _scsih_sas_host_refresh(ioc);
  8146. pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
  8147. /* expanders */
  8148. handle = 0xFFFF;
  8149. while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  8150. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  8151. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8152. MPI2_IOCSTATUS_MASK;
  8153. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8154. pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
  8155. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  8156. ioc->name, ioc_status,
  8157. le32_to_cpu(mpi_reply.IOCLogInfo));
  8158. break;
  8159. }
  8160. handle = le16_to_cpu(expander_pg0.DevHandle);
  8161. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  8162. expander_device = mpt3sas_scsih_expander_find_by_sas_address(
  8163. ioc, le64_to_cpu(expander_pg0.SASAddress));
  8164. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  8165. if (expander_device)
  8166. _scsih_refresh_expander_links(ioc, expander_device,
  8167. handle);
  8168. else {
  8169. pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
  8170. "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  8171. handle, (unsigned long long)
  8172. le64_to_cpu(expander_pg0.SASAddress));
  8173. _scsih_expander_add(ioc, handle);
  8174. pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
  8175. "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  8176. handle, (unsigned long long)
  8177. le64_to_cpu(expander_pg0.SASAddress));
  8178. }
  8179. }
  8180. pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
  8181. ioc->name);
  8182. if (!ioc->ir_firmware)
  8183. goto skip_to_sas;
  8184. pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
  8185. /* phys disk */
  8186. phys_disk_num = 0xFF;
  8187. while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  8188. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
  8189. phys_disk_num))) {
  8190. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8191. MPI2_IOCSTATUS_MASK;
  8192. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8193. pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
  8194. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  8195. ioc->name, ioc_status,
  8196. le32_to_cpu(mpi_reply.IOCLogInfo));
  8197. break;
  8198. }
  8199. phys_disk_num = pd_pg0.PhysDiskNum;
  8200. handle = le16_to_cpu(pd_pg0.DevHandle);
  8201. sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
  8202. if (sas_device) {
  8203. sas_device_put(sas_device);
  8204. continue;
  8205. }
  8206. if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  8207. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  8208. handle) != 0)
  8209. continue;
  8210. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8211. MPI2_IOCSTATUS_MASK;
  8212. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8213. pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
  8214. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  8215. ioc->name, ioc_status,
  8216. le32_to_cpu(mpi_reply.IOCLogInfo));
  8217. break;
  8218. }
  8219. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  8220. if (!_scsih_get_sas_address(ioc, parent_handle,
  8221. &sas_address)) {
  8222. pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
  8223. " handle (0x%04x), sas_addr(0x%016llx)\n",
  8224. ioc->name, handle, (unsigned long long)
  8225. le64_to_cpu(sas_device_pg0.SASAddress));
  8226. mpt3sas_transport_update_links(ioc, sas_address,
  8227. handle, sas_device_pg0.PhyNum,
  8228. MPI2_SAS_NEG_LINK_RATE_1_5);
  8229. set_bit(handle, ioc->pd_handles);
  8230. retry_count = 0;
  8231. /* This will retry adding the end device.
  8232. * _scsih_add_device() will decide on retries and
  8233. * return "1" when it should be retried
  8234. */
  8235. while (_scsih_add_device(ioc, handle, retry_count++,
  8236. 1)) {
  8237. ssleep(1);
  8238. }
  8239. pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
  8240. " handle (0x%04x), sas_addr(0x%016llx)\n",
  8241. ioc->name, handle, (unsigned long long)
  8242. le64_to_cpu(sas_device_pg0.SASAddress));
  8243. }
  8244. }
  8245. pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
  8246. ioc->name);
  8247. pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
  8248. /* volumes */
  8249. handle = 0xFFFF;
  8250. while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  8251. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  8252. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8253. MPI2_IOCSTATUS_MASK;
  8254. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8255. pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
  8256. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  8257. ioc->name, ioc_status,
  8258. le32_to_cpu(mpi_reply.IOCLogInfo));
  8259. break;
  8260. }
  8261. handle = le16_to_cpu(volume_pg1.DevHandle);
  8262. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  8263. raid_device = _scsih_raid_device_find_by_wwid(ioc,
  8264. le64_to_cpu(volume_pg1.WWID));
  8265. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  8266. if (raid_device)
  8267. continue;
  8268. if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
  8269. &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  8270. sizeof(Mpi2RaidVolPage0_t)))
  8271. continue;
  8272. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8273. MPI2_IOCSTATUS_MASK;
  8274. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8275. pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
  8276. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  8277. ioc->name, ioc_status,
  8278. le32_to_cpu(mpi_reply.IOCLogInfo));
  8279. break;
  8280. }
  8281. if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
  8282. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
  8283. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
  8284. memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
  8285. element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
  8286. element.VolDevHandle = volume_pg1.DevHandle;
  8287. pr_info(MPT3SAS_FMT
  8288. "\tBEFORE adding volume: handle (0x%04x)\n",
  8289. ioc->name, volume_pg1.DevHandle);
  8290. _scsih_sas_volume_add(ioc, &element);
  8291. pr_info(MPT3SAS_FMT
  8292. "\tAFTER adding volume: handle (0x%04x)\n",
  8293. ioc->name, volume_pg1.DevHandle);
  8294. }
  8295. }
  8296. pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
  8297. ioc->name);
  8298. skip_to_sas:
  8299. pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
  8300. ioc->name);
  8301. /* sas devices */
  8302. handle = 0xFFFF;
  8303. while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  8304. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  8305. handle))) {
  8306. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  8307. MPI2_IOCSTATUS_MASK;
  8308. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8309. pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
  8310. " ioc_status(0x%04x), loginfo(0x%08x)\n",
  8311. ioc->name, ioc_status,
  8312. le32_to_cpu(mpi_reply.IOCLogInfo));
  8313. break;
  8314. }
  8315. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  8316. if (!(_scsih_is_end_device(
  8317. le32_to_cpu(sas_device_pg0.DeviceInfo))))
  8318. continue;
  8319. sas_device = mpt3sas_get_sdev_by_addr(ioc,
  8320. le64_to_cpu(sas_device_pg0.SASAddress));
  8321. if (sas_device) {
  8322. sas_device_put(sas_device);
  8323. continue;
  8324. }
  8325. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  8326. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
  8327. pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
  8328. "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  8329. handle, (unsigned long long)
  8330. le64_to_cpu(sas_device_pg0.SASAddress));
  8331. mpt3sas_transport_update_links(ioc, sas_address, handle,
  8332. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  8333. retry_count = 0;
  8334. /* This will retry adding the end device.
  8335. * _scsih_add_device() will decide on retries and
  8336. * return "1" when it should be retried
  8337. */
  8338. while (_scsih_add_device(ioc, handle, retry_count++,
  8339. 0)) {
  8340. ssleep(1);
  8341. }
  8342. pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
  8343. "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  8344. handle, (unsigned long long)
  8345. le64_to_cpu(sas_device_pg0.SASAddress));
  8346. }
  8347. }
  8348. pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
  8349. ioc->name);
  8350. pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n",
  8351. ioc->name);
  8352. /* pcie devices */
  8353. handle = 0xFFFF;
  8354. while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
  8355. &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  8356. handle))) {
  8357. ioc_status = le16_to_cpu(mpi_reply.IOCStatus)
  8358. & MPI2_IOCSTATUS_MASK;
  8359. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  8360. pr_info(MPT3SAS_FMT "\tbreak from pcie end device"
  8361. " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
  8362. ioc->name, ioc_status,
  8363. le32_to_cpu(mpi_reply.IOCLogInfo));
  8364. break;
  8365. }
  8366. handle = le16_to_cpu(pcie_device_pg0.DevHandle);
  8367. if (!(_scsih_is_nvme_device(
  8368. le32_to_cpu(pcie_device_pg0.DeviceInfo))))
  8369. continue;
  8370. pcie_device = mpt3sas_get_pdev_by_wwid(ioc,
  8371. le64_to_cpu(pcie_device_pg0.WWID));
  8372. if (pcie_device) {
  8373. pcie_device_put(pcie_device);
  8374. continue;
  8375. }
  8376. retry_count = 0;
  8377. parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle);
  8378. _scsih_pcie_add_device(ioc, handle);
  8379. pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: "
  8380. "handle (0x%04x), wwid(0x%016llx)\n", ioc->name,
  8381. handle,
  8382. (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID));
  8383. }
  8384. pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n",
  8385. ioc->name);
  8386. pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
  8387. }
  8388. /**
  8389. * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
  8390. * @ioc: per adapter object
  8391. *
  8392. * The handler for doing any required cleanup or initialization.
  8393. */
  8394. void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
  8395. {
  8396. dtmprintk(ioc, pr_info(MPT3SAS_FMT
  8397. "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
  8398. }
  8399. /**
  8400. * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
  8401. * @ioc: per adapter object
  8402. *
  8403. * The handler for doing any required cleanup or initialization.
  8404. */
  8405. void
  8406. mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
  8407. {
  8408. dtmprintk(ioc, pr_info(MPT3SAS_FMT
  8409. "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
  8410. if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
  8411. ioc->scsih_cmds.status |= MPT3_CMD_RESET;
  8412. mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
  8413. complete(&ioc->scsih_cmds.done);
  8414. }
  8415. if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
  8416. ioc->tm_cmds.status |= MPT3_CMD_RESET;
  8417. mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
  8418. complete(&ioc->tm_cmds.done);
  8419. }
  8420. memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
  8421. memset(ioc->device_remove_in_progress, 0,
  8422. ioc->device_remove_in_progress_sz);
  8423. _scsih_fw_event_cleanup_queue(ioc);
  8424. _scsih_flush_running_cmds(ioc);
  8425. }
  8426. /**
  8427. * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
  8428. * @ioc: per adapter object
  8429. *
  8430. * The handler for doing any required cleanup or initialization.
  8431. */
  8432. void
  8433. mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
  8434. {
  8435. dtmprintk(ioc, pr_info(MPT3SAS_FMT
  8436. "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
  8437. if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
  8438. !ioc->sas_hba.num_phys)) {
  8439. _scsih_prep_device_scan(ioc);
  8440. _scsih_create_enclosure_list_after_reset(ioc);
  8441. _scsih_search_responding_sas_devices(ioc);
  8442. _scsih_search_responding_pcie_devices(ioc);
  8443. _scsih_search_responding_raid_devices(ioc);
  8444. _scsih_search_responding_expanders(ioc);
  8445. _scsih_error_recovery_delete_devices(ioc);
  8446. }
  8447. }
  8448. /**
  8449. * _mpt3sas_fw_work - delayed task for processing firmware events
  8450. * @ioc: per adapter object
  8451. * @fw_event: The fw_event_work object
  8452. * Context: user.
  8453. */
  8454. static void
  8455. _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  8456. {
  8457. _scsih_fw_event_del_from_list(ioc, fw_event);
  8458. /* the queue is being flushed so ignore this event */
  8459. if (ioc->remove_host || ioc->pci_error_recovery) {
  8460. fw_event_work_put(fw_event);
  8461. return;
  8462. }
  8463. switch (fw_event->event) {
  8464. case MPT3SAS_PROCESS_TRIGGER_DIAG:
  8465. mpt3sas_process_trigger_data(ioc,
  8466. (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
  8467. fw_event->event_data);
  8468. break;
  8469. case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
  8470. while (scsi_host_in_recovery(ioc->shost) ||
  8471. ioc->shost_recovery) {
  8472. /*
  8473. * If we're unloading, bail. Otherwise, this can become
  8474. * an infinite loop.
  8475. */
  8476. if (ioc->remove_host)
  8477. goto out;
  8478. ssleep(1);
  8479. }
  8480. _scsih_remove_unresponding_devices(ioc);
  8481. _scsih_scan_for_devices_after_reset(ioc);
  8482. break;
  8483. case MPT3SAS_PORT_ENABLE_COMPLETE:
  8484. ioc->start_scan = 0;
  8485. if (missing_delay[0] != -1 && missing_delay[1] != -1)
  8486. mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
  8487. missing_delay[1]);
  8488. dewtprintk(ioc, pr_info(MPT3SAS_FMT
  8489. "port enable: complete from worker thread\n",
  8490. ioc->name));
  8491. break;
  8492. case MPT3SAS_TURN_ON_PFA_LED:
  8493. _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
  8494. break;
  8495. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  8496. _scsih_sas_topology_change_event(ioc, fw_event);
  8497. break;
  8498. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  8499. _scsih_sas_device_status_change_event(ioc, fw_event);
  8500. break;
  8501. case MPI2_EVENT_SAS_DISCOVERY:
  8502. _scsih_sas_discovery_event(ioc, fw_event);
  8503. break;
  8504. case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
  8505. _scsih_sas_device_discovery_error_event(ioc, fw_event);
  8506. break;
  8507. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  8508. _scsih_sas_broadcast_primitive_event(ioc, fw_event);
  8509. break;
  8510. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  8511. _scsih_sas_enclosure_dev_status_change_event(ioc,
  8512. fw_event);
  8513. break;
  8514. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  8515. _scsih_sas_ir_config_change_event(ioc, fw_event);
  8516. break;
  8517. case MPI2_EVENT_IR_VOLUME:
  8518. _scsih_sas_ir_volume_event(ioc, fw_event);
  8519. break;
  8520. case MPI2_EVENT_IR_PHYSICAL_DISK:
  8521. _scsih_sas_ir_physical_disk_event(ioc, fw_event);
  8522. break;
  8523. case MPI2_EVENT_IR_OPERATION_STATUS:
  8524. _scsih_sas_ir_operation_status_event(ioc, fw_event);
  8525. break;
  8526. case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
  8527. _scsih_pcie_device_status_change_event(ioc, fw_event);
  8528. break;
  8529. case MPI2_EVENT_PCIE_ENUMERATION:
  8530. _scsih_pcie_enumeration_event(ioc, fw_event);
  8531. break;
  8532. case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
  8533. _scsih_pcie_topology_change_event(ioc, fw_event);
  8534. return;
  8535. break;
  8536. }
  8537. out:
  8538. fw_event_work_put(fw_event);
  8539. }
  8540. /**
  8541. * _firmware_event_work
  8542. * @work: The fw_event_work object
  8543. * Context: user.
  8544. *
  8545. * wrappers for the work thread handling firmware events
  8546. */
  8547. static void
  8548. _firmware_event_work(struct work_struct *work)
  8549. {
  8550. struct fw_event_work *fw_event = container_of(work,
  8551. struct fw_event_work, work);
  8552. _mpt3sas_fw_work(fw_event->ioc, fw_event);
  8553. }
  8554. /**
  8555. * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
  8556. * @ioc: per adapter object
  8557. * @msix_index: MSIX table index supplied by the OS
  8558. * @reply: reply message frame(lower 32bit addr)
  8559. * Context: interrupt.
  8560. *
  8561. * This function merely adds a new work task into ioc->firmware_event_thread.
  8562. * The tasks are worked from _firmware_event_work in user context.
  8563. *
  8564. * Return: 1 meaning mf should be freed from _base_interrupt
  8565. * 0 means the mf is freed from this function.
  8566. */
  8567. u8
  8568. mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
  8569. u32 reply)
  8570. {
  8571. struct fw_event_work *fw_event;
  8572. Mpi2EventNotificationReply_t *mpi_reply;
  8573. u16 event;
  8574. u16 sz;
  8575. Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
  8576. /* events turned off due to host reset */
  8577. if (ioc->pci_error_recovery)
  8578. return 1;
  8579. mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
  8580. if (unlikely(!mpi_reply)) {
  8581. pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
  8582. ioc->name, __FILE__, __LINE__, __func__);
  8583. return 1;
  8584. }
  8585. event = le16_to_cpu(mpi_reply->Event);
  8586. if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
  8587. mpt3sas_trigger_event(ioc, event, 0);
  8588. switch (event) {
  8589. /* handle these */
  8590. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  8591. {
  8592. Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
  8593. (Mpi2EventDataSasBroadcastPrimitive_t *)
  8594. mpi_reply->EventData;
  8595. if (baen_data->Primitive !=
  8596. MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
  8597. return 1;
  8598. if (ioc->broadcast_aen_busy) {
  8599. ioc->broadcast_aen_pending++;
  8600. return 1;
  8601. } else
  8602. ioc->broadcast_aen_busy = 1;
  8603. break;
  8604. }
  8605. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  8606. _scsih_check_topo_delete_events(ioc,
  8607. (Mpi2EventDataSasTopologyChangeList_t *)
  8608. mpi_reply->EventData);
  8609. break;
  8610. case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
  8611. _scsih_check_pcie_topo_remove_events(ioc,
  8612. (Mpi26EventDataPCIeTopologyChangeList_t *)
  8613. mpi_reply->EventData);
  8614. break;
  8615. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  8616. _scsih_check_ir_config_unhide_events(ioc,
  8617. (Mpi2EventDataIrConfigChangeList_t *)
  8618. mpi_reply->EventData);
  8619. break;
  8620. case MPI2_EVENT_IR_VOLUME:
  8621. _scsih_check_volume_delete_events(ioc,
  8622. (Mpi2EventDataIrVolume_t *)
  8623. mpi_reply->EventData);
  8624. break;
  8625. case MPI2_EVENT_LOG_ENTRY_ADDED:
  8626. {
  8627. Mpi2EventDataLogEntryAdded_t *log_entry;
  8628. u32 *log_code;
  8629. if (!ioc->is_warpdrive)
  8630. break;
  8631. log_entry = (Mpi2EventDataLogEntryAdded_t *)
  8632. mpi_reply->EventData;
  8633. log_code = (u32 *)log_entry->LogData;
  8634. if (le16_to_cpu(log_entry->LogEntryQualifier)
  8635. != MPT2_WARPDRIVE_LOGENTRY)
  8636. break;
  8637. switch (le32_to_cpu(*log_code)) {
  8638. case MPT2_WARPDRIVE_LC_SSDT:
  8639. pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
  8640. "IO Throttling has occurred in the WarpDrive "
  8641. "subsystem. Check WarpDrive documentation for "
  8642. "additional details.\n", ioc->name);
  8643. break;
  8644. case MPT2_WARPDRIVE_LC_SSDLW:
  8645. pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
  8646. "Program/Erase Cycles for the WarpDrive subsystem "
  8647. "in degraded range. Check WarpDrive documentation "
  8648. "for additional details.\n", ioc->name);
  8649. break;
  8650. case MPT2_WARPDRIVE_LC_SSDLF:
  8651. pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
  8652. "There are no Program/Erase Cycles for the "
  8653. "WarpDrive subsystem. The storage device will be "
  8654. "in read-only mode. Check WarpDrive documentation "
  8655. "for additional details.\n", ioc->name);
  8656. break;
  8657. case MPT2_WARPDRIVE_LC_BRMF:
  8658. pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
  8659. "The Backup Rail Monitor has failed on the "
  8660. "WarpDrive subsystem. Check WarpDrive "
  8661. "documentation for additional details.\n",
  8662. ioc->name);
  8663. break;
  8664. }
  8665. break;
  8666. }
  8667. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  8668. case MPI2_EVENT_IR_OPERATION_STATUS:
  8669. case MPI2_EVENT_SAS_DISCOVERY:
  8670. case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
  8671. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  8672. case MPI2_EVENT_IR_PHYSICAL_DISK:
  8673. case MPI2_EVENT_PCIE_ENUMERATION:
  8674. case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
  8675. break;
  8676. case MPI2_EVENT_TEMP_THRESHOLD:
  8677. _scsih_temp_threshold_events(ioc,
  8678. (Mpi2EventDataTemperature_t *)
  8679. mpi_reply->EventData);
  8680. break;
  8681. case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
  8682. ActiveCableEventData =
  8683. (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
  8684. switch (ActiveCableEventData->ReasonCode) {
  8685. case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
  8686. pr_notice(MPT3SAS_FMT
  8687. "Currently an active cable with ReceptacleID %d\n",
  8688. ioc->name, ActiveCableEventData->ReceptacleID);
  8689. pr_notice("cannot be powered and devices connected\n");
  8690. pr_notice("to this active cable will not be seen\n");
  8691. pr_notice("This active cable requires %d mW of power\n",
  8692. ActiveCableEventData->ActiveCablePowerRequirement);
  8693. break;
  8694. case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
  8695. pr_notice(MPT3SAS_FMT
  8696. "Currently a cable with ReceptacleID %d\n",
  8697. ioc->name, ActiveCableEventData->ReceptacleID);
  8698. pr_notice(
  8699. "is not running at optimal speed(12 Gb/s rate)\n");
  8700. break;
  8701. }
  8702. break;
  8703. default: /* ignore the rest */
  8704. return 1;
  8705. }
  8706. sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
  8707. fw_event = alloc_fw_event_work(sz);
  8708. if (!fw_event) {
  8709. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  8710. ioc->name, __FILE__, __LINE__, __func__);
  8711. return 1;
  8712. }
  8713. memcpy(fw_event->event_data, mpi_reply->EventData, sz);
  8714. fw_event->ioc = ioc;
  8715. fw_event->VF_ID = mpi_reply->VF_ID;
  8716. fw_event->VP_ID = mpi_reply->VP_ID;
  8717. fw_event->event = event;
  8718. _scsih_fw_event_add(ioc, fw_event);
  8719. fw_event_work_put(fw_event);
  8720. return 1;
  8721. }
  8722. /**
  8723. * _scsih_expander_node_remove - removing expander device from list.
  8724. * @ioc: per adapter object
  8725. * @sas_expander: the sas_device object
  8726. *
  8727. * Removing object and freeing associated memory from the
  8728. * ioc->sas_expander_list.
  8729. */
  8730. static void
  8731. _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
  8732. struct _sas_node *sas_expander)
  8733. {
  8734. struct _sas_port *mpt3sas_port, *next;
  8735. unsigned long flags;
  8736. /* remove sibling ports attached to this expander */
  8737. list_for_each_entry_safe(mpt3sas_port, next,
  8738. &sas_expander->sas_port_list, port_list) {
  8739. if (ioc->shost_recovery)
  8740. return;
  8741. if (mpt3sas_port->remote_identify.device_type ==
  8742. SAS_END_DEVICE)
  8743. mpt3sas_device_remove_by_sas_address(ioc,
  8744. mpt3sas_port->remote_identify.sas_address);
  8745. else if (mpt3sas_port->remote_identify.device_type ==
  8746. SAS_EDGE_EXPANDER_DEVICE ||
  8747. mpt3sas_port->remote_identify.device_type ==
  8748. SAS_FANOUT_EXPANDER_DEVICE)
  8749. mpt3sas_expander_remove(ioc,
  8750. mpt3sas_port->remote_identify.sas_address);
  8751. }
  8752. mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
  8753. sas_expander->sas_address_parent);
  8754. pr_info(MPT3SAS_FMT
  8755. "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
  8756. ioc->name,
  8757. sas_expander->handle, (unsigned long long)
  8758. sas_expander->sas_address);
  8759. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  8760. list_del(&sas_expander->list);
  8761. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  8762. kfree(sas_expander->phy);
  8763. kfree(sas_expander);
  8764. }
  8765. /**
  8766. * _scsih_ir_shutdown - IR shutdown notification
  8767. * @ioc: per adapter object
  8768. *
  8769. * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
  8770. * the host system is shutting down.
  8771. */
  8772. static void
  8773. _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
  8774. {
  8775. Mpi2RaidActionRequest_t *mpi_request;
  8776. Mpi2RaidActionReply_t *mpi_reply;
  8777. u16 smid;
  8778. /* is IR firmware build loaded ? */
  8779. if (!ioc->ir_firmware)
  8780. return;
  8781. /* are there any volumes ? */
  8782. if (list_empty(&ioc->raid_device_list))
  8783. return;
  8784. mutex_lock(&ioc->scsih_cmds.mutex);
  8785. if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
  8786. pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
  8787. ioc->name, __func__);
  8788. goto out;
  8789. }
  8790. ioc->scsih_cmds.status = MPT3_CMD_PENDING;
  8791. smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
  8792. if (!smid) {
  8793. pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
  8794. ioc->name, __func__);
  8795. ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
  8796. goto out;
  8797. }
  8798. mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
  8799. ioc->scsih_cmds.smid = smid;
  8800. memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
  8801. mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
  8802. mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
  8803. if (!ioc->hide_ir_msg)
  8804. pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
  8805. init_completion(&ioc->scsih_cmds.done);
  8806. mpt3sas_base_put_smid_default(ioc, smid);
  8807. wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
  8808. if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
  8809. pr_err(MPT3SAS_FMT "%s: timeout\n",
  8810. ioc->name, __func__);
  8811. goto out;
  8812. }
  8813. if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
  8814. mpi_reply = ioc->scsih_cmds.reply;
  8815. if (!ioc->hide_ir_msg)
  8816. pr_info(MPT3SAS_FMT "IR shutdown "
  8817. "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
  8818. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  8819. le32_to_cpu(mpi_reply->IOCLogInfo));
  8820. }
  8821. out:
  8822. ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
  8823. mutex_unlock(&ioc->scsih_cmds.mutex);
  8824. }
  8825. /**
  8826. * scsih_remove - detach and remove add host
  8827. * @pdev: PCI device struct
  8828. *
  8829. * Routine called when unloading the driver.
  8830. */
  8831. static void scsih_remove(struct pci_dev *pdev)
  8832. {
  8833. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8834. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  8835. struct _sas_port *mpt3sas_port, *next_port;
  8836. struct _raid_device *raid_device, *next;
  8837. struct MPT3SAS_TARGET *sas_target_priv_data;
  8838. struct _pcie_device *pcie_device, *pcienext;
  8839. struct workqueue_struct *wq;
  8840. unsigned long flags;
  8841. ioc->remove_host = 1;
  8842. if (!pci_device_is_present(pdev))
  8843. _scsih_flush_running_cmds(ioc);
  8844. _scsih_fw_event_cleanup_queue(ioc);
  8845. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  8846. wq = ioc->firmware_event_thread;
  8847. ioc->firmware_event_thread = NULL;
  8848. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  8849. if (wq)
  8850. destroy_workqueue(wq);
  8851. /* release all the volumes */
  8852. _scsih_ir_shutdown(ioc);
  8853. sas_remove_host(shost);
  8854. list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
  8855. list) {
  8856. if (raid_device->starget) {
  8857. sas_target_priv_data =
  8858. raid_device->starget->hostdata;
  8859. sas_target_priv_data->deleted = 1;
  8860. scsi_remove_target(&raid_device->starget->dev);
  8861. }
  8862. pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
  8863. ioc->name, raid_device->handle,
  8864. (unsigned long long) raid_device->wwid);
  8865. _scsih_raid_device_remove(ioc, raid_device);
  8866. }
  8867. list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list,
  8868. list) {
  8869. _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
  8870. list_del_init(&pcie_device->list);
  8871. pcie_device_put(pcie_device);
  8872. }
  8873. /* free ports attached to the sas_host */
  8874. list_for_each_entry_safe(mpt3sas_port, next_port,
  8875. &ioc->sas_hba.sas_port_list, port_list) {
  8876. if (mpt3sas_port->remote_identify.device_type ==
  8877. SAS_END_DEVICE)
  8878. mpt3sas_device_remove_by_sas_address(ioc,
  8879. mpt3sas_port->remote_identify.sas_address);
  8880. else if (mpt3sas_port->remote_identify.device_type ==
  8881. SAS_EDGE_EXPANDER_DEVICE ||
  8882. mpt3sas_port->remote_identify.device_type ==
  8883. SAS_FANOUT_EXPANDER_DEVICE)
  8884. mpt3sas_expander_remove(ioc,
  8885. mpt3sas_port->remote_identify.sas_address);
  8886. }
  8887. /* free phys attached to the sas_host */
  8888. if (ioc->sas_hba.num_phys) {
  8889. kfree(ioc->sas_hba.phy);
  8890. ioc->sas_hba.phy = NULL;
  8891. ioc->sas_hba.num_phys = 0;
  8892. }
  8893. mpt3sas_base_detach(ioc);
  8894. spin_lock(&gioc_lock);
  8895. list_del(&ioc->list);
  8896. spin_unlock(&gioc_lock);
  8897. scsi_host_put(shost);
  8898. }
  8899. /**
  8900. * scsih_shutdown - routine call during system shutdown
  8901. * @pdev: PCI device struct
  8902. */
  8903. static void
  8904. scsih_shutdown(struct pci_dev *pdev)
  8905. {
  8906. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8907. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  8908. struct workqueue_struct *wq;
  8909. unsigned long flags;
  8910. ioc->remove_host = 1;
  8911. if (!pci_device_is_present(pdev))
  8912. _scsih_flush_running_cmds(ioc);
  8913. _scsih_fw_event_cleanup_queue(ioc);
  8914. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  8915. wq = ioc->firmware_event_thread;
  8916. ioc->firmware_event_thread = NULL;
  8917. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  8918. if (wq)
  8919. destroy_workqueue(wq);
  8920. _scsih_ir_shutdown(ioc);
  8921. mpt3sas_base_detach(ioc);
  8922. }
  8923. /**
  8924. * _scsih_probe_boot_devices - reports 1st device
  8925. * @ioc: per adapter object
  8926. *
  8927. * If specified in bios page 2, this routine reports the 1st
  8928. * device scsi-ml or sas transport for persistent boot device
  8929. * purposes. Please refer to function _scsih_determine_boot_device()
  8930. */
  8931. static void
  8932. _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
  8933. {
  8934. u32 channel;
  8935. void *device;
  8936. struct _sas_device *sas_device;
  8937. struct _raid_device *raid_device;
  8938. struct _pcie_device *pcie_device;
  8939. u16 handle;
  8940. u64 sas_address_parent;
  8941. u64 sas_address;
  8942. unsigned long flags;
  8943. int rc;
  8944. int tid;
  8945. /* no Bios, return immediately */
  8946. if (!ioc->bios_pg3.BiosVersion)
  8947. return;
  8948. device = NULL;
  8949. if (ioc->req_boot_device.device) {
  8950. device = ioc->req_boot_device.device;
  8951. channel = ioc->req_boot_device.channel;
  8952. } else if (ioc->req_alt_boot_device.device) {
  8953. device = ioc->req_alt_boot_device.device;
  8954. channel = ioc->req_alt_boot_device.channel;
  8955. } else if (ioc->current_boot_device.device) {
  8956. device = ioc->current_boot_device.device;
  8957. channel = ioc->current_boot_device.channel;
  8958. }
  8959. if (!device)
  8960. return;
  8961. if (channel == RAID_CHANNEL) {
  8962. raid_device = device;
  8963. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  8964. raid_device->id, 0);
  8965. if (rc)
  8966. _scsih_raid_device_remove(ioc, raid_device);
  8967. } else if (channel == PCIE_CHANNEL) {
  8968. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  8969. pcie_device = device;
  8970. tid = pcie_device->id;
  8971. list_move_tail(&pcie_device->list, &ioc->pcie_device_list);
  8972. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  8973. rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0);
  8974. if (rc)
  8975. _scsih_pcie_device_remove(ioc, pcie_device);
  8976. } else {
  8977. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  8978. sas_device = device;
  8979. handle = sas_device->handle;
  8980. sas_address_parent = sas_device->sas_address_parent;
  8981. sas_address = sas_device->sas_address;
  8982. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  8983. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  8984. if (ioc->hide_drives)
  8985. return;
  8986. if (!mpt3sas_transport_port_add(ioc, handle,
  8987. sas_address_parent)) {
  8988. _scsih_sas_device_remove(ioc, sas_device);
  8989. } else if (!sas_device->starget) {
  8990. if (!ioc->is_driver_loading) {
  8991. mpt3sas_transport_port_remove(ioc,
  8992. sas_address,
  8993. sas_address_parent);
  8994. _scsih_sas_device_remove(ioc, sas_device);
  8995. }
  8996. }
  8997. }
  8998. }
  8999. /**
  9000. * _scsih_probe_raid - reporting raid volumes to scsi-ml
  9001. * @ioc: per adapter object
  9002. *
  9003. * Called during initial loading of the driver.
  9004. */
  9005. static void
  9006. _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
  9007. {
  9008. struct _raid_device *raid_device, *raid_next;
  9009. int rc;
  9010. list_for_each_entry_safe(raid_device, raid_next,
  9011. &ioc->raid_device_list, list) {
  9012. if (raid_device->starget)
  9013. continue;
  9014. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  9015. raid_device->id, 0);
  9016. if (rc)
  9017. _scsih_raid_device_remove(ioc, raid_device);
  9018. }
  9019. }
  9020. static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
  9021. {
  9022. struct _sas_device *sas_device = NULL;
  9023. unsigned long flags;
  9024. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  9025. if (!list_empty(&ioc->sas_device_init_list)) {
  9026. sas_device = list_first_entry(&ioc->sas_device_init_list,
  9027. struct _sas_device, list);
  9028. sas_device_get(sas_device);
  9029. }
  9030. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  9031. return sas_device;
  9032. }
  9033. static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
  9034. struct _sas_device *sas_device)
  9035. {
  9036. unsigned long flags;
  9037. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  9038. /*
  9039. * Since we dropped the lock during the call to port_add(), we need to
  9040. * be careful here that somebody else didn't move or delete this item
  9041. * while we were busy with other things.
  9042. *
  9043. * If it was on the list, we need a put() for the reference the list
  9044. * had. Either way, we need a get() for the destination list.
  9045. */
  9046. if (!list_empty(&sas_device->list)) {
  9047. list_del_init(&sas_device->list);
  9048. sas_device_put(sas_device);
  9049. }
  9050. sas_device_get(sas_device);
  9051. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  9052. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  9053. }
  9054. /**
  9055. * _scsih_probe_sas - reporting sas devices to sas transport
  9056. * @ioc: per adapter object
  9057. *
  9058. * Called during initial loading of the driver.
  9059. */
  9060. static void
  9061. _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
  9062. {
  9063. struct _sas_device *sas_device;
  9064. if (ioc->hide_drives)
  9065. return;
  9066. while ((sas_device = get_next_sas_device(ioc))) {
  9067. if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
  9068. sas_device->sas_address_parent)) {
  9069. _scsih_sas_device_remove(ioc, sas_device);
  9070. sas_device_put(sas_device);
  9071. continue;
  9072. } else if (!sas_device->starget) {
  9073. /*
  9074. * When asyn scanning is enabled, its not possible to
  9075. * remove devices while scanning is turned on due to an
  9076. * oops in scsi_sysfs_add_sdev()->add_device()->
  9077. * sysfs_addrm_start()
  9078. */
  9079. if (!ioc->is_driver_loading) {
  9080. mpt3sas_transport_port_remove(ioc,
  9081. sas_device->sas_address,
  9082. sas_device->sas_address_parent);
  9083. _scsih_sas_device_remove(ioc, sas_device);
  9084. sas_device_put(sas_device);
  9085. continue;
  9086. }
  9087. }
  9088. sas_device_make_active(ioc, sas_device);
  9089. sas_device_put(sas_device);
  9090. }
  9091. }
  9092. /**
  9093. * get_next_pcie_device - Get the next pcie device
  9094. * @ioc: per adapter object
  9095. *
  9096. * Get the next pcie device from pcie_device_init_list list.
  9097. *
  9098. * Return: pcie device structure if pcie_device_init_list list is not empty
  9099. * otherwise returns NULL
  9100. */
  9101. static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc)
  9102. {
  9103. struct _pcie_device *pcie_device = NULL;
  9104. unsigned long flags;
  9105. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  9106. if (!list_empty(&ioc->pcie_device_init_list)) {
  9107. pcie_device = list_first_entry(&ioc->pcie_device_init_list,
  9108. struct _pcie_device, list);
  9109. pcie_device_get(pcie_device);
  9110. }
  9111. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  9112. return pcie_device;
  9113. }
  9114. /**
  9115. * pcie_device_make_active - Add pcie device to pcie_device_list list
  9116. * @ioc: per adapter object
  9117. * @pcie_device: pcie device object
  9118. *
  9119. * Add the pcie device which has registered with SCSI Transport Later to
  9120. * pcie_device_list list
  9121. */
  9122. static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
  9123. struct _pcie_device *pcie_device)
  9124. {
  9125. unsigned long flags;
  9126. spin_lock_irqsave(&ioc->pcie_device_lock, flags);
  9127. if (!list_empty(&pcie_device->list)) {
  9128. list_del_init(&pcie_device->list);
  9129. pcie_device_put(pcie_device);
  9130. }
  9131. pcie_device_get(pcie_device);
  9132. list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
  9133. spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
  9134. }
  9135. /**
  9136. * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
  9137. * @ioc: per adapter object
  9138. *
  9139. * Called during initial loading of the driver.
  9140. */
  9141. static void
  9142. _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc)
  9143. {
  9144. struct _pcie_device *pcie_device;
  9145. int rc;
  9146. /* PCIe Device List */
  9147. while ((pcie_device = get_next_pcie_device(ioc))) {
  9148. if (pcie_device->starget) {
  9149. pcie_device_put(pcie_device);
  9150. continue;
  9151. }
  9152. rc = scsi_add_device(ioc->shost, PCIE_CHANNEL,
  9153. pcie_device->id, 0);
  9154. if (rc) {
  9155. _scsih_pcie_device_remove(ioc, pcie_device);
  9156. pcie_device_put(pcie_device);
  9157. continue;
  9158. } else if (!pcie_device->starget) {
  9159. /*
  9160. * When async scanning is enabled, its not possible to
  9161. * remove devices while scanning is turned on due to an
  9162. * oops in scsi_sysfs_add_sdev()->add_device()->
  9163. * sysfs_addrm_start()
  9164. */
  9165. if (!ioc->is_driver_loading) {
  9166. /* TODO-- Need to find out whether this condition will
  9167. * occur or not
  9168. */
  9169. _scsih_pcie_device_remove(ioc, pcie_device);
  9170. pcie_device_put(pcie_device);
  9171. continue;
  9172. }
  9173. }
  9174. pcie_device_make_active(ioc, pcie_device);
  9175. pcie_device_put(pcie_device);
  9176. }
  9177. }
  9178. /**
  9179. * _scsih_probe_devices - probing for devices
  9180. * @ioc: per adapter object
  9181. *
  9182. * Called during initial loading of the driver.
  9183. */
  9184. static void
  9185. _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
  9186. {
  9187. u16 volume_mapping_flags;
  9188. if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
  9189. return; /* return when IOC doesn't support initiator mode */
  9190. _scsih_probe_boot_devices(ioc);
  9191. if (ioc->ir_firmware) {
  9192. volume_mapping_flags =
  9193. le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
  9194. MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
  9195. if (volume_mapping_flags ==
  9196. MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
  9197. _scsih_probe_raid(ioc);
  9198. _scsih_probe_sas(ioc);
  9199. } else {
  9200. _scsih_probe_sas(ioc);
  9201. _scsih_probe_raid(ioc);
  9202. }
  9203. } else {
  9204. _scsih_probe_sas(ioc);
  9205. _scsih_probe_pcie(ioc);
  9206. }
  9207. }
  9208. /**
  9209. * scsih_scan_start - scsi lld callback for .scan_start
  9210. * @shost: SCSI host pointer
  9211. *
  9212. * The shost has the ability to discover targets on its own instead
  9213. * of scanning the entire bus. In our implemention, we will kick off
  9214. * firmware discovery.
  9215. */
  9216. static void
  9217. scsih_scan_start(struct Scsi_Host *shost)
  9218. {
  9219. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9220. int rc;
  9221. if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
  9222. mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
  9223. if (disable_discovery > 0)
  9224. return;
  9225. ioc->start_scan = 1;
  9226. rc = mpt3sas_port_enable(ioc);
  9227. if (rc != 0)
  9228. pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
  9229. }
  9230. /**
  9231. * scsih_scan_finished - scsi lld callback for .scan_finished
  9232. * @shost: SCSI host pointer
  9233. * @time: elapsed time of the scan in jiffies
  9234. *
  9235. * This function will be called periodicallyn until it returns 1 with the
  9236. * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
  9237. * we wait for firmware discovery to complete, then return 1.
  9238. */
  9239. static int
  9240. scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
  9241. {
  9242. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9243. if (disable_discovery > 0) {
  9244. ioc->is_driver_loading = 0;
  9245. ioc->wait_for_discovery_to_complete = 0;
  9246. return 1;
  9247. }
  9248. if (time >= (300 * HZ)) {
  9249. ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
  9250. pr_info(MPT3SAS_FMT
  9251. "port enable: FAILED with timeout (timeout=300s)\n",
  9252. ioc->name);
  9253. ioc->is_driver_loading = 0;
  9254. return 1;
  9255. }
  9256. if (ioc->start_scan)
  9257. return 0;
  9258. if (ioc->start_scan_failed) {
  9259. pr_info(MPT3SAS_FMT
  9260. "port enable: FAILED with (ioc_status=0x%08x)\n",
  9261. ioc->name, ioc->start_scan_failed);
  9262. ioc->is_driver_loading = 0;
  9263. ioc->wait_for_discovery_to_complete = 0;
  9264. ioc->remove_host = 1;
  9265. return 1;
  9266. }
  9267. pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
  9268. ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
  9269. if (ioc->wait_for_discovery_to_complete) {
  9270. ioc->wait_for_discovery_to_complete = 0;
  9271. _scsih_probe_devices(ioc);
  9272. }
  9273. mpt3sas_base_start_watchdog(ioc);
  9274. ioc->is_driver_loading = 0;
  9275. return 1;
  9276. }
  9277. /* shost template for SAS 2.0 HBA devices */
  9278. static struct scsi_host_template mpt2sas_driver_template = {
  9279. .module = THIS_MODULE,
  9280. .name = "Fusion MPT SAS Host",
  9281. .proc_name = MPT2SAS_DRIVER_NAME,
  9282. .queuecommand = scsih_qcmd,
  9283. .target_alloc = scsih_target_alloc,
  9284. .slave_alloc = scsih_slave_alloc,
  9285. .slave_configure = scsih_slave_configure,
  9286. .target_destroy = scsih_target_destroy,
  9287. .slave_destroy = scsih_slave_destroy,
  9288. .scan_finished = scsih_scan_finished,
  9289. .scan_start = scsih_scan_start,
  9290. .change_queue_depth = scsih_change_queue_depth,
  9291. .eh_abort_handler = scsih_abort,
  9292. .eh_device_reset_handler = scsih_dev_reset,
  9293. .eh_target_reset_handler = scsih_target_reset,
  9294. .eh_host_reset_handler = scsih_host_reset,
  9295. .bios_param = scsih_bios_param,
  9296. .can_queue = 1,
  9297. .this_id = -1,
  9298. .sg_tablesize = MPT2SAS_SG_DEPTH,
  9299. .max_sectors = 32767,
  9300. .cmd_per_lun = 7,
  9301. .use_clustering = ENABLE_CLUSTERING,
  9302. .shost_attrs = mpt3sas_host_attrs,
  9303. .sdev_attrs = mpt3sas_dev_attrs,
  9304. .track_queue_depth = 1,
  9305. .cmd_size = sizeof(struct scsiio_tracker),
  9306. };
  9307. /* raid transport support for SAS 2.0 HBA devices */
  9308. static struct raid_function_template mpt2sas_raid_functions = {
  9309. .cookie = &mpt2sas_driver_template,
  9310. .is_raid = scsih_is_raid,
  9311. .get_resync = scsih_get_resync,
  9312. .get_state = scsih_get_state,
  9313. };
  9314. /* shost template for SAS 3.0 HBA devices */
  9315. static struct scsi_host_template mpt3sas_driver_template = {
  9316. .module = THIS_MODULE,
  9317. .name = "Fusion MPT SAS Host",
  9318. .proc_name = MPT3SAS_DRIVER_NAME,
  9319. .queuecommand = scsih_qcmd,
  9320. .target_alloc = scsih_target_alloc,
  9321. .slave_alloc = scsih_slave_alloc,
  9322. .slave_configure = scsih_slave_configure,
  9323. .target_destroy = scsih_target_destroy,
  9324. .slave_destroy = scsih_slave_destroy,
  9325. .scan_finished = scsih_scan_finished,
  9326. .scan_start = scsih_scan_start,
  9327. .change_queue_depth = scsih_change_queue_depth,
  9328. .eh_abort_handler = scsih_abort,
  9329. .eh_device_reset_handler = scsih_dev_reset,
  9330. .eh_target_reset_handler = scsih_target_reset,
  9331. .eh_host_reset_handler = scsih_host_reset,
  9332. .bios_param = scsih_bios_param,
  9333. .can_queue = 1,
  9334. .this_id = -1,
  9335. .sg_tablesize = MPT3SAS_SG_DEPTH,
  9336. .max_sectors = 32767,
  9337. .cmd_per_lun = 7,
  9338. .use_clustering = ENABLE_CLUSTERING,
  9339. .shost_attrs = mpt3sas_host_attrs,
  9340. .sdev_attrs = mpt3sas_dev_attrs,
  9341. .track_queue_depth = 1,
  9342. .cmd_size = sizeof(struct scsiio_tracker),
  9343. };
  9344. /* raid transport support for SAS 3.0 HBA devices */
  9345. static struct raid_function_template mpt3sas_raid_functions = {
  9346. .cookie = &mpt3sas_driver_template,
  9347. .is_raid = scsih_is_raid,
  9348. .get_resync = scsih_get_resync,
  9349. .get_state = scsih_get_state,
  9350. };
  9351. /**
  9352. * _scsih_determine_hba_mpi_version - determine in which MPI version class
  9353. * this device belongs to.
  9354. * @pdev: PCI device struct
  9355. *
  9356. * return MPI2_VERSION for SAS 2.0 HBA devices,
  9357. * MPI25_VERSION for SAS 3.0 HBA devices, and
  9358. * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
  9359. */
  9360. static u16
  9361. _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
  9362. {
  9363. switch (pdev->device) {
  9364. case MPI2_MFGPAGE_DEVID_SSS6200:
  9365. case MPI2_MFGPAGE_DEVID_SAS2004:
  9366. case MPI2_MFGPAGE_DEVID_SAS2008:
  9367. case MPI2_MFGPAGE_DEVID_SAS2108_1:
  9368. case MPI2_MFGPAGE_DEVID_SAS2108_2:
  9369. case MPI2_MFGPAGE_DEVID_SAS2108_3:
  9370. case MPI2_MFGPAGE_DEVID_SAS2116_1:
  9371. case MPI2_MFGPAGE_DEVID_SAS2116_2:
  9372. case MPI2_MFGPAGE_DEVID_SAS2208_1:
  9373. case MPI2_MFGPAGE_DEVID_SAS2208_2:
  9374. case MPI2_MFGPAGE_DEVID_SAS2208_3:
  9375. case MPI2_MFGPAGE_DEVID_SAS2208_4:
  9376. case MPI2_MFGPAGE_DEVID_SAS2208_5:
  9377. case MPI2_MFGPAGE_DEVID_SAS2208_6:
  9378. case MPI2_MFGPAGE_DEVID_SAS2308_1:
  9379. case MPI2_MFGPAGE_DEVID_SAS2308_2:
  9380. case MPI2_MFGPAGE_DEVID_SAS2308_3:
  9381. case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
  9382. return MPI2_VERSION;
  9383. case MPI25_MFGPAGE_DEVID_SAS3004:
  9384. case MPI25_MFGPAGE_DEVID_SAS3008:
  9385. case MPI25_MFGPAGE_DEVID_SAS3108_1:
  9386. case MPI25_MFGPAGE_DEVID_SAS3108_2:
  9387. case MPI25_MFGPAGE_DEVID_SAS3108_5:
  9388. case MPI25_MFGPAGE_DEVID_SAS3108_6:
  9389. return MPI25_VERSION;
  9390. case MPI26_MFGPAGE_DEVID_SAS3216:
  9391. case MPI26_MFGPAGE_DEVID_SAS3224:
  9392. case MPI26_MFGPAGE_DEVID_SAS3316_1:
  9393. case MPI26_MFGPAGE_DEVID_SAS3316_2:
  9394. case MPI26_MFGPAGE_DEVID_SAS3316_3:
  9395. case MPI26_MFGPAGE_DEVID_SAS3316_4:
  9396. case MPI26_MFGPAGE_DEVID_SAS3324_1:
  9397. case MPI26_MFGPAGE_DEVID_SAS3324_2:
  9398. case MPI26_MFGPAGE_DEVID_SAS3324_3:
  9399. case MPI26_MFGPAGE_DEVID_SAS3324_4:
  9400. case MPI26_MFGPAGE_DEVID_SAS3508:
  9401. case MPI26_MFGPAGE_DEVID_SAS3508_1:
  9402. case MPI26_MFGPAGE_DEVID_SAS3408:
  9403. case MPI26_MFGPAGE_DEVID_SAS3516:
  9404. case MPI26_MFGPAGE_DEVID_SAS3516_1:
  9405. case MPI26_MFGPAGE_DEVID_SAS3416:
  9406. case MPI26_MFGPAGE_DEVID_SAS3616:
  9407. return MPI26_VERSION;
  9408. }
  9409. return 0;
  9410. }
  9411. /**
  9412. * _scsih_probe - attach and add scsi host
  9413. * @pdev: PCI device struct
  9414. * @id: pci device id
  9415. *
  9416. * Return: 0 success, anything else error.
  9417. */
  9418. static int
  9419. _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  9420. {
  9421. struct MPT3SAS_ADAPTER *ioc;
  9422. struct Scsi_Host *shost = NULL;
  9423. int rv;
  9424. u16 hba_mpi_version;
  9425. /* Determine in which MPI version class this pci device belongs */
  9426. hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
  9427. if (hba_mpi_version == 0)
  9428. return -ENODEV;
  9429. /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
  9430. * for other generation HBA's return with -ENODEV
  9431. */
  9432. if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
  9433. return -ENODEV;
  9434. /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
  9435. * for other generation HBA's return with -ENODEV
  9436. */
  9437. if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
  9438. || hba_mpi_version == MPI26_VERSION)))
  9439. return -ENODEV;
  9440. switch (hba_mpi_version) {
  9441. case MPI2_VERSION:
  9442. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
  9443. PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
  9444. /* Use mpt2sas driver host template for SAS 2.0 HBA's */
  9445. shost = scsi_host_alloc(&mpt2sas_driver_template,
  9446. sizeof(struct MPT3SAS_ADAPTER));
  9447. if (!shost)
  9448. return -ENODEV;
  9449. ioc = shost_priv(shost);
  9450. memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
  9451. ioc->hba_mpi_version_belonged = hba_mpi_version;
  9452. ioc->id = mpt2_ids++;
  9453. sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
  9454. switch (pdev->device) {
  9455. case MPI2_MFGPAGE_DEVID_SSS6200:
  9456. ioc->is_warpdrive = 1;
  9457. ioc->hide_ir_msg = 1;
  9458. break;
  9459. case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
  9460. ioc->is_mcpu_endpoint = 1;
  9461. break;
  9462. default:
  9463. ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
  9464. break;
  9465. }
  9466. break;
  9467. case MPI25_VERSION:
  9468. case MPI26_VERSION:
  9469. /* Use mpt3sas driver host template for SAS 3.0 HBA's */
  9470. shost = scsi_host_alloc(&mpt3sas_driver_template,
  9471. sizeof(struct MPT3SAS_ADAPTER));
  9472. if (!shost)
  9473. return -ENODEV;
  9474. ioc = shost_priv(shost);
  9475. memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
  9476. ioc->hba_mpi_version_belonged = hba_mpi_version;
  9477. ioc->id = mpt3_ids++;
  9478. sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
  9479. switch (pdev->device) {
  9480. case MPI26_MFGPAGE_DEVID_SAS3508:
  9481. case MPI26_MFGPAGE_DEVID_SAS3508_1:
  9482. case MPI26_MFGPAGE_DEVID_SAS3408:
  9483. case MPI26_MFGPAGE_DEVID_SAS3516:
  9484. case MPI26_MFGPAGE_DEVID_SAS3516_1:
  9485. case MPI26_MFGPAGE_DEVID_SAS3416:
  9486. case MPI26_MFGPAGE_DEVID_SAS3616:
  9487. ioc->is_gen35_ioc = 1;
  9488. break;
  9489. default:
  9490. ioc->is_gen35_ioc = 0;
  9491. }
  9492. if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
  9493. pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
  9494. (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
  9495. ioc->combined_reply_queue = 1;
  9496. if (ioc->is_gen35_ioc)
  9497. ioc->combined_reply_index_count =
  9498. MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
  9499. else
  9500. ioc->combined_reply_index_count =
  9501. MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
  9502. }
  9503. break;
  9504. default:
  9505. return -ENODEV;
  9506. }
  9507. INIT_LIST_HEAD(&ioc->list);
  9508. spin_lock(&gioc_lock);
  9509. list_add_tail(&ioc->list, &mpt3sas_ioc_list);
  9510. spin_unlock(&gioc_lock);
  9511. ioc->shost = shost;
  9512. ioc->pdev = pdev;
  9513. ioc->scsi_io_cb_idx = scsi_io_cb_idx;
  9514. ioc->tm_cb_idx = tm_cb_idx;
  9515. ioc->ctl_cb_idx = ctl_cb_idx;
  9516. ioc->base_cb_idx = base_cb_idx;
  9517. ioc->port_enable_cb_idx = port_enable_cb_idx;
  9518. ioc->transport_cb_idx = transport_cb_idx;
  9519. ioc->scsih_cb_idx = scsih_cb_idx;
  9520. ioc->config_cb_idx = config_cb_idx;
  9521. ioc->tm_tr_cb_idx = tm_tr_cb_idx;
  9522. ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
  9523. ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
  9524. ioc->logging_level = logging_level;
  9525. ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
  9526. /* misc semaphores and spin locks */
  9527. mutex_init(&ioc->reset_in_progress_mutex);
  9528. /* initializing pci_access_mutex lock */
  9529. mutex_init(&ioc->pci_access_mutex);
  9530. spin_lock_init(&ioc->ioc_reset_in_progress_lock);
  9531. spin_lock_init(&ioc->scsi_lookup_lock);
  9532. spin_lock_init(&ioc->sas_device_lock);
  9533. spin_lock_init(&ioc->sas_node_lock);
  9534. spin_lock_init(&ioc->fw_event_lock);
  9535. spin_lock_init(&ioc->raid_device_lock);
  9536. spin_lock_init(&ioc->pcie_device_lock);
  9537. spin_lock_init(&ioc->diag_trigger_lock);
  9538. INIT_LIST_HEAD(&ioc->sas_device_list);
  9539. INIT_LIST_HEAD(&ioc->sas_device_init_list);
  9540. INIT_LIST_HEAD(&ioc->sas_expander_list);
  9541. INIT_LIST_HEAD(&ioc->enclosure_list);
  9542. INIT_LIST_HEAD(&ioc->pcie_device_list);
  9543. INIT_LIST_HEAD(&ioc->pcie_device_init_list);
  9544. INIT_LIST_HEAD(&ioc->fw_event_list);
  9545. INIT_LIST_HEAD(&ioc->raid_device_list);
  9546. INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
  9547. INIT_LIST_HEAD(&ioc->delayed_tr_list);
  9548. INIT_LIST_HEAD(&ioc->delayed_sc_list);
  9549. INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
  9550. INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
  9551. INIT_LIST_HEAD(&ioc->reply_queue_list);
  9552. sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
  9553. /* init shost parameters */
  9554. shost->max_cmd_len = 32;
  9555. shost->max_lun = max_lun;
  9556. shost->transportt = mpt3sas_transport_template;
  9557. shost->unique_id = ioc->id;
  9558. if (ioc->is_mcpu_endpoint) {
  9559. /* mCPU MPI support 64K max IO */
  9560. shost->max_sectors = 128;
  9561. pr_info(MPT3SAS_FMT
  9562. "The max_sectors value is set to %d\n",
  9563. ioc->name, shost->max_sectors);
  9564. } else {
  9565. if (max_sectors != 0xFFFF) {
  9566. if (max_sectors < 64) {
  9567. shost->max_sectors = 64;
  9568. pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
  9569. "for max_sectors, range is 64 to 32767. " \
  9570. "Assigning value of 64.\n", \
  9571. ioc->name, max_sectors);
  9572. } else if (max_sectors > 32767) {
  9573. shost->max_sectors = 32767;
  9574. pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
  9575. "for max_sectors, range is 64 to 32767." \
  9576. "Assigning default value of 32767.\n", \
  9577. ioc->name, max_sectors);
  9578. } else {
  9579. shost->max_sectors = max_sectors & 0xFFFE;
  9580. pr_info(MPT3SAS_FMT
  9581. "The max_sectors value is set to %d\n",
  9582. ioc->name, shost->max_sectors);
  9583. }
  9584. }
  9585. }
  9586. /* register EEDP capabilities with SCSI layer */
  9587. if (prot_mask > 0)
  9588. scsi_host_set_prot(shost, prot_mask);
  9589. else
  9590. scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
  9591. | SHOST_DIF_TYPE2_PROTECTION
  9592. | SHOST_DIF_TYPE3_PROTECTION);
  9593. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  9594. /* event thread */
  9595. snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
  9596. "fw_event_%s%d", ioc->driver_name, ioc->id);
  9597. ioc->firmware_event_thread = alloc_ordered_workqueue(
  9598. ioc->firmware_event_name, 0);
  9599. if (!ioc->firmware_event_thread) {
  9600. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  9601. ioc->name, __FILE__, __LINE__, __func__);
  9602. rv = -ENODEV;
  9603. goto out_thread_fail;
  9604. }
  9605. ioc->is_driver_loading = 1;
  9606. if ((mpt3sas_base_attach(ioc))) {
  9607. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  9608. ioc->name, __FILE__, __LINE__, __func__);
  9609. rv = -ENODEV;
  9610. goto out_attach_fail;
  9611. }
  9612. if (ioc->is_warpdrive) {
  9613. if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
  9614. ioc->hide_drives = 0;
  9615. else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
  9616. ioc->hide_drives = 1;
  9617. else {
  9618. if (mpt3sas_get_num_volumes(ioc))
  9619. ioc->hide_drives = 1;
  9620. else
  9621. ioc->hide_drives = 0;
  9622. }
  9623. } else
  9624. ioc->hide_drives = 0;
  9625. rv = scsi_add_host(shost, &pdev->dev);
  9626. if (rv) {
  9627. pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
  9628. ioc->name, __FILE__, __LINE__, __func__);
  9629. goto out_add_shost_fail;
  9630. }
  9631. scsi_scan_host(shost);
  9632. return 0;
  9633. out_add_shost_fail:
  9634. mpt3sas_base_detach(ioc);
  9635. out_attach_fail:
  9636. destroy_workqueue(ioc->firmware_event_thread);
  9637. out_thread_fail:
  9638. spin_lock(&gioc_lock);
  9639. list_del(&ioc->list);
  9640. spin_unlock(&gioc_lock);
  9641. scsi_host_put(shost);
  9642. return rv;
  9643. }
  9644. #ifdef CONFIG_PM
  9645. /**
  9646. * scsih_suspend - power management suspend main entry point
  9647. * @pdev: PCI device struct
  9648. * @state: PM state change to (usually PCI_D3)
  9649. *
  9650. * Return: 0 success, anything else error.
  9651. */
  9652. static int
  9653. scsih_suspend(struct pci_dev *pdev, pm_message_t state)
  9654. {
  9655. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9656. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9657. pci_power_t device_state;
  9658. mpt3sas_base_stop_watchdog(ioc);
  9659. flush_scheduled_work();
  9660. scsi_block_requests(shost);
  9661. device_state = pci_choose_state(pdev, state);
  9662. pr_info(MPT3SAS_FMT
  9663. "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
  9664. ioc->name, pdev, pci_name(pdev), device_state);
  9665. pci_save_state(pdev);
  9666. mpt3sas_base_free_resources(ioc);
  9667. pci_set_power_state(pdev, device_state);
  9668. return 0;
  9669. }
  9670. /**
  9671. * scsih_resume - power management resume main entry point
  9672. * @pdev: PCI device struct
  9673. *
  9674. * Return: 0 success, anything else error.
  9675. */
  9676. static int
  9677. scsih_resume(struct pci_dev *pdev)
  9678. {
  9679. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9680. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9681. pci_power_t device_state = pdev->current_state;
  9682. int r;
  9683. pr_info(MPT3SAS_FMT
  9684. "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
  9685. ioc->name, pdev, pci_name(pdev), device_state);
  9686. pci_set_power_state(pdev, PCI_D0);
  9687. pci_enable_wake(pdev, PCI_D0, 0);
  9688. pci_restore_state(pdev);
  9689. ioc->pdev = pdev;
  9690. r = mpt3sas_base_map_resources(ioc);
  9691. if (r)
  9692. return r;
  9693. mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
  9694. scsi_unblock_requests(shost);
  9695. mpt3sas_base_start_watchdog(ioc);
  9696. return 0;
  9697. }
  9698. #endif /* CONFIG_PM */
  9699. /**
  9700. * scsih_pci_error_detected - Called when a PCI error is detected.
  9701. * @pdev: PCI device struct
  9702. * @state: PCI channel state
  9703. *
  9704. * Description: Called when a PCI error is detected.
  9705. *
  9706. * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
  9707. */
  9708. static pci_ers_result_t
  9709. scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  9710. {
  9711. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9712. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9713. pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
  9714. ioc->name, state);
  9715. switch (state) {
  9716. case pci_channel_io_normal:
  9717. return PCI_ERS_RESULT_CAN_RECOVER;
  9718. case pci_channel_io_frozen:
  9719. /* Fatal error, prepare for slot reset */
  9720. ioc->pci_error_recovery = 1;
  9721. scsi_block_requests(ioc->shost);
  9722. mpt3sas_base_stop_watchdog(ioc);
  9723. mpt3sas_base_free_resources(ioc);
  9724. return PCI_ERS_RESULT_NEED_RESET;
  9725. case pci_channel_io_perm_failure:
  9726. /* Permanent error, prepare for device removal */
  9727. ioc->pci_error_recovery = 1;
  9728. mpt3sas_base_stop_watchdog(ioc);
  9729. _scsih_flush_running_cmds(ioc);
  9730. return PCI_ERS_RESULT_DISCONNECT;
  9731. }
  9732. return PCI_ERS_RESULT_NEED_RESET;
  9733. }
  9734. /**
  9735. * scsih_pci_slot_reset - Called when PCI slot has been reset.
  9736. * @pdev: PCI device struct
  9737. *
  9738. * Description: This routine is called by the pci error recovery
  9739. * code after the PCI slot has been reset, just before we
  9740. * should resume normal operations.
  9741. */
  9742. static pci_ers_result_t
  9743. scsih_pci_slot_reset(struct pci_dev *pdev)
  9744. {
  9745. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9746. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9747. int rc;
  9748. pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
  9749. ioc->name);
  9750. ioc->pci_error_recovery = 0;
  9751. ioc->pdev = pdev;
  9752. pci_restore_state(pdev);
  9753. rc = mpt3sas_base_map_resources(ioc);
  9754. if (rc)
  9755. return PCI_ERS_RESULT_DISCONNECT;
  9756. rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
  9757. pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
  9758. (rc == 0) ? "success" : "failed");
  9759. if (!rc)
  9760. return PCI_ERS_RESULT_RECOVERED;
  9761. else
  9762. return PCI_ERS_RESULT_DISCONNECT;
  9763. }
  9764. /**
  9765. * scsih_pci_resume() - resume normal ops after PCI reset
  9766. * @pdev: pointer to PCI device
  9767. *
  9768. * Called when the error recovery driver tells us that its
  9769. * OK to resume normal operation. Use completion to allow
  9770. * halted scsi ops to resume.
  9771. */
  9772. static void
  9773. scsih_pci_resume(struct pci_dev *pdev)
  9774. {
  9775. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9776. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9777. pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
  9778. pci_cleanup_aer_uncorrect_error_status(pdev);
  9779. mpt3sas_base_start_watchdog(ioc);
  9780. scsi_unblock_requests(ioc->shost);
  9781. }
  9782. /**
  9783. * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
  9784. * @pdev: pointer to PCI device
  9785. */
  9786. static pci_ers_result_t
  9787. scsih_pci_mmio_enabled(struct pci_dev *pdev)
  9788. {
  9789. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  9790. struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
  9791. pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
  9792. ioc->name);
  9793. /* TODO - dump whatever for debugging purposes */
  9794. /* This called only if scsih_pci_error_detected returns
  9795. * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
  9796. * works, no need to reset slot.
  9797. */
  9798. return PCI_ERS_RESULT_RECOVERED;
  9799. }
  9800. /**
  9801. * scsih__ncq_prio_supp - Check for NCQ command priority support
  9802. * @sdev: scsi device struct
  9803. *
  9804. * This is called when a user indicates they would like to enable
  9805. * ncq command priorities. This works only on SATA devices.
  9806. */
  9807. bool scsih_ncq_prio_supp(struct scsi_device *sdev)
  9808. {
  9809. unsigned char *buf;
  9810. bool ncq_prio_supp = false;
  9811. if (!scsi_device_supports_vpd(sdev))
  9812. return ncq_prio_supp;
  9813. buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
  9814. if (!buf)
  9815. return ncq_prio_supp;
  9816. if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
  9817. ncq_prio_supp = (buf[213] >> 4) & 1;
  9818. kfree(buf);
  9819. return ncq_prio_supp;
  9820. }
  9821. /*
  9822. * The pci device ids are defined in mpi/mpi2_cnfg.h.
  9823. */
  9824. static const struct pci_device_id mpt3sas_pci_table[] = {
  9825. /* Spitfire ~ 2004 */
  9826. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
  9827. PCI_ANY_ID, PCI_ANY_ID },
  9828. /* Falcon ~ 2008 */
  9829. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
  9830. PCI_ANY_ID, PCI_ANY_ID },
  9831. /* Liberator ~ 2108 */
  9832. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
  9833. PCI_ANY_ID, PCI_ANY_ID },
  9834. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
  9835. PCI_ANY_ID, PCI_ANY_ID },
  9836. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
  9837. PCI_ANY_ID, PCI_ANY_ID },
  9838. /* Meteor ~ 2116 */
  9839. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
  9840. PCI_ANY_ID, PCI_ANY_ID },
  9841. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
  9842. PCI_ANY_ID, PCI_ANY_ID },
  9843. /* Thunderbolt ~ 2208 */
  9844. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
  9845. PCI_ANY_ID, PCI_ANY_ID },
  9846. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
  9847. PCI_ANY_ID, PCI_ANY_ID },
  9848. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
  9849. PCI_ANY_ID, PCI_ANY_ID },
  9850. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
  9851. PCI_ANY_ID, PCI_ANY_ID },
  9852. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
  9853. PCI_ANY_ID, PCI_ANY_ID },
  9854. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
  9855. PCI_ANY_ID, PCI_ANY_ID },
  9856. /* Mustang ~ 2308 */
  9857. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
  9858. PCI_ANY_ID, PCI_ANY_ID },
  9859. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
  9860. PCI_ANY_ID, PCI_ANY_ID },
  9861. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
  9862. PCI_ANY_ID, PCI_ANY_ID },
  9863. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP,
  9864. PCI_ANY_ID, PCI_ANY_ID },
  9865. /* SSS6200 */
  9866. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
  9867. PCI_ANY_ID, PCI_ANY_ID },
  9868. /* Fury ~ 3004 and 3008 */
  9869. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
  9870. PCI_ANY_ID, PCI_ANY_ID },
  9871. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
  9872. PCI_ANY_ID, PCI_ANY_ID },
  9873. /* Invader ~ 3108 */
  9874. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
  9875. PCI_ANY_ID, PCI_ANY_ID },
  9876. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
  9877. PCI_ANY_ID, PCI_ANY_ID },
  9878. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
  9879. PCI_ANY_ID, PCI_ANY_ID },
  9880. { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
  9881. PCI_ANY_ID, PCI_ANY_ID },
  9882. /* Cutlass ~ 3216 and 3224 */
  9883. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
  9884. PCI_ANY_ID, PCI_ANY_ID },
  9885. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
  9886. PCI_ANY_ID, PCI_ANY_ID },
  9887. /* Intruder ~ 3316 and 3324 */
  9888. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
  9889. PCI_ANY_ID, PCI_ANY_ID },
  9890. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
  9891. PCI_ANY_ID, PCI_ANY_ID },
  9892. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
  9893. PCI_ANY_ID, PCI_ANY_ID },
  9894. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
  9895. PCI_ANY_ID, PCI_ANY_ID },
  9896. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
  9897. PCI_ANY_ID, PCI_ANY_ID },
  9898. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
  9899. PCI_ANY_ID, PCI_ANY_ID },
  9900. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
  9901. PCI_ANY_ID, PCI_ANY_ID },
  9902. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
  9903. PCI_ANY_ID, PCI_ANY_ID },
  9904. /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
  9905. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
  9906. PCI_ANY_ID, PCI_ANY_ID },
  9907. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
  9908. PCI_ANY_ID, PCI_ANY_ID },
  9909. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
  9910. PCI_ANY_ID, PCI_ANY_ID },
  9911. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
  9912. PCI_ANY_ID, PCI_ANY_ID },
  9913. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
  9914. PCI_ANY_ID, PCI_ANY_ID },
  9915. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
  9916. PCI_ANY_ID, PCI_ANY_ID },
  9917. /* Mercator ~ 3616*/
  9918. { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616,
  9919. PCI_ANY_ID, PCI_ANY_ID },
  9920. {0} /* Terminating entry */
  9921. };
  9922. MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
  9923. static struct pci_error_handlers _mpt3sas_err_handler = {
  9924. .error_detected = scsih_pci_error_detected,
  9925. .mmio_enabled = scsih_pci_mmio_enabled,
  9926. .slot_reset = scsih_pci_slot_reset,
  9927. .resume = scsih_pci_resume,
  9928. };
  9929. static struct pci_driver mpt3sas_driver = {
  9930. .name = MPT3SAS_DRIVER_NAME,
  9931. .id_table = mpt3sas_pci_table,
  9932. .probe = _scsih_probe,
  9933. .remove = scsih_remove,
  9934. .shutdown = scsih_shutdown,
  9935. .err_handler = &_mpt3sas_err_handler,
  9936. #ifdef CONFIG_PM
  9937. .suspend = scsih_suspend,
  9938. .resume = scsih_resume,
  9939. #endif
  9940. };
  9941. /**
  9942. * scsih_init - main entry point for this driver.
  9943. *
  9944. * Return: 0 success, anything else error.
  9945. */
  9946. static int
  9947. scsih_init(void)
  9948. {
  9949. mpt2_ids = 0;
  9950. mpt3_ids = 0;
  9951. mpt3sas_base_initialize_callback_handler();
  9952. /* queuecommand callback hander */
  9953. scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
  9954. /* task management callback handler */
  9955. tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
  9956. /* base internal commands callback handler */
  9957. base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
  9958. port_enable_cb_idx = mpt3sas_base_register_callback_handler(
  9959. mpt3sas_port_enable_done);
  9960. /* transport internal commands callback handler */
  9961. transport_cb_idx = mpt3sas_base_register_callback_handler(
  9962. mpt3sas_transport_done);
  9963. /* scsih internal commands callback handler */
  9964. scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
  9965. /* configuration page API internal commands callback handler */
  9966. config_cb_idx = mpt3sas_base_register_callback_handler(
  9967. mpt3sas_config_done);
  9968. /* ctl module callback handler */
  9969. ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
  9970. tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
  9971. _scsih_tm_tr_complete);
  9972. tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
  9973. _scsih_tm_volume_tr_complete);
  9974. tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
  9975. _scsih_sas_control_complete);
  9976. return 0;
  9977. }
  9978. /**
  9979. * scsih_exit - exit point for this driver (when it is a module).
  9980. *
  9981. * Return: 0 success, anything else error.
  9982. */
  9983. static void
  9984. scsih_exit(void)
  9985. {
  9986. mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
  9987. mpt3sas_base_release_callback_handler(tm_cb_idx);
  9988. mpt3sas_base_release_callback_handler(base_cb_idx);
  9989. mpt3sas_base_release_callback_handler(port_enable_cb_idx);
  9990. mpt3sas_base_release_callback_handler(transport_cb_idx);
  9991. mpt3sas_base_release_callback_handler(scsih_cb_idx);
  9992. mpt3sas_base_release_callback_handler(config_cb_idx);
  9993. mpt3sas_base_release_callback_handler(ctl_cb_idx);
  9994. mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
  9995. mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
  9996. mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
  9997. /* raid transport support */
  9998. if (hbas_to_enumerate != 1)
  9999. raid_class_release(mpt3sas_raid_template);
  10000. if (hbas_to_enumerate != 2)
  10001. raid_class_release(mpt2sas_raid_template);
  10002. sas_release_transport(mpt3sas_transport_template);
  10003. }
  10004. /**
  10005. * _mpt3sas_init - main entry point for this driver.
  10006. *
  10007. * Return: 0 success, anything else error.
  10008. */
  10009. static int __init
  10010. _mpt3sas_init(void)
  10011. {
  10012. int error;
  10013. pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
  10014. MPT3SAS_DRIVER_VERSION);
  10015. mpt3sas_transport_template =
  10016. sas_attach_transport(&mpt3sas_transport_functions);
  10017. if (!mpt3sas_transport_template)
  10018. return -ENODEV;
  10019. /* No need attach mpt3sas raid functions template
  10020. * if hbas_to_enumarate value is one.
  10021. */
  10022. if (hbas_to_enumerate != 1) {
  10023. mpt3sas_raid_template =
  10024. raid_class_attach(&mpt3sas_raid_functions);
  10025. if (!mpt3sas_raid_template) {
  10026. sas_release_transport(mpt3sas_transport_template);
  10027. return -ENODEV;
  10028. }
  10029. }
  10030. /* No need to attach mpt2sas raid functions template
  10031. * if hbas_to_enumarate value is two
  10032. */
  10033. if (hbas_to_enumerate != 2) {
  10034. mpt2sas_raid_template =
  10035. raid_class_attach(&mpt2sas_raid_functions);
  10036. if (!mpt2sas_raid_template) {
  10037. sas_release_transport(mpt3sas_transport_template);
  10038. return -ENODEV;
  10039. }
  10040. }
  10041. error = scsih_init();
  10042. if (error) {
  10043. scsih_exit();
  10044. return error;
  10045. }
  10046. mpt3sas_ctl_init(hbas_to_enumerate);
  10047. error = pci_register_driver(&mpt3sas_driver);
  10048. if (error)
  10049. scsih_exit();
  10050. return error;
  10051. }
  10052. /**
  10053. * _mpt3sas_exit - exit point for this driver (when it is a module).
  10054. *
  10055. */
  10056. static void __exit
  10057. _mpt3sas_exit(void)
  10058. {
  10059. pr_info("mpt3sas version %s unloading\n",
  10060. MPT3SAS_DRIVER_VERSION);
  10061. mpt3sas_ctl_exit(hbas_to_enumerate);
  10062. pci_unregister_driver(&mpt3sas_driver);
  10063. scsih_exit();
  10064. }
  10065. module_init(_mpt3sas_init);
  10066. module_exit(_mpt3sas_exit);