Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch '200GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue

Tony Nguyen says:

====================
idpf: XDP chapter I: convert Rx to libeth

Alexander Lobakin says:

XDP for idpf is currently 5 chapters:
* convert Rx to libeth (this);
* convert Tx and stats to libeth;
* generic XDP and XSk code changes, libeth_xdp;
* actual XDP for idpf via libeth_xdp;
* XSk for idpf (^).

Part I does the following:
* splits &idpf_queue into 4 (RQ, SQ, FQ, CQ) and puts them on a diet;
* ensures optimal cacheline placement, strictly asserts CL sizes;
* moves currently unused/dead singleq mode out of line;
* reuses libeth's Rx ptype definitions and helpers;
* uses libeth's Rx buffer management for both header and payload;
* eliminates memcpy()s and coherent DMA uses on hotpath, uses
napi_build_skb() instead of in-place short skb allocation.

Most idpf patches, except for the queue split, removes more lines
than adds.

Expect far better memory utilization and +5-8% on Rx depending on
the case (+17% on skb XDP_DROP :>).

* '200GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue:
idpf: use libeth Rx buffer management for payload buffer
idpf: convert header split mode to libeth + napi_build_skb()
libeth: support different types of buffers for Rx
idpf: remove legacy Page Pool Ethtool stats
idpf: reuse libeth's definitions of parsed ptype structures
idpf: compile singleq code only under default-n CONFIG_IDPF_SINGLEQ
idpf: merge singleq and splitq &net_device_ops
idpf: strictly assert cachelines of queue and queue vector structures
idpf: avoid bloating &idpf_q_vector with big %NR_CPUS
idpf: split &idpf_queue into 4 strictly-typed queue structures
idpf: stop using macros for accessing queue descriptors
libeth: add cacheline / struct layout assertion helpers
page_pool: use __cacheline_group_{begin, end}_aligned()
cache: add __cacheline_group_{begin, end}_aligned() (+ couple more)
====================

