cpsw.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662
  1. /*
  2. * Texas Instruments Ethernet Switch Driver
  3. *
  4. * Copyright (C) 2012 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/io.h>
  17. #include <linux/clk.h>
  18. #include <linux/timer.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/irqreturn.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/if_ether.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/net_tstamp.h>
  27. #include <linux/phy.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/delay.h>
  30. #include <linux/pm_runtime.h>
  31. #include <linux/gpio.h>
  32. #include <linux/of.h>
  33. #include <linux/of_mdio.h>
  34. #include <linux/of_net.h>
  35. #include <linux/of_device.h>
  36. #include <linux/if_vlan.h>
  37. #include <linux/pinctrl/consumer.h>
  38. #include "cpsw.h"
  39. #include "cpsw_ale.h"
  40. #include "cpts.h"
  41. #include "davinci_cpdma.h"
  42. #define CPSW_DEBUG (NETIF_MSG_HW | NETIF_MSG_WOL | \
  43. NETIF_MSG_DRV | NETIF_MSG_LINK | \
  44. NETIF_MSG_IFUP | NETIF_MSG_INTR | \
  45. NETIF_MSG_PROBE | NETIF_MSG_TIMER | \
  46. NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | \
  47. NETIF_MSG_TX_ERR | NETIF_MSG_TX_DONE | \
  48. NETIF_MSG_PKTDATA | NETIF_MSG_TX_QUEUED | \
  49. NETIF_MSG_RX_STATUS)
  50. #define cpsw_info(priv, type, format, ...) \
  51. do { \
  52. if (netif_msg_##type(priv) && net_ratelimit()) \
  53. dev_info(priv->dev, format, ## __VA_ARGS__); \
  54. } while (0)
  55. #define cpsw_err(priv, type, format, ...) \
  56. do { \
  57. if (netif_msg_##type(priv) && net_ratelimit()) \
  58. dev_err(priv->dev, format, ## __VA_ARGS__); \
  59. } while (0)
  60. #define cpsw_dbg(priv, type, format, ...) \
  61. do { \
  62. if (netif_msg_##type(priv) && net_ratelimit()) \
  63. dev_dbg(priv->dev, format, ## __VA_ARGS__); \
  64. } while (0)
  65. #define cpsw_notice(priv, type, format, ...) \
  66. do { \
  67. if (netif_msg_##type(priv) && net_ratelimit()) \
  68. dev_notice(priv->dev, format, ## __VA_ARGS__); \
  69. } while (0)
  70. #define ALE_ALL_PORTS 0x7
  71. #define CPSW_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
  72. #define CPSW_MINOR_VERSION(reg) (reg & 0xff)
  73. #define CPSW_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
  74. #define CPSW_VERSION_1 0x19010a
  75. #define CPSW_VERSION_2 0x19010c
  76. #define CPSW_VERSION_3 0x19010f
  77. #define CPSW_VERSION_4 0x190112
  78. #define HOST_PORT_NUM 0
  79. #define SLIVER_SIZE 0x40
  80. #define CPSW1_HOST_PORT_OFFSET 0x028
  81. #define CPSW1_SLAVE_OFFSET 0x050
  82. #define CPSW1_SLAVE_SIZE 0x040
  83. #define CPSW1_CPDMA_OFFSET 0x100
  84. #define CPSW1_STATERAM_OFFSET 0x200
  85. #define CPSW1_HW_STATS 0x400
  86. #define CPSW1_CPTS_OFFSET 0x500
  87. #define CPSW1_ALE_OFFSET 0x600
  88. #define CPSW1_SLIVER_OFFSET 0x700
  89. #define CPSW2_HOST_PORT_OFFSET 0x108
  90. #define CPSW2_SLAVE_OFFSET 0x200
  91. #define CPSW2_SLAVE_SIZE 0x100
  92. #define CPSW2_CPDMA_OFFSET 0x800
  93. #define CPSW2_HW_STATS 0x900
  94. #define CPSW2_STATERAM_OFFSET 0xa00
  95. #define CPSW2_CPTS_OFFSET 0xc00
  96. #define CPSW2_ALE_OFFSET 0xd00
  97. #define CPSW2_SLIVER_OFFSET 0xd80
  98. #define CPSW2_BD_OFFSET 0x2000
  99. #define CPDMA_RXTHRESH 0x0c0
  100. #define CPDMA_RXFREE 0x0e0
  101. #define CPDMA_TXHDP 0x00
  102. #define CPDMA_RXHDP 0x20
  103. #define CPDMA_TXCP 0x40
  104. #define CPDMA_RXCP 0x60
  105. #define CPSW_POLL_WEIGHT 64
  106. #define CPSW_MIN_PACKET_SIZE 60
  107. #define CPSW_MAX_PACKET_SIZE (1500 + 14 + 4 + 4)
  108. #define RX_PRIORITY_MAPPING 0x76543210
  109. #define TX_PRIORITY_MAPPING 0x33221100
  110. #define CPDMA_TX_PRIORITY_MAP 0x76543210
  111. #define CPSW_VLAN_AWARE BIT(1)
  112. #define CPSW_ALE_VLAN_AWARE 1
  113. #define CPSW_FIFO_NORMAL_MODE (0 << 16)
  114. #define CPSW_FIFO_DUAL_MAC_MODE (1 << 16)
  115. #define CPSW_FIFO_RATE_LIMIT_MODE (2 << 16)
  116. #define CPSW_INTPACEEN (0x3f << 16)
  117. #define CPSW_INTPRESCALE_MASK (0x7FF << 0)
  118. #define CPSW_CMINTMAX_CNT 63
  119. #define CPSW_CMINTMIN_CNT 2
  120. #define CPSW_CMINTMAX_INTVL (1000 / CPSW_CMINTMIN_CNT)
  121. #define CPSW_CMINTMIN_INTVL ((1000 / CPSW_CMINTMAX_CNT) + 1)
  122. #define cpsw_slave_index(priv) \
  123. ((priv->data.dual_emac) ? priv->emac_port : \
  124. priv->data.active_slave)
  125. static int debug_level;
  126. module_param(debug_level, int, 0);
  127. MODULE_PARM_DESC(debug_level, "cpsw debug level (NETIF_MSG bits)");
  128. static int ale_ageout = 10;
  129. module_param(ale_ageout, int, 0);
  130. MODULE_PARM_DESC(ale_ageout, "cpsw ale ageout interval (seconds)");
  131. static int rx_packet_max = CPSW_MAX_PACKET_SIZE;
  132. module_param(rx_packet_max, int, 0);
  133. MODULE_PARM_DESC(rx_packet_max, "maximum receive packet size (bytes)");
  134. struct cpsw_wr_regs {
  135. u32 id_ver;
  136. u32 soft_reset;
  137. u32 control;
  138. u32 int_control;
  139. u32 rx_thresh_en;
  140. u32 rx_en;
  141. u32 tx_en;
  142. u32 misc_en;
  143. u32 mem_allign1[8];
  144. u32 rx_thresh_stat;
  145. u32 rx_stat;
  146. u32 tx_stat;
  147. u32 misc_stat;
  148. u32 mem_allign2[8];
  149. u32 rx_imax;
  150. u32 tx_imax;
  151. };
  152. struct cpsw_ss_regs {
  153. u32 id_ver;
  154. u32 control;
  155. u32 soft_reset;
  156. u32 stat_port_en;
  157. u32 ptype;
  158. u32 soft_idle;
  159. u32 thru_rate;
  160. u32 gap_thresh;
  161. u32 tx_start_wds;
  162. u32 flow_control;
  163. u32 vlan_ltype;
  164. u32 ts_ltype;
  165. u32 dlr_ltype;
  166. };
  167. /* CPSW_PORT_V1 */
  168. #define CPSW1_MAX_BLKS 0x00 /* Maximum FIFO Blocks */
  169. #define CPSW1_BLK_CNT 0x04 /* FIFO Block Usage Count (Read Only) */
  170. #define CPSW1_TX_IN_CTL 0x08 /* Transmit FIFO Control */
  171. #define CPSW1_PORT_VLAN 0x0c /* VLAN Register */
  172. #define CPSW1_TX_PRI_MAP 0x10 /* Tx Header Priority to Switch Pri Mapping */
  173. #define CPSW1_TS_CTL 0x14 /* Time Sync Control */
  174. #define CPSW1_TS_SEQ_LTYPE 0x18 /* Time Sync Sequence ID Offset and Msg Type */
  175. #define CPSW1_TS_VLAN 0x1c /* Time Sync VLAN1 and VLAN2 */
  176. /* CPSW_PORT_V2 */
  177. #define CPSW2_CONTROL 0x00 /* Control Register */
  178. #define CPSW2_MAX_BLKS 0x08 /* Maximum FIFO Blocks */
  179. #define CPSW2_BLK_CNT 0x0c /* FIFO Block Usage Count (Read Only) */
  180. #define CPSW2_TX_IN_CTL 0x10 /* Transmit FIFO Control */
  181. #define CPSW2_PORT_VLAN 0x14 /* VLAN Register */
  182. #define CPSW2_TX_PRI_MAP 0x18 /* Tx Header Priority to Switch Pri Mapping */
  183. #define CPSW2_TS_SEQ_MTYPE 0x1c /* Time Sync Sequence ID Offset and Msg Type */
  184. /* CPSW_PORT_V1 and V2 */
  185. #define SA_LO 0x20 /* CPGMAC_SL Source Address Low */
  186. #define SA_HI 0x24 /* CPGMAC_SL Source Address High */
  187. #define SEND_PERCENT 0x28 /* Transmit Queue Send Percentages */
  188. /* CPSW_PORT_V2 only */
  189. #define RX_DSCP_PRI_MAP0 0x30 /* Rx DSCP Priority to Rx Packet Mapping */
  190. #define RX_DSCP_PRI_MAP1 0x34 /* Rx DSCP Priority to Rx Packet Mapping */
  191. #define RX_DSCP_PRI_MAP2 0x38 /* Rx DSCP Priority to Rx Packet Mapping */
  192. #define RX_DSCP_PRI_MAP3 0x3c /* Rx DSCP Priority to Rx Packet Mapping */
  193. #define RX_DSCP_PRI_MAP4 0x40 /* Rx DSCP Priority to Rx Packet Mapping */
  194. #define RX_DSCP_PRI_MAP5 0x44 /* Rx DSCP Priority to Rx Packet Mapping */
  195. #define RX_DSCP_PRI_MAP6 0x48 /* Rx DSCP Priority to Rx Packet Mapping */
  196. #define RX_DSCP_PRI_MAP7 0x4c /* Rx DSCP Priority to Rx Packet Mapping */
  197. /* Bit definitions for the CPSW2_CONTROL register */
  198. #define PASS_PRI_TAGGED (1<<24) /* Pass Priority Tagged */
  199. #define VLAN_LTYPE2_EN (1<<21) /* VLAN LTYPE 2 enable */
  200. #define VLAN_LTYPE1_EN (1<<20) /* VLAN LTYPE 1 enable */
  201. #define DSCP_PRI_EN (1<<16) /* DSCP Priority Enable */
  202. #define TS_320 (1<<14) /* Time Sync Dest Port 320 enable */
  203. #define TS_319 (1<<13) /* Time Sync Dest Port 319 enable */
  204. #define TS_132 (1<<12) /* Time Sync Dest IP Addr 132 enable */
  205. #define TS_131 (1<<11) /* Time Sync Dest IP Addr 131 enable */
  206. #define TS_130 (1<<10) /* Time Sync Dest IP Addr 130 enable */
  207. #define TS_129 (1<<9) /* Time Sync Dest IP Addr 129 enable */
  208. #define TS_TTL_NONZERO (1<<8) /* Time Sync Time To Live Non-zero enable */
  209. #define TS_ANNEX_F_EN (1<<6) /* Time Sync Annex F enable */
  210. #define TS_ANNEX_D_EN (1<<4) /* Time Sync Annex D enable */
  211. #define TS_LTYPE2_EN (1<<3) /* Time Sync LTYPE 2 enable */
  212. #define TS_LTYPE1_EN (1<<2) /* Time Sync LTYPE 1 enable */
  213. #define TS_TX_EN (1<<1) /* Time Sync Transmit Enable */
  214. #define TS_RX_EN (1<<0) /* Time Sync Receive Enable */
  215. #define CTRL_V2_TS_BITS \
  216. (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 |\
  217. TS_TTL_NONZERO | TS_ANNEX_D_EN | TS_LTYPE1_EN)
  218. #define CTRL_V2_ALL_TS_MASK (CTRL_V2_TS_BITS | TS_TX_EN | TS_RX_EN)
  219. #define CTRL_V2_TX_TS_BITS (CTRL_V2_TS_BITS | TS_TX_EN)
  220. #define CTRL_V2_RX_TS_BITS (CTRL_V2_TS_BITS | TS_RX_EN)
  221. #define CTRL_V3_TS_BITS \
  222. (TS_320 | TS_319 | TS_132 | TS_131 | TS_130 | TS_129 |\
  223. TS_TTL_NONZERO | TS_ANNEX_F_EN | TS_ANNEX_D_EN |\
  224. TS_LTYPE1_EN)
  225. #define CTRL_V3_ALL_TS_MASK (CTRL_V3_TS_BITS | TS_TX_EN | TS_RX_EN)
  226. #define CTRL_V3_TX_TS_BITS (CTRL_V3_TS_BITS | TS_TX_EN)
  227. #define CTRL_V3_RX_TS_BITS (CTRL_V3_TS_BITS | TS_RX_EN)
  228. /* Bit definitions for the CPSW2_TS_SEQ_MTYPE register */
  229. #define TS_SEQ_ID_OFFSET_SHIFT (16) /* Time Sync Sequence ID Offset */
  230. #define TS_SEQ_ID_OFFSET_MASK (0x3f)
  231. #define TS_MSG_TYPE_EN_SHIFT (0) /* Time Sync Message Type Enable */
  232. #define TS_MSG_TYPE_EN_MASK (0xffff)
  233. /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
  234. #define EVENT_MSG_BITS ((1<<0) | (1<<1) | (1<<2) | (1<<3))
  235. /* Bit definitions for the CPSW1_TS_CTL register */
  236. #define CPSW_V1_TS_RX_EN BIT(0)
  237. #define CPSW_V1_TS_TX_EN BIT(4)
  238. #define CPSW_V1_MSG_TYPE_OFS 16
  239. /* Bit definitions for the CPSW1_TS_SEQ_LTYPE register */
  240. #define CPSW_V1_SEQ_ID_OFS_SHIFT 16
  241. struct cpsw_host_regs {
  242. u32 max_blks;
  243. u32 blk_cnt;
  244. u32 tx_in_ctl;
  245. u32 port_vlan;
  246. u32 tx_pri_map;
  247. u32 cpdma_tx_pri_map;
  248. u32 cpdma_rx_chan_map;
  249. };
  250. struct cpsw_sliver_regs {
  251. u32 id_ver;
  252. u32 mac_control;
  253. u32 mac_status;
  254. u32 soft_reset;
  255. u32 rx_maxlen;
  256. u32 __reserved_0;
  257. u32 rx_pause;
  258. u32 tx_pause;
  259. u32 __reserved_1;
  260. u32 rx_pri_map;
  261. };
  262. struct cpsw_hw_stats {
  263. u32 rxgoodframes;
  264. u32 rxbroadcastframes;
  265. u32 rxmulticastframes;
  266. u32 rxpauseframes;
  267. u32 rxcrcerrors;
  268. u32 rxaligncodeerrors;
  269. u32 rxoversizedframes;
  270. u32 rxjabberframes;
  271. u32 rxundersizedframes;
  272. u32 rxfragments;
  273. u32 __pad_0[2];
  274. u32 rxoctets;
  275. u32 txgoodframes;
  276. u32 txbroadcastframes;
  277. u32 txmulticastframes;
  278. u32 txpauseframes;
  279. u32 txdeferredframes;
  280. u32 txcollisionframes;
  281. u32 txsinglecollframes;
  282. u32 txmultcollframes;
  283. u32 txexcessivecollisions;
  284. u32 txlatecollisions;
  285. u32 txunderrun;
  286. u32 txcarriersenseerrors;
  287. u32 txoctets;
  288. u32 octetframes64;
  289. u32 octetframes65t127;
  290. u32 octetframes128t255;
  291. u32 octetframes256t511;
  292. u32 octetframes512t1023;
  293. u32 octetframes1024tup;
  294. u32 netoctets;
  295. u32 rxsofoverruns;
  296. u32 rxmofoverruns;
  297. u32 rxdmaoverruns;
  298. };
  299. struct cpsw_slave {
  300. void __iomem *regs;
  301. struct cpsw_sliver_regs __iomem *sliver;
  302. int slave_num;
  303. u32 mac_control;
  304. struct cpsw_slave_data *data;
  305. struct phy_device *phy;
  306. struct net_device *ndev;
  307. u32 port_vlan;
  308. u32 open_stat;
  309. };
  310. static inline u32 slave_read(struct cpsw_slave *slave, u32 offset)
  311. {
  312. return __raw_readl(slave->regs + offset);
  313. }
  314. static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset)
  315. {
  316. __raw_writel(val, slave->regs + offset);
  317. }
  318. struct cpsw_priv {
  319. struct platform_device *pdev;
  320. struct net_device *ndev;
  321. struct napi_struct napi_rx;
  322. struct napi_struct napi_tx;
  323. struct device *dev;
  324. struct cpsw_platform_data data;
  325. struct cpsw_ss_regs __iomem *regs;
  326. struct cpsw_wr_regs __iomem *wr_regs;
  327. u8 __iomem *hw_stats;
  328. struct cpsw_host_regs __iomem *host_port_regs;
  329. u32 msg_enable;
  330. u32 version;
  331. u32 coal_intvl;
  332. u32 bus_freq_mhz;
  333. int rx_packet_max;
  334. struct clk *clk;
  335. u8 mac_addr[ETH_ALEN];
  336. struct cpsw_slave *slaves;
  337. struct cpdma_ctlr *dma;
  338. struct cpdma_chan *txch, *rxch;
  339. struct cpsw_ale *ale;
  340. bool rx_pause;
  341. bool tx_pause;
  342. bool quirk_irq;
  343. bool rx_irq_disabled;
  344. bool tx_irq_disabled;
  345. /* snapshot of IRQ numbers */
  346. u32 irqs_table[4];
  347. u32 num_irqs;
  348. struct cpts *cpts;
  349. u32 emac_port;
  350. };
  351. struct cpsw_stats {
  352. char stat_string[ETH_GSTRING_LEN];
  353. int type;
  354. int sizeof_stat;
  355. int stat_offset;
  356. };
  357. enum {
  358. CPSW_STATS,
  359. CPDMA_RX_STATS,
  360. CPDMA_TX_STATS,
  361. };
  362. #define CPSW_STAT(m) CPSW_STATS, \
  363. sizeof(((struct cpsw_hw_stats *)0)->m), \
  364. offsetof(struct cpsw_hw_stats, m)
  365. #define CPDMA_RX_STAT(m) CPDMA_RX_STATS, \
  366. sizeof(((struct cpdma_chan_stats *)0)->m), \
  367. offsetof(struct cpdma_chan_stats, m)
  368. #define CPDMA_TX_STAT(m) CPDMA_TX_STATS, \
  369. sizeof(((struct cpdma_chan_stats *)0)->m), \
  370. offsetof(struct cpdma_chan_stats, m)
  371. static const struct cpsw_stats cpsw_gstrings_stats[] = {
  372. { "Good Rx Frames", CPSW_STAT(rxgoodframes) },
  373. { "Broadcast Rx Frames", CPSW_STAT(rxbroadcastframes) },
  374. { "Multicast Rx Frames", CPSW_STAT(rxmulticastframes) },
  375. { "Pause Rx Frames", CPSW_STAT(rxpauseframes) },
  376. { "Rx CRC Errors", CPSW_STAT(rxcrcerrors) },
  377. { "Rx Align/Code Errors", CPSW_STAT(rxaligncodeerrors) },
  378. { "Oversize Rx Frames", CPSW_STAT(rxoversizedframes) },
  379. { "Rx Jabbers", CPSW_STAT(rxjabberframes) },
  380. { "Undersize (Short) Rx Frames", CPSW_STAT(rxundersizedframes) },
  381. { "Rx Fragments", CPSW_STAT(rxfragments) },
  382. { "Rx Octets", CPSW_STAT(rxoctets) },
  383. { "Good Tx Frames", CPSW_STAT(txgoodframes) },
  384. { "Broadcast Tx Frames", CPSW_STAT(txbroadcastframes) },
  385. { "Multicast Tx Frames", CPSW_STAT(txmulticastframes) },
  386. { "Pause Tx Frames", CPSW_STAT(txpauseframes) },
  387. { "Deferred Tx Frames", CPSW_STAT(txdeferredframes) },
  388. { "Collisions", CPSW_STAT(txcollisionframes) },
  389. { "Single Collision Tx Frames", CPSW_STAT(txsinglecollframes) },
  390. { "Multiple Collision Tx Frames", CPSW_STAT(txmultcollframes) },
  391. { "Excessive Collisions", CPSW_STAT(txexcessivecollisions) },
  392. { "Late Collisions", CPSW_STAT(txlatecollisions) },
  393. { "Tx Underrun", CPSW_STAT(txunderrun) },
  394. { "Carrier Sense Errors", CPSW_STAT(txcarriersenseerrors) },
  395. { "Tx Octets", CPSW_STAT(txoctets) },
  396. { "Rx + Tx 64 Octet Frames", CPSW_STAT(octetframes64) },
  397. { "Rx + Tx 65-127 Octet Frames", CPSW_STAT(octetframes65t127) },
  398. { "Rx + Tx 128-255 Octet Frames", CPSW_STAT(octetframes128t255) },
  399. { "Rx + Tx 256-511 Octet Frames", CPSW_STAT(octetframes256t511) },
  400. { "Rx + Tx 512-1023 Octet Frames", CPSW_STAT(octetframes512t1023) },
  401. { "Rx + Tx 1024-Up Octet Frames", CPSW_STAT(octetframes1024tup) },
  402. { "Net Octets", CPSW_STAT(netoctets) },
  403. { "Rx Start of Frame Overruns", CPSW_STAT(rxsofoverruns) },
  404. { "Rx Middle of Frame Overruns", CPSW_STAT(rxmofoverruns) },
  405. { "Rx DMA Overruns", CPSW_STAT(rxdmaoverruns) },
  406. { "Rx DMA chan: head_enqueue", CPDMA_RX_STAT(head_enqueue) },
  407. { "Rx DMA chan: tail_enqueue", CPDMA_RX_STAT(tail_enqueue) },
  408. { "Rx DMA chan: pad_enqueue", CPDMA_RX_STAT(pad_enqueue) },
  409. { "Rx DMA chan: misqueued", CPDMA_RX_STAT(misqueued) },
  410. { "Rx DMA chan: desc_alloc_fail", CPDMA_RX_STAT(desc_alloc_fail) },
  411. { "Rx DMA chan: pad_alloc_fail", CPDMA_RX_STAT(pad_alloc_fail) },
  412. { "Rx DMA chan: runt_receive_buf", CPDMA_RX_STAT(runt_receive_buff) },
  413. { "Rx DMA chan: runt_transmit_buf", CPDMA_RX_STAT(runt_transmit_buff) },
  414. { "Rx DMA chan: empty_dequeue", CPDMA_RX_STAT(empty_dequeue) },
  415. { "Rx DMA chan: busy_dequeue", CPDMA_RX_STAT(busy_dequeue) },
  416. { "Rx DMA chan: good_dequeue", CPDMA_RX_STAT(good_dequeue) },
  417. { "Rx DMA chan: requeue", CPDMA_RX_STAT(requeue) },
  418. { "Rx DMA chan: teardown_dequeue", CPDMA_RX_STAT(teardown_dequeue) },
  419. { "Tx DMA chan: head_enqueue", CPDMA_TX_STAT(head_enqueue) },
  420. { "Tx DMA chan: tail_enqueue", CPDMA_TX_STAT(tail_enqueue) },
  421. { "Tx DMA chan: pad_enqueue", CPDMA_TX_STAT(pad_enqueue) },
  422. { "Tx DMA chan: misqueued", CPDMA_TX_STAT(misqueued) },
  423. { "Tx DMA chan: desc_alloc_fail", CPDMA_TX_STAT(desc_alloc_fail) },
  424. { "Tx DMA chan: pad_alloc_fail", CPDMA_TX_STAT(pad_alloc_fail) },
  425. { "Tx DMA chan: runt_receive_buf", CPDMA_TX_STAT(runt_receive_buff) },
  426. { "Tx DMA chan: runt_transmit_buf", CPDMA_TX_STAT(runt_transmit_buff) },
  427. { "Tx DMA chan: empty_dequeue", CPDMA_TX_STAT(empty_dequeue) },
  428. { "Tx DMA chan: busy_dequeue", CPDMA_TX_STAT(busy_dequeue) },
  429. { "Tx DMA chan: good_dequeue", CPDMA_TX_STAT(good_dequeue) },
  430. { "Tx DMA chan: requeue", CPDMA_TX_STAT(requeue) },
  431. { "Tx DMA chan: teardown_dequeue", CPDMA_TX_STAT(teardown_dequeue) },
  432. };
  433. #define CPSW_STATS_LEN ARRAY_SIZE(cpsw_gstrings_stats)
  434. #define napi_to_priv(napi) container_of(napi, struct cpsw_priv, napi)
  435. #define for_each_slave(priv, func, arg...) \
  436. do { \
  437. struct cpsw_slave *slave; \
  438. int n; \
  439. if (priv->data.dual_emac) \
  440. (func)((priv)->slaves + priv->emac_port, ##arg);\
  441. else \
  442. for (n = (priv)->data.slaves, \
  443. slave = (priv)->slaves; \
  444. n; n--) \
  445. (func)(slave++, ##arg); \
  446. } while (0)
  447. #define cpsw_get_slave_ndev(priv, __slave_no__) \
  448. ((__slave_no__ < priv->data.slaves) ? \
  449. priv->slaves[__slave_no__].ndev : NULL)
  450. #define cpsw_get_slave_priv(priv, __slave_no__) \
  451. (((__slave_no__ < priv->data.slaves) && \
  452. (priv->slaves[__slave_no__].ndev)) ? \
  453. netdev_priv(priv->slaves[__slave_no__].ndev) : NULL) \
  454. #define cpsw_dual_emac_src_port_detect(status, priv, ndev, skb) \
  455. do { \
  456. if (!priv->data.dual_emac) \
  457. break; \
  458. if (CPDMA_RX_SOURCE_PORT(status) == 1) { \
  459. ndev = cpsw_get_slave_ndev(priv, 0); \
  460. priv = netdev_priv(ndev); \
  461. skb->dev = ndev; \
  462. } else if (CPDMA_RX_SOURCE_PORT(status) == 2) { \
  463. ndev = cpsw_get_slave_ndev(priv, 1); \
  464. priv = netdev_priv(ndev); \
  465. skb->dev = ndev; \
  466. } \
  467. } while (0)
  468. #define cpsw_add_mcast(priv, addr) \
  469. do { \
  470. if (priv->data.dual_emac) { \
  471. struct cpsw_slave *slave = priv->slaves + \
  472. priv->emac_port; \
  473. int slave_port = cpsw_get_slave_port(priv, \
  474. slave->slave_num); \
  475. cpsw_ale_add_mcast(priv->ale, addr, \
  476. 1 << slave_port | ALE_PORT_HOST, \
  477. ALE_VLAN, slave->port_vlan, 0); \
  478. } else { \
  479. cpsw_ale_add_mcast(priv->ale, addr, \
  480. ALE_ALL_PORTS, \
  481. 0, 0, 0); \
  482. } \
  483. } while (0)
  484. static inline int cpsw_get_slave_port(struct cpsw_priv *priv, u32 slave_num)
  485. {
  486. return slave_num + 1;
  487. }
  488. static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
  489. {
  490. struct cpsw_priv *priv = netdev_priv(ndev);
  491. struct cpsw_ale *ale = priv->ale;
  492. int i;
  493. if (priv->data.dual_emac) {
  494. bool flag = false;
  495. /* Enabling promiscuous mode for one interface will be
  496. * common for both the interface as the interface shares
  497. * the same hardware resource.
  498. */
  499. for (i = 0; i < priv->data.slaves; i++)
  500. if (priv->slaves[i].ndev->flags & IFF_PROMISC)
  501. flag = true;
  502. if (!enable && flag) {
  503. enable = true;
  504. dev_err(&ndev->dev, "promiscuity not disabled as the other interface is still in promiscuity mode\n");
  505. }
  506. if (enable) {
  507. /* Enable Bypass */
  508. cpsw_ale_control_set(ale, 0, ALE_BYPASS, 1);
  509. dev_dbg(&ndev->dev, "promiscuity enabled\n");
  510. } else {
  511. /* Disable Bypass */
  512. cpsw_ale_control_set(ale, 0, ALE_BYPASS, 0);
  513. dev_dbg(&ndev->dev, "promiscuity disabled\n");
  514. }
  515. } else {
  516. if (enable) {
  517. unsigned long timeout = jiffies + HZ;
  518. /* Disable Learn for all ports (host is port 0 and slaves are port 1 and up */
  519. for (i = 0; i <= priv->data.slaves; i++) {
  520. cpsw_ale_control_set(ale, i,
  521. ALE_PORT_NOLEARN, 1);
  522. cpsw_ale_control_set(ale, i,
  523. ALE_PORT_NO_SA_UPDATE, 1);
  524. }
  525. /* Clear All Untouched entries */
  526. cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
  527. do {
  528. cpu_relax();
  529. if (cpsw_ale_control_get(ale, 0, ALE_AGEOUT))
  530. break;
  531. } while (time_after(timeout, jiffies));
  532. cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
  533. /* Clear all mcast from ALE */
  534. cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS, -1);
  535. /* Flood All Unicast Packets to Host port */
  536. cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
  537. dev_dbg(&ndev->dev, "promiscuity enabled\n");
  538. } else {
  539. /* Don't Flood All Unicast Packets to Host port */
  540. cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
  541. /* Enable Learn for all ports (host is port 0 and slaves are port 1 and up */
  542. for (i = 0; i <= priv->data.slaves; i++) {
  543. cpsw_ale_control_set(ale, i,
  544. ALE_PORT_NOLEARN, 0);
  545. cpsw_ale_control_set(ale, i,
  546. ALE_PORT_NO_SA_UPDATE, 0);
  547. }
  548. dev_dbg(&ndev->dev, "promiscuity disabled\n");
  549. }
  550. }
  551. }
  552. static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
  553. {
  554. struct cpsw_priv *priv = netdev_priv(ndev);
  555. int vid;
  556. if (priv->data.dual_emac)
  557. vid = priv->slaves[priv->emac_port].port_vlan;
  558. else
  559. vid = priv->data.default_vlan;
  560. if (ndev->flags & IFF_PROMISC) {
  561. /* Enable promiscuous mode */
  562. cpsw_set_promiscious(ndev, true);
  563. cpsw_ale_set_allmulti(priv->ale, IFF_ALLMULTI);
  564. return;
  565. } else {
  566. /* Disable promiscuous mode */
  567. cpsw_set_promiscious(ndev, false);
  568. }
  569. /* Restore allmulti on vlans if necessary */
  570. cpsw_ale_set_allmulti(priv->ale, priv->ndev->flags & IFF_ALLMULTI);
  571. /* Clear all mcast from ALE */
  572. cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS, vid);
  573. if (!netdev_mc_empty(ndev)) {
  574. struct netdev_hw_addr *ha;
  575. /* program multicast address list into ALE register */
  576. netdev_for_each_mc_addr(ha, ndev) {
  577. cpsw_add_mcast(priv, (u8 *)ha->addr);
  578. }
  579. }
  580. }
  581. static void cpsw_intr_enable(struct cpsw_priv *priv)
  582. {
  583. __raw_writel(0xFF, &priv->wr_regs->tx_en);
  584. __raw_writel(0xFF, &priv->wr_regs->rx_en);
  585. cpdma_ctlr_int_ctrl(priv->dma, true);
  586. return;
  587. }
  588. static void cpsw_intr_disable(struct cpsw_priv *priv)
  589. {
  590. __raw_writel(0, &priv->wr_regs->tx_en);
  591. __raw_writel(0, &priv->wr_regs->rx_en);
  592. cpdma_ctlr_int_ctrl(priv->dma, false);
  593. return;
  594. }
  595. static void cpsw_tx_handler(void *token, int len, int status)
  596. {
  597. struct sk_buff *skb = token;
  598. struct net_device *ndev = skb->dev;
  599. struct cpsw_priv *priv = netdev_priv(ndev);
  600. /* Check whether the queue is stopped due to stalled tx dma, if the
  601. * queue is stopped then start the queue as we have free desc for tx
  602. */
  603. if (unlikely(netif_queue_stopped(ndev)))
  604. netif_wake_queue(ndev);
  605. cpts_tx_timestamp(priv->cpts, skb);
  606. ndev->stats.tx_packets++;
  607. ndev->stats.tx_bytes += len;
  608. dev_kfree_skb_any(skb);
  609. }
  610. static void cpsw_rx_handler(void *token, int len, int status)
  611. {
  612. struct sk_buff *skb = token;
  613. struct sk_buff *new_skb;
  614. struct net_device *ndev = skb->dev;
  615. struct cpsw_priv *priv = netdev_priv(ndev);
  616. int ret = 0;
  617. cpsw_dual_emac_src_port_detect(status, priv, ndev, skb);
  618. if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
  619. bool ndev_status = false;
  620. struct cpsw_slave *slave = priv->slaves;
  621. int n;
  622. if (priv->data.dual_emac) {
  623. /* In dual emac mode check for all interfaces */
  624. for (n = priv->data.slaves; n; n--, slave++)
  625. if (netif_running(slave->ndev))
  626. ndev_status = true;
  627. }
  628. if (ndev_status && (status >= 0)) {
  629. /* The packet received is for the interface which
  630. * is already down and the other interface is up
  631. * and running, instead of freeing which results
  632. * in reducing of the number of rx descriptor in
  633. * DMA engine, requeue skb back to cpdma.
  634. */
  635. new_skb = skb;
  636. goto requeue;
  637. }
  638. /* the interface is going down, skbs are purged */
  639. dev_kfree_skb_any(skb);
  640. return;
  641. }
  642. new_skb = netdev_alloc_skb_ip_align(ndev, priv->rx_packet_max);
  643. if (new_skb) {
  644. skb_put(skb, len);
  645. cpts_rx_timestamp(priv->cpts, skb);
  646. skb->protocol = eth_type_trans(skb, ndev);
  647. netif_receive_skb(skb);
  648. ndev->stats.rx_bytes += len;
  649. ndev->stats.rx_packets++;
  650. kmemleak_not_leak(new_skb);
  651. } else {
  652. ndev->stats.rx_dropped++;
  653. new_skb = skb;
  654. }
  655. requeue:
  656. ret = cpdma_chan_submit(priv->rxch, new_skb, new_skb->data,
  657. skb_tailroom(new_skb), 0);
  658. if (WARN_ON(ret < 0))
  659. dev_kfree_skb_any(new_skb);
  660. }
  661. static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id)
  662. {
  663. struct cpsw_priv *priv = dev_id;
  664. writel(0, &priv->wr_regs->tx_en);
  665. cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
  666. if (priv->quirk_irq) {
  667. disable_irq_nosync(priv->irqs_table[1]);
  668. priv->tx_irq_disabled = true;
  669. }
  670. napi_schedule(&priv->napi_tx);
  671. return IRQ_HANDLED;
  672. }
  673. static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id)
  674. {
  675. struct cpsw_priv *priv = dev_id;
  676. cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
  677. writel(0, &priv->wr_regs->rx_en);
  678. if (priv->quirk_irq) {
  679. disable_irq_nosync(priv->irqs_table[0]);
  680. priv->rx_irq_disabled = true;
  681. }
  682. napi_schedule(&priv->napi_rx);
  683. return IRQ_HANDLED;
  684. }
  685. static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget)
  686. {
  687. struct cpsw_priv *priv = napi_to_priv(napi_tx);
  688. int num_tx;
  689. num_tx = cpdma_chan_process(priv->txch, budget);
  690. if (num_tx < budget) {
  691. napi_complete(napi_tx);
  692. writel(0xff, &priv->wr_regs->tx_en);
  693. if (priv->quirk_irq && priv->tx_irq_disabled) {
  694. priv->tx_irq_disabled = false;
  695. enable_irq(priv->irqs_table[1]);
  696. }
  697. }
  698. if (num_tx)
  699. cpsw_dbg(priv, intr, "poll %d tx pkts\n", num_tx);
  700. return num_tx;
  701. }
  702. static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget)
  703. {
  704. struct cpsw_priv *priv = napi_to_priv(napi_rx);
  705. int num_rx;
  706. num_rx = cpdma_chan_process(priv->rxch, budget);
  707. if (num_rx < budget) {
  708. napi_complete(napi_rx);
  709. writel(0xff, &priv->wr_regs->rx_en);
  710. if (priv->quirk_irq && priv->rx_irq_disabled) {
  711. priv->rx_irq_disabled = false;
  712. enable_irq(priv->irqs_table[0]);
  713. }
  714. }
  715. if (num_rx)
  716. cpsw_dbg(priv, intr, "poll %d rx pkts\n", num_rx);
  717. return num_rx;
  718. }
  719. static inline void soft_reset(const char *module, void __iomem *reg)
  720. {
  721. unsigned long timeout = jiffies + HZ;
  722. __raw_writel(1, reg);
  723. do {
  724. cpu_relax();
  725. } while ((__raw_readl(reg) & 1) && time_after(timeout, jiffies));
  726. WARN(__raw_readl(reg) & 1, "failed to soft-reset %s\n", module);
  727. }
  728. #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \
  729. ((mac)[2] << 16) | ((mac)[3] << 24))
  730. #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8))
  731. static void cpsw_set_slave_mac(struct cpsw_slave *slave,
  732. struct cpsw_priv *priv)
  733. {
  734. slave_write(slave, mac_hi(priv->mac_addr), SA_HI);
  735. slave_write(slave, mac_lo(priv->mac_addr), SA_LO);
  736. }
  737. static void _cpsw_adjust_link(struct cpsw_slave *slave,
  738. struct cpsw_priv *priv, bool *link)
  739. {
  740. struct phy_device *phy = slave->phy;
  741. u32 mac_control = 0;
  742. u32 slave_port;
  743. if (!phy)
  744. return;
  745. slave_port = cpsw_get_slave_port(priv, slave->slave_num);
  746. if (phy->link) {
  747. mac_control = priv->data.mac_control;
  748. /* enable forwarding */
  749. cpsw_ale_control_set(priv->ale, slave_port,
  750. ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
  751. if (phy->speed == 1000)
  752. mac_control |= BIT(7); /* GIGABITEN */
  753. if (phy->duplex)
  754. mac_control |= BIT(0); /* FULLDUPLEXEN */
  755. /* set speed_in input in case RMII mode is used in 100Mbps */
  756. if (phy->speed == 100)
  757. mac_control |= BIT(15);
  758. else if (phy->speed == 10)
  759. mac_control |= BIT(18); /* In Band mode */
  760. if (priv->rx_pause)
  761. mac_control |= BIT(3);
  762. if (priv->tx_pause)
  763. mac_control |= BIT(4);
  764. *link = true;
  765. } else {
  766. mac_control = 0;
  767. /* disable forwarding */
  768. cpsw_ale_control_set(priv->ale, slave_port,
  769. ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
  770. }
  771. if (mac_control != slave->mac_control) {
  772. phy_print_status(phy);
  773. __raw_writel(mac_control, &slave->sliver->mac_control);
  774. }
  775. slave->mac_control = mac_control;
  776. }
  777. static void cpsw_adjust_link(struct net_device *ndev)
  778. {
  779. struct cpsw_priv *priv = netdev_priv(ndev);
  780. bool link = false;
  781. for_each_slave(priv, _cpsw_adjust_link, priv, &link);
  782. if (link) {
  783. netif_carrier_on(ndev);
  784. if (netif_running(ndev))
  785. netif_wake_queue(ndev);
  786. } else {
  787. netif_carrier_off(ndev);
  788. netif_stop_queue(ndev);
  789. }
  790. }
  791. static int cpsw_get_coalesce(struct net_device *ndev,
  792. struct ethtool_coalesce *coal)
  793. {
  794. struct cpsw_priv *priv = netdev_priv(ndev);
  795. coal->rx_coalesce_usecs = priv->coal_intvl;
  796. return 0;
  797. }
  798. static int cpsw_set_coalesce(struct net_device *ndev,
  799. struct ethtool_coalesce *coal)
  800. {
  801. struct cpsw_priv *priv = netdev_priv(ndev);
  802. u32 int_ctrl;
  803. u32 num_interrupts = 0;
  804. u32 prescale = 0;
  805. u32 addnl_dvdr = 1;
  806. u32 coal_intvl = 0;
  807. coal_intvl = coal->rx_coalesce_usecs;
  808. int_ctrl = readl(&priv->wr_regs->int_control);
  809. prescale = priv->bus_freq_mhz * 4;
  810. if (!coal->rx_coalesce_usecs) {
  811. int_ctrl &= ~(CPSW_INTPRESCALE_MASK | CPSW_INTPACEEN);
  812. goto update_return;
  813. }
  814. if (coal_intvl < CPSW_CMINTMIN_INTVL)
  815. coal_intvl = CPSW_CMINTMIN_INTVL;
  816. if (coal_intvl > CPSW_CMINTMAX_INTVL) {
  817. /* Interrupt pacer works with 4us Pulse, we can
  818. * throttle further by dilating the 4us pulse.
  819. */
  820. addnl_dvdr = CPSW_INTPRESCALE_MASK / prescale;
  821. if (addnl_dvdr > 1) {
  822. prescale *= addnl_dvdr;
  823. if (coal_intvl > (CPSW_CMINTMAX_INTVL * addnl_dvdr))
  824. coal_intvl = (CPSW_CMINTMAX_INTVL
  825. * addnl_dvdr);
  826. } else {
  827. addnl_dvdr = 1;
  828. coal_intvl = CPSW_CMINTMAX_INTVL;
  829. }
  830. }
  831. num_interrupts = (1000 * addnl_dvdr) / coal_intvl;
  832. writel(num_interrupts, &priv->wr_regs->rx_imax);
  833. writel(num_interrupts, &priv->wr_regs->tx_imax);
  834. int_ctrl |= CPSW_INTPACEEN;
  835. int_ctrl &= (~CPSW_INTPRESCALE_MASK);
  836. int_ctrl |= (prescale & CPSW_INTPRESCALE_MASK);
  837. update_return:
  838. writel(int_ctrl, &priv->wr_regs->int_control);
  839. cpsw_notice(priv, timer, "Set coalesce to %d usecs.\n", coal_intvl);
  840. if (priv->data.dual_emac) {
  841. int i;
  842. for (i = 0; i < priv->data.slaves; i++) {
  843. priv = netdev_priv(priv->slaves[i].ndev);
  844. priv->coal_intvl = coal_intvl;
  845. }
  846. } else {
  847. priv->coal_intvl = coal_intvl;
  848. }
  849. return 0;
  850. }
  851. static int cpsw_get_sset_count(struct net_device *ndev, int sset)
  852. {
  853. switch (sset) {
  854. case ETH_SS_STATS:
  855. return CPSW_STATS_LEN;
  856. default:
  857. return -EOPNOTSUPP;
  858. }
  859. }
  860. static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
  861. {
  862. u8 *p = data;
  863. int i;
  864. switch (stringset) {
  865. case ETH_SS_STATS:
  866. for (i = 0; i < CPSW_STATS_LEN; i++) {
  867. memcpy(p, cpsw_gstrings_stats[i].stat_string,
  868. ETH_GSTRING_LEN);
  869. p += ETH_GSTRING_LEN;
  870. }
  871. break;
  872. }
  873. }
  874. static void cpsw_get_ethtool_stats(struct net_device *ndev,
  875. struct ethtool_stats *stats, u64 *data)
  876. {
  877. struct cpsw_priv *priv = netdev_priv(ndev);
  878. struct cpdma_chan_stats rx_stats;
  879. struct cpdma_chan_stats tx_stats;
  880. u32 val;
  881. u8 *p;
  882. int i;
  883. /* Collect Davinci CPDMA stats for Rx and Tx Channel */
  884. cpdma_chan_get_stats(priv->rxch, &rx_stats);
  885. cpdma_chan_get_stats(priv->txch, &tx_stats);
  886. for (i = 0; i < CPSW_STATS_LEN; i++) {
  887. switch (cpsw_gstrings_stats[i].type) {
  888. case CPSW_STATS:
  889. val = readl(priv->hw_stats +
  890. cpsw_gstrings_stats[i].stat_offset);
  891. data[i] = val;
  892. break;
  893. case CPDMA_RX_STATS:
  894. p = (u8 *)&rx_stats +
  895. cpsw_gstrings_stats[i].stat_offset;
  896. data[i] = *(u32 *)p;
  897. break;
  898. case CPDMA_TX_STATS:
  899. p = (u8 *)&tx_stats +
  900. cpsw_gstrings_stats[i].stat_offset;
  901. data[i] = *(u32 *)p;
  902. break;
  903. }
  904. }
  905. }
  906. static int cpsw_common_res_usage_state(struct cpsw_priv *priv)
  907. {
  908. u32 i;
  909. u32 usage_count = 0;
  910. if (!priv->data.dual_emac)
  911. return 0;
  912. for (i = 0; i < priv->data.slaves; i++)
  913. if (priv->slaves[i].open_stat)
  914. usage_count++;
  915. return usage_count;
  916. }
  917. static inline int cpsw_tx_packet_submit(struct net_device *ndev,
  918. struct cpsw_priv *priv, struct sk_buff *skb)
  919. {
  920. if (!priv->data.dual_emac)
  921. return cpdma_chan_submit(priv->txch, skb, skb->data,
  922. skb->len, 0);
  923. if (ndev == cpsw_get_slave_ndev(priv, 0))
  924. return cpdma_chan_submit(priv->txch, skb, skb->data,
  925. skb->len, 1);
  926. else
  927. return cpdma_chan_submit(priv->txch, skb, skb->data,
  928. skb->len, 2);
  929. }
  930. static inline void cpsw_add_dual_emac_def_ale_entries(
  931. struct cpsw_priv *priv, struct cpsw_slave *slave,
  932. u32 slave_port)
  933. {
  934. u32 port_mask = 1 << slave_port | ALE_PORT_HOST;
  935. if (priv->version == CPSW_VERSION_1)
  936. slave_write(slave, slave->port_vlan, CPSW1_PORT_VLAN);
  937. else
  938. slave_write(slave, slave->port_vlan, CPSW2_PORT_VLAN);
  939. cpsw_ale_add_vlan(priv->ale, slave->port_vlan, port_mask,
  940. port_mask, port_mask, 0);
  941. cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
  942. port_mask, ALE_VLAN, slave->port_vlan, 0);
  943. cpsw_ale_add_ucast(priv->ale, priv->mac_addr,
  944. HOST_PORT_NUM, ALE_VLAN | ALE_SECURE, slave->port_vlan);
  945. }
  946. static void soft_reset_slave(struct cpsw_slave *slave)
  947. {
  948. char name[32];
  949. snprintf(name, sizeof(name), "slave-%d", slave->slave_num);
  950. soft_reset(name, &slave->sliver->soft_reset);
  951. }
  952. static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
  953. {
  954. u32 slave_port;
  955. soft_reset_slave(slave);
  956. /* setup priority mapping */
  957. __raw_writel(RX_PRIORITY_MAPPING, &slave->sliver->rx_pri_map);
  958. switch (priv->version) {
  959. case CPSW_VERSION_1:
  960. slave_write(slave, TX_PRIORITY_MAPPING, CPSW1_TX_PRI_MAP);
  961. break;
  962. case CPSW_VERSION_2:
  963. case CPSW_VERSION_3:
  964. case CPSW_VERSION_4:
  965. slave_write(slave, TX_PRIORITY_MAPPING, CPSW2_TX_PRI_MAP);
  966. break;
  967. }
  968. /* setup max packet size, and mac address */
  969. __raw_writel(priv->rx_packet_max, &slave->sliver->rx_maxlen);
  970. cpsw_set_slave_mac(slave, priv);
  971. slave->mac_control = 0; /* no link yet */
  972. slave_port = cpsw_get_slave_port(priv, slave->slave_num);
  973. if (priv->data.dual_emac)
  974. cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port);
  975. else
  976. cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
  977. 1 << slave_port, 0, 0, ALE_MCAST_FWD_2);
  978. if (slave->data->phy_node) {
  979. slave->phy = of_phy_connect(priv->ndev, slave->data->phy_node,
  980. &cpsw_adjust_link, 0, slave->data->phy_if);
  981. if (!slave->phy) {
  982. dev_err(priv->dev, "phy \"%s\" not found on slave %d\n",
  983. slave->data->phy_node->full_name,
  984. slave->slave_num);
  985. return;
  986. }
  987. } else {
  988. slave->phy = phy_connect(priv->ndev, slave->data->phy_id,
  989. &cpsw_adjust_link, slave->data->phy_if);
  990. if (IS_ERR(slave->phy)) {
  991. dev_err(priv->dev,
  992. "phy \"%s\" not found on slave %d, err %ld\n",
  993. slave->data->phy_id, slave->slave_num,
  994. PTR_ERR(slave->phy));
  995. slave->phy = NULL;
  996. return;
  997. }
  998. }
  999. phy_attached_info(slave->phy);
  1000. phy_start(slave->phy);
  1001. /* Configure GMII_SEL register */
  1002. cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface, slave->slave_num);
  1003. }
  1004. static inline void cpsw_add_default_vlan(struct cpsw_priv *priv)
  1005. {
  1006. const int vlan = priv->data.default_vlan;
  1007. u32 reg;
  1008. int i;
  1009. int unreg_mcast_mask;
  1010. reg = (priv->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN :
  1011. CPSW2_PORT_VLAN;
  1012. writel(vlan, &priv->host_port_regs->port_vlan);
  1013. for (i = 0; i < priv->data.slaves; i++)
  1014. slave_write(priv->slaves + i, vlan, reg);
  1015. if (priv->ndev->flags & IFF_ALLMULTI)
  1016. unreg_mcast_mask = ALE_ALL_PORTS;
  1017. else
  1018. unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2;
  1019. cpsw_ale_add_vlan(priv->ale, vlan, ALE_ALL_PORTS,
  1020. ALE_ALL_PORTS, ALE_ALL_PORTS,
  1021. unreg_mcast_mask);
  1022. }
  1023. static void cpsw_init_host_port(struct cpsw_priv *priv)
  1024. {
  1025. u32 control_reg;
  1026. u32 fifo_mode;
  1027. /* soft reset the controller and initialize ale */
  1028. soft_reset("cpsw", &priv->regs->soft_reset);
  1029. cpsw_ale_start(priv->ale);
  1030. /* switch to vlan unaware mode */
  1031. cpsw_ale_control_set(priv->ale, HOST_PORT_NUM, ALE_VLAN_AWARE,
  1032. CPSW_ALE_VLAN_AWARE);
  1033. control_reg = readl(&priv->regs->control);
  1034. control_reg |= CPSW_VLAN_AWARE;
  1035. writel(control_reg, &priv->regs->control);
  1036. fifo_mode = (priv->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE :
  1037. CPSW_FIFO_NORMAL_MODE;
  1038. writel(fifo_mode, &priv->host_port_regs->tx_in_ctl);
  1039. /* setup host port priority mapping */
  1040. __raw_writel(CPDMA_TX_PRIORITY_MAP,
  1041. &priv->host_port_regs->cpdma_tx_pri_map);
  1042. __raw_writel(0, &priv->host_port_regs->cpdma_rx_chan_map);
  1043. cpsw_ale_control_set(priv->ale, HOST_PORT_NUM,
  1044. ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
  1045. if (!priv->data.dual_emac) {
  1046. cpsw_ale_add_ucast(priv->ale, priv->mac_addr, HOST_PORT_NUM,
  1047. 0, 0);
  1048. cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
  1049. ALE_PORT_HOST, 0, 0, ALE_MCAST_FWD_2);
  1050. }
  1051. }
  1052. static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv)
  1053. {
  1054. u32 slave_port;
  1055. slave_port = cpsw_get_slave_port(priv, slave->slave_num);
  1056. if (!slave->phy)
  1057. return;
  1058. phy_stop(slave->phy);
  1059. phy_disconnect(slave->phy);
  1060. slave->phy = NULL;
  1061. cpsw_ale_control_set(priv->ale, slave_port,
  1062. ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
  1063. soft_reset_slave(slave);
  1064. }
  1065. static int cpsw_ndo_open(struct net_device *ndev)
  1066. {
  1067. struct cpsw_priv *priv = netdev_priv(ndev);
  1068. int i, ret;
  1069. u32 reg;
  1070. ret = pm_runtime_get_sync(&priv->pdev->dev);
  1071. if (ret < 0) {
  1072. pm_runtime_put_noidle(&priv->pdev->dev);
  1073. return ret;
  1074. }
  1075. if (!cpsw_common_res_usage_state(priv))
  1076. cpsw_intr_disable(priv);
  1077. netif_carrier_off(ndev);
  1078. reg = priv->version;
  1079. dev_info(priv->dev, "initializing cpsw version %d.%d (%d)\n",
  1080. CPSW_MAJOR_VERSION(reg), CPSW_MINOR_VERSION(reg),
  1081. CPSW_RTL_VERSION(reg));
  1082. /* initialize host and slave ports */
  1083. if (!cpsw_common_res_usage_state(priv))
  1084. cpsw_init_host_port(priv);
  1085. for_each_slave(priv, cpsw_slave_open, priv);
  1086. /* Add default VLAN */
  1087. if (!priv->data.dual_emac)
  1088. cpsw_add_default_vlan(priv);
  1089. else
  1090. cpsw_ale_add_vlan(priv->ale, priv->data.default_vlan,
  1091. ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0);
  1092. if (!cpsw_common_res_usage_state(priv)) {
  1093. struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(priv, 0);
  1094. int buf_num;
  1095. /* setup tx dma to fixed prio and zero offset */
  1096. cpdma_control_set(priv->dma, CPDMA_TX_PRIO_FIXED, 1);
  1097. cpdma_control_set(priv->dma, CPDMA_RX_BUFFER_OFFSET, 0);
  1098. /* disable priority elevation */
  1099. __raw_writel(0, &priv->regs->ptype);
  1100. /* enable statistics collection only on all ports */
  1101. __raw_writel(0x7, &priv->regs->stat_port_en);
  1102. /* Enable internal fifo flow control */
  1103. writel(0x7, &priv->regs->flow_control);
  1104. napi_enable(&priv_sl0->napi_rx);
  1105. napi_enable(&priv_sl0->napi_tx);
  1106. if (priv_sl0->tx_irq_disabled) {
  1107. priv_sl0->tx_irq_disabled = false;
  1108. enable_irq(priv->irqs_table[1]);
  1109. }
  1110. if (priv_sl0->rx_irq_disabled) {
  1111. priv_sl0->rx_irq_disabled = false;
  1112. enable_irq(priv->irqs_table[0]);
  1113. }
  1114. buf_num = cpdma_chan_get_rx_buf_num(priv->dma);
  1115. for (i = 0; i < buf_num; i++) {
  1116. struct sk_buff *skb;
  1117. ret = -ENOMEM;
  1118. skb = __netdev_alloc_skb_ip_align(priv->ndev,
  1119. priv->rx_packet_max, GFP_KERNEL);
  1120. if (!skb)
  1121. goto err_cleanup;
  1122. ret = cpdma_chan_submit(priv->rxch, skb, skb->data,
  1123. skb_tailroom(skb), 0);
  1124. if (ret < 0) {
  1125. kfree_skb(skb);
  1126. goto err_cleanup;
  1127. }
  1128. kmemleak_not_leak(skb);
  1129. }
  1130. /* continue even if we didn't manage to submit all
  1131. * receive descs
  1132. */
  1133. cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i);
  1134. if (cpts_register(&priv->pdev->dev, priv->cpts,
  1135. priv->data.cpts_clock_mult,
  1136. priv->data.cpts_clock_shift))
  1137. dev_err(priv->dev, "error registering cpts device\n");
  1138. }
  1139. /* Enable Interrupt pacing if configured */
  1140. if (priv->coal_intvl != 0) {
  1141. struct ethtool_coalesce coal;
  1142. coal.rx_coalesce_usecs = priv->coal_intvl;
  1143. cpsw_set_coalesce(ndev, &coal);
  1144. }
  1145. cpdma_ctlr_start(priv->dma);
  1146. cpsw_intr_enable(priv);
  1147. if (priv->data.dual_emac)
  1148. priv->slaves[priv->emac_port].open_stat = true;
  1149. return 0;
  1150. err_cleanup:
  1151. cpdma_ctlr_stop(priv->dma);
  1152. for_each_slave(priv, cpsw_slave_stop, priv);
  1153. pm_runtime_put_sync(&priv->pdev->dev);
  1154. netif_carrier_off(priv->ndev);
  1155. return ret;
  1156. }
  1157. static int cpsw_ndo_stop(struct net_device *ndev)
  1158. {
  1159. struct cpsw_priv *priv = netdev_priv(ndev);
  1160. cpsw_info(priv, ifdown, "shutting down cpsw device\n");
  1161. netif_stop_queue(priv->ndev);
  1162. netif_carrier_off(priv->ndev);
  1163. if (cpsw_common_res_usage_state(priv) <= 1) {
  1164. struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(priv, 0);
  1165. napi_disable(&priv_sl0->napi_rx);
  1166. napi_disable(&priv_sl0->napi_tx);
  1167. cpts_unregister(priv->cpts);
  1168. cpsw_intr_disable(priv);
  1169. cpdma_ctlr_stop(priv->dma);
  1170. cpsw_ale_stop(priv->ale);
  1171. }
  1172. for_each_slave(priv, cpsw_slave_stop, priv);
  1173. pm_runtime_put_sync(&priv->pdev->dev);
  1174. if (priv->data.dual_emac)
  1175. priv->slaves[priv->emac_port].open_stat = false;
  1176. return 0;
  1177. }
  1178. static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
  1179. struct net_device *ndev)
  1180. {
  1181. struct cpsw_priv *priv = netdev_priv(ndev);
  1182. int ret;
  1183. netif_trans_update(ndev);
  1184. if (skb_padto(skb, CPSW_MIN_PACKET_SIZE)) {
  1185. cpsw_err(priv, tx_err, "packet pad failed\n");
  1186. ndev->stats.tx_dropped++;
  1187. return NETDEV_TX_OK;
  1188. }
  1189. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
  1190. priv->cpts->tx_enable)
  1191. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1192. skb_tx_timestamp(skb);
  1193. ret = cpsw_tx_packet_submit(ndev, priv, skb);
  1194. if (unlikely(ret != 0)) {
  1195. cpsw_err(priv, tx_err, "desc submit failed\n");
  1196. goto fail;
  1197. }
  1198. /* If there is no more tx desc left free then we need to
  1199. * tell the kernel to stop sending us tx frames.
  1200. */
  1201. if (unlikely(!cpdma_check_free_tx_desc(priv->txch)))
  1202. netif_stop_queue(ndev);
  1203. return NETDEV_TX_OK;
  1204. fail:
  1205. ndev->stats.tx_dropped++;
  1206. netif_stop_queue(ndev);
  1207. return NETDEV_TX_BUSY;
  1208. }
  1209. #ifdef CONFIG_TI_CPTS
  1210. static void cpsw_hwtstamp_v1(struct cpsw_priv *priv)
  1211. {
  1212. struct cpsw_slave *slave = &priv->slaves[priv->data.active_slave];
  1213. u32 ts_en, seq_id;
  1214. if (!priv->cpts->tx_enable && !priv->cpts->rx_enable) {
  1215. slave_write(slave, 0, CPSW1_TS_CTL);
  1216. return;
  1217. }
  1218. seq_id = (30 << CPSW_V1_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
  1219. ts_en = EVENT_MSG_BITS << CPSW_V1_MSG_TYPE_OFS;
  1220. if (priv->cpts->tx_enable)
  1221. ts_en |= CPSW_V1_TS_TX_EN;
  1222. if (priv->cpts->rx_enable)
  1223. ts_en |= CPSW_V1_TS_RX_EN;
  1224. slave_write(slave, ts_en, CPSW1_TS_CTL);
  1225. slave_write(slave, seq_id, CPSW1_TS_SEQ_LTYPE);
  1226. }
  1227. static void cpsw_hwtstamp_v2(struct cpsw_priv *priv)
  1228. {
  1229. struct cpsw_slave *slave;
  1230. u32 ctrl, mtype;
  1231. if (priv->data.dual_emac)
  1232. slave = &priv->slaves[priv->emac_port];
  1233. else
  1234. slave = &priv->slaves[priv->data.active_slave];
  1235. ctrl = slave_read(slave, CPSW2_CONTROL);
  1236. switch (priv->version) {
  1237. case CPSW_VERSION_2:
  1238. ctrl &= ~CTRL_V2_ALL_TS_MASK;
  1239. if (priv->cpts->tx_enable)
  1240. ctrl |= CTRL_V2_TX_TS_BITS;
  1241. if (priv->cpts->rx_enable)
  1242. ctrl |= CTRL_V2_RX_TS_BITS;
  1243. break;
  1244. case CPSW_VERSION_3:
  1245. default:
  1246. ctrl &= ~CTRL_V3_ALL_TS_MASK;
  1247. if (priv->cpts->tx_enable)
  1248. ctrl |= CTRL_V3_TX_TS_BITS;
  1249. if (priv->cpts->rx_enable)
  1250. ctrl |= CTRL_V3_RX_TS_BITS;
  1251. break;
  1252. }
  1253. mtype = (30 << TS_SEQ_ID_OFFSET_SHIFT) | EVENT_MSG_BITS;
  1254. slave_write(slave, mtype, CPSW2_TS_SEQ_MTYPE);
  1255. slave_write(slave, ctrl, CPSW2_CONTROL);
  1256. __raw_writel(ETH_P_1588, &priv->regs->ts_ltype);
  1257. }
  1258. static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
  1259. {
  1260. struct cpsw_priv *priv = netdev_priv(dev);
  1261. struct cpts *cpts = priv->cpts;
  1262. struct hwtstamp_config cfg;
  1263. if (priv->version != CPSW_VERSION_1 &&
  1264. priv->version != CPSW_VERSION_2 &&
  1265. priv->version != CPSW_VERSION_3)
  1266. return -EOPNOTSUPP;
  1267. if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
  1268. return -EFAULT;
  1269. /* reserved for future extensions */
  1270. if (cfg.flags)
  1271. return -EINVAL;
  1272. if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
  1273. return -ERANGE;
  1274. switch (cfg.rx_filter) {
  1275. case HWTSTAMP_FILTER_NONE:
  1276. cpts->rx_enable = 0;
  1277. break;
  1278. case HWTSTAMP_FILTER_ALL:
  1279. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  1280. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  1281. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  1282. return -ERANGE;
  1283. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  1284. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  1285. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  1286. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  1287. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  1288. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  1289. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  1290. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  1291. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  1292. cpts->rx_enable = 1;
  1293. cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  1294. break;
  1295. default:
  1296. return -ERANGE;
  1297. }
  1298. cpts->tx_enable = cfg.tx_type == HWTSTAMP_TX_ON;
  1299. switch (priv->version) {
  1300. case CPSW_VERSION_1:
  1301. cpsw_hwtstamp_v1(priv);
  1302. break;
  1303. case CPSW_VERSION_2:
  1304. case CPSW_VERSION_3:
  1305. cpsw_hwtstamp_v2(priv);
  1306. break;
  1307. default:
  1308. WARN_ON(1);
  1309. }
  1310. return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
  1311. }
  1312. static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
  1313. {
  1314. struct cpsw_priv *priv = netdev_priv(dev);
  1315. struct cpts *cpts = priv->cpts;
  1316. struct hwtstamp_config cfg;
  1317. if (priv->version != CPSW_VERSION_1 &&
  1318. priv->version != CPSW_VERSION_2 &&
  1319. priv->version != CPSW_VERSION_3)
  1320. return -EOPNOTSUPP;
  1321. cfg.flags = 0;
  1322. cfg.tx_type = cpts->tx_enable ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
  1323. cfg.rx_filter = (cpts->rx_enable ?
  1324. HWTSTAMP_FILTER_PTP_V2_EVENT : HWTSTAMP_FILTER_NONE);
  1325. return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
  1326. }
  1327. #endif /*CONFIG_TI_CPTS*/
  1328. static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  1329. {
  1330. struct cpsw_priv *priv = netdev_priv(dev);
  1331. int slave_no = cpsw_slave_index(priv);
  1332. if (!netif_running(dev))
  1333. return -EINVAL;
  1334. switch (cmd) {
  1335. #ifdef CONFIG_TI_CPTS
  1336. case SIOCSHWTSTAMP:
  1337. return cpsw_hwtstamp_set(dev, req);
  1338. case SIOCGHWTSTAMP:
  1339. return cpsw_hwtstamp_get(dev, req);
  1340. #endif
  1341. }
  1342. if (!priv->slaves[slave_no].phy)
  1343. return -EOPNOTSUPP;
  1344. return phy_mii_ioctl(priv->slaves[slave_no].phy, req, cmd);
  1345. }
  1346. static void cpsw_ndo_tx_timeout(struct net_device *ndev)
  1347. {
  1348. struct cpsw_priv *priv = netdev_priv(ndev);
  1349. cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n");
  1350. ndev->stats.tx_errors++;
  1351. cpsw_intr_disable(priv);
  1352. cpdma_chan_stop(priv->txch);
  1353. cpdma_chan_start(priv->txch);
  1354. cpsw_intr_enable(priv);
  1355. }
  1356. static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
  1357. {
  1358. struct cpsw_priv *priv = netdev_priv(ndev);
  1359. struct sockaddr *addr = (struct sockaddr *)p;
  1360. int flags = 0;
  1361. u16 vid = 0;
  1362. int ret;
  1363. if (!is_valid_ether_addr(addr->sa_data))
  1364. return -EADDRNOTAVAIL;
  1365. ret = pm_runtime_get_sync(&priv->pdev->dev);
  1366. if (ret < 0) {
  1367. pm_runtime_put_noidle(&priv->pdev->dev);
  1368. return ret;
  1369. }
  1370. if (priv->data.dual_emac) {
  1371. vid = priv->slaves[priv->emac_port].port_vlan;
  1372. flags = ALE_VLAN;
  1373. }
  1374. cpsw_ale_del_ucast(priv->ale, priv->mac_addr, HOST_PORT_NUM,
  1375. flags, vid);
  1376. cpsw_ale_add_ucast(priv->ale, addr->sa_data, HOST_PORT_NUM,
  1377. flags, vid);
  1378. memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
  1379. memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
  1380. for_each_slave(priv, cpsw_set_slave_mac, priv);
  1381. pm_runtime_put(&priv->pdev->dev);
  1382. return 0;
  1383. }
  1384. #ifdef CONFIG_NET_POLL_CONTROLLER
  1385. static void cpsw_ndo_poll_controller(struct net_device *ndev)
  1386. {
  1387. struct cpsw_priv *priv = netdev_priv(ndev);
  1388. cpsw_intr_disable(priv);
  1389. cpsw_rx_interrupt(priv->irqs_table[0], priv);
  1390. cpsw_tx_interrupt(priv->irqs_table[1], priv);
  1391. cpsw_intr_enable(priv);
  1392. }
  1393. #endif
  1394. static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv,
  1395. unsigned short vid)
  1396. {
  1397. int ret;
  1398. int unreg_mcast_mask = 0;
  1399. u32 port_mask;
  1400. if (priv->data.dual_emac) {
  1401. port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST;
  1402. if (priv->ndev->flags & IFF_ALLMULTI)
  1403. unreg_mcast_mask = port_mask;
  1404. } else {
  1405. port_mask = ALE_ALL_PORTS;
  1406. if (priv->ndev->flags & IFF_ALLMULTI)
  1407. unreg_mcast_mask = ALE_ALL_PORTS;
  1408. else
  1409. unreg_mcast_mask = ALE_PORT_1 | ALE_PORT_2;
  1410. }
  1411. ret = cpsw_ale_add_vlan(priv->ale, vid, port_mask, 0, port_mask,
  1412. unreg_mcast_mask);
  1413. if (ret != 0)
  1414. return ret;
  1415. ret = cpsw_ale_add_ucast(priv->ale, priv->mac_addr,
  1416. HOST_PORT_NUM, ALE_VLAN, vid);
  1417. if (ret != 0)
  1418. goto clean_vid;
  1419. ret = cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
  1420. port_mask, ALE_VLAN, vid, 0);
  1421. if (ret != 0)
  1422. goto clean_vlan_ucast;
  1423. return 0;
  1424. clean_vlan_ucast:
  1425. cpsw_ale_del_ucast(priv->ale, priv->mac_addr,
  1426. HOST_PORT_NUM, ALE_VLAN, vid);
  1427. clean_vid:
  1428. cpsw_ale_del_vlan(priv->ale, vid, 0);
  1429. return ret;
  1430. }
  1431. static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev,
  1432. __be16 proto, u16 vid)
  1433. {
  1434. struct cpsw_priv *priv = netdev_priv(ndev);
  1435. int ret;
  1436. if (vid == priv->data.default_vlan)
  1437. return 0;
  1438. ret = pm_runtime_get_sync(&priv->pdev->dev);
  1439. if (ret < 0) {
  1440. pm_runtime_put_noidle(&priv->pdev->dev);
  1441. return ret;
  1442. }
  1443. if (priv->data.dual_emac) {
  1444. /* In dual EMAC, reserved VLAN id should not be used for
  1445. * creating VLAN interfaces as this can break the dual
  1446. * EMAC port separation
  1447. */
  1448. int i;
  1449. for (i = 0; i < priv->data.slaves; i++) {
  1450. if (vid == priv->slaves[i].port_vlan)
  1451. return -EINVAL;
  1452. }
  1453. }
  1454. dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid);
  1455. ret = cpsw_add_vlan_ale_entry(priv, vid);
  1456. pm_runtime_put(&priv->pdev->dev);
  1457. return ret;
  1458. }
  1459. static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev,
  1460. __be16 proto, u16 vid)
  1461. {
  1462. struct cpsw_priv *priv = netdev_priv(ndev);
  1463. int ret;
  1464. if (vid == priv->data.default_vlan)
  1465. return 0;
  1466. ret = pm_runtime_get_sync(&priv->pdev->dev);
  1467. if (ret < 0) {
  1468. pm_runtime_put_noidle(&priv->pdev->dev);
  1469. return ret;
  1470. }
  1471. if (priv->data.dual_emac) {
  1472. int i;
  1473. for (i = 0; i < priv->data.slaves; i++) {
  1474. if (vid == priv->slaves[i].port_vlan)
  1475. return -EINVAL;
  1476. }
  1477. }
  1478. dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid);
  1479. ret = cpsw_ale_del_vlan(priv->ale, vid, 0);
  1480. if (ret != 0)
  1481. return ret;
  1482. ret = cpsw_ale_del_ucast(priv->ale, priv->mac_addr,
  1483. HOST_PORT_NUM, ALE_VLAN, vid);
  1484. if (ret != 0)
  1485. return ret;
  1486. ret = cpsw_ale_del_mcast(priv->ale, priv->ndev->broadcast,
  1487. 0, ALE_VLAN, vid);
  1488. pm_runtime_put(&priv->pdev->dev);
  1489. return ret;
  1490. }
  1491. static const struct net_device_ops cpsw_netdev_ops = {
  1492. .ndo_open = cpsw_ndo_open,
  1493. .ndo_stop = cpsw_ndo_stop,
  1494. .ndo_start_xmit = cpsw_ndo_start_xmit,
  1495. .ndo_set_mac_address = cpsw_ndo_set_mac_address,
  1496. .ndo_do_ioctl = cpsw_ndo_ioctl,
  1497. .ndo_validate_addr = eth_validate_addr,
  1498. .ndo_change_mtu = eth_change_mtu,
  1499. .ndo_tx_timeout = cpsw_ndo_tx_timeout,
  1500. .ndo_set_rx_mode = cpsw_ndo_set_rx_mode,
  1501. #ifdef CONFIG_NET_POLL_CONTROLLER
  1502. .ndo_poll_controller = cpsw_ndo_poll_controller,
  1503. #endif
  1504. .ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid,
  1505. .ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid,
  1506. };
  1507. static int cpsw_get_regs_len(struct net_device *ndev)
  1508. {
  1509. struct cpsw_priv *priv = netdev_priv(ndev);
  1510. return priv->data.ale_entries * ALE_ENTRY_WORDS * sizeof(u32);
  1511. }
  1512. static void cpsw_get_regs(struct net_device *ndev,
  1513. struct ethtool_regs *regs, void *p)
  1514. {
  1515. struct cpsw_priv *priv = netdev_priv(ndev);
  1516. u32 *reg = p;
  1517. /* update CPSW IP version */
  1518. regs->version = priv->version;
  1519. cpsw_ale_dump(priv->ale, reg);
  1520. }
  1521. static void cpsw_get_drvinfo(struct net_device *ndev,
  1522. struct ethtool_drvinfo *info)
  1523. {
  1524. struct cpsw_priv *priv = netdev_priv(ndev);
  1525. strlcpy(info->driver, "cpsw", sizeof(info->driver));
  1526. strlcpy(info->version, "1.0", sizeof(info->version));
  1527. strlcpy(info->bus_info, priv->pdev->name, sizeof(info->bus_info));
  1528. }
  1529. static u32 cpsw_get_msglevel(struct net_device *ndev)
  1530. {
  1531. struct cpsw_priv *priv = netdev_priv(ndev);
  1532. return priv->msg_enable;
  1533. }
  1534. static void cpsw_set_msglevel(struct net_device *ndev, u32 value)
  1535. {
  1536. struct cpsw_priv *priv = netdev_priv(ndev);
  1537. priv->msg_enable = value;
  1538. }
  1539. static int cpsw_get_ts_info(struct net_device *ndev,
  1540. struct ethtool_ts_info *info)
  1541. {
  1542. #ifdef CONFIG_TI_CPTS
  1543. struct cpsw_priv *priv = netdev_priv(ndev);
  1544. info->so_timestamping =
  1545. SOF_TIMESTAMPING_TX_HARDWARE |
  1546. SOF_TIMESTAMPING_TX_SOFTWARE |
  1547. SOF_TIMESTAMPING_RX_HARDWARE |
  1548. SOF_TIMESTAMPING_RX_SOFTWARE |
  1549. SOF_TIMESTAMPING_SOFTWARE |
  1550. SOF_TIMESTAMPING_RAW_HARDWARE;
  1551. info->phc_index = priv->cpts->phc_index;
  1552. info->tx_types =
  1553. (1 << HWTSTAMP_TX_OFF) |
  1554. (1 << HWTSTAMP_TX_ON);
  1555. info->rx_filters =
  1556. (1 << HWTSTAMP_FILTER_NONE) |
  1557. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
  1558. #else
  1559. info->so_timestamping =
  1560. SOF_TIMESTAMPING_TX_SOFTWARE |
  1561. SOF_TIMESTAMPING_RX_SOFTWARE |
  1562. SOF_TIMESTAMPING_SOFTWARE;
  1563. info->phc_index = -1;
  1564. info->tx_types = 0;
  1565. info->rx_filters = 0;
  1566. #endif
  1567. return 0;
  1568. }
  1569. static int cpsw_get_settings(struct net_device *ndev,
  1570. struct ethtool_cmd *ecmd)
  1571. {
  1572. struct cpsw_priv *priv = netdev_priv(ndev);
  1573. int slave_no = cpsw_slave_index(priv);
  1574. if (priv->slaves[slave_no].phy)
  1575. return phy_ethtool_gset(priv->slaves[slave_no].phy, ecmd);
  1576. else
  1577. return -EOPNOTSUPP;
  1578. }
  1579. static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
  1580. {
  1581. struct cpsw_priv *priv = netdev_priv(ndev);
  1582. int slave_no = cpsw_slave_index(priv);
  1583. if (priv->slaves[slave_no].phy)
  1584. return phy_ethtool_sset(priv->slaves[slave_no].phy, ecmd);
  1585. else
  1586. return -EOPNOTSUPP;
  1587. }
  1588. static void cpsw_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  1589. {
  1590. struct cpsw_priv *priv = netdev_priv(ndev);
  1591. int slave_no = cpsw_slave_index(priv);
  1592. wol->supported = 0;
  1593. wol->wolopts = 0;
  1594. if (priv->slaves[slave_no].phy)
  1595. phy_ethtool_get_wol(priv->slaves[slave_no].phy, wol);
  1596. }
  1597. static int cpsw_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  1598. {
  1599. struct cpsw_priv *priv = netdev_priv(ndev);
  1600. int slave_no = cpsw_slave_index(priv);
  1601. if (priv->slaves[slave_no].phy)
  1602. return phy_ethtool_set_wol(priv->slaves[slave_no].phy, wol);
  1603. else
  1604. return -EOPNOTSUPP;
  1605. }
  1606. static void cpsw_get_pauseparam(struct net_device *ndev,
  1607. struct ethtool_pauseparam *pause)
  1608. {
  1609. struct cpsw_priv *priv = netdev_priv(ndev);
  1610. pause->autoneg = AUTONEG_DISABLE;
  1611. pause->rx_pause = priv->rx_pause ? true : false;
  1612. pause->tx_pause = priv->tx_pause ? true : false;
  1613. }
  1614. static int cpsw_set_pauseparam(struct net_device *ndev,
  1615. struct ethtool_pauseparam *pause)
  1616. {
  1617. struct cpsw_priv *priv = netdev_priv(ndev);
  1618. bool link;
  1619. priv->rx_pause = pause->rx_pause ? true : false;
  1620. priv->tx_pause = pause->tx_pause ? true : false;
  1621. for_each_slave(priv, _cpsw_adjust_link, priv, &link);
  1622. return 0;
  1623. }
  1624. static int cpsw_ethtool_op_begin(struct net_device *ndev)
  1625. {
  1626. struct cpsw_priv *priv = netdev_priv(ndev);
  1627. int ret;
  1628. ret = pm_runtime_get_sync(&priv->pdev->dev);
  1629. if (ret < 0) {
  1630. cpsw_err(priv, drv, "ethtool begin failed %d\n", ret);
  1631. pm_runtime_put_noidle(&priv->pdev->dev);
  1632. }
  1633. return ret;
  1634. }
  1635. static void cpsw_ethtool_op_complete(struct net_device *ndev)
  1636. {
  1637. struct cpsw_priv *priv = netdev_priv(ndev);
  1638. int ret;
  1639. ret = pm_runtime_put(&priv->pdev->dev);
  1640. if (ret < 0)
  1641. cpsw_err(priv, drv, "ethtool complete failed %d\n", ret);
  1642. }
  1643. static const struct ethtool_ops cpsw_ethtool_ops = {
  1644. .get_drvinfo = cpsw_get_drvinfo,
  1645. .get_msglevel = cpsw_get_msglevel,
  1646. .set_msglevel = cpsw_set_msglevel,
  1647. .get_link = ethtool_op_get_link,
  1648. .get_ts_info = cpsw_get_ts_info,
  1649. .get_settings = cpsw_get_settings,
  1650. .set_settings = cpsw_set_settings,
  1651. .get_coalesce = cpsw_get_coalesce,
  1652. .set_coalesce = cpsw_set_coalesce,
  1653. .get_sset_count = cpsw_get_sset_count,
  1654. .get_strings = cpsw_get_strings,
  1655. .get_ethtool_stats = cpsw_get_ethtool_stats,
  1656. .get_pauseparam = cpsw_get_pauseparam,
  1657. .set_pauseparam = cpsw_set_pauseparam,
  1658. .get_wol = cpsw_get_wol,
  1659. .set_wol = cpsw_set_wol,
  1660. .get_regs_len = cpsw_get_regs_len,
  1661. .get_regs = cpsw_get_regs,
  1662. .begin = cpsw_ethtool_op_begin,
  1663. .complete = cpsw_ethtool_op_complete,
  1664. };
  1665. static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv,
  1666. u32 slave_reg_ofs, u32 sliver_reg_ofs)
  1667. {
  1668. void __iomem *regs = priv->regs;
  1669. int slave_num = slave->slave_num;
  1670. struct cpsw_slave_data *data = priv->data.slave_data + slave_num;
  1671. slave->data = data;
  1672. slave->regs = regs + slave_reg_ofs;
  1673. slave->sliver = regs + sliver_reg_ofs;
  1674. slave->port_vlan = data->dual_emac_res_vlan;
  1675. }
  1676. static int cpsw_probe_dt(struct cpsw_platform_data *data,
  1677. struct platform_device *pdev)
  1678. {
  1679. struct device_node *node = pdev->dev.of_node;
  1680. struct device_node *slave_node;
  1681. int i = 0, ret;
  1682. u32 prop;
  1683. if (!node)
  1684. return -EINVAL;
  1685. if (of_property_read_u32(node, "slaves", &prop)) {
  1686. dev_err(&pdev->dev, "Missing slaves property in the DT.\n");
  1687. return -EINVAL;
  1688. }
  1689. data->slaves = prop;
  1690. if (of_property_read_u32(node, "active_slave", &prop)) {
  1691. dev_err(&pdev->dev, "Missing active_slave property in the DT.\n");
  1692. return -EINVAL;
  1693. }
  1694. data->active_slave = prop;
  1695. if (of_property_read_u32(node, "cpts_clock_mult", &prop)) {
  1696. dev_err(&pdev->dev, "Missing cpts_clock_mult property in the DT.\n");
  1697. return -EINVAL;
  1698. }
  1699. data->cpts_clock_mult = prop;
  1700. if (of_property_read_u32(node, "cpts_clock_shift", &prop)) {
  1701. dev_err(&pdev->dev, "Missing cpts_clock_shift property in the DT.\n");
  1702. return -EINVAL;
  1703. }
  1704. data->cpts_clock_shift = prop;
  1705. data->slave_data = devm_kzalloc(&pdev->dev, data->slaves
  1706. * sizeof(struct cpsw_slave_data),
  1707. GFP_KERNEL);
  1708. if (!data->slave_data)
  1709. return -ENOMEM;
  1710. if (of_property_read_u32(node, "cpdma_channels", &prop)) {
  1711. dev_err(&pdev->dev, "Missing cpdma_channels property in the DT.\n");
  1712. return -EINVAL;
  1713. }
  1714. data->channels = prop;
  1715. if (of_property_read_u32(node, "ale_entries", &prop)) {
  1716. dev_err(&pdev->dev, "Missing ale_entries property in the DT.\n");
  1717. return -EINVAL;
  1718. }
  1719. data->ale_entries = prop;
  1720. if (of_property_read_u32(node, "bd_ram_size", &prop)) {
  1721. dev_err(&pdev->dev, "Missing bd_ram_size property in the DT.\n");
  1722. return -EINVAL;
  1723. }
  1724. data->bd_ram_size = prop;
  1725. if (of_property_read_u32(node, "mac_control", &prop)) {
  1726. dev_err(&pdev->dev, "Missing mac_control property in the DT.\n");
  1727. return -EINVAL;
  1728. }
  1729. data->mac_control = prop;
  1730. if (of_property_read_bool(node, "dual_emac"))
  1731. data->dual_emac = 1;
  1732. /*
  1733. * Populate all the child nodes here...
  1734. */
  1735. ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
  1736. /* We do not want to force this, as in some cases may not have child */
  1737. if (ret)
  1738. dev_warn(&pdev->dev, "Doesn't have any child node\n");
  1739. for_each_available_child_of_node(node, slave_node) {
  1740. struct cpsw_slave_data *slave_data = data->slave_data + i;
  1741. const void *mac_addr = NULL;
  1742. int lenp;
  1743. const __be32 *parp;
  1744. /* This is no slave child node, continue */
  1745. if (strcmp(slave_node->name, "slave"))
  1746. continue;
  1747. slave_data->phy_node = of_parse_phandle(slave_node,
  1748. "phy-handle", 0);
  1749. parp = of_get_property(slave_node, "phy_id", &lenp);
  1750. if (slave_data->phy_node) {
  1751. dev_dbg(&pdev->dev,
  1752. "slave[%d] using phy-handle=\"%s\"\n",
  1753. i, slave_data->phy_node->full_name);
  1754. } else if (of_phy_is_fixed_link(slave_node)) {
  1755. /* In the case of a fixed PHY, the DT node associated
  1756. * to the PHY is the Ethernet MAC DT node.
  1757. */
  1758. ret = of_phy_register_fixed_link(slave_node);
  1759. if (ret)
  1760. return ret;
  1761. slave_data->phy_node = of_node_get(slave_node);
  1762. } else if (parp) {
  1763. u32 phyid;
  1764. struct device_node *mdio_node;
  1765. struct platform_device *mdio;
  1766. if (lenp != (sizeof(__be32) * 2)) {
  1767. dev_err(&pdev->dev, "Invalid slave[%d] phy_id property\n", i);
  1768. goto no_phy_slave;
  1769. }
  1770. mdio_node = of_find_node_by_phandle(be32_to_cpup(parp));
  1771. phyid = be32_to_cpup(parp+1);
  1772. mdio = of_find_device_by_node(mdio_node);
  1773. of_node_put(mdio_node);
  1774. if (!mdio) {
  1775. dev_err(&pdev->dev, "Missing mdio platform device\n");
  1776. return -EINVAL;
  1777. }
  1778. snprintf(slave_data->phy_id, sizeof(slave_data->phy_id),
  1779. PHY_ID_FMT, mdio->name, phyid);
  1780. } else {
  1781. dev_err(&pdev->dev,
  1782. "No slave[%d] phy_id, phy-handle, or fixed-link property\n",
  1783. i);
  1784. goto no_phy_slave;
  1785. }
  1786. slave_data->phy_if = of_get_phy_mode(slave_node);
  1787. if (slave_data->phy_if < 0) {
  1788. dev_err(&pdev->dev, "Missing or malformed slave[%d] phy-mode property\n",
  1789. i);
  1790. return slave_data->phy_if;
  1791. }
  1792. no_phy_slave:
  1793. mac_addr = of_get_mac_address(slave_node);
  1794. if (mac_addr) {
  1795. memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN);
  1796. } else {
  1797. ret = ti_cm_get_macid(&pdev->dev, i,
  1798. slave_data->mac_addr);
  1799. if (ret)
  1800. return ret;
  1801. }
  1802. if (data->dual_emac) {
  1803. if (of_property_read_u32(slave_node, "dual_emac_res_vlan",
  1804. &prop)) {
  1805. dev_err(&pdev->dev, "Missing dual_emac_res_vlan in DT.\n");
  1806. slave_data->dual_emac_res_vlan = i+1;
  1807. dev_err(&pdev->dev, "Using %d as Reserved VLAN for %d slave\n",
  1808. slave_data->dual_emac_res_vlan, i);
  1809. } else {
  1810. slave_data->dual_emac_res_vlan = prop;
  1811. }
  1812. }
  1813. i++;
  1814. if (i == data->slaves)
  1815. break;
  1816. }
  1817. return 0;
  1818. }
  1819. static int cpsw_probe_dual_emac(struct platform_device *pdev,
  1820. struct cpsw_priv *priv)
  1821. {
  1822. struct cpsw_platform_data *data = &priv->data;
  1823. struct net_device *ndev;
  1824. struct cpsw_priv *priv_sl2;
  1825. int ret = 0, i;
  1826. ndev = alloc_etherdev(sizeof(struct cpsw_priv));
  1827. if (!ndev) {
  1828. dev_err(&pdev->dev, "cpsw: error allocating net_device\n");
  1829. return -ENOMEM;
  1830. }
  1831. priv_sl2 = netdev_priv(ndev);
  1832. priv_sl2->data = *data;
  1833. priv_sl2->pdev = pdev;
  1834. priv_sl2->ndev = ndev;
  1835. priv_sl2->dev = &ndev->dev;
  1836. priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
  1837. priv_sl2->rx_packet_max = max(rx_packet_max, 128);
  1838. if (is_valid_ether_addr(data->slave_data[1].mac_addr)) {
  1839. memcpy(priv_sl2->mac_addr, data->slave_data[1].mac_addr,
  1840. ETH_ALEN);
  1841. dev_info(&pdev->dev, "cpsw: Detected MACID = %pM\n", priv_sl2->mac_addr);
  1842. } else {
  1843. random_ether_addr(priv_sl2->mac_addr);
  1844. dev_info(&pdev->dev, "cpsw: Random MACID = %pM\n", priv_sl2->mac_addr);
  1845. }
  1846. memcpy(ndev->dev_addr, priv_sl2->mac_addr, ETH_ALEN);
  1847. priv_sl2->slaves = priv->slaves;
  1848. priv_sl2->clk = priv->clk;
  1849. priv_sl2->coal_intvl = 0;
  1850. priv_sl2->bus_freq_mhz = priv->bus_freq_mhz;
  1851. priv_sl2->regs = priv->regs;
  1852. priv_sl2->host_port_regs = priv->host_port_regs;
  1853. priv_sl2->wr_regs = priv->wr_regs;
  1854. priv_sl2->hw_stats = priv->hw_stats;
  1855. priv_sl2->dma = priv->dma;
  1856. priv_sl2->txch = priv->txch;
  1857. priv_sl2->rxch = priv->rxch;
  1858. priv_sl2->ale = priv->ale;
  1859. priv_sl2->emac_port = 1;
  1860. priv->slaves[1].ndev = ndev;
  1861. priv_sl2->cpts = priv->cpts;
  1862. priv_sl2->version = priv->version;
  1863. for (i = 0; i < priv->num_irqs; i++) {
  1864. priv_sl2->irqs_table[i] = priv->irqs_table[i];
  1865. priv_sl2->num_irqs = priv->num_irqs;
  1866. }
  1867. ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  1868. ndev->netdev_ops = &cpsw_netdev_ops;
  1869. ndev->ethtool_ops = &cpsw_ethtool_ops;
  1870. /* register the network device */
  1871. SET_NETDEV_DEV(ndev, &pdev->dev);
  1872. ret = register_netdev(ndev);
  1873. if (ret) {
  1874. dev_err(&pdev->dev, "cpsw: error registering net device\n");
  1875. free_netdev(ndev);
  1876. ret = -ENODEV;
  1877. }
  1878. return ret;
  1879. }
  1880. #define CPSW_QUIRK_IRQ BIT(0)
  1881. static struct platform_device_id cpsw_devtype[] = {
  1882. {
  1883. /* keep it for existing comaptibles */
  1884. .name = "cpsw",
  1885. .driver_data = CPSW_QUIRK_IRQ,
  1886. }, {
  1887. .name = "am335x-cpsw",
  1888. .driver_data = CPSW_QUIRK_IRQ,
  1889. }, {
  1890. .name = "am4372-cpsw",
  1891. .driver_data = 0,
  1892. }, {
  1893. .name = "dra7-cpsw",
  1894. .driver_data = 0,
  1895. }, {
  1896. /* sentinel */
  1897. }
  1898. };
  1899. MODULE_DEVICE_TABLE(platform, cpsw_devtype);
  1900. enum ti_cpsw_type {
  1901. CPSW = 0,
  1902. AM335X_CPSW,
  1903. AM4372_CPSW,
  1904. DRA7_CPSW,
  1905. };
  1906. static const struct of_device_id cpsw_of_mtable[] = {
  1907. { .compatible = "ti,cpsw", .data = &cpsw_devtype[CPSW], },
  1908. { .compatible = "ti,am335x-cpsw", .data = &cpsw_devtype[AM335X_CPSW], },
  1909. { .compatible = "ti,am4372-cpsw", .data = &cpsw_devtype[AM4372_CPSW], },
  1910. { .compatible = "ti,dra7-cpsw", .data = &cpsw_devtype[DRA7_CPSW], },
  1911. { /* sentinel */ },
  1912. };
  1913. MODULE_DEVICE_TABLE(of, cpsw_of_mtable);
  1914. static int cpsw_probe(struct platform_device *pdev)
  1915. {
  1916. struct cpsw_platform_data *data;
  1917. struct net_device *ndev;
  1918. struct cpsw_priv *priv;
  1919. struct cpdma_params dma_params;
  1920. struct cpsw_ale_params ale_params;
  1921. void __iomem *ss_regs;
  1922. struct resource *res, *ss_res;
  1923. const struct of_device_id *of_id;
  1924. struct gpio_descs *mode;
  1925. u32 slave_offset, sliver_offset, slave_size;
  1926. int ret = 0, i;
  1927. int irq;
  1928. ndev = alloc_etherdev(sizeof(struct cpsw_priv));
  1929. if (!ndev) {
  1930. dev_err(&pdev->dev, "error allocating net_device\n");
  1931. return -ENOMEM;
  1932. }
  1933. platform_set_drvdata(pdev, ndev);
  1934. priv = netdev_priv(ndev);
  1935. priv->pdev = pdev;
  1936. priv->ndev = ndev;
  1937. priv->dev = &ndev->dev;
  1938. priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
  1939. priv->rx_packet_max = max(rx_packet_max, 128);
  1940. priv->cpts = devm_kzalloc(&pdev->dev, sizeof(struct cpts), GFP_KERNEL);
  1941. if (!priv->cpts) {
  1942. dev_err(&pdev->dev, "error allocating cpts\n");
  1943. ret = -ENOMEM;
  1944. goto clean_ndev_ret;
  1945. }
  1946. mode = devm_gpiod_get_array_optional(&pdev->dev, "mode", GPIOD_OUT_LOW);
  1947. if (IS_ERR(mode)) {
  1948. ret = PTR_ERR(mode);
  1949. dev_err(&pdev->dev, "gpio request failed, ret %d\n", ret);
  1950. goto clean_ndev_ret;
  1951. }
  1952. /*
  1953. * This may be required here for child devices.
  1954. */
  1955. pm_runtime_enable(&pdev->dev);
  1956. /* Select default pin state */
  1957. pinctrl_pm_select_default_state(&pdev->dev);
  1958. if (cpsw_probe_dt(&priv->data, pdev)) {
  1959. dev_err(&pdev->dev, "cpsw: platform data missing\n");
  1960. ret = -ENODEV;
  1961. goto clean_runtime_disable_ret;
  1962. }
  1963. data = &priv->data;
  1964. if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
  1965. memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
  1966. dev_info(&pdev->dev, "Detected MACID = %pM\n", priv->mac_addr);
  1967. } else {
  1968. eth_random_addr(priv->mac_addr);
  1969. dev_info(&pdev->dev, "Random MACID = %pM\n", priv->mac_addr);
  1970. }
  1971. memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
  1972. priv->slaves = devm_kzalloc(&pdev->dev,
  1973. sizeof(struct cpsw_slave) * data->slaves,
  1974. GFP_KERNEL);
  1975. if (!priv->slaves) {
  1976. ret = -ENOMEM;
  1977. goto clean_runtime_disable_ret;
  1978. }
  1979. for (i = 0; i < data->slaves; i++)
  1980. priv->slaves[i].slave_num = i;
  1981. priv->slaves[0].ndev = ndev;
  1982. priv->emac_port = 0;
  1983. priv->clk = devm_clk_get(&pdev->dev, "fck");
  1984. if (IS_ERR(priv->clk)) {
  1985. dev_err(priv->dev, "fck is not found\n");
  1986. ret = -ENODEV;
  1987. goto clean_runtime_disable_ret;
  1988. }
  1989. priv->coal_intvl = 0;
  1990. priv->bus_freq_mhz = clk_get_rate(priv->clk) / 1000000;
  1991. ss_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1992. ss_regs = devm_ioremap_resource(&pdev->dev, ss_res);
  1993. if (IS_ERR(ss_regs)) {
  1994. ret = PTR_ERR(ss_regs);
  1995. goto clean_runtime_disable_ret;
  1996. }
  1997. priv->regs = ss_regs;
  1998. /* Need to enable clocks with runtime PM api to access module
  1999. * registers
  2000. */
  2001. ret = pm_runtime_get_sync(&pdev->dev);
  2002. if (ret < 0) {
  2003. pm_runtime_put_noidle(&pdev->dev);
  2004. goto clean_runtime_disable_ret;
  2005. }
  2006. priv->version = readl(&priv->regs->id_ver);
  2007. pm_runtime_put_sync(&pdev->dev);
  2008. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  2009. priv->wr_regs = devm_ioremap_resource(&pdev->dev, res);
  2010. if (IS_ERR(priv->wr_regs)) {
  2011. ret = PTR_ERR(priv->wr_regs);
  2012. goto clean_runtime_disable_ret;
  2013. }
  2014. memset(&dma_params, 0, sizeof(dma_params));
  2015. memset(&ale_params, 0, sizeof(ale_params));
  2016. switch (priv->version) {
  2017. case CPSW_VERSION_1:
  2018. priv->host_port_regs = ss_regs + CPSW1_HOST_PORT_OFFSET;
  2019. priv->cpts->reg = ss_regs + CPSW1_CPTS_OFFSET;
  2020. priv->hw_stats = ss_regs + CPSW1_HW_STATS;
  2021. dma_params.dmaregs = ss_regs + CPSW1_CPDMA_OFFSET;
  2022. dma_params.txhdp = ss_regs + CPSW1_STATERAM_OFFSET;
  2023. ale_params.ale_regs = ss_regs + CPSW1_ALE_OFFSET;
  2024. slave_offset = CPSW1_SLAVE_OFFSET;
  2025. slave_size = CPSW1_SLAVE_SIZE;
  2026. sliver_offset = CPSW1_SLIVER_OFFSET;
  2027. dma_params.desc_mem_phys = 0;
  2028. break;
  2029. case CPSW_VERSION_2:
  2030. case CPSW_VERSION_3:
  2031. case CPSW_VERSION_4:
  2032. priv->host_port_regs = ss_regs + CPSW2_HOST_PORT_OFFSET;
  2033. priv->cpts->reg = ss_regs + CPSW2_CPTS_OFFSET;
  2034. priv->hw_stats = ss_regs + CPSW2_HW_STATS;
  2035. dma_params.dmaregs = ss_regs + CPSW2_CPDMA_OFFSET;
  2036. dma_params.txhdp = ss_regs + CPSW2_STATERAM_OFFSET;
  2037. ale_params.ale_regs = ss_regs + CPSW2_ALE_OFFSET;
  2038. slave_offset = CPSW2_SLAVE_OFFSET;
  2039. slave_size = CPSW2_SLAVE_SIZE;
  2040. sliver_offset = CPSW2_SLIVER_OFFSET;
  2041. dma_params.desc_mem_phys =
  2042. (u32 __force) ss_res->start + CPSW2_BD_OFFSET;
  2043. break;
  2044. default:
  2045. dev_err(priv->dev, "unknown version 0x%08x\n", priv->version);
  2046. ret = -ENODEV;
  2047. goto clean_runtime_disable_ret;
  2048. }
  2049. for (i = 0; i < priv->data.slaves; i++) {
  2050. struct cpsw_slave *slave = &priv->slaves[i];
  2051. cpsw_slave_init(slave, priv, slave_offset, sliver_offset);
  2052. slave_offset += slave_size;
  2053. sliver_offset += SLIVER_SIZE;
  2054. }
  2055. dma_params.dev = &pdev->dev;
  2056. dma_params.rxthresh = dma_params.dmaregs + CPDMA_RXTHRESH;
  2057. dma_params.rxfree = dma_params.dmaregs + CPDMA_RXFREE;
  2058. dma_params.rxhdp = dma_params.txhdp + CPDMA_RXHDP;
  2059. dma_params.txcp = dma_params.txhdp + CPDMA_TXCP;
  2060. dma_params.rxcp = dma_params.txhdp + CPDMA_RXCP;
  2061. dma_params.num_chan = data->channels;
  2062. dma_params.has_soft_reset = true;
  2063. dma_params.min_packet_size = CPSW_MIN_PACKET_SIZE;
  2064. dma_params.desc_mem_size = data->bd_ram_size;
  2065. dma_params.desc_align = 16;
  2066. dma_params.has_ext_regs = true;
  2067. dma_params.desc_hw_addr = dma_params.desc_mem_phys;
  2068. priv->dma = cpdma_ctlr_create(&dma_params);
  2069. if (!priv->dma) {
  2070. dev_err(priv->dev, "error initializing dma\n");
  2071. ret = -ENOMEM;
  2072. goto clean_runtime_disable_ret;
  2073. }
  2074. priv->txch = cpdma_chan_create(priv->dma, tx_chan_num(0),
  2075. cpsw_tx_handler);
  2076. priv->rxch = cpdma_chan_create(priv->dma, rx_chan_num(0),
  2077. cpsw_rx_handler);
  2078. if (WARN_ON(!priv->txch || !priv->rxch)) {
  2079. dev_err(priv->dev, "error initializing dma channels\n");
  2080. ret = -ENOMEM;
  2081. goto clean_dma_ret;
  2082. }
  2083. ale_params.dev = &ndev->dev;
  2084. ale_params.ale_ageout = ale_ageout;
  2085. ale_params.ale_entries = data->ale_entries;
  2086. ale_params.ale_ports = data->slaves;
  2087. priv->ale = cpsw_ale_create(&ale_params);
  2088. if (!priv->ale) {
  2089. dev_err(priv->dev, "error initializing ale engine\n");
  2090. ret = -ENODEV;
  2091. goto clean_dma_ret;
  2092. }
  2093. ndev->irq = platform_get_irq(pdev, 1);
  2094. if (ndev->irq < 0) {
  2095. dev_err(priv->dev, "error getting irq resource\n");
  2096. ret = ndev->irq;
  2097. goto clean_ale_ret;
  2098. }
  2099. of_id = of_match_device(cpsw_of_mtable, &pdev->dev);
  2100. if (of_id) {
  2101. pdev->id_entry = of_id->data;
  2102. if (pdev->id_entry->driver_data)
  2103. priv->quirk_irq = true;
  2104. }
  2105. /* Grab RX and TX IRQs. Note that we also have RX_THRESHOLD and
  2106. * MISC IRQs which are always kept disabled with this driver so
  2107. * we will not request them.
  2108. *
  2109. * If anyone wants to implement support for those, make sure to
  2110. * first request and append them to irqs_table array.
  2111. */
  2112. /* RX IRQ */
  2113. irq = platform_get_irq(pdev, 1);
  2114. if (irq < 0) {
  2115. ret = irq;
  2116. goto clean_ale_ret;
  2117. }
  2118. priv->irqs_table[0] = irq;
  2119. ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
  2120. 0, dev_name(&pdev->dev), priv);
  2121. if (ret < 0) {
  2122. dev_err(priv->dev, "error attaching irq (%d)\n", ret);
  2123. goto clean_ale_ret;
  2124. }
  2125. /* TX IRQ */
  2126. irq = platform_get_irq(pdev, 2);
  2127. if (irq < 0) {
  2128. ret = irq;
  2129. goto clean_ale_ret;
  2130. }
  2131. priv->irqs_table[1] = irq;
  2132. ret = devm_request_irq(&pdev->dev, irq, cpsw_tx_interrupt,
  2133. 0, dev_name(&pdev->dev), priv);
  2134. if (ret < 0) {
  2135. dev_err(priv->dev, "error attaching irq (%d)\n", ret);
  2136. goto clean_ale_ret;
  2137. }
  2138. priv->num_irqs = 2;
  2139. ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  2140. ndev->netdev_ops = &cpsw_netdev_ops;
  2141. ndev->ethtool_ops = &cpsw_ethtool_ops;
  2142. netif_napi_add(ndev, &priv->napi_rx, cpsw_rx_poll, CPSW_POLL_WEIGHT);
  2143. netif_tx_napi_add(ndev, &priv->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT);
  2144. /* register the network device */
  2145. SET_NETDEV_DEV(ndev, &pdev->dev);
  2146. ret = register_netdev(ndev);
  2147. if (ret) {
  2148. dev_err(priv->dev, "error registering net device\n");
  2149. ret = -ENODEV;
  2150. goto clean_ale_ret;
  2151. }
  2152. cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n",
  2153. &ss_res->start, ndev->irq);
  2154. if (priv->data.dual_emac) {
  2155. ret = cpsw_probe_dual_emac(pdev, priv);
  2156. if (ret) {
  2157. cpsw_err(priv, probe, "error probe slave 2 emac interface\n");
  2158. goto clean_ale_ret;
  2159. }
  2160. }
  2161. return 0;
  2162. clean_ale_ret:
  2163. cpsw_ale_destroy(priv->ale);
  2164. clean_dma_ret:
  2165. cpdma_ctlr_destroy(priv->dma);
  2166. clean_runtime_disable_ret:
  2167. pm_runtime_disable(&pdev->dev);
  2168. clean_ndev_ret:
  2169. free_netdev(priv->ndev);
  2170. return ret;
  2171. }
  2172. static int cpsw_remove(struct platform_device *pdev)
  2173. {
  2174. struct net_device *ndev = platform_get_drvdata(pdev);
  2175. struct cpsw_priv *priv = netdev_priv(ndev);
  2176. int ret;
  2177. ret = pm_runtime_get_sync(&pdev->dev);
  2178. if (ret < 0) {
  2179. pm_runtime_put_noidle(&pdev->dev);
  2180. return ret;
  2181. }
  2182. if (priv->data.dual_emac)
  2183. unregister_netdev(cpsw_get_slave_ndev(priv, 1));
  2184. unregister_netdev(ndev);
  2185. cpsw_ale_destroy(priv->ale);
  2186. cpdma_ctlr_destroy(priv->dma);
  2187. of_platform_depopulate(&pdev->dev);
  2188. pm_runtime_put_sync(&pdev->dev);
  2189. pm_runtime_disable(&pdev->dev);
  2190. if (priv->data.dual_emac)
  2191. free_netdev(cpsw_get_slave_ndev(priv, 1));
  2192. free_netdev(ndev);
  2193. return 0;
  2194. }
  2195. #ifdef CONFIG_PM_SLEEP
  2196. static int cpsw_suspend(struct device *dev)
  2197. {
  2198. struct platform_device *pdev = to_platform_device(dev);
  2199. struct net_device *ndev = platform_get_drvdata(pdev);
  2200. struct cpsw_priv *priv = netdev_priv(ndev);
  2201. if (priv->data.dual_emac) {
  2202. int i;
  2203. for (i = 0; i < priv->data.slaves; i++) {
  2204. if (netif_running(priv->slaves[i].ndev))
  2205. cpsw_ndo_stop(priv->slaves[i].ndev);
  2206. }
  2207. } else {
  2208. if (netif_running(ndev))
  2209. cpsw_ndo_stop(ndev);
  2210. }
  2211. /* Select sleep pin state */
  2212. pinctrl_pm_select_sleep_state(&pdev->dev);
  2213. return 0;
  2214. }
  2215. static int cpsw_resume(struct device *dev)
  2216. {
  2217. struct platform_device *pdev = to_platform_device(dev);
  2218. struct net_device *ndev = platform_get_drvdata(pdev);
  2219. struct cpsw_priv *priv = netdev_priv(ndev);
  2220. /* Select default pin state */
  2221. pinctrl_pm_select_default_state(&pdev->dev);
  2222. if (priv->data.dual_emac) {
  2223. int i;
  2224. for (i = 0; i < priv->data.slaves; i++) {
  2225. if (netif_running(priv->slaves[i].ndev))
  2226. cpsw_ndo_open(priv->slaves[i].ndev);
  2227. }
  2228. } else {
  2229. if (netif_running(ndev))
  2230. cpsw_ndo_open(ndev);
  2231. }
  2232. return 0;
  2233. }
  2234. #endif
  2235. static SIMPLE_DEV_PM_OPS(cpsw_pm_ops, cpsw_suspend, cpsw_resume);
  2236. static struct platform_driver cpsw_driver = {
  2237. .driver = {
  2238. .name = "cpsw",
  2239. .pm = &cpsw_pm_ops,
  2240. .of_match_table = cpsw_of_mtable,
  2241. },
  2242. .probe = cpsw_probe,
  2243. .remove = cpsw_remove,
  2244. };
  2245. module_platform_driver(cpsw_driver);
  2246. MODULE_LICENSE("GPL");
  2247. MODULE_AUTHOR("Cyril Chemparathy <cyril@ti.com>");
  2248. MODULE_AUTHOR("Mugunthan V N <mugunthanvnm@ti.com>");
  2249. MODULE_DESCRIPTION("TI CPSW Ethernet driver");