mpt2sas_scsih.c 206 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231
  1. /*
  2. * Scsi Host Layer for MPT (Message Passing Technology) based controllers
  3. *
  4. * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
  5. * Copyright (C) 2007-2010 LSI Corporation
  6. * (mailto:DL-MPTFusionLinux@lsi.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. * DISCLAIMER OF LIABILITY
  29. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  39. * USA.
  40. */
  41. #include <linux/version.h>
  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/interrupt.h>
  52. #include <linux/aer.h>
  53. #include <linux/raid_class.h>
  54. #include <linux/slab.h>
  55. #include "mpt2sas_base.h"
  56. MODULE_AUTHOR(MPT2SAS_AUTHOR);
  57. MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
  58. MODULE_LICENSE("GPL");
  59. MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
  60. #define RAID_CHANNEL 1
  61. /* forward proto's */
  62. static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  63. struct _sas_node *sas_expander);
  64. static void _firmware_event_work(struct work_struct *work);
  65. static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
  66. /* global parameters */
  67. LIST_HEAD(mpt2sas_ioc_list);
  68. /* local parameters */
  69. static u8 scsi_io_cb_idx = -1;
  70. static u8 tm_cb_idx = -1;
  71. static u8 ctl_cb_idx = -1;
  72. static u8 base_cb_idx = -1;
  73. static u8 transport_cb_idx = -1;
  74. static u8 scsih_cb_idx = -1;
  75. static u8 config_cb_idx = -1;
  76. static int mpt_ids;
  77. static u8 tm_tr_cb_idx = -1 ;
  78. static u8 tm_tr_volume_cb_idx = -1 ;
  79. static u8 tm_sas_control_cb_idx = -1;
  80. /* command line options */
  81. static u32 logging_level;
  82. MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
  83. "(default=0)");
  84. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  85. #define MPT2SAS_MAX_LUN (16895)
  86. static int max_lun = MPT2SAS_MAX_LUN;
  87. module_param(max_lun, int, 0);
  88. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  89. /**
  90. * struct sense_info - common structure for obtaining sense keys
  91. * @skey: sense key
  92. * @asc: additional sense code
  93. * @ascq: additional sense code qualifier
  94. */
  95. struct sense_info {
  96. u8 skey;
  97. u8 asc;
  98. u8 ascq;
  99. };
  100. #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
  101. /**
  102. * struct fw_event_work - firmware event struct
  103. * @list: link list framework
  104. * @work: work object (ioc->fault_reset_work_q)
  105. * @cancel_pending_work: flag set during reset handling
  106. * @ioc: per adapter object
  107. * @VF_ID: virtual function id
  108. * @VP_ID: virtual port id
  109. * @ignore: flag meaning this event has been marked to ignore
  110. * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
  111. * @event_data: reply event data payload follows
  112. *
  113. * This object stored on ioc->fw_event_list.
  114. */
  115. struct fw_event_work {
  116. struct list_head list;
  117. u8 cancel_pending_work;
  118. struct delayed_work delayed_work;
  119. struct MPT2SAS_ADAPTER *ioc;
  120. u8 VF_ID;
  121. u8 VP_ID;
  122. u8 ignore;
  123. u16 event;
  124. void *event_data;
  125. };
  126. /* raid transport support */
  127. static struct raid_template *mpt2sas_raid_template;
  128. /**
  129. * struct _scsi_io_transfer - scsi io transfer
  130. * @handle: sas device handle (assigned by firmware)
  131. * @is_raid: flag set for hidden raid components
  132. * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
  133. * @data_length: data transfer length
  134. * @data_dma: dma pointer to data
  135. * @sense: sense data
  136. * @lun: lun number
  137. * @cdb_length: cdb length
  138. * @cdb: cdb contents
  139. * @timeout: timeout for this command
  140. * @VF_ID: virtual function id
  141. * @VP_ID: virtual port id
  142. * @valid_reply: flag set for reply message
  143. * @sense_length: sense length
  144. * @ioc_status: ioc status
  145. * @scsi_state: scsi state
  146. * @scsi_status: scsi staus
  147. * @log_info: log information
  148. * @transfer_length: data length transfer when there is a reply message
  149. *
  150. * Used for sending internal scsi commands to devices within this module.
  151. * Refer to _scsi_send_scsi_io().
  152. */
  153. struct _scsi_io_transfer {
  154. u16 handle;
  155. u8 is_raid;
  156. enum dma_data_direction dir;
  157. u32 data_length;
  158. dma_addr_t data_dma;
  159. u8 sense[SCSI_SENSE_BUFFERSIZE];
  160. u32 lun;
  161. u8 cdb_length;
  162. u8 cdb[32];
  163. u8 timeout;
  164. u8 VF_ID;
  165. u8 VP_ID;
  166. u8 valid_reply;
  167. /* the following bits are only valid when 'valid_reply = 1' */
  168. u32 sense_length;
  169. u16 ioc_status;
  170. u8 scsi_state;
  171. u8 scsi_status;
  172. u32 log_info;
  173. u32 transfer_length;
  174. };
  175. /*
  176. * The pci device ids are defined in mpi/mpi2_cnfg.h.
  177. */
  178. static struct pci_device_id scsih_pci_table[] = {
  179. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
  180. PCI_ANY_ID, PCI_ANY_ID },
  181. /* Falcon ~ 2008*/
  182. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
  183. PCI_ANY_ID, PCI_ANY_ID },
  184. /* Liberator ~ 2108 */
  185. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
  186. PCI_ANY_ID, PCI_ANY_ID },
  187. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
  188. PCI_ANY_ID, PCI_ANY_ID },
  189. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
  190. PCI_ANY_ID, PCI_ANY_ID },
  191. /* Meteor ~ 2116 */
  192. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
  193. PCI_ANY_ID, PCI_ANY_ID },
  194. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
  195. PCI_ANY_ID, PCI_ANY_ID },
  196. /* Thunderbolt ~ 2208 */
  197. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
  198. PCI_ANY_ID, PCI_ANY_ID },
  199. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
  200. PCI_ANY_ID, PCI_ANY_ID },
  201. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
  202. PCI_ANY_ID, PCI_ANY_ID },
  203. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
  204. PCI_ANY_ID, PCI_ANY_ID },
  205. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
  206. PCI_ANY_ID, PCI_ANY_ID },
  207. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
  208. PCI_ANY_ID, PCI_ANY_ID },
  209. /* Mustang ~ 2308 */
  210. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
  211. PCI_ANY_ID, PCI_ANY_ID },
  212. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
  213. PCI_ANY_ID, PCI_ANY_ID },
  214. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
  215. PCI_ANY_ID, PCI_ANY_ID },
  216. {0} /* Terminating entry */
  217. };
  218. MODULE_DEVICE_TABLE(pci, scsih_pci_table);
  219. /**
  220. * _scsih_set_debug_level - global setting of ioc->logging_level.
  221. *
  222. * Note: The logging levels are defined in mpt2sas_debug.h.
  223. */
  224. static int
  225. _scsih_set_debug_level(const char *val, struct kernel_param *kp)
  226. {
  227. int ret = param_set_int(val, kp);
  228. struct MPT2SAS_ADAPTER *ioc;
  229. if (ret)
  230. return ret;
  231. printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
  232. list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
  233. ioc->logging_level = logging_level;
  234. return 0;
  235. }
  236. module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
  237. &logging_level, 0644);
  238. /**
  239. * _scsih_srch_boot_sas_address - search based on sas_address
  240. * @sas_address: sas address
  241. * @boot_device: boot device object from bios page 2
  242. *
  243. * Returns 1 when there's a match, 0 means no match.
  244. */
  245. static inline int
  246. _scsih_srch_boot_sas_address(u64 sas_address,
  247. Mpi2BootDeviceSasWwid_t *boot_device)
  248. {
  249. return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
  250. }
  251. /**
  252. * _scsih_srch_boot_device_name - search based on device name
  253. * @device_name: device name specified in INDENTIFY fram
  254. * @boot_device: boot device object from bios page 2
  255. *
  256. * Returns 1 when there's a match, 0 means no match.
  257. */
  258. static inline int
  259. _scsih_srch_boot_device_name(u64 device_name,
  260. Mpi2BootDeviceDeviceName_t *boot_device)
  261. {
  262. return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
  263. }
  264. /**
  265. * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
  266. * @enclosure_logical_id: enclosure logical id
  267. * @slot_number: slot number
  268. * @boot_device: boot device object from bios page 2
  269. *
  270. * Returns 1 when there's a match, 0 means no match.
  271. */
  272. static inline int
  273. _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
  274. Mpi2BootDeviceEnclosureSlot_t *boot_device)
  275. {
  276. return (enclosure_logical_id == le64_to_cpu(boot_device->
  277. EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
  278. SlotNumber)) ? 1 : 0;
  279. }
  280. /**
  281. * _scsih_is_boot_device - search for matching boot device.
  282. * @sas_address: sas address
  283. * @device_name: device name specified in INDENTIFY fram
  284. * @enclosure_logical_id: enclosure logical id
  285. * @slot_number: slot number
  286. * @form: specifies boot device form
  287. * @boot_device: boot device object from bios page 2
  288. *
  289. * Returns 1 when there's a match, 0 means no match.
  290. */
  291. static int
  292. _scsih_is_boot_device(u64 sas_address, u64 device_name,
  293. u64 enclosure_logical_id, u16 slot, u8 form,
  294. Mpi2BiosPage2BootDevice_t *boot_device)
  295. {
  296. int rc = 0;
  297. switch (form) {
  298. case MPI2_BIOSPAGE2_FORM_SAS_WWID:
  299. if (!sas_address)
  300. break;
  301. rc = _scsih_srch_boot_sas_address(
  302. sas_address, &boot_device->SasWwid);
  303. break;
  304. case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
  305. if (!enclosure_logical_id)
  306. break;
  307. rc = _scsih_srch_boot_encl_slot(
  308. enclosure_logical_id,
  309. slot, &boot_device->EnclosureSlot);
  310. break;
  311. case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
  312. if (!device_name)
  313. break;
  314. rc = _scsih_srch_boot_device_name(
  315. device_name, &boot_device->DeviceName);
  316. break;
  317. case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
  318. break;
  319. }
  320. return rc;
  321. }
  322. /**
  323. * _scsih_get_sas_address - set the sas_address for given device handle
  324. * @handle: device handle
  325. * @sas_address: sas address
  326. *
  327. * Returns 0 success, non-zero when failure
  328. */
  329. static int
  330. _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  331. u64 *sas_address)
  332. {
  333. Mpi2SasDevicePage0_t sas_device_pg0;
  334. Mpi2ConfigReply_t mpi_reply;
  335. u32 ioc_status;
  336. if (handle <= ioc->sas_hba.num_phys) {
  337. *sas_address = ioc->sas_hba.sas_address;
  338. return 0;
  339. } else
  340. *sas_address = 0;
  341. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  342. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  343. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  344. ioc->name, __FILE__, __LINE__, __func__);
  345. return -ENXIO;
  346. }
  347. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  348. MPI2_IOCSTATUS_MASK;
  349. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  350. printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
  351. "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
  352. __FILE__, __LINE__, __func__);
  353. return -EIO;
  354. }
  355. *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  356. return 0;
  357. }
  358. /**
  359. * _scsih_determine_boot_device - determine boot device.
  360. * @ioc: per adapter object
  361. * @device: either sas_device or raid_device object
  362. * @is_raid: [flag] 1 = raid object, 0 = sas object
  363. *
  364. * Determines whether this device should be first reported device to
  365. * to scsi-ml or sas transport, this purpose is for persistant boot device.
  366. * There are primary, alternate, and current entries in bios page 2. The order
  367. * priority is primary, alternate, then current. This routine saves
  368. * the corresponding device object and is_raid flag in the ioc object.
  369. * The saved data to be used later in _scsih_probe_boot_devices().
  370. */
  371. static void
  372. _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
  373. void *device, u8 is_raid)
  374. {
  375. struct _sas_device *sas_device;
  376. struct _raid_device *raid_device;
  377. u64 sas_address;
  378. u64 device_name;
  379. u64 enclosure_logical_id;
  380. u16 slot;
  381. /* only process this function when driver loads */
  382. if (!ioc->wait_for_port_enable_to_complete)
  383. return;
  384. if (!is_raid) {
  385. sas_device = device;
  386. sas_address = sas_device->sas_address;
  387. device_name = sas_device->device_name;
  388. enclosure_logical_id = sas_device->enclosure_logical_id;
  389. slot = sas_device->slot;
  390. } else {
  391. raid_device = device;
  392. sas_address = raid_device->wwid;
  393. device_name = 0;
  394. enclosure_logical_id = 0;
  395. slot = 0;
  396. }
  397. if (!ioc->req_boot_device.device) {
  398. if (_scsih_is_boot_device(sas_address, device_name,
  399. enclosure_logical_id, slot,
  400. (ioc->bios_pg2.ReqBootDeviceForm &
  401. MPI2_BIOSPAGE2_FORM_MASK),
  402. &ioc->bios_pg2.RequestedBootDevice)) {
  403. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  404. "%s: req_boot_device(0x%016llx)\n",
  405. ioc->name, __func__,
  406. (unsigned long long)sas_address));
  407. ioc->req_boot_device.device = device;
  408. ioc->req_boot_device.is_raid = is_raid;
  409. }
  410. }
  411. if (!ioc->req_alt_boot_device.device) {
  412. if (_scsih_is_boot_device(sas_address, device_name,
  413. enclosure_logical_id, slot,
  414. (ioc->bios_pg2.ReqAltBootDeviceForm &
  415. MPI2_BIOSPAGE2_FORM_MASK),
  416. &ioc->bios_pg2.RequestedAltBootDevice)) {
  417. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  418. "%s: req_alt_boot_device(0x%016llx)\n",
  419. ioc->name, __func__,
  420. (unsigned long long)sas_address));
  421. ioc->req_alt_boot_device.device = device;
  422. ioc->req_alt_boot_device.is_raid = is_raid;
  423. }
  424. }
  425. if (!ioc->current_boot_device.device) {
  426. if (_scsih_is_boot_device(sas_address, device_name,
  427. enclosure_logical_id, slot,
  428. (ioc->bios_pg2.CurrentBootDeviceForm &
  429. MPI2_BIOSPAGE2_FORM_MASK),
  430. &ioc->bios_pg2.CurrentBootDevice)) {
  431. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  432. "%s: current_boot_device(0x%016llx)\n",
  433. ioc->name, __func__,
  434. (unsigned long long)sas_address));
  435. ioc->current_boot_device.device = device;
  436. ioc->current_boot_device.is_raid = is_raid;
  437. }
  438. }
  439. }
  440. /**
  441. * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
  442. * @ioc: per adapter object
  443. * @sas_address: sas address
  444. * Context: Calling function should acquire ioc->sas_device_lock
  445. *
  446. * This searches for sas_device based on sas_address, then return sas_device
  447. * object.
  448. */
  449. struct _sas_device *
  450. mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  451. u64 sas_address)
  452. {
  453. struct _sas_device *sas_device;
  454. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  455. if (sas_device->sas_address == sas_address)
  456. return sas_device;
  457. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  458. if (sas_device->sas_address == sas_address)
  459. return sas_device;
  460. return NULL;
  461. }
  462. /**
  463. * _scsih_sas_device_find_by_handle - sas device search
  464. * @ioc: per adapter object
  465. * @handle: sas device handle (assigned by firmware)
  466. * Context: Calling function should acquire ioc->sas_device_lock
  467. *
  468. * This searches for sas_device based on sas_address, then return sas_device
  469. * object.
  470. */
  471. static struct _sas_device *
  472. _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  473. {
  474. struct _sas_device *sas_device;
  475. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  476. if (sas_device->handle == handle)
  477. return sas_device;
  478. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  479. if (sas_device->handle == handle)
  480. return sas_device;
  481. return NULL;
  482. }
  483. /**
  484. * _scsih_sas_device_remove - remove sas_device from list.
  485. * @ioc: per adapter object
  486. * @sas_device: the sas_device object
  487. * Context: This function will acquire ioc->sas_device_lock.
  488. *
  489. * Removing object and freeing associated memory from the ioc->sas_device_list.
  490. */
  491. static void
  492. _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
  493. struct _sas_device *sas_device)
  494. {
  495. unsigned long flags;
  496. if (!sas_device)
  497. return;
  498. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  499. if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  500. sas_device->sas_address)) {
  501. list_del(&sas_device->list);
  502. kfree(sas_device);
  503. }
  504. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  505. }
  506. /**
  507. * _scsih_sas_device_add - insert sas_device to the list.
  508. * @ioc: per adapter object
  509. * @sas_device: the sas_device object
  510. * Context: This function will acquire ioc->sas_device_lock.
  511. *
  512. * Adding new object to the ioc->sas_device_list.
  513. */
  514. static void
  515. _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
  516. struct _sas_device *sas_device)
  517. {
  518. unsigned long flags;
  519. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  520. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  521. sas_device->handle, (unsigned long long)sas_device->sas_address));
  522. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  523. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  524. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  525. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  526. sas_device->sas_address_parent))
  527. _scsih_sas_device_remove(ioc, sas_device);
  528. }
  529. /**
  530. * _scsih_sas_device_init_add - insert sas_device to the list.
  531. * @ioc: per adapter object
  532. * @sas_device: the sas_device object
  533. * Context: This function will acquire ioc->sas_device_lock.
  534. *
  535. * Adding new object at driver load time to the ioc->sas_device_init_list.
  536. */
  537. static void
  538. _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
  539. struct _sas_device *sas_device)
  540. {
  541. unsigned long flags;
  542. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  543. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  544. sas_device->handle, (unsigned long long)sas_device->sas_address));
  545. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  546. list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
  547. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  548. _scsih_determine_boot_device(ioc, sas_device, 0);
  549. }
  550. /**
  551. * _scsih_raid_device_find_by_id - raid device search
  552. * @ioc: per adapter object
  553. * @id: sas device target id
  554. * @channel: sas device channel
  555. * Context: Calling function should acquire ioc->raid_device_lock
  556. *
  557. * This searches for raid_device based on target id, then return raid_device
  558. * object.
  559. */
  560. static struct _raid_device *
  561. _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
  562. {
  563. struct _raid_device *raid_device, *r;
  564. r = NULL;
  565. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  566. if (raid_device->id == id && raid_device->channel == channel) {
  567. r = raid_device;
  568. goto out;
  569. }
  570. }
  571. out:
  572. return r;
  573. }
  574. /**
  575. * _scsih_raid_device_find_by_handle - raid device search
  576. * @ioc: per adapter object
  577. * @handle: sas device handle (assigned by firmware)
  578. * Context: Calling function should acquire ioc->raid_device_lock
  579. *
  580. * This searches for raid_device based on handle, then return raid_device
  581. * object.
  582. */
  583. static struct _raid_device *
  584. _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  585. {
  586. struct _raid_device *raid_device, *r;
  587. r = NULL;
  588. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  589. if (raid_device->handle != handle)
  590. continue;
  591. r = raid_device;
  592. goto out;
  593. }
  594. out:
  595. return r;
  596. }
  597. /**
  598. * _scsih_raid_device_find_by_wwid - raid device search
  599. * @ioc: per adapter object
  600. * @handle: sas device handle (assigned by firmware)
  601. * Context: Calling function should acquire ioc->raid_device_lock
  602. *
  603. * This searches for raid_device based on wwid, then return raid_device
  604. * object.
  605. */
  606. static struct _raid_device *
  607. _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
  608. {
  609. struct _raid_device *raid_device, *r;
  610. r = NULL;
  611. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  612. if (raid_device->wwid != wwid)
  613. continue;
  614. r = raid_device;
  615. goto out;
  616. }
  617. out:
  618. return r;
  619. }
  620. /**
  621. * _scsih_raid_device_add - add raid_device object
  622. * @ioc: per adapter object
  623. * @raid_device: raid_device object
  624. *
  625. * This is added to the raid_device_list link list.
  626. */
  627. static void
  628. _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
  629. struct _raid_device *raid_device)
  630. {
  631. unsigned long flags;
  632. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  633. "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  634. raid_device->handle, (unsigned long long)raid_device->wwid));
  635. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  636. list_add_tail(&raid_device->list, &ioc->raid_device_list);
  637. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  638. }
  639. /**
  640. * _scsih_raid_device_remove - delete raid_device object
  641. * @ioc: per adapter object
  642. * @raid_device: raid_device object
  643. *
  644. * This is removed from the raid_device_list link list.
  645. */
  646. static void
  647. _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
  648. struct _raid_device *raid_device)
  649. {
  650. unsigned long flags;
  651. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  652. list_del(&raid_device->list);
  653. memset(raid_device, 0, sizeof(struct _raid_device));
  654. kfree(raid_device);
  655. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  656. }
  657. /**
  658. * mpt2sas_scsih_expander_find_by_handle - expander device search
  659. * @ioc: per adapter object
  660. * @handle: expander handle (assigned by firmware)
  661. * Context: Calling function should acquire ioc->sas_device_lock
  662. *
  663. * This searches for expander device based on handle, then returns the
  664. * sas_node object.
  665. */
  666. struct _sas_node *
  667. mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  668. {
  669. struct _sas_node *sas_expander, *r;
  670. r = NULL;
  671. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  672. if (sas_expander->handle != handle)
  673. continue;
  674. r = sas_expander;
  675. goto out;
  676. }
  677. out:
  678. return r;
  679. }
  680. /**
  681. * mpt2sas_scsih_expander_find_by_sas_address - expander device search
  682. * @ioc: per adapter object
  683. * @sas_address: sas address
  684. * Context: Calling function should acquire ioc->sas_node_lock.
  685. *
  686. * This searches for expander device based on sas_address, then returns the
  687. * sas_node object.
  688. */
  689. struct _sas_node *
  690. mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  691. u64 sas_address)
  692. {
  693. struct _sas_node *sas_expander, *r;
  694. r = NULL;
  695. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  696. if (sas_expander->sas_address != sas_address)
  697. continue;
  698. r = sas_expander;
  699. goto out;
  700. }
  701. out:
  702. return r;
  703. }
  704. /**
  705. * _scsih_expander_node_add - insert expander device to the list.
  706. * @ioc: per adapter object
  707. * @sas_expander: the sas_device object
  708. * Context: This function will acquire ioc->sas_node_lock.
  709. *
  710. * Adding new object to the ioc->sas_expander_list.
  711. *
  712. * Return nothing.
  713. */
  714. static void
  715. _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
  716. struct _sas_node *sas_expander)
  717. {
  718. unsigned long flags;
  719. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  720. list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
  721. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  722. }
  723. /**
  724. * _scsih_is_end_device - determines if device is an end device
  725. * @device_info: bitfield providing information about the device.
  726. * Context: none
  727. *
  728. * Returns 1 if end device.
  729. */
  730. static int
  731. _scsih_is_end_device(u32 device_info)
  732. {
  733. if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
  734. ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
  735. (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
  736. (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
  737. return 1;
  738. else
  739. return 0;
  740. }
  741. /**
  742. * mptscsih_get_scsi_lookup - returns scmd entry
  743. * @ioc: per adapter object
  744. * @smid: system request message index
  745. *
  746. * Returns the smid stored scmd pointer.
  747. */
  748. static struct scsi_cmnd *
  749. _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  750. {
  751. return ioc->scsi_lookup[smid - 1].scmd;
  752. }
  753. /**
  754. * _scsih_scsi_lookup_find_by_scmd - scmd lookup
  755. * @ioc: per adapter object
  756. * @smid: system request message index
  757. * @scmd: pointer to scsi command object
  758. * Context: This function will acquire ioc->scsi_lookup_lock.
  759. *
  760. * This will search for a scmd pointer in the scsi_lookup array,
  761. * returning the revelent smid. A returned value of zero means invalid.
  762. */
  763. static u16
  764. _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
  765. *scmd)
  766. {
  767. u16 smid;
  768. unsigned long flags;
  769. int i;
  770. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  771. smid = 0;
  772. for (i = 0; i < ioc->scsiio_depth; i++) {
  773. if (ioc->scsi_lookup[i].scmd == scmd) {
  774. smid = ioc->scsi_lookup[i].smid;
  775. goto out;
  776. }
  777. }
  778. out:
  779. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  780. return smid;
  781. }
  782. /**
  783. * _scsih_scsi_lookup_find_by_target - search for matching channel:id
  784. * @ioc: per adapter object
  785. * @id: target id
  786. * @channel: channel
  787. * Context: This function will acquire ioc->scsi_lookup_lock.
  788. *
  789. * This will search for a matching channel:id in the scsi_lookup array,
  790. * returning 1 if found.
  791. */
  792. static u8
  793. _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
  794. int channel)
  795. {
  796. u8 found;
  797. unsigned long flags;
  798. int i;
  799. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  800. found = 0;
  801. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  802. if (ioc->scsi_lookup[i].scmd &&
  803. (ioc->scsi_lookup[i].scmd->device->id == id &&
  804. ioc->scsi_lookup[i].scmd->device->channel == channel)) {
  805. found = 1;
  806. goto out;
  807. }
  808. }
  809. out:
  810. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  811. return found;
  812. }
  813. /**
  814. * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
  815. * @ioc: per adapter object
  816. * @id: target id
  817. * @lun: lun number
  818. * @channel: channel
  819. * Context: This function will acquire ioc->scsi_lookup_lock.
  820. *
  821. * This will search for a matching channel:id:lun in the scsi_lookup array,
  822. * returning 1 if found.
  823. */
  824. static u8
  825. _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
  826. unsigned int lun, int channel)
  827. {
  828. u8 found;
  829. unsigned long flags;
  830. int i;
  831. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  832. found = 0;
  833. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  834. if (ioc->scsi_lookup[i].scmd &&
  835. (ioc->scsi_lookup[i].scmd->device->id == id &&
  836. ioc->scsi_lookup[i].scmd->device->channel == channel &&
  837. ioc->scsi_lookup[i].scmd->device->lun == lun)) {
  838. found = 1;
  839. goto out;
  840. }
  841. }
  842. out:
  843. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  844. return found;
  845. }
  846. /**
  847. * _scsih_get_chain_buffer_tracker - obtain chain tracker
  848. * @ioc: per adapter object
  849. * @smid: smid associated to an IO request
  850. *
  851. * Returns chain tracker(from ioc->free_chain_list)
  852. */
  853. static struct chain_tracker *
  854. _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  855. {
  856. struct chain_tracker *chain_req;
  857. unsigned long flags;
  858. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  859. if (list_empty(&ioc->free_chain_list)) {
  860. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  861. printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
  862. ioc->name);
  863. return NULL;
  864. }
  865. chain_req = list_entry(ioc->free_chain_list.next,
  866. struct chain_tracker, tracker_list);
  867. list_del_init(&chain_req->tracker_list);
  868. list_add_tail(&chain_req->tracker_list,
  869. &ioc->scsi_lookup[smid - 1].chain_list);
  870. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  871. return chain_req;
  872. }
  873. /**
  874. * _scsih_build_scatter_gather - main sg creation routine
  875. * @ioc: per adapter object
  876. * @scmd: scsi command
  877. * @smid: system request message index
  878. * Context: none.
  879. *
  880. * The main routine that builds scatter gather table from a given
  881. * scsi request sent via the .queuecommand main handler.
  882. *
  883. * Returns 0 success, anything else error
  884. */
  885. static int
  886. _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
  887. struct scsi_cmnd *scmd, u16 smid)
  888. {
  889. Mpi2SCSIIORequest_t *mpi_request;
  890. dma_addr_t chain_dma;
  891. struct scatterlist *sg_scmd;
  892. void *sg_local, *chain;
  893. u32 chain_offset;
  894. u32 chain_length;
  895. u32 chain_flags;
  896. int sges_left;
  897. u32 sges_in_segment;
  898. u32 sgl_flags;
  899. u32 sgl_flags_last_element;
  900. u32 sgl_flags_end_buffer;
  901. struct chain_tracker *chain_req;
  902. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  903. /* init scatter gather flags */
  904. sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
  905. if (scmd->sc_data_direction == DMA_TO_DEVICE)
  906. sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
  907. sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
  908. << MPI2_SGE_FLAGS_SHIFT;
  909. sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
  910. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
  911. << MPI2_SGE_FLAGS_SHIFT;
  912. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  913. sg_scmd = scsi_sglist(scmd);
  914. sges_left = scsi_dma_map(scmd);
  915. if (sges_left < 0) {
  916. sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
  917. " failed: request for %d bytes!\n", scsi_bufflen(scmd));
  918. return -ENOMEM;
  919. }
  920. sg_local = &mpi_request->SGL;
  921. sges_in_segment = ioc->max_sges_in_main_message;
  922. if (sges_left <= sges_in_segment)
  923. goto fill_in_last_segment;
  924. mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
  925. (sges_in_segment * ioc->sge_size))/4;
  926. /* fill in main message segment when there is a chain following */
  927. while (sges_in_segment) {
  928. if (sges_in_segment == 1)
  929. ioc->base_add_sg_single(sg_local,
  930. sgl_flags_last_element | sg_dma_len(sg_scmd),
  931. sg_dma_address(sg_scmd));
  932. else
  933. ioc->base_add_sg_single(sg_local, sgl_flags |
  934. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  935. sg_scmd = sg_next(sg_scmd);
  936. sg_local += ioc->sge_size;
  937. sges_left--;
  938. sges_in_segment--;
  939. }
  940. /* initializing the chain flags and pointers */
  941. chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
  942. chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
  943. if (!chain_req)
  944. return -1;
  945. chain = chain_req->chain_buffer;
  946. chain_dma = chain_req->chain_buffer_dma;
  947. do {
  948. sges_in_segment = (sges_left <=
  949. ioc->max_sges_in_chain_message) ? sges_left :
  950. ioc->max_sges_in_chain_message;
  951. chain_offset = (sges_left == sges_in_segment) ?
  952. 0 : (sges_in_segment * ioc->sge_size)/4;
  953. chain_length = sges_in_segment * ioc->sge_size;
  954. if (chain_offset) {
  955. chain_offset = chain_offset <<
  956. MPI2_SGE_CHAIN_OFFSET_SHIFT;
  957. chain_length += ioc->sge_size;
  958. }
  959. ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
  960. chain_length, chain_dma);
  961. sg_local = chain;
  962. if (!chain_offset)
  963. goto fill_in_last_segment;
  964. /* fill in chain segments */
  965. while (sges_in_segment) {
  966. if (sges_in_segment == 1)
  967. ioc->base_add_sg_single(sg_local,
  968. sgl_flags_last_element |
  969. sg_dma_len(sg_scmd),
  970. sg_dma_address(sg_scmd));
  971. else
  972. ioc->base_add_sg_single(sg_local, sgl_flags |
  973. sg_dma_len(sg_scmd),
  974. sg_dma_address(sg_scmd));
  975. sg_scmd = sg_next(sg_scmd);
  976. sg_local += ioc->sge_size;
  977. sges_left--;
  978. sges_in_segment--;
  979. }
  980. chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
  981. if (!chain_req)
  982. return -1;
  983. chain = chain_req->chain_buffer;
  984. chain_dma = chain_req->chain_buffer_dma;
  985. } while (1);
  986. fill_in_last_segment:
  987. /* fill the last segment */
  988. while (sges_left) {
  989. if (sges_left == 1)
  990. ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
  991. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  992. else
  993. ioc->base_add_sg_single(sg_local, sgl_flags |
  994. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  995. sg_scmd = sg_next(sg_scmd);
  996. sg_local += ioc->sge_size;
  997. sges_left--;
  998. }
  999. return 0;
  1000. }
  1001. /**
  1002. * _scsih_adjust_queue_depth - setting device queue depth
  1003. * @sdev: scsi device struct
  1004. * @qdepth: requested queue depth
  1005. *
  1006. *
  1007. * Returns nothing
  1008. */
  1009. static void
  1010. _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
  1011. {
  1012. struct Scsi_Host *shost = sdev->host;
  1013. int max_depth;
  1014. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1015. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1016. struct MPT2SAS_TARGET *sas_target_priv_data;
  1017. struct _sas_device *sas_device;
  1018. unsigned long flags;
  1019. max_depth = shost->can_queue;
  1020. /* limit max device queue for SATA to 32 */
  1021. sas_device_priv_data = sdev->hostdata;
  1022. if (!sas_device_priv_data)
  1023. goto not_sata;
  1024. sas_target_priv_data = sas_device_priv_data->sas_target;
  1025. if (!sas_target_priv_data)
  1026. goto not_sata;
  1027. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
  1028. goto not_sata;
  1029. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1030. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1031. sas_device_priv_data->sas_target->sas_address);
  1032. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1033. if (sas_device && sas_device->device_info &
  1034. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1035. max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
  1036. not_sata:
  1037. if (!sdev->tagged_supported)
  1038. max_depth = 1;
  1039. if (qdepth > max_depth)
  1040. qdepth = max_depth;
  1041. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1042. }
  1043. /**
  1044. * _scsih_change_queue_depth - setting device queue depth
  1045. * @sdev: scsi device struct
  1046. * @qdepth: requested queue depth
  1047. * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
  1048. * (see include/scsi/scsi_host.h for definition)
  1049. *
  1050. * Returns queue depth.
  1051. */
  1052. static int
  1053. _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1054. {
  1055. if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
  1056. _scsih_adjust_queue_depth(sdev, qdepth);
  1057. else if (reason == SCSI_QDEPTH_QFULL)
  1058. scsi_track_queue_full(sdev, qdepth);
  1059. else
  1060. return -EOPNOTSUPP;
  1061. if (sdev->inquiry_len > 7)
  1062. sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
  1063. "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
  1064. sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
  1065. sdev->ordered_tags, sdev->scsi_level,
  1066. (sdev->inquiry[7] & 2) >> 1);
  1067. return sdev->queue_depth;
  1068. }
  1069. /**
  1070. * _scsih_change_queue_type - changing device queue tag type
  1071. * @sdev: scsi device struct
  1072. * @tag_type: requested tag type
  1073. *
  1074. * Returns queue tag type.
  1075. */
  1076. static int
  1077. _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
  1078. {
  1079. if (sdev->tagged_supported) {
  1080. scsi_set_tag_type(sdev, tag_type);
  1081. if (tag_type)
  1082. scsi_activate_tcq(sdev, sdev->queue_depth);
  1083. else
  1084. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1085. } else
  1086. tag_type = 0;
  1087. return tag_type;
  1088. }
  1089. /**
  1090. * _scsih_target_alloc - target add routine
  1091. * @starget: scsi target struct
  1092. *
  1093. * Returns 0 if ok. Any other return is assumed to be an error and
  1094. * the device is ignored.
  1095. */
  1096. static int
  1097. _scsih_target_alloc(struct scsi_target *starget)
  1098. {
  1099. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1100. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1101. struct MPT2SAS_TARGET *sas_target_priv_data;
  1102. struct _sas_device *sas_device;
  1103. struct _raid_device *raid_device;
  1104. unsigned long flags;
  1105. struct sas_rphy *rphy;
  1106. sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
  1107. if (!sas_target_priv_data)
  1108. return -ENOMEM;
  1109. starget->hostdata = sas_target_priv_data;
  1110. sas_target_priv_data->starget = starget;
  1111. sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
  1112. /* RAID volumes */
  1113. if (starget->channel == RAID_CHANNEL) {
  1114. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1115. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1116. starget->channel);
  1117. if (raid_device) {
  1118. sas_target_priv_data->handle = raid_device->handle;
  1119. sas_target_priv_data->sas_address = raid_device->wwid;
  1120. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
  1121. raid_device->starget = starget;
  1122. }
  1123. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1124. return 0;
  1125. }
  1126. /* sas/sata devices */
  1127. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1128. rphy = dev_to_rphy(starget->dev.parent);
  1129. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1130. rphy->identify.sas_address);
  1131. if (sas_device) {
  1132. sas_target_priv_data->handle = sas_device->handle;
  1133. sas_target_priv_data->sas_address = sas_device->sas_address;
  1134. sas_device->starget = starget;
  1135. sas_device->id = starget->id;
  1136. sas_device->channel = starget->channel;
  1137. if (test_bit(sas_device->handle, ioc->pd_handles))
  1138. sas_target_priv_data->flags |=
  1139. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1140. }
  1141. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1142. return 0;
  1143. }
  1144. /**
  1145. * _scsih_target_destroy - target destroy routine
  1146. * @starget: scsi target struct
  1147. *
  1148. * Returns nothing.
  1149. */
  1150. static void
  1151. _scsih_target_destroy(struct scsi_target *starget)
  1152. {
  1153. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1154. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1155. struct MPT2SAS_TARGET *sas_target_priv_data;
  1156. struct _sas_device *sas_device;
  1157. struct _raid_device *raid_device;
  1158. unsigned long flags;
  1159. struct sas_rphy *rphy;
  1160. sas_target_priv_data = starget->hostdata;
  1161. if (!sas_target_priv_data)
  1162. return;
  1163. if (starget->channel == RAID_CHANNEL) {
  1164. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1165. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1166. starget->channel);
  1167. if (raid_device) {
  1168. raid_device->starget = NULL;
  1169. raid_device->sdev = NULL;
  1170. }
  1171. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1172. goto out;
  1173. }
  1174. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1175. rphy = dev_to_rphy(starget->dev.parent);
  1176. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1177. rphy->identify.sas_address);
  1178. if (sas_device && (sas_device->starget == starget) &&
  1179. (sas_device->id == starget->id) &&
  1180. (sas_device->channel == starget->channel))
  1181. sas_device->starget = NULL;
  1182. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1183. out:
  1184. kfree(sas_target_priv_data);
  1185. starget->hostdata = NULL;
  1186. }
  1187. /**
  1188. * _scsih_slave_alloc - device add routine
  1189. * @sdev: scsi device struct
  1190. *
  1191. * Returns 0 if ok. Any other return is assumed to be an error and
  1192. * the device is ignored.
  1193. */
  1194. static int
  1195. _scsih_slave_alloc(struct scsi_device *sdev)
  1196. {
  1197. struct Scsi_Host *shost;
  1198. struct MPT2SAS_ADAPTER *ioc;
  1199. struct MPT2SAS_TARGET *sas_target_priv_data;
  1200. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1201. struct scsi_target *starget;
  1202. struct _raid_device *raid_device;
  1203. unsigned long flags;
  1204. sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
  1205. if (!sas_device_priv_data)
  1206. return -ENOMEM;
  1207. sas_device_priv_data->lun = sdev->lun;
  1208. sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
  1209. starget = scsi_target(sdev);
  1210. sas_target_priv_data = starget->hostdata;
  1211. sas_target_priv_data->num_luns++;
  1212. sas_device_priv_data->sas_target = sas_target_priv_data;
  1213. sdev->hostdata = sas_device_priv_data;
  1214. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
  1215. sdev->no_uld_attach = 1;
  1216. shost = dev_to_shost(&starget->dev);
  1217. ioc = shost_priv(shost);
  1218. if (starget->channel == RAID_CHANNEL) {
  1219. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1220. raid_device = _scsih_raid_device_find_by_id(ioc,
  1221. starget->id, starget->channel);
  1222. if (raid_device)
  1223. raid_device->sdev = sdev; /* raid is single lun */
  1224. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1225. }
  1226. return 0;
  1227. }
  1228. /**
  1229. * _scsih_slave_destroy - device destroy routine
  1230. * @sdev: scsi device struct
  1231. *
  1232. * Returns nothing.
  1233. */
  1234. static void
  1235. _scsih_slave_destroy(struct scsi_device *sdev)
  1236. {
  1237. struct MPT2SAS_TARGET *sas_target_priv_data;
  1238. struct scsi_target *starget;
  1239. if (!sdev->hostdata)
  1240. return;
  1241. starget = scsi_target(sdev);
  1242. sas_target_priv_data = starget->hostdata;
  1243. sas_target_priv_data->num_luns--;
  1244. kfree(sdev->hostdata);
  1245. sdev->hostdata = NULL;
  1246. }
  1247. /**
  1248. * _scsih_display_sata_capabilities - sata capabilities
  1249. * @ioc: per adapter object
  1250. * @sas_device: the sas_device object
  1251. * @sdev: scsi device struct
  1252. */
  1253. static void
  1254. _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1255. struct _sas_device *sas_device, struct scsi_device *sdev)
  1256. {
  1257. Mpi2ConfigReply_t mpi_reply;
  1258. Mpi2SasDevicePage0_t sas_device_pg0;
  1259. u32 ioc_status;
  1260. u16 flags;
  1261. u32 device_info;
  1262. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  1263. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
  1264. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1265. ioc->name, __FILE__, __LINE__, __func__);
  1266. return;
  1267. }
  1268. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1269. MPI2_IOCSTATUS_MASK;
  1270. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1271. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1272. ioc->name, __FILE__, __LINE__, __func__);
  1273. return;
  1274. }
  1275. flags = le16_to_cpu(sas_device_pg0.Flags);
  1276. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  1277. sdev_printk(KERN_INFO, sdev,
  1278. "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
  1279. "sw_preserve(%s)\n",
  1280. (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
  1281. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
  1282. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
  1283. "n",
  1284. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
  1285. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
  1286. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
  1287. }
  1288. /**
  1289. * _scsih_is_raid - return boolean indicating device is raid volume
  1290. * @dev the device struct object
  1291. */
  1292. static int
  1293. _scsih_is_raid(struct device *dev)
  1294. {
  1295. struct scsi_device *sdev = to_scsi_device(dev);
  1296. return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
  1297. }
  1298. /**
  1299. * _scsih_get_resync - get raid volume resync percent complete
  1300. * @dev the device struct object
  1301. */
  1302. static void
  1303. _scsih_get_resync(struct device *dev)
  1304. {
  1305. struct scsi_device *sdev = to_scsi_device(dev);
  1306. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1307. static struct _raid_device *raid_device;
  1308. unsigned long flags;
  1309. Mpi2RaidVolPage0_t vol_pg0;
  1310. Mpi2ConfigReply_t mpi_reply;
  1311. u32 volume_status_flags;
  1312. u8 percent_complete = 0;
  1313. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1314. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1315. sdev->channel);
  1316. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1317. if (!raid_device)
  1318. goto out;
  1319. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1320. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
  1321. sizeof(Mpi2RaidVolPage0_t))) {
  1322. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1323. ioc->name, __FILE__, __LINE__, __func__);
  1324. goto out;
  1325. }
  1326. volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1327. if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
  1328. percent_complete = raid_device->percent_complete;
  1329. out:
  1330. raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
  1331. }
  1332. /**
  1333. * _scsih_get_state - get raid volume level
  1334. * @dev the device struct object
  1335. */
  1336. static void
  1337. _scsih_get_state(struct device *dev)
  1338. {
  1339. struct scsi_device *sdev = to_scsi_device(dev);
  1340. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1341. static struct _raid_device *raid_device;
  1342. unsigned long flags;
  1343. Mpi2RaidVolPage0_t vol_pg0;
  1344. Mpi2ConfigReply_t mpi_reply;
  1345. u32 volstate;
  1346. enum raid_state state = RAID_STATE_UNKNOWN;
  1347. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1348. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1349. sdev->channel);
  1350. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1351. if (!raid_device)
  1352. goto out;
  1353. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1354. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
  1355. sizeof(Mpi2RaidVolPage0_t))) {
  1356. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1357. ioc->name, __FILE__, __LINE__, __func__);
  1358. goto out;
  1359. }
  1360. volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1361. if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
  1362. state = RAID_STATE_RESYNCING;
  1363. goto out;
  1364. }
  1365. switch (vol_pg0.VolumeState) {
  1366. case MPI2_RAID_VOL_STATE_OPTIMAL:
  1367. case MPI2_RAID_VOL_STATE_ONLINE:
  1368. state = RAID_STATE_ACTIVE;
  1369. break;
  1370. case MPI2_RAID_VOL_STATE_DEGRADED:
  1371. state = RAID_STATE_DEGRADED;
  1372. break;
  1373. case MPI2_RAID_VOL_STATE_FAILED:
  1374. case MPI2_RAID_VOL_STATE_MISSING:
  1375. state = RAID_STATE_OFFLINE;
  1376. break;
  1377. }
  1378. out:
  1379. raid_set_state(mpt2sas_raid_template, dev, state);
  1380. }
  1381. /**
  1382. * _scsih_set_level - set raid level
  1383. * @sdev: scsi device struct
  1384. * @raid_device: raid_device object
  1385. */
  1386. static void
  1387. _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
  1388. {
  1389. enum raid_level level = RAID_LEVEL_UNKNOWN;
  1390. switch (raid_device->volume_type) {
  1391. case MPI2_RAID_VOL_TYPE_RAID0:
  1392. level = RAID_LEVEL_0;
  1393. break;
  1394. case MPI2_RAID_VOL_TYPE_RAID10:
  1395. level = RAID_LEVEL_10;
  1396. break;
  1397. case MPI2_RAID_VOL_TYPE_RAID1E:
  1398. level = RAID_LEVEL_1E;
  1399. break;
  1400. case MPI2_RAID_VOL_TYPE_RAID1:
  1401. level = RAID_LEVEL_1;
  1402. break;
  1403. }
  1404. raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
  1405. }
  1406. /**
  1407. * _scsih_get_volume_capabilities - volume capabilities
  1408. * @ioc: per adapter object
  1409. * @sas_device: the raid_device object
  1410. */
  1411. static void
  1412. _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1413. struct _raid_device *raid_device)
  1414. {
  1415. Mpi2RaidVolPage0_t *vol_pg0;
  1416. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1417. Mpi2SasDevicePage0_t sas_device_pg0;
  1418. Mpi2ConfigReply_t mpi_reply;
  1419. u16 sz;
  1420. u8 num_pds;
  1421. if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
  1422. &num_pds)) || !num_pds) {
  1423. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1424. ioc->name, __FILE__, __LINE__, __func__);
  1425. return;
  1426. }
  1427. raid_device->num_pds = num_pds;
  1428. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1429. sizeof(Mpi2RaidVol0PhysDisk_t));
  1430. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1431. if (!vol_pg0) {
  1432. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1433. ioc->name, __FILE__, __LINE__, __func__);
  1434. return;
  1435. }
  1436. if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1437. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1438. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1439. ioc->name, __FILE__, __LINE__, __func__);
  1440. kfree(vol_pg0);
  1441. return;
  1442. }
  1443. raid_device->volume_type = vol_pg0->VolumeType;
  1444. /* figure out what the underlying devices are by
  1445. * obtaining the device_info bits for the 1st device
  1446. */
  1447. if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1448. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1449. vol_pg0->PhysDisk[0].PhysDiskNum))) {
  1450. if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  1451. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  1452. le16_to_cpu(pd_pg0.DevHandle)))) {
  1453. raid_device->device_info =
  1454. le32_to_cpu(sas_device_pg0.DeviceInfo);
  1455. }
  1456. }
  1457. kfree(vol_pg0);
  1458. }
  1459. /**
  1460. * _scsih_enable_tlr - setting TLR flags
  1461. * @ioc: per adapter object
  1462. * @sdev: scsi device struct
  1463. *
  1464. * Enabling Transaction Layer Retries for tape devices when
  1465. * vpd page 0x90 is present
  1466. *
  1467. */
  1468. static void
  1469. _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
  1470. {
  1471. /* only for TAPE */
  1472. if (sdev->type != TYPE_TAPE)
  1473. return;
  1474. if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
  1475. return;
  1476. sas_enable_tlr(sdev);
  1477. sdev_printk(KERN_INFO, sdev, "TLR %s\n",
  1478. sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
  1479. return;
  1480. }
  1481. /**
  1482. * _scsih_slave_configure - device configure routine.
  1483. * @sdev: scsi device struct
  1484. *
  1485. * Returns 0 if ok. Any other return is assumed to be an error and
  1486. * the device is ignored.
  1487. */
  1488. static int
  1489. _scsih_slave_configure(struct scsi_device *sdev)
  1490. {
  1491. struct Scsi_Host *shost = sdev->host;
  1492. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1493. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1494. struct MPT2SAS_TARGET *sas_target_priv_data;
  1495. struct _sas_device *sas_device;
  1496. struct _raid_device *raid_device;
  1497. unsigned long flags;
  1498. int qdepth;
  1499. u8 ssp_target = 0;
  1500. char *ds = "";
  1501. char *r_level = "";
  1502. qdepth = 1;
  1503. sas_device_priv_data = sdev->hostdata;
  1504. sas_device_priv_data->configured_lun = 1;
  1505. sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
  1506. sas_target_priv_data = sas_device_priv_data->sas_target;
  1507. /* raid volume handling */
  1508. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
  1509. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1510. raid_device = _scsih_raid_device_find_by_handle(ioc,
  1511. sas_target_priv_data->handle);
  1512. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1513. if (!raid_device) {
  1514. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1515. ioc->name, __FILE__, __LINE__, __func__);
  1516. return 0;
  1517. }
  1518. _scsih_get_volume_capabilities(ioc, raid_device);
  1519. /* RAID Queue Depth Support
  1520. * IS volume = underlying qdepth of drive type, either
  1521. * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
  1522. * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
  1523. */
  1524. if (raid_device->device_info &
  1525. MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1526. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1527. ds = "SSP";
  1528. } else {
  1529. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1530. if (raid_device->device_info &
  1531. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1532. ds = "SATA";
  1533. else
  1534. ds = "STP";
  1535. }
  1536. switch (raid_device->volume_type) {
  1537. case MPI2_RAID_VOL_TYPE_RAID0:
  1538. r_level = "RAID0";
  1539. break;
  1540. case MPI2_RAID_VOL_TYPE_RAID1E:
  1541. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1542. if (ioc->manu_pg10.OEMIdentifier &&
  1543. (ioc->manu_pg10.GenericFlags0 &
  1544. MFG10_GF0_R10_DISPLAY) &&
  1545. !(raid_device->num_pds % 2))
  1546. r_level = "RAID10";
  1547. else
  1548. r_level = "RAID1E";
  1549. break;
  1550. case MPI2_RAID_VOL_TYPE_RAID1:
  1551. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1552. r_level = "RAID1";
  1553. break;
  1554. case MPI2_RAID_VOL_TYPE_RAID10:
  1555. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1556. r_level = "RAID10";
  1557. break;
  1558. case MPI2_RAID_VOL_TYPE_UNKNOWN:
  1559. default:
  1560. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1561. r_level = "RAIDX";
  1562. break;
  1563. }
  1564. sdev_printk(KERN_INFO, sdev, "%s: "
  1565. "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
  1566. r_level, raid_device->handle,
  1567. (unsigned long long)raid_device->wwid,
  1568. raid_device->num_pds, ds);
  1569. _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
  1570. /* raid transport support */
  1571. _scsih_set_level(sdev, raid_device);
  1572. return 0;
  1573. }
  1574. /* non-raid handling */
  1575. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1576. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1577. sas_device_priv_data->sas_target->sas_address);
  1578. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1579. if (sas_device) {
  1580. if (sas_target_priv_data->flags &
  1581. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1582. mpt2sas_config_get_volume_handle(ioc,
  1583. sas_device->handle, &sas_device->volume_handle);
  1584. mpt2sas_config_get_volume_wwid(ioc,
  1585. sas_device->volume_handle,
  1586. &sas_device->volume_wwid);
  1587. }
  1588. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1589. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1590. ssp_target = 1;
  1591. ds = "SSP";
  1592. } else {
  1593. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1594. if (sas_device->device_info &
  1595. MPI2_SAS_DEVICE_INFO_STP_TARGET)
  1596. ds = "STP";
  1597. else if (sas_device->device_info &
  1598. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1599. ds = "SATA";
  1600. }
  1601. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
  1602. "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
  1603. ds, sas_device->handle,
  1604. (unsigned long long)sas_device->sas_address,
  1605. sas_device->phy,
  1606. (unsigned long long)sas_device->device_name);
  1607. sdev_printk(KERN_INFO, sdev, "%s: "
  1608. "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
  1609. (unsigned long long) sas_device->enclosure_logical_id,
  1610. sas_device->slot);
  1611. if (!ssp_target)
  1612. _scsih_display_sata_capabilities(ioc, sas_device, sdev);
  1613. }
  1614. _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
  1615. if (ssp_target) {
  1616. sas_read_port_mode_page(sdev);
  1617. _scsih_enable_tlr(ioc, sdev);
  1618. }
  1619. return 0;
  1620. }
  1621. /**
  1622. * _scsih_bios_param - fetch head, sector, cylinder info for a disk
  1623. * @sdev: scsi device struct
  1624. * @bdev: pointer to block device context
  1625. * @capacity: device size (in 512 byte sectors)
  1626. * @params: three element array to place output:
  1627. * params[0] number of heads (max 255)
  1628. * params[1] number of sectors (max 63)
  1629. * params[2] number of cylinders
  1630. *
  1631. * Return nothing.
  1632. */
  1633. static int
  1634. _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  1635. sector_t capacity, int params[])
  1636. {
  1637. int heads;
  1638. int sectors;
  1639. sector_t cylinders;
  1640. ulong dummy;
  1641. heads = 64;
  1642. sectors = 32;
  1643. dummy = heads * sectors;
  1644. cylinders = capacity;
  1645. sector_div(cylinders, dummy);
  1646. /*
  1647. * Handle extended translation size for logical drives
  1648. * > 1Gb
  1649. */
  1650. if ((ulong)capacity >= 0x200000) {
  1651. heads = 255;
  1652. sectors = 63;
  1653. dummy = heads * sectors;
  1654. cylinders = capacity;
  1655. sector_div(cylinders, dummy);
  1656. }
  1657. /* return result */
  1658. params[0] = heads;
  1659. params[1] = sectors;
  1660. params[2] = cylinders;
  1661. return 0;
  1662. }
  1663. /**
  1664. * _scsih_response_code - translation of device response code
  1665. * @ioc: per adapter object
  1666. * @response_code: response code returned by the device
  1667. *
  1668. * Return nothing.
  1669. */
  1670. static void
  1671. _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
  1672. {
  1673. char *desc;
  1674. switch (response_code) {
  1675. case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
  1676. desc = "task management request completed";
  1677. break;
  1678. case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
  1679. desc = "invalid frame";
  1680. break;
  1681. case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1682. desc = "task management request not supported";
  1683. break;
  1684. case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
  1685. desc = "task management request failed";
  1686. break;
  1687. case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1688. desc = "task management request succeeded";
  1689. break;
  1690. case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1691. desc = "invalid lun";
  1692. break;
  1693. case 0xA:
  1694. desc = "overlapped tag attempted";
  1695. break;
  1696. case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1697. desc = "task queued, however not sent to target";
  1698. break;
  1699. default:
  1700. desc = "unknown";
  1701. break;
  1702. }
  1703. printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
  1704. ioc->name, response_code, desc);
  1705. }
  1706. /**
  1707. * _scsih_tm_done - tm completion routine
  1708. * @ioc: per adapter object
  1709. * @smid: system request message index
  1710. * @msix_index: MSIX table index supplied by the OS
  1711. * @reply: reply message frame(lower 32bit addr)
  1712. * Context: none.
  1713. *
  1714. * The callback handler when using scsih_issue_tm.
  1715. *
  1716. * Return 1 meaning mf should be freed from _base_interrupt
  1717. * 0 means the mf is freed from this function.
  1718. */
  1719. static u8
  1720. _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  1721. {
  1722. MPI2DefaultReply_t *mpi_reply;
  1723. if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
  1724. return 1;
  1725. if (ioc->tm_cmds.smid != smid)
  1726. return 1;
  1727. ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
  1728. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  1729. if (mpi_reply) {
  1730. memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  1731. ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
  1732. }
  1733. ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
  1734. complete(&ioc->tm_cmds.done);
  1735. return 1;
  1736. }
  1737. /**
  1738. * mpt2sas_scsih_set_tm_flag - set per target tm_busy
  1739. * @ioc: per adapter object
  1740. * @handle: device handle
  1741. *
  1742. * During taskmangement request, we need to freeze the device queue.
  1743. */
  1744. void
  1745. mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1746. {
  1747. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1748. struct scsi_device *sdev;
  1749. u8 skip = 0;
  1750. shost_for_each_device(sdev, ioc->shost) {
  1751. if (skip)
  1752. continue;
  1753. sas_device_priv_data = sdev->hostdata;
  1754. if (!sas_device_priv_data)
  1755. continue;
  1756. if (sas_device_priv_data->sas_target->handle == handle) {
  1757. sas_device_priv_data->sas_target->tm_busy = 1;
  1758. skip = 1;
  1759. ioc->ignore_loginfos = 1;
  1760. }
  1761. }
  1762. }
  1763. /**
  1764. * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
  1765. * @ioc: per adapter object
  1766. * @handle: device handle
  1767. *
  1768. * During taskmangement request, we need to freeze the device queue.
  1769. */
  1770. void
  1771. mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1772. {
  1773. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1774. struct scsi_device *sdev;
  1775. u8 skip = 0;
  1776. shost_for_each_device(sdev, ioc->shost) {
  1777. if (skip)
  1778. continue;
  1779. sas_device_priv_data = sdev->hostdata;
  1780. if (!sas_device_priv_data)
  1781. continue;
  1782. if (sas_device_priv_data->sas_target->handle == handle) {
  1783. sas_device_priv_data->sas_target->tm_busy = 0;
  1784. skip = 1;
  1785. ioc->ignore_loginfos = 0;
  1786. }
  1787. }
  1788. }
  1789. /**
  1790. * mpt2sas_scsih_issue_tm - main routine for sending tm requests
  1791. * @ioc: per adapter struct
  1792. * @device_handle: device handle
  1793. * @channel: the channel assigned by the OS
  1794. * @id: the id assigned by the OS
  1795. * @lun: lun number
  1796. * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  1797. * @smid_task: smid assigned to the task
  1798. * @timeout: timeout in seconds
  1799. * Context: user
  1800. *
  1801. * A generic API for sending task management requests to firmware.
  1802. *
  1803. * The callback index is set inside `ioc->tm_cb_idx`.
  1804. *
  1805. * Return SUCCESS or FAILED.
  1806. */
  1807. int
  1808. mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
  1809. uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
  1810. struct scsi_cmnd *scmd)
  1811. {
  1812. Mpi2SCSITaskManagementRequest_t *mpi_request;
  1813. Mpi2SCSITaskManagementReply_t *mpi_reply;
  1814. u16 smid = 0;
  1815. u32 ioc_state;
  1816. unsigned long timeleft;
  1817. struct scsi_cmnd *scmd_lookup;
  1818. int rc;
  1819. mutex_lock(&ioc->tm_cmds.mutex);
  1820. if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
  1821. printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
  1822. __func__, ioc->name);
  1823. rc = FAILED;
  1824. goto err_out;
  1825. }
  1826. if (ioc->shost_recovery || ioc->remove_host ||
  1827. ioc->pci_error_recovery) {
  1828. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1829. __func__, ioc->name);
  1830. rc = FAILED;
  1831. goto err_out;
  1832. }
  1833. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  1834. if (ioc_state & MPI2_DOORBELL_USED) {
  1835. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
  1836. "active!\n", ioc->name));
  1837. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1838. FORCE_BIG_HAMMER);
  1839. rc = SUCCESS;
  1840. goto err_out;
  1841. }
  1842. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  1843. mpt2sas_base_fault_info(ioc, ioc_state &
  1844. MPI2_DOORBELL_DATA_MASK);
  1845. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1846. FORCE_BIG_HAMMER);
  1847. rc = SUCCESS;
  1848. goto err_out;
  1849. }
  1850. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
  1851. if (!smid) {
  1852. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1853. ioc->name, __func__);
  1854. rc = FAILED;
  1855. goto err_out;
  1856. }
  1857. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
  1858. " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
  1859. smid_task));
  1860. ioc->tm_cmds.status = MPT2_CMD_PENDING;
  1861. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1862. ioc->tm_cmds.smid = smid;
  1863. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  1864. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  1865. mpi_request->DevHandle = cpu_to_le16(handle);
  1866. mpi_request->TaskType = type;
  1867. mpi_request->TaskMID = cpu_to_le16(smid_task);
  1868. int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
  1869. mpt2sas_scsih_set_tm_flag(ioc, handle);
  1870. init_completion(&ioc->tm_cmds.done);
  1871. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  1872. timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
  1873. if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
  1874. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1875. ioc->name, __func__);
  1876. _debug_dump_mf(mpi_request,
  1877. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  1878. if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
  1879. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1880. FORCE_BIG_HAMMER);
  1881. rc = SUCCESS;
  1882. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1883. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  1884. goto err_out;
  1885. }
  1886. }
  1887. if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
  1888. mpi_reply = ioc->tm_cmds.reply;
  1889. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
  1890. "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
  1891. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  1892. le32_to_cpu(mpi_reply->IOCLogInfo),
  1893. le32_to_cpu(mpi_reply->TerminationCount)));
  1894. if (ioc->logging_level & MPT_DEBUG_TM) {
  1895. _scsih_response_code(ioc, mpi_reply->ResponseCode);
  1896. if (mpi_reply->IOCStatus)
  1897. _debug_dump_mf(mpi_request,
  1898. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  1899. }
  1900. }
  1901. /* sanity check:
  1902. * Check to see the commands were terminated.
  1903. * This is only needed for eh callbacks, hence the scmd check.
  1904. */
  1905. rc = FAILED;
  1906. if (scmd == NULL)
  1907. goto bypass_sanity_checks;
  1908. switch (type) {
  1909. case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
  1910. scmd_lookup = _scsih_scsi_lookup_get(ioc, smid_task);
  1911. if (scmd_lookup && (scmd_lookup->serial_number ==
  1912. scmd->serial_number))
  1913. rc = FAILED;
  1914. else
  1915. rc = SUCCESS;
  1916. break;
  1917. case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
  1918. if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
  1919. rc = FAILED;
  1920. else
  1921. rc = SUCCESS;
  1922. break;
  1923. case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
  1924. if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
  1925. rc = FAILED;
  1926. else
  1927. rc = SUCCESS;
  1928. break;
  1929. }
  1930. bypass_sanity_checks:
  1931. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  1932. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1933. mutex_unlock(&ioc->tm_cmds.mutex);
  1934. return rc;
  1935. err_out:
  1936. mutex_unlock(&ioc->tm_cmds.mutex);
  1937. return rc;
  1938. }
  1939. /**
  1940. * _scsih_tm_display_info - displays info about the device
  1941. * @ioc: per adapter struct
  1942. * @scmd: pointer to scsi command object
  1943. *
  1944. * Called by task management callback handlers.
  1945. */
  1946. static void
  1947. _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
  1948. {
  1949. struct scsi_target *starget = scmd->device->sdev_target;
  1950. struct MPT2SAS_TARGET *priv_target = starget->hostdata;
  1951. struct _sas_device *sas_device = NULL;
  1952. unsigned long flags;
  1953. if (!priv_target)
  1954. return;
  1955. scsi_print_command(scmd);
  1956. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  1957. starget_printk(KERN_INFO, starget, "volume handle(0x%04x), "
  1958. "volume wwid(0x%016llx)\n",
  1959. priv_target->handle,
  1960. (unsigned long long)priv_target->sas_address);
  1961. } else {
  1962. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1963. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1964. priv_target->sas_address);
  1965. if (sas_device) {
  1966. if (priv_target->flags &
  1967. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1968. starget_printk(KERN_INFO, starget,
  1969. "volume handle(0x%04x), "
  1970. "volume wwid(0x%016llx)\n",
  1971. sas_device->volume_handle,
  1972. (unsigned long long)sas_device->volume_wwid);
  1973. }
  1974. starget_printk(KERN_INFO, starget,
  1975. "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
  1976. sas_device->handle,
  1977. (unsigned long long)sas_device->sas_address,
  1978. sas_device->phy);
  1979. starget_printk(KERN_INFO, starget,
  1980. "enclosure_logical_id(0x%016llx), slot(%d)\n",
  1981. (unsigned long long)sas_device->enclosure_logical_id,
  1982. sas_device->slot);
  1983. }
  1984. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1985. }
  1986. }
  1987. /**
  1988. * _scsih_abort - eh threads main abort routine
  1989. * @scmd: pointer to scsi command object
  1990. *
  1991. * Returns SUCCESS if command aborted else FAILED
  1992. */
  1993. static int
  1994. _scsih_abort(struct scsi_cmnd *scmd)
  1995. {
  1996. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1997. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1998. u16 smid;
  1999. u16 handle;
  2000. int r;
  2001. sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
  2002. "scmd(%p)\n", scmd);
  2003. _scsih_tm_display_info(ioc, scmd);
  2004. sas_device_priv_data = scmd->device->hostdata;
  2005. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2006. sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
  2007. "scmd(%p)\n", scmd);
  2008. scmd->result = DID_NO_CONNECT << 16;
  2009. scmd->scsi_done(scmd);
  2010. r = SUCCESS;
  2011. goto out;
  2012. }
  2013. /* search for the command */
  2014. smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
  2015. if (!smid) {
  2016. scmd->result = DID_RESET << 16;
  2017. r = SUCCESS;
  2018. goto out;
  2019. }
  2020. /* for hidden raid components and volumes this is not supported */
  2021. if (sas_device_priv_data->sas_target->flags &
  2022. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  2023. sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  2024. scmd->result = DID_RESET << 16;
  2025. r = FAILED;
  2026. goto out;
  2027. }
  2028. mpt2sas_halt_firmware(ioc);
  2029. handle = sas_device_priv_data->sas_target->handle;
  2030. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2031. scmd->device->id, scmd->device->lun,
  2032. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, scmd);
  2033. out:
  2034. sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
  2035. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2036. return r;
  2037. }
  2038. /**
  2039. * _scsih_dev_reset - eh threads main device reset routine
  2040. * @scmd: pointer to scsi command object
  2041. *
  2042. * Returns SUCCESS if command aborted else FAILED
  2043. */
  2044. static int
  2045. _scsih_dev_reset(struct scsi_cmnd *scmd)
  2046. {
  2047. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2048. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2049. struct _sas_device *sas_device;
  2050. unsigned long flags;
  2051. u16 handle;
  2052. int r;
  2053. struct scsi_target *starget = scmd->device->sdev_target;
  2054. starget_printk(KERN_INFO, starget, "attempting target reset! "
  2055. "scmd(%p)\n", scmd);
  2056. _scsih_tm_display_info(ioc, scmd);
  2057. sas_device_priv_data = scmd->device->hostdata;
  2058. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2059. starget_printk(KERN_INFO, starget, "target been deleted! "
  2060. "scmd(%p)\n", scmd);
  2061. scmd->result = DID_NO_CONNECT << 16;
  2062. scmd->scsi_done(scmd);
  2063. r = SUCCESS;
  2064. goto out;
  2065. }
  2066. /* for hidden raid components obtain the volume_handle */
  2067. handle = 0;
  2068. if (sas_device_priv_data->sas_target->flags &
  2069. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2070. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2071. sas_device = _scsih_sas_device_find_by_handle(ioc,
  2072. sas_device_priv_data->sas_target->handle);
  2073. if (sas_device)
  2074. handle = sas_device->volume_handle;
  2075. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2076. } else
  2077. handle = sas_device_priv_data->sas_target->handle;
  2078. if (!handle) {
  2079. scmd->result = DID_RESET << 16;
  2080. r = FAILED;
  2081. goto out;
  2082. }
  2083. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2084. scmd->device->id, scmd->device->lun,
  2085. MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, scmd);
  2086. out:
  2087. sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
  2088. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2089. return r;
  2090. }
  2091. /**
  2092. * _scsih_target_reset - eh threads main target reset routine
  2093. * @scmd: pointer to scsi command object
  2094. *
  2095. * Returns SUCCESS if command aborted else FAILED
  2096. */
  2097. static int
  2098. _scsih_target_reset(struct scsi_cmnd *scmd)
  2099. {
  2100. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2101. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2102. struct _sas_device *sas_device;
  2103. unsigned long flags;
  2104. u16 handle;
  2105. int r;
  2106. struct scsi_target *starget = scmd->device->sdev_target;
  2107. starget_printk(KERN_INFO, starget, "attempting target reset! "
  2108. "scmd(%p)\n", scmd);
  2109. _scsih_tm_display_info(ioc, scmd);
  2110. sas_device_priv_data = scmd->device->hostdata;
  2111. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2112. starget_printk(KERN_INFO, starget, "target been deleted! "
  2113. "scmd(%p)\n", scmd);
  2114. scmd->result = DID_NO_CONNECT << 16;
  2115. scmd->scsi_done(scmd);
  2116. r = SUCCESS;
  2117. goto out;
  2118. }
  2119. /* for hidden raid components obtain the volume_handle */
  2120. handle = 0;
  2121. if (sas_device_priv_data->sas_target->flags &
  2122. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2123. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2124. sas_device = _scsih_sas_device_find_by_handle(ioc,
  2125. sas_device_priv_data->sas_target->handle);
  2126. if (sas_device)
  2127. handle = sas_device->volume_handle;
  2128. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2129. } else
  2130. handle = sas_device_priv_data->sas_target->handle;
  2131. if (!handle) {
  2132. scmd->result = DID_RESET << 16;
  2133. r = FAILED;
  2134. goto out;
  2135. }
  2136. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2137. scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
  2138. 30, scmd);
  2139. out:
  2140. starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
  2141. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2142. return r;
  2143. }
  2144. /**
  2145. * _scsih_host_reset - eh threads main host reset routine
  2146. * @scmd: pointer to scsi command object
  2147. *
  2148. * Returns SUCCESS if command aborted else FAILED
  2149. */
  2150. static int
  2151. _scsih_host_reset(struct scsi_cmnd *scmd)
  2152. {
  2153. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2154. int r, retval;
  2155. printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
  2156. ioc->name, scmd);
  2157. scsi_print_command(scmd);
  2158. retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2159. FORCE_BIG_HAMMER);
  2160. r = (retval < 0) ? FAILED : SUCCESS;
  2161. printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
  2162. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2163. return r;
  2164. }
  2165. /**
  2166. * _scsih_fw_event_add - insert and queue up fw_event
  2167. * @ioc: per adapter object
  2168. * @fw_event: object describing the event
  2169. * Context: This function will acquire ioc->fw_event_lock.
  2170. *
  2171. * This adds the firmware event object into link list, then queues it up to
  2172. * be processed from user context.
  2173. *
  2174. * Return nothing.
  2175. */
  2176. static void
  2177. _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  2178. {
  2179. unsigned long flags;
  2180. if (ioc->firmware_event_thread == NULL)
  2181. return;
  2182. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2183. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  2184. INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
  2185. queue_delayed_work(ioc->firmware_event_thread,
  2186. &fw_event->delayed_work, 0);
  2187. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2188. }
  2189. /**
  2190. * _scsih_fw_event_free - delete fw_event
  2191. * @ioc: per adapter object
  2192. * @fw_event: object describing the event
  2193. * Context: This function will acquire ioc->fw_event_lock.
  2194. *
  2195. * This removes firmware event object from link list, frees associated memory.
  2196. *
  2197. * Return nothing.
  2198. */
  2199. static void
  2200. _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  2201. *fw_event)
  2202. {
  2203. unsigned long flags;
  2204. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2205. list_del(&fw_event->list);
  2206. kfree(fw_event->event_data);
  2207. kfree(fw_event);
  2208. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2209. }
  2210. /**
  2211. * _scsih_queue_rescan - queue a topology rescan from user context
  2212. * @ioc: per adapter object
  2213. *
  2214. * Return nothing.
  2215. */
  2216. static void
  2217. _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc)
  2218. {
  2219. struct fw_event_work *fw_event;
  2220. if (ioc->wait_for_port_enable_to_complete)
  2221. return;
  2222. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  2223. if (!fw_event)
  2224. return;
  2225. fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET;
  2226. fw_event->ioc = ioc;
  2227. _scsih_fw_event_add(ioc, fw_event);
  2228. }
  2229. /**
  2230. * _scsih_fw_event_cleanup_queue - cleanup event queue
  2231. * @ioc: per adapter object
  2232. *
  2233. * Walk the firmware event queue, either killing timers, or waiting
  2234. * for outstanding events to complete
  2235. *
  2236. * Return nothing.
  2237. */
  2238. static void
  2239. _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
  2240. {
  2241. struct fw_event_work *fw_event, *next;
  2242. if (list_empty(&ioc->fw_event_list) ||
  2243. !ioc->firmware_event_thread || in_interrupt())
  2244. return;
  2245. list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
  2246. if (cancel_delayed_work(&fw_event->delayed_work)) {
  2247. _scsih_fw_event_free(ioc, fw_event);
  2248. continue;
  2249. }
  2250. fw_event->cancel_pending_work = 1;
  2251. }
  2252. }
  2253. /**
  2254. * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
  2255. * @ioc: per adapter object
  2256. * @handle: device handle
  2257. *
  2258. * During device pull we need to appropiately set the sdev state.
  2259. */
  2260. static void
  2261. _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2262. {
  2263. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2264. struct scsi_device *sdev;
  2265. shost_for_each_device(sdev, ioc->shost) {
  2266. sas_device_priv_data = sdev->hostdata;
  2267. if (!sas_device_priv_data)
  2268. continue;
  2269. if (!sas_device_priv_data->block)
  2270. continue;
  2271. if (sas_device_priv_data->sas_target->handle == handle) {
  2272. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2273. MPT2SAS_INFO_FMT "SDEV_RUNNING: "
  2274. "handle(0x%04x)\n", ioc->name, handle));
  2275. sas_device_priv_data->block = 0;
  2276. scsi_internal_device_unblock(sdev);
  2277. }
  2278. }
  2279. }
  2280. /**
  2281. * _scsih_block_io_device - set the device state to SDEV_BLOCK
  2282. * @ioc: per adapter object
  2283. * @handle: device handle
  2284. *
  2285. * During device pull we need to appropiately set the sdev state.
  2286. */
  2287. static void
  2288. _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2289. {
  2290. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2291. struct scsi_device *sdev;
  2292. shost_for_each_device(sdev, ioc->shost) {
  2293. sas_device_priv_data = sdev->hostdata;
  2294. if (!sas_device_priv_data)
  2295. continue;
  2296. if (sas_device_priv_data->block)
  2297. continue;
  2298. if (sas_device_priv_data->sas_target->handle == handle) {
  2299. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2300. MPT2SAS_INFO_FMT "SDEV_BLOCK: "
  2301. "handle(0x%04x)\n", ioc->name, handle));
  2302. sas_device_priv_data->block = 1;
  2303. scsi_internal_device_block(sdev);
  2304. }
  2305. }
  2306. }
  2307. /**
  2308. * _scsih_block_io_to_children_attached_to_ex
  2309. * @ioc: per adapter object
  2310. * @sas_expander: the sas_device object
  2311. *
  2312. * This routine set sdev state to SDEV_BLOCK for all devices
  2313. * attached to this expander. This function called when expander is
  2314. * pulled.
  2315. */
  2316. static void
  2317. _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
  2318. struct _sas_node *sas_expander)
  2319. {
  2320. struct _sas_port *mpt2sas_port;
  2321. struct _sas_device *sas_device;
  2322. struct _sas_node *expander_sibling;
  2323. unsigned long flags;
  2324. if (!sas_expander)
  2325. return;
  2326. list_for_each_entry(mpt2sas_port,
  2327. &sas_expander->sas_port_list, port_list) {
  2328. if (mpt2sas_port->remote_identify.device_type ==
  2329. SAS_END_DEVICE) {
  2330. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2331. sas_device =
  2332. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  2333. mpt2sas_port->remote_identify.sas_address);
  2334. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2335. if (!sas_device)
  2336. continue;
  2337. _scsih_block_io_device(ioc, sas_device->handle);
  2338. }
  2339. }
  2340. list_for_each_entry(mpt2sas_port,
  2341. &sas_expander->sas_port_list, port_list) {
  2342. if (mpt2sas_port->remote_identify.device_type ==
  2343. SAS_EDGE_EXPANDER_DEVICE ||
  2344. mpt2sas_port->remote_identify.device_type ==
  2345. SAS_FANOUT_EXPANDER_DEVICE) {
  2346. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2347. expander_sibling =
  2348. mpt2sas_scsih_expander_find_by_sas_address(
  2349. ioc, mpt2sas_port->remote_identify.sas_address);
  2350. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2351. _scsih_block_io_to_children_attached_to_ex(ioc,
  2352. expander_sibling);
  2353. }
  2354. }
  2355. }
  2356. /**
  2357. * _scsih_block_io_to_children_attached_directly
  2358. * @ioc: per adapter object
  2359. * @event_data: topology change event data
  2360. *
  2361. * This routine set sdev state to SDEV_BLOCK for all devices
  2362. * direct attached during device pull.
  2363. */
  2364. static void
  2365. _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
  2366. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2367. {
  2368. int i;
  2369. u16 handle;
  2370. u16 reason_code;
  2371. u8 phy_number;
  2372. for (i = 0; i < event_data->NumEntries; i++) {
  2373. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2374. if (!handle)
  2375. continue;
  2376. phy_number = event_data->StartPhyNum + i;
  2377. reason_code = event_data->PHY[i].PhyStatus &
  2378. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2379. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
  2380. _scsih_block_io_device(ioc, handle);
  2381. }
  2382. }
  2383. /**
  2384. * _scsih_tm_tr_send - send task management request
  2385. * @ioc: per adapter object
  2386. * @handle: device handle
  2387. * Context: interrupt time.
  2388. *
  2389. * This code is to initiate the device removal handshake protocal
  2390. * with controller firmware. This function will issue target reset
  2391. * using high priority request queue. It will send a sas iounit
  2392. * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
  2393. *
  2394. * This is designed to send muliple task management request at the same
  2395. * time to the fifo. If the fifo is full, we will append the request,
  2396. * and process it in a future completion.
  2397. */
  2398. static void
  2399. _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2400. {
  2401. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2402. u16 smid;
  2403. struct _sas_device *sas_device;
  2404. struct MPT2SAS_TARGET *sas_target_priv_data;
  2405. unsigned long flags;
  2406. struct _tr_list *delayed_tr;
  2407. if (ioc->shost_recovery || ioc->remove_host ||
  2408. ioc->pci_error_recovery) {
  2409. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2410. "progress!\n", __func__, ioc->name));
  2411. return;
  2412. }
  2413. /* if PD, then return */
  2414. if (test_bit(handle, ioc->pd_handles))
  2415. return;
  2416. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2417. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2418. if (sas_device && sas_device->starget &&
  2419. sas_device->starget->hostdata) {
  2420. sas_target_priv_data = sas_device->starget->hostdata;
  2421. sas_target_priv_data->deleted = 1;
  2422. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2423. "setting delete flag: handle(0x%04x), "
  2424. "sas_addr(0x%016llx)\n", ioc->name, handle,
  2425. (unsigned long long) sas_device->sas_address));
  2426. }
  2427. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2428. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
  2429. if (!smid) {
  2430. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2431. if (!delayed_tr)
  2432. return;
  2433. INIT_LIST_HEAD(&delayed_tr->list);
  2434. delayed_tr->handle = handle;
  2435. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  2436. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2437. "DELAYED:tr:handle(0x%04x), (open)\n",
  2438. ioc->name, handle));
  2439. return;
  2440. }
  2441. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
  2442. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
  2443. ioc->tm_tr_cb_idx));
  2444. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2445. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2446. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2447. mpi_request->DevHandle = cpu_to_le16(handle);
  2448. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2449. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2450. }
  2451. /**
  2452. * _scsih_sas_control_complete - completion routine
  2453. * @ioc: per adapter object
  2454. * @smid: system request message index
  2455. * @msix_index: MSIX table index supplied by the OS
  2456. * @reply: reply message frame(lower 32bit addr)
  2457. * Context: interrupt time.
  2458. *
  2459. * This is the sas iounit controll completion routine.
  2460. * This code is part of the code to initiate the device removal
  2461. * handshake protocal with controller firmware.
  2462. *
  2463. * Return 1 meaning mf should be freed from _base_interrupt
  2464. * 0 means the mf is freed from this function.
  2465. */
  2466. static u8
  2467. _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2468. u8 msix_index, u32 reply)
  2469. {
  2470. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  2471. Mpi2SasIoUnitControlReply_t *mpi_reply =
  2472. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2473. #endif
  2474. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2475. "sc_complete:handle(0x%04x), (open) "
  2476. "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
  2477. ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
  2478. le16_to_cpu(mpi_reply->IOCStatus),
  2479. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2480. return 1;
  2481. }
  2482. /**
  2483. * _scsih_tm_tr_volume_send - send target reset request for volumes
  2484. * @ioc: per adapter object
  2485. * @handle: device handle
  2486. * Context: interrupt time.
  2487. *
  2488. * This is designed to send muliple task management request at the same
  2489. * time to the fifo. If the fifo is full, we will append the request,
  2490. * and process it in a future completion.
  2491. */
  2492. static void
  2493. _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2494. {
  2495. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2496. u16 smid;
  2497. struct _tr_list *delayed_tr;
  2498. if (ioc->shost_recovery || ioc->remove_host ||
  2499. ioc->pci_error_recovery) {
  2500. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2501. "progress!\n", __func__, ioc->name));
  2502. return;
  2503. }
  2504. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
  2505. if (!smid) {
  2506. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2507. if (!delayed_tr)
  2508. return;
  2509. INIT_LIST_HEAD(&delayed_tr->list);
  2510. delayed_tr->handle = handle;
  2511. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
  2512. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2513. "DELAYED:tr:handle(0x%04x), (open)\n",
  2514. ioc->name, handle));
  2515. return;
  2516. }
  2517. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
  2518. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
  2519. ioc->tm_tr_volume_cb_idx));
  2520. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2521. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2522. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2523. mpi_request->DevHandle = cpu_to_le16(handle);
  2524. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2525. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2526. }
  2527. /**
  2528. * _scsih_tm_volume_tr_complete - target reset completion
  2529. * @ioc: per adapter object
  2530. * @smid: system request message index
  2531. * @msix_index: MSIX table index supplied by the OS
  2532. * @reply: reply message frame(lower 32bit addr)
  2533. * Context: interrupt time.
  2534. *
  2535. * Return 1 meaning mf should be freed from _base_interrupt
  2536. * 0 means the mf is freed from this function.
  2537. */
  2538. static u8
  2539. _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2540. u8 msix_index, u32 reply)
  2541. {
  2542. u16 handle;
  2543. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  2544. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2545. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2546. if (ioc->shost_recovery || ioc->remove_host ||
  2547. ioc->pci_error_recovery) {
  2548. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2549. "progress!\n", __func__, ioc->name));
  2550. return 1;
  2551. }
  2552. mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
  2553. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  2554. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  2555. dewtprintk(ioc, printk("spurious interrupt: "
  2556. "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
  2557. le16_to_cpu(mpi_reply->DevHandle), smid));
  2558. return 0;
  2559. }
  2560. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2561. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  2562. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2563. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  2564. le32_to_cpu(mpi_reply->IOCLogInfo),
  2565. le32_to_cpu(mpi_reply->TerminationCount)));
  2566. return _scsih_check_for_pending_tm(ioc, smid);
  2567. }
  2568. /**
  2569. * _scsih_tm_tr_complete -
  2570. * @ioc: per adapter object
  2571. * @smid: system request message index
  2572. * @msix_index: MSIX table index supplied by the OS
  2573. * @reply: reply message frame(lower 32bit addr)
  2574. * Context: interrupt time.
  2575. *
  2576. * This is the target reset completion routine.
  2577. * This code is part of the code to initiate the device removal
  2578. * handshake protocal with controller firmware.
  2579. * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
  2580. *
  2581. * Return 1 meaning mf should be freed from _base_interrupt
  2582. * 0 means the mf is freed from this function.
  2583. */
  2584. static u8
  2585. _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  2586. u32 reply)
  2587. {
  2588. u16 handle;
  2589. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  2590. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2591. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2592. Mpi2SasIoUnitControlRequest_t *mpi_request;
  2593. u16 smid_sas_ctrl;
  2594. if (ioc->shost_recovery || ioc->remove_host ||
  2595. ioc->pci_error_recovery) {
  2596. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2597. "progress!\n", __func__, ioc->name));
  2598. return 1;
  2599. }
  2600. mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
  2601. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  2602. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  2603. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
  2604. "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
  2605. le16_to_cpu(mpi_reply->DevHandle), smid));
  2606. return 0;
  2607. }
  2608. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2609. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  2610. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2611. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  2612. le32_to_cpu(mpi_reply->IOCLogInfo),
  2613. le32_to_cpu(mpi_reply->TerminationCount)));
  2614. smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
  2615. if (!smid_sas_ctrl) {
  2616. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2617. ioc->name, __func__);
  2618. return 1;
  2619. }
  2620. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
  2621. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
  2622. ioc->tm_sas_control_cb_idx));
  2623. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
  2624. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  2625. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  2626. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  2627. mpi_request->DevHandle = mpi_request_tm->DevHandle;
  2628. mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
  2629. return _scsih_check_for_pending_tm(ioc, smid);
  2630. }
  2631. /**
  2632. * _scsih_check_for_pending_tm - check for pending task management
  2633. * @ioc: per adapter object
  2634. * @smid: system request message index
  2635. *
  2636. * This will check delayed target reset list, and feed the
  2637. * next reqeust.
  2638. *
  2639. * Return 1 meaning mf should be freed from _base_interrupt
  2640. * 0 means the mf is freed from this function.
  2641. */
  2642. static u8
  2643. _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  2644. {
  2645. struct _tr_list *delayed_tr;
  2646. if (!list_empty(&ioc->delayed_tr_volume_list)) {
  2647. delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
  2648. struct _tr_list, list);
  2649. mpt2sas_base_free_smid(ioc, smid);
  2650. _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
  2651. list_del(&delayed_tr->list);
  2652. kfree(delayed_tr);
  2653. return 0;
  2654. }
  2655. if (!list_empty(&ioc->delayed_tr_list)) {
  2656. delayed_tr = list_entry(ioc->delayed_tr_list.next,
  2657. struct _tr_list, list);
  2658. mpt2sas_base_free_smid(ioc, smid);
  2659. _scsih_tm_tr_send(ioc, delayed_tr->handle);
  2660. list_del(&delayed_tr->list);
  2661. kfree(delayed_tr);
  2662. return 0;
  2663. }
  2664. return 1;
  2665. }
  2666. /**
  2667. * _scsih_check_topo_delete_events - sanity check on topo events
  2668. * @ioc: per adapter object
  2669. * @event_data: the event data payload
  2670. *
  2671. * This routine added to better handle cable breaker.
  2672. *
  2673. * This handles the case where driver recieves multiple expander
  2674. * add and delete events in a single shot. When there is a delete event
  2675. * the routine will void any pending add events waiting in the event queue.
  2676. *
  2677. * Return nothing.
  2678. */
  2679. static void
  2680. _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
  2681. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2682. {
  2683. struct fw_event_work *fw_event;
  2684. Mpi2EventDataSasTopologyChangeList_t *local_event_data;
  2685. u16 expander_handle;
  2686. struct _sas_node *sas_expander;
  2687. unsigned long flags;
  2688. int i, reason_code;
  2689. u16 handle;
  2690. for (i = 0 ; i < event_data->NumEntries; i++) {
  2691. if (event_data->PHY[i].PhyStatus &
  2692. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
  2693. continue;
  2694. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2695. if (!handle)
  2696. continue;
  2697. reason_code = event_data->PHY[i].PhyStatus &
  2698. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2699. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
  2700. _scsih_tm_tr_send(ioc, handle);
  2701. }
  2702. expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  2703. if (expander_handle < ioc->sas_hba.num_phys) {
  2704. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2705. return;
  2706. }
  2707. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
  2708. || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
  2709. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2710. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  2711. expander_handle);
  2712. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2713. _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
  2714. } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
  2715. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2716. if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  2717. return;
  2718. /* mark ignore flag for pending events */
  2719. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2720. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  2721. if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
  2722. fw_event->ignore)
  2723. continue;
  2724. local_event_data = fw_event->event_data;
  2725. if (local_event_data->ExpStatus ==
  2726. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  2727. local_event_data->ExpStatus ==
  2728. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  2729. if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
  2730. expander_handle) {
  2731. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2732. "setting ignoring flag\n", ioc->name));
  2733. fw_event->ignore = 1;
  2734. }
  2735. }
  2736. }
  2737. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2738. }
  2739. /**
  2740. * _scsih_set_volume_delete_flag - setting volume delete flag
  2741. * @ioc: per adapter object
  2742. * @handle: device handle
  2743. *
  2744. * This
  2745. * Return nothing.
  2746. */
  2747. static void
  2748. _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2749. {
  2750. struct _raid_device *raid_device;
  2751. struct MPT2SAS_TARGET *sas_target_priv_data;
  2752. unsigned long flags;
  2753. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  2754. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  2755. if (raid_device && raid_device->starget &&
  2756. raid_device->starget->hostdata) {
  2757. sas_target_priv_data =
  2758. raid_device->starget->hostdata;
  2759. sas_target_priv_data->deleted = 1;
  2760. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2761. "setting delete flag: handle(0x%04x), "
  2762. "wwid(0x%016llx)\n", ioc->name, handle,
  2763. (unsigned long long) raid_device->wwid));
  2764. }
  2765. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  2766. }
  2767. /**
  2768. * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
  2769. * @handle: input handle
  2770. * @a: handle for volume a
  2771. * @b: handle for volume b
  2772. *
  2773. * IR firmware only supports two raid volumes. The purpose of this
  2774. * routine is to set the volume handle in either a or b. When the given
  2775. * input handle is non-zero, or when a and b have not been set before.
  2776. */
  2777. static void
  2778. _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
  2779. {
  2780. if (!handle || handle == *a || handle == *b)
  2781. return;
  2782. if (!*a)
  2783. *a = handle;
  2784. else if (!*b)
  2785. *b = handle;
  2786. }
  2787. /**
  2788. * _scsih_check_ir_config_unhide_events - check for UNHIDE events
  2789. * @ioc: per adapter object
  2790. * @event_data: the event data payload
  2791. * Context: interrupt time.
  2792. *
  2793. * This routine will send target reset to volume, followed by target
  2794. * resets to the PDs. This is called when a PD has been removed, or
  2795. * volume has been deleted or removed. When the target reset is sent
  2796. * to volume, the PD target resets need to be queued to start upon
  2797. * completion of the volume target reset.
  2798. *
  2799. * Return nothing.
  2800. */
  2801. static void
  2802. _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
  2803. Mpi2EventDataIrConfigChangeList_t *event_data)
  2804. {
  2805. Mpi2EventIrConfigElement_t *element;
  2806. int i;
  2807. u16 handle, volume_handle, a, b;
  2808. struct _tr_list *delayed_tr;
  2809. a = 0;
  2810. b = 0;
  2811. /* Volume Resets for Deleted or Removed */
  2812. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  2813. for (i = 0; i < event_data->NumElements; i++, element++) {
  2814. if (element->ReasonCode ==
  2815. MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
  2816. element->ReasonCode ==
  2817. MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
  2818. volume_handle = le16_to_cpu(element->VolDevHandle);
  2819. _scsih_set_volume_delete_flag(ioc, volume_handle);
  2820. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  2821. }
  2822. }
  2823. /* Volume Resets for UNHIDE events */
  2824. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  2825. for (i = 0; i < event_data->NumElements; i++, element++) {
  2826. if (le32_to_cpu(event_data->Flags) &
  2827. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
  2828. continue;
  2829. if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
  2830. volume_handle = le16_to_cpu(element->VolDevHandle);
  2831. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  2832. }
  2833. }
  2834. if (a)
  2835. _scsih_tm_tr_volume_send(ioc, a);
  2836. if (b)
  2837. _scsih_tm_tr_volume_send(ioc, b);
  2838. /* PD target resets */
  2839. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  2840. for (i = 0; i < event_data->NumElements; i++, element++) {
  2841. if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
  2842. continue;
  2843. handle = le16_to_cpu(element->PhysDiskDevHandle);
  2844. volume_handle = le16_to_cpu(element->VolDevHandle);
  2845. clear_bit(handle, ioc->pd_handles);
  2846. if (!volume_handle)
  2847. _scsih_tm_tr_send(ioc, handle);
  2848. else if (volume_handle == a || volume_handle == b) {
  2849. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2850. BUG_ON(!delayed_tr);
  2851. INIT_LIST_HEAD(&delayed_tr->list);
  2852. delayed_tr->handle = handle;
  2853. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  2854. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2855. "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
  2856. handle));
  2857. } else
  2858. _scsih_tm_tr_send(ioc, handle);
  2859. }
  2860. }
  2861. /**
  2862. * _scsih_check_volume_delete_events - set delete flag for volumes
  2863. * @ioc: per adapter object
  2864. * @event_data: the event data payload
  2865. * Context: interrupt time.
  2866. *
  2867. * This will handle the case when the cable connected to entire volume is
  2868. * pulled. We will take care of setting the deleted flag so normal IO will
  2869. * not be sent.
  2870. *
  2871. * Return nothing.
  2872. */
  2873. static void
  2874. _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
  2875. Mpi2EventDataIrVolume_t *event_data)
  2876. {
  2877. u32 state;
  2878. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  2879. return;
  2880. state = le32_to_cpu(event_data->NewValue);
  2881. if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
  2882. MPI2_RAID_VOL_STATE_FAILED)
  2883. _scsih_set_volume_delete_flag(ioc,
  2884. le16_to_cpu(event_data->VolDevHandle));
  2885. }
  2886. /**
  2887. * _scsih_flush_running_cmds - completing outstanding commands.
  2888. * @ioc: per adapter object
  2889. *
  2890. * The flushing out of all pending scmd commands following host reset,
  2891. * where all IO is dropped to the floor.
  2892. *
  2893. * Return nothing.
  2894. */
  2895. static void
  2896. _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
  2897. {
  2898. struct scsi_cmnd *scmd;
  2899. u16 smid;
  2900. u16 count = 0;
  2901. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  2902. scmd = _scsih_scsi_lookup_get(ioc, smid);
  2903. if (!scmd)
  2904. continue;
  2905. count++;
  2906. mpt2sas_base_free_smid(ioc, smid);
  2907. scsi_dma_unmap(scmd);
  2908. if (ioc->pci_error_recovery)
  2909. scmd->result = DID_NO_CONNECT << 16;
  2910. else
  2911. scmd->result = DID_RESET << 16;
  2912. scmd->scsi_done(scmd);
  2913. }
  2914. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
  2915. ioc->name, count));
  2916. }
  2917. /**
  2918. * _scsih_setup_eedp - setup MPI request for EEDP transfer
  2919. * @scmd: pointer to scsi command object
  2920. * @mpi_request: pointer to the SCSI_IO reqest message frame
  2921. *
  2922. * Supporting protection 1 and 3.
  2923. *
  2924. * Returns nothing
  2925. */
  2926. static void
  2927. _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
  2928. {
  2929. u16 eedp_flags;
  2930. unsigned char prot_op = scsi_get_prot_op(scmd);
  2931. unsigned char prot_type = scsi_get_prot_type(scmd);
  2932. if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
  2933. return;
  2934. if (prot_op == SCSI_PROT_READ_STRIP)
  2935. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
  2936. else if (prot_op == SCSI_PROT_WRITE_INSERT)
  2937. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  2938. else
  2939. return;
  2940. switch (prot_type) {
  2941. case SCSI_PROT_DIF_TYPE1:
  2942. /*
  2943. * enable ref/guard checking
  2944. * auto increment ref tag
  2945. */
  2946. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  2947. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  2948. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2949. mpi_request->CDB.EEDP32.PrimaryReferenceTag =
  2950. cpu_to_be32(scsi_get_lba(scmd));
  2951. break;
  2952. case SCSI_PROT_DIF_TYPE2:
  2953. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  2954. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  2955. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2956. break;
  2957. case SCSI_PROT_DIF_TYPE3:
  2958. /*
  2959. * enable guard checking
  2960. */
  2961. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2962. break;
  2963. }
  2964. mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
  2965. mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
  2966. }
  2967. /**
  2968. * _scsih_eedp_error_handling - return sense code for EEDP errors
  2969. * @scmd: pointer to scsi command object
  2970. * @ioc_status: ioc status
  2971. *
  2972. * Returns nothing
  2973. */
  2974. static void
  2975. _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
  2976. {
  2977. u8 ascq;
  2978. u8 sk;
  2979. u8 host_byte;
  2980. switch (ioc_status) {
  2981. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  2982. ascq = 0x01;
  2983. break;
  2984. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  2985. ascq = 0x02;
  2986. break;
  2987. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  2988. ascq = 0x03;
  2989. break;
  2990. default:
  2991. ascq = 0x00;
  2992. break;
  2993. }
  2994. if (scmd->sc_data_direction == DMA_TO_DEVICE) {
  2995. sk = ILLEGAL_REQUEST;
  2996. host_byte = DID_ABORT;
  2997. } else {
  2998. sk = ABORTED_COMMAND;
  2999. host_byte = DID_OK;
  3000. }
  3001. scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
  3002. scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
  3003. SAM_STAT_CHECK_CONDITION;
  3004. }
  3005. /**
  3006. * _scsih_qcmd - main scsi request entry point
  3007. * @scmd: pointer to scsi command object
  3008. * @done: function pointer to be invoked on completion
  3009. *
  3010. * The callback index is set inside `ioc->scsi_io_cb_idx`.
  3011. *
  3012. * Returns 0 on success. If there's a failure, return either:
  3013. * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
  3014. * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  3015. */
  3016. static int
  3017. _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
  3018. {
  3019. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  3020. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3021. struct MPT2SAS_TARGET *sas_target_priv_data;
  3022. Mpi2SCSIIORequest_t *mpi_request;
  3023. u32 mpi_control;
  3024. u16 smid;
  3025. scmd->scsi_done = done;
  3026. sas_device_priv_data = scmd->device->hostdata;
  3027. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  3028. scmd->result = DID_NO_CONNECT << 16;
  3029. scmd->scsi_done(scmd);
  3030. return 0;
  3031. }
  3032. if (ioc->pci_error_recovery) {
  3033. scmd->result = DID_NO_CONNECT << 16;
  3034. scmd->scsi_done(scmd);
  3035. return 0;
  3036. }
  3037. sas_target_priv_data = sas_device_priv_data->sas_target;
  3038. /* invalid device handle */
  3039. if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
  3040. scmd->result = DID_NO_CONNECT << 16;
  3041. scmd->scsi_done(scmd);
  3042. return 0;
  3043. }
  3044. /* host recovery or link resets sent via IOCTLs */
  3045. if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
  3046. return SCSI_MLQUEUE_HOST_BUSY;
  3047. /* device busy with task management */
  3048. else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
  3049. return SCSI_MLQUEUE_DEVICE_BUSY;
  3050. /* device has been deleted */
  3051. else if (sas_target_priv_data->deleted) {
  3052. scmd->result = DID_NO_CONNECT << 16;
  3053. scmd->scsi_done(scmd);
  3054. return 0;
  3055. }
  3056. if (scmd->sc_data_direction == DMA_FROM_DEVICE)
  3057. mpi_control = MPI2_SCSIIO_CONTROL_READ;
  3058. else if (scmd->sc_data_direction == DMA_TO_DEVICE)
  3059. mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
  3060. else
  3061. mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
  3062. /* set tags */
  3063. if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
  3064. if (scmd->device->tagged_supported) {
  3065. if (scmd->device->ordered_tags)
  3066. mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
  3067. else
  3068. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  3069. } else
  3070. /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
  3071. /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
  3072. */
  3073. mpi_control |= (0x500);
  3074. } else
  3075. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  3076. /* Make sure Device is not raid volume */
  3077. if (!_scsih_is_raid(&scmd->device->sdev_gendev) &&
  3078. sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
  3079. mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
  3080. smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
  3081. if (!smid) {
  3082. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  3083. ioc->name, __func__);
  3084. goto out;
  3085. }
  3086. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3087. memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
  3088. _scsih_setup_eedp(scmd, mpi_request);
  3089. if (scmd->cmd_len == 32)
  3090. mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
  3091. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  3092. if (sas_device_priv_data->sas_target->flags &
  3093. MPT_TARGET_FLAGS_RAID_COMPONENT)
  3094. mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  3095. else
  3096. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  3097. mpi_request->DevHandle =
  3098. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  3099. mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
  3100. mpi_request->Control = cpu_to_le32(mpi_control);
  3101. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
  3102. mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
  3103. mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  3104. mpi_request->SenseBufferLowAddress =
  3105. mpt2sas_base_get_sense_buffer_dma(ioc, smid);
  3106. mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
  3107. mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
  3108. MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
  3109. mpi_request->VF_ID = 0; /* TODO */
  3110. mpi_request->VP_ID = 0;
  3111. int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
  3112. mpi_request->LUN);
  3113. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  3114. if (!mpi_request->DataLength) {
  3115. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
  3116. } else {
  3117. if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
  3118. mpt2sas_base_free_smid(ioc, smid);
  3119. goto out;
  3120. }
  3121. }
  3122. if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
  3123. mpt2sas_base_put_smid_scsi_io(ioc, smid,
  3124. sas_device_priv_data->sas_target->handle);
  3125. else
  3126. mpt2sas_base_put_smid_default(ioc, smid);
  3127. return 0;
  3128. out:
  3129. return SCSI_MLQUEUE_HOST_BUSY;
  3130. }
  3131. static DEF_SCSI_QCMD(_scsih_qcmd)
  3132. /**
  3133. * _scsih_normalize_sense - normalize descriptor and fixed format sense data
  3134. * @sense_buffer: sense data returned by target
  3135. * @data: normalized skey/asc/ascq
  3136. *
  3137. * Return nothing.
  3138. */
  3139. static void
  3140. _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
  3141. {
  3142. if ((sense_buffer[0] & 0x7F) >= 0x72) {
  3143. /* descriptor format */
  3144. data->skey = sense_buffer[1] & 0x0F;
  3145. data->asc = sense_buffer[2];
  3146. data->ascq = sense_buffer[3];
  3147. } else {
  3148. /* fixed format */
  3149. data->skey = sense_buffer[2] & 0x0F;
  3150. data->asc = sense_buffer[12];
  3151. data->ascq = sense_buffer[13];
  3152. }
  3153. }
  3154. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3155. /**
  3156. * _scsih_scsi_ioc_info - translated non-successfull SCSI_IO request
  3157. * @ioc: per adapter object
  3158. * @scmd: pointer to scsi command object
  3159. * @mpi_reply: reply mf payload returned from firmware
  3160. *
  3161. * scsi_status - SCSI Status code returned from target device
  3162. * scsi_state - state info associated with SCSI_IO determined by ioc
  3163. * ioc_status - ioc supplied status info
  3164. *
  3165. * Return nothing.
  3166. */
  3167. static void
  3168. _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  3169. Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
  3170. {
  3171. u32 response_info;
  3172. u8 *response_bytes;
  3173. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  3174. MPI2_IOCSTATUS_MASK;
  3175. u8 scsi_state = mpi_reply->SCSIState;
  3176. u8 scsi_status = mpi_reply->SCSIStatus;
  3177. char *desc_ioc_state = NULL;
  3178. char *desc_scsi_status = NULL;
  3179. char *desc_scsi_state = ioc->tmp_string;
  3180. u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  3181. struct _sas_device *sas_device = NULL;
  3182. unsigned long flags;
  3183. struct scsi_target *starget = scmd->device->sdev_target;
  3184. struct MPT2SAS_TARGET *priv_target = starget->hostdata;
  3185. if (!priv_target)
  3186. return;
  3187. if (log_info == 0x31170000)
  3188. return;
  3189. switch (ioc_status) {
  3190. case MPI2_IOCSTATUS_SUCCESS:
  3191. desc_ioc_state = "success";
  3192. break;
  3193. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  3194. desc_ioc_state = "invalid function";
  3195. break;
  3196. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  3197. desc_ioc_state = "scsi recovered error";
  3198. break;
  3199. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  3200. desc_ioc_state = "scsi invalid dev handle";
  3201. break;
  3202. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3203. desc_ioc_state = "scsi device not there";
  3204. break;
  3205. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  3206. desc_ioc_state = "scsi data overrun";
  3207. break;
  3208. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3209. desc_ioc_state = "scsi data underrun";
  3210. break;
  3211. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  3212. desc_ioc_state = "scsi io data error";
  3213. break;
  3214. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  3215. desc_ioc_state = "scsi protocol error";
  3216. break;
  3217. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3218. desc_ioc_state = "scsi task terminated";
  3219. break;
  3220. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3221. desc_ioc_state = "scsi residual mismatch";
  3222. break;
  3223. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  3224. desc_ioc_state = "scsi task mgmt failed";
  3225. break;
  3226. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3227. desc_ioc_state = "scsi ioc terminated";
  3228. break;
  3229. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3230. desc_ioc_state = "scsi ext terminated";
  3231. break;
  3232. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3233. desc_ioc_state = "eedp guard error";
  3234. break;
  3235. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3236. desc_ioc_state = "eedp ref tag error";
  3237. break;
  3238. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3239. desc_ioc_state = "eedp app tag error";
  3240. break;
  3241. default:
  3242. desc_ioc_state = "unknown";
  3243. break;
  3244. }
  3245. switch (scsi_status) {
  3246. case MPI2_SCSI_STATUS_GOOD:
  3247. desc_scsi_status = "good";
  3248. break;
  3249. case MPI2_SCSI_STATUS_CHECK_CONDITION:
  3250. desc_scsi_status = "check condition";
  3251. break;
  3252. case MPI2_SCSI_STATUS_CONDITION_MET:
  3253. desc_scsi_status = "condition met";
  3254. break;
  3255. case MPI2_SCSI_STATUS_BUSY:
  3256. desc_scsi_status = "busy";
  3257. break;
  3258. case MPI2_SCSI_STATUS_INTERMEDIATE:
  3259. desc_scsi_status = "intermediate";
  3260. break;
  3261. case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
  3262. desc_scsi_status = "intermediate condmet";
  3263. break;
  3264. case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
  3265. desc_scsi_status = "reservation conflict";
  3266. break;
  3267. case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
  3268. desc_scsi_status = "command terminated";
  3269. break;
  3270. case MPI2_SCSI_STATUS_TASK_SET_FULL:
  3271. desc_scsi_status = "task set full";
  3272. break;
  3273. case MPI2_SCSI_STATUS_ACA_ACTIVE:
  3274. desc_scsi_status = "aca active";
  3275. break;
  3276. case MPI2_SCSI_STATUS_TASK_ABORTED:
  3277. desc_scsi_status = "task aborted";
  3278. break;
  3279. default:
  3280. desc_scsi_status = "unknown";
  3281. break;
  3282. }
  3283. desc_scsi_state[0] = '\0';
  3284. if (!scsi_state)
  3285. desc_scsi_state = " ";
  3286. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  3287. strcat(desc_scsi_state, "response info ");
  3288. if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3289. strcat(desc_scsi_state, "state terminated ");
  3290. if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
  3291. strcat(desc_scsi_state, "no status ");
  3292. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
  3293. strcat(desc_scsi_state, "autosense failed ");
  3294. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
  3295. strcat(desc_scsi_state, "autosense valid ");
  3296. scsi_print_command(scmd);
  3297. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  3298. printk(MPT2SAS_WARN_FMT "\tvolume wwid(0x%016llx)\n", ioc->name,
  3299. (unsigned long long)priv_target->sas_address);
  3300. } else {
  3301. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3302. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  3303. priv_target->sas_address);
  3304. if (sas_device) {
  3305. printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
  3306. "phy(%d)\n", ioc->name, sas_device->sas_address,
  3307. sas_device->phy);
  3308. printk(MPT2SAS_WARN_FMT
  3309. "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
  3310. ioc->name, sas_device->enclosure_logical_id,
  3311. sas_device->slot);
  3312. }
  3313. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3314. }
  3315. printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
  3316. "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
  3317. desc_ioc_state, ioc_status, smid);
  3318. printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
  3319. "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
  3320. scsi_get_resid(scmd));
  3321. printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
  3322. "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
  3323. le32_to_cpu(mpi_reply->TransferCount), scmd->result);
  3324. printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
  3325. "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
  3326. scsi_status, desc_scsi_state, scsi_state);
  3327. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  3328. struct sense_info data;
  3329. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3330. printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
  3331. "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
  3332. data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
  3333. }
  3334. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
  3335. response_info = le32_to_cpu(mpi_reply->ResponseInfo);
  3336. response_bytes = (u8 *)&response_info;
  3337. _scsih_response_code(ioc, response_bytes[0]);
  3338. }
  3339. }
  3340. #endif
  3341. /**
  3342. * _scsih_smart_predicted_fault - illuminate Fault LED
  3343. * @ioc: per adapter object
  3344. * @handle: device handle
  3345. *
  3346. * Return nothing.
  3347. */
  3348. static void
  3349. _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3350. {
  3351. Mpi2SepReply_t mpi_reply;
  3352. Mpi2SepRequest_t mpi_request;
  3353. struct scsi_target *starget;
  3354. struct MPT2SAS_TARGET *sas_target_priv_data;
  3355. Mpi2EventNotificationReply_t *event_reply;
  3356. Mpi2EventDataSasDeviceStatusChange_t *event_data;
  3357. struct _sas_device *sas_device;
  3358. ssize_t sz;
  3359. unsigned long flags;
  3360. /* only handle non-raid devices */
  3361. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3362. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  3363. if (!sas_device) {
  3364. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3365. return;
  3366. }
  3367. starget = sas_device->starget;
  3368. sas_target_priv_data = starget->hostdata;
  3369. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
  3370. ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
  3371. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3372. return;
  3373. }
  3374. starget_printk(KERN_WARNING, starget, "predicted fault\n");
  3375. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3376. if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
  3377. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  3378. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  3379. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  3380. mpi_request.SlotStatus =
  3381. cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  3382. mpi_request.DevHandle = cpu_to_le16(handle);
  3383. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
  3384. if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  3385. &mpi_request)) != 0) {
  3386. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3387. ioc->name, __FILE__, __LINE__, __func__);
  3388. return;
  3389. }
  3390. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  3391. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  3392. "enclosure_processor: ioc_status (0x%04x), "
  3393. "loginfo(0x%08x)\n", ioc->name,
  3394. le16_to_cpu(mpi_reply.IOCStatus),
  3395. le32_to_cpu(mpi_reply.IOCLogInfo)));
  3396. return;
  3397. }
  3398. }
  3399. /* insert into event log */
  3400. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  3401. sizeof(Mpi2EventDataSasDeviceStatusChange_t);
  3402. event_reply = kzalloc(sz, GFP_KERNEL);
  3403. if (!event_reply) {
  3404. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3405. ioc->name, __FILE__, __LINE__, __func__);
  3406. return;
  3407. }
  3408. event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  3409. event_reply->Event =
  3410. cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  3411. event_reply->MsgLength = sz/4;
  3412. event_reply->EventDataLength =
  3413. cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
  3414. event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
  3415. event_reply->EventData;
  3416. event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
  3417. event_data->ASC = 0x5D;
  3418. event_data->DevHandle = cpu_to_le16(handle);
  3419. event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
  3420. mpt2sas_ctl_add_to_event_log(ioc, event_reply);
  3421. kfree(event_reply);
  3422. }
  3423. /**
  3424. * _scsih_io_done - scsi request callback
  3425. * @ioc: per adapter object
  3426. * @smid: system request message index
  3427. * @msix_index: MSIX table index supplied by the OS
  3428. * @reply: reply message frame(lower 32bit addr)
  3429. *
  3430. * Callback handler when using _scsih_qcmd.
  3431. *
  3432. * Return 1 meaning mf should be freed from _base_interrupt
  3433. * 0 means the mf is freed from this function.
  3434. */
  3435. static u8
  3436. _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  3437. {
  3438. Mpi2SCSIIORequest_t *mpi_request;
  3439. Mpi2SCSIIOReply_t *mpi_reply;
  3440. struct scsi_cmnd *scmd;
  3441. u16 ioc_status;
  3442. u32 xfer_cnt;
  3443. u8 scsi_state;
  3444. u8 scsi_status;
  3445. u32 log_info;
  3446. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3447. u32 response_code = 0;
  3448. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  3449. scmd = _scsih_scsi_lookup_get(ioc, smid);
  3450. if (scmd == NULL)
  3451. return 1;
  3452. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3453. if (mpi_reply == NULL) {
  3454. scmd->result = DID_OK << 16;
  3455. goto out;
  3456. }
  3457. sas_device_priv_data = scmd->device->hostdata;
  3458. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  3459. sas_device_priv_data->sas_target->deleted) {
  3460. scmd->result = DID_NO_CONNECT << 16;
  3461. goto out;
  3462. }
  3463. /* turning off TLR */
  3464. scsi_state = mpi_reply->SCSIState;
  3465. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  3466. response_code =
  3467. le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
  3468. if (!sas_device_priv_data->tlr_snoop_check) {
  3469. sas_device_priv_data->tlr_snoop_check++;
  3470. if (!_scsih_is_raid(&scmd->device->sdev_gendev) &&
  3471. sas_is_tlr_enabled(scmd->device) &&
  3472. response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
  3473. sas_disable_tlr(scmd->device);
  3474. sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
  3475. }
  3476. }
  3477. xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
  3478. scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
  3479. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  3480. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  3481. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  3482. else
  3483. log_info = 0;
  3484. ioc_status &= MPI2_IOCSTATUS_MASK;
  3485. scsi_status = mpi_reply->SCSIStatus;
  3486. if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  3487. (scsi_status == MPI2_SCSI_STATUS_BUSY ||
  3488. scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
  3489. scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
  3490. ioc_status = MPI2_IOCSTATUS_SUCCESS;
  3491. }
  3492. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  3493. struct sense_info data;
  3494. const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
  3495. smid);
  3496. u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
  3497. le32_to_cpu(mpi_reply->SenseCount));
  3498. memcpy(scmd->sense_buffer, sense_data, sz);
  3499. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3500. /* failure prediction threshold exceeded */
  3501. if (data.asc == 0x5D)
  3502. _scsih_smart_predicted_fault(ioc,
  3503. le16_to_cpu(mpi_reply->DevHandle));
  3504. }
  3505. switch (ioc_status) {
  3506. case MPI2_IOCSTATUS_BUSY:
  3507. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  3508. scmd->result = SAM_STAT_BUSY;
  3509. break;
  3510. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3511. scmd->result = DID_NO_CONNECT << 16;
  3512. break;
  3513. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3514. if (sas_device_priv_data->block) {
  3515. scmd->result = DID_TRANSPORT_DISRUPTED << 16;
  3516. goto out;
  3517. }
  3518. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3519. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3520. scmd->result = DID_RESET << 16;
  3521. break;
  3522. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3523. if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
  3524. scmd->result = DID_SOFT_ERROR << 16;
  3525. else
  3526. scmd->result = (DID_OK << 16) | scsi_status;
  3527. break;
  3528. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3529. scmd->result = (DID_OK << 16) | scsi_status;
  3530. if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
  3531. break;
  3532. if (xfer_cnt < scmd->underflow) {
  3533. if (scsi_status == SAM_STAT_BUSY)
  3534. scmd->result = SAM_STAT_BUSY;
  3535. else
  3536. scmd->result = DID_SOFT_ERROR << 16;
  3537. } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3538. MPI2_SCSI_STATE_NO_SCSI_STATUS))
  3539. scmd->result = DID_SOFT_ERROR << 16;
  3540. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3541. scmd->result = DID_RESET << 16;
  3542. else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
  3543. mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
  3544. mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
  3545. scmd->result = (DRIVER_SENSE << 24) |
  3546. SAM_STAT_CHECK_CONDITION;
  3547. scmd->sense_buffer[0] = 0x70;
  3548. scmd->sense_buffer[2] = ILLEGAL_REQUEST;
  3549. scmd->sense_buffer[12] = 0x20;
  3550. scmd->sense_buffer[13] = 0;
  3551. }
  3552. break;
  3553. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  3554. scsi_set_resid(scmd, 0);
  3555. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  3556. case MPI2_IOCSTATUS_SUCCESS:
  3557. scmd->result = (DID_OK << 16) | scsi_status;
  3558. if (response_code ==
  3559. MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
  3560. (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3561. MPI2_SCSI_STATE_NO_SCSI_STATUS)))
  3562. scmd->result = DID_SOFT_ERROR << 16;
  3563. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3564. scmd->result = DID_RESET << 16;
  3565. break;
  3566. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3567. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3568. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3569. _scsih_eedp_error_handling(scmd, ioc_status);
  3570. break;
  3571. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  3572. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  3573. case MPI2_IOCSTATUS_INVALID_SGL:
  3574. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  3575. case MPI2_IOCSTATUS_INVALID_FIELD:
  3576. case MPI2_IOCSTATUS_INVALID_STATE:
  3577. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  3578. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  3579. default:
  3580. scmd->result = DID_SOFT_ERROR << 16;
  3581. break;
  3582. }
  3583. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3584. if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
  3585. _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
  3586. #endif
  3587. out:
  3588. scsi_dma_unmap(scmd);
  3589. scmd->scsi_done(scmd);
  3590. return 1;
  3591. }
  3592. /**
  3593. * _scsih_sas_host_refresh - refreshing sas host object contents
  3594. * @ioc: per adapter object
  3595. * Context: user
  3596. *
  3597. * During port enable, fw will send topology events for every device. Its
  3598. * possible that the handles may change from the previous setting, so this
  3599. * code keeping handles updating if changed.
  3600. *
  3601. * Return nothing.
  3602. */
  3603. static void
  3604. _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
  3605. {
  3606. u16 sz;
  3607. u16 ioc_status;
  3608. int i;
  3609. Mpi2ConfigReply_t mpi_reply;
  3610. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3611. u16 attached_handle;
  3612. u8 link_rate;
  3613. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
  3614. "updating handles for sas_host(0x%016llx)\n",
  3615. ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
  3616. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
  3617. * sizeof(Mpi2SasIOUnit0PhyData_t));
  3618. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3619. if (!sas_iounit_pg0) {
  3620. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3621. ioc->name, __FILE__, __LINE__, __func__);
  3622. return;
  3623. }
  3624. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3625. sas_iounit_pg0, sz)) != 0)
  3626. goto out;
  3627. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  3628. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  3629. goto out;
  3630. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3631. link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
  3632. if (i == 0)
  3633. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3634. PhyData[0].ControllerDevHandle);
  3635. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3636. attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
  3637. AttachedDevHandle);
  3638. if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  3639. link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
  3640. mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
  3641. attached_handle, i, link_rate);
  3642. }
  3643. out:
  3644. kfree(sas_iounit_pg0);
  3645. }
  3646. /**
  3647. * _scsih_sas_host_add - create sas host object
  3648. * @ioc: per adapter object
  3649. *
  3650. * Creating host side data object, stored in ioc->sas_hba
  3651. *
  3652. * Return nothing.
  3653. */
  3654. static void
  3655. _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
  3656. {
  3657. int i;
  3658. Mpi2ConfigReply_t mpi_reply;
  3659. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3660. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  3661. Mpi2SasPhyPage0_t phy_pg0;
  3662. Mpi2SasDevicePage0_t sas_device_pg0;
  3663. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3664. u16 ioc_status;
  3665. u16 sz;
  3666. u16 device_missing_delay;
  3667. mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
  3668. if (!ioc->sas_hba.num_phys) {
  3669. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3670. ioc->name, __FILE__, __LINE__, __func__);
  3671. return;
  3672. }
  3673. /* sas_iounit page 0 */
  3674. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
  3675. sizeof(Mpi2SasIOUnit0PhyData_t));
  3676. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3677. if (!sas_iounit_pg0) {
  3678. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3679. ioc->name, __FILE__, __LINE__, __func__);
  3680. return;
  3681. }
  3682. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3683. sas_iounit_pg0, sz))) {
  3684. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3685. ioc->name, __FILE__, __LINE__, __func__);
  3686. goto out;
  3687. }
  3688. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3689. MPI2_IOCSTATUS_MASK;
  3690. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3691. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3692. ioc->name, __FILE__, __LINE__, __func__);
  3693. goto out;
  3694. }
  3695. /* sas_iounit page 1 */
  3696. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  3697. sizeof(Mpi2SasIOUnit1PhyData_t));
  3698. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  3699. if (!sas_iounit_pg1) {
  3700. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3701. ioc->name, __FILE__, __LINE__, __func__);
  3702. goto out;
  3703. }
  3704. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  3705. sas_iounit_pg1, sz))) {
  3706. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3707. ioc->name, __FILE__, __LINE__, __func__);
  3708. goto out;
  3709. }
  3710. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3711. MPI2_IOCSTATUS_MASK;
  3712. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3713. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3714. ioc->name, __FILE__, __LINE__, __func__);
  3715. goto out;
  3716. }
  3717. ioc->io_missing_delay =
  3718. le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
  3719. device_missing_delay =
  3720. le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
  3721. if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  3722. ioc->device_missing_delay = (device_missing_delay &
  3723. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  3724. else
  3725. ioc->device_missing_delay = device_missing_delay &
  3726. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  3727. ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
  3728. ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
  3729. sizeof(struct _sas_phy), GFP_KERNEL);
  3730. if (!ioc->sas_hba.phy) {
  3731. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3732. ioc->name, __FILE__, __LINE__, __func__);
  3733. goto out;
  3734. }
  3735. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3736. if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  3737. i))) {
  3738. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3739. ioc->name, __FILE__, __LINE__, __func__);
  3740. goto out;
  3741. }
  3742. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3743. MPI2_IOCSTATUS_MASK;
  3744. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3745. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3746. ioc->name, __FILE__, __LINE__, __func__);
  3747. goto out;
  3748. }
  3749. if (i == 0)
  3750. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3751. PhyData[0].ControllerDevHandle);
  3752. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3753. ioc->sas_hba.phy[i].phy_id = i;
  3754. mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
  3755. phy_pg0, ioc->sas_hba.parent_dev);
  3756. }
  3757. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  3758. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
  3759. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3760. ioc->name, __FILE__, __LINE__, __func__);
  3761. goto out;
  3762. }
  3763. ioc->sas_hba.enclosure_handle =
  3764. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  3765. ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  3766. printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
  3767. "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
  3768. (unsigned long long) ioc->sas_hba.sas_address,
  3769. ioc->sas_hba.num_phys) ;
  3770. if (ioc->sas_hba.enclosure_handle) {
  3771. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3772. &enclosure_pg0,
  3773. MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3774. ioc->sas_hba.enclosure_handle))) {
  3775. ioc->sas_hba.enclosure_logical_id =
  3776. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3777. }
  3778. }
  3779. out:
  3780. kfree(sas_iounit_pg1);
  3781. kfree(sas_iounit_pg0);
  3782. }
  3783. /**
  3784. * _scsih_expander_add - creating expander object
  3785. * @ioc: per adapter object
  3786. * @handle: expander handle
  3787. *
  3788. * Creating expander object, stored in ioc->sas_expander_list.
  3789. *
  3790. * Return 0 for success, else error.
  3791. */
  3792. static int
  3793. _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3794. {
  3795. struct _sas_node *sas_expander;
  3796. Mpi2ConfigReply_t mpi_reply;
  3797. Mpi2ExpanderPage0_t expander_pg0;
  3798. Mpi2ExpanderPage1_t expander_pg1;
  3799. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3800. u32 ioc_status;
  3801. u16 parent_handle;
  3802. __le64 sas_address, sas_address_parent = 0;
  3803. int i;
  3804. unsigned long flags;
  3805. struct _sas_port *mpt2sas_port = NULL;
  3806. int rc = 0;
  3807. if (!handle)
  3808. return -1;
  3809. if (ioc->shost_recovery || ioc->pci_error_recovery)
  3810. return -1;
  3811. if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  3812. MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
  3813. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3814. ioc->name, __FILE__, __LINE__, __func__);
  3815. return -1;
  3816. }
  3817. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3818. MPI2_IOCSTATUS_MASK;
  3819. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3820. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3821. ioc->name, __FILE__, __LINE__, __func__);
  3822. return -1;
  3823. }
  3824. /* handle out of order topology events */
  3825. parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
  3826. if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
  3827. != 0) {
  3828. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3829. ioc->name, __FILE__, __LINE__, __func__);
  3830. return -1;
  3831. }
  3832. if (sas_address_parent != ioc->sas_hba.sas_address) {
  3833. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3834. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3835. sas_address_parent);
  3836. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3837. if (!sas_expander) {
  3838. rc = _scsih_expander_add(ioc, parent_handle);
  3839. if (rc != 0)
  3840. return rc;
  3841. }
  3842. }
  3843. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3844. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  3845. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3846. sas_address);
  3847. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3848. if (sas_expander)
  3849. return 0;
  3850. sas_expander = kzalloc(sizeof(struct _sas_node),
  3851. GFP_KERNEL);
  3852. if (!sas_expander) {
  3853. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3854. ioc->name, __FILE__, __LINE__, __func__);
  3855. return -1;
  3856. }
  3857. sas_expander->handle = handle;
  3858. sas_expander->num_phys = expander_pg0.NumPhys;
  3859. sas_expander->sas_address_parent = sas_address_parent;
  3860. sas_expander->sas_address = sas_address;
  3861. printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
  3862. " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
  3863. handle, parent_handle, (unsigned long long)
  3864. sas_expander->sas_address, sas_expander->num_phys);
  3865. if (!sas_expander->num_phys)
  3866. goto out_fail;
  3867. sas_expander->phy = kcalloc(sas_expander->num_phys,
  3868. sizeof(struct _sas_phy), GFP_KERNEL);
  3869. if (!sas_expander->phy) {
  3870. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3871. ioc->name, __FILE__, __LINE__, __func__);
  3872. rc = -1;
  3873. goto out_fail;
  3874. }
  3875. INIT_LIST_HEAD(&sas_expander->sas_port_list);
  3876. mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
  3877. sas_address_parent);
  3878. if (!mpt2sas_port) {
  3879. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3880. ioc->name, __FILE__, __LINE__, __func__);
  3881. rc = -1;
  3882. goto out_fail;
  3883. }
  3884. sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
  3885. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  3886. if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
  3887. &expander_pg1, i, handle))) {
  3888. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3889. ioc->name, __FILE__, __LINE__, __func__);
  3890. rc = -1;
  3891. goto out_fail;
  3892. }
  3893. sas_expander->phy[i].handle = handle;
  3894. sas_expander->phy[i].phy_id = i;
  3895. if ((mpt2sas_transport_add_expander_phy(ioc,
  3896. &sas_expander->phy[i], expander_pg1,
  3897. sas_expander->parent_dev))) {
  3898. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3899. ioc->name, __FILE__, __LINE__, __func__);
  3900. rc = -1;
  3901. goto out_fail;
  3902. }
  3903. }
  3904. if (sas_expander->enclosure_handle) {
  3905. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3906. &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3907. sas_expander->enclosure_handle))) {
  3908. sas_expander->enclosure_logical_id =
  3909. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3910. }
  3911. }
  3912. _scsih_expander_node_add(ioc, sas_expander);
  3913. return 0;
  3914. out_fail:
  3915. if (mpt2sas_port)
  3916. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  3917. sas_address_parent);
  3918. kfree(sas_expander);
  3919. return rc;
  3920. }
  3921. /**
  3922. * _scsih_done - scsih callback handler.
  3923. * @ioc: per adapter object
  3924. * @smid: system request message index
  3925. * @msix_index: MSIX table index supplied by the OS
  3926. * @reply: reply message frame(lower 32bit addr)
  3927. *
  3928. * Callback handler when sending internal generated message frames.
  3929. * The callback index passed is `ioc->scsih_cb_idx`
  3930. *
  3931. * Return 1 meaning mf should be freed from _base_interrupt
  3932. * 0 means the mf is freed from this function.
  3933. */
  3934. static u8
  3935. _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  3936. {
  3937. MPI2DefaultReply_t *mpi_reply;
  3938. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  3939. if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
  3940. return 1;
  3941. if (ioc->scsih_cmds.smid != smid)
  3942. return 1;
  3943. ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
  3944. if (mpi_reply) {
  3945. memcpy(ioc->scsih_cmds.reply, mpi_reply,
  3946. mpi_reply->MsgLength*4);
  3947. ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
  3948. }
  3949. ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
  3950. complete(&ioc->scsih_cmds.done);
  3951. return 1;
  3952. }
  3953. /**
  3954. * mpt2sas_expander_remove - removing expander object
  3955. * @ioc: per adapter object
  3956. * @sas_address: expander sas_address
  3957. *
  3958. * Return nothing.
  3959. */
  3960. void
  3961. mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  3962. {
  3963. struct _sas_node *sas_expander;
  3964. unsigned long flags;
  3965. if (ioc->shost_recovery)
  3966. return;
  3967. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3968. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3969. sas_address);
  3970. if (!sas_expander) {
  3971. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3972. return;
  3973. }
  3974. list_del(&sas_expander->list);
  3975. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3976. _scsih_expander_node_remove(ioc, sas_expander);
  3977. }
  3978. /**
  3979. * _scsih_check_access_status - check access flags
  3980. * @ioc: per adapter object
  3981. * @sas_address: sas address
  3982. * @handle: sas device handle
  3983. * @access_flags: errors returned during discovery of the device
  3984. *
  3985. * Return 0 for success, else failure
  3986. */
  3987. static u8
  3988. _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  3989. u16 handle, u8 access_status)
  3990. {
  3991. u8 rc = 1;
  3992. char *desc = NULL;
  3993. switch (access_status) {
  3994. case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
  3995. case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
  3996. rc = 0;
  3997. break;
  3998. case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
  3999. desc = "sata capability failed";
  4000. break;
  4001. case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
  4002. desc = "sata affiliation conflict";
  4003. break;
  4004. case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
  4005. desc = "route not addressable";
  4006. break;
  4007. case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
  4008. desc = "smp error not addressable";
  4009. break;
  4010. case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
  4011. desc = "device blocked";
  4012. break;
  4013. case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
  4014. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
  4015. case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
  4016. case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
  4017. case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
  4018. case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
  4019. case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
  4020. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
  4021. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
  4022. case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
  4023. case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
  4024. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
  4025. desc = "sata initialization failed";
  4026. break;
  4027. default:
  4028. desc = "unknown";
  4029. break;
  4030. }
  4031. if (!rc)
  4032. return 0;
  4033. printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
  4034. "handle(0x%04x)\n", ioc->name, desc,
  4035. (unsigned long long)sas_address, handle);
  4036. return rc;
  4037. }
  4038. static void
  4039. _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  4040. {
  4041. Mpi2ConfigReply_t mpi_reply;
  4042. Mpi2SasDevicePage0_t sas_device_pg0;
  4043. struct _sas_device *sas_device;
  4044. u32 ioc_status;
  4045. unsigned long flags;
  4046. u64 sas_address;
  4047. struct scsi_target *starget;
  4048. struct MPT2SAS_TARGET *sas_target_priv_data;
  4049. u32 device_info;
  4050. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4051. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
  4052. return;
  4053. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  4054. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  4055. return;
  4056. /* check if this is end device */
  4057. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4058. if (!(_scsih_is_end_device(device_info)))
  4059. return;
  4060. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4061. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4062. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4063. sas_address);
  4064. if (!sas_device) {
  4065. printk(MPT2SAS_ERR_FMT "device is not present "
  4066. "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
  4067. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4068. return;
  4069. }
  4070. if (unlikely(sas_device->handle != handle)) {
  4071. starget = sas_device->starget;
  4072. sas_target_priv_data = starget->hostdata;
  4073. starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
  4074. " to (0x%04x)!!!\n", sas_device->handle, handle);
  4075. sas_target_priv_data->handle = handle;
  4076. sas_device->handle = handle;
  4077. }
  4078. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4079. /* check if device is present */
  4080. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  4081. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  4082. printk(MPT2SAS_ERR_FMT "device is not present "
  4083. "handle(0x%04x), flags!!!\n", ioc->name, handle);
  4084. return;
  4085. }
  4086. /* check if there were any issues with discovery */
  4087. if (_scsih_check_access_status(ioc, sas_address, handle,
  4088. sas_device_pg0.AccessStatus))
  4089. return;
  4090. _scsih_ublock_io_device(ioc, handle);
  4091. }
  4092. /**
  4093. * _scsih_add_device - creating sas device object
  4094. * @ioc: per adapter object
  4095. * @handle: sas device handle
  4096. * @phy_num: phy number end device attached to
  4097. * @is_pd: is this hidden raid component
  4098. *
  4099. * Creating end device object, stored in ioc->sas_device_list.
  4100. *
  4101. * Returns 0 for success, non-zero for failure.
  4102. */
  4103. static int
  4104. _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
  4105. {
  4106. Mpi2ConfigReply_t mpi_reply;
  4107. Mpi2SasDevicePage0_t sas_device_pg0;
  4108. Mpi2SasEnclosurePage0_t enclosure_pg0;
  4109. struct _sas_device *sas_device;
  4110. u32 ioc_status;
  4111. __le64 sas_address;
  4112. u32 device_info;
  4113. unsigned long flags;
  4114. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4115. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  4116. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4117. ioc->name, __FILE__, __LINE__, __func__);
  4118. return -1;
  4119. }
  4120. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4121. MPI2_IOCSTATUS_MASK;
  4122. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4123. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4124. ioc->name, __FILE__, __LINE__, __func__);
  4125. return -1;
  4126. }
  4127. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4128. /* check if device is present */
  4129. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  4130. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  4131. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4132. ioc->name, __FILE__, __LINE__, __func__);
  4133. printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
  4134. ioc->name, le16_to_cpu(sas_device_pg0.Flags));
  4135. return -1;
  4136. }
  4137. /* check if there were any issues with discovery */
  4138. if (_scsih_check_access_status(ioc, sas_address, handle,
  4139. sas_device_pg0.AccessStatus))
  4140. return -1;
  4141. /* check if this is end device */
  4142. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4143. if (!(_scsih_is_end_device(device_info))) {
  4144. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4145. ioc->name, __FILE__, __LINE__, __func__);
  4146. return -1;
  4147. }
  4148. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4149. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4150. sas_address);
  4151. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4152. if (sas_device)
  4153. return 0;
  4154. sas_device = kzalloc(sizeof(struct _sas_device),
  4155. GFP_KERNEL);
  4156. if (!sas_device) {
  4157. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4158. ioc->name, __FILE__, __LINE__, __func__);
  4159. return -1;
  4160. }
  4161. sas_device->handle = handle;
  4162. if (_scsih_get_sas_address(ioc, le16_to_cpu
  4163. (sas_device_pg0.ParentDevHandle),
  4164. &sas_device->sas_address_parent) != 0)
  4165. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4166. ioc->name, __FILE__, __LINE__, __func__);
  4167. sas_device->enclosure_handle =
  4168. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  4169. sas_device->slot =
  4170. le16_to_cpu(sas_device_pg0.Slot);
  4171. sas_device->device_info = device_info;
  4172. sas_device->sas_address = sas_address;
  4173. sas_device->phy = sas_device_pg0.PhyNum;
  4174. /* get enclosure_logical_id */
  4175. if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
  4176. ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  4177. sas_device->enclosure_handle)))
  4178. sas_device->enclosure_logical_id =
  4179. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  4180. /* get device name */
  4181. sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
  4182. if (ioc->wait_for_port_enable_to_complete)
  4183. _scsih_sas_device_init_add(ioc, sas_device);
  4184. else
  4185. _scsih_sas_device_add(ioc, sas_device);
  4186. return 0;
  4187. }
  4188. /**
  4189. * _scsih_remove_device - removing sas device object
  4190. * @ioc: per adapter object
  4191. * @sas_device_delete: the sas_device object
  4192. *
  4193. * Return nothing.
  4194. */
  4195. static void
  4196. _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
  4197. struct _sas_device *sas_device)
  4198. {
  4199. struct _sas_device sas_device_backup;
  4200. struct MPT2SAS_TARGET *sas_target_priv_data;
  4201. if (!sas_device)
  4202. return;
  4203. memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
  4204. _scsih_sas_device_remove(ioc, sas_device);
  4205. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
  4206. "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  4207. sas_device_backup.handle, (unsigned long long)
  4208. sas_device_backup.sas_address));
  4209. if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
  4210. sas_target_priv_data = sas_device_backup.starget->hostdata;
  4211. sas_target_priv_data->deleted = 1;
  4212. }
  4213. _scsih_ublock_io_device(ioc, sas_device_backup.handle);
  4214. mpt2sas_transport_port_remove(ioc, sas_device_backup.sas_address,
  4215. sas_device_backup.sas_address_parent);
  4216. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
  4217. "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
  4218. (unsigned long long) sas_device_backup.sas_address);
  4219. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
  4220. "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  4221. sas_device_backup.handle, (unsigned long long)
  4222. sas_device_backup.sas_address));
  4223. }
  4224. /**
  4225. * mpt2sas_device_remove - removing device object
  4226. * @ioc: per adapter object
  4227. * @sas_address: expander sas_address
  4228. *
  4229. * Return nothing.
  4230. */
  4231. void
  4232. mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  4233. {
  4234. struct _sas_device *sas_device;
  4235. unsigned long flags;
  4236. if (ioc->shost_recovery)
  4237. return;
  4238. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4239. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4240. sas_address);
  4241. if (!sas_device) {
  4242. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4243. return;
  4244. }
  4245. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4246. _scsih_remove_device(ioc, sas_device);
  4247. }
  4248. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4249. /**
  4250. * _scsih_sas_topology_change_event_debug - debug for topology event
  4251. * @ioc: per adapter object
  4252. * @event_data: event data payload
  4253. * Context: user.
  4254. */
  4255. static void
  4256. _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4257. Mpi2EventDataSasTopologyChangeList_t *event_data)
  4258. {
  4259. int i;
  4260. u16 handle;
  4261. u16 reason_code;
  4262. u8 phy_number;
  4263. char *status_str = NULL;
  4264. u8 link_rate, prev_link_rate;
  4265. switch (event_data->ExpStatus) {
  4266. case MPI2_EVENT_SAS_TOPO_ES_ADDED:
  4267. status_str = "add";
  4268. break;
  4269. case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
  4270. status_str = "remove";
  4271. break;
  4272. case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
  4273. case 0:
  4274. status_str = "responding";
  4275. break;
  4276. case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
  4277. status_str = "remove delay";
  4278. break;
  4279. default:
  4280. status_str = "unknown status";
  4281. break;
  4282. }
  4283. printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
  4284. ioc->name, status_str);
  4285. printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
  4286. "start_phy(%02d), count(%d)\n",
  4287. le16_to_cpu(event_data->ExpanderDevHandle),
  4288. le16_to_cpu(event_data->EnclosureHandle),
  4289. event_data->StartPhyNum, event_data->NumEntries);
  4290. for (i = 0; i < event_data->NumEntries; i++) {
  4291. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  4292. if (!handle)
  4293. continue;
  4294. phy_number = event_data->StartPhyNum + i;
  4295. reason_code = event_data->PHY[i].PhyStatus &
  4296. MPI2_EVENT_SAS_TOPO_RC_MASK;
  4297. switch (reason_code) {
  4298. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  4299. status_str = "target add";
  4300. break;
  4301. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  4302. status_str = "target remove";
  4303. break;
  4304. case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
  4305. status_str = "delay target remove";
  4306. break;
  4307. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  4308. status_str = "link rate change";
  4309. break;
  4310. case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
  4311. status_str = "target responding";
  4312. break;
  4313. default:
  4314. status_str = "unknown";
  4315. break;
  4316. }
  4317. link_rate = event_data->PHY[i].LinkRate >> 4;
  4318. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  4319. printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
  4320. " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
  4321. handle, status_str, link_rate, prev_link_rate);
  4322. }
  4323. }
  4324. #endif
  4325. /**
  4326. * _scsih_sas_topology_change_event - handle topology changes
  4327. * @ioc: per adapter object
  4328. * @fw_event: The fw_event_work object
  4329. * Context: user.
  4330. *
  4331. */
  4332. static void
  4333. _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
  4334. struct fw_event_work *fw_event)
  4335. {
  4336. int i;
  4337. u16 parent_handle, handle;
  4338. u16 reason_code;
  4339. u8 phy_number;
  4340. struct _sas_node *sas_expander;
  4341. struct _sas_device *sas_device;
  4342. u64 sas_address;
  4343. unsigned long flags;
  4344. u8 link_rate, prev_link_rate;
  4345. Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
  4346. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4347. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4348. _scsih_sas_topology_change_event_debug(ioc, event_data);
  4349. #endif
  4350. if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
  4351. return;
  4352. if (!ioc->sas_hba.num_phys)
  4353. _scsih_sas_host_add(ioc);
  4354. else
  4355. _scsih_sas_host_refresh(ioc);
  4356. if (fw_event->ignore) {
  4357. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
  4358. "event\n", ioc->name));
  4359. return;
  4360. }
  4361. parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  4362. /* handle expander add */
  4363. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
  4364. if (_scsih_expander_add(ioc, parent_handle) != 0)
  4365. return;
  4366. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4367. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  4368. parent_handle);
  4369. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4370. if (sas_expander)
  4371. sas_address = sas_expander->sas_address;
  4372. else if (parent_handle < ioc->sas_hba.num_phys)
  4373. sas_address = ioc->sas_hba.sas_address;
  4374. else
  4375. return;
  4376. /* handle siblings events */
  4377. for (i = 0; i < event_data->NumEntries; i++) {
  4378. if (fw_event->ignore) {
  4379. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
  4380. "expander event\n", ioc->name));
  4381. return;
  4382. }
  4383. if (ioc->shost_recovery || ioc->remove_host ||
  4384. ioc->pci_error_recovery)
  4385. return;
  4386. phy_number = event_data->StartPhyNum + i;
  4387. reason_code = event_data->PHY[i].PhyStatus &
  4388. MPI2_EVENT_SAS_TOPO_RC_MASK;
  4389. if ((event_data->PHY[i].PhyStatus &
  4390. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
  4391. MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
  4392. continue;
  4393. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  4394. if (!handle)
  4395. continue;
  4396. link_rate = event_data->PHY[i].LinkRate >> 4;
  4397. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  4398. switch (reason_code) {
  4399. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  4400. if (link_rate == prev_link_rate)
  4401. break;
  4402. mpt2sas_transport_update_links(ioc, sas_address,
  4403. handle, phy_number, link_rate);
  4404. if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  4405. break;
  4406. _scsih_check_device(ioc, handle);
  4407. break;
  4408. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  4409. mpt2sas_transport_update_links(ioc, sas_address,
  4410. handle, phy_number, link_rate);
  4411. _scsih_add_device(ioc, handle, phy_number, 0);
  4412. break;
  4413. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  4414. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4415. sas_device = _scsih_sas_device_find_by_handle(ioc,
  4416. handle);
  4417. if (!sas_device) {
  4418. spin_unlock_irqrestore(&ioc->sas_device_lock,
  4419. flags);
  4420. break;
  4421. }
  4422. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4423. _scsih_remove_device(ioc, sas_device);
  4424. break;
  4425. }
  4426. }
  4427. /* handle expander removal */
  4428. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
  4429. sas_expander)
  4430. mpt2sas_expander_remove(ioc, sas_address);
  4431. }
  4432. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4433. /**
  4434. * _scsih_sas_device_status_change_event_debug - debug for device event
  4435. * @event_data: event data payload
  4436. * Context: user.
  4437. *
  4438. * Return nothing.
  4439. */
  4440. static void
  4441. _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4442. Mpi2EventDataSasDeviceStatusChange_t *event_data)
  4443. {
  4444. char *reason_str = NULL;
  4445. switch (event_data->ReasonCode) {
  4446. case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  4447. reason_str = "smart data";
  4448. break;
  4449. case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  4450. reason_str = "unsupported device discovered";
  4451. break;
  4452. case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  4453. reason_str = "internal device reset";
  4454. break;
  4455. case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  4456. reason_str = "internal task abort";
  4457. break;
  4458. case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  4459. reason_str = "internal task abort set";
  4460. break;
  4461. case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  4462. reason_str = "internal clear task set";
  4463. break;
  4464. case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  4465. reason_str = "internal query task";
  4466. break;
  4467. case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
  4468. reason_str = "sata init failure";
  4469. break;
  4470. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  4471. reason_str = "internal device reset complete";
  4472. break;
  4473. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  4474. reason_str = "internal task abort complete";
  4475. break;
  4476. case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
  4477. reason_str = "internal async notification";
  4478. break;
  4479. case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
  4480. reason_str = "expander reduced functionality";
  4481. break;
  4482. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
  4483. reason_str = "expander reduced functionality complete";
  4484. break;
  4485. default:
  4486. reason_str = "unknown reason";
  4487. break;
  4488. }
  4489. printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
  4490. "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
  4491. reason_str, le16_to_cpu(event_data->DevHandle),
  4492. (unsigned long long)le64_to_cpu(event_data->SASAddress));
  4493. if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
  4494. printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  4495. event_data->ASC, event_data->ASCQ);
  4496. printk(KERN_INFO "\n");
  4497. }
  4498. #endif
  4499. /**
  4500. * _scsih_sas_device_status_change_event - handle device status change
  4501. * @ioc: per adapter object
  4502. * @fw_event: The fw_event_work object
  4503. * Context: user.
  4504. *
  4505. * Return nothing.
  4506. */
  4507. static void
  4508. _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  4509. struct fw_event_work *fw_event)
  4510. {
  4511. struct MPT2SAS_TARGET *target_priv_data;
  4512. struct _sas_device *sas_device;
  4513. __le64 sas_address;
  4514. unsigned long flags;
  4515. Mpi2EventDataSasDeviceStatusChange_t *event_data =
  4516. fw_event->event_data;
  4517. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4518. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4519. _scsih_sas_device_status_change_event_debug(ioc,
  4520. event_data);
  4521. #endif
  4522. if (event_data->ReasonCode !=
  4523. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
  4524. event_data->ReasonCode !=
  4525. MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
  4526. return;
  4527. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4528. sas_address = le64_to_cpu(event_data->SASAddress);
  4529. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4530. sas_address);
  4531. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4532. if (!sas_device || !sas_device->starget)
  4533. return;
  4534. target_priv_data = sas_device->starget->hostdata;
  4535. if (!target_priv_data)
  4536. return;
  4537. if (event_data->ReasonCode ==
  4538. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
  4539. target_priv_data->tm_busy = 1;
  4540. else
  4541. target_priv_data->tm_busy = 0;
  4542. }
  4543. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4544. /**
  4545. * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
  4546. * @ioc: per adapter object
  4547. * @event_data: event data payload
  4548. * Context: user.
  4549. *
  4550. * Return nothing.
  4551. */
  4552. static void
  4553. _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4554. Mpi2EventDataSasEnclDevStatusChange_t *event_data)
  4555. {
  4556. char *reason_str = NULL;
  4557. switch (event_data->ReasonCode) {
  4558. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  4559. reason_str = "enclosure add";
  4560. break;
  4561. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  4562. reason_str = "enclosure remove";
  4563. break;
  4564. default:
  4565. reason_str = "unknown reason";
  4566. break;
  4567. }
  4568. printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
  4569. "\thandle(0x%04x), enclosure logical id(0x%016llx)"
  4570. " number slots(%d)\n", ioc->name, reason_str,
  4571. le16_to_cpu(event_data->EnclosureHandle),
  4572. (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
  4573. le16_to_cpu(event_data->StartSlot));
  4574. }
  4575. #endif
  4576. /**
  4577. * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
  4578. * @ioc: per adapter object
  4579. * @fw_event: The fw_event_work object
  4580. * Context: user.
  4581. *
  4582. * Return nothing.
  4583. */
  4584. static void
  4585. _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  4586. struct fw_event_work *fw_event)
  4587. {
  4588. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4589. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4590. _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
  4591. fw_event->event_data);
  4592. #endif
  4593. }
  4594. /**
  4595. * _scsih_sas_broadcast_primative_event - handle broadcast events
  4596. * @ioc: per adapter object
  4597. * @fw_event: The fw_event_work object
  4598. * Context: user.
  4599. *
  4600. * Return nothing.
  4601. */
  4602. static void
  4603. _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
  4604. struct fw_event_work *fw_event)
  4605. {
  4606. struct scsi_cmnd *scmd;
  4607. u16 smid, handle;
  4608. u32 lun;
  4609. struct MPT2SAS_DEVICE *sas_device_priv_data;
  4610. u32 termination_count;
  4611. u32 query_count;
  4612. Mpi2SCSITaskManagementReply_t *mpi_reply;
  4613. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4614. Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
  4615. #endif
  4616. u16 ioc_status;
  4617. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "broadcast primative: "
  4618. "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
  4619. event_data->PortWidth));
  4620. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
  4621. __func__));
  4622. termination_count = 0;
  4623. query_count = 0;
  4624. mpi_reply = ioc->tm_cmds.reply;
  4625. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  4626. scmd = _scsih_scsi_lookup_get(ioc, smid);
  4627. if (!scmd)
  4628. continue;
  4629. sas_device_priv_data = scmd->device->hostdata;
  4630. if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
  4631. continue;
  4632. /* skip hidden raid components */
  4633. if (sas_device_priv_data->sas_target->flags &
  4634. MPT_TARGET_FLAGS_RAID_COMPONENT)
  4635. continue;
  4636. /* skip volumes */
  4637. if (sas_device_priv_data->sas_target->flags &
  4638. MPT_TARGET_FLAGS_VOLUME)
  4639. continue;
  4640. handle = sas_device_priv_data->sas_target->handle;
  4641. lun = sas_device_priv_data->lun;
  4642. query_count++;
  4643. mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
  4644. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, NULL);
  4645. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  4646. ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
  4647. & MPI2_IOCSTATUS_MASK;
  4648. if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) &&
  4649. (mpi_reply->ResponseCode ==
  4650. MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
  4651. mpi_reply->ResponseCode ==
  4652. MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
  4653. continue;
  4654. mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
  4655. MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30, NULL);
  4656. termination_count += le32_to_cpu(mpi_reply->TerminationCount);
  4657. }
  4658. ioc->broadcast_aen_busy = 0;
  4659. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
  4660. "%s - exit, query_count = %d termination_count = %d\n",
  4661. ioc->name, __func__, query_count, termination_count));
  4662. }
  4663. /**
  4664. * _scsih_sas_discovery_event - handle discovery events
  4665. * @ioc: per adapter object
  4666. * @fw_event: The fw_event_work object
  4667. * Context: user.
  4668. *
  4669. * Return nothing.
  4670. */
  4671. static void
  4672. _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
  4673. struct fw_event_work *fw_event)
  4674. {
  4675. Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
  4676. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4677. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
  4678. printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
  4679. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  4680. "start" : "stop");
  4681. if (event_data->DiscoveryStatus)
  4682. printk("discovery_status(0x%08x)",
  4683. le32_to_cpu(event_data->DiscoveryStatus));
  4684. printk("\n");
  4685. }
  4686. #endif
  4687. if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
  4688. !ioc->sas_hba.num_phys)
  4689. _scsih_sas_host_add(ioc);
  4690. }
  4691. /**
  4692. * _scsih_reprobe_lun - reprobing lun
  4693. * @sdev: scsi device struct
  4694. * @no_uld_attach: sdev->no_uld_attach flag setting
  4695. *
  4696. **/
  4697. static void
  4698. _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
  4699. {
  4700. int rc;
  4701. sdev->no_uld_attach = no_uld_attach ? 1 : 0;
  4702. sdev_printk(KERN_INFO, sdev, "%s raid component\n",
  4703. sdev->no_uld_attach ? "hidding" : "exposing");
  4704. rc = scsi_device_reprobe(sdev);
  4705. }
  4706. /**
  4707. * _scsih_reprobe_target - reprobing target
  4708. * @starget: scsi target struct
  4709. * @no_uld_attach: sdev->no_uld_attach flag setting
  4710. *
  4711. * Note: no_uld_attach flag determines whether the disk device is attached
  4712. * to block layer. A value of `1` means to not attach.
  4713. **/
  4714. static void
  4715. _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
  4716. {
  4717. struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
  4718. if (no_uld_attach)
  4719. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  4720. else
  4721. sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  4722. starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
  4723. _scsih_reprobe_lun);
  4724. }
  4725. /**
  4726. * _scsih_sas_volume_add - add new volume
  4727. * @ioc: per adapter object
  4728. * @element: IR config element data
  4729. * Context: user.
  4730. *
  4731. * Return nothing.
  4732. */
  4733. static void
  4734. _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
  4735. Mpi2EventIrConfigElement_t *element)
  4736. {
  4737. struct _raid_device *raid_device;
  4738. unsigned long flags;
  4739. u64 wwid;
  4740. u16 handle = le16_to_cpu(element->VolDevHandle);
  4741. int rc;
  4742. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  4743. if (!wwid) {
  4744. printk(MPT2SAS_ERR_FMT
  4745. "failure at %s:%d/%s()!\n", ioc->name,
  4746. __FILE__, __LINE__, __func__);
  4747. return;
  4748. }
  4749. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4750. raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
  4751. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4752. if (raid_device)
  4753. return;
  4754. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  4755. if (!raid_device) {
  4756. printk(MPT2SAS_ERR_FMT
  4757. "failure at %s:%d/%s()!\n", ioc->name,
  4758. __FILE__, __LINE__, __func__);
  4759. return;
  4760. }
  4761. raid_device->id = ioc->sas_id++;
  4762. raid_device->channel = RAID_CHANNEL;
  4763. raid_device->handle = handle;
  4764. raid_device->wwid = wwid;
  4765. _scsih_raid_device_add(ioc, raid_device);
  4766. if (!ioc->wait_for_port_enable_to_complete) {
  4767. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  4768. raid_device->id, 0);
  4769. if (rc)
  4770. _scsih_raid_device_remove(ioc, raid_device);
  4771. } else
  4772. _scsih_determine_boot_device(ioc, raid_device, 1);
  4773. }
  4774. /**
  4775. * _scsih_sas_volume_delete - delete volume
  4776. * @ioc: per adapter object
  4777. * @handle: volume device handle
  4778. * Context: user.
  4779. *
  4780. * Return nothing.
  4781. */
  4782. static void
  4783. _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  4784. {
  4785. struct _raid_device *raid_device;
  4786. unsigned long flags;
  4787. struct MPT2SAS_TARGET *sas_target_priv_data;
  4788. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4789. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  4790. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4791. if (!raid_device)
  4792. return;
  4793. if (raid_device->starget) {
  4794. sas_target_priv_data = raid_device->starget->hostdata;
  4795. sas_target_priv_data->deleted = 1;
  4796. scsi_remove_target(&raid_device->starget->dev);
  4797. }
  4798. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
  4799. "(0x%016llx)\n", ioc->name, raid_device->handle,
  4800. (unsigned long long) raid_device->wwid);
  4801. _scsih_raid_device_remove(ioc, raid_device);
  4802. }
  4803. /**
  4804. * _scsih_sas_pd_expose - expose pd component to /dev/sdX
  4805. * @ioc: per adapter object
  4806. * @element: IR config element data
  4807. * Context: user.
  4808. *
  4809. * Return nothing.
  4810. */
  4811. static void
  4812. _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
  4813. Mpi2EventIrConfigElement_t *element)
  4814. {
  4815. struct _sas_device *sas_device;
  4816. unsigned long flags;
  4817. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4818. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4819. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4820. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4821. if (!sas_device)
  4822. return;
  4823. /* exposing raid component */
  4824. sas_device->volume_handle = 0;
  4825. sas_device->volume_wwid = 0;
  4826. clear_bit(handle, ioc->pd_handles);
  4827. _scsih_reprobe_target(sas_device->starget, 0);
  4828. }
  4829. /**
  4830. * _scsih_sas_pd_hide - hide pd component from /dev/sdX
  4831. * @ioc: per adapter object
  4832. * @element: IR config element data
  4833. * Context: user.
  4834. *
  4835. * Return nothing.
  4836. */
  4837. static void
  4838. _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
  4839. Mpi2EventIrConfigElement_t *element)
  4840. {
  4841. struct _sas_device *sas_device;
  4842. unsigned long flags;
  4843. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4844. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4845. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4846. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4847. if (!sas_device)
  4848. return;
  4849. /* hiding raid component */
  4850. mpt2sas_config_get_volume_handle(ioc, handle,
  4851. &sas_device->volume_handle);
  4852. mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
  4853. &sas_device->volume_wwid);
  4854. set_bit(handle, ioc->pd_handles);
  4855. _scsih_reprobe_target(sas_device->starget, 1);
  4856. }
  4857. /**
  4858. * _scsih_sas_pd_delete - delete pd component
  4859. * @ioc: per adapter object
  4860. * @element: IR config element data
  4861. * Context: user.
  4862. *
  4863. * Return nothing.
  4864. */
  4865. static void
  4866. _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
  4867. Mpi2EventIrConfigElement_t *element)
  4868. {
  4869. struct _sas_device *sas_device;
  4870. unsigned long flags;
  4871. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4872. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4873. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4874. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4875. if (!sas_device)
  4876. return;
  4877. _scsih_remove_device(ioc, sas_device);
  4878. }
  4879. /**
  4880. * _scsih_sas_pd_add - remove pd component
  4881. * @ioc: per adapter object
  4882. * @element: IR config element data
  4883. * Context: user.
  4884. *
  4885. * Return nothing.
  4886. */
  4887. static void
  4888. _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
  4889. Mpi2EventIrConfigElement_t *element)
  4890. {
  4891. struct _sas_device *sas_device;
  4892. unsigned long flags;
  4893. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4894. Mpi2ConfigReply_t mpi_reply;
  4895. Mpi2SasDevicePage0_t sas_device_pg0;
  4896. u32 ioc_status;
  4897. u64 sas_address;
  4898. u16 parent_handle;
  4899. set_bit(handle, ioc->pd_handles);
  4900. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4901. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4902. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4903. if (sas_device)
  4904. return;
  4905. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4906. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  4907. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4908. ioc->name, __FILE__, __LINE__, __func__);
  4909. return;
  4910. }
  4911. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4912. MPI2_IOCSTATUS_MASK;
  4913. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4914. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4915. ioc->name, __FILE__, __LINE__, __func__);
  4916. return;
  4917. }
  4918. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  4919. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  4920. mpt2sas_transport_update_links(ioc, sas_address, handle,
  4921. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  4922. _scsih_add_device(ioc, handle, 0, 1);
  4923. }
  4924. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4925. /**
  4926. * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
  4927. * @ioc: per adapter object
  4928. * @event_data: event data payload
  4929. * Context: user.
  4930. *
  4931. * Return nothing.
  4932. */
  4933. static void
  4934. _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4935. Mpi2EventDataIrConfigChangeList_t *event_data)
  4936. {
  4937. Mpi2EventIrConfigElement_t *element;
  4938. u8 element_type;
  4939. int i;
  4940. char *reason_str = NULL, *element_str = NULL;
  4941. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  4942. printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
  4943. ioc->name, (le32_to_cpu(event_data->Flags) &
  4944. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
  4945. "foreign" : "native", event_data->NumElements);
  4946. for (i = 0; i < event_data->NumElements; i++, element++) {
  4947. switch (element->ReasonCode) {
  4948. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  4949. reason_str = "add";
  4950. break;
  4951. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  4952. reason_str = "remove";
  4953. break;
  4954. case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
  4955. reason_str = "no change";
  4956. break;
  4957. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  4958. reason_str = "hide";
  4959. break;
  4960. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  4961. reason_str = "unhide";
  4962. break;
  4963. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  4964. reason_str = "volume_created";
  4965. break;
  4966. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  4967. reason_str = "volume_deleted";
  4968. break;
  4969. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  4970. reason_str = "pd_created";
  4971. break;
  4972. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  4973. reason_str = "pd_deleted";
  4974. break;
  4975. default:
  4976. reason_str = "unknown reason";
  4977. break;
  4978. }
  4979. element_type = le16_to_cpu(element->ElementFlags) &
  4980. MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
  4981. switch (element_type) {
  4982. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
  4983. element_str = "volume";
  4984. break;
  4985. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
  4986. element_str = "phys disk";
  4987. break;
  4988. case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
  4989. element_str = "hot spare";
  4990. break;
  4991. default:
  4992. element_str = "unknown element";
  4993. break;
  4994. }
  4995. printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
  4996. "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
  4997. reason_str, le16_to_cpu(element->VolDevHandle),
  4998. le16_to_cpu(element->PhysDiskDevHandle),
  4999. element->PhysDiskNum);
  5000. }
  5001. }
  5002. #endif
  5003. /**
  5004. * _scsih_sas_ir_config_change_event - handle ir configuration change events
  5005. * @ioc: per adapter object
  5006. * @fw_event: The fw_event_work object
  5007. * Context: user.
  5008. *
  5009. * Return nothing.
  5010. */
  5011. static void
  5012. _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
  5013. struct fw_event_work *fw_event)
  5014. {
  5015. Mpi2EventIrConfigElement_t *element;
  5016. int i;
  5017. u8 foreign_config;
  5018. Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
  5019. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5020. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5021. _scsih_sas_ir_config_change_event_debug(ioc, event_data);
  5022. #endif
  5023. foreign_config = (le32_to_cpu(event_data->Flags) &
  5024. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
  5025. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  5026. for (i = 0; i < event_data->NumElements; i++, element++) {
  5027. switch (element->ReasonCode) {
  5028. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  5029. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  5030. if (!foreign_config)
  5031. _scsih_sas_volume_add(ioc, element);
  5032. break;
  5033. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  5034. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  5035. if (!foreign_config)
  5036. _scsih_sas_volume_delete(ioc,
  5037. le16_to_cpu(element->VolDevHandle));
  5038. break;
  5039. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  5040. _scsih_sas_pd_hide(ioc, element);
  5041. break;
  5042. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  5043. _scsih_sas_pd_expose(ioc, element);
  5044. break;
  5045. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  5046. _scsih_sas_pd_add(ioc, element);
  5047. break;
  5048. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  5049. _scsih_sas_pd_delete(ioc, element);
  5050. break;
  5051. }
  5052. }
  5053. }
  5054. /**
  5055. * _scsih_sas_ir_volume_event - IR volume event
  5056. * @ioc: per adapter object
  5057. * @fw_event: The fw_event_work object
  5058. * Context: user.
  5059. *
  5060. * Return nothing.
  5061. */
  5062. static void
  5063. _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
  5064. struct fw_event_work *fw_event)
  5065. {
  5066. u64 wwid;
  5067. unsigned long flags;
  5068. struct _raid_device *raid_device;
  5069. u16 handle;
  5070. u32 state;
  5071. int rc;
  5072. Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
  5073. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  5074. return;
  5075. handle = le16_to_cpu(event_data->VolDevHandle);
  5076. state = le32_to_cpu(event_data->NewValue);
  5077. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
  5078. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  5079. le32_to_cpu(event_data->PreviousValue), state));
  5080. switch (state) {
  5081. case MPI2_RAID_VOL_STATE_MISSING:
  5082. case MPI2_RAID_VOL_STATE_FAILED:
  5083. _scsih_sas_volume_delete(ioc, handle);
  5084. break;
  5085. case MPI2_RAID_VOL_STATE_ONLINE:
  5086. case MPI2_RAID_VOL_STATE_DEGRADED:
  5087. case MPI2_RAID_VOL_STATE_OPTIMAL:
  5088. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5089. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  5090. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5091. if (raid_device)
  5092. break;
  5093. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  5094. if (!wwid) {
  5095. printk(MPT2SAS_ERR_FMT
  5096. "failure at %s:%d/%s()!\n", ioc->name,
  5097. __FILE__, __LINE__, __func__);
  5098. break;
  5099. }
  5100. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  5101. if (!raid_device) {
  5102. printk(MPT2SAS_ERR_FMT
  5103. "failure at %s:%d/%s()!\n", ioc->name,
  5104. __FILE__, __LINE__, __func__);
  5105. break;
  5106. }
  5107. raid_device->id = ioc->sas_id++;
  5108. raid_device->channel = RAID_CHANNEL;
  5109. raid_device->handle = handle;
  5110. raid_device->wwid = wwid;
  5111. _scsih_raid_device_add(ioc, raid_device);
  5112. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5113. raid_device->id, 0);
  5114. if (rc)
  5115. _scsih_raid_device_remove(ioc, raid_device);
  5116. break;
  5117. case MPI2_RAID_VOL_STATE_INITIALIZING:
  5118. default:
  5119. break;
  5120. }
  5121. }
  5122. /**
  5123. * _scsih_sas_ir_physical_disk_event - PD event
  5124. * @ioc: per adapter object
  5125. * @fw_event: The fw_event_work object
  5126. * Context: user.
  5127. *
  5128. * Return nothing.
  5129. */
  5130. static void
  5131. _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
  5132. struct fw_event_work *fw_event)
  5133. {
  5134. u16 handle, parent_handle;
  5135. u32 state;
  5136. struct _sas_device *sas_device;
  5137. unsigned long flags;
  5138. Mpi2ConfigReply_t mpi_reply;
  5139. Mpi2SasDevicePage0_t sas_device_pg0;
  5140. u32 ioc_status;
  5141. Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
  5142. u64 sas_address;
  5143. if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
  5144. return;
  5145. handle = le16_to_cpu(event_data->PhysDiskDevHandle);
  5146. state = le32_to_cpu(event_data->NewValue);
  5147. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
  5148. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  5149. le32_to_cpu(event_data->PreviousValue), state));
  5150. switch (state) {
  5151. case MPI2_RAID_PD_STATE_ONLINE:
  5152. case MPI2_RAID_PD_STATE_DEGRADED:
  5153. case MPI2_RAID_PD_STATE_REBUILDING:
  5154. case MPI2_RAID_PD_STATE_OPTIMAL:
  5155. case MPI2_RAID_PD_STATE_HOT_SPARE:
  5156. set_bit(handle, ioc->pd_handles);
  5157. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5158. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5159. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5160. if (sas_device)
  5161. return;
  5162. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  5163. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  5164. handle))) {
  5165. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5166. ioc->name, __FILE__, __LINE__, __func__);
  5167. return;
  5168. }
  5169. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5170. MPI2_IOCSTATUS_MASK;
  5171. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5172. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5173. ioc->name, __FILE__, __LINE__, __func__);
  5174. return;
  5175. }
  5176. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  5177. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  5178. mpt2sas_transport_update_links(ioc, sas_address, handle,
  5179. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  5180. _scsih_add_device(ioc, handle, 0, 1);
  5181. break;
  5182. case MPI2_RAID_PD_STATE_OFFLINE:
  5183. case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
  5184. case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
  5185. default:
  5186. break;
  5187. }
  5188. }
  5189. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5190. /**
  5191. * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
  5192. * @ioc: per adapter object
  5193. * @event_data: event data payload
  5194. * Context: user.
  5195. *
  5196. * Return nothing.
  5197. */
  5198. static void
  5199. _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
  5200. Mpi2EventDataIrOperationStatus_t *event_data)
  5201. {
  5202. char *reason_str = NULL;
  5203. switch (event_data->RAIDOperation) {
  5204. case MPI2_EVENT_IR_RAIDOP_RESYNC:
  5205. reason_str = "resync";
  5206. break;
  5207. case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
  5208. reason_str = "online capacity expansion";
  5209. break;
  5210. case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
  5211. reason_str = "consistency check";
  5212. break;
  5213. case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
  5214. reason_str = "background init";
  5215. break;
  5216. case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
  5217. reason_str = "make data consistent";
  5218. break;
  5219. }
  5220. if (!reason_str)
  5221. return;
  5222. printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
  5223. "\thandle(0x%04x), percent complete(%d)\n",
  5224. ioc->name, reason_str,
  5225. le16_to_cpu(event_data->VolDevHandle),
  5226. event_data->PercentComplete);
  5227. }
  5228. #endif
  5229. /**
  5230. * _scsih_sas_ir_operation_status_event - handle RAID operation events
  5231. * @ioc: per adapter object
  5232. * @fw_event: The fw_event_work object
  5233. * Context: user.
  5234. *
  5235. * Return nothing.
  5236. */
  5237. static void
  5238. _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
  5239. struct fw_event_work *fw_event)
  5240. {
  5241. Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
  5242. static struct _raid_device *raid_device;
  5243. unsigned long flags;
  5244. u16 handle;
  5245. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5246. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5247. _scsih_sas_ir_operation_status_event_debug(ioc,
  5248. event_data);
  5249. #endif
  5250. /* code added for raid transport support */
  5251. if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
  5252. handle = le16_to_cpu(event_data->VolDevHandle);
  5253. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5254. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  5255. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5256. if (!raid_device)
  5257. return;
  5258. if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
  5259. raid_device->percent_complete =
  5260. event_data->PercentComplete;
  5261. }
  5262. }
  5263. /**
  5264. * _scsih_prep_device_scan - initialize parameters prior to device scan
  5265. * @ioc: per adapter object
  5266. *
  5267. * Set the deleted flag prior to device scan. If the device is found during
  5268. * the scan, then we clear the deleted flag.
  5269. */
  5270. static void
  5271. _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
  5272. {
  5273. struct MPT2SAS_DEVICE *sas_device_priv_data;
  5274. struct scsi_device *sdev;
  5275. shost_for_each_device(sdev, ioc->shost) {
  5276. sas_device_priv_data = sdev->hostdata;
  5277. if (sas_device_priv_data && sas_device_priv_data->sas_target)
  5278. sas_device_priv_data->sas_target->deleted = 1;
  5279. }
  5280. }
  5281. /**
  5282. * _scsih_mark_responding_sas_device - mark a sas_devices as responding
  5283. * @ioc: per adapter object
  5284. * @sas_address: sas address
  5285. * @slot: enclosure slot id
  5286. * @handle: device handle
  5287. *
  5288. * After host reset, find out whether devices are still responding.
  5289. * Used in _scsi_remove_unresponsive_sas_devices.
  5290. *
  5291. * Return nothing.
  5292. */
  5293. static void
  5294. _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  5295. u16 slot, u16 handle)
  5296. {
  5297. struct MPT2SAS_TARGET *sas_target_priv_data;
  5298. struct scsi_target *starget;
  5299. struct _sas_device *sas_device;
  5300. unsigned long flags;
  5301. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5302. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  5303. if (sas_device->sas_address == sas_address &&
  5304. sas_device->slot == slot && sas_device->starget) {
  5305. sas_device->responding = 1;
  5306. starget = sas_device->starget;
  5307. if (starget && starget->hostdata) {
  5308. sas_target_priv_data = starget->hostdata;
  5309. sas_target_priv_data->tm_busy = 0;
  5310. sas_target_priv_data->deleted = 0;
  5311. } else
  5312. sas_target_priv_data = NULL;
  5313. starget_printk(KERN_INFO, sas_device->starget,
  5314. "handle(0x%04x), sas_addr(0x%016llx), enclosure "
  5315. "logical id(0x%016llx), slot(%d)\n", handle,
  5316. (unsigned long long)sas_device->sas_address,
  5317. (unsigned long long)
  5318. sas_device->enclosure_logical_id,
  5319. sas_device->slot);
  5320. if (sas_device->handle == handle)
  5321. goto out;
  5322. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  5323. sas_device->handle);
  5324. sas_device->handle = handle;
  5325. if (sas_target_priv_data)
  5326. sas_target_priv_data->handle = handle;
  5327. goto out;
  5328. }
  5329. }
  5330. out:
  5331. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5332. }
  5333. /**
  5334. * _scsih_search_responding_sas_devices -
  5335. * @ioc: per adapter object
  5336. *
  5337. * After host reset, find out whether devices are still responding.
  5338. * If not remove.
  5339. *
  5340. * Return nothing.
  5341. */
  5342. static void
  5343. _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  5344. {
  5345. Mpi2SasDevicePage0_t sas_device_pg0;
  5346. Mpi2ConfigReply_t mpi_reply;
  5347. u16 ioc_status;
  5348. __le64 sas_address;
  5349. u16 handle;
  5350. u32 device_info;
  5351. u16 slot;
  5352. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  5353. if (list_empty(&ioc->sas_device_list))
  5354. return;
  5355. handle = 0xFFFF;
  5356. while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  5357. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  5358. handle))) {
  5359. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5360. MPI2_IOCSTATUS_MASK;
  5361. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  5362. break;
  5363. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  5364. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  5365. if (!(_scsih_is_end_device(device_info)))
  5366. continue;
  5367. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  5368. slot = le16_to_cpu(sas_device_pg0.Slot);
  5369. _scsih_mark_responding_sas_device(ioc, sas_address, slot,
  5370. handle);
  5371. }
  5372. }
  5373. /**
  5374. * _scsih_mark_responding_raid_device - mark a raid_device as responding
  5375. * @ioc: per adapter object
  5376. * @wwid: world wide identifier for raid volume
  5377. * @handle: device handle
  5378. *
  5379. * After host reset, find out whether devices are still responding.
  5380. * Used in _scsi_remove_unresponsive_raid_devices.
  5381. *
  5382. * Return nothing.
  5383. */
  5384. static void
  5385. _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
  5386. u16 handle)
  5387. {
  5388. struct MPT2SAS_TARGET *sas_target_priv_data;
  5389. struct scsi_target *starget;
  5390. struct _raid_device *raid_device;
  5391. unsigned long flags;
  5392. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5393. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  5394. if (raid_device->wwid == wwid && raid_device->starget) {
  5395. starget = raid_device->starget;
  5396. if (starget && starget->hostdata) {
  5397. sas_target_priv_data = starget->hostdata;
  5398. sas_target_priv_data->deleted = 0;
  5399. } else
  5400. sas_target_priv_data = NULL;
  5401. raid_device->responding = 1;
  5402. starget_printk(KERN_INFO, raid_device->starget,
  5403. "handle(0x%04x), wwid(0x%016llx)\n", handle,
  5404. (unsigned long long)raid_device->wwid);
  5405. if (raid_device->handle == handle)
  5406. goto out;
  5407. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  5408. raid_device->handle);
  5409. raid_device->handle = handle;
  5410. if (sas_target_priv_data)
  5411. sas_target_priv_data->handle = handle;
  5412. goto out;
  5413. }
  5414. }
  5415. out:
  5416. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5417. }
  5418. /**
  5419. * _scsih_search_responding_raid_devices -
  5420. * @ioc: per adapter object
  5421. *
  5422. * After host reset, find out whether devices are still responding.
  5423. * If not remove.
  5424. *
  5425. * Return nothing.
  5426. */
  5427. static void
  5428. _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
  5429. {
  5430. Mpi2RaidVolPage1_t volume_pg1;
  5431. Mpi2RaidVolPage0_t volume_pg0;
  5432. Mpi2RaidPhysDiskPage0_t pd_pg0;
  5433. Mpi2ConfigReply_t mpi_reply;
  5434. u16 ioc_status;
  5435. u16 handle;
  5436. u8 phys_disk_num;
  5437. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  5438. if (list_empty(&ioc->raid_device_list))
  5439. return;
  5440. handle = 0xFFFF;
  5441. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  5442. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  5443. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5444. MPI2_IOCSTATUS_MASK;
  5445. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  5446. break;
  5447. handle = le16_to_cpu(volume_pg1.DevHandle);
  5448. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
  5449. &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  5450. sizeof(Mpi2RaidVolPage0_t)))
  5451. continue;
  5452. if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
  5453. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
  5454. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
  5455. _scsih_mark_responding_raid_device(ioc,
  5456. le64_to_cpu(volume_pg1.WWID), handle);
  5457. }
  5458. /* refresh the pd_handles */
  5459. phys_disk_num = 0xFF;
  5460. memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
  5461. while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  5462. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
  5463. phys_disk_num))) {
  5464. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5465. MPI2_IOCSTATUS_MASK;
  5466. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  5467. break;
  5468. phys_disk_num = pd_pg0.PhysDiskNum;
  5469. handle = le16_to_cpu(pd_pg0.DevHandle);
  5470. set_bit(handle, ioc->pd_handles);
  5471. }
  5472. }
  5473. /**
  5474. * _scsih_mark_responding_expander - mark a expander as responding
  5475. * @ioc: per adapter object
  5476. * @sas_address: sas address
  5477. * @handle:
  5478. *
  5479. * After host reset, find out whether devices are still responding.
  5480. * Used in _scsi_remove_unresponsive_expanders.
  5481. *
  5482. * Return nothing.
  5483. */
  5484. static void
  5485. _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  5486. u16 handle)
  5487. {
  5488. struct _sas_node *sas_expander;
  5489. unsigned long flags;
  5490. int i;
  5491. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5492. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  5493. if (sas_expander->sas_address != sas_address)
  5494. continue;
  5495. sas_expander->responding = 1;
  5496. if (sas_expander->handle == handle)
  5497. goto out;
  5498. printk(KERN_INFO "\texpander(0x%016llx): handle changed"
  5499. " from(0x%04x) to (0x%04x)!!!\n",
  5500. (unsigned long long)sas_expander->sas_address,
  5501. sas_expander->handle, handle);
  5502. sas_expander->handle = handle;
  5503. for (i = 0 ; i < sas_expander->num_phys ; i++)
  5504. sas_expander->phy[i].handle = handle;
  5505. goto out;
  5506. }
  5507. out:
  5508. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5509. }
  5510. /**
  5511. * _scsih_search_responding_expanders -
  5512. * @ioc: per adapter object
  5513. *
  5514. * After host reset, find out whether devices are still responding.
  5515. * If not remove.
  5516. *
  5517. * Return nothing.
  5518. */
  5519. static void
  5520. _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
  5521. {
  5522. Mpi2ExpanderPage0_t expander_pg0;
  5523. Mpi2ConfigReply_t mpi_reply;
  5524. u16 ioc_status;
  5525. __le64 sas_address;
  5526. u16 handle;
  5527. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  5528. if (list_empty(&ioc->sas_expander_list))
  5529. return;
  5530. handle = 0xFFFF;
  5531. while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  5532. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  5533. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5534. MPI2_IOCSTATUS_MASK;
  5535. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  5536. break;
  5537. handle = le16_to_cpu(expander_pg0.DevHandle);
  5538. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  5539. printk(KERN_INFO "\texpander present: handle(0x%04x), "
  5540. "sas_addr(0x%016llx)\n", handle,
  5541. (unsigned long long)sas_address);
  5542. _scsih_mark_responding_expander(ioc, sas_address, handle);
  5543. }
  5544. }
  5545. /**
  5546. * _scsih_remove_unresponding_sas_devices - removing unresponding devices
  5547. * @ioc: per adapter object
  5548. *
  5549. * Return nothing.
  5550. */
  5551. static void
  5552. _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  5553. {
  5554. struct _sas_device *sas_device, *sas_device_next;
  5555. struct _sas_node *sas_expander;
  5556. struct _raid_device *raid_device, *raid_device_next;
  5557. list_for_each_entry_safe(sas_device, sas_device_next,
  5558. &ioc->sas_device_list, list) {
  5559. if (sas_device->responding) {
  5560. sas_device->responding = 0;
  5561. continue;
  5562. }
  5563. if (sas_device->starget)
  5564. starget_printk(KERN_INFO, sas_device->starget,
  5565. "removing: handle(0x%04x), sas_addr(0x%016llx), "
  5566. "enclosure logical id(0x%016llx), slot(%d)\n",
  5567. sas_device->handle,
  5568. (unsigned long long)sas_device->sas_address,
  5569. (unsigned long long)
  5570. sas_device->enclosure_logical_id,
  5571. sas_device->slot);
  5572. _scsih_remove_device(ioc, sas_device);
  5573. }
  5574. list_for_each_entry_safe(raid_device, raid_device_next,
  5575. &ioc->raid_device_list, list) {
  5576. if (raid_device->responding) {
  5577. raid_device->responding = 0;
  5578. continue;
  5579. }
  5580. if (raid_device->starget) {
  5581. starget_printk(KERN_INFO, raid_device->starget,
  5582. "removing: handle(0x%04x), wwid(0x%016llx)\n",
  5583. raid_device->handle,
  5584. (unsigned long long)raid_device->wwid);
  5585. scsi_remove_target(&raid_device->starget->dev);
  5586. }
  5587. _scsih_raid_device_remove(ioc, raid_device);
  5588. }
  5589. retry_expander_search:
  5590. sas_expander = NULL;
  5591. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  5592. if (sas_expander->responding) {
  5593. sas_expander->responding = 0;
  5594. continue;
  5595. }
  5596. mpt2sas_expander_remove(ioc, sas_expander->sas_address);
  5597. goto retry_expander_search;
  5598. }
  5599. }
  5600. /**
  5601. * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
  5602. * @ioc: per adapter object
  5603. * @reset_phase: phase
  5604. *
  5605. * The handler for doing any required cleanup or initialization.
  5606. *
  5607. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  5608. * MPT2_IOC_DONE_RESET
  5609. *
  5610. * Return nothing.
  5611. */
  5612. void
  5613. mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  5614. {
  5615. switch (reset_phase) {
  5616. case MPT2_IOC_PRE_RESET:
  5617. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  5618. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  5619. break;
  5620. case MPT2_IOC_AFTER_RESET:
  5621. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  5622. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  5623. if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
  5624. ioc->scsih_cmds.status |= MPT2_CMD_RESET;
  5625. mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
  5626. complete(&ioc->scsih_cmds.done);
  5627. }
  5628. if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
  5629. ioc->tm_cmds.status |= MPT2_CMD_RESET;
  5630. mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
  5631. complete(&ioc->tm_cmds.done);
  5632. }
  5633. _scsih_fw_event_cleanup_queue(ioc);
  5634. _scsih_flush_running_cmds(ioc);
  5635. _scsih_queue_rescan(ioc);
  5636. break;
  5637. case MPT2_IOC_DONE_RESET:
  5638. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  5639. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  5640. _scsih_sas_host_refresh(ioc);
  5641. _scsih_prep_device_scan(ioc);
  5642. _scsih_search_responding_sas_devices(ioc);
  5643. _scsih_search_responding_raid_devices(ioc);
  5644. _scsih_search_responding_expanders(ioc);
  5645. break;
  5646. }
  5647. }
  5648. /**
  5649. * _firmware_event_work - delayed task for processing firmware events
  5650. * @ioc: per adapter object
  5651. * @work: equal to the fw_event_work object
  5652. * Context: user.
  5653. *
  5654. * Return nothing.
  5655. */
  5656. static void
  5657. _firmware_event_work(struct work_struct *work)
  5658. {
  5659. struct fw_event_work *fw_event = container_of(work,
  5660. struct fw_event_work, delayed_work.work);
  5661. unsigned long flags;
  5662. struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
  5663. /* the queue is being flushed so ignore this event */
  5664. if (ioc->remove_host || fw_event->cancel_pending_work ||
  5665. ioc->pci_error_recovery) {
  5666. _scsih_fw_event_free(ioc, fw_event);
  5667. return;
  5668. }
  5669. if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) {
  5670. _scsih_fw_event_free(ioc, fw_event);
  5671. spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
  5672. if (ioc->shost_recovery) {
  5673. init_completion(&ioc->shost_recovery_done);
  5674. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
  5675. flags);
  5676. wait_for_completion(&ioc->shost_recovery_done);
  5677. } else
  5678. spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
  5679. flags);
  5680. _scsih_remove_unresponding_sas_devices(ioc);
  5681. return;
  5682. }
  5683. switch (fw_event->event) {
  5684. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5685. _scsih_sas_topology_change_event(ioc, fw_event);
  5686. break;
  5687. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5688. _scsih_sas_device_status_change_event(ioc,
  5689. fw_event);
  5690. break;
  5691. case MPI2_EVENT_SAS_DISCOVERY:
  5692. _scsih_sas_discovery_event(ioc,
  5693. fw_event);
  5694. break;
  5695. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5696. _scsih_sas_broadcast_primative_event(ioc,
  5697. fw_event);
  5698. break;
  5699. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5700. _scsih_sas_enclosure_dev_status_change_event(ioc,
  5701. fw_event);
  5702. break;
  5703. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5704. _scsih_sas_ir_config_change_event(ioc, fw_event);
  5705. break;
  5706. case MPI2_EVENT_IR_VOLUME:
  5707. _scsih_sas_ir_volume_event(ioc, fw_event);
  5708. break;
  5709. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5710. _scsih_sas_ir_physical_disk_event(ioc, fw_event);
  5711. break;
  5712. case MPI2_EVENT_IR_OPERATION_STATUS:
  5713. _scsih_sas_ir_operation_status_event(ioc, fw_event);
  5714. break;
  5715. }
  5716. _scsih_fw_event_free(ioc, fw_event);
  5717. }
  5718. /**
  5719. * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
  5720. * @ioc: per adapter object
  5721. * @msix_index: MSIX table index supplied by the OS
  5722. * @reply: reply message frame(lower 32bit addr)
  5723. * Context: interrupt.
  5724. *
  5725. * This function merely adds a new work task into ioc->firmware_event_thread.
  5726. * The tasks are worked from _firmware_event_work in user context.
  5727. *
  5728. * Return 1 meaning mf should be freed from _base_interrupt
  5729. * 0 means the mf is freed from this function.
  5730. */
  5731. u8
  5732. mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
  5733. u32 reply)
  5734. {
  5735. struct fw_event_work *fw_event;
  5736. Mpi2EventNotificationReply_t *mpi_reply;
  5737. u16 event;
  5738. u16 sz;
  5739. /* events turned off due to host reset or driver unloading */
  5740. if (ioc->remove_host || ioc->pci_error_recovery)
  5741. return 1;
  5742. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  5743. event = le16_to_cpu(mpi_reply->Event);
  5744. switch (event) {
  5745. /* handle these */
  5746. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5747. {
  5748. Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
  5749. (Mpi2EventDataSasBroadcastPrimitive_t *)
  5750. mpi_reply->EventData;
  5751. if (baen_data->Primitive !=
  5752. MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
  5753. ioc->broadcast_aen_busy)
  5754. return 1;
  5755. ioc->broadcast_aen_busy = 1;
  5756. break;
  5757. }
  5758. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5759. _scsih_check_topo_delete_events(ioc,
  5760. (Mpi2EventDataSasTopologyChangeList_t *)
  5761. mpi_reply->EventData);
  5762. break;
  5763. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5764. _scsih_check_ir_config_unhide_events(ioc,
  5765. (Mpi2EventDataIrConfigChangeList_t *)
  5766. mpi_reply->EventData);
  5767. break;
  5768. case MPI2_EVENT_IR_VOLUME:
  5769. _scsih_check_volume_delete_events(ioc,
  5770. (Mpi2EventDataIrVolume_t *)
  5771. mpi_reply->EventData);
  5772. break;
  5773. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5774. case MPI2_EVENT_IR_OPERATION_STATUS:
  5775. case MPI2_EVENT_SAS_DISCOVERY:
  5776. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5777. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5778. break;
  5779. default: /* ignore the rest */
  5780. return 1;
  5781. }
  5782. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  5783. if (!fw_event) {
  5784. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5785. ioc->name, __FILE__, __LINE__, __func__);
  5786. return 1;
  5787. }
  5788. sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
  5789. fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
  5790. if (!fw_event->event_data) {
  5791. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5792. ioc->name, __FILE__, __LINE__, __func__);
  5793. kfree(fw_event);
  5794. return 1;
  5795. }
  5796. memcpy(fw_event->event_data, mpi_reply->EventData,
  5797. sz);
  5798. fw_event->ioc = ioc;
  5799. fw_event->VF_ID = mpi_reply->VF_ID;
  5800. fw_event->VP_ID = mpi_reply->VP_ID;
  5801. fw_event->event = event;
  5802. _scsih_fw_event_add(ioc, fw_event);
  5803. return 1;
  5804. }
  5805. /* shost template */
  5806. static struct scsi_host_template scsih_driver_template = {
  5807. .module = THIS_MODULE,
  5808. .name = "Fusion MPT SAS Host",
  5809. .proc_name = MPT2SAS_DRIVER_NAME,
  5810. .queuecommand = _scsih_qcmd,
  5811. .target_alloc = _scsih_target_alloc,
  5812. .slave_alloc = _scsih_slave_alloc,
  5813. .slave_configure = _scsih_slave_configure,
  5814. .target_destroy = _scsih_target_destroy,
  5815. .slave_destroy = _scsih_slave_destroy,
  5816. .change_queue_depth = _scsih_change_queue_depth,
  5817. .change_queue_type = _scsih_change_queue_type,
  5818. .eh_abort_handler = _scsih_abort,
  5819. .eh_device_reset_handler = _scsih_dev_reset,
  5820. .eh_target_reset_handler = _scsih_target_reset,
  5821. .eh_host_reset_handler = _scsih_host_reset,
  5822. .bios_param = _scsih_bios_param,
  5823. .can_queue = 1,
  5824. .this_id = -1,
  5825. .sg_tablesize = MPT2SAS_SG_DEPTH,
  5826. .max_sectors = 8192,
  5827. .cmd_per_lun = 7,
  5828. .use_clustering = ENABLE_CLUSTERING,
  5829. .shost_attrs = mpt2sas_host_attrs,
  5830. .sdev_attrs = mpt2sas_dev_attrs,
  5831. };
  5832. /**
  5833. * _scsih_expander_node_remove - removing expander device from list.
  5834. * @ioc: per adapter object
  5835. * @sas_expander: the sas_device object
  5836. * Context: Calling function should acquire ioc->sas_node_lock.
  5837. *
  5838. * Removing object and freeing associated memory from the
  5839. * ioc->sas_expander_list.
  5840. *
  5841. * Return nothing.
  5842. */
  5843. static void
  5844. _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  5845. struct _sas_node *sas_expander)
  5846. {
  5847. struct _sas_port *mpt2sas_port, *next;
  5848. /* remove sibling ports attached to this expander */
  5849. list_for_each_entry_safe(mpt2sas_port, next,
  5850. &sas_expander->sas_port_list, port_list) {
  5851. if (ioc->shost_recovery)
  5852. return;
  5853. if (mpt2sas_port->remote_identify.device_type ==
  5854. SAS_END_DEVICE)
  5855. mpt2sas_device_remove(ioc,
  5856. mpt2sas_port->remote_identify.sas_address);
  5857. else if (mpt2sas_port->remote_identify.device_type ==
  5858. SAS_EDGE_EXPANDER_DEVICE ||
  5859. mpt2sas_port->remote_identify.device_type ==
  5860. SAS_FANOUT_EXPANDER_DEVICE)
  5861. mpt2sas_expander_remove(ioc,
  5862. mpt2sas_port->remote_identify.sas_address);
  5863. }
  5864. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  5865. sas_expander->sas_address_parent);
  5866. printk(MPT2SAS_INFO_FMT "expander_remove: handle"
  5867. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  5868. sas_expander->handle, (unsigned long long)
  5869. sas_expander->sas_address);
  5870. kfree(sas_expander->phy);
  5871. kfree(sas_expander);
  5872. }
  5873. /**
  5874. * _scsih_ir_shutdown - IR shutdown notification
  5875. * @ioc: per adapter object
  5876. *
  5877. * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
  5878. * the host system is shutting down.
  5879. *
  5880. * Return nothing.
  5881. */
  5882. static void
  5883. _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
  5884. {
  5885. Mpi2RaidActionRequest_t *mpi_request;
  5886. Mpi2RaidActionReply_t *mpi_reply;
  5887. u16 smid;
  5888. /* is IR firmware build loaded ? */
  5889. if (!ioc->ir_firmware)
  5890. return;
  5891. /* are there any volumes ? */
  5892. if (list_empty(&ioc->raid_device_list))
  5893. return;
  5894. mutex_lock(&ioc->scsih_cmds.mutex);
  5895. if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
  5896. printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
  5897. ioc->name, __func__);
  5898. goto out;
  5899. }
  5900. ioc->scsih_cmds.status = MPT2_CMD_PENDING;
  5901. smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
  5902. if (!smid) {
  5903. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  5904. ioc->name, __func__);
  5905. ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
  5906. goto out;
  5907. }
  5908. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  5909. ioc->scsih_cmds.smid = smid;
  5910. memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
  5911. mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
  5912. mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
  5913. printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
  5914. init_completion(&ioc->scsih_cmds.done);
  5915. mpt2sas_base_put_smid_default(ioc, smid);
  5916. wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
  5917. if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
  5918. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  5919. ioc->name, __func__);
  5920. goto out;
  5921. }
  5922. if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
  5923. mpi_reply = ioc->scsih_cmds.reply;
  5924. printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
  5925. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  5926. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  5927. le32_to_cpu(mpi_reply->IOCLogInfo));
  5928. }
  5929. out:
  5930. ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
  5931. mutex_unlock(&ioc->scsih_cmds.mutex);
  5932. }
  5933. /**
  5934. * _scsih_shutdown - routine call during system shutdown
  5935. * @pdev: PCI device struct
  5936. *
  5937. * Return nothing.
  5938. */
  5939. static void
  5940. _scsih_shutdown(struct pci_dev *pdev)
  5941. {
  5942. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5943. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5944. struct workqueue_struct *wq;
  5945. unsigned long flags;
  5946. ioc->remove_host = 1;
  5947. _scsih_fw_event_cleanup_queue(ioc);
  5948. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5949. wq = ioc->firmware_event_thread;
  5950. ioc->firmware_event_thread = NULL;
  5951. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5952. if (wq)
  5953. destroy_workqueue(wq);
  5954. _scsih_ir_shutdown(ioc);
  5955. mpt2sas_base_detach(ioc);
  5956. }
  5957. /**
  5958. * _scsih_remove - detach and remove add host
  5959. * @pdev: PCI device struct
  5960. *
  5961. * Routine called when unloading the driver.
  5962. * Return nothing.
  5963. */
  5964. static void __devexit
  5965. _scsih_remove(struct pci_dev *pdev)
  5966. {
  5967. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5968. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5969. struct _sas_port *mpt2sas_port, *next_port;
  5970. struct _raid_device *raid_device, *next;
  5971. struct MPT2SAS_TARGET *sas_target_priv_data;
  5972. struct workqueue_struct *wq;
  5973. unsigned long flags;
  5974. ioc->remove_host = 1;
  5975. _scsih_fw_event_cleanup_queue(ioc);
  5976. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5977. wq = ioc->firmware_event_thread;
  5978. ioc->firmware_event_thread = NULL;
  5979. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5980. if (wq)
  5981. destroy_workqueue(wq);
  5982. /* release all the volumes */
  5983. list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
  5984. list) {
  5985. if (raid_device->starget) {
  5986. sas_target_priv_data =
  5987. raid_device->starget->hostdata;
  5988. sas_target_priv_data->deleted = 1;
  5989. scsi_remove_target(&raid_device->starget->dev);
  5990. }
  5991. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
  5992. "(0x%016llx)\n", ioc->name, raid_device->handle,
  5993. (unsigned long long) raid_device->wwid);
  5994. _scsih_raid_device_remove(ioc, raid_device);
  5995. }
  5996. /* free ports attached to the sas_host */
  5997. list_for_each_entry_safe(mpt2sas_port, next_port,
  5998. &ioc->sas_hba.sas_port_list, port_list) {
  5999. if (mpt2sas_port->remote_identify.device_type ==
  6000. SAS_END_DEVICE)
  6001. mpt2sas_device_remove(ioc,
  6002. mpt2sas_port->remote_identify.sas_address);
  6003. else if (mpt2sas_port->remote_identify.device_type ==
  6004. SAS_EDGE_EXPANDER_DEVICE ||
  6005. mpt2sas_port->remote_identify.device_type ==
  6006. SAS_FANOUT_EXPANDER_DEVICE)
  6007. mpt2sas_expander_remove(ioc,
  6008. mpt2sas_port->remote_identify.sas_address);
  6009. }
  6010. /* free phys attached to the sas_host */
  6011. if (ioc->sas_hba.num_phys) {
  6012. kfree(ioc->sas_hba.phy);
  6013. ioc->sas_hba.phy = NULL;
  6014. ioc->sas_hba.num_phys = 0;
  6015. }
  6016. sas_remove_host(shost);
  6017. _scsih_shutdown(pdev);
  6018. list_del(&ioc->list);
  6019. scsi_remove_host(shost);
  6020. scsi_host_put(shost);
  6021. }
  6022. /**
  6023. * _scsih_probe_boot_devices - reports 1st device
  6024. * @ioc: per adapter object
  6025. *
  6026. * If specified in bios page 2, this routine reports the 1st
  6027. * device scsi-ml or sas transport for persistent boot device
  6028. * purposes. Please refer to function _scsih_determine_boot_device()
  6029. */
  6030. static void
  6031. _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
  6032. {
  6033. u8 is_raid;
  6034. void *device;
  6035. struct _sas_device *sas_device;
  6036. struct _raid_device *raid_device;
  6037. u16 handle;
  6038. u64 sas_address_parent;
  6039. u64 sas_address;
  6040. unsigned long flags;
  6041. int rc;
  6042. device = NULL;
  6043. if (ioc->req_boot_device.device) {
  6044. device = ioc->req_boot_device.device;
  6045. is_raid = ioc->req_boot_device.is_raid;
  6046. } else if (ioc->req_alt_boot_device.device) {
  6047. device = ioc->req_alt_boot_device.device;
  6048. is_raid = ioc->req_alt_boot_device.is_raid;
  6049. } else if (ioc->current_boot_device.device) {
  6050. device = ioc->current_boot_device.device;
  6051. is_raid = ioc->current_boot_device.is_raid;
  6052. }
  6053. if (!device)
  6054. return;
  6055. if (is_raid) {
  6056. raid_device = device;
  6057. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  6058. raid_device->id, 0);
  6059. if (rc)
  6060. _scsih_raid_device_remove(ioc, raid_device);
  6061. } else {
  6062. sas_device = device;
  6063. handle = sas_device->handle;
  6064. sas_address_parent = sas_device->sas_address_parent;
  6065. sas_address = sas_device->sas_address;
  6066. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  6067. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  6068. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  6069. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  6070. sas_device->sas_address_parent)) {
  6071. _scsih_sas_device_remove(ioc, sas_device);
  6072. } else if (!sas_device->starget) {
  6073. mpt2sas_transport_port_remove(ioc, sas_address,
  6074. sas_address_parent);
  6075. _scsih_sas_device_remove(ioc, sas_device);
  6076. }
  6077. }
  6078. }
  6079. /**
  6080. * _scsih_probe_raid - reporting raid volumes to scsi-ml
  6081. * @ioc: per adapter object
  6082. *
  6083. * Called during initial loading of the driver.
  6084. */
  6085. static void
  6086. _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
  6087. {
  6088. struct _raid_device *raid_device, *raid_next;
  6089. int rc;
  6090. list_for_each_entry_safe(raid_device, raid_next,
  6091. &ioc->raid_device_list, list) {
  6092. if (raid_device->starget)
  6093. continue;
  6094. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  6095. raid_device->id, 0);
  6096. if (rc)
  6097. _scsih_raid_device_remove(ioc, raid_device);
  6098. }
  6099. }
  6100. /**
  6101. * _scsih_probe_sas - reporting sas devices to sas transport
  6102. * @ioc: per adapter object
  6103. *
  6104. * Called during initial loading of the driver.
  6105. */
  6106. static void
  6107. _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
  6108. {
  6109. struct _sas_device *sas_device, *next;
  6110. unsigned long flags;
  6111. /* SAS Device List */
  6112. list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
  6113. list) {
  6114. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  6115. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  6116. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  6117. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  6118. sas_device->sas_address_parent)) {
  6119. _scsih_sas_device_remove(ioc, sas_device);
  6120. } else if (!sas_device->starget) {
  6121. mpt2sas_transport_port_remove(ioc,
  6122. sas_device->sas_address,
  6123. sas_device->sas_address_parent);
  6124. _scsih_sas_device_remove(ioc, sas_device);
  6125. }
  6126. }
  6127. }
  6128. /**
  6129. * _scsih_probe_devices - probing for devices
  6130. * @ioc: per adapter object
  6131. *
  6132. * Called during initial loading of the driver.
  6133. */
  6134. static void
  6135. _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
  6136. {
  6137. u16 volume_mapping_flags =
  6138. le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
  6139. MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
  6140. if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
  6141. return; /* return when IOC doesn't support initiator mode */
  6142. _scsih_probe_boot_devices(ioc);
  6143. if (ioc->ir_firmware) {
  6144. if ((volume_mapping_flags &
  6145. MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
  6146. _scsih_probe_sas(ioc);
  6147. _scsih_probe_raid(ioc);
  6148. } else {
  6149. _scsih_probe_raid(ioc);
  6150. _scsih_probe_sas(ioc);
  6151. }
  6152. } else
  6153. _scsih_probe_sas(ioc);
  6154. }
  6155. /**
  6156. * _scsih_probe - attach and add scsi host
  6157. * @pdev: PCI device struct
  6158. * @id: pci device id
  6159. *
  6160. * Returns 0 success, anything else error.
  6161. */
  6162. static int
  6163. _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  6164. {
  6165. struct MPT2SAS_ADAPTER *ioc;
  6166. struct Scsi_Host *shost;
  6167. shost = scsi_host_alloc(&scsih_driver_template,
  6168. sizeof(struct MPT2SAS_ADAPTER));
  6169. if (!shost)
  6170. return -ENODEV;
  6171. /* init local params */
  6172. ioc = shost_priv(shost);
  6173. memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
  6174. INIT_LIST_HEAD(&ioc->list);
  6175. list_add_tail(&ioc->list, &mpt2sas_ioc_list);
  6176. ioc->shost = shost;
  6177. ioc->id = mpt_ids++;
  6178. sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
  6179. ioc->pdev = pdev;
  6180. ioc->scsi_io_cb_idx = scsi_io_cb_idx;
  6181. ioc->tm_cb_idx = tm_cb_idx;
  6182. ioc->ctl_cb_idx = ctl_cb_idx;
  6183. ioc->base_cb_idx = base_cb_idx;
  6184. ioc->transport_cb_idx = transport_cb_idx;
  6185. ioc->scsih_cb_idx = scsih_cb_idx;
  6186. ioc->config_cb_idx = config_cb_idx;
  6187. ioc->tm_tr_cb_idx = tm_tr_cb_idx;
  6188. ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
  6189. ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
  6190. ioc->logging_level = logging_level;
  6191. /* misc semaphores and spin locks */
  6192. mutex_init(&ioc->reset_in_progress_mutex);
  6193. spin_lock_init(&ioc->ioc_reset_in_progress_lock);
  6194. spin_lock_init(&ioc->scsi_lookup_lock);
  6195. spin_lock_init(&ioc->sas_device_lock);
  6196. spin_lock_init(&ioc->sas_node_lock);
  6197. spin_lock_init(&ioc->fw_event_lock);
  6198. spin_lock_init(&ioc->raid_device_lock);
  6199. INIT_LIST_HEAD(&ioc->sas_device_list);
  6200. INIT_LIST_HEAD(&ioc->sas_device_init_list);
  6201. INIT_LIST_HEAD(&ioc->sas_expander_list);
  6202. INIT_LIST_HEAD(&ioc->fw_event_list);
  6203. INIT_LIST_HEAD(&ioc->raid_device_list);
  6204. INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
  6205. INIT_LIST_HEAD(&ioc->delayed_tr_list);
  6206. INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
  6207. /* init shost parameters */
  6208. shost->max_cmd_len = 32;
  6209. shost->max_lun = max_lun;
  6210. shost->transportt = mpt2sas_transport_template;
  6211. shost->unique_id = ioc->id;
  6212. if ((scsi_add_host(shost, &pdev->dev))) {
  6213. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6214. ioc->name, __FILE__, __LINE__, __func__);
  6215. list_del(&ioc->list);
  6216. goto out_add_shost_fail;
  6217. }
  6218. scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
  6219. | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
  6220. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  6221. /* event thread */
  6222. snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
  6223. "fw_event%d", ioc->id);
  6224. ioc->firmware_event_thread = create_singlethread_workqueue(
  6225. ioc->firmware_event_name);
  6226. if (!ioc->firmware_event_thread) {
  6227. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6228. ioc->name, __FILE__, __LINE__, __func__);
  6229. goto out_thread_fail;
  6230. }
  6231. ioc->wait_for_port_enable_to_complete = 1;
  6232. if ((mpt2sas_base_attach(ioc))) {
  6233. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6234. ioc->name, __FILE__, __LINE__, __func__);
  6235. goto out_attach_fail;
  6236. }
  6237. ioc->wait_for_port_enable_to_complete = 0;
  6238. _scsih_probe_devices(ioc);
  6239. return 0;
  6240. out_attach_fail:
  6241. destroy_workqueue(ioc->firmware_event_thread);
  6242. out_thread_fail:
  6243. list_del(&ioc->list);
  6244. scsi_remove_host(shost);
  6245. out_add_shost_fail:
  6246. return -ENODEV;
  6247. }
  6248. #ifdef CONFIG_PM
  6249. /**
  6250. * _scsih_suspend - power management suspend main entry point
  6251. * @pdev: PCI device struct
  6252. * @state: PM state change to (usually PCI_D3)
  6253. *
  6254. * Returns 0 success, anything else error.
  6255. */
  6256. static int
  6257. _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
  6258. {
  6259. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6260. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6261. u32 device_state;
  6262. mpt2sas_base_stop_watchdog(ioc);
  6263. flush_scheduled_work();
  6264. scsi_block_requests(shost);
  6265. device_state = pci_choose_state(pdev, state);
  6266. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
  6267. "operating state [D%d]\n", ioc->name, pdev,
  6268. pci_name(pdev), device_state);
  6269. mpt2sas_base_free_resources(ioc);
  6270. pci_save_state(pdev);
  6271. pci_disable_device(pdev);
  6272. pci_set_power_state(pdev, device_state);
  6273. return 0;
  6274. }
  6275. /**
  6276. * _scsih_resume - power management resume main entry point
  6277. * @pdev: PCI device struct
  6278. *
  6279. * Returns 0 success, anything else error.
  6280. */
  6281. static int
  6282. _scsih_resume(struct pci_dev *pdev)
  6283. {
  6284. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6285. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6286. u32 device_state = pdev->current_state;
  6287. int r;
  6288. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
  6289. "operating state [D%d]\n", ioc->name, pdev,
  6290. pci_name(pdev), device_state);
  6291. pci_set_power_state(pdev, PCI_D0);
  6292. pci_enable_wake(pdev, PCI_D0, 0);
  6293. pci_restore_state(pdev);
  6294. ioc->pdev = pdev;
  6295. r = mpt2sas_base_map_resources(ioc);
  6296. if (r)
  6297. return r;
  6298. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
  6299. scsi_unblock_requests(shost);
  6300. mpt2sas_base_start_watchdog(ioc);
  6301. return 0;
  6302. }
  6303. #endif /* CONFIG_PM */
  6304. /**
  6305. * _scsih_pci_error_detected - Called when a PCI error is detected.
  6306. * @pdev: PCI device struct
  6307. * @state: PCI channel state
  6308. *
  6309. * Description: Called when a PCI error is detected.
  6310. *
  6311. * Return value:
  6312. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  6313. */
  6314. static pci_ers_result_t
  6315. _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  6316. {
  6317. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6318. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6319. printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
  6320. ioc->name, state);
  6321. switch (state) {
  6322. case pci_channel_io_normal:
  6323. return PCI_ERS_RESULT_CAN_RECOVER;
  6324. case pci_channel_io_frozen:
  6325. /* Fatal error, prepare for slot reset */
  6326. ioc->pci_error_recovery = 1;
  6327. scsi_block_requests(ioc->shost);
  6328. mpt2sas_base_stop_watchdog(ioc);
  6329. mpt2sas_base_free_resources(ioc);
  6330. return PCI_ERS_RESULT_NEED_RESET;
  6331. case pci_channel_io_perm_failure:
  6332. /* Permanent error, prepare for device removal */
  6333. ioc->pci_error_recovery = 1;
  6334. mpt2sas_base_stop_watchdog(ioc);
  6335. _scsih_flush_running_cmds(ioc);
  6336. return PCI_ERS_RESULT_DISCONNECT;
  6337. }
  6338. return PCI_ERS_RESULT_NEED_RESET;
  6339. }
  6340. /**
  6341. * _scsih_pci_slot_reset - Called when PCI slot has been reset.
  6342. * @pdev: PCI device struct
  6343. *
  6344. * Description: This routine is called by the pci error recovery
  6345. * code after the PCI slot has been reset, just before we
  6346. * should resume normal operations.
  6347. */
  6348. static pci_ers_result_t
  6349. _scsih_pci_slot_reset(struct pci_dev *pdev)
  6350. {
  6351. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6352. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6353. int rc;
  6354. printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
  6355. ioc->name);
  6356. ioc->pci_error_recovery = 0;
  6357. ioc->pdev = pdev;
  6358. pci_restore_state(pdev);
  6359. rc = mpt2sas_base_map_resources(ioc);
  6360. if (rc)
  6361. return PCI_ERS_RESULT_DISCONNECT;
  6362. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  6363. FORCE_BIG_HAMMER);
  6364. printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
  6365. (rc == 0) ? "success" : "failed");
  6366. if (!rc)
  6367. return PCI_ERS_RESULT_RECOVERED;
  6368. else
  6369. return PCI_ERS_RESULT_DISCONNECT;
  6370. }
  6371. /**
  6372. * _scsih_pci_resume() - resume normal ops after PCI reset
  6373. * @pdev: pointer to PCI device
  6374. *
  6375. * Called when the error recovery driver tells us that its
  6376. * OK to resume normal operation. Use completion to allow
  6377. * halted scsi ops to resume.
  6378. */
  6379. static void
  6380. _scsih_pci_resume(struct pci_dev *pdev)
  6381. {
  6382. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6383. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6384. printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
  6385. pci_cleanup_aer_uncorrect_error_status(pdev);
  6386. mpt2sas_base_start_watchdog(ioc);
  6387. scsi_unblock_requests(ioc->shost);
  6388. }
  6389. /**
  6390. * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
  6391. * @pdev: pointer to PCI device
  6392. */
  6393. static pci_ers_result_t
  6394. _scsih_pci_mmio_enabled(struct pci_dev *pdev)
  6395. {
  6396. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6397. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6398. printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
  6399. ioc->name);
  6400. /* TODO - dump whatever for debugging purposes */
  6401. /* Request a slot reset. */
  6402. return PCI_ERS_RESULT_NEED_RESET;
  6403. }
  6404. static struct pci_error_handlers _scsih_err_handler = {
  6405. .error_detected = _scsih_pci_error_detected,
  6406. .mmio_enabled = _scsih_pci_mmio_enabled,
  6407. .slot_reset = _scsih_pci_slot_reset,
  6408. .resume = _scsih_pci_resume,
  6409. };
  6410. static struct pci_driver scsih_driver = {
  6411. .name = MPT2SAS_DRIVER_NAME,
  6412. .id_table = scsih_pci_table,
  6413. .probe = _scsih_probe,
  6414. .remove = __devexit_p(_scsih_remove),
  6415. .shutdown = _scsih_shutdown,
  6416. .err_handler = &_scsih_err_handler,
  6417. #ifdef CONFIG_PM
  6418. .suspend = _scsih_suspend,
  6419. .resume = _scsih_resume,
  6420. #endif
  6421. };
  6422. /* raid transport support */
  6423. static struct raid_function_template mpt2sas_raid_functions = {
  6424. .cookie = &scsih_driver_template,
  6425. .is_raid = _scsih_is_raid,
  6426. .get_resync = _scsih_get_resync,
  6427. .get_state = _scsih_get_state,
  6428. };
  6429. /**
  6430. * _scsih_init - main entry point for this driver.
  6431. *
  6432. * Returns 0 success, anything else error.
  6433. */
  6434. static int __init
  6435. _scsih_init(void)
  6436. {
  6437. int error;
  6438. mpt_ids = 0;
  6439. printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
  6440. MPT2SAS_DRIVER_VERSION);
  6441. mpt2sas_transport_template =
  6442. sas_attach_transport(&mpt2sas_transport_functions);
  6443. if (!mpt2sas_transport_template)
  6444. return -ENODEV;
  6445. /* raid transport support */
  6446. mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
  6447. if (!mpt2sas_raid_template) {
  6448. sas_release_transport(mpt2sas_transport_template);
  6449. return -ENODEV;
  6450. }
  6451. mpt2sas_base_initialize_callback_handler();
  6452. /* queuecommand callback hander */
  6453. scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
  6454. /* task management callback handler */
  6455. tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
  6456. /* base internal commands callback handler */
  6457. base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
  6458. /* transport internal commands callback handler */
  6459. transport_cb_idx = mpt2sas_base_register_callback_handler(
  6460. mpt2sas_transport_done);
  6461. /* scsih internal commands callback handler */
  6462. scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
  6463. /* configuration page API internal commands callback handler */
  6464. config_cb_idx = mpt2sas_base_register_callback_handler(
  6465. mpt2sas_config_done);
  6466. /* ctl module callback handler */
  6467. ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
  6468. tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
  6469. _scsih_tm_tr_complete);
  6470. tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
  6471. _scsih_tm_volume_tr_complete);
  6472. tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
  6473. _scsih_sas_control_complete);
  6474. mpt2sas_ctl_init();
  6475. error = pci_register_driver(&scsih_driver);
  6476. if (error) {
  6477. /* raid transport support */
  6478. raid_class_release(mpt2sas_raid_template);
  6479. sas_release_transport(mpt2sas_transport_template);
  6480. }
  6481. return error;
  6482. }
  6483. /**
  6484. * _scsih_exit - exit point for this driver (when it is a module).
  6485. *
  6486. * Returns 0 success, anything else error.
  6487. */
  6488. static void __exit
  6489. _scsih_exit(void)
  6490. {
  6491. printk(KERN_INFO "mpt2sas version %s unloading\n",
  6492. MPT2SAS_DRIVER_VERSION);
  6493. pci_unregister_driver(&scsih_driver);
  6494. mpt2sas_ctl_exit();
  6495. mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
  6496. mpt2sas_base_release_callback_handler(tm_cb_idx);
  6497. mpt2sas_base_release_callback_handler(base_cb_idx);
  6498. mpt2sas_base_release_callback_handler(transport_cb_idx);
  6499. mpt2sas_base_release_callback_handler(scsih_cb_idx);
  6500. mpt2sas_base_release_callback_handler(config_cb_idx);
  6501. mpt2sas_base_release_callback_handler(ctl_cb_idx);
  6502. mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
  6503. mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
  6504. mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
  6505. /* raid transport support */
  6506. raid_class_release(mpt2sas_raid_template);
  6507. sas_release_transport(mpt2sas_transport_template);
  6508. }
  6509. module_init(_scsih_init);
  6510. module_exit(_scsih_exit);