ipr.c 182 KB

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