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