mptbase.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854
  1. /*
  2. * linux/drivers/message/fusion/mptbase.c
  3. * This is the Fusion MPT base driver which supports multiple
  4. * (SCSI + LAN) specialized protocol drivers.
  5. * For use with LSI Logic PCI chip/adapter(s)
  6. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  7. *
  8. * Copyright (c) 1999-2005 LSI Logic Corporation
  9. * (mailto:mpt_linux_developer@lsil.com)
  10. *
  11. */
  12. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  13. /*
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; version 2 of the License.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. NO WARRANTY
  22. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  23. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  24. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  25. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  26. solely responsible for determining the appropriateness of using and
  27. distributing the Program and assumes all risks associated with its
  28. exercise of rights under this Agreement, including but not limited to
  29. the risks and costs of program errors, damage to or loss of data,
  30. programs or equipment, and unavailability or interruption of operations.
  31. DISCLAIMER OF LIABILITY
  32. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  33. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  36. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  37. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  38. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  39. You should have received a copy of the GNU General Public License
  40. along with this program; if not, write to the Free Software
  41. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  42. */
  43. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  44. #include <linux/config.h>
  45. #include <linux/version.h>
  46. #include <linux/kernel.h>
  47. #include <linux/module.h>
  48. #include <linux/errno.h>
  49. #include <linux/init.h>
  50. #include <linux/slab.h>
  51. #include <linux/types.h>
  52. #include <linux/pci.h>
  53. #include <linux/kdev_t.h>
  54. #include <linux/blkdev.h>
  55. #include <linux/delay.h>
  56. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  57. #include <linux/dma-mapping.h>
  58. #include <asm/io.h>
  59. #ifdef CONFIG_MTRR
  60. #include <asm/mtrr.h>
  61. #endif
  62. #ifdef __sparc__
  63. #include <asm/irq.h> /* needed for __irq_itoa() proto */
  64. #endif
  65. #include "mptbase.h"
  66. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  67. #define my_NAME "Fusion MPT base driver"
  68. #define my_VERSION MPT_LINUX_VERSION_COMMON
  69. #define MYNAM "mptbase"
  70. MODULE_AUTHOR(MODULEAUTHOR);
  71. MODULE_DESCRIPTION(my_NAME);
  72. MODULE_LICENSE("GPL");
  73. /*
  74. * cmd line parameters
  75. */
  76. #ifdef MFCNT
  77. static int mfcounter = 0;
  78. #define PRINT_MF_COUNT 20000
  79. #endif
  80. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  81. /*
  82. * Public data...
  83. */
  84. int mpt_lan_index = -1;
  85. int mpt_stm_index = -1;
  86. struct proc_dir_entry *mpt_proc_root_dir;
  87. #define WHOINIT_UNKNOWN 0xAA
  88. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  89. /*
  90. * Private data...
  91. */
  92. /* Adapter link list */
  93. LIST_HEAD(ioc_list);
  94. /* Callback lookup table */
  95. static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
  96. /* Protocol driver class lookup table */
  97. static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
  98. /* Event handler lookup table */
  99. static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  100. /* Reset handler lookup table */
  101. static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  102. static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  103. static int mpt_base_index = -1;
  104. static int last_drv_idx = -1;
  105. static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
  106. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  107. /*
  108. * Forward protos...
  109. */
  110. static irqreturn_t mpt_interrupt(int irq, void *bus_id, struct pt_regs *r);
  111. static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
  112. static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
  113. u32 *req, int replyBytes, u16 *u16reply, int maxwait,
  114. int sleepFlag);
  115. static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
  116. static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
  117. static void mpt_adapter_disable(MPT_ADAPTER *ioc);
  118. static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
  119. static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
  120. static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
  121. //static u32 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
  122. static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
  123. static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  124. static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
  125. static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  126. static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
  127. static int mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag);
  128. static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  129. static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  130. static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
  131. static int PrimeIocFifos(MPT_ADAPTER *ioc);
  132. static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  133. static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  134. static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  135. static int GetLanConfigPages(MPT_ADAPTER *ioc);
  136. static int GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
  137. static int GetIoUnitPage2(MPT_ADAPTER *ioc);
  138. static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
  139. static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
  140. static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
  141. static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
  142. static void mpt_timer_expired(unsigned long data);
  143. static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
  144. static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
  145. #ifdef CONFIG_PROC_FS
  146. static int procmpt_summary_read(char *buf, char **start, off_t offset,
  147. int request, int *eof, void *data);
  148. static int procmpt_version_read(char *buf, char **start, off_t offset,
  149. int request, int *eof, void *data);
  150. static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
  151. int request, int *eof, void *data);
  152. #endif
  153. static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
  154. //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
  155. static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
  156. static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
  157. static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
  158. static void mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info);
  159. /* module entry point */
  160. static int __init fusion_init (void);
  161. static void __exit fusion_exit (void);
  162. #define CHIPREG_READ32(addr) readl_relaxed(addr)
  163. #define CHIPREG_READ32_dmasync(addr) readl(addr)
  164. #define CHIPREG_WRITE32(addr,val) writel(val, addr)
  165. #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
  166. #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
  167. static void
  168. pci_disable_io_access(struct pci_dev *pdev)
  169. {
  170. u16 command_reg;
  171. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  172. command_reg &= ~1;
  173. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  174. }
  175. static void
  176. pci_enable_io_access(struct pci_dev *pdev)
  177. {
  178. u16 command_reg;
  179. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  180. command_reg |= 1;
  181. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  182. }
  183. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  184. /*
  185. * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
  186. * @irq: irq number (not used)
  187. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  188. * @r: pt_regs pointer (not used)
  189. *
  190. * This routine is registered via the request_irq() kernel API call,
  191. * and handles all interrupts generated from a specific MPT adapter
  192. * (also referred to as a IO Controller or IOC).
  193. * This routine must clear the interrupt from the adapter and does
  194. * so by reading the reply FIFO. Multiple replies may be processed
  195. * per single call to this routine; up to MPT_MAX_REPLIES_PER_ISR
  196. * which is currently set to 32 in mptbase.h.
  197. *
  198. * This routine handles register-level access of the adapter but
  199. * dispatches (calls) a protocol-specific callback routine to handle
  200. * the protocol-specific details of the MPT request completion.
  201. */
  202. static irqreturn_t
  203. mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
  204. {
  205. MPT_ADAPTER *ioc;
  206. MPT_FRAME_HDR *mf;
  207. MPT_FRAME_HDR *mr;
  208. u32 pa;
  209. int req_idx;
  210. int cb_idx;
  211. int type;
  212. int freeme;
  213. ioc = (MPT_ADAPTER *)bus_id;
  214. /*
  215. * Drain the reply FIFO!
  216. *
  217. * NOTES: I've seen up to 10 replies processed in this loop, so far...
  218. * Update: I've seen up to 9182 replies processed in this loop! ??
  219. * Update: Limit ourselves to processing max of N replies
  220. * (bottom of loop).
  221. */
  222. while (1) {
  223. if ((pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo)) == 0xFFFFFFFF)
  224. return IRQ_HANDLED;
  225. cb_idx = 0;
  226. freeme = 0;
  227. /*
  228. * Check for non-TURBO reply!
  229. */
  230. if (pa & MPI_ADDRESS_REPLY_A_BIT) {
  231. u32 reply_dma_low;
  232. u16 ioc_stat;
  233. /* non-TURBO reply! Hmmm, something may be up...
  234. * Newest turbo reply mechanism; get address
  235. * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
  236. */
  237. /* Map DMA address of reply header to cpu address.
  238. * pa is 32 bits - but the dma address may be 32 or 64 bits
  239. * get offset based only only the low addresses
  240. */
  241. reply_dma_low = (pa = (pa << 1));
  242. mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
  243. (reply_dma_low - ioc->reply_frames_low_dma));
  244. req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
  245. cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
  246. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  247. dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x\n",
  248. ioc->name, mr, req_idx));
  249. DBG_DUMP_REPLY_FRAME(mr)
  250. /* Check/log IOC log info
  251. */
  252. ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
  253. if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  254. u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
  255. if (ioc->bus_type == FC)
  256. mpt_fc_log_info(ioc, log_info);
  257. else if (ioc->bus_type == SCSI)
  258. mpt_sp_log_info(ioc, log_info);
  259. }
  260. if (ioc_stat & MPI_IOCSTATUS_MASK) {
  261. if (ioc->bus_type == SCSI)
  262. mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
  263. }
  264. } else {
  265. /*
  266. * Process turbo (context) reply...
  267. */
  268. dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n", ioc->name, pa));
  269. type = (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT);
  270. if (type == MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET) {
  271. cb_idx = mpt_stm_index;
  272. mf = NULL;
  273. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  274. } else if (type == MPI_CONTEXT_REPLY_TYPE_LAN) {
  275. cb_idx = mpt_lan_index;
  276. /* Blind set of mf to NULL here was fatal
  277. * after lan_reply says "freeme"
  278. * Fix sort of combined with an optimization here;
  279. * added explicit check for case where lan_reply
  280. * was just returning 1 and doing nothing else.
  281. * For this case skip the callback, but set up
  282. * proper mf value first here:-)
  283. */
  284. if ((pa & 0x58000000) == 0x58000000) {
  285. req_idx = pa & 0x0000FFFF;
  286. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  287. freeme = 1;
  288. /*
  289. * IMPORTANT! Invalidate the callback!
  290. */
  291. cb_idx = 0;
  292. } else {
  293. mf = NULL;
  294. }
  295. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  296. } else {
  297. req_idx = pa & 0x0000FFFF;
  298. cb_idx = (pa & 0x00FF0000) >> 16;
  299. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  300. mr = NULL;
  301. }
  302. pa = 0; /* No reply flush! */
  303. }
  304. #ifdef MPT_DEBUG_IRQ
  305. if (ioc->bus_type == SCSI) {
  306. /* Verify mf, mr are reasonable.
  307. */
  308. if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))
  309. || (mf < ioc->req_frames)) ) {
  310. printk(MYIOC_s_WARN_FMT
  311. "mpt_interrupt: Invalid mf (%p) req_idx (%d)!\n", ioc->name, (void *)mf, req_idx);
  312. cb_idx = 0;
  313. pa = 0;
  314. freeme = 0;
  315. }
  316. if ((pa) && (mr) && ((mr >= MPT_INDEX_2_RFPTR(ioc, ioc->req_depth))
  317. || (mr < ioc->reply_frames)) ) {
  318. printk(MYIOC_s_WARN_FMT
  319. "mpt_interrupt: Invalid rf (%p)!\n", ioc->name, (void *)mr);
  320. cb_idx = 0;
  321. pa = 0;
  322. freeme = 0;
  323. }
  324. if (cb_idx > (MPT_MAX_PROTOCOL_DRIVERS-1)) {
  325. printk(MYIOC_s_WARN_FMT
  326. "mpt_interrupt: Invalid cb_idx (%d)!\n", ioc->name, cb_idx);
  327. cb_idx = 0;
  328. pa = 0;
  329. freeme = 0;
  330. }
  331. }
  332. #endif
  333. /* Check for (valid) IO callback! */
  334. if (cb_idx) {
  335. /* Do the callback! */
  336. freeme = (*(MptCallbacks[cb_idx]))(ioc, mf, mr);
  337. }
  338. if (pa) {
  339. /* Flush (non-TURBO) reply with a WRITE! */
  340. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
  341. }
  342. if (freeme) {
  343. /* Put Request back on FreeQ! */
  344. mpt_free_msg_frame(ioc, mf);
  345. }
  346. mb();
  347. } /* drain reply FIFO */
  348. return IRQ_HANDLED;
  349. }
  350. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  351. /*
  352. * mpt_base_reply - MPT base driver's callback routine; all base driver
  353. * "internal" request/reply processing is routed here.
  354. * Currently used for EventNotification and EventAck handling.
  355. * @ioc: Pointer to MPT_ADAPTER structure
  356. * @mf: Pointer to original MPT request frame
  357. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  358. *
  359. * Returns 1 indicating original alloc'd request frame ptr
  360. * should be freed, or 0 if it shouldn't.
  361. */
  362. static int
  363. mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
  364. {
  365. int freereq = 1;
  366. u8 func;
  367. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
  368. if ((mf == NULL) ||
  369. (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
  370. printk(MYIOC_s_ERR_FMT "NULL or BAD request frame ptr! (=%p)\n",
  371. ioc->name, (void *)mf);
  372. return 1;
  373. }
  374. if (reply == NULL) {
  375. dprintk((MYIOC_s_ERR_FMT "Unexpected NULL Event (turbo?) reply!\n",
  376. ioc->name));
  377. return 1;
  378. }
  379. if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
  380. dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
  381. DBG_DUMP_REQUEST_FRAME_HDR(mf)
  382. }
  383. func = reply->u.hdr.Function;
  384. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
  385. ioc->name, func));
  386. if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
  387. EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
  388. int evHandlers = 0;
  389. int results;
  390. results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
  391. if (results != evHandlers) {
  392. /* CHECKME! Any special handling needed here? */
  393. devtprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
  394. ioc->name, evHandlers, results));
  395. }
  396. /*
  397. * Hmmm... It seems that EventNotificationReply is an exception
  398. * to the rule of one reply per request.
  399. */
  400. if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
  401. freereq = 0;
  402. #ifdef CONFIG_PROC_FS
  403. // LogEvent(ioc, pEvReply);
  404. #endif
  405. } else if (func == MPI_FUNCTION_EVENT_ACK) {
  406. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
  407. ioc->name));
  408. } else if (func == MPI_FUNCTION_CONFIG ||
  409. func == MPI_FUNCTION_TOOLBOX) {
  410. CONFIGPARMS *pCfg;
  411. unsigned long flags;
  412. dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
  413. ioc->name, mf, reply));
  414. pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
  415. if (pCfg) {
  416. /* disable timer and remove from linked list */
  417. del_timer(&pCfg->timer);
  418. spin_lock_irqsave(&ioc->FreeQlock, flags);
  419. list_del(&pCfg->linkage);
  420. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  421. /*
  422. * If IOC Status is SUCCESS, save the header
  423. * and set the status code to GOOD.
  424. */
  425. pCfg->status = MPT_CONFIG_ERROR;
  426. if (reply) {
  427. ConfigReply_t *pReply = (ConfigReply_t *)reply;
  428. u16 status;
  429. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  430. dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
  431. status, le32_to_cpu(pReply->IOCLogInfo)));
  432. pCfg->status = status;
  433. if (status == MPI_IOCSTATUS_SUCCESS) {
  434. pCfg->hdr->PageVersion = pReply->Header.PageVersion;
  435. pCfg->hdr->PageLength = pReply->Header.PageLength;
  436. pCfg->hdr->PageNumber = pReply->Header.PageNumber;
  437. pCfg->hdr->PageType = pReply->Header.PageType;
  438. }
  439. }
  440. /*
  441. * Wake up the original calling thread
  442. */
  443. pCfg->wait_done = 1;
  444. wake_up(&mpt_waitq);
  445. }
  446. } else {
  447. printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
  448. ioc->name, func);
  449. }
  450. /*
  451. * Conditionally tell caller to free the original
  452. * EventNotification/EventAck/unexpected request frame!
  453. */
  454. return freereq;
  455. }
  456. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  457. /**
  458. * mpt_register - Register protocol-specific main callback handler.
  459. * @cbfunc: callback function pointer
  460. * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
  461. *
  462. * This routine is called by a protocol-specific driver (SCSI host,
  463. * LAN, SCSI target) to register it's reply callback routine. Each
  464. * protocol-specific driver must do this before it will be able to
  465. * use any IOC resources, such as obtaining request frames.
  466. *
  467. * NOTES: The SCSI protocol driver currently calls this routine thrice
  468. * in order to register separate callbacks; one for "normal" SCSI IO;
  469. * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  470. *
  471. * Returns a positive integer valued "handle" in the
  472. * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
  473. * Any non-positive return value (including zero!) should be considered
  474. * an error by the caller.
  475. */
  476. int
  477. mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
  478. {
  479. int i;
  480. last_drv_idx = -1;
  481. /*
  482. * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
  483. * (slot/handle 0 is reserved!)
  484. */
  485. for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
  486. if (MptCallbacks[i] == NULL) {
  487. MptCallbacks[i] = cbfunc;
  488. MptDriverClass[i] = dclass;
  489. MptEvHandlers[i] = NULL;
  490. last_drv_idx = i;
  491. break;
  492. }
  493. }
  494. return last_drv_idx;
  495. }
  496. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  497. /**
  498. * mpt_deregister - Deregister a protocol drivers resources.
  499. * @cb_idx: previously registered callback handle
  500. *
  501. * Each protocol-specific driver should call this routine when it's
  502. * module is unloaded.
  503. */
  504. void
  505. mpt_deregister(int cb_idx)
  506. {
  507. if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
  508. MptCallbacks[cb_idx] = NULL;
  509. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  510. MptEvHandlers[cb_idx] = NULL;
  511. last_drv_idx++;
  512. }
  513. }
  514. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  515. /**
  516. * mpt_event_register - Register protocol-specific event callback
  517. * handler.
  518. * @cb_idx: previously registered (via mpt_register) callback handle
  519. * @ev_cbfunc: callback function
  520. *
  521. * This routine can be called by one or more protocol-specific drivers
  522. * if/when they choose to be notified of MPT events.
  523. *
  524. * Returns 0 for success.
  525. */
  526. int
  527. mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
  528. {
  529. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  530. return -1;
  531. MptEvHandlers[cb_idx] = ev_cbfunc;
  532. return 0;
  533. }
  534. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  535. /**
  536. * mpt_event_deregister - Deregister protocol-specific event callback
  537. * handler.
  538. * @cb_idx: previously registered callback handle
  539. *
  540. * Each protocol-specific driver should call this routine
  541. * when it does not (or can no longer) handle events,
  542. * or when it's module is unloaded.
  543. */
  544. void
  545. mpt_event_deregister(int cb_idx)
  546. {
  547. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  548. return;
  549. MptEvHandlers[cb_idx] = NULL;
  550. }
  551. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  552. /**
  553. * mpt_reset_register - Register protocol-specific IOC reset handler.
  554. * @cb_idx: previously registered (via mpt_register) callback handle
  555. * @reset_func: reset function
  556. *
  557. * This routine can be called by one or more protocol-specific drivers
  558. * if/when they choose to be notified of IOC resets.
  559. *
  560. * Returns 0 for success.
  561. */
  562. int
  563. mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
  564. {
  565. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  566. return -1;
  567. MptResetHandlers[cb_idx] = reset_func;
  568. return 0;
  569. }
  570. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  571. /**
  572. * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
  573. * @cb_idx: previously registered callback handle
  574. *
  575. * Each protocol-specific driver should call this routine
  576. * when it does not (or can no longer) handle IOC reset handling,
  577. * or when it's module is unloaded.
  578. */
  579. void
  580. mpt_reset_deregister(int cb_idx)
  581. {
  582. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  583. return;
  584. MptResetHandlers[cb_idx] = NULL;
  585. }
  586. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  587. /**
  588. * mpt_device_driver_register - Register device driver hooks
  589. */
  590. int
  591. mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
  592. {
  593. MPT_ADAPTER *ioc;
  594. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) {
  595. return -EINVAL;
  596. }
  597. MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
  598. /* call per pci device probe entry point */
  599. list_for_each_entry(ioc, &ioc_list, list) {
  600. if(dd_cbfunc->probe) {
  601. dd_cbfunc->probe(ioc->pcidev,
  602. ioc->pcidev->driver->id_table);
  603. }
  604. }
  605. return 0;
  606. }
  607. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  608. /**
  609. * mpt_device_driver_deregister - DeRegister device driver hooks
  610. */
  611. void
  612. mpt_device_driver_deregister(int cb_idx)
  613. {
  614. struct mpt_pci_driver *dd_cbfunc;
  615. MPT_ADAPTER *ioc;
  616. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  617. return;
  618. dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
  619. list_for_each_entry(ioc, &ioc_list, list) {
  620. if (dd_cbfunc->remove)
  621. dd_cbfunc->remove(ioc->pcidev);
  622. }
  623. MptDeviceDriverHandlers[cb_idx] = NULL;
  624. }
  625. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  626. /**
  627. * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
  628. * allocated per MPT adapter.
  629. * @handle: Handle of registered MPT protocol driver
  630. * @ioc: Pointer to MPT adapter structure
  631. *
  632. * Returns pointer to a MPT request frame or %NULL if none are available
  633. * or IOC is not active.
  634. */
  635. MPT_FRAME_HDR*
  636. mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
  637. {
  638. MPT_FRAME_HDR *mf;
  639. unsigned long flags;
  640. u16 req_idx; /* Request index */
  641. /* validate handle and ioc identifier */
  642. #ifdef MFCNT
  643. if (!ioc->active)
  644. printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
  645. #endif
  646. /* If interrupts are not attached, do not return a request frame */
  647. if (!ioc->active)
  648. return NULL;
  649. spin_lock_irqsave(&ioc->FreeQlock, flags);
  650. if (!list_empty(&ioc->FreeQ)) {
  651. int req_offset;
  652. mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
  653. u.frame.linkage.list);
  654. list_del(&mf->u.frame.linkage.list);
  655. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  656. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  657. /* u16! */
  658. req_idx = req_offset / ioc->req_sz;
  659. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  660. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  661. ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
  662. #ifdef MFCNT
  663. ioc->mfcnt++;
  664. #endif
  665. }
  666. else
  667. mf = NULL;
  668. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  669. #ifdef MFCNT
  670. if (mf == NULL)
  671. printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
  672. mfcounter++;
  673. if (mfcounter == PRINT_MF_COUNT)
  674. printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
  675. #endif
  676. dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
  677. ioc->name, handle, ioc->id, mf));
  678. return mf;
  679. }
  680. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  681. /**
  682. * mpt_put_msg_frame - Send a protocol specific MPT request frame
  683. * to a IOC.
  684. * @handle: Handle of registered MPT protocol driver
  685. * @ioc: Pointer to MPT adapter structure
  686. * @mf: Pointer to MPT request frame
  687. *
  688. * This routine posts a MPT request frame to the request post FIFO of a
  689. * specific MPT adapter.
  690. */
  691. void
  692. mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  693. {
  694. u32 mf_dma_addr;
  695. int req_offset;
  696. u16 req_idx; /* Request index */
  697. /* ensure values are reset properly! */
  698. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  699. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  700. /* u16! */
  701. req_idx = req_offset / ioc->req_sz;
  702. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  703. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  704. #ifdef MPT_DEBUG_MSG_FRAME
  705. {
  706. u32 *m = mf->u.frame.hwhdr.__hdr;
  707. int ii, n;
  708. printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
  709. ioc->name, m);
  710. n = ioc->req_sz/4 - 1;
  711. while (m[n] == 0)
  712. n--;
  713. for (ii=0; ii<=n; ii++) {
  714. if (ii && ((ii%8)==0))
  715. printk("\n" KERN_INFO " ");
  716. printk(" %08x", le32_to_cpu(m[ii]));
  717. }
  718. printk("\n");
  719. }
  720. #endif
  721. mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
  722. dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
  723. CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
  724. }
  725. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  726. /**
  727. * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
  728. * @handle: Handle of registered MPT protocol driver
  729. * @ioc: Pointer to MPT adapter structure
  730. * @mf: Pointer to MPT request frame
  731. *
  732. * This routine places a MPT request frame back on the MPT adapter's
  733. * FreeQ.
  734. */
  735. void
  736. mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  737. {
  738. unsigned long flags;
  739. /* Put Request back on FreeQ! */
  740. spin_lock_irqsave(&ioc->FreeQlock, flags);
  741. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  742. #ifdef MFCNT
  743. ioc->mfcnt--;
  744. #endif
  745. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  746. }
  747. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  748. /**
  749. * mpt_add_sge - Place a simple SGE at address pAddr.
  750. * @pAddr: virtual address for SGE
  751. * @flagslength: SGE flags and data transfer length
  752. * @dma_addr: Physical address
  753. *
  754. * This routine places a MPT request frame back on the MPT adapter's
  755. * FreeQ.
  756. */
  757. void
  758. mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  759. {
  760. if (sizeof(dma_addr_t) == sizeof(u64)) {
  761. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  762. u32 tmp = dma_addr & 0xFFFFFFFF;
  763. pSge->FlagsLength = cpu_to_le32(flagslength);
  764. pSge->Address.Low = cpu_to_le32(tmp);
  765. tmp = (u32) ((u64)dma_addr >> 32);
  766. pSge->Address.High = cpu_to_le32(tmp);
  767. } else {
  768. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  769. pSge->FlagsLength = cpu_to_le32(flagslength);
  770. pSge->Address = cpu_to_le32(dma_addr);
  771. }
  772. }
  773. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  774. /**
  775. * mpt_send_handshake_request - Send MPT request via doorbell
  776. * handshake method.
  777. * @handle: Handle of registered MPT protocol driver
  778. * @ioc: Pointer to MPT adapter structure
  779. * @reqBytes: Size of the request in bytes
  780. * @req: Pointer to MPT request frame
  781. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  782. *
  783. * This routine is used exclusively to send MptScsiTaskMgmt
  784. * requests since they are required to be sent via doorbell handshake.
  785. *
  786. * NOTE: It is the callers responsibility to byte-swap fields in the
  787. * request which are greater than 1 byte in size.
  788. *
  789. * Returns 0 for success, non-zero for failure.
  790. */
  791. int
  792. mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
  793. {
  794. int r = 0;
  795. u8 *req_as_bytes;
  796. int ii;
  797. /* State is known to be good upon entering
  798. * this function so issue the bus reset
  799. * request.
  800. */
  801. /*
  802. * Emulate what mpt_put_msg_frame() does /wrt to sanity
  803. * setting cb_idx/req_idx. But ONLY if this request
  804. * is in proper (pre-alloc'd) request buffer range...
  805. */
  806. ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
  807. if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
  808. MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
  809. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
  810. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
  811. }
  812. /* Make sure there are no doorbells */
  813. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  814. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  815. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  816. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  817. /* Wait for IOC doorbell int */
  818. if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
  819. return ii;
  820. }
  821. /* Read doorbell and check for active bit */
  822. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  823. return -5;
  824. dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
  825. ioc->name, ii));
  826. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  827. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  828. return -2;
  829. }
  830. /* Send request via doorbell handshake */
  831. req_as_bytes = (u8 *) req;
  832. for (ii = 0; ii < reqBytes/4; ii++) {
  833. u32 word;
  834. word = ((req_as_bytes[(ii*4) + 0] << 0) |
  835. (req_as_bytes[(ii*4) + 1] << 8) |
  836. (req_as_bytes[(ii*4) + 2] << 16) |
  837. (req_as_bytes[(ii*4) + 3] << 24));
  838. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  839. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  840. r = -3;
  841. break;
  842. }
  843. }
  844. if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
  845. r = 0;
  846. else
  847. r = -4;
  848. /* Make sure there are no doorbells */
  849. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  850. return r;
  851. }
  852. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  853. /**
  854. * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
  855. * the associated MPT adapter structure.
  856. * @iocid: IOC unique identifier (integer)
  857. * @iocpp: Pointer to pointer to IOC adapter
  858. *
  859. * Returns iocid and sets iocpp.
  860. */
  861. int
  862. mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  863. {
  864. MPT_ADAPTER *ioc;
  865. list_for_each_entry(ioc,&ioc_list,list) {
  866. if (ioc->id == iocid) {
  867. *iocpp =ioc;
  868. return iocid;
  869. }
  870. }
  871. *iocpp = NULL;
  872. return -1;
  873. }
  874. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  875. /*
  876. * mpt_attach - Install a PCI intelligent MPT adapter.
  877. * @pdev: Pointer to pci_dev structure
  878. *
  879. * This routine performs all the steps necessary to bring the IOC of
  880. * a MPT adapter to a OPERATIONAL state. This includes registering
  881. * memory regions, registering the interrupt, and allocating request
  882. * and reply memory pools.
  883. *
  884. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  885. * MPT adapter.
  886. *
  887. * Returns 0 for success, non-zero for failure.
  888. *
  889. * TODO: Add support for polled controllers
  890. */
  891. int
  892. mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  893. {
  894. MPT_ADAPTER *ioc;
  895. u8 __iomem *mem;
  896. unsigned long mem_phys;
  897. unsigned long port;
  898. u32 msize;
  899. u32 psize;
  900. int ii;
  901. int r = -ENODEV;
  902. u8 revision;
  903. u8 pcixcmd;
  904. static int mpt_ids = 0;
  905. #ifdef CONFIG_PROC_FS
  906. struct proc_dir_entry *dent, *ent;
  907. #endif
  908. if (pci_enable_device(pdev))
  909. return r;
  910. dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
  911. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  912. dprintk((KERN_INFO MYNAM
  913. ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
  914. } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  915. printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
  916. return r;
  917. }
  918. if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
  919. dprintk((KERN_INFO MYNAM
  920. ": Using 64 bit consistent mask\n"));
  921. else
  922. dprintk((KERN_INFO MYNAM
  923. ": Not using 64 bit consistent mask\n"));
  924. ioc = kmalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
  925. if (ioc == NULL) {
  926. printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
  927. return -ENOMEM;
  928. }
  929. memset(ioc, 0, sizeof(MPT_ADAPTER));
  930. ioc->alloc_total = sizeof(MPT_ADAPTER);
  931. ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
  932. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  933. ioc->pcidev = pdev;
  934. ioc->diagPending = 0;
  935. spin_lock_init(&ioc->diagLock);
  936. /* Initialize the event logging.
  937. */
  938. ioc->eventTypes = 0; /* None */
  939. ioc->eventContext = 0;
  940. ioc->eventLogSize = 0;
  941. ioc->events = NULL;
  942. #ifdef MFCNT
  943. ioc->mfcnt = 0;
  944. #endif
  945. ioc->cached_fw = NULL;
  946. /* Initilize SCSI Config Data structure
  947. */
  948. memset(&ioc->spi_data, 0, sizeof(ScsiCfgData));
  949. /* Initialize the running configQ head.
  950. */
  951. INIT_LIST_HEAD(&ioc->configQ);
  952. /* Find lookup slot. */
  953. INIT_LIST_HEAD(&ioc->list);
  954. ioc->id = mpt_ids++;
  955. mem_phys = msize = 0;
  956. port = psize = 0;
  957. for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
  958. if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
  959. /* Get I/O space! */
  960. port = pci_resource_start(pdev, ii);
  961. psize = pci_resource_len(pdev,ii);
  962. } else {
  963. /* Get memmap */
  964. mem_phys = pci_resource_start(pdev, ii);
  965. msize = pci_resource_len(pdev,ii);
  966. break;
  967. }
  968. }
  969. ioc->mem_size = msize;
  970. if (ii == DEVICE_COUNT_RESOURCE) {
  971. printk(KERN_ERR MYNAM ": ERROR - MPT adapter has no memory regions defined!\n");
  972. kfree(ioc);
  973. return -EINVAL;
  974. }
  975. dinitprintk((KERN_INFO MYNAM ": MPT adapter @ %lx, msize=%dd bytes\n", mem_phys, msize));
  976. dinitprintk((KERN_INFO MYNAM ": (port i/o @ %lx, psize=%dd bytes)\n", port, psize));
  977. mem = NULL;
  978. /* Get logical ptr for PciMem0 space */
  979. /*mem = ioremap(mem_phys, msize);*/
  980. mem = ioremap(mem_phys, 0x100);
  981. if (mem == NULL) {
  982. printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
  983. kfree(ioc);
  984. return -EINVAL;
  985. }
  986. ioc->memmap = mem;
  987. dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
  988. dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
  989. &ioc->facts, &ioc->pfacts[0]));
  990. ioc->mem_phys = mem_phys;
  991. ioc->chip = (SYSIF_REGS __iomem *)mem;
  992. /* Save Port IO values in case we need to do downloadboot */
  993. {
  994. u8 *pmem = (u8*)port;
  995. ioc->pio_mem_phys = port;
  996. ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
  997. }
  998. if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
  999. ioc->prod_name = "LSIFC909";
  1000. ioc->bus_type = FC;
  1001. }
  1002. if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
  1003. ioc->prod_name = "LSIFC929";
  1004. ioc->bus_type = FC;
  1005. }
  1006. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
  1007. ioc->prod_name = "LSIFC919";
  1008. ioc->bus_type = FC;
  1009. }
  1010. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
  1011. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1012. ioc->bus_type = FC;
  1013. if (revision < XL_929) {
  1014. ioc->prod_name = "LSIFC929X";
  1015. /* 929X Chip Fix. Set Split transactions level
  1016. * for PCIX. Set MOST bits to zero.
  1017. */
  1018. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1019. pcixcmd &= 0x8F;
  1020. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1021. } else {
  1022. ioc->prod_name = "LSIFC929XL";
  1023. /* 929XL Chip Fix. Set MMRBC to 0x08.
  1024. */
  1025. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1026. pcixcmd |= 0x08;
  1027. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1028. }
  1029. }
  1030. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
  1031. ioc->prod_name = "LSIFC919X";
  1032. ioc->bus_type = FC;
  1033. /* 919X Chip Fix. Set Split transactions level
  1034. * for PCIX. Set MOST bits to zero.
  1035. */
  1036. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1037. pcixcmd &= 0x8F;
  1038. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1039. }
  1040. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC939X) {
  1041. ioc->prod_name = "LSIFC939X";
  1042. ioc->bus_type = FC;
  1043. ioc->errata_flag_1064 = 1;
  1044. }
  1045. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949X) {
  1046. ioc->prod_name = "LSIFC949X";
  1047. ioc->bus_type = FC;
  1048. ioc->errata_flag_1064 = 1;
  1049. }
  1050. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
  1051. ioc->prod_name = "LSI53C1030";
  1052. ioc->bus_type = SCSI;
  1053. /* 1030 Chip Fix. Disable Split transactions
  1054. * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
  1055. */
  1056. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1057. if (revision < C0_1030) {
  1058. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1059. pcixcmd &= 0x8F;
  1060. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1061. }
  1062. }
  1063. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
  1064. ioc->prod_name = "LSI53C1035";
  1065. ioc->bus_type = SCSI;
  1066. }
  1067. if (ioc->errata_flag_1064)
  1068. pci_disable_io_access(pdev);
  1069. sprintf(ioc->name, "ioc%d", ioc->id);
  1070. spin_lock_init(&ioc->FreeQlock);
  1071. /* Disable all! */
  1072. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1073. ioc->active = 0;
  1074. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1075. /* Set lookup ptr. */
  1076. list_add_tail(&ioc->list, &ioc_list);
  1077. ioc->pci_irq = -1;
  1078. if (pdev->irq) {
  1079. r = request_irq(pdev->irq, mpt_interrupt, SA_SHIRQ, ioc->name, ioc);
  1080. if (r < 0) {
  1081. #ifndef __sparc__
  1082. printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %d!\n",
  1083. ioc->name, pdev->irq);
  1084. #else
  1085. printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %s!\n",
  1086. ioc->name, __irq_itoa(pdev->irq));
  1087. #endif
  1088. list_del(&ioc->list);
  1089. iounmap(mem);
  1090. kfree(ioc);
  1091. return -EBUSY;
  1092. }
  1093. ioc->pci_irq = pdev->irq;
  1094. pci_set_master(pdev); /* ?? */
  1095. pci_set_drvdata(pdev, ioc);
  1096. #ifndef __sparc__
  1097. dprintk((KERN_INFO MYNAM ": %s installed at interrupt %d\n", ioc->name, pdev->irq));
  1098. #else
  1099. dprintk((KERN_INFO MYNAM ": %s installed at interrupt %s\n", ioc->name, __irq_itoa(pdev->irq)));
  1100. #endif
  1101. }
  1102. /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
  1103. */
  1104. mpt_detect_bound_ports(ioc, pdev);
  1105. if ((r = mpt_do_ioc_recovery(ioc,
  1106. MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0) {
  1107. printk(KERN_WARNING MYNAM
  1108. ": WARNING - %s did not initialize properly! (%d)\n",
  1109. ioc->name, r);
  1110. list_del(&ioc->list);
  1111. free_irq(ioc->pci_irq, ioc);
  1112. iounmap(mem);
  1113. kfree(ioc);
  1114. pci_set_drvdata(pdev, NULL);
  1115. return r;
  1116. }
  1117. /* call per device driver probe entry point */
  1118. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1119. if(MptDeviceDriverHandlers[ii] &&
  1120. MptDeviceDriverHandlers[ii]->probe) {
  1121. MptDeviceDriverHandlers[ii]->probe(pdev,id);
  1122. }
  1123. }
  1124. #ifdef CONFIG_PROC_FS
  1125. /*
  1126. * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
  1127. */
  1128. dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
  1129. if (dent) {
  1130. ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
  1131. if (ent) {
  1132. ent->read_proc = procmpt_iocinfo_read;
  1133. ent->data = ioc;
  1134. }
  1135. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
  1136. if (ent) {
  1137. ent->read_proc = procmpt_summary_read;
  1138. ent->data = ioc;
  1139. }
  1140. }
  1141. #endif
  1142. return 0;
  1143. }
  1144. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1145. /*
  1146. * mpt_detach - Remove a PCI intelligent MPT adapter.
  1147. * @pdev: Pointer to pci_dev structure
  1148. *
  1149. */
  1150. void
  1151. mpt_detach(struct pci_dev *pdev)
  1152. {
  1153. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1154. char pname[32];
  1155. int ii;
  1156. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
  1157. remove_proc_entry(pname, NULL);
  1158. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
  1159. remove_proc_entry(pname, NULL);
  1160. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
  1161. remove_proc_entry(pname, NULL);
  1162. /* call per device driver remove entry point */
  1163. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1164. if(MptDeviceDriverHandlers[ii] &&
  1165. MptDeviceDriverHandlers[ii]->remove) {
  1166. MptDeviceDriverHandlers[ii]->remove(pdev);
  1167. }
  1168. }
  1169. /* Disable interrupts! */
  1170. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1171. ioc->active = 0;
  1172. synchronize_irq(pdev->irq);
  1173. /* Clear any lingering interrupt */
  1174. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1175. CHIPREG_READ32(&ioc->chip->IntStatus);
  1176. mpt_adapter_dispose(ioc);
  1177. pci_set_drvdata(pdev, NULL);
  1178. }
  1179. /**************************************************************************
  1180. * Power Management
  1181. */
  1182. #ifdef CONFIG_PM
  1183. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1184. /*
  1185. * mpt_suspend - Fusion MPT base driver suspend routine.
  1186. *
  1187. *
  1188. */
  1189. int
  1190. mpt_suspend(struct pci_dev *pdev, pm_message_t state)
  1191. {
  1192. u32 device_state;
  1193. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1194. switch(state)
  1195. {
  1196. case 1: /* S1 */
  1197. device_state=1; /* D1 */;
  1198. break;
  1199. case 3: /* S3 */
  1200. case 4: /* S4 */
  1201. device_state=3; /* D3 */;
  1202. break;
  1203. default:
  1204. return -EAGAIN /*FIXME*/;
  1205. break;
  1206. }
  1207. printk(MYIOC_s_INFO_FMT
  1208. "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
  1209. ioc->name, pdev, pci_name(pdev), device_state);
  1210. pci_save_state(pdev);
  1211. /* put ioc into READY_STATE */
  1212. if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
  1213. printk(MYIOC_s_ERR_FMT
  1214. "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
  1215. }
  1216. /* disable interrupts */
  1217. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1218. ioc->active = 0;
  1219. /* Clear any lingering interrupt */
  1220. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1221. pci_disable_device(pdev);
  1222. pci_set_power_state(pdev, device_state);
  1223. return 0;
  1224. }
  1225. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1226. /*
  1227. * mpt_resume - Fusion MPT base driver resume routine.
  1228. *
  1229. *
  1230. */
  1231. int
  1232. mpt_resume(struct pci_dev *pdev)
  1233. {
  1234. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1235. u32 device_state = pdev->current_state;
  1236. int recovery_state;
  1237. int ii;
  1238. printk(MYIOC_s_INFO_FMT
  1239. "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
  1240. ioc->name, pdev, pci_name(pdev), device_state);
  1241. pci_set_power_state(pdev, 0);
  1242. pci_restore_state(pdev);
  1243. pci_enable_device(pdev);
  1244. /* enable interrupts */
  1245. CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1246. ioc->active = 1;
  1247. /* F/W not running */
  1248. if(!CHIPREG_READ32(&ioc->chip->Doorbell)) {
  1249. /* enable domain validation flags */
  1250. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  1251. ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_NEED_DV;
  1252. }
  1253. }
  1254. printk(MYIOC_s_INFO_FMT
  1255. "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
  1256. ioc->name,
  1257. (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
  1258. CHIPREG_READ32(&ioc->chip->Doorbell));
  1259. /* bring ioc to operational state */
  1260. if ((recovery_state = mpt_do_ioc_recovery(ioc,
  1261. MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
  1262. printk(MYIOC_s_INFO_FMT
  1263. "pci-resume: Cannot recover, error:[%x]\n",
  1264. ioc->name, recovery_state);
  1265. } else {
  1266. printk(MYIOC_s_INFO_FMT
  1267. "pci-resume: success\n", ioc->name);
  1268. }
  1269. return 0;
  1270. }
  1271. #endif
  1272. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1273. /*
  1274. * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
  1275. * @ioc: Pointer to MPT adapter structure
  1276. * @reason: Event word / reason
  1277. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1278. *
  1279. * This routine performs all the steps necessary to bring the IOC
  1280. * to a OPERATIONAL state.
  1281. *
  1282. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1283. * MPT adapter.
  1284. *
  1285. * Returns:
  1286. * 0 for success
  1287. * -1 if failed to get board READY
  1288. * -2 if READY but IOCFacts Failed
  1289. * -3 if READY but PrimeIOCFifos Failed
  1290. * -4 if READY but IOCInit Failed
  1291. */
  1292. static int
  1293. mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  1294. {
  1295. int hard_reset_done = 0;
  1296. int alt_ioc_ready = 0;
  1297. int hard;
  1298. int rc=0;
  1299. int ii;
  1300. int handlers;
  1301. int ret = 0;
  1302. int reset_alt_ioc_active = 0;
  1303. printk(KERN_INFO MYNAM ": Initiating %s %s\n",
  1304. ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
  1305. /* Disable reply interrupts (also blocks FreeQ) */
  1306. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1307. ioc->active = 0;
  1308. if (ioc->alt_ioc) {
  1309. if (ioc->alt_ioc->active)
  1310. reset_alt_ioc_active = 1;
  1311. /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
  1312. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
  1313. ioc->alt_ioc->active = 0;
  1314. }
  1315. hard = 1;
  1316. if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
  1317. hard = 0;
  1318. if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
  1319. if (hard_reset_done == -4) {
  1320. printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
  1321. ioc->name);
  1322. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1323. /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
  1324. dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1325. ioc->alt_ioc->name));
  1326. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1327. ioc->alt_ioc->active = 1;
  1328. }
  1329. } else {
  1330. printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
  1331. ioc->name);
  1332. }
  1333. return -1;
  1334. }
  1335. /* hard_reset_done = 0 if a soft reset was performed
  1336. * and 1 if a hard reset was performed.
  1337. */
  1338. if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
  1339. if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
  1340. alt_ioc_ready = 1;
  1341. else
  1342. printk(KERN_WARNING MYNAM
  1343. ": alt-%s: Not ready WARNING!\n",
  1344. ioc->alt_ioc->name);
  1345. }
  1346. for (ii=0; ii<5; ii++) {
  1347. /* Get IOC facts! Allow 5 retries */
  1348. if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
  1349. break;
  1350. }
  1351. if (ii == 5) {
  1352. dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
  1353. ret = -2;
  1354. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1355. MptDisplayIocCapabilities(ioc);
  1356. }
  1357. if (alt_ioc_ready) {
  1358. if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
  1359. dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1360. /* Retry - alt IOC was initialized once
  1361. */
  1362. rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
  1363. }
  1364. if (rc) {
  1365. dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1366. alt_ioc_ready = 0;
  1367. reset_alt_ioc_active = 0;
  1368. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1369. MptDisplayIocCapabilities(ioc->alt_ioc);
  1370. }
  1371. }
  1372. /* Prime reply & request queues!
  1373. * (mucho alloc's) Must be done prior to
  1374. * init as upper addresses are needed for init.
  1375. * If fails, continue with alt-ioc processing
  1376. */
  1377. if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
  1378. ret = -3;
  1379. /* May need to check/upload firmware & data here!
  1380. * If fails, continue with alt-ioc processing
  1381. */
  1382. if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
  1383. ret = -4;
  1384. // NEW!
  1385. if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
  1386. printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
  1387. ioc->alt_ioc->name, rc);
  1388. alt_ioc_ready = 0;
  1389. reset_alt_ioc_active = 0;
  1390. }
  1391. if (alt_ioc_ready) {
  1392. if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
  1393. alt_ioc_ready = 0;
  1394. reset_alt_ioc_active = 0;
  1395. printk(KERN_WARNING MYNAM
  1396. ": alt-%s: (%d) init failure WARNING!\n",
  1397. ioc->alt_ioc->name, rc);
  1398. }
  1399. }
  1400. if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
  1401. if (ioc->upload_fw) {
  1402. ddlprintk((MYIOC_s_INFO_FMT
  1403. "firmware upload required!\n", ioc->name));
  1404. /* Controller is not operational, cannot do upload
  1405. */
  1406. if (ret == 0) {
  1407. rc = mpt_do_upload(ioc, sleepFlag);
  1408. if (rc != 0)
  1409. printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
  1410. }
  1411. }
  1412. }
  1413. if (ret == 0) {
  1414. /* Enable! (reply interrupt) */
  1415. CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1416. ioc->active = 1;
  1417. }
  1418. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1419. /* (re)Enable alt-IOC! (reply interrupt) */
  1420. dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1421. ioc->alt_ioc->name));
  1422. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1423. ioc->alt_ioc->active = 1;
  1424. }
  1425. /* Enable MPT base driver management of EventNotification
  1426. * and EventAck handling.
  1427. */
  1428. if ((ret == 0) && (!ioc->facts.EventState))
  1429. (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
  1430. if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
  1431. (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
  1432. /* Add additional "reason" check before call to GetLanConfigPages
  1433. * (combined with GetIoUnitPage2 call). This prevents a somewhat
  1434. * recursive scenario; GetLanConfigPages times out, timer expired
  1435. * routine calls HardResetHandler, which calls into here again,
  1436. * and we try GetLanConfigPages again...
  1437. */
  1438. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  1439. if (ioc->bus_type == FC) {
  1440. /*
  1441. * Pre-fetch FC port WWN and stuff...
  1442. * (FCPortPage0_t stuff)
  1443. */
  1444. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1445. (void) GetFcPortPage0(ioc, ii);
  1446. }
  1447. if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
  1448. (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
  1449. /*
  1450. * Pre-fetch the ports LAN MAC address!
  1451. * (LANPage1_t stuff)
  1452. */
  1453. (void) GetLanConfigPages(ioc);
  1454. #ifdef MPT_DEBUG
  1455. {
  1456. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  1457. dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  1458. ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
  1459. }
  1460. #endif
  1461. }
  1462. } else {
  1463. /* Get NVRAM and adapter maximums from SPP 0 and 2
  1464. */
  1465. mpt_GetScsiPortSettings(ioc, 0);
  1466. /* Get version and length of SDP 1
  1467. */
  1468. mpt_readScsiDevicePageHeaders(ioc, 0);
  1469. /* Find IM volumes
  1470. */
  1471. if (ioc->facts.MsgVersion >= 0x0102)
  1472. mpt_findImVolumes(ioc);
  1473. /* Check, and possibly reset, the coalescing value
  1474. */
  1475. mpt_read_ioc_pg_1(ioc);
  1476. mpt_read_ioc_pg_4(ioc);
  1477. }
  1478. GetIoUnitPage2(ioc);
  1479. }
  1480. /*
  1481. * Call each currently registered protocol IOC reset handler
  1482. * with post-reset indication.
  1483. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  1484. * MptResetHandlers[] registered yet.
  1485. */
  1486. if (hard_reset_done) {
  1487. rc = handlers = 0;
  1488. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  1489. if ((ret == 0) && MptResetHandlers[ii]) {
  1490. dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
  1491. ioc->name, ii));
  1492. rc += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_POST_RESET);
  1493. handlers++;
  1494. }
  1495. if (alt_ioc_ready && MptResetHandlers[ii]) {
  1496. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
  1497. ioc->name, ioc->alt_ioc->name, ii));
  1498. rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
  1499. handlers++;
  1500. }
  1501. }
  1502. /* FIXME? Examine results here? */
  1503. }
  1504. return ret;
  1505. }
  1506. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1507. /*
  1508. * mpt_detect_bound_ports - Search for PCI bus/dev_function
  1509. * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
  1510. * 929X, 1030 or 1035.
  1511. * @ioc: Pointer to MPT adapter structure
  1512. * @pdev: Pointer to (struct pci_dev) structure
  1513. *
  1514. * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
  1515. * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
  1516. */
  1517. static void
  1518. mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
  1519. {
  1520. struct pci_dev *peer=NULL;
  1521. unsigned int slot = PCI_SLOT(pdev->devfn);
  1522. unsigned int func = PCI_FUNC(pdev->devfn);
  1523. MPT_ADAPTER *ioc_srch;
  1524. dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
  1525. " searching for devfn match on %x or %x\n",
  1526. ioc->name, pci_name(pdev), pdev->devfn,
  1527. func-1, func+1));
  1528. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
  1529. if (!peer) {
  1530. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
  1531. if (!peer)
  1532. return;
  1533. }
  1534. list_for_each_entry(ioc_srch, &ioc_list, list) {
  1535. struct pci_dev *_pcidev = ioc_srch->pcidev;
  1536. if (_pcidev == peer) {
  1537. /* Paranoia checks */
  1538. if (ioc->alt_ioc != NULL) {
  1539. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1540. ioc->name, ioc->alt_ioc->name);
  1541. break;
  1542. } else if (ioc_srch->alt_ioc != NULL) {
  1543. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1544. ioc_srch->name, ioc_srch->alt_ioc->name);
  1545. break;
  1546. }
  1547. dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
  1548. ioc->name, ioc_srch->name));
  1549. ioc_srch->alt_ioc = ioc;
  1550. ioc->alt_ioc = ioc_srch;
  1551. }
  1552. }
  1553. pci_dev_put(peer);
  1554. }
  1555. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1556. /*
  1557. * mpt_adapter_disable - Disable misbehaving MPT adapter.
  1558. * @this: Pointer to MPT adapter structure
  1559. */
  1560. static void
  1561. mpt_adapter_disable(MPT_ADAPTER *ioc)
  1562. {
  1563. int sz;
  1564. int ret;
  1565. if (ioc->cached_fw != NULL) {
  1566. ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
  1567. if ((ret = mpt_downloadboot(ioc, NO_SLEEP)) < 0) {
  1568. printk(KERN_WARNING MYNAM
  1569. ": firmware downloadboot failure (%d)!\n", ret);
  1570. }
  1571. }
  1572. /* Disable adapter interrupts! */
  1573. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1574. ioc->active = 0;
  1575. /* Clear any lingering interrupt */
  1576. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1577. if (ioc->alloc != NULL) {
  1578. sz = ioc->alloc_sz;
  1579. dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
  1580. ioc->name, ioc->alloc, ioc->alloc_sz));
  1581. pci_free_consistent(ioc->pcidev, sz,
  1582. ioc->alloc, ioc->alloc_dma);
  1583. ioc->reply_frames = NULL;
  1584. ioc->req_frames = NULL;
  1585. ioc->alloc = NULL;
  1586. ioc->alloc_total -= sz;
  1587. }
  1588. if (ioc->sense_buf_pool != NULL) {
  1589. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  1590. pci_free_consistent(ioc->pcidev, sz,
  1591. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  1592. ioc->sense_buf_pool = NULL;
  1593. ioc->alloc_total -= sz;
  1594. }
  1595. if (ioc->events != NULL){
  1596. sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  1597. kfree(ioc->events);
  1598. ioc->events = NULL;
  1599. ioc->alloc_total -= sz;
  1600. }
  1601. if (ioc->cached_fw != NULL) {
  1602. sz = ioc->facts.FWImageSize;
  1603. pci_free_consistent(ioc->pcidev, sz,
  1604. ioc->cached_fw, ioc->cached_fw_dma);
  1605. ioc->cached_fw = NULL;
  1606. ioc->alloc_total -= sz;
  1607. }
  1608. if (ioc->spi_data.nvram != NULL) {
  1609. kfree(ioc->spi_data.nvram);
  1610. ioc->spi_data.nvram = NULL;
  1611. }
  1612. if (ioc->spi_data.pIocPg3 != NULL) {
  1613. kfree(ioc->spi_data.pIocPg3);
  1614. ioc->spi_data.pIocPg3 = NULL;
  1615. }
  1616. if (ioc->spi_data.pIocPg4 != NULL) {
  1617. sz = ioc->spi_data.IocPg4Sz;
  1618. pci_free_consistent(ioc->pcidev, sz,
  1619. ioc->spi_data.pIocPg4,
  1620. ioc->spi_data.IocPg4_dma);
  1621. ioc->spi_data.pIocPg4 = NULL;
  1622. ioc->alloc_total -= sz;
  1623. }
  1624. if (ioc->ReqToChain != NULL) {
  1625. kfree(ioc->ReqToChain);
  1626. kfree(ioc->RequestNB);
  1627. ioc->ReqToChain = NULL;
  1628. }
  1629. if (ioc->ChainToChain != NULL) {
  1630. kfree(ioc->ChainToChain);
  1631. ioc->ChainToChain = NULL;
  1632. }
  1633. }
  1634. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1635. /*
  1636. * mpt_adapter_dispose - Free all resources associated with a MPT
  1637. * adapter.
  1638. * @ioc: Pointer to MPT adapter structure
  1639. *
  1640. * This routine unregisters h/w resources and frees all alloc'd memory
  1641. * associated with a MPT adapter structure.
  1642. */
  1643. static void
  1644. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  1645. {
  1646. if (ioc != NULL) {
  1647. int sz_first, sz_last;
  1648. sz_first = ioc->alloc_total;
  1649. mpt_adapter_disable(ioc);
  1650. if (ioc->pci_irq != -1) {
  1651. free_irq(ioc->pci_irq, ioc);
  1652. ioc->pci_irq = -1;
  1653. }
  1654. if (ioc->memmap != NULL)
  1655. iounmap(ioc->memmap);
  1656. #if defined(CONFIG_MTRR) && 0
  1657. if (ioc->mtrr_reg > 0) {
  1658. mtrr_del(ioc->mtrr_reg, 0, 0);
  1659. dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
  1660. }
  1661. #endif
  1662. /* Zap the adapter lookup ptr! */
  1663. list_del(&ioc->list);
  1664. sz_last = ioc->alloc_total;
  1665. dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
  1666. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  1667. kfree(ioc);
  1668. }
  1669. }
  1670. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1671. /*
  1672. * MptDisplayIocCapabilities - Disply IOC's capacilities.
  1673. * @ioc: Pointer to MPT adapter structure
  1674. */
  1675. static void
  1676. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  1677. {
  1678. int i = 0;
  1679. printk(KERN_INFO "%s: ", ioc->name);
  1680. if (ioc->prod_name && strlen(ioc->prod_name) > 3)
  1681. printk("%s: ", ioc->prod_name+3);
  1682. printk("Capabilities={");
  1683. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  1684. printk("Initiator");
  1685. i++;
  1686. }
  1687. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1688. printk("%sTarget", i ? "," : "");
  1689. i++;
  1690. }
  1691. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  1692. printk("%sLAN", i ? "," : "");
  1693. i++;
  1694. }
  1695. #if 0
  1696. /*
  1697. * This would probably evoke more questions than it's worth
  1698. */
  1699. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1700. printk("%sLogBusAddr", i ? "," : "");
  1701. i++;
  1702. }
  1703. #endif
  1704. printk("}\n");
  1705. }
  1706. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1707. /*
  1708. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  1709. * @ioc: Pointer to MPT_ADAPTER structure
  1710. * @force: Force hard KickStart of IOC
  1711. * @sleepFlag: Specifies whether the process can sleep
  1712. *
  1713. * Returns:
  1714. * 1 - DIAG reset and READY
  1715. * 0 - READY initially OR soft reset and READY
  1716. * -1 - Any failure on KickStart
  1717. * -2 - Msg Unit Reset Failed
  1718. * -3 - IO Unit Reset Failed
  1719. * -4 - IOC owned by a PEER
  1720. */
  1721. static int
  1722. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  1723. {
  1724. u32 ioc_state;
  1725. int statefault = 0;
  1726. int cntdn;
  1727. int hard_reset_done = 0;
  1728. int r;
  1729. int ii;
  1730. int whoinit;
  1731. /* Get current [raw] IOC state */
  1732. ioc_state = mpt_GetIocState(ioc, 0);
  1733. dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
  1734. /*
  1735. * Check to see if IOC got left/stuck in doorbell handshake
  1736. * grip of death. If so, hard reset the IOC.
  1737. */
  1738. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  1739. statefault = 1;
  1740. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  1741. ioc->name);
  1742. }
  1743. /* Is it already READY? */
  1744. if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
  1745. return 0;
  1746. /*
  1747. * Check to see if IOC is in FAULT state.
  1748. */
  1749. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  1750. statefault = 2;
  1751. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  1752. ioc->name);
  1753. printk(KERN_WARNING " FAULT code = %04xh\n",
  1754. ioc_state & MPI_DOORBELL_DATA_MASK);
  1755. }
  1756. /*
  1757. * Hmmm... Did it get left operational?
  1758. */
  1759. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  1760. dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
  1761. ioc->name));
  1762. /* Check WhoInit.
  1763. * If PCI Peer, exit.
  1764. * Else, if no fault conditions are present, issue a MessageUnitReset
  1765. * Else, fall through to KickStart case
  1766. */
  1767. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  1768. dprintk((KERN_WARNING MYNAM
  1769. ": whoinit 0x%x\n statefault %d force %d\n",
  1770. whoinit, statefault, force));
  1771. if (whoinit == MPI_WHOINIT_PCI_PEER)
  1772. return -4;
  1773. else {
  1774. if ((statefault == 0 ) && (force == 0)) {
  1775. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  1776. return 0;
  1777. }
  1778. statefault = 3;
  1779. }
  1780. }
  1781. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  1782. if (hard_reset_done < 0)
  1783. return -1;
  1784. /*
  1785. * Loop here waiting for IOC to come READY.
  1786. */
  1787. ii = 0;
  1788. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  1789. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  1790. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  1791. /*
  1792. * BIOS or previous driver load left IOC in OP state.
  1793. * Reset messaging FIFOs.
  1794. */
  1795. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  1796. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  1797. return -2;
  1798. }
  1799. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  1800. /*
  1801. * Something is wrong. Try to get IOC back
  1802. * to a known state.
  1803. */
  1804. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  1805. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  1806. return -3;
  1807. }
  1808. }
  1809. ii++; cntdn--;
  1810. if (!cntdn) {
  1811. printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
  1812. ioc->name, (int)((ii+5)/HZ));
  1813. return -ETIME;
  1814. }
  1815. if (sleepFlag == CAN_SLEEP) {
  1816. msleep_interruptible(1);
  1817. } else {
  1818. mdelay (1); /* 1 msec delay */
  1819. }
  1820. }
  1821. if (statefault < 3) {
  1822. printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
  1823. ioc->name,
  1824. statefault==1 ? "stuck handshake" : "IOC FAULT");
  1825. }
  1826. return hard_reset_done;
  1827. }
  1828. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1829. /*
  1830. * mpt_GetIocState - Get the current state of a MPT adapter.
  1831. * @ioc: Pointer to MPT_ADAPTER structure
  1832. * @cooked: Request raw or cooked IOC state
  1833. *
  1834. * Returns all IOC Doorbell register bits if cooked==0, else just the
  1835. * Doorbell bits in MPI_IOC_STATE_MASK.
  1836. */
  1837. u32
  1838. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  1839. {
  1840. u32 s, sc;
  1841. /* Get! */
  1842. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  1843. // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
  1844. sc = s & MPI_IOC_STATE_MASK;
  1845. /* Save! */
  1846. ioc->last_state = sc;
  1847. return cooked ? sc : s;
  1848. }
  1849. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1850. /*
  1851. * GetIocFacts - Send IOCFacts request to MPT adapter.
  1852. * @ioc: Pointer to MPT_ADAPTER structure
  1853. * @sleepFlag: Specifies whether the process can sleep
  1854. * @reason: If recovery, only update facts.
  1855. *
  1856. * Returns 0 for success, non-zero for failure.
  1857. */
  1858. static int
  1859. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  1860. {
  1861. IOCFacts_t get_facts;
  1862. IOCFactsReply_t *facts;
  1863. int r;
  1864. int req_sz;
  1865. int reply_sz;
  1866. int sz;
  1867. u32 status, vv;
  1868. u8 shiftFactor=1;
  1869. /* IOC *must* NOT be in RESET state! */
  1870. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  1871. printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  1872. ioc->name,
  1873. ioc->last_state );
  1874. return -44;
  1875. }
  1876. facts = &ioc->facts;
  1877. /* Destination (reply area)... */
  1878. reply_sz = sizeof(*facts);
  1879. memset(facts, 0, reply_sz);
  1880. /* Request area (get_facts on the stack right now!) */
  1881. req_sz = sizeof(get_facts);
  1882. memset(&get_facts, 0, req_sz);
  1883. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  1884. /* Assert: All other get_facts fields are zero! */
  1885. dinitprintk((MYIOC_s_INFO_FMT
  1886. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  1887. ioc->name, req_sz, reply_sz));
  1888. /* No non-zero fields in the get_facts request are greater than
  1889. * 1 byte in size, so we can just fire it off as is.
  1890. */
  1891. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  1892. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  1893. if (r != 0)
  1894. return r;
  1895. /*
  1896. * Now byte swap (GRRR) the necessary fields before any further
  1897. * inspection of reply contents.
  1898. *
  1899. * But need to do some sanity checks on MsgLength (byte) field
  1900. * to make sure we don't zero IOC's req_sz!
  1901. */
  1902. /* Did we get a valid reply? */
  1903. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  1904. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1905. /*
  1906. * If not been here, done that, save off first WhoInit value
  1907. */
  1908. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  1909. ioc->FirstWhoInit = facts->WhoInit;
  1910. }
  1911. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  1912. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  1913. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  1914. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  1915. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  1916. status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
  1917. /* CHECKME! IOCStatus, IOCLogInfo */
  1918. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  1919. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  1920. /*
  1921. * FC f/w version changed between 1.1 and 1.2
  1922. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  1923. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  1924. */
  1925. if (facts->MsgVersion < 0x0102) {
  1926. /*
  1927. * Handle old FC f/w style, convert to new...
  1928. */
  1929. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  1930. facts->FWVersion.Word =
  1931. ((oldv<<12) & 0xFF000000) |
  1932. ((oldv<<8) & 0x000FFF00);
  1933. } else
  1934. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  1935. facts->ProductID = le16_to_cpu(facts->ProductID);
  1936. facts->CurrentHostMfaHighAddr =
  1937. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  1938. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  1939. facts->CurrentSenseBufferHighAddr =
  1940. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  1941. facts->CurReplyFrameSize =
  1942. le16_to_cpu(facts->CurReplyFrameSize);
  1943. /*
  1944. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  1945. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  1946. * to 14 in MPI-1.01.0x.
  1947. */
  1948. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  1949. facts->MsgVersion > 0x0100) {
  1950. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  1951. }
  1952. sz = facts->FWImageSize;
  1953. if ( sz & 0x01 )
  1954. sz += 1;
  1955. if ( sz & 0x02 )
  1956. sz += 2;
  1957. facts->FWImageSize = sz;
  1958. if (!facts->RequestFrameSize) {
  1959. /* Something is wrong! */
  1960. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  1961. ioc->name);
  1962. return -55;
  1963. }
  1964. r = sz = facts->BlockSize;
  1965. vv = ((63 / (sz * 4)) + 1) & 0x03;
  1966. ioc->NB_for_64_byte_frame = vv;
  1967. while ( sz )
  1968. {
  1969. shiftFactor++;
  1970. sz = sz >> 1;
  1971. }
  1972. ioc->NBShiftFactor = shiftFactor;
  1973. dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  1974. ioc->name, vv, shiftFactor, r));
  1975. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1976. /*
  1977. * Set values for this IOC's request & reply frame sizes,
  1978. * and request & reply queue depths...
  1979. */
  1980. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  1981. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  1982. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  1983. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  1984. dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
  1985. ioc->name, ioc->reply_sz, ioc->reply_depth));
  1986. dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
  1987. ioc->name, ioc->req_sz, ioc->req_depth));
  1988. /* Get port facts! */
  1989. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  1990. return r;
  1991. }
  1992. } else {
  1993. printk(MYIOC_s_ERR_FMT
  1994. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  1995. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  1996. RequestFrameSize)/sizeof(u32)));
  1997. return -66;
  1998. }
  1999. return 0;
  2000. }
  2001. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2002. /*
  2003. * GetPortFacts - Send PortFacts request to MPT adapter.
  2004. * @ioc: Pointer to MPT_ADAPTER structure
  2005. * @portnum: Port number
  2006. * @sleepFlag: Specifies whether the process can sleep
  2007. *
  2008. * Returns 0 for success, non-zero for failure.
  2009. */
  2010. static int
  2011. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2012. {
  2013. PortFacts_t get_pfacts;
  2014. PortFactsReply_t *pfacts;
  2015. int ii;
  2016. int req_sz;
  2017. int reply_sz;
  2018. /* IOC *must* NOT be in RESET state! */
  2019. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2020. printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
  2021. ioc->name,
  2022. ioc->last_state );
  2023. return -4;
  2024. }
  2025. pfacts = &ioc->pfacts[portnum];
  2026. /* Destination (reply area)... */
  2027. reply_sz = sizeof(*pfacts);
  2028. memset(pfacts, 0, reply_sz);
  2029. /* Request area (get_pfacts on the stack right now!) */
  2030. req_sz = sizeof(get_pfacts);
  2031. memset(&get_pfacts, 0, req_sz);
  2032. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2033. get_pfacts.PortNumber = portnum;
  2034. /* Assert: All other get_pfacts fields are zero! */
  2035. dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
  2036. ioc->name, portnum));
  2037. /* No non-zero fields in the get_pfacts request are greater than
  2038. * 1 byte in size, so we can just fire it off as is.
  2039. */
  2040. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2041. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2042. if (ii != 0)
  2043. return ii;
  2044. /* Did we get a valid reply? */
  2045. /* Now byte swap the necessary fields in the response. */
  2046. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2047. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2048. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2049. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2050. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2051. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2052. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2053. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2054. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2055. return 0;
  2056. }
  2057. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2058. /*
  2059. * SendIocInit - Send IOCInit request to MPT adapter.
  2060. * @ioc: Pointer to MPT_ADAPTER structure
  2061. * @sleepFlag: Specifies whether the process can sleep
  2062. *
  2063. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2064. *
  2065. * Returns 0 for success, non-zero for failure.
  2066. */
  2067. static int
  2068. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2069. {
  2070. IOCInit_t ioc_init;
  2071. MPIDefaultReply_t init_reply;
  2072. u32 state;
  2073. int r;
  2074. int count;
  2075. int cntdn;
  2076. memset(&ioc_init, 0, sizeof(ioc_init));
  2077. memset(&init_reply, 0, sizeof(init_reply));
  2078. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2079. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2080. /* If we are in a recovery mode and we uploaded the FW image,
  2081. * then this pointer is not NULL. Skip the upload a second time.
  2082. * Set this flag if cached_fw set for either IOC.
  2083. */
  2084. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2085. ioc->upload_fw = 1;
  2086. else
  2087. ioc->upload_fw = 0;
  2088. ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
  2089. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2090. if (ioc->bus_type == FC)
  2091. ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
  2092. else
  2093. ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
  2094. ioc_init.MaxBuses = MPT_MAX_BUS;
  2095. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2096. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2097. /* Save the upper 32-bits of the request
  2098. * (reply) and sense buffers.
  2099. */
  2100. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2101. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2102. } else {
  2103. /* Force 32-bit addressing */
  2104. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2105. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2106. }
  2107. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2108. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2109. dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
  2110. ioc->name, &ioc_init));
  2111. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2112. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2113. if (r != 0)
  2114. return r;
  2115. /* No need to byte swap the multibyte fields in the reply
  2116. * since we don't even look at it's contents.
  2117. */
  2118. dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
  2119. ioc->name, &ioc_init));
  2120. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
  2121. return r;
  2122. /* YIKES! SUPER IMPORTANT!!!
  2123. * Poll IocState until _OPERATIONAL while IOC is doing
  2124. * LoopInit and TargetDiscovery!
  2125. */
  2126. count = 0;
  2127. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  2128. state = mpt_GetIocState(ioc, 1);
  2129. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  2130. if (sleepFlag == CAN_SLEEP) {
  2131. msleep_interruptible(1);
  2132. } else {
  2133. mdelay(1);
  2134. }
  2135. if (!cntdn) {
  2136. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  2137. ioc->name, (int)((count+5)/HZ));
  2138. return -9;
  2139. }
  2140. state = mpt_GetIocState(ioc, 1);
  2141. count++;
  2142. }
  2143. dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
  2144. ioc->name, count));
  2145. return r;
  2146. }
  2147. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2148. /*
  2149. * SendPortEnable - Send PortEnable request to MPT adapter port.
  2150. * @ioc: Pointer to MPT_ADAPTER structure
  2151. * @portnum: Port number to enable
  2152. * @sleepFlag: Specifies whether the process can sleep
  2153. *
  2154. * Send PortEnable to bring IOC to OPERATIONAL state.
  2155. *
  2156. * Returns 0 for success, non-zero for failure.
  2157. */
  2158. static int
  2159. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2160. {
  2161. PortEnable_t port_enable;
  2162. MPIDefaultReply_t reply_buf;
  2163. int ii;
  2164. int req_sz;
  2165. int reply_sz;
  2166. /* Destination... */
  2167. reply_sz = sizeof(MPIDefaultReply_t);
  2168. memset(&reply_buf, 0, reply_sz);
  2169. req_sz = sizeof(PortEnable_t);
  2170. memset(&port_enable, 0, req_sz);
  2171. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  2172. port_enable.PortNumber = portnum;
  2173. /* port_enable.ChainOffset = 0; */
  2174. /* port_enable.MsgFlags = 0; */
  2175. /* port_enable.MsgContext = 0; */
  2176. dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
  2177. ioc->name, portnum, &port_enable));
  2178. /* RAID FW may take a long time to enable
  2179. */
  2180. if (ioc->bus_type == FC) {
  2181. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2182. reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
  2183. } else {
  2184. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2185. reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
  2186. }
  2187. if (ii != 0)
  2188. return ii;
  2189. /* We do not even look at the reply, so we need not
  2190. * swap the multi-byte fields.
  2191. */
  2192. return 0;
  2193. }
  2194. /*
  2195. * ioc: Pointer to MPT_ADAPTER structure
  2196. * size - total FW bytes
  2197. */
  2198. void
  2199. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  2200. {
  2201. if (ioc->cached_fw)
  2202. return; /* use already allocated memory */
  2203. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2204. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  2205. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  2206. } else {
  2207. if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
  2208. ioc->alloc_total += size;
  2209. }
  2210. }
  2211. /*
  2212. * If alt_img is NULL, delete from ioc structure.
  2213. * Else, delete a secondary image in same format.
  2214. */
  2215. void
  2216. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  2217. {
  2218. int sz;
  2219. sz = ioc->facts.FWImageSize;
  2220. dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2221. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2222. pci_free_consistent(ioc->pcidev, sz,
  2223. ioc->cached_fw, ioc->cached_fw_dma);
  2224. ioc->cached_fw = NULL;
  2225. return;
  2226. }
  2227. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2228. /*
  2229. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  2230. * @ioc: Pointer to MPT_ADAPTER structure
  2231. * @sleepFlag: Specifies whether the process can sleep
  2232. *
  2233. * Returns 0 for success, >0 for handshake failure
  2234. * <0 for fw upload failure.
  2235. *
  2236. * Remark: If bound IOC and a successful FWUpload was performed
  2237. * on the bound IOC, the second image is discarded
  2238. * and memory is free'd. Both channels must upload to prevent
  2239. * IOC from running in degraded mode.
  2240. */
  2241. static int
  2242. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  2243. {
  2244. u8 request[ioc->req_sz];
  2245. u8 reply[sizeof(FWUploadReply_t)];
  2246. FWUpload_t *prequest;
  2247. FWUploadReply_t *preply;
  2248. FWUploadTCSGE_t *ptcsge;
  2249. int sgeoffset;
  2250. u32 flagsLength;
  2251. int ii, sz, reply_sz;
  2252. int cmdStatus;
  2253. /* If the image size is 0, we are done.
  2254. */
  2255. if ((sz = ioc->facts.FWImageSize) == 0)
  2256. return 0;
  2257. mpt_alloc_fw_memory(ioc, sz);
  2258. dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2259. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2260. if (ioc->cached_fw == NULL) {
  2261. /* Major Failure.
  2262. */
  2263. return -ENOMEM;
  2264. }
  2265. prequest = (FWUpload_t *)&request;
  2266. preply = (FWUploadReply_t *)&reply;
  2267. /* Destination... */
  2268. memset(prequest, 0, ioc->req_sz);
  2269. reply_sz = sizeof(reply);
  2270. memset(preply, 0, reply_sz);
  2271. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  2272. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  2273. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  2274. ptcsge->DetailsLength = 12;
  2275. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  2276. ptcsge->ImageSize = cpu_to_le32(sz);
  2277. sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
  2278. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  2279. mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
  2280. sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
  2281. dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
  2282. prequest, sgeoffset));
  2283. DBG_DUMP_FW_REQUEST_FRAME(prequest)
  2284. ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
  2285. reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
  2286. dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
  2287. cmdStatus = -EFAULT;
  2288. if (ii == 0) {
  2289. /* Handshake transfer was complete and successful.
  2290. * Check the Reply Frame.
  2291. */
  2292. int status, transfer_sz;
  2293. status = le16_to_cpu(preply->IOCStatus);
  2294. if (status == MPI_IOCSTATUS_SUCCESS) {
  2295. transfer_sz = le32_to_cpu(preply->ActualImageSize);
  2296. if (transfer_sz == sz)
  2297. cmdStatus = 0;
  2298. }
  2299. }
  2300. dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
  2301. ioc->name, cmdStatus));
  2302. if (cmdStatus) {
  2303. ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
  2304. ioc->name));
  2305. mpt_free_fw_memory(ioc);
  2306. }
  2307. return cmdStatus;
  2308. }
  2309. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2310. /*
  2311. * mpt_downloadboot - DownloadBoot code
  2312. * @ioc: Pointer to MPT_ADAPTER structure
  2313. * @flag: Specify which part of IOC memory is to be uploaded.
  2314. * @sleepFlag: Specifies whether the process can sleep
  2315. *
  2316. * FwDownloadBoot requires Programmed IO access.
  2317. *
  2318. * Returns 0 for success
  2319. * -1 FW Image size is 0
  2320. * -2 No valid cached_fw Pointer
  2321. * <0 for fw upload failure.
  2322. */
  2323. static int
  2324. mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
  2325. {
  2326. MpiFwHeader_t *pFwHeader;
  2327. MpiExtImageHeader_t *pExtImage;
  2328. u32 fwSize;
  2329. u32 diag0val;
  2330. int count;
  2331. u32 *ptrFw;
  2332. u32 diagRwData;
  2333. u32 nextImage;
  2334. u32 load_addr;
  2335. u32 ioc_state=0;
  2336. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
  2337. ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
  2338. if ( ioc->facts.FWImageSize == 0 )
  2339. return -1;
  2340. if (ioc->cached_fw == NULL)
  2341. return -2;
  2342. /* prevent a second downloadboot and memory free with alt_ioc */
  2343. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  2344. ioc->alt_ioc->cached_fw = NULL;
  2345. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2346. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2347. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2348. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2349. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2350. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2351. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  2352. /* wait 1 msec */
  2353. if (sleepFlag == CAN_SLEEP) {
  2354. msleep_interruptible(1);
  2355. } else {
  2356. mdelay (1);
  2357. }
  2358. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2359. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2360. for (count = 0; count < 30; count ++) {
  2361. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2362. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2363. ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
  2364. ioc->name, count));
  2365. break;
  2366. }
  2367. /* wait 1 sec */
  2368. if (sleepFlag == CAN_SLEEP) {
  2369. msleep_interruptible (1000);
  2370. } else {
  2371. mdelay (1000);
  2372. }
  2373. }
  2374. if ( count == 30 ) {
  2375. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
  2376. ioc->name, diag0val));
  2377. return -3;
  2378. }
  2379. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2380. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2381. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2382. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2383. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2384. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2385. /* Set the DiagRwEn and Disable ARM bits */
  2386. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  2387. pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
  2388. fwSize = (pFwHeader->ImageSize + 3)/4;
  2389. ptrFw = (u32 *) pFwHeader;
  2390. /* Write the LoadStartAddress to the DiagRw Address Register
  2391. * using Programmed IO
  2392. */
  2393. if (ioc->errata_flag_1064)
  2394. pci_enable_io_access(ioc->pcidev);
  2395. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  2396. ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
  2397. ioc->name, pFwHeader->LoadStartAddress));
  2398. ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
  2399. ioc->name, fwSize*4, ptrFw));
  2400. while (fwSize--) {
  2401. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2402. }
  2403. nextImage = pFwHeader->NextImageHeaderOffset;
  2404. while (nextImage) {
  2405. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  2406. load_addr = pExtImage->LoadStartAddress;
  2407. fwSize = (pExtImage->ImageSize + 3) >> 2;
  2408. ptrFw = (u32 *)pExtImage;
  2409. ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
  2410. ioc->name, fwSize*4, ptrFw, load_addr));
  2411. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  2412. while (fwSize--) {
  2413. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2414. }
  2415. nextImage = pExtImage->NextImageHeaderOffset;
  2416. }
  2417. /* Write the IopResetVectorRegAddr */
  2418. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  2419. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  2420. /* Write the IopResetVectorValue */
  2421. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  2422. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  2423. /* Clear the internal flash bad bit - autoincrementing register,
  2424. * so must do two writes.
  2425. */
  2426. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2427. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  2428. diagRwData |= 0x4000000;
  2429. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2430. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  2431. if (ioc->errata_flag_1064)
  2432. pci_disable_io_access(ioc->pcidev);
  2433. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2434. ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
  2435. ioc->name, diag0val));
  2436. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
  2437. ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
  2438. ioc->name, diag0val));
  2439. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2440. /* Write 0xFF to reset the sequencer */
  2441. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2442. for (count=0; count<HZ*20; count++) {
  2443. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  2444. ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
  2445. ioc->name, count, ioc_state));
  2446. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  2447. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
  2448. ioc->name));
  2449. return -EFAULT;
  2450. }
  2451. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
  2452. ioc->name));
  2453. return 0;
  2454. }
  2455. if (sleepFlag == CAN_SLEEP) {
  2456. msleep_interruptible (10);
  2457. } else {
  2458. mdelay (10);
  2459. }
  2460. }
  2461. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
  2462. ioc->name, ioc_state));
  2463. return -EFAULT;
  2464. }
  2465. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2466. /*
  2467. * KickStart - Perform hard reset of MPT adapter.
  2468. * @ioc: Pointer to MPT_ADAPTER structure
  2469. * @force: Force hard reset
  2470. * @sleepFlag: Specifies whether the process can sleep
  2471. *
  2472. * This routine places MPT adapter in diagnostic mode via the
  2473. * WriteSequence register, and then performs a hard reset of adapter
  2474. * via the Diagnostic register.
  2475. *
  2476. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  2477. * or NO_SLEEP (interrupt thread, use mdelay)
  2478. * force - 1 if doorbell active, board fault state
  2479. * board operational, IOC_RECOVERY or
  2480. * IOC_BRINGUP and there is an alt_ioc.
  2481. * 0 else
  2482. *
  2483. * Returns:
  2484. * 1 - hard reset, READY
  2485. * 0 - no reset due to History bit, READY
  2486. * -1 - no reset due to History bit but not READY
  2487. * OR reset but failed to come READY
  2488. * -2 - no reset, could not enter DIAG mode
  2489. * -3 - reset but bad FW bit
  2490. */
  2491. static int
  2492. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2493. {
  2494. int hard_reset_done = 0;
  2495. u32 ioc_state=0;
  2496. int cnt,cntdn;
  2497. dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
  2498. if (ioc->bus_type == SCSI) {
  2499. /* Always issue a Msg Unit Reset first. This will clear some
  2500. * SCSI bus hang conditions.
  2501. */
  2502. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  2503. if (sleepFlag == CAN_SLEEP) {
  2504. msleep_interruptible (1000);
  2505. } else {
  2506. mdelay (1000);
  2507. }
  2508. }
  2509. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  2510. if (hard_reset_done < 0)
  2511. return hard_reset_done;
  2512. dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
  2513. ioc->name));
  2514. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  2515. for (cnt=0; cnt<cntdn; cnt++) {
  2516. ioc_state = mpt_GetIocState(ioc, 1);
  2517. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  2518. dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
  2519. ioc->name, cnt));
  2520. return hard_reset_done;
  2521. }
  2522. if (sleepFlag == CAN_SLEEP) {
  2523. msleep_interruptible (10);
  2524. } else {
  2525. mdelay (10);
  2526. }
  2527. }
  2528. printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  2529. ioc->name, ioc_state);
  2530. return -1;
  2531. }
  2532. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2533. /*
  2534. * mpt_diag_reset - Perform hard reset of the adapter.
  2535. * @ioc: Pointer to MPT_ADAPTER structure
  2536. * @ignore: Set if to honor and clear to ignore
  2537. * the reset history bit
  2538. * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
  2539. * else set to NO_SLEEP (use mdelay instead)
  2540. *
  2541. * This routine places the adapter in diagnostic mode via the
  2542. * WriteSequence register and then performs a hard reset of adapter
  2543. * via the Diagnostic register. Adapter should be in ready state
  2544. * upon successful completion.
  2545. *
  2546. * Returns: 1 hard reset successful
  2547. * 0 no reset performed because reset history bit set
  2548. * -2 enabling diagnostic mode failed
  2549. * -3 diagnostic reset failed
  2550. */
  2551. static int
  2552. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  2553. {
  2554. u32 diag0val;
  2555. u32 doorbell;
  2556. int hard_reset_done = 0;
  2557. int count = 0;
  2558. #ifdef MPT_DEBUG
  2559. u32 diag1val = 0;
  2560. #endif
  2561. /* Clear any existing interrupts */
  2562. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2563. /* Use "Diagnostic reset" method! (only thing available!) */
  2564. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2565. #ifdef MPT_DEBUG
  2566. if (ioc->alt_ioc)
  2567. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2568. dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  2569. ioc->name, diag0val, diag1val));
  2570. #endif
  2571. /* Do the reset if we are told to ignore the reset history
  2572. * or if the reset history is 0
  2573. */
  2574. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  2575. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2576. /* Write magic sequence to WriteSequence register
  2577. * Loop until in diagnostic mode
  2578. */
  2579. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2580. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2581. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2582. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2583. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2584. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2585. /* wait 100 msec */
  2586. if (sleepFlag == CAN_SLEEP) {
  2587. msleep_interruptible (100);
  2588. } else {
  2589. mdelay (100);
  2590. }
  2591. count++;
  2592. if (count > 20) {
  2593. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2594. ioc->name, diag0val);
  2595. return -2;
  2596. }
  2597. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2598. dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  2599. ioc->name, diag0val));
  2600. }
  2601. #ifdef MPT_DEBUG
  2602. if (ioc->alt_ioc)
  2603. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2604. dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  2605. ioc->name, diag0val, diag1val));
  2606. #endif
  2607. /*
  2608. * Disable the ARM (Bug fix)
  2609. *
  2610. */
  2611. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  2612. mdelay (1);
  2613. /*
  2614. * Now hit the reset bit in the Diagnostic register
  2615. * (THE BIG HAMMER!) (Clears DRWE bit).
  2616. */
  2617. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2618. hard_reset_done = 1;
  2619. dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
  2620. ioc->name));
  2621. /*
  2622. * Call each currently registered protocol IOC reset handler
  2623. * with pre-reset indication.
  2624. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  2625. * MptResetHandlers[] registered yet.
  2626. */
  2627. {
  2628. int ii;
  2629. int r = 0;
  2630. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  2631. if (MptResetHandlers[ii]) {
  2632. dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
  2633. ioc->name, ii));
  2634. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
  2635. if (ioc->alt_ioc) {
  2636. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
  2637. ioc->name, ioc->alt_ioc->name, ii));
  2638. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
  2639. }
  2640. }
  2641. }
  2642. /* FIXME? Examine results here? */
  2643. }
  2644. if (ioc->cached_fw) {
  2645. /* If the DownloadBoot operation fails, the
  2646. * IOC will be left unusable. This is a fatal error
  2647. * case. _diag_reset will return < 0
  2648. */
  2649. for (count = 0; count < 30; count ++) {
  2650. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2651. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2652. break;
  2653. }
  2654. /* wait 1 sec */
  2655. if (sleepFlag == CAN_SLEEP) {
  2656. ssleep(1);
  2657. } else {
  2658. mdelay (1000);
  2659. }
  2660. }
  2661. if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
  2662. printk(KERN_WARNING MYNAM
  2663. ": firmware downloadboot failure (%d)!\n", count);
  2664. }
  2665. } else {
  2666. /* Wait for FW to reload and for board
  2667. * to go to the READY state.
  2668. * Maximum wait is 60 seconds.
  2669. * If fail, no error will check again
  2670. * with calling program.
  2671. */
  2672. for (count = 0; count < 60; count ++) {
  2673. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  2674. doorbell &= MPI_IOC_STATE_MASK;
  2675. if (doorbell == MPI_IOC_STATE_READY) {
  2676. break;
  2677. }
  2678. /* wait 1 sec */
  2679. if (sleepFlag == CAN_SLEEP) {
  2680. msleep_interruptible (1000);
  2681. } else {
  2682. mdelay (1000);
  2683. }
  2684. }
  2685. }
  2686. }
  2687. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2688. #ifdef MPT_DEBUG
  2689. if (ioc->alt_ioc)
  2690. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2691. dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  2692. ioc->name, diag0val, diag1val));
  2693. #endif
  2694. /* Clear RESET_HISTORY bit! Place board in the
  2695. * diagnostic mode to update the diag register.
  2696. */
  2697. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2698. count = 0;
  2699. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2700. /* Write magic sequence to WriteSequence register
  2701. * Loop until in diagnostic mode
  2702. */
  2703. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2704. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2705. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2706. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2707. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2708. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2709. /* wait 100 msec */
  2710. if (sleepFlag == CAN_SLEEP) {
  2711. msleep_interruptible (100);
  2712. } else {
  2713. mdelay (100);
  2714. }
  2715. count++;
  2716. if (count > 20) {
  2717. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2718. ioc->name, diag0val);
  2719. break;
  2720. }
  2721. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2722. }
  2723. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  2724. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2725. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2726. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  2727. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  2728. ioc->name);
  2729. }
  2730. /* Disable Diagnostic Mode
  2731. */
  2732. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  2733. /* Check FW reload status flags.
  2734. */
  2735. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2736. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  2737. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  2738. ioc->name, diag0val);
  2739. return -3;
  2740. }
  2741. #ifdef MPT_DEBUG
  2742. if (ioc->alt_ioc)
  2743. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2744. dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  2745. ioc->name, diag0val, diag1val));
  2746. #endif
  2747. /*
  2748. * Reset flag that says we've enabled event notification
  2749. */
  2750. ioc->facts.EventState = 0;
  2751. if (ioc->alt_ioc)
  2752. ioc->alt_ioc->facts.EventState = 0;
  2753. return hard_reset_done;
  2754. }
  2755. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2756. /*
  2757. * SendIocReset - Send IOCReset request to MPT adapter.
  2758. * @ioc: Pointer to MPT_ADAPTER structure
  2759. * @reset_type: reset type, expected values are
  2760. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  2761. *
  2762. * Send IOCReset request to the MPT adapter.
  2763. *
  2764. * Returns 0 for success, non-zero for failure.
  2765. */
  2766. static int
  2767. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  2768. {
  2769. int r;
  2770. u32 state;
  2771. int cntdn, count;
  2772. drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
  2773. ioc->name, reset_type));
  2774. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  2775. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  2776. return r;
  2777. /* FW ACK'd request, wait for READY state
  2778. */
  2779. count = 0;
  2780. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  2781. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  2782. cntdn--;
  2783. count++;
  2784. if (!cntdn) {
  2785. if (sleepFlag != CAN_SLEEP)
  2786. count *= 10;
  2787. printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
  2788. ioc->name, (int)((count+5)/HZ));
  2789. return -ETIME;
  2790. }
  2791. if (sleepFlag == CAN_SLEEP) {
  2792. msleep_interruptible(1);
  2793. } else {
  2794. mdelay (1); /* 1 msec delay */
  2795. }
  2796. }
  2797. /* TODO!
  2798. * Cleanup all event stuff for this IOC; re-issue EventNotification
  2799. * request if needed.
  2800. */
  2801. if (ioc->facts.Function)
  2802. ioc->facts.EventState = 0;
  2803. return 0;
  2804. }
  2805. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2806. /*
  2807. * initChainBuffers - Allocate memory for and initialize
  2808. * chain buffers, chain buffer control arrays and spinlock.
  2809. * @hd: Pointer to MPT_SCSI_HOST structure
  2810. * @init: If set, initialize the spin lock.
  2811. */
  2812. static int
  2813. initChainBuffers(MPT_ADAPTER *ioc)
  2814. {
  2815. u8 *mem;
  2816. int sz, ii, num_chain;
  2817. int scale, num_sge, numSGE;
  2818. /* ReqToChain size must equal the req_depth
  2819. * index = req_idx
  2820. */
  2821. if (ioc->ReqToChain == NULL) {
  2822. sz = ioc->req_depth * sizeof(int);
  2823. mem = kmalloc(sz, GFP_ATOMIC);
  2824. if (mem == NULL)
  2825. return -1;
  2826. ioc->ReqToChain = (int *) mem;
  2827. dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
  2828. ioc->name, mem, sz));
  2829. mem = kmalloc(sz, GFP_ATOMIC);
  2830. if (mem == NULL)
  2831. return -1;
  2832. ioc->RequestNB = (int *) mem;
  2833. dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
  2834. ioc->name, mem, sz));
  2835. }
  2836. for (ii = 0; ii < ioc->req_depth; ii++) {
  2837. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  2838. }
  2839. /* ChainToChain size must equal the total number
  2840. * of chain buffers to be allocated.
  2841. * index = chain_idx
  2842. *
  2843. * Calculate the number of chain buffers needed(plus 1) per I/O
  2844. * then multiply the the maximum number of simultaneous cmds
  2845. *
  2846. * num_sge = num sge in request frame + last chain buffer
  2847. * scale = num sge per chain buffer if no chain element
  2848. */
  2849. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  2850. if (sizeof(dma_addr_t) == sizeof(u64))
  2851. num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2852. else
  2853. num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2854. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2855. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2856. (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2857. } else {
  2858. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2859. (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2860. }
  2861. dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
  2862. ioc->name, num_sge, numSGE));
  2863. if ( numSGE > MPT_SCSI_SG_DEPTH )
  2864. numSGE = MPT_SCSI_SG_DEPTH;
  2865. num_chain = 1;
  2866. while (numSGE - num_sge > 0) {
  2867. num_chain++;
  2868. num_sge += (scale - 1);
  2869. }
  2870. num_chain++;
  2871. dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
  2872. ioc->name, numSGE, num_sge, num_chain));
  2873. if (ioc->bus_type == SCSI)
  2874. num_chain *= MPT_SCSI_CAN_QUEUE;
  2875. else
  2876. num_chain *= MPT_FC_CAN_QUEUE;
  2877. ioc->num_chain = num_chain;
  2878. sz = num_chain * sizeof(int);
  2879. if (ioc->ChainToChain == NULL) {
  2880. mem = kmalloc(sz, GFP_ATOMIC);
  2881. if (mem == NULL)
  2882. return -1;
  2883. ioc->ChainToChain = (int *) mem;
  2884. dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
  2885. ioc->name, mem, sz));
  2886. } else {
  2887. mem = (u8 *) ioc->ChainToChain;
  2888. }
  2889. memset(mem, 0xFF, sz);
  2890. return num_chain;
  2891. }
  2892. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2893. /*
  2894. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  2895. * @ioc: Pointer to MPT_ADAPTER structure
  2896. *
  2897. * This routine allocates memory for the MPT reply and request frame
  2898. * pools (if necessary), and primes the IOC reply FIFO with
  2899. * reply frames.
  2900. *
  2901. * Returns 0 for success, non-zero for failure.
  2902. */
  2903. static int
  2904. PrimeIocFifos(MPT_ADAPTER *ioc)
  2905. {
  2906. MPT_FRAME_HDR *mf;
  2907. unsigned long flags;
  2908. dma_addr_t alloc_dma;
  2909. u8 *mem;
  2910. int i, reply_sz, sz, total_size, num_chain;
  2911. /* Prime reply FIFO... */
  2912. if (ioc->reply_frames == NULL) {
  2913. if ( (num_chain = initChainBuffers(ioc)) < 0)
  2914. return -1;
  2915. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  2916. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  2917. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2918. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
  2919. ioc->name, reply_sz, reply_sz));
  2920. sz = (ioc->req_sz * ioc->req_depth);
  2921. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  2922. ioc->name, ioc->req_sz, ioc->req_depth));
  2923. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
  2924. ioc->name, sz, sz));
  2925. total_size += sz;
  2926. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  2927. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  2928. ioc->name, ioc->req_sz, num_chain));
  2929. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  2930. ioc->name, sz, sz, num_chain));
  2931. total_size += sz;
  2932. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  2933. if (mem == NULL) {
  2934. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  2935. ioc->name);
  2936. goto out_fail;
  2937. }
  2938. dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  2939. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  2940. memset(mem, 0, total_size);
  2941. ioc->alloc_total += total_size;
  2942. ioc->alloc = mem;
  2943. ioc->alloc_dma = alloc_dma;
  2944. ioc->alloc_sz = total_size;
  2945. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  2946. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  2947. alloc_dma += reply_sz;
  2948. mem += reply_sz;
  2949. /* Request FIFO - WE manage this! */
  2950. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  2951. ioc->req_frames_dma = alloc_dma;
  2952. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
  2953. ioc->name, mem, (void *)(ulong)alloc_dma));
  2954. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  2955. #if defined(CONFIG_MTRR) && 0
  2956. /*
  2957. * Enable Write Combining MTRR for IOC's memory region.
  2958. * (at least as much as we can; "size and base must be
  2959. * multiples of 4 kiB"
  2960. */
  2961. ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
  2962. sz,
  2963. MTRR_TYPE_WRCOMB, 1);
  2964. dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
  2965. ioc->name, ioc->req_frames_dma, sz));
  2966. #endif
  2967. for (i = 0; i < ioc->req_depth; i++) {
  2968. alloc_dma += ioc->req_sz;
  2969. mem += ioc->req_sz;
  2970. }
  2971. ioc->ChainBuffer = mem;
  2972. ioc->ChainBufferDMA = alloc_dma;
  2973. dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
  2974. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  2975. /* Initialize the free chain Q.
  2976. */
  2977. INIT_LIST_HEAD(&ioc->FreeChainQ);
  2978. /* Post the chain buffers to the FreeChainQ.
  2979. */
  2980. mem = (u8 *)ioc->ChainBuffer;
  2981. for (i=0; i < num_chain; i++) {
  2982. mf = (MPT_FRAME_HDR *) mem;
  2983. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  2984. mem += ioc->req_sz;
  2985. }
  2986. /* Initialize Request frames linked list
  2987. */
  2988. alloc_dma = ioc->req_frames_dma;
  2989. mem = (u8 *) ioc->req_frames;
  2990. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2991. INIT_LIST_HEAD(&ioc->FreeQ);
  2992. for (i = 0; i < ioc->req_depth; i++) {
  2993. mf = (MPT_FRAME_HDR *) mem;
  2994. /* Queue REQUESTs *internally*! */
  2995. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  2996. mem += ioc->req_sz;
  2997. }
  2998. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2999. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3000. ioc->sense_buf_pool =
  3001. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  3002. if (ioc->sense_buf_pool == NULL) {
  3003. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  3004. ioc->name);
  3005. goto out_fail;
  3006. }
  3007. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  3008. ioc->alloc_total += sz;
  3009. dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
  3010. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  3011. }
  3012. /* Post Reply frames to FIFO
  3013. */
  3014. alloc_dma = ioc->alloc_dma;
  3015. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
  3016. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3017. for (i = 0; i < ioc->reply_depth; i++) {
  3018. /* Write each address to the IOC! */
  3019. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  3020. alloc_dma += ioc->reply_sz;
  3021. }
  3022. return 0;
  3023. out_fail:
  3024. if (ioc->alloc != NULL) {
  3025. sz = ioc->alloc_sz;
  3026. pci_free_consistent(ioc->pcidev,
  3027. sz,
  3028. ioc->alloc, ioc->alloc_dma);
  3029. ioc->reply_frames = NULL;
  3030. ioc->req_frames = NULL;
  3031. ioc->alloc_total -= sz;
  3032. }
  3033. if (ioc->sense_buf_pool != NULL) {
  3034. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3035. pci_free_consistent(ioc->pcidev,
  3036. sz,
  3037. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  3038. ioc->sense_buf_pool = NULL;
  3039. }
  3040. return -1;
  3041. }
  3042. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3043. /**
  3044. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  3045. * from IOC via doorbell handshake method.
  3046. * @ioc: Pointer to MPT_ADAPTER structure
  3047. * @reqBytes: Size of the request in bytes
  3048. * @req: Pointer to MPT request frame
  3049. * @replyBytes: Expected size of the reply in bytes
  3050. * @u16reply: Pointer to area where reply should be written
  3051. * @maxwait: Max wait time for a reply (in seconds)
  3052. * @sleepFlag: Specifies whether the process can sleep
  3053. *
  3054. * NOTES: It is the callers responsibility to byte-swap fields in the
  3055. * request which are greater than 1 byte in size. It is also the
  3056. * callers responsibility to byte-swap response fields which are
  3057. * greater than 1 byte in size.
  3058. *
  3059. * Returns 0 for success, non-zero for failure.
  3060. */
  3061. static int
  3062. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  3063. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  3064. {
  3065. MPIDefaultReply_t *mptReply;
  3066. int failcnt = 0;
  3067. int t;
  3068. /*
  3069. * Get ready to cache a handshake reply
  3070. */
  3071. ioc->hs_reply_idx = 0;
  3072. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3073. mptReply->MsgLength = 0;
  3074. /*
  3075. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  3076. * then tell IOC that we want to handshake a request of N words.
  3077. * (WRITE u32val to Doorbell reg).
  3078. */
  3079. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3080. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  3081. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  3082. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  3083. /*
  3084. * Wait for IOC's doorbell handshake int
  3085. */
  3086. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3087. failcnt++;
  3088. dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  3089. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3090. /* Read doorbell and check for active bit */
  3091. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  3092. return -1;
  3093. /*
  3094. * Clear doorbell int (WRITE 0 to IntStatus reg),
  3095. * then wait for IOC to ACKnowledge that it's ready for
  3096. * our handshake request.
  3097. */
  3098. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3099. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3100. failcnt++;
  3101. if (!failcnt) {
  3102. int ii;
  3103. u8 *req_as_bytes = (u8 *) req;
  3104. /*
  3105. * Stuff request words via doorbell handshake,
  3106. * with ACK from IOC for each.
  3107. */
  3108. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  3109. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  3110. (req_as_bytes[(ii*4) + 1] << 8) |
  3111. (req_as_bytes[(ii*4) + 2] << 16) |
  3112. (req_as_bytes[(ii*4) + 3] << 24));
  3113. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  3114. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3115. failcnt++;
  3116. }
  3117. dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
  3118. DBG_DUMP_REQUEST_FRAME_HDR(req)
  3119. dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
  3120. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  3121. /*
  3122. * Wait for completion of doorbell handshake reply from the IOC
  3123. */
  3124. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  3125. failcnt++;
  3126. dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
  3127. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  3128. /*
  3129. * Copy out the cached reply...
  3130. */
  3131. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  3132. u16reply[ii] = ioc->hs_reply[ii];
  3133. } else {
  3134. return -99;
  3135. }
  3136. return -failcnt;
  3137. }
  3138. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3139. /*
  3140. * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
  3141. * in it's IntStatus register.
  3142. * @ioc: Pointer to MPT_ADAPTER structure
  3143. * @howlong: How long to wait (in seconds)
  3144. * @sleepFlag: Specifies whether the process can sleep
  3145. *
  3146. * This routine waits (up to ~2 seconds max) for IOC doorbell
  3147. * handshake ACKnowledge.
  3148. *
  3149. * Returns a negative value on failure, else wait loop count.
  3150. */
  3151. static int
  3152. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3153. {
  3154. int cntdn;
  3155. int count = 0;
  3156. u32 intstat=0;
  3157. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3158. if (sleepFlag == CAN_SLEEP) {
  3159. while (--cntdn) {
  3160. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3161. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3162. break;
  3163. msleep_interruptible (1);
  3164. count++;
  3165. }
  3166. } else {
  3167. while (--cntdn) {
  3168. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3169. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3170. break;
  3171. mdelay (1);
  3172. count++;
  3173. }
  3174. }
  3175. if (cntdn) {
  3176. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
  3177. ioc->name, count));
  3178. return count;
  3179. }
  3180. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  3181. ioc->name, count, intstat);
  3182. return -1;
  3183. }
  3184. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3185. /*
  3186. * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
  3187. * in it's IntStatus register.
  3188. * @ioc: Pointer to MPT_ADAPTER structure
  3189. * @howlong: How long to wait (in seconds)
  3190. * @sleepFlag: Specifies whether the process can sleep
  3191. *
  3192. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
  3193. *
  3194. * Returns a negative value on failure, else wait loop count.
  3195. */
  3196. static int
  3197. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3198. {
  3199. int cntdn;
  3200. int count = 0;
  3201. u32 intstat=0;
  3202. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3203. if (sleepFlag == CAN_SLEEP) {
  3204. while (--cntdn) {
  3205. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3206. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3207. break;
  3208. msleep_interruptible(1);
  3209. count++;
  3210. }
  3211. } else {
  3212. while (--cntdn) {
  3213. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3214. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3215. break;
  3216. mdelay(1);
  3217. count++;
  3218. }
  3219. }
  3220. if (cntdn) {
  3221. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  3222. ioc->name, count, howlong));
  3223. return count;
  3224. }
  3225. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  3226. ioc->name, count, intstat);
  3227. return -1;
  3228. }
  3229. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3230. /*
  3231. * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
  3232. * @ioc: Pointer to MPT_ADAPTER structure
  3233. * @howlong: How long to wait (in seconds)
  3234. * @sleepFlag: Specifies whether the process can sleep
  3235. *
  3236. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  3237. * Reply is cached to IOC private area large enough to hold a maximum
  3238. * of 128 bytes of reply data.
  3239. *
  3240. * Returns a negative value on failure, else size of reply in WORDS.
  3241. */
  3242. static int
  3243. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3244. {
  3245. int u16cnt = 0;
  3246. int failcnt = 0;
  3247. int t;
  3248. u16 *hs_reply = ioc->hs_reply;
  3249. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3250. u16 hword;
  3251. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  3252. /*
  3253. * Get first two u16's so we can look at IOC's intended reply MsgLength
  3254. */
  3255. u16cnt=0;
  3256. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  3257. failcnt++;
  3258. } else {
  3259. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3260. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3261. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3262. failcnt++;
  3263. else {
  3264. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3265. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3266. }
  3267. }
  3268. dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  3269. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  3270. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3271. /*
  3272. * If no error (and IOC said MsgLength is > 0), piece together
  3273. * reply 16 bits at a time.
  3274. */
  3275. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  3276. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3277. failcnt++;
  3278. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3279. /* don't overflow our IOC hs_reply[] buffer! */
  3280. if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
  3281. hs_reply[u16cnt] = hword;
  3282. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3283. }
  3284. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3285. failcnt++;
  3286. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3287. if (failcnt) {
  3288. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  3289. ioc->name);
  3290. return -failcnt;
  3291. }
  3292. #if 0
  3293. else if (u16cnt != (2 * mptReply->MsgLength)) {
  3294. return -101;
  3295. }
  3296. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  3297. return -102;
  3298. }
  3299. #endif
  3300. dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
  3301. DBG_DUMP_REPLY_FRAME(mptReply)
  3302. dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  3303. ioc->name, t, u16cnt/2));
  3304. return u16cnt/2;
  3305. }
  3306. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3307. /*
  3308. * GetLanConfigPages - Fetch LANConfig pages.
  3309. * @ioc: Pointer to MPT_ADAPTER structure
  3310. *
  3311. * Return: 0 for success
  3312. * -ENOMEM if no memory available
  3313. * -EPERM if not allowed due to ISR context
  3314. * -EAGAIN if no msg frames currently available
  3315. * -EFAULT for non-successful reply or no reply (timeout)
  3316. */
  3317. static int
  3318. GetLanConfigPages(MPT_ADAPTER *ioc)
  3319. {
  3320. ConfigPageHeader_t hdr;
  3321. CONFIGPARMS cfg;
  3322. LANPage0_t *ppage0_alloc;
  3323. dma_addr_t page0_dma;
  3324. LANPage1_t *ppage1_alloc;
  3325. dma_addr_t page1_dma;
  3326. int rc = 0;
  3327. int data_sz;
  3328. int copy_sz;
  3329. /* Get LAN Page 0 header */
  3330. hdr.PageVersion = 0;
  3331. hdr.PageLength = 0;
  3332. hdr.PageNumber = 0;
  3333. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3334. cfg.hdr = &hdr;
  3335. cfg.physAddr = -1;
  3336. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3337. cfg.dir = 0;
  3338. cfg.pageAddr = 0;
  3339. cfg.timeout = 0;
  3340. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3341. return rc;
  3342. if (hdr.PageLength > 0) {
  3343. data_sz = hdr.PageLength * 4;
  3344. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3345. rc = -ENOMEM;
  3346. if (ppage0_alloc) {
  3347. memset((u8 *)ppage0_alloc, 0, data_sz);
  3348. cfg.physAddr = page0_dma;
  3349. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3350. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3351. /* save the data */
  3352. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  3353. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  3354. }
  3355. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3356. /* FIXME!
  3357. * Normalize endianness of structure data,
  3358. * by byte-swapping all > 1 byte fields!
  3359. */
  3360. }
  3361. if (rc)
  3362. return rc;
  3363. }
  3364. /* Get LAN Page 1 header */
  3365. hdr.PageVersion = 0;
  3366. hdr.PageLength = 0;
  3367. hdr.PageNumber = 1;
  3368. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3369. cfg.hdr = &hdr;
  3370. cfg.physAddr = -1;
  3371. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3372. cfg.dir = 0;
  3373. cfg.pageAddr = 0;
  3374. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3375. return rc;
  3376. if (hdr.PageLength == 0)
  3377. return 0;
  3378. data_sz = hdr.PageLength * 4;
  3379. rc = -ENOMEM;
  3380. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  3381. if (ppage1_alloc) {
  3382. memset((u8 *)ppage1_alloc, 0, data_sz);
  3383. cfg.physAddr = page1_dma;
  3384. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3385. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3386. /* save the data */
  3387. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  3388. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  3389. }
  3390. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  3391. /* FIXME!
  3392. * Normalize endianness of structure data,
  3393. * by byte-swapping all > 1 byte fields!
  3394. */
  3395. }
  3396. return rc;
  3397. }
  3398. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3399. /*
  3400. * GetFcPortPage0 - Fetch FCPort config Page0.
  3401. * @ioc: Pointer to MPT_ADAPTER structure
  3402. * @portnum: IOC Port number
  3403. *
  3404. * Return: 0 for success
  3405. * -ENOMEM if no memory available
  3406. * -EPERM if not allowed due to ISR context
  3407. * -EAGAIN if no msg frames currently available
  3408. * -EFAULT for non-successful reply or no reply (timeout)
  3409. */
  3410. static int
  3411. GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
  3412. {
  3413. ConfigPageHeader_t hdr;
  3414. CONFIGPARMS cfg;
  3415. FCPortPage0_t *ppage0_alloc;
  3416. FCPortPage0_t *pp0dest;
  3417. dma_addr_t page0_dma;
  3418. int data_sz;
  3419. int copy_sz;
  3420. int rc;
  3421. /* Get FCPort Page 0 header */
  3422. hdr.PageVersion = 0;
  3423. hdr.PageLength = 0;
  3424. hdr.PageNumber = 0;
  3425. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  3426. cfg.hdr = &hdr;
  3427. cfg.physAddr = -1;
  3428. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3429. cfg.dir = 0;
  3430. cfg.pageAddr = portnum;
  3431. cfg.timeout = 0;
  3432. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3433. return rc;
  3434. if (hdr.PageLength == 0)
  3435. return 0;
  3436. data_sz = hdr.PageLength * 4;
  3437. rc = -ENOMEM;
  3438. ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3439. if (ppage0_alloc) {
  3440. memset((u8 *)ppage0_alloc, 0, data_sz);
  3441. cfg.physAddr = page0_dma;
  3442. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3443. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3444. /* save the data */
  3445. pp0dest = &ioc->fc_port_page0[portnum];
  3446. copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
  3447. memcpy(pp0dest, ppage0_alloc, copy_sz);
  3448. /*
  3449. * Normalize endianness of structure data,
  3450. * by byte-swapping all > 1 byte fields!
  3451. */
  3452. pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
  3453. pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
  3454. pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
  3455. pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
  3456. pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
  3457. pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
  3458. pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
  3459. pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
  3460. pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
  3461. pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
  3462. pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
  3463. pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
  3464. pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
  3465. pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
  3466. pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
  3467. pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
  3468. }
  3469. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3470. }
  3471. return rc;
  3472. }
  3473. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3474. /*
  3475. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  3476. * @ioc: Pointer to MPT_ADAPTER structure
  3477. *
  3478. * Returns: 0 for success
  3479. * -ENOMEM if no memory available
  3480. * -EPERM if not allowed due to ISR context
  3481. * -EAGAIN if no msg frames currently available
  3482. * -EFAULT for non-successful reply or no reply (timeout)
  3483. */
  3484. static int
  3485. GetIoUnitPage2(MPT_ADAPTER *ioc)
  3486. {
  3487. ConfigPageHeader_t hdr;
  3488. CONFIGPARMS cfg;
  3489. IOUnitPage2_t *ppage_alloc;
  3490. dma_addr_t page_dma;
  3491. int data_sz;
  3492. int rc;
  3493. /* Get the page header */
  3494. hdr.PageVersion = 0;
  3495. hdr.PageLength = 0;
  3496. hdr.PageNumber = 2;
  3497. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  3498. cfg.hdr = &hdr;
  3499. cfg.physAddr = -1;
  3500. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3501. cfg.dir = 0;
  3502. cfg.pageAddr = 0;
  3503. cfg.timeout = 0;
  3504. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3505. return rc;
  3506. if (hdr.PageLength == 0)
  3507. return 0;
  3508. /* Read the config page */
  3509. data_sz = hdr.PageLength * 4;
  3510. rc = -ENOMEM;
  3511. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  3512. if (ppage_alloc) {
  3513. memset((u8 *)ppage_alloc, 0, data_sz);
  3514. cfg.physAddr = page_dma;
  3515. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3516. /* If Good, save data */
  3517. if ((rc = mpt_config(ioc, &cfg)) == 0)
  3518. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  3519. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  3520. }
  3521. return rc;
  3522. }
  3523. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3524. /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  3525. * @ioc: Pointer to a Adapter Strucutre
  3526. * @portnum: IOC port number
  3527. *
  3528. * Return: -EFAULT if read of config page header fails
  3529. * or if no nvram
  3530. * If read of SCSI Port Page 0 fails,
  3531. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3532. * Adapter settings: async, narrow
  3533. * Return 1
  3534. * If read of SCSI Port Page 2 fails,
  3535. * Adapter settings valid
  3536. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3537. * Return 1
  3538. * Else
  3539. * Both valid
  3540. * Return 0
  3541. * CHECK - what type of locking mechanisms should be used????
  3542. */
  3543. static int
  3544. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  3545. {
  3546. u8 *pbuf;
  3547. dma_addr_t buf_dma;
  3548. CONFIGPARMS cfg;
  3549. ConfigPageHeader_t header;
  3550. int ii;
  3551. int data, rc = 0;
  3552. /* Allocate memory
  3553. */
  3554. if (!ioc->spi_data.nvram) {
  3555. int sz;
  3556. u8 *mem;
  3557. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  3558. mem = kmalloc(sz, GFP_ATOMIC);
  3559. if (mem == NULL)
  3560. return -EFAULT;
  3561. ioc->spi_data.nvram = (int *) mem;
  3562. dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  3563. ioc->name, ioc->spi_data.nvram, sz));
  3564. }
  3565. /* Invalidate NVRAM information
  3566. */
  3567. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3568. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  3569. }
  3570. /* Read SPP0 header, allocate memory, then read page.
  3571. */
  3572. header.PageVersion = 0;
  3573. header.PageLength = 0;
  3574. header.PageNumber = 0;
  3575. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3576. cfg.hdr = &header;
  3577. cfg.physAddr = -1;
  3578. cfg.pageAddr = portnum;
  3579. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3580. cfg.dir = 0;
  3581. cfg.timeout = 0; /* use default */
  3582. if (mpt_config(ioc, &cfg) != 0)
  3583. return -EFAULT;
  3584. if (header.PageLength > 0) {
  3585. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3586. if (pbuf) {
  3587. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3588. cfg.physAddr = buf_dma;
  3589. if (mpt_config(ioc, &cfg) != 0) {
  3590. ioc->spi_data.maxBusWidth = MPT_NARROW;
  3591. ioc->spi_data.maxSyncOffset = 0;
  3592. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3593. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  3594. rc = 1;
  3595. } else {
  3596. /* Save the Port Page 0 data
  3597. */
  3598. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  3599. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  3600. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  3601. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  3602. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  3603. dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
  3604. ioc->name, pPP0->Capabilities));
  3605. }
  3606. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  3607. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  3608. if (data) {
  3609. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  3610. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  3611. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  3612. } else {
  3613. ioc->spi_data.maxSyncOffset = 0;
  3614. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3615. }
  3616. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  3617. /* Update the minSyncFactor based on bus type.
  3618. */
  3619. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  3620. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  3621. if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
  3622. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  3623. }
  3624. }
  3625. if (pbuf) {
  3626. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3627. }
  3628. }
  3629. }
  3630. /* SCSI Port Page 2 - Read the header then the page.
  3631. */
  3632. header.PageVersion = 0;
  3633. header.PageLength = 0;
  3634. header.PageNumber = 2;
  3635. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3636. cfg.hdr = &header;
  3637. cfg.physAddr = -1;
  3638. cfg.pageAddr = portnum;
  3639. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3640. cfg.dir = 0;
  3641. if (mpt_config(ioc, &cfg) != 0)
  3642. return -EFAULT;
  3643. if (header.PageLength > 0) {
  3644. /* Allocate memory and read SCSI Port Page 2
  3645. */
  3646. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3647. if (pbuf) {
  3648. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  3649. cfg.physAddr = buf_dma;
  3650. if (mpt_config(ioc, &cfg) != 0) {
  3651. /* Nvram data is left with INVALID mark
  3652. */
  3653. rc = 1;
  3654. } else {
  3655. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  3656. MpiDeviceInfo_t *pdevice = NULL;
  3657. /* Save the Port Page 2 data
  3658. * (reformat into a 32bit quantity)
  3659. */
  3660. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  3661. ioc->spi_data.PortFlags = data;
  3662. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3663. pdevice = &pPP2->DeviceSettings[ii];
  3664. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  3665. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  3666. ioc->spi_data.nvram[ii] = data;
  3667. }
  3668. }
  3669. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3670. }
  3671. }
  3672. /* Update Adapter limits with those from NVRAM
  3673. * Comment: Don't need to do this. Target performance
  3674. * parameters will never exceed the adapters limits.
  3675. */
  3676. return rc;
  3677. }
  3678. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3679. /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
  3680. * @ioc: Pointer to a Adapter Strucutre
  3681. * @portnum: IOC port number
  3682. *
  3683. * Return: -EFAULT if read of config page header fails
  3684. * or 0 if success.
  3685. */
  3686. static int
  3687. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  3688. {
  3689. CONFIGPARMS cfg;
  3690. ConfigPageHeader_t header;
  3691. /* Read the SCSI Device Page 1 header
  3692. */
  3693. header.PageVersion = 0;
  3694. header.PageLength = 0;
  3695. header.PageNumber = 1;
  3696. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3697. cfg.hdr = &header;
  3698. cfg.physAddr = -1;
  3699. cfg.pageAddr = portnum;
  3700. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3701. cfg.dir = 0;
  3702. cfg.timeout = 0;
  3703. if (mpt_config(ioc, &cfg) != 0)
  3704. return -EFAULT;
  3705. ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
  3706. ioc->spi_data.sdp1length = cfg.hdr->PageLength;
  3707. header.PageVersion = 0;
  3708. header.PageLength = 0;
  3709. header.PageNumber = 0;
  3710. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3711. if (mpt_config(ioc, &cfg) != 0)
  3712. return -EFAULT;
  3713. ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
  3714. ioc->spi_data.sdp0length = cfg.hdr->PageLength;
  3715. dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
  3716. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  3717. dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
  3718. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  3719. return 0;
  3720. }
  3721. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3722. /**
  3723. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  3724. * @ioc: Pointer to a Adapter Strucutre
  3725. * @portnum: IOC port number
  3726. *
  3727. * Return:
  3728. * 0 on success
  3729. * -EFAULT if read of config page header fails or data pointer not NULL
  3730. * -ENOMEM if pci_alloc failed
  3731. */
  3732. int
  3733. mpt_findImVolumes(MPT_ADAPTER *ioc)
  3734. {
  3735. IOCPage2_t *pIoc2;
  3736. u8 *mem;
  3737. ConfigPageIoc2RaidVol_t *pIocRv;
  3738. dma_addr_t ioc2_dma;
  3739. CONFIGPARMS cfg;
  3740. ConfigPageHeader_t header;
  3741. int jj;
  3742. int rc = 0;
  3743. int iocpage2sz;
  3744. u8 nVols, nPhys;
  3745. u8 vid, vbus, vioc;
  3746. /* Read IOCP2 header then the page.
  3747. */
  3748. header.PageVersion = 0;
  3749. header.PageLength = 0;
  3750. header.PageNumber = 2;
  3751. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3752. cfg.hdr = &header;
  3753. cfg.physAddr = -1;
  3754. cfg.pageAddr = 0;
  3755. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3756. cfg.dir = 0;
  3757. cfg.timeout = 0;
  3758. if (mpt_config(ioc, &cfg) != 0)
  3759. return -EFAULT;
  3760. if (header.PageLength == 0)
  3761. return -EFAULT;
  3762. iocpage2sz = header.PageLength * 4;
  3763. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  3764. if (!pIoc2)
  3765. return -ENOMEM;
  3766. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3767. cfg.physAddr = ioc2_dma;
  3768. if (mpt_config(ioc, &cfg) != 0)
  3769. goto done_and_free;
  3770. if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
  3771. mem = kmalloc(iocpage2sz, GFP_ATOMIC);
  3772. if (mem) {
  3773. ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
  3774. } else {
  3775. goto done_and_free;
  3776. }
  3777. }
  3778. memcpy(mem, (u8 *)pIoc2, iocpage2sz);
  3779. /* Identify RAID Volume Id's */
  3780. nVols = pIoc2->NumActiveVolumes;
  3781. if ( nVols == 0) {
  3782. /* No RAID Volume.
  3783. */
  3784. goto done_and_free;
  3785. } else {
  3786. /* At least 1 RAID Volume
  3787. */
  3788. pIocRv = pIoc2->RaidVolume;
  3789. ioc->spi_data.isRaid = 0;
  3790. for (jj = 0; jj < nVols; jj++, pIocRv++) {
  3791. vid = pIocRv->VolumeID;
  3792. vbus = pIocRv->VolumeBus;
  3793. vioc = pIocRv->VolumeIOC;
  3794. /* find the match
  3795. */
  3796. if (vbus == 0) {
  3797. ioc->spi_data.isRaid |= (1 << vid);
  3798. } else {
  3799. /* Error! Always bus 0
  3800. */
  3801. }
  3802. }
  3803. }
  3804. /* Identify Hidden Physical Disk Id's */
  3805. nPhys = pIoc2->NumActivePhysDisks;
  3806. if (nPhys == 0) {
  3807. /* No physical disks.
  3808. */
  3809. } else {
  3810. mpt_read_ioc_pg_3(ioc);
  3811. }
  3812. done_and_free:
  3813. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  3814. return rc;
  3815. }
  3816. int
  3817. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  3818. {
  3819. IOCPage3_t *pIoc3;
  3820. u8 *mem;
  3821. CONFIGPARMS cfg;
  3822. ConfigPageHeader_t header;
  3823. dma_addr_t ioc3_dma;
  3824. int iocpage3sz = 0;
  3825. /* Free the old page
  3826. */
  3827. if (ioc->spi_data.pIocPg3) {
  3828. kfree(ioc->spi_data.pIocPg3);
  3829. ioc->spi_data.pIocPg3 = NULL;
  3830. }
  3831. /* There is at least one physical disk.
  3832. * Read and save IOC Page 3
  3833. */
  3834. header.PageVersion = 0;
  3835. header.PageLength = 0;
  3836. header.PageNumber = 3;
  3837. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3838. cfg.hdr = &header;
  3839. cfg.physAddr = -1;
  3840. cfg.pageAddr = 0;
  3841. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3842. cfg.dir = 0;
  3843. cfg.timeout = 0;
  3844. if (mpt_config(ioc, &cfg) != 0)
  3845. return 0;
  3846. if (header.PageLength == 0)
  3847. return 0;
  3848. /* Read Header good, alloc memory
  3849. */
  3850. iocpage3sz = header.PageLength * 4;
  3851. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  3852. if (!pIoc3)
  3853. return 0;
  3854. /* Read the Page and save the data
  3855. * into malloc'd memory.
  3856. */
  3857. cfg.physAddr = ioc3_dma;
  3858. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3859. if (mpt_config(ioc, &cfg) == 0) {
  3860. mem = kmalloc(iocpage3sz, GFP_ATOMIC);
  3861. if (mem) {
  3862. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  3863. ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
  3864. }
  3865. }
  3866. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  3867. return 0;
  3868. }
  3869. static void
  3870. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  3871. {
  3872. IOCPage4_t *pIoc4;
  3873. CONFIGPARMS cfg;
  3874. ConfigPageHeader_t header;
  3875. dma_addr_t ioc4_dma;
  3876. int iocpage4sz;
  3877. /* Read and save IOC Page 4
  3878. */
  3879. header.PageVersion = 0;
  3880. header.PageLength = 0;
  3881. header.PageNumber = 4;
  3882. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3883. cfg.hdr = &header;
  3884. cfg.physAddr = -1;
  3885. cfg.pageAddr = 0;
  3886. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3887. cfg.dir = 0;
  3888. cfg.timeout = 0;
  3889. if (mpt_config(ioc, &cfg) != 0)
  3890. return;
  3891. if (header.PageLength == 0)
  3892. return;
  3893. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  3894. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  3895. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  3896. if (!pIoc4)
  3897. return;
  3898. } else {
  3899. ioc4_dma = ioc->spi_data.IocPg4_dma;
  3900. iocpage4sz = ioc->spi_data.IocPg4Sz;
  3901. }
  3902. /* Read the Page into dma memory.
  3903. */
  3904. cfg.physAddr = ioc4_dma;
  3905. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3906. if (mpt_config(ioc, &cfg) == 0) {
  3907. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  3908. ioc->spi_data.IocPg4_dma = ioc4_dma;
  3909. ioc->spi_data.IocPg4Sz = iocpage4sz;
  3910. } else {
  3911. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  3912. ioc->spi_data.pIocPg4 = NULL;
  3913. }
  3914. }
  3915. static void
  3916. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  3917. {
  3918. IOCPage1_t *pIoc1;
  3919. CONFIGPARMS cfg;
  3920. ConfigPageHeader_t header;
  3921. dma_addr_t ioc1_dma;
  3922. int iocpage1sz = 0;
  3923. u32 tmp;
  3924. /* Check the Coalescing Timeout in IOC Page 1
  3925. */
  3926. header.PageVersion = 0;
  3927. header.PageLength = 0;
  3928. header.PageNumber = 1;
  3929. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3930. cfg.hdr = &header;
  3931. cfg.physAddr = -1;
  3932. cfg.pageAddr = 0;
  3933. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3934. cfg.dir = 0;
  3935. cfg.timeout = 0;
  3936. if (mpt_config(ioc, &cfg) != 0)
  3937. return;
  3938. if (header.PageLength == 0)
  3939. return;
  3940. /* Read Header good, alloc memory
  3941. */
  3942. iocpage1sz = header.PageLength * 4;
  3943. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  3944. if (!pIoc1)
  3945. return;
  3946. /* Read the Page and check coalescing timeout
  3947. */
  3948. cfg.physAddr = ioc1_dma;
  3949. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3950. if (mpt_config(ioc, &cfg) == 0) {
  3951. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  3952. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  3953. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  3954. dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
  3955. ioc->name, tmp));
  3956. if (tmp > MPT_COALESCING_TIMEOUT) {
  3957. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  3958. /* Write NVRAM and current
  3959. */
  3960. cfg.dir = 1;
  3961. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3962. if (mpt_config(ioc, &cfg) == 0) {
  3963. dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
  3964. ioc->name, MPT_COALESCING_TIMEOUT));
  3965. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  3966. if (mpt_config(ioc, &cfg) == 0) {
  3967. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
  3968. ioc->name, MPT_COALESCING_TIMEOUT));
  3969. } else {
  3970. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
  3971. ioc->name));
  3972. }
  3973. } else {
  3974. dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
  3975. ioc->name));
  3976. }
  3977. }
  3978. } else {
  3979. dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  3980. }
  3981. }
  3982. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  3983. return;
  3984. }
  3985. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3986. /*
  3987. * SendEventNotification - Send EventNotification (on or off) request
  3988. * to MPT adapter.
  3989. * @ioc: Pointer to MPT_ADAPTER structure
  3990. * @EvSwitch: Event switch flags
  3991. */
  3992. static int
  3993. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
  3994. {
  3995. EventNotification_t *evnp;
  3996. evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
  3997. if (evnp == NULL) {
  3998. dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
  3999. ioc->name));
  4000. return 0;
  4001. }
  4002. memset(evnp, 0, sizeof(*evnp));
  4003. dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
  4004. evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  4005. evnp->ChainOffset = 0;
  4006. evnp->MsgFlags = 0;
  4007. evnp->Switch = EvSwitch;
  4008. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
  4009. return 0;
  4010. }
  4011. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4012. /**
  4013. * SendEventAck - Send EventAck request to MPT adapter.
  4014. * @ioc: Pointer to MPT_ADAPTER structure
  4015. * @evnp: Pointer to original EventNotification request
  4016. */
  4017. static int
  4018. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  4019. {
  4020. EventAck_t *pAck;
  4021. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4022. printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
  4023. ioc->name);
  4024. return -1;
  4025. }
  4026. memset(pAck, 0, sizeof(*pAck));
  4027. dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
  4028. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  4029. pAck->ChainOffset = 0;
  4030. pAck->MsgFlags = 0;
  4031. pAck->Event = evnp->Event;
  4032. pAck->EventContext = evnp->EventContext;
  4033. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  4034. return 0;
  4035. }
  4036. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4037. /**
  4038. * mpt_config - Generic function to issue config message
  4039. * @ioc - Pointer to an adapter structure
  4040. * @cfg - Pointer to a configuration structure. Struct contains
  4041. * action, page address, direction, physical address
  4042. * and pointer to a configuration page header
  4043. * Page header is updated.
  4044. *
  4045. * Returns 0 for success
  4046. * -EPERM if not allowed due to ISR context
  4047. * -EAGAIN if no msg frames currently available
  4048. * -EFAULT for non-successful reply or no reply (timeout)
  4049. */
  4050. int
  4051. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4052. {
  4053. Config_t *pReq;
  4054. MPT_FRAME_HDR *mf;
  4055. unsigned long flags;
  4056. int ii, rc;
  4057. u32 flagsLength;
  4058. int in_isr;
  4059. /* Prevent calling wait_event() (below), if caller happens
  4060. * to be in ISR context, because that is fatal!
  4061. */
  4062. in_isr = in_interrupt();
  4063. if (in_isr) {
  4064. dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  4065. ioc->name));
  4066. return -EPERM;
  4067. }
  4068. /* Get and Populate a free Frame
  4069. */
  4070. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4071. dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
  4072. ioc->name));
  4073. return -EAGAIN;
  4074. }
  4075. pReq = (Config_t *)mf;
  4076. pReq->Action = pCfg->action;
  4077. pReq->Reserved = 0;
  4078. pReq->ChainOffset = 0;
  4079. pReq->Function = MPI_FUNCTION_CONFIG;
  4080. pReq->ExtPageLength = 0;
  4081. pReq->ExtPageType = 0;
  4082. pReq->MsgFlags = 0;
  4083. for (ii=0; ii < 8; ii++)
  4084. pReq->Reserved2[ii] = 0;
  4085. pReq->Header.PageVersion = pCfg->hdr->PageVersion;
  4086. pReq->Header.PageLength = pCfg->hdr->PageLength;
  4087. pReq->Header.PageNumber = pCfg->hdr->PageNumber;
  4088. pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  4089. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  4090. /* Add a SGE to the config request.
  4091. */
  4092. if (pCfg->dir)
  4093. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  4094. else
  4095. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  4096. flagsLength |= pCfg->hdr->PageLength * 4;
  4097. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  4098. dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
  4099. ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
  4100. /* Append pCfg pointer to end of mf
  4101. */
  4102. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4103. /* Initalize the timer
  4104. */
  4105. init_timer(&pCfg->timer);
  4106. pCfg->timer.data = (unsigned long) ioc;
  4107. pCfg->timer.function = mpt_timer_expired;
  4108. pCfg->wait_done = 0;
  4109. /* Set the timer; ensure 10 second minimum */
  4110. if (pCfg->timeout < 10)
  4111. pCfg->timer.expires = jiffies + HZ*10;
  4112. else
  4113. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4114. /* Add to end of Q, set timer and then issue this command */
  4115. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4116. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4117. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4118. add_timer(&pCfg->timer);
  4119. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4120. wait_event(mpt_waitq, pCfg->wait_done);
  4121. /* mf has been freed - do not access */
  4122. rc = pCfg->status;
  4123. return rc;
  4124. }
  4125. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4126. /**
  4127. * mpt_toolbox - Generic function to issue toolbox message
  4128. * @ioc - Pointer to an adapter structure
  4129. * @cfg - Pointer to a toolbox structure. Struct contains
  4130. * action, page address, direction, physical address
  4131. * and pointer to a configuration page header
  4132. * Page header is updated.
  4133. *
  4134. * Returns 0 for success
  4135. * -EPERM if not allowed due to ISR context
  4136. * -EAGAIN if no msg frames currently available
  4137. * -EFAULT for non-successful reply or no reply (timeout)
  4138. */
  4139. int
  4140. mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4141. {
  4142. ToolboxIstwiReadWriteRequest_t *pReq;
  4143. MPT_FRAME_HDR *mf;
  4144. struct pci_dev *pdev;
  4145. unsigned long flags;
  4146. int rc;
  4147. u32 flagsLength;
  4148. int in_isr;
  4149. /* Prevent calling wait_event() (below), if caller happens
  4150. * to be in ISR context, because that is fatal!
  4151. */
  4152. in_isr = in_interrupt();
  4153. if (in_isr) {
  4154. dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
  4155. ioc->name));
  4156. return -EPERM;
  4157. }
  4158. /* Get and Populate a free Frame
  4159. */
  4160. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4161. dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
  4162. ioc->name));
  4163. return -EAGAIN;
  4164. }
  4165. pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
  4166. pReq->Tool = pCfg->action;
  4167. pReq->Reserved = 0;
  4168. pReq->ChainOffset = 0;
  4169. pReq->Function = MPI_FUNCTION_TOOLBOX;
  4170. pReq->Reserved1 = 0;
  4171. pReq->Reserved2 = 0;
  4172. pReq->MsgFlags = 0;
  4173. pReq->Flags = pCfg->dir;
  4174. pReq->BusNum = 0;
  4175. pReq->Reserved3 = 0;
  4176. pReq->NumAddressBytes = 0x01;
  4177. pReq->Reserved4 = 0;
  4178. pReq->DataLength = 0x04;
  4179. pdev = (struct pci_dev *) ioc->pcidev;
  4180. if (pdev->devfn & 1)
  4181. pReq->DeviceAddr = 0xB2;
  4182. else
  4183. pReq->DeviceAddr = 0xB0;
  4184. pReq->Addr1 = 0;
  4185. pReq->Addr2 = 0;
  4186. pReq->Addr3 = 0;
  4187. pReq->Reserved5 = 0;
  4188. /* Add a SGE to the config request.
  4189. */
  4190. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
  4191. mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
  4192. dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
  4193. ioc->name, pReq->Tool));
  4194. /* Append pCfg pointer to end of mf
  4195. */
  4196. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4197. /* Initalize the timer
  4198. */
  4199. init_timer(&pCfg->timer);
  4200. pCfg->timer.data = (unsigned long) ioc;
  4201. pCfg->timer.function = mpt_timer_expired;
  4202. pCfg->wait_done = 0;
  4203. /* Set the timer; ensure 10 second minimum */
  4204. if (pCfg->timeout < 10)
  4205. pCfg->timer.expires = jiffies + HZ*10;
  4206. else
  4207. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4208. /* Add to end of Q, set timer and then issue this command */
  4209. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4210. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4211. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4212. add_timer(&pCfg->timer);
  4213. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4214. wait_event(mpt_waitq, pCfg->wait_done);
  4215. /* mf has been freed - do not access */
  4216. rc = pCfg->status;
  4217. return rc;
  4218. }
  4219. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4220. /*
  4221. * mpt_timer_expired - Call back for timer process.
  4222. * Used only internal config functionality.
  4223. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  4224. */
  4225. static void
  4226. mpt_timer_expired(unsigned long data)
  4227. {
  4228. MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
  4229. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
  4230. /* Perform a FW reload */
  4231. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
  4232. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
  4233. /* No more processing.
  4234. * Hard reset clean-up will wake up
  4235. * process and free all resources.
  4236. */
  4237. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
  4238. return;
  4239. }
  4240. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4241. /*
  4242. * mpt_ioc_reset - Base cleanup for hard reset
  4243. * @ioc: Pointer to the adapter structure
  4244. * @reset_phase: Indicates pre- or post-reset functionality
  4245. *
  4246. * Remark: Free's resources with internally generated commands.
  4247. */
  4248. static int
  4249. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  4250. {
  4251. CONFIGPARMS *pCfg;
  4252. unsigned long flags;
  4253. dprintk((KERN_WARNING MYNAM
  4254. ": IOC %s_reset routed to MPT base driver!\n",
  4255. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  4256. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  4257. if (reset_phase == MPT_IOC_SETUP_RESET) {
  4258. ;
  4259. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  4260. /* If the internal config Q is not empty -
  4261. * delete timer. MF resources will be freed when
  4262. * the FIFO's are primed.
  4263. */
  4264. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4265. list_for_each_entry(pCfg, &ioc->configQ, linkage)
  4266. del_timer(&pCfg->timer);
  4267. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4268. } else {
  4269. CONFIGPARMS *pNext;
  4270. /* Search the configQ for internal commands.
  4271. * Flush the Q, and wake up all suspended threads.
  4272. */
  4273. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4274. list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
  4275. list_del(&pCfg->linkage);
  4276. pCfg->status = MPT_CONFIG_ERROR;
  4277. pCfg->wait_done = 1;
  4278. wake_up(&mpt_waitq);
  4279. }
  4280. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4281. }
  4282. return 1; /* currently means nothing really */
  4283. }
  4284. #ifdef CONFIG_PROC_FS /* { */
  4285. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4286. /*
  4287. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  4288. */
  4289. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4290. /*
  4291. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  4292. *
  4293. * Returns 0 for success, non-zero for failure.
  4294. */
  4295. static int
  4296. procmpt_create(void)
  4297. {
  4298. struct proc_dir_entry *ent;
  4299. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  4300. if (mpt_proc_root_dir == NULL)
  4301. return -ENOTDIR;
  4302. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4303. if (ent)
  4304. ent->read_proc = procmpt_summary_read;
  4305. ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4306. if (ent)
  4307. ent->read_proc = procmpt_version_read;
  4308. return 0;
  4309. }
  4310. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4311. /*
  4312. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  4313. *
  4314. * Returns 0 for success, non-zero for failure.
  4315. */
  4316. static void
  4317. procmpt_destroy(void)
  4318. {
  4319. remove_proc_entry("version", mpt_proc_root_dir);
  4320. remove_proc_entry("summary", mpt_proc_root_dir);
  4321. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  4322. }
  4323. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4324. /*
  4325. * procmpt_summary_read - Handle read request from /proc/mpt/summary
  4326. * or from /proc/mpt/iocN/summary.
  4327. * @buf: Pointer to area to write information
  4328. * @start: Pointer to start pointer
  4329. * @offset: Offset to start writing
  4330. * @request:
  4331. * @eof: Pointer to EOF integer
  4332. * @data: Pointer
  4333. *
  4334. * Returns number of characters written to process performing the read.
  4335. */
  4336. static int
  4337. procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4338. {
  4339. MPT_ADAPTER *ioc;
  4340. char *out = buf;
  4341. int len;
  4342. if (data) {
  4343. int more = 0;
  4344. ioc = data;
  4345. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4346. out += more;
  4347. } else {
  4348. list_for_each_entry(ioc, &ioc_list, list) {
  4349. int more = 0;
  4350. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4351. out += more;
  4352. if ((out-buf) >= request)
  4353. break;
  4354. }
  4355. }
  4356. len = out - buf;
  4357. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4358. }
  4359. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4360. /*
  4361. * procmpt_version_read - Handle read request from /proc/mpt/version.
  4362. * @buf: Pointer to area to write information
  4363. * @start: Pointer to start pointer
  4364. * @offset: Offset to start writing
  4365. * @request:
  4366. * @eof: Pointer to EOF integer
  4367. * @data: Pointer
  4368. *
  4369. * Returns number of characters written to process performing the read.
  4370. */
  4371. static int
  4372. procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4373. {
  4374. int ii;
  4375. int scsi, fc, sas, lan, ctl, targ, dmp;
  4376. char *drvname;
  4377. int len;
  4378. len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  4379. len += sprintf(buf+len, " Fusion MPT base driver\n");
  4380. scsi = fc = sas = lan = ctl = targ = dmp = 0;
  4381. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4382. drvname = NULL;
  4383. if (MptCallbacks[ii]) {
  4384. switch (MptDriverClass[ii]) {
  4385. case MPTSPI_DRIVER:
  4386. if (!scsi++) drvname = "SPI host";
  4387. break;
  4388. case MPTFC_DRIVER:
  4389. if (!fc++) drvname = "FC host";
  4390. break;
  4391. case MPTSAS_DRIVER:
  4392. if (!sas++) drvname = "SAS host";
  4393. break;
  4394. case MPTLAN_DRIVER:
  4395. if (!lan++) drvname = "LAN";
  4396. break;
  4397. case MPTSTM_DRIVER:
  4398. if (!targ++) drvname = "SCSI target";
  4399. break;
  4400. case MPTCTL_DRIVER:
  4401. if (!ctl++) drvname = "ioctl";
  4402. break;
  4403. }
  4404. if (drvname)
  4405. len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
  4406. }
  4407. }
  4408. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4409. }
  4410. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4411. /*
  4412. * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
  4413. * @buf: Pointer to area to write information
  4414. * @start: Pointer to start pointer
  4415. * @offset: Offset to start writing
  4416. * @request:
  4417. * @eof: Pointer to EOF integer
  4418. * @data: Pointer
  4419. *
  4420. * Returns number of characters written to process performing the read.
  4421. */
  4422. static int
  4423. procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4424. {
  4425. MPT_ADAPTER *ioc = data;
  4426. int len;
  4427. char expVer[32];
  4428. int sz;
  4429. int p;
  4430. mpt_get_fw_exp_ver(expVer, ioc);
  4431. len = sprintf(buf, "%s:", ioc->name);
  4432. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  4433. len += sprintf(buf+len, " (f/w download boot flag set)");
  4434. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  4435. // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
  4436. len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
  4437. ioc->facts.ProductID,
  4438. ioc->prod_name);
  4439. len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  4440. if (ioc->facts.FWImageSize)
  4441. len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
  4442. len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  4443. len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  4444. len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
  4445. len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
  4446. ioc->facts.CurrentHostMfaHighAddr);
  4447. len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
  4448. ioc->facts.CurrentSenseBufferHighAddr);
  4449. len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  4450. len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  4451. len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  4452. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  4453. /*
  4454. * Rounding UP to nearest 4-kB boundary here...
  4455. */
  4456. sz = (ioc->req_sz * ioc->req_depth) + 128;
  4457. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  4458. len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  4459. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  4460. len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  4461. 4*ioc->facts.RequestFrameSize,
  4462. ioc->facts.GlobalCredits);
  4463. len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
  4464. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  4465. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  4466. len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  4467. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  4468. len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  4469. ioc->facts.CurReplyFrameSize,
  4470. ioc->facts.ReplyQueueDepth);
  4471. len += sprintf(buf+len, " MaxDevices = %d\n",
  4472. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  4473. len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  4474. /* per-port info */
  4475. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  4476. len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
  4477. p+1,
  4478. ioc->facts.NumberOfPorts);
  4479. if (ioc->bus_type == FC) {
  4480. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  4481. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4482. len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  4483. a[5], a[4], a[3], a[2], a[1], a[0]);
  4484. }
  4485. len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
  4486. ioc->fc_port_page0[p].WWNN.High,
  4487. ioc->fc_port_page0[p].WWNN.Low,
  4488. ioc->fc_port_page0[p].WWPN.High,
  4489. ioc->fc_port_page0[p].WWPN.Low);
  4490. }
  4491. }
  4492. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4493. }
  4494. #endif /* CONFIG_PROC_FS } */
  4495. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4496. static void
  4497. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  4498. {
  4499. buf[0] ='\0';
  4500. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  4501. sprintf(buf, " (Exp %02d%02d)",
  4502. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  4503. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  4504. /* insider hack! */
  4505. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  4506. strcat(buf, " [MDBG]");
  4507. }
  4508. }
  4509. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4510. /**
  4511. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  4512. * @ioc: Pointer to MPT_ADAPTER structure
  4513. * @buffer: Pointer to buffer where IOC summary info should be written
  4514. * @size: Pointer to number of bytes we wrote (set by this routine)
  4515. * @len: Offset at which to start writing in buffer
  4516. * @showlan: Display LAN stuff?
  4517. *
  4518. * This routine writes (english readable) ASCII text, which represents
  4519. * a summary of IOC information, to a buffer.
  4520. */
  4521. void
  4522. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  4523. {
  4524. char expVer[32];
  4525. int y;
  4526. mpt_get_fw_exp_ver(expVer, ioc);
  4527. /*
  4528. * Shorter summary of attached ioc's...
  4529. */
  4530. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  4531. ioc->name,
  4532. ioc->prod_name,
  4533. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  4534. ioc->facts.FWVersion.Word,
  4535. expVer,
  4536. ioc->facts.NumberOfPorts,
  4537. ioc->req_depth);
  4538. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  4539. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4540. y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  4541. a[5], a[4], a[3], a[2], a[1], a[0]);
  4542. }
  4543. #ifndef __sparc__
  4544. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  4545. #else
  4546. y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
  4547. #endif
  4548. if (!ioc->active)
  4549. y += sprintf(buffer+len+y, " (disabled)");
  4550. y += sprintf(buffer+len+y, "\n");
  4551. *size = y;
  4552. }
  4553. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4554. /*
  4555. * Reset Handling
  4556. */
  4557. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4558. /**
  4559. * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
  4560. * Management call based on input arg values. If TaskMgmt fails,
  4561. * return associated SCSI request.
  4562. * @ioc: Pointer to MPT_ADAPTER structure
  4563. * @sleepFlag: Indicates if sleep or schedule must be called.
  4564. *
  4565. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  4566. * or a non-interrupt thread. In the former, must not call schedule().
  4567. *
  4568. * Remark: A return of -1 is a FATAL error case, as it means a
  4569. * FW reload/initialization failed.
  4570. *
  4571. * Returns 0 for SUCCESS or -1 if FAILED.
  4572. */
  4573. int
  4574. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  4575. {
  4576. int rc;
  4577. unsigned long flags;
  4578. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
  4579. #ifdef MFCNT
  4580. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  4581. printk("MF count 0x%x !\n", ioc->mfcnt);
  4582. #endif
  4583. /* Reset the adapter. Prevent more than 1 call to
  4584. * mpt_do_ioc_recovery at any instant in time.
  4585. */
  4586. spin_lock_irqsave(&ioc->diagLock, flags);
  4587. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
  4588. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4589. return 0;
  4590. } else {
  4591. ioc->diagPending = 1;
  4592. }
  4593. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4594. /* FIXME: If do_ioc_recovery fails, repeat....
  4595. */
  4596. /* The SCSI driver needs to adjust timeouts on all current
  4597. * commands prior to the diagnostic reset being issued.
  4598. * Prevents timeouts occuring during a diagnostic reset...very bad.
  4599. * For all other protocol drivers, this is a no-op.
  4600. */
  4601. {
  4602. int ii;
  4603. int r = 0;
  4604. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4605. if (MptResetHandlers[ii]) {
  4606. dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
  4607. ioc->name, ii));
  4608. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
  4609. if (ioc->alt_ioc) {
  4610. dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
  4611. ioc->name, ioc->alt_ioc->name, ii));
  4612. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
  4613. }
  4614. }
  4615. }
  4616. }
  4617. if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
  4618. printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
  4619. rc, ioc->name);
  4620. }
  4621. ioc->reload_fw = 0;
  4622. if (ioc->alt_ioc)
  4623. ioc->alt_ioc->reload_fw = 0;
  4624. spin_lock_irqsave(&ioc->diagLock, flags);
  4625. ioc->diagPending = 0;
  4626. if (ioc->alt_ioc)
  4627. ioc->alt_ioc->diagPending = 0;
  4628. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4629. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
  4630. return rc;
  4631. }
  4632. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4633. static char *
  4634. EventDescriptionStr(u8 event, u32 evData0)
  4635. {
  4636. char *ds;
  4637. switch(event) {
  4638. case MPI_EVENT_NONE:
  4639. ds = "None";
  4640. break;
  4641. case MPI_EVENT_LOG_DATA:
  4642. ds = "Log Data";
  4643. break;
  4644. case MPI_EVENT_STATE_CHANGE:
  4645. ds = "State Change";
  4646. break;
  4647. case MPI_EVENT_UNIT_ATTENTION:
  4648. ds = "Unit Attention";
  4649. break;
  4650. case MPI_EVENT_IOC_BUS_RESET:
  4651. ds = "IOC Bus Reset";
  4652. break;
  4653. case MPI_EVENT_EXT_BUS_RESET:
  4654. ds = "External Bus Reset";
  4655. break;
  4656. case MPI_EVENT_RESCAN:
  4657. ds = "Bus Rescan Event";
  4658. /* Ok, do we need to do anything here? As far as
  4659. I can tell, this is when a new device gets added
  4660. to the loop. */
  4661. break;
  4662. case MPI_EVENT_LINK_STATUS_CHANGE:
  4663. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  4664. ds = "Link Status(FAILURE) Change";
  4665. else
  4666. ds = "Link Status(ACTIVE) Change";
  4667. break;
  4668. case MPI_EVENT_LOOP_STATE_CHANGE:
  4669. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  4670. ds = "Loop State(LIP) Change";
  4671. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  4672. ds = "Loop State(LPE) Change"; /* ??? */
  4673. else
  4674. ds = "Loop State(LPB) Change"; /* ??? */
  4675. break;
  4676. case MPI_EVENT_LOGOUT:
  4677. ds = "Logout";
  4678. break;
  4679. case MPI_EVENT_EVENT_CHANGE:
  4680. if (evData0)
  4681. ds = "Events(ON) Change";
  4682. else
  4683. ds = "Events(OFF) Change";
  4684. break;
  4685. case MPI_EVENT_INTEGRATED_RAID:
  4686. ds = "Integrated Raid";
  4687. break;
  4688. /*
  4689. * MPT base "custom" events may be added here...
  4690. */
  4691. default:
  4692. ds = "Unknown";
  4693. break;
  4694. }
  4695. return ds;
  4696. }
  4697. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4698. /*
  4699. * ProcessEventNotification - Route a received EventNotificationReply to
  4700. * all currently regeistered event handlers.
  4701. * @ioc: Pointer to MPT_ADAPTER structure
  4702. * @pEventReply: Pointer to EventNotification reply frame
  4703. * @evHandlers: Pointer to integer, number of event handlers
  4704. *
  4705. * Returns sum of event handlers return values.
  4706. */
  4707. static int
  4708. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  4709. {
  4710. u16 evDataLen;
  4711. u32 evData0 = 0;
  4712. // u32 evCtx;
  4713. int ii;
  4714. int r = 0;
  4715. int handlers = 0;
  4716. char *evStr;
  4717. u8 event;
  4718. /*
  4719. * Do platform normalization of values
  4720. */
  4721. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  4722. // evCtx = le32_to_cpu(pEventReply->EventContext);
  4723. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  4724. if (evDataLen) {
  4725. evData0 = le32_to_cpu(pEventReply->Data[0]);
  4726. }
  4727. evStr = EventDescriptionStr(event, evData0);
  4728. devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
  4729. ioc->name,
  4730. evStr,
  4731. event));
  4732. #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
  4733. printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
  4734. for (ii = 0; ii < evDataLen; ii++)
  4735. printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
  4736. printk("\n");
  4737. #endif
  4738. /*
  4739. * Do general / base driver event processing
  4740. */
  4741. switch(event) {
  4742. case MPI_EVENT_NONE: /* 00 */
  4743. case MPI_EVENT_LOG_DATA: /* 01 */
  4744. case MPI_EVENT_STATE_CHANGE: /* 02 */
  4745. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  4746. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  4747. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  4748. case MPI_EVENT_RESCAN: /* 06 */
  4749. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  4750. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  4751. case MPI_EVENT_LOGOUT: /* 09 */
  4752. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  4753. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
  4754. default:
  4755. break;
  4756. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  4757. if (evDataLen) {
  4758. u8 evState = evData0 & 0xFF;
  4759. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  4760. /* Update EventState field in cached IocFacts */
  4761. if (ioc->facts.Function) {
  4762. ioc->facts.EventState = evState;
  4763. }
  4764. }
  4765. break;
  4766. }
  4767. /*
  4768. * Should this event be logged? Events are written sequentially.
  4769. * When buffer is full, start again at the top.
  4770. */
  4771. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  4772. int idx;
  4773. idx = ioc->eventContext % ioc->eventLogSize;
  4774. ioc->events[idx].event = event;
  4775. ioc->events[idx].eventContext = ioc->eventContext;
  4776. for (ii = 0; ii < 2; ii++) {
  4777. if (ii < evDataLen)
  4778. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  4779. else
  4780. ioc->events[idx].data[ii] = 0;
  4781. }
  4782. ioc->eventContext++;
  4783. }
  4784. /*
  4785. * Call each currently registered protocol event handler.
  4786. */
  4787. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4788. if (MptEvHandlers[ii]) {
  4789. devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
  4790. ioc->name, ii));
  4791. r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
  4792. handlers++;
  4793. }
  4794. }
  4795. /* FIXME? Examine results here? */
  4796. /*
  4797. * If needed, send (a single) EventAck.
  4798. */
  4799. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  4800. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  4801. devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
  4802. ioc->name, ii));
  4803. }
  4804. }
  4805. *evHandlers = handlers;
  4806. return r;
  4807. }
  4808. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4809. /*
  4810. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  4811. * @ioc: Pointer to MPT_ADAPTER structure
  4812. * @log_info: U32 LogInfo reply word from the IOC
  4813. *
  4814. * Refer to lsi/fc_log.h.
  4815. */
  4816. static void
  4817. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4818. {
  4819. static char *subcl_str[8] = {
  4820. "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
  4821. "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
  4822. };
  4823. u8 subcl = (log_info >> 24) & 0x7;
  4824. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
  4825. ioc->name, log_info, subcl_str[subcl]);
  4826. }
  4827. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4828. /*
  4829. * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
  4830. * @ioc: Pointer to MPT_ADAPTER structure
  4831. * @mr: Pointer to MPT reply frame
  4832. * @log_info: U32 LogInfo word from the IOC
  4833. *
  4834. * Refer to lsi/sp_log.h.
  4835. */
  4836. static void
  4837. mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4838. {
  4839. u32 info = log_info & 0x00FF0000;
  4840. char *desc = "unknown";
  4841. switch (info) {
  4842. case 0x00010000:
  4843. desc = "bug! MID not found";
  4844. if (ioc->reload_fw == 0)
  4845. ioc->reload_fw++;
  4846. break;
  4847. case 0x00020000:
  4848. desc = "Parity Error";
  4849. break;
  4850. case 0x00030000:
  4851. desc = "ASYNC Outbound Overrun";
  4852. break;
  4853. case 0x00040000:
  4854. desc = "SYNC Offset Error";
  4855. break;
  4856. case 0x00050000:
  4857. desc = "BM Change";
  4858. break;
  4859. case 0x00060000:
  4860. desc = "Msg In Overflow";
  4861. break;
  4862. case 0x00070000:
  4863. desc = "DMA Error";
  4864. break;
  4865. case 0x00080000:
  4866. desc = "Outbound DMA Overrun";
  4867. break;
  4868. case 0x00090000:
  4869. desc = "Task Management";
  4870. break;
  4871. case 0x000A0000:
  4872. desc = "Device Problem";
  4873. break;
  4874. case 0x000B0000:
  4875. desc = "Invalid Phase Change";
  4876. break;
  4877. case 0x000C0000:
  4878. desc = "Untagged Table Size";
  4879. break;
  4880. }
  4881. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  4882. }
  4883. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4884. /*
  4885. * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
  4886. * @ioc: Pointer to MPT_ADAPTER structure
  4887. * @ioc_status: U32 IOCStatus word from IOC
  4888. * @mf: Pointer to MPT request frame
  4889. *
  4890. * Refer to lsi/mpi.h.
  4891. */
  4892. static void
  4893. mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  4894. {
  4895. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  4896. char *desc = "";
  4897. switch (status) {
  4898. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  4899. desc = "Invalid Function";
  4900. break;
  4901. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  4902. desc = "Busy";
  4903. break;
  4904. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  4905. desc = "Invalid SGL";
  4906. break;
  4907. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  4908. desc = "Internal Error";
  4909. break;
  4910. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  4911. desc = "Reserved";
  4912. break;
  4913. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  4914. desc = "Insufficient Resources";
  4915. break;
  4916. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  4917. desc = "Invalid Field";
  4918. break;
  4919. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  4920. desc = "Invalid State";
  4921. break;
  4922. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  4923. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  4924. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  4925. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  4926. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  4927. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  4928. /* No message for Config IOCStatus values */
  4929. break;
  4930. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  4931. /* No message for recovered error
  4932. desc = "SCSI Recovered Error";
  4933. */
  4934. break;
  4935. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  4936. desc = "SCSI Invalid Bus";
  4937. break;
  4938. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  4939. desc = "SCSI Invalid TargetID";
  4940. break;
  4941. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  4942. {
  4943. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  4944. U8 cdb = pScsiReq->CDB[0];
  4945. if (cdb != 0x12) { /* Inquiry is issued for device scanning */
  4946. desc = "SCSI Device Not There";
  4947. }
  4948. break;
  4949. }
  4950. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  4951. desc = "SCSI Data Overrun";
  4952. break;
  4953. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  4954. /* This error is checked in scsi_io_done(). Skip.
  4955. desc = "SCSI Data Underrun";
  4956. */
  4957. break;
  4958. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  4959. desc = "SCSI I/O Data Error";
  4960. break;
  4961. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  4962. desc = "SCSI Protocol Error";
  4963. break;
  4964. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  4965. desc = "SCSI Task Terminated";
  4966. break;
  4967. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  4968. desc = "SCSI Residual Mismatch";
  4969. break;
  4970. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  4971. desc = "SCSI Task Management Failed";
  4972. break;
  4973. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  4974. desc = "SCSI IOC Terminated";
  4975. break;
  4976. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  4977. desc = "SCSI Ext Terminated";
  4978. break;
  4979. default:
  4980. desc = "Others";
  4981. break;
  4982. }
  4983. if (desc != "")
  4984. printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
  4985. }
  4986. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4987. EXPORT_SYMBOL(mpt_attach);
  4988. EXPORT_SYMBOL(mpt_detach);
  4989. #ifdef CONFIG_PM
  4990. EXPORT_SYMBOL(mpt_resume);
  4991. EXPORT_SYMBOL(mpt_suspend);
  4992. #endif
  4993. EXPORT_SYMBOL(ioc_list);
  4994. EXPORT_SYMBOL(mpt_proc_root_dir);
  4995. EXPORT_SYMBOL(mpt_register);
  4996. EXPORT_SYMBOL(mpt_deregister);
  4997. EXPORT_SYMBOL(mpt_event_register);
  4998. EXPORT_SYMBOL(mpt_event_deregister);
  4999. EXPORT_SYMBOL(mpt_reset_register);
  5000. EXPORT_SYMBOL(mpt_reset_deregister);
  5001. EXPORT_SYMBOL(mpt_device_driver_register);
  5002. EXPORT_SYMBOL(mpt_device_driver_deregister);
  5003. EXPORT_SYMBOL(mpt_get_msg_frame);
  5004. EXPORT_SYMBOL(mpt_put_msg_frame);
  5005. EXPORT_SYMBOL(mpt_free_msg_frame);
  5006. EXPORT_SYMBOL(mpt_add_sge);
  5007. EXPORT_SYMBOL(mpt_send_handshake_request);
  5008. EXPORT_SYMBOL(mpt_verify_adapter);
  5009. EXPORT_SYMBOL(mpt_GetIocState);
  5010. EXPORT_SYMBOL(mpt_print_ioc_summary);
  5011. EXPORT_SYMBOL(mpt_lan_index);
  5012. EXPORT_SYMBOL(mpt_stm_index);
  5013. EXPORT_SYMBOL(mpt_HardResetHandler);
  5014. EXPORT_SYMBOL(mpt_config);
  5015. EXPORT_SYMBOL(mpt_toolbox);
  5016. EXPORT_SYMBOL(mpt_findImVolumes);
  5017. EXPORT_SYMBOL(mpt_read_ioc_pg_3);
  5018. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  5019. EXPORT_SYMBOL(mpt_free_fw_memory);
  5020. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5021. /*
  5022. * fusion_init - Fusion MPT base driver initialization routine.
  5023. *
  5024. * Returns 0 for success, non-zero for failure.
  5025. */
  5026. static int __init
  5027. fusion_init(void)
  5028. {
  5029. int i;
  5030. show_mptmod_ver(my_NAME, my_VERSION);
  5031. printk(KERN_INFO COPYRIGHT "\n");
  5032. for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
  5033. MptCallbacks[i] = NULL;
  5034. MptDriverClass[i] = MPTUNKNOWN_DRIVER;
  5035. MptEvHandlers[i] = NULL;
  5036. MptResetHandlers[i] = NULL;
  5037. }
  5038. /* Register ourselves (mptbase) in order to facilitate
  5039. * EventNotification handling.
  5040. */
  5041. mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
  5042. /* Register for hard reset handling callbacks.
  5043. */
  5044. if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
  5045. dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
  5046. } else {
  5047. /* FIXME! */
  5048. }
  5049. #ifdef CONFIG_PROC_FS
  5050. (void) procmpt_create();
  5051. #endif
  5052. return 0;
  5053. }
  5054. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5055. /*
  5056. * fusion_exit - Perform driver unload cleanup.
  5057. *
  5058. * This routine frees all resources associated with each MPT adapter
  5059. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  5060. */
  5061. static void __exit
  5062. fusion_exit(void)
  5063. {
  5064. dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
  5065. mpt_reset_deregister(mpt_base_index);
  5066. #ifdef CONFIG_PROC_FS
  5067. procmpt_destroy();
  5068. #endif
  5069. }
  5070. module_init(fusion_init);
  5071. module_exit(fusion_exit);