Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 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 | * |
Lendacky, Thomas | 491aefb | 2016-02-17 11:48:19 -0600 | [diff] [blame] | 9 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 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 | * |
Lendacky, Thomas | 491aefb | 2016-02-17 11:48:19 -0600 | [diff] [blame] | 59 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 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 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 117 | #include <linux/module.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 118 | #include <linux/spinlock.h> |
| 119 | #include <linux/tcp.h> |
| 120 | #include <linux/if_vlan.h> |
Florian Westphal | 282ccf6 | 2017-03-29 17:17:31 +0200 | [diff] [blame] | 121 | #include <linux/interrupt.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 122 | #include <net/busy_poll.h> |
| 123 | #include <linux/clk.h> |
| 124 | #include <linux/if_ether.h> |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 125 | #include <linux/net_tstamp.h> |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 126 | #include <linux/phy.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 127 | |
| 128 | #include "xgbe.h" |
| 129 | #include "xgbe-common.h" |
| 130 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 131 | static unsigned int ecc_sec_info_threshold = 10; |
| 132 | static unsigned int ecc_sec_warn_threshold = 10000; |
| 133 | static unsigned int ecc_sec_period = 600; |
| 134 | static unsigned int ecc_ded_threshold = 2; |
| 135 | static unsigned int ecc_ded_period = 600; |
| 136 | |
| 137 | #ifdef CONFIG_AMD_XGBE_HAVE_ECC |
| 138 | /* Only expose the ECC parameters if supported */ |
| 139 | module_param(ecc_sec_info_threshold, uint, S_IWUSR | S_IRUGO); |
| 140 | MODULE_PARM_DESC(ecc_sec_info_threshold, |
| 141 | " ECC corrected error informational threshold setting"); |
| 142 | |
| 143 | module_param(ecc_sec_warn_threshold, uint, S_IWUSR | S_IRUGO); |
| 144 | MODULE_PARM_DESC(ecc_sec_warn_threshold, |
| 145 | " ECC corrected error warning threshold setting"); |
| 146 | |
| 147 | module_param(ecc_sec_period, uint, S_IWUSR | S_IRUGO); |
| 148 | MODULE_PARM_DESC(ecc_sec_period, " ECC corrected error period (in seconds)"); |
| 149 | |
| 150 | module_param(ecc_ded_threshold, uint, S_IWUSR | S_IRUGO); |
| 151 | MODULE_PARM_DESC(ecc_ded_threshold, " ECC detected error threshold setting"); |
| 152 | |
| 153 | module_param(ecc_ded_period, uint, S_IWUSR | S_IRUGO); |
| 154 | MODULE_PARM_DESC(ecc_ded_period, " ECC detected error period (in seconds)"); |
| 155 | #endif |
| 156 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 157 | static int xgbe_one_poll(struct napi_struct *, int); |
| 158 | static int xgbe_all_poll(struct napi_struct *, int); |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 159 | static void xgbe_stop(struct xgbe_prv_data *); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 160 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 161 | static int xgbe_alloc_channels(struct xgbe_prv_data *pdata) |
| 162 | { |
| 163 | struct xgbe_channel *channel_mem, *channel; |
| 164 | struct xgbe_ring *tx_ring, *rx_ring; |
| 165 | unsigned int count, i; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 166 | int ret = -ENOMEM; |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 167 | |
| 168 | count = max_t(unsigned int, pdata->tx_ring_count, pdata->rx_ring_count); |
| 169 | |
| 170 | channel_mem = kcalloc(count, sizeof(struct xgbe_channel), GFP_KERNEL); |
| 171 | if (!channel_mem) |
| 172 | goto err_channel; |
| 173 | |
| 174 | tx_ring = kcalloc(pdata->tx_ring_count, sizeof(struct xgbe_ring), |
| 175 | GFP_KERNEL); |
| 176 | if (!tx_ring) |
| 177 | goto err_tx_ring; |
| 178 | |
| 179 | rx_ring = kcalloc(pdata->rx_ring_count, sizeof(struct xgbe_ring), |
| 180 | GFP_KERNEL); |
| 181 | if (!rx_ring) |
| 182 | goto err_rx_ring; |
| 183 | |
| 184 | for (i = 0, channel = channel_mem; i < count; i++, channel++) { |
xypron.glpk@gmx.de | fb160eb | 2016-07-31 10:07:18 +0200 | [diff] [blame] | 185 | snprintf(channel->name, sizeof(channel->name), "channel-%u", i); |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 186 | channel->pdata = pdata; |
| 187 | channel->queue_index = i; |
| 188 | channel->dma_regs = pdata->xgmac_regs + DMA_CH_BASE + |
| 189 | (DMA_CH_INC * i); |
| 190 | |
Lendacky, Thomas | bd8255d | 2016-11-03 13:19:27 -0500 | [diff] [blame] | 191 | if (pdata->per_channel_irq) |
| 192 | channel->dma_irq = pdata->channel_irq[i]; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 193 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 194 | if (i < pdata->tx_ring_count) { |
| 195 | spin_lock_init(&tx_ring->lock); |
| 196 | channel->tx_ring = tx_ring++; |
| 197 | } |
| 198 | |
| 199 | if (i < pdata->rx_ring_count) { |
| 200 | spin_lock_init(&rx_ring->lock); |
| 201 | channel->rx_ring = rx_ring++; |
| 202 | } |
| 203 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 204 | netif_dbg(pdata, drv, pdata->netdev, |
| 205 | "%s: dma_regs=%p, dma_irq=%d, tx=%p, rx=%p\n", |
| 206 | channel->name, channel->dma_regs, channel->dma_irq, |
| 207 | channel->tx_ring, channel->rx_ring); |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | pdata->channel = channel_mem; |
| 211 | pdata->channel_count = count; |
| 212 | |
| 213 | return 0; |
| 214 | |
| 215 | err_rx_ring: |
| 216 | kfree(tx_ring); |
| 217 | |
| 218 | err_tx_ring: |
| 219 | kfree(channel_mem); |
| 220 | |
| 221 | err_channel: |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 222 | return ret; |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void xgbe_free_channels(struct xgbe_prv_data *pdata) |
| 226 | { |
| 227 | if (!pdata->channel) |
| 228 | return; |
| 229 | |
| 230 | kfree(pdata->channel->rx_ring); |
| 231 | kfree(pdata->channel->tx_ring); |
| 232 | kfree(pdata->channel); |
| 233 | |
| 234 | pdata->channel = NULL; |
| 235 | pdata->channel_count = 0; |
| 236 | } |
| 237 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 238 | static inline unsigned int xgbe_tx_avail_desc(struct xgbe_ring *ring) |
| 239 | { |
| 240 | return (ring->rdesc_count - (ring->cur - ring->dirty)); |
| 241 | } |
| 242 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 243 | static inline unsigned int xgbe_rx_dirty_desc(struct xgbe_ring *ring) |
| 244 | { |
| 245 | return (ring->cur - ring->dirty); |
| 246 | } |
| 247 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 248 | static int xgbe_maybe_stop_tx_queue(struct xgbe_channel *channel, |
| 249 | struct xgbe_ring *ring, unsigned int count) |
| 250 | { |
| 251 | struct xgbe_prv_data *pdata = channel->pdata; |
| 252 | |
| 253 | if (count > xgbe_tx_avail_desc(ring)) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 254 | netif_info(pdata, drv, pdata->netdev, |
| 255 | "Tx queue stopped, not enough descriptors available\n"); |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 256 | netif_stop_subqueue(pdata->netdev, channel->queue_index); |
| 257 | ring->tx.queue_stopped = 1; |
| 258 | |
| 259 | /* If we haven't notified the hardware because of xmit_more |
| 260 | * support, tell it now |
| 261 | */ |
| 262 | if (ring->tx.xmit_more) |
| 263 | pdata->hw_if.tx_start_xmit(channel, ring); |
| 264 | |
| 265 | return NETDEV_TX_BUSY; |
| 266 | } |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 271 | static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu) |
| 272 | { |
| 273 | unsigned int rx_buf_size; |
| 274 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 275 | rx_buf_size = mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 276 | rx_buf_size = clamp_val(rx_buf_size, XGBE_RX_MIN_BUF_SIZE, PAGE_SIZE); |
| 277 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 278 | rx_buf_size = (rx_buf_size + XGBE_RX_BUF_ALIGN - 1) & |
| 279 | ~(XGBE_RX_BUF_ALIGN - 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 280 | |
| 281 | return rx_buf_size; |
| 282 | } |
| 283 | |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 284 | static void xgbe_enable_rx_tx_int(struct xgbe_prv_data *pdata, |
| 285 | struct xgbe_channel *channel) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 286 | { |
| 287 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 288 | enum xgbe_int int_id; |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 289 | |
| 290 | if (channel->tx_ring && channel->rx_ring) |
| 291 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 292 | else if (channel->tx_ring) |
| 293 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 294 | else if (channel->rx_ring) |
| 295 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 296 | else |
| 297 | return; |
| 298 | |
| 299 | hw_if->enable_int(channel, int_id); |
| 300 | } |
| 301 | |
| 302 | static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 303 | { |
| 304 | struct xgbe_channel *channel; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 305 | unsigned int i; |
| 306 | |
| 307 | channel = pdata->channel; |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 308 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 309 | xgbe_enable_rx_tx_int(pdata, channel); |
| 310 | } |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 311 | |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 312 | static void xgbe_disable_rx_tx_int(struct xgbe_prv_data *pdata, |
| 313 | struct xgbe_channel *channel) |
| 314 | { |
| 315 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 316 | enum xgbe_int int_id; |
| 317 | |
| 318 | if (channel->tx_ring && channel->rx_ring) |
| 319 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 320 | else if (channel->tx_ring) |
| 321 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 322 | else if (channel->rx_ring) |
| 323 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 324 | else |
| 325 | return; |
| 326 | |
| 327 | hw_if->disable_int(channel, int_id); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 331 | { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 332 | struct xgbe_channel *channel; |
| 333 | unsigned int i; |
| 334 | |
| 335 | channel = pdata->channel; |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 336 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 337 | xgbe_disable_rx_tx_int(pdata, channel); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 338 | } |
| 339 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 340 | static bool xgbe_ecc_sec(struct xgbe_prv_data *pdata, unsigned long *period, |
| 341 | unsigned int *count, const char *area) |
| 342 | { |
| 343 | if (time_before(jiffies, *period)) { |
| 344 | (*count)++; |
| 345 | } else { |
| 346 | *period = jiffies + (ecc_sec_period * HZ); |
| 347 | *count = 1; |
| 348 | } |
| 349 | |
| 350 | if (*count > ecc_sec_info_threshold) |
| 351 | dev_warn_once(pdata->dev, |
| 352 | "%s ECC corrected errors exceed informational threshold\n", |
| 353 | area); |
| 354 | |
| 355 | if (*count > ecc_sec_warn_threshold) { |
| 356 | dev_warn_once(pdata->dev, |
| 357 | "%s ECC corrected errors exceed warning threshold\n", |
| 358 | area); |
| 359 | return true; |
| 360 | } |
| 361 | |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | static bool xgbe_ecc_ded(struct xgbe_prv_data *pdata, unsigned long *period, |
| 366 | unsigned int *count, const char *area) |
| 367 | { |
| 368 | if (time_before(jiffies, *period)) { |
| 369 | (*count)++; |
| 370 | } else { |
| 371 | *period = jiffies + (ecc_ded_period * HZ); |
| 372 | *count = 1; |
| 373 | } |
| 374 | |
| 375 | if (*count > ecc_ded_threshold) { |
| 376 | netdev_alert(pdata->netdev, |
| 377 | "%s ECC detected errors exceed threshold\n", |
| 378 | area); |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | return false; |
| 383 | } |
| 384 | |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 385 | static void xgbe_ecc_isr_task(unsigned long data) |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 386 | { |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 387 | struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data; |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 388 | unsigned int ecc_isr; |
| 389 | bool stop = false; |
| 390 | |
| 391 | /* Mask status with only the interrupts we care about */ |
| 392 | ecc_isr = XP_IOREAD(pdata, XP_ECC_ISR); |
| 393 | ecc_isr &= XP_IOREAD(pdata, XP_ECC_IER); |
| 394 | netif_dbg(pdata, intr, pdata->netdev, "ECC_ISR=%#010x\n", ecc_isr); |
| 395 | |
| 396 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, TX_DED)) { |
| 397 | stop |= xgbe_ecc_ded(pdata, &pdata->tx_ded_period, |
| 398 | &pdata->tx_ded_count, "TX fifo"); |
| 399 | } |
| 400 | |
| 401 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, RX_DED)) { |
| 402 | stop |= xgbe_ecc_ded(pdata, &pdata->rx_ded_period, |
| 403 | &pdata->rx_ded_count, "RX fifo"); |
| 404 | } |
| 405 | |
| 406 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, DESC_DED)) { |
| 407 | stop |= xgbe_ecc_ded(pdata, &pdata->desc_ded_period, |
| 408 | &pdata->desc_ded_count, |
| 409 | "descriptor cache"); |
| 410 | } |
| 411 | |
| 412 | if (stop) { |
| 413 | pdata->hw_if.disable_ecc_ded(pdata); |
| 414 | schedule_work(&pdata->stopdev_work); |
| 415 | goto out; |
| 416 | } |
| 417 | |
| 418 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, TX_SEC)) { |
| 419 | if (xgbe_ecc_sec(pdata, &pdata->tx_sec_period, |
| 420 | &pdata->tx_sec_count, "TX fifo")) |
| 421 | pdata->hw_if.disable_ecc_sec(pdata, XGBE_ECC_SEC_TX); |
| 422 | } |
| 423 | |
| 424 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, RX_SEC)) |
| 425 | if (xgbe_ecc_sec(pdata, &pdata->rx_sec_period, |
| 426 | &pdata->rx_sec_count, "RX fifo")) |
| 427 | pdata->hw_if.disable_ecc_sec(pdata, XGBE_ECC_SEC_RX); |
| 428 | |
| 429 | if (XP_GET_BITS(ecc_isr, XP_ECC_ISR, DESC_SEC)) |
| 430 | if (xgbe_ecc_sec(pdata, &pdata->desc_sec_period, |
| 431 | &pdata->desc_sec_count, "descriptor cache")) |
| 432 | pdata->hw_if.disable_ecc_sec(pdata, XGBE_ECC_SEC_DESC); |
| 433 | |
| 434 | out: |
| 435 | /* Clear all ECC interrupts */ |
| 436 | XP_IOWRITE(pdata, XP_ECC_ISR, ecc_isr); |
| 437 | |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 438 | /* Reissue interrupt if status is not clear */ |
| 439 | if (pdata->vdata->irq_reissue_support) |
| 440 | XP_IOWRITE(pdata, XP_INT_REISSUE_EN, 1 << 1); |
| 441 | } |
| 442 | |
| 443 | static irqreturn_t xgbe_ecc_isr(int irq, void *data) |
| 444 | { |
| 445 | struct xgbe_prv_data *pdata = data; |
| 446 | |
| 447 | if (pdata->isr_as_tasklet) |
| 448 | tasklet_schedule(&pdata->tasklet_ecc); |
| 449 | else |
| 450 | xgbe_ecc_isr_task((unsigned long)pdata); |
| 451 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 452 | return IRQ_HANDLED; |
| 453 | } |
| 454 | |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 455 | static void xgbe_isr_task(unsigned long data) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 456 | { |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 457 | struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 458 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 459 | struct xgbe_channel *channel; |
| 460 | unsigned int dma_isr, dma_ch_isr; |
Lendacky, Thomas | 732f2ab | 2016-11-10 17:11:14 -0600 | [diff] [blame] | 461 | unsigned int mac_isr, mac_tssr, mac_mdioisr; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 462 | unsigned int i; |
| 463 | |
| 464 | /* The DMA interrupt status register also reports MAC and MTL |
| 465 | * interrupts. So for polling mode, we just need to check for |
| 466 | * this register to be non-zero |
| 467 | */ |
| 468 | dma_isr = XGMAC_IOREAD(pdata, DMA_ISR); |
| 469 | if (!dma_isr) |
| 470 | goto isr_done; |
| 471 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 472 | netif_dbg(pdata, intr, pdata->netdev, "DMA_ISR=%#010x\n", dma_isr); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 473 | |
| 474 | for (i = 0; i < pdata->channel_count; i++) { |
| 475 | if (!(dma_isr & (1 << i))) |
| 476 | continue; |
| 477 | |
| 478 | channel = pdata->channel + i; |
| 479 | |
| 480 | dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 481 | netif_dbg(pdata, intr, pdata->netdev, "DMA_CH%u_ISR=%#010x\n", |
| 482 | i, dma_ch_isr); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 483 | |
Lendacky, Thomas | fd972b7 | 2015-02-05 19:17:14 -0600 | [diff] [blame] | 484 | /* The TI or RI interrupt bits may still be set even if using |
| 485 | * per channel DMA interrupts. Check to be sure those are not |
| 486 | * enabled before using the private data napi structure. |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 487 | */ |
Lendacky, Thomas | fd972b7 | 2015-02-05 19:17:14 -0600 | [diff] [blame] | 488 | if (!pdata->per_channel_irq && |
| 489 | (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, TI) || |
| 490 | XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RI))) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 491 | if (napi_schedule_prep(&pdata->napi)) { |
| 492 | /* Disable Tx and Rx interrupts */ |
| 493 | xgbe_disable_rx_tx_ints(pdata); |
| 494 | |
| 495 | /* Turn on polling */ |
Lendacky, Thomas | 7934942 | 2016-02-17 11:48:29 -0600 | [diff] [blame] | 496 | __napi_schedule_irqoff(&pdata->napi); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 497 | } |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 498 | } else { |
| 499 | /* Don't clear Rx/Tx status if doing per channel DMA |
| 500 | * interrupts, these will be cleared by the ISR for |
| 501 | * per channel DMA interrupts. |
| 502 | */ |
| 503 | XGMAC_SET_BITS(dma_ch_isr, DMA_CH_SR, TI, 0); |
| 504 | XGMAC_SET_BITS(dma_ch_isr, DMA_CH_SR, RI, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 505 | } |
| 506 | |
Lendacky, Thomas | 72c9ac4 | 2015-09-30 08:53:10 -0500 | [diff] [blame] | 507 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RBU)) |
| 508 | pdata->ext_stats.rx_buffer_unavailable++; |
| 509 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 510 | /* Restart the device on a Fatal Bus Error */ |
| 511 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, FBE)) |
Lendacky, Thomas | 96aec91 | 2015-10-14 12:37:32 -0500 | [diff] [blame] | 512 | schedule_work(&pdata->restart_work); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 513 | |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 514 | /* Clear interrupt signals */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 515 | XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr); |
| 516 | } |
| 517 | |
| 518 | if (XGMAC_GET_BITS(dma_isr, DMA_ISR, MACIS)) { |
| 519 | mac_isr = XGMAC_IOREAD(pdata, MAC_ISR); |
| 520 | |
Lendacky, Thomas | 732f2ab | 2016-11-10 17:11:14 -0600 | [diff] [blame] | 521 | netif_dbg(pdata, intr, pdata->netdev, "MAC_ISR=%#010x\n", |
| 522 | mac_isr); |
| 523 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 524 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCTXIS)) |
| 525 | hw_if->tx_mmc_int(pdata); |
| 526 | |
| 527 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCRXIS)) |
| 528 | hw_if->rx_mmc_int(pdata); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 529 | |
| 530 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, TSIS)) { |
| 531 | mac_tssr = XGMAC_IOREAD(pdata, MAC_TSSR); |
| 532 | |
Lendacky, Thomas | 732f2ab | 2016-11-10 17:11:14 -0600 | [diff] [blame] | 533 | netif_dbg(pdata, intr, pdata->netdev, |
| 534 | "MAC_TSSR=%#010x\n", mac_tssr); |
| 535 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 536 | if (XGMAC_GET_BITS(mac_tssr, MAC_TSSR, TXTSC)) { |
| 537 | /* Read Tx Timestamp to clear interrupt */ |
| 538 | pdata->tx_tstamp = |
| 539 | hw_if->get_tx_tstamp(pdata); |
Lendacky, Thomas | afb43e8 | 2015-09-30 08:53:16 -0500 | [diff] [blame] | 540 | queue_work(pdata->dev_workqueue, |
| 541 | &pdata->tx_tstamp_work); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 542 | } |
| 543 | } |
Lendacky, Thomas | 732f2ab | 2016-11-10 17:11:14 -0600 | [diff] [blame] | 544 | |
| 545 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, SMI)) { |
| 546 | mac_mdioisr = XGMAC_IOREAD(pdata, MAC_MDIOISR); |
| 547 | |
| 548 | netif_dbg(pdata, intr, pdata->netdev, |
| 549 | "MAC_MDIOISR=%#010x\n", mac_mdioisr); |
| 550 | |
| 551 | if (XGMAC_GET_BITS(mac_mdioisr, MAC_MDIOISR, |
| 552 | SNGLCOMPINT)) |
| 553 | complete(&pdata->mdio_complete); |
| 554 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 555 | } |
| 556 | |
Lendacky, Thomas | 896b4db | 2017-01-04 15:07:16 -0600 | [diff] [blame] | 557 | isr_done: |
Lendacky, Thomas | 47f164d | 2016-11-10 17:09:55 -0600 | [diff] [blame] | 558 | /* If there is not a separate AN irq, handle it here */ |
| 559 | if (pdata->dev_irq == pdata->an_irq) |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 560 | pdata->phy_if.an_isr(pdata); |
Lendacky, Thomas | 47f164d | 2016-11-10 17:09:55 -0600 | [diff] [blame] | 561 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 562 | /* If there is not a separate ECC irq, handle it here */ |
| 563 | if (pdata->vdata->ecc_support && (pdata->dev_irq == pdata->ecc_irq)) |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 564 | xgbe_ecc_isr_task((unsigned long)pdata); |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 565 | |
Lendacky, Thomas | 5ab1dcd | 2016-11-10 17:10:36 -0600 | [diff] [blame] | 566 | /* If there is not a separate I2C irq, handle it here */ |
| 567 | if (pdata->vdata->i2c_support && (pdata->dev_irq == pdata->i2c_irq)) |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 568 | pdata->i2c_if.i2c_isr(pdata); |
| 569 | |
| 570 | /* Reissue interrupt if status is not clear */ |
| 571 | if (pdata->vdata->irq_reissue_support) { |
| 572 | unsigned int reissue_mask; |
| 573 | |
| 574 | reissue_mask = 1 << 0; |
| 575 | if (!pdata->per_channel_irq) |
| 576 | reissue_mask |= 0xffff < 4; |
| 577 | |
| 578 | XP_IOWRITE(pdata, XP_INT_REISSUE_EN, reissue_mask); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | static irqreturn_t xgbe_isr(int irq, void *data) |
| 583 | { |
| 584 | struct xgbe_prv_data *pdata = data; |
| 585 | |
| 586 | if (pdata->isr_as_tasklet) |
| 587 | tasklet_schedule(&pdata->tasklet_dev); |
| 588 | else |
| 589 | xgbe_isr_task((unsigned long)pdata); |
Lendacky, Thomas | 5ab1dcd | 2016-11-10 17:10:36 -0600 | [diff] [blame] | 590 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 591 | return IRQ_HANDLED; |
| 592 | } |
| 593 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 594 | static irqreturn_t xgbe_dma_isr(int irq, void *data) |
| 595 | { |
| 596 | struct xgbe_channel *channel = data; |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 597 | struct xgbe_prv_data *pdata = channel->pdata; |
| 598 | unsigned int dma_status; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 599 | |
| 600 | /* Per channel DMA interrupts are enabled, so we use the per |
| 601 | * channel napi structure and not the private data napi structure |
| 602 | */ |
| 603 | if (napi_schedule_prep(&channel->napi)) { |
| 604 | /* Disable Tx and Rx interrupts */ |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 605 | if (pdata->channel_irq_mode) |
| 606 | xgbe_disable_rx_tx_int(pdata, channel); |
| 607 | else |
| 608 | disable_irq_nosync(channel->dma_irq); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 609 | |
| 610 | /* Turn on polling */ |
Lendacky, Thomas | 7934942 | 2016-02-17 11:48:29 -0600 | [diff] [blame] | 611 | __napi_schedule_irqoff(&channel->napi); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 612 | } |
| 613 | |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 614 | /* Clear Tx/Rx signals */ |
| 615 | dma_status = 0; |
| 616 | XGMAC_SET_BITS(dma_status, DMA_CH_SR, TI, 1); |
| 617 | XGMAC_SET_BITS(dma_status, DMA_CH_SR, RI, 1); |
| 618 | XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_status); |
| 619 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 620 | return IRQ_HANDLED; |
| 621 | } |
| 622 | |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 623 | static void xgbe_tx_timer(unsigned long data) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 624 | { |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 625 | struct xgbe_channel *channel = (struct xgbe_channel *)data; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 626 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 627 | struct napi_struct *napi; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 628 | |
| 629 | DBGPR("-->xgbe_tx_timer\n"); |
| 630 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 631 | napi = (pdata->per_channel_irq) ? &channel->napi : &pdata->napi; |
| 632 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 633 | if (napi_schedule_prep(napi)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 634 | /* Disable Tx and Rx interrupts */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 635 | if (pdata->per_channel_irq) |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 636 | if (pdata->channel_irq_mode) |
| 637 | xgbe_disable_rx_tx_int(pdata, channel); |
| 638 | else |
| 639 | disable_irq_nosync(channel->dma_irq); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 640 | else |
| 641 | xgbe_disable_rx_tx_ints(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 642 | |
| 643 | /* Turn on polling */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 644 | __napi_schedule(napi); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | channel->tx_timer_active = 0; |
| 648 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 649 | DBGPR("<--xgbe_tx_timer\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 650 | } |
| 651 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 652 | static void xgbe_service(struct work_struct *work) |
| 653 | { |
| 654 | struct xgbe_prv_data *pdata = container_of(work, |
| 655 | struct xgbe_prv_data, |
| 656 | service_work); |
| 657 | |
| 658 | pdata->phy_if.phy_status(pdata); |
| 659 | } |
| 660 | |
| 661 | static void xgbe_service_timer(unsigned long data) |
| 662 | { |
| 663 | struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data; |
| 664 | |
Lendacky, Thomas | afb43e8 | 2015-09-30 08:53:16 -0500 | [diff] [blame] | 665 | queue_work(pdata->dev_workqueue, &pdata->service_work); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 666 | |
| 667 | mod_timer(&pdata->service_timer, jiffies + HZ); |
| 668 | } |
| 669 | |
| 670 | static void xgbe_init_timers(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 671 | { |
| 672 | struct xgbe_channel *channel; |
| 673 | unsigned int i; |
| 674 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 675 | setup_timer(&pdata->service_timer, xgbe_service_timer, |
| 676 | (unsigned long)pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 677 | |
| 678 | channel = pdata->channel; |
| 679 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 680 | if (!channel->tx_ring) |
| 681 | break; |
| 682 | |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 683 | setup_timer(&channel->tx_timer, xgbe_tx_timer, |
| 684 | (unsigned long)channel); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 685 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 686 | } |
| 687 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 688 | static void xgbe_start_timers(struct xgbe_prv_data *pdata) |
| 689 | { |
| 690 | mod_timer(&pdata->service_timer, jiffies + HZ); |
| 691 | } |
| 692 | |
| 693 | static void xgbe_stop_timers(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 694 | { |
| 695 | struct xgbe_channel *channel; |
| 696 | unsigned int i; |
| 697 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 698 | del_timer_sync(&pdata->service_timer); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 699 | |
| 700 | channel = pdata->channel; |
| 701 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 702 | if (!channel->tx_ring) |
| 703 | break; |
| 704 | |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 705 | del_timer_sync(&channel->tx_timer); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 706 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | void xgbe_get_all_hw_features(struct xgbe_prv_data *pdata) |
| 710 | { |
| 711 | unsigned int mac_hfr0, mac_hfr1, mac_hfr2; |
| 712 | struct xgbe_hw_features *hw_feat = &pdata->hw_feat; |
| 713 | |
| 714 | DBGPR("-->xgbe_get_all_hw_features\n"); |
| 715 | |
| 716 | mac_hfr0 = XGMAC_IOREAD(pdata, MAC_HWF0R); |
| 717 | mac_hfr1 = XGMAC_IOREAD(pdata, MAC_HWF1R); |
| 718 | mac_hfr2 = XGMAC_IOREAD(pdata, MAC_HWF2R); |
| 719 | |
| 720 | memset(hw_feat, 0, sizeof(*hw_feat)); |
| 721 | |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 722 | hw_feat->version = XGMAC_IOREAD(pdata, MAC_VR); |
| 723 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 724 | /* Hardware feature register 0 */ |
| 725 | hw_feat->gmii = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL); |
| 726 | hw_feat->vlhash = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH); |
| 727 | hw_feat->sma = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL); |
| 728 | hw_feat->rwk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL); |
| 729 | hw_feat->mgk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL); |
| 730 | hw_feat->mmc = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL); |
| 731 | hw_feat->aoe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL); |
| 732 | hw_feat->ts = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL); |
| 733 | hw_feat->eee = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL); |
| 734 | hw_feat->tx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL); |
| 735 | hw_feat->rx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL); |
| 736 | hw_feat->addn_mac = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, |
| 737 | ADDMACADRSEL); |
| 738 | hw_feat->ts_src = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL); |
| 739 | hw_feat->sa_vlan_ins = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS); |
| 740 | |
| 741 | /* Hardware feature register 1 */ |
| 742 | hw_feat->rx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 743 | RXFIFOSIZE); |
| 744 | hw_feat->tx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 745 | TXFIFOSIZE); |
Lendacky, Thomas | 73c25916 | 2015-05-22 16:32:09 -0500 | [diff] [blame] | 746 | hw_feat->adv_ts_hi = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADVTHWORD); |
Lendacky, Thomas | 386d325 | 2015-03-20 11:50:22 -0500 | [diff] [blame] | 747 | hw_feat->dma_width = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADDR64); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 748 | hw_feat->dcb = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN); |
| 749 | hw_feat->sph = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN); |
| 750 | hw_feat->tso = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN); |
| 751 | hw_feat->dma_debug = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA); |
Lendacky, Thomas | cf180b8 | 2015-02-03 14:14:32 -0600 | [diff] [blame] | 752 | hw_feat->rss = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, RSSEN); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 753 | hw_feat->tc_cnt = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 754 | hw_feat->hash_table_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 755 | HASHTBLSZ); |
| 756 | hw_feat->l3l4_filter_num = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 757 | L3L4FNUM); |
| 758 | |
| 759 | /* Hardware feature register 2 */ |
| 760 | hw_feat->rx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT); |
| 761 | hw_feat->tx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT); |
| 762 | hw_feat->rx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT); |
| 763 | hw_feat->tx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT); |
| 764 | hw_feat->pps_out_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM); |
| 765 | hw_feat->aux_snap_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, AUXSNAPNUM); |
| 766 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 767 | /* Translate the Hash Table size into actual number */ |
| 768 | switch (hw_feat->hash_table_size) { |
| 769 | case 0: |
| 770 | break; |
| 771 | case 1: |
| 772 | hw_feat->hash_table_size = 64; |
| 773 | break; |
| 774 | case 2: |
| 775 | hw_feat->hash_table_size = 128; |
| 776 | break; |
| 777 | case 3: |
| 778 | hw_feat->hash_table_size = 256; |
| 779 | break; |
| 780 | } |
| 781 | |
Lendacky, Thomas | 386d325 | 2015-03-20 11:50:22 -0500 | [diff] [blame] | 782 | /* Translate the address width setting into actual number */ |
| 783 | switch (hw_feat->dma_width) { |
| 784 | case 0: |
| 785 | hw_feat->dma_width = 32; |
| 786 | break; |
| 787 | case 1: |
| 788 | hw_feat->dma_width = 40; |
| 789 | break; |
| 790 | case 2: |
| 791 | hw_feat->dma_width = 48; |
| 792 | break; |
| 793 | default: |
| 794 | hw_feat->dma_width = 32; |
| 795 | } |
| 796 | |
Lendacky, Thomas | 211fcf6 | 2015-02-03 12:49:55 -0600 | [diff] [blame] | 797 | /* The Queue, Channel and TC counts are zero based so increment them |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 798 | * to get the actual number |
| 799 | */ |
| 800 | hw_feat->rx_q_cnt++; |
| 801 | hw_feat->tx_q_cnt++; |
| 802 | hw_feat->rx_ch_cnt++; |
| 803 | hw_feat->tx_ch_cnt++; |
Lendacky, Thomas | 211fcf6 | 2015-02-03 12:49:55 -0600 | [diff] [blame] | 804 | hw_feat->tc_cnt++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 805 | |
Lendacky, Thomas | bd8255d | 2016-11-03 13:19:27 -0500 | [diff] [blame] | 806 | /* Translate the fifo sizes into actual numbers */ |
| 807 | hw_feat->rx_fifo_size = 1 << (hw_feat->rx_fifo_size + 7); |
| 808 | hw_feat->tx_fifo_size = 1 << (hw_feat->tx_fifo_size + 7); |
| 809 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 810 | DBGPR("<--xgbe_get_all_hw_features\n"); |
| 811 | } |
| 812 | |
| 813 | static void xgbe_napi_enable(struct xgbe_prv_data *pdata, unsigned int add) |
| 814 | { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 815 | struct xgbe_channel *channel; |
| 816 | unsigned int i; |
| 817 | |
| 818 | if (pdata->per_channel_irq) { |
| 819 | channel = pdata->channel; |
| 820 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 821 | if (add) |
| 822 | netif_napi_add(pdata->netdev, &channel->napi, |
| 823 | xgbe_one_poll, NAPI_POLL_WEIGHT); |
| 824 | |
| 825 | napi_enable(&channel->napi); |
| 826 | } |
| 827 | } else { |
| 828 | if (add) |
| 829 | netif_napi_add(pdata->netdev, &pdata->napi, |
| 830 | xgbe_all_poll, NAPI_POLL_WEIGHT); |
| 831 | |
| 832 | napi_enable(&pdata->napi); |
| 833 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 834 | } |
| 835 | |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 836 | static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 837 | { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 838 | struct xgbe_channel *channel; |
| 839 | unsigned int i; |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 840 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 841 | if (pdata->per_channel_irq) { |
| 842 | channel = pdata->channel; |
| 843 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 844 | napi_disable(&channel->napi); |
| 845 | |
| 846 | if (del) |
| 847 | netif_napi_del(&channel->napi); |
| 848 | } |
| 849 | } else { |
| 850 | napi_disable(&pdata->napi); |
| 851 | |
| 852 | if (del) |
| 853 | netif_napi_del(&pdata->napi); |
| 854 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 855 | } |
| 856 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 857 | static int xgbe_request_irqs(struct xgbe_prv_data *pdata) |
| 858 | { |
| 859 | struct xgbe_channel *channel; |
| 860 | struct net_device *netdev = pdata->netdev; |
| 861 | unsigned int i; |
| 862 | int ret; |
| 863 | |
Lendacky, Thomas | 85b85c8 | 2017-06-28 13:42:42 -0500 | [diff] [blame^] | 864 | tasklet_init(&pdata->tasklet_dev, xgbe_isr_task, (unsigned long)pdata); |
| 865 | tasklet_init(&pdata->tasklet_ecc, xgbe_ecc_isr_task, |
| 866 | (unsigned long)pdata); |
| 867 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 868 | ret = devm_request_irq(pdata->dev, pdata->dev_irq, xgbe_isr, 0, |
| 869 | netdev->name, pdata); |
| 870 | if (ret) { |
| 871 | netdev_alert(netdev, "error requesting irq %d\n", |
| 872 | pdata->dev_irq); |
| 873 | return ret; |
| 874 | } |
| 875 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 876 | if (pdata->vdata->ecc_support && (pdata->dev_irq != pdata->ecc_irq)) { |
| 877 | ret = devm_request_irq(pdata->dev, pdata->ecc_irq, xgbe_ecc_isr, |
| 878 | 0, pdata->ecc_name, pdata); |
| 879 | if (ret) { |
| 880 | netdev_alert(netdev, "error requesting ecc irq %d\n", |
| 881 | pdata->ecc_irq); |
| 882 | goto err_dev_irq; |
| 883 | } |
| 884 | } |
| 885 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 886 | if (!pdata->per_channel_irq) |
| 887 | return 0; |
| 888 | |
| 889 | channel = pdata->channel; |
| 890 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 891 | snprintf(channel->dma_irq_name, |
| 892 | sizeof(channel->dma_irq_name) - 1, |
| 893 | "%s-TxRx-%u", netdev_name(netdev), |
| 894 | channel->queue_index); |
| 895 | |
| 896 | ret = devm_request_irq(pdata->dev, channel->dma_irq, |
| 897 | xgbe_dma_isr, 0, |
| 898 | channel->dma_irq_name, channel); |
| 899 | if (ret) { |
| 900 | netdev_alert(netdev, "error requesting irq %d\n", |
| 901 | channel->dma_irq); |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 902 | goto err_dma_irq; |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | return 0; |
| 907 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 908 | err_dma_irq: |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 909 | /* Using an unsigned int, 'i' will go to UINT_MAX and exit */ |
| 910 | for (i--, channel--; i < pdata->channel_count; i--, channel--) |
| 911 | devm_free_irq(pdata->dev, channel->dma_irq, channel); |
| 912 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 913 | if (pdata->vdata->ecc_support && (pdata->dev_irq != pdata->ecc_irq)) |
| 914 | devm_free_irq(pdata->dev, pdata->ecc_irq, pdata); |
| 915 | |
| 916 | err_dev_irq: |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 917 | devm_free_irq(pdata->dev, pdata->dev_irq, pdata); |
| 918 | |
| 919 | return ret; |
| 920 | } |
| 921 | |
| 922 | static void xgbe_free_irqs(struct xgbe_prv_data *pdata) |
| 923 | { |
| 924 | struct xgbe_channel *channel; |
| 925 | unsigned int i; |
| 926 | |
| 927 | devm_free_irq(pdata->dev, pdata->dev_irq, pdata); |
| 928 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 929 | if (pdata->vdata->ecc_support && (pdata->dev_irq != pdata->ecc_irq)) |
| 930 | devm_free_irq(pdata->dev, pdata->ecc_irq, pdata); |
| 931 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 932 | if (!pdata->per_channel_irq) |
| 933 | return; |
| 934 | |
| 935 | channel = pdata->channel; |
| 936 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 937 | devm_free_irq(pdata->dev, channel->dma_irq, channel); |
| 938 | } |
| 939 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 940 | void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata) |
| 941 | { |
| 942 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 943 | |
| 944 | DBGPR("-->xgbe_init_tx_coalesce\n"); |
| 945 | |
| 946 | pdata->tx_usecs = XGMAC_INIT_DMA_TX_USECS; |
| 947 | pdata->tx_frames = XGMAC_INIT_DMA_TX_FRAMES; |
| 948 | |
| 949 | hw_if->config_tx_coalesce(pdata); |
| 950 | |
| 951 | DBGPR("<--xgbe_init_tx_coalesce\n"); |
| 952 | } |
| 953 | |
| 954 | void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata) |
| 955 | { |
| 956 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 957 | |
| 958 | DBGPR("-->xgbe_init_rx_coalesce\n"); |
| 959 | |
| 960 | pdata->rx_riwt = hw_if->usec_to_riwt(pdata, XGMAC_INIT_DMA_RX_USECS); |
Lendacky, Thomas | 4a57ebc | 2015-03-20 11:50:34 -0500 | [diff] [blame] | 961 | pdata->rx_usecs = XGMAC_INIT_DMA_RX_USECS; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 962 | pdata->rx_frames = XGMAC_INIT_DMA_RX_FRAMES; |
| 963 | |
| 964 | hw_if->config_rx_coalesce(pdata); |
| 965 | |
| 966 | DBGPR("<--xgbe_init_rx_coalesce\n"); |
| 967 | } |
| 968 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 969 | static void xgbe_free_tx_data(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 970 | { |
| 971 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 972 | struct xgbe_channel *channel; |
| 973 | struct xgbe_ring *ring; |
| 974 | struct xgbe_ring_data *rdata; |
| 975 | unsigned int i, j; |
| 976 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 977 | DBGPR("-->xgbe_free_tx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 978 | |
| 979 | channel = pdata->channel; |
| 980 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 981 | ring = channel->tx_ring; |
| 982 | if (!ring) |
| 983 | break; |
| 984 | |
| 985 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 986 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 987 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 991 | DBGPR("<--xgbe_free_tx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 992 | } |
| 993 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 994 | static void xgbe_free_rx_data(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 995 | { |
| 996 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 997 | struct xgbe_channel *channel; |
| 998 | struct xgbe_ring *ring; |
| 999 | struct xgbe_ring_data *rdata; |
| 1000 | unsigned int i, j; |
| 1001 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1002 | DBGPR("-->xgbe_free_rx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1003 | |
| 1004 | channel = pdata->channel; |
| 1005 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 1006 | ring = channel->rx_ring; |
| 1007 | if (!ring) |
| 1008 | break; |
| 1009 | |
| 1010 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1011 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1012 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1016 | DBGPR("<--xgbe_free_rx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 1019 | static int xgbe_phy_reset(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1020 | { |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1021 | pdata->phy_link = -1; |
| 1022 | pdata->phy_speed = SPEED_UNKNOWN; |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1023 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1024 | return pdata->phy_if.phy_reset(pdata); |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1025 | } |
| 1026 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1027 | int xgbe_powerdown(struct net_device *netdev, unsigned int caller) |
| 1028 | { |
| 1029 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1030 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1031 | unsigned long flags; |
| 1032 | |
| 1033 | DBGPR("-->xgbe_powerdown\n"); |
| 1034 | |
| 1035 | if (!netif_running(netdev) || |
| 1036 | (caller == XGMAC_IOCTL_CONTEXT && pdata->power_down)) { |
| 1037 | netdev_alert(netdev, "Device is already powered down\n"); |
| 1038 | DBGPR("<--xgbe_powerdown\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1042 | spin_lock_irqsave(&pdata->lock, flags); |
| 1043 | |
| 1044 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 1045 | netif_device_detach(netdev); |
| 1046 | |
| 1047 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1048 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1049 | xgbe_stop_timers(pdata); |
| 1050 | flush_workqueue(pdata->dev_workqueue); |
| 1051 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1052 | hw_if->powerdown_tx(pdata); |
| 1053 | hw_if->powerdown_rx(pdata); |
| 1054 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1055 | xgbe_napi_disable(pdata, 0); |
| 1056 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1057 | pdata->power_down = 1; |
| 1058 | |
| 1059 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 1060 | |
| 1061 | DBGPR("<--xgbe_powerdown\n"); |
| 1062 | |
| 1063 | return 0; |
| 1064 | } |
| 1065 | |
| 1066 | int xgbe_powerup(struct net_device *netdev, unsigned int caller) |
| 1067 | { |
| 1068 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1069 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1070 | unsigned long flags; |
| 1071 | |
| 1072 | DBGPR("-->xgbe_powerup\n"); |
| 1073 | |
| 1074 | if (!netif_running(netdev) || |
| 1075 | (caller == XGMAC_IOCTL_CONTEXT && !pdata->power_down)) { |
| 1076 | netdev_alert(netdev, "Device is already powered up\n"); |
| 1077 | DBGPR("<--xgbe_powerup\n"); |
| 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
| 1081 | spin_lock_irqsave(&pdata->lock, flags); |
| 1082 | |
| 1083 | pdata->power_down = 0; |
| 1084 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1085 | xgbe_napi_enable(pdata, 0); |
| 1086 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1087 | hw_if->powerup_tx(pdata); |
| 1088 | hw_if->powerup_rx(pdata); |
| 1089 | |
| 1090 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 1091 | netif_device_attach(netdev); |
| 1092 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1093 | netif_tx_start_all_queues(netdev); |
| 1094 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1095 | xgbe_start_timers(pdata); |
| 1096 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1097 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 1098 | |
| 1099 | DBGPR("<--xgbe_powerup\n"); |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | static int xgbe_start(struct xgbe_prv_data *pdata) |
| 1105 | { |
| 1106 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1107 | struct xgbe_phy_if *phy_if = &pdata->phy_if; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1108 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1109 | int ret; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1110 | |
| 1111 | DBGPR("-->xgbe_start\n"); |
| 1112 | |
Lendacky, Thomas | 738f7f6 | 2017-01-20 12:14:13 -0600 | [diff] [blame] | 1113 | ret = hw_if->init(pdata); |
| 1114 | if (ret) |
| 1115 | return ret; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1116 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1117 | xgbe_napi_enable(pdata, 1); |
| 1118 | |
| 1119 | ret = xgbe_request_irqs(pdata); |
| 1120 | if (ret) |
| 1121 | goto err_napi; |
| 1122 | |
Lendacky, Thomas | 47f164d | 2016-11-10 17:09:55 -0600 | [diff] [blame] | 1123 | ret = phy_if->phy_start(pdata); |
| 1124 | if (ret) |
| 1125 | goto err_irqs; |
| 1126 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1127 | hw_if->enable_tx(pdata); |
| 1128 | hw_if->enable_rx(pdata); |
| 1129 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1130 | netif_tx_start_all_queues(netdev); |
| 1131 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1132 | xgbe_start_timers(pdata); |
Lendacky, Thomas | afb43e8 | 2015-09-30 08:53:16 -0500 | [diff] [blame] | 1133 | queue_work(pdata->dev_workqueue, &pdata->service_work); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1134 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 1135 | clear_bit(XGBE_STOPPED, &pdata->dev_state); |
| 1136 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1137 | DBGPR("<--xgbe_start\n"); |
| 1138 | |
| 1139 | return 0; |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1140 | |
Lendacky, Thomas | 47f164d | 2016-11-10 17:09:55 -0600 | [diff] [blame] | 1141 | err_irqs: |
| 1142 | xgbe_free_irqs(pdata); |
| 1143 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1144 | err_napi: |
| 1145 | xgbe_napi_disable(pdata, 1); |
| 1146 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1147 | hw_if->exit(pdata); |
| 1148 | |
| 1149 | return ret; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void xgbe_stop(struct xgbe_prv_data *pdata) |
| 1153 | { |
| 1154 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1155 | struct xgbe_phy_if *phy_if = &pdata->phy_if; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1156 | struct xgbe_channel *channel; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1157 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1158 | struct netdev_queue *txq; |
| 1159 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1160 | |
| 1161 | DBGPR("-->xgbe_stop\n"); |
| 1162 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 1163 | if (test_bit(XGBE_STOPPED, &pdata->dev_state)) |
| 1164 | return; |
| 1165 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1166 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1167 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1168 | xgbe_stop_timers(pdata); |
| 1169 | flush_workqueue(pdata->dev_workqueue); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1170 | |
| 1171 | hw_if->disable_tx(pdata); |
| 1172 | hw_if->disable_rx(pdata); |
| 1173 | |
Lendacky, Thomas | 402168b | 2017-02-28 15:02:51 -0600 | [diff] [blame] | 1174 | phy_if->phy_stop(pdata); |
| 1175 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1176 | xgbe_free_irqs(pdata); |
| 1177 | |
| 1178 | xgbe_napi_disable(pdata, 1); |
| 1179 | |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1180 | hw_if->exit(pdata); |
| 1181 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1182 | channel = pdata->channel; |
| 1183 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 1184 | if (!channel->tx_ring) |
| 1185 | continue; |
| 1186 | |
| 1187 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
| 1188 | netdev_tx_reset_queue(txq); |
| 1189 | } |
| 1190 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 1191 | set_bit(XGBE_STOPPED, &pdata->dev_state); |
| 1192 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1193 | DBGPR("<--xgbe_stop\n"); |
| 1194 | } |
| 1195 | |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 1196 | static void xgbe_stopdev(struct work_struct *work) |
| 1197 | { |
| 1198 | struct xgbe_prv_data *pdata = container_of(work, |
| 1199 | struct xgbe_prv_data, |
| 1200 | stopdev_work); |
| 1201 | |
| 1202 | rtnl_lock(); |
| 1203 | |
| 1204 | xgbe_stop(pdata); |
| 1205 | |
| 1206 | xgbe_free_tx_data(pdata); |
| 1207 | xgbe_free_rx_data(pdata); |
| 1208 | |
| 1209 | rtnl_unlock(); |
| 1210 | |
| 1211 | netdev_alert(pdata->netdev, "device stopped\n"); |
| 1212 | } |
| 1213 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 1214 | static void xgbe_restart_dev(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1215 | { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1216 | DBGPR("-->xgbe_restart_dev\n"); |
| 1217 | |
| 1218 | /* If not running, "restart" will happen on open */ |
| 1219 | if (!netif_running(pdata->netdev)) |
| 1220 | return; |
| 1221 | |
| 1222 | xgbe_stop(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1223 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1224 | xgbe_free_tx_data(pdata); |
| 1225 | xgbe_free_rx_data(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1226 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1227 | xgbe_start(pdata); |
| 1228 | |
| 1229 | DBGPR("<--xgbe_restart_dev\n"); |
| 1230 | } |
| 1231 | |
| 1232 | static void xgbe_restart(struct work_struct *work) |
| 1233 | { |
| 1234 | struct xgbe_prv_data *pdata = container_of(work, |
| 1235 | struct xgbe_prv_data, |
| 1236 | restart_work); |
| 1237 | |
| 1238 | rtnl_lock(); |
| 1239 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 1240 | xgbe_restart_dev(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1241 | |
| 1242 | rtnl_unlock(); |
| 1243 | } |
| 1244 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1245 | static void xgbe_tx_tstamp(struct work_struct *work) |
| 1246 | { |
| 1247 | struct xgbe_prv_data *pdata = container_of(work, |
| 1248 | struct xgbe_prv_data, |
| 1249 | tx_tstamp_work); |
| 1250 | struct skb_shared_hwtstamps hwtstamps; |
| 1251 | u64 nsec; |
| 1252 | unsigned long flags; |
| 1253 | |
Lendacky, Thomas | 93845d5 | 2017-06-28 13:41:58 -0500 | [diff] [blame] | 1254 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 1255 | if (!pdata->tx_tstamp_skb) |
| 1256 | goto unlock; |
| 1257 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1258 | if (pdata->tx_tstamp) { |
| 1259 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 1260 | pdata->tx_tstamp); |
| 1261 | |
| 1262 | memset(&hwtstamps, 0, sizeof(hwtstamps)); |
| 1263 | hwtstamps.hwtstamp = ns_to_ktime(nsec); |
| 1264 | skb_tstamp_tx(pdata->tx_tstamp_skb, &hwtstamps); |
| 1265 | } |
| 1266 | |
| 1267 | dev_kfree_skb_any(pdata->tx_tstamp_skb); |
| 1268 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1269 | pdata->tx_tstamp_skb = NULL; |
Lendacky, Thomas | 93845d5 | 2017-06-28 13:41:58 -0500 | [diff] [blame] | 1270 | |
| 1271 | unlock: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1272 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 1273 | } |
| 1274 | |
| 1275 | static int xgbe_get_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 1276 | struct ifreq *ifreq) |
| 1277 | { |
| 1278 | if (copy_to_user(ifreq->ifr_data, &pdata->tstamp_config, |
| 1279 | sizeof(pdata->tstamp_config))) |
| 1280 | return -EFAULT; |
| 1281 | |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 1286 | struct ifreq *ifreq) |
| 1287 | { |
| 1288 | struct hwtstamp_config config; |
| 1289 | unsigned int mac_tscr; |
| 1290 | |
| 1291 | if (copy_from_user(&config, ifreq->ifr_data, sizeof(config))) |
| 1292 | return -EFAULT; |
| 1293 | |
| 1294 | if (config.flags) |
| 1295 | return -EINVAL; |
| 1296 | |
| 1297 | mac_tscr = 0; |
| 1298 | |
| 1299 | switch (config.tx_type) { |
| 1300 | case HWTSTAMP_TX_OFF: |
| 1301 | break; |
| 1302 | |
| 1303 | case HWTSTAMP_TX_ON: |
| 1304 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1305 | break; |
| 1306 | |
| 1307 | default: |
| 1308 | return -ERANGE; |
| 1309 | } |
| 1310 | |
| 1311 | switch (config.rx_filter) { |
| 1312 | case HWTSTAMP_FILTER_NONE: |
| 1313 | break; |
| 1314 | |
Miroslav Lichvar | e341257 | 2017-05-19 17:52:36 +0200 | [diff] [blame] | 1315 | case HWTSTAMP_FILTER_NTP_ALL: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1316 | case HWTSTAMP_FILTER_ALL: |
| 1317 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1); |
| 1318 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1319 | break; |
| 1320 | |
| 1321 | /* PTP v2, UDP, any kind of event packet */ |
| 1322 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 1323 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1324 | /* PTP v1, UDP, any kind of event packet */ |
| 1325 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 1326 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1327 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1328 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1329 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1330 | break; |
| 1331 | |
| 1332 | /* PTP v2, UDP, Sync packet */ |
| 1333 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 1334 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1335 | /* PTP v1, UDP, Sync packet */ |
| 1336 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 1337 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1338 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1339 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1340 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1341 | break; |
| 1342 | |
| 1343 | /* PTP v2, UDP, Delay_req packet */ |
| 1344 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 1345 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1346 | /* PTP v1, UDP, Delay_req packet */ |
| 1347 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 1348 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1349 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1350 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1351 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1352 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1353 | break; |
| 1354 | |
| 1355 | /* 802.AS1, Ethernet, any kind of event packet */ |
| 1356 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 1357 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1358 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1359 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1360 | break; |
| 1361 | |
| 1362 | /* 802.AS1, Ethernet, Sync packet */ |
| 1363 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 1364 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1365 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1366 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1367 | break; |
| 1368 | |
| 1369 | /* 802.AS1, Ethernet, Delay_req packet */ |
| 1370 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 1371 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1372 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1373 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1374 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1375 | break; |
| 1376 | |
| 1377 | /* PTP v2/802.AS1, any layer, any kind of event packet */ |
| 1378 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 1379 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1380 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1381 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1382 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1383 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1384 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1385 | break; |
| 1386 | |
| 1387 | /* PTP v2/802.AS1, any layer, Sync packet */ |
| 1388 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 1389 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1390 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1391 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1392 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1393 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1394 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1395 | break; |
| 1396 | |
| 1397 | /* PTP v2/802.AS1, any layer, Delay_req packet */ |
| 1398 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 1399 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1400 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1401 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1402 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1403 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1404 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1405 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1406 | break; |
| 1407 | |
| 1408 | default: |
| 1409 | return -ERANGE; |
| 1410 | } |
| 1411 | |
| 1412 | pdata->hw_if.config_tstamp(pdata, mac_tscr); |
| 1413 | |
| 1414 | memcpy(&pdata->tstamp_config, &config, sizeof(config)); |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | static void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata, |
| 1420 | struct sk_buff *skb, |
| 1421 | struct xgbe_packet_data *packet) |
| 1422 | { |
| 1423 | unsigned long flags; |
| 1424 | |
| 1425 | if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) { |
| 1426 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 1427 | if (pdata->tx_tstamp_skb) { |
| 1428 | /* Another timestamp in progress, ignore this one */ |
| 1429 | XGMAC_SET_BITS(packet->attributes, |
| 1430 | TX_PACKET_ATTRIBUTES, PTP, 0); |
| 1431 | } else { |
| 1432 | pdata->tx_tstamp_skb = skb_get(skb); |
| 1433 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 1434 | } |
| 1435 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 1436 | } |
| 1437 | |
Miroslav Lichvar | 74abc9b1 | 2017-05-19 17:52:41 +0200 | [diff] [blame] | 1438 | skb_tx_timestamp(skb); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1439 | } |
| 1440 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1441 | static void xgbe_prep_vlan(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 1442 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1443 | if (skb_vlan_tag_present(skb)) |
| 1444 | packet->vlan_ctag = skb_vlan_tag_get(skb); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | static int xgbe_prep_tso(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 1448 | { |
| 1449 | int ret; |
| 1450 | |
| 1451 | if (!XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1452 | TSO_ENABLE)) |
| 1453 | return 0; |
| 1454 | |
| 1455 | ret = skb_cow_head(skb, 0); |
| 1456 | if (ret) |
| 1457 | return ret; |
| 1458 | |
| 1459 | packet->header_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1460 | packet->tcp_header_len = tcp_hdrlen(skb); |
| 1461 | packet->tcp_payload_len = skb->len - packet->header_len; |
| 1462 | packet->mss = skb_shinfo(skb)->gso_size; |
| 1463 | DBGPR(" packet->header_len=%u\n", packet->header_len); |
| 1464 | DBGPR(" packet->tcp_header_len=%u, packet->tcp_payload_len=%u\n", |
| 1465 | packet->tcp_header_len, packet->tcp_payload_len); |
| 1466 | DBGPR(" packet->mss=%u\n", packet->mss); |
| 1467 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1468 | /* Update the number of packets that will ultimately be transmitted |
| 1469 | * along with the extra bytes for each extra packet |
| 1470 | */ |
| 1471 | packet->tx_packets = skb_shinfo(skb)->gso_segs; |
| 1472 | packet->tx_bytes += (packet->tx_packets - 1) * packet->header_len; |
| 1473 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | static int xgbe_is_tso(struct sk_buff *skb) |
| 1478 | { |
| 1479 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1480 | return 0; |
| 1481 | |
| 1482 | if (!skb_is_gso(skb)) |
| 1483 | return 0; |
| 1484 | |
| 1485 | DBGPR(" TSO packet to be processed\n"); |
| 1486 | |
| 1487 | return 1; |
| 1488 | } |
| 1489 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1490 | static void xgbe_packet_info(struct xgbe_prv_data *pdata, |
| 1491 | struct xgbe_ring *ring, struct sk_buff *skb, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1492 | struct xgbe_packet_data *packet) |
| 1493 | { |
| 1494 | struct skb_frag_struct *frag; |
| 1495 | unsigned int context_desc; |
| 1496 | unsigned int len; |
| 1497 | unsigned int i; |
| 1498 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1499 | packet->skb = skb; |
| 1500 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1501 | context_desc = 0; |
| 1502 | packet->rdesc_count = 0; |
| 1503 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1504 | packet->tx_packets = 1; |
| 1505 | packet->tx_bytes = skb->len; |
| 1506 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1507 | if (xgbe_is_tso(skb)) { |
Lendacky, Thomas | a7beaf2 | 2014-11-04 16:07:29 -0600 | [diff] [blame] | 1508 | /* TSO requires an extra descriptor if mss is different */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1509 | if (skb_shinfo(skb)->gso_size != ring->tx.cur_mss) { |
| 1510 | context_desc = 1; |
| 1511 | packet->rdesc_count++; |
| 1512 | } |
| 1513 | |
Lendacky, Thomas | a7beaf2 | 2014-11-04 16:07:29 -0600 | [diff] [blame] | 1514 | /* TSO requires an extra descriptor for TSO header */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1515 | packet->rdesc_count++; |
| 1516 | |
| 1517 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1518 | TSO_ENABLE, 1); |
| 1519 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1520 | CSUM_ENABLE, 1); |
| 1521 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 1522 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1523 | CSUM_ENABLE, 1); |
| 1524 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1525 | if (skb_vlan_tag_present(skb)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1526 | /* VLAN requires an extra descriptor if tag is different */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1527 | if (skb_vlan_tag_get(skb) != ring->tx.cur_vlan_ctag) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1528 | /* We can share with the TSO context descriptor */ |
| 1529 | if (!context_desc) { |
| 1530 | context_desc = 1; |
| 1531 | packet->rdesc_count++; |
| 1532 | } |
| 1533 | |
| 1534 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1535 | VLAN_CTAG, 1); |
| 1536 | } |
| 1537 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1538 | if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 1539 | (pdata->tstamp_config.tx_type == HWTSTAMP_TX_ON)) |
| 1540 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1541 | PTP, 1); |
| 1542 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1543 | for (len = skb_headlen(skb); len;) { |
| 1544 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1545 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1549 | frag = &skb_shinfo(skb)->frags[i]; |
| 1550 | for (len = skb_frag_size(frag); len; ) { |
| 1551 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1552 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | static int xgbe_open(struct net_device *netdev) |
| 1558 | { |
| 1559 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1560 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1561 | int ret; |
| 1562 | |
| 1563 | DBGPR("-->xgbe_open\n"); |
| 1564 | |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 1565 | /* Reset the phy settings */ |
| 1566 | ret = xgbe_phy_reset(pdata); |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1567 | if (ret) |
| 1568 | return ret; |
| 1569 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1570 | /* Enable the clocks */ |
| 1571 | ret = clk_prepare_enable(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1572 | if (ret) { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1573 | netdev_alert(netdev, "dma clk_prepare_enable failed\n"); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1574 | return ret; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1577 | ret = clk_prepare_enable(pdata->ptpclk); |
| 1578 | if (ret) { |
| 1579 | netdev_alert(netdev, "ptp clk_prepare_enable failed\n"); |
| 1580 | goto err_sysclk; |
| 1581 | } |
| 1582 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1583 | /* Calculate the Rx buffer size before allocating rings */ |
| 1584 | ret = xgbe_calc_rx_buf_size(netdev, netdev->mtu); |
| 1585 | if (ret < 0) |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1586 | goto err_ptpclk; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1587 | pdata->rx_buf_size = ret; |
| 1588 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1589 | /* Allocate the channel and ring structures */ |
| 1590 | ret = xgbe_alloc_channels(pdata); |
| 1591 | if (ret) |
| 1592 | goto err_ptpclk; |
| 1593 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1594 | /* Allocate the ring descriptors and buffers */ |
| 1595 | ret = desc_if->alloc_ring_resources(pdata); |
| 1596 | if (ret) |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1597 | goto err_channels; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1598 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1599 | INIT_WORK(&pdata->service_work, xgbe_service); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1600 | INIT_WORK(&pdata->restart_work, xgbe_restart); |
Lendacky, Thomas | e78332b | 2016-11-10 17:10:26 -0600 | [diff] [blame] | 1601 | INIT_WORK(&pdata->stopdev_work, xgbe_stopdev); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1602 | INIT_WORK(&pdata->tx_tstamp_work, xgbe_tx_tstamp); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1603 | xgbe_init_timers(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1604 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1605 | ret = xgbe_start(pdata); |
| 1606 | if (ret) |
Lendacky, Thomas | c30e76a | 2015-02-25 13:50:12 -0600 | [diff] [blame] | 1607 | goto err_rings; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1608 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1609 | clear_bit(XGBE_DOWN, &pdata->dev_state); |
| 1610 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1611 | DBGPR("<--xgbe_open\n"); |
| 1612 | |
| 1613 | return 0; |
| 1614 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1615 | err_rings: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1616 | desc_if->free_ring_resources(pdata); |
| 1617 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1618 | err_channels: |
| 1619 | xgbe_free_channels(pdata); |
| 1620 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1621 | err_ptpclk: |
| 1622 | clk_disable_unprepare(pdata->ptpclk); |
| 1623 | |
| 1624 | err_sysclk: |
| 1625 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1626 | |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | static int xgbe_close(struct net_device *netdev) |
| 1631 | { |
| 1632 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1633 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1634 | |
| 1635 | DBGPR("-->xgbe_close\n"); |
| 1636 | |
| 1637 | /* Stop the device */ |
| 1638 | xgbe_stop(pdata); |
| 1639 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1640 | /* Free the ring descriptors and buffers */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1641 | desc_if->free_ring_resources(pdata); |
| 1642 | |
Lendacky, Thomas | e98c72c | 2014-11-06 17:02:13 -0600 | [diff] [blame] | 1643 | /* Free the channel and ring structures */ |
| 1644 | xgbe_free_channels(pdata); |
| 1645 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1646 | /* Disable the clocks */ |
| 1647 | clk_disable_unprepare(pdata->ptpclk); |
| 1648 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1649 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 1650 | set_bit(XGBE_DOWN, &pdata->dev_state); |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1651 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1652 | DBGPR("<--xgbe_close\n"); |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
| 1657 | static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1658 | { |
| 1659 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1660 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1661 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1662 | struct xgbe_channel *channel; |
| 1663 | struct xgbe_ring *ring; |
| 1664 | struct xgbe_packet_data *packet; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1665 | struct netdev_queue *txq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1666 | int ret; |
| 1667 | |
| 1668 | DBGPR("-->xgbe_xmit: skb->len = %d\n", skb->len); |
| 1669 | |
| 1670 | channel = pdata->channel + skb->queue_mapping; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1671 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1672 | ring = channel->tx_ring; |
| 1673 | packet = &ring->packet_data; |
| 1674 | |
| 1675 | ret = NETDEV_TX_OK; |
| 1676 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1677 | if (skb->len == 0) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1678 | netif_err(pdata, tx_err, netdev, |
| 1679 | "empty skb received from stack\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1680 | dev_kfree_skb_any(skb); |
| 1681 | goto tx_netdev_return; |
| 1682 | } |
| 1683 | |
| 1684 | /* Calculate preliminary packet info */ |
| 1685 | memset(packet, 0, sizeof(*packet)); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1686 | xgbe_packet_info(pdata, ring, skb, packet); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1687 | |
| 1688 | /* Check that there are enough descriptors available */ |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1689 | ret = xgbe_maybe_stop_tx_queue(channel, ring, packet->rdesc_count); |
| 1690 | if (ret) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1691 | goto tx_netdev_return; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1692 | |
| 1693 | ret = xgbe_prep_tso(skb, packet); |
| 1694 | if (ret) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1695 | netif_err(pdata, tx_err, netdev, |
| 1696 | "error processing TSO packet\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1697 | dev_kfree_skb_any(skb); |
| 1698 | goto tx_netdev_return; |
| 1699 | } |
| 1700 | xgbe_prep_vlan(skb, packet); |
| 1701 | |
| 1702 | if (!desc_if->map_tx_skb(channel, skb)) { |
| 1703 | dev_kfree_skb_any(skb); |
| 1704 | goto tx_netdev_return; |
| 1705 | } |
| 1706 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1707 | xgbe_prep_tx_tstamp(pdata, skb, packet); |
| 1708 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1709 | /* Report on the actual number of bytes (to be) sent */ |
| 1710 | netdev_tx_sent_queue(txq, packet->tx_bytes); |
| 1711 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1712 | /* Configure required descriptor fields for transmission */ |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 1713 | hw_if->dev_xmit(channel); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1714 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 1715 | if (netif_msg_pktdata(pdata)) |
| 1716 | xgbe_print_pkt(netdev, skb, true); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1717 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1718 | /* Stop the queue in advance if there may not be enough descriptors */ |
| 1719 | xgbe_maybe_stop_tx_queue(channel, ring, XGBE_TX_MAX_DESCS); |
| 1720 | |
| 1721 | ret = NETDEV_TX_OK; |
| 1722 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1723 | tx_netdev_return: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1724 | return ret; |
| 1725 | } |
| 1726 | |
| 1727 | static void xgbe_set_rx_mode(struct net_device *netdev) |
| 1728 | { |
| 1729 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1730 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1731 | |
| 1732 | DBGPR("-->xgbe_set_rx_mode\n"); |
| 1733 | |
Lendacky, Thomas | b876382 | 2015-04-09 12:11:57 -0500 | [diff] [blame] | 1734 | hw_if->config_rx_mode(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1735 | |
| 1736 | DBGPR("<--xgbe_set_rx_mode\n"); |
| 1737 | } |
| 1738 | |
| 1739 | static int xgbe_set_mac_address(struct net_device *netdev, void *addr) |
| 1740 | { |
| 1741 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1742 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1743 | struct sockaddr *saddr = addr; |
| 1744 | |
| 1745 | DBGPR("-->xgbe_set_mac_address\n"); |
| 1746 | |
| 1747 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 1748 | return -EADDRNOTAVAIL; |
| 1749 | |
| 1750 | memcpy(netdev->dev_addr, saddr->sa_data, netdev->addr_len); |
| 1751 | |
| 1752 | hw_if->set_mac_address(pdata, netdev->dev_addr); |
| 1753 | |
| 1754 | DBGPR("<--xgbe_set_mac_address\n"); |
| 1755 | |
| 1756 | return 0; |
| 1757 | } |
| 1758 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1759 | static int xgbe_ioctl(struct net_device *netdev, struct ifreq *ifreq, int cmd) |
| 1760 | { |
| 1761 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1762 | int ret; |
| 1763 | |
| 1764 | switch (cmd) { |
| 1765 | case SIOCGHWTSTAMP: |
| 1766 | ret = xgbe_get_hwtstamp_settings(pdata, ifreq); |
| 1767 | break; |
| 1768 | |
| 1769 | case SIOCSHWTSTAMP: |
| 1770 | ret = xgbe_set_hwtstamp_settings(pdata, ifreq); |
| 1771 | break; |
| 1772 | |
| 1773 | default: |
| 1774 | ret = -EOPNOTSUPP; |
| 1775 | } |
| 1776 | |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1780 | static int xgbe_change_mtu(struct net_device *netdev, int mtu) |
| 1781 | { |
| 1782 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1783 | int ret; |
| 1784 | |
| 1785 | DBGPR("-->xgbe_change_mtu\n"); |
| 1786 | |
| 1787 | ret = xgbe_calc_rx_buf_size(netdev, mtu); |
| 1788 | if (ret < 0) |
| 1789 | return ret; |
| 1790 | |
| 1791 | pdata->rx_buf_size = ret; |
| 1792 | netdev->mtu = mtu; |
| 1793 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 1794 | xgbe_restart_dev(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1795 | |
| 1796 | DBGPR("<--xgbe_change_mtu\n"); |
| 1797 | |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
Lendacky, Thomas | a8373f1 | 2015-04-09 12:12:03 -0500 | [diff] [blame] | 1801 | static void xgbe_tx_timeout(struct net_device *netdev) |
| 1802 | { |
| 1803 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1804 | |
| 1805 | netdev_warn(netdev, "tx timeout, device restarting\n"); |
Lendacky, Thomas | 96aec91 | 2015-10-14 12:37:32 -0500 | [diff] [blame] | 1806 | schedule_work(&pdata->restart_work); |
Lendacky, Thomas | a8373f1 | 2015-04-09 12:12:03 -0500 | [diff] [blame] | 1807 | } |
| 1808 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 1809 | static void xgbe_get_stats64(struct net_device *netdev, |
| 1810 | struct rtnl_link_stats64 *s) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1811 | { |
| 1812 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1813 | struct xgbe_mmc_stats *pstats = &pdata->mmc_stats; |
| 1814 | |
| 1815 | DBGPR("-->%s\n", __func__); |
| 1816 | |
| 1817 | pdata->hw_if.read_mmc_stats(pdata); |
| 1818 | |
| 1819 | s->rx_packets = pstats->rxframecount_gb; |
| 1820 | s->rx_bytes = pstats->rxoctetcount_gb; |
| 1821 | s->rx_errors = pstats->rxframecount_gb - |
| 1822 | pstats->rxbroadcastframes_g - |
| 1823 | pstats->rxmulticastframes_g - |
| 1824 | pstats->rxunicastframes_g; |
| 1825 | s->multicast = pstats->rxmulticastframes_g; |
| 1826 | s->rx_length_errors = pstats->rxlengtherror; |
| 1827 | s->rx_crc_errors = pstats->rxcrcerror; |
| 1828 | s->rx_fifo_errors = pstats->rxfifooverflow; |
| 1829 | |
| 1830 | s->tx_packets = pstats->txframecount_gb; |
| 1831 | s->tx_bytes = pstats->txoctetcount_gb; |
| 1832 | s->tx_errors = pstats->txframecount_gb - pstats->txframecount_g; |
| 1833 | s->tx_dropped = netdev->stats.tx_dropped; |
| 1834 | |
| 1835 | DBGPR("<--%s\n", __func__); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1836 | } |
| 1837 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1838 | static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, |
| 1839 | u16 vid) |
| 1840 | { |
| 1841 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1842 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1843 | |
| 1844 | DBGPR("-->%s\n", __func__); |
| 1845 | |
| 1846 | set_bit(vid, pdata->active_vlans); |
| 1847 | hw_if->update_vlan_hash_table(pdata); |
| 1848 | |
| 1849 | DBGPR("<--%s\n", __func__); |
| 1850 | |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, |
| 1855 | u16 vid) |
| 1856 | { |
| 1857 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1858 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1859 | |
| 1860 | DBGPR("-->%s\n", __func__); |
| 1861 | |
| 1862 | clear_bit(vid, pdata->active_vlans); |
| 1863 | hw_if->update_vlan_hash_table(pdata); |
| 1864 | |
| 1865 | DBGPR("<--%s\n", __func__); |
| 1866 | |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1870 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1871 | static void xgbe_poll_controller(struct net_device *netdev) |
| 1872 | { |
| 1873 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1874 | struct xgbe_channel *channel; |
| 1875 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1876 | |
| 1877 | DBGPR("-->xgbe_poll_controller\n"); |
| 1878 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1879 | if (pdata->per_channel_irq) { |
| 1880 | channel = pdata->channel; |
| 1881 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 1882 | xgbe_dma_isr(channel->dma_irq, channel); |
| 1883 | } else { |
| 1884 | disable_irq(pdata->dev_irq); |
| 1885 | xgbe_isr(pdata->dev_irq, pdata); |
| 1886 | enable_irq(pdata->dev_irq); |
| 1887 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1888 | |
| 1889 | DBGPR("<--xgbe_poll_controller\n"); |
| 1890 | } |
| 1891 | #endif /* End CONFIG_NET_POLL_CONTROLLER */ |
| 1892 | |
Jiri Pirko | a5fcf8a | 2017-06-06 17:00:16 +0200 | [diff] [blame] | 1893 | static int xgbe_setup_tc(struct net_device *netdev, u32 handle, u32 chain_index, |
| 1894 | __be16 proto, |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 1895 | struct tc_to_netdev *tc_to_netdev) |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1896 | { |
| 1897 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | b3b7159 | 2016-02-17 11:49:08 -0600 | [diff] [blame] | 1898 | u8 tc; |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1899 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 1900 | if (tc_to_netdev->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 1901 | return -EINVAL; |
| 1902 | |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 1903 | tc_to_netdev->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 1904 | tc = tc_to_netdev->mqprio->num_tc; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 1905 | |
Lendacky, Thomas | b3b7159 | 2016-02-17 11:49:08 -0600 | [diff] [blame] | 1906 | if (tc > pdata->hw_feat.tc_cnt) |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1907 | return -EINVAL; |
| 1908 | |
Lendacky, Thomas | b3b7159 | 2016-02-17 11:49:08 -0600 | [diff] [blame] | 1909 | pdata->num_tcs = tc; |
| 1910 | pdata->hw_if.config_tc(pdata); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1911 | |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1915 | static int xgbe_set_features(struct net_device *netdev, |
| 1916 | netdev_features_t features) |
| 1917 | { |
| 1918 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1919 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1920 | netdev_features_t rxhash, rxcsum, rxvlan, rxvlan_filter; |
| 1921 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1922 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1923 | rxhash = pdata->netdev_features & NETIF_F_RXHASH; |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1924 | rxcsum = pdata->netdev_features & NETIF_F_RXCSUM; |
| 1925 | rxvlan = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_RX; |
| 1926 | rxvlan_filter = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_FILTER; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1927 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1928 | if ((features & NETIF_F_RXHASH) && !rxhash) |
| 1929 | ret = hw_if->enable_rss(pdata); |
| 1930 | else if (!(features & NETIF_F_RXHASH) && rxhash) |
| 1931 | ret = hw_if->disable_rss(pdata); |
| 1932 | if (ret) |
| 1933 | return ret; |
| 1934 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1935 | if ((features & NETIF_F_RXCSUM) && !rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1936 | hw_if->enable_rx_csum(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1937 | else if (!(features & NETIF_F_RXCSUM) && rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1938 | hw_if->disable_rx_csum(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1939 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1940 | if ((features & NETIF_F_HW_VLAN_CTAG_RX) && !rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1941 | hw_if->enable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1942 | else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) && rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1943 | hw_if->disable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1944 | |
| 1945 | if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && !rxvlan_filter) |
| 1946 | hw_if->enable_rx_vlan_filtering(pdata); |
| 1947 | else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && rxvlan_filter) |
| 1948 | hw_if->disable_rx_vlan_filtering(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1949 | |
| 1950 | pdata->netdev_features = features; |
| 1951 | |
| 1952 | DBGPR("<--xgbe_set_features\n"); |
| 1953 | |
| 1954 | return 0; |
| 1955 | } |
| 1956 | |
| 1957 | static const struct net_device_ops xgbe_netdev_ops = { |
| 1958 | .ndo_open = xgbe_open, |
| 1959 | .ndo_stop = xgbe_close, |
| 1960 | .ndo_start_xmit = xgbe_xmit, |
| 1961 | .ndo_set_rx_mode = xgbe_set_rx_mode, |
| 1962 | .ndo_set_mac_address = xgbe_set_mac_address, |
| 1963 | .ndo_validate_addr = eth_validate_addr, |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1964 | .ndo_do_ioctl = xgbe_ioctl, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1965 | .ndo_change_mtu = xgbe_change_mtu, |
Lendacky, Thomas | a8373f1 | 2015-04-09 12:12:03 -0500 | [diff] [blame] | 1966 | .ndo_tx_timeout = xgbe_tx_timeout, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1967 | .ndo_get_stats64 = xgbe_get_stats64, |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1968 | .ndo_vlan_rx_add_vid = xgbe_vlan_rx_add_vid, |
| 1969 | .ndo_vlan_rx_kill_vid = xgbe_vlan_rx_kill_vid, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1970 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1971 | .ndo_poll_controller = xgbe_poll_controller, |
| 1972 | #endif |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1973 | .ndo_setup_tc = xgbe_setup_tc, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1974 | .ndo_set_features = xgbe_set_features, |
| 1975 | }; |
| 1976 | |
stephen hemminger | ce0b15d | 2016-08-31 08:57:36 -0700 | [diff] [blame] | 1977 | const struct net_device_ops *xgbe_get_netdev_ops(void) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1978 | { |
stephen hemminger | ce0b15d | 2016-08-31 08:57:36 -0700 | [diff] [blame] | 1979 | return &xgbe_netdev_ops; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1982 | static void xgbe_rx_refresh(struct xgbe_channel *channel) |
| 1983 | { |
| 1984 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 1985 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1986 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1987 | struct xgbe_ring *ring = channel->rx_ring; |
| 1988 | struct xgbe_ring_data *rdata; |
| 1989 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 1990 | while (ring->dirty != ring->cur) { |
| 1991 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty); |
| 1992 | |
| 1993 | /* Reset rdata values */ |
| 1994 | desc_if->unmap_rdata(pdata, rdata); |
| 1995 | |
| 1996 | if (desc_if->map_rx_buffer(pdata, ring, rdata)) |
| 1997 | break; |
| 1998 | |
Lendacky, Thomas | 8dee19e | 2015-04-09 12:11:51 -0500 | [diff] [blame] | 1999 | hw_if->rx_desc_reset(pdata, rdata, ring->dirty); |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 2000 | |
| 2001 | ring->dirty++; |
| 2002 | } |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2003 | |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 2004 | /* Make sure everything is written before the register write */ |
| 2005 | wmb(); |
| 2006 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2007 | /* Update the Rx Tail Pointer Register with address of |
| 2008 | * the last cleaned entry */ |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 2009 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty - 1); |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2010 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO, |
| 2011 | lower_32_bits(rdata->rdesc_dma)); |
| 2012 | } |
| 2013 | |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2014 | static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata, |
| 2015 | struct napi_struct *napi, |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2016 | struct xgbe_ring_data *rdata, |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2017 | unsigned int len) |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2018 | { |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2019 | struct sk_buff *skb; |
| 2020 | u8 *packet; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2021 | |
Lendacky, Thomas | 385565a | 2015-03-20 11:50:41 -0500 | [diff] [blame] | 2022 | skb = napi_alloc_skb(napi, rdata->rx.hdr.dma_len); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2023 | if (!skb) |
| 2024 | return NULL; |
| 2025 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2026 | /* Pull in the header buffer which may contain just the header |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2027 | * or the header plus data |
| 2028 | */ |
Lendacky, Thomas | cfbfd86 | 2015-07-06 11:57:37 -0500 | [diff] [blame] | 2029 | dma_sync_single_range_for_cpu(pdata->dev, rdata->rx.hdr.dma_base, |
| 2030 | rdata->rx.hdr.dma_off, |
| 2031 | rdata->rx.hdr.dma_len, DMA_FROM_DEVICE); |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2032 | |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2033 | packet = page_address(rdata->rx.hdr.pa.pages) + |
| 2034 | rdata->rx.hdr.pa.pages_offset; |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2035 | skb_copy_to_linear_data(skb, packet, len); |
| 2036 | skb_put(skb, len); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2037 | |
| 2038 | return skb; |
| 2039 | } |
| 2040 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2041 | static unsigned int xgbe_rx_buf1_len(struct xgbe_ring_data *rdata, |
| 2042 | struct xgbe_packet_data *packet) |
| 2043 | { |
| 2044 | /* Always zero if not the first descriptor */ |
| 2045 | if (!XGMAC_GET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, FIRST)) |
| 2046 | return 0; |
| 2047 | |
| 2048 | /* First descriptor with split header, return header length */ |
| 2049 | if (rdata->rx.hdr_len) |
| 2050 | return rdata->rx.hdr_len; |
| 2051 | |
| 2052 | /* First descriptor but not the last descriptor and no split header, |
| 2053 | * so the full buffer was used |
| 2054 | */ |
| 2055 | if (!XGMAC_GET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, LAST)) |
| 2056 | return rdata->rx.hdr.dma_len; |
| 2057 | |
| 2058 | /* First descriptor and last descriptor and no split header, so |
| 2059 | * calculate how much of the buffer was used |
| 2060 | */ |
| 2061 | return min_t(unsigned int, rdata->rx.hdr.dma_len, rdata->rx.len); |
| 2062 | } |
| 2063 | |
| 2064 | static unsigned int xgbe_rx_buf2_len(struct xgbe_ring_data *rdata, |
| 2065 | struct xgbe_packet_data *packet, |
| 2066 | unsigned int len) |
| 2067 | { |
| 2068 | /* Always the full buffer if not the last descriptor */ |
| 2069 | if (!XGMAC_GET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, LAST)) |
| 2070 | return rdata->rx.buf.dma_len; |
| 2071 | |
| 2072 | /* Last descriptor so calculate how much of the buffer was used |
| 2073 | * for the last bit of data |
| 2074 | */ |
| 2075 | return rdata->rx.len - len; |
| 2076 | } |
| 2077 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2078 | static int xgbe_tx_poll(struct xgbe_channel *channel) |
| 2079 | { |
| 2080 | struct xgbe_prv_data *pdata = channel->pdata; |
| 2081 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 2082 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 2083 | struct xgbe_ring *ring = channel->tx_ring; |
| 2084 | struct xgbe_ring_data *rdata; |
| 2085 | struct xgbe_ring_desc *rdesc; |
| 2086 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2087 | struct netdev_queue *txq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2088 | int processed = 0; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2089 | unsigned int tx_packets = 0, tx_bytes = 0; |
Lendacky, Thomas | 20a41fb | 2015-10-21 15:37:05 -0500 | [diff] [blame] | 2090 | unsigned int cur; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2091 | |
| 2092 | DBGPR("-->xgbe_tx_poll\n"); |
| 2093 | |
| 2094 | /* Nothing to do if there isn't a Tx ring for this channel */ |
| 2095 | if (!ring) |
| 2096 | return 0; |
| 2097 | |
Lendacky, Thomas | 20a41fb | 2015-10-21 15:37:05 -0500 | [diff] [blame] | 2098 | cur = ring->cur; |
Lendacky, Thomas | 20986ed | 2015-10-26 17:13:54 -0500 | [diff] [blame] | 2099 | |
| 2100 | /* Be sure we get ring->cur before accessing descriptor data */ |
| 2101 | smp_rmb(); |
| 2102 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2103 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
| 2104 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 2105 | while ((processed < XGBE_TX_DESC_MAX_PROC) && |
Lendacky, Thomas | 20a41fb | 2015-10-21 15:37:05 -0500 | [diff] [blame] | 2106 | (ring->dirty != cur)) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 2107 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2108 | rdesc = rdata->rdesc; |
| 2109 | |
| 2110 | if (!hw_if->tx_complete(rdesc)) |
| 2111 | break; |
| 2112 | |
Lendacky, Thomas | 5449e27 | 2014-11-20 11:03:26 -0600 | [diff] [blame] | 2113 | /* Make sure descriptor fields are read after reading the OWN |
| 2114 | * bit */ |
Lendacky, Thomas | ceb8f6b | 2015-03-20 11:50:16 -0500 | [diff] [blame] | 2115 | dma_rmb(); |
Lendacky, Thomas | 5449e27 | 2014-11-20 11:03:26 -0600 | [diff] [blame] | 2116 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2117 | if (netif_msg_tx_done(pdata)) |
| 2118 | xgbe_dump_tx_desc(pdata, ring, ring->dirty, 1, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2119 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2120 | if (hw_if->is_last_desc(rdesc)) { |
| 2121 | tx_packets += rdata->tx.packets; |
| 2122 | tx_bytes += rdata->tx.bytes; |
| 2123 | } |
| 2124 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2125 | /* Free the SKB and reset the descriptor for re-use */ |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2126 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2127 | hw_if->tx_desc_reset(rdata); |
| 2128 | |
| 2129 | processed++; |
| 2130 | ring->dirty++; |
| 2131 | } |
| 2132 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2133 | if (!processed) |
Lendacky, Thomas | a83ef42 | 2015-01-16 12:46:55 -0600 | [diff] [blame] | 2134 | return 0; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2135 | |
| 2136 | netdev_tx_completed_queue(txq, tx_packets, tx_bytes); |
| 2137 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2138 | if ((ring->tx.queue_stopped == 1) && |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 2139 | (xgbe_tx_avail_desc(ring) > XGBE_TX_DESC_MIN_FREE)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2140 | ring->tx.queue_stopped = 0; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 2141 | netif_tx_wake_queue(txq); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | DBGPR("<--xgbe_tx_poll: processed=%d\n", processed); |
| 2145 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2146 | return processed; |
| 2147 | } |
| 2148 | |
| 2149 | static int xgbe_rx_poll(struct xgbe_channel *channel, int budget) |
| 2150 | { |
| 2151 | struct xgbe_prv_data *pdata = channel->pdata; |
| 2152 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2153 | struct xgbe_ring *ring = channel->rx_ring; |
| 2154 | struct xgbe_ring_data *rdata; |
| 2155 | struct xgbe_packet_data *packet; |
| 2156 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2157 | struct napi_struct *napi; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2158 | struct sk_buff *skb; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2159 | struct skb_shared_hwtstamps *hwtstamps; |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2160 | unsigned int last, error, context_next, context; |
| 2161 | unsigned int len, buf1_len, buf2_len, max_len; |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2162 | unsigned int received = 0; |
| 2163 | int packet_count = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2164 | |
| 2165 | DBGPR("-->xgbe_rx_poll: budget=%d\n", budget); |
| 2166 | |
| 2167 | /* Nothing to do if there isn't a Rx ring for this channel */ |
| 2168 | if (!ring) |
| 2169 | return 0; |
| 2170 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2171 | last = 0; |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2172 | context_next = 0; |
| 2173 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2174 | napi = (pdata->per_channel_irq) ? &channel->napi : &pdata->napi; |
| 2175 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2176 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2177 | packet = &ring->packet_data; |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2178 | while (packet_count < budget) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2179 | DBGPR(" cur = %d\n", ring->cur); |
| 2180 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2181 | /* First time in loop see if we need to restore state */ |
| 2182 | if (!received && rdata->state_saved) { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2183 | skb = rdata->state.skb; |
| 2184 | error = rdata->state.error; |
| 2185 | len = rdata->state.len; |
| 2186 | } else { |
| 2187 | memset(packet, 0, sizeof(*packet)); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2188 | skb = NULL; |
| 2189 | error = 0; |
| 2190 | len = 0; |
| 2191 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2192 | |
| 2193 | read_again: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2194 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 2195 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame] | 2196 | if (xgbe_rx_dirty_desc(ring) > (XGBE_RX_DESC_CNT >> 3)) |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2197 | xgbe_rx_refresh(channel); |
| 2198 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2199 | if (hw_if->dev_read(channel)) |
| 2200 | break; |
| 2201 | |
| 2202 | received++; |
| 2203 | ring->cur++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2204 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2205 | last = XGMAC_GET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, |
| 2206 | LAST); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2207 | context_next = XGMAC_GET_BITS(packet->attributes, |
| 2208 | RX_PACKET_ATTRIBUTES, |
| 2209 | CONTEXT_NEXT); |
| 2210 | context = XGMAC_GET_BITS(packet->attributes, |
| 2211 | RX_PACKET_ATTRIBUTES, |
| 2212 | CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2213 | |
| 2214 | /* Earlier error, just drain the remaining data */ |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2215 | if ((!last || context_next) && error) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2216 | goto read_again; |
| 2217 | |
| 2218 | if (error || packet->errors) { |
| 2219 | if (packet->errors) |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2220 | netif_err(pdata, rx_err, netdev, |
| 2221 | "error in received packet\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2222 | dev_kfree_skb(skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2223 | goto next_packet; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2224 | } |
| 2225 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2226 | if (!context) { |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2227 | /* Get the data length in the descriptor buffers */ |
| 2228 | buf1_len = xgbe_rx_buf1_len(rdata, packet); |
| 2229 | len += buf1_len; |
| 2230 | buf2_len = xgbe_rx_buf2_len(rdata, packet, len); |
| 2231 | len += buf2_len; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2232 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2233 | if (!skb) { |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2234 | skb = xgbe_create_skb(pdata, napi, rdata, |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2235 | buf1_len); |
| 2236 | if (!skb) { |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 2237 | error = 1; |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2238 | goto skip_data; |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | if (buf2_len) { |
Lendacky, Thomas | cfbfd86 | 2015-07-06 11:57:37 -0500 | [diff] [blame] | 2243 | dma_sync_single_range_for_cpu(pdata->dev, |
| 2244 | rdata->rx.buf.dma_base, |
| 2245 | rdata->rx.buf.dma_off, |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2246 | rdata->rx.buf.dma_len, |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2247 | DMA_FROM_DEVICE); |
| 2248 | |
| 2249 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2250 | rdata->rx.buf.pa.pages, |
| 2251 | rdata->rx.buf.pa.pages_offset, |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2252 | buf2_len, |
Lendacky, Thomas | 7d9ca34 | 2015-05-14 11:44:09 -0500 | [diff] [blame] | 2253 | rdata->rx.buf.dma_len); |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2254 | rdata->rx.buf.pa.pages = NULL; |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2255 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2256 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2257 | |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2258 | skip_data: |
| 2259 | if (!last || context_next) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2260 | goto read_again; |
| 2261 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2262 | if (!skb) |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2263 | goto next_packet; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2264 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2265 | /* Be sure we don't exceed the configured MTU */ |
| 2266 | max_len = netdev->mtu + ETH_HLEN; |
| 2267 | if (!(netdev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
| 2268 | (skb->protocol == htons(ETH_P_8021Q))) |
| 2269 | max_len += VLAN_HLEN; |
| 2270 | |
| 2271 | if (skb->len > max_len) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2272 | netif_err(pdata, rx_err, netdev, |
| 2273 | "packet length exceeds configured MTU\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2274 | dev_kfree_skb(skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2275 | goto next_packet; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2276 | } |
| 2277 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2278 | if (netif_msg_pktdata(pdata)) |
| 2279 | xgbe_print_pkt(netdev, skb, false); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2280 | |
| 2281 | skb_checksum_none_assert(skb); |
| 2282 | if (XGMAC_GET_BITS(packet->attributes, |
| 2283 | RX_PACKET_ATTRIBUTES, CSUM_DONE)) |
| 2284 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2285 | |
| 2286 | if (XGMAC_GET_BITS(packet->attributes, |
| 2287 | RX_PACKET_ATTRIBUTES, VLAN_CTAG)) |
| 2288 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2289 | packet->vlan_ctag); |
| 2290 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2291 | if (XGMAC_GET_BITS(packet->attributes, |
| 2292 | RX_PACKET_ATTRIBUTES, RX_TSTAMP)) { |
| 2293 | u64 nsec; |
| 2294 | |
| 2295 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 2296 | packet->rx_tstamp); |
| 2297 | hwtstamps = skb_hwtstamps(skb); |
| 2298 | hwtstamps->hwtstamp = ns_to_ktime(nsec); |
| 2299 | } |
| 2300 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 2301 | if (XGMAC_GET_BITS(packet->attributes, |
| 2302 | RX_PACKET_ATTRIBUTES, RSS_HASH)) |
| 2303 | skb_set_hash(skb, packet->rss_hash, |
| 2304 | packet->rss_hash_type); |
| 2305 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2306 | skb->dev = netdev; |
| 2307 | skb->protocol = eth_type_trans(skb, netdev); |
| 2308 | skb_record_rx_queue(skb, channel->queue_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2309 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2310 | napi_gro_receive(napi, skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2311 | |
| 2312 | next_packet: |
| 2313 | packet_count++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2314 | } |
| 2315 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2316 | /* Check if we need to save state before leaving */ |
Lendacky, Thomas | 622c36f | 2017-03-15 15:11:23 -0500 | [diff] [blame] | 2317 | if (received && (!last || context_next)) { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2318 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 2319 | rdata->state_saved = 1; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2320 | rdata->state.skb = skb; |
| 2321 | rdata->state.len = len; |
| 2322 | rdata->state.error = error; |
| 2323 | } |
| 2324 | |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2325 | DBGPR("<--xgbe_rx_poll: packet_count = %d\n", packet_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2326 | |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2327 | return packet_count; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2328 | } |
| 2329 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2330 | static int xgbe_one_poll(struct napi_struct *napi, int budget) |
| 2331 | { |
| 2332 | struct xgbe_channel *channel = container_of(napi, struct xgbe_channel, |
| 2333 | napi); |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 2334 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2335 | int processed = 0; |
| 2336 | |
| 2337 | DBGPR("-->xgbe_one_poll: budget=%d\n", budget); |
| 2338 | |
| 2339 | /* Cleanup Tx ring first */ |
| 2340 | xgbe_tx_poll(channel); |
| 2341 | |
| 2342 | /* Process Rx ring next */ |
| 2343 | processed = xgbe_rx_poll(channel, budget); |
| 2344 | |
| 2345 | /* If we processed everything, we are done */ |
Lendacky, Thomas | d7aba64 | 2017-03-09 17:48:23 -0600 | [diff] [blame] | 2346 | if ((processed < budget) && napi_complete_done(napi, processed)) { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2347 | /* Enable Tx and Rx interrupts */ |
Lendacky, Thomas | 4c70dd8 | 2016-11-10 17:10:17 -0600 | [diff] [blame] | 2348 | if (pdata->channel_irq_mode) |
| 2349 | xgbe_enable_rx_tx_int(pdata, channel); |
| 2350 | else |
| 2351 | enable_irq(channel->dma_irq); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | DBGPR("<--xgbe_one_poll: received = %d\n", processed); |
| 2355 | |
| 2356 | return processed; |
| 2357 | } |
| 2358 | |
| 2359 | static int xgbe_all_poll(struct napi_struct *napi, int budget) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2360 | { |
| 2361 | struct xgbe_prv_data *pdata = container_of(napi, struct xgbe_prv_data, |
| 2362 | napi); |
| 2363 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2364 | int ring_budget; |
| 2365 | int processed, last_processed; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2366 | unsigned int i; |
| 2367 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2368 | DBGPR("-->xgbe_all_poll: budget=%d\n", budget); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2369 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2370 | processed = 0; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2371 | ring_budget = budget / pdata->rx_ring_count; |
| 2372 | do { |
| 2373 | last_processed = processed; |
| 2374 | |
| 2375 | channel = pdata->channel; |
| 2376 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 2377 | /* Cleanup Tx ring first */ |
| 2378 | xgbe_tx_poll(channel); |
| 2379 | |
| 2380 | /* Process Rx ring next */ |
| 2381 | if (ring_budget > (budget - processed)) |
| 2382 | ring_budget = budget - processed; |
| 2383 | processed += xgbe_rx_poll(channel, ring_budget); |
| 2384 | } |
| 2385 | } while ((processed < budget) && (processed != last_processed)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2386 | |
| 2387 | /* If we processed everything, we are done */ |
Lendacky, Thomas | d7aba64 | 2017-03-09 17:48:23 -0600 | [diff] [blame] | 2388 | if ((processed < budget) && napi_complete_done(napi, processed)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2389 | /* Enable Tx and Rx interrupts */ |
| 2390 | xgbe_enable_rx_tx_ints(pdata); |
| 2391 | } |
| 2392 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2393 | DBGPR("<--xgbe_all_poll: received = %d\n", processed); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2394 | |
| 2395 | return processed; |
| 2396 | } |
| 2397 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2398 | void xgbe_dump_tx_desc(struct xgbe_prv_data *pdata, struct xgbe_ring *ring, |
| 2399 | unsigned int idx, unsigned int count, unsigned int flag) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2400 | { |
| 2401 | struct xgbe_ring_data *rdata; |
| 2402 | struct xgbe_ring_desc *rdesc; |
| 2403 | |
| 2404 | while (count--) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 2405 | rdata = XGBE_GET_DESC_DATA(ring, idx); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2406 | rdesc = rdata->rdesc; |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2407 | netdev_dbg(pdata->netdev, |
| 2408 | "TX_NORMAL_DESC[%d %s] = %08x:%08x:%08x:%08x\n", idx, |
| 2409 | (flag == 1) ? "QUEUED FOR TX" : "TX BY DEVICE", |
| 2410 | le32_to_cpu(rdesc->desc0), |
| 2411 | le32_to_cpu(rdesc->desc1), |
| 2412 | le32_to_cpu(rdesc->desc2), |
| 2413 | le32_to_cpu(rdesc->desc3)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2414 | idx++; |
| 2415 | } |
| 2416 | } |
| 2417 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2418 | void xgbe_dump_rx_desc(struct xgbe_prv_data *pdata, struct xgbe_ring *ring, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2419 | unsigned int idx) |
| 2420 | { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2421 | struct xgbe_ring_data *rdata; |
| 2422 | struct xgbe_ring_desc *rdesc; |
| 2423 | |
| 2424 | rdata = XGBE_GET_DESC_DATA(ring, idx); |
| 2425 | rdesc = rdata->rdesc; |
| 2426 | netdev_dbg(pdata->netdev, |
| 2427 | "RX_NORMAL_DESC[%d RX BY DEVICE] = %08x:%08x:%08x:%08x\n", |
| 2428 | idx, le32_to_cpu(rdesc->desc0), le32_to_cpu(rdesc->desc1), |
| 2429 | le32_to_cpu(rdesc->desc2), le32_to_cpu(rdesc->desc3)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx) |
| 2433 | { |
| 2434 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 2435 | unsigned char *buf = skb->data; |
| 2436 | unsigned char buffer[128]; |
| 2437 | unsigned int i, j; |
| 2438 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2439 | netdev_dbg(netdev, "\n************** SKB dump ****************\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2440 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2441 | netdev_dbg(netdev, "%s packet of %d bytes\n", |
| 2442 | (tx_rx ? "TX" : "RX"), skb->len); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2443 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2444 | netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest); |
| 2445 | netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source); |
| 2446 | netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2447 | |
| 2448 | for (i = 0, j = 0; i < skb->len;) { |
| 2449 | j += snprintf(buffer + j, sizeof(buffer) - j, "%02hhx", |
| 2450 | buf[i++]); |
| 2451 | |
| 2452 | if ((i % 32) == 0) { |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2453 | netdev_dbg(netdev, " %#06x: %s\n", i - 32, buffer); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2454 | j = 0; |
| 2455 | } else if ((i % 16) == 0) { |
| 2456 | buffer[j++] = ' '; |
| 2457 | buffer[j++] = ' '; |
| 2458 | } else if ((i % 4) == 0) { |
| 2459 | buffer[j++] = ' '; |
| 2460 | } |
| 2461 | } |
| 2462 | if (i % 32) |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2463 | netdev_dbg(netdev, " %#06x: %s\n", i - (i % 32), buffer); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2464 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 2465 | netdev_dbg(netdev, "\n************** SKB dump ****************\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2466 | } |