Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/if_vlan.h> |
| 18 | #include "ess_edma.h" |
| 19 | #include "edma.h" |
| 20 | |
| 21 | extern struct net_device *edma_netdev[EDMA_MAX_PORTID_SUPPORTED]; |
| 22 | bool edma_stp_rstp; |
| 23 | u16 edma_ath_eth_type; |
| 24 | |
| 25 | /* edma_skb_priority_offset() |
| 26 | * get edma skb priority |
| 27 | */ |
| 28 | static unsigned int edma_skb_priority_offset(struct sk_buff *skb) |
| 29 | { |
| 30 | return (skb->priority >> 2) & 1; |
| 31 | } |
| 32 | |
| 33 | /* edma_alloc_tx_ring() |
| 34 | * Allocate Tx descriptors ring |
| 35 | */ |
| 36 | static int edma_alloc_tx_ring(struct edma_common_info *edma_cinfo, |
| 37 | struct edma_tx_desc_ring *etdr) |
| 38 | { |
| 39 | struct platform_device *pdev = edma_cinfo->pdev; |
| 40 | u16 sw_size = sizeof(struct edma_sw_desc) * etdr->count; |
| 41 | |
| 42 | /* Initialize ring */ |
| 43 | etdr->size = sizeof(struct edma_tx_desc) * etdr->count; |
| 44 | etdr->sw_next_to_fill = 0; |
| 45 | etdr->sw_next_to_clean = 0; |
| 46 | |
| 47 | /* Allocate SW descriptors */ |
| 48 | etdr->sw_desc = vzalloc(sw_size); |
| 49 | if (!etdr->sw_desc) { |
| 50 | dev_err(&pdev->dev, "buffer alloc of tx ring failed=%p", etdr); |
| 51 | return -ENOMEM; |
| 52 | } |
| 53 | |
| 54 | /* Allocate HW descriptors */ |
| 55 | etdr->hw_desc = dma_alloc_coherent(&pdev->dev, etdr->size, &etdr->dma, |
| 56 | GFP_KERNEL); |
| 57 | if (!etdr->hw_desc) { |
| 58 | dev_err(&pdev->dev, "descriptor allocation for tx ring failed"); |
| 59 | vfree(etdr->sw_desc); |
| 60 | etdr->sw_desc = NULL; |
| 61 | return -ENOMEM; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | /* edma_free_tx_ring() |
| 68 | * Free tx rings allocated by edma_alloc_tx_rings |
| 69 | */ |
| 70 | static void edma_free_tx_ring(struct edma_common_info *edma_cinfo, |
| 71 | struct edma_tx_desc_ring *etdr) |
| 72 | { |
| 73 | struct platform_device *pdev = edma_cinfo->pdev; |
| 74 | |
| 75 | if (likely(etdr->hw_desc)) { |
| 76 | dma_free_coherent(&pdev->dev, etdr->size, etdr->hw_desc, |
| 77 | etdr->dma); |
| 78 | |
| 79 | vfree(etdr->sw_desc); |
| 80 | etdr->sw_desc = NULL; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* edma_alloc_rx_ring() |
| 85 | * allocate rx descriptor ring |
| 86 | */ |
| 87 | static int edma_alloc_rx_ring(struct edma_common_info *edma_cinfo, |
| 88 | struct edma_rfd_desc_ring *erxd) |
| 89 | { |
| 90 | struct platform_device *pdev = edma_cinfo->pdev; |
| 91 | u16 sw_size = sizeof(struct edma_sw_desc) * erxd->count; |
| 92 | |
| 93 | erxd->size = sizeof(struct edma_sw_desc) * erxd->count; |
| 94 | erxd->sw_next_to_fill = 0; |
| 95 | erxd->sw_next_to_clean = 0; |
| 96 | |
| 97 | /* Allocate SW descriptors */ |
| 98 | erxd->sw_desc = vzalloc(sw_size); |
| 99 | if (!erxd->sw_desc) |
| 100 | return -ENOMEM; |
| 101 | |
| 102 | /* Alloc HW descriptors */ |
| 103 | erxd->hw_desc = dma_alloc_coherent(&pdev->dev, erxd->size, &erxd->dma, |
| 104 | GFP_KERNEL); |
| 105 | if (!erxd->hw_desc) { |
| 106 | vfree(erxd->sw_desc); |
| 107 | erxd->sw_desc = NULL; |
| 108 | return -ENOMEM; |
| 109 | } |
| 110 | |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 111 | /* Initialize pending fill */ |
| 112 | erxd->pending_fill = 0; |
| 113 | |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /* edma_free_rx_ring() |
| 118 | * Free rx ring allocated by alloc_rx_ring |
| 119 | */ |
| 120 | static void edma_free_rx_ring(struct edma_common_info *edma_cinfo, |
| 121 | struct edma_rfd_desc_ring *erxd) |
| 122 | { |
| 123 | struct platform_device *pdev = edma_cinfo->pdev; |
| 124 | |
| 125 | if (likely(erxd->hw_desc)) { |
| 126 | dma_free_coherent(&pdev->dev, erxd->size, erxd->hw_desc, |
| 127 | erxd->dma); |
| 128 | |
| 129 | vfree(erxd->sw_desc); |
| 130 | erxd->sw_desc = NULL; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* edma_configure_tx() |
| 135 | * Configure transmission control data |
| 136 | */ |
| 137 | static void edma_configure_tx(struct edma_common_info *edma_cinfo) |
| 138 | { |
| 139 | u32 txq_ctrl_data; |
| 140 | |
| 141 | txq_ctrl_data = (EDMA_TPD_BURST << EDMA_TXQ_NUM_TPD_BURST_SHIFT); |
| 142 | txq_ctrl_data |= EDMA_TXQ_CTRL_TPD_BURST_EN; |
| 143 | txq_ctrl_data |= (EDMA_TXF_BURST << EDMA_TXQ_TXF_BURST_NUM_SHIFT); |
| 144 | edma_write_reg(EDMA_REG_TXQ_CTRL, txq_ctrl_data); |
| 145 | } |
| 146 | |
| 147 | /* edma_configure_rx() |
| 148 | * configure reception control data |
| 149 | */ |
| 150 | static void edma_configure_rx(struct edma_common_info *edma_cinfo) |
| 151 | { |
| 152 | struct edma_hw *hw = &edma_cinfo->hw; |
| 153 | u32 rss_type, rx_desc1, rxq_ctrl_data; |
| 154 | |
| 155 | /* Set RSS type */ |
| 156 | rss_type = hw->rss_type; |
| 157 | edma_write_reg(EDMA_REG_RSS_TYPE, rss_type); |
| 158 | |
| 159 | /* Set RFD burst number */ |
| 160 | rx_desc1 = (EDMA_RFD_BURST << EDMA_RXQ_RFD_BURST_NUM_SHIFT); |
| 161 | |
| 162 | /* Set RFD prefetch threshold */ |
| 163 | rx_desc1 |= (EDMA_RFD_THR << EDMA_RXQ_RFD_PF_THRESH_SHIFT); |
| 164 | |
| 165 | /* Set RFD in host ring low threshold to generte interrupt */ |
| 166 | rx_desc1 |= (EDMA_RFD_LTHR << EDMA_RXQ_RFD_LOW_THRESH_SHIFT); |
| 167 | edma_write_reg(EDMA_REG_RX_DESC1, rx_desc1); |
| 168 | |
| 169 | /* Set Rx FIFO threshold to start to DMA data to host */ |
| 170 | rxq_ctrl_data = EDMA_FIFO_THRESH_128_BYTE; |
| 171 | |
| 172 | /* Set RX remove vlan bit */ |
| 173 | rxq_ctrl_data |= EDMA_RXQ_CTRL_RMV_VLAN; |
| 174 | |
| 175 | edma_write_reg(EDMA_REG_RXQ_CTRL, rxq_ctrl_data); |
| 176 | } |
| 177 | |
| 178 | /* edma_alloc_rx_buf() |
| 179 | * does skb allocation for the received packets. |
| 180 | */ |
| 181 | static int edma_alloc_rx_buf(struct edma_common_info |
| 182 | *edma_cinfo, |
| 183 | struct edma_rfd_desc_ring *erdr, |
| 184 | int cleaned_count, int queue_id) |
| 185 | { |
| 186 | struct platform_device *pdev = edma_cinfo->pdev; |
| 187 | struct edma_rx_free_desc *rx_desc; |
| 188 | struct edma_sw_desc *sw_desc; |
| 189 | struct sk_buff *skb; |
| 190 | unsigned int i; |
| 191 | u16 prod_idx, length; |
| 192 | u32 reg_data; |
| 193 | |
| 194 | if (cleaned_count > erdr->count) { |
| 195 | dev_err(&pdev->dev, "Incorrect cleaned_count %d", |
| 196 | cleaned_count); |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | i = erdr->sw_next_to_fill; |
| 201 | |
| 202 | while (cleaned_count) { |
| 203 | sw_desc = &erdr->sw_desc[i]; |
| 204 | length = edma_cinfo->rx_head_buffer_len; |
| 205 | |
| 206 | if (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_REUSE) { |
| 207 | skb = sw_desc->skb; |
| 208 | |
| 209 | /* Clear REUSE flag */ |
| 210 | sw_desc->flags &= ~EDMA_SW_DESC_FLAG_SKB_REUSE; |
| 211 | } else { |
| 212 | /* alloc skb */ |
| 213 | skb = netdev_alloc_skb(edma_netdev[0], length); |
| 214 | if (!skb) { |
| 215 | /* Better luck next round */ |
| 216 | sw_desc->flags = 0; |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (!edma_cinfo->page_mode) { |
| 222 | sw_desc->dma = dma_map_single(&pdev->dev, skb->data, |
| 223 | length, DMA_FROM_DEVICE); |
| 224 | if (dma_mapping_error(&pdev->dev, sw_desc->dma)) { |
| 225 | WARN_ONCE(0, "EDMA DMA mapping failed for linear address %x", sw_desc->dma); |
| 226 | sw_desc->flags = 0; |
| 227 | sw_desc->skb = NULL; |
| 228 | dev_kfree_skb_any(skb); |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * We should not exit from here with REUSE flag set |
| 234 | * This is to avoid re-using same sk_buff for next |
| 235 | * time around |
| 236 | */ |
| 237 | sw_desc->flags = EDMA_SW_DESC_FLAG_SKB_HEAD; |
| 238 | sw_desc->length = length; |
| 239 | } else { |
| 240 | struct page *pg = alloc_page(GFP_ATOMIC); |
| 241 | |
| 242 | if (!pg) { |
| 243 | sw_desc->flags = 0; |
| 244 | sw_desc->skb = NULL; |
| 245 | dev_kfree_skb_any(skb); |
| 246 | break; |
| 247 | } |
| 248 | |
| 249 | sw_desc->dma = dma_map_page(&pdev->dev, pg, 0, |
| 250 | edma_cinfo->rx_page_buffer_len, |
| 251 | DMA_FROM_DEVICE); |
| 252 | if (dma_mapping_error(&pdev->dev, sw_desc->dma)) { |
| 253 | WARN_ONCE(0, "EDMA DMA mapping failed for page address %x", sw_desc->dma); |
| 254 | sw_desc->flags = 0; |
| 255 | sw_desc->skb = NULL; |
| 256 | __free_page(pg); |
| 257 | dev_kfree_skb_any(skb); |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | skb_fill_page_desc(skb, 0, pg, 0, |
| 262 | edma_cinfo->rx_page_buffer_len); |
| 263 | sw_desc->flags = EDMA_SW_DESC_FLAG_SKB_FRAG; |
| 264 | sw_desc->length = edma_cinfo->rx_page_buffer_len; |
| 265 | } |
| 266 | |
| 267 | /* Update the buffer info */ |
| 268 | sw_desc->skb = skb; |
| 269 | rx_desc = (&(erdr->hw_desc)[i]); |
| 270 | rx_desc->buffer_addr = cpu_to_le64(sw_desc->dma); |
| 271 | if (++i == erdr->count) |
| 272 | i = 0; |
| 273 | cleaned_count--; |
| 274 | } |
| 275 | |
| 276 | erdr->sw_next_to_fill = i; |
| 277 | |
| 278 | if (i == 0) |
| 279 | prod_idx = erdr->count - 1; |
| 280 | else |
| 281 | prod_idx = i - 1; |
| 282 | |
| 283 | /* Update the producer index */ |
| 284 | edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), ®_data); |
| 285 | reg_data &= ~EDMA_RFD_PROD_IDX_BITS; |
| 286 | reg_data |= prod_idx; |
| 287 | edma_write_reg(EDMA_REG_RFD_IDX_Q(queue_id), reg_data); |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 288 | |
| 289 | /* If we couldn't allocate all the buffers, |
| 290 | * we increment the alloc failure counters |
| 291 | */ |
| 292 | if (cleaned_count) |
| 293 | edma_cinfo->edma_ethstats.rx_alloc_fail_ctr++; |
| 294 | |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 295 | return cleaned_count; |
| 296 | } |
| 297 | |
| 298 | /* edma_init_desc() |
| 299 | * update descriptor ring size, buffer and producer/consumer index |
| 300 | */ |
| 301 | static void edma_init_desc(struct edma_common_info *edma_cinfo) |
| 302 | { |
| 303 | struct edma_rfd_desc_ring *rfd_ring; |
| 304 | struct edma_tx_desc_ring *etdr; |
| 305 | int i = 0, j = 0; |
| 306 | u32 data = 0; |
| 307 | u16 hw_cons_idx = 0; |
| 308 | |
| 309 | /* Set the base address of every TPD ring. */ |
| 310 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) { |
| 311 | etdr = edma_cinfo->tpd_ring[i]; |
| 312 | |
| 313 | /* Update descriptor ring base address */ |
| 314 | edma_write_reg(EDMA_REG_TPD_BASE_ADDR_Q(i), (u32)etdr->dma); |
| 315 | edma_read_reg(EDMA_REG_TPD_IDX_Q(i), &data); |
| 316 | |
| 317 | /* Calculate hardware consumer index */ |
| 318 | hw_cons_idx = (data >> EDMA_TPD_CONS_IDX_SHIFT) & 0xffff; |
| 319 | etdr->sw_next_to_fill = hw_cons_idx; |
| 320 | etdr->sw_next_to_clean = hw_cons_idx; |
| 321 | data &= ~(EDMA_TPD_PROD_IDX_MASK << EDMA_TPD_PROD_IDX_SHIFT); |
| 322 | data |= hw_cons_idx; |
| 323 | |
| 324 | /* update producer index */ |
| 325 | edma_write_reg(EDMA_REG_TPD_IDX_Q(i), data); |
| 326 | |
| 327 | /* update SW consumer index register */ |
| 328 | edma_write_reg(EDMA_REG_TX_SW_CONS_IDX_Q(i), hw_cons_idx); |
| 329 | |
| 330 | /* Set TPD ring size */ |
| 331 | edma_write_reg(EDMA_REG_TPD_RING_SIZE, |
| 332 | edma_cinfo->tx_ring_count & |
| 333 | EDMA_TPD_RING_SIZE_MASK); |
| 334 | } |
| 335 | |
| 336 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 337 | rfd_ring = edma_cinfo->rfd_ring[j]; |
| 338 | /* Update Receive Free descriptor ring base address */ |
| 339 | edma_write_reg(EDMA_REG_RFD_BASE_ADDR_Q(j), |
| 340 | (u32)(rfd_ring->dma)); |
| 341 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 342 | } |
| 343 | |
| 344 | data = edma_cinfo->rx_head_buffer_len; |
| 345 | if (edma_cinfo->page_mode) |
| 346 | data = edma_cinfo->rx_page_buffer_len; |
| 347 | |
| 348 | data &= EDMA_RX_BUF_SIZE_MASK; |
| 349 | data <<= EDMA_RX_BUF_SIZE_SHIFT; |
| 350 | |
| 351 | /* Update RFD ring size and RX buffer size */ |
| 352 | data |= (edma_cinfo->rx_ring_count & EDMA_RFD_RING_SIZE_MASK) |
| 353 | << EDMA_RFD_RING_SIZE_SHIFT; |
| 354 | |
| 355 | edma_write_reg(EDMA_REG_RX_DESC0, data); |
| 356 | |
| 357 | /* Disable TX FIFO low watermark and high watermark */ |
| 358 | edma_write_reg(EDMA_REG_TXF_WATER_MARK, 0); |
| 359 | |
| 360 | /* Load all of base address above */ |
| 361 | edma_read_reg(EDMA_REG_TX_SRAM_PART, &data); |
| 362 | data |= 1 << EDMA_LOAD_PTR_SHIFT; |
| 363 | edma_write_reg(EDMA_REG_TX_SRAM_PART, data); |
| 364 | } |
| 365 | |
| 366 | /* edma_receive_checksum |
| 367 | * Api to check checksum on receive packets |
| 368 | */ |
| 369 | static void edma_receive_checksum(struct edma_rx_return_desc *rd, |
| 370 | struct sk_buff *skb) |
| 371 | { |
| 372 | skb_checksum_none_assert(skb); |
| 373 | |
| 374 | /* check the RRD IP/L4 checksum bit to see if |
| 375 | * its set, which in turn indicates checksum |
| 376 | * failure. |
| 377 | */ |
| 378 | if (rd->rrd6 & EDMA_RRD_CSUM_FAIL_MASK) |
| 379 | return; |
| 380 | |
Rakesh Nair | 72e1d28 | 2017-05-19 22:21:01 +0530 | [diff] [blame^] | 381 | /* |
| 382 | * We disable checksum verification only if |
| 383 | * we have a TCP/UDP packet |
| 384 | */ |
| 385 | if (rd->rrd7 & (EDMA_RRD_L4OFFSET_MASK << EDMA_RRD_L4OFFSET_SHIFT)) |
| 386 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* edma_clean_rfd() |
| 390 | * clean up rx resourcers on error |
| 391 | */ |
| 392 | static void edma_clean_rfd(struct platform_device *pdev, |
| 393 | struct edma_rfd_desc_ring *erdr, |
| 394 | u16 index, |
| 395 | int pos) |
| 396 | { |
| 397 | struct edma_rx_free_desc *rx_desc = &(erdr->hw_desc[index]); |
| 398 | struct edma_sw_desc *sw_desc = &erdr->sw_desc[index]; |
| 399 | |
| 400 | /* Unmap non-first RFD positions in packet */ |
| 401 | if (pos) { |
| 402 | if (likely(sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_HEAD)) |
| 403 | dma_unmap_single(&pdev->dev, sw_desc->dma, |
| 404 | sw_desc->length, DMA_FROM_DEVICE); |
| 405 | else |
| 406 | dma_unmap_page(&pdev->dev, sw_desc->dma, |
| 407 | sw_desc->length, DMA_FROM_DEVICE); |
| 408 | } |
| 409 | |
| 410 | if (sw_desc->skb) { |
| 411 | dev_kfree_skb_any(sw_desc->skb); |
| 412 | sw_desc->skb = NULL; |
| 413 | } |
| 414 | |
| 415 | sw_desc->flags = 0; |
| 416 | memset(rx_desc, 0, sizeof(struct edma_rx_free_desc)); |
| 417 | } |
| 418 | |
| 419 | /* edma_rx_complete_stp_rstp() |
| 420 | * Complete Rx processing for STP RSTP packets |
| 421 | */ |
| 422 | static void edma_rx_complete_stp_rstp(struct sk_buff *skb, int port_id, struct edma_rx_return_desc *rd) |
| 423 | { |
| 424 | int i; |
| 425 | u32 priority; |
| 426 | u16 port_type; |
| 427 | u8 mac_addr[EDMA_ETH_HDR_LEN]; |
| 428 | |
| 429 | port_type = (rd->rrd1 >> EDMA_RRD_PORT_TYPE_SHIFT) |
| 430 | & EDMA_RRD_PORT_TYPE_MASK; |
| 431 | /* if port type is 0x4, then only proceed with |
| 432 | * other stp/rstp calculation |
| 433 | */ |
| 434 | if (port_type == EDMA_RX_ATH_HDR_RSTP_PORT_TYPE) { |
| 435 | u8 bpdu_mac[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x00}; |
| 436 | |
| 437 | /* calculate the frame priority */ |
| 438 | priority = (rd->rrd1 >> EDMA_RRD_PRIORITY_SHIFT) |
| 439 | & EDMA_RRD_PRIORITY_MASK; |
| 440 | |
| 441 | for (i = 0; i < EDMA_ETH_HDR_LEN; i++) |
| 442 | mac_addr[i] = skb->data[i]; |
| 443 | |
| 444 | /* Check if destination mac addr is bpdu addr */ |
| 445 | if (!memcmp(mac_addr, bpdu_mac, 6)) { |
| 446 | /* destination mac address is BPDU |
| 447 | * destination mac address, then add |
| 448 | * atheros header to the packet. |
| 449 | */ |
| 450 | u16 athr_hdr = (EDMA_RX_ATH_HDR_VERSION << EDMA_RX_ATH_HDR_VERSION_SHIFT) | |
| 451 | (priority << EDMA_RX_ATH_HDR_PRIORITY_SHIFT) | |
| 452 | (EDMA_RX_ATH_HDR_RSTP_PORT_TYPE << EDMA_RX_ATH_PORT_TYPE_SHIFT) | port_id; |
| 453 | skb_push(skb, 4); |
| 454 | memcpy(skb->data, mac_addr, EDMA_ETH_HDR_LEN); |
| 455 | *(uint16_t *)&skb->data[12] = htons(edma_ath_eth_type); |
| 456 | *(uint16_t *)&skb->data[14] = htons(athr_hdr); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /* edma_rx_complete_fraglist() |
| 462 | * Complete Rx processing for fraglist skbs |
| 463 | */ |
| 464 | static int edma_rx_complete_fraglist(struct sk_buff *skb, u16 num_rfds, u16 length, u32 sw_next_to_clean, |
| 465 | struct edma_rfd_desc_ring *erdr, struct edma_common_info *edma_cinfo) |
| 466 | { |
| 467 | struct platform_device *pdev = edma_cinfo->pdev; |
| 468 | struct edma_hw *hw = &edma_cinfo->hw; |
| 469 | struct sk_buff *skb_temp; |
| 470 | struct edma_sw_desc *sw_desc; |
| 471 | int i; |
| 472 | u16 size_remaining; |
| 473 | |
| 474 | skb->data_len = 0; |
| 475 | skb->tail += (hw->rx_head_buff_size - 16); |
| 476 | skb->len = skb->truesize = length; |
| 477 | size_remaining = length - (hw->rx_head_buff_size - 16); |
| 478 | |
| 479 | /* clean-up all related sw_descs */ |
| 480 | for (i = 1; i < num_rfds; i++) { |
| 481 | struct sk_buff *skb_prev; |
| 482 | |
| 483 | sw_desc = &erdr->sw_desc[sw_next_to_clean]; |
| 484 | skb_temp = sw_desc->skb; |
| 485 | |
| 486 | dma_unmap_single(&pdev->dev, sw_desc->dma, |
| 487 | sw_desc->length, DMA_FROM_DEVICE); |
| 488 | |
| 489 | if (size_remaining < hw->rx_head_buff_size) |
| 490 | skb_put(skb_temp, size_remaining); |
| 491 | else |
| 492 | skb_put(skb_temp, hw->rx_head_buff_size); |
| 493 | |
| 494 | /* If we are processing the first rfd, we link |
| 495 | * skb->frag_list to the skb corresponding to the |
| 496 | * first RFD |
| 497 | */ |
| 498 | if (i == 1) |
| 499 | skb_shinfo(skb)->frag_list = skb_temp; |
| 500 | else |
| 501 | skb_prev->next = skb_temp; |
| 502 | skb_prev = skb_temp; |
| 503 | skb_temp->next = NULL; |
| 504 | |
| 505 | skb->data_len += skb_temp->len; |
| 506 | size_remaining -= skb_temp->len; |
| 507 | |
| 508 | /* Increment SW index */ |
| 509 | sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1); |
| 510 | } |
| 511 | |
| 512 | return sw_next_to_clean; |
| 513 | } |
| 514 | |
| 515 | /* edma_rx_complete_paged() |
| 516 | * Complete Rx processing for paged skbs |
| 517 | */ |
| 518 | static int edma_rx_complete_paged(struct sk_buff *skb, u16 num_rfds, |
| 519 | u16 length, u32 sw_next_to_clean, |
| 520 | struct edma_rfd_desc_ring *erdr, |
| 521 | struct edma_common_info *edma_cinfo) |
| 522 | { |
| 523 | struct platform_device *pdev = edma_cinfo->pdev; |
| 524 | struct sk_buff *skb_temp; |
| 525 | struct edma_sw_desc *sw_desc; |
| 526 | int i; |
| 527 | u16 size_remaining; |
| 528 | |
| 529 | skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; |
| 530 | |
| 531 | /* Setup skbuff fields */ |
| 532 | skb->len = length; |
| 533 | |
| 534 | if (likely(num_rfds <= 1)) { |
| 535 | skb->data_len = length; |
| 536 | skb->truesize += edma_cinfo->rx_page_buffer_len; |
| 537 | skb_fill_page_desc(skb, 0, skb_frag_page(frag), |
| 538 | 16, length); |
| 539 | } else { |
| 540 | frag->size -= 16; |
| 541 | skb->data_len = frag->size; |
| 542 | skb->truesize += edma_cinfo->rx_page_buffer_len; |
| 543 | size_remaining = length - frag->size; |
| 544 | |
| 545 | skb_fill_page_desc(skb, 0, skb_frag_page(frag), |
| 546 | 16, frag->size); |
| 547 | |
| 548 | /* clean-up all related sw_descs */ |
| 549 | for (i = 1; i < num_rfds; i++) { |
| 550 | sw_desc = &erdr->sw_desc[sw_next_to_clean]; |
| 551 | skb_temp = sw_desc->skb; |
| 552 | frag = &skb_shinfo(skb_temp)->frags[0]; |
| 553 | dma_unmap_page(&pdev->dev, sw_desc->dma, |
| 554 | sw_desc->length, DMA_FROM_DEVICE); |
| 555 | |
| 556 | if (size_remaining < edma_cinfo->rx_page_buffer_len) |
| 557 | frag->size = size_remaining; |
| 558 | |
| 559 | skb_fill_page_desc(skb, i, skb_frag_page(frag), |
| 560 | 0, frag->size); |
| 561 | |
| 562 | /* We used frag pages from skb_temp in skb */ |
| 563 | skb_shinfo(skb_temp)->nr_frags = 0; |
| 564 | dev_kfree_skb_any(skb_temp); |
| 565 | |
| 566 | skb->data_len += frag->size; |
| 567 | skb->truesize += edma_cinfo->rx_page_buffer_len; |
| 568 | size_remaining -= frag->size; |
| 569 | |
| 570 | /* Increment SW index */ |
| 571 | sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return sw_next_to_clean; |
| 576 | } |
| 577 | |
| 578 | /* |
| 579 | * edma_rx_complete() |
| 580 | * Main api called from the poll function to process rx packets. |
| 581 | */ |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 582 | static u16 edma_rx_complete(struct edma_common_info *edma_cinfo, |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 583 | int *work_done, int work_to_do, int queue_id, |
| 584 | struct napi_struct *napi) |
| 585 | { |
| 586 | struct platform_device *pdev = edma_cinfo->pdev; |
| 587 | struct edma_rfd_desc_ring *erdr = edma_cinfo->rfd_ring[queue_id]; |
| 588 | u16 hash_type, rrd[8], cleaned_count = 0, length = 0, num_rfds = 1, |
| 589 | sw_next_to_clean, hw_next_to_clean = 0, vlan = 0, ret_count = 0; |
| 590 | u32 data = 0; |
| 591 | u16 count = erdr->count, rfd_avail; |
| 592 | u8 queue_to_rxid[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 593 | |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 594 | cleaned_count = erdr->pending_fill; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 595 | sw_next_to_clean = erdr->sw_next_to_clean; |
| 596 | |
| 597 | edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), &data); |
| 598 | hw_next_to_clean = (data >> EDMA_RFD_CONS_IDX_SHIFT) & |
| 599 | EDMA_RFD_CONS_IDX_MASK; |
| 600 | |
| 601 | do { |
| 602 | while (sw_next_to_clean != hw_next_to_clean) { |
| 603 | struct net_device *netdev; |
| 604 | struct edma_adapter *adapter; |
| 605 | struct edma_sw_desc *sw_desc; |
| 606 | struct sk_buff *skb; |
| 607 | struct edma_rx_return_desc *rd; |
| 608 | u8 *vaddr; |
| 609 | int port_id, i, drop_count = 0; |
| 610 | u32 priority; |
| 611 | |
| 612 | if (!work_to_do) |
| 613 | break; |
| 614 | |
| 615 | sw_desc = &erdr->sw_desc[sw_next_to_clean]; |
| 616 | skb = sw_desc->skb; |
| 617 | |
| 618 | /* Get RRD */ |
| 619 | if (!edma_cinfo->page_mode) { |
| 620 | dma_unmap_single(&pdev->dev, sw_desc->dma, |
| 621 | sw_desc->length, DMA_FROM_DEVICE); |
| 622 | rd = (struct edma_rx_return_desc *)skb->data; |
| 623 | |
| 624 | } else { |
| 625 | dma_unmap_page(&pdev->dev, sw_desc->dma, |
| 626 | sw_desc->length, DMA_FROM_DEVICE); |
| 627 | vaddr = kmap_atomic(skb_frag_page(&skb_shinfo(skb)->frags[0])); |
| 628 | memcpy((uint8_t *)&rrd[0], vaddr, 16); |
| 629 | rd = (struct edma_rx_return_desc *)rrd; |
| 630 | kunmap_atomic(vaddr); |
| 631 | } |
| 632 | |
| 633 | /* Check if RRD is valid */ |
| 634 | if (!(rd->rrd7 & EDMA_RRD_DESC_VALID)) { |
| 635 | dev_err(&pdev->dev, "Incorrect RRD DESC valid bit set"); |
| 636 | edma_clean_rfd(pdev, erdr, sw_next_to_clean, 0); |
| 637 | sw_next_to_clean = (sw_next_to_clean + 1) & |
| 638 | (erdr->count - 1); |
| 639 | cleaned_count++; |
| 640 | continue; |
| 641 | } |
| 642 | |
| 643 | /* Get the number of RFDs from RRD */ |
| 644 | num_rfds = rd->rrd1 & EDMA_RRD_NUM_RFD_MASK; |
| 645 | |
| 646 | /* Get Rx port ID from switch */ |
| 647 | port_id = (rd->rrd1 >> EDMA_PORT_ID_SHIFT) & EDMA_PORT_ID_MASK; |
| 648 | if ((!port_id) || (port_id > EDMA_MAX_PORTID_SUPPORTED)) { |
| 649 | if (net_ratelimit()) { |
| 650 | dev_err(&pdev->dev, "Incorrect RRD source port bit set"); |
| 651 | dev_err(&pdev->dev, |
| 652 | "RRD Dump\n rrd0:%x rrd1: %x rrd2: %x rrd3: %x rrd4: %x rrd5: %x rrd6: %x rrd7: %x", |
| 653 | rd->rrd0, rd->rrd1, rd->rrd2, rd->rrd3, rd->rrd4, rd->rrd5, rd->rrd6, rd->rrd7); |
| 654 | dev_err(&pdev->dev, "Num_rfds: %d, src_port: %d, pkt_size: %d, cvlan_tag: %d\n", |
| 655 | num_rfds, rd->rrd1 & EDMA_RRD_SRC_PORT_NUM_MASK, |
| 656 | rd->rrd6 & EDMA_RRD_PKT_SIZE_MASK, rd->rrd7 & EDMA_RRD_CVLAN); |
| 657 | } |
| 658 | for (i = 0; i < num_rfds; i++) { |
| 659 | edma_clean_rfd(pdev, erdr, sw_next_to_clean, i); |
| 660 | sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1); |
| 661 | } |
| 662 | |
| 663 | cleaned_count += num_rfds; |
| 664 | continue; |
| 665 | } |
| 666 | |
| 667 | netdev = edma_cinfo->portid_netdev_lookup_tbl[port_id]; |
| 668 | if (!netdev) { |
| 669 | dev_err(&pdev->dev, "Invalid netdev"); |
| 670 | for (i = 0; i < num_rfds; i++) { |
| 671 | edma_clean_rfd(pdev, erdr, sw_next_to_clean, i); |
| 672 | sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1); |
| 673 | } |
| 674 | |
| 675 | cleaned_count += num_rfds; |
| 676 | continue; |
| 677 | } |
| 678 | adapter = netdev_priv(netdev); |
| 679 | |
| 680 | /* This code is added to handle a usecase where high |
| 681 | * priority stream and a low priority stream are |
| 682 | * received simultaneously on DUT. The problem occurs |
| 683 | * if one of the Rx rings is full and the corresponding |
| 684 | * core is busy with other stuff. This causes ESS CPU |
| 685 | * port to backpressure all incoming traffic including |
| 686 | * high priority one. We monitor free descriptor count |
| 687 | * on each CPU and whenever it reaches threshold (< 80), |
| 688 | * we drop all low priority traffic and let only high |
| 689 | * priotiy traffic pass through. We can hence avoid |
| 690 | * ESS CPU port to send backpressure on high priroity |
| 691 | * stream. |
| 692 | */ |
| 693 | priority = (rd->rrd1 >> EDMA_RRD_PRIORITY_SHIFT) |
| 694 | & EDMA_RRD_PRIORITY_MASK; |
| 695 | if (likely(!priority && !edma_cinfo->page_mode && (num_rfds <= 1))) { |
| 696 | rfd_avail = (count + sw_next_to_clean - hw_next_to_clean - 1) & (count - 1); |
| 697 | if (rfd_avail < EDMA_RFD_AVAIL_THR) { |
| 698 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_REUSE; |
| 699 | sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1); |
| 700 | adapter->stats.rx_dropped++; |
| 701 | cleaned_count++; |
| 702 | drop_count++; |
| 703 | if (drop_count == 3) { |
| 704 | work_to_do--; |
| 705 | (*work_done)++; |
| 706 | drop_count = 0; |
| 707 | } |
| 708 | if (cleaned_count == EDMA_RX_BUFFER_WRITE) { |
| 709 | /* If buffer clean count reaches 16, we replenish HW buffers. */ |
| 710 | ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id); |
| 711 | edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id), |
| 712 | sw_next_to_clean); |
| 713 | cleaned_count = ret_count; |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 714 | erdr->pending_fill = ret_count; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 715 | } |
| 716 | continue; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | work_to_do--; |
| 721 | (*work_done)++; |
| 722 | |
| 723 | /* Increment SW index */ |
| 724 | sw_next_to_clean = (sw_next_to_clean + 1) & |
| 725 | (erdr->count - 1); |
| 726 | |
| 727 | /* Get the packet size and allocate buffer */ |
| 728 | length = rd->rrd6 & EDMA_RRD_PKT_SIZE_MASK; |
| 729 | |
| 730 | if (edma_cinfo->page_mode) { |
| 731 | /* paged skb */ |
| 732 | sw_next_to_clean = edma_rx_complete_paged(skb, num_rfds, length, |
| 733 | sw_next_to_clean, |
| 734 | erdr, edma_cinfo); |
| 735 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
| 736 | cleaned_count += num_rfds; |
| 737 | dev_kfree_skb_any(skb); |
| 738 | continue; |
| 739 | } |
| 740 | } else { |
| 741 | /* single or fraglist skb */ |
| 742 | |
| 743 | /* Addition of 16 bytes is required, as in the packet |
| 744 | * first 16 bytes are rrd descriptors, so actual data |
| 745 | * starts from an offset of 16. |
| 746 | */ |
| 747 | skb_reserve(skb, 16); |
| 748 | if (likely((num_rfds <= 1) || !edma_cinfo->fraglist_mode)) |
| 749 | skb_put(skb, length); |
| 750 | else |
| 751 | sw_next_to_clean = edma_rx_complete_fraglist(skb, num_rfds, length, |
| 752 | sw_next_to_clean, |
| 753 | erdr, edma_cinfo); |
| 754 | } |
| 755 | |
| 756 | cleaned_count += num_rfds; |
| 757 | |
| 758 | if (edma_stp_rstp) |
| 759 | edma_rx_complete_stp_rstp(skb, port_id, rd); |
| 760 | |
| 761 | skb->protocol = eth_type_trans(skb, netdev); |
| 762 | |
| 763 | /* Record Rx queue for RFS/RPS and fill flow hash from HW */ |
| 764 | skb_record_rx_queue(skb, queue_to_rxid[queue_id]); |
| 765 | if (netdev->features & NETIF_F_RXHASH) { |
| 766 | hash_type = (rd->rrd5 >> EDMA_HASH_TYPE_SHIFT); |
| 767 | if ((hash_type > EDMA_HASH_TYPE_START) && (hash_type < EDMA_HASH_TYPE_END)) |
| 768 | skb_set_hash(skb, rd->rrd2, PKT_HASH_TYPE_L4); |
| 769 | } |
| 770 | |
| 771 | #ifdef CONFIG_NF_FLOW_COOKIE |
| 772 | skb->flow_cookie = rd->rrd3 & EDMA_RRD_FLOW_COOKIE_MASK; |
| 773 | #endif |
| 774 | edma_receive_checksum(rd, skb); |
| 775 | |
| 776 | /* Process VLAN HW acceleration indication provided by HW */ |
| 777 | if (adapter->default_vlan_tag != rd->rrd4) { |
| 778 | vlan = rd->rrd4; |
| 779 | if (likely(rd->rrd7 & EDMA_RRD_CVLAN)) |
| 780 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan); |
| 781 | else if (rd->rrd1 & EDMA_RRD_SVLAN) |
| 782 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), vlan); |
| 783 | } |
| 784 | |
| 785 | /* Update rx statistics */ |
| 786 | adapter->stats.rx_packets++; |
| 787 | adapter->stats.rx_bytes += length; |
| 788 | |
| 789 | /* Check if we reached refill threshold */ |
| 790 | if (cleaned_count == EDMA_RX_BUFFER_WRITE) { |
| 791 | ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id); |
| 792 | edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id), |
| 793 | sw_next_to_clean); |
| 794 | cleaned_count = ret_count; |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 795 | erdr->pending_fill = ret_count; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* At this point skb should go to stack */ |
| 799 | napi_gro_receive(napi, skb); |
| 800 | } |
| 801 | |
| 802 | /* Check if we still have NAPI budget */ |
| 803 | if (!work_to_do) |
| 804 | break; |
| 805 | |
| 806 | /* Read index once again since we still have NAPI budget */ |
| 807 | edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), &data); |
| 808 | hw_next_to_clean = (data >> EDMA_RFD_CONS_IDX_SHIFT) & |
| 809 | EDMA_RFD_CONS_IDX_MASK; |
| 810 | } while (hw_next_to_clean != sw_next_to_clean); |
| 811 | |
| 812 | erdr->sw_next_to_clean = sw_next_to_clean; |
| 813 | |
| 814 | /* Refill here in case refill threshold wasn't reached */ |
| 815 | if (likely(cleaned_count)) { |
| 816 | ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id); |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 817 | erdr->pending_fill = ret_count; |
| 818 | if (ret_count) { |
| 819 | if(net_ratelimit()) |
| 820 | dev_dbg(&pdev->dev, "Edma not getting memory for descriptors.\n"); |
| 821 | } |
| 822 | |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 823 | edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id), |
| 824 | erdr->sw_next_to_clean); |
| 825 | } |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 826 | |
| 827 | return erdr->pending_fill; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /* edma_delete_rfs_filter() |
| 831 | * Remove RFS filter from switch |
| 832 | */ |
| 833 | static int edma_delete_rfs_filter(struct edma_adapter *adapter, |
| 834 | struct edma_rfs_filter_node *filter_node) |
| 835 | { |
| 836 | int res = -1; |
| 837 | |
| 838 | if (likely(adapter->set_rfs_rule)) |
| 839 | res = (*adapter->set_rfs_rule)(adapter->netdev, |
| 840 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 841 | filter_node->keys.src, |
| 842 | filter_node->keys.dst, filter_node->keys.port16[0], |
| 843 | filter_node->keys.port16[1], |
| 844 | filter_node->keys.ip_proto, |
| 845 | #else |
| 846 | filter_node->keys.addrs.v4addrs.src, |
| 847 | filter_node->keys.addrs.v4addrs.dst, filter_node->keys.ports.src, |
| 848 | filter_node->keys.ports.dst, |
| 849 | filter_node->keys.basic.ip_proto, |
| 850 | #endif |
| 851 | filter_node->rq_id, |
| 852 | 0); |
| 853 | |
| 854 | return res; |
| 855 | } |
| 856 | |
| 857 | /* edma_add_rfs_filter() |
| 858 | * Add RFS filter to switch |
| 859 | */ |
| 860 | static int edma_add_rfs_filter(struct edma_adapter *adapter, |
| 861 | struct flow_keys *keys, u16 rq, |
| 862 | struct edma_rfs_filter_node *filter_node) |
| 863 | { |
| 864 | int res = -1; |
| 865 | |
| 866 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 867 | filter_node->keys.src = keys->src; |
| 868 | filter_node->keys.dst = keys->dst; |
| 869 | filter_node->keys.ports = keys->ports; |
| 870 | filter_node->keys.ip_proto = keys->ip_proto; |
| 871 | #else |
| 872 | filter_node->keys.addrs.v4addrs.src = keys->addrs.v4addrs.src; |
| 873 | filter_node->keys.addrs.v4addrs.dst = keys->addrs.v4addrs.dst; |
| 874 | filter_node->keys.ports.ports = keys->ports.ports; |
| 875 | filter_node->keys.basic.ip_proto = keys->basic.ip_proto; |
| 876 | #endif |
| 877 | |
| 878 | /* Call callback registered by ESS driver */ |
| 879 | if (likely(adapter->set_rfs_rule)) |
| 880 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 881 | res = (*adapter->set_rfs_rule)(adapter->netdev, keys->src, |
| 882 | keys->dst, keys->port16[0], keys->port16[1], |
| 883 | keys->ip_proto, rq, 1); |
| 884 | #else |
| 885 | res = (*adapter->set_rfs_rule)(adapter->netdev, keys->addrs.v4addrs.src, |
| 886 | keys->addrs.v4addrs.dst, keys->ports.src, keys->ports.dst, |
| 887 | keys->basic.ip_proto, rq, 1); |
| 888 | #endif |
| 889 | |
| 890 | return res; |
| 891 | } |
| 892 | |
| 893 | /* edma_rfs_key_search() |
| 894 | * Look for existing RFS entry |
| 895 | */ |
| 896 | static struct edma_rfs_filter_node *edma_rfs_key_search(struct hlist_head *h, |
| 897 | struct flow_keys *key) |
| 898 | { |
| 899 | struct edma_rfs_filter_node *p; |
| 900 | |
| 901 | hlist_for_each_entry(p, h, node) |
| 902 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 903 | if (p->keys.src == key->src && |
| 904 | p->keys.dst == key->dst && |
| 905 | p->keys.ports == key->ports && |
| 906 | p->keys.ip_proto == key->ip_proto) |
| 907 | #else |
| 908 | if (p->keys.addrs.v4addrs.src == key->addrs.v4addrs.src && |
| 909 | p->keys.addrs.v4addrs.dst == key->addrs.v4addrs.dst && |
| 910 | p->keys.ports.ports == key->ports.ports && |
| 911 | p->keys.basic.ip_proto == key->basic.ip_proto) |
| 912 | #endif |
| 913 | return p; |
| 914 | return NULL; |
| 915 | } |
| 916 | |
| 917 | /* edma_initialise_rfs_flow_table() |
| 918 | * Initialise EDMA RFS flow table |
| 919 | */ |
| 920 | static void edma_initialise_rfs_flow_table(struct edma_adapter *adapter) |
| 921 | { |
| 922 | int i; |
| 923 | |
| 924 | spin_lock_init(&adapter->rfs.rfs_ftab_lock); |
| 925 | |
| 926 | /* Initialize EDMA flow hash table */ |
| 927 | for (i = 0; i < EDMA_RFS_FLOW_ENTRIES; i++) |
| 928 | INIT_HLIST_HEAD(&adapter->rfs.hlist_head[i]); |
| 929 | |
| 930 | adapter->rfs.max_num_filter = EDMA_RFS_FLOW_ENTRIES; |
| 931 | adapter->rfs.filter_available = adapter->rfs.max_num_filter; |
| 932 | adapter->rfs.hashtoclean = 0; |
| 933 | |
| 934 | /* Add timer to get periodic RFS updates from OS */ |
| 935 | init_timer(&adapter->rfs.expire_rfs); |
| 936 | adapter->rfs.expire_rfs.function = edma_flow_may_expire; |
| 937 | adapter->rfs.expire_rfs.data = (unsigned long)adapter; |
| 938 | mod_timer(&adapter->rfs.expire_rfs, jiffies + HZ/4); |
| 939 | } |
| 940 | |
| 941 | /* edma_free_rfs_flow_table() |
| 942 | * Free EDMA RFS flow table |
| 943 | */ |
| 944 | static void edma_free_rfs_flow_table(struct edma_adapter *adapter) |
| 945 | { |
| 946 | int i; |
| 947 | |
| 948 | /* Remove sync timer */ |
| 949 | del_timer_sync(&adapter->rfs.expire_rfs); |
| 950 | spin_lock_bh(&adapter->rfs.rfs_ftab_lock); |
| 951 | |
| 952 | /* Free EDMA RFS table entries */ |
| 953 | adapter->rfs.filter_available = 0; |
| 954 | |
| 955 | /* Clean-up EDMA flow hash table */ |
| 956 | for (i = 0; i < EDMA_RFS_FLOW_ENTRIES; i++) { |
| 957 | struct hlist_head *hhead; |
| 958 | struct hlist_node *tmp; |
| 959 | struct edma_rfs_filter_node *filter_node; |
| 960 | int res; |
| 961 | |
| 962 | hhead = &adapter->rfs.hlist_head[i]; |
| 963 | hlist_for_each_entry_safe(filter_node, tmp, hhead, node) { |
| 964 | res = edma_delete_rfs_filter(adapter, filter_node); |
| 965 | if (res < 0) |
| 966 | dev_warn(&adapter->netdev->dev, |
| 967 | "EDMA going down but RFS entry %d not allowed to be flushed by Switch", |
| 968 | filter_node->flow_id); |
| 969 | hlist_del(&filter_node->node); |
| 970 | kfree(filter_node); |
| 971 | } |
| 972 | } |
| 973 | spin_unlock_bh(&adapter->rfs.rfs_ftab_lock); |
| 974 | } |
| 975 | |
| 976 | /* edma_tx_unmap_and_free() |
| 977 | * clean TX buffer |
| 978 | */ |
| 979 | static inline void edma_tx_unmap_and_free(struct platform_device *pdev, |
| 980 | struct edma_sw_desc *sw_desc) |
| 981 | { |
| 982 | struct sk_buff *skb = sw_desc->skb; |
| 983 | |
| 984 | if (likely((sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_HEAD) || |
| 985 | (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_FRAGLIST))) |
| 986 | /* unmap_single for skb head area */ |
| 987 | dma_unmap_single(&pdev->dev, sw_desc->dma, |
| 988 | sw_desc->length, DMA_TO_DEVICE); |
| 989 | else if (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_FRAG) |
| 990 | /* unmap page for paged fragments */ |
| 991 | dma_unmap_page(&pdev->dev, sw_desc->dma, |
| 992 | sw_desc->length, DMA_TO_DEVICE); |
| 993 | |
| 994 | if (likely(sw_desc->flags & EDMA_SW_DESC_FLAG_LAST)) |
| 995 | dev_kfree_skb_any(skb); |
| 996 | |
| 997 | sw_desc->flags = 0; |
| 998 | } |
| 999 | |
| 1000 | /* edma_tx_complete() |
| 1001 | * Used to clean tx queues and update hardware and consumer index |
| 1002 | */ |
| 1003 | static void edma_tx_complete(struct edma_common_info *edma_cinfo, int queue_id) |
| 1004 | { |
| 1005 | struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1006 | struct edma_sw_desc *sw_desc; |
| 1007 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1008 | int i; |
| 1009 | |
| 1010 | u16 sw_next_to_clean = etdr->sw_next_to_clean; |
| 1011 | u16 hw_next_to_clean; |
| 1012 | u32 data = 0; |
| 1013 | |
| 1014 | edma_read_reg(EDMA_REG_TPD_IDX_Q(queue_id), &data); |
| 1015 | hw_next_to_clean = (data >> EDMA_TPD_CONS_IDX_SHIFT) & EDMA_TPD_CONS_IDX_MASK; |
| 1016 | |
| 1017 | /* clean the buffer here */ |
| 1018 | while (sw_next_to_clean != hw_next_to_clean) { |
| 1019 | sw_desc = &etdr->sw_desc[sw_next_to_clean]; |
| 1020 | edma_tx_unmap_and_free(pdev, sw_desc); |
| 1021 | sw_next_to_clean = (sw_next_to_clean + 1) & (etdr->count - 1); |
| 1022 | } |
| 1023 | |
| 1024 | etdr->sw_next_to_clean = sw_next_to_clean; |
| 1025 | |
| 1026 | /* update the TPD consumer index register */ |
| 1027 | edma_write_reg(EDMA_REG_TX_SW_CONS_IDX_Q(queue_id), sw_next_to_clean); |
| 1028 | |
| 1029 | /* Wake the queue if queue is stopped and netdev link is up */ |
| 1030 | for (i = 0; i < EDMA_MAX_NETDEV_PER_QUEUE && etdr->nq[i] ; i++) { |
| 1031 | if (netif_tx_queue_stopped(etdr->nq[i])) { |
| 1032 | if ((etdr->netdev[i]) && netif_carrier_ok(etdr->netdev[i])) |
| 1033 | netif_tx_wake_queue(etdr->nq[i]); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | /* edma_get_tx_buffer() |
| 1039 | * Get sw_desc corresponding to the TPD |
| 1040 | */ |
| 1041 | static struct edma_sw_desc *edma_get_tx_buffer(struct edma_common_info *edma_cinfo, |
| 1042 | struct edma_tx_desc *tpd, int queue_id) |
| 1043 | { |
| 1044 | struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1045 | |
| 1046 | return &etdr->sw_desc[tpd - (struct edma_tx_desc *)etdr->hw_desc]; |
| 1047 | } |
| 1048 | |
| 1049 | /* edma_get_next_tpd() |
| 1050 | * Return a TPD descriptor for transfer |
| 1051 | */ |
| 1052 | static struct edma_tx_desc *edma_get_next_tpd(struct edma_common_info *edma_cinfo, |
| 1053 | int queue_id) |
| 1054 | { |
| 1055 | struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1056 | u16 sw_next_to_fill = etdr->sw_next_to_fill; |
| 1057 | struct edma_tx_desc *tpd_desc = |
| 1058 | (&((struct edma_tx_desc *)(etdr->hw_desc))[sw_next_to_fill]); |
| 1059 | |
| 1060 | etdr->sw_next_to_fill = (etdr->sw_next_to_fill + 1) & (etdr->count - 1); |
| 1061 | |
| 1062 | return tpd_desc; |
| 1063 | } |
| 1064 | |
| 1065 | /* edma_tpd_available() |
| 1066 | * Check number of free TPDs |
| 1067 | */ |
| 1068 | static inline u16 edma_tpd_available(struct edma_common_info *edma_cinfo, |
| 1069 | int queue_id) |
| 1070 | { |
| 1071 | struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1072 | |
| 1073 | u16 sw_next_to_fill; |
| 1074 | u16 sw_next_to_clean; |
| 1075 | u16 count = 0; |
| 1076 | |
| 1077 | sw_next_to_clean = etdr->sw_next_to_clean; |
| 1078 | sw_next_to_fill = etdr->sw_next_to_fill; |
| 1079 | |
| 1080 | if (likely(sw_next_to_clean <= sw_next_to_fill)) |
| 1081 | count = etdr->count; |
| 1082 | |
| 1083 | return count + sw_next_to_clean - sw_next_to_fill - 1; |
| 1084 | } |
| 1085 | |
| 1086 | /* edma_tx_queue_get() |
| 1087 | * Get the starting number of the queue |
| 1088 | */ |
| 1089 | static inline int edma_tx_queue_get(struct edma_adapter *adapter, |
| 1090 | struct sk_buff *skb, int txq_id) |
| 1091 | { |
| 1092 | /* skb->priority is used as an index to skb priority table |
| 1093 | * and based on packet priority, correspong queue is assigned. |
| 1094 | */ |
| 1095 | return adapter->tx_start_offset[txq_id] + edma_skb_priority_offset(skb); |
| 1096 | } |
| 1097 | |
| 1098 | /* edma_tx_update_hw_idx() |
| 1099 | * update the producer index for the ring transmitted |
| 1100 | */ |
| 1101 | static void edma_tx_update_hw_idx(struct edma_common_info *edma_cinfo, |
| 1102 | struct sk_buff *skb, int queue_id) |
| 1103 | { |
| 1104 | struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1105 | u32 tpd_idx_data; |
| 1106 | |
| 1107 | /* Read and update the producer index */ |
| 1108 | edma_read_reg(EDMA_REG_TPD_IDX_Q(queue_id), &tpd_idx_data); |
| 1109 | tpd_idx_data &= ~EDMA_TPD_PROD_IDX_BITS; |
| 1110 | tpd_idx_data |= (etdr->sw_next_to_fill & EDMA_TPD_PROD_IDX_MASK) |
| 1111 | << EDMA_TPD_PROD_IDX_SHIFT; |
| 1112 | |
| 1113 | edma_write_reg(EDMA_REG_TPD_IDX_Q(queue_id), tpd_idx_data); |
| 1114 | } |
| 1115 | |
| 1116 | /* edma_rollback_tx() |
| 1117 | * Function to retrieve tx resources in case of error |
| 1118 | */ |
| 1119 | static void edma_rollback_tx(struct edma_adapter *adapter, |
| 1120 | struct edma_tx_desc *start_tpd, int queue_id) |
| 1121 | { |
| 1122 | struct edma_tx_desc_ring *etdr = adapter->edma_cinfo->tpd_ring[queue_id]; |
| 1123 | struct edma_sw_desc *sw_desc; |
| 1124 | struct edma_tx_desc *tpd = NULL; |
| 1125 | u16 start_index, index; |
| 1126 | |
| 1127 | start_index = start_tpd - (struct edma_tx_desc *)(etdr->hw_desc); |
| 1128 | |
| 1129 | index = start_index; |
| 1130 | while (index != etdr->sw_next_to_fill) { |
| 1131 | tpd = (&((struct edma_tx_desc *)(etdr->hw_desc))[index]); |
| 1132 | sw_desc = &etdr->sw_desc[index]; |
| 1133 | edma_tx_unmap_and_free(adapter->pdev, sw_desc); |
| 1134 | memset(tpd, 0, sizeof(struct edma_tx_desc)); |
| 1135 | if (++index == etdr->count) |
| 1136 | index = 0; |
| 1137 | } |
| 1138 | etdr->sw_next_to_fill = start_index; |
| 1139 | } |
| 1140 | |
| 1141 | /* edma_tx_map_and_fill() |
| 1142 | * gets called from edma_xmit_frame |
| 1143 | * |
| 1144 | * This is where the dma of the buffer to be transmitted |
| 1145 | * gets mapped |
| 1146 | */ |
| 1147 | static int edma_tx_map_and_fill(struct edma_common_info *edma_cinfo, |
| 1148 | struct edma_adapter *adapter, |
| 1149 | struct sk_buff *skb, int queue_id, |
| 1150 | unsigned int flags_transmit, |
| 1151 | u16 from_cpu, u16 dp_bitmap, |
| 1152 | bool packet_is_rstp, int nr_frags) |
| 1153 | { |
| 1154 | struct edma_sw_desc *sw_desc = NULL; |
| 1155 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1156 | struct edma_tx_desc *tpd = NULL; |
| 1157 | struct edma_tx_desc *start_tpd = NULL; |
| 1158 | struct sk_buff *iter_skb; |
| 1159 | int i; |
| 1160 | u32 word1 = 0, word3 = 0, lso_word1 = 0, svlan_tag = 0; |
| 1161 | u16 buf_len, lso_desc_len = 0; |
| 1162 | |
| 1163 | if (skb_is_gso(skb)) { |
| 1164 | /* TODO: What additional checks need to be performed here */ |
| 1165 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { |
| 1166 | lso_word1 |= EDMA_TPD_IPV4_EN; |
| 1167 | ip_hdr(skb)->check = 0; |
| 1168 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 1169 | ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 1170 | } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { |
| 1171 | lso_word1 |= EDMA_TPD_LSO_V2_EN; |
| 1172 | ipv6_hdr(skb)->payload_len = 0; |
| 1173 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 1174 | &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 1175 | } else |
| 1176 | return -EINVAL; |
| 1177 | |
| 1178 | lso_word1 |= EDMA_TPD_LSO_EN | ((skb_shinfo(skb)->gso_size & EDMA_TPD_MSS_MASK) << EDMA_TPD_MSS_SHIFT) | |
| 1179 | (skb_transport_offset(skb) << EDMA_TPD_HDR_SHIFT); |
| 1180 | } else if (flags_transmit & EDMA_HW_CHECKSUM) { |
| 1181 | u8 css, cso; |
| 1182 | cso = skb_checksum_start_offset(skb); |
| 1183 | css = cso + skb->csum_offset; |
| 1184 | |
| 1185 | word1 |= (EDMA_TPD_CUSTOM_CSUM_EN); |
| 1186 | word1 |= (cso >> 1) << EDMA_TPD_HDR_SHIFT; |
| 1187 | word1 |= ((css >> 1) << EDMA_TPD_CUSTOM_CSUM_SHIFT); |
| 1188 | } |
| 1189 | |
| 1190 | if (skb->protocol == htons(ETH_P_PPP_SES)) |
| 1191 | word1 |= EDMA_TPD_PPPOE_EN; |
| 1192 | |
| 1193 | if (flags_transmit & EDMA_VLAN_TX_TAG_INSERT_FLAG) { |
| 1194 | switch (skb->vlan_proto) { |
| 1195 | case htons(ETH_P_8021Q): |
| 1196 | word3 |= (1 << EDMA_TX_INS_CVLAN); |
| 1197 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 1198 | word3 |= vlan_tx_tag_get(skb) << EDMA_TX_CVLAN_TAG_SHIFT; |
| 1199 | #else |
| 1200 | word3 |= skb_vlan_tag_get(skb) << EDMA_TX_CVLAN_TAG_SHIFT; |
| 1201 | #endif |
| 1202 | break; |
| 1203 | case htons(ETH_P_8021AD): |
| 1204 | word1 |= (1 << EDMA_TX_INS_SVLAN); |
| 1205 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 1206 | svlan_tag = vlan_tx_tag_get(skb) << EDMA_TX_SVLAN_TAG_SHIFT; |
| 1207 | #else |
| 1208 | svlan_tag = skb_vlan_tag_get(skb) << EDMA_TX_SVLAN_TAG_SHIFT; |
| 1209 | #endif |
| 1210 | break; |
| 1211 | default: |
| 1212 | dev_err(&pdev->dev, "no ctag or stag present\n"); |
| 1213 | goto vlan_tag_error; |
| 1214 | } |
| 1215 | } else if (flags_transmit & EDMA_VLAN_TX_TAG_INSERT_DEFAULT_FLAG) { |
| 1216 | word3 |= (1 << EDMA_TX_INS_CVLAN); |
| 1217 | word3 |= (adapter->default_vlan_tag) << EDMA_TX_CVLAN_TAG_SHIFT; |
| 1218 | } |
| 1219 | |
| 1220 | if (packet_is_rstp) { |
| 1221 | word3 |= dp_bitmap << EDMA_TPD_PORT_BITMAP_SHIFT; |
| 1222 | word3 |= from_cpu << EDMA_TPD_FROM_CPU_SHIFT; |
| 1223 | } else { |
| 1224 | word3 |= adapter->dp_bitmap << EDMA_TPD_PORT_BITMAP_SHIFT; |
| 1225 | } |
| 1226 | |
| 1227 | buf_len = skb_headlen(skb); |
| 1228 | |
| 1229 | if (lso_word1) { |
| 1230 | if (lso_word1 & EDMA_TPD_LSO_V2_EN) { |
| 1231 | |
| 1232 | /* IPv6 LSOv2 descriptor */ |
| 1233 | start_tpd = tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1234 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1235 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_NONE; |
| 1236 | |
| 1237 | /* LSOv2 descriptor overrides addr field to pass length */ |
| 1238 | tpd->addr = cpu_to_le16(skb->len); |
| 1239 | tpd->svlan_tag = svlan_tag; |
| 1240 | tpd->word1 = word1 | lso_word1; |
| 1241 | tpd->word3 = word3; |
| 1242 | } |
| 1243 | |
| 1244 | tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1245 | if (!start_tpd) |
| 1246 | start_tpd = tpd; |
| 1247 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1248 | |
| 1249 | /* The last buffer info contain the skb address, |
| 1250 | * so skb will be freed after unmap |
| 1251 | */ |
| 1252 | sw_desc->length = lso_desc_len; |
| 1253 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD; |
| 1254 | |
| 1255 | sw_desc->dma = dma_map_single(&adapter->pdev->dev, |
| 1256 | skb->data, buf_len, DMA_TO_DEVICE); |
| 1257 | if (dma_mapping_error(&pdev->dev, sw_desc->dma)) |
| 1258 | goto dma_error; |
| 1259 | |
| 1260 | tpd->addr = cpu_to_le32(sw_desc->dma); |
| 1261 | tpd->len = cpu_to_le16(buf_len); |
| 1262 | |
| 1263 | tpd->svlan_tag = svlan_tag; |
| 1264 | tpd->word1 = word1 | lso_word1; |
| 1265 | tpd->word3 = word3; |
| 1266 | |
| 1267 | /* The last buffer info contain the skb address, |
| 1268 | * so it will be freed after unmap |
| 1269 | */ |
| 1270 | sw_desc->length = lso_desc_len; |
| 1271 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD; |
| 1272 | |
| 1273 | buf_len = 0; |
| 1274 | } |
| 1275 | |
| 1276 | if (likely(buf_len)) { |
| 1277 | |
| 1278 | /* TODO Do not dequeue descriptor if there is a potential error */ |
| 1279 | tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1280 | |
| 1281 | if (!start_tpd) |
| 1282 | start_tpd = tpd; |
| 1283 | |
| 1284 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1285 | |
| 1286 | /* The last buffer info contain the skb address, |
| 1287 | * so it will be free after unmap |
| 1288 | */ |
| 1289 | sw_desc->length = buf_len; |
| 1290 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD; |
| 1291 | sw_desc->dma = dma_map_single(&adapter->pdev->dev, |
| 1292 | skb->data, buf_len, DMA_TO_DEVICE); |
| 1293 | if (dma_mapping_error(&pdev->dev, sw_desc->dma)) |
| 1294 | goto dma_error; |
| 1295 | |
| 1296 | tpd->addr = cpu_to_le32(sw_desc->dma); |
| 1297 | tpd->len = cpu_to_le16(buf_len); |
| 1298 | |
| 1299 | tpd->svlan_tag = svlan_tag; |
| 1300 | tpd->word1 = word1 | lso_word1; |
| 1301 | tpd->word3 = word3; |
| 1302 | } |
| 1303 | |
| 1304 | i = 0; |
| 1305 | |
| 1306 | /* Walk through paged frags for head skb */ |
| 1307 | while (nr_frags--) { |
| 1308 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1309 | buf_len = skb_frag_size(frag); |
| 1310 | tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1311 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1312 | sw_desc->length = buf_len; |
| 1313 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_FRAG; |
| 1314 | |
| 1315 | sw_desc->dma = skb_frag_dma_map(&pdev->dev, frag, 0, buf_len, DMA_TO_DEVICE); |
| 1316 | |
| 1317 | if (dma_mapping_error(NULL, sw_desc->dma)) |
| 1318 | goto dma_error; |
| 1319 | |
| 1320 | tpd->addr = cpu_to_le32(sw_desc->dma); |
| 1321 | tpd->len = cpu_to_le16(buf_len); |
| 1322 | |
| 1323 | tpd->svlan_tag = svlan_tag; |
| 1324 | tpd->word1 = word1 | lso_word1; |
| 1325 | tpd->word3 = word3; |
| 1326 | i++; |
| 1327 | } |
| 1328 | |
| 1329 | /* Walk through all fraglist skbs */ |
| 1330 | skb_walk_frags(skb, iter_skb) { |
| 1331 | buf_len = iter_skb->len; |
| 1332 | tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1333 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1334 | sw_desc->length = buf_len; |
| 1335 | sw_desc->dma = dma_map_single(&adapter->pdev->dev, |
| 1336 | iter_skb->data, buf_len, DMA_TO_DEVICE); |
| 1337 | |
| 1338 | if (dma_mapping_error(NULL, sw_desc->dma)) |
| 1339 | goto dma_error; |
| 1340 | |
| 1341 | tpd->addr = cpu_to_le32(sw_desc->dma); |
| 1342 | tpd->len = cpu_to_le16(buf_len); |
| 1343 | tpd->svlan_tag = svlan_tag; |
| 1344 | tpd->word1 = word1 | lso_word1; |
| 1345 | tpd->word3 = word3; |
| 1346 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_FRAGLIST; |
| 1347 | |
| 1348 | i = 0; |
| 1349 | |
| 1350 | nr_frags = skb_shinfo(iter_skb)->nr_frags; |
| 1351 | |
| 1352 | /* Walk through paged frags for this fraglist skb */ |
| 1353 | while (nr_frags--) { |
| 1354 | skb_frag_t *frag = &skb_shinfo(iter_skb)->frags[i]; |
| 1355 | buf_len = skb_frag_size(frag); |
| 1356 | tpd = edma_get_next_tpd(edma_cinfo, queue_id); |
| 1357 | sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id); |
| 1358 | sw_desc->length = buf_len; |
| 1359 | sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_FRAG; |
| 1360 | |
| 1361 | sw_desc->dma = skb_frag_dma_map(&pdev->dev, frag, |
| 1362 | 0, buf_len, DMA_TO_DEVICE); |
| 1363 | if (dma_mapping_error(NULL, sw_desc->dma)) |
| 1364 | goto dma_error; |
| 1365 | |
| 1366 | tpd->addr = cpu_to_le32(sw_desc->dma); |
| 1367 | tpd->len = cpu_to_le16(buf_len); |
| 1368 | tpd->svlan_tag = svlan_tag; |
| 1369 | tpd->word1 = word1 | lso_word1; |
| 1370 | tpd->word3 = word3; |
| 1371 | i++; |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | /* If tpd or sw_desc is still unitiialized then we need to return */ |
| 1376 | if ((!tpd) || (!sw_desc)) |
| 1377 | return -EINVAL; |
| 1378 | |
| 1379 | tpd->word1 |= 1 << EDMA_TPD_EOP_SHIFT; |
| 1380 | |
| 1381 | sw_desc->skb = skb; |
| 1382 | sw_desc->flags |= EDMA_SW_DESC_FLAG_LAST; |
| 1383 | |
| 1384 | return 0; |
| 1385 | |
| 1386 | dma_error: |
| 1387 | edma_rollback_tx(adapter, start_tpd, queue_id); |
| 1388 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 1389 | vlan_tag_error: |
| 1390 | return -ENOMEM; |
| 1391 | } |
| 1392 | |
| 1393 | /* edma_check_link() |
| 1394 | * check Link status |
| 1395 | */ |
| 1396 | static int edma_check_link(struct edma_adapter *adapter) |
| 1397 | { |
| 1398 | struct phy_device *phydev = adapter->phydev; |
| 1399 | |
| 1400 | if (!(adapter->poll_required)) |
| 1401 | return __EDMA_LINKUP; |
| 1402 | |
| 1403 | if (phydev->link) |
| 1404 | return __EDMA_LINKUP; |
| 1405 | |
| 1406 | return __EDMA_LINKDOWN; |
| 1407 | } |
| 1408 | |
| 1409 | /* edma_adjust_link() |
| 1410 | * check for edma link status |
| 1411 | */ |
| 1412 | void edma_adjust_link(struct net_device *netdev) |
| 1413 | { |
| 1414 | int status; |
| 1415 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 1416 | struct phy_device *phydev = adapter->phydev; |
| 1417 | |
| 1418 | if (!test_bit(__EDMA_UP, &adapter->state_flags)) |
| 1419 | return; |
| 1420 | |
| 1421 | status = edma_check_link(adapter); |
| 1422 | |
| 1423 | if (status == __EDMA_LINKUP && adapter->link_state == __EDMA_LINKDOWN) { |
| 1424 | dev_info(&adapter->pdev->dev, "%s: GMAC Link is up with phy_speed=%d\n", netdev->name, phydev->speed); |
| 1425 | adapter->link_state = __EDMA_LINKUP; |
| 1426 | netif_carrier_on(netdev); |
| 1427 | if (netif_running(netdev)) |
| 1428 | netif_tx_wake_all_queues(netdev); |
| 1429 | } else if (status == __EDMA_LINKDOWN && adapter->link_state == __EDMA_LINKUP) { |
| 1430 | dev_info(&adapter->pdev->dev, "%s: GMAC Link is down\n", netdev->name); |
| 1431 | adapter->link_state = __EDMA_LINKDOWN; |
| 1432 | netif_carrier_off(netdev); |
| 1433 | netif_tx_stop_all_queues(netdev); |
| 1434 | } |
| 1435 | } |
| 1436 | |
Bhaskar Valaboju | e429bab | 2017-03-15 09:01:23 +0530 | [diff] [blame] | 1437 | /* edma_get_stats64() |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 1438 | * Statistics api used to retreive the tx/rx statistics |
| 1439 | */ |
Bhaskar Valaboju | e429bab | 2017-03-15 09:01:23 +0530 | [diff] [blame] | 1440 | struct rtnl_link_stats64 *edma_get_stats64(struct net_device *netdev, |
| 1441 | struct rtnl_link_stats64 *stats) |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 1442 | { |
| 1443 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 1444 | |
Bhaskar Valaboju | e429bab | 2017-03-15 09:01:23 +0530 | [diff] [blame] | 1445 | memcpy(stats, &adapter->stats, sizeof(*stats)); |
| 1446 | |
| 1447 | return stats; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /* edma_xmit() |
| 1451 | * Main api to be called by the core for packet transmission |
| 1452 | */ |
| 1453 | netdev_tx_t edma_xmit(struct sk_buff *skb, |
| 1454 | struct net_device *net_dev) |
| 1455 | { |
| 1456 | struct edma_adapter *adapter = netdev_priv(net_dev); |
| 1457 | struct edma_common_info *edma_cinfo = adapter->edma_cinfo; |
| 1458 | struct edma_tx_desc_ring *etdr; |
| 1459 | u16 from_cpu = 0, dp_bitmap = 0, txq_id; |
| 1460 | int ret, nr_frags_first = 0, num_tpds_needed = 1, queue_id = 0; |
| 1461 | unsigned int flags_transmit = 0; |
| 1462 | bool packet_is_rstp = false; |
| 1463 | struct netdev_queue *nq = NULL; |
| 1464 | |
| 1465 | if (skb_shinfo(skb)->nr_frags) { |
| 1466 | nr_frags_first = skb_shinfo(skb)->nr_frags; |
| 1467 | |
| 1468 | /* It is unlikely below check hits, BUG_ON */ |
| 1469 | BUG_ON(nr_frags_first > MAX_SKB_FRAGS); |
| 1470 | |
| 1471 | num_tpds_needed += nr_frags_first; |
| 1472 | } |
| 1473 | |
| 1474 | if (skb_has_frag_list(skb)) { |
| 1475 | struct sk_buff *iter_skb; |
| 1476 | |
| 1477 | /* Walk through fraglist skbs making a note of nr_frags */ |
| 1478 | skb_walk_frags(skb, iter_skb) { |
| 1479 | unsigned char nr_frags = skb_shinfo(iter_skb)->nr_frags; |
| 1480 | |
| 1481 | /* It is unlikely below check hits, BUG_ON */ |
| 1482 | BUG_ON(nr_frags > MAX_SKB_FRAGS); |
| 1483 | |
| 1484 | /* One TPD for skb->data and more for nr_frags */ |
| 1485 | num_tpds_needed += (1 + nr_frags); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | if (edma_stp_rstp) { |
| 1490 | u16 ath_hdr, ath_eth_type; |
| 1491 | u8 mac_addr[EDMA_ETH_HDR_LEN]; |
| 1492 | ath_eth_type = ntohs(*(uint16_t *)&skb->data[12]); |
| 1493 | if (ath_eth_type == edma_ath_eth_type) { |
| 1494 | packet_is_rstp = true; |
| 1495 | ath_hdr = htons(*(uint16_t *)&skb->data[14]); |
| 1496 | dp_bitmap = ath_hdr & EDMA_TX_ATH_HDR_PORT_BITMAP_MASK; |
| 1497 | from_cpu = (ath_hdr & EDMA_TX_ATH_HDR_FROM_CPU_MASK) >> EDMA_TX_ATH_HDR_FROM_CPU_SHIFT; |
| 1498 | memcpy(mac_addr, skb->data, EDMA_ETH_HDR_LEN); |
| 1499 | |
| 1500 | skb_pull(skb, 4); |
| 1501 | |
| 1502 | memcpy(skb->data, mac_addr, EDMA_ETH_HDR_LEN); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | /* this will be one of the 4 TX queues exposed to linux kernel */ |
| 1507 | txq_id = skb_get_queue_mapping(skb); |
| 1508 | queue_id = edma_tx_queue_get(adapter, skb, txq_id); |
| 1509 | etdr = edma_cinfo->tpd_ring[queue_id]; |
| 1510 | nq = netdev_get_tx_queue(net_dev, txq_id); |
| 1511 | |
| 1512 | local_bh_disable(); |
| 1513 | /* Tx is not handled in bottom half context. Hence, we need to protect |
| 1514 | * Tx from tasks and bottom half |
| 1515 | */ |
| 1516 | |
| 1517 | if (num_tpds_needed > edma_tpd_available(edma_cinfo, queue_id)) { |
| 1518 | /* not enough descriptor, just stop queue */ |
| 1519 | netif_tx_stop_queue(nq); |
| 1520 | local_bh_enable(); |
| 1521 | dev_dbg(&net_dev->dev, "Not enough descriptors available"); |
| 1522 | edma_cinfo->edma_ethstats.tx_desc_error++; |
| 1523 | return NETDEV_TX_BUSY; |
| 1524 | } |
| 1525 | |
| 1526 | /* Check and mark VLAN tag offload */ |
| 1527 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 1528 | if (vlan_tx_tag_present(skb)) |
| 1529 | #else |
| 1530 | if (skb_vlan_tag_present(skb)) |
| 1531 | #endif |
| 1532 | flags_transmit |= EDMA_VLAN_TX_TAG_INSERT_FLAG; |
| 1533 | else if (adapter->default_vlan_tag) |
| 1534 | flags_transmit |= EDMA_VLAN_TX_TAG_INSERT_DEFAULT_FLAG; |
| 1535 | |
| 1536 | /* Check and mark checksum offload */ |
| 1537 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) |
| 1538 | flags_transmit |= EDMA_HW_CHECKSUM; |
| 1539 | |
| 1540 | /* Map and fill descriptor for Tx */ |
| 1541 | ret = edma_tx_map_and_fill(edma_cinfo, adapter, skb, queue_id, |
| 1542 | flags_transmit, from_cpu, dp_bitmap, |
| 1543 | packet_is_rstp, nr_frags_first); |
| 1544 | if (ret) { |
| 1545 | dev_kfree_skb_any(skb); |
| 1546 | adapter->stats.tx_errors++; |
| 1547 | goto netdev_okay; |
| 1548 | } |
| 1549 | |
| 1550 | /* Update SW producer index */ |
| 1551 | edma_tx_update_hw_idx(edma_cinfo, skb, queue_id); |
| 1552 | |
| 1553 | /* update tx statistics */ |
| 1554 | adapter->stats.tx_packets++; |
| 1555 | adapter->stats.tx_bytes += skb->len; |
| 1556 | |
| 1557 | netdev_okay: |
| 1558 | local_bh_enable(); |
| 1559 | return NETDEV_TX_OK; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | * edma_flow_may_expire() |
| 1564 | * Timer function called periodically to delete the node |
| 1565 | */ |
| 1566 | void edma_flow_may_expire(unsigned long data) |
| 1567 | { |
| 1568 | struct edma_adapter *adapter = (struct edma_adapter *)data; |
| 1569 | int j; |
| 1570 | |
| 1571 | spin_lock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1572 | for (j = 0; j < EDMA_RFS_EXPIRE_COUNT_PER_CALL; j++) { |
| 1573 | struct hlist_head *hhead; |
| 1574 | struct hlist_node *tmp; |
| 1575 | struct edma_rfs_filter_node *n; |
| 1576 | bool res; |
| 1577 | |
| 1578 | hhead = &adapter->rfs.hlist_head[adapter->rfs.hashtoclean++]; |
| 1579 | hlist_for_each_entry_safe(n, tmp, hhead, node) { |
| 1580 | res = rps_may_expire_flow(adapter->netdev, n->rq_id, |
| 1581 | n->flow_id, n->filter_id); |
| 1582 | if (res) { |
| 1583 | res = edma_delete_rfs_filter(adapter, n); |
| 1584 | if (res < 0) |
| 1585 | dev_dbg(&adapter->netdev->dev, |
| 1586 | "RFS entry %d not allowed to be flushed by Switch", |
| 1587 | n->flow_id); |
| 1588 | else { |
| 1589 | hlist_del(&n->node); |
| 1590 | kfree(n); |
| 1591 | adapter->rfs.filter_available++; |
| 1592 | } |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | adapter->rfs.hashtoclean = adapter->rfs.hashtoclean & (EDMA_RFS_FLOW_ENTRIES - 1); |
| 1598 | spin_unlock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1599 | mod_timer(&adapter->rfs.expire_rfs, jiffies + HZ/4); |
| 1600 | } |
| 1601 | |
| 1602 | /* edma_rx_flow_steer() |
| 1603 | * Called by core to to steer the flow to CPU |
| 1604 | */ |
| 1605 | int edma_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, |
| 1606 | u16 rxq, u32 flow_id) |
| 1607 | { |
| 1608 | struct flow_keys keys; |
| 1609 | struct edma_rfs_filter_node *filter_node; |
| 1610 | struct edma_adapter *adapter = netdev_priv(dev); |
| 1611 | u16 hash_tblid; |
| 1612 | int res; |
| 1613 | |
| 1614 | if (skb->protocol == htons(ETH_P_IPV6)) { |
| 1615 | res = -EPROTONOSUPPORT; |
| 1616 | goto no_protocol_err; |
| 1617 | } |
| 1618 | |
| 1619 | /* Dissect flow parameters |
| 1620 | * We only support IPv4 + TCP/UDP |
| 1621 | */ |
| 1622 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 1623 | res = skb_flow_dissect(skb, &keys); |
| 1624 | if (!((keys.ip_proto == IPPROTO_TCP) || (keys.ip_proto == IPPROTO_UDP))) { |
| 1625 | #else |
| 1626 | res = skb_flow_dissect_flow_keys(skb, &keys, 0); |
| 1627 | if (!((keys.basic.ip_proto == IPPROTO_TCP) || (keys.basic.ip_proto == IPPROTO_UDP))) { |
| 1628 | #endif |
| 1629 | res = -EPROTONOSUPPORT; |
| 1630 | goto no_protocol_err; |
| 1631 | } |
| 1632 | |
| 1633 | /* Check if table entry exists */ |
| 1634 | hash_tblid = skb_get_hash_raw(skb) & EDMA_RFS_FLOW_ENTRIES_MASK; |
| 1635 | |
| 1636 | spin_lock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1637 | filter_node = edma_rfs_key_search(&adapter->rfs.hlist_head[hash_tblid], &keys); |
| 1638 | |
| 1639 | if (filter_node) { |
| 1640 | if (rxq == filter_node->rq_id) { |
| 1641 | res = -EEXIST; |
| 1642 | goto out; |
| 1643 | } else { |
| 1644 | res = edma_delete_rfs_filter(adapter, filter_node); |
| 1645 | if (res < 0) |
| 1646 | dev_warn(&adapter->netdev->dev, |
| 1647 | "Cannot steer flow %d to different queue", |
| 1648 | filter_node->flow_id); |
| 1649 | else { |
| 1650 | adapter->rfs.filter_available++; |
| 1651 | res = edma_add_rfs_filter(adapter, &keys, rxq, filter_node); |
| 1652 | if (res < 0) { |
| 1653 | dev_warn(&adapter->netdev->dev, |
| 1654 | "Cannot steer flow %d to different queue", |
| 1655 | filter_node->flow_id); |
| 1656 | } else { |
| 1657 | adapter->rfs.filter_available--; |
| 1658 | filter_node->rq_id = rxq; |
| 1659 | filter_node->filter_id = res; |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | } else { |
| 1664 | if (adapter->rfs.filter_available == 0) { |
| 1665 | res = -EBUSY; |
| 1666 | goto out; |
| 1667 | } |
| 1668 | |
| 1669 | filter_node = kmalloc(sizeof(*filter_node), GFP_ATOMIC); |
| 1670 | if (!filter_node) { |
| 1671 | res = -ENOMEM; |
| 1672 | goto out; |
| 1673 | } |
| 1674 | |
| 1675 | res = edma_add_rfs_filter(adapter, &keys, rxq, filter_node); |
| 1676 | if (res < 0) { |
| 1677 | kfree(filter_node); |
| 1678 | goto out; |
| 1679 | } |
| 1680 | |
| 1681 | adapter->rfs.filter_available--; |
| 1682 | filter_node->rq_id = rxq; |
| 1683 | filter_node->filter_id = res; |
| 1684 | filter_node->flow_id = flow_id; |
| 1685 | filter_node->keys = keys; |
| 1686 | INIT_HLIST_NODE(&filter_node->node); |
| 1687 | hlist_add_head(&filter_node->node, &adapter->rfs.hlist_head[hash_tblid]); |
| 1688 | } |
| 1689 | |
| 1690 | out: |
| 1691 | spin_unlock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1692 | no_protocol_err: |
| 1693 | return res; |
| 1694 | } |
| 1695 | |
| 1696 | #ifdef CONFIG_RFS_ACCEL |
| 1697 | /* edma_register_rfs_filter() |
| 1698 | * Add RFS filter callback |
| 1699 | */ |
| 1700 | int edma_register_rfs_filter(struct net_device *netdev, |
| 1701 | set_rfs_filter_callback_t set_filter) |
| 1702 | { |
| 1703 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 1704 | |
| 1705 | spin_lock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1706 | |
| 1707 | if (adapter->set_rfs_rule) { |
| 1708 | spin_unlock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1709 | return -1; |
| 1710 | } |
| 1711 | |
| 1712 | adapter->set_rfs_rule = set_filter; |
| 1713 | spin_unlock_bh(&adapter->rfs.rfs_ftab_lock); |
| 1714 | |
| 1715 | return 0; |
| 1716 | } |
| 1717 | #endif |
| 1718 | |
| 1719 | /* edma_select_xps_queue() |
| 1720 | * Called by Linux TX stack to populate Linux TX queue |
| 1721 | */ |
| 1722 | u16 edma_select_xps_queue(struct net_device *dev, struct sk_buff *skb, |
| 1723 | void *accel_priv, select_queue_fallback_t fallback) |
| 1724 | { |
| 1725 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 18, 21)) |
| 1726 | return smp_processor_id(); |
| 1727 | #else |
| 1728 | int cpu = get_cpu(); |
| 1729 | put_cpu(); |
| 1730 | |
| 1731 | return cpu; |
| 1732 | #endif |
| 1733 | } |
| 1734 | |
| 1735 | /* edma_alloc_tx_rings() |
| 1736 | * Allocate rx rings |
| 1737 | */ |
| 1738 | int edma_alloc_tx_rings(struct edma_common_info *edma_cinfo) |
| 1739 | { |
| 1740 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1741 | int i, err = 0; |
| 1742 | |
| 1743 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) { |
| 1744 | err = edma_alloc_tx_ring(edma_cinfo, edma_cinfo->tpd_ring[i]); |
| 1745 | if (err) { |
| 1746 | dev_err(&pdev->dev, "Tx Queue alloc %u failed\n", i); |
| 1747 | return err; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
| 1754 | /* edma_free_tx_rings() |
| 1755 | * Free tx rings |
| 1756 | */ |
| 1757 | void edma_free_tx_rings(struct edma_common_info *edma_cinfo) |
| 1758 | { |
| 1759 | int i; |
| 1760 | |
| 1761 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) |
| 1762 | edma_free_tx_ring(edma_cinfo, edma_cinfo->tpd_ring[i]); |
| 1763 | } |
| 1764 | |
| 1765 | /* edma_free_tx_resources() |
| 1766 | * Free buffers associated with tx rings |
| 1767 | */ |
| 1768 | void edma_free_tx_resources(struct edma_common_info *edma_cinfo) |
| 1769 | { |
| 1770 | struct edma_tx_desc_ring *etdr; |
| 1771 | struct edma_sw_desc *sw_desc; |
| 1772 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1773 | int i, j; |
| 1774 | |
| 1775 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) { |
| 1776 | etdr = edma_cinfo->tpd_ring[i]; |
| 1777 | for (j = 0; j < EDMA_TX_RING_SIZE; j++) { |
| 1778 | sw_desc = &etdr->sw_desc[j]; |
| 1779 | if (sw_desc->flags & (EDMA_SW_DESC_FLAG_SKB_HEAD | |
| 1780 | EDMA_SW_DESC_FLAG_SKB_FRAG | EDMA_SW_DESC_FLAG_SKB_FRAGLIST)) |
| 1781 | edma_tx_unmap_and_free(pdev, sw_desc); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | /* edma_alloc_rx_rings() |
| 1787 | * Allocate rx rings |
| 1788 | */ |
| 1789 | int edma_alloc_rx_rings(struct edma_common_info *edma_cinfo) |
| 1790 | { |
| 1791 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1792 | int i, j, err = 0; |
| 1793 | |
| 1794 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1795 | err = edma_alloc_rx_ring(edma_cinfo, edma_cinfo->rfd_ring[j]); |
| 1796 | if (err) { |
| 1797 | dev_err(&pdev->dev, "Rx Queue alloc%u failed\n", i); |
| 1798 | return err; |
| 1799 | } |
| 1800 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1801 | } |
| 1802 | |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | /* edma_free_rx_rings() |
| 1807 | * free rx rings |
| 1808 | */ |
| 1809 | void edma_free_rx_rings(struct edma_common_info *edma_cinfo) |
| 1810 | { |
| 1811 | int i, j; |
| 1812 | |
| 1813 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1814 | edma_free_rx_ring(edma_cinfo, edma_cinfo->rfd_ring[j]); |
| 1815 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | /* edma_free_queues() |
| 1820 | * Free the queues allocaated |
| 1821 | */ |
| 1822 | void edma_free_queues(struct edma_common_info *edma_cinfo) |
| 1823 | { |
| 1824 | int i , j; |
| 1825 | |
| 1826 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) { |
| 1827 | if (edma_cinfo->tpd_ring[i]) |
| 1828 | kfree(edma_cinfo->tpd_ring[i]); |
| 1829 | edma_cinfo->tpd_ring[i] = NULL; |
| 1830 | } |
| 1831 | |
| 1832 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1833 | if (edma_cinfo->rfd_ring[j]) |
| 1834 | kfree(edma_cinfo->rfd_ring[j]); |
| 1835 | edma_cinfo->rfd_ring[j] = NULL; |
| 1836 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1837 | } |
| 1838 | |
| 1839 | edma_cinfo->num_rx_queues = 0; |
| 1840 | edma_cinfo->num_tx_queues = 0; |
| 1841 | |
| 1842 | return; |
| 1843 | } |
| 1844 | |
| 1845 | /* edma_free_rx_resources() |
| 1846 | * Free buffers associated with tx rings |
| 1847 | */ |
| 1848 | void edma_free_rx_resources(struct edma_common_info *edma_cinfo) |
| 1849 | { |
| 1850 | struct edma_rfd_desc_ring *erdr; |
| 1851 | struct platform_device *pdev = edma_cinfo->pdev; |
| 1852 | int i, j, k; |
| 1853 | |
| 1854 | for (i = 0, k = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1855 | erdr = edma_cinfo->rfd_ring[k]; |
| 1856 | for (j = 0; j < EDMA_RX_RING_SIZE; j++) { |
| 1857 | /* unmap all descriptors while cleaning */ |
| 1858 | edma_clean_rfd(pdev, erdr, j, 1); |
| 1859 | } |
| 1860 | k += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1861 | |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | /* edma_alloc_queues_tx() |
| 1866 | * Allocate memory for all rings |
| 1867 | */ |
| 1868 | int edma_alloc_queues_tx(struct edma_common_info *edma_cinfo) |
| 1869 | { |
| 1870 | int i; |
| 1871 | |
| 1872 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) { |
| 1873 | struct edma_tx_desc_ring *etdr; |
| 1874 | etdr = kzalloc(sizeof(struct edma_tx_desc_ring), GFP_KERNEL); |
| 1875 | if (!etdr) |
| 1876 | goto err; |
| 1877 | etdr->count = edma_cinfo->tx_ring_count; |
| 1878 | edma_cinfo->tpd_ring[i] = etdr; |
| 1879 | } |
| 1880 | |
| 1881 | return 0; |
| 1882 | err: |
| 1883 | edma_free_queues(edma_cinfo); |
| 1884 | return -1; |
| 1885 | } |
| 1886 | |
| 1887 | /* edma_alloc_queues_rx() |
| 1888 | * Allocate memory for all rings |
| 1889 | */ |
| 1890 | int edma_alloc_queues_rx(struct edma_common_info *edma_cinfo) |
| 1891 | { |
| 1892 | int i, j; |
| 1893 | |
| 1894 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1895 | struct edma_rfd_desc_ring *rfd_ring; |
| 1896 | rfd_ring = kzalloc(sizeof(struct edma_rfd_desc_ring), |
| 1897 | GFP_KERNEL); |
| 1898 | if (!rfd_ring) |
| 1899 | goto err; |
| 1900 | rfd_ring->count = edma_cinfo->rx_ring_count; |
| 1901 | edma_cinfo->rfd_ring[j] = rfd_ring; |
| 1902 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1903 | } |
| 1904 | return 0; |
| 1905 | err: |
| 1906 | edma_free_queues(edma_cinfo); |
| 1907 | return -1; |
| 1908 | } |
| 1909 | |
| 1910 | /* edma_clear_irq_status() |
| 1911 | * Clear interrupt status |
| 1912 | */ |
| 1913 | void edma_clear_irq_status(void) |
| 1914 | { |
| 1915 | edma_write_reg(EDMA_REG_RX_ISR, 0xff); |
| 1916 | edma_write_reg(EDMA_REG_TX_ISR, 0xffff); |
| 1917 | edma_write_reg(EDMA_REG_MISC_ISR, 0x1fff); |
| 1918 | edma_write_reg(EDMA_REG_WOL_ISR, 0x1); |
| 1919 | }; |
| 1920 | |
| 1921 | /* edma_configure() |
| 1922 | * Configure skb, edma interrupts and control register. |
| 1923 | */ |
| 1924 | int edma_configure(struct edma_common_info *edma_cinfo) |
| 1925 | { |
| 1926 | struct edma_hw *hw = &edma_cinfo->hw; |
| 1927 | u32 intr_modrt_data; |
| 1928 | u32 intr_ctrl_data = 0; |
| 1929 | int i, j, ret_count; |
| 1930 | |
| 1931 | edma_read_reg(EDMA_REG_INTR_CTRL, &intr_ctrl_data); |
| 1932 | intr_ctrl_data &= ~(1 << EDMA_INTR_SW_IDX_W_TYP_SHIFT); |
| 1933 | intr_ctrl_data |= hw->intr_sw_idx_w << EDMA_INTR_SW_IDX_W_TYP_SHIFT; |
| 1934 | edma_write_reg(EDMA_REG_INTR_CTRL, intr_ctrl_data); |
| 1935 | |
| 1936 | edma_clear_irq_status(); |
| 1937 | |
| 1938 | /* Clear any WOL status */ |
| 1939 | edma_write_reg(EDMA_REG_WOL_CTRL, 0); |
| 1940 | intr_modrt_data = (EDMA_TX_IMT << EDMA_IRQ_MODRT_TX_TIMER_SHIFT); |
| 1941 | intr_modrt_data |= (EDMA_RX_IMT << EDMA_IRQ_MODRT_RX_TIMER_SHIFT); |
| 1942 | edma_write_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, intr_modrt_data); |
| 1943 | edma_configure_tx(edma_cinfo); |
| 1944 | edma_configure_rx(edma_cinfo); |
| 1945 | |
| 1946 | /* Allocate the RX buffer */ |
| 1947 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1948 | struct edma_rfd_desc_ring *ring = edma_cinfo->rfd_ring[j]; |
| 1949 | ret_count = edma_alloc_rx_buf(edma_cinfo, ring, ring->count, j); |
| 1950 | if (ret_count) |
| 1951 | dev_dbg(&edma_cinfo->pdev->dev, "not all rx buffers allocated\n"); |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 1952 | ring->pending_fill = ret_count; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 1953 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1954 | } |
| 1955 | |
| 1956 | /* Configure descriptor Ring */ |
| 1957 | edma_init_desc(edma_cinfo); |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
| 1961 | /* edma_irq_enable() |
| 1962 | * Enable default interrupt generation settings |
| 1963 | */ |
| 1964 | void edma_irq_enable(struct edma_common_info *edma_cinfo) |
| 1965 | { |
| 1966 | struct edma_hw *hw = &edma_cinfo->hw; |
| 1967 | int i, j; |
| 1968 | |
| 1969 | edma_write_reg(EDMA_REG_RX_ISR, 0xff); |
| 1970 | for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) { |
| 1971 | edma_write_reg(EDMA_REG_RX_INT_MASK_Q(j), hw->rx_intr_mask); |
| 1972 | j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1); |
| 1973 | } |
| 1974 | edma_write_reg(EDMA_REG_TX_ISR, 0xffff); |
| 1975 | for (i = 0; i < edma_cinfo->num_tx_queues; i++) |
| 1976 | edma_write_reg(EDMA_REG_TX_INT_MASK_Q(i), hw->tx_intr_mask); |
| 1977 | } |
| 1978 | |
| 1979 | /* edma_irq_disable() |
| 1980 | * Disable Interrupt |
| 1981 | */ |
| 1982 | void edma_irq_disable(struct edma_common_info *edma_cinfo) |
| 1983 | { |
| 1984 | int i; |
| 1985 | |
| 1986 | for (i = 0; i < EDMA_MAX_RECEIVE_QUEUE; i++) |
| 1987 | edma_write_reg(EDMA_REG_RX_INT_MASK_Q(i), 0x0); |
| 1988 | |
| 1989 | for (i = 0; i < EDMA_MAX_TRANSMIT_QUEUE; i++) |
| 1990 | edma_write_reg(EDMA_REG_TX_INT_MASK_Q(i), 0x0); |
| 1991 | edma_write_reg(EDMA_REG_MISC_IMR, 0); |
| 1992 | edma_write_reg(EDMA_REG_WOL_IMR, 0); |
| 1993 | } |
| 1994 | |
| 1995 | /* edma_free_irqs() |
| 1996 | * Free All IRQs |
| 1997 | */ |
| 1998 | void edma_free_irqs(struct edma_adapter *adapter) |
| 1999 | { |
| 2000 | struct edma_common_info *edma_cinfo = adapter->edma_cinfo; |
| 2001 | int i, j; |
| 2002 | int k = ((edma_cinfo->num_rx_queues == 4) ? 1 : 2); |
| 2003 | |
| 2004 | for (i = 0; i < CONFIG_NR_CPUS; i++) { |
| 2005 | for (j = edma_cinfo->edma_percpu_info[i].tx_start; j < (edma_cinfo->edma_percpu_info[i].tx_start + 4); j++) |
| 2006 | free_irq(edma_cinfo->tx_irq[j], &edma_cinfo->edma_percpu_info[i]); |
| 2007 | |
| 2008 | for (j = edma_cinfo->edma_percpu_info[i].rx_start; j < (edma_cinfo->edma_percpu_info[i].rx_start + k); j++) |
| 2009 | free_irq(edma_cinfo->rx_irq[j], &edma_cinfo->edma_percpu_info[i]); |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | /* edma_enable_rx_ctrl() |
| 2014 | * Enable RX queue control |
| 2015 | */ |
| 2016 | void edma_enable_rx_ctrl(struct edma_hw *hw) |
| 2017 | { |
| 2018 | u32 data; |
| 2019 | |
| 2020 | edma_read_reg(EDMA_REG_RXQ_CTRL, &data); |
| 2021 | data |= EDMA_RXQ_CTRL_EN; |
| 2022 | edma_write_reg(EDMA_REG_RXQ_CTRL, data); |
| 2023 | } |
| 2024 | |
| 2025 | |
| 2026 | /* edma_enable_tx_ctrl() |
| 2027 | * Enable TX queue control |
| 2028 | */ |
| 2029 | void edma_enable_tx_ctrl(struct edma_hw *hw) |
| 2030 | { |
| 2031 | u32 data; |
| 2032 | |
| 2033 | edma_read_reg(EDMA_REG_TXQ_CTRL, &data); |
| 2034 | data |= EDMA_TXQ_CTRL_TXQ_EN; |
| 2035 | edma_write_reg(EDMA_REG_TXQ_CTRL, data); |
| 2036 | } |
| 2037 | |
| 2038 | /* edma_stop_rx_tx() |
| 2039 | * Disable RX/TQ Queue control |
| 2040 | */ |
| 2041 | void edma_stop_rx_tx(struct edma_hw *hw) |
| 2042 | { |
| 2043 | u32 data; |
| 2044 | |
| 2045 | edma_read_reg(EDMA_REG_RXQ_CTRL, &data); |
| 2046 | data &= ~EDMA_RXQ_CTRL_EN; |
| 2047 | edma_write_reg(EDMA_REG_RXQ_CTRL, data); |
| 2048 | edma_read_reg(EDMA_REG_TXQ_CTRL, &data); |
| 2049 | data &= ~EDMA_TXQ_CTRL_TXQ_EN; |
| 2050 | edma_write_reg(EDMA_REG_TXQ_CTRL, data); |
| 2051 | } |
| 2052 | |
| 2053 | /* edma_reset() |
| 2054 | * Reset the EDMA |
| 2055 | */ |
| 2056 | int edma_reset(struct edma_common_info *edma_cinfo) |
| 2057 | { |
| 2058 | struct edma_hw *hw = &edma_cinfo->hw; |
| 2059 | |
| 2060 | edma_irq_disable(edma_cinfo); |
| 2061 | |
| 2062 | edma_clear_irq_status(); |
| 2063 | |
| 2064 | edma_stop_rx_tx(hw); |
| 2065 | |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
| 2069 | /* edma_fill_netdev() |
| 2070 | * Fill netdev for each etdr |
| 2071 | */ |
| 2072 | int edma_fill_netdev(struct edma_common_info *edma_cinfo, int queue_id, |
| 2073 | int dev, int txq_id) |
| 2074 | { |
| 2075 | struct edma_tx_desc_ring *etdr; |
| 2076 | int i = 0; |
| 2077 | |
| 2078 | etdr = edma_cinfo->tpd_ring[queue_id]; |
| 2079 | |
| 2080 | while (etdr->netdev[i]) |
| 2081 | i++; |
| 2082 | |
| 2083 | if (i >= EDMA_MAX_NETDEV_PER_QUEUE) |
| 2084 | return -1; |
| 2085 | |
| 2086 | /* Populate the netdev associated with the tpd ring */ |
| 2087 | etdr->netdev[i] = edma_netdev[dev]; |
| 2088 | etdr->nq[i] = netdev_get_tx_queue(edma_netdev[dev], txq_id); |
| 2089 | |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
| 2093 | /* edma_change_mtu() |
| 2094 | * change the MTU of the NIC. |
| 2095 | */ |
| 2096 | int edma_change_mtu(struct net_device *netdev, int new_mtu) |
| 2097 | { |
| 2098 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 2099 | struct edma_common_info *edma_cinfo = adapter->edma_cinfo; |
| 2100 | int old_mtu = netdev->mtu; |
| 2101 | int max_frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + (2 * VLAN_HLEN); |
| 2102 | |
| 2103 | if ((max_frame_size < ETH_ZLEN + ETH_FCS_LEN) || |
| 2104 | (max_frame_size > EDMA_MAX_JUMBO_FRAME_SIZE)) { |
| 2105 | dev_err(&edma_cinfo->pdev->dev, "MTU setting not correct\n"); |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | |
| 2109 | /* set MTU */ |
| 2110 | if (old_mtu != new_mtu) { |
| 2111 | netdev->mtu = new_mtu; |
| 2112 | netdev_update_features(netdev); |
| 2113 | } |
| 2114 | |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
| 2118 | /* edma_set_mac() |
| 2119 | * Change the Ethernet Address of the NIC |
| 2120 | */ |
| 2121 | int edma_set_mac_addr(struct net_device *netdev, void *p) |
| 2122 | { |
| 2123 | struct sockaddr *addr = p; |
| 2124 | |
| 2125 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2126 | return -EINVAL; |
| 2127 | |
| 2128 | if (netif_running(netdev)) |
| 2129 | return -EBUSY; |
| 2130 | |
| 2131 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
| 2135 | /* edma_set_stp_rstp() |
| 2136 | * set stp/rstp |
| 2137 | */ |
| 2138 | void edma_set_stp_rstp(bool rstp) |
| 2139 | { |
| 2140 | edma_stp_rstp = rstp; |
| 2141 | } |
| 2142 | |
| 2143 | /* edma_assign_ath_hdr_type() |
| 2144 | * assign atheros header eth type |
| 2145 | */ |
| 2146 | void edma_assign_ath_hdr_type(int eth_type) |
| 2147 | { |
| 2148 | edma_ath_eth_type = eth_type & EDMA_ETH_TYPE_MASK; |
| 2149 | } |
| 2150 | |
| 2151 | /* edma_get_default_vlan_tag() |
| 2152 | * Used by other modules to get the default vlan tag |
| 2153 | */ |
| 2154 | int edma_get_default_vlan_tag(struct net_device *netdev) |
| 2155 | { |
| 2156 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 2157 | |
| 2158 | if (adapter->default_vlan_tag) |
| 2159 | return adapter->default_vlan_tag; |
| 2160 | |
| 2161 | return 0; |
| 2162 | } |
| 2163 | |
| 2164 | /* edma_open() |
| 2165 | * gets called when netdevice is up, start the queue. |
| 2166 | */ |
| 2167 | int edma_open(struct net_device *netdev) |
| 2168 | { |
| 2169 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 2170 | struct platform_device *pdev = adapter->edma_cinfo->pdev; |
| 2171 | |
| 2172 | netif_tx_start_all_queues(netdev); |
| 2173 | edma_initialise_rfs_flow_table(adapter); |
| 2174 | set_bit(__EDMA_UP, &adapter->state_flags); |
| 2175 | |
| 2176 | /* if Link polling is enabled, in our case enabled for WAN, then |
| 2177 | * do a phy start, else always set link as UP |
| 2178 | */ |
Rakesh Nair | ed29f6b | 2017-04-04 15:48:08 +0530 | [diff] [blame] | 2179 | mutex_lock(&adapter->poll_mutex); |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2180 | if (adapter->poll_required) { |
| 2181 | if (!IS_ERR(adapter->phydev)) { |
| 2182 | phy_start(adapter->phydev); |
| 2183 | phy_start_aneg(adapter->phydev); |
| 2184 | adapter->link_state = __EDMA_LINKDOWN; |
| 2185 | } else { |
| 2186 | dev_dbg(&pdev->dev, "Invalid PHY device for a link polled interface\n"); |
| 2187 | } |
| 2188 | } else { |
| 2189 | adapter->link_state = __EDMA_LINKUP; |
| 2190 | netif_carrier_on(netdev); |
| 2191 | } |
Rakesh Nair | ed29f6b | 2017-04-04 15:48:08 +0530 | [diff] [blame] | 2192 | mutex_unlock(&adapter->poll_mutex); |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2193 | |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | /* edma_close() |
| 2199 | * gets called when netdevice is down, stops the queue. |
| 2200 | */ |
| 2201 | int edma_close(struct net_device *netdev) |
| 2202 | { |
| 2203 | struct edma_adapter *adapter = netdev_priv(netdev); |
| 2204 | |
| 2205 | edma_free_rfs_flow_table(adapter); |
| 2206 | netif_carrier_off(netdev); |
| 2207 | netif_tx_stop_all_queues(netdev); |
| 2208 | |
Rakesh Nair | ed29f6b | 2017-04-04 15:48:08 +0530 | [diff] [blame] | 2209 | mutex_lock(&adapter->poll_mutex); |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2210 | if (adapter->poll_required) { |
| 2211 | if (!IS_ERR(adapter->phydev)) |
| 2212 | phy_stop(adapter->phydev); |
| 2213 | } |
Rakesh Nair | ed29f6b | 2017-04-04 15:48:08 +0530 | [diff] [blame] | 2214 | mutex_unlock(&adapter->poll_mutex); |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2215 | |
| 2216 | adapter->link_state = __EDMA_LINKDOWN; |
| 2217 | |
| 2218 | /* Set GMAC state to UP before link state is checked |
| 2219 | */ |
| 2220 | clear_bit(__EDMA_UP, &adapter->state_flags); |
| 2221 | |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
| 2225 | /* edma_poll |
| 2226 | * polling function that gets called when the napi gets scheduled. |
| 2227 | * |
| 2228 | * Main sequence of task performed in this api |
| 2229 | * is clear irq status -> clear_tx_irq -> clean_rx_irq-> |
| 2230 | * enable interrupts. |
| 2231 | */ |
| 2232 | int edma_poll(struct napi_struct *napi, int budget) |
| 2233 | { |
| 2234 | struct edma_per_cpu_queues_info *edma_percpu_info = container_of(napi, |
| 2235 | struct edma_per_cpu_queues_info, napi); |
| 2236 | struct edma_common_info *edma_cinfo = edma_percpu_info->edma_cinfo; |
| 2237 | u32 reg_data; |
| 2238 | u32 shadow_rx_status, shadow_tx_status; |
| 2239 | int queue_id; |
| 2240 | int i, work_done = 0; |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 2241 | u16 rx_pending_fill; |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2242 | |
| 2243 | /* Store the Rx/Tx status by ANDing it with |
| 2244 | * appropriate CPU RX?TX mask |
| 2245 | */ |
| 2246 | edma_read_reg(EDMA_REG_RX_ISR, ®_data); |
| 2247 | edma_percpu_info->rx_status |= reg_data & edma_percpu_info->rx_mask; |
| 2248 | shadow_rx_status = edma_percpu_info->rx_status; |
| 2249 | edma_read_reg(EDMA_REG_TX_ISR, ®_data); |
| 2250 | edma_percpu_info->tx_status |= reg_data & edma_percpu_info->tx_mask; |
| 2251 | shadow_tx_status = edma_percpu_info->tx_status; |
| 2252 | |
| 2253 | /* Every core will have a start, which will be computed |
| 2254 | * in probe and stored in edma_percpu_info->tx_start variable. |
| 2255 | * We will shift the status bit by tx_start to obtain |
| 2256 | * status bits for the core on which the current processing |
| 2257 | * is happening. Since, there are 4 tx queues per core, |
| 2258 | * we will run the loop till we get the correct queue to clear. |
| 2259 | */ |
| 2260 | while (edma_percpu_info->tx_status) { |
| 2261 | queue_id = ffs(edma_percpu_info->tx_status) - 1; |
| 2262 | edma_tx_complete(edma_cinfo, queue_id); |
| 2263 | edma_percpu_info->tx_status &= ~(1 << queue_id); |
| 2264 | } |
| 2265 | |
| 2266 | /* Every core will have a start, which will be computed |
| 2267 | * in probe and stored in edma_percpu_info->tx_start variable. |
| 2268 | * We will shift the status bit by tx_start to obtain |
| 2269 | * status bits for the core on which the current processing |
| 2270 | * is happening. Since, there are 4 tx queues per core, we |
| 2271 | * will run the loop till we get the correct queue to clear. |
| 2272 | */ |
| 2273 | while (edma_percpu_info->rx_status) { |
| 2274 | queue_id = ffs(edma_percpu_info->rx_status) - 1; |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 2275 | rx_pending_fill = edma_rx_complete(edma_cinfo, &work_done, |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2276 | budget, queue_id, napi); |
| 2277 | |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 2278 | if (likely(work_done < budget)) { |
| 2279 | if (rx_pending_fill) { |
| 2280 | work_done = budget; |
| 2281 | break; |
| 2282 | } |
| 2283 | |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2284 | edma_percpu_info->rx_status &= ~(1 << queue_id); |
Rakesh Nair | 03b586c | 2017-04-03 18:28:58 +0530 | [diff] [blame] | 2285 | } |
Rakesh Nair | 9bcf260 | 2017-01-06 16:02:16 +0530 | [diff] [blame] | 2286 | else |
| 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | /* Clear the status register, to avoid the interrupts to |
| 2291 | * reoccur.This clearing of interrupt status register is |
| 2292 | * done here as writing to status register only takes place |
| 2293 | * once the producer/consumer index has been updated to |
| 2294 | * reflect that the packet transmission/reception went fine. |
| 2295 | */ |
| 2296 | edma_write_reg(EDMA_REG_RX_ISR, shadow_rx_status); |
| 2297 | edma_write_reg(EDMA_REG_TX_ISR, shadow_tx_status); |
| 2298 | |
| 2299 | /* If budget not fully consumed, exit the polling mode */ |
| 2300 | if (likely(work_done < budget)) { |
| 2301 | napi_complete(napi); |
| 2302 | |
| 2303 | /* re-enable the interrupts */ |
| 2304 | for (i = 0; i < edma_cinfo->num_rxq_per_core; i++) |
| 2305 | edma_write_reg(EDMA_REG_RX_INT_MASK_Q(edma_percpu_info->rx_start + i), 0x1); |
| 2306 | for (i = 0; i < edma_cinfo->num_txq_per_core; i++) |
| 2307 | edma_write_reg(EDMA_REG_TX_INT_MASK_Q(edma_percpu_info->tx_start + i), 0x1); |
| 2308 | } |
| 2309 | |
| 2310 | return work_done; |
| 2311 | } |
| 2312 | |
| 2313 | /* edma interrupt() |
| 2314 | * interrupt handler |
| 2315 | */ |
| 2316 | irqreturn_t edma_interrupt(int irq, void *dev) |
| 2317 | { |
| 2318 | struct edma_per_cpu_queues_info *edma_percpu_info = (struct edma_per_cpu_queues_info *) dev; |
| 2319 | struct edma_common_info *edma_cinfo = edma_percpu_info->edma_cinfo; |
| 2320 | int i; |
| 2321 | |
| 2322 | /* Unmask the TX/RX interrupt register */ |
| 2323 | for (i = 0; i < edma_cinfo->num_rxq_per_core; i++) |
| 2324 | edma_write_reg(EDMA_REG_RX_INT_MASK_Q(edma_percpu_info->rx_start + i), 0x0); |
| 2325 | |
| 2326 | for (i = 0; i < edma_cinfo->num_txq_per_core; i++) |
| 2327 | edma_write_reg(EDMA_REG_TX_INT_MASK_Q(edma_percpu_info->tx_start + i), 0x0); |
| 2328 | |
| 2329 | napi_schedule(&edma_percpu_info->napi); |
| 2330 | |
| 2331 | return IRQ_HANDLED; |
| 2332 | } |