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 | * |
| 9 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 10 | * |
| 11 | * This file is free software; you may copy, redistribute and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This file is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * This file incorporates work covered by the following copyright and |
| 25 | * permission notice: |
| 26 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 27 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 28 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 29 | * and you. |
| 30 | * |
| 31 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 32 | * under any End User Software License Agreement or Agreement for Licensed |
| 33 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 34 | * granted, free of charge, to any person obtaining a copy of this software |
| 35 | * annotated with this license and the Software, to deal in the Software |
| 36 | * without restriction, including without limitation the rights to use, |
| 37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 38 | * of the Software, and to permit persons to whom the Software is furnished |
| 39 | * to do so, subject to the following conditions: |
| 40 | * |
| 41 | * The above copyright notice and this permission notice shall be included |
| 42 | * in all copies or substantial portions of the Software. |
| 43 | * |
| 44 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 45 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 47 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 48 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 54 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 55 | * |
| 56 | * |
| 57 | * License 2: Modified BSD |
| 58 | * |
| 59 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 60 | * All rights reserved. |
| 61 | * |
| 62 | * Redistribution and use in source and binary forms, with or without |
| 63 | * modification, are permitted provided that the following conditions are met: |
| 64 | * * Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * * Redistributions in binary form must reproduce the above copyright |
| 67 | * notice, this list of conditions and the following disclaimer in the |
| 68 | * documentation and/or other materials provided with the distribution. |
| 69 | * * Neither the name of Advanced Micro Devices, Inc. nor the |
| 70 | * names of its contributors may be used to endorse or promote products |
| 71 | * derived from this software without specific prior written permission. |
| 72 | * |
| 73 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 74 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 75 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 76 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 77 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 78 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 79 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 80 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 81 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 82 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 83 | * |
| 84 | * This file incorporates work covered by the following copyright and |
| 85 | * permission notice: |
| 86 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 87 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 88 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 89 | * and you. |
| 90 | * |
| 91 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 92 | * under any End User Software License Agreement or Agreement for Licensed |
| 93 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 94 | * granted, free of charge, to any person obtaining a copy of this software |
| 95 | * annotated with this license and the Software, to deal in the Software |
| 96 | * without restriction, including without limitation the rights to use, |
| 97 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 98 | * of the Software, and to permit persons to whom the Software is furnished |
| 99 | * to do so, subject to the following conditions: |
| 100 | * |
| 101 | * The above copyright notice and this permission notice shall be included |
| 102 | * in all copies or substantial portions of the Software. |
| 103 | * |
| 104 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 105 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 106 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 107 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 108 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 109 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 110 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 111 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 112 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 113 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 114 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 115 | */ |
| 116 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 117 | #include <linux/platform_device.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 | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 130 | static int xgbe_one_poll(struct napi_struct *, int); |
| 131 | static int xgbe_all_poll(struct napi_struct *, int); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 132 | static void xgbe_set_rx_mode(struct net_device *); |
| 133 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 134 | static int xgbe_alloc_channels(struct xgbe_prv_data *pdata) |
| 135 | { |
| 136 | struct xgbe_channel *channel_mem, *channel; |
| 137 | struct xgbe_ring *tx_ring, *rx_ring; |
| 138 | unsigned int count, i; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 139 | int ret = -ENOMEM; |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 140 | |
| 141 | count = max_t(unsigned int, pdata->tx_ring_count, pdata->rx_ring_count); |
| 142 | |
| 143 | channel_mem = kcalloc(count, sizeof(struct xgbe_channel), GFP_KERNEL); |
| 144 | if (!channel_mem) |
| 145 | goto err_channel; |
| 146 | |
| 147 | tx_ring = kcalloc(pdata->tx_ring_count, sizeof(struct xgbe_ring), |
| 148 | GFP_KERNEL); |
| 149 | if (!tx_ring) |
| 150 | goto err_tx_ring; |
| 151 | |
| 152 | rx_ring = kcalloc(pdata->rx_ring_count, sizeof(struct xgbe_ring), |
| 153 | GFP_KERNEL); |
| 154 | if (!rx_ring) |
| 155 | goto err_rx_ring; |
| 156 | |
| 157 | for (i = 0, channel = channel_mem; i < count; i++, channel++) { |
| 158 | snprintf(channel->name, sizeof(channel->name), "channel-%d", i); |
| 159 | channel->pdata = pdata; |
| 160 | channel->queue_index = i; |
| 161 | channel->dma_regs = pdata->xgmac_regs + DMA_CH_BASE + |
| 162 | (DMA_CH_INC * i); |
| 163 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 164 | if (pdata->per_channel_irq) { |
| 165 | /* Get the DMA interrupt (offset 1) */ |
| 166 | ret = platform_get_irq(pdata->pdev, i + 1); |
| 167 | if (ret < 0) { |
| 168 | netdev_err(pdata->netdev, |
| 169 | "platform_get_irq %u failed\n", |
| 170 | i + 1); |
| 171 | goto err_irq; |
| 172 | } |
| 173 | |
| 174 | channel->dma_irq = ret; |
| 175 | } |
| 176 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 177 | if (i < pdata->tx_ring_count) { |
| 178 | spin_lock_init(&tx_ring->lock); |
| 179 | channel->tx_ring = tx_ring++; |
| 180 | } |
| 181 | |
| 182 | if (i < pdata->rx_ring_count) { |
| 183 | spin_lock_init(&rx_ring->lock); |
| 184 | channel->rx_ring = rx_ring++; |
| 185 | } |
| 186 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 187 | DBGPR(" %s: queue=%u, dma_regs=%p, dma_irq=%d, tx=%p, rx=%p\n", |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 188 | channel->name, channel->queue_index, channel->dma_regs, |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 189 | channel->dma_irq, channel->tx_ring, channel->rx_ring); |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | pdata->channel = channel_mem; |
| 193 | pdata->channel_count = count; |
| 194 | |
| 195 | return 0; |
| 196 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 197 | err_irq: |
| 198 | kfree(rx_ring); |
| 199 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 200 | err_rx_ring: |
| 201 | kfree(tx_ring); |
| 202 | |
| 203 | err_tx_ring: |
| 204 | kfree(channel_mem); |
| 205 | |
| 206 | err_channel: |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 207 | return ret; |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void xgbe_free_channels(struct xgbe_prv_data *pdata) |
| 211 | { |
| 212 | if (!pdata->channel) |
| 213 | return; |
| 214 | |
| 215 | kfree(pdata->channel->rx_ring); |
| 216 | kfree(pdata->channel->tx_ring); |
| 217 | kfree(pdata->channel); |
| 218 | |
| 219 | pdata->channel = NULL; |
| 220 | pdata->channel_count = 0; |
| 221 | } |
| 222 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 223 | static inline unsigned int xgbe_tx_avail_desc(struct xgbe_ring *ring) |
| 224 | { |
| 225 | return (ring->rdesc_count - (ring->cur - ring->dirty)); |
| 226 | } |
| 227 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame^] | 228 | static inline unsigned int xgbe_rx_dirty_desc(struct xgbe_ring *ring) |
| 229 | { |
| 230 | return (ring->cur - ring->dirty); |
| 231 | } |
| 232 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 233 | static int xgbe_maybe_stop_tx_queue(struct xgbe_channel *channel, |
| 234 | struct xgbe_ring *ring, unsigned int count) |
| 235 | { |
| 236 | struct xgbe_prv_data *pdata = channel->pdata; |
| 237 | |
| 238 | if (count > xgbe_tx_avail_desc(ring)) { |
| 239 | DBGPR(" Tx queue stopped, not enough descriptors available\n"); |
| 240 | netif_stop_subqueue(pdata->netdev, channel->queue_index); |
| 241 | ring->tx.queue_stopped = 1; |
| 242 | |
| 243 | /* If we haven't notified the hardware because of xmit_more |
| 244 | * support, tell it now |
| 245 | */ |
| 246 | if (ring->tx.xmit_more) |
| 247 | pdata->hw_if.tx_start_xmit(channel, ring); |
| 248 | |
| 249 | return NETDEV_TX_BUSY; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 255 | static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu) |
| 256 | { |
| 257 | unsigned int rx_buf_size; |
| 258 | |
| 259 | if (mtu > XGMAC_JUMBO_PACKET_MTU) { |
| 260 | netdev_alert(netdev, "MTU exceeds maximum supported value\n"); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | rx_buf_size = mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 265 | rx_buf_size = clamp_val(rx_buf_size, XGBE_RX_MIN_BUF_SIZE, PAGE_SIZE); |
| 266 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 267 | rx_buf_size = (rx_buf_size + XGBE_RX_BUF_ALIGN - 1) & |
| 268 | ~(XGBE_RX_BUF_ALIGN - 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 269 | |
| 270 | return rx_buf_size; |
| 271 | } |
| 272 | |
| 273 | static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 274 | { |
| 275 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 276 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 277 | enum xgbe_int int_id; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 278 | unsigned int i; |
| 279 | |
| 280 | channel = pdata->channel; |
| 281 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 282 | if (channel->tx_ring && channel->rx_ring) |
| 283 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 284 | else if (channel->tx_ring) |
| 285 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 286 | else if (channel->rx_ring) |
| 287 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 288 | else |
| 289 | continue; |
| 290 | |
| 291 | hw_if->enable_int(channel, int_id); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 296 | { |
| 297 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 298 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 299 | enum xgbe_int int_id; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 300 | unsigned int i; |
| 301 | |
| 302 | channel = pdata->channel; |
| 303 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 304 | if (channel->tx_ring && channel->rx_ring) |
| 305 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 306 | else if (channel->tx_ring) |
| 307 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 308 | else if (channel->rx_ring) |
| 309 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 310 | else |
| 311 | continue; |
| 312 | |
| 313 | hw_if->disable_int(channel, int_id); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | static irqreturn_t xgbe_isr(int irq, void *data) |
| 318 | { |
| 319 | struct xgbe_prv_data *pdata = data; |
| 320 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 321 | struct xgbe_channel *channel; |
| 322 | unsigned int dma_isr, dma_ch_isr; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 323 | unsigned int mac_isr, mac_tssr; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 324 | unsigned int i; |
| 325 | |
| 326 | /* The DMA interrupt status register also reports MAC and MTL |
| 327 | * interrupts. So for polling mode, we just need to check for |
| 328 | * this register to be non-zero |
| 329 | */ |
| 330 | dma_isr = XGMAC_IOREAD(pdata, DMA_ISR); |
| 331 | if (!dma_isr) |
| 332 | goto isr_done; |
| 333 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 334 | DBGPR(" DMA_ISR = %08x\n", dma_isr); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 335 | |
| 336 | for (i = 0; i < pdata->channel_count; i++) { |
| 337 | if (!(dma_isr & (1 << i))) |
| 338 | continue; |
| 339 | |
| 340 | channel = pdata->channel + i; |
| 341 | |
| 342 | dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); |
| 343 | DBGPR(" DMA_CH%u_ISR = %08x\n", i, dma_ch_isr); |
| 344 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 345 | /* If we get a TI or RI interrupt that means per channel DMA |
| 346 | * interrupts are not enabled, so we use the private data napi |
| 347 | * structure, not the per channel napi structure |
| 348 | */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 349 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, TI) || |
| 350 | XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RI)) { |
| 351 | if (napi_schedule_prep(&pdata->napi)) { |
| 352 | /* Disable Tx and Rx interrupts */ |
| 353 | xgbe_disable_rx_tx_ints(pdata); |
| 354 | |
| 355 | /* Turn on polling */ |
| 356 | __napi_schedule(&pdata->napi); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /* Restart the device on a Fatal Bus Error */ |
| 361 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, FBE)) |
| 362 | schedule_work(&pdata->restart_work); |
| 363 | |
| 364 | /* Clear all interrupt signals */ |
| 365 | XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr); |
| 366 | } |
| 367 | |
| 368 | if (XGMAC_GET_BITS(dma_isr, DMA_ISR, MACIS)) { |
| 369 | mac_isr = XGMAC_IOREAD(pdata, MAC_ISR); |
| 370 | |
| 371 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCTXIS)) |
| 372 | hw_if->tx_mmc_int(pdata); |
| 373 | |
| 374 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCRXIS)) |
| 375 | hw_if->rx_mmc_int(pdata); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 376 | |
| 377 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, TSIS)) { |
| 378 | mac_tssr = XGMAC_IOREAD(pdata, MAC_TSSR); |
| 379 | |
| 380 | if (XGMAC_GET_BITS(mac_tssr, MAC_TSSR, TXTSC)) { |
| 381 | /* Read Tx Timestamp to clear interrupt */ |
| 382 | pdata->tx_tstamp = |
| 383 | hw_if->get_tx_tstamp(pdata); |
| 384 | schedule_work(&pdata->tx_tstamp_work); |
| 385 | } |
| 386 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | DBGPR(" DMA_ISR = %08x\n", XGMAC_IOREAD(pdata, DMA_ISR)); |
| 390 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 391 | isr_done: |
| 392 | return IRQ_HANDLED; |
| 393 | } |
| 394 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 395 | static irqreturn_t xgbe_dma_isr(int irq, void *data) |
| 396 | { |
| 397 | struct xgbe_channel *channel = data; |
| 398 | |
| 399 | /* Per channel DMA interrupts are enabled, so we use the per |
| 400 | * channel napi structure and not the private data napi structure |
| 401 | */ |
| 402 | if (napi_schedule_prep(&channel->napi)) { |
| 403 | /* Disable Tx and Rx interrupts */ |
Lendacky, Thomas | f9c5c62 | 2014-12-09 14:54:08 -0600 | [diff] [blame] | 404 | disable_irq_nosync(channel->dma_irq); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 405 | |
| 406 | /* Turn on polling */ |
| 407 | __napi_schedule(&channel->napi); |
| 408 | } |
| 409 | |
| 410 | return IRQ_HANDLED; |
| 411 | } |
| 412 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 413 | static enum hrtimer_restart xgbe_tx_timer(struct hrtimer *timer) |
| 414 | { |
| 415 | struct xgbe_channel *channel = container_of(timer, |
| 416 | struct xgbe_channel, |
| 417 | tx_timer); |
| 418 | struct xgbe_ring *ring = channel->tx_ring; |
| 419 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 420 | struct napi_struct *napi; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 421 | unsigned long flags; |
| 422 | |
| 423 | DBGPR("-->xgbe_tx_timer\n"); |
| 424 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 425 | napi = (pdata->per_channel_irq) ? &channel->napi : &pdata->napi; |
| 426 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 427 | spin_lock_irqsave(&ring->lock, flags); |
| 428 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 429 | if (napi_schedule_prep(napi)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 430 | /* Disable Tx and Rx interrupts */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 431 | if (pdata->per_channel_irq) |
| 432 | disable_irq(channel->dma_irq); |
| 433 | else |
| 434 | xgbe_disable_rx_tx_ints(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 435 | |
| 436 | /* Turn on polling */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 437 | __napi_schedule(napi); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | channel->tx_timer_active = 0; |
| 441 | |
| 442 | spin_unlock_irqrestore(&ring->lock, flags); |
| 443 | |
| 444 | DBGPR("<--xgbe_tx_timer\n"); |
| 445 | |
| 446 | return HRTIMER_NORESTART; |
| 447 | } |
| 448 | |
| 449 | static void xgbe_init_tx_timers(struct xgbe_prv_data *pdata) |
| 450 | { |
| 451 | struct xgbe_channel *channel; |
| 452 | unsigned int i; |
| 453 | |
| 454 | DBGPR("-->xgbe_init_tx_timers\n"); |
| 455 | |
| 456 | channel = pdata->channel; |
| 457 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 458 | if (!channel->tx_ring) |
| 459 | break; |
| 460 | |
| 461 | DBGPR(" %s adding tx timer\n", channel->name); |
| 462 | hrtimer_init(&channel->tx_timer, CLOCK_MONOTONIC, |
| 463 | HRTIMER_MODE_REL); |
| 464 | channel->tx_timer.function = xgbe_tx_timer; |
| 465 | } |
| 466 | |
| 467 | DBGPR("<--xgbe_init_tx_timers\n"); |
| 468 | } |
| 469 | |
| 470 | static void xgbe_stop_tx_timers(struct xgbe_prv_data *pdata) |
| 471 | { |
| 472 | struct xgbe_channel *channel; |
| 473 | unsigned int i; |
| 474 | |
| 475 | DBGPR("-->xgbe_stop_tx_timers\n"); |
| 476 | |
| 477 | channel = pdata->channel; |
| 478 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 479 | if (!channel->tx_ring) |
| 480 | break; |
| 481 | |
| 482 | DBGPR(" %s deleting tx timer\n", channel->name); |
| 483 | channel->tx_timer_active = 0; |
| 484 | hrtimer_cancel(&channel->tx_timer); |
| 485 | } |
| 486 | |
| 487 | DBGPR("<--xgbe_stop_tx_timers\n"); |
| 488 | } |
| 489 | |
| 490 | void xgbe_get_all_hw_features(struct xgbe_prv_data *pdata) |
| 491 | { |
| 492 | unsigned int mac_hfr0, mac_hfr1, mac_hfr2; |
| 493 | struct xgbe_hw_features *hw_feat = &pdata->hw_feat; |
| 494 | |
| 495 | DBGPR("-->xgbe_get_all_hw_features\n"); |
| 496 | |
| 497 | mac_hfr0 = XGMAC_IOREAD(pdata, MAC_HWF0R); |
| 498 | mac_hfr1 = XGMAC_IOREAD(pdata, MAC_HWF1R); |
| 499 | mac_hfr2 = XGMAC_IOREAD(pdata, MAC_HWF2R); |
| 500 | |
| 501 | memset(hw_feat, 0, sizeof(*hw_feat)); |
| 502 | |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 503 | hw_feat->version = XGMAC_IOREAD(pdata, MAC_VR); |
| 504 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 505 | /* Hardware feature register 0 */ |
| 506 | hw_feat->gmii = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL); |
| 507 | hw_feat->vlhash = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH); |
| 508 | hw_feat->sma = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL); |
| 509 | hw_feat->rwk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL); |
| 510 | hw_feat->mgk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL); |
| 511 | hw_feat->mmc = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL); |
| 512 | hw_feat->aoe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL); |
| 513 | hw_feat->ts = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL); |
| 514 | hw_feat->eee = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL); |
| 515 | hw_feat->tx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL); |
| 516 | hw_feat->rx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL); |
| 517 | hw_feat->addn_mac = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, |
| 518 | ADDMACADRSEL); |
| 519 | hw_feat->ts_src = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL); |
| 520 | hw_feat->sa_vlan_ins = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS); |
| 521 | |
| 522 | /* Hardware feature register 1 */ |
| 523 | hw_feat->rx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 524 | RXFIFOSIZE); |
| 525 | hw_feat->tx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 526 | TXFIFOSIZE); |
| 527 | hw_feat->dcb = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN); |
| 528 | hw_feat->sph = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN); |
| 529 | hw_feat->tso = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN); |
| 530 | hw_feat->dma_debug = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 531 | hw_feat->tc_cnt = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 532 | hw_feat->hash_table_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 533 | HASHTBLSZ); |
| 534 | hw_feat->l3l4_filter_num = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 535 | L3L4FNUM); |
| 536 | |
| 537 | /* Hardware feature register 2 */ |
| 538 | hw_feat->rx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT); |
| 539 | hw_feat->tx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT); |
| 540 | hw_feat->rx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT); |
| 541 | hw_feat->tx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT); |
| 542 | hw_feat->pps_out_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM); |
| 543 | hw_feat->aux_snap_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, AUXSNAPNUM); |
| 544 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 545 | /* Translate the Hash Table size into actual number */ |
| 546 | switch (hw_feat->hash_table_size) { |
| 547 | case 0: |
| 548 | break; |
| 549 | case 1: |
| 550 | hw_feat->hash_table_size = 64; |
| 551 | break; |
| 552 | case 2: |
| 553 | hw_feat->hash_table_size = 128; |
| 554 | break; |
| 555 | case 3: |
| 556 | hw_feat->hash_table_size = 256; |
| 557 | break; |
| 558 | } |
| 559 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 560 | /* The Queue and Channel counts are zero based so increment them |
| 561 | * to get the actual number |
| 562 | */ |
| 563 | hw_feat->rx_q_cnt++; |
| 564 | hw_feat->tx_q_cnt++; |
| 565 | hw_feat->rx_ch_cnt++; |
| 566 | hw_feat->tx_ch_cnt++; |
| 567 | |
| 568 | DBGPR("<--xgbe_get_all_hw_features\n"); |
| 569 | } |
| 570 | |
| 571 | static void xgbe_napi_enable(struct xgbe_prv_data *pdata, unsigned int add) |
| 572 | { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 573 | struct xgbe_channel *channel; |
| 574 | unsigned int i; |
| 575 | |
| 576 | if (pdata->per_channel_irq) { |
| 577 | channel = pdata->channel; |
| 578 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 579 | if (add) |
| 580 | netif_napi_add(pdata->netdev, &channel->napi, |
| 581 | xgbe_one_poll, NAPI_POLL_WEIGHT); |
| 582 | |
| 583 | napi_enable(&channel->napi); |
| 584 | } |
| 585 | } else { |
| 586 | if (add) |
| 587 | netif_napi_add(pdata->netdev, &pdata->napi, |
| 588 | xgbe_all_poll, NAPI_POLL_WEIGHT); |
| 589 | |
| 590 | napi_enable(&pdata->napi); |
| 591 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 594 | 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] | 595 | { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 596 | struct xgbe_channel *channel; |
| 597 | unsigned int i; |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 598 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 599 | if (pdata->per_channel_irq) { |
| 600 | channel = pdata->channel; |
| 601 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 602 | napi_disable(&channel->napi); |
| 603 | |
| 604 | if (del) |
| 605 | netif_napi_del(&channel->napi); |
| 606 | } |
| 607 | } else { |
| 608 | napi_disable(&pdata->napi); |
| 609 | |
| 610 | if (del) |
| 611 | netif_napi_del(&pdata->napi); |
| 612 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata) |
| 616 | { |
| 617 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 618 | |
| 619 | DBGPR("-->xgbe_init_tx_coalesce\n"); |
| 620 | |
| 621 | pdata->tx_usecs = XGMAC_INIT_DMA_TX_USECS; |
| 622 | pdata->tx_frames = XGMAC_INIT_DMA_TX_FRAMES; |
| 623 | |
| 624 | hw_if->config_tx_coalesce(pdata); |
| 625 | |
| 626 | DBGPR("<--xgbe_init_tx_coalesce\n"); |
| 627 | } |
| 628 | |
| 629 | void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata) |
| 630 | { |
| 631 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 632 | |
| 633 | DBGPR("-->xgbe_init_rx_coalesce\n"); |
| 634 | |
| 635 | pdata->rx_riwt = hw_if->usec_to_riwt(pdata, XGMAC_INIT_DMA_RX_USECS); |
| 636 | pdata->rx_frames = XGMAC_INIT_DMA_RX_FRAMES; |
| 637 | |
| 638 | hw_if->config_rx_coalesce(pdata); |
| 639 | |
| 640 | DBGPR("<--xgbe_init_rx_coalesce\n"); |
| 641 | } |
| 642 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 643 | static void xgbe_free_tx_data(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 644 | { |
| 645 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 646 | struct xgbe_channel *channel; |
| 647 | struct xgbe_ring *ring; |
| 648 | struct xgbe_ring_data *rdata; |
| 649 | unsigned int i, j; |
| 650 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 651 | DBGPR("-->xgbe_free_tx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 652 | |
| 653 | channel = pdata->channel; |
| 654 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 655 | ring = channel->tx_ring; |
| 656 | if (!ring) |
| 657 | break; |
| 658 | |
| 659 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 660 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 661 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 665 | DBGPR("<--xgbe_free_tx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 666 | } |
| 667 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 668 | static void xgbe_free_rx_data(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 669 | { |
| 670 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 671 | struct xgbe_channel *channel; |
| 672 | struct xgbe_ring *ring; |
| 673 | struct xgbe_ring_data *rdata; |
| 674 | unsigned int i, j; |
| 675 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 676 | DBGPR("-->xgbe_free_rx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 677 | |
| 678 | channel = pdata->channel; |
| 679 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 680 | ring = channel->rx_ring; |
| 681 | if (!ring) |
| 682 | break; |
| 683 | |
| 684 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 685 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 686 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 690 | DBGPR("<--xgbe_free_rx_data\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 691 | } |
| 692 | |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 693 | static void xgbe_adjust_link(struct net_device *netdev) |
| 694 | { |
| 695 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 696 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 697 | struct phy_device *phydev = pdata->phydev; |
| 698 | int new_state = 0; |
| 699 | |
Lendacky, Thomas | 1d67d7f6 | 2015-01-16 12:46:24 -0600 | [diff] [blame] | 700 | if (!phydev) |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 701 | return; |
| 702 | |
| 703 | if (phydev->link) { |
| 704 | /* Flow control support */ |
| 705 | if (pdata->pause_autoneg) { |
| 706 | if (phydev->pause || phydev->asym_pause) { |
| 707 | pdata->tx_pause = 1; |
| 708 | pdata->rx_pause = 1; |
| 709 | } else { |
| 710 | pdata->tx_pause = 0; |
| 711 | pdata->rx_pause = 0; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | if (pdata->tx_pause != pdata->phy_tx_pause) { |
| 716 | hw_if->config_tx_flow_control(pdata); |
| 717 | pdata->phy_tx_pause = pdata->tx_pause; |
| 718 | } |
| 719 | |
| 720 | if (pdata->rx_pause != pdata->phy_rx_pause) { |
| 721 | hw_if->config_rx_flow_control(pdata); |
| 722 | pdata->phy_rx_pause = pdata->rx_pause; |
| 723 | } |
| 724 | |
| 725 | /* Speed support */ |
| 726 | if (phydev->speed != pdata->phy_speed) { |
| 727 | new_state = 1; |
| 728 | |
| 729 | switch (phydev->speed) { |
| 730 | case SPEED_10000: |
| 731 | hw_if->set_xgmii_speed(pdata); |
| 732 | break; |
| 733 | |
| 734 | case SPEED_2500: |
| 735 | hw_if->set_gmii_2500_speed(pdata); |
| 736 | break; |
| 737 | |
| 738 | case SPEED_1000: |
| 739 | hw_if->set_gmii_speed(pdata); |
| 740 | break; |
| 741 | } |
| 742 | pdata->phy_speed = phydev->speed; |
| 743 | } |
| 744 | |
| 745 | if (phydev->link != pdata->phy_link) { |
| 746 | new_state = 1; |
| 747 | pdata->phy_link = 1; |
| 748 | } |
| 749 | } else if (pdata->phy_link) { |
| 750 | new_state = 1; |
| 751 | pdata->phy_link = 0; |
| 752 | pdata->phy_speed = SPEED_UNKNOWN; |
| 753 | } |
| 754 | |
| 755 | if (new_state) |
| 756 | phy_print_status(phydev); |
| 757 | } |
| 758 | |
| 759 | static int xgbe_phy_init(struct xgbe_prv_data *pdata) |
| 760 | { |
| 761 | struct net_device *netdev = pdata->netdev; |
| 762 | struct phy_device *phydev = pdata->phydev; |
| 763 | int ret; |
| 764 | |
| 765 | pdata->phy_link = -1; |
| 766 | pdata->phy_speed = SPEED_UNKNOWN; |
| 767 | pdata->phy_tx_pause = pdata->tx_pause; |
| 768 | pdata->phy_rx_pause = pdata->rx_pause; |
| 769 | |
| 770 | ret = phy_connect_direct(netdev, phydev, &xgbe_adjust_link, |
| 771 | pdata->phy_mode); |
| 772 | if (ret) { |
| 773 | netdev_err(netdev, "phy_connect_direct failed\n"); |
| 774 | return ret; |
| 775 | } |
| 776 | |
| 777 | if (!phydev->drv || (phydev->drv->phy_id == 0)) { |
| 778 | netdev_err(netdev, "phy_id not valid\n"); |
| 779 | ret = -ENODEV; |
| 780 | goto err_phy_connect; |
| 781 | } |
| 782 | DBGPR(" phy_connect_direct succeeded for PHY %s, link=%d\n", |
| 783 | dev_name(&phydev->dev), phydev->link); |
| 784 | |
| 785 | return 0; |
| 786 | |
| 787 | err_phy_connect: |
| 788 | phy_disconnect(phydev); |
| 789 | |
| 790 | return ret; |
| 791 | } |
| 792 | |
| 793 | static void xgbe_phy_exit(struct xgbe_prv_data *pdata) |
| 794 | { |
| 795 | if (!pdata->phydev) |
| 796 | return; |
| 797 | |
| 798 | phy_disconnect(pdata->phydev); |
| 799 | } |
| 800 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 801 | int xgbe_powerdown(struct net_device *netdev, unsigned int caller) |
| 802 | { |
| 803 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 804 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 805 | unsigned long flags; |
| 806 | |
| 807 | DBGPR("-->xgbe_powerdown\n"); |
| 808 | |
| 809 | if (!netif_running(netdev) || |
| 810 | (caller == XGMAC_IOCTL_CONTEXT && pdata->power_down)) { |
| 811 | netdev_alert(netdev, "Device is already powered down\n"); |
| 812 | DBGPR("<--xgbe_powerdown\n"); |
| 813 | return -EINVAL; |
| 814 | } |
| 815 | |
| 816 | phy_stop(pdata->phydev); |
| 817 | |
| 818 | spin_lock_irqsave(&pdata->lock, flags); |
| 819 | |
| 820 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 821 | netif_device_detach(netdev); |
| 822 | |
| 823 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 824 | xgbe_napi_disable(pdata, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 825 | |
| 826 | /* Powerdown Tx/Rx */ |
| 827 | hw_if->powerdown_tx(pdata); |
| 828 | hw_if->powerdown_rx(pdata); |
| 829 | |
| 830 | pdata->power_down = 1; |
| 831 | |
| 832 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 833 | |
| 834 | DBGPR("<--xgbe_powerdown\n"); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | int xgbe_powerup(struct net_device *netdev, unsigned int caller) |
| 840 | { |
| 841 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 842 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 843 | unsigned long flags; |
| 844 | |
| 845 | DBGPR("-->xgbe_powerup\n"); |
| 846 | |
| 847 | if (!netif_running(netdev) || |
| 848 | (caller == XGMAC_IOCTL_CONTEXT && !pdata->power_down)) { |
| 849 | netdev_alert(netdev, "Device is already powered up\n"); |
| 850 | DBGPR("<--xgbe_powerup\n"); |
| 851 | return -EINVAL; |
| 852 | } |
| 853 | |
| 854 | spin_lock_irqsave(&pdata->lock, flags); |
| 855 | |
| 856 | pdata->power_down = 0; |
| 857 | |
| 858 | phy_start(pdata->phydev); |
| 859 | |
| 860 | /* Enable Tx/Rx */ |
| 861 | hw_if->powerup_tx(pdata); |
| 862 | hw_if->powerup_rx(pdata); |
| 863 | |
| 864 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 865 | netif_device_attach(netdev); |
| 866 | |
| 867 | xgbe_napi_enable(pdata, 0); |
| 868 | netif_tx_start_all_queues(netdev); |
| 869 | |
| 870 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 871 | |
| 872 | DBGPR("<--xgbe_powerup\n"); |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | static int xgbe_start(struct xgbe_prv_data *pdata) |
| 878 | { |
| 879 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 880 | struct net_device *netdev = pdata->netdev; |
| 881 | |
| 882 | DBGPR("-->xgbe_start\n"); |
| 883 | |
| 884 | xgbe_set_rx_mode(netdev); |
| 885 | |
| 886 | hw_if->init(pdata); |
| 887 | |
| 888 | phy_start(pdata->phydev); |
| 889 | |
| 890 | hw_if->enable_tx(pdata); |
| 891 | hw_if->enable_rx(pdata); |
| 892 | |
| 893 | xgbe_init_tx_timers(pdata); |
| 894 | |
| 895 | xgbe_napi_enable(pdata, 1); |
| 896 | netif_tx_start_all_queues(netdev); |
| 897 | |
| 898 | DBGPR("<--xgbe_start\n"); |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static void xgbe_stop(struct xgbe_prv_data *pdata) |
| 904 | { |
| 905 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 906 | struct xgbe_channel *channel; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 907 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 908 | struct netdev_queue *txq; |
| 909 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 910 | |
| 911 | DBGPR("-->xgbe_stop\n"); |
| 912 | |
| 913 | phy_stop(pdata->phydev); |
| 914 | |
| 915 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 916 | xgbe_napi_disable(pdata, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 917 | |
| 918 | xgbe_stop_tx_timers(pdata); |
| 919 | |
| 920 | hw_if->disable_tx(pdata); |
| 921 | hw_if->disable_rx(pdata); |
| 922 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 923 | channel = pdata->channel; |
| 924 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 925 | if (!channel->tx_ring) |
| 926 | continue; |
| 927 | |
| 928 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
| 929 | netdev_tx_reset_queue(txq); |
| 930 | } |
| 931 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 932 | DBGPR("<--xgbe_stop\n"); |
| 933 | } |
| 934 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 935 | static void xgbe_restart_dev(struct xgbe_prv_data *pdata) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 936 | { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 937 | struct xgbe_channel *channel; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 938 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 939 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 940 | |
| 941 | DBGPR("-->xgbe_restart_dev\n"); |
| 942 | |
| 943 | /* If not running, "restart" will happen on open */ |
| 944 | if (!netif_running(pdata->netdev)) |
| 945 | return; |
| 946 | |
| 947 | xgbe_stop(pdata); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 948 | synchronize_irq(pdata->dev_irq); |
| 949 | if (pdata->per_channel_irq) { |
| 950 | channel = pdata->channel; |
| 951 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 952 | synchronize_irq(channel->dma_irq); |
| 953 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 954 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 955 | xgbe_free_tx_data(pdata); |
| 956 | xgbe_free_rx_data(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 957 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 958 | /* Issue software reset to device */ |
| 959 | hw_if->exit(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 960 | |
| 961 | xgbe_start(pdata); |
| 962 | |
| 963 | DBGPR("<--xgbe_restart_dev\n"); |
| 964 | } |
| 965 | |
| 966 | static void xgbe_restart(struct work_struct *work) |
| 967 | { |
| 968 | struct xgbe_prv_data *pdata = container_of(work, |
| 969 | struct xgbe_prv_data, |
| 970 | restart_work); |
| 971 | |
| 972 | rtnl_lock(); |
| 973 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 974 | xgbe_restart_dev(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 975 | |
| 976 | rtnl_unlock(); |
| 977 | } |
| 978 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 979 | static void xgbe_tx_tstamp(struct work_struct *work) |
| 980 | { |
| 981 | struct xgbe_prv_data *pdata = container_of(work, |
| 982 | struct xgbe_prv_data, |
| 983 | tx_tstamp_work); |
| 984 | struct skb_shared_hwtstamps hwtstamps; |
| 985 | u64 nsec; |
| 986 | unsigned long flags; |
| 987 | |
| 988 | if (pdata->tx_tstamp) { |
| 989 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 990 | pdata->tx_tstamp); |
| 991 | |
| 992 | memset(&hwtstamps, 0, sizeof(hwtstamps)); |
| 993 | hwtstamps.hwtstamp = ns_to_ktime(nsec); |
| 994 | skb_tstamp_tx(pdata->tx_tstamp_skb, &hwtstamps); |
| 995 | } |
| 996 | |
| 997 | dev_kfree_skb_any(pdata->tx_tstamp_skb); |
| 998 | |
| 999 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 1000 | pdata->tx_tstamp_skb = NULL; |
| 1001 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 1002 | } |
| 1003 | |
| 1004 | static int xgbe_get_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 1005 | struct ifreq *ifreq) |
| 1006 | { |
| 1007 | if (copy_to_user(ifreq->ifr_data, &pdata->tstamp_config, |
| 1008 | sizeof(pdata->tstamp_config))) |
| 1009 | return -EFAULT; |
| 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 1015 | struct ifreq *ifreq) |
| 1016 | { |
| 1017 | struct hwtstamp_config config; |
| 1018 | unsigned int mac_tscr; |
| 1019 | |
| 1020 | if (copy_from_user(&config, ifreq->ifr_data, sizeof(config))) |
| 1021 | return -EFAULT; |
| 1022 | |
| 1023 | if (config.flags) |
| 1024 | return -EINVAL; |
| 1025 | |
| 1026 | mac_tscr = 0; |
| 1027 | |
| 1028 | switch (config.tx_type) { |
| 1029 | case HWTSTAMP_TX_OFF: |
| 1030 | break; |
| 1031 | |
| 1032 | case HWTSTAMP_TX_ON: |
| 1033 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1034 | break; |
| 1035 | |
| 1036 | default: |
| 1037 | return -ERANGE; |
| 1038 | } |
| 1039 | |
| 1040 | switch (config.rx_filter) { |
| 1041 | case HWTSTAMP_FILTER_NONE: |
| 1042 | break; |
| 1043 | |
| 1044 | case HWTSTAMP_FILTER_ALL: |
| 1045 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1); |
| 1046 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1047 | break; |
| 1048 | |
| 1049 | /* PTP v2, UDP, any kind of event packet */ |
| 1050 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 1051 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1052 | /* PTP v1, UDP, any kind of event packet */ |
| 1053 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 1054 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1055 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1056 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1057 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1058 | break; |
| 1059 | |
| 1060 | /* PTP v2, UDP, Sync packet */ |
| 1061 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 1062 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1063 | /* PTP v1, UDP, Sync packet */ |
| 1064 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 1065 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1066 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1067 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1068 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1069 | break; |
| 1070 | |
| 1071 | /* PTP v2, UDP, Delay_req packet */ |
| 1072 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 1073 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1074 | /* PTP v1, UDP, Delay_req packet */ |
| 1075 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 1076 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1077 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1078 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1079 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1080 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1081 | break; |
| 1082 | |
| 1083 | /* 802.AS1, Ethernet, any kind of event packet */ |
| 1084 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 1085 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1086 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1087 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1088 | break; |
| 1089 | |
| 1090 | /* 802.AS1, Ethernet, Sync packet */ |
| 1091 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 1092 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1093 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1094 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1095 | break; |
| 1096 | |
| 1097 | /* 802.AS1, Ethernet, Delay_req packet */ |
| 1098 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 1099 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 1100 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1101 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1102 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1103 | break; |
| 1104 | |
| 1105 | /* PTP v2/802.AS1, any layer, any kind of event packet */ |
| 1106 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 1107 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1108 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1109 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1110 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1111 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 1112 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1113 | break; |
| 1114 | |
| 1115 | /* PTP v2/802.AS1, any layer, Sync packet */ |
| 1116 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 1117 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1118 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1119 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1120 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1121 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1122 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1123 | break; |
| 1124 | |
| 1125 | /* PTP v2/802.AS1, any layer, Delay_req packet */ |
| 1126 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 1127 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 1128 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 1129 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 1130 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 1131 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 1132 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 1133 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 1134 | break; |
| 1135 | |
| 1136 | default: |
| 1137 | return -ERANGE; |
| 1138 | } |
| 1139 | |
| 1140 | pdata->hw_if.config_tstamp(pdata, mac_tscr); |
| 1141 | |
| 1142 | memcpy(&pdata->tstamp_config, &config, sizeof(config)); |
| 1143 | |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | static void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata, |
| 1148 | struct sk_buff *skb, |
| 1149 | struct xgbe_packet_data *packet) |
| 1150 | { |
| 1151 | unsigned long flags; |
| 1152 | |
| 1153 | if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) { |
| 1154 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 1155 | if (pdata->tx_tstamp_skb) { |
| 1156 | /* Another timestamp in progress, ignore this one */ |
| 1157 | XGMAC_SET_BITS(packet->attributes, |
| 1158 | TX_PACKET_ATTRIBUTES, PTP, 0); |
| 1159 | } else { |
| 1160 | pdata->tx_tstamp_skb = skb_get(skb); |
| 1161 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 1162 | } |
| 1163 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 1164 | } |
| 1165 | |
| 1166 | if (!XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) |
| 1167 | skb_tx_timestamp(skb); |
| 1168 | } |
| 1169 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1170 | static void xgbe_prep_vlan(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 1171 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1172 | if (skb_vlan_tag_present(skb)) |
| 1173 | packet->vlan_ctag = skb_vlan_tag_get(skb); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | static int xgbe_prep_tso(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 1177 | { |
| 1178 | int ret; |
| 1179 | |
| 1180 | if (!XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1181 | TSO_ENABLE)) |
| 1182 | return 0; |
| 1183 | |
| 1184 | ret = skb_cow_head(skb, 0); |
| 1185 | if (ret) |
| 1186 | return ret; |
| 1187 | |
| 1188 | packet->header_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1189 | packet->tcp_header_len = tcp_hdrlen(skb); |
| 1190 | packet->tcp_payload_len = skb->len - packet->header_len; |
| 1191 | packet->mss = skb_shinfo(skb)->gso_size; |
| 1192 | DBGPR(" packet->header_len=%u\n", packet->header_len); |
| 1193 | DBGPR(" packet->tcp_header_len=%u, packet->tcp_payload_len=%u\n", |
| 1194 | packet->tcp_header_len, packet->tcp_payload_len); |
| 1195 | DBGPR(" packet->mss=%u\n", packet->mss); |
| 1196 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1197 | /* Update the number of packets that will ultimately be transmitted |
| 1198 | * along with the extra bytes for each extra packet |
| 1199 | */ |
| 1200 | packet->tx_packets = skb_shinfo(skb)->gso_segs; |
| 1201 | packet->tx_bytes += (packet->tx_packets - 1) * packet->header_len; |
| 1202 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1203 | return 0; |
| 1204 | } |
| 1205 | |
| 1206 | static int xgbe_is_tso(struct sk_buff *skb) |
| 1207 | { |
| 1208 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1209 | return 0; |
| 1210 | |
| 1211 | if (!skb_is_gso(skb)) |
| 1212 | return 0; |
| 1213 | |
| 1214 | DBGPR(" TSO packet to be processed\n"); |
| 1215 | |
| 1216 | return 1; |
| 1217 | } |
| 1218 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1219 | static void xgbe_packet_info(struct xgbe_prv_data *pdata, |
| 1220 | struct xgbe_ring *ring, struct sk_buff *skb, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1221 | struct xgbe_packet_data *packet) |
| 1222 | { |
| 1223 | struct skb_frag_struct *frag; |
| 1224 | unsigned int context_desc; |
| 1225 | unsigned int len; |
| 1226 | unsigned int i; |
| 1227 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1228 | packet->skb = skb; |
| 1229 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1230 | context_desc = 0; |
| 1231 | packet->rdesc_count = 0; |
| 1232 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1233 | packet->tx_packets = 1; |
| 1234 | packet->tx_bytes = skb->len; |
| 1235 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1236 | if (xgbe_is_tso(skb)) { |
Lendacky, Thomas | a7beaf2 | 2014-11-04 16:07:29 -0600 | [diff] [blame] | 1237 | /* TSO requires an extra descriptor if mss is different */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1238 | if (skb_shinfo(skb)->gso_size != ring->tx.cur_mss) { |
| 1239 | context_desc = 1; |
| 1240 | packet->rdesc_count++; |
| 1241 | } |
| 1242 | |
Lendacky, Thomas | a7beaf2 | 2014-11-04 16:07:29 -0600 | [diff] [blame] | 1243 | /* TSO requires an extra descriptor for TSO header */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1244 | packet->rdesc_count++; |
| 1245 | |
| 1246 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1247 | TSO_ENABLE, 1); |
| 1248 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1249 | CSUM_ENABLE, 1); |
| 1250 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 1251 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1252 | CSUM_ENABLE, 1); |
| 1253 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1254 | if (skb_vlan_tag_present(skb)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1255 | /* VLAN requires an extra descriptor if tag is different */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1256 | if (skb_vlan_tag_get(skb) != ring->tx.cur_vlan_ctag) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1257 | /* We can share with the TSO context descriptor */ |
| 1258 | if (!context_desc) { |
| 1259 | context_desc = 1; |
| 1260 | packet->rdesc_count++; |
| 1261 | } |
| 1262 | |
| 1263 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1264 | VLAN_CTAG, 1); |
| 1265 | } |
| 1266 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1267 | if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 1268 | (pdata->tstamp_config.tx_type == HWTSTAMP_TX_ON)) |
| 1269 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 1270 | PTP, 1); |
| 1271 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1272 | for (len = skb_headlen(skb); len;) { |
| 1273 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1274 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1278 | frag = &skb_shinfo(skb)->frags[i]; |
| 1279 | for (len = skb_frag_size(frag); len; ) { |
| 1280 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1281 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | static int xgbe_open(struct net_device *netdev) |
| 1287 | { |
| 1288 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1289 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1290 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1291 | struct xgbe_channel *channel = NULL; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1292 | unsigned int i = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1293 | int ret; |
| 1294 | |
| 1295 | DBGPR("-->xgbe_open\n"); |
| 1296 | |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1297 | /* Initialize the phy */ |
| 1298 | ret = xgbe_phy_init(pdata); |
| 1299 | if (ret) |
| 1300 | return ret; |
| 1301 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1302 | /* Enable the clocks */ |
| 1303 | ret = clk_prepare_enable(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1304 | if (ret) { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1305 | netdev_alert(netdev, "dma clk_prepare_enable failed\n"); |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1306 | goto err_phy_init; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1307 | } |
| 1308 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1309 | ret = clk_prepare_enable(pdata->ptpclk); |
| 1310 | if (ret) { |
| 1311 | netdev_alert(netdev, "ptp clk_prepare_enable failed\n"); |
| 1312 | goto err_sysclk; |
| 1313 | } |
| 1314 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1315 | /* Calculate the Rx buffer size before allocating rings */ |
| 1316 | ret = xgbe_calc_rx_buf_size(netdev, netdev->mtu); |
| 1317 | if (ret < 0) |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1318 | goto err_ptpclk; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1319 | pdata->rx_buf_size = ret; |
| 1320 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1321 | /* Allocate the channel and ring structures */ |
| 1322 | ret = xgbe_alloc_channels(pdata); |
| 1323 | if (ret) |
| 1324 | goto err_ptpclk; |
| 1325 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1326 | /* Allocate the ring descriptors and buffers */ |
| 1327 | ret = desc_if->alloc_ring_resources(pdata); |
| 1328 | if (ret) |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1329 | goto err_channels; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1330 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1331 | /* Initialize the device restart and Tx timestamp work struct */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1332 | INIT_WORK(&pdata->restart_work, xgbe_restart); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1333 | INIT_WORK(&pdata->tx_tstamp_work, xgbe_tx_tstamp); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1334 | |
| 1335 | /* Request interrupts */ |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1336 | ret = devm_request_irq(pdata->dev, pdata->dev_irq, xgbe_isr, 0, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1337 | netdev->name, pdata); |
| 1338 | if (ret) { |
| 1339 | netdev_alert(netdev, "error requesting irq %d\n", |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1340 | pdata->dev_irq); |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1341 | goto err_rings; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1342 | } |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1343 | |
| 1344 | if (pdata->per_channel_irq) { |
| 1345 | channel = pdata->channel; |
| 1346 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
Lendacky, Thomas | 54ceb9e | 2014-12-02 18:07:18 -0600 | [diff] [blame] | 1347 | snprintf(channel->dma_irq_name, |
| 1348 | sizeof(channel->dma_irq_name) - 1, |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1349 | "%s-TxRx-%u", netdev_name(netdev), |
| 1350 | channel->queue_index); |
| 1351 | |
| 1352 | ret = devm_request_irq(pdata->dev, channel->dma_irq, |
Lendacky, Thomas | 54ceb9e | 2014-12-02 18:07:18 -0600 | [diff] [blame] | 1353 | xgbe_dma_isr, 0, |
| 1354 | channel->dma_irq_name, channel); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1355 | if (ret) { |
| 1356 | netdev_alert(netdev, |
| 1357 | "error requesting irq %d\n", |
| 1358 | channel->dma_irq); |
| 1359 | goto err_irq; |
| 1360 | } |
| 1361 | } |
| 1362 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1363 | |
| 1364 | ret = xgbe_start(pdata); |
| 1365 | if (ret) |
| 1366 | goto err_start; |
| 1367 | |
| 1368 | DBGPR("<--xgbe_open\n"); |
| 1369 | |
| 1370 | return 0; |
| 1371 | |
| 1372 | err_start: |
| 1373 | hw_if->exit(pdata); |
| 1374 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1375 | err_irq: |
| 1376 | if (pdata->per_channel_irq) { |
| 1377 | /* Using an unsigned int, 'i' will go to UINT_MAX and exit */ |
| 1378 | for (i--, channel--; i < pdata->channel_count; i--, channel--) |
| 1379 | devm_free_irq(pdata->dev, channel->dma_irq, channel); |
| 1380 | } |
| 1381 | |
| 1382 | devm_free_irq(pdata->dev, pdata->dev_irq, pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1383 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1384 | err_rings: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1385 | desc_if->free_ring_resources(pdata); |
| 1386 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1387 | err_channels: |
| 1388 | xgbe_free_channels(pdata); |
| 1389 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1390 | err_ptpclk: |
| 1391 | clk_disable_unprepare(pdata->ptpclk); |
| 1392 | |
| 1393 | err_sysclk: |
| 1394 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1395 | |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1396 | err_phy_init: |
| 1397 | xgbe_phy_exit(pdata); |
| 1398 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1399 | return ret; |
| 1400 | } |
| 1401 | |
| 1402 | static int xgbe_close(struct net_device *netdev) |
| 1403 | { |
| 1404 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1405 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1406 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1407 | struct xgbe_channel *channel; |
| 1408 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1409 | |
| 1410 | DBGPR("-->xgbe_close\n"); |
| 1411 | |
| 1412 | /* Stop the device */ |
| 1413 | xgbe_stop(pdata); |
| 1414 | |
| 1415 | /* Issue software reset to device */ |
| 1416 | hw_if->exit(pdata); |
| 1417 | |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 1418 | /* Free the ring descriptors and buffers */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1419 | desc_if->free_ring_resources(pdata); |
| 1420 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1421 | /* Release the interrupts */ |
| 1422 | devm_free_irq(pdata->dev, pdata->dev_irq, pdata); |
| 1423 | if (pdata->per_channel_irq) { |
| 1424 | channel = pdata->channel; |
| 1425 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 1426 | devm_free_irq(pdata->dev, channel->dma_irq, channel); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1427 | } |
| 1428 | |
Lendacky, Thomas | e98c72c | 2014-11-06 17:02:13 -0600 | [diff] [blame] | 1429 | /* Free the channel and ring structures */ |
| 1430 | xgbe_free_channels(pdata); |
| 1431 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1432 | /* Disable the clocks */ |
| 1433 | clk_disable_unprepare(pdata->ptpclk); |
| 1434 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1435 | |
Lendacky, Thomas | 88131a8 | 2014-08-05 13:30:44 -0500 | [diff] [blame] | 1436 | /* Release the phy */ |
| 1437 | xgbe_phy_exit(pdata); |
| 1438 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1439 | DBGPR("<--xgbe_close\n"); |
| 1440 | |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
| 1444 | static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1445 | { |
| 1446 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1447 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1448 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1449 | struct xgbe_channel *channel; |
| 1450 | struct xgbe_ring *ring; |
| 1451 | struct xgbe_packet_data *packet; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1452 | struct netdev_queue *txq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1453 | unsigned long flags; |
| 1454 | int ret; |
| 1455 | |
| 1456 | DBGPR("-->xgbe_xmit: skb->len = %d\n", skb->len); |
| 1457 | |
| 1458 | channel = pdata->channel + skb->queue_mapping; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1459 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1460 | ring = channel->tx_ring; |
| 1461 | packet = &ring->packet_data; |
| 1462 | |
| 1463 | ret = NETDEV_TX_OK; |
| 1464 | |
| 1465 | spin_lock_irqsave(&ring->lock, flags); |
| 1466 | |
| 1467 | if (skb->len == 0) { |
| 1468 | netdev_err(netdev, "empty skb received from stack\n"); |
| 1469 | dev_kfree_skb_any(skb); |
| 1470 | goto tx_netdev_return; |
| 1471 | } |
| 1472 | |
| 1473 | /* Calculate preliminary packet info */ |
| 1474 | memset(packet, 0, sizeof(*packet)); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1475 | xgbe_packet_info(pdata, ring, skb, packet); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1476 | |
| 1477 | /* Check that there are enough descriptors available */ |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1478 | ret = xgbe_maybe_stop_tx_queue(channel, ring, packet->rdesc_count); |
| 1479 | if (ret) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1480 | goto tx_netdev_return; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1481 | |
| 1482 | ret = xgbe_prep_tso(skb, packet); |
| 1483 | if (ret) { |
| 1484 | netdev_err(netdev, "error processing TSO packet\n"); |
| 1485 | dev_kfree_skb_any(skb); |
| 1486 | goto tx_netdev_return; |
| 1487 | } |
| 1488 | xgbe_prep_vlan(skb, packet); |
| 1489 | |
| 1490 | if (!desc_if->map_tx_skb(channel, skb)) { |
| 1491 | dev_kfree_skb_any(skb); |
| 1492 | goto tx_netdev_return; |
| 1493 | } |
| 1494 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1495 | xgbe_prep_tx_tstamp(pdata, skb, packet); |
| 1496 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1497 | /* Report on the actual number of bytes (to be) sent */ |
| 1498 | netdev_tx_sent_queue(txq, packet->tx_bytes); |
| 1499 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1500 | /* Configure required descriptor fields for transmission */ |
Lendacky, Thomas | a9d4198 | 2014-11-04 16:06:32 -0600 | [diff] [blame] | 1501 | hw_if->dev_xmit(channel); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1502 | |
| 1503 | #ifdef XGMAC_ENABLE_TX_PKT_DUMP |
| 1504 | xgbe_print_pkt(netdev, skb, true); |
| 1505 | #endif |
| 1506 | |
Lendacky, Thomas | 16958a2 | 2014-11-20 11:04:08 -0600 | [diff] [blame] | 1507 | /* Stop the queue in advance if there may not be enough descriptors */ |
| 1508 | xgbe_maybe_stop_tx_queue(channel, ring, XGBE_TX_MAX_DESCS); |
| 1509 | |
| 1510 | ret = NETDEV_TX_OK; |
| 1511 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1512 | tx_netdev_return: |
| 1513 | spin_unlock_irqrestore(&ring->lock, flags); |
| 1514 | |
| 1515 | DBGPR("<--xgbe_xmit\n"); |
| 1516 | |
| 1517 | return ret; |
| 1518 | } |
| 1519 | |
| 1520 | static void xgbe_set_rx_mode(struct net_device *netdev) |
| 1521 | { |
| 1522 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1523 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1524 | unsigned int pr_mode, am_mode; |
| 1525 | |
| 1526 | DBGPR("-->xgbe_set_rx_mode\n"); |
| 1527 | |
| 1528 | pr_mode = ((netdev->flags & IFF_PROMISC) != 0); |
| 1529 | am_mode = ((netdev->flags & IFF_ALLMULTI) != 0); |
| 1530 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1531 | hw_if->set_promiscuous_mode(pdata, pr_mode); |
| 1532 | hw_if->set_all_multicast_mode(pdata, am_mode); |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 1533 | |
| 1534 | hw_if->add_mac_addresses(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1535 | |
| 1536 | DBGPR("<--xgbe_set_rx_mode\n"); |
| 1537 | } |
| 1538 | |
| 1539 | static int xgbe_set_mac_address(struct net_device *netdev, void *addr) |
| 1540 | { |
| 1541 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1542 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1543 | struct sockaddr *saddr = addr; |
| 1544 | |
| 1545 | DBGPR("-->xgbe_set_mac_address\n"); |
| 1546 | |
| 1547 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 1548 | return -EADDRNOTAVAIL; |
| 1549 | |
| 1550 | memcpy(netdev->dev_addr, saddr->sa_data, netdev->addr_len); |
| 1551 | |
| 1552 | hw_if->set_mac_address(pdata, netdev->dev_addr); |
| 1553 | |
| 1554 | DBGPR("<--xgbe_set_mac_address\n"); |
| 1555 | |
| 1556 | return 0; |
| 1557 | } |
| 1558 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1559 | static int xgbe_ioctl(struct net_device *netdev, struct ifreq *ifreq, int cmd) |
| 1560 | { |
| 1561 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1562 | int ret; |
| 1563 | |
| 1564 | switch (cmd) { |
| 1565 | case SIOCGHWTSTAMP: |
| 1566 | ret = xgbe_get_hwtstamp_settings(pdata, ifreq); |
| 1567 | break; |
| 1568 | |
| 1569 | case SIOCSHWTSTAMP: |
| 1570 | ret = xgbe_set_hwtstamp_settings(pdata, ifreq); |
| 1571 | break; |
| 1572 | |
| 1573 | default: |
| 1574 | ret = -EOPNOTSUPP; |
| 1575 | } |
| 1576 | |
| 1577 | return ret; |
| 1578 | } |
| 1579 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1580 | static int xgbe_change_mtu(struct net_device *netdev, int mtu) |
| 1581 | { |
| 1582 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1583 | int ret; |
| 1584 | |
| 1585 | DBGPR("-->xgbe_change_mtu\n"); |
| 1586 | |
| 1587 | ret = xgbe_calc_rx_buf_size(netdev, mtu); |
| 1588 | if (ret < 0) |
| 1589 | return ret; |
| 1590 | |
| 1591 | pdata->rx_buf_size = ret; |
| 1592 | netdev->mtu = mtu; |
| 1593 | |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 1594 | xgbe_restart_dev(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1595 | |
| 1596 | DBGPR("<--xgbe_change_mtu\n"); |
| 1597 | |
| 1598 | return 0; |
| 1599 | } |
| 1600 | |
| 1601 | static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev, |
| 1602 | struct rtnl_link_stats64 *s) |
| 1603 | { |
| 1604 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1605 | struct xgbe_mmc_stats *pstats = &pdata->mmc_stats; |
| 1606 | |
| 1607 | DBGPR("-->%s\n", __func__); |
| 1608 | |
| 1609 | pdata->hw_if.read_mmc_stats(pdata); |
| 1610 | |
| 1611 | s->rx_packets = pstats->rxframecount_gb; |
| 1612 | s->rx_bytes = pstats->rxoctetcount_gb; |
| 1613 | s->rx_errors = pstats->rxframecount_gb - |
| 1614 | pstats->rxbroadcastframes_g - |
| 1615 | pstats->rxmulticastframes_g - |
| 1616 | pstats->rxunicastframes_g; |
| 1617 | s->multicast = pstats->rxmulticastframes_g; |
| 1618 | s->rx_length_errors = pstats->rxlengtherror; |
| 1619 | s->rx_crc_errors = pstats->rxcrcerror; |
| 1620 | s->rx_fifo_errors = pstats->rxfifooverflow; |
| 1621 | |
| 1622 | s->tx_packets = pstats->txframecount_gb; |
| 1623 | s->tx_bytes = pstats->txoctetcount_gb; |
| 1624 | s->tx_errors = pstats->txframecount_gb - pstats->txframecount_g; |
| 1625 | s->tx_dropped = netdev->stats.tx_dropped; |
| 1626 | |
| 1627 | DBGPR("<--%s\n", __func__); |
| 1628 | |
| 1629 | return s; |
| 1630 | } |
| 1631 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1632 | static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, |
| 1633 | u16 vid) |
| 1634 | { |
| 1635 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1636 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1637 | |
| 1638 | DBGPR("-->%s\n", __func__); |
| 1639 | |
| 1640 | set_bit(vid, pdata->active_vlans); |
| 1641 | hw_if->update_vlan_hash_table(pdata); |
| 1642 | |
| 1643 | DBGPR("<--%s\n", __func__); |
| 1644 | |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, |
| 1649 | u16 vid) |
| 1650 | { |
| 1651 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1652 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1653 | |
| 1654 | DBGPR("-->%s\n", __func__); |
| 1655 | |
| 1656 | clear_bit(vid, pdata->active_vlans); |
| 1657 | hw_if->update_vlan_hash_table(pdata); |
| 1658 | |
| 1659 | DBGPR("<--%s\n", __func__); |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1664 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1665 | static void xgbe_poll_controller(struct net_device *netdev) |
| 1666 | { |
| 1667 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1668 | struct xgbe_channel *channel; |
| 1669 | unsigned int i; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1670 | |
| 1671 | DBGPR("-->xgbe_poll_controller\n"); |
| 1672 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1673 | if (pdata->per_channel_irq) { |
| 1674 | channel = pdata->channel; |
| 1675 | for (i = 0; i < pdata->channel_count; i++, channel++) |
| 1676 | xgbe_dma_isr(channel->dma_irq, channel); |
| 1677 | } else { |
| 1678 | disable_irq(pdata->dev_irq); |
| 1679 | xgbe_isr(pdata->dev_irq, pdata); |
| 1680 | enable_irq(pdata->dev_irq); |
| 1681 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1682 | |
| 1683 | DBGPR("<--xgbe_poll_controller\n"); |
| 1684 | } |
| 1685 | #endif /* End CONFIG_NET_POLL_CONTROLLER */ |
| 1686 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1687 | static int xgbe_setup_tc(struct net_device *netdev, u8 tc) |
| 1688 | { |
| 1689 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1690 | unsigned int offset, queue; |
| 1691 | u8 i; |
| 1692 | |
| 1693 | if (tc && (tc != pdata->hw_feat.tc_cnt)) |
| 1694 | return -EINVAL; |
| 1695 | |
| 1696 | if (tc) { |
| 1697 | netdev_set_num_tc(netdev, tc); |
| 1698 | for (i = 0, queue = 0, offset = 0; i < tc; i++) { |
| 1699 | while ((queue < pdata->tx_q_count) && |
| 1700 | (pdata->q2tc_map[queue] == i)) |
| 1701 | queue++; |
| 1702 | |
| 1703 | DBGPR(" TC%u using TXq%u-%u\n", i, offset, queue - 1); |
| 1704 | netdev_set_tc_queue(netdev, i, queue - offset, offset); |
| 1705 | offset = queue; |
| 1706 | } |
| 1707 | } else { |
| 1708 | netdev_reset_tc(netdev); |
| 1709 | } |
| 1710 | |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1714 | static int xgbe_set_features(struct net_device *netdev, |
| 1715 | netdev_features_t features) |
| 1716 | { |
| 1717 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1718 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1719 | netdev_features_t rxhash, rxcsum, rxvlan, rxvlan_filter; |
| 1720 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1721 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1722 | rxhash = pdata->netdev_features & NETIF_F_RXHASH; |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1723 | rxcsum = pdata->netdev_features & NETIF_F_RXCSUM; |
| 1724 | rxvlan = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_RX; |
| 1725 | rxvlan_filter = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_FILTER; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1726 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 1727 | if ((features & NETIF_F_RXHASH) && !rxhash) |
| 1728 | ret = hw_if->enable_rss(pdata); |
| 1729 | else if (!(features & NETIF_F_RXHASH) && rxhash) |
| 1730 | ret = hw_if->disable_rss(pdata); |
| 1731 | if (ret) |
| 1732 | return ret; |
| 1733 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1734 | if ((features & NETIF_F_RXCSUM) && !rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1735 | hw_if->enable_rx_csum(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1736 | else if (!(features & NETIF_F_RXCSUM) && rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1737 | hw_if->disable_rx_csum(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1738 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1739 | if ((features & NETIF_F_HW_VLAN_CTAG_RX) && !rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1740 | hw_if->enable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1741 | else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) && rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1742 | hw_if->disable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1743 | |
| 1744 | if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && !rxvlan_filter) |
| 1745 | hw_if->enable_rx_vlan_filtering(pdata); |
| 1746 | else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && rxvlan_filter) |
| 1747 | hw_if->disable_rx_vlan_filtering(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1748 | |
| 1749 | pdata->netdev_features = features; |
| 1750 | |
| 1751 | DBGPR("<--xgbe_set_features\n"); |
| 1752 | |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | static const struct net_device_ops xgbe_netdev_ops = { |
| 1757 | .ndo_open = xgbe_open, |
| 1758 | .ndo_stop = xgbe_close, |
| 1759 | .ndo_start_xmit = xgbe_xmit, |
| 1760 | .ndo_set_rx_mode = xgbe_set_rx_mode, |
| 1761 | .ndo_set_mac_address = xgbe_set_mac_address, |
| 1762 | .ndo_validate_addr = eth_validate_addr, |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1763 | .ndo_do_ioctl = xgbe_ioctl, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1764 | .ndo_change_mtu = xgbe_change_mtu, |
| 1765 | .ndo_get_stats64 = xgbe_get_stats64, |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1766 | .ndo_vlan_rx_add_vid = xgbe_vlan_rx_add_vid, |
| 1767 | .ndo_vlan_rx_kill_vid = xgbe_vlan_rx_kill_vid, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1768 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1769 | .ndo_poll_controller = xgbe_poll_controller, |
| 1770 | #endif |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 1771 | .ndo_setup_tc = xgbe_setup_tc, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1772 | .ndo_set_features = xgbe_set_features, |
| 1773 | }; |
| 1774 | |
| 1775 | struct net_device_ops *xgbe_get_netdev_ops(void) |
| 1776 | { |
| 1777 | return (struct net_device_ops *)&xgbe_netdev_ops; |
| 1778 | } |
| 1779 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1780 | static void xgbe_rx_refresh(struct xgbe_channel *channel) |
| 1781 | { |
| 1782 | struct xgbe_prv_data *pdata = channel->pdata; |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame^] | 1783 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1784 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1785 | struct xgbe_ring *ring = channel->rx_ring; |
| 1786 | struct xgbe_ring_data *rdata; |
| 1787 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame^] | 1788 | while (ring->dirty != ring->cur) { |
| 1789 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty); |
| 1790 | |
| 1791 | /* Reset rdata values */ |
| 1792 | desc_if->unmap_rdata(pdata, rdata); |
| 1793 | |
| 1794 | if (desc_if->map_rx_buffer(pdata, ring, rdata)) |
| 1795 | break; |
| 1796 | |
| 1797 | hw_if->rx_desc_reset(rdata); |
| 1798 | |
| 1799 | ring->dirty++; |
| 1800 | } |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1801 | |
| 1802 | /* Update the Rx Tail Pointer Register with address of |
| 1803 | * the last cleaned entry */ |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame^] | 1804 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty - 1); |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1805 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO, |
| 1806 | lower_32_bits(rdata->rdesc_dma)); |
| 1807 | } |
| 1808 | |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1809 | static struct sk_buff *xgbe_create_skb(struct xgbe_prv_data *pdata, |
| 1810 | struct xgbe_ring_data *rdata, |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1811 | unsigned int *len) |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1812 | { |
| 1813 | struct net_device *netdev = pdata->netdev; |
| 1814 | struct sk_buff *skb; |
| 1815 | u8 *packet; |
| 1816 | unsigned int copy_len; |
| 1817 | |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1818 | skb = netdev_alloc_skb_ip_align(netdev, rdata->rx.hdr.dma_len); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1819 | if (!skb) |
| 1820 | return NULL; |
| 1821 | |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1822 | packet = page_address(rdata->rx.hdr.pa.pages) + |
| 1823 | rdata->rx.hdr.pa.pages_offset; |
| 1824 | copy_len = (rdata->rx.hdr_len) ? rdata->rx.hdr_len : *len; |
| 1825 | copy_len = min(rdata->rx.hdr.dma_len, copy_len); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1826 | skb_copy_to_linear_data(skb, packet, copy_len); |
| 1827 | skb_put(skb, copy_len); |
| 1828 | |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1829 | *len -= copy_len; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1830 | |
| 1831 | return skb; |
| 1832 | } |
| 1833 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1834 | static int xgbe_tx_poll(struct xgbe_channel *channel) |
| 1835 | { |
| 1836 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1837 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1838 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1839 | struct xgbe_ring *ring = channel->tx_ring; |
| 1840 | struct xgbe_ring_data *rdata; |
| 1841 | struct xgbe_ring_desc *rdesc; |
| 1842 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1843 | struct netdev_queue *txq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1844 | unsigned long flags; |
| 1845 | int processed = 0; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1846 | unsigned int tx_packets = 0, tx_bytes = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1847 | |
| 1848 | DBGPR("-->xgbe_tx_poll\n"); |
| 1849 | |
| 1850 | /* Nothing to do if there isn't a Tx ring for this channel */ |
| 1851 | if (!ring) |
| 1852 | return 0; |
| 1853 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1854 | txq = netdev_get_tx_queue(netdev, channel->queue_index); |
| 1855 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1856 | spin_lock_irqsave(&ring->lock, flags); |
| 1857 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1858 | while ((processed < XGBE_TX_DESC_MAX_PROC) && |
Lendacky, Thomas | 244d62b | 2014-12-04 11:52:35 -0600 | [diff] [blame] | 1859 | (ring->dirty != ring->cur)) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1860 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1861 | rdesc = rdata->rdesc; |
| 1862 | |
| 1863 | if (!hw_if->tx_complete(rdesc)) |
| 1864 | break; |
| 1865 | |
Lendacky, Thomas | 5449e27 | 2014-11-20 11:03:26 -0600 | [diff] [blame] | 1866 | /* Make sure descriptor fields are read after reading the OWN |
| 1867 | * bit */ |
| 1868 | rmb(); |
| 1869 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1870 | #ifdef XGMAC_ENABLE_TX_DESC_DUMP |
| 1871 | xgbe_dump_tx_desc(ring, ring->dirty, 1, 0); |
| 1872 | #endif |
| 1873 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1874 | if (hw_if->is_last_desc(rdesc)) { |
| 1875 | tx_packets += rdata->tx.packets; |
| 1876 | tx_bytes += rdata->tx.bytes; |
| 1877 | } |
| 1878 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1879 | /* Free the SKB and reset the descriptor for re-use */ |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1880 | desc_if->unmap_rdata(pdata, rdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1881 | hw_if->tx_desc_reset(rdata); |
| 1882 | |
| 1883 | processed++; |
| 1884 | ring->dirty++; |
| 1885 | } |
| 1886 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1887 | if (!processed) |
| 1888 | goto unlock; |
| 1889 | |
| 1890 | netdev_tx_completed_queue(txq, tx_packets, tx_bytes); |
| 1891 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1892 | if ((ring->tx.queue_stopped == 1) && |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1893 | (xgbe_tx_avail_desc(ring) > XGBE_TX_DESC_MIN_FREE)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1894 | ring->tx.queue_stopped = 0; |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1895 | netif_tx_wake_queue(txq); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | DBGPR("<--xgbe_tx_poll: processed=%d\n", processed); |
| 1899 | |
Lendacky, Thomas | 5fb4b86 | 2014-11-20 11:03:50 -0600 | [diff] [blame] | 1900 | unlock: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1901 | spin_unlock_irqrestore(&ring->lock, flags); |
| 1902 | |
| 1903 | return processed; |
| 1904 | } |
| 1905 | |
| 1906 | static int xgbe_rx_poll(struct xgbe_channel *channel, int budget) |
| 1907 | { |
| 1908 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1909 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1910 | struct xgbe_ring *ring = channel->rx_ring; |
| 1911 | struct xgbe_ring_data *rdata; |
| 1912 | struct xgbe_packet_data *packet; |
| 1913 | struct net_device *netdev = pdata->netdev; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1914 | struct napi_struct *napi; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1915 | struct sk_buff *skb; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1916 | struct skb_shared_hwtstamps *hwtstamps; |
| 1917 | unsigned int incomplete, error, context_next, context; |
| 1918 | unsigned int len, put_len, max_len; |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 1919 | unsigned int received = 0; |
| 1920 | int packet_count = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1921 | |
| 1922 | DBGPR("-->xgbe_rx_poll: budget=%d\n", budget); |
| 1923 | |
| 1924 | /* Nothing to do if there isn't a Rx ring for this channel */ |
| 1925 | if (!ring) |
| 1926 | return 0; |
| 1927 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 1928 | napi = (pdata->per_channel_irq) ? &channel->napi : &pdata->napi; |
| 1929 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1930 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1931 | packet = &ring->packet_data; |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 1932 | while (packet_count < budget) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1933 | DBGPR(" cur = %d\n", ring->cur); |
| 1934 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1935 | /* First time in loop see if we need to restore state */ |
| 1936 | if (!received && rdata->state_saved) { |
| 1937 | incomplete = rdata->state.incomplete; |
| 1938 | context_next = rdata->state.context_next; |
| 1939 | skb = rdata->state.skb; |
| 1940 | error = rdata->state.error; |
| 1941 | len = rdata->state.len; |
| 1942 | } else { |
| 1943 | memset(packet, 0, sizeof(*packet)); |
| 1944 | incomplete = 0; |
| 1945 | context_next = 0; |
| 1946 | skb = NULL; |
| 1947 | error = 0; |
| 1948 | len = 0; |
| 1949 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1950 | |
| 1951 | read_again: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1952 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 1953 | |
Lendacky, Thomas | 270894e | 2015-01-16 12:46:50 -0600 | [diff] [blame^] | 1954 | if (xgbe_rx_dirty_desc(ring) > (XGBE_RX_DESC_CNT >> 3)) |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1955 | xgbe_rx_refresh(channel); |
| 1956 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1957 | if (hw_if->dev_read(channel)) |
| 1958 | break; |
| 1959 | |
| 1960 | received++; |
| 1961 | ring->cur++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1962 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1963 | incomplete = XGMAC_GET_BITS(packet->attributes, |
| 1964 | RX_PACKET_ATTRIBUTES, |
| 1965 | INCOMPLETE); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1966 | context_next = XGMAC_GET_BITS(packet->attributes, |
| 1967 | RX_PACKET_ATTRIBUTES, |
| 1968 | CONTEXT_NEXT); |
| 1969 | context = XGMAC_GET_BITS(packet->attributes, |
| 1970 | RX_PACKET_ATTRIBUTES, |
| 1971 | CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1972 | |
| 1973 | /* Earlier error, just drain the remaining data */ |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1974 | if ((incomplete || context_next) && error) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1975 | goto read_again; |
| 1976 | |
| 1977 | if (error || packet->errors) { |
| 1978 | if (packet->errors) |
| 1979 | DBGPR("Error in received packet\n"); |
| 1980 | dev_kfree_skb(skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 1981 | goto next_packet; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1982 | } |
| 1983 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1984 | if (!context) { |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1985 | put_len = rdata->rx.len - len; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 1986 | len += put_len; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1987 | |
| 1988 | if (!skb) { |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1989 | dma_sync_single_for_cpu(pdata->dev, |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 1990 | rdata->rx.hdr.dma, |
| 1991 | rdata->rx.hdr.dma_len, |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 1992 | DMA_FROM_DEVICE); |
| 1993 | |
| 1994 | skb = xgbe_create_skb(pdata, rdata, &put_len); |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1995 | if (!skb) { |
| 1996 | error = 1; |
Lendacky, Thomas | f5eecbb | 2014-11-06 17:02:19 -0600 | [diff] [blame] | 1997 | goto skip_data; |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1998 | } |
Lendacky, Thomas | 08dcc47 | 2014-11-04 16:06:44 -0600 | [diff] [blame] | 1999 | } |
| 2000 | |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2001 | if (put_len) { |
| 2002 | dma_sync_single_for_cpu(pdata->dev, |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2003 | rdata->rx.buf.dma, |
| 2004 | rdata->rx.buf.dma_len, |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2005 | DMA_FROM_DEVICE); |
| 2006 | |
| 2007 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, |
Lendacky, Thomas | c9f140e | 2014-11-20 11:03:44 -0600 | [diff] [blame] | 2008 | rdata->rx.buf.pa.pages, |
| 2009 | rdata->rx.buf.pa.pages_offset, |
| 2010 | put_len, rdata->rx.buf.dma_len); |
| 2011 | rdata->rx.buf.pa.pages = NULL; |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2012 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2013 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2014 | |
Lendacky, Thomas | f5eecbb | 2014-11-06 17:02:19 -0600 | [diff] [blame] | 2015 | skip_data: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2016 | if (incomplete || context_next) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2017 | goto read_again; |
| 2018 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2019 | if (!skb) |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2020 | goto next_packet; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2021 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2022 | /* Be sure we don't exceed the configured MTU */ |
| 2023 | max_len = netdev->mtu + ETH_HLEN; |
| 2024 | if (!(netdev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
| 2025 | (skb->protocol == htons(ETH_P_8021Q))) |
| 2026 | max_len += VLAN_HLEN; |
| 2027 | |
| 2028 | if (skb->len > max_len) { |
| 2029 | DBGPR("packet length exceeds configured MTU\n"); |
| 2030 | dev_kfree_skb(skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2031 | goto next_packet; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | #ifdef XGMAC_ENABLE_RX_PKT_DUMP |
| 2035 | xgbe_print_pkt(netdev, skb, false); |
| 2036 | #endif |
| 2037 | |
| 2038 | skb_checksum_none_assert(skb); |
| 2039 | if (XGMAC_GET_BITS(packet->attributes, |
| 2040 | RX_PACKET_ATTRIBUTES, CSUM_DONE)) |
| 2041 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2042 | |
| 2043 | if (XGMAC_GET_BITS(packet->attributes, |
| 2044 | RX_PACKET_ATTRIBUTES, VLAN_CTAG)) |
| 2045 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2046 | packet->vlan_ctag); |
| 2047 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2048 | if (XGMAC_GET_BITS(packet->attributes, |
| 2049 | RX_PACKET_ATTRIBUTES, RX_TSTAMP)) { |
| 2050 | u64 nsec; |
| 2051 | |
| 2052 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 2053 | packet->rx_tstamp); |
| 2054 | hwtstamps = skb_hwtstamps(skb); |
| 2055 | hwtstamps->hwtstamp = ns_to_ktime(nsec); |
| 2056 | } |
| 2057 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 2058 | if (XGMAC_GET_BITS(packet->attributes, |
| 2059 | RX_PACKET_ATTRIBUTES, RSS_HASH)) |
| 2060 | skb_set_hash(skb, packet->rss_hash, |
| 2061 | packet->rss_hash_type); |
| 2062 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2063 | skb->dev = netdev; |
| 2064 | skb->protocol = eth_type_trans(skb, netdev); |
| 2065 | skb_record_rx_queue(skb, channel->queue_index); |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2066 | skb_mark_napi_id(skb, napi); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2067 | |
| 2068 | netdev->last_rx = jiffies; |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2069 | napi_gro_receive(napi, skb); |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2070 | |
| 2071 | next_packet: |
| 2072 | packet_count++; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2073 | } |
| 2074 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 2075 | /* Check if we need to save state before leaving */ |
| 2076 | if (received && (incomplete || context_next)) { |
| 2077 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 2078 | rdata->state_saved = 1; |
| 2079 | rdata->state.incomplete = incomplete; |
| 2080 | rdata->state.context_next = context_next; |
| 2081 | rdata->state.skb = skb; |
| 2082 | rdata->state.len = len; |
| 2083 | rdata->state.error = error; |
| 2084 | } |
| 2085 | |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2086 | DBGPR("<--xgbe_rx_poll: packet_count = %d\n", packet_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2087 | |
Lendacky, Thomas | 55ca6bc | 2014-10-22 11:26:17 -0500 | [diff] [blame] | 2088 | return packet_count; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2089 | } |
| 2090 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2091 | static int xgbe_one_poll(struct napi_struct *napi, int budget) |
| 2092 | { |
| 2093 | struct xgbe_channel *channel = container_of(napi, struct xgbe_channel, |
| 2094 | napi); |
| 2095 | int processed = 0; |
| 2096 | |
| 2097 | DBGPR("-->xgbe_one_poll: budget=%d\n", budget); |
| 2098 | |
| 2099 | /* Cleanup Tx ring first */ |
| 2100 | xgbe_tx_poll(channel); |
| 2101 | |
| 2102 | /* Process Rx ring next */ |
| 2103 | processed = xgbe_rx_poll(channel, budget); |
| 2104 | |
| 2105 | /* If we processed everything, we are done */ |
| 2106 | if (processed < budget) { |
| 2107 | /* Turn off polling */ |
| 2108 | napi_complete(napi); |
| 2109 | |
| 2110 | /* Enable Tx and Rx interrupts */ |
| 2111 | enable_irq(channel->dma_irq); |
| 2112 | } |
| 2113 | |
| 2114 | DBGPR("<--xgbe_one_poll: received = %d\n", processed); |
| 2115 | |
| 2116 | return processed; |
| 2117 | } |
| 2118 | |
| 2119 | static int xgbe_all_poll(struct napi_struct *napi, int budget) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2120 | { |
| 2121 | struct xgbe_prv_data *pdata = container_of(napi, struct xgbe_prv_data, |
| 2122 | napi); |
| 2123 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2124 | int ring_budget; |
| 2125 | int processed, last_processed; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2126 | unsigned int i; |
| 2127 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2128 | DBGPR("-->xgbe_all_poll: budget=%d\n", budget); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2129 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2130 | processed = 0; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 2131 | ring_budget = budget / pdata->rx_ring_count; |
| 2132 | do { |
| 2133 | last_processed = processed; |
| 2134 | |
| 2135 | channel = pdata->channel; |
| 2136 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 2137 | /* Cleanup Tx ring first */ |
| 2138 | xgbe_tx_poll(channel); |
| 2139 | |
| 2140 | /* Process Rx ring next */ |
| 2141 | if (ring_budget > (budget - processed)) |
| 2142 | ring_budget = budget - processed; |
| 2143 | processed += xgbe_rx_poll(channel, ring_budget); |
| 2144 | } |
| 2145 | } while ((processed < budget) && (processed != last_processed)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2146 | |
| 2147 | /* If we processed everything, we are done */ |
| 2148 | if (processed < budget) { |
| 2149 | /* Turn off polling */ |
| 2150 | napi_complete(napi); |
| 2151 | |
| 2152 | /* Enable Tx and Rx interrupts */ |
| 2153 | xgbe_enable_rx_tx_ints(pdata); |
| 2154 | } |
| 2155 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 2156 | DBGPR("<--xgbe_all_poll: received = %d\n", processed); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2157 | |
| 2158 | return processed; |
| 2159 | } |
| 2160 | |
| 2161 | void xgbe_dump_tx_desc(struct xgbe_ring *ring, unsigned int idx, |
| 2162 | unsigned int count, unsigned int flag) |
| 2163 | { |
| 2164 | struct xgbe_ring_data *rdata; |
| 2165 | struct xgbe_ring_desc *rdesc; |
| 2166 | |
| 2167 | while (count--) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 2168 | rdata = XGBE_GET_DESC_DATA(ring, idx); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2169 | rdesc = rdata->rdesc; |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2170 | pr_alert("TX_NORMAL_DESC[%d %s] = %08x:%08x:%08x:%08x\n", idx, |
| 2171 | (flag == 1) ? "QUEUED FOR TX" : "TX BY DEVICE", |
| 2172 | le32_to_cpu(rdesc->desc0), le32_to_cpu(rdesc->desc1), |
| 2173 | le32_to_cpu(rdesc->desc2), le32_to_cpu(rdesc->desc3)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2174 | idx++; |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | void xgbe_dump_rx_desc(struct xgbe_ring *ring, struct xgbe_ring_desc *desc, |
| 2179 | unsigned int idx) |
| 2180 | { |
Lendacky, Thomas | 174fd25 | 2014-11-04 16:06:50 -0600 | [diff] [blame] | 2181 | pr_alert("RX_NORMAL_DESC[%d RX BY DEVICE] = %08x:%08x:%08x:%08x\n", idx, |
| 2182 | le32_to_cpu(desc->desc0), le32_to_cpu(desc->desc1), |
| 2183 | le32_to_cpu(desc->desc2), le32_to_cpu(desc->desc3)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx) |
| 2187 | { |
| 2188 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 2189 | unsigned char *buf = skb->data; |
| 2190 | unsigned char buffer[128]; |
| 2191 | unsigned int i, j; |
| 2192 | |
| 2193 | netdev_alert(netdev, "\n************** SKB dump ****************\n"); |
| 2194 | |
| 2195 | netdev_alert(netdev, "%s packet of %d bytes\n", |
| 2196 | (tx_rx ? "TX" : "RX"), skb->len); |
| 2197 | |
| 2198 | netdev_alert(netdev, "Dst MAC addr: %pM\n", eth->h_dest); |
| 2199 | netdev_alert(netdev, "Src MAC addr: %pM\n", eth->h_source); |
| 2200 | netdev_alert(netdev, "Protocol: 0x%04hx\n", ntohs(eth->h_proto)); |
| 2201 | |
| 2202 | for (i = 0, j = 0; i < skb->len;) { |
| 2203 | j += snprintf(buffer + j, sizeof(buffer) - j, "%02hhx", |
| 2204 | buf[i++]); |
| 2205 | |
| 2206 | if ((i % 32) == 0) { |
| 2207 | netdev_alert(netdev, " 0x%04x: %s\n", i - 32, buffer); |
| 2208 | j = 0; |
| 2209 | } else if ((i % 16) == 0) { |
| 2210 | buffer[j++] = ' '; |
| 2211 | buffer[j++] = ' '; |
| 2212 | } else if ((i % 4) == 0) { |
| 2213 | buffer[j++] = ' '; |
| 2214 | } |
| 2215 | } |
| 2216 | if (i % 32) |
| 2217 | netdev_alert(netdev, " 0x%04x: %s\n", i - (i % 32), buffer); |
| 2218 | |
| 2219 | netdev_alert(netdev, "\n************** SKB dump ****************\n"); |
| 2220 | } |