xgbe.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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.0-a"
  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 contigous 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. /* MDIO bus phy name */
  168. #define XGBE_PHY_NAME "amd_xgbe_phy"
  169. #define XGBE_PRTAD 0
  170. /* Common property names */
  171. #define XGBE_MAC_ADDR_PROPERTY "mac-address"
  172. #define XGBE_PHY_MODE_PROPERTY "phy-mode"
  173. #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
  174. /* Device-tree clock names */
  175. #define XGBE_DMA_CLOCK "dma_clk"
  176. #define XGBE_PTP_CLOCK "ptp_clk"
  177. /* ACPI property names */
  178. #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
  179. #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
  180. /* Timestamp support - values based on 50MHz PTP clock
  181. * 50MHz => 20 nsec
  182. */
  183. #define XGBE_TSTAMP_SSINC 20
  184. #define XGBE_TSTAMP_SNSINC 0
  185. /* Driver PMT macros */
  186. #define XGMAC_DRIVER_CONTEXT 1
  187. #define XGMAC_IOCTL_CONTEXT 2
  188. #define XGBE_FIFO_MAX 81920
  189. #define XGBE_FIFO_SIZE_B(x) (x)
  190. #define XGBE_FIFO_SIZE_KB(x) (x * 1024)
  191. #define XGBE_TC_MIN_QUANTUM 10
  192. /* Helper macro for descriptor handling
  193. * Always use XGBE_GET_DESC_DATA to access the descriptor data
  194. * since the index is free-running and needs to be and-ed
  195. * with the descriptor count value of the ring to index to
  196. * the proper descriptor data.
  197. */
  198. #define XGBE_GET_DESC_DATA(_ring, _idx) \
  199. ((_ring)->rdata + \
  200. ((_idx) & ((_ring)->rdesc_count - 1)))
  201. /* Default coalescing parameters */
  202. #define XGMAC_INIT_DMA_TX_USECS 1000
  203. #define XGMAC_INIT_DMA_TX_FRAMES 25
  204. #define XGMAC_MAX_DMA_RIWT 0xff
  205. #define XGMAC_INIT_DMA_RX_USECS 30
  206. #define XGMAC_INIT_DMA_RX_FRAMES 25
  207. /* Flow control queue count */
  208. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  209. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  210. #define XGBE_MAC_HASH_TABLE_SIZE 8
  211. /* Receive Side Scaling */
  212. #define XGBE_RSS_HASH_KEY_SIZE 40
  213. #define XGBE_RSS_MAX_TABLE_SIZE 256
  214. #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
  215. #define XGBE_RSS_HASH_KEY_TYPE 1
  216. struct xgbe_prv_data;
  217. struct xgbe_packet_data {
  218. struct sk_buff *skb;
  219. unsigned int attributes;
  220. unsigned int errors;
  221. unsigned int rdesc_count;
  222. unsigned int length;
  223. unsigned int header_len;
  224. unsigned int tcp_header_len;
  225. unsigned int tcp_payload_len;
  226. unsigned short mss;
  227. unsigned short vlan_ctag;
  228. u64 rx_tstamp;
  229. u32 rss_hash;
  230. enum pkt_hash_types rss_hash_type;
  231. unsigned int tx_packets;
  232. unsigned int tx_bytes;
  233. };
  234. /* Common Rx and Tx descriptor mapping */
  235. struct xgbe_ring_desc {
  236. __le32 desc0;
  237. __le32 desc1;
  238. __le32 desc2;
  239. __le32 desc3;
  240. };
  241. /* Page allocation related values */
  242. struct xgbe_page_alloc {
  243. struct page *pages;
  244. unsigned int pages_len;
  245. unsigned int pages_offset;
  246. dma_addr_t pages_dma;
  247. };
  248. /* Ring entry buffer data */
  249. struct xgbe_buffer_data {
  250. struct xgbe_page_alloc pa;
  251. struct xgbe_page_alloc pa_unmap;
  252. dma_addr_t dma;
  253. unsigned int dma_len;
  254. };
  255. /* Tx-related ring data */
  256. struct xgbe_tx_ring_data {
  257. unsigned int packets; /* BQL packet count */
  258. unsigned int bytes; /* BQL byte count */
  259. };
  260. /* Rx-related ring data */
  261. struct xgbe_rx_ring_data {
  262. struct xgbe_buffer_data hdr; /* Header locations */
  263. struct xgbe_buffer_data buf; /* Payload locations */
  264. unsigned short hdr_len; /* Length of received header */
  265. unsigned short len; /* Length of received packet */
  266. };
  267. /* Structure used to hold information related to the descriptor
  268. * and the packet associated with the descriptor (always use
  269. * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
  270. */
  271. struct xgbe_ring_data {
  272. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  273. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  274. struct sk_buff *skb; /* Virtual address of SKB */
  275. dma_addr_t skb_dma; /* DMA address of SKB data */
  276. unsigned int skb_dma_len; /* Length of SKB DMA area */
  277. struct xgbe_tx_ring_data tx; /* Tx-related data */
  278. struct xgbe_rx_ring_data rx; /* Rx-related data */
  279. unsigned int mapped_as_page;
  280. /* Incomplete receive save location. If the budget is exhausted
  281. * or the last descriptor (last normal descriptor or a following
  282. * context descriptor) has not been DMA'd yet the current state
  283. * of the receive processing needs to be saved.
  284. */
  285. unsigned int state_saved;
  286. struct {
  287. unsigned int incomplete;
  288. unsigned int context_next;
  289. struct sk_buff *skb;
  290. unsigned int len;
  291. unsigned int error;
  292. } state;
  293. };
  294. struct xgbe_ring {
  295. /* Ring lock - used just for TX rings at the moment */
  296. spinlock_t lock;
  297. /* Per packet related information */
  298. struct xgbe_packet_data packet_data;
  299. /* Virtual/DMA addresses and count of allocated descriptor memory */
  300. struct xgbe_ring_desc *rdesc;
  301. dma_addr_t rdesc_dma;
  302. unsigned int rdesc_count;
  303. /* Array of descriptor data corresponding the descriptor memory
  304. * (always use the XGBE_GET_DESC_DATA macro to access this data)
  305. */
  306. struct xgbe_ring_data *rdata;
  307. /* Page allocation for RX buffers */
  308. struct xgbe_page_alloc rx_hdr_pa;
  309. struct xgbe_page_alloc rx_buf_pa;
  310. /* Ring index values
  311. * cur - Tx: index of descriptor to be used for current transfer
  312. * Rx: index of descriptor to check for packet availability
  313. * dirty - Tx: index of descriptor to check for transfer complete
  314. * Rx: index of descriptor to check for buffer reallocation
  315. */
  316. unsigned int cur;
  317. unsigned int dirty;
  318. /* Coalesce frame count used for interrupt bit setting */
  319. unsigned int coalesce_count;
  320. union {
  321. struct {
  322. unsigned int queue_stopped;
  323. unsigned int xmit_more;
  324. unsigned short cur_mss;
  325. unsigned short cur_vlan_ctag;
  326. } tx;
  327. };
  328. } ____cacheline_aligned;
  329. /* Structure used to describe the descriptor rings associated with
  330. * a DMA channel.
  331. */
  332. struct xgbe_channel {
  333. char name[16];
  334. /* Address of private data area for device */
  335. struct xgbe_prv_data *pdata;
  336. /* Queue index and base address of queue's DMA registers */
  337. unsigned int queue_index;
  338. void __iomem *dma_regs;
  339. /* Per channel interrupt irq number */
  340. int dma_irq;
  341. char dma_irq_name[IFNAMSIZ + 32];
  342. /* Netdev related settings */
  343. struct napi_struct napi;
  344. unsigned int saved_ier;
  345. unsigned int tx_timer_active;
  346. struct timer_list tx_timer;
  347. struct xgbe_ring *tx_ring;
  348. struct xgbe_ring *rx_ring;
  349. } ____cacheline_aligned;
  350. enum xgbe_int {
  351. XGMAC_INT_DMA_CH_SR_TI,
  352. XGMAC_INT_DMA_CH_SR_TPS,
  353. XGMAC_INT_DMA_CH_SR_TBU,
  354. XGMAC_INT_DMA_CH_SR_RI,
  355. XGMAC_INT_DMA_CH_SR_RBU,
  356. XGMAC_INT_DMA_CH_SR_RPS,
  357. XGMAC_INT_DMA_CH_SR_TI_RI,
  358. XGMAC_INT_DMA_CH_SR_FBE,
  359. XGMAC_INT_DMA_ALL,
  360. };
  361. enum xgbe_int_state {
  362. XGMAC_INT_STATE_SAVE,
  363. XGMAC_INT_STATE_RESTORE,
  364. };
  365. enum xgbe_mtl_fifo_size {
  366. XGMAC_MTL_FIFO_SIZE_256 = 0x00,
  367. XGMAC_MTL_FIFO_SIZE_512 = 0x01,
  368. XGMAC_MTL_FIFO_SIZE_1K = 0x03,
  369. XGMAC_MTL_FIFO_SIZE_2K = 0x07,
  370. XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
  371. XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
  372. XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
  373. XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
  374. XGMAC_MTL_FIFO_SIZE_64K = 0xff,
  375. XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
  376. XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
  377. };
  378. struct xgbe_mmc_stats {
  379. /* Tx Stats */
  380. u64 txoctetcount_gb;
  381. u64 txframecount_gb;
  382. u64 txbroadcastframes_g;
  383. u64 txmulticastframes_g;
  384. u64 tx64octets_gb;
  385. u64 tx65to127octets_gb;
  386. u64 tx128to255octets_gb;
  387. u64 tx256to511octets_gb;
  388. u64 tx512to1023octets_gb;
  389. u64 tx1024tomaxoctets_gb;
  390. u64 txunicastframes_gb;
  391. u64 txmulticastframes_gb;
  392. u64 txbroadcastframes_gb;
  393. u64 txunderflowerror;
  394. u64 txoctetcount_g;
  395. u64 txframecount_g;
  396. u64 txpauseframes;
  397. u64 txvlanframes_g;
  398. /* Rx Stats */
  399. u64 rxframecount_gb;
  400. u64 rxoctetcount_gb;
  401. u64 rxoctetcount_g;
  402. u64 rxbroadcastframes_g;
  403. u64 rxmulticastframes_g;
  404. u64 rxcrcerror;
  405. u64 rxrunterror;
  406. u64 rxjabbererror;
  407. u64 rxundersize_g;
  408. u64 rxoversize_g;
  409. u64 rx64octets_gb;
  410. u64 rx65to127octets_gb;
  411. u64 rx128to255octets_gb;
  412. u64 rx256to511octets_gb;
  413. u64 rx512to1023octets_gb;
  414. u64 rx1024tomaxoctets_gb;
  415. u64 rxunicastframes_g;
  416. u64 rxlengtherror;
  417. u64 rxoutofrangetype;
  418. u64 rxpauseframes;
  419. u64 rxfifooverflow;
  420. u64 rxvlanframes_gb;
  421. u64 rxwatchdogerror;
  422. };
  423. struct xgbe_hw_if {
  424. int (*tx_complete)(struct xgbe_ring_desc *);
  425. int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
  426. int (*config_rx_mode)(struct xgbe_prv_data *);
  427. int (*enable_rx_csum)(struct xgbe_prv_data *);
  428. int (*disable_rx_csum)(struct xgbe_prv_data *);
  429. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  430. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  431. int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
  432. int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
  433. int (*update_vlan_hash_table)(struct xgbe_prv_data *);
  434. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  435. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  436. int (*set_gmii_speed)(struct xgbe_prv_data *);
  437. int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
  438. int (*set_xgmii_speed)(struct xgbe_prv_data *);
  439. void (*enable_tx)(struct xgbe_prv_data *);
  440. void (*disable_tx)(struct xgbe_prv_data *);
  441. void (*enable_rx)(struct xgbe_prv_data *);
  442. void (*disable_rx)(struct xgbe_prv_data *);
  443. void (*powerup_tx)(struct xgbe_prv_data *);
  444. void (*powerdown_tx)(struct xgbe_prv_data *);
  445. void (*powerup_rx)(struct xgbe_prv_data *);
  446. void (*powerdown_rx)(struct xgbe_prv_data *);
  447. int (*init)(struct xgbe_prv_data *);
  448. int (*exit)(struct xgbe_prv_data *);
  449. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  450. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  451. void (*dev_xmit)(struct xgbe_channel *);
  452. int (*dev_read)(struct xgbe_channel *);
  453. void (*tx_desc_init)(struct xgbe_channel *);
  454. void (*rx_desc_init)(struct xgbe_channel *);
  455. void (*tx_desc_reset)(struct xgbe_ring_data *);
  456. void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
  457. unsigned int);
  458. int (*is_last_desc)(struct xgbe_ring_desc *);
  459. int (*is_context_desc)(struct xgbe_ring_desc *);
  460. void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
  461. /* For FLOW ctrl */
  462. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  463. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  464. /* For RX coalescing */
  465. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  466. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  467. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  468. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  469. /* For RX and TX threshold config */
  470. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  471. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  472. /* For RX and TX Store and Forward Mode config */
  473. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  474. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  475. /* For TX DMA Operate on Second Frame config */
  476. int (*config_osp_mode)(struct xgbe_prv_data *);
  477. /* For RX and TX PBL config */
  478. int (*config_rx_pbl_val)(struct xgbe_prv_data *);
  479. int (*get_rx_pbl_val)(struct xgbe_prv_data *);
  480. int (*config_tx_pbl_val)(struct xgbe_prv_data *);
  481. int (*get_tx_pbl_val)(struct xgbe_prv_data *);
  482. int (*config_pblx8)(struct xgbe_prv_data *);
  483. /* For MMC statistics */
  484. void (*rx_mmc_int)(struct xgbe_prv_data *);
  485. void (*tx_mmc_int)(struct xgbe_prv_data *);
  486. void (*read_mmc_stats)(struct xgbe_prv_data *);
  487. /* For Timestamp config */
  488. int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
  489. void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
  490. void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
  491. unsigned int nsec);
  492. u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  493. u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
  494. /* For Data Center Bridging config */
  495. void (*config_dcb_tc)(struct xgbe_prv_data *);
  496. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  497. /* For Receive Side Scaling */
  498. int (*enable_rss)(struct xgbe_prv_data *);
  499. int (*disable_rss)(struct xgbe_prv_data *);
  500. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  501. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  502. };
  503. struct xgbe_desc_if {
  504. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  505. void (*free_ring_resources)(struct xgbe_prv_data *);
  506. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  507. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  508. struct xgbe_ring_data *);
  509. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  510. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  511. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  512. };
  513. /* This structure contains flags that indicate what hardware features
  514. * or configurations are present in the device.
  515. */
  516. struct xgbe_hw_features {
  517. /* HW Version */
  518. unsigned int version;
  519. /* HW Feature Register0 */
  520. unsigned int gmii; /* 1000 Mbps support */
  521. unsigned int vlhash; /* VLAN Hash Filter */
  522. unsigned int sma; /* SMA(MDIO) Interface */
  523. unsigned int rwk; /* PMT remote wake-up packet */
  524. unsigned int mgk; /* PMT magic packet */
  525. unsigned int mmc; /* RMON module */
  526. unsigned int aoe; /* ARP Offload */
  527. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  528. unsigned int eee; /* Energy Efficient Ethernet */
  529. unsigned int tx_coe; /* Tx Checksum Offload */
  530. unsigned int rx_coe; /* Rx Checksum Offload */
  531. unsigned int addn_mac; /* Additional MAC Addresses */
  532. unsigned int ts_src; /* Timestamp Source */
  533. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  534. /* HW Feature Register1 */
  535. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  536. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  537. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  538. unsigned int dma_width; /* DMA width */
  539. unsigned int dcb; /* DCB Feature */
  540. unsigned int sph; /* Split Header Feature */
  541. unsigned int tso; /* TCP Segmentation Offload */
  542. unsigned int dma_debug; /* DMA Debug Registers */
  543. unsigned int rss; /* Receive Side Scaling */
  544. unsigned int tc_cnt; /* Number of Traffic Classes */
  545. unsigned int hash_table_size; /* Hash Table Size */
  546. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  547. /* HW Feature Register2 */
  548. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  549. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  550. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  551. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  552. unsigned int pps_out_num; /* Number of PPS outputs */
  553. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  554. };
  555. struct xgbe_prv_data {
  556. struct net_device *netdev;
  557. struct platform_device *pdev;
  558. struct acpi_device *adev;
  559. struct device *dev;
  560. /* ACPI or DT flag */
  561. unsigned int use_acpi;
  562. /* XGMAC/XPCS related mmio registers */
  563. void __iomem *xgmac_regs; /* XGMAC CSRs */
  564. void __iomem *xpcs_regs; /* XPCS MMD registers */
  565. /* Overall device lock */
  566. spinlock_t lock;
  567. /* XPCS indirect addressing mutex */
  568. struct mutex xpcs_mutex;
  569. /* RSS addressing mutex */
  570. struct mutex rss_mutex;
  571. int dev_irq;
  572. unsigned int per_channel_irq;
  573. struct xgbe_hw_if hw_if;
  574. struct xgbe_desc_if desc_if;
  575. /* AXI DMA settings */
  576. unsigned int coherent;
  577. unsigned int axdomain;
  578. unsigned int arcache;
  579. unsigned int awcache;
  580. /* Rings for Tx/Rx on a DMA channel */
  581. struct xgbe_channel *channel;
  582. unsigned int channel_count;
  583. unsigned int tx_ring_count;
  584. unsigned int tx_desc_count;
  585. unsigned int rx_ring_count;
  586. unsigned int rx_desc_count;
  587. unsigned int tx_q_count;
  588. unsigned int rx_q_count;
  589. /* Tx/Rx common settings */
  590. unsigned int pblx8;
  591. /* Tx settings */
  592. unsigned int tx_sf_mode;
  593. unsigned int tx_threshold;
  594. unsigned int tx_pbl;
  595. unsigned int tx_osp_mode;
  596. /* Rx settings */
  597. unsigned int rx_sf_mode;
  598. unsigned int rx_threshold;
  599. unsigned int rx_pbl;
  600. /* Tx coalescing settings */
  601. unsigned int tx_usecs;
  602. unsigned int tx_frames;
  603. /* Rx coalescing settings */
  604. unsigned int rx_riwt;
  605. unsigned int rx_usecs;
  606. unsigned int rx_frames;
  607. /* Current Rx buffer size */
  608. unsigned int rx_buf_size;
  609. /* Flow control settings */
  610. unsigned int pause_autoneg;
  611. unsigned int tx_pause;
  612. unsigned int rx_pause;
  613. /* Receive Side Scaling settings */
  614. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  615. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  616. u32 rss_options;
  617. /* MDIO settings */
  618. struct module *phy_module;
  619. char *mii_bus_id;
  620. struct mii_bus *mii;
  621. int mdio_mmd;
  622. struct phy_device *phydev;
  623. int default_autoneg;
  624. int default_speed;
  625. /* Current PHY settings */
  626. phy_interface_t phy_mode;
  627. int phy_link;
  628. int phy_speed;
  629. unsigned int phy_tx_pause;
  630. unsigned int phy_rx_pause;
  631. /* Netdev related settings */
  632. unsigned char mac_addr[ETH_ALEN];
  633. netdev_features_t netdev_features;
  634. struct napi_struct napi;
  635. struct xgbe_mmc_stats mmc_stats;
  636. /* Filtering support */
  637. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  638. /* Device clocks */
  639. struct clk *sysclk;
  640. unsigned long sysclk_rate;
  641. struct clk *ptpclk;
  642. unsigned long ptpclk_rate;
  643. /* Timestamp support */
  644. spinlock_t tstamp_lock;
  645. struct ptp_clock_info ptp_clock_info;
  646. struct ptp_clock *ptp_clock;
  647. struct hwtstamp_config tstamp_config;
  648. struct cyclecounter tstamp_cc;
  649. struct timecounter tstamp_tc;
  650. unsigned int tstamp_addend;
  651. struct work_struct tx_tstamp_work;
  652. struct sk_buff *tx_tstamp_skb;
  653. u64 tx_tstamp;
  654. /* DCB support */
  655. struct ieee_ets *ets;
  656. struct ieee_pfc *pfc;
  657. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  658. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  659. /* Hardware features of the device */
  660. struct xgbe_hw_features hw_feat;
  661. /* Device restart work structure */
  662. struct work_struct restart_work;
  663. /* Keeps track of power mode */
  664. unsigned int power_down;
  665. #ifdef CONFIG_DEBUG_FS
  666. struct dentry *xgbe_debugfs;
  667. unsigned int debugfs_xgmac_reg;
  668. unsigned int debugfs_xpcs_mmd;
  669. unsigned int debugfs_xpcs_reg;
  670. #endif
  671. };
  672. /* Function prototypes*/
  673. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  674. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  675. struct net_device_ops *xgbe_get_netdev_ops(void);
  676. struct ethtool_ops *xgbe_get_ethtool_ops(void);
  677. #ifdef CONFIG_AMD_XGBE_DCB
  678. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  679. #endif
  680. int xgbe_mdio_register(struct xgbe_prv_data *);
  681. void xgbe_mdio_unregister(struct xgbe_prv_data *);
  682. void xgbe_dump_phy_registers(struct xgbe_prv_data *);
  683. void xgbe_ptp_register(struct xgbe_prv_data *);
  684. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  685. void xgbe_dump_tx_desc(struct xgbe_ring *, unsigned int, unsigned int,
  686. unsigned int);
  687. void xgbe_dump_rx_desc(struct xgbe_ring *, struct xgbe_ring_desc *,
  688. unsigned int);
  689. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  690. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  691. int xgbe_powerup(struct net_device *, unsigned int);
  692. int xgbe_powerdown(struct net_device *, unsigned int);
  693. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  694. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  695. #ifdef CONFIG_DEBUG_FS
  696. void xgbe_debugfs_init(struct xgbe_prv_data *);
  697. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  698. #else
  699. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  700. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  701. #endif /* CONFIG_DEBUG_FS */
  702. /* NOTE: Uncomment for TX and RX DESCRIPTOR DUMP in KERNEL LOG */
  703. #if 0
  704. #define XGMAC_ENABLE_TX_DESC_DUMP
  705. #define XGMAC_ENABLE_RX_DESC_DUMP
  706. #endif
  707. /* NOTE: Uncomment for TX and RX PACKET DUMP in KERNEL LOG */
  708. #if 0
  709. #define XGMAC_ENABLE_TX_PKT_DUMP
  710. #define XGMAC_ENABLE_RX_PKT_DUMP
  711. #endif
  712. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  713. #if 0
  714. #define YDEBUG
  715. #define YDEBUG_MDIO
  716. #endif
  717. /* For debug prints */
  718. #ifdef YDEBUG
  719. #define DBGPR(x...) pr_alert(x)
  720. #define DBGPHY_REGS(x...) xgbe_dump_phy_registers(x)
  721. #else
  722. #define DBGPR(x...) do { } while (0)
  723. #define DBGPHY_REGS(x...) do { } while (0)
  724. #endif
  725. #ifdef YDEBUG_MDIO
  726. #define DBGPR_MDIO(x...) pr_alert(x)
  727. #else
  728. #define DBGPR_MDIO(x...) do { } while (0)
  729. #endif
  730. #endif