mptbase.c 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845
  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. kfree(ioc->spi_data.nvram);
  1609. kfree(ioc->spi_data.pIocPg3);
  1610. ioc->spi_data.nvram = NULL;
  1611. ioc->spi_data.pIocPg3 = NULL;
  1612. if (ioc->spi_data.pIocPg4 != NULL) {
  1613. sz = ioc->spi_data.IocPg4Sz;
  1614. pci_free_consistent(ioc->pcidev, sz,
  1615. ioc->spi_data.pIocPg4,
  1616. ioc->spi_data.IocPg4_dma);
  1617. ioc->spi_data.pIocPg4 = NULL;
  1618. ioc->alloc_total -= sz;
  1619. }
  1620. if (ioc->ReqToChain != NULL) {
  1621. kfree(ioc->ReqToChain);
  1622. kfree(ioc->RequestNB);
  1623. ioc->ReqToChain = NULL;
  1624. }
  1625. kfree(ioc->ChainToChain);
  1626. ioc->ChainToChain = NULL;
  1627. }
  1628. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1629. /*
  1630. * mpt_adapter_dispose - Free all resources associated with a MPT
  1631. * adapter.
  1632. * @ioc: Pointer to MPT adapter structure
  1633. *
  1634. * This routine unregisters h/w resources and frees all alloc'd memory
  1635. * associated with a MPT adapter structure.
  1636. */
  1637. static void
  1638. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  1639. {
  1640. if (ioc != NULL) {
  1641. int sz_first, sz_last;
  1642. sz_first = ioc->alloc_total;
  1643. mpt_adapter_disable(ioc);
  1644. if (ioc->pci_irq != -1) {
  1645. free_irq(ioc->pci_irq, ioc);
  1646. ioc->pci_irq = -1;
  1647. }
  1648. if (ioc->memmap != NULL)
  1649. iounmap(ioc->memmap);
  1650. #if defined(CONFIG_MTRR) && 0
  1651. if (ioc->mtrr_reg > 0) {
  1652. mtrr_del(ioc->mtrr_reg, 0, 0);
  1653. dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
  1654. }
  1655. #endif
  1656. /* Zap the adapter lookup ptr! */
  1657. list_del(&ioc->list);
  1658. sz_last = ioc->alloc_total;
  1659. dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
  1660. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  1661. kfree(ioc);
  1662. }
  1663. }
  1664. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1665. /*
  1666. * MptDisplayIocCapabilities - Disply IOC's capacilities.
  1667. * @ioc: Pointer to MPT adapter structure
  1668. */
  1669. static void
  1670. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  1671. {
  1672. int i = 0;
  1673. printk(KERN_INFO "%s: ", ioc->name);
  1674. if (ioc->prod_name && strlen(ioc->prod_name) > 3)
  1675. printk("%s: ", ioc->prod_name+3);
  1676. printk("Capabilities={");
  1677. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  1678. printk("Initiator");
  1679. i++;
  1680. }
  1681. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1682. printk("%sTarget", i ? "," : "");
  1683. i++;
  1684. }
  1685. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  1686. printk("%sLAN", i ? "," : "");
  1687. i++;
  1688. }
  1689. #if 0
  1690. /*
  1691. * This would probably evoke more questions than it's worth
  1692. */
  1693. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1694. printk("%sLogBusAddr", i ? "," : "");
  1695. i++;
  1696. }
  1697. #endif
  1698. printk("}\n");
  1699. }
  1700. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1701. /*
  1702. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  1703. * @ioc: Pointer to MPT_ADAPTER structure
  1704. * @force: Force hard KickStart of IOC
  1705. * @sleepFlag: Specifies whether the process can sleep
  1706. *
  1707. * Returns:
  1708. * 1 - DIAG reset and READY
  1709. * 0 - READY initially OR soft reset and READY
  1710. * -1 - Any failure on KickStart
  1711. * -2 - Msg Unit Reset Failed
  1712. * -3 - IO Unit Reset Failed
  1713. * -4 - IOC owned by a PEER
  1714. */
  1715. static int
  1716. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  1717. {
  1718. u32 ioc_state;
  1719. int statefault = 0;
  1720. int cntdn;
  1721. int hard_reset_done = 0;
  1722. int r;
  1723. int ii;
  1724. int whoinit;
  1725. /* Get current [raw] IOC state */
  1726. ioc_state = mpt_GetIocState(ioc, 0);
  1727. dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
  1728. /*
  1729. * Check to see if IOC got left/stuck in doorbell handshake
  1730. * grip of death. If so, hard reset the IOC.
  1731. */
  1732. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  1733. statefault = 1;
  1734. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  1735. ioc->name);
  1736. }
  1737. /* Is it already READY? */
  1738. if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
  1739. return 0;
  1740. /*
  1741. * Check to see if IOC is in FAULT state.
  1742. */
  1743. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  1744. statefault = 2;
  1745. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  1746. ioc->name);
  1747. printk(KERN_WARNING " FAULT code = %04xh\n",
  1748. ioc_state & MPI_DOORBELL_DATA_MASK);
  1749. }
  1750. /*
  1751. * Hmmm... Did it get left operational?
  1752. */
  1753. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  1754. dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
  1755. ioc->name));
  1756. /* Check WhoInit.
  1757. * If PCI Peer, exit.
  1758. * Else, if no fault conditions are present, issue a MessageUnitReset
  1759. * Else, fall through to KickStart case
  1760. */
  1761. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  1762. dprintk((KERN_WARNING MYNAM
  1763. ": whoinit 0x%x\n statefault %d force %d\n",
  1764. whoinit, statefault, force));
  1765. if (whoinit == MPI_WHOINIT_PCI_PEER)
  1766. return -4;
  1767. else {
  1768. if ((statefault == 0 ) && (force == 0)) {
  1769. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  1770. return 0;
  1771. }
  1772. statefault = 3;
  1773. }
  1774. }
  1775. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  1776. if (hard_reset_done < 0)
  1777. return -1;
  1778. /*
  1779. * Loop here waiting for IOC to come READY.
  1780. */
  1781. ii = 0;
  1782. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  1783. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  1784. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  1785. /*
  1786. * BIOS or previous driver load left IOC in OP state.
  1787. * Reset messaging FIFOs.
  1788. */
  1789. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  1790. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  1791. return -2;
  1792. }
  1793. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  1794. /*
  1795. * Something is wrong. Try to get IOC back
  1796. * to a known state.
  1797. */
  1798. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  1799. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  1800. return -3;
  1801. }
  1802. }
  1803. ii++; cntdn--;
  1804. if (!cntdn) {
  1805. printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
  1806. ioc->name, (int)((ii+5)/HZ));
  1807. return -ETIME;
  1808. }
  1809. if (sleepFlag == CAN_SLEEP) {
  1810. msleep_interruptible(1);
  1811. } else {
  1812. mdelay (1); /* 1 msec delay */
  1813. }
  1814. }
  1815. if (statefault < 3) {
  1816. printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
  1817. ioc->name,
  1818. statefault==1 ? "stuck handshake" : "IOC FAULT");
  1819. }
  1820. return hard_reset_done;
  1821. }
  1822. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1823. /*
  1824. * mpt_GetIocState - Get the current state of a MPT adapter.
  1825. * @ioc: Pointer to MPT_ADAPTER structure
  1826. * @cooked: Request raw or cooked IOC state
  1827. *
  1828. * Returns all IOC Doorbell register bits if cooked==0, else just the
  1829. * Doorbell bits in MPI_IOC_STATE_MASK.
  1830. */
  1831. u32
  1832. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  1833. {
  1834. u32 s, sc;
  1835. /* Get! */
  1836. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  1837. // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
  1838. sc = s & MPI_IOC_STATE_MASK;
  1839. /* Save! */
  1840. ioc->last_state = sc;
  1841. return cooked ? sc : s;
  1842. }
  1843. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1844. /*
  1845. * GetIocFacts - Send IOCFacts request to MPT adapter.
  1846. * @ioc: Pointer to MPT_ADAPTER structure
  1847. * @sleepFlag: Specifies whether the process can sleep
  1848. * @reason: If recovery, only update facts.
  1849. *
  1850. * Returns 0 for success, non-zero for failure.
  1851. */
  1852. static int
  1853. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  1854. {
  1855. IOCFacts_t get_facts;
  1856. IOCFactsReply_t *facts;
  1857. int r;
  1858. int req_sz;
  1859. int reply_sz;
  1860. int sz;
  1861. u32 status, vv;
  1862. u8 shiftFactor=1;
  1863. /* IOC *must* NOT be in RESET state! */
  1864. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  1865. printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  1866. ioc->name,
  1867. ioc->last_state );
  1868. return -44;
  1869. }
  1870. facts = &ioc->facts;
  1871. /* Destination (reply area)... */
  1872. reply_sz = sizeof(*facts);
  1873. memset(facts, 0, reply_sz);
  1874. /* Request area (get_facts on the stack right now!) */
  1875. req_sz = sizeof(get_facts);
  1876. memset(&get_facts, 0, req_sz);
  1877. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  1878. /* Assert: All other get_facts fields are zero! */
  1879. dinitprintk((MYIOC_s_INFO_FMT
  1880. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  1881. ioc->name, req_sz, reply_sz));
  1882. /* No non-zero fields in the get_facts request are greater than
  1883. * 1 byte in size, so we can just fire it off as is.
  1884. */
  1885. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  1886. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  1887. if (r != 0)
  1888. return r;
  1889. /*
  1890. * Now byte swap (GRRR) the necessary fields before any further
  1891. * inspection of reply contents.
  1892. *
  1893. * But need to do some sanity checks on MsgLength (byte) field
  1894. * to make sure we don't zero IOC's req_sz!
  1895. */
  1896. /* Did we get a valid reply? */
  1897. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  1898. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1899. /*
  1900. * If not been here, done that, save off first WhoInit value
  1901. */
  1902. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  1903. ioc->FirstWhoInit = facts->WhoInit;
  1904. }
  1905. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  1906. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  1907. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  1908. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  1909. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  1910. status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
  1911. /* CHECKME! IOCStatus, IOCLogInfo */
  1912. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  1913. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  1914. /*
  1915. * FC f/w version changed between 1.1 and 1.2
  1916. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  1917. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  1918. */
  1919. if (facts->MsgVersion < 0x0102) {
  1920. /*
  1921. * Handle old FC f/w style, convert to new...
  1922. */
  1923. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  1924. facts->FWVersion.Word =
  1925. ((oldv<<12) & 0xFF000000) |
  1926. ((oldv<<8) & 0x000FFF00);
  1927. } else
  1928. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  1929. facts->ProductID = le16_to_cpu(facts->ProductID);
  1930. facts->CurrentHostMfaHighAddr =
  1931. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  1932. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  1933. facts->CurrentSenseBufferHighAddr =
  1934. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  1935. facts->CurReplyFrameSize =
  1936. le16_to_cpu(facts->CurReplyFrameSize);
  1937. /*
  1938. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  1939. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  1940. * to 14 in MPI-1.01.0x.
  1941. */
  1942. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  1943. facts->MsgVersion > 0x0100) {
  1944. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  1945. }
  1946. sz = facts->FWImageSize;
  1947. if ( sz & 0x01 )
  1948. sz += 1;
  1949. if ( sz & 0x02 )
  1950. sz += 2;
  1951. facts->FWImageSize = sz;
  1952. if (!facts->RequestFrameSize) {
  1953. /* Something is wrong! */
  1954. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  1955. ioc->name);
  1956. return -55;
  1957. }
  1958. r = sz = facts->BlockSize;
  1959. vv = ((63 / (sz * 4)) + 1) & 0x03;
  1960. ioc->NB_for_64_byte_frame = vv;
  1961. while ( sz )
  1962. {
  1963. shiftFactor++;
  1964. sz = sz >> 1;
  1965. }
  1966. ioc->NBShiftFactor = shiftFactor;
  1967. dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  1968. ioc->name, vv, shiftFactor, r));
  1969. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1970. /*
  1971. * Set values for this IOC's request & reply frame sizes,
  1972. * and request & reply queue depths...
  1973. */
  1974. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  1975. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  1976. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  1977. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  1978. dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
  1979. ioc->name, ioc->reply_sz, ioc->reply_depth));
  1980. dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
  1981. ioc->name, ioc->req_sz, ioc->req_depth));
  1982. /* Get port facts! */
  1983. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  1984. return r;
  1985. }
  1986. } else {
  1987. printk(MYIOC_s_ERR_FMT
  1988. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  1989. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  1990. RequestFrameSize)/sizeof(u32)));
  1991. return -66;
  1992. }
  1993. return 0;
  1994. }
  1995. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1996. /*
  1997. * GetPortFacts - Send PortFacts request to MPT adapter.
  1998. * @ioc: Pointer to MPT_ADAPTER structure
  1999. * @portnum: Port number
  2000. * @sleepFlag: Specifies whether the process can sleep
  2001. *
  2002. * Returns 0 for success, non-zero for failure.
  2003. */
  2004. static int
  2005. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2006. {
  2007. PortFacts_t get_pfacts;
  2008. PortFactsReply_t *pfacts;
  2009. int ii;
  2010. int req_sz;
  2011. int reply_sz;
  2012. /* IOC *must* NOT be in RESET state! */
  2013. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2014. printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
  2015. ioc->name,
  2016. ioc->last_state );
  2017. return -4;
  2018. }
  2019. pfacts = &ioc->pfacts[portnum];
  2020. /* Destination (reply area)... */
  2021. reply_sz = sizeof(*pfacts);
  2022. memset(pfacts, 0, reply_sz);
  2023. /* Request area (get_pfacts on the stack right now!) */
  2024. req_sz = sizeof(get_pfacts);
  2025. memset(&get_pfacts, 0, req_sz);
  2026. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2027. get_pfacts.PortNumber = portnum;
  2028. /* Assert: All other get_pfacts fields are zero! */
  2029. dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
  2030. ioc->name, portnum));
  2031. /* No non-zero fields in the get_pfacts request are greater than
  2032. * 1 byte in size, so we can just fire it off as is.
  2033. */
  2034. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2035. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2036. if (ii != 0)
  2037. return ii;
  2038. /* Did we get a valid reply? */
  2039. /* Now byte swap the necessary fields in the response. */
  2040. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2041. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2042. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2043. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2044. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2045. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2046. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2047. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2048. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2049. return 0;
  2050. }
  2051. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2052. /*
  2053. * SendIocInit - Send IOCInit request to MPT adapter.
  2054. * @ioc: Pointer to MPT_ADAPTER structure
  2055. * @sleepFlag: Specifies whether the process can sleep
  2056. *
  2057. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2058. *
  2059. * Returns 0 for success, non-zero for failure.
  2060. */
  2061. static int
  2062. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2063. {
  2064. IOCInit_t ioc_init;
  2065. MPIDefaultReply_t init_reply;
  2066. u32 state;
  2067. int r;
  2068. int count;
  2069. int cntdn;
  2070. memset(&ioc_init, 0, sizeof(ioc_init));
  2071. memset(&init_reply, 0, sizeof(init_reply));
  2072. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2073. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2074. /* If we are in a recovery mode and we uploaded the FW image,
  2075. * then this pointer is not NULL. Skip the upload a second time.
  2076. * Set this flag if cached_fw set for either IOC.
  2077. */
  2078. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2079. ioc->upload_fw = 1;
  2080. else
  2081. ioc->upload_fw = 0;
  2082. ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
  2083. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2084. if (ioc->bus_type == FC)
  2085. ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
  2086. else
  2087. ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
  2088. ioc_init.MaxBuses = MPT_MAX_BUS;
  2089. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2090. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2091. /* Save the upper 32-bits of the request
  2092. * (reply) and sense buffers.
  2093. */
  2094. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2095. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2096. } else {
  2097. /* Force 32-bit addressing */
  2098. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2099. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2100. }
  2101. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2102. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2103. dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
  2104. ioc->name, &ioc_init));
  2105. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2106. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2107. if (r != 0)
  2108. return r;
  2109. /* No need to byte swap the multibyte fields in the reply
  2110. * since we don't even look at it's contents.
  2111. */
  2112. dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
  2113. ioc->name, &ioc_init));
  2114. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
  2115. return r;
  2116. /* YIKES! SUPER IMPORTANT!!!
  2117. * Poll IocState until _OPERATIONAL while IOC is doing
  2118. * LoopInit and TargetDiscovery!
  2119. */
  2120. count = 0;
  2121. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  2122. state = mpt_GetIocState(ioc, 1);
  2123. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  2124. if (sleepFlag == CAN_SLEEP) {
  2125. msleep_interruptible(1);
  2126. } else {
  2127. mdelay(1);
  2128. }
  2129. if (!cntdn) {
  2130. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  2131. ioc->name, (int)((count+5)/HZ));
  2132. return -9;
  2133. }
  2134. state = mpt_GetIocState(ioc, 1);
  2135. count++;
  2136. }
  2137. dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
  2138. ioc->name, count));
  2139. return r;
  2140. }
  2141. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2142. /*
  2143. * SendPortEnable - Send PortEnable request to MPT adapter port.
  2144. * @ioc: Pointer to MPT_ADAPTER structure
  2145. * @portnum: Port number to enable
  2146. * @sleepFlag: Specifies whether the process can sleep
  2147. *
  2148. * Send PortEnable to bring IOC to OPERATIONAL state.
  2149. *
  2150. * Returns 0 for success, non-zero for failure.
  2151. */
  2152. static int
  2153. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2154. {
  2155. PortEnable_t port_enable;
  2156. MPIDefaultReply_t reply_buf;
  2157. int ii;
  2158. int req_sz;
  2159. int reply_sz;
  2160. /* Destination... */
  2161. reply_sz = sizeof(MPIDefaultReply_t);
  2162. memset(&reply_buf, 0, reply_sz);
  2163. req_sz = sizeof(PortEnable_t);
  2164. memset(&port_enable, 0, req_sz);
  2165. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  2166. port_enable.PortNumber = portnum;
  2167. /* port_enable.ChainOffset = 0; */
  2168. /* port_enable.MsgFlags = 0; */
  2169. /* port_enable.MsgContext = 0; */
  2170. dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
  2171. ioc->name, portnum, &port_enable));
  2172. /* RAID FW may take a long time to enable
  2173. */
  2174. if (ioc->bus_type == FC) {
  2175. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2176. reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
  2177. } else {
  2178. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2179. reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
  2180. }
  2181. if (ii != 0)
  2182. return ii;
  2183. /* We do not even look at the reply, so we need not
  2184. * swap the multi-byte fields.
  2185. */
  2186. return 0;
  2187. }
  2188. /*
  2189. * ioc: Pointer to MPT_ADAPTER structure
  2190. * size - total FW bytes
  2191. */
  2192. void
  2193. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  2194. {
  2195. if (ioc->cached_fw)
  2196. return; /* use already allocated memory */
  2197. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2198. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  2199. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  2200. } else {
  2201. if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
  2202. ioc->alloc_total += size;
  2203. }
  2204. }
  2205. /*
  2206. * If alt_img is NULL, delete from ioc structure.
  2207. * Else, delete a secondary image in same format.
  2208. */
  2209. void
  2210. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  2211. {
  2212. int sz;
  2213. sz = ioc->facts.FWImageSize;
  2214. dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2215. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2216. pci_free_consistent(ioc->pcidev, sz,
  2217. ioc->cached_fw, ioc->cached_fw_dma);
  2218. ioc->cached_fw = NULL;
  2219. return;
  2220. }
  2221. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2222. /*
  2223. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  2224. * @ioc: Pointer to MPT_ADAPTER structure
  2225. * @sleepFlag: Specifies whether the process can sleep
  2226. *
  2227. * Returns 0 for success, >0 for handshake failure
  2228. * <0 for fw upload failure.
  2229. *
  2230. * Remark: If bound IOC and a successful FWUpload was performed
  2231. * on the bound IOC, the second image is discarded
  2232. * and memory is free'd. Both channels must upload to prevent
  2233. * IOC from running in degraded mode.
  2234. */
  2235. static int
  2236. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  2237. {
  2238. u8 request[ioc->req_sz];
  2239. u8 reply[sizeof(FWUploadReply_t)];
  2240. FWUpload_t *prequest;
  2241. FWUploadReply_t *preply;
  2242. FWUploadTCSGE_t *ptcsge;
  2243. int sgeoffset;
  2244. u32 flagsLength;
  2245. int ii, sz, reply_sz;
  2246. int cmdStatus;
  2247. /* If the image size is 0, we are done.
  2248. */
  2249. if ((sz = ioc->facts.FWImageSize) == 0)
  2250. return 0;
  2251. mpt_alloc_fw_memory(ioc, sz);
  2252. dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2253. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2254. if (ioc->cached_fw == NULL) {
  2255. /* Major Failure.
  2256. */
  2257. return -ENOMEM;
  2258. }
  2259. prequest = (FWUpload_t *)&request;
  2260. preply = (FWUploadReply_t *)&reply;
  2261. /* Destination... */
  2262. memset(prequest, 0, ioc->req_sz);
  2263. reply_sz = sizeof(reply);
  2264. memset(preply, 0, reply_sz);
  2265. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  2266. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  2267. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  2268. ptcsge->DetailsLength = 12;
  2269. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  2270. ptcsge->ImageSize = cpu_to_le32(sz);
  2271. sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
  2272. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  2273. mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
  2274. sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
  2275. dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
  2276. prequest, sgeoffset));
  2277. DBG_DUMP_FW_REQUEST_FRAME(prequest)
  2278. ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
  2279. reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
  2280. dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
  2281. cmdStatus = -EFAULT;
  2282. if (ii == 0) {
  2283. /* Handshake transfer was complete and successful.
  2284. * Check the Reply Frame.
  2285. */
  2286. int status, transfer_sz;
  2287. status = le16_to_cpu(preply->IOCStatus);
  2288. if (status == MPI_IOCSTATUS_SUCCESS) {
  2289. transfer_sz = le32_to_cpu(preply->ActualImageSize);
  2290. if (transfer_sz == sz)
  2291. cmdStatus = 0;
  2292. }
  2293. }
  2294. dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
  2295. ioc->name, cmdStatus));
  2296. if (cmdStatus) {
  2297. ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
  2298. ioc->name));
  2299. mpt_free_fw_memory(ioc);
  2300. }
  2301. return cmdStatus;
  2302. }
  2303. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2304. /*
  2305. * mpt_downloadboot - DownloadBoot code
  2306. * @ioc: Pointer to MPT_ADAPTER structure
  2307. * @flag: Specify which part of IOC memory is to be uploaded.
  2308. * @sleepFlag: Specifies whether the process can sleep
  2309. *
  2310. * FwDownloadBoot requires Programmed IO access.
  2311. *
  2312. * Returns 0 for success
  2313. * -1 FW Image size is 0
  2314. * -2 No valid cached_fw Pointer
  2315. * <0 for fw upload failure.
  2316. */
  2317. static int
  2318. mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
  2319. {
  2320. MpiFwHeader_t *pFwHeader;
  2321. MpiExtImageHeader_t *pExtImage;
  2322. u32 fwSize;
  2323. u32 diag0val;
  2324. int count;
  2325. u32 *ptrFw;
  2326. u32 diagRwData;
  2327. u32 nextImage;
  2328. u32 load_addr;
  2329. u32 ioc_state=0;
  2330. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
  2331. ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
  2332. if ( ioc->facts.FWImageSize == 0 )
  2333. return -1;
  2334. if (ioc->cached_fw == NULL)
  2335. return -2;
  2336. /* prevent a second downloadboot and memory free with alt_ioc */
  2337. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  2338. ioc->alt_ioc->cached_fw = NULL;
  2339. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2340. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2341. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2342. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2343. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2344. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2345. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  2346. /* wait 1 msec */
  2347. if (sleepFlag == CAN_SLEEP) {
  2348. msleep_interruptible(1);
  2349. } else {
  2350. mdelay (1);
  2351. }
  2352. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2353. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2354. for (count = 0; count < 30; count ++) {
  2355. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2356. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2357. ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
  2358. ioc->name, count));
  2359. break;
  2360. }
  2361. /* wait 1 sec */
  2362. if (sleepFlag == CAN_SLEEP) {
  2363. msleep_interruptible (1000);
  2364. } else {
  2365. mdelay (1000);
  2366. }
  2367. }
  2368. if ( count == 30 ) {
  2369. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
  2370. ioc->name, diag0val));
  2371. return -3;
  2372. }
  2373. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2374. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2375. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2376. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2377. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2378. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2379. /* Set the DiagRwEn and Disable ARM bits */
  2380. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  2381. pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
  2382. fwSize = (pFwHeader->ImageSize + 3)/4;
  2383. ptrFw = (u32 *) pFwHeader;
  2384. /* Write the LoadStartAddress to the DiagRw Address Register
  2385. * using Programmed IO
  2386. */
  2387. if (ioc->errata_flag_1064)
  2388. pci_enable_io_access(ioc->pcidev);
  2389. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  2390. ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
  2391. ioc->name, pFwHeader->LoadStartAddress));
  2392. ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
  2393. ioc->name, fwSize*4, ptrFw));
  2394. while (fwSize--) {
  2395. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2396. }
  2397. nextImage = pFwHeader->NextImageHeaderOffset;
  2398. while (nextImage) {
  2399. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  2400. load_addr = pExtImage->LoadStartAddress;
  2401. fwSize = (pExtImage->ImageSize + 3) >> 2;
  2402. ptrFw = (u32 *)pExtImage;
  2403. ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
  2404. ioc->name, fwSize*4, ptrFw, load_addr));
  2405. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  2406. while (fwSize--) {
  2407. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2408. }
  2409. nextImage = pExtImage->NextImageHeaderOffset;
  2410. }
  2411. /* Write the IopResetVectorRegAddr */
  2412. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  2413. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  2414. /* Write the IopResetVectorValue */
  2415. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  2416. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  2417. /* Clear the internal flash bad bit - autoincrementing register,
  2418. * so must do two writes.
  2419. */
  2420. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2421. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  2422. diagRwData |= 0x4000000;
  2423. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2424. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  2425. if (ioc->errata_flag_1064)
  2426. pci_disable_io_access(ioc->pcidev);
  2427. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2428. ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
  2429. ioc->name, diag0val));
  2430. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
  2431. ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
  2432. ioc->name, diag0val));
  2433. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2434. /* Write 0xFF to reset the sequencer */
  2435. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2436. for (count=0; count<HZ*20; count++) {
  2437. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  2438. ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
  2439. ioc->name, count, ioc_state));
  2440. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  2441. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
  2442. ioc->name));
  2443. return -EFAULT;
  2444. }
  2445. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
  2446. ioc->name));
  2447. return 0;
  2448. }
  2449. if (sleepFlag == CAN_SLEEP) {
  2450. msleep_interruptible (10);
  2451. } else {
  2452. mdelay (10);
  2453. }
  2454. }
  2455. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
  2456. ioc->name, ioc_state));
  2457. return -EFAULT;
  2458. }
  2459. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2460. /*
  2461. * KickStart - Perform hard reset of MPT adapter.
  2462. * @ioc: Pointer to MPT_ADAPTER structure
  2463. * @force: Force hard reset
  2464. * @sleepFlag: Specifies whether the process can sleep
  2465. *
  2466. * This routine places MPT adapter in diagnostic mode via the
  2467. * WriteSequence register, and then performs a hard reset of adapter
  2468. * via the Diagnostic register.
  2469. *
  2470. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  2471. * or NO_SLEEP (interrupt thread, use mdelay)
  2472. * force - 1 if doorbell active, board fault state
  2473. * board operational, IOC_RECOVERY or
  2474. * IOC_BRINGUP and there is an alt_ioc.
  2475. * 0 else
  2476. *
  2477. * Returns:
  2478. * 1 - hard reset, READY
  2479. * 0 - no reset due to History bit, READY
  2480. * -1 - no reset due to History bit but not READY
  2481. * OR reset but failed to come READY
  2482. * -2 - no reset, could not enter DIAG mode
  2483. * -3 - reset but bad FW bit
  2484. */
  2485. static int
  2486. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2487. {
  2488. int hard_reset_done = 0;
  2489. u32 ioc_state=0;
  2490. int cnt,cntdn;
  2491. dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
  2492. if (ioc->bus_type == SCSI) {
  2493. /* Always issue a Msg Unit Reset first. This will clear some
  2494. * SCSI bus hang conditions.
  2495. */
  2496. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  2497. if (sleepFlag == CAN_SLEEP) {
  2498. msleep_interruptible (1000);
  2499. } else {
  2500. mdelay (1000);
  2501. }
  2502. }
  2503. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  2504. if (hard_reset_done < 0)
  2505. return hard_reset_done;
  2506. dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
  2507. ioc->name));
  2508. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  2509. for (cnt=0; cnt<cntdn; cnt++) {
  2510. ioc_state = mpt_GetIocState(ioc, 1);
  2511. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  2512. dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
  2513. ioc->name, cnt));
  2514. return hard_reset_done;
  2515. }
  2516. if (sleepFlag == CAN_SLEEP) {
  2517. msleep_interruptible (10);
  2518. } else {
  2519. mdelay (10);
  2520. }
  2521. }
  2522. printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  2523. ioc->name, ioc_state);
  2524. return -1;
  2525. }
  2526. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2527. /*
  2528. * mpt_diag_reset - Perform hard reset of the adapter.
  2529. * @ioc: Pointer to MPT_ADAPTER structure
  2530. * @ignore: Set if to honor and clear to ignore
  2531. * the reset history bit
  2532. * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
  2533. * else set to NO_SLEEP (use mdelay instead)
  2534. *
  2535. * This routine places the adapter in diagnostic mode via the
  2536. * WriteSequence register and then performs a hard reset of adapter
  2537. * via the Diagnostic register. Adapter should be in ready state
  2538. * upon successful completion.
  2539. *
  2540. * Returns: 1 hard reset successful
  2541. * 0 no reset performed because reset history bit set
  2542. * -2 enabling diagnostic mode failed
  2543. * -3 diagnostic reset failed
  2544. */
  2545. static int
  2546. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  2547. {
  2548. u32 diag0val;
  2549. u32 doorbell;
  2550. int hard_reset_done = 0;
  2551. int count = 0;
  2552. #ifdef MPT_DEBUG
  2553. u32 diag1val = 0;
  2554. #endif
  2555. /* Clear any existing interrupts */
  2556. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2557. /* Use "Diagnostic reset" method! (only thing available!) */
  2558. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2559. #ifdef MPT_DEBUG
  2560. if (ioc->alt_ioc)
  2561. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2562. dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  2563. ioc->name, diag0val, diag1val));
  2564. #endif
  2565. /* Do the reset if we are told to ignore the reset history
  2566. * or if the reset history is 0
  2567. */
  2568. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  2569. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2570. /* Write magic sequence to WriteSequence register
  2571. * Loop until in diagnostic mode
  2572. */
  2573. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2574. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2575. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2576. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2577. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2578. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2579. /* wait 100 msec */
  2580. if (sleepFlag == CAN_SLEEP) {
  2581. msleep_interruptible (100);
  2582. } else {
  2583. mdelay (100);
  2584. }
  2585. count++;
  2586. if (count > 20) {
  2587. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2588. ioc->name, diag0val);
  2589. return -2;
  2590. }
  2591. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2592. dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  2593. ioc->name, diag0val));
  2594. }
  2595. #ifdef MPT_DEBUG
  2596. if (ioc->alt_ioc)
  2597. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2598. dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  2599. ioc->name, diag0val, diag1val));
  2600. #endif
  2601. /*
  2602. * Disable the ARM (Bug fix)
  2603. *
  2604. */
  2605. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  2606. mdelay (1);
  2607. /*
  2608. * Now hit the reset bit in the Diagnostic register
  2609. * (THE BIG HAMMER!) (Clears DRWE bit).
  2610. */
  2611. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2612. hard_reset_done = 1;
  2613. dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
  2614. ioc->name));
  2615. /*
  2616. * Call each currently registered protocol IOC reset handler
  2617. * with pre-reset indication.
  2618. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  2619. * MptResetHandlers[] registered yet.
  2620. */
  2621. {
  2622. int ii;
  2623. int r = 0;
  2624. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  2625. if (MptResetHandlers[ii]) {
  2626. dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
  2627. ioc->name, ii));
  2628. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
  2629. if (ioc->alt_ioc) {
  2630. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
  2631. ioc->name, ioc->alt_ioc->name, ii));
  2632. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
  2633. }
  2634. }
  2635. }
  2636. /* FIXME? Examine results here? */
  2637. }
  2638. if (ioc->cached_fw) {
  2639. /* If the DownloadBoot operation fails, the
  2640. * IOC will be left unusable. This is a fatal error
  2641. * case. _diag_reset will return < 0
  2642. */
  2643. for (count = 0; count < 30; count ++) {
  2644. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2645. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2646. break;
  2647. }
  2648. /* wait 1 sec */
  2649. if (sleepFlag == CAN_SLEEP) {
  2650. ssleep(1);
  2651. } else {
  2652. mdelay (1000);
  2653. }
  2654. }
  2655. if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
  2656. printk(KERN_WARNING MYNAM
  2657. ": firmware downloadboot failure (%d)!\n", count);
  2658. }
  2659. } else {
  2660. /* Wait for FW to reload and for board
  2661. * to go to the READY state.
  2662. * Maximum wait is 60 seconds.
  2663. * If fail, no error will check again
  2664. * with calling program.
  2665. */
  2666. for (count = 0; count < 60; count ++) {
  2667. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  2668. doorbell &= MPI_IOC_STATE_MASK;
  2669. if (doorbell == MPI_IOC_STATE_READY) {
  2670. break;
  2671. }
  2672. /* wait 1 sec */
  2673. if (sleepFlag == CAN_SLEEP) {
  2674. msleep_interruptible (1000);
  2675. } else {
  2676. mdelay (1000);
  2677. }
  2678. }
  2679. }
  2680. }
  2681. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2682. #ifdef MPT_DEBUG
  2683. if (ioc->alt_ioc)
  2684. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2685. dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  2686. ioc->name, diag0val, diag1val));
  2687. #endif
  2688. /* Clear RESET_HISTORY bit! Place board in the
  2689. * diagnostic mode to update the diag register.
  2690. */
  2691. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2692. count = 0;
  2693. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2694. /* Write magic sequence to WriteSequence register
  2695. * Loop until in diagnostic mode
  2696. */
  2697. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2698. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2699. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2700. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2701. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2702. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2703. /* wait 100 msec */
  2704. if (sleepFlag == CAN_SLEEP) {
  2705. msleep_interruptible (100);
  2706. } else {
  2707. mdelay (100);
  2708. }
  2709. count++;
  2710. if (count > 20) {
  2711. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2712. ioc->name, diag0val);
  2713. break;
  2714. }
  2715. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2716. }
  2717. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  2718. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2719. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2720. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  2721. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  2722. ioc->name);
  2723. }
  2724. /* Disable Diagnostic Mode
  2725. */
  2726. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  2727. /* Check FW reload status flags.
  2728. */
  2729. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2730. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  2731. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  2732. ioc->name, diag0val);
  2733. return -3;
  2734. }
  2735. #ifdef MPT_DEBUG
  2736. if (ioc->alt_ioc)
  2737. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2738. dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  2739. ioc->name, diag0val, diag1val));
  2740. #endif
  2741. /*
  2742. * Reset flag that says we've enabled event notification
  2743. */
  2744. ioc->facts.EventState = 0;
  2745. if (ioc->alt_ioc)
  2746. ioc->alt_ioc->facts.EventState = 0;
  2747. return hard_reset_done;
  2748. }
  2749. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2750. /*
  2751. * SendIocReset - Send IOCReset request to MPT adapter.
  2752. * @ioc: Pointer to MPT_ADAPTER structure
  2753. * @reset_type: reset type, expected values are
  2754. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  2755. *
  2756. * Send IOCReset request to the MPT adapter.
  2757. *
  2758. * Returns 0 for success, non-zero for failure.
  2759. */
  2760. static int
  2761. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  2762. {
  2763. int r;
  2764. u32 state;
  2765. int cntdn, count;
  2766. drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
  2767. ioc->name, reset_type));
  2768. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  2769. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  2770. return r;
  2771. /* FW ACK'd request, wait for READY state
  2772. */
  2773. count = 0;
  2774. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  2775. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  2776. cntdn--;
  2777. count++;
  2778. if (!cntdn) {
  2779. if (sleepFlag != CAN_SLEEP)
  2780. count *= 10;
  2781. printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
  2782. ioc->name, (int)((count+5)/HZ));
  2783. return -ETIME;
  2784. }
  2785. if (sleepFlag == CAN_SLEEP) {
  2786. msleep_interruptible(1);
  2787. } else {
  2788. mdelay (1); /* 1 msec delay */
  2789. }
  2790. }
  2791. /* TODO!
  2792. * Cleanup all event stuff for this IOC; re-issue EventNotification
  2793. * request if needed.
  2794. */
  2795. if (ioc->facts.Function)
  2796. ioc->facts.EventState = 0;
  2797. return 0;
  2798. }
  2799. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2800. /*
  2801. * initChainBuffers - Allocate memory for and initialize
  2802. * chain buffers, chain buffer control arrays and spinlock.
  2803. * @hd: Pointer to MPT_SCSI_HOST structure
  2804. * @init: If set, initialize the spin lock.
  2805. */
  2806. static int
  2807. initChainBuffers(MPT_ADAPTER *ioc)
  2808. {
  2809. u8 *mem;
  2810. int sz, ii, num_chain;
  2811. int scale, num_sge, numSGE;
  2812. /* ReqToChain size must equal the req_depth
  2813. * index = req_idx
  2814. */
  2815. if (ioc->ReqToChain == NULL) {
  2816. sz = ioc->req_depth * sizeof(int);
  2817. mem = kmalloc(sz, GFP_ATOMIC);
  2818. if (mem == NULL)
  2819. return -1;
  2820. ioc->ReqToChain = (int *) mem;
  2821. dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
  2822. ioc->name, mem, sz));
  2823. mem = kmalloc(sz, GFP_ATOMIC);
  2824. if (mem == NULL)
  2825. return -1;
  2826. ioc->RequestNB = (int *) mem;
  2827. dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
  2828. ioc->name, mem, sz));
  2829. }
  2830. for (ii = 0; ii < ioc->req_depth; ii++) {
  2831. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  2832. }
  2833. /* ChainToChain size must equal the total number
  2834. * of chain buffers to be allocated.
  2835. * index = chain_idx
  2836. *
  2837. * Calculate the number of chain buffers needed(plus 1) per I/O
  2838. * then multiply the the maximum number of simultaneous cmds
  2839. *
  2840. * num_sge = num sge in request frame + last chain buffer
  2841. * scale = num sge per chain buffer if no chain element
  2842. */
  2843. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  2844. if (sizeof(dma_addr_t) == sizeof(u64))
  2845. num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2846. else
  2847. num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2848. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2849. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2850. (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2851. } else {
  2852. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2853. (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2854. }
  2855. dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
  2856. ioc->name, num_sge, numSGE));
  2857. if ( numSGE > MPT_SCSI_SG_DEPTH )
  2858. numSGE = MPT_SCSI_SG_DEPTH;
  2859. num_chain = 1;
  2860. while (numSGE - num_sge > 0) {
  2861. num_chain++;
  2862. num_sge += (scale - 1);
  2863. }
  2864. num_chain++;
  2865. dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
  2866. ioc->name, numSGE, num_sge, num_chain));
  2867. if (ioc->bus_type == SCSI)
  2868. num_chain *= MPT_SCSI_CAN_QUEUE;
  2869. else
  2870. num_chain *= MPT_FC_CAN_QUEUE;
  2871. ioc->num_chain = num_chain;
  2872. sz = num_chain * sizeof(int);
  2873. if (ioc->ChainToChain == NULL) {
  2874. mem = kmalloc(sz, GFP_ATOMIC);
  2875. if (mem == NULL)
  2876. return -1;
  2877. ioc->ChainToChain = (int *) mem;
  2878. dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
  2879. ioc->name, mem, sz));
  2880. } else {
  2881. mem = (u8 *) ioc->ChainToChain;
  2882. }
  2883. memset(mem, 0xFF, sz);
  2884. return num_chain;
  2885. }
  2886. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2887. /*
  2888. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  2889. * @ioc: Pointer to MPT_ADAPTER structure
  2890. *
  2891. * This routine allocates memory for the MPT reply and request frame
  2892. * pools (if necessary), and primes the IOC reply FIFO with
  2893. * reply frames.
  2894. *
  2895. * Returns 0 for success, non-zero for failure.
  2896. */
  2897. static int
  2898. PrimeIocFifos(MPT_ADAPTER *ioc)
  2899. {
  2900. MPT_FRAME_HDR *mf;
  2901. unsigned long flags;
  2902. dma_addr_t alloc_dma;
  2903. u8 *mem;
  2904. int i, reply_sz, sz, total_size, num_chain;
  2905. /* Prime reply FIFO... */
  2906. if (ioc->reply_frames == NULL) {
  2907. if ( (num_chain = initChainBuffers(ioc)) < 0)
  2908. return -1;
  2909. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  2910. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  2911. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2912. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
  2913. ioc->name, reply_sz, reply_sz));
  2914. sz = (ioc->req_sz * ioc->req_depth);
  2915. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  2916. ioc->name, ioc->req_sz, ioc->req_depth));
  2917. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
  2918. ioc->name, sz, sz));
  2919. total_size += sz;
  2920. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  2921. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  2922. ioc->name, ioc->req_sz, num_chain));
  2923. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  2924. ioc->name, sz, sz, num_chain));
  2925. total_size += sz;
  2926. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  2927. if (mem == NULL) {
  2928. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  2929. ioc->name);
  2930. goto out_fail;
  2931. }
  2932. dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  2933. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  2934. memset(mem, 0, total_size);
  2935. ioc->alloc_total += total_size;
  2936. ioc->alloc = mem;
  2937. ioc->alloc_dma = alloc_dma;
  2938. ioc->alloc_sz = total_size;
  2939. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  2940. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  2941. alloc_dma += reply_sz;
  2942. mem += reply_sz;
  2943. /* Request FIFO - WE manage this! */
  2944. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  2945. ioc->req_frames_dma = alloc_dma;
  2946. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
  2947. ioc->name, mem, (void *)(ulong)alloc_dma));
  2948. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  2949. #if defined(CONFIG_MTRR) && 0
  2950. /*
  2951. * Enable Write Combining MTRR for IOC's memory region.
  2952. * (at least as much as we can; "size and base must be
  2953. * multiples of 4 kiB"
  2954. */
  2955. ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
  2956. sz,
  2957. MTRR_TYPE_WRCOMB, 1);
  2958. dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
  2959. ioc->name, ioc->req_frames_dma, sz));
  2960. #endif
  2961. for (i = 0; i < ioc->req_depth; i++) {
  2962. alloc_dma += ioc->req_sz;
  2963. mem += ioc->req_sz;
  2964. }
  2965. ioc->ChainBuffer = mem;
  2966. ioc->ChainBufferDMA = alloc_dma;
  2967. dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
  2968. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  2969. /* Initialize the free chain Q.
  2970. */
  2971. INIT_LIST_HEAD(&ioc->FreeChainQ);
  2972. /* Post the chain buffers to the FreeChainQ.
  2973. */
  2974. mem = (u8 *)ioc->ChainBuffer;
  2975. for (i=0; i < num_chain; i++) {
  2976. mf = (MPT_FRAME_HDR *) mem;
  2977. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  2978. mem += ioc->req_sz;
  2979. }
  2980. /* Initialize Request frames linked list
  2981. */
  2982. alloc_dma = ioc->req_frames_dma;
  2983. mem = (u8 *) ioc->req_frames;
  2984. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2985. INIT_LIST_HEAD(&ioc->FreeQ);
  2986. for (i = 0; i < ioc->req_depth; i++) {
  2987. mf = (MPT_FRAME_HDR *) mem;
  2988. /* Queue REQUESTs *internally*! */
  2989. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  2990. mem += ioc->req_sz;
  2991. }
  2992. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2993. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  2994. ioc->sense_buf_pool =
  2995. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  2996. if (ioc->sense_buf_pool == NULL) {
  2997. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  2998. ioc->name);
  2999. goto out_fail;
  3000. }
  3001. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  3002. ioc->alloc_total += sz;
  3003. dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
  3004. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  3005. }
  3006. /* Post Reply frames to FIFO
  3007. */
  3008. alloc_dma = ioc->alloc_dma;
  3009. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
  3010. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3011. for (i = 0; i < ioc->reply_depth; i++) {
  3012. /* Write each address to the IOC! */
  3013. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  3014. alloc_dma += ioc->reply_sz;
  3015. }
  3016. return 0;
  3017. out_fail:
  3018. if (ioc->alloc != NULL) {
  3019. sz = ioc->alloc_sz;
  3020. pci_free_consistent(ioc->pcidev,
  3021. sz,
  3022. ioc->alloc, ioc->alloc_dma);
  3023. ioc->reply_frames = NULL;
  3024. ioc->req_frames = NULL;
  3025. ioc->alloc_total -= sz;
  3026. }
  3027. if (ioc->sense_buf_pool != NULL) {
  3028. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3029. pci_free_consistent(ioc->pcidev,
  3030. sz,
  3031. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  3032. ioc->sense_buf_pool = NULL;
  3033. }
  3034. return -1;
  3035. }
  3036. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3037. /**
  3038. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  3039. * from IOC via doorbell handshake method.
  3040. * @ioc: Pointer to MPT_ADAPTER structure
  3041. * @reqBytes: Size of the request in bytes
  3042. * @req: Pointer to MPT request frame
  3043. * @replyBytes: Expected size of the reply in bytes
  3044. * @u16reply: Pointer to area where reply should be written
  3045. * @maxwait: Max wait time for a reply (in seconds)
  3046. * @sleepFlag: Specifies whether the process can sleep
  3047. *
  3048. * NOTES: It is the callers responsibility to byte-swap fields in the
  3049. * request which are greater than 1 byte in size. It is also the
  3050. * callers responsibility to byte-swap response fields which are
  3051. * greater than 1 byte in size.
  3052. *
  3053. * Returns 0 for success, non-zero for failure.
  3054. */
  3055. static int
  3056. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  3057. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  3058. {
  3059. MPIDefaultReply_t *mptReply;
  3060. int failcnt = 0;
  3061. int t;
  3062. /*
  3063. * Get ready to cache a handshake reply
  3064. */
  3065. ioc->hs_reply_idx = 0;
  3066. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3067. mptReply->MsgLength = 0;
  3068. /*
  3069. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  3070. * then tell IOC that we want to handshake a request of N words.
  3071. * (WRITE u32val to Doorbell reg).
  3072. */
  3073. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3074. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  3075. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  3076. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  3077. /*
  3078. * Wait for IOC's doorbell handshake int
  3079. */
  3080. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3081. failcnt++;
  3082. dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  3083. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3084. /* Read doorbell and check for active bit */
  3085. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  3086. return -1;
  3087. /*
  3088. * Clear doorbell int (WRITE 0 to IntStatus reg),
  3089. * then wait for IOC to ACKnowledge that it's ready for
  3090. * our handshake request.
  3091. */
  3092. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3093. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3094. failcnt++;
  3095. if (!failcnt) {
  3096. int ii;
  3097. u8 *req_as_bytes = (u8 *) req;
  3098. /*
  3099. * Stuff request words via doorbell handshake,
  3100. * with ACK from IOC for each.
  3101. */
  3102. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  3103. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  3104. (req_as_bytes[(ii*4) + 1] << 8) |
  3105. (req_as_bytes[(ii*4) + 2] << 16) |
  3106. (req_as_bytes[(ii*4) + 3] << 24));
  3107. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  3108. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3109. failcnt++;
  3110. }
  3111. dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
  3112. DBG_DUMP_REQUEST_FRAME_HDR(req)
  3113. dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
  3114. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  3115. /*
  3116. * Wait for completion of doorbell handshake reply from the IOC
  3117. */
  3118. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  3119. failcnt++;
  3120. dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
  3121. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  3122. /*
  3123. * Copy out the cached reply...
  3124. */
  3125. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  3126. u16reply[ii] = ioc->hs_reply[ii];
  3127. } else {
  3128. return -99;
  3129. }
  3130. return -failcnt;
  3131. }
  3132. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3133. /*
  3134. * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
  3135. * in it's IntStatus register.
  3136. * @ioc: Pointer to MPT_ADAPTER structure
  3137. * @howlong: How long to wait (in seconds)
  3138. * @sleepFlag: Specifies whether the process can sleep
  3139. *
  3140. * This routine waits (up to ~2 seconds max) for IOC doorbell
  3141. * handshake ACKnowledge.
  3142. *
  3143. * Returns a negative value on failure, else wait loop count.
  3144. */
  3145. static int
  3146. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3147. {
  3148. int cntdn;
  3149. int count = 0;
  3150. u32 intstat=0;
  3151. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3152. if (sleepFlag == CAN_SLEEP) {
  3153. while (--cntdn) {
  3154. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3155. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3156. break;
  3157. msleep_interruptible (1);
  3158. count++;
  3159. }
  3160. } else {
  3161. while (--cntdn) {
  3162. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3163. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3164. break;
  3165. mdelay (1);
  3166. count++;
  3167. }
  3168. }
  3169. if (cntdn) {
  3170. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
  3171. ioc->name, count));
  3172. return count;
  3173. }
  3174. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  3175. ioc->name, count, intstat);
  3176. return -1;
  3177. }
  3178. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3179. /*
  3180. * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
  3181. * in it's IntStatus register.
  3182. * @ioc: Pointer to MPT_ADAPTER structure
  3183. * @howlong: How long to wait (in seconds)
  3184. * @sleepFlag: Specifies whether the process can sleep
  3185. *
  3186. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
  3187. *
  3188. * Returns a negative value on failure, else wait loop count.
  3189. */
  3190. static int
  3191. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3192. {
  3193. int cntdn;
  3194. int count = 0;
  3195. u32 intstat=0;
  3196. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3197. if (sleepFlag == CAN_SLEEP) {
  3198. while (--cntdn) {
  3199. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3200. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3201. break;
  3202. msleep_interruptible(1);
  3203. count++;
  3204. }
  3205. } else {
  3206. while (--cntdn) {
  3207. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3208. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3209. break;
  3210. mdelay(1);
  3211. count++;
  3212. }
  3213. }
  3214. if (cntdn) {
  3215. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  3216. ioc->name, count, howlong));
  3217. return count;
  3218. }
  3219. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  3220. ioc->name, count, intstat);
  3221. return -1;
  3222. }
  3223. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3224. /*
  3225. * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
  3226. * @ioc: Pointer to MPT_ADAPTER structure
  3227. * @howlong: How long to wait (in seconds)
  3228. * @sleepFlag: Specifies whether the process can sleep
  3229. *
  3230. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  3231. * Reply is cached to IOC private area large enough to hold a maximum
  3232. * of 128 bytes of reply data.
  3233. *
  3234. * Returns a negative value on failure, else size of reply in WORDS.
  3235. */
  3236. static int
  3237. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3238. {
  3239. int u16cnt = 0;
  3240. int failcnt = 0;
  3241. int t;
  3242. u16 *hs_reply = ioc->hs_reply;
  3243. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3244. u16 hword;
  3245. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  3246. /*
  3247. * Get first two u16's so we can look at IOC's intended reply MsgLength
  3248. */
  3249. u16cnt=0;
  3250. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  3251. failcnt++;
  3252. } else {
  3253. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3254. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3255. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3256. failcnt++;
  3257. else {
  3258. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3259. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3260. }
  3261. }
  3262. dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  3263. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  3264. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3265. /*
  3266. * If no error (and IOC said MsgLength is > 0), piece together
  3267. * reply 16 bits at a time.
  3268. */
  3269. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  3270. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3271. failcnt++;
  3272. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3273. /* don't overflow our IOC hs_reply[] buffer! */
  3274. if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
  3275. hs_reply[u16cnt] = hword;
  3276. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3277. }
  3278. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3279. failcnt++;
  3280. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3281. if (failcnt) {
  3282. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  3283. ioc->name);
  3284. return -failcnt;
  3285. }
  3286. #if 0
  3287. else if (u16cnt != (2 * mptReply->MsgLength)) {
  3288. return -101;
  3289. }
  3290. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  3291. return -102;
  3292. }
  3293. #endif
  3294. dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
  3295. DBG_DUMP_REPLY_FRAME(mptReply)
  3296. dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  3297. ioc->name, t, u16cnt/2));
  3298. return u16cnt/2;
  3299. }
  3300. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3301. /*
  3302. * GetLanConfigPages - Fetch LANConfig pages.
  3303. * @ioc: Pointer to MPT_ADAPTER structure
  3304. *
  3305. * Return: 0 for success
  3306. * -ENOMEM if no memory available
  3307. * -EPERM if not allowed due to ISR context
  3308. * -EAGAIN if no msg frames currently available
  3309. * -EFAULT for non-successful reply or no reply (timeout)
  3310. */
  3311. static int
  3312. GetLanConfigPages(MPT_ADAPTER *ioc)
  3313. {
  3314. ConfigPageHeader_t hdr;
  3315. CONFIGPARMS cfg;
  3316. LANPage0_t *ppage0_alloc;
  3317. dma_addr_t page0_dma;
  3318. LANPage1_t *ppage1_alloc;
  3319. dma_addr_t page1_dma;
  3320. int rc = 0;
  3321. int data_sz;
  3322. int copy_sz;
  3323. /* Get LAN Page 0 header */
  3324. hdr.PageVersion = 0;
  3325. hdr.PageLength = 0;
  3326. hdr.PageNumber = 0;
  3327. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3328. cfg.hdr = &hdr;
  3329. cfg.physAddr = -1;
  3330. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3331. cfg.dir = 0;
  3332. cfg.pageAddr = 0;
  3333. cfg.timeout = 0;
  3334. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3335. return rc;
  3336. if (hdr.PageLength > 0) {
  3337. data_sz = hdr.PageLength * 4;
  3338. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3339. rc = -ENOMEM;
  3340. if (ppage0_alloc) {
  3341. memset((u8 *)ppage0_alloc, 0, data_sz);
  3342. cfg.physAddr = page0_dma;
  3343. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3344. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3345. /* save the data */
  3346. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  3347. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  3348. }
  3349. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3350. /* FIXME!
  3351. * Normalize endianness of structure data,
  3352. * by byte-swapping all > 1 byte fields!
  3353. */
  3354. }
  3355. if (rc)
  3356. return rc;
  3357. }
  3358. /* Get LAN Page 1 header */
  3359. hdr.PageVersion = 0;
  3360. hdr.PageLength = 0;
  3361. hdr.PageNumber = 1;
  3362. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3363. cfg.hdr = &hdr;
  3364. cfg.physAddr = -1;
  3365. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3366. cfg.dir = 0;
  3367. cfg.pageAddr = 0;
  3368. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3369. return rc;
  3370. if (hdr.PageLength == 0)
  3371. return 0;
  3372. data_sz = hdr.PageLength * 4;
  3373. rc = -ENOMEM;
  3374. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  3375. if (ppage1_alloc) {
  3376. memset((u8 *)ppage1_alloc, 0, data_sz);
  3377. cfg.physAddr = page1_dma;
  3378. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3379. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3380. /* save the data */
  3381. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  3382. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  3383. }
  3384. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  3385. /* FIXME!
  3386. * Normalize endianness of structure data,
  3387. * by byte-swapping all > 1 byte fields!
  3388. */
  3389. }
  3390. return rc;
  3391. }
  3392. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3393. /*
  3394. * GetFcPortPage0 - Fetch FCPort config Page0.
  3395. * @ioc: Pointer to MPT_ADAPTER structure
  3396. * @portnum: IOC Port number
  3397. *
  3398. * Return: 0 for success
  3399. * -ENOMEM if no memory available
  3400. * -EPERM if not allowed due to ISR context
  3401. * -EAGAIN if no msg frames currently available
  3402. * -EFAULT for non-successful reply or no reply (timeout)
  3403. */
  3404. static int
  3405. GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
  3406. {
  3407. ConfigPageHeader_t hdr;
  3408. CONFIGPARMS cfg;
  3409. FCPortPage0_t *ppage0_alloc;
  3410. FCPortPage0_t *pp0dest;
  3411. dma_addr_t page0_dma;
  3412. int data_sz;
  3413. int copy_sz;
  3414. int rc;
  3415. /* Get FCPort Page 0 header */
  3416. hdr.PageVersion = 0;
  3417. hdr.PageLength = 0;
  3418. hdr.PageNumber = 0;
  3419. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  3420. cfg.hdr = &hdr;
  3421. cfg.physAddr = -1;
  3422. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3423. cfg.dir = 0;
  3424. cfg.pageAddr = portnum;
  3425. cfg.timeout = 0;
  3426. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3427. return rc;
  3428. if (hdr.PageLength == 0)
  3429. return 0;
  3430. data_sz = hdr.PageLength * 4;
  3431. rc = -ENOMEM;
  3432. ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3433. if (ppage0_alloc) {
  3434. memset((u8 *)ppage0_alloc, 0, data_sz);
  3435. cfg.physAddr = page0_dma;
  3436. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3437. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3438. /* save the data */
  3439. pp0dest = &ioc->fc_port_page0[portnum];
  3440. copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
  3441. memcpy(pp0dest, ppage0_alloc, copy_sz);
  3442. /*
  3443. * Normalize endianness of structure data,
  3444. * by byte-swapping all > 1 byte fields!
  3445. */
  3446. pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
  3447. pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
  3448. pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
  3449. pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
  3450. pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
  3451. pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
  3452. pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
  3453. pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
  3454. pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
  3455. pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
  3456. pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
  3457. pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
  3458. pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
  3459. pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
  3460. pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
  3461. pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
  3462. }
  3463. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3464. }
  3465. return rc;
  3466. }
  3467. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3468. /*
  3469. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  3470. * @ioc: Pointer to MPT_ADAPTER structure
  3471. *
  3472. * Returns: 0 for success
  3473. * -ENOMEM if no memory available
  3474. * -EPERM if not allowed due to ISR context
  3475. * -EAGAIN if no msg frames currently available
  3476. * -EFAULT for non-successful reply or no reply (timeout)
  3477. */
  3478. static int
  3479. GetIoUnitPage2(MPT_ADAPTER *ioc)
  3480. {
  3481. ConfigPageHeader_t hdr;
  3482. CONFIGPARMS cfg;
  3483. IOUnitPage2_t *ppage_alloc;
  3484. dma_addr_t page_dma;
  3485. int data_sz;
  3486. int rc;
  3487. /* Get the page header */
  3488. hdr.PageVersion = 0;
  3489. hdr.PageLength = 0;
  3490. hdr.PageNumber = 2;
  3491. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  3492. cfg.hdr = &hdr;
  3493. cfg.physAddr = -1;
  3494. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3495. cfg.dir = 0;
  3496. cfg.pageAddr = 0;
  3497. cfg.timeout = 0;
  3498. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3499. return rc;
  3500. if (hdr.PageLength == 0)
  3501. return 0;
  3502. /* Read the config page */
  3503. data_sz = hdr.PageLength * 4;
  3504. rc = -ENOMEM;
  3505. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  3506. if (ppage_alloc) {
  3507. memset((u8 *)ppage_alloc, 0, data_sz);
  3508. cfg.physAddr = page_dma;
  3509. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3510. /* If Good, save data */
  3511. if ((rc = mpt_config(ioc, &cfg)) == 0)
  3512. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  3513. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  3514. }
  3515. return rc;
  3516. }
  3517. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3518. /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  3519. * @ioc: Pointer to a Adapter Strucutre
  3520. * @portnum: IOC port number
  3521. *
  3522. * Return: -EFAULT if read of config page header fails
  3523. * or if no nvram
  3524. * If read of SCSI Port Page 0 fails,
  3525. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3526. * Adapter settings: async, narrow
  3527. * Return 1
  3528. * If read of SCSI Port Page 2 fails,
  3529. * Adapter settings valid
  3530. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3531. * Return 1
  3532. * Else
  3533. * Both valid
  3534. * Return 0
  3535. * CHECK - what type of locking mechanisms should be used????
  3536. */
  3537. static int
  3538. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  3539. {
  3540. u8 *pbuf;
  3541. dma_addr_t buf_dma;
  3542. CONFIGPARMS cfg;
  3543. ConfigPageHeader_t header;
  3544. int ii;
  3545. int data, rc = 0;
  3546. /* Allocate memory
  3547. */
  3548. if (!ioc->spi_data.nvram) {
  3549. int sz;
  3550. u8 *mem;
  3551. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  3552. mem = kmalloc(sz, GFP_ATOMIC);
  3553. if (mem == NULL)
  3554. return -EFAULT;
  3555. ioc->spi_data.nvram = (int *) mem;
  3556. dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  3557. ioc->name, ioc->spi_data.nvram, sz));
  3558. }
  3559. /* Invalidate NVRAM information
  3560. */
  3561. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3562. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  3563. }
  3564. /* Read SPP0 header, allocate memory, then read page.
  3565. */
  3566. header.PageVersion = 0;
  3567. header.PageLength = 0;
  3568. header.PageNumber = 0;
  3569. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3570. cfg.hdr = &header;
  3571. cfg.physAddr = -1;
  3572. cfg.pageAddr = portnum;
  3573. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3574. cfg.dir = 0;
  3575. cfg.timeout = 0; /* use default */
  3576. if (mpt_config(ioc, &cfg) != 0)
  3577. return -EFAULT;
  3578. if (header.PageLength > 0) {
  3579. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3580. if (pbuf) {
  3581. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3582. cfg.physAddr = buf_dma;
  3583. if (mpt_config(ioc, &cfg) != 0) {
  3584. ioc->spi_data.maxBusWidth = MPT_NARROW;
  3585. ioc->spi_data.maxSyncOffset = 0;
  3586. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3587. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  3588. rc = 1;
  3589. } else {
  3590. /* Save the Port Page 0 data
  3591. */
  3592. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  3593. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  3594. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  3595. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  3596. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  3597. dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
  3598. ioc->name, pPP0->Capabilities));
  3599. }
  3600. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  3601. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  3602. if (data) {
  3603. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  3604. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  3605. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  3606. } else {
  3607. ioc->spi_data.maxSyncOffset = 0;
  3608. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3609. }
  3610. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  3611. /* Update the minSyncFactor based on bus type.
  3612. */
  3613. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  3614. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  3615. if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
  3616. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  3617. }
  3618. }
  3619. if (pbuf) {
  3620. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3621. }
  3622. }
  3623. }
  3624. /* SCSI Port Page 2 - Read the header then the page.
  3625. */
  3626. header.PageVersion = 0;
  3627. header.PageLength = 0;
  3628. header.PageNumber = 2;
  3629. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3630. cfg.hdr = &header;
  3631. cfg.physAddr = -1;
  3632. cfg.pageAddr = portnum;
  3633. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3634. cfg.dir = 0;
  3635. if (mpt_config(ioc, &cfg) != 0)
  3636. return -EFAULT;
  3637. if (header.PageLength > 0) {
  3638. /* Allocate memory and read SCSI Port Page 2
  3639. */
  3640. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3641. if (pbuf) {
  3642. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  3643. cfg.physAddr = buf_dma;
  3644. if (mpt_config(ioc, &cfg) != 0) {
  3645. /* Nvram data is left with INVALID mark
  3646. */
  3647. rc = 1;
  3648. } else {
  3649. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  3650. MpiDeviceInfo_t *pdevice = NULL;
  3651. /* Save the Port Page 2 data
  3652. * (reformat into a 32bit quantity)
  3653. */
  3654. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  3655. ioc->spi_data.PortFlags = data;
  3656. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3657. pdevice = &pPP2->DeviceSettings[ii];
  3658. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  3659. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  3660. ioc->spi_data.nvram[ii] = data;
  3661. }
  3662. }
  3663. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3664. }
  3665. }
  3666. /* Update Adapter limits with those from NVRAM
  3667. * Comment: Don't need to do this. Target performance
  3668. * parameters will never exceed the adapters limits.
  3669. */
  3670. return rc;
  3671. }
  3672. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3673. /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
  3674. * @ioc: Pointer to a Adapter Strucutre
  3675. * @portnum: IOC port number
  3676. *
  3677. * Return: -EFAULT if read of config page header fails
  3678. * or 0 if success.
  3679. */
  3680. static int
  3681. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  3682. {
  3683. CONFIGPARMS cfg;
  3684. ConfigPageHeader_t header;
  3685. /* Read the SCSI Device Page 1 header
  3686. */
  3687. header.PageVersion = 0;
  3688. header.PageLength = 0;
  3689. header.PageNumber = 1;
  3690. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3691. cfg.hdr = &header;
  3692. cfg.physAddr = -1;
  3693. cfg.pageAddr = portnum;
  3694. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3695. cfg.dir = 0;
  3696. cfg.timeout = 0;
  3697. if (mpt_config(ioc, &cfg) != 0)
  3698. return -EFAULT;
  3699. ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
  3700. ioc->spi_data.sdp1length = cfg.hdr->PageLength;
  3701. header.PageVersion = 0;
  3702. header.PageLength = 0;
  3703. header.PageNumber = 0;
  3704. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3705. if (mpt_config(ioc, &cfg) != 0)
  3706. return -EFAULT;
  3707. ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
  3708. ioc->spi_data.sdp0length = cfg.hdr->PageLength;
  3709. dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
  3710. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  3711. dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
  3712. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  3713. return 0;
  3714. }
  3715. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3716. /**
  3717. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  3718. * @ioc: Pointer to a Adapter Strucutre
  3719. * @portnum: IOC port number
  3720. *
  3721. * Return:
  3722. * 0 on success
  3723. * -EFAULT if read of config page header fails or data pointer not NULL
  3724. * -ENOMEM if pci_alloc failed
  3725. */
  3726. int
  3727. mpt_findImVolumes(MPT_ADAPTER *ioc)
  3728. {
  3729. IOCPage2_t *pIoc2;
  3730. u8 *mem;
  3731. ConfigPageIoc2RaidVol_t *pIocRv;
  3732. dma_addr_t ioc2_dma;
  3733. CONFIGPARMS cfg;
  3734. ConfigPageHeader_t header;
  3735. int jj;
  3736. int rc = 0;
  3737. int iocpage2sz;
  3738. u8 nVols, nPhys;
  3739. u8 vid, vbus, vioc;
  3740. /* Read IOCP2 header then the page.
  3741. */
  3742. header.PageVersion = 0;
  3743. header.PageLength = 0;
  3744. header.PageNumber = 2;
  3745. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3746. cfg.hdr = &header;
  3747. cfg.physAddr = -1;
  3748. cfg.pageAddr = 0;
  3749. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3750. cfg.dir = 0;
  3751. cfg.timeout = 0;
  3752. if (mpt_config(ioc, &cfg) != 0)
  3753. return -EFAULT;
  3754. if (header.PageLength == 0)
  3755. return -EFAULT;
  3756. iocpage2sz = header.PageLength * 4;
  3757. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  3758. if (!pIoc2)
  3759. return -ENOMEM;
  3760. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3761. cfg.physAddr = ioc2_dma;
  3762. if (mpt_config(ioc, &cfg) != 0)
  3763. goto done_and_free;
  3764. if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
  3765. mem = kmalloc(iocpage2sz, GFP_ATOMIC);
  3766. if (mem) {
  3767. ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
  3768. } else {
  3769. goto done_and_free;
  3770. }
  3771. }
  3772. memcpy(mem, (u8 *)pIoc2, iocpage2sz);
  3773. /* Identify RAID Volume Id's */
  3774. nVols = pIoc2->NumActiveVolumes;
  3775. if ( nVols == 0) {
  3776. /* No RAID Volume.
  3777. */
  3778. goto done_and_free;
  3779. } else {
  3780. /* At least 1 RAID Volume
  3781. */
  3782. pIocRv = pIoc2->RaidVolume;
  3783. ioc->spi_data.isRaid = 0;
  3784. for (jj = 0; jj < nVols; jj++, pIocRv++) {
  3785. vid = pIocRv->VolumeID;
  3786. vbus = pIocRv->VolumeBus;
  3787. vioc = pIocRv->VolumeIOC;
  3788. /* find the match
  3789. */
  3790. if (vbus == 0) {
  3791. ioc->spi_data.isRaid |= (1 << vid);
  3792. } else {
  3793. /* Error! Always bus 0
  3794. */
  3795. }
  3796. }
  3797. }
  3798. /* Identify Hidden Physical Disk Id's */
  3799. nPhys = pIoc2->NumActivePhysDisks;
  3800. if (nPhys == 0) {
  3801. /* No physical disks.
  3802. */
  3803. } else {
  3804. mpt_read_ioc_pg_3(ioc);
  3805. }
  3806. done_and_free:
  3807. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  3808. return rc;
  3809. }
  3810. int
  3811. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  3812. {
  3813. IOCPage3_t *pIoc3;
  3814. u8 *mem;
  3815. CONFIGPARMS cfg;
  3816. ConfigPageHeader_t header;
  3817. dma_addr_t ioc3_dma;
  3818. int iocpage3sz = 0;
  3819. /* Free the old page
  3820. */
  3821. kfree(ioc->spi_data.pIocPg3);
  3822. ioc->spi_data.pIocPg3 = NULL;
  3823. /* There is at least one physical disk.
  3824. * Read and save IOC Page 3
  3825. */
  3826. header.PageVersion = 0;
  3827. header.PageLength = 0;
  3828. header.PageNumber = 3;
  3829. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3830. cfg.hdr = &header;
  3831. cfg.physAddr = -1;
  3832. cfg.pageAddr = 0;
  3833. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3834. cfg.dir = 0;
  3835. cfg.timeout = 0;
  3836. if (mpt_config(ioc, &cfg) != 0)
  3837. return 0;
  3838. if (header.PageLength == 0)
  3839. return 0;
  3840. /* Read Header good, alloc memory
  3841. */
  3842. iocpage3sz = header.PageLength * 4;
  3843. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  3844. if (!pIoc3)
  3845. return 0;
  3846. /* Read the Page and save the data
  3847. * into malloc'd memory.
  3848. */
  3849. cfg.physAddr = ioc3_dma;
  3850. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3851. if (mpt_config(ioc, &cfg) == 0) {
  3852. mem = kmalloc(iocpage3sz, GFP_ATOMIC);
  3853. if (mem) {
  3854. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  3855. ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
  3856. }
  3857. }
  3858. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  3859. return 0;
  3860. }
  3861. static void
  3862. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  3863. {
  3864. IOCPage4_t *pIoc4;
  3865. CONFIGPARMS cfg;
  3866. ConfigPageHeader_t header;
  3867. dma_addr_t ioc4_dma;
  3868. int iocpage4sz;
  3869. /* Read and save IOC Page 4
  3870. */
  3871. header.PageVersion = 0;
  3872. header.PageLength = 0;
  3873. header.PageNumber = 4;
  3874. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3875. cfg.hdr = &header;
  3876. cfg.physAddr = -1;
  3877. cfg.pageAddr = 0;
  3878. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3879. cfg.dir = 0;
  3880. cfg.timeout = 0;
  3881. if (mpt_config(ioc, &cfg) != 0)
  3882. return;
  3883. if (header.PageLength == 0)
  3884. return;
  3885. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  3886. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  3887. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  3888. if (!pIoc4)
  3889. return;
  3890. } else {
  3891. ioc4_dma = ioc->spi_data.IocPg4_dma;
  3892. iocpage4sz = ioc->spi_data.IocPg4Sz;
  3893. }
  3894. /* Read the Page into dma memory.
  3895. */
  3896. cfg.physAddr = ioc4_dma;
  3897. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3898. if (mpt_config(ioc, &cfg) == 0) {
  3899. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  3900. ioc->spi_data.IocPg4_dma = ioc4_dma;
  3901. ioc->spi_data.IocPg4Sz = iocpage4sz;
  3902. } else {
  3903. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  3904. ioc->spi_data.pIocPg4 = NULL;
  3905. }
  3906. }
  3907. static void
  3908. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  3909. {
  3910. IOCPage1_t *pIoc1;
  3911. CONFIGPARMS cfg;
  3912. ConfigPageHeader_t header;
  3913. dma_addr_t ioc1_dma;
  3914. int iocpage1sz = 0;
  3915. u32 tmp;
  3916. /* Check the Coalescing Timeout in IOC Page 1
  3917. */
  3918. header.PageVersion = 0;
  3919. header.PageLength = 0;
  3920. header.PageNumber = 1;
  3921. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3922. cfg.hdr = &header;
  3923. cfg.physAddr = -1;
  3924. cfg.pageAddr = 0;
  3925. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3926. cfg.dir = 0;
  3927. cfg.timeout = 0;
  3928. if (mpt_config(ioc, &cfg) != 0)
  3929. return;
  3930. if (header.PageLength == 0)
  3931. return;
  3932. /* Read Header good, alloc memory
  3933. */
  3934. iocpage1sz = header.PageLength * 4;
  3935. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  3936. if (!pIoc1)
  3937. return;
  3938. /* Read the Page and check coalescing timeout
  3939. */
  3940. cfg.physAddr = ioc1_dma;
  3941. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3942. if (mpt_config(ioc, &cfg) == 0) {
  3943. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  3944. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  3945. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  3946. dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
  3947. ioc->name, tmp));
  3948. if (tmp > MPT_COALESCING_TIMEOUT) {
  3949. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  3950. /* Write NVRAM and current
  3951. */
  3952. cfg.dir = 1;
  3953. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3954. if (mpt_config(ioc, &cfg) == 0) {
  3955. dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
  3956. ioc->name, MPT_COALESCING_TIMEOUT));
  3957. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  3958. if (mpt_config(ioc, &cfg) == 0) {
  3959. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
  3960. ioc->name, MPT_COALESCING_TIMEOUT));
  3961. } else {
  3962. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
  3963. ioc->name));
  3964. }
  3965. } else {
  3966. dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
  3967. ioc->name));
  3968. }
  3969. }
  3970. } else {
  3971. dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  3972. }
  3973. }
  3974. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  3975. return;
  3976. }
  3977. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3978. /*
  3979. * SendEventNotification - Send EventNotification (on or off) request
  3980. * to MPT adapter.
  3981. * @ioc: Pointer to MPT_ADAPTER structure
  3982. * @EvSwitch: Event switch flags
  3983. */
  3984. static int
  3985. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
  3986. {
  3987. EventNotification_t *evnp;
  3988. evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
  3989. if (evnp == NULL) {
  3990. dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
  3991. ioc->name));
  3992. return 0;
  3993. }
  3994. memset(evnp, 0, sizeof(*evnp));
  3995. dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
  3996. evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  3997. evnp->ChainOffset = 0;
  3998. evnp->MsgFlags = 0;
  3999. evnp->Switch = EvSwitch;
  4000. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
  4001. return 0;
  4002. }
  4003. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4004. /**
  4005. * SendEventAck - Send EventAck request to MPT adapter.
  4006. * @ioc: Pointer to MPT_ADAPTER structure
  4007. * @evnp: Pointer to original EventNotification request
  4008. */
  4009. static int
  4010. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  4011. {
  4012. EventAck_t *pAck;
  4013. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4014. printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
  4015. ioc->name);
  4016. return -1;
  4017. }
  4018. memset(pAck, 0, sizeof(*pAck));
  4019. dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
  4020. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  4021. pAck->ChainOffset = 0;
  4022. pAck->MsgFlags = 0;
  4023. pAck->Event = evnp->Event;
  4024. pAck->EventContext = evnp->EventContext;
  4025. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  4026. return 0;
  4027. }
  4028. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4029. /**
  4030. * mpt_config - Generic function to issue config message
  4031. * @ioc - Pointer to an adapter structure
  4032. * @cfg - Pointer to a configuration structure. Struct contains
  4033. * action, page address, direction, physical address
  4034. * and pointer to a configuration page header
  4035. * Page header is updated.
  4036. *
  4037. * Returns 0 for success
  4038. * -EPERM if not allowed due to ISR context
  4039. * -EAGAIN if no msg frames currently available
  4040. * -EFAULT for non-successful reply or no reply (timeout)
  4041. */
  4042. int
  4043. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4044. {
  4045. Config_t *pReq;
  4046. MPT_FRAME_HDR *mf;
  4047. unsigned long flags;
  4048. int ii, rc;
  4049. u32 flagsLength;
  4050. int in_isr;
  4051. /* Prevent calling wait_event() (below), if caller happens
  4052. * to be in ISR context, because that is fatal!
  4053. */
  4054. in_isr = in_interrupt();
  4055. if (in_isr) {
  4056. dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  4057. ioc->name));
  4058. return -EPERM;
  4059. }
  4060. /* Get and Populate a free Frame
  4061. */
  4062. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4063. dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
  4064. ioc->name));
  4065. return -EAGAIN;
  4066. }
  4067. pReq = (Config_t *)mf;
  4068. pReq->Action = pCfg->action;
  4069. pReq->Reserved = 0;
  4070. pReq->ChainOffset = 0;
  4071. pReq->Function = MPI_FUNCTION_CONFIG;
  4072. pReq->ExtPageLength = 0;
  4073. pReq->ExtPageType = 0;
  4074. pReq->MsgFlags = 0;
  4075. for (ii=0; ii < 8; ii++)
  4076. pReq->Reserved2[ii] = 0;
  4077. pReq->Header.PageVersion = pCfg->hdr->PageVersion;
  4078. pReq->Header.PageLength = pCfg->hdr->PageLength;
  4079. pReq->Header.PageNumber = pCfg->hdr->PageNumber;
  4080. pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  4081. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  4082. /* Add a SGE to the config request.
  4083. */
  4084. if (pCfg->dir)
  4085. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  4086. else
  4087. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  4088. flagsLength |= pCfg->hdr->PageLength * 4;
  4089. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  4090. dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
  4091. ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
  4092. /* Append pCfg pointer to end of mf
  4093. */
  4094. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4095. /* Initalize the timer
  4096. */
  4097. init_timer(&pCfg->timer);
  4098. pCfg->timer.data = (unsigned long) ioc;
  4099. pCfg->timer.function = mpt_timer_expired;
  4100. pCfg->wait_done = 0;
  4101. /* Set the timer; ensure 10 second minimum */
  4102. if (pCfg->timeout < 10)
  4103. pCfg->timer.expires = jiffies + HZ*10;
  4104. else
  4105. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4106. /* Add to end of Q, set timer and then issue this command */
  4107. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4108. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4109. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4110. add_timer(&pCfg->timer);
  4111. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4112. wait_event(mpt_waitq, pCfg->wait_done);
  4113. /* mf has been freed - do not access */
  4114. rc = pCfg->status;
  4115. return rc;
  4116. }
  4117. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4118. /**
  4119. * mpt_toolbox - Generic function to issue toolbox message
  4120. * @ioc - Pointer to an adapter structure
  4121. * @cfg - Pointer to a toolbox structure. Struct contains
  4122. * action, page address, direction, physical address
  4123. * and pointer to a configuration page header
  4124. * Page header is updated.
  4125. *
  4126. * Returns 0 for success
  4127. * -EPERM if not allowed due to ISR context
  4128. * -EAGAIN if no msg frames currently available
  4129. * -EFAULT for non-successful reply or no reply (timeout)
  4130. */
  4131. int
  4132. mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4133. {
  4134. ToolboxIstwiReadWriteRequest_t *pReq;
  4135. MPT_FRAME_HDR *mf;
  4136. struct pci_dev *pdev;
  4137. unsigned long flags;
  4138. int rc;
  4139. u32 flagsLength;
  4140. int in_isr;
  4141. /* Prevent calling wait_event() (below), if caller happens
  4142. * to be in ISR context, because that is fatal!
  4143. */
  4144. in_isr = in_interrupt();
  4145. if (in_isr) {
  4146. dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
  4147. ioc->name));
  4148. return -EPERM;
  4149. }
  4150. /* Get and Populate a free Frame
  4151. */
  4152. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4153. dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
  4154. ioc->name));
  4155. return -EAGAIN;
  4156. }
  4157. pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
  4158. pReq->Tool = pCfg->action;
  4159. pReq->Reserved = 0;
  4160. pReq->ChainOffset = 0;
  4161. pReq->Function = MPI_FUNCTION_TOOLBOX;
  4162. pReq->Reserved1 = 0;
  4163. pReq->Reserved2 = 0;
  4164. pReq->MsgFlags = 0;
  4165. pReq->Flags = pCfg->dir;
  4166. pReq->BusNum = 0;
  4167. pReq->Reserved3 = 0;
  4168. pReq->NumAddressBytes = 0x01;
  4169. pReq->Reserved4 = 0;
  4170. pReq->DataLength = 0x04;
  4171. pdev = (struct pci_dev *) ioc->pcidev;
  4172. if (pdev->devfn & 1)
  4173. pReq->DeviceAddr = 0xB2;
  4174. else
  4175. pReq->DeviceAddr = 0xB0;
  4176. pReq->Addr1 = 0;
  4177. pReq->Addr2 = 0;
  4178. pReq->Addr3 = 0;
  4179. pReq->Reserved5 = 0;
  4180. /* Add a SGE to the config request.
  4181. */
  4182. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
  4183. mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
  4184. dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
  4185. ioc->name, pReq->Tool));
  4186. /* Append pCfg pointer to end of mf
  4187. */
  4188. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4189. /* Initalize the timer
  4190. */
  4191. init_timer(&pCfg->timer);
  4192. pCfg->timer.data = (unsigned long) ioc;
  4193. pCfg->timer.function = mpt_timer_expired;
  4194. pCfg->wait_done = 0;
  4195. /* Set the timer; ensure 10 second minimum */
  4196. if (pCfg->timeout < 10)
  4197. pCfg->timer.expires = jiffies + HZ*10;
  4198. else
  4199. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4200. /* Add to end of Q, set timer and then issue this command */
  4201. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4202. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4203. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4204. add_timer(&pCfg->timer);
  4205. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4206. wait_event(mpt_waitq, pCfg->wait_done);
  4207. /* mf has been freed - do not access */
  4208. rc = pCfg->status;
  4209. return rc;
  4210. }
  4211. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4212. /*
  4213. * mpt_timer_expired - Call back for timer process.
  4214. * Used only internal config functionality.
  4215. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  4216. */
  4217. static void
  4218. mpt_timer_expired(unsigned long data)
  4219. {
  4220. MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
  4221. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
  4222. /* Perform a FW reload */
  4223. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
  4224. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
  4225. /* No more processing.
  4226. * Hard reset clean-up will wake up
  4227. * process and free all resources.
  4228. */
  4229. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
  4230. return;
  4231. }
  4232. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4233. /*
  4234. * mpt_ioc_reset - Base cleanup for hard reset
  4235. * @ioc: Pointer to the adapter structure
  4236. * @reset_phase: Indicates pre- or post-reset functionality
  4237. *
  4238. * Remark: Free's resources with internally generated commands.
  4239. */
  4240. static int
  4241. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  4242. {
  4243. CONFIGPARMS *pCfg;
  4244. unsigned long flags;
  4245. dprintk((KERN_WARNING MYNAM
  4246. ": IOC %s_reset routed to MPT base driver!\n",
  4247. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  4248. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  4249. if (reset_phase == MPT_IOC_SETUP_RESET) {
  4250. ;
  4251. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  4252. /* If the internal config Q is not empty -
  4253. * delete timer. MF resources will be freed when
  4254. * the FIFO's are primed.
  4255. */
  4256. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4257. list_for_each_entry(pCfg, &ioc->configQ, linkage)
  4258. del_timer(&pCfg->timer);
  4259. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4260. } else {
  4261. CONFIGPARMS *pNext;
  4262. /* Search the configQ for internal commands.
  4263. * Flush the Q, and wake up all suspended threads.
  4264. */
  4265. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4266. list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
  4267. list_del(&pCfg->linkage);
  4268. pCfg->status = MPT_CONFIG_ERROR;
  4269. pCfg->wait_done = 1;
  4270. wake_up(&mpt_waitq);
  4271. }
  4272. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4273. }
  4274. return 1; /* currently means nothing really */
  4275. }
  4276. #ifdef CONFIG_PROC_FS /* { */
  4277. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4278. /*
  4279. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  4280. */
  4281. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4282. /*
  4283. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  4284. *
  4285. * Returns 0 for success, non-zero for failure.
  4286. */
  4287. static int
  4288. procmpt_create(void)
  4289. {
  4290. struct proc_dir_entry *ent;
  4291. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  4292. if (mpt_proc_root_dir == NULL)
  4293. return -ENOTDIR;
  4294. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4295. if (ent)
  4296. ent->read_proc = procmpt_summary_read;
  4297. ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4298. if (ent)
  4299. ent->read_proc = procmpt_version_read;
  4300. return 0;
  4301. }
  4302. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4303. /*
  4304. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  4305. *
  4306. * Returns 0 for success, non-zero for failure.
  4307. */
  4308. static void
  4309. procmpt_destroy(void)
  4310. {
  4311. remove_proc_entry("version", mpt_proc_root_dir);
  4312. remove_proc_entry("summary", mpt_proc_root_dir);
  4313. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  4314. }
  4315. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4316. /*
  4317. * procmpt_summary_read - Handle read request from /proc/mpt/summary
  4318. * or from /proc/mpt/iocN/summary.
  4319. * @buf: Pointer to area to write information
  4320. * @start: Pointer to start pointer
  4321. * @offset: Offset to start writing
  4322. * @request:
  4323. * @eof: Pointer to EOF integer
  4324. * @data: Pointer
  4325. *
  4326. * Returns number of characters written to process performing the read.
  4327. */
  4328. static int
  4329. procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4330. {
  4331. MPT_ADAPTER *ioc;
  4332. char *out = buf;
  4333. int len;
  4334. if (data) {
  4335. int more = 0;
  4336. ioc = data;
  4337. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4338. out += more;
  4339. } else {
  4340. list_for_each_entry(ioc, &ioc_list, list) {
  4341. int more = 0;
  4342. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4343. out += more;
  4344. if ((out-buf) >= request)
  4345. break;
  4346. }
  4347. }
  4348. len = out - buf;
  4349. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4350. }
  4351. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4352. /*
  4353. * procmpt_version_read - Handle read request from /proc/mpt/version.
  4354. * @buf: Pointer to area to write information
  4355. * @start: Pointer to start pointer
  4356. * @offset: Offset to start writing
  4357. * @request:
  4358. * @eof: Pointer to EOF integer
  4359. * @data: Pointer
  4360. *
  4361. * Returns number of characters written to process performing the read.
  4362. */
  4363. static int
  4364. procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4365. {
  4366. int ii;
  4367. int scsi, fc, sas, lan, ctl, targ, dmp;
  4368. char *drvname;
  4369. int len;
  4370. len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  4371. len += sprintf(buf+len, " Fusion MPT base driver\n");
  4372. scsi = fc = sas = lan = ctl = targ = dmp = 0;
  4373. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4374. drvname = NULL;
  4375. if (MptCallbacks[ii]) {
  4376. switch (MptDriverClass[ii]) {
  4377. case MPTSPI_DRIVER:
  4378. if (!scsi++) drvname = "SPI host";
  4379. break;
  4380. case MPTFC_DRIVER:
  4381. if (!fc++) drvname = "FC host";
  4382. break;
  4383. case MPTSAS_DRIVER:
  4384. if (!sas++) drvname = "SAS host";
  4385. break;
  4386. case MPTLAN_DRIVER:
  4387. if (!lan++) drvname = "LAN";
  4388. break;
  4389. case MPTSTM_DRIVER:
  4390. if (!targ++) drvname = "SCSI target";
  4391. break;
  4392. case MPTCTL_DRIVER:
  4393. if (!ctl++) drvname = "ioctl";
  4394. break;
  4395. }
  4396. if (drvname)
  4397. len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
  4398. }
  4399. }
  4400. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4401. }
  4402. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4403. /*
  4404. * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
  4405. * @buf: Pointer to area to write information
  4406. * @start: Pointer to start pointer
  4407. * @offset: Offset to start writing
  4408. * @request:
  4409. * @eof: Pointer to EOF integer
  4410. * @data: Pointer
  4411. *
  4412. * Returns number of characters written to process performing the read.
  4413. */
  4414. static int
  4415. procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4416. {
  4417. MPT_ADAPTER *ioc = data;
  4418. int len;
  4419. char expVer[32];
  4420. int sz;
  4421. int p;
  4422. mpt_get_fw_exp_ver(expVer, ioc);
  4423. len = sprintf(buf, "%s:", ioc->name);
  4424. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  4425. len += sprintf(buf+len, " (f/w download boot flag set)");
  4426. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  4427. // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
  4428. len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
  4429. ioc->facts.ProductID,
  4430. ioc->prod_name);
  4431. len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  4432. if (ioc->facts.FWImageSize)
  4433. len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
  4434. len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  4435. len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  4436. len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
  4437. len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
  4438. ioc->facts.CurrentHostMfaHighAddr);
  4439. len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
  4440. ioc->facts.CurrentSenseBufferHighAddr);
  4441. len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  4442. len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  4443. len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  4444. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  4445. /*
  4446. * Rounding UP to nearest 4-kB boundary here...
  4447. */
  4448. sz = (ioc->req_sz * ioc->req_depth) + 128;
  4449. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  4450. len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  4451. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  4452. len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  4453. 4*ioc->facts.RequestFrameSize,
  4454. ioc->facts.GlobalCredits);
  4455. len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
  4456. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  4457. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  4458. len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  4459. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  4460. len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  4461. ioc->facts.CurReplyFrameSize,
  4462. ioc->facts.ReplyQueueDepth);
  4463. len += sprintf(buf+len, " MaxDevices = %d\n",
  4464. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  4465. len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  4466. /* per-port info */
  4467. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  4468. len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
  4469. p+1,
  4470. ioc->facts.NumberOfPorts);
  4471. if (ioc->bus_type == FC) {
  4472. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  4473. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4474. len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  4475. a[5], a[4], a[3], a[2], a[1], a[0]);
  4476. }
  4477. len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
  4478. ioc->fc_port_page0[p].WWNN.High,
  4479. ioc->fc_port_page0[p].WWNN.Low,
  4480. ioc->fc_port_page0[p].WWPN.High,
  4481. ioc->fc_port_page0[p].WWPN.Low);
  4482. }
  4483. }
  4484. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4485. }
  4486. #endif /* CONFIG_PROC_FS } */
  4487. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4488. static void
  4489. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  4490. {
  4491. buf[0] ='\0';
  4492. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  4493. sprintf(buf, " (Exp %02d%02d)",
  4494. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  4495. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  4496. /* insider hack! */
  4497. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  4498. strcat(buf, " [MDBG]");
  4499. }
  4500. }
  4501. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4502. /**
  4503. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  4504. * @ioc: Pointer to MPT_ADAPTER structure
  4505. * @buffer: Pointer to buffer where IOC summary info should be written
  4506. * @size: Pointer to number of bytes we wrote (set by this routine)
  4507. * @len: Offset at which to start writing in buffer
  4508. * @showlan: Display LAN stuff?
  4509. *
  4510. * This routine writes (english readable) ASCII text, which represents
  4511. * a summary of IOC information, to a buffer.
  4512. */
  4513. void
  4514. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  4515. {
  4516. char expVer[32];
  4517. int y;
  4518. mpt_get_fw_exp_ver(expVer, ioc);
  4519. /*
  4520. * Shorter summary of attached ioc's...
  4521. */
  4522. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  4523. ioc->name,
  4524. ioc->prod_name,
  4525. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  4526. ioc->facts.FWVersion.Word,
  4527. expVer,
  4528. ioc->facts.NumberOfPorts,
  4529. ioc->req_depth);
  4530. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  4531. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4532. y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  4533. a[5], a[4], a[3], a[2], a[1], a[0]);
  4534. }
  4535. #ifndef __sparc__
  4536. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  4537. #else
  4538. y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
  4539. #endif
  4540. if (!ioc->active)
  4541. y += sprintf(buffer+len+y, " (disabled)");
  4542. y += sprintf(buffer+len+y, "\n");
  4543. *size = y;
  4544. }
  4545. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4546. /*
  4547. * Reset Handling
  4548. */
  4549. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4550. /**
  4551. * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
  4552. * Management call based on input arg values. If TaskMgmt fails,
  4553. * return associated SCSI request.
  4554. * @ioc: Pointer to MPT_ADAPTER structure
  4555. * @sleepFlag: Indicates if sleep or schedule must be called.
  4556. *
  4557. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  4558. * or a non-interrupt thread. In the former, must not call schedule().
  4559. *
  4560. * Remark: A return of -1 is a FATAL error case, as it means a
  4561. * FW reload/initialization failed.
  4562. *
  4563. * Returns 0 for SUCCESS or -1 if FAILED.
  4564. */
  4565. int
  4566. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  4567. {
  4568. int rc;
  4569. unsigned long flags;
  4570. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
  4571. #ifdef MFCNT
  4572. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  4573. printk("MF count 0x%x !\n", ioc->mfcnt);
  4574. #endif
  4575. /* Reset the adapter. Prevent more than 1 call to
  4576. * mpt_do_ioc_recovery at any instant in time.
  4577. */
  4578. spin_lock_irqsave(&ioc->diagLock, flags);
  4579. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
  4580. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4581. return 0;
  4582. } else {
  4583. ioc->diagPending = 1;
  4584. }
  4585. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4586. /* FIXME: If do_ioc_recovery fails, repeat....
  4587. */
  4588. /* The SCSI driver needs to adjust timeouts on all current
  4589. * commands prior to the diagnostic reset being issued.
  4590. * Prevents timeouts occuring during a diagnostic reset...very bad.
  4591. * For all other protocol drivers, this is a no-op.
  4592. */
  4593. {
  4594. int ii;
  4595. int r = 0;
  4596. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4597. if (MptResetHandlers[ii]) {
  4598. dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
  4599. ioc->name, ii));
  4600. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
  4601. if (ioc->alt_ioc) {
  4602. dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
  4603. ioc->name, ioc->alt_ioc->name, ii));
  4604. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
  4605. }
  4606. }
  4607. }
  4608. }
  4609. if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
  4610. printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
  4611. rc, ioc->name);
  4612. }
  4613. ioc->reload_fw = 0;
  4614. if (ioc->alt_ioc)
  4615. ioc->alt_ioc->reload_fw = 0;
  4616. spin_lock_irqsave(&ioc->diagLock, flags);
  4617. ioc->diagPending = 0;
  4618. if (ioc->alt_ioc)
  4619. ioc->alt_ioc->diagPending = 0;
  4620. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4621. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
  4622. return rc;
  4623. }
  4624. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4625. static char *
  4626. EventDescriptionStr(u8 event, u32 evData0)
  4627. {
  4628. char *ds;
  4629. switch(event) {
  4630. case MPI_EVENT_NONE:
  4631. ds = "None";
  4632. break;
  4633. case MPI_EVENT_LOG_DATA:
  4634. ds = "Log Data";
  4635. break;
  4636. case MPI_EVENT_STATE_CHANGE:
  4637. ds = "State Change";
  4638. break;
  4639. case MPI_EVENT_UNIT_ATTENTION:
  4640. ds = "Unit Attention";
  4641. break;
  4642. case MPI_EVENT_IOC_BUS_RESET:
  4643. ds = "IOC Bus Reset";
  4644. break;
  4645. case MPI_EVENT_EXT_BUS_RESET:
  4646. ds = "External Bus Reset";
  4647. break;
  4648. case MPI_EVENT_RESCAN:
  4649. ds = "Bus Rescan Event";
  4650. /* Ok, do we need to do anything here? As far as
  4651. I can tell, this is when a new device gets added
  4652. to the loop. */
  4653. break;
  4654. case MPI_EVENT_LINK_STATUS_CHANGE:
  4655. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  4656. ds = "Link Status(FAILURE) Change";
  4657. else
  4658. ds = "Link Status(ACTIVE) Change";
  4659. break;
  4660. case MPI_EVENT_LOOP_STATE_CHANGE:
  4661. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  4662. ds = "Loop State(LIP) Change";
  4663. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  4664. ds = "Loop State(LPE) Change"; /* ??? */
  4665. else
  4666. ds = "Loop State(LPB) Change"; /* ??? */
  4667. break;
  4668. case MPI_EVENT_LOGOUT:
  4669. ds = "Logout";
  4670. break;
  4671. case MPI_EVENT_EVENT_CHANGE:
  4672. if (evData0)
  4673. ds = "Events(ON) Change";
  4674. else
  4675. ds = "Events(OFF) Change";
  4676. break;
  4677. case MPI_EVENT_INTEGRATED_RAID:
  4678. ds = "Integrated Raid";
  4679. break;
  4680. /*
  4681. * MPT base "custom" events may be added here...
  4682. */
  4683. default:
  4684. ds = "Unknown";
  4685. break;
  4686. }
  4687. return ds;
  4688. }
  4689. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4690. /*
  4691. * ProcessEventNotification - Route a received EventNotificationReply to
  4692. * all currently regeistered event handlers.
  4693. * @ioc: Pointer to MPT_ADAPTER structure
  4694. * @pEventReply: Pointer to EventNotification reply frame
  4695. * @evHandlers: Pointer to integer, number of event handlers
  4696. *
  4697. * Returns sum of event handlers return values.
  4698. */
  4699. static int
  4700. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  4701. {
  4702. u16 evDataLen;
  4703. u32 evData0 = 0;
  4704. // u32 evCtx;
  4705. int ii;
  4706. int r = 0;
  4707. int handlers = 0;
  4708. char *evStr;
  4709. u8 event;
  4710. /*
  4711. * Do platform normalization of values
  4712. */
  4713. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  4714. // evCtx = le32_to_cpu(pEventReply->EventContext);
  4715. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  4716. if (evDataLen) {
  4717. evData0 = le32_to_cpu(pEventReply->Data[0]);
  4718. }
  4719. evStr = EventDescriptionStr(event, evData0);
  4720. devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
  4721. ioc->name,
  4722. evStr,
  4723. event));
  4724. #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
  4725. printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
  4726. for (ii = 0; ii < evDataLen; ii++)
  4727. printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
  4728. printk("\n");
  4729. #endif
  4730. /*
  4731. * Do general / base driver event processing
  4732. */
  4733. switch(event) {
  4734. case MPI_EVENT_NONE: /* 00 */
  4735. case MPI_EVENT_LOG_DATA: /* 01 */
  4736. case MPI_EVENT_STATE_CHANGE: /* 02 */
  4737. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  4738. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  4739. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  4740. case MPI_EVENT_RESCAN: /* 06 */
  4741. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  4742. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  4743. case MPI_EVENT_LOGOUT: /* 09 */
  4744. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  4745. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
  4746. default:
  4747. break;
  4748. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  4749. if (evDataLen) {
  4750. u8 evState = evData0 & 0xFF;
  4751. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  4752. /* Update EventState field in cached IocFacts */
  4753. if (ioc->facts.Function) {
  4754. ioc->facts.EventState = evState;
  4755. }
  4756. }
  4757. break;
  4758. }
  4759. /*
  4760. * Should this event be logged? Events are written sequentially.
  4761. * When buffer is full, start again at the top.
  4762. */
  4763. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  4764. int idx;
  4765. idx = ioc->eventContext % ioc->eventLogSize;
  4766. ioc->events[idx].event = event;
  4767. ioc->events[idx].eventContext = ioc->eventContext;
  4768. for (ii = 0; ii < 2; ii++) {
  4769. if (ii < evDataLen)
  4770. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  4771. else
  4772. ioc->events[idx].data[ii] = 0;
  4773. }
  4774. ioc->eventContext++;
  4775. }
  4776. /*
  4777. * Call each currently registered protocol event handler.
  4778. */
  4779. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4780. if (MptEvHandlers[ii]) {
  4781. devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
  4782. ioc->name, ii));
  4783. r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
  4784. handlers++;
  4785. }
  4786. }
  4787. /* FIXME? Examine results here? */
  4788. /*
  4789. * If needed, send (a single) EventAck.
  4790. */
  4791. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  4792. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  4793. devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
  4794. ioc->name, ii));
  4795. }
  4796. }
  4797. *evHandlers = handlers;
  4798. return r;
  4799. }
  4800. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4801. /*
  4802. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  4803. * @ioc: Pointer to MPT_ADAPTER structure
  4804. * @log_info: U32 LogInfo reply word from the IOC
  4805. *
  4806. * Refer to lsi/fc_log.h.
  4807. */
  4808. static void
  4809. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4810. {
  4811. static char *subcl_str[8] = {
  4812. "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
  4813. "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
  4814. };
  4815. u8 subcl = (log_info >> 24) & 0x7;
  4816. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
  4817. ioc->name, log_info, subcl_str[subcl]);
  4818. }
  4819. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4820. /*
  4821. * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
  4822. * @ioc: Pointer to MPT_ADAPTER structure
  4823. * @mr: Pointer to MPT reply frame
  4824. * @log_info: U32 LogInfo word from the IOC
  4825. *
  4826. * Refer to lsi/sp_log.h.
  4827. */
  4828. static void
  4829. mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4830. {
  4831. u32 info = log_info & 0x00FF0000;
  4832. char *desc = "unknown";
  4833. switch (info) {
  4834. case 0x00010000:
  4835. desc = "bug! MID not found";
  4836. if (ioc->reload_fw == 0)
  4837. ioc->reload_fw++;
  4838. break;
  4839. case 0x00020000:
  4840. desc = "Parity Error";
  4841. break;
  4842. case 0x00030000:
  4843. desc = "ASYNC Outbound Overrun";
  4844. break;
  4845. case 0x00040000:
  4846. desc = "SYNC Offset Error";
  4847. break;
  4848. case 0x00050000:
  4849. desc = "BM Change";
  4850. break;
  4851. case 0x00060000:
  4852. desc = "Msg In Overflow";
  4853. break;
  4854. case 0x00070000:
  4855. desc = "DMA Error";
  4856. break;
  4857. case 0x00080000:
  4858. desc = "Outbound DMA Overrun";
  4859. break;
  4860. case 0x00090000:
  4861. desc = "Task Management";
  4862. break;
  4863. case 0x000A0000:
  4864. desc = "Device Problem";
  4865. break;
  4866. case 0x000B0000:
  4867. desc = "Invalid Phase Change";
  4868. break;
  4869. case 0x000C0000:
  4870. desc = "Untagged Table Size";
  4871. break;
  4872. }
  4873. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  4874. }
  4875. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4876. /*
  4877. * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
  4878. * @ioc: Pointer to MPT_ADAPTER structure
  4879. * @ioc_status: U32 IOCStatus word from IOC
  4880. * @mf: Pointer to MPT request frame
  4881. *
  4882. * Refer to lsi/mpi.h.
  4883. */
  4884. static void
  4885. mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  4886. {
  4887. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  4888. char *desc = "";
  4889. switch (status) {
  4890. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  4891. desc = "Invalid Function";
  4892. break;
  4893. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  4894. desc = "Busy";
  4895. break;
  4896. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  4897. desc = "Invalid SGL";
  4898. break;
  4899. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  4900. desc = "Internal Error";
  4901. break;
  4902. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  4903. desc = "Reserved";
  4904. break;
  4905. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  4906. desc = "Insufficient Resources";
  4907. break;
  4908. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  4909. desc = "Invalid Field";
  4910. break;
  4911. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  4912. desc = "Invalid State";
  4913. break;
  4914. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  4915. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  4916. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  4917. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  4918. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  4919. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  4920. /* No message for Config IOCStatus values */
  4921. break;
  4922. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  4923. /* No message for recovered error
  4924. desc = "SCSI Recovered Error";
  4925. */
  4926. break;
  4927. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  4928. desc = "SCSI Invalid Bus";
  4929. break;
  4930. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  4931. desc = "SCSI Invalid TargetID";
  4932. break;
  4933. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  4934. {
  4935. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  4936. U8 cdb = pScsiReq->CDB[0];
  4937. if (cdb != 0x12) { /* Inquiry is issued for device scanning */
  4938. desc = "SCSI Device Not There";
  4939. }
  4940. break;
  4941. }
  4942. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  4943. desc = "SCSI Data Overrun";
  4944. break;
  4945. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  4946. /* This error is checked in scsi_io_done(). Skip.
  4947. desc = "SCSI Data Underrun";
  4948. */
  4949. break;
  4950. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  4951. desc = "SCSI I/O Data Error";
  4952. break;
  4953. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  4954. desc = "SCSI Protocol Error";
  4955. break;
  4956. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  4957. desc = "SCSI Task Terminated";
  4958. break;
  4959. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  4960. desc = "SCSI Residual Mismatch";
  4961. break;
  4962. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  4963. desc = "SCSI Task Management Failed";
  4964. break;
  4965. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  4966. desc = "SCSI IOC Terminated";
  4967. break;
  4968. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  4969. desc = "SCSI Ext Terminated";
  4970. break;
  4971. default:
  4972. desc = "Others";
  4973. break;
  4974. }
  4975. if (desc != "")
  4976. printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
  4977. }
  4978. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4979. EXPORT_SYMBOL(mpt_attach);
  4980. EXPORT_SYMBOL(mpt_detach);
  4981. #ifdef CONFIG_PM
  4982. EXPORT_SYMBOL(mpt_resume);
  4983. EXPORT_SYMBOL(mpt_suspend);
  4984. #endif
  4985. EXPORT_SYMBOL(ioc_list);
  4986. EXPORT_SYMBOL(mpt_proc_root_dir);
  4987. EXPORT_SYMBOL(mpt_register);
  4988. EXPORT_SYMBOL(mpt_deregister);
  4989. EXPORT_SYMBOL(mpt_event_register);
  4990. EXPORT_SYMBOL(mpt_event_deregister);
  4991. EXPORT_SYMBOL(mpt_reset_register);
  4992. EXPORT_SYMBOL(mpt_reset_deregister);
  4993. EXPORT_SYMBOL(mpt_device_driver_register);
  4994. EXPORT_SYMBOL(mpt_device_driver_deregister);
  4995. EXPORT_SYMBOL(mpt_get_msg_frame);
  4996. EXPORT_SYMBOL(mpt_put_msg_frame);
  4997. EXPORT_SYMBOL(mpt_free_msg_frame);
  4998. EXPORT_SYMBOL(mpt_add_sge);
  4999. EXPORT_SYMBOL(mpt_send_handshake_request);
  5000. EXPORT_SYMBOL(mpt_verify_adapter);
  5001. EXPORT_SYMBOL(mpt_GetIocState);
  5002. EXPORT_SYMBOL(mpt_print_ioc_summary);
  5003. EXPORT_SYMBOL(mpt_lan_index);
  5004. EXPORT_SYMBOL(mpt_stm_index);
  5005. EXPORT_SYMBOL(mpt_HardResetHandler);
  5006. EXPORT_SYMBOL(mpt_config);
  5007. EXPORT_SYMBOL(mpt_toolbox);
  5008. EXPORT_SYMBOL(mpt_findImVolumes);
  5009. EXPORT_SYMBOL(mpt_read_ioc_pg_3);
  5010. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  5011. EXPORT_SYMBOL(mpt_free_fw_memory);
  5012. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5013. /*
  5014. * fusion_init - Fusion MPT base driver initialization routine.
  5015. *
  5016. * Returns 0 for success, non-zero for failure.
  5017. */
  5018. static int __init
  5019. fusion_init(void)
  5020. {
  5021. int i;
  5022. show_mptmod_ver(my_NAME, my_VERSION);
  5023. printk(KERN_INFO COPYRIGHT "\n");
  5024. for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
  5025. MptCallbacks[i] = NULL;
  5026. MptDriverClass[i] = MPTUNKNOWN_DRIVER;
  5027. MptEvHandlers[i] = NULL;
  5028. MptResetHandlers[i] = NULL;
  5029. }
  5030. /* Register ourselves (mptbase) in order to facilitate
  5031. * EventNotification handling.
  5032. */
  5033. mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
  5034. /* Register for hard reset handling callbacks.
  5035. */
  5036. if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
  5037. dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
  5038. } else {
  5039. /* FIXME! */
  5040. }
  5041. #ifdef CONFIG_PROC_FS
  5042. (void) procmpt_create();
  5043. #endif
  5044. return 0;
  5045. }
  5046. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5047. /*
  5048. * fusion_exit - Perform driver unload cleanup.
  5049. *
  5050. * This routine frees all resources associated with each MPT adapter
  5051. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  5052. */
  5053. static void __exit
  5054. fusion_exit(void)
  5055. {
  5056. dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
  5057. mpt_reset_deregister(mpt_base_index);
  5058. #ifdef CONFIG_PROC_FS
  5059. procmpt_destroy();
  5060. #endif
  5061. }
  5062. module_init(fusion_init);
  5063. module_exit(fusion_exit);