mpt2sas_scsih.c 222 KB

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