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