ipr.c 249 KB

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