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