felix_vsc9959.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756
  1. // SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. /* Copyright 2017 Microsemi Corporation
  3. * Copyright 2018-2019 NXP
  4. */
  5. #include <linux/fsl/enetc_mdio.h>
  6. #include <soc/mscc/ocelot_qsys.h>
  7. #include <soc/mscc/ocelot_vcap.h>
  8. #include <soc/mscc/ocelot_ana.h>
  9. #include <soc/mscc/ocelot_dev.h>
  10. #include <soc/mscc/ocelot_ptp.h>
  11. #include <soc/mscc/ocelot_sys.h>
  12. #include <net/tc_act/tc_gate.h>
  13. #include <soc/mscc/ocelot.h>
  14. #include <linux/dsa/ocelot.h>
  15. #include <linux/pcs-lynx.h>
  16. #include <net/pkt_sched.h>
  17. #include <linux/iopoll.h>
  18. #include <linux/mdio.h>
  19. #include <linux/of.h>
  20. #include <linux/pci.h>
  21. #include <linux/time.h>
  22. #include "felix.h"
  23. #define VSC9959_NUM_PORTS 6
  24. #define VSC9959_TAS_GCL_ENTRY_MAX 63
  25. #define VSC9959_TAS_MIN_GATE_LEN_NS 35
  26. #define VSC9959_VCAP_POLICER_BASE 63
  27. #define VSC9959_VCAP_POLICER_MAX 383
  28. #define VSC9959_SWITCH_PCI_BAR 4
  29. #define VSC9959_IMDIO_PCI_BAR 0
  30. #define VSC9959_PORT_MODE_SERDES (OCELOT_PORT_MODE_SGMII | \
  31. OCELOT_PORT_MODE_QSGMII | \
  32. OCELOT_PORT_MODE_1000BASEX | \
  33. OCELOT_PORT_MODE_2500BASEX | \
  34. OCELOT_PORT_MODE_USXGMII)
  35. static const u32 vsc9959_port_modes[VSC9959_NUM_PORTS] = {
  36. VSC9959_PORT_MODE_SERDES,
  37. VSC9959_PORT_MODE_SERDES,
  38. VSC9959_PORT_MODE_SERDES,
  39. VSC9959_PORT_MODE_SERDES,
  40. OCELOT_PORT_MODE_INTERNAL,
  41. OCELOT_PORT_MODE_INTERNAL,
  42. };
  43. static const u32 vsc9959_ana_regmap[] = {
  44. REG(ANA_ADVLEARN, 0x0089a0),
  45. REG(ANA_VLANMASK, 0x0089a4),
  46. REG_RESERVED(ANA_PORT_B_DOMAIN),
  47. REG(ANA_ANAGEFIL, 0x0089ac),
  48. REG(ANA_ANEVENTS, 0x0089b0),
  49. REG(ANA_STORMLIMIT_BURST, 0x0089b4),
  50. REG(ANA_STORMLIMIT_CFG, 0x0089b8),
  51. REG(ANA_ISOLATED_PORTS, 0x0089c8),
  52. REG(ANA_COMMUNITY_PORTS, 0x0089cc),
  53. REG(ANA_AUTOAGE, 0x0089d0),
  54. REG(ANA_MACTOPTIONS, 0x0089d4),
  55. REG(ANA_LEARNDISC, 0x0089d8),
  56. REG(ANA_AGENCTRL, 0x0089dc),
  57. REG(ANA_MIRRORPORTS, 0x0089e0),
  58. REG(ANA_EMIRRORPORTS, 0x0089e4),
  59. REG(ANA_FLOODING, 0x0089e8),
  60. REG(ANA_FLOODING_IPMC, 0x008a08),
  61. REG(ANA_SFLOW_CFG, 0x008a0c),
  62. REG(ANA_PORT_MODE, 0x008a28),
  63. REG(ANA_CUT_THRU_CFG, 0x008a48),
  64. REG(ANA_PGID_PGID, 0x008400),
  65. REG(ANA_TABLES_ANMOVED, 0x007f1c),
  66. REG(ANA_TABLES_MACHDATA, 0x007f20),
  67. REG(ANA_TABLES_MACLDATA, 0x007f24),
  68. REG(ANA_TABLES_STREAMDATA, 0x007f28),
  69. REG(ANA_TABLES_MACACCESS, 0x007f2c),
  70. REG(ANA_TABLES_MACTINDX, 0x007f30),
  71. REG(ANA_TABLES_VLANACCESS, 0x007f34),
  72. REG(ANA_TABLES_VLANTIDX, 0x007f38),
  73. REG(ANA_TABLES_ISDXACCESS, 0x007f3c),
  74. REG(ANA_TABLES_ISDXTIDX, 0x007f40),
  75. REG(ANA_TABLES_ENTRYLIM, 0x007f00),
  76. REG(ANA_TABLES_PTP_ID_HIGH, 0x007f44),
  77. REG(ANA_TABLES_PTP_ID_LOW, 0x007f48),
  78. REG(ANA_TABLES_STREAMACCESS, 0x007f4c),
  79. REG(ANA_TABLES_STREAMTIDX, 0x007f50),
  80. REG(ANA_TABLES_SEQ_HISTORY, 0x007f54),
  81. REG(ANA_TABLES_SEQ_MASK, 0x007f58),
  82. REG(ANA_TABLES_SFID_MASK, 0x007f5c),
  83. REG(ANA_TABLES_SFIDACCESS, 0x007f60),
  84. REG(ANA_TABLES_SFIDTIDX, 0x007f64),
  85. REG(ANA_MSTI_STATE, 0x008600),
  86. REG(ANA_OAM_UPM_LM_CNT, 0x008000),
  87. REG(ANA_SG_ACCESS_CTRL, 0x008a64),
  88. REG(ANA_SG_CONFIG_REG_1, 0x007fb0),
  89. REG(ANA_SG_CONFIG_REG_2, 0x007fb4),
  90. REG(ANA_SG_CONFIG_REG_3, 0x007fb8),
  91. REG(ANA_SG_CONFIG_REG_4, 0x007fbc),
  92. REG(ANA_SG_CONFIG_REG_5, 0x007fc0),
  93. REG(ANA_SG_GCL_GS_CONFIG, 0x007f80),
  94. REG(ANA_SG_GCL_TI_CONFIG, 0x007f90),
  95. REG(ANA_SG_STATUS_REG_1, 0x008980),
  96. REG(ANA_SG_STATUS_REG_2, 0x008984),
  97. REG(ANA_SG_STATUS_REG_3, 0x008988),
  98. REG(ANA_PORT_VLAN_CFG, 0x007800),
  99. REG(ANA_PORT_DROP_CFG, 0x007804),
  100. REG(ANA_PORT_QOS_CFG, 0x007808),
  101. REG(ANA_PORT_VCAP_CFG, 0x00780c),
  102. REG(ANA_PORT_VCAP_S1_KEY_CFG, 0x007810),
  103. REG(ANA_PORT_VCAP_S2_CFG, 0x00781c),
  104. REG(ANA_PORT_PCP_DEI_MAP, 0x007820),
  105. REG(ANA_PORT_CPU_FWD_CFG, 0x007860),
  106. REG(ANA_PORT_CPU_FWD_BPDU_CFG, 0x007864),
  107. REG(ANA_PORT_CPU_FWD_GARP_CFG, 0x007868),
  108. REG(ANA_PORT_CPU_FWD_CCM_CFG, 0x00786c),
  109. REG(ANA_PORT_PORT_CFG, 0x007870),
  110. REG(ANA_PORT_POL_CFG, 0x007874),
  111. REG(ANA_PORT_PTP_CFG, 0x007878),
  112. REG(ANA_PORT_PTP_DLY1_CFG, 0x00787c),
  113. REG(ANA_PORT_PTP_DLY2_CFG, 0x007880),
  114. REG(ANA_PORT_SFID_CFG, 0x007884),
  115. REG(ANA_PFC_PFC_CFG, 0x008800),
  116. REG_RESERVED(ANA_PFC_PFC_TIMER),
  117. REG_RESERVED(ANA_IPT_OAM_MEP_CFG),
  118. REG_RESERVED(ANA_IPT_IPT),
  119. REG_RESERVED(ANA_PPT_PPT),
  120. REG_RESERVED(ANA_FID_MAP_FID_MAP),
  121. REG(ANA_AGGR_CFG, 0x008a68),
  122. REG(ANA_CPUQ_CFG, 0x008a6c),
  123. REG_RESERVED(ANA_CPUQ_CFG2),
  124. REG(ANA_CPUQ_8021_CFG, 0x008a74),
  125. REG(ANA_DSCP_CFG, 0x008ab4),
  126. REG(ANA_DSCP_REWR_CFG, 0x008bb4),
  127. REG(ANA_VCAP_RNG_TYPE_CFG, 0x008bf4),
  128. REG(ANA_VCAP_RNG_VAL_CFG, 0x008c14),
  129. REG_RESERVED(ANA_VRAP_CFG),
  130. REG_RESERVED(ANA_VRAP_HDR_DATA),
  131. REG_RESERVED(ANA_VRAP_HDR_MASK),
  132. REG(ANA_DISCARD_CFG, 0x008c40),
  133. REG(ANA_FID_CFG, 0x008c44),
  134. REG(ANA_POL_PIR_CFG, 0x004000),
  135. REG(ANA_POL_CIR_CFG, 0x004004),
  136. REG(ANA_POL_MODE_CFG, 0x004008),
  137. REG(ANA_POL_PIR_STATE, 0x00400c),
  138. REG(ANA_POL_CIR_STATE, 0x004010),
  139. REG_RESERVED(ANA_POL_STATE),
  140. REG(ANA_POL_FLOWC, 0x008c48),
  141. REG(ANA_POL_HYST, 0x008cb4),
  142. REG_RESERVED(ANA_POL_MISC_CFG),
  143. };
  144. static const u32 vsc9959_qs_regmap[] = {
  145. REG(QS_XTR_GRP_CFG, 0x000000),
  146. REG(QS_XTR_RD, 0x000008),
  147. REG(QS_XTR_FRM_PRUNING, 0x000010),
  148. REG(QS_XTR_FLUSH, 0x000018),
  149. REG(QS_XTR_DATA_PRESENT, 0x00001c),
  150. REG(QS_XTR_CFG, 0x000020),
  151. REG(QS_INJ_GRP_CFG, 0x000024),
  152. REG(QS_INJ_WR, 0x00002c),
  153. REG(QS_INJ_CTRL, 0x000034),
  154. REG(QS_INJ_STATUS, 0x00003c),
  155. REG(QS_INJ_ERR, 0x000040),
  156. REG_RESERVED(QS_INH_DBG),
  157. };
  158. static const u32 vsc9959_vcap_regmap[] = {
  159. /* VCAP_CORE_CFG */
  160. REG(VCAP_CORE_UPDATE_CTRL, 0x000000),
  161. REG(VCAP_CORE_MV_CFG, 0x000004),
  162. /* VCAP_CORE_CACHE */
  163. REG(VCAP_CACHE_ENTRY_DAT, 0x000008),
  164. REG(VCAP_CACHE_MASK_DAT, 0x000108),
  165. REG(VCAP_CACHE_ACTION_DAT, 0x000208),
  166. REG(VCAP_CACHE_CNT_DAT, 0x000308),
  167. REG(VCAP_CACHE_TG_DAT, 0x000388),
  168. /* VCAP_CONST */
  169. REG(VCAP_CONST_VCAP_VER, 0x000398),
  170. REG(VCAP_CONST_ENTRY_WIDTH, 0x00039c),
  171. REG(VCAP_CONST_ENTRY_CNT, 0x0003a0),
  172. REG(VCAP_CONST_ENTRY_SWCNT, 0x0003a4),
  173. REG(VCAP_CONST_ENTRY_TG_WIDTH, 0x0003a8),
  174. REG(VCAP_CONST_ACTION_DEF_CNT, 0x0003ac),
  175. REG(VCAP_CONST_ACTION_WIDTH, 0x0003b0),
  176. REG(VCAP_CONST_CNT_WIDTH, 0x0003b4),
  177. REG(VCAP_CONST_CORE_CNT, 0x0003b8),
  178. REG(VCAP_CONST_IF_CNT, 0x0003bc),
  179. };
  180. static const u32 vsc9959_qsys_regmap[] = {
  181. REG(QSYS_PORT_MODE, 0x00f460),
  182. REG(QSYS_SWITCH_PORT_MODE, 0x00f480),
  183. REG(QSYS_STAT_CNT_CFG, 0x00f49c),
  184. REG(QSYS_EEE_CFG, 0x00f4a0),
  185. REG(QSYS_EEE_THRES, 0x00f4b8),
  186. REG(QSYS_IGR_NO_SHARING, 0x00f4bc),
  187. REG(QSYS_EGR_NO_SHARING, 0x00f4c0),
  188. REG(QSYS_SW_STATUS, 0x00f4c4),
  189. REG(QSYS_EXT_CPU_CFG, 0x00f4e0),
  190. REG_RESERVED(QSYS_PAD_CFG),
  191. REG(QSYS_CPU_GROUP_MAP, 0x00f4e8),
  192. REG_RESERVED(QSYS_QMAP),
  193. REG_RESERVED(QSYS_ISDX_SGRP),
  194. REG_RESERVED(QSYS_TIMED_FRAME_ENTRY),
  195. REG(QSYS_TFRM_MISC, 0x00f50c),
  196. REG(QSYS_TFRM_PORT_DLY, 0x00f510),
  197. REG(QSYS_TFRM_TIMER_CFG_1, 0x00f514),
  198. REG(QSYS_TFRM_TIMER_CFG_2, 0x00f518),
  199. REG(QSYS_TFRM_TIMER_CFG_3, 0x00f51c),
  200. REG(QSYS_TFRM_TIMER_CFG_4, 0x00f520),
  201. REG(QSYS_TFRM_TIMER_CFG_5, 0x00f524),
  202. REG(QSYS_TFRM_TIMER_CFG_6, 0x00f528),
  203. REG(QSYS_TFRM_TIMER_CFG_7, 0x00f52c),
  204. REG(QSYS_TFRM_TIMER_CFG_8, 0x00f530),
  205. REG(QSYS_RED_PROFILE, 0x00f534),
  206. REG(QSYS_RES_QOS_MODE, 0x00f574),
  207. REG(QSYS_RES_CFG, 0x00c000),
  208. REG(QSYS_RES_STAT, 0x00c004),
  209. REG(QSYS_EGR_DROP_MODE, 0x00f578),
  210. REG(QSYS_EQ_CTRL, 0x00f57c),
  211. REG_RESERVED(QSYS_EVENTS_CORE),
  212. REG(QSYS_QMAXSDU_CFG_0, 0x00f584),
  213. REG(QSYS_QMAXSDU_CFG_1, 0x00f5a0),
  214. REG(QSYS_QMAXSDU_CFG_2, 0x00f5bc),
  215. REG(QSYS_QMAXSDU_CFG_3, 0x00f5d8),
  216. REG(QSYS_QMAXSDU_CFG_4, 0x00f5f4),
  217. REG(QSYS_QMAXSDU_CFG_5, 0x00f610),
  218. REG(QSYS_QMAXSDU_CFG_6, 0x00f62c),
  219. REG(QSYS_QMAXSDU_CFG_7, 0x00f648),
  220. REG(QSYS_PREEMPTION_CFG, 0x00f664),
  221. REG(QSYS_CIR_CFG, 0x000000),
  222. REG(QSYS_EIR_CFG, 0x000004),
  223. REG(QSYS_SE_CFG, 0x000008),
  224. REG(QSYS_SE_DWRR_CFG, 0x00000c),
  225. REG_RESERVED(QSYS_SE_CONNECT),
  226. REG(QSYS_SE_DLB_SENSE, 0x000040),
  227. REG(QSYS_CIR_STATE, 0x000044),
  228. REG(QSYS_EIR_STATE, 0x000048),
  229. REG_RESERVED(QSYS_SE_STATE),
  230. REG(QSYS_HSCH_MISC_CFG, 0x00f67c),
  231. REG(QSYS_TAG_CONFIG, 0x00f680),
  232. REG(QSYS_TAS_PARAM_CFG_CTRL, 0x00f698),
  233. REG(QSYS_PORT_MAX_SDU, 0x00f69c),
  234. REG(QSYS_PARAM_CFG_REG_1, 0x00f440),
  235. REG(QSYS_PARAM_CFG_REG_2, 0x00f444),
  236. REG(QSYS_PARAM_CFG_REG_3, 0x00f448),
  237. REG(QSYS_PARAM_CFG_REG_4, 0x00f44c),
  238. REG(QSYS_PARAM_CFG_REG_5, 0x00f450),
  239. REG(QSYS_GCL_CFG_REG_1, 0x00f454),
  240. REG(QSYS_GCL_CFG_REG_2, 0x00f458),
  241. REG(QSYS_PARAM_STATUS_REG_1, 0x00f400),
  242. REG(QSYS_PARAM_STATUS_REG_2, 0x00f404),
  243. REG(QSYS_PARAM_STATUS_REG_3, 0x00f408),
  244. REG(QSYS_PARAM_STATUS_REG_4, 0x00f40c),
  245. REG(QSYS_PARAM_STATUS_REG_5, 0x00f410),
  246. REG(QSYS_PARAM_STATUS_REG_6, 0x00f414),
  247. REG(QSYS_PARAM_STATUS_REG_7, 0x00f418),
  248. REG(QSYS_PARAM_STATUS_REG_8, 0x00f41c),
  249. REG(QSYS_PARAM_STATUS_REG_9, 0x00f420),
  250. REG(QSYS_GCL_STATUS_REG_1, 0x00f424),
  251. REG(QSYS_GCL_STATUS_REG_2, 0x00f428),
  252. };
  253. static const u32 vsc9959_rew_regmap[] = {
  254. REG(REW_PORT_VLAN_CFG, 0x000000),
  255. REG(REW_TAG_CFG, 0x000004),
  256. REG(REW_PORT_CFG, 0x000008),
  257. REG(REW_DSCP_CFG, 0x00000c),
  258. REG(REW_PCP_DEI_QOS_MAP_CFG, 0x000010),
  259. REG(REW_PTP_CFG, 0x000050),
  260. REG(REW_PTP_DLY1_CFG, 0x000054),
  261. REG(REW_RED_TAG_CFG, 0x000058),
  262. REG(REW_DSCP_REMAP_DP1_CFG, 0x000410),
  263. REG(REW_DSCP_REMAP_CFG, 0x000510),
  264. REG_RESERVED(REW_STAT_CFG),
  265. REG_RESERVED(REW_REW_STICKY),
  266. REG_RESERVED(REW_PPT),
  267. };
  268. static const u32 vsc9959_sys_regmap[] = {
  269. REG(SYS_COUNT_RX_OCTETS, 0x000000),
  270. REG(SYS_COUNT_RX_UNICAST, 0x000004),
  271. REG(SYS_COUNT_RX_MULTICAST, 0x000008),
  272. REG(SYS_COUNT_RX_BROADCAST, 0x00000c),
  273. REG(SYS_COUNT_RX_SHORTS, 0x000010),
  274. REG(SYS_COUNT_RX_FRAGMENTS, 0x000014),
  275. REG(SYS_COUNT_RX_JABBERS, 0x000018),
  276. REG(SYS_COUNT_RX_CRC_ALIGN_ERRS, 0x00001c),
  277. REG(SYS_COUNT_RX_SYM_ERRS, 0x000020),
  278. REG(SYS_COUNT_RX_64, 0x000024),
  279. REG(SYS_COUNT_RX_65_127, 0x000028),
  280. REG(SYS_COUNT_RX_128_255, 0x00002c),
  281. REG(SYS_COUNT_RX_256_511, 0x000030),
  282. REG(SYS_COUNT_RX_512_1023, 0x000034),
  283. REG(SYS_COUNT_RX_1024_1526, 0x000038),
  284. REG(SYS_COUNT_RX_1527_MAX, 0x00003c),
  285. REG(SYS_COUNT_RX_PAUSE, 0x000040),
  286. REG(SYS_COUNT_RX_CONTROL, 0x000044),
  287. REG(SYS_COUNT_RX_LONGS, 0x000048),
  288. REG(SYS_COUNT_RX_CLASSIFIED_DROPS, 0x00004c),
  289. REG(SYS_COUNT_RX_RED_PRIO_0, 0x000050),
  290. REG(SYS_COUNT_RX_RED_PRIO_1, 0x000054),
  291. REG(SYS_COUNT_RX_RED_PRIO_2, 0x000058),
  292. REG(SYS_COUNT_RX_RED_PRIO_3, 0x00005c),
  293. REG(SYS_COUNT_RX_RED_PRIO_4, 0x000060),
  294. REG(SYS_COUNT_RX_RED_PRIO_5, 0x000064),
  295. REG(SYS_COUNT_RX_RED_PRIO_6, 0x000068),
  296. REG(SYS_COUNT_RX_RED_PRIO_7, 0x00006c),
  297. REG(SYS_COUNT_RX_YELLOW_PRIO_0, 0x000070),
  298. REG(SYS_COUNT_RX_YELLOW_PRIO_1, 0x000074),
  299. REG(SYS_COUNT_RX_YELLOW_PRIO_2, 0x000078),
  300. REG(SYS_COUNT_RX_YELLOW_PRIO_3, 0x00007c),
  301. REG(SYS_COUNT_RX_YELLOW_PRIO_4, 0x000080),
  302. REG(SYS_COUNT_RX_YELLOW_PRIO_5, 0x000084),
  303. REG(SYS_COUNT_RX_YELLOW_PRIO_6, 0x000088),
  304. REG(SYS_COUNT_RX_YELLOW_PRIO_7, 0x00008c),
  305. REG(SYS_COUNT_RX_GREEN_PRIO_0, 0x000090),
  306. REG(SYS_COUNT_RX_GREEN_PRIO_1, 0x000094),
  307. REG(SYS_COUNT_RX_GREEN_PRIO_2, 0x000098),
  308. REG(SYS_COUNT_RX_GREEN_PRIO_3, 0x00009c),
  309. REG(SYS_COUNT_RX_GREEN_PRIO_4, 0x0000a0),
  310. REG(SYS_COUNT_RX_GREEN_PRIO_5, 0x0000a4),
  311. REG(SYS_COUNT_RX_GREEN_PRIO_6, 0x0000a8),
  312. REG(SYS_COUNT_RX_GREEN_PRIO_7, 0x0000ac),
  313. REG(SYS_COUNT_RX_ASSEMBLY_ERRS, 0x0000b0),
  314. REG(SYS_COUNT_RX_SMD_ERRS, 0x0000b4),
  315. REG(SYS_COUNT_RX_ASSEMBLY_OK, 0x0000b8),
  316. REG(SYS_COUNT_RX_MERGE_FRAGMENTS, 0x0000bc),
  317. REG(SYS_COUNT_RX_PMAC_OCTETS, 0x0000c0),
  318. REG(SYS_COUNT_RX_PMAC_UNICAST, 0x0000c4),
  319. REG(SYS_COUNT_RX_PMAC_MULTICAST, 0x0000c8),
  320. REG(SYS_COUNT_RX_PMAC_BROADCAST, 0x0000cc),
  321. REG(SYS_COUNT_RX_PMAC_SHORTS, 0x0000d0),
  322. REG(SYS_COUNT_RX_PMAC_FRAGMENTS, 0x0000d4),
  323. REG(SYS_COUNT_RX_PMAC_JABBERS, 0x0000d8),
  324. REG(SYS_COUNT_RX_PMAC_CRC_ALIGN_ERRS, 0x0000dc),
  325. REG(SYS_COUNT_RX_PMAC_SYM_ERRS, 0x0000e0),
  326. REG(SYS_COUNT_RX_PMAC_64, 0x0000e4),
  327. REG(SYS_COUNT_RX_PMAC_65_127, 0x0000e8),
  328. REG(SYS_COUNT_RX_PMAC_128_255, 0x0000ec),
  329. REG(SYS_COUNT_RX_PMAC_256_511, 0x0000f0),
  330. REG(SYS_COUNT_RX_PMAC_512_1023, 0x0000f4),
  331. REG(SYS_COUNT_RX_PMAC_1024_1526, 0x0000f8),
  332. REG(SYS_COUNT_RX_PMAC_1527_MAX, 0x0000fc),
  333. REG(SYS_COUNT_RX_PMAC_PAUSE, 0x000100),
  334. REG(SYS_COUNT_RX_PMAC_CONTROL, 0x000104),
  335. REG(SYS_COUNT_RX_PMAC_LONGS, 0x000108),
  336. REG(SYS_COUNT_TX_OCTETS, 0x000200),
  337. REG(SYS_COUNT_TX_UNICAST, 0x000204),
  338. REG(SYS_COUNT_TX_MULTICAST, 0x000208),
  339. REG(SYS_COUNT_TX_BROADCAST, 0x00020c),
  340. REG(SYS_COUNT_TX_COLLISION, 0x000210),
  341. REG(SYS_COUNT_TX_DROPS, 0x000214),
  342. REG(SYS_COUNT_TX_PAUSE, 0x000218),
  343. REG(SYS_COUNT_TX_64, 0x00021c),
  344. REG(SYS_COUNT_TX_65_127, 0x000220),
  345. REG(SYS_COUNT_TX_128_255, 0x000224),
  346. REG(SYS_COUNT_TX_256_511, 0x000228),
  347. REG(SYS_COUNT_TX_512_1023, 0x00022c),
  348. REG(SYS_COUNT_TX_1024_1526, 0x000230),
  349. REG(SYS_COUNT_TX_1527_MAX, 0x000234),
  350. REG(SYS_COUNT_TX_YELLOW_PRIO_0, 0x000238),
  351. REG(SYS_COUNT_TX_YELLOW_PRIO_1, 0x00023c),
  352. REG(SYS_COUNT_TX_YELLOW_PRIO_2, 0x000240),
  353. REG(SYS_COUNT_TX_YELLOW_PRIO_3, 0x000244),
  354. REG(SYS_COUNT_TX_YELLOW_PRIO_4, 0x000248),
  355. REG(SYS_COUNT_TX_YELLOW_PRIO_5, 0x00024c),
  356. REG(SYS_COUNT_TX_YELLOW_PRIO_6, 0x000250),
  357. REG(SYS_COUNT_TX_YELLOW_PRIO_7, 0x000254),
  358. REG(SYS_COUNT_TX_GREEN_PRIO_0, 0x000258),
  359. REG(SYS_COUNT_TX_GREEN_PRIO_1, 0x00025c),
  360. REG(SYS_COUNT_TX_GREEN_PRIO_2, 0x000260),
  361. REG(SYS_COUNT_TX_GREEN_PRIO_3, 0x000264),
  362. REG(SYS_COUNT_TX_GREEN_PRIO_4, 0x000268),
  363. REG(SYS_COUNT_TX_GREEN_PRIO_5, 0x00026c),
  364. REG(SYS_COUNT_TX_GREEN_PRIO_6, 0x000270),
  365. REG(SYS_COUNT_TX_GREEN_PRIO_7, 0x000274),
  366. REG(SYS_COUNT_TX_AGED, 0x000278),
  367. REG(SYS_COUNT_TX_MM_HOLD, 0x00027c),
  368. REG(SYS_COUNT_TX_MERGE_FRAGMENTS, 0x000280),
  369. REG(SYS_COUNT_TX_PMAC_OCTETS, 0x000284),
  370. REG(SYS_COUNT_TX_PMAC_UNICAST, 0x000288),
  371. REG(SYS_COUNT_TX_PMAC_MULTICAST, 0x00028c),
  372. REG(SYS_COUNT_TX_PMAC_BROADCAST, 0x000290),
  373. REG(SYS_COUNT_TX_PMAC_PAUSE, 0x000294),
  374. REG(SYS_COUNT_TX_PMAC_64, 0x000298),
  375. REG(SYS_COUNT_TX_PMAC_65_127, 0x00029c),
  376. REG(SYS_COUNT_TX_PMAC_128_255, 0x0002a0),
  377. REG(SYS_COUNT_TX_PMAC_256_511, 0x0002a4),
  378. REG(SYS_COUNT_TX_PMAC_512_1023, 0x0002a8),
  379. REG(SYS_COUNT_TX_PMAC_1024_1526, 0x0002ac),
  380. REG(SYS_COUNT_TX_PMAC_1527_MAX, 0x0002b0),
  381. REG(SYS_COUNT_DROP_LOCAL, 0x000400),
  382. REG(SYS_COUNT_DROP_TAIL, 0x000404),
  383. REG(SYS_COUNT_DROP_YELLOW_PRIO_0, 0x000408),
  384. REG(SYS_COUNT_DROP_YELLOW_PRIO_1, 0x00040c),
  385. REG(SYS_COUNT_DROP_YELLOW_PRIO_2, 0x000410),
  386. REG(SYS_COUNT_DROP_YELLOW_PRIO_3, 0x000414),
  387. REG(SYS_COUNT_DROP_YELLOW_PRIO_4, 0x000418),
  388. REG(SYS_COUNT_DROP_YELLOW_PRIO_5, 0x00041c),
  389. REG(SYS_COUNT_DROP_YELLOW_PRIO_6, 0x000420),
  390. REG(SYS_COUNT_DROP_YELLOW_PRIO_7, 0x000424),
  391. REG(SYS_COUNT_DROP_GREEN_PRIO_0, 0x000428),
  392. REG(SYS_COUNT_DROP_GREEN_PRIO_1, 0x00042c),
  393. REG(SYS_COUNT_DROP_GREEN_PRIO_2, 0x000430),
  394. REG(SYS_COUNT_DROP_GREEN_PRIO_3, 0x000434),
  395. REG(SYS_COUNT_DROP_GREEN_PRIO_4, 0x000438),
  396. REG(SYS_COUNT_DROP_GREEN_PRIO_5, 0x00043c),
  397. REG(SYS_COUNT_DROP_GREEN_PRIO_6, 0x000440),
  398. REG(SYS_COUNT_DROP_GREEN_PRIO_7, 0x000444),
  399. REG(SYS_COUNT_SF_MATCHING_FRAMES, 0x000800),
  400. REG(SYS_COUNT_SF_NOT_PASSING_FRAMES, 0x000804),
  401. REG(SYS_COUNT_SF_NOT_PASSING_SDU, 0x000808),
  402. REG(SYS_COUNT_SF_RED_FRAMES, 0x00080c),
  403. REG(SYS_RESET_CFG, 0x000e00),
  404. REG(SYS_SR_ETYPE_CFG, 0x000e04),
  405. REG(SYS_VLAN_ETYPE_CFG, 0x000e08),
  406. REG(SYS_PORT_MODE, 0x000e0c),
  407. REG(SYS_FRONT_PORT_MODE, 0x000e2c),
  408. REG(SYS_FRM_AGING, 0x000e44),
  409. REG(SYS_STAT_CFG, 0x000e48),
  410. REG(SYS_SW_STATUS, 0x000e4c),
  411. REG_RESERVED(SYS_MISC_CFG),
  412. REG(SYS_REW_MAC_HIGH_CFG, 0x000e6c),
  413. REG(SYS_REW_MAC_LOW_CFG, 0x000e84),
  414. REG(SYS_TIMESTAMP_OFFSET, 0x000e9c),
  415. REG(SYS_PAUSE_CFG, 0x000ea0),
  416. REG(SYS_PAUSE_TOT_CFG, 0x000ebc),
  417. REG(SYS_ATOP, 0x000ec0),
  418. REG(SYS_ATOP_TOT_CFG, 0x000edc),
  419. REG(SYS_MAC_FC_CFG, 0x000ee0),
  420. REG(SYS_MMGT, 0x000ef8),
  421. REG_RESERVED(SYS_MMGT_FAST),
  422. REG_RESERVED(SYS_EVENTS_DIF),
  423. REG_RESERVED(SYS_EVENTS_CORE),
  424. REG(SYS_PTP_STATUS, 0x000f14),
  425. REG(SYS_PTP_TXSTAMP, 0x000f18),
  426. REG(SYS_PTP_NXT, 0x000f1c),
  427. REG(SYS_PTP_CFG, 0x000f20),
  428. REG(SYS_RAM_INIT, 0x000f24),
  429. REG_RESERVED(SYS_CM_ADDR),
  430. REG_RESERVED(SYS_CM_DATA_WR),
  431. REG_RESERVED(SYS_CM_DATA_RD),
  432. REG_RESERVED(SYS_CM_OP),
  433. REG_RESERVED(SYS_CM_DATA),
  434. };
  435. static const u32 vsc9959_ptp_regmap[] = {
  436. REG(PTP_PIN_CFG, 0x000000),
  437. REG(PTP_PIN_TOD_SEC_MSB, 0x000004),
  438. REG(PTP_PIN_TOD_SEC_LSB, 0x000008),
  439. REG(PTP_PIN_TOD_NSEC, 0x00000c),
  440. REG(PTP_PIN_WF_HIGH_PERIOD, 0x000014),
  441. REG(PTP_PIN_WF_LOW_PERIOD, 0x000018),
  442. REG(PTP_CFG_MISC, 0x0000a0),
  443. REG(PTP_CLK_CFG_ADJ_CFG, 0x0000a4),
  444. REG(PTP_CLK_CFG_ADJ_FREQ, 0x0000a8),
  445. };
  446. static const u32 vsc9959_gcb_regmap[] = {
  447. REG(GCB_SOFT_RST, 0x000004),
  448. };
  449. static const u32 vsc9959_dev_gmii_regmap[] = {
  450. REG(DEV_CLOCK_CFG, 0x0),
  451. REG(DEV_PORT_MISC, 0x4),
  452. REG(DEV_EVENTS, 0x8),
  453. REG(DEV_EEE_CFG, 0xc),
  454. REG(DEV_RX_PATH_DELAY, 0x10),
  455. REG(DEV_TX_PATH_DELAY, 0x14),
  456. REG(DEV_PTP_PREDICT_CFG, 0x18),
  457. REG(DEV_MAC_ENA_CFG, 0x1c),
  458. REG(DEV_MAC_MODE_CFG, 0x20),
  459. REG(DEV_MAC_MAXLEN_CFG, 0x24),
  460. REG(DEV_MAC_TAGS_CFG, 0x28),
  461. REG(DEV_MAC_ADV_CHK_CFG, 0x2c),
  462. REG(DEV_MAC_IFG_CFG, 0x30),
  463. REG(DEV_MAC_HDX_CFG, 0x34),
  464. REG(DEV_MAC_DBG_CFG, 0x38),
  465. REG(DEV_MAC_FC_MAC_LOW_CFG, 0x3c),
  466. REG(DEV_MAC_FC_MAC_HIGH_CFG, 0x40),
  467. REG(DEV_MAC_STICKY, 0x44),
  468. REG(DEV_MM_ENABLE_CONFIG, 0x48),
  469. REG(DEV_MM_VERIF_CONFIG, 0x4C),
  470. REG(DEV_MM_STATUS, 0x50),
  471. REG_RESERVED(PCS1G_CFG),
  472. REG_RESERVED(PCS1G_MODE_CFG),
  473. REG_RESERVED(PCS1G_SD_CFG),
  474. REG_RESERVED(PCS1G_ANEG_CFG),
  475. REG_RESERVED(PCS1G_ANEG_NP_CFG),
  476. REG_RESERVED(PCS1G_LB_CFG),
  477. REG_RESERVED(PCS1G_DBG_CFG),
  478. REG_RESERVED(PCS1G_CDET_CFG),
  479. REG_RESERVED(PCS1G_ANEG_STATUS),
  480. REG_RESERVED(PCS1G_ANEG_NP_STATUS),
  481. REG_RESERVED(PCS1G_LINK_STATUS),
  482. REG_RESERVED(PCS1G_LINK_DOWN_CNT),
  483. REG_RESERVED(PCS1G_STICKY),
  484. REG_RESERVED(PCS1G_DEBUG_STATUS),
  485. REG_RESERVED(PCS1G_LPI_CFG),
  486. REG_RESERVED(PCS1G_LPI_WAKE_ERROR_CNT),
  487. REG_RESERVED(PCS1G_LPI_STATUS),
  488. REG_RESERVED(PCS1G_TSTPAT_MODE_CFG),
  489. REG_RESERVED(PCS1G_TSTPAT_STATUS),
  490. REG_RESERVED(DEV_PCS_FX100_CFG),
  491. REG_RESERVED(DEV_PCS_FX100_STATUS),
  492. };
  493. static const u32 *vsc9959_regmap[TARGET_MAX] = {
  494. [ANA] = vsc9959_ana_regmap,
  495. [QS] = vsc9959_qs_regmap,
  496. [QSYS] = vsc9959_qsys_regmap,
  497. [REW] = vsc9959_rew_regmap,
  498. [SYS] = vsc9959_sys_regmap,
  499. [S0] = vsc9959_vcap_regmap,
  500. [S1] = vsc9959_vcap_regmap,
  501. [S2] = vsc9959_vcap_regmap,
  502. [PTP] = vsc9959_ptp_regmap,
  503. [GCB] = vsc9959_gcb_regmap,
  504. [DEV_GMII] = vsc9959_dev_gmii_regmap,
  505. };
  506. /* Addresses are relative to the PCI device's base address */
  507. static const struct resource vsc9959_resources[] = {
  508. DEFINE_RES_MEM_NAMED(0x0010000, 0x0010000, "sys"),
  509. DEFINE_RES_MEM_NAMED(0x0030000, 0x0010000, "rew"),
  510. DEFINE_RES_MEM_NAMED(0x0040000, 0x0000400, "s0"),
  511. DEFINE_RES_MEM_NAMED(0x0050000, 0x0000400, "s1"),
  512. DEFINE_RES_MEM_NAMED(0x0060000, 0x0000400, "s2"),
  513. DEFINE_RES_MEM_NAMED(0x0070000, 0x0000200, "devcpu_gcb"),
  514. DEFINE_RES_MEM_NAMED(0x0080000, 0x0000100, "qs"),
  515. DEFINE_RES_MEM_NAMED(0x0090000, 0x00000cc, "ptp"),
  516. DEFINE_RES_MEM_NAMED(0x0100000, 0x0010000, "port0"),
  517. DEFINE_RES_MEM_NAMED(0x0110000, 0x0010000, "port1"),
  518. DEFINE_RES_MEM_NAMED(0x0120000, 0x0010000, "port2"),
  519. DEFINE_RES_MEM_NAMED(0x0130000, 0x0010000, "port3"),
  520. DEFINE_RES_MEM_NAMED(0x0140000, 0x0010000, "port4"),
  521. DEFINE_RES_MEM_NAMED(0x0150000, 0x0010000, "port5"),
  522. DEFINE_RES_MEM_NAMED(0x0200000, 0x0020000, "qsys"),
  523. DEFINE_RES_MEM_NAMED(0x0280000, 0x0010000, "ana"),
  524. };
  525. static const char * const vsc9959_resource_names[TARGET_MAX] = {
  526. [SYS] = "sys",
  527. [REW] = "rew",
  528. [S0] = "s0",
  529. [S1] = "s1",
  530. [S2] = "s2",
  531. [GCB] = "devcpu_gcb",
  532. [QS] = "qs",
  533. [PTP] = "ptp",
  534. [QSYS] = "qsys",
  535. [ANA] = "ana",
  536. };
  537. /* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
  538. * SGMII/QSGMII MAC PCS can be found.
  539. */
  540. static const struct resource vsc9959_imdio_res =
  541. DEFINE_RES_MEM_NAMED(0x8030, 0x10, "imdio");
  542. static const struct reg_field vsc9959_regfields[REGFIELD_MAX] = {
  543. [ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 6, 6),
  544. [ANA_ADVLEARN_LEARN_MIRROR] = REG_FIELD(ANA_ADVLEARN, 0, 5),
  545. [ANA_ANEVENTS_FLOOD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 30, 30),
  546. [ANA_ANEVENTS_AUTOAGE] = REG_FIELD(ANA_ANEVENTS, 26, 26),
  547. [ANA_ANEVENTS_STORM_DROP] = REG_FIELD(ANA_ANEVENTS, 24, 24),
  548. [ANA_ANEVENTS_LEARN_DROP] = REG_FIELD(ANA_ANEVENTS, 23, 23),
  549. [ANA_ANEVENTS_AGED_ENTRY] = REG_FIELD(ANA_ANEVENTS, 22, 22),
  550. [ANA_ANEVENTS_CPU_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 21, 21),
  551. [ANA_ANEVENTS_AUTO_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 20, 20),
  552. [ANA_ANEVENTS_LEARN_REMOVE] = REG_FIELD(ANA_ANEVENTS, 19, 19),
  553. [ANA_ANEVENTS_AUTO_LEARNED] = REG_FIELD(ANA_ANEVENTS, 18, 18),
  554. [ANA_ANEVENTS_AUTO_MOVED] = REG_FIELD(ANA_ANEVENTS, 17, 17),
  555. [ANA_ANEVENTS_CLASSIFIED_DROP] = REG_FIELD(ANA_ANEVENTS, 15, 15),
  556. [ANA_ANEVENTS_CLASSIFIED_COPY] = REG_FIELD(ANA_ANEVENTS, 14, 14),
  557. [ANA_ANEVENTS_VLAN_DISCARD] = REG_FIELD(ANA_ANEVENTS, 13, 13),
  558. [ANA_ANEVENTS_FWD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 12, 12),
  559. [ANA_ANEVENTS_MULTICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 11, 11),
  560. [ANA_ANEVENTS_UNICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 10, 10),
  561. [ANA_ANEVENTS_DEST_KNOWN] = REG_FIELD(ANA_ANEVENTS, 9, 9),
  562. [ANA_ANEVENTS_BUCKET3_MATCH] = REG_FIELD(ANA_ANEVENTS, 8, 8),
  563. [ANA_ANEVENTS_BUCKET2_MATCH] = REG_FIELD(ANA_ANEVENTS, 7, 7),
  564. [ANA_ANEVENTS_BUCKET1_MATCH] = REG_FIELD(ANA_ANEVENTS, 6, 6),
  565. [ANA_ANEVENTS_BUCKET0_MATCH] = REG_FIELD(ANA_ANEVENTS, 5, 5),
  566. [ANA_ANEVENTS_CPU_OPERATION] = REG_FIELD(ANA_ANEVENTS, 4, 4),
  567. [ANA_ANEVENTS_DMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 3, 3),
  568. [ANA_ANEVENTS_SMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 2, 2),
  569. [ANA_ANEVENTS_SEQ_GEN_ERR_0] = REG_FIELD(ANA_ANEVENTS, 1, 1),
  570. [ANA_ANEVENTS_SEQ_GEN_ERR_1] = REG_FIELD(ANA_ANEVENTS, 0, 0),
  571. [ANA_TABLES_MACACCESS_B_DOM] = REG_FIELD(ANA_TABLES_MACACCESS, 16, 16),
  572. [ANA_TABLES_MACTINDX_BUCKET] = REG_FIELD(ANA_TABLES_MACTINDX, 11, 12),
  573. [ANA_TABLES_MACTINDX_M_INDEX] = REG_FIELD(ANA_TABLES_MACTINDX, 0, 10),
  574. [SYS_RESET_CFG_CORE_ENA] = REG_FIELD(SYS_RESET_CFG, 0, 0),
  575. [GCB_SOFT_RST_SWC_RST] = REG_FIELD(GCB_SOFT_RST, 0, 0),
  576. /* Replicated per number of ports (7), register size 4 per port */
  577. [QSYS_SWITCH_PORT_MODE_PORT_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 14, 14, 7, 4),
  578. [QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 11, 13, 7, 4),
  579. [QSYS_SWITCH_PORT_MODE_YEL_RSRVD] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 10, 10, 7, 4),
  580. [QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 9, 9, 7, 4),
  581. [QSYS_SWITCH_PORT_MODE_TX_PFC_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 1, 8, 7, 4),
  582. [QSYS_SWITCH_PORT_MODE_TX_PFC_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 0, 0, 7, 4),
  583. [SYS_PORT_MODE_DATA_WO_TS] = REG_FIELD_ID(SYS_PORT_MODE, 5, 6, 7, 4),
  584. [SYS_PORT_MODE_INCL_INJ_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 3, 4, 7, 4),
  585. [SYS_PORT_MODE_INCL_XTR_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 1, 2, 7, 4),
  586. [SYS_PORT_MODE_INCL_HDR_ERR] = REG_FIELD_ID(SYS_PORT_MODE, 0, 0, 7, 4),
  587. [SYS_PAUSE_CFG_PAUSE_START] = REG_FIELD_ID(SYS_PAUSE_CFG, 10, 18, 7, 4),
  588. [SYS_PAUSE_CFG_PAUSE_STOP] = REG_FIELD_ID(SYS_PAUSE_CFG, 1, 9, 7, 4),
  589. [SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 7, 4),
  590. };
  591. static const struct vcap_field vsc9959_vcap_es0_keys[] = {
  592. [VCAP_ES0_EGR_PORT] = { 0, 3},
  593. [VCAP_ES0_IGR_PORT] = { 3, 3},
  594. [VCAP_ES0_RSV] = { 6, 2},
  595. [VCAP_ES0_L2_MC] = { 8, 1},
  596. [VCAP_ES0_L2_BC] = { 9, 1},
  597. [VCAP_ES0_VID] = { 10, 12},
  598. [VCAP_ES0_DP] = { 22, 1},
  599. [VCAP_ES0_PCP] = { 23, 3},
  600. };
  601. static const struct vcap_field vsc9959_vcap_es0_actions[] = {
  602. [VCAP_ES0_ACT_PUSH_OUTER_TAG] = { 0, 2},
  603. [VCAP_ES0_ACT_PUSH_INNER_TAG] = { 2, 1},
  604. [VCAP_ES0_ACT_TAG_A_TPID_SEL] = { 3, 2},
  605. [VCAP_ES0_ACT_TAG_A_VID_SEL] = { 5, 1},
  606. [VCAP_ES0_ACT_TAG_A_PCP_SEL] = { 6, 2},
  607. [VCAP_ES0_ACT_TAG_A_DEI_SEL] = { 8, 2},
  608. [VCAP_ES0_ACT_TAG_B_TPID_SEL] = { 10, 2},
  609. [VCAP_ES0_ACT_TAG_B_VID_SEL] = { 12, 1},
  610. [VCAP_ES0_ACT_TAG_B_PCP_SEL] = { 13, 2},
  611. [VCAP_ES0_ACT_TAG_B_DEI_SEL] = { 15, 2},
  612. [VCAP_ES0_ACT_VID_A_VAL] = { 17, 12},
  613. [VCAP_ES0_ACT_PCP_A_VAL] = { 29, 3},
  614. [VCAP_ES0_ACT_DEI_A_VAL] = { 32, 1},
  615. [VCAP_ES0_ACT_VID_B_VAL] = { 33, 12},
  616. [VCAP_ES0_ACT_PCP_B_VAL] = { 45, 3},
  617. [VCAP_ES0_ACT_DEI_B_VAL] = { 48, 1},
  618. [VCAP_ES0_ACT_RSV] = { 49, 23},
  619. [VCAP_ES0_ACT_HIT_STICKY] = { 72, 1},
  620. };
  621. static const struct vcap_field vsc9959_vcap_is1_keys[] = {
  622. [VCAP_IS1_HK_TYPE] = { 0, 1},
  623. [VCAP_IS1_HK_LOOKUP] = { 1, 2},
  624. [VCAP_IS1_HK_IGR_PORT_MASK] = { 3, 7},
  625. [VCAP_IS1_HK_RSV] = { 10, 9},
  626. [VCAP_IS1_HK_OAM_Y1731] = { 19, 1},
  627. [VCAP_IS1_HK_L2_MC] = { 20, 1},
  628. [VCAP_IS1_HK_L2_BC] = { 21, 1},
  629. [VCAP_IS1_HK_IP_MC] = { 22, 1},
  630. [VCAP_IS1_HK_VLAN_TAGGED] = { 23, 1},
  631. [VCAP_IS1_HK_VLAN_DBL_TAGGED] = { 24, 1},
  632. [VCAP_IS1_HK_TPID] = { 25, 1},
  633. [VCAP_IS1_HK_VID] = { 26, 12},
  634. [VCAP_IS1_HK_DEI] = { 38, 1},
  635. [VCAP_IS1_HK_PCP] = { 39, 3},
  636. /* Specific Fields for IS1 Half Key S1_NORMAL */
  637. [VCAP_IS1_HK_L2_SMAC] = { 42, 48},
  638. [VCAP_IS1_HK_ETYPE_LEN] = { 90, 1},
  639. [VCAP_IS1_HK_ETYPE] = { 91, 16},
  640. [VCAP_IS1_HK_IP_SNAP] = {107, 1},
  641. [VCAP_IS1_HK_IP4] = {108, 1},
  642. /* Layer-3 Information */
  643. [VCAP_IS1_HK_L3_FRAGMENT] = {109, 1},
  644. [VCAP_IS1_HK_L3_FRAG_OFS_GT0] = {110, 1},
  645. [VCAP_IS1_HK_L3_OPTIONS] = {111, 1},
  646. [VCAP_IS1_HK_L3_DSCP] = {112, 6},
  647. [VCAP_IS1_HK_L3_IP4_SIP] = {118, 32},
  648. /* Layer-4 Information */
  649. [VCAP_IS1_HK_TCP_UDP] = {150, 1},
  650. [VCAP_IS1_HK_TCP] = {151, 1},
  651. [VCAP_IS1_HK_L4_SPORT] = {152, 16},
  652. [VCAP_IS1_HK_L4_RNG] = {168, 8},
  653. /* Specific Fields for IS1 Half Key S1_5TUPLE_IP4 */
  654. [VCAP_IS1_HK_IP4_INNER_TPID] = { 42, 1},
  655. [VCAP_IS1_HK_IP4_INNER_VID] = { 43, 12},
  656. [VCAP_IS1_HK_IP4_INNER_DEI] = { 55, 1},
  657. [VCAP_IS1_HK_IP4_INNER_PCP] = { 56, 3},
  658. [VCAP_IS1_HK_IP4_IP4] = { 59, 1},
  659. [VCAP_IS1_HK_IP4_L3_FRAGMENT] = { 60, 1},
  660. [VCAP_IS1_HK_IP4_L3_FRAG_OFS_GT0] = { 61, 1},
  661. [VCAP_IS1_HK_IP4_L3_OPTIONS] = { 62, 1},
  662. [VCAP_IS1_HK_IP4_L3_DSCP] = { 63, 6},
  663. [VCAP_IS1_HK_IP4_L3_IP4_DIP] = { 69, 32},
  664. [VCAP_IS1_HK_IP4_L3_IP4_SIP] = {101, 32},
  665. [VCAP_IS1_HK_IP4_L3_PROTO] = {133, 8},
  666. [VCAP_IS1_HK_IP4_TCP_UDP] = {141, 1},
  667. [VCAP_IS1_HK_IP4_TCP] = {142, 1},
  668. [VCAP_IS1_HK_IP4_L4_RNG] = {143, 8},
  669. [VCAP_IS1_HK_IP4_IP_PAYLOAD_S1_5TUPLE] = {151, 32},
  670. };
  671. static const struct vcap_field vsc9959_vcap_is1_actions[] = {
  672. [VCAP_IS1_ACT_DSCP_ENA] = { 0, 1},
  673. [VCAP_IS1_ACT_DSCP_VAL] = { 1, 6},
  674. [VCAP_IS1_ACT_QOS_ENA] = { 7, 1},
  675. [VCAP_IS1_ACT_QOS_VAL] = { 8, 3},
  676. [VCAP_IS1_ACT_DP_ENA] = { 11, 1},
  677. [VCAP_IS1_ACT_DP_VAL] = { 12, 1},
  678. [VCAP_IS1_ACT_PAG_OVERRIDE_MASK] = { 13, 8},
  679. [VCAP_IS1_ACT_PAG_VAL] = { 21, 8},
  680. [VCAP_IS1_ACT_RSV] = { 29, 9},
  681. /* The fields below are incorrectly shifted by 2 in the manual */
  682. [VCAP_IS1_ACT_VID_REPLACE_ENA] = { 38, 1},
  683. [VCAP_IS1_ACT_VID_ADD_VAL] = { 39, 12},
  684. [VCAP_IS1_ACT_FID_SEL] = { 51, 2},
  685. [VCAP_IS1_ACT_FID_VAL] = { 53, 13},
  686. [VCAP_IS1_ACT_PCP_DEI_ENA] = { 66, 1},
  687. [VCAP_IS1_ACT_PCP_VAL] = { 67, 3},
  688. [VCAP_IS1_ACT_DEI_VAL] = { 70, 1},
  689. [VCAP_IS1_ACT_VLAN_POP_CNT_ENA] = { 71, 1},
  690. [VCAP_IS1_ACT_VLAN_POP_CNT] = { 72, 2},
  691. [VCAP_IS1_ACT_CUSTOM_ACE_TYPE_ENA] = { 74, 4},
  692. [VCAP_IS1_ACT_HIT_STICKY] = { 78, 1},
  693. };
  694. static struct vcap_field vsc9959_vcap_is2_keys[] = {
  695. /* Common: 41 bits */
  696. [VCAP_IS2_TYPE] = { 0, 4},
  697. [VCAP_IS2_HK_FIRST] = { 4, 1},
  698. [VCAP_IS2_HK_PAG] = { 5, 8},
  699. [VCAP_IS2_HK_IGR_PORT_MASK] = { 13, 7},
  700. [VCAP_IS2_HK_RSV2] = { 20, 1},
  701. [VCAP_IS2_HK_HOST_MATCH] = { 21, 1},
  702. [VCAP_IS2_HK_L2_MC] = { 22, 1},
  703. [VCAP_IS2_HK_L2_BC] = { 23, 1},
  704. [VCAP_IS2_HK_VLAN_TAGGED] = { 24, 1},
  705. [VCAP_IS2_HK_VID] = { 25, 12},
  706. [VCAP_IS2_HK_DEI] = { 37, 1},
  707. [VCAP_IS2_HK_PCP] = { 38, 3},
  708. /* MAC_ETYPE / MAC_LLC / MAC_SNAP / OAM common */
  709. [VCAP_IS2_HK_L2_DMAC] = { 41, 48},
  710. [VCAP_IS2_HK_L2_SMAC] = { 89, 48},
  711. /* MAC_ETYPE (TYPE=000) */
  712. [VCAP_IS2_HK_MAC_ETYPE_ETYPE] = {137, 16},
  713. [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0] = {153, 16},
  714. [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1] = {169, 8},
  715. [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2] = {177, 3},
  716. /* MAC_LLC (TYPE=001) */
  717. [VCAP_IS2_HK_MAC_LLC_L2_LLC] = {137, 40},
  718. /* MAC_SNAP (TYPE=010) */
  719. [VCAP_IS2_HK_MAC_SNAP_L2_SNAP] = {137, 40},
  720. /* MAC_ARP (TYPE=011) */
  721. [VCAP_IS2_HK_MAC_ARP_SMAC] = { 41, 48},
  722. [VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK] = { 89, 1},
  723. [VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK] = { 90, 1},
  724. [VCAP_IS2_HK_MAC_ARP_LEN_OK] = { 91, 1},
  725. [VCAP_IS2_HK_MAC_ARP_TARGET_MATCH] = { 92, 1},
  726. [VCAP_IS2_HK_MAC_ARP_SENDER_MATCH] = { 93, 1},
  727. [VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN] = { 94, 1},
  728. [VCAP_IS2_HK_MAC_ARP_OPCODE] = { 95, 2},
  729. [VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP] = { 97, 32},
  730. [VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP] = {129, 32},
  731. [VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP] = {161, 1},
  732. /* IP4_TCP_UDP / IP4_OTHER common */
  733. [VCAP_IS2_HK_IP4] = { 41, 1},
  734. [VCAP_IS2_HK_L3_FRAGMENT] = { 42, 1},
  735. [VCAP_IS2_HK_L3_FRAG_OFS_GT0] = { 43, 1},
  736. [VCAP_IS2_HK_L3_OPTIONS] = { 44, 1},
  737. [VCAP_IS2_HK_IP4_L3_TTL_GT0] = { 45, 1},
  738. [VCAP_IS2_HK_L3_TOS] = { 46, 8},
  739. [VCAP_IS2_HK_L3_IP4_DIP] = { 54, 32},
  740. [VCAP_IS2_HK_L3_IP4_SIP] = { 86, 32},
  741. [VCAP_IS2_HK_DIP_EQ_SIP] = {118, 1},
  742. /* IP4_TCP_UDP (TYPE=100) */
  743. [VCAP_IS2_HK_TCP] = {119, 1},
  744. [VCAP_IS2_HK_L4_DPORT] = {120, 16},
  745. [VCAP_IS2_HK_L4_SPORT] = {136, 16},
  746. [VCAP_IS2_HK_L4_RNG] = {152, 8},
  747. [VCAP_IS2_HK_L4_SPORT_EQ_DPORT] = {160, 1},
  748. [VCAP_IS2_HK_L4_SEQUENCE_EQ0] = {161, 1},
  749. [VCAP_IS2_HK_L4_FIN] = {162, 1},
  750. [VCAP_IS2_HK_L4_SYN] = {163, 1},
  751. [VCAP_IS2_HK_L4_RST] = {164, 1},
  752. [VCAP_IS2_HK_L4_PSH] = {165, 1},
  753. [VCAP_IS2_HK_L4_ACK] = {166, 1},
  754. [VCAP_IS2_HK_L4_URG] = {167, 1},
  755. [VCAP_IS2_HK_L4_1588_DOM] = {168, 8},
  756. [VCAP_IS2_HK_L4_1588_VER] = {176, 4},
  757. /* IP4_OTHER (TYPE=101) */
  758. [VCAP_IS2_HK_IP4_L3_PROTO] = {119, 8},
  759. [VCAP_IS2_HK_L3_PAYLOAD] = {127, 56},
  760. /* IP6_STD (TYPE=110) */
  761. [VCAP_IS2_HK_IP6_L3_TTL_GT0] = { 41, 1},
  762. [VCAP_IS2_HK_L3_IP6_SIP] = { 42, 128},
  763. [VCAP_IS2_HK_IP6_L3_PROTO] = {170, 8},
  764. /* OAM (TYPE=111) */
  765. [VCAP_IS2_HK_OAM_MEL_FLAGS] = {137, 7},
  766. [VCAP_IS2_HK_OAM_VER] = {144, 5},
  767. [VCAP_IS2_HK_OAM_OPCODE] = {149, 8},
  768. [VCAP_IS2_HK_OAM_FLAGS] = {157, 8},
  769. [VCAP_IS2_HK_OAM_MEPID] = {165, 16},
  770. [VCAP_IS2_HK_OAM_CCM_CNTS_EQ0] = {181, 1},
  771. [VCAP_IS2_HK_OAM_IS_Y1731] = {182, 1},
  772. };
  773. static struct vcap_field vsc9959_vcap_is2_actions[] = {
  774. [VCAP_IS2_ACT_HIT_ME_ONCE] = { 0, 1},
  775. [VCAP_IS2_ACT_CPU_COPY_ENA] = { 1, 1},
  776. [VCAP_IS2_ACT_CPU_QU_NUM] = { 2, 3},
  777. [VCAP_IS2_ACT_MASK_MODE] = { 5, 2},
  778. [VCAP_IS2_ACT_MIRROR_ENA] = { 7, 1},
  779. [VCAP_IS2_ACT_LRN_DIS] = { 8, 1},
  780. [VCAP_IS2_ACT_POLICE_ENA] = { 9, 1},
  781. [VCAP_IS2_ACT_POLICE_IDX] = { 10, 9},
  782. [VCAP_IS2_ACT_POLICE_VCAP_ONLY] = { 19, 1},
  783. [VCAP_IS2_ACT_PORT_MASK] = { 20, 6},
  784. [VCAP_IS2_ACT_REW_OP] = { 26, 9},
  785. [VCAP_IS2_ACT_SMAC_REPLACE_ENA] = { 35, 1},
  786. [VCAP_IS2_ACT_RSV] = { 36, 2},
  787. [VCAP_IS2_ACT_ACL_ID] = { 38, 6},
  788. [VCAP_IS2_ACT_HIT_CNT] = { 44, 32},
  789. };
  790. static struct vcap_props vsc9959_vcap_props[] = {
  791. [VCAP_ES0] = {
  792. .action_type_width = 0,
  793. .action_table = {
  794. [ES0_ACTION_TYPE_NORMAL] = {
  795. .width = 72, /* HIT_STICKY not included */
  796. .count = 1,
  797. },
  798. },
  799. .target = S0,
  800. .keys = vsc9959_vcap_es0_keys,
  801. .actions = vsc9959_vcap_es0_actions,
  802. },
  803. [VCAP_IS1] = {
  804. .action_type_width = 0,
  805. .action_table = {
  806. [IS1_ACTION_TYPE_NORMAL] = {
  807. .width = 78, /* HIT_STICKY not included */
  808. .count = 4,
  809. },
  810. },
  811. .target = S1,
  812. .keys = vsc9959_vcap_is1_keys,
  813. .actions = vsc9959_vcap_is1_actions,
  814. },
  815. [VCAP_IS2] = {
  816. .action_type_width = 1,
  817. .action_table = {
  818. [IS2_ACTION_TYPE_NORMAL] = {
  819. .width = 44,
  820. .count = 2
  821. },
  822. [IS2_ACTION_TYPE_SMAC_SIP] = {
  823. .width = 6,
  824. .count = 4
  825. },
  826. },
  827. .target = S2,
  828. .keys = vsc9959_vcap_is2_keys,
  829. .actions = vsc9959_vcap_is2_actions,
  830. },
  831. };
  832. static const struct ptp_clock_info vsc9959_ptp_caps = {
  833. .owner = THIS_MODULE,
  834. .name = "felix ptp",
  835. .max_adj = 0x7fffffff,
  836. .n_alarm = 0,
  837. .n_ext_ts = 0,
  838. .n_per_out = OCELOT_PTP_PINS_NUM,
  839. .n_pins = OCELOT_PTP_PINS_NUM,
  840. .pps = 0,
  841. .gettime64 = ocelot_ptp_gettime64,
  842. .settime64 = ocelot_ptp_settime64,
  843. .adjtime = ocelot_ptp_adjtime,
  844. .adjfine = ocelot_ptp_adjfine,
  845. .verify = ocelot_ptp_verify,
  846. .enable = ocelot_ptp_enable,
  847. };
  848. #define VSC9959_INIT_TIMEOUT 50000
  849. #define VSC9959_GCB_RST_SLEEP 100
  850. #define VSC9959_SYS_RAMINIT_SLEEP 80
  851. static int vsc9959_gcb_soft_rst_status(struct ocelot *ocelot)
  852. {
  853. int val;
  854. ocelot_field_read(ocelot, GCB_SOFT_RST_SWC_RST, &val);
  855. return val;
  856. }
  857. static int vsc9959_sys_ram_init_status(struct ocelot *ocelot)
  858. {
  859. return ocelot_read(ocelot, SYS_RAM_INIT);
  860. }
  861. /* CORE_ENA is in SYS:SYSTEM:RESET_CFG
  862. * RAM_INIT is in SYS:RAM_CTRL:RAM_INIT
  863. */
  864. static int vsc9959_reset(struct ocelot *ocelot)
  865. {
  866. int val, err;
  867. /* soft-reset the switch core */
  868. ocelot_field_write(ocelot, GCB_SOFT_RST_SWC_RST, 1);
  869. err = readx_poll_timeout(vsc9959_gcb_soft_rst_status, ocelot, val, !val,
  870. VSC9959_GCB_RST_SLEEP, VSC9959_INIT_TIMEOUT);
  871. if (err) {
  872. dev_err(ocelot->dev, "timeout: switch core reset\n");
  873. return err;
  874. }
  875. /* initialize switch mem ~40us */
  876. ocelot_write(ocelot, SYS_RAM_INIT_RAM_INIT, SYS_RAM_INIT);
  877. err = readx_poll_timeout(vsc9959_sys_ram_init_status, ocelot, val, !val,
  878. VSC9959_SYS_RAMINIT_SLEEP,
  879. VSC9959_INIT_TIMEOUT);
  880. if (err) {
  881. dev_err(ocelot->dev, "timeout: switch sram init\n");
  882. return err;
  883. }
  884. /* enable switch core */
  885. ocelot_field_write(ocelot, SYS_RESET_CFG_CORE_ENA, 1);
  886. return 0;
  887. }
  888. /* Watermark encode
  889. * Bit 8: Unit; 0:1, 1:16
  890. * Bit 7-0: Value to be multiplied with unit
  891. */
  892. static u16 vsc9959_wm_enc(u16 value)
  893. {
  894. WARN_ON(value >= 16 * BIT(8));
  895. if (value >= BIT(8))
  896. return BIT(8) | (value / 16);
  897. return value;
  898. }
  899. static u16 vsc9959_wm_dec(u16 wm)
  900. {
  901. WARN_ON(wm & ~GENMASK(8, 0));
  902. if (wm & BIT(8))
  903. return (wm & GENMASK(7, 0)) * 16;
  904. return wm;
  905. }
  906. static void vsc9959_wm_stat(u32 val, u32 *inuse, u32 *maxuse)
  907. {
  908. *inuse = (val & GENMASK(23, 12)) >> 12;
  909. *maxuse = val & GENMASK(11, 0);
  910. }
  911. static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
  912. {
  913. struct pci_dev *pdev = to_pci_dev(ocelot->dev);
  914. struct felix *felix = ocelot_to_felix(ocelot);
  915. struct enetc_mdio_priv *mdio_priv;
  916. struct device *dev = ocelot->dev;
  917. resource_size_t imdio_base;
  918. void __iomem *imdio_regs;
  919. struct resource res;
  920. struct enetc_hw *hw;
  921. struct mii_bus *bus;
  922. int port;
  923. int rc;
  924. felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
  925. sizeof(struct phylink_pcs *),
  926. GFP_KERNEL);
  927. if (!felix->pcs) {
  928. dev_err(dev, "failed to allocate array for PCS PHYs\n");
  929. return -ENOMEM;
  930. }
  931. imdio_base = pci_resource_start(pdev, VSC9959_IMDIO_PCI_BAR);
  932. memcpy(&res, &vsc9959_imdio_res, sizeof(res));
  933. res.start += imdio_base;
  934. res.end += imdio_base;
  935. imdio_regs = devm_ioremap_resource(dev, &res);
  936. if (IS_ERR(imdio_regs))
  937. return PTR_ERR(imdio_regs);
  938. hw = enetc_hw_alloc(dev, imdio_regs);
  939. if (IS_ERR(hw)) {
  940. dev_err(dev, "failed to allocate ENETC HW structure\n");
  941. return PTR_ERR(hw);
  942. }
  943. bus = mdiobus_alloc_size(sizeof(*mdio_priv));
  944. if (!bus)
  945. return -ENOMEM;
  946. bus->name = "VSC9959 internal MDIO bus";
  947. bus->read = enetc_mdio_read_c22;
  948. bus->write = enetc_mdio_write_c22;
  949. bus->read_c45 = enetc_mdio_read_c45;
  950. bus->write_c45 = enetc_mdio_write_c45;
  951. bus->parent = dev;
  952. mdio_priv = bus->priv;
  953. mdio_priv->hw = hw;
  954. /* This gets added to imdio_regs, which already maps addresses
  955. * starting with the proper offset.
  956. */
  957. mdio_priv->mdio_base = 0;
  958. snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
  959. /* Needed in order to initialize the bus mutex lock */
  960. rc = mdiobus_register(bus);
  961. if (rc < 0) {
  962. dev_err(dev, "failed to register MDIO bus\n");
  963. mdiobus_free(bus);
  964. return rc;
  965. }
  966. felix->imdio = bus;
  967. for (port = 0; port < felix->info->num_ports; port++) {
  968. struct ocelot_port *ocelot_port = ocelot->ports[port];
  969. struct phylink_pcs *phylink_pcs;
  970. if (dsa_is_unused_port(felix->ds, port))
  971. continue;
  972. if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
  973. continue;
  974. phylink_pcs = lynx_pcs_create_mdiodev(felix->imdio, port);
  975. if (IS_ERR(phylink_pcs))
  976. continue;
  977. felix->pcs[port] = phylink_pcs;
  978. dev_info(dev, "Found PCS at internal MDIO address %d\n", port);
  979. }
  980. return 0;
  981. }
  982. static void vsc9959_mdio_bus_free(struct ocelot *ocelot)
  983. {
  984. struct felix *felix = ocelot_to_felix(ocelot);
  985. int port;
  986. for (port = 0; port < ocelot->num_phys_ports; port++) {
  987. struct phylink_pcs *phylink_pcs = felix->pcs[port];
  988. if (phylink_pcs)
  989. lynx_pcs_destroy(phylink_pcs);
  990. }
  991. mdiobus_unregister(felix->imdio);
  992. mdiobus_free(felix->imdio);
  993. }
  994. /* The switch considers any frame (regardless of size) as eligible
  995. * for transmission if the traffic class gate is open for at least
  996. * VSC9959_TAS_MIN_GATE_LEN_NS.
  997. *
  998. * Overruns are prevented by cropping an interval at the end of the gate time
  999. * slot for which egress scheduling is blocked, but we need to still keep
  1000. * VSC9959_TAS_MIN_GATE_LEN_NS available for one packet to be transmitted,
  1001. * otherwise the port tc will hang.
  1002. *
  1003. * This function returns the size of a gate interval that remains available for
  1004. * setting the guard band, after reserving the space for one egress frame.
  1005. */
  1006. static u64 vsc9959_tas_remaining_gate_len_ps(u64 gate_len_ns)
  1007. {
  1008. /* Gate always open */
  1009. if (gate_len_ns == U64_MAX)
  1010. return U64_MAX;
  1011. if (gate_len_ns < VSC9959_TAS_MIN_GATE_LEN_NS)
  1012. return 0;
  1013. return (gate_len_ns - VSC9959_TAS_MIN_GATE_LEN_NS) * PSEC_PER_NSEC;
  1014. }
  1015. /* Extract shortest continuous gate open intervals in ns for each traffic class
  1016. * of a cyclic tc-taprio schedule. If a gate is always open, the duration is
  1017. * considered U64_MAX. If the gate is always closed, it is considered 0.
  1018. */
  1019. static void vsc9959_tas_min_gate_lengths(struct tc_taprio_qopt_offload *taprio,
  1020. u64 min_gate_len[OCELOT_NUM_TC])
  1021. {
  1022. struct tc_taprio_sched_entry *entry;
  1023. u64 gate_len[OCELOT_NUM_TC];
  1024. u8 gates_ever_opened = 0;
  1025. int tc, i, n;
  1026. /* Initialize arrays */
  1027. for (tc = 0; tc < OCELOT_NUM_TC; tc++) {
  1028. min_gate_len[tc] = U64_MAX;
  1029. gate_len[tc] = 0;
  1030. }
  1031. /* If we don't have taprio, consider all gates as permanently open */
  1032. if (!taprio)
  1033. return;
  1034. n = taprio->num_entries;
  1035. /* Walk through the gate list twice to determine the length
  1036. * of consecutively open gates for a traffic class, including
  1037. * open gates that wrap around. We are just interested in the
  1038. * minimum window size, and this doesn't change what the
  1039. * minimum is (if the gate never closes, min_gate_len will
  1040. * remain U64_MAX).
  1041. */
  1042. for (i = 0; i < 2 * n; i++) {
  1043. entry = &taprio->entries[i % n];
  1044. for (tc = 0; tc < OCELOT_NUM_TC; tc++) {
  1045. if (entry->gate_mask & BIT(tc)) {
  1046. gate_len[tc] += entry->interval;
  1047. gates_ever_opened |= BIT(tc);
  1048. } else {
  1049. /* Gate closes now, record a potential new
  1050. * minimum and reinitialize length
  1051. */
  1052. if (min_gate_len[tc] > gate_len[tc] &&
  1053. gate_len[tc])
  1054. min_gate_len[tc] = gate_len[tc];
  1055. gate_len[tc] = 0;
  1056. }
  1057. }
  1058. }
  1059. /* min_gate_len[tc] actually tracks minimum *open* gate time, so for
  1060. * permanently closed gates, min_gate_len[tc] will still be U64_MAX.
  1061. * Therefore they are currently indistinguishable from permanently
  1062. * open gates. Overwrite the gate len with 0 when we know they're
  1063. * actually permanently closed, i.e. after the loop above.
  1064. */
  1065. for (tc = 0; tc < OCELOT_NUM_TC; tc++)
  1066. if (!(gates_ever_opened & BIT(tc)))
  1067. min_gate_len[tc] = 0;
  1068. }
  1069. /* ocelot_write_rix is a macro that concatenates QSYS_MAXSDU_CFG_* with _RSZ,
  1070. * so we need to spell out the register access to each traffic class in helper
  1071. * functions, to simplify callers
  1072. */
  1073. static void vsc9959_port_qmaxsdu_set(struct ocelot *ocelot, int port, int tc,
  1074. u32 max_sdu)
  1075. {
  1076. switch (tc) {
  1077. case 0:
  1078. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_0,
  1079. port);
  1080. break;
  1081. case 1:
  1082. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_1,
  1083. port);
  1084. break;
  1085. case 2:
  1086. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_2,
  1087. port);
  1088. break;
  1089. case 3:
  1090. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_3,
  1091. port);
  1092. break;
  1093. case 4:
  1094. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_4,
  1095. port);
  1096. break;
  1097. case 5:
  1098. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_5,
  1099. port);
  1100. break;
  1101. case 6:
  1102. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_6,
  1103. port);
  1104. break;
  1105. case 7:
  1106. ocelot_write_rix(ocelot, max_sdu, QSYS_QMAXSDU_CFG_7,
  1107. port);
  1108. break;
  1109. }
  1110. }
  1111. static u32 vsc9959_port_qmaxsdu_get(struct ocelot *ocelot, int port, int tc)
  1112. {
  1113. switch (tc) {
  1114. case 0: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_0, port);
  1115. case 1: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_1, port);
  1116. case 2: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_2, port);
  1117. case 3: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_3, port);
  1118. case 4: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_4, port);
  1119. case 5: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_5, port);
  1120. case 6: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_6, port);
  1121. case 7: return ocelot_read_rix(ocelot, QSYS_QMAXSDU_CFG_7, port);
  1122. default:
  1123. return 0;
  1124. }
  1125. }
  1126. static u32 vsc9959_tas_tc_max_sdu(struct tc_taprio_qopt_offload *taprio, int tc)
  1127. {
  1128. if (!taprio || !taprio->max_sdu[tc])
  1129. return 0;
  1130. return taprio->max_sdu[tc] + ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN;
  1131. }
  1132. /* Update QSYS_PORT_MAX_SDU to make sure the static guard bands added by the
  1133. * switch (see the ALWAYS_GUARD_BAND_SCH_Q comment) are correct at all MTU
  1134. * values (the default value is 1518). Also, for traffic class windows smaller
  1135. * than one MTU sized frame, update QSYS_QMAXSDU_CFG to enable oversized frame
  1136. * dropping, such that these won't hang the port, as they will never be sent.
  1137. */
  1138. static void vsc9959_tas_guard_bands_update(struct ocelot *ocelot, int port)
  1139. {
  1140. struct ocelot_port *ocelot_port = ocelot->ports[port];
  1141. struct ocelot_mm_state *mm = &ocelot->mm[port];
  1142. struct tc_taprio_qopt_offload *taprio;
  1143. u64 min_gate_len[OCELOT_NUM_TC];
  1144. u32 val, maxlen, add_frag_size;
  1145. u64 needed_min_frag_time_ps;
  1146. int speed, picos_per_byte;
  1147. u64 needed_bit_time_ps;
  1148. u8 tas_speed;
  1149. int tc;
  1150. lockdep_assert_held(&ocelot->fwd_domain_lock);
  1151. taprio = ocelot_port->taprio;
  1152. val = ocelot_read_rix(ocelot, QSYS_TAG_CONFIG, port);
  1153. tas_speed = QSYS_TAG_CONFIG_LINK_SPEED_X(val);
  1154. switch (tas_speed) {
  1155. case OCELOT_SPEED_10:
  1156. speed = SPEED_10;
  1157. break;
  1158. case OCELOT_SPEED_100:
  1159. speed = SPEED_100;
  1160. break;
  1161. case OCELOT_SPEED_1000:
  1162. speed = SPEED_1000;
  1163. break;
  1164. case OCELOT_SPEED_2500:
  1165. speed = SPEED_2500;
  1166. break;
  1167. default:
  1168. return;
  1169. }
  1170. picos_per_byte = (USEC_PER_SEC * 8) / speed;
  1171. val = ocelot_port_readl(ocelot_port, DEV_MAC_MAXLEN_CFG);
  1172. /* MAXLEN_CFG accounts automatically for VLAN. We need to include it
  1173. * manually in the bit time calculation, plus the preamble and SFD.
  1174. */
  1175. maxlen = val + 2 * VLAN_HLEN;
  1176. /* Consider the standard Ethernet overhead of 8 octets preamble+SFD,
  1177. * 4 octets FCS, 12 octets IFG.
  1178. */
  1179. needed_bit_time_ps = (u64)(maxlen + 24) * picos_per_byte;
  1180. /* Preemptible TCs don't need to pass a full MTU, the port will
  1181. * automatically emit a HOLD request when a preemptible TC gate closes
  1182. */
  1183. val = ocelot_read_rix(ocelot, QSYS_PREEMPTION_CFG, port);
  1184. add_frag_size = QSYS_PREEMPTION_CFG_MM_ADD_FRAG_SIZE_X(val);
  1185. needed_min_frag_time_ps = picos_per_byte *
  1186. (u64)(24 + 2 * ethtool_mm_frag_size_add_to_min(add_frag_size));
  1187. dev_dbg(ocelot->dev,
  1188. "port %d: max frame size %d needs %llu ps, %llu ps for mPackets at speed %d\n",
  1189. port, maxlen, needed_bit_time_ps, needed_min_frag_time_ps,
  1190. speed);
  1191. vsc9959_tas_min_gate_lengths(taprio, min_gate_len);
  1192. for (tc = 0; tc < OCELOT_NUM_TC; tc++) {
  1193. u32 requested_max_sdu = vsc9959_tas_tc_max_sdu(taprio, tc);
  1194. u64 remaining_gate_len_ps;
  1195. u32 max_sdu;
  1196. remaining_gate_len_ps =
  1197. vsc9959_tas_remaining_gate_len_ps(min_gate_len[tc]);
  1198. if ((mm->active_preemptible_tcs & BIT(tc)) ?
  1199. remaining_gate_len_ps > needed_min_frag_time_ps :
  1200. remaining_gate_len_ps > needed_bit_time_ps) {
  1201. /* Setting QMAXSDU_CFG to 0 disables oversized frame
  1202. * dropping.
  1203. */
  1204. max_sdu = requested_max_sdu;
  1205. dev_dbg(ocelot->dev,
  1206. "port %d tc %d min gate len %llu"
  1207. ", sending all frames\n",
  1208. port, tc, min_gate_len[tc]);
  1209. } else {
  1210. /* If traffic class doesn't support a full MTU sized
  1211. * frame, make sure to enable oversize frame dropping
  1212. * for frames larger than the smallest that would fit.
  1213. *
  1214. * However, the exact same register, QSYS_QMAXSDU_CFG_*,
  1215. * controls not only oversized frame dropping, but also
  1216. * per-tc static guard band lengths, so it reduces the
  1217. * useful gate interval length. Therefore, be careful
  1218. * to calculate a guard band (and therefore max_sdu)
  1219. * that still leaves VSC9959_TAS_MIN_GATE_LEN_NS
  1220. * available in the time slot.
  1221. */
  1222. max_sdu = div_u64(remaining_gate_len_ps, picos_per_byte);
  1223. /* A TC gate may be completely closed, which is a
  1224. * special case where all packets are oversized.
  1225. * Any limit smaller than 64 octets accomplishes this
  1226. */
  1227. if (!max_sdu)
  1228. max_sdu = 1;
  1229. /* Take L1 overhead into account, but just don't allow
  1230. * max_sdu to go negative or to 0. Here we use 20
  1231. * because QSYS_MAXSDU_CFG_* already counts the 4 FCS
  1232. * octets as part of packet size.
  1233. */
  1234. if (max_sdu > 20)
  1235. max_sdu -= 20;
  1236. if (requested_max_sdu && requested_max_sdu < max_sdu)
  1237. max_sdu = requested_max_sdu;
  1238. dev_info(ocelot->dev,
  1239. "port %d tc %d min gate length %llu"
  1240. " ns not enough for max frame size %d at %d"
  1241. " Mbps, dropping frames over %d"
  1242. " octets including FCS\n",
  1243. port, tc, min_gate_len[tc], maxlen, speed,
  1244. max_sdu);
  1245. }
  1246. vsc9959_port_qmaxsdu_set(ocelot, port, tc, max_sdu);
  1247. }
  1248. ocelot_write_rix(ocelot, maxlen, QSYS_PORT_MAX_SDU, port);
  1249. ocelot->ops->cut_through_fwd(ocelot);
  1250. }
  1251. static void vsc9959_sched_speed_set(struct ocelot *ocelot, int port,
  1252. u32 speed)
  1253. {
  1254. struct ocelot_port *ocelot_port = ocelot->ports[port];
  1255. u8 tas_speed;
  1256. switch (speed) {
  1257. case SPEED_10:
  1258. tas_speed = OCELOT_SPEED_10;
  1259. break;
  1260. case SPEED_100:
  1261. tas_speed = OCELOT_SPEED_100;
  1262. break;
  1263. case SPEED_1000:
  1264. tas_speed = OCELOT_SPEED_1000;
  1265. break;
  1266. case SPEED_2500:
  1267. tas_speed = OCELOT_SPEED_2500;
  1268. break;
  1269. default:
  1270. tas_speed = OCELOT_SPEED_1000;
  1271. break;
  1272. }
  1273. mutex_lock(&ocelot->fwd_domain_lock);
  1274. ocelot_rmw_rix(ocelot,
  1275. QSYS_TAG_CONFIG_LINK_SPEED(tas_speed),
  1276. QSYS_TAG_CONFIG_LINK_SPEED_M,
  1277. QSYS_TAG_CONFIG, port);
  1278. if (ocelot_port->taprio)
  1279. vsc9959_tas_guard_bands_update(ocelot, port);
  1280. mutex_unlock(&ocelot->fwd_domain_lock);
  1281. }
  1282. static void vsc9959_new_base_time(struct ocelot *ocelot, ktime_t base_time,
  1283. u64 cycle_time,
  1284. struct timespec64 *new_base_ts)
  1285. {
  1286. struct timespec64 ts;
  1287. ktime_t new_base_time;
  1288. ktime_t current_time;
  1289. ocelot_ptp_gettime64(&ocelot->ptp_info, &ts);
  1290. current_time = timespec64_to_ktime(ts);
  1291. new_base_time = base_time;
  1292. if (base_time < current_time) {
  1293. u64 nr_of_cycles = current_time - base_time;
  1294. do_div(nr_of_cycles, cycle_time);
  1295. new_base_time += cycle_time * (nr_of_cycles + 1);
  1296. }
  1297. *new_base_ts = ktime_to_timespec64(new_base_time);
  1298. }
  1299. static u32 vsc9959_tas_read_cfg_status(struct ocelot *ocelot)
  1300. {
  1301. return ocelot_read(ocelot, QSYS_TAS_PARAM_CFG_CTRL);
  1302. }
  1303. static void vsc9959_tas_gcl_set(struct ocelot *ocelot, const u32 gcl_ix,
  1304. struct tc_taprio_sched_entry *entry)
  1305. {
  1306. ocelot_write(ocelot,
  1307. QSYS_GCL_CFG_REG_1_GCL_ENTRY_NUM(gcl_ix) |
  1308. QSYS_GCL_CFG_REG_1_GATE_STATE(entry->gate_mask),
  1309. QSYS_GCL_CFG_REG_1);
  1310. ocelot_write(ocelot, entry->interval, QSYS_GCL_CFG_REG_2);
  1311. }
  1312. static int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port,
  1313. struct tc_taprio_qopt_offload *taprio)
  1314. {
  1315. struct ocelot_port *ocelot_port = ocelot->ports[port];
  1316. struct timespec64 base_ts;
  1317. int ret, i;
  1318. u32 val;
  1319. mutex_lock(&ocelot->fwd_domain_lock);
  1320. if (taprio->cmd == TAPRIO_CMD_DESTROY) {
  1321. ocelot_port_mqprio(ocelot, port, &taprio->mqprio);
  1322. ocelot_rmw_rix(ocelot, 0, QSYS_TAG_CONFIG_ENABLE,
  1323. QSYS_TAG_CONFIG, port);
  1324. taprio_offload_free(ocelot_port->taprio);
  1325. ocelot_port->taprio = NULL;
  1326. vsc9959_tas_guard_bands_update(ocelot, port);
  1327. mutex_unlock(&ocelot->fwd_domain_lock);
  1328. return 0;
  1329. } else if (taprio->cmd != TAPRIO_CMD_REPLACE) {
  1330. ret = -EOPNOTSUPP;
  1331. goto err_unlock;
  1332. }
  1333. ret = ocelot_port_mqprio(ocelot, port, &taprio->mqprio);
  1334. if (ret)
  1335. goto err_unlock;
  1336. if (taprio->cycle_time > NSEC_PER_SEC ||
  1337. taprio->cycle_time_extension >= NSEC_PER_SEC) {
  1338. ret = -EINVAL;
  1339. goto err_reset_tc;
  1340. }
  1341. if (taprio->num_entries > VSC9959_TAS_GCL_ENTRY_MAX) {
  1342. ret = -ERANGE;
  1343. goto err_reset_tc;
  1344. }
  1345. /* Enable guard band. The switch will schedule frames without taking
  1346. * their length into account. Thus we'll always need to enable the
  1347. * guard band which reserves the time of a maximum sized frame at the
  1348. * end of the time window.
  1349. *
  1350. * Although the ALWAYS_GUARD_BAND_SCH_Q bit is global for all ports, we
  1351. * need to set PORT_NUM, because subsequent writes to PARAM_CFG_REG_n
  1352. * operate on the port number.
  1353. */
  1354. ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM(port) |
  1355. QSYS_TAS_PARAM_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q,
  1356. QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM_M |
  1357. QSYS_TAS_PARAM_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q,
  1358. QSYS_TAS_PARAM_CFG_CTRL);
  1359. /* Hardware errata - Admin config could not be overwritten if
  1360. * config is pending, need reset the TAS module
  1361. */
  1362. val = ocelot_read_rix(ocelot, QSYS_TAG_CONFIG, port);
  1363. if (val & QSYS_TAG_CONFIG_ENABLE) {
  1364. val = ocelot_read(ocelot, QSYS_PARAM_STATUS_REG_8);
  1365. if (val & QSYS_PARAM_STATUS_REG_8_CONFIG_PENDING) {
  1366. ret = -EBUSY;
  1367. goto err_reset_tc;
  1368. }
  1369. }
  1370. ocelot_rmw_rix(ocelot,
  1371. QSYS_TAG_CONFIG_ENABLE |
  1372. QSYS_TAG_CONFIG_INIT_GATE_STATE(0xFF) |
  1373. QSYS_TAG_CONFIG_SCH_TRAFFIC_QUEUES(0xFF),
  1374. QSYS_TAG_CONFIG_ENABLE |
  1375. QSYS_TAG_CONFIG_INIT_GATE_STATE_M |
  1376. QSYS_TAG_CONFIG_SCH_TRAFFIC_QUEUES_M,
  1377. QSYS_TAG_CONFIG, port);
  1378. vsc9959_new_base_time(ocelot, taprio->base_time,
  1379. taprio->cycle_time, &base_ts);
  1380. ocelot_write(ocelot, base_ts.tv_nsec, QSYS_PARAM_CFG_REG_1);
  1381. ocelot_write(ocelot, lower_32_bits(base_ts.tv_sec), QSYS_PARAM_CFG_REG_2);
  1382. val = upper_32_bits(base_ts.tv_sec);
  1383. ocelot_write(ocelot,
  1384. QSYS_PARAM_CFG_REG_3_BASE_TIME_SEC_MSB(val) |
  1385. QSYS_PARAM_CFG_REG_3_LIST_LENGTH(taprio->num_entries),
  1386. QSYS_PARAM_CFG_REG_3);
  1387. ocelot_write(ocelot, taprio->cycle_time, QSYS_PARAM_CFG_REG_4);
  1388. ocelot_write(ocelot, taprio->cycle_time_extension, QSYS_PARAM_CFG_REG_5);
  1389. for (i = 0; i < taprio->num_entries; i++)
  1390. vsc9959_tas_gcl_set(ocelot, i, &taprio->entries[i]);
  1391. ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
  1392. QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
  1393. QSYS_TAS_PARAM_CFG_CTRL);
  1394. ret = readx_poll_timeout(vsc9959_tas_read_cfg_status, ocelot, val,
  1395. !(val & QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE),
  1396. 10, 100000);
  1397. if (ret)
  1398. goto err_reset_tc;
  1399. ocelot_port->taprio = taprio_offload_get(taprio);
  1400. vsc9959_tas_guard_bands_update(ocelot, port);
  1401. mutex_unlock(&ocelot->fwd_domain_lock);
  1402. return 0;
  1403. err_reset_tc:
  1404. taprio->mqprio.qopt.num_tc = 0;
  1405. ocelot_port_mqprio(ocelot, port, &taprio->mqprio);
  1406. err_unlock:
  1407. mutex_unlock(&ocelot->fwd_domain_lock);
  1408. return ret;
  1409. }
  1410. static void vsc9959_tas_clock_adjust(struct ocelot *ocelot)
  1411. {
  1412. struct tc_taprio_qopt_offload *taprio;
  1413. struct ocelot_port *ocelot_port;
  1414. struct timespec64 base_ts;
  1415. int i, port;
  1416. u32 val;
  1417. mutex_lock(&ocelot->fwd_domain_lock);
  1418. for (port = 0; port < ocelot->num_phys_ports; port++) {
  1419. ocelot_port = ocelot->ports[port];
  1420. taprio = ocelot_port->taprio;
  1421. if (!taprio)
  1422. continue;
  1423. ocelot_rmw(ocelot,
  1424. QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM(port),
  1425. QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM_M,
  1426. QSYS_TAS_PARAM_CFG_CTRL);
  1427. /* Disable time-aware shaper */
  1428. ocelot_rmw_rix(ocelot, 0, QSYS_TAG_CONFIG_ENABLE,
  1429. QSYS_TAG_CONFIG, port);
  1430. vsc9959_new_base_time(ocelot, taprio->base_time,
  1431. taprio->cycle_time, &base_ts);
  1432. ocelot_write(ocelot, base_ts.tv_nsec, QSYS_PARAM_CFG_REG_1);
  1433. ocelot_write(ocelot, lower_32_bits(base_ts.tv_sec),
  1434. QSYS_PARAM_CFG_REG_2);
  1435. val = upper_32_bits(base_ts.tv_sec);
  1436. ocelot_rmw(ocelot,
  1437. QSYS_PARAM_CFG_REG_3_BASE_TIME_SEC_MSB(val),
  1438. QSYS_PARAM_CFG_REG_3_BASE_TIME_SEC_MSB_M,
  1439. QSYS_PARAM_CFG_REG_3);
  1440. for (i = 0; i < taprio->num_entries; i++)
  1441. vsc9959_tas_gcl_set(ocelot, i, &taprio->entries[i]);
  1442. ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
  1443. QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
  1444. QSYS_TAS_PARAM_CFG_CTRL);
  1445. /* Re-enable time-aware shaper */
  1446. ocelot_rmw_rix(ocelot, QSYS_TAG_CONFIG_ENABLE,
  1447. QSYS_TAG_CONFIG_ENABLE,
  1448. QSYS_TAG_CONFIG, port);
  1449. }
  1450. mutex_unlock(&ocelot->fwd_domain_lock);
  1451. }
  1452. static int vsc9959_qos_port_cbs_set(struct dsa_switch *ds, int port,
  1453. struct tc_cbs_qopt_offload *cbs_qopt)
  1454. {
  1455. struct ocelot *ocelot = ds->priv;
  1456. int port_ix = port * 8 + cbs_qopt->queue;
  1457. u32 rate, burst;
  1458. if (cbs_qopt->queue >= ds->num_tx_queues)
  1459. return -EINVAL;
  1460. if (!cbs_qopt->enable) {
  1461. ocelot_write_gix(ocelot, QSYS_CIR_CFG_CIR_RATE(0) |
  1462. QSYS_CIR_CFG_CIR_BURST(0),
  1463. QSYS_CIR_CFG, port_ix);
  1464. ocelot_rmw_gix(ocelot, 0, QSYS_SE_CFG_SE_AVB_ENA,
  1465. QSYS_SE_CFG, port_ix);
  1466. return 0;
  1467. }
  1468. /* Rate unit is 100 kbps */
  1469. rate = DIV_ROUND_UP(cbs_qopt->idleslope, 100);
  1470. /* Avoid using zero rate */
  1471. rate = clamp_t(u32, rate, 1, GENMASK(14, 0));
  1472. /* Burst unit is 4kB */
  1473. burst = DIV_ROUND_UP(cbs_qopt->hicredit, 4096);
  1474. /* Avoid using zero burst size */
  1475. burst = clamp_t(u32, burst, 1, GENMASK(5, 0));
  1476. ocelot_write_gix(ocelot,
  1477. QSYS_CIR_CFG_CIR_RATE(rate) |
  1478. QSYS_CIR_CFG_CIR_BURST(burst),
  1479. QSYS_CIR_CFG,
  1480. port_ix);
  1481. ocelot_rmw_gix(ocelot,
  1482. QSYS_SE_CFG_SE_FRM_MODE(0) |
  1483. QSYS_SE_CFG_SE_AVB_ENA,
  1484. QSYS_SE_CFG_SE_AVB_ENA |
  1485. QSYS_SE_CFG_SE_FRM_MODE_M,
  1486. QSYS_SE_CFG,
  1487. port_ix);
  1488. return 0;
  1489. }
  1490. static int vsc9959_qos_query_caps(struct tc_query_caps_base *base)
  1491. {
  1492. switch (base->type) {
  1493. case TC_SETUP_QDISC_MQPRIO: {
  1494. struct tc_mqprio_caps *caps = base->caps;
  1495. caps->validate_queue_counts = true;
  1496. return 0;
  1497. }
  1498. case TC_SETUP_QDISC_TAPRIO: {
  1499. struct tc_taprio_caps *caps = base->caps;
  1500. caps->supports_queue_max_sdu = true;
  1501. return 0;
  1502. }
  1503. default:
  1504. return -EOPNOTSUPP;
  1505. }
  1506. }
  1507. static int vsc9959_qos_port_mqprio(struct ocelot *ocelot, int port,
  1508. struct tc_mqprio_qopt_offload *mqprio)
  1509. {
  1510. int ret;
  1511. mutex_lock(&ocelot->fwd_domain_lock);
  1512. ret = ocelot_port_mqprio(ocelot, port, mqprio);
  1513. mutex_unlock(&ocelot->fwd_domain_lock);
  1514. return ret;
  1515. }
  1516. static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,
  1517. enum tc_setup_type type,
  1518. void *type_data)
  1519. {
  1520. struct ocelot *ocelot = ds->priv;
  1521. switch (type) {
  1522. case TC_QUERY_CAPS:
  1523. return vsc9959_qos_query_caps(type_data);
  1524. case TC_SETUP_QDISC_TAPRIO:
  1525. return vsc9959_qos_port_tas_set(ocelot, port, type_data);
  1526. case TC_SETUP_QDISC_MQPRIO:
  1527. return vsc9959_qos_port_mqprio(ocelot, port, type_data);
  1528. case TC_SETUP_QDISC_CBS:
  1529. return vsc9959_qos_port_cbs_set(ds, port, type_data);
  1530. default:
  1531. return -EOPNOTSUPP;
  1532. }
  1533. }
  1534. #define VSC9959_PSFP_SFID_MAX 175
  1535. #define VSC9959_PSFP_GATE_ID_MAX 183
  1536. #define VSC9959_PSFP_POLICER_BASE 63
  1537. #define VSC9959_PSFP_POLICER_MAX 383
  1538. #define VSC9959_PSFP_GATE_LIST_NUM 4
  1539. #define VSC9959_PSFP_GATE_CYCLETIME_MIN 5000
  1540. struct felix_stream {
  1541. struct list_head list;
  1542. unsigned long id;
  1543. bool dummy;
  1544. int ports;
  1545. int port;
  1546. u8 dmac[ETH_ALEN];
  1547. u16 vid;
  1548. s8 prio;
  1549. u8 sfid_valid;
  1550. u8 ssid_valid;
  1551. u32 sfid;
  1552. u32 ssid;
  1553. };
  1554. struct felix_stream_filter_counters {
  1555. u64 match;
  1556. u64 not_pass_gate;
  1557. u64 not_pass_sdu;
  1558. u64 red;
  1559. };
  1560. struct felix_stream_filter {
  1561. struct felix_stream_filter_counters stats;
  1562. struct list_head list;
  1563. refcount_t refcount;
  1564. u32 index;
  1565. u8 enable;
  1566. int portmask;
  1567. u8 sg_valid;
  1568. u32 sgid;
  1569. u8 fm_valid;
  1570. u32 fmid;
  1571. u8 prio_valid;
  1572. u8 prio;
  1573. u32 maxsdu;
  1574. };
  1575. struct felix_stream_gate {
  1576. u32 index;
  1577. u8 enable;
  1578. u8 ipv_valid;
  1579. u8 init_ipv;
  1580. u64 basetime;
  1581. u64 cycletime;
  1582. u64 cycletime_ext;
  1583. u32 num_entries;
  1584. struct action_gate_entry entries[] __counted_by(num_entries);
  1585. };
  1586. struct felix_stream_gate_entry {
  1587. struct list_head list;
  1588. refcount_t refcount;
  1589. u32 index;
  1590. };
  1591. static int vsc9959_stream_identify(struct flow_cls_offload *f,
  1592. struct felix_stream *stream)
  1593. {
  1594. struct flow_rule *rule = flow_cls_offload_flow_rule(f);
  1595. struct flow_dissector *dissector = rule->match.dissector;
  1596. if (dissector->used_keys &
  1597. ~(BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) |
  1598. BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) |
  1599. BIT_ULL(FLOW_DISSECTOR_KEY_VLAN) |
  1600. BIT_ULL(FLOW_DISSECTOR_KEY_ETH_ADDRS)))
  1601. return -EOPNOTSUPP;
  1602. if (flow_rule_match_has_control_flags(rule, f->common.extack))
  1603. return -EOPNOTSUPP;
  1604. if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  1605. struct flow_match_eth_addrs match;
  1606. flow_rule_match_eth_addrs(rule, &match);
  1607. ether_addr_copy(stream->dmac, match.key->dst);
  1608. if (!is_zero_ether_addr(match.mask->src))
  1609. return -EOPNOTSUPP;
  1610. } else {
  1611. return -EOPNOTSUPP;
  1612. }
  1613. if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
  1614. struct flow_match_vlan match;
  1615. flow_rule_match_vlan(rule, &match);
  1616. if (match.mask->vlan_priority)
  1617. stream->prio = match.key->vlan_priority;
  1618. else
  1619. stream->prio = -1;
  1620. if (!match.mask->vlan_id)
  1621. return -EOPNOTSUPP;
  1622. stream->vid = match.key->vlan_id;
  1623. } else {
  1624. return -EOPNOTSUPP;
  1625. }
  1626. stream->id = f->cookie;
  1627. return 0;
  1628. }
  1629. static int vsc9959_mact_stream_set(struct ocelot *ocelot,
  1630. struct felix_stream *stream,
  1631. struct netlink_ext_ack *extack)
  1632. {
  1633. enum macaccess_entry_type type;
  1634. int ret, sfid, ssid;
  1635. u32 vid, dst_idx;
  1636. u8 mac[ETH_ALEN];
  1637. ether_addr_copy(mac, stream->dmac);
  1638. vid = stream->vid;
  1639. /* Stream identification desn't support to add a stream with non
  1640. * existent MAC (The MAC entry has not been learned in MAC table).
  1641. */
  1642. ret = ocelot_mact_lookup(ocelot, &dst_idx, mac, vid, &type);
  1643. if (ret) {
  1644. if (extack)
  1645. NL_SET_ERR_MSG_MOD(extack, "Stream is not learned in MAC table");
  1646. return -EOPNOTSUPP;
  1647. }
  1648. if ((stream->sfid_valid || stream->ssid_valid) &&
  1649. type == ENTRYTYPE_NORMAL)
  1650. type = ENTRYTYPE_LOCKED;
  1651. sfid = stream->sfid_valid ? stream->sfid : -1;
  1652. ssid = stream->ssid_valid ? stream->ssid : -1;
  1653. ret = ocelot_mact_learn_streamdata(ocelot, dst_idx, mac, vid, type,
  1654. sfid, ssid);
  1655. return ret;
  1656. }
  1657. static struct felix_stream *
  1658. vsc9959_stream_table_lookup(struct list_head *stream_list,
  1659. struct felix_stream *stream)
  1660. {
  1661. struct felix_stream *tmp;
  1662. list_for_each_entry(tmp, stream_list, list)
  1663. if (ether_addr_equal(tmp->dmac, stream->dmac) &&
  1664. tmp->vid == stream->vid)
  1665. return tmp;
  1666. return NULL;
  1667. }
  1668. static int vsc9959_stream_table_add(struct ocelot *ocelot,
  1669. struct list_head *stream_list,
  1670. struct felix_stream *stream,
  1671. struct netlink_ext_ack *extack)
  1672. {
  1673. struct felix_stream *stream_entry;
  1674. int ret;
  1675. stream_entry = kmemdup(stream, sizeof(*stream_entry), GFP_KERNEL);
  1676. if (!stream_entry)
  1677. return -ENOMEM;
  1678. if (!stream->dummy) {
  1679. ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack);
  1680. if (ret) {
  1681. kfree(stream_entry);
  1682. return ret;
  1683. }
  1684. }
  1685. list_add_tail(&stream_entry->list, stream_list);
  1686. return 0;
  1687. }
  1688. static struct felix_stream *
  1689. vsc9959_stream_table_get(struct list_head *stream_list, unsigned long id)
  1690. {
  1691. struct felix_stream *tmp;
  1692. list_for_each_entry(tmp, stream_list, list)
  1693. if (tmp->id == id)
  1694. return tmp;
  1695. return NULL;
  1696. }
  1697. static void vsc9959_stream_table_del(struct ocelot *ocelot,
  1698. struct felix_stream *stream)
  1699. {
  1700. if (!stream->dummy)
  1701. vsc9959_mact_stream_set(ocelot, stream, NULL);
  1702. list_del(&stream->list);
  1703. kfree(stream);
  1704. }
  1705. static u32 vsc9959_sfi_access_status(struct ocelot *ocelot)
  1706. {
  1707. return ocelot_read(ocelot, ANA_TABLES_SFIDACCESS);
  1708. }
  1709. static int vsc9959_psfp_sfi_set(struct ocelot *ocelot,
  1710. struct felix_stream_filter *sfi)
  1711. {
  1712. u32 val;
  1713. if (sfi->index > VSC9959_PSFP_SFID_MAX)
  1714. return -EINVAL;
  1715. if (!sfi->enable) {
  1716. ocelot_write(ocelot, ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index),
  1717. ANA_TABLES_SFIDTIDX);
  1718. val = ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(SFIDACCESS_CMD_WRITE);
  1719. ocelot_write(ocelot, val, ANA_TABLES_SFIDACCESS);
  1720. return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val,
  1721. (!ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(val)),
  1722. 10, 100000);
  1723. }
  1724. if (sfi->sgid > VSC9959_PSFP_GATE_ID_MAX ||
  1725. sfi->fmid > VSC9959_PSFP_POLICER_MAX)
  1726. return -EINVAL;
  1727. ocelot_write(ocelot,
  1728. (sfi->sg_valid ? ANA_TABLES_SFIDTIDX_SGID_VALID : 0) |
  1729. ANA_TABLES_SFIDTIDX_SGID(sfi->sgid) |
  1730. (sfi->fm_valid ? ANA_TABLES_SFIDTIDX_POL_ENA : 0) |
  1731. ANA_TABLES_SFIDTIDX_POL_IDX(sfi->fmid) |
  1732. ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index),
  1733. ANA_TABLES_SFIDTIDX);
  1734. ocelot_write(ocelot,
  1735. (sfi->prio_valid ? ANA_TABLES_SFIDACCESS_IGR_PRIO_MATCH_ENA : 0) |
  1736. ANA_TABLES_SFIDACCESS_IGR_PRIO(sfi->prio) |
  1737. ANA_TABLES_SFIDACCESS_MAX_SDU_LEN(sfi->maxsdu) |
  1738. ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(SFIDACCESS_CMD_WRITE),
  1739. ANA_TABLES_SFIDACCESS);
  1740. return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val,
  1741. (!ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(val)),
  1742. 10, 100000);
  1743. }
  1744. static int vsc9959_psfp_sfidmask_set(struct ocelot *ocelot, u32 sfid, int ports)
  1745. {
  1746. u32 val;
  1747. ocelot_rmw(ocelot,
  1748. ANA_TABLES_SFIDTIDX_SFID_INDEX(sfid),
  1749. ANA_TABLES_SFIDTIDX_SFID_INDEX_M,
  1750. ANA_TABLES_SFIDTIDX);
  1751. ocelot_write(ocelot,
  1752. ANA_TABLES_SFID_MASK_IGR_PORT_MASK(ports) |
  1753. ANA_TABLES_SFID_MASK_IGR_SRCPORT_MATCH_ENA,
  1754. ANA_TABLES_SFID_MASK);
  1755. ocelot_rmw(ocelot,
  1756. ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(SFIDACCESS_CMD_WRITE),
  1757. ANA_TABLES_SFIDACCESS_SFID_TBL_CMD_M,
  1758. ANA_TABLES_SFIDACCESS);
  1759. return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val,
  1760. (!ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(val)),
  1761. 10, 100000);
  1762. }
  1763. static int vsc9959_psfp_sfi_list_add(struct ocelot *ocelot,
  1764. struct felix_stream_filter *sfi,
  1765. struct list_head *pos)
  1766. {
  1767. struct felix_stream_filter *sfi_entry;
  1768. int ret;
  1769. sfi_entry = kmemdup(sfi, sizeof(*sfi_entry), GFP_KERNEL);
  1770. if (!sfi_entry)
  1771. return -ENOMEM;
  1772. refcount_set(&sfi_entry->refcount, 1);
  1773. ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry);
  1774. if (ret) {
  1775. kfree(sfi_entry);
  1776. return ret;
  1777. }
  1778. vsc9959_psfp_sfidmask_set(ocelot, sfi->index, sfi->portmask);
  1779. list_add(&sfi_entry->list, pos);
  1780. return 0;
  1781. }
  1782. static int vsc9959_psfp_sfi_table_add(struct ocelot *ocelot,
  1783. struct felix_stream_filter *sfi)
  1784. {
  1785. struct list_head *pos, *q, *last;
  1786. struct felix_stream_filter *tmp;
  1787. struct ocelot_psfp_list *psfp;
  1788. u32 insert = 0;
  1789. psfp = &ocelot->psfp;
  1790. last = &psfp->sfi_list;
  1791. list_for_each_safe(pos, q, &psfp->sfi_list) {
  1792. tmp = list_entry(pos, struct felix_stream_filter, list);
  1793. if (sfi->sg_valid == tmp->sg_valid &&
  1794. sfi->fm_valid == tmp->fm_valid &&
  1795. sfi->portmask == tmp->portmask &&
  1796. tmp->sgid == sfi->sgid &&
  1797. tmp->fmid == sfi->fmid) {
  1798. sfi->index = tmp->index;
  1799. refcount_inc(&tmp->refcount);
  1800. return 0;
  1801. }
  1802. /* Make sure that the index is increasing in order. */
  1803. if (tmp->index == insert) {
  1804. last = pos;
  1805. insert++;
  1806. }
  1807. }
  1808. sfi->index = insert;
  1809. return vsc9959_psfp_sfi_list_add(ocelot, sfi, last);
  1810. }
  1811. static int vsc9959_psfp_sfi_table_add2(struct ocelot *ocelot,
  1812. struct felix_stream_filter *sfi,
  1813. struct felix_stream_filter *sfi2)
  1814. {
  1815. struct felix_stream_filter *tmp;
  1816. struct list_head *pos, *q, *last;
  1817. struct ocelot_psfp_list *psfp;
  1818. u32 insert = 0;
  1819. int ret;
  1820. psfp = &ocelot->psfp;
  1821. last = &psfp->sfi_list;
  1822. list_for_each_safe(pos, q, &psfp->sfi_list) {
  1823. tmp = list_entry(pos, struct felix_stream_filter, list);
  1824. /* Make sure that the index is increasing in order. */
  1825. if (tmp->index >= insert + 2)
  1826. break;
  1827. insert = tmp->index + 1;
  1828. last = pos;
  1829. }
  1830. sfi->index = insert;
  1831. ret = vsc9959_psfp_sfi_list_add(ocelot, sfi, last);
  1832. if (ret)
  1833. return ret;
  1834. sfi2->index = insert + 1;
  1835. return vsc9959_psfp_sfi_list_add(ocelot, sfi2, last->next);
  1836. }
  1837. static struct felix_stream_filter *
  1838. vsc9959_psfp_sfi_table_get(struct list_head *sfi_list, u32 index)
  1839. {
  1840. struct felix_stream_filter *tmp;
  1841. list_for_each_entry(tmp, sfi_list, list)
  1842. if (tmp->index == index)
  1843. return tmp;
  1844. return NULL;
  1845. }
  1846. static void vsc9959_psfp_sfi_table_del(struct ocelot *ocelot, u32 index)
  1847. {
  1848. struct felix_stream_filter *tmp, *n;
  1849. struct ocelot_psfp_list *psfp;
  1850. u8 z;
  1851. psfp = &ocelot->psfp;
  1852. list_for_each_entry_safe(tmp, n, &psfp->sfi_list, list)
  1853. if (tmp->index == index) {
  1854. z = refcount_dec_and_test(&tmp->refcount);
  1855. if (z) {
  1856. tmp->enable = 0;
  1857. vsc9959_psfp_sfi_set(ocelot, tmp);
  1858. list_del(&tmp->list);
  1859. kfree(tmp);
  1860. }
  1861. break;
  1862. }
  1863. }
  1864. static void vsc9959_psfp_parse_gate(const struct flow_action_entry *entry,
  1865. struct felix_stream_gate *sgi)
  1866. {
  1867. sgi->index = entry->hw_index;
  1868. sgi->ipv_valid = (entry->gate.prio < 0) ? 0 : 1;
  1869. sgi->init_ipv = (sgi->ipv_valid) ? entry->gate.prio : 0;
  1870. sgi->basetime = entry->gate.basetime;
  1871. sgi->cycletime = entry->gate.cycletime;
  1872. sgi->num_entries = entry->gate.num_entries;
  1873. sgi->enable = 1;
  1874. memcpy(sgi->entries, entry->gate.entries,
  1875. entry->gate.num_entries * sizeof(struct action_gate_entry));
  1876. }
  1877. static u32 vsc9959_sgi_cfg_status(struct ocelot *ocelot)
  1878. {
  1879. return ocelot_read(ocelot, ANA_SG_ACCESS_CTRL);
  1880. }
  1881. static int vsc9959_psfp_sgi_set(struct ocelot *ocelot,
  1882. struct felix_stream_gate *sgi)
  1883. {
  1884. struct action_gate_entry *e;
  1885. struct timespec64 base_ts;
  1886. u32 interval_sum = 0;
  1887. u32 val;
  1888. int i;
  1889. if (sgi->index > VSC9959_PSFP_GATE_ID_MAX)
  1890. return -EINVAL;
  1891. ocelot_write(ocelot, ANA_SG_ACCESS_CTRL_SGID(sgi->index),
  1892. ANA_SG_ACCESS_CTRL);
  1893. if (!sgi->enable) {
  1894. ocelot_rmw(ocelot, ANA_SG_CONFIG_REG_3_INIT_GATE_STATE,
  1895. ANA_SG_CONFIG_REG_3_INIT_GATE_STATE |
  1896. ANA_SG_CONFIG_REG_3_GATE_ENABLE,
  1897. ANA_SG_CONFIG_REG_3);
  1898. return 0;
  1899. }
  1900. if (sgi->cycletime < VSC9959_PSFP_GATE_CYCLETIME_MIN ||
  1901. sgi->cycletime > NSEC_PER_SEC)
  1902. return -EINVAL;
  1903. if (sgi->num_entries > VSC9959_PSFP_GATE_LIST_NUM)
  1904. return -EINVAL;
  1905. vsc9959_new_base_time(ocelot, sgi->basetime, sgi->cycletime, &base_ts);
  1906. ocelot_write(ocelot, base_ts.tv_nsec, ANA_SG_CONFIG_REG_1);
  1907. val = lower_32_bits(base_ts.tv_sec);
  1908. ocelot_write(ocelot, val, ANA_SG_CONFIG_REG_2);
  1909. val = upper_32_bits(base_ts.tv_sec);
  1910. ocelot_write(ocelot,
  1911. (sgi->ipv_valid ? ANA_SG_CONFIG_REG_3_IPV_VALID : 0) |
  1912. ANA_SG_CONFIG_REG_3_INIT_IPV(sgi->init_ipv) |
  1913. ANA_SG_CONFIG_REG_3_GATE_ENABLE |
  1914. ANA_SG_CONFIG_REG_3_LIST_LENGTH(sgi->num_entries) |
  1915. ANA_SG_CONFIG_REG_3_INIT_GATE_STATE |
  1916. ANA_SG_CONFIG_REG_3_BASE_TIME_SEC_MSB(val),
  1917. ANA_SG_CONFIG_REG_3);
  1918. ocelot_write(ocelot, sgi->cycletime, ANA_SG_CONFIG_REG_4);
  1919. e = sgi->entries;
  1920. for (i = 0; i < sgi->num_entries; i++) {
  1921. u32 ips = (e[i].ipv < 0) ? 0 : (e[i].ipv + 8);
  1922. ocelot_write_rix(ocelot, ANA_SG_GCL_GS_CONFIG_IPS(ips) |
  1923. (e[i].gate_state ?
  1924. ANA_SG_GCL_GS_CONFIG_GATE_STATE : 0),
  1925. ANA_SG_GCL_GS_CONFIG, i);
  1926. interval_sum += e[i].interval;
  1927. ocelot_write_rix(ocelot, interval_sum, ANA_SG_GCL_TI_CONFIG, i);
  1928. }
  1929. ocelot_rmw(ocelot, ANA_SG_ACCESS_CTRL_CONFIG_CHANGE,
  1930. ANA_SG_ACCESS_CTRL_CONFIG_CHANGE,
  1931. ANA_SG_ACCESS_CTRL);
  1932. return readx_poll_timeout(vsc9959_sgi_cfg_status, ocelot, val,
  1933. (!(ANA_SG_ACCESS_CTRL_CONFIG_CHANGE & val)),
  1934. 10, 100000);
  1935. }
  1936. static int vsc9959_psfp_sgi_table_add(struct ocelot *ocelot,
  1937. struct felix_stream_gate *sgi)
  1938. {
  1939. struct felix_stream_gate_entry *tmp;
  1940. struct ocelot_psfp_list *psfp;
  1941. int ret;
  1942. psfp = &ocelot->psfp;
  1943. list_for_each_entry(tmp, &psfp->sgi_list, list)
  1944. if (tmp->index == sgi->index) {
  1945. refcount_inc(&tmp->refcount);
  1946. return 0;
  1947. }
  1948. tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
  1949. if (!tmp)
  1950. return -ENOMEM;
  1951. ret = vsc9959_psfp_sgi_set(ocelot, sgi);
  1952. if (ret) {
  1953. kfree(tmp);
  1954. return ret;
  1955. }
  1956. tmp->index = sgi->index;
  1957. refcount_set(&tmp->refcount, 1);
  1958. list_add_tail(&tmp->list, &psfp->sgi_list);
  1959. return 0;
  1960. }
  1961. static void vsc9959_psfp_sgi_table_del(struct ocelot *ocelot,
  1962. u32 index)
  1963. {
  1964. struct felix_stream_gate_entry *tmp, *n;
  1965. struct felix_stream_gate sgi = {0};
  1966. struct ocelot_psfp_list *psfp;
  1967. u8 z;
  1968. psfp = &ocelot->psfp;
  1969. list_for_each_entry_safe(tmp, n, &psfp->sgi_list, list)
  1970. if (tmp->index == index) {
  1971. z = refcount_dec_and_test(&tmp->refcount);
  1972. if (z) {
  1973. sgi.index = index;
  1974. sgi.enable = 0;
  1975. vsc9959_psfp_sgi_set(ocelot, &sgi);
  1976. list_del(&tmp->list);
  1977. kfree(tmp);
  1978. }
  1979. break;
  1980. }
  1981. }
  1982. static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port,
  1983. struct flow_cls_offload *f)
  1984. {
  1985. struct netlink_ext_ack *extack = f->common.extack;
  1986. struct felix_stream_filter old_sfi, *sfi_entry;
  1987. struct felix_stream_filter sfi = {0};
  1988. const struct flow_action_entry *a;
  1989. struct felix_stream *stream_entry;
  1990. struct felix_stream stream = {0};
  1991. struct felix_stream_gate *sgi;
  1992. struct ocelot_psfp_list *psfp;
  1993. struct ocelot_policer pol;
  1994. int ret, i, size;
  1995. u64 rate, burst;
  1996. u32 index;
  1997. psfp = &ocelot->psfp;
  1998. ret = vsc9959_stream_identify(f, &stream);
  1999. if (ret) {
  2000. NL_SET_ERR_MSG_MOD(extack, "Only can match on VID, PCP, and dest MAC");
  2001. return ret;
  2002. }
  2003. mutex_lock(&psfp->lock);
  2004. flow_action_for_each(i, a, &f->rule->action) {
  2005. switch (a->id) {
  2006. case FLOW_ACTION_GATE:
  2007. size = struct_size(sgi, entries, a->gate.num_entries);
  2008. sgi = kzalloc(size, GFP_KERNEL);
  2009. if (!sgi) {
  2010. ret = -ENOMEM;
  2011. goto err;
  2012. }
  2013. vsc9959_psfp_parse_gate(a, sgi);
  2014. ret = vsc9959_psfp_sgi_table_add(ocelot, sgi);
  2015. if (ret) {
  2016. kfree(sgi);
  2017. goto err;
  2018. }
  2019. sfi.sg_valid = 1;
  2020. sfi.sgid = sgi->index;
  2021. kfree(sgi);
  2022. break;
  2023. case FLOW_ACTION_POLICE:
  2024. index = a->hw_index + VSC9959_PSFP_POLICER_BASE;
  2025. if (index > VSC9959_PSFP_POLICER_MAX) {
  2026. ret = -EINVAL;
  2027. goto err;
  2028. }
  2029. rate = a->police.rate_bytes_ps;
  2030. burst = rate * PSCHED_NS2TICKS(a->police.burst);
  2031. pol = (struct ocelot_policer) {
  2032. .burst = div_u64(burst, PSCHED_TICKS_PER_SEC),
  2033. .rate = div_u64(rate, 1000) * 8,
  2034. };
  2035. ret = ocelot_vcap_policer_add(ocelot, index, &pol);
  2036. if (ret)
  2037. goto err;
  2038. sfi.fm_valid = 1;
  2039. sfi.fmid = index;
  2040. sfi.maxsdu = a->police.mtu;
  2041. break;
  2042. default:
  2043. mutex_unlock(&psfp->lock);
  2044. return -EOPNOTSUPP;
  2045. }
  2046. }
  2047. stream.ports = BIT(port);
  2048. stream.port = port;
  2049. sfi.portmask = stream.ports;
  2050. sfi.prio_valid = (stream.prio < 0 ? 0 : 1);
  2051. sfi.prio = (sfi.prio_valid ? stream.prio : 0);
  2052. sfi.enable = 1;
  2053. /* Check if stream is set. */
  2054. stream_entry = vsc9959_stream_table_lookup(&psfp->stream_list, &stream);
  2055. if (stream_entry) {
  2056. if (stream_entry->ports & BIT(port)) {
  2057. NL_SET_ERR_MSG_MOD(extack,
  2058. "The stream is added on this port");
  2059. ret = -EEXIST;
  2060. goto err;
  2061. }
  2062. if (stream_entry->ports != BIT(stream_entry->port)) {
  2063. NL_SET_ERR_MSG_MOD(extack,
  2064. "The stream is added on two ports");
  2065. ret = -EEXIST;
  2066. goto err;
  2067. }
  2068. stream_entry->ports |= BIT(port);
  2069. stream.ports = stream_entry->ports;
  2070. sfi_entry = vsc9959_psfp_sfi_table_get(&psfp->sfi_list,
  2071. stream_entry->sfid);
  2072. memcpy(&old_sfi, sfi_entry, sizeof(old_sfi));
  2073. vsc9959_psfp_sfi_table_del(ocelot, stream_entry->sfid);
  2074. old_sfi.portmask = stream_entry->ports;
  2075. sfi.portmask = stream.ports;
  2076. if (stream_entry->port > port) {
  2077. ret = vsc9959_psfp_sfi_table_add2(ocelot, &sfi,
  2078. &old_sfi);
  2079. stream_entry->dummy = true;
  2080. } else {
  2081. ret = vsc9959_psfp_sfi_table_add2(ocelot, &old_sfi,
  2082. &sfi);
  2083. stream.dummy = true;
  2084. }
  2085. if (ret)
  2086. goto err;
  2087. stream_entry->sfid = old_sfi.index;
  2088. } else {
  2089. ret = vsc9959_psfp_sfi_table_add(ocelot, &sfi);
  2090. if (ret)
  2091. goto err;
  2092. }
  2093. stream.sfid = sfi.index;
  2094. stream.sfid_valid = 1;
  2095. ret = vsc9959_stream_table_add(ocelot, &psfp->stream_list,
  2096. &stream, extack);
  2097. if (ret) {
  2098. vsc9959_psfp_sfi_table_del(ocelot, stream.sfid);
  2099. goto err;
  2100. }
  2101. mutex_unlock(&psfp->lock);
  2102. return 0;
  2103. err:
  2104. if (sfi.sg_valid)
  2105. vsc9959_psfp_sgi_table_del(ocelot, sfi.sgid);
  2106. if (sfi.fm_valid)
  2107. ocelot_vcap_policer_del(ocelot, sfi.fmid);
  2108. mutex_unlock(&psfp->lock);
  2109. return ret;
  2110. }
  2111. static int vsc9959_psfp_filter_del(struct ocelot *ocelot,
  2112. struct flow_cls_offload *f)
  2113. {
  2114. struct felix_stream *stream, tmp, *stream_entry;
  2115. struct ocelot_psfp_list *psfp = &ocelot->psfp;
  2116. static struct felix_stream_filter *sfi;
  2117. mutex_lock(&psfp->lock);
  2118. stream = vsc9959_stream_table_get(&psfp->stream_list, f->cookie);
  2119. if (!stream) {
  2120. mutex_unlock(&psfp->lock);
  2121. return -ENOMEM;
  2122. }
  2123. sfi = vsc9959_psfp_sfi_table_get(&psfp->sfi_list, stream->sfid);
  2124. if (!sfi) {
  2125. mutex_unlock(&psfp->lock);
  2126. return -ENOMEM;
  2127. }
  2128. if (sfi->sg_valid)
  2129. vsc9959_psfp_sgi_table_del(ocelot, sfi->sgid);
  2130. if (sfi->fm_valid)
  2131. ocelot_vcap_policer_del(ocelot, sfi->fmid);
  2132. vsc9959_psfp_sfi_table_del(ocelot, stream->sfid);
  2133. memcpy(&tmp, stream, sizeof(tmp));
  2134. stream->sfid_valid = 0;
  2135. vsc9959_stream_table_del(ocelot, stream);
  2136. stream_entry = vsc9959_stream_table_lookup(&psfp->stream_list, &tmp);
  2137. if (stream_entry) {
  2138. stream_entry->ports = BIT(stream_entry->port);
  2139. if (stream_entry->dummy) {
  2140. stream_entry->dummy = false;
  2141. vsc9959_mact_stream_set(ocelot, stream_entry, NULL);
  2142. }
  2143. vsc9959_psfp_sfidmask_set(ocelot, stream_entry->sfid,
  2144. stream_entry->ports);
  2145. }
  2146. mutex_unlock(&psfp->lock);
  2147. return 0;
  2148. }
  2149. static void vsc9959_update_sfid_stats(struct ocelot *ocelot,
  2150. struct felix_stream_filter *sfi)
  2151. {
  2152. struct felix_stream_filter_counters *s = &sfi->stats;
  2153. u32 match, not_pass_gate, not_pass_sdu, red;
  2154. u32 sfid = sfi->index;
  2155. lockdep_assert_held(&ocelot->stat_view_lock);
  2156. ocelot_rmw(ocelot, SYS_STAT_CFG_STAT_VIEW(sfid),
  2157. SYS_STAT_CFG_STAT_VIEW_M,
  2158. SYS_STAT_CFG);
  2159. match = ocelot_read(ocelot, SYS_COUNT_SF_MATCHING_FRAMES);
  2160. not_pass_gate = ocelot_read(ocelot, SYS_COUNT_SF_NOT_PASSING_FRAMES);
  2161. not_pass_sdu = ocelot_read(ocelot, SYS_COUNT_SF_NOT_PASSING_SDU);
  2162. red = ocelot_read(ocelot, SYS_COUNT_SF_RED_FRAMES);
  2163. /* Clear the PSFP counter. */
  2164. ocelot_write(ocelot,
  2165. SYS_STAT_CFG_STAT_VIEW(sfid) |
  2166. SYS_STAT_CFG_STAT_CLEAR_SHOT(0x10),
  2167. SYS_STAT_CFG);
  2168. s->match += match;
  2169. s->not_pass_gate += not_pass_gate;
  2170. s->not_pass_sdu += not_pass_sdu;
  2171. s->red += red;
  2172. }
  2173. /* Caller must hold &ocelot->stat_view_lock */
  2174. static void vsc9959_update_stats(struct ocelot *ocelot)
  2175. {
  2176. struct ocelot_psfp_list *psfp = &ocelot->psfp;
  2177. struct felix_stream_filter *sfi;
  2178. mutex_lock(&psfp->lock);
  2179. list_for_each_entry(sfi, &psfp->sfi_list, list)
  2180. vsc9959_update_sfid_stats(ocelot, sfi);
  2181. mutex_unlock(&psfp->lock);
  2182. }
  2183. static int vsc9959_psfp_stats_get(struct ocelot *ocelot,
  2184. struct flow_cls_offload *f,
  2185. struct flow_stats *stats)
  2186. {
  2187. struct ocelot_psfp_list *psfp = &ocelot->psfp;
  2188. struct felix_stream_filter_counters *s;
  2189. static struct felix_stream_filter *sfi;
  2190. struct felix_stream *stream;
  2191. stream = vsc9959_stream_table_get(&psfp->stream_list, f->cookie);
  2192. if (!stream)
  2193. return -ENOMEM;
  2194. sfi = vsc9959_psfp_sfi_table_get(&psfp->sfi_list, stream->sfid);
  2195. if (!sfi)
  2196. return -EINVAL;
  2197. mutex_lock(&ocelot->stat_view_lock);
  2198. vsc9959_update_sfid_stats(ocelot, sfi);
  2199. s = &sfi->stats;
  2200. stats->pkts = s->match;
  2201. stats->drops = s->not_pass_gate + s->not_pass_sdu + s->red;
  2202. memset(s, 0, sizeof(*s));
  2203. mutex_unlock(&ocelot->stat_view_lock);
  2204. return 0;
  2205. }
  2206. static void vsc9959_psfp_init(struct ocelot *ocelot)
  2207. {
  2208. struct ocelot_psfp_list *psfp = &ocelot->psfp;
  2209. INIT_LIST_HEAD(&psfp->stream_list);
  2210. INIT_LIST_HEAD(&psfp->sfi_list);
  2211. INIT_LIST_HEAD(&psfp->sgi_list);
  2212. mutex_init(&psfp->lock);
  2213. }
  2214. /* When using cut-through forwarding and the egress port runs at a higher data
  2215. * rate than the ingress port, the packet currently under transmission would
  2216. * suffer an underrun since it would be transmitted faster than it is received.
  2217. * The Felix switch implementation of cut-through forwarding does not check in
  2218. * hardware whether this condition is satisfied or not, so we must restrict the
  2219. * list of ports that have cut-through forwarding enabled on egress to only be
  2220. * the ports operating at the lowest link speed within their respective
  2221. * forwarding domain.
  2222. */
  2223. static void vsc9959_cut_through_fwd(struct ocelot *ocelot)
  2224. {
  2225. struct felix *felix = ocelot_to_felix(ocelot);
  2226. struct dsa_switch *ds = felix->ds;
  2227. int tc, port, other_port;
  2228. lockdep_assert_held(&ocelot->fwd_domain_lock);
  2229. for (port = 0; port < ocelot->num_phys_ports; port++) {
  2230. struct ocelot_port *ocelot_port = ocelot->ports[port];
  2231. struct ocelot_mm_state *mm = &ocelot->mm[port];
  2232. int min_speed = ocelot_port->speed;
  2233. unsigned long mask = 0;
  2234. u32 tmp, val = 0;
  2235. /* Disable cut-through on ports that are down */
  2236. if (ocelot_port->speed <= 0)
  2237. goto set;
  2238. if (dsa_is_cpu_port(ds, port)) {
  2239. /* Ocelot switches forward from the NPI port towards
  2240. * any port, regardless of it being in the NPI port's
  2241. * forwarding domain or not.
  2242. */
  2243. mask = dsa_user_ports(ds);
  2244. } else {
  2245. mask = ocelot_get_bridge_fwd_mask(ocelot, port);
  2246. mask &= ~BIT(port);
  2247. if (ocelot->npi >= 0)
  2248. mask |= BIT(ocelot->npi);
  2249. else
  2250. mask |= ocelot_port_assigned_dsa_8021q_cpu_mask(ocelot,
  2251. port);
  2252. }
  2253. /* Calculate the minimum link speed, among the ports that are
  2254. * up, of this source port's forwarding domain.
  2255. */
  2256. for_each_set_bit(other_port, &mask, ocelot->num_phys_ports) {
  2257. struct ocelot_port *other_ocelot_port;
  2258. other_ocelot_port = ocelot->ports[other_port];
  2259. if (other_ocelot_port->speed <= 0)
  2260. continue;
  2261. if (min_speed > other_ocelot_port->speed)
  2262. min_speed = other_ocelot_port->speed;
  2263. }
  2264. /* Enable cut-through forwarding for all traffic classes that
  2265. * don't have oversized dropping enabled, since this check is
  2266. * bypassed in cut-through mode. Also exclude preemptible
  2267. * traffic classes, since these would hang the port for some
  2268. * reason, if sent as cut-through.
  2269. */
  2270. if (ocelot_port->speed == min_speed) {
  2271. val = GENMASK(7, 0) & ~mm->active_preemptible_tcs;
  2272. for (tc = 0; tc < OCELOT_NUM_TC; tc++)
  2273. if (vsc9959_port_qmaxsdu_get(ocelot, port, tc))
  2274. val &= ~BIT(tc);
  2275. }
  2276. set:
  2277. tmp = ocelot_read_rix(ocelot, ANA_CUT_THRU_CFG, port);
  2278. if (tmp == val)
  2279. continue;
  2280. dev_dbg(ocelot->dev,
  2281. "port %d fwd mask 0x%lx speed %d min_speed %d, %s cut-through forwarding on TC mask 0x%x\n",
  2282. port, mask, ocelot_port->speed, min_speed,
  2283. val ? "enabling" : "disabling", val);
  2284. ocelot_write_rix(ocelot, val, ANA_CUT_THRU_CFG, port);
  2285. }
  2286. }
  2287. /* The INTB interrupt is shared between for PTP TX timestamp availability
  2288. * notification and MAC Merge status change on each port.
  2289. */
  2290. static irqreturn_t vsc9959_irq_handler(int irq, void *data)
  2291. {
  2292. struct ocelot *ocelot = data;
  2293. ocelot_get_txtstamp(ocelot);
  2294. ocelot_mm_irq(ocelot);
  2295. return IRQ_HANDLED;
  2296. }
  2297. static int vsc9959_request_irq(struct ocelot *ocelot)
  2298. {
  2299. struct pci_dev *pdev = to_pci_dev(ocelot->dev);
  2300. return devm_request_threaded_irq(ocelot->dev, pdev->irq, NULL,
  2301. &vsc9959_irq_handler, IRQF_ONESHOT,
  2302. "felix-intb", ocelot);
  2303. }
  2304. static const struct ocelot_ops vsc9959_ops = {
  2305. .reset = vsc9959_reset,
  2306. .wm_enc = vsc9959_wm_enc,
  2307. .wm_dec = vsc9959_wm_dec,
  2308. .wm_stat = vsc9959_wm_stat,
  2309. .port_to_netdev = felix_port_to_netdev,
  2310. .netdev_to_port = felix_netdev_to_port,
  2311. .psfp_init = vsc9959_psfp_init,
  2312. .psfp_filter_add = vsc9959_psfp_filter_add,
  2313. .psfp_filter_del = vsc9959_psfp_filter_del,
  2314. .psfp_stats_get = vsc9959_psfp_stats_get,
  2315. .cut_through_fwd = vsc9959_cut_through_fwd,
  2316. .tas_clock_adjust = vsc9959_tas_clock_adjust,
  2317. .update_stats = vsc9959_update_stats,
  2318. .tas_guard_bands_update = vsc9959_tas_guard_bands_update,
  2319. };
  2320. static const struct felix_info felix_info_vsc9959 = {
  2321. .resources = vsc9959_resources,
  2322. .num_resources = ARRAY_SIZE(vsc9959_resources),
  2323. .resource_names = vsc9959_resource_names,
  2324. .regfields = vsc9959_regfields,
  2325. .map = vsc9959_regmap,
  2326. .ops = &vsc9959_ops,
  2327. .vcap = vsc9959_vcap_props,
  2328. .vcap_pol_base = VSC9959_VCAP_POLICER_BASE,
  2329. .vcap_pol_max = VSC9959_VCAP_POLICER_MAX,
  2330. .vcap_pol_base2 = 0,
  2331. .vcap_pol_max2 = 0,
  2332. .num_mact_rows = 2048,
  2333. .num_ports = VSC9959_NUM_PORTS,
  2334. .quirks = FELIX_MAC_QUIRKS,
  2335. .quirk_no_xtr_irq = true,
  2336. .ptp_caps = &vsc9959_ptp_caps,
  2337. .mdio_bus_alloc = vsc9959_mdio_bus_alloc,
  2338. .mdio_bus_free = vsc9959_mdio_bus_free,
  2339. .port_modes = vsc9959_port_modes,
  2340. .port_setup_tc = vsc9959_port_setup_tc,
  2341. .port_sched_speed_set = vsc9959_sched_speed_set,
  2342. .request_irq = vsc9959_request_irq,
  2343. };
  2344. static int felix_pci_probe(struct pci_dev *pdev,
  2345. const struct pci_device_id *id)
  2346. {
  2347. struct device *dev = &pdev->dev;
  2348. resource_size_t switch_base;
  2349. int err;
  2350. err = pci_enable_device(pdev);
  2351. if (err) {
  2352. dev_err(dev, "device enable failed: %pe\n", ERR_PTR(err));
  2353. return err;
  2354. }
  2355. pci_set_master(pdev);
  2356. switch_base = pci_resource_start(pdev, VSC9959_SWITCH_PCI_BAR);
  2357. err = felix_register_switch(dev, switch_base, OCELOT_NUM_TC,
  2358. true, true, DSA_TAG_PROTO_OCELOT,
  2359. &felix_info_vsc9959);
  2360. if (err)
  2361. goto out_disable;
  2362. return 0;
  2363. out_disable:
  2364. pci_disable_device(pdev);
  2365. return err;
  2366. }
  2367. static void felix_pci_remove(struct pci_dev *pdev)
  2368. {
  2369. struct felix *felix = pci_get_drvdata(pdev);
  2370. if (!felix)
  2371. return;
  2372. dsa_unregister_switch(felix->ds);
  2373. pci_disable_device(pdev);
  2374. }
  2375. static void felix_pci_shutdown(struct pci_dev *pdev)
  2376. {
  2377. struct felix *felix = pci_get_drvdata(pdev);
  2378. if (!felix)
  2379. return;
  2380. dsa_switch_shutdown(felix->ds);
  2381. pci_set_drvdata(pdev, NULL);
  2382. }
  2383. static struct pci_device_id felix_ids[] = {
  2384. {
  2385. /* NXP LS1028A */
  2386. PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0xEEF0),
  2387. },
  2388. { 0, }
  2389. };
  2390. MODULE_DEVICE_TABLE(pci, felix_ids);
  2391. static struct pci_driver felix_vsc9959_pci_driver = {
  2392. .name = "mscc_felix",
  2393. .id_table = felix_ids,
  2394. .probe = felix_pci_probe,
  2395. .remove = felix_pci_remove,
  2396. .shutdown = felix_pci_shutdown,
  2397. };
  2398. module_pci_driver(felix_vsc9959_pci_driver);
  2399. MODULE_DESCRIPTION("Felix Switch driver");
  2400. MODULE_LICENSE("GPL v2");