ipr.c 180 KB

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