sja1105_main.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018, Sensor-Technik Wiedemann GmbH
  3. * Copyright (c) 2018-2019, Vladimir Oltean <[email protected]>
  4. */
  5. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  6. #include <linux/delay.h>
  7. #include <linux/module.h>
  8. #include <linux/printk.h>
  9. #include <linux/spi/spi.h>
  10. #include <linux/errno.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/phylink.h>
  13. #include <linux/of.h>
  14. #include <linux/of_net.h>
  15. #include <linux/of_mdio.h>
  16. #include <linux/of_device.h>
  17. #include <linux/pcs/pcs-xpcs.h>
  18. #include <linux/netdev_features.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/if_bridge.h>
  21. #include <linux/if_ether.h>
  22. #include <linux/dsa/8021q.h>
  23. #include "sja1105.h"
  24. #include "sja1105_tas.h"
  25. #define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull
  26. /* Configure the optional reset pin and bring up switch */
  27. static int sja1105_hw_reset(struct device *dev, unsigned int pulse_len,
  28. unsigned int startup_delay)
  29. {
  30. struct gpio_desc *gpio;
  31. gpio = gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  32. if (IS_ERR(gpio))
  33. return PTR_ERR(gpio);
  34. if (!gpio)
  35. return 0;
  36. gpiod_set_value_cansleep(gpio, 1);
  37. /* Wait for minimum reset pulse length */
  38. msleep(pulse_len);
  39. gpiod_set_value_cansleep(gpio, 0);
  40. /* Wait until chip is ready after reset */
  41. msleep(startup_delay);
  42. gpiod_put(gpio);
  43. return 0;
  44. }
  45. static void
  46. sja1105_port_allow_traffic(struct sja1105_l2_forwarding_entry *l2_fwd,
  47. int from, int to, bool allow)
  48. {
  49. if (allow)
  50. l2_fwd[from].reach_port |= BIT(to);
  51. else
  52. l2_fwd[from].reach_port &= ~BIT(to);
  53. }
  54. static bool sja1105_can_forward(struct sja1105_l2_forwarding_entry *l2_fwd,
  55. int from, int to)
  56. {
  57. return !!(l2_fwd[from].reach_port & BIT(to));
  58. }
  59. static int sja1105_is_vlan_configured(struct sja1105_private *priv, u16 vid)
  60. {
  61. struct sja1105_vlan_lookup_entry *vlan;
  62. int count, i;
  63. vlan = priv->static_config.tables[BLK_IDX_VLAN_LOOKUP].entries;
  64. count = priv->static_config.tables[BLK_IDX_VLAN_LOOKUP].entry_count;
  65. for (i = 0; i < count; i++)
  66. if (vlan[i].vlanid == vid)
  67. return i;
  68. /* Return an invalid entry index if not found */
  69. return -1;
  70. }
  71. static int sja1105_drop_untagged(struct dsa_switch *ds, int port, bool drop)
  72. {
  73. struct sja1105_private *priv = ds->priv;
  74. struct sja1105_mac_config_entry *mac;
  75. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  76. if (mac[port].drpuntag == drop)
  77. return 0;
  78. mac[port].drpuntag = drop;
  79. return sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
  80. &mac[port], true);
  81. }
  82. static int sja1105_pvid_apply(struct sja1105_private *priv, int port, u16 pvid)
  83. {
  84. struct sja1105_mac_config_entry *mac;
  85. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  86. if (mac[port].vlanid == pvid)
  87. return 0;
  88. mac[port].vlanid = pvid;
  89. return sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
  90. &mac[port], true);
  91. }
  92. static int sja1105_commit_pvid(struct dsa_switch *ds, int port)
  93. {
  94. struct dsa_port *dp = dsa_to_port(ds, port);
  95. struct net_device *br = dsa_port_bridge_dev_get(dp);
  96. struct sja1105_private *priv = ds->priv;
  97. struct sja1105_vlan_lookup_entry *vlan;
  98. bool drop_untagged = false;
  99. int match, rc;
  100. u16 pvid;
  101. if (br && br_vlan_enabled(br))
  102. pvid = priv->bridge_pvid[port];
  103. else
  104. pvid = priv->tag_8021q_pvid[port];
  105. rc = sja1105_pvid_apply(priv, port, pvid);
  106. if (rc)
  107. return rc;
  108. /* Only force dropping of untagged packets when the port is under a
  109. * VLAN-aware bridge. When the tag_8021q pvid is used, we are
  110. * deliberately removing the RX VLAN from the port's VMEMB_PORT list,
  111. * to prevent DSA tag spoofing from the link partner. Untagged packets
  112. * are the only ones that should be received with tag_8021q, so
  113. * definitely don't drop them.
  114. */
  115. if (pvid == priv->bridge_pvid[port]) {
  116. vlan = priv->static_config.tables[BLK_IDX_VLAN_LOOKUP].entries;
  117. match = sja1105_is_vlan_configured(priv, pvid);
  118. if (match < 0 || !(vlan[match].vmemb_port & BIT(port)))
  119. drop_untagged = true;
  120. }
  121. if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
  122. drop_untagged = true;
  123. return sja1105_drop_untagged(ds, port, drop_untagged);
  124. }
  125. static int sja1105_init_mac_settings(struct sja1105_private *priv)
  126. {
  127. struct sja1105_mac_config_entry default_mac = {
  128. /* Enable all 8 priority queues on egress.
  129. * Every queue i holds top[i] - base[i] frames.
  130. * Sum of top[i] - base[i] is 511 (max hardware limit).
  131. */
  132. .top = {0x3F, 0x7F, 0xBF, 0xFF, 0x13F, 0x17F, 0x1BF, 0x1FF},
  133. .base = {0x0, 0x40, 0x80, 0xC0, 0x100, 0x140, 0x180, 0x1C0},
  134. .enabled = {true, true, true, true, true, true, true, true},
  135. /* Keep standard IFG of 12 bytes on egress. */
  136. .ifg = 0,
  137. /* Always put the MAC speed in automatic mode, where it can be
  138. * adjusted at runtime by PHYLINK.
  139. */
  140. .speed = priv->info->port_speed[SJA1105_SPEED_AUTO],
  141. /* No static correction for 1-step 1588 events */
  142. .tp_delin = 0,
  143. .tp_delout = 0,
  144. /* Disable aging for critical TTEthernet traffic */
  145. .maxage = 0xFF,
  146. /* Internal VLAN (pvid) to apply to untagged ingress */
  147. .vlanprio = 0,
  148. .vlanid = 1,
  149. .ing_mirr = false,
  150. .egr_mirr = false,
  151. /* Don't drop traffic with other EtherType than ETH_P_IP */
  152. .drpnona664 = false,
  153. /* Don't drop double-tagged traffic */
  154. .drpdtag = false,
  155. /* Don't drop untagged traffic */
  156. .drpuntag = false,
  157. /* Don't retag 802.1p (VID 0) traffic with the pvid */
  158. .retag = false,
  159. /* Disable learning and I/O on user ports by default -
  160. * STP will enable it.
  161. */
  162. .dyn_learn = false,
  163. .egress = false,
  164. .ingress = false,
  165. };
  166. struct sja1105_mac_config_entry *mac;
  167. struct dsa_switch *ds = priv->ds;
  168. struct sja1105_table *table;
  169. struct dsa_port *dp;
  170. table = &priv->static_config.tables[BLK_IDX_MAC_CONFIG];
  171. /* Discard previous MAC Configuration Table */
  172. if (table->entry_count) {
  173. kfree(table->entries);
  174. table->entry_count = 0;
  175. }
  176. table->entries = kcalloc(table->ops->max_entry_count,
  177. table->ops->unpacked_entry_size, GFP_KERNEL);
  178. if (!table->entries)
  179. return -ENOMEM;
  180. table->entry_count = table->ops->max_entry_count;
  181. mac = table->entries;
  182. list_for_each_entry(dp, &ds->dst->ports, list) {
  183. if (dp->ds != ds)
  184. continue;
  185. mac[dp->index] = default_mac;
  186. /* Let sja1105_bridge_stp_state_set() keep address learning
  187. * enabled for the DSA ports. CPU ports use software-assisted
  188. * learning to ensure that only FDB entries belonging to the
  189. * bridge are learned, and that they are learned towards all
  190. * CPU ports in a cross-chip topology if multiple CPU ports
  191. * exist.
  192. */
  193. if (dsa_port_is_dsa(dp))
  194. dp->learning = true;
  195. /* Disallow untagged packets from being received on the
  196. * CPU and DSA ports.
  197. */
  198. if (dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))
  199. mac[dp->index].drpuntag = true;
  200. }
  201. return 0;
  202. }
  203. static int sja1105_init_mii_settings(struct sja1105_private *priv)
  204. {
  205. struct device *dev = &priv->spidev->dev;
  206. struct sja1105_xmii_params_entry *mii;
  207. struct dsa_switch *ds = priv->ds;
  208. struct sja1105_table *table;
  209. int i;
  210. table = &priv->static_config.tables[BLK_IDX_XMII_PARAMS];
  211. /* Discard previous xMII Mode Parameters Table */
  212. if (table->entry_count) {
  213. kfree(table->entries);
  214. table->entry_count = 0;
  215. }
  216. table->entries = kcalloc(table->ops->max_entry_count,
  217. table->ops->unpacked_entry_size, GFP_KERNEL);
  218. if (!table->entries)
  219. return -ENOMEM;
  220. /* Override table based on PHYLINK DT bindings */
  221. table->entry_count = table->ops->max_entry_count;
  222. mii = table->entries;
  223. for (i = 0; i < ds->num_ports; i++) {
  224. sja1105_mii_role_t role = XMII_MAC;
  225. if (dsa_is_unused_port(priv->ds, i))
  226. continue;
  227. switch (priv->phy_mode[i]) {
  228. case PHY_INTERFACE_MODE_INTERNAL:
  229. if (priv->info->internal_phy[i] == SJA1105_NO_PHY)
  230. goto unsupported;
  231. mii->xmii_mode[i] = XMII_MODE_MII;
  232. if (priv->info->internal_phy[i] == SJA1105_PHY_BASE_TX)
  233. mii->special[i] = true;
  234. break;
  235. case PHY_INTERFACE_MODE_REVMII:
  236. role = XMII_PHY;
  237. fallthrough;
  238. case PHY_INTERFACE_MODE_MII:
  239. if (!priv->info->supports_mii[i])
  240. goto unsupported;
  241. mii->xmii_mode[i] = XMII_MODE_MII;
  242. break;
  243. case PHY_INTERFACE_MODE_REVRMII:
  244. role = XMII_PHY;
  245. fallthrough;
  246. case PHY_INTERFACE_MODE_RMII:
  247. if (!priv->info->supports_rmii[i])
  248. goto unsupported;
  249. mii->xmii_mode[i] = XMII_MODE_RMII;
  250. break;
  251. case PHY_INTERFACE_MODE_RGMII:
  252. case PHY_INTERFACE_MODE_RGMII_ID:
  253. case PHY_INTERFACE_MODE_RGMII_RXID:
  254. case PHY_INTERFACE_MODE_RGMII_TXID:
  255. if (!priv->info->supports_rgmii[i])
  256. goto unsupported;
  257. mii->xmii_mode[i] = XMII_MODE_RGMII;
  258. break;
  259. case PHY_INTERFACE_MODE_SGMII:
  260. if (!priv->info->supports_sgmii[i])
  261. goto unsupported;
  262. mii->xmii_mode[i] = XMII_MODE_SGMII;
  263. mii->special[i] = true;
  264. break;
  265. case PHY_INTERFACE_MODE_2500BASEX:
  266. if (!priv->info->supports_2500basex[i])
  267. goto unsupported;
  268. mii->xmii_mode[i] = XMII_MODE_SGMII;
  269. mii->special[i] = true;
  270. break;
  271. unsupported:
  272. default:
  273. dev_err(dev, "Unsupported PHY mode %s on port %d!\n",
  274. phy_modes(priv->phy_mode[i]), i);
  275. return -EINVAL;
  276. }
  277. mii->phy_mac[i] = role;
  278. }
  279. return 0;
  280. }
  281. static int sja1105_init_static_fdb(struct sja1105_private *priv)
  282. {
  283. struct sja1105_l2_lookup_entry *l2_lookup;
  284. struct sja1105_table *table;
  285. int port;
  286. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP];
  287. /* We only populate the FDB table through dynamic L2 Address Lookup
  288. * entries, except for a special entry at the end which is a catch-all
  289. * for unknown multicast and will be used to control flooding domain.
  290. */
  291. if (table->entry_count) {
  292. kfree(table->entries);
  293. table->entry_count = 0;
  294. }
  295. if (!priv->info->can_limit_mcast_flood)
  296. return 0;
  297. table->entries = kcalloc(1, table->ops->unpacked_entry_size,
  298. GFP_KERNEL);
  299. if (!table->entries)
  300. return -ENOMEM;
  301. table->entry_count = 1;
  302. l2_lookup = table->entries;
  303. /* All L2 multicast addresses have an odd first octet */
  304. l2_lookup[0].macaddr = SJA1105_UNKNOWN_MULTICAST;
  305. l2_lookup[0].mask_macaddr = SJA1105_UNKNOWN_MULTICAST;
  306. l2_lookup[0].lockeds = true;
  307. l2_lookup[0].index = SJA1105_MAX_L2_LOOKUP_COUNT - 1;
  308. /* Flood multicast to every port by default */
  309. for (port = 0; port < priv->ds->num_ports; port++)
  310. if (!dsa_is_unused_port(priv->ds, port))
  311. l2_lookup[0].destports |= BIT(port);
  312. return 0;
  313. }
  314. static int sja1105_init_l2_lookup_params(struct sja1105_private *priv)
  315. {
  316. struct sja1105_l2_lookup_params_entry default_l2_lookup_params = {
  317. /* Learned FDB entries are forgotten after 300 seconds */
  318. .maxage = SJA1105_AGEING_TIME_MS(300000),
  319. /* All entries within a FDB bin are available for learning */
  320. .dyn_tbsz = SJA1105ET_FDB_BIN_SIZE,
  321. /* And the P/Q/R/S equivalent setting: */
  322. .start_dynspc = 0,
  323. /* 2^8 + 2^5 + 2^3 + 2^2 + 2^1 + 1 in Koopman notation */
  324. .poly = 0x97,
  325. /* Always use Independent VLAN Learning (IVL) */
  326. .shared_learn = false,
  327. /* Don't discard management traffic based on ENFPORT -
  328. * we don't perform SMAC port enforcement anyway, so
  329. * what we are setting here doesn't matter.
  330. */
  331. .no_enf_hostprt = false,
  332. /* Don't learn SMAC for mac_fltres1 and mac_fltres0.
  333. * Maybe correlate with no_linklocal_learn from bridge driver?
  334. */
  335. .no_mgmt_learn = true,
  336. /* P/Q/R/S only */
  337. .use_static = true,
  338. /* Dynamically learned FDB entries can overwrite other (older)
  339. * dynamic FDB entries
  340. */
  341. .owr_dyn = true,
  342. .drpnolearn = true,
  343. };
  344. struct dsa_switch *ds = priv->ds;
  345. int port, num_used_ports = 0;
  346. struct sja1105_table *table;
  347. u64 max_fdb_entries;
  348. for (port = 0; port < ds->num_ports; port++)
  349. if (!dsa_is_unused_port(ds, port))
  350. num_used_ports++;
  351. max_fdb_entries = SJA1105_MAX_L2_LOOKUP_COUNT / num_used_ports;
  352. for (port = 0; port < ds->num_ports; port++) {
  353. if (dsa_is_unused_port(ds, port))
  354. continue;
  355. default_l2_lookup_params.maxaddrp[port] = max_fdb_entries;
  356. }
  357. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP_PARAMS];
  358. if (table->entry_count) {
  359. kfree(table->entries);
  360. table->entry_count = 0;
  361. }
  362. table->entries = kcalloc(table->ops->max_entry_count,
  363. table->ops->unpacked_entry_size, GFP_KERNEL);
  364. if (!table->entries)
  365. return -ENOMEM;
  366. table->entry_count = table->ops->max_entry_count;
  367. /* This table only has a single entry */
  368. ((struct sja1105_l2_lookup_params_entry *)table->entries)[0] =
  369. default_l2_lookup_params;
  370. return 0;
  371. }
  372. /* Set up a default VLAN for untagged traffic injected from the CPU
  373. * using management routes (e.g. STP, PTP) as opposed to tag_8021q.
  374. * All DT-defined ports are members of this VLAN, and there are no
  375. * restrictions on forwarding (since the CPU selects the destination).
  376. * Frames from this VLAN will always be transmitted as untagged, and
  377. * neither the bridge nor the 8021q module cannot create this VLAN ID.
  378. */
  379. static int sja1105_init_static_vlan(struct sja1105_private *priv)
  380. {
  381. struct sja1105_table *table;
  382. struct sja1105_vlan_lookup_entry pvid = {
  383. .type_entry = SJA1110_VLAN_D_TAG,
  384. .ving_mirr = 0,
  385. .vegr_mirr = 0,
  386. .vmemb_port = 0,
  387. .vlan_bc = 0,
  388. .tag_port = 0,
  389. .vlanid = SJA1105_DEFAULT_VLAN,
  390. };
  391. struct dsa_switch *ds = priv->ds;
  392. int port;
  393. table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
  394. if (table->entry_count) {
  395. kfree(table->entries);
  396. table->entry_count = 0;
  397. }
  398. table->entries = kzalloc(table->ops->unpacked_entry_size,
  399. GFP_KERNEL);
  400. if (!table->entries)
  401. return -ENOMEM;
  402. table->entry_count = 1;
  403. for (port = 0; port < ds->num_ports; port++) {
  404. if (dsa_is_unused_port(ds, port))
  405. continue;
  406. pvid.vmemb_port |= BIT(port);
  407. pvid.vlan_bc |= BIT(port);
  408. pvid.tag_port &= ~BIT(port);
  409. if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
  410. priv->tag_8021q_pvid[port] = SJA1105_DEFAULT_VLAN;
  411. priv->bridge_pvid[port] = SJA1105_DEFAULT_VLAN;
  412. }
  413. }
  414. ((struct sja1105_vlan_lookup_entry *)table->entries)[0] = pvid;
  415. return 0;
  416. }
  417. static int sja1105_init_l2_forwarding(struct sja1105_private *priv)
  418. {
  419. struct sja1105_l2_forwarding_entry *l2fwd;
  420. struct dsa_switch *ds = priv->ds;
  421. struct dsa_switch_tree *dst;
  422. struct sja1105_table *table;
  423. struct dsa_link *dl;
  424. int port, tc;
  425. int from, to;
  426. table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING];
  427. if (table->entry_count) {
  428. kfree(table->entries);
  429. table->entry_count = 0;
  430. }
  431. table->entries = kcalloc(table->ops->max_entry_count,
  432. table->ops->unpacked_entry_size, GFP_KERNEL);
  433. if (!table->entries)
  434. return -ENOMEM;
  435. table->entry_count = table->ops->max_entry_count;
  436. l2fwd = table->entries;
  437. /* First 5 entries in the L2 Forwarding Table define the forwarding
  438. * rules and the VLAN PCP to ingress queue mapping.
  439. * Set up the ingress queue mapping first.
  440. */
  441. for (port = 0; port < ds->num_ports; port++) {
  442. if (dsa_is_unused_port(ds, port))
  443. continue;
  444. for (tc = 0; tc < SJA1105_NUM_TC; tc++)
  445. l2fwd[port].vlan_pmap[tc] = tc;
  446. }
  447. /* Then manage the forwarding domain for user ports. These can forward
  448. * only to the always-on domain (CPU port and DSA links)
  449. */
  450. for (from = 0; from < ds->num_ports; from++) {
  451. if (!dsa_is_user_port(ds, from))
  452. continue;
  453. for (to = 0; to < ds->num_ports; to++) {
  454. if (!dsa_is_cpu_port(ds, to) &&
  455. !dsa_is_dsa_port(ds, to))
  456. continue;
  457. l2fwd[from].bc_domain |= BIT(to);
  458. l2fwd[from].fl_domain |= BIT(to);
  459. sja1105_port_allow_traffic(l2fwd, from, to, true);
  460. }
  461. }
  462. /* Then manage the forwarding domain for DSA links and CPU ports (the
  463. * always-on domain). These can send packets to any enabled port except
  464. * themselves.
  465. */
  466. for (from = 0; from < ds->num_ports; from++) {
  467. if (!dsa_is_cpu_port(ds, from) && !dsa_is_dsa_port(ds, from))
  468. continue;
  469. for (to = 0; to < ds->num_ports; to++) {
  470. if (dsa_is_unused_port(ds, to))
  471. continue;
  472. if (from == to)
  473. continue;
  474. l2fwd[from].bc_domain |= BIT(to);
  475. l2fwd[from].fl_domain |= BIT(to);
  476. sja1105_port_allow_traffic(l2fwd, from, to, true);
  477. }
  478. }
  479. /* In odd topologies ("H" connections where there is a DSA link to
  480. * another switch which also has its own CPU port), TX packets can loop
  481. * back into the system (they are flooded from CPU port 1 to the DSA
  482. * link, and from there to CPU port 2). Prevent this from happening by
  483. * cutting RX from DSA links towards our CPU port, if the remote switch
  484. * has its own CPU port and therefore doesn't need ours for network
  485. * stack termination.
  486. */
  487. dst = ds->dst;
  488. list_for_each_entry(dl, &dst->rtable, list) {
  489. if (dl->dp->ds != ds || dl->link_dp->cpu_dp == dl->dp->cpu_dp)
  490. continue;
  491. from = dl->dp->index;
  492. to = dsa_upstream_port(ds, from);
  493. dev_warn(ds->dev,
  494. "H topology detected, cutting RX from DSA link %d to CPU port %d to prevent TX packet loops\n",
  495. from, to);
  496. sja1105_port_allow_traffic(l2fwd, from, to, false);
  497. l2fwd[from].bc_domain &= ~BIT(to);
  498. l2fwd[from].fl_domain &= ~BIT(to);
  499. }
  500. /* Finally, manage the egress flooding domain. All ports start up with
  501. * flooding enabled, including the CPU port and DSA links.
  502. */
  503. for (port = 0; port < ds->num_ports; port++) {
  504. if (dsa_is_unused_port(ds, port))
  505. continue;
  506. priv->ucast_egress_floods |= BIT(port);
  507. priv->bcast_egress_floods |= BIT(port);
  508. }
  509. /* Next 8 entries define VLAN PCP mapping from ingress to egress.
  510. * Create a one-to-one mapping.
  511. */
  512. for (tc = 0; tc < SJA1105_NUM_TC; tc++) {
  513. for (port = 0; port < ds->num_ports; port++) {
  514. if (dsa_is_unused_port(ds, port))
  515. continue;
  516. l2fwd[ds->num_ports + tc].vlan_pmap[port] = tc;
  517. }
  518. l2fwd[ds->num_ports + tc].type_egrpcp2outputq = true;
  519. }
  520. return 0;
  521. }
  522. static int sja1110_init_pcp_remapping(struct sja1105_private *priv)
  523. {
  524. struct sja1110_pcp_remapping_entry *pcp_remap;
  525. struct dsa_switch *ds = priv->ds;
  526. struct sja1105_table *table;
  527. int port, tc;
  528. table = &priv->static_config.tables[BLK_IDX_PCP_REMAPPING];
  529. /* Nothing to do for SJA1105 */
  530. if (!table->ops->max_entry_count)
  531. return 0;
  532. if (table->entry_count) {
  533. kfree(table->entries);
  534. table->entry_count = 0;
  535. }
  536. table->entries = kcalloc(table->ops->max_entry_count,
  537. table->ops->unpacked_entry_size, GFP_KERNEL);
  538. if (!table->entries)
  539. return -ENOMEM;
  540. table->entry_count = table->ops->max_entry_count;
  541. pcp_remap = table->entries;
  542. /* Repeat the configuration done for vlan_pmap */
  543. for (port = 0; port < ds->num_ports; port++) {
  544. if (dsa_is_unused_port(ds, port))
  545. continue;
  546. for (tc = 0; tc < SJA1105_NUM_TC; tc++)
  547. pcp_remap[port].egrpcp[tc] = tc;
  548. }
  549. return 0;
  550. }
  551. static int sja1105_init_l2_forwarding_params(struct sja1105_private *priv)
  552. {
  553. struct sja1105_l2_forwarding_params_entry *l2fwd_params;
  554. struct sja1105_table *table;
  555. table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
  556. if (table->entry_count) {
  557. kfree(table->entries);
  558. table->entry_count = 0;
  559. }
  560. table->entries = kcalloc(table->ops->max_entry_count,
  561. table->ops->unpacked_entry_size, GFP_KERNEL);
  562. if (!table->entries)
  563. return -ENOMEM;
  564. table->entry_count = table->ops->max_entry_count;
  565. /* This table only has a single entry */
  566. l2fwd_params = table->entries;
  567. /* Disallow dynamic reconfiguration of vlan_pmap */
  568. l2fwd_params->max_dynp = 0;
  569. /* Use a single memory partition for all ingress queues */
  570. l2fwd_params->part_spc[0] = priv->info->max_frame_mem;
  571. return 0;
  572. }
  573. void sja1105_frame_memory_partitioning(struct sja1105_private *priv)
  574. {
  575. struct sja1105_l2_forwarding_params_entry *l2_fwd_params;
  576. struct sja1105_vl_forwarding_params_entry *vl_fwd_params;
  577. struct sja1105_table *table;
  578. table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING_PARAMS];
  579. l2_fwd_params = table->entries;
  580. l2_fwd_params->part_spc[0] = SJA1105_MAX_FRAME_MEMORY;
  581. /* If we have any critical-traffic virtual links, we need to reserve
  582. * some frame buffer memory for them. At the moment, hardcode the value
  583. * at 100 blocks of 128 bytes of memory each. This leaves 829 blocks
  584. * remaining for best-effort traffic. TODO: figure out a more flexible
  585. * way to perform the frame buffer partitioning.
  586. */
  587. if (!priv->static_config.tables[BLK_IDX_VL_FORWARDING].entry_count)
  588. return;
  589. table = &priv->static_config.tables[BLK_IDX_VL_FORWARDING_PARAMS];
  590. vl_fwd_params = table->entries;
  591. l2_fwd_params->part_spc[0] -= SJA1105_VL_FRAME_MEMORY;
  592. vl_fwd_params->partspc[0] = SJA1105_VL_FRAME_MEMORY;
  593. }
  594. /* SJA1110 TDMACONFIGIDX values:
  595. *
  596. * | 100 Mbps ports | 1Gbps ports | 2.5Gbps ports | Disabled ports
  597. * -----+----------------+---------------+---------------+---------------
  598. * 0 | 0, [5:10] | [1:2] | [3:4] | retag
  599. * 1 |0, [5:10], retag| [1:2] | [3:4] | -
  600. * 2 | 0, [5:10] | [1:3], retag | 4 | -
  601. * 3 | 0, [5:10] |[1:2], 4, retag| 3 | -
  602. * 4 | 0, 2, [5:10] | 1, retag | [3:4] | -
  603. * 5 | 0, 1, [5:10] | 2, retag | [3:4] | -
  604. * 14 | 0, [5:10] | [1:4], retag | - | -
  605. * 15 | [5:10] | [0:4], retag | - | -
  606. */
  607. static void sja1110_select_tdmaconfigidx(struct sja1105_private *priv)
  608. {
  609. struct sja1105_general_params_entry *general_params;
  610. struct sja1105_table *table;
  611. bool port_1_is_base_tx;
  612. bool port_3_is_2500;
  613. bool port_4_is_2500;
  614. u64 tdmaconfigidx;
  615. if (priv->info->device_id != SJA1110_DEVICE_ID)
  616. return;
  617. table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
  618. general_params = table->entries;
  619. /* All the settings below are "as opposed to SGMII", which is the
  620. * other pinmuxing option.
  621. */
  622. port_1_is_base_tx = priv->phy_mode[1] == PHY_INTERFACE_MODE_INTERNAL;
  623. port_3_is_2500 = priv->phy_mode[3] == PHY_INTERFACE_MODE_2500BASEX;
  624. port_4_is_2500 = priv->phy_mode[4] == PHY_INTERFACE_MODE_2500BASEX;
  625. if (port_1_is_base_tx)
  626. /* Retagging port will operate at 1 Gbps */
  627. tdmaconfigidx = 5;
  628. else if (port_3_is_2500 && port_4_is_2500)
  629. /* Retagging port will operate at 100 Mbps */
  630. tdmaconfigidx = 1;
  631. else if (port_3_is_2500)
  632. /* Retagging port will operate at 1 Gbps */
  633. tdmaconfigidx = 3;
  634. else if (port_4_is_2500)
  635. /* Retagging port will operate at 1 Gbps */
  636. tdmaconfigidx = 2;
  637. else
  638. /* Retagging port will operate at 1 Gbps */
  639. tdmaconfigidx = 14;
  640. general_params->tdmaconfigidx = tdmaconfigidx;
  641. }
  642. static int sja1105_init_topology(struct sja1105_private *priv,
  643. struct sja1105_general_params_entry *general_params)
  644. {
  645. struct dsa_switch *ds = priv->ds;
  646. int port;
  647. /* The host port is the destination for traffic matching mac_fltres1
  648. * and mac_fltres0 on all ports except itself. Default to an invalid
  649. * value.
  650. */
  651. general_params->host_port = ds->num_ports;
  652. /* Link-local traffic received on casc_port will be forwarded
  653. * to host_port without embedding the source port and device ID
  654. * info in the destination MAC address, and no RX timestamps will be
  655. * taken either (presumably because it is a cascaded port and a
  656. * downstream SJA switch already did that).
  657. * To disable the feature, we need to do different things depending on
  658. * switch generation. On SJA1105 we need to set an invalid port, while
  659. * on SJA1110 which support multiple cascaded ports, this field is a
  660. * bitmask so it must be left zero.
  661. */
  662. if (!priv->info->multiple_cascade_ports)
  663. general_params->casc_port = ds->num_ports;
  664. for (port = 0; port < ds->num_ports; port++) {
  665. bool is_upstream = dsa_is_upstream_port(ds, port);
  666. bool is_dsa_link = dsa_is_dsa_port(ds, port);
  667. /* Upstream ports can be dedicated CPU ports or
  668. * upstream-facing DSA links
  669. */
  670. if (is_upstream) {
  671. if (general_params->host_port == ds->num_ports) {
  672. general_params->host_port = port;
  673. } else {
  674. dev_err(ds->dev,
  675. "Port %llu is already a host port, configuring %d as one too is not supported\n",
  676. general_params->host_port, port);
  677. return -EINVAL;
  678. }
  679. }
  680. /* Cascade ports are downstream-facing DSA links */
  681. if (is_dsa_link && !is_upstream) {
  682. if (priv->info->multiple_cascade_ports) {
  683. general_params->casc_port |= BIT(port);
  684. } else if (general_params->casc_port == ds->num_ports) {
  685. general_params->casc_port = port;
  686. } else {
  687. dev_err(ds->dev,
  688. "Port %llu is already a cascade port, configuring %d as one too is not supported\n",
  689. general_params->casc_port, port);
  690. return -EINVAL;
  691. }
  692. }
  693. }
  694. if (general_params->host_port == ds->num_ports) {
  695. dev_err(ds->dev, "No host port configured\n");
  696. return -EINVAL;
  697. }
  698. return 0;
  699. }
  700. static int sja1105_init_general_params(struct sja1105_private *priv)
  701. {
  702. struct sja1105_general_params_entry default_general_params = {
  703. /* Allow dynamic changing of the mirror port */
  704. .mirr_ptacu = true,
  705. .switchid = priv->ds->index,
  706. /* Priority queue for link-local management frames
  707. * (both ingress to and egress from CPU - PTP, STP etc)
  708. */
  709. .hostprio = 7,
  710. .mac_fltres1 = SJA1105_LINKLOCAL_FILTER_A,
  711. .mac_flt1 = SJA1105_LINKLOCAL_FILTER_A_MASK,
  712. .incl_srcpt1 = true,
  713. .send_meta1 = true,
  714. .mac_fltres0 = SJA1105_LINKLOCAL_FILTER_B,
  715. .mac_flt0 = SJA1105_LINKLOCAL_FILTER_B_MASK,
  716. .incl_srcpt0 = true,
  717. .send_meta0 = true,
  718. /* Default to an invalid value */
  719. .mirr_port = priv->ds->num_ports,
  720. /* No TTEthernet */
  721. .vllupformat = SJA1105_VL_FORMAT_PSFP,
  722. .vlmarker = 0,
  723. .vlmask = 0,
  724. /* Only update correctionField for 1-step PTP (L2 transport) */
  725. .ignore2stf = 0,
  726. /* Forcefully disable VLAN filtering by telling
  727. * the switch that VLAN has a different EtherType.
  728. */
  729. .tpid = ETH_P_SJA1105,
  730. .tpid2 = ETH_P_SJA1105,
  731. /* Enable the TTEthernet engine on SJA1110 */
  732. .tte_en = true,
  733. /* Set up the EtherType for control packets on SJA1110 */
  734. .header_type = ETH_P_SJA1110,
  735. };
  736. struct sja1105_general_params_entry *general_params;
  737. struct sja1105_table *table;
  738. int rc;
  739. rc = sja1105_init_topology(priv, &default_general_params);
  740. if (rc)
  741. return rc;
  742. table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
  743. if (table->entry_count) {
  744. kfree(table->entries);
  745. table->entry_count = 0;
  746. }
  747. table->entries = kcalloc(table->ops->max_entry_count,
  748. table->ops->unpacked_entry_size, GFP_KERNEL);
  749. if (!table->entries)
  750. return -ENOMEM;
  751. table->entry_count = table->ops->max_entry_count;
  752. general_params = table->entries;
  753. /* This table only has a single entry */
  754. general_params[0] = default_general_params;
  755. sja1110_select_tdmaconfigidx(priv);
  756. return 0;
  757. }
  758. static int sja1105_init_avb_params(struct sja1105_private *priv)
  759. {
  760. struct sja1105_avb_params_entry *avb;
  761. struct sja1105_table *table;
  762. table = &priv->static_config.tables[BLK_IDX_AVB_PARAMS];
  763. /* Discard previous AVB Parameters Table */
  764. if (table->entry_count) {
  765. kfree(table->entries);
  766. table->entry_count = 0;
  767. }
  768. table->entries = kcalloc(table->ops->max_entry_count,
  769. table->ops->unpacked_entry_size, GFP_KERNEL);
  770. if (!table->entries)
  771. return -ENOMEM;
  772. table->entry_count = table->ops->max_entry_count;
  773. avb = table->entries;
  774. /* Configure the MAC addresses for meta frames */
  775. avb->destmeta = SJA1105_META_DMAC;
  776. avb->srcmeta = SJA1105_META_SMAC;
  777. /* On P/Q/R/S, configure the direction of the PTP_CLK pin as input by
  778. * default. This is because there might be boards with a hardware
  779. * layout where enabling the pin as output might cause an electrical
  780. * clash. On E/T the pin is always an output, which the board designers
  781. * probably already knew, so even if there are going to be electrical
  782. * issues, there's nothing we can do.
  783. */
  784. avb->cas_master = false;
  785. return 0;
  786. }
  787. /* The L2 policing table is 2-stage. The table is looked up for each frame
  788. * according to the ingress port, whether it was broadcast or not, and the
  789. * classified traffic class (given by VLAN PCP). This portion of the lookup is
  790. * fixed, and gives access to the SHARINDX, an indirection register pointing
  791. * within the policing table itself, which is used to resolve the policer that
  792. * will be used for this frame.
  793. *
  794. * Stage 1 Stage 2
  795. * +------------+--------+ +---------------------------------+
  796. * |Port 0 TC 0 |SHARINDX| | Policer 0: Rate, Burst, MTU |
  797. * +------------+--------+ +---------------------------------+
  798. * |Port 0 TC 1 |SHARINDX| | Policer 1: Rate, Burst, MTU |
  799. * +------------+--------+ +---------------------------------+
  800. * ... | Policer 2: Rate, Burst, MTU |
  801. * +------------+--------+ +---------------------------------+
  802. * |Port 0 TC 7 |SHARINDX| | Policer 3: Rate, Burst, MTU |
  803. * +------------+--------+ +---------------------------------+
  804. * |Port 1 TC 0 |SHARINDX| | Policer 4: Rate, Burst, MTU |
  805. * +------------+--------+ +---------------------------------+
  806. * ... | Policer 5: Rate, Burst, MTU |
  807. * +------------+--------+ +---------------------------------+
  808. * |Port 1 TC 7 |SHARINDX| | Policer 6: Rate, Burst, MTU |
  809. * +------------+--------+ +---------------------------------+
  810. * ... | Policer 7: Rate, Burst, MTU |
  811. * +------------+--------+ +---------------------------------+
  812. * |Port 4 TC 7 |SHARINDX| ...
  813. * +------------+--------+
  814. * |Port 0 BCAST|SHARINDX| ...
  815. * +------------+--------+
  816. * |Port 1 BCAST|SHARINDX| ...
  817. * +------------+--------+
  818. * ... ...
  819. * +------------+--------+ +---------------------------------+
  820. * |Port 4 BCAST|SHARINDX| | Policer 44: Rate, Burst, MTU |
  821. * +------------+--------+ +---------------------------------+
  822. *
  823. * In this driver, we shall use policers 0-4 as statically alocated port
  824. * (matchall) policers. So we need to make the SHARINDX for all lookups
  825. * corresponding to this ingress port (8 VLAN PCP lookups and 1 broadcast
  826. * lookup) equal.
  827. * The remaining policers (40) shall be dynamically allocated for flower
  828. * policers, where the key is either vlan_prio or dst_mac ff:ff:ff:ff:ff:ff.
  829. */
  830. #define SJA1105_RATE_MBPS(speed) (((speed) * 64000) / 1000)
  831. static int sja1105_init_l2_policing(struct sja1105_private *priv)
  832. {
  833. struct sja1105_l2_policing_entry *policing;
  834. struct dsa_switch *ds = priv->ds;
  835. struct sja1105_table *table;
  836. int port, tc;
  837. table = &priv->static_config.tables[BLK_IDX_L2_POLICING];
  838. /* Discard previous L2 Policing Table */
  839. if (table->entry_count) {
  840. kfree(table->entries);
  841. table->entry_count = 0;
  842. }
  843. table->entries = kcalloc(table->ops->max_entry_count,
  844. table->ops->unpacked_entry_size, GFP_KERNEL);
  845. if (!table->entries)
  846. return -ENOMEM;
  847. table->entry_count = table->ops->max_entry_count;
  848. policing = table->entries;
  849. /* Setup shared indices for the matchall policers */
  850. for (port = 0; port < ds->num_ports; port++) {
  851. int mcast = (ds->num_ports * (SJA1105_NUM_TC + 1)) + port;
  852. int bcast = (ds->num_ports * SJA1105_NUM_TC) + port;
  853. for (tc = 0; tc < SJA1105_NUM_TC; tc++)
  854. policing[port * SJA1105_NUM_TC + tc].sharindx = port;
  855. policing[bcast].sharindx = port;
  856. /* Only SJA1110 has multicast policers */
  857. if (mcast < table->ops->max_entry_count)
  858. policing[mcast].sharindx = port;
  859. }
  860. /* Setup the matchall policer parameters */
  861. for (port = 0; port < ds->num_ports; port++) {
  862. int mtu = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  863. if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
  864. mtu += VLAN_HLEN;
  865. policing[port].smax = 65535; /* Burst size in bytes */
  866. policing[port].rate = SJA1105_RATE_MBPS(1000);
  867. policing[port].maxlen = mtu;
  868. policing[port].partition = 0;
  869. }
  870. return 0;
  871. }
  872. static int sja1105_static_config_load(struct sja1105_private *priv)
  873. {
  874. int rc;
  875. sja1105_static_config_free(&priv->static_config);
  876. rc = sja1105_static_config_init(&priv->static_config,
  877. priv->info->static_ops,
  878. priv->info->device_id);
  879. if (rc)
  880. return rc;
  881. /* Build static configuration */
  882. rc = sja1105_init_mac_settings(priv);
  883. if (rc < 0)
  884. return rc;
  885. rc = sja1105_init_mii_settings(priv);
  886. if (rc < 0)
  887. return rc;
  888. rc = sja1105_init_static_fdb(priv);
  889. if (rc < 0)
  890. return rc;
  891. rc = sja1105_init_static_vlan(priv);
  892. if (rc < 0)
  893. return rc;
  894. rc = sja1105_init_l2_lookup_params(priv);
  895. if (rc < 0)
  896. return rc;
  897. rc = sja1105_init_l2_forwarding(priv);
  898. if (rc < 0)
  899. return rc;
  900. rc = sja1105_init_l2_forwarding_params(priv);
  901. if (rc < 0)
  902. return rc;
  903. rc = sja1105_init_l2_policing(priv);
  904. if (rc < 0)
  905. return rc;
  906. rc = sja1105_init_general_params(priv);
  907. if (rc < 0)
  908. return rc;
  909. rc = sja1105_init_avb_params(priv);
  910. if (rc < 0)
  911. return rc;
  912. rc = sja1110_init_pcp_remapping(priv);
  913. if (rc < 0)
  914. return rc;
  915. /* Send initial configuration to hardware via SPI */
  916. return sja1105_static_config_upload(priv);
  917. }
  918. /* This is the "new way" for a MAC driver to configure its RGMII delay lines,
  919. * based on the explicit "rx-internal-delay-ps" and "tx-internal-delay-ps"
  920. * properties. It has the advantage of working with fixed links and with PHYs
  921. * that apply RGMII delays too, and the MAC driver needs not perform any
  922. * special checks.
  923. *
  924. * Previously we were acting upon the "phy-mode" property when we were
  925. * operating in fixed-link, basically acting as a PHY, but with a reversed
  926. * interpretation: PHY_INTERFACE_MODE_RGMII_TXID means that the MAC should
  927. * behave as if it is connected to a PHY which has applied RGMII delays in the
  928. * TX direction. So if anything, RX delays should have been added by the MAC,
  929. * but we were adding TX delays.
  930. *
  931. * If the "{rx,tx}-internal-delay-ps" properties are not specified, we fall
  932. * back to the legacy behavior and apply delays on fixed-link ports based on
  933. * the reverse interpretation of the phy-mode. This is a deviation from the
  934. * expected default behavior which is to simply apply no delays. To achieve
  935. * that behavior with the new bindings, it is mandatory to specify
  936. * "{rx,tx}-internal-delay-ps" with a value of 0.
  937. */
  938. static int sja1105_parse_rgmii_delays(struct sja1105_private *priv, int port,
  939. struct device_node *port_dn)
  940. {
  941. phy_interface_t phy_mode = priv->phy_mode[port];
  942. struct device *dev = &priv->spidev->dev;
  943. int rx_delay = -1, tx_delay = -1;
  944. if (!phy_interface_mode_is_rgmii(phy_mode))
  945. return 0;
  946. of_property_read_u32(port_dn, "rx-internal-delay-ps", &rx_delay);
  947. of_property_read_u32(port_dn, "tx-internal-delay-ps", &tx_delay);
  948. if (rx_delay == -1 && tx_delay == -1 && priv->fixed_link[port]) {
  949. dev_warn(dev,
  950. "Port %d interpreting RGMII delay settings based on \"phy-mode\" property, "
  951. "please update device tree to specify \"rx-internal-delay-ps\" and "
  952. "\"tx-internal-delay-ps\"",
  953. port);
  954. if (phy_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
  955. phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
  956. rx_delay = 2000;
  957. if (phy_mode == PHY_INTERFACE_MODE_RGMII_TXID ||
  958. phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
  959. tx_delay = 2000;
  960. }
  961. if (rx_delay < 0)
  962. rx_delay = 0;
  963. if (tx_delay < 0)
  964. tx_delay = 0;
  965. if ((rx_delay || tx_delay) && !priv->info->setup_rgmii_delay) {
  966. dev_err(dev, "Chip cannot apply RGMII delays\n");
  967. return -EINVAL;
  968. }
  969. if ((rx_delay && rx_delay < SJA1105_RGMII_DELAY_MIN_PS) ||
  970. (tx_delay && tx_delay < SJA1105_RGMII_DELAY_MIN_PS) ||
  971. (rx_delay > SJA1105_RGMII_DELAY_MAX_PS) ||
  972. (tx_delay > SJA1105_RGMII_DELAY_MAX_PS)) {
  973. dev_err(dev,
  974. "port %d RGMII delay values out of range, must be between %d and %d ps\n",
  975. port, SJA1105_RGMII_DELAY_MIN_PS, SJA1105_RGMII_DELAY_MAX_PS);
  976. return -ERANGE;
  977. }
  978. priv->rgmii_rx_delay_ps[port] = rx_delay;
  979. priv->rgmii_tx_delay_ps[port] = tx_delay;
  980. return 0;
  981. }
  982. static int sja1105_parse_ports_node(struct sja1105_private *priv,
  983. struct device_node *ports_node)
  984. {
  985. struct device *dev = &priv->spidev->dev;
  986. struct device_node *child;
  987. for_each_available_child_of_node(ports_node, child) {
  988. struct device_node *phy_node;
  989. phy_interface_t phy_mode;
  990. u32 index;
  991. int err;
  992. /* Get switch port number from DT */
  993. if (of_property_read_u32(child, "reg", &index) < 0) {
  994. dev_err(dev, "Port number not defined in device tree "
  995. "(property \"reg\")\n");
  996. of_node_put(child);
  997. return -ENODEV;
  998. }
  999. /* Get PHY mode from DT */
  1000. err = of_get_phy_mode(child, &phy_mode);
  1001. if (err) {
  1002. dev_err(dev, "Failed to read phy-mode or "
  1003. "phy-interface-type property for port %d\n",
  1004. index);
  1005. of_node_put(child);
  1006. return -ENODEV;
  1007. }
  1008. phy_node = of_parse_phandle(child, "phy-handle", 0);
  1009. if (!phy_node) {
  1010. if (!of_phy_is_fixed_link(child)) {
  1011. dev_err(dev, "phy-handle or fixed-link "
  1012. "properties missing!\n");
  1013. of_node_put(child);
  1014. return -ENODEV;
  1015. }
  1016. /* phy-handle is missing, but fixed-link isn't.
  1017. * So it's a fixed link. Default to PHY role.
  1018. */
  1019. priv->fixed_link[index] = true;
  1020. } else {
  1021. of_node_put(phy_node);
  1022. }
  1023. priv->phy_mode[index] = phy_mode;
  1024. err = sja1105_parse_rgmii_delays(priv, index, child);
  1025. if (err) {
  1026. of_node_put(child);
  1027. return err;
  1028. }
  1029. }
  1030. return 0;
  1031. }
  1032. static int sja1105_parse_dt(struct sja1105_private *priv)
  1033. {
  1034. struct device *dev = &priv->spidev->dev;
  1035. struct device_node *switch_node = dev->of_node;
  1036. struct device_node *ports_node;
  1037. int rc;
  1038. ports_node = of_get_child_by_name(switch_node, "ports");
  1039. if (!ports_node)
  1040. ports_node = of_get_child_by_name(switch_node, "ethernet-ports");
  1041. if (!ports_node) {
  1042. dev_err(dev, "Incorrect bindings: absent \"ports\" node\n");
  1043. return -ENODEV;
  1044. }
  1045. rc = sja1105_parse_ports_node(priv, ports_node);
  1046. of_node_put(ports_node);
  1047. return rc;
  1048. }
  1049. /* Convert link speed from SJA1105 to ethtool encoding */
  1050. static int sja1105_port_speed_to_ethtool(struct sja1105_private *priv,
  1051. u64 speed)
  1052. {
  1053. if (speed == priv->info->port_speed[SJA1105_SPEED_10MBPS])
  1054. return SPEED_10;
  1055. if (speed == priv->info->port_speed[SJA1105_SPEED_100MBPS])
  1056. return SPEED_100;
  1057. if (speed == priv->info->port_speed[SJA1105_SPEED_1000MBPS])
  1058. return SPEED_1000;
  1059. if (speed == priv->info->port_speed[SJA1105_SPEED_2500MBPS])
  1060. return SPEED_2500;
  1061. return SPEED_UNKNOWN;
  1062. }
  1063. /* Set link speed in the MAC configuration for a specific port. */
  1064. static int sja1105_adjust_port_config(struct sja1105_private *priv, int port,
  1065. int speed_mbps)
  1066. {
  1067. struct sja1105_mac_config_entry *mac;
  1068. struct device *dev = priv->ds->dev;
  1069. u64 speed;
  1070. int rc;
  1071. /* On P/Q/R/S, one can read from the device via the MAC reconfiguration
  1072. * tables. On E/T, MAC reconfig tables are not readable, only writable.
  1073. * We have to *know* what the MAC looks like. For the sake of keeping
  1074. * the code common, we'll use the static configuration tables as a
  1075. * reasonable approximation for both E/T and P/Q/R/S.
  1076. */
  1077. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  1078. switch (speed_mbps) {
  1079. case SPEED_UNKNOWN:
  1080. /* PHYLINK called sja1105_mac_config() to inform us about
  1081. * the state->interface, but AN has not completed and the
  1082. * speed is not yet valid. UM10944.pdf says that setting
  1083. * SJA1105_SPEED_AUTO at runtime disables the port, so that is
  1084. * ok for power consumption in case AN will never complete -
  1085. * otherwise PHYLINK should come back with a new update.
  1086. */
  1087. speed = priv->info->port_speed[SJA1105_SPEED_AUTO];
  1088. break;
  1089. case SPEED_10:
  1090. speed = priv->info->port_speed[SJA1105_SPEED_10MBPS];
  1091. break;
  1092. case SPEED_100:
  1093. speed = priv->info->port_speed[SJA1105_SPEED_100MBPS];
  1094. break;
  1095. case SPEED_1000:
  1096. speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS];
  1097. break;
  1098. case SPEED_2500:
  1099. speed = priv->info->port_speed[SJA1105_SPEED_2500MBPS];
  1100. break;
  1101. default:
  1102. dev_err(dev, "Invalid speed %iMbps\n", speed_mbps);
  1103. return -EINVAL;
  1104. }
  1105. /* Overwrite SJA1105_SPEED_AUTO from the static MAC configuration
  1106. * table, since this will be used for the clocking setup, and we no
  1107. * longer need to store it in the static config (already told hardware
  1108. * we want auto during upload phase).
  1109. * Actually for the SGMII port, the MAC is fixed at 1 Gbps and
  1110. * we need to configure the PCS only (if even that).
  1111. */
  1112. if (priv->phy_mode[port] == PHY_INTERFACE_MODE_SGMII)
  1113. mac[port].speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS];
  1114. else if (priv->phy_mode[port] == PHY_INTERFACE_MODE_2500BASEX)
  1115. mac[port].speed = priv->info->port_speed[SJA1105_SPEED_2500MBPS];
  1116. else
  1117. mac[port].speed = speed;
  1118. /* Write to the dynamic reconfiguration tables */
  1119. rc = sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
  1120. &mac[port], true);
  1121. if (rc < 0) {
  1122. dev_err(dev, "Failed to write MAC config: %d\n", rc);
  1123. return rc;
  1124. }
  1125. /* Reconfigure the PLLs for the RGMII interfaces (required 125 MHz at
  1126. * gigabit, 25 MHz at 100 Mbps and 2.5 MHz at 10 Mbps). For MII and
  1127. * RMII no change of the clock setup is required. Actually, changing
  1128. * the clock setup does interrupt the clock signal for a certain time
  1129. * which causes trouble for all PHYs relying on this signal.
  1130. */
  1131. if (!phy_interface_mode_is_rgmii(priv->phy_mode[port]))
  1132. return 0;
  1133. return sja1105_clocking_setup_port(priv, port);
  1134. }
  1135. static struct phylink_pcs *
  1136. sja1105_mac_select_pcs(struct dsa_switch *ds, int port, phy_interface_t iface)
  1137. {
  1138. struct sja1105_private *priv = ds->priv;
  1139. struct dw_xpcs *xpcs = priv->xpcs[port];
  1140. if (xpcs)
  1141. return &xpcs->pcs;
  1142. return NULL;
  1143. }
  1144. static void sja1105_mac_link_down(struct dsa_switch *ds, int port,
  1145. unsigned int mode,
  1146. phy_interface_t interface)
  1147. {
  1148. sja1105_inhibit_tx(ds->priv, BIT(port), true);
  1149. }
  1150. static void sja1105_mac_link_up(struct dsa_switch *ds, int port,
  1151. unsigned int mode,
  1152. phy_interface_t interface,
  1153. struct phy_device *phydev,
  1154. int speed, int duplex,
  1155. bool tx_pause, bool rx_pause)
  1156. {
  1157. struct sja1105_private *priv = ds->priv;
  1158. sja1105_adjust_port_config(priv, port, speed);
  1159. sja1105_inhibit_tx(priv, BIT(port), false);
  1160. }
  1161. static void sja1105_phylink_get_caps(struct dsa_switch *ds, int port,
  1162. struct phylink_config *config)
  1163. {
  1164. struct sja1105_private *priv = ds->priv;
  1165. struct sja1105_xmii_params_entry *mii;
  1166. phy_interface_t phy_mode;
  1167. /* This driver does not make use of the speed, duplex, pause or the
  1168. * advertisement in its mac_config, so it is safe to mark this driver
  1169. * as non-legacy.
  1170. */
  1171. config->legacy_pre_march2020 = false;
  1172. phy_mode = priv->phy_mode[port];
  1173. if (phy_mode == PHY_INTERFACE_MODE_SGMII ||
  1174. phy_mode == PHY_INTERFACE_MODE_2500BASEX) {
  1175. /* Changing the PHY mode on SERDES ports is possible and makes
  1176. * sense, because that is done through the XPCS. We allow
  1177. * changes between SGMII and 2500base-X.
  1178. */
  1179. if (priv->info->supports_sgmii[port])
  1180. __set_bit(PHY_INTERFACE_MODE_SGMII,
  1181. config->supported_interfaces);
  1182. if (priv->info->supports_2500basex[port])
  1183. __set_bit(PHY_INTERFACE_MODE_2500BASEX,
  1184. config->supported_interfaces);
  1185. } else {
  1186. /* The SJA1105 MAC programming model is through the static
  1187. * config (the xMII Mode table cannot be dynamically
  1188. * reconfigured), and we have to program that early.
  1189. */
  1190. __set_bit(phy_mode, config->supported_interfaces);
  1191. }
  1192. /* The MAC does not support pause frames, and also doesn't
  1193. * support half-duplex traffic modes.
  1194. */
  1195. config->mac_capabilities = MAC_10FD | MAC_100FD;
  1196. mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS].entries;
  1197. if (mii->xmii_mode[port] == XMII_MODE_RGMII ||
  1198. mii->xmii_mode[port] == XMII_MODE_SGMII)
  1199. config->mac_capabilities |= MAC_1000FD;
  1200. if (priv->info->supports_2500basex[port])
  1201. config->mac_capabilities |= MAC_2500FD;
  1202. }
  1203. static int
  1204. sja1105_find_static_fdb_entry(struct sja1105_private *priv, int port,
  1205. const struct sja1105_l2_lookup_entry *requested)
  1206. {
  1207. struct sja1105_l2_lookup_entry *l2_lookup;
  1208. struct sja1105_table *table;
  1209. int i;
  1210. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP];
  1211. l2_lookup = table->entries;
  1212. for (i = 0; i < table->entry_count; i++)
  1213. if (l2_lookup[i].macaddr == requested->macaddr &&
  1214. l2_lookup[i].vlanid == requested->vlanid &&
  1215. l2_lookup[i].destports & BIT(port))
  1216. return i;
  1217. return -1;
  1218. }
  1219. /* We want FDB entries added statically through the bridge command to persist
  1220. * across switch resets, which are a common thing during normal SJA1105
  1221. * operation. So we have to back them up in the static configuration tables
  1222. * and hence apply them on next static config upload... yay!
  1223. */
  1224. static int
  1225. sja1105_static_fdb_change(struct sja1105_private *priv, int port,
  1226. const struct sja1105_l2_lookup_entry *requested,
  1227. bool keep)
  1228. {
  1229. struct sja1105_l2_lookup_entry *l2_lookup;
  1230. struct sja1105_table *table;
  1231. int rc, match;
  1232. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP];
  1233. match = sja1105_find_static_fdb_entry(priv, port, requested);
  1234. if (match < 0) {
  1235. /* Can't delete a missing entry. */
  1236. if (!keep)
  1237. return 0;
  1238. /* No match => new entry */
  1239. rc = sja1105_table_resize(table, table->entry_count + 1);
  1240. if (rc)
  1241. return rc;
  1242. match = table->entry_count - 1;
  1243. }
  1244. /* Assign pointer after the resize (it may be new memory) */
  1245. l2_lookup = table->entries;
  1246. /* We have a match.
  1247. * If the job was to add this FDB entry, it's already done (mostly
  1248. * anyway, since the port forwarding mask may have changed, case in
  1249. * which we update it).
  1250. * Otherwise we have to delete it.
  1251. */
  1252. if (keep) {
  1253. l2_lookup[match] = *requested;
  1254. return 0;
  1255. }
  1256. /* To remove, the strategy is to overwrite the element with
  1257. * the last one, and then reduce the array size by 1
  1258. */
  1259. l2_lookup[match] = l2_lookup[table->entry_count - 1];
  1260. return sja1105_table_resize(table, table->entry_count - 1);
  1261. }
  1262. /* First-generation switches have a 4-way set associative TCAM that
  1263. * holds the FDB entries. An FDB index spans from 0 to 1023 and is comprised of
  1264. * a "bin" (grouping of 4 entries) and a "way" (an entry within a bin).
  1265. * For the placement of a newly learnt FDB entry, the switch selects the bin
  1266. * based on a hash function, and the way within that bin incrementally.
  1267. */
  1268. static int sja1105et_fdb_index(int bin, int way)
  1269. {
  1270. return bin * SJA1105ET_FDB_BIN_SIZE + way;
  1271. }
  1272. static int sja1105et_is_fdb_entry_in_bin(struct sja1105_private *priv, int bin,
  1273. const u8 *addr, u16 vid,
  1274. struct sja1105_l2_lookup_entry *match,
  1275. int *last_unused)
  1276. {
  1277. int way;
  1278. for (way = 0; way < SJA1105ET_FDB_BIN_SIZE; way++) {
  1279. struct sja1105_l2_lookup_entry l2_lookup = {0};
  1280. int index = sja1105et_fdb_index(bin, way);
  1281. /* Skip unused entries, optionally marking them
  1282. * into the return value
  1283. */
  1284. if (sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1285. index, &l2_lookup)) {
  1286. if (last_unused)
  1287. *last_unused = way;
  1288. continue;
  1289. }
  1290. if (l2_lookup.macaddr == ether_addr_to_u64(addr) &&
  1291. l2_lookup.vlanid == vid) {
  1292. if (match)
  1293. *match = l2_lookup;
  1294. return way;
  1295. }
  1296. }
  1297. /* Return an invalid entry index if not found */
  1298. return -1;
  1299. }
  1300. int sja1105et_fdb_add(struct dsa_switch *ds, int port,
  1301. const unsigned char *addr, u16 vid)
  1302. {
  1303. struct sja1105_l2_lookup_entry l2_lookup = {0}, tmp;
  1304. struct sja1105_private *priv = ds->priv;
  1305. struct device *dev = ds->dev;
  1306. int last_unused = -1;
  1307. int start, end, i;
  1308. int bin, way, rc;
  1309. bin = sja1105et_fdb_hash(priv, addr, vid);
  1310. way = sja1105et_is_fdb_entry_in_bin(priv, bin, addr, vid,
  1311. &l2_lookup, &last_unused);
  1312. if (way >= 0) {
  1313. /* We have an FDB entry. Is our port in the destination
  1314. * mask? If yes, we need to do nothing. If not, we need
  1315. * to rewrite the entry by adding this port to it.
  1316. */
  1317. if ((l2_lookup.destports & BIT(port)) && l2_lookup.lockeds)
  1318. return 0;
  1319. l2_lookup.destports |= BIT(port);
  1320. } else {
  1321. int index = sja1105et_fdb_index(bin, way);
  1322. /* We don't have an FDB entry. We construct a new one and
  1323. * try to find a place for it within the FDB table.
  1324. */
  1325. l2_lookup.macaddr = ether_addr_to_u64(addr);
  1326. l2_lookup.destports = BIT(port);
  1327. l2_lookup.vlanid = vid;
  1328. if (last_unused >= 0) {
  1329. way = last_unused;
  1330. } else {
  1331. /* Bin is full, need to evict somebody.
  1332. * Choose victim at random. If you get these messages
  1333. * often, you may need to consider changing the
  1334. * distribution function:
  1335. * static_config[BLK_IDX_L2_LOOKUP_PARAMS].entries->poly
  1336. */
  1337. get_random_bytes(&way, sizeof(u8));
  1338. way %= SJA1105ET_FDB_BIN_SIZE;
  1339. dev_warn(dev, "Warning, FDB bin %d full while adding entry for %pM. Evicting entry %u.\n",
  1340. bin, addr, way);
  1341. /* Evict entry */
  1342. sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1343. index, NULL, false);
  1344. }
  1345. }
  1346. l2_lookup.lockeds = true;
  1347. l2_lookup.index = sja1105et_fdb_index(bin, way);
  1348. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1349. l2_lookup.index, &l2_lookup,
  1350. true);
  1351. if (rc < 0)
  1352. return rc;
  1353. /* Invalidate a dynamically learned entry if that exists */
  1354. start = sja1105et_fdb_index(bin, 0);
  1355. end = sja1105et_fdb_index(bin, way);
  1356. for (i = start; i < end; i++) {
  1357. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1358. i, &tmp);
  1359. if (rc == -ENOENT)
  1360. continue;
  1361. if (rc)
  1362. return rc;
  1363. if (tmp.macaddr != ether_addr_to_u64(addr) || tmp.vlanid != vid)
  1364. continue;
  1365. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1366. i, NULL, false);
  1367. if (rc)
  1368. return rc;
  1369. break;
  1370. }
  1371. return sja1105_static_fdb_change(priv, port, &l2_lookup, true);
  1372. }
  1373. int sja1105et_fdb_del(struct dsa_switch *ds, int port,
  1374. const unsigned char *addr, u16 vid)
  1375. {
  1376. struct sja1105_l2_lookup_entry l2_lookup = {0};
  1377. struct sja1105_private *priv = ds->priv;
  1378. int index, bin, way, rc;
  1379. bool keep;
  1380. bin = sja1105et_fdb_hash(priv, addr, vid);
  1381. way = sja1105et_is_fdb_entry_in_bin(priv, bin, addr, vid,
  1382. &l2_lookup, NULL);
  1383. if (way < 0)
  1384. return 0;
  1385. index = sja1105et_fdb_index(bin, way);
  1386. /* We have an FDB entry. Is our port in the destination mask? If yes,
  1387. * we need to remove it. If the resulting port mask becomes empty, we
  1388. * need to completely evict the FDB entry.
  1389. * Otherwise we just write it back.
  1390. */
  1391. l2_lookup.destports &= ~BIT(port);
  1392. if (l2_lookup.destports)
  1393. keep = true;
  1394. else
  1395. keep = false;
  1396. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1397. index, &l2_lookup, keep);
  1398. if (rc < 0)
  1399. return rc;
  1400. return sja1105_static_fdb_change(priv, port, &l2_lookup, keep);
  1401. }
  1402. int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
  1403. const unsigned char *addr, u16 vid)
  1404. {
  1405. struct sja1105_l2_lookup_entry l2_lookup = {0}, tmp;
  1406. struct sja1105_private *priv = ds->priv;
  1407. int rc, i;
  1408. /* Search for an existing entry in the FDB table */
  1409. l2_lookup.macaddr = ether_addr_to_u64(addr);
  1410. l2_lookup.vlanid = vid;
  1411. l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
  1412. l2_lookup.mask_vlanid = VLAN_VID_MASK;
  1413. l2_lookup.destports = BIT(port);
  1414. tmp = l2_lookup;
  1415. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1416. SJA1105_SEARCH, &tmp);
  1417. if (rc == 0 && tmp.index != SJA1105_MAX_L2_LOOKUP_COUNT - 1) {
  1418. /* Found a static entry and this port is already in the entry's
  1419. * port mask => job done
  1420. */
  1421. if ((tmp.destports & BIT(port)) && tmp.lockeds)
  1422. return 0;
  1423. l2_lookup = tmp;
  1424. /* l2_lookup.index is populated by the switch in case it
  1425. * found something.
  1426. */
  1427. l2_lookup.destports |= BIT(port);
  1428. goto skip_finding_an_index;
  1429. }
  1430. /* Not found, so try to find an unused spot in the FDB.
  1431. * This is slightly inefficient because the strategy is knock-knock at
  1432. * every possible position from 0 to 1023.
  1433. */
  1434. for (i = 0; i < SJA1105_MAX_L2_LOOKUP_COUNT; i++) {
  1435. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1436. i, NULL);
  1437. if (rc < 0)
  1438. break;
  1439. }
  1440. if (i == SJA1105_MAX_L2_LOOKUP_COUNT) {
  1441. dev_err(ds->dev, "FDB is full, cannot add entry.\n");
  1442. return -EINVAL;
  1443. }
  1444. l2_lookup.index = i;
  1445. skip_finding_an_index:
  1446. l2_lookup.lockeds = true;
  1447. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1448. l2_lookup.index, &l2_lookup,
  1449. true);
  1450. if (rc < 0)
  1451. return rc;
  1452. /* The switch learns dynamic entries and looks up the FDB left to
  1453. * right. It is possible that our addition was concurrent with the
  1454. * dynamic learning of the same address, so now that the static entry
  1455. * has been installed, we are certain that address learning for this
  1456. * particular address has been turned off, so the dynamic entry either
  1457. * is in the FDB at an index smaller than the static one, or isn't (it
  1458. * can also be at a larger index, but in that case it is inactive
  1459. * because the static FDB entry will match first, and the dynamic one
  1460. * will eventually age out). Search for a dynamically learned address
  1461. * prior to our static one and invalidate it.
  1462. */
  1463. tmp = l2_lookup;
  1464. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1465. SJA1105_SEARCH, &tmp);
  1466. if (rc < 0) {
  1467. dev_err(ds->dev,
  1468. "port %d failed to read back entry for %pM vid %d: %pe\n",
  1469. port, addr, vid, ERR_PTR(rc));
  1470. return rc;
  1471. }
  1472. if (tmp.index < l2_lookup.index) {
  1473. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1474. tmp.index, NULL, false);
  1475. if (rc < 0)
  1476. return rc;
  1477. }
  1478. return sja1105_static_fdb_change(priv, port, &l2_lookup, true);
  1479. }
  1480. int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
  1481. const unsigned char *addr, u16 vid)
  1482. {
  1483. struct sja1105_l2_lookup_entry l2_lookup = {0};
  1484. struct sja1105_private *priv = ds->priv;
  1485. bool keep;
  1486. int rc;
  1487. l2_lookup.macaddr = ether_addr_to_u64(addr);
  1488. l2_lookup.vlanid = vid;
  1489. l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
  1490. l2_lookup.mask_vlanid = VLAN_VID_MASK;
  1491. l2_lookup.destports = BIT(port);
  1492. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1493. SJA1105_SEARCH, &l2_lookup);
  1494. if (rc < 0)
  1495. return 0;
  1496. l2_lookup.destports &= ~BIT(port);
  1497. /* Decide whether we remove just this port from the FDB entry,
  1498. * or if we remove it completely.
  1499. */
  1500. if (l2_lookup.destports)
  1501. keep = true;
  1502. else
  1503. keep = false;
  1504. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  1505. l2_lookup.index, &l2_lookup, keep);
  1506. if (rc < 0)
  1507. return rc;
  1508. return sja1105_static_fdb_change(priv, port, &l2_lookup, keep);
  1509. }
  1510. static int sja1105_fdb_add(struct dsa_switch *ds, int port,
  1511. const unsigned char *addr, u16 vid,
  1512. struct dsa_db db)
  1513. {
  1514. struct sja1105_private *priv = ds->priv;
  1515. int rc;
  1516. if (!vid) {
  1517. switch (db.type) {
  1518. case DSA_DB_PORT:
  1519. vid = dsa_tag_8021q_standalone_vid(db.dp);
  1520. break;
  1521. case DSA_DB_BRIDGE:
  1522. vid = dsa_tag_8021q_bridge_vid(db.bridge.num);
  1523. break;
  1524. default:
  1525. return -EOPNOTSUPP;
  1526. }
  1527. }
  1528. mutex_lock(&priv->fdb_lock);
  1529. rc = priv->info->fdb_add_cmd(ds, port, addr, vid);
  1530. mutex_unlock(&priv->fdb_lock);
  1531. return rc;
  1532. }
  1533. static int __sja1105_fdb_del(struct dsa_switch *ds, int port,
  1534. const unsigned char *addr, u16 vid,
  1535. struct dsa_db db)
  1536. {
  1537. struct sja1105_private *priv = ds->priv;
  1538. if (!vid) {
  1539. switch (db.type) {
  1540. case DSA_DB_PORT:
  1541. vid = dsa_tag_8021q_standalone_vid(db.dp);
  1542. break;
  1543. case DSA_DB_BRIDGE:
  1544. vid = dsa_tag_8021q_bridge_vid(db.bridge.num);
  1545. break;
  1546. default:
  1547. return -EOPNOTSUPP;
  1548. }
  1549. }
  1550. return priv->info->fdb_del_cmd(ds, port, addr, vid);
  1551. }
  1552. static int sja1105_fdb_del(struct dsa_switch *ds, int port,
  1553. const unsigned char *addr, u16 vid,
  1554. struct dsa_db db)
  1555. {
  1556. struct sja1105_private *priv = ds->priv;
  1557. int rc;
  1558. mutex_lock(&priv->fdb_lock);
  1559. rc = __sja1105_fdb_del(ds, port, addr, vid, db);
  1560. mutex_unlock(&priv->fdb_lock);
  1561. return rc;
  1562. }
  1563. static int sja1105_fdb_dump(struct dsa_switch *ds, int port,
  1564. dsa_fdb_dump_cb_t *cb, void *data)
  1565. {
  1566. struct sja1105_private *priv = ds->priv;
  1567. struct device *dev = ds->dev;
  1568. int i;
  1569. for (i = 0; i < SJA1105_MAX_L2_LOOKUP_COUNT; i++) {
  1570. struct sja1105_l2_lookup_entry l2_lookup = {0};
  1571. u8 macaddr[ETH_ALEN];
  1572. int rc;
  1573. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1574. i, &l2_lookup);
  1575. /* No fdb entry at i, not an issue */
  1576. if (rc == -ENOENT)
  1577. continue;
  1578. if (rc) {
  1579. dev_err(dev, "Failed to dump FDB: %d\n", rc);
  1580. return rc;
  1581. }
  1582. /* FDB dump callback is per port. This means we have to
  1583. * disregard a valid entry if it's not for this port, even if
  1584. * only to revisit it later. This is inefficient because the
  1585. * 1024-sized FDB table needs to be traversed 4 times through
  1586. * SPI during a 'bridge fdb show' command.
  1587. */
  1588. if (!(l2_lookup.destports & BIT(port)))
  1589. continue;
  1590. u64_to_ether_addr(l2_lookup.macaddr, macaddr);
  1591. /* Hardware FDB is shared for fdb and mdb, "bridge fdb show"
  1592. * only wants to see unicast
  1593. */
  1594. if (is_multicast_ether_addr(macaddr))
  1595. continue;
  1596. /* We need to hide the dsa_8021q VLANs from the user. */
  1597. if (vid_is_dsa_8021q(l2_lookup.vlanid))
  1598. l2_lookup.vlanid = 0;
  1599. rc = cb(macaddr, l2_lookup.vlanid, l2_lookup.lockeds, data);
  1600. if (rc)
  1601. return rc;
  1602. }
  1603. return 0;
  1604. }
  1605. static void sja1105_fast_age(struct dsa_switch *ds, int port)
  1606. {
  1607. struct dsa_port *dp = dsa_to_port(ds, port);
  1608. struct sja1105_private *priv = ds->priv;
  1609. struct dsa_db db = {
  1610. .type = DSA_DB_BRIDGE,
  1611. .bridge = {
  1612. .dev = dsa_port_bridge_dev_get(dp),
  1613. .num = dsa_port_bridge_num_get(dp),
  1614. },
  1615. };
  1616. int i;
  1617. mutex_lock(&priv->fdb_lock);
  1618. for (i = 0; i < SJA1105_MAX_L2_LOOKUP_COUNT; i++) {
  1619. struct sja1105_l2_lookup_entry l2_lookup = {0};
  1620. u8 macaddr[ETH_ALEN];
  1621. int rc;
  1622. rc = sja1105_dynamic_config_read(priv, BLK_IDX_L2_LOOKUP,
  1623. i, &l2_lookup);
  1624. /* No fdb entry at i, not an issue */
  1625. if (rc == -ENOENT)
  1626. continue;
  1627. if (rc) {
  1628. dev_err(ds->dev, "Failed to read FDB: %pe\n",
  1629. ERR_PTR(rc));
  1630. break;
  1631. }
  1632. if (!(l2_lookup.destports & BIT(port)))
  1633. continue;
  1634. /* Don't delete static FDB entries */
  1635. if (l2_lookup.lockeds)
  1636. continue;
  1637. u64_to_ether_addr(l2_lookup.macaddr, macaddr);
  1638. rc = __sja1105_fdb_del(ds, port, macaddr, l2_lookup.vlanid, db);
  1639. if (rc) {
  1640. dev_err(ds->dev,
  1641. "Failed to delete FDB entry %pM vid %lld: %pe\n",
  1642. macaddr, l2_lookup.vlanid, ERR_PTR(rc));
  1643. break;
  1644. }
  1645. }
  1646. mutex_unlock(&priv->fdb_lock);
  1647. }
  1648. static int sja1105_mdb_add(struct dsa_switch *ds, int port,
  1649. const struct switchdev_obj_port_mdb *mdb,
  1650. struct dsa_db db)
  1651. {
  1652. return sja1105_fdb_add(ds, port, mdb->addr, mdb->vid, db);
  1653. }
  1654. static int sja1105_mdb_del(struct dsa_switch *ds, int port,
  1655. const struct switchdev_obj_port_mdb *mdb,
  1656. struct dsa_db db)
  1657. {
  1658. return sja1105_fdb_del(ds, port, mdb->addr, mdb->vid, db);
  1659. }
  1660. /* Common function for unicast and broadcast flood configuration.
  1661. * Flooding is configured between each {ingress, egress} port pair, and since
  1662. * the bridge's semantics are those of "egress flooding", it means we must
  1663. * enable flooding towards this port from all ingress ports that are in the
  1664. * same forwarding domain.
  1665. */
  1666. static int sja1105_manage_flood_domains(struct sja1105_private *priv)
  1667. {
  1668. struct sja1105_l2_forwarding_entry *l2_fwd;
  1669. struct dsa_switch *ds = priv->ds;
  1670. int from, to, rc;
  1671. l2_fwd = priv->static_config.tables[BLK_IDX_L2_FORWARDING].entries;
  1672. for (from = 0; from < ds->num_ports; from++) {
  1673. u64 fl_domain = 0, bc_domain = 0;
  1674. for (to = 0; to < priv->ds->num_ports; to++) {
  1675. if (!sja1105_can_forward(l2_fwd, from, to))
  1676. continue;
  1677. if (priv->ucast_egress_floods & BIT(to))
  1678. fl_domain |= BIT(to);
  1679. if (priv->bcast_egress_floods & BIT(to))
  1680. bc_domain |= BIT(to);
  1681. }
  1682. /* Nothing changed, nothing to do */
  1683. if (l2_fwd[from].fl_domain == fl_domain &&
  1684. l2_fwd[from].bc_domain == bc_domain)
  1685. continue;
  1686. l2_fwd[from].fl_domain = fl_domain;
  1687. l2_fwd[from].bc_domain = bc_domain;
  1688. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_FORWARDING,
  1689. from, &l2_fwd[from], true);
  1690. if (rc < 0)
  1691. return rc;
  1692. }
  1693. return 0;
  1694. }
  1695. static int sja1105_bridge_member(struct dsa_switch *ds, int port,
  1696. struct dsa_bridge bridge, bool member)
  1697. {
  1698. struct sja1105_l2_forwarding_entry *l2_fwd;
  1699. struct sja1105_private *priv = ds->priv;
  1700. int i, rc;
  1701. l2_fwd = priv->static_config.tables[BLK_IDX_L2_FORWARDING].entries;
  1702. for (i = 0; i < ds->num_ports; i++) {
  1703. /* Add this port to the forwarding matrix of the
  1704. * other ports in the same bridge, and viceversa.
  1705. */
  1706. if (!dsa_is_user_port(ds, i))
  1707. continue;
  1708. /* For the ports already under the bridge, only one thing needs
  1709. * to be done, and that is to add this port to their
  1710. * reachability domain. So we can perform the SPI write for
  1711. * them immediately. However, for this port itself (the one
  1712. * that is new to the bridge), we need to add all other ports
  1713. * to its reachability domain. So we do that incrementally in
  1714. * this loop, and perform the SPI write only at the end, once
  1715. * the domain contains all other bridge ports.
  1716. */
  1717. if (i == port)
  1718. continue;
  1719. if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge))
  1720. continue;
  1721. sja1105_port_allow_traffic(l2_fwd, i, port, member);
  1722. sja1105_port_allow_traffic(l2_fwd, port, i, member);
  1723. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_FORWARDING,
  1724. i, &l2_fwd[i], true);
  1725. if (rc < 0)
  1726. return rc;
  1727. }
  1728. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_FORWARDING,
  1729. port, &l2_fwd[port], true);
  1730. if (rc)
  1731. return rc;
  1732. rc = sja1105_commit_pvid(ds, port);
  1733. if (rc)
  1734. return rc;
  1735. return sja1105_manage_flood_domains(priv);
  1736. }
  1737. static void sja1105_bridge_stp_state_set(struct dsa_switch *ds, int port,
  1738. u8 state)
  1739. {
  1740. struct dsa_port *dp = dsa_to_port(ds, port);
  1741. struct sja1105_private *priv = ds->priv;
  1742. struct sja1105_mac_config_entry *mac;
  1743. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  1744. switch (state) {
  1745. case BR_STATE_DISABLED:
  1746. case BR_STATE_BLOCKING:
  1747. /* From UM10944 description of DRPDTAG (why put this there?):
  1748. * "Management traffic flows to the port regardless of the state
  1749. * of the INGRESS flag". So BPDUs are still be allowed to pass.
  1750. * At the moment no difference between DISABLED and BLOCKING.
  1751. */
  1752. mac[port].ingress = false;
  1753. mac[port].egress = false;
  1754. mac[port].dyn_learn = false;
  1755. break;
  1756. case BR_STATE_LISTENING:
  1757. mac[port].ingress = true;
  1758. mac[port].egress = false;
  1759. mac[port].dyn_learn = false;
  1760. break;
  1761. case BR_STATE_LEARNING:
  1762. mac[port].ingress = true;
  1763. mac[port].egress = false;
  1764. mac[port].dyn_learn = dp->learning;
  1765. break;
  1766. case BR_STATE_FORWARDING:
  1767. mac[port].ingress = true;
  1768. mac[port].egress = true;
  1769. mac[port].dyn_learn = dp->learning;
  1770. break;
  1771. default:
  1772. dev_err(ds->dev, "invalid STP state: %d\n", state);
  1773. return;
  1774. }
  1775. sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
  1776. &mac[port], true);
  1777. }
  1778. static int sja1105_bridge_join(struct dsa_switch *ds, int port,
  1779. struct dsa_bridge bridge,
  1780. bool *tx_fwd_offload,
  1781. struct netlink_ext_ack *extack)
  1782. {
  1783. int rc;
  1784. rc = sja1105_bridge_member(ds, port, bridge, true);
  1785. if (rc)
  1786. return rc;
  1787. rc = dsa_tag_8021q_bridge_join(ds, port, bridge);
  1788. if (rc) {
  1789. sja1105_bridge_member(ds, port, bridge, false);
  1790. return rc;
  1791. }
  1792. *tx_fwd_offload = true;
  1793. return 0;
  1794. }
  1795. static void sja1105_bridge_leave(struct dsa_switch *ds, int port,
  1796. struct dsa_bridge bridge)
  1797. {
  1798. dsa_tag_8021q_bridge_leave(ds, port, bridge);
  1799. sja1105_bridge_member(ds, port, bridge, false);
  1800. }
  1801. #define BYTES_PER_KBIT (1000LL / 8)
  1802. /* Port 0 (the uC port) does not have CBS shapers */
  1803. #define SJA1110_FIXED_CBS(port, prio) ((((port) - 1) * SJA1105_NUM_TC) + (prio))
  1804. static int sja1105_find_cbs_shaper(struct sja1105_private *priv,
  1805. int port, int prio)
  1806. {
  1807. int i;
  1808. if (priv->info->fixed_cbs_mapping) {
  1809. i = SJA1110_FIXED_CBS(port, prio);
  1810. if (i >= 0 && i < priv->info->num_cbs_shapers)
  1811. return i;
  1812. return -1;
  1813. }
  1814. for (i = 0; i < priv->info->num_cbs_shapers; i++)
  1815. if (priv->cbs[i].port == port && priv->cbs[i].prio == prio)
  1816. return i;
  1817. return -1;
  1818. }
  1819. static int sja1105_find_unused_cbs_shaper(struct sja1105_private *priv)
  1820. {
  1821. int i;
  1822. if (priv->info->fixed_cbs_mapping)
  1823. return -1;
  1824. for (i = 0; i < priv->info->num_cbs_shapers; i++)
  1825. if (!priv->cbs[i].idle_slope && !priv->cbs[i].send_slope)
  1826. return i;
  1827. return -1;
  1828. }
  1829. static int sja1105_delete_cbs_shaper(struct sja1105_private *priv, int port,
  1830. int prio)
  1831. {
  1832. int i;
  1833. for (i = 0; i < priv->info->num_cbs_shapers; i++) {
  1834. struct sja1105_cbs_entry *cbs = &priv->cbs[i];
  1835. if (cbs->port == port && cbs->prio == prio) {
  1836. memset(cbs, 0, sizeof(*cbs));
  1837. return sja1105_dynamic_config_write(priv, BLK_IDX_CBS,
  1838. i, cbs, true);
  1839. }
  1840. }
  1841. return 0;
  1842. }
  1843. static int sja1105_setup_tc_cbs(struct dsa_switch *ds, int port,
  1844. struct tc_cbs_qopt_offload *offload)
  1845. {
  1846. struct sja1105_private *priv = ds->priv;
  1847. struct sja1105_cbs_entry *cbs;
  1848. s64 port_transmit_rate_kbps;
  1849. int index;
  1850. if (!offload->enable)
  1851. return sja1105_delete_cbs_shaper(priv, port, offload->queue);
  1852. /* The user may be replacing an existing shaper */
  1853. index = sja1105_find_cbs_shaper(priv, port, offload->queue);
  1854. if (index < 0) {
  1855. /* That isn't the case - see if we can allocate a new one */
  1856. index = sja1105_find_unused_cbs_shaper(priv);
  1857. if (index < 0)
  1858. return -ENOSPC;
  1859. }
  1860. cbs = &priv->cbs[index];
  1861. cbs->port = port;
  1862. cbs->prio = offload->queue;
  1863. /* locredit and sendslope are negative by definition. In hardware,
  1864. * positive values must be provided, and the negative sign is implicit.
  1865. */
  1866. cbs->credit_hi = offload->hicredit;
  1867. cbs->credit_lo = abs(offload->locredit);
  1868. /* User space is in kbits/sec, while the hardware in bytes/sec times
  1869. * link speed. Since the given offload->sendslope is good only for the
  1870. * current link speed anyway, and user space is likely to reprogram it
  1871. * when that changes, don't even bother to track the port's link speed,
  1872. * but deduce the port transmit rate from idleslope - sendslope.
  1873. */
  1874. port_transmit_rate_kbps = offload->idleslope - offload->sendslope;
  1875. cbs->idle_slope = div_s64(offload->idleslope * BYTES_PER_KBIT,
  1876. port_transmit_rate_kbps);
  1877. cbs->send_slope = div_s64(abs(offload->sendslope * BYTES_PER_KBIT),
  1878. port_transmit_rate_kbps);
  1879. /* Convert the negative values from 64-bit 2's complement
  1880. * to 32-bit 2's complement (for the case of 0x80000000 whose
  1881. * negative is still negative).
  1882. */
  1883. cbs->credit_lo &= GENMASK_ULL(31, 0);
  1884. cbs->send_slope &= GENMASK_ULL(31, 0);
  1885. return sja1105_dynamic_config_write(priv, BLK_IDX_CBS, index, cbs,
  1886. true);
  1887. }
  1888. static int sja1105_reload_cbs(struct sja1105_private *priv)
  1889. {
  1890. int rc = 0, i;
  1891. /* The credit based shapers are only allocated if
  1892. * CONFIG_NET_SCH_CBS is enabled.
  1893. */
  1894. if (!priv->cbs)
  1895. return 0;
  1896. for (i = 0; i < priv->info->num_cbs_shapers; i++) {
  1897. struct sja1105_cbs_entry *cbs = &priv->cbs[i];
  1898. if (!cbs->idle_slope && !cbs->send_slope)
  1899. continue;
  1900. rc = sja1105_dynamic_config_write(priv, BLK_IDX_CBS, i, cbs,
  1901. true);
  1902. if (rc)
  1903. break;
  1904. }
  1905. return rc;
  1906. }
  1907. static const char * const sja1105_reset_reasons[] = {
  1908. [SJA1105_VLAN_FILTERING] = "VLAN filtering",
  1909. [SJA1105_AGEING_TIME] = "Ageing time",
  1910. [SJA1105_SCHEDULING] = "Time-aware scheduling",
  1911. [SJA1105_BEST_EFFORT_POLICING] = "Best-effort policing",
  1912. [SJA1105_VIRTUAL_LINKS] = "Virtual links",
  1913. };
  1914. /* For situations where we need to change a setting at runtime that is only
  1915. * available through the static configuration, resetting the switch in order
  1916. * to upload the new static config is unavoidable. Back up the settings we
  1917. * modify at runtime (currently only MAC) and restore them after uploading,
  1918. * such that this operation is relatively seamless.
  1919. */
  1920. int sja1105_static_config_reload(struct sja1105_private *priv,
  1921. enum sja1105_reset_reason reason)
  1922. {
  1923. struct ptp_system_timestamp ptp_sts_before;
  1924. struct ptp_system_timestamp ptp_sts_after;
  1925. int speed_mbps[SJA1105_MAX_NUM_PORTS];
  1926. u16 bmcr[SJA1105_MAX_NUM_PORTS] = {0};
  1927. struct sja1105_mac_config_entry *mac;
  1928. struct dsa_switch *ds = priv->ds;
  1929. s64 t1, t2, t3, t4;
  1930. s64 t12, t34;
  1931. int rc, i;
  1932. s64 now;
  1933. mutex_lock(&priv->fdb_lock);
  1934. mutex_lock(&priv->mgmt_lock);
  1935. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  1936. /* Back up the dynamic link speed changed by sja1105_adjust_port_config
  1937. * in order to temporarily restore it to SJA1105_SPEED_AUTO - which the
  1938. * switch wants to see in the static config in order to allow us to
  1939. * change it through the dynamic interface later.
  1940. */
  1941. for (i = 0; i < ds->num_ports; i++) {
  1942. speed_mbps[i] = sja1105_port_speed_to_ethtool(priv,
  1943. mac[i].speed);
  1944. mac[i].speed = priv->info->port_speed[SJA1105_SPEED_AUTO];
  1945. if (priv->xpcs[i])
  1946. bmcr[i] = mdiobus_c45_read(priv->mdio_pcs, i,
  1947. MDIO_MMD_VEND2, MDIO_CTRL1);
  1948. }
  1949. /* No PTP operations can run right now */
  1950. mutex_lock(&priv->ptp_data.lock);
  1951. rc = __sja1105_ptp_gettimex(ds, &now, &ptp_sts_before);
  1952. if (rc < 0) {
  1953. mutex_unlock(&priv->ptp_data.lock);
  1954. goto out;
  1955. }
  1956. /* Reset switch and send updated static configuration */
  1957. rc = sja1105_static_config_upload(priv);
  1958. if (rc < 0) {
  1959. mutex_unlock(&priv->ptp_data.lock);
  1960. goto out;
  1961. }
  1962. rc = __sja1105_ptp_settime(ds, 0, &ptp_sts_after);
  1963. if (rc < 0) {
  1964. mutex_unlock(&priv->ptp_data.lock);
  1965. goto out;
  1966. }
  1967. t1 = timespec64_to_ns(&ptp_sts_before.pre_ts);
  1968. t2 = timespec64_to_ns(&ptp_sts_before.post_ts);
  1969. t3 = timespec64_to_ns(&ptp_sts_after.pre_ts);
  1970. t4 = timespec64_to_ns(&ptp_sts_after.post_ts);
  1971. /* Mid point, corresponds to pre-reset PTPCLKVAL */
  1972. t12 = t1 + (t2 - t1) / 2;
  1973. /* Mid point, corresponds to post-reset PTPCLKVAL, aka 0 */
  1974. t34 = t3 + (t4 - t3) / 2;
  1975. /* Advance PTPCLKVAL by the time it took since its readout */
  1976. now += (t34 - t12);
  1977. __sja1105_ptp_adjtime(ds, now);
  1978. mutex_unlock(&priv->ptp_data.lock);
  1979. dev_info(priv->ds->dev,
  1980. "Reset switch and programmed static config. Reason: %s\n",
  1981. sja1105_reset_reasons[reason]);
  1982. /* Configure the CGU (PLLs) for MII and RMII PHYs.
  1983. * For these interfaces there is no dynamic configuration
  1984. * needed, since PLLs have same settings at all speeds.
  1985. */
  1986. if (priv->info->clocking_setup) {
  1987. rc = priv->info->clocking_setup(priv);
  1988. if (rc < 0)
  1989. goto out;
  1990. }
  1991. for (i = 0; i < ds->num_ports; i++) {
  1992. struct dw_xpcs *xpcs = priv->xpcs[i];
  1993. unsigned int mode;
  1994. rc = sja1105_adjust_port_config(priv, i, speed_mbps[i]);
  1995. if (rc < 0)
  1996. goto out;
  1997. if (!xpcs)
  1998. continue;
  1999. if (bmcr[i] & BMCR_ANENABLE)
  2000. mode = MLO_AN_INBAND;
  2001. else if (priv->fixed_link[i])
  2002. mode = MLO_AN_FIXED;
  2003. else
  2004. mode = MLO_AN_PHY;
  2005. rc = xpcs_do_config(xpcs, priv->phy_mode[i], mode, NULL);
  2006. if (rc < 0)
  2007. goto out;
  2008. if (!phylink_autoneg_inband(mode)) {
  2009. int speed = SPEED_UNKNOWN;
  2010. if (priv->phy_mode[i] == PHY_INTERFACE_MODE_2500BASEX)
  2011. speed = SPEED_2500;
  2012. else if (bmcr[i] & BMCR_SPEED1000)
  2013. speed = SPEED_1000;
  2014. else if (bmcr[i] & BMCR_SPEED100)
  2015. speed = SPEED_100;
  2016. else
  2017. speed = SPEED_10;
  2018. xpcs_link_up(&xpcs->pcs, mode, priv->phy_mode[i],
  2019. speed, DUPLEX_FULL);
  2020. }
  2021. }
  2022. rc = sja1105_reload_cbs(priv);
  2023. if (rc < 0)
  2024. goto out;
  2025. out:
  2026. mutex_unlock(&priv->mgmt_lock);
  2027. mutex_unlock(&priv->fdb_lock);
  2028. return rc;
  2029. }
  2030. static enum dsa_tag_protocol
  2031. sja1105_get_tag_protocol(struct dsa_switch *ds, int port,
  2032. enum dsa_tag_protocol mp)
  2033. {
  2034. struct sja1105_private *priv = ds->priv;
  2035. return priv->info->tag_proto;
  2036. }
  2037. /* The TPID setting belongs to the General Parameters table,
  2038. * which can only be partially reconfigured at runtime (and not the TPID).
  2039. * So a switch reset is required.
  2040. */
  2041. int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled,
  2042. struct netlink_ext_ack *extack)
  2043. {
  2044. struct sja1105_general_params_entry *general_params;
  2045. struct sja1105_private *priv = ds->priv;
  2046. struct sja1105_table *table;
  2047. struct sja1105_rule *rule;
  2048. u16 tpid, tpid2;
  2049. int rc;
  2050. list_for_each_entry(rule, &priv->flow_block.rules, list) {
  2051. if (rule->type == SJA1105_RULE_VL) {
  2052. NL_SET_ERR_MSG_MOD(extack,
  2053. "Cannot change VLAN filtering with active VL rules");
  2054. return -EBUSY;
  2055. }
  2056. }
  2057. if (enabled) {
  2058. /* Enable VLAN filtering. */
  2059. tpid = ETH_P_8021Q;
  2060. tpid2 = ETH_P_8021AD;
  2061. } else {
  2062. /* Disable VLAN filtering. */
  2063. tpid = ETH_P_SJA1105;
  2064. tpid2 = ETH_P_SJA1105;
  2065. }
  2066. table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
  2067. general_params = table->entries;
  2068. /* EtherType used to identify inner tagged (C-tag) VLAN traffic */
  2069. general_params->tpid = tpid;
  2070. /* EtherType used to identify outer tagged (S-tag) VLAN traffic */
  2071. general_params->tpid2 = tpid2;
  2072. for (port = 0; port < ds->num_ports; port++) {
  2073. if (dsa_is_unused_port(ds, port))
  2074. continue;
  2075. rc = sja1105_commit_pvid(ds, port);
  2076. if (rc)
  2077. return rc;
  2078. }
  2079. rc = sja1105_static_config_reload(priv, SJA1105_VLAN_FILTERING);
  2080. if (rc)
  2081. NL_SET_ERR_MSG_MOD(extack, "Failed to change VLAN Ethertype");
  2082. return rc;
  2083. }
  2084. static int sja1105_vlan_add(struct sja1105_private *priv, int port, u16 vid,
  2085. u16 flags, bool allowed_ingress)
  2086. {
  2087. struct sja1105_vlan_lookup_entry *vlan;
  2088. struct sja1105_table *table;
  2089. int match, rc;
  2090. table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
  2091. match = sja1105_is_vlan_configured(priv, vid);
  2092. if (match < 0) {
  2093. rc = sja1105_table_resize(table, table->entry_count + 1);
  2094. if (rc)
  2095. return rc;
  2096. match = table->entry_count - 1;
  2097. }
  2098. /* Assign pointer after the resize (it's new memory) */
  2099. vlan = table->entries;
  2100. vlan[match].type_entry = SJA1110_VLAN_D_TAG;
  2101. vlan[match].vlanid = vid;
  2102. vlan[match].vlan_bc |= BIT(port);
  2103. if (allowed_ingress)
  2104. vlan[match].vmemb_port |= BIT(port);
  2105. else
  2106. vlan[match].vmemb_port &= ~BIT(port);
  2107. if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
  2108. vlan[match].tag_port &= ~BIT(port);
  2109. else
  2110. vlan[match].tag_port |= BIT(port);
  2111. return sja1105_dynamic_config_write(priv, BLK_IDX_VLAN_LOOKUP, vid,
  2112. &vlan[match], true);
  2113. }
  2114. static int sja1105_vlan_del(struct sja1105_private *priv, int port, u16 vid)
  2115. {
  2116. struct sja1105_vlan_lookup_entry *vlan;
  2117. struct sja1105_table *table;
  2118. bool keep = true;
  2119. int match, rc;
  2120. table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
  2121. match = sja1105_is_vlan_configured(priv, vid);
  2122. /* Can't delete a missing entry. */
  2123. if (match < 0)
  2124. return 0;
  2125. /* Assign pointer after the resize (it's new memory) */
  2126. vlan = table->entries;
  2127. vlan[match].vlanid = vid;
  2128. vlan[match].vlan_bc &= ~BIT(port);
  2129. vlan[match].vmemb_port &= ~BIT(port);
  2130. /* Also unset tag_port, just so we don't have a confusing bitmap
  2131. * (no practical purpose).
  2132. */
  2133. vlan[match].tag_port &= ~BIT(port);
  2134. /* If there's no port left as member of this VLAN,
  2135. * it's time for it to go.
  2136. */
  2137. if (!vlan[match].vmemb_port)
  2138. keep = false;
  2139. rc = sja1105_dynamic_config_write(priv, BLK_IDX_VLAN_LOOKUP, vid,
  2140. &vlan[match], keep);
  2141. if (rc < 0)
  2142. return rc;
  2143. if (!keep)
  2144. return sja1105_table_delete_entry(table, match);
  2145. return 0;
  2146. }
  2147. static int sja1105_bridge_vlan_add(struct dsa_switch *ds, int port,
  2148. const struct switchdev_obj_port_vlan *vlan,
  2149. struct netlink_ext_ack *extack)
  2150. {
  2151. struct sja1105_private *priv = ds->priv;
  2152. u16 flags = vlan->flags;
  2153. int rc;
  2154. /* Be sure to deny alterations to the configuration done by tag_8021q.
  2155. */
  2156. if (vid_is_dsa_8021q(vlan->vid)) {
  2157. NL_SET_ERR_MSG_MOD(extack,
  2158. "Range 3072-4095 reserved for dsa_8021q operation");
  2159. return -EBUSY;
  2160. }
  2161. /* Always install bridge VLANs as egress-tagged on CPU and DSA ports */
  2162. if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
  2163. flags = 0;
  2164. rc = sja1105_vlan_add(priv, port, vlan->vid, flags, true);
  2165. if (rc)
  2166. return rc;
  2167. if (vlan->flags & BRIDGE_VLAN_INFO_PVID)
  2168. priv->bridge_pvid[port] = vlan->vid;
  2169. return sja1105_commit_pvid(ds, port);
  2170. }
  2171. static int sja1105_bridge_vlan_del(struct dsa_switch *ds, int port,
  2172. const struct switchdev_obj_port_vlan *vlan)
  2173. {
  2174. struct sja1105_private *priv = ds->priv;
  2175. int rc;
  2176. rc = sja1105_vlan_del(priv, port, vlan->vid);
  2177. if (rc)
  2178. return rc;
  2179. /* In case the pvid was deleted, make sure that untagged packets will
  2180. * be dropped.
  2181. */
  2182. return sja1105_commit_pvid(ds, port);
  2183. }
  2184. static int sja1105_dsa_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid,
  2185. u16 flags)
  2186. {
  2187. struct sja1105_private *priv = ds->priv;
  2188. bool allowed_ingress = true;
  2189. int rc;
  2190. /* Prevent attackers from trying to inject a DSA tag from
  2191. * the outside world.
  2192. */
  2193. if (dsa_is_user_port(ds, port))
  2194. allowed_ingress = false;
  2195. rc = sja1105_vlan_add(priv, port, vid, flags, allowed_ingress);
  2196. if (rc)
  2197. return rc;
  2198. if (flags & BRIDGE_VLAN_INFO_PVID)
  2199. priv->tag_8021q_pvid[port] = vid;
  2200. return sja1105_commit_pvid(ds, port);
  2201. }
  2202. static int sja1105_dsa_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)
  2203. {
  2204. struct sja1105_private *priv = ds->priv;
  2205. return sja1105_vlan_del(priv, port, vid);
  2206. }
  2207. static int sja1105_prechangeupper(struct dsa_switch *ds, int port,
  2208. struct netdev_notifier_changeupper_info *info)
  2209. {
  2210. struct netlink_ext_ack *extack = info->info.extack;
  2211. struct net_device *upper = info->upper_dev;
  2212. struct dsa_switch_tree *dst = ds->dst;
  2213. struct dsa_port *dp;
  2214. if (is_vlan_dev(upper)) {
  2215. NL_SET_ERR_MSG_MOD(extack, "8021q uppers are not supported");
  2216. return -EBUSY;
  2217. }
  2218. if (netif_is_bridge_master(upper)) {
  2219. list_for_each_entry(dp, &dst->ports, list) {
  2220. struct net_device *br = dsa_port_bridge_dev_get(dp);
  2221. if (br && br != upper && br_vlan_enabled(br)) {
  2222. NL_SET_ERR_MSG_MOD(extack,
  2223. "Only one VLAN-aware bridge is supported");
  2224. return -EBUSY;
  2225. }
  2226. }
  2227. }
  2228. return 0;
  2229. }
  2230. static int sja1105_mgmt_xmit(struct dsa_switch *ds, int port, int slot,
  2231. struct sk_buff *skb, bool takets)
  2232. {
  2233. struct sja1105_mgmt_entry mgmt_route = {0};
  2234. struct sja1105_private *priv = ds->priv;
  2235. struct ethhdr *hdr;
  2236. int timeout = 10;
  2237. int rc;
  2238. hdr = eth_hdr(skb);
  2239. mgmt_route.macaddr = ether_addr_to_u64(hdr->h_dest);
  2240. mgmt_route.destports = BIT(port);
  2241. mgmt_route.enfport = 1;
  2242. mgmt_route.tsreg = 0;
  2243. mgmt_route.takets = takets;
  2244. rc = sja1105_dynamic_config_write(priv, BLK_IDX_MGMT_ROUTE,
  2245. slot, &mgmt_route, true);
  2246. if (rc < 0) {
  2247. kfree_skb(skb);
  2248. return rc;
  2249. }
  2250. /* Transfer skb to the host port. */
  2251. dsa_enqueue_skb(skb, dsa_to_port(ds, port)->slave);
  2252. /* Wait until the switch has processed the frame */
  2253. do {
  2254. rc = sja1105_dynamic_config_read(priv, BLK_IDX_MGMT_ROUTE,
  2255. slot, &mgmt_route);
  2256. if (rc < 0) {
  2257. dev_err_ratelimited(priv->ds->dev,
  2258. "failed to poll for mgmt route\n");
  2259. continue;
  2260. }
  2261. /* UM10944: The ENFPORT flag of the respective entry is
  2262. * cleared when a match is found. The host can use this
  2263. * flag as an acknowledgment.
  2264. */
  2265. cpu_relax();
  2266. } while (mgmt_route.enfport && --timeout);
  2267. if (!timeout) {
  2268. /* Clean up the management route so that a follow-up
  2269. * frame may not match on it by mistake.
  2270. * This is only hardware supported on P/Q/R/S - on E/T it is
  2271. * a no-op and we are silently discarding the -EOPNOTSUPP.
  2272. */
  2273. sja1105_dynamic_config_write(priv, BLK_IDX_MGMT_ROUTE,
  2274. slot, &mgmt_route, false);
  2275. dev_err_ratelimited(priv->ds->dev, "xmit timed out\n");
  2276. }
  2277. return NETDEV_TX_OK;
  2278. }
  2279. #define work_to_xmit_work(w) \
  2280. container_of((w), struct sja1105_deferred_xmit_work, work)
  2281. /* Deferred work is unfortunately necessary because setting up the management
  2282. * route cannot be done from atomit context (SPI transfer takes a sleepable
  2283. * lock on the bus)
  2284. */
  2285. static void sja1105_port_deferred_xmit(struct kthread_work *work)
  2286. {
  2287. struct sja1105_deferred_xmit_work *xmit_work = work_to_xmit_work(work);
  2288. struct sk_buff *clone, *skb = xmit_work->skb;
  2289. struct dsa_switch *ds = xmit_work->dp->ds;
  2290. struct sja1105_private *priv = ds->priv;
  2291. int port = xmit_work->dp->index;
  2292. clone = SJA1105_SKB_CB(skb)->clone;
  2293. mutex_lock(&priv->mgmt_lock);
  2294. sja1105_mgmt_xmit(ds, port, 0, skb, !!clone);
  2295. /* The clone, if there, was made by dsa_skb_tx_timestamp */
  2296. if (clone)
  2297. sja1105_ptp_txtstamp_skb(ds, port, clone);
  2298. mutex_unlock(&priv->mgmt_lock);
  2299. kfree(xmit_work);
  2300. }
  2301. static int sja1105_connect_tag_protocol(struct dsa_switch *ds,
  2302. enum dsa_tag_protocol proto)
  2303. {
  2304. struct sja1105_private *priv = ds->priv;
  2305. struct sja1105_tagger_data *tagger_data;
  2306. if (proto != priv->info->tag_proto)
  2307. return -EPROTONOSUPPORT;
  2308. tagger_data = sja1105_tagger_data(ds);
  2309. tagger_data->xmit_work_fn = sja1105_port_deferred_xmit;
  2310. tagger_data->meta_tstamp_handler = sja1110_process_meta_tstamp;
  2311. return 0;
  2312. }
  2313. /* The MAXAGE setting belongs to the L2 Forwarding Parameters table,
  2314. * which cannot be reconfigured at runtime. So a switch reset is required.
  2315. */
  2316. static int sja1105_set_ageing_time(struct dsa_switch *ds,
  2317. unsigned int ageing_time)
  2318. {
  2319. struct sja1105_l2_lookup_params_entry *l2_lookup_params;
  2320. struct sja1105_private *priv = ds->priv;
  2321. struct sja1105_table *table;
  2322. unsigned int maxage;
  2323. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP_PARAMS];
  2324. l2_lookup_params = table->entries;
  2325. maxage = SJA1105_AGEING_TIME_MS(ageing_time);
  2326. if (l2_lookup_params->maxage == maxage)
  2327. return 0;
  2328. l2_lookup_params->maxage = maxage;
  2329. return sja1105_static_config_reload(priv, SJA1105_AGEING_TIME);
  2330. }
  2331. static int sja1105_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
  2332. {
  2333. struct sja1105_l2_policing_entry *policing;
  2334. struct sja1105_private *priv = ds->priv;
  2335. new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN;
  2336. if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
  2337. new_mtu += VLAN_HLEN;
  2338. policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
  2339. if (policing[port].maxlen == new_mtu)
  2340. return 0;
  2341. policing[port].maxlen = new_mtu;
  2342. return sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING);
  2343. }
  2344. static int sja1105_get_max_mtu(struct dsa_switch *ds, int port)
  2345. {
  2346. return 2043 - VLAN_ETH_HLEN - ETH_FCS_LEN;
  2347. }
  2348. static int sja1105_port_setup_tc(struct dsa_switch *ds, int port,
  2349. enum tc_setup_type type,
  2350. void *type_data)
  2351. {
  2352. switch (type) {
  2353. case TC_SETUP_QDISC_TAPRIO:
  2354. return sja1105_setup_tc_taprio(ds, port, type_data);
  2355. case TC_SETUP_QDISC_CBS:
  2356. return sja1105_setup_tc_cbs(ds, port, type_data);
  2357. default:
  2358. return -EOPNOTSUPP;
  2359. }
  2360. }
  2361. /* We have a single mirror (@to) port, but can configure ingress and egress
  2362. * mirroring on all other (@from) ports.
  2363. * We need to allow mirroring rules only as long as the @to port is always the
  2364. * same, and we need to unset the @to port from mirr_port only when there is no
  2365. * mirroring rule that references it.
  2366. */
  2367. static int sja1105_mirror_apply(struct sja1105_private *priv, int from, int to,
  2368. bool ingress, bool enabled)
  2369. {
  2370. struct sja1105_general_params_entry *general_params;
  2371. struct sja1105_mac_config_entry *mac;
  2372. struct dsa_switch *ds = priv->ds;
  2373. struct sja1105_table *table;
  2374. bool already_enabled;
  2375. u64 new_mirr_port;
  2376. int rc;
  2377. table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
  2378. general_params = table->entries;
  2379. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  2380. already_enabled = (general_params->mirr_port != ds->num_ports);
  2381. if (already_enabled && enabled && general_params->mirr_port != to) {
  2382. dev_err(priv->ds->dev,
  2383. "Delete mirroring rules towards port %llu first\n",
  2384. general_params->mirr_port);
  2385. return -EBUSY;
  2386. }
  2387. new_mirr_port = to;
  2388. if (!enabled) {
  2389. bool keep = false;
  2390. int port;
  2391. /* Anybody still referencing mirr_port? */
  2392. for (port = 0; port < ds->num_ports; port++) {
  2393. if (mac[port].ing_mirr || mac[port].egr_mirr) {
  2394. keep = true;
  2395. break;
  2396. }
  2397. }
  2398. /* Unset already_enabled for next time */
  2399. if (!keep)
  2400. new_mirr_port = ds->num_ports;
  2401. }
  2402. if (new_mirr_port != general_params->mirr_port) {
  2403. general_params->mirr_port = new_mirr_port;
  2404. rc = sja1105_dynamic_config_write(priv, BLK_IDX_GENERAL_PARAMS,
  2405. 0, general_params, true);
  2406. if (rc < 0)
  2407. return rc;
  2408. }
  2409. if (ingress)
  2410. mac[from].ing_mirr = enabled;
  2411. else
  2412. mac[from].egr_mirr = enabled;
  2413. return sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, from,
  2414. &mac[from], true);
  2415. }
  2416. static int sja1105_mirror_add(struct dsa_switch *ds, int port,
  2417. struct dsa_mall_mirror_tc_entry *mirror,
  2418. bool ingress, struct netlink_ext_ack *extack)
  2419. {
  2420. return sja1105_mirror_apply(ds->priv, port, mirror->to_local_port,
  2421. ingress, true);
  2422. }
  2423. static void sja1105_mirror_del(struct dsa_switch *ds, int port,
  2424. struct dsa_mall_mirror_tc_entry *mirror)
  2425. {
  2426. sja1105_mirror_apply(ds->priv, port, mirror->to_local_port,
  2427. mirror->ingress, false);
  2428. }
  2429. static int sja1105_port_policer_add(struct dsa_switch *ds, int port,
  2430. struct dsa_mall_policer_tc_entry *policer)
  2431. {
  2432. struct sja1105_l2_policing_entry *policing;
  2433. struct sja1105_private *priv = ds->priv;
  2434. policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
  2435. /* In hardware, every 8 microseconds the credit level is incremented by
  2436. * the value of RATE bytes divided by 64, up to a maximum of SMAX
  2437. * bytes.
  2438. */
  2439. policing[port].rate = div_u64(512 * policer->rate_bytes_per_sec,
  2440. 1000000);
  2441. policing[port].smax = policer->burst;
  2442. return sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING);
  2443. }
  2444. static void sja1105_port_policer_del(struct dsa_switch *ds, int port)
  2445. {
  2446. struct sja1105_l2_policing_entry *policing;
  2447. struct sja1105_private *priv = ds->priv;
  2448. policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
  2449. policing[port].rate = SJA1105_RATE_MBPS(1000);
  2450. policing[port].smax = 65535;
  2451. sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING);
  2452. }
  2453. static int sja1105_port_set_learning(struct sja1105_private *priv, int port,
  2454. bool enabled)
  2455. {
  2456. struct sja1105_mac_config_entry *mac;
  2457. mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
  2458. mac[port].dyn_learn = enabled;
  2459. return sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
  2460. &mac[port], true);
  2461. }
  2462. static int sja1105_port_ucast_bcast_flood(struct sja1105_private *priv, int to,
  2463. struct switchdev_brport_flags flags)
  2464. {
  2465. if (flags.mask & BR_FLOOD) {
  2466. if (flags.val & BR_FLOOD)
  2467. priv->ucast_egress_floods |= BIT(to);
  2468. else
  2469. priv->ucast_egress_floods &= ~BIT(to);
  2470. }
  2471. if (flags.mask & BR_BCAST_FLOOD) {
  2472. if (flags.val & BR_BCAST_FLOOD)
  2473. priv->bcast_egress_floods |= BIT(to);
  2474. else
  2475. priv->bcast_egress_floods &= ~BIT(to);
  2476. }
  2477. return sja1105_manage_flood_domains(priv);
  2478. }
  2479. static int sja1105_port_mcast_flood(struct sja1105_private *priv, int to,
  2480. struct switchdev_brport_flags flags,
  2481. struct netlink_ext_ack *extack)
  2482. {
  2483. struct sja1105_l2_lookup_entry *l2_lookup;
  2484. struct sja1105_table *table;
  2485. int match, rc;
  2486. mutex_lock(&priv->fdb_lock);
  2487. table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP];
  2488. l2_lookup = table->entries;
  2489. for (match = 0; match < table->entry_count; match++)
  2490. if (l2_lookup[match].macaddr == SJA1105_UNKNOWN_MULTICAST &&
  2491. l2_lookup[match].mask_macaddr == SJA1105_UNKNOWN_MULTICAST)
  2492. break;
  2493. if (match == table->entry_count) {
  2494. NL_SET_ERR_MSG_MOD(extack,
  2495. "Could not find FDB entry for unknown multicast");
  2496. rc = -ENOSPC;
  2497. goto out;
  2498. }
  2499. if (flags.val & BR_MCAST_FLOOD)
  2500. l2_lookup[match].destports |= BIT(to);
  2501. else
  2502. l2_lookup[match].destports &= ~BIT(to);
  2503. rc = sja1105_dynamic_config_write(priv, BLK_IDX_L2_LOOKUP,
  2504. l2_lookup[match].index,
  2505. &l2_lookup[match], true);
  2506. out:
  2507. mutex_unlock(&priv->fdb_lock);
  2508. return rc;
  2509. }
  2510. static int sja1105_port_pre_bridge_flags(struct dsa_switch *ds, int port,
  2511. struct switchdev_brport_flags flags,
  2512. struct netlink_ext_ack *extack)
  2513. {
  2514. struct sja1105_private *priv = ds->priv;
  2515. if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
  2516. BR_BCAST_FLOOD))
  2517. return -EINVAL;
  2518. if (flags.mask & (BR_FLOOD | BR_MCAST_FLOOD) &&
  2519. !priv->info->can_limit_mcast_flood) {
  2520. bool multicast = !!(flags.val & BR_MCAST_FLOOD);
  2521. bool unicast = !!(flags.val & BR_FLOOD);
  2522. if (unicast != multicast) {
  2523. NL_SET_ERR_MSG_MOD(extack,
  2524. "This chip cannot configure multicast flooding independently of unicast");
  2525. return -EINVAL;
  2526. }
  2527. }
  2528. return 0;
  2529. }
  2530. static int sja1105_port_bridge_flags(struct dsa_switch *ds, int port,
  2531. struct switchdev_brport_flags flags,
  2532. struct netlink_ext_ack *extack)
  2533. {
  2534. struct sja1105_private *priv = ds->priv;
  2535. int rc;
  2536. if (flags.mask & BR_LEARNING) {
  2537. bool learn_ena = !!(flags.val & BR_LEARNING);
  2538. rc = sja1105_port_set_learning(priv, port, learn_ena);
  2539. if (rc)
  2540. return rc;
  2541. }
  2542. if (flags.mask & (BR_FLOOD | BR_BCAST_FLOOD)) {
  2543. rc = sja1105_port_ucast_bcast_flood(priv, port, flags);
  2544. if (rc)
  2545. return rc;
  2546. }
  2547. /* For chips that can't offload BR_MCAST_FLOOD independently, there
  2548. * is nothing to do here, we ensured the configuration is in sync by
  2549. * offloading BR_FLOOD.
  2550. */
  2551. if (flags.mask & BR_MCAST_FLOOD && priv->info->can_limit_mcast_flood) {
  2552. rc = sja1105_port_mcast_flood(priv, port, flags,
  2553. extack);
  2554. if (rc)
  2555. return rc;
  2556. }
  2557. return 0;
  2558. }
  2559. /* The programming model for the SJA1105 switch is "all-at-once" via static
  2560. * configuration tables. Some of these can be dynamically modified at runtime,
  2561. * but not the xMII mode parameters table.
  2562. * Furthermode, some PHYs may not have crystals for generating their clocks
  2563. * (e.g. RMII). Instead, their 50MHz clock is supplied via the SJA1105 port's
  2564. * ref_clk pin. So port clocking needs to be initialized early, before
  2565. * connecting to PHYs is attempted, otherwise they won't respond through MDIO.
  2566. * Setting correct PHY link speed does not matter now.
  2567. * But dsa_slave_phy_setup is called later than sja1105_setup, so the PHY
  2568. * bindings are not yet parsed by DSA core. We need to parse early so that we
  2569. * can populate the xMII mode parameters table.
  2570. */
  2571. static int sja1105_setup(struct dsa_switch *ds)
  2572. {
  2573. struct sja1105_private *priv = ds->priv;
  2574. int rc;
  2575. if (priv->info->disable_microcontroller) {
  2576. rc = priv->info->disable_microcontroller(priv);
  2577. if (rc < 0) {
  2578. dev_err(ds->dev,
  2579. "Failed to disable microcontroller: %pe\n",
  2580. ERR_PTR(rc));
  2581. return rc;
  2582. }
  2583. }
  2584. /* Create and send configuration down to device */
  2585. rc = sja1105_static_config_load(priv);
  2586. if (rc < 0) {
  2587. dev_err(ds->dev, "Failed to load static config: %d\n", rc);
  2588. return rc;
  2589. }
  2590. /* Configure the CGU (PHY link modes and speeds) */
  2591. if (priv->info->clocking_setup) {
  2592. rc = priv->info->clocking_setup(priv);
  2593. if (rc < 0) {
  2594. dev_err(ds->dev,
  2595. "Failed to configure MII clocking: %pe\n",
  2596. ERR_PTR(rc));
  2597. goto out_static_config_free;
  2598. }
  2599. }
  2600. sja1105_tas_setup(ds);
  2601. sja1105_flower_setup(ds);
  2602. rc = sja1105_ptp_clock_register(ds);
  2603. if (rc < 0) {
  2604. dev_err(ds->dev, "Failed to register PTP clock: %d\n", rc);
  2605. goto out_flower_teardown;
  2606. }
  2607. rc = sja1105_mdiobus_register(ds);
  2608. if (rc < 0) {
  2609. dev_err(ds->dev, "Failed to register MDIO bus: %pe\n",
  2610. ERR_PTR(rc));
  2611. goto out_ptp_clock_unregister;
  2612. }
  2613. rc = sja1105_devlink_setup(ds);
  2614. if (rc < 0)
  2615. goto out_mdiobus_unregister;
  2616. rtnl_lock();
  2617. rc = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q));
  2618. rtnl_unlock();
  2619. if (rc)
  2620. goto out_devlink_teardown;
  2621. /* On SJA1105, VLAN filtering per se is always enabled in hardware.
  2622. * The only thing we can do to disable it is lie about what the 802.1Q
  2623. * EtherType is.
  2624. * So it will still try to apply VLAN filtering, but all ingress
  2625. * traffic (except frames received with EtherType of ETH_P_SJA1105)
  2626. * will be internally tagged with a distorted VLAN header where the
  2627. * TPID is ETH_P_SJA1105, and the VLAN ID is the port pvid.
  2628. */
  2629. ds->vlan_filtering_is_global = true;
  2630. ds->untag_bridge_pvid = true;
  2631. ds->fdb_isolation = true;
  2632. /* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */
  2633. ds->max_num_bridges = 7;
  2634. /* Advertise the 8 egress queues */
  2635. ds->num_tx_queues = SJA1105_NUM_TC;
  2636. ds->mtu_enforcement_ingress = true;
  2637. ds->assisted_learning_on_cpu_port = true;
  2638. return 0;
  2639. out_devlink_teardown:
  2640. sja1105_devlink_teardown(ds);
  2641. out_mdiobus_unregister:
  2642. sja1105_mdiobus_unregister(ds);
  2643. out_ptp_clock_unregister:
  2644. sja1105_ptp_clock_unregister(ds);
  2645. out_flower_teardown:
  2646. sja1105_flower_teardown(ds);
  2647. sja1105_tas_teardown(ds);
  2648. out_static_config_free:
  2649. sja1105_static_config_free(&priv->static_config);
  2650. return rc;
  2651. }
  2652. static void sja1105_teardown(struct dsa_switch *ds)
  2653. {
  2654. struct sja1105_private *priv = ds->priv;
  2655. rtnl_lock();
  2656. dsa_tag_8021q_unregister(ds);
  2657. rtnl_unlock();
  2658. sja1105_devlink_teardown(ds);
  2659. sja1105_mdiobus_unregister(ds);
  2660. sja1105_ptp_clock_unregister(ds);
  2661. sja1105_flower_teardown(ds);
  2662. sja1105_tas_teardown(ds);
  2663. sja1105_static_config_free(&priv->static_config);
  2664. }
  2665. static const struct dsa_switch_ops sja1105_switch_ops = {
  2666. .get_tag_protocol = sja1105_get_tag_protocol,
  2667. .connect_tag_protocol = sja1105_connect_tag_protocol,
  2668. .setup = sja1105_setup,
  2669. .teardown = sja1105_teardown,
  2670. .set_ageing_time = sja1105_set_ageing_time,
  2671. .port_change_mtu = sja1105_change_mtu,
  2672. .port_max_mtu = sja1105_get_max_mtu,
  2673. .phylink_get_caps = sja1105_phylink_get_caps,
  2674. .phylink_mac_select_pcs = sja1105_mac_select_pcs,
  2675. .phylink_mac_link_up = sja1105_mac_link_up,
  2676. .phylink_mac_link_down = sja1105_mac_link_down,
  2677. .get_strings = sja1105_get_strings,
  2678. .get_ethtool_stats = sja1105_get_ethtool_stats,
  2679. .get_sset_count = sja1105_get_sset_count,
  2680. .get_ts_info = sja1105_get_ts_info,
  2681. .port_fdb_dump = sja1105_fdb_dump,
  2682. .port_fdb_add = sja1105_fdb_add,
  2683. .port_fdb_del = sja1105_fdb_del,
  2684. .port_fast_age = sja1105_fast_age,
  2685. .port_bridge_join = sja1105_bridge_join,
  2686. .port_bridge_leave = sja1105_bridge_leave,
  2687. .port_pre_bridge_flags = sja1105_port_pre_bridge_flags,
  2688. .port_bridge_flags = sja1105_port_bridge_flags,
  2689. .port_stp_state_set = sja1105_bridge_stp_state_set,
  2690. .port_vlan_filtering = sja1105_vlan_filtering,
  2691. .port_vlan_add = sja1105_bridge_vlan_add,
  2692. .port_vlan_del = sja1105_bridge_vlan_del,
  2693. .port_mdb_add = sja1105_mdb_add,
  2694. .port_mdb_del = sja1105_mdb_del,
  2695. .port_hwtstamp_get = sja1105_hwtstamp_get,
  2696. .port_hwtstamp_set = sja1105_hwtstamp_set,
  2697. .port_rxtstamp = sja1105_port_rxtstamp,
  2698. .port_txtstamp = sja1105_port_txtstamp,
  2699. .port_setup_tc = sja1105_port_setup_tc,
  2700. .port_mirror_add = sja1105_mirror_add,
  2701. .port_mirror_del = sja1105_mirror_del,
  2702. .port_policer_add = sja1105_port_policer_add,
  2703. .port_policer_del = sja1105_port_policer_del,
  2704. .cls_flower_add = sja1105_cls_flower_add,
  2705. .cls_flower_del = sja1105_cls_flower_del,
  2706. .cls_flower_stats = sja1105_cls_flower_stats,
  2707. .devlink_info_get = sja1105_devlink_info_get,
  2708. .tag_8021q_vlan_add = sja1105_dsa_8021q_vlan_add,
  2709. .tag_8021q_vlan_del = sja1105_dsa_8021q_vlan_del,
  2710. .port_prechangeupper = sja1105_prechangeupper,
  2711. };
  2712. static const struct of_device_id sja1105_dt_ids[];
  2713. static int sja1105_check_device_id(struct sja1105_private *priv)
  2714. {
  2715. const struct sja1105_regs *regs = priv->info->regs;
  2716. u8 prod_id[SJA1105_SIZE_DEVICE_ID] = {0};
  2717. struct device *dev = &priv->spidev->dev;
  2718. const struct of_device_id *match;
  2719. u32 device_id;
  2720. u64 part_no;
  2721. int rc;
  2722. rc = sja1105_xfer_u32(priv, SPI_READ, regs->device_id, &device_id,
  2723. NULL);
  2724. if (rc < 0)
  2725. return rc;
  2726. rc = sja1105_xfer_buf(priv, SPI_READ, regs->prod_id, prod_id,
  2727. SJA1105_SIZE_DEVICE_ID);
  2728. if (rc < 0)
  2729. return rc;
  2730. sja1105_unpack(prod_id, &part_no, 19, 4, SJA1105_SIZE_DEVICE_ID);
  2731. for (match = sja1105_dt_ids; match->compatible[0]; match++) {
  2732. const struct sja1105_info *info = match->data;
  2733. /* Is what's been probed in our match table at all? */
  2734. if (info->device_id != device_id || info->part_no != part_no)
  2735. continue;
  2736. /* But is it what's in the device tree? */
  2737. if (priv->info->device_id != device_id ||
  2738. priv->info->part_no != part_no) {
  2739. dev_warn(dev, "Device tree specifies chip %s but found %s, please fix it!\n",
  2740. priv->info->name, info->name);
  2741. /* It isn't. No problem, pick that up. */
  2742. priv->info = info;
  2743. }
  2744. return 0;
  2745. }
  2746. dev_err(dev, "Unexpected {device ID, part number}: 0x%x 0x%llx\n",
  2747. device_id, part_no);
  2748. return -ENODEV;
  2749. }
  2750. static int sja1105_probe(struct spi_device *spi)
  2751. {
  2752. struct device *dev = &spi->dev;
  2753. struct sja1105_private *priv;
  2754. size_t max_xfer, max_msg;
  2755. struct dsa_switch *ds;
  2756. int rc;
  2757. if (!dev->of_node) {
  2758. dev_err(dev, "No DTS bindings for SJA1105 driver\n");
  2759. return -EINVAL;
  2760. }
  2761. rc = sja1105_hw_reset(dev, 1, 1);
  2762. if (rc)
  2763. return rc;
  2764. priv = devm_kzalloc(dev, sizeof(struct sja1105_private), GFP_KERNEL);
  2765. if (!priv)
  2766. return -ENOMEM;
  2767. /* Populate our driver private structure (priv) based on
  2768. * the device tree node that was probed (spi)
  2769. */
  2770. priv->spidev = spi;
  2771. spi_set_drvdata(spi, priv);
  2772. /* Configure the SPI bus */
  2773. spi->bits_per_word = 8;
  2774. rc = spi_setup(spi);
  2775. if (rc < 0) {
  2776. dev_err(dev, "Could not init SPI\n");
  2777. return rc;
  2778. }
  2779. /* In sja1105_xfer, we send spi_messages composed of two spi_transfers:
  2780. * a small one for the message header and another one for the current
  2781. * chunk of the packed buffer.
  2782. * Check that the restrictions imposed by the SPI controller are
  2783. * respected: the chunk buffer is smaller than the max transfer size,
  2784. * and the total length of the chunk plus its message header is smaller
  2785. * than the max message size.
  2786. * We do that during probe time since the maximum transfer size is a
  2787. * runtime invariant.
  2788. */
  2789. max_xfer = spi_max_transfer_size(spi);
  2790. max_msg = spi_max_message_size(spi);
  2791. /* We need to send at least one 64-bit word of SPI payload per message
  2792. * in order to be able to make useful progress.
  2793. */
  2794. if (max_msg < SJA1105_SIZE_SPI_MSG_HEADER + 8) {
  2795. dev_err(dev, "SPI master cannot send large enough buffers, aborting\n");
  2796. return -EINVAL;
  2797. }
  2798. priv->max_xfer_len = SJA1105_SIZE_SPI_MSG_MAXLEN;
  2799. if (priv->max_xfer_len > max_xfer)
  2800. priv->max_xfer_len = max_xfer;
  2801. if (priv->max_xfer_len > max_msg - SJA1105_SIZE_SPI_MSG_HEADER)
  2802. priv->max_xfer_len = max_msg - SJA1105_SIZE_SPI_MSG_HEADER;
  2803. priv->info = of_device_get_match_data(dev);
  2804. /* Detect hardware device */
  2805. rc = sja1105_check_device_id(priv);
  2806. if (rc < 0) {
  2807. dev_err(dev, "Device ID check failed: %d\n", rc);
  2808. return rc;
  2809. }
  2810. dev_info(dev, "Probed switch chip: %s\n", priv->info->name);
  2811. ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
  2812. if (!ds)
  2813. return -ENOMEM;
  2814. ds->dev = dev;
  2815. ds->num_ports = priv->info->num_ports;
  2816. ds->ops = &sja1105_switch_ops;
  2817. ds->priv = priv;
  2818. priv->ds = ds;
  2819. mutex_init(&priv->ptp_data.lock);
  2820. mutex_init(&priv->dynamic_config_lock);
  2821. mutex_init(&priv->mgmt_lock);
  2822. mutex_init(&priv->fdb_lock);
  2823. spin_lock_init(&priv->ts_id_lock);
  2824. rc = sja1105_parse_dt(priv);
  2825. if (rc < 0) {
  2826. dev_err(ds->dev, "Failed to parse DT: %d\n", rc);
  2827. return rc;
  2828. }
  2829. if (IS_ENABLED(CONFIG_NET_SCH_CBS)) {
  2830. priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers,
  2831. sizeof(struct sja1105_cbs_entry),
  2832. GFP_KERNEL);
  2833. if (!priv->cbs)
  2834. return -ENOMEM;
  2835. }
  2836. return dsa_register_switch(priv->ds);
  2837. }
  2838. static void sja1105_remove(struct spi_device *spi)
  2839. {
  2840. struct sja1105_private *priv = spi_get_drvdata(spi);
  2841. if (!priv)
  2842. return;
  2843. dsa_unregister_switch(priv->ds);
  2844. }
  2845. static void sja1105_shutdown(struct spi_device *spi)
  2846. {
  2847. struct sja1105_private *priv = spi_get_drvdata(spi);
  2848. if (!priv)
  2849. return;
  2850. dsa_switch_shutdown(priv->ds);
  2851. spi_set_drvdata(spi, NULL);
  2852. }
  2853. static const struct of_device_id sja1105_dt_ids[] = {
  2854. { .compatible = "nxp,sja1105e", .data = &sja1105e_info },
  2855. { .compatible = "nxp,sja1105t", .data = &sja1105t_info },
  2856. { .compatible = "nxp,sja1105p", .data = &sja1105p_info },
  2857. { .compatible = "nxp,sja1105q", .data = &sja1105q_info },
  2858. { .compatible = "nxp,sja1105r", .data = &sja1105r_info },
  2859. { .compatible = "nxp,sja1105s", .data = &sja1105s_info },
  2860. { .compatible = "nxp,sja1110a", .data = &sja1110a_info },
  2861. { .compatible = "nxp,sja1110b", .data = &sja1110b_info },
  2862. { .compatible = "nxp,sja1110c", .data = &sja1110c_info },
  2863. { .compatible = "nxp,sja1110d", .data = &sja1110d_info },
  2864. { /* sentinel */ },
  2865. };
  2866. MODULE_DEVICE_TABLE(of, sja1105_dt_ids);
  2867. static const struct spi_device_id sja1105_spi_ids[] = {
  2868. { "sja1105e" },
  2869. { "sja1105t" },
  2870. { "sja1105p" },
  2871. { "sja1105q" },
  2872. { "sja1105r" },
  2873. { "sja1105s" },
  2874. { "sja1110a" },
  2875. { "sja1110b" },
  2876. { "sja1110c" },
  2877. { "sja1110d" },
  2878. { },
  2879. };
  2880. MODULE_DEVICE_TABLE(spi, sja1105_spi_ids);
  2881. static struct spi_driver sja1105_driver = {
  2882. .driver = {
  2883. .name = "sja1105",
  2884. .owner = THIS_MODULE,
  2885. .of_match_table = of_match_ptr(sja1105_dt_ids),
  2886. },
  2887. .id_table = sja1105_spi_ids,
  2888. .probe = sja1105_probe,
  2889. .remove = sja1105_remove,
  2890. .shutdown = sja1105_shutdown,
  2891. };
  2892. module_spi_driver(sja1105_driver);
  2893. MODULE_AUTHOR("Vladimir Oltean <[email protected]>");
  2894. MODULE_AUTHOR("Georg Waibel <[email protected]>");
  2895. MODULE_DESCRIPTION("SJA1105 Driver");
  2896. MODULE_LICENSE("GPL v2");