mpt2sas_scsih.c 191 KB

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