Link: https://patch.msgid.link/20240710203031.188081-1-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+1841 -1420
+1 -12
drivers/net/ethernet/intel/Kconfig
··· 384 384 Optional support for controlling the NIC LED's with the netdev 385 385 LED trigger. 386 386 387 - config IDPF 388 - tristate "Intel(R) Infrastructure Data Path Function Support" 389 - depends on PCI_MSI 390 - select DIMLIB 391 - select PAGE_POOL 392 - select PAGE_POOL_STATS 393 - help 394 - This driver supports Intel(R) Infrastructure Data Path Function 395 - devices. 396 - 397 - To compile this driver as a module, choose M here. The module 398 - will be called idpf. 387 + source "drivers/net/ethernet/intel/idpf/Kconfig" 399 388 400 389 endif # NET_VENDOR_INTEL
+26
drivers/net/ethernet/intel/idpf/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + # Copyright (C) 2024 Intel Corporation 3 + 4 + config IDPF 5 + tristate "Intel(R) Infrastructure Data Path Function Support" 6 + depends on PCI_MSI 7 + select DIMLIB 8 + select LIBETH 9 + help 10 + This driver supports Intel(R) Infrastructure Data Path Function 11 + devices. 12 + 13 + To compile this driver as a module, choose M here. The module 14 + will be called idpf. 15 + 16 + if IDPF 17 + 18 + config IDPF_SINGLEQ 19 + bool "idpf singleq support" 20 + help 21 + This option enables support for legacy single Rx/Tx queues w/no 22 + completion and fill queues. Only enable if you have hardware which 23 + wants to work in this mode as it increases the driver size and adds 24 + runtme checks on hotpath. 25 + 26 + endif # IDPF
+2 -1
drivers/net/ethernet/intel/idpf/Makefile
··· 12 12 idpf_ethtool.o \ 13 13 idpf_lib.o \ 14 14 idpf_main.o \ 15 - idpf_singleq_txrx.o \ 16 15 idpf_txrx.o \ 17 16 idpf_virtchnl.o \ 18 17 idpf_vf_dev.o 18 + 19 + idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o
+4 -7
drivers/net/ethernet/intel/idpf/idpf.h
··· 17 17 #include <linux/sctp.h> 18 18 #include <linux/ethtool_netlink.h> 19 19 #include <net/gro.h> 20 - #include <linux/dim.h> 21 20 22 21 #include "virtchnl2.h" 23 - #include "idpf_lan_txrx.h" 24 22 #include "idpf_txrx.h" 25 23 #include "idpf_controlq.h" 26 24 ··· 264 266 * the worst case. 265 267 * @num_bufqs_per_qgrp: Buffer queues per RX queue in a given grouping 266 268 * @bufq_desc_count: Buffer queue descriptor count 267 - * @bufq_size: Size of buffers in ring (e.g. 2K, 4K, etc) 268 269 * @num_rxq_grp: Number of RX queues in a group 269 270 * @rxq_grps: Total number of RX groups. Number of groups * number of RX per 270 271 * group will yield total number of RX queues. ··· 299 302 u16 num_txq_grp; 300 303 struct idpf_txq_group *txq_grps; 301 304 u32 txq_model; 302 - struct idpf_queue **txqs; 305 + struct idpf_tx_queue **txqs; 303 306 bool crc_enable; 304 307 305 308 u16 num_rxq; ··· 307 310 u32 rxq_desc_count; 308 311 u8 num_bufqs_per_qgrp; 309 312 u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 310 - u32 bufq_size[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 311 313 u16 num_rxq_grp; 312 314 struct idpf_rxq_group *rxq_grps; 313 315 u32 rxq_model; 314 - struct idpf_rx_ptype_decoded rx_ptype_lkup[IDPF_RX_MAX_PTYPE]; 316 + struct libeth_rx_pt *rx_ptype_lkup; 315 317 316 318 struct idpf_adapter *adapter; 317 319 struct net_device *netdev; ··· 597 601 */ 598 602 static inline int idpf_is_queue_model_split(u16 q_model) 599 603 { 600 - return q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT; 604 + return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) || 605 + q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT; 601 606 } 602 607 603 608 #define idpf_is_cap_ena(adapter, field, flag) \
+69 -83
drivers/net/ethernet/intel/idpf/idpf_ethtool.c
··· 437 437 .stat_offset = offsetof(_type, _stat) \ 438 438 } 439 439 440 - /* Helper macro for defining some statistics related to queues */ 441 - #define IDPF_QUEUE_STAT(_name, _stat) \ 442 - IDPF_STAT(struct idpf_queue, _name, _stat) 440 + /* Helper macros for defining some statistics related to queues */ 441 + #define IDPF_RX_QUEUE_STAT(_name, _stat) \ 442 + IDPF_STAT(struct idpf_rx_queue, _name, _stat) 443 + #define IDPF_TX_QUEUE_STAT(_name, _stat) \ 444 + IDPF_STAT(struct idpf_tx_queue, _name, _stat) 443 445 444 446 /* Stats associated with a Tx queue */ 445 447 static const struct idpf_stats idpf_gstrings_tx_queue_stats[] = { 446 - IDPF_QUEUE_STAT("pkts", q_stats.tx.packets), 447 - IDPF_QUEUE_STAT("bytes", q_stats.tx.bytes), 448 - IDPF_QUEUE_STAT("lso_pkts", q_stats.tx.lso_pkts), 448 + IDPF_TX_QUEUE_STAT("pkts", q_stats.packets), 449 + IDPF_TX_QUEUE_STAT("bytes", q_stats.bytes), 450 + IDPF_TX_QUEUE_STAT("lso_pkts", q_stats.lso_pkts), 449 451 }; 450 452 451 453 /* Stats associated with an Rx queue */ 452 454 static const struct idpf_stats idpf_gstrings_rx_queue_stats[] = { 453 - IDPF_QUEUE_STAT("pkts", q_stats.rx.packets), 454 - IDPF_QUEUE_STAT("bytes", q_stats.rx.bytes), 455 - IDPF_QUEUE_STAT("rx_gro_hw_pkts", q_stats.rx.rsc_pkts), 455 + IDPF_RX_QUEUE_STAT("pkts", q_stats.packets), 456 + IDPF_RX_QUEUE_STAT("bytes", q_stats.bytes), 457 + IDPF_RX_QUEUE_STAT("rx_gro_hw_pkts", q_stats.rsc_pkts), 456 458 }; 457 459 458 460 #define IDPF_TX_QUEUE_STATS_LEN ARRAY_SIZE(idpf_gstrings_tx_queue_stats) ··· 565 563 for (i = 0; i < vport_config->max_q.max_rxq; i++) 566 564 idpf_add_qstat_strings(&data, idpf_gstrings_rx_queue_stats, 567 565 "rx", i); 568 - 569 - page_pool_ethtool_stats_get_strings(data); 570 566 } 571 567 572 568 /** ··· 598 598 struct idpf_netdev_priv *np = netdev_priv(netdev); 599 599 struct idpf_vport_config *vport_config; 600 600 u16 max_txq, max_rxq; 601 - unsigned int size; 602 601 603 602 if (sset != ETH_SS_STATS) 604 603 return -EINVAL; ··· 616 617 max_txq = vport_config->max_q.max_txq; 617 618 max_rxq = vport_config->max_q.max_rxq; 618 619 619 - size = IDPF_PORT_STATS_LEN + (IDPF_TX_QUEUE_STATS_LEN * max_txq) + 620 + return IDPF_PORT_STATS_LEN + (IDPF_TX_QUEUE_STATS_LEN * max_txq) + 620 621 (IDPF_RX_QUEUE_STATS_LEN * max_rxq); 621 - size += page_pool_ethtool_stats_get_count(); 622 - 623 - return size; 624 622 } 625 623 626 624 /** ··· 629 633 * Copies the stat data defined by the pointer and stat structure pair into 630 634 * the memory supplied as data. If the pointer is null, data will be zero'd. 631 635 */ 632 - static void idpf_add_one_ethtool_stat(u64 *data, void *pstat, 636 + static void idpf_add_one_ethtool_stat(u64 *data, const void *pstat, 633 637 const struct idpf_stats *stat) 634 638 { 635 639 char *p; ··· 667 671 * idpf_add_queue_stats - copy queue statistics into supplied buffer 668 672 * @data: ethtool stats buffer 669 673 * @q: the queue to copy 674 + * @type: type of the queue 670 675 * 671 676 * Queue statistics must be copied while protected by u64_stats_fetch_begin, 672 677 * so we can't directly use idpf_add_ethtool_stats. Assumes that queue stats ··· 678 681 * 679 682 * This function expects to be called while under rcu_read_lock(). 680 683 */ 681 - static void idpf_add_queue_stats(u64 **data, struct idpf_queue *q) 684 + static void idpf_add_queue_stats(u64 **data, const void *q, 685 + enum virtchnl2_queue_type type) 682 686 { 687 + const struct u64_stats_sync *stats_sync; 683 688 const struct idpf_stats *stats; 684 689 unsigned int start; 685 690 unsigned int size; 686 691 unsigned int i; 687 692 688 - if (q->q_type == VIRTCHNL2_QUEUE_TYPE_RX) { 693 + if (type == VIRTCHNL2_QUEUE_TYPE_RX) { 689 694 size = IDPF_RX_QUEUE_STATS_LEN; 690 695 stats = idpf_gstrings_rx_queue_stats; 696 + stats_sync = &((const struct idpf_rx_queue *)q)->stats_sync; 691 697 } else { 692 698 size = IDPF_TX_QUEUE_STATS_LEN; 693 699 stats = idpf_gstrings_tx_queue_stats; 700 + stats_sync = &((const struct idpf_tx_queue *)q)->stats_sync; 694 701 } 695 702 696 703 /* To avoid invalid statistics values, ensure that we keep retrying ··· 702 701 * u64_stats_fetch_retry. 703 702 */ 704 703 do { 705 - start = u64_stats_fetch_begin(&q->stats_sync); 704 + start = u64_stats_fetch_begin(stats_sync); 706 705 for (i = 0; i < size; i++) 707 706 idpf_add_one_ethtool_stat(&(*data)[i], q, &stats[i]); 708 - } while (u64_stats_fetch_retry(&q->stats_sync, start)); 707 + } while (u64_stats_fetch_retry(stats_sync, start)); 709 708 710 709 /* Once we successfully copy the stats in, update the data pointer */ 711 710 *data += size; ··· 794 793 for (j = 0; j < num_rxq; j++) { 795 794 u64 hw_csum_err, hsplit, hsplit_hbo, bad_descs; 796 795 struct idpf_rx_queue_stats *stats; 797 - struct idpf_queue *rxq; 796 + struct idpf_rx_queue *rxq; 798 797 unsigned int start; 799 798 800 799 if (idpf_is_queue_model_split(vport->rxq_model)) ··· 808 807 do { 809 808 start = u64_stats_fetch_begin(&rxq->stats_sync); 810 809 811 - stats = &rxq->q_stats.rx; 810 + stats = &rxq->q_stats; 812 811 hw_csum_err = u64_stats_read(&stats->hw_csum_err); 813 812 hsplit = u64_stats_read(&stats->hsplit_pkts); 814 813 hsplit_hbo = u64_stats_read(&stats->hsplit_buf_ovf); ··· 829 828 830 829 for (j = 0; j < txq_grp->num_txq; j++) { 831 830 u64 linearize, qbusy, skb_drops, dma_map_errs; 832 - struct idpf_queue *txq = txq_grp->txqs[j]; 831 + struct idpf_tx_queue *txq = txq_grp->txqs[j]; 833 832 struct idpf_tx_queue_stats *stats; 834 833 unsigned int start; 835 834 ··· 839 838 do { 840 839 start = u64_stats_fetch_begin(&txq->stats_sync); 841 840 842 - stats = &txq->q_stats.tx; 841 + stats = &txq->q_stats; 843 842 linearize = u64_stats_read(&stats->linearize); 844 843 qbusy = u64_stats_read(&stats->q_busy); 845 844 skb_drops = u64_stats_read(&stats->skb_drops); ··· 870 869 { 871 870 struct idpf_netdev_priv *np = netdev_priv(netdev); 872 871 struct idpf_vport_config *vport_config; 873 - struct page_pool_stats pp_stats = { }; 874 872 struct idpf_vport *vport; 875 873 unsigned int total = 0; 876 874 unsigned int i, j; ··· 896 896 qtype = VIRTCHNL2_QUEUE_TYPE_TX; 897 897 898 898 for (j = 0; j < txq_grp->num_txq; j++, total++) { 899 - struct idpf_queue *txq = txq_grp->txqs[j]; 899 + struct idpf_tx_queue *txq = txq_grp->txqs[j]; 900 900 901 901 if (!txq) 902 902 idpf_add_empty_queue_stats(&data, qtype); 903 903 else 904 - idpf_add_queue_stats(&data, txq); 904 + idpf_add_queue_stats(&data, txq, qtype); 905 905 } 906 906 } 907 907 ··· 929 929 num_rxq = rxq_grp->singleq.num_rxq; 930 930 931 931 for (j = 0; j < num_rxq; j++, total++) { 932 - struct idpf_queue *rxq; 932 + struct idpf_rx_queue *rxq; 933 933 934 934 if (is_splitq) 935 935 rxq = &rxq_grp->splitq.rxq_sets[j]->rxq; ··· 938 938 if (!rxq) 939 939 idpf_add_empty_queue_stats(&data, qtype); 940 940 else 941 - idpf_add_queue_stats(&data, rxq); 942 - 943 - /* In splitq mode, don't get page pool stats here since 944 - * the pools are attached to the buffer queues 945 - */ 946 - if (is_splitq) 947 - continue; 948 - 949 - if (rxq) 950 - page_pool_get_stats(rxq->pp, &pp_stats); 951 - } 952 - } 953 - 954 - for (i = 0; i < vport->num_rxq_grp; i++) { 955 - for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { 956 - struct idpf_queue *rxbufq = 957 - &vport->rxq_grps[i].splitq.bufq_sets[j].bufq; 958 - 959 - page_pool_get_stats(rxbufq->pp, &pp_stats); 941 + idpf_add_queue_stats(&data, rxq, qtype); 960 942 } 961 943 } 962 944 963 945 for (; total < vport_config->max_q.max_rxq; total++) 964 946 idpf_add_empty_queue_stats(&data, VIRTCHNL2_QUEUE_TYPE_RX); 965 - 966 - page_pool_ethtool_stats_get(data, &pp_stats); 967 947 968 948 rcu_read_unlock(); 969 949 ··· 951 971 } 952 972 953 973 /** 954 - * idpf_find_rxq - find rxq from q index 974 + * idpf_find_rxq_vec - find rxq vector from q index 955 975 * @vport: virtual port associated to queue 956 976 * @q_num: q index used to find queue 957 977 * 958 - * returns pointer to rx queue 978 + * returns pointer to rx vector 959 979 */ 960 - static struct idpf_queue *idpf_find_rxq(struct idpf_vport *vport, int q_num) 980 + static struct idpf_q_vector *idpf_find_rxq_vec(const struct idpf_vport *vport, 981 + int q_num) 961 982 { 962 983 int q_grp, q_idx; 963 984 964 985 if (!idpf_is_queue_model_split(vport->rxq_model)) 965 - return vport->rxq_grps->singleq.rxqs[q_num]; 986 + return vport->rxq_grps->singleq.rxqs[q_num]->q_vector; 966 987 967 988 q_grp = q_num / IDPF_DFLT_SPLITQ_RXQ_PER_GROUP; 968 989 q_idx = q_num % IDPF_DFLT_SPLITQ_RXQ_PER_GROUP; 969 990 970 - return &vport->rxq_grps[q_grp].splitq.rxq_sets[q_idx]->rxq; 991 + return vport->rxq_grps[q_grp].splitq.rxq_sets[q_idx]->rxq.q_vector; 971 992 } 972 993 973 994 /** 974 - * idpf_find_txq - find txq from q index 995 + * idpf_find_txq_vec - find txq vector from q index 975 996 * @vport: virtual port associated to queue 976 997 * @q_num: q index used to find queue 977 998 * 978 - * returns pointer to tx queue 999 + * returns pointer to tx vector 979 1000 */ 980 - static struct idpf_queue *idpf_find_txq(struct idpf_vport *vport, int q_num) 1001 + static struct idpf_q_vector *idpf_find_txq_vec(const struct idpf_vport *vport, 1002 + int q_num) 981 1003 { 982 1004 int q_grp; 983 1005 984 1006 if (!idpf_is_queue_model_split(vport->txq_model)) 985 - return vport->txqs[q_num]; 1007 + return vport->txqs[q_num]->q_vector; 986 1008 987 1009 q_grp = q_num / IDPF_DFLT_SPLITQ_TXQ_PER_GROUP; 988 1010 989 - return vport->txq_grps[q_grp].complq; 1011 + return vport->txq_grps[q_grp].complq->q_vector; 990 1012 } 991 1013 992 1014 /** 993 1015 * __idpf_get_q_coalesce - get ITR values for specific queue 994 1016 * @ec: ethtool structure to fill with driver's coalesce settings 995 - * @q: quuee of Rx or Tx 1017 + * @q_vector: queue vector corresponding to this queue 1018 + * @type: queue type 996 1019 */ 997 1020 static void __idpf_get_q_coalesce(struct ethtool_coalesce *ec, 998 - struct idpf_queue *q) 1021 + const struct idpf_q_vector *q_vector, 1022 + enum virtchnl2_queue_type type) 999 1023 { 1000 - if (q->q_type == VIRTCHNL2_QUEUE_TYPE_RX) { 1024 + if (type == VIRTCHNL2_QUEUE_TYPE_RX) { 1001 1025 ec->use_adaptive_rx_coalesce = 1002 - IDPF_ITR_IS_DYNAMIC(q->q_vector->rx_intr_mode); 1003 - ec->rx_coalesce_usecs = q->q_vector->rx_itr_value; 1026 + IDPF_ITR_IS_DYNAMIC(q_vector->rx_intr_mode); 1027 + ec->rx_coalesce_usecs = q_vector->rx_itr_value; 1004 1028 } else { 1005 1029 ec->use_adaptive_tx_coalesce = 1006 - IDPF_ITR_IS_DYNAMIC(q->q_vector->tx_intr_mode); 1007 - ec->tx_coalesce_usecs = q->q_vector->tx_itr_value; 1030 + IDPF_ITR_IS_DYNAMIC(q_vector->tx_intr_mode); 1031 + ec->tx_coalesce_usecs = q_vector->tx_itr_value; 1008 1032 } 1009 1033 } 1010 1034 ··· 1024 1040 struct ethtool_coalesce *ec, 1025 1041 u32 q_num) 1026 1042 { 1027 - struct idpf_netdev_priv *np = netdev_priv(netdev); 1028 - struct idpf_vport *vport; 1043 + const struct idpf_netdev_priv *np = netdev_priv(netdev); 1044 + const struct idpf_vport *vport; 1029 1045 int err = 0; 1030 1046 1031 1047 idpf_vport_ctrl_lock(netdev); ··· 1040 1056 } 1041 1057 1042 1058 if (q_num < vport->num_rxq) 1043 - __idpf_get_q_coalesce(ec, idpf_find_rxq(vport, q_num)); 1059 + __idpf_get_q_coalesce(ec, idpf_find_rxq_vec(vport, q_num), 1060 + VIRTCHNL2_QUEUE_TYPE_RX); 1044 1061 1045 1062 if (q_num < vport->num_txq) 1046 - __idpf_get_q_coalesce(ec, idpf_find_txq(vport, q_num)); 1063 + __idpf_get_q_coalesce(ec, idpf_find_txq_vec(vport, q_num), 1064 + VIRTCHNL2_QUEUE_TYPE_TX); 1047 1065 1048 1066 unlock_mutex: 1049 1067 idpf_vport_ctrl_unlock(netdev); ··· 1089 1103 /** 1090 1104 * __idpf_set_q_coalesce - set ITR values for specific queue 1091 1105 * @ec: ethtool structure from user to update ITR settings 1092 - * @q: queue for which itr values has to be set 1106 + * @qv: queue vector for which itr values has to be set 1093 1107 * @is_rxq: is queue type rx 1094 1108 * 1095 1109 * Returns 0 on success, negative otherwise. 1096 1110 */ 1097 - static int __idpf_set_q_coalesce(struct ethtool_coalesce *ec, 1098 - struct idpf_queue *q, bool is_rxq) 1111 + static int __idpf_set_q_coalesce(const struct ethtool_coalesce *ec, 1112 + struct idpf_q_vector *qv, bool is_rxq) 1099 1113 { 1100 1114 u32 use_adaptive_coalesce, coalesce_usecs; 1101 - struct idpf_q_vector *qv = q->q_vector; 1102 1115 bool is_dim_ena = false; 1103 1116 u16 itr_val; 1104 1117 ··· 1113 1128 itr_val = qv->tx_itr_value; 1114 1129 } 1115 1130 if (coalesce_usecs != itr_val && use_adaptive_coalesce) { 1116 - netdev_err(q->vport->netdev, "Cannot set coalesce usecs if adaptive enabled\n"); 1131 + netdev_err(qv->vport->netdev, "Cannot set coalesce usecs if adaptive enabled\n"); 1117 1132 1118 1133 return -EINVAL; 1119 1134 } ··· 1122 1137 return 0; 1123 1138 1124 1139 if (coalesce_usecs > IDPF_ITR_MAX) { 1125 - netdev_err(q->vport->netdev, 1140 + netdev_err(qv->vport->netdev, 1126 1141 "Invalid value, %d-usecs range is 0-%d\n", 1127 1142 coalesce_usecs, IDPF_ITR_MAX); 1128 1143 ··· 1131 1146 1132 1147 if (coalesce_usecs % 2) { 1133 1148 coalesce_usecs--; 1134 - netdev_info(q->vport->netdev, 1149 + netdev_info(qv->vport->netdev, 1135 1150 "HW only supports even ITR values, ITR rounded to %d\n", 1136 1151 coalesce_usecs); 1137 1152 } ··· 1170 1185 * 1171 1186 * Return 0 on success, and negative on failure 1172 1187 */ 1173 - static int idpf_set_q_coalesce(struct idpf_vport *vport, 1174 - struct ethtool_coalesce *ec, 1188 + static int idpf_set_q_coalesce(const struct idpf_vport *vport, 1189 + const struct ethtool_coalesce *ec, 1175 1190 int q_num, bool is_rxq) 1176 1191 { 1177 - struct idpf_queue *q; 1192 + struct idpf_q_vector *qv; 1178 1193 1179 - q = is_rxq ? idpf_find_rxq(vport, q_num) : idpf_find_txq(vport, q_num); 1194 + qv = is_rxq ? idpf_find_rxq_vec(vport, q_num) : 1195 + idpf_find_txq_vec(vport, q_num); 1180 1196 1181 - if (q && __idpf_set_q_coalesce(ec, q, is_rxq)) 1197 + if (qv && __idpf_set_q_coalesce(ec, qv, is_rxq)) 1182 1198 return -EINVAL; 1183 1199 1184 1200 return 0;
+2
drivers/net/ethernet/intel/idpf/idpf_lan_txrx.h
··· 4 4 #ifndef _IDPF_LAN_TXRX_H_ 5 5 #define _IDPF_LAN_TXRX_H_ 6 6 7 + #include <linux/bits.h> 8 + 7 9 enum idpf_rss_hash { 8 10 IDPF_HASH_INVALID = 0, 9 11 /* Values 1 - 28 are reserved for future use */
+16 -72
drivers/net/ethernet/intel/idpf/idpf_lib.c
··· 4 4 #include "idpf.h" 5 5 #include "idpf_virtchnl.h" 6 6 7 - static const struct net_device_ops idpf_netdev_ops_splitq; 8 - static const struct net_device_ops idpf_netdev_ops_singleq; 7 + static const struct net_device_ops idpf_netdev_ops; 9 8 10 9 /** 11 10 * idpf_init_vector_stack - Fill the MSIX vector stack with vector index ··· 68 69 static void idpf_mb_intr_rel_irq(struct idpf_adapter *adapter) 69 70 { 70 71 clear_bit(IDPF_MB_INTR_MODE, adapter->flags); 71 - free_irq(adapter->msix_entries[0].vector, adapter); 72 + kfree(free_irq(adapter->msix_entries[0].vector, adapter)); 72 73 queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0); 73 74 } 74 75 ··· 123 124 */ 124 125 static int idpf_mb_intr_req_irq(struct idpf_adapter *adapter) 125 126 { 126 - struct idpf_q_vector *mb_vector = &adapter->mb_vector; 127 127 int irq_num, mb_vidx = 0, err; 128 + char *name; 128 129 129 130 irq_num = adapter->msix_entries[mb_vidx].vector; 130 - mb_vector->name = kasprintf(GFP_KERNEL, "%s-%s-%d", 131 - dev_driver_string(&adapter->pdev->dev), 132 - "Mailbox", mb_vidx); 133 - err = request_irq(irq_num, adapter->irq_mb_handler, 0, 134 - mb_vector->name, adapter); 131 + name = kasprintf(GFP_KERNEL, "%s-%s-%d", 132 + dev_driver_string(&adapter->pdev->dev), 133 + "Mailbox", mb_vidx); 134 + err = request_irq(irq_num, adapter->irq_mb_handler, 0, name, adapter); 135 135 if (err) { 136 136 dev_err(&adapter->pdev->dev, 137 137 "IRQ request for mailbox failed, error: %d\n", err); ··· 763 765 } 764 766 765 767 /* assign netdev_ops */ 766 - if (idpf_is_queue_model_split(vport->txq_model)) 767 - netdev->netdev_ops = &idpf_netdev_ops_splitq; 768 - else 769 - netdev->netdev_ops = &idpf_netdev_ops_singleq; 768 + netdev->netdev_ops = &idpf_netdev_ops; 770 769 771 770 /* setup watchdog timeout value to be 5 second */ 772 771 netdev->watchdog_timeo = 5 * HZ; ··· 940 945 static void idpf_decfg_netdev(struct idpf_vport *vport) 941 946 { 942 947 struct idpf_adapter *adapter = vport->adapter; 948 + 949 + kfree(vport->rx_ptype_lkup); 950 + vport->rx_ptype_lkup = NULL; 943 951 944 952 unregister_netdev(vport->netdev); 945 953 free_netdev(vport->netdev); ··· 1316 1318 1317 1319 if (idpf_is_queue_model_split(vport->rxq_model)) { 1318 1320 for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { 1319 - struct idpf_queue *q = 1321 + const struct idpf_buf_queue *q = 1320 1322 &grp->splitq.bufq_sets[j].bufq; 1321 1323 1322 1324 writel(q->next_to_alloc, q->tail); 1323 1325 } 1324 1326 } else { 1325 1327 for (j = 0; j < grp->singleq.num_rxq; j++) { 1326 - struct idpf_queue *q = 1328 + const struct idpf_rx_queue *q = 1327 1329 grp->singleq.rxqs[j]; 1328 1330 1329 1331 writel(q->next_to_alloc, q->tail); ··· 1853 1855 enum idpf_vport_state current_state = np->state; 1854 1856 struct idpf_adapter *adapter = vport->adapter; 1855 1857 struct idpf_vport *new_vport; 1856 - int err, i; 1858 + int err; 1857 1859 1858 1860 /* If the system is low on memory, we can end up in bad state if we 1859 1861 * free all the memory for queue resources and try to allocate them ··· 1926 1928 * mutexes applies here. We do not want to mess with those if possible. 1927 1929 */ 1928 1930 memcpy(vport, new_vport, offsetof(struct idpf_vport, link_speed_mbps)); 1929 - 1930 - /* Since idpf_vport_queues_alloc was called with new_port, the queue 1931 - * back pointers are currently pointing to the local new_vport. Reset 1932 - * the backpointers to the original vport here 1933 - */ 1934 - for (i = 0; i < vport->num_txq_grp; i++) { 1935 - struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 1936 - int j; 1937 - 1938 - tx_qgrp->vport = vport; 1939 - for (j = 0; j < tx_qgrp->num_txq; j++) 1940 - tx_qgrp->txqs[j]->vport = vport; 1941 - 1942 - if (idpf_is_queue_model_split(vport->txq_model)) 1943 - tx_qgrp->complq->vport = vport; 1944 - } 1945 - 1946 - for (i = 0; i < vport->num_rxq_grp; i++) { 1947 - struct idpf_rxq_group *rx_qgrp = &vport->rxq_grps[i]; 1948 - struct idpf_queue *q; 1949 - u16 num_rxq; 1950 - int j; 1951 - 1952 - rx_qgrp->vport = vport; 1953 - for (j = 0; j < vport->num_bufqs_per_qgrp; j++) 1954 - rx_qgrp->splitq.bufq_sets[j].bufq.vport = vport; 1955 - 1956 - if (idpf_is_queue_model_split(vport->rxq_model)) 1957 - num_rxq = rx_qgrp->splitq.num_rxq_sets; 1958 - else 1959 - num_rxq = rx_qgrp->singleq.num_rxq; 1960 - 1961 - for (j = 0; j < num_rxq; j++) { 1962 - if (idpf_is_queue_model_split(vport->rxq_model)) 1963 - q = &rx_qgrp->splitq.rxq_sets[j]->rxq; 1964 - else 1965 - q = rx_qgrp->singleq.rxqs[j]; 1966 - q->vport = vport; 1967 - } 1968 - } 1969 1931 1970 1932 if (reset_cause == IDPF_SR_Q_CHANGE) 1971 1933 idpf_vport_alloc_vec_indexes(vport); ··· 2351 2393 mem->pa = 0; 2352 2394 } 2353 2395 2354 - static const struct net_device_ops idpf_netdev_ops_splitq = { 2396 + static const struct net_device_ops idpf_netdev_ops = { 2355 2397 .ndo_open = idpf_open, 2356 2398 .ndo_stop = idpf_stop, 2357 - .ndo_start_xmit = idpf_tx_splitq_start, 2358 - .ndo_features_check = idpf_features_check, 2359 - .ndo_set_rx_mode = idpf_set_rx_mode, 2360 - .ndo_validate_addr = eth_validate_addr, 2361 - .ndo_set_mac_address = idpf_set_mac, 2362 - .ndo_change_mtu = idpf_change_mtu, 2363 - .ndo_get_stats64 = idpf_get_stats64, 2364 - .ndo_set_features = idpf_set_features, 2365 - .ndo_tx_timeout = idpf_tx_timeout, 2366 - }; 2367 - 2368 - static const struct net_device_ops idpf_netdev_ops_singleq = { 2369 - .ndo_open = idpf_open, 2370 - .ndo_stop = idpf_stop, 2371 - .ndo_start_xmit = idpf_tx_singleq_start, 2399 + .ndo_start_xmit = idpf_tx_start, 2372 2400 .ndo_features_check = idpf_features_check, 2373 2401 .ndo_set_rx_mode = idpf_set_rx_mode, 2374 2402 .ndo_validate_addr = eth_validate_addr,
+1
drivers/net/ethernet/intel/idpf/idpf_main.c
··· 8 8 #define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver" 9 9 10 10 MODULE_DESCRIPTION(DRV_SUMMARY); 11 + MODULE_IMPORT_NS(LIBETH); 11 12 MODULE_LICENSE("GPL"); 12 13 13 14 /**
+137 -169
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* Copyright (C) 2023 Intel Corporation */ 3 3 4 + #include <net/libeth/rx.h> 5 + 4 6 #include "idpf.h" 5 7 6 8 /** ··· 188 186 * and gets a physical address for each memory location and programs 189 187 * it and the length into the transmit base mode descriptor. 190 188 */ 191 - static void idpf_tx_singleq_map(struct idpf_queue *tx_q, 189 + static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q, 192 190 struct idpf_tx_buf *first, 193 191 struct idpf_tx_offload_params *offloads) 194 192 { ··· 207 205 data_len = skb->data_len; 208 206 size = skb_headlen(skb); 209 207 210 - tx_desc = IDPF_BASE_TX_DESC(tx_q, i); 208 + tx_desc = &tx_q->base_tx[i]; 211 209 212 210 dma = dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE); 213 211 214 212 /* write each descriptor with CRC bit */ 215 - if (tx_q->vport->crc_enable) 213 + if (idpf_queue_has(CRC_EN, tx_q)) 216 214 td_cmd |= IDPF_TX_DESC_CMD_ICRC; 217 215 218 216 for (frag = &skb_shinfo(skb)->frags[0];; frag++) { ··· 241 239 i++; 242 240 243 241 if (i == tx_q->desc_count) { 244 - tx_desc = IDPF_BASE_TX_DESC(tx_q, 0); 242 + tx_desc = &tx_q->base_tx[0]; 245 243 i = 0; 246 244 } 247 245 ··· 261 259 i++; 262 260 263 261 if (i == tx_q->desc_count) { 264 - tx_desc = IDPF_BASE_TX_DESC(tx_q, 0); 262 + tx_desc = &tx_q->base_tx[0]; 265 263 i = 0; 266 264 } 267 265 ··· 287 285 /* set next_to_watch value indicating a packet is present */ 288 286 first->next_to_watch = tx_desc; 289 287 290 - nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx); 288 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 291 289 netdev_tx_sent_queue(nq, first->bytecount); 292 290 293 291 idpf_tx_buf_hw_update(tx_q, i, netdev_xmit_more()); ··· 301 299 * ring entry to reflect that this index is a context descriptor 302 300 */ 303 301 static struct idpf_base_tx_ctx_desc * 304 - idpf_tx_singleq_get_ctx_desc(struct idpf_queue *txq) 302 + idpf_tx_singleq_get_ctx_desc(struct idpf_tx_queue *txq) 305 303 { 306 304 struct idpf_base_tx_ctx_desc *ctx_desc; 307 305 int ntu = txq->next_to_use; ··· 309 307 memset(&txq->tx_buf[ntu], 0, sizeof(struct idpf_tx_buf)); 310 308 txq->tx_buf[ntu].ctx_entry = true; 311 309 312 - ctx_desc = IDPF_BASE_TX_CTX_DESC(txq, ntu); 310 + ctx_desc = &txq->base_ctx[ntu]; 313 311 314 312 IDPF_SINGLEQ_BUMP_RING_IDX(txq, ntu); 315 313 txq->next_to_use = ntu; ··· 322 320 * @txq: queue to send buffer on 323 321 * @offload: offload parameter structure 324 322 **/ 325 - static void idpf_tx_singleq_build_ctx_desc(struct idpf_queue *txq, 323 + static void idpf_tx_singleq_build_ctx_desc(struct idpf_tx_queue *txq, 326 324 struct idpf_tx_offload_params *offload) 327 325 { 328 326 struct idpf_base_tx_ctx_desc *desc = idpf_tx_singleq_get_ctx_desc(txq); ··· 335 333 qw1 |= FIELD_PREP(IDPF_TXD_CTX_QW1_MSS_M, offload->mss); 336 334 337 335 u64_stats_update_begin(&txq->stats_sync); 338 - u64_stats_inc(&txq->q_stats.tx.lso_pkts); 336 + u64_stats_inc(&txq->q_stats.lso_pkts); 339 337 u64_stats_update_end(&txq->stats_sync); 340 338 } 341 339 ··· 353 351 * 354 352 * Returns NETDEV_TX_OK if sent, else an error code 355 353 */ 356 - static netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, 357 - struct idpf_queue *tx_q) 354 + netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, 355 + struct idpf_tx_queue *tx_q) 358 356 { 359 357 struct idpf_tx_offload_params offload = { }; 360 358 struct idpf_tx_buf *first; ··· 411 409 } 412 410 413 411 /** 414 - * idpf_tx_singleq_start - Selects the right Tx queue to send buffer 415 - * @skb: send buffer 416 - * @netdev: network interface device structure 417 - * 418 - * Returns NETDEV_TX_OK if sent, else an error code 419 - */ 420 - netdev_tx_t idpf_tx_singleq_start(struct sk_buff *skb, 421 - struct net_device *netdev) 422 - { 423 - struct idpf_vport *vport = idpf_netdev_to_vport(netdev); 424 - struct idpf_queue *tx_q; 425 - 426 - tx_q = vport->txqs[skb_get_queue_mapping(skb)]; 427 - 428 - /* hardware can't handle really short frames, hardware padding works 429 - * beyond this point 430 - */ 431 - if (skb_put_padto(skb, IDPF_TX_MIN_PKT_LEN)) { 432 - idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false); 433 - 434 - return NETDEV_TX_OK; 435 - } 436 - 437 - return idpf_tx_singleq_frame(skb, tx_q); 438 - } 439 - 440 - /** 441 412 * idpf_tx_singleq_clean - Reclaim resources from queue 442 413 * @tx_q: Tx queue to clean 443 414 * @napi_budget: Used to determine if we are in netpoll 444 415 * @cleaned: returns number of packets cleaned 445 416 * 446 417 */ 447 - static bool idpf_tx_singleq_clean(struct idpf_queue *tx_q, int napi_budget, 418 + static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget, 448 419 int *cleaned) 449 420 { 450 - unsigned int budget = tx_q->vport->compln_clean_budget; 451 421 unsigned int total_bytes = 0, total_pkts = 0; 452 422 struct idpf_base_tx_desc *tx_desc; 423 + u32 budget = tx_q->clean_budget; 453 424 s16 ntc = tx_q->next_to_clean; 454 425 struct idpf_netdev_priv *np; 455 426 struct idpf_tx_buf *tx_buf; 456 - struct idpf_vport *vport; 457 427 struct netdev_queue *nq; 458 428 bool dont_wake; 459 429 460 - tx_desc = IDPF_BASE_TX_DESC(tx_q, ntc); 430 + tx_desc = &tx_q->base_tx[ntc]; 461 431 tx_buf = &tx_q->tx_buf[ntc]; 462 432 ntc -= tx_q->desc_count; 463 433 ··· 491 517 if (unlikely(!ntc)) { 492 518 ntc -= tx_q->desc_count; 493 519 tx_buf = tx_q->tx_buf; 494 - tx_desc = IDPF_BASE_TX_DESC(tx_q, 0); 520 + tx_desc = &tx_q->base_tx[0]; 495 521 } 496 522 497 523 /* unmap any remaining paged data */ ··· 514 540 if (unlikely(!ntc)) { 515 541 ntc -= tx_q->desc_count; 516 542 tx_buf = tx_q->tx_buf; 517 - tx_desc = IDPF_BASE_TX_DESC(tx_q, 0); 543 + tx_desc = &tx_q->base_tx[0]; 518 544 } 519 545 } while (likely(budget)); 520 546 ··· 524 550 *cleaned += total_pkts; 525 551 526 552 u64_stats_update_begin(&tx_q->stats_sync); 527 - u64_stats_add(&tx_q->q_stats.tx.packets, total_pkts); 528 - u64_stats_add(&tx_q->q_stats.tx.bytes, total_bytes); 553 + u64_stats_add(&tx_q->q_stats.packets, total_pkts); 554 + u64_stats_add(&tx_q->q_stats.bytes, total_bytes); 529 555 u64_stats_update_end(&tx_q->stats_sync); 530 556 531 - vport = tx_q->vport; 532 - np = netdev_priv(vport->netdev); 533 - nq = netdev_get_tx_queue(vport->netdev, tx_q->idx); 557 + np = netdev_priv(tx_q->netdev); 558 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 534 559 535 560 dont_wake = np->state != __IDPF_VPORT_UP || 536 - !netif_carrier_ok(vport->netdev); 561 + !netif_carrier_ok(tx_q->netdev); 537 562 __netif_txq_completed_wake(nq, total_pkts, total_bytes, 538 563 IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH, 539 564 dont_wake); ··· 557 584 558 585 budget_per_q = num_txq ? max(budget / num_txq, 1) : 0; 559 586 for (i = 0; i < num_txq; i++) { 560 - struct idpf_queue *q; 587 + struct idpf_tx_queue *q; 561 588 562 589 q = q_vec->tx[i]; 563 590 clean_complete &= idpf_tx_singleq_clean(q, budget_per_q, ··· 587 614 588 615 /** 589 616 * idpf_rx_singleq_is_non_eop - process handling of non-EOP buffers 590 - * @rxq: Rx ring being processed 591 617 * @rx_desc: Rx descriptor for current buffer 592 - * @skb: Current socket buffer containing buffer in progress 593 - * @ntc: next to clean 594 618 */ 595 - static bool idpf_rx_singleq_is_non_eop(struct idpf_queue *rxq, 596 - union virtchnl2_rx_desc *rx_desc, 597 - struct sk_buff *skb, u16 ntc) 619 + static bool idpf_rx_singleq_is_non_eop(const union virtchnl2_rx_desc *rx_desc) 598 620 { 599 621 /* if we are the last buffer then there is nothing else to do */ 600 622 if (likely(idpf_rx_singleq_test_staterr(rx_desc, IDPF_RXD_EOF_SINGLEQ))) ··· 603 635 * @rxq: Rx ring being processed 604 636 * @skb: skb currently being received and modified 605 637 * @csum_bits: checksum bits from descriptor 606 - * @ptype: the packet type decoded by hardware 638 + * @decoded: the packet type decoded by hardware 607 639 * 608 640 * skb->protocol must be set before this function is called 609 641 */ 610 - static void idpf_rx_singleq_csum(struct idpf_queue *rxq, struct sk_buff *skb, 611 - struct idpf_rx_csum_decoded *csum_bits, 612 - u16 ptype) 642 + static void idpf_rx_singleq_csum(struct idpf_rx_queue *rxq, 643 + struct sk_buff *skb, 644 + struct idpf_rx_csum_decoded csum_bits, 645 + struct libeth_rx_pt decoded) 613 646 { 614 - struct idpf_rx_ptype_decoded decoded; 615 647 bool ipv4, ipv6; 616 648 617 649 /* check if Rx checksum is enabled */ 618 - if (unlikely(!(rxq->vport->netdev->features & NETIF_F_RXCSUM))) 650 + if (!libeth_rx_pt_has_checksum(rxq->netdev, decoded)) 619 651 return; 620 652 621 653 /* check if HW has decoded the packet and checksum */ 622 - if (unlikely(!(csum_bits->l3l4p))) 654 + if (unlikely(!csum_bits.l3l4p)) 623 655 return; 624 656 625 - decoded = rxq->vport->rx_ptype_lkup[ptype]; 626 - if (unlikely(!(decoded.known && decoded.outer_ip))) 627 - return; 628 - 629 - ipv4 = IDPF_RX_PTYPE_TO_IPV(&decoded, IDPF_RX_PTYPE_OUTER_IPV4); 630 - ipv6 = IDPF_RX_PTYPE_TO_IPV(&decoded, IDPF_RX_PTYPE_OUTER_IPV6); 657 + ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4; 658 + ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6; 631 659 632 660 /* Check if there were any checksum errors */ 633 - if (unlikely(ipv4 && (csum_bits->ipe || csum_bits->eipe))) 661 + if (unlikely(ipv4 && (csum_bits.ipe || csum_bits.eipe))) 634 662 goto checksum_fail; 635 663 636 664 /* Device could not do any checksum offload for certain extension 637 665 * headers as indicated by setting IPV6EXADD bit 638 666 */ 639 - if (unlikely(ipv6 && csum_bits->ipv6exadd)) 667 + if (unlikely(ipv6 && csum_bits.ipv6exadd)) 640 668 return; 641 669 642 670 /* check for L4 errors and handle packets that were not able to be 643 671 * checksummed due to arrival speed 644 672 */ 645 - if (unlikely(csum_bits->l4e)) 673 + if (unlikely(csum_bits.l4e)) 646 674 goto checksum_fail; 647 675 648 - if (unlikely(csum_bits->nat && csum_bits->eudpe)) 676 + if (unlikely(csum_bits.nat && csum_bits.eudpe)) 649 677 goto checksum_fail; 650 678 651 679 /* Handle packets that were not able to be checksummed due to arrival 652 680 * speed, in this case the stack can compute the csum. 653 681 */ 654 - if (unlikely(csum_bits->pprs)) 682 + if (unlikely(csum_bits.pprs)) 655 683 return; 656 684 657 685 /* If there is an outer header present that might contain a checksum 658 686 * we need to bump the checksum level by 1 to reflect the fact that 659 687 * we are indicating we validated the inner checksum. 660 688 */ 661 - if (decoded.tunnel_type >= IDPF_RX_PTYPE_TUNNEL_IP_GRENAT) 689 + if (decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT) 662 690 skb->csum_level = 1; 663 691 664 - /* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */ 665 - switch (decoded.inner_prot) { 666 - case IDPF_RX_PTYPE_INNER_PROT_ICMP: 667 - case IDPF_RX_PTYPE_INNER_PROT_TCP: 668 - case IDPF_RX_PTYPE_INNER_PROT_UDP: 669 - case IDPF_RX_PTYPE_INNER_PROT_SCTP: 670 - skb->ip_summed = CHECKSUM_UNNECESSARY; 671 - return; 672 - default: 673 - return; 674 - } 692 + skb->ip_summed = CHECKSUM_UNNECESSARY; 693 + return; 675 694 676 695 checksum_fail: 677 696 u64_stats_update_begin(&rxq->stats_sync); 678 - u64_stats_inc(&rxq->q_stats.rx.hw_csum_err); 697 + u64_stats_inc(&rxq->q_stats.hw_csum_err); 679 698 u64_stats_update_end(&rxq->stats_sync); 680 699 } 681 700 682 701 /** 683 702 * idpf_rx_singleq_base_csum - Indicate in skb if hw indicated a good cksum 684 - * @rx_q: Rx completion queue 685 - * @skb: skb currently being received and modified 686 703 * @rx_desc: the receive descriptor 687 - * @ptype: Rx packet type 688 704 * 689 705 * This function only operates on the VIRTCHNL2_RXDID_1_32B_BASE_M base 32byte 690 706 * descriptor writeback format. 707 + * 708 + * Return: parsed checksum status. 691 709 **/ 692 - static void idpf_rx_singleq_base_csum(struct idpf_queue *rx_q, 693 - struct sk_buff *skb, 694 - union virtchnl2_rx_desc *rx_desc, 695 - u16 ptype) 710 + static struct idpf_rx_csum_decoded 711 + idpf_rx_singleq_base_csum(const union virtchnl2_rx_desc *rx_desc) 696 712 { 697 - struct idpf_rx_csum_decoded csum_bits; 713 + struct idpf_rx_csum_decoded csum_bits = { }; 698 714 u32 rx_error, rx_status; 699 715 u64 qword; 700 716 ··· 697 745 rx_status); 698 746 csum_bits.ipv6exadd = FIELD_GET(VIRTCHNL2_RX_BASE_DESC_STATUS_IPV6EXADD_M, 699 747 rx_status); 700 - csum_bits.nat = 0; 701 - csum_bits.eudpe = 0; 702 748 703 - idpf_rx_singleq_csum(rx_q, skb, &csum_bits, ptype); 749 + return csum_bits; 704 750 } 705 751 706 752 /** 707 753 * idpf_rx_singleq_flex_csum - Indicate in skb if hw indicated a good cksum 708 - * @rx_q: Rx completion queue 709 - * @skb: skb currently being received and modified 710 754 * @rx_desc: the receive descriptor 711 - * @ptype: Rx packet type 712 755 * 713 756 * This function only operates on the VIRTCHNL2_RXDID_2_FLEX_SQ_NIC flexible 714 757 * descriptor writeback format. 758 + * 759 + * Return: parsed checksum status. 715 760 **/ 716 - static void idpf_rx_singleq_flex_csum(struct idpf_queue *rx_q, 717 - struct sk_buff *skb, 718 - union virtchnl2_rx_desc *rx_desc, 719 - u16 ptype) 761 + static struct idpf_rx_csum_decoded 762 + idpf_rx_singleq_flex_csum(const union virtchnl2_rx_desc *rx_desc) 720 763 { 721 - struct idpf_rx_csum_decoded csum_bits; 764 + struct idpf_rx_csum_decoded csum_bits = { }; 722 765 u16 rx_status0, rx_status1; 723 766 724 767 rx_status0 = le16_to_cpu(rx_desc->flex_nic_wb.status_error0); ··· 733 786 rx_status0); 734 787 csum_bits.nat = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_STATUS1_NAT_M, 735 788 rx_status1); 736 - csum_bits.pprs = 0; 737 789 738 - idpf_rx_singleq_csum(rx_q, skb, &csum_bits, ptype); 790 + return csum_bits; 739 791 } 740 792 741 793 /** ··· 747 801 * This function only operates on the VIRTCHNL2_RXDID_1_32B_BASE_M base 32byte 748 802 * descriptor writeback format. 749 803 **/ 750 - static void idpf_rx_singleq_base_hash(struct idpf_queue *rx_q, 804 + static void idpf_rx_singleq_base_hash(struct idpf_rx_queue *rx_q, 751 805 struct sk_buff *skb, 752 - union virtchnl2_rx_desc *rx_desc, 753 - struct idpf_rx_ptype_decoded *decoded) 806 + const union virtchnl2_rx_desc *rx_desc, 807 + struct libeth_rx_pt decoded) 754 808 { 755 809 u64 mask, qw1; 756 810 757 - if (unlikely(!(rx_q->vport->netdev->features & NETIF_F_RXHASH))) 811 + if (!libeth_rx_pt_has_hash(rx_q->netdev, decoded)) 758 812 return; 759 813 760 814 mask = VIRTCHNL2_RX_BASE_DESC_FLTSTAT_RSS_HASH_M; ··· 763 817 if (FIELD_GET(mask, qw1) == mask) { 764 818 u32 hash = le32_to_cpu(rx_desc->base_wb.qword0.hi_dword.rss); 765 819 766 - skb_set_hash(skb, hash, idpf_ptype_to_htype(decoded)); 820 + libeth_rx_pt_set_hash(skb, hash, decoded); 767 821 } 768 822 } 769 823 ··· 777 831 * This function only operates on the VIRTCHNL2_RXDID_2_FLEX_SQ_NIC flexible 778 832 * descriptor writeback format. 779 833 **/ 780 - static void idpf_rx_singleq_flex_hash(struct idpf_queue *rx_q, 834 + static void idpf_rx_singleq_flex_hash(struct idpf_rx_queue *rx_q, 781 835 struct sk_buff *skb, 782 - union virtchnl2_rx_desc *rx_desc, 783 - struct idpf_rx_ptype_decoded *decoded) 836 + const union virtchnl2_rx_desc *rx_desc, 837 + struct libeth_rx_pt decoded) 784 838 { 785 - if (unlikely(!(rx_q->vport->netdev->features & NETIF_F_RXHASH))) 839 + if (!libeth_rx_pt_has_hash(rx_q->netdev, decoded)) 786 840 return; 787 841 788 842 if (FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_STATUS0_RSS_VALID_M, 789 - le16_to_cpu(rx_desc->flex_nic_wb.status_error0))) 790 - skb_set_hash(skb, le32_to_cpu(rx_desc->flex_nic_wb.rss_hash), 791 - idpf_ptype_to_htype(decoded)); 843 + le16_to_cpu(rx_desc->flex_nic_wb.status_error0))) { 844 + u32 hash = le32_to_cpu(rx_desc->flex_nic_wb.rss_hash); 845 + 846 + libeth_rx_pt_set_hash(skb, hash, decoded); 847 + } 792 848 } 793 849 794 850 /** ··· 805 857 * order to populate the hash, checksum, VLAN, protocol, and 806 858 * other fields within the skb. 807 859 */ 808 - static void idpf_rx_singleq_process_skb_fields(struct idpf_queue *rx_q, 809 - struct sk_buff *skb, 810 - union virtchnl2_rx_desc *rx_desc, 811 - u16 ptype) 860 + static void 861 + idpf_rx_singleq_process_skb_fields(struct idpf_rx_queue *rx_q, 862 + struct sk_buff *skb, 863 + const union virtchnl2_rx_desc *rx_desc, 864 + u16 ptype) 812 865 { 813 - struct idpf_rx_ptype_decoded decoded = 814 - rx_q->vport->rx_ptype_lkup[ptype]; 866 + struct libeth_rx_pt decoded = rx_q->rx_ptype_lkup[ptype]; 867 + struct idpf_rx_csum_decoded csum_bits; 815 868 816 869 /* modifies the skb - consumes the enet header */ 817 - skb->protocol = eth_type_trans(skb, rx_q->vport->netdev); 870 + skb->protocol = eth_type_trans(skb, rx_q->netdev); 818 871 819 872 /* Check if we're using base mode descriptor IDs */ 820 873 if (rx_q->rxdids == VIRTCHNL2_RXDID_1_32B_BASE_M) { 821 - idpf_rx_singleq_base_hash(rx_q, skb, rx_desc, &decoded); 822 - idpf_rx_singleq_base_csum(rx_q, skb, rx_desc, ptype); 874 + idpf_rx_singleq_base_hash(rx_q, skb, rx_desc, decoded); 875 + csum_bits = idpf_rx_singleq_base_csum(rx_desc); 823 876 } else { 824 - idpf_rx_singleq_flex_hash(rx_q, skb, rx_desc, &decoded); 825 - idpf_rx_singleq_flex_csum(rx_q, skb, rx_desc, ptype); 877 + idpf_rx_singleq_flex_hash(rx_q, skb, rx_desc, decoded); 878 + csum_bits = idpf_rx_singleq_flex_csum(rx_desc); 826 879 } 880 + 881 + idpf_rx_singleq_csum(rx_q, skb, csum_bits, decoded); 882 + skb_record_rx_queue(skb, rx_q->idx); 883 + } 884 + 885 + /** 886 + * idpf_rx_buf_hw_update - Store the new tail and head values 887 + * @rxq: queue to bump 888 + * @val: new head index 889 + */ 890 + static void idpf_rx_buf_hw_update(struct idpf_rx_queue *rxq, u32 val) 891 + { 892 + rxq->next_to_use = val; 893 + 894 + if (unlikely(!rxq->tail)) 895 + return; 896 + 897 + /* writel has an implicit memory barrier */ 898 + writel(val, rxq->tail); 827 899 } 828 900 829 901 /** ··· 853 885 * 854 886 * Returns false if all allocations were successful, true if any fail 855 887 */ 856 - bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rx_q, 888 + bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rx_q, 857 889 u16 cleaned_count) 858 890 { 859 891 struct virtchnl2_singleq_rx_buf_desc *desc; 892 + const struct libeth_fq_fp fq = { 893 + .pp = rx_q->pp, 894 + .fqes = rx_q->rx_buf, 895 + .truesize = rx_q->truesize, 896 + .count = rx_q->desc_count, 897 + }; 860 898 u16 nta = rx_q->next_to_alloc; 861 - struct idpf_rx_buf *buf; 862 899 863 900 if (!cleaned_count) 864 901 return false; 865 902 866 - desc = IDPF_SINGLEQ_RX_BUF_DESC(rx_q, nta); 867 - buf = &rx_q->rx_buf.buf[nta]; 903 + desc = &rx_q->single_buf[nta]; 868 904 869 905 do { 870 906 dma_addr_t addr; 871 907 872 - addr = idpf_alloc_page(rx_q->pp, buf, rx_q->rx_buf_size); 873 - if (unlikely(addr == DMA_MAPPING_ERROR)) 908 + addr = libeth_rx_alloc(&fq, nta); 909 + if (addr == DMA_MAPPING_ERROR) 874 910 break; 875 911 876 912 /* Refresh the desc even if buffer_addrs didn't change ··· 884 912 desc->hdr_addr = 0; 885 913 desc++; 886 914 887 - buf++; 888 915 nta++; 889 916 if (unlikely(nta == rx_q->desc_count)) { 890 - desc = IDPF_SINGLEQ_RX_BUF_DESC(rx_q, 0); 891 - buf = rx_q->rx_buf.buf; 917 + desc = &rx_q->single_buf[0]; 892 918 nta = 0; 893 919 } 894 920 ··· 903 933 904 934 /** 905 935 * idpf_rx_singleq_extract_base_fields - Extract fields from the Rx descriptor 906 - * @rx_q: Rx descriptor queue 907 936 * @rx_desc: the descriptor to process 908 937 * @fields: storage for extracted values 909 938 * ··· 912 943 * This function only operates on the VIRTCHNL2_RXDID_1_32B_BASE_M base 32byte 913 944 * descriptor writeback format. 914 945 */ 915 - static void idpf_rx_singleq_extract_base_fields(struct idpf_queue *rx_q, 916 - union virtchnl2_rx_desc *rx_desc, 917 - struct idpf_rx_extracted *fields) 946 + static void 947 + idpf_rx_singleq_extract_base_fields(const union virtchnl2_rx_desc *rx_desc, 948 + struct idpf_rx_extracted *fields) 918 949 { 919 950 u64 qword; 920 951 ··· 926 957 927 958 /** 928 959 * idpf_rx_singleq_extract_flex_fields - Extract fields from the Rx descriptor 929 - * @rx_q: Rx descriptor queue 930 960 * @rx_desc: the descriptor to process 931 961 * @fields: storage for extracted values 932 962 * ··· 935 967 * This function only operates on the VIRTCHNL2_RXDID_2_FLEX_SQ_NIC flexible 936 968 * descriptor writeback format. 937 969 */ 938 - static void idpf_rx_singleq_extract_flex_fields(struct idpf_queue *rx_q, 939 - union virtchnl2_rx_desc *rx_desc, 940 - struct idpf_rx_extracted *fields) 970 + static void 971 + idpf_rx_singleq_extract_flex_fields(const union virtchnl2_rx_desc *rx_desc, 972 + struct idpf_rx_extracted *fields) 941 973 { 942 974 fields->size = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_PKT_LEN_M, 943 975 le16_to_cpu(rx_desc->flex_nic_wb.pkt_len)); ··· 952 984 * @fields: storage for extracted values 953 985 * 954 986 */ 955 - static void idpf_rx_singleq_extract_fields(struct idpf_queue *rx_q, 956 - union virtchnl2_rx_desc *rx_desc, 957 - struct idpf_rx_extracted *fields) 987 + static void 988 + idpf_rx_singleq_extract_fields(const struct idpf_rx_queue *rx_q, 989 + const union virtchnl2_rx_desc *rx_desc, 990 + struct idpf_rx_extracted *fields) 958 991 { 959 992 if (rx_q->rxdids == VIRTCHNL2_RXDID_1_32B_BASE_M) 960 - idpf_rx_singleq_extract_base_fields(rx_q, rx_desc, fields); 993 + idpf_rx_singleq_extract_base_fields(rx_desc, fields); 961 994 else 962 - idpf_rx_singleq_extract_flex_fields(rx_q, rx_desc, fields); 995 + idpf_rx_singleq_extract_flex_fields(rx_desc, fields); 963 996 } 964 997 965 998 /** ··· 970 1001 * 971 1002 * Returns true if there's any budget left (e.g. the clean is finished) 972 1003 */ 973 - static int idpf_rx_singleq_clean(struct idpf_queue *rx_q, int budget) 1004 + static int idpf_rx_singleq_clean(struct idpf_rx_queue *rx_q, int budget) 974 1005 { 975 1006 unsigned int total_rx_bytes = 0, total_rx_pkts = 0; 976 1007 struct sk_buff *skb = rx_q->skb; ··· 985 1016 struct idpf_rx_buf *rx_buf; 986 1017 987 1018 /* get the Rx desc from Rx queue based on 'next_to_clean' */ 988 - rx_desc = IDPF_RX_DESC(rx_q, ntc); 1019 + rx_desc = &rx_q->rx[ntc]; 989 1020 990 1021 /* status_error_ptype_len will always be zero for unused 991 1022 * descriptors because it's cleared in cleanup, and overlaps ··· 1005 1036 1006 1037 idpf_rx_singleq_extract_fields(rx_q, rx_desc, &fields); 1007 1038 1008 - rx_buf = &rx_q->rx_buf.buf[ntc]; 1009 - if (!fields.size) { 1010 - idpf_rx_put_page(rx_buf); 1039 + rx_buf = &rx_q->rx_buf[ntc]; 1040 + if (!libeth_rx_sync_for_cpu(rx_buf, fields.size)) 1011 1041 goto skip_data; 1012 - } 1013 1042 1014 - idpf_rx_sync_for_cpu(rx_buf, fields.size); 1015 1043 if (skb) 1016 1044 idpf_rx_add_frag(rx_buf, skb, fields.size); 1017 1045 else 1018 - skb = idpf_rx_construct_skb(rx_q, rx_buf, fields.size); 1046 + skb = idpf_rx_build_skb(rx_buf, fields.size); 1019 1047 1020 1048 /* exit if we failed to retrieve a buffer */ 1021 1049 if (!skb) 1022 1050 break; 1023 1051 1024 1052 skip_data: 1025 - IDPF_SINGLEQ_BUMP_RING_IDX(rx_q, ntc); 1053 + rx_buf->page = NULL; 1026 1054 1055 + IDPF_SINGLEQ_BUMP_RING_IDX(rx_q, ntc); 1027 1056 cleaned_count++; 1028 1057 1029 1058 /* skip if it is non EOP desc */ 1030 - if (idpf_rx_singleq_is_non_eop(rx_q, rx_desc, skb, ntc)) 1059 + if (idpf_rx_singleq_is_non_eop(rx_desc) || unlikely(!skb)) 1031 1060 continue; 1032 1061 1033 1062 #define IDPF_RXD_ERR_S FIELD_PREP(VIRTCHNL2_RX_BASE_DESC_QW1_ERROR_M, \ ··· 1051 1084 rx_desc, fields.rx_ptype); 1052 1085 1053 1086 /* send completed skb up the stack */ 1054 - napi_gro_receive(&rx_q->q_vector->napi, skb); 1087 + napi_gro_receive(rx_q->pp->p.napi, skb); 1055 1088 skb = NULL; 1056 1089 1057 1090 /* update budget accounting */ ··· 1062 1095 1063 1096 rx_q->next_to_clean = ntc; 1064 1097 1098 + page_pool_nid_changed(rx_q->pp, numa_mem_id()); 1065 1099 if (cleaned_count) 1066 1100 failure = idpf_rx_singleq_buf_hw_alloc_all(rx_q, cleaned_count); 1067 1101 1068 1102 u64_stats_update_begin(&rx_q->stats_sync); 1069 - u64_stats_add(&rx_q->q_stats.rx.packets, total_rx_pkts); 1070 - u64_stats_add(&rx_q->q_stats.rx.bytes, total_rx_bytes); 1103 + u64_stats_add(&rx_q->q_stats.packets, total_rx_pkts); 1104 + u64_stats_add(&rx_q->q_stats.bytes, total_rx_bytes); 1071 1105 u64_stats_update_end(&rx_q->stats_sync); 1072 1106 1073 1107 /* guarantee a trip back through this routine if there was a failure */ ··· 1095 1127 */ 1096 1128 budget_per_q = num_rxq ? max(budget / num_rxq, 1) : 0; 1097 1129 for (i = 0; i < num_rxq; i++) { 1098 - struct idpf_queue *rxq = q_vec->rx[i]; 1130 + struct idpf_rx_queue *rxq = q_vec->rx[i]; 1099 1131 int pkts_cleaned_per_q; 1100 1132 1101 1133 pkts_cleaned_per_q = idpf_rx_singleq_clean(rxq, budget_per_q);
+790 -634
drivers/net/ethernet/intel/idpf/idpf_txrx.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* Copyright (C) 2023 Intel Corporation */ 3 3 4 + #include <net/libeth/rx.h> 5 + 4 6 #include "idpf.h" 5 7 #include "idpf_virtchnl.h" 8 + 9 + static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, 10 + unsigned int count); 6 11 7 12 /** 8 13 * idpf_buf_lifo_push - push a buffer pointer onto stack ··· 65 60 * @tx_q: the queue that owns the buffer 66 61 * @tx_buf: the buffer to free 67 62 */ 68 - static void idpf_tx_buf_rel(struct idpf_queue *tx_q, struct idpf_tx_buf *tx_buf) 63 + static void idpf_tx_buf_rel(struct idpf_tx_queue *tx_q, 64 + struct idpf_tx_buf *tx_buf) 69 65 { 70 66 if (tx_buf->skb) { 71 67 if (dma_unmap_len(tx_buf, len)) ··· 92 86 * idpf_tx_buf_rel_all - Free any empty Tx buffers 93 87 * @txq: queue to be cleaned 94 88 */ 95 - static void idpf_tx_buf_rel_all(struct idpf_queue *txq) 89 + static void idpf_tx_buf_rel_all(struct idpf_tx_queue *txq) 96 90 { 91 + struct idpf_buf_lifo *buf_stack; 97 92 u16 i; 98 93 99 94 /* Buffers already cleared, nothing to do */ ··· 108 101 kfree(txq->tx_buf); 109 102 txq->tx_buf = NULL; 110 103 111 - if (!txq->buf_stack.bufs) 104 + if (!idpf_queue_has(FLOW_SCH_EN, txq)) 112 105 return; 113 106 114 - for (i = 0; i < txq->buf_stack.size; i++) 115 - kfree(txq->buf_stack.bufs[i]); 107 + buf_stack = &txq->stash->buf_stack; 108 + if (!buf_stack->bufs) 109 + return; 116 110 117 - kfree(txq->buf_stack.bufs); 118 - txq->buf_stack.bufs = NULL; 111 + for (i = 0; i < buf_stack->size; i++) 112 + kfree(buf_stack->bufs[i]); 113 + 114 + kfree(buf_stack->bufs); 115 + buf_stack->bufs = NULL; 119 116 } 120 117 121 118 /** 122 119 * idpf_tx_desc_rel - Free Tx resources per queue 123 120 * @txq: Tx descriptor ring for a specific queue 124 - * @bufq: buffer q or completion q 125 121 * 126 122 * Free all transmit software resources 127 123 */ 128 - static void idpf_tx_desc_rel(struct idpf_queue *txq, bool bufq) 124 + static void idpf_tx_desc_rel(struct idpf_tx_queue *txq) 129 125 { 130 - if (bufq) 131 - idpf_tx_buf_rel_all(txq); 126 + idpf_tx_buf_rel_all(txq); 132 127 133 128 if (!txq->desc_ring) 134 129 return; 135 130 136 131 dmam_free_coherent(txq->dev, txq->size, txq->desc_ring, txq->dma); 137 132 txq->desc_ring = NULL; 138 - txq->next_to_alloc = 0; 139 133 txq->next_to_use = 0; 140 134 txq->next_to_clean = 0; 135 + } 136 + 137 + /** 138 + * idpf_compl_desc_rel - Free completion resources per queue 139 + * @complq: completion queue 140 + * 141 + * Free all completion software resources. 142 + */ 143 + static void idpf_compl_desc_rel(struct idpf_compl_queue *complq) 144 + { 145 + if (!complq->comp) 146 + return; 147 + 148 + dma_free_coherent(complq->netdev->dev.parent, complq->size, 149 + complq->comp, complq->dma); 150 + complq->comp = NULL; 151 + complq->next_to_use = 0; 152 + complq->next_to_clean = 0; 141 153 } 142 154 143 155 /** ··· 176 150 struct idpf_txq_group *txq_grp = &vport->txq_grps[i]; 177 151 178 152 for (j = 0; j < txq_grp->num_txq; j++) 179 - idpf_tx_desc_rel(txq_grp->txqs[j], true); 153 + idpf_tx_desc_rel(txq_grp->txqs[j]); 180 154 181 155 if (idpf_is_queue_model_split(vport->txq_model)) 182 - idpf_tx_desc_rel(txq_grp->complq, false); 156 + idpf_compl_desc_rel(txq_grp->complq); 183 157 } 184 158 } 185 159 ··· 189 163 * 190 164 * Returns 0 on success, negative on failure 191 165 */ 192 - static int idpf_tx_buf_alloc_all(struct idpf_queue *tx_q) 166 + static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q) 193 167 { 168 + struct idpf_buf_lifo *buf_stack; 194 169 int buf_size; 195 170 int i; 196 171 ··· 207 180 for (i = 0; i < tx_q->desc_count; i++) 208 181 tx_q->tx_buf[i].compl_tag = IDPF_SPLITQ_TX_INVAL_COMPL_TAG; 209 182 183 + if (!idpf_queue_has(FLOW_SCH_EN, tx_q)) 184 + return 0; 185 + 186 + buf_stack = &tx_q->stash->buf_stack; 187 + 210 188 /* Initialize tx buf stack for out-of-order completions if 211 189 * flow scheduling offload is enabled 212 190 */ 213 - tx_q->buf_stack.bufs = 214 - kcalloc(tx_q->desc_count, sizeof(struct idpf_tx_stash *), 215 - GFP_KERNEL); 216 - if (!tx_q->buf_stack.bufs) 191 + buf_stack->bufs = kcalloc(tx_q->desc_count, sizeof(*buf_stack->bufs), 192 + GFP_KERNEL); 193 + if (!buf_stack->bufs) 217 194 return -ENOMEM; 218 195 219 - tx_q->buf_stack.size = tx_q->desc_count; 220 - tx_q->buf_stack.top = tx_q->desc_count; 196 + buf_stack->size = tx_q->desc_count; 197 + buf_stack->top = tx_q->desc_count; 221 198 222 199 for (i = 0; i < tx_q->desc_count; i++) { 223 - tx_q->buf_stack.bufs[i] = kzalloc(sizeof(*tx_q->buf_stack.bufs[i]), 224 - GFP_KERNEL); 225 - if (!tx_q->buf_stack.bufs[i]) 200 + buf_stack->bufs[i] = kzalloc(sizeof(*buf_stack->bufs[i]), 201 + GFP_KERNEL); 202 + if (!buf_stack->bufs[i]) 226 203 return -ENOMEM; 227 204 } 228 205 ··· 235 204 236 205 /** 237 206 * idpf_tx_desc_alloc - Allocate the Tx descriptors 207 + * @vport: vport to allocate resources for 238 208 * @tx_q: the tx ring to set up 239 - * @bufq: buffer or completion queue 240 209 * 241 210 * Returns 0 on success, negative on failure 242 211 */ 243 - static int idpf_tx_desc_alloc(struct idpf_queue *tx_q, bool bufq) 212 + static int idpf_tx_desc_alloc(const struct idpf_vport *vport, 213 + struct idpf_tx_queue *tx_q) 244 214 { 245 215 struct device *dev = tx_q->dev; 246 - u32 desc_sz; 247 216 int err; 248 217 249 - if (bufq) { 250 - err = idpf_tx_buf_alloc_all(tx_q); 251 - if (err) 252 - goto err_alloc; 218 + err = idpf_tx_buf_alloc_all(tx_q); 219 + if (err) 220 + goto err_alloc; 253 221 254 - desc_sz = sizeof(struct idpf_base_tx_desc); 255 - } else { 256 - desc_sz = sizeof(struct idpf_splitq_tx_compl_desc); 257 - } 258 - 259 - tx_q->size = tx_q->desc_count * desc_sz; 222 + tx_q->size = tx_q->desc_count * sizeof(*tx_q->base_tx); 260 223 261 224 /* Allocate descriptors also round up to nearest 4K */ 262 225 tx_q->size = ALIGN(tx_q->size, 4096); ··· 263 238 goto err_alloc; 264 239 } 265 240 266 - tx_q->next_to_alloc = 0; 267 241 tx_q->next_to_use = 0; 268 242 tx_q->next_to_clean = 0; 269 - set_bit(__IDPF_Q_GEN_CHK, tx_q->flags); 243 + idpf_queue_set(GEN_CHK, tx_q); 270 244 271 245 return 0; 272 246 273 247 err_alloc: 274 - idpf_tx_desc_rel(tx_q, bufq); 248 + idpf_tx_desc_rel(tx_q); 275 249 276 250 return err; 251 + } 252 + 253 + /** 254 + * idpf_compl_desc_alloc - allocate completion descriptors 255 + * @vport: vport to allocate resources for 256 + * @complq: completion queue to set up 257 + * 258 + * Return: 0 on success, -errno on failure. 259 + */ 260 + static int idpf_compl_desc_alloc(const struct idpf_vport *vport, 261 + struct idpf_compl_queue *complq) 262 + { 263 + complq->size = array_size(complq->desc_count, sizeof(*complq->comp)); 264 + 265 + complq->comp = dma_alloc_coherent(complq->netdev->dev.parent, 266 + complq->size, &complq->dma, 267 + GFP_KERNEL); 268 + if (!complq->comp) 269 + return -ENOMEM; 270 + 271 + complq->next_to_use = 0; 272 + complq->next_to_clean = 0; 273 + idpf_queue_set(GEN_CHK, complq); 274 + 275 + return 0; 277 276 } 278 277 279 278 /** ··· 308 259 */ 309 260 static int idpf_tx_desc_alloc_all(struct idpf_vport *vport) 310 261 { 311 - struct device *dev = &vport->adapter->pdev->dev; 312 262 int err = 0; 313 263 int i, j; 314 264 ··· 316 268 */ 317 269 for (i = 0; i < vport->num_txq_grp; i++) { 318 270 for (j = 0; j < vport->txq_grps[i].num_txq; j++) { 319 - struct idpf_queue *txq = vport->txq_grps[i].txqs[j]; 271 + struct idpf_tx_queue *txq = vport->txq_grps[i].txqs[j]; 320 272 u8 gen_bits = 0; 321 273 u16 bufidx_mask; 322 274 323 - err = idpf_tx_desc_alloc(txq, true); 275 + err = idpf_tx_desc_alloc(vport, txq); 324 276 if (err) { 325 - dev_err(dev, "Allocation for Tx Queue %u failed\n", 277 + pci_err(vport->adapter->pdev, 278 + "Allocation for Tx Queue %u failed\n", 326 279 i); 327 280 goto err_out; 328 281 } ··· 361 312 continue; 362 313 363 314 /* Setup completion queues */ 364 - err = idpf_tx_desc_alloc(vport->txq_grps[i].complq, false); 315 + err = idpf_compl_desc_alloc(vport, vport->txq_grps[i].complq); 365 316 if (err) { 366 - dev_err(dev, "Allocation for Tx Completion Queue %u failed\n", 317 + pci_err(vport->adapter->pdev, 318 + "Allocation for Tx Completion Queue %u failed\n", 367 319 i); 368 320 goto err_out; 369 321 } ··· 379 329 380 330 /** 381 331 * idpf_rx_page_rel - Release an rx buffer page 382 - * @rxq: the queue that owns the buffer 383 332 * @rx_buf: the buffer to free 384 333 */ 385 - static void idpf_rx_page_rel(struct idpf_queue *rxq, struct idpf_rx_buf *rx_buf) 334 + static void idpf_rx_page_rel(struct libeth_fqe *rx_buf) 386 335 { 387 336 if (unlikely(!rx_buf->page)) 388 337 return; 389 338 390 - page_pool_put_full_page(rxq->pp, rx_buf->page, false); 339 + page_pool_put_full_page(rx_buf->page->pp, rx_buf->page, false); 391 340 392 341 rx_buf->page = NULL; 393 - rx_buf->page_offset = 0; 342 + rx_buf->offset = 0; 394 343 } 395 344 396 345 /** 397 346 * idpf_rx_hdr_buf_rel_all - Release header buffer memory 398 - * @rxq: queue to use 347 + * @bufq: queue to use 399 348 */ 400 - static void idpf_rx_hdr_buf_rel_all(struct idpf_queue *rxq) 349 + static void idpf_rx_hdr_buf_rel_all(struct idpf_buf_queue *bufq) 401 350 { 402 - struct idpf_adapter *adapter = rxq->vport->adapter; 351 + struct libeth_fq fq = { 352 + .fqes = bufq->hdr_buf, 353 + .pp = bufq->hdr_pp, 354 + }; 403 355 404 - dma_free_coherent(&adapter->pdev->dev, 405 - rxq->desc_count * IDPF_HDR_BUF_SIZE, 406 - rxq->rx_buf.hdr_buf_va, 407 - rxq->rx_buf.hdr_buf_pa); 408 - rxq->rx_buf.hdr_buf_va = NULL; 356 + for (u32 i = 0; i < bufq->desc_count; i++) 357 + idpf_rx_page_rel(&bufq->hdr_buf[i]); 358 + 359 + libeth_rx_fq_destroy(&fq); 360 + bufq->hdr_buf = NULL; 361 + bufq->hdr_pp = NULL; 409 362 } 410 363 411 364 /** 412 - * idpf_rx_buf_rel_all - Free all Rx buffer resources for a queue 413 - * @rxq: queue to be cleaned 365 + * idpf_rx_buf_rel_bufq - Free all Rx buffer resources for a buffer queue 366 + * @bufq: queue to be cleaned 414 367 */ 415 - static void idpf_rx_buf_rel_all(struct idpf_queue *rxq) 368 + static void idpf_rx_buf_rel_bufq(struct idpf_buf_queue *bufq) 416 369 { 417 - u16 i; 370 + struct libeth_fq fq = { 371 + .fqes = bufq->buf, 372 + .pp = bufq->pp, 373 + }; 418 374 419 375 /* queue already cleared, nothing to do */ 420 - if (!rxq->rx_buf.buf) 376 + if (!bufq->buf) 421 377 return; 422 378 423 379 /* Free all the bufs allocated and given to hw on Rx queue */ 424 - for (i = 0; i < rxq->desc_count; i++) 425 - idpf_rx_page_rel(rxq, &rxq->rx_buf.buf[i]); 380 + for (u32 i = 0; i < bufq->desc_count; i++) 381 + idpf_rx_page_rel(&bufq->buf[i]); 426 382 427 - if (rxq->rx_hsplit_en) 428 - idpf_rx_hdr_buf_rel_all(rxq); 383 + if (idpf_queue_has(HSPLIT_EN, bufq)) 384 + idpf_rx_hdr_buf_rel_all(bufq); 429 385 430 - page_pool_destroy(rxq->pp); 386 + libeth_rx_fq_destroy(&fq); 387 + bufq->buf = NULL; 388 + bufq->pp = NULL; 389 + } 390 + 391 + /** 392 + * idpf_rx_buf_rel_all - Free all Rx buffer resources for a receive queue 393 + * @rxq: queue to be cleaned 394 + */ 395 + static void idpf_rx_buf_rel_all(struct idpf_rx_queue *rxq) 396 + { 397 + struct libeth_fq fq = { 398 + .fqes = rxq->rx_buf, 399 + .pp = rxq->pp, 400 + }; 401 + 402 + if (!rxq->rx_buf) 403 + return; 404 + 405 + for (u32 i = 0; i < rxq->desc_count; i++) 406 + idpf_rx_page_rel(&rxq->rx_buf[i]); 407 + 408 + libeth_rx_fq_destroy(&fq); 409 + rxq->rx_buf = NULL; 431 410 rxq->pp = NULL; 432 - 433 - kfree(rxq->rx_buf.buf); 434 - rxq->rx_buf.buf = NULL; 435 411 } 436 412 437 413 /** 438 414 * idpf_rx_desc_rel - Free a specific Rx q resources 439 415 * @rxq: queue to clean the resources from 440 - * @bufq: buffer q or completion q 441 - * @q_model: single or split q model 416 + * @dev: device to free DMA memory 417 + * @model: single or split queue model 442 418 * 443 419 * Free a specific rx queue resources 444 420 */ 445 - static void idpf_rx_desc_rel(struct idpf_queue *rxq, bool bufq, s32 q_model) 421 + static void idpf_rx_desc_rel(struct idpf_rx_queue *rxq, struct device *dev, 422 + u32 model) 446 423 { 447 424 if (!rxq) 448 425 return; ··· 479 402 rxq->skb = NULL; 480 403 } 481 404 482 - if (bufq || !idpf_is_queue_model_split(q_model)) 405 + if (!idpf_is_queue_model_split(model)) 483 406 idpf_rx_buf_rel_all(rxq); 484 407 485 408 rxq->next_to_alloc = 0; ··· 488 411 if (!rxq->desc_ring) 489 412 return; 490 413 491 - dmam_free_coherent(rxq->dev, rxq->size, rxq->desc_ring, rxq->dma); 414 + dmam_free_coherent(dev, rxq->size, rxq->desc_ring, rxq->dma); 492 415 rxq->desc_ring = NULL; 416 + } 417 + 418 + /** 419 + * idpf_rx_desc_rel_bufq - free buffer queue resources 420 + * @bufq: buffer queue to clean the resources from 421 + * @dev: device to free DMA memory 422 + */ 423 + static void idpf_rx_desc_rel_bufq(struct idpf_buf_queue *bufq, 424 + struct device *dev) 425 + { 426 + if (!bufq) 427 + return; 428 + 429 + idpf_rx_buf_rel_bufq(bufq); 430 + 431 + bufq->next_to_alloc = 0; 432 + bufq->next_to_clean = 0; 433 + bufq->next_to_use = 0; 434 + 435 + if (!bufq->split_buf) 436 + return; 437 + 438 + dma_free_coherent(dev, bufq->size, bufq->split_buf, bufq->dma); 439 + bufq->split_buf = NULL; 493 440 } 494 441 495 442 /** ··· 524 423 */ 525 424 static void idpf_rx_desc_rel_all(struct idpf_vport *vport) 526 425 { 426 + struct device *dev = &vport->adapter->pdev->dev; 527 427 struct idpf_rxq_group *rx_qgrp; 528 428 u16 num_rxq; 529 429 int i, j; ··· 537 435 538 436 if (!idpf_is_queue_model_split(vport->rxq_model)) { 539 437 for (j = 0; j < rx_qgrp->singleq.num_rxq; j++) 540 - idpf_rx_desc_rel(rx_qgrp->singleq.rxqs[j], 541 - false, vport->rxq_model); 438 + idpf_rx_desc_rel(rx_qgrp->singleq.rxqs[j], dev, 439 + VIRTCHNL2_QUEUE_MODEL_SINGLE); 542 440 continue; 543 441 } 544 442 545 443 num_rxq = rx_qgrp->splitq.num_rxq_sets; 546 444 for (j = 0; j < num_rxq; j++) 547 445 idpf_rx_desc_rel(&rx_qgrp->splitq.rxq_sets[j]->rxq, 548 - false, vport->rxq_model); 446 + dev, VIRTCHNL2_QUEUE_MODEL_SPLIT); 549 447 550 448 if (!rx_qgrp->splitq.bufq_sets) 551 449 continue; ··· 554 452 struct idpf_bufq_set *bufq_set = 555 453 &rx_qgrp->splitq.bufq_sets[j]; 556 454 557 - idpf_rx_desc_rel(&bufq_set->bufq, true, 558 - vport->rxq_model); 455 + idpf_rx_desc_rel_bufq(&bufq_set->bufq, dev); 559 456 } 560 457 } 561 458 } 562 459 563 460 /** 564 461 * idpf_rx_buf_hw_update - Store the new tail and head values 565 - * @rxq: queue to bump 462 + * @bufq: queue to bump 566 463 * @val: new head index 567 464 */ 568 - void idpf_rx_buf_hw_update(struct idpf_queue *rxq, u32 val) 465 + static void idpf_rx_buf_hw_update(struct idpf_buf_queue *bufq, u32 val) 569 466 { 570 - rxq->next_to_use = val; 467 + bufq->next_to_use = val; 571 468 572 - if (unlikely(!rxq->tail)) 469 + if (unlikely(!bufq->tail)) 573 470 return; 574 471 575 472 /* writel has an implicit memory barrier */ 576 - writel(val, rxq->tail); 473 + writel(val, bufq->tail); 577 474 } 578 475 579 476 /** 580 477 * idpf_rx_hdr_buf_alloc_all - Allocate memory for header buffers 581 - * @rxq: ring to use 478 + * @bufq: ring to use 582 479 * 583 480 * Returns 0 on success, negative on failure. 584 481 */ 585 - static int idpf_rx_hdr_buf_alloc_all(struct idpf_queue *rxq) 482 + static int idpf_rx_hdr_buf_alloc_all(struct idpf_buf_queue *bufq) 586 483 { 587 - struct idpf_adapter *adapter = rxq->vport->adapter; 484 + struct libeth_fq fq = { 485 + .count = bufq->desc_count, 486 + .type = LIBETH_FQE_HDR, 487 + .nid = idpf_q_vector_to_mem(bufq->q_vector), 488 + }; 489 + int ret; 588 490 589 - rxq->rx_buf.hdr_buf_va = 590 - dma_alloc_coherent(&adapter->pdev->dev, 591 - IDPF_HDR_BUF_SIZE * rxq->desc_count, 592 - &rxq->rx_buf.hdr_buf_pa, 593 - GFP_KERNEL); 594 - if (!rxq->rx_buf.hdr_buf_va) 595 - return -ENOMEM; 491 + ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi); 492 + if (ret) 493 + return ret; 494 + 495 + bufq->hdr_pp = fq.pp; 496 + bufq->hdr_buf = fq.fqes; 497 + bufq->hdr_truesize = fq.truesize; 498 + bufq->rx_hbuf_size = fq.buf_len; 596 499 597 500 return 0; 598 501 } ··· 609 502 */ 610 503 static void idpf_rx_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id) 611 504 { 612 - u16 nta = refillq->next_to_alloc; 505 + u32 nta = refillq->next_to_use; 613 506 614 507 /* store the buffer ID and the SW maintained GEN bit to the refillq */ 615 508 refillq->ring[nta] = 616 509 FIELD_PREP(IDPF_RX_BI_BUFID_M, buf_id) | 617 510 FIELD_PREP(IDPF_RX_BI_GEN_M, 618 - test_bit(__IDPF_Q_GEN_CHK, refillq->flags)); 511 + idpf_queue_has(GEN_CHK, refillq)); 619 512 620 513 if (unlikely(++nta == refillq->desc_count)) { 621 514 nta = 0; 622 - change_bit(__IDPF_Q_GEN_CHK, refillq->flags); 515 + idpf_queue_change(GEN_CHK, refillq); 623 516 } 624 - refillq->next_to_alloc = nta; 517 + 518 + refillq->next_to_use = nta; 625 519 } 626 520 627 521 /** ··· 632 524 * 633 525 * Returns false if buffer could not be allocated, true otherwise. 634 526 */ 635 - static bool idpf_rx_post_buf_desc(struct idpf_queue *bufq, u16 buf_id) 527 + static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id) 636 528 { 637 529 struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL; 530 + struct libeth_fq_fp fq = { 531 + .count = bufq->desc_count, 532 + }; 638 533 u16 nta = bufq->next_to_alloc; 639 - struct idpf_rx_buf *buf; 640 534 dma_addr_t addr; 641 535 642 - splitq_rx_desc = IDPF_SPLITQ_RX_BUF_DESC(bufq, nta); 643 - buf = &bufq->rx_buf.buf[buf_id]; 536 + splitq_rx_desc = &bufq->split_buf[nta]; 644 537 645 - if (bufq->rx_hsplit_en) { 646 - splitq_rx_desc->hdr_addr = 647 - cpu_to_le64(bufq->rx_buf.hdr_buf_pa + 648 - (u32)buf_id * IDPF_HDR_BUF_SIZE); 538 + if (idpf_queue_has(HSPLIT_EN, bufq)) { 539 + fq.pp = bufq->hdr_pp; 540 + fq.fqes = bufq->hdr_buf; 541 + fq.truesize = bufq->hdr_truesize; 542 + 543 + addr = libeth_rx_alloc(&fq, buf_id); 544 + if (addr == DMA_MAPPING_ERROR) 545 + return false; 546 + 547 + splitq_rx_desc->hdr_addr = cpu_to_le64(addr); 649 548 } 650 549 651 - addr = idpf_alloc_page(bufq->pp, buf, bufq->rx_buf_size); 652 - if (unlikely(addr == DMA_MAPPING_ERROR)) 550 + fq.pp = bufq->pp; 551 + fq.fqes = bufq->buf; 552 + fq.truesize = bufq->truesize; 553 + 554 + addr = libeth_rx_alloc(&fq, buf_id); 555 + if (addr == DMA_MAPPING_ERROR) 653 556 return false; 654 557 655 558 splitq_rx_desc->pkt_addr = cpu_to_le64(addr); ··· 681 562 * 682 563 * Returns true if @working_set bufs were posted successfully, false otherwise. 683 564 */ 684 - static bool idpf_rx_post_init_bufs(struct idpf_queue *bufq, u16 working_set) 565 + static bool idpf_rx_post_init_bufs(struct idpf_buf_queue *bufq, 566 + u16 working_set) 685 567 { 686 568 int i; 687 569 ··· 691 571 return false; 692 572 } 693 573 694 - idpf_rx_buf_hw_update(bufq, 695 - bufq->next_to_alloc & ~(bufq->rx_buf_stride - 1)); 574 + idpf_rx_buf_hw_update(bufq, ALIGN_DOWN(bufq->next_to_alloc, 575 + IDPF_RX_BUF_STRIDE)); 696 576 697 577 return true; 698 578 } 699 579 700 580 /** 701 - * idpf_rx_create_page_pool - Create a page pool 702 - * @rxbufq: RX queue to create page pool for 581 + * idpf_rx_buf_alloc_singleq - Allocate memory for all buffer resources 582 + * @rxq: queue for which the buffers are allocated 703 583 * 704 - * Returns &page_pool on success, casted -errno on failure 584 + * Return: 0 on success, -ENOMEM on failure. 705 585 */ 706 - static struct page_pool *idpf_rx_create_page_pool(struct idpf_queue *rxbufq) 586 + static int idpf_rx_buf_alloc_singleq(struct idpf_rx_queue *rxq) 707 587 { 708 - struct page_pool_params pp = { 709 - .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, 710 - .order = 0, 711 - .pool_size = rxbufq->desc_count, 712 - .nid = NUMA_NO_NODE, 713 - .dev = rxbufq->vport->netdev->dev.parent, 714 - .max_len = PAGE_SIZE, 715 - .dma_dir = DMA_FROM_DEVICE, 716 - .offset = 0, 717 - }; 588 + if (idpf_rx_singleq_buf_hw_alloc_all(rxq, rxq->desc_count - 1)) 589 + goto err; 718 590 719 - return page_pool_create(&pp); 591 + return 0; 592 + 593 + err: 594 + idpf_rx_buf_rel_all(rxq); 595 + 596 + return -ENOMEM; 597 + } 598 + 599 + /** 600 + * idpf_rx_bufs_init_singleq - Initialize page pool and allocate Rx bufs 601 + * @rxq: buffer queue to create page pool for 602 + * 603 + * Return: 0 on success, -errno on failure. 604 + */ 605 + static int idpf_rx_bufs_init_singleq(struct idpf_rx_queue *rxq) 606 + { 607 + struct libeth_fq fq = { 608 + .count = rxq->desc_count, 609 + .type = LIBETH_FQE_MTU, 610 + .nid = idpf_q_vector_to_mem(rxq->q_vector), 611 + }; 612 + int ret; 613 + 614 + ret = libeth_rx_fq_create(&fq, &rxq->q_vector->napi); 615 + if (ret) 616 + return ret; 617 + 618 + rxq->pp = fq.pp; 619 + rxq->rx_buf = fq.fqes; 620 + rxq->truesize = fq.truesize; 621 + rxq->rx_buf_size = fq.buf_len; 622 + 623 + return idpf_rx_buf_alloc_singleq(rxq); 720 624 } 721 625 722 626 /** 723 627 * idpf_rx_buf_alloc_all - Allocate memory for all buffer resources 724 - * @rxbufq: queue for which the buffers are allocated; equivalent to 725 - * rxq when operating in singleq mode 628 + * @rxbufq: queue for which the buffers are allocated 726 629 * 727 630 * Returns 0 on success, negative on failure 728 631 */ 729 - static int idpf_rx_buf_alloc_all(struct idpf_queue *rxbufq) 632 + static int idpf_rx_buf_alloc_all(struct idpf_buf_queue *rxbufq) 730 633 { 731 634 int err = 0; 732 635 733 - /* Allocate book keeping buffers */ 734 - rxbufq->rx_buf.buf = kcalloc(rxbufq->desc_count, 735 - sizeof(struct idpf_rx_buf), GFP_KERNEL); 736 - if (!rxbufq->rx_buf.buf) { 737 - err = -ENOMEM; 738 - goto rx_buf_alloc_all_out; 739 - } 740 - 741 - if (rxbufq->rx_hsplit_en) { 636 + if (idpf_queue_has(HSPLIT_EN, rxbufq)) { 742 637 err = idpf_rx_hdr_buf_alloc_all(rxbufq); 743 638 if (err) 744 639 goto rx_buf_alloc_all_out; 745 640 } 746 641 747 642 /* Allocate buffers to be given to HW. */ 748 - if (idpf_is_queue_model_split(rxbufq->vport->rxq_model)) { 749 - int working_set = IDPF_RX_BUFQ_WORKING_SET(rxbufq); 750 - 751 - if (!idpf_rx_post_init_bufs(rxbufq, working_set)) 752 - err = -ENOMEM; 753 - } else { 754 - if (idpf_rx_singleq_buf_hw_alloc_all(rxbufq, 755 - rxbufq->desc_count - 1)) 756 - err = -ENOMEM; 757 - } 643 + if (!idpf_rx_post_init_bufs(rxbufq, IDPF_RX_BUFQ_WORKING_SET(rxbufq))) 644 + err = -ENOMEM; 758 645 759 646 rx_buf_alloc_all_out: 760 647 if (err) 761 - idpf_rx_buf_rel_all(rxbufq); 648 + idpf_rx_buf_rel_bufq(rxbufq); 762 649 763 650 return err; 764 651 } 765 652 766 653 /** 767 654 * idpf_rx_bufs_init - Initialize page pool, allocate rx bufs, and post to HW 768 - * @rxbufq: RX queue to create page pool for 655 + * @bufq: buffer queue to create page pool for 656 + * @type: type of Rx buffers to allocate 769 657 * 770 658 * Returns 0 on success, negative on failure 771 659 */ 772 - static int idpf_rx_bufs_init(struct idpf_queue *rxbufq) 660 + static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq, 661 + enum libeth_fqe_type type) 773 662 { 774 - struct page_pool *pool; 663 + struct libeth_fq fq = { 664 + .truesize = bufq->truesize, 665 + .count = bufq->desc_count, 666 + .type = type, 667 + .hsplit = idpf_queue_has(HSPLIT_EN, bufq), 668 + .nid = idpf_q_vector_to_mem(bufq->q_vector), 669 + }; 670 + int ret; 775 671 776 - pool = idpf_rx_create_page_pool(rxbufq); 777 - if (IS_ERR(pool)) 778 - return PTR_ERR(pool); 672 + ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi); 673 + if (ret) 674 + return ret; 779 675 780 - rxbufq->pp = pool; 676 + bufq->pp = fq.pp; 677 + bufq->buf = fq.fqes; 678 + bufq->truesize = fq.truesize; 679 + bufq->rx_buf_size = fq.buf_len; 781 680 782 - return idpf_rx_buf_alloc_all(rxbufq); 681 + return idpf_rx_buf_alloc_all(bufq); 783 682 } 784 683 785 684 /** ··· 809 670 */ 810 671 int idpf_rx_bufs_init_all(struct idpf_vport *vport) 811 672 { 812 - struct idpf_rxq_group *rx_qgrp; 813 - struct idpf_queue *q; 673 + bool split = idpf_is_queue_model_split(vport->rxq_model); 814 674 int i, j, err; 815 675 816 676 for (i = 0; i < vport->num_rxq_grp; i++) { 817 - rx_qgrp = &vport->rxq_grps[i]; 677 + struct idpf_rxq_group *rx_qgrp = &vport->rxq_grps[i]; 678 + u32 truesize = 0; 818 679 819 680 /* Allocate bufs for the rxq itself in singleq */ 820 - if (!idpf_is_queue_model_split(vport->rxq_model)) { 681 + if (!split) { 821 682 int num_rxq = rx_qgrp->singleq.num_rxq; 822 683 823 684 for (j = 0; j < num_rxq; j++) { 685 + struct idpf_rx_queue *q; 686 + 824 687 q = rx_qgrp->singleq.rxqs[j]; 825 - err = idpf_rx_bufs_init(q); 688 + err = idpf_rx_bufs_init_singleq(q); 826 689 if (err) 827 690 return err; 828 691 } ··· 834 693 835 694 /* Otherwise, allocate bufs for the buffer queues */ 836 695 for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { 696 + enum libeth_fqe_type type; 697 + struct idpf_buf_queue *q; 698 + 837 699 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 838 - err = idpf_rx_bufs_init(q); 700 + q->truesize = truesize; 701 + 702 + type = truesize ? LIBETH_FQE_SHORT : LIBETH_FQE_MTU; 703 + 704 + err = idpf_rx_bufs_init(q, type); 839 705 if (err) 840 706 return err; 707 + 708 + truesize = q->truesize >> 1; 841 709 } 842 710 } 843 711 ··· 855 705 856 706 /** 857 707 * idpf_rx_desc_alloc - Allocate queue Rx resources 708 + * @vport: vport to allocate resources for 858 709 * @rxq: Rx queue for which the resources are setup 859 - * @bufq: buffer or completion queue 860 - * @q_model: single or split queue model 861 710 * 862 711 * Returns 0 on success, negative on failure 863 712 */ 864 - static int idpf_rx_desc_alloc(struct idpf_queue *rxq, bool bufq, s32 q_model) 713 + static int idpf_rx_desc_alloc(const struct idpf_vport *vport, 714 + struct idpf_rx_queue *rxq) 865 715 { 866 - struct device *dev = rxq->dev; 716 + struct device *dev = &vport->adapter->pdev->dev; 867 717 868 - if (bufq) 869 - rxq->size = rxq->desc_count * 870 - sizeof(struct virtchnl2_splitq_rx_buf_desc); 871 - else 872 - rxq->size = rxq->desc_count * 873 - sizeof(union virtchnl2_rx_desc); 718 + rxq->size = rxq->desc_count * sizeof(union virtchnl2_rx_desc); 874 719 875 720 /* Allocate descriptors and also round up to nearest 4K */ 876 721 rxq->size = ALIGN(rxq->size, 4096); ··· 880 735 rxq->next_to_alloc = 0; 881 736 rxq->next_to_clean = 0; 882 737 rxq->next_to_use = 0; 883 - set_bit(__IDPF_Q_GEN_CHK, rxq->flags); 738 + idpf_queue_set(GEN_CHK, rxq); 739 + 740 + return 0; 741 + } 742 + 743 + /** 744 + * idpf_bufq_desc_alloc - Allocate buffer queue descriptor ring 745 + * @vport: vport to allocate resources for 746 + * @bufq: buffer queue for which the resources are set up 747 + * 748 + * Return: 0 on success, -ENOMEM on failure. 749 + */ 750 + static int idpf_bufq_desc_alloc(const struct idpf_vport *vport, 751 + struct idpf_buf_queue *bufq) 752 + { 753 + struct device *dev = &vport->adapter->pdev->dev; 754 + 755 + bufq->size = array_size(bufq->desc_count, sizeof(*bufq->split_buf)); 756 + 757 + bufq->split_buf = dma_alloc_coherent(dev, bufq->size, &bufq->dma, 758 + GFP_KERNEL); 759 + if (!bufq->split_buf) 760 + return -ENOMEM; 761 + 762 + bufq->next_to_alloc = 0; 763 + bufq->next_to_clean = 0; 764 + bufq->next_to_use = 0; 765 + 766 + idpf_queue_set(GEN_CHK, bufq); 884 767 885 768 return 0; 886 769 } ··· 921 748 */ 922 749 static int idpf_rx_desc_alloc_all(struct idpf_vport *vport) 923 750 { 924 - struct device *dev = &vport->adapter->pdev->dev; 925 751 struct idpf_rxq_group *rx_qgrp; 926 - struct idpf_queue *q; 927 752 int i, j, err; 928 753 u16 num_rxq; 929 754 ··· 933 762 num_rxq = rx_qgrp->singleq.num_rxq; 934 763 935 764 for (j = 0; j < num_rxq; j++) { 765 + struct idpf_rx_queue *q; 766 + 936 767 if (idpf_is_queue_model_split(vport->rxq_model)) 937 768 q = &rx_qgrp->splitq.rxq_sets[j]->rxq; 938 769 else 939 770 q = rx_qgrp->singleq.rxqs[j]; 940 - err = idpf_rx_desc_alloc(q, false, vport->rxq_model); 771 + 772 + err = idpf_rx_desc_alloc(vport, q); 941 773 if (err) { 942 - dev_err(dev, "Memory allocation for Rx Queue %u failed\n", 774 + pci_err(vport->adapter->pdev, 775 + "Memory allocation for Rx Queue %u failed\n", 943 776 i); 944 777 goto err_out; 945 778 } ··· 953 778 continue; 954 779 955 780 for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { 781 + struct idpf_buf_queue *q; 782 + 956 783 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 957 - err = idpf_rx_desc_alloc(q, true, vport->rxq_model); 784 + 785 + err = idpf_bufq_desc_alloc(vport, q); 958 786 if (err) { 959 - dev_err(dev, "Memory allocation for Rx Buffer Queue %u failed\n", 787 + pci_err(vport->adapter->pdev, 788 + "Memory allocation for Rx Buffer Queue %u failed\n", 960 789 i); 961 790 goto err_out; 962 791 } ··· 981 802 */ 982 803 static void idpf_txq_group_rel(struct idpf_vport *vport) 983 804 { 805 + bool split, flow_sch_en; 984 806 int i, j; 985 807 986 808 if (!vport->txq_grps) 987 809 return; 810 + 811 + split = idpf_is_queue_model_split(vport->txq_model); 812 + flow_sch_en = !idpf_is_cap_ena(vport->adapter, IDPF_OTHER_CAPS, 813 + VIRTCHNL2_CAP_SPLITQ_QSCHED); 988 814 989 815 for (i = 0; i < vport->num_txq_grp; i++) { 990 816 struct idpf_txq_group *txq_grp = &vport->txq_grps[i]; ··· 998 814 kfree(txq_grp->txqs[j]); 999 815 txq_grp->txqs[j] = NULL; 1000 816 } 817 + 818 + if (!split) 819 + continue; 820 + 1001 821 kfree(txq_grp->complq); 1002 822 txq_grp->complq = NULL; 823 + 824 + if (flow_sch_en) 825 + kfree(txq_grp->stashes); 1003 826 } 1004 827 kfree(vport->txq_grps); 1005 828 vport->txq_grps = NULL; ··· 1110 919 { 1111 920 int i, j, k = 0; 1112 921 1113 - vport->txqs = kcalloc(vport->num_txq, sizeof(struct idpf_queue *), 922 + vport->txqs = kcalloc(vport->num_txq, sizeof(*vport->txqs), 1114 923 GFP_KERNEL); 1115 924 1116 925 if (!vport->txqs) ··· 1158 967 /* Adjust number of buffer queues per Rx queue group. */ 1159 968 if (!idpf_is_queue_model_split(vport->rxq_model)) { 1160 969 vport->num_bufqs_per_qgrp = 0; 1161 - vport->bufq_size[0] = IDPF_RX_BUF_2048; 1162 970 1163 971 return; 1164 972 } 1165 973 1166 974 vport->num_bufqs_per_qgrp = IDPF_MAX_BUFQS_PER_RXQ_GRP; 1167 - /* Bufq[0] default buffer size is 4K 1168 - * Bufq[1] default buffer size is 2K 1169 - */ 1170 - vport->bufq_size[0] = IDPF_RX_BUF_4096; 1171 - vport->bufq_size[1] = IDPF_RX_BUF_2048; 1172 975 } 1173 976 1174 977 /** ··· 1322 1137 * @q: rx queue for which descids are set 1323 1138 * 1324 1139 */ 1325 - static void idpf_rxq_set_descids(struct idpf_vport *vport, struct idpf_queue *q) 1140 + static void idpf_rxq_set_descids(const struct idpf_vport *vport, 1141 + struct idpf_rx_queue *q) 1326 1142 { 1327 - if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { 1143 + if (idpf_is_queue_model_split(vport->rxq_model)) { 1328 1144 q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M; 1329 1145 } else { 1330 1146 if (vport->base_rxd) ··· 1344 1158 */ 1345 1159 static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) 1346 1160 { 1347 - bool flow_sch_en; 1348 - int err, i; 1161 + bool split, flow_sch_en; 1162 + int i; 1349 1163 1350 1164 vport->txq_grps = kcalloc(vport->num_txq_grp, 1351 1165 sizeof(*vport->txq_grps), GFP_KERNEL); 1352 1166 if (!vport->txq_grps) 1353 1167 return -ENOMEM; 1354 1168 1169 + split = idpf_is_queue_model_split(vport->txq_model); 1355 1170 flow_sch_en = !idpf_is_cap_ena(vport->adapter, IDPF_OTHER_CAPS, 1356 1171 VIRTCHNL2_CAP_SPLITQ_QSCHED); 1357 1172 1358 1173 for (i = 0; i < vport->num_txq_grp; i++) { 1359 1174 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 1360 1175 struct idpf_adapter *adapter = vport->adapter; 1176 + struct idpf_txq_stash *stashes; 1361 1177 int j; 1362 1178 1363 1179 tx_qgrp->vport = vport; ··· 1368 1180 for (j = 0; j < tx_qgrp->num_txq; j++) { 1369 1181 tx_qgrp->txqs[j] = kzalloc(sizeof(*tx_qgrp->txqs[j]), 1370 1182 GFP_KERNEL); 1371 - if (!tx_qgrp->txqs[j]) { 1372 - err = -ENOMEM; 1183 + if (!tx_qgrp->txqs[j]) 1373 1184 goto err_alloc; 1374 - } 1185 + } 1186 + 1187 + if (split && flow_sch_en) { 1188 + stashes = kcalloc(num_txq, sizeof(*stashes), 1189 + GFP_KERNEL); 1190 + if (!stashes) 1191 + goto err_alloc; 1192 + 1193 + tx_qgrp->stashes = stashes; 1375 1194 } 1376 1195 1377 1196 for (j = 0; j < tx_qgrp->num_txq; j++) { 1378 - struct idpf_queue *q = tx_qgrp->txqs[j]; 1197 + struct idpf_tx_queue *q = tx_qgrp->txqs[j]; 1379 1198 1380 1199 q->dev = &adapter->pdev->dev; 1381 1200 q->desc_count = vport->txq_desc_count; 1382 1201 q->tx_max_bufs = idpf_get_max_tx_bufs(adapter); 1383 1202 q->tx_min_pkt_len = idpf_get_min_tx_pkt_len(adapter); 1384 - q->vport = vport; 1203 + q->netdev = vport->netdev; 1385 1204 q->txq_grp = tx_qgrp; 1386 - hash_init(q->sched_buf_hash); 1387 1205 1388 - if (flow_sch_en) 1389 - set_bit(__IDPF_Q_FLOW_SCH_EN, q->flags); 1206 + if (!split) { 1207 + q->clean_budget = vport->compln_clean_budget; 1208 + idpf_queue_assign(CRC_EN, q, 1209 + vport->crc_enable); 1210 + } 1211 + 1212 + if (!flow_sch_en) 1213 + continue; 1214 + 1215 + if (split) { 1216 + q->stash = &stashes[j]; 1217 + hash_init(q->stash->sched_buf_hash); 1218 + } 1219 + 1220 + idpf_queue_set(FLOW_SCH_EN, q); 1390 1221 } 1391 1222 1392 - if (!idpf_is_queue_model_split(vport->txq_model)) 1223 + if (!split) 1393 1224 continue; 1394 1225 1395 1226 tx_qgrp->complq = kcalloc(IDPF_COMPLQ_PER_GROUP, 1396 1227 sizeof(*tx_qgrp->complq), 1397 1228 GFP_KERNEL); 1398 - if (!tx_qgrp->complq) { 1399 - err = -ENOMEM; 1229 + if (!tx_qgrp->complq) 1400 1230 goto err_alloc; 1401 - } 1402 1231 1403 - tx_qgrp->complq->dev = &adapter->pdev->dev; 1404 1232 tx_qgrp->complq->desc_count = vport->complq_desc_count; 1405 - tx_qgrp->complq->vport = vport; 1406 1233 tx_qgrp->complq->txq_grp = tx_qgrp; 1234 + tx_qgrp->complq->netdev = vport->netdev; 1235 + tx_qgrp->complq->clean_budget = vport->compln_clean_budget; 1407 1236 1408 1237 if (flow_sch_en) 1409 - __set_bit(__IDPF_Q_FLOW_SCH_EN, tx_qgrp->complq->flags); 1238 + idpf_queue_set(FLOW_SCH_EN, tx_qgrp->complq); 1410 1239 } 1411 1240 1412 1241 return 0; ··· 1431 1226 err_alloc: 1432 1227 idpf_txq_group_rel(vport); 1433 1228 1434 - return err; 1229 + return -ENOMEM; 1435 1230 } 1436 1231 1437 1232 /** ··· 1443 1238 */ 1444 1239 static int idpf_rxq_group_alloc(struct idpf_vport *vport, u16 num_rxq) 1445 1240 { 1446 - struct idpf_adapter *adapter = vport->adapter; 1447 - struct idpf_queue *q; 1448 1241 int i, k, err = 0; 1449 1242 bool hs; 1450 1243 ··· 1495 1292 struct idpf_bufq_set *bufq_set = 1496 1293 &rx_qgrp->splitq.bufq_sets[j]; 1497 1294 int swq_size = sizeof(struct idpf_sw_queue); 1295 + struct idpf_buf_queue *q; 1498 1296 1499 1297 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 1500 - q->dev = &adapter->pdev->dev; 1501 1298 q->desc_count = vport->bufq_desc_count[j]; 1502 - q->vport = vport; 1503 - q->rxq_grp = rx_qgrp; 1504 - q->idx = j; 1505 - q->rx_buf_size = vport->bufq_size[j]; 1506 1299 q->rx_buffer_low_watermark = IDPF_LOW_WATERMARK; 1507 - q->rx_buf_stride = IDPF_RX_BUF_STRIDE; 1508 1300 1509 - if (hs) { 1510 - q->rx_hsplit_en = true; 1511 - q->rx_hbuf_size = IDPF_HDR_BUF_SIZE; 1512 - } 1301 + idpf_queue_assign(HSPLIT_EN, q, hs); 1513 1302 1514 1303 bufq_set->num_refillqs = num_rxq; 1515 1304 bufq_set->refillqs = kcalloc(num_rxq, swq_size, ··· 1514 1319 struct idpf_sw_queue *refillq = 1515 1320 &bufq_set->refillqs[k]; 1516 1321 1517 - refillq->dev = &vport->adapter->pdev->dev; 1518 1322 refillq->desc_count = 1519 1323 vport->bufq_desc_count[j]; 1520 - set_bit(__IDPF_Q_GEN_CHK, refillq->flags); 1521 - set_bit(__IDPF_RFLQ_GEN_CHK, refillq->flags); 1324 + idpf_queue_set(GEN_CHK, refillq); 1325 + idpf_queue_set(RFL_GEN_CHK, refillq); 1522 1326 refillq->ring = kcalloc(refillq->desc_count, 1523 - sizeof(u16), 1327 + sizeof(*refillq->ring), 1524 1328 GFP_KERNEL); 1525 1329 if (!refillq->ring) { 1526 1330 err = -ENOMEM; ··· 1530 1336 1531 1337 skip_splitq_rx_init: 1532 1338 for (j = 0; j < num_rxq; j++) { 1339 + struct idpf_rx_queue *q; 1340 + 1533 1341 if (!idpf_is_queue_model_split(vport->rxq_model)) { 1534 1342 q = rx_qgrp->singleq.rxqs[j]; 1535 1343 goto setup_rxq; 1536 1344 } 1537 1345 q = &rx_qgrp->splitq.rxq_sets[j]->rxq; 1538 - rx_qgrp->splitq.rxq_sets[j]->refillq0 = 1346 + rx_qgrp->splitq.rxq_sets[j]->refillq[0] = 1539 1347 &rx_qgrp->splitq.bufq_sets[0].refillqs[j]; 1540 1348 if (vport->num_bufqs_per_qgrp > IDPF_SINGLE_BUFQ_PER_RXQ_GRP) 1541 - rx_qgrp->splitq.rxq_sets[j]->refillq1 = 1349 + rx_qgrp->splitq.rxq_sets[j]->refillq[1] = 1542 1350 &rx_qgrp->splitq.bufq_sets[1].refillqs[j]; 1543 1351 1544 - if (hs) { 1545 - q->rx_hsplit_en = true; 1546 - q->rx_hbuf_size = IDPF_HDR_BUF_SIZE; 1547 - } 1352 + idpf_queue_assign(HSPLIT_EN, q, hs); 1548 1353 1549 1354 setup_rxq: 1550 - q->dev = &adapter->pdev->dev; 1551 1355 q->desc_count = vport->rxq_desc_count; 1552 - q->vport = vport; 1553 - q->rxq_grp = rx_qgrp; 1356 + q->rx_ptype_lkup = vport->rx_ptype_lkup; 1357 + q->netdev = vport->netdev; 1358 + q->bufq_sets = rx_qgrp->splitq.bufq_sets; 1554 1359 q->idx = (i * num_rxq) + j; 1555 - /* In splitq mode, RXQ buffer size should be 1556 - * set to that of the first buffer queue 1557 - * associated with this RXQ 1558 - */ 1559 - q->rx_buf_size = vport->bufq_size[0]; 1560 1360 q->rx_buffer_low_watermark = IDPF_LOW_WATERMARK; 1561 1361 q->rx_max_pkt_size = vport->netdev->mtu + 1562 - IDPF_PACKET_HDR_PAD; 1362 + LIBETH_RX_LL_LEN; 1563 1363 idpf_rxq_set_descids(vport, q); 1564 1364 } 1565 1365 } ··· 1633 1445 * idpf_tx_handle_sw_marker - Handle queue marker packet 1634 1446 * @tx_q: tx queue to handle software marker 1635 1447 */ 1636 - static void idpf_tx_handle_sw_marker(struct idpf_queue *tx_q) 1448 + static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q) 1637 1449 { 1638 - struct idpf_vport *vport = tx_q->vport; 1450 + struct idpf_netdev_priv *priv = netdev_priv(tx_q->netdev); 1451 + struct idpf_vport *vport = priv->vport; 1639 1452 int i; 1640 1453 1641 - clear_bit(__IDPF_Q_SW_MARKER, tx_q->flags); 1454 + idpf_queue_clear(SW_MARKER, tx_q); 1642 1455 /* Hardware must write marker packets to all queues associated with 1643 1456 * completion queues. So check if all queues received marker packets 1644 1457 */ ··· 1647 1458 /* If we're still waiting on any other TXQ marker completions, 1648 1459 * just return now since we cannot wake up the marker_wq yet. 1649 1460 */ 1650 - if (test_bit(__IDPF_Q_SW_MARKER, vport->txqs[i]->flags)) 1461 + if (idpf_queue_has(SW_MARKER, vport->txqs[i])) 1651 1462 return; 1652 1463 1653 1464 /* Drain complete */ ··· 1663 1474 * @cleaned: pointer to stats struct to track cleaned packets/bytes 1664 1475 * @napi_budget: Used to determine if we are in netpoll 1665 1476 */ 1666 - static void idpf_tx_splitq_clean_hdr(struct idpf_queue *tx_q, 1477 + static void idpf_tx_splitq_clean_hdr(struct idpf_tx_queue *tx_q, 1667 1478 struct idpf_tx_buf *tx_buf, 1668 1479 struct idpf_cleaned_stats *cleaned, 1669 1480 int napi_budget) ··· 1694 1505 * @cleaned: pointer to stats struct to track cleaned packets/bytes 1695 1506 * @budget: Used to determine if we are in netpoll 1696 1507 */ 1697 - static void idpf_tx_clean_stashed_bufs(struct idpf_queue *txq, u16 compl_tag, 1508 + static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq, 1509 + u16 compl_tag, 1698 1510 struct idpf_cleaned_stats *cleaned, 1699 1511 int budget) 1700 1512 { ··· 1703 1513 struct hlist_node *tmp_buf; 1704 1514 1705 1515 /* Buffer completion */ 1706 - hash_for_each_possible_safe(txq->sched_buf_hash, stash, tmp_buf, 1516 + hash_for_each_possible_safe(txq->stash->sched_buf_hash, stash, tmp_buf, 1707 1517 hlist, compl_tag) { 1708 1518 if (unlikely(stash->buf.compl_tag != (int)compl_tag)) 1709 1519 continue; ··· 1720 1530 } 1721 1531 1722 1532 /* Push shadow buf back onto stack */ 1723 - idpf_buf_lifo_push(&txq->buf_stack, stash); 1533 + idpf_buf_lifo_push(&txq->stash->buf_stack, stash); 1724 1534 1725 1535 hash_del(&stash->hlist); 1726 1536 } ··· 1732 1542 * @txq: Tx queue to clean 1733 1543 * @tx_buf: buffer to store 1734 1544 */ 1735 - static int idpf_stash_flow_sch_buffers(struct idpf_queue *txq, 1545 + static int idpf_stash_flow_sch_buffers(struct idpf_tx_queue *txq, 1736 1546 struct idpf_tx_buf *tx_buf) 1737 1547 { 1738 1548 struct idpf_tx_stash *stash; ··· 1741 1551 !dma_unmap_len(tx_buf, len))) 1742 1552 return 0; 1743 1553 1744 - stash = idpf_buf_lifo_pop(&txq->buf_stack); 1554 + stash = idpf_buf_lifo_pop(&txq->stash->buf_stack); 1745 1555 if (unlikely(!stash)) { 1746 1556 net_err_ratelimited("%s: No out-of-order TX buffers left!\n", 1747 - txq->vport->netdev->name); 1557 + netdev_name(txq->netdev)); 1748 1558 1749 1559 return -ENOMEM; 1750 1560 } ··· 1758 1568 stash->buf.compl_tag = tx_buf->compl_tag; 1759 1569 1760 1570 /* Add buffer to buf_hash table to be freed later */ 1761 - hash_add(txq->sched_buf_hash, &stash->hlist, stash->buf.compl_tag); 1571 + hash_add(txq->stash->sched_buf_hash, &stash->hlist, 1572 + stash->buf.compl_tag); 1762 1573 1763 1574 memset(tx_buf, 0, sizeof(struct idpf_tx_buf)); 1764 1575 ··· 1775 1584 if (unlikely(!(ntc))) { \ 1776 1585 ntc -= (txq)->desc_count; \ 1777 1586 buf = (txq)->tx_buf; \ 1778 - desc = IDPF_FLEX_TX_DESC(txq, 0); \ 1587 + desc = &(txq)->flex_tx[0]; \ 1779 1588 } else { \ 1780 1589 (buf)++; \ 1781 1590 (desc)++; \ ··· 1798 1607 * and the buffers will be cleaned separately. The stats are not updated from 1799 1608 * this function when using flow-based scheduling. 1800 1609 */ 1801 - static void idpf_tx_splitq_clean(struct idpf_queue *tx_q, u16 end, 1610 + static void idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, 1802 1611 int napi_budget, 1803 1612 struct idpf_cleaned_stats *cleaned, 1804 1613 bool descs_only) ··· 1808 1617 s16 ntc = tx_q->next_to_clean; 1809 1618 struct idpf_tx_buf *tx_buf; 1810 1619 1811 - tx_desc = IDPF_FLEX_TX_DESC(tx_q, ntc); 1812 - next_pending_desc = IDPF_FLEX_TX_DESC(tx_q, end); 1620 + tx_desc = &tx_q->flex_tx[ntc]; 1621 + next_pending_desc = &tx_q->flex_tx[end]; 1813 1622 tx_buf = &tx_q->tx_buf[ntc]; 1814 1623 ntc -= tx_q->desc_count; 1815 1624 ··· 1894 1703 * stashed. Returns the byte/segment count for the cleaned packet associated 1895 1704 * this completion tag. 1896 1705 */ 1897 - static bool idpf_tx_clean_buf_ring(struct idpf_queue *txq, u16 compl_tag, 1706 + static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, 1898 1707 struct idpf_cleaned_stats *cleaned, 1899 1708 int budget) 1900 1709 { ··· 1963 1772 * 1964 1773 * Returns bytes/packets cleaned 1965 1774 */ 1966 - static void idpf_tx_handle_rs_completion(struct idpf_queue *txq, 1775 + static void idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq, 1967 1776 struct idpf_splitq_tx_compl_desc *desc, 1968 1777 struct idpf_cleaned_stats *cleaned, 1969 1778 int budget) 1970 1779 { 1971 1780 u16 compl_tag; 1972 1781 1973 - if (!test_bit(__IDPF_Q_FLOW_SCH_EN, txq->flags)) { 1782 + if (!idpf_queue_has(FLOW_SCH_EN, txq)) { 1974 1783 u16 head = le16_to_cpu(desc->q_head_compl_tag.q_head); 1975 1784 1976 1785 return idpf_tx_splitq_clean(txq, head, budget, cleaned, false); ··· 1993 1802 * 1994 1803 * Returns true if there's any budget left (e.g. the clean is finished) 1995 1804 */ 1996 - static bool idpf_tx_clean_complq(struct idpf_queue *complq, int budget, 1805 + static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget, 1997 1806 int *cleaned) 1998 1807 { 1999 1808 struct idpf_splitq_tx_compl_desc *tx_desc; 2000 - struct idpf_vport *vport = complq->vport; 2001 1809 s16 ntc = complq->next_to_clean; 2002 1810 struct idpf_netdev_priv *np; 2003 1811 unsigned int complq_budget; 2004 1812 bool complq_ok = true; 2005 1813 int i; 2006 1814 2007 - complq_budget = vport->compln_clean_budget; 2008 - tx_desc = IDPF_SPLITQ_TX_COMPLQ_DESC(complq, ntc); 1815 + complq_budget = complq->clean_budget; 1816 + tx_desc = &complq->comp[ntc]; 2009 1817 ntc -= complq->desc_count; 2010 1818 2011 1819 do { 2012 1820 struct idpf_cleaned_stats cleaned_stats = { }; 2013 - struct idpf_queue *tx_q; 1821 + struct idpf_tx_queue *tx_q; 2014 1822 int rel_tx_qid; 2015 1823 u16 hw_head; 2016 1824 u8 ctype; /* completion type */ ··· 2018 1828 /* if the descriptor isn't done, no work yet to do */ 2019 1829 gen = le16_get_bits(tx_desc->qid_comptype_gen, 2020 1830 IDPF_TXD_COMPLQ_GEN_M); 2021 - if (test_bit(__IDPF_Q_GEN_CHK, complq->flags) != gen) 1831 + if (idpf_queue_has(GEN_CHK, complq) != gen) 2022 1832 break; 2023 1833 2024 1834 /* Find necessary info of TX queue to clean buffers */ ··· 2026 1836 IDPF_TXD_COMPLQ_QID_M); 2027 1837 if (rel_tx_qid >= complq->txq_grp->num_txq || 2028 1838 !complq->txq_grp->txqs[rel_tx_qid]) { 2029 - dev_err(&complq->vport->adapter->pdev->dev, 2030 - "TxQ not found\n"); 1839 + netdev_err(complq->netdev, "TxQ not found\n"); 2031 1840 goto fetch_next_desc; 2032 1841 } 2033 1842 tx_q = complq->txq_grp->txqs[rel_tx_qid]; ··· 2049 1860 idpf_tx_handle_sw_marker(tx_q); 2050 1861 break; 2051 1862 default: 2052 - dev_err(&tx_q->vport->adapter->pdev->dev, 2053 - "Unknown TX completion type: %d\n", 2054 - ctype); 1863 + netdev_err(tx_q->netdev, 1864 + "Unknown TX completion type: %d\n", ctype); 2055 1865 goto fetch_next_desc; 2056 1866 } 2057 1867 2058 1868 u64_stats_update_begin(&tx_q->stats_sync); 2059 - u64_stats_add(&tx_q->q_stats.tx.packets, cleaned_stats.packets); 2060 - u64_stats_add(&tx_q->q_stats.tx.bytes, cleaned_stats.bytes); 1869 + u64_stats_add(&tx_q->q_stats.packets, cleaned_stats.packets); 1870 + u64_stats_add(&tx_q->q_stats.bytes, cleaned_stats.bytes); 2061 1871 tx_q->cleaned_pkts += cleaned_stats.packets; 2062 1872 tx_q->cleaned_bytes += cleaned_stats.bytes; 2063 1873 complq->num_completions++; ··· 2067 1879 ntc++; 2068 1880 if (unlikely(!ntc)) { 2069 1881 ntc -= complq->desc_count; 2070 - tx_desc = IDPF_SPLITQ_TX_COMPLQ_DESC(complq, 0); 2071 - change_bit(__IDPF_Q_GEN_CHK, complq->flags); 1882 + tx_desc = &complq->comp[0]; 1883 + idpf_queue_change(GEN_CHK, complq); 2072 1884 } 2073 1885 2074 1886 prefetch(tx_desc); ··· 2084 1896 IDPF_TX_COMPLQ_OVERFLOW_THRESH(complq))) 2085 1897 complq_ok = false; 2086 1898 2087 - np = netdev_priv(complq->vport->netdev); 1899 + np = netdev_priv(complq->netdev); 2088 1900 for (i = 0; i < complq->txq_grp->num_txq; ++i) { 2089 - struct idpf_queue *tx_q = complq->txq_grp->txqs[i]; 1901 + struct idpf_tx_queue *tx_q = complq->txq_grp->txqs[i]; 2090 1902 struct netdev_queue *nq; 2091 1903 bool dont_wake; 2092 1904 ··· 2097 1909 *cleaned += tx_q->cleaned_pkts; 2098 1910 2099 1911 /* Update BQL */ 2100 - nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx); 1912 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 2101 1913 2102 1914 dont_wake = !complq_ok || IDPF_TX_BUF_RSV_LOW(tx_q) || 2103 1915 np->state != __IDPF_VPORT_UP || 2104 - !netif_carrier_ok(tx_q->vport->netdev); 1916 + !netif_carrier_ok(tx_q->netdev); 2105 1917 /* Check if the TXQ needs to and can be restarted */ 2106 1918 __netif_txq_completed_wake(nq, tx_q->cleaned_pkts, tx_q->cleaned_bytes, 2107 1919 IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH, ··· 2164 1976 * 2165 1977 * Returns 0 if stop is not needed 2166 1978 */ 2167 - int idpf_tx_maybe_stop_common(struct idpf_queue *tx_q, unsigned int size) 1979 + int idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q, unsigned int size) 2168 1980 { 2169 1981 struct netdev_queue *nq; 2170 1982 ··· 2172 1984 return 0; 2173 1985 2174 1986 u64_stats_update_begin(&tx_q->stats_sync); 2175 - u64_stats_inc(&tx_q->q_stats.tx.q_busy); 1987 + u64_stats_inc(&tx_q->q_stats.q_busy); 2176 1988 u64_stats_update_end(&tx_q->stats_sync); 2177 1989 2178 - nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx); 1990 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 2179 1991 2180 1992 return netif_txq_maybe_stop(nq, IDPF_DESC_UNUSED(tx_q), size, size); 2181 1993 } ··· 2187 1999 * 2188 2000 * Returns 0 if stop is not needed 2189 2001 */ 2190 - static int idpf_tx_maybe_stop_splitq(struct idpf_queue *tx_q, 2002 + static int idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q, 2191 2003 unsigned int descs_needed) 2192 2004 { 2193 2005 if (idpf_tx_maybe_stop_common(tx_q, descs_needed)) ··· 2211 2023 2212 2024 splitq_stop: 2213 2025 u64_stats_update_begin(&tx_q->stats_sync); 2214 - u64_stats_inc(&tx_q->q_stats.tx.q_busy); 2026 + u64_stats_inc(&tx_q->q_stats.q_busy); 2215 2027 u64_stats_update_end(&tx_q->stats_sync); 2216 - netif_stop_subqueue(tx_q->vport->netdev, tx_q->idx); 2028 + netif_stop_subqueue(tx_q->netdev, tx_q->idx); 2217 2029 2218 2030 return -EBUSY; 2219 2031 } ··· 2228 2040 * to do a register write to update our queue status. We know this can only 2229 2041 * mean tail here as HW should be owning head for TX. 2230 2042 */ 2231 - void idpf_tx_buf_hw_update(struct idpf_queue *tx_q, u32 val, 2043 + void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, 2232 2044 bool xmit_more) 2233 2045 { 2234 2046 struct netdev_queue *nq; 2235 2047 2236 - nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx); 2048 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 2237 2049 tx_q->next_to_use = val; 2238 2050 2239 2051 idpf_tx_maybe_stop_common(tx_q, IDPF_TX_DESC_NEEDED); ··· 2257 2069 * 2258 2070 * Returns number of data descriptors needed for this skb. 2259 2071 */ 2260 - unsigned int idpf_tx_desc_count_required(struct idpf_queue *txq, 2072 + unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, 2261 2073 struct sk_buff *skb) 2262 2074 { 2263 2075 const struct skb_shared_info *shinfo; ··· 2290 2102 2291 2103 count = idpf_size_to_txd_count(skb->len); 2292 2104 u64_stats_update_begin(&txq->stats_sync); 2293 - u64_stats_inc(&txq->q_stats.tx.linearize); 2105 + u64_stats_inc(&txq->q_stats.linearize); 2294 2106 u64_stats_update_end(&txq->stats_sync); 2295 2107 } 2296 2108 ··· 2304 2116 * @first: original first buffer info buffer for packet 2305 2117 * @idx: starting point on ring to unwind 2306 2118 */ 2307 - void idpf_tx_dma_map_error(struct idpf_queue *txq, struct sk_buff *skb, 2119 + void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb, 2308 2120 struct idpf_tx_buf *first, u16 idx) 2309 2121 { 2310 2122 u64_stats_update_begin(&txq->stats_sync); 2311 - u64_stats_inc(&txq->q_stats.tx.dma_map_errs); 2123 + u64_stats_inc(&txq->q_stats.dma_map_errs); 2312 2124 u64_stats_update_end(&txq->stats_sync); 2313 2125 2314 2126 /* clear dma mappings for failed tx_buf map */ ··· 2331 2143 * used one additional descriptor for a context 2332 2144 * descriptor. Reset that here. 2333 2145 */ 2334 - tx_desc = IDPF_FLEX_TX_DESC(txq, idx); 2146 + tx_desc = &txq->flex_tx[idx]; 2335 2147 memset(tx_desc, 0, sizeof(struct idpf_flex_tx_ctx_desc)); 2336 2148 if (idx == 0) 2337 2149 idx = txq->desc_count; ··· 2347 2159 * @txq: the tx ring to wrap 2348 2160 * @ntu: ring index to bump 2349 2161 */ 2350 - static unsigned int idpf_tx_splitq_bump_ntu(struct idpf_queue *txq, u16 ntu) 2162 + static unsigned int idpf_tx_splitq_bump_ntu(struct idpf_tx_queue *txq, u16 ntu) 2351 2163 { 2352 2164 ntu++; 2353 2165 ··· 2369 2181 * and gets a physical address for each memory location and programs 2370 2182 * it and the length into the transmit flex descriptor. 2371 2183 */ 2372 - static void idpf_tx_splitq_map(struct idpf_queue *tx_q, 2184 + static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, 2373 2185 struct idpf_tx_splitq_params *params, 2374 2186 struct idpf_tx_buf *first) 2375 2187 { ··· 2390 2202 data_len = skb->data_len; 2391 2203 size = skb_headlen(skb); 2392 2204 2393 - tx_desc = IDPF_FLEX_TX_DESC(tx_q, i); 2205 + tx_desc = &tx_q->flex_tx[i]; 2394 2206 2395 2207 dma = dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE); 2396 2208 ··· 2463 2275 i++; 2464 2276 2465 2277 if (i == tx_q->desc_count) { 2466 - tx_desc = IDPF_FLEX_TX_DESC(tx_q, 0); 2278 + tx_desc = &tx_q->flex_tx[0]; 2467 2279 i = 0; 2468 2280 tx_q->compl_tag_cur_gen = 2469 2281 IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); ··· 2508 2320 i++; 2509 2321 2510 2322 if (i == tx_q->desc_count) { 2511 - tx_desc = IDPF_FLEX_TX_DESC(tx_q, 0); 2323 + tx_desc = &tx_q->flex_tx[0]; 2512 2324 i = 0; 2513 2325 tx_q->compl_tag_cur_gen = IDPF_TX_ADJ_COMPL_TAG_GEN(tx_q); 2514 2326 } ··· 2536 2348 tx_q->txq_grp->num_completions_pending++; 2537 2349 2538 2350 /* record bytecount for BQL */ 2539 - nq = netdev_get_tx_queue(tx_q->vport->netdev, tx_q->idx); 2351 + nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx); 2540 2352 netdev_tx_sent_queue(nq, first->bytecount); 2541 2353 2542 2354 idpf_tx_buf_hw_update(tx_q, i, netdev_xmit_more()); ··· 2713 2525 * E.g.: a packet with 7 fragments can require 9 DMA transactions; 1 for TSO 2714 2526 * header, 1 for segment payload, and then 7 for the fragments. 2715 2527 */ 2716 - bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, 2717 - unsigned int count) 2528 + static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, 2529 + unsigned int count) 2718 2530 { 2719 2531 if (likely(count < max_bufs)) 2720 2532 return false; ··· 2732 2544 * ring entry to reflect that this index is a context descriptor 2733 2545 */ 2734 2546 static struct idpf_flex_tx_ctx_desc * 2735 - idpf_tx_splitq_get_ctx_desc(struct idpf_queue *txq) 2547 + idpf_tx_splitq_get_ctx_desc(struct idpf_tx_queue *txq) 2736 2548 { 2737 2549 struct idpf_flex_tx_ctx_desc *desc; 2738 2550 int i = txq->next_to_use; ··· 2741 2553 txq->tx_buf[i].compl_tag = IDPF_SPLITQ_TX_INVAL_COMPL_TAG; 2742 2554 2743 2555 /* grab the next descriptor */ 2744 - desc = IDPF_FLEX_TX_CTX_DESC(txq, i); 2556 + desc = &txq->flex_ctx[i]; 2745 2557 txq->next_to_use = idpf_tx_splitq_bump_ntu(txq, i); 2746 2558 2747 2559 return desc; ··· 2752 2564 * @tx_q: queue to send buffer on 2753 2565 * @skb: pointer to skb 2754 2566 */ 2755 - netdev_tx_t idpf_tx_drop_skb(struct idpf_queue *tx_q, struct sk_buff *skb) 2567 + netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb) 2756 2568 { 2757 2569 u64_stats_update_begin(&tx_q->stats_sync); 2758 - u64_stats_inc(&tx_q->q_stats.tx.skb_drops); 2570 + u64_stats_inc(&tx_q->q_stats.skb_drops); 2759 2571 u64_stats_update_end(&tx_q->stats_sync); 2760 2572 2761 2573 idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false); ··· 2773 2585 * Returns NETDEV_TX_OK if sent, else an error code 2774 2586 */ 2775 2587 static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, 2776 - struct idpf_queue *tx_q) 2588 + struct idpf_tx_queue *tx_q) 2777 2589 { 2778 2590 struct idpf_tx_splitq_params tx_params = { }; 2779 2591 struct idpf_tx_buf *first; ··· 2813 2625 ctx_desc->tso.qw0.hdr_len = tx_params.offload.tso_hdr_len; 2814 2626 2815 2627 u64_stats_update_begin(&tx_q->stats_sync); 2816 - u64_stats_inc(&tx_q->q_stats.tx.lso_pkts); 2628 + u64_stats_inc(&tx_q->q_stats.lso_pkts); 2817 2629 u64_stats_update_end(&tx_q->stats_sync); 2818 2630 } 2819 2631 ··· 2830 2642 first->bytecount = max_t(unsigned int, skb->len, ETH_ZLEN); 2831 2643 } 2832 2644 2833 - if (test_bit(__IDPF_Q_FLOW_SCH_EN, tx_q->flags)) { 2645 + if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { 2834 2646 tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE; 2835 2647 tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; 2836 2648 /* Set the RE bit to catch any packets that may have not been ··· 2860 2672 } 2861 2673 2862 2674 /** 2863 - * idpf_tx_splitq_start - Selects the right Tx queue to send buffer 2675 + * idpf_tx_start - Selects the right Tx queue to send buffer 2864 2676 * @skb: send buffer 2865 2677 * @netdev: network interface device structure 2866 2678 * 2867 2679 * Returns NETDEV_TX_OK if sent, else an error code 2868 2680 */ 2869 - netdev_tx_t idpf_tx_splitq_start(struct sk_buff *skb, 2870 - struct net_device *netdev) 2681 + netdev_tx_t idpf_tx_start(struct sk_buff *skb, struct net_device *netdev) 2871 2682 { 2872 2683 struct idpf_vport *vport = idpf_netdev_to_vport(netdev); 2873 - struct idpf_queue *tx_q; 2684 + struct idpf_tx_queue *tx_q; 2874 2685 2875 2686 if (unlikely(skb_get_queue_mapping(skb) >= vport->num_txq)) { 2876 2687 dev_kfree_skb_any(skb); ··· 2888 2701 return NETDEV_TX_OK; 2889 2702 } 2890 2703 2891 - return idpf_tx_splitq_frame(skb, tx_q); 2892 - } 2893 - 2894 - /** 2895 - * idpf_ptype_to_htype - get a hash type 2896 - * @decoded: Decoded Rx packet type related fields 2897 - * 2898 - * Returns appropriate hash type (such as PKT_HASH_TYPE_L2/L3/L4) to be used by 2899 - * skb_set_hash based on PTYPE as parsed by HW Rx pipeline and is part of 2900 - * Rx desc. 2901 - */ 2902 - enum pkt_hash_types idpf_ptype_to_htype(const struct idpf_rx_ptype_decoded *decoded) 2903 - { 2904 - if (!decoded->known) 2905 - return PKT_HASH_TYPE_NONE; 2906 - if (decoded->payload_layer == IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY2 && 2907 - decoded->inner_prot) 2908 - return PKT_HASH_TYPE_L4; 2909 - if (decoded->payload_layer == IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY2 && 2910 - decoded->outer_ip) 2911 - return PKT_HASH_TYPE_L3; 2912 - if (decoded->outer_ip == IDPF_RX_PTYPE_OUTER_L2) 2913 - return PKT_HASH_TYPE_L2; 2914 - 2915 - return PKT_HASH_TYPE_NONE; 2704 + if (idpf_is_queue_model_split(vport->txq_model)) 2705 + return idpf_tx_splitq_frame(skb, tx_q); 2706 + else 2707 + return idpf_tx_singleq_frame(skb, tx_q); 2916 2708 } 2917 2709 2918 2710 /** ··· 2901 2735 * @rx_desc: Receive descriptor 2902 2736 * @decoded: Decoded Rx packet type related fields 2903 2737 */ 2904 - static void idpf_rx_hash(struct idpf_queue *rxq, struct sk_buff *skb, 2905 - struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, 2906 - struct idpf_rx_ptype_decoded *decoded) 2738 + static void 2739 + idpf_rx_hash(const struct idpf_rx_queue *rxq, struct sk_buff *skb, 2740 + const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, 2741 + struct libeth_rx_pt decoded) 2907 2742 { 2908 2743 u32 hash; 2909 2744 2910 - if (unlikely(!idpf_is_feature_ena(rxq->vport, NETIF_F_RXHASH))) 2745 + if (!libeth_rx_pt_has_hash(rxq->netdev, decoded)) 2911 2746 return; 2912 2747 2913 2748 hash = le16_to_cpu(rx_desc->hash1) | 2914 2749 (rx_desc->ff2_mirrid_hash2.hash2 << 16) | 2915 2750 (rx_desc->hash3 << 24); 2916 2751 2917 - skb_set_hash(skb, hash, idpf_ptype_to_htype(decoded)); 2752 + libeth_rx_pt_set_hash(skb, hash, decoded); 2918 2753 } 2919 2754 2920 2755 /** ··· 2927 2760 * 2928 2761 * skb->protocol must be set before this function is called 2929 2762 */ 2930 - static void idpf_rx_csum(struct idpf_queue *rxq, struct sk_buff *skb, 2931 - struct idpf_rx_csum_decoded *csum_bits, 2932 - struct idpf_rx_ptype_decoded *decoded) 2763 + static void idpf_rx_csum(struct idpf_rx_queue *rxq, struct sk_buff *skb, 2764 + struct idpf_rx_csum_decoded csum_bits, 2765 + struct libeth_rx_pt decoded) 2933 2766 { 2934 2767 bool ipv4, ipv6; 2935 2768 2936 2769 /* check if Rx checksum is enabled */ 2937 - if (unlikely(!idpf_is_feature_ena(rxq->vport, NETIF_F_RXCSUM))) 2770 + if (!libeth_rx_pt_has_checksum(rxq->netdev, decoded)) 2938 2771 return; 2939 2772 2940 2773 /* check if HW has decoded the packet and checksum */ 2941 - if (!(csum_bits->l3l4p)) 2774 + if (unlikely(!csum_bits.l3l4p)) 2942 2775 return; 2943 2776 2944 - ipv4 = IDPF_RX_PTYPE_TO_IPV(decoded, IDPF_RX_PTYPE_OUTER_IPV4); 2945 - ipv6 = IDPF_RX_PTYPE_TO_IPV(decoded, IDPF_RX_PTYPE_OUTER_IPV6); 2777 + ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4; 2778 + ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6; 2946 2779 2947 - if (ipv4 && (csum_bits->ipe || csum_bits->eipe)) 2780 + if (unlikely(ipv4 && (csum_bits.ipe || csum_bits.eipe))) 2948 2781 goto checksum_fail; 2949 2782 2950 - if (ipv6 && csum_bits->ipv6exadd) 2783 + if (unlikely(ipv6 && csum_bits.ipv6exadd)) 2951 2784 return; 2952 2785 2953 2786 /* check for L4 errors and handle packets that were not able to be 2954 2787 * checksummed 2955 2788 */ 2956 - if (csum_bits->l4e) 2789 + if (unlikely(csum_bits.l4e)) 2957 2790 goto checksum_fail; 2958 2791 2959 - /* Only report checksum unnecessary for ICMP, TCP, UDP, or SCTP */ 2960 - switch (decoded->inner_prot) { 2961 - case IDPF_RX_PTYPE_INNER_PROT_ICMP: 2962 - case IDPF_RX_PTYPE_INNER_PROT_TCP: 2963 - case IDPF_RX_PTYPE_INNER_PROT_UDP: 2964 - if (!csum_bits->raw_csum_inv) { 2965 - u16 csum = csum_bits->raw_csum; 2966 - 2967 - skb->csum = csum_unfold((__force __sum16)~swab16(csum)); 2968 - skb->ip_summed = CHECKSUM_COMPLETE; 2969 - } else { 2970 - skb->ip_summed = CHECKSUM_UNNECESSARY; 2971 - } 2972 - break; 2973 - case IDPF_RX_PTYPE_INNER_PROT_SCTP: 2792 + if (csum_bits.raw_csum_inv || 2793 + decoded.inner_prot == LIBETH_RX_PT_INNER_SCTP) { 2974 2794 skb->ip_summed = CHECKSUM_UNNECESSARY; 2975 - break; 2976 - default: 2977 - break; 2795 + return; 2978 2796 } 2797 + 2798 + skb->csum = csum_unfold((__force __sum16)~swab16(csum_bits.raw_csum)); 2799 + skb->ip_summed = CHECKSUM_COMPLETE; 2979 2800 2980 2801 return; 2981 2802 2982 2803 checksum_fail: 2983 2804 u64_stats_update_begin(&rxq->stats_sync); 2984 - u64_stats_inc(&rxq->q_stats.rx.hw_csum_err); 2805 + u64_stats_inc(&rxq->q_stats.hw_csum_err); 2985 2806 u64_stats_update_end(&rxq->stats_sync); 2986 2807 } 2987 2808 2988 2809 /** 2989 2810 * idpf_rx_splitq_extract_csum_bits - Extract checksum bits from descriptor 2990 2811 * @rx_desc: receive descriptor 2991 - * @csum: structure to extract checksum fields 2992 2812 * 2813 + * Return: parsed checksum status. 2993 2814 **/ 2994 - static void idpf_rx_splitq_extract_csum_bits(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, 2995 - struct idpf_rx_csum_decoded *csum) 2815 + static struct idpf_rx_csum_decoded 2816 + idpf_rx_splitq_extract_csum_bits(const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) 2996 2817 { 2818 + struct idpf_rx_csum_decoded csum = { }; 2997 2819 u8 qword0, qword1; 2998 2820 2999 2821 qword0 = rx_desc->status_err0_qw0; 3000 2822 qword1 = rx_desc->status_err0_qw1; 3001 2823 3002 - csum->ipe = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_M, 2824 + csum.ipe = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_IPE_M, 2825 + qword1); 2826 + csum.eipe = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_M, 3003 2827 qword1); 3004 - csum->eipe = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_EIPE_M, 2828 + csum.l4e = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_M, 2829 + qword1); 2830 + csum.l3l4p = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_M, 3005 2831 qword1); 3006 - csum->l4e = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_XSUM_L4E_M, 3007 - qword1); 3008 - csum->l3l4p = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_L3L4P_M, 3009 - qword1); 3010 - csum->ipv6exadd = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_M, 3011 - qword0); 3012 - csum->raw_csum_inv = 2832 + csum.ipv6exadd = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_IPV6EXADD_M, 2833 + qword0); 2834 + csum.raw_csum_inv = 3013 2835 le16_get_bits(rx_desc->ptype_err_fflags0, 3014 2836 VIRTCHNL2_RX_FLEX_DESC_ADV_RAW_CSUM_INV_M); 3015 - csum->raw_csum = le16_to_cpu(rx_desc->misc.raw_cs); 2837 + csum.raw_csum = le16_to_cpu(rx_desc->misc.raw_cs); 2838 + 2839 + return csum; 3016 2840 } 3017 2841 3018 2842 /** ··· 3018 2860 * Populate the skb fields with the total number of RSC segments, RSC payload 3019 2861 * length and packet type. 3020 2862 */ 3021 - static int idpf_rx_rsc(struct idpf_queue *rxq, struct sk_buff *skb, 3022 - struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, 3023 - struct idpf_rx_ptype_decoded *decoded) 2863 + static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb, 2864 + const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, 2865 + struct libeth_rx_pt decoded) 3024 2866 { 3025 2867 u16 rsc_segments, rsc_seg_len; 3026 2868 bool ipv4, ipv6; 3027 2869 int len; 3028 2870 3029 - if (unlikely(!decoded->outer_ip)) 2871 + if (unlikely(libeth_rx_pt_get_ip_ver(decoded) == 2872 + LIBETH_RX_PT_OUTER_L2)) 3030 2873 return -EINVAL; 3031 2874 3032 2875 rsc_seg_len = le16_to_cpu(rx_desc->misc.rscseglen); 3033 2876 if (unlikely(!rsc_seg_len)) 3034 2877 return -EINVAL; 3035 2878 3036 - ipv4 = IDPF_RX_PTYPE_TO_IPV(decoded, IDPF_RX_PTYPE_OUTER_IPV4); 3037 - ipv6 = IDPF_RX_PTYPE_TO_IPV(decoded, IDPF_RX_PTYPE_OUTER_IPV6); 2879 + ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4; 2880 + ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6; 3038 2881 3039 2882 if (unlikely(!(ipv4 ^ ipv6))) 3040 2883 return -EINVAL; ··· 3073 2914 tcp_gro_complete(skb); 3074 2915 3075 2916 u64_stats_update_begin(&rxq->stats_sync); 3076 - u64_stats_inc(&rxq->q_stats.rx.rsc_pkts); 2917 + u64_stats_inc(&rxq->q_stats.rsc_pkts); 3077 2918 u64_stats_update_end(&rxq->stats_sync); 3078 2919 3079 2920 return 0; ··· 3089 2930 * order to populate the hash, checksum, protocol, and 3090 2931 * other fields within the skb. 3091 2932 */ 3092 - static int idpf_rx_process_skb_fields(struct idpf_queue *rxq, 3093 - struct sk_buff *skb, 3094 - struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) 2933 + static int 2934 + idpf_rx_process_skb_fields(struct idpf_rx_queue *rxq, struct sk_buff *skb, 2935 + const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) 3095 2936 { 3096 - struct idpf_rx_csum_decoded csum_bits = { }; 3097 - struct idpf_rx_ptype_decoded decoded; 2937 + struct idpf_rx_csum_decoded csum_bits; 2938 + struct libeth_rx_pt decoded; 3098 2939 u16 rx_ptype; 3099 2940 3100 2941 rx_ptype = le16_get_bits(rx_desc->ptype_err_fflags0, 3101 2942 VIRTCHNL2_RX_FLEX_DESC_ADV_PTYPE_M); 3102 - 3103 - skb->protocol = eth_type_trans(skb, rxq->vport->netdev); 3104 - 3105 - decoded = rxq->vport->rx_ptype_lkup[rx_ptype]; 3106 - /* If we don't know the ptype we can't do anything else with it. Just 3107 - * pass it up the stack as-is. 3108 - */ 3109 - if (!decoded.known) 3110 - return 0; 2943 + decoded = rxq->rx_ptype_lkup[rx_ptype]; 3111 2944 3112 2945 /* process RSS/hash */ 3113 - idpf_rx_hash(rxq, skb, rx_desc, &decoded); 2946 + idpf_rx_hash(rxq, skb, rx_desc, decoded); 2947 + 2948 + skb->protocol = eth_type_trans(skb, rxq->netdev); 3114 2949 3115 2950 if (le16_get_bits(rx_desc->hdrlen_flags, 3116 2951 VIRTCHNL2_RX_FLEX_DESC_ADV_RSC_M)) 3117 - return idpf_rx_rsc(rxq, skb, rx_desc, &decoded); 2952 + return idpf_rx_rsc(rxq, skb, rx_desc, decoded); 3118 2953 3119 - idpf_rx_splitq_extract_csum_bits(rx_desc, &csum_bits); 3120 - idpf_rx_csum(rxq, skb, &csum_bits, &decoded); 2954 + csum_bits = idpf_rx_splitq_extract_csum_bits(rx_desc); 2955 + idpf_rx_csum(rxq, skb, csum_bits, decoded); 2956 + 2957 + skb_record_rx_queue(skb, rxq->idx); 3121 2958 3122 2959 return 0; 3123 2960 } ··· 3131 2976 void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb, 3132 2977 unsigned int size) 3133 2978 { 2979 + u32 hr = rx_buf->page->pp->p.offset; 2980 + 3134 2981 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buf->page, 3135 - rx_buf->page_offset, size, rx_buf->truesize); 3136 - 3137 - rx_buf->page = NULL; 2982 + rx_buf->offset + hr, size, rx_buf->truesize); 3138 2983 } 3139 2984 3140 2985 /** 3141 - * idpf_rx_construct_skb - Allocate skb and populate it 3142 - * @rxq: Rx descriptor queue 3143 - * @rx_buf: Rx buffer to pull data from 3144 - * @size: the length of the packet 2986 + * idpf_rx_hsplit_wa - handle header buffer overflows and split errors 2987 + * @hdr: Rx buffer for the headers 2988 + * @buf: Rx buffer for the payload 2989 + * @data_len: number of bytes received to the payload buffer 3145 2990 * 3146 - * This function allocates an skb. It then populates it with the page 3147 - * data from the current receive descriptor, taking care to set up the 3148 - * skb correctly. 2991 + * When a header buffer overflow occurs or the HW was unable do parse the 2992 + * packet type to perform header split, the whole frame gets placed to the 2993 + * payload buffer. We can't build a valid skb around a payload buffer when 2994 + * the header split is active since it doesn't reserve any head- or tailroom. 2995 + * In that case, copy either the whole frame when it's short or just the 2996 + * Ethernet header to the header buffer to be able to build an skb and adjust 2997 + * the data offset in the payload buffer, IOW emulate the header split. 2998 + * 2999 + * Return: number of bytes copied to the header buffer. 3149 3000 */ 3150 - struct sk_buff *idpf_rx_construct_skb(struct idpf_queue *rxq, 3151 - struct idpf_rx_buf *rx_buf, 3152 - unsigned int size) 3001 + static u32 idpf_rx_hsplit_wa(const struct libeth_fqe *hdr, 3002 + struct libeth_fqe *buf, u32 data_len) 3153 3003 { 3154 - unsigned int headlen; 3155 - struct sk_buff *skb; 3156 - void *va; 3004 + u32 copy = data_len <= L1_CACHE_BYTES ? data_len : ETH_HLEN; 3005 + const void *src; 3006 + void *dst; 3157 3007 3158 - va = page_address(rx_buf->page) + rx_buf->page_offset; 3008 + if (!libeth_rx_sync_for_cpu(buf, copy)) 3009 + return 0; 3159 3010 3160 - /* prefetch first cache line of first page */ 3161 - net_prefetch(va); 3162 - /* allocate a skb to store the frags */ 3163 - skb = napi_alloc_skb(&rxq->q_vector->napi, IDPF_RX_HDR_SIZE); 3164 - if (unlikely(!skb)) { 3165 - idpf_rx_put_page(rx_buf); 3011 + dst = page_address(hdr->page) + hdr->offset + hdr->page->pp->p.offset; 3012 + src = page_address(buf->page) + buf->offset + buf->page->pp->p.offset; 3013 + memcpy(dst, src, LARGEST_ALIGN(copy)); 3166 3014 3167 - return NULL; 3168 - } 3015 + buf->offset += copy; 3169 3016 3170 - skb_record_rx_queue(skb, rxq->idx); 3171 - skb_mark_for_recycle(skb); 3172 - 3173 - /* Determine available headroom for copy */ 3174 - headlen = size; 3175 - if (headlen > IDPF_RX_HDR_SIZE) 3176 - headlen = eth_get_headlen(skb->dev, va, IDPF_RX_HDR_SIZE); 3177 - 3178 - /* align pull length to size of long to optimize memcpy performance */ 3179 - memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long))); 3180 - 3181 - /* if we exhaust the linear part then add what is left as a frag */ 3182 - size -= headlen; 3183 - if (!size) { 3184 - idpf_rx_put_page(rx_buf); 3185 - 3186 - return skb; 3187 - } 3188 - 3189 - skb_add_rx_frag(skb, 0, rx_buf->page, rx_buf->page_offset + headlen, 3190 - size, rx_buf->truesize); 3191 - 3192 - /* Since we're giving the page to the stack, clear our reference to it. 3193 - * We'll get a new one during buffer posting. 3194 - */ 3195 - rx_buf->page = NULL; 3196 - 3197 - return skb; 3017 + return copy; 3198 3018 } 3199 3019 3200 3020 /** 3201 - * idpf_rx_hdr_construct_skb - Allocate skb and populate it from header buffer 3202 - * @rxq: Rx descriptor queue 3203 - * @va: Rx buffer to pull data from 3021 + * idpf_rx_build_skb - Allocate skb and populate it from header buffer 3022 + * @buf: Rx buffer to pull data from 3204 3023 * @size: the length of the packet 3205 3024 * 3206 3025 * This function allocates an skb. It then populates it with the page data from 3207 3026 * the current receive descriptor, taking care to set up the skb correctly. 3208 - * This specifically uses a header buffer to start building the skb. 3209 3027 */ 3210 - static struct sk_buff *idpf_rx_hdr_construct_skb(struct idpf_queue *rxq, 3211 - const void *va, 3212 - unsigned int size) 3028 + struct sk_buff *idpf_rx_build_skb(const struct libeth_fqe *buf, u32 size) 3213 3029 { 3030 + u32 hr = buf->page->pp->p.offset; 3214 3031 struct sk_buff *skb; 3032 + void *va; 3215 3033 3216 - /* allocate a skb to store the frags */ 3217 - skb = napi_alloc_skb(&rxq->q_vector->napi, size); 3034 + va = page_address(buf->page) + buf->offset; 3035 + prefetch(va + hr); 3036 + 3037 + skb = napi_build_skb(va, buf->truesize); 3218 3038 if (unlikely(!skb)) 3219 3039 return NULL; 3220 3040 3221 - skb_record_rx_queue(skb, rxq->idx); 3222 - 3223 - memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); 3224 - 3225 - /* More than likely, a payload fragment, which will use a page from 3226 - * page_pool will be added to the SKB so mark it for recycle 3227 - * preemptively. And if not, it's inconsequential. 3228 - */ 3229 3041 skb_mark_for_recycle(skb); 3042 + 3043 + skb_reserve(skb, hr); 3044 + __skb_put(skb, size); 3230 3045 3231 3046 return skb; 3232 3047 } ··· 3240 3115 * 3241 3116 * Returns amount of work completed 3242 3117 */ 3243 - static int idpf_rx_splitq_clean(struct idpf_queue *rxq, int budget) 3118 + static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget) 3244 3119 { 3245 3120 int total_rx_bytes = 0, total_rx_pkts = 0; 3246 - struct idpf_queue *rx_bufq = NULL; 3121 + struct idpf_buf_queue *rx_bufq = NULL; 3247 3122 struct sk_buff *skb = rxq->skb; 3248 3123 u16 ntc = rxq->next_to_clean; 3249 3124 3250 3125 /* Process Rx packets bounded by budget */ 3251 3126 while (likely(total_rx_pkts < budget)) { 3252 3127 struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc; 3128 + struct libeth_fqe *hdr, *rx_buf = NULL; 3253 3129 struct idpf_sw_queue *refillq = NULL; 3254 3130 struct idpf_rxq_set *rxq_set = NULL; 3255 - struct idpf_rx_buf *rx_buf = NULL; 3256 - union virtchnl2_rx_desc *desc; 3257 3131 unsigned int pkt_len = 0; 3258 3132 unsigned int hdr_len = 0; 3259 3133 u16 gen_id, buf_id = 0; 3260 - /* Header buffer overflow only valid for header split */ 3261 - bool hbo = false; 3262 3134 int bufq_id; 3263 3135 u8 rxdid; 3264 3136 3265 3137 /* get the Rx desc from Rx queue based on 'next_to_clean' */ 3266 - desc = IDPF_RX_DESC(rxq, ntc); 3267 - rx_desc = (struct virtchnl2_rx_flex_desc_adv_nic_3 *)desc; 3138 + rx_desc = &rxq->rx[ntc].flex_adv_nic_3_wb; 3268 3139 3269 3140 /* This memory barrier is needed to keep us from reading 3270 3141 * any other fields out of the rx_desc ··· 3271 3150 gen_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id, 3272 3151 VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M); 3273 3152 3274 - if (test_bit(__IDPF_Q_GEN_CHK, rxq->flags) != gen_id) 3153 + if (idpf_queue_has(GEN_CHK, rxq) != gen_id) 3275 3154 break; 3276 3155 3277 3156 rxdid = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_RXDID_M, ··· 3279 3158 if (rxdid != VIRTCHNL2_RXDID_2_FLEX_SPLITQ) { 3280 3159 IDPF_RX_BUMP_NTC(rxq, ntc); 3281 3160 u64_stats_update_begin(&rxq->stats_sync); 3282 - u64_stats_inc(&rxq->q_stats.rx.bad_descs); 3161 + u64_stats_inc(&rxq->q_stats.bad_descs); 3283 3162 u64_stats_update_end(&rxq->stats_sync); 3284 3163 continue; 3285 3164 } ··· 3287 3166 pkt_len = le16_get_bits(rx_desc->pktlen_gen_bufq_id, 3288 3167 VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_PBUF_M); 3289 3168 3290 - hbo = FIELD_GET(VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_M, 3291 - rx_desc->status_err0_qw1); 3169 + bufq_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id, 3170 + VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M); 3292 3171 3293 - if (unlikely(hbo)) { 3172 + rxq_set = container_of(rxq, struct idpf_rxq_set, rxq); 3173 + refillq = rxq_set->refillq[bufq_id]; 3174 + 3175 + /* retrieve buffer from the rxq */ 3176 + rx_bufq = &rxq->bufq_sets[bufq_id].bufq; 3177 + 3178 + buf_id = le16_to_cpu(rx_desc->buf_id); 3179 + 3180 + rx_buf = &rx_bufq->buf[buf_id]; 3181 + 3182 + if (!rx_bufq->hdr_pp) 3183 + goto payload; 3184 + 3185 + #define __HBO_BIT VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_M 3186 + #define __HDR_LEN_MASK VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M 3187 + if (likely(!(rx_desc->status_err0_qw1 & __HBO_BIT))) 3294 3188 /* If a header buffer overflow, occurs, i.e. header is 3295 3189 * too large to fit in the header split buffer, HW will 3296 3190 * put the entire packet, including headers, in the 3297 3191 * data/payload buffer. 3298 3192 */ 3193 + hdr_len = le16_get_bits(rx_desc->hdrlen_flags, 3194 + __HDR_LEN_MASK); 3195 + #undef __HDR_LEN_MASK 3196 + #undef __HBO_BIT 3197 + 3198 + hdr = &rx_bufq->hdr_buf[buf_id]; 3199 + 3200 + if (unlikely(!hdr_len && !skb)) { 3201 + hdr_len = idpf_rx_hsplit_wa(hdr, rx_buf, pkt_len); 3202 + pkt_len -= hdr_len; 3203 + 3299 3204 u64_stats_update_begin(&rxq->stats_sync); 3300 - u64_stats_inc(&rxq->q_stats.rx.hsplit_buf_ovf); 3205 + u64_stats_inc(&rxq->q_stats.hsplit_buf_ovf); 3301 3206 u64_stats_update_end(&rxq->stats_sync); 3302 - goto bypass_hsplit; 3303 3207 } 3304 3208 3305 - hdr_len = le16_get_bits(rx_desc->hdrlen_flags, 3306 - VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M); 3209 + if (libeth_rx_sync_for_cpu(hdr, hdr_len)) { 3210 + skb = idpf_rx_build_skb(hdr, hdr_len); 3211 + if (!skb) 3212 + break; 3307 3213 3308 - bypass_hsplit: 3309 - bufq_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id, 3310 - VIRTCHNL2_RX_FLEX_DESC_ADV_BUFQ_ID_M); 3214 + u64_stats_update_begin(&rxq->stats_sync); 3215 + u64_stats_inc(&rxq->q_stats.hsplit_pkts); 3216 + u64_stats_update_end(&rxq->stats_sync); 3217 + } 3311 3218 3312 - rxq_set = container_of(rxq, struct idpf_rxq_set, rxq); 3313 - if (!bufq_id) 3314 - refillq = rxq_set->refillq0; 3219 + hdr->page = NULL; 3220 + 3221 + payload: 3222 + if (!libeth_rx_sync_for_cpu(rx_buf, pkt_len)) 3223 + goto skip_data; 3224 + 3225 + if (skb) 3226 + idpf_rx_add_frag(rx_buf, skb, pkt_len); 3315 3227 else 3316 - refillq = rxq_set->refillq1; 3317 - 3318 - /* retrieve buffer from the rxq */ 3319 - rx_bufq = &rxq->rxq_grp->splitq.bufq_sets[bufq_id].bufq; 3320 - 3321 - buf_id = le16_to_cpu(rx_desc->buf_id); 3322 - 3323 - rx_buf = &rx_bufq->rx_buf.buf[buf_id]; 3324 - 3325 - if (hdr_len) { 3326 - const void *va = (u8 *)rx_bufq->rx_buf.hdr_buf_va + 3327 - (u32)buf_id * IDPF_HDR_BUF_SIZE; 3328 - 3329 - skb = idpf_rx_hdr_construct_skb(rxq, va, hdr_len); 3330 - u64_stats_update_begin(&rxq->stats_sync); 3331 - u64_stats_inc(&rxq->q_stats.rx.hsplit_pkts); 3332 - u64_stats_update_end(&rxq->stats_sync); 3333 - } 3334 - 3335 - if (pkt_len) { 3336 - idpf_rx_sync_for_cpu(rx_buf, pkt_len); 3337 - if (skb) 3338 - idpf_rx_add_frag(rx_buf, skb, pkt_len); 3339 - else 3340 - skb = idpf_rx_construct_skb(rxq, rx_buf, 3341 - pkt_len); 3342 - } else { 3343 - idpf_rx_put_page(rx_buf); 3344 - } 3228 + skb = idpf_rx_build_skb(rx_buf, pkt_len); 3345 3229 3346 3230 /* exit if we failed to retrieve a buffer */ 3347 3231 if (!skb) 3348 3232 break; 3349 3233 3350 - idpf_rx_post_buf_refill(refillq, buf_id); 3234 + skip_data: 3235 + rx_buf->page = NULL; 3351 3236 3237 + idpf_rx_post_buf_refill(refillq, buf_id); 3352 3238 IDPF_RX_BUMP_NTC(rxq, ntc); 3239 + 3353 3240 /* skip if it is non EOP desc */ 3354 - if (!idpf_rx_splitq_is_eop(rx_desc)) 3241 + if (!idpf_rx_splitq_is_eop(rx_desc) || unlikely(!skb)) 3355 3242 continue; 3356 3243 3357 3244 /* pad skb if needed (to make valid ethernet frame) */ ··· 3379 3250 } 3380 3251 3381 3252 /* send completed skb up the stack */ 3382 - napi_gro_receive(&rxq->q_vector->napi, skb); 3253 + napi_gro_receive(rxq->napi, skb); 3383 3254 skb = NULL; 3384 3255 3385 3256 /* update budget accounting */ ··· 3390 3261 3391 3262 rxq->skb = skb; 3392 3263 u64_stats_update_begin(&rxq->stats_sync); 3393 - u64_stats_add(&rxq->q_stats.rx.packets, total_rx_pkts); 3394 - u64_stats_add(&rxq->q_stats.rx.bytes, total_rx_bytes); 3264 + u64_stats_add(&rxq->q_stats.packets, total_rx_pkts); 3265 + u64_stats_add(&rxq->q_stats.bytes, total_rx_bytes); 3395 3266 u64_stats_update_end(&rxq->stats_sync); 3396 3267 3397 3268 /* guarantee a trip back through this routine if there was a failure */ ··· 3401 3272 /** 3402 3273 * idpf_rx_update_bufq_desc - Update buffer queue descriptor 3403 3274 * @bufq: Pointer to the buffer queue 3404 - * @refill_desc: SW Refill queue descriptor containing buffer ID 3275 + * @buf_id: buffer ID 3405 3276 * @buf_desc: Buffer queue descriptor 3406 3277 * 3407 3278 * Return 0 on success and negative on failure. 3408 3279 */ 3409 - static int idpf_rx_update_bufq_desc(struct idpf_queue *bufq, u16 refill_desc, 3280 + static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id, 3410 3281 struct virtchnl2_splitq_rx_buf_desc *buf_desc) 3411 3282 { 3412 - struct idpf_rx_buf *buf; 3283 + struct libeth_fq_fp fq = { 3284 + .pp = bufq->pp, 3285 + .fqes = bufq->buf, 3286 + .truesize = bufq->truesize, 3287 + .count = bufq->desc_count, 3288 + }; 3413 3289 dma_addr_t addr; 3414 - u16 buf_id; 3415 3290 3416 - buf_id = FIELD_GET(IDPF_RX_BI_BUFID_M, refill_desc); 3417 - 3418 - buf = &bufq->rx_buf.buf[buf_id]; 3419 - 3420 - addr = idpf_alloc_page(bufq->pp, buf, bufq->rx_buf_size); 3421 - if (unlikely(addr == DMA_MAPPING_ERROR)) 3291 + addr = libeth_rx_alloc(&fq, buf_id); 3292 + if (addr == DMA_MAPPING_ERROR) 3422 3293 return -ENOMEM; 3423 3294 3424 3295 buf_desc->pkt_addr = cpu_to_le64(addr); 3425 3296 buf_desc->qword0.buf_id = cpu_to_le16(buf_id); 3426 3297 3427 - if (!bufq->rx_hsplit_en) 3298 + if (!idpf_queue_has(HSPLIT_EN, bufq)) 3428 3299 return 0; 3429 3300 3430 - buf_desc->hdr_addr = cpu_to_le64(bufq->rx_buf.hdr_buf_pa + 3431 - (u32)buf_id * IDPF_HDR_BUF_SIZE); 3301 + fq.pp = bufq->hdr_pp; 3302 + fq.fqes = bufq->hdr_buf; 3303 + fq.truesize = bufq->hdr_truesize; 3304 + 3305 + addr = libeth_rx_alloc(&fq, buf_id); 3306 + if (addr == DMA_MAPPING_ERROR) 3307 + return -ENOMEM; 3308 + 3309 + buf_desc->hdr_addr = cpu_to_le64(addr); 3432 3310 3433 3311 return 0; 3434 3312 } ··· 3447 3311 * 3448 3312 * This function takes care of the buffer refill management 3449 3313 */ 3450 - static void idpf_rx_clean_refillq(struct idpf_queue *bufq, 3314 + static void idpf_rx_clean_refillq(struct idpf_buf_queue *bufq, 3451 3315 struct idpf_sw_queue *refillq) 3452 3316 { 3453 3317 struct virtchnl2_splitq_rx_buf_desc *buf_desc; 3454 3318 u16 bufq_nta = bufq->next_to_alloc; 3455 3319 u16 ntc = refillq->next_to_clean; 3456 3320 int cleaned = 0; 3457 - u16 gen; 3458 3321 3459 - buf_desc = IDPF_SPLITQ_RX_BUF_DESC(bufq, bufq_nta); 3322 + buf_desc = &bufq->split_buf[bufq_nta]; 3460 3323 3461 3324 /* make sure we stop at ring wrap in the unlikely case ring is full */ 3462 3325 while (likely(cleaned < refillq->desc_count)) { 3463 - u16 refill_desc = IDPF_SPLITQ_RX_BI_DESC(refillq, ntc); 3326 + u32 buf_id, refill_desc = refillq->ring[ntc]; 3464 3327 bool failure; 3465 3328 3466 - gen = FIELD_GET(IDPF_RX_BI_GEN_M, refill_desc); 3467 - if (test_bit(__IDPF_RFLQ_GEN_CHK, refillq->flags) != gen) 3329 + if (idpf_queue_has(RFL_GEN_CHK, refillq) != 3330 + !!(refill_desc & IDPF_RX_BI_GEN_M)) 3468 3331 break; 3469 3332 3470 - failure = idpf_rx_update_bufq_desc(bufq, refill_desc, 3471 - buf_desc); 3333 + buf_id = FIELD_GET(IDPF_RX_BI_BUFID_M, refill_desc); 3334 + failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc); 3472 3335 if (failure) 3473 3336 break; 3474 3337 3475 3338 if (unlikely(++ntc == refillq->desc_count)) { 3476 - change_bit(__IDPF_RFLQ_GEN_CHK, refillq->flags); 3339 + idpf_queue_change(RFL_GEN_CHK, refillq); 3477 3340 ntc = 0; 3478 3341 } 3479 3342 3480 3343 if (unlikely(++bufq_nta == bufq->desc_count)) { 3481 - buf_desc = IDPF_SPLITQ_RX_BUF_DESC(bufq, 0); 3344 + buf_desc = &bufq->split_buf[0]; 3482 3345 bufq_nta = 0; 3483 3346 } else { 3484 3347 buf_desc++; ··· 3506 3371 /** 3507 3372 * idpf_rx_clean_refillq_all - Clean all refill queues 3508 3373 * @bufq: buffer queue with refill queues 3374 + * @nid: ID of the closest NUMA node with memory 3509 3375 * 3510 3376 * Iterates through all refill queues assigned to the buffer queue assigned to 3511 3377 * this vector. Returns true if clean is complete within budget, false 3512 3378 * otherwise. 3513 3379 */ 3514 - static void idpf_rx_clean_refillq_all(struct idpf_queue *bufq) 3380 + static void idpf_rx_clean_refillq_all(struct idpf_buf_queue *bufq, int nid) 3515 3381 { 3516 3382 struct idpf_bufq_set *bufq_set; 3517 3383 int i; 3384 + 3385 + page_pool_nid_changed(bufq->pp, nid); 3386 + if (bufq->hdr_pp) 3387 + page_pool_nid_changed(bufq->hdr_pp, nid); 3518 3388 3519 3389 bufq_set = container_of(bufq, struct idpf_bufq_set, bufq); 3520 3390 for (i = 0; i < bufq_set->num_refillqs; i++) ··· 3581 3441 for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++) { 3582 3442 struct idpf_q_vector *q_vector = &vport->q_vectors[v_idx]; 3583 3443 3444 + kfree(q_vector->complq); 3445 + q_vector->complq = NULL; 3584 3446 kfree(q_vector->bufq); 3585 3447 q_vector->bufq = NULL; 3586 3448 kfree(q_vector->tx); 3587 3449 q_vector->tx = NULL; 3588 3450 kfree(q_vector->rx); 3589 3451 q_vector->rx = NULL; 3452 + 3453 + free_cpumask_var(q_vector->affinity_mask); 3590 3454 } 3591 3455 3592 3456 /* Clean up the mapping of queues to vectors */ ··· 3639 3495 3640 3496 /* clear the affinity_mask in the IRQ descriptor */ 3641 3497 irq_set_affinity_hint(irq_num, NULL); 3642 - free_irq(irq_num, q_vector); 3498 + kfree(free_irq(irq_num, q_vector)); 3643 3499 } 3644 3500 } 3645 3501 ··· 3723 3579 goto check_rx_itr; 3724 3580 3725 3581 for (i = 0, packets = 0, bytes = 0; i < q_vector->num_txq; i++) { 3726 - struct idpf_queue *txq = q_vector->tx[i]; 3582 + struct idpf_tx_queue *txq = q_vector->tx[i]; 3727 3583 unsigned int start; 3728 3584 3729 3585 do { 3730 3586 start = u64_stats_fetch_begin(&txq->stats_sync); 3731 - packets += u64_stats_read(&txq->q_stats.tx.packets); 3732 - bytes += u64_stats_read(&txq->q_stats.tx.bytes); 3587 + packets += u64_stats_read(&txq->q_stats.packets); 3588 + bytes += u64_stats_read(&txq->q_stats.bytes); 3733 3589 } while (u64_stats_fetch_retry(&txq->stats_sync, start)); 3734 3590 } 3735 3591 ··· 3742 3598 return; 3743 3599 3744 3600 for (i = 0, packets = 0, bytes = 0; i < q_vector->num_rxq; i++) { 3745 - struct idpf_queue *rxq = q_vector->rx[i]; 3601 + struct idpf_rx_queue *rxq = q_vector->rx[i]; 3746 3602 unsigned int start; 3747 3603 3748 3604 do { 3749 3605 start = u64_stats_fetch_begin(&rxq->stats_sync); 3750 - packets += u64_stats_read(&rxq->q_stats.rx.packets); 3751 - bytes += u64_stats_read(&rxq->q_stats.rx.bytes); 3606 + packets += u64_stats_read(&rxq->q_stats.packets); 3607 + bytes += u64_stats_read(&rxq->q_stats.bytes); 3752 3608 } while (u64_stats_fetch_retry(&rxq->stats_sync, start)); 3753 3609 } 3754 3610 ··· 3790 3646 3791 3647 for (vector = 0; vector < vport->num_q_vectors; vector++) { 3792 3648 struct idpf_q_vector *q_vector = &vport->q_vectors[vector]; 3649 + char *name; 3793 3650 3794 3651 vidx = vport->q_vector_idxs[vector]; 3795 3652 irq_num = adapter->msix_entries[vidx].vector; ··· 3804 3659 else 3805 3660 continue; 3806 3661 3807 - q_vector->name = kasprintf(GFP_KERNEL, "%s-%s-%d", 3808 - basename, vec_name, vidx); 3662 + name = kasprintf(GFP_KERNEL, "%s-%s-%d", basename, vec_name, 3663 + vidx); 3809 3664 3810 3665 err = request_irq(irq_num, idpf_vport_intr_clean_queues, 0, 3811 - q_vector->name, q_vector); 3666 + name, q_vector); 3812 3667 if (err) { 3813 3668 netdev_err(vport->netdev, 3814 3669 "Request_irq failed, error: %d\n", err); 3815 3670 goto free_q_irqs; 3816 3671 } 3817 3672 /* assign the mask for this irq */ 3818 - irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); 3673 + irq_set_affinity_hint(irq_num, q_vector->affinity_mask); 3819 3674 } 3820 3675 3821 3676 return 0; ··· 3824 3679 while (--vector >= 0) { 3825 3680 vidx = vport->q_vector_idxs[vector]; 3826 3681 irq_num = adapter->msix_entries[vidx].vector; 3827 - free_irq(irq_num, &vport->q_vectors[vector]); 3682 + kfree(free_irq(irq_num, &vport->q_vectors[vector])); 3828 3683 } 3829 3684 3830 3685 return err; ··· 3991 3846 static bool idpf_tx_splitq_clean_all(struct idpf_q_vector *q_vec, 3992 3847 int budget, int *cleaned) 3993 3848 { 3994 - u16 num_txq = q_vec->num_txq; 3849 + u16 num_complq = q_vec->num_complq; 3995 3850 bool clean_complete = true; 3996 3851 int i, budget_per_q; 3997 3852 3998 - if (unlikely(!num_txq)) 3853 + if (unlikely(!num_complq)) 3999 3854 return true; 4000 3855 4001 - budget_per_q = DIV_ROUND_UP(budget, num_txq); 4002 - for (i = 0; i < num_txq; i++) 4003 - clean_complete &= idpf_tx_clean_complq(q_vec->tx[i], 3856 + budget_per_q = DIV_ROUND_UP(budget, num_complq); 3857 + 3858 + for (i = 0; i < num_complq; i++) 3859 + clean_complete &= idpf_tx_clean_complq(q_vec->complq[i], 4004 3860 budget_per_q, cleaned); 4005 3861 4006 3862 return clean_complete; ··· 4022 3876 bool clean_complete = true; 4023 3877 int pkts_cleaned = 0; 4024 3878 int i, budget_per_q; 3879 + int nid; 4025 3880 4026 3881 /* We attempt to distribute budget to each Rx queue fairly, but don't 4027 3882 * allow the budget to go below 1 because that would exit polling early. 4028 3883 */ 4029 3884 budget_per_q = num_rxq ? max(budget / num_rxq, 1) : 0; 4030 3885 for (i = 0; i < num_rxq; i++) { 4031 - struct idpf_queue *rxq = q_vec->rx[i]; 3886 + struct idpf_rx_queue *rxq = q_vec->rx[i]; 4032 3887 int pkts_cleaned_per_q; 4033 3888 4034 3889 pkts_cleaned_per_q = idpf_rx_splitq_clean(rxq, budget_per_q); ··· 4040 3893 } 4041 3894 *cleaned = pkts_cleaned; 4042 3895 3896 + nid = numa_mem_id(); 3897 + 4043 3898 for (i = 0; i < q_vec->num_bufq; i++) 4044 - idpf_rx_clean_refillq_all(q_vec->bufq[i]); 3899 + idpf_rx_clean_refillq_all(q_vec->bufq[i], nid); 4045 3900 4046 3901 return clean_complete; 4047 3902 } ··· 4086 3937 * queues virtchnl message, as the interrupts will be disabled after 4087 3938 * that 4088 3939 */ 4089 - if (unlikely(q_vector->num_txq && test_bit(__IDPF_Q_POLL_MODE, 4090 - q_vector->tx[0]->flags))) 3940 + if (unlikely(q_vector->num_txq && idpf_queue_has(POLL_MODE, 3941 + q_vector->tx[0]))) 4091 3942 return budget; 4092 3943 else 4093 3944 return work_done; ··· 4101 3952 */ 4102 3953 static void idpf_vport_intr_map_vector_to_qs(struct idpf_vport *vport) 4103 3954 { 3955 + bool split = idpf_is_queue_model_split(vport->rxq_model); 4104 3956 u16 num_txq_grp = vport->num_txq_grp; 4105 - int i, j, qv_idx, bufq_vidx = 0; 4106 3957 struct idpf_rxq_group *rx_qgrp; 4107 3958 struct idpf_txq_group *tx_qgrp; 4108 - struct idpf_queue *q, *bufq; 4109 - u16 q_index; 3959 + u32 i, qv_idx, q_index; 4110 3960 4111 3961 for (i = 0, qv_idx = 0; i < vport->num_rxq_grp; i++) { 4112 3962 u16 num_rxq; 4113 3963 3964 + if (qv_idx >= vport->num_q_vectors) 3965 + qv_idx = 0; 3966 + 4114 3967 rx_qgrp = &vport->rxq_grps[i]; 4115 - if (idpf_is_queue_model_split(vport->rxq_model)) 3968 + if (split) 4116 3969 num_rxq = rx_qgrp->splitq.num_rxq_sets; 4117 3970 else 4118 3971 num_rxq = rx_qgrp->singleq.num_rxq; 4119 3972 4120 - for (j = 0; j < num_rxq; j++) { 4121 - if (qv_idx >= vport->num_q_vectors) 4122 - qv_idx = 0; 3973 + for (u32 j = 0; j < num_rxq; j++) { 3974 + struct idpf_rx_queue *q; 4123 3975 4124 - if (idpf_is_queue_model_split(vport->rxq_model)) 3976 + if (split) 4125 3977 q = &rx_qgrp->splitq.rxq_sets[j]->rxq; 4126 3978 else 4127 3979 q = rx_qgrp->singleq.rxqs[j]; ··· 4130 3980 q_index = q->q_vector->num_rxq; 4131 3981 q->q_vector->rx[q_index] = q; 4132 3982 q->q_vector->num_rxq++; 4133 - qv_idx++; 3983 + 3984 + if (split) 3985 + q->napi = &q->q_vector->napi; 4134 3986 } 4135 3987 4136 - if (idpf_is_queue_model_split(vport->rxq_model)) { 4137 - for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { 3988 + if (split) { 3989 + for (u32 j = 0; j < vport->num_bufqs_per_qgrp; j++) { 3990 + struct idpf_buf_queue *bufq; 3991 + 4138 3992 bufq = &rx_qgrp->splitq.bufq_sets[j].bufq; 4139 - bufq->q_vector = &vport->q_vectors[bufq_vidx]; 3993 + bufq->q_vector = &vport->q_vectors[qv_idx]; 4140 3994 q_index = bufq->q_vector->num_bufq; 4141 3995 bufq->q_vector->bufq[q_index] = bufq; 4142 3996 bufq->q_vector->num_bufq++; 4143 3997 } 4144 - if (++bufq_vidx >= vport->num_q_vectors) 4145 - bufq_vidx = 0; 4146 3998 } 3999 + 4000 + qv_idx++; 4147 4001 } 4002 + 4003 + split = idpf_is_queue_model_split(vport->txq_model); 4148 4004 4149 4005 for (i = 0, qv_idx = 0; i < num_txq_grp; i++) { 4150 4006 u16 num_txq; 4151 4007 4008 + if (qv_idx >= vport->num_q_vectors) 4009 + qv_idx = 0; 4010 + 4152 4011 tx_qgrp = &vport->txq_grps[i]; 4153 4012 num_txq = tx_qgrp->num_txq; 4154 4013 4155 - if (idpf_is_queue_model_split(vport->txq_model)) { 4156 - if (qv_idx >= vport->num_q_vectors) 4157 - qv_idx = 0; 4014 + for (u32 j = 0; j < num_txq; j++) { 4015 + struct idpf_tx_queue *q; 4158 4016 4159 - q = tx_qgrp->complq; 4017 + q = tx_qgrp->txqs[j]; 4160 4018 q->q_vector = &vport->q_vectors[qv_idx]; 4161 - q_index = q->q_vector->num_txq; 4162 - q->q_vector->tx[q_index] = q; 4163 - q->q_vector->num_txq++; 4164 - qv_idx++; 4165 - } else { 4166 - for (j = 0; j < num_txq; j++) { 4167 - if (qv_idx >= vport->num_q_vectors) 4168 - qv_idx = 0; 4169 - 4170 - q = tx_qgrp->txqs[j]; 4171 - q->q_vector = &vport->q_vectors[qv_idx]; 4172 - q_index = q->q_vector->num_txq; 4173 - q->q_vector->tx[q_index] = q; 4174 - q->q_vector->num_txq++; 4175 - 4176 - qv_idx++; 4177 - } 4019 + q->q_vector->tx[q->q_vector->num_txq++] = q; 4178 4020 } 4021 + 4022 + if (split) { 4023 + struct idpf_compl_queue *q = tx_qgrp->complq; 4024 + 4025 + q->q_vector = &vport->q_vectors[qv_idx]; 4026 + q->q_vector->complq[q->q_vector->num_complq++] = q; 4027 + } 4028 + 4029 + qv_idx++; 4179 4030 } 4180 4031 } 4181 4032 ··· 4237 4086 4238 4087 /* only set affinity_mask if the CPU is online */ 4239 4088 if (cpu_online(v_idx)) 4240 - cpumask_set_cpu(v_idx, &q_vector->affinity_mask); 4089 + cpumask_set_cpu(v_idx, q_vector->affinity_mask); 4241 4090 } 4242 4091 } 4243 4092 ··· 4252 4101 { 4253 4102 u16 txqs_per_vector, rxqs_per_vector, bufqs_per_vector; 4254 4103 struct idpf_q_vector *q_vector; 4255 - int v_idx, err; 4104 + u32 complqs_per_vector, v_idx; 4256 4105 4257 4106 vport->q_vectors = kcalloc(vport->num_q_vectors, 4258 4107 sizeof(struct idpf_q_vector), GFP_KERNEL); 4259 4108 if (!vport->q_vectors) 4260 4109 return -ENOMEM; 4261 4110 4262 - txqs_per_vector = DIV_ROUND_UP(vport->num_txq, vport->num_q_vectors); 4263 - rxqs_per_vector = DIV_ROUND_UP(vport->num_rxq, vport->num_q_vectors); 4111 + txqs_per_vector = DIV_ROUND_UP(vport->num_txq_grp, 4112 + vport->num_q_vectors); 4113 + rxqs_per_vector = DIV_ROUND_UP(vport->num_rxq_grp, 4114 + vport->num_q_vectors); 4264 4115 bufqs_per_vector = vport->num_bufqs_per_qgrp * 4265 4116 DIV_ROUND_UP(vport->num_rxq_grp, 4266 4117 vport->num_q_vectors); 4118 + complqs_per_vector = DIV_ROUND_UP(vport->num_txq_grp, 4119 + vport->num_q_vectors); 4267 4120 4268 4121 for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++) { 4269 4122 q_vector = &vport->q_vectors[v_idx]; ··· 4281 4126 q_vector->rx_intr_mode = IDPF_ITR_DYNAMIC; 4282 4127 q_vector->rx_itr_idx = VIRTCHNL2_ITR_IDX_0; 4283 4128 4284 - q_vector->tx = kcalloc(txqs_per_vector, 4285 - sizeof(struct idpf_queue *), 4286 - GFP_KERNEL); 4287 - if (!q_vector->tx) { 4288 - err = -ENOMEM; 4129 + if (!zalloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL)) 4289 4130 goto error; 4290 - } 4291 4131 4292 - q_vector->rx = kcalloc(rxqs_per_vector, 4293 - sizeof(struct idpf_queue *), 4132 + q_vector->tx = kcalloc(txqs_per_vector, sizeof(*q_vector->tx), 4294 4133 GFP_KERNEL); 4295 - if (!q_vector->rx) { 4296 - err = -ENOMEM; 4134 + if (!q_vector->tx) 4297 4135 goto error; 4298 - } 4136 + 4137 + q_vector->rx = kcalloc(rxqs_per_vector, sizeof(*q_vector->rx), 4138 + GFP_KERNEL); 4139 + if (!q_vector->rx) 4140 + goto error; 4299 4141 4300 4142 if (!idpf_is_queue_model_split(vport->rxq_model)) 4301 4143 continue; 4302 4144 4303 4145 q_vector->bufq = kcalloc(bufqs_per_vector, 4304 - sizeof(struct idpf_queue *), 4146 + sizeof(*q_vector->bufq), 4305 4147 GFP_KERNEL); 4306 - if (!q_vector->bufq) { 4307 - err = -ENOMEM; 4148 + if (!q_vector->bufq) 4308 4149 goto error; 4309 - } 4150 + 4151 + q_vector->complq = kcalloc(complqs_per_vector, 4152 + sizeof(*q_vector->complq), 4153 + GFP_KERNEL); 4154 + if (!q_vector->complq) 4155 + goto error; 4310 4156 } 4311 4157 4312 4158 return 0; ··· 4315 4159 error: 4316 4160 idpf_vport_intr_rel(vport); 4317 4161 4318 - return err; 4162 + return -ENOMEM; 4319 4163 } 4320 4164 4321 4165 /**
+403 -353
drivers/net/ethernet/intel/idpf/idpf_txrx.h
··· 4 4 #ifndef _IDPF_TXRX_H_ 5 5 #define _IDPF_TXRX_H_ 6 6 7 - #include <net/page_pool/helpers.h> 7 + #include <linux/dim.h> 8 + 9 + #include <net/libeth/cache.h> 8 10 #include <net/tcp.h> 9 11 #include <net/netdev_queues.h> 10 12 13 + #include "idpf_lan_txrx.h" 11 14 #include "virtchnl2_lan_desc.h" 12 15 13 16 #define IDPF_LARGE_MAX_Q 256 ··· 86 83 do { \ 87 84 if (unlikely(++(ntc) == (rxq)->desc_count)) { \ 88 85 ntc = 0; \ 89 - change_bit(__IDPF_Q_GEN_CHK, (rxq)->flags); \ 86 + idpf_queue_change(GEN_CHK, rxq); \ 90 87 } \ 91 88 } while (0) 92 89 ··· 96 93 idx = 0; \ 97 94 } while (0) 98 95 99 - #define IDPF_RX_HDR_SIZE 256 100 - #define IDPF_RX_BUF_2048 2048 101 - #define IDPF_RX_BUF_4096 4096 102 96 #define IDPF_RX_BUF_STRIDE 32 103 97 #define IDPF_RX_BUF_POST_STRIDE 16 104 98 #define IDPF_LOW_WATERMARK 64 105 - /* Size of header buffer specifically for header split */ 106 - #define IDPF_HDR_BUF_SIZE 256 107 - #define IDPF_PACKET_HDR_PAD \ 108 - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN * 2) 99 + 109 100 #define IDPF_TX_TSO_MIN_MSS 88 110 101 111 102 /* Minimum number of descriptors between 2 descriptors with the RE bit set; ··· 107 110 */ 108 111 #define IDPF_TX_SPLITQ_RE_MIN_GAP 64 109 112 110 - #define IDPF_RX_BI_BUFID_S 0 111 - #define IDPF_RX_BI_BUFID_M GENMASK(14, 0) 112 - #define IDPF_RX_BI_GEN_S 15 113 - #define IDPF_RX_BI_GEN_M BIT(IDPF_RX_BI_GEN_S) 113 + #define IDPF_RX_BI_GEN_M BIT(16) 114 + #define IDPF_RX_BI_BUFID_M GENMASK(15, 0) 115 + 114 116 #define IDPF_RXD_EOF_SPLITQ VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_M 115 117 #define IDPF_RXD_EOF_SINGLEQ VIRTCHNL2_RX_BASE_DESC_STATUS_EOF_M 116 - 117 - #define IDPF_SINGLEQ_RX_BUF_DESC(rxq, i) \ 118 - (&(((struct virtchnl2_singleq_rx_buf_desc *)((rxq)->desc_ring))[i])) 119 - #define IDPF_SPLITQ_RX_BUF_DESC(rxq, i) \ 120 - (&(((struct virtchnl2_splitq_rx_buf_desc *)((rxq)->desc_ring))[i])) 121 - #define IDPF_SPLITQ_RX_BI_DESC(rxq, i) ((((rxq)->ring))[i]) 122 - 123 - #define IDPF_BASE_TX_DESC(txq, i) \ 124 - (&(((struct idpf_base_tx_desc *)((txq)->desc_ring))[i])) 125 - #define IDPF_BASE_TX_CTX_DESC(txq, i) \ 126 - (&(((struct idpf_base_tx_ctx_desc *)((txq)->desc_ring))[i])) 127 - #define IDPF_SPLITQ_TX_COMPLQ_DESC(txcq, i) \ 128 - (&(((struct idpf_splitq_tx_compl_desc *)((txcq)->desc_ring))[i])) 129 - 130 - #define IDPF_FLEX_TX_DESC(txq, i) \ 131 - (&(((union idpf_tx_flex_desc *)((txq)->desc_ring))[i])) 132 - #define IDPF_FLEX_TX_CTX_DESC(txq, i) \ 133 - (&(((struct idpf_flex_tx_ctx_desc *)((txq)->desc_ring))[i])) 134 118 135 119 #define IDPF_DESC_UNUSED(txq) \ 136 120 ((((txq)->next_to_clean > (txq)->next_to_use) ? 0 : (txq)->desc_count) + \ 137 121 (txq)->next_to_clean - (txq)->next_to_use - 1) 138 122 139 - #define IDPF_TX_BUF_RSV_UNUSED(txq) ((txq)->buf_stack.top) 123 + #define IDPF_TX_BUF_RSV_UNUSED(txq) ((txq)->stash->buf_stack.top) 140 124 #define IDPF_TX_BUF_RSV_LOW(txq) (IDPF_TX_BUF_RSV_UNUSED(txq) < \ 141 125 (txq)->desc_count >> 2) 142 126 ··· 293 315 #define IDPF_TX_MAX_DESC_DATA_ALIGNED \ 294 316 ALIGN_DOWN(IDPF_TX_MAX_DESC_DATA, IDPF_TX_MAX_READ_REQ_SIZE) 295 317 296 - #define IDPF_RX_DMA_ATTR \ 297 - (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) 298 - #define IDPF_RX_DESC(rxq, i) \ 299 - (&(((union virtchnl2_rx_desc *)((rxq)->desc_ring))[i])) 300 - 301 - struct idpf_rx_buf { 302 - struct page *page; 303 - unsigned int page_offset; 304 - u16 truesize; 305 - }; 318 + #define idpf_rx_buf libeth_fqe 306 319 307 320 #define IDPF_RX_MAX_PTYPE_PROTO_IDS 32 308 321 #define IDPF_RX_MAX_PTYPE_SZ (sizeof(struct virtchnl2_ptype) + \ ··· 317 348 #define IDPF_RX_MAX_BASE_PTYPE 256 318 349 #define IDPF_INVALID_PTYPE_ID 0xFFFF 319 350 320 - /* Packet type non-ip values */ 321 - enum idpf_rx_ptype_l2 { 322 - IDPF_RX_PTYPE_L2_RESERVED = 0, 323 - IDPF_RX_PTYPE_L2_MAC_PAY2 = 1, 324 - IDPF_RX_PTYPE_L2_TIMESYNC_PAY2 = 2, 325 - IDPF_RX_PTYPE_L2_FIP_PAY2 = 3, 326 - IDPF_RX_PTYPE_L2_OUI_PAY2 = 4, 327 - IDPF_RX_PTYPE_L2_MACCNTRL_PAY2 = 5, 328 - IDPF_RX_PTYPE_L2_LLDP_PAY2 = 6, 329 - IDPF_RX_PTYPE_L2_ECP_PAY2 = 7, 330 - IDPF_RX_PTYPE_L2_EVB_PAY2 = 8, 331 - IDPF_RX_PTYPE_L2_QCN_PAY2 = 9, 332 - IDPF_RX_PTYPE_L2_EAPOL_PAY2 = 10, 333 - IDPF_RX_PTYPE_L2_ARP = 11, 334 - }; 335 - 336 - enum idpf_rx_ptype_outer_ip { 337 - IDPF_RX_PTYPE_OUTER_L2 = 0, 338 - IDPF_RX_PTYPE_OUTER_IP = 1, 339 - }; 340 - 341 - #define IDPF_RX_PTYPE_TO_IPV(ptype, ipv) \ 342 - (((ptype)->outer_ip == IDPF_RX_PTYPE_OUTER_IP) && \ 343 - ((ptype)->outer_ip_ver == (ipv))) 344 - 345 - enum idpf_rx_ptype_outer_ip_ver { 346 - IDPF_RX_PTYPE_OUTER_NONE = 0, 347 - IDPF_RX_PTYPE_OUTER_IPV4 = 1, 348 - IDPF_RX_PTYPE_OUTER_IPV6 = 2, 349 - }; 350 - 351 - enum idpf_rx_ptype_outer_fragmented { 352 - IDPF_RX_PTYPE_NOT_FRAG = 0, 353 - IDPF_RX_PTYPE_FRAG = 1, 354 - }; 355 - 356 - enum idpf_rx_ptype_tunnel_type { 357 - IDPF_RX_PTYPE_TUNNEL_NONE = 0, 358 - IDPF_RX_PTYPE_TUNNEL_IP_IP = 1, 359 - IDPF_RX_PTYPE_TUNNEL_IP_GRENAT = 2, 360 - IDPF_RX_PTYPE_TUNNEL_IP_GRENAT_MAC = 3, 361 - IDPF_RX_PTYPE_TUNNEL_IP_GRENAT_MAC_VLAN = 4, 362 - }; 363 - 364 - enum idpf_rx_ptype_tunnel_end_prot { 365 - IDPF_RX_PTYPE_TUNNEL_END_NONE = 0, 366 - IDPF_RX_PTYPE_TUNNEL_END_IPV4 = 1, 367 - IDPF_RX_PTYPE_TUNNEL_END_IPV6 = 2, 368 - }; 369 - 370 - enum idpf_rx_ptype_inner_prot { 371 - IDPF_RX_PTYPE_INNER_PROT_NONE = 0, 372 - IDPF_RX_PTYPE_INNER_PROT_UDP = 1, 373 - IDPF_RX_PTYPE_INNER_PROT_TCP = 2, 374 - IDPF_RX_PTYPE_INNER_PROT_SCTP = 3, 375 - IDPF_RX_PTYPE_INNER_PROT_ICMP = 4, 376 - IDPF_RX_PTYPE_INNER_PROT_TIMESYNC = 5, 377 - }; 378 - 379 - enum idpf_rx_ptype_payload_layer { 380 - IDPF_RX_PTYPE_PAYLOAD_LAYER_NONE = 0, 381 - IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY2 = 1, 382 - IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY3 = 2, 383 - IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY4 = 3, 384 - }; 385 - 386 351 enum idpf_tunnel_state { 387 352 IDPF_PTYPE_TUNNEL_IP = BIT(0), 388 353 IDPF_PTYPE_TUNNEL_IP_GRENAT = BIT(1), ··· 324 421 }; 325 422 326 423 struct idpf_ptype_state { 327 - bool outer_ip; 328 - bool outer_frag; 329 - u8 tunnel_state; 330 - }; 331 - 332 - struct idpf_rx_ptype_decoded { 333 - u32 ptype:10; 334 - u32 known:1; 335 - u32 outer_ip:1; 336 - u32 outer_ip_ver:2; 337 - u32 outer_frag:1; 338 - u32 tunnel_type:3; 339 - u32 tunnel_end_prot:2; 340 - u32 tunnel_end_frag:1; 341 - u32 inner_prot:4; 342 - u32 payload_layer:3; 424 + bool outer_ip:1; 425 + bool outer_frag:1; 426 + u8 tunnel_state:6; 343 427 }; 344 428 345 429 /** ··· 342 452 * to 1 and knows that reading a gen bit of 1 in any 343 453 * descriptor on the initial pass of the ring indicates a 344 454 * writeback. It also flips on every ring wrap. 345 - * @__IDPF_RFLQ_GEN_CHK: Refill queues are SW only, so Q_GEN acts as the HW bit 346 - * and RFLGQ_GEN is the SW bit. 455 + * @__IDPF_Q_RFL_GEN_CHK: Refill queues are SW only, so Q_GEN acts as the HW 456 + * bit and Q_RFL_GEN is the SW bit. 347 457 * @__IDPF_Q_FLOW_SCH_EN: Enable flow scheduling 348 458 * @__IDPF_Q_SW_MARKER: Used to indicate TX queue marker completions 349 459 * @__IDPF_Q_POLL_MODE: Enable poll mode 460 + * @__IDPF_Q_CRC_EN: enable CRC offload in singleq mode 461 + * @__IDPF_Q_HSPLIT_EN: enable header split on Rx (splitq) 350 462 * @__IDPF_Q_FLAGS_NBITS: Must be last 351 463 */ 352 464 enum idpf_queue_flags_t { 353 465 __IDPF_Q_GEN_CHK, 354 - __IDPF_RFLQ_GEN_CHK, 466 + __IDPF_Q_RFL_GEN_CHK, 355 467 __IDPF_Q_FLOW_SCH_EN, 356 468 __IDPF_Q_SW_MARKER, 357 469 __IDPF_Q_POLL_MODE, 470 + __IDPF_Q_CRC_EN, 471 + __IDPF_Q_HSPLIT_EN, 358 472 359 473 __IDPF_Q_FLAGS_NBITS, 360 474 }; 475 + 476 + #define idpf_queue_set(f, q) __set_bit(__IDPF_Q_##f, (q)->flags) 477 + #define idpf_queue_clear(f, q) __clear_bit(__IDPF_Q_##f, (q)->flags) 478 + #define idpf_queue_change(f, q) __change_bit(__IDPF_Q_##f, (q)->flags) 479 + #define idpf_queue_has(f, q) test_bit(__IDPF_Q_##f, (q)->flags) 480 + 481 + #define idpf_queue_has_clear(f, q) \ 482 + __test_and_clear_bit(__IDPF_Q_##f, (q)->flags) 483 + #define idpf_queue_assign(f, q, v) \ 484 + __assign_bit(__IDPF_Q_##f, (q)->flags, v) 361 485 362 486 /** 363 487 * struct idpf_vec_regs ··· 413 509 /** 414 510 * struct idpf_q_vector 415 511 * @vport: Vport back pointer 416 - * @affinity_mask: CPU affinity mask 417 - * @napi: napi handler 418 - * @v_idx: Vector index 419 - * @intr_reg: See struct idpf_intr_reg 512 + * @num_rxq: Number of RX queues 420 513 * @num_txq: Number of TX queues 514 + * @num_bufq: Number of buffer queues 515 + * @num_complq: number of completion queues 516 + * @rx: Array of RX queues to service 421 517 * @tx: Array of TX queues to service 518 + * @bufq: Array of buffer queues to service 519 + * @complq: array of completion queues 520 + * @intr_reg: See struct idpf_intr_reg 521 + * @napi: napi handler 522 + * @total_events: Number of interrupts processed 422 523 * @tx_dim: Data for TX net_dim algorithm 423 524 * @tx_itr_value: TX interrupt throttling rate 424 525 * @tx_intr_mode: Dynamic ITR or not 425 526 * @tx_itr_idx: TX ITR index 426 - * @num_rxq: Number of RX queues 427 - * @rx: Array of RX queues to service 428 527 * @rx_dim: Data for RX net_dim algorithm 429 528 * @rx_itr_value: RX interrupt throttling rate 430 529 * @rx_intr_mode: Dynamic ITR or not 431 530 * @rx_itr_idx: RX ITR index 432 - * @num_bufq: Number of buffer queues 433 - * @bufq: Array of buffer queues to service 434 - * @total_events: Number of interrupts processed 435 - * @name: Queue vector name 531 + * @v_idx: Vector index 532 + * @affinity_mask: CPU affinity mask 436 533 */ 437 534 struct idpf_q_vector { 535 + __cacheline_group_begin_aligned(read_mostly); 438 536 struct idpf_vport *vport; 439 - cpumask_t affinity_mask; 440 - struct napi_struct napi; 441 - u16 v_idx; 442 - struct idpf_intr_reg intr_reg; 443 537 538 + u16 num_rxq; 444 539 u16 num_txq; 445 - struct idpf_queue **tx; 540 + u16 num_bufq; 541 + u16 num_complq; 542 + struct idpf_rx_queue **rx; 543 + struct idpf_tx_queue **tx; 544 + struct idpf_buf_queue **bufq; 545 + struct idpf_compl_queue **complq; 546 + 547 + struct idpf_intr_reg intr_reg; 548 + __cacheline_group_end_aligned(read_mostly); 549 + 550 + __cacheline_group_begin_aligned(read_write); 551 + struct napi_struct napi; 552 + u16 total_events; 553 + 446 554 struct dim tx_dim; 447 555 u16 tx_itr_value; 448 556 bool tx_intr_mode; 449 557 u32 tx_itr_idx; 450 558 451 - u16 num_rxq; 452 - struct idpf_queue **rx; 453 559 struct dim rx_dim; 454 560 u16 rx_itr_value; 455 561 bool rx_intr_mode; 456 562 u32 rx_itr_idx; 563 + __cacheline_group_end_aligned(read_write); 457 564 458 - u16 num_bufq; 459 - struct idpf_queue **bufq; 565 + __cacheline_group_begin_aligned(cold); 566 + u16 v_idx; 460 567 461 - u16 total_events; 462 - char *name; 568 + cpumask_var_t affinity_mask; 569 + __cacheline_group_end_aligned(cold); 463 570 }; 571 + libeth_cacheline_set_assert(struct idpf_q_vector, 104, 572 + 424 + 2 * sizeof(struct dim), 573 + 8 + sizeof(cpumask_var_t)); 464 574 465 575 struct idpf_rx_queue_stats { 466 576 u64_stats_t packets; ··· 501 583 u32 bytes; 502 584 }; 503 585 504 - union idpf_queue_stats { 505 - struct idpf_rx_queue_stats rx; 506 - struct idpf_tx_queue_stats tx; 507 - }; 508 - 509 586 #define IDPF_ITR_DYNAMIC 1 510 587 #define IDPF_ITR_MAX 0x1FE0 511 588 #define IDPF_ITR_20K 0x0032 ··· 516 603 #define IDPF_DIM_DEFAULT_PROFILE_IX 1 517 604 518 605 /** 519 - * struct idpf_queue 520 - * @dev: Device back pointer for DMA mapping 521 - * @vport: Back pointer to associated vport 522 - * @txq_grp: See struct idpf_txq_group 523 - * @rxq_grp: See struct idpf_rxq_group 524 - * @idx: For buffer queue, it is used as group id, either 0 or 1. On clean, 525 - * buffer queue uses this index to determine which group of refill queues 526 - * to clean. 527 - * For TX queue, it is used as index to map between TX queue group and 528 - * hot path TX pointers stored in vport. Used in both singleq/splitq. 529 - * For RX queue, it is used to index to total RX queue across groups and 530 - * used for skb reporting. 531 - * @tail: Tail offset. Used for both queue models single and split. In splitq 532 - * model relevant only for TX queue and RX queue. 533 - * @tx_buf: See struct idpf_tx_buf 534 - * @rx_buf: Struct with RX buffer related members 535 - * @rx_buf.buf: See struct idpf_rx_buf 536 - * @rx_buf.hdr_buf_pa: DMA handle 537 - * @rx_buf.hdr_buf_va: Virtual address 538 - * @pp: Page pool pointer 539 - * @skb: Pointer to the skb 540 - * @q_type: Queue type (TX, RX, TX completion, RX buffer) 541 - * @q_id: Queue id 542 - * @desc_count: Number of descriptors 543 - * @next_to_use: Next descriptor to use. Relevant in both split & single txq 544 - * and bufq. 545 - * @next_to_clean: Next descriptor to clean. In split queue model, only 546 - * relevant to TX completion queue and RX queue. 547 - * @next_to_alloc: RX buffer to allocate at. Used only for RX. In splitq model 548 - * only relevant to RX queue. 606 + * struct idpf_txq_stash - Tx buffer stash for Flow-based scheduling mode 607 + * @buf_stack: Stack of empty buffers to store buffer info for out of order 608 + * buffer completions. See struct idpf_buf_lifo 609 + * @sched_buf_hash: Hash table to store buffers 610 + */ 611 + struct idpf_txq_stash { 612 + struct idpf_buf_lifo buf_stack; 613 + DECLARE_HASHTABLE(sched_buf_hash, 12); 614 + } ____cacheline_aligned; 615 + 616 + /** 617 + * struct idpf_rx_queue - software structure representing a receive queue 618 + * @rx: universal receive descriptor array 619 + * @single_buf: buffer descriptor array in singleq 620 + * @desc_ring: virtual descriptor ring address 621 + * @bufq_sets: Pointer to the array of buffer queues in splitq mode 622 + * @napi: NAPI instance corresponding to this queue (splitq) 623 + * @rx_buf: See struct &libeth_fqe 624 + * @pp: Page pool pointer in singleq mode 625 + * @netdev: &net_device corresponding to this queue 626 + * @tail: Tail offset. Used for both queue models single and split. 549 627 * @flags: See enum idpf_queue_flags_t 550 - * @q_stats: See union idpf_queue_stats 628 + * @idx: For RX queue, it is used to index to total RX queue across groups and 629 + * used for skb reporting. 630 + * @desc_count: Number of descriptors 631 + * @rxdids: Supported RX descriptor ids 632 + * @rx_ptype_lkup: LUT of Rx ptypes 633 + * @next_to_use: Next descriptor to use 634 + * @next_to_clean: Next descriptor to clean 635 + * @next_to_alloc: RX buffer to allocate at 636 + * @skb: Pointer to the skb 637 + * @truesize: data buffer truesize in singleq 551 638 * @stats_sync: See struct u64_stats_sync 552 - * @cleaned_bytes: Splitq only, TXQ only: When a TX completion is received on 553 - * the TX completion queue, it can be for any TXQ associated 554 - * with that completion queue. This means we can clean up to 555 - * N TXQs during a single call to clean the completion queue. 556 - * cleaned_bytes|pkts tracks the clean stats per TXQ during 557 - * that single call to clean the completion queue. By doing so, 558 - * we can update BQL with aggregate cleaned stats for each TXQ 559 - * only once at the end of the cleaning routine. 560 - * @cleaned_pkts: Number of packets cleaned for the above said case 561 - * @rx_hsplit_en: RX headsplit enable 639 + * @q_stats: See union idpf_rx_queue_stats 640 + * @q_id: Queue id 641 + * @size: Length of descriptor ring in bytes 642 + * @dma: Physical address of ring 643 + * @q_vector: Backreference to associated vector 644 + * @rx_buffer_low_watermark: RX buffer low watermark 562 645 * @rx_hbuf_size: Header buffer size 563 646 * @rx_buf_size: Buffer size 564 647 * @rx_max_pkt_size: RX max packet size 565 - * @rx_buf_stride: RX buffer stride 566 - * @rx_buffer_low_watermark: RX buffer low watermark 567 - * @rxdids: Supported RX descriptor ids 568 - * @q_vector: Backreference to associated vector 569 - * @size: Length of descriptor ring in bytes 570 - * @dma: Physical address of ring 571 - * @desc_ring: Descriptor ring memory 572 - * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather 648 + */ 649 + struct idpf_rx_queue { 650 + __cacheline_group_begin_aligned(read_mostly); 651 + union { 652 + union virtchnl2_rx_desc *rx; 653 + struct virtchnl2_singleq_rx_buf_desc *single_buf; 654 + 655 + void *desc_ring; 656 + }; 657 + union { 658 + struct { 659 + struct idpf_bufq_set *bufq_sets; 660 + struct napi_struct *napi; 661 + }; 662 + struct { 663 + struct libeth_fqe *rx_buf; 664 + struct page_pool *pp; 665 + }; 666 + }; 667 + struct net_device *netdev; 668 + void __iomem *tail; 669 + 670 + DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 671 + u16 idx; 672 + u16 desc_count; 673 + 674 + u32 rxdids; 675 + const struct libeth_rx_pt *rx_ptype_lkup; 676 + __cacheline_group_end_aligned(read_mostly); 677 + 678 + __cacheline_group_begin_aligned(read_write); 679 + u16 next_to_use; 680 + u16 next_to_clean; 681 + u16 next_to_alloc; 682 + 683 + struct sk_buff *skb; 684 + u32 truesize; 685 + 686 + struct u64_stats_sync stats_sync; 687 + struct idpf_rx_queue_stats q_stats; 688 + __cacheline_group_end_aligned(read_write); 689 + 690 + __cacheline_group_begin_aligned(cold); 691 + u32 q_id; 692 + u32 size; 693 + dma_addr_t dma; 694 + 695 + struct idpf_q_vector *q_vector; 696 + 697 + u16 rx_buffer_low_watermark; 698 + u16 rx_hbuf_size; 699 + u16 rx_buf_size; 700 + u16 rx_max_pkt_size; 701 + __cacheline_group_end_aligned(cold); 702 + }; 703 + libeth_cacheline_set_assert(struct idpf_rx_queue, 64, 704 + 80 + sizeof(struct u64_stats_sync), 705 + 32); 706 + 707 + /** 708 + * struct idpf_tx_queue - software structure representing a transmit queue 709 + * @base_tx: base Tx descriptor array 710 + * @base_ctx: base Tx context descriptor array 711 + * @flex_tx: flex Tx descriptor array 712 + * @flex_ctx: flex Tx context descriptor array 713 + * @desc_ring: virtual descriptor ring address 714 + * @tx_buf: See struct idpf_tx_buf 715 + * @txq_grp: See struct idpf_txq_group 716 + * @dev: Device back pointer for DMA mapping 717 + * @tail: Tail offset. Used for both queue models single and split 718 + * @flags: See enum idpf_queue_flags_t 719 + * @idx: For TX queue, it is used as index to map between TX queue group and 720 + * hot path TX pointers stored in vport. Used in both singleq/splitq. 721 + * @desc_count: Number of descriptors 573 722 * @tx_min_pkt_len: Min supported packet length 574 - * @num_completions: Only relevant for TX completion queue. It tracks the 575 - * number of completions received to compare against the 576 - * number of completions pending, as accumulated by the 577 - * TX queues. 578 - * @buf_stack: Stack of empty buffers to store buffer info for out of order 579 - * buffer completions. See struct idpf_buf_lifo. 580 - * @compl_tag_bufid_m: Completion tag buffer id mask 581 723 * @compl_tag_gen_s: Completion tag generation bit 582 724 * The format of the completion tag will change based on the TXQ 583 725 * descriptor ring size so that we can maintain roughly the same level ··· 653 685 * -------------------------------- 654 686 * 655 687 * This gives us 8*8160 = 65280 possible unique values. 688 + * @netdev: &net_device corresponding to this queue 689 + * @next_to_use: Next descriptor to use 690 + * @next_to_clean: Next descriptor to clean 691 + * @cleaned_bytes: Splitq only, TXQ only: When a TX completion is received on 692 + * the TX completion queue, it can be for any TXQ associated 693 + * with that completion queue. This means we can clean up to 694 + * N TXQs during a single call to clean the completion queue. 695 + * cleaned_bytes|pkts tracks the clean stats per TXQ during 696 + * that single call to clean the completion queue. By doing so, 697 + * we can update BQL with aggregate cleaned stats for each TXQ 698 + * only once at the end of the cleaning routine. 699 + * @clean_budget: singleq only, queue cleaning budget 700 + * @cleaned_pkts: Number of packets cleaned for the above said case 701 + * @tx_max_bufs: Max buffers that can be transmitted with scatter-gather 702 + * @stash: Tx buffer stash for Flow-based scheduling mode 703 + * @compl_tag_bufid_m: Completion tag buffer id mask 656 704 * @compl_tag_cur_gen: Used to keep track of current completion tag generation 657 705 * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset 658 - * @sched_buf_hash: Hash table to stores buffers 706 + * @stats_sync: See struct u64_stats_sync 707 + * @q_stats: See union idpf_tx_queue_stats 708 + * @q_id: Queue id 709 + * @size: Length of descriptor ring in bytes 710 + * @dma: Physical address of ring 711 + * @q_vector: Backreference to associated vector 659 712 */ 660 - struct idpf_queue { 713 + struct idpf_tx_queue { 714 + __cacheline_group_begin_aligned(read_mostly); 715 + union { 716 + struct idpf_base_tx_desc *base_tx; 717 + struct idpf_base_tx_ctx_desc *base_ctx; 718 + union idpf_tx_flex_desc *flex_tx; 719 + struct idpf_flex_tx_ctx_desc *flex_ctx; 720 + 721 + void *desc_ring; 722 + }; 723 + struct idpf_tx_buf *tx_buf; 724 + struct idpf_txq_group *txq_grp; 661 725 struct device *dev; 662 - struct idpf_vport *vport; 663 - union { 664 - struct idpf_txq_group *txq_grp; 665 - struct idpf_rxq_group *rxq_grp; 666 - }; 667 - u16 idx; 668 726 void __iomem *tail; 669 - union { 670 - struct idpf_tx_buf *tx_buf; 671 - struct { 672 - struct idpf_rx_buf *buf; 673 - dma_addr_t hdr_buf_pa; 674 - void *hdr_buf_va; 675 - } rx_buf; 676 - }; 677 - struct page_pool *pp; 678 - struct sk_buff *skb; 679 - u16 q_type; 680 - u32 q_id; 727 + 728 + DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 729 + u16 idx; 681 730 u16 desc_count; 682 731 683 - u16 next_to_use; 684 - u16 next_to_clean; 685 - u16 next_to_alloc; 686 - DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 687 - 688 - union idpf_queue_stats q_stats; 689 - struct u64_stats_sync stats_sync; 690 - 691 - u32 cleaned_bytes; 692 - u16 cleaned_pkts; 693 - 694 - bool rx_hsplit_en; 695 - u16 rx_hbuf_size; 696 - u16 rx_buf_size; 697 - u16 rx_max_pkt_size; 698 - u16 rx_buf_stride; 699 - u8 rx_buffer_low_watermark; 700 - u64 rxdids; 701 - struct idpf_q_vector *q_vector; 702 - unsigned int size; 703 - dma_addr_t dma; 704 - void *desc_ring; 705 - 706 - u16 tx_max_bufs; 707 - u8 tx_min_pkt_len; 708 - 709 - u32 num_completions; 710 - 711 - struct idpf_buf_lifo buf_stack; 712 - 713 - u16 compl_tag_bufid_m; 732 + u16 tx_min_pkt_len; 714 733 u16 compl_tag_gen_s; 715 734 735 + struct net_device *netdev; 736 + __cacheline_group_end_aligned(read_mostly); 737 + 738 + __cacheline_group_begin_aligned(read_write); 739 + u16 next_to_use; 740 + u16 next_to_clean; 741 + 742 + union { 743 + u32 cleaned_bytes; 744 + u32 clean_budget; 745 + }; 746 + u16 cleaned_pkts; 747 + 748 + u16 tx_max_bufs; 749 + struct idpf_txq_stash *stash; 750 + 751 + u16 compl_tag_bufid_m; 716 752 u16 compl_tag_cur_gen; 717 753 u16 compl_tag_gen_max; 718 754 719 - DECLARE_HASHTABLE(sched_buf_hash, 12); 720 - } ____cacheline_internodealigned_in_smp; 755 + struct u64_stats_sync stats_sync; 756 + struct idpf_tx_queue_stats q_stats; 757 + __cacheline_group_end_aligned(read_write); 758 + 759 + __cacheline_group_begin_aligned(cold); 760 + u32 q_id; 761 + u32 size; 762 + dma_addr_t dma; 763 + 764 + struct idpf_q_vector *q_vector; 765 + __cacheline_group_end_aligned(cold); 766 + }; 767 + libeth_cacheline_set_assert(struct idpf_tx_queue, 64, 768 + 88 + sizeof(struct u64_stats_sync), 769 + 24); 770 + 771 + /** 772 + * struct idpf_buf_queue - software structure representing a buffer queue 773 + * @split_buf: buffer descriptor array 774 + * @hdr_buf: &libeth_fqe for header buffers 775 + * @hdr_pp: &page_pool for header buffers 776 + * @buf: &libeth_fqe for data buffers 777 + * @pp: &page_pool for data buffers 778 + * @tail: Tail offset 779 + * @flags: See enum idpf_queue_flags_t 780 + * @desc_count: Number of descriptors 781 + * @next_to_use: Next descriptor to use 782 + * @next_to_clean: Next descriptor to clean 783 + * @next_to_alloc: RX buffer to allocate at 784 + * @hdr_truesize: truesize for buffer headers 785 + * @truesize: truesize for data buffers 786 + * @q_id: Queue id 787 + * @size: Length of descriptor ring in bytes 788 + * @dma: Physical address of ring 789 + * @q_vector: Backreference to associated vector 790 + * @rx_buffer_low_watermark: RX buffer low watermark 791 + * @rx_hbuf_size: Header buffer size 792 + * @rx_buf_size: Buffer size 793 + */ 794 + struct idpf_buf_queue { 795 + __cacheline_group_begin_aligned(read_mostly); 796 + struct virtchnl2_splitq_rx_buf_desc *split_buf; 797 + struct libeth_fqe *hdr_buf; 798 + struct page_pool *hdr_pp; 799 + struct libeth_fqe *buf; 800 + struct page_pool *pp; 801 + void __iomem *tail; 802 + 803 + DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 804 + u32 desc_count; 805 + __cacheline_group_end_aligned(read_mostly); 806 + 807 + __cacheline_group_begin_aligned(read_write); 808 + u32 next_to_use; 809 + u32 next_to_clean; 810 + u32 next_to_alloc; 811 + 812 + u32 hdr_truesize; 813 + u32 truesize; 814 + __cacheline_group_end_aligned(read_write); 815 + 816 + __cacheline_group_begin_aligned(cold); 817 + u32 q_id; 818 + u32 size; 819 + dma_addr_t dma; 820 + 821 + struct idpf_q_vector *q_vector; 822 + 823 + u16 rx_buffer_low_watermark; 824 + u16 rx_hbuf_size; 825 + u16 rx_buf_size; 826 + __cacheline_group_end_aligned(cold); 827 + }; 828 + libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 24, 32); 829 + 830 + /** 831 + * struct idpf_compl_queue - software structure representing a completion queue 832 + * @comp: completion descriptor array 833 + * @txq_grp: See struct idpf_txq_group 834 + * @flags: See enum idpf_queue_flags_t 835 + * @desc_count: Number of descriptors 836 + * @clean_budget: queue cleaning budget 837 + * @netdev: &net_device corresponding to this queue 838 + * @next_to_use: Next descriptor to use. Relevant in both split & single txq 839 + * and bufq. 840 + * @next_to_clean: Next descriptor to clean 841 + * @num_completions: Only relevant for TX completion queue. It tracks the 842 + * number of completions received to compare against the 843 + * number of completions pending, as accumulated by the 844 + * TX queues. 845 + * @q_id: Queue id 846 + * @size: Length of descriptor ring in bytes 847 + * @dma: Physical address of ring 848 + * @q_vector: Backreference to associated vector 849 + */ 850 + struct idpf_compl_queue { 851 + __cacheline_group_begin_aligned(read_mostly); 852 + struct idpf_splitq_tx_compl_desc *comp; 853 + struct idpf_txq_group *txq_grp; 854 + 855 + DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 856 + u32 desc_count; 857 + 858 + u32 clean_budget; 859 + struct net_device *netdev; 860 + __cacheline_group_end_aligned(read_mostly); 861 + 862 + __cacheline_group_begin_aligned(read_write); 863 + u32 next_to_use; 864 + u32 next_to_clean; 865 + 866 + u32 num_completions; 867 + __cacheline_group_end_aligned(read_write); 868 + 869 + __cacheline_group_begin_aligned(cold); 870 + u32 q_id; 871 + u32 size; 872 + dma_addr_t dma; 873 + 874 + struct idpf_q_vector *q_vector; 875 + __cacheline_group_end_aligned(cold); 876 + }; 877 + libeth_cacheline_set_assert(struct idpf_compl_queue, 40, 16, 24); 721 878 722 879 /** 723 880 * struct idpf_sw_queue 724 - * @next_to_clean: Next descriptor to clean 725 - * @next_to_alloc: Buffer to allocate at 726 - * @flags: See enum idpf_queue_flags_t 727 881 * @ring: Pointer to the ring 882 + * @flags: See enum idpf_queue_flags_t 728 883 * @desc_count: Descriptor count 729 - * @dev: Device back pointer for DMA mapping 884 + * @next_to_use: Buffer to allocate at 885 + * @next_to_clean: Next descriptor to clean 730 886 * 731 887 * Software queues are used in splitq mode to manage buffers between rxq 732 888 * producer and the bufq consumer. These are required in order to maintain a 733 889 * lockless buffer management system and are strictly software only constructs. 734 890 */ 735 891 struct idpf_sw_queue { 736 - u16 next_to_clean; 737 - u16 next_to_alloc; 892 + __cacheline_group_begin_aligned(read_mostly); 893 + u32 *ring; 894 + 738 895 DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS); 739 - u16 *ring; 740 - u16 desc_count; 741 - struct device *dev; 742 - } ____cacheline_internodealigned_in_smp; 896 + u32 desc_count; 897 + __cacheline_group_end_aligned(read_mostly); 898 + 899 + __cacheline_group_begin_aligned(read_write); 900 + u32 next_to_use; 901 + u32 next_to_clean; 902 + __cacheline_group_end_aligned(read_write); 903 + }; 904 + libeth_cacheline_group_assert(struct idpf_sw_queue, read_mostly, 24); 905 + libeth_cacheline_group_assert(struct idpf_sw_queue, read_write, 8); 906 + libeth_cacheline_struct_assert(struct idpf_sw_queue, 24, 8); 743 907 744 908 /** 745 909 * struct idpf_rxq_set 746 910 * @rxq: RX queue 747 - * @refillq0: Pointer to refill queue 0 748 - * @refillq1: Pointer to refill queue 1 911 + * @refillq: pointers to refill queues 749 912 * 750 913 * Splitq only. idpf_rxq_set associates an rxq with at an array of refillqs. 751 914 * Each rxq needs a refillq to return used buffers back to the respective bufq. 752 915 * Bufqs then clean these refillqs for buffers to give to hardware. 753 916 */ 754 917 struct idpf_rxq_set { 755 - struct idpf_queue rxq; 756 - struct idpf_sw_queue *refillq0; 757 - struct idpf_sw_queue *refillq1; 918 + struct idpf_rx_queue rxq; 919 + struct idpf_sw_queue *refillq[IDPF_MAX_BUFQS_PER_RXQ_GRP]; 758 920 }; 759 921 760 922 /** ··· 903 805 * managed by at most two bufqs (depending on performance configuration). 904 806 */ 905 807 struct idpf_bufq_set { 906 - struct idpf_queue bufq; 808 + struct idpf_buf_queue bufq; 907 809 int num_refillqs; 908 810 struct idpf_sw_queue *refillqs; 909 811 }; ··· 929 831 union { 930 832 struct { 931 833 u16 num_rxq; 932 - struct idpf_queue *rxqs[IDPF_LARGE_MAX_Q]; 834 + struct idpf_rx_queue *rxqs[IDPF_LARGE_MAX_Q]; 933 835 } singleq; 934 836 struct { 935 837 u16 num_rxq_sets; ··· 944 846 * @vport: Vport back pointer 945 847 * @num_txq: Number of TX queues associated 946 848 * @txqs: Array of TX queue pointers 849 + * @stashes: array of OOO stashes for the queues 947 850 * @complq: Associated completion queue pointer, split queue only 948 851 * @num_completions_pending: Total number of completions pending for the 949 852 * completion queue, acculumated for all TX queues ··· 958 859 struct idpf_vport *vport; 959 860 960 861 u16 num_txq; 961 - struct idpf_queue *txqs[IDPF_LARGE_MAX_Q]; 862 + struct idpf_tx_queue *txqs[IDPF_LARGE_MAX_Q]; 863 + struct idpf_txq_stash *stashes; 962 864 963 - struct idpf_queue *complq; 865 + struct idpf_compl_queue *complq; 964 866 965 867 u32 num_completions_pending; 966 868 }; 869 + 870 + static inline int idpf_q_vector_to_mem(const struct idpf_q_vector *q_vector) 871 + { 872 + u32 cpu; 873 + 874 + if (!q_vector) 875 + return NUMA_NO_NODE; 876 + 877 + cpu = cpumask_first(q_vector->affinity_mask); 878 + 879 + return cpu < nr_cpu_ids ? cpu_to_mem(cpu) : NUMA_NO_NODE; 880 + } 967 881 968 882 /** 969 883 * idpf_size_to_txd_count - Get number of descriptors needed for large Tx frag ··· 1033 921 idpf_tx_splitq_build_flow_desc(desc, params, td_cmd, size); 1034 922 } 1035 923 1036 - /** 1037 - * idpf_alloc_page - Allocate a new RX buffer from the page pool 1038 - * @pool: page_pool to allocate from 1039 - * @buf: metadata struct to populate with page info 1040 - * @buf_size: 2K or 4K 1041 - * 1042 - * Returns &dma_addr_t to be passed to HW for Rx, %DMA_MAPPING_ERROR otherwise. 1043 - */ 1044 - static inline dma_addr_t idpf_alloc_page(struct page_pool *pool, 1045 - struct idpf_rx_buf *buf, 1046 - unsigned int buf_size) 1047 - { 1048 - if (buf_size == IDPF_RX_BUF_2048) 1049 - buf->page = page_pool_dev_alloc_frag(pool, &buf->page_offset, 1050 - buf_size); 1051 - else 1052 - buf->page = page_pool_dev_alloc_pages(pool); 1053 - 1054 - if (!buf->page) 1055 - return DMA_MAPPING_ERROR; 1056 - 1057 - buf->truesize = buf_size; 1058 - 1059 - return page_pool_get_dma_addr(buf->page) + buf->page_offset + 1060 - pool->p.offset; 1061 - } 1062 - 1063 - /** 1064 - * idpf_rx_put_page - Return RX buffer page to pool 1065 - * @rx_buf: RX buffer metadata struct 1066 - */ 1067 - static inline void idpf_rx_put_page(struct idpf_rx_buf *rx_buf) 1068 - { 1069 - page_pool_put_page(rx_buf->page->pp, rx_buf->page, 1070 - rx_buf->truesize, true); 1071 - rx_buf->page = NULL; 1072 - } 1073 - 1074 - /** 1075 - * idpf_rx_sync_for_cpu - Synchronize DMA buffer 1076 - * @rx_buf: RX buffer metadata struct 1077 - * @len: frame length from descriptor 1078 - */ 1079 - static inline void idpf_rx_sync_for_cpu(struct idpf_rx_buf *rx_buf, u32 len) 1080 - { 1081 - struct page *page = rx_buf->page; 1082 - struct page_pool *pp = page->pp; 1083 - 1084 - dma_sync_single_range_for_cpu(pp->p.dev, 1085 - page_pool_get_dma_addr(page), 1086 - rx_buf->page_offset + pp->p.offset, len, 1087 - page_pool_get_dma_dir(pp)); 1088 - } 1089 - 1090 924 int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget); 1091 925 void idpf_vport_init_num_qs(struct idpf_vport *vport, 1092 926 struct virtchnl2_create_vport *vport_msg); ··· 1049 991 void idpf_vport_intr_deinit(struct idpf_vport *vport); 1050 992 int idpf_vport_intr_init(struct idpf_vport *vport); 1051 993 void idpf_vport_intr_ena(struct idpf_vport *vport); 1052 - enum pkt_hash_types idpf_ptype_to_htype(const struct idpf_rx_ptype_decoded *decoded); 1053 994 int idpf_config_rss(struct idpf_vport *vport); 1054 995 int idpf_init_rss(struct idpf_vport *vport); 1055 996 void idpf_deinit_rss(struct idpf_vport *vport); 1056 997 int idpf_rx_bufs_init_all(struct idpf_vport *vport); 1057 998 void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb, 1058 999 unsigned int size); 1059 - struct sk_buff *idpf_rx_construct_skb(struct idpf_queue *rxq, 1060 - struct idpf_rx_buf *rx_buf, 1061 - unsigned int size); 1062 - bool idpf_init_rx_buf_hw_alloc(struct idpf_queue *rxq, struct idpf_rx_buf *buf); 1063 - void idpf_rx_buf_hw_update(struct idpf_queue *rxq, u32 val); 1064 - void idpf_tx_buf_hw_update(struct idpf_queue *tx_q, u32 val, 1000 + struct sk_buff *idpf_rx_build_skb(const struct libeth_fqe *buf, u32 size); 1001 + void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, 1065 1002 bool xmit_more); 1066 1003 unsigned int idpf_size_to_txd_count(unsigned int size); 1067 - netdev_tx_t idpf_tx_drop_skb(struct idpf_queue *tx_q, struct sk_buff *skb); 1068 - void idpf_tx_dma_map_error(struct idpf_queue *txq, struct sk_buff *skb, 1004 + netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb); 1005 + void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb, 1069 1006 struct idpf_tx_buf *first, u16 ring_idx); 1070 - unsigned int idpf_tx_desc_count_required(struct idpf_queue *txq, 1007 + unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq, 1071 1008 struct sk_buff *skb); 1072 - bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs, 1073 - unsigned int count); 1074 - int idpf_tx_maybe_stop_common(struct idpf_queue *tx_q, unsigned int size); 1009 + int idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q, unsigned int size); 1075 1010 void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue); 1076 - netdev_tx_t idpf_tx_splitq_start(struct sk_buff *skb, 1077 - struct net_device *netdev); 1078 - netdev_tx_t idpf_tx_singleq_start(struct sk_buff *skb, 1079 - struct net_device *netdev); 1080 - bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_queue *rxq, 1011 + netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, 1012 + struct idpf_tx_queue *tx_q); 1013 + netdev_tx_t idpf_tx_start(struct sk_buff *skb, struct net_device *netdev); 1014 + bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rxq, 1081 1015 u16 cleaned_count); 1082 1016 int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off); 1083 1017
+111 -67
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* Copyright (C) 2023 Intel Corporation */ 3 3 4 + #include <net/libeth/rx.h> 5 + 4 6 #include "idpf.h" 5 7 #include "idpf_virtchnl.h" 6 8 ··· 752 750 int i; 753 751 754 752 for (i = 0; i < vport->num_txq; i++) 755 - set_bit(__IDPF_Q_SW_MARKER, vport->txqs[i]->flags); 753 + idpf_queue_set(SW_MARKER, vport->txqs[i]); 756 754 757 755 event = wait_event_timeout(vport->sw_marker_wq, 758 756 test_and_clear_bit(IDPF_VPORT_SW_MARKER, ··· 760 758 msecs_to_jiffies(500)); 761 759 762 760 for (i = 0; i < vport->num_txq; i++) 763 - clear_bit(__IDPF_Q_POLL_MODE, vport->txqs[i]->flags); 761 + idpf_queue_clear(POLL_MODE, vport->txqs[i]); 764 762 765 763 if (event) 766 764 return 0; ··· 1094 1092 int num_regs, u32 q_type) 1095 1093 { 1096 1094 struct idpf_adapter *adapter = vport->adapter; 1097 - struct idpf_queue *q; 1098 1095 int i, j, k = 0; 1099 1096 1100 1097 switch (q_type) { ··· 1112 1111 u16 num_rxq = rx_qgrp->singleq.num_rxq; 1113 1112 1114 1113 for (j = 0; j < num_rxq && k < num_regs; j++, k++) { 1114 + struct idpf_rx_queue *q; 1115 + 1115 1116 q = rx_qgrp->singleq.rxqs[j]; 1116 1117 q->tail = idpf_get_reg_addr(adapter, 1117 1118 reg_vals[k]); ··· 1126 1123 u8 num_bufqs = vport->num_bufqs_per_qgrp; 1127 1124 1128 1125 for (j = 0; j < num_bufqs && k < num_regs; j++, k++) { 1126 + struct idpf_buf_queue *q; 1127 + 1129 1128 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 1130 1129 q->tail = idpf_get_reg_addr(adapter, 1131 1130 reg_vals[k]); ··· 1258 1253 vport_msg->vport_type = cpu_to_le16(VIRTCHNL2_VPORT_TYPE_DEFAULT); 1259 1254 vport_msg->vport_index = cpu_to_le16(idx); 1260 1255 1261 - if (adapter->req_tx_splitq) 1256 + if (adapter->req_tx_splitq || !IS_ENABLED(CONFIG_IDPF_SINGLEQ)) 1262 1257 vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT); 1263 1258 else 1264 1259 vport_msg->txq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE); 1265 1260 1266 - if (adapter->req_rx_splitq) 1261 + if (adapter->req_rx_splitq || !IS_ENABLED(CONFIG_IDPF_SINGLEQ)) 1267 1262 vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SPLIT); 1268 1263 else 1269 1264 vport_msg->rxq_model = cpu_to_le16(VIRTCHNL2_QUEUE_MODEL_SINGLE); ··· 1325 1320 1326 1321 vport_msg = adapter->vport_params_recvd[vport->idx]; 1327 1322 1323 + if (!IS_ENABLED(CONFIG_IDPF_SINGLEQ) && 1324 + (vport_msg->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE || 1325 + vport_msg->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE)) { 1326 + pci_err(adapter->pdev, "singleq mode requested, but not compiled-in\n"); 1327 + return -EOPNOTSUPP; 1328 + } 1329 + 1328 1330 rx_desc_ids = le64_to_cpu(vport_msg->rx_desc_ids); 1329 1331 tx_desc_ids = le64_to_cpu(vport_msg->tx_desc_ids); 1330 1332 1331 - if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { 1333 + if (idpf_is_queue_model_split(vport->rxq_model)) { 1332 1334 if (!(rx_desc_ids & VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M)) { 1333 1335 dev_info(&adapter->pdev->dev, "Minimum RX descriptor support not provided, using the default\n"); 1334 1336 vport_msg->rx_desc_ids = cpu_to_le64(VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M); ··· 1345 1333 vport->base_rxd = true; 1346 1334 } 1347 1335 1348 - if (vport->txq_model != VIRTCHNL2_QUEUE_MODEL_SPLIT) 1336 + if (!idpf_is_queue_model_split(vport->txq_model)) 1349 1337 return 0; 1350 1338 1351 1339 if ((tx_desc_ids & MIN_SUPPORT_TXDID) != MIN_SUPPORT_TXDID) { ··· 1461 1449 qi[k].model = 1462 1450 cpu_to_le16(vport->txq_model); 1463 1451 qi[k].type = 1464 - cpu_to_le32(tx_qgrp->txqs[j]->q_type); 1452 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_TX); 1465 1453 qi[k].ring_len = 1466 1454 cpu_to_le16(tx_qgrp->txqs[j]->desc_count); 1467 1455 qi[k].dma_ring_addr = 1468 1456 cpu_to_le64(tx_qgrp->txqs[j]->dma); 1469 1457 if (idpf_is_queue_model_split(vport->txq_model)) { 1470 - struct idpf_queue *q = tx_qgrp->txqs[j]; 1458 + struct idpf_tx_queue *q = tx_qgrp->txqs[j]; 1471 1459 1472 1460 qi[k].tx_compl_queue_id = 1473 1461 cpu_to_le16(tx_qgrp->complq->q_id); 1474 1462 qi[k].relative_queue_id = cpu_to_le16(j); 1475 1463 1476 - if (test_bit(__IDPF_Q_FLOW_SCH_EN, q->flags)) 1464 + if (idpf_queue_has(FLOW_SCH_EN, q)) 1477 1465 qi[k].sched_mode = 1478 1466 cpu_to_le16(VIRTCHNL2_TXQ_SCHED_MODE_FLOW); 1479 1467 else ··· 1490 1478 1491 1479 qi[k].queue_id = cpu_to_le32(tx_qgrp->complq->q_id); 1492 1480 qi[k].model = cpu_to_le16(vport->txq_model); 1493 - qi[k].type = cpu_to_le32(tx_qgrp->complq->q_type); 1481 + qi[k].type = cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION); 1494 1482 qi[k].ring_len = cpu_to_le16(tx_qgrp->complq->desc_count); 1495 1483 qi[k].dma_ring_addr = cpu_to_le64(tx_qgrp->complq->dma); 1496 1484 1497 - if (test_bit(__IDPF_Q_FLOW_SCH_EN, tx_qgrp->complq->flags)) 1485 + if (idpf_queue_has(FLOW_SCH_EN, tx_qgrp->complq)) 1498 1486 sched_mode = VIRTCHNL2_TXQ_SCHED_MODE_FLOW; 1499 1487 else 1500 1488 sched_mode = VIRTCHNL2_TXQ_SCHED_MODE_QUEUE; ··· 1579 1567 goto setup_rxqs; 1580 1568 1581 1569 for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) { 1582 - struct idpf_queue *bufq = 1570 + struct idpf_buf_queue *bufq = 1583 1571 &rx_qgrp->splitq.bufq_sets[j].bufq; 1584 1572 1585 1573 qi[k].queue_id = cpu_to_le32(bufq->q_id); 1586 1574 qi[k].model = cpu_to_le16(vport->rxq_model); 1587 - qi[k].type = cpu_to_le32(bufq->q_type); 1575 + qi[k].type = 1576 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX_BUFFER); 1588 1577 qi[k].desc_ids = cpu_to_le64(VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M); 1589 1578 qi[k].ring_len = cpu_to_le16(bufq->desc_count); 1590 1579 qi[k].dma_ring_addr = cpu_to_le64(bufq->dma); 1591 1580 qi[k].data_buffer_size = cpu_to_le32(bufq->rx_buf_size); 1592 - qi[k].buffer_notif_stride = bufq->rx_buf_stride; 1581 + qi[k].buffer_notif_stride = IDPF_RX_BUF_STRIDE; 1593 1582 qi[k].rx_buffer_low_watermark = 1594 1583 cpu_to_le16(bufq->rx_buffer_low_watermark); 1595 1584 if (idpf_is_feature_ena(vport, NETIF_F_GRO_HW)) ··· 1604 1591 num_rxq = rx_qgrp->singleq.num_rxq; 1605 1592 1606 1593 for (j = 0; j < num_rxq; j++, k++) { 1607 - struct idpf_queue *rxq; 1594 + const struct idpf_bufq_set *sets; 1595 + struct idpf_rx_queue *rxq; 1608 1596 1609 1597 if (!idpf_is_queue_model_split(vport->rxq_model)) { 1610 1598 rxq = rx_qgrp->singleq.rxqs[j]; 1611 1599 goto common_qi_fields; 1612 1600 } 1601 + 1613 1602 rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq; 1614 - qi[k].rx_bufq1_id = 1615 - cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[0].bufq.q_id); 1603 + sets = rxq->bufq_sets; 1604 + 1605 + /* In splitq mode, RXQ buffer size should be 1606 + * set to that of the first buffer queue 1607 + * associated with this RXQ. 1608 + */ 1609 + rxq->rx_buf_size = sets[0].bufq.rx_buf_size; 1610 + 1611 + qi[k].rx_bufq1_id = cpu_to_le16(sets[0].bufq.q_id); 1616 1612 if (vport->num_bufqs_per_qgrp > IDPF_SINGLE_BUFQ_PER_RXQ_GRP) { 1617 1613 qi[k].bufq2_ena = IDPF_BUFQ2_ENA; 1618 1614 qi[k].rx_bufq2_id = 1619 - cpu_to_le16(rxq->rxq_grp->splitq.bufq_sets[1].bufq.q_id); 1615 + cpu_to_le16(sets[1].bufq.q_id); 1620 1616 } 1621 1617 qi[k].rx_buffer_low_watermark = 1622 1618 cpu_to_le16(rxq->rx_buffer_low_watermark); 1623 1619 if (idpf_is_feature_ena(vport, NETIF_F_GRO_HW)) 1624 1620 qi[k].qflags |= cpu_to_le16(VIRTCHNL2_RXQ_RSC); 1625 1621 1626 - common_qi_fields: 1627 - if (rxq->rx_hsplit_en) { 1622 + rxq->rx_hbuf_size = sets[0].bufq.rx_hbuf_size; 1623 + 1624 + if (idpf_queue_has(HSPLIT_EN, rxq)) { 1628 1625 qi[k].qflags |= 1629 1626 cpu_to_le16(VIRTCHNL2_RXQ_HDR_SPLIT); 1630 1627 qi[k].hdr_buffer_size = 1631 1628 cpu_to_le16(rxq->rx_hbuf_size); 1632 1629 } 1630 + 1631 + common_qi_fields: 1633 1632 qi[k].queue_id = cpu_to_le32(rxq->q_id); 1634 1633 qi[k].model = cpu_to_le16(vport->rxq_model); 1635 - qi[k].type = cpu_to_le32(rxq->q_type); 1634 + qi[k].type = cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX); 1636 1635 qi[k].ring_len = cpu_to_le16(rxq->desc_count); 1637 1636 qi[k].dma_ring_addr = cpu_to_le64(rxq->dma); 1638 1637 qi[k].max_pkt_size = cpu_to_le32(rxq->rx_max_pkt_size); ··· 1731 1706 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 1732 1707 1733 1708 for (j = 0; j < tx_qgrp->num_txq; j++, k++) { 1734 - qc[k].type = cpu_to_le32(tx_qgrp->txqs[j]->q_type); 1709 + qc[k].type = cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_TX); 1735 1710 qc[k].start_queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id); 1736 1711 qc[k].num_queues = cpu_to_le32(IDPF_NUMQ_PER_CHUNK); 1737 1712 } ··· 1745 1720 for (i = 0; i < vport->num_txq_grp; i++, k++) { 1746 1721 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 1747 1722 1748 - qc[k].type = cpu_to_le32(tx_qgrp->complq->q_type); 1723 + qc[k].type = cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION); 1749 1724 qc[k].start_queue_id = cpu_to_le32(tx_qgrp->complq->q_id); 1750 1725 qc[k].num_queues = cpu_to_le32(IDPF_NUMQ_PER_CHUNK); 1751 1726 } ··· 1766 1741 qc[k].start_queue_id = 1767 1742 cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_id); 1768 1743 qc[k].type = 1769 - cpu_to_le32(rx_qgrp->splitq.rxq_sets[j]->rxq.q_type); 1744 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX); 1770 1745 } else { 1771 1746 qc[k].start_queue_id = 1772 1747 cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_id); 1773 1748 qc[k].type = 1774 - cpu_to_le32(rx_qgrp->singleq.rxqs[j]->q_type); 1749 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX); 1775 1750 } 1776 1751 qc[k].num_queues = cpu_to_le32(IDPF_NUMQ_PER_CHUNK); 1777 1752 } ··· 1786 1761 struct idpf_rxq_group *rx_qgrp = &vport->rxq_grps[i]; 1787 1762 1788 1763 for (j = 0; j < vport->num_bufqs_per_qgrp; j++, k++) { 1789 - struct idpf_queue *q; 1764 + const struct idpf_buf_queue *q; 1790 1765 1791 1766 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 1792 - qc[k].type = cpu_to_le32(q->q_type); 1767 + qc[k].type = 1768 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX_BUFFER); 1793 1769 qc[k].start_queue_id = cpu_to_le32(q->q_id); 1794 1770 qc[k].num_queues = cpu_to_le32(IDPF_NUMQ_PER_CHUNK); 1795 1771 } ··· 1875 1849 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 1876 1850 1877 1851 for (j = 0; j < tx_qgrp->num_txq; j++, k++) { 1878 - vqv[k].queue_type = cpu_to_le32(tx_qgrp->txqs[j]->q_type); 1852 + vqv[k].queue_type = 1853 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_TX); 1879 1854 vqv[k].queue_id = cpu_to_le32(tx_qgrp->txqs[j]->q_id); 1880 1855 1881 1856 if (idpf_is_queue_model_split(vport->txq_model)) { ··· 1906 1879 num_rxq = rx_qgrp->singleq.num_rxq; 1907 1880 1908 1881 for (j = 0; j < num_rxq; j++, k++) { 1909 - struct idpf_queue *rxq; 1882 + struct idpf_rx_queue *rxq; 1910 1883 1911 1884 if (idpf_is_queue_model_split(vport->rxq_model)) 1912 1885 rxq = &rx_qgrp->splitq.rxq_sets[j]->rxq; 1913 1886 else 1914 1887 rxq = rx_qgrp->singleq.rxqs[j]; 1915 1888 1916 - vqv[k].queue_type = cpu_to_le32(rxq->q_type); 1889 + vqv[k].queue_type = 1890 + cpu_to_le32(VIRTCHNL2_QUEUE_TYPE_RX); 1917 1891 vqv[k].queue_id = cpu_to_le32(rxq->q_id); 1918 1892 vqv[k].vector_id = cpu_to_le16(rxq->q_vector->v_idx); 1919 1893 vqv[k].itr_idx = cpu_to_le32(rxq->q_vector->rx_itr_idx); ··· 2003 1975 * queues virtchnl message is sent 2004 1976 */ 2005 1977 for (i = 0; i < vport->num_txq; i++) 2006 - set_bit(__IDPF_Q_POLL_MODE, vport->txqs[i]->flags); 1978 + idpf_queue_set(POLL_MODE, vport->txqs[i]); 2007 1979 2008 1980 /* schedule the napi to receive all the marker packets */ 2009 1981 local_bh_disable(); ··· 2497 2469 * @frag: fragmentation allowed 2498 2470 * 2499 2471 */ 2500 - static void idpf_fill_ptype_lookup(struct idpf_rx_ptype_decoded *ptype, 2472 + static void idpf_fill_ptype_lookup(struct libeth_rx_pt *ptype, 2501 2473 struct idpf_ptype_state *pstate, 2502 2474 bool ipv4, bool frag) 2503 2475 { 2504 2476 if (!pstate->outer_ip || !pstate->outer_frag) { 2505 - ptype->outer_ip = IDPF_RX_PTYPE_OUTER_IP; 2506 2477 pstate->outer_ip = true; 2507 2478 2508 2479 if (ipv4) 2509 - ptype->outer_ip_ver = IDPF_RX_PTYPE_OUTER_IPV4; 2480 + ptype->outer_ip = LIBETH_RX_PT_OUTER_IPV4; 2510 2481 else 2511 - ptype->outer_ip_ver = IDPF_RX_PTYPE_OUTER_IPV6; 2482 + ptype->outer_ip = LIBETH_RX_PT_OUTER_IPV6; 2512 2483 2513 2484 if (frag) { 2514 - ptype->outer_frag = IDPF_RX_PTYPE_FRAG; 2485 + ptype->outer_frag = LIBETH_RX_PT_FRAG; 2515 2486 pstate->outer_frag = true; 2516 2487 } 2517 2488 } else { 2518 - ptype->tunnel_type = IDPF_RX_PTYPE_TUNNEL_IP_IP; 2489 + ptype->tunnel_type = LIBETH_RX_PT_TUNNEL_IP_IP; 2519 2490 pstate->tunnel_state = IDPF_PTYPE_TUNNEL_IP; 2520 2491 2521 2492 if (ipv4) 2522 - ptype->tunnel_end_prot = 2523 - IDPF_RX_PTYPE_TUNNEL_END_IPV4; 2493 + ptype->tunnel_end_prot = LIBETH_RX_PT_TUNNEL_END_IPV4; 2524 2494 else 2525 - ptype->tunnel_end_prot = 2526 - IDPF_RX_PTYPE_TUNNEL_END_IPV6; 2495 + ptype->tunnel_end_prot = LIBETH_RX_PT_TUNNEL_END_IPV6; 2527 2496 2528 2497 if (frag) 2529 - ptype->tunnel_end_frag = IDPF_RX_PTYPE_FRAG; 2498 + ptype->tunnel_end_frag = LIBETH_RX_PT_FRAG; 2530 2499 } 2500 + } 2501 + 2502 + static void idpf_finalize_ptype_lookup(struct libeth_rx_pt *ptype) 2503 + { 2504 + if (ptype->payload_layer == LIBETH_RX_PT_PAYLOAD_L2 && 2505 + ptype->inner_prot) 2506 + ptype->payload_layer = LIBETH_RX_PT_PAYLOAD_L4; 2507 + else if (ptype->payload_layer == LIBETH_RX_PT_PAYLOAD_L2 && 2508 + ptype->outer_ip) 2509 + ptype->payload_layer = LIBETH_RX_PT_PAYLOAD_L3; 2510 + else if (ptype->outer_ip == LIBETH_RX_PT_OUTER_L2) 2511 + ptype->payload_layer = LIBETH_RX_PT_PAYLOAD_L2; 2512 + else 2513 + ptype->payload_layer = LIBETH_RX_PT_PAYLOAD_NONE; 2514 + 2515 + libeth_rx_pt_gen_hash_type(ptype); 2531 2516 } 2532 2517 2533 2518 /** ··· 2553 2512 { 2554 2513 struct virtchnl2_get_ptype_info *get_ptype_info __free(kfree) = NULL; 2555 2514 struct virtchnl2_get_ptype_info *ptype_info __free(kfree) = NULL; 2556 - struct idpf_rx_ptype_decoded *ptype_lkup = vport->rx_ptype_lkup; 2515 + struct libeth_rx_pt *ptype_lkup __free(kfree) = NULL; 2557 2516 int max_ptype, ptypes_recvd = 0, ptype_offset; 2558 2517 struct idpf_adapter *adapter = vport->adapter; 2559 2518 struct idpf_vc_xn_params xn_params = {}; ··· 2561 2520 ssize_t reply_sz; 2562 2521 int i, j, k; 2563 2522 2523 + if (vport->rx_ptype_lkup) 2524 + return 0; 2525 + 2564 2526 if (idpf_is_queue_model_split(vport->rxq_model)) 2565 2527 max_ptype = IDPF_RX_MAX_PTYPE; 2566 2528 else 2567 2529 max_ptype = IDPF_RX_MAX_BASE_PTYPE; 2568 2530 2569 - memset(vport->rx_ptype_lkup, 0, sizeof(vport->rx_ptype_lkup)); 2531 + ptype_lkup = kcalloc(max_ptype, sizeof(*ptype_lkup), GFP_KERNEL); 2532 + if (!ptype_lkup) 2533 + return -ENOMEM; 2570 2534 2571 2535 get_ptype_info = kzalloc(sizeof(*get_ptype_info), GFP_KERNEL); 2572 2536 if (!get_ptype_info) ··· 2629 2583 /* 0xFFFF indicates end of ptypes */ 2630 2584 if (le16_to_cpu(ptype->ptype_id_10) == 2631 2585 IDPF_INVALID_PTYPE_ID) 2632 - return 0; 2586 + goto out; 2633 2587 2634 2588 if (idpf_is_queue_model_split(vport->rxq_model)) 2635 2589 k = le16_to_cpu(ptype->ptype_id_10); 2636 2590 else 2637 2591 k = ptype->ptype_id_8; 2638 - 2639 - if (ptype->proto_id_count) 2640 - ptype_lkup[k].known = 1; 2641 2592 2642 2593 for (j = 0; j < ptype->proto_id_count; j++) { 2643 2594 id = le16_to_cpu(ptype->proto_id[j]); ··· 2643 2600 if (pstate.tunnel_state == 2644 2601 IDPF_PTYPE_TUNNEL_IP) { 2645 2602 ptype_lkup[k].tunnel_type = 2646 - IDPF_RX_PTYPE_TUNNEL_IP_GRENAT; 2603 + LIBETH_RX_PT_TUNNEL_IP_GRENAT; 2647 2604 pstate.tunnel_state |= 2648 2605 IDPF_PTYPE_TUNNEL_IP_GRENAT; 2649 2606 } 2650 2607 break; 2651 2608 case VIRTCHNL2_PROTO_HDR_MAC: 2652 2609 ptype_lkup[k].outer_ip = 2653 - IDPF_RX_PTYPE_OUTER_L2; 2610 + LIBETH_RX_PT_OUTER_L2; 2654 2611 if (pstate.tunnel_state == 2655 2612 IDPF_TUN_IP_GRE) { 2656 2613 ptype_lkup[k].tunnel_type = 2657 - IDPF_RX_PTYPE_TUNNEL_IP_GRENAT_MAC; 2614 + LIBETH_RX_PT_TUNNEL_IP_GRENAT_MAC; 2658 2615 pstate.tunnel_state |= 2659 2616 IDPF_PTYPE_TUNNEL_IP_GRENAT_MAC; 2660 2617 } ··· 2681 2638 break; 2682 2639 case VIRTCHNL2_PROTO_HDR_UDP: 2683 2640 ptype_lkup[k].inner_prot = 2684 - IDPF_RX_PTYPE_INNER_PROT_UDP; 2641 + LIBETH_RX_PT_INNER_UDP; 2685 2642 break; 2686 2643 case VIRTCHNL2_PROTO_HDR_TCP: 2687 2644 ptype_lkup[k].inner_prot = 2688 - IDPF_RX_PTYPE_INNER_PROT_TCP; 2645 + LIBETH_RX_PT_INNER_TCP; 2689 2646 break; 2690 2647 case VIRTCHNL2_PROTO_HDR_SCTP: 2691 2648 ptype_lkup[k].inner_prot = 2692 - IDPF_RX_PTYPE_INNER_PROT_SCTP; 2649 + LIBETH_RX_PT_INNER_SCTP; 2693 2650 break; 2694 2651 case VIRTCHNL2_PROTO_HDR_ICMP: 2695 2652 ptype_lkup[k].inner_prot = 2696 - IDPF_RX_PTYPE_INNER_PROT_ICMP; 2653 + LIBETH_RX_PT_INNER_ICMP; 2697 2654 break; 2698 2655 case VIRTCHNL2_PROTO_HDR_PAY: 2699 2656 ptype_lkup[k].payload_layer = 2700 - IDPF_RX_PTYPE_PAYLOAD_LAYER_PAY2; 2657 + LIBETH_RX_PT_PAYLOAD_L2; 2701 2658 break; 2702 2659 case VIRTCHNL2_PROTO_HDR_ICMPV6: 2703 2660 case VIRTCHNL2_PROTO_HDR_IPV6_EH: ··· 2751 2708 break; 2752 2709 } 2753 2710 } 2711 + 2712 + idpf_finalize_ptype_lookup(&ptype_lkup[k]); 2754 2713 } 2755 2714 } 2715 + 2716 + out: 2717 + vport->rx_ptype_lkup = no_free_ptr(ptype_lkup); 2756 2718 2757 2719 return 0; 2758 2720 } ··· 3173 3125 rss_data->rss_lut_size = le16_to_cpu(vport_msg->rss_lut_size); 3174 3126 3175 3127 ether_addr_copy(vport->default_mac_addr, vport_msg->default_mac_addr); 3176 - vport->max_mtu = le16_to_cpu(vport_msg->max_mtu) - IDPF_PACKET_HDR_PAD; 3128 + vport->max_mtu = le16_to_cpu(vport_msg->max_mtu) - LIBETH_RX_LL_LEN; 3177 3129 3178 3130 /* Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */ 3179 3131 memcpy(vport->rx_itr_profile, rx_itr, IDPF_DIM_PROFILE_SLOTS); ··· 3290 3242 int num_qids, 3291 3243 u32 q_type) 3292 3244 { 3293 - struct idpf_queue *q; 3294 3245 int i, j, k = 0; 3295 3246 3296 3247 switch (q_type) { ··· 3297 3250 for (i = 0; i < vport->num_txq_grp; i++) { 3298 3251 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 3299 3252 3300 - for (j = 0; j < tx_qgrp->num_txq && k < num_qids; j++, k++) { 3253 + for (j = 0; j < tx_qgrp->num_txq && k < num_qids; j++, k++) 3301 3254 tx_qgrp->txqs[j]->q_id = qids[k]; 3302 - tx_qgrp->txqs[j]->q_type = 3303 - VIRTCHNL2_QUEUE_TYPE_TX; 3304 - } 3305 3255 } 3306 3256 break; 3307 3257 case VIRTCHNL2_QUEUE_TYPE_RX: ··· 3312 3268 num_rxq = rx_qgrp->singleq.num_rxq; 3313 3269 3314 3270 for (j = 0; j < num_rxq && k < num_qids; j++, k++) { 3271 + struct idpf_rx_queue *q; 3272 + 3315 3273 if (idpf_is_queue_model_split(vport->rxq_model)) 3316 3274 q = &rx_qgrp->splitq.rxq_sets[j]->rxq; 3317 3275 else 3318 3276 q = rx_qgrp->singleq.rxqs[j]; 3319 3277 q->q_id = qids[k]; 3320 - q->q_type = VIRTCHNL2_QUEUE_TYPE_RX; 3321 3278 } 3322 3279 } 3323 3280 break; ··· 3327 3282 struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; 3328 3283 3329 3284 tx_qgrp->complq->q_id = qids[k]; 3330 - tx_qgrp->complq->q_type = 3331 - VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; 3332 3285 } 3333 3286 break; 3334 3287 case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER: ··· 3335 3292 u8 num_bufqs = vport->num_bufqs_per_qgrp; 3336 3293 3337 3294 for (j = 0; j < num_bufqs && k < num_qids; j++, k++) { 3295 + struct idpf_buf_queue *q; 3296 + 3338 3297 q = &rx_qgrp->splitq.bufq_sets[j].bufq; 3339 3298 q->q_id = qids[k]; 3340 - q->q_type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER; 3341 3299 } 3342 3300 } 3343 3301 break;
+121 -11
drivers/net/ethernet/intel/libeth/rx.c
··· 6 6 /* Rx buffer management */ 7 7 8 8 /** 9 - * libeth_rx_hw_len - get the actual buffer size to be passed to HW 9 + * libeth_rx_hw_len_mtu - get the actual buffer size to be passed to HW 10 10 * @pp: &page_pool_params of the netdev to calculate the size for 11 11 * @max_len: maximum buffer size for a single descriptor 12 12 * ··· 14 14 * MTU the @dev has, HW required alignment, minimum and maximum allowed values, 15 15 * and system's page size. 16 16 */ 17 - static u32 libeth_rx_hw_len(const struct page_pool_params *pp, u32 max_len) 17 + static u32 libeth_rx_hw_len_mtu(const struct page_pool_params *pp, u32 max_len) 18 18 { 19 19 u32 len; 20 20 ··· 24 24 pp->max_len); 25 25 26 26 return len; 27 + } 28 + 29 + /** 30 + * libeth_rx_hw_len_truesize - get the short buffer size to be passed to HW 31 + * @pp: &page_pool_params of the netdev to calculate the size for 32 + * @max_len: maximum buffer size for a single descriptor 33 + * @truesize: desired truesize for the buffers 34 + * 35 + * Return: HW-writeable length per one buffer to pass it to the HW ignoring the 36 + * MTU and closest to the passed truesize. Can be used for "short" buffer 37 + * queues to fragment pages more efficiently. 38 + */ 39 + static u32 libeth_rx_hw_len_truesize(const struct page_pool_params *pp, 40 + u32 max_len, u32 truesize) 41 + { 42 + u32 min, len; 43 + 44 + min = SKB_HEAD_ALIGN(pp->offset + LIBETH_RX_BUF_STRIDE); 45 + truesize = clamp(roundup_pow_of_two(truesize), roundup_pow_of_two(min), 46 + PAGE_SIZE << LIBETH_RX_PAGE_ORDER); 47 + 48 + len = SKB_WITH_OVERHEAD(truesize - pp->offset); 49 + len = ALIGN_DOWN(len, LIBETH_RX_BUF_STRIDE) ? : LIBETH_RX_BUF_STRIDE; 50 + len = min3(len, ALIGN_DOWN(max_len ? : U32_MAX, LIBETH_RX_BUF_STRIDE), 51 + pp->max_len); 52 + 53 + return len; 54 + } 55 + 56 + /** 57 + * libeth_rx_page_pool_params - calculate params with the stack overhead 58 + * @fq: buffer queue to calculate the size for 59 + * @pp: &page_pool_params of the netdev 60 + * 61 + * Set the PP params to will all needed stack overhead (headroom, tailroom) and 62 + * both the HW buffer length and the truesize for all types of buffers. For 63 + * "short" buffers, truesize never exceeds the "wanted" one; for the rest, 64 + * it can be up to the page size. 65 + * 66 + * Return: true on success, false on invalid input params. 67 + */ 68 + static bool libeth_rx_page_pool_params(struct libeth_fq *fq, 69 + struct page_pool_params *pp) 70 + { 71 + pp->offset = LIBETH_SKB_HEADROOM; 72 + /* HW-writeable / syncable length per one page */ 73 + pp->max_len = LIBETH_RX_PAGE_LEN(pp->offset); 74 + 75 + /* HW-writeable length per buffer */ 76 + switch (fq->type) { 77 + case LIBETH_FQE_MTU: 78 + fq->buf_len = libeth_rx_hw_len_mtu(pp, fq->buf_len); 79 + break; 80 + case LIBETH_FQE_SHORT: 81 + fq->buf_len = libeth_rx_hw_len_truesize(pp, fq->buf_len, 82 + fq->truesize); 83 + break; 84 + case LIBETH_FQE_HDR: 85 + fq->buf_len = ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE); 86 + break; 87 + default: 88 + return false; 89 + } 90 + 91 + /* Buffer size to allocate */ 92 + fq->truesize = roundup_pow_of_two(SKB_HEAD_ALIGN(pp->offset + 93 + fq->buf_len)); 94 + 95 + return true; 96 + } 97 + 98 + /** 99 + * libeth_rx_page_pool_params_zc - calculate params without the stack overhead 100 + * @fq: buffer queue to calculate the size for 101 + * @pp: &page_pool_params of the netdev 102 + * 103 + * Set the PP params to exclude the stack overhead and both the buffer length 104 + * and the truesize, which are equal for the data buffers. Note that this 105 + * requires separate header buffers to be always active and account the 106 + * overhead. 107 + * With the MTU == ``PAGE_SIZE``, this allows the kernel to enable the zerocopy 108 + * mode. 109 + * 110 + * Return: true on success, false on invalid input params. 111 + */ 112 + static bool libeth_rx_page_pool_params_zc(struct libeth_fq *fq, 113 + struct page_pool_params *pp) 114 + { 115 + u32 mtu, max; 116 + 117 + pp->offset = 0; 118 + pp->max_len = PAGE_SIZE << LIBETH_RX_PAGE_ORDER; 119 + 120 + switch (fq->type) { 121 + case LIBETH_FQE_MTU: 122 + mtu = READ_ONCE(pp->netdev->mtu); 123 + break; 124 + case LIBETH_FQE_SHORT: 125 + mtu = fq->truesize; 126 + break; 127 + default: 128 + return false; 129 + } 130 + 131 + mtu = roundup_pow_of_two(mtu); 132 + max = min(rounddown_pow_of_two(fq->buf_len ? : U32_MAX), 133 + pp->max_len); 134 + 135 + fq->buf_len = clamp(mtu, LIBETH_RX_BUF_STRIDE, max); 136 + fq->truesize = fq->buf_len; 137 + 138 + return true; 27 139 } 28 140 29 141 /** ··· 156 44 .netdev = napi->dev, 157 45 .napi = napi, 158 46 .dma_dir = DMA_FROM_DEVICE, 159 - .offset = LIBETH_SKB_HEADROOM, 160 47 }; 161 48 struct libeth_fqe *fqes; 162 49 struct page_pool *pool; 50 + bool ret; 163 51 164 - /* HW-writeable / syncable length per one page */ 165 - pp.max_len = LIBETH_RX_PAGE_LEN(pp.offset); 166 - 167 - /* HW-writeable length per buffer */ 168 - fq->buf_len = libeth_rx_hw_len(&pp, fq->buf_len); 169 - /* Buffer size to allocate */ 170 - fq->truesize = roundup_pow_of_two(SKB_HEAD_ALIGN(pp.offset + 171 - fq->buf_len)); 52 + if (!fq->hsplit) 53 + ret = libeth_rx_page_pool_params(fq, &pp); 54 + else 55 + ret = libeth_rx_page_pool_params_zc(fq, &pp); 56 + if (!ret) 57 + return -EINVAL; 172 58 173 59 pool = page_pool_create(&pp); 174 60 if (IS_ERR(pool))
+59
include/linux/cache.h
··· 13 13 #define SMP_CACHE_BYTES L1_CACHE_BYTES 14 14 #endif 15 15 16 + /** 17 + * SMP_CACHE_ALIGN - align a value to the L2 cacheline size 18 + * @x: value to align 19 + * 20 + * On some architectures, L2 ("SMP") CL size is bigger than L1, and sometimes, 21 + * this needs to be accounted. 22 + * 23 + * Return: aligned value. 24 + */ 25 + #ifndef SMP_CACHE_ALIGN 26 + #define SMP_CACHE_ALIGN(x) ALIGN(x, SMP_CACHE_BYTES) 27 + #endif 28 + 29 + /* 30 + * ``__aligned_largest`` aligns a field to the value most optimal for the 31 + * target architecture to perform memory operations. Get the actual value 32 + * to be able to use it anywhere else. 33 + */ 34 + #ifndef __LARGEST_ALIGN 35 + #define __LARGEST_ALIGN sizeof(struct { long x; } __aligned_largest) 36 + #endif 37 + 38 + #ifndef LARGEST_ALIGN 39 + #define LARGEST_ALIGN(x) ALIGN(x, __LARGEST_ALIGN) 40 + #endif 41 + 16 42 /* 17 43 * __read_mostly is used to keep rarely changing variables out of frequently 18 44 * updated cachelines. Its use should be reserved for data that is used ··· 120 94 #define __cacheline_group_end(GROUP) \ 121 95 __u8 __cacheline_group_end__##GROUP[0] 122 96 #endif 97 + 98 + /** 99 + * __cacheline_group_begin_aligned - declare an aligned group start 100 + * @GROUP: name of the group 101 + * @...: optional group alignment 102 + * 103 + * The following block inside a struct: 104 + * 105 + * __cacheline_group_begin_aligned(grp); 106 + * field a; 107 + * field b; 108 + * __cacheline_group_end_aligned(grp); 109 + * 110 + * will always be aligned to either the specified alignment or 111 + * ``SMP_CACHE_BYTES``. 112 + */ 113 + #define __cacheline_group_begin_aligned(GROUP, ...) \ 114 + __cacheline_group_begin(GROUP) \ 115 + __aligned((__VA_ARGS__ + 0) ? : SMP_CACHE_BYTES) 116 + 117 + /** 118 + * __cacheline_group_end_aligned - declare an aligned group end 119 + * @GROUP: name of the group 120 + * @...: optional alignment (same as was in __cacheline_group_begin_aligned()) 121 + * 122 + * Note that the end marker is aligned to sizeof(long) to allow more precise 123 + * size assertion. It also declares a padding at the end to avoid next field 124 + * falling into this cacheline. 125 + */ 126 + #define __cacheline_group_end_aligned(GROUP, ...) \ 127 + __cacheline_group_end(GROUP) __aligned(sizeof(long)); \ 128 + struct { } __cacheline_group_pad__##GROUP \ 129 + __aligned((__VA_ARGS__ + 0) ? : SMP_CACHE_BYTES) 123 130 124 131 #ifndef CACHELINE_ASSERT_GROUP_MEMBER 125 132 #define CACHELINE_ASSERT_GROUP_MEMBER(TYPE, GROUP, MEMBER) \
+66
include/net/libeth/cache.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* Copyright (C) 2024 Intel Corporation */ 3 + 4 + #ifndef __LIBETH_CACHE_H 5 + #define __LIBETH_CACHE_H 6 + 7 + #include <linux/cache.h> 8 + 9 + /** 10 + * libeth_cacheline_group_assert - make sure cacheline group size is expected 11 + * @type: type of the structure containing the group 12 + * @grp: group name inside the struct 13 + * @sz: expected group size 14 + */ 15 + #if defined(CONFIG_64BIT) && SMP_CACHE_BYTES == 64 16 + #define libeth_cacheline_group_assert(type, grp, sz) \ 17 + static_assert(offsetof(type, __cacheline_group_end__##grp) - \ 18 + offsetofend(type, __cacheline_group_begin__##grp) == \ 19 + (sz)) 20 + #define __libeth_cacheline_struct_assert(type, sz) \ 21 + static_assert(sizeof(type) == (sz)) 22 + #else /* !CONFIG_64BIT || SMP_CACHE_BYTES != 64 */ 23 + #define libeth_cacheline_group_assert(type, grp, sz) \ 24 + static_assert(offsetof(type, __cacheline_group_end__##grp) - \ 25 + offsetofend(type, __cacheline_group_begin__##grp) <= \ 26 + (sz)) 27 + #define __libeth_cacheline_struct_assert(type, sz) \ 28 + static_assert(sizeof(type) <= (sz)) 29 + #endif /* !CONFIG_64BIT || SMP_CACHE_BYTES != 64 */ 30 + 31 + #define __libeth_cls1(sz1) SMP_CACHE_ALIGN(sz1) 32 + #define __libeth_cls2(sz1, sz2) (SMP_CACHE_ALIGN(sz1) + SMP_CACHE_ALIGN(sz2)) 33 + #define __libeth_cls3(sz1, sz2, sz3) \ 34 + (SMP_CACHE_ALIGN(sz1) + SMP_CACHE_ALIGN(sz2) + SMP_CACHE_ALIGN(sz3)) 35 + #define __libeth_cls(...) \ 36 + CONCATENATE(__libeth_cls, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__) 37 + 38 + /** 39 + * libeth_cacheline_struct_assert - make sure CL-based struct size is expected 40 + * @type: type of the struct 41 + * @...: from 1 to 3 CL group sizes (read-mostly, read-write, cold) 42 + * 43 + * When a struct contains several CL groups, it's difficult to predict its size 44 + * on different architectures. The macro instead takes sizes of all of the 45 + * groups the structure contains and generates the final struct size. 46 + */ 47 + #define libeth_cacheline_struct_assert(type, ...) \ 48 + __libeth_cacheline_struct_assert(type, __libeth_cls(__VA_ARGS__)); \ 49 + static_assert(__alignof(type) >= SMP_CACHE_BYTES) 50 + 51 + /** 52 + * libeth_cacheline_set_assert - make sure CL-based struct layout is expected 53 + * @type: type of the struct 54 + * @ro: expected size of the read-mostly group 55 + * @rw: expected size of the read-write group 56 + * @c: expected size of the cold group 57 + * 58 + * Check that each group size is expected and then do final struct size check. 59 + */ 60 + #define libeth_cacheline_set_assert(type, ro, rw, c) \ 61 + libeth_cacheline_group_assert(type, read_mostly, ro); \ 62 + libeth_cacheline_group_assert(type, read_write, rw); \ 63 + libeth_cacheline_group_assert(type, cold, c); \ 64 + libeth_cacheline_struct_assert(type, ro, rw, c) 65 + 66 + #endif /* __LIBETH_CACHE_H */
+19
include/net/libeth/rx.h
··· 17 17 #define LIBETH_MAX_HEADROOM LIBETH_SKB_HEADROOM 18 18 /* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */ 19 19 #define LIBETH_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN) 20 + /* Maximum supported L2-L4 header length */ 21 + #define LIBETH_MAX_HEAD roundup_pow_of_two(max(MAX_HEADER, 256)) 20 22 21 23 /* Always use order-0 pages */ 22 24 #define LIBETH_RX_PAGE_ORDER 0 ··· 46 44 } __aligned_largest; 47 45 48 46 /** 47 + * enum libeth_fqe_type - enum representing types of Rx buffers 48 + * @LIBETH_FQE_MTU: buffer size is determined by MTU 49 + * @LIBETH_FQE_SHORT: buffer size is smaller than MTU, for short frames 50 + * @LIBETH_FQE_HDR: buffer size is ```LIBETH_MAX_HEAD```-sized, for headers 51 + */ 52 + enum libeth_fqe_type { 53 + LIBETH_FQE_MTU = 0U, 54 + LIBETH_FQE_SHORT, 55 + LIBETH_FQE_HDR, 56 + }; 57 + 58 + /** 49 59 * struct libeth_fq - structure representing a buffer (fill) queue 50 60 * @fp: hotpath part of the structure 51 61 * @pp: &page_pool for buffer management 52 62 * @fqes: array of Rx buffers 53 63 * @truesize: size to allocate per buffer, w/overhead 54 64 * @count: number of descriptors/buffers the queue has 65 + * @type: type of the buffers this queue has 66 + * @hsplit: flag whether header split is enabled 55 67 * @buf_len: HW-writeable length per each buffer 56 68 * @nid: ID of the closest NUMA node with memory 57 69 */ ··· 79 63 ); 80 64 81 65 /* Cold fields */ 66 + enum libeth_fqe_type type:2; 67 + bool hsplit:1; 68 + 82 69 u32 buf_len; 83 70 int nid; 84 71 };
+12 -10
include/net/page_pool/types.h
··· 129 129 }; 130 130 #endif 131 131 132 + /* The whole frag API block must stay within one cacheline. On 32-bit systems, 133 + * sizeof(long) == sizeof(int), so that the block size is ``3 * sizeof(long)``. 134 + * On 64-bit systems, the actual size is ``2 * sizeof(long) + sizeof(int)``. 135 + * The closest pow-2 to both of them is ``4 * sizeof(long)``, so just use that 136 + * one for simplicity. 137 + * Having it aligned to a cacheline boundary may be excessive and doesn't bring 138 + * any good. 139 + */ 140 + #define PAGE_POOL_FRAG_GROUP_ALIGN (4 * sizeof(long)) 141 + 132 142 struct page_pool { 133 143 struct page_pool_params_fast p; 134 144 ··· 152 142 bool system:1; /* This is a global percpu pool */ 153 143 #endif 154 144 155 - /* The following block must stay within one cacheline. On 32-bit 156 - * systems, sizeof(long) == sizeof(int), so that the block size is 157 - * ``3 * sizeof(long)``. On 64-bit systems, the actual size is 158 - * ``2 * sizeof(long) + sizeof(int)``. The closest pow-2 to both of 159 - * them is ``4 * sizeof(long)``, so just use that one for simplicity. 160 - * Having it aligned to a cacheline boundary may be excessive and 161 - * doesn't bring any good. 162 - */ 163 - __cacheline_group_begin(frag) __aligned(4 * sizeof(long)); 145 + __cacheline_group_begin_aligned(frag, PAGE_POOL_FRAG_GROUP_ALIGN); 164 146 long frag_users; 165 147 netmem_ref frag_page; 166 148 unsigned int frag_offset; 167 - __cacheline_group_end(frag); 149 + __cacheline_group_end_aligned(frag, PAGE_POOL_FRAG_GROUP_ALIGN); 168 150 169 151 struct delayed_work release_dw; 170 152 void (*disconnect)(void *pool);
+2 -1
net/core/page_pool.c
··· 178 178 CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_users); 179 179 CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_page); 180 180 CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_offset); 181 - CACHELINE_ASSERT_GROUP_SIZE(struct page_pool, frag, 4 * sizeof(long)); 181 + CACHELINE_ASSERT_GROUP_SIZE(struct page_pool, frag, 182 + PAGE_POOL_FRAG_GROUP_ALIGN); 182 183 } 183 184 184 185 static int page_pool_init(struct page_pool *pool,