blob: 0779247057fb3dc369bc4301142d091941e4be70 [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
174#define XGBE_DMA_INTERRUPT_MASK 0x31c7
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500175
176#define XGMAC_MIN_PACKET 60
177#define XGMAC_STD_PACKET_MTU 1500
178#define XGMAC_MAX_STD_PACKET 1518
179#define XGMAC_JUMBO_PACKET_MTU 9000
180#define XGMAC_MAX_JUMBO_PACKET 9018
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500181#define XGMAC_ETH_PREAMBLE (12 + 8) /* Inter-frame gap + preamble */
182
183#define XGMAC_PFC_DATA_LEN 46
184#define XGMAC_PFC_DELAYS 14000
185
186#define XGMAC_PRIO_QUEUES(_cnt) \
187 min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500188
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600189/* Common property names */
190#define XGBE_MAC_ADDR_PROPERTY "mac-address"
191#define XGBE_PHY_MODE_PROPERTY "phy-mode"
192#define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500193#define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600194
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500195/* Device-tree clock names */
196#define XGBE_DMA_CLOCK "dma_clk"
197#define XGBE_PTP_CLOCK "ptp_clk"
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600198
199/* ACPI property names */
200#define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
201#define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500202
203/* Timestamp support - values based on 50MHz PTP clock
204 * 50MHz => 20 nsec
205 */
206#define XGBE_TSTAMP_SSINC 20
207#define XGBE_TSTAMP_SNSINC 0
208
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500209/* Driver PMT macros */
210#define XGMAC_DRIVER_CONTEXT 1
211#define XGMAC_IOCTL_CONTEXT 2
212
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500213#define XGMAC_FIFO_MIN_ALLOC 2048
214#define XGMAC_FIFO_UNIT 256
215#define XGMAC_FIFO_ALIGN(_x) \
216 (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
217#define XGMAC_FIFO_FC_OFF 2048
218#define XGMAC_FIFO_FC_MIN 4096
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500219
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500220#define XGBE_TC_MIN_QUANTUM 10
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500221
222/* Helper macro for descriptor handling
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500223 * Always use XGBE_GET_DESC_DATA to access the descriptor data
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500224 * since the index is free-running and needs to be and-ed
225 * with the descriptor count value of the ring to index to
226 * the proper descriptor data.
227 */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500228#define XGBE_GET_DESC_DATA(_ring, _idx) \
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500229 ((_ring)->rdata + \
230 ((_idx) & ((_ring)->rdesc_count - 1)))
231
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500232/* Default coalescing parameters */
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500233#define XGMAC_INIT_DMA_TX_USECS 1000
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500234#define XGMAC_INIT_DMA_TX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500235
236#define XGMAC_MAX_DMA_RIWT 0xff
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500237#define XGMAC_INIT_DMA_RX_USECS 30
238#define XGMAC_INIT_DMA_RX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500239
240/* Flow control queue count */
241#define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
242
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500243/* Flow control threshold units */
244#define XGMAC_FLOW_CONTROL_UNIT 512
245#define XGMAC_FLOW_CONTROL_ALIGN(_x) \
246 (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
247#define XGMAC_FLOW_CONTROL_VALUE(_x) \
248 (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
249#define XGMAC_FLOW_CONTROL_MAX 33280
250
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500251/* Maximum MAC address hash table size (256 bits = 8 bytes) */
252#define XGBE_MAC_HASH_TABLE_SIZE 8
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500253
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600254/* Receive Side Scaling */
255#define XGBE_RSS_HASH_KEY_SIZE 40
256#define XGBE_RSS_MAX_TABLE_SIZE 256
257#define XGBE_RSS_LOOKUP_TABLE_TYPE 0
258#define XGBE_RSS_HASH_KEY_TYPE 1
259
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500260/* Auto-negotiation */
261#define XGBE_AN_MS_TIMEOUT 500
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -0500262#define XGBE_LINK_TIMEOUT 5
263
264#define XGBE_SGMII_AN_LINK_STATUS BIT(1)
265#define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
266#define XGBE_SGMII_AN_LINK_SPEED_100 0x04
267#define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
268#define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500269
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500270struct xgbe_prv_data;
271
272struct xgbe_packet_data {
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600273 struct sk_buff *skb;
274
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500275 unsigned int attributes;
276
277 unsigned int errors;
278
279 unsigned int rdesc_count;
280 unsigned int length;
281
282 unsigned int header_len;
283 unsigned int tcp_header_len;
284 unsigned int tcp_payload_len;
285 unsigned short mss;
286
287 unsigned short vlan_ctag;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500288
289 u64 rx_tstamp;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600290
291 u32 rss_hash;
292 enum pkt_hash_types rss_hash_type;
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -0600293
294 unsigned int tx_packets;
295 unsigned int tx_bytes;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500296};
297
298/* Common Rx and Tx descriptor mapping */
299struct xgbe_ring_desc {
Lendacky, Thomas5226cfc2014-11-12 10:37:49 -0600300 __le32 desc0;
301 __le32 desc1;
302 __le32 desc2;
303 __le32 desc3;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500304};
305
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600306/* Page allocation related values */
307struct xgbe_page_alloc {
308 struct page *pages;
309 unsigned int pages_len;
310 unsigned int pages_offset;
311
312 dma_addr_t pages_dma;
313};
314
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600315/* Ring entry buffer data */
316struct xgbe_buffer_data {
317 struct xgbe_page_alloc pa;
318 struct xgbe_page_alloc pa_unmap;
319
Lendacky, Thomascfbfd862015-07-06 11:57:37 -0500320 dma_addr_t dma_base;
321 unsigned long dma_off;
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600322 unsigned int dma_len;
323};
324
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600325/* Tx-related ring data */
326struct xgbe_tx_ring_data {
Lendacky, Thomas5fb4b862014-11-20 11:03:50 -0600327 unsigned int packets; /* BQL packet count */
328 unsigned int bytes; /* BQL byte count */
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600329};
330
331/* Rx-related ring data */
332struct xgbe_rx_ring_data {
333 struct xgbe_buffer_data hdr; /* Header locations */
334 struct xgbe_buffer_data buf; /* Payload locations */
335
336 unsigned short hdr_len; /* Length of received header */
337 unsigned short len; /* Length of received packet */
338};
339
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500340/* Structure used to hold information related to the descriptor
341 * and the packet associated with the descriptor (always use
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500342 * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500343 */
344struct xgbe_ring_data {
345 struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
346 dma_addr_t rdesc_dma; /* DMA address of descriptor */
347
348 struct sk_buff *skb; /* Virtual address of SKB */
349 dma_addr_t skb_dma; /* DMA address of SKB data */
350 unsigned int skb_dma_len; /* Length of SKB DMA area */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500351
Lendacky, Thomasc9f140e2014-11-20 11:03:44 -0600352 struct xgbe_tx_ring_data tx; /* Tx-related data */
353 struct xgbe_rx_ring_data rx; /* Rx-related data */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500354
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500355 unsigned int mapped_as_page;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500356
357 /* Incomplete receive save location. If the budget is exhausted
358 * or the last descriptor (last normal descriptor or a following
359 * context descriptor) has not been DMA'd yet the current state
360 * of the receive processing needs to be saved.
361 */
362 unsigned int state_saved;
363 struct {
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500364 struct sk_buff *skb;
365 unsigned int len;
366 unsigned int error;
367 } state;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500368};
369
370struct xgbe_ring {
371 /* Ring lock - used just for TX rings at the moment */
372 spinlock_t lock;
373
374 /* Per packet related information */
375 struct xgbe_packet_data packet_data;
376
377 /* Virtual/DMA addresses and count of allocated descriptor memory */
378 struct xgbe_ring_desc *rdesc;
379 dma_addr_t rdesc_dma;
380 unsigned int rdesc_count;
381
382 /* Array of descriptor data corresponding the descriptor memory
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500383 * (always use the XGBE_GET_DESC_DATA macro to access this data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500384 */
385 struct xgbe_ring_data *rdata;
386
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600387 /* Page allocation for RX buffers */
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600388 struct xgbe_page_alloc rx_hdr_pa;
389 struct xgbe_page_alloc rx_buf_pa;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600390
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500391 /* Ring index values
392 * cur - Tx: index of descriptor to be used for current transfer
393 * Rx: index of descriptor to check for packet availability
394 * dirty - Tx: index of descriptor to check for transfer complete
Lendacky, Thomas270894e2015-01-16 12:46:50 -0600395 * Rx: index of descriptor to check for buffer reallocation
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500396 */
397 unsigned int cur;
398 unsigned int dirty;
399
400 /* Coalesce frame count used for interrupt bit setting */
401 unsigned int coalesce_count;
402
403 union {
404 struct {
405 unsigned int queue_stopped;
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600406 unsigned int xmit_more;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500407 unsigned short cur_mss;
408 unsigned short cur_vlan_ctag;
409 } tx;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500410 };
411} ____cacheline_aligned;
412
413/* Structure used to describe the descriptor rings associated with
414 * a DMA channel.
415 */
416struct xgbe_channel {
417 char name[16];
418
419 /* Address of private data area for device */
420 struct xgbe_prv_data *pdata;
421
422 /* Queue index and base address of queue's DMA registers */
423 unsigned int queue_index;
424 void __iomem *dma_regs;
425
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600426 /* Per channel interrupt irq number */
427 int dma_irq;
Lendacky, Thomas54ceb9e2014-12-02 18:07:18 -0600428 char dma_irq_name[IFNAMSIZ + 32];
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600429
430 /* Netdev related settings */
431 struct napi_struct napi;
432
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500433 unsigned int saved_ier;
434
435 unsigned int tx_timer_active;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500436 struct timer_list tx_timer;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500437
438 struct xgbe_ring *tx_ring;
439 struct xgbe_ring *rx_ring;
440} ____cacheline_aligned;
441
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500442enum xgbe_state {
443 XGBE_DOWN,
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500444 XGBE_LINK_INIT,
445 XGBE_LINK_ERR,
446};
447
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500448enum xgbe_int {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500449 XGMAC_INT_DMA_CH_SR_TI,
450 XGMAC_INT_DMA_CH_SR_TPS,
451 XGMAC_INT_DMA_CH_SR_TBU,
452 XGMAC_INT_DMA_CH_SR_RI,
453 XGMAC_INT_DMA_CH_SR_RBU,
454 XGMAC_INT_DMA_CH_SR_RPS,
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500455 XGMAC_INT_DMA_CH_SR_TI_RI,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500456 XGMAC_INT_DMA_CH_SR_FBE,
457 XGMAC_INT_DMA_ALL,
458};
459
460enum xgbe_int_state {
461 XGMAC_INT_STATE_SAVE,
462 XGMAC_INT_STATE_RESTORE,
463};
464
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500465enum xgbe_speed {
466 XGBE_SPEED_1000 = 0,
467 XGBE_SPEED_2500,
468 XGBE_SPEED_10000,
469 XGBE_SPEEDS,
470};
471
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500472enum xgbe_xpcs_access {
473 XGBE_XPCS_ACCESS_V1 = 0,
474 XGBE_XPCS_ACCESS_V2,
475};
476
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500477enum xgbe_an_mode {
478 XGBE_AN_MODE_CL73 = 0,
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -0500479 XGBE_AN_MODE_CL37,
480 XGBE_AN_MODE_CL37_SGMII,
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500481 XGBE_AN_MODE_NONE,
482};
483
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500484enum xgbe_an {
485 XGBE_AN_READY = 0,
486 XGBE_AN_PAGE_RECEIVED,
487 XGBE_AN_INCOMPAT_LINK,
488 XGBE_AN_COMPLETE,
489 XGBE_AN_NO_LINK,
490 XGBE_AN_ERROR,
491};
492
493enum xgbe_rx {
494 XGBE_RX_BPA = 0,
495 XGBE_RX_XNP,
496 XGBE_RX_COMPLETE,
497 XGBE_RX_ERROR,
498};
499
500enum xgbe_mode {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500501 XGBE_MODE_KX_1000 = 0,
502 XGBE_MODE_KX_2500,
503 XGBE_MODE_KR,
504 XGBE_MODE_UNKNOWN,
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500505};
506
507enum xgbe_speedset {
508 XGBE_SPEEDSET_1000_10000 = 0,
509 XGBE_SPEEDSET_2500_10000,
510};
511
512struct xgbe_phy {
513 u32 supported;
514 u32 advertising;
515 u32 lp_advertising;
516
517 int address;
518
519 int autoneg;
520 int speed;
521 int duplex;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500522
523 int link;
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500524
525 int pause_autoneg;
526 int tx_pause;
527 int rx_pause;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500528};
529
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500530struct xgbe_mmc_stats {
531 /* Tx Stats */
532 u64 txoctetcount_gb;
533 u64 txframecount_gb;
534 u64 txbroadcastframes_g;
535 u64 txmulticastframes_g;
536 u64 tx64octets_gb;
537 u64 tx65to127octets_gb;
538 u64 tx128to255octets_gb;
539 u64 tx256to511octets_gb;
540 u64 tx512to1023octets_gb;
541 u64 tx1024tomaxoctets_gb;
542 u64 txunicastframes_gb;
543 u64 txmulticastframes_gb;
544 u64 txbroadcastframes_gb;
545 u64 txunderflowerror;
546 u64 txoctetcount_g;
547 u64 txframecount_g;
548 u64 txpauseframes;
549 u64 txvlanframes_g;
550
551 /* Rx Stats */
552 u64 rxframecount_gb;
553 u64 rxoctetcount_gb;
554 u64 rxoctetcount_g;
555 u64 rxbroadcastframes_g;
556 u64 rxmulticastframes_g;
557 u64 rxcrcerror;
558 u64 rxrunterror;
559 u64 rxjabbererror;
560 u64 rxundersize_g;
561 u64 rxoversize_g;
562 u64 rx64octets_gb;
563 u64 rx65to127octets_gb;
564 u64 rx128to255octets_gb;
565 u64 rx256to511octets_gb;
566 u64 rx512to1023octets_gb;
567 u64 rx1024tomaxoctets_gb;
568 u64 rxunicastframes_g;
569 u64 rxlengtherror;
570 u64 rxoutofrangetype;
571 u64 rxpauseframes;
572 u64 rxfifooverflow;
573 u64 rxvlanframes_gb;
574 u64 rxwatchdogerror;
575};
576
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500577struct xgbe_ext_stats {
578 u64 tx_tso_packets;
579 u64 rx_split_header_packets;
Lendacky, Thomas72c9ac42015-09-30 08:53:10 -0500580 u64 rx_buffer_unavailable;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500581};
582
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500583struct xgbe_hw_if {
584 int (*tx_complete)(struct xgbe_ring_desc *);
585
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500586 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
Lendacky, Thomasb8763822015-04-09 12:11:57 -0500587 int (*config_rx_mode)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500588
589 int (*enable_rx_csum)(struct xgbe_prv_data *);
590 int (*disable_rx_csum)(struct xgbe_prv_data *);
591
592 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
593 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500594 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
595 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
596 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500597
598 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
599 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500600 int (*set_speed)(struct xgbe_prv_data *, int);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500601
602 void (*enable_tx)(struct xgbe_prv_data *);
603 void (*disable_tx)(struct xgbe_prv_data *);
604 void (*enable_rx)(struct xgbe_prv_data *);
605 void (*disable_rx)(struct xgbe_prv_data *);
606
607 void (*powerup_tx)(struct xgbe_prv_data *);
608 void (*powerdown_tx)(struct xgbe_prv_data *);
609 void (*powerup_rx)(struct xgbe_prv_data *);
610 void (*powerdown_rx)(struct xgbe_prv_data *);
611
612 int (*init)(struct xgbe_prv_data *);
613 int (*exit)(struct xgbe_prv_data *);
614
615 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
616 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
Lendacky, Thomasa9d41982014-11-04 16:06:32 -0600617 void (*dev_xmit)(struct xgbe_channel *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500618 int (*dev_read)(struct xgbe_channel *);
619 void (*tx_desc_init)(struct xgbe_channel *);
620 void (*rx_desc_init)(struct xgbe_channel *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500621 void (*tx_desc_reset)(struct xgbe_ring_data *);
Lendacky, Thomas8dee19e2015-04-09 12:11:51 -0500622 void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
623 unsigned int);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500624 int (*is_last_desc)(struct xgbe_ring_desc *);
625 int (*is_context_desc)(struct xgbe_ring_desc *);
Lendacky, Thomas16958a22014-11-20 11:04:08 -0600626 void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500627
628 /* For FLOW ctrl */
629 int (*config_tx_flow_control)(struct xgbe_prv_data *);
630 int (*config_rx_flow_control)(struct xgbe_prv_data *);
631
632 /* For RX coalescing */
633 int (*config_rx_coalesce)(struct xgbe_prv_data *);
634 int (*config_tx_coalesce)(struct xgbe_prv_data *);
635 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
636 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
637
638 /* For RX and TX threshold config */
639 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
640 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
641
642 /* For RX and TX Store and Forward Mode config */
643 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
644 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
645
646 /* For TX DMA Operate on Second Frame config */
647 int (*config_osp_mode)(struct xgbe_prv_data *);
648
649 /* For RX and TX PBL config */
650 int (*config_rx_pbl_val)(struct xgbe_prv_data *);
651 int (*get_rx_pbl_val)(struct xgbe_prv_data *);
652 int (*config_tx_pbl_val)(struct xgbe_prv_data *);
653 int (*get_tx_pbl_val)(struct xgbe_prv_data *);
654 int (*config_pblx8)(struct xgbe_prv_data *);
655
656 /* For MMC statistics */
657 void (*rx_mmc_int)(struct xgbe_prv_data *);
658 void (*tx_mmc_int)(struct xgbe_prv_data *);
659 void (*read_mmc_stats)(struct xgbe_prv_data *);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500660
661 /* For Timestamp config */
662 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
663 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
664 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
665 unsigned int nsec);
666 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
667 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500668
669 /* For Data Center Bridging config */
Lendacky, Thomasb3b71592016-02-17 11:49:08 -0600670 void (*config_tc)(struct xgbe_prv_data *);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500671 void (*config_dcb_tc)(struct xgbe_prv_data *);
672 void (*config_dcb_pfc)(struct xgbe_prv_data *);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600673
674 /* For Receive Side Scaling */
675 int (*enable_rss)(struct xgbe_prv_data *);
676 int (*disable_rss)(struct xgbe_prv_data *);
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600677 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
678 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500679};
680
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500681/* This structure represents implementation specific routines for an
682 * implementation of a PHY. All routines are required unless noted below.
683 * Optional routines:
684 * kr_training_pre, kr_training_post
685 */
686struct xgbe_phy_impl_if {
687 /* Perform Setup/teardown actions */
688 int (*init)(struct xgbe_prv_data *);
689 void (*exit)(struct xgbe_prv_data *);
690
691 /* Perform start/stop specific actions */
692 int (*reset)(struct xgbe_prv_data *);
693 int (*start)(struct xgbe_prv_data *);
694 void (*stop)(struct xgbe_prv_data *);
695
696 /* Return the link status */
697 int (*link_status)(struct xgbe_prv_data *);
698
699 /* Indicate if a particular speed is valid */
700 bool (*valid_speed)(struct xgbe_prv_data *, int);
701
702 /* Check if the specified mode can/should be used */
703 bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
704 /* Switch the PHY into various modes */
705 void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
706 /* Retrieve mode needed for a specific speed */
707 enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
708 /* Retrieve new/next mode when trying to auto-negotiate */
709 enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
710 /* Retrieve current mode */
711 enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
712
Lendacky, Thomasa64def42016-11-03 13:18:38 -0500713 /* Retrieve current auto-negotiation mode */
714 enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
715
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500716 /* Process results of auto-negotiation */
717 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
718
719 /* Pre/Post KR training enablement support */
720 void (*kr_training_pre)(struct xgbe_prv_data *);
721 void (*kr_training_post)(struct xgbe_prv_data *);
722};
723
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500724struct xgbe_phy_if {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500725 /* For PHY setup/teardown */
726 int (*phy_init)(struct xgbe_prv_data *);
727 void (*phy_exit)(struct xgbe_prv_data *);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500728
729 /* For PHY support when setting device up/down */
730 int (*phy_reset)(struct xgbe_prv_data *);
731 int (*phy_start)(struct xgbe_prv_data *);
732 void (*phy_stop)(struct xgbe_prv_data *);
733
734 /* For PHY support while device is up */
735 void (*phy_status)(struct xgbe_prv_data *);
736 int (*phy_config_aneg)(struct xgbe_prv_data *);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500737
738 /* For PHY settings validation */
739 bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
740
741 /* PHY implementation specific services */
742 struct xgbe_phy_impl_if phy_impl;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500743};
744
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500745struct xgbe_desc_if {
746 int (*alloc_ring_resources)(struct xgbe_prv_data *);
747 void (*free_ring_resources)(struct xgbe_prv_data *);
748 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
Lendacky, Thomas270894e2015-01-16 12:46:50 -0600749 int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
750 struct xgbe_ring_data *);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600751 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500752 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
753 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
754};
755
756/* This structure contains flags that indicate what hardware features
757 * or configurations are present in the device.
758 */
759struct xgbe_hw_features {
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500760 /* HW Version */
761 unsigned int version;
762
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500763 /* HW Feature Register0 */
764 unsigned int gmii; /* 1000 Mbps support */
765 unsigned int vlhash; /* VLAN Hash Filter */
766 unsigned int sma; /* SMA(MDIO) Interface */
767 unsigned int rwk; /* PMT remote wake-up packet */
768 unsigned int mgk; /* PMT magic packet */
769 unsigned int mmc; /* RMON module */
770 unsigned int aoe; /* ARP Offload */
Joe Perchesdbedd442015-03-06 20:49:12 -0800771 unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500772 unsigned int eee; /* Energy Efficient Ethernet */
773 unsigned int tx_coe; /* Tx Checksum Offload */
774 unsigned int rx_coe; /* Rx Checksum Offload */
775 unsigned int addn_mac; /* Additional MAC Addresses */
776 unsigned int ts_src; /* Timestamp Source */
777 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
778
779 /* HW Feature Register1 */
780 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
781 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
782 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500783 unsigned int dma_width; /* DMA width */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500784 unsigned int dcb; /* DCB Feature */
785 unsigned int sph; /* Split Header Feature */
786 unsigned int tso; /* TCP Segmentation Offload */
787 unsigned int dma_debug; /* DMA Debug Registers */
788 unsigned int rss; /* Receive Side Scaling */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500789 unsigned int tc_cnt; /* Number of Traffic Classes */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500790 unsigned int hash_table_size; /* Hash Table Size */
791 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
792
793 /* HW Feature Register2 */
794 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
795 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
796 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
797 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
798 unsigned int pps_out_num; /* Number of PPS outputs */
799 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
800};
801
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500802struct xgbe_version_data {
803 void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500804 enum xgbe_xpcs_access xpcs_access;
Lendacky, Thomase5a20b92016-11-03 13:19:07 -0500805 unsigned int mmc_64bit;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500806 unsigned int tx_max_fifo_size;
807 unsigned int rx_max_fifo_size;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500808};
809
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500810struct xgbe_prv_data {
811 struct net_device *netdev;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500812 struct platform_device *platdev;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600813 struct acpi_device *adev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500814 struct device *dev;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500815 struct platform_device *phy_platdev;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500816 struct device *phy_dev;
817
818 /* Version related data */
819 struct xgbe_version_data *vdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500820
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600821 /* ACPI or DT flag */
822 unsigned int use_acpi;
823
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500824 /* XGMAC/XPCS related mmio registers */
825 void __iomem *xgmac_regs; /* XGMAC CSRs */
826 void __iomem *xpcs_regs; /* XPCS MMD registers */
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500827 void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
828 void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
829 void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500830
831 /* Overall device lock */
832 spinlock_t lock;
833
Lendacky, Thomasced3fca2016-02-17 11:49:28 -0600834 /* XPCS indirect addressing lock */
835 spinlock_t xpcs_lock;
Lendacky, Thomasb03a4a62016-11-03 13:18:56 -0500836 unsigned int xpcs_window;
837 unsigned int xpcs_window_size;
838 unsigned int xpcs_window_mask;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500839
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600840 /* RSS addressing mutex */
841 struct mutex rss_mutex;
842
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500843 /* Flags representing xgbe_state */
844 unsigned long dev_state;
845
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600846 int dev_irq;
847 unsigned int per_channel_irq;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500848 int channel_irq[XGBE_MAX_DMA_CHANNELS];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500849
850 struct xgbe_hw_if hw_if;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500851 struct xgbe_phy_if phy_if;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500852 struct xgbe_desc_if desc_if;
853
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500854 /* AXI DMA settings */
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600855 unsigned int coherent;
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500856 unsigned int axdomain;
857 unsigned int arcache;
858 unsigned int awcache;
859
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500860 /* Service routine support */
861 struct workqueue_struct *dev_workqueue;
862 struct work_struct service_work;
863 struct timer_list service_timer;
864
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500865 /* Rings for Tx/Rx on a DMA channel */
866 struct xgbe_channel *channel;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500867 unsigned int tx_max_channel_count;
868 unsigned int rx_max_channel_count;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500869 unsigned int channel_count;
870 unsigned int tx_ring_count;
871 unsigned int tx_desc_count;
872 unsigned int rx_ring_count;
873 unsigned int rx_desc_count;
874
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500875 unsigned int tx_max_q_count;
876 unsigned int rx_max_q_count;
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500877 unsigned int tx_q_count;
878 unsigned int rx_q_count;
879
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500880 /* Tx/Rx common settings */
881 unsigned int pblx8;
882
883 /* Tx settings */
884 unsigned int tx_sf_mode;
885 unsigned int tx_threshold;
886 unsigned int tx_pbl;
887 unsigned int tx_osp_mode;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500888 unsigned int tx_max_fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500889
890 /* Rx settings */
891 unsigned int rx_sf_mode;
892 unsigned int rx_threshold;
893 unsigned int rx_pbl;
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500894 unsigned int rx_max_fifo_size;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500895
896 /* Tx coalescing settings */
897 unsigned int tx_usecs;
898 unsigned int tx_frames;
899
900 /* Rx coalescing settings */
901 unsigned int rx_riwt;
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500902 unsigned int rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500903 unsigned int rx_frames;
904
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600905 /* Current Rx buffer size */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500906 unsigned int rx_buf_size;
907
908 /* Flow control settings */
909 unsigned int pause_autoneg;
910 unsigned int tx_pause;
911 unsigned int rx_pause;
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500912 unsigned int rx_rfa[XGBE_MAX_QUEUES];
913 unsigned int rx_rfd[XGBE_MAX_QUEUES];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500914
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600915 /* Receive Side Scaling settings */
916 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
917 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
918 u32 rss_options;
919
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500920 /* Netdev related settings */
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600921 unsigned char mac_addr[ETH_ALEN];
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500922 netdev_features_t netdev_features;
923 struct napi_struct napi;
924 struct xgbe_mmc_stats mmc_stats;
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500925 struct xgbe_ext_stats ext_stats;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500926
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500927 /* Filtering support */
928 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
929
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500930 /* Device clocks */
931 struct clk *sysclk;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600932 unsigned long sysclk_rate;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500933 struct clk *ptpclk;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600934 unsigned long ptpclk_rate;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500935
936 /* Timestamp support */
937 spinlock_t tstamp_lock;
938 struct ptp_clock_info ptp_clock_info;
939 struct ptp_clock *ptp_clock;
940 struct hwtstamp_config tstamp_config;
941 struct cyclecounter tstamp_cc;
942 struct timecounter tstamp_tc;
943 unsigned int tstamp_addend;
944 struct work_struct tx_tstamp_work;
945 struct sk_buff *tx_tstamp_skb;
946 u64 tx_tstamp;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500947
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500948 /* DCB support */
949 struct ieee_ets *ets;
950 struct ieee_pfc *pfc;
951 unsigned int q2tc_map[XGBE_MAX_QUEUES];
952 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
Lendacky, Thomas43e0dcf2016-11-03 13:18:16 -0500953 unsigned int pfcq[XGBE_MAX_QUEUES];
954 unsigned int pfc_rfa;
Lendacky, Thomasb3b71592016-02-17 11:49:08 -0600955 u8 num_tcs;
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500956
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500957 /* Hardware features of the device */
958 struct xgbe_hw_features hw_feat;
959
960 /* Device restart work structure */
961 struct work_struct restart_work;
962
963 /* Keeps track of power mode */
964 unsigned int power_down;
965
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500966 /* Network interface message level setting */
967 u32 msg_enable;
968
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500969 /* Current PHY settings */
970 phy_interface_t phy_mode;
971 int phy_link;
972 int phy_speed;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500973
974 /* MDIO/PHY related settings */
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500975 unsigned int phy_started;
976 void *phy_data;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500977 struct xgbe_phy phy;
978 int mdio_mmd;
979 unsigned long link_check;
980
981 char an_name[IFNAMSIZ + 32];
982 struct workqueue_struct *an_workqueue;
983
984 int an_irq;
985 struct work_struct an_irq_work;
986
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500987 /* Auto-negotiation state machine support */
Lendacky, Thomasced3fca2016-02-17 11:49:28 -0600988 unsigned int an_int;
Lendacky, Thomas1bf40ad2016-11-03 13:18:47 -0500989 unsigned int an_status;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500990 struct mutex an_mutex;
991 enum xgbe_an an_result;
992 enum xgbe_an an_state;
993 enum xgbe_rx kr_state;
994 enum xgbe_rx kx_state;
995 struct work_struct an_work;
996 unsigned int an_supported;
997 unsigned int parallel_detect;
998 unsigned int fec_ability;
999 unsigned long an_start;
Lendacky, Thomasa64def42016-11-03 13:18:38 -05001000 enum xgbe_an_mode an_mode;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001001
1002 unsigned int lpm_ctrl; /* CTRL1 for resume */
1003
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001004#ifdef CONFIG_DEBUG_FS
1005 struct dentry *xgbe_debugfs;
1006
1007 unsigned int debugfs_xgmac_reg;
1008
1009 unsigned int debugfs_xpcs_mmd;
1010 unsigned int debugfs_xpcs_reg;
1011#endif
1012};
1013
1014/* Function prototypes*/
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -05001015struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
1016void xgbe_free_pdata(struct xgbe_prv_data *);
1017void xgbe_set_counts(struct xgbe_prv_data *);
1018int xgbe_config_netdev(struct xgbe_prv_data *);
1019void xgbe_deconfig_netdev(struct xgbe_prv_data *);
1020
1021int xgbe_platform_init(void);
1022void xgbe_platform_exit(void);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001023
1024void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -05001025void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -05001026void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001027void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
stephen hemmingerce0b15d2016-08-31 08:57:36 -07001028const struct net_device_ops *xgbe_get_netdev_ops(void);
1029const struct ethtool_ops *xgbe_get_ethtool_ops(void);
1030
Lendacky, Thomasfca2d992014-07-29 08:57:55 -05001031#ifdef CONFIG_AMD_XGBE_DCB
1032const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
1033#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001034
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -05001035void xgbe_ptp_register(struct xgbe_prv_data *);
1036void xgbe_ptp_unregister(struct xgbe_prv_data *);
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -05001037void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1038 unsigned int, unsigned int, unsigned int);
1039void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001040 unsigned int);
1041void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
1042void xgbe_get_all_hw_features(struct xgbe_prv_data *);
1043int xgbe_powerup(struct net_device *, unsigned int);
1044int xgbe_powerdown(struct net_device *, unsigned int);
1045void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
1046void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
1047
1048#ifdef CONFIG_DEBUG_FS
1049void xgbe_debugfs_init(struct xgbe_prv_data *);
1050void xgbe_debugfs_exit(struct xgbe_prv_data *);
1051#else
1052static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
1053static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
1054#endif /* CONFIG_DEBUG_FS */
1055
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001056/* NOTE: Uncomment for function trace log messages in KERNEL LOG */
1057#if 0
1058#define YDEBUG
1059#define YDEBUG_MDIO
1060#endif
1061
1062/* For debug prints */
1063#ifdef YDEBUG
1064#define DBGPR(x...) pr_alert(x)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001065#else
1066#define DBGPR(x...) do { } while (0)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001067#endif
1068
1069#ifdef YDEBUG_MDIO
1070#define DBGPR_MDIO(x...) pr_alert(x)
1071#else
1072#define DBGPR_MDIO(x...) do { } while (0)
1073#endif
1074
1075#endif