ipr.c 254 KB

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