Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * AMD 10Gb Ethernet driver
0003  *
0004  * This file is available to you under your choice of the following two
0005  * licenses:
0006  *
0007  * License 1: GPLv2
0008  *
0009  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
0010  *
0011  * This file is free software; you may copy, redistribute and/or modify
0012  * it under the terms of the GNU General Public License as published by
0013  * the Free Software Foundation, either version 2 of the License, or (at
0014  * your option) any later version.
0015  *
0016  * This file is distributed in the hope that it will be useful, but
0017  * WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019  * General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU General Public License
0022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0023  *
0024  * This file incorporates work covered by the following copyright and
0025  * permission notice:
0026  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
0027  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
0028  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
0029  *     and you.
0030  *
0031  *     The Software IS NOT an item of Licensed Software or Licensed Product
0032  *     under any End User Software License Agreement or Agreement for Licensed
0033  *     Product with Synopsys or any supplement thereto.  Permission is hereby
0034  *     granted, free of charge, to any person obtaining a copy of this software
0035  *     annotated with this license and the Software, to deal in the Software
0036  *     without restriction, including without limitation the rights to use,
0037  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
0038  *     of the Software, and to permit persons to whom the Software is furnished
0039  *     to do so, subject to the following conditions:
0040  *
0041  *     The above copyright notice and this permission notice shall be included
0042  *     in all copies or substantial portions of the Software.
0043  *
0044  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
0045  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0046  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0047  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
0048  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0049  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0050  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0051  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0052  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0053  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
0054  *     THE POSSIBILITY OF SUCH DAMAGE.
0055  *
0056  *
0057  * License 2: Modified BSD
0058  *
0059  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
0060  * All rights reserved.
0061  *
0062  * Redistribution and use in source and binary forms, with or without
0063  * modification, are permitted provided that the following conditions are met:
0064  *     * Redistributions of source code must retain the above copyright
0065  *       notice, this list of conditions and the following disclaimer.
0066  *     * Redistributions in binary form must reproduce the above copyright
0067  *       notice, this list of conditions and the following disclaimer in the
0068  *       documentation and/or other materials provided with the distribution.
0069  *     * Neither the name of Advanced Micro Devices, Inc. nor the
0070  *       names of its contributors may be used to endorse or promote products
0071  *       derived from this software without specific prior written permission.
0072  *
0073  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0074  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0075  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0076  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
0077  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0078  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0079  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0080  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0081  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0082  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0083  *
0084  * This file incorporates work covered by the following copyright and
0085  * permission notice:
0086  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
0087  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
0088  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
0089  *     and you.
0090  *
0091  *     The Software IS NOT an item of Licensed Software or Licensed Product
0092  *     under any End User Software License Agreement or Agreement for Licensed
0093  *     Product with Synopsys or any supplement thereto.  Permission is hereby
0094  *     granted, free of charge, to any person obtaining a copy of this software
0095  *     annotated with this license and the Software, to deal in the Software
0096  *     without restriction, including without limitation the rights to use,
0097  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
0098  *     of the Software, and to permit persons to whom the Software is furnished
0099  *     to do so, subject to the following conditions:
0100  *
0101  *     The above copyright notice and this permission notice shall be included
0102  *     in all copies or substantial portions of the Software.
0103  *
0104  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
0105  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0106  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0107  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
0108  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0109  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0110  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0111  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0112  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0113  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
0114  *     THE POSSIBILITY OF SUCH DAMAGE.
0115  */
0116 
0117 #ifndef __XGBE_H__
0118 #define __XGBE_H__
0119 
0120 #include <linux/dma-mapping.h>
0121 #include <linux/netdevice.h>
0122 #include <linux/workqueue.h>
0123 #include <linux/phy.h>
0124 #include <linux/if_vlan.h>
0125 #include <linux/bitops.h>
0126 #include <linux/ptp_clock_kernel.h>
0127 #include <linux/timecounter.h>
0128 #include <linux/net_tstamp.h>
0129 #include <net/dcbnl.h>
0130 #include <linux/completion.h>
0131 #include <linux/cpumask.h>
0132 #include <linux/interrupt.h>
0133 #include <linux/dcache.h>
0134 #include <linux/ethtool.h>
0135 #include <linux/list.h>
0136 
0137 #define XGBE_DRV_NAME       "amd-xgbe"
0138 #define XGBE_DRV_DESC       "AMD 10 Gigabit Ethernet Driver"
0139 
0140 /* Descriptor related defines */
0141 #define XGBE_TX_DESC_CNT    512
0142 #define XGBE_TX_DESC_MIN_FREE   (XGBE_TX_DESC_CNT >> 3)
0143 #define XGBE_TX_DESC_MAX_PROC   (XGBE_TX_DESC_CNT >> 1)
0144 #define XGBE_RX_DESC_CNT    512
0145 
0146 #define XGBE_TX_DESC_CNT_MIN    64
0147 #define XGBE_TX_DESC_CNT_MAX    4096
0148 #define XGBE_RX_DESC_CNT_MIN    64
0149 #define XGBE_RX_DESC_CNT_MAX    4096
0150 
0151 #define XGBE_TX_MAX_BUF_SIZE    (0x3fff & ~(64 - 1))
0152 
0153 /* Descriptors required for maximum contiguous TSO/GSO packet */
0154 #define XGBE_TX_MAX_SPLIT   \
0155     ((GSO_LEGACY_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
0156 
0157 /* Maximum possible descriptors needed for an SKB:
0158  * - Maximum number of SKB frags
0159  * - Maximum descriptors for contiguous TSO/GSO packet
0160  * - Possible context descriptor
0161  * - Possible TSO header descriptor
0162  */
0163 #define XGBE_TX_MAX_DESCS   (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
0164 
0165 #define XGBE_RX_MIN_BUF_SIZE    (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
0166 #define XGBE_RX_BUF_ALIGN   64
0167 #define XGBE_SKB_ALLOC_SIZE 256
0168 #define XGBE_SPH_HDSMS_SIZE 2   /* Keep in sync with SKB_ALLOC_SIZE */
0169 
0170 #define XGBE_MAX_DMA_CHANNELS   16
0171 #define XGBE_MAX_QUEUES     16
0172 #define XGBE_PRIORITY_QUEUES    8
0173 #define XGBE_DMA_STOP_TIMEOUT   1
0174 
0175 /* DMA cache settings - Outer sharable, write-back, write-allocate */
0176 #define XGBE_DMA_OS_ARCR    0x002b2b2b
0177 #define XGBE_DMA_OS_AWCR    0x2f2f2f2f
0178 
0179 /* DMA cache settings - System, no caches used */
0180 #define XGBE_DMA_SYS_ARCR   0x00303030
0181 #define XGBE_DMA_SYS_AWCR   0x30303030
0182 
0183 /* DMA cache settings - PCI device */
0184 #define XGBE_DMA_PCI_ARCR   0x000f0f0f
0185 #define XGBE_DMA_PCI_AWCR   0x0f0f0f0f
0186 #define XGBE_DMA_PCI_AWARCR 0x00000f0f
0187 
0188 /* DMA channel interrupt modes */
0189 #define XGBE_IRQ_MODE_EDGE  0
0190 #define XGBE_IRQ_MODE_LEVEL 1
0191 
0192 #define XGMAC_MIN_PACKET    60
0193 #define XGMAC_STD_PACKET_MTU    1500
0194 #define XGMAC_MAX_STD_PACKET    1518
0195 #define XGMAC_JUMBO_PACKET_MTU  9000
0196 #define XGMAC_MAX_JUMBO_PACKET  9018
0197 #define XGMAC_ETH_PREAMBLE  (12 + 8)    /* Inter-frame gap + preamble */
0198 
0199 #define XGMAC_PFC_DATA_LEN  46
0200 #define XGMAC_PFC_DELAYS    14000
0201 
0202 #define XGMAC_PRIO_QUEUES(_cnt)                 \
0203     min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
0204 
0205 /* Common property names */
0206 #define XGBE_MAC_ADDR_PROPERTY  "mac-address"
0207 #define XGBE_PHY_MODE_PROPERTY  "phy-mode"
0208 #define XGBE_DMA_IRQS_PROPERTY  "amd,per-channel-interrupt"
0209 #define XGBE_SPEEDSET_PROPERTY  "amd,speed-set"
0210 
0211 /* Device-tree clock names */
0212 #define XGBE_DMA_CLOCK      "dma_clk"
0213 #define XGBE_PTP_CLOCK      "ptp_clk"
0214 
0215 /* ACPI property names */
0216 #define XGBE_ACPI_DMA_FREQ  "amd,dma-freq"
0217 #define XGBE_ACPI_PTP_FREQ  "amd,ptp-freq"
0218 
0219 /* PCI BAR mapping */
0220 #define XGBE_XGMAC_BAR      0
0221 #define XGBE_XPCS_BAR       1
0222 #define XGBE_MAC_PROP_OFFSET    0x1d000
0223 #define XGBE_I2C_CTRL_OFFSET    0x1e000
0224 
0225 /* PCI MSI/MSIx support */
0226 #define XGBE_MSI_BASE_COUNT 4
0227 #define XGBE_MSI_MIN_COUNT  (XGBE_MSI_BASE_COUNT + 1)
0228 
0229 /* PCI clock frequencies */
0230 #define XGBE_V2_DMA_CLOCK_FREQ  500000000   /* 500 MHz */
0231 #define XGBE_V2_PTP_CLOCK_FREQ  125000000   /* 125 MHz */
0232 
0233 /* Timestamp support - values based on 50MHz PTP clock
0234  *   50MHz => 20 nsec
0235  */
0236 #define XGBE_TSTAMP_SSINC   20
0237 #define XGBE_TSTAMP_SNSINC  0
0238 
0239 /* Driver PMT macros */
0240 #define XGMAC_DRIVER_CONTEXT    1
0241 #define XGMAC_IOCTL_CONTEXT 2
0242 
0243 #define XGMAC_FIFO_MIN_ALLOC    2048
0244 #define XGMAC_FIFO_UNIT     256
0245 #define XGMAC_FIFO_ALIGN(_x)                \
0246     (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
0247 #define XGMAC_FIFO_FC_OFF   2048
0248 #define XGMAC_FIFO_FC_MIN   4096
0249 
0250 #define XGBE_TC_MIN_QUANTUM 10
0251 
0252 /* Helper macro for descriptor handling
0253  *  Always use XGBE_GET_DESC_DATA to access the descriptor data
0254  *  since the index is free-running and needs to be and-ed
0255  *  with the descriptor count value of the ring to index to
0256  *  the proper descriptor data.
0257  */
0258 #define XGBE_GET_DESC_DATA(_ring, _idx)             \
0259     ((_ring)->rdata +                   \
0260      ((_idx) & ((_ring)->rdesc_count - 1)))
0261 
0262 /* Default coalescing parameters */
0263 #define XGMAC_INIT_DMA_TX_USECS     1000
0264 #define XGMAC_INIT_DMA_TX_FRAMES    25
0265 
0266 #define XGMAC_MAX_DMA_RIWT      0xff
0267 #define XGMAC_INIT_DMA_RX_USECS     30
0268 #define XGMAC_INIT_DMA_RX_FRAMES    25
0269 
0270 /* Flow control queue count */
0271 #define XGMAC_MAX_FLOW_CONTROL_QUEUES   8
0272 
0273 /* Flow control threshold units */
0274 #define XGMAC_FLOW_CONTROL_UNIT     512
0275 #define XGMAC_FLOW_CONTROL_ALIGN(_x)                \
0276     (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
0277 #define XGMAC_FLOW_CONTROL_VALUE(_x)                \
0278     (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
0279 #define XGMAC_FLOW_CONTROL_MAX      33280
0280 
0281 /* Maximum MAC address hash table size (256 bits = 8 bytes) */
0282 #define XGBE_MAC_HASH_TABLE_SIZE    8
0283 
0284 /* Receive Side Scaling */
0285 #define XGBE_RSS_HASH_KEY_SIZE      40
0286 #define XGBE_RSS_MAX_TABLE_SIZE     256
0287 #define XGBE_RSS_LOOKUP_TABLE_TYPE  0
0288 #define XGBE_RSS_HASH_KEY_TYPE      1
0289 
0290 /* Auto-negotiation */
0291 #define XGBE_AN_MS_TIMEOUT      500
0292 #define XGBE_LINK_TIMEOUT       5
0293 
0294 #define XGBE_SGMII_AN_LINK_STATUS   BIT(1)
0295 #define XGBE_SGMII_AN_LINK_SPEED    (BIT(2) | BIT(3))
0296 #define XGBE_SGMII_AN_LINK_SPEED_100    0x04
0297 #define XGBE_SGMII_AN_LINK_SPEED_1000   0x08
0298 #define XGBE_SGMII_AN_LINK_DUPLEX   BIT(4)
0299 
0300 /* ECC correctable error notification window (seconds) */
0301 #define XGBE_ECC_LIMIT          60
0302 
0303 /* MDIO port types */
0304 #define XGMAC_MAX_C22_PORT      3
0305 
0306 /* Link mode bit operations */
0307 #define XGBE_ZERO_SUP(_ls)      \
0308     ethtool_link_ksettings_zero_link_mode((_ls), supported)
0309 
0310 #define XGBE_SET_SUP(_ls, _mode)    \
0311     ethtool_link_ksettings_add_link_mode((_ls), supported, _mode)
0312 
0313 #define XGBE_CLR_SUP(_ls, _mode)    \
0314     ethtool_link_ksettings_del_link_mode((_ls), supported, _mode)
0315 
0316 #define XGBE_IS_SUP(_ls, _mode) \
0317     ethtool_link_ksettings_test_link_mode((_ls), supported, _mode)
0318 
0319 #define XGBE_ZERO_ADV(_ls)      \
0320     ethtool_link_ksettings_zero_link_mode((_ls), advertising)
0321 
0322 #define XGBE_SET_ADV(_ls, _mode)    \
0323     ethtool_link_ksettings_add_link_mode((_ls), advertising, _mode)
0324 
0325 #define XGBE_CLR_ADV(_ls, _mode)    \
0326     ethtool_link_ksettings_del_link_mode((_ls), advertising, _mode)
0327 
0328 #define XGBE_ADV(_ls, _mode)        \
0329     ethtool_link_ksettings_test_link_mode((_ls), advertising, _mode)
0330 
0331 #define XGBE_ZERO_LP_ADV(_ls)       \
0332     ethtool_link_ksettings_zero_link_mode((_ls), lp_advertising)
0333 
0334 #define XGBE_SET_LP_ADV(_ls, _mode) \
0335     ethtool_link_ksettings_add_link_mode((_ls), lp_advertising, _mode)
0336 
0337 #define XGBE_CLR_LP_ADV(_ls, _mode) \
0338     ethtool_link_ksettings_del_link_mode((_ls), lp_advertising, _mode)
0339 
0340 #define XGBE_LP_ADV(_ls, _mode)     \
0341     ethtool_link_ksettings_test_link_mode((_ls), lp_advertising, _mode)
0342 
0343 #define XGBE_LM_COPY(_dst, _dname, _src, _sname)    \
0344     bitmap_copy((_dst)->link_modes._dname,      \
0345             (_src)->link_modes._sname,      \
0346             __ETHTOOL_LINK_MODE_MASK_NBITS)
0347 
0348 struct xgbe_prv_data;
0349 
0350 struct xgbe_packet_data {
0351     struct sk_buff *skb;
0352 
0353     unsigned int attributes;
0354 
0355     unsigned int errors;
0356 
0357     unsigned int rdesc_count;
0358     unsigned int length;
0359 
0360     unsigned int header_len;
0361     unsigned int tcp_header_len;
0362     unsigned int tcp_payload_len;
0363     unsigned short mss;
0364 
0365     unsigned short vlan_ctag;
0366 
0367     u64 rx_tstamp;
0368 
0369     u32 rss_hash;
0370     enum pkt_hash_types rss_hash_type;
0371 
0372     unsigned int tx_packets;
0373     unsigned int tx_bytes;
0374 };
0375 
0376 /* Common Rx and Tx descriptor mapping */
0377 struct xgbe_ring_desc {
0378     __le32 desc0;
0379     __le32 desc1;
0380     __le32 desc2;
0381     __le32 desc3;
0382 };
0383 
0384 /* Page allocation related values */
0385 struct xgbe_page_alloc {
0386     struct page *pages;
0387     unsigned int pages_len;
0388     unsigned int pages_offset;
0389 
0390     dma_addr_t pages_dma;
0391 };
0392 
0393 /* Ring entry buffer data */
0394 struct xgbe_buffer_data {
0395     struct xgbe_page_alloc pa;
0396     struct xgbe_page_alloc pa_unmap;
0397 
0398     dma_addr_t dma_base;
0399     unsigned long dma_off;
0400     unsigned int dma_len;
0401 };
0402 
0403 /* Tx-related ring data */
0404 struct xgbe_tx_ring_data {
0405     unsigned int packets;       /* BQL packet count */
0406     unsigned int bytes;     /* BQL byte count */
0407 };
0408 
0409 /* Rx-related ring data */
0410 struct xgbe_rx_ring_data {
0411     struct xgbe_buffer_data hdr;    /* Header locations */
0412     struct xgbe_buffer_data buf;    /* Payload locations */
0413 
0414     unsigned short hdr_len;     /* Length of received header */
0415     unsigned short len;     /* Length of received packet */
0416 };
0417 
0418 /* Structure used to hold information related to the descriptor
0419  * and the packet associated with the descriptor (always use
0420  * the XGBE_GET_DESC_DATA macro to access this data from the ring)
0421  */
0422 struct xgbe_ring_data {
0423     struct xgbe_ring_desc *rdesc;   /* Virtual address of descriptor */
0424     dma_addr_t rdesc_dma;       /* DMA address of descriptor */
0425 
0426     struct sk_buff *skb;        /* Virtual address of SKB */
0427     dma_addr_t skb_dma;     /* DMA address of SKB data */
0428     unsigned int skb_dma_len;   /* Length of SKB DMA area */
0429 
0430     struct xgbe_tx_ring_data tx;    /* Tx-related data */
0431     struct xgbe_rx_ring_data rx;    /* Rx-related data */
0432 
0433     unsigned int mapped_as_page;
0434 
0435     /* Incomplete receive save location.  If the budget is exhausted
0436      * or the last descriptor (last normal descriptor or a following
0437      * context descriptor) has not been DMA'd yet the current state
0438      * of the receive processing needs to be saved.
0439      */
0440     unsigned int state_saved;
0441     struct {
0442         struct sk_buff *skb;
0443         unsigned int len;
0444         unsigned int error;
0445     } state;
0446 };
0447 
0448 struct xgbe_ring {
0449     /* Ring lock - used just for TX rings at the moment */
0450     spinlock_t lock;
0451 
0452     /* Per packet related information */
0453     struct xgbe_packet_data packet_data;
0454 
0455     /* Virtual/DMA addresses and count of allocated descriptor memory */
0456     struct xgbe_ring_desc *rdesc;
0457     dma_addr_t rdesc_dma;
0458     unsigned int rdesc_count;
0459 
0460     /* Array of descriptor data corresponding the descriptor memory
0461      * (always use the XGBE_GET_DESC_DATA macro to access this data)
0462      */
0463     struct xgbe_ring_data *rdata;
0464 
0465     /* Page allocation for RX buffers */
0466     struct xgbe_page_alloc rx_hdr_pa;
0467     struct xgbe_page_alloc rx_buf_pa;
0468     int node;
0469 
0470     /* Ring index values
0471      *  cur   - Tx: index of descriptor to be used for current transfer
0472      *          Rx: index of descriptor to check for packet availability
0473      *  dirty - Tx: index of descriptor to check for transfer complete
0474      *          Rx: index of descriptor to check for buffer reallocation
0475      */
0476     unsigned int cur;
0477     unsigned int dirty;
0478 
0479     /* Coalesce frame count used for interrupt bit setting */
0480     unsigned int coalesce_count;
0481 
0482     union {
0483         struct {
0484             unsigned int queue_stopped;
0485             unsigned int xmit_more;
0486             unsigned short cur_mss;
0487             unsigned short cur_vlan_ctag;
0488         } tx;
0489     };
0490 } ____cacheline_aligned;
0491 
0492 /* Structure used to describe the descriptor rings associated with
0493  * a DMA channel.
0494  */
0495 struct xgbe_channel {
0496     char name[16];
0497 
0498     /* Address of private data area for device */
0499     struct xgbe_prv_data *pdata;
0500 
0501     /* Queue index and base address of queue's DMA registers */
0502     unsigned int queue_index;
0503     void __iomem *dma_regs;
0504 
0505     /* Per channel interrupt irq number */
0506     int dma_irq;
0507     char dma_irq_name[IFNAMSIZ + 32];
0508 
0509     /* Netdev related settings */
0510     struct napi_struct napi;
0511 
0512     /* Per channel interrupt enablement tracker */
0513     unsigned int curr_ier;
0514     unsigned int saved_ier;
0515 
0516     unsigned int tx_timer_active;
0517     struct timer_list tx_timer;
0518 
0519     struct xgbe_ring *tx_ring;
0520     struct xgbe_ring *rx_ring;
0521 
0522     int node;
0523     cpumask_t affinity_mask;
0524 } ____cacheline_aligned;
0525 
0526 enum xgbe_state {
0527     XGBE_DOWN,
0528     XGBE_LINK_INIT,
0529     XGBE_LINK_ERR,
0530     XGBE_STOPPED,
0531 };
0532 
0533 enum xgbe_int {
0534     XGMAC_INT_DMA_CH_SR_TI,
0535     XGMAC_INT_DMA_CH_SR_TPS,
0536     XGMAC_INT_DMA_CH_SR_TBU,
0537     XGMAC_INT_DMA_CH_SR_RI,
0538     XGMAC_INT_DMA_CH_SR_RBU,
0539     XGMAC_INT_DMA_CH_SR_RPS,
0540     XGMAC_INT_DMA_CH_SR_TI_RI,
0541     XGMAC_INT_DMA_CH_SR_FBE,
0542     XGMAC_INT_DMA_ALL,
0543 };
0544 
0545 enum xgbe_int_state {
0546     XGMAC_INT_STATE_SAVE,
0547     XGMAC_INT_STATE_RESTORE,
0548 };
0549 
0550 enum xgbe_ecc_sec {
0551     XGBE_ECC_SEC_TX,
0552     XGBE_ECC_SEC_RX,
0553     XGBE_ECC_SEC_DESC,
0554 };
0555 
0556 enum xgbe_speed {
0557     XGBE_SPEED_1000 = 0,
0558     XGBE_SPEED_2500,
0559     XGBE_SPEED_10000,
0560     XGBE_SPEEDS,
0561 };
0562 
0563 enum xgbe_xpcs_access {
0564     XGBE_XPCS_ACCESS_V1 = 0,
0565     XGBE_XPCS_ACCESS_V2,
0566 };
0567 
0568 enum xgbe_an_mode {
0569     XGBE_AN_MODE_CL73 = 0,
0570     XGBE_AN_MODE_CL73_REDRV,
0571     XGBE_AN_MODE_CL37,
0572     XGBE_AN_MODE_CL37_SGMII,
0573     XGBE_AN_MODE_NONE,
0574 };
0575 
0576 enum xgbe_an {
0577     XGBE_AN_READY = 0,
0578     XGBE_AN_PAGE_RECEIVED,
0579     XGBE_AN_INCOMPAT_LINK,
0580     XGBE_AN_COMPLETE,
0581     XGBE_AN_NO_LINK,
0582     XGBE_AN_ERROR,
0583 };
0584 
0585 enum xgbe_rx {
0586     XGBE_RX_BPA = 0,
0587     XGBE_RX_XNP,
0588     XGBE_RX_COMPLETE,
0589     XGBE_RX_ERROR,
0590 };
0591 
0592 enum xgbe_mode {
0593     XGBE_MODE_KX_1000 = 0,
0594     XGBE_MODE_KX_2500,
0595     XGBE_MODE_KR,
0596     XGBE_MODE_X,
0597     XGBE_MODE_SGMII_100,
0598     XGBE_MODE_SGMII_1000,
0599     XGBE_MODE_SFI,
0600     XGBE_MODE_UNKNOWN,
0601 };
0602 
0603 enum xgbe_speedset {
0604     XGBE_SPEEDSET_1000_10000 = 0,
0605     XGBE_SPEEDSET_2500_10000,
0606 };
0607 
0608 enum xgbe_mdio_mode {
0609     XGBE_MDIO_MODE_NONE = 0,
0610     XGBE_MDIO_MODE_CL22,
0611     XGBE_MDIO_MODE_CL45,
0612 };
0613 
0614 struct xgbe_phy {
0615     struct ethtool_link_ksettings lks;
0616 
0617     int address;
0618 
0619     int autoneg;
0620     int speed;
0621     int duplex;
0622 
0623     int link;
0624 
0625     int pause_autoneg;
0626     int tx_pause;
0627     int rx_pause;
0628 };
0629 
0630 enum xgbe_i2c_cmd {
0631     XGBE_I2C_CMD_READ = 0,
0632     XGBE_I2C_CMD_WRITE,
0633 };
0634 
0635 struct xgbe_i2c_op {
0636     enum xgbe_i2c_cmd cmd;
0637 
0638     unsigned int target;
0639 
0640     void *buf;
0641     unsigned int len;
0642 };
0643 
0644 struct xgbe_i2c_op_state {
0645     struct xgbe_i2c_op *op;
0646 
0647     unsigned int tx_len;
0648     unsigned char *tx_buf;
0649 
0650     unsigned int rx_len;
0651     unsigned char *rx_buf;
0652 
0653     unsigned int tx_abort_source;
0654 
0655     int ret;
0656 };
0657 
0658 struct xgbe_i2c {
0659     unsigned int started;
0660     unsigned int max_speed_mode;
0661     unsigned int rx_fifo_size;
0662     unsigned int tx_fifo_size;
0663 
0664     struct xgbe_i2c_op_state op_state;
0665 };
0666 
0667 struct xgbe_mmc_stats {
0668     /* Tx Stats */
0669     u64 txoctetcount_gb;
0670     u64 txframecount_gb;
0671     u64 txbroadcastframes_g;
0672     u64 txmulticastframes_g;
0673     u64 tx64octets_gb;
0674     u64 tx65to127octets_gb;
0675     u64 tx128to255octets_gb;
0676     u64 tx256to511octets_gb;
0677     u64 tx512to1023octets_gb;
0678     u64 tx1024tomaxoctets_gb;
0679     u64 txunicastframes_gb;
0680     u64 txmulticastframes_gb;
0681     u64 txbroadcastframes_gb;
0682     u64 txunderflowerror;
0683     u64 txoctetcount_g;
0684     u64 txframecount_g;
0685     u64 txpauseframes;
0686     u64 txvlanframes_g;
0687 
0688     /* Rx Stats */
0689     u64 rxframecount_gb;
0690     u64 rxoctetcount_gb;
0691     u64 rxoctetcount_g;
0692     u64 rxbroadcastframes_g;
0693     u64 rxmulticastframes_g;
0694     u64 rxcrcerror;
0695     u64 rxrunterror;
0696     u64 rxjabbererror;
0697     u64 rxundersize_g;
0698     u64 rxoversize_g;
0699     u64 rx64octets_gb;
0700     u64 rx65to127octets_gb;
0701     u64 rx128to255octets_gb;
0702     u64 rx256to511octets_gb;
0703     u64 rx512to1023octets_gb;
0704     u64 rx1024tomaxoctets_gb;
0705     u64 rxunicastframes_g;
0706     u64 rxlengtherror;
0707     u64 rxoutofrangetype;
0708     u64 rxpauseframes;
0709     u64 rxfifooverflow;
0710     u64 rxvlanframes_gb;
0711     u64 rxwatchdogerror;
0712 };
0713 
0714 struct xgbe_ext_stats {
0715     u64 tx_tso_packets;
0716     u64 rx_split_header_packets;
0717     u64 rx_buffer_unavailable;
0718 
0719     u64 txq_packets[XGBE_MAX_DMA_CHANNELS];
0720     u64 txq_bytes[XGBE_MAX_DMA_CHANNELS];
0721     u64 rxq_packets[XGBE_MAX_DMA_CHANNELS];
0722     u64 rxq_bytes[XGBE_MAX_DMA_CHANNELS];
0723 
0724     u64 tx_vxlan_packets;
0725     u64 rx_vxlan_packets;
0726     u64 rx_csum_errors;
0727     u64 rx_vxlan_csum_errors;
0728 };
0729 
0730 struct xgbe_hw_if {
0731     int (*tx_complete)(struct xgbe_ring_desc *);
0732 
0733     int (*set_mac_address)(struct xgbe_prv_data *, const u8 *addr);
0734     int (*config_rx_mode)(struct xgbe_prv_data *);
0735 
0736     int (*enable_rx_csum)(struct xgbe_prv_data *);
0737     int (*disable_rx_csum)(struct xgbe_prv_data *);
0738 
0739     int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
0740     int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
0741     int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
0742     int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
0743     int (*update_vlan_hash_table)(struct xgbe_prv_data *);
0744 
0745     int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
0746     void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
0747     int (*set_speed)(struct xgbe_prv_data *, int);
0748 
0749     int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
0750                 enum xgbe_mdio_mode);
0751     int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
0752     int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, u16);
0753 
0754     int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
0755     int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
0756 
0757     void (*enable_tx)(struct xgbe_prv_data *);
0758     void (*disable_tx)(struct xgbe_prv_data *);
0759     void (*enable_rx)(struct xgbe_prv_data *);
0760     void (*disable_rx)(struct xgbe_prv_data *);
0761 
0762     void (*powerup_tx)(struct xgbe_prv_data *);
0763     void (*powerdown_tx)(struct xgbe_prv_data *);
0764     void (*powerup_rx)(struct xgbe_prv_data *);
0765     void (*powerdown_rx)(struct xgbe_prv_data *);
0766 
0767     int (*init)(struct xgbe_prv_data *);
0768     int (*exit)(struct xgbe_prv_data *);
0769 
0770     int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
0771     int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
0772     void (*dev_xmit)(struct xgbe_channel *);
0773     int (*dev_read)(struct xgbe_channel *);
0774     void (*tx_desc_init)(struct xgbe_channel *);
0775     void (*rx_desc_init)(struct xgbe_channel *);
0776     void (*tx_desc_reset)(struct xgbe_ring_data *);
0777     void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
0778                   unsigned int);
0779     int (*is_last_desc)(struct xgbe_ring_desc *);
0780     int (*is_context_desc)(struct xgbe_ring_desc *);
0781     void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
0782 
0783     /* For FLOW ctrl */
0784     int (*config_tx_flow_control)(struct xgbe_prv_data *);
0785     int (*config_rx_flow_control)(struct xgbe_prv_data *);
0786 
0787     /* For RX coalescing */
0788     int (*config_rx_coalesce)(struct xgbe_prv_data *);
0789     int (*config_tx_coalesce)(struct xgbe_prv_data *);
0790     unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
0791     unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
0792 
0793     /* For RX and TX threshold config */
0794     int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
0795     int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
0796 
0797     /* For RX and TX Store and Forward Mode config */
0798     int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
0799     int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
0800 
0801     /* For TX DMA Operate on Second Frame config */
0802     int (*config_osp_mode)(struct xgbe_prv_data *);
0803 
0804     /* For MMC statistics */
0805     void (*rx_mmc_int)(struct xgbe_prv_data *);
0806     void (*tx_mmc_int)(struct xgbe_prv_data *);
0807     void (*read_mmc_stats)(struct xgbe_prv_data *);
0808 
0809     /* For Timestamp config */
0810     int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
0811     void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
0812     void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
0813                 unsigned int nsec);
0814     u64 (*get_tstamp_time)(struct xgbe_prv_data *);
0815     u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
0816 
0817     /* For Data Center Bridging config */
0818     void (*config_tc)(struct xgbe_prv_data *);
0819     void (*config_dcb_tc)(struct xgbe_prv_data *);
0820     void (*config_dcb_pfc)(struct xgbe_prv_data *);
0821 
0822     /* For Receive Side Scaling */
0823     int (*enable_rss)(struct xgbe_prv_data *);
0824     int (*disable_rss)(struct xgbe_prv_data *);
0825     int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
0826     int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
0827 
0828     /* For ECC */
0829     void (*disable_ecc_ded)(struct xgbe_prv_data *);
0830     void (*disable_ecc_sec)(struct xgbe_prv_data *, enum xgbe_ecc_sec);
0831 
0832     /* For VXLAN */
0833     void (*enable_vxlan)(struct xgbe_prv_data *);
0834     void (*disable_vxlan)(struct xgbe_prv_data *);
0835     void (*set_vxlan_id)(struct xgbe_prv_data *);
0836 };
0837 
0838 /* This structure represents implementation specific routines for an
0839  * implementation of a PHY. All routines are required unless noted below.
0840  *   Optional routines:
0841  *     an_pre, an_post
0842  *     kr_training_pre, kr_training_post
0843  *     module_info, module_eeprom
0844  */
0845 struct xgbe_phy_impl_if {
0846     /* Perform Setup/teardown actions */
0847     int (*init)(struct xgbe_prv_data *);
0848     void (*exit)(struct xgbe_prv_data *);
0849 
0850     /* Perform start/stop specific actions */
0851     int (*reset)(struct xgbe_prv_data *);
0852     int (*start)(struct xgbe_prv_data *);
0853     void (*stop)(struct xgbe_prv_data *);
0854 
0855     /* Return the link status */
0856     int (*link_status)(struct xgbe_prv_data *, int *);
0857 
0858     /* Indicate if a particular speed is valid */
0859     bool (*valid_speed)(struct xgbe_prv_data *, int);
0860 
0861     /* Check if the specified mode can/should be used */
0862     bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
0863     /* Switch the PHY into various modes */
0864     void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
0865     /* Retrieve mode needed for a specific speed */
0866     enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
0867     /* Retrieve new/next mode when trying to auto-negotiate */
0868     enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
0869     /* Retrieve current mode */
0870     enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
0871 
0872     /* Retrieve current auto-negotiation mode */
0873     enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
0874 
0875     /* Configure auto-negotiation settings */
0876     int (*an_config)(struct xgbe_prv_data *);
0877 
0878     /* Set/override auto-negotiation advertisement settings */
0879     void (*an_advertising)(struct xgbe_prv_data *,
0880                    struct ethtool_link_ksettings *);
0881 
0882     /* Process results of auto-negotiation */
0883     enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
0884 
0885     /* Pre/Post auto-negotiation support */
0886     void (*an_pre)(struct xgbe_prv_data *);
0887     void (*an_post)(struct xgbe_prv_data *);
0888 
0889     /* Pre/Post KR training enablement support */
0890     void (*kr_training_pre)(struct xgbe_prv_data *);
0891     void (*kr_training_post)(struct xgbe_prv_data *);
0892 
0893     /* SFP module related info */
0894     int (*module_info)(struct xgbe_prv_data *pdata,
0895                struct ethtool_modinfo *modinfo);
0896     int (*module_eeprom)(struct xgbe_prv_data *pdata,
0897                  struct ethtool_eeprom *eeprom, u8 *data);
0898 };
0899 
0900 struct xgbe_phy_if {
0901     /* For PHY setup/teardown */
0902     int (*phy_init)(struct xgbe_prv_data *);
0903     void (*phy_exit)(struct xgbe_prv_data *);
0904 
0905     /* For PHY support when setting device up/down */
0906     int (*phy_reset)(struct xgbe_prv_data *);
0907     int (*phy_start)(struct xgbe_prv_data *);
0908     void (*phy_stop)(struct xgbe_prv_data *);
0909 
0910     /* For PHY support while device is up */
0911     void (*phy_status)(struct xgbe_prv_data *);
0912     int (*phy_config_aneg)(struct xgbe_prv_data *);
0913 
0914     /* For PHY settings validation */
0915     bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
0916 
0917     /* For single interrupt support */
0918     irqreturn_t (*an_isr)(struct xgbe_prv_data *);
0919 
0920     /* For ethtool PHY support */
0921     int (*module_info)(struct xgbe_prv_data *pdata,
0922                struct ethtool_modinfo *modinfo);
0923     int (*module_eeprom)(struct xgbe_prv_data *pdata,
0924                  struct ethtool_eeprom *eeprom, u8 *data);
0925 
0926     /* PHY implementation specific services */
0927     struct xgbe_phy_impl_if phy_impl;
0928 };
0929 
0930 struct xgbe_i2c_if {
0931     /* For initial I2C setup */
0932     int (*i2c_init)(struct xgbe_prv_data *);
0933 
0934     /* For I2C support when setting device up/down */
0935     int (*i2c_start)(struct xgbe_prv_data *);
0936     void (*i2c_stop)(struct xgbe_prv_data *);
0937 
0938     /* For performing I2C operations */
0939     int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
0940 
0941     /* For single interrupt support */
0942     irqreturn_t (*i2c_isr)(struct xgbe_prv_data *);
0943 };
0944 
0945 struct xgbe_desc_if {
0946     int (*alloc_ring_resources)(struct xgbe_prv_data *);
0947     void (*free_ring_resources)(struct xgbe_prv_data *);
0948     int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
0949     int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
0950                  struct xgbe_ring_data *);
0951     void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
0952     void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
0953     void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
0954 };
0955 
0956 /* This structure contains flags that indicate what hardware features
0957  * or configurations are present in the device.
0958  */
0959 struct xgbe_hw_features {
0960     /* HW Version */
0961     unsigned int version;
0962 
0963     /* HW Feature Register0 */
0964     unsigned int gmii;      /* 1000 Mbps support */
0965     unsigned int vlhash;        /* VLAN Hash Filter */
0966     unsigned int sma;       /* SMA(MDIO) Interface */
0967     unsigned int rwk;       /* PMT remote wake-up packet */
0968     unsigned int mgk;       /* PMT magic packet */
0969     unsigned int mmc;       /* RMON module */
0970     unsigned int aoe;       /* ARP Offload */
0971     unsigned int ts;        /* IEEE 1588-2008 Advanced Timestamp */
0972     unsigned int eee;       /* Energy Efficient Ethernet */
0973     unsigned int tx_coe;        /* Tx Checksum Offload */
0974     unsigned int rx_coe;        /* Rx Checksum Offload */
0975     unsigned int addn_mac;      /* Additional MAC Addresses */
0976     unsigned int ts_src;        /* Timestamp Source */
0977     unsigned int sa_vlan_ins;   /* Source Address or VLAN Insertion */
0978     unsigned int vxn;       /* VXLAN/NVGRE */
0979 
0980     /* HW Feature Register1 */
0981     unsigned int rx_fifo_size;  /* MTL Receive FIFO Size */
0982     unsigned int tx_fifo_size;  /* MTL Transmit FIFO Size */
0983     unsigned int adv_ts_hi;     /* Advance Timestamping High Word */
0984     unsigned int dma_width;     /* DMA width */
0985     unsigned int dcb;       /* DCB Feature */
0986     unsigned int sph;       /* Split Header Feature */
0987     unsigned int tso;       /* TCP Segmentation Offload */
0988     unsigned int dma_debug;     /* DMA Debug Registers */
0989     unsigned int rss;       /* Receive Side Scaling */
0990     unsigned int tc_cnt;        /* Number of Traffic Classes */
0991     unsigned int hash_table_size;   /* Hash Table Size */
0992     unsigned int l3l4_filter_num;   /* Number of L3-L4 Filters */
0993 
0994     /* HW Feature Register2 */
0995     unsigned int rx_q_cnt;      /* Number of MTL Receive Queues */
0996     unsigned int tx_q_cnt;      /* Number of MTL Transmit Queues */
0997     unsigned int rx_ch_cnt;     /* Number of DMA Receive Channels */
0998     unsigned int tx_ch_cnt;     /* Number of DMA Transmit Channels */
0999     unsigned int pps_out_num;   /* Number of PPS outputs */
1000     unsigned int aux_snap_num;  /* Number of Aux snapshot inputs */
1001 };
1002 
1003 struct xgbe_version_data {
1004     void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
1005     enum xgbe_xpcs_access xpcs_access;
1006     unsigned int mmc_64bit;
1007     unsigned int tx_max_fifo_size;
1008     unsigned int rx_max_fifo_size;
1009     unsigned int tx_tstamp_workaround;
1010     unsigned int ecc_support;
1011     unsigned int i2c_support;
1012     unsigned int irq_reissue_support;
1013     unsigned int tx_desc_prefetch;
1014     unsigned int rx_desc_prefetch;
1015     unsigned int an_cdr_workaround;
1016 };
1017 
1018 struct xgbe_prv_data {
1019     struct net_device *netdev;
1020     struct pci_dev *pcidev;
1021     struct platform_device *platdev;
1022     struct acpi_device *adev;
1023     struct device *dev;
1024     struct platform_device *phy_platdev;
1025     struct device *phy_dev;
1026 
1027     /* Version related data */
1028     struct xgbe_version_data *vdata;
1029 
1030     /* ACPI or DT flag */
1031     unsigned int use_acpi;
1032 
1033     /* XGMAC/XPCS related mmio registers */
1034     void __iomem *xgmac_regs;   /* XGMAC CSRs */
1035     void __iomem *xpcs_regs;    /* XPCS MMD registers */
1036     void __iomem *rxtx_regs;    /* SerDes Rx/Tx CSRs */
1037     void __iomem *sir0_regs;    /* SerDes integration registers (1/2) */
1038     void __iomem *sir1_regs;    /* SerDes integration registers (2/2) */
1039     void __iomem *xprop_regs;   /* XGBE property registers */
1040     void __iomem *xi2c_regs;    /* XGBE I2C CSRs */
1041 
1042     /* Port property registers */
1043     unsigned int pp0;
1044     unsigned int pp1;
1045     unsigned int pp2;
1046     unsigned int pp3;
1047     unsigned int pp4;
1048 
1049     /* Overall device lock */
1050     spinlock_t lock;
1051 
1052     /* XPCS indirect addressing lock */
1053     spinlock_t xpcs_lock;
1054     unsigned int xpcs_window_def_reg;
1055     unsigned int xpcs_window_sel_reg;
1056     unsigned int xpcs_window;
1057     unsigned int xpcs_window_size;
1058     unsigned int xpcs_window_mask;
1059 
1060     /* RSS addressing mutex */
1061     struct mutex rss_mutex;
1062 
1063     /* Flags representing xgbe_state */
1064     unsigned long dev_state;
1065 
1066     /* ECC support */
1067     unsigned long tx_sec_period;
1068     unsigned long tx_ded_period;
1069     unsigned long rx_sec_period;
1070     unsigned long rx_ded_period;
1071     unsigned long desc_sec_period;
1072     unsigned long desc_ded_period;
1073 
1074     unsigned int tx_sec_count;
1075     unsigned int tx_ded_count;
1076     unsigned int rx_sec_count;
1077     unsigned int rx_ded_count;
1078     unsigned int desc_ded_count;
1079     unsigned int desc_sec_count;
1080 
1081     int dev_irq;
1082     int ecc_irq;
1083     int i2c_irq;
1084     int channel_irq[XGBE_MAX_DMA_CHANNELS];
1085 
1086     unsigned int per_channel_irq;
1087     unsigned int irq_count;
1088     unsigned int channel_irq_count;
1089     unsigned int channel_irq_mode;
1090 
1091     char ecc_name[IFNAMSIZ + 32];
1092 
1093     struct xgbe_hw_if hw_if;
1094     struct xgbe_phy_if phy_if;
1095     struct xgbe_desc_if desc_if;
1096     struct xgbe_i2c_if i2c_if;
1097 
1098     /* AXI DMA settings */
1099     unsigned int coherent;
1100     unsigned int arcr;
1101     unsigned int awcr;
1102     unsigned int awarcr;
1103 
1104     /* Service routine support */
1105     struct workqueue_struct *dev_workqueue;
1106     struct work_struct service_work;
1107     struct timer_list service_timer;
1108 
1109     /* Rings for Tx/Rx on a DMA channel */
1110     struct xgbe_channel *channel[XGBE_MAX_DMA_CHANNELS];
1111     unsigned int tx_max_channel_count;
1112     unsigned int rx_max_channel_count;
1113     unsigned int channel_count;
1114     unsigned int tx_ring_count;
1115     unsigned int tx_desc_count;
1116     unsigned int rx_ring_count;
1117     unsigned int rx_desc_count;
1118 
1119     unsigned int new_tx_ring_count;
1120     unsigned int new_rx_ring_count;
1121 
1122     unsigned int tx_max_q_count;
1123     unsigned int rx_max_q_count;
1124     unsigned int tx_q_count;
1125     unsigned int rx_q_count;
1126 
1127     /* Tx/Rx common settings */
1128     unsigned int blen;
1129     unsigned int pbl;
1130     unsigned int aal;
1131     unsigned int rd_osr_limit;
1132     unsigned int wr_osr_limit;
1133 
1134     /* Tx settings */
1135     unsigned int tx_sf_mode;
1136     unsigned int tx_threshold;
1137     unsigned int tx_osp_mode;
1138     unsigned int tx_max_fifo_size;
1139 
1140     /* Rx settings */
1141     unsigned int rx_sf_mode;
1142     unsigned int rx_threshold;
1143     unsigned int rx_max_fifo_size;
1144 
1145     /* Tx coalescing settings */
1146     unsigned int tx_usecs;
1147     unsigned int tx_frames;
1148 
1149     /* Rx coalescing settings */
1150     unsigned int rx_riwt;
1151     unsigned int rx_usecs;
1152     unsigned int rx_frames;
1153 
1154     /* Current Rx buffer size */
1155     unsigned int rx_buf_size;
1156 
1157     /* Flow control settings */
1158     unsigned int pause_autoneg;
1159     unsigned int tx_pause;
1160     unsigned int rx_pause;
1161     unsigned int rx_rfa[XGBE_MAX_QUEUES];
1162     unsigned int rx_rfd[XGBE_MAX_QUEUES];
1163 
1164     /* Receive Side Scaling settings */
1165     u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
1166     u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
1167     u32 rss_options;
1168 
1169     /* VXLAN settings */
1170     u16 vxlan_port;
1171 
1172     /* Netdev related settings */
1173     unsigned char mac_addr[ETH_ALEN];
1174     netdev_features_t netdev_features;
1175     struct napi_struct napi;
1176     struct xgbe_mmc_stats mmc_stats;
1177     struct xgbe_ext_stats ext_stats;
1178 
1179     /* Filtering support */
1180     unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
1181 
1182     /* Device clocks */
1183     struct clk *sysclk;
1184     unsigned long sysclk_rate;
1185     struct clk *ptpclk;
1186     unsigned long ptpclk_rate;
1187 
1188     /* Timestamp support */
1189     spinlock_t tstamp_lock;
1190     struct ptp_clock_info ptp_clock_info;
1191     struct ptp_clock *ptp_clock;
1192     struct hwtstamp_config tstamp_config;
1193     struct cyclecounter tstamp_cc;
1194     struct timecounter tstamp_tc;
1195     unsigned int tstamp_addend;
1196     struct work_struct tx_tstamp_work;
1197     struct sk_buff *tx_tstamp_skb;
1198     u64 tx_tstamp;
1199 
1200     /* DCB support */
1201     struct ieee_ets *ets;
1202     struct ieee_pfc *pfc;
1203     unsigned int q2tc_map[XGBE_MAX_QUEUES];
1204     unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
1205     unsigned int pfcq[XGBE_MAX_QUEUES];
1206     unsigned int pfc_rfa;
1207     u8 num_tcs;
1208 
1209     /* Hardware features of the device */
1210     struct xgbe_hw_features hw_feat;
1211 
1212     /* Device work structures */
1213     struct work_struct restart_work;
1214     struct work_struct stopdev_work;
1215 
1216     /* Keeps track of power mode */
1217     unsigned int power_down;
1218 
1219     /* Network interface message level setting */
1220     u32 msg_enable;
1221 
1222     /* Current PHY settings */
1223     phy_interface_t phy_mode;
1224     int phy_link;
1225     int phy_speed;
1226 
1227     /* MDIO/PHY related settings */
1228     unsigned int phy_started;
1229     void *phy_data;
1230     struct xgbe_phy phy;
1231     int mdio_mmd;
1232     unsigned long link_check;
1233     struct completion mdio_complete;
1234 
1235     unsigned int kr_redrv;
1236 
1237     char an_name[IFNAMSIZ + 32];
1238     struct workqueue_struct *an_workqueue;
1239 
1240     int an_irq;
1241     struct work_struct an_irq_work;
1242 
1243     /* Auto-negotiation state machine support */
1244     unsigned int an_int;
1245     unsigned int an_status;
1246     struct mutex an_mutex;
1247     enum xgbe_an an_result;
1248     enum xgbe_an an_state;
1249     enum xgbe_rx kr_state;
1250     enum xgbe_rx kx_state;
1251     struct work_struct an_work;
1252     unsigned int an_again;
1253     unsigned int an_supported;
1254     unsigned int parallel_detect;
1255     unsigned int fec_ability;
1256     unsigned long an_start;
1257     enum xgbe_an_mode an_mode;
1258 
1259     /* I2C support */
1260     struct xgbe_i2c i2c;
1261     struct mutex i2c_mutex;
1262     struct completion i2c_complete;
1263     char i2c_name[IFNAMSIZ + 32];
1264 
1265     unsigned int lpm_ctrl;      /* CTRL1 for resume */
1266 
1267     unsigned int isr_as_tasklet;
1268     struct tasklet_struct tasklet_dev;
1269     struct tasklet_struct tasklet_ecc;
1270     struct tasklet_struct tasklet_i2c;
1271     struct tasklet_struct tasklet_an;
1272 
1273     struct dentry *xgbe_debugfs;
1274 
1275     unsigned int debugfs_xgmac_reg;
1276 
1277     unsigned int debugfs_xpcs_mmd;
1278     unsigned int debugfs_xpcs_reg;
1279 
1280     unsigned int debugfs_xprop_reg;
1281 
1282     unsigned int debugfs_xi2c_reg;
1283 
1284     bool debugfs_an_cdr_workaround;
1285     bool debugfs_an_cdr_track_early;
1286 };
1287 
1288 /* Function prototypes*/
1289 struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
1290 void xgbe_free_pdata(struct xgbe_prv_data *);
1291 void xgbe_set_counts(struct xgbe_prv_data *);
1292 int xgbe_config_netdev(struct xgbe_prv_data *);
1293 void xgbe_deconfig_netdev(struct xgbe_prv_data *);
1294 
1295 int xgbe_platform_init(void);
1296 void xgbe_platform_exit(void);
1297 #ifdef CONFIG_PCI
1298 int xgbe_pci_init(void);
1299 void xgbe_pci_exit(void);
1300 #else
1301 static inline int xgbe_pci_init(void) { return 0; }
1302 static inline void xgbe_pci_exit(void) { }
1303 #endif
1304 
1305 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
1306 void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
1307 void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
1308 void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
1309 void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
1310 void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
1311 const struct net_device_ops *xgbe_get_netdev_ops(void);
1312 const struct ethtool_ops *xgbe_get_ethtool_ops(void);
1313 const struct udp_tunnel_nic_info *xgbe_get_udp_tunnel_info(void);
1314 
1315 #ifdef CONFIG_AMD_XGBE_DCB
1316 const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
1317 #endif
1318 
1319 void xgbe_ptp_register(struct xgbe_prv_data *);
1320 void xgbe_ptp_unregister(struct xgbe_prv_data *);
1321 void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1322                unsigned int, unsigned int, unsigned int);
1323 void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1324                unsigned int);
1325 void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
1326 void xgbe_get_all_hw_features(struct xgbe_prv_data *);
1327 int xgbe_powerup(struct net_device *, unsigned int);
1328 int xgbe_powerdown(struct net_device *, unsigned int);
1329 void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
1330 void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
1331 void xgbe_restart_dev(struct xgbe_prv_data *pdata);
1332 void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
1333 
1334 #ifdef CONFIG_DEBUG_FS
1335 void xgbe_debugfs_init(struct xgbe_prv_data *);
1336 void xgbe_debugfs_exit(struct xgbe_prv_data *);
1337 void xgbe_debugfs_rename(struct xgbe_prv_data *pdata);
1338 #else
1339 static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
1340 static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
1341 static inline void xgbe_debugfs_rename(struct xgbe_prv_data *pdata) {}
1342 #endif /* CONFIG_DEBUG_FS */
1343 
1344 /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
1345 #if 0
1346 #define YDEBUG
1347 #define YDEBUG_MDIO
1348 #endif
1349 
1350 /* For debug prints */
1351 #ifdef YDEBUG
1352 #define DBGPR(x...) pr_alert(x)
1353 #else
1354 #define DBGPR(x...) do { } while (0)
1355 #endif
1356 
1357 #ifdef YDEBUG_MDIO
1358 #define DBGPR_MDIO(x...) pr_alert(x)
1359 #else
1360 #define DBGPR_MDIO(x...) do { } while (0)
1361 #endif
1362 
1363 #endif