emac-mac.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. /* Qualcomm Technologies, Inc. EMAC Ethernet Controller MAC layer support
  13. */
  14. #include <linux/tcp.h>
  15. #include <linux/ip.h>
  16. #include <linux/ipv6.h>
  17. #include <linux/crc32.h>
  18. #include <linux/if_vlan.h>
  19. #include <linux/jiffies.h>
  20. #include <linux/phy.h>
  21. #include <linux/of.h>
  22. #include <net/ip6_checksum.h>
  23. #include "emac.h"
  24. #include "emac-sgmii.h"
  25. /* EMAC base register offsets */
  26. #define EMAC_MAC_CTRL 0x001480
  27. #define EMAC_WOL_CTRL0 0x0014a0
  28. #define EMAC_RSS_KEY0 0x0014b0
  29. #define EMAC_H1TPD_BASE_ADDR_LO 0x0014e0
  30. #define EMAC_H2TPD_BASE_ADDR_LO 0x0014e4
  31. #define EMAC_H3TPD_BASE_ADDR_LO 0x0014e8
  32. #define EMAC_INTER_SRAM_PART9 0x001534
  33. #define EMAC_DESC_CTRL_0 0x001540
  34. #define EMAC_DESC_CTRL_1 0x001544
  35. #define EMAC_DESC_CTRL_2 0x001550
  36. #define EMAC_DESC_CTRL_10 0x001554
  37. #define EMAC_DESC_CTRL_12 0x001558
  38. #define EMAC_DESC_CTRL_13 0x00155c
  39. #define EMAC_DESC_CTRL_3 0x001560
  40. #define EMAC_DESC_CTRL_4 0x001564
  41. #define EMAC_DESC_CTRL_5 0x001568
  42. #define EMAC_DESC_CTRL_14 0x00156c
  43. #define EMAC_DESC_CTRL_15 0x001570
  44. #define EMAC_DESC_CTRL_16 0x001574
  45. #define EMAC_DESC_CTRL_6 0x001578
  46. #define EMAC_DESC_CTRL_8 0x001580
  47. #define EMAC_DESC_CTRL_9 0x001584
  48. #define EMAC_DESC_CTRL_11 0x001588
  49. #define EMAC_TXQ_CTRL_0 0x001590
  50. #define EMAC_TXQ_CTRL_1 0x001594
  51. #define EMAC_TXQ_CTRL_2 0x001598
  52. #define EMAC_RXQ_CTRL_0 0x0015a0
  53. #define EMAC_RXQ_CTRL_1 0x0015a4
  54. #define EMAC_RXQ_CTRL_2 0x0015a8
  55. #define EMAC_RXQ_CTRL_3 0x0015ac
  56. #define EMAC_BASE_CPU_NUMBER 0x0015b8
  57. #define EMAC_DMA_CTRL 0x0015c0
  58. #define EMAC_MAILBOX_0 0x0015e0
  59. #define EMAC_MAILBOX_5 0x0015e4
  60. #define EMAC_MAILBOX_6 0x0015e8
  61. #define EMAC_MAILBOX_13 0x0015ec
  62. #define EMAC_MAILBOX_2 0x0015f4
  63. #define EMAC_MAILBOX_3 0x0015f8
  64. #define EMAC_MAILBOX_11 0x00160c
  65. #define EMAC_AXI_MAST_CTRL 0x001610
  66. #define EMAC_MAILBOX_12 0x001614
  67. #define EMAC_MAILBOX_9 0x001618
  68. #define EMAC_MAILBOX_10 0x00161c
  69. #define EMAC_ATHR_HEADER_CTRL 0x001620
  70. #define EMAC_CLK_GATE_CTRL 0x001814
  71. #define EMAC_MISC_CTRL 0x001990
  72. #define EMAC_MAILBOX_7 0x0019e0
  73. #define EMAC_MAILBOX_8 0x0019e4
  74. #define EMAC_MAILBOX_15 0x001bd4
  75. #define EMAC_MAILBOX_16 0x001bd8
  76. /* EMAC_MAC_CTRL */
  77. #define SINGLE_PAUSE_MODE 0x10000000
  78. #define DEBUG_MODE 0x08000000
  79. #define BROAD_EN 0x04000000
  80. #define MULTI_ALL 0x02000000
  81. #define RX_CHKSUM_EN 0x01000000
  82. #define HUGE 0x00800000
  83. #define SPEED(x) (((x) & 0x3) << 20)
  84. #define SPEED_MASK SPEED(0x3)
  85. #define SIMR 0x00080000
  86. #define TPAUSE 0x00010000
  87. #define PROM_MODE 0x00008000
  88. #define VLAN_STRIP 0x00004000
  89. #define PRLEN_BMSK 0x00003c00
  90. #define PRLEN_SHFT 10
  91. #define HUGEN 0x00000200
  92. #define FLCHK 0x00000100
  93. #define PCRCE 0x00000080
  94. #define CRCE 0x00000040
  95. #define FULLD 0x00000020
  96. #define MAC_LP_EN 0x00000010
  97. #define RXFC 0x00000008
  98. #define TXFC 0x00000004
  99. #define RXEN 0x00000002
  100. #define TXEN 0x00000001
  101. /* EMAC_WOL_CTRL0 */
  102. #define LK_CHG_PME 0x20
  103. #define LK_CHG_EN 0x10
  104. #define MG_FRAME_PME 0x8
  105. #define MG_FRAME_EN 0x4
  106. #define WK_FRAME_EN 0x1
  107. /* EMAC_DESC_CTRL_3 */
  108. #define RFD_RING_SIZE_BMSK 0xfff
  109. /* EMAC_DESC_CTRL_4 */
  110. #define RX_BUFFER_SIZE_BMSK 0xffff
  111. /* EMAC_DESC_CTRL_6 */
  112. #define RRD_RING_SIZE_BMSK 0xfff
  113. /* EMAC_DESC_CTRL_9 */
  114. #define TPD_RING_SIZE_BMSK 0xffff
  115. /* EMAC_TXQ_CTRL_0 */
  116. #define NUM_TXF_BURST_PREF_BMSK 0xffff0000
  117. #define NUM_TXF_BURST_PREF_SHFT 16
  118. #define LS_8023_SP 0x80
  119. #define TXQ_MODE 0x40
  120. #define TXQ_EN 0x20
  121. #define IP_OP_SP 0x10
  122. #define NUM_TPD_BURST_PREF_BMSK 0xf
  123. #define NUM_TPD_BURST_PREF_SHFT 0
  124. /* EMAC_TXQ_CTRL_1 */
  125. #define JUMBO_TASK_OFFLOAD_THRESHOLD_BMSK 0x7ff
  126. /* EMAC_TXQ_CTRL_2 */
  127. #define TXF_HWM_BMSK 0xfff0000
  128. #define TXF_LWM_BMSK 0xfff
  129. /* EMAC_RXQ_CTRL_0 */
  130. #define RXQ_EN BIT(31)
  131. #define CUT_THRU_EN BIT(30)
  132. #define RSS_HASH_EN BIT(29)
  133. #define NUM_RFD_BURST_PREF_BMSK 0x3f00000
  134. #define NUM_RFD_BURST_PREF_SHFT 20
  135. #define IDT_TABLE_SIZE_BMSK 0x1ff00
  136. #define IDT_TABLE_SIZE_SHFT 8
  137. #define SP_IPV6 0x80
  138. /* EMAC_RXQ_CTRL_1 */
  139. #define JUMBO_1KAH_BMSK 0xf000
  140. #define JUMBO_1KAH_SHFT 12
  141. #define RFD_PREF_LOW_TH 0x10
  142. #define RFD_PREF_LOW_THRESHOLD_BMSK 0xfc0
  143. #define RFD_PREF_LOW_THRESHOLD_SHFT 6
  144. #define RFD_PREF_UP_TH 0x10
  145. #define RFD_PREF_UP_THRESHOLD_BMSK 0x3f
  146. #define RFD_PREF_UP_THRESHOLD_SHFT 0
  147. /* EMAC_RXQ_CTRL_2 */
  148. #define RXF_DOF_THRESFHOLD 0x1a0
  149. #define RXF_DOF_THRESHOLD_BMSK 0xfff0000
  150. #define RXF_DOF_THRESHOLD_SHFT 16
  151. #define RXF_UOF_THRESFHOLD 0xbe
  152. #define RXF_UOF_THRESHOLD_BMSK 0xfff
  153. #define RXF_UOF_THRESHOLD_SHFT 0
  154. /* EMAC_RXQ_CTRL_3 */
  155. #define RXD_TIMER_BMSK 0xffff0000
  156. #define RXD_THRESHOLD_BMSK 0xfff
  157. #define RXD_THRESHOLD_SHFT 0
  158. /* EMAC_DMA_CTRL */
  159. #define DMAW_DLY_CNT_BMSK 0xf0000
  160. #define DMAW_DLY_CNT_SHFT 16
  161. #define DMAR_DLY_CNT_BMSK 0xf800
  162. #define DMAR_DLY_CNT_SHFT 11
  163. #define DMAR_REQ_PRI 0x400
  164. #define REGWRBLEN_BMSK 0x380
  165. #define REGWRBLEN_SHFT 7
  166. #define REGRDBLEN_BMSK 0x70
  167. #define REGRDBLEN_SHFT 4
  168. #define OUT_ORDER_MODE 0x4
  169. #define ENH_ORDER_MODE 0x2
  170. #define IN_ORDER_MODE 0x1
  171. /* EMAC_MAILBOX_13 */
  172. #define RFD3_PROC_IDX_BMSK 0xfff0000
  173. #define RFD3_PROC_IDX_SHFT 16
  174. #define RFD3_PROD_IDX_BMSK 0xfff
  175. #define RFD3_PROD_IDX_SHFT 0
  176. /* EMAC_MAILBOX_2 */
  177. #define NTPD_CONS_IDX_BMSK 0xffff0000
  178. #define NTPD_CONS_IDX_SHFT 16
  179. /* EMAC_MAILBOX_3 */
  180. #define RFD0_CONS_IDX_BMSK 0xfff
  181. #define RFD0_CONS_IDX_SHFT 0
  182. /* EMAC_MAILBOX_11 */
  183. #define H3TPD_PROD_IDX_BMSK 0xffff0000
  184. #define H3TPD_PROD_IDX_SHFT 16
  185. /* EMAC_AXI_MAST_CTRL */
  186. #define DATA_BYTE_SWAP 0x8
  187. #define MAX_BOUND 0x2
  188. #define MAX_BTYPE 0x1
  189. /* EMAC_MAILBOX_12 */
  190. #define H3TPD_CONS_IDX_BMSK 0xffff0000
  191. #define H3TPD_CONS_IDX_SHFT 16
  192. /* EMAC_MAILBOX_9 */
  193. #define H2TPD_PROD_IDX_BMSK 0xffff
  194. #define H2TPD_PROD_IDX_SHFT 0
  195. /* EMAC_MAILBOX_10 */
  196. #define H1TPD_CONS_IDX_BMSK 0xffff0000
  197. #define H1TPD_CONS_IDX_SHFT 16
  198. #define H2TPD_CONS_IDX_BMSK 0xffff
  199. #define H2TPD_CONS_IDX_SHFT 0
  200. /* EMAC_ATHR_HEADER_CTRL */
  201. #define HEADER_CNT_EN 0x2
  202. #define HEADER_ENABLE 0x1
  203. /* EMAC_MAILBOX_0 */
  204. #define RFD0_PROC_IDX_BMSK 0xfff0000
  205. #define RFD0_PROC_IDX_SHFT 16
  206. #define RFD0_PROD_IDX_BMSK 0xfff
  207. #define RFD0_PROD_IDX_SHFT 0
  208. /* EMAC_MAILBOX_5 */
  209. #define RFD1_PROC_IDX_BMSK 0xfff0000
  210. #define RFD1_PROC_IDX_SHFT 16
  211. #define RFD1_PROD_IDX_BMSK 0xfff
  212. #define RFD1_PROD_IDX_SHFT 0
  213. /* EMAC_MISC_CTRL */
  214. #define RX_UNCPL_INT_EN 0x1
  215. /* EMAC_MAILBOX_7 */
  216. #define RFD2_CONS_IDX_BMSK 0xfff0000
  217. #define RFD2_CONS_IDX_SHFT 16
  218. #define RFD1_CONS_IDX_BMSK 0xfff
  219. #define RFD1_CONS_IDX_SHFT 0
  220. /* EMAC_MAILBOX_8 */
  221. #define RFD3_CONS_IDX_BMSK 0xfff
  222. #define RFD3_CONS_IDX_SHFT 0
  223. /* EMAC_MAILBOX_15 */
  224. #define NTPD_PROD_IDX_BMSK 0xffff
  225. #define NTPD_PROD_IDX_SHFT 0
  226. /* EMAC_MAILBOX_16 */
  227. #define H1TPD_PROD_IDX_BMSK 0xffff
  228. #define H1TPD_PROD_IDX_SHFT 0
  229. #define RXQ0_RSS_HSTYP_IPV6_TCP_EN 0x20
  230. #define RXQ0_RSS_HSTYP_IPV6_EN 0x10
  231. #define RXQ0_RSS_HSTYP_IPV4_TCP_EN 0x8
  232. #define RXQ0_RSS_HSTYP_IPV4_EN 0x4
  233. /* EMAC_EMAC_WRAPPER_TX_TS_INX */
  234. #define EMAC_WRAPPER_TX_TS_EMPTY BIT(31)
  235. #define EMAC_WRAPPER_TX_TS_INX_BMSK 0xffff
  236. struct emac_skb_cb {
  237. u32 tpd_idx;
  238. unsigned long jiffies;
  239. };
  240. #define EMAC_SKB_CB(skb) ((struct emac_skb_cb *)(skb)->cb)
  241. #define EMAC_RSS_IDT_SIZE 256
  242. #define JUMBO_1KAH 0x4
  243. #define RXD_TH 0x100
  244. #define EMAC_TPD_LAST_FRAGMENT 0x80000000
  245. #define EMAC_TPD_TSTAMP_SAVE 0x80000000
  246. /* EMAC Errors in emac_rrd.word[3] */
  247. #define EMAC_RRD_L4F BIT(14)
  248. #define EMAC_RRD_IPF BIT(15)
  249. #define EMAC_RRD_CRC BIT(21)
  250. #define EMAC_RRD_FAE BIT(22)
  251. #define EMAC_RRD_TRN BIT(23)
  252. #define EMAC_RRD_RNT BIT(24)
  253. #define EMAC_RRD_INC BIT(25)
  254. #define EMAC_RRD_FOV BIT(29)
  255. #define EMAC_RRD_LEN BIT(30)
  256. /* Error bits that will result in a received frame being discarded */
  257. #define EMAC_RRD_ERROR (EMAC_RRD_IPF | EMAC_RRD_CRC | EMAC_RRD_FAE | \
  258. EMAC_RRD_TRN | EMAC_RRD_RNT | EMAC_RRD_INC | \
  259. EMAC_RRD_FOV | EMAC_RRD_LEN)
  260. #define EMAC_RRD_STATS_DW_IDX 3
  261. #define EMAC_RRD(RXQ, SIZE, IDX) ((RXQ)->rrd.v_addr + (SIZE * (IDX)))
  262. #define EMAC_RFD(RXQ, SIZE, IDX) ((RXQ)->rfd.v_addr + (SIZE * (IDX)))
  263. #define EMAC_TPD(TXQ, SIZE, IDX) ((TXQ)->tpd.v_addr + (SIZE * (IDX)))
  264. #define GET_RFD_BUFFER(RXQ, IDX) (&((RXQ)->rfd.rfbuff[(IDX)]))
  265. #define GET_TPD_BUFFER(RTQ, IDX) (&((RTQ)->tpd.tpbuff[(IDX)]))
  266. #define EMAC_TX_POLL_HWTXTSTAMP_THRESHOLD 8
  267. #define ISR_RX_PKT (\
  268. RX_PKT_INT0 |\
  269. RX_PKT_INT1 |\
  270. RX_PKT_INT2 |\
  271. RX_PKT_INT3)
  272. #define EMAC_MAC_IRQ_RES "core0"
  273. void emac_mac_multicast_addr_set(struct emac_adapter *adpt, u8 *addr)
  274. {
  275. u32 crc32, bit, reg, mta;
  276. /* Calculate the CRC of the MAC address */
  277. crc32 = ether_crc(ETH_ALEN, addr);
  278. /* The HASH Table is an array of 2 32-bit registers. It is
  279. * treated like an array of 64 bits (BitArray[hash_value]).
  280. * Use the upper 6 bits of the above CRC as the hash value.
  281. */
  282. reg = (crc32 >> 31) & 0x1;
  283. bit = (crc32 >> 26) & 0x1F;
  284. mta = readl(adpt->base + EMAC_HASH_TAB_REG0 + (reg << 2));
  285. mta |= BIT(bit);
  286. writel(mta, adpt->base + EMAC_HASH_TAB_REG0 + (reg << 2));
  287. }
  288. void emac_mac_multicast_addr_clear(struct emac_adapter *adpt)
  289. {
  290. writel(0, adpt->base + EMAC_HASH_TAB_REG0);
  291. writel(0, adpt->base + EMAC_HASH_TAB_REG1);
  292. }
  293. /* definitions for RSS */
  294. #define EMAC_RSS_KEY(_i, _type) \
  295. (EMAC_RSS_KEY0 + ((_i) * sizeof(_type)))
  296. #define EMAC_RSS_TBL(_i, _type) \
  297. (EMAC_IDT_TABLE0 + ((_i) * sizeof(_type)))
  298. /* Config MAC modes */
  299. void emac_mac_mode_config(struct emac_adapter *adpt)
  300. {
  301. struct net_device *netdev = adpt->netdev;
  302. u32 mac;
  303. mac = readl(adpt->base + EMAC_MAC_CTRL);
  304. mac &= ~(VLAN_STRIP | PROM_MODE | MULTI_ALL | MAC_LP_EN);
  305. if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  306. mac |= VLAN_STRIP;
  307. if (netdev->flags & IFF_PROMISC)
  308. mac |= PROM_MODE;
  309. if (netdev->flags & IFF_ALLMULTI)
  310. mac |= MULTI_ALL;
  311. writel(mac, adpt->base + EMAC_MAC_CTRL);
  312. }
  313. /* Config descriptor rings */
  314. static void emac_mac_dma_rings_config(struct emac_adapter *adpt)
  315. {
  316. static const unsigned short tpd_q_offset[] = {
  317. EMAC_DESC_CTRL_8, EMAC_H1TPD_BASE_ADDR_LO,
  318. EMAC_H2TPD_BASE_ADDR_LO, EMAC_H3TPD_BASE_ADDR_LO};
  319. static const unsigned short rfd_q_offset[] = {
  320. EMAC_DESC_CTRL_2, EMAC_DESC_CTRL_10,
  321. EMAC_DESC_CTRL_12, EMAC_DESC_CTRL_13};
  322. static const unsigned short rrd_q_offset[] = {
  323. EMAC_DESC_CTRL_5, EMAC_DESC_CTRL_14,
  324. EMAC_DESC_CTRL_15, EMAC_DESC_CTRL_16};
  325. /* TPD (Transmit Packet Descriptor) */
  326. writel(upper_32_bits(adpt->tx_q.tpd.dma_addr),
  327. adpt->base + EMAC_DESC_CTRL_1);
  328. writel(lower_32_bits(adpt->tx_q.tpd.dma_addr),
  329. adpt->base + tpd_q_offset[0]);
  330. writel(adpt->tx_q.tpd.count & TPD_RING_SIZE_BMSK,
  331. adpt->base + EMAC_DESC_CTRL_9);
  332. /* RFD (Receive Free Descriptor) & RRD (Receive Return Descriptor) */
  333. writel(upper_32_bits(adpt->rx_q.rfd.dma_addr),
  334. adpt->base + EMAC_DESC_CTRL_0);
  335. writel(lower_32_bits(adpt->rx_q.rfd.dma_addr),
  336. adpt->base + rfd_q_offset[0]);
  337. writel(lower_32_bits(adpt->rx_q.rrd.dma_addr),
  338. adpt->base + rrd_q_offset[0]);
  339. writel(adpt->rx_q.rfd.count & RFD_RING_SIZE_BMSK,
  340. adpt->base + EMAC_DESC_CTRL_3);
  341. writel(adpt->rx_q.rrd.count & RRD_RING_SIZE_BMSK,
  342. adpt->base + EMAC_DESC_CTRL_6);
  343. writel(adpt->rxbuf_size & RX_BUFFER_SIZE_BMSK,
  344. adpt->base + EMAC_DESC_CTRL_4);
  345. writel(0, adpt->base + EMAC_DESC_CTRL_11);
  346. /* Load all of the base addresses above and ensure that triggering HW to
  347. * read ring pointers is flushed
  348. */
  349. writel(1, adpt->base + EMAC_INTER_SRAM_PART9);
  350. }
  351. /* Config transmit parameters */
  352. static void emac_mac_tx_config(struct emac_adapter *adpt)
  353. {
  354. u32 val;
  355. writel((EMAC_MAX_TX_OFFLOAD_THRESH >> 3) &
  356. JUMBO_TASK_OFFLOAD_THRESHOLD_BMSK, adpt->base + EMAC_TXQ_CTRL_1);
  357. val = (adpt->tpd_burst << NUM_TPD_BURST_PREF_SHFT) &
  358. NUM_TPD_BURST_PREF_BMSK;
  359. val |= TXQ_MODE | LS_8023_SP;
  360. val |= (0x0100 << NUM_TXF_BURST_PREF_SHFT) &
  361. NUM_TXF_BURST_PREF_BMSK;
  362. writel(val, adpt->base + EMAC_TXQ_CTRL_0);
  363. emac_reg_update32(adpt->base + EMAC_TXQ_CTRL_2,
  364. (TXF_HWM_BMSK | TXF_LWM_BMSK), 0);
  365. }
  366. /* Config receive parameters */
  367. static void emac_mac_rx_config(struct emac_adapter *adpt)
  368. {
  369. u32 val;
  370. val = (adpt->rfd_burst << NUM_RFD_BURST_PREF_SHFT) &
  371. NUM_RFD_BURST_PREF_BMSK;
  372. val |= (SP_IPV6 | CUT_THRU_EN);
  373. writel(val, adpt->base + EMAC_RXQ_CTRL_0);
  374. val = readl(adpt->base + EMAC_RXQ_CTRL_1);
  375. val &= ~(JUMBO_1KAH_BMSK | RFD_PREF_LOW_THRESHOLD_BMSK |
  376. RFD_PREF_UP_THRESHOLD_BMSK);
  377. val |= (JUMBO_1KAH << JUMBO_1KAH_SHFT) |
  378. (RFD_PREF_LOW_TH << RFD_PREF_LOW_THRESHOLD_SHFT) |
  379. (RFD_PREF_UP_TH << RFD_PREF_UP_THRESHOLD_SHFT);
  380. writel(val, adpt->base + EMAC_RXQ_CTRL_1);
  381. val = readl(adpt->base + EMAC_RXQ_CTRL_2);
  382. val &= ~(RXF_DOF_THRESHOLD_BMSK | RXF_UOF_THRESHOLD_BMSK);
  383. val |= (RXF_DOF_THRESFHOLD << RXF_DOF_THRESHOLD_SHFT) |
  384. (RXF_UOF_THRESFHOLD << RXF_UOF_THRESHOLD_SHFT);
  385. writel(val, adpt->base + EMAC_RXQ_CTRL_2);
  386. val = readl(adpt->base + EMAC_RXQ_CTRL_3);
  387. val &= ~(RXD_TIMER_BMSK | RXD_THRESHOLD_BMSK);
  388. val |= RXD_TH << RXD_THRESHOLD_SHFT;
  389. writel(val, adpt->base + EMAC_RXQ_CTRL_3);
  390. }
  391. /* Config dma */
  392. static void emac_mac_dma_config(struct emac_adapter *adpt)
  393. {
  394. u32 dma_ctrl = DMAR_REQ_PRI;
  395. switch (adpt->dma_order) {
  396. case emac_dma_ord_in:
  397. dma_ctrl |= IN_ORDER_MODE;
  398. break;
  399. case emac_dma_ord_enh:
  400. dma_ctrl |= ENH_ORDER_MODE;
  401. break;
  402. case emac_dma_ord_out:
  403. dma_ctrl |= OUT_ORDER_MODE;
  404. break;
  405. default:
  406. break;
  407. }
  408. dma_ctrl |= (((u32)adpt->dmar_block) << REGRDBLEN_SHFT) &
  409. REGRDBLEN_BMSK;
  410. dma_ctrl |= (((u32)adpt->dmaw_block) << REGWRBLEN_SHFT) &
  411. REGWRBLEN_BMSK;
  412. dma_ctrl |= (((u32)adpt->dmar_dly_cnt) << DMAR_DLY_CNT_SHFT) &
  413. DMAR_DLY_CNT_BMSK;
  414. dma_ctrl |= (((u32)adpt->dmaw_dly_cnt) << DMAW_DLY_CNT_SHFT) &
  415. DMAW_DLY_CNT_BMSK;
  416. /* config DMA and ensure that configuration is flushed to HW */
  417. writel(dma_ctrl, adpt->base + EMAC_DMA_CTRL);
  418. }
  419. /* set MAC address */
  420. static void emac_set_mac_address(struct emac_adapter *adpt, u8 *addr)
  421. {
  422. u32 sta;
  423. /* for example: 00-A0-C6-11-22-33
  424. * 0<-->C6112233, 1<-->00A0.
  425. */
  426. /* low 32bit word */
  427. sta = (((u32)addr[2]) << 24) | (((u32)addr[3]) << 16) |
  428. (((u32)addr[4]) << 8) | (((u32)addr[5]));
  429. writel(sta, adpt->base + EMAC_MAC_STA_ADDR0);
  430. /* hight 32bit word */
  431. sta = (((u32)addr[0]) << 8) | (u32)addr[1];
  432. writel(sta, adpt->base + EMAC_MAC_STA_ADDR1);
  433. }
  434. static void emac_mac_config(struct emac_adapter *adpt)
  435. {
  436. struct net_device *netdev = adpt->netdev;
  437. unsigned int max_frame;
  438. u32 val;
  439. emac_set_mac_address(adpt, netdev->dev_addr);
  440. max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  441. adpt->rxbuf_size = netdev->mtu > EMAC_DEF_RX_BUF_SIZE ?
  442. ALIGN(max_frame, 8) : EMAC_DEF_RX_BUF_SIZE;
  443. emac_mac_dma_rings_config(adpt);
  444. writel(netdev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN,
  445. adpt->base + EMAC_MAX_FRAM_LEN_CTRL);
  446. emac_mac_tx_config(adpt);
  447. emac_mac_rx_config(adpt);
  448. emac_mac_dma_config(adpt);
  449. val = readl(adpt->base + EMAC_AXI_MAST_CTRL);
  450. val &= ~(DATA_BYTE_SWAP | MAX_BOUND);
  451. val |= MAX_BTYPE;
  452. writel(val, adpt->base + EMAC_AXI_MAST_CTRL);
  453. writel(0, adpt->base + EMAC_CLK_GATE_CTRL);
  454. writel(RX_UNCPL_INT_EN, adpt->base + EMAC_MISC_CTRL);
  455. }
  456. void emac_mac_reset(struct emac_adapter *adpt)
  457. {
  458. emac_mac_stop(adpt);
  459. emac_reg_update32(adpt->base + EMAC_DMA_MAS_CTRL, 0, SOFT_RST);
  460. usleep_range(100, 150); /* reset may take up to 100usec */
  461. /* interrupt clear-on-read */
  462. emac_reg_update32(adpt->base + EMAC_DMA_MAS_CTRL, 0, INT_RD_CLR_EN);
  463. }
  464. void emac_mac_start(struct emac_adapter *adpt)
  465. {
  466. struct phy_device *phydev = adpt->phydev;
  467. u32 mac, csr1;
  468. /* enable tx queue */
  469. emac_reg_update32(adpt->base + EMAC_TXQ_CTRL_0, 0, TXQ_EN);
  470. /* enable rx queue */
  471. emac_reg_update32(adpt->base + EMAC_RXQ_CTRL_0, 0, RXQ_EN);
  472. /* enable mac control */
  473. mac = readl(adpt->base + EMAC_MAC_CTRL);
  474. csr1 = readl(adpt->csr + EMAC_EMAC_WRAPPER_CSR1);
  475. mac |= TXEN | RXEN; /* enable RX/TX */
  476. /* Configure MAC flow control to match the PHY's settings. */
  477. if (phydev->pause)
  478. mac |= RXFC;
  479. if (phydev->pause != phydev->asym_pause)
  480. mac |= TXFC;
  481. /* setup link speed */
  482. mac &= ~SPEED_MASK;
  483. if (phydev->speed == SPEED_1000) {
  484. mac |= SPEED(2);
  485. csr1 |= FREQ_MODE;
  486. } else {
  487. mac |= SPEED(1);
  488. csr1 &= ~FREQ_MODE;
  489. }
  490. if (phydev->duplex == DUPLEX_FULL)
  491. mac |= FULLD;
  492. else
  493. mac &= ~FULLD;
  494. /* other parameters */
  495. mac |= (CRCE | PCRCE);
  496. mac |= ((adpt->preamble << PRLEN_SHFT) & PRLEN_BMSK);
  497. mac |= BROAD_EN;
  498. mac |= FLCHK;
  499. mac &= ~RX_CHKSUM_EN;
  500. mac &= ~(HUGEN | VLAN_STRIP | TPAUSE | SIMR | HUGE | MULTI_ALL |
  501. DEBUG_MODE | SINGLE_PAUSE_MODE);
  502. writel_relaxed(csr1, adpt->csr + EMAC_EMAC_WRAPPER_CSR1);
  503. writel_relaxed(mac, adpt->base + EMAC_MAC_CTRL);
  504. /* enable interrupt read clear, low power sleep mode and
  505. * the irq moderators
  506. */
  507. writel_relaxed(adpt->irq_mod, adpt->base + EMAC_IRQ_MOD_TIM_INIT);
  508. writel_relaxed(INT_RD_CLR_EN | LPW_MODE | IRQ_MODERATOR_EN |
  509. IRQ_MODERATOR2_EN, adpt->base + EMAC_DMA_MAS_CTRL);
  510. emac_mac_mode_config(adpt);
  511. emac_reg_update32(adpt->base + EMAC_ATHR_HEADER_CTRL,
  512. (HEADER_ENABLE | HEADER_CNT_EN), 0);
  513. emac_reg_update32(adpt->csr + EMAC_EMAC_WRAPPER_CSR2, 0, WOL_EN);
  514. }
  515. void emac_mac_stop(struct emac_adapter *adpt)
  516. {
  517. emac_reg_update32(adpt->base + EMAC_RXQ_CTRL_0, RXQ_EN, 0);
  518. emac_reg_update32(adpt->base + EMAC_TXQ_CTRL_0, TXQ_EN, 0);
  519. emac_reg_update32(adpt->base + EMAC_MAC_CTRL, TXEN | RXEN, 0);
  520. usleep_range(1000, 1050); /* stopping mac may take upto 1msec */
  521. }
  522. /* Free all descriptors of given transmit queue */
  523. static void emac_tx_q_descs_free(struct emac_adapter *adpt)
  524. {
  525. struct emac_tx_queue *tx_q = &adpt->tx_q;
  526. unsigned int i;
  527. size_t size;
  528. /* ring already cleared, nothing to do */
  529. if (!tx_q->tpd.tpbuff)
  530. return;
  531. for (i = 0; i < tx_q->tpd.count; i++) {
  532. struct emac_buffer *tpbuf = GET_TPD_BUFFER(tx_q, i);
  533. if (tpbuf->dma_addr) {
  534. dma_unmap_single(adpt->netdev->dev.parent,
  535. tpbuf->dma_addr, tpbuf->length,
  536. DMA_TO_DEVICE);
  537. tpbuf->dma_addr = 0;
  538. }
  539. if (tpbuf->skb) {
  540. dev_kfree_skb_any(tpbuf->skb);
  541. tpbuf->skb = NULL;
  542. }
  543. }
  544. size = sizeof(struct emac_buffer) * tx_q->tpd.count;
  545. memset(tx_q->tpd.tpbuff, 0, size);
  546. /* clear the descriptor ring */
  547. memset(tx_q->tpd.v_addr, 0, tx_q->tpd.size);
  548. tx_q->tpd.consume_idx = 0;
  549. tx_q->tpd.produce_idx = 0;
  550. }
  551. /* Free all descriptors of given receive queue */
  552. static void emac_rx_q_free_descs(struct emac_adapter *adpt)
  553. {
  554. struct device *dev = adpt->netdev->dev.parent;
  555. struct emac_rx_queue *rx_q = &adpt->rx_q;
  556. unsigned int i;
  557. size_t size;
  558. /* ring already cleared, nothing to do */
  559. if (!rx_q->rfd.rfbuff)
  560. return;
  561. for (i = 0; i < rx_q->rfd.count; i++) {
  562. struct emac_buffer *rfbuf = GET_RFD_BUFFER(rx_q, i);
  563. if (rfbuf->dma_addr) {
  564. dma_unmap_single(dev, rfbuf->dma_addr, rfbuf->length,
  565. DMA_FROM_DEVICE);
  566. rfbuf->dma_addr = 0;
  567. }
  568. if (rfbuf->skb) {
  569. dev_kfree_skb(rfbuf->skb);
  570. rfbuf->skb = NULL;
  571. }
  572. }
  573. size = sizeof(struct emac_buffer) * rx_q->rfd.count;
  574. memset(rx_q->rfd.rfbuff, 0, size);
  575. /* clear the descriptor rings */
  576. memset(rx_q->rrd.v_addr, 0, rx_q->rrd.size);
  577. rx_q->rrd.produce_idx = 0;
  578. rx_q->rrd.consume_idx = 0;
  579. memset(rx_q->rfd.v_addr, 0, rx_q->rfd.size);
  580. rx_q->rfd.produce_idx = 0;
  581. rx_q->rfd.consume_idx = 0;
  582. }
  583. /* Free all buffers associated with given transmit queue */
  584. static void emac_tx_q_bufs_free(struct emac_adapter *adpt)
  585. {
  586. struct emac_tx_queue *tx_q = &adpt->tx_q;
  587. emac_tx_q_descs_free(adpt);
  588. kfree(tx_q->tpd.tpbuff);
  589. tx_q->tpd.tpbuff = NULL;
  590. tx_q->tpd.v_addr = NULL;
  591. tx_q->tpd.dma_addr = 0;
  592. tx_q->tpd.size = 0;
  593. }
  594. /* Allocate TX descriptor ring for the given transmit queue */
  595. static int emac_tx_q_desc_alloc(struct emac_adapter *adpt,
  596. struct emac_tx_queue *tx_q)
  597. {
  598. struct emac_ring_header *ring_header = &adpt->ring_header;
  599. size_t size;
  600. size = sizeof(struct emac_buffer) * tx_q->tpd.count;
  601. tx_q->tpd.tpbuff = kzalloc(size, GFP_KERNEL);
  602. if (!tx_q->tpd.tpbuff)
  603. return -ENOMEM;
  604. tx_q->tpd.size = tx_q->tpd.count * (adpt->tpd_size * 4);
  605. tx_q->tpd.dma_addr = ring_header->dma_addr + ring_header->used;
  606. tx_q->tpd.v_addr = ring_header->v_addr + ring_header->used;
  607. ring_header->used += ALIGN(tx_q->tpd.size, 8);
  608. tx_q->tpd.produce_idx = 0;
  609. tx_q->tpd.consume_idx = 0;
  610. return 0;
  611. }
  612. /* Free all buffers associated with given transmit queue */
  613. static void emac_rx_q_bufs_free(struct emac_adapter *adpt)
  614. {
  615. struct emac_rx_queue *rx_q = &adpt->rx_q;
  616. emac_rx_q_free_descs(adpt);
  617. kfree(rx_q->rfd.rfbuff);
  618. rx_q->rfd.rfbuff = NULL;
  619. rx_q->rfd.v_addr = NULL;
  620. rx_q->rfd.dma_addr = 0;
  621. rx_q->rfd.size = 0;
  622. rx_q->rrd.v_addr = NULL;
  623. rx_q->rrd.dma_addr = 0;
  624. rx_q->rrd.size = 0;
  625. }
  626. /* Allocate RX descriptor rings for the given receive queue */
  627. static int emac_rx_descs_alloc(struct emac_adapter *adpt)
  628. {
  629. struct emac_ring_header *ring_header = &adpt->ring_header;
  630. struct emac_rx_queue *rx_q = &adpt->rx_q;
  631. size_t size;
  632. size = sizeof(struct emac_buffer) * rx_q->rfd.count;
  633. rx_q->rfd.rfbuff = kzalloc(size, GFP_KERNEL);
  634. if (!rx_q->rfd.rfbuff)
  635. return -ENOMEM;
  636. rx_q->rrd.size = rx_q->rrd.count * (adpt->rrd_size * 4);
  637. rx_q->rfd.size = rx_q->rfd.count * (adpt->rfd_size * 4);
  638. rx_q->rrd.dma_addr = ring_header->dma_addr + ring_header->used;
  639. rx_q->rrd.v_addr = ring_header->v_addr + ring_header->used;
  640. ring_header->used += ALIGN(rx_q->rrd.size, 8);
  641. rx_q->rfd.dma_addr = ring_header->dma_addr + ring_header->used;
  642. rx_q->rfd.v_addr = ring_header->v_addr + ring_header->used;
  643. ring_header->used += ALIGN(rx_q->rfd.size, 8);
  644. rx_q->rrd.produce_idx = 0;
  645. rx_q->rrd.consume_idx = 0;
  646. rx_q->rfd.produce_idx = 0;
  647. rx_q->rfd.consume_idx = 0;
  648. return 0;
  649. }
  650. /* Allocate all TX and RX descriptor rings */
  651. int emac_mac_rx_tx_rings_alloc_all(struct emac_adapter *adpt)
  652. {
  653. struct emac_ring_header *ring_header = &adpt->ring_header;
  654. struct device *dev = adpt->netdev->dev.parent;
  655. unsigned int num_tx_descs = adpt->tx_desc_cnt;
  656. unsigned int num_rx_descs = adpt->rx_desc_cnt;
  657. int ret;
  658. adpt->tx_q.tpd.count = adpt->tx_desc_cnt;
  659. adpt->rx_q.rrd.count = adpt->rx_desc_cnt;
  660. adpt->rx_q.rfd.count = adpt->rx_desc_cnt;
  661. /* Ring DMA buffer. Each ring may need up to 8 bytes for alignment,
  662. * hence the additional padding bytes are allocated.
  663. */
  664. ring_header->size = num_tx_descs * (adpt->tpd_size * 4) +
  665. num_rx_descs * (adpt->rfd_size * 4) +
  666. num_rx_descs * (adpt->rrd_size * 4) +
  667. 8 + 2 * 8; /* 8 byte per one Tx and two Rx rings */
  668. ring_header->used = 0;
  669. ring_header->v_addr = dma_zalloc_coherent(dev, ring_header->size,
  670. &ring_header->dma_addr,
  671. GFP_KERNEL);
  672. if (!ring_header->v_addr)
  673. return -ENOMEM;
  674. ring_header->used = ALIGN(ring_header->dma_addr, 8) -
  675. ring_header->dma_addr;
  676. ret = emac_tx_q_desc_alloc(adpt, &adpt->tx_q);
  677. if (ret) {
  678. netdev_err(adpt->netdev, "error: Tx Queue alloc failed\n");
  679. goto err_alloc_tx;
  680. }
  681. ret = emac_rx_descs_alloc(adpt);
  682. if (ret) {
  683. netdev_err(adpt->netdev, "error: Rx Queue alloc failed\n");
  684. goto err_alloc_rx;
  685. }
  686. return 0;
  687. err_alloc_rx:
  688. emac_tx_q_bufs_free(adpt);
  689. err_alloc_tx:
  690. dma_free_coherent(dev, ring_header->size,
  691. ring_header->v_addr, ring_header->dma_addr);
  692. ring_header->v_addr = NULL;
  693. ring_header->dma_addr = 0;
  694. ring_header->size = 0;
  695. ring_header->used = 0;
  696. return ret;
  697. }
  698. /* Free all TX and RX descriptor rings */
  699. void emac_mac_rx_tx_rings_free_all(struct emac_adapter *adpt)
  700. {
  701. struct emac_ring_header *ring_header = &adpt->ring_header;
  702. struct device *dev = adpt->netdev->dev.parent;
  703. emac_tx_q_bufs_free(adpt);
  704. emac_rx_q_bufs_free(adpt);
  705. dma_free_coherent(dev, ring_header->size,
  706. ring_header->v_addr, ring_header->dma_addr);
  707. ring_header->v_addr = NULL;
  708. ring_header->dma_addr = 0;
  709. ring_header->size = 0;
  710. ring_header->used = 0;
  711. }
  712. /* Initialize descriptor rings */
  713. static void emac_mac_rx_tx_ring_reset_all(struct emac_adapter *adpt)
  714. {
  715. unsigned int i;
  716. adpt->tx_q.tpd.produce_idx = 0;
  717. adpt->tx_q.tpd.consume_idx = 0;
  718. for (i = 0; i < adpt->tx_q.tpd.count; i++)
  719. adpt->tx_q.tpd.tpbuff[i].dma_addr = 0;
  720. adpt->rx_q.rrd.produce_idx = 0;
  721. adpt->rx_q.rrd.consume_idx = 0;
  722. adpt->rx_q.rfd.produce_idx = 0;
  723. adpt->rx_q.rfd.consume_idx = 0;
  724. for (i = 0; i < adpt->rx_q.rfd.count; i++)
  725. adpt->rx_q.rfd.rfbuff[i].dma_addr = 0;
  726. }
  727. /* Produce new receive free descriptor */
  728. static void emac_mac_rx_rfd_create(struct emac_adapter *adpt,
  729. struct emac_rx_queue *rx_q,
  730. dma_addr_t addr)
  731. {
  732. u32 *hw_rfd = EMAC_RFD(rx_q, adpt->rfd_size, rx_q->rfd.produce_idx);
  733. *(hw_rfd++) = lower_32_bits(addr);
  734. *hw_rfd = upper_32_bits(addr);
  735. if (++rx_q->rfd.produce_idx == rx_q->rfd.count)
  736. rx_q->rfd.produce_idx = 0;
  737. }
  738. /* Fill up receive queue's RFD with preallocated receive buffers */
  739. static void emac_mac_rx_descs_refill(struct emac_adapter *adpt,
  740. struct emac_rx_queue *rx_q)
  741. {
  742. struct emac_buffer *curr_rxbuf;
  743. struct emac_buffer *next_rxbuf;
  744. unsigned int count = 0;
  745. u32 next_produce_idx;
  746. next_produce_idx = rx_q->rfd.produce_idx + 1;
  747. if (next_produce_idx == rx_q->rfd.count)
  748. next_produce_idx = 0;
  749. curr_rxbuf = GET_RFD_BUFFER(rx_q, rx_q->rfd.produce_idx);
  750. next_rxbuf = GET_RFD_BUFFER(rx_q, next_produce_idx);
  751. /* this always has a blank rx_buffer*/
  752. while (!next_rxbuf->dma_addr) {
  753. struct sk_buff *skb;
  754. int ret;
  755. skb = netdev_alloc_skb_ip_align(adpt->netdev, adpt->rxbuf_size);
  756. if (!skb)
  757. break;
  758. curr_rxbuf->dma_addr =
  759. dma_map_single(adpt->netdev->dev.parent, skb->data,
  760. adpt->rxbuf_size, DMA_FROM_DEVICE);
  761. ret = dma_mapping_error(adpt->netdev->dev.parent,
  762. curr_rxbuf->dma_addr);
  763. if (ret) {
  764. dev_kfree_skb(skb);
  765. break;
  766. }
  767. curr_rxbuf->skb = skb;
  768. curr_rxbuf->length = adpt->rxbuf_size;
  769. emac_mac_rx_rfd_create(adpt, rx_q, curr_rxbuf->dma_addr);
  770. next_produce_idx = rx_q->rfd.produce_idx + 1;
  771. if (next_produce_idx == rx_q->rfd.count)
  772. next_produce_idx = 0;
  773. curr_rxbuf = GET_RFD_BUFFER(rx_q, rx_q->rfd.produce_idx);
  774. next_rxbuf = GET_RFD_BUFFER(rx_q, next_produce_idx);
  775. count++;
  776. }
  777. if (count) {
  778. u32 prod_idx = (rx_q->rfd.produce_idx << rx_q->produce_shift) &
  779. rx_q->produce_mask;
  780. emac_reg_update32(adpt->base + rx_q->produce_reg,
  781. rx_q->produce_mask, prod_idx);
  782. }
  783. }
  784. static void emac_adjust_link(struct net_device *netdev)
  785. {
  786. struct emac_adapter *adpt = netdev_priv(netdev);
  787. struct phy_device *phydev = netdev->phydev;
  788. if (phydev->link)
  789. emac_mac_start(adpt);
  790. else
  791. emac_mac_stop(adpt);
  792. phy_print_status(phydev);
  793. }
  794. /* Bringup the interface/HW */
  795. int emac_mac_up(struct emac_adapter *adpt)
  796. {
  797. struct net_device *netdev = adpt->netdev;
  798. struct emac_irq *irq = &adpt->irq;
  799. int ret;
  800. emac_mac_rx_tx_ring_reset_all(adpt);
  801. emac_mac_config(adpt);
  802. ret = request_irq(irq->irq, emac_isr, 0, EMAC_MAC_IRQ_RES, irq);
  803. if (ret) {
  804. netdev_err(adpt->netdev, "could not request %s irq\n",
  805. EMAC_MAC_IRQ_RES);
  806. return ret;
  807. }
  808. emac_mac_rx_descs_refill(adpt, &adpt->rx_q);
  809. ret = phy_connect_direct(netdev, adpt->phydev, emac_adjust_link,
  810. PHY_INTERFACE_MODE_SGMII);
  811. if (ret) {
  812. netdev_err(adpt->netdev, "could not connect phy\n");
  813. free_irq(irq->irq, irq);
  814. return ret;
  815. }
  816. /* enable mac irq */
  817. writel((u32)~DIS_INT, adpt->base + EMAC_INT_STATUS);
  818. writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
  819. /* Enable pause frames. Without this feature, the EMAC has been shown
  820. * to receive (and drop) frames with FCS errors at gigabit connections.
  821. */
  822. adpt->phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  823. adpt->phydev->advertising |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  824. adpt->phydev->irq = PHY_IGNORE_INTERRUPT;
  825. phy_start(adpt->phydev);
  826. napi_enable(&adpt->rx_q.napi);
  827. netif_start_queue(netdev);
  828. return 0;
  829. }
  830. /* Bring down the interface/HW */
  831. void emac_mac_down(struct emac_adapter *adpt)
  832. {
  833. struct net_device *netdev = adpt->netdev;
  834. netif_stop_queue(netdev);
  835. napi_disable(&adpt->rx_q.napi);
  836. phy_stop(adpt->phydev);
  837. /* Interrupts must be disabled before the PHY is disconnected, to
  838. * avoid a race condition where adjust_link is null when we get
  839. * an interrupt.
  840. */
  841. writel(DIS_INT, adpt->base + EMAC_INT_STATUS);
  842. writel(0, adpt->base + EMAC_INT_MASK);
  843. synchronize_irq(adpt->irq.irq);
  844. free_irq(adpt->irq.irq, &adpt->irq);
  845. phy_disconnect(adpt->phydev);
  846. emac_mac_reset(adpt);
  847. emac_tx_q_descs_free(adpt);
  848. netdev_reset_queue(adpt->netdev);
  849. emac_rx_q_free_descs(adpt);
  850. }
  851. /* Consume next received packet descriptor */
  852. static bool emac_rx_process_rrd(struct emac_adapter *adpt,
  853. struct emac_rx_queue *rx_q,
  854. struct emac_rrd *rrd)
  855. {
  856. u32 *hw_rrd = EMAC_RRD(rx_q, adpt->rrd_size, rx_q->rrd.consume_idx);
  857. rrd->word[3] = *(hw_rrd + 3);
  858. if (!RRD_UPDT(rrd))
  859. return false;
  860. rrd->word[4] = 0;
  861. rrd->word[5] = 0;
  862. rrd->word[0] = *(hw_rrd++);
  863. rrd->word[1] = *(hw_rrd++);
  864. rrd->word[2] = *(hw_rrd++);
  865. if (unlikely(RRD_NOR(rrd) != 1)) {
  866. netdev_err(adpt->netdev,
  867. "error: multi-RFD not support yet! nor:%lu\n",
  868. RRD_NOR(rrd));
  869. }
  870. /* mark rrd as processed */
  871. RRD_UPDT_SET(rrd, 0);
  872. *hw_rrd = rrd->word[3];
  873. if (++rx_q->rrd.consume_idx == rx_q->rrd.count)
  874. rx_q->rrd.consume_idx = 0;
  875. return true;
  876. }
  877. /* Produce new transmit descriptor */
  878. static void emac_tx_tpd_create(struct emac_adapter *adpt,
  879. struct emac_tx_queue *tx_q, struct emac_tpd *tpd)
  880. {
  881. u32 *hw_tpd;
  882. tx_q->tpd.last_produce_idx = tx_q->tpd.produce_idx;
  883. hw_tpd = EMAC_TPD(tx_q, adpt->tpd_size, tx_q->tpd.produce_idx);
  884. if (++tx_q->tpd.produce_idx == tx_q->tpd.count)
  885. tx_q->tpd.produce_idx = 0;
  886. *(hw_tpd++) = tpd->word[0];
  887. *(hw_tpd++) = tpd->word[1];
  888. *(hw_tpd++) = tpd->word[2];
  889. *hw_tpd = tpd->word[3];
  890. }
  891. /* Mark the last transmit descriptor as such (for the transmit packet) */
  892. static void emac_tx_tpd_mark_last(struct emac_adapter *adpt,
  893. struct emac_tx_queue *tx_q)
  894. {
  895. u32 *hw_tpd =
  896. EMAC_TPD(tx_q, adpt->tpd_size, tx_q->tpd.last_produce_idx);
  897. u32 tmp_tpd;
  898. tmp_tpd = *(hw_tpd + 1);
  899. tmp_tpd |= EMAC_TPD_LAST_FRAGMENT;
  900. *(hw_tpd + 1) = tmp_tpd;
  901. }
  902. static void emac_rx_rfd_clean(struct emac_rx_queue *rx_q, struct emac_rrd *rrd)
  903. {
  904. struct emac_buffer *rfbuf = rx_q->rfd.rfbuff;
  905. u32 consume_idx = RRD_SI(rrd);
  906. unsigned int i;
  907. for (i = 0; i < RRD_NOR(rrd); i++) {
  908. rfbuf[consume_idx].skb = NULL;
  909. if (++consume_idx == rx_q->rfd.count)
  910. consume_idx = 0;
  911. }
  912. rx_q->rfd.consume_idx = consume_idx;
  913. rx_q->rfd.process_idx = consume_idx;
  914. }
  915. /* Push the received skb to upper layers */
  916. static void emac_receive_skb(struct emac_rx_queue *rx_q,
  917. struct sk_buff *skb,
  918. u16 vlan_tag, bool vlan_flag)
  919. {
  920. if (vlan_flag) {
  921. u16 vlan;
  922. EMAC_TAG_TO_VLAN(vlan_tag, vlan);
  923. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan);
  924. }
  925. napi_gro_receive(&rx_q->napi, skb);
  926. }
  927. /* Process receive event */
  928. void emac_mac_rx_process(struct emac_adapter *adpt, struct emac_rx_queue *rx_q,
  929. int *num_pkts, int max_pkts)
  930. {
  931. u32 proc_idx, hw_consume_idx, num_consume_pkts;
  932. struct net_device *netdev = adpt->netdev;
  933. struct emac_buffer *rfbuf;
  934. unsigned int count = 0;
  935. struct emac_rrd rrd;
  936. struct sk_buff *skb;
  937. u32 reg;
  938. reg = readl_relaxed(adpt->base + rx_q->consume_reg);
  939. hw_consume_idx = (reg & rx_q->consume_mask) >> rx_q->consume_shift;
  940. num_consume_pkts = (hw_consume_idx >= rx_q->rrd.consume_idx) ?
  941. (hw_consume_idx - rx_q->rrd.consume_idx) :
  942. (hw_consume_idx + rx_q->rrd.count - rx_q->rrd.consume_idx);
  943. do {
  944. if (!num_consume_pkts)
  945. break;
  946. if (!emac_rx_process_rrd(adpt, rx_q, &rrd))
  947. break;
  948. if (likely(RRD_NOR(&rrd) == 1)) {
  949. /* good receive */
  950. rfbuf = GET_RFD_BUFFER(rx_q, RRD_SI(&rrd));
  951. dma_unmap_single(adpt->netdev->dev.parent,
  952. rfbuf->dma_addr, rfbuf->length,
  953. DMA_FROM_DEVICE);
  954. rfbuf->dma_addr = 0;
  955. skb = rfbuf->skb;
  956. } else {
  957. netdev_err(adpt->netdev,
  958. "error: multi-RFD not support yet!\n");
  959. break;
  960. }
  961. emac_rx_rfd_clean(rx_q, &rrd);
  962. num_consume_pkts--;
  963. count++;
  964. /* Due to a HW issue in L4 check sum detection (UDP/TCP frags
  965. * with DF set are marked as error), drop packets based on the
  966. * error mask rather than the summary bit (ignoring L4F errors)
  967. */
  968. if (rrd.word[EMAC_RRD_STATS_DW_IDX] & EMAC_RRD_ERROR) {
  969. netif_dbg(adpt, rx_status, adpt->netdev,
  970. "Drop error packet[RRD: 0x%x:0x%x:0x%x:0x%x]\n",
  971. rrd.word[0], rrd.word[1],
  972. rrd.word[2], rrd.word[3]);
  973. dev_kfree_skb(skb);
  974. continue;
  975. }
  976. skb_put(skb, RRD_PKT_SIZE(&rrd) - ETH_FCS_LEN);
  977. skb->dev = netdev;
  978. skb->protocol = eth_type_trans(skb, skb->dev);
  979. if (netdev->features & NETIF_F_RXCSUM)
  980. skb->ip_summed = RRD_L4F(&rrd) ?
  981. CHECKSUM_NONE : CHECKSUM_UNNECESSARY;
  982. else
  983. skb_checksum_none_assert(skb);
  984. emac_receive_skb(rx_q, skb, (u16)RRD_CVALN_TAG(&rrd),
  985. (bool)RRD_CVTAG(&rrd));
  986. netdev->last_rx = jiffies;
  987. (*num_pkts)++;
  988. } while (*num_pkts < max_pkts);
  989. if (count) {
  990. proc_idx = (rx_q->rfd.process_idx << rx_q->process_shft) &
  991. rx_q->process_mask;
  992. emac_reg_update32(adpt->base + rx_q->process_reg,
  993. rx_q->process_mask, proc_idx);
  994. emac_mac_rx_descs_refill(adpt, rx_q);
  995. }
  996. }
  997. /* get the number of free transmit descriptors */
  998. static unsigned int emac_tpd_num_free_descs(struct emac_tx_queue *tx_q)
  999. {
  1000. u32 produce_idx = tx_q->tpd.produce_idx;
  1001. u32 consume_idx = tx_q->tpd.consume_idx;
  1002. return (consume_idx > produce_idx) ?
  1003. (consume_idx - produce_idx - 1) :
  1004. (tx_q->tpd.count + consume_idx - produce_idx - 1);
  1005. }
  1006. /* Process transmit event */
  1007. void emac_mac_tx_process(struct emac_adapter *adpt, struct emac_tx_queue *tx_q)
  1008. {
  1009. u32 reg = readl_relaxed(adpt->base + tx_q->consume_reg);
  1010. u32 hw_consume_idx, pkts_compl = 0, bytes_compl = 0;
  1011. struct emac_buffer *tpbuf;
  1012. hw_consume_idx = (reg & tx_q->consume_mask) >> tx_q->consume_shift;
  1013. while (tx_q->tpd.consume_idx != hw_consume_idx) {
  1014. tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.consume_idx);
  1015. if (tpbuf->dma_addr) {
  1016. dma_unmap_page(adpt->netdev->dev.parent,
  1017. tpbuf->dma_addr, tpbuf->length,
  1018. DMA_TO_DEVICE);
  1019. tpbuf->dma_addr = 0;
  1020. }
  1021. if (tpbuf->skb) {
  1022. pkts_compl++;
  1023. bytes_compl += tpbuf->skb->len;
  1024. dev_kfree_skb_irq(tpbuf->skb);
  1025. tpbuf->skb = NULL;
  1026. }
  1027. if (++tx_q->tpd.consume_idx == tx_q->tpd.count)
  1028. tx_q->tpd.consume_idx = 0;
  1029. }
  1030. netdev_completed_queue(adpt->netdev, pkts_compl, bytes_compl);
  1031. if (netif_queue_stopped(adpt->netdev))
  1032. if (emac_tpd_num_free_descs(tx_q) > (MAX_SKB_FRAGS + 1))
  1033. netif_wake_queue(adpt->netdev);
  1034. }
  1035. /* Initialize all queue data structures */
  1036. void emac_mac_rx_tx_ring_init_all(struct platform_device *pdev,
  1037. struct emac_adapter *adpt)
  1038. {
  1039. adpt->rx_q.netdev = adpt->netdev;
  1040. adpt->rx_q.produce_reg = EMAC_MAILBOX_0;
  1041. adpt->rx_q.produce_mask = RFD0_PROD_IDX_BMSK;
  1042. adpt->rx_q.produce_shift = RFD0_PROD_IDX_SHFT;
  1043. adpt->rx_q.process_reg = EMAC_MAILBOX_0;
  1044. adpt->rx_q.process_mask = RFD0_PROC_IDX_BMSK;
  1045. adpt->rx_q.process_shft = RFD0_PROC_IDX_SHFT;
  1046. adpt->rx_q.consume_reg = EMAC_MAILBOX_3;
  1047. adpt->rx_q.consume_mask = RFD0_CONS_IDX_BMSK;
  1048. adpt->rx_q.consume_shift = RFD0_CONS_IDX_SHFT;
  1049. adpt->rx_q.irq = &adpt->irq;
  1050. adpt->rx_q.intr = adpt->irq.mask & ISR_RX_PKT;
  1051. adpt->tx_q.produce_reg = EMAC_MAILBOX_15;
  1052. adpt->tx_q.produce_mask = NTPD_PROD_IDX_BMSK;
  1053. adpt->tx_q.produce_shift = NTPD_PROD_IDX_SHFT;
  1054. adpt->tx_q.consume_reg = EMAC_MAILBOX_2;
  1055. adpt->tx_q.consume_mask = NTPD_CONS_IDX_BMSK;
  1056. adpt->tx_q.consume_shift = NTPD_CONS_IDX_SHFT;
  1057. }
  1058. /* Fill up transmit descriptors with TSO and Checksum offload information */
  1059. static int emac_tso_csum(struct emac_adapter *adpt,
  1060. struct emac_tx_queue *tx_q,
  1061. struct sk_buff *skb,
  1062. struct emac_tpd *tpd)
  1063. {
  1064. unsigned int hdr_len;
  1065. int ret;
  1066. if (skb_is_gso(skb)) {
  1067. if (skb_header_cloned(skb)) {
  1068. ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  1069. if (unlikely(ret))
  1070. return ret;
  1071. }
  1072. if (skb->protocol == htons(ETH_P_IP)) {
  1073. u32 pkt_len = ((unsigned char *)ip_hdr(skb) - skb->data)
  1074. + ntohs(ip_hdr(skb)->tot_len);
  1075. if (skb->len > pkt_len)
  1076. pskb_trim(skb, pkt_len);
  1077. }
  1078. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  1079. if (unlikely(skb->len == hdr_len)) {
  1080. /* we only need to do csum */
  1081. netif_warn(adpt, tx_err, adpt->netdev,
  1082. "tso not needed for packet with 0 data\n");
  1083. goto do_csum;
  1084. }
  1085. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) {
  1086. ip_hdr(skb)->check = 0;
  1087. tcp_hdr(skb)->check =
  1088. ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  1089. ip_hdr(skb)->daddr,
  1090. 0, IPPROTO_TCP, 0);
  1091. TPD_IPV4_SET(tpd, 1);
  1092. }
  1093. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  1094. /* ipv6 tso need an extra tpd */
  1095. struct emac_tpd extra_tpd;
  1096. memset(tpd, 0, sizeof(*tpd));
  1097. memset(&extra_tpd, 0, sizeof(extra_tpd));
  1098. ipv6_hdr(skb)->payload_len = 0;
  1099. tcp_hdr(skb)->check =
  1100. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  1101. &ipv6_hdr(skb)->daddr,
  1102. 0, IPPROTO_TCP, 0);
  1103. TPD_PKT_LEN_SET(&extra_tpd, skb->len);
  1104. TPD_LSO_SET(&extra_tpd, 1);
  1105. TPD_LSOV_SET(&extra_tpd, 1);
  1106. emac_tx_tpd_create(adpt, tx_q, &extra_tpd);
  1107. TPD_LSOV_SET(tpd, 1);
  1108. }
  1109. TPD_LSO_SET(tpd, 1);
  1110. TPD_TCPHDR_OFFSET_SET(tpd, skb_transport_offset(skb));
  1111. TPD_MSS_SET(tpd, skb_shinfo(skb)->gso_size);
  1112. return 0;
  1113. }
  1114. do_csum:
  1115. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  1116. unsigned int css, cso;
  1117. cso = skb_transport_offset(skb);
  1118. if (unlikely(cso & 0x1)) {
  1119. netdev_err(adpt->netdev,
  1120. "error: payload offset should be even\n");
  1121. return -EINVAL;
  1122. }
  1123. css = cso + skb->csum_offset;
  1124. TPD_PAYLOAD_OFFSET_SET(tpd, cso >> 1);
  1125. TPD_CXSUM_OFFSET_SET(tpd, css >> 1);
  1126. TPD_CSX_SET(tpd, 1);
  1127. }
  1128. return 0;
  1129. }
  1130. /* Fill up transmit descriptors */
  1131. static void emac_tx_fill_tpd(struct emac_adapter *adpt,
  1132. struct emac_tx_queue *tx_q, struct sk_buff *skb,
  1133. struct emac_tpd *tpd)
  1134. {
  1135. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  1136. unsigned int first = tx_q->tpd.produce_idx;
  1137. unsigned int len = skb_headlen(skb);
  1138. struct emac_buffer *tpbuf = NULL;
  1139. unsigned int mapped_len = 0;
  1140. unsigned int i;
  1141. int count = 0;
  1142. int ret;
  1143. /* if Large Segment Offload is (in TCP Segmentation Offload struct) */
  1144. if (TPD_LSO(tpd)) {
  1145. mapped_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  1146. tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
  1147. tpbuf->length = mapped_len;
  1148. tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
  1149. virt_to_page(skb->data),
  1150. offset_in_page(skb->data),
  1151. tpbuf->length,
  1152. DMA_TO_DEVICE);
  1153. ret = dma_mapping_error(adpt->netdev->dev.parent,
  1154. tpbuf->dma_addr);
  1155. if (ret)
  1156. goto error;
  1157. TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
  1158. TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
  1159. TPD_BUF_LEN_SET(tpd, tpbuf->length);
  1160. emac_tx_tpd_create(adpt, tx_q, tpd);
  1161. count++;
  1162. }
  1163. if (mapped_len < len) {
  1164. tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
  1165. tpbuf->length = len - mapped_len;
  1166. tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
  1167. virt_to_page(skb->data +
  1168. mapped_len),
  1169. offset_in_page(skb->data +
  1170. mapped_len),
  1171. tpbuf->length, DMA_TO_DEVICE);
  1172. ret = dma_mapping_error(adpt->netdev->dev.parent,
  1173. tpbuf->dma_addr);
  1174. if (ret)
  1175. goto error;
  1176. TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
  1177. TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
  1178. TPD_BUF_LEN_SET(tpd, tpbuf->length);
  1179. emac_tx_tpd_create(adpt, tx_q, tpd);
  1180. count++;
  1181. }
  1182. for (i = 0; i < nr_frags; i++) {
  1183. struct skb_frag_struct *frag;
  1184. frag = &skb_shinfo(skb)->frags[i];
  1185. tpbuf = GET_TPD_BUFFER(tx_q, tx_q->tpd.produce_idx);
  1186. tpbuf->length = frag->size;
  1187. tpbuf->dma_addr = dma_map_page(adpt->netdev->dev.parent,
  1188. frag->page.p, frag->page_offset,
  1189. tpbuf->length, DMA_TO_DEVICE);
  1190. ret = dma_mapping_error(adpt->netdev->dev.parent,
  1191. tpbuf->dma_addr);
  1192. if (ret)
  1193. goto error;
  1194. TPD_BUFFER_ADDR_L_SET(tpd, lower_32_bits(tpbuf->dma_addr));
  1195. TPD_BUFFER_ADDR_H_SET(tpd, upper_32_bits(tpbuf->dma_addr));
  1196. TPD_BUF_LEN_SET(tpd, tpbuf->length);
  1197. emac_tx_tpd_create(adpt, tx_q, tpd);
  1198. count++;
  1199. }
  1200. /* The last tpd */
  1201. wmb();
  1202. emac_tx_tpd_mark_last(adpt, tx_q);
  1203. /* The last buffer info contain the skb address,
  1204. * so it will be freed after unmap
  1205. */
  1206. tpbuf->skb = skb;
  1207. return;
  1208. error:
  1209. /* One of the memory mappings failed, so undo everything */
  1210. tx_q->tpd.produce_idx = first;
  1211. while (count--) {
  1212. tpbuf = GET_TPD_BUFFER(tx_q, first);
  1213. dma_unmap_page(adpt->netdev->dev.parent, tpbuf->dma_addr,
  1214. tpbuf->length, DMA_TO_DEVICE);
  1215. tpbuf->dma_addr = 0;
  1216. tpbuf->length = 0;
  1217. if (++first == tx_q->tpd.count)
  1218. first = 0;
  1219. }
  1220. dev_kfree_skb(skb);
  1221. }
  1222. /* Transmit the packet using specified transmit queue */
  1223. int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q,
  1224. struct sk_buff *skb)
  1225. {
  1226. struct emac_tpd tpd;
  1227. u32 prod_idx;
  1228. memset(&tpd, 0, sizeof(tpd));
  1229. if (emac_tso_csum(adpt, tx_q, skb, &tpd) != 0) {
  1230. dev_kfree_skb_any(skb);
  1231. return NETDEV_TX_OK;
  1232. }
  1233. if (skb_vlan_tag_present(skb)) {
  1234. u16 tag;
  1235. EMAC_VLAN_TO_TAG(skb_vlan_tag_get(skb), tag);
  1236. TPD_CVLAN_TAG_SET(&tpd, tag);
  1237. TPD_INSTC_SET(&tpd, 1);
  1238. }
  1239. if (skb_network_offset(skb) != ETH_HLEN)
  1240. TPD_TYP_SET(&tpd, 1);
  1241. emac_tx_fill_tpd(adpt, tx_q, skb, &tpd);
  1242. netdev_sent_queue(adpt->netdev, skb->len);
  1243. /* Make sure the are enough free descriptors to hold one
  1244. * maximum-sized SKB. We need one desc for each fragment,
  1245. * one for the checksum (emac_tso_csum), one for TSO, and
  1246. * and one for the SKB header.
  1247. */
  1248. if (emac_tpd_num_free_descs(tx_q) < (MAX_SKB_FRAGS + 3))
  1249. netif_stop_queue(adpt->netdev);
  1250. /* update produce idx */
  1251. prod_idx = (tx_q->tpd.produce_idx << tx_q->produce_shift) &
  1252. tx_q->produce_mask;
  1253. emac_reg_update32(adpt->base + tx_q->produce_reg,
  1254. tx_q->produce_mask, prod_idx);
  1255. return NETDEV_TX_OK;
  1256. }