ipr.c 259 KB

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