xgbe.h 40 KB

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