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 | |
| 117 | #include <linux/spinlock.h> |
| 118 | #include <linux/tcp.h> |
| 119 | #include <linux/if_vlan.h> |
| 120 | #include <linux/phy.h> |
| 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 | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 125 | |
| 126 | #include "xgbe.h" |
| 127 | #include "xgbe-common.h" |
| 128 | |
| 129 | |
| 130 | static int xgbe_poll(struct napi_struct *, int); |
| 131 | static void xgbe_set_rx_mode(struct net_device *); |
| 132 | |
| 133 | static inline unsigned int xgbe_tx_avail_desc(struct xgbe_ring *ring) |
| 134 | { |
| 135 | return (ring->rdesc_count - (ring->cur - ring->dirty)); |
| 136 | } |
| 137 | |
| 138 | static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu) |
| 139 | { |
| 140 | unsigned int rx_buf_size; |
| 141 | |
| 142 | if (mtu > XGMAC_JUMBO_PACKET_MTU) { |
| 143 | netdev_alert(netdev, "MTU exceeds maximum supported value\n"); |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
| 147 | rx_buf_size = mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 148 | if (rx_buf_size < XGBE_RX_MIN_BUF_SIZE) |
| 149 | rx_buf_size = XGBE_RX_MIN_BUF_SIZE; |
| 150 | rx_buf_size = (rx_buf_size + XGBE_RX_BUF_ALIGN - 1) & |
| 151 | ~(XGBE_RX_BUF_ALIGN - 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 152 | |
| 153 | return rx_buf_size; |
| 154 | } |
| 155 | |
| 156 | static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 157 | { |
| 158 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 159 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 160 | enum xgbe_int int_id; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 161 | unsigned int i; |
| 162 | |
| 163 | channel = pdata->channel; |
| 164 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 165 | if (channel->tx_ring && channel->rx_ring) |
| 166 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 167 | else if (channel->tx_ring) |
| 168 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 169 | else if (channel->rx_ring) |
| 170 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 171 | else |
| 172 | continue; |
| 173 | |
| 174 | hw_if->enable_int(channel, int_id); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata) |
| 179 | { |
| 180 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 181 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 182 | enum xgbe_int int_id; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 183 | unsigned int i; |
| 184 | |
| 185 | channel = pdata->channel; |
| 186 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 187 | if (channel->tx_ring && channel->rx_ring) |
| 188 | int_id = XGMAC_INT_DMA_CH_SR_TI_RI; |
| 189 | else if (channel->tx_ring) |
| 190 | int_id = XGMAC_INT_DMA_CH_SR_TI; |
| 191 | else if (channel->rx_ring) |
| 192 | int_id = XGMAC_INT_DMA_CH_SR_RI; |
| 193 | else |
| 194 | continue; |
| 195 | |
| 196 | hw_if->disable_int(channel, int_id); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
| 200 | static irqreturn_t xgbe_isr(int irq, void *data) |
| 201 | { |
| 202 | struct xgbe_prv_data *pdata = data; |
| 203 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 204 | struct xgbe_channel *channel; |
| 205 | unsigned int dma_isr, dma_ch_isr; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 206 | unsigned int mac_isr, mac_tssr; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 207 | unsigned int i; |
| 208 | |
| 209 | /* The DMA interrupt status register also reports MAC and MTL |
| 210 | * interrupts. So for polling mode, we just need to check for |
| 211 | * this register to be non-zero |
| 212 | */ |
| 213 | dma_isr = XGMAC_IOREAD(pdata, DMA_ISR); |
| 214 | if (!dma_isr) |
| 215 | goto isr_done; |
| 216 | |
| 217 | DBGPR("-->xgbe_isr\n"); |
| 218 | |
| 219 | DBGPR(" DMA_ISR = %08x\n", dma_isr); |
| 220 | DBGPR(" DMA_DS0 = %08x\n", XGMAC_IOREAD(pdata, DMA_DSR0)); |
| 221 | DBGPR(" DMA_DS1 = %08x\n", XGMAC_IOREAD(pdata, DMA_DSR1)); |
| 222 | |
| 223 | for (i = 0; i < pdata->channel_count; i++) { |
| 224 | if (!(dma_isr & (1 << i))) |
| 225 | continue; |
| 226 | |
| 227 | channel = pdata->channel + i; |
| 228 | |
| 229 | dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); |
| 230 | DBGPR(" DMA_CH%u_ISR = %08x\n", i, dma_ch_isr); |
| 231 | |
| 232 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, TI) || |
| 233 | XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RI)) { |
| 234 | if (napi_schedule_prep(&pdata->napi)) { |
| 235 | /* Disable Tx and Rx interrupts */ |
| 236 | xgbe_disable_rx_tx_ints(pdata); |
| 237 | |
| 238 | /* Turn on polling */ |
| 239 | __napi_schedule(&pdata->napi); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /* Restart the device on a Fatal Bus Error */ |
| 244 | if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, FBE)) |
| 245 | schedule_work(&pdata->restart_work); |
| 246 | |
| 247 | /* Clear all interrupt signals */ |
| 248 | XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr); |
| 249 | } |
| 250 | |
| 251 | if (XGMAC_GET_BITS(dma_isr, DMA_ISR, MACIS)) { |
| 252 | mac_isr = XGMAC_IOREAD(pdata, MAC_ISR); |
| 253 | |
| 254 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCTXIS)) |
| 255 | hw_if->tx_mmc_int(pdata); |
| 256 | |
| 257 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCRXIS)) |
| 258 | hw_if->rx_mmc_int(pdata); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 259 | |
| 260 | if (XGMAC_GET_BITS(mac_isr, MAC_ISR, TSIS)) { |
| 261 | mac_tssr = XGMAC_IOREAD(pdata, MAC_TSSR); |
| 262 | |
| 263 | if (XGMAC_GET_BITS(mac_tssr, MAC_TSSR, TXTSC)) { |
| 264 | /* Read Tx Timestamp to clear interrupt */ |
| 265 | pdata->tx_tstamp = |
| 266 | hw_if->get_tx_tstamp(pdata); |
| 267 | schedule_work(&pdata->tx_tstamp_work); |
| 268 | } |
| 269 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | DBGPR(" DMA_ISR = %08x\n", XGMAC_IOREAD(pdata, DMA_ISR)); |
| 273 | |
| 274 | DBGPR("<--xgbe_isr\n"); |
| 275 | |
| 276 | isr_done: |
| 277 | return IRQ_HANDLED; |
| 278 | } |
| 279 | |
| 280 | static enum hrtimer_restart xgbe_tx_timer(struct hrtimer *timer) |
| 281 | { |
| 282 | struct xgbe_channel *channel = container_of(timer, |
| 283 | struct xgbe_channel, |
| 284 | tx_timer); |
| 285 | struct xgbe_ring *ring = channel->tx_ring; |
| 286 | struct xgbe_prv_data *pdata = channel->pdata; |
| 287 | unsigned long flags; |
| 288 | |
| 289 | DBGPR("-->xgbe_tx_timer\n"); |
| 290 | |
| 291 | spin_lock_irqsave(&ring->lock, flags); |
| 292 | |
| 293 | if (napi_schedule_prep(&pdata->napi)) { |
| 294 | /* Disable Tx and Rx interrupts */ |
| 295 | xgbe_disable_rx_tx_ints(pdata); |
| 296 | |
| 297 | /* Turn on polling */ |
| 298 | __napi_schedule(&pdata->napi); |
| 299 | } |
| 300 | |
| 301 | channel->tx_timer_active = 0; |
| 302 | |
| 303 | spin_unlock_irqrestore(&ring->lock, flags); |
| 304 | |
| 305 | DBGPR("<--xgbe_tx_timer\n"); |
| 306 | |
| 307 | return HRTIMER_NORESTART; |
| 308 | } |
| 309 | |
| 310 | static void xgbe_init_tx_timers(struct xgbe_prv_data *pdata) |
| 311 | { |
| 312 | struct xgbe_channel *channel; |
| 313 | unsigned int i; |
| 314 | |
| 315 | DBGPR("-->xgbe_init_tx_timers\n"); |
| 316 | |
| 317 | channel = pdata->channel; |
| 318 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 319 | if (!channel->tx_ring) |
| 320 | break; |
| 321 | |
| 322 | DBGPR(" %s adding tx timer\n", channel->name); |
| 323 | hrtimer_init(&channel->tx_timer, CLOCK_MONOTONIC, |
| 324 | HRTIMER_MODE_REL); |
| 325 | channel->tx_timer.function = xgbe_tx_timer; |
| 326 | } |
| 327 | |
| 328 | DBGPR("<--xgbe_init_tx_timers\n"); |
| 329 | } |
| 330 | |
| 331 | static void xgbe_stop_tx_timers(struct xgbe_prv_data *pdata) |
| 332 | { |
| 333 | struct xgbe_channel *channel; |
| 334 | unsigned int i; |
| 335 | |
| 336 | DBGPR("-->xgbe_stop_tx_timers\n"); |
| 337 | |
| 338 | channel = pdata->channel; |
| 339 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 340 | if (!channel->tx_ring) |
| 341 | break; |
| 342 | |
| 343 | DBGPR(" %s deleting tx timer\n", channel->name); |
| 344 | channel->tx_timer_active = 0; |
| 345 | hrtimer_cancel(&channel->tx_timer); |
| 346 | } |
| 347 | |
| 348 | DBGPR("<--xgbe_stop_tx_timers\n"); |
| 349 | } |
| 350 | |
| 351 | void xgbe_get_all_hw_features(struct xgbe_prv_data *pdata) |
| 352 | { |
| 353 | unsigned int mac_hfr0, mac_hfr1, mac_hfr2; |
| 354 | struct xgbe_hw_features *hw_feat = &pdata->hw_feat; |
| 355 | |
| 356 | DBGPR("-->xgbe_get_all_hw_features\n"); |
| 357 | |
| 358 | mac_hfr0 = XGMAC_IOREAD(pdata, MAC_HWF0R); |
| 359 | mac_hfr1 = XGMAC_IOREAD(pdata, MAC_HWF1R); |
| 360 | mac_hfr2 = XGMAC_IOREAD(pdata, MAC_HWF2R); |
| 361 | |
| 362 | memset(hw_feat, 0, sizeof(*hw_feat)); |
| 363 | |
| 364 | /* Hardware feature register 0 */ |
| 365 | hw_feat->gmii = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL); |
| 366 | hw_feat->vlhash = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH); |
| 367 | hw_feat->sma = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL); |
| 368 | hw_feat->rwk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL); |
| 369 | hw_feat->mgk = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL); |
| 370 | hw_feat->mmc = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL); |
| 371 | hw_feat->aoe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL); |
| 372 | hw_feat->ts = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL); |
| 373 | hw_feat->eee = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL); |
| 374 | hw_feat->tx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL); |
| 375 | hw_feat->rx_coe = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL); |
| 376 | hw_feat->addn_mac = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, |
| 377 | ADDMACADRSEL); |
| 378 | hw_feat->ts_src = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL); |
| 379 | hw_feat->sa_vlan_ins = XGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS); |
| 380 | |
| 381 | /* Hardware feature register 1 */ |
| 382 | hw_feat->rx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 383 | RXFIFOSIZE); |
| 384 | hw_feat->tx_fifo_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 385 | TXFIFOSIZE); |
| 386 | hw_feat->dcb = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN); |
| 387 | hw_feat->sph = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN); |
| 388 | hw_feat->tso = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN); |
| 389 | hw_feat->dma_debug = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA); |
| 390 | hw_feat->hash_table_size = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 391 | HASHTBLSZ); |
| 392 | hw_feat->l3l4_filter_num = XGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, |
| 393 | L3L4FNUM); |
| 394 | |
| 395 | /* Hardware feature register 2 */ |
| 396 | hw_feat->rx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT); |
| 397 | hw_feat->tx_q_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT); |
| 398 | hw_feat->rx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT); |
| 399 | hw_feat->tx_ch_cnt = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT); |
| 400 | hw_feat->pps_out_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM); |
| 401 | hw_feat->aux_snap_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, AUXSNAPNUM); |
| 402 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 403 | /* Translate the Hash Table size into actual number */ |
| 404 | switch (hw_feat->hash_table_size) { |
| 405 | case 0: |
| 406 | break; |
| 407 | case 1: |
| 408 | hw_feat->hash_table_size = 64; |
| 409 | break; |
| 410 | case 2: |
| 411 | hw_feat->hash_table_size = 128; |
| 412 | break; |
| 413 | case 3: |
| 414 | hw_feat->hash_table_size = 256; |
| 415 | break; |
| 416 | } |
| 417 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 418 | /* The Queue and Channel counts are zero based so increment them |
| 419 | * to get the actual number |
| 420 | */ |
| 421 | hw_feat->rx_q_cnt++; |
| 422 | hw_feat->tx_q_cnt++; |
| 423 | hw_feat->rx_ch_cnt++; |
| 424 | hw_feat->tx_ch_cnt++; |
| 425 | |
| 426 | DBGPR("<--xgbe_get_all_hw_features\n"); |
| 427 | } |
| 428 | |
| 429 | static void xgbe_napi_enable(struct xgbe_prv_data *pdata, unsigned int add) |
| 430 | { |
| 431 | if (add) |
| 432 | netif_napi_add(pdata->netdev, &pdata->napi, xgbe_poll, |
| 433 | NAPI_POLL_WEIGHT); |
| 434 | napi_enable(&pdata->napi); |
| 435 | } |
| 436 | |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 437 | 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] | 438 | { |
| 439 | napi_disable(&pdata->napi); |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 440 | |
| 441 | if (del) |
| 442 | netif_napi_del(&pdata->napi); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata) |
| 446 | { |
| 447 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 448 | |
| 449 | DBGPR("-->xgbe_init_tx_coalesce\n"); |
| 450 | |
| 451 | pdata->tx_usecs = XGMAC_INIT_DMA_TX_USECS; |
| 452 | pdata->tx_frames = XGMAC_INIT_DMA_TX_FRAMES; |
| 453 | |
| 454 | hw_if->config_tx_coalesce(pdata); |
| 455 | |
| 456 | DBGPR("<--xgbe_init_tx_coalesce\n"); |
| 457 | } |
| 458 | |
| 459 | void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata) |
| 460 | { |
| 461 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 462 | |
| 463 | DBGPR("-->xgbe_init_rx_coalesce\n"); |
| 464 | |
| 465 | pdata->rx_riwt = hw_if->usec_to_riwt(pdata, XGMAC_INIT_DMA_RX_USECS); |
| 466 | pdata->rx_frames = XGMAC_INIT_DMA_RX_FRAMES; |
| 467 | |
| 468 | hw_if->config_rx_coalesce(pdata); |
| 469 | |
| 470 | DBGPR("<--xgbe_init_rx_coalesce\n"); |
| 471 | } |
| 472 | |
| 473 | static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata) |
| 474 | { |
| 475 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 476 | struct xgbe_channel *channel; |
| 477 | struct xgbe_ring *ring; |
| 478 | struct xgbe_ring_data *rdata; |
| 479 | unsigned int i, j; |
| 480 | |
| 481 | DBGPR("-->xgbe_free_tx_skbuff\n"); |
| 482 | |
| 483 | channel = pdata->channel; |
| 484 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 485 | ring = channel->tx_ring; |
| 486 | if (!ring) |
| 487 | break; |
| 488 | |
| 489 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 490 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 491 | desc_if->unmap_skb(pdata, rdata); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | DBGPR("<--xgbe_free_tx_skbuff\n"); |
| 496 | } |
| 497 | |
| 498 | static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata) |
| 499 | { |
| 500 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 501 | struct xgbe_channel *channel; |
| 502 | struct xgbe_ring *ring; |
| 503 | struct xgbe_ring_data *rdata; |
| 504 | unsigned int i, j; |
| 505 | |
| 506 | DBGPR("-->xgbe_free_rx_skbuff\n"); |
| 507 | |
| 508 | channel = pdata->channel; |
| 509 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 510 | ring = channel->rx_ring; |
| 511 | if (!ring) |
| 512 | break; |
| 513 | |
| 514 | for (j = 0; j < ring->rdesc_count; j++) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 515 | rdata = XGBE_GET_DESC_DATA(ring, j); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 516 | desc_if->unmap_skb(pdata, rdata); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | DBGPR("<--xgbe_free_rx_skbuff\n"); |
| 521 | } |
| 522 | |
| 523 | int xgbe_powerdown(struct net_device *netdev, unsigned int caller) |
| 524 | { |
| 525 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 526 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 527 | unsigned long flags; |
| 528 | |
| 529 | DBGPR("-->xgbe_powerdown\n"); |
| 530 | |
| 531 | if (!netif_running(netdev) || |
| 532 | (caller == XGMAC_IOCTL_CONTEXT && pdata->power_down)) { |
| 533 | netdev_alert(netdev, "Device is already powered down\n"); |
| 534 | DBGPR("<--xgbe_powerdown\n"); |
| 535 | return -EINVAL; |
| 536 | } |
| 537 | |
| 538 | phy_stop(pdata->phydev); |
| 539 | |
| 540 | spin_lock_irqsave(&pdata->lock, flags); |
| 541 | |
| 542 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 543 | netif_device_detach(netdev); |
| 544 | |
| 545 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 546 | xgbe_napi_disable(pdata, 0); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 547 | |
| 548 | /* Powerdown Tx/Rx */ |
| 549 | hw_if->powerdown_tx(pdata); |
| 550 | hw_if->powerdown_rx(pdata); |
| 551 | |
| 552 | pdata->power_down = 1; |
| 553 | |
| 554 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 555 | |
| 556 | DBGPR("<--xgbe_powerdown\n"); |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | int xgbe_powerup(struct net_device *netdev, unsigned int caller) |
| 562 | { |
| 563 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 564 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 565 | unsigned long flags; |
| 566 | |
| 567 | DBGPR("-->xgbe_powerup\n"); |
| 568 | |
| 569 | if (!netif_running(netdev) || |
| 570 | (caller == XGMAC_IOCTL_CONTEXT && !pdata->power_down)) { |
| 571 | netdev_alert(netdev, "Device is already powered up\n"); |
| 572 | DBGPR("<--xgbe_powerup\n"); |
| 573 | return -EINVAL; |
| 574 | } |
| 575 | |
| 576 | spin_lock_irqsave(&pdata->lock, flags); |
| 577 | |
| 578 | pdata->power_down = 0; |
| 579 | |
| 580 | phy_start(pdata->phydev); |
| 581 | |
| 582 | /* Enable Tx/Rx */ |
| 583 | hw_if->powerup_tx(pdata); |
| 584 | hw_if->powerup_rx(pdata); |
| 585 | |
| 586 | if (caller == XGMAC_DRIVER_CONTEXT) |
| 587 | netif_device_attach(netdev); |
| 588 | |
| 589 | xgbe_napi_enable(pdata, 0); |
| 590 | netif_tx_start_all_queues(netdev); |
| 591 | |
| 592 | spin_unlock_irqrestore(&pdata->lock, flags); |
| 593 | |
| 594 | DBGPR("<--xgbe_powerup\n"); |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static int xgbe_start(struct xgbe_prv_data *pdata) |
| 600 | { |
| 601 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 602 | struct net_device *netdev = pdata->netdev; |
| 603 | |
| 604 | DBGPR("-->xgbe_start\n"); |
| 605 | |
| 606 | xgbe_set_rx_mode(netdev); |
| 607 | |
| 608 | hw_if->init(pdata); |
| 609 | |
| 610 | phy_start(pdata->phydev); |
| 611 | |
| 612 | hw_if->enable_tx(pdata); |
| 613 | hw_if->enable_rx(pdata); |
| 614 | |
| 615 | xgbe_init_tx_timers(pdata); |
| 616 | |
| 617 | xgbe_napi_enable(pdata, 1); |
| 618 | netif_tx_start_all_queues(netdev); |
| 619 | |
| 620 | DBGPR("<--xgbe_start\n"); |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static void xgbe_stop(struct xgbe_prv_data *pdata) |
| 626 | { |
| 627 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 628 | struct net_device *netdev = pdata->netdev; |
| 629 | |
| 630 | DBGPR("-->xgbe_stop\n"); |
| 631 | |
| 632 | phy_stop(pdata->phydev); |
| 633 | |
| 634 | netif_tx_stop_all_queues(netdev); |
Lendacky, Thomas | ff42606 | 2014-07-02 13:04:40 -0500 | [diff] [blame] | 635 | xgbe_napi_disable(pdata, 1); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 636 | |
| 637 | xgbe_stop_tx_timers(pdata); |
| 638 | |
| 639 | hw_if->disable_tx(pdata); |
| 640 | hw_if->disable_rx(pdata); |
| 641 | |
| 642 | DBGPR("<--xgbe_stop\n"); |
| 643 | } |
| 644 | |
| 645 | static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset) |
| 646 | { |
| 647 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 648 | |
| 649 | DBGPR("-->xgbe_restart_dev\n"); |
| 650 | |
| 651 | /* If not running, "restart" will happen on open */ |
| 652 | if (!netif_running(pdata->netdev)) |
| 653 | return; |
| 654 | |
| 655 | xgbe_stop(pdata); |
| 656 | synchronize_irq(pdata->irq_number); |
| 657 | |
| 658 | xgbe_free_tx_skbuff(pdata); |
| 659 | xgbe_free_rx_skbuff(pdata); |
| 660 | |
| 661 | /* Issue software reset to device if requested */ |
| 662 | if (reset) |
| 663 | hw_if->exit(pdata); |
| 664 | |
| 665 | xgbe_start(pdata); |
| 666 | |
| 667 | DBGPR("<--xgbe_restart_dev\n"); |
| 668 | } |
| 669 | |
| 670 | static void xgbe_restart(struct work_struct *work) |
| 671 | { |
| 672 | struct xgbe_prv_data *pdata = container_of(work, |
| 673 | struct xgbe_prv_data, |
| 674 | restart_work); |
| 675 | |
| 676 | rtnl_lock(); |
| 677 | |
| 678 | xgbe_restart_dev(pdata, 1); |
| 679 | |
| 680 | rtnl_unlock(); |
| 681 | } |
| 682 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 683 | static void xgbe_tx_tstamp(struct work_struct *work) |
| 684 | { |
| 685 | struct xgbe_prv_data *pdata = container_of(work, |
| 686 | struct xgbe_prv_data, |
| 687 | tx_tstamp_work); |
| 688 | struct skb_shared_hwtstamps hwtstamps; |
| 689 | u64 nsec; |
| 690 | unsigned long flags; |
| 691 | |
| 692 | if (pdata->tx_tstamp) { |
| 693 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 694 | pdata->tx_tstamp); |
| 695 | |
| 696 | memset(&hwtstamps, 0, sizeof(hwtstamps)); |
| 697 | hwtstamps.hwtstamp = ns_to_ktime(nsec); |
| 698 | skb_tstamp_tx(pdata->tx_tstamp_skb, &hwtstamps); |
| 699 | } |
| 700 | |
| 701 | dev_kfree_skb_any(pdata->tx_tstamp_skb); |
| 702 | |
| 703 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 704 | pdata->tx_tstamp_skb = NULL; |
| 705 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 706 | } |
| 707 | |
| 708 | static int xgbe_get_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 709 | struct ifreq *ifreq) |
| 710 | { |
| 711 | if (copy_to_user(ifreq->ifr_data, &pdata->tstamp_config, |
| 712 | sizeof(pdata->tstamp_config))) |
| 713 | return -EFAULT; |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata, |
| 719 | struct ifreq *ifreq) |
| 720 | { |
| 721 | struct hwtstamp_config config; |
| 722 | unsigned int mac_tscr; |
| 723 | |
| 724 | if (copy_from_user(&config, ifreq->ifr_data, sizeof(config))) |
| 725 | return -EFAULT; |
| 726 | |
| 727 | if (config.flags) |
| 728 | return -EINVAL; |
| 729 | |
| 730 | mac_tscr = 0; |
| 731 | |
| 732 | switch (config.tx_type) { |
| 733 | case HWTSTAMP_TX_OFF: |
| 734 | break; |
| 735 | |
| 736 | case HWTSTAMP_TX_ON: |
| 737 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 738 | break; |
| 739 | |
| 740 | default: |
| 741 | return -ERANGE; |
| 742 | } |
| 743 | |
| 744 | switch (config.rx_filter) { |
| 745 | case HWTSTAMP_FILTER_NONE: |
| 746 | break; |
| 747 | |
| 748 | case HWTSTAMP_FILTER_ALL: |
| 749 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1); |
| 750 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 751 | break; |
| 752 | |
| 753 | /* PTP v2, UDP, any kind of event packet */ |
| 754 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 755 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 756 | /* PTP v1, UDP, any kind of event packet */ |
| 757 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 758 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 759 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 760 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 761 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 762 | break; |
| 763 | |
| 764 | /* PTP v2, UDP, Sync packet */ |
| 765 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 766 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 767 | /* PTP v1, UDP, Sync packet */ |
| 768 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 769 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 770 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 771 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 772 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 773 | break; |
| 774 | |
| 775 | /* PTP v2, UDP, Delay_req packet */ |
| 776 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 777 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 778 | /* PTP v1, UDP, Delay_req packet */ |
| 779 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 780 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 781 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 782 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 783 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 784 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 785 | break; |
| 786 | |
| 787 | /* 802.AS1, Ethernet, any kind of event packet */ |
| 788 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 789 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 790 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 791 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 792 | break; |
| 793 | |
| 794 | /* 802.AS1, Ethernet, Sync packet */ |
| 795 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 796 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 797 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 798 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 799 | break; |
| 800 | |
| 801 | /* 802.AS1, Ethernet, Delay_req packet */ |
| 802 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 803 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, AV8021ASMEN, 1); |
| 804 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 805 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 806 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 807 | break; |
| 808 | |
| 809 | /* PTP v2/802.AS1, any layer, any kind of event packet */ |
| 810 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 811 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 812 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 813 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 814 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 815 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, SNAPTYPSEL, 1); |
| 816 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 817 | break; |
| 818 | |
| 819 | /* PTP v2/802.AS1, any layer, Sync packet */ |
| 820 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 821 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 822 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 823 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 824 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 825 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 826 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 827 | break; |
| 828 | |
| 829 | /* PTP v2/802.AS1, any layer, Delay_req packet */ |
| 830 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 831 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); |
| 832 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); |
| 833 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1); |
| 834 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1); |
| 835 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSMSTRENA, 1); |
| 836 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSEVNTENA, 1); |
| 837 | XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); |
| 838 | break; |
| 839 | |
| 840 | default: |
| 841 | return -ERANGE; |
| 842 | } |
| 843 | |
| 844 | pdata->hw_if.config_tstamp(pdata, mac_tscr); |
| 845 | |
| 846 | memcpy(&pdata->tstamp_config, &config, sizeof(config)); |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata, |
| 852 | struct sk_buff *skb, |
| 853 | struct xgbe_packet_data *packet) |
| 854 | { |
| 855 | unsigned long flags; |
| 856 | |
| 857 | if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) { |
| 858 | spin_lock_irqsave(&pdata->tstamp_lock, flags); |
| 859 | if (pdata->tx_tstamp_skb) { |
| 860 | /* Another timestamp in progress, ignore this one */ |
| 861 | XGMAC_SET_BITS(packet->attributes, |
| 862 | TX_PACKET_ATTRIBUTES, PTP, 0); |
| 863 | } else { |
| 864 | pdata->tx_tstamp_skb = skb_get(skb); |
| 865 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 866 | } |
| 867 | spin_unlock_irqrestore(&pdata->tstamp_lock, flags); |
| 868 | } |
| 869 | |
| 870 | if (!XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP)) |
| 871 | skb_tx_timestamp(skb); |
| 872 | } |
| 873 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 874 | static void xgbe_prep_vlan(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 875 | { |
| 876 | if (vlan_tx_tag_present(skb)) |
| 877 | packet->vlan_ctag = vlan_tx_tag_get(skb); |
| 878 | } |
| 879 | |
| 880 | static int xgbe_prep_tso(struct sk_buff *skb, struct xgbe_packet_data *packet) |
| 881 | { |
| 882 | int ret; |
| 883 | |
| 884 | if (!XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 885 | TSO_ENABLE)) |
| 886 | return 0; |
| 887 | |
| 888 | ret = skb_cow_head(skb, 0); |
| 889 | if (ret) |
| 890 | return ret; |
| 891 | |
| 892 | packet->header_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 893 | packet->tcp_header_len = tcp_hdrlen(skb); |
| 894 | packet->tcp_payload_len = skb->len - packet->header_len; |
| 895 | packet->mss = skb_shinfo(skb)->gso_size; |
| 896 | DBGPR(" packet->header_len=%u\n", packet->header_len); |
| 897 | DBGPR(" packet->tcp_header_len=%u, packet->tcp_payload_len=%u\n", |
| 898 | packet->tcp_header_len, packet->tcp_payload_len); |
| 899 | DBGPR(" packet->mss=%u\n", packet->mss); |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int xgbe_is_tso(struct sk_buff *skb) |
| 905 | { |
| 906 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 907 | return 0; |
| 908 | |
| 909 | if (!skb_is_gso(skb)) |
| 910 | return 0; |
| 911 | |
| 912 | DBGPR(" TSO packet to be processed\n"); |
| 913 | |
| 914 | return 1; |
| 915 | } |
| 916 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 917 | static void xgbe_packet_info(struct xgbe_prv_data *pdata, |
| 918 | struct xgbe_ring *ring, struct sk_buff *skb, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 919 | struct xgbe_packet_data *packet) |
| 920 | { |
| 921 | struct skb_frag_struct *frag; |
| 922 | unsigned int context_desc; |
| 923 | unsigned int len; |
| 924 | unsigned int i; |
| 925 | |
| 926 | context_desc = 0; |
| 927 | packet->rdesc_count = 0; |
| 928 | |
| 929 | if (xgbe_is_tso(skb)) { |
| 930 | /* TSO requires an extra desriptor if mss is different */ |
| 931 | if (skb_shinfo(skb)->gso_size != ring->tx.cur_mss) { |
| 932 | context_desc = 1; |
| 933 | packet->rdesc_count++; |
| 934 | } |
| 935 | |
| 936 | /* TSO requires an extra desriptor for TSO header */ |
| 937 | packet->rdesc_count++; |
| 938 | |
| 939 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 940 | TSO_ENABLE, 1); |
| 941 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 942 | CSUM_ENABLE, 1); |
| 943 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 944 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 945 | CSUM_ENABLE, 1); |
| 946 | |
| 947 | if (vlan_tx_tag_present(skb)) { |
| 948 | /* VLAN requires an extra descriptor if tag is different */ |
| 949 | if (vlan_tx_tag_get(skb) != ring->tx.cur_vlan_ctag) |
| 950 | /* We can share with the TSO context descriptor */ |
| 951 | if (!context_desc) { |
| 952 | context_desc = 1; |
| 953 | packet->rdesc_count++; |
| 954 | } |
| 955 | |
| 956 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 957 | VLAN_CTAG, 1); |
| 958 | } |
| 959 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 960 | if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 961 | (pdata->tstamp_config.tx_type == HWTSTAMP_TX_ON)) |
| 962 | XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, |
| 963 | PTP, 1); |
| 964 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 965 | for (len = skb_headlen(skb); len;) { |
| 966 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 967 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 971 | frag = &skb_shinfo(skb)->frags[i]; |
| 972 | for (len = skb_frag_size(frag); len; ) { |
| 973 | packet->rdesc_count++; |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 974 | len -= min_t(unsigned int, len, XGBE_TX_MAX_BUF_SIZE); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | static int xgbe_open(struct net_device *netdev) |
| 980 | { |
| 981 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 982 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 983 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 984 | int ret; |
| 985 | |
| 986 | DBGPR("-->xgbe_open\n"); |
| 987 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 988 | /* Enable the clocks */ |
| 989 | ret = clk_prepare_enable(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 990 | if (ret) { |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 991 | netdev_alert(netdev, "dma clk_prepare_enable failed\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 992 | return ret; |
| 993 | } |
| 994 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 995 | ret = clk_prepare_enable(pdata->ptpclk); |
| 996 | if (ret) { |
| 997 | netdev_alert(netdev, "ptp clk_prepare_enable failed\n"); |
| 998 | goto err_sysclk; |
| 999 | } |
| 1000 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1001 | /* Calculate the Rx buffer size before allocating rings */ |
| 1002 | ret = xgbe_calc_rx_buf_size(netdev, netdev->mtu); |
| 1003 | if (ret < 0) |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1004 | goto err_ptpclk; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1005 | pdata->rx_buf_size = ret; |
| 1006 | |
| 1007 | /* Allocate the ring descriptors and buffers */ |
| 1008 | ret = desc_if->alloc_ring_resources(pdata); |
| 1009 | if (ret) |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1010 | goto err_ptpclk; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1011 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1012 | /* Initialize the device restart and Tx timestamp work struct */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1013 | INIT_WORK(&pdata->restart_work, xgbe_restart); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1014 | INIT_WORK(&pdata->tx_tstamp_work, xgbe_tx_tstamp); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1015 | |
| 1016 | /* Request interrupts */ |
| 1017 | ret = devm_request_irq(pdata->dev, netdev->irq, xgbe_isr, 0, |
| 1018 | netdev->name, pdata); |
| 1019 | if (ret) { |
| 1020 | netdev_alert(netdev, "error requesting irq %d\n", |
| 1021 | pdata->irq_number); |
| 1022 | goto err_irq; |
| 1023 | } |
| 1024 | pdata->irq_number = netdev->irq; |
| 1025 | |
| 1026 | ret = xgbe_start(pdata); |
| 1027 | if (ret) |
| 1028 | goto err_start; |
| 1029 | |
| 1030 | DBGPR("<--xgbe_open\n"); |
| 1031 | |
| 1032 | return 0; |
| 1033 | |
| 1034 | err_start: |
| 1035 | hw_if->exit(pdata); |
| 1036 | |
| 1037 | devm_free_irq(pdata->dev, pdata->irq_number, pdata); |
| 1038 | pdata->irq_number = 0; |
| 1039 | |
| 1040 | err_irq: |
| 1041 | desc_if->free_ring_resources(pdata); |
| 1042 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1043 | err_ptpclk: |
| 1044 | clk_disable_unprepare(pdata->ptpclk); |
| 1045 | |
| 1046 | err_sysclk: |
| 1047 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1048 | |
| 1049 | return ret; |
| 1050 | } |
| 1051 | |
| 1052 | static int xgbe_close(struct net_device *netdev) |
| 1053 | { |
| 1054 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1055 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1056 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1057 | |
| 1058 | DBGPR("-->xgbe_close\n"); |
| 1059 | |
| 1060 | /* Stop the device */ |
| 1061 | xgbe_stop(pdata); |
| 1062 | |
| 1063 | /* Issue software reset to device */ |
| 1064 | hw_if->exit(pdata); |
| 1065 | |
| 1066 | /* Free all the ring data */ |
| 1067 | desc_if->free_ring_resources(pdata); |
| 1068 | |
| 1069 | /* Release the interrupt */ |
| 1070 | if (pdata->irq_number != 0) { |
| 1071 | devm_free_irq(pdata->dev, pdata->irq_number, pdata); |
| 1072 | pdata->irq_number = 0; |
| 1073 | } |
| 1074 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1075 | /* Disable the clocks */ |
| 1076 | clk_disable_unprepare(pdata->ptpclk); |
| 1077 | clk_disable_unprepare(pdata->sysclk); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1078 | |
| 1079 | DBGPR("<--xgbe_close\n"); |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1085 | { |
| 1086 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1087 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1088 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1089 | struct xgbe_channel *channel; |
| 1090 | struct xgbe_ring *ring; |
| 1091 | struct xgbe_packet_data *packet; |
| 1092 | unsigned long flags; |
| 1093 | int ret; |
| 1094 | |
| 1095 | DBGPR("-->xgbe_xmit: skb->len = %d\n", skb->len); |
| 1096 | |
| 1097 | channel = pdata->channel + skb->queue_mapping; |
| 1098 | ring = channel->tx_ring; |
| 1099 | packet = &ring->packet_data; |
| 1100 | |
| 1101 | ret = NETDEV_TX_OK; |
| 1102 | |
| 1103 | spin_lock_irqsave(&ring->lock, flags); |
| 1104 | |
| 1105 | if (skb->len == 0) { |
| 1106 | netdev_err(netdev, "empty skb received from stack\n"); |
| 1107 | dev_kfree_skb_any(skb); |
| 1108 | goto tx_netdev_return; |
| 1109 | } |
| 1110 | |
| 1111 | /* Calculate preliminary packet info */ |
| 1112 | memset(packet, 0, sizeof(*packet)); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1113 | xgbe_packet_info(pdata, ring, skb, packet); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1114 | |
| 1115 | /* Check that there are enough descriptors available */ |
| 1116 | if (packet->rdesc_count > xgbe_tx_avail_desc(ring)) { |
| 1117 | DBGPR(" Tx queue stopped, not enough descriptors available\n"); |
| 1118 | netif_stop_subqueue(netdev, channel->queue_index); |
| 1119 | ring->tx.queue_stopped = 1; |
| 1120 | ret = NETDEV_TX_BUSY; |
| 1121 | goto tx_netdev_return; |
| 1122 | } |
| 1123 | |
| 1124 | ret = xgbe_prep_tso(skb, packet); |
| 1125 | if (ret) { |
| 1126 | netdev_err(netdev, "error processing TSO packet\n"); |
| 1127 | dev_kfree_skb_any(skb); |
| 1128 | goto tx_netdev_return; |
| 1129 | } |
| 1130 | xgbe_prep_vlan(skb, packet); |
| 1131 | |
| 1132 | if (!desc_if->map_tx_skb(channel, skb)) { |
| 1133 | dev_kfree_skb_any(skb); |
| 1134 | goto tx_netdev_return; |
| 1135 | } |
| 1136 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1137 | xgbe_prep_tx_tstamp(pdata, skb, packet); |
| 1138 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1139 | /* Configure required descriptor fields for transmission */ |
| 1140 | hw_if->pre_xmit(channel); |
| 1141 | |
| 1142 | #ifdef XGMAC_ENABLE_TX_PKT_DUMP |
| 1143 | xgbe_print_pkt(netdev, skb, true); |
| 1144 | #endif |
| 1145 | |
| 1146 | tx_netdev_return: |
| 1147 | spin_unlock_irqrestore(&ring->lock, flags); |
| 1148 | |
| 1149 | DBGPR("<--xgbe_xmit\n"); |
| 1150 | |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
| 1154 | static void xgbe_set_rx_mode(struct net_device *netdev) |
| 1155 | { |
| 1156 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1157 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1158 | unsigned int pr_mode, am_mode; |
| 1159 | |
| 1160 | DBGPR("-->xgbe_set_rx_mode\n"); |
| 1161 | |
| 1162 | pr_mode = ((netdev->flags & IFF_PROMISC) != 0); |
| 1163 | am_mode = ((netdev->flags & IFF_ALLMULTI) != 0); |
| 1164 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1165 | hw_if->set_promiscuous_mode(pdata, pr_mode); |
| 1166 | hw_if->set_all_multicast_mode(pdata, am_mode); |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 1167 | |
| 1168 | hw_if->add_mac_addresses(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1169 | |
| 1170 | DBGPR("<--xgbe_set_rx_mode\n"); |
| 1171 | } |
| 1172 | |
| 1173 | static int xgbe_set_mac_address(struct net_device *netdev, void *addr) |
| 1174 | { |
| 1175 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1176 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1177 | struct sockaddr *saddr = addr; |
| 1178 | |
| 1179 | DBGPR("-->xgbe_set_mac_address\n"); |
| 1180 | |
| 1181 | if (!is_valid_ether_addr(saddr->sa_data)) |
| 1182 | return -EADDRNOTAVAIL; |
| 1183 | |
| 1184 | memcpy(netdev->dev_addr, saddr->sa_data, netdev->addr_len); |
| 1185 | |
| 1186 | hw_if->set_mac_address(pdata, netdev->dev_addr); |
| 1187 | |
| 1188 | DBGPR("<--xgbe_set_mac_address\n"); |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1193 | static int xgbe_ioctl(struct net_device *netdev, struct ifreq *ifreq, int cmd) |
| 1194 | { |
| 1195 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1196 | int ret; |
| 1197 | |
| 1198 | switch (cmd) { |
| 1199 | case SIOCGHWTSTAMP: |
| 1200 | ret = xgbe_get_hwtstamp_settings(pdata, ifreq); |
| 1201 | break; |
| 1202 | |
| 1203 | case SIOCSHWTSTAMP: |
| 1204 | ret = xgbe_set_hwtstamp_settings(pdata, ifreq); |
| 1205 | break; |
| 1206 | |
| 1207 | default: |
| 1208 | ret = -EOPNOTSUPP; |
| 1209 | } |
| 1210 | |
| 1211 | return ret; |
| 1212 | } |
| 1213 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1214 | static int xgbe_change_mtu(struct net_device *netdev, int mtu) |
| 1215 | { |
| 1216 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1217 | int ret; |
| 1218 | |
| 1219 | DBGPR("-->xgbe_change_mtu\n"); |
| 1220 | |
| 1221 | ret = xgbe_calc_rx_buf_size(netdev, mtu); |
| 1222 | if (ret < 0) |
| 1223 | return ret; |
| 1224 | |
| 1225 | pdata->rx_buf_size = ret; |
| 1226 | netdev->mtu = mtu; |
| 1227 | |
| 1228 | xgbe_restart_dev(pdata, 0); |
| 1229 | |
| 1230 | DBGPR("<--xgbe_change_mtu\n"); |
| 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev, |
| 1236 | struct rtnl_link_stats64 *s) |
| 1237 | { |
| 1238 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1239 | struct xgbe_mmc_stats *pstats = &pdata->mmc_stats; |
| 1240 | |
| 1241 | DBGPR("-->%s\n", __func__); |
| 1242 | |
| 1243 | pdata->hw_if.read_mmc_stats(pdata); |
| 1244 | |
| 1245 | s->rx_packets = pstats->rxframecount_gb; |
| 1246 | s->rx_bytes = pstats->rxoctetcount_gb; |
| 1247 | s->rx_errors = pstats->rxframecount_gb - |
| 1248 | pstats->rxbroadcastframes_g - |
| 1249 | pstats->rxmulticastframes_g - |
| 1250 | pstats->rxunicastframes_g; |
| 1251 | s->multicast = pstats->rxmulticastframes_g; |
| 1252 | s->rx_length_errors = pstats->rxlengtherror; |
| 1253 | s->rx_crc_errors = pstats->rxcrcerror; |
| 1254 | s->rx_fifo_errors = pstats->rxfifooverflow; |
| 1255 | |
| 1256 | s->tx_packets = pstats->txframecount_gb; |
| 1257 | s->tx_bytes = pstats->txoctetcount_gb; |
| 1258 | s->tx_errors = pstats->txframecount_gb - pstats->txframecount_g; |
| 1259 | s->tx_dropped = netdev->stats.tx_dropped; |
| 1260 | |
| 1261 | DBGPR("<--%s\n", __func__); |
| 1262 | |
| 1263 | return s; |
| 1264 | } |
| 1265 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1266 | static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, |
| 1267 | u16 vid) |
| 1268 | { |
| 1269 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1270 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1271 | |
| 1272 | DBGPR("-->%s\n", __func__); |
| 1273 | |
| 1274 | set_bit(vid, pdata->active_vlans); |
| 1275 | hw_if->update_vlan_hash_table(pdata); |
| 1276 | |
| 1277 | DBGPR("<--%s\n", __func__); |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, |
| 1283 | u16 vid) |
| 1284 | { |
| 1285 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1286 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1287 | |
| 1288 | DBGPR("-->%s\n", __func__); |
| 1289 | |
| 1290 | clear_bit(vid, pdata->active_vlans); |
| 1291 | hw_if->update_vlan_hash_table(pdata); |
| 1292 | |
| 1293 | DBGPR("<--%s\n", __func__); |
| 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1298 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1299 | static void xgbe_poll_controller(struct net_device *netdev) |
| 1300 | { |
| 1301 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1302 | |
| 1303 | DBGPR("-->xgbe_poll_controller\n"); |
| 1304 | |
| 1305 | disable_irq(pdata->irq_number); |
| 1306 | |
| 1307 | xgbe_isr(pdata->irq_number, pdata); |
| 1308 | |
| 1309 | enable_irq(pdata->irq_number); |
| 1310 | |
| 1311 | DBGPR("<--xgbe_poll_controller\n"); |
| 1312 | } |
| 1313 | #endif /* End CONFIG_NET_POLL_CONTROLLER */ |
| 1314 | |
| 1315 | static int xgbe_set_features(struct net_device *netdev, |
| 1316 | netdev_features_t features) |
| 1317 | { |
| 1318 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 1319 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1320 | unsigned int rxcsum, rxvlan, rxvlan_filter; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1321 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1322 | rxcsum = pdata->netdev_features & NETIF_F_RXCSUM; |
| 1323 | rxvlan = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_RX; |
| 1324 | rxvlan_filter = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_FILTER; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1325 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1326 | if ((features & NETIF_F_RXCSUM) && !rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1327 | hw_if->enable_rx_csum(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1328 | else if (!(features & NETIF_F_RXCSUM) && rxcsum) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1329 | hw_if->disable_rx_csum(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1330 | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1331 | if ((features & NETIF_F_HW_VLAN_CTAG_RX) && !rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1332 | hw_if->enable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1333 | else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) && rxvlan) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1334 | hw_if->disable_rx_vlan_stripping(pdata); |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1335 | |
| 1336 | if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && !rxvlan_filter) |
| 1337 | hw_if->enable_rx_vlan_filtering(pdata); |
| 1338 | else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && rxvlan_filter) |
| 1339 | hw_if->disable_rx_vlan_filtering(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1340 | |
| 1341 | pdata->netdev_features = features; |
| 1342 | |
| 1343 | DBGPR("<--xgbe_set_features\n"); |
| 1344 | |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | static const struct net_device_ops xgbe_netdev_ops = { |
| 1349 | .ndo_open = xgbe_open, |
| 1350 | .ndo_stop = xgbe_close, |
| 1351 | .ndo_start_xmit = xgbe_xmit, |
| 1352 | .ndo_set_rx_mode = xgbe_set_rx_mode, |
| 1353 | .ndo_set_mac_address = xgbe_set_mac_address, |
| 1354 | .ndo_validate_addr = eth_validate_addr, |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1355 | .ndo_do_ioctl = xgbe_ioctl, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1356 | .ndo_change_mtu = xgbe_change_mtu, |
| 1357 | .ndo_get_stats64 = xgbe_get_stats64, |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 1358 | .ndo_vlan_rx_add_vid = xgbe_vlan_rx_add_vid, |
| 1359 | .ndo_vlan_rx_kill_vid = xgbe_vlan_rx_kill_vid, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1360 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1361 | .ndo_poll_controller = xgbe_poll_controller, |
| 1362 | #endif |
| 1363 | .ndo_set_features = xgbe_set_features, |
| 1364 | }; |
| 1365 | |
| 1366 | struct net_device_ops *xgbe_get_netdev_ops(void) |
| 1367 | { |
| 1368 | return (struct net_device_ops *)&xgbe_netdev_ops; |
| 1369 | } |
| 1370 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1371 | static void xgbe_rx_refresh(struct xgbe_channel *channel) |
| 1372 | { |
| 1373 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1374 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1375 | struct xgbe_ring *ring = channel->rx_ring; |
| 1376 | struct xgbe_ring_data *rdata; |
| 1377 | |
| 1378 | desc_if->realloc_skb(channel); |
| 1379 | |
| 1380 | /* Update the Rx Tail Pointer Register with address of |
| 1381 | * the last cleaned entry */ |
| 1382 | rdata = XGBE_GET_DESC_DATA(ring, ring->rx.realloc_index - 1); |
| 1383 | XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO, |
| 1384 | lower_32_bits(rdata->rdesc_dma)); |
| 1385 | } |
| 1386 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1387 | static int xgbe_tx_poll(struct xgbe_channel *channel) |
| 1388 | { |
| 1389 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1390 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 1391 | struct xgbe_desc_if *desc_if = &pdata->desc_if; |
| 1392 | struct xgbe_ring *ring = channel->tx_ring; |
| 1393 | struct xgbe_ring_data *rdata; |
| 1394 | struct xgbe_ring_desc *rdesc; |
| 1395 | struct net_device *netdev = pdata->netdev; |
| 1396 | unsigned long flags; |
| 1397 | int processed = 0; |
| 1398 | |
| 1399 | DBGPR("-->xgbe_tx_poll\n"); |
| 1400 | |
| 1401 | /* Nothing to do if there isn't a Tx ring for this channel */ |
| 1402 | if (!ring) |
| 1403 | return 0; |
| 1404 | |
| 1405 | spin_lock_irqsave(&ring->lock, flags); |
| 1406 | |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1407 | while ((processed < XGBE_TX_DESC_MAX_PROC) && |
| 1408 | (ring->dirty < ring->cur)) { |
| 1409 | rdata = XGBE_GET_DESC_DATA(ring, ring->dirty); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1410 | rdesc = rdata->rdesc; |
| 1411 | |
| 1412 | if (!hw_if->tx_complete(rdesc)) |
| 1413 | break; |
| 1414 | |
| 1415 | #ifdef XGMAC_ENABLE_TX_DESC_DUMP |
| 1416 | xgbe_dump_tx_desc(ring, ring->dirty, 1, 0); |
| 1417 | #endif |
| 1418 | |
| 1419 | /* Free the SKB and reset the descriptor for re-use */ |
| 1420 | desc_if->unmap_skb(pdata, rdata); |
| 1421 | hw_if->tx_desc_reset(rdata); |
| 1422 | |
| 1423 | processed++; |
| 1424 | ring->dirty++; |
| 1425 | } |
| 1426 | |
| 1427 | if ((ring->tx.queue_stopped == 1) && |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1428 | (xgbe_tx_avail_desc(ring) > XGBE_TX_DESC_MIN_FREE)) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1429 | ring->tx.queue_stopped = 0; |
| 1430 | netif_wake_subqueue(netdev, channel->queue_index); |
| 1431 | } |
| 1432 | |
| 1433 | DBGPR("<--xgbe_tx_poll: processed=%d\n", processed); |
| 1434 | |
| 1435 | spin_unlock_irqrestore(&ring->lock, flags); |
| 1436 | |
| 1437 | return processed; |
| 1438 | } |
| 1439 | |
| 1440 | static int xgbe_rx_poll(struct xgbe_channel *channel, int budget) |
| 1441 | { |
| 1442 | struct xgbe_prv_data *pdata = channel->pdata; |
| 1443 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1444 | struct xgbe_ring *ring = channel->rx_ring; |
| 1445 | struct xgbe_ring_data *rdata; |
| 1446 | struct xgbe_packet_data *packet; |
| 1447 | struct net_device *netdev = pdata->netdev; |
| 1448 | struct sk_buff *skb; |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1449 | struct skb_shared_hwtstamps *hwtstamps; |
| 1450 | unsigned int incomplete, error, context_next, context; |
| 1451 | unsigned int len, put_len, max_len; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1452 | int received = 0; |
| 1453 | |
| 1454 | DBGPR("-->xgbe_rx_poll: budget=%d\n", budget); |
| 1455 | |
| 1456 | /* Nothing to do if there isn't a Rx ring for this channel */ |
| 1457 | if (!ring) |
| 1458 | return 0; |
| 1459 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1460 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1461 | packet = &ring->packet_data; |
| 1462 | while (received < budget) { |
| 1463 | DBGPR(" cur = %d\n", ring->cur); |
| 1464 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1465 | /* First time in loop see if we need to restore state */ |
| 1466 | if (!received && rdata->state_saved) { |
| 1467 | incomplete = rdata->state.incomplete; |
| 1468 | context_next = rdata->state.context_next; |
| 1469 | skb = rdata->state.skb; |
| 1470 | error = rdata->state.error; |
| 1471 | len = rdata->state.len; |
| 1472 | } else { |
| 1473 | memset(packet, 0, sizeof(*packet)); |
| 1474 | incomplete = 0; |
| 1475 | context_next = 0; |
| 1476 | skb = NULL; |
| 1477 | error = 0; |
| 1478 | len = 0; |
| 1479 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1480 | |
| 1481 | read_again: |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1482 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 1483 | |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1484 | if (ring->dirty > (XGBE_RX_DESC_CNT >> 3)) |
| 1485 | xgbe_rx_refresh(channel); |
| 1486 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1487 | if (hw_if->dev_read(channel)) |
| 1488 | break; |
| 1489 | |
| 1490 | received++; |
| 1491 | ring->cur++; |
| 1492 | ring->dirty++; |
| 1493 | |
| 1494 | dma_unmap_single(pdata->dev, rdata->skb_dma, |
| 1495 | rdata->skb_dma_len, DMA_FROM_DEVICE); |
| 1496 | rdata->skb_dma = 0; |
| 1497 | |
| 1498 | incomplete = XGMAC_GET_BITS(packet->attributes, |
| 1499 | RX_PACKET_ATTRIBUTES, |
| 1500 | INCOMPLETE); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1501 | context_next = XGMAC_GET_BITS(packet->attributes, |
| 1502 | RX_PACKET_ATTRIBUTES, |
| 1503 | CONTEXT_NEXT); |
| 1504 | context = XGMAC_GET_BITS(packet->attributes, |
| 1505 | RX_PACKET_ATTRIBUTES, |
| 1506 | CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1507 | |
| 1508 | /* Earlier error, just drain the remaining data */ |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1509 | if ((incomplete || context_next) && error) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1510 | goto read_again; |
| 1511 | |
| 1512 | if (error || packet->errors) { |
| 1513 | if (packet->errors) |
| 1514 | DBGPR("Error in received packet\n"); |
| 1515 | dev_kfree_skb(skb); |
| 1516 | continue; |
| 1517 | } |
| 1518 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1519 | if (!context) { |
| 1520 | put_len = rdata->len - len; |
| 1521 | if (skb) { |
| 1522 | if (pskb_expand_head(skb, 0, put_len, |
| 1523 | GFP_ATOMIC)) { |
| 1524 | DBGPR("pskb_expand_head error\n"); |
| 1525 | if (incomplete) { |
| 1526 | error = 1; |
| 1527 | goto read_again; |
| 1528 | } |
| 1529 | |
| 1530 | dev_kfree_skb(skb); |
| 1531 | continue; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1532 | } |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1533 | memcpy(skb_tail_pointer(skb), rdata->skb->data, |
| 1534 | put_len); |
| 1535 | } else { |
| 1536 | skb = rdata->skb; |
| 1537 | rdata->skb = NULL; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1538 | } |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1539 | skb_put(skb, put_len); |
| 1540 | len += put_len; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1541 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1542 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1543 | if (incomplete || context_next) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1544 | goto read_again; |
| 1545 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1546 | /* Stray Context Descriptor? */ |
| 1547 | if (!skb) |
| 1548 | continue; |
| 1549 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1550 | /* Be sure we don't exceed the configured MTU */ |
| 1551 | max_len = netdev->mtu + ETH_HLEN; |
| 1552 | if (!(netdev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
| 1553 | (skb->protocol == htons(ETH_P_8021Q))) |
| 1554 | max_len += VLAN_HLEN; |
| 1555 | |
| 1556 | if (skb->len > max_len) { |
| 1557 | DBGPR("packet length exceeds configured MTU\n"); |
| 1558 | dev_kfree_skb(skb); |
| 1559 | continue; |
| 1560 | } |
| 1561 | |
| 1562 | #ifdef XGMAC_ENABLE_RX_PKT_DUMP |
| 1563 | xgbe_print_pkt(netdev, skb, false); |
| 1564 | #endif |
| 1565 | |
| 1566 | skb_checksum_none_assert(skb); |
| 1567 | if (XGMAC_GET_BITS(packet->attributes, |
| 1568 | RX_PACKET_ATTRIBUTES, CSUM_DONE)) |
| 1569 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1570 | |
| 1571 | if (XGMAC_GET_BITS(packet->attributes, |
| 1572 | RX_PACKET_ATTRIBUTES, VLAN_CTAG)) |
| 1573 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 1574 | packet->vlan_ctag); |
| 1575 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1576 | if (XGMAC_GET_BITS(packet->attributes, |
| 1577 | RX_PACKET_ATTRIBUTES, RX_TSTAMP)) { |
| 1578 | u64 nsec; |
| 1579 | |
| 1580 | nsec = timecounter_cyc2time(&pdata->tstamp_tc, |
| 1581 | packet->rx_tstamp); |
| 1582 | hwtstamps = skb_hwtstamps(skb); |
| 1583 | hwtstamps->hwtstamp = ns_to_ktime(nsec); |
| 1584 | } |
| 1585 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1586 | skb->dev = netdev; |
| 1587 | skb->protocol = eth_type_trans(skb, netdev); |
| 1588 | skb_record_rx_queue(skb, channel->queue_index); |
| 1589 | skb_mark_napi_id(skb, &pdata->napi); |
| 1590 | |
| 1591 | netdev->last_rx = jiffies; |
| 1592 | napi_gro_receive(&pdata->napi, skb); |
| 1593 | } |
| 1594 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame^] | 1595 | /* Check if we need to save state before leaving */ |
| 1596 | if (received && (incomplete || context_next)) { |
| 1597 | rdata = XGBE_GET_DESC_DATA(ring, ring->cur); |
| 1598 | rdata->state_saved = 1; |
| 1599 | rdata->state.incomplete = incomplete; |
| 1600 | rdata->state.context_next = context_next; |
| 1601 | rdata->state.skb = skb; |
| 1602 | rdata->state.len = len; |
| 1603 | rdata->state.error = error; |
| 1604 | } |
| 1605 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1606 | DBGPR("<--xgbe_rx_poll: received = %d\n", received); |
| 1607 | |
| 1608 | return received; |
| 1609 | } |
| 1610 | |
| 1611 | static int xgbe_poll(struct napi_struct *napi, int budget) |
| 1612 | { |
| 1613 | struct xgbe_prv_data *pdata = container_of(napi, struct xgbe_prv_data, |
| 1614 | napi); |
| 1615 | struct xgbe_channel *channel; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1616 | int ring_budget; |
| 1617 | int processed, last_processed; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1618 | unsigned int i; |
| 1619 | |
| 1620 | DBGPR("-->xgbe_poll: budget=%d\n", budget); |
| 1621 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1622 | processed = 0; |
Lendacky, Thomas | 9867e8f | 2014-07-02 13:04:46 -0500 | [diff] [blame] | 1623 | ring_budget = budget / pdata->rx_ring_count; |
| 1624 | do { |
| 1625 | last_processed = processed; |
| 1626 | |
| 1627 | channel = pdata->channel; |
| 1628 | for (i = 0; i < pdata->channel_count; i++, channel++) { |
| 1629 | /* Cleanup Tx ring first */ |
| 1630 | xgbe_tx_poll(channel); |
| 1631 | |
| 1632 | /* Process Rx ring next */ |
| 1633 | if (ring_budget > (budget - processed)) |
| 1634 | ring_budget = budget - processed; |
| 1635 | processed += xgbe_rx_poll(channel, ring_budget); |
| 1636 | } |
| 1637 | } while ((processed < budget) && (processed != last_processed)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1638 | |
| 1639 | /* If we processed everything, we are done */ |
| 1640 | if (processed < budget) { |
| 1641 | /* Turn off polling */ |
| 1642 | napi_complete(napi); |
| 1643 | |
| 1644 | /* Enable Tx and Rx interrupts */ |
| 1645 | xgbe_enable_rx_tx_ints(pdata); |
| 1646 | } |
| 1647 | |
| 1648 | DBGPR("<--xgbe_poll: received = %d\n", processed); |
| 1649 | |
| 1650 | return processed; |
| 1651 | } |
| 1652 | |
| 1653 | void xgbe_dump_tx_desc(struct xgbe_ring *ring, unsigned int idx, |
| 1654 | unsigned int count, unsigned int flag) |
| 1655 | { |
| 1656 | struct xgbe_ring_data *rdata; |
| 1657 | struct xgbe_ring_desc *rdesc; |
| 1658 | |
| 1659 | while (count--) { |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 1660 | rdata = XGBE_GET_DESC_DATA(ring, idx); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1661 | rdesc = rdata->rdesc; |
| 1662 | DBGPR("TX_NORMAL_DESC[%d %s] = %08x:%08x:%08x:%08x\n", idx, |
| 1663 | (flag == 1) ? "QUEUED FOR TX" : "TX BY DEVICE", |
| 1664 | le32_to_cpu(rdesc->desc0), le32_to_cpu(rdesc->desc1), |
| 1665 | le32_to_cpu(rdesc->desc2), le32_to_cpu(rdesc->desc3)); |
| 1666 | idx++; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | void xgbe_dump_rx_desc(struct xgbe_ring *ring, struct xgbe_ring_desc *desc, |
| 1671 | unsigned int idx) |
| 1672 | { |
| 1673 | DBGPR("RX_NORMAL_DESC[%d RX BY DEVICE] = %08x:%08x:%08x:%08x\n", idx, |
| 1674 | le32_to_cpu(desc->desc0), le32_to_cpu(desc->desc1), |
| 1675 | le32_to_cpu(desc->desc2), le32_to_cpu(desc->desc3)); |
| 1676 | } |
| 1677 | |
| 1678 | void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx) |
| 1679 | { |
| 1680 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 1681 | unsigned char *buf = skb->data; |
| 1682 | unsigned char buffer[128]; |
| 1683 | unsigned int i, j; |
| 1684 | |
| 1685 | netdev_alert(netdev, "\n************** SKB dump ****************\n"); |
| 1686 | |
| 1687 | netdev_alert(netdev, "%s packet of %d bytes\n", |
| 1688 | (tx_rx ? "TX" : "RX"), skb->len); |
| 1689 | |
| 1690 | netdev_alert(netdev, "Dst MAC addr: %pM\n", eth->h_dest); |
| 1691 | netdev_alert(netdev, "Src MAC addr: %pM\n", eth->h_source); |
| 1692 | netdev_alert(netdev, "Protocol: 0x%04hx\n", ntohs(eth->h_proto)); |
| 1693 | |
| 1694 | for (i = 0, j = 0; i < skb->len;) { |
| 1695 | j += snprintf(buffer + j, sizeof(buffer) - j, "%02hhx", |
| 1696 | buf[i++]); |
| 1697 | |
| 1698 | if ((i % 32) == 0) { |
| 1699 | netdev_alert(netdev, " 0x%04x: %s\n", i - 32, buffer); |
| 1700 | j = 0; |
| 1701 | } else if ((i % 16) == 0) { |
| 1702 | buffer[j++] = ' '; |
| 1703 | buffer[j++] = ' '; |
| 1704 | } else if ((i % 4) == 0) { |
| 1705 | buffer[j++] = ' '; |
| 1706 | } |
| 1707 | } |
| 1708 | if (i % 32) |
| 1709 | netdev_alert(netdev, " 0x%04x: %s\n", i - (i % 32), buffer); |
| 1710 | |
| 1711 | netdev_alert(netdev, "\n************** SKB dump ****************\n"); |
| 1712 | } |