blob: 46ce54459121f14f41d42fc21cd7f201cdbd8403 [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 *
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>
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>
127#include <linux/clocksource.h>
128#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"
132#define XGBE_DRV_VERSION "1.0.0-a"
133#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
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500143#define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
144#define XGBE_RX_BUF_ALIGN 64
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600145#define XGBE_SKB_ALLOC_SIZE 256
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600146#define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500147
Lendacky, Thomasd5c48582014-06-09 09:19:32 -0500148#define XGBE_MAX_DMA_CHANNELS 16
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500149#define XGBE_MAX_QUEUES 16
Lendacky, Thomas16edd342014-11-20 11:03:32 -0600150#define XGBE_DMA_STOP_TIMEOUT 5
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500151
152/* DMA cache settings - Outer sharable, write-back, write-allocate */
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500153#define XGBE_DMA_OS_AXDOMAIN 0x2
154#define XGBE_DMA_OS_ARCACHE 0xb
155#define XGBE_DMA_OS_AWCACHE 0xf
156
157/* DMA cache settings - System, no caches used */
158#define XGBE_DMA_SYS_AXDOMAIN 0x3
159#define XGBE_DMA_SYS_ARCACHE 0x0
160#define XGBE_DMA_SYS_AWCACHE 0x0
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500161
162#define XGBE_DMA_INTERRUPT_MASK 0x31c7
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500163
164#define XGMAC_MIN_PACKET 60
165#define XGMAC_STD_PACKET_MTU 1500
166#define XGMAC_MAX_STD_PACKET 1518
167#define XGMAC_JUMBO_PACKET_MTU 9000
168#define XGMAC_MAX_JUMBO_PACKET 9018
169
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500170/* MDIO bus phy name */
171#define XGBE_PHY_NAME "amd_xgbe_phy"
172#define XGBE_PRTAD 0
173
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500174/* Device-tree clock names */
175#define XGBE_DMA_CLOCK "dma_clk"
176#define XGBE_PTP_CLOCK "ptp_clk"
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600177#define XGBE_DMA_IRQS "amd,per-channel-interrupt"
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500178
179/* Timestamp support - values based on 50MHz PTP clock
180 * 50MHz => 20 nsec
181 */
182#define XGBE_TSTAMP_SSINC 20
183#define XGBE_TSTAMP_SNSINC 0
184
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500185/* Driver PMT macros */
186#define XGMAC_DRIVER_CONTEXT 1
187#define XGMAC_IOCTL_CONTEXT 2
188
Lendacky, Thomasf076f452014-08-29 13:16:56 -0500189#define XGBE_FIFO_MAX 81920
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500190#define XGBE_FIFO_SIZE_B(x) (x)
191#define XGBE_FIFO_SIZE_KB(x) (x * 1024)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500192
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500193#define XGBE_TC_MIN_QUANTUM 10
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500194
195/* Helper macro for descriptor handling
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500196 * Always use XGBE_GET_DESC_DATA to access the descriptor data
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500197 * since the index is free-running and needs to be and-ed
198 * with the descriptor count value of the ring to index to
199 * the proper descriptor data.
200 */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500201#define XGBE_GET_DESC_DATA(_ring, _idx) \
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500202 ((_ring)->rdata + \
203 ((_idx) & ((_ring)->rdesc_count - 1)))
204
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500205/* Default coalescing parameters */
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500206#define XGMAC_INIT_DMA_TX_USECS 50
207#define XGMAC_INIT_DMA_TX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500208
209#define XGMAC_MAX_DMA_RIWT 0xff
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500210#define XGMAC_INIT_DMA_RX_USECS 30
211#define XGMAC_INIT_DMA_RX_FRAMES 25
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500212
213/* Flow control queue count */
214#define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
215
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500216/* Maximum MAC address hash table size (256 bits = 8 bytes) */
217#define XGBE_MAC_HASH_TABLE_SIZE 8
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500218
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600219/* Receive Side Scaling */
220#define XGBE_RSS_HASH_KEY_SIZE 40
221#define XGBE_RSS_MAX_TABLE_SIZE 256
222#define XGBE_RSS_LOOKUP_TABLE_TYPE 0
223#define XGBE_RSS_HASH_KEY_TYPE 1
224
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500225struct xgbe_prv_data;
226
227struct xgbe_packet_data {
228 unsigned int attributes;
229
230 unsigned int errors;
231
232 unsigned int rdesc_count;
233 unsigned int length;
234
235 unsigned int header_len;
236 unsigned int tcp_header_len;
237 unsigned int tcp_payload_len;
238 unsigned short mss;
239
240 unsigned short vlan_ctag;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500241
242 u64 rx_tstamp;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600243
244 u32 rss_hash;
245 enum pkt_hash_types rss_hash_type;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500246};
247
248/* Common Rx and Tx descriptor mapping */
249struct xgbe_ring_desc {
Lendacky, Thomas5226cfc2014-11-12 10:37:49 -0600250 __le32 desc0;
251 __le32 desc1;
252 __le32 desc2;
253 __le32 desc3;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500254};
255
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600256/* Page allocation related values */
257struct xgbe_page_alloc {
258 struct page *pages;
259 unsigned int pages_len;
260 unsigned int pages_offset;
261
262 dma_addr_t pages_dma;
263};
264
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600265/* Ring entry buffer data */
266struct xgbe_buffer_data {
267 struct xgbe_page_alloc pa;
268 struct xgbe_page_alloc pa_unmap;
269
270 dma_addr_t dma;
271 unsigned int dma_len;
272};
273
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500274/* Structure used to hold information related to the descriptor
275 * and the packet associated with the descriptor (always use
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500276 * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500277 */
278struct xgbe_ring_data {
279 struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
280 dma_addr_t rdesc_dma; /* DMA address of descriptor */
281
282 struct sk_buff *skb; /* Virtual address of SKB */
283 dma_addr_t skb_dma; /* DMA address of SKB data */
284 unsigned int skb_dma_len; /* Length of SKB DMA area */
285 unsigned int tso_header; /* TSO header indicator */
286
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600287 struct xgbe_buffer_data rx_hdr; /* Header locations */
288 struct xgbe_buffer_data rx_buf; /* Payload locations */
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600289
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600290 unsigned short hdr_len; /* Length of received header */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500291 unsigned short len; /* Length of received Rx packet */
292
293 unsigned int interrupt; /* Interrupt indicator */
294
295 unsigned int mapped_as_page;
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500296
297 /* Incomplete receive save location. If the budget is exhausted
298 * or the last descriptor (last normal descriptor or a following
299 * context descriptor) has not been DMA'd yet the current state
300 * of the receive processing needs to be saved.
301 */
302 unsigned int state_saved;
303 struct {
304 unsigned int incomplete;
305 unsigned int context_next;
306 struct sk_buff *skb;
307 unsigned int len;
308 unsigned int error;
309 } state;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500310};
311
312struct xgbe_ring {
313 /* Ring lock - used just for TX rings at the moment */
314 spinlock_t lock;
315
316 /* Per packet related information */
317 struct xgbe_packet_data packet_data;
318
319 /* Virtual/DMA addresses and count of allocated descriptor memory */
320 struct xgbe_ring_desc *rdesc;
321 dma_addr_t rdesc_dma;
322 unsigned int rdesc_count;
323
324 /* Array of descriptor data corresponding the descriptor memory
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500325 * (always use the XGBE_GET_DESC_DATA macro to access this data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500326 */
327 struct xgbe_ring_data *rdata;
328
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600329 /* Page allocation for RX buffers */
Lendacky, Thomas174fd252014-11-04 16:06:50 -0600330 struct xgbe_page_alloc rx_hdr_pa;
331 struct xgbe_page_alloc rx_buf_pa;
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600332
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500333 /* Ring index values
334 * cur - Tx: index of descriptor to be used for current transfer
335 * Rx: index of descriptor to check for packet availability
336 * dirty - Tx: index of descriptor to check for transfer complete
337 * Rx: count of descriptors in which a packet has been received
338 * (used with skb_realloc_index to refresh the ring)
339 */
340 unsigned int cur;
341 unsigned int dirty;
342
343 /* Coalesce frame count used for interrupt bit setting */
344 unsigned int coalesce_count;
345
346 union {
347 struct {
348 unsigned int queue_stopped;
349 unsigned short cur_mss;
350 unsigned short cur_vlan_ctag;
351 } tx;
352
353 struct {
354 unsigned int realloc_index;
355 unsigned int realloc_threshold;
356 } rx;
357 };
358} ____cacheline_aligned;
359
360/* Structure used to describe the descriptor rings associated with
361 * a DMA channel.
362 */
363struct xgbe_channel {
364 char name[16];
365
366 /* Address of private data area for device */
367 struct xgbe_prv_data *pdata;
368
369 /* Queue index and base address of queue's DMA registers */
370 unsigned int queue_index;
371 void __iomem *dma_regs;
372
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600373 /* Per channel interrupt irq number */
374 int dma_irq;
375
376 /* Netdev related settings */
377 struct napi_struct napi;
378
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500379 unsigned int saved_ier;
380
381 unsigned int tx_timer_active;
382 struct hrtimer tx_timer;
383
384 struct xgbe_ring *tx_ring;
385 struct xgbe_ring *rx_ring;
386} ____cacheline_aligned;
387
388enum xgbe_int {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500389 XGMAC_INT_DMA_CH_SR_TI,
390 XGMAC_INT_DMA_CH_SR_TPS,
391 XGMAC_INT_DMA_CH_SR_TBU,
392 XGMAC_INT_DMA_CH_SR_RI,
393 XGMAC_INT_DMA_CH_SR_RBU,
394 XGMAC_INT_DMA_CH_SR_RPS,
Lendacky, Thomas9867e8f2014-07-02 13:04:46 -0500395 XGMAC_INT_DMA_CH_SR_TI_RI,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500396 XGMAC_INT_DMA_CH_SR_FBE,
397 XGMAC_INT_DMA_ALL,
398};
399
400enum xgbe_int_state {
401 XGMAC_INT_STATE_SAVE,
402 XGMAC_INT_STATE_RESTORE,
403};
404
405enum xgbe_mtl_fifo_size {
406 XGMAC_MTL_FIFO_SIZE_256 = 0x00,
407 XGMAC_MTL_FIFO_SIZE_512 = 0x01,
408 XGMAC_MTL_FIFO_SIZE_1K = 0x03,
409 XGMAC_MTL_FIFO_SIZE_2K = 0x07,
410 XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
411 XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
412 XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
413 XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
414 XGMAC_MTL_FIFO_SIZE_64K = 0xff,
415 XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
416 XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
417};
418
419struct xgbe_mmc_stats {
420 /* Tx Stats */
421 u64 txoctetcount_gb;
422 u64 txframecount_gb;
423 u64 txbroadcastframes_g;
424 u64 txmulticastframes_g;
425 u64 tx64octets_gb;
426 u64 tx65to127octets_gb;
427 u64 tx128to255octets_gb;
428 u64 tx256to511octets_gb;
429 u64 tx512to1023octets_gb;
430 u64 tx1024tomaxoctets_gb;
431 u64 txunicastframes_gb;
432 u64 txmulticastframes_gb;
433 u64 txbroadcastframes_gb;
434 u64 txunderflowerror;
435 u64 txoctetcount_g;
436 u64 txframecount_g;
437 u64 txpauseframes;
438 u64 txvlanframes_g;
439
440 /* Rx Stats */
441 u64 rxframecount_gb;
442 u64 rxoctetcount_gb;
443 u64 rxoctetcount_g;
444 u64 rxbroadcastframes_g;
445 u64 rxmulticastframes_g;
446 u64 rxcrcerror;
447 u64 rxrunterror;
448 u64 rxjabbererror;
449 u64 rxundersize_g;
450 u64 rxoversize_g;
451 u64 rx64octets_gb;
452 u64 rx65to127octets_gb;
453 u64 rx128to255octets_gb;
454 u64 rx256to511octets_gb;
455 u64 rx512to1023octets_gb;
456 u64 rx1024tomaxoctets_gb;
457 u64 rxunicastframes_g;
458 u64 rxlengtherror;
459 u64 rxoutofrangetype;
460 u64 rxpauseframes;
461 u64 rxfifooverflow;
462 u64 rxvlanframes_gb;
463 u64 rxwatchdogerror;
464};
465
466struct xgbe_hw_if {
467 int (*tx_complete)(struct xgbe_ring_desc *);
468
469 int (*set_promiscuous_mode)(struct xgbe_prv_data *, unsigned int);
470 int (*set_all_multicast_mode)(struct xgbe_prv_data *, unsigned int);
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500471 int (*add_mac_addresses)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500472 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
473
474 int (*enable_rx_csum)(struct xgbe_prv_data *);
475 int (*disable_rx_csum)(struct xgbe_prv_data *);
476
477 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
478 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500479 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
480 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
481 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500482
483 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
484 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
485 int (*set_gmii_speed)(struct xgbe_prv_data *);
486 int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
487 int (*set_xgmii_speed)(struct xgbe_prv_data *);
488
489 void (*enable_tx)(struct xgbe_prv_data *);
490 void (*disable_tx)(struct xgbe_prv_data *);
491 void (*enable_rx)(struct xgbe_prv_data *);
492 void (*disable_rx)(struct xgbe_prv_data *);
493
494 void (*powerup_tx)(struct xgbe_prv_data *);
495 void (*powerdown_tx)(struct xgbe_prv_data *);
496 void (*powerup_rx)(struct xgbe_prv_data *);
497 void (*powerdown_rx)(struct xgbe_prv_data *);
498
499 int (*init)(struct xgbe_prv_data *);
500 int (*exit)(struct xgbe_prv_data *);
501
502 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
503 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
Lendacky, Thomasa9d41982014-11-04 16:06:32 -0600504 void (*dev_xmit)(struct xgbe_channel *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500505 int (*dev_read)(struct xgbe_channel *);
506 void (*tx_desc_init)(struct xgbe_channel *);
507 void (*rx_desc_init)(struct xgbe_channel *);
508 void (*rx_desc_reset)(struct xgbe_ring_data *);
509 void (*tx_desc_reset)(struct xgbe_ring_data *);
510 int (*is_last_desc)(struct xgbe_ring_desc *);
511 int (*is_context_desc)(struct xgbe_ring_desc *);
512
513 /* For FLOW ctrl */
514 int (*config_tx_flow_control)(struct xgbe_prv_data *);
515 int (*config_rx_flow_control)(struct xgbe_prv_data *);
516
517 /* For RX coalescing */
518 int (*config_rx_coalesce)(struct xgbe_prv_data *);
519 int (*config_tx_coalesce)(struct xgbe_prv_data *);
520 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
521 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
522
523 /* For RX and TX threshold config */
524 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
525 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
526
527 /* For RX and TX Store and Forward Mode config */
528 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
529 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
530
531 /* For TX DMA Operate on Second Frame config */
532 int (*config_osp_mode)(struct xgbe_prv_data *);
533
534 /* For RX and TX PBL config */
535 int (*config_rx_pbl_val)(struct xgbe_prv_data *);
536 int (*get_rx_pbl_val)(struct xgbe_prv_data *);
537 int (*config_tx_pbl_val)(struct xgbe_prv_data *);
538 int (*get_tx_pbl_val)(struct xgbe_prv_data *);
539 int (*config_pblx8)(struct xgbe_prv_data *);
540
541 /* For MMC statistics */
542 void (*rx_mmc_int)(struct xgbe_prv_data *);
543 void (*tx_mmc_int)(struct xgbe_prv_data *);
544 void (*read_mmc_stats)(struct xgbe_prv_data *);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500545
546 /* For Timestamp config */
547 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
548 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
549 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
550 unsigned int nsec);
551 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
552 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500553
554 /* For Data Center Bridging config */
555 void (*config_dcb_tc)(struct xgbe_prv_data *);
556 void (*config_dcb_pfc)(struct xgbe_prv_data *);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600557
558 /* For Receive Side Scaling */
559 int (*enable_rss)(struct xgbe_prv_data *);
560 int (*disable_rss)(struct xgbe_prv_data *);
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600561 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
562 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500563};
564
565struct xgbe_desc_if {
566 int (*alloc_ring_resources)(struct xgbe_prv_data *);
567 void (*free_ring_resources)(struct xgbe_prv_data *);
568 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600569 void (*realloc_rx_buffer)(struct xgbe_channel *);
570 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500571 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
572 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
573};
574
575/* This structure contains flags that indicate what hardware features
576 * or configurations are present in the device.
577 */
578struct xgbe_hw_features {
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500579 /* HW Version */
580 unsigned int version;
581
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500582 /* HW Feature Register0 */
583 unsigned int gmii; /* 1000 Mbps support */
584 unsigned int vlhash; /* VLAN Hash Filter */
585 unsigned int sma; /* SMA(MDIO) Interface */
586 unsigned int rwk; /* PMT remote wake-up packet */
587 unsigned int mgk; /* PMT magic packet */
588 unsigned int mmc; /* RMON module */
589 unsigned int aoe; /* ARP Offload */
590 unsigned int ts; /* IEEE 1588-2008 Adavanced Timestamp */
591 unsigned int eee; /* Energy Efficient Ethernet */
592 unsigned int tx_coe; /* Tx Checksum Offload */
593 unsigned int rx_coe; /* Rx Checksum Offload */
594 unsigned int addn_mac; /* Additional MAC Addresses */
595 unsigned int ts_src; /* Timestamp Source */
596 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
597
598 /* HW Feature Register1 */
599 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
600 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
601 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
602 unsigned int dcb; /* DCB Feature */
603 unsigned int sph; /* Split Header Feature */
604 unsigned int tso; /* TCP Segmentation Offload */
605 unsigned int dma_debug; /* DMA Debug Registers */
606 unsigned int rss; /* Receive Side Scaling */
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500607 unsigned int tc_cnt; /* Number of Traffic Classes */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500608 unsigned int hash_table_size; /* Hash Table Size */
609 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
610
611 /* HW Feature Register2 */
612 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
613 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
614 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
615 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
616 unsigned int pps_out_num; /* Number of PPS outputs */
617 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
618};
619
620struct xgbe_prv_data {
621 struct net_device *netdev;
622 struct platform_device *pdev;
623 struct device *dev;
624
625 /* XGMAC/XPCS related mmio registers */
626 void __iomem *xgmac_regs; /* XGMAC CSRs */
627 void __iomem *xpcs_regs; /* XPCS MMD registers */
628
629 /* Overall device lock */
630 spinlock_t lock;
631
632 /* XPCS indirect addressing mutex */
633 struct mutex xpcs_mutex;
634
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600635 /* RSS addressing mutex */
636 struct mutex rss_mutex;
637
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600638 int dev_irq;
639 unsigned int per_channel_irq;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500640
641 struct xgbe_hw_if hw_if;
642 struct xgbe_desc_if desc_if;
643
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500644 /* AXI DMA settings */
645 unsigned int axdomain;
646 unsigned int arcache;
647 unsigned int awcache;
648
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500649 /* Rings for Tx/Rx on a DMA channel */
650 struct xgbe_channel *channel;
651 unsigned int channel_count;
652 unsigned int tx_ring_count;
653 unsigned int tx_desc_count;
654 unsigned int rx_ring_count;
655 unsigned int rx_desc_count;
656
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500657 unsigned int tx_q_count;
658 unsigned int rx_q_count;
659
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500660 /* Tx/Rx common settings */
661 unsigned int pblx8;
662
663 /* Tx settings */
664 unsigned int tx_sf_mode;
665 unsigned int tx_threshold;
666 unsigned int tx_pbl;
667 unsigned int tx_osp_mode;
668
669 /* Rx settings */
670 unsigned int rx_sf_mode;
671 unsigned int rx_threshold;
672 unsigned int rx_pbl;
673
674 /* Tx coalescing settings */
675 unsigned int tx_usecs;
676 unsigned int tx_frames;
677
678 /* Rx coalescing settings */
679 unsigned int rx_riwt;
680 unsigned int rx_frames;
681
Lendacky, Thomas08dcc472014-11-04 16:06:44 -0600682 /* Current Rx buffer size */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500683 unsigned int rx_buf_size;
684
685 /* Flow control settings */
686 unsigned int pause_autoneg;
687 unsigned int tx_pause;
688 unsigned int rx_pause;
689
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600690 /* Receive Side Scaling settings */
691 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
692 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
693 u32 rss_options;
694
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500695 /* MDIO settings */
696 struct module *phy_module;
697 char *mii_bus_id;
698 struct mii_bus *mii;
699 int mdio_mmd;
700 struct phy_device *phydev;
701 int default_autoneg;
702 int default_speed;
703
704 /* Current PHY settings */
705 phy_interface_t phy_mode;
706 int phy_link;
707 int phy_speed;
708 unsigned int phy_tx_pause;
709 unsigned int phy_rx_pause;
710
711 /* Netdev related settings */
712 netdev_features_t netdev_features;
713 struct napi_struct napi;
714 struct xgbe_mmc_stats mmc_stats;
715
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500716 /* Filtering support */
717 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
718
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500719 /* Device clocks */
720 struct clk *sysclk;
721 struct clk *ptpclk;
722
723 /* Timestamp support */
724 spinlock_t tstamp_lock;
725 struct ptp_clock_info ptp_clock_info;
726 struct ptp_clock *ptp_clock;
727 struct hwtstamp_config tstamp_config;
728 struct cyclecounter tstamp_cc;
729 struct timecounter tstamp_tc;
730 unsigned int tstamp_addend;
731 struct work_struct tx_tstamp_work;
732 struct sk_buff *tx_tstamp_skb;
733 u64 tx_tstamp;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500734
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500735 /* DCB support */
736 struct ieee_ets *ets;
737 struct ieee_pfc *pfc;
738 unsigned int q2tc_map[XGBE_MAX_QUEUES];
739 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
740
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500741 /* Hardware features of the device */
742 struct xgbe_hw_features hw_feat;
743
744 /* Device restart work structure */
745 struct work_struct restart_work;
746
747 /* Keeps track of power mode */
748 unsigned int power_down;
749
750#ifdef CONFIG_DEBUG_FS
751 struct dentry *xgbe_debugfs;
752
753 unsigned int debugfs_xgmac_reg;
754
755 unsigned int debugfs_xpcs_mmd;
756 unsigned int debugfs_xpcs_reg;
757#endif
758};
759
760/* Function prototypes*/
761
762void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
763void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
764struct net_device_ops *xgbe_get_netdev_ops(void);
765struct ethtool_ops *xgbe_get_ethtool_ops(void);
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500766#ifdef CONFIG_AMD_XGBE_DCB
767const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
768#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500769
770int xgbe_mdio_register(struct xgbe_prv_data *);
771void xgbe_mdio_unregister(struct xgbe_prv_data *);
772void xgbe_dump_phy_registers(struct xgbe_prv_data *);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500773void xgbe_ptp_register(struct xgbe_prv_data *);
774void xgbe_ptp_unregister(struct xgbe_prv_data *);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500775void xgbe_dump_tx_desc(struct xgbe_ring *, unsigned int, unsigned int,
776 unsigned int);
777void xgbe_dump_rx_desc(struct xgbe_ring *, struct xgbe_ring_desc *,
778 unsigned int);
779void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
780void xgbe_get_all_hw_features(struct xgbe_prv_data *);
781int xgbe_powerup(struct net_device *, unsigned int);
782int xgbe_powerdown(struct net_device *, unsigned int);
783void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
784void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
785
786#ifdef CONFIG_DEBUG_FS
787void xgbe_debugfs_init(struct xgbe_prv_data *);
788void xgbe_debugfs_exit(struct xgbe_prv_data *);
789#else
790static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
791static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
792#endif /* CONFIG_DEBUG_FS */
793
794/* NOTE: Uncomment for TX and RX DESCRIPTOR DUMP in KERNEL LOG */
795#if 0
796#define XGMAC_ENABLE_TX_DESC_DUMP
797#define XGMAC_ENABLE_RX_DESC_DUMP
798#endif
799
800/* NOTE: Uncomment for TX and RX PACKET DUMP in KERNEL LOG */
801#if 0
802#define XGMAC_ENABLE_TX_PKT_DUMP
803#define XGMAC_ENABLE_RX_PKT_DUMP
804#endif
805
806/* NOTE: Uncomment for function trace log messages in KERNEL LOG */
807#if 0
808#define YDEBUG
809#define YDEBUG_MDIO
810#endif
811
812/* For debug prints */
813#ifdef YDEBUG
814#define DBGPR(x...) pr_alert(x)
815#define DBGPHY_REGS(x...) xgbe_dump_phy_registers(x)
816#else
817#define DBGPR(x...) do { } while (0)
818#define DBGPHY_REGS(x...) do { } while (0)
819#endif
820
821#ifdef YDEBUG_MDIO
822#define DBGPR_MDIO(x...) pr_alert(x)
823#else
824#define DBGPR_MDIO(x...) do { } while (0)
825#endif
826
827#endif