]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/amd/xgbe/xgbe.h
d3aa05501ee8e696c77ea882ff6678851e566087
[karo-tx-linux.git] / drivers / net / ethernet / amd / xgbe / xgbe.h
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>
124 #include <linux/if_vlan.h>
125 #include <linux/bitops.h>
126 #include <linux/ptp_clock_kernel.h>
127 #include <linux/clocksource.h>
128 #include <linux/net_tstamp.h>
129 #include <net/dcbnl.h>
130
131 #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 */
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
140
141 #define XGBE_TX_MAX_BUF_SIZE    (0x3fff & ~(64 - 1))
142
143 #define XGBE_RX_MIN_BUF_SIZE    (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
144 #define XGBE_RX_BUF_ALIGN       64
145 #define XGBE_SKB_ALLOC_SIZE     256
146
147 #define XGBE_MAX_DMA_CHANNELS   16
148 #define XGBE_MAX_QUEUES         16
149
150 /* DMA cache settings - Outer sharable, write-back, write-allocate */
151 #define XGBE_DMA_OS_AXDOMAIN    0x2
152 #define XGBE_DMA_OS_ARCACHE     0xb
153 #define XGBE_DMA_OS_AWCACHE     0xf
154
155 /* DMA cache settings - System, no caches used */
156 #define XGBE_DMA_SYS_AXDOMAIN   0x3
157 #define XGBE_DMA_SYS_ARCACHE    0x0
158 #define XGBE_DMA_SYS_AWCACHE    0x0
159
160 #define XGBE_DMA_INTERRUPT_MASK 0x31c7
161
162 #define XGMAC_MIN_PACKET        60
163 #define XGMAC_STD_PACKET_MTU    1500
164 #define XGMAC_MAX_STD_PACKET    1518
165 #define XGMAC_JUMBO_PACKET_MTU  9000
166 #define XGMAC_MAX_JUMBO_PACKET  9018
167
168 /* MDIO bus phy name */
169 #define XGBE_PHY_NAME           "amd_xgbe_phy"
170 #define XGBE_PRTAD              0
171
172 /* Device-tree clock names */
173 #define XGBE_DMA_CLOCK          "dma_clk"
174 #define XGBE_PTP_CLOCK          "ptp_clk"
175
176 /* Timestamp support - values based on 50MHz PTP clock
177  *   50MHz => 20 nsec
178  */
179 #define XGBE_TSTAMP_SSINC       20
180 #define XGBE_TSTAMP_SNSINC      0
181
182 /* Driver PMT macros */
183 #define XGMAC_DRIVER_CONTEXT    1
184 #define XGMAC_IOCTL_CONTEXT     2
185
186 #define XGBE_FIFO_MAX           81920
187 #define XGBE_FIFO_SIZE_B(x)     (x)
188 #define XGBE_FIFO_SIZE_KB(x)    (x * 1024)
189
190 #define XGBE_TC_MIN_QUANTUM     10
191
192 /* Helper macro for descriptor handling
193  *  Always use XGBE_GET_DESC_DATA to access the descriptor data
194  *  since the index is free-running and needs to be and-ed
195  *  with the descriptor count value of the ring to index to
196  *  the proper descriptor data.
197  */
198 #define XGBE_GET_DESC_DATA(_ring, _idx)                         \
199         ((_ring)->rdata +                                       \
200          ((_idx) & ((_ring)->rdesc_count - 1)))
201
202 /* Default coalescing parameters */
203 #define XGMAC_INIT_DMA_TX_USECS         50
204 #define XGMAC_INIT_DMA_TX_FRAMES        25
205
206 #define XGMAC_MAX_DMA_RIWT              0xff
207 #define XGMAC_INIT_DMA_RX_USECS         30
208 #define XGMAC_INIT_DMA_RX_FRAMES        25
209
210 /* Flow control queue count */
211 #define XGMAC_MAX_FLOW_CONTROL_QUEUES   8
212
213 /* Maximum MAC address hash table size (256 bits = 8 bytes) */
214 #define XGBE_MAC_HASH_TABLE_SIZE        8
215
216 struct xgbe_prv_data;
217
218 struct xgbe_packet_data {
219         unsigned int attributes;
220
221         unsigned int errors;
222
223         unsigned int rdesc_count;
224         unsigned int length;
225
226         unsigned int header_len;
227         unsigned int tcp_header_len;
228         unsigned int tcp_payload_len;
229         unsigned short mss;
230
231         unsigned short vlan_ctag;
232
233         u64 rx_tstamp;
234 };
235
236 /* Common Rx and Tx descriptor mapping */
237 struct xgbe_ring_desc {
238         u32 desc0;
239         u32 desc1;
240         u32 desc2;
241         u32 desc3;
242 };
243
244 /* Page allocation related values */
245 struct xgbe_page_alloc {
246         struct page *pages;
247         unsigned int pages_len;
248         unsigned int pages_offset;
249
250         dma_addr_t pages_dma;
251 };
252
253 /* Structure used to hold information related to the descriptor
254  * and the packet associated with the descriptor (always use
255  * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
256  */
257 struct xgbe_ring_data {
258         struct xgbe_ring_desc *rdesc;   /* Virtual address of descriptor */
259         dma_addr_t rdesc_dma;           /* DMA address of descriptor */
260
261         struct sk_buff *skb;            /* Virtual address of SKB */
262         dma_addr_t skb_dma;             /* DMA address of SKB data */
263         unsigned int skb_dma_len;       /* Length of SKB DMA area */
264         unsigned int tso_header;        /* TSO header indicator */
265
266         struct xgbe_page_alloc rx_pa;   /* Rx buffer page allocation */
267         struct xgbe_page_alloc rx_unmap;
268
269         dma_addr_t rx_dma;              /* DMA address of Rx buffer */
270         unsigned int rx_dma_len;        /* Length of the Rx DMA buffer */
271
272         unsigned short len;             /* Length of received Rx packet */
273
274         unsigned int interrupt;         /* Interrupt indicator */
275
276         unsigned int mapped_as_page;
277
278         /* Incomplete receive save location.  If the budget is exhausted
279          * or the last descriptor (last normal descriptor or a following
280          * context descriptor) has not been DMA'd yet the current state
281          * of the receive processing needs to be saved.
282          */
283         unsigned int state_saved;
284         struct {
285                 unsigned int incomplete;
286                 unsigned int context_next;
287                 struct sk_buff *skb;
288                 unsigned int len;
289                 unsigned int error;
290         } state;
291 };
292
293 struct xgbe_ring {
294         /* Ring lock - used just for TX rings at the moment */
295         spinlock_t lock;
296
297         /* Per packet related information */
298         struct xgbe_packet_data packet_data;
299
300         /* Virtual/DMA addresses and count of allocated descriptor memory */
301         struct xgbe_ring_desc *rdesc;
302         dma_addr_t rdesc_dma;
303         unsigned int rdesc_count;
304
305         /* Array of descriptor data corresponding the descriptor memory
306          * (always use the XGBE_GET_DESC_DATA macro to access this data)
307          */
308         struct xgbe_ring_data *rdata;
309
310         /* Page allocation for RX buffers */
311         struct xgbe_page_alloc rx_pa;
312
313         /* Ring index values
314          *  cur   - Tx: index of descriptor to be used for current transfer
315          *          Rx: index of descriptor to check for packet availability
316          *  dirty - Tx: index of descriptor to check for transfer complete
317          *          Rx: count of descriptors in which a packet has been received
318          *              (used with skb_realloc_index to refresh the ring)
319          */
320         unsigned int cur;
321         unsigned int dirty;
322
323         /* Coalesce frame count used for interrupt bit setting */
324         unsigned int coalesce_count;
325
326         union {
327                 struct {
328                         unsigned int queue_stopped;
329                         unsigned short cur_mss;
330                         unsigned short cur_vlan_ctag;
331                 } tx;
332
333                 struct {
334                         unsigned int realloc_index;
335                         unsigned int realloc_threshold;
336                 } rx;
337         };
338 } ____cacheline_aligned;
339
340 /* Structure used to describe the descriptor rings associated with
341  * a DMA channel.
342  */
343 struct xgbe_channel {
344         char name[16];
345
346         /* Address of private data area for device */
347         struct xgbe_prv_data *pdata;
348
349         /* Queue index and base address of queue's DMA registers */
350         unsigned int queue_index;
351         void __iomem *dma_regs;
352
353         unsigned int saved_ier;
354
355         unsigned int tx_timer_active;
356         struct hrtimer tx_timer;
357
358         struct xgbe_ring *tx_ring;
359         struct xgbe_ring *rx_ring;
360 } ____cacheline_aligned;
361
362 enum xgbe_int {
363         XGMAC_INT_DMA_CH_SR_TI,
364         XGMAC_INT_DMA_CH_SR_TPS,
365         XGMAC_INT_DMA_CH_SR_TBU,
366         XGMAC_INT_DMA_CH_SR_RI,
367         XGMAC_INT_DMA_CH_SR_RBU,
368         XGMAC_INT_DMA_CH_SR_RPS,
369         XGMAC_INT_DMA_CH_SR_TI_RI,
370         XGMAC_INT_DMA_CH_SR_FBE,
371         XGMAC_INT_DMA_ALL,
372 };
373
374 enum xgbe_int_state {
375         XGMAC_INT_STATE_SAVE,
376         XGMAC_INT_STATE_RESTORE,
377 };
378
379 enum xgbe_mtl_fifo_size {
380         XGMAC_MTL_FIFO_SIZE_256  = 0x00,
381         XGMAC_MTL_FIFO_SIZE_512  = 0x01,
382         XGMAC_MTL_FIFO_SIZE_1K   = 0x03,
383         XGMAC_MTL_FIFO_SIZE_2K   = 0x07,
384         XGMAC_MTL_FIFO_SIZE_4K   = 0x0f,
385         XGMAC_MTL_FIFO_SIZE_8K   = 0x1f,
386         XGMAC_MTL_FIFO_SIZE_16K  = 0x3f,
387         XGMAC_MTL_FIFO_SIZE_32K  = 0x7f,
388         XGMAC_MTL_FIFO_SIZE_64K  = 0xff,
389         XGMAC_MTL_FIFO_SIZE_128K = 0x1ff,
390         XGMAC_MTL_FIFO_SIZE_256K = 0x3ff,
391 };
392
393 struct xgbe_mmc_stats {
394         /* Tx Stats */
395         u64 txoctetcount_gb;
396         u64 txframecount_gb;
397         u64 txbroadcastframes_g;
398         u64 txmulticastframes_g;
399         u64 tx64octets_gb;
400         u64 tx65to127octets_gb;
401         u64 tx128to255octets_gb;
402         u64 tx256to511octets_gb;
403         u64 tx512to1023octets_gb;
404         u64 tx1024tomaxoctets_gb;
405         u64 txunicastframes_gb;
406         u64 txmulticastframes_gb;
407         u64 txbroadcastframes_gb;
408         u64 txunderflowerror;
409         u64 txoctetcount_g;
410         u64 txframecount_g;
411         u64 txpauseframes;
412         u64 txvlanframes_g;
413
414         /* Rx Stats */
415         u64 rxframecount_gb;
416         u64 rxoctetcount_gb;
417         u64 rxoctetcount_g;
418         u64 rxbroadcastframes_g;
419         u64 rxmulticastframes_g;
420         u64 rxcrcerror;
421         u64 rxrunterror;
422         u64 rxjabbererror;
423         u64 rxundersize_g;
424         u64 rxoversize_g;
425         u64 rx64octets_gb;
426         u64 rx65to127octets_gb;
427         u64 rx128to255octets_gb;
428         u64 rx256to511octets_gb;
429         u64 rx512to1023octets_gb;
430         u64 rx1024tomaxoctets_gb;
431         u64 rxunicastframes_g;
432         u64 rxlengtherror;
433         u64 rxoutofrangetype;
434         u64 rxpauseframes;
435         u64 rxfifooverflow;
436         u64 rxvlanframes_gb;
437         u64 rxwatchdogerror;
438 };
439
440 struct xgbe_hw_if {
441         int (*tx_complete)(struct xgbe_ring_desc *);
442
443         int (*set_promiscuous_mode)(struct xgbe_prv_data *, unsigned int);
444         int (*set_all_multicast_mode)(struct xgbe_prv_data *, unsigned int);
445         int (*add_mac_addresses)(struct xgbe_prv_data *);
446         int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
447
448         int (*enable_rx_csum)(struct xgbe_prv_data *);
449         int (*disable_rx_csum)(struct xgbe_prv_data *);
450
451         int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
452         int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
453         int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
454         int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
455         int (*update_vlan_hash_table)(struct xgbe_prv_data *);
456
457         int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
458         void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
459         int (*set_gmii_speed)(struct xgbe_prv_data *);
460         int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
461         int (*set_xgmii_speed)(struct xgbe_prv_data *);
462
463         void (*enable_tx)(struct xgbe_prv_data *);
464         void (*disable_tx)(struct xgbe_prv_data *);
465         void (*enable_rx)(struct xgbe_prv_data *);
466         void (*disable_rx)(struct xgbe_prv_data *);
467
468         void (*powerup_tx)(struct xgbe_prv_data *);
469         void (*powerdown_tx)(struct xgbe_prv_data *);
470         void (*powerup_rx)(struct xgbe_prv_data *);
471         void (*powerdown_rx)(struct xgbe_prv_data *);
472
473         int (*init)(struct xgbe_prv_data *);
474         int (*exit)(struct xgbe_prv_data *);
475
476         int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
477         int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
478         void (*dev_xmit)(struct xgbe_channel *);
479         int (*dev_read)(struct xgbe_channel *);
480         void (*tx_desc_init)(struct xgbe_channel *);
481         void (*rx_desc_init)(struct xgbe_channel *);
482         void (*rx_desc_reset)(struct xgbe_ring_data *);
483         void (*tx_desc_reset)(struct xgbe_ring_data *);
484         int (*is_last_desc)(struct xgbe_ring_desc *);
485         int (*is_context_desc)(struct xgbe_ring_desc *);
486
487         /* For FLOW ctrl */
488         int (*config_tx_flow_control)(struct xgbe_prv_data *);
489         int (*config_rx_flow_control)(struct xgbe_prv_data *);
490
491         /* For RX coalescing */
492         int (*config_rx_coalesce)(struct xgbe_prv_data *);
493         int (*config_tx_coalesce)(struct xgbe_prv_data *);
494         unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
495         unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
496
497         /* For RX and TX threshold config */
498         int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
499         int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
500
501         /* For RX and TX Store and Forward Mode config */
502         int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
503         int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
504
505         /* For TX DMA Operate on Second Frame config */
506         int (*config_osp_mode)(struct xgbe_prv_data *);
507
508         /* For RX and TX PBL config */
509         int (*config_rx_pbl_val)(struct xgbe_prv_data *);
510         int (*get_rx_pbl_val)(struct xgbe_prv_data *);
511         int (*config_tx_pbl_val)(struct xgbe_prv_data *);
512         int (*get_tx_pbl_val)(struct xgbe_prv_data *);
513         int (*config_pblx8)(struct xgbe_prv_data *);
514
515         /* For MMC statistics */
516         void (*rx_mmc_int)(struct xgbe_prv_data *);
517         void (*tx_mmc_int)(struct xgbe_prv_data *);
518         void (*read_mmc_stats)(struct xgbe_prv_data *);
519
520         /* For Timestamp config */
521         int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
522         void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
523         void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
524                                 unsigned int nsec);
525         u64 (*get_tstamp_time)(struct xgbe_prv_data *);
526         u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
527
528         /* For Data Center Bridging config */
529         void (*config_dcb_tc)(struct xgbe_prv_data *);
530         void (*config_dcb_pfc)(struct xgbe_prv_data *);
531 };
532
533 struct xgbe_desc_if {
534         int (*alloc_ring_resources)(struct xgbe_prv_data *);
535         void (*free_ring_resources)(struct xgbe_prv_data *);
536         int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
537         void (*realloc_rx_buffer)(struct xgbe_channel *);
538         void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
539         void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
540         void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
541 };
542
543 /* This structure contains flags that indicate what hardware features
544  * or configurations are present in the device.
545  */
546 struct xgbe_hw_features {
547         /* HW Version */
548         unsigned int version;
549
550         /* HW Feature Register0 */
551         unsigned int gmii;              /* 1000 Mbps support */
552         unsigned int vlhash;            /* VLAN Hash Filter */
553         unsigned int sma;               /* SMA(MDIO) Interface */
554         unsigned int rwk;               /* PMT remote wake-up packet */
555         unsigned int mgk;               /* PMT magic packet */
556         unsigned int mmc;               /* RMON module */
557         unsigned int aoe;               /* ARP Offload */
558         unsigned int ts;                /* IEEE 1588-2008 Adavanced Timestamp */
559         unsigned int eee;               /* Energy Efficient Ethernet */
560         unsigned int tx_coe;            /* Tx Checksum Offload */
561         unsigned int rx_coe;            /* Rx Checksum Offload */
562         unsigned int addn_mac;          /* Additional MAC Addresses */
563         unsigned int ts_src;            /* Timestamp Source */
564         unsigned int sa_vlan_ins;       /* Source Address or VLAN Insertion */
565
566         /* HW Feature Register1 */
567         unsigned int rx_fifo_size;      /* MTL Receive FIFO Size */
568         unsigned int tx_fifo_size;      /* MTL Transmit FIFO Size */
569         unsigned int adv_ts_hi;         /* Advance Timestamping High Word */
570         unsigned int dcb;               /* DCB Feature */
571         unsigned int sph;               /* Split Header Feature */
572         unsigned int tso;               /* TCP Segmentation Offload */
573         unsigned int dma_debug;         /* DMA Debug Registers */
574         unsigned int rss;               /* Receive Side Scaling */
575         unsigned int tc_cnt;            /* Number of Traffic Classes */
576         unsigned int hash_table_size;   /* Hash Table Size */
577         unsigned int l3l4_filter_num;   /* Number of L3-L4 Filters */
578
579         /* HW Feature Register2 */
580         unsigned int rx_q_cnt;          /* Number of MTL Receive Queues */
581         unsigned int tx_q_cnt;          /* Number of MTL Transmit Queues */
582         unsigned int rx_ch_cnt;         /* Number of DMA Receive Channels */
583         unsigned int tx_ch_cnt;         /* Number of DMA Transmit Channels */
584         unsigned int pps_out_num;       /* Number of PPS outputs */
585         unsigned int aux_snap_num;      /* Number of Aux snapshot inputs */
586 };
587
588 struct xgbe_prv_data {
589         struct net_device *netdev;
590         struct platform_device *pdev;
591         struct device *dev;
592
593         /* XGMAC/XPCS related mmio registers */
594         void __iomem *xgmac_regs;       /* XGMAC CSRs */
595         void __iomem *xpcs_regs;        /* XPCS MMD registers */
596
597         /* Overall device lock */
598         spinlock_t lock;
599
600         /* XPCS indirect addressing mutex */
601         struct mutex xpcs_mutex;
602
603         int irq_number;
604
605         struct xgbe_hw_if hw_if;
606         struct xgbe_desc_if desc_if;
607
608         /* AXI DMA settings */
609         unsigned int axdomain;
610         unsigned int arcache;
611         unsigned int awcache;
612
613         /* Rings for Tx/Rx on a DMA channel */
614         struct xgbe_channel *channel;
615         unsigned int channel_count;
616         unsigned int tx_ring_count;
617         unsigned int tx_desc_count;
618         unsigned int rx_ring_count;
619         unsigned int rx_desc_count;
620
621         unsigned int tx_q_count;
622         unsigned int rx_q_count;
623
624         /* Tx/Rx common settings */
625         unsigned int pblx8;
626
627         /* Tx settings */
628         unsigned int tx_sf_mode;
629         unsigned int tx_threshold;
630         unsigned int tx_pbl;
631         unsigned int tx_osp_mode;
632
633         /* Rx settings */
634         unsigned int rx_sf_mode;
635         unsigned int rx_threshold;
636         unsigned int rx_pbl;
637
638         /* Tx coalescing settings */
639         unsigned int tx_usecs;
640         unsigned int tx_frames;
641
642         /* Rx coalescing settings */
643         unsigned int rx_riwt;
644         unsigned int rx_frames;
645
646         /* Current Rx buffer size */
647         unsigned int rx_buf_size;
648
649         /* Flow control settings */
650         unsigned int pause_autoneg;
651         unsigned int tx_pause;
652         unsigned int rx_pause;
653
654         /* MDIO settings */
655         struct module *phy_module;
656         char *mii_bus_id;
657         struct mii_bus *mii;
658         int mdio_mmd;
659         struct phy_device *phydev;
660         int default_autoneg;
661         int default_speed;
662
663         /* Current PHY settings */
664         phy_interface_t phy_mode;
665         int phy_link;
666         int phy_speed;
667         unsigned int phy_tx_pause;
668         unsigned int phy_rx_pause;
669
670         /* Netdev related settings */
671         netdev_features_t netdev_features;
672         struct napi_struct napi;
673         struct xgbe_mmc_stats mmc_stats;
674
675         /* Filtering support */
676         unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
677
678         /* Device clocks */
679         struct clk *sysclk;
680         struct clk *ptpclk;
681
682         /* Timestamp support */
683         spinlock_t tstamp_lock;
684         struct ptp_clock_info ptp_clock_info;
685         struct ptp_clock *ptp_clock;
686         struct hwtstamp_config tstamp_config;
687         struct cyclecounter tstamp_cc;
688         struct timecounter tstamp_tc;
689         unsigned int tstamp_addend;
690         struct work_struct tx_tstamp_work;
691         struct sk_buff *tx_tstamp_skb;
692         u64 tx_tstamp;
693
694         /* DCB support */
695         struct ieee_ets *ets;
696         struct ieee_pfc *pfc;
697         unsigned int q2tc_map[XGBE_MAX_QUEUES];
698         unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
699
700         /* Hardware features of the device */
701         struct xgbe_hw_features hw_feat;
702
703         /* Device restart work structure */
704         struct work_struct restart_work;
705
706         /* Keeps track of power mode */
707         unsigned int power_down;
708
709 #ifdef CONFIG_DEBUG_FS
710         struct dentry *xgbe_debugfs;
711
712         unsigned int debugfs_xgmac_reg;
713
714         unsigned int debugfs_xpcs_mmd;
715         unsigned int debugfs_xpcs_reg;
716 #endif
717 };
718
719 /* Function prototypes*/
720
721 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
722 void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
723 struct net_device_ops *xgbe_get_netdev_ops(void);
724 struct ethtool_ops *xgbe_get_ethtool_ops(void);
725 #ifdef CONFIG_AMD_XGBE_DCB
726 const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
727 #endif
728
729 int xgbe_mdio_register(struct xgbe_prv_data *);
730 void xgbe_mdio_unregister(struct xgbe_prv_data *);
731 void xgbe_dump_phy_registers(struct xgbe_prv_data *);
732 void xgbe_ptp_register(struct xgbe_prv_data *);
733 void xgbe_ptp_unregister(struct xgbe_prv_data *);
734 void xgbe_dump_tx_desc(struct xgbe_ring *, unsigned int, unsigned int,
735                        unsigned int);
736 void xgbe_dump_rx_desc(struct xgbe_ring *, struct xgbe_ring_desc *,
737                        unsigned int);
738 void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
739 void xgbe_get_all_hw_features(struct xgbe_prv_data *);
740 int xgbe_powerup(struct net_device *, unsigned int);
741 int xgbe_powerdown(struct net_device *, unsigned int);
742 void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
743 void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
744
745 #ifdef CONFIG_DEBUG_FS
746 void xgbe_debugfs_init(struct xgbe_prv_data *);
747 void xgbe_debugfs_exit(struct xgbe_prv_data *);
748 #else
749 static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
750 static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
751 #endif /* CONFIG_DEBUG_FS */
752
753 /* NOTE: Uncomment for TX and RX DESCRIPTOR DUMP in KERNEL LOG */
754 #if 0
755 #define XGMAC_ENABLE_TX_DESC_DUMP
756 #define XGMAC_ENABLE_RX_DESC_DUMP
757 #endif
758
759 /* NOTE: Uncomment for TX and RX PACKET DUMP in KERNEL LOG */
760 #if 0
761 #define XGMAC_ENABLE_TX_PKT_DUMP
762 #define XGMAC_ENABLE_RX_PKT_DUMP
763 #endif
764
765 /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
766 #if 0
767 #define YDEBUG
768 #define YDEBUG_MDIO
769 #endif
770
771 /* For debug prints */
772 #ifdef YDEBUG
773 #define DBGPR(x...) pr_alert(x)
774 #define DBGPHY_REGS(x...) xgbe_dump_phy_registers(x)
775 #else
776 #define DBGPR(x...) do { } while (0)
777 #define DBGPHY_REGS(x...) do { } while (0)
778 #endif
779
780 #ifdef YDEBUG_MDIO
781 #define DBGPR_MDIO(x...) pr_alert(x)
782 #else
783 #define DBGPR_MDIO(x...) do { } while (0)
784 #endif
785
786 #endif