xgbe.h 25 KB

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