blob: 381144b8394738d8e5c38bb396e6ef42e89a61f6 [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
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 *
Lendacky, Thomasb3b71592016-02-17 11:49:08 -06009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050010 *
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 *
Lendacky, Thomasb3b71592016-02-17 11:49:08 -060059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050060 * 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
117#ifndef __XGBE_H__
118#define __XGBE_H__
119
120#include <linux/dma-mapping.h>
121#include <linux/netdevice.h>
122#include <linux/workqueue.h>
123#include <linux/phy.h>
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500124#include <linux/if_vlan.h>
125#include <linux/bitops.h>
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500126#include <linux/ptp_clock_kernel.h>
Richard Cochran74d23cc2014-12-21 19:46:56 +0100127#include <linux/timecounter.h>
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500128#include <linux/net_tstamp.h>
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500129#include <net/dcbnl.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500130
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500131#define XGBE_DRV_NAME "amd-xgbe"
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500132#define XGBE_DRV_VERSION "1.0.3"
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500133#define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
134
135/* Descriptor related defines */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500136#define XGBE_TX_DESC_CNT 512
137#define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
138#define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
139#define XGBE_RX_DESC_CNT 512
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500140
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500141#define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500142
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900143/* Descriptors required for maximum contiguous TSO/GSO packet */
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600144#define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
145
146/* Maximum possible descriptors needed for an SKB:
147 * - Maximum number of SKB frags
148 * - Maximum descriptors for contiguous TSO/GSO packet
149 * - Possible context descriptor
150 * - Possible TSO header descriptor
151 */
152#define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
153
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500154#define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
155#define XGBE_RX_BUF_ALIGN 64
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600156#define XGBE_SKB_ALLOC_SIZE 256
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600157#define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500158
Lendacky, Thomasd5c48582014-06-09 09:19:32 -0500159#define XGBE_MAX_DMA_CHANNELS 16
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500160#define XGBE_MAX_QUEUES 16
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500161#define XGBE_PRIORITY_QUEUES 8
Lendacky, Thomas4b8acdf2016-11-03 13:19:17 -0500162#define XGBE_DMA_STOP_TIMEOUT 1
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500163
164/* DMA cache settings - Outer sharable, write-back, write-allocate */
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500165#define XGBE_DMA_OS_AXDOMAIN 0x2
166#define XGBE_DMA_OS_ARCACHE 0xb
167#define XGBE_DMA_OS_AWCACHE 0xf
168
169/* DMA cache settings - System, no caches used */
170#define XGBE_DMA_SYS_AXDOMAIN 0x3
171#define XGBE_DMA_SYS_ARCACHE 0x0
172#define XGBE_DMA_SYS_AWCACHE 0x0
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500173
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600174/* DMA channel interrupt modes */
175#define XGBE_IRQ_MODE_EDGE 0
176#define XGBE_IRQ_MODE_LEVEL 1
177
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500178#define XGBE_DMA_INTERRUPT_MASK 0x31c7
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500179
180#define XGMAC_MIN_PACKET 60
181#define XGMAC_STD_PACKET_MTU 1500
182#define XGMAC_MAX_STD_PACKET 1518
183#define XGMAC_JUMBO_PACKET_MTU 9000
184#define XGMAC_MAX_JUMBO_PACKET 9018
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500185#define XGMAC_ETH_PREAMBLE (12 + 8) /* Inter-frame gap + preamble */
186
187#define XGMAC_PFC_DATA_LEN 46
188#define XGMAC_PFC_DELAYS 14000
189
190#define XGMAC_PRIO_QUEUES(_cnt) \
191 min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500192
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600193/* Common property names */
194#define XGBE_MAC_ADDR_PROPERTY "mac-address"
195#define XGBE_PHY_MODE_PROPERTY "phy-mode"
196#define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500197#define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600198
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500199/* Device-tree clock names */
200#define XGBE_DMA_CLOCK "dma_clk"
201#define XGBE_PTP_CLOCK "ptp_clk"
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600202
203/* ACPI property names */
204#define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
205#define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500206
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600207/* PCI BAR mapping */
208#define XGBE_XGMAC_BAR 0
209#define XGBE_XPCS_BAR 1
210#define XGBE_MAC_PROP_OFFSET 0x1d000
211#define XGBE_I2C_CTRL_OFFSET 0x1e000
212
213/* PCI MSIx support */
214#define XGBE_MSIX_BASE_COUNT 4
215#define XGBE_MSIX_MIN_COUNT (XGBE_MSIX_BASE_COUNT + 1)
216
217/* PCI clock frequencies */
218#define XGBE_V2_DMA_CLOCK_FREQ 500000000 /* 500 MHz */
219#define XGBE_V2_PTP_CLOCK_FREQ 125000000 /* 125 MHz */
220
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500221/* Timestamp support - values based on 50MHz PTP clock
222 * 50MHz => 20 nsec
223 */
224#define XGBE_TSTAMP_SSINC 20
225#define XGBE_TSTAMP_SNSINC 0
226
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500227/* Driver PMT macros */
228#define XGMAC_DRIVER_CONTEXT 1
229#define XGMAC_IOCTL_CONTEXT 2
230
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500231#define XGMAC_FIFO_MIN_ALLOC 2048
232#define XGMAC_FIFO_UNIT 256
233#define XGMAC_FIFO_ALIGN(_x) \
234 (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
235#define XGMAC_FIFO_FC_OFF 2048
236#define XGMAC_FIFO_FC_MIN 4096
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500237
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500238#define XGBE_TC_MIN_QUANTUM 10
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500239
240/* Helper macro for descriptor handling
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500241 * Always use XGBE_GET_DESC_DATA to access the descriptor data
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500242 * since the index is free-running and needs to be and-ed
243 * with the descriptor count value of the ring to index to
244 * the proper descriptor data.
245 */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500246#define XGBE_GET_DESC_DATA(_ring, _idx) \
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500247 ((_ring)->rdata + \
248 ((_idx) & ((_ring)->rdesc_count - 1)))
249
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500250/* Default coalescing parameters */
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500251#define XGMAC_INIT_DMA_TX_USECS 1000
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500252#define XGMAC_INIT_DMA_TX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500253
254#define XGMAC_MAX_DMA_RIWT 0xff
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500255#define XGMAC_INIT_DMA_RX_USECS 30
256#define XGMAC_INIT_DMA_RX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500257
258/* Flow control queue count */
259#define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
260
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500261/* Flow control threshold units */
262#define XGMAC_FLOW_CONTROL_UNIT 512
263#define XGMAC_FLOW_CONTROL_ALIGN(_x) \
264 (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
265#define XGMAC_FLOW_CONTROL_VALUE(_x) \
266 (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
267#define XGMAC_FLOW_CONTROL_MAX 33280
268
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500269/* Maximum MAC address hash table size (256 bits = 8 bytes) */
270#define XGBE_MAC_HASH_TABLE_SIZE 8
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500271
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600272/* Receive Side Scaling */
273#define XGBE_RSS_HASH_KEY_SIZE 40
274#define XGBE_RSS_MAX_TABLE_SIZE 256
275#define XGBE_RSS_LOOKUP_TABLE_TYPE 0
276#define XGBE_RSS_HASH_KEY_TYPE 1
277
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500278/* Auto-negotiation */
279#define XGBE_AN_MS_TIMEOUT 500
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -0500280#define XGBE_LINK_TIMEOUT 5
281
282#define XGBE_SGMII_AN_LINK_STATUS BIT(1)
283#define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
284#define XGBE_SGMII_AN_LINK_SPEED_100 0x04
285#define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
286#define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500287
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500288struct xgbe_prv_data;
289
290struct xgbe_packet_data {
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600291 struct sk_buff *skb;
292
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500293 unsigned int attributes;
294
295 unsigned int errors;
296
297 unsigned int rdesc_count;
298 unsigned int length;
299
300 unsigned int header_len;
301 unsigned int tcp_header_len;
302 unsigned int tcp_payload_len;
303 unsigned short mss;
304
305 unsigned short vlan_ctag;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500306
307 u64 rx_tstamp;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600308
309 u32 rss_hash;
310 enum pkt_hash_types rss_hash_type;
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -0600311
312 unsigned int tx_packets;
313 unsigned int tx_bytes;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500314};
315
316/* Common Rx and Tx descriptor mapping */
317struct xgbe_ring_desc {
Lendacky, Thomas5226cfc2014-11-12 10:37:49 -0600318 __le32 desc0;
319 __le32 desc1;
320 __le32 desc2;
321 __le32 desc3;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500322};
323
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600324/* Page allocation related values */
325struct xgbe_page_alloc {
326 struct page *pages;
327 unsigned int pages_len;
328 unsigned int pages_offset;
329
330 dma_addr_t pages_dma;
331};
332
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600333/* Ring entry buffer data */
334struct xgbe_buffer_data {
335 struct xgbe_page_alloc pa;
336 struct xgbe_page_alloc pa_unmap;
337
Lendacky, Thomascfbfd862015-07-06 11:57:37 -0500338 dma_addr_t dma_base;
339 unsigned long dma_off;
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600340 unsigned int dma_len;
341};
342
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600343/* Tx-related ring data */
344struct xgbe_tx_ring_data {
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -0600345 unsigned int packets; /* BQL packet count */
346 unsigned int bytes; /* BQL byte count */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600347};
348
349/* Rx-related ring data */
350struct xgbe_rx_ring_data {
351 struct xgbe_buffer_data hdr; /* Header locations */
352 struct xgbe_buffer_data buf; /* Payload locations */
353
354 unsigned short hdr_len; /* Length of received header */
355 unsigned short len; /* Length of received packet */
356};
357
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500358/* Structure used to hold information related to the descriptor
359 * and the packet associated with the descriptor (always use
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500360 * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500361 */
362struct xgbe_ring_data {
363 struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
364 dma_addr_t rdesc_dma; /* DMA address of descriptor */
365
366 struct sk_buff *skb; /* Virtual address of SKB */
367 dma_addr_t skb_dma; /* DMA address of SKB data */
368 unsigned int skb_dma_len; /* Length of SKB DMA area */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500369
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600370 struct xgbe_tx_ring_data tx; /* Tx-related data */
371 struct xgbe_rx_ring_data rx; /* Rx-related data */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500372
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500373 unsigned int mapped_as_page;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500374
375 /* Incomplete receive save location. If the budget is exhausted
376 * or the last descriptor (last normal descriptor or a following
377 * context descriptor) has not been DMA'd yet the current state
378 * of the receive processing needs to be saved.
379 */
380 unsigned int state_saved;
381 struct {
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500382 struct sk_buff *skb;
383 unsigned int len;
384 unsigned int error;
385 } state;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500386};
387
388struct xgbe_ring {
389 /* Ring lock - used just for TX rings at the moment */
390 spinlock_t lock;
391
392 /* Per packet related information */
393 struct xgbe_packet_data packet_data;
394
395 /* Virtual/DMA addresses and count of allocated descriptor memory */
396 struct xgbe_ring_desc *rdesc;
397 dma_addr_t rdesc_dma;
398 unsigned int rdesc_count;
399
400 /* Array of descriptor data corresponding the descriptor memory
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500401 * (always use the XGBE_GET_DESC_DATA macro to access this data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500402 */
403 struct xgbe_ring_data *rdata;
404
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600405 /* Page allocation for RX buffers */
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600406 struct xgbe_page_alloc rx_hdr_pa;
407 struct xgbe_page_alloc rx_buf_pa;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600408
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500409 /* Ring index values
410 * cur - Tx: index of descriptor to be used for current transfer
411 * Rx: index of descriptor to check for packet availability
412 * dirty - Tx: index of descriptor to check for transfer complete
Lendacky, Thomas270894e2015-01-16 12:46:50 -0600413 * Rx: index of descriptor to check for buffer reallocation
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500414 */
415 unsigned int cur;
416 unsigned int dirty;
417
418 /* Coalesce frame count used for interrupt bit setting */
419 unsigned int coalesce_count;
420
421 union {
422 struct {
423 unsigned int queue_stopped;
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600424 unsigned int xmit_more;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500425 unsigned short cur_mss;
426 unsigned short cur_vlan_ctag;
427 } tx;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500428 };
429} ____cacheline_aligned;
430
431/* Structure used to describe the descriptor rings associated with
432 * a DMA channel.
433 */
434struct xgbe_channel {
435 char name[16];
436
437 /* Address of private data area for device */
438 struct xgbe_prv_data *pdata;
439
440 /* Queue index and base address of queue's DMA registers */
441 unsigned int queue_index;
442 void __iomem *dma_regs;
443
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600444 /* Per channel interrupt irq number */
445 int dma_irq;
Lendacky, Thomas54ceb9e2014-12-02 18:07:18 -0600446 char dma_irq_name[IFNAMSIZ + 32];
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600447
448 /* Netdev related settings */
449 struct napi_struct napi;
450
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500451 unsigned int saved_ier;
452
453 unsigned int tx_timer_active;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500454 struct timer_list tx_timer;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500455
456 struct xgbe_ring *tx_ring;
457 struct xgbe_ring *rx_ring;
458} ____cacheline_aligned;
459
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500460enum xgbe_state {
461 XGBE_DOWN,
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500462 XGBE_LINK_INIT,
463 XGBE_LINK_ERR,
464};
465
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500466enum xgbe_int {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500467 XGMAC_INT_DMA_CH_SR_TI,
468 XGMAC_INT_DMA_CH_SR_TPS,
469 XGMAC_INT_DMA_CH_SR_TBU,
470 XGMAC_INT_DMA_CH_SR_RI,
471 XGMAC_INT_DMA_CH_SR_RBU,
472 XGMAC_INT_DMA_CH_SR_RPS,
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500473 XGMAC_INT_DMA_CH_SR_TI_RI,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500474 XGMAC_INT_DMA_CH_SR_FBE,
475 XGMAC_INT_DMA_ALL,
476};
477
478enum xgbe_int_state {
479 XGMAC_INT_STATE_SAVE,
480 XGMAC_INT_STATE_RESTORE,
481};
482
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500483enum xgbe_speed {
484 XGBE_SPEED_1000 = 0,
485 XGBE_SPEED_2500,
486 XGBE_SPEED_10000,
487 XGBE_SPEEDS,
488};
489
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500490enum xgbe_xpcs_access {
491 XGBE_XPCS_ACCESS_V1 = 0,
492 XGBE_XPCS_ACCESS_V2,
493};
494
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500495enum xgbe_an_mode {
496 XGBE_AN_MODE_CL73 = 0,
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -0500497 XGBE_AN_MODE_CL37,
498 XGBE_AN_MODE_CL37_SGMII,
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500499 XGBE_AN_MODE_NONE,
500};
501
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500502enum xgbe_an {
503 XGBE_AN_READY = 0,
504 XGBE_AN_PAGE_RECEIVED,
505 XGBE_AN_INCOMPAT_LINK,
506 XGBE_AN_COMPLETE,
507 XGBE_AN_NO_LINK,
508 XGBE_AN_ERROR,
509};
510
511enum xgbe_rx {
512 XGBE_RX_BPA = 0,
513 XGBE_RX_XNP,
514 XGBE_RX_COMPLETE,
515 XGBE_RX_ERROR,
516};
517
518enum xgbe_mode {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500519 XGBE_MODE_KX_1000 = 0,
520 XGBE_MODE_KX_2500,
521 XGBE_MODE_KR,
522 XGBE_MODE_UNKNOWN,
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500523};
524
525enum xgbe_speedset {
526 XGBE_SPEEDSET_1000_10000 = 0,
527 XGBE_SPEEDSET_2500_10000,
528};
529
530struct xgbe_phy {
531 u32 supported;
532 u32 advertising;
533 u32 lp_advertising;
534
535 int address;
536
537 int autoneg;
538 int speed;
539 int duplex;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500540
541 int link;
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500542
543 int pause_autoneg;
544 int tx_pause;
545 int rx_pause;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500546};
547
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500548struct xgbe_mmc_stats {
549 /* Tx Stats */
550 u64 txoctetcount_gb;
551 u64 txframecount_gb;
552 u64 txbroadcastframes_g;
553 u64 txmulticastframes_g;
554 u64 tx64octets_gb;
555 u64 tx65to127octets_gb;
556 u64 tx128to255octets_gb;
557 u64 tx256to511octets_gb;
558 u64 tx512to1023octets_gb;
559 u64 tx1024tomaxoctets_gb;
560 u64 txunicastframes_gb;
561 u64 txmulticastframes_gb;
562 u64 txbroadcastframes_gb;
563 u64 txunderflowerror;
564 u64 txoctetcount_g;
565 u64 txframecount_g;
566 u64 txpauseframes;
567 u64 txvlanframes_g;
568
569 /* Rx Stats */
570 u64 rxframecount_gb;
571 u64 rxoctetcount_gb;
572 u64 rxoctetcount_g;
573 u64 rxbroadcastframes_g;
574 u64 rxmulticastframes_g;
575 u64 rxcrcerror;
576 u64 rxrunterror;
577 u64 rxjabbererror;
578 u64 rxundersize_g;
579 u64 rxoversize_g;
580 u64 rx64octets_gb;
581 u64 rx65to127octets_gb;
582 u64 rx128to255octets_gb;
583 u64 rx256to511octets_gb;
584 u64 rx512to1023octets_gb;
585 u64 rx1024tomaxoctets_gb;
586 u64 rxunicastframes_g;
587 u64 rxlengtherror;
588 u64 rxoutofrangetype;
589 u64 rxpauseframes;
590 u64 rxfifooverflow;
591 u64 rxvlanframes_gb;
592 u64 rxwatchdogerror;
593};
594
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500595struct xgbe_ext_stats {
596 u64 tx_tso_packets;
597 u64 rx_split_header_packets;
Lendacky, Thomas72c9ac42015-09-30 08:53:10 -0500598 u64 rx_buffer_unavailable;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500599};
600
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500601struct xgbe_hw_if {
602 int (*tx_complete)(struct xgbe_ring_desc *);
603
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500604 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
Lendacky, Thomasb8763822015-04-09 12:11:57 -0500605 int (*config_rx_mode)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500606
607 int (*enable_rx_csum)(struct xgbe_prv_data *);
608 int (*disable_rx_csum)(struct xgbe_prv_data *);
609
610 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
611 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500612 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
613 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
614 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500615
616 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
617 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500618 int (*set_speed)(struct xgbe_prv_data *, int);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500619
620 void (*enable_tx)(struct xgbe_prv_data *);
621 void (*disable_tx)(struct xgbe_prv_data *);
622 void (*enable_rx)(struct xgbe_prv_data *);
623 void (*disable_rx)(struct xgbe_prv_data *);
624
625 void (*powerup_tx)(struct xgbe_prv_data *);
626 void (*powerdown_tx)(struct xgbe_prv_data *);
627 void (*powerup_rx)(struct xgbe_prv_data *);
628 void (*powerdown_rx)(struct xgbe_prv_data *);
629
630 int (*init)(struct xgbe_prv_data *);
631 int (*exit)(struct xgbe_prv_data *);
632
633 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
634 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
Lendacky, Thomasa9d41982014-11-04 16:06:32 -0600635 void (*dev_xmit)(struct xgbe_channel *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500636 int (*dev_read)(struct xgbe_channel *);
637 void (*tx_desc_init)(struct xgbe_channel *);
638 void (*rx_desc_init)(struct xgbe_channel *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500639 void (*tx_desc_reset)(struct xgbe_ring_data *);
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -0500640 void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
641 unsigned int);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500642 int (*is_last_desc)(struct xgbe_ring_desc *);
643 int (*is_context_desc)(struct xgbe_ring_desc *);
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600644 void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500645
646 /* For FLOW ctrl */
647 int (*config_tx_flow_control)(struct xgbe_prv_data *);
648 int (*config_rx_flow_control)(struct xgbe_prv_data *);
649
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
656 /* For RX and TX threshold config */
657 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
658 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
659
660 /* For RX and TX Store and Forward Mode config */
661 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
662 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
663
664 /* For TX DMA Operate on Second Frame config */
665 int (*config_osp_mode)(struct xgbe_prv_data *);
666
667 /* For RX and TX PBL config */
668 int (*config_rx_pbl_val)(struct xgbe_prv_data *);
669 int (*get_rx_pbl_val)(struct xgbe_prv_data *);
670 int (*config_tx_pbl_val)(struct xgbe_prv_data *);
671 int (*get_tx_pbl_val)(struct xgbe_prv_data *);
672 int (*config_pblx8)(struct xgbe_prv_data *);
673
674 /* For MMC statistics */
675 void (*rx_mmc_int)(struct xgbe_prv_data *);
676 void (*tx_mmc_int)(struct xgbe_prv_data *);
677 void (*read_mmc_stats)(struct xgbe_prv_data *);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500678
679 /* For Timestamp config */
680 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
681 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
682 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
683 unsigned int nsec);
684 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
685 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500686
687 /* For Data Center Bridging config */
Lendacky, Thomasb3b71592016-02-17 11:49:08 -0600688 void (*config_tc)(struct xgbe_prv_data *);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500689 void (*config_dcb_tc)(struct xgbe_prv_data *);
690 void (*config_dcb_pfc)(struct xgbe_prv_data *);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600691
692 /* For Receive Side Scaling */
693 int (*enable_rss)(struct xgbe_prv_data *);
694 int (*disable_rss)(struct xgbe_prv_data *);
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600695 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
696 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500697};
698
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500699/* This structure represents implementation specific routines for an
700 * implementation of a PHY. All routines are required unless noted below.
701 * Optional routines:
702 * kr_training_pre, kr_training_post
703 */
704struct xgbe_phy_impl_if {
705 /* Perform Setup/teardown actions */
706 int (*init)(struct xgbe_prv_data *);
707 void (*exit)(struct xgbe_prv_data *);
708
709 /* Perform start/stop specific actions */
710 int (*reset)(struct xgbe_prv_data *);
711 int (*start)(struct xgbe_prv_data *);
712 void (*stop)(struct xgbe_prv_data *);
713
714 /* Return the link status */
715 int (*link_status)(struct xgbe_prv_data *);
716
717 /* Indicate if a particular speed is valid */
718 bool (*valid_speed)(struct xgbe_prv_data *, int);
719
720 /* Check if the specified mode can/should be used */
721 bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
722 /* Switch the PHY into various modes */
723 void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
724 /* Retrieve mode needed for a specific speed */
725 enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
726 /* Retrieve new/next mode when trying to auto-negotiate */
727 enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
728 /* Retrieve current mode */
729 enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
730
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500731 /* Retrieve current auto-negotiation mode */
732 enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
733
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500734 /* Process results of auto-negotiation */
735 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
736
737 /* Pre/Post KR training enablement support */
738 void (*kr_training_pre)(struct xgbe_prv_data *);
739 void (*kr_training_post)(struct xgbe_prv_data *);
740};
741
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500742struct xgbe_phy_if {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500743 /* For PHY setup/teardown */
744 int (*phy_init)(struct xgbe_prv_data *);
745 void (*phy_exit)(struct xgbe_prv_data *);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500746
747 /* For PHY support when setting device up/down */
748 int (*phy_reset)(struct xgbe_prv_data *);
749 int (*phy_start)(struct xgbe_prv_data *);
750 void (*phy_stop)(struct xgbe_prv_data *);
751
752 /* For PHY support while device is up */
753 void (*phy_status)(struct xgbe_prv_data *);
754 int (*phy_config_aneg)(struct xgbe_prv_data *);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500755
756 /* For PHY settings validation */
757 bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
758
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600759 /* For single interrupt support */
760 irqreturn_t (*an_isr)(int, struct xgbe_prv_data *);
761
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500762 /* PHY implementation specific services */
763 struct xgbe_phy_impl_if phy_impl;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500764};
765
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500766struct xgbe_desc_if {
767 int (*alloc_ring_resources)(struct xgbe_prv_data *);
768 void (*free_ring_resources)(struct xgbe_prv_data *);
769 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
Lendacky, Thomas270894e2015-01-16 12:46:50 -0600770 int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
771 struct xgbe_ring_data *);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600772 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500773 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
774 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
775};
776
777/* This structure contains flags that indicate what hardware features
778 * or configurations are present in the device.
779 */
780struct xgbe_hw_features {
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500781 /* HW Version */
782 unsigned int version;
783
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500784 /* HW Feature Register0 */
785 unsigned int gmii; /* 1000 Mbps support */
786 unsigned int vlhash; /* VLAN Hash Filter */
787 unsigned int sma; /* SMA(MDIO) Interface */
788 unsigned int rwk; /* PMT remote wake-up packet */
789 unsigned int mgk; /* PMT magic packet */
790 unsigned int mmc; /* RMON module */
791 unsigned int aoe; /* ARP Offload */
Joe Perchesdbedd442015-03-06 20:49:12 -0800792 unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500793 unsigned int eee; /* Energy Efficient Ethernet */
794 unsigned int tx_coe; /* Tx Checksum Offload */
795 unsigned int rx_coe; /* Rx Checksum Offload */
796 unsigned int addn_mac; /* Additional MAC Addresses */
797 unsigned int ts_src; /* Timestamp Source */
798 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
799
800 /* HW Feature Register1 */
801 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
802 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
803 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500804 unsigned int dma_width; /* DMA width */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500805 unsigned int dcb; /* DCB Feature */
806 unsigned int sph; /* Split Header Feature */
807 unsigned int tso; /* TCP Segmentation Offload */
808 unsigned int dma_debug; /* DMA Debug Registers */
809 unsigned int rss; /* Receive Side Scaling */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500810 unsigned int tc_cnt; /* Number of Traffic Classes */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500811 unsigned int hash_table_size; /* Hash Table Size */
812 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
813
814 /* HW Feature Register2 */
815 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
816 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
817 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
818 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
819 unsigned int pps_out_num; /* Number of PPS outputs */
820 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
821};
822
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500823struct xgbe_version_data {
824 void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500825 enum xgbe_xpcs_access xpcs_access;
Lendacky, Thomase5a20b92016-11-03 13:19:07 -0500826 unsigned int mmc_64bit;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500827 unsigned int tx_max_fifo_size;
828 unsigned int rx_max_fifo_size;
Lendacky, Thomasaba97772016-11-10 17:09:45 -0600829 unsigned int tx_tstamp_workaround;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500830};
831
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500832struct xgbe_prv_data {
833 struct net_device *netdev;
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600834 struct pci_dev *pcidev;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500835 struct platform_device *platdev;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600836 struct acpi_device *adev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500837 struct device *dev;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500838 struct platform_device *phy_platdev;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500839 struct device *phy_dev;
840
841 /* Version related data */
842 struct xgbe_version_data *vdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500843
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600844 /* ACPI or DT flag */
845 unsigned int use_acpi;
846
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500847 /* XGMAC/XPCS related mmio registers */
848 void __iomem *xgmac_regs; /* XGMAC CSRs */
849 void __iomem *xpcs_regs; /* XPCS MMD registers */
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500850 void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
851 void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
852 void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600853 void __iomem *xprop_regs; /* XGBE property registers */
854 void __iomem *xi2c_regs; /* XGBE I2C CSRs */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500855
856 /* Overall device lock */
857 spinlock_t lock;
858
Lendacky, Thomasced3fca2016-02-17 11:49:28 -0600859 /* XPCS indirect addressing lock */
860 spinlock_t xpcs_lock;
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500861 unsigned int xpcs_window;
862 unsigned int xpcs_window_size;
863 unsigned int xpcs_window_mask;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500864
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600865 /* RSS addressing mutex */
866 struct mutex rss_mutex;
867
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500868 /* Flags representing xgbe_state */
869 unsigned long dev_state;
870
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600871 struct msix_entry *msix_entries;
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600872 int dev_irq;
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600873 int ecc_irq;
874 int i2c_irq;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500875 int channel_irq[XGBE_MAX_DMA_CHANNELS];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500876
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600877 unsigned int per_channel_irq;
878 unsigned int irq_shared;
879 unsigned int irq_count;
880 unsigned int channel_irq_count;
Lendacky, Thomas4c70dd82016-11-10 17:10:17 -0600881 unsigned int channel_irq_mode;
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600882
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500883 struct xgbe_hw_if hw_if;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500884 struct xgbe_phy_if phy_if;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500885 struct xgbe_desc_if desc_if;
886
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500887 /* AXI DMA settings */
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600888 unsigned int coherent;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500889 unsigned int axdomain;
890 unsigned int arcache;
891 unsigned int awcache;
892
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500893 /* Service routine support */
894 struct workqueue_struct *dev_workqueue;
895 struct work_struct service_work;
896 struct timer_list service_timer;
897
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500898 /* Rings for Tx/Rx on a DMA channel */
899 struct xgbe_channel *channel;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500900 unsigned int tx_max_channel_count;
901 unsigned int rx_max_channel_count;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500902 unsigned int channel_count;
903 unsigned int tx_ring_count;
904 unsigned int tx_desc_count;
905 unsigned int rx_ring_count;
906 unsigned int rx_desc_count;
907
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500908 unsigned int tx_max_q_count;
909 unsigned int rx_max_q_count;
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500910 unsigned int tx_q_count;
911 unsigned int rx_q_count;
912
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500913 /* Tx/Rx common settings */
914 unsigned int pblx8;
915
916 /* Tx settings */
917 unsigned int tx_sf_mode;
918 unsigned int tx_threshold;
919 unsigned int tx_pbl;
920 unsigned int tx_osp_mode;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500921 unsigned int tx_max_fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500922
923 /* Rx settings */
924 unsigned int rx_sf_mode;
925 unsigned int rx_threshold;
926 unsigned int rx_pbl;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500927 unsigned int rx_max_fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500928
929 /* Tx coalescing settings */
930 unsigned int tx_usecs;
931 unsigned int tx_frames;
932
933 /* Rx coalescing settings */
934 unsigned int rx_riwt;
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500935 unsigned int rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500936 unsigned int rx_frames;
937
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600938 /* Current Rx buffer size */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500939 unsigned int rx_buf_size;
940
941 /* Flow control settings */
942 unsigned int pause_autoneg;
943 unsigned int tx_pause;
944 unsigned int rx_pause;
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500945 unsigned int rx_rfa[XGBE_MAX_QUEUES];
946 unsigned int rx_rfd[XGBE_MAX_QUEUES];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500947
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600948 /* Receive Side Scaling settings */
949 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
950 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
951 u32 rss_options;
952
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500953 /* Netdev related settings */
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600954 unsigned char mac_addr[ETH_ALEN];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500955 netdev_features_t netdev_features;
956 struct napi_struct napi;
957 struct xgbe_mmc_stats mmc_stats;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500958 struct xgbe_ext_stats ext_stats;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500959
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500960 /* Filtering support */
961 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
962
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500963 /* Device clocks */
964 struct clk *sysclk;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600965 unsigned long sysclk_rate;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500966 struct clk *ptpclk;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600967 unsigned long ptpclk_rate;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500968
969 /* Timestamp support */
970 spinlock_t tstamp_lock;
971 struct ptp_clock_info ptp_clock_info;
972 struct ptp_clock *ptp_clock;
973 struct hwtstamp_config tstamp_config;
974 struct cyclecounter tstamp_cc;
975 struct timecounter tstamp_tc;
976 unsigned int tstamp_addend;
977 struct work_struct tx_tstamp_work;
978 struct sk_buff *tx_tstamp_skb;
979 u64 tx_tstamp;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500980
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500981 /* DCB support */
982 struct ieee_ets *ets;
983 struct ieee_pfc *pfc;
984 unsigned int q2tc_map[XGBE_MAX_QUEUES];
985 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500986 unsigned int pfcq[XGBE_MAX_QUEUES];
987 unsigned int pfc_rfa;
Lendacky, Thomasb3b71592016-02-17 11:49:08 -0600988 u8 num_tcs;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500989
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500990 /* Hardware features of the device */
991 struct xgbe_hw_features hw_feat;
992
993 /* Device restart work structure */
994 struct work_struct restart_work;
995
996 /* Keeps track of power mode */
997 unsigned int power_down;
998
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500999 /* Network interface message level setting */
1000 u32 msg_enable;
1001
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001002 /* Current PHY settings */
1003 phy_interface_t phy_mode;
1004 int phy_link;
1005 int phy_speed;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001006
1007 /* MDIO/PHY related settings */
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05001008 unsigned int phy_started;
1009 void *phy_data;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001010 struct xgbe_phy phy;
1011 int mdio_mmd;
1012 unsigned long link_check;
1013
1014 char an_name[IFNAMSIZ + 32];
1015 struct workqueue_struct *an_workqueue;
1016
1017 int an_irq;
1018 struct work_struct an_irq_work;
1019
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001020 /* Auto-negotiation state machine support */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06001021 unsigned int an_int;
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -05001022 unsigned int an_status;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001023 struct mutex an_mutex;
1024 enum xgbe_an an_result;
1025 enum xgbe_an an_state;
1026 enum xgbe_rx kr_state;
1027 enum xgbe_rx kx_state;
1028 struct work_struct an_work;
1029 unsigned int an_supported;
1030 unsigned int parallel_detect;
1031 unsigned int fec_ability;
1032 unsigned long an_start;
Lendacky, Thomasa64def42016-11-03 13:18:38 -05001033 enum xgbe_an_mode an_mode;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001034
1035 unsigned int lpm_ctrl; /* CTRL1 for resume */
1036
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001037#ifdef CONFIG_DEBUG_FS
1038 struct dentry *xgbe_debugfs;
1039
1040 unsigned int debugfs_xgmac_reg;
1041
1042 unsigned int debugfs_xpcs_mmd;
1043 unsigned int debugfs_xpcs_reg;
Lendacky, Thomas47f164d2016-11-10 17:09:55 -06001044
1045 unsigned int debugfs_xprop_reg;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001046#endif
1047};
1048
1049/* Function prototypes*/
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05001050struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
1051void xgbe_free_pdata(struct xgbe_prv_data *);
1052void xgbe_set_counts(struct xgbe_prv_data *);
1053int xgbe_config_netdev(struct xgbe_prv_data *);
1054void xgbe_deconfig_netdev(struct xgbe_prv_data *);
1055
1056int xgbe_platform_init(void);
1057void xgbe_platform_exit(void);
Lendacky, Thomas47f164d2016-11-10 17:09:55 -06001058#ifdef CONFIG_PCI
1059int xgbe_pci_init(void);
1060void xgbe_pci_exit(void);
1061#else
1062static inline int xgbe_pci_init(void) { return 0; }
1063static inline void xgbe_pci_exit(void) { }
1064#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001065
1066void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001067void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05001068void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
Lendacky, Thomas47f164d2016-11-10 17:09:55 -06001069void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001070void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
stephen hemmingerce0b15d2016-08-31 08:57:36 -07001071const struct net_device_ops *xgbe_get_netdev_ops(void);
1072const struct ethtool_ops *xgbe_get_ethtool_ops(void);
1073
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001074#ifdef CONFIG_AMD_XGBE_DCB
1075const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
1076#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001077
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001078void xgbe_ptp_register(struct xgbe_prv_data *);
1079void xgbe_ptp_unregister(struct xgbe_prv_data *);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001080void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1081 unsigned int, unsigned int, unsigned int);
1082void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001083 unsigned int);
1084void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
1085void xgbe_get_all_hw_features(struct xgbe_prv_data *);
1086int xgbe_powerup(struct net_device *, unsigned int);
1087int xgbe_powerdown(struct net_device *, unsigned int);
1088void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
1089void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
1090
1091#ifdef CONFIG_DEBUG_FS
1092void xgbe_debugfs_init(struct xgbe_prv_data *);
1093void xgbe_debugfs_exit(struct xgbe_prv_data *);
1094#else
1095static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
1096static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
1097#endif /* CONFIG_DEBUG_FS */
1098
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001099/* NOTE: Uncomment for function trace log messages in KERNEL LOG */
1100#if 0
1101#define YDEBUG
1102#define YDEBUG_MDIO
1103#endif
1104
1105/* For debug prints */
1106#ifdef YDEBUG
1107#define DBGPR(x...) pr_alert(x)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001108#else
1109#define DBGPR(x...) do { } while (0)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001110#endif
1111
1112#ifdef YDEBUG_MDIO
1113#define DBGPR_MDIO(x...) pr_alert(x)
1114#else
1115#define DBGPR_MDIO(x...) do { } while (0)
1116#endif
1117
1118#endif