t4_hw.c 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/delay.h>
  35. #include "cxgb4.h"
  36. #include "t4_regs.h"
  37. #include "t4_values.h"
  38. #include "t4fw_api.h"
  39. /**
  40. * t4_wait_op_done_val - wait until an operation is completed
  41. * @adapter: the adapter performing the operation
  42. * @reg: the register to check for completion
  43. * @mask: a single-bit field within @reg that indicates completion
  44. * @polarity: the value of the field when the operation is completed
  45. * @attempts: number of check iterations
  46. * @delay: delay in usecs between iterations
  47. * @valp: where to store the value of the register at completion time
  48. *
  49. * Wait until an operation is completed by checking a bit in a register
  50. * up to @attempts times. If @valp is not NULL the value of the register
  51. * at the time it indicated completion is stored there. Returns 0 if the
  52. * operation completes and -EAGAIN otherwise.
  53. */
  54. static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
  55. int polarity, int attempts, int delay, u32 *valp)
  56. {
  57. while (1) {
  58. u32 val = t4_read_reg(adapter, reg);
  59. if (!!(val & mask) == polarity) {
  60. if (valp)
  61. *valp = val;
  62. return 0;
  63. }
  64. if (--attempts == 0)
  65. return -EAGAIN;
  66. if (delay)
  67. udelay(delay);
  68. }
  69. }
  70. static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
  71. int polarity, int attempts, int delay)
  72. {
  73. return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
  74. delay, NULL);
  75. }
  76. /**
  77. * t4_set_reg_field - set a register field to a value
  78. * @adapter: the adapter to program
  79. * @addr: the register address
  80. * @mask: specifies the portion of the register to modify
  81. * @val: the new value for the register field
  82. *
  83. * Sets a register field specified by the supplied mask to the
  84. * given value.
  85. */
  86. void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
  87. u32 val)
  88. {
  89. u32 v = t4_read_reg(adapter, addr) & ~mask;
  90. t4_write_reg(adapter, addr, v | val);
  91. (void) t4_read_reg(adapter, addr); /* flush */
  92. }
  93. /**
  94. * t4_read_indirect - read indirectly addressed registers
  95. * @adap: the adapter
  96. * @addr_reg: register holding the indirect address
  97. * @data_reg: register holding the value of the indirect register
  98. * @vals: where the read register values are stored
  99. * @nregs: how many indirect registers to read
  100. * @start_idx: index of first indirect register to read
  101. *
  102. * Reads registers that are accessed indirectly through an address/data
  103. * register pair.
  104. */
  105. void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  106. unsigned int data_reg, u32 *vals,
  107. unsigned int nregs, unsigned int start_idx)
  108. {
  109. while (nregs--) {
  110. t4_write_reg(adap, addr_reg, start_idx);
  111. *vals++ = t4_read_reg(adap, data_reg);
  112. start_idx++;
  113. }
  114. }
  115. /**
  116. * t4_write_indirect - write indirectly addressed registers
  117. * @adap: the adapter
  118. * @addr_reg: register holding the indirect addresses
  119. * @data_reg: register holding the value for the indirect registers
  120. * @vals: values to write
  121. * @nregs: how many indirect registers to write
  122. * @start_idx: address of first indirect register to write
  123. *
  124. * Writes a sequential block of registers that are accessed indirectly
  125. * through an address/data register pair.
  126. */
  127. void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  128. unsigned int data_reg, const u32 *vals,
  129. unsigned int nregs, unsigned int start_idx)
  130. {
  131. while (nregs--) {
  132. t4_write_reg(adap, addr_reg, start_idx++);
  133. t4_write_reg(adap, data_reg, *vals++);
  134. }
  135. }
  136. /*
  137. * Read a 32-bit PCI Configuration Space register via the PCI-E backdoor
  138. * mechanism. This guarantees that we get the real value even if we're
  139. * operating within a Virtual Machine and the Hypervisor is trapping our
  140. * Configuration Space accesses.
  141. */
  142. void t4_hw_pci_read_cfg4(struct adapter *adap, int reg, u32 *val)
  143. {
  144. u32 req = ENABLE_F | FUNCTION_V(adap->fn) | REGISTER_V(reg);
  145. if (is_t4(adap->params.chip))
  146. req |= LOCALCFG_F;
  147. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, req);
  148. *val = t4_read_reg(adap, PCIE_CFG_SPACE_DATA_A);
  149. /* Reset ENABLE to 0 so reads of PCIE_CFG_SPACE_DATA won't cause a
  150. * Configuration Space read. (None of the other fields matter when
  151. * ENABLE is 0 so a simple register write is easier than a
  152. * read-modify-write via t4_set_reg_field().)
  153. */
  154. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, 0);
  155. }
  156. /*
  157. * t4_report_fw_error - report firmware error
  158. * @adap: the adapter
  159. *
  160. * The adapter firmware can indicate error conditions to the host.
  161. * If the firmware has indicated an error, print out the reason for
  162. * the firmware error.
  163. */
  164. static void t4_report_fw_error(struct adapter *adap)
  165. {
  166. static const char *const reason[] = {
  167. "Crash", /* PCIE_FW_EVAL_CRASH */
  168. "During Device Preparation", /* PCIE_FW_EVAL_PREP */
  169. "During Device Configuration", /* PCIE_FW_EVAL_CONF */
  170. "During Device Initialization", /* PCIE_FW_EVAL_INIT */
  171. "Unexpected Event", /* PCIE_FW_EVAL_UNEXPECTEDEVENT */
  172. "Insufficient Airflow", /* PCIE_FW_EVAL_OVERHEAT */
  173. "Device Shutdown", /* PCIE_FW_EVAL_DEVICESHUTDOWN */
  174. "Reserved", /* reserved */
  175. };
  176. u32 pcie_fw;
  177. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  178. if (pcie_fw & PCIE_FW_ERR_F)
  179. dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
  180. reason[PCIE_FW_EVAL_G(pcie_fw)]);
  181. }
  182. /*
  183. * Get the reply to a mailbox command and store it in @rpl in big-endian order.
  184. */
  185. static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
  186. u32 mbox_addr)
  187. {
  188. for ( ; nflit; nflit--, mbox_addr += 8)
  189. *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
  190. }
  191. /*
  192. * Handle a FW assertion reported in a mailbox.
  193. */
  194. static void fw_asrt(struct adapter *adap, u32 mbox_addr)
  195. {
  196. struct fw_debug_cmd asrt;
  197. get_mbox_rpl(adap, (__be64 *)&asrt, sizeof(asrt) / 8, mbox_addr);
  198. dev_alert(adap->pdev_dev,
  199. "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  200. asrt.u.assert.filename_0_7, ntohl(asrt.u.assert.line),
  201. ntohl(asrt.u.assert.x), ntohl(asrt.u.assert.y));
  202. }
  203. static void dump_mbox(struct adapter *adap, int mbox, u32 data_reg)
  204. {
  205. dev_err(adap->pdev_dev,
  206. "mbox %d: %llx %llx %llx %llx %llx %llx %llx %llx\n", mbox,
  207. (unsigned long long)t4_read_reg64(adap, data_reg),
  208. (unsigned long long)t4_read_reg64(adap, data_reg + 8),
  209. (unsigned long long)t4_read_reg64(adap, data_reg + 16),
  210. (unsigned long long)t4_read_reg64(adap, data_reg + 24),
  211. (unsigned long long)t4_read_reg64(adap, data_reg + 32),
  212. (unsigned long long)t4_read_reg64(adap, data_reg + 40),
  213. (unsigned long long)t4_read_reg64(adap, data_reg + 48),
  214. (unsigned long long)t4_read_reg64(adap, data_reg + 56));
  215. }
  216. /**
  217. * t4_wr_mbox_meat - send a command to FW through the given mailbox
  218. * @adap: the adapter
  219. * @mbox: index of the mailbox to use
  220. * @cmd: the command to write
  221. * @size: command length in bytes
  222. * @rpl: where to optionally store the reply
  223. * @sleep_ok: if true we may sleep while awaiting command completion
  224. *
  225. * Sends the given command to FW through the selected mailbox and waits
  226. * for the FW to execute the command. If @rpl is not %NULL it is used to
  227. * store the FW's reply to the command. The command and its optional
  228. * reply are of the same length. FW can take up to %FW_CMD_MAX_TIMEOUT ms
  229. * to respond. @sleep_ok determines whether we may sleep while awaiting
  230. * the response. If sleeping is allowed we use progressive backoff
  231. * otherwise we spin.
  232. *
  233. * The return value is 0 on success or a negative errno on failure. A
  234. * failure can happen either because we are not able to execute the
  235. * command or FW executes it but signals an error. In the latter case
  236. * the return value is the error code indicated by FW (negated).
  237. */
  238. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  239. void *rpl, bool sleep_ok)
  240. {
  241. static const int delay[] = {
  242. 1, 1, 3, 5, 10, 10, 20, 50, 100, 200
  243. };
  244. u32 v;
  245. u64 res;
  246. int i, ms, delay_idx;
  247. const __be64 *p = cmd;
  248. u32 data_reg = PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  249. u32 ctl_reg = PF_REG(mbox, CIM_PF_MAILBOX_CTRL_A);
  250. if ((size & 15) || size > MBOX_LEN)
  251. return -EINVAL;
  252. /*
  253. * If the device is off-line, as in EEH, commands will time out.
  254. * Fail them early so we don't waste time waiting.
  255. */
  256. if (adap->pdev->error_state != pci_channel_io_normal)
  257. return -EIO;
  258. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  259. for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
  260. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  261. if (v != MBOX_OWNER_DRV)
  262. return v ? -EBUSY : -ETIMEDOUT;
  263. for (i = 0; i < size; i += 8)
  264. t4_write_reg64(adap, data_reg + i, be64_to_cpu(*p++));
  265. t4_write_reg(adap, ctl_reg, MBMSGVALID_F | MBOWNER_V(MBOX_OWNER_FW));
  266. t4_read_reg(adap, ctl_reg); /* flush write */
  267. delay_idx = 0;
  268. ms = delay[0];
  269. for (i = 0; i < FW_CMD_MAX_TIMEOUT; i += ms) {
  270. if (sleep_ok) {
  271. ms = delay[delay_idx]; /* last element may repeat */
  272. if (delay_idx < ARRAY_SIZE(delay) - 1)
  273. delay_idx++;
  274. msleep(ms);
  275. } else
  276. mdelay(ms);
  277. v = t4_read_reg(adap, ctl_reg);
  278. if (MBOWNER_G(v) == MBOX_OWNER_DRV) {
  279. if (!(v & MBMSGVALID_F)) {
  280. t4_write_reg(adap, ctl_reg, 0);
  281. continue;
  282. }
  283. res = t4_read_reg64(adap, data_reg);
  284. if (FW_CMD_OP_G(res >> 32) == FW_DEBUG_CMD) {
  285. fw_asrt(adap, data_reg);
  286. res = FW_CMD_RETVAL_V(EIO);
  287. } else if (rpl) {
  288. get_mbox_rpl(adap, rpl, size / 8, data_reg);
  289. }
  290. if (FW_CMD_RETVAL_G((int)res))
  291. dump_mbox(adap, mbox, data_reg);
  292. t4_write_reg(adap, ctl_reg, 0);
  293. return -FW_CMD_RETVAL_G((int)res);
  294. }
  295. }
  296. dump_mbox(adap, mbox, data_reg);
  297. dev_err(adap->pdev_dev, "command %#x in mailbox %d timed out\n",
  298. *(const u8 *)cmd, mbox);
  299. t4_report_fw_error(adap);
  300. return -ETIMEDOUT;
  301. }
  302. /**
  303. * t4_mc_read - read from MC through backdoor accesses
  304. * @adap: the adapter
  305. * @addr: address of first byte requested
  306. * @idx: which MC to access
  307. * @data: 64 bytes of data containing the requested address
  308. * @ecc: where to store the corresponding 64-bit ECC word
  309. *
  310. * Read 64 bytes of data from MC starting at a 64-byte-aligned address
  311. * that covers the requested address @addr. If @parity is not %NULL it
  312. * is assigned the 64-bit ECC word for the read data.
  313. */
  314. int t4_mc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
  315. {
  316. int i;
  317. u32 mc_bist_cmd, mc_bist_cmd_addr, mc_bist_cmd_len;
  318. u32 mc_bist_status_rdata, mc_bist_data_pattern;
  319. if (is_t4(adap->params.chip)) {
  320. mc_bist_cmd = MC_BIST_CMD_A;
  321. mc_bist_cmd_addr = MC_BIST_CMD_ADDR_A;
  322. mc_bist_cmd_len = MC_BIST_CMD_LEN_A;
  323. mc_bist_status_rdata = MC_BIST_STATUS_RDATA_A;
  324. mc_bist_data_pattern = MC_BIST_DATA_PATTERN_A;
  325. } else {
  326. mc_bist_cmd = MC_REG(MC_P_BIST_CMD_A, idx);
  327. mc_bist_cmd_addr = MC_REG(MC_P_BIST_CMD_ADDR_A, idx);
  328. mc_bist_cmd_len = MC_REG(MC_P_BIST_CMD_LEN_A, idx);
  329. mc_bist_status_rdata = MC_REG(MC_P_BIST_STATUS_RDATA_A, idx);
  330. mc_bist_data_pattern = MC_REG(MC_P_BIST_DATA_PATTERN_A, idx);
  331. }
  332. if (t4_read_reg(adap, mc_bist_cmd) & START_BIST_F)
  333. return -EBUSY;
  334. t4_write_reg(adap, mc_bist_cmd_addr, addr & ~0x3fU);
  335. t4_write_reg(adap, mc_bist_cmd_len, 64);
  336. t4_write_reg(adap, mc_bist_data_pattern, 0xc);
  337. t4_write_reg(adap, mc_bist_cmd, BIST_OPCODE_V(1) | START_BIST_F |
  338. BIST_CMD_GAP_V(1));
  339. i = t4_wait_op_done(adap, mc_bist_cmd, START_BIST_F, 0, 10, 1);
  340. if (i)
  341. return i;
  342. #define MC_DATA(i) MC_BIST_STATUS_REG(mc_bist_status_rdata, i)
  343. for (i = 15; i >= 0; i--)
  344. *data++ = htonl(t4_read_reg(adap, MC_DATA(i)));
  345. if (ecc)
  346. *ecc = t4_read_reg64(adap, MC_DATA(16));
  347. #undef MC_DATA
  348. return 0;
  349. }
  350. /**
  351. * t4_edc_read - read from EDC through backdoor accesses
  352. * @adap: the adapter
  353. * @idx: which EDC to access
  354. * @addr: address of first byte requested
  355. * @data: 64 bytes of data containing the requested address
  356. * @ecc: where to store the corresponding 64-bit ECC word
  357. *
  358. * Read 64 bytes of data from EDC starting at a 64-byte-aligned address
  359. * that covers the requested address @addr. If @parity is not %NULL it
  360. * is assigned the 64-bit ECC word for the read data.
  361. */
  362. int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
  363. {
  364. int i;
  365. u32 edc_bist_cmd, edc_bist_cmd_addr, edc_bist_cmd_len;
  366. u32 edc_bist_cmd_data_pattern, edc_bist_status_rdata;
  367. if (is_t4(adap->params.chip)) {
  368. edc_bist_cmd = EDC_REG(EDC_BIST_CMD_A, idx);
  369. edc_bist_cmd_addr = EDC_REG(EDC_BIST_CMD_ADDR_A, idx);
  370. edc_bist_cmd_len = EDC_REG(EDC_BIST_CMD_LEN_A, idx);
  371. edc_bist_cmd_data_pattern = EDC_REG(EDC_BIST_DATA_PATTERN_A,
  372. idx);
  373. edc_bist_status_rdata = EDC_REG(EDC_BIST_STATUS_RDATA_A,
  374. idx);
  375. } else {
  376. edc_bist_cmd = EDC_REG_T5(EDC_H_BIST_CMD_A, idx);
  377. edc_bist_cmd_addr = EDC_REG_T5(EDC_H_BIST_CMD_ADDR_A, idx);
  378. edc_bist_cmd_len = EDC_REG_T5(EDC_H_BIST_CMD_LEN_A, idx);
  379. edc_bist_cmd_data_pattern =
  380. EDC_REG_T5(EDC_H_BIST_DATA_PATTERN_A, idx);
  381. edc_bist_status_rdata =
  382. EDC_REG_T5(EDC_H_BIST_STATUS_RDATA_A, idx);
  383. }
  384. if (t4_read_reg(adap, edc_bist_cmd) & START_BIST_F)
  385. return -EBUSY;
  386. t4_write_reg(adap, edc_bist_cmd_addr, addr & ~0x3fU);
  387. t4_write_reg(adap, edc_bist_cmd_len, 64);
  388. t4_write_reg(adap, edc_bist_cmd_data_pattern, 0xc);
  389. t4_write_reg(adap, edc_bist_cmd,
  390. BIST_OPCODE_V(1) | BIST_CMD_GAP_V(1) | START_BIST_F);
  391. i = t4_wait_op_done(adap, edc_bist_cmd, START_BIST_F, 0, 10, 1);
  392. if (i)
  393. return i;
  394. #define EDC_DATA(i) (EDC_BIST_STATUS_REG(edc_bist_status_rdata, i))
  395. for (i = 15; i >= 0; i--)
  396. *data++ = htonl(t4_read_reg(adap, EDC_DATA(i)));
  397. if (ecc)
  398. *ecc = t4_read_reg64(adap, EDC_DATA(16));
  399. #undef EDC_DATA
  400. return 0;
  401. }
  402. /**
  403. * t4_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window
  404. * @adap: the adapter
  405. * @win: PCI-E Memory Window to use
  406. * @mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
  407. * @addr: address within indicated memory type
  408. * @len: amount of memory to transfer
  409. * @hbuf: host memory buffer
  410. * @dir: direction of transfer T4_MEMORY_READ (1) or T4_MEMORY_WRITE (0)
  411. *
  412. * Reads/writes an [almost] arbitrary memory region in the firmware: the
  413. * firmware memory address and host buffer must be aligned on 32-bit
  414. * boudaries; the length may be arbitrary. The memory is transferred as
  415. * a raw byte sequence from/to the firmware's memory. If this memory
  416. * contains data structures which contain multi-byte integers, it's the
  417. * caller's responsibility to perform appropriate byte order conversions.
  418. */
  419. int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr,
  420. u32 len, void *hbuf, int dir)
  421. {
  422. u32 pos, offset, resid, memoffset;
  423. u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
  424. u32 *buf;
  425. /* Argument sanity checks ...
  426. */
  427. if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
  428. return -EINVAL;
  429. buf = (u32 *)hbuf;
  430. /* It's convenient to be able to handle lengths which aren't a
  431. * multiple of 32-bits because we often end up transferring files to
  432. * the firmware. So we'll handle that by normalizing the length here
  433. * and then handling any residual transfer at the end.
  434. */
  435. resid = len & 0x3;
  436. len -= resid;
  437. /* Offset into the region of memory which is being accessed
  438. * MEM_EDC0 = 0
  439. * MEM_EDC1 = 1
  440. * MEM_MC = 2 -- T4
  441. * MEM_MC0 = 2 -- For T5
  442. * MEM_MC1 = 3 -- For T5
  443. */
  444. edc_size = EDRAM0_SIZE_G(t4_read_reg(adap, MA_EDRAM0_BAR_A));
  445. if (mtype != MEM_MC1)
  446. memoffset = (mtype * (edc_size * 1024 * 1024));
  447. else {
  448. mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap,
  449. MA_EXT_MEMORY0_BAR_A));
  450. memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
  451. }
  452. /* Determine the PCIE_MEM_ACCESS_OFFSET */
  453. addr = addr + memoffset;
  454. /* Each PCI-E Memory Window is programmed with a window size -- or
  455. * "aperture" -- which controls the granularity of its mapping onto
  456. * adapter memory. We need to grab that aperture in order to know
  457. * how to use the specified window. The window is also programmed
  458. * with the base address of the Memory Window in BAR0's address
  459. * space. For T4 this is an absolute PCI-E Bus Address. For T5
  460. * the address is relative to BAR0.
  461. */
  462. mem_reg = t4_read_reg(adap,
  463. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A,
  464. win));
  465. mem_aperture = 1 << (WINDOW_G(mem_reg) + WINDOW_SHIFT_X);
  466. mem_base = PCIEOFST_G(mem_reg) << PCIEOFST_SHIFT_X;
  467. if (is_t4(adap->params.chip))
  468. mem_base -= adap->t4_bar0;
  469. win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->fn);
  470. /* Calculate our initial PCI-E Memory Window Position and Offset into
  471. * that Window.
  472. */
  473. pos = addr & ~(mem_aperture-1);
  474. offset = addr - pos;
  475. /* Set up initial PCI-E Memory Window to cover the start of our
  476. * transfer. (Read it back to ensure that changes propagate before we
  477. * attempt to use the new value.)
  478. */
  479. t4_write_reg(adap,
  480. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win),
  481. pos | win_pf);
  482. t4_read_reg(adap,
  483. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  484. /* Transfer data to/from the adapter as long as there's an integral
  485. * number of 32-bit transfers to complete.
  486. *
  487. * A note on Endianness issues:
  488. *
  489. * The "register" reads and writes below from/to the PCI-E Memory
  490. * Window invoke the standard adapter Big-Endian to PCI-E Link
  491. * Little-Endian "swizzel." As a result, if we have the following
  492. * data in adapter memory:
  493. *
  494. * Memory: ... | b0 | b1 | b2 | b3 | ...
  495. * Address: i+0 i+1 i+2 i+3
  496. *
  497. * Then a read of the adapter memory via the PCI-E Memory Window
  498. * will yield:
  499. *
  500. * x = readl(i)
  501. * 31 0
  502. * [ b3 | b2 | b1 | b0 ]
  503. *
  504. * If this value is stored into local memory on a Little-Endian system
  505. * it will show up correctly in local memory as:
  506. *
  507. * ( ..., b0, b1, b2, b3, ... )
  508. *
  509. * But on a Big-Endian system, the store will show up in memory
  510. * incorrectly swizzled as:
  511. *
  512. * ( ..., b3, b2, b1, b0, ... )
  513. *
  514. * So we need to account for this in the reads and writes to the
  515. * PCI-E Memory Window below by undoing the register read/write
  516. * swizzels.
  517. */
  518. while (len > 0) {
  519. if (dir == T4_MEMORY_READ)
  520. *buf++ = le32_to_cpu((__force __le32)t4_read_reg(adap,
  521. mem_base + offset));
  522. else
  523. t4_write_reg(adap, mem_base + offset,
  524. (__force u32)cpu_to_le32(*buf++));
  525. offset += sizeof(__be32);
  526. len -= sizeof(__be32);
  527. /* If we've reached the end of our current window aperture,
  528. * move the PCI-E Memory Window on to the next. Note that
  529. * doing this here after "len" may be 0 allows us to set up
  530. * the PCI-E Memory Window for a possible final residual
  531. * transfer below ...
  532. */
  533. if (offset == mem_aperture) {
  534. pos += mem_aperture;
  535. offset = 0;
  536. t4_write_reg(adap,
  537. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  538. win), pos | win_pf);
  539. t4_read_reg(adap,
  540. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  541. win));
  542. }
  543. }
  544. /* If the original transfer had a length which wasn't a multiple of
  545. * 32-bits, now's where we need to finish off the transfer of the
  546. * residual amount. The PCI-E Memory Window has already been moved
  547. * above (if necessary) to cover this final transfer.
  548. */
  549. if (resid) {
  550. union {
  551. u32 word;
  552. char byte[4];
  553. } last;
  554. unsigned char *bp;
  555. int i;
  556. if (dir == T4_MEMORY_READ) {
  557. last.word = le32_to_cpu(
  558. (__force __le32)t4_read_reg(adap,
  559. mem_base + offset));
  560. for (bp = (unsigned char *)buf, i = resid; i < 4; i++)
  561. bp[i] = last.byte[i];
  562. } else {
  563. last.word = *buf;
  564. for (i = resid; i < 4; i++)
  565. last.byte[i] = 0;
  566. t4_write_reg(adap, mem_base + offset,
  567. (__force u32)cpu_to_le32(last.word));
  568. }
  569. }
  570. return 0;
  571. }
  572. /**
  573. * t4_get_regs_len - return the size of the chips register set
  574. * @adapter: the adapter
  575. *
  576. * Returns the size of the chip's BAR0 register space.
  577. */
  578. unsigned int t4_get_regs_len(struct adapter *adapter)
  579. {
  580. unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
  581. switch (chip_version) {
  582. case CHELSIO_T4:
  583. return T4_REGMAP_SIZE;
  584. case CHELSIO_T5:
  585. return T5_REGMAP_SIZE;
  586. }
  587. dev_err(adapter->pdev_dev,
  588. "Unsupported chip version %d\n", chip_version);
  589. return 0;
  590. }
  591. /**
  592. * t4_get_regs - read chip registers into provided buffer
  593. * @adap: the adapter
  594. * @buf: register buffer
  595. * @buf_size: size (in bytes) of register buffer
  596. *
  597. * If the provided register buffer isn't large enough for the chip's
  598. * full register range, the register dump will be truncated to the
  599. * register buffer's size.
  600. */
  601. void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)
  602. {
  603. static const unsigned int t4_reg_ranges[] = {
  604. 0x1008, 0x1108,
  605. 0x1180, 0x11b4,
  606. 0x11fc, 0x123c,
  607. 0x1300, 0x173c,
  608. 0x1800, 0x18fc,
  609. 0x3000, 0x30d8,
  610. 0x30e0, 0x5924,
  611. 0x5960, 0x59d4,
  612. 0x5a00, 0x5af8,
  613. 0x6000, 0x6098,
  614. 0x6100, 0x6150,
  615. 0x6200, 0x6208,
  616. 0x6240, 0x6248,
  617. 0x6280, 0x6338,
  618. 0x6370, 0x638c,
  619. 0x6400, 0x643c,
  620. 0x6500, 0x6524,
  621. 0x6a00, 0x6a38,
  622. 0x6a60, 0x6a78,
  623. 0x6b00, 0x6b84,
  624. 0x6bf0, 0x6c84,
  625. 0x6cf0, 0x6d84,
  626. 0x6df0, 0x6e84,
  627. 0x6ef0, 0x6f84,
  628. 0x6ff0, 0x7084,
  629. 0x70f0, 0x7184,
  630. 0x71f0, 0x7284,
  631. 0x72f0, 0x7384,
  632. 0x73f0, 0x7450,
  633. 0x7500, 0x7530,
  634. 0x7600, 0x761c,
  635. 0x7680, 0x76cc,
  636. 0x7700, 0x7798,
  637. 0x77c0, 0x77fc,
  638. 0x7900, 0x79fc,
  639. 0x7b00, 0x7c38,
  640. 0x7d00, 0x7efc,
  641. 0x8dc0, 0x8e1c,
  642. 0x8e30, 0x8e78,
  643. 0x8ea0, 0x8f6c,
  644. 0x8fc0, 0x9074,
  645. 0x90fc, 0x90fc,
  646. 0x9400, 0x9458,
  647. 0x9600, 0x96bc,
  648. 0x9800, 0x9808,
  649. 0x9820, 0x983c,
  650. 0x9850, 0x9864,
  651. 0x9c00, 0x9c6c,
  652. 0x9c80, 0x9cec,
  653. 0x9d00, 0x9d6c,
  654. 0x9d80, 0x9dec,
  655. 0x9e00, 0x9e6c,
  656. 0x9e80, 0x9eec,
  657. 0x9f00, 0x9f6c,
  658. 0x9f80, 0x9fec,
  659. 0xd004, 0xd03c,
  660. 0xdfc0, 0xdfe0,
  661. 0xe000, 0xea7c,
  662. 0xf000, 0x11110,
  663. 0x11118, 0x11190,
  664. 0x19040, 0x1906c,
  665. 0x19078, 0x19080,
  666. 0x1908c, 0x19124,
  667. 0x19150, 0x191b0,
  668. 0x191d0, 0x191e8,
  669. 0x19238, 0x1924c,
  670. 0x193f8, 0x19474,
  671. 0x19490, 0x194f8,
  672. 0x19800, 0x19f30,
  673. 0x1a000, 0x1a06c,
  674. 0x1a0b0, 0x1a120,
  675. 0x1a128, 0x1a138,
  676. 0x1a190, 0x1a1c4,
  677. 0x1a1fc, 0x1a1fc,
  678. 0x1e040, 0x1e04c,
  679. 0x1e284, 0x1e28c,
  680. 0x1e2c0, 0x1e2c0,
  681. 0x1e2e0, 0x1e2e0,
  682. 0x1e300, 0x1e384,
  683. 0x1e3c0, 0x1e3c8,
  684. 0x1e440, 0x1e44c,
  685. 0x1e684, 0x1e68c,
  686. 0x1e6c0, 0x1e6c0,
  687. 0x1e6e0, 0x1e6e0,
  688. 0x1e700, 0x1e784,
  689. 0x1e7c0, 0x1e7c8,
  690. 0x1e840, 0x1e84c,
  691. 0x1ea84, 0x1ea8c,
  692. 0x1eac0, 0x1eac0,
  693. 0x1eae0, 0x1eae0,
  694. 0x1eb00, 0x1eb84,
  695. 0x1ebc0, 0x1ebc8,
  696. 0x1ec40, 0x1ec4c,
  697. 0x1ee84, 0x1ee8c,
  698. 0x1eec0, 0x1eec0,
  699. 0x1eee0, 0x1eee0,
  700. 0x1ef00, 0x1ef84,
  701. 0x1efc0, 0x1efc8,
  702. 0x1f040, 0x1f04c,
  703. 0x1f284, 0x1f28c,
  704. 0x1f2c0, 0x1f2c0,
  705. 0x1f2e0, 0x1f2e0,
  706. 0x1f300, 0x1f384,
  707. 0x1f3c0, 0x1f3c8,
  708. 0x1f440, 0x1f44c,
  709. 0x1f684, 0x1f68c,
  710. 0x1f6c0, 0x1f6c0,
  711. 0x1f6e0, 0x1f6e0,
  712. 0x1f700, 0x1f784,
  713. 0x1f7c0, 0x1f7c8,
  714. 0x1f840, 0x1f84c,
  715. 0x1fa84, 0x1fa8c,
  716. 0x1fac0, 0x1fac0,
  717. 0x1fae0, 0x1fae0,
  718. 0x1fb00, 0x1fb84,
  719. 0x1fbc0, 0x1fbc8,
  720. 0x1fc40, 0x1fc4c,
  721. 0x1fe84, 0x1fe8c,
  722. 0x1fec0, 0x1fec0,
  723. 0x1fee0, 0x1fee0,
  724. 0x1ff00, 0x1ff84,
  725. 0x1ffc0, 0x1ffc8,
  726. 0x20000, 0x2002c,
  727. 0x20100, 0x2013c,
  728. 0x20190, 0x201c8,
  729. 0x20200, 0x20318,
  730. 0x20400, 0x20528,
  731. 0x20540, 0x20614,
  732. 0x21000, 0x21040,
  733. 0x2104c, 0x21060,
  734. 0x210c0, 0x210ec,
  735. 0x21200, 0x21268,
  736. 0x21270, 0x21284,
  737. 0x212fc, 0x21388,
  738. 0x21400, 0x21404,
  739. 0x21500, 0x21518,
  740. 0x2152c, 0x2153c,
  741. 0x21550, 0x21554,
  742. 0x21600, 0x21600,
  743. 0x21608, 0x21628,
  744. 0x21630, 0x2163c,
  745. 0x21700, 0x2171c,
  746. 0x21780, 0x2178c,
  747. 0x21800, 0x21c38,
  748. 0x21c80, 0x21d7c,
  749. 0x21e00, 0x21e04,
  750. 0x22000, 0x2202c,
  751. 0x22100, 0x2213c,
  752. 0x22190, 0x221c8,
  753. 0x22200, 0x22318,
  754. 0x22400, 0x22528,
  755. 0x22540, 0x22614,
  756. 0x23000, 0x23040,
  757. 0x2304c, 0x23060,
  758. 0x230c0, 0x230ec,
  759. 0x23200, 0x23268,
  760. 0x23270, 0x23284,
  761. 0x232fc, 0x23388,
  762. 0x23400, 0x23404,
  763. 0x23500, 0x23518,
  764. 0x2352c, 0x2353c,
  765. 0x23550, 0x23554,
  766. 0x23600, 0x23600,
  767. 0x23608, 0x23628,
  768. 0x23630, 0x2363c,
  769. 0x23700, 0x2371c,
  770. 0x23780, 0x2378c,
  771. 0x23800, 0x23c38,
  772. 0x23c80, 0x23d7c,
  773. 0x23e00, 0x23e04,
  774. 0x24000, 0x2402c,
  775. 0x24100, 0x2413c,
  776. 0x24190, 0x241c8,
  777. 0x24200, 0x24318,
  778. 0x24400, 0x24528,
  779. 0x24540, 0x24614,
  780. 0x25000, 0x25040,
  781. 0x2504c, 0x25060,
  782. 0x250c0, 0x250ec,
  783. 0x25200, 0x25268,
  784. 0x25270, 0x25284,
  785. 0x252fc, 0x25388,
  786. 0x25400, 0x25404,
  787. 0x25500, 0x25518,
  788. 0x2552c, 0x2553c,
  789. 0x25550, 0x25554,
  790. 0x25600, 0x25600,
  791. 0x25608, 0x25628,
  792. 0x25630, 0x2563c,
  793. 0x25700, 0x2571c,
  794. 0x25780, 0x2578c,
  795. 0x25800, 0x25c38,
  796. 0x25c80, 0x25d7c,
  797. 0x25e00, 0x25e04,
  798. 0x26000, 0x2602c,
  799. 0x26100, 0x2613c,
  800. 0x26190, 0x261c8,
  801. 0x26200, 0x26318,
  802. 0x26400, 0x26528,
  803. 0x26540, 0x26614,
  804. 0x27000, 0x27040,
  805. 0x2704c, 0x27060,
  806. 0x270c0, 0x270ec,
  807. 0x27200, 0x27268,
  808. 0x27270, 0x27284,
  809. 0x272fc, 0x27388,
  810. 0x27400, 0x27404,
  811. 0x27500, 0x27518,
  812. 0x2752c, 0x2753c,
  813. 0x27550, 0x27554,
  814. 0x27600, 0x27600,
  815. 0x27608, 0x27628,
  816. 0x27630, 0x2763c,
  817. 0x27700, 0x2771c,
  818. 0x27780, 0x2778c,
  819. 0x27800, 0x27c38,
  820. 0x27c80, 0x27d7c,
  821. 0x27e00, 0x27e04
  822. };
  823. static const unsigned int t5_reg_ranges[] = {
  824. 0x1008, 0x1148,
  825. 0x1180, 0x11b4,
  826. 0x11fc, 0x123c,
  827. 0x1280, 0x173c,
  828. 0x1800, 0x18fc,
  829. 0x3000, 0x3028,
  830. 0x3060, 0x30d8,
  831. 0x30e0, 0x30fc,
  832. 0x3140, 0x357c,
  833. 0x35a8, 0x35cc,
  834. 0x35ec, 0x35ec,
  835. 0x3600, 0x5624,
  836. 0x56cc, 0x575c,
  837. 0x580c, 0x5814,
  838. 0x5890, 0x58bc,
  839. 0x5940, 0x59dc,
  840. 0x59fc, 0x5a18,
  841. 0x5a60, 0x5a9c,
  842. 0x5b9c, 0x5bfc,
  843. 0x6000, 0x6040,
  844. 0x6058, 0x614c,
  845. 0x7700, 0x7798,
  846. 0x77c0, 0x78fc,
  847. 0x7b00, 0x7c54,
  848. 0x7d00, 0x7efc,
  849. 0x8dc0, 0x8de0,
  850. 0x8df8, 0x8e84,
  851. 0x8ea0, 0x8f84,
  852. 0x8fc0, 0x90f8,
  853. 0x9400, 0x9470,
  854. 0x9600, 0x96f4,
  855. 0x9800, 0x9808,
  856. 0x9820, 0x983c,
  857. 0x9850, 0x9864,
  858. 0x9c00, 0x9c6c,
  859. 0x9c80, 0x9cec,
  860. 0x9d00, 0x9d6c,
  861. 0x9d80, 0x9dec,
  862. 0x9e00, 0x9e6c,
  863. 0x9e80, 0x9eec,
  864. 0x9f00, 0x9f6c,
  865. 0x9f80, 0xa020,
  866. 0xd004, 0xd03c,
  867. 0xdfc0, 0xdfe0,
  868. 0xe000, 0x11088,
  869. 0x1109c, 0x11110,
  870. 0x11118, 0x1117c,
  871. 0x11190, 0x11204,
  872. 0x19040, 0x1906c,
  873. 0x19078, 0x19080,
  874. 0x1908c, 0x19124,
  875. 0x19150, 0x191b0,
  876. 0x191d0, 0x191e8,
  877. 0x19238, 0x19290,
  878. 0x193f8, 0x19474,
  879. 0x19490, 0x194cc,
  880. 0x194f0, 0x194f8,
  881. 0x19c00, 0x19c60,
  882. 0x19c94, 0x19e10,
  883. 0x19e50, 0x19f34,
  884. 0x19f40, 0x19f50,
  885. 0x19f90, 0x19fe4,
  886. 0x1a000, 0x1a06c,
  887. 0x1a0b0, 0x1a120,
  888. 0x1a128, 0x1a138,
  889. 0x1a190, 0x1a1c4,
  890. 0x1a1fc, 0x1a1fc,
  891. 0x1e008, 0x1e00c,
  892. 0x1e040, 0x1e04c,
  893. 0x1e284, 0x1e290,
  894. 0x1e2c0, 0x1e2c0,
  895. 0x1e2e0, 0x1e2e0,
  896. 0x1e300, 0x1e384,
  897. 0x1e3c0, 0x1e3c8,
  898. 0x1e408, 0x1e40c,
  899. 0x1e440, 0x1e44c,
  900. 0x1e684, 0x1e690,
  901. 0x1e6c0, 0x1e6c0,
  902. 0x1e6e0, 0x1e6e0,
  903. 0x1e700, 0x1e784,
  904. 0x1e7c0, 0x1e7c8,
  905. 0x1e808, 0x1e80c,
  906. 0x1e840, 0x1e84c,
  907. 0x1ea84, 0x1ea90,
  908. 0x1eac0, 0x1eac0,
  909. 0x1eae0, 0x1eae0,
  910. 0x1eb00, 0x1eb84,
  911. 0x1ebc0, 0x1ebc8,
  912. 0x1ec08, 0x1ec0c,
  913. 0x1ec40, 0x1ec4c,
  914. 0x1ee84, 0x1ee90,
  915. 0x1eec0, 0x1eec0,
  916. 0x1eee0, 0x1eee0,
  917. 0x1ef00, 0x1ef84,
  918. 0x1efc0, 0x1efc8,
  919. 0x1f008, 0x1f00c,
  920. 0x1f040, 0x1f04c,
  921. 0x1f284, 0x1f290,
  922. 0x1f2c0, 0x1f2c0,
  923. 0x1f2e0, 0x1f2e0,
  924. 0x1f300, 0x1f384,
  925. 0x1f3c0, 0x1f3c8,
  926. 0x1f408, 0x1f40c,
  927. 0x1f440, 0x1f44c,
  928. 0x1f684, 0x1f690,
  929. 0x1f6c0, 0x1f6c0,
  930. 0x1f6e0, 0x1f6e0,
  931. 0x1f700, 0x1f784,
  932. 0x1f7c0, 0x1f7c8,
  933. 0x1f808, 0x1f80c,
  934. 0x1f840, 0x1f84c,
  935. 0x1fa84, 0x1fa90,
  936. 0x1fac0, 0x1fac0,
  937. 0x1fae0, 0x1fae0,
  938. 0x1fb00, 0x1fb84,
  939. 0x1fbc0, 0x1fbc8,
  940. 0x1fc08, 0x1fc0c,
  941. 0x1fc40, 0x1fc4c,
  942. 0x1fe84, 0x1fe90,
  943. 0x1fec0, 0x1fec0,
  944. 0x1fee0, 0x1fee0,
  945. 0x1ff00, 0x1ff84,
  946. 0x1ffc0, 0x1ffc8,
  947. 0x30000, 0x30030,
  948. 0x30100, 0x30144,
  949. 0x30190, 0x301d0,
  950. 0x30200, 0x30318,
  951. 0x30400, 0x3052c,
  952. 0x30540, 0x3061c,
  953. 0x30800, 0x30834,
  954. 0x308c0, 0x30908,
  955. 0x30910, 0x309ac,
  956. 0x30a00, 0x30a04,
  957. 0x30a0c, 0x30a2c,
  958. 0x30a44, 0x30a50,
  959. 0x30a74, 0x30c24,
  960. 0x30d08, 0x30d14,
  961. 0x30d1c, 0x30d20,
  962. 0x30d3c, 0x30d50,
  963. 0x31200, 0x3120c,
  964. 0x31220, 0x31220,
  965. 0x31240, 0x31240,
  966. 0x31600, 0x31600,
  967. 0x31608, 0x3160c,
  968. 0x31a00, 0x31a1c,
  969. 0x31e04, 0x31e20,
  970. 0x31e38, 0x31e3c,
  971. 0x31e80, 0x31e80,
  972. 0x31e88, 0x31ea8,
  973. 0x31eb0, 0x31eb4,
  974. 0x31ec8, 0x31ed4,
  975. 0x31fb8, 0x32004,
  976. 0x32208, 0x3223c,
  977. 0x32600, 0x32630,
  978. 0x32a00, 0x32abc,
  979. 0x32b00, 0x32b70,
  980. 0x33000, 0x33048,
  981. 0x33060, 0x3309c,
  982. 0x330f0, 0x33148,
  983. 0x33160, 0x3319c,
  984. 0x331f0, 0x332e4,
  985. 0x332f8, 0x333e4,
  986. 0x333f8, 0x33448,
  987. 0x33460, 0x3349c,
  988. 0x334f0, 0x33548,
  989. 0x33560, 0x3359c,
  990. 0x335f0, 0x336e4,
  991. 0x336f8, 0x337e4,
  992. 0x337f8, 0x337fc,
  993. 0x33814, 0x33814,
  994. 0x3382c, 0x3382c,
  995. 0x33880, 0x3388c,
  996. 0x338e8, 0x338ec,
  997. 0x33900, 0x33948,
  998. 0x33960, 0x3399c,
  999. 0x339f0, 0x33ae4,
  1000. 0x33af8, 0x33b10,
  1001. 0x33b28, 0x33b28,
  1002. 0x33b3c, 0x33b50,
  1003. 0x33bf0, 0x33c10,
  1004. 0x33c28, 0x33c28,
  1005. 0x33c3c, 0x33c50,
  1006. 0x33cf0, 0x33cfc,
  1007. 0x34000, 0x34030,
  1008. 0x34100, 0x34144,
  1009. 0x34190, 0x341d0,
  1010. 0x34200, 0x34318,
  1011. 0x34400, 0x3452c,
  1012. 0x34540, 0x3461c,
  1013. 0x34800, 0x34834,
  1014. 0x348c0, 0x34908,
  1015. 0x34910, 0x349ac,
  1016. 0x34a00, 0x34a04,
  1017. 0x34a0c, 0x34a2c,
  1018. 0x34a44, 0x34a50,
  1019. 0x34a74, 0x34c24,
  1020. 0x34d08, 0x34d14,
  1021. 0x34d1c, 0x34d20,
  1022. 0x34d3c, 0x34d50,
  1023. 0x35200, 0x3520c,
  1024. 0x35220, 0x35220,
  1025. 0x35240, 0x35240,
  1026. 0x35600, 0x35600,
  1027. 0x35608, 0x3560c,
  1028. 0x35a00, 0x35a1c,
  1029. 0x35e04, 0x35e20,
  1030. 0x35e38, 0x35e3c,
  1031. 0x35e80, 0x35e80,
  1032. 0x35e88, 0x35ea8,
  1033. 0x35eb0, 0x35eb4,
  1034. 0x35ec8, 0x35ed4,
  1035. 0x35fb8, 0x36004,
  1036. 0x36208, 0x3623c,
  1037. 0x36600, 0x36630,
  1038. 0x36a00, 0x36abc,
  1039. 0x36b00, 0x36b70,
  1040. 0x37000, 0x37048,
  1041. 0x37060, 0x3709c,
  1042. 0x370f0, 0x37148,
  1043. 0x37160, 0x3719c,
  1044. 0x371f0, 0x372e4,
  1045. 0x372f8, 0x373e4,
  1046. 0x373f8, 0x37448,
  1047. 0x37460, 0x3749c,
  1048. 0x374f0, 0x37548,
  1049. 0x37560, 0x3759c,
  1050. 0x375f0, 0x376e4,
  1051. 0x376f8, 0x377e4,
  1052. 0x377f8, 0x377fc,
  1053. 0x37814, 0x37814,
  1054. 0x3782c, 0x3782c,
  1055. 0x37880, 0x3788c,
  1056. 0x378e8, 0x378ec,
  1057. 0x37900, 0x37948,
  1058. 0x37960, 0x3799c,
  1059. 0x379f0, 0x37ae4,
  1060. 0x37af8, 0x37b10,
  1061. 0x37b28, 0x37b28,
  1062. 0x37b3c, 0x37b50,
  1063. 0x37bf0, 0x37c10,
  1064. 0x37c28, 0x37c28,
  1065. 0x37c3c, 0x37c50,
  1066. 0x37cf0, 0x37cfc,
  1067. 0x38000, 0x38030,
  1068. 0x38100, 0x38144,
  1069. 0x38190, 0x381d0,
  1070. 0x38200, 0x38318,
  1071. 0x38400, 0x3852c,
  1072. 0x38540, 0x3861c,
  1073. 0x38800, 0x38834,
  1074. 0x388c0, 0x38908,
  1075. 0x38910, 0x389ac,
  1076. 0x38a00, 0x38a04,
  1077. 0x38a0c, 0x38a2c,
  1078. 0x38a44, 0x38a50,
  1079. 0x38a74, 0x38c24,
  1080. 0x38d08, 0x38d14,
  1081. 0x38d1c, 0x38d20,
  1082. 0x38d3c, 0x38d50,
  1083. 0x39200, 0x3920c,
  1084. 0x39220, 0x39220,
  1085. 0x39240, 0x39240,
  1086. 0x39600, 0x39600,
  1087. 0x39608, 0x3960c,
  1088. 0x39a00, 0x39a1c,
  1089. 0x39e04, 0x39e20,
  1090. 0x39e38, 0x39e3c,
  1091. 0x39e80, 0x39e80,
  1092. 0x39e88, 0x39ea8,
  1093. 0x39eb0, 0x39eb4,
  1094. 0x39ec8, 0x39ed4,
  1095. 0x39fb8, 0x3a004,
  1096. 0x3a208, 0x3a23c,
  1097. 0x3a600, 0x3a630,
  1098. 0x3aa00, 0x3aabc,
  1099. 0x3ab00, 0x3ab70,
  1100. 0x3b000, 0x3b048,
  1101. 0x3b060, 0x3b09c,
  1102. 0x3b0f0, 0x3b148,
  1103. 0x3b160, 0x3b19c,
  1104. 0x3b1f0, 0x3b2e4,
  1105. 0x3b2f8, 0x3b3e4,
  1106. 0x3b3f8, 0x3b448,
  1107. 0x3b460, 0x3b49c,
  1108. 0x3b4f0, 0x3b548,
  1109. 0x3b560, 0x3b59c,
  1110. 0x3b5f0, 0x3b6e4,
  1111. 0x3b6f8, 0x3b7e4,
  1112. 0x3b7f8, 0x3b7fc,
  1113. 0x3b814, 0x3b814,
  1114. 0x3b82c, 0x3b82c,
  1115. 0x3b880, 0x3b88c,
  1116. 0x3b8e8, 0x3b8ec,
  1117. 0x3b900, 0x3b948,
  1118. 0x3b960, 0x3b99c,
  1119. 0x3b9f0, 0x3bae4,
  1120. 0x3baf8, 0x3bb10,
  1121. 0x3bb28, 0x3bb28,
  1122. 0x3bb3c, 0x3bb50,
  1123. 0x3bbf0, 0x3bc10,
  1124. 0x3bc28, 0x3bc28,
  1125. 0x3bc3c, 0x3bc50,
  1126. 0x3bcf0, 0x3bcfc,
  1127. 0x3c000, 0x3c030,
  1128. 0x3c100, 0x3c144,
  1129. 0x3c190, 0x3c1d0,
  1130. 0x3c200, 0x3c318,
  1131. 0x3c400, 0x3c52c,
  1132. 0x3c540, 0x3c61c,
  1133. 0x3c800, 0x3c834,
  1134. 0x3c8c0, 0x3c908,
  1135. 0x3c910, 0x3c9ac,
  1136. 0x3ca00, 0x3ca04,
  1137. 0x3ca0c, 0x3ca2c,
  1138. 0x3ca44, 0x3ca50,
  1139. 0x3ca74, 0x3cc24,
  1140. 0x3cd08, 0x3cd14,
  1141. 0x3cd1c, 0x3cd20,
  1142. 0x3cd3c, 0x3cd50,
  1143. 0x3d200, 0x3d20c,
  1144. 0x3d220, 0x3d220,
  1145. 0x3d240, 0x3d240,
  1146. 0x3d600, 0x3d600,
  1147. 0x3d608, 0x3d60c,
  1148. 0x3da00, 0x3da1c,
  1149. 0x3de04, 0x3de20,
  1150. 0x3de38, 0x3de3c,
  1151. 0x3de80, 0x3de80,
  1152. 0x3de88, 0x3dea8,
  1153. 0x3deb0, 0x3deb4,
  1154. 0x3dec8, 0x3ded4,
  1155. 0x3dfb8, 0x3e004,
  1156. 0x3e208, 0x3e23c,
  1157. 0x3e600, 0x3e630,
  1158. 0x3ea00, 0x3eabc,
  1159. 0x3eb00, 0x3eb70,
  1160. 0x3f000, 0x3f048,
  1161. 0x3f060, 0x3f09c,
  1162. 0x3f0f0, 0x3f148,
  1163. 0x3f160, 0x3f19c,
  1164. 0x3f1f0, 0x3f2e4,
  1165. 0x3f2f8, 0x3f3e4,
  1166. 0x3f3f8, 0x3f448,
  1167. 0x3f460, 0x3f49c,
  1168. 0x3f4f0, 0x3f548,
  1169. 0x3f560, 0x3f59c,
  1170. 0x3f5f0, 0x3f6e4,
  1171. 0x3f6f8, 0x3f7e4,
  1172. 0x3f7f8, 0x3f7fc,
  1173. 0x3f814, 0x3f814,
  1174. 0x3f82c, 0x3f82c,
  1175. 0x3f880, 0x3f88c,
  1176. 0x3f8e8, 0x3f8ec,
  1177. 0x3f900, 0x3f948,
  1178. 0x3f960, 0x3f99c,
  1179. 0x3f9f0, 0x3fae4,
  1180. 0x3faf8, 0x3fb10,
  1181. 0x3fb28, 0x3fb28,
  1182. 0x3fb3c, 0x3fb50,
  1183. 0x3fbf0, 0x3fc10,
  1184. 0x3fc28, 0x3fc28,
  1185. 0x3fc3c, 0x3fc50,
  1186. 0x3fcf0, 0x3fcfc,
  1187. 0x40000, 0x4000c,
  1188. 0x40040, 0x40068,
  1189. 0x40080, 0x40144,
  1190. 0x40180, 0x4018c,
  1191. 0x40200, 0x40298,
  1192. 0x402ac, 0x4033c,
  1193. 0x403f8, 0x403fc,
  1194. 0x41304, 0x413c4,
  1195. 0x41400, 0x4141c,
  1196. 0x41480, 0x414d0,
  1197. 0x44000, 0x44078,
  1198. 0x440c0, 0x44278,
  1199. 0x442c0, 0x44478,
  1200. 0x444c0, 0x44678,
  1201. 0x446c0, 0x44878,
  1202. 0x448c0, 0x449fc,
  1203. 0x45000, 0x45068,
  1204. 0x45080, 0x45084,
  1205. 0x450a0, 0x450b0,
  1206. 0x45200, 0x45268,
  1207. 0x45280, 0x45284,
  1208. 0x452a0, 0x452b0,
  1209. 0x460c0, 0x460e4,
  1210. 0x47000, 0x4708c,
  1211. 0x47200, 0x47250,
  1212. 0x47400, 0x47420,
  1213. 0x47600, 0x47618,
  1214. 0x47800, 0x47814,
  1215. 0x48000, 0x4800c,
  1216. 0x48040, 0x48068,
  1217. 0x48080, 0x48144,
  1218. 0x48180, 0x4818c,
  1219. 0x48200, 0x48298,
  1220. 0x482ac, 0x4833c,
  1221. 0x483f8, 0x483fc,
  1222. 0x49304, 0x493c4,
  1223. 0x49400, 0x4941c,
  1224. 0x49480, 0x494d0,
  1225. 0x4c000, 0x4c078,
  1226. 0x4c0c0, 0x4c278,
  1227. 0x4c2c0, 0x4c478,
  1228. 0x4c4c0, 0x4c678,
  1229. 0x4c6c0, 0x4c878,
  1230. 0x4c8c0, 0x4c9fc,
  1231. 0x4d000, 0x4d068,
  1232. 0x4d080, 0x4d084,
  1233. 0x4d0a0, 0x4d0b0,
  1234. 0x4d200, 0x4d268,
  1235. 0x4d280, 0x4d284,
  1236. 0x4d2a0, 0x4d2b0,
  1237. 0x4e0c0, 0x4e0e4,
  1238. 0x4f000, 0x4f08c,
  1239. 0x4f200, 0x4f250,
  1240. 0x4f400, 0x4f420,
  1241. 0x4f600, 0x4f618,
  1242. 0x4f800, 0x4f814,
  1243. 0x50000, 0x500cc,
  1244. 0x50400, 0x50400,
  1245. 0x50800, 0x508cc,
  1246. 0x50c00, 0x50c00,
  1247. 0x51000, 0x5101c,
  1248. 0x51300, 0x51308,
  1249. };
  1250. u32 *buf_end = (u32 *)((char *)buf + buf_size);
  1251. const unsigned int *reg_ranges;
  1252. int reg_ranges_size, range;
  1253. unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
  1254. /* Select the right set of register ranges to dump depending on the
  1255. * adapter chip type.
  1256. */
  1257. switch (chip_version) {
  1258. case CHELSIO_T4:
  1259. reg_ranges = t4_reg_ranges;
  1260. reg_ranges_size = ARRAY_SIZE(t4_reg_ranges);
  1261. break;
  1262. case CHELSIO_T5:
  1263. reg_ranges = t5_reg_ranges;
  1264. reg_ranges_size = ARRAY_SIZE(t5_reg_ranges);
  1265. break;
  1266. default:
  1267. dev_err(adap->pdev_dev,
  1268. "Unsupported chip version %d\n", chip_version);
  1269. return;
  1270. }
  1271. /* Clear the register buffer and insert the appropriate register
  1272. * values selected by the above register ranges.
  1273. */
  1274. memset(buf, 0, buf_size);
  1275. for (range = 0; range < reg_ranges_size; range += 2) {
  1276. unsigned int reg = reg_ranges[range];
  1277. unsigned int last_reg = reg_ranges[range + 1];
  1278. u32 *bufp = (u32 *)((char *)buf + reg);
  1279. /* Iterate across the register range filling in the register
  1280. * buffer but don't write past the end of the register buffer.
  1281. */
  1282. while (reg <= last_reg && bufp < buf_end) {
  1283. *bufp++ = t4_read_reg(adap, reg);
  1284. reg += sizeof(u32);
  1285. }
  1286. }
  1287. }
  1288. #define EEPROM_STAT_ADDR 0x7bfc
  1289. #define VPD_BASE 0x400
  1290. #define VPD_BASE_OLD 0
  1291. #define VPD_LEN 1024
  1292. #define CHELSIO_VPD_UNIQUE_ID 0x82
  1293. /**
  1294. * t4_seeprom_wp - enable/disable EEPROM write protection
  1295. * @adapter: the adapter
  1296. * @enable: whether to enable or disable write protection
  1297. *
  1298. * Enables or disables write protection on the serial EEPROM.
  1299. */
  1300. int t4_seeprom_wp(struct adapter *adapter, bool enable)
  1301. {
  1302. unsigned int v = enable ? 0xc : 0;
  1303. int ret = pci_write_vpd(adapter->pdev, EEPROM_STAT_ADDR, 4, &v);
  1304. return ret < 0 ? ret : 0;
  1305. }
  1306. /**
  1307. * get_vpd_params - read VPD parameters from VPD EEPROM
  1308. * @adapter: adapter to read
  1309. * @p: where to store the parameters
  1310. *
  1311. * Reads card parameters stored in VPD EEPROM.
  1312. */
  1313. int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
  1314. {
  1315. u32 cclk_param, cclk_val;
  1316. int i, ret, addr;
  1317. int ec, sn, pn;
  1318. u8 *vpd, csum;
  1319. unsigned int vpdr_len, kw_offset, id_len;
  1320. vpd = vmalloc(VPD_LEN);
  1321. if (!vpd)
  1322. return -ENOMEM;
  1323. ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(u32), vpd);
  1324. if (ret < 0)
  1325. goto out;
  1326. /* The VPD shall have a unique identifier specified by the PCI SIG.
  1327. * For chelsio adapters, the identifier is 0x82. The first byte of a VPD
  1328. * shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software
  1329. * is expected to automatically put this entry at the
  1330. * beginning of the VPD.
  1331. */
  1332. addr = *vpd == CHELSIO_VPD_UNIQUE_ID ? VPD_BASE : VPD_BASE_OLD;
  1333. ret = pci_read_vpd(adapter->pdev, addr, VPD_LEN, vpd);
  1334. if (ret < 0)
  1335. goto out;
  1336. if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
  1337. dev_err(adapter->pdev_dev, "missing VPD ID string\n");
  1338. ret = -EINVAL;
  1339. goto out;
  1340. }
  1341. id_len = pci_vpd_lrdt_size(vpd);
  1342. if (id_len > ID_LEN)
  1343. id_len = ID_LEN;
  1344. i = pci_vpd_find_tag(vpd, 0, VPD_LEN, PCI_VPD_LRDT_RO_DATA);
  1345. if (i < 0) {
  1346. dev_err(adapter->pdev_dev, "missing VPD-R section\n");
  1347. ret = -EINVAL;
  1348. goto out;
  1349. }
  1350. vpdr_len = pci_vpd_lrdt_size(&vpd[i]);
  1351. kw_offset = i + PCI_VPD_LRDT_TAG_SIZE;
  1352. if (vpdr_len + kw_offset > VPD_LEN) {
  1353. dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
  1354. ret = -EINVAL;
  1355. goto out;
  1356. }
  1357. #define FIND_VPD_KW(var, name) do { \
  1358. var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \
  1359. if (var < 0) { \
  1360. dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
  1361. ret = -EINVAL; \
  1362. goto out; \
  1363. } \
  1364. var += PCI_VPD_INFO_FLD_HDR_SIZE; \
  1365. } while (0)
  1366. FIND_VPD_KW(i, "RV");
  1367. for (csum = 0; i >= 0; i--)
  1368. csum += vpd[i];
  1369. if (csum) {
  1370. dev_err(adapter->pdev_dev,
  1371. "corrupted VPD EEPROM, actual csum %u\n", csum);
  1372. ret = -EINVAL;
  1373. goto out;
  1374. }
  1375. FIND_VPD_KW(ec, "EC");
  1376. FIND_VPD_KW(sn, "SN");
  1377. FIND_VPD_KW(pn, "PN");
  1378. #undef FIND_VPD_KW
  1379. memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len);
  1380. strim(p->id);
  1381. memcpy(p->ec, vpd + ec, EC_LEN);
  1382. strim(p->ec);
  1383. i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE);
  1384. memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
  1385. strim(p->sn);
  1386. i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE);
  1387. memcpy(p->pn, vpd + pn, min(i, PN_LEN));
  1388. strim(p->pn);
  1389. /*
  1390. * Ask firmware for the Core Clock since it knows how to translate the
  1391. * Reference Clock ('V2') VPD field into a Core Clock value ...
  1392. */
  1393. cclk_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1394. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CCLK));
  1395. ret = t4_query_params(adapter, adapter->mbox, 0, 0,
  1396. 1, &cclk_param, &cclk_val);
  1397. out:
  1398. vfree(vpd);
  1399. if (ret)
  1400. return ret;
  1401. p->cclk = cclk_val;
  1402. return 0;
  1403. }
  1404. /* serial flash and firmware constants */
  1405. enum {
  1406. SF_ATTEMPTS = 10, /* max retries for SF operations */
  1407. /* flash command opcodes */
  1408. SF_PROG_PAGE = 2, /* program page */
  1409. SF_WR_DISABLE = 4, /* disable writes */
  1410. SF_RD_STATUS = 5, /* read status register */
  1411. SF_WR_ENABLE = 6, /* enable writes */
  1412. SF_RD_DATA_FAST = 0xb, /* read flash */
  1413. SF_RD_ID = 0x9f, /* read ID */
  1414. SF_ERASE_SECTOR = 0xd8, /* erase sector */
  1415. FW_MAX_SIZE = 16 * SF_SEC_SIZE,
  1416. };
  1417. /**
  1418. * sf1_read - read data from the serial flash
  1419. * @adapter: the adapter
  1420. * @byte_cnt: number of bytes to read
  1421. * @cont: whether another operation will be chained
  1422. * @lock: whether to lock SF for PL access only
  1423. * @valp: where to store the read data
  1424. *
  1425. * Reads up to 4 bytes of data from the serial flash. The location of
  1426. * the read needs to be specified prior to calling this by issuing the
  1427. * appropriate commands to the serial flash.
  1428. */
  1429. static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
  1430. int lock, u32 *valp)
  1431. {
  1432. int ret;
  1433. if (!byte_cnt || byte_cnt > 4)
  1434. return -EINVAL;
  1435. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  1436. return -EBUSY;
  1437. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  1438. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1));
  1439. ret = t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  1440. if (!ret)
  1441. *valp = t4_read_reg(adapter, SF_DATA_A);
  1442. return ret;
  1443. }
  1444. /**
  1445. * sf1_write - write data to the serial flash
  1446. * @adapter: the adapter
  1447. * @byte_cnt: number of bytes to write
  1448. * @cont: whether another operation will be chained
  1449. * @lock: whether to lock SF for PL access only
  1450. * @val: value to write
  1451. *
  1452. * Writes up to 4 bytes of data to the serial flash. The location of
  1453. * the write needs to be specified prior to calling this by issuing the
  1454. * appropriate commands to the serial flash.
  1455. */
  1456. static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
  1457. int lock, u32 val)
  1458. {
  1459. if (!byte_cnt || byte_cnt > 4)
  1460. return -EINVAL;
  1461. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  1462. return -EBUSY;
  1463. t4_write_reg(adapter, SF_DATA_A, val);
  1464. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  1465. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1) | OP_V(1));
  1466. return t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  1467. }
  1468. /**
  1469. * flash_wait_op - wait for a flash operation to complete
  1470. * @adapter: the adapter
  1471. * @attempts: max number of polls of the status register
  1472. * @delay: delay between polls in ms
  1473. *
  1474. * Wait for a flash operation to complete by polling the status register.
  1475. */
  1476. static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
  1477. {
  1478. int ret;
  1479. u32 status;
  1480. while (1) {
  1481. if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
  1482. (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
  1483. return ret;
  1484. if (!(status & 1))
  1485. return 0;
  1486. if (--attempts == 0)
  1487. return -EAGAIN;
  1488. if (delay)
  1489. msleep(delay);
  1490. }
  1491. }
  1492. /**
  1493. * t4_read_flash - read words from serial flash
  1494. * @adapter: the adapter
  1495. * @addr: the start address for the read
  1496. * @nwords: how many 32-bit words to read
  1497. * @data: where to store the read data
  1498. * @byte_oriented: whether to store data as bytes or as words
  1499. *
  1500. * Read the specified number of 32-bit words from the serial flash.
  1501. * If @byte_oriented is set the read data is stored as a byte array
  1502. * (i.e., big-endian), otherwise as 32-bit words in the platform's
  1503. * natural endianness.
  1504. */
  1505. int t4_read_flash(struct adapter *adapter, unsigned int addr,
  1506. unsigned int nwords, u32 *data, int byte_oriented)
  1507. {
  1508. int ret;
  1509. if (addr + nwords * sizeof(u32) > adapter->params.sf_size || (addr & 3))
  1510. return -EINVAL;
  1511. addr = swab32(addr) | SF_RD_DATA_FAST;
  1512. if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
  1513. (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
  1514. return ret;
  1515. for ( ; nwords; nwords--, data++) {
  1516. ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
  1517. if (nwords == 1)
  1518. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  1519. if (ret)
  1520. return ret;
  1521. if (byte_oriented)
  1522. *data = (__force __u32) (htonl(*data));
  1523. }
  1524. return 0;
  1525. }
  1526. /**
  1527. * t4_write_flash - write up to a page of data to the serial flash
  1528. * @adapter: the adapter
  1529. * @addr: the start address to write
  1530. * @n: length of data to write in bytes
  1531. * @data: the data to write
  1532. *
  1533. * Writes up to a page of data (256 bytes) to the serial flash starting
  1534. * at the given address. All the data must be written to the same page.
  1535. */
  1536. static int t4_write_flash(struct adapter *adapter, unsigned int addr,
  1537. unsigned int n, const u8 *data)
  1538. {
  1539. int ret;
  1540. u32 buf[64];
  1541. unsigned int i, c, left, val, offset = addr & 0xff;
  1542. if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
  1543. return -EINVAL;
  1544. val = swab32(addr) | SF_PROG_PAGE;
  1545. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  1546. (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
  1547. goto unlock;
  1548. for (left = n; left; left -= c) {
  1549. c = min(left, 4U);
  1550. for (val = 0, i = 0; i < c; ++i)
  1551. val = (val << 8) + *data++;
  1552. ret = sf1_write(adapter, c, c != left, 1, val);
  1553. if (ret)
  1554. goto unlock;
  1555. }
  1556. ret = flash_wait_op(adapter, 8, 1);
  1557. if (ret)
  1558. goto unlock;
  1559. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  1560. /* Read the page to verify the write succeeded */
  1561. ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
  1562. if (ret)
  1563. return ret;
  1564. if (memcmp(data - n, (u8 *)buf + offset, n)) {
  1565. dev_err(adapter->pdev_dev,
  1566. "failed to correctly write the flash page at %#x\n",
  1567. addr);
  1568. return -EIO;
  1569. }
  1570. return 0;
  1571. unlock:
  1572. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  1573. return ret;
  1574. }
  1575. /**
  1576. * t4_get_fw_version - read the firmware version
  1577. * @adapter: the adapter
  1578. * @vers: where to place the version
  1579. *
  1580. * Reads the FW version from flash.
  1581. */
  1582. int t4_get_fw_version(struct adapter *adapter, u32 *vers)
  1583. {
  1584. return t4_read_flash(adapter, FLASH_FW_START +
  1585. offsetof(struct fw_hdr, fw_ver), 1,
  1586. vers, 0);
  1587. }
  1588. /**
  1589. * t4_get_tp_version - read the TP microcode version
  1590. * @adapter: the adapter
  1591. * @vers: where to place the version
  1592. *
  1593. * Reads the TP microcode version from flash.
  1594. */
  1595. int t4_get_tp_version(struct adapter *adapter, u32 *vers)
  1596. {
  1597. return t4_read_flash(adapter, FLASH_FW_START +
  1598. offsetof(struct fw_hdr, tp_microcode_ver),
  1599. 1, vers, 0);
  1600. }
  1601. /**
  1602. * t4_get_exprom_version - return the Expansion ROM version (if any)
  1603. * @adapter: the adapter
  1604. * @vers: where to place the version
  1605. *
  1606. * Reads the Expansion ROM header from FLASH and returns the version
  1607. * number (if present) through the @vers return value pointer. We return
  1608. * this in the Firmware Version Format since it's convenient. Return
  1609. * 0 on success, -ENOENT if no Expansion ROM is present.
  1610. */
  1611. int t4_get_exprom_version(struct adapter *adap, u32 *vers)
  1612. {
  1613. struct exprom_header {
  1614. unsigned char hdr_arr[16]; /* must start with 0x55aa */
  1615. unsigned char hdr_ver[4]; /* Expansion ROM version */
  1616. } *hdr;
  1617. u32 exprom_header_buf[DIV_ROUND_UP(sizeof(struct exprom_header),
  1618. sizeof(u32))];
  1619. int ret;
  1620. ret = t4_read_flash(adap, FLASH_EXP_ROM_START,
  1621. ARRAY_SIZE(exprom_header_buf), exprom_header_buf,
  1622. 0);
  1623. if (ret)
  1624. return ret;
  1625. hdr = (struct exprom_header *)exprom_header_buf;
  1626. if (hdr->hdr_arr[0] != 0x55 || hdr->hdr_arr[1] != 0xaa)
  1627. return -ENOENT;
  1628. *vers = (FW_HDR_FW_VER_MAJOR_V(hdr->hdr_ver[0]) |
  1629. FW_HDR_FW_VER_MINOR_V(hdr->hdr_ver[1]) |
  1630. FW_HDR_FW_VER_MICRO_V(hdr->hdr_ver[2]) |
  1631. FW_HDR_FW_VER_BUILD_V(hdr->hdr_ver[3]));
  1632. return 0;
  1633. }
  1634. /* Is the given firmware API compatible with the one the driver was compiled
  1635. * with?
  1636. */
  1637. static int fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
  1638. {
  1639. /* short circuit if it's the exact same firmware version */
  1640. if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
  1641. return 1;
  1642. #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
  1643. if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
  1644. SAME_INTF(ri) && SAME_INTF(iscsi) && SAME_INTF(fcoe))
  1645. return 1;
  1646. #undef SAME_INTF
  1647. return 0;
  1648. }
  1649. /* The firmware in the filesystem is usable, but should it be installed?
  1650. * This routine explains itself in detail if it indicates the filesystem
  1651. * firmware should be installed.
  1652. */
  1653. static int should_install_fs_fw(struct adapter *adap, int card_fw_usable,
  1654. int k, int c)
  1655. {
  1656. const char *reason;
  1657. if (!card_fw_usable) {
  1658. reason = "incompatible or unusable";
  1659. goto install;
  1660. }
  1661. if (k > c) {
  1662. reason = "older than the version supported with this driver";
  1663. goto install;
  1664. }
  1665. return 0;
  1666. install:
  1667. dev_err(adap->pdev_dev, "firmware on card (%u.%u.%u.%u) is %s, "
  1668. "installing firmware %u.%u.%u.%u on card.\n",
  1669. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  1670. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
  1671. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  1672. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  1673. return 1;
  1674. }
  1675. int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
  1676. const u8 *fw_data, unsigned int fw_size,
  1677. struct fw_hdr *card_fw, enum dev_state state,
  1678. int *reset)
  1679. {
  1680. int ret, card_fw_usable, fs_fw_usable;
  1681. const struct fw_hdr *fs_fw;
  1682. const struct fw_hdr *drv_fw;
  1683. drv_fw = &fw_info->fw_hdr;
  1684. /* Read the header of the firmware on the card */
  1685. ret = -t4_read_flash(adap, FLASH_FW_START,
  1686. sizeof(*card_fw) / sizeof(uint32_t),
  1687. (uint32_t *)card_fw, 1);
  1688. if (ret == 0) {
  1689. card_fw_usable = fw_compatible(drv_fw, (const void *)card_fw);
  1690. } else {
  1691. dev_err(adap->pdev_dev,
  1692. "Unable to read card's firmware header: %d\n", ret);
  1693. card_fw_usable = 0;
  1694. }
  1695. if (fw_data != NULL) {
  1696. fs_fw = (const void *)fw_data;
  1697. fs_fw_usable = fw_compatible(drv_fw, fs_fw);
  1698. } else {
  1699. fs_fw = NULL;
  1700. fs_fw_usable = 0;
  1701. }
  1702. if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
  1703. (!fs_fw_usable || fs_fw->fw_ver == drv_fw->fw_ver)) {
  1704. /* Common case: the firmware on the card is an exact match and
  1705. * the filesystem one is an exact match too, or the filesystem
  1706. * one is absent/incompatible.
  1707. */
  1708. } else if (fs_fw_usable && state == DEV_STATE_UNINIT &&
  1709. should_install_fs_fw(adap, card_fw_usable,
  1710. be32_to_cpu(fs_fw->fw_ver),
  1711. be32_to_cpu(card_fw->fw_ver))) {
  1712. ret = -t4_fw_upgrade(adap, adap->mbox, fw_data,
  1713. fw_size, 0);
  1714. if (ret != 0) {
  1715. dev_err(adap->pdev_dev,
  1716. "failed to install firmware: %d\n", ret);
  1717. goto bye;
  1718. }
  1719. /* Installed successfully, update the cached header too. */
  1720. *card_fw = *fs_fw;
  1721. card_fw_usable = 1;
  1722. *reset = 0; /* already reset as part of load_fw */
  1723. }
  1724. if (!card_fw_usable) {
  1725. uint32_t d, c, k;
  1726. d = be32_to_cpu(drv_fw->fw_ver);
  1727. c = be32_to_cpu(card_fw->fw_ver);
  1728. k = fs_fw ? be32_to_cpu(fs_fw->fw_ver) : 0;
  1729. dev_err(adap->pdev_dev, "Cannot find a usable firmware: "
  1730. "chip state %d, "
  1731. "driver compiled with %d.%d.%d.%d, "
  1732. "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
  1733. state,
  1734. FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
  1735. FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
  1736. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  1737. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
  1738. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  1739. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  1740. ret = EINVAL;
  1741. goto bye;
  1742. }
  1743. /* We're using whatever's on the card and it's known to be good. */
  1744. adap->params.fw_vers = be32_to_cpu(card_fw->fw_ver);
  1745. adap->params.tp_vers = be32_to_cpu(card_fw->tp_microcode_ver);
  1746. bye:
  1747. return ret;
  1748. }
  1749. /**
  1750. * t4_flash_erase_sectors - erase a range of flash sectors
  1751. * @adapter: the adapter
  1752. * @start: the first sector to erase
  1753. * @end: the last sector to erase
  1754. *
  1755. * Erases the sectors in the given inclusive range.
  1756. */
  1757. static int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
  1758. {
  1759. int ret = 0;
  1760. if (end >= adapter->params.sf_nsec)
  1761. return -EINVAL;
  1762. while (start <= end) {
  1763. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  1764. (ret = sf1_write(adapter, 4, 0, 1,
  1765. SF_ERASE_SECTOR | (start << 8))) != 0 ||
  1766. (ret = flash_wait_op(adapter, 14, 500)) != 0) {
  1767. dev_err(adapter->pdev_dev,
  1768. "erase of flash sector %d failed, error %d\n",
  1769. start, ret);
  1770. break;
  1771. }
  1772. start++;
  1773. }
  1774. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  1775. return ret;
  1776. }
  1777. /**
  1778. * t4_flash_cfg_addr - return the address of the flash configuration file
  1779. * @adapter: the adapter
  1780. *
  1781. * Return the address within the flash where the Firmware Configuration
  1782. * File is stored.
  1783. */
  1784. unsigned int t4_flash_cfg_addr(struct adapter *adapter)
  1785. {
  1786. if (adapter->params.sf_size == 0x100000)
  1787. return FLASH_FPGA_CFG_START;
  1788. else
  1789. return FLASH_CFG_START;
  1790. }
  1791. /* Return TRUE if the specified firmware matches the adapter. I.e. T4
  1792. * firmware for T4 adapters, T5 firmware for T5 adapters, etc. We go ahead
  1793. * and emit an error message for mismatched firmware to save our caller the
  1794. * effort ...
  1795. */
  1796. static bool t4_fw_matches_chip(const struct adapter *adap,
  1797. const struct fw_hdr *hdr)
  1798. {
  1799. /* The expression below will return FALSE for any unsupported adapter
  1800. * which will keep us "honest" in the future ...
  1801. */
  1802. if ((is_t4(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T4) ||
  1803. (is_t5(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T5))
  1804. return true;
  1805. dev_err(adap->pdev_dev,
  1806. "FW image (%d) is not suitable for this adapter (%d)\n",
  1807. hdr->chip, CHELSIO_CHIP_VERSION(adap->params.chip));
  1808. return false;
  1809. }
  1810. /**
  1811. * t4_load_fw - download firmware
  1812. * @adap: the adapter
  1813. * @fw_data: the firmware image to write
  1814. * @size: image size
  1815. *
  1816. * Write the supplied firmware image to the card's serial flash.
  1817. */
  1818. int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
  1819. {
  1820. u32 csum;
  1821. int ret, addr;
  1822. unsigned int i;
  1823. u8 first_page[SF_PAGE_SIZE];
  1824. const __be32 *p = (const __be32 *)fw_data;
  1825. const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
  1826. unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
  1827. unsigned int fw_img_start = adap->params.sf_fw_start;
  1828. unsigned int fw_start_sec = fw_img_start / sf_sec_size;
  1829. if (!size) {
  1830. dev_err(adap->pdev_dev, "FW image has no data\n");
  1831. return -EINVAL;
  1832. }
  1833. if (size & 511) {
  1834. dev_err(adap->pdev_dev,
  1835. "FW image size not multiple of 512 bytes\n");
  1836. return -EINVAL;
  1837. }
  1838. if (ntohs(hdr->len512) * 512 != size) {
  1839. dev_err(adap->pdev_dev,
  1840. "FW image size differs from size in FW header\n");
  1841. return -EINVAL;
  1842. }
  1843. if (size > FW_MAX_SIZE) {
  1844. dev_err(adap->pdev_dev, "FW image too large, max is %u bytes\n",
  1845. FW_MAX_SIZE);
  1846. return -EFBIG;
  1847. }
  1848. if (!t4_fw_matches_chip(adap, hdr))
  1849. return -EINVAL;
  1850. for (csum = 0, i = 0; i < size / sizeof(csum); i++)
  1851. csum += ntohl(p[i]);
  1852. if (csum != 0xffffffff) {
  1853. dev_err(adap->pdev_dev,
  1854. "corrupted firmware image, checksum %#x\n", csum);
  1855. return -EINVAL;
  1856. }
  1857. i = DIV_ROUND_UP(size, sf_sec_size); /* # of sectors spanned */
  1858. ret = t4_flash_erase_sectors(adap, fw_start_sec, fw_start_sec + i - 1);
  1859. if (ret)
  1860. goto out;
  1861. /*
  1862. * We write the correct version at the end so the driver can see a bad
  1863. * version if the FW write fails. Start by writing a copy of the
  1864. * first page with a bad version.
  1865. */
  1866. memcpy(first_page, fw_data, SF_PAGE_SIZE);
  1867. ((struct fw_hdr *)first_page)->fw_ver = htonl(0xffffffff);
  1868. ret = t4_write_flash(adap, fw_img_start, SF_PAGE_SIZE, first_page);
  1869. if (ret)
  1870. goto out;
  1871. addr = fw_img_start;
  1872. for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
  1873. addr += SF_PAGE_SIZE;
  1874. fw_data += SF_PAGE_SIZE;
  1875. ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
  1876. if (ret)
  1877. goto out;
  1878. }
  1879. ret = t4_write_flash(adap,
  1880. fw_img_start + offsetof(struct fw_hdr, fw_ver),
  1881. sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
  1882. out:
  1883. if (ret)
  1884. dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
  1885. ret);
  1886. else
  1887. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  1888. return ret;
  1889. }
  1890. /**
  1891. * t4_fwcache - firmware cache operation
  1892. * @adap: the adapter
  1893. * @op : the operation (flush or flush and invalidate)
  1894. */
  1895. int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op)
  1896. {
  1897. struct fw_params_cmd c;
  1898. memset(&c, 0, sizeof(c));
  1899. c.op_to_vfn =
  1900. cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  1901. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  1902. FW_PARAMS_CMD_PFN_V(adap->fn) |
  1903. FW_PARAMS_CMD_VFN_V(0));
  1904. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  1905. c.param[0].mnem =
  1906. cpu_to_be32(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1907. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FWCACHE));
  1908. c.param[0].val = (__force __be32)op;
  1909. return t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), NULL);
  1910. }
  1911. void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf)
  1912. {
  1913. unsigned int i, j;
  1914. for (i = 0; i < 8; i++) {
  1915. u32 *p = la_buf + i;
  1916. t4_write_reg(adap, ULP_RX_LA_CTL_A, i);
  1917. j = t4_read_reg(adap, ULP_RX_LA_WRPTR_A);
  1918. t4_write_reg(adap, ULP_RX_LA_RDPTR_A, j);
  1919. for (j = 0; j < ULPRX_LA_SIZE; j++, p += 8)
  1920. *p = t4_read_reg(adap, ULP_RX_LA_RDDATA_A);
  1921. }
  1922. }
  1923. #define ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
  1924. FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_SPEED_40G | \
  1925. FW_PORT_CAP_ANEG)
  1926. /**
  1927. * t4_link_start - apply link configuration to MAC/PHY
  1928. * @phy: the PHY to setup
  1929. * @mac: the MAC to setup
  1930. * @lc: the requested link configuration
  1931. *
  1932. * Set up a port's MAC and PHY according to a desired link configuration.
  1933. * - If the PHY can auto-negotiate first decide what to advertise, then
  1934. * enable/disable auto-negotiation as desired, and reset.
  1935. * - If the PHY does not auto-negotiate just reset it.
  1936. * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  1937. * otherwise do it later based on the outcome of auto-negotiation.
  1938. */
  1939. int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
  1940. struct link_config *lc)
  1941. {
  1942. struct fw_port_cmd c;
  1943. unsigned int fc = 0, mdi = FW_PORT_CAP_MDI_V(FW_PORT_CAP_MDI_AUTO);
  1944. lc->link_ok = 0;
  1945. if (lc->requested_fc & PAUSE_RX)
  1946. fc |= FW_PORT_CAP_FC_RX;
  1947. if (lc->requested_fc & PAUSE_TX)
  1948. fc |= FW_PORT_CAP_FC_TX;
  1949. memset(&c, 0, sizeof(c));
  1950. c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) | FW_CMD_REQUEST_F |
  1951. FW_CMD_EXEC_F | FW_PORT_CMD_PORTID_V(port));
  1952. c.action_to_len16 = htonl(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  1953. FW_LEN16(c));
  1954. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  1955. c.u.l1cfg.rcap = htonl((lc->supported & ADVERT_MASK) | fc);
  1956. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  1957. } else if (lc->autoneg == AUTONEG_DISABLE) {
  1958. c.u.l1cfg.rcap = htonl(lc->requested_speed | fc | mdi);
  1959. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  1960. } else
  1961. c.u.l1cfg.rcap = htonl(lc->advertising | fc | mdi);
  1962. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  1963. }
  1964. /**
  1965. * t4_restart_aneg - restart autonegotiation
  1966. * @adap: the adapter
  1967. * @mbox: mbox to use for the FW command
  1968. * @port: the port id
  1969. *
  1970. * Restarts autonegotiation for the selected port.
  1971. */
  1972. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
  1973. {
  1974. struct fw_port_cmd c;
  1975. memset(&c, 0, sizeof(c));
  1976. c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) | FW_CMD_REQUEST_F |
  1977. FW_CMD_EXEC_F | FW_PORT_CMD_PORTID_V(port));
  1978. c.action_to_len16 = htonl(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  1979. FW_LEN16(c));
  1980. c.u.l1cfg.rcap = htonl(FW_PORT_CAP_ANEG);
  1981. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  1982. }
  1983. typedef void (*int_handler_t)(struct adapter *adap);
  1984. struct intr_info {
  1985. unsigned int mask; /* bits to check in interrupt status */
  1986. const char *msg; /* message to print or NULL */
  1987. short stat_idx; /* stat counter to increment or -1 */
  1988. unsigned short fatal; /* whether the condition reported is fatal */
  1989. int_handler_t int_handler; /* platform-specific int handler */
  1990. };
  1991. /**
  1992. * t4_handle_intr_status - table driven interrupt handler
  1993. * @adapter: the adapter that generated the interrupt
  1994. * @reg: the interrupt status register to process
  1995. * @acts: table of interrupt actions
  1996. *
  1997. * A table driven interrupt handler that applies a set of masks to an
  1998. * interrupt status word and performs the corresponding actions if the
  1999. * interrupts described by the mask have occurred. The actions include
  2000. * optionally emitting a warning or alert message. The table is terminated
  2001. * by an entry specifying mask 0. Returns the number of fatal interrupt
  2002. * conditions.
  2003. */
  2004. static int t4_handle_intr_status(struct adapter *adapter, unsigned int reg,
  2005. const struct intr_info *acts)
  2006. {
  2007. int fatal = 0;
  2008. unsigned int mask = 0;
  2009. unsigned int status = t4_read_reg(adapter, reg);
  2010. for ( ; acts->mask; ++acts) {
  2011. if (!(status & acts->mask))
  2012. continue;
  2013. if (acts->fatal) {
  2014. fatal++;
  2015. dev_alert(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  2016. status & acts->mask);
  2017. } else if (acts->msg && printk_ratelimit())
  2018. dev_warn(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  2019. status & acts->mask);
  2020. if (acts->int_handler)
  2021. acts->int_handler(adapter);
  2022. mask |= acts->mask;
  2023. }
  2024. status &= mask;
  2025. if (status) /* clear processed interrupts */
  2026. t4_write_reg(adapter, reg, status);
  2027. return fatal;
  2028. }
  2029. /*
  2030. * Interrupt handler for the PCIE module.
  2031. */
  2032. static void pcie_intr_handler(struct adapter *adapter)
  2033. {
  2034. static const struct intr_info sysbus_intr_info[] = {
  2035. { RNPP_F, "RXNP array parity error", -1, 1 },
  2036. { RPCP_F, "RXPC array parity error", -1, 1 },
  2037. { RCIP_F, "RXCIF array parity error", -1, 1 },
  2038. { RCCP_F, "Rx completions control array parity error", -1, 1 },
  2039. { RFTP_F, "RXFT array parity error", -1, 1 },
  2040. { 0 }
  2041. };
  2042. static const struct intr_info pcie_port_intr_info[] = {
  2043. { TPCP_F, "TXPC array parity error", -1, 1 },
  2044. { TNPP_F, "TXNP array parity error", -1, 1 },
  2045. { TFTP_F, "TXFT array parity error", -1, 1 },
  2046. { TCAP_F, "TXCA array parity error", -1, 1 },
  2047. { TCIP_F, "TXCIF array parity error", -1, 1 },
  2048. { RCAP_F, "RXCA array parity error", -1, 1 },
  2049. { OTDD_F, "outbound request TLP discarded", -1, 1 },
  2050. { RDPE_F, "Rx data parity error", -1, 1 },
  2051. { TDUE_F, "Tx uncorrectable data error", -1, 1 },
  2052. { 0 }
  2053. };
  2054. static const struct intr_info pcie_intr_info[] = {
  2055. { MSIADDRLPERR_F, "MSI AddrL parity error", -1, 1 },
  2056. { MSIADDRHPERR_F, "MSI AddrH parity error", -1, 1 },
  2057. { MSIDATAPERR_F, "MSI data parity error", -1, 1 },
  2058. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  2059. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  2060. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  2061. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  2062. { PIOCPLPERR_F, "PCI PIO completion FIFO parity error", -1, 1 },
  2063. { PIOREQPERR_F, "PCI PIO request FIFO parity error", -1, 1 },
  2064. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  2065. { CCNTPERR_F, "PCI CMD channel count parity error", -1, 1 },
  2066. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  2067. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  2068. { DCNTPERR_F, "PCI DMA channel count parity error", -1, 1 },
  2069. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  2070. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  2071. { HCNTPERR_F, "PCI HMA channel count parity error", -1, 1 },
  2072. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  2073. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  2074. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  2075. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  2076. { INTXCLRPERR_F, "PCI INTx clear parity error", -1, 1 },
  2077. { MATAGPERR_F, "PCI MA tag parity error", -1, 1 },
  2078. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  2079. { RXCPLPERR_F, "PCI Rx completion parity error", -1, 1 },
  2080. { RXWRPERR_F, "PCI Rx write parity error", -1, 1 },
  2081. { RPLPERR_F, "PCI replay buffer parity error", -1, 1 },
  2082. { PCIESINT_F, "PCI core secondary fault", -1, 1 },
  2083. { PCIEPINT_F, "PCI core primary fault", -1, 1 },
  2084. { UNXSPLCPLERR_F, "PCI unexpected split completion error",
  2085. -1, 0 },
  2086. { 0 }
  2087. };
  2088. static struct intr_info t5_pcie_intr_info[] = {
  2089. { MSTGRPPERR_F, "Master Response Read Queue parity error",
  2090. -1, 1 },
  2091. { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
  2092. { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
  2093. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  2094. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  2095. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  2096. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  2097. { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
  2098. -1, 1 },
  2099. { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
  2100. -1, 1 },
  2101. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  2102. { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
  2103. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  2104. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  2105. { DREQWRPERR_F, "PCI DMA channel write request parity error",
  2106. -1, 1 },
  2107. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  2108. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  2109. { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
  2110. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  2111. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  2112. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  2113. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  2114. { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
  2115. { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
  2116. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  2117. { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
  2118. -1, 1 },
  2119. { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
  2120. -1, 1 },
  2121. { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
  2122. { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
  2123. { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
  2124. { READRSPERR_F, "Outbound read error", -1, 0 },
  2125. { 0 }
  2126. };
  2127. int fat;
  2128. if (is_t4(adapter->params.chip))
  2129. fat = t4_handle_intr_status(adapter,
  2130. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS_A,
  2131. sysbus_intr_info) +
  2132. t4_handle_intr_status(adapter,
  2133. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS_A,
  2134. pcie_port_intr_info) +
  2135. t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  2136. pcie_intr_info);
  2137. else
  2138. fat = t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  2139. t5_pcie_intr_info);
  2140. if (fat)
  2141. t4_fatal_err(adapter);
  2142. }
  2143. /*
  2144. * TP interrupt handler.
  2145. */
  2146. static void tp_intr_handler(struct adapter *adapter)
  2147. {
  2148. static const struct intr_info tp_intr_info[] = {
  2149. { 0x3fffffff, "TP parity error", -1, 1 },
  2150. { FLMTXFLSTEMPTY_F, "TP out of Tx pages", -1, 1 },
  2151. { 0 }
  2152. };
  2153. if (t4_handle_intr_status(adapter, TP_INT_CAUSE_A, tp_intr_info))
  2154. t4_fatal_err(adapter);
  2155. }
  2156. /*
  2157. * SGE interrupt handler.
  2158. */
  2159. static void sge_intr_handler(struct adapter *adapter)
  2160. {
  2161. u64 v;
  2162. static const struct intr_info sge_intr_info[] = {
  2163. { ERR_CPL_EXCEED_IQE_SIZE_F,
  2164. "SGE received CPL exceeding IQE size", -1, 1 },
  2165. { ERR_INVALID_CIDX_INC_F,
  2166. "SGE GTS CIDX increment too large", -1, 0 },
  2167. { ERR_CPL_OPCODE_0_F, "SGE received 0-length CPL", -1, 0 },
  2168. { DBFIFO_LP_INT_F, NULL, -1, 0, t4_db_full },
  2169. { DBFIFO_HP_INT_F, NULL, -1, 0, t4_db_full },
  2170. { ERR_DROPPED_DB_F, NULL, -1, 0, t4_db_dropped },
  2171. { ERR_DATA_CPL_ON_HIGH_QID1_F | ERR_DATA_CPL_ON_HIGH_QID0_F,
  2172. "SGE IQID > 1023 received CPL for FL", -1, 0 },
  2173. { ERR_BAD_DB_PIDX3_F, "SGE DBP 3 pidx increment too large", -1,
  2174. 0 },
  2175. { ERR_BAD_DB_PIDX2_F, "SGE DBP 2 pidx increment too large", -1,
  2176. 0 },
  2177. { ERR_BAD_DB_PIDX1_F, "SGE DBP 1 pidx increment too large", -1,
  2178. 0 },
  2179. { ERR_BAD_DB_PIDX0_F, "SGE DBP 0 pidx increment too large", -1,
  2180. 0 },
  2181. { ERR_ING_CTXT_PRIO_F,
  2182. "SGE too many priority ingress contexts", -1, 0 },
  2183. { ERR_EGR_CTXT_PRIO_F,
  2184. "SGE too many priority egress contexts", -1, 0 },
  2185. { INGRESS_SIZE_ERR_F, "SGE illegal ingress QID", -1, 0 },
  2186. { EGRESS_SIZE_ERR_F, "SGE illegal egress QID", -1, 0 },
  2187. { 0 }
  2188. };
  2189. v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1_A) |
  2190. ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2_A) << 32);
  2191. if (v) {
  2192. dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
  2193. (unsigned long long)v);
  2194. t4_write_reg(adapter, SGE_INT_CAUSE1_A, v);
  2195. t4_write_reg(adapter, SGE_INT_CAUSE2_A, v >> 32);
  2196. }
  2197. if (t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A, sge_intr_info) ||
  2198. v != 0)
  2199. t4_fatal_err(adapter);
  2200. }
  2201. #define CIM_OBQ_INTR (OBQULP0PARERR_F | OBQULP1PARERR_F | OBQULP2PARERR_F |\
  2202. OBQULP3PARERR_F | OBQSGEPARERR_F | OBQNCSIPARERR_F)
  2203. #define CIM_IBQ_INTR (IBQTP0PARERR_F | IBQTP1PARERR_F | IBQULPPARERR_F |\
  2204. IBQSGEHIPARERR_F | IBQSGELOPARERR_F | IBQNCSIPARERR_F)
  2205. /*
  2206. * CIM interrupt handler.
  2207. */
  2208. static void cim_intr_handler(struct adapter *adapter)
  2209. {
  2210. static const struct intr_info cim_intr_info[] = {
  2211. { PREFDROPINT_F, "CIM control register prefetch drop", -1, 1 },
  2212. { CIM_OBQ_INTR, "CIM OBQ parity error", -1, 1 },
  2213. { CIM_IBQ_INTR, "CIM IBQ parity error", -1, 1 },
  2214. { MBUPPARERR_F, "CIM mailbox uP parity error", -1, 1 },
  2215. { MBHOSTPARERR_F, "CIM mailbox host parity error", -1, 1 },
  2216. { TIEQINPARERRINT_F, "CIM TIEQ outgoing parity error", -1, 1 },
  2217. { TIEQOUTPARERRINT_F, "CIM TIEQ incoming parity error", -1, 1 },
  2218. { 0 }
  2219. };
  2220. static const struct intr_info cim_upintr_info[] = {
  2221. { RSVDSPACEINT_F, "CIM reserved space access", -1, 1 },
  2222. { ILLTRANSINT_F, "CIM illegal transaction", -1, 1 },
  2223. { ILLWRINT_F, "CIM illegal write", -1, 1 },
  2224. { ILLRDINT_F, "CIM illegal read", -1, 1 },
  2225. { ILLRDBEINT_F, "CIM illegal read BE", -1, 1 },
  2226. { ILLWRBEINT_F, "CIM illegal write BE", -1, 1 },
  2227. { SGLRDBOOTINT_F, "CIM single read from boot space", -1, 1 },
  2228. { SGLWRBOOTINT_F, "CIM single write to boot space", -1, 1 },
  2229. { BLKWRBOOTINT_F, "CIM block write to boot space", -1, 1 },
  2230. { SGLRDFLASHINT_F, "CIM single read from flash space", -1, 1 },
  2231. { SGLWRFLASHINT_F, "CIM single write to flash space", -1, 1 },
  2232. { BLKWRFLASHINT_F, "CIM block write to flash space", -1, 1 },
  2233. { SGLRDEEPROMINT_F, "CIM single EEPROM read", -1, 1 },
  2234. { SGLWREEPROMINT_F, "CIM single EEPROM write", -1, 1 },
  2235. { BLKRDEEPROMINT_F, "CIM block EEPROM read", -1, 1 },
  2236. { BLKWREEPROMINT_F, "CIM block EEPROM write", -1, 1 },
  2237. { SGLRDCTLINT_F, "CIM single read from CTL space", -1, 1 },
  2238. { SGLWRCTLINT_F, "CIM single write to CTL space", -1, 1 },
  2239. { BLKRDCTLINT_F, "CIM block read from CTL space", -1, 1 },
  2240. { BLKWRCTLINT_F, "CIM block write to CTL space", -1, 1 },
  2241. { SGLRDPLINT_F, "CIM single read from PL space", -1, 1 },
  2242. { SGLWRPLINT_F, "CIM single write to PL space", -1, 1 },
  2243. { BLKRDPLINT_F, "CIM block read from PL space", -1, 1 },
  2244. { BLKWRPLINT_F, "CIM block write to PL space", -1, 1 },
  2245. { REQOVRLOOKUPINT_F, "CIM request FIFO overwrite", -1, 1 },
  2246. { RSPOVRLOOKUPINT_F, "CIM response FIFO overwrite", -1, 1 },
  2247. { TIMEOUTINT_F, "CIM PIF timeout", -1, 1 },
  2248. { TIMEOUTMAINT_F, "CIM PIF MA timeout", -1, 1 },
  2249. { 0 }
  2250. };
  2251. int fat;
  2252. if (t4_read_reg(adapter, PCIE_FW_A) & PCIE_FW_ERR_F)
  2253. t4_report_fw_error(adapter);
  2254. fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE_A,
  2255. cim_intr_info) +
  2256. t4_handle_intr_status(adapter, CIM_HOST_UPACC_INT_CAUSE_A,
  2257. cim_upintr_info);
  2258. if (fat)
  2259. t4_fatal_err(adapter);
  2260. }
  2261. /*
  2262. * ULP RX interrupt handler.
  2263. */
  2264. static void ulprx_intr_handler(struct adapter *adapter)
  2265. {
  2266. static const struct intr_info ulprx_intr_info[] = {
  2267. { 0x1800000, "ULPRX context error", -1, 1 },
  2268. { 0x7fffff, "ULPRX parity error", -1, 1 },
  2269. { 0 }
  2270. };
  2271. if (t4_handle_intr_status(adapter, ULP_RX_INT_CAUSE_A, ulprx_intr_info))
  2272. t4_fatal_err(adapter);
  2273. }
  2274. /*
  2275. * ULP TX interrupt handler.
  2276. */
  2277. static void ulptx_intr_handler(struct adapter *adapter)
  2278. {
  2279. static const struct intr_info ulptx_intr_info[] = {
  2280. { PBL_BOUND_ERR_CH3_F, "ULPTX channel 3 PBL out of bounds", -1,
  2281. 0 },
  2282. { PBL_BOUND_ERR_CH2_F, "ULPTX channel 2 PBL out of bounds", -1,
  2283. 0 },
  2284. { PBL_BOUND_ERR_CH1_F, "ULPTX channel 1 PBL out of bounds", -1,
  2285. 0 },
  2286. { PBL_BOUND_ERR_CH0_F, "ULPTX channel 0 PBL out of bounds", -1,
  2287. 0 },
  2288. { 0xfffffff, "ULPTX parity error", -1, 1 },
  2289. { 0 }
  2290. };
  2291. if (t4_handle_intr_status(adapter, ULP_TX_INT_CAUSE_A, ulptx_intr_info))
  2292. t4_fatal_err(adapter);
  2293. }
  2294. /*
  2295. * PM TX interrupt handler.
  2296. */
  2297. static void pmtx_intr_handler(struct adapter *adapter)
  2298. {
  2299. static const struct intr_info pmtx_intr_info[] = {
  2300. { PCMD_LEN_OVFL0_F, "PMTX channel 0 pcmd too large", -1, 1 },
  2301. { PCMD_LEN_OVFL1_F, "PMTX channel 1 pcmd too large", -1, 1 },
  2302. { PCMD_LEN_OVFL2_F, "PMTX channel 2 pcmd too large", -1, 1 },
  2303. { ZERO_C_CMD_ERROR_F, "PMTX 0-length pcmd", -1, 1 },
  2304. { PMTX_FRAMING_ERROR_F, "PMTX framing error", -1, 1 },
  2305. { OESPI_PAR_ERROR_F, "PMTX oespi parity error", -1, 1 },
  2306. { DB_OPTIONS_PAR_ERROR_F, "PMTX db_options parity error",
  2307. -1, 1 },
  2308. { ICSPI_PAR_ERROR_F, "PMTX icspi parity error", -1, 1 },
  2309. { PMTX_C_PCMD_PAR_ERROR_F, "PMTX c_pcmd parity error", -1, 1},
  2310. { 0 }
  2311. };
  2312. if (t4_handle_intr_status(adapter, PM_TX_INT_CAUSE_A, pmtx_intr_info))
  2313. t4_fatal_err(adapter);
  2314. }
  2315. /*
  2316. * PM RX interrupt handler.
  2317. */
  2318. static void pmrx_intr_handler(struct adapter *adapter)
  2319. {
  2320. static const struct intr_info pmrx_intr_info[] = {
  2321. { ZERO_E_CMD_ERROR_F, "PMRX 0-length pcmd", -1, 1 },
  2322. { PMRX_FRAMING_ERROR_F, "PMRX framing error", -1, 1 },
  2323. { OCSPI_PAR_ERROR_F, "PMRX ocspi parity error", -1, 1 },
  2324. { DB_OPTIONS_PAR_ERROR_F, "PMRX db_options parity error",
  2325. -1, 1 },
  2326. { IESPI_PAR_ERROR_F, "PMRX iespi parity error", -1, 1 },
  2327. { PMRX_E_PCMD_PAR_ERROR_F, "PMRX e_pcmd parity error", -1, 1},
  2328. { 0 }
  2329. };
  2330. if (t4_handle_intr_status(adapter, PM_RX_INT_CAUSE_A, pmrx_intr_info))
  2331. t4_fatal_err(adapter);
  2332. }
  2333. /*
  2334. * CPL switch interrupt handler.
  2335. */
  2336. static void cplsw_intr_handler(struct adapter *adapter)
  2337. {
  2338. static const struct intr_info cplsw_intr_info[] = {
  2339. { CIM_OP_MAP_PERR_F, "CPLSW CIM op_map parity error", -1, 1 },
  2340. { CIM_OVFL_ERROR_F, "CPLSW CIM overflow", -1, 1 },
  2341. { TP_FRAMING_ERROR_F, "CPLSW TP framing error", -1, 1 },
  2342. { SGE_FRAMING_ERROR_F, "CPLSW SGE framing error", -1, 1 },
  2343. { CIM_FRAMING_ERROR_F, "CPLSW CIM framing error", -1, 1 },
  2344. { ZERO_SWITCH_ERROR_F, "CPLSW no-switch error", -1, 1 },
  2345. { 0 }
  2346. };
  2347. if (t4_handle_intr_status(adapter, CPL_INTR_CAUSE_A, cplsw_intr_info))
  2348. t4_fatal_err(adapter);
  2349. }
  2350. /*
  2351. * LE interrupt handler.
  2352. */
  2353. static void le_intr_handler(struct adapter *adap)
  2354. {
  2355. static const struct intr_info le_intr_info[] = {
  2356. { LIPMISS_F, "LE LIP miss", -1, 0 },
  2357. { LIP0_F, "LE 0 LIP error", -1, 0 },
  2358. { PARITYERR_F, "LE parity error", -1, 1 },
  2359. { UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  2360. { REQQPARERR_F, "LE request queue parity error", -1, 1 },
  2361. { 0 }
  2362. };
  2363. if (t4_handle_intr_status(adap, LE_DB_INT_CAUSE_A, le_intr_info))
  2364. t4_fatal_err(adap);
  2365. }
  2366. /*
  2367. * MPS interrupt handler.
  2368. */
  2369. static void mps_intr_handler(struct adapter *adapter)
  2370. {
  2371. static const struct intr_info mps_rx_intr_info[] = {
  2372. { 0xffffff, "MPS Rx parity error", -1, 1 },
  2373. { 0 }
  2374. };
  2375. static const struct intr_info mps_tx_intr_info[] = {
  2376. { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
  2377. { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
  2378. { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
  2379. -1, 1 },
  2380. { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
  2381. -1, 1 },
  2382. { BUBBLE_F, "MPS Tx underflow", -1, 1 },
  2383. { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
  2384. { FRMERR_F, "MPS Tx framing error", -1, 1 },
  2385. { 0 }
  2386. };
  2387. static const struct intr_info mps_trc_intr_info[] = {
  2388. { FILTMEM_V(FILTMEM_M), "MPS TRC filter parity error", -1, 1 },
  2389. { PKTFIFO_V(PKTFIFO_M), "MPS TRC packet FIFO parity error",
  2390. -1, 1 },
  2391. { MISCPERR_F, "MPS TRC misc parity error", -1, 1 },
  2392. { 0 }
  2393. };
  2394. static const struct intr_info mps_stat_sram_intr_info[] = {
  2395. { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
  2396. { 0 }
  2397. };
  2398. static const struct intr_info mps_stat_tx_intr_info[] = {
  2399. { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
  2400. { 0 }
  2401. };
  2402. static const struct intr_info mps_stat_rx_intr_info[] = {
  2403. { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
  2404. { 0 }
  2405. };
  2406. static const struct intr_info mps_cls_intr_info[] = {
  2407. { MATCHSRAM_F, "MPS match SRAM parity error", -1, 1 },
  2408. { MATCHTCAM_F, "MPS match TCAM parity error", -1, 1 },
  2409. { HASHSRAM_F, "MPS hash SRAM parity error", -1, 1 },
  2410. { 0 }
  2411. };
  2412. int fat;
  2413. fat = t4_handle_intr_status(adapter, MPS_RX_PERR_INT_CAUSE_A,
  2414. mps_rx_intr_info) +
  2415. t4_handle_intr_status(adapter, MPS_TX_INT_CAUSE_A,
  2416. mps_tx_intr_info) +
  2417. t4_handle_intr_status(adapter, MPS_TRC_INT_CAUSE_A,
  2418. mps_trc_intr_info) +
  2419. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_SRAM_A,
  2420. mps_stat_sram_intr_info) +
  2421. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_TX_FIFO_A,
  2422. mps_stat_tx_intr_info) +
  2423. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_RX_FIFO_A,
  2424. mps_stat_rx_intr_info) +
  2425. t4_handle_intr_status(adapter, MPS_CLS_INT_CAUSE_A,
  2426. mps_cls_intr_info);
  2427. t4_write_reg(adapter, MPS_INT_CAUSE_A, 0);
  2428. t4_read_reg(adapter, MPS_INT_CAUSE_A); /* flush */
  2429. if (fat)
  2430. t4_fatal_err(adapter);
  2431. }
  2432. #define MEM_INT_MASK (PERR_INT_CAUSE_F | ECC_CE_INT_CAUSE_F | \
  2433. ECC_UE_INT_CAUSE_F)
  2434. /*
  2435. * EDC/MC interrupt handler.
  2436. */
  2437. static void mem_intr_handler(struct adapter *adapter, int idx)
  2438. {
  2439. static const char name[4][7] = { "EDC0", "EDC1", "MC/MC0", "MC1" };
  2440. unsigned int addr, cnt_addr, v;
  2441. if (idx <= MEM_EDC1) {
  2442. addr = EDC_REG(EDC_INT_CAUSE_A, idx);
  2443. cnt_addr = EDC_REG(EDC_ECC_STATUS_A, idx);
  2444. } else if (idx == MEM_MC) {
  2445. if (is_t4(adapter->params.chip)) {
  2446. addr = MC_INT_CAUSE_A;
  2447. cnt_addr = MC_ECC_STATUS_A;
  2448. } else {
  2449. addr = MC_P_INT_CAUSE_A;
  2450. cnt_addr = MC_P_ECC_STATUS_A;
  2451. }
  2452. } else {
  2453. addr = MC_REG(MC_P_INT_CAUSE_A, 1);
  2454. cnt_addr = MC_REG(MC_P_ECC_STATUS_A, 1);
  2455. }
  2456. v = t4_read_reg(adapter, addr) & MEM_INT_MASK;
  2457. if (v & PERR_INT_CAUSE_F)
  2458. dev_alert(adapter->pdev_dev, "%s FIFO parity error\n",
  2459. name[idx]);
  2460. if (v & ECC_CE_INT_CAUSE_F) {
  2461. u32 cnt = ECC_CECNT_G(t4_read_reg(adapter, cnt_addr));
  2462. t4_write_reg(adapter, cnt_addr, ECC_CECNT_V(ECC_CECNT_M));
  2463. if (printk_ratelimit())
  2464. dev_warn(adapter->pdev_dev,
  2465. "%u %s correctable ECC data error%s\n",
  2466. cnt, name[idx], cnt > 1 ? "s" : "");
  2467. }
  2468. if (v & ECC_UE_INT_CAUSE_F)
  2469. dev_alert(adapter->pdev_dev,
  2470. "%s uncorrectable ECC data error\n", name[idx]);
  2471. t4_write_reg(adapter, addr, v);
  2472. if (v & (PERR_INT_CAUSE_F | ECC_UE_INT_CAUSE_F))
  2473. t4_fatal_err(adapter);
  2474. }
  2475. /*
  2476. * MA interrupt handler.
  2477. */
  2478. static void ma_intr_handler(struct adapter *adap)
  2479. {
  2480. u32 v, status = t4_read_reg(adap, MA_INT_CAUSE_A);
  2481. if (status & MEM_PERR_INT_CAUSE_F) {
  2482. dev_alert(adap->pdev_dev,
  2483. "MA parity error, parity status %#x\n",
  2484. t4_read_reg(adap, MA_PARITY_ERROR_STATUS1_A));
  2485. if (is_t5(adap->params.chip))
  2486. dev_alert(adap->pdev_dev,
  2487. "MA parity error, parity status %#x\n",
  2488. t4_read_reg(adap,
  2489. MA_PARITY_ERROR_STATUS2_A));
  2490. }
  2491. if (status & MEM_WRAP_INT_CAUSE_F) {
  2492. v = t4_read_reg(adap, MA_INT_WRAP_STATUS_A);
  2493. dev_alert(adap->pdev_dev, "MA address wrap-around error by "
  2494. "client %u to address %#x\n",
  2495. MEM_WRAP_CLIENT_NUM_G(v),
  2496. MEM_WRAP_ADDRESS_G(v) << 4);
  2497. }
  2498. t4_write_reg(adap, MA_INT_CAUSE_A, status);
  2499. t4_fatal_err(adap);
  2500. }
  2501. /*
  2502. * SMB interrupt handler.
  2503. */
  2504. static void smb_intr_handler(struct adapter *adap)
  2505. {
  2506. static const struct intr_info smb_intr_info[] = {
  2507. { MSTTXFIFOPARINT_F, "SMB master Tx FIFO parity error", -1, 1 },
  2508. { MSTRXFIFOPARINT_F, "SMB master Rx FIFO parity error", -1, 1 },
  2509. { SLVFIFOPARINT_F, "SMB slave FIFO parity error", -1, 1 },
  2510. { 0 }
  2511. };
  2512. if (t4_handle_intr_status(adap, SMB_INT_CAUSE_A, smb_intr_info))
  2513. t4_fatal_err(adap);
  2514. }
  2515. /*
  2516. * NC-SI interrupt handler.
  2517. */
  2518. static void ncsi_intr_handler(struct adapter *adap)
  2519. {
  2520. static const struct intr_info ncsi_intr_info[] = {
  2521. { CIM_DM_PRTY_ERR_F, "NC-SI CIM parity error", -1, 1 },
  2522. { MPS_DM_PRTY_ERR_F, "NC-SI MPS parity error", -1, 1 },
  2523. { TXFIFO_PRTY_ERR_F, "NC-SI Tx FIFO parity error", -1, 1 },
  2524. { RXFIFO_PRTY_ERR_F, "NC-SI Rx FIFO parity error", -1, 1 },
  2525. { 0 }
  2526. };
  2527. if (t4_handle_intr_status(adap, NCSI_INT_CAUSE_A, ncsi_intr_info))
  2528. t4_fatal_err(adap);
  2529. }
  2530. /*
  2531. * XGMAC interrupt handler.
  2532. */
  2533. static void xgmac_intr_handler(struct adapter *adap, int port)
  2534. {
  2535. u32 v, int_cause_reg;
  2536. if (is_t4(adap->params.chip))
  2537. int_cause_reg = PORT_REG(port, XGMAC_PORT_INT_CAUSE_A);
  2538. else
  2539. int_cause_reg = T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A);
  2540. v = t4_read_reg(adap, int_cause_reg);
  2541. v &= TXFIFO_PRTY_ERR_F | RXFIFO_PRTY_ERR_F;
  2542. if (!v)
  2543. return;
  2544. if (v & TXFIFO_PRTY_ERR_F)
  2545. dev_alert(adap->pdev_dev, "XGMAC %d Tx FIFO parity error\n",
  2546. port);
  2547. if (v & RXFIFO_PRTY_ERR_F)
  2548. dev_alert(adap->pdev_dev, "XGMAC %d Rx FIFO parity error\n",
  2549. port);
  2550. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE_A), v);
  2551. t4_fatal_err(adap);
  2552. }
  2553. /*
  2554. * PL interrupt handler.
  2555. */
  2556. static void pl_intr_handler(struct adapter *adap)
  2557. {
  2558. static const struct intr_info pl_intr_info[] = {
  2559. { FATALPERR_F, "T4 fatal parity error", -1, 1 },
  2560. { PERRVFID_F, "PL VFID_MAP parity error", -1, 1 },
  2561. { 0 }
  2562. };
  2563. if (t4_handle_intr_status(adap, PL_PL_INT_CAUSE_A, pl_intr_info))
  2564. t4_fatal_err(adap);
  2565. }
  2566. #define PF_INTR_MASK (PFSW_F)
  2567. #define GLBL_INTR_MASK (CIM_F | MPS_F | PL_F | PCIE_F | MC_F | EDC0_F | \
  2568. EDC1_F | LE_F | TP_F | MA_F | PM_TX_F | PM_RX_F | ULP_RX_F | \
  2569. CPL_SWITCH_F | SGE_F | ULP_TX_F)
  2570. /**
  2571. * t4_slow_intr_handler - control path interrupt handler
  2572. * @adapter: the adapter
  2573. *
  2574. * T4 interrupt handler for non-data global interrupt events, e.g., errors.
  2575. * The designation 'slow' is because it involves register reads, while
  2576. * data interrupts typically don't involve any MMIOs.
  2577. */
  2578. int t4_slow_intr_handler(struct adapter *adapter)
  2579. {
  2580. u32 cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
  2581. if (!(cause & GLBL_INTR_MASK))
  2582. return 0;
  2583. if (cause & CIM_F)
  2584. cim_intr_handler(adapter);
  2585. if (cause & MPS_F)
  2586. mps_intr_handler(adapter);
  2587. if (cause & NCSI_F)
  2588. ncsi_intr_handler(adapter);
  2589. if (cause & PL_F)
  2590. pl_intr_handler(adapter);
  2591. if (cause & SMB_F)
  2592. smb_intr_handler(adapter);
  2593. if (cause & XGMAC0_F)
  2594. xgmac_intr_handler(adapter, 0);
  2595. if (cause & XGMAC1_F)
  2596. xgmac_intr_handler(adapter, 1);
  2597. if (cause & XGMAC_KR0_F)
  2598. xgmac_intr_handler(adapter, 2);
  2599. if (cause & XGMAC_KR1_F)
  2600. xgmac_intr_handler(adapter, 3);
  2601. if (cause & PCIE_F)
  2602. pcie_intr_handler(adapter);
  2603. if (cause & MC_F)
  2604. mem_intr_handler(adapter, MEM_MC);
  2605. if (!is_t4(adapter->params.chip) && (cause & MC1_S))
  2606. mem_intr_handler(adapter, MEM_MC1);
  2607. if (cause & EDC0_F)
  2608. mem_intr_handler(adapter, MEM_EDC0);
  2609. if (cause & EDC1_F)
  2610. mem_intr_handler(adapter, MEM_EDC1);
  2611. if (cause & LE_F)
  2612. le_intr_handler(adapter);
  2613. if (cause & TP_F)
  2614. tp_intr_handler(adapter);
  2615. if (cause & MA_F)
  2616. ma_intr_handler(adapter);
  2617. if (cause & PM_TX_F)
  2618. pmtx_intr_handler(adapter);
  2619. if (cause & PM_RX_F)
  2620. pmrx_intr_handler(adapter);
  2621. if (cause & ULP_RX_F)
  2622. ulprx_intr_handler(adapter);
  2623. if (cause & CPL_SWITCH_F)
  2624. cplsw_intr_handler(adapter);
  2625. if (cause & SGE_F)
  2626. sge_intr_handler(adapter);
  2627. if (cause & ULP_TX_F)
  2628. ulptx_intr_handler(adapter);
  2629. /* Clear the interrupts just processed for which we are the master. */
  2630. t4_write_reg(adapter, PL_INT_CAUSE_A, cause & GLBL_INTR_MASK);
  2631. (void)t4_read_reg(adapter, PL_INT_CAUSE_A); /* flush */
  2632. return 1;
  2633. }
  2634. /**
  2635. * t4_intr_enable - enable interrupts
  2636. * @adapter: the adapter whose interrupts should be enabled
  2637. *
  2638. * Enable PF-specific interrupts for the calling function and the top-level
  2639. * interrupt concentrator for global interrupts. Interrupts are already
  2640. * enabled at each module, here we just enable the roots of the interrupt
  2641. * hierarchies.
  2642. *
  2643. * Note: this function should be called only when the driver manages
  2644. * non PF-specific interrupts from the various HW modules. Only one PCI
  2645. * function at a time should be doing this.
  2646. */
  2647. void t4_intr_enable(struct adapter *adapter)
  2648. {
  2649. u32 pf = SOURCEPF_G(t4_read_reg(adapter, PL_WHOAMI_A));
  2650. t4_write_reg(adapter, SGE_INT_ENABLE3_A, ERR_CPL_EXCEED_IQE_SIZE_F |
  2651. ERR_INVALID_CIDX_INC_F | ERR_CPL_OPCODE_0_F |
  2652. ERR_DROPPED_DB_F | ERR_DATA_CPL_ON_HIGH_QID1_F |
  2653. ERR_DATA_CPL_ON_HIGH_QID0_F | ERR_BAD_DB_PIDX3_F |
  2654. ERR_BAD_DB_PIDX2_F | ERR_BAD_DB_PIDX1_F |
  2655. ERR_BAD_DB_PIDX0_F | ERR_ING_CTXT_PRIO_F |
  2656. ERR_EGR_CTXT_PRIO_F | INGRESS_SIZE_ERR_F |
  2657. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F |
  2658. EGRESS_SIZE_ERR_F);
  2659. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), PF_INTR_MASK);
  2660. t4_set_reg_field(adapter, PL_INT_MAP0_A, 0, 1 << pf);
  2661. }
  2662. /**
  2663. * t4_intr_disable - disable interrupts
  2664. * @adapter: the adapter whose interrupts should be disabled
  2665. *
  2666. * Disable interrupts. We only disable the top-level interrupt
  2667. * concentrators. The caller must be a PCI function managing global
  2668. * interrupts.
  2669. */
  2670. void t4_intr_disable(struct adapter *adapter)
  2671. {
  2672. u32 pf = SOURCEPF_G(t4_read_reg(adapter, PL_WHOAMI_A));
  2673. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), 0);
  2674. t4_set_reg_field(adapter, PL_INT_MAP0_A, 1 << pf, 0);
  2675. }
  2676. /**
  2677. * hash_mac_addr - return the hash value of a MAC address
  2678. * @addr: the 48-bit Ethernet MAC address
  2679. *
  2680. * Hashes a MAC address according to the hash function used by HW inexact
  2681. * (hash) address matching.
  2682. */
  2683. static int hash_mac_addr(const u8 *addr)
  2684. {
  2685. u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
  2686. u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
  2687. a ^= b;
  2688. a ^= (a >> 12);
  2689. a ^= (a >> 6);
  2690. return a & 0x3f;
  2691. }
  2692. /**
  2693. * t4_config_rss_range - configure a portion of the RSS mapping table
  2694. * @adapter: the adapter
  2695. * @mbox: mbox to use for the FW command
  2696. * @viid: virtual interface whose RSS subtable is to be written
  2697. * @start: start entry in the table to write
  2698. * @n: how many table entries to write
  2699. * @rspq: values for the response queue lookup table
  2700. * @nrspq: number of values in @rspq
  2701. *
  2702. * Programs the selected part of the VI's RSS mapping table with the
  2703. * provided values. If @nrspq < @n the supplied values are used repeatedly
  2704. * until the full table range is populated.
  2705. *
  2706. * The caller must ensure the values in @rspq are in the range allowed for
  2707. * @viid.
  2708. */
  2709. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  2710. int start, int n, const u16 *rspq, unsigned int nrspq)
  2711. {
  2712. int ret;
  2713. const u16 *rsp = rspq;
  2714. const u16 *rsp_end = rspq + nrspq;
  2715. struct fw_rss_ind_tbl_cmd cmd;
  2716. memset(&cmd, 0, sizeof(cmd));
  2717. cmd.op_to_viid = htonl(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
  2718. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  2719. FW_RSS_IND_TBL_CMD_VIID_V(viid));
  2720. cmd.retval_len16 = htonl(FW_LEN16(cmd));
  2721. /* each fw_rss_ind_tbl_cmd takes up to 32 entries */
  2722. while (n > 0) {
  2723. int nq = min(n, 32);
  2724. __be32 *qp = &cmd.iq0_to_iq2;
  2725. cmd.niqid = htons(nq);
  2726. cmd.startidx = htons(start);
  2727. start += nq;
  2728. n -= nq;
  2729. while (nq > 0) {
  2730. unsigned int v;
  2731. v = FW_RSS_IND_TBL_CMD_IQ0_V(*rsp);
  2732. if (++rsp >= rsp_end)
  2733. rsp = rspq;
  2734. v |= FW_RSS_IND_TBL_CMD_IQ1_V(*rsp);
  2735. if (++rsp >= rsp_end)
  2736. rsp = rspq;
  2737. v |= FW_RSS_IND_TBL_CMD_IQ2_V(*rsp);
  2738. if (++rsp >= rsp_end)
  2739. rsp = rspq;
  2740. *qp++ = htonl(v);
  2741. nq -= 3;
  2742. }
  2743. ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
  2744. if (ret)
  2745. return ret;
  2746. }
  2747. return 0;
  2748. }
  2749. /**
  2750. * t4_config_glbl_rss - configure the global RSS mode
  2751. * @adapter: the adapter
  2752. * @mbox: mbox to use for the FW command
  2753. * @mode: global RSS mode
  2754. * @flags: mode-specific flags
  2755. *
  2756. * Sets the global RSS mode.
  2757. */
  2758. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  2759. unsigned int flags)
  2760. {
  2761. struct fw_rss_glb_config_cmd c;
  2762. memset(&c, 0, sizeof(c));
  2763. c.op_to_write = htonl(FW_CMD_OP_V(FW_RSS_GLB_CONFIG_CMD) |
  2764. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  2765. c.retval_len16 = htonl(FW_LEN16(c));
  2766. if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
  2767. c.u.manual.mode_pkd = htonl(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  2768. } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  2769. c.u.basicvirtual.mode_pkd =
  2770. htonl(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  2771. c.u.basicvirtual.synmapen_to_hashtoeplitz = htonl(flags);
  2772. } else
  2773. return -EINVAL;
  2774. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  2775. }
  2776. /* Read an RSS table row */
  2777. static int rd_rss_row(struct adapter *adap, int row, u32 *val)
  2778. {
  2779. t4_write_reg(adap, TP_RSS_LKP_TABLE_A, 0xfff00000 | row);
  2780. return t4_wait_op_done_val(adap, TP_RSS_LKP_TABLE_A, LKPTBLROWVLD_F, 1,
  2781. 5, 0, val);
  2782. }
  2783. /**
  2784. * t4_read_rss - read the contents of the RSS mapping table
  2785. * @adapter: the adapter
  2786. * @map: holds the contents of the RSS mapping table
  2787. *
  2788. * Reads the contents of the RSS hash->queue mapping table.
  2789. */
  2790. int t4_read_rss(struct adapter *adapter, u16 *map)
  2791. {
  2792. u32 val;
  2793. int i, ret;
  2794. for (i = 0; i < RSS_NENTRIES / 2; ++i) {
  2795. ret = rd_rss_row(adapter, i, &val);
  2796. if (ret)
  2797. return ret;
  2798. *map++ = LKPTBLQUEUE0_G(val);
  2799. *map++ = LKPTBLQUEUE1_G(val);
  2800. }
  2801. return 0;
  2802. }
  2803. /**
  2804. * t4_read_rss_key - read the global RSS key
  2805. * @adap: the adapter
  2806. * @key: 10-entry array holding the 320-bit RSS key
  2807. *
  2808. * Reads the global 320-bit RSS key.
  2809. */
  2810. void t4_read_rss_key(struct adapter *adap, u32 *key)
  2811. {
  2812. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  2813. TP_RSS_SECRET_KEY0_A);
  2814. }
  2815. /**
  2816. * t4_write_rss_key - program one of the RSS keys
  2817. * @adap: the adapter
  2818. * @key: 10-entry array holding the 320-bit RSS key
  2819. * @idx: which RSS key to write
  2820. *
  2821. * Writes one of the RSS keys with the given 320-bit value. If @idx is
  2822. * 0..15 the corresponding entry in the RSS key table is written,
  2823. * otherwise the global RSS key is written.
  2824. */
  2825. void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx)
  2826. {
  2827. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  2828. TP_RSS_SECRET_KEY0_A);
  2829. if (idx >= 0 && idx < 16)
  2830. t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
  2831. KEYWRADDR_V(idx) | KEYWREN_F);
  2832. }
  2833. /**
  2834. * t4_read_rss_pf_config - read PF RSS Configuration Table
  2835. * @adapter: the adapter
  2836. * @index: the entry in the PF RSS table to read
  2837. * @valp: where to store the returned value
  2838. *
  2839. * Reads the PF RSS Configuration Table at the specified index and returns
  2840. * the value found there.
  2841. */
  2842. void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
  2843. u32 *valp)
  2844. {
  2845. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2846. valp, 1, TP_RSS_PF0_CONFIG_A + index);
  2847. }
  2848. /**
  2849. * t4_read_rss_vf_config - read VF RSS Configuration Table
  2850. * @adapter: the adapter
  2851. * @index: the entry in the VF RSS table to read
  2852. * @vfl: where to store the returned VFL
  2853. * @vfh: where to store the returned VFH
  2854. *
  2855. * Reads the VF RSS Configuration Table at the specified index and returns
  2856. * the (VFL, VFH) values found there.
  2857. */
  2858. void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
  2859. u32 *vfl, u32 *vfh)
  2860. {
  2861. u32 vrt, mask, data;
  2862. mask = VFWRADDR_V(VFWRADDR_M);
  2863. data = VFWRADDR_V(index);
  2864. /* Request that the index'th VF Table values be read into VFL/VFH.
  2865. */
  2866. vrt = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
  2867. vrt &= ~(VFRDRG_F | VFWREN_F | KEYWREN_F | mask);
  2868. vrt |= data | VFRDEN_F;
  2869. t4_write_reg(adapter, TP_RSS_CONFIG_VRT_A, vrt);
  2870. /* Grab the VFL/VFH values ...
  2871. */
  2872. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2873. vfl, 1, TP_RSS_VFL_CONFIG_A);
  2874. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2875. vfh, 1, TP_RSS_VFH_CONFIG_A);
  2876. }
  2877. /**
  2878. * t4_read_rss_pf_map - read PF RSS Map
  2879. * @adapter: the adapter
  2880. *
  2881. * Reads the PF RSS Map register and returns its value.
  2882. */
  2883. u32 t4_read_rss_pf_map(struct adapter *adapter)
  2884. {
  2885. u32 pfmap;
  2886. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2887. &pfmap, 1, TP_RSS_PF_MAP_A);
  2888. return pfmap;
  2889. }
  2890. /**
  2891. * t4_read_rss_pf_mask - read PF RSS Mask
  2892. * @adapter: the adapter
  2893. *
  2894. * Reads the PF RSS Mask register and returns its value.
  2895. */
  2896. u32 t4_read_rss_pf_mask(struct adapter *adapter)
  2897. {
  2898. u32 pfmask;
  2899. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2900. &pfmask, 1, TP_RSS_PF_MSK_A);
  2901. return pfmask;
  2902. }
  2903. /**
  2904. * t4_tp_get_tcp_stats - read TP's TCP MIB counters
  2905. * @adap: the adapter
  2906. * @v4: holds the TCP/IP counter values
  2907. * @v6: holds the TCP/IPv6 counter values
  2908. *
  2909. * Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
  2910. * Either @v4 or @v6 may be %NULL to skip the corresponding stats.
  2911. */
  2912. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  2913. struct tp_tcp_stats *v6)
  2914. {
  2915. u32 val[TP_MIB_TCP_RXT_SEG_LO_A - TP_MIB_TCP_OUT_RST_A + 1];
  2916. #define STAT_IDX(x) ((TP_MIB_TCP_##x##_A) - TP_MIB_TCP_OUT_RST_A)
  2917. #define STAT(x) val[STAT_IDX(x)]
  2918. #define STAT64(x) (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
  2919. if (v4) {
  2920. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  2921. ARRAY_SIZE(val), TP_MIB_TCP_OUT_RST_A);
  2922. v4->tcpOutRsts = STAT(OUT_RST);
  2923. v4->tcpInSegs = STAT64(IN_SEG);
  2924. v4->tcpOutSegs = STAT64(OUT_SEG);
  2925. v4->tcpRetransSegs = STAT64(RXT_SEG);
  2926. }
  2927. if (v6) {
  2928. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  2929. ARRAY_SIZE(val), TP_MIB_TCP_V6OUT_RST_A);
  2930. v6->tcpOutRsts = STAT(OUT_RST);
  2931. v6->tcpInSegs = STAT64(IN_SEG);
  2932. v6->tcpOutSegs = STAT64(OUT_SEG);
  2933. v6->tcpRetransSegs = STAT64(RXT_SEG);
  2934. }
  2935. #undef STAT64
  2936. #undef STAT
  2937. #undef STAT_IDX
  2938. }
  2939. /**
  2940. * t4_read_mtu_tbl - returns the values in the HW path MTU table
  2941. * @adap: the adapter
  2942. * @mtus: where to store the MTU values
  2943. * @mtu_log: where to store the MTU base-2 log (may be %NULL)
  2944. *
  2945. * Reads the HW path MTU table.
  2946. */
  2947. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
  2948. {
  2949. u32 v;
  2950. int i;
  2951. for (i = 0; i < NMTUS; ++i) {
  2952. t4_write_reg(adap, TP_MTU_TABLE_A,
  2953. MTUINDEX_V(0xff) | MTUVALUE_V(i));
  2954. v = t4_read_reg(adap, TP_MTU_TABLE_A);
  2955. mtus[i] = MTUVALUE_G(v);
  2956. if (mtu_log)
  2957. mtu_log[i] = MTUWIDTH_G(v);
  2958. }
  2959. }
  2960. /**
  2961. * t4_read_cong_tbl - reads the congestion control table
  2962. * @adap: the adapter
  2963. * @incr: where to store the alpha values
  2964. *
  2965. * Reads the additive increments programmed into the HW congestion
  2966. * control table.
  2967. */
  2968. void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
  2969. {
  2970. unsigned int mtu, w;
  2971. for (mtu = 0; mtu < NMTUS; ++mtu)
  2972. for (w = 0; w < NCCTRL_WIN; ++w) {
  2973. t4_write_reg(adap, TP_CCTRL_TABLE_A,
  2974. ROWINDEX_V(0xffff) | (mtu << 5) | w);
  2975. incr[mtu][w] = (u16)t4_read_reg(adap,
  2976. TP_CCTRL_TABLE_A) & 0x1fff;
  2977. }
  2978. }
  2979. /**
  2980. * t4_tp_wr_bits_indirect - set/clear bits in an indirect TP register
  2981. * @adap: the adapter
  2982. * @addr: the indirect TP register address
  2983. * @mask: specifies the field within the register to modify
  2984. * @val: new value for the field
  2985. *
  2986. * Sets a field of an indirect TP register to the given value.
  2987. */
  2988. void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
  2989. unsigned int mask, unsigned int val)
  2990. {
  2991. t4_write_reg(adap, TP_PIO_ADDR_A, addr);
  2992. val |= t4_read_reg(adap, TP_PIO_DATA_A) & ~mask;
  2993. t4_write_reg(adap, TP_PIO_DATA_A, val);
  2994. }
  2995. /**
  2996. * init_cong_ctrl - initialize congestion control parameters
  2997. * @a: the alpha values for congestion control
  2998. * @b: the beta values for congestion control
  2999. *
  3000. * Initialize the congestion control parameters.
  3001. */
  3002. static void init_cong_ctrl(unsigned short *a, unsigned short *b)
  3003. {
  3004. a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
  3005. a[9] = 2;
  3006. a[10] = 3;
  3007. a[11] = 4;
  3008. a[12] = 5;
  3009. a[13] = 6;
  3010. a[14] = 7;
  3011. a[15] = 8;
  3012. a[16] = 9;
  3013. a[17] = 10;
  3014. a[18] = 14;
  3015. a[19] = 17;
  3016. a[20] = 21;
  3017. a[21] = 25;
  3018. a[22] = 30;
  3019. a[23] = 35;
  3020. a[24] = 45;
  3021. a[25] = 60;
  3022. a[26] = 80;
  3023. a[27] = 100;
  3024. a[28] = 200;
  3025. a[29] = 300;
  3026. a[30] = 400;
  3027. a[31] = 500;
  3028. b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
  3029. b[9] = b[10] = 1;
  3030. b[11] = b[12] = 2;
  3031. b[13] = b[14] = b[15] = b[16] = 3;
  3032. b[17] = b[18] = b[19] = b[20] = b[21] = 4;
  3033. b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
  3034. b[28] = b[29] = 6;
  3035. b[30] = b[31] = 7;
  3036. }
  3037. /* The minimum additive increment value for the congestion control table */
  3038. #define CC_MIN_INCR 2U
  3039. /**
  3040. * t4_load_mtus - write the MTU and congestion control HW tables
  3041. * @adap: the adapter
  3042. * @mtus: the values for the MTU table
  3043. * @alpha: the values for the congestion control alpha parameter
  3044. * @beta: the values for the congestion control beta parameter
  3045. *
  3046. * Write the HW MTU table with the supplied MTUs and the high-speed
  3047. * congestion control table with the supplied alpha, beta, and MTUs.
  3048. * We write the two tables together because the additive increments
  3049. * depend on the MTUs.
  3050. */
  3051. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  3052. const unsigned short *alpha, const unsigned short *beta)
  3053. {
  3054. static const unsigned int avg_pkts[NCCTRL_WIN] = {
  3055. 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
  3056. 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
  3057. 28672, 40960, 57344, 81920, 114688, 163840, 229376
  3058. };
  3059. unsigned int i, w;
  3060. for (i = 0; i < NMTUS; ++i) {
  3061. unsigned int mtu = mtus[i];
  3062. unsigned int log2 = fls(mtu);
  3063. if (!(mtu & ((1 << log2) >> 2))) /* round */
  3064. log2--;
  3065. t4_write_reg(adap, TP_MTU_TABLE_A, MTUINDEX_V(i) |
  3066. MTUWIDTH_V(log2) | MTUVALUE_V(mtu));
  3067. for (w = 0; w < NCCTRL_WIN; ++w) {
  3068. unsigned int inc;
  3069. inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
  3070. CC_MIN_INCR);
  3071. t4_write_reg(adap, TP_CCTRL_TABLE_A, (i << 21) |
  3072. (w << 16) | (beta[w] << 13) | inc);
  3073. }
  3074. }
  3075. }
  3076. /**
  3077. * t4_pmtx_get_stats - returns the HW stats from PMTX
  3078. * @adap: the adapter
  3079. * @cnt: where to store the count statistics
  3080. * @cycles: where to store the cycle statistics
  3081. *
  3082. * Returns performance statistics from PMTX.
  3083. */
  3084. void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  3085. {
  3086. int i;
  3087. u32 data[2];
  3088. for (i = 0; i < PM_NSTATS; i++) {
  3089. t4_write_reg(adap, PM_TX_STAT_CONFIG_A, i + 1);
  3090. cnt[i] = t4_read_reg(adap, PM_TX_STAT_COUNT_A);
  3091. if (is_t4(adap->params.chip)) {
  3092. cycles[i] = t4_read_reg64(adap, PM_TX_STAT_LSB_A);
  3093. } else {
  3094. t4_read_indirect(adap, PM_TX_DBG_CTRL_A,
  3095. PM_TX_DBG_DATA_A, data, 2,
  3096. PM_TX_DBG_STAT_MSB_A);
  3097. cycles[i] = (((u64)data[0] << 32) | data[1]);
  3098. }
  3099. }
  3100. }
  3101. /**
  3102. * t4_pmrx_get_stats - returns the HW stats from PMRX
  3103. * @adap: the adapter
  3104. * @cnt: where to store the count statistics
  3105. * @cycles: where to store the cycle statistics
  3106. *
  3107. * Returns performance statistics from PMRX.
  3108. */
  3109. void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  3110. {
  3111. int i;
  3112. u32 data[2];
  3113. for (i = 0; i < PM_NSTATS; i++) {
  3114. t4_write_reg(adap, PM_RX_STAT_CONFIG_A, i + 1);
  3115. cnt[i] = t4_read_reg(adap, PM_RX_STAT_COUNT_A);
  3116. if (is_t4(adap->params.chip)) {
  3117. cycles[i] = t4_read_reg64(adap, PM_RX_STAT_LSB_A);
  3118. } else {
  3119. t4_read_indirect(adap, PM_RX_DBG_CTRL_A,
  3120. PM_RX_DBG_DATA_A, data, 2,
  3121. PM_RX_DBG_STAT_MSB_A);
  3122. cycles[i] = (((u64)data[0] << 32) | data[1]);
  3123. }
  3124. }
  3125. }
  3126. /**
  3127. * get_mps_bg_map - return the buffer groups associated with a port
  3128. * @adap: the adapter
  3129. * @idx: the port index
  3130. *
  3131. * Returns a bitmap indicating which MPS buffer groups are associated
  3132. * with the given port. Bit i is set if buffer group i is used by the
  3133. * port.
  3134. */
  3135. static unsigned int get_mps_bg_map(struct adapter *adap, int idx)
  3136. {
  3137. u32 n = NUMPORTS_G(t4_read_reg(adap, MPS_CMN_CTL_A));
  3138. if (n == 0)
  3139. return idx == 0 ? 0xf : 0;
  3140. if (n == 1)
  3141. return idx < 2 ? (3 << (2 * idx)) : 0;
  3142. return 1 << idx;
  3143. }
  3144. /**
  3145. * t4_get_port_type_description - return Port Type string description
  3146. * @port_type: firmware Port Type enumeration
  3147. */
  3148. const char *t4_get_port_type_description(enum fw_port_type port_type)
  3149. {
  3150. static const char *const port_type_description[] = {
  3151. "R XFI",
  3152. "R XAUI",
  3153. "T SGMII",
  3154. "T XFI",
  3155. "T XAUI",
  3156. "KX4",
  3157. "CX4",
  3158. "KX",
  3159. "KR",
  3160. "R SFP+",
  3161. "KR/KX",
  3162. "KR/KX/KX4",
  3163. "R QSFP_10G",
  3164. "R QSA",
  3165. "R QSFP",
  3166. "R BP40_BA",
  3167. };
  3168. if (port_type < ARRAY_SIZE(port_type_description))
  3169. return port_type_description[port_type];
  3170. return "UNKNOWN";
  3171. }
  3172. /**
  3173. * t4_get_port_stats - collect port statistics
  3174. * @adap: the adapter
  3175. * @idx: the port index
  3176. * @p: the stats structure to fill
  3177. *
  3178. * Collect statistics related to the given port from HW.
  3179. */
  3180. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
  3181. {
  3182. u32 bgmap = get_mps_bg_map(adap, idx);
  3183. #define GET_STAT(name) \
  3184. t4_read_reg64(adap, \
  3185. (is_t4(adap->params.chip) ? PORT_REG(idx, MPS_PORT_STAT_##name##_L) : \
  3186. T5_PORT_REG(idx, MPS_PORT_STAT_##name##_L)))
  3187. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  3188. p->tx_octets = GET_STAT(TX_PORT_BYTES);
  3189. p->tx_frames = GET_STAT(TX_PORT_FRAMES);
  3190. p->tx_bcast_frames = GET_STAT(TX_PORT_BCAST);
  3191. p->tx_mcast_frames = GET_STAT(TX_PORT_MCAST);
  3192. p->tx_ucast_frames = GET_STAT(TX_PORT_UCAST);
  3193. p->tx_error_frames = GET_STAT(TX_PORT_ERROR);
  3194. p->tx_frames_64 = GET_STAT(TX_PORT_64B);
  3195. p->tx_frames_65_127 = GET_STAT(TX_PORT_65B_127B);
  3196. p->tx_frames_128_255 = GET_STAT(TX_PORT_128B_255B);
  3197. p->tx_frames_256_511 = GET_STAT(TX_PORT_256B_511B);
  3198. p->tx_frames_512_1023 = GET_STAT(TX_PORT_512B_1023B);
  3199. p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
  3200. p->tx_frames_1519_max = GET_STAT(TX_PORT_1519B_MAX);
  3201. p->tx_drop = GET_STAT(TX_PORT_DROP);
  3202. p->tx_pause = GET_STAT(TX_PORT_PAUSE);
  3203. p->tx_ppp0 = GET_STAT(TX_PORT_PPP0);
  3204. p->tx_ppp1 = GET_STAT(TX_PORT_PPP1);
  3205. p->tx_ppp2 = GET_STAT(TX_PORT_PPP2);
  3206. p->tx_ppp3 = GET_STAT(TX_PORT_PPP3);
  3207. p->tx_ppp4 = GET_STAT(TX_PORT_PPP4);
  3208. p->tx_ppp5 = GET_STAT(TX_PORT_PPP5);
  3209. p->tx_ppp6 = GET_STAT(TX_PORT_PPP6);
  3210. p->tx_ppp7 = GET_STAT(TX_PORT_PPP7);
  3211. p->rx_octets = GET_STAT(RX_PORT_BYTES);
  3212. p->rx_frames = GET_STAT(RX_PORT_FRAMES);
  3213. p->rx_bcast_frames = GET_STAT(RX_PORT_BCAST);
  3214. p->rx_mcast_frames = GET_STAT(RX_PORT_MCAST);
  3215. p->rx_ucast_frames = GET_STAT(RX_PORT_UCAST);
  3216. p->rx_too_long = GET_STAT(RX_PORT_MTU_ERROR);
  3217. p->rx_jabber = GET_STAT(RX_PORT_MTU_CRC_ERROR);
  3218. p->rx_fcs_err = GET_STAT(RX_PORT_CRC_ERROR);
  3219. p->rx_len_err = GET_STAT(RX_PORT_LEN_ERROR);
  3220. p->rx_symbol_err = GET_STAT(RX_PORT_SYM_ERROR);
  3221. p->rx_runt = GET_STAT(RX_PORT_LESS_64B);
  3222. p->rx_frames_64 = GET_STAT(RX_PORT_64B);
  3223. p->rx_frames_65_127 = GET_STAT(RX_PORT_65B_127B);
  3224. p->rx_frames_128_255 = GET_STAT(RX_PORT_128B_255B);
  3225. p->rx_frames_256_511 = GET_STAT(RX_PORT_256B_511B);
  3226. p->rx_frames_512_1023 = GET_STAT(RX_PORT_512B_1023B);
  3227. p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
  3228. p->rx_frames_1519_max = GET_STAT(RX_PORT_1519B_MAX);
  3229. p->rx_pause = GET_STAT(RX_PORT_PAUSE);
  3230. p->rx_ppp0 = GET_STAT(RX_PORT_PPP0);
  3231. p->rx_ppp1 = GET_STAT(RX_PORT_PPP1);
  3232. p->rx_ppp2 = GET_STAT(RX_PORT_PPP2);
  3233. p->rx_ppp3 = GET_STAT(RX_PORT_PPP3);
  3234. p->rx_ppp4 = GET_STAT(RX_PORT_PPP4);
  3235. p->rx_ppp5 = GET_STAT(RX_PORT_PPP5);
  3236. p->rx_ppp6 = GET_STAT(RX_PORT_PPP6);
  3237. p->rx_ppp7 = GET_STAT(RX_PORT_PPP7);
  3238. p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
  3239. p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
  3240. p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
  3241. p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
  3242. p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
  3243. p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
  3244. p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
  3245. p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
  3246. #undef GET_STAT
  3247. #undef GET_STAT_COM
  3248. }
  3249. /**
  3250. * t4_wol_magic_enable - enable/disable magic packet WoL
  3251. * @adap: the adapter
  3252. * @port: the physical port index
  3253. * @addr: MAC address expected in magic packets, %NULL to disable
  3254. *
  3255. * Enables/disables magic packet wake-on-LAN for the selected port.
  3256. */
  3257. void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
  3258. const u8 *addr)
  3259. {
  3260. u32 mag_id_reg_l, mag_id_reg_h, port_cfg_reg;
  3261. if (is_t4(adap->params.chip)) {
  3262. mag_id_reg_l = PORT_REG(port, XGMAC_PORT_MAGIC_MACID_LO);
  3263. mag_id_reg_h = PORT_REG(port, XGMAC_PORT_MAGIC_MACID_HI);
  3264. port_cfg_reg = PORT_REG(port, XGMAC_PORT_CFG2_A);
  3265. } else {
  3266. mag_id_reg_l = T5_PORT_REG(port, MAC_PORT_MAGIC_MACID_LO);
  3267. mag_id_reg_h = T5_PORT_REG(port, MAC_PORT_MAGIC_MACID_HI);
  3268. port_cfg_reg = T5_PORT_REG(port, MAC_PORT_CFG2_A);
  3269. }
  3270. if (addr) {
  3271. t4_write_reg(adap, mag_id_reg_l,
  3272. (addr[2] << 24) | (addr[3] << 16) |
  3273. (addr[4] << 8) | addr[5]);
  3274. t4_write_reg(adap, mag_id_reg_h,
  3275. (addr[0] << 8) | addr[1]);
  3276. }
  3277. t4_set_reg_field(adap, port_cfg_reg, MAGICEN_F,
  3278. addr ? MAGICEN_F : 0);
  3279. }
  3280. /**
  3281. * t4_wol_pat_enable - enable/disable pattern-based WoL
  3282. * @adap: the adapter
  3283. * @port: the physical port index
  3284. * @map: bitmap of which HW pattern filters to set
  3285. * @mask0: byte mask for bytes 0-63 of a packet
  3286. * @mask1: byte mask for bytes 64-127 of a packet
  3287. * @crc: Ethernet CRC for selected bytes
  3288. * @enable: enable/disable switch
  3289. *
  3290. * Sets the pattern filters indicated in @map to mask out the bytes
  3291. * specified in @mask0/@mask1 in received packets and compare the CRC of
  3292. * the resulting packet against @crc. If @enable is %true pattern-based
  3293. * WoL is enabled, otherwise disabled.
  3294. */
  3295. int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
  3296. u64 mask0, u64 mask1, unsigned int crc, bool enable)
  3297. {
  3298. int i;
  3299. u32 port_cfg_reg;
  3300. if (is_t4(adap->params.chip))
  3301. port_cfg_reg = PORT_REG(port, XGMAC_PORT_CFG2_A);
  3302. else
  3303. port_cfg_reg = T5_PORT_REG(port, MAC_PORT_CFG2_A);
  3304. if (!enable) {
  3305. t4_set_reg_field(adap, port_cfg_reg, PATEN_F, 0);
  3306. return 0;
  3307. }
  3308. if (map > 0xff)
  3309. return -EINVAL;
  3310. #define EPIO_REG(name) \
  3311. (is_t4(adap->params.chip) ? \
  3312. PORT_REG(port, XGMAC_PORT_EPIO_##name##_A) : \
  3313. T5_PORT_REG(port, MAC_PORT_EPIO_##name##_A))
  3314. t4_write_reg(adap, EPIO_REG(DATA1), mask0 >> 32);
  3315. t4_write_reg(adap, EPIO_REG(DATA2), mask1);
  3316. t4_write_reg(adap, EPIO_REG(DATA3), mask1 >> 32);
  3317. for (i = 0; i < NWOL_PAT; i++, map >>= 1) {
  3318. if (!(map & 1))
  3319. continue;
  3320. /* write byte masks */
  3321. t4_write_reg(adap, EPIO_REG(DATA0), mask0);
  3322. t4_write_reg(adap, EPIO_REG(OP), ADDRESS_V(i) | EPIOWR_F);
  3323. t4_read_reg(adap, EPIO_REG(OP)); /* flush */
  3324. if (t4_read_reg(adap, EPIO_REG(OP)) & SF_BUSY_F)
  3325. return -ETIMEDOUT;
  3326. /* write CRC */
  3327. t4_write_reg(adap, EPIO_REG(DATA0), crc);
  3328. t4_write_reg(adap, EPIO_REG(OP), ADDRESS_V(i + 32) | EPIOWR_F);
  3329. t4_read_reg(adap, EPIO_REG(OP)); /* flush */
  3330. if (t4_read_reg(adap, EPIO_REG(OP)) & SF_BUSY_F)
  3331. return -ETIMEDOUT;
  3332. }
  3333. #undef EPIO_REG
  3334. t4_set_reg_field(adap, PORT_REG(port, XGMAC_PORT_CFG2_A), 0, PATEN_F);
  3335. return 0;
  3336. }
  3337. /* t4_mk_filtdelwr - create a delete filter WR
  3338. * @ftid: the filter ID
  3339. * @wr: the filter work request to populate
  3340. * @qid: ingress queue to receive the delete notification
  3341. *
  3342. * Creates a filter work request to delete the supplied filter. If @qid is
  3343. * negative the delete notification is suppressed.
  3344. */
  3345. void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
  3346. {
  3347. memset(wr, 0, sizeof(*wr));
  3348. wr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER_WR));
  3349. wr->len16_pkd = htonl(FW_WR_LEN16_V(sizeof(*wr) / 16));
  3350. wr->tid_to_iq = htonl(FW_FILTER_WR_TID_V(ftid) |
  3351. FW_FILTER_WR_NOREPLY_V(qid < 0));
  3352. wr->del_filter_to_l2tix = htonl(FW_FILTER_WR_DEL_FILTER_F);
  3353. if (qid >= 0)
  3354. wr->rx_chan_rx_rpl_iq = htons(FW_FILTER_WR_RX_RPL_IQ_V(qid));
  3355. }
  3356. #define INIT_CMD(var, cmd, rd_wr) do { \
  3357. (var).op_to_write = htonl(FW_CMD_OP_V(FW_##cmd##_CMD) | \
  3358. FW_CMD_REQUEST_F | FW_CMD_##rd_wr##_F); \
  3359. (var).retval_len16 = htonl(FW_LEN16(var)); \
  3360. } while (0)
  3361. int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
  3362. u32 addr, u32 val)
  3363. {
  3364. struct fw_ldst_cmd c;
  3365. memset(&c, 0, sizeof(c));
  3366. c.op_to_addrspace = htonl(FW_CMD_OP_V(FW_LDST_CMD) | FW_CMD_REQUEST_F |
  3367. FW_CMD_WRITE_F |
  3368. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FIRMWARE));
  3369. c.cycles_to_len16 = htonl(FW_LEN16(c));
  3370. c.u.addrval.addr = htonl(addr);
  3371. c.u.addrval.val = htonl(val);
  3372. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3373. }
  3374. /**
  3375. * t4_mdio_rd - read a PHY register through MDIO
  3376. * @adap: the adapter
  3377. * @mbox: mailbox to use for the FW command
  3378. * @phy_addr: the PHY address
  3379. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  3380. * @reg: the register to read
  3381. * @valp: where to store the value
  3382. *
  3383. * Issues a FW command through the given mailbox to read a PHY register.
  3384. */
  3385. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  3386. unsigned int mmd, unsigned int reg, u16 *valp)
  3387. {
  3388. int ret;
  3389. struct fw_ldst_cmd c;
  3390. memset(&c, 0, sizeof(c));
  3391. c.op_to_addrspace = htonl(FW_CMD_OP_V(FW_LDST_CMD) | FW_CMD_REQUEST_F |
  3392. FW_CMD_READ_F | FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO));
  3393. c.cycles_to_len16 = htonl(FW_LEN16(c));
  3394. c.u.mdio.paddr_mmd = htons(FW_LDST_CMD_PADDR_V(phy_addr) |
  3395. FW_LDST_CMD_MMD_V(mmd));
  3396. c.u.mdio.raddr = htons(reg);
  3397. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  3398. if (ret == 0)
  3399. *valp = ntohs(c.u.mdio.rval);
  3400. return ret;
  3401. }
  3402. /**
  3403. * t4_mdio_wr - write a PHY register through MDIO
  3404. * @adap: the adapter
  3405. * @mbox: mailbox to use for the FW command
  3406. * @phy_addr: the PHY address
  3407. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  3408. * @reg: the register to write
  3409. * @valp: value to write
  3410. *
  3411. * Issues a FW command through the given mailbox to write a PHY register.
  3412. */
  3413. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  3414. unsigned int mmd, unsigned int reg, u16 val)
  3415. {
  3416. struct fw_ldst_cmd c;
  3417. memset(&c, 0, sizeof(c));
  3418. c.op_to_addrspace = htonl(FW_CMD_OP_V(FW_LDST_CMD) | FW_CMD_REQUEST_F |
  3419. FW_CMD_WRITE_F | FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO));
  3420. c.cycles_to_len16 = htonl(FW_LEN16(c));
  3421. c.u.mdio.paddr_mmd = htons(FW_LDST_CMD_PADDR_V(phy_addr) |
  3422. FW_LDST_CMD_MMD_V(mmd));
  3423. c.u.mdio.raddr = htons(reg);
  3424. c.u.mdio.rval = htons(val);
  3425. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3426. }
  3427. /**
  3428. * t4_sge_decode_idma_state - decode the idma state
  3429. * @adap: the adapter
  3430. * @state: the state idma is stuck in
  3431. */
  3432. void t4_sge_decode_idma_state(struct adapter *adapter, int state)
  3433. {
  3434. static const char * const t4_decode[] = {
  3435. "IDMA_IDLE",
  3436. "IDMA_PUSH_MORE_CPL_FIFO",
  3437. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  3438. "Not used",
  3439. "IDMA_PHYSADDR_SEND_PCIEHDR",
  3440. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  3441. "IDMA_PHYSADDR_SEND_PAYLOAD",
  3442. "IDMA_SEND_FIFO_TO_IMSG",
  3443. "IDMA_FL_REQ_DATA_FL_PREP",
  3444. "IDMA_FL_REQ_DATA_FL",
  3445. "IDMA_FL_DROP",
  3446. "IDMA_FL_H_REQ_HEADER_FL",
  3447. "IDMA_FL_H_SEND_PCIEHDR",
  3448. "IDMA_FL_H_PUSH_CPL_FIFO",
  3449. "IDMA_FL_H_SEND_CPL",
  3450. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  3451. "IDMA_FL_H_SEND_IP_HDR",
  3452. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  3453. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  3454. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  3455. "IDMA_FL_D_SEND_PCIEHDR",
  3456. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  3457. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  3458. "IDMA_FL_SEND_PCIEHDR",
  3459. "IDMA_FL_PUSH_CPL_FIFO",
  3460. "IDMA_FL_SEND_CPL",
  3461. "IDMA_FL_SEND_PAYLOAD_FIRST",
  3462. "IDMA_FL_SEND_PAYLOAD",
  3463. "IDMA_FL_REQ_NEXT_DATA_FL",
  3464. "IDMA_FL_SEND_NEXT_PCIEHDR",
  3465. "IDMA_FL_SEND_PADDING",
  3466. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  3467. "IDMA_FL_SEND_FIFO_TO_IMSG",
  3468. "IDMA_FL_REQ_DATAFL_DONE",
  3469. "IDMA_FL_REQ_HEADERFL_DONE",
  3470. };
  3471. static const char * const t5_decode[] = {
  3472. "IDMA_IDLE",
  3473. "IDMA_ALMOST_IDLE",
  3474. "IDMA_PUSH_MORE_CPL_FIFO",
  3475. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  3476. "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
  3477. "IDMA_PHYSADDR_SEND_PCIEHDR",
  3478. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  3479. "IDMA_PHYSADDR_SEND_PAYLOAD",
  3480. "IDMA_SEND_FIFO_TO_IMSG",
  3481. "IDMA_FL_REQ_DATA_FL",
  3482. "IDMA_FL_DROP",
  3483. "IDMA_FL_DROP_SEND_INC",
  3484. "IDMA_FL_H_REQ_HEADER_FL",
  3485. "IDMA_FL_H_SEND_PCIEHDR",
  3486. "IDMA_FL_H_PUSH_CPL_FIFO",
  3487. "IDMA_FL_H_SEND_CPL",
  3488. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  3489. "IDMA_FL_H_SEND_IP_HDR",
  3490. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  3491. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  3492. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  3493. "IDMA_FL_D_SEND_PCIEHDR",
  3494. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  3495. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  3496. "IDMA_FL_SEND_PCIEHDR",
  3497. "IDMA_FL_PUSH_CPL_FIFO",
  3498. "IDMA_FL_SEND_CPL",
  3499. "IDMA_FL_SEND_PAYLOAD_FIRST",
  3500. "IDMA_FL_SEND_PAYLOAD",
  3501. "IDMA_FL_REQ_NEXT_DATA_FL",
  3502. "IDMA_FL_SEND_NEXT_PCIEHDR",
  3503. "IDMA_FL_SEND_PADDING",
  3504. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  3505. };
  3506. static const u32 sge_regs[] = {
  3507. SGE_DEBUG_DATA_LOW_INDEX_2_A,
  3508. SGE_DEBUG_DATA_LOW_INDEX_3_A,
  3509. SGE_DEBUG_DATA_HIGH_INDEX_10_A,
  3510. };
  3511. const char **sge_idma_decode;
  3512. int sge_idma_decode_nstates;
  3513. int i;
  3514. if (is_t4(adapter->params.chip)) {
  3515. sge_idma_decode = (const char **)t4_decode;
  3516. sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
  3517. } else {
  3518. sge_idma_decode = (const char **)t5_decode;
  3519. sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
  3520. }
  3521. if (state < sge_idma_decode_nstates)
  3522. CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
  3523. else
  3524. CH_WARN(adapter, "idma state %d unknown\n", state);
  3525. for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
  3526. CH_WARN(adapter, "SGE register %#x value %#x\n",
  3527. sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
  3528. }
  3529. /**
  3530. * t4_fw_hello - establish communication with FW
  3531. * @adap: the adapter
  3532. * @mbox: mailbox to use for the FW command
  3533. * @evt_mbox: mailbox to receive async FW events
  3534. * @master: specifies the caller's willingness to be the device master
  3535. * @state: returns the current device state (if non-NULL)
  3536. *
  3537. * Issues a command to establish communication with FW. Returns either
  3538. * an error (negative integer) or the mailbox of the Master PF.
  3539. */
  3540. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  3541. enum dev_master master, enum dev_state *state)
  3542. {
  3543. int ret;
  3544. struct fw_hello_cmd c;
  3545. u32 v;
  3546. unsigned int master_mbox;
  3547. int retries = FW_CMD_HELLO_RETRIES;
  3548. retry:
  3549. memset(&c, 0, sizeof(c));
  3550. INIT_CMD(c, HELLO, WRITE);
  3551. c.err_to_clearinit = htonl(
  3552. FW_HELLO_CMD_MASTERDIS_V(master == MASTER_CANT) |
  3553. FW_HELLO_CMD_MASTERFORCE_V(master == MASTER_MUST) |
  3554. FW_HELLO_CMD_MBMASTER_V(master == MASTER_MUST ? mbox :
  3555. FW_HELLO_CMD_MBMASTER_M) |
  3556. FW_HELLO_CMD_MBASYNCNOT_V(evt_mbox) |
  3557. FW_HELLO_CMD_STAGE_V(fw_hello_cmd_stage_os) |
  3558. FW_HELLO_CMD_CLEARINIT_F);
  3559. /*
  3560. * Issue the HELLO command to the firmware. If it's not successful
  3561. * but indicates that we got a "busy" or "timeout" condition, retry
  3562. * the HELLO until we exhaust our retry limit. If we do exceed our
  3563. * retry limit, check to see if the firmware left us any error
  3564. * information and report that if so.
  3565. */
  3566. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  3567. if (ret < 0) {
  3568. if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
  3569. goto retry;
  3570. if (t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_ERR_F)
  3571. t4_report_fw_error(adap);
  3572. return ret;
  3573. }
  3574. v = ntohl(c.err_to_clearinit);
  3575. master_mbox = FW_HELLO_CMD_MBMASTER_G(v);
  3576. if (state) {
  3577. if (v & FW_HELLO_CMD_ERR_F)
  3578. *state = DEV_STATE_ERR;
  3579. else if (v & FW_HELLO_CMD_INIT_F)
  3580. *state = DEV_STATE_INIT;
  3581. else
  3582. *state = DEV_STATE_UNINIT;
  3583. }
  3584. /*
  3585. * If we're not the Master PF then we need to wait around for the
  3586. * Master PF Driver to finish setting up the adapter.
  3587. *
  3588. * Note that we also do this wait if we're a non-Master-capable PF and
  3589. * there is no current Master PF; a Master PF may show up momentarily
  3590. * and we wouldn't want to fail pointlessly. (This can happen when an
  3591. * OS loads lots of different drivers rapidly at the same time). In
  3592. * this case, the Master PF returned by the firmware will be
  3593. * PCIE_FW_MASTER_M so the test below will work ...
  3594. */
  3595. if ((v & (FW_HELLO_CMD_ERR_F|FW_HELLO_CMD_INIT_F)) == 0 &&
  3596. master_mbox != mbox) {
  3597. int waiting = FW_CMD_HELLO_TIMEOUT;
  3598. /*
  3599. * Wait for the firmware to either indicate an error or
  3600. * initialized state. If we see either of these we bail out
  3601. * and report the issue to the caller. If we exhaust the
  3602. * "hello timeout" and we haven't exhausted our retries, try
  3603. * again. Otherwise bail with a timeout error.
  3604. */
  3605. for (;;) {
  3606. u32 pcie_fw;
  3607. msleep(50);
  3608. waiting -= 50;
  3609. /*
  3610. * If neither Error nor Initialialized are indicated
  3611. * by the firmware keep waiting till we exaust our
  3612. * timeout ... and then retry if we haven't exhausted
  3613. * our retries ...
  3614. */
  3615. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  3616. if (!(pcie_fw & (PCIE_FW_ERR_F|PCIE_FW_INIT_F))) {
  3617. if (waiting <= 0) {
  3618. if (retries-- > 0)
  3619. goto retry;
  3620. return -ETIMEDOUT;
  3621. }
  3622. continue;
  3623. }
  3624. /*
  3625. * We either have an Error or Initialized condition
  3626. * report errors preferentially.
  3627. */
  3628. if (state) {
  3629. if (pcie_fw & PCIE_FW_ERR_F)
  3630. *state = DEV_STATE_ERR;
  3631. else if (pcie_fw & PCIE_FW_INIT_F)
  3632. *state = DEV_STATE_INIT;
  3633. }
  3634. /*
  3635. * If we arrived before a Master PF was selected and
  3636. * there's not a valid Master PF, grab its identity
  3637. * for our caller.
  3638. */
  3639. if (master_mbox == PCIE_FW_MASTER_M &&
  3640. (pcie_fw & PCIE_FW_MASTER_VLD_F))
  3641. master_mbox = PCIE_FW_MASTER_G(pcie_fw);
  3642. break;
  3643. }
  3644. }
  3645. return master_mbox;
  3646. }
  3647. /**
  3648. * t4_fw_bye - end communication with FW
  3649. * @adap: the adapter
  3650. * @mbox: mailbox to use for the FW command
  3651. *
  3652. * Issues a command to terminate communication with FW.
  3653. */
  3654. int t4_fw_bye(struct adapter *adap, unsigned int mbox)
  3655. {
  3656. struct fw_bye_cmd c;
  3657. memset(&c, 0, sizeof(c));
  3658. INIT_CMD(c, BYE, WRITE);
  3659. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3660. }
  3661. /**
  3662. * t4_init_cmd - ask FW to initialize the device
  3663. * @adap: the adapter
  3664. * @mbox: mailbox to use for the FW command
  3665. *
  3666. * Issues a command to FW to partially initialize the device. This
  3667. * performs initialization that generally doesn't depend on user input.
  3668. */
  3669. int t4_early_init(struct adapter *adap, unsigned int mbox)
  3670. {
  3671. struct fw_initialize_cmd c;
  3672. memset(&c, 0, sizeof(c));
  3673. INIT_CMD(c, INITIALIZE, WRITE);
  3674. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3675. }
  3676. /**
  3677. * t4_fw_reset - issue a reset to FW
  3678. * @adap: the adapter
  3679. * @mbox: mailbox to use for the FW command
  3680. * @reset: specifies the type of reset to perform
  3681. *
  3682. * Issues a reset command of the specified type to FW.
  3683. */
  3684. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
  3685. {
  3686. struct fw_reset_cmd c;
  3687. memset(&c, 0, sizeof(c));
  3688. INIT_CMD(c, RESET, WRITE);
  3689. c.val = htonl(reset);
  3690. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3691. }
  3692. /**
  3693. * t4_fw_halt - issue a reset/halt to FW and put uP into RESET
  3694. * @adap: the adapter
  3695. * @mbox: mailbox to use for the FW RESET command (if desired)
  3696. * @force: force uP into RESET even if FW RESET command fails
  3697. *
  3698. * Issues a RESET command to firmware (if desired) with a HALT indication
  3699. * and then puts the microprocessor into RESET state. The RESET command
  3700. * will only be issued if a legitimate mailbox is provided (mbox <=
  3701. * PCIE_FW_MASTER_M).
  3702. *
  3703. * This is generally used in order for the host to safely manipulate the
  3704. * adapter without fear of conflicting with whatever the firmware might
  3705. * be doing. The only way out of this state is to RESTART the firmware
  3706. * ...
  3707. */
  3708. static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
  3709. {
  3710. int ret = 0;
  3711. /*
  3712. * If a legitimate mailbox is provided, issue a RESET command
  3713. * with a HALT indication.
  3714. */
  3715. if (mbox <= PCIE_FW_MASTER_M) {
  3716. struct fw_reset_cmd c;
  3717. memset(&c, 0, sizeof(c));
  3718. INIT_CMD(c, RESET, WRITE);
  3719. c.val = htonl(PIORST_F | PIORSTMODE_F);
  3720. c.halt_pkd = htonl(FW_RESET_CMD_HALT_F);
  3721. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3722. }
  3723. /*
  3724. * Normally we won't complete the operation if the firmware RESET
  3725. * command fails but if our caller insists we'll go ahead and put the
  3726. * uP into RESET. This can be useful if the firmware is hung or even
  3727. * missing ... We'll have to take the risk of putting the uP into
  3728. * RESET without the cooperation of firmware in that case.
  3729. *
  3730. * We also force the firmware's HALT flag to be on in case we bypassed
  3731. * the firmware RESET command above or we're dealing with old firmware
  3732. * which doesn't have the HALT capability. This will serve as a flag
  3733. * for the incoming firmware to know that it's coming out of a HALT
  3734. * rather than a RESET ... if it's new enough to understand that ...
  3735. */
  3736. if (ret == 0 || force) {
  3737. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, UPCRST_F);
  3738. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F,
  3739. PCIE_FW_HALT_F);
  3740. }
  3741. /*
  3742. * And we always return the result of the firmware RESET command
  3743. * even when we force the uP into RESET ...
  3744. */
  3745. return ret;
  3746. }
  3747. /**
  3748. * t4_fw_restart - restart the firmware by taking the uP out of RESET
  3749. * @adap: the adapter
  3750. * @reset: if we want to do a RESET to restart things
  3751. *
  3752. * Restart firmware previously halted by t4_fw_halt(). On successful
  3753. * return the previous PF Master remains as the new PF Master and there
  3754. * is no need to issue a new HELLO command, etc.
  3755. *
  3756. * We do this in two ways:
  3757. *
  3758. * 1. If we're dealing with newer firmware we'll simply want to take
  3759. * the chip's microprocessor out of RESET. This will cause the
  3760. * firmware to start up from its start vector. And then we'll loop
  3761. * until the firmware indicates it's started again (PCIE_FW.HALT
  3762. * reset to 0) or we timeout.
  3763. *
  3764. * 2. If we're dealing with older firmware then we'll need to RESET
  3765. * the chip since older firmware won't recognize the PCIE_FW.HALT
  3766. * flag and automatically RESET itself on startup.
  3767. */
  3768. static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
  3769. {
  3770. if (reset) {
  3771. /*
  3772. * Since we're directing the RESET instead of the firmware
  3773. * doing it automatically, we need to clear the PCIE_FW.HALT
  3774. * bit.
  3775. */
  3776. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F, 0);
  3777. /*
  3778. * If we've been given a valid mailbox, first try to get the
  3779. * firmware to do the RESET. If that works, great and we can
  3780. * return success. Otherwise, if we haven't been given a
  3781. * valid mailbox or the RESET command failed, fall back to
  3782. * hitting the chip with a hammer.
  3783. */
  3784. if (mbox <= PCIE_FW_MASTER_M) {
  3785. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  3786. msleep(100);
  3787. if (t4_fw_reset(adap, mbox,
  3788. PIORST_F | PIORSTMODE_F) == 0)
  3789. return 0;
  3790. }
  3791. t4_write_reg(adap, PL_RST_A, PIORST_F | PIORSTMODE_F);
  3792. msleep(2000);
  3793. } else {
  3794. int ms;
  3795. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  3796. for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
  3797. if (!(t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_HALT_F))
  3798. return 0;
  3799. msleep(100);
  3800. ms += 100;
  3801. }
  3802. return -ETIMEDOUT;
  3803. }
  3804. return 0;
  3805. }
  3806. /**
  3807. * t4_fw_upgrade - perform all of the steps necessary to upgrade FW
  3808. * @adap: the adapter
  3809. * @mbox: mailbox to use for the FW RESET command (if desired)
  3810. * @fw_data: the firmware image to write
  3811. * @size: image size
  3812. * @force: force upgrade even if firmware doesn't cooperate
  3813. *
  3814. * Perform all of the steps necessary for upgrading an adapter's
  3815. * firmware image. Normally this requires the cooperation of the
  3816. * existing firmware in order to halt all existing activities
  3817. * but if an invalid mailbox token is passed in we skip that step
  3818. * (though we'll still put the adapter microprocessor into RESET in
  3819. * that case).
  3820. *
  3821. * On successful return the new firmware will have been loaded and
  3822. * the adapter will have been fully RESET losing all previous setup
  3823. * state. On unsuccessful return the adapter may be completely hosed ...
  3824. * positive errno indicates that the adapter is ~probably~ intact, a
  3825. * negative errno indicates that things are looking bad ...
  3826. */
  3827. int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
  3828. const u8 *fw_data, unsigned int size, int force)
  3829. {
  3830. const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
  3831. int reset, ret;
  3832. if (!t4_fw_matches_chip(adap, fw_hdr))
  3833. return -EINVAL;
  3834. ret = t4_fw_halt(adap, mbox, force);
  3835. if (ret < 0 && !force)
  3836. return ret;
  3837. ret = t4_load_fw(adap, fw_data, size);
  3838. if (ret < 0)
  3839. return ret;
  3840. /*
  3841. * Older versions of the firmware don't understand the new
  3842. * PCIE_FW.HALT flag and so won't know to perform a RESET when they
  3843. * restart. So for newly loaded older firmware we'll have to do the
  3844. * RESET for it so it starts up on a clean slate. We can tell if
  3845. * the newly loaded firmware will handle this right by checking
  3846. * its header flags to see if it advertises the capability.
  3847. */
  3848. reset = ((ntohl(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
  3849. return t4_fw_restart(adap, mbox, reset);
  3850. }
  3851. /**
  3852. * t4_fixup_host_params - fix up host-dependent parameters
  3853. * @adap: the adapter
  3854. * @page_size: the host's Base Page Size
  3855. * @cache_line_size: the host's Cache Line Size
  3856. *
  3857. * Various registers in T4 contain values which are dependent on the
  3858. * host's Base Page and Cache Line Sizes. This function will fix all of
  3859. * those registers with the appropriate values as passed in ...
  3860. */
  3861. int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
  3862. unsigned int cache_line_size)
  3863. {
  3864. unsigned int page_shift = fls(page_size) - 1;
  3865. unsigned int sge_hps = page_shift - 10;
  3866. unsigned int stat_len = cache_line_size > 64 ? 128 : 64;
  3867. unsigned int fl_align = cache_line_size < 32 ? 32 : cache_line_size;
  3868. unsigned int fl_align_log = fls(fl_align) - 1;
  3869. t4_write_reg(adap, SGE_HOST_PAGE_SIZE_A,
  3870. HOSTPAGESIZEPF0_V(sge_hps) |
  3871. HOSTPAGESIZEPF1_V(sge_hps) |
  3872. HOSTPAGESIZEPF2_V(sge_hps) |
  3873. HOSTPAGESIZEPF3_V(sge_hps) |
  3874. HOSTPAGESIZEPF4_V(sge_hps) |
  3875. HOSTPAGESIZEPF5_V(sge_hps) |
  3876. HOSTPAGESIZEPF6_V(sge_hps) |
  3877. HOSTPAGESIZEPF7_V(sge_hps));
  3878. if (is_t4(adap->params.chip)) {
  3879. t4_set_reg_field(adap, SGE_CONTROL_A,
  3880. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  3881. EGRSTATUSPAGESIZE_F,
  3882. INGPADBOUNDARY_V(fl_align_log -
  3883. INGPADBOUNDARY_SHIFT_X) |
  3884. EGRSTATUSPAGESIZE_V(stat_len != 64));
  3885. } else {
  3886. /* T5 introduced the separation of the Free List Padding and
  3887. * Packing Boundaries. Thus, we can select a smaller Padding
  3888. * Boundary to avoid uselessly chewing up PCIe Link and Memory
  3889. * Bandwidth, and use a Packing Boundary which is large enough
  3890. * to avoid false sharing between CPUs, etc.
  3891. *
  3892. * For the PCI Link, the smaller the Padding Boundary the
  3893. * better. For the Memory Controller, a smaller Padding
  3894. * Boundary is better until we cross under the Memory Line
  3895. * Size (the minimum unit of transfer to/from Memory). If we
  3896. * have a Padding Boundary which is smaller than the Memory
  3897. * Line Size, that'll involve a Read-Modify-Write cycle on the
  3898. * Memory Controller which is never good. For T5 the smallest
  3899. * Padding Boundary which we can select is 32 bytes which is
  3900. * larger than any known Memory Controller Line Size so we'll
  3901. * use that.
  3902. *
  3903. * T5 has a different interpretation of the "0" value for the
  3904. * Packing Boundary. This corresponds to 16 bytes instead of
  3905. * the expected 32 bytes. We never have a Packing Boundary
  3906. * less than 32 bytes so we can't use that special value but
  3907. * on the other hand, if we wanted 32 bytes, the best we can
  3908. * really do is 64 bytes.
  3909. */
  3910. if (fl_align <= 32) {
  3911. fl_align = 64;
  3912. fl_align_log = 6;
  3913. }
  3914. t4_set_reg_field(adap, SGE_CONTROL_A,
  3915. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  3916. EGRSTATUSPAGESIZE_F,
  3917. INGPADBOUNDARY_V(INGPCIEBOUNDARY_32B_X) |
  3918. EGRSTATUSPAGESIZE_V(stat_len != 64));
  3919. t4_set_reg_field(adap, SGE_CONTROL2_A,
  3920. INGPACKBOUNDARY_V(INGPACKBOUNDARY_M),
  3921. INGPACKBOUNDARY_V(fl_align_log -
  3922. INGPACKBOUNDARY_SHIFT_X));
  3923. }
  3924. /*
  3925. * Adjust various SGE Free List Host Buffer Sizes.
  3926. *
  3927. * This is something of a crock since we're using fixed indices into
  3928. * the array which are also known by the sge.c code and the T4
  3929. * Firmware Configuration File. We need to come up with a much better
  3930. * approach to managing this array. For now, the first four entries
  3931. * are:
  3932. *
  3933. * 0: Host Page Size
  3934. * 1: 64KB
  3935. * 2: Buffer size corresponding to 1500 byte MTU (unpacked mode)
  3936. * 3: Buffer size corresponding to 9000 byte MTU (unpacked mode)
  3937. *
  3938. * For the single-MTU buffers in unpacked mode we need to include
  3939. * space for the SGE Control Packet Shift, 14 byte Ethernet header,
  3940. * possible 4 byte VLAN tag, all rounded up to the next Ingress Packet
  3941. * Padding boundary. All of these are accommodated in the Factory
  3942. * Default Firmware Configuration File but we need to adjust it for
  3943. * this host's cache line size.
  3944. */
  3945. t4_write_reg(adap, SGE_FL_BUFFER_SIZE0_A, page_size);
  3946. t4_write_reg(adap, SGE_FL_BUFFER_SIZE2_A,
  3947. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE2_A) + fl_align-1)
  3948. & ~(fl_align-1));
  3949. t4_write_reg(adap, SGE_FL_BUFFER_SIZE3_A,
  3950. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE3_A) + fl_align-1)
  3951. & ~(fl_align-1));
  3952. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(page_shift - 12));
  3953. return 0;
  3954. }
  3955. /**
  3956. * t4_fw_initialize - ask FW to initialize the device
  3957. * @adap: the adapter
  3958. * @mbox: mailbox to use for the FW command
  3959. *
  3960. * Issues a command to FW to partially initialize the device. This
  3961. * performs initialization that generally doesn't depend on user input.
  3962. */
  3963. int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
  3964. {
  3965. struct fw_initialize_cmd c;
  3966. memset(&c, 0, sizeof(c));
  3967. INIT_CMD(c, INITIALIZE, WRITE);
  3968. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3969. }
  3970. /**
  3971. * t4_query_params - query FW or device parameters
  3972. * @adap: the adapter
  3973. * @mbox: mailbox to use for the FW command
  3974. * @pf: the PF
  3975. * @vf: the VF
  3976. * @nparams: the number of parameters
  3977. * @params: the parameter names
  3978. * @val: the parameter values
  3979. *
  3980. * Reads the value of FW or device parameters. Up to 7 parameters can be
  3981. * queried at once.
  3982. */
  3983. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  3984. unsigned int vf, unsigned int nparams, const u32 *params,
  3985. u32 *val)
  3986. {
  3987. int i, ret;
  3988. struct fw_params_cmd c;
  3989. __be32 *p = &c.param[0].mnem;
  3990. if (nparams > 7)
  3991. return -EINVAL;
  3992. memset(&c, 0, sizeof(c));
  3993. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_PARAMS_CMD) | FW_CMD_REQUEST_F |
  3994. FW_CMD_READ_F | FW_PARAMS_CMD_PFN_V(pf) |
  3995. FW_PARAMS_CMD_VFN_V(vf));
  3996. c.retval_len16 = htonl(FW_LEN16(c));
  3997. for (i = 0; i < nparams; i++, p += 2)
  3998. *p = htonl(*params++);
  3999. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  4000. if (ret == 0)
  4001. for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
  4002. *val++ = ntohl(*p);
  4003. return ret;
  4004. }
  4005. /**
  4006. * t4_set_params_nosleep - sets FW or device parameters
  4007. * @adap: the adapter
  4008. * @mbox: mailbox to use for the FW command
  4009. * @pf: the PF
  4010. * @vf: the VF
  4011. * @nparams: the number of parameters
  4012. * @params: the parameter names
  4013. * @val: the parameter values
  4014. *
  4015. * Does not ever sleep
  4016. * Sets the value of FW or device parameters. Up to 7 parameters can be
  4017. * specified at once.
  4018. */
  4019. int t4_set_params_nosleep(struct adapter *adap, unsigned int mbox,
  4020. unsigned int pf, unsigned int vf,
  4021. unsigned int nparams, const u32 *params,
  4022. const u32 *val)
  4023. {
  4024. struct fw_params_cmd c;
  4025. __be32 *p = &c.param[0].mnem;
  4026. if (nparams > 7)
  4027. return -EINVAL;
  4028. memset(&c, 0, sizeof(c));
  4029. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  4030. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  4031. FW_PARAMS_CMD_PFN_V(pf) |
  4032. FW_PARAMS_CMD_VFN_V(vf));
  4033. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  4034. while (nparams--) {
  4035. *p++ = cpu_to_be32(*params++);
  4036. *p++ = cpu_to_be32(*val++);
  4037. }
  4038. return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
  4039. }
  4040. /**
  4041. * t4_set_params - sets FW or device parameters
  4042. * @adap: the adapter
  4043. * @mbox: mailbox to use for the FW command
  4044. * @pf: the PF
  4045. * @vf: the VF
  4046. * @nparams: the number of parameters
  4047. * @params: the parameter names
  4048. * @val: the parameter values
  4049. *
  4050. * Sets the value of FW or device parameters. Up to 7 parameters can be
  4051. * specified at once.
  4052. */
  4053. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4054. unsigned int vf, unsigned int nparams, const u32 *params,
  4055. const u32 *val)
  4056. {
  4057. struct fw_params_cmd c;
  4058. __be32 *p = &c.param[0].mnem;
  4059. if (nparams > 7)
  4060. return -EINVAL;
  4061. memset(&c, 0, sizeof(c));
  4062. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_PARAMS_CMD) | FW_CMD_REQUEST_F |
  4063. FW_CMD_WRITE_F | FW_PARAMS_CMD_PFN_V(pf) |
  4064. FW_PARAMS_CMD_VFN_V(vf));
  4065. c.retval_len16 = htonl(FW_LEN16(c));
  4066. while (nparams--) {
  4067. *p++ = htonl(*params++);
  4068. *p++ = htonl(*val++);
  4069. }
  4070. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4071. }
  4072. /**
  4073. * t4_cfg_pfvf - configure PF/VF resource limits
  4074. * @adap: the adapter
  4075. * @mbox: mailbox to use for the FW command
  4076. * @pf: the PF being configured
  4077. * @vf: the VF being configured
  4078. * @txq: the max number of egress queues
  4079. * @txq_eth_ctrl: the max number of egress Ethernet or control queues
  4080. * @rxqi: the max number of interrupt-capable ingress queues
  4081. * @rxq: the max number of interruptless ingress queues
  4082. * @tc: the PCI traffic class
  4083. * @vi: the max number of virtual interfaces
  4084. * @cmask: the channel access rights mask for the PF/VF
  4085. * @pmask: the port access rights mask for the PF/VF
  4086. * @nexact: the maximum number of exact MPS filters
  4087. * @rcaps: read capabilities
  4088. * @wxcaps: write/execute capabilities
  4089. *
  4090. * Configures resource limits and capabilities for a physical or virtual
  4091. * function.
  4092. */
  4093. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4094. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  4095. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  4096. unsigned int vi, unsigned int cmask, unsigned int pmask,
  4097. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
  4098. {
  4099. struct fw_pfvf_cmd c;
  4100. memset(&c, 0, sizeof(c));
  4101. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_PFVF_CMD) | FW_CMD_REQUEST_F |
  4102. FW_CMD_WRITE_F | FW_PFVF_CMD_PFN_V(pf) |
  4103. FW_PFVF_CMD_VFN_V(vf));
  4104. c.retval_len16 = htonl(FW_LEN16(c));
  4105. c.niqflint_niq = htonl(FW_PFVF_CMD_NIQFLINT_V(rxqi) |
  4106. FW_PFVF_CMD_NIQ_V(rxq));
  4107. c.type_to_neq = htonl(FW_PFVF_CMD_CMASK_V(cmask) |
  4108. FW_PFVF_CMD_PMASK_V(pmask) |
  4109. FW_PFVF_CMD_NEQ_V(txq));
  4110. c.tc_to_nexactf = htonl(FW_PFVF_CMD_TC_V(tc) | FW_PFVF_CMD_NVI_V(vi) |
  4111. FW_PFVF_CMD_NEXACTF_V(nexact));
  4112. c.r_caps_to_nethctrl = htonl(FW_PFVF_CMD_R_CAPS_V(rcaps) |
  4113. FW_PFVF_CMD_WX_CAPS_V(wxcaps) |
  4114. FW_PFVF_CMD_NETHCTRL_V(txq_eth_ctrl));
  4115. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4116. }
  4117. /**
  4118. * t4_alloc_vi - allocate a virtual interface
  4119. * @adap: the adapter
  4120. * @mbox: mailbox to use for the FW command
  4121. * @port: physical port associated with the VI
  4122. * @pf: the PF owning the VI
  4123. * @vf: the VF owning the VI
  4124. * @nmac: number of MAC addresses needed (1 to 5)
  4125. * @mac: the MAC addresses of the VI
  4126. * @rss_size: size of RSS table slice associated with this VI
  4127. *
  4128. * Allocates a virtual interface for the given physical port. If @mac is
  4129. * not %NULL it contains the MAC addresses of the VI as assigned by FW.
  4130. * @mac should be large enough to hold @nmac Ethernet addresses, they are
  4131. * stored consecutively so the space needed is @nmac * 6 bytes.
  4132. * Returns a negative error number or the non-negative VI id.
  4133. */
  4134. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  4135. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  4136. unsigned int *rss_size)
  4137. {
  4138. int ret;
  4139. struct fw_vi_cmd c;
  4140. memset(&c, 0, sizeof(c));
  4141. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_VI_CMD) | FW_CMD_REQUEST_F |
  4142. FW_CMD_WRITE_F | FW_CMD_EXEC_F |
  4143. FW_VI_CMD_PFN_V(pf) | FW_VI_CMD_VFN_V(vf));
  4144. c.alloc_to_len16 = htonl(FW_VI_CMD_ALLOC_F | FW_LEN16(c));
  4145. c.portid_pkd = FW_VI_CMD_PORTID_V(port);
  4146. c.nmac = nmac - 1;
  4147. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  4148. if (ret)
  4149. return ret;
  4150. if (mac) {
  4151. memcpy(mac, c.mac, sizeof(c.mac));
  4152. switch (nmac) {
  4153. case 5:
  4154. memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
  4155. case 4:
  4156. memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
  4157. case 3:
  4158. memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
  4159. case 2:
  4160. memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
  4161. }
  4162. }
  4163. if (rss_size)
  4164. *rss_size = FW_VI_CMD_RSSSIZE_G(ntohs(c.rsssize_pkd));
  4165. return FW_VI_CMD_VIID_G(ntohs(c.type_viid));
  4166. }
  4167. /**
  4168. * t4_set_rxmode - set Rx properties of a virtual interface
  4169. * @adap: the adapter
  4170. * @mbox: mailbox to use for the FW command
  4171. * @viid: the VI id
  4172. * @mtu: the new MTU or -1
  4173. * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  4174. * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
  4175. * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
  4176. * @vlanex: 1 to enable HW VLAN extraction, 0 to disable it, -1 no change
  4177. * @sleep_ok: if true we may sleep while awaiting command completion
  4178. *
  4179. * Sets Rx properties of a virtual interface.
  4180. */
  4181. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  4182. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  4183. bool sleep_ok)
  4184. {
  4185. struct fw_vi_rxmode_cmd c;
  4186. /* convert to FW values */
  4187. if (mtu < 0)
  4188. mtu = FW_RXMODE_MTU_NO_CHG;
  4189. if (promisc < 0)
  4190. promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
  4191. if (all_multi < 0)
  4192. all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
  4193. if (bcast < 0)
  4194. bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
  4195. if (vlanex < 0)
  4196. vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
  4197. memset(&c, 0, sizeof(c));
  4198. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_RXMODE_CMD) | FW_CMD_REQUEST_F |
  4199. FW_CMD_WRITE_F | FW_VI_RXMODE_CMD_VIID_V(viid));
  4200. c.retval_len16 = htonl(FW_LEN16(c));
  4201. c.mtu_to_vlanexen = htonl(FW_VI_RXMODE_CMD_MTU_V(mtu) |
  4202. FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
  4203. FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
  4204. FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
  4205. FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
  4206. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  4207. }
  4208. /**
  4209. * t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
  4210. * @adap: the adapter
  4211. * @mbox: mailbox to use for the FW command
  4212. * @viid: the VI id
  4213. * @free: if true any existing filters for this VI id are first removed
  4214. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  4215. * @addr: the MAC address(es)
  4216. * @idx: where to store the index of each allocated filter
  4217. * @hash: pointer to hash address filter bitmap
  4218. * @sleep_ok: call is allowed to sleep
  4219. *
  4220. * Allocates an exact-match filter for each of the supplied addresses and
  4221. * sets it to the corresponding address. If @idx is not %NULL it should
  4222. * have at least @naddr entries, each of which will be set to the index of
  4223. * the filter allocated for the corresponding MAC address. If a filter
  4224. * could not be allocated for an address its index is set to 0xffff.
  4225. * If @hash is not %NULL addresses that fail to allocate an exact filter
  4226. * are hashed and update the hash filter bitmap pointed at by @hash.
  4227. *
  4228. * Returns a negative error number or the number of filters allocated.
  4229. */
  4230. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  4231. unsigned int viid, bool free, unsigned int naddr,
  4232. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
  4233. {
  4234. int i, ret;
  4235. struct fw_vi_mac_cmd c;
  4236. struct fw_vi_mac_exact *p;
  4237. unsigned int max_naddr = is_t4(adap->params.chip) ?
  4238. NUM_MPS_CLS_SRAM_L_INSTANCES :
  4239. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  4240. if (naddr > 7)
  4241. return -EINVAL;
  4242. memset(&c, 0, sizeof(c));
  4243. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
  4244. FW_CMD_WRITE_F | (free ? FW_CMD_EXEC_F : 0) |
  4245. FW_VI_MAC_CMD_VIID_V(viid));
  4246. c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_FREEMACS_V(free) |
  4247. FW_CMD_LEN16_V((naddr + 2) / 2));
  4248. for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
  4249. p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID_F |
  4250. FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_ADD_MAC));
  4251. memcpy(p->macaddr, addr[i], sizeof(p->macaddr));
  4252. }
  4253. ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
  4254. if (ret)
  4255. return ret;
  4256. for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
  4257. u16 index = FW_VI_MAC_CMD_IDX_G(ntohs(p->valid_to_idx));
  4258. if (idx)
  4259. idx[i] = index >= max_naddr ? 0xffff : index;
  4260. if (index < max_naddr)
  4261. ret++;
  4262. else if (hash)
  4263. *hash |= (1ULL << hash_mac_addr(addr[i]));
  4264. }
  4265. return ret;
  4266. }
  4267. /**
  4268. * t4_change_mac - modifies the exact-match filter for a MAC address
  4269. * @adap: the adapter
  4270. * @mbox: mailbox to use for the FW command
  4271. * @viid: the VI id
  4272. * @idx: index of existing filter for old value of MAC address, or -1
  4273. * @addr: the new MAC address value
  4274. * @persist: whether a new MAC allocation should be persistent
  4275. * @add_smt: if true also add the address to the HW SMT
  4276. *
  4277. * Modifies an exact-match filter and sets it to the new MAC address.
  4278. * Note that in general it is not possible to modify the value of a given
  4279. * filter so the generic way to modify an address filter is to free the one
  4280. * being used by the old address value and allocate a new filter for the
  4281. * new address value. @idx can be -1 if the address is a new addition.
  4282. *
  4283. * Returns a negative error number or the index of the filter with the new
  4284. * MAC value.
  4285. */
  4286. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  4287. int idx, const u8 *addr, bool persist, bool add_smt)
  4288. {
  4289. int ret, mode;
  4290. struct fw_vi_mac_cmd c;
  4291. struct fw_vi_mac_exact *p = c.u.exact;
  4292. unsigned int max_mac_addr = is_t4(adap->params.chip) ?
  4293. NUM_MPS_CLS_SRAM_L_INSTANCES :
  4294. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  4295. if (idx < 0) /* new allocation */
  4296. idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
  4297. mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
  4298. memset(&c, 0, sizeof(c));
  4299. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
  4300. FW_CMD_WRITE_F | FW_VI_MAC_CMD_VIID_V(viid));
  4301. c.freemacs_to_len16 = htonl(FW_CMD_LEN16_V(1));
  4302. p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID_F |
  4303. FW_VI_MAC_CMD_SMAC_RESULT_V(mode) |
  4304. FW_VI_MAC_CMD_IDX_V(idx));
  4305. memcpy(p->macaddr, addr, sizeof(p->macaddr));
  4306. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  4307. if (ret == 0) {
  4308. ret = FW_VI_MAC_CMD_IDX_G(ntohs(p->valid_to_idx));
  4309. if (ret >= max_mac_addr)
  4310. ret = -ENOMEM;
  4311. }
  4312. return ret;
  4313. }
  4314. /**
  4315. * t4_set_addr_hash - program the MAC inexact-match hash filter
  4316. * @adap: the adapter
  4317. * @mbox: mailbox to use for the FW command
  4318. * @viid: the VI id
  4319. * @ucast: whether the hash filter should also match unicast addresses
  4320. * @vec: the value to be written to the hash filter
  4321. * @sleep_ok: call is allowed to sleep
  4322. *
  4323. * Sets the 64-bit inexact-match hash filter for a virtual interface.
  4324. */
  4325. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  4326. bool ucast, u64 vec, bool sleep_ok)
  4327. {
  4328. struct fw_vi_mac_cmd c;
  4329. memset(&c, 0, sizeof(c));
  4330. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
  4331. FW_CMD_WRITE_F | FW_VI_ENABLE_CMD_VIID_V(viid));
  4332. c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_HASHVECEN_F |
  4333. FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
  4334. FW_CMD_LEN16_V(1));
  4335. c.u.hash.hashvec = cpu_to_be64(vec);
  4336. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  4337. }
  4338. /**
  4339. * t4_enable_vi_params - enable/disable a virtual interface
  4340. * @adap: the adapter
  4341. * @mbox: mailbox to use for the FW command
  4342. * @viid: the VI id
  4343. * @rx_en: 1=enable Rx, 0=disable Rx
  4344. * @tx_en: 1=enable Tx, 0=disable Tx
  4345. * @dcb_en: 1=enable delivery of Data Center Bridging messages.
  4346. *
  4347. * Enables/disables a virtual interface. Note that setting DCB Enable
  4348. * only makes sense when enabling a Virtual Interface ...
  4349. */
  4350. int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
  4351. unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
  4352. {
  4353. struct fw_vi_enable_cmd c;
  4354. memset(&c, 0, sizeof(c));
  4355. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST_F |
  4356. FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID_V(viid));
  4357. c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
  4358. FW_VI_ENABLE_CMD_EEN_V(tx_en) | FW_LEN16(c) |
  4359. FW_VI_ENABLE_CMD_DCB_INFO_V(dcb_en));
  4360. return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
  4361. }
  4362. /**
  4363. * t4_enable_vi - enable/disable a virtual interface
  4364. * @adap: the adapter
  4365. * @mbox: mailbox to use for the FW command
  4366. * @viid: the VI id
  4367. * @rx_en: 1=enable Rx, 0=disable Rx
  4368. * @tx_en: 1=enable Tx, 0=disable Tx
  4369. *
  4370. * Enables/disables a virtual interface.
  4371. */
  4372. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  4373. bool rx_en, bool tx_en)
  4374. {
  4375. return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
  4376. }
  4377. /**
  4378. * t4_identify_port - identify a VI's port by blinking its LED
  4379. * @adap: the adapter
  4380. * @mbox: mailbox to use for the FW command
  4381. * @viid: the VI id
  4382. * @nblinks: how many times to blink LED at 2.5 Hz
  4383. *
  4384. * Identifies a VI's port by blinking its LED.
  4385. */
  4386. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  4387. unsigned int nblinks)
  4388. {
  4389. struct fw_vi_enable_cmd c;
  4390. memset(&c, 0, sizeof(c));
  4391. c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST_F |
  4392. FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID_V(viid));
  4393. c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_LED_F | FW_LEN16(c));
  4394. c.blinkdur = htons(nblinks);
  4395. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4396. }
  4397. /**
  4398. * t4_iq_free - free an ingress queue and its FLs
  4399. * @adap: the adapter
  4400. * @mbox: mailbox to use for the FW command
  4401. * @pf: the PF owning the queues
  4402. * @vf: the VF owning the queues
  4403. * @iqtype: the ingress queue type
  4404. * @iqid: ingress queue id
  4405. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  4406. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  4407. *
  4408. * Frees an ingress queue and its associated FLs, if any.
  4409. */
  4410. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4411. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  4412. unsigned int fl0id, unsigned int fl1id)
  4413. {
  4414. struct fw_iq_cmd c;
  4415. memset(&c, 0, sizeof(c));
  4416. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
  4417. FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
  4418. FW_IQ_CMD_VFN_V(vf));
  4419. c.alloc_to_len16 = htonl(FW_IQ_CMD_FREE_F | FW_LEN16(c));
  4420. c.type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE_V(iqtype));
  4421. c.iqid = htons(iqid);
  4422. c.fl0id = htons(fl0id);
  4423. c.fl1id = htons(fl1id);
  4424. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4425. }
  4426. /**
  4427. * t4_eth_eq_free - free an Ethernet egress queue
  4428. * @adap: the adapter
  4429. * @mbox: mailbox to use for the FW command
  4430. * @pf: the PF owning the queue
  4431. * @vf: the VF owning the queue
  4432. * @eqid: egress queue id
  4433. *
  4434. * Frees an Ethernet egress queue.
  4435. */
  4436. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4437. unsigned int vf, unsigned int eqid)
  4438. {
  4439. struct fw_eq_eth_cmd c;
  4440. memset(&c, 0, sizeof(c));
  4441. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_ETH_CMD) | FW_CMD_REQUEST_F |
  4442. FW_CMD_EXEC_F | FW_EQ_ETH_CMD_PFN_V(pf) |
  4443. FW_EQ_ETH_CMD_VFN_V(vf));
  4444. c.alloc_to_len16 = htonl(FW_EQ_ETH_CMD_FREE_F | FW_LEN16(c));
  4445. c.eqid_pkd = htonl(FW_EQ_ETH_CMD_EQID_V(eqid));
  4446. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4447. }
  4448. /**
  4449. * t4_ctrl_eq_free - free a control egress queue
  4450. * @adap: the adapter
  4451. * @mbox: mailbox to use for the FW command
  4452. * @pf: the PF owning the queue
  4453. * @vf: the VF owning the queue
  4454. * @eqid: egress queue id
  4455. *
  4456. * Frees a control egress queue.
  4457. */
  4458. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4459. unsigned int vf, unsigned int eqid)
  4460. {
  4461. struct fw_eq_ctrl_cmd c;
  4462. memset(&c, 0, sizeof(c));
  4463. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_CTRL_CMD) | FW_CMD_REQUEST_F |
  4464. FW_CMD_EXEC_F | FW_EQ_CTRL_CMD_PFN_V(pf) |
  4465. FW_EQ_CTRL_CMD_VFN_V(vf));
  4466. c.alloc_to_len16 = htonl(FW_EQ_CTRL_CMD_FREE_F | FW_LEN16(c));
  4467. c.cmpliqid_eqid = htonl(FW_EQ_CTRL_CMD_EQID_V(eqid));
  4468. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4469. }
  4470. /**
  4471. * t4_ofld_eq_free - free an offload egress queue
  4472. * @adap: the adapter
  4473. * @mbox: mailbox to use for the FW command
  4474. * @pf: the PF owning the queue
  4475. * @vf: the VF owning the queue
  4476. * @eqid: egress queue id
  4477. *
  4478. * Frees a control egress queue.
  4479. */
  4480. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  4481. unsigned int vf, unsigned int eqid)
  4482. {
  4483. struct fw_eq_ofld_cmd c;
  4484. memset(&c, 0, sizeof(c));
  4485. c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) | FW_CMD_REQUEST_F |
  4486. FW_CMD_EXEC_F | FW_EQ_OFLD_CMD_PFN_V(pf) |
  4487. FW_EQ_OFLD_CMD_VFN_V(vf));
  4488. c.alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE_F | FW_LEN16(c));
  4489. c.eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID_V(eqid));
  4490. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  4491. }
  4492. /**
  4493. * t4_handle_fw_rpl - process a FW reply message
  4494. * @adap: the adapter
  4495. * @rpl: start of the FW message
  4496. *
  4497. * Processes a FW message, such as link state change messages.
  4498. */
  4499. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
  4500. {
  4501. u8 opcode = *(const u8 *)rpl;
  4502. if (opcode == FW_PORT_CMD) { /* link/module state change message */
  4503. int speed = 0, fc = 0;
  4504. const struct fw_port_cmd *p = (void *)rpl;
  4505. int chan = FW_PORT_CMD_PORTID_G(ntohl(p->op_to_portid));
  4506. int port = adap->chan_map[chan];
  4507. struct port_info *pi = adap2pinfo(adap, port);
  4508. struct link_config *lc = &pi->link_cfg;
  4509. u32 stat = ntohl(p->u.info.lstatus_to_modtype);
  4510. int link_ok = (stat & FW_PORT_CMD_LSTATUS_F) != 0;
  4511. u32 mod = FW_PORT_CMD_MODTYPE_G(stat);
  4512. if (stat & FW_PORT_CMD_RXPAUSE_F)
  4513. fc |= PAUSE_RX;
  4514. if (stat & FW_PORT_CMD_TXPAUSE_F)
  4515. fc |= PAUSE_TX;
  4516. if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
  4517. speed = 100;
  4518. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
  4519. speed = 1000;
  4520. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
  4521. speed = 10000;
  4522. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
  4523. speed = 40000;
  4524. if (link_ok != lc->link_ok || speed != lc->speed ||
  4525. fc != lc->fc) { /* something changed */
  4526. lc->link_ok = link_ok;
  4527. lc->speed = speed;
  4528. lc->fc = fc;
  4529. lc->supported = be16_to_cpu(p->u.info.pcap);
  4530. t4_os_link_changed(adap, port, link_ok);
  4531. }
  4532. if (mod != pi->mod_type) {
  4533. pi->mod_type = mod;
  4534. t4_os_portmod_changed(adap, port);
  4535. }
  4536. }
  4537. return 0;
  4538. }
  4539. static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
  4540. {
  4541. u16 val;
  4542. if (pci_is_pcie(adapter->pdev)) {
  4543. pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
  4544. p->speed = val & PCI_EXP_LNKSTA_CLS;
  4545. p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
  4546. }
  4547. }
  4548. /**
  4549. * init_link_config - initialize a link's SW state
  4550. * @lc: structure holding the link state
  4551. * @caps: link capabilities
  4552. *
  4553. * Initializes the SW state maintained for each link, including the link's
  4554. * capabilities and default speed/flow-control/autonegotiation settings.
  4555. */
  4556. static void init_link_config(struct link_config *lc, unsigned int caps)
  4557. {
  4558. lc->supported = caps;
  4559. lc->requested_speed = 0;
  4560. lc->speed = 0;
  4561. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  4562. if (lc->supported & FW_PORT_CAP_ANEG) {
  4563. lc->advertising = lc->supported & ADVERT_MASK;
  4564. lc->autoneg = AUTONEG_ENABLE;
  4565. lc->requested_fc |= PAUSE_AUTONEG;
  4566. } else {
  4567. lc->advertising = 0;
  4568. lc->autoneg = AUTONEG_DISABLE;
  4569. }
  4570. }
  4571. #define CIM_PF_NOACCESS 0xeeeeeeee
  4572. int t4_wait_dev_ready(void __iomem *regs)
  4573. {
  4574. u32 whoami;
  4575. whoami = readl(regs + PL_WHOAMI_A);
  4576. if (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS)
  4577. return 0;
  4578. msleep(500);
  4579. whoami = readl(regs + PL_WHOAMI_A);
  4580. return (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS ? 0 : -EIO);
  4581. }
  4582. struct flash_desc {
  4583. u32 vendor_and_model_id;
  4584. u32 size_mb;
  4585. };
  4586. static int get_flash_params(struct adapter *adap)
  4587. {
  4588. /* Table for non-Numonix supported flash parts. Numonix parts are left
  4589. * to the preexisting code. All flash parts have 64KB sectors.
  4590. */
  4591. static struct flash_desc supported_flash[] = {
  4592. { 0x150201, 4 << 20 }, /* Spansion 4MB S25FL032P */
  4593. };
  4594. int ret;
  4595. u32 info;
  4596. ret = sf1_write(adap, 1, 1, 0, SF_RD_ID);
  4597. if (!ret)
  4598. ret = sf1_read(adap, 3, 0, 1, &info);
  4599. t4_write_reg(adap, SF_OP_A, 0); /* unlock SF */
  4600. if (ret)
  4601. return ret;
  4602. for (ret = 0; ret < ARRAY_SIZE(supported_flash); ++ret)
  4603. if (supported_flash[ret].vendor_and_model_id == info) {
  4604. adap->params.sf_size = supported_flash[ret].size_mb;
  4605. adap->params.sf_nsec =
  4606. adap->params.sf_size / SF_SEC_SIZE;
  4607. return 0;
  4608. }
  4609. if ((info & 0xff) != 0x20) /* not a Numonix flash */
  4610. return -EINVAL;
  4611. info >>= 16; /* log2 of size */
  4612. if (info >= 0x14 && info < 0x18)
  4613. adap->params.sf_nsec = 1 << (info - 16);
  4614. else if (info == 0x18)
  4615. adap->params.sf_nsec = 64;
  4616. else
  4617. return -EINVAL;
  4618. adap->params.sf_size = 1 << info;
  4619. adap->params.sf_fw_start =
  4620. t4_read_reg(adap, CIM_BOOT_CFG_A) & BOOTADDR_M;
  4621. if (adap->params.sf_size < FLASH_MIN_SIZE)
  4622. dev_warn(adap->pdev_dev, "WARNING!!! FLASH size %#x < %#x!!!\n",
  4623. adap->params.sf_size, FLASH_MIN_SIZE);
  4624. return 0;
  4625. }
  4626. /**
  4627. * t4_prep_adapter - prepare SW and HW for operation
  4628. * @adapter: the adapter
  4629. * @reset: if true perform a HW reset
  4630. *
  4631. * Initialize adapter SW state for the various HW modules, set initial
  4632. * values for some adapter tunables, take PHYs out of reset, and
  4633. * initialize the MDIO interface.
  4634. */
  4635. int t4_prep_adapter(struct adapter *adapter)
  4636. {
  4637. int ret, ver;
  4638. uint16_t device_id;
  4639. u32 pl_rev;
  4640. get_pci_mode(adapter, &adapter->params.pci);
  4641. pl_rev = REV_G(t4_read_reg(adapter, PL_REV_A));
  4642. ret = get_flash_params(adapter);
  4643. if (ret < 0) {
  4644. dev_err(adapter->pdev_dev, "error %d identifying flash\n", ret);
  4645. return ret;
  4646. }
  4647. /* Retrieve adapter's device ID
  4648. */
  4649. pci_read_config_word(adapter->pdev, PCI_DEVICE_ID, &device_id);
  4650. ver = device_id >> 12;
  4651. adapter->params.chip = 0;
  4652. switch (ver) {
  4653. case CHELSIO_T4:
  4654. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  4655. break;
  4656. case CHELSIO_T5:
  4657. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  4658. break;
  4659. default:
  4660. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  4661. device_id);
  4662. return -EINVAL;
  4663. }
  4664. adapter->params.cim_la_size = CIMLA_SIZE;
  4665. init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
  4666. /*
  4667. * Default port for debugging in case we can't reach FW.
  4668. */
  4669. adapter->params.nports = 1;
  4670. adapter->params.portvec = 1;
  4671. adapter->params.vpd.cclk = 50000;
  4672. return 0;
  4673. }
  4674. /**
  4675. * cxgb4_t4_bar2_sge_qregs - return BAR2 SGE Queue register information
  4676. * @adapter: the adapter
  4677. * @qid: the Queue ID
  4678. * @qtype: the Ingress or Egress type for @qid
  4679. * @pbar2_qoffset: BAR2 Queue Offset
  4680. * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
  4681. *
  4682. * Returns the BAR2 SGE Queue Registers information associated with the
  4683. * indicated Absolute Queue ID. These are passed back in return value
  4684. * pointers. @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
  4685. * and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
  4686. *
  4687. * This may return an error which indicates that BAR2 SGE Queue
  4688. * registers aren't available. If an error is not returned, then the
  4689. * following values are returned:
  4690. *
  4691. * *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
  4692. * *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
  4693. *
  4694. * If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
  4695. * require the "Inferred Queue ID" ability may be used. E.g. the
  4696. * Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
  4697. * then these "Inferred Queue ID" register may not be used.
  4698. */
  4699. int cxgb4_t4_bar2_sge_qregs(struct adapter *adapter,
  4700. unsigned int qid,
  4701. enum t4_bar2_qtype qtype,
  4702. u64 *pbar2_qoffset,
  4703. unsigned int *pbar2_qid)
  4704. {
  4705. unsigned int page_shift, page_size, qpp_shift, qpp_mask;
  4706. u64 bar2_page_offset, bar2_qoffset;
  4707. unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
  4708. /* T4 doesn't support BAR2 SGE Queue registers.
  4709. */
  4710. if (is_t4(adapter->params.chip))
  4711. return -EINVAL;
  4712. /* Get our SGE Page Size parameters.
  4713. */
  4714. page_shift = adapter->params.sge.hps + 10;
  4715. page_size = 1 << page_shift;
  4716. /* Get the right Queues per Page parameters for our Queue.
  4717. */
  4718. qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
  4719. ? adapter->params.sge.eq_qpp
  4720. : adapter->params.sge.iq_qpp);
  4721. qpp_mask = (1 << qpp_shift) - 1;
  4722. /* Calculate the basics of the BAR2 SGE Queue register area:
  4723. * o The BAR2 page the Queue registers will be in.
  4724. * o The BAR2 Queue ID.
  4725. * o The BAR2 Queue ID Offset into the BAR2 page.
  4726. */
  4727. bar2_page_offset = ((qid >> qpp_shift) << page_shift);
  4728. bar2_qid = qid & qpp_mask;
  4729. bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
  4730. /* If the BAR2 Queue ID Offset is less than the Page Size, then the
  4731. * hardware will infer the Absolute Queue ID simply from the writes to
  4732. * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
  4733. * BAR2 Queue ID of 0 for those writes). Otherwise, we'll simply
  4734. * write to the first BAR2 SGE Queue Area within the BAR2 Page with
  4735. * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
  4736. * from the BAR2 Page and BAR2 Queue ID.
  4737. *
  4738. * One important censequence of this is that some BAR2 SGE registers
  4739. * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
  4740. * there. But other registers synthesize the SGE Queue ID purely
  4741. * from the writes to the registers -- the Write Combined Doorbell
  4742. * Buffer is a good example. These BAR2 SGE Registers are only
  4743. * available for those BAR2 SGE Register areas where the SGE Absolute
  4744. * Queue ID can be inferred from simple writes.
  4745. */
  4746. bar2_qoffset = bar2_page_offset;
  4747. bar2_qinferred = (bar2_qid_offset < page_size);
  4748. if (bar2_qinferred) {
  4749. bar2_qoffset += bar2_qid_offset;
  4750. bar2_qid = 0;
  4751. }
  4752. *pbar2_qoffset = bar2_qoffset;
  4753. *pbar2_qid = bar2_qid;
  4754. return 0;
  4755. }
  4756. /**
  4757. * t4_init_devlog_params - initialize adapter->params.devlog
  4758. * @adap: the adapter
  4759. *
  4760. * Initialize various fields of the adapter's Firmware Device Log
  4761. * Parameters structure.
  4762. */
  4763. int t4_init_devlog_params(struct adapter *adap)
  4764. {
  4765. struct devlog_params *dparams = &adap->params.devlog;
  4766. u32 pf_dparams;
  4767. unsigned int devlog_meminfo;
  4768. struct fw_devlog_cmd devlog_cmd;
  4769. int ret;
  4770. /* If we're dealing with newer firmware, the Device Log Paramerters
  4771. * are stored in a designated register which allows us to access the
  4772. * Device Log even if we can't talk to the firmware.
  4773. */
  4774. pf_dparams =
  4775. t4_read_reg(adap, PCIE_FW_REG(PCIE_FW_PF_A, PCIE_FW_PF_DEVLOG));
  4776. if (pf_dparams) {
  4777. unsigned int nentries, nentries128;
  4778. dparams->memtype = PCIE_FW_PF_DEVLOG_MEMTYPE_G(pf_dparams);
  4779. dparams->start = PCIE_FW_PF_DEVLOG_ADDR16_G(pf_dparams) << 4;
  4780. nentries128 = PCIE_FW_PF_DEVLOG_NENTRIES128_G(pf_dparams);
  4781. nentries = (nentries128 + 1) * 128;
  4782. dparams->size = nentries * sizeof(struct fw_devlog_e);
  4783. return 0;
  4784. }
  4785. /* Otherwise, ask the firmware for it's Device Log Parameters.
  4786. */
  4787. memset(&devlog_cmd, 0, sizeof(devlog_cmd));
  4788. devlog_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_DEVLOG_CMD) |
  4789. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  4790. devlog_cmd.retval_len16 = htonl(FW_LEN16(devlog_cmd));
  4791. ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
  4792. &devlog_cmd);
  4793. if (ret)
  4794. return ret;
  4795. devlog_meminfo = ntohl(devlog_cmd.memtype_devlog_memaddr16_devlog);
  4796. dparams->memtype = FW_DEVLOG_CMD_MEMTYPE_DEVLOG_G(devlog_meminfo);
  4797. dparams->start = FW_DEVLOG_CMD_MEMADDR16_DEVLOG_G(devlog_meminfo) << 4;
  4798. dparams->size = ntohl(devlog_cmd.memsize_devlog);
  4799. return 0;
  4800. }
  4801. /**
  4802. * t4_init_sge_params - initialize adap->params.sge
  4803. * @adapter: the adapter
  4804. *
  4805. * Initialize various fields of the adapter's SGE Parameters structure.
  4806. */
  4807. int t4_init_sge_params(struct adapter *adapter)
  4808. {
  4809. struct sge_params *sge_params = &adapter->params.sge;
  4810. u32 hps, qpp;
  4811. unsigned int s_hps, s_qpp;
  4812. /* Extract the SGE Page Size for our PF.
  4813. */
  4814. hps = t4_read_reg(adapter, SGE_HOST_PAGE_SIZE_A);
  4815. s_hps = (HOSTPAGESIZEPF0_S +
  4816. (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * adapter->fn);
  4817. sge_params->hps = ((hps >> s_hps) & HOSTPAGESIZEPF0_M);
  4818. /* Extract the SGE Egress and Ingess Queues Per Page for our PF.
  4819. */
  4820. s_qpp = (QUEUESPERPAGEPF0_S +
  4821. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * adapter->fn);
  4822. qpp = t4_read_reg(adapter, SGE_EGRESS_QUEUES_PER_PAGE_PF_A);
  4823. sge_params->eq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  4824. qpp = t4_read_reg(adapter, SGE_INGRESS_QUEUES_PER_PAGE_PF_A);
  4825. sge_params->iq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  4826. return 0;
  4827. }
  4828. /**
  4829. * t4_init_tp_params - initialize adap->params.tp
  4830. * @adap: the adapter
  4831. *
  4832. * Initialize various fields of the adapter's TP Parameters structure.
  4833. */
  4834. int t4_init_tp_params(struct adapter *adap)
  4835. {
  4836. int chan;
  4837. u32 v;
  4838. v = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
  4839. adap->params.tp.tre = TIMERRESOLUTION_G(v);
  4840. adap->params.tp.dack_re = DELAYEDACKRESOLUTION_G(v);
  4841. /* MODQ_REQ_MAP defaults to setting queues 0-3 to chan 0-3 */
  4842. for (chan = 0; chan < NCHAN; chan++)
  4843. adap->params.tp.tx_modq[chan] = chan;
  4844. /* Cache the adapter's Compressed Filter Mode and global Incress
  4845. * Configuration.
  4846. */
  4847. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4848. &adap->params.tp.vlan_pri_map, 1,
  4849. TP_VLAN_PRI_MAP_A);
  4850. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4851. &adap->params.tp.ingress_config, 1,
  4852. TP_INGRESS_CONFIG_A);
  4853. /* Now that we have TP_VLAN_PRI_MAP cached, we can calculate the field
  4854. * shift positions of several elements of the Compressed Filter Tuple
  4855. * for this adapter which we need frequently ...
  4856. */
  4857. adap->params.tp.vlan_shift = t4_filter_field_shift(adap, VLAN_F);
  4858. adap->params.tp.vnic_shift = t4_filter_field_shift(adap, VNIC_ID_F);
  4859. adap->params.tp.port_shift = t4_filter_field_shift(adap, PORT_F);
  4860. adap->params.tp.protocol_shift = t4_filter_field_shift(adap,
  4861. PROTOCOL_F);
  4862. /* If TP_INGRESS_CONFIG.VNID == 0, then TP_VLAN_PRI_MAP.VNIC_ID
  4863. * represents the presence of an Outer VLAN instead of a VNIC ID.
  4864. */
  4865. if ((adap->params.tp.ingress_config & VNIC_F) == 0)
  4866. adap->params.tp.vnic_shift = -1;
  4867. return 0;
  4868. }
  4869. /**
  4870. * t4_filter_field_shift - calculate filter field shift
  4871. * @adap: the adapter
  4872. * @filter_sel: the desired field (from TP_VLAN_PRI_MAP bits)
  4873. *
  4874. * Return the shift position of a filter field within the Compressed
  4875. * Filter Tuple. The filter field is specified via its selection bit
  4876. * within TP_VLAN_PRI_MAL (filter mode). E.g. F_VLAN.
  4877. */
  4878. int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
  4879. {
  4880. unsigned int filter_mode = adap->params.tp.vlan_pri_map;
  4881. unsigned int sel;
  4882. int field_shift;
  4883. if ((filter_mode & filter_sel) == 0)
  4884. return -1;
  4885. for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
  4886. switch (filter_mode & sel) {
  4887. case FCOE_F:
  4888. field_shift += FT_FCOE_W;
  4889. break;
  4890. case PORT_F:
  4891. field_shift += FT_PORT_W;
  4892. break;
  4893. case VNIC_ID_F:
  4894. field_shift += FT_VNIC_ID_W;
  4895. break;
  4896. case VLAN_F:
  4897. field_shift += FT_VLAN_W;
  4898. break;
  4899. case TOS_F:
  4900. field_shift += FT_TOS_W;
  4901. break;
  4902. case PROTOCOL_F:
  4903. field_shift += FT_PROTOCOL_W;
  4904. break;
  4905. case ETHERTYPE_F:
  4906. field_shift += FT_ETHERTYPE_W;
  4907. break;
  4908. case MACMATCH_F:
  4909. field_shift += FT_MACMATCH_W;
  4910. break;
  4911. case MPSHITTYPE_F:
  4912. field_shift += FT_MPSHITTYPE_W;
  4913. break;
  4914. case FRAGMENTATION_F:
  4915. field_shift += FT_FRAGMENTATION_W;
  4916. break;
  4917. }
  4918. }
  4919. return field_shift;
  4920. }
  4921. int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
  4922. {
  4923. u8 addr[6];
  4924. int ret, i, j = 0;
  4925. struct fw_port_cmd c;
  4926. struct fw_rss_vi_config_cmd rvc;
  4927. memset(&c, 0, sizeof(c));
  4928. memset(&rvc, 0, sizeof(rvc));
  4929. for_each_port(adap, i) {
  4930. unsigned int rss_size;
  4931. struct port_info *p = adap2pinfo(adap, i);
  4932. while ((adap->params.portvec & (1 << j)) == 0)
  4933. j++;
  4934. c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) |
  4935. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  4936. FW_PORT_CMD_PORTID_V(j));
  4937. c.action_to_len16 = htonl(
  4938. FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
  4939. FW_LEN16(c));
  4940. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  4941. if (ret)
  4942. return ret;
  4943. ret = t4_alloc_vi(adap, mbox, j, pf, vf, 1, addr, &rss_size);
  4944. if (ret < 0)
  4945. return ret;
  4946. p->viid = ret;
  4947. p->tx_chan = j;
  4948. p->lport = j;
  4949. p->rss_size = rss_size;
  4950. memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
  4951. adap->port[i]->dev_port = j;
  4952. ret = ntohl(c.u.info.lstatus_to_modtype);
  4953. p->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP_F) ?
  4954. FW_PORT_CMD_MDIOADDR_G(ret) : -1;
  4955. p->port_type = FW_PORT_CMD_PTYPE_G(ret);
  4956. p->mod_type = FW_PORT_MOD_TYPE_NA;
  4957. rvc.op_to_viid = htonl(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  4958. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  4959. FW_RSS_VI_CONFIG_CMD_VIID(p->viid));
  4960. rvc.retval_len16 = htonl(FW_LEN16(rvc));
  4961. ret = t4_wr_mbox(adap, mbox, &rvc, sizeof(rvc), &rvc);
  4962. if (ret)
  4963. return ret;
  4964. p->rss_mode = ntohl(rvc.u.basicvirtual.defaultq_to_udpen);
  4965. init_link_config(&p->link_cfg, ntohs(c.u.info.pcap));
  4966. j++;
  4967. }
  4968. return 0;
  4969. }
  4970. /**
  4971. * t4_read_cimq_cfg - read CIM queue configuration
  4972. * @adap: the adapter
  4973. * @base: holds the queue base addresses in bytes
  4974. * @size: holds the queue sizes in bytes
  4975. * @thres: holds the queue full thresholds in bytes
  4976. *
  4977. * Returns the current configuration of the CIM queues, starting with
  4978. * the IBQs, then the OBQs.
  4979. */
  4980. void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres)
  4981. {
  4982. unsigned int i, v;
  4983. int cim_num_obq = is_t4(adap->params.chip) ?
  4984. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  4985. for (i = 0; i < CIM_NUM_IBQ; i++) {
  4986. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, IBQSELECT_F |
  4987. QUENUMSELECT_V(i));
  4988. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  4989. /* value is in 256-byte units */
  4990. *base++ = CIMQBASE_G(v) * 256;
  4991. *size++ = CIMQSIZE_G(v) * 256;
  4992. *thres++ = QUEFULLTHRSH_G(v) * 8; /* 8-byte unit */
  4993. }
  4994. for (i = 0; i < cim_num_obq; i++) {
  4995. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  4996. QUENUMSELECT_V(i));
  4997. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  4998. /* value is in 256-byte units */
  4999. *base++ = CIMQBASE_G(v) * 256;
  5000. *size++ = CIMQSIZE_G(v) * 256;
  5001. }
  5002. }
  5003. /**
  5004. * t4_read_cim_ibq - read the contents of a CIM inbound queue
  5005. * @adap: the adapter
  5006. * @qid: the queue index
  5007. * @data: where to store the queue contents
  5008. * @n: capacity of @data in 32-bit words
  5009. *
  5010. * Reads the contents of the selected CIM queue starting at address 0 up
  5011. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  5012. * error and the number of 32-bit words actually read on success.
  5013. */
  5014. int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  5015. {
  5016. int i, err, attempts;
  5017. unsigned int addr;
  5018. const unsigned int nwords = CIM_IBQ_SIZE * 4;
  5019. if (qid > 5 || (n & 3))
  5020. return -EINVAL;
  5021. addr = qid * nwords;
  5022. if (n > nwords)
  5023. n = nwords;
  5024. /* It might take 3-10ms before the IBQ debug read access is allowed.
  5025. * Wait for 1 Sec with a delay of 1 usec.
  5026. */
  5027. attempts = 1000000;
  5028. for (i = 0; i < n; i++, addr++) {
  5029. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, IBQDBGADDR_V(addr) |
  5030. IBQDBGEN_F);
  5031. err = t4_wait_op_done(adap, CIM_IBQ_DBG_CFG_A, IBQDBGBUSY_F, 0,
  5032. attempts, 1);
  5033. if (err)
  5034. return err;
  5035. *data++ = t4_read_reg(adap, CIM_IBQ_DBG_DATA_A);
  5036. }
  5037. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, 0);
  5038. return i;
  5039. }
  5040. /**
  5041. * t4_read_cim_obq - read the contents of a CIM outbound queue
  5042. * @adap: the adapter
  5043. * @qid: the queue index
  5044. * @data: where to store the queue contents
  5045. * @n: capacity of @data in 32-bit words
  5046. *
  5047. * Reads the contents of the selected CIM queue starting at address 0 up
  5048. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  5049. * error and the number of 32-bit words actually read on success.
  5050. */
  5051. int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  5052. {
  5053. int i, err;
  5054. unsigned int addr, v, nwords;
  5055. int cim_num_obq = is_t4(adap->params.chip) ?
  5056. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  5057. if ((qid > (cim_num_obq - 1)) || (n & 3))
  5058. return -EINVAL;
  5059. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  5060. QUENUMSELECT_V(qid));
  5061. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  5062. addr = CIMQBASE_G(v) * 64; /* muliple of 256 -> muliple of 4 */
  5063. nwords = CIMQSIZE_G(v) * 64; /* same */
  5064. if (n > nwords)
  5065. n = nwords;
  5066. for (i = 0; i < n; i++, addr++) {
  5067. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, OBQDBGADDR_V(addr) |
  5068. OBQDBGEN_F);
  5069. err = t4_wait_op_done(adap, CIM_OBQ_DBG_CFG_A, OBQDBGBUSY_F, 0,
  5070. 2, 1);
  5071. if (err)
  5072. return err;
  5073. *data++ = t4_read_reg(adap, CIM_OBQ_DBG_DATA_A);
  5074. }
  5075. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, 0);
  5076. return i;
  5077. }
  5078. /**
  5079. * t4_cim_read - read a block from CIM internal address space
  5080. * @adap: the adapter
  5081. * @addr: the start address within the CIM address space
  5082. * @n: number of words to read
  5083. * @valp: where to store the result
  5084. *
  5085. * Reads a block of 4-byte words from the CIM intenal address space.
  5086. */
  5087. int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
  5088. unsigned int *valp)
  5089. {
  5090. int ret = 0;
  5091. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  5092. return -EBUSY;
  5093. for ( ; !ret && n--; addr += 4) {
  5094. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr);
  5095. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  5096. 0, 5, 2);
  5097. if (!ret)
  5098. *valp++ = t4_read_reg(adap, CIM_HOST_ACC_DATA_A);
  5099. }
  5100. return ret;
  5101. }
  5102. /**
  5103. * t4_cim_write - write a block into CIM internal address space
  5104. * @adap: the adapter
  5105. * @addr: the start address within the CIM address space
  5106. * @n: number of words to write
  5107. * @valp: set of values to write
  5108. *
  5109. * Writes a block of 4-byte words into the CIM intenal address space.
  5110. */
  5111. int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
  5112. const unsigned int *valp)
  5113. {
  5114. int ret = 0;
  5115. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  5116. return -EBUSY;
  5117. for ( ; !ret && n--; addr += 4) {
  5118. t4_write_reg(adap, CIM_HOST_ACC_DATA_A, *valp++);
  5119. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr | HOSTWRITE_F);
  5120. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  5121. 0, 5, 2);
  5122. }
  5123. return ret;
  5124. }
  5125. static int t4_cim_write1(struct adapter *adap, unsigned int addr,
  5126. unsigned int val)
  5127. {
  5128. return t4_cim_write(adap, addr, 1, &val);
  5129. }
  5130. /**
  5131. * t4_cim_read_la - read CIM LA capture buffer
  5132. * @adap: the adapter
  5133. * @la_buf: where to store the LA data
  5134. * @wrptr: the HW write pointer within the capture buffer
  5135. *
  5136. * Reads the contents of the CIM LA buffer with the most recent entry at
  5137. * the end of the returned data and with the entry at @wrptr first.
  5138. * We try to leave the LA in the running state we find it in.
  5139. */
  5140. int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr)
  5141. {
  5142. int i, ret;
  5143. unsigned int cfg, val, idx;
  5144. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  5145. if (ret)
  5146. return ret;
  5147. if (cfg & UPDBGLAEN_F) { /* LA is running, freeze it */
  5148. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A, 0);
  5149. if (ret)
  5150. return ret;
  5151. }
  5152. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  5153. if (ret)
  5154. goto restart;
  5155. idx = UPDBGLAWRPTR_G(val);
  5156. if (wrptr)
  5157. *wrptr = idx;
  5158. for (i = 0; i < adap->params.cim_la_size; i++) {
  5159. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  5160. UPDBGLARDPTR_V(idx) | UPDBGLARDEN_F);
  5161. if (ret)
  5162. break;
  5163. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  5164. if (ret)
  5165. break;
  5166. if (val & UPDBGLARDEN_F) {
  5167. ret = -ETIMEDOUT;
  5168. break;
  5169. }
  5170. ret = t4_cim_read(adap, UP_UP_DBG_LA_DATA_A, 1, &la_buf[i]);
  5171. if (ret)
  5172. break;
  5173. idx = (idx + 1) & UPDBGLARDPTR_M;
  5174. }
  5175. restart:
  5176. if (cfg & UPDBGLAEN_F) {
  5177. int r = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  5178. cfg & ~UPDBGLARDEN_F);
  5179. if (!ret)
  5180. ret = r;
  5181. }
  5182. return ret;
  5183. }
  5184. /**
  5185. * t4_tp_read_la - read TP LA capture buffer
  5186. * @adap: the adapter
  5187. * @la_buf: where to store the LA data
  5188. * @wrptr: the HW write pointer within the capture buffer
  5189. *
  5190. * Reads the contents of the TP LA buffer with the most recent entry at
  5191. * the end of the returned data and with the entry at @wrptr first.
  5192. * We leave the LA in the running state we find it in.
  5193. */
  5194. void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
  5195. {
  5196. bool last_incomplete;
  5197. unsigned int i, cfg, val, idx;
  5198. cfg = t4_read_reg(adap, TP_DBG_LA_CONFIG_A) & 0xffff;
  5199. if (cfg & DBGLAENABLE_F) /* freeze LA */
  5200. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  5201. adap->params.tp.la_mask | (cfg ^ DBGLAENABLE_F));
  5202. val = t4_read_reg(adap, TP_DBG_LA_CONFIG_A);
  5203. idx = DBGLAWPTR_G(val);
  5204. last_incomplete = DBGLAMODE_G(val) >= 2 && (val & DBGLAWHLF_F) == 0;
  5205. if (last_incomplete)
  5206. idx = (idx + 1) & DBGLARPTR_M;
  5207. if (wrptr)
  5208. *wrptr = idx;
  5209. val &= 0xffff;
  5210. val &= ~DBGLARPTR_V(DBGLARPTR_M);
  5211. val |= adap->params.tp.la_mask;
  5212. for (i = 0; i < TPLA_SIZE; i++) {
  5213. t4_write_reg(adap, TP_DBG_LA_CONFIG_A, DBGLARPTR_V(idx) | val);
  5214. la_buf[i] = t4_read_reg64(adap, TP_DBG_LA_DATAL_A);
  5215. idx = (idx + 1) & DBGLARPTR_M;
  5216. }
  5217. /* Wipe out last entry if it isn't valid */
  5218. if (last_incomplete)
  5219. la_buf[TPLA_SIZE - 1] = ~0ULL;
  5220. if (cfg & DBGLAENABLE_F) /* restore running state */
  5221. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  5222. cfg | adap->params.tp.la_mask);
  5223. }