ipr.c 241 KB

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