blob: f5da54cddd8d20438c33bea0511d7e996409fd4b [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>
124
125
126#define XGBE_DRV_NAME "amd-xgbe"
127#define XGBE_DRV_VERSION "1.0.0-a"
128#define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
129
130/* Descriptor related defines */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500131#define XGBE_TX_DESC_CNT 512
132#define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
133#define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
134#define XGBE_RX_DESC_CNT 512
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500135
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500136#define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500137
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500138#define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
139#define XGBE_RX_BUF_ALIGN 64
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500140
Lendacky, Thomasd5c48582014-06-09 09:19:32 -0500141#define XGBE_MAX_DMA_CHANNELS 16
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500142
143/* DMA cache settings - Outer sharable, write-back, write-allocate */
144#define XGBE_DMA_ARDOMAIN 0x2
145#define XGBE_DMA_ARCACHE 0xb
146#define XGBE_DMA_AWDOMAIN 0x2
147#define XGBE_DMA_AWCACHE 0x7
148
149#define XGBE_DMA_INTERRUPT_MASK 0x31c7
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500150
151#define XGMAC_MIN_PACKET 60
152#define XGMAC_STD_PACKET_MTU 1500
153#define XGMAC_MAX_STD_PACKET 1518
154#define XGMAC_JUMBO_PACKET_MTU 9000
155#define XGMAC_MAX_JUMBO_PACKET 9018
156
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500157/* MDIO bus phy name */
158#define XGBE_PHY_NAME "amd_xgbe_phy"
159#define XGBE_PRTAD 0
160
161/* Driver PMT macros */
162#define XGMAC_DRIVER_CONTEXT 1
163#define XGMAC_IOCTL_CONTEXT 2
164
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500165#define XGBE_FIFO_SIZE_B(x) (x)
166#define XGBE_FIFO_SIZE_KB(x) (x * 1024)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500167
168#define XGBE_TC_CNT 2
169
170/* Helper macro for descriptor handling
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500171 * Always use XGBE_GET_DESC_DATA to access the descriptor data
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500172 * since the index is free-running and needs to be and-ed
173 * with the descriptor count value of the ring to index to
174 * the proper descriptor data.
175 */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500176#define XGBE_GET_DESC_DATA(_ring, _idx) \
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500177 ((_ring)->rdata + \
178 ((_idx) & ((_ring)->rdesc_count - 1)))
179
180
181/* Default coalescing parameters */
182#define XGMAC_INIT_DMA_TX_USECS 100
183#define XGMAC_INIT_DMA_TX_FRAMES 16
184
185#define XGMAC_MAX_DMA_RIWT 0xff
186#define XGMAC_INIT_DMA_RX_USECS 100
187#define XGMAC_INIT_DMA_RX_FRAMES 16
188
189/* Flow control queue count */
190#define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
191
192
193struct xgbe_prv_data;
194
195struct xgbe_packet_data {
196 unsigned int attributes;
197
198 unsigned int errors;
199
200 unsigned int rdesc_count;
201 unsigned int length;
202
203 unsigned int header_len;
204 unsigned int tcp_header_len;
205 unsigned int tcp_payload_len;
206 unsigned short mss;
207
208 unsigned short vlan_ctag;
209};
210
211/* Common Rx and Tx descriptor mapping */
212struct xgbe_ring_desc {
213 unsigned int desc0;
214 unsigned int desc1;
215 unsigned int desc2;
216 unsigned int desc3;
217};
218
219/* Structure used to hold information related to the descriptor
220 * and the packet associated with the descriptor (always use
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500221 * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500222 */
223struct xgbe_ring_data {
224 struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
225 dma_addr_t rdesc_dma; /* DMA address of descriptor */
226
227 struct sk_buff *skb; /* Virtual address of SKB */
228 dma_addr_t skb_dma; /* DMA address of SKB data */
229 unsigned int skb_dma_len; /* Length of SKB DMA area */
230 unsigned int tso_header; /* TSO header indicator */
231
232 unsigned short len; /* Length of received Rx packet */
233
234 unsigned int interrupt; /* Interrupt indicator */
235
236 unsigned int mapped_as_page;
237};
238
239struct xgbe_ring {
240 /* Ring lock - used just for TX rings at the moment */
241 spinlock_t lock;
242
243 /* Per packet related information */
244 struct xgbe_packet_data packet_data;
245
246 /* Virtual/DMA addresses and count of allocated descriptor memory */
247 struct xgbe_ring_desc *rdesc;
248 dma_addr_t rdesc_dma;
249 unsigned int rdesc_count;
250
251 /* Array of descriptor data corresponding the descriptor memory
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500252 * (always use the XGBE_GET_DESC_DATA macro to access this data)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500253 */
254 struct xgbe_ring_data *rdata;
255
256 /* Ring index values
257 * cur - Tx: index of descriptor to be used for current transfer
258 * Rx: index of descriptor to check for packet availability
259 * dirty - Tx: index of descriptor to check for transfer complete
260 * Rx: count of descriptors in which a packet has been received
261 * (used with skb_realloc_index to refresh the ring)
262 */
263 unsigned int cur;
264 unsigned int dirty;
265
266 /* Coalesce frame count used for interrupt bit setting */
267 unsigned int coalesce_count;
268
269 union {
270 struct {
271 unsigned int queue_stopped;
272 unsigned short cur_mss;
273 unsigned short cur_vlan_ctag;
274 } tx;
275
276 struct {
277 unsigned int realloc_index;
278 unsigned int realloc_threshold;
279 } rx;
280 };
281} ____cacheline_aligned;
282
283/* Structure used to describe the descriptor rings associated with
284 * a DMA channel.
285 */
286struct xgbe_channel {
287 char name[16];
288
289 /* Address of private data area for device */
290 struct xgbe_prv_data *pdata;
291
292 /* Queue index and base address of queue's DMA registers */
293 unsigned int queue_index;
294 void __iomem *dma_regs;
295
296 unsigned int saved_ier;
297
298 unsigned int tx_timer_active;
299 struct hrtimer tx_timer;
300
301 struct xgbe_ring *tx_ring;
302 struct xgbe_ring *rx_ring;
303} ____cacheline_aligned;
304
305enum xgbe_int {
306 XGMAC_INT_DMA_ISR_DC0IS,
307 XGMAC_INT_DMA_CH_SR_TI,
308 XGMAC_INT_DMA_CH_SR_TPS,
309 XGMAC_INT_DMA_CH_SR_TBU,
310 XGMAC_INT_DMA_CH_SR_RI,
311 XGMAC_INT_DMA_CH_SR_RBU,
312 XGMAC_INT_DMA_CH_SR_RPS,
313 XGMAC_INT_DMA_CH_SR_FBE,
314 XGMAC_INT_DMA_ALL,
315};
316
317enum xgbe_int_state {
318 XGMAC_INT_STATE_SAVE,
319 XGMAC_INT_STATE_RESTORE,
320};
321
322enum xgbe_mtl_fifo_size {
323 XGMAC_MTL_FIFO_SIZE_256 = 0x00,
324 XGMAC_MTL_FIFO_SIZE_512 = 0x01,
325 XGMAC_MTL_FIFO_SIZE_1K = 0x03,
326 XGMAC_MTL_FIFO_SIZE_2K = 0x07,
327 XGMAC_MTL_FIFO_SIZE_4K = 0x0f,
328 XGMAC_MTL_FIFO_SIZE_8K = 0x1f,
329 XGMAC_MTL_FIFO_SIZE_16K = 0x3f,
330 XGMAC_MTL_FIFO_SIZE_32K = 0x7f,
331 XGMAC_MTL_FIFO_SIZE_64K = 0xff,
332 XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
333 XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
334};
335
336struct xgbe_mmc_stats {
337 /* Tx Stats */
338 u64 txoctetcount_gb;
339 u64 txframecount_gb;
340 u64 txbroadcastframes_g;
341 u64 txmulticastframes_g;
342 u64 tx64octets_gb;
343 u64 tx65to127octets_gb;
344 u64 tx128to255octets_gb;
345 u64 tx256to511octets_gb;
346 u64 tx512to1023octets_gb;
347 u64 tx1024tomaxoctets_gb;
348 u64 txunicastframes_gb;
349 u64 txmulticastframes_gb;
350 u64 txbroadcastframes_gb;
351 u64 txunderflowerror;
352 u64 txoctetcount_g;
353 u64 txframecount_g;
354 u64 txpauseframes;
355 u64 txvlanframes_g;
356
357 /* Rx Stats */
358 u64 rxframecount_gb;
359 u64 rxoctetcount_gb;
360 u64 rxoctetcount_g;
361 u64 rxbroadcastframes_g;
362 u64 rxmulticastframes_g;
363 u64 rxcrcerror;
364 u64 rxrunterror;
365 u64 rxjabbererror;
366 u64 rxundersize_g;
367 u64 rxoversize_g;
368 u64 rx64octets_gb;
369 u64 rx65to127octets_gb;
370 u64 rx128to255octets_gb;
371 u64 rx256to511octets_gb;
372 u64 rx512to1023octets_gb;
373 u64 rx1024tomaxoctets_gb;
374 u64 rxunicastframes_g;
375 u64 rxlengtherror;
376 u64 rxoutofrangetype;
377 u64 rxpauseframes;
378 u64 rxfifooverflow;
379 u64 rxvlanframes_gb;
380 u64 rxwatchdogerror;
381};
382
383struct xgbe_hw_if {
384 int (*tx_complete)(struct xgbe_ring_desc *);
385
386 int (*set_promiscuous_mode)(struct xgbe_prv_data *, unsigned int);
387 int (*set_all_multicast_mode)(struct xgbe_prv_data *, unsigned int);
388 int (*set_addn_mac_addrs)(struct xgbe_prv_data *, unsigned int);
389 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
390
391 int (*enable_rx_csum)(struct xgbe_prv_data *);
392 int (*disable_rx_csum)(struct xgbe_prv_data *);
393
394 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
395 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
396
397 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
398 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
399 int (*set_gmii_speed)(struct xgbe_prv_data *);
400 int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
401 int (*set_xgmii_speed)(struct xgbe_prv_data *);
402
403 void (*enable_tx)(struct xgbe_prv_data *);
404 void (*disable_tx)(struct xgbe_prv_data *);
405 void (*enable_rx)(struct xgbe_prv_data *);
406 void (*disable_rx)(struct xgbe_prv_data *);
407
408 void (*powerup_tx)(struct xgbe_prv_data *);
409 void (*powerdown_tx)(struct xgbe_prv_data *);
410 void (*powerup_rx)(struct xgbe_prv_data *);
411 void (*powerdown_rx)(struct xgbe_prv_data *);
412
413 int (*init)(struct xgbe_prv_data *);
414 int (*exit)(struct xgbe_prv_data *);
415
416 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
417 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
418 void (*pre_xmit)(struct xgbe_channel *);
419 int (*dev_read)(struct xgbe_channel *);
420 void (*tx_desc_init)(struct xgbe_channel *);
421 void (*rx_desc_init)(struct xgbe_channel *);
422 void (*rx_desc_reset)(struct xgbe_ring_data *);
423 void (*tx_desc_reset)(struct xgbe_ring_data *);
424 int (*is_last_desc)(struct xgbe_ring_desc *);
425 int (*is_context_desc)(struct xgbe_ring_desc *);
426
427 /* For FLOW ctrl */
428 int (*config_tx_flow_control)(struct xgbe_prv_data *);
429 int (*config_rx_flow_control)(struct xgbe_prv_data *);
430
431 /* For RX coalescing */
432 int (*config_rx_coalesce)(struct xgbe_prv_data *);
433 int (*config_tx_coalesce)(struct xgbe_prv_data *);
434 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
435 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
436
437 /* For RX and TX threshold config */
438 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
439 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
440
441 /* For RX and TX Store and Forward Mode config */
442 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
443 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
444
445 /* For TX DMA Operate on Second Frame config */
446 int (*config_osp_mode)(struct xgbe_prv_data *);
447
448 /* For RX and TX PBL config */
449 int (*config_rx_pbl_val)(struct xgbe_prv_data *);
450 int (*get_rx_pbl_val)(struct xgbe_prv_data *);
451 int (*config_tx_pbl_val)(struct xgbe_prv_data *);
452 int (*get_tx_pbl_val)(struct xgbe_prv_data *);
453 int (*config_pblx8)(struct xgbe_prv_data *);
454
455 /* For MMC statistics */
456 void (*rx_mmc_int)(struct xgbe_prv_data *);
457 void (*tx_mmc_int)(struct xgbe_prv_data *);
458 void (*read_mmc_stats)(struct xgbe_prv_data *);
459};
460
461struct xgbe_desc_if {
462 int (*alloc_ring_resources)(struct xgbe_prv_data *);
463 void (*free_ring_resources)(struct xgbe_prv_data *);
464 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
465 void (*realloc_skb)(struct xgbe_channel *);
466 void (*unmap_skb)(struct xgbe_prv_data *, struct xgbe_ring_data *);
467 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
468 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
469};
470
471/* This structure contains flags that indicate what hardware features
472 * or configurations are present in the device.
473 */
474struct xgbe_hw_features {
475 /* HW Feature Register0 */
476 unsigned int gmii; /* 1000 Mbps support */
477 unsigned int vlhash; /* VLAN Hash Filter */
478 unsigned int sma; /* SMA(MDIO) Interface */
479 unsigned int rwk; /* PMT remote wake-up packet */
480 unsigned int mgk; /* PMT magic packet */
481 unsigned int mmc; /* RMON module */
482 unsigned int aoe; /* ARP Offload */
483 unsigned int ts; /* IEEE 1588-2008 Adavanced Timestamp */
484 unsigned int eee; /* Energy Efficient Ethernet */
485 unsigned int tx_coe; /* Tx Checksum Offload */
486 unsigned int rx_coe; /* Rx Checksum Offload */
487 unsigned int addn_mac; /* Additional MAC Addresses */
488 unsigned int ts_src; /* Timestamp Source */
489 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
490
491 /* HW Feature Register1 */
492 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
493 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
494 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
495 unsigned int dcb; /* DCB Feature */
496 unsigned int sph; /* Split Header Feature */
497 unsigned int tso; /* TCP Segmentation Offload */
498 unsigned int dma_debug; /* DMA Debug Registers */
499 unsigned int rss; /* Receive Side Scaling */
500 unsigned int hash_table_size; /* Hash Table Size */
501 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
502
503 /* HW Feature Register2 */
504 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
505 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
506 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
507 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
508 unsigned int pps_out_num; /* Number of PPS outputs */
509 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
510};
511
512struct xgbe_prv_data {
513 struct net_device *netdev;
514 struct platform_device *pdev;
515 struct device *dev;
516
517 /* XGMAC/XPCS related mmio registers */
518 void __iomem *xgmac_regs; /* XGMAC CSRs */
519 void __iomem *xpcs_regs; /* XPCS MMD registers */
520
521 /* Overall device lock */
522 spinlock_t lock;
523
524 /* XPCS indirect addressing mutex */
525 struct mutex xpcs_mutex;
526
527 int irq_number;
528
529 struct xgbe_hw_if hw_if;
530 struct xgbe_desc_if desc_if;
531
532 /* Rings for Tx/Rx on a DMA channel */
533 struct xgbe_channel *channel;
534 unsigned int channel_count;
535 unsigned int tx_ring_count;
536 unsigned int tx_desc_count;
537 unsigned int rx_ring_count;
538 unsigned int rx_desc_count;
539
540 /* Tx/Rx common settings */
541 unsigned int pblx8;
542
543 /* Tx settings */
544 unsigned int tx_sf_mode;
545 unsigned int tx_threshold;
546 unsigned int tx_pbl;
547 unsigned int tx_osp_mode;
548
549 /* Rx settings */
550 unsigned int rx_sf_mode;
551 unsigned int rx_threshold;
552 unsigned int rx_pbl;
553
554 /* Tx coalescing settings */
555 unsigned int tx_usecs;
556 unsigned int tx_frames;
557
558 /* Rx coalescing settings */
559 unsigned int rx_riwt;
560 unsigned int rx_frames;
561
562 /* Current MTU */
563 unsigned int rx_buf_size;
564
565 /* Flow control settings */
566 unsigned int pause_autoneg;
567 unsigned int tx_pause;
568 unsigned int rx_pause;
569
570 /* MDIO settings */
571 struct module *phy_module;
572 char *mii_bus_id;
573 struct mii_bus *mii;
574 int mdio_mmd;
575 struct phy_device *phydev;
576 int default_autoneg;
577 int default_speed;
578
579 /* Current PHY settings */
580 phy_interface_t phy_mode;
581 int phy_link;
582 int phy_speed;
583 unsigned int phy_tx_pause;
584 unsigned int phy_rx_pause;
585
586 /* Netdev related settings */
587 netdev_features_t netdev_features;
588 struct napi_struct napi;
589 struct xgbe_mmc_stats mmc_stats;
590
591 /* System clock value used for Rx watchdog */
592 struct clk *sysclock;
593
594 /* Hardware features of the device */
595 struct xgbe_hw_features hw_feat;
596
597 /* Device restart work structure */
598 struct work_struct restart_work;
599
600 /* Keeps track of power mode */
601 unsigned int power_down;
602
603#ifdef CONFIG_DEBUG_FS
604 struct dentry *xgbe_debugfs;
605
606 unsigned int debugfs_xgmac_reg;
607
608 unsigned int debugfs_xpcs_mmd;
609 unsigned int debugfs_xpcs_reg;
610#endif
611};
612
613/* Function prototypes*/
614
615void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
616void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
617struct net_device_ops *xgbe_get_netdev_ops(void);
618struct ethtool_ops *xgbe_get_ethtool_ops(void);
619
620int xgbe_mdio_register(struct xgbe_prv_data *);
621void xgbe_mdio_unregister(struct xgbe_prv_data *);
622void xgbe_dump_phy_registers(struct xgbe_prv_data *);
623void xgbe_dump_tx_desc(struct xgbe_ring *, unsigned int, unsigned int,
624 unsigned int);
625void xgbe_dump_rx_desc(struct xgbe_ring *, struct xgbe_ring_desc *,
626 unsigned int);
627void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
628void xgbe_get_all_hw_features(struct xgbe_prv_data *);
629int xgbe_powerup(struct net_device *, unsigned int);
630int xgbe_powerdown(struct net_device *, unsigned int);
631void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
632void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
633
634#ifdef CONFIG_DEBUG_FS
635void xgbe_debugfs_init(struct xgbe_prv_data *);
636void xgbe_debugfs_exit(struct xgbe_prv_data *);
637#else
638static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
639static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
640#endif /* CONFIG_DEBUG_FS */
641
642/* NOTE: Uncomment for TX and RX DESCRIPTOR DUMP in KERNEL LOG */
643#if 0
644#define XGMAC_ENABLE_TX_DESC_DUMP
645#define XGMAC_ENABLE_RX_DESC_DUMP
646#endif
647
648/* NOTE: Uncomment for TX and RX PACKET DUMP in KERNEL LOG */
649#if 0
650#define XGMAC_ENABLE_TX_PKT_DUMP
651#define XGMAC_ENABLE_RX_PKT_DUMP
652#endif
653
654/* NOTE: Uncomment for function trace log messages in KERNEL LOG */
655#if 0
656#define YDEBUG
657#define YDEBUG_MDIO
658#endif
659
660/* For debug prints */
661#ifdef YDEBUG
662#define DBGPR(x...) pr_alert(x)
663#define DBGPHY_REGS(x...) xgbe_dump_phy_registers(x)
664#else
665#define DBGPR(x...) do { } while (0)
666#define DBGPHY_REGS(x...) do { } while (0)
667#endif
668
669#ifdef YDEBUG_MDIO
670#define DBGPR_MDIO(x...) pr_alert(x)
671#else
672#define DBGPR_MDIO(x...) do { } while (0)
673#endif
674
675#endif