ipr.c 226 KB

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