ipr.c 252 KB

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