mptbase.c 161 KB

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