mpt2sas_scsih.c 221 KB

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