ipr.c 200 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411
  1. /*
  2. * ipr.c -- driver for IBM Power Linux RAID adapters
  3. *
  4. * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) 2003, 2004 IBM Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. /*
  24. * Notes:
  25. *
  26. * This driver is used to control the following SCSI adapters:
  27. *
  28. * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
  29. *
  30. * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
  31. * PCI-X Dual Channel Ultra 320 SCSI Adapter
  32. * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
  33. * Embedded SCSI adapter on p615 and p655 systems
  34. *
  35. * Supported Hardware Features:
  36. * - Ultra 320 SCSI controller
  37. * - PCI-X host interface
  38. * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
  39. * - Non-Volatile Write Cache
  40. * - Supports attachment of non-RAID disks, tape, and optical devices
  41. * - RAID Levels 0, 5, 10
  42. * - Hot spare
  43. * - Background Parity Checking
  44. * - Background Data Scrubbing
  45. * - Ability to increase the capacity of an existing RAID 5 disk array
  46. * by adding disks
  47. *
  48. * Driver Features:
  49. * - Tagged command queuing
  50. * - Adapter microcode download
  51. * - PCI hot plug
  52. * - SCSI device hot plug
  53. *
  54. */
  55. #include <linux/fs.h>
  56. #include <linux/init.h>
  57. #include <linux/types.h>
  58. #include <linux/errno.h>
  59. #include <linux/kernel.h>
  60. #include <linux/ioport.h>
  61. #include <linux/delay.h>
  62. #include <linux/pci.h>
  63. #include <linux/wait.h>
  64. #include <linux/spinlock.h>
  65. #include <linux/sched.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/blkdev.h>
  68. #include <linux/firmware.h>
  69. #include <linux/module.h>
  70. #include <linux/moduleparam.h>
  71. #include <linux/libata.h>
  72. #include <asm/io.h>
  73. #include <asm/irq.h>
  74. #include <asm/processor.h>
  75. #include <scsi/scsi.h>
  76. #include <scsi/scsi_host.h>
  77. #include <scsi/scsi_tcq.h>
  78. #include <scsi/scsi_eh.h>
  79. #include <scsi/scsi_cmnd.h>
  80. #include "ipr.h"
  81. /*
  82. * Global Data
  83. */
  84. static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
  85. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  86. static unsigned int ipr_max_speed = 1;
  87. static int ipr_testmode = 0;
  88. static unsigned int ipr_fastfail = 0;
  89. static unsigned int ipr_transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  90. static unsigned int ipr_enable_cache = 1;
  91. static unsigned int ipr_debug = 0;
  92. static int ipr_auto_create = 1;
  93. static DEFINE_SPINLOCK(ipr_driver_lock);
  94. /* This table describes the differences between DMA controller chips */
  95. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  96. { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  97. .mailbox = 0x0042C,
  98. .cache_line_size = 0x20,
  99. {
  100. .set_interrupt_mask_reg = 0x0022C,
  101. .clr_interrupt_mask_reg = 0x00230,
  102. .sense_interrupt_mask_reg = 0x0022C,
  103. .clr_interrupt_reg = 0x00228,
  104. .sense_interrupt_reg = 0x00224,
  105. .ioarrin_reg = 0x00404,
  106. .sense_uproc_interrupt_reg = 0x00214,
  107. .set_uproc_interrupt_reg = 0x00214,
  108. .clr_uproc_interrupt_reg = 0x00218
  109. }
  110. },
  111. { /* Snipe and Scamp */
  112. .mailbox = 0x0052C,
  113. .cache_line_size = 0x20,
  114. {
  115. .set_interrupt_mask_reg = 0x00288,
  116. .clr_interrupt_mask_reg = 0x0028C,
  117. .sense_interrupt_mask_reg = 0x00288,
  118. .clr_interrupt_reg = 0x00284,
  119. .sense_interrupt_reg = 0x00280,
  120. .ioarrin_reg = 0x00504,
  121. .sense_uproc_interrupt_reg = 0x00290,
  122. .set_uproc_interrupt_reg = 0x00290,
  123. .clr_uproc_interrupt_reg = 0x00294
  124. }
  125. },
  126. };
  127. static const struct ipr_chip_t ipr_chip[] = {
  128. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
  129. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
  130. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
  131. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
  132. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
  133. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
  134. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
  135. };
  136. static int ipr_max_bus_speeds [] = {
  137. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  138. };
  139. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  140. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  141. module_param_named(max_speed, ipr_max_speed, uint, 0);
  142. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  143. module_param_named(log_level, ipr_log_level, uint, 0);
  144. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  145. module_param_named(testmode, ipr_testmode, int, 0);
  146. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  147. module_param_named(fastfail, ipr_fastfail, int, 0);
  148. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  149. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  150. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  151. module_param_named(enable_cache, ipr_enable_cache, int, 0);
  152. MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
  153. module_param_named(debug, ipr_debug, int, 0);
  154. MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
  155. module_param_named(auto_create, ipr_auto_create, int, 0);
  156. MODULE_PARM_DESC(auto_create, "Auto-create single device RAID 0 arrays when initialized (default: 1)");
  157. MODULE_LICENSE("GPL");
  158. MODULE_VERSION(IPR_DRIVER_VERSION);
  159. /* A constant array of IOASCs/URCs/Error Messages */
  160. static const
  161. struct ipr_error_table_t ipr_error_table[] = {
  162. {0x00000000, 1, 1,
  163. "8155: An unknown error was received"},
  164. {0x00330000, 0, 0,
  165. "Soft underlength error"},
  166. {0x005A0000, 0, 0,
  167. "Command to be cancelled not found"},
  168. {0x00808000, 0, 0,
  169. "Qualified success"},
  170. {0x01080000, 1, 1,
  171. "FFFE: Soft device bus error recovered by the IOA"},
  172. {0x01088100, 0, 1,
  173. "4101: Soft device bus fabric error"},
  174. {0x01170600, 0, 1,
  175. "FFF9: Device sector reassign successful"},
  176. {0x01170900, 0, 1,
  177. "FFF7: Media error recovered by device rewrite procedures"},
  178. {0x01180200, 0, 1,
  179. "7001: IOA sector reassignment successful"},
  180. {0x01180500, 0, 1,
  181. "FFF9: Soft media error. Sector reassignment recommended"},
  182. {0x01180600, 0, 1,
  183. "FFF7: Media error recovered by IOA rewrite procedures"},
  184. {0x01418000, 0, 1,
  185. "FF3D: Soft PCI bus error recovered by the IOA"},
  186. {0x01440000, 1, 1,
  187. "FFF6: Device hardware error recovered by the IOA"},
  188. {0x01448100, 0, 1,
  189. "FFF6: Device hardware error recovered by the device"},
  190. {0x01448200, 1, 1,
  191. "FF3D: Soft IOA error recovered by the IOA"},
  192. {0x01448300, 0, 1,
  193. "FFFA: Undefined device response recovered by the IOA"},
  194. {0x014A0000, 1, 1,
  195. "FFF6: Device bus error, message or command phase"},
  196. {0x014A8000, 0, 1,
  197. "FFFE: Task Management Function failed"},
  198. {0x015D0000, 0, 1,
  199. "FFF6: Failure prediction threshold exceeded"},
  200. {0x015D9200, 0, 1,
  201. "8009: Impending cache battery pack failure"},
  202. {0x02040400, 0, 0,
  203. "34FF: Disk device format in progress"},
  204. {0x023F0000, 0, 0,
  205. "Synchronization required"},
  206. {0x024E0000, 0, 0,
  207. "No ready, IOA shutdown"},
  208. {0x025A0000, 0, 0,
  209. "Not ready, IOA has been shutdown"},
  210. {0x02670100, 0, 1,
  211. "3020: Storage subsystem configuration error"},
  212. {0x03110B00, 0, 0,
  213. "FFF5: Medium error, data unreadable, recommend reassign"},
  214. {0x03110C00, 0, 0,
  215. "7000: Medium error, data unreadable, do not reassign"},
  216. {0x03310000, 0, 1,
  217. "FFF3: Disk media format bad"},
  218. {0x04050000, 0, 1,
  219. "3002: Addressed device failed to respond to selection"},
  220. {0x04080000, 1, 1,
  221. "3100: Device bus error"},
  222. {0x04080100, 0, 1,
  223. "3109: IOA timed out a device command"},
  224. {0x04088000, 0, 0,
  225. "3120: SCSI bus is not operational"},
  226. {0x04088100, 0, 1,
  227. "4100: Hard device bus fabric error"},
  228. {0x04118000, 0, 1,
  229. "9000: IOA reserved area data check"},
  230. {0x04118100, 0, 1,
  231. "9001: IOA reserved area invalid data pattern"},
  232. {0x04118200, 0, 1,
  233. "9002: IOA reserved area LRC error"},
  234. {0x04320000, 0, 1,
  235. "102E: Out of alternate sectors for disk storage"},
  236. {0x04330000, 1, 1,
  237. "FFF4: Data transfer underlength error"},
  238. {0x04338000, 1, 1,
  239. "FFF4: Data transfer overlength error"},
  240. {0x043E0100, 0, 1,
  241. "3400: Logical unit failure"},
  242. {0x04408500, 0, 1,
  243. "FFF4: Device microcode is corrupt"},
  244. {0x04418000, 1, 1,
  245. "8150: PCI bus error"},
  246. {0x04430000, 1, 0,
  247. "Unsupported device bus message received"},
  248. {0x04440000, 1, 1,
  249. "FFF4: Disk device problem"},
  250. {0x04448200, 1, 1,
  251. "8150: Permanent IOA failure"},
  252. {0x04448300, 0, 1,
  253. "3010: Disk device returned wrong response to IOA"},
  254. {0x04448400, 0, 1,
  255. "8151: IOA microcode error"},
  256. {0x04448500, 0, 0,
  257. "Device bus status error"},
  258. {0x04448600, 0, 1,
  259. "8157: IOA error requiring IOA reset to recover"},
  260. {0x04448700, 0, 0,
  261. "ATA device status error"},
  262. {0x04490000, 0, 0,
  263. "Message reject received from the device"},
  264. {0x04449200, 0, 1,
  265. "8008: A permanent cache battery pack failure occurred"},
  266. {0x0444A000, 0, 1,
  267. "9090: Disk unit has been modified after the last known status"},
  268. {0x0444A200, 0, 1,
  269. "9081: IOA detected device error"},
  270. {0x0444A300, 0, 1,
  271. "9082: IOA detected device error"},
  272. {0x044A0000, 1, 1,
  273. "3110: Device bus error, message or command phase"},
  274. {0x044A8000, 1, 1,
  275. "3110: SAS Command / Task Management Function failed"},
  276. {0x04670400, 0, 1,
  277. "9091: Incorrect hardware configuration change has been detected"},
  278. {0x04678000, 0, 1,
  279. "9073: Invalid multi-adapter configuration"},
  280. {0x04678100, 0, 1,
  281. "4010: Incorrect connection between cascaded expanders"},
  282. {0x04678200, 0, 1,
  283. "4020: Connections exceed IOA design limits"},
  284. {0x04678300, 0, 1,
  285. "4030: Incorrect multipath connection"},
  286. {0x04679000, 0, 1,
  287. "4110: Unsupported enclosure function"},
  288. {0x046E0000, 0, 1,
  289. "FFF4: Command to logical unit failed"},
  290. {0x05240000, 1, 0,
  291. "Illegal request, invalid request type or request packet"},
  292. {0x05250000, 0, 0,
  293. "Illegal request, invalid resource handle"},
  294. {0x05258000, 0, 0,
  295. "Illegal request, commands not allowed to this device"},
  296. {0x05258100, 0, 0,
  297. "Illegal request, command not allowed to a secondary adapter"},
  298. {0x05260000, 0, 0,
  299. "Illegal request, invalid field in parameter list"},
  300. {0x05260100, 0, 0,
  301. "Illegal request, parameter not supported"},
  302. {0x05260200, 0, 0,
  303. "Illegal request, parameter value invalid"},
  304. {0x052C0000, 0, 0,
  305. "Illegal request, command sequence error"},
  306. {0x052C8000, 1, 0,
  307. "Illegal request, dual adapter support not enabled"},
  308. {0x06040500, 0, 1,
  309. "9031: Array protection temporarily suspended, protection resuming"},
  310. {0x06040600, 0, 1,
  311. "9040: Array protection temporarily suspended, protection resuming"},
  312. {0x06288000, 0, 1,
  313. "3140: Device bus not ready to ready transition"},
  314. {0x06290000, 0, 1,
  315. "FFFB: SCSI bus was reset"},
  316. {0x06290500, 0, 0,
  317. "FFFE: SCSI bus transition to single ended"},
  318. {0x06290600, 0, 0,
  319. "FFFE: SCSI bus transition to LVD"},
  320. {0x06298000, 0, 1,
  321. "FFFB: SCSI bus was reset by another initiator"},
  322. {0x063F0300, 0, 1,
  323. "3029: A device replacement has occurred"},
  324. {0x064C8000, 0, 1,
  325. "9051: IOA cache data exists for a missing or failed device"},
  326. {0x064C8100, 0, 1,
  327. "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
  328. {0x06670100, 0, 1,
  329. "9025: Disk unit is not supported at its physical location"},
  330. {0x06670600, 0, 1,
  331. "3020: IOA detected a SCSI bus configuration error"},
  332. {0x06678000, 0, 1,
  333. "3150: SCSI bus configuration error"},
  334. {0x06678100, 0, 1,
  335. "9074: Asymmetric advanced function disk configuration"},
  336. {0x06678300, 0, 1,
  337. "4040: Incomplete multipath connection between IOA and enclosure"},
  338. {0x06678400, 0, 1,
  339. "4041: Incomplete multipath connection between enclosure and device"},
  340. {0x06678500, 0, 1,
  341. "9075: Incomplete multipath connection between IOA and remote IOA"},
  342. {0x06678600, 0, 1,
  343. "9076: Configuration error, missing remote IOA"},
  344. {0x06679100, 0, 1,
  345. "4050: Enclosure does not support a required multipath function"},
  346. {0x06690200, 0, 1,
  347. "9041: Array protection temporarily suspended"},
  348. {0x06698200, 0, 1,
  349. "9042: Corrupt array parity detected on specified device"},
  350. {0x066B0200, 0, 1,
  351. "9030: Array no longer protected due to missing or failed disk unit"},
  352. {0x066B8000, 0, 1,
  353. "9071: Link operational transition"},
  354. {0x066B8100, 0, 1,
  355. "9072: Link not operational transition"},
  356. {0x066B8200, 0, 1,
  357. "9032: Array exposed but still protected"},
  358. {0x066B9100, 0, 1,
  359. "4061: Multipath redundancy level got better"},
  360. {0x066B9200, 0, 1,
  361. "4060: Multipath redundancy level got worse"},
  362. {0x07270000, 0, 0,
  363. "Failure due to other device"},
  364. {0x07278000, 0, 1,
  365. "9008: IOA does not support functions expected by devices"},
  366. {0x07278100, 0, 1,
  367. "9010: Cache data associated with attached devices cannot be found"},
  368. {0x07278200, 0, 1,
  369. "9011: Cache data belongs to devices other than those attached"},
  370. {0x07278400, 0, 1,
  371. "9020: Array missing 2 or more devices with only 1 device present"},
  372. {0x07278500, 0, 1,
  373. "9021: Array missing 2 or more devices with 2 or more devices present"},
  374. {0x07278600, 0, 1,
  375. "9022: Exposed array is missing a required device"},
  376. {0x07278700, 0, 1,
  377. "9023: Array member(s) not at required physical locations"},
  378. {0x07278800, 0, 1,
  379. "9024: Array not functional due to present hardware configuration"},
  380. {0x07278900, 0, 1,
  381. "9026: Array not functional due to present hardware configuration"},
  382. {0x07278A00, 0, 1,
  383. "9027: Array is missing a device and parity is out of sync"},
  384. {0x07278B00, 0, 1,
  385. "9028: Maximum number of arrays already exist"},
  386. {0x07278C00, 0, 1,
  387. "9050: Required cache data cannot be located for a disk unit"},
  388. {0x07278D00, 0, 1,
  389. "9052: Cache data exists for a device that has been modified"},
  390. {0x07278F00, 0, 1,
  391. "9054: IOA resources not available due to previous problems"},
  392. {0x07279100, 0, 1,
  393. "9092: Disk unit requires initialization before use"},
  394. {0x07279200, 0, 1,
  395. "9029: Incorrect hardware configuration change has been detected"},
  396. {0x07279600, 0, 1,
  397. "9060: One or more disk pairs are missing from an array"},
  398. {0x07279700, 0, 1,
  399. "9061: One or more disks are missing from an array"},
  400. {0x07279800, 0, 1,
  401. "9062: One or more disks are missing from an array"},
  402. {0x07279900, 0, 1,
  403. "9063: Maximum number of functional arrays has been exceeded"},
  404. {0x0B260000, 0, 0,
  405. "Aborted command, invalid descriptor"},
  406. {0x0B5A0000, 0, 0,
  407. "Command terminated by host"}
  408. };
  409. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  410. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  411. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  412. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  413. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  414. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  415. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  416. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  417. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  418. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  419. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  420. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  421. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  422. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  423. };
  424. /*
  425. * Function Prototypes
  426. */
  427. static int ipr_reset_alert(struct ipr_cmnd *);
  428. static void ipr_process_ccn(struct ipr_cmnd *);
  429. static void ipr_process_error(struct ipr_cmnd *);
  430. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  431. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  432. enum ipr_shutdown_type);
  433. #ifdef CONFIG_SCSI_IPR_TRACE
  434. /**
  435. * ipr_trc_hook - Add a trace entry to the driver trace
  436. * @ipr_cmd: ipr command struct
  437. * @type: trace type
  438. * @add_data: additional data
  439. *
  440. * Return value:
  441. * none
  442. **/
  443. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  444. u8 type, u32 add_data)
  445. {
  446. struct ipr_trace_entry *trace_entry;
  447. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  448. trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
  449. trace_entry->time = jiffies;
  450. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  451. trace_entry->type = type;
  452. trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
  453. trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
  454. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  455. trace_entry->u.add_data = add_data;
  456. }
  457. #else
  458. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
  459. #endif
  460. /**
  461. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  462. * @ipr_cmd: ipr command struct
  463. *
  464. * Return value:
  465. * none
  466. **/
  467. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  468. {
  469. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  470. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  471. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  472. ioarcb->write_data_transfer_length = 0;
  473. ioarcb->read_data_transfer_length = 0;
  474. ioarcb->write_ioadl_len = 0;
  475. ioarcb->read_ioadl_len = 0;
  476. ioasa->ioasc = 0;
  477. ioasa->residual_data_len = 0;
  478. ioasa->u.gata.status = 0;
  479. ipr_cmd->scsi_cmd = NULL;
  480. ipr_cmd->qc = NULL;
  481. ipr_cmd->sense_buffer[0] = 0;
  482. ipr_cmd->dma_use_sg = 0;
  483. }
  484. /**
  485. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  486. * @ipr_cmd: ipr command struct
  487. *
  488. * Return value:
  489. * none
  490. **/
  491. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  492. {
  493. ipr_reinit_ipr_cmnd(ipr_cmd);
  494. ipr_cmd->u.scratch = 0;
  495. ipr_cmd->sibling = NULL;
  496. init_timer(&ipr_cmd->timer);
  497. }
  498. /**
  499. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  500. * @ioa_cfg: ioa config struct
  501. *
  502. * Return value:
  503. * pointer to ipr command struct
  504. **/
  505. static
  506. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  507. {
  508. struct ipr_cmnd *ipr_cmd;
  509. ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
  510. list_del(&ipr_cmd->queue);
  511. ipr_init_ipr_cmnd(ipr_cmd);
  512. return ipr_cmd;
  513. }
  514. /**
  515. * ipr_unmap_sglist - Unmap scatterlist if mapped
  516. * @ioa_cfg: ioa config struct
  517. * @ipr_cmd: ipr command struct
  518. *
  519. * Return value:
  520. * nothing
  521. **/
  522. static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
  523. struct ipr_cmnd *ipr_cmd)
  524. {
  525. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  526. if (ipr_cmd->dma_use_sg) {
  527. if (scsi_cmd->use_sg > 0) {
  528. pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
  529. scsi_cmd->use_sg,
  530. scsi_cmd->sc_data_direction);
  531. } else {
  532. pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
  533. scsi_cmd->request_bufflen,
  534. scsi_cmd->sc_data_direction);
  535. }
  536. }
  537. }
  538. /**
  539. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  540. * @ioa_cfg: ioa config struct
  541. * @clr_ints: interrupts to clear
  542. *
  543. * This function masks all interrupts on the adapter, then clears the
  544. * interrupts specified in the mask
  545. *
  546. * Return value:
  547. * none
  548. **/
  549. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  550. u32 clr_ints)
  551. {
  552. volatile u32 int_reg;
  553. /* Stop new interrupts */
  554. ioa_cfg->allow_interrupts = 0;
  555. /* Set interrupt mask to stop all new interrupts */
  556. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  557. /* Clear any pending interrupts */
  558. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
  559. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  560. }
  561. /**
  562. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  563. * @ioa_cfg: ioa config struct
  564. *
  565. * Return value:
  566. * 0 on success / -EIO on failure
  567. **/
  568. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  569. {
  570. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  571. if (pcix_cmd_reg == 0) {
  572. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  573. return -EIO;
  574. }
  575. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  576. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  577. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  578. return -EIO;
  579. }
  580. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  581. return 0;
  582. }
  583. /**
  584. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  585. * @ioa_cfg: ioa config struct
  586. *
  587. * Return value:
  588. * 0 on success / -EIO on failure
  589. **/
  590. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  591. {
  592. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  593. if (pcix_cmd_reg) {
  594. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  595. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  596. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  597. return -EIO;
  598. }
  599. } else {
  600. dev_err(&ioa_cfg->pdev->dev,
  601. "Failed to setup PCI-X command register\n");
  602. return -EIO;
  603. }
  604. return 0;
  605. }
  606. /**
  607. * ipr_sata_eh_done - done function for aborted SATA commands
  608. * @ipr_cmd: ipr command struct
  609. *
  610. * This function is invoked for ops generated to SATA
  611. * devices which are being aborted.
  612. *
  613. * Return value:
  614. * none
  615. **/
  616. static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  617. {
  618. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  619. struct ata_queued_cmd *qc = ipr_cmd->qc;
  620. struct ipr_sata_port *sata_port = qc->ap->private_data;
  621. qc->err_mask |= AC_ERR_OTHER;
  622. sata_port->ioasa.status |= ATA_BUSY;
  623. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  624. ata_qc_complete(qc);
  625. }
  626. /**
  627. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  628. * @ipr_cmd: ipr command struct
  629. *
  630. * This function is invoked by the interrupt handler for
  631. * ops generated by the SCSI mid-layer which are being aborted.
  632. *
  633. * Return value:
  634. * none
  635. **/
  636. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  637. {
  638. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  639. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  640. scsi_cmd->result |= (DID_ERROR << 16);
  641. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  642. scsi_cmd->scsi_done(scsi_cmd);
  643. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  644. }
  645. /**
  646. * ipr_fail_all_ops - Fails all outstanding ops.
  647. * @ioa_cfg: ioa config struct
  648. *
  649. * This function fails all outstanding ops.
  650. *
  651. * Return value:
  652. * none
  653. **/
  654. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  655. {
  656. struct ipr_cmnd *ipr_cmd, *temp;
  657. ENTER;
  658. list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
  659. list_del(&ipr_cmd->queue);
  660. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  661. ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
  662. if (ipr_cmd->scsi_cmd)
  663. ipr_cmd->done = ipr_scsi_eh_done;
  664. else if (ipr_cmd->qc)
  665. ipr_cmd->done = ipr_sata_eh_done;
  666. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
  667. del_timer(&ipr_cmd->timer);
  668. ipr_cmd->done(ipr_cmd);
  669. }
  670. LEAVE;
  671. }
  672. /**
  673. * ipr_do_req - Send driver initiated requests.
  674. * @ipr_cmd: ipr command struct
  675. * @done: done function
  676. * @timeout_func: timeout function
  677. * @timeout: timeout value
  678. *
  679. * This function sends the specified command to the adapter with the
  680. * timeout given. The done function is invoked on command completion.
  681. *
  682. * Return value:
  683. * none
  684. **/
  685. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  686. void (*done) (struct ipr_cmnd *),
  687. void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
  688. {
  689. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  690. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  691. ipr_cmd->done = done;
  692. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  693. ipr_cmd->timer.expires = jiffies + timeout;
  694. ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
  695. add_timer(&ipr_cmd->timer);
  696. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  697. mb();
  698. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  699. ioa_cfg->regs.ioarrin_reg);
  700. }
  701. /**
  702. * ipr_internal_cmd_done - Op done function for an internally generated op.
  703. * @ipr_cmd: ipr command struct
  704. *
  705. * This function is the op done function for an internally generated,
  706. * blocking op. It simply wakes the sleeping thread.
  707. *
  708. * Return value:
  709. * none
  710. **/
  711. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  712. {
  713. if (ipr_cmd->sibling)
  714. ipr_cmd->sibling = NULL;
  715. else
  716. complete(&ipr_cmd->completion);
  717. }
  718. /**
  719. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  720. * @ipr_cmd: ipr command struct
  721. * @timeout_func: function to invoke if command times out
  722. * @timeout: timeout
  723. *
  724. * Return value:
  725. * none
  726. **/
  727. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  728. void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
  729. u32 timeout)
  730. {
  731. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  732. init_completion(&ipr_cmd->completion);
  733. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  734. spin_unlock_irq(ioa_cfg->host->host_lock);
  735. wait_for_completion(&ipr_cmd->completion);
  736. spin_lock_irq(ioa_cfg->host->host_lock);
  737. }
  738. /**
  739. * ipr_send_hcam - Send an HCAM to the adapter.
  740. * @ioa_cfg: ioa config struct
  741. * @type: HCAM type
  742. * @hostrcb: hostrcb struct
  743. *
  744. * This function will send a Host Controlled Async command to the adapter.
  745. * If HCAMs are currently not allowed to be issued to the adapter, it will
  746. * place the hostrcb on the free queue.
  747. *
  748. * Return value:
  749. * none
  750. **/
  751. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  752. struct ipr_hostrcb *hostrcb)
  753. {
  754. struct ipr_cmnd *ipr_cmd;
  755. struct ipr_ioarcb *ioarcb;
  756. if (ioa_cfg->allow_cmds) {
  757. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  758. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  759. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  760. ipr_cmd->u.hostrcb = hostrcb;
  761. ioarcb = &ipr_cmd->ioarcb;
  762. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  763. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  764. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  765. ioarcb->cmd_pkt.cdb[1] = type;
  766. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  767. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  768. ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
  769. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  770. ipr_cmd->ioadl[0].flags_and_data_len =
  771. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
  772. ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
  773. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  774. ipr_cmd->done = ipr_process_ccn;
  775. else
  776. ipr_cmd->done = ipr_process_error;
  777. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  778. mb();
  779. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  780. ioa_cfg->regs.ioarrin_reg);
  781. } else {
  782. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  783. }
  784. }
  785. /**
  786. * ipr_init_res_entry - Initialize a resource entry struct.
  787. * @res: resource entry struct
  788. *
  789. * Return value:
  790. * none
  791. **/
  792. static void ipr_init_res_entry(struct ipr_resource_entry *res)
  793. {
  794. res->needs_sync_complete = 0;
  795. res->in_erp = 0;
  796. res->add_to_ml = 0;
  797. res->del_from_ml = 0;
  798. res->resetting_device = 0;
  799. res->sdev = NULL;
  800. res->sata_port = NULL;
  801. }
  802. /**
  803. * ipr_handle_config_change - Handle a config change from the adapter
  804. * @ioa_cfg: ioa config struct
  805. * @hostrcb: hostrcb
  806. *
  807. * Return value:
  808. * none
  809. **/
  810. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  811. struct ipr_hostrcb *hostrcb)
  812. {
  813. struct ipr_resource_entry *res = NULL;
  814. struct ipr_config_table_entry *cfgte;
  815. u32 is_ndn = 1;
  816. cfgte = &hostrcb->hcam.u.ccn.cfgte;
  817. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  818. if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
  819. sizeof(cfgte->res_addr))) {
  820. is_ndn = 0;
  821. break;
  822. }
  823. }
  824. if (is_ndn) {
  825. if (list_empty(&ioa_cfg->free_res_q)) {
  826. ipr_send_hcam(ioa_cfg,
  827. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  828. hostrcb);
  829. return;
  830. }
  831. res = list_entry(ioa_cfg->free_res_q.next,
  832. struct ipr_resource_entry, queue);
  833. list_del(&res->queue);
  834. ipr_init_res_entry(res);
  835. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  836. }
  837. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  838. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  839. if (res->sdev) {
  840. res->del_from_ml = 1;
  841. res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
  842. if (ioa_cfg->allow_ml_add_del)
  843. schedule_work(&ioa_cfg->work_q);
  844. } else
  845. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  846. } else if (!res->sdev) {
  847. res->add_to_ml = 1;
  848. if (ioa_cfg->allow_ml_add_del)
  849. schedule_work(&ioa_cfg->work_q);
  850. }
  851. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  852. }
  853. /**
  854. * ipr_process_ccn - Op done function for a CCN.
  855. * @ipr_cmd: ipr command struct
  856. *
  857. * This function is the op done function for a configuration
  858. * change notification host controlled async from the adapter.
  859. *
  860. * Return value:
  861. * none
  862. **/
  863. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  864. {
  865. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  866. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  867. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  868. list_del(&hostrcb->queue);
  869. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  870. if (ioasc) {
  871. if (ioasc != IPR_IOASC_IOA_WAS_RESET)
  872. dev_err(&ioa_cfg->pdev->dev,
  873. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  874. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  875. } else {
  876. ipr_handle_config_change(ioa_cfg, hostrcb);
  877. }
  878. }
  879. /**
  880. * ipr_log_vpd - Log the passed VPD to the error log.
  881. * @vpd: vendor/product id/sn struct
  882. *
  883. * Return value:
  884. * none
  885. **/
  886. static void ipr_log_vpd(struct ipr_vpd *vpd)
  887. {
  888. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  889. + IPR_SERIAL_NUM_LEN];
  890. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  891. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  892. IPR_PROD_ID_LEN);
  893. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  894. ipr_err("Vendor/Product ID: %s\n", buffer);
  895. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  896. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  897. ipr_err(" Serial Number: %s\n", buffer);
  898. }
  899. /**
  900. * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
  901. * @vpd: vendor/product id/sn/wwn struct
  902. *
  903. * Return value:
  904. * none
  905. **/
  906. static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
  907. {
  908. ipr_log_vpd(&vpd->vpd);
  909. ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
  910. be32_to_cpu(vpd->wwid[1]));
  911. }
  912. /**
  913. * ipr_log_enhanced_cache_error - Log a cache error.
  914. * @ioa_cfg: ioa config struct
  915. * @hostrcb: hostrcb struct
  916. *
  917. * Return value:
  918. * none
  919. **/
  920. static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  921. struct ipr_hostrcb *hostrcb)
  922. {
  923. struct ipr_hostrcb_type_12_error *error =
  924. &hostrcb->hcam.u.error.u.type_12_error;
  925. ipr_err("-----Current Configuration-----\n");
  926. ipr_err("Cache Directory Card Information:\n");
  927. ipr_log_ext_vpd(&error->ioa_vpd);
  928. ipr_err("Adapter Card Information:\n");
  929. ipr_log_ext_vpd(&error->cfc_vpd);
  930. ipr_err("-----Expected Configuration-----\n");
  931. ipr_err("Cache Directory Card Information:\n");
  932. ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
  933. ipr_err("Adapter Card Information:\n");
  934. ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
  935. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  936. be32_to_cpu(error->ioa_data[0]),
  937. be32_to_cpu(error->ioa_data[1]),
  938. be32_to_cpu(error->ioa_data[2]));
  939. }
  940. /**
  941. * ipr_log_cache_error - Log a cache error.
  942. * @ioa_cfg: ioa config struct
  943. * @hostrcb: hostrcb struct
  944. *
  945. * Return value:
  946. * none
  947. **/
  948. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  949. struct ipr_hostrcb *hostrcb)
  950. {
  951. struct ipr_hostrcb_type_02_error *error =
  952. &hostrcb->hcam.u.error.u.type_02_error;
  953. ipr_err("-----Current Configuration-----\n");
  954. ipr_err("Cache Directory Card Information:\n");
  955. ipr_log_vpd(&error->ioa_vpd);
  956. ipr_err("Adapter Card Information:\n");
  957. ipr_log_vpd(&error->cfc_vpd);
  958. ipr_err("-----Expected Configuration-----\n");
  959. ipr_err("Cache Directory Card Information:\n");
  960. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  961. ipr_err("Adapter Card Information:\n");
  962. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  963. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  964. be32_to_cpu(error->ioa_data[0]),
  965. be32_to_cpu(error->ioa_data[1]),
  966. be32_to_cpu(error->ioa_data[2]));
  967. }
  968. /**
  969. * ipr_log_enhanced_config_error - Log a configuration error.
  970. * @ioa_cfg: ioa config struct
  971. * @hostrcb: hostrcb struct
  972. *
  973. * Return value:
  974. * none
  975. **/
  976. static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
  977. struct ipr_hostrcb *hostrcb)
  978. {
  979. int errors_logged, i;
  980. struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
  981. struct ipr_hostrcb_type_13_error *error;
  982. error = &hostrcb->hcam.u.error.u.type_13_error;
  983. errors_logged = be32_to_cpu(error->errors_logged);
  984. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  985. be32_to_cpu(error->errors_detected), errors_logged);
  986. dev_entry = error->dev;
  987. for (i = 0; i < errors_logged; i++, dev_entry++) {
  988. ipr_err_separator;
  989. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  990. ipr_log_ext_vpd(&dev_entry->vpd);
  991. ipr_err("-----New Device Information-----\n");
  992. ipr_log_ext_vpd(&dev_entry->new_vpd);
  993. ipr_err("Cache Directory Card Information:\n");
  994. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  995. ipr_err("Adapter Card Information:\n");
  996. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  997. }
  998. }
  999. /**
  1000. * ipr_log_config_error - Log a configuration error.
  1001. * @ioa_cfg: ioa config struct
  1002. * @hostrcb: hostrcb struct
  1003. *
  1004. * Return value:
  1005. * none
  1006. **/
  1007. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1008. struct ipr_hostrcb *hostrcb)
  1009. {
  1010. int errors_logged, i;
  1011. struct ipr_hostrcb_device_data_entry *dev_entry;
  1012. struct ipr_hostrcb_type_03_error *error;
  1013. error = &hostrcb->hcam.u.error.u.type_03_error;
  1014. errors_logged = be32_to_cpu(error->errors_logged);
  1015. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1016. be32_to_cpu(error->errors_detected), errors_logged);
  1017. dev_entry = error->dev;
  1018. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1019. ipr_err_separator;
  1020. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1021. ipr_log_vpd(&dev_entry->vpd);
  1022. ipr_err("-----New Device Information-----\n");
  1023. ipr_log_vpd(&dev_entry->new_vpd);
  1024. ipr_err("Cache Directory Card Information:\n");
  1025. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1026. ipr_err("Adapter Card Information:\n");
  1027. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1028. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  1029. be32_to_cpu(dev_entry->ioa_data[0]),
  1030. be32_to_cpu(dev_entry->ioa_data[1]),
  1031. be32_to_cpu(dev_entry->ioa_data[2]),
  1032. be32_to_cpu(dev_entry->ioa_data[3]),
  1033. be32_to_cpu(dev_entry->ioa_data[4]));
  1034. }
  1035. }
  1036. /**
  1037. * ipr_log_enhanced_array_error - Log an array configuration error.
  1038. * @ioa_cfg: ioa config struct
  1039. * @hostrcb: hostrcb struct
  1040. *
  1041. * Return value:
  1042. * none
  1043. **/
  1044. static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1045. struct ipr_hostrcb *hostrcb)
  1046. {
  1047. int i, num_entries;
  1048. struct ipr_hostrcb_type_14_error *error;
  1049. struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
  1050. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1051. error = &hostrcb->hcam.u.error.u.type_14_error;
  1052. ipr_err_separator;
  1053. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1054. error->protection_level,
  1055. ioa_cfg->host->host_no,
  1056. error->last_func_vset_res_addr.bus,
  1057. error->last_func_vset_res_addr.target,
  1058. error->last_func_vset_res_addr.lun);
  1059. ipr_err_separator;
  1060. array_entry = error->array_member;
  1061. num_entries = min_t(u32, be32_to_cpu(error->num_entries),
  1062. sizeof(error->array_member));
  1063. for (i = 0; i < num_entries; i++, array_entry++) {
  1064. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1065. continue;
  1066. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1067. ipr_err("Exposed Array Member %d:\n", i);
  1068. else
  1069. ipr_err("Array Member %d:\n", i);
  1070. ipr_log_ext_vpd(&array_entry->vpd);
  1071. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1072. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1073. "Expected Location");
  1074. ipr_err_separator;
  1075. }
  1076. }
  1077. /**
  1078. * ipr_log_array_error - Log an array configuration error.
  1079. * @ioa_cfg: ioa config struct
  1080. * @hostrcb: hostrcb struct
  1081. *
  1082. * Return value:
  1083. * none
  1084. **/
  1085. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1086. struct ipr_hostrcb *hostrcb)
  1087. {
  1088. int i;
  1089. struct ipr_hostrcb_type_04_error *error;
  1090. struct ipr_hostrcb_array_data_entry *array_entry;
  1091. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1092. error = &hostrcb->hcam.u.error.u.type_04_error;
  1093. ipr_err_separator;
  1094. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1095. error->protection_level,
  1096. ioa_cfg->host->host_no,
  1097. error->last_func_vset_res_addr.bus,
  1098. error->last_func_vset_res_addr.target,
  1099. error->last_func_vset_res_addr.lun);
  1100. ipr_err_separator;
  1101. array_entry = error->array_member;
  1102. for (i = 0; i < 18; i++) {
  1103. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1104. continue;
  1105. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1106. ipr_err("Exposed Array Member %d:\n", i);
  1107. else
  1108. ipr_err("Array Member %d:\n", i);
  1109. ipr_log_vpd(&array_entry->vpd);
  1110. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1111. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1112. "Expected Location");
  1113. ipr_err_separator;
  1114. if (i == 9)
  1115. array_entry = error->array_member2;
  1116. else
  1117. array_entry++;
  1118. }
  1119. }
  1120. /**
  1121. * ipr_log_hex_data - Log additional hex IOA error data.
  1122. * @data: IOA error data
  1123. * @len: data length
  1124. *
  1125. * Return value:
  1126. * none
  1127. **/
  1128. static void ipr_log_hex_data(u32 *data, int len)
  1129. {
  1130. int i;
  1131. if (len == 0)
  1132. return;
  1133. for (i = 0; i < len / 4; i += 4) {
  1134. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  1135. be32_to_cpu(data[i]),
  1136. be32_to_cpu(data[i+1]),
  1137. be32_to_cpu(data[i+2]),
  1138. be32_to_cpu(data[i+3]));
  1139. }
  1140. }
  1141. /**
  1142. * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
  1143. * @ioa_cfg: ioa config struct
  1144. * @hostrcb: hostrcb struct
  1145. *
  1146. * Return value:
  1147. * none
  1148. **/
  1149. static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1150. struct ipr_hostrcb *hostrcb)
  1151. {
  1152. struct ipr_hostrcb_type_17_error *error;
  1153. error = &hostrcb->hcam.u.error.u.type_17_error;
  1154. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1155. ipr_err("%s\n", error->failure_reason);
  1156. ipr_err("Remote Adapter VPD:\n");
  1157. ipr_log_ext_vpd(&error->vpd);
  1158. ipr_log_hex_data(error->data,
  1159. be32_to_cpu(hostrcb->hcam.length) -
  1160. (offsetof(struct ipr_hostrcb_error, u) +
  1161. offsetof(struct ipr_hostrcb_type_17_error, data)));
  1162. }
  1163. /**
  1164. * ipr_log_dual_ioa_error - Log a dual adapter error.
  1165. * @ioa_cfg: ioa config struct
  1166. * @hostrcb: hostrcb struct
  1167. *
  1168. * Return value:
  1169. * none
  1170. **/
  1171. static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1172. struct ipr_hostrcb *hostrcb)
  1173. {
  1174. struct ipr_hostrcb_type_07_error *error;
  1175. error = &hostrcb->hcam.u.error.u.type_07_error;
  1176. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1177. ipr_err("%s\n", error->failure_reason);
  1178. ipr_err("Remote Adapter VPD:\n");
  1179. ipr_log_vpd(&error->vpd);
  1180. ipr_log_hex_data(error->data,
  1181. be32_to_cpu(hostrcb->hcam.length) -
  1182. (offsetof(struct ipr_hostrcb_error, u) +
  1183. offsetof(struct ipr_hostrcb_type_07_error, data)));
  1184. }
  1185. /**
  1186. * ipr_log_generic_error - Log an adapter error.
  1187. * @ioa_cfg: ioa config struct
  1188. * @hostrcb: hostrcb struct
  1189. *
  1190. * Return value:
  1191. * none
  1192. **/
  1193. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  1194. struct ipr_hostrcb *hostrcb)
  1195. {
  1196. ipr_log_hex_data(hostrcb->hcam.u.raw.data,
  1197. be32_to_cpu(hostrcb->hcam.length));
  1198. }
  1199. /**
  1200. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  1201. * @ioasc: IOASC
  1202. *
  1203. * This function will return the index of into the ipr_error_table
  1204. * for the specified IOASC. If the IOASC is not in the table,
  1205. * 0 will be returned, which points to the entry used for unknown errors.
  1206. *
  1207. * Return value:
  1208. * index into the ipr_error_table
  1209. **/
  1210. static u32 ipr_get_error(u32 ioasc)
  1211. {
  1212. int i;
  1213. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  1214. if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
  1215. return i;
  1216. return 0;
  1217. }
  1218. /**
  1219. * ipr_handle_log_data - Log an adapter error.
  1220. * @ioa_cfg: ioa config struct
  1221. * @hostrcb: hostrcb struct
  1222. *
  1223. * This function logs an adapter error to the system.
  1224. *
  1225. * Return value:
  1226. * none
  1227. **/
  1228. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  1229. struct ipr_hostrcb *hostrcb)
  1230. {
  1231. u32 ioasc;
  1232. int error_index;
  1233. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  1234. return;
  1235. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  1236. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  1237. ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  1238. if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  1239. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
  1240. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  1241. scsi_report_bus_reset(ioa_cfg->host,
  1242. hostrcb->hcam.u.error.failing_dev_res_addr.bus);
  1243. }
  1244. error_index = ipr_get_error(ioasc);
  1245. if (!ipr_error_table[error_index].log_hcam)
  1246. return;
  1247. if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
  1248. ipr_ra_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
  1249. "%s\n", ipr_error_table[error_index].error);
  1250. } else {
  1251. dev_err(&ioa_cfg->pdev->dev, "%s\n",
  1252. ipr_error_table[error_index].error);
  1253. }
  1254. /* Set indication we have logged an error */
  1255. ioa_cfg->errors_logged++;
  1256. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  1257. return;
  1258. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  1259. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  1260. switch (hostrcb->hcam.overlay_id) {
  1261. case IPR_HOST_RCB_OVERLAY_ID_2:
  1262. ipr_log_cache_error(ioa_cfg, hostrcb);
  1263. break;
  1264. case IPR_HOST_RCB_OVERLAY_ID_3:
  1265. ipr_log_config_error(ioa_cfg, hostrcb);
  1266. break;
  1267. case IPR_HOST_RCB_OVERLAY_ID_4:
  1268. case IPR_HOST_RCB_OVERLAY_ID_6:
  1269. ipr_log_array_error(ioa_cfg, hostrcb);
  1270. break;
  1271. case IPR_HOST_RCB_OVERLAY_ID_7:
  1272. ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
  1273. break;
  1274. case IPR_HOST_RCB_OVERLAY_ID_12:
  1275. ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
  1276. break;
  1277. case IPR_HOST_RCB_OVERLAY_ID_13:
  1278. ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
  1279. break;
  1280. case IPR_HOST_RCB_OVERLAY_ID_14:
  1281. case IPR_HOST_RCB_OVERLAY_ID_16:
  1282. ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
  1283. break;
  1284. case IPR_HOST_RCB_OVERLAY_ID_17:
  1285. ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
  1286. break;
  1287. case IPR_HOST_RCB_OVERLAY_ID_1:
  1288. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  1289. default:
  1290. ipr_log_generic_error(ioa_cfg, hostrcb);
  1291. break;
  1292. }
  1293. }
  1294. /**
  1295. * ipr_process_error - Op done function for an adapter error log.
  1296. * @ipr_cmd: ipr command struct
  1297. *
  1298. * This function is the op done function for an error log host
  1299. * controlled async from the adapter. It will log the error and
  1300. * send the HCAM back to the adapter.
  1301. *
  1302. * Return value:
  1303. * none
  1304. **/
  1305. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  1306. {
  1307. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1308. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1309. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  1310. list_del(&hostrcb->queue);
  1311. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  1312. if (!ioasc) {
  1313. ipr_handle_log_data(ioa_cfg, hostrcb);
  1314. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
  1315. dev_err(&ioa_cfg->pdev->dev,
  1316. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1317. }
  1318. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  1319. }
  1320. /**
  1321. * ipr_timeout - An internally generated op has timed out.
  1322. * @ipr_cmd: ipr command struct
  1323. *
  1324. * This function blocks host requests and initiates an
  1325. * adapter reset.
  1326. *
  1327. * Return value:
  1328. * none
  1329. **/
  1330. static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
  1331. {
  1332. unsigned long lock_flags = 0;
  1333. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1334. ENTER;
  1335. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1336. ioa_cfg->errors_logged++;
  1337. dev_err(&ioa_cfg->pdev->dev,
  1338. "Adapter being reset due to command timeout.\n");
  1339. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1340. ioa_cfg->sdt_state = GET_DUMP;
  1341. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  1342. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1343. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1344. LEAVE;
  1345. }
  1346. /**
  1347. * ipr_oper_timeout - Adapter timed out transitioning to operational
  1348. * @ipr_cmd: ipr command struct
  1349. *
  1350. * This function blocks host requests and initiates an
  1351. * adapter reset.
  1352. *
  1353. * Return value:
  1354. * none
  1355. **/
  1356. static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
  1357. {
  1358. unsigned long lock_flags = 0;
  1359. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1360. ENTER;
  1361. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1362. ioa_cfg->errors_logged++;
  1363. dev_err(&ioa_cfg->pdev->dev,
  1364. "Adapter timed out transitioning to operational.\n");
  1365. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1366. ioa_cfg->sdt_state = GET_DUMP;
  1367. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  1368. if (ipr_fastfail)
  1369. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  1370. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1371. }
  1372. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1373. LEAVE;
  1374. }
  1375. /**
  1376. * ipr_reset_reload - Reset/Reload the IOA
  1377. * @ioa_cfg: ioa config struct
  1378. * @shutdown_type: shutdown type
  1379. *
  1380. * This function resets the adapter and re-initializes it.
  1381. * This function assumes that all new host commands have been stopped.
  1382. * Return value:
  1383. * SUCCESS / FAILED
  1384. **/
  1385. static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
  1386. enum ipr_shutdown_type shutdown_type)
  1387. {
  1388. if (!ioa_cfg->in_reset_reload)
  1389. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  1390. spin_unlock_irq(ioa_cfg->host->host_lock);
  1391. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1392. spin_lock_irq(ioa_cfg->host->host_lock);
  1393. /* If we got hit with a host reset while we were already resetting
  1394. the adapter for some reason, and the reset failed. */
  1395. if (ioa_cfg->ioa_is_dead) {
  1396. ipr_trace;
  1397. return FAILED;
  1398. }
  1399. return SUCCESS;
  1400. }
  1401. /**
  1402. * ipr_find_ses_entry - Find matching SES in SES table
  1403. * @res: resource entry struct of SES
  1404. *
  1405. * Return value:
  1406. * pointer to SES table entry / NULL on failure
  1407. **/
  1408. static const struct ipr_ses_table_entry *
  1409. ipr_find_ses_entry(struct ipr_resource_entry *res)
  1410. {
  1411. int i, j, matches;
  1412. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  1413. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  1414. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  1415. if (ste->compare_product_id_byte[j] == 'X') {
  1416. if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
  1417. matches++;
  1418. else
  1419. break;
  1420. } else
  1421. matches++;
  1422. }
  1423. if (matches == IPR_PROD_ID_LEN)
  1424. return ste;
  1425. }
  1426. return NULL;
  1427. }
  1428. /**
  1429. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  1430. * @ioa_cfg: ioa config struct
  1431. * @bus: SCSI bus
  1432. * @bus_width: bus width
  1433. *
  1434. * Return value:
  1435. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  1436. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  1437. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  1438. * max 160MHz = max 320MB/sec).
  1439. **/
  1440. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  1441. {
  1442. struct ipr_resource_entry *res;
  1443. const struct ipr_ses_table_entry *ste;
  1444. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  1445. /* Loop through each config table entry in the config table buffer */
  1446. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1447. if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
  1448. continue;
  1449. if (bus != res->cfgte.res_addr.bus)
  1450. continue;
  1451. if (!(ste = ipr_find_ses_entry(res)))
  1452. continue;
  1453. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  1454. }
  1455. return max_xfer_rate;
  1456. }
  1457. /**
  1458. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  1459. * @ioa_cfg: ioa config struct
  1460. * @max_delay: max delay in micro-seconds to wait
  1461. *
  1462. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  1463. *
  1464. * Return value:
  1465. * 0 on success / other on failure
  1466. **/
  1467. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  1468. {
  1469. volatile u32 pcii_reg;
  1470. int delay = 1;
  1471. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  1472. while (delay < max_delay) {
  1473. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  1474. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  1475. return 0;
  1476. /* udelay cannot be used if delay is more than a few milliseconds */
  1477. if ((delay / 1000) > MAX_UDELAY_MS)
  1478. mdelay(delay / 1000);
  1479. else
  1480. udelay(delay);
  1481. delay += delay;
  1482. }
  1483. return -EIO;
  1484. }
  1485. /**
  1486. * ipr_get_ldump_data_section - Dump IOA memory
  1487. * @ioa_cfg: ioa config struct
  1488. * @start_addr: adapter address to dump
  1489. * @dest: destination kernel buffer
  1490. * @length_in_words: length to dump in 4 byte words
  1491. *
  1492. * Return value:
  1493. * 0 on success / -EIO on failure
  1494. **/
  1495. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  1496. u32 start_addr,
  1497. __be32 *dest, u32 length_in_words)
  1498. {
  1499. volatile u32 temp_pcii_reg;
  1500. int i, delay = 0;
  1501. /* Write IOA interrupt reg starting LDUMP state */
  1502. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  1503. ioa_cfg->regs.set_uproc_interrupt_reg);
  1504. /* Wait for IO debug acknowledge */
  1505. if (ipr_wait_iodbg_ack(ioa_cfg,
  1506. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  1507. dev_err(&ioa_cfg->pdev->dev,
  1508. "IOA dump long data transfer timeout\n");
  1509. return -EIO;
  1510. }
  1511. /* Signal LDUMP interlocked - clear IO debug ack */
  1512. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1513. ioa_cfg->regs.clr_interrupt_reg);
  1514. /* Write Mailbox with starting address */
  1515. writel(start_addr, ioa_cfg->ioa_mailbox);
  1516. /* Signal address valid - clear IOA Reset alert */
  1517. writel(IPR_UPROCI_RESET_ALERT,
  1518. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1519. for (i = 0; i < length_in_words; i++) {
  1520. /* Wait for IO debug acknowledge */
  1521. if (ipr_wait_iodbg_ack(ioa_cfg,
  1522. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  1523. dev_err(&ioa_cfg->pdev->dev,
  1524. "IOA dump short data transfer timeout\n");
  1525. return -EIO;
  1526. }
  1527. /* Read data from mailbox and increment destination pointer */
  1528. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  1529. dest++;
  1530. /* For all but the last word of data, signal data received */
  1531. if (i < (length_in_words - 1)) {
  1532. /* Signal dump data received - Clear IO debug Ack */
  1533. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1534. ioa_cfg->regs.clr_interrupt_reg);
  1535. }
  1536. }
  1537. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  1538. writel(IPR_UPROCI_RESET_ALERT,
  1539. ioa_cfg->regs.set_uproc_interrupt_reg);
  1540. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  1541. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1542. /* Signal dump data received - Clear IO debug Ack */
  1543. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1544. ioa_cfg->regs.clr_interrupt_reg);
  1545. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  1546. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  1547. temp_pcii_reg =
  1548. readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  1549. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  1550. return 0;
  1551. udelay(10);
  1552. delay += 10;
  1553. }
  1554. return 0;
  1555. }
  1556. #ifdef CONFIG_SCSI_IPR_DUMP
  1557. /**
  1558. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  1559. * @ioa_cfg: ioa config struct
  1560. * @pci_address: adapter address
  1561. * @length: length of data to copy
  1562. *
  1563. * Copy data from PCI adapter to kernel buffer.
  1564. * Note: length MUST be a 4 byte multiple
  1565. * Return value:
  1566. * 0 on success / other on failure
  1567. **/
  1568. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  1569. unsigned long pci_address, u32 length)
  1570. {
  1571. int bytes_copied = 0;
  1572. int cur_len, rc, rem_len, rem_page_len;
  1573. __be32 *page;
  1574. unsigned long lock_flags = 0;
  1575. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  1576. while (bytes_copied < length &&
  1577. (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
  1578. if (ioa_dump->page_offset >= PAGE_SIZE ||
  1579. ioa_dump->page_offset == 0) {
  1580. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  1581. if (!page) {
  1582. ipr_trace;
  1583. return bytes_copied;
  1584. }
  1585. ioa_dump->page_offset = 0;
  1586. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  1587. ioa_dump->next_page_index++;
  1588. } else
  1589. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  1590. rem_len = length - bytes_copied;
  1591. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  1592. cur_len = min(rem_len, rem_page_len);
  1593. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1594. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  1595. rc = -EIO;
  1596. } else {
  1597. rc = ipr_get_ldump_data_section(ioa_cfg,
  1598. pci_address + bytes_copied,
  1599. &page[ioa_dump->page_offset / 4],
  1600. (cur_len / sizeof(u32)));
  1601. }
  1602. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1603. if (!rc) {
  1604. ioa_dump->page_offset += cur_len;
  1605. bytes_copied += cur_len;
  1606. } else {
  1607. ipr_trace;
  1608. break;
  1609. }
  1610. schedule();
  1611. }
  1612. return bytes_copied;
  1613. }
  1614. /**
  1615. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  1616. * @hdr: dump entry header struct
  1617. *
  1618. * Return value:
  1619. * nothing
  1620. **/
  1621. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  1622. {
  1623. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  1624. hdr->num_elems = 1;
  1625. hdr->offset = sizeof(*hdr);
  1626. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  1627. }
  1628. /**
  1629. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  1630. * @ioa_cfg: ioa config struct
  1631. * @driver_dump: driver dump struct
  1632. *
  1633. * Return value:
  1634. * nothing
  1635. **/
  1636. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  1637. struct ipr_driver_dump *driver_dump)
  1638. {
  1639. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1640. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  1641. driver_dump->ioa_type_entry.hdr.len =
  1642. sizeof(struct ipr_dump_ioa_type_entry) -
  1643. sizeof(struct ipr_dump_entry_header);
  1644. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1645. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  1646. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  1647. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  1648. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  1649. ucode_vpd->minor_release[1];
  1650. driver_dump->hdr.num_entries++;
  1651. }
  1652. /**
  1653. * ipr_dump_version_data - Fill in the driver version in the dump.
  1654. * @ioa_cfg: ioa config struct
  1655. * @driver_dump: driver dump struct
  1656. *
  1657. * Return value:
  1658. * nothing
  1659. **/
  1660. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  1661. struct ipr_driver_dump *driver_dump)
  1662. {
  1663. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  1664. driver_dump->version_entry.hdr.len =
  1665. sizeof(struct ipr_dump_version_entry) -
  1666. sizeof(struct ipr_dump_entry_header);
  1667. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1668. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  1669. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  1670. driver_dump->hdr.num_entries++;
  1671. }
  1672. /**
  1673. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  1674. * @ioa_cfg: ioa config struct
  1675. * @driver_dump: driver dump struct
  1676. *
  1677. * Return value:
  1678. * nothing
  1679. **/
  1680. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  1681. struct ipr_driver_dump *driver_dump)
  1682. {
  1683. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  1684. driver_dump->trace_entry.hdr.len =
  1685. sizeof(struct ipr_dump_trace_entry) -
  1686. sizeof(struct ipr_dump_entry_header);
  1687. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1688. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  1689. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  1690. driver_dump->hdr.num_entries++;
  1691. }
  1692. /**
  1693. * ipr_dump_location_data - Fill in the IOA location in the dump.
  1694. * @ioa_cfg: ioa config struct
  1695. * @driver_dump: driver dump struct
  1696. *
  1697. * Return value:
  1698. * nothing
  1699. **/
  1700. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  1701. struct ipr_driver_dump *driver_dump)
  1702. {
  1703. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  1704. driver_dump->location_entry.hdr.len =
  1705. sizeof(struct ipr_dump_location_entry) -
  1706. sizeof(struct ipr_dump_entry_header);
  1707. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1708. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  1709. strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
  1710. driver_dump->hdr.num_entries++;
  1711. }
  1712. /**
  1713. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  1714. * @ioa_cfg: ioa config struct
  1715. * @dump: dump struct
  1716. *
  1717. * Return value:
  1718. * nothing
  1719. **/
  1720. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  1721. {
  1722. unsigned long start_addr, sdt_word;
  1723. unsigned long lock_flags = 0;
  1724. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  1725. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  1726. u32 num_entries, start_off, end_off;
  1727. u32 bytes_to_copy, bytes_copied, rc;
  1728. struct ipr_sdt *sdt;
  1729. int i;
  1730. ENTER;
  1731. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1732. if (ioa_cfg->sdt_state != GET_DUMP) {
  1733. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1734. return;
  1735. }
  1736. start_addr = readl(ioa_cfg->ioa_mailbox);
  1737. if (!ipr_sdt_is_fmt2(start_addr)) {
  1738. dev_err(&ioa_cfg->pdev->dev,
  1739. "Invalid dump table format: %lx\n", start_addr);
  1740. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1741. return;
  1742. }
  1743. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  1744. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  1745. /* Initialize the overall dump header */
  1746. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  1747. driver_dump->hdr.num_entries = 1;
  1748. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  1749. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  1750. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  1751. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  1752. ipr_dump_version_data(ioa_cfg, driver_dump);
  1753. ipr_dump_location_data(ioa_cfg, driver_dump);
  1754. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  1755. ipr_dump_trace_data(ioa_cfg, driver_dump);
  1756. /* Update dump_header */
  1757. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  1758. /* IOA Dump entry */
  1759. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  1760. ioa_dump->format = IPR_SDT_FMT2;
  1761. ioa_dump->hdr.len = 0;
  1762. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1763. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  1764. /* First entries in sdt are actually a list of dump addresses and
  1765. lengths to gather the real dump data. sdt represents the pointer
  1766. to the ioa generated dump table. Dump data will be extracted based
  1767. on entries in this table */
  1768. sdt = &ioa_dump->sdt;
  1769. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  1770. sizeof(struct ipr_sdt) / sizeof(__be32));
  1771. /* Smart Dump table is ready to use and the first entry is valid */
  1772. if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
  1773. dev_err(&ioa_cfg->pdev->dev,
  1774. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  1775. rc, be32_to_cpu(sdt->hdr.state));
  1776. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  1777. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1778. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1779. return;
  1780. }
  1781. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  1782. if (num_entries > IPR_NUM_SDT_ENTRIES)
  1783. num_entries = IPR_NUM_SDT_ENTRIES;
  1784. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1785. for (i = 0; i < num_entries; i++) {
  1786. if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
  1787. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1788. break;
  1789. }
  1790. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  1791. sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
  1792. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  1793. end_off = be32_to_cpu(sdt->entry[i].end_offset);
  1794. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
  1795. bytes_to_copy = end_off - start_off;
  1796. if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
  1797. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  1798. continue;
  1799. }
  1800. /* Copy data from adapter to driver buffers */
  1801. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  1802. bytes_to_copy);
  1803. ioa_dump->hdr.len += bytes_copied;
  1804. if (bytes_copied != bytes_to_copy) {
  1805. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1806. break;
  1807. }
  1808. }
  1809. }
  1810. }
  1811. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  1812. /* Update dump_header */
  1813. driver_dump->hdr.len += ioa_dump->hdr.len;
  1814. wmb();
  1815. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1816. LEAVE;
  1817. }
  1818. #else
  1819. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
  1820. #endif
  1821. /**
  1822. * ipr_release_dump - Free adapter dump memory
  1823. * @kref: kref struct
  1824. *
  1825. * Return value:
  1826. * nothing
  1827. **/
  1828. static void ipr_release_dump(struct kref *kref)
  1829. {
  1830. struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
  1831. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  1832. unsigned long lock_flags = 0;
  1833. int i;
  1834. ENTER;
  1835. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1836. ioa_cfg->dump = NULL;
  1837. ioa_cfg->sdt_state = INACTIVE;
  1838. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1839. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  1840. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  1841. kfree(dump);
  1842. LEAVE;
  1843. }
  1844. /**
  1845. * ipr_worker_thread - Worker thread
  1846. * @data: ioa config struct
  1847. *
  1848. * Called at task level from a work thread. This function takes care
  1849. * of adding and removing device from the mid-layer as configuration
  1850. * changes are detected by the adapter.
  1851. *
  1852. * Return value:
  1853. * nothing
  1854. **/
  1855. static void ipr_worker_thread(void *data)
  1856. {
  1857. unsigned long lock_flags;
  1858. struct ipr_resource_entry *res;
  1859. struct scsi_device *sdev;
  1860. struct ipr_dump *dump;
  1861. struct ipr_ioa_cfg *ioa_cfg = data;
  1862. u8 bus, target, lun;
  1863. int did_work;
  1864. ENTER;
  1865. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1866. if (ioa_cfg->sdt_state == GET_DUMP) {
  1867. dump = ioa_cfg->dump;
  1868. if (!dump) {
  1869. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1870. return;
  1871. }
  1872. kref_get(&dump->kref);
  1873. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1874. ipr_get_ioa_dump(ioa_cfg, dump);
  1875. kref_put(&dump->kref, ipr_release_dump);
  1876. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1877. if (ioa_cfg->sdt_state == DUMP_OBTAINED)
  1878. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1879. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1880. return;
  1881. }
  1882. restart:
  1883. do {
  1884. did_work = 0;
  1885. if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
  1886. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1887. return;
  1888. }
  1889. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1890. if (res->del_from_ml && res->sdev) {
  1891. did_work = 1;
  1892. sdev = res->sdev;
  1893. if (!scsi_device_get(sdev)) {
  1894. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1895. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1896. scsi_remove_device(sdev);
  1897. scsi_device_put(sdev);
  1898. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1899. }
  1900. break;
  1901. }
  1902. }
  1903. } while(did_work);
  1904. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1905. if (res->add_to_ml) {
  1906. bus = res->cfgte.res_addr.bus;
  1907. target = res->cfgte.res_addr.target;
  1908. lun = res->cfgte.res_addr.lun;
  1909. res->add_to_ml = 0;
  1910. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1911. scsi_add_device(ioa_cfg->host, bus, target, lun);
  1912. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1913. goto restart;
  1914. }
  1915. }
  1916. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1917. kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
  1918. LEAVE;
  1919. }
  1920. #ifdef CONFIG_SCSI_IPR_TRACE
  1921. /**
  1922. * ipr_read_trace - Dump the adapter trace
  1923. * @kobj: kobject struct
  1924. * @buf: buffer
  1925. * @off: offset
  1926. * @count: buffer size
  1927. *
  1928. * Return value:
  1929. * number of bytes printed to buffer
  1930. **/
  1931. static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
  1932. loff_t off, size_t count)
  1933. {
  1934. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  1935. struct Scsi_Host *shost = class_to_shost(cdev);
  1936. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1937. unsigned long lock_flags = 0;
  1938. int size = IPR_TRACE_SIZE;
  1939. char *src = (char *)ioa_cfg->trace;
  1940. if (off > size)
  1941. return 0;
  1942. if (off + count > size) {
  1943. size -= off;
  1944. count = size;
  1945. }
  1946. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1947. memcpy(buf, &src[off], count);
  1948. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1949. return count;
  1950. }
  1951. static struct bin_attribute ipr_trace_attr = {
  1952. .attr = {
  1953. .name = "trace",
  1954. .mode = S_IRUGO,
  1955. },
  1956. .size = 0,
  1957. .read = ipr_read_trace,
  1958. };
  1959. #endif
  1960. static const struct {
  1961. enum ipr_cache_state state;
  1962. char *name;
  1963. } cache_state [] = {
  1964. { CACHE_NONE, "none" },
  1965. { CACHE_DISABLED, "disabled" },
  1966. { CACHE_ENABLED, "enabled" }
  1967. };
  1968. /**
  1969. * ipr_show_write_caching - Show the write caching attribute
  1970. * @class_dev: class device struct
  1971. * @buf: buffer
  1972. *
  1973. * Return value:
  1974. * number of bytes printed to buffer
  1975. **/
  1976. static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
  1977. {
  1978. struct Scsi_Host *shost = class_to_shost(class_dev);
  1979. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1980. unsigned long lock_flags = 0;
  1981. int i, len = 0;
  1982. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1983. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  1984. if (cache_state[i].state == ioa_cfg->cache_state) {
  1985. len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
  1986. break;
  1987. }
  1988. }
  1989. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1990. return len;
  1991. }
  1992. /**
  1993. * ipr_store_write_caching - Enable/disable adapter write cache
  1994. * @class_dev: class_device struct
  1995. * @buf: buffer
  1996. * @count: buffer size
  1997. *
  1998. * This function will enable/disable adapter write cache.
  1999. *
  2000. * Return value:
  2001. * count on success / other on failure
  2002. **/
  2003. static ssize_t ipr_store_write_caching(struct class_device *class_dev,
  2004. const char *buf, size_t count)
  2005. {
  2006. struct Scsi_Host *shost = class_to_shost(class_dev);
  2007. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2008. unsigned long lock_flags = 0;
  2009. enum ipr_cache_state new_state = CACHE_INVALID;
  2010. int i;
  2011. if (!capable(CAP_SYS_ADMIN))
  2012. return -EACCES;
  2013. if (ioa_cfg->cache_state == CACHE_NONE)
  2014. return -EINVAL;
  2015. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  2016. if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
  2017. new_state = cache_state[i].state;
  2018. break;
  2019. }
  2020. }
  2021. if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
  2022. return -EINVAL;
  2023. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2024. if (ioa_cfg->cache_state == new_state) {
  2025. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2026. return count;
  2027. }
  2028. ioa_cfg->cache_state = new_state;
  2029. dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
  2030. new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
  2031. if (!ioa_cfg->in_reset_reload)
  2032. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2033. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2034. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2035. return count;
  2036. }
  2037. static struct class_device_attribute ipr_ioa_cache_attr = {
  2038. .attr = {
  2039. .name = "write_cache",
  2040. .mode = S_IRUGO | S_IWUSR,
  2041. },
  2042. .show = ipr_show_write_caching,
  2043. .store = ipr_store_write_caching
  2044. };
  2045. /**
  2046. * ipr_show_fw_version - Show the firmware version
  2047. * @class_dev: class device struct
  2048. * @buf: buffer
  2049. *
  2050. * Return value:
  2051. * number of bytes printed to buffer
  2052. **/
  2053. static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
  2054. {
  2055. struct Scsi_Host *shost = class_to_shost(class_dev);
  2056. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2057. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2058. unsigned long lock_flags = 0;
  2059. int len;
  2060. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2061. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  2062. ucode_vpd->major_release, ucode_vpd->card_type,
  2063. ucode_vpd->minor_release[0],
  2064. ucode_vpd->minor_release[1]);
  2065. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2066. return len;
  2067. }
  2068. static struct class_device_attribute ipr_fw_version_attr = {
  2069. .attr = {
  2070. .name = "fw_version",
  2071. .mode = S_IRUGO,
  2072. },
  2073. .show = ipr_show_fw_version,
  2074. };
  2075. /**
  2076. * ipr_show_log_level - Show the adapter's error logging level
  2077. * @class_dev: class device struct
  2078. * @buf: buffer
  2079. *
  2080. * Return value:
  2081. * number of bytes printed to buffer
  2082. **/
  2083. static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
  2084. {
  2085. struct Scsi_Host *shost = class_to_shost(class_dev);
  2086. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2087. unsigned long lock_flags = 0;
  2088. int len;
  2089. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2090. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  2091. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2092. return len;
  2093. }
  2094. /**
  2095. * ipr_store_log_level - Change the adapter's error logging level
  2096. * @class_dev: class device struct
  2097. * @buf: buffer
  2098. *
  2099. * Return value:
  2100. * number of bytes printed to buffer
  2101. **/
  2102. static ssize_t ipr_store_log_level(struct class_device *class_dev,
  2103. const char *buf, size_t count)
  2104. {
  2105. struct Scsi_Host *shost = class_to_shost(class_dev);
  2106. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2107. unsigned long lock_flags = 0;
  2108. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2109. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  2110. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2111. return strlen(buf);
  2112. }
  2113. static struct class_device_attribute ipr_log_level_attr = {
  2114. .attr = {
  2115. .name = "log_level",
  2116. .mode = S_IRUGO | S_IWUSR,
  2117. },
  2118. .show = ipr_show_log_level,
  2119. .store = ipr_store_log_level
  2120. };
  2121. /**
  2122. * ipr_store_diagnostics - IOA Diagnostics interface
  2123. * @class_dev: class_device struct
  2124. * @buf: buffer
  2125. * @count: buffer size
  2126. *
  2127. * This function will reset the adapter and wait a reasonable
  2128. * amount of time for any errors that the adapter might log.
  2129. *
  2130. * Return value:
  2131. * count on success / other on failure
  2132. **/
  2133. static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
  2134. const char *buf, size_t count)
  2135. {
  2136. struct Scsi_Host *shost = class_to_shost(class_dev);
  2137. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2138. unsigned long lock_flags = 0;
  2139. int rc = count;
  2140. if (!capable(CAP_SYS_ADMIN))
  2141. return -EACCES;
  2142. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2143. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2144. ioa_cfg->errors_logged = 0;
  2145. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2146. if (ioa_cfg->in_reset_reload) {
  2147. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2148. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2149. /* Wait for a second for any errors to be logged */
  2150. msleep(1000);
  2151. } else {
  2152. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2153. return -EIO;
  2154. }
  2155. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2156. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  2157. rc = -EIO;
  2158. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2159. return rc;
  2160. }
  2161. static struct class_device_attribute ipr_diagnostics_attr = {
  2162. .attr = {
  2163. .name = "run_diagnostics",
  2164. .mode = S_IWUSR,
  2165. },
  2166. .store = ipr_store_diagnostics
  2167. };
  2168. /**
  2169. * ipr_show_adapter_state - Show the adapter's state
  2170. * @class_dev: class device struct
  2171. * @buf: buffer
  2172. *
  2173. * Return value:
  2174. * number of bytes printed to buffer
  2175. **/
  2176. static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
  2177. {
  2178. struct Scsi_Host *shost = class_to_shost(class_dev);
  2179. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2180. unsigned long lock_flags = 0;
  2181. int len;
  2182. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2183. if (ioa_cfg->ioa_is_dead)
  2184. len = snprintf(buf, PAGE_SIZE, "offline\n");
  2185. else
  2186. len = snprintf(buf, PAGE_SIZE, "online\n");
  2187. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2188. return len;
  2189. }
  2190. /**
  2191. * ipr_store_adapter_state - Change adapter state
  2192. * @class_dev: class_device struct
  2193. * @buf: buffer
  2194. * @count: buffer size
  2195. *
  2196. * This function will change the adapter's state.
  2197. *
  2198. * Return value:
  2199. * count on success / other on failure
  2200. **/
  2201. static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
  2202. const char *buf, size_t count)
  2203. {
  2204. struct Scsi_Host *shost = class_to_shost(class_dev);
  2205. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2206. unsigned long lock_flags;
  2207. int result = count;
  2208. if (!capable(CAP_SYS_ADMIN))
  2209. return -EACCES;
  2210. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2211. if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
  2212. ioa_cfg->ioa_is_dead = 0;
  2213. ioa_cfg->reset_retries = 0;
  2214. ioa_cfg->in_ioa_bringdown = 0;
  2215. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2216. }
  2217. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2218. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2219. return result;
  2220. }
  2221. static struct class_device_attribute ipr_ioa_state_attr = {
  2222. .attr = {
  2223. .name = "state",
  2224. .mode = S_IRUGO | S_IWUSR,
  2225. },
  2226. .show = ipr_show_adapter_state,
  2227. .store = ipr_store_adapter_state
  2228. };
  2229. /**
  2230. * ipr_store_reset_adapter - Reset the adapter
  2231. * @class_dev: class_device struct
  2232. * @buf: buffer
  2233. * @count: buffer size
  2234. *
  2235. * This function will reset the adapter.
  2236. *
  2237. * Return value:
  2238. * count on success / other on failure
  2239. **/
  2240. static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
  2241. const char *buf, size_t count)
  2242. {
  2243. struct Scsi_Host *shost = class_to_shost(class_dev);
  2244. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2245. unsigned long lock_flags;
  2246. int result = count;
  2247. if (!capable(CAP_SYS_ADMIN))
  2248. return -EACCES;
  2249. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2250. if (!ioa_cfg->in_reset_reload)
  2251. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2252. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2253. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2254. return result;
  2255. }
  2256. static struct class_device_attribute ipr_ioa_reset_attr = {
  2257. .attr = {
  2258. .name = "reset_host",
  2259. .mode = S_IWUSR,
  2260. },
  2261. .store = ipr_store_reset_adapter
  2262. };
  2263. /**
  2264. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  2265. * @buf_len: buffer length
  2266. *
  2267. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  2268. * list to use for microcode download
  2269. *
  2270. * Return value:
  2271. * pointer to sglist / NULL on failure
  2272. **/
  2273. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  2274. {
  2275. int sg_size, order, bsize_elem, num_elem, i, j;
  2276. struct ipr_sglist *sglist;
  2277. struct scatterlist *scatterlist;
  2278. struct page *page;
  2279. /* Get the minimum size per scatter/gather element */
  2280. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  2281. /* Get the actual size per element */
  2282. order = get_order(sg_size);
  2283. /* Determine the actual number of bytes per element */
  2284. bsize_elem = PAGE_SIZE * (1 << order);
  2285. /* Determine the actual number of sg entries needed */
  2286. if (buf_len % bsize_elem)
  2287. num_elem = (buf_len / bsize_elem) + 1;
  2288. else
  2289. num_elem = buf_len / bsize_elem;
  2290. /* Allocate a scatter/gather list for the DMA */
  2291. sglist = kzalloc(sizeof(struct ipr_sglist) +
  2292. (sizeof(struct scatterlist) * (num_elem - 1)),
  2293. GFP_KERNEL);
  2294. if (sglist == NULL) {
  2295. ipr_trace;
  2296. return NULL;
  2297. }
  2298. scatterlist = sglist->scatterlist;
  2299. sglist->order = order;
  2300. sglist->num_sg = num_elem;
  2301. /* Allocate a bunch of sg elements */
  2302. for (i = 0; i < num_elem; i++) {
  2303. page = alloc_pages(GFP_KERNEL, order);
  2304. if (!page) {
  2305. ipr_trace;
  2306. /* Free up what we already allocated */
  2307. for (j = i - 1; j >= 0; j--)
  2308. __free_pages(scatterlist[j].page, order);
  2309. kfree(sglist);
  2310. return NULL;
  2311. }
  2312. scatterlist[i].page = page;
  2313. }
  2314. return sglist;
  2315. }
  2316. /**
  2317. * ipr_free_ucode_buffer - Frees a microcode download buffer
  2318. * @p_dnld: scatter/gather list pointer
  2319. *
  2320. * Free a DMA'able ucode download buffer previously allocated with
  2321. * ipr_alloc_ucode_buffer
  2322. *
  2323. * Return value:
  2324. * nothing
  2325. **/
  2326. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  2327. {
  2328. int i;
  2329. for (i = 0; i < sglist->num_sg; i++)
  2330. __free_pages(sglist->scatterlist[i].page, sglist->order);
  2331. kfree(sglist);
  2332. }
  2333. /**
  2334. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  2335. * @sglist: scatter/gather list pointer
  2336. * @buffer: buffer pointer
  2337. * @len: buffer length
  2338. *
  2339. * Copy a microcode image from a user buffer into a buffer allocated by
  2340. * ipr_alloc_ucode_buffer
  2341. *
  2342. * Return value:
  2343. * 0 on success / other on failure
  2344. **/
  2345. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  2346. u8 *buffer, u32 len)
  2347. {
  2348. int bsize_elem, i, result = 0;
  2349. struct scatterlist *scatterlist;
  2350. void *kaddr;
  2351. /* Determine the actual number of bytes per element */
  2352. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  2353. scatterlist = sglist->scatterlist;
  2354. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  2355. kaddr = kmap(scatterlist[i].page);
  2356. memcpy(kaddr, buffer, bsize_elem);
  2357. kunmap(scatterlist[i].page);
  2358. scatterlist[i].length = bsize_elem;
  2359. if (result != 0) {
  2360. ipr_trace;
  2361. return result;
  2362. }
  2363. }
  2364. if (len % bsize_elem) {
  2365. kaddr = kmap(scatterlist[i].page);
  2366. memcpy(kaddr, buffer, len % bsize_elem);
  2367. kunmap(scatterlist[i].page);
  2368. scatterlist[i].length = len % bsize_elem;
  2369. }
  2370. sglist->buffer_len = len;
  2371. return result;
  2372. }
  2373. /**
  2374. * ipr_build_ucode_ioadl - Build a microcode download IOADL
  2375. * @ipr_cmd: ipr command struct
  2376. * @sglist: scatter/gather list
  2377. *
  2378. * Builds a microcode download IOA data list (IOADL).
  2379. *
  2380. **/
  2381. static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
  2382. struct ipr_sglist *sglist)
  2383. {
  2384. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2385. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2386. struct scatterlist *scatterlist = sglist->scatterlist;
  2387. int i;
  2388. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  2389. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2390. ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
  2391. ioarcb->write_ioadl_len =
  2392. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2393. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2394. ioadl[i].flags_and_data_len =
  2395. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  2396. ioadl[i].address =
  2397. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  2398. }
  2399. ioadl[i-1].flags_and_data_len |=
  2400. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2401. }
  2402. /**
  2403. * ipr_update_ioa_ucode - Update IOA's microcode
  2404. * @ioa_cfg: ioa config struct
  2405. * @sglist: scatter/gather list
  2406. *
  2407. * Initiate an adapter reset to update the IOA's microcode
  2408. *
  2409. * Return value:
  2410. * 0 on success / -EIO on failure
  2411. **/
  2412. static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
  2413. struct ipr_sglist *sglist)
  2414. {
  2415. unsigned long lock_flags;
  2416. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2417. if (ioa_cfg->ucode_sglist) {
  2418. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2419. dev_err(&ioa_cfg->pdev->dev,
  2420. "Microcode download already in progress\n");
  2421. return -EIO;
  2422. }
  2423. sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
  2424. sglist->num_sg, DMA_TO_DEVICE);
  2425. if (!sglist->num_dma_sg) {
  2426. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2427. dev_err(&ioa_cfg->pdev->dev,
  2428. "Failed to map microcode download buffer!\n");
  2429. return -EIO;
  2430. }
  2431. ioa_cfg->ucode_sglist = sglist;
  2432. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2433. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2434. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2435. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2436. ioa_cfg->ucode_sglist = NULL;
  2437. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2438. return 0;
  2439. }
  2440. /**
  2441. * ipr_store_update_fw - Update the firmware on the adapter
  2442. * @class_dev: class_device struct
  2443. * @buf: buffer
  2444. * @count: buffer size
  2445. *
  2446. * This function will update the firmware on the adapter.
  2447. *
  2448. * Return value:
  2449. * count on success / other on failure
  2450. **/
  2451. static ssize_t ipr_store_update_fw(struct class_device *class_dev,
  2452. const char *buf, size_t count)
  2453. {
  2454. struct Scsi_Host *shost = class_to_shost(class_dev);
  2455. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2456. struct ipr_ucode_image_header *image_hdr;
  2457. const struct firmware *fw_entry;
  2458. struct ipr_sglist *sglist;
  2459. char fname[100];
  2460. char *src;
  2461. int len, result, dnld_size;
  2462. if (!capable(CAP_SYS_ADMIN))
  2463. return -EACCES;
  2464. len = snprintf(fname, 99, "%s", buf);
  2465. fname[len-1] = '\0';
  2466. if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  2467. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  2468. return -EIO;
  2469. }
  2470. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  2471. if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
  2472. (ioa_cfg->vpd_cbs->page3_data.card_type &&
  2473. ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
  2474. dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
  2475. release_firmware(fw_entry);
  2476. return -EINVAL;
  2477. }
  2478. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  2479. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  2480. sglist = ipr_alloc_ucode_buffer(dnld_size);
  2481. if (!sglist) {
  2482. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  2483. release_firmware(fw_entry);
  2484. return -ENOMEM;
  2485. }
  2486. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  2487. if (result) {
  2488. dev_err(&ioa_cfg->pdev->dev,
  2489. "Microcode buffer copy to DMA buffer failed\n");
  2490. goto out;
  2491. }
  2492. result = ipr_update_ioa_ucode(ioa_cfg, sglist);
  2493. if (!result)
  2494. result = count;
  2495. out:
  2496. ipr_free_ucode_buffer(sglist);
  2497. release_firmware(fw_entry);
  2498. return result;
  2499. }
  2500. static struct class_device_attribute ipr_update_fw_attr = {
  2501. .attr = {
  2502. .name = "update_fw",
  2503. .mode = S_IWUSR,
  2504. },
  2505. .store = ipr_store_update_fw
  2506. };
  2507. static struct class_device_attribute *ipr_ioa_attrs[] = {
  2508. &ipr_fw_version_attr,
  2509. &ipr_log_level_attr,
  2510. &ipr_diagnostics_attr,
  2511. &ipr_ioa_state_attr,
  2512. &ipr_ioa_reset_attr,
  2513. &ipr_update_fw_attr,
  2514. &ipr_ioa_cache_attr,
  2515. NULL,
  2516. };
  2517. #ifdef CONFIG_SCSI_IPR_DUMP
  2518. /**
  2519. * ipr_read_dump - Dump the adapter
  2520. * @kobj: kobject struct
  2521. * @buf: buffer
  2522. * @off: offset
  2523. * @count: buffer size
  2524. *
  2525. * Return value:
  2526. * number of bytes printed to buffer
  2527. **/
  2528. static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
  2529. loff_t off, size_t count)
  2530. {
  2531. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2532. struct Scsi_Host *shost = class_to_shost(cdev);
  2533. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2534. struct ipr_dump *dump;
  2535. unsigned long lock_flags = 0;
  2536. char *src;
  2537. int len;
  2538. size_t rc = count;
  2539. if (!capable(CAP_SYS_ADMIN))
  2540. return -EACCES;
  2541. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2542. dump = ioa_cfg->dump;
  2543. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  2544. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2545. return 0;
  2546. }
  2547. kref_get(&dump->kref);
  2548. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2549. if (off > dump->driver_dump.hdr.len) {
  2550. kref_put(&dump->kref, ipr_release_dump);
  2551. return 0;
  2552. }
  2553. if (off + count > dump->driver_dump.hdr.len) {
  2554. count = dump->driver_dump.hdr.len - off;
  2555. rc = count;
  2556. }
  2557. if (count && off < sizeof(dump->driver_dump)) {
  2558. if (off + count > sizeof(dump->driver_dump))
  2559. len = sizeof(dump->driver_dump) - off;
  2560. else
  2561. len = count;
  2562. src = (u8 *)&dump->driver_dump + off;
  2563. memcpy(buf, src, len);
  2564. buf += len;
  2565. off += len;
  2566. count -= len;
  2567. }
  2568. off -= sizeof(dump->driver_dump);
  2569. if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
  2570. if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
  2571. len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
  2572. else
  2573. len = count;
  2574. src = (u8 *)&dump->ioa_dump + off;
  2575. memcpy(buf, src, len);
  2576. buf += len;
  2577. off += len;
  2578. count -= len;
  2579. }
  2580. off -= offsetof(struct ipr_ioa_dump, ioa_data);
  2581. while (count) {
  2582. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  2583. len = PAGE_ALIGN(off) - off;
  2584. else
  2585. len = count;
  2586. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  2587. src += off & ~PAGE_MASK;
  2588. memcpy(buf, src, len);
  2589. buf += len;
  2590. off += len;
  2591. count -= len;
  2592. }
  2593. kref_put(&dump->kref, ipr_release_dump);
  2594. return rc;
  2595. }
  2596. /**
  2597. * ipr_alloc_dump - Prepare for adapter dump
  2598. * @ioa_cfg: ioa config struct
  2599. *
  2600. * Return value:
  2601. * 0 on success / other on failure
  2602. **/
  2603. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  2604. {
  2605. struct ipr_dump *dump;
  2606. unsigned long lock_flags = 0;
  2607. ENTER;
  2608. dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  2609. if (!dump) {
  2610. ipr_err("Dump memory allocation failed\n");
  2611. return -ENOMEM;
  2612. }
  2613. kref_init(&dump->kref);
  2614. dump->ioa_cfg = ioa_cfg;
  2615. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2616. if (INACTIVE != ioa_cfg->sdt_state) {
  2617. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2618. kfree(dump);
  2619. return 0;
  2620. }
  2621. ioa_cfg->dump = dump;
  2622. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  2623. if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
  2624. ioa_cfg->dump_taken = 1;
  2625. schedule_work(&ioa_cfg->work_q);
  2626. }
  2627. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2628. LEAVE;
  2629. return 0;
  2630. }
  2631. /**
  2632. * ipr_free_dump - Free adapter dump memory
  2633. * @ioa_cfg: ioa config struct
  2634. *
  2635. * Return value:
  2636. * 0 on success / other on failure
  2637. **/
  2638. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  2639. {
  2640. struct ipr_dump *dump;
  2641. unsigned long lock_flags = 0;
  2642. ENTER;
  2643. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2644. dump = ioa_cfg->dump;
  2645. if (!dump) {
  2646. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2647. return 0;
  2648. }
  2649. ioa_cfg->dump = NULL;
  2650. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2651. kref_put(&dump->kref, ipr_release_dump);
  2652. LEAVE;
  2653. return 0;
  2654. }
  2655. /**
  2656. * ipr_write_dump - Setup dump state of adapter
  2657. * @kobj: kobject struct
  2658. * @buf: buffer
  2659. * @off: offset
  2660. * @count: buffer size
  2661. *
  2662. * Return value:
  2663. * number of bytes printed to buffer
  2664. **/
  2665. static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
  2666. loff_t off, size_t count)
  2667. {
  2668. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2669. struct Scsi_Host *shost = class_to_shost(cdev);
  2670. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2671. int rc;
  2672. if (!capable(CAP_SYS_ADMIN))
  2673. return -EACCES;
  2674. if (buf[0] == '1')
  2675. rc = ipr_alloc_dump(ioa_cfg);
  2676. else if (buf[0] == '0')
  2677. rc = ipr_free_dump(ioa_cfg);
  2678. else
  2679. return -EINVAL;
  2680. if (rc)
  2681. return rc;
  2682. else
  2683. return count;
  2684. }
  2685. static struct bin_attribute ipr_dump_attr = {
  2686. .attr = {
  2687. .name = "dump",
  2688. .mode = S_IRUSR | S_IWUSR,
  2689. },
  2690. .size = 0,
  2691. .read = ipr_read_dump,
  2692. .write = ipr_write_dump
  2693. };
  2694. #else
  2695. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  2696. #endif
  2697. /**
  2698. * ipr_change_queue_depth - Change the device's queue depth
  2699. * @sdev: scsi device struct
  2700. * @qdepth: depth to set
  2701. *
  2702. * Return value:
  2703. * actual depth set
  2704. **/
  2705. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2706. {
  2707. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2708. struct ipr_resource_entry *res;
  2709. unsigned long lock_flags = 0;
  2710. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2711. res = (struct ipr_resource_entry *)sdev->hostdata;
  2712. if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
  2713. qdepth = IPR_MAX_CMD_PER_ATA_LUN;
  2714. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2715. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  2716. return sdev->queue_depth;
  2717. }
  2718. /**
  2719. * ipr_change_queue_type - Change the device's queue type
  2720. * @dsev: scsi device struct
  2721. * @tag_type: type of tags to use
  2722. *
  2723. * Return value:
  2724. * actual queue type set
  2725. **/
  2726. static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
  2727. {
  2728. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2729. struct ipr_resource_entry *res;
  2730. unsigned long lock_flags = 0;
  2731. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2732. res = (struct ipr_resource_entry *)sdev->hostdata;
  2733. if (res) {
  2734. if (ipr_is_gscsi(res) && sdev->tagged_supported) {
  2735. /*
  2736. * We don't bother quiescing the device here since the
  2737. * adapter firmware does it for us.
  2738. */
  2739. scsi_set_tag_type(sdev, tag_type);
  2740. if (tag_type)
  2741. scsi_activate_tcq(sdev, sdev->queue_depth);
  2742. else
  2743. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2744. } else
  2745. tag_type = 0;
  2746. } else
  2747. tag_type = 0;
  2748. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2749. return tag_type;
  2750. }
  2751. /**
  2752. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  2753. * @dev: device struct
  2754. * @buf: buffer
  2755. *
  2756. * Return value:
  2757. * number of bytes printed to buffer
  2758. **/
  2759. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  2760. {
  2761. struct scsi_device *sdev = to_scsi_device(dev);
  2762. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2763. struct ipr_resource_entry *res;
  2764. unsigned long lock_flags = 0;
  2765. ssize_t len = -ENXIO;
  2766. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2767. res = (struct ipr_resource_entry *)sdev->hostdata;
  2768. if (res)
  2769. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
  2770. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2771. return len;
  2772. }
  2773. static struct device_attribute ipr_adapter_handle_attr = {
  2774. .attr = {
  2775. .name = "adapter_handle",
  2776. .mode = S_IRUSR,
  2777. },
  2778. .show = ipr_show_adapter_handle
  2779. };
  2780. static struct device_attribute *ipr_dev_attrs[] = {
  2781. &ipr_adapter_handle_attr,
  2782. NULL,
  2783. };
  2784. /**
  2785. * ipr_biosparam - Return the HSC mapping
  2786. * @sdev: scsi device struct
  2787. * @block_device: block device pointer
  2788. * @capacity: capacity of the device
  2789. * @parm: Array containing returned HSC values.
  2790. *
  2791. * This function generates the HSC parms that fdisk uses.
  2792. * We want to make sure we return something that places partitions
  2793. * on 4k boundaries for best performance with the IOA.
  2794. *
  2795. * Return value:
  2796. * 0 on success
  2797. **/
  2798. static int ipr_biosparam(struct scsi_device *sdev,
  2799. struct block_device *block_device,
  2800. sector_t capacity, int *parm)
  2801. {
  2802. int heads, sectors;
  2803. sector_t cylinders;
  2804. heads = 128;
  2805. sectors = 32;
  2806. cylinders = capacity;
  2807. sector_div(cylinders, (128 * 32));
  2808. /* return result */
  2809. parm[0] = heads;
  2810. parm[1] = sectors;
  2811. parm[2] = cylinders;
  2812. return 0;
  2813. }
  2814. /**
  2815. * ipr_find_starget - Find target based on bus/target.
  2816. * @starget: scsi target struct
  2817. *
  2818. * Return value:
  2819. * resource entry pointer if found / NULL if not found
  2820. **/
  2821. static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
  2822. {
  2823. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  2824. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  2825. struct ipr_resource_entry *res;
  2826. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2827. if ((res->cfgte.res_addr.bus == starget->channel) &&
  2828. (res->cfgte.res_addr.target == starget->id) &&
  2829. (res->cfgte.res_addr.lun == 0)) {
  2830. return res;
  2831. }
  2832. }
  2833. return NULL;
  2834. }
  2835. static struct ata_port_info sata_port_info;
  2836. /**
  2837. * ipr_target_alloc - Prepare for commands to a SCSI target
  2838. * @starget: scsi target struct
  2839. *
  2840. * If the device is a SATA device, this function allocates an
  2841. * ATA port with libata, else it does nothing.
  2842. *
  2843. * Return value:
  2844. * 0 on success / non-0 on failure
  2845. **/
  2846. static int ipr_target_alloc(struct scsi_target *starget)
  2847. {
  2848. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  2849. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  2850. struct ipr_sata_port *sata_port;
  2851. struct ata_port *ap;
  2852. struct ipr_resource_entry *res;
  2853. unsigned long lock_flags;
  2854. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2855. res = ipr_find_starget(starget);
  2856. starget->hostdata = NULL;
  2857. if (res && ipr_is_gata(res)) {
  2858. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2859. sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
  2860. if (!sata_port)
  2861. return -ENOMEM;
  2862. ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
  2863. if (ap) {
  2864. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2865. sata_port->ioa_cfg = ioa_cfg;
  2866. sata_port->ap = ap;
  2867. sata_port->res = res;
  2868. res->sata_port = sata_port;
  2869. ap->private_data = sata_port;
  2870. starget->hostdata = sata_port;
  2871. } else {
  2872. kfree(sata_port);
  2873. return -ENOMEM;
  2874. }
  2875. }
  2876. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2877. return 0;
  2878. }
  2879. /**
  2880. * ipr_target_destroy - Destroy a SCSI target
  2881. * @starget: scsi target struct
  2882. *
  2883. * If the device was a SATA device, this function frees the libata
  2884. * ATA port, else it does nothing.
  2885. *
  2886. **/
  2887. static void ipr_target_destroy(struct scsi_target *starget)
  2888. {
  2889. struct ipr_sata_port *sata_port = starget->hostdata;
  2890. if (sata_port) {
  2891. starget->hostdata = NULL;
  2892. ata_sas_port_destroy(sata_port->ap);
  2893. kfree(sata_port);
  2894. }
  2895. }
  2896. /**
  2897. * ipr_find_sdev - Find device based on bus/target/lun.
  2898. * @sdev: scsi device struct
  2899. *
  2900. * Return value:
  2901. * resource entry pointer if found / NULL if not found
  2902. **/
  2903. static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
  2904. {
  2905. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2906. struct ipr_resource_entry *res;
  2907. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2908. if ((res->cfgte.res_addr.bus == sdev->channel) &&
  2909. (res->cfgte.res_addr.target == sdev->id) &&
  2910. (res->cfgte.res_addr.lun == sdev->lun))
  2911. return res;
  2912. }
  2913. return NULL;
  2914. }
  2915. /**
  2916. * ipr_slave_destroy - Unconfigure a SCSI device
  2917. * @sdev: scsi device struct
  2918. *
  2919. * Return value:
  2920. * nothing
  2921. **/
  2922. static void ipr_slave_destroy(struct scsi_device *sdev)
  2923. {
  2924. struct ipr_resource_entry *res;
  2925. struct ipr_ioa_cfg *ioa_cfg;
  2926. unsigned long lock_flags = 0;
  2927. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2928. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2929. res = (struct ipr_resource_entry *) sdev->hostdata;
  2930. if (res) {
  2931. if (res->sata_port)
  2932. ata_port_disable(res->sata_port->ap);
  2933. sdev->hostdata = NULL;
  2934. res->sdev = NULL;
  2935. res->sata_port = NULL;
  2936. }
  2937. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2938. }
  2939. /**
  2940. * ipr_slave_configure - Configure a SCSI device
  2941. * @sdev: scsi device struct
  2942. *
  2943. * This function configures the specified scsi device.
  2944. *
  2945. * Return value:
  2946. * 0 on success
  2947. **/
  2948. static int ipr_slave_configure(struct scsi_device *sdev)
  2949. {
  2950. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2951. struct ipr_resource_entry *res;
  2952. unsigned long lock_flags = 0;
  2953. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2954. res = sdev->hostdata;
  2955. if (res) {
  2956. if (ipr_is_af_dasd_device(res))
  2957. sdev->type = TYPE_RAID;
  2958. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  2959. sdev->scsi_level = 4;
  2960. sdev->no_uld_attach = 1;
  2961. }
  2962. if (ipr_is_vset_device(res)) {
  2963. sdev->timeout = IPR_VSET_RW_TIMEOUT;
  2964. blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  2965. }
  2966. if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
  2967. sdev->allow_restart = 1;
  2968. if (ipr_is_gata(res) && res->sata_port) {
  2969. scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
  2970. ata_sas_slave_configure(sdev, res->sata_port->ap);
  2971. } else {
  2972. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  2973. }
  2974. }
  2975. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2976. return 0;
  2977. }
  2978. /**
  2979. * ipr_ata_slave_alloc - Prepare for commands to a SATA device
  2980. * @sdev: scsi device struct
  2981. *
  2982. * This function initializes an ATA port so that future commands
  2983. * sent through queuecommand will work.
  2984. *
  2985. * Return value:
  2986. * 0 on success
  2987. **/
  2988. static int ipr_ata_slave_alloc(struct scsi_device *sdev)
  2989. {
  2990. struct ipr_sata_port *sata_port = NULL;
  2991. int rc = -ENXIO;
  2992. ENTER;
  2993. if (sdev->sdev_target)
  2994. sata_port = sdev->sdev_target->hostdata;
  2995. if (sata_port)
  2996. rc = ata_sas_port_init(sata_port->ap);
  2997. if (rc)
  2998. ipr_slave_destroy(sdev);
  2999. LEAVE;
  3000. return rc;
  3001. }
  3002. /**
  3003. * ipr_slave_alloc - Prepare for commands to a device.
  3004. * @sdev: scsi device struct
  3005. *
  3006. * This function saves a pointer to the resource entry
  3007. * in the scsi device struct if the device exists. We
  3008. * can then use this pointer in ipr_queuecommand when
  3009. * handling new commands.
  3010. *
  3011. * Return value:
  3012. * 0 on success / -ENXIO if device does not exist
  3013. **/
  3014. static int ipr_slave_alloc(struct scsi_device *sdev)
  3015. {
  3016. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3017. struct ipr_resource_entry *res;
  3018. unsigned long lock_flags;
  3019. int rc = -ENXIO;
  3020. sdev->hostdata = NULL;
  3021. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3022. res = ipr_find_sdev(sdev);
  3023. if (res) {
  3024. res->sdev = sdev;
  3025. res->add_to_ml = 0;
  3026. res->in_erp = 0;
  3027. sdev->hostdata = res;
  3028. if (!ipr_is_naca_model(res))
  3029. res->needs_sync_complete = 1;
  3030. rc = 0;
  3031. if (ipr_is_gata(res)) {
  3032. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3033. return ipr_ata_slave_alloc(sdev);
  3034. }
  3035. }
  3036. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3037. return rc;
  3038. }
  3039. /**
  3040. * ipr_eh_host_reset - Reset the host adapter
  3041. * @scsi_cmd: scsi command struct
  3042. *
  3043. * Return value:
  3044. * SUCCESS / FAILED
  3045. **/
  3046. static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
  3047. {
  3048. struct ipr_ioa_cfg *ioa_cfg;
  3049. int rc;
  3050. ENTER;
  3051. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  3052. dev_err(&ioa_cfg->pdev->dev,
  3053. "Adapter being reset as a result of error recovery.\n");
  3054. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3055. ioa_cfg->sdt_state = GET_DUMP;
  3056. rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  3057. LEAVE;
  3058. return rc;
  3059. }
  3060. static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
  3061. {
  3062. int rc;
  3063. spin_lock_irq(cmd->device->host->host_lock);
  3064. rc = __ipr_eh_host_reset(cmd);
  3065. spin_unlock_irq(cmd->device->host->host_lock);
  3066. return rc;
  3067. }
  3068. /**
  3069. * ipr_device_reset - Reset the device
  3070. * @ioa_cfg: ioa config struct
  3071. * @res: resource entry struct
  3072. *
  3073. * This function issues a device reset to the affected device.
  3074. * If the device is a SCSI device, a LUN reset will be sent
  3075. * to the device first. If that does not work, a target reset
  3076. * will be sent. If the device is a SATA device, a PHY reset will
  3077. * be sent.
  3078. *
  3079. * Return value:
  3080. * 0 on success / non-zero on failure
  3081. **/
  3082. static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
  3083. struct ipr_resource_entry *res)
  3084. {
  3085. struct ipr_cmnd *ipr_cmd;
  3086. struct ipr_ioarcb *ioarcb;
  3087. struct ipr_cmd_pkt *cmd_pkt;
  3088. struct ipr_ioarcb_ata_regs *regs;
  3089. u32 ioasc;
  3090. ENTER;
  3091. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3092. ioarcb = &ipr_cmd->ioarcb;
  3093. cmd_pkt = &ioarcb->cmd_pkt;
  3094. regs = &ioarcb->add_data.u.regs;
  3095. ioarcb->res_handle = res->cfgte.res_handle;
  3096. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3097. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  3098. if (ipr_is_gata(res)) {
  3099. cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
  3100. ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
  3101. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  3102. }
  3103. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  3104. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3105. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3106. if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
  3107. memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
  3108. sizeof(struct ipr_ioasa_gata));
  3109. LEAVE;
  3110. return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
  3111. }
  3112. /**
  3113. * ipr_sata_reset - Reset the SATA port
  3114. * @ap: SATA port to reset
  3115. * @classes: class of the attached device
  3116. *
  3117. * This function issues a SATA phy reset to the affected ATA port.
  3118. *
  3119. * Return value:
  3120. * 0 on success / non-zero on failure
  3121. **/
  3122. static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes)
  3123. {
  3124. struct ipr_sata_port *sata_port = ap->private_data;
  3125. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  3126. struct ipr_resource_entry *res;
  3127. unsigned long lock_flags = 0;
  3128. int rc = -ENXIO;
  3129. ENTER;
  3130. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3131. while(ioa_cfg->in_reset_reload) {
  3132. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3133. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3134. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3135. }
  3136. res = sata_port->res;
  3137. if (res) {
  3138. rc = ipr_device_reset(ioa_cfg, res);
  3139. switch(res->cfgte.proto) {
  3140. case IPR_PROTO_SATA:
  3141. case IPR_PROTO_SAS_STP:
  3142. *classes = ATA_DEV_ATA;
  3143. break;
  3144. case IPR_PROTO_SATA_ATAPI:
  3145. case IPR_PROTO_SAS_STP_ATAPI:
  3146. *classes = ATA_DEV_ATAPI;
  3147. break;
  3148. default:
  3149. *classes = ATA_DEV_UNKNOWN;
  3150. break;
  3151. };
  3152. }
  3153. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3154. LEAVE;
  3155. return rc;
  3156. }
  3157. /**
  3158. * ipr_eh_dev_reset - Reset the device
  3159. * @scsi_cmd: scsi command struct
  3160. *
  3161. * This function issues a device reset to the affected device.
  3162. * A LUN reset will be sent to the device first. If that does
  3163. * not work, a target reset will be sent.
  3164. *
  3165. * Return value:
  3166. * SUCCESS / FAILED
  3167. **/
  3168. static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
  3169. {
  3170. struct ipr_cmnd *ipr_cmd;
  3171. struct ipr_ioa_cfg *ioa_cfg;
  3172. struct ipr_resource_entry *res;
  3173. struct ata_port *ap;
  3174. int rc = 0;
  3175. ENTER;
  3176. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  3177. res = scsi_cmd->device->hostdata;
  3178. if (!res)
  3179. return FAILED;
  3180. /*
  3181. * If we are currently going through reset/reload, return failed. This will force the
  3182. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  3183. * reset to complete
  3184. */
  3185. if (ioa_cfg->in_reset_reload)
  3186. return FAILED;
  3187. if (ioa_cfg->ioa_is_dead)
  3188. return FAILED;
  3189. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  3190. if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
  3191. if (ipr_cmd->scsi_cmd)
  3192. ipr_cmd->done = ipr_scsi_eh_done;
  3193. if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
  3194. ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
  3195. ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
  3196. }
  3197. }
  3198. }
  3199. res->resetting_device = 1;
  3200. scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
  3201. if (ipr_is_gata(res) && res->sata_port) {
  3202. ap = res->sata_port->ap;
  3203. spin_unlock_irq(scsi_cmd->device->host->host_lock);
  3204. ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL);
  3205. spin_lock_irq(scsi_cmd->device->host->host_lock);
  3206. } else
  3207. rc = ipr_device_reset(ioa_cfg, res);
  3208. res->resetting_device = 0;
  3209. LEAVE;
  3210. return (rc ? FAILED : SUCCESS);
  3211. }
  3212. static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
  3213. {
  3214. int rc;
  3215. spin_lock_irq(cmd->device->host->host_lock);
  3216. rc = __ipr_eh_dev_reset(cmd);
  3217. spin_unlock_irq(cmd->device->host->host_lock);
  3218. return rc;
  3219. }
  3220. /**
  3221. * ipr_bus_reset_done - Op done function for bus reset.
  3222. * @ipr_cmd: ipr command struct
  3223. *
  3224. * This function is the op done function for a bus reset
  3225. *
  3226. * Return value:
  3227. * none
  3228. **/
  3229. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  3230. {
  3231. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3232. struct ipr_resource_entry *res;
  3233. ENTER;
  3234. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3235. if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
  3236. sizeof(res->cfgte.res_handle))) {
  3237. scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
  3238. break;
  3239. }
  3240. }
  3241. /*
  3242. * If abort has not completed, indicate the reset has, else call the
  3243. * abort's done function to wake the sleeping eh thread
  3244. */
  3245. if (ipr_cmd->sibling->sibling)
  3246. ipr_cmd->sibling->sibling = NULL;
  3247. else
  3248. ipr_cmd->sibling->done(ipr_cmd->sibling);
  3249. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3250. LEAVE;
  3251. }
  3252. /**
  3253. * ipr_abort_timeout - An abort task has timed out
  3254. * @ipr_cmd: ipr command struct
  3255. *
  3256. * This function handles when an abort task times out. If this
  3257. * happens we issue a bus reset since we have resources tied
  3258. * up that must be freed before returning to the midlayer.
  3259. *
  3260. * Return value:
  3261. * none
  3262. **/
  3263. static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
  3264. {
  3265. struct ipr_cmnd *reset_cmd;
  3266. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3267. struct ipr_cmd_pkt *cmd_pkt;
  3268. unsigned long lock_flags = 0;
  3269. ENTER;
  3270. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3271. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  3272. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3273. return;
  3274. }
  3275. sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
  3276. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3277. ipr_cmd->sibling = reset_cmd;
  3278. reset_cmd->sibling = ipr_cmd;
  3279. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  3280. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  3281. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3282. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  3283. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  3284. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  3285. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3286. LEAVE;
  3287. }
  3288. /**
  3289. * ipr_cancel_op - Cancel specified op
  3290. * @scsi_cmd: scsi command struct
  3291. *
  3292. * This function cancels specified op.
  3293. *
  3294. * Return value:
  3295. * SUCCESS / FAILED
  3296. **/
  3297. static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
  3298. {
  3299. struct ipr_cmnd *ipr_cmd;
  3300. struct ipr_ioa_cfg *ioa_cfg;
  3301. struct ipr_resource_entry *res;
  3302. struct ipr_cmd_pkt *cmd_pkt;
  3303. u32 ioasc;
  3304. int op_found = 0;
  3305. ENTER;
  3306. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  3307. res = scsi_cmd->device->hostdata;
  3308. /* If we are currently going through reset/reload, return failed.
  3309. * This will force the mid-layer to call ipr_eh_host_reset,
  3310. * which will then go to sleep and wait for the reset to complete
  3311. */
  3312. if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
  3313. return FAILED;
  3314. if (!res || !ipr_is_gscsi(res))
  3315. return FAILED;
  3316. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  3317. if (ipr_cmd->scsi_cmd == scsi_cmd) {
  3318. ipr_cmd->done = ipr_scsi_eh_done;
  3319. op_found = 1;
  3320. break;
  3321. }
  3322. }
  3323. if (!op_found)
  3324. return SUCCESS;
  3325. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3326. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  3327. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3328. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3329. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3330. ipr_cmd->u.sdev = scsi_cmd->device;
  3331. scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
  3332. scsi_cmd->cmnd[0]);
  3333. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  3334. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3335. /*
  3336. * If the abort task timed out and we sent a bus reset, we will get
  3337. * one the following responses to the abort
  3338. */
  3339. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  3340. ioasc = 0;
  3341. ipr_trace;
  3342. }
  3343. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3344. if (!ipr_is_naca_model(res))
  3345. res->needs_sync_complete = 1;
  3346. LEAVE;
  3347. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  3348. }
  3349. /**
  3350. * ipr_eh_abort - Abort a single op
  3351. * @scsi_cmd: scsi command struct
  3352. *
  3353. * Return value:
  3354. * SUCCESS / FAILED
  3355. **/
  3356. static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
  3357. {
  3358. unsigned long flags;
  3359. int rc;
  3360. ENTER;
  3361. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  3362. rc = ipr_cancel_op(scsi_cmd);
  3363. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  3364. LEAVE;
  3365. return rc;
  3366. }
  3367. /**
  3368. * ipr_handle_other_interrupt - Handle "other" interrupts
  3369. * @ioa_cfg: ioa config struct
  3370. * @int_reg: interrupt register
  3371. *
  3372. * Return value:
  3373. * IRQ_NONE / IRQ_HANDLED
  3374. **/
  3375. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  3376. volatile u32 int_reg)
  3377. {
  3378. irqreturn_t rc = IRQ_HANDLED;
  3379. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  3380. /* Mask the interrupt */
  3381. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  3382. /* Clear the interrupt */
  3383. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
  3384. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  3385. list_del(&ioa_cfg->reset_cmd->queue);
  3386. del_timer(&ioa_cfg->reset_cmd->timer);
  3387. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  3388. } else {
  3389. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  3390. ioa_cfg->ioa_unit_checked = 1;
  3391. else
  3392. dev_err(&ioa_cfg->pdev->dev,
  3393. "Permanent IOA failure. 0x%08X\n", int_reg);
  3394. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3395. ioa_cfg->sdt_state = GET_DUMP;
  3396. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  3397. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3398. }
  3399. return rc;
  3400. }
  3401. /**
  3402. * ipr_isr - Interrupt service routine
  3403. * @irq: irq number
  3404. * @devp: pointer to ioa config struct
  3405. *
  3406. * Return value:
  3407. * IRQ_NONE / IRQ_HANDLED
  3408. **/
  3409. static irqreturn_t ipr_isr(int irq, void *devp)
  3410. {
  3411. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  3412. unsigned long lock_flags = 0;
  3413. volatile u32 int_reg, int_mask_reg;
  3414. u32 ioasc;
  3415. u16 cmd_index;
  3416. struct ipr_cmnd *ipr_cmd;
  3417. irqreturn_t rc = IRQ_NONE;
  3418. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3419. /* If interrupts are disabled, ignore the interrupt */
  3420. if (!ioa_cfg->allow_interrupts) {
  3421. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3422. return IRQ_NONE;
  3423. }
  3424. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  3425. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  3426. /* If an interrupt on the adapter did not occur, ignore it */
  3427. if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
  3428. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3429. return IRQ_NONE;
  3430. }
  3431. while (1) {
  3432. ipr_cmd = NULL;
  3433. while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  3434. ioa_cfg->toggle_bit) {
  3435. cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
  3436. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  3437. if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
  3438. ioa_cfg->errors_logged++;
  3439. dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
  3440. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3441. ioa_cfg->sdt_state = GET_DUMP;
  3442. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3443. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3444. return IRQ_HANDLED;
  3445. }
  3446. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  3447. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3448. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  3449. list_del(&ipr_cmd->queue);
  3450. del_timer(&ipr_cmd->timer);
  3451. ipr_cmd->done(ipr_cmd);
  3452. rc = IRQ_HANDLED;
  3453. if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
  3454. ioa_cfg->hrrq_curr++;
  3455. } else {
  3456. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  3457. ioa_cfg->toggle_bit ^= 1u;
  3458. }
  3459. }
  3460. if (ipr_cmd != NULL) {
  3461. /* Clear the PCI interrupt */
  3462. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
  3463. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  3464. } else
  3465. break;
  3466. }
  3467. if (unlikely(rc == IRQ_NONE))
  3468. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  3469. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3470. return rc;
  3471. }
  3472. /**
  3473. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  3474. * @ioa_cfg: ioa config struct
  3475. * @ipr_cmd: ipr command struct
  3476. *
  3477. * Return value:
  3478. * 0 on success / -1 on failure
  3479. **/
  3480. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  3481. struct ipr_cmnd *ipr_cmd)
  3482. {
  3483. int i;
  3484. struct scatterlist *sglist;
  3485. u32 length;
  3486. u32 ioadl_flags = 0;
  3487. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3488. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3489. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3490. length = scsi_cmd->request_bufflen;
  3491. if (length == 0)
  3492. return 0;
  3493. if (scsi_cmd->use_sg) {
  3494. ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
  3495. scsi_cmd->request_buffer,
  3496. scsi_cmd->use_sg,
  3497. scsi_cmd->sc_data_direction);
  3498. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  3499. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  3500. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3501. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  3502. ioarcb->write_ioadl_len =
  3503. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3504. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  3505. ioadl_flags = IPR_IOADL_FLAGS_READ;
  3506. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  3507. ioarcb->read_ioadl_len =
  3508. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3509. }
  3510. sglist = scsi_cmd->request_buffer;
  3511. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  3512. ioadl[i].flags_and_data_len =
  3513. cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
  3514. ioadl[i].address =
  3515. cpu_to_be32(sg_dma_address(&sglist[i]));
  3516. }
  3517. if (likely(ipr_cmd->dma_use_sg)) {
  3518. ioadl[i-1].flags_and_data_len |=
  3519. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3520. return 0;
  3521. } else
  3522. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  3523. } else {
  3524. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  3525. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  3526. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3527. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  3528. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3529. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  3530. ioadl_flags = IPR_IOADL_FLAGS_READ;
  3531. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  3532. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3533. }
  3534. ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
  3535. scsi_cmd->request_buffer, length,
  3536. scsi_cmd->sc_data_direction);
  3537. if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
  3538. ipr_cmd->dma_use_sg = 1;
  3539. ioadl[0].flags_and_data_len =
  3540. cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
  3541. ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
  3542. return 0;
  3543. } else
  3544. dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
  3545. }
  3546. return -1;
  3547. }
  3548. /**
  3549. * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
  3550. * @scsi_cmd: scsi command struct
  3551. *
  3552. * Return value:
  3553. * task attributes
  3554. **/
  3555. static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
  3556. {
  3557. u8 tag[2];
  3558. u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
  3559. if (scsi_populate_tag_msg(scsi_cmd, tag)) {
  3560. switch (tag[0]) {
  3561. case MSG_SIMPLE_TAG:
  3562. rc = IPR_FLAGS_LO_SIMPLE_TASK;
  3563. break;
  3564. case MSG_HEAD_TAG:
  3565. rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
  3566. break;
  3567. case MSG_ORDERED_TAG:
  3568. rc = IPR_FLAGS_LO_ORDERED_TASK;
  3569. break;
  3570. };
  3571. }
  3572. return rc;
  3573. }
  3574. /**
  3575. * ipr_erp_done - Process completion of ERP for a device
  3576. * @ipr_cmd: ipr command struct
  3577. *
  3578. * This function copies the sense buffer into the scsi_cmd
  3579. * struct and pushes the scsi_done function.
  3580. *
  3581. * Return value:
  3582. * nothing
  3583. **/
  3584. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  3585. {
  3586. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3587. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3588. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3589. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3590. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3591. scsi_cmd->result |= (DID_ERROR << 16);
  3592. scmd_printk(KERN_ERR, scsi_cmd,
  3593. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  3594. } else {
  3595. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  3596. SCSI_SENSE_BUFFERSIZE);
  3597. }
  3598. if (res) {
  3599. if (!ipr_is_naca_model(res))
  3600. res->needs_sync_complete = 1;
  3601. res->in_erp = 0;
  3602. }
  3603. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3604. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3605. scsi_cmd->scsi_done(scsi_cmd);
  3606. }
  3607. /**
  3608. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  3609. * @ipr_cmd: ipr command struct
  3610. *
  3611. * Return value:
  3612. * none
  3613. **/
  3614. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  3615. {
  3616. struct ipr_ioarcb *ioarcb;
  3617. struct ipr_ioasa *ioasa;
  3618. ioarcb = &ipr_cmd->ioarcb;
  3619. ioasa = &ipr_cmd->ioasa;
  3620. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  3621. ioarcb->write_data_transfer_length = 0;
  3622. ioarcb->read_data_transfer_length = 0;
  3623. ioarcb->write_ioadl_len = 0;
  3624. ioarcb->read_ioadl_len = 0;
  3625. ioasa->ioasc = 0;
  3626. ioasa->residual_data_len = 0;
  3627. }
  3628. /**
  3629. * ipr_erp_request_sense - Send request sense to a device
  3630. * @ipr_cmd: ipr command struct
  3631. *
  3632. * This function sends a request sense to a device as a result
  3633. * of a check condition.
  3634. *
  3635. * Return value:
  3636. * nothing
  3637. **/
  3638. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  3639. {
  3640. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3641. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3642. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3643. ipr_erp_done(ipr_cmd);
  3644. return;
  3645. }
  3646. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3647. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  3648. cmd_pkt->cdb[0] = REQUEST_SENSE;
  3649. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  3650. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  3651. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3652. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  3653. ipr_cmd->ioadl[0].flags_and_data_len =
  3654. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
  3655. ipr_cmd->ioadl[0].address =
  3656. cpu_to_be32(ipr_cmd->sense_buffer_dma);
  3657. ipr_cmd->ioarcb.read_ioadl_len =
  3658. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3659. ipr_cmd->ioarcb.read_data_transfer_length =
  3660. cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
  3661. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  3662. IPR_REQUEST_SENSE_TIMEOUT * 2);
  3663. }
  3664. /**
  3665. * ipr_erp_cancel_all - Send cancel all to a device
  3666. * @ipr_cmd: ipr command struct
  3667. *
  3668. * This function sends a cancel all to a device to clear the
  3669. * queue. If we are running TCQ on the device, QERR is set to 1,
  3670. * which means all outstanding ops have been dropped on the floor.
  3671. * Cancel all will return them to us.
  3672. *
  3673. * Return value:
  3674. * nothing
  3675. **/
  3676. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  3677. {
  3678. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3679. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3680. struct ipr_cmd_pkt *cmd_pkt;
  3681. res->in_erp = 1;
  3682. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3683. if (!scsi_get_tag_type(scsi_cmd->device)) {
  3684. ipr_erp_request_sense(ipr_cmd);
  3685. return;
  3686. }
  3687. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3688. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3689. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3690. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  3691. IPR_CANCEL_ALL_TIMEOUT);
  3692. }
  3693. /**
  3694. * ipr_dump_ioasa - Dump contents of IOASA
  3695. * @ioa_cfg: ioa config struct
  3696. * @ipr_cmd: ipr command struct
  3697. * @res: resource entry struct
  3698. *
  3699. * This function is invoked by the interrupt handler when ops
  3700. * fail. It will log the IOASA if appropriate. Only called
  3701. * for GPDD ops.
  3702. *
  3703. * Return value:
  3704. * none
  3705. **/
  3706. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  3707. struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
  3708. {
  3709. int i;
  3710. u16 data_len;
  3711. u32 ioasc;
  3712. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3713. __be32 *ioasa_data = (__be32 *)ioasa;
  3714. int error_index;
  3715. ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
  3716. if (0 == ioasc)
  3717. return;
  3718. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  3719. return;
  3720. error_index = ipr_get_error(ioasc);
  3721. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  3722. /* Don't log an error if the IOA already logged one */
  3723. if (ioasa->ilid != 0)
  3724. return;
  3725. if (ipr_error_table[error_index].log_ioasa == 0)
  3726. return;
  3727. }
  3728. ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
  3729. if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
  3730. data_len = sizeof(struct ipr_ioasa);
  3731. else
  3732. data_len = be16_to_cpu(ioasa->ret_stat_len);
  3733. ipr_err("IOASA Dump:\n");
  3734. for (i = 0; i < data_len / 4; i += 4) {
  3735. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  3736. be32_to_cpu(ioasa_data[i]),
  3737. be32_to_cpu(ioasa_data[i+1]),
  3738. be32_to_cpu(ioasa_data[i+2]),
  3739. be32_to_cpu(ioasa_data[i+3]));
  3740. }
  3741. }
  3742. /**
  3743. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  3744. * @ioasa: IOASA
  3745. * @sense_buf: sense data buffer
  3746. *
  3747. * Return value:
  3748. * none
  3749. **/
  3750. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  3751. {
  3752. u32 failing_lba;
  3753. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  3754. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  3755. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3756. u32 ioasc = be32_to_cpu(ioasa->ioasc);
  3757. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  3758. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  3759. return;
  3760. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  3761. if (ipr_is_vset_device(res) &&
  3762. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  3763. ioasa->u.vset.failing_lba_hi != 0) {
  3764. sense_buf[0] = 0x72;
  3765. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  3766. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  3767. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  3768. sense_buf[7] = 12;
  3769. sense_buf[8] = 0;
  3770. sense_buf[9] = 0x0A;
  3771. sense_buf[10] = 0x80;
  3772. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  3773. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  3774. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  3775. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  3776. sense_buf[15] = failing_lba & 0x000000ff;
  3777. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3778. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  3779. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  3780. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  3781. sense_buf[19] = failing_lba & 0x000000ff;
  3782. } else {
  3783. sense_buf[0] = 0x70;
  3784. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  3785. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  3786. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  3787. /* Illegal request */
  3788. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  3789. (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  3790. sense_buf[7] = 10; /* additional length */
  3791. /* IOARCB was in error */
  3792. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  3793. sense_buf[15] = 0xC0;
  3794. else /* Parameter data was invalid */
  3795. sense_buf[15] = 0x80;
  3796. sense_buf[16] =
  3797. ((IPR_FIELD_POINTER_MASK &
  3798. be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
  3799. sense_buf[17] =
  3800. (IPR_FIELD_POINTER_MASK &
  3801. be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
  3802. } else {
  3803. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  3804. if (ipr_is_vset_device(res))
  3805. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3806. else
  3807. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  3808. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  3809. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  3810. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  3811. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  3812. sense_buf[6] = failing_lba & 0x000000ff;
  3813. }
  3814. sense_buf[7] = 6; /* additional length */
  3815. }
  3816. }
  3817. }
  3818. /**
  3819. * ipr_get_autosense - Copy autosense data to sense buffer
  3820. * @ipr_cmd: ipr command struct
  3821. *
  3822. * This function copies the autosense buffer to the buffer
  3823. * in the scsi_cmd, if there is autosense available.
  3824. *
  3825. * Return value:
  3826. * 1 if autosense was available / 0 if not
  3827. **/
  3828. static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
  3829. {
  3830. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3831. if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
  3832. return 0;
  3833. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
  3834. min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
  3835. SCSI_SENSE_BUFFERSIZE));
  3836. return 1;
  3837. }
  3838. /**
  3839. * ipr_erp_start - Process an error response for a SCSI op
  3840. * @ioa_cfg: ioa config struct
  3841. * @ipr_cmd: ipr command struct
  3842. *
  3843. * This function determines whether or not to initiate ERP
  3844. * on the affected device.
  3845. *
  3846. * Return value:
  3847. * nothing
  3848. **/
  3849. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  3850. struct ipr_cmnd *ipr_cmd)
  3851. {
  3852. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3853. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3854. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3855. if (!res) {
  3856. ipr_scsi_eh_done(ipr_cmd);
  3857. return;
  3858. }
  3859. if (ipr_is_gscsi(res))
  3860. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  3861. else
  3862. ipr_gen_sense(ipr_cmd);
  3863. switch (ioasc & IPR_IOASC_IOASC_MASK) {
  3864. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  3865. if (ipr_is_naca_model(res))
  3866. scsi_cmd->result |= (DID_ABORT << 16);
  3867. else
  3868. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3869. break;
  3870. case IPR_IOASC_IR_RESOURCE_HANDLE:
  3871. case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
  3872. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3873. break;
  3874. case IPR_IOASC_HW_SEL_TIMEOUT:
  3875. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3876. if (!ipr_is_naca_model(res))
  3877. res->needs_sync_complete = 1;
  3878. break;
  3879. case IPR_IOASC_SYNC_REQUIRED:
  3880. if (!res->in_erp)
  3881. res->needs_sync_complete = 1;
  3882. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3883. break;
  3884. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  3885. case IPR_IOASA_IR_DUAL_IOA_DISABLED:
  3886. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  3887. break;
  3888. case IPR_IOASC_BUS_WAS_RESET:
  3889. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  3890. /*
  3891. * Report the bus reset and ask for a retry. The device
  3892. * will give CC/UA the next command.
  3893. */
  3894. if (!res->resetting_device)
  3895. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  3896. scsi_cmd->result |= (DID_ERROR << 16);
  3897. if (!ipr_is_naca_model(res))
  3898. res->needs_sync_complete = 1;
  3899. break;
  3900. case IPR_IOASC_HW_DEV_BUS_STATUS:
  3901. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  3902. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  3903. if (!ipr_get_autosense(ipr_cmd)) {
  3904. if (!ipr_is_naca_model(res)) {
  3905. ipr_erp_cancel_all(ipr_cmd);
  3906. return;
  3907. }
  3908. }
  3909. }
  3910. if (!ipr_is_naca_model(res))
  3911. res->needs_sync_complete = 1;
  3912. break;
  3913. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  3914. break;
  3915. default:
  3916. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  3917. scsi_cmd->result |= (DID_ERROR << 16);
  3918. if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
  3919. res->needs_sync_complete = 1;
  3920. break;
  3921. }
  3922. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3923. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3924. scsi_cmd->scsi_done(scsi_cmd);
  3925. }
  3926. /**
  3927. * ipr_scsi_done - mid-layer done function
  3928. * @ipr_cmd: ipr command struct
  3929. *
  3930. * This function is invoked by the interrupt handler for
  3931. * ops generated by the SCSI mid-layer
  3932. *
  3933. * Return value:
  3934. * none
  3935. **/
  3936. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  3937. {
  3938. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3939. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3940. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3941. scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
  3942. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  3943. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3944. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3945. scsi_cmd->scsi_done(scsi_cmd);
  3946. } else
  3947. ipr_erp_start(ioa_cfg, ipr_cmd);
  3948. }
  3949. /**
  3950. * ipr_queuecommand - Queue a mid-layer request
  3951. * @scsi_cmd: scsi command struct
  3952. * @done: done function
  3953. *
  3954. * This function queues a request generated by the mid-layer.
  3955. *
  3956. * Return value:
  3957. * 0 on success
  3958. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  3959. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  3960. **/
  3961. static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
  3962. void (*done) (struct scsi_cmnd *))
  3963. {
  3964. struct ipr_ioa_cfg *ioa_cfg;
  3965. struct ipr_resource_entry *res;
  3966. struct ipr_ioarcb *ioarcb;
  3967. struct ipr_cmnd *ipr_cmd;
  3968. int rc = 0;
  3969. scsi_cmd->scsi_done = done;
  3970. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  3971. res = scsi_cmd->device->hostdata;
  3972. scsi_cmd->result = (DID_OK << 16);
  3973. /*
  3974. * We are currently blocking all devices due to a host reset
  3975. * We have told the host to stop giving us new requests, but
  3976. * ERP ops don't count. FIXME
  3977. */
  3978. if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
  3979. return SCSI_MLQUEUE_HOST_BUSY;
  3980. /*
  3981. * FIXME - Create scsi_set_host_offline interface
  3982. * and the ioa_is_dead check can be removed
  3983. */
  3984. if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
  3985. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  3986. scsi_cmd->result = (DID_NO_CONNECT << 16);
  3987. scsi_cmd->scsi_done(scsi_cmd);
  3988. return 0;
  3989. }
  3990. if (ipr_is_gata(res) && res->sata_port)
  3991. return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
  3992. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3993. ioarcb = &ipr_cmd->ioarcb;
  3994. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  3995. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  3996. ipr_cmd->scsi_cmd = scsi_cmd;
  3997. ioarcb->res_handle = res->cfgte.res_handle;
  3998. ipr_cmd->done = ipr_scsi_done;
  3999. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  4000. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  4001. if (scsi_cmd->underflow == 0)
  4002. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  4003. if (res->needs_sync_complete) {
  4004. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  4005. res->needs_sync_complete = 0;
  4006. }
  4007. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  4008. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  4009. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  4010. ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
  4011. }
  4012. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  4013. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
  4014. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4015. if (likely(rc == 0))
  4016. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  4017. if (likely(rc == 0)) {
  4018. mb();
  4019. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  4020. ioa_cfg->regs.ioarrin_reg);
  4021. } else {
  4022. list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4023. return SCSI_MLQUEUE_HOST_BUSY;
  4024. }
  4025. return 0;
  4026. }
  4027. /**
  4028. * ipr_ioctl - IOCTL handler
  4029. * @sdev: scsi device struct
  4030. * @cmd: IOCTL cmd
  4031. * @arg: IOCTL arg
  4032. *
  4033. * Return value:
  4034. * 0 on success / other on failure
  4035. **/
  4036. int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
  4037. {
  4038. struct ipr_resource_entry *res;
  4039. res = (struct ipr_resource_entry *)sdev->hostdata;
  4040. if (res && ipr_is_gata(res))
  4041. return ata_scsi_ioctl(sdev, cmd, arg);
  4042. return -EINVAL;
  4043. }
  4044. /**
  4045. * ipr_info - Get information about the card/driver
  4046. * @scsi_host: scsi host struct
  4047. *
  4048. * Return value:
  4049. * pointer to buffer with description string
  4050. **/
  4051. static const char * ipr_ioa_info(struct Scsi_Host *host)
  4052. {
  4053. static char buffer[512];
  4054. struct ipr_ioa_cfg *ioa_cfg;
  4055. unsigned long lock_flags = 0;
  4056. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  4057. spin_lock_irqsave(host->host_lock, lock_flags);
  4058. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  4059. spin_unlock_irqrestore(host->host_lock, lock_flags);
  4060. return buffer;
  4061. }
  4062. static struct scsi_host_template driver_template = {
  4063. .module = THIS_MODULE,
  4064. .name = "IPR",
  4065. .info = ipr_ioa_info,
  4066. .ioctl = ipr_ioctl,
  4067. .queuecommand = ipr_queuecommand,
  4068. .eh_abort_handler = ipr_eh_abort,
  4069. .eh_device_reset_handler = ipr_eh_dev_reset,
  4070. .eh_host_reset_handler = ipr_eh_host_reset,
  4071. .slave_alloc = ipr_slave_alloc,
  4072. .slave_configure = ipr_slave_configure,
  4073. .slave_destroy = ipr_slave_destroy,
  4074. .target_alloc = ipr_target_alloc,
  4075. .target_destroy = ipr_target_destroy,
  4076. .change_queue_depth = ipr_change_queue_depth,
  4077. .change_queue_type = ipr_change_queue_type,
  4078. .bios_param = ipr_biosparam,
  4079. .can_queue = IPR_MAX_COMMANDS,
  4080. .this_id = -1,
  4081. .sg_tablesize = IPR_MAX_SGLIST,
  4082. .max_sectors = IPR_IOA_MAX_SECTORS,
  4083. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  4084. .use_clustering = ENABLE_CLUSTERING,
  4085. .shost_attrs = ipr_ioa_attrs,
  4086. .sdev_attrs = ipr_dev_attrs,
  4087. .proc_name = IPR_NAME
  4088. };
  4089. /**
  4090. * ipr_ata_phy_reset - libata phy_reset handler
  4091. * @ap: ata port to reset
  4092. *
  4093. **/
  4094. static void ipr_ata_phy_reset(struct ata_port *ap)
  4095. {
  4096. unsigned long flags;
  4097. struct ipr_sata_port *sata_port = ap->private_data;
  4098. struct ipr_resource_entry *res = sata_port->res;
  4099. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4100. int rc;
  4101. ENTER;
  4102. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4103. while(ioa_cfg->in_reset_reload) {
  4104. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4105. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4106. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4107. }
  4108. if (!ioa_cfg->allow_cmds)
  4109. goto out_unlock;
  4110. rc = ipr_device_reset(ioa_cfg, res);
  4111. if (rc) {
  4112. ap->ops->port_disable(ap);
  4113. goto out_unlock;
  4114. }
  4115. switch(res->cfgte.proto) {
  4116. case IPR_PROTO_SATA:
  4117. case IPR_PROTO_SAS_STP:
  4118. ap->device[0].class = ATA_DEV_ATA;
  4119. break;
  4120. case IPR_PROTO_SATA_ATAPI:
  4121. case IPR_PROTO_SAS_STP_ATAPI:
  4122. ap->device[0].class = ATA_DEV_ATAPI;
  4123. break;
  4124. default:
  4125. ap->device[0].class = ATA_DEV_UNKNOWN;
  4126. ap->ops->port_disable(ap);
  4127. break;
  4128. };
  4129. out_unlock:
  4130. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4131. LEAVE;
  4132. }
  4133. /**
  4134. * ipr_ata_post_internal - Cleanup after an internal command
  4135. * @qc: ATA queued command
  4136. *
  4137. * Return value:
  4138. * none
  4139. **/
  4140. static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
  4141. {
  4142. struct ipr_sata_port *sata_port = qc->ap->private_data;
  4143. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4144. struct ipr_cmnd *ipr_cmd;
  4145. unsigned long flags;
  4146. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4147. while(ioa_cfg->in_reset_reload) {
  4148. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4149. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4150. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4151. }
  4152. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  4153. if (ipr_cmd->qc == qc) {
  4154. ipr_device_reset(ioa_cfg, sata_port->res);
  4155. break;
  4156. }
  4157. }
  4158. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4159. }
  4160. /**
  4161. * ipr_tf_read - Read the current ATA taskfile for the ATA port
  4162. * @ap: ATA port
  4163. * @tf: destination ATA taskfile
  4164. *
  4165. * Return value:
  4166. * none
  4167. **/
  4168. static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
  4169. {
  4170. struct ipr_sata_port *sata_port = ap->private_data;
  4171. struct ipr_ioasa_gata *g = &sata_port->ioasa;
  4172. tf->feature = g->error;
  4173. tf->nsect = g->nsect;
  4174. tf->lbal = g->lbal;
  4175. tf->lbam = g->lbam;
  4176. tf->lbah = g->lbah;
  4177. tf->device = g->device;
  4178. tf->command = g->status;
  4179. tf->hob_nsect = g->hob_nsect;
  4180. tf->hob_lbal = g->hob_lbal;
  4181. tf->hob_lbam = g->hob_lbam;
  4182. tf->hob_lbah = g->hob_lbah;
  4183. tf->ctl = g->alt_status;
  4184. }
  4185. /**
  4186. * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
  4187. * @regs: destination
  4188. * @tf: source ATA taskfile
  4189. *
  4190. * Return value:
  4191. * none
  4192. **/
  4193. static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
  4194. struct ata_taskfile *tf)
  4195. {
  4196. regs->feature = tf->feature;
  4197. regs->nsect = tf->nsect;
  4198. regs->lbal = tf->lbal;
  4199. regs->lbam = tf->lbam;
  4200. regs->lbah = tf->lbah;
  4201. regs->device = tf->device;
  4202. regs->command = tf->command;
  4203. regs->hob_feature = tf->hob_feature;
  4204. regs->hob_nsect = tf->hob_nsect;
  4205. regs->hob_lbal = tf->hob_lbal;
  4206. regs->hob_lbam = tf->hob_lbam;
  4207. regs->hob_lbah = tf->hob_lbah;
  4208. regs->ctl = tf->ctl;
  4209. }
  4210. /**
  4211. * ipr_sata_done - done function for SATA commands
  4212. * @ipr_cmd: ipr command struct
  4213. *
  4214. * This function is invoked by the interrupt handler for
  4215. * ops generated by the SCSI mid-layer to SATA devices
  4216. *
  4217. * Return value:
  4218. * none
  4219. **/
  4220. static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
  4221. {
  4222. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4223. struct ata_queued_cmd *qc = ipr_cmd->qc;
  4224. struct ipr_sata_port *sata_port = qc->ap->private_data;
  4225. struct ipr_resource_entry *res = sata_port->res;
  4226. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4227. memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
  4228. sizeof(struct ipr_ioasa_gata));
  4229. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  4230. if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
  4231. scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
  4232. res->cfgte.res_addr.target);
  4233. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  4234. qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
  4235. else
  4236. qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
  4237. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4238. ata_qc_complete(qc);
  4239. }
  4240. /**
  4241. * ipr_build_ata_ioadl - Build an ATA scatter/gather list
  4242. * @ipr_cmd: ipr command struct
  4243. * @qc: ATA queued command
  4244. *
  4245. **/
  4246. static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
  4247. struct ata_queued_cmd *qc)
  4248. {
  4249. u32 ioadl_flags = 0;
  4250. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4251. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4252. int len = qc->nbytes + qc->pad_len;
  4253. struct scatterlist *sg;
  4254. if (len == 0)
  4255. return;
  4256. if (qc->dma_dir == DMA_TO_DEVICE) {
  4257. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  4258. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4259. ioarcb->write_data_transfer_length = cpu_to_be32(len);
  4260. ioarcb->write_ioadl_len =
  4261. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4262. } else if (qc->dma_dir == DMA_FROM_DEVICE) {
  4263. ioadl_flags = IPR_IOADL_FLAGS_READ;
  4264. ioarcb->read_data_transfer_length = cpu_to_be32(len);
  4265. ioarcb->read_ioadl_len =
  4266. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4267. }
  4268. ata_for_each_sg(sg, qc) {
  4269. ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  4270. ioadl->address = cpu_to_be32(sg_dma_address(sg));
  4271. if (ata_sg_is_last(sg, qc))
  4272. ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  4273. else
  4274. ioadl++;
  4275. }
  4276. }
  4277. /**
  4278. * ipr_qc_issue - Issue a SATA qc to a device
  4279. * @qc: queued command
  4280. *
  4281. * Return value:
  4282. * 0 if success
  4283. **/
  4284. static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
  4285. {
  4286. struct ata_port *ap = qc->ap;
  4287. struct ipr_sata_port *sata_port = ap->private_data;
  4288. struct ipr_resource_entry *res = sata_port->res;
  4289. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4290. struct ipr_cmnd *ipr_cmd;
  4291. struct ipr_ioarcb *ioarcb;
  4292. struct ipr_ioarcb_ata_regs *regs;
  4293. if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
  4294. return -EIO;
  4295. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4296. ioarcb = &ipr_cmd->ioarcb;
  4297. regs = &ioarcb->add_data.u.regs;
  4298. memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
  4299. ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
  4300. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  4301. ipr_cmd->qc = qc;
  4302. ipr_cmd->done = ipr_sata_done;
  4303. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  4304. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
  4305. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  4306. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  4307. ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
  4308. ipr_build_ata_ioadl(ipr_cmd, qc);
  4309. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  4310. ipr_copy_sata_tf(regs, &qc->tf);
  4311. memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
  4312. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  4313. switch (qc->tf.protocol) {
  4314. case ATA_PROT_NODATA:
  4315. case ATA_PROT_PIO:
  4316. break;
  4317. case ATA_PROT_DMA:
  4318. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  4319. break;
  4320. case ATA_PROT_ATAPI:
  4321. case ATA_PROT_ATAPI_NODATA:
  4322. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  4323. break;
  4324. case ATA_PROT_ATAPI_DMA:
  4325. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  4326. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  4327. break;
  4328. default:
  4329. WARN_ON(1);
  4330. return -1;
  4331. }
  4332. mb();
  4333. writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
  4334. ioa_cfg->regs.ioarrin_reg);
  4335. return 0;
  4336. }
  4337. /**
  4338. * ipr_ata_check_status - Return last ATA status
  4339. * @ap: ATA port
  4340. *
  4341. * Return value:
  4342. * ATA status
  4343. **/
  4344. static u8 ipr_ata_check_status(struct ata_port *ap)
  4345. {
  4346. struct ipr_sata_port *sata_port = ap->private_data;
  4347. return sata_port->ioasa.status;
  4348. }
  4349. /**
  4350. * ipr_ata_check_altstatus - Return last ATA altstatus
  4351. * @ap: ATA port
  4352. *
  4353. * Return value:
  4354. * Alt ATA status
  4355. **/
  4356. static u8 ipr_ata_check_altstatus(struct ata_port *ap)
  4357. {
  4358. struct ipr_sata_port *sata_port = ap->private_data;
  4359. return sata_port->ioasa.alt_status;
  4360. }
  4361. static struct ata_port_operations ipr_sata_ops = {
  4362. .port_disable = ata_port_disable,
  4363. .check_status = ipr_ata_check_status,
  4364. .check_altstatus = ipr_ata_check_altstatus,
  4365. .dev_select = ata_noop_dev_select,
  4366. .phy_reset = ipr_ata_phy_reset,
  4367. .post_internal_cmd = ipr_ata_post_internal,
  4368. .tf_read = ipr_tf_read,
  4369. .qc_prep = ata_noop_qc_prep,
  4370. .qc_issue = ipr_qc_issue,
  4371. .port_start = ata_sas_port_start,
  4372. .port_stop = ata_sas_port_stop
  4373. };
  4374. static struct ata_port_info sata_port_info = {
  4375. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
  4376. ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
  4377. .pio_mask = 0x10, /* pio4 */
  4378. .mwdma_mask = 0x07,
  4379. .udma_mask = 0x7f, /* udma0-6 */
  4380. .port_ops = &ipr_sata_ops
  4381. };
  4382. #ifdef CONFIG_PPC_PSERIES
  4383. static const u16 ipr_blocked_processors[] = {
  4384. PV_NORTHSTAR,
  4385. PV_PULSAR,
  4386. PV_POWER4,
  4387. PV_ICESTAR,
  4388. PV_SSTAR,
  4389. PV_POWER4p,
  4390. PV_630,
  4391. PV_630p
  4392. };
  4393. /**
  4394. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  4395. * @ioa_cfg: ioa cfg struct
  4396. *
  4397. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  4398. * certain pSeries hardware. This function determines if the given
  4399. * adapter is in one of these confgurations or not.
  4400. *
  4401. * Return value:
  4402. * 1 if adapter is not supported / 0 if adapter is supported
  4403. **/
  4404. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  4405. {
  4406. u8 rev_id;
  4407. int i;
  4408. if (ioa_cfg->type == 0x5702) {
  4409. if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
  4410. &rev_id) == PCIBIOS_SUCCESSFUL) {
  4411. if (rev_id < 4) {
  4412. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
  4413. if (__is_processor(ipr_blocked_processors[i]))
  4414. return 1;
  4415. }
  4416. }
  4417. }
  4418. }
  4419. return 0;
  4420. }
  4421. #else
  4422. #define ipr_invalid_adapter(ioa_cfg) 0
  4423. #endif
  4424. /**
  4425. * ipr_ioa_bringdown_done - IOA bring down completion.
  4426. * @ipr_cmd: ipr command struct
  4427. *
  4428. * This function processes the completion of an adapter bring down.
  4429. * It wakes any reset sleepers.
  4430. *
  4431. * Return value:
  4432. * IPR_RC_JOB_RETURN
  4433. **/
  4434. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  4435. {
  4436. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4437. ENTER;
  4438. ioa_cfg->in_reset_reload = 0;
  4439. ioa_cfg->reset_retries = 0;
  4440. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4441. wake_up_all(&ioa_cfg->reset_wait_q);
  4442. spin_unlock_irq(ioa_cfg->host->host_lock);
  4443. scsi_unblock_requests(ioa_cfg->host);
  4444. spin_lock_irq(ioa_cfg->host->host_lock);
  4445. LEAVE;
  4446. return IPR_RC_JOB_RETURN;
  4447. }
  4448. /**
  4449. * ipr_ioa_reset_done - IOA reset completion.
  4450. * @ipr_cmd: ipr command struct
  4451. *
  4452. * This function processes the completion of an adapter reset.
  4453. * It schedules any necessary mid-layer add/removes and
  4454. * wakes any reset sleepers.
  4455. *
  4456. * Return value:
  4457. * IPR_RC_JOB_RETURN
  4458. **/
  4459. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  4460. {
  4461. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4462. struct ipr_resource_entry *res;
  4463. struct ipr_hostrcb *hostrcb, *temp;
  4464. int i = 0;
  4465. ENTER;
  4466. ioa_cfg->in_reset_reload = 0;
  4467. ioa_cfg->allow_cmds = 1;
  4468. ioa_cfg->reset_cmd = NULL;
  4469. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  4470. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4471. if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
  4472. ipr_trace;
  4473. break;
  4474. }
  4475. }
  4476. schedule_work(&ioa_cfg->work_q);
  4477. list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
  4478. list_del(&hostrcb->queue);
  4479. if (i++ < IPR_NUM_LOG_HCAMS)
  4480. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  4481. else
  4482. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  4483. }
  4484. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  4485. ioa_cfg->reset_retries = 0;
  4486. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4487. wake_up_all(&ioa_cfg->reset_wait_q);
  4488. spin_unlock_irq(ioa_cfg->host->host_lock);
  4489. scsi_unblock_requests(ioa_cfg->host);
  4490. spin_lock_irq(ioa_cfg->host->host_lock);
  4491. if (!ioa_cfg->allow_cmds)
  4492. scsi_block_requests(ioa_cfg->host);
  4493. LEAVE;
  4494. return IPR_RC_JOB_RETURN;
  4495. }
  4496. /**
  4497. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  4498. * @supported_dev: supported device struct
  4499. * @vpids: vendor product id struct
  4500. *
  4501. * Return value:
  4502. * none
  4503. **/
  4504. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  4505. struct ipr_std_inq_vpids *vpids)
  4506. {
  4507. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  4508. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  4509. supported_dev->num_records = 1;
  4510. supported_dev->data_length =
  4511. cpu_to_be16(sizeof(struct ipr_supported_device));
  4512. supported_dev->reserved = 0;
  4513. }
  4514. /**
  4515. * ipr_set_supported_devs - Send Set Supported Devices for a device
  4516. * @ipr_cmd: ipr command struct
  4517. *
  4518. * This function send a Set Supported Devices to the adapter
  4519. *
  4520. * Return value:
  4521. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4522. **/
  4523. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  4524. {
  4525. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4526. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  4527. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4528. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4529. struct ipr_resource_entry *res = ipr_cmd->u.res;
  4530. ipr_cmd->job_step = ipr_ioa_reset_done;
  4531. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  4532. if (!ipr_is_scsi_disk(res))
  4533. continue;
  4534. ipr_cmd->u.res = res;
  4535. ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
  4536. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4537. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4538. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4539. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  4540. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  4541. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  4542. ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
  4543. sizeof(struct ipr_supported_device));
  4544. ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
  4545. offsetof(struct ipr_misc_cbs, supp_dev));
  4546. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4547. ioarcb->write_data_transfer_length =
  4548. cpu_to_be32(sizeof(struct ipr_supported_device));
  4549. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  4550. IPR_SET_SUP_DEVICE_TIMEOUT);
  4551. ipr_cmd->job_step = ipr_set_supported_devs;
  4552. return IPR_RC_JOB_RETURN;
  4553. }
  4554. return IPR_RC_JOB_CONTINUE;
  4555. }
  4556. /**
  4557. * ipr_setup_write_cache - Disable write cache if needed
  4558. * @ipr_cmd: ipr command struct
  4559. *
  4560. * This function sets up adapters write cache to desired setting
  4561. *
  4562. * Return value:
  4563. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4564. **/
  4565. static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
  4566. {
  4567. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4568. ipr_cmd->job_step = ipr_set_supported_devs;
  4569. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  4570. struct ipr_resource_entry, queue);
  4571. if (ioa_cfg->cache_state != CACHE_DISABLED)
  4572. return IPR_RC_JOB_CONTINUE;
  4573. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4574. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4575. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  4576. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  4577. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4578. return IPR_RC_JOB_RETURN;
  4579. }
  4580. /**
  4581. * ipr_get_mode_page - Locate specified mode page
  4582. * @mode_pages: mode page buffer
  4583. * @page_code: page code to find
  4584. * @len: minimum required length for mode page
  4585. *
  4586. * Return value:
  4587. * pointer to mode page / NULL on failure
  4588. **/
  4589. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  4590. u32 page_code, u32 len)
  4591. {
  4592. struct ipr_mode_page_hdr *mode_hdr;
  4593. u32 page_length;
  4594. u32 length;
  4595. if (!mode_pages || (mode_pages->hdr.length == 0))
  4596. return NULL;
  4597. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  4598. mode_hdr = (struct ipr_mode_page_hdr *)
  4599. (mode_pages->data + mode_pages->hdr.block_desc_len);
  4600. while (length) {
  4601. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  4602. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  4603. return mode_hdr;
  4604. break;
  4605. } else {
  4606. page_length = (sizeof(struct ipr_mode_page_hdr) +
  4607. mode_hdr->page_length);
  4608. length -= page_length;
  4609. mode_hdr = (struct ipr_mode_page_hdr *)
  4610. ((unsigned long)mode_hdr + page_length);
  4611. }
  4612. }
  4613. return NULL;
  4614. }
  4615. /**
  4616. * ipr_check_term_power - Check for term power errors
  4617. * @ioa_cfg: ioa config struct
  4618. * @mode_pages: IOAFP mode pages buffer
  4619. *
  4620. * Check the IOAFP's mode page 28 for term power errors
  4621. *
  4622. * Return value:
  4623. * nothing
  4624. **/
  4625. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  4626. struct ipr_mode_pages *mode_pages)
  4627. {
  4628. int i;
  4629. int entry_length;
  4630. struct ipr_dev_bus_entry *bus;
  4631. struct ipr_mode_page28 *mode_page;
  4632. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  4633. sizeof(struct ipr_mode_page28));
  4634. entry_length = mode_page->entry_length;
  4635. bus = mode_page->bus;
  4636. for (i = 0; i < mode_page->num_entries; i++) {
  4637. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  4638. dev_err(&ioa_cfg->pdev->dev,
  4639. "Term power is absent on scsi bus %d\n",
  4640. bus->res_addr.bus);
  4641. }
  4642. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  4643. }
  4644. }
  4645. /**
  4646. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  4647. * @ioa_cfg: ioa config struct
  4648. *
  4649. * Looks through the config table checking for SES devices. If
  4650. * the SES device is in the SES table indicating a maximum SCSI
  4651. * bus speed, the speed is limited for the bus.
  4652. *
  4653. * Return value:
  4654. * none
  4655. **/
  4656. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  4657. {
  4658. u32 max_xfer_rate;
  4659. int i;
  4660. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  4661. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  4662. ioa_cfg->bus_attr[i].bus_width);
  4663. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  4664. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  4665. }
  4666. }
  4667. /**
  4668. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  4669. * @ioa_cfg: ioa config struct
  4670. * @mode_pages: mode page 28 buffer
  4671. *
  4672. * Updates mode page 28 based on driver configuration
  4673. *
  4674. * Return value:
  4675. * none
  4676. **/
  4677. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  4678. struct ipr_mode_pages *mode_pages)
  4679. {
  4680. int i, entry_length;
  4681. struct ipr_dev_bus_entry *bus;
  4682. struct ipr_bus_attributes *bus_attr;
  4683. struct ipr_mode_page28 *mode_page;
  4684. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  4685. sizeof(struct ipr_mode_page28));
  4686. entry_length = mode_page->entry_length;
  4687. /* Loop for each device bus entry */
  4688. for (i = 0, bus = mode_page->bus;
  4689. i < mode_page->num_entries;
  4690. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  4691. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  4692. dev_err(&ioa_cfg->pdev->dev,
  4693. "Invalid resource address reported: 0x%08X\n",
  4694. IPR_GET_PHYS_LOC(bus->res_addr));
  4695. continue;
  4696. }
  4697. bus_attr = &ioa_cfg->bus_attr[i];
  4698. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  4699. bus->bus_width = bus_attr->bus_width;
  4700. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  4701. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  4702. if (bus_attr->qas_enabled)
  4703. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  4704. else
  4705. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  4706. }
  4707. }
  4708. /**
  4709. * ipr_build_mode_select - Build a mode select command
  4710. * @ipr_cmd: ipr command struct
  4711. * @res_handle: resource handle to send command to
  4712. * @parm: Byte 2 of Mode Sense command
  4713. * @dma_addr: DMA buffer address
  4714. * @xfer_len: data transfer length
  4715. *
  4716. * Return value:
  4717. * none
  4718. **/
  4719. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  4720. __be32 res_handle, u8 parm, u32 dma_addr,
  4721. u8 xfer_len)
  4722. {
  4723. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4724. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4725. ioarcb->res_handle = res_handle;
  4726. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4727. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4728. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  4729. ioarcb->cmd_pkt.cdb[1] = parm;
  4730. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  4731. ioadl->flags_and_data_len =
  4732. cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
  4733. ioadl->address = cpu_to_be32(dma_addr);
  4734. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4735. ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
  4736. }
  4737. /**
  4738. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  4739. * @ipr_cmd: ipr command struct
  4740. *
  4741. * This function sets up the SCSI bus attributes and sends
  4742. * a Mode Select for Page 28 to activate them.
  4743. *
  4744. * Return value:
  4745. * IPR_RC_JOB_RETURN
  4746. **/
  4747. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  4748. {
  4749. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4750. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  4751. int length;
  4752. ENTER;
  4753. ipr_scsi_bus_speed_limit(ioa_cfg);
  4754. ipr_check_term_power(ioa_cfg, mode_pages);
  4755. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  4756. length = mode_pages->hdr.length + 1;
  4757. mode_pages->hdr.length = 0;
  4758. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  4759. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  4760. length);
  4761. ipr_cmd->job_step = ipr_setup_write_cache;
  4762. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4763. LEAVE;
  4764. return IPR_RC_JOB_RETURN;
  4765. }
  4766. /**
  4767. * ipr_build_mode_sense - Builds a mode sense command
  4768. * @ipr_cmd: ipr command struct
  4769. * @res: resource entry struct
  4770. * @parm: Byte 2 of mode sense command
  4771. * @dma_addr: DMA address of mode sense buffer
  4772. * @xfer_len: Size of DMA buffer
  4773. *
  4774. * Return value:
  4775. * none
  4776. **/
  4777. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  4778. __be32 res_handle,
  4779. u8 parm, u32 dma_addr, u8 xfer_len)
  4780. {
  4781. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4782. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4783. ioarcb->res_handle = res_handle;
  4784. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  4785. ioarcb->cmd_pkt.cdb[2] = parm;
  4786. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  4787. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4788. ioadl->flags_and_data_len =
  4789. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  4790. ioadl->address = cpu_to_be32(dma_addr);
  4791. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4792. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  4793. }
  4794. /**
  4795. * ipr_reset_cmd_failed - Handle failure of IOA reset command
  4796. * @ipr_cmd: ipr command struct
  4797. *
  4798. * This function handles the failure of an IOA bringup command.
  4799. *
  4800. * Return value:
  4801. * IPR_RC_JOB_RETURN
  4802. **/
  4803. static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
  4804. {
  4805. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4806. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4807. dev_err(&ioa_cfg->pdev->dev,
  4808. "0x%02X failed with IOASC: 0x%08X\n",
  4809. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  4810. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  4811. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4812. return IPR_RC_JOB_RETURN;
  4813. }
  4814. /**
  4815. * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
  4816. * @ipr_cmd: ipr command struct
  4817. *
  4818. * This function handles the failure of a Mode Sense to the IOAFP.
  4819. * Some adapters do not handle all mode pages.
  4820. *
  4821. * Return value:
  4822. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4823. **/
  4824. static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
  4825. {
  4826. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4827. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  4828. ipr_cmd->job_step = ipr_setup_write_cache;
  4829. return IPR_RC_JOB_CONTINUE;
  4830. }
  4831. return ipr_reset_cmd_failed(ipr_cmd);
  4832. }
  4833. /**
  4834. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  4835. * @ipr_cmd: ipr command struct
  4836. *
  4837. * This function send a Page 28 mode sense to the IOA to
  4838. * retrieve SCSI bus attributes.
  4839. *
  4840. * Return value:
  4841. * IPR_RC_JOB_RETURN
  4842. **/
  4843. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  4844. {
  4845. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4846. ENTER;
  4847. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  4848. 0x28, ioa_cfg->vpd_cbs_dma +
  4849. offsetof(struct ipr_misc_cbs, mode_pages),
  4850. sizeof(struct ipr_mode_pages));
  4851. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  4852. ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
  4853. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4854. LEAVE;
  4855. return IPR_RC_JOB_RETURN;
  4856. }
  4857. /**
  4858. * ipr_init_res_table - Initialize the resource table
  4859. * @ipr_cmd: ipr command struct
  4860. *
  4861. * This function looks through the existing resource table, comparing
  4862. * it with the config table. This function will take care of old/new
  4863. * devices and schedule adding/removing them from the mid-layer
  4864. * as appropriate.
  4865. *
  4866. * Return value:
  4867. * IPR_RC_JOB_CONTINUE
  4868. **/
  4869. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  4870. {
  4871. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4872. struct ipr_resource_entry *res, *temp;
  4873. struct ipr_config_table_entry *cfgte;
  4874. int found, i;
  4875. LIST_HEAD(old_res);
  4876. ENTER;
  4877. if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
  4878. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  4879. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  4880. list_move_tail(&res->queue, &old_res);
  4881. for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
  4882. cfgte = &ioa_cfg->cfg_table->dev[i];
  4883. found = 0;
  4884. list_for_each_entry_safe(res, temp, &old_res, queue) {
  4885. if (!memcmp(&res->cfgte.res_addr,
  4886. &cfgte->res_addr, sizeof(cfgte->res_addr))) {
  4887. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  4888. found = 1;
  4889. break;
  4890. }
  4891. }
  4892. if (!found) {
  4893. if (list_empty(&ioa_cfg->free_res_q)) {
  4894. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  4895. break;
  4896. }
  4897. found = 1;
  4898. res = list_entry(ioa_cfg->free_res_q.next,
  4899. struct ipr_resource_entry, queue);
  4900. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  4901. ipr_init_res_entry(res);
  4902. res->add_to_ml = 1;
  4903. }
  4904. if (found)
  4905. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  4906. }
  4907. list_for_each_entry_safe(res, temp, &old_res, queue) {
  4908. if (res->sdev) {
  4909. res->del_from_ml = 1;
  4910. res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
  4911. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  4912. } else {
  4913. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  4914. }
  4915. }
  4916. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  4917. LEAVE;
  4918. return IPR_RC_JOB_CONTINUE;
  4919. }
  4920. /**
  4921. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  4922. * @ipr_cmd: ipr command struct
  4923. *
  4924. * This function sends a Query IOA Configuration command
  4925. * to the adapter to retrieve the IOA configuration table.
  4926. *
  4927. * Return value:
  4928. * IPR_RC_JOB_RETURN
  4929. **/
  4930. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  4931. {
  4932. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4933. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4934. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4935. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  4936. ENTER;
  4937. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  4938. ucode_vpd->major_release, ucode_vpd->card_type,
  4939. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  4940. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4941. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4942. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  4943. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
  4944. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
  4945. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4946. ioarcb->read_data_transfer_length =
  4947. cpu_to_be32(sizeof(struct ipr_config_table));
  4948. ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
  4949. ioadl->flags_and_data_len =
  4950. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
  4951. ipr_cmd->job_step = ipr_init_res_table;
  4952. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4953. LEAVE;
  4954. return IPR_RC_JOB_RETURN;
  4955. }
  4956. /**
  4957. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  4958. * @ipr_cmd: ipr command struct
  4959. *
  4960. * This utility function sends an inquiry to the adapter.
  4961. *
  4962. * Return value:
  4963. * none
  4964. **/
  4965. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  4966. u32 dma_addr, u8 xfer_len)
  4967. {
  4968. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4969. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4970. ENTER;
  4971. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4972. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4973. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  4974. ioarcb->cmd_pkt.cdb[1] = flags;
  4975. ioarcb->cmd_pkt.cdb[2] = page;
  4976. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  4977. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4978. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  4979. ioadl->address = cpu_to_be32(dma_addr);
  4980. ioadl->flags_and_data_len =
  4981. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  4982. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4983. LEAVE;
  4984. }
  4985. /**
  4986. * ipr_inquiry_page_supported - Is the given inquiry page supported
  4987. * @page0: inquiry page 0 buffer
  4988. * @page: page code.
  4989. *
  4990. * This function determines if the specified inquiry page is supported.
  4991. *
  4992. * Return value:
  4993. * 1 if page is supported / 0 if not
  4994. **/
  4995. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  4996. {
  4997. int i;
  4998. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  4999. if (page0->page[i] == page)
  5000. return 1;
  5001. return 0;
  5002. }
  5003. /**
  5004. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  5005. * @ipr_cmd: ipr command struct
  5006. *
  5007. * This function sends a Page 3 inquiry to the adapter
  5008. * to retrieve software VPD information.
  5009. *
  5010. * Return value:
  5011. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5012. **/
  5013. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  5014. {
  5015. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5016. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  5017. ENTER;
  5018. if (!ipr_inquiry_page_supported(page0, 1))
  5019. ioa_cfg->cache_state = CACHE_NONE;
  5020. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  5021. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  5022. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  5023. sizeof(struct ipr_inquiry_page3));
  5024. LEAVE;
  5025. return IPR_RC_JOB_RETURN;
  5026. }
  5027. /**
  5028. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  5029. * @ipr_cmd: ipr command struct
  5030. *
  5031. * This function sends a Page 0 inquiry to the adapter
  5032. * to retrieve supported inquiry pages.
  5033. *
  5034. * Return value:
  5035. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5036. **/
  5037. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  5038. {
  5039. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5040. char type[5];
  5041. ENTER;
  5042. /* Grab the type out of the VPD and store it away */
  5043. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  5044. type[4] = '\0';
  5045. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  5046. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  5047. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  5048. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  5049. sizeof(struct ipr_inquiry_page0));
  5050. LEAVE;
  5051. return IPR_RC_JOB_RETURN;
  5052. }
  5053. /**
  5054. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  5055. * @ipr_cmd: ipr command struct
  5056. *
  5057. * This function sends a standard inquiry to the adapter.
  5058. *
  5059. * Return value:
  5060. * IPR_RC_JOB_RETURN
  5061. **/
  5062. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  5063. {
  5064. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5065. ENTER;
  5066. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  5067. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  5068. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  5069. sizeof(struct ipr_ioa_vpd));
  5070. LEAVE;
  5071. return IPR_RC_JOB_RETURN;
  5072. }
  5073. /**
  5074. * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
  5075. * @ipr_cmd: ipr command struct
  5076. *
  5077. * This function send an Identify Host Request Response Queue
  5078. * command to establish the HRRQ with the adapter.
  5079. *
  5080. * Return value:
  5081. * IPR_RC_JOB_RETURN
  5082. **/
  5083. static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
  5084. {
  5085. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5086. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5087. ENTER;
  5088. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  5089. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  5090. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5091. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5092. ioarcb->cmd_pkt.cdb[2] =
  5093. ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
  5094. ioarcb->cmd_pkt.cdb[3] =
  5095. ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
  5096. ioarcb->cmd_pkt.cdb[4] =
  5097. ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
  5098. ioarcb->cmd_pkt.cdb[5] =
  5099. ((u32) ioa_cfg->host_rrq_dma) & 0xff;
  5100. ioarcb->cmd_pkt.cdb[7] =
  5101. ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
  5102. ioarcb->cmd_pkt.cdb[8] =
  5103. (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
  5104. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  5105. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5106. LEAVE;
  5107. return IPR_RC_JOB_RETURN;
  5108. }
  5109. /**
  5110. * ipr_reset_timer_done - Adapter reset timer function
  5111. * @ipr_cmd: ipr command struct
  5112. *
  5113. * Description: This function is used in adapter reset processing
  5114. * for timing events. If the reset_cmd pointer in the IOA
  5115. * config struct is not this adapter's we are doing nested
  5116. * resets and fail_all_ops will take care of freeing the
  5117. * command block.
  5118. *
  5119. * Return value:
  5120. * none
  5121. **/
  5122. static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
  5123. {
  5124. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5125. unsigned long lock_flags = 0;
  5126. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5127. if (ioa_cfg->reset_cmd == ipr_cmd) {
  5128. list_del(&ipr_cmd->queue);
  5129. ipr_cmd->done(ipr_cmd);
  5130. }
  5131. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5132. }
  5133. /**
  5134. * ipr_reset_start_timer - Start a timer for adapter reset job
  5135. * @ipr_cmd: ipr command struct
  5136. * @timeout: timeout value
  5137. *
  5138. * Description: This function is used in adapter reset processing
  5139. * for timing events. If the reset_cmd pointer in the IOA
  5140. * config struct is not this adapter's we are doing nested
  5141. * resets and fail_all_ops will take care of freeing the
  5142. * command block.
  5143. *
  5144. * Return value:
  5145. * none
  5146. **/
  5147. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  5148. unsigned long timeout)
  5149. {
  5150. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  5151. ipr_cmd->done = ipr_reset_ioa_job;
  5152. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  5153. ipr_cmd->timer.expires = jiffies + timeout;
  5154. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
  5155. add_timer(&ipr_cmd->timer);
  5156. }
  5157. /**
  5158. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  5159. * @ioa_cfg: ioa cfg struct
  5160. *
  5161. * Return value:
  5162. * nothing
  5163. **/
  5164. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  5165. {
  5166. memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
  5167. /* Initialize Host RRQ pointers */
  5168. ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
  5169. ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
  5170. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  5171. ioa_cfg->toggle_bit = 1;
  5172. /* Zero out config table */
  5173. memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
  5174. }
  5175. /**
  5176. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  5177. * @ipr_cmd: ipr command struct
  5178. *
  5179. * This function reinitializes some control blocks and
  5180. * enables destructive diagnostics on the adapter.
  5181. *
  5182. * Return value:
  5183. * IPR_RC_JOB_RETURN
  5184. **/
  5185. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  5186. {
  5187. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5188. volatile u32 int_reg;
  5189. ENTER;
  5190. ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
  5191. ipr_init_ioa_mem(ioa_cfg);
  5192. ioa_cfg->allow_interrupts = 1;
  5193. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  5194. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  5195. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  5196. ioa_cfg->regs.clr_interrupt_mask_reg);
  5197. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  5198. return IPR_RC_JOB_CONTINUE;
  5199. }
  5200. /* Enable destructive diagnostics on IOA */
  5201. writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
  5202. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
  5203. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  5204. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  5205. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  5206. ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
  5207. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  5208. ipr_cmd->done = ipr_reset_ioa_job;
  5209. add_timer(&ipr_cmd->timer);
  5210. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  5211. LEAVE;
  5212. return IPR_RC_JOB_RETURN;
  5213. }
  5214. /**
  5215. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  5216. * @ipr_cmd: ipr command struct
  5217. *
  5218. * This function is invoked when an adapter dump has run out
  5219. * of processing time.
  5220. *
  5221. * Return value:
  5222. * IPR_RC_JOB_CONTINUE
  5223. **/
  5224. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  5225. {
  5226. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5227. if (ioa_cfg->sdt_state == GET_DUMP)
  5228. ioa_cfg->sdt_state = ABORT_DUMP;
  5229. ipr_cmd->job_step = ipr_reset_alert;
  5230. return IPR_RC_JOB_CONTINUE;
  5231. }
  5232. /**
  5233. * ipr_unit_check_no_data - Log a unit check/no data error log
  5234. * @ioa_cfg: ioa config struct
  5235. *
  5236. * Logs an error indicating the adapter unit checked, but for some
  5237. * reason, we were unable to fetch the unit check buffer.
  5238. *
  5239. * Return value:
  5240. * nothing
  5241. **/
  5242. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  5243. {
  5244. ioa_cfg->errors_logged++;
  5245. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  5246. }
  5247. /**
  5248. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  5249. * @ioa_cfg: ioa config struct
  5250. *
  5251. * Fetches the unit check buffer from the adapter by clocking the data
  5252. * through the mailbox register.
  5253. *
  5254. * Return value:
  5255. * nothing
  5256. **/
  5257. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  5258. {
  5259. unsigned long mailbox;
  5260. struct ipr_hostrcb *hostrcb;
  5261. struct ipr_uc_sdt sdt;
  5262. int rc, length;
  5263. mailbox = readl(ioa_cfg->ioa_mailbox);
  5264. if (!ipr_sdt_is_fmt2(mailbox)) {
  5265. ipr_unit_check_no_data(ioa_cfg);
  5266. return;
  5267. }
  5268. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  5269. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  5270. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  5271. if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
  5272. !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
  5273. ipr_unit_check_no_data(ioa_cfg);
  5274. return;
  5275. }
  5276. /* Find length of the first sdt entry (UC buffer) */
  5277. length = (be32_to_cpu(sdt.entry[0].end_offset) -
  5278. be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
  5279. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  5280. struct ipr_hostrcb, queue);
  5281. list_del(&hostrcb->queue);
  5282. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  5283. rc = ipr_get_ldump_data_section(ioa_cfg,
  5284. be32_to_cpu(sdt.entry[0].bar_str_offset),
  5285. (__be32 *)&hostrcb->hcam,
  5286. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  5287. if (!rc)
  5288. ipr_handle_log_data(ioa_cfg, hostrcb);
  5289. else
  5290. ipr_unit_check_no_data(ioa_cfg);
  5291. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  5292. }
  5293. /**
  5294. * ipr_reset_restore_cfg_space - Restore PCI config space.
  5295. * @ipr_cmd: ipr command struct
  5296. *
  5297. * Description: This function restores the saved PCI config space of
  5298. * the adapter, fails all outstanding ops back to the callers, and
  5299. * fetches the dump/unit check if applicable to this reset.
  5300. *
  5301. * Return value:
  5302. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5303. **/
  5304. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  5305. {
  5306. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5307. int rc;
  5308. ENTER;
  5309. pci_unblock_user_cfg_access(ioa_cfg->pdev);
  5310. rc = pci_restore_state(ioa_cfg->pdev);
  5311. if (rc != PCIBIOS_SUCCESSFUL) {
  5312. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5313. return IPR_RC_JOB_CONTINUE;
  5314. }
  5315. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  5316. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5317. return IPR_RC_JOB_CONTINUE;
  5318. }
  5319. ipr_fail_all_ops(ioa_cfg);
  5320. if (ioa_cfg->ioa_unit_checked) {
  5321. ioa_cfg->ioa_unit_checked = 0;
  5322. ipr_get_unit_check_buffer(ioa_cfg);
  5323. ipr_cmd->job_step = ipr_reset_alert;
  5324. ipr_reset_start_timer(ipr_cmd, 0);
  5325. return IPR_RC_JOB_RETURN;
  5326. }
  5327. if (ioa_cfg->in_ioa_bringdown) {
  5328. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  5329. } else {
  5330. ipr_cmd->job_step = ipr_reset_enable_ioa;
  5331. if (GET_DUMP == ioa_cfg->sdt_state) {
  5332. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
  5333. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  5334. schedule_work(&ioa_cfg->work_q);
  5335. return IPR_RC_JOB_RETURN;
  5336. }
  5337. }
  5338. ENTER;
  5339. return IPR_RC_JOB_CONTINUE;
  5340. }
  5341. /**
  5342. * ipr_reset_start_bist - Run BIST on the adapter.
  5343. * @ipr_cmd: ipr command struct
  5344. *
  5345. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  5346. *
  5347. * Return value:
  5348. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5349. **/
  5350. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  5351. {
  5352. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5353. int rc;
  5354. ENTER;
  5355. pci_block_user_cfg_access(ioa_cfg->pdev);
  5356. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  5357. if (rc != PCIBIOS_SUCCESSFUL) {
  5358. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5359. rc = IPR_RC_JOB_CONTINUE;
  5360. } else {
  5361. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  5362. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  5363. rc = IPR_RC_JOB_RETURN;
  5364. }
  5365. LEAVE;
  5366. return rc;
  5367. }
  5368. /**
  5369. * ipr_reset_allowed - Query whether or not IOA can be reset
  5370. * @ioa_cfg: ioa config struct
  5371. *
  5372. * Return value:
  5373. * 0 if reset not allowed / non-zero if reset is allowed
  5374. **/
  5375. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  5376. {
  5377. volatile u32 temp_reg;
  5378. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  5379. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  5380. }
  5381. /**
  5382. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  5383. * @ipr_cmd: ipr command struct
  5384. *
  5385. * Description: This function waits for adapter permission to run BIST,
  5386. * then runs BIST. If the adapter does not give permission after a
  5387. * reasonable time, we will reset the adapter anyway. The impact of
  5388. * resetting the adapter without warning the adapter is the risk of
  5389. * losing the persistent error log on the adapter. If the adapter is
  5390. * reset while it is writing to the flash on the adapter, the flash
  5391. * segment will have bad ECC and be zeroed.
  5392. *
  5393. * Return value:
  5394. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5395. **/
  5396. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  5397. {
  5398. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5399. int rc = IPR_RC_JOB_RETURN;
  5400. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  5401. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  5402. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  5403. } else {
  5404. ipr_cmd->job_step = ipr_reset_start_bist;
  5405. rc = IPR_RC_JOB_CONTINUE;
  5406. }
  5407. return rc;
  5408. }
  5409. /**
  5410. * ipr_reset_alert_part2 - Alert the adapter of a pending reset
  5411. * @ipr_cmd: ipr command struct
  5412. *
  5413. * Description: This function alerts the adapter that it will be reset.
  5414. * If memory space is not currently enabled, proceed directly
  5415. * to running BIST on the adapter. The timer must always be started
  5416. * so we guarantee we do not run BIST from ipr_isr.
  5417. *
  5418. * Return value:
  5419. * IPR_RC_JOB_RETURN
  5420. **/
  5421. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  5422. {
  5423. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5424. u16 cmd_reg;
  5425. int rc;
  5426. ENTER;
  5427. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  5428. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  5429. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  5430. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
  5431. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  5432. } else {
  5433. ipr_cmd->job_step = ipr_reset_start_bist;
  5434. }
  5435. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  5436. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  5437. LEAVE;
  5438. return IPR_RC_JOB_RETURN;
  5439. }
  5440. /**
  5441. * ipr_reset_ucode_download_done - Microcode download completion
  5442. * @ipr_cmd: ipr command struct
  5443. *
  5444. * Description: This function unmaps the microcode download buffer.
  5445. *
  5446. * Return value:
  5447. * IPR_RC_JOB_CONTINUE
  5448. **/
  5449. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  5450. {
  5451. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5452. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  5453. pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
  5454. sglist->num_sg, DMA_TO_DEVICE);
  5455. ipr_cmd->job_step = ipr_reset_alert;
  5456. return IPR_RC_JOB_CONTINUE;
  5457. }
  5458. /**
  5459. * ipr_reset_ucode_download - Download microcode to the adapter
  5460. * @ipr_cmd: ipr command struct
  5461. *
  5462. * Description: This function checks to see if it there is microcode
  5463. * to download to the adapter. If there is, a download is performed.
  5464. *
  5465. * Return value:
  5466. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5467. **/
  5468. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  5469. {
  5470. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5471. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  5472. ENTER;
  5473. ipr_cmd->job_step = ipr_reset_alert;
  5474. if (!sglist)
  5475. return IPR_RC_JOB_CONTINUE;
  5476. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5477. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5478. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  5479. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  5480. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  5481. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  5482. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  5483. ipr_build_ucode_ioadl(ipr_cmd, sglist);
  5484. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  5485. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  5486. IPR_WRITE_BUFFER_TIMEOUT);
  5487. LEAVE;
  5488. return IPR_RC_JOB_RETURN;
  5489. }
  5490. /**
  5491. * ipr_reset_shutdown_ioa - Shutdown the adapter
  5492. * @ipr_cmd: ipr command struct
  5493. *
  5494. * Description: This function issues an adapter shutdown of the
  5495. * specified type to the specified adapter as part of the
  5496. * adapter reset job.
  5497. *
  5498. * Return value:
  5499. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5500. **/
  5501. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  5502. {
  5503. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5504. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  5505. unsigned long timeout;
  5506. int rc = IPR_RC_JOB_CONTINUE;
  5507. ENTER;
  5508. if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
  5509. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5510. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5511. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  5512. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  5513. if (shutdown_type == IPR_SHUTDOWN_ABBREV)
  5514. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  5515. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  5516. timeout = IPR_INTERNAL_TIMEOUT;
  5517. else
  5518. timeout = IPR_SHUTDOWN_TIMEOUT;
  5519. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  5520. rc = IPR_RC_JOB_RETURN;
  5521. ipr_cmd->job_step = ipr_reset_ucode_download;
  5522. } else
  5523. ipr_cmd->job_step = ipr_reset_alert;
  5524. LEAVE;
  5525. return rc;
  5526. }
  5527. /**
  5528. * ipr_reset_ioa_job - Adapter reset job
  5529. * @ipr_cmd: ipr command struct
  5530. *
  5531. * Description: This function is the job router for the adapter reset job.
  5532. *
  5533. * Return value:
  5534. * none
  5535. **/
  5536. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  5537. {
  5538. u32 rc, ioasc;
  5539. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5540. do {
  5541. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  5542. if (ioa_cfg->reset_cmd != ipr_cmd) {
  5543. /*
  5544. * We are doing nested adapter resets and this is
  5545. * not the current reset job.
  5546. */
  5547. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5548. return;
  5549. }
  5550. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  5551. rc = ipr_cmd->job_step_failed(ipr_cmd);
  5552. if (rc == IPR_RC_JOB_RETURN)
  5553. return;
  5554. }
  5555. ipr_reinit_ipr_cmnd(ipr_cmd);
  5556. ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
  5557. rc = ipr_cmd->job_step(ipr_cmd);
  5558. } while(rc == IPR_RC_JOB_CONTINUE);
  5559. }
  5560. /**
  5561. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  5562. * @ioa_cfg: ioa config struct
  5563. * @job_step: first job step of reset job
  5564. * @shutdown_type: shutdown type
  5565. *
  5566. * Description: This function will initiate the reset of the given adapter
  5567. * starting at the selected job step.
  5568. * If the caller needs to wait on the completion of the reset,
  5569. * the caller must sleep on the reset_wait_q.
  5570. *
  5571. * Return value:
  5572. * none
  5573. **/
  5574. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  5575. int (*job_step) (struct ipr_cmnd *),
  5576. enum ipr_shutdown_type shutdown_type)
  5577. {
  5578. struct ipr_cmnd *ipr_cmd;
  5579. ioa_cfg->in_reset_reload = 1;
  5580. ioa_cfg->allow_cmds = 0;
  5581. scsi_block_requests(ioa_cfg->host);
  5582. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  5583. ioa_cfg->reset_cmd = ipr_cmd;
  5584. ipr_cmd->job_step = job_step;
  5585. ipr_cmd->u.shutdown_type = shutdown_type;
  5586. ipr_reset_ioa_job(ipr_cmd);
  5587. }
  5588. /**
  5589. * ipr_initiate_ioa_reset - Initiate an adapter reset
  5590. * @ioa_cfg: ioa config struct
  5591. * @shutdown_type: shutdown type
  5592. *
  5593. * Description: This function will initiate the reset of the given adapter.
  5594. * If the caller needs to wait on the completion of the reset,
  5595. * the caller must sleep on the reset_wait_q.
  5596. *
  5597. * Return value:
  5598. * none
  5599. **/
  5600. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  5601. enum ipr_shutdown_type shutdown_type)
  5602. {
  5603. if (ioa_cfg->ioa_is_dead)
  5604. return;
  5605. if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
  5606. ioa_cfg->sdt_state = ABORT_DUMP;
  5607. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  5608. dev_err(&ioa_cfg->pdev->dev,
  5609. "IOA taken offline - error recovery failed\n");
  5610. ioa_cfg->reset_retries = 0;
  5611. ioa_cfg->ioa_is_dead = 1;
  5612. if (ioa_cfg->in_ioa_bringdown) {
  5613. ioa_cfg->reset_cmd = NULL;
  5614. ioa_cfg->in_reset_reload = 0;
  5615. ipr_fail_all_ops(ioa_cfg);
  5616. wake_up_all(&ioa_cfg->reset_wait_q);
  5617. spin_unlock_irq(ioa_cfg->host->host_lock);
  5618. scsi_unblock_requests(ioa_cfg->host);
  5619. spin_lock_irq(ioa_cfg->host->host_lock);
  5620. return;
  5621. } else {
  5622. ioa_cfg->in_ioa_bringdown = 1;
  5623. shutdown_type = IPR_SHUTDOWN_NONE;
  5624. }
  5625. }
  5626. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  5627. shutdown_type);
  5628. }
  5629. /**
  5630. * ipr_reset_freeze - Hold off all I/O activity
  5631. * @ipr_cmd: ipr command struct
  5632. *
  5633. * Description: If the PCI slot is frozen, hold off all I/O
  5634. * activity; then, as soon as the slot is available again,
  5635. * initiate an adapter reset.
  5636. */
  5637. static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
  5638. {
  5639. /* Disallow new interrupts, avoid loop */
  5640. ipr_cmd->ioa_cfg->allow_interrupts = 0;
  5641. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  5642. ipr_cmd->done = ipr_reset_ioa_job;
  5643. return IPR_RC_JOB_RETURN;
  5644. }
  5645. /**
  5646. * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
  5647. * @pdev: PCI device struct
  5648. *
  5649. * Description: This routine is called to tell us that the PCI bus
  5650. * is down. Can't do anything here, except put the device driver
  5651. * into a holding pattern, waiting for the PCI bus to come back.
  5652. */
  5653. static void ipr_pci_frozen(struct pci_dev *pdev)
  5654. {
  5655. unsigned long flags = 0;
  5656. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5657. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5658. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
  5659. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5660. }
  5661. /**
  5662. * ipr_pci_slot_reset - Called when PCI slot has been reset.
  5663. * @pdev: PCI device struct
  5664. *
  5665. * Description: This routine is called by the pci error recovery
  5666. * code after the PCI slot has been reset, just before we
  5667. * should resume normal operations.
  5668. */
  5669. static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
  5670. {
  5671. unsigned long flags = 0;
  5672. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5673. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5674. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
  5675. IPR_SHUTDOWN_NONE);
  5676. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5677. return PCI_ERS_RESULT_RECOVERED;
  5678. }
  5679. /**
  5680. * ipr_pci_perm_failure - Called when PCI slot is dead for good.
  5681. * @pdev: PCI device struct
  5682. *
  5683. * Description: This routine is called when the PCI bus has
  5684. * permanently failed.
  5685. */
  5686. static void ipr_pci_perm_failure(struct pci_dev *pdev)
  5687. {
  5688. unsigned long flags = 0;
  5689. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5690. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5691. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  5692. ioa_cfg->sdt_state = ABORT_DUMP;
  5693. ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
  5694. ioa_cfg->in_ioa_bringdown = 1;
  5695. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5696. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5697. }
  5698. /**
  5699. * ipr_pci_error_detected - Called when a PCI error is detected.
  5700. * @pdev: PCI device struct
  5701. * @state: PCI channel state
  5702. *
  5703. * Description: Called when a PCI error is detected.
  5704. *
  5705. * Return value:
  5706. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  5707. */
  5708. static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  5709. pci_channel_state_t state)
  5710. {
  5711. switch (state) {
  5712. case pci_channel_io_frozen:
  5713. ipr_pci_frozen(pdev);
  5714. return PCI_ERS_RESULT_NEED_RESET;
  5715. case pci_channel_io_perm_failure:
  5716. ipr_pci_perm_failure(pdev);
  5717. return PCI_ERS_RESULT_DISCONNECT;
  5718. break;
  5719. default:
  5720. break;
  5721. }
  5722. return PCI_ERS_RESULT_NEED_RESET;
  5723. }
  5724. /**
  5725. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  5726. * @ioa_cfg: ioa cfg struct
  5727. *
  5728. * Description: This is the second phase of adapter intialization
  5729. * This function takes care of initilizing the adapter to the point
  5730. * where it can accept new commands.
  5731. * Return value:
  5732. * 0 on sucess / -EIO on failure
  5733. **/
  5734. static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  5735. {
  5736. int rc = 0;
  5737. unsigned long host_lock_flags = 0;
  5738. ENTER;
  5739. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5740. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  5741. if (ioa_cfg->needs_hard_reset) {
  5742. ioa_cfg->needs_hard_reset = 0;
  5743. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5744. } else
  5745. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
  5746. IPR_SHUTDOWN_NONE);
  5747. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5748. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5749. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5750. if (ioa_cfg->ioa_is_dead) {
  5751. rc = -EIO;
  5752. } else if (ipr_invalid_adapter(ioa_cfg)) {
  5753. if (!ipr_testmode)
  5754. rc = -EIO;
  5755. dev_err(&ioa_cfg->pdev->dev,
  5756. "Adapter not supported in this hardware configuration.\n");
  5757. }
  5758. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5759. LEAVE;
  5760. return rc;
  5761. }
  5762. /**
  5763. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  5764. * @ioa_cfg: ioa config struct
  5765. *
  5766. * Return value:
  5767. * none
  5768. **/
  5769. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  5770. {
  5771. int i;
  5772. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  5773. if (ioa_cfg->ipr_cmnd_list[i])
  5774. pci_pool_free(ioa_cfg->ipr_cmd_pool,
  5775. ioa_cfg->ipr_cmnd_list[i],
  5776. ioa_cfg->ipr_cmnd_list_dma[i]);
  5777. ioa_cfg->ipr_cmnd_list[i] = NULL;
  5778. }
  5779. if (ioa_cfg->ipr_cmd_pool)
  5780. pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
  5781. ioa_cfg->ipr_cmd_pool = NULL;
  5782. }
  5783. /**
  5784. * ipr_free_mem - Frees memory allocated for an adapter
  5785. * @ioa_cfg: ioa cfg struct
  5786. *
  5787. * Return value:
  5788. * nothing
  5789. **/
  5790. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  5791. {
  5792. int i;
  5793. kfree(ioa_cfg->res_entries);
  5794. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
  5795. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  5796. ipr_free_cmd_blks(ioa_cfg);
  5797. pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  5798. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  5799. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
  5800. ioa_cfg->cfg_table,
  5801. ioa_cfg->cfg_table_dma);
  5802. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  5803. pci_free_consistent(ioa_cfg->pdev,
  5804. sizeof(struct ipr_hostrcb),
  5805. ioa_cfg->hostrcb[i],
  5806. ioa_cfg->hostrcb_dma[i]);
  5807. }
  5808. ipr_free_dump(ioa_cfg);
  5809. kfree(ioa_cfg->trace);
  5810. }
  5811. /**
  5812. * ipr_free_all_resources - Free all allocated resources for an adapter.
  5813. * @ipr_cmd: ipr command struct
  5814. *
  5815. * This function frees all allocated resources for the
  5816. * specified adapter.
  5817. *
  5818. * Return value:
  5819. * none
  5820. **/
  5821. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  5822. {
  5823. struct pci_dev *pdev = ioa_cfg->pdev;
  5824. ENTER;
  5825. free_irq(pdev->irq, ioa_cfg);
  5826. iounmap(ioa_cfg->hdw_dma_regs);
  5827. pci_release_regions(pdev);
  5828. ipr_free_mem(ioa_cfg);
  5829. scsi_host_put(ioa_cfg->host);
  5830. pci_disable_device(pdev);
  5831. LEAVE;
  5832. }
  5833. /**
  5834. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  5835. * @ioa_cfg: ioa config struct
  5836. *
  5837. * Return value:
  5838. * 0 on success / -ENOMEM on allocation failure
  5839. **/
  5840. static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  5841. {
  5842. struct ipr_cmnd *ipr_cmd;
  5843. struct ipr_ioarcb *ioarcb;
  5844. dma_addr_t dma_addr;
  5845. int i;
  5846. ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
  5847. sizeof(struct ipr_cmnd), 8, 0);
  5848. if (!ioa_cfg->ipr_cmd_pool)
  5849. return -ENOMEM;
  5850. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  5851. ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
  5852. if (!ipr_cmd) {
  5853. ipr_free_cmd_blks(ioa_cfg);
  5854. return -ENOMEM;
  5855. }
  5856. memset(ipr_cmd, 0, sizeof(*ipr_cmd));
  5857. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  5858. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  5859. ioarcb = &ipr_cmd->ioarcb;
  5860. ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  5861. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  5862. ioarcb->write_ioadl_addr =
  5863. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  5864. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  5865. ioarcb->ioasa_host_pci_addr =
  5866. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
  5867. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  5868. ipr_cmd->cmd_index = i;
  5869. ipr_cmd->ioa_cfg = ioa_cfg;
  5870. ipr_cmd->sense_buffer_dma = dma_addr +
  5871. offsetof(struct ipr_cmnd, sense_buffer);
  5872. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5873. }
  5874. return 0;
  5875. }
  5876. /**
  5877. * ipr_alloc_mem - Allocate memory for an adapter
  5878. * @ioa_cfg: ioa config struct
  5879. *
  5880. * Return value:
  5881. * 0 on success / non-zero for error
  5882. **/
  5883. static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  5884. {
  5885. struct pci_dev *pdev = ioa_cfg->pdev;
  5886. int i, rc = -ENOMEM;
  5887. ENTER;
  5888. ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
  5889. IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
  5890. if (!ioa_cfg->res_entries)
  5891. goto out;
  5892. for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
  5893. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  5894. ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
  5895. sizeof(struct ipr_misc_cbs),
  5896. &ioa_cfg->vpd_cbs_dma);
  5897. if (!ioa_cfg->vpd_cbs)
  5898. goto out_free_res_entries;
  5899. if (ipr_alloc_cmd_blks(ioa_cfg))
  5900. goto out_free_vpd_cbs;
  5901. ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
  5902. sizeof(u32) * IPR_NUM_CMD_BLKS,
  5903. &ioa_cfg->host_rrq_dma);
  5904. if (!ioa_cfg->host_rrq)
  5905. goto out_ipr_free_cmd_blocks;
  5906. ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
  5907. sizeof(struct ipr_config_table),
  5908. &ioa_cfg->cfg_table_dma);
  5909. if (!ioa_cfg->cfg_table)
  5910. goto out_free_host_rrq;
  5911. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  5912. ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
  5913. sizeof(struct ipr_hostrcb),
  5914. &ioa_cfg->hostrcb_dma[i]);
  5915. if (!ioa_cfg->hostrcb[i])
  5916. goto out_free_hostrcb_dma;
  5917. ioa_cfg->hostrcb[i]->hostrcb_dma =
  5918. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  5919. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  5920. }
  5921. ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
  5922. IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
  5923. if (!ioa_cfg->trace)
  5924. goto out_free_hostrcb_dma;
  5925. rc = 0;
  5926. out:
  5927. LEAVE;
  5928. return rc;
  5929. out_free_hostrcb_dma:
  5930. while (i-- > 0) {
  5931. pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
  5932. ioa_cfg->hostrcb[i],
  5933. ioa_cfg->hostrcb_dma[i]);
  5934. }
  5935. pci_free_consistent(pdev, sizeof(struct ipr_config_table),
  5936. ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
  5937. out_free_host_rrq:
  5938. pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  5939. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  5940. out_ipr_free_cmd_blocks:
  5941. ipr_free_cmd_blks(ioa_cfg);
  5942. out_free_vpd_cbs:
  5943. pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
  5944. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  5945. out_free_res_entries:
  5946. kfree(ioa_cfg->res_entries);
  5947. goto out;
  5948. }
  5949. /**
  5950. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  5951. * @ioa_cfg: ioa config struct
  5952. *
  5953. * Return value:
  5954. * none
  5955. **/
  5956. static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  5957. {
  5958. int i;
  5959. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  5960. ioa_cfg->bus_attr[i].bus = i;
  5961. ioa_cfg->bus_attr[i].qas_enabled = 0;
  5962. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  5963. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  5964. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  5965. else
  5966. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  5967. }
  5968. }
  5969. /**
  5970. * ipr_init_ioa_cfg - Initialize IOA config struct
  5971. * @ioa_cfg: ioa config struct
  5972. * @host: scsi host struct
  5973. * @pdev: PCI dev struct
  5974. *
  5975. * Return value:
  5976. * none
  5977. **/
  5978. static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  5979. struct Scsi_Host *host, struct pci_dev *pdev)
  5980. {
  5981. const struct ipr_interrupt_offsets *p;
  5982. struct ipr_interrupts *t;
  5983. void __iomem *base;
  5984. ioa_cfg->host = host;
  5985. ioa_cfg->pdev = pdev;
  5986. ioa_cfg->log_level = ipr_log_level;
  5987. ioa_cfg->doorbell = IPR_DOORBELL;
  5988. if (!ipr_auto_create)
  5989. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  5990. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  5991. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  5992. sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
  5993. sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
  5994. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  5995. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  5996. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  5997. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  5998. INIT_LIST_HEAD(&ioa_cfg->free_q);
  5999. INIT_LIST_HEAD(&ioa_cfg->pending_q);
  6000. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  6001. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  6002. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  6003. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  6004. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
  6005. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  6006. ioa_cfg->sdt_state = INACTIVE;
  6007. if (ipr_enable_cache)
  6008. ioa_cfg->cache_state = CACHE_ENABLED;
  6009. else
  6010. ioa_cfg->cache_state = CACHE_DISABLED;
  6011. ipr_initialize_bus_attr(ioa_cfg);
  6012. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  6013. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  6014. host->max_channel = IPR_MAX_BUS_TO_SCAN;
  6015. host->unique_id = host->host_no;
  6016. host->max_cmd_len = IPR_MAX_CDB_LEN;
  6017. pci_set_drvdata(pdev, ioa_cfg);
  6018. p = &ioa_cfg->chip_cfg->regs;
  6019. t = &ioa_cfg->regs;
  6020. base = ioa_cfg->hdw_dma_regs;
  6021. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  6022. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  6023. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  6024. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  6025. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  6026. t->ioarrin_reg = base + p->ioarrin_reg;
  6027. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  6028. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  6029. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  6030. }
  6031. /**
  6032. * ipr_get_chip_cfg - Find adapter chip configuration
  6033. * @dev_id: PCI device id struct
  6034. *
  6035. * Return value:
  6036. * ptr to chip config on success / NULL on failure
  6037. **/
  6038. static const struct ipr_chip_cfg_t * __devinit
  6039. ipr_get_chip_cfg(const struct pci_device_id *dev_id)
  6040. {
  6041. int i;
  6042. if (dev_id->driver_data)
  6043. return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
  6044. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  6045. if (ipr_chip[i].vendor == dev_id->vendor &&
  6046. ipr_chip[i].device == dev_id->device)
  6047. return ipr_chip[i].cfg;
  6048. return NULL;
  6049. }
  6050. /**
  6051. * ipr_probe_ioa - Allocates memory and does first stage of initialization
  6052. * @pdev: PCI device struct
  6053. * @dev_id: PCI device id struct
  6054. *
  6055. * Return value:
  6056. * 0 on success / non-zero on failure
  6057. **/
  6058. static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
  6059. const struct pci_device_id *dev_id)
  6060. {
  6061. struct ipr_ioa_cfg *ioa_cfg;
  6062. struct Scsi_Host *host;
  6063. unsigned long ipr_regs_pci;
  6064. void __iomem *ipr_regs;
  6065. int rc = PCIBIOS_SUCCESSFUL;
  6066. volatile u32 mask, uproc;
  6067. ENTER;
  6068. if ((rc = pci_enable_device(pdev))) {
  6069. dev_err(&pdev->dev, "Cannot enable adapter\n");
  6070. goto out;
  6071. }
  6072. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  6073. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  6074. if (!host) {
  6075. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  6076. rc = -ENOMEM;
  6077. goto out_disable;
  6078. }
  6079. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  6080. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  6081. ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
  6082. sata_port_info.flags, &ipr_sata_ops);
  6083. ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
  6084. if (!ioa_cfg->chip_cfg) {
  6085. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  6086. dev_id->vendor, dev_id->device);
  6087. goto out_scsi_host_put;
  6088. }
  6089. ipr_regs_pci = pci_resource_start(pdev, 0);
  6090. rc = pci_request_regions(pdev, IPR_NAME);
  6091. if (rc < 0) {
  6092. dev_err(&pdev->dev,
  6093. "Couldn't register memory range of registers\n");
  6094. goto out_scsi_host_put;
  6095. }
  6096. ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
  6097. if (!ipr_regs) {
  6098. dev_err(&pdev->dev,
  6099. "Couldn't map memory range of registers\n");
  6100. rc = -ENOMEM;
  6101. goto out_release_regions;
  6102. }
  6103. ioa_cfg->hdw_dma_regs = ipr_regs;
  6104. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  6105. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  6106. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  6107. pci_set_master(pdev);
  6108. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  6109. if (rc < 0) {
  6110. dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
  6111. goto cleanup_nomem;
  6112. }
  6113. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  6114. ioa_cfg->chip_cfg->cache_line_size);
  6115. if (rc != PCIBIOS_SUCCESSFUL) {
  6116. dev_err(&pdev->dev, "Write of cache line size failed\n");
  6117. rc = -EIO;
  6118. goto cleanup_nomem;
  6119. }
  6120. /* Save away PCI config space for use following IOA reset */
  6121. rc = pci_save_state(pdev);
  6122. if (rc != PCIBIOS_SUCCESSFUL) {
  6123. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  6124. rc = -EIO;
  6125. goto cleanup_nomem;
  6126. }
  6127. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  6128. goto cleanup_nomem;
  6129. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  6130. goto cleanup_nomem;
  6131. rc = ipr_alloc_mem(ioa_cfg);
  6132. if (rc < 0) {
  6133. dev_err(&pdev->dev,
  6134. "Couldn't allocate enough memory for device driver!\n");
  6135. goto cleanup_nomem;
  6136. }
  6137. /*
  6138. * If HRRQ updated interrupt is not masked, or reset alert is set,
  6139. * the card is in an unknown state and needs a hard reset
  6140. */
  6141. mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6142. uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  6143. if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
  6144. ioa_cfg->needs_hard_reset = 1;
  6145. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  6146. rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
  6147. if (rc) {
  6148. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  6149. pdev->irq, rc);
  6150. goto cleanup_nolog;
  6151. }
  6152. spin_lock(&ipr_driver_lock);
  6153. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  6154. spin_unlock(&ipr_driver_lock);
  6155. LEAVE;
  6156. out:
  6157. return rc;
  6158. cleanup_nolog:
  6159. ipr_free_mem(ioa_cfg);
  6160. cleanup_nomem:
  6161. iounmap(ipr_regs);
  6162. out_release_regions:
  6163. pci_release_regions(pdev);
  6164. out_scsi_host_put:
  6165. scsi_host_put(host);
  6166. out_disable:
  6167. pci_disable_device(pdev);
  6168. goto out;
  6169. }
  6170. /**
  6171. * ipr_scan_vsets - Scans for VSET devices
  6172. * @ioa_cfg: ioa config struct
  6173. *
  6174. * Description: Since the VSET resources do not follow SAM in that we can have
  6175. * sparse LUNs with no LUN 0, we have to scan for these ourselves.
  6176. *
  6177. * Return value:
  6178. * none
  6179. **/
  6180. static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
  6181. {
  6182. int target, lun;
  6183. for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
  6184. for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
  6185. scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
  6186. }
  6187. /**
  6188. * ipr_initiate_ioa_bringdown - Bring down an adapter
  6189. * @ioa_cfg: ioa config struct
  6190. * @shutdown_type: shutdown type
  6191. *
  6192. * Description: This function will initiate bringing down the adapter.
  6193. * This consists of issuing an IOA shutdown to the adapter
  6194. * to flush the cache, and running BIST.
  6195. * If the caller needs to wait on the completion of the reset,
  6196. * the caller must sleep on the reset_wait_q.
  6197. *
  6198. * Return value:
  6199. * none
  6200. **/
  6201. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  6202. enum ipr_shutdown_type shutdown_type)
  6203. {
  6204. ENTER;
  6205. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  6206. ioa_cfg->sdt_state = ABORT_DUMP;
  6207. ioa_cfg->reset_retries = 0;
  6208. ioa_cfg->in_ioa_bringdown = 1;
  6209. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  6210. LEAVE;
  6211. }
  6212. /**
  6213. * __ipr_remove - Remove a single adapter
  6214. * @pdev: pci device struct
  6215. *
  6216. * Adapter hot plug remove entry point.
  6217. *
  6218. * Return value:
  6219. * none
  6220. **/
  6221. static void __ipr_remove(struct pci_dev *pdev)
  6222. {
  6223. unsigned long host_lock_flags = 0;
  6224. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6225. ENTER;
  6226. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6227. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  6228. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6229. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6230. flush_scheduled_work();
  6231. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6232. spin_lock(&ipr_driver_lock);
  6233. list_del(&ioa_cfg->queue);
  6234. spin_unlock(&ipr_driver_lock);
  6235. if (ioa_cfg->sdt_state == ABORT_DUMP)
  6236. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  6237. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6238. ipr_free_all_resources(ioa_cfg);
  6239. LEAVE;
  6240. }
  6241. /**
  6242. * ipr_remove - IOA hot plug remove entry point
  6243. * @pdev: pci device struct
  6244. *
  6245. * Adapter hot plug remove entry point.
  6246. *
  6247. * Return value:
  6248. * none
  6249. **/
  6250. static void ipr_remove(struct pci_dev *pdev)
  6251. {
  6252. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6253. ENTER;
  6254. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  6255. &ipr_trace_attr);
  6256. ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  6257. &ipr_dump_attr);
  6258. scsi_remove_host(ioa_cfg->host);
  6259. __ipr_remove(pdev);
  6260. LEAVE;
  6261. }
  6262. /**
  6263. * ipr_probe - Adapter hot plug add entry point
  6264. *
  6265. * Return value:
  6266. * 0 on success / non-zero on failure
  6267. **/
  6268. static int __devinit ipr_probe(struct pci_dev *pdev,
  6269. const struct pci_device_id *dev_id)
  6270. {
  6271. struct ipr_ioa_cfg *ioa_cfg;
  6272. int rc;
  6273. rc = ipr_probe_ioa(pdev, dev_id);
  6274. if (rc)
  6275. return rc;
  6276. ioa_cfg = pci_get_drvdata(pdev);
  6277. rc = ipr_probe_ioa_part2(ioa_cfg);
  6278. if (rc) {
  6279. __ipr_remove(pdev);
  6280. return rc;
  6281. }
  6282. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  6283. if (rc) {
  6284. __ipr_remove(pdev);
  6285. return rc;
  6286. }
  6287. rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  6288. &ipr_trace_attr);
  6289. if (rc) {
  6290. scsi_remove_host(ioa_cfg->host);
  6291. __ipr_remove(pdev);
  6292. return rc;
  6293. }
  6294. rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  6295. &ipr_dump_attr);
  6296. if (rc) {
  6297. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  6298. &ipr_trace_attr);
  6299. scsi_remove_host(ioa_cfg->host);
  6300. __ipr_remove(pdev);
  6301. return rc;
  6302. }
  6303. scsi_scan_host(ioa_cfg->host);
  6304. ipr_scan_vsets(ioa_cfg);
  6305. scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
  6306. ioa_cfg->allow_ml_add_del = 1;
  6307. ioa_cfg->host->max_channel = IPR_VSET_BUS;
  6308. schedule_work(&ioa_cfg->work_q);
  6309. return 0;
  6310. }
  6311. /**
  6312. * ipr_shutdown - Shutdown handler.
  6313. * @pdev: pci device struct
  6314. *
  6315. * This function is invoked upon system shutdown/reboot. It will issue
  6316. * an adapter shutdown to the adapter to flush the write cache.
  6317. *
  6318. * Return value:
  6319. * none
  6320. **/
  6321. static void ipr_shutdown(struct pci_dev *pdev)
  6322. {
  6323. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6324. unsigned long lock_flags = 0;
  6325. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  6326. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  6327. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  6328. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6329. }
  6330. static struct pci_device_id ipr_pci_table[] __devinitdata = {
  6331. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6332. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
  6333. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6334. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6335. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
  6336. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6337. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6338. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
  6339. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6340. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6341. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
  6342. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6343. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6344. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
  6345. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6346. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6347. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
  6348. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6349. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6350. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
  6351. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6352. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6353. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B,
  6354. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6355. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6356. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A,
  6357. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6358. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6359. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B,
  6360. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6361. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6362. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C,
  6363. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6364. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6365. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A,
  6366. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6367. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6368. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B,
  6369. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6370. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6371. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C,
  6372. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6373. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6374. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B8,
  6375. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6376. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  6377. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7,
  6378. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  6379. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  6380. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
  6381. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  6382. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6383. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
  6384. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  6385. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6386. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F,
  6387. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  6388. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6389. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F,
  6390. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  6391. { }
  6392. };
  6393. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  6394. static struct pci_error_handlers ipr_err_handler = {
  6395. .error_detected = ipr_pci_error_detected,
  6396. .slot_reset = ipr_pci_slot_reset,
  6397. };
  6398. static struct pci_driver ipr_driver = {
  6399. .name = IPR_NAME,
  6400. .id_table = ipr_pci_table,
  6401. .probe = ipr_probe,
  6402. .remove = ipr_remove,
  6403. .shutdown = ipr_shutdown,
  6404. .err_handler = &ipr_err_handler,
  6405. };
  6406. /**
  6407. * ipr_init - Module entry point
  6408. *
  6409. * Return value:
  6410. * 0 on success / negative value on failure
  6411. **/
  6412. static int __init ipr_init(void)
  6413. {
  6414. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  6415. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  6416. return pci_register_driver(&ipr_driver);
  6417. }
  6418. /**
  6419. * ipr_exit - Module unload
  6420. *
  6421. * Module unload entry point.
  6422. *
  6423. * Return value:
  6424. * none
  6425. **/
  6426. static void __exit ipr_exit(void)
  6427. {
  6428. pci_unregister_driver(&ipr_driver);
  6429. }
  6430. module_init(ipr_init);
  6431. module_exit(ipr_exit);