cpsw.c 72 KB

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