mpt2sas_scsih.c 205 KB

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