mpt2sas_scsih.c 235 KB

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