xgbe.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. #define XGBE_DRV_NAME "amd-xgbe"
  123. #define XGBE_DRV_VERSION "1.0.0-a"
  124. #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
  125. /* Descriptor related defines */
  126. #define TX_DESC_CNT 512
  127. #define TX_DESC_MIN_FREE (TX_DESC_CNT >> 3)
  128. #define TX_DESC_MAX_PROC (TX_DESC_CNT >> 1)
  129. #define RX_DESC_CNT 512
  130. #define TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  131. #define RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  132. #define RX_BUF_ALIGN 64
  133. #define XGBE_MAX_DMA_CHANNELS 16
  134. #define DMA_ARDOMAIN_SETTING 0x2
  135. #define DMA_ARCACHE_SETTING 0xb
  136. #define DMA_AWDOMAIN_SETTING 0x2
  137. #define DMA_AWCACHE_SETTING 0x7
  138. #define DMA_INTERRUPT_MASK 0x31c7
  139. #define XGMAC_MIN_PACKET 60
  140. #define XGMAC_STD_PACKET_MTU 1500
  141. #define XGMAC_MAX_STD_PACKET 1518
  142. #define XGMAC_JUMBO_PACKET_MTU 9000
  143. #define XGMAC_MAX_JUMBO_PACKET 9018
  144. #define MAX_MULTICAST_LIST 14
  145. #define TX_FLAGS_IP_PKT 0x00000001
  146. #define TX_FLAGS_TCP_PKT 0x00000002
  147. /* MDIO bus phy name */
  148. #define XGBE_PHY_NAME "amd_xgbe_phy"
  149. #define XGBE_PRTAD 0
  150. /* Driver PMT macros */
  151. #define XGMAC_DRIVER_CONTEXT 1
  152. #define XGMAC_IOCTL_CONTEXT 2
  153. #define FIFO_SIZE_B(x) (x)
  154. #define FIFO_SIZE_KB(x) (x * 1024)
  155. #define XGBE_TC_CNT 2
  156. /* Helper macro for descriptor handling
  157. * Always use GET_DESC_DATA to access the descriptor data
  158. * since the index is free-running and needs to be and-ed
  159. * with the descriptor count value of the ring to index to
  160. * the proper descriptor data.
  161. */
  162. #define GET_DESC_DATA(_ring, _idx) \
  163. ((_ring)->rdata + \
  164. ((_idx) & ((_ring)->rdesc_count - 1)))
  165. /* Default coalescing parameters */
  166. #define XGMAC_INIT_DMA_TX_USECS 100
  167. #define XGMAC_INIT_DMA_TX_FRAMES 16
  168. #define XGMAC_MAX_DMA_RIWT 0xff
  169. #define XGMAC_INIT_DMA_RX_USECS 100
  170. #define XGMAC_INIT_DMA_RX_FRAMES 16
  171. /* Flow control queue count */
  172. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  173. struct xgbe_prv_data;
  174. struct xgbe_packet_data {
  175. unsigned int attributes;
  176. unsigned int errors;
  177. unsigned int rdesc_count;
  178. unsigned int length;
  179. unsigned int header_len;
  180. unsigned int tcp_header_len;
  181. unsigned int tcp_payload_len;
  182. unsigned short mss;
  183. unsigned short vlan_ctag;
  184. };
  185. /* Common Rx and Tx descriptor mapping */
  186. struct xgbe_ring_desc {
  187. unsigned int desc0;
  188. unsigned int desc1;
  189. unsigned int desc2;
  190. unsigned int desc3;
  191. };
  192. /* Structure used to hold information related to the descriptor
  193. * and the packet associated with the descriptor (always use
  194. * use the GET_DESC_DATA macro to access this data from the ring)
  195. */
  196. struct xgbe_ring_data {
  197. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  198. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  199. struct sk_buff *skb; /* Virtual address of SKB */
  200. dma_addr_t skb_dma; /* DMA address of SKB data */
  201. unsigned int skb_dma_len; /* Length of SKB DMA area */
  202. unsigned int tso_header; /* TSO header indicator */
  203. unsigned short len; /* Length of received Rx packet */
  204. unsigned int interrupt; /* Interrupt indicator */
  205. unsigned int mapped_as_page;
  206. };
  207. struct xgbe_ring {
  208. /* Ring lock - used just for TX rings at the moment */
  209. spinlock_t lock;
  210. /* Per packet related information */
  211. struct xgbe_packet_data packet_data;
  212. /* Virtual/DMA addresses and count of allocated descriptor memory */
  213. struct xgbe_ring_desc *rdesc;
  214. dma_addr_t rdesc_dma;
  215. unsigned int rdesc_count;
  216. /* Array of descriptor data corresponding the descriptor memory
  217. * (always use the GET_DESC_DATA macro to access this data)
  218. */
  219. struct xgbe_ring_data *rdata;
  220. /* Ring index values
  221. * cur - Tx: index of descriptor to be used for current transfer
  222. * Rx: index of descriptor to check for packet availability
  223. * dirty - Tx: index of descriptor to check for transfer complete
  224. * Rx: count of descriptors in which a packet has been received
  225. * (used with skb_realloc_index to refresh the ring)
  226. */
  227. unsigned int cur;
  228. unsigned int dirty;
  229. /* Coalesce frame count used for interrupt bit setting */
  230. unsigned int coalesce_count;
  231. union {
  232. struct {
  233. unsigned int queue_stopped;
  234. unsigned short cur_mss;
  235. unsigned short cur_vlan_ctag;
  236. } tx;
  237. struct {
  238. unsigned int realloc_index;
  239. unsigned int realloc_threshold;
  240. } rx;
  241. };
  242. } ____cacheline_aligned;
  243. /* Structure used to describe the descriptor rings associated with
  244. * a DMA channel.
  245. */
  246. struct xgbe_channel {
  247. char name[16];
  248. /* Address of private data area for device */
  249. struct xgbe_prv_data *pdata;
  250. /* Queue index and base address of queue's DMA registers */
  251. unsigned int queue_index;
  252. void __iomem *dma_regs;
  253. unsigned int saved_ier;
  254. unsigned int tx_timer_active;
  255. struct hrtimer tx_timer;
  256. struct xgbe_ring *tx_ring;
  257. struct xgbe_ring *rx_ring;
  258. } ____cacheline_aligned;
  259. enum xgbe_int {
  260. XGMAC_INT_DMA_ISR_DC0IS,
  261. XGMAC_INT_DMA_CH_SR_TI,
  262. XGMAC_INT_DMA_CH_SR_TPS,
  263. XGMAC_INT_DMA_CH_SR_TBU,
  264. XGMAC_INT_DMA_CH_SR_RI,
  265. XGMAC_INT_DMA_CH_SR_RBU,
  266. XGMAC_INT_DMA_CH_SR_RPS,
  267. XGMAC_INT_DMA_CH_SR_FBE,
  268. XGMAC_INT_DMA_ALL,
  269. };
  270. enum xgbe_int_state {
  271. XGMAC_INT_STATE_SAVE,
  272. XGMAC_INT_STATE_RESTORE,
  273. };
  274. enum xgbe_mtl_fifo_size {
  275. XGMAC_MTL_FIFO_SIZE_256 = 0x00,
  276. XGMAC_MTL_FIFO_SIZE_512 = 0x01,
  277. XGMAC_MTL_FIFO_SIZE_1K = 0x03,
  278. XGMAC_MTL_FIFO_SIZE_2K = 0x07,
  279. XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
  280. XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
  281. XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
  282. XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
  283. XGMAC_MTL_FIFO_SIZE_64K = 0xff,
  284. XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
  285. XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
  286. };
  287. struct xgbe_mmc_stats {
  288. /* Tx Stats */
  289. u64 txoctetcount_gb;
  290. u64 txframecount_gb;
  291. u64 txbroadcastframes_g;
  292. u64 txmulticastframes_g;
  293. u64 tx64octets_gb;
  294. u64 tx65to127octets_gb;
  295. u64 tx128to255octets_gb;
  296. u64 tx256to511octets_gb;
  297. u64 tx512to1023octets_gb;
  298. u64 tx1024tomaxoctets_gb;
  299. u64 txunicastframes_gb;
  300. u64 txmulticastframes_gb;
  301. u64 txbroadcastframes_gb;
  302. u64 txunderflowerror;
  303. u64 txoctetcount_g;
  304. u64 txframecount_g;
  305. u64 txpauseframes;
  306. u64 txvlanframes_g;
  307. /* Rx Stats */
  308. u64 rxframecount_gb;
  309. u64 rxoctetcount_gb;
  310. u64 rxoctetcount_g;
  311. u64 rxbroadcastframes_g;
  312. u64 rxmulticastframes_g;
  313. u64 rxcrcerror;
  314. u64 rxrunterror;
  315. u64 rxjabbererror;
  316. u64 rxundersize_g;
  317. u64 rxoversize_g;
  318. u64 rx64octets_gb;
  319. u64 rx65to127octets_gb;
  320. u64 rx128to255octets_gb;
  321. u64 rx256to511octets_gb;
  322. u64 rx512to1023octets_gb;
  323. u64 rx1024tomaxoctets_gb;
  324. u64 rxunicastframes_g;
  325. u64 rxlengtherror;
  326. u64 rxoutofrangetype;
  327. u64 rxpauseframes;
  328. u64 rxfifooverflow;
  329. u64 rxvlanframes_gb;
  330. u64 rxwatchdogerror;
  331. };
  332. struct xgbe_hw_if {
  333. int (*tx_complete)(struct xgbe_ring_desc *);
  334. int (*set_promiscuous_mode)(struct xgbe_prv_data *, unsigned int);
  335. int (*set_all_multicast_mode)(struct xgbe_prv_data *, unsigned int);
  336. int (*set_addn_mac_addrs)(struct xgbe_prv_data *, unsigned int);
  337. int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
  338. int (*enable_rx_csum)(struct xgbe_prv_data *);
  339. int (*disable_rx_csum)(struct xgbe_prv_data *);
  340. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  341. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  342. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  343. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  344. int (*set_gmii_speed)(struct xgbe_prv_data *);
  345. int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
  346. int (*set_xgmii_speed)(struct xgbe_prv_data *);
  347. void (*enable_tx)(struct xgbe_prv_data *);
  348. void (*disable_tx)(struct xgbe_prv_data *);
  349. void (*enable_rx)(struct xgbe_prv_data *);
  350. void (*disable_rx)(struct xgbe_prv_data *);
  351. void (*powerup_tx)(struct xgbe_prv_data *);
  352. void (*powerdown_tx)(struct xgbe_prv_data *);
  353. void (*powerup_rx)(struct xgbe_prv_data *);
  354. void (*powerdown_rx)(struct xgbe_prv_data *);
  355. int (*init)(struct xgbe_prv_data *);
  356. int (*exit)(struct xgbe_prv_data *);
  357. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  358. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  359. void (*pre_xmit)(struct xgbe_channel *);
  360. int (*dev_read)(struct xgbe_channel *);
  361. void (*tx_desc_init)(struct xgbe_channel *);
  362. void (*rx_desc_init)(struct xgbe_channel *);
  363. void (*rx_desc_reset)(struct xgbe_ring_data *);
  364. void (*tx_desc_reset)(struct xgbe_ring_data *);
  365. int (*is_last_desc)(struct xgbe_ring_desc *);
  366. int (*is_context_desc)(struct xgbe_ring_desc *);
  367. /* For FLOW ctrl */
  368. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  369. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  370. /* For RX coalescing */
  371. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  372. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  373. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  374. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  375. /* For RX and TX threshold config */
  376. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  377. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  378. /* For RX and TX Store and Forward Mode config */
  379. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  380. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  381. /* For TX DMA Operate on Second Frame config */
  382. int (*config_osp_mode)(struct xgbe_prv_data *);
  383. /* For RX and TX PBL config */
  384. int (*config_rx_pbl_val)(struct xgbe_prv_data *);
  385. int (*get_rx_pbl_val)(struct xgbe_prv_data *);
  386. int (*config_tx_pbl_val)(struct xgbe_prv_data *);
  387. int (*get_tx_pbl_val)(struct xgbe_prv_data *);
  388. int (*config_pblx8)(struct xgbe_prv_data *);
  389. /* For MMC statistics */
  390. void (*rx_mmc_int)(struct xgbe_prv_data *);
  391. void (*tx_mmc_int)(struct xgbe_prv_data *);
  392. void (*read_mmc_stats)(struct xgbe_prv_data *);
  393. };
  394. struct xgbe_desc_if {
  395. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  396. void (*free_ring_resources)(struct xgbe_prv_data *);
  397. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  398. void (*realloc_skb)(struct xgbe_channel *);
  399. void (*unmap_skb)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  400. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  401. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  402. };
  403. /* This structure contains flags that indicate what hardware features
  404. * or configurations are present in the device.
  405. */
  406. struct xgbe_hw_features {
  407. /* HW Feature Register0 */
  408. unsigned int gmii; /* 1000 Mbps support */
  409. unsigned int vlhash; /* VLAN Hash Filter */
  410. unsigned int sma; /* SMA(MDIO) Interface */
  411. unsigned int rwk; /* PMT remote wake-up packet */
  412. unsigned int mgk; /* PMT magic packet */
  413. unsigned int mmc; /* RMON module */
  414. unsigned int aoe; /* ARP Offload */
  415. unsigned int ts; /* IEEE 1588-2008 Adavanced Timestamp */
  416. unsigned int eee; /* Energy Efficient Ethernet */
  417. unsigned int tx_coe; /* Tx Checksum Offload */
  418. unsigned int rx_coe; /* Rx Checksum Offload */
  419. unsigned int addn_mac; /* Additional MAC Addresses */
  420. unsigned int ts_src; /* Timestamp Source */
  421. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  422. /* HW Feature Register1 */
  423. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  424. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  425. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  426. unsigned int dcb; /* DCB Feature */
  427. unsigned int sph; /* Split Header Feature */
  428. unsigned int tso; /* TCP Segmentation Offload */
  429. unsigned int dma_debug; /* DMA Debug Registers */
  430. unsigned int rss; /* Receive Side Scaling */
  431. unsigned int hash_table_size; /* Hash Table Size */
  432. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  433. /* HW Feature Register2 */
  434. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  435. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  436. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  437. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  438. unsigned int pps_out_num; /* Number of PPS outputs */
  439. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  440. };
  441. struct xgbe_prv_data {
  442. struct net_device *netdev;
  443. struct platform_device *pdev;
  444. struct device *dev;
  445. /* XGMAC/XPCS related mmio registers */
  446. void __iomem *xgmac_regs; /* XGMAC CSRs */
  447. void __iomem *xpcs_regs; /* XPCS MMD registers */
  448. /* Overall device lock */
  449. spinlock_t lock;
  450. /* XPCS indirect addressing mutex */
  451. struct mutex xpcs_mutex;
  452. int irq_number;
  453. struct xgbe_hw_if hw_if;
  454. struct xgbe_desc_if desc_if;
  455. /* Rings for Tx/Rx on a DMA channel */
  456. struct xgbe_channel *channel;
  457. unsigned int channel_count;
  458. unsigned int tx_ring_count;
  459. unsigned int tx_desc_count;
  460. unsigned int rx_ring_count;
  461. unsigned int rx_desc_count;
  462. /* Tx/Rx common settings */
  463. unsigned int pblx8;
  464. /* Tx settings */
  465. unsigned int tx_sf_mode;
  466. unsigned int tx_threshold;
  467. unsigned int tx_pbl;
  468. unsigned int tx_osp_mode;
  469. /* Rx settings */
  470. unsigned int rx_sf_mode;
  471. unsigned int rx_threshold;
  472. unsigned int rx_pbl;
  473. /* Tx coalescing settings */
  474. unsigned int tx_usecs;
  475. unsigned int tx_frames;
  476. /* Rx coalescing settings */
  477. unsigned int rx_riwt;
  478. unsigned int rx_frames;
  479. /* Current MTU */
  480. unsigned int rx_buf_size;
  481. /* Flow control settings */
  482. unsigned int pause_autoneg;
  483. unsigned int tx_pause;
  484. unsigned int rx_pause;
  485. /* MDIO settings */
  486. struct module *phy_module;
  487. char *mii_bus_id;
  488. struct mii_bus *mii;
  489. int mdio_mmd;
  490. struct phy_device *phydev;
  491. int default_autoneg;
  492. int default_speed;
  493. /* Current PHY settings */
  494. phy_interface_t phy_mode;
  495. int phy_link;
  496. int phy_speed;
  497. unsigned int phy_tx_pause;
  498. unsigned int phy_rx_pause;
  499. /* Netdev related settings */
  500. netdev_features_t netdev_features;
  501. struct napi_struct napi;
  502. struct xgbe_mmc_stats mmc_stats;
  503. /* System clock value used for Rx watchdog */
  504. struct clk *sysclock;
  505. /* Hardware features of the device */
  506. struct xgbe_hw_features hw_feat;
  507. /* Device restart work structure */
  508. struct work_struct restart_work;
  509. /* Keeps track of power mode */
  510. unsigned int power_down;
  511. #ifdef CONFIG_DEBUG_FS
  512. struct dentry *xgbe_debugfs;
  513. unsigned int debugfs_xgmac_reg;
  514. unsigned int debugfs_xpcs_mmd;
  515. unsigned int debugfs_xpcs_reg;
  516. #endif
  517. };
  518. /* Function prototypes*/
  519. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  520. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  521. struct net_device_ops *xgbe_get_netdev_ops(void);
  522. struct ethtool_ops *xgbe_get_ethtool_ops(void);
  523. int xgbe_mdio_register(struct xgbe_prv_data *);
  524. void xgbe_mdio_unregister(struct xgbe_prv_data *);
  525. void xgbe_dump_phy_registers(struct xgbe_prv_data *);
  526. void xgbe_dump_tx_desc(struct xgbe_ring *, unsigned int, unsigned int,
  527. unsigned int);
  528. void xgbe_dump_rx_desc(struct xgbe_ring *, struct xgbe_ring_desc *,
  529. unsigned int);
  530. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  531. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  532. int xgbe_powerup(struct net_device *, unsigned int);
  533. int xgbe_powerdown(struct net_device *, unsigned int);
  534. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  535. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  536. #ifdef CONFIG_DEBUG_FS
  537. void xgbe_debugfs_init(struct xgbe_prv_data *);
  538. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  539. #else
  540. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  541. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  542. #endif /* CONFIG_DEBUG_FS */
  543. /* NOTE: Uncomment for TX and RX DESCRIPTOR DUMP in KERNEL LOG */
  544. #if 0
  545. #define XGMAC_ENABLE_TX_DESC_DUMP
  546. #define XGMAC_ENABLE_RX_DESC_DUMP
  547. #endif
  548. /* NOTE: Uncomment for TX and RX PACKET DUMP in KERNEL LOG */
  549. #if 0
  550. #define XGMAC_ENABLE_TX_PKT_DUMP
  551. #define XGMAC_ENABLE_RX_PKT_DUMP
  552. #endif
  553. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  554. #if 0
  555. #define YDEBUG
  556. #define YDEBUG_MDIO
  557. #endif
  558. /* For debug prints */
  559. #ifdef YDEBUG
  560. #define DBGPR(x...) pr_alert(x)
  561. #define DBGPHY_REGS(x...) xgbe_dump_phy_registers(x)
  562. #else
  563. #define DBGPR(x...) do { } while (0)
  564. #define DBGPHY_REGS(x...) do { } while (0)
  565. #endif
  566. #ifdef YDEBUG_MDIO
  567. #define DBGPR_MDIO(x...) pr_alert(x)
  568. #else
  569. #define DBGPR_MDIO(x...) do { } while (0)
  570. #endif
  571. #endif