ipr.c 301 KB

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