ipr.c 301 KB

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