]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/net/ethernet/amd/xgbe/xgbe.h
Revert "dev: set iflink to 0 for virtual interfaces"
[thirdparty/kernel/stable.git] / drivers / net / ethernet / amd / xgbe / xgbe.h
CommitLineData
c5aa9e3b
LT
1/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
10 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 *
84 * This file incorporates work covered by the following copyright and
85 * permission notice:
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
89 * and you.
90 *
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
115 */
116
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>
801c62d9
LT
124#include <linux/if_vlan.h>
125#include <linux/bitops.h>
23e4eef7 126#include <linux/ptp_clock_kernel.h>
74d23cc7 127#include <linux/timecounter.h>
23e4eef7 128#include <linux/net_tstamp.h>
fca2d994 129#include <net/dcbnl.h>
c5aa9e3b 130
c5aa9e3b 131#define XGBE_DRV_NAME "amd-xgbe"
34bfff40 132#define XGBE_DRV_VERSION "1.0.2"
c5aa9e3b
LT
133#define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
134
135/* Descriptor related defines */
d0a8ba6c
LT
136#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
c5aa9e3b 140
d0a8ba6c 141#define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
c5aa9e3b 142
16958a2b
LT
143/* Descriptors required for maximum contigous TSO/GSO packet */
144#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
d0a8ba6c
LT
154#define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
155#define XGBE_RX_BUF_ALIGN 64
08dcc47c 156#define XGBE_SKB_ALLOC_SIZE 256
174fd259 157#define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
c5aa9e3b 158
d5c48582 159#define XGBE_MAX_DMA_CHANNELS 16
fca2d994 160#define XGBE_MAX_QUEUES 16
16edd34e 161#define XGBE_DMA_STOP_TIMEOUT 5
d0a8ba6c
LT
162
163/* DMA cache settings - Outer sharable, write-back, write-allocate */
cfa50c78
LT
164#define XGBE_DMA_OS_AXDOMAIN 0x2
165#define XGBE_DMA_OS_ARCACHE 0xb
166#define XGBE_DMA_OS_AWCACHE 0xf
167
168/* DMA cache settings - System, no caches used */
169#define XGBE_DMA_SYS_AXDOMAIN 0x3
170#define XGBE_DMA_SYS_ARCACHE 0x0
171#define XGBE_DMA_SYS_AWCACHE 0x0
d0a8ba6c
LT
172
173#define XGBE_DMA_INTERRUPT_MASK 0x31c7
c5aa9e3b
LT
174
175#define XGMAC_MIN_PACKET 60
176#define XGMAC_STD_PACKET_MTU 1500
177#define XGMAC_MAX_STD_PACKET 1518
178#define XGMAC_JUMBO_PACKET_MTU 9000
179#define XGMAC_MAX_JUMBO_PACKET 9018
180
82a19035
LT
181/* Common property names */
182#define XGBE_MAC_ADDR_PROPERTY "mac-address"
183#define XGBE_PHY_MODE_PROPERTY "phy-mode"
184#define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
7c12aa08
LT
185#define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
186#define XGBE_BLWC_PROPERTY "amd,serdes-blwc"
187#define XGBE_CDR_RATE_PROPERTY "amd,serdes-cdr-rate"
188#define XGBE_PQ_SKEW_PROPERTY "amd,serdes-pq-skew"
189#define XGBE_TX_AMP_PROPERTY "amd,serdes-tx-amp"
190#define XGBE_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config"
191#define XGBE_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable"
82a19035 192
23e4eef7
LT
193/* Device-tree clock names */
194#define XGBE_DMA_CLOCK "dma_clk"
195#define XGBE_PTP_CLOCK "ptp_clk"
82a19035
LT
196
197/* ACPI property names */
198#define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
199#define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
23e4eef7
LT
200
201/* Timestamp support - values based on 50MHz PTP clock
202 * 50MHz => 20 nsec
203 */
204#define XGBE_TSTAMP_SSINC 20
205#define XGBE_TSTAMP_SNSINC 0
206
c5aa9e3b
LT
207/* Driver PMT macros */
208#define XGMAC_DRIVER_CONTEXT 1
209#define XGMAC_IOCTL_CONTEXT 2
210
f076f453 211#define XGBE_FIFO_MAX 81920
d0a8ba6c
LT
212#define XGBE_FIFO_SIZE_B(x) (x)
213#define XGBE_FIFO_SIZE_KB(x) (x * 1024)
c5aa9e3b 214
fca2d994 215#define XGBE_TC_MIN_QUANTUM 10
c5aa9e3b
LT
216
217/* Helper macro for descriptor handling
d0a8ba6c 218 * Always use XGBE_GET_DESC_DATA to access the descriptor data
c5aa9e3b
LT
219 * since the index is free-running and needs to be and-ed
220 * with the descriptor count value of the ring to index to
221 * the proper descriptor data.
222 */
d0a8ba6c 223#define XGBE_GET_DESC_DATA(_ring, _idx) \
c5aa9e3b
LT
224 ((_ring)->rdata + \
225 ((_idx) & ((_ring)->rdesc_count - 1)))
226
c5aa9e3b 227/* Default coalescing parameters */
c635eaac 228#define XGMAC_INIT_DMA_TX_USECS 1000
9867e8fb 229#define XGMAC_INIT_DMA_TX_FRAMES 25
c5aa9e3b
LT
230
231#define XGMAC_MAX_DMA_RIWT 0xff
9867e8fb
LT
232#define XGMAC_INIT_DMA_RX_USECS 30
233#define XGMAC_INIT_DMA_RX_FRAMES 25
c5aa9e3b
LT
234
235/* Flow control queue count */
236#define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
237
b85e4d89
LT
238/* Maximum MAC address hash table size (256 bits = 8 bytes) */
239#define XGBE_MAC_HASH_TABLE_SIZE 8
c5aa9e3b 240
5b9dfe29
LT
241/* Receive Side Scaling */
242#define XGBE_RSS_HASH_KEY_SIZE 40
243#define XGBE_RSS_MAX_TABLE_SIZE 256
244#define XGBE_RSS_LOOKUP_TABLE_TYPE 0
245#define XGBE_RSS_HASH_KEY_TYPE 1
246
7c12aa08
LT
247/* Auto-negotiation */
248#define XGBE_AN_MS_TIMEOUT 500
249#define XGBE_LINK_TIMEOUT 10
250
251#define XGBE_AN_INT_CMPLT 0x01
252#define XGBE_AN_INC_LINK 0x02
253#define XGBE_AN_PG_RCV 0x04
254#define XGBE_AN_INT_MASK 0x07
255
256/* Rate-change complete wait/retry count */
257#define XGBE_RATECHANGE_COUNT 500
258
259/* Default SerDes settings */
260#define XGBE_SPEED_10000_BLWC 0
261#define XGBE_SPEED_10000_CDR 0x7
262#define XGBE_SPEED_10000_PLL 0x1
263#define XGBE_SPEED_10000_PQ 0x12
264#define XGBE_SPEED_10000_RATE 0x0
265#define XGBE_SPEED_10000_TXAMP 0xa
266#define XGBE_SPEED_10000_WORD 0x7
267#define XGBE_SPEED_10000_DFE_TAP_CONFIG 0x1
268#define XGBE_SPEED_10000_DFE_TAP_ENABLE 0x7f
269
270#define XGBE_SPEED_2500_BLWC 1
271#define XGBE_SPEED_2500_CDR 0x2
272#define XGBE_SPEED_2500_PLL 0x0
273#define XGBE_SPEED_2500_PQ 0xa
274#define XGBE_SPEED_2500_RATE 0x1
275#define XGBE_SPEED_2500_TXAMP 0xf
276#define XGBE_SPEED_2500_WORD 0x1
277#define XGBE_SPEED_2500_DFE_TAP_CONFIG 0x3
278#define XGBE_SPEED_2500_DFE_TAP_ENABLE 0x0
279
280#define XGBE_SPEED_1000_BLWC 1
281#define XGBE_SPEED_1000_CDR 0x2
282#define XGBE_SPEED_1000_PLL 0x0
283#define XGBE_SPEED_1000_PQ 0xa
284#define XGBE_SPEED_1000_RATE 0x3
285#define XGBE_SPEED_1000_TXAMP 0xf
286#define XGBE_SPEED_1000_WORD 0x1
287#define XGBE_SPEED_1000_DFE_TAP_CONFIG 0x3
288#define XGBE_SPEED_1000_DFE_TAP_ENABLE 0x0
289
c5aa9e3b
LT
290struct xgbe_prv_data;
291
292struct xgbe_packet_data {
16958a2b
LT
293 struct sk_buff *skb;
294
c5aa9e3b
LT
295 unsigned int attributes;
296
297 unsigned int errors;
298
299 unsigned int rdesc_count;
300 unsigned int length;
301
302 unsigned int header_len;
303 unsigned int tcp_header_len;
304 unsigned int tcp_payload_len;
305 unsigned short mss;
306
307 unsigned short vlan_ctag;
23e4eef7
LT
308
309 u64 rx_tstamp;
5b9dfe29
LT
310
311 u32 rss_hash;
312 enum pkt_hash_types rss_hash_type;
5fb4b86a
LT
313
314 unsigned int tx_packets;
315 unsigned int tx_bytes;
c5aa9e3b
LT
316};
317
318/* Common Rx and Tx descriptor mapping */
319struct xgbe_ring_desc {
5226cfc5
LT
320 __le32 desc0;
321 __le32 desc1;
322 __le32 desc2;
323 __le32 desc3;
c5aa9e3b
LT
324};
325
08dcc47c
LT
326/* Page allocation related values */
327struct xgbe_page_alloc {
328 struct page *pages;
329 unsigned int pages_len;
330 unsigned int pages_offset;
331
332 dma_addr_t pages_dma;
333};
334
174fd259
LT
335/* Ring entry buffer data */
336struct xgbe_buffer_data {
337 struct xgbe_page_alloc pa;
338 struct xgbe_page_alloc pa_unmap;
339
340 dma_addr_t dma;
341 unsigned int dma_len;
342};
343
c9f140eb
LT
344/* Tx-related ring data */
345struct xgbe_tx_ring_data {
5fb4b86a
LT
346 unsigned int packets; /* BQL packet count */
347 unsigned int bytes; /* BQL byte count */
c9f140eb
LT
348};
349
350/* Rx-related ring data */
351struct xgbe_rx_ring_data {
352 struct xgbe_buffer_data hdr; /* Header locations */
353 struct xgbe_buffer_data buf; /* Payload locations */
354
355 unsigned short hdr_len; /* Length of received header */
356 unsigned short len; /* Length of received packet */
357};
358
c5aa9e3b
LT
359/* Structure used to hold information related to the descriptor
360 * and the packet associated with the descriptor (always use
d0a8ba6c 361 * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
c5aa9e3b
LT
362 */
363struct xgbe_ring_data {
364 struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
365 dma_addr_t rdesc_dma; /* DMA address of descriptor */
366
367 struct sk_buff *skb; /* Virtual address of SKB */
368 dma_addr_t skb_dma; /* DMA address of SKB data */
369 unsigned int skb_dma_len; /* Length of SKB DMA area */
c5aa9e3b 370
c9f140eb
LT
371 struct xgbe_tx_ring_data tx; /* Tx-related data */
372 struct xgbe_rx_ring_data rx; /* Rx-related data */
c5aa9e3b 373
c5aa9e3b 374 unsigned int mapped_as_page;
23e4eef7
LT
375
376 /* Incomplete receive save location. If the budget is exhausted
377 * or the last descriptor (last normal descriptor or a following
378 * context descriptor) has not been DMA'd yet the current state
379 * of the receive processing needs to be saved.
380 */
381 unsigned int state_saved;
382 struct {
23e4eef7
LT
383 struct sk_buff *skb;
384 unsigned int len;
385 unsigned int error;
386 } state;
c5aa9e3b
LT
387};
388
389struct xgbe_ring {
390 /* Ring lock - used just for TX rings at the moment */
391 spinlock_t lock;
392
393 /* Per packet related information */
394 struct xgbe_packet_data packet_data;
395
396 /* Virtual/DMA addresses and count of allocated descriptor memory */
397 struct xgbe_ring_desc *rdesc;
398 dma_addr_t rdesc_dma;
399 unsigned int rdesc_count;
400
401 /* Array of descriptor data corresponding the descriptor memory
d0a8ba6c 402 * (always use the XGBE_GET_DESC_DATA macro to access this data)
c5aa9e3b
LT
403 */
404 struct xgbe_ring_data *rdata;
405
08dcc47c 406 /* Page allocation for RX buffers */
174fd259
LT
407 struct xgbe_page_alloc rx_hdr_pa;
408 struct xgbe_page_alloc rx_buf_pa;
08dcc47c 409
c5aa9e3b
LT
410 /* Ring index values
411 * cur - Tx: index of descriptor to be used for current transfer
412 * Rx: index of descriptor to check for packet availability
413 * dirty - Tx: index of descriptor to check for transfer complete
270894e7 414 * Rx: index of descriptor to check for buffer reallocation
c5aa9e3b
LT
415 */
416 unsigned int cur;
417 unsigned int dirty;
418
419 /* Coalesce frame count used for interrupt bit setting */
420 unsigned int coalesce_count;
421
422 union {
423 struct {
424 unsigned int queue_stopped;
16958a2b 425 unsigned int xmit_more;
c5aa9e3b
LT
426 unsigned short cur_mss;
427 unsigned short cur_vlan_ctag;
428 } tx;
c5aa9e3b
LT
429 };
430} ____cacheline_aligned;
431
432/* Structure used to describe the descriptor rings associated with
433 * a DMA channel.
434 */
435struct xgbe_channel {
436 char name[16];
437
438 /* Address of private data area for device */
439 struct xgbe_prv_data *pdata;
440
441 /* Queue index and base address of queue's DMA registers */
442 unsigned int queue_index;
443 void __iomem *dma_regs;
444
9227dc5e
LT
445 /* Per channel interrupt irq number */
446 int dma_irq;
54ceb9ec 447 char dma_irq_name[IFNAMSIZ + 32];
9227dc5e
LT
448
449 /* Netdev related settings */
450 struct napi_struct napi;
451
c5aa9e3b
LT
452 unsigned int saved_ier;
453
454 unsigned int tx_timer_active;
c635eaac 455 struct timer_list tx_timer;
c5aa9e3b
LT
456
457 struct xgbe_ring *tx_ring;
458 struct xgbe_ring *rx_ring;
459} ____cacheline_aligned;
460
7c12aa08
LT
461enum xgbe_state {
462 XGBE_DOWN,
463 XGBE_LINK,
464 XGBE_LINK_INIT,
465 XGBE_LINK_ERR,
466};
467
c5aa9e3b 468enum xgbe_int {
c5aa9e3b
LT
469 XGMAC_INT_DMA_CH_SR_TI,
470 XGMAC_INT_DMA_CH_SR_TPS,
471 XGMAC_INT_DMA_CH_SR_TBU,
472 XGMAC_INT_DMA_CH_SR_RI,
473 XGMAC_INT_DMA_CH_SR_RBU,
474 XGMAC_INT_DMA_CH_SR_RPS,
9867e8fb 475 XGMAC_INT_DMA_CH_SR_TI_RI,
c5aa9e3b
LT
476 XGMAC_INT_DMA_CH_SR_FBE,
477 XGMAC_INT_DMA_ALL,
478};
479
480enum xgbe_int_state {
481 XGMAC_INT_STATE_SAVE,
482 XGMAC_INT_STATE_RESTORE,
483};
484
485enum xgbe_mtl_fifo_size {
486 XGMAC_MTL_FIFO_SIZE_256 = 0x00,
487 XGMAC_MTL_FIFO_SIZE_512 = 0x01,
488 XGMAC_MTL_FIFO_SIZE_1K = 0x03,
489 XGMAC_MTL_FIFO_SIZE_2K = 0x07,
490 XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
491 XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
492 XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
493 XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
494 XGMAC_MTL_FIFO_SIZE_64K = 0xff,
495 XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
496 XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
497};
498
7c12aa08
LT
499enum xgbe_speed {
500 XGBE_SPEED_1000 = 0,
501 XGBE_SPEED_2500,
502 XGBE_SPEED_10000,
503 XGBE_SPEEDS,
504};
505
506enum xgbe_an {
507 XGBE_AN_READY = 0,
508 XGBE_AN_PAGE_RECEIVED,
509 XGBE_AN_INCOMPAT_LINK,
510 XGBE_AN_COMPLETE,
511 XGBE_AN_NO_LINK,
512 XGBE_AN_ERROR,
513};
514
515enum xgbe_rx {
516 XGBE_RX_BPA = 0,
517 XGBE_RX_XNP,
518 XGBE_RX_COMPLETE,
519 XGBE_RX_ERROR,
520};
521
522enum xgbe_mode {
523 XGBE_MODE_KR = 0,
524 XGBE_MODE_KX,
525};
526
527enum xgbe_speedset {
528 XGBE_SPEEDSET_1000_10000 = 0,
529 XGBE_SPEEDSET_2500_10000,
530};
531
532struct xgbe_phy {
533 u32 supported;
534 u32 advertising;
535 u32 lp_advertising;
536
537 int address;
538
539 int autoneg;
540 int speed;
541 int duplex;
7c12aa08
LT
542
543 int link;
c1ce2f77
LT
544
545 int pause_autoneg;
546 int tx_pause;
547 int rx_pause;
7c12aa08
LT
548};
549
c5aa9e3b
LT
550struct xgbe_mmc_stats {
551 /* Tx Stats */
552 u64 txoctetcount_gb;
553 u64 txframecount_gb;
554 u64 txbroadcastframes_g;
555 u64 txmulticastframes_g;
556 u64 tx64octets_gb;
557 u64 tx65to127octets_gb;
558 u64 tx128to255octets_gb;
559 u64 tx256to511octets_gb;
560 u64 tx512to1023octets_gb;
561 u64 tx1024tomaxoctets_gb;
562 u64 txunicastframes_gb;
563 u64 txmulticastframes_gb;
564 u64 txbroadcastframes_gb;
565 u64 txunderflowerror;
566 u64 txoctetcount_g;
567 u64 txframecount_g;
568 u64 txpauseframes;
569 u64 txvlanframes_g;
570
571 /* Rx Stats */
572 u64 rxframecount_gb;
573 u64 rxoctetcount_gb;
574 u64 rxoctetcount_g;
575 u64 rxbroadcastframes_g;
576 u64 rxmulticastframes_g;
577 u64 rxcrcerror;
578 u64 rxrunterror;
579 u64 rxjabbererror;
580 u64 rxundersize_g;
581 u64 rxoversize_g;
582 u64 rx64octets_gb;
583 u64 rx65to127octets_gb;
584 u64 rx128to255octets_gb;
585 u64 rx256to511octets_gb;
586 u64 rx512to1023octets_gb;
587 u64 rx1024tomaxoctets_gb;
588 u64 rxunicastframes_g;
589 u64 rxlengtherror;
590 u64 rxoutofrangetype;
591 u64 rxpauseframes;
592 u64 rxfifooverflow;
593 u64 rxvlanframes_gb;
594 u64 rxwatchdogerror;
595};
596
5452b2df
LT
597struct xgbe_ext_stats {
598 u64 tx_tso_packets;
599 u64 rx_split_header_packets;
600};
601
c5aa9e3b
LT
602struct xgbe_hw_if {
603 int (*tx_complete)(struct xgbe_ring_desc *);
604
c5aa9e3b 605 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
b876382b 606 int (*config_rx_mode)(struct xgbe_prv_data *);
c5aa9e3b
LT
607
608 int (*enable_rx_csum)(struct xgbe_prv_data *);
609 int (*disable_rx_csum)(struct xgbe_prv_data *);
610
611 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
612 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
801c62d9
LT
613 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
614 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
615 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
c5aa9e3b
LT
616
617 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
618 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
619 int (*set_gmii_speed)(struct xgbe_prv_data *);
620 int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
621 int (*set_xgmii_speed)(struct xgbe_prv_data *);
622
623 void (*enable_tx)(struct xgbe_prv_data *);
624 void (*disable_tx)(struct xgbe_prv_data *);
625 void (*enable_rx)(struct xgbe_prv_data *);
626 void (*disable_rx)(struct xgbe_prv_data *);
627
628 void (*powerup_tx)(struct xgbe_prv_data *);
629 void (*powerdown_tx)(struct xgbe_prv_data *);
630 void (*powerup_rx)(struct xgbe_prv_data *);
631 void (*powerdown_rx)(struct xgbe_prv_data *);
632
633 int (*init)(struct xgbe_prv_data *);
634 int (*exit)(struct xgbe_prv_data *);
635
636 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
637 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
a9d41981 638 void (*dev_xmit)(struct xgbe_channel *);
c5aa9e3b
LT
639 int (*dev_read)(struct xgbe_channel *);
640 void (*tx_desc_init)(struct xgbe_channel *);
641 void (*rx_desc_init)(struct xgbe_channel *);
c5aa9e3b 642 void (*tx_desc_reset)(struct xgbe_ring_data *);
8dee19e6
LT
643 void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
644 unsigned int);
c5aa9e3b
LT
645 int (*is_last_desc)(struct xgbe_ring_desc *);
646 int (*is_context_desc)(struct xgbe_ring_desc *);
16958a2b 647 void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
c5aa9e3b
LT
648
649 /* For FLOW ctrl */
650 int (*config_tx_flow_control)(struct xgbe_prv_data *);
651 int (*config_rx_flow_control)(struct xgbe_prv_data *);
652
653 /* For RX coalescing */
654 int (*config_rx_coalesce)(struct xgbe_prv_data *);
655 int (*config_tx_coalesce)(struct xgbe_prv_data *);
656 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
657 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
658
659 /* For RX and TX threshold config */
660 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
661 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
662
663 /* For RX and TX Store and Forward Mode config */
664 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
665 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
666
667 /* For TX DMA Operate on Second Frame config */
668 int (*config_osp_mode)(struct xgbe_prv_data *);
669
670 /* For RX and TX PBL config */
671 int (*config_rx_pbl_val)(struct xgbe_prv_data *);
672 int (*get_rx_pbl_val)(struct xgbe_prv_data *);
673 int (*config_tx_pbl_val)(struct xgbe_prv_data *);
674 int (*get_tx_pbl_val)(struct xgbe_prv_data *);
675 int (*config_pblx8)(struct xgbe_prv_data *);
676
677 /* For MMC statistics */
678 void (*rx_mmc_int)(struct xgbe_prv_data *);
679 void (*tx_mmc_int)(struct xgbe_prv_data *);
680 void (*read_mmc_stats)(struct xgbe_prv_data *);
23e4eef7
LT
681
682 /* For Timestamp config */
683 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
684 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
685 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
686 unsigned int nsec);
687 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
688 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
fca2d994
LT
689
690 /* For Data Center Bridging config */
691 void (*config_dcb_tc)(struct xgbe_prv_data *);
692 void (*config_dcb_pfc)(struct xgbe_prv_data *);
5b9dfe29
LT
693
694 /* For Receive Side Scaling */
695 int (*enable_rss)(struct xgbe_prv_data *);
696 int (*disable_rss)(struct xgbe_prv_data *);
f6ac8628
LT
697 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
698 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
c5aa9e3b
LT
699};
700
7c12aa08
LT
701struct xgbe_phy_if {
702 /* For initial PHY setup */
703 void (*phy_init)(struct xgbe_prv_data *);
704
705 /* For PHY support when setting device up/down */
706 int (*phy_reset)(struct xgbe_prv_data *);
707 int (*phy_start)(struct xgbe_prv_data *);
708 void (*phy_stop)(struct xgbe_prv_data *);
709
710 /* For PHY support while device is up */
711 void (*phy_status)(struct xgbe_prv_data *);
712 int (*phy_config_aneg)(struct xgbe_prv_data *);
713};
714
c5aa9e3b
LT
715struct xgbe_desc_if {
716 int (*alloc_ring_resources)(struct xgbe_prv_data *);
717 void (*free_ring_resources)(struct xgbe_prv_data *);
718 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
270894e7
LT
719 int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
720 struct xgbe_ring_data *);
08dcc47c 721 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
c5aa9e3b
LT
722 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
723 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
724};
725
726/* This structure contains flags that indicate what hardware features
727 * or configurations are present in the device.
728 */
729struct xgbe_hw_features {
a9a4a2d9
LT
730 /* HW Version */
731 unsigned int version;
732
c5aa9e3b
LT
733 /* HW Feature Register0 */
734 unsigned int gmii; /* 1000 Mbps support */
735 unsigned int vlhash; /* VLAN Hash Filter */
736 unsigned int sma; /* SMA(MDIO) Interface */
737 unsigned int rwk; /* PMT remote wake-up packet */
738 unsigned int mgk; /* PMT magic packet */
739 unsigned int mmc; /* RMON module */
740 unsigned int aoe; /* ARP Offload */
dbedd44e 741 unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
c5aa9e3b
LT
742 unsigned int eee; /* Energy Efficient Ethernet */
743 unsigned int tx_coe; /* Tx Checksum Offload */
744 unsigned int rx_coe; /* Rx Checksum Offload */
745 unsigned int addn_mac; /* Additional MAC Addresses */
746 unsigned int ts_src; /* Timestamp Source */
747 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
748
749 /* HW Feature Register1 */
750 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
751 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
752 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
386d325d 753 unsigned int dma_width; /* DMA width */
c5aa9e3b
LT
754 unsigned int dcb; /* DCB Feature */
755 unsigned int sph; /* Split Header Feature */
756 unsigned int tso; /* TCP Segmentation Offload */
757 unsigned int dma_debug; /* DMA Debug Registers */
758 unsigned int rss; /* Receive Side Scaling */
fca2d994 759 unsigned int tc_cnt; /* Number of Traffic Classes */
c5aa9e3b
LT
760 unsigned int hash_table_size; /* Hash Table Size */
761 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
762
763 /* HW Feature Register2 */
764 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
765 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
766 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
767 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
768 unsigned int pps_out_num; /* Number of PPS outputs */
769 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
770};
771
772struct xgbe_prv_data {
773 struct net_device *netdev;
774 struct platform_device *pdev;
82a19035 775 struct acpi_device *adev;
c5aa9e3b
LT
776 struct device *dev;
777
82a19035
LT
778 /* ACPI or DT flag */
779 unsigned int use_acpi;
780
c5aa9e3b
LT
781 /* XGMAC/XPCS related mmio registers */
782 void __iomem *xgmac_regs; /* XGMAC CSRs */
783 void __iomem *xpcs_regs; /* XPCS MMD registers */
7c12aa08
LT
784 void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
785 void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
786 void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
c5aa9e3b
LT
787
788 /* Overall device lock */
789 spinlock_t lock;
790
791 /* XPCS indirect addressing mutex */
792 struct mutex xpcs_mutex;
793
5b9dfe29
LT
794 /* RSS addressing mutex */
795 struct mutex rss_mutex;
796
7c12aa08
LT
797 /* Flags representing xgbe_state */
798 unsigned long dev_state;
799
9227dc5e
LT
800 int dev_irq;
801 unsigned int per_channel_irq;
c5aa9e3b
LT
802
803 struct xgbe_hw_if hw_if;
7c12aa08 804 struct xgbe_phy_if phy_if;
c5aa9e3b
LT
805 struct xgbe_desc_if desc_if;
806
cfa50c78 807 /* AXI DMA settings */
82a19035 808 unsigned int coherent;
cfa50c78
LT
809 unsigned int axdomain;
810 unsigned int arcache;
811 unsigned int awcache;
812
7c12aa08
LT
813 /* Service routine support */
814 struct workqueue_struct *dev_workqueue;
815 struct work_struct service_work;
816 struct timer_list service_timer;
817
c5aa9e3b
LT
818 /* Rings for Tx/Rx on a DMA channel */
819 struct xgbe_channel *channel;
820 unsigned int channel_count;
821 unsigned int tx_ring_count;
822 unsigned int tx_desc_count;
823 unsigned int rx_ring_count;
824 unsigned int rx_desc_count;
825
853eb16b
LT
826 unsigned int tx_q_count;
827 unsigned int rx_q_count;
828
c5aa9e3b
LT
829 /* Tx/Rx common settings */
830 unsigned int pblx8;
831
832 /* Tx settings */
833 unsigned int tx_sf_mode;
834 unsigned int tx_threshold;
835 unsigned int tx_pbl;
836 unsigned int tx_osp_mode;
837
838 /* Rx settings */
839 unsigned int rx_sf_mode;
840 unsigned int rx_threshold;
841 unsigned int rx_pbl;
842
843 /* Tx coalescing settings */
844 unsigned int tx_usecs;
845 unsigned int tx_frames;
846
847 /* Rx coalescing settings */
848 unsigned int rx_riwt;
4a57ebcc 849 unsigned int rx_usecs;
c5aa9e3b
LT
850 unsigned int rx_frames;
851
08dcc47c 852 /* Current Rx buffer size */
c5aa9e3b
LT
853 unsigned int rx_buf_size;
854
855 /* Flow control settings */
856 unsigned int pause_autoneg;
857 unsigned int tx_pause;
858 unsigned int rx_pause;
859
5b9dfe29
LT
860 /* Receive Side Scaling settings */
861 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
862 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
863 u32 rss_options;
864
c5aa9e3b 865 /* Netdev related settings */
82a19035 866 unsigned char mac_addr[ETH_ALEN];
c5aa9e3b
LT
867 netdev_features_t netdev_features;
868 struct napi_struct napi;
869 struct xgbe_mmc_stats mmc_stats;
5452b2df 870 struct xgbe_ext_stats ext_stats;
c5aa9e3b 871
801c62d9
LT
872 /* Filtering support */
873 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
874
23e4eef7
LT
875 /* Device clocks */
876 struct clk *sysclk;
82a19035 877 unsigned long sysclk_rate;
23e4eef7 878 struct clk *ptpclk;
82a19035 879 unsigned long ptpclk_rate;
23e4eef7
LT
880
881 /* Timestamp support */
882 spinlock_t tstamp_lock;
883 struct ptp_clock_info ptp_clock_info;
884 struct ptp_clock *ptp_clock;
885 struct hwtstamp_config tstamp_config;
886 struct cyclecounter tstamp_cc;
887 struct timecounter tstamp_tc;
888 unsigned int tstamp_addend;
889 struct work_struct tx_tstamp_work;
890 struct sk_buff *tx_tstamp_skb;
891 u64 tx_tstamp;
c5aa9e3b 892
fca2d994
LT
893 /* DCB support */
894 struct ieee_ets *ets;
895 struct ieee_pfc *pfc;
896 unsigned int q2tc_map[XGBE_MAX_QUEUES];
897 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
898
c5aa9e3b
LT
899 /* Hardware features of the device */
900 struct xgbe_hw_features hw_feat;
901
902 /* Device restart work structure */
903 struct work_struct restart_work;
904
905 /* Keeps track of power mode */
906 unsigned int power_down;
907
34bf65df
LT
908 /* Network interface message level setting */
909 u32 msg_enable;
910
7c12aa08
LT
911 /* Current PHY settings */
912 phy_interface_t phy_mode;
913 int phy_link;
914 int phy_speed;
7c12aa08
LT
915
916 /* MDIO/PHY related settings */
917 struct xgbe_phy phy;
918 int mdio_mmd;
919 unsigned long link_check;
920
921 char an_name[IFNAMSIZ + 32];
922 struct workqueue_struct *an_workqueue;
923
924 int an_irq;
925 struct work_struct an_irq_work;
926
927 unsigned int speed_set;
928
929 /* SerDes UEFI configurable settings.
930 * Switching between modes/speeds requires new values for some
931 * SerDes settings. The values can be supplied as device
932 * properties in array format. The first array entry is for
933 * 1GbE, second for 2.5GbE and third for 10GbE
934 */
935 u32 serdes_blwc[XGBE_SPEEDS];
936 u32 serdes_cdr_rate[XGBE_SPEEDS];
937 u32 serdes_pq_skew[XGBE_SPEEDS];
938 u32 serdes_tx_amp[XGBE_SPEEDS];
939 u32 serdes_dfe_tap_cfg[XGBE_SPEEDS];
940 u32 serdes_dfe_tap_ena[XGBE_SPEEDS];
941
942 /* Auto-negotiation state machine support */
943 struct mutex an_mutex;
944 enum xgbe_an an_result;
945 enum xgbe_an an_state;
946 enum xgbe_rx kr_state;
947 enum xgbe_rx kx_state;
948 struct work_struct an_work;
949 unsigned int an_supported;
950 unsigned int parallel_detect;
951 unsigned int fec_ability;
952 unsigned long an_start;
953
954 unsigned int lpm_ctrl; /* CTRL1 for resume */
955
c5aa9e3b
LT
956#ifdef CONFIG_DEBUG_FS
957 struct dentry *xgbe_debugfs;
958
959 unsigned int debugfs_xgmac_reg;
960
961 unsigned int debugfs_xpcs_mmd;
962 unsigned int debugfs_xpcs_reg;
963#endif
964};
965
966/* Function prototypes*/
967
968void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
7c12aa08 969void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
c5aa9e3b
LT
970void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
971struct net_device_ops *xgbe_get_netdev_ops(void);
972struct ethtool_ops *xgbe_get_ethtool_ops(void);
fca2d994
LT
973#ifdef CONFIG_AMD_XGBE_DCB
974const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
975#endif
c5aa9e3b 976
23e4eef7
LT
977void xgbe_ptp_register(struct xgbe_prv_data *);
978void xgbe_ptp_unregister(struct xgbe_prv_data *);
34bf65df
LT
979void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
980 unsigned int, unsigned int, unsigned int);
981void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
c5aa9e3b
LT
982 unsigned int);
983void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
984void xgbe_get_all_hw_features(struct xgbe_prv_data *);
985int xgbe_powerup(struct net_device *, unsigned int);
986int xgbe_powerdown(struct net_device *, unsigned int);
987void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
988void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
989
990#ifdef CONFIG_DEBUG_FS
991void xgbe_debugfs_init(struct xgbe_prv_data *);
992void xgbe_debugfs_exit(struct xgbe_prv_data *);
993#else
994static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
995static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
996#endif /* CONFIG_DEBUG_FS */
997
c5aa9e3b
LT
998/* NOTE: Uncomment for function trace log messages in KERNEL LOG */
999#if 0
1000#define YDEBUG
1001#define YDEBUG_MDIO
1002#endif
1003
1004/* For debug prints */
1005#ifdef YDEBUG
1006#define DBGPR(x...) pr_alert(x)
c5aa9e3b
LT
1007#else
1008#define DBGPR(x...) do { } while (0)
c5aa9e3b
LT
1009#endif
1010
1011#ifdef YDEBUG_MDIO
1012#define DBGPR_MDIO(x...) pr_alert(x)
1013#else
1014#define DBGPR_MDIO(x...) do { } while (0)
1015#endif
1016
1017#endif