ipr.c 287 KB

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