ipr.c 226 KB

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