.. | .. |
---|
2 | 2 | /* Copyright(c) 2013 - 2018 Intel Corporation. */ |
---|
3 | 3 | |
---|
4 | 4 | #include <linux/prefetch.h> |
---|
5 | | -#include <net/busy_poll.h> |
---|
6 | 5 | #include <linux/bpf_trace.h> |
---|
7 | 6 | #include <net/xdp.h> |
---|
8 | 7 | #include "i40e.h" |
---|
9 | 8 | #include "i40e_trace.h" |
---|
10 | 9 | #include "i40e_prototype.h" |
---|
11 | | - |
---|
12 | | -static inline __le64 build_ctob(u32 td_cmd, u32 td_offset, unsigned int size, |
---|
13 | | - u32 td_tag) |
---|
14 | | -{ |
---|
15 | | - return cpu_to_le64(I40E_TX_DESC_DTYPE_DATA | |
---|
16 | | - ((u64)td_cmd << I40E_TXD_QW1_CMD_SHIFT) | |
---|
17 | | - ((u64)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) | |
---|
18 | | - ((u64)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) | |
---|
19 | | - ((u64)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT)); |
---|
20 | | -} |
---|
| 10 | +#include "i40e_txrx_common.h" |
---|
| 11 | +#include "i40e_xsk.h" |
---|
21 | 12 | |
---|
22 | 13 | #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS) |
---|
23 | 14 | /** |
---|
.. | .. |
---|
530 | 521 | /** |
---|
531 | 522 | * i40e_fd_handle_status - check the Programming Status for FD |
---|
532 | 523 | * @rx_ring: the Rx ring for this descriptor |
---|
533 | | - * @rx_desc: the Rx descriptor for programming Status, not a packet descriptor. |
---|
| 524 | + * @qword0_raw: qword0 |
---|
| 525 | + * @qword1: qword1 after le_to_cpu |
---|
534 | 526 | * @prog_id: the id originally used for programming |
---|
535 | 527 | * |
---|
536 | 528 | * This is used to verify if the FD programming or invalidation |
---|
537 | 529 | * requested by SW to the HW is successful or not and take actions accordingly. |
---|
538 | 530 | **/ |
---|
539 | | -static void i40e_fd_handle_status(struct i40e_ring *rx_ring, |
---|
540 | | - union i40e_rx_desc *rx_desc, u8 prog_id) |
---|
| 531 | +static void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw, |
---|
| 532 | + u64 qword1, u8 prog_id) |
---|
541 | 533 | { |
---|
542 | 534 | struct i40e_pf *pf = rx_ring->vsi->back; |
---|
543 | 535 | struct pci_dev *pdev = pf->pdev; |
---|
| 536 | + struct i40e_16b_rx_wb_qw0 *qw0; |
---|
544 | 537 | u32 fcnt_prog, fcnt_avail; |
---|
545 | 538 | u32 error; |
---|
546 | | - u64 qw; |
---|
547 | 539 | |
---|
548 | | - qw = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
---|
549 | | - error = (qw & I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >> |
---|
| 540 | + qw0 = (struct i40e_16b_rx_wb_qw0 *)&qword0_raw; |
---|
| 541 | + error = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >> |
---|
550 | 542 | I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT; |
---|
551 | 543 | |
---|
552 | 544 | if (error == BIT(I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) { |
---|
553 | | - pf->fd_inv = le32_to_cpu(rx_desc->wb.qword0.hi_dword.fd_id); |
---|
554 | | - if ((rx_desc->wb.qword0.hi_dword.fd_id != 0) || |
---|
| 545 | + pf->fd_inv = le32_to_cpu(qw0->hi_dword.fd_id); |
---|
| 546 | + if (qw0->hi_dword.fd_id != 0 || |
---|
555 | 547 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
---|
556 | 548 | dev_warn(&pdev->dev, "ntuple filter loc = %d, could not be added\n", |
---|
557 | 549 | pf->fd_inv); |
---|
.. | .. |
---|
569 | 561 | /* store the current atr filter count */ |
---|
570 | 562 | pf->fd_atr_cnt = i40e_get_current_atr_cnt(pf); |
---|
571 | 563 | |
---|
572 | | - if ((rx_desc->wb.qword0.hi_dword.fd_id == 0) && |
---|
| 564 | + if (qw0->hi_dword.fd_id == 0 && |
---|
573 | 565 | test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state)) { |
---|
574 | 566 | /* These set_bit() calls aren't atomic with the |
---|
575 | 567 | * test_bit() here, but worse case we potentially |
---|
.. | .. |
---|
598 | 590 | } else if (error == BIT(I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) { |
---|
599 | 591 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
---|
600 | 592 | dev_info(&pdev->dev, "ntuple filter fd_id = %d, could not be removed\n", |
---|
601 | | - rx_desc->wb.qword0.hi_dword.fd_id); |
---|
| 593 | + qw0->hi_dword.fd_id); |
---|
602 | 594 | } |
---|
603 | 595 | } |
---|
604 | 596 | |
---|
.. | .. |
---|
644 | 636 | unsigned long bi_size; |
---|
645 | 637 | u16 i; |
---|
646 | 638 | |
---|
647 | | - /* ring already cleared, nothing to do */ |
---|
648 | | - if (!tx_ring->tx_bi) |
---|
649 | | - return; |
---|
| 639 | + if (ring_is_xdp(tx_ring) && tx_ring->xsk_pool) { |
---|
| 640 | + i40e_xsk_clean_tx_ring(tx_ring); |
---|
| 641 | + } else { |
---|
| 642 | + /* ring already cleared, nothing to do */ |
---|
| 643 | + if (!tx_ring->tx_bi) |
---|
| 644 | + return; |
---|
650 | 645 | |
---|
651 | | - /* Free all the Tx ring sk_buffs */ |
---|
652 | | - for (i = 0; i < tx_ring->count; i++) |
---|
653 | | - i40e_unmap_and_free_tx_resource(tx_ring, &tx_ring->tx_bi[i]); |
---|
| 646 | + /* Free all the Tx ring sk_buffs */ |
---|
| 647 | + for (i = 0; i < tx_ring->count; i++) |
---|
| 648 | + i40e_unmap_and_free_tx_resource(tx_ring, |
---|
| 649 | + &tx_ring->tx_bi[i]); |
---|
| 650 | + } |
---|
654 | 651 | |
---|
655 | 652 | bi_size = sizeof(struct i40e_tx_buffer) * tx_ring->count; |
---|
656 | 653 | memset(tx_ring->tx_bi, 0, bi_size); |
---|
.. | .. |
---|
767 | 764 | } |
---|
768 | 765 | } |
---|
769 | 766 | |
---|
770 | | -#define WB_STRIDE 4 |
---|
771 | | - |
---|
772 | 767 | /** |
---|
773 | 768 | * i40e_clean_tx_irq - Reclaim resources after transmit completes |
---|
774 | 769 | * @vsi: the VSI we care about |
---|
.. | .. |
---|
780 | 775 | static bool i40e_clean_tx_irq(struct i40e_vsi *vsi, |
---|
781 | 776 | struct i40e_ring *tx_ring, int napi_budget) |
---|
782 | 777 | { |
---|
783 | | - u16 i = tx_ring->next_to_clean; |
---|
| 778 | + int i = tx_ring->next_to_clean; |
---|
784 | 779 | struct i40e_tx_buffer *tx_buf; |
---|
785 | 780 | struct i40e_tx_desc *tx_head; |
---|
786 | 781 | struct i40e_tx_desc *tx_desc; |
---|
.. | .. |
---|
873 | 868 | |
---|
874 | 869 | i += tx_ring->count; |
---|
875 | 870 | tx_ring->next_to_clean = i; |
---|
876 | | - u64_stats_update_begin(&tx_ring->syncp); |
---|
877 | | - tx_ring->stats.bytes += total_bytes; |
---|
878 | | - tx_ring->stats.packets += total_packets; |
---|
879 | | - u64_stats_update_end(&tx_ring->syncp); |
---|
880 | | - tx_ring->q_vector->tx.total_bytes += total_bytes; |
---|
881 | | - tx_ring->q_vector->tx.total_packets += total_packets; |
---|
882 | | - |
---|
883 | | - if (tx_ring->flags & I40E_TXR_FLAGS_WB_ON_ITR) { |
---|
884 | | - /* check to see if there are < 4 descriptors |
---|
885 | | - * waiting to be written back, then kick the hardware to force |
---|
886 | | - * them to be written back in case we stay in NAPI. |
---|
887 | | - * In this mode on X722 we do not enable Interrupt. |
---|
888 | | - */ |
---|
889 | | - unsigned int j = i40e_get_tx_pending(tx_ring, false); |
---|
890 | | - |
---|
891 | | - if (budget && |
---|
892 | | - ((j / WB_STRIDE) == 0) && (j > 0) && |
---|
893 | | - !test_bit(__I40E_VSI_DOWN, vsi->state) && |
---|
894 | | - (I40E_DESC_UNUSED(tx_ring) != tx_ring->count)) |
---|
895 | | - tx_ring->arm_wb = true; |
---|
896 | | - } |
---|
| 871 | + i40e_update_tx_stats(tx_ring, total_packets, total_bytes); |
---|
| 872 | + i40e_arm_wb(tx_ring, vsi, budget); |
---|
897 | 873 | |
---|
898 | 874 | if (ring_is_xdp(tx_ring)) |
---|
899 | 875 | return !!budget; |
---|
.. | .. |
---|
1220 | 1196 | rc->total_packets = 0; |
---|
1221 | 1197 | } |
---|
1222 | 1198 | |
---|
| 1199 | +static struct i40e_rx_buffer *i40e_rx_bi(struct i40e_ring *rx_ring, u32 idx) |
---|
| 1200 | +{ |
---|
| 1201 | + return &rx_ring->rx_bi[idx]; |
---|
| 1202 | +} |
---|
| 1203 | + |
---|
1223 | 1204 | /** |
---|
1224 | 1205 | * i40e_reuse_rx_page - page flip buffer and store it back on the ring |
---|
1225 | 1206 | * @rx_ring: rx descriptor ring to store buffers on |
---|
.. | .. |
---|
1233 | 1214 | struct i40e_rx_buffer *new_buff; |
---|
1234 | 1215 | u16 nta = rx_ring->next_to_alloc; |
---|
1235 | 1216 | |
---|
1236 | | - new_buff = &rx_ring->rx_bi[nta]; |
---|
| 1217 | + new_buff = i40e_rx_bi(rx_ring, nta); |
---|
1237 | 1218 | |
---|
1238 | 1219 | /* update, and store next to alloc */ |
---|
1239 | 1220 | nta++; |
---|
.. | .. |
---|
1244 | 1225 | new_buff->page = old_buff->page; |
---|
1245 | 1226 | new_buff->page_offset = old_buff->page_offset; |
---|
1246 | 1227 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
---|
1247 | | -} |
---|
1248 | 1228 | |
---|
1249 | | -/** |
---|
1250 | | - * i40e_rx_is_programming_status - check for programming status descriptor |
---|
1251 | | - * @qw: qword representing status_error_len in CPU ordering |
---|
1252 | | - * |
---|
1253 | | - * The value of in the descriptor length field indicate if this |
---|
1254 | | - * is a programming status descriptor for flow director or FCoE |
---|
1255 | | - * by the value of I40E_RX_PROG_STATUS_DESC_LENGTH, otherwise |
---|
1256 | | - * it is a packet descriptor. |
---|
1257 | | - **/ |
---|
1258 | | -static inline bool i40e_rx_is_programming_status(u64 qw) |
---|
1259 | | -{ |
---|
1260 | | - /* The Rx filter programming status and SPH bit occupy the same |
---|
1261 | | - * spot in the descriptor. Since we don't support packet split we |
---|
1262 | | - * can just reuse the bit as an indication that this is a |
---|
1263 | | - * programming status descriptor. |
---|
1264 | | - */ |
---|
1265 | | - return qw & I40E_RXD_QW1_LENGTH_SPH_MASK; |
---|
| 1229 | + rx_ring->rx_stats.page_reuse_count++; |
---|
| 1230 | + |
---|
| 1231 | + /* clear contents of buffer_info */ |
---|
| 1232 | + old_buff->page = NULL; |
---|
1266 | 1233 | } |
---|
1267 | 1234 | |
---|
1268 | 1235 | /** |
---|
1269 | 1236 | * i40e_clean_programming_status - clean the programming status descriptor |
---|
1270 | 1237 | * @rx_ring: the rx ring that has this descriptor |
---|
1271 | | - * @rx_desc: the rx descriptor written back by HW |
---|
1272 | | - * @qw: qword representing status_error_len in CPU ordering |
---|
| 1238 | + * @qword0_raw: qword0 |
---|
| 1239 | + * @qword1: qword1 representing status_error_len in CPU ordering |
---|
1273 | 1240 | * |
---|
1274 | 1241 | * Flow director should handle FD_FILTER_STATUS to check its filter programming |
---|
1275 | 1242 | * status being successful or not and take actions accordingly. FCoE should |
---|
1276 | 1243 | * handle its context/filter programming/invalidation status and take actions. |
---|
1277 | 1244 | * |
---|
| 1245 | + * Returns an i40e_rx_buffer to reuse if the cleanup occurred, otherwise NULL. |
---|
1278 | 1246 | **/ |
---|
1279 | | -static void i40e_clean_programming_status(struct i40e_ring *rx_ring, |
---|
1280 | | - union i40e_rx_desc *rx_desc, |
---|
1281 | | - u64 qw) |
---|
| 1247 | +void i40e_clean_programming_status(struct i40e_ring *rx_ring, u64 qword0_raw, |
---|
| 1248 | + u64 qword1) |
---|
1282 | 1249 | { |
---|
1283 | | - struct i40e_rx_buffer *rx_buffer; |
---|
1284 | | - u32 ntc = rx_ring->next_to_clean; |
---|
1285 | 1250 | u8 id; |
---|
1286 | 1251 | |
---|
1287 | | - /* fetch, update, and store next to clean */ |
---|
1288 | | - rx_buffer = &rx_ring->rx_bi[ntc++]; |
---|
1289 | | - ntc = (ntc < rx_ring->count) ? ntc : 0; |
---|
1290 | | - rx_ring->next_to_clean = ntc; |
---|
1291 | | - |
---|
1292 | | - prefetch(I40E_RX_DESC(rx_ring, ntc)); |
---|
1293 | | - |
---|
1294 | | - /* place unused page back on the ring */ |
---|
1295 | | - i40e_reuse_rx_page(rx_ring, rx_buffer); |
---|
1296 | | - rx_ring->rx_stats.page_reuse_count++; |
---|
1297 | | - |
---|
1298 | | - /* clear contents of buffer_info */ |
---|
1299 | | - rx_buffer->page = NULL; |
---|
1300 | | - |
---|
1301 | | - id = (qw & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >> |
---|
| 1252 | + id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >> |
---|
1302 | 1253 | I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT; |
---|
1303 | 1254 | |
---|
1304 | 1255 | if (id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) |
---|
1305 | | - i40e_fd_handle_status(rx_ring, rx_desc, id); |
---|
| 1256 | + i40e_fd_handle_status(rx_ring, qword0_raw, qword1, id); |
---|
1306 | 1257 | } |
---|
1307 | 1258 | |
---|
1308 | 1259 | /** |
---|
.. | .. |
---|
1354 | 1305 | return -ENOMEM; |
---|
1355 | 1306 | } |
---|
1356 | 1307 | |
---|
| 1308 | +static void i40e_clear_rx_bi(struct i40e_ring *rx_ring) |
---|
| 1309 | +{ |
---|
| 1310 | + memset(rx_ring->rx_bi, 0, sizeof(*rx_ring->rx_bi) * rx_ring->count); |
---|
| 1311 | +} |
---|
| 1312 | + |
---|
1357 | 1313 | /** |
---|
1358 | 1314 | * i40e_clean_rx_ring - Free Rx buffers |
---|
1359 | 1315 | * @rx_ring: ring to be cleaned |
---|
1360 | 1316 | **/ |
---|
1361 | 1317 | void i40e_clean_rx_ring(struct i40e_ring *rx_ring) |
---|
1362 | 1318 | { |
---|
1363 | | - unsigned long bi_size; |
---|
1364 | 1319 | u16 i; |
---|
1365 | 1320 | |
---|
1366 | 1321 | /* ring already cleared, nothing to do */ |
---|
.. | .. |
---|
1372 | 1327 | rx_ring->skb = NULL; |
---|
1373 | 1328 | } |
---|
1374 | 1329 | |
---|
| 1330 | + if (rx_ring->xsk_pool) { |
---|
| 1331 | + i40e_xsk_clean_rx_ring(rx_ring); |
---|
| 1332 | + goto skip_free; |
---|
| 1333 | + } |
---|
| 1334 | + |
---|
1375 | 1335 | /* Free all the Rx ring sk_buffs */ |
---|
1376 | 1336 | for (i = 0; i < rx_ring->count; i++) { |
---|
1377 | | - struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i]; |
---|
| 1337 | + struct i40e_rx_buffer *rx_bi = i40e_rx_bi(rx_ring, i); |
---|
1378 | 1338 | |
---|
1379 | 1339 | if (!rx_bi->page) |
---|
1380 | 1340 | continue; |
---|
.. | .. |
---|
1400 | 1360 | rx_bi->page_offset = 0; |
---|
1401 | 1361 | } |
---|
1402 | 1362 | |
---|
1403 | | - bi_size = sizeof(struct i40e_rx_buffer) * rx_ring->count; |
---|
1404 | | - memset(rx_ring->rx_bi, 0, bi_size); |
---|
| 1363 | +skip_free: |
---|
| 1364 | + if (rx_ring->xsk_pool) |
---|
| 1365 | + i40e_clear_rx_bi_zc(rx_ring); |
---|
| 1366 | + else |
---|
| 1367 | + i40e_clear_rx_bi(rx_ring); |
---|
1405 | 1368 | |
---|
1406 | 1369 | /* Zero out the descriptor ring */ |
---|
1407 | 1370 | memset(rx_ring->desc, 0, rx_ring->size); |
---|
.. | .. |
---|
1442 | 1405 | int i40e_setup_rx_descriptors(struct i40e_ring *rx_ring) |
---|
1443 | 1406 | { |
---|
1444 | 1407 | struct device *dev = rx_ring->dev; |
---|
1445 | | - int err = -ENOMEM; |
---|
1446 | | - int bi_size; |
---|
1447 | | - |
---|
1448 | | - /* warn if we are about to overwrite the pointer */ |
---|
1449 | | - WARN_ON(rx_ring->rx_bi); |
---|
1450 | | - bi_size = sizeof(struct i40e_rx_buffer) * rx_ring->count; |
---|
1451 | | - rx_ring->rx_bi = kzalloc(bi_size, GFP_KERNEL); |
---|
1452 | | - if (!rx_ring->rx_bi) |
---|
1453 | | - goto err; |
---|
| 1408 | + int err; |
---|
1454 | 1409 | |
---|
1455 | 1410 | u64_stats_init(&rx_ring->syncp); |
---|
1456 | 1411 | |
---|
1457 | 1412 | /* Round up to nearest 4K */ |
---|
1458 | | - rx_ring->size = rx_ring->count * sizeof(union i40e_32byte_rx_desc); |
---|
| 1413 | + rx_ring->size = rx_ring->count * sizeof(union i40e_rx_desc); |
---|
1459 | 1414 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
---|
1460 | 1415 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
---|
1461 | 1416 | &rx_ring->dma, GFP_KERNEL); |
---|
.. | .. |
---|
1463 | 1418 | if (!rx_ring->desc) { |
---|
1464 | 1419 | dev_info(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n", |
---|
1465 | 1420 | rx_ring->size); |
---|
1466 | | - goto err; |
---|
| 1421 | + return -ENOMEM; |
---|
1467 | 1422 | } |
---|
1468 | 1423 | |
---|
1469 | 1424 | rx_ring->next_to_alloc = 0; |
---|
.. | .. |
---|
1475 | 1430 | err = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev, |
---|
1476 | 1431 | rx_ring->queue_index); |
---|
1477 | 1432 | if (err < 0) |
---|
1478 | | - goto err; |
---|
| 1433 | + return err; |
---|
1479 | 1434 | } |
---|
1480 | 1435 | |
---|
1481 | 1436 | rx_ring->xdp_prog = rx_ring->vsi->xdp_prog; |
---|
1482 | 1437 | |
---|
| 1438 | + rx_ring->rx_bi = |
---|
| 1439 | + kcalloc(rx_ring->count, sizeof(*rx_ring->rx_bi), GFP_KERNEL); |
---|
| 1440 | + if (!rx_ring->rx_bi) |
---|
| 1441 | + return -ENOMEM; |
---|
| 1442 | + |
---|
1483 | 1443 | return 0; |
---|
1484 | | -err: |
---|
1485 | | - kfree(rx_ring->rx_bi); |
---|
1486 | | - rx_ring->rx_bi = NULL; |
---|
1487 | | - return err; |
---|
1488 | 1444 | } |
---|
1489 | 1445 | |
---|
1490 | 1446 | /** |
---|
.. | .. |
---|
1492 | 1448 | * @rx_ring: ring to bump |
---|
1493 | 1449 | * @val: new head index |
---|
1494 | 1450 | **/ |
---|
1495 | | -static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
---|
| 1451 | +void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
---|
1496 | 1452 | { |
---|
1497 | 1453 | rx_ring->next_to_use = val; |
---|
1498 | 1454 | |
---|
.. | .. |
---|
1517 | 1473 | static inline unsigned int i40e_rx_offset(struct i40e_ring *rx_ring) |
---|
1518 | 1474 | { |
---|
1519 | 1475 | return ring_uses_build_skb(rx_ring) ? I40E_SKB_PAD : 0; |
---|
| 1476 | +} |
---|
| 1477 | + |
---|
| 1478 | +static unsigned int i40e_rx_frame_truesize(struct i40e_ring *rx_ring, |
---|
| 1479 | + unsigned int size) |
---|
| 1480 | +{ |
---|
| 1481 | + unsigned int truesize; |
---|
| 1482 | + |
---|
| 1483 | +#if (PAGE_SIZE < 8192) |
---|
| 1484 | + truesize = i40e_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */ |
---|
| 1485 | +#else |
---|
| 1486 | + truesize = i40e_rx_offset(rx_ring) ? |
---|
| 1487 | + SKB_DATA_ALIGN(size + i40e_rx_offset(rx_ring)) + |
---|
| 1488 | + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : |
---|
| 1489 | + SKB_DATA_ALIGN(size); |
---|
| 1490 | +#endif |
---|
| 1491 | + return truesize; |
---|
1520 | 1492 | } |
---|
1521 | 1493 | |
---|
1522 | 1494 | /** |
---|
.. | .. |
---|
1571 | 1543 | } |
---|
1572 | 1544 | |
---|
1573 | 1545 | /** |
---|
1574 | | - * i40e_receive_skb - Send a completed packet up the stack |
---|
1575 | | - * @rx_ring: rx ring in play |
---|
1576 | | - * @skb: packet to send up |
---|
1577 | | - * @vlan_tag: vlan tag for packet |
---|
1578 | | - **/ |
---|
1579 | | -static void i40e_receive_skb(struct i40e_ring *rx_ring, |
---|
1580 | | - struct sk_buff *skb, u16 vlan_tag) |
---|
1581 | | -{ |
---|
1582 | | - struct i40e_q_vector *q_vector = rx_ring->q_vector; |
---|
1583 | | - |
---|
1584 | | - if ((rx_ring->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
---|
1585 | | - (vlan_tag & VLAN_VID_MASK)) |
---|
1586 | | - __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag); |
---|
1587 | | - |
---|
1588 | | - napi_gro_receive(&q_vector->napi, skb); |
---|
1589 | | -} |
---|
1590 | | - |
---|
1591 | | -/** |
---|
1592 | 1546 | * i40e_alloc_rx_buffers - Replace used receive buffers |
---|
1593 | 1547 | * @rx_ring: ring to place buffers on |
---|
1594 | 1548 | * @cleaned_count: number of buffers to replace |
---|
.. | .. |
---|
1606 | 1560 | return false; |
---|
1607 | 1561 | |
---|
1608 | 1562 | rx_desc = I40E_RX_DESC(rx_ring, ntu); |
---|
1609 | | - bi = &rx_ring->rx_bi[ntu]; |
---|
| 1563 | + bi = i40e_rx_bi(rx_ring, ntu); |
---|
1610 | 1564 | |
---|
1611 | 1565 | do { |
---|
1612 | 1566 | if (!i40e_alloc_mapped_page(rx_ring, bi)) |
---|
.. | .. |
---|
1628 | 1582 | ntu++; |
---|
1629 | 1583 | if (unlikely(ntu == rx_ring->count)) { |
---|
1630 | 1584 | rx_desc = I40E_RX_DESC(rx_ring, 0); |
---|
1631 | | - bi = rx_ring->rx_bi; |
---|
| 1585 | + bi = i40e_rx_bi(rx_ring, 0); |
---|
1632 | 1586 | ntu = 0; |
---|
1633 | 1587 | } |
---|
1634 | 1588 | |
---|
.. | .. |
---|
1733 | 1687 | case I40E_RX_PTYPE_INNER_PROT_UDP: |
---|
1734 | 1688 | case I40E_RX_PTYPE_INNER_PROT_SCTP: |
---|
1735 | 1689 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
---|
1736 | | - /* fall though */ |
---|
| 1690 | + fallthrough; |
---|
1737 | 1691 | default: |
---|
1738 | 1692 | break; |
---|
1739 | 1693 | } |
---|
.. | .. |
---|
1798 | 1752 | * @rx_ring: rx descriptor ring packet is being transacted on |
---|
1799 | 1753 | * @rx_desc: pointer to the EOP Rx descriptor |
---|
1800 | 1754 | * @skb: pointer to current skb being populated |
---|
1801 | | - * @rx_ptype: the packet type decoded by hardware |
---|
1802 | 1755 | * |
---|
1803 | 1756 | * This function checks the ring, descriptor, and packet information in |
---|
1804 | 1757 | * order to populate the hash, checksum, VLAN, protocol, and |
---|
1805 | 1758 | * other fields within the skb. |
---|
1806 | 1759 | **/ |
---|
1807 | | -static inline |
---|
1808 | 1760 | void i40e_process_skb_fields(struct i40e_ring *rx_ring, |
---|
1809 | | - union i40e_rx_desc *rx_desc, struct sk_buff *skb, |
---|
1810 | | - u8 rx_ptype) |
---|
| 1761 | + union i40e_rx_desc *rx_desc, struct sk_buff *skb) |
---|
1811 | 1762 | { |
---|
1812 | 1763 | u64 qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
---|
1813 | 1764 | u32 rx_status = (qword & I40E_RXD_QW1_STATUS_MASK) >> |
---|
.. | .. |
---|
1815 | 1766 | u32 tsynvalid = rx_status & I40E_RXD_QW1_STATUS_TSYNVALID_MASK; |
---|
1816 | 1767 | u32 tsyn = (rx_status & I40E_RXD_QW1_STATUS_TSYNINDX_MASK) >> |
---|
1817 | 1768 | I40E_RXD_QW1_STATUS_TSYNINDX_SHIFT; |
---|
| 1769 | + u8 rx_ptype = (qword & I40E_RXD_QW1_PTYPE_MASK) >> |
---|
| 1770 | + I40E_RXD_QW1_PTYPE_SHIFT; |
---|
1818 | 1771 | |
---|
1819 | 1772 | if (unlikely(tsynvalid)) |
---|
1820 | 1773 | i40e_ptp_rx_hwtstamp(rx_ring->vsi->back, skb, tsyn); |
---|
.. | .. |
---|
1824 | 1777 | i40e_rx_checksum(rx_ring->vsi, skb, rx_desc); |
---|
1825 | 1778 | |
---|
1826 | 1779 | skb_record_rx_queue(skb, rx_ring->queue_index); |
---|
| 1780 | + |
---|
| 1781 | + if (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) { |
---|
| 1782 | + __le16 vlan_tag = rx_desc->wb.qword0.lo_dword.l2tag1; |
---|
| 1783 | + |
---|
| 1784 | + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
---|
| 1785 | + le16_to_cpu(vlan_tag)); |
---|
| 1786 | + } |
---|
1827 | 1787 | |
---|
1828 | 1788 | /* modifies the skb - consumes the enet header */ |
---|
1829 | 1789 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
---|
.. | .. |
---|
1847 | 1807 | union i40e_rx_desc *rx_desc) |
---|
1848 | 1808 | |
---|
1849 | 1809 | { |
---|
1850 | | - /* XDP packets use error pointer so abort at this point */ |
---|
1851 | | - if (IS_ERR(skb)) |
---|
1852 | | - return true; |
---|
1853 | | - |
---|
1854 | 1810 | /* ERR_MASK will only have valid bits if EOP set, and |
---|
1855 | 1811 | * what we are doing here is actually checking |
---|
1856 | 1812 | * I40E_RX_DESC_ERROR_RXE_SHIFT, since it is the zeroth bit in |
---|
.. | .. |
---|
1887 | 1843 | * the adapter for another receive |
---|
1888 | 1844 | * |
---|
1889 | 1845 | * @rx_buffer: buffer containing the page |
---|
| 1846 | + * @rx_buffer_pgcnt: buffer page refcount pre xdp_do_redirect() call |
---|
1890 | 1847 | * |
---|
1891 | 1848 | * If page is reusable, rx_buffer->page_offset is adjusted to point to |
---|
1892 | 1849 | * an unused region in the page. |
---|
.. | .. |
---|
1909 | 1866 | * |
---|
1910 | 1867 | * In either case, if the page is reusable its refcount is increased. |
---|
1911 | 1868 | **/ |
---|
1912 | | -static bool i40e_can_reuse_rx_page(struct i40e_rx_buffer *rx_buffer) |
---|
| 1869 | +static bool i40e_can_reuse_rx_page(struct i40e_rx_buffer *rx_buffer, |
---|
| 1870 | + int rx_buffer_pgcnt) |
---|
1913 | 1871 | { |
---|
1914 | 1872 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
---|
1915 | 1873 | struct page *page = rx_buffer->page; |
---|
.. | .. |
---|
1920 | 1878 | |
---|
1921 | 1879 | #if (PAGE_SIZE < 8192) |
---|
1922 | 1880 | /* if we are only owner of page we can reuse it */ |
---|
1923 | | - if (unlikely((page_count(page) - pagecnt_bias) > 1)) |
---|
| 1881 | + if (unlikely((rx_buffer_pgcnt - pagecnt_bias) > 1)) |
---|
1924 | 1882 | return false; |
---|
1925 | 1883 | #else |
---|
1926 | 1884 | #define I40E_LAST_OFFSET \ |
---|
.. | .. |
---|
1979 | 1937 | * i40e_get_rx_buffer - Fetch Rx buffer and synchronize data for use |
---|
1980 | 1938 | * @rx_ring: rx descriptor ring to transact packets on |
---|
1981 | 1939 | * @size: size of buffer to add to skb |
---|
| 1940 | + * @rx_buffer_pgcnt: buffer page refcount |
---|
1982 | 1941 | * |
---|
1983 | 1942 | * This function will pull an Rx buffer from the ring and synchronize it |
---|
1984 | 1943 | * for use by the CPU. |
---|
1985 | 1944 | */ |
---|
1986 | 1945 | static struct i40e_rx_buffer *i40e_get_rx_buffer(struct i40e_ring *rx_ring, |
---|
1987 | | - const unsigned int size) |
---|
| 1946 | + const unsigned int size, |
---|
| 1947 | + int *rx_buffer_pgcnt) |
---|
1988 | 1948 | { |
---|
1989 | 1949 | struct i40e_rx_buffer *rx_buffer; |
---|
1990 | 1950 | |
---|
1991 | | - rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean]; |
---|
1992 | | - prefetchw(rx_buffer->page); |
---|
| 1951 | + rx_buffer = i40e_rx_bi(rx_ring, rx_ring->next_to_clean); |
---|
| 1952 | + *rx_buffer_pgcnt = |
---|
| 1953 | +#if (PAGE_SIZE < 8192) |
---|
| 1954 | + page_count(rx_buffer->page); |
---|
| 1955 | +#else |
---|
| 1956 | + 0; |
---|
| 1957 | +#endif |
---|
| 1958 | + prefetch_page_address(rx_buffer->page); |
---|
1993 | 1959 | |
---|
1994 | 1960 | /* we are reusing so sync this buffer for CPU use */ |
---|
1995 | 1961 | dma_sync_single_range_for_cpu(rx_ring->dev, |
---|
.. | .. |
---|
2028 | 1994 | struct sk_buff *skb; |
---|
2029 | 1995 | |
---|
2030 | 1996 | /* prefetch first cache line of first page */ |
---|
2031 | | - prefetch(xdp->data); |
---|
2032 | | -#if L1_CACHE_BYTES < 128 |
---|
2033 | | - prefetch(xdp->data + L1_CACHE_BYTES); |
---|
2034 | | -#endif |
---|
| 1997 | + net_prefetch(xdp->data); |
---|
| 1998 | + |
---|
2035 | 1999 | /* Note, we get here by enabling legacy-rx via: |
---|
2036 | 2000 | * |
---|
2037 | 2001 | * ethtool --set-priv-flags <dev> legacy-rx on |
---|
.. | .. |
---|
2058 | 2022 | /* Determine available headroom for copy */ |
---|
2059 | 2023 | headlen = size; |
---|
2060 | 2024 | if (headlen > I40E_RX_HDR_SIZE) |
---|
2061 | | - headlen = eth_get_headlen(xdp->data, I40E_RX_HDR_SIZE); |
---|
| 2025 | + headlen = eth_get_headlen(skb->dev, xdp->data, |
---|
| 2026 | + I40E_RX_HDR_SIZE); |
---|
2062 | 2027 | |
---|
2063 | 2028 | /* align pull length to size of long to optimize memcpy performance */ |
---|
2064 | 2029 | memcpy(__skb_put(skb, headlen), xdp->data, |
---|
.. | .. |
---|
2113 | 2078 | * likely have a consumer accessing first few bytes of meta |
---|
2114 | 2079 | * data, and then actual data. |
---|
2115 | 2080 | */ |
---|
2116 | | - prefetch(xdp->data_meta); |
---|
2117 | | -#if L1_CACHE_BYTES < 128 |
---|
2118 | | - prefetch(xdp->data_meta + L1_CACHE_BYTES); |
---|
2119 | | -#endif |
---|
| 2081 | + net_prefetch(xdp->data_meta); |
---|
| 2082 | + |
---|
2120 | 2083 | /* build an skb around the page buffer */ |
---|
2121 | 2084 | skb = build_skb(xdp->data_hard_start, truesize); |
---|
2122 | 2085 | if (unlikely(!skb)) |
---|
.. | .. |
---|
2142 | 2105 | * i40e_put_rx_buffer - Clean up used buffer and either recycle or free |
---|
2143 | 2106 | * @rx_ring: rx descriptor ring to transact packets on |
---|
2144 | 2107 | * @rx_buffer: rx buffer to pull data from |
---|
| 2108 | + * @rx_buffer_pgcnt: rx buffer page refcount pre xdp_do_redirect() call |
---|
2145 | 2109 | * |
---|
2146 | 2110 | * This function will clean up the contents of the rx_buffer. It will |
---|
2147 | 2111 | * either recycle the buffer or unmap it and free the associated resources. |
---|
2148 | 2112 | */ |
---|
2149 | 2113 | static void i40e_put_rx_buffer(struct i40e_ring *rx_ring, |
---|
2150 | | - struct i40e_rx_buffer *rx_buffer) |
---|
| 2114 | + struct i40e_rx_buffer *rx_buffer, |
---|
| 2115 | + int rx_buffer_pgcnt) |
---|
2151 | 2116 | { |
---|
2152 | | - if (i40e_can_reuse_rx_page(rx_buffer)) { |
---|
| 2117 | + if (i40e_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) { |
---|
2153 | 2118 | /* hand second half of page back to the ring */ |
---|
2154 | 2119 | i40e_reuse_rx_page(rx_ring, rx_buffer); |
---|
2155 | | - rx_ring->rx_stats.page_reuse_count++; |
---|
2156 | 2120 | } else { |
---|
2157 | 2121 | /* we are not reusing the buffer so unmap it */ |
---|
2158 | 2122 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
---|
.. | .. |
---|
2160 | 2124 | DMA_FROM_DEVICE, I40E_RX_DMA_ATTR); |
---|
2161 | 2125 | __page_frag_cache_drain(rx_buffer->page, |
---|
2162 | 2126 | rx_buffer->pagecnt_bias); |
---|
| 2127 | + /* clear contents of buffer_info */ |
---|
| 2128 | + rx_buffer->page = NULL; |
---|
2163 | 2129 | } |
---|
2164 | | - |
---|
2165 | | - /* clear contents of buffer_info */ |
---|
2166 | | - rx_buffer->page = NULL; |
---|
2167 | 2130 | } |
---|
2168 | 2131 | |
---|
2169 | 2132 | /** |
---|
.. | .. |
---|
2199 | 2162 | return true; |
---|
2200 | 2163 | } |
---|
2201 | 2164 | |
---|
2202 | | -#define I40E_XDP_PASS 0 |
---|
2203 | | -#define I40E_XDP_CONSUMED BIT(0) |
---|
2204 | | -#define I40E_XDP_TX BIT(1) |
---|
2205 | | -#define I40E_XDP_REDIR BIT(2) |
---|
2206 | | - |
---|
2207 | 2165 | static int i40e_xmit_xdp_ring(struct xdp_frame *xdpf, |
---|
2208 | 2166 | struct i40e_ring *xdp_ring); |
---|
2209 | 2167 | |
---|
2210 | | -static int i40e_xmit_xdp_tx_ring(struct xdp_buff *xdp, |
---|
2211 | | - struct i40e_ring *xdp_ring) |
---|
| 2168 | +int i40e_xmit_xdp_tx_ring(struct xdp_buff *xdp, struct i40e_ring *xdp_ring) |
---|
2212 | 2169 | { |
---|
2213 | | - struct xdp_frame *xdpf = convert_to_xdp_frame(xdp); |
---|
| 2170 | + struct xdp_frame *xdpf = xdp_convert_buff_to_frame(xdp); |
---|
2214 | 2171 | |
---|
2215 | 2172 | if (unlikely(!xdpf)) |
---|
2216 | 2173 | return I40E_XDP_CONSUMED; |
---|
.. | .. |
---|
2223 | 2180 | * @rx_ring: Rx ring being processed |
---|
2224 | 2181 | * @xdp: XDP buffer containing the frame |
---|
2225 | 2182 | **/ |
---|
2226 | | -static struct sk_buff *i40e_run_xdp(struct i40e_ring *rx_ring, |
---|
2227 | | - struct xdp_buff *xdp) |
---|
| 2183 | +static int i40e_run_xdp(struct i40e_ring *rx_ring, struct xdp_buff *xdp) |
---|
2228 | 2184 | { |
---|
2229 | 2185 | int err, result = I40E_XDP_PASS; |
---|
2230 | 2186 | struct i40e_ring *xdp_ring; |
---|
.. | .. |
---|
2246 | 2202 | case XDP_TX: |
---|
2247 | 2203 | xdp_ring = rx_ring->vsi->xdp_rings[rx_ring->queue_index]; |
---|
2248 | 2204 | result = i40e_xmit_xdp_tx_ring(xdp, xdp_ring); |
---|
| 2205 | + if (result == I40E_XDP_CONSUMED) |
---|
| 2206 | + goto out_failure; |
---|
2249 | 2207 | break; |
---|
2250 | 2208 | case XDP_REDIRECT: |
---|
2251 | 2209 | err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog); |
---|
2252 | | - result = !err ? I40E_XDP_REDIR : I40E_XDP_CONSUMED; |
---|
| 2210 | + if (err) |
---|
| 2211 | + goto out_failure; |
---|
| 2212 | + result = I40E_XDP_REDIR; |
---|
2253 | 2213 | break; |
---|
2254 | 2214 | default: |
---|
2255 | 2215 | bpf_warn_invalid_xdp_action(act); |
---|
2256 | | - /* fall through */ |
---|
| 2216 | + fallthrough; |
---|
2257 | 2217 | case XDP_ABORTED: |
---|
| 2218 | +out_failure: |
---|
2258 | 2219 | trace_xdp_exception(rx_ring->netdev, xdp_prog, act); |
---|
2259 | | - /* fall through -- handle aborts by dropping packet */ |
---|
| 2220 | + fallthrough; /* handle aborts by dropping packet */ |
---|
2260 | 2221 | case XDP_DROP: |
---|
2261 | 2222 | result = I40E_XDP_CONSUMED; |
---|
2262 | 2223 | break; |
---|
2263 | 2224 | } |
---|
2264 | 2225 | xdp_out: |
---|
2265 | 2226 | rcu_read_unlock(); |
---|
2266 | | - return ERR_PTR(-result); |
---|
| 2227 | + return result; |
---|
2267 | 2228 | } |
---|
2268 | 2229 | |
---|
2269 | 2230 | /** |
---|
.. | .. |
---|
2276 | 2237 | struct i40e_rx_buffer *rx_buffer, |
---|
2277 | 2238 | unsigned int size) |
---|
2278 | 2239 | { |
---|
2279 | | -#if (PAGE_SIZE < 8192) |
---|
2280 | | - unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2; |
---|
| 2240 | + unsigned int truesize = i40e_rx_frame_truesize(rx_ring, size); |
---|
2281 | 2241 | |
---|
| 2242 | +#if (PAGE_SIZE < 8192) |
---|
2282 | 2243 | rx_buffer->page_offset ^= truesize; |
---|
2283 | 2244 | #else |
---|
2284 | | - unsigned int truesize = SKB_DATA_ALIGN(i40e_rx_offset(rx_ring) + size); |
---|
2285 | | - |
---|
2286 | 2245 | rx_buffer->page_offset += truesize; |
---|
2287 | 2246 | #endif |
---|
2288 | 2247 | } |
---|
2289 | 2248 | |
---|
2290 | | -static inline void i40e_xdp_ring_update_tail(struct i40e_ring *xdp_ring) |
---|
| 2249 | +/** |
---|
| 2250 | + * i40e_xdp_ring_update_tail - Updates the XDP Tx ring tail register |
---|
| 2251 | + * @xdp_ring: XDP Tx ring |
---|
| 2252 | + * |
---|
| 2253 | + * This function updates the XDP Tx ring tail register. |
---|
| 2254 | + **/ |
---|
| 2255 | +void i40e_xdp_ring_update_tail(struct i40e_ring *xdp_ring) |
---|
2291 | 2256 | { |
---|
2292 | 2257 | /* Force memory writes to complete before letting h/w |
---|
2293 | 2258 | * know there are new descriptors to fetch. |
---|
2294 | 2259 | */ |
---|
2295 | 2260 | wmb(); |
---|
2296 | 2261 | writel_relaxed(xdp_ring->next_to_use, xdp_ring->tail); |
---|
| 2262 | +} |
---|
| 2263 | + |
---|
| 2264 | +/** |
---|
| 2265 | + * i40e_update_rx_stats - Update Rx ring statistics |
---|
| 2266 | + * @rx_ring: rx descriptor ring |
---|
| 2267 | + * @total_rx_bytes: number of bytes received |
---|
| 2268 | + * @total_rx_packets: number of packets received |
---|
| 2269 | + * |
---|
| 2270 | + * This function updates the Rx ring statistics. |
---|
| 2271 | + **/ |
---|
| 2272 | +void i40e_update_rx_stats(struct i40e_ring *rx_ring, |
---|
| 2273 | + unsigned int total_rx_bytes, |
---|
| 2274 | + unsigned int total_rx_packets) |
---|
| 2275 | +{ |
---|
| 2276 | + u64_stats_update_begin(&rx_ring->syncp); |
---|
| 2277 | + rx_ring->stats.packets += total_rx_packets; |
---|
| 2278 | + rx_ring->stats.bytes += total_rx_bytes; |
---|
| 2279 | + u64_stats_update_end(&rx_ring->syncp); |
---|
| 2280 | + rx_ring->q_vector->rx.total_packets += total_rx_packets; |
---|
| 2281 | + rx_ring->q_vector->rx.total_bytes += total_rx_bytes; |
---|
| 2282 | +} |
---|
| 2283 | + |
---|
| 2284 | +/** |
---|
| 2285 | + * i40e_finalize_xdp_rx - Bump XDP Tx tail and/or flush redirect map |
---|
| 2286 | + * @rx_ring: Rx ring |
---|
| 2287 | + * @xdp_res: Result of the receive batch |
---|
| 2288 | + * |
---|
| 2289 | + * This function bumps XDP Tx tail and/or flush redirect map, and |
---|
| 2290 | + * should be called when a batch of packets has been processed in the |
---|
| 2291 | + * napi loop. |
---|
| 2292 | + **/ |
---|
| 2293 | +void i40e_finalize_xdp_rx(struct i40e_ring *rx_ring, unsigned int xdp_res) |
---|
| 2294 | +{ |
---|
| 2295 | + if (xdp_res & I40E_XDP_REDIR) |
---|
| 2296 | + xdp_do_flush_map(); |
---|
| 2297 | + |
---|
| 2298 | + if (xdp_res & I40E_XDP_TX) { |
---|
| 2299 | + struct i40e_ring *xdp_ring = |
---|
| 2300 | + rx_ring->vsi->xdp_rings[rx_ring->queue_index]; |
---|
| 2301 | + |
---|
| 2302 | + i40e_xdp_ring_update_tail(xdp_ring); |
---|
| 2303 | + } |
---|
| 2304 | +} |
---|
| 2305 | + |
---|
| 2306 | +/** |
---|
| 2307 | + * i40e_inc_ntc: Advance the next_to_clean index |
---|
| 2308 | + * @rx_ring: Rx ring |
---|
| 2309 | + **/ |
---|
| 2310 | +static void i40e_inc_ntc(struct i40e_ring *rx_ring) |
---|
| 2311 | +{ |
---|
| 2312 | + u32 ntc = rx_ring->next_to_clean + 1; |
---|
| 2313 | + |
---|
| 2314 | + ntc = (ntc < rx_ring->count) ? ntc : 0; |
---|
| 2315 | + rx_ring->next_to_clean = ntc; |
---|
| 2316 | + prefetch(I40E_RX_DESC(rx_ring, ntc)); |
---|
2297 | 2317 | } |
---|
2298 | 2318 | |
---|
2299 | 2319 | /** |
---|
.. | .. |
---|
2316 | 2336 | unsigned int xdp_xmit = 0; |
---|
2317 | 2337 | bool failure = false; |
---|
2318 | 2338 | struct xdp_buff xdp; |
---|
| 2339 | + int xdp_res = 0; |
---|
2319 | 2340 | |
---|
| 2341 | +#if (PAGE_SIZE < 8192) |
---|
| 2342 | + xdp.frame_sz = i40e_rx_frame_truesize(rx_ring, 0); |
---|
| 2343 | +#endif |
---|
2320 | 2344 | xdp.rxq = &rx_ring->xdp_rxq; |
---|
2321 | 2345 | |
---|
2322 | 2346 | while (likely(total_rx_packets < (unsigned int)budget)) { |
---|
2323 | 2347 | struct i40e_rx_buffer *rx_buffer; |
---|
2324 | 2348 | union i40e_rx_desc *rx_desc; |
---|
| 2349 | + int rx_buffer_pgcnt; |
---|
2325 | 2350 | unsigned int size; |
---|
2326 | | - u16 vlan_tag; |
---|
2327 | | - u8 rx_ptype; |
---|
2328 | 2351 | u64 qword; |
---|
2329 | 2352 | |
---|
2330 | 2353 | /* return some buffers to hardware, one at a time is too slow */ |
---|
.. | .. |
---|
2349 | 2372 | */ |
---|
2350 | 2373 | dma_rmb(); |
---|
2351 | 2374 | |
---|
2352 | | - if (unlikely(i40e_rx_is_programming_status(qword))) { |
---|
2353 | | - i40e_clean_programming_status(rx_ring, rx_desc, qword); |
---|
| 2375 | + if (i40e_rx_is_programming_status(qword)) { |
---|
| 2376 | + i40e_clean_programming_status(rx_ring, |
---|
| 2377 | + rx_desc->raw.qword[0], |
---|
| 2378 | + qword); |
---|
| 2379 | + rx_buffer = i40e_rx_bi(rx_ring, rx_ring->next_to_clean); |
---|
| 2380 | + i40e_inc_ntc(rx_ring); |
---|
| 2381 | + i40e_reuse_rx_page(rx_ring, rx_buffer); |
---|
2354 | 2382 | cleaned_count++; |
---|
2355 | 2383 | continue; |
---|
2356 | 2384 | } |
---|
| 2385 | + |
---|
2357 | 2386 | size = (qword & I40E_RXD_QW1_LENGTH_PBUF_MASK) >> |
---|
2358 | 2387 | I40E_RXD_QW1_LENGTH_PBUF_SHIFT; |
---|
2359 | 2388 | if (!size) |
---|
2360 | 2389 | break; |
---|
2361 | 2390 | |
---|
2362 | 2391 | i40e_trace(clean_rx_irq, rx_ring, rx_desc, skb); |
---|
2363 | | - rx_buffer = i40e_get_rx_buffer(rx_ring, size); |
---|
| 2392 | + rx_buffer = i40e_get_rx_buffer(rx_ring, size, &rx_buffer_pgcnt); |
---|
2364 | 2393 | |
---|
2365 | 2394 | /* retrieve a buffer from the ring */ |
---|
2366 | 2395 | if (!skb) { |
---|
.. | .. |
---|
2370 | 2399 | xdp.data_hard_start = xdp.data - |
---|
2371 | 2400 | i40e_rx_offset(rx_ring); |
---|
2372 | 2401 | xdp.data_end = xdp.data + size; |
---|
2373 | | - |
---|
2374 | | - skb = i40e_run_xdp(rx_ring, &xdp); |
---|
| 2402 | +#if (PAGE_SIZE > 4096) |
---|
| 2403 | + /* At larger PAGE_SIZE, frame_sz depend on len size */ |
---|
| 2404 | + xdp.frame_sz = i40e_rx_frame_truesize(rx_ring, size); |
---|
| 2405 | +#endif |
---|
| 2406 | + xdp_res = i40e_run_xdp(rx_ring, &xdp); |
---|
2375 | 2407 | } |
---|
2376 | 2408 | |
---|
2377 | | - if (IS_ERR(skb)) { |
---|
2378 | | - unsigned int xdp_res = -PTR_ERR(skb); |
---|
2379 | | - |
---|
| 2409 | + if (xdp_res) { |
---|
2380 | 2410 | if (xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR)) { |
---|
2381 | 2411 | xdp_xmit |= xdp_res; |
---|
2382 | 2412 | i40e_rx_buffer_flip(rx_ring, rx_buffer, size); |
---|
.. | .. |
---|
2394 | 2424 | } |
---|
2395 | 2425 | |
---|
2396 | 2426 | /* exit if we failed to retrieve a buffer */ |
---|
2397 | | - if (!skb) { |
---|
| 2427 | + if (!xdp_res && !skb) { |
---|
2398 | 2428 | rx_ring->rx_stats.alloc_buff_failed++; |
---|
2399 | 2429 | rx_buffer->pagecnt_bias++; |
---|
2400 | 2430 | break; |
---|
2401 | 2431 | } |
---|
2402 | 2432 | |
---|
2403 | | - i40e_put_rx_buffer(rx_ring, rx_buffer); |
---|
| 2433 | + i40e_put_rx_buffer(rx_ring, rx_buffer, rx_buffer_pgcnt); |
---|
2404 | 2434 | cleaned_count++; |
---|
2405 | 2435 | |
---|
2406 | 2436 | if (i40e_is_non_eop(rx_ring, rx_desc, skb)) |
---|
2407 | 2437 | continue; |
---|
2408 | 2438 | |
---|
2409 | | - if (i40e_cleanup_headers(rx_ring, skb, rx_desc)) { |
---|
| 2439 | + if (xdp_res || i40e_cleanup_headers(rx_ring, skb, rx_desc)) { |
---|
2410 | 2440 | skb = NULL; |
---|
2411 | 2441 | continue; |
---|
2412 | 2442 | } |
---|
.. | .. |
---|
2414 | 2444 | /* probably a little skewed due to removing CRC */ |
---|
2415 | 2445 | total_rx_bytes += skb->len; |
---|
2416 | 2446 | |
---|
2417 | | - qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
---|
2418 | | - rx_ptype = (qword & I40E_RXD_QW1_PTYPE_MASK) >> |
---|
2419 | | - I40E_RXD_QW1_PTYPE_SHIFT; |
---|
2420 | | - |
---|
2421 | 2447 | /* populate checksum, VLAN, and protocol */ |
---|
2422 | | - i40e_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype); |
---|
2423 | | - |
---|
2424 | | - vlan_tag = (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) ? |
---|
2425 | | - le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1) : 0; |
---|
| 2448 | + i40e_process_skb_fields(rx_ring, rx_desc, skb); |
---|
2426 | 2449 | |
---|
2427 | 2450 | i40e_trace(clean_rx_irq_rx, rx_ring, rx_desc, skb); |
---|
2428 | | - i40e_receive_skb(rx_ring, skb, vlan_tag); |
---|
| 2451 | + napi_gro_receive(&rx_ring->q_vector->napi, skb); |
---|
2429 | 2452 | skb = NULL; |
---|
2430 | 2453 | |
---|
2431 | 2454 | /* update budget accounting */ |
---|
2432 | 2455 | total_rx_packets++; |
---|
2433 | 2456 | } |
---|
2434 | 2457 | |
---|
2435 | | - if (xdp_xmit & I40E_XDP_REDIR) |
---|
2436 | | - xdp_do_flush_map(); |
---|
2437 | | - |
---|
2438 | | - if (xdp_xmit & I40E_XDP_TX) { |
---|
2439 | | - struct i40e_ring *xdp_ring = |
---|
2440 | | - rx_ring->vsi->xdp_rings[rx_ring->queue_index]; |
---|
2441 | | - |
---|
2442 | | - i40e_xdp_ring_update_tail(xdp_ring); |
---|
2443 | | - } |
---|
2444 | | - |
---|
| 2458 | + i40e_finalize_xdp_rx(rx_ring, xdp_xmit); |
---|
2445 | 2459 | rx_ring->skb = skb; |
---|
2446 | 2460 | |
---|
2447 | | - u64_stats_update_begin(&rx_ring->syncp); |
---|
2448 | | - rx_ring->stats.packets += total_rx_packets; |
---|
2449 | | - rx_ring->stats.bytes += total_rx_bytes; |
---|
2450 | | - u64_stats_update_end(&rx_ring->syncp); |
---|
2451 | | - rx_ring->q_vector->rx.total_packets += total_rx_packets; |
---|
2452 | | - rx_ring->q_vector->rx.total_bytes += total_rx_bytes; |
---|
| 2461 | + i40e_update_rx_stats(rx_ring, total_rx_bytes, total_rx_packets); |
---|
2453 | 2462 | |
---|
2454 | 2463 | /* guarantee a trip back through this routine if there was a failure */ |
---|
2455 | 2464 | return failure ? budget : (int)total_rx_packets; |
---|
.. | .. |
---|
2587 | 2596 | * budget and be more aggressive about cleaning up the Tx descriptors. |
---|
2588 | 2597 | */ |
---|
2589 | 2598 | i40e_for_each_ring(ring, q_vector->tx) { |
---|
2590 | | - if (!i40e_clean_tx_irq(vsi, ring, budget)) { |
---|
| 2599 | + bool wd = ring->xsk_pool ? |
---|
| 2600 | + i40e_clean_xdp_tx_irq(vsi, ring) : |
---|
| 2601 | + i40e_clean_tx_irq(vsi, ring, budget); |
---|
| 2602 | + |
---|
| 2603 | + if (!wd) { |
---|
2591 | 2604 | clean_complete = false; |
---|
2592 | 2605 | continue; |
---|
2593 | 2606 | } |
---|
.. | .. |
---|
2599 | 2612 | if (budget <= 0) |
---|
2600 | 2613 | goto tx_only; |
---|
2601 | 2614 | |
---|
2602 | | - /* We attempt to distribute budget to each Rx queue fairly, but don't |
---|
2603 | | - * allow the budget to go below 1 because that would exit polling early. |
---|
2604 | | - */ |
---|
2605 | | - budget_per_ring = max(budget/q_vector->num_ringpairs, 1); |
---|
| 2615 | + /* normally we have 1 Rx ring per q_vector */ |
---|
| 2616 | + if (unlikely(q_vector->num_ringpairs > 1)) |
---|
| 2617 | + /* We attempt to distribute budget to each Rx queue fairly, but |
---|
| 2618 | + * don't allow the budget to go below 1 because that would exit |
---|
| 2619 | + * polling early. |
---|
| 2620 | + */ |
---|
| 2621 | + budget_per_ring = max_t(int, budget / q_vector->num_ringpairs, 1); |
---|
| 2622 | + else |
---|
| 2623 | + /* Max of 1 Rx ring in this q_vector so give it the budget */ |
---|
| 2624 | + budget_per_ring = budget; |
---|
2606 | 2625 | |
---|
2607 | 2626 | i40e_for_each_ring(ring, q_vector->rx) { |
---|
2608 | | - int cleaned = i40e_clean_rx_irq(ring, budget_per_ring); |
---|
| 2627 | + int cleaned = ring->xsk_pool ? |
---|
| 2628 | + i40e_clean_rx_irq_zc(ring, budget_per_ring) : |
---|
| 2629 | + i40e_clean_rx_irq(ring, budget_per_ring); |
---|
2609 | 2630 | |
---|
2610 | 2631 | work_done += cleaned; |
---|
2611 | 2632 | /* if we clean as many as budgeted, we must not be done */ |
---|
.. | .. |
---|
2645 | 2666 | if (vsi->back->flags & I40E_TXR_FLAGS_WB_ON_ITR) |
---|
2646 | 2667 | q_vector->arm_wb_state = false; |
---|
2647 | 2668 | |
---|
2648 | | - /* Work is done so exit the polling mode and re-enable the interrupt */ |
---|
2649 | | - napi_complete_done(napi, work_done); |
---|
2650 | | - |
---|
2651 | | - i40e_update_enable_itr(vsi, q_vector); |
---|
| 2669 | + /* Exit the polling mode, but don't re-enable interrupts if stack might |
---|
| 2670 | + * poll us due to busy-polling |
---|
| 2671 | + */ |
---|
| 2672 | + if (likely(napi_complete_done(napi, work_done))) |
---|
| 2673 | + i40e_update_enable_itr(vsi, q_vector); |
---|
2652 | 2674 | |
---|
2653 | 2675 | return min(work_done, budget - 1); |
---|
2654 | 2676 | } |
---|
.. | .. |
---|
2955 | 2977 | |
---|
2956 | 2978 | /* remove payload length from inner checksum */ |
---|
2957 | 2979 | paylen = skb->len - l4_offset; |
---|
2958 | | - csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen)); |
---|
2959 | 2980 | |
---|
2960 | | - /* compute length of segmentation header */ |
---|
2961 | | - *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
---|
| 2981 | + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) { |
---|
| 2982 | + csum_replace_by_diff(&l4.udp->check, (__force __wsum)htonl(paylen)); |
---|
| 2983 | + /* compute length of segmentation header */ |
---|
| 2984 | + *hdr_len = sizeof(*l4.udp) + l4_offset; |
---|
| 2985 | + } else { |
---|
| 2986 | + csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen)); |
---|
| 2987 | + /* compute length of segmentation header */ |
---|
| 2988 | + *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
---|
| 2989 | + } |
---|
2962 | 2990 | |
---|
2963 | 2991 | /* pull values out of skb_shinfo */ |
---|
2964 | 2992 | gso_size = skb_shinfo(skb)->gso_size; |
---|
.. | .. |
---|
3260 | 3288 | **/ |
---|
3261 | 3289 | bool __i40e_chk_linearize(struct sk_buff *skb) |
---|
3262 | 3290 | { |
---|
3263 | | - const struct skb_frag_struct *frag, *stale; |
---|
| 3291 | + const skb_frag_t *frag, *stale; |
---|
3264 | 3292 | int nr_frags, sum; |
---|
3265 | 3293 | |
---|
3266 | 3294 | /* no need to check if number of frags is less than 7 */ |
---|
.. | .. |
---|
3304 | 3332 | * descriptor associated with the fragment. |
---|
3305 | 3333 | */ |
---|
3306 | 3334 | if (stale_size > I40E_MAX_DATA_PER_TXD) { |
---|
3307 | | - int align_pad = -(stale->page_offset) & |
---|
| 3335 | + int align_pad = -(skb_frag_off(stale)) & |
---|
3308 | 3336 | (I40E_MAX_READ_REQ_SIZE - 1); |
---|
3309 | 3337 | |
---|
3310 | 3338 | sum -= align_pad; |
---|
.. | .. |
---|
3347 | 3375 | { |
---|
3348 | 3376 | unsigned int data_len = skb->data_len; |
---|
3349 | 3377 | unsigned int size = skb_headlen(skb); |
---|
3350 | | - struct skb_frag_struct *frag; |
---|
| 3378 | + skb_frag_t *frag; |
---|
3351 | 3379 | struct i40e_tx_buffer *tx_bi; |
---|
3352 | 3380 | struct i40e_tx_desc *tx_desc; |
---|
3353 | 3381 | u16 i = tx_ring->next_to_use; |
---|
.. | .. |
---|
3454 | 3482 | tx_desc->cmd_type_offset_bsz = |
---|
3455 | 3483 | build_ctob(td_cmd, td_offset, size, td_tag); |
---|
3456 | 3484 | |
---|
| 3485 | + skb_tx_timestamp(skb); |
---|
| 3486 | + |
---|
3457 | 3487 | /* Force memory writes to complete before letting h/w know there |
---|
3458 | 3488 | * are new descriptors to fetch. |
---|
3459 | 3489 | * |
---|
.. | .. |
---|
3466 | 3496 | first->next_to_watch = tx_desc; |
---|
3467 | 3497 | |
---|
3468 | 3498 | /* notify HW of packet */ |
---|
3469 | | - if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
---|
| 3499 | + if (netif_xmit_stopped(txring_txq(tx_ring)) || !netdev_xmit_more()) { |
---|
3470 | 3500 | writel(i, tx_ring->tail); |
---|
3471 | | - |
---|
3472 | | - /* we need this if more than one processor can write to our tail |
---|
3473 | | - * at a time, it synchronizes IO on IA64/Altix systems |
---|
3474 | | - */ |
---|
3475 | | - mmiowb(); |
---|
3476 | 3501 | } |
---|
3477 | 3502 | |
---|
3478 | 3503 | return 0; |
---|
.. | .. |
---|
3496 | 3521 | return -1; |
---|
3497 | 3522 | } |
---|
3498 | 3523 | |
---|
| 3524 | +static u16 i40e_swdcb_skb_tx_hash(struct net_device *dev, |
---|
| 3525 | + const struct sk_buff *skb, |
---|
| 3526 | + u16 num_tx_queues) |
---|
| 3527 | +{ |
---|
| 3528 | + u32 jhash_initval_salt = 0xd631614b; |
---|
| 3529 | + u32 hash; |
---|
| 3530 | + |
---|
| 3531 | + if (skb->sk && skb->sk->sk_hash) |
---|
| 3532 | + hash = skb->sk->sk_hash; |
---|
| 3533 | + else |
---|
| 3534 | + hash = (__force u16)skb->protocol ^ skb->hash; |
---|
| 3535 | + |
---|
| 3536 | + hash = jhash_1word(hash, jhash_initval_salt); |
---|
| 3537 | + |
---|
| 3538 | + return (u16)(((u64)hash * num_tx_queues) >> 32); |
---|
| 3539 | +} |
---|
| 3540 | + |
---|
| 3541 | +u16 i40e_lan_select_queue(struct net_device *netdev, |
---|
| 3542 | + struct sk_buff *skb, |
---|
| 3543 | + struct net_device __always_unused *sb_dev) |
---|
| 3544 | +{ |
---|
| 3545 | + struct i40e_netdev_priv *np = netdev_priv(netdev); |
---|
| 3546 | + struct i40e_vsi *vsi = np->vsi; |
---|
| 3547 | + struct i40e_hw *hw; |
---|
| 3548 | + u16 qoffset; |
---|
| 3549 | + u16 qcount; |
---|
| 3550 | + u8 tclass; |
---|
| 3551 | + u16 hash; |
---|
| 3552 | + u8 prio; |
---|
| 3553 | + |
---|
| 3554 | + /* is DCB enabled at all? */ |
---|
| 3555 | + if (vsi->tc_config.numtc == 1) |
---|
| 3556 | + return netdev_pick_tx(netdev, skb, sb_dev); |
---|
| 3557 | + |
---|
| 3558 | + prio = skb->priority; |
---|
| 3559 | + hw = &vsi->back->hw; |
---|
| 3560 | + tclass = hw->local_dcbx_config.etscfg.prioritytable[prio]; |
---|
| 3561 | + /* sanity check */ |
---|
| 3562 | + if (unlikely(!(vsi->tc_config.enabled_tc & BIT(tclass)))) |
---|
| 3563 | + tclass = 0; |
---|
| 3564 | + |
---|
| 3565 | + /* select a queue assigned for the given TC */ |
---|
| 3566 | + qcount = vsi->tc_config.tc_info[tclass].qcount; |
---|
| 3567 | + hash = i40e_swdcb_skb_tx_hash(netdev, skb, qcount); |
---|
| 3568 | + |
---|
| 3569 | + qoffset = vsi->tc_config.tc_info[tclass].qoffset; |
---|
| 3570 | + return qoffset + hash; |
---|
| 3571 | +} |
---|
| 3572 | + |
---|
3499 | 3573 | /** |
---|
3500 | 3574 | * i40e_xmit_xdp_ring - transmits an XDP buffer to an XDP Tx ring |
---|
3501 | | - * @xdp: data to transmit |
---|
| 3575 | + * @xdpf: data to transmit |
---|
3502 | 3576 | * @xdp_ring: XDP Tx ring |
---|
3503 | 3577 | **/ |
---|
3504 | 3578 | static int i40e_xmit_xdp_ring(struct xdp_frame *xdpf, |
---|
.. | .. |
---|
3507 | 3581 | u16 i = xdp_ring->next_to_use; |
---|
3508 | 3582 | struct i40e_tx_buffer *tx_bi; |
---|
3509 | 3583 | struct i40e_tx_desc *tx_desc; |
---|
| 3584 | + void *data = xdpf->data; |
---|
3510 | 3585 | u32 size = xdpf->len; |
---|
3511 | 3586 | dma_addr_t dma; |
---|
3512 | 3587 | |
---|
.. | .. |
---|
3514 | 3589 | xdp_ring->tx_stats.tx_busy++; |
---|
3515 | 3590 | return I40E_XDP_CONSUMED; |
---|
3516 | 3591 | } |
---|
3517 | | - |
---|
3518 | | - dma = dma_map_single(xdp_ring->dev, xdpf->data, size, DMA_TO_DEVICE); |
---|
| 3592 | + dma = dma_map_single(xdp_ring->dev, data, size, DMA_TO_DEVICE); |
---|
3519 | 3593 | if (dma_mapping_error(xdp_ring->dev, dma)) |
---|
3520 | 3594 | return I40E_XDP_CONSUMED; |
---|
3521 | 3595 | |
---|
.. | .. |
---|
3539 | 3613 | */ |
---|
3540 | 3614 | smp_wmb(); |
---|
3541 | 3615 | |
---|
| 3616 | + xdp_ring->xdp_tx_active++; |
---|
3542 | 3617 | i++; |
---|
3543 | 3618 | if (i == xdp_ring->count) |
---|
3544 | 3619 | i = 0; |
---|
.. | .. |
---|
3633 | 3708 | if (tsyn) |
---|
3634 | 3709 | tx_flags |= I40E_TX_FLAGS_TSYN; |
---|
3635 | 3710 | |
---|
3636 | | - skb_tx_timestamp(skb); |
---|
3637 | | - |
---|
3638 | 3711 | /* always enable CRC insertion offload */ |
---|
3639 | 3712 | td_cmd |= I40E_TX_DESC_CMD_ICRC; |
---|
3640 | 3713 | |
---|
.. | .. |
---|
3694 | 3767 | /** |
---|
3695 | 3768 | * i40e_xdp_xmit - Implements ndo_xdp_xmit |
---|
3696 | 3769 | * @dev: netdev |
---|
3697 | | - * @xdp: XDP buffer |
---|
| 3770 | + * @n: number of frames |
---|
| 3771 | + * @frames: array of XDP buffer pointers |
---|
| 3772 | + * @flags: XDP extra info |
---|
3698 | 3773 | * |
---|
3699 | 3774 | * Returns number of frames successfully sent. Frames that fail are |
---|
3700 | 3775 | * free'ed via XDP return API. |
---|
.. | .. |
---|
3708 | 3783 | struct i40e_netdev_priv *np = netdev_priv(dev); |
---|
3709 | 3784 | unsigned int queue_index = smp_processor_id(); |
---|
3710 | 3785 | struct i40e_vsi *vsi = np->vsi; |
---|
| 3786 | + struct i40e_pf *pf = vsi->back; |
---|
3711 | 3787 | struct i40e_ring *xdp_ring; |
---|
3712 | 3788 | int drops = 0; |
---|
3713 | 3789 | int i; |
---|
.. | .. |
---|
3715 | 3791 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
---|
3716 | 3792 | return -ENETDOWN; |
---|
3717 | 3793 | |
---|
3718 | | - if (!i40e_enabled_xdp_vsi(vsi) || queue_index >= vsi->num_queue_pairs) |
---|
| 3794 | + if (!i40e_enabled_xdp_vsi(vsi) || queue_index >= vsi->num_queue_pairs || |
---|
| 3795 | + test_bit(__I40E_CONFIG_BUSY, pf->state)) |
---|
3719 | 3796 | return -ENXIO; |
---|
3720 | 3797 | |
---|
3721 | 3798 | if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) |
---|