xgbe.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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-2016 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-2016 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. #include <linux/completion.h>
  129. #define XGBE_DRV_NAME "amd-xgbe"
  130. #define XGBE_DRV_VERSION "1.0.3"
  131. #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
  132. /* Descriptor related defines */
  133. #define XGBE_TX_DESC_CNT 512
  134. #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
  135. #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
  136. #define XGBE_RX_DESC_CNT 512
  137. #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  138. /* Descriptors required for maximum contiguous TSO/GSO packet */
  139. #define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
  140. /* Maximum possible descriptors needed for an SKB:
  141. * - Maximum number of SKB frags
  142. * - Maximum descriptors for contiguous TSO/GSO packet
  143. * - Possible context descriptor
  144. * - Possible TSO header descriptor
  145. */
  146. #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
  147. #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  148. #define XGBE_RX_BUF_ALIGN 64
  149. #define XGBE_SKB_ALLOC_SIZE 256
  150. #define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
  151. #define XGBE_MAX_DMA_CHANNELS 16
  152. #define XGBE_MAX_QUEUES 16
  153. #define XGBE_PRIORITY_QUEUES 8
  154. #define XGBE_DMA_STOP_TIMEOUT 1
  155. /* DMA cache settings - Outer sharable, write-back, write-allocate */
  156. #define XGBE_DMA_OS_AXDOMAIN 0x2
  157. #define XGBE_DMA_OS_ARCACHE 0xb
  158. #define XGBE_DMA_OS_AWCACHE 0xf
  159. /* DMA cache settings - System, no caches used */
  160. #define XGBE_DMA_SYS_AXDOMAIN 0x3
  161. #define XGBE_DMA_SYS_ARCACHE 0x0
  162. #define XGBE_DMA_SYS_AWCACHE 0x0
  163. /* DMA channel interrupt modes */
  164. #define XGBE_IRQ_MODE_EDGE 0
  165. #define XGBE_IRQ_MODE_LEVEL 1
  166. #define XGBE_DMA_INTERRUPT_MASK 0x31c7
  167. #define XGMAC_MIN_PACKET 60
  168. #define XGMAC_STD_PACKET_MTU 1500
  169. #define XGMAC_MAX_STD_PACKET 1518
  170. #define XGMAC_JUMBO_PACKET_MTU 9000
  171. #define XGMAC_MAX_JUMBO_PACKET 9018
  172. #define XGMAC_ETH_PREAMBLE (12 + 8) /* Inter-frame gap + preamble */
  173. #define XGMAC_PFC_DATA_LEN 46
  174. #define XGMAC_PFC_DELAYS 14000
  175. #define XGMAC_PRIO_QUEUES(_cnt) \
  176. min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
  177. /* Common property names */
  178. #define XGBE_MAC_ADDR_PROPERTY "mac-address"
  179. #define XGBE_PHY_MODE_PROPERTY "phy-mode"
  180. #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
  181. #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
  182. /* Device-tree clock names */
  183. #define XGBE_DMA_CLOCK "dma_clk"
  184. #define XGBE_PTP_CLOCK "ptp_clk"
  185. /* ACPI property names */
  186. #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
  187. #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
  188. /* PCI BAR mapping */
  189. #define XGBE_XGMAC_BAR 0
  190. #define XGBE_XPCS_BAR 1
  191. #define XGBE_MAC_PROP_OFFSET 0x1d000
  192. #define XGBE_I2C_CTRL_OFFSET 0x1e000
  193. /* PCI MSIx support */
  194. #define XGBE_MSIX_BASE_COUNT 4
  195. #define XGBE_MSIX_MIN_COUNT (XGBE_MSIX_BASE_COUNT + 1)
  196. /* PCI clock frequencies */
  197. #define XGBE_V2_DMA_CLOCK_FREQ 500000000 /* 500 MHz */
  198. #define XGBE_V2_PTP_CLOCK_FREQ 125000000 /* 125 MHz */
  199. /* Timestamp support - values based on 50MHz PTP clock
  200. * 50MHz => 20 nsec
  201. */
  202. #define XGBE_TSTAMP_SSINC 20
  203. #define XGBE_TSTAMP_SNSINC 0
  204. /* Driver PMT macros */
  205. #define XGMAC_DRIVER_CONTEXT 1
  206. #define XGMAC_IOCTL_CONTEXT 2
  207. #define XGMAC_FIFO_MIN_ALLOC 2048
  208. #define XGMAC_FIFO_UNIT 256
  209. #define XGMAC_FIFO_ALIGN(_x) \
  210. (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
  211. #define XGMAC_FIFO_FC_OFF 2048
  212. #define XGMAC_FIFO_FC_MIN 4096
  213. #define XGBE_TC_MIN_QUANTUM 10
  214. /* Helper macro for descriptor handling
  215. * Always use XGBE_GET_DESC_DATA to access the descriptor data
  216. * since the index is free-running and needs to be and-ed
  217. * with the descriptor count value of the ring to index to
  218. * the proper descriptor data.
  219. */
  220. #define XGBE_GET_DESC_DATA(_ring, _idx) \
  221. ((_ring)->rdata + \
  222. ((_idx) & ((_ring)->rdesc_count - 1)))
  223. /* Default coalescing parameters */
  224. #define XGMAC_INIT_DMA_TX_USECS 1000
  225. #define XGMAC_INIT_DMA_TX_FRAMES 25
  226. #define XGMAC_MAX_DMA_RIWT 0xff
  227. #define XGMAC_INIT_DMA_RX_USECS 30
  228. #define XGMAC_INIT_DMA_RX_FRAMES 25
  229. /* Flow control queue count */
  230. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  231. /* Flow control threshold units */
  232. #define XGMAC_FLOW_CONTROL_UNIT 512
  233. #define XGMAC_FLOW_CONTROL_ALIGN(_x) \
  234. (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
  235. #define XGMAC_FLOW_CONTROL_VALUE(_x) \
  236. (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
  237. #define XGMAC_FLOW_CONTROL_MAX 33280
  238. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  239. #define XGBE_MAC_HASH_TABLE_SIZE 8
  240. /* Receive Side Scaling */
  241. #define XGBE_RSS_HASH_KEY_SIZE 40
  242. #define XGBE_RSS_MAX_TABLE_SIZE 256
  243. #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
  244. #define XGBE_RSS_HASH_KEY_TYPE 1
  245. /* Auto-negotiation */
  246. #define XGBE_AN_MS_TIMEOUT 500
  247. #define XGBE_LINK_TIMEOUT 5
  248. #define XGBE_SGMII_AN_LINK_STATUS BIT(1)
  249. #define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
  250. #define XGBE_SGMII_AN_LINK_SPEED_100 0x04
  251. #define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
  252. #define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
  253. /* ECC correctable error notification window (seconds) */
  254. #define XGBE_ECC_LIMIT 60
  255. /* MDIO port types */
  256. #define XGMAC_MAX_C22_PORT 3
  257. struct xgbe_prv_data;
  258. struct xgbe_packet_data {
  259. struct sk_buff *skb;
  260. unsigned int attributes;
  261. unsigned int errors;
  262. unsigned int rdesc_count;
  263. unsigned int length;
  264. unsigned int header_len;
  265. unsigned int tcp_header_len;
  266. unsigned int tcp_payload_len;
  267. unsigned short mss;
  268. unsigned short vlan_ctag;
  269. u64 rx_tstamp;
  270. u32 rss_hash;
  271. enum pkt_hash_types rss_hash_type;
  272. unsigned int tx_packets;
  273. unsigned int tx_bytes;
  274. };
  275. /* Common Rx and Tx descriptor mapping */
  276. struct xgbe_ring_desc {
  277. __le32 desc0;
  278. __le32 desc1;
  279. __le32 desc2;
  280. __le32 desc3;
  281. };
  282. /* Page allocation related values */
  283. struct xgbe_page_alloc {
  284. struct page *pages;
  285. unsigned int pages_len;
  286. unsigned int pages_offset;
  287. dma_addr_t pages_dma;
  288. };
  289. /* Ring entry buffer data */
  290. struct xgbe_buffer_data {
  291. struct xgbe_page_alloc pa;
  292. struct xgbe_page_alloc pa_unmap;
  293. dma_addr_t dma_base;
  294. unsigned long dma_off;
  295. unsigned int dma_len;
  296. };
  297. /* Tx-related ring data */
  298. struct xgbe_tx_ring_data {
  299. unsigned int packets; /* BQL packet count */
  300. unsigned int bytes; /* BQL byte count */
  301. };
  302. /* Rx-related ring data */
  303. struct xgbe_rx_ring_data {
  304. struct xgbe_buffer_data hdr; /* Header locations */
  305. struct xgbe_buffer_data buf; /* Payload locations */
  306. unsigned short hdr_len; /* Length of received header */
  307. unsigned short len; /* Length of received packet */
  308. };
  309. /* Structure used to hold information related to the descriptor
  310. * and the packet associated with the descriptor (always use
  311. * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
  312. */
  313. struct xgbe_ring_data {
  314. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  315. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  316. struct sk_buff *skb; /* Virtual address of SKB */
  317. dma_addr_t skb_dma; /* DMA address of SKB data */
  318. unsigned int skb_dma_len; /* Length of SKB DMA area */
  319. struct xgbe_tx_ring_data tx; /* Tx-related data */
  320. struct xgbe_rx_ring_data rx; /* Rx-related data */
  321. unsigned int mapped_as_page;
  322. /* Incomplete receive save location. If the budget is exhausted
  323. * or the last descriptor (last normal descriptor or a following
  324. * context descriptor) has not been DMA'd yet the current state
  325. * of the receive processing needs to be saved.
  326. */
  327. unsigned int state_saved;
  328. struct {
  329. struct sk_buff *skb;
  330. unsigned int len;
  331. unsigned int error;
  332. } state;
  333. };
  334. struct xgbe_ring {
  335. /* Ring lock - used just for TX rings at the moment */
  336. spinlock_t lock;
  337. /* Per packet related information */
  338. struct xgbe_packet_data packet_data;
  339. /* Virtual/DMA addresses and count of allocated descriptor memory */
  340. struct xgbe_ring_desc *rdesc;
  341. dma_addr_t rdesc_dma;
  342. unsigned int rdesc_count;
  343. /* Array of descriptor data corresponding the descriptor memory
  344. * (always use the XGBE_GET_DESC_DATA macro to access this data)
  345. */
  346. struct xgbe_ring_data *rdata;
  347. /* Page allocation for RX buffers */
  348. struct xgbe_page_alloc rx_hdr_pa;
  349. struct xgbe_page_alloc rx_buf_pa;
  350. /* Ring index values
  351. * cur - Tx: index of descriptor to be used for current transfer
  352. * Rx: index of descriptor to check for packet availability
  353. * dirty - Tx: index of descriptor to check for transfer complete
  354. * Rx: index of descriptor to check for buffer reallocation
  355. */
  356. unsigned int cur;
  357. unsigned int dirty;
  358. /* Coalesce frame count used for interrupt bit setting */
  359. unsigned int coalesce_count;
  360. union {
  361. struct {
  362. unsigned int queue_stopped;
  363. unsigned int xmit_more;
  364. unsigned short cur_mss;
  365. unsigned short cur_vlan_ctag;
  366. } tx;
  367. };
  368. } ____cacheline_aligned;
  369. /* Structure used to describe the descriptor rings associated with
  370. * a DMA channel.
  371. */
  372. struct xgbe_channel {
  373. char name[16];
  374. /* Address of private data area for device */
  375. struct xgbe_prv_data *pdata;
  376. /* Queue index and base address of queue's DMA registers */
  377. unsigned int queue_index;
  378. void __iomem *dma_regs;
  379. /* Per channel interrupt irq number */
  380. int dma_irq;
  381. char dma_irq_name[IFNAMSIZ + 32];
  382. /* Netdev related settings */
  383. struct napi_struct napi;
  384. unsigned int saved_ier;
  385. unsigned int tx_timer_active;
  386. struct timer_list tx_timer;
  387. struct xgbe_ring *tx_ring;
  388. struct xgbe_ring *rx_ring;
  389. } ____cacheline_aligned;
  390. enum xgbe_state {
  391. XGBE_DOWN,
  392. XGBE_LINK_INIT,
  393. XGBE_LINK_ERR,
  394. XGBE_STOPPED,
  395. };
  396. enum xgbe_int {
  397. XGMAC_INT_DMA_CH_SR_TI,
  398. XGMAC_INT_DMA_CH_SR_TPS,
  399. XGMAC_INT_DMA_CH_SR_TBU,
  400. XGMAC_INT_DMA_CH_SR_RI,
  401. XGMAC_INT_DMA_CH_SR_RBU,
  402. XGMAC_INT_DMA_CH_SR_RPS,
  403. XGMAC_INT_DMA_CH_SR_TI_RI,
  404. XGMAC_INT_DMA_CH_SR_FBE,
  405. XGMAC_INT_DMA_ALL,
  406. };
  407. enum xgbe_int_state {
  408. XGMAC_INT_STATE_SAVE,
  409. XGMAC_INT_STATE_RESTORE,
  410. };
  411. enum xgbe_ecc_sec {
  412. XGBE_ECC_SEC_TX,
  413. XGBE_ECC_SEC_RX,
  414. XGBE_ECC_SEC_DESC,
  415. };
  416. enum xgbe_speed {
  417. XGBE_SPEED_1000 = 0,
  418. XGBE_SPEED_2500,
  419. XGBE_SPEED_10000,
  420. XGBE_SPEEDS,
  421. };
  422. enum xgbe_xpcs_access {
  423. XGBE_XPCS_ACCESS_V1 = 0,
  424. XGBE_XPCS_ACCESS_V2,
  425. };
  426. enum xgbe_an_mode {
  427. XGBE_AN_MODE_CL73 = 0,
  428. XGBE_AN_MODE_CL73_REDRV,
  429. XGBE_AN_MODE_CL37,
  430. XGBE_AN_MODE_CL37_SGMII,
  431. XGBE_AN_MODE_NONE,
  432. };
  433. enum xgbe_an {
  434. XGBE_AN_READY = 0,
  435. XGBE_AN_PAGE_RECEIVED,
  436. XGBE_AN_INCOMPAT_LINK,
  437. XGBE_AN_COMPLETE,
  438. XGBE_AN_NO_LINK,
  439. XGBE_AN_ERROR,
  440. };
  441. enum xgbe_rx {
  442. XGBE_RX_BPA = 0,
  443. XGBE_RX_XNP,
  444. XGBE_RX_COMPLETE,
  445. XGBE_RX_ERROR,
  446. };
  447. enum xgbe_mode {
  448. XGBE_MODE_KX_1000 = 0,
  449. XGBE_MODE_KX_2500,
  450. XGBE_MODE_KR,
  451. XGBE_MODE_X,
  452. XGBE_MODE_SGMII_100,
  453. XGBE_MODE_SGMII_1000,
  454. XGBE_MODE_SFI,
  455. XGBE_MODE_UNKNOWN,
  456. };
  457. enum xgbe_speedset {
  458. XGBE_SPEEDSET_1000_10000 = 0,
  459. XGBE_SPEEDSET_2500_10000,
  460. };
  461. enum xgbe_mdio_mode {
  462. XGBE_MDIO_MODE_NONE = 0,
  463. XGBE_MDIO_MODE_CL22,
  464. XGBE_MDIO_MODE_CL45,
  465. };
  466. struct xgbe_phy {
  467. u32 supported;
  468. u32 advertising;
  469. u32 lp_advertising;
  470. int address;
  471. int autoneg;
  472. int speed;
  473. int duplex;
  474. int link;
  475. int pause_autoneg;
  476. int tx_pause;
  477. int rx_pause;
  478. };
  479. enum xgbe_i2c_cmd {
  480. XGBE_I2C_CMD_READ = 0,
  481. XGBE_I2C_CMD_WRITE,
  482. };
  483. struct xgbe_i2c_op {
  484. enum xgbe_i2c_cmd cmd;
  485. unsigned int target;
  486. void *buf;
  487. unsigned int len;
  488. };
  489. struct xgbe_i2c_op_state {
  490. struct xgbe_i2c_op *op;
  491. unsigned int tx_len;
  492. unsigned char *tx_buf;
  493. unsigned int rx_len;
  494. unsigned char *rx_buf;
  495. unsigned int tx_abort_source;
  496. int ret;
  497. };
  498. struct xgbe_i2c {
  499. unsigned int started;
  500. unsigned int max_speed_mode;
  501. unsigned int rx_fifo_size;
  502. unsigned int tx_fifo_size;
  503. struct xgbe_i2c_op_state op_state;
  504. };
  505. struct xgbe_mmc_stats {
  506. /* Tx Stats */
  507. u64 txoctetcount_gb;
  508. u64 txframecount_gb;
  509. u64 txbroadcastframes_g;
  510. u64 txmulticastframes_g;
  511. u64 tx64octets_gb;
  512. u64 tx65to127octets_gb;
  513. u64 tx128to255octets_gb;
  514. u64 tx256to511octets_gb;
  515. u64 tx512to1023octets_gb;
  516. u64 tx1024tomaxoctets_gb;
  517. u64 txunicastframes_gb;
  518. u64 txmulticastframes_gb;
  519. u64 txbroadcastframes_gb;
  520. u64 txunderflowerror;
  521. u64 txoctetcount_g;
  522. u64 txframecount_g;
  523. u64 txpauseframes;
  524. u64 txvlanframes_g;
  525. /* Rx Stats */
  526. u64 rxframecount_gb;
  527. u64 rxoctetcount_gb;
  528. u64 rxoctetcount_g;
  529. u64 rxbroadcastframes_g;
  530. u64 rxmulticastframes_g;
  531. u64 rxcrcerror;
  532. u64 rxrunterror;
  533. u64 rxjabbererror;
  534. u64 rxundersize_g;
  535. u64 rxoversize_g;
  536. u64 rx64octets_gb;
  537. u64 rx65to127octets_gb;
  538. u64 rx128to255octets_gb;
  539. u64 rx256to511octets_gb;
  540. u64 rx512to1023octets_gb;
  541. u64 rx1024tomaxoctets_gb;
  542. u64 rxunicastframes_g;
  543. u64 rxlengtherror;
  544. u64 rxoutofrangetype;
  545. u64 rxpauseframes;
  546. u64 rxfifooverflow;
  547. u64 rxvlanframes_gb;
  548. u64 rxwatchdogerror;
  549. };
  550. struct xgbe_ext_stats {
  551. u64 tx_tso_packets;
  552. u64 rx_split_header_packets;
  553. u64 rx_buffer_unavailable;
  554. };
  555. struct xgbe_hw_if {
  556. int (*tx_complete)(struct xgbe_ring_desc *);
  557. int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
  558. int (*config_rx_mode)(struct xgbe_prv_data *);
  559. int (*enable_rx_csum)(struct xgbe_prv_data *);
  560. int (*disable_rx_csum)(struct xgbe_prv_data *);
  561. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  562. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  563. int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
  564. int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
  565. int (*update_vlan_hash_table)(struct xgbe_prv_data *);
  566. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  567. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  568. int (*set_speed)(struct xgbe_prv_data *, int);
  569. int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
  570. enum xgbe_mdio_mode);
  571. int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
  572. int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, u16);
  573. int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
  574. int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
  575. void (*enable_tx)(struct xgbe_prv_data *);
  576. void (*disable_tx)(struct xgbe_prv_data *);
  577. void (*enable_rx)(struct xgbe_prv_data *);
  578. void (*disable_rx)(struct xgbe_prv_data *);
  579. void (*powerup_tx)(struct xgbe_prv_data *);
  580. void (*powerdown_tx)(struct xgbe_prv_data *);
  581. void (*powerup_rx)(struct xgbe_prv_data *);
  582. void (*powerdown_rx)(struct xgbe_prv_data *);
  583. int (*init)(struct xgbe_prv_data *);
  584. int (*exit)(struct xgbe_prv_data *);
  585. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  586. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  587. void (*dev_xmit)(struct xgbe_channel *);
  588. int (*dev_read)(struct xgbe_channel *);
  589. void (*tx_desc_init)(struct xgbe_channel *);
  590. void (*rx_desc_init)(struct xgbe_channel *);
  591. void (*tx_desc_reset)(struct xgbe_ring_data *);
  592. void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
  593. unsigned int);
  594. int (*is_last_desc)(struct xgbe_ring_desc *);
  595. int (*is_context_desc)(struct xgbe_ring_desc *);
  596. void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
  597. /* For FLOW ctrl */
  598. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  599. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  600. /* For RX coalescing */
  601. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  602. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  603. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  604. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  605. /* For RX and TX threshold config */
  606. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  607. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  608. /* For RX and TX Store and Forward Mode config */
  609. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  610. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  611. /* For TX DMA Operate on Second Frame config */
  612. int (*config_osp_mode)(struct xgbe_prv_data *);
  613. /* For RX and TX PBL config */
  614. int (*config_rx_pbl_val)(struct xgbe_prv_data *);
  615. int (*get_rx_pbl_val)(struct xgbe_prv_data *);
  616. int (*config_tx_pbl_val)(struct xgbe_prv_data *);
  617. int (*get_tx_pbl_val)(struct xgbe_prv_data *);
  618. int (*config_pblx8)(struct xgbe_prv_data *);
  619. /* For MMC statistics */
  620. void (*rx_mmc_int)(struct xgbe_prv_data *);
  621. void (*tx_mmc_int)(struct xgbe_prv_data *);
  622. void (*read_mmc_stats)(struct xgbe_prv_data *);
  623. /* For Timestamp config */
  624. int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
  625. void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
  626. void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
  627. unsigned int nsec);
  628. u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  629. u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
  630. /* For Data Center Bridging config */
  631. void (*config_tc)(struct xgbe_prv_data *);
  632. void (*config_dcb_tc)(struct xgbe_prv_data *);
  633. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  634. /* For Receive Side Scaling */
  635. int (*enable_rss)(struct xgbe_prv_data *);
  636. int (*disable_rss)(struct xgbe_prv_data *);
  637. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  638. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  639. /* For ECC */
  640. void (*disable_ecc_ded)(struct xgbe_prv_data *);
  641. void (*disable_ecc_sec)(struct xgbe_prv_data *, enum xgbe_ecc_sec);
  642. };
  643. /* This structure represents implementation specific routines for an
  644. * implementation of a PHY. All routines are required unless noted below.
  645. * Optional routines:
  646. * kr_training_pre, kr_training_post
  647. */
  648. struct xgbe_phy_impl_if {
  649. /* Perform Setup/teardown actions */
  650. int (*init)(struct xgbe_prv_data *);
  651. void (*exit)(struct xgbe_prv_data *);
  652. /* Perform start/stop specific actions */
  653. int (*reset)(struct xgbe_prv_data *);
  654. int (*start)(struct xgbe_prv_data *);
  655. void (*stop)(struct xgbe_prv_data *);
  656. /* Return the link status */
  657. int (*link_status)(struct xgbe_prv_data *, int *);
  658. /* Indicate if a particular speed is valid */
  659. bool (*valid_speed)(struct xgbe_prv_data *, int);
  660. /* Check if the specified mode can/should be used */
  661. bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
  662. /* Switch the PHY into various modes */
  663. void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
  664. /* Retrieve mode needed for a specific speed */
  665. enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
  666. /* Retrieve new/next mode when trying to auto-negotiate */
  667. enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
  668. /* Retrieve current mode */
  669. enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
  670. /* Retrieve current auto-negotiation mode */
  671. enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
  672. /* Configure auto-negotiation settings */
  673. int (*an_config)(struct xgbe_prv_data *);
  674. /* Set/override auto-negotiation advertisement settings */
  675. unsigned int (*an_advertising)(struct xgbe_prv_data *);
  676. /* Process results of auto-negotiation */
  677. enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
  678. /* Pre/Post KR training enablement support */
  679. void (*kr_training_pre)(struct xgbe_prv_data *);
  680. void (*kr_training_post)(struct xgbe_prv_data *);
  681. };
  682. struct xgbe_phy_if {
  683. /* For PHY setup/teardown */
  684. int (*phy_init)(struct xgbe_prv_data *);
  685. void (*phy_exit)(struct xgbe_prv_data *);
  686. /* For PHY support when setting device up/down */
  687. int (*phy_reset)(struct xgbe_prv_data *);
  688. int (*phy_start)(struct xgbe_prv_data *);
  689. void (*phy_stop)(struct xgbe_prv_data *);
  690. /* For PHY support while device is up */
  691. void (*phy_status)(struct xgbe_prv_data *);
  692. int (*phy_config_aneg)(struct xgbe_prv_data *);
  693. /* For PHY settings validation */
  694. bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
  695. /* For single interrupt support */
  696. irqreturn_t (*an_isr)(int, struct xgbe_prv_data *);
  697. /* PHY implementation specific services */
  698. struct xgbe_phy_impl_if phy_impl;
  699. };
  700. struct xgbe_i2c_if {
  701. /* For initial I2C setup */
  702. int (*i2c_init)(struct xgbe_prv_data *);
  703. /* For I2C support when setting device up/down */
  704. int (*i2c_start)(struct xgbe_prv_data *);
  705. void (*i2c_stop)(struct xgbe_prv_data *);
  706. /* For performing I2C operations */
  707. int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
  708. /* For single interrupt support */
  709. irqreturn_t (*i2c_isr)(int, struct xgbe_prv_data *);
  710. };
  711. struct xgbe_desc_if {
  712. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  713. void (*free_ring_resources)(struct xgbe_prv_data *);
  714. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  715. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  716. struct xgbe_ring_data *);
  717. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  718. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  719. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  720. };
  721. /* This structure contains flags that indicate what hardware features
  722. * or configurations are present in the device.
  723. */
  724. struct xgbe_hw_features {
  725. /* HW Version */
  726. unsigned int version;
  727. /* HW Feature Register0 */
  728. unsigned int gmii; /* 1000 Mbps support */
  729. unsigned int vlhash; /* VLAN Hash Filter */
  730. unsigned int sma; /* SMA(MDIO) Interface */
  731. unsigned int rwk; /* PMT remote wake-up packet */
  732. unsigned int mgk; /* PMT magic packet */
  733. unsigned int mmc; /* RMON module */
  734. unsigned int aoe; /* ARP Offload */
  735. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  736. unsigned int eee; /* Energy Efficient Ethernet */
  737. unsigned int tx_coe; /* Tx Checksum Offload */
  738. unsigned int rx_coe; /* Rx Checksum Offload */
  739. unsigned int addn_mac; /* Additional MAC Addresses */
  740. unsigned int ts_src; /* Timestamp Source */
  741. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  742. /* HW Feature Register1 */
  743. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  744. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  745. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  746. unsigned int dma_width; /* DMA width */
  747. unsigned int dcb; /* DCB Feature */
  748. unsigned int sph; /* Split Header Feature */
  749. unsigned int tso; /* TCP Segmentation Offload */
  750. unsigned int dma_debug; /* DMA Debug Registers */
  751. unsigned int rss; /* Receive Side Scaling */
  752. unsigned int tc_cnt; /* Number of Traffic Classes */
  753. unsigned int hash_table_size; /* Hash Table Size */
  754. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  755. /* HW Feature Register2 */
  756. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  757. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  758. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  759. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  760. unsigned int pps_out_num; /* Number of PPS outputs */
  761. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  762. };
  763. struct xgbe_version_data {
  764. void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
  765. enum xgbe_xpcs_access xpcs_access;
  766. unsigned int mmc_64bit;
  767. unsigned int tx_max_fifo_size;
  768. unsigned int rx_max_fifo_size;
  769. unsigned int tx_tstamp_workaround;
  770. unsigned int ecc_support;
  771. unsigned int i2c_support;
  772. };
  773. struct xgbe_prv_data {
  774. struct net_device *netdev;
  775. struct pci_dev *pcidev;
  776. struct platform_device *platdev;
  777. struct acpi_device *adev;
  778. struct device *dev;
  779. struct platform_device *phy_platdev;
  780. struct device *phy_dev;
  781. /* Version related data */
  782. struct xgbe_version_data *vdata;
  783. /* ACPI or DT flag */
  784. unsigned int use_acpi;
  785. /* XGMAC/XPCS related mmio registers */
  786. void __iomem *xgmac_regs; /* XGMAC CSRs */
  787. void __iomem *xpcs_regs; /* XPCS MMD registers */
  788. void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
  789. void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
  790. void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
  791. void __iomem *xprop_regs; /* XGBE property registers */
  792. void __iomem *xi2c_regs; /* XGBE I2C CSRs */
  793. /* Overall device lock */
  794. spinlock_t lock;
  795. /* XPCS indirect addressing lock */
  796. spinlock_t xpcs_lock;
  797. unsigned int xpcs_window;
  798. unsigned int xpcs_window_size;
  799. unsigned int xpcs_window_mask;
  800. /* RSS addressing mutex */
  801. struct mutex rss_mutex;
  802. /* Flags representing xgbe_state */
  803. unsigned long dev_state;
  804. /* ECC support */
  805. unsigned long tx_sec_period;
  806. unsigned long tx_ded_period;
  807. unsigned long rx_sec_period;
  808. unsigned long rx_ded_period;
  809. unsigned long desc_sec_period;
  810. unsigned long desc_ded_period;
  811. unsigned int tx_sec_count;
  812. unsigned int tx_ded_count;
  813. unsigned int rx_sec_count;
  814. unsigned int rx_ded_count;
  815. unsigned int desc_ded_count;
  816. unsigned int desc_sec_count;
  817. struct msix_entry *msix_entries;
  818. int dev_irq;
  819. int ecc_irq;
  820. int i2c_irq;
  821. int channel_irq[XGBE_MAX_DMA_CHANNELS];
  822. unsigned int per_channel_irq;
  823. unsigned int irq_shared;
  824. unsigned int irq_count;
  825. unsigned int channel_irq_count;
  826. unsigned int channel_irq_mode;
  827. char ecc_name[IFNAMSIZ + 32];
  828. struct xgbe_hw_if hw_if;
  829. struct xgbe_phy_if phy_if;
  830. struct xgbe_desc_if desc_if;
  831. struct xgbe_i2c_if i2c_if;
  832. /* AXI DMA settings */
  833. unsigned int coherent;
  834. unsigned int axdomain;
  835. unsigned int arcache;
  836. unsigned int awcache;
  837. /* Service routine support */
  838. struct workqueue_struct *dev_workqueue;
  839. struct work_struct service_work;
  840. struct timer_list service_timer;
  841. /* Rings for Tx/Rx on a DMA channel */
  842. struct xgbe_channel *channel;
  843. unsigned int tx_max_channel_count;
  844. unsigned int rx_max_channel_count;
  845. unsigned int channel_count;
  846. unsigned int tx_ring_count;
  847. unsigned int tx_desc_count;
  848. unsigned int rx_ring_count;
  849. unsigned int rx_desc_count;
  850. unsigned int tx_max_q_count;
  851. unsigned int rx_max_q_count;
  852. unsigned int tx_q_count;
  853. unsigned int rx_q_count;
  854. /* Tx/Rx common settings */
  855. unsigned int pblx8;
  856. /* Tx settings */
  857. unsigned int tx_sf_mode;
  858. unsigned int tx_threshold;
  859. unsigned int tx_pbl;
  860. unsigned int tx_osp_mode;
  861. unsigned int tx_max_fifo_size;
  862. /* Rx settings */
  863. unsigned int rx_sf_mode;
  864. unsigned int rx_threshold;
  865. unsigned int rx_pbl;
  866. unsigned int rx_max_fifo_size;
  867. /* Tx coalescing settings */
  868. unsigned int tx_usecs;
  869. unsigned int tx_frames;
  870. /* Rx coalescing settings */
  871. unsigned int rx_riwt;
  872. unsigned int rx_usecs;
  873. unsigned int rx_frames;
  874. /* Current Rx buffer size */
  875. unsigned int rx_buf_size;
  876. /* Flow control settings */
  877. unsigned int pause_autoneg;
  878. unsigned int tx_pause;
  879. unsigned int rx_pause;
  880. unsigned int rx_rfa[XGBE_MAX_QUEUES];
  881. unsigned int rx_rfd[XGBE_MAX_QUEUES];
  882. /* Receive Side Scaling settings */
  883. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  884. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  885. u32 rss_options;
  886. /* Netdev related settings */
  887. unsigned char mac_addr[ETH_ALEN];
  888. netdev_features_t netdev_features;
  889. struct napi_struct napi;
  890. struct xgbe_mmc_stats mmc_stats;
  891. struct xgbe_ext_stats ext_stats;
  892. /* Filtering support */
  893. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  894. /* Device clocks */
  895. struct clk *sysclk;
  896. unsigned long sysclk_rate;
  897. struct clk *ptpclk;
  898. unsigned long ptpclk_rate;
  899. /* Timestamp support */
  900. spinlock_t tstamp_lock;
  901. struct ptp_clock_info ptp_clock_info;
  902. struct ptp_clock *ptp_clock;
  903. struct hwtstamp_config tstamp_config;
  904. struct cyclecounter tstamp_cc;
  905. struct timecounter tstamp_tc;
  906. unsigned int tstamp_addend;
  907. struct work_struct tx_tstamp_work;
  908. struct sk_buff *tx_tstamp_skb;
  909. u64 tx_tstamp;
  910. /* DCB support */
  911. struct ieee_ets *ets;
  912. struct ieee_pfc *pfc;
  913. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  914. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  915. unsigned int pfcq[XGBE_MAX_QUEUES];
  916. unsigned int pfc_rfa;
  917. u8 num_tcs;
  918. /* Hardware features of the device */
  919. struct xgbe_hw_features hw_feat;
  920. /* Device work structures */
  921. struct work_struct restart_work;
  922. struct work_struct stopdev_work;
  923. /* Keeps track of power mode */
  924. unsigned int power_down;
  925. /* Network interface message level setting */
  926. u32 msg_enable;
  927. /* Current PHY settings */
  928. phy_interface_t phy_mode;
  929. int phy_link;
  930. int phy_speed;
  931. /* MDIO/PHY related settings */
  932. unsigned int phy_started;
  933. void *phy_data;
  934. struct xgbe_phy phy;
  935. int mdio_mmd;
  936. unsigned long link_check;
  937. struct completion mdio_complete;
  938. unsigned int kr_redrv;
  939. char an_name[IFNAMSIZ + 32];
  940. struct workqueue_struct *an_workqueue;
  941. int an_irq;
  942. struct work_struct an_irq_work;
  943. /* Auto-negotiation state machine support */
  944. unsigned int an_int;
  945. unsigned int an_status;
  946. struct mutex an_mutex;
  947. enum xgbe_an an_result;
  948. enum xgbe_an an_state;
  949. enum xgbe_rx kr_state;
  950. enum xgbe_rx kx_state;
  951. struct work_struct an_work;
  952. unsigned int an_supported;
  953. unsigned int parallel_detect;
  954. unsigned int fec_ability;
  955. unsigned long an_start;
  956. enum xgbe_an_mode an_mode;
  957. /* I2C support */
  958. struct xgbe_i2c i2c;
  959. struct mutex i2c_mutex;
  960. struct completion i2c_complete;
  961. char i2c_name[IFNAMSIZ + 32];
  962. unsigned int lpm_ctrl; /* CTRL1 for resume */
  963. #ifdef CONFIG_DEBUG_FS
  964. struct dentry *xgbe_debugfs;
  965. unsigned int debugfs_xgmac_reg;
  966. unsigned int debugfs_xpcs_mmd;
  967. unsigned int debugfs_xpcs_reg;
  968. unsigned int debugfs_xprop_reg;
  969. unsigned int debugfs_xi2c_reg;
  970. #endif
  971. };
  972. /* Function prototypes*/
  973. struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
  974. void xgbe_free_pdata(struct xgbe_prv_data *);
  975. void xgbe_set_counts(struct xgbe_prv_data *);
  976. int xgbe_config_netdev(struct xgbe_prv_data *);
  977. void xgbe_deconfig_netdev(struct xgbe_prv_data *);
  978. int xgbe_platform_init(void);
  979. void xgbe_platform_exit(void);
  980. #ifdef CONFIG_PCI
  981. int xgbe_pci_init(void);
  982. void xgbe_pci_exit(void);
  983. #else
  984. static inline int xgbe_pci_init(void) { return 0; }
  985. static inline void xgbe_pci_exit(void) { }
  986. #endif
  987. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  988. void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
  989. void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
  990. void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
  991. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  992. void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
  993. const struct net_device_ops *xgbe_get_netdev_ops(void);
  994. const struct ethtool_ops *xgbe_get_ethtool_ops(void);
  995. #ifdef CONFIG_AMD_XGBE_DCB
  996. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  997. #endif
  998. void xgbe_ptp_register(struct xgbe_prv_data *);
  999. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  1000. void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  1001. unsigned int, unsigned int, unsigned int);
  1002. void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  1003. unsigned int);
  1004. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  1005. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  1006. int xgbe_powerup(struct net_device *, unsigned int);
  1007. int xgbe_powerdown(struct net_device *, unsigned int);
  1008. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  1009. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  1010. #ifdef CONFIG_DEBUG_FS
  1011. void xgbe_debugfs_init(struct xgbe_prv_data *);
  1012. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  1013. #else
  1014. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  1015. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  1016. #endif /* CONFIG_DEBUG_FS */
  1017. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  1018. #if 0
  1019. #define YDEBUG
  1020. #define YDEBUG_MDIO
  1021. #endif
  1022. /* For debug prints */
  1023. #ifdef YDEBUG
  1024. #define DBGPR(x...) pr_alert(x)
  1025. #else
  1026. #define DBGPR(x...) do { } while (0)
  1027. #endif
  1028. #ifdef YDEBUG_MDIO
  1029. #define DBGPR_MDIO(x...) pr_alert(x)
  1030. #else
  1031. #define DBGPR_MDIO(x...) do { } while (0)
  1032. #endif
  1033. #endif