mpt2sas_scsih.c 234 KB

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