xgbe.h 41 KB

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