mpt2sas_scsih.c 236 KB

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