xgbe.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * AMD 10Gb Ethernet driver
  3. *
  4. * This file is available to you under your choice of the following two
  5. * licenses:
  6. *
  7. * License 1: GPLv2
  8. *
  9. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  10. *
  11. * This file is free software; you may copy, redistribute and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * This file incorporates work covered by the following copyright and
  25. * permission notice:
  26. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  27. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  28. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  29. * and you.
  30. *
  31. * The Software IS NOT an item of Licensed Software or Licensed Product
  32. * under any End User Software License Agreement or Agreement for Licensed
  33. * Product with Synopsys or any supplement thereto. Permission is hereby
  34. * granted, free of charge, to any person obtaining a copy of this software
  35. * annotated with this license and the Software, to deal in the Software
  36. * without restriction, including without limitation the rights to use,
  37. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  38. * of the Software, and to permit persons to whom the Software is furnished
  39. * to do so, subject to the following conditions:
  40. *
  41. * The above copyright notice and this permission notice shall be included
  42. * in all copies or substantial portions of the Software.
  43. *
  44. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  47. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  48. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  50. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  51. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  53. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  54. * THE POSSIBILITY OF SUCH DAMAGE.
  55. *
  56. *
  57. * License 2: Modified BSD
  58. *
  59. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  60. * All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions are met:
  64. * * Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. * * Redistributions in binary form must reproduce the above copyright
  67. * notice, this list of conditions and the following disclaimer in the
  68. * documentation and/or other materials provided with the distribution.
  69. * * Neither the name of Advanced Micro Devices, Inc. nor the
  70. * names of its contributors may be used to endorse or promote products
  71. * derived from this software without specific prior written permission.
  72. *
  73. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  74. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76. * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  77. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  80. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  81. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  82. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83. *
  84. * This file incorporates work covered by the following copyright and
  85. * permission notice:
  86. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  87. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  88. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  89. * and you.
  90. *
  91. * The Software IS NOT an item of Licensed Software or Licensed Product
  92. * under any End User Software License Agreement or Agreement for Licensed
  93. * Product with Synopsys or any supplement thereto. Permission is hereby
  94. * granted, free of charge, to any person obtaining a copy of this software
  95. * annotated with this license and the Software, to deal in the Software
  96. * without restriction, including without limitation the rights to use,
  97. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  98. * of the Software, and to permit persons to whom the Software is furnished
  99. * to do so, subject to the following conditions:
  100. *
  101. * The above copyright notice and this permission notice shall be included
  102. * in all copies or substantial portions of the Software.
  103. *
  104. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  105. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  106. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  107. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  108. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  109. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  110. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  111. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  112. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  113. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  114. * THE POSSIBILITY OF SUCH DAMAGE.
  115. */
  116. #ifndef __XGBE_H__
  117. #define __XGBE_H__
  118. #include <linux/dma-mapping.h>
  119. #include <linux/netdevice.h>
  120. #include <linux/workqueue.h>
  121. #include <linux/phy.h>
  122. #include <linux/if_vlan.h>
  123. #include <linux/bitops.h>
  124. #include <linux/ptp_clock_kernel.h>
  125. #include <linux/timecounter.h>
  126. #include <linux/net_tstamp.h>
  127. #include <net/dcbnl.h>
  128. #define XGBE_DRV_NAME "amd-xgbe"
  129. #define XGBE_DRV_VERSION "1.0.2"
  130. #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
  131. /* Descriptor related defines */
  132. #define XGBE_TX_DESC_CNT 512
  133. #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
  134. #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
  135. #define XGBE_RX_DESC_CNT 512
  136. #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  137. /* Descriptors required for maximum contiguous TSO/GSO packet */
  138. #define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
  139. /* Maximum possible descriptors needed for an SKB:
  140. * - Maximum number of SKB frags
  141. * - Maximum descriptors for contiguous TSO/GSO packet
  142. * - Possible context descriptor
  143. * - Possible TSO header descriptor
  144. */
  145. #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
  146. #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  147. #define XGBE_RX_BUF_ALIGN 64
  148. #define XGBE_SKB_ALLOC_SIZE 256
  149. #define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
  150. #define XGBE_MAX_DMA_CHANNELS 16
  151. #define XGBE_MAX_QUEUES 16
  152. #define XGBE_DMA_STOP_TIMEOUT 5
  153. /* DMA cache settings - Outer sharable, write-back, write-allocate */
  154. #define XGBE_DMA_OS_AXDOMAIN 0x2
  155. #define XGBE_DMA_OS_ARCACHE 0xb
  156. #define XGBE_DMA_OS_AWCACHE 0xf
  157. /* DMA cache settings - System, no caches used */
  158. #define XGBE_DMA_SYS_AXDOMAIN 0x3
  159. #define XGBE_DMA_SYS_ARCACHE 0x0
  160. #define XGBE_DMA_SYS_AWCACHE 0x0
  161. #define XGBE_DMA_INTERRUPT_MASK 0x31c7
  162. #define XGMAC_MIN_PACKET 60
  163. #define XGMAC_STD_PACKET_MTU 1500
  164. #define XGMAC_MAX_STD_PACKET 1518
  165. #define XGMAC_JUMBO_PACKET_MTU 9000
  166. #define XGMAC_MAX_JUMBO_PACKET 9018
  167. /* Common property names */
  168. #define XGBE_MAC_ADDR_PROPERTY "mac-address"
  169. #define XGBE_PHY_MODE_PROPERTY "phy-mode"
  170. #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
  171. #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
  172. #define XGBE_BLWC_PROPERTY "amd,serdes-blwc"
  173. #define XGBE_CDR_RATE_PROPERTY "amd,serdes-cdr-rate"
  174. #define XGBE_PQ_SKEW_PROPERTY "amd,serdes-pq-skew"
  175. #define XGBE_TX_AMP_PROPERTY "amd,serdes-tx-amp"
  176. #define XGBE_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config"
  177. #define XGBE_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable"
  178. /* Device-tree clock names */
  179. #define XGBE_DMA_CLOCK "dma_clk"
  180. #define XGBE_PTP_CLOCK "ptp_clk"
  181. /* ACPI property names */
  182. #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
  183. #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
  184. /* Timestamp support - values based on 50MHz PTP clock
  185. * 50MHz => 20 nsec
  186. */
  187. #define XGBE_TSTAMP_SSINC 20
  188. #define XGBE_TSTAMP_SNSINC 0
  189. /* Driver PMT macros */
  190. #define XGMAC_DRIVER_CONTEXT 1
  191. #define XGMAC_IOCTL_CONTEXT 2
  192. #define XGBE_FIFO_MAX 81920
  193. #define XGBE_FIFO_SIZE_B(x) (x)
  194. #define XGBE_FIFO_SIZE_KB(x) (x * 1024)
  195. #define XGBE_TC_MIN_QUANTUM 10
  196. /* Helper macro for descriptor handling
  197. * Always use XGBE_GET_DESC_DATA to access the descriptor data
  198. * since the index is free-running and needs to be and-ed
  199. * with the descriptor count value of the ring to index to
  200. * the proper descriptor data.
  201. */
  202. #define XGBE_GET_DESC_DATA(_ring, _idx) \
  203. ((_ring)->rdata + \
  204. ((_idx) & ((_ring)->rdesc_count - 1)))
  205. /* Default coalescing parameters */
  206. #define XGMAC_INIT_DMA_TX_USECS 1000
  207. #define XGMAC_INIT_DMA_TX_FRAMES 25
  208. #define XGMAC_MAX_DMA_RIWT 0xff
  209. #define XGMAC_INIT_DMA_RX_USECS 30
  210. #define XGMAC_INIT_DMA_RX_FRAMES 25
  211. /* Flow control queue count */
  212. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  213. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  214. #define XGBE_MAC_HASH_TABLE_SIZE 8
  215. /* Receive Side Scaling */
  216. #define XGBE_RSS_HASH_KEY_SIZE 40
  217. #define XGBE_RSS_MAX_TABLE_SIZE 256
  218. #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
  219. #define XGBE_RSS_HASH_KEY_TYPE 1
  220. /* Auto-negotiation */
  221. #define XGBE_AN_MS_TIMEOUT 500
  222. #define XGBE_LINK_TIMEOUT 10
  223. #define XGBE_AN_INT_CMPLT 0x01
  224. #define XGBE_AN_INC_LINK 0x02
  225. #define XGBE_AN_PG_RCV 0x04
  226. #define XGBE_AN_INT_MASK 0x07
  227. /* Rate-change complete wait/retry count */
  228. #define XGBE_RATECHANGE_COUNT 500
  229. /* Default SerDes settings */
  230. #define XGBE_SPEED_10000_BLWC 0
  231. #define XGBE_SPEED_10000_CDR 0x7
  232. #define XGBE_SPEED_10000_PLL 0x1
  233. #define XGBE_SPEED_10000_PQ 0x12
  234. #define XGBE_SPEED_10000_RATE 0x0
  235. #define XGBE_SPEED_10000_TXAMP 0xa
  236. #define XGBE_SPEED_10000_WORD 0x7
  237. #define XGBE_SPEED_10000_DFE_TAP_CONFIG 0x1
  238. #define XGBE_SPEED_10000_DFE_TAP_ENABLE 0x7f
  239. #define XGBE_SPEED_2500_BLWC 1
  240. #define XGBE_SPEED_2500_CDR 0x2
  241. #define XGBE_SPEED_2500_PLL 0x0
  242. #define XGBE_SPEED_2500_PQ 0xa
  243. #define XGBE_SPEED_2500_RATE 0x1
  244. #define XGBE_SPEED_2500_TXAMP 0xf
  245. #define XGBE_SPEED_2500_WORD 0x1
  246. #define XGBE_SPEED_2500_DFE_TAP_CONFIG 0x3
  247. #define XGBE_SPEED_2500_DFE_TAP_ENABLE 0x0
  248. #define XGBE_SPEED_1000_BLWC 1
  249. #define XGBE_SPEED_1000_CDR 0x2
  250. #define XGBE_SPEED_1000_PLL 0x0
  251. #define XGBE_SPEED_1000_PQ 0xa
  252. #define XGBE_SPEED_1000_RATE 0x3
  253. #define XGBE_SPEED_1000_TXAMP 0xf
  254. #define XGBE_SPEED_1000_WORD 0x1
  255. #define XGBE_SPEED_1000_DFE_TAP_CONFIG 0x3
  256. #define XGBE_SPEED_1000_DFE_TAP_ENABLE 0x0
  257. struct xgbe_prv_data;
  258. struct xgbe_packet_data {
  259. struct sk_buff *skb;
  260. unsigned int attributes;
  261. unsigned int errors;
  262. unsigned int rdesc_count;
  263. unsigned int length;
  264. unsigned int header_len;
  265. unsigned int tcp_header_len;
  266. unsigned int tcp_payload_len;
  267. unsigned short mss;
  268. unsigned short vlan_ctag;
  269. u64 rx_tstamp;
  270. u32 rss_hash;
  271. enum pkt_hash_types rss_hash_type;
  272. unsigned int tx_packets;
  273. unsigned int tx_bytes;
  274. };
  275. /* Common Rx and Tx descriptor mapping */
  276. struct xgbe_ring_desc {
  277. __le32 desc0;
  278. __le32 desc1;
  279. __le32 desc2;
  280. __le32 desc3;
  281. };
  282. /* Page allocation related values */
  283. struct xgbe_page_alloc {
  284. struct page *pages;
  285. unsigned int pages_len;
  286. unsigned int pages_offset;
  287. dma_addr_t pages_dma;
  288. };
  289. /* Ring entry buffer data */
  290. struct xgbe_buffer_data {
  291. struct xgbe_page_alloc pa;
  292. struct xgbe_page_alloc pa_unmap;
  293. dma_addr_t dma_base;
  294. unsigned long dma_off;
  295. unsigned int dma_len;
  296. };
  297. /* Tx-related ring data */
  298. struct xgbe_tx_ring_data {
  299. unsigned int packets; /* BQL packet count */
  300. unsigned int bytes; /* BQL byte count */
  301. };
  302. /* Rx-related ring data */
  303. struct xgbe_rx_ring_data {
  304. struct xgbe_buffer_data hdr; /* Header locations */
  305. struct xgbe_buffer_data buf; /* Payload locations */
  306. unsigned short hdr_len; /* Length of received header */
  307. unsigned short len; /* Length of received packet */
  308. };
  309. /* Structure used to hold information related to the descriptor
  310. * and the packet associated with the descriptor (always use
  311. * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
  312. */
  313. struct xgbe_ring_data {
  314. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  315. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  316. struct sk_buff *skb; /* Virtual address of SKB */
  317. dma_addr_t skb_dma; /* DMA address of SKB data */
  318. unsigned int skb_dma_len; /* Length of SKB DMA area */
  319. struct xgbe_tx_ring_data tx; /* Tx-related data */
  320. struct xgbe_rx_ring_data rx; /* Rx-related data */
  321. unsigned int mapped_as_page;
  322. /* Incomplete receive save location. If the budget is exhausted
  323. * or the last descriptor (last normal descriptor or a following
  324. * context descriptor) has not been DMA'd yet the current state
  325. * of the receive processing needs to be saved.
  326. */
  327. unsigned int state_saved;
  328. struct {
  329. struct sk_buff *skb;
  330. unsigned int len;
  331. unsigned int error;
  332. } state;
  333. };
  334. struct xgbe_ring {
  335. /* Ring lock - used just for TX rings at the moment */
  336. spinlock_t lock;
  337. /* Per packet related information */
  338. struct xgbe_packet_data packet_data;
  339. /* Virtual/DMA addresses and count of allocated descriptor memory */
  340. struct xgbe_ring_desc *rdesc;
  341. dma_addr_t rdesc_dma;
  342. unsigned int rdesc_count;
  343. /* Array of descriptor data corresponding the descriptor memory
  344. * (always use the XGBE_GET_DESC_DATA macro to access this data)
  345. */
  346. struct xgbe_ring_data *rdata;
  347. /* Page allocation for RX buffers */
  348. struct xgbe_page_alloc rx_hdr_pa;
  349. struct xgbe_page_alloc rx_buf_pa;
  350. /* Ring index values
  351. * cur - Tx: index of descriptor to be used for current transfer
  352. * Rx: index of descriptor to check for packet availability
  353. * dirty - Tx: index of descriptor to check for transfer complete
  354. * Rx: index of descriptor to check for buffer reallocation
  355. */
  356. unsigned int cur;
  357. unsigned int dirty;
  358. /* Coalesce frame count used for interrupt bit setting */
  359. unsigned int coalesce_count;
  360. union {
  361. struct {
  362. unsigned int queue_stopped;
  363. unsigned int xmit_more;
  364. unsigned short cur_mss;
  365. unsigned short cur_vlan_ctag;
  366. } tx;
  367. };
  368. } ____cacheline_aligned;
  369. /* Structure used to describe the descriptor rings associated with
  370. * a DMA channel.
  371. */
  372. struct xgbe_channel {
  373. char name[16];
  374. /* Address of private data area for device */
  375. struct xgbe_prv_data *pdata;
  376. /* Queue index and base address of queue's DMA registers */
  377. unsigned int queue_index;
  378. void __iomem *dma_regs;
  379. /* Per channel interrupt irq number */
  380. int dma_irq;
  381. char dma_irq_name[IFNAMSIZ + 32];
  382. /* Netdev related settings */
  383. struct napi_struct napi;
  384. unsigned int saved_ier;
  385. unsigned int tx_timer_active;
  386. struct timer_list tx_timer;
  387. struct xgbe_ring *tx_ring;
  388. struct xgbe_ring *rx_ring;
  389. } ____cacheline_aligned;
  390. enum xgbe_state {
  391. XGBE_DOWN,
  392. XGBE_LINK,
  393. XGBE_LINK_INIT,
  394. XGBE_LINK_ERR,
  395. };
  396. enum xgbe_int {
  397. XGMAC_INT_DMA_CH_SR_TI,
  398. XGMAC_INT_DMA_CH_SR_TPS,
  399. XGMAC_INT_DMA_CH_SR_TBU,
  400. XGMAC_INT_DMA_CH_SR_RI,
  401. XGMAC_INT_DMA_CH_SR_RBU,
  402. XGMAC_INT_DMA_CH_SR_RPS,
  403. XGMAC_INT_DMA_CH_SR_TI_RI,
  404. XGMAC_INT_DMA_CH_SR_FBE,
  405. XGMAC_INT_DMA_ALL,
  406. };
  407. enum xgbe_int_state {
  408. XGMAC_INT_STATE_SAVE,
  409. XGMAC_INT_STATE_RESTORE,
  410. };
  411. enum xgbe_mtl_fifo_size {
  412. XGMAC_MTL_FIFO_SIZE_256 = 0x00,
  413. XGMAC_MTL_FIFO_SIZE_512 = 0x01,
  414. XGMAC_MTL_FIFO_SIZE_1K = 0x03,
  415. XGMAC_MTL_FIFO_SIZE_2K = 0x07,
  416. XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
  417. XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
  418. XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
  419. XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
  420. XGMAC_MTL_FIFO_SIZE_64K = 0xff,
  421. XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
  422. XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
  423. };
  424. enum xgbe_speed {
  425. XGBE_SPEED_1000 = 0,
  426. XGBE_SPEED_2500,
  427. XGBE_SPEED_10000,
  428. XGBE_SPEEDS,
  429. };
  430. enum xgbe_an {
  431. XGBE_AN_READY = 0,
  432. XGBE_AN_PAGE_RECEIVED,
  433. XGBE_AN_INCOMPAT_LINK,
  434. XGBE_AN_COMPLETE,
  435. XGBE_AN_NO_LINK,
  436. XGBE_AN_ERROR,
  437. };
  438. enum xgbe_rx {
  439. XGBE_RX_BPA = 0,
  440. XGBE_RX_XNP,
  441. XGBE_RX_COMPLETE,
  442. XGBE_RX_ERROR,
  443. };
  444. enum xgbe_mode {
  445. XGBE_MODE_KR = 0,
  446. XGBE_MODE_KX,
  447. };
  448. enum xgbe_speedset {
  449. XGBE_SPEEDSET_1000_10000 = 0,
  450. XGBE_SPEEDSET_2500_10000,
  451. };
  452. struct xgbe_phy {
  453. u32 supported;
  454. u32 advertising;
  455. u32 lp_advertising;
  456. int address;
  457. int autoneg;
  458. int speed;
  459. int duplex;
  460. int link;
  461. int pause_autoneg;
  462. int tx_pause;
  463. int rx_pause;
  464. };
  465. struct xgbe_mmc_stats {
  466. /* Tx Stats */
  467. u64 txoctetcount_gb;
  468. u64 txframecount_gb;
  469. u64 txbroadcastframes_g;
  470. u64 txmulticastframes_g;
  471. u64 tx64octets_gb;
  472. u64 tx65to127octets_gb;
  473. u64 tx128to255octets_gb;
  474. u64 tx256to511octets_gb;
  475. u64 tx512to1023octets_gb;
  476. u64 tx1024tomaxoctets_gb;
  477. u64 txunicastframes_gb;
  478. u64 txmulticastframes_gb;
  479. u64 txbroadcastframes_gb;
  480. u64 txunderflowerror;
  481. u64 txoctetcount_g;
  482. u64 txframecount_g;
  483. u64 txpauseframes;
  484. u64 txvlanframes_g;
  485. /* Rx Stats */
  486. u64 rxframecount_gb;
  487. u64 rxoctetcount_gb;
  488. u64 rxoctetcount_g;
  489. u64 rxbroadcastframes_g;
  490. u64 rxmulticastframes_g;
  491. u64 rxcrcerror;
  492. u64 rxrunterror;
  493. u64 rxjabbererror;
  494. u64 rxundersize_g;
  495. u64 rxoversize_g;
  496. u64 rx64octets_gb;
  497. u64 rx65to127octets_gb;
  498. u64 rx128to255octets_gb;
  499. u64 rx256to511octets_gb;
  500. u64 rx512to1023octets_gb;
  501. u64 rx1024tomaxoctets_gb;
  502. u64 rxunicastframes_g;
  503. u64 rxlengtherror;
  504. u64 rxoutofrangetype;
  505. u64 rxpauseframes;
  506. u64 rxfifooverflow;
  507. u64 rxvlanframes_gb;
  508. u64 rxwatchdogerror;
  509. };
  510. struct xgbe_ext_stats {
  511. u64 tx_tso_packets;
  512. u64 rx_split_header_packets;
  513. };
  514. struct xgbe_hw_if {
  515. int (*tx_complete)(struct xgbe_ring_desc *);
  516. int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
  517. int (*config_rx_mode)(struct xgbe_prv_data *);
  518. int (*enable_rx_csum)(struct xgbe_prv_data *);
  519. int (*disable_rx_csum)(struct xgbe_prv_data *);
  520. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  521. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  522. int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
  523. int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
  524. int (*update_vlan_hash_table)(struct xgbe_prv_data *);
  525. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  526. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  527. int (*set_gmii_speed)(struct xgbe_prv_data *);
  528. int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
  529. int (*set_xgmii_speed)(struct xgbe_prv_data *);
  530. void (*enable_tx)(struct xgbe_prv_data *);
  531. void (*disable_tx)(struct xgbe_prv_data *);
  532. void (*enable_rx)(struct xgbe_prv_data *);
  533. void (*disable_rx)(struct xgbe_prv_data *);
  534. void (*powerup_tx)(struct xgbe_prv_data *);
  535. void (*powerdown_tx)(struct xgbe_prv_data *);
  536. void (*powerup_rx)(struct xgbe_prv_data *);
  537. void (*powerdown_rx)(struct xgbe_prv_data *);
  538. int (*init)(struct xgbe_prv_data *);
  539. int (*exit)(struct xgbe_prv_data *);
  540. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  541. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  542. void (*dev_xmit)(struct xgbe_channel *);
  543. int (*dev_read)(struct xgbe_channel *);
  544. void (*tx_desc_init)(struct xgbe_channel *);
  545. void (*rx_desc_init)(struct xgbe_channel *);
  546. void (*tx_desc_reset)(struct xgbe_ring_data *);
  547. void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
  548. unsigned int);
  549. int (*is_last_desc)(struct xgbe_ring_desc *);
  550. int (*is_context_desc)(struct xgbe_ring_desc *);
  551. void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
  552. /* For FLOW ctrl */
  553. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  554. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  555. /* For RX coalescing */
  556. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  557. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  558. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  559. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  560. /* For RX and TX threshold config */
  561. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  562. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  563. /* For RX and TX Store and Forward Mode config */
  564. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  565. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  566. /* For TX DMA Operate on Second Frame config */
  567. int (*config_osp_mode)(struct xgbe_prv_data *);
  568. /* For RX and TX PBL config */
  569. int (*config_rx_pbl_val)(struct xgbe_prv_data *);
  570. int (*get_rx_pbl_val)(struct xgbe_prv_data *);
  571. int (*config_tx_pbl_val)(struct xgbe_prv_data *);
  572. int (*get_tx_pbl_val)(struct xgbe_prv_data *);
  573. int (*config_pblx8)(struct xgbe_prv_data *);
  574. /* For MMC statistics */
  575. void (*rx_mmc_int)(struct xgbe_prv_data *);
  576. void (*tx_mmc_int)(struct xgbe_prv_data *);
  577. void (*read_mmc_stats)(struct xgbe_prv_data *);
  578. /* For Timestamp config */
  579. int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
  580. void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
  581. void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
  582. unsigned int nsec);
  583. u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  584. u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
  585. /* For Data Center Bridging config */
  586. void (*config_dcb_tc)(struct xgbe_prv_data *);
  587. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  588. /* For Receive Side Scaling */
  589. int (*enable_rss)(struct xgbe_prv_data *);
  590. int (*disable_rss)(struct xgbe_prv_data *);
  591. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  592. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  593. };
  594. struct xgbe_phy_if {
  595. /* For initial PHY setup */
  596. void (*phy_init)(struct xgbe_prv_data *);
  597. /* For PHY support when setting device up/down */
  598. int (*phy_reset)(struct xgbe_prv_data *);
  599. int (*phy_start)(struct xgbe_prv_data *);
  600. void (*phy_stop)(struct xgbe_prv_data *);
  601. /* For PHY support while device is up */
  602. void (*phy_status)(struct xgbe_prv_data *);
  603. int (*phy_config_aneg)(struct xgbe_prv_data *);
  604. };
  605. struct xgbe_desc_if {
  606. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  607. void (*free_ring_resources)(struct xgbe_prv_data *);
  608. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  609. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  610. struct xgbe_ring_data *);
  611. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  612. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  613. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  614. };
  615. /* This structure contains flags that indicate what hardware features
  616. * or configurations are present in the device.
  617. */
  618. struct xgbe_hw_features {
  619. /* HW Version */
  620. unsigned int version;
  621. /* HW Feature Register0 */
  622. unsigned int gmii; /* 1000 Mbps support */
  623. unsigned int vlhash; /* VLAN Hash Filter */
  624. unsigned int sma; /* SMA(MDIO) Interface */
  625. unsigned int rwk; /* PMT remote wake-up packet */
  626. unsigned int mgk; /* PMT magic packet */
  627. unsigned int mmc; /* RMON module */
  628. unsigned int aoe; /* ARP Offload */
  629. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  630. unsigned int eee; /* Energy Efficient Ethernet */
  631. unsigned int tx_coe; /* Tx Checksum Offload */
  632. unsigned int rx_coe; /* Rx Checksum Offload */
  633. unsigned int addn_mac; /* Additional MAC Addresses */
  634. unsigned int ts_src; /* Timestamp Source */
  635. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  636. /* HW Feature Register1 */
  637. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  638. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  639. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  640. unsigned int dma_width; /* DMA width */
  641. unsigned int dcb; /* DCB Feature */
  642. unsigned int sph; /* Split Header Feature */
  643. unsigned int tso; /* TCP Segmentation Offload */
  644. unsigned int dma_debug; /* DMA Debug Registers */
  645. unsigned int rss; /* Receive Side Scaling */
  646. unsigned int tc_cnt; /* Number of Traffic Classes */
  647. unsigned int hash_table_size; /* Hash Table Size */
  648. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  649. /* HW Feature Register2 */
  650. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  651. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  652. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  653. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  654. unsigned int pps_out_num; /* Number of PPS outputs */
  655. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  656. };
  657. struct xgbe_prv_data {
  658. struct net_device *netdev;
  659. struct platform_device *pdev;
  660. struct acpi_device *adev;
  661. struct device *dev;
  662. /* ACPI or DT flag */
  663. unsigned int use_acpi;
  664. /* XGMAC/XPCS related mmio registers */
  665. void __iomem *xgmac_regs; /* XGMAC CSRs */
  666. void __iomem *xpcs_regs; /* XPCS MMD registers */
  667. void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
  668. void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
  669. void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
  670. /* Overall device lock */
  671. spinlock_t lock;
  672. /* XPCS indirect addressing mutex */
  673. struct mutex xpcs_mutex;
  674. /* RSS addressing mutex */
  675. struct mutex rss_mutex;
  676. /* Flags representing xgbe_state */
  677. unsigned long dev_state;
  678. int dev_irq;
  679. unsigned int per_channel_irq;
  680. struct xgbe_hw_if hw_if;
  681. struct xgbe_phy_if phy_if;
  682. struct xgbe_desc_if desc_if;
  683. /* AXI DMA settings */
  684. unsigned int coherent;
  685. unsigned int axdomain;
  686. unsigned int arcache;
  687. unsigned int awcache;
  688. /* Service routine support */
  689. struct workqueue_struct *dev_workqueue;
  690. struct work_struct service_work;
  691. struct timer_list service_timer;
  692. /* Rings for Tx/Rx on a DMA channel */
  693. struct xgbe_channel *channel;
  694. unsigned int channel_count;
  695. unsigned int tx_ring_count;
  696. unsigned int tx_desc_count;
  697. unsigned int rx_ring_count;
  698. unsigned int rx_desc_count;
  699. unsigned int tx_q_count;
  700. unsigned int rx_q_count;
  701. /* Tx/Rx common settings */
  702. unsigned int pblx8;
  703. /* Tx settings */
  704. unsigned int tx_sf_mode;
  705. unsigned int tx_threshold;
  706. unsigned int tx_pbl;
  707. unsigned int tx_osp_mode;
  708. /* Rx settings */
  709. unsigned int rx_sf_mode;
  710. unsigned int rx_threshold;
  711. unsigned int rx_pbl;
  712. /* Tx coalescing settings */
  713. unsigned int tx_usecs;
  714. unsigned int tx_frames;
  715. /* Rx coalescing settings */
  716. unsigned int rx_riwt;
  717. unsigned int rx_usecs;
  718. unsigned int rx_frames;
  719. /* Current Rx buffer size */
  720. unsigned int rx_buf_size;
  721. /* Flow control settings */
  722. unsigned int pause_autoneg;
  723. unsigned int tx_pause;
  724. unsigned int rx_pause;
  725. /* Receive Side Scaling settings */
  726. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  727. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  728. u32 rss_options;
  729. /* Netdev related settings */
  730. unsigned char mac_addr[ETH_ALEN];
  731. netdev_features_t netdev_features;
  732. struct napi_struct napi;
  733. struct xgbe_mmc_stats mmc_stats;
  734. struct xgbe_ext_stats ext_stats;
  735. /* Filtering support */
  736. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  737. /* Device clocks */
  738. struct clk *sysclk;
  739. unsigned long sysclk_rate;
  740. struct clk *ptpclk;
  741. unsigned long ptpclk_rate;
  742. /* Timestamp support */
  743. spinlock_t tstamp_lock;
  744. struct ptp_clock_info ptp_clock_info;
  745. struct ptp_clock *ptp_clock;
  746. struct hwtstamp_config tstamp_config;
  747. struct cyclecounter tstamp_cc;
  748. struct timecounter tstamp_tc;
  749. unsigned int tstamp_addend;
  750. struct work_struct tx_tstamp_work;
  751. struct sk_buff *tx_tstamp_skb;
  752. u64 tx_tstamp;
  753. /* DCB support */
  754. struct ieee_ets *ets;
  755. struct ieee_pfc *pfc;
  756. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  757. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  758. /* Hardware features of the device */
  759. struct xgbe_hw_features hw_feat;
  760. /* Device restart work structure */
  761. struct work_struct restart_work;
  762. /* Keeps track of power mode */
  763. unsigned int power_down;
  764. /* Network interface message level setting */
  765. u32 msg_enable;
  766. /* Current PHY settings */
  767. phy_interface_t phy_mode;
  768. int phy_link;
  769. int phy_speed;
  770. /* MDIO/PHY related settings */
  771. struct xgbe_phy phy;
  772. int mdio_mmd;
  773. unsigned long link_check;
  774. char an_name[IFNAMSIZ + 32];
  775. struct workqueue_struct *an_workqueue;
  776. int an_irq;
  777. struct work_struct an_irq_work;
  778. unsigned int speed_set;
  779. /* SerDes UEFI configurable settings.
  780. * Switching between modes/speeds requires new values for some
  781. * SerDes settings. The values can be supplied as device
  782. * properties in array format. The first array entry is for
  783. * 1GbE, second for 2.5GbE and third for 10GbE
  784. */
  785. u32 serdes_blwc[XGBE_SPEEDS];
  786. u32 serdes_cdr_rate[XGBE_SPEEDS];
  787. u32 serdes_pq_skew[XGBE_SPEEDS];
  788. u32 serdes_tx_amp[XGBE_SPEEDS];
  789. u32 serdes_dfe_tap_cfg[XGBE_SPEEDS];
  790. u32 serdes_dfe_tap_ena[XGBE_SPEEDS];
  791. /* Auto-negotiation state machine support */
  792. struct mutex an_mutex;
  793. enum xgbe_an an_result;
  794. enum xgbe_an an_state;
  795. enum xgbe_rx kr_state;
  796. enum xgbe_rx kx_state;
  797. struct work_struct an_work;
  798. unsigned int an_supported;
  799. unsigned int parallel_detect;
  800. unsigned int fec_ability;
  801. unsigned long an_start;
  802. unsigned int lpm_ctrl; /* CTRL1 for resume */
  803. #ifdef CONFIG_DEBUG_FS
  804. struct dentry *xgbe_debugfs;
  805. unsigned int debugfs_xgmac_reg;
  806. unsigned int debugfs_xpcs_mmd;
  807. unsigned int debugfs_xpcs_reg;
  808. #endif
  809. };
  810. /* Function prototypes*/
  811. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  812. void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
  813. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  814. struct net_device_ops *xgbe_get_netdev_ops(void);
  815. struct ethtool_ops *xgbe_get_ethtool_ops(void);
  816. #ifdef CONFIG_AMD_XGBE_DCB
  817. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  818. #endif
  819. void xgbe_ptp_register(struct xgbe_prv_data *);
  820. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  821. void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  822. unsigned int, unsigned int, unsigned int);
  823. void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  824. unsigned int);
  825. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  826. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  827. int xgbe_powerup(struct net_device *, unsigned int);
  828. int xgbe_powerdown(struct net_device *, unsigned int);
  829. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  830. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  831. #ifdef CONFIG_DEBUG_FS
  832. void xgbe_debugfs_init(struct xgbe_prv_data *);
  833. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  834. #else
  835. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  836. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  837. #endif /* CONFIG_DEBUG_FS */
  838. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  839. #if 0
  840. #define YDEBUG
  841. #define YDEBUG_MDIO
  842. #endif
  843. /* For debug prints */
  844. #ifdef YDEBUG
  845. #define DBGPR(x...) pr_alert(x)
  846. #else
  847. #define DBGPR(x...) do { } while (0)
  848. #endif
  849. #ifdef YDEBUG_MDIO
  850. #define DBGPR_MDIO(x...) pr_alert(x)
  851. #else
  852. #define DBGPR_MDIO(x...) do { } while (0)
  853. #endif
  854. #endif