/** * idpf_chk_linearize - Check if skb exceeds max descriptors per packet * @skb: send buffer * @max_bufs: maximum scatter gather buffers for single packet * @count: number of buffers this packet needs * * Make sure we don't exceed maximum scatter gather buffers for a single * packet. * TSO case has been handled earlier from idpf_features_check().
*/ staticbool idpf_chk_linearize(conststruct sk_buff *skb, unsignedint max_bufs, unsignedint count)
{ if (likely(count <= max_bufs)) returnfalse;
/** * idpf_tx_desc_rel_all - Free Tx Resources for All Queues * @vport: virtual port structure * * Free all transmit software resources
*/ staticvoid idpf_tx_desc_rel_all(struct idpf_vport *vport)
{ int i, j;
if (!vport->txq_grps) return;
for (i = 0; i < vport->num_txq_grp; i++) { struct idpf_txq_group *txq_grp = &vport->txq_grps[i];
for (j = 0; j < txq_grp->num_txq; j++)
idpf_tx_desc_rel(txq_grp->txqs[j]);
if (idpf_is_queue_model_split(vport->txq_model))
idpf_compl_desc_rel(txq_grp->complq);
}
}
/** * idpf_tx_buf_alloc_all - Allocate memory for all buffer resources * @tx_q: queue for which the buffers are allocated * * Returns 0 on success, negative on failure
*/ staticint idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q)
{ /* Allocate book keeping buffers only. Buffers to be supplied to HW * are allocated by kernel network stack and received as part of skb
*/ if (idpf_queue_has(FLOW_SCH_EN, tx_q))
tx_q->buf_pool_size = U16_MAX; else
tx_q->buf_pool_size = tx_q->desc_count;
tx_q->tx_buf = kcalloc(tx_q->buf_pool_size, sizeof(*tx_q->tx_buf),
GFP_KERNEL); if (!tx_q->tx_buf) return -ENOMEM;
return 0;
}
/** * idpf_tx_desc_alloc - Allocate the Tx descriptors * @vport: vport to allocate resources for * @tx_q: the tx ring to set up * * Returns 0 on success, negative on failure
*/ staticint idpf_tx_desc_alloc(conststruct idpf_vport *vport, struct idpf_tx_queue *tx_q)
{ struct device *dev = tx_q->dev; struct idpf_sw_queue *refillq; int err;
err = idpf_tx_buf_alloc_all(tx_q); if (err) goto err_alloc;
/** * idpf_tx_desc_alloc_all - allocate all queues Tx resources * @vport: virtual port private structure * * Returns 0 on success, negative on failure
*/ staticint idpf_tx_desc_alloc_all(struct idpf_vport *vport)
{ int err = 0; int i, j;
/* Setup buffer queues. In single queue model buffer queues and * completion queues will be same
*/ for (i = 0; i < vport->num_txq_grp; i++) { for (j = 0; j < vport->txq_grps[i].num_txq; j++) { struct idpf_tx_queue *txq = vport->txq_grps[i].txqs[j];
err = idpf_tx_desc_alloc(vport, txq); if (err) {
pci_err(vport->adapter->pdev, "Allocation for Tx Queue %u failed\n",
i); goto err_out;
}
}
if (!idpf_is_queue_model_split(vport->txq_model)) continue;
/** * idpf_rx_desc_rel - Free a specific Rx q resources * @rxq: queue to clean the resources from * @dev: device to free DMA memory * @model: single or split queue model * * Free a specific rx queue resources
*/ staticvoid idpf_rx_desc_rel(struct idpf_rx_queue *rxq, struct device *dev,
u32 model)
{ if (!rxq) return;
if (rxq->skb) {
dev_kfree_skb_any(rxq->skb);
rxq->skb = NULL;
}
if (!idpf_is_queue_model_split(model))
idpf_rx_buf_rel_all(rxq);
/** * idpf_rx_buf_hw_update - Store the new tail and head values * @bufq: queue to bump * @val: new head index
*/ staticvoid idpf_rx_buf_hw_update(struct idpf_buf_queue *bufq, u32 val)
{
bufq->next_to_use = val;
if (unlikely(!bufq->tail)) return;
/* writel has an implicit memory barrier */
writel(val, bufq->tail);
}
/** * idpf_rx_hdr_buf_alloc_all - Allocate memory for header buffers * @bufq: ring to use * * Returns 0 on success, negative on failure.
*/ staticint idpf_rx_hdr_buf_alloc_all(struct idpf_buf_queue *bufq)
{ struct libeth_fq fq = {
.count = bufq->desc_count,
.type = LIBETH_FQE_HDR,
.nid = idpf_q_vector_to_mem(bufq->q_vector),
}; int ret;
ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi); if (ret) return ret;
/** * idpf_post_buf_refill - Post buffer id to refill queue * @refillq: refill queue to post to * @buf_id: buffer id to post
*/ staticvoid idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
{
u32 nta = refillq->next_to_use;
/* store the buffer ID and the SW maintained GEN bit to the refillq */
refillq->ring[nta] =
FIELD_PREP(IDPF_RFL_BI_BUFID_M, buf_id) |
FIELD_PREP(IDPF_RFL_BI_GEN_M,
idpf_queue_has(GEN_CHK, refillq));
if (unlikely(++nta == refillq->desc_count)) {
nta = 0;
idpf_queue_change(GEN_CHK, refillq);
}
refillq->next_to_use = nta;
}
/** * idpf_rx_post_buf_desc - Post buffer to bufq descriptor ring * @bufq: buffer queue to post to * @buf_id: buffer id to post * * Returns false if buffer could not be allocated, true otherwise.
*/ staticbool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)
{ struct virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL; struct libeth_fq_fp fq = {
.count = bufq->desc_count,
};
u16 nta = bufq->next_to_alloc;
dma_addr_t addr;
nta++; if (unlikely(nta == bufq->desc_count))
nta = 0;
bufq->next_to_alloc = nta;
returntrue;
}
/** * idpf_rx_post_init_bufs - Post initial buffers to bufq * @bufq: buffer queue to post working set to * @working_set: number of buffers to put in working set * * Returns true if @working_set bufs were posted successfully, false otherwise.
*/ staticbool idpf_rx_post_init_bufs(struct idpf_buf_queue *bufq,
u16 working_set)
{ int i;
for (i = 0; i < working_set; i++) { if (!idpf_rx_post_buf_desc(bufq, i)) returnfalse;
}
/** * idpf_rx_buf_alloc_singleq - Allocate memory for all buffer resources * @rxq: queue for which the buffers are allocated * * Return: 0 on success, -ENOMEM on failure.
*/ staticint idpf_rx_buf_alloc_singleq(struct idpf_rx_queue *rxq)
{ if (idpf_rx_singleq_buf_hw_alloc_all(rxq, rxq->desc_count - 1)) goto err;
return 0;
err:
idpf_rx_buf_rel_all(rxq);
return -ENOMEM;
}
/** * idpf_rx_bufs_init_singleq - Initialize page pool and allocate Rx bufs * @rxq: buffer queue to create page pool for * * Return: 0 on success, -errno on failure.
*/ staticint idpf_rx_bufs_init_singleq(struct idpf_rx_queue *rxq)
{ struct libeth_fq fq = {
.count = rxq->desc_count,
.type = LIBETH_FQE_MTU,
.nid = idpf_q_vector_to_mem(rxq->q_vector),
}; int ret;
ret = libeth_rx_fq_create(&fq, &rxq->q_vector->napi); if (ret) return ret;
/** * idpf_rx_buf_alloc_all - Allocate memory for all buffer resources * @rxbufq: queue for which the buffers are allocated * * Returns 0 on success, negative on failure
*/ staticint idpf_rx_buf_alloc_all(struct idpf_buf_queue *rxbufq)
{ int err = 0;
if (idpf_queue_has(HSPLIT_EN, rxbufq)) {
err = idpf_rx_hdr_buf_alloc_all(rxbufq); if (err) goto rx_buf_alloc_all_out;
}
/* Allocate buffers to be given to HW. */ if (!idpf_rx_post_init_bufs(rxbufq, IDPF_RX_BUFQ_WORKING_SET(rxbufq)))
err = -ENOMEM;
rx_buf_alloc_all_out: if (err)
idpf_rx_buf_rel_bufq(rxbufq);
return err;
}
/** * idpf_rx_bufs_init - Initialize page pool, allocate rx bufs, and post to HW * @bufq: buffer queue to create page pool for * @type: type of Rx buffers to allocate * * Returns 0 on success, negative on failure
*/ staticint idpf_rx_bufs_init(struct idpf_buf_queue *bufq, enum libeth_fqe_type type)
{ struct libeth_fq fq = {
.truesize = bufq->truesize,
.count = bufq->desc_count,
.type = type,
.hsplit = idpf_queue_has(HSPLIT_EN, bufq),
.nid = idpf_q_vector_to_mem(bufq->q_vector),
}; int ret;
ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi); if (ret) return ret;
/* Allocate descriptors and also round up to nearest 4K */
rxq->size = ALIGN(rxq->size, 4096);
rxq->desc_ring = dmam_alloc_coherent(dev, rxq->size,
&rxq->dma, GFP_KERNEL); if (!rxq->desc_ring) {
dev_err(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n",
rxq->size); return -ENOMEM;
}
/** * idpf_bufq_desc_alloc - Allocate buffer queue descriptor ring * @vport: vport to allocate resources for * @bufq: buffer queue for which the resources are set up * * Return: 0 on success, -ENOMEM on failure.
*/ staticint idpf_bufq_desc_alloc(conststruct idpf_vport *vport, struct idpf_buf_queue *bufq)
{ struct device *dev = &vport->adapter->pdev->dev;
/** * idpf_txq_group_rel - Release all resources for txq groups * @vport: vport to release txq groups on
*/ staticvoid idpf_txq_group_rel(struct idpf_vport *vport)
{ bool split, flow_sch_en; int i, j;
/** * idpf_rxq_group_rel - Release all resources for rxq groups * @vport: vport to release rxq groups on
*/ staticvoid idpf_rxq_group_rel(struct idpf_vport *vport)
{ int i;
if (!vport->rxq_grps) return;
for (i = 0; i < vport->num_rxq_grp; i++) { struct idpf_rxq_group *rx_qgrp = &vport->rxq_grps[i];
u16 num_rxq; int j;
if (idpf_is_queue_model_split(vport->rxq_model)) {
num_rxq = rx_qgrp->splitq.num_rxq_sets; for (j = 0; j < num_rxq; j++) {
kfree(rx_qgrp->splitq.rxq_sets[j]);
rx_qgrp->splitq.rxq_sets[j] = NULL;
}
/** * idpf_vport_queue_grp_rel_all - Release all queue groups * @vport: vport to release queue groups for
*/ staticvoid idpf_vport_queue_grp_rel_all(struct idpf_vport *vport)
{
idpf_txq_group_rel(vport);
idpf_rxq_group_rel(vport);
}
/** * idpf_vport_queues_rel - Free memory for all queues * @vport: virtual port * * Free the memory allocated for queues associated to a vport
*/ void idpf_vport_queues_rel(struct idpf_vport *vport)
{
idpf_tx_desc_rel_all(vport);
idpf_rx_desc_rel_all(vport);
idpf_vport_queue_grp_rel_all(vport);
kfree(vport->txqs);
vport->txqs = NULL;
}
/** * idpf_vport_init_fast_path_txqs - Initialize fast path txq array * @vport: vport to init txqs on * * We get a queue index from skb->queue_mapping and we need a fast way to * dereference the queue from queue groups. This allows us to quickly pull a * txq based on a queue index. * * Returns 0 on success, negative on failure
*/ staticint idpf_vport_init_fast_path_txqs(struct idpf_vport *vport)
{ struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps; struct work_struct *tstamp_task = &vport->tstamp_task; int i, j, k = 0;
/** * idpf_vport_init_num_qs - Initialize number of queues * @vport: vport to initialize queues * @vport_msg: data to be filled into vport
*/ void idpf_vport_init_num_qs(struct idpf_vport *vport, struct virtchnl2_create_vport *vport_msg)
{ struct idpf_vport_user_config_data *config_data;
u16 idx = vport->idx;
config_data = &vport->adapter->vport_config[idx]->user_config;
vport->num_txq = le16_to_cpu(vport_msg->num_tx_q);
vport->num_rxq = le16_to_cpu(vport_msg->num_rx_q); /* number of txqs and rxqs in config data will be zeros only in the * driver load path and we dont update them there after
*/ if (!config_data->num_req_tx_qs && !config_data->num_req_rx_qs) {
config_data->num_req_tx_qs = le16_to_cpu(vport_msg->num_tx_q);
config_data->num_req_rx_qs = le16_to_cpu(vport_msg->num_rx_q);
}
if (idpf_is_queue_model_split(vport->txq_model))
vport->num_complq = le16_to_cpu(vport_msg->num_tx_complq); if (idpf_is_queue_model_split(vport->rxq_model))
vport->num_bufq = le16_to_cpu(vport_msg->num_rx_bufq);
/* Adjust number of buffer queues per Rx queue group. */ if (!idpf_is_queue_model_split(vport->rxq_model)) {
vport->num_bufqs_per_qgrp = 0;
/** * idpf_vport_calc_num_q_desc - Calculate number of queue groups * @vport: vport to calculate q groups for
*/ void idpf_vport_calc_num_q_desc(struct idpf_vport *vport)
{ struct idpf_vport_user_config_data *config_data; int num_bufqs = vport->num_bufqs_per_qgrp;
u32 num_req_txq_desc, num_req_rxq_desc;
u16 idx = vport->idx; int i;
vport->complq_desc_count = 0; if (num_req_txq_desc) {
vport->txq_desc_count = num_req_txq_desc; if (idpf_is_queue_model_split(vport->txq_model)) {
vport->complq_desc_count = num_req_txq_desc; if (vport->complq_desc_count < IDPF_MIN_TXQ_COMPLQ_DESC)
vport->complq_desc_count =
IDPF_MIN_TXQ_COMPLQ_DESC;
}
} else {
vport->txq_desc_count = IDPF_DFLT_TX_Q_DESC_COUNT; if (idpf_is_queue_model_split(vport->txq_model))
vport->complq_desc_count =
IDPF_DFLT_TX_COMPLQ_DESC_COUNT;
}
if (num_req_rxq_desc)
vport->rxq_desc_count = num_req_rxq_desc; else
vport->rxq_desc_count = IDPF_DFLT_RX_Q_DESC_COUNT;
for (i = 0; i < num_bufqs; i++) { if (!vport->bufq_desc_count[i])
vport->bufq_desc_count[i] =
IDPF_RX_BUFQ_DESC_COUNT(vport->rxq_desc_count,
num_bufqs);
}
}
/** * idpf_vport_calc_total_qs - Calculate total number of queues * @adapter: private data struct * @vport_idx: vport idx to retrieve vport pointer * @vport_msg: message to fill with data * @max_q: vport max queue info * * Return 0 on success, error value on failure.
*/ int idpf_vport_calc_total_qs(struct idpf_adapter *adapter, u16 vport_idx, struct virtchnl2_create_vport *vport_msg, struct idpf_vport_max_q *max_q)
{ int dflt_splitq_txq_grps = 0, dflt_singleq_txqs = 0; int dflt_splitq_rxq_grps = 0, dflt_singleq_rxqs = 0;
u16 num_req_tx_qs = 0, num_req_rx_qs = 0; struct idpf_vport_config *vport_config;
u16 num_txq_grps, num_rxq_grps;
u32 num_qs;
vport_config = adapter->vport_config[vport_idx]; if (vport_config) {
num_req_tx_qs = vport_config->user_config.num_req_tx_qs;
num_req_rx_qs = vport_config->user_config.num_req_rx_qs;
} else { int num_cpus;
/* Restrict num of queues to cpus online as a default * configuration to give best performance. User can always * override to a max number of queues via ethtool.
*/
num_cpus = num_online_cpus();
/** * idpf_vport_calc_num_q_groups - Calculate number of queue groups * @vport: vport to calculate q groups for
*/ void idpf_vport_calc_num_q_groups(struct idpf_vport *vport)
{ if (idpf_is_queue_model_split(vport->txq_model))
vport->num_txq_grp = vport->num_txq; else
vport->num_txq_grp = IDPF_DFLT_SINGLEQ_TX_Q_GROUPS;
if (idpf_is_queue_model_split(vport->rxq_model))
vport->num_rxq_grp = vport->num_rxq; else
vport->num_rxq_grp = IDPF_DFLT_SINGLEQ_RX_Q_GROUPS;
}
/** * idpf_vport_calc_numq_per_grp - Calculate number of queues per group * @vport: vport to calculate queues for * @num_txq: return parameter for number of TX queues * @num_rxq: return parameter for number of RX queues
*/ staticvoid idpf_vport_calc_numq_per_grp(struct idpf_vport *vport,
u16 *num_txq, u16 *num_rxq)
{ if (idpf_is_queue_model_split(vport->txq_model))
*num_txq = IDPF_DFLT_SPLITQ_TXQ_PER_GROUP; else
*num_txq = vport->num_txq;
if (idpf_is_queue_model_split(vport->rxq_model))
*num_rxq = IDPF_DFLT_SPLITQ_RXQ_PER_GROUP; else
*num_rxq = vport->num_rxq;
}
/** * idpf_rxq_set_descids - set the descids supported by this queue * @vport: virtual port data structure * @q: rx queue for which descids are set *
*/ staticvoid idpf_rxq_set_descids(conststruct idpf_vport *vport, struct idpf_rx_queue *q)
{ if (idpf_is_queue_model_split(vport->rxq_model)) {
q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SPLITQ_M;
} else { if (vport->base_rxd)
q->rxdids = VIRTCHNL2_RXDID_1_32B_BASE_M; else
q->rxdids = VIRTCHNL2_RXDID_2_FLEX_SQ_NIC_M;
}
}
/** * idpf_txq_group_alloc - Allocate all txq group resources * @vport: vport to allocate txq groups for * @num_txq: number of txqs to allocate for each group * * Returns 0 on success, negative on failure
*/ staticint idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq)
{ bool split, flow_sch_en; int i;
vport->txq_grps = kcalloc(vport->num_txq_grp, sizeof(*vport->txq_grps), GFP_KERNEL); if (!vport->txq_grps) return -ENOMEM;
if (flow_sch_en)
idpf_queue_set(FLOW_SCH_EN, tx_qgrp->complq);
}
return 0;
err_alloc:
idpf_txq_group_rel(vport);
return -ENOMEM;
}
/** * idpf_rxq_group_alloc - Allocate all rxq group resources * @vport: vport to allocate rxq groups for * @num_rxq: number of rxqs to allocate for each group * * Returns 0 on success, negative on failure
*/ staticint idpf_rxq_group_alloc(struct idpf_vport *vport, u16 num_rxq)
{ int i, k, err = 0; bool hs;
vport->rxq_grps = kcalloc(vport->num_rxq_grp, sizeof(struct idpf_rxq_group), GFP_KERNEL); if (!vport->rxq_grps) return -ENOMEM;
err = idpf_txq_group_alloc(vport, num_txq); if (err) goto err_out;
err = idpf_rxq_group_alloc(vport, num_rxq); if (err) goto err_out;
return 0;
err_out:
idpf_vport_queue_grp_rel_all(vport);
return err;
}
/** * idpf_vport_queues_alloc - Allocate memory for all queues * @vport: virtual port * * Allocate memory for queues associated with a vport. Returns 0 on success, * negative on failure.
*/ int idpf_vport_queues_alloc(struct idpf_vport *vport)
{ int err;
err = idpf_vport_queue_grp_alloc_all(vport); if (err) goto err_out;
err = idpf_tx_desc_alloc_all(vport); if (err) goto err_out;
err = idpf_rx_desc_alloc_all(vport); if (err) goto err_out;
err = idpf_vport_init_fast_path_txqs(vport); if (err) goto err_out;
idpf_queue_clear(SW_MARKER, tx_q); /* Hardware must write marker packets to all queues associated with * completion queues. So check if all queues received marker packets
*/ for (i = 0; i < vport->num_txq; i++) /* If we're still waiting on any other TXQ marker completions, * just return now since we cannot wake up the marker_wq yet.
*/ if (idpf_queue_has(SW_MARKER, vport->txqs[i])) return;
/** * idpf_tx_read_tstamp - schedule a work to read Tx timestamp value * @txq: queue to read the timestamp from * @skb: socket buffer to provide Tx timestamp value * * Schedule a work to read Tx timestamp value generated once the packet is * transmitted.
*/ staticvoid idpf_tx_read_tstamp(struct idpf_tx_queue *txq, struct sk_buff *skb)
{ struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; struct idpf_ptp_tx_tstamp_status *tx_tstamp_status;
for (u32 i = 0; i < tx_tstamp_caps->num_entries; i++) {
tx_tstamp_status = &tx_tstamp_caps->tx_tstamp_status[i]; if (tx_tstamp_status->state != IDPF_PTP_FREE) continue;
/** * idpf_tx_splitq_clean - Reclaim resources from buffer queue * @tx_q: Tx queue to clean * @end: queue index until which it should be cleaned * @napi_budget: Used to determine if we are in netpoll * @cleaned: pointer to stats struct to track cleaned packets/bytes * @descs_only: true if queue is using flow-based scheduling and should * not clean buffers at this time * * Cleans the queue descriptor ring. If the queue is using queue-based * scheduling, the buffers will be cleaned as well. If the queue is using * flow-based scheduling, only the descriptors are cleaned at this time. * Separate packet completion events will be reported on the completion queue, * and the buffers will be cleaned separately. The stats are not updated from * this function when using flow-based scheduling.
*/ staticvoid idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end, int napi_budget, struct libeth_sq_napi_stats *cleaned, bool descs_only)
{ union idpf_tx_flex_desc *next_pending_desc = NULL; union idpf_tx_flex_desc *tx_desc;
u32 ntc = tx_q->next_to_clean; struct libeth_cq_pp cp = {
.dev = tx_q->dev,
.ss = cleaned,
.napi = napi_budget,
}; struct idpf_tx_buf *tx_buf;
if (descs_only) { /* Bump ring index to mark as cleaned. */
tx_q->next_to_clean = end; return;
}
while (tx_desc != next_pending_desc) {
u32 eop_idx;
/* If this entry in the ring was used as a context descriptor, * it's corresponding entry in the buffer ring is reserved. We * can skip this descriptor since there is no buffer to clean.
*/ if (tx_buf->type <= LIBETH_SQE_CTX) goto fetch_next_txq_desc;
if (unlikely(tx_buf->type != LIBETH_SQE_SKB)) break;
/** * idpf_tx_handle_rs_completion - clean a single packet and all of its buffers * whether on the buffer ring or in the hash table * @txq: Tx ring to clean * @desc: pointer to completion queue descriptor to extract completion * information from * @cleaned: pointer to stats struct to track cleaned packets/bytes * @budget: Used to determine if we are in netpoll * * Returns bytes/packets cleaned
*/ staticvoid idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq, struct idpf_splitq_tx_compl_desc *desc, struct libeth_sq_napi_stats *cleaned, int budget)
{ /* RS completion contains queue head for queue based scheduling or * completion tag for flow based scheduling.
*/
u16 rs_compl_val = le16_to_cpu(desc->q_head_compl_tag.q_head);
/** * idpf_tx_clean_complq - Reclaim resources on completion queue * @complq: Tx ring to clean * @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * * Returns true if there's any budget left (e.g. the clean is finished)
*/ staticbool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget, int *cleaned)
{ struct idpf_splitq_tx_compl_desc *tx_desc;
s16 ntc = complq->next_to_clean; struct idpf_netdev_priv *np; unsignedint complq_budget; bool complq_ok = true; int i;
do { struct libeth_sq_napi_stats cleaned_stats = { }; struct idpf_tx_queue *tx_q; int rel_tx_qid;
u16 hw_head;
u8 ctype; /* completion type */
u16 gen;
/* if the descriptor isn't done, no work yet to do */
gen = le16_get_bits(tx_desc->qid_comptype_gen,
IDPF_TXD_COMPLQ_GEN_M); if (idpf_queue_has(GEN_CHK, complq) != gen) break;
/* Find necessary info of TX queue to clean buffers */
rel_tx_qid = le16_get_bits(tx_desc->qid_comptype_gen,
IDPF_TXD_COMPLQ_QID_M); if (rel_tx_qid >= complq->txq_grp->num_txq ||
!complq->txq_grp->txqs[rel_tx_qid]) {
netdev_err(complq->netdev, "TxQ not found\n"); goto fetch_next_desc;
}
tx_q = complq->txq_grp->txqs[rel_tx_qid];
/* Determine completion type */
ctype = le16_get_bits(tx_desc->qid_comptype_gen,
IDPF_TXD_COMPLQ_COMPL_TYPE_M); switch (ctype) { case IDPF_TXD_COMPLT_RE:
hw_head = le16_to_cpu(tx_desc->q_head_compl_tag.q_head);
/* update budget accounting */
complq_budget--;
} while (likely(complq_budget));
/* Store the state of the complq to be used later in deciding if a * TXQ can be started again
*/ if (unlikely(IDPF_TX_COMPLQ_PENDING(complq->txq_grp) >
IDPF_TX_COMPLQ_OVERFLOW_THRESH(complq)))
complq_ok = false;
np = netdev_priv(complq->netdev); for (i = 0; i < complq->txq_grp->num_txq; ++i) { struct idpf_tx_queue *tx_q = complq->txq_grp->txqs[i]; struct netdev_queue *nq; bool dont_wake;
/* We didn't clean anything on this queue, move along */ if (!tx_q->cleaned_bytes) continue;
dont_wake = !complq_ok || np->state != __IDPF_VPORT_UP ||
!netif_carrier_ok(tx_q->netdev); /* Check if the TXQ needs to and can be restarted */
__netif_txq_completed_wake(nq, tx_q->cleaned_pkts, tx_q->cleaned_bytes,
IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH,
dont_wake);
/* Reset cleaned stats for the next time this queue is * cleaned
*/
tx_q->cleaned_bytes = 0;
tx_q->cleaned_pkts = 0;
}
/** * idpf_tx_splitq_build_ctb - populate command tag and size for queue * based scheduling descriptors * @desc: descriptor to populate * @params: pointer to tx params struct * @td_cmd: command to be filled in desc * @size: size of buffer
*/ void idpf_tx_splitq_build_ctb(union idpf_tx_flex_desc *desc, struct idpf_tx_splitq_params *params,
u16 td_cmd, u16 size)
{
desc->q.qw1.cmd_dtype =
le16_encode_bits(params->dtype, IDPF_FLEX_TXD_QW1_DTYPE_M);
desc->q.qw1.cmd_dtype |=
le16_encode_bits(td_cmd, IDPF_FLEX_TXD_QW1_CMD_M);
desc->q.qw1.buf_size = cpu_to_le16(size);
desc->q.qw1.l2tags.l2tag1 = cpu_to_le16(params->td_tag);
}
/** * idpf_tx_splitq_build_flow_desc - populate command tag and size for flow * scheduling descriptors * @desc: descriptor to populate * @params: pointer to tx params struct * @td_cmd: command to be filled in desc * @size: size of buffer
*/ void idpf_tx_splitq_build_flow_desc(union idpf_tx_flex_desc *desc, struct idpf_tx_splitq_params *params,
u16 td_cmd, u16 size)
{
*(u32 *)&desc->flow.qw1.cmd_dtype = (u8)(params->dtype | td_cmd);
desc->flow.qw1.rxr_bufsize = cpu_to_le16((u16)size);
desc->flow.qw1.compl_tag = cpu_to_le16(params->compl_tag);
}
/** * idpf_tx_splitq_has_room - check if enough Tx splitq resources are available * @tx_q: the queue to be checked * @descs_needed: number of descriptors required for this packet * @bufs_needed: number of Tx buffers required for this packet * * Return: 0 if no room available, 1 otherwise
*/ staticint idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 descs_needed,
u32 bufs_needed)
{ if (IDPF_DESC_UNUSED(tx_q) < descs_needed ||
IDPF_TX_COMPLQ_PENDING(tx_q->txq_grp) >
IDPF_TX_COMPLQ_OVERFLOW_THRESH(tx_q->txq_grp->complq) ||
idpf_tx_splitq_get_free_bufs(tx_q->refillq) < bufs_needed) return 0; return 1;
}
/** * idpf_tx_maybe_stop_splitq - 1st level check for Tx splitq stop conditions * @tx_q: the queue to be checked * @descs_needed: number of descriptors required for this packet * @bufs_needed: number of buffers needed for this packet * * Return: 0 if stop is not needed
*/ staticint idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q,
u32 descs_needed,
u32 bufs_needed)
{ /* Since we have multiple resources to check for splitq, our * start,stop_thrs becomes a boolean check instead of a count * threshold.
*/ if (netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx,
idpf_txq_has_room(tx_q, descs_needed,
bufs_needed),
1, 1)) return 0;
/** * idpf_tx_buf_hw_update - Store the new tail value * @tx_q: queue to bump * @val: new tail index * @xmit_more: more skb's pending * * The naming here is special in that 'hw' signals that this function is about * to do a register write to update our queue status. We know this can only * mean tail here as HW should be owning head for TX.
*/ void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val, bool xmit_more)
{ struct netdev_queue *nq;
/* Force memory writes to complete before letting h/w * know there are new descriptors to fetch. (Only * applicable for weak-ordered memory model archs, * such as IA-64).
*/
wmb();
/* notify HW of packet */ if (netif_xmit_stopped(nq) || !xmit_more)
writel(val, tx_q->tail);
}
/** * idpf_tx_res_count_required - get number of Tx resources needed for this pkt * @txq: queue to send buffer on * @skb: send buffer * @bufs_needed: (output) number of buffers needed for this skb. * * Return: number of data descriptors and buffers needed for this skb.
*/ unsignedint idpf_tx_res_count_required(struct idpf_tx_queue *txq, struct sk_buff *skb,
u32 *bufs_needed)
{ conststruct skb_shared_info *shinfo; unsignedint count = 0, i;
count += !!skb_headlen(skb);
if (!skb_is_nonlinear(skb)) return count;
shinfo = skb_shinfo(skb);
*bufs_needed += shinfo->nr_frags; for (i = 0; i < shinfo->nr_frags; i++) { unsignedint size;
size = skb_frag_size(&shinfo->frags[i]);
/* We only need to use the idpf_size_to_txd_count check if the * fragment is going to span multiple descriptors, * i.e. size >= 16K.
*/ if (size >= SZ_16K)
count += idpf_size_to_txd_count(size); else
count++;
}
if (idpf_chk_linearize(skb, txq->tx_max_bufs, count)) { if (__skb_linearize(skb)) return 0;
/** * idpf_tx_splitq_bump_ntu - adjust NTU and generation * @txq: the tx ring to wrap * @ntu: ring index to bump
*/ staticunsignedint idpf_tx_splitq_bump_ntu(struct idpf_tx_queue *txq, u16 ntu)
{
ntu++;
if (ntu == txq->desc_count)
ntu = 0;
return ntu;
}
/** * idpf_tx_get_free_buf_id - get a free buffer ID from the refill queue * @refillq: refill queue to get buffer ID from * @buf_id: return buffer ID * * Return: true if a buffer ID was found, false if not
*/ staticbool idpf_tx_get_free_buf_id(struct idpf_sw_queue *refillq,
u32 *buf_id)
{
u32 ntc = refillq->next_to_clean;
u32 refill_desc;
refill_desc = refillq->ring[ntc];
if (unlikely(idpf_queue_has(RFL_GEN_CHK, refillq) !=
!!(refill_desc & IDPF_RFL_BI_GEN_M))) returnfalse;
/* Update tail in case netdev_xmit_more was previously true. */
idpf_tx_buf_hw_update(txq, params->prev_ntu, false);
if (!refillq) return;
/* Restore refillq state to avoid leaking tags. */ if (params->prev_refill_gen != idpf_queue_has(RFL_GEN_CHK, refillq))
idpf_queue_change(RFL_GEN_CHK, refillq);
refillq->next_to_clean = params->prev_refill_ntc;
}
/** * idpf_tx_splitq_map - Build the Tx flex descriptor * @tx_q: queue to send buffer on * @params: pointer to splitq params struct * @first: first buffer info buffer to use * * This function loops over the skb data pointed to by *first * and gets a physical address for each memory location and programs * it and the length into the transmit flex descriptor.
*/ staticvoid idpf_tx_splitq_map(struct idpf_tx_queue *tx_q, struct idpf_tx_splitq_params *params, struct idpf_tx_buf *first)
{ union idpf_tx_flex_desc *tx_desc; unsignedint data_len, size; struct idpf_tx_buf *tx_buf;
u16 i = tx_q->next_to_use; struct netdev_queue *nq; struct sk_buff *skb;
skb_frag_t *frag;
u32 next_buf_id;
u16 td_cmd = 0;
dma_addr_t dma;
/* record length, and DMA address */
dma_unmap_len_set(tx_buf, len, size);
dma_unmap_addr_set(tx_buf, dma, dma);
/* buf_addr is in same location for both desc types */
tx_desc->q.buf_addr = cpu_to_le64(dma);
/* The stack can send us fragments that are too large for a * single descriptor i.e. frag size > 16K-1. We will need to * split the fragment across multiple descriptors in this case. * To adhere to HW alignment restrictions, the fragment needs * to be split such that the first chunk ends on a 4K boundary * and all subsequent chunks start on a 4K boundary. We still * want to send as much data as possible though, so our * intermediate descriptor chunk size will be 12K. * * For example, consider a 32K fragment mapped to DMA addr 2600. * ------------------------------------------------------------ * | frag_size = 32K | * ------------------------------------------------------------ * |2600 |16384 |28672 * * 3 descriptors will be used for this fragment. The HW expects * the descriptors to contain the following: * ------------------------------------------------------------ * | size = 13784 | size = 12K | size = 6696 | * | dma = 2600 | dma = 16384 | dma = 28672 | * ------------------------------------------------------------ * * We need to first adjust the max_data for the first chunk so * that it ends on a 4K boundary. By negating the value of the * DMA address and taking only the low order bits, we're * effectively calculating * 4K - (DMA addr lower order bits) = * bytes to next boundary. * * Add that to our base aligned max_data (12K) and we have * our first chunk size. In the example above, * 13784 = 12K + (4096-2600) * * After guaranteeing the first chunk ends on a 4K boundary, we * will give the intermediate descriptors 12K chunks and * whatever is left to the final descriptor. This ensures that * all descriptors used for the remaining chunks of the * fragment start on a 4K boundary and we use as few * descriptors as possible.
*/
max_data += -dma & (IDPF_TX_MAX_READ_REQ_SIZE - 1); while (unlikely(size > IDPF_TX_MAX_DESC_DATA)) {
idpf_tx_splitq_build_desc(tx_desc, params, td_cmd,
max_data);
if (unlikely(++i == tx_q->desc_count)) {
tx_desc = &tx_q->flex_tx[0];
i = 0;
} else {
tx_desc++;
}
/* Adjust the DMA offset and the remaining size of the * fragment. On the first iteration of this loop, * max_data will be >= 12K and <= 16K-1. On any * subsequent iteration of this loop, max_data will * always be 12K.
*/
dma += max_data;
size -= max_data;
/* Reset max_data since remaining chunks will be 12K * at most
*/
max_data = IDPF_TX_MAX_DESC_DATA_ALIGNED;
/* buf_addr is in same location for both desc types */
tx_desc->q.buf_addr = cpu_to_le64(dma);
}
/* record SW timestamp if HW timestamp is not available */
skb_tx_timestamp(skb);
first->type = LIBETH_SQE_SKB;
/* write last descriptor with RS and EOP bits */
first->rs_idx = i;
idpf_tx_buf_next(tx_buf) = IDPF_TXBUF_NULL;
td_cmd |= params->eop_cmd;
idpf_tx_splitq_build_desc(tx_desc, params, td_cmd, size);
i = idpf_tx_splitq_bump_ntu(tx_q, i);
tx_q->txq_grp->num_completions_pending++;
/* record bytecount for BQL */
nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
netdev_tx_sent_queue(nq, first->bytes);
idpf_tx_buf_hw_update(tx_q, i, netdev_xmit_more());
}
/** * idpf_tso - computes mss and TSO length to prepare for TSO * @skb: pointer to skb * @off: pointer to struct that holds offload parameters * * Returns error (negative) if TSO was requested but cannot be applied to the * given skb, 0 if TSO does not apply to the given skb, or 1 otherwise.
*/ int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off)
{ conststruct skb_shared_info *shinfo; union { struct iphdr *v4; struct ipv6hdr *v6; unsignedchar *hdr;
} ip; union { struct tcphdr *tcp; struct udphdr *udp; unsignedchar *hdr;
} l4;
u32 paylen, l4_start; int err;
if (!skb_is_gso(skb)) return 0;
err = skb_cow_head(skb, 0); if (err < 0) return err;
/** * idpf_tx_splitq_get_ctx_desc - grab next desc and update buffer ring * @txq: queue to put context descriptor on * * Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor
*/ staticunion idpf_flex_tx_ctx_desc *
idpf_tx_splitq_get_ctx_desc(struct idpf_tx_queue *txq)
{ union idpf_flex_tx_ctx_desc *desc; int i = txq->next_to_use;
/* grab the next descriptor */
desc = &txq->flex_ctx[i];
txq->next_to_use = idpf_tx_splitq_bump_ntu(txq, i);
return desc;
}
/** * idpf_tx_drop_skb - free the SKB and bump tail if necessary * @tx_q: queue to send buffer on * @skb: pointer to skb
*/
netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb)
{
u64_stats_update_begin(&tx_q->stats_sync);
u64_stats_inc(&tx_q->q_stats.skb_drops);
u64_stats_update_end(&tx_q->stats_sync);
#if (IS_ENABLED(CONFIG_PTP_1588_CLOCK)) /** * idpf_tx_tstamp - set up context descriptor for hardware timestamp * @tx_q: queue to send buffer on * @skb: pointer to the SKB we're sending * @off: pointer to the offload struct * * Return: Positive index number on success, negative otherwise.
*/ staticint idpf_tx_tstamp(struct idpf_tx_queue *tx_q, struct sk_buff *skb, struct idpf_tx_offload_params *off)
{ int err, idx;
/* only timestamp the outbound packet if the user has requested it */ if (likely(!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))) return -1;
if (!idpf_ptp_get_txq_tstamp_capability(tx_q)) return -1;
/* Tx timestamps cannot be sampled when doing TSO */ if (off->tx_flags & IDPF_TX_FLAGS_TSO) return -1;
/* Grab an open timestamp slot */
err = idpf_ptp_request_ts(tx_q, skb, &idx); if (err) {
u64_stats_update_begin(&tx_q->stats_sync);
u64_stats_inc(&tx_q->q_stats.tstamp_skipped);
u64_stats_update_end(&tx_q->stats_sync);
/** * idpf_tx_splitq_need_re - check whether RE bit needs to be set * @tx_q: pointer to Tx queue * * Return: true if RE bit needs to be set, false otherwise
*/ staticbool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q)
{ int gap = tx_q->next_to_use - tx_q->last_re;
gap += (gap < 0) ? tx_q->desc_count : 0;
return gap >= IDPF_TX_SPLITQ_RE_MIN_GAP;
}
/** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer * @tx_q: queue to send buffer on * * Returns NETDEV_TX_OK if sent, else an error code
*/ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q)
{ struct idpf_tx_splitq_params tx_params = {
.prev_ntu = tx_q->next_to_use,
}; union idpf_flex_tx_ctx_desc *ctx_desc; struct idpf_tx_buf *first;
u32 count, buf_count = 1; int tso, idx;
u32 buf_id;
count = idpf_tx_res_count_required(tx_q, skb, &buf_count); if (unlikely(!count)) return idpf_tx_drop_skb(tx_q, skb);
if (idpf_queue_has(FLOW_SCH_EN, tx_q)) { struct idpf_sw_queue *refillq = tx_q->refillq;
/* Save refillq state in case of a packet rollback. Otherwise, * the tags will be leaked since they will be popped from the * refillq but never reposted during cleaning.
*/
tx_params.prev_refill_gen =
idpf_queue_has(RFL_GEN_CHK, refillq);
tx_params.prev_refill_ntc = refillq->next_to_clean;
if (unlikely(!idpf_tx_get_free_buf_id(tx_q->refillq,
&buf_id))) { if (tx_params.prev_refill_gen !=
idpf_queue_has(RFL_GEN_CHK, refillq))
idpf_queue_change(RFL_GEN_CHK, refillq);
refillq->next_to_clean = tx_params.prev_refill_ntc;
tx_params.dtype = IDPF_TX_DESC_DTYPE_FLEX_FLOW_SCHE;
tx_params.eop_cmd = IDPF_TXD_FLEX_FLOW_CMD_EOP; /* Set the RE bit to periodically "clean" the descriptor ring. * MIN_GAP is set to MIN_RING size to ensure it will be set at * least once each time around the ring.
*/ if (idpf_tx_splitq_need_re(tx_q)) {
tx_params.eop_cmd |= IDPF_TXD_FLEX_FLOW_CMD_RE;
tx_q->txq_grp->num_completions_pending++;
tx_q->last_re = tx_q->next_to_use;
}
if (skb->ip_summed == CHECKSUM_PARTIAL)
tx_params.offload.td_cmd |= IDPF_TXD_FLEX_FLOW_CMD_CS_EN;
/** * idpf_tx_start - Selects the right Tx queue to send buffer * @skb: send buffer * @netdev: network interface device structure * * Returns NETDEV_TX_OK if sent, else an error code
*/
netdev_tx_t idpf_tx_start(struct sk_buff *skb, struct net_device *netdev)
{ struct idpf_vport *vport = idpf_netdev_to_vport(netdev); struct idpf_tx_queue *tx_q;
if (unlikely(skb_get_queue_mapping(skb) >= vport->num_txq)) {
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
tx_q = vport->txqs[skb_get_queue_mapping(skb)];
/* hardware can't handle really short frames, hardware padding works * beyond this point
*/ if (skb_put_padto(skb, tx_q->tx_min_pkt_len)) {
idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false);
return NETDEV_TX_OK;
}
if (idpf_is_queue_model_split(vport->txq_model)) return idpf_tx_splitq_frame(skb, tx_q); else return idpf_tx_singleq_frame(skb, tx_q);
}
/** * idpf_rx_hash - set the hash value in the skb * @rxq: Rx descriptor ring packet is being transacted on * @skb: pointer to current skb being populated * @rx_desc: Receive descriptor * @decoded: Decoded Rx packet type related fields
*/ staticvoid
idpf_rx_hash(conststruct idpf_rx_queue *rxq, struct sk_buff *skb, conststruct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, struct libeth_rx_pt decoded)
{
u32 hash;
if (!libeth_rx_pt_has_hash(rxq->netdev, decoded)) return;
/** * idpf_rx_csum - Indicate in skb if checksum is good * @rxq: Rx descriptor ring packet is being transacted on * @skb: pointer to current skb being populated * @csum_bits: checksum fields extracted from the descriptor * @decoded: Decoded Rx packet type related fields * * skb->protocol must be set before this function is called
*/ staticvoid idpf_rx_csum(struct idpf_rx_queue *rxq, struct sk_buff *skb, struct libeth_rx_csum csum_bits, struct libeth_rx_pt decoded)
{ bool ipv4, ipv6;
/* check if Rx checksum is enabled */ if (!libeth_rx_pt_has_checksum(rxq->netdev, decoded)) return;
/* check if HW has decoded the packet and checksum */ if (unlikely(!csum_bits.l3l4p)) return;
/** * idpf_rx_rsc - Set the RSC fields in the skb * @rxq : Rx descriptor ring packet is being transacted on * @skb : pointer to current skb being populated * @rx_desc: Receive descriptor * @decoded: Decoded Rx packet type related fields * * Return 0 on success and error code on failure * * Populate the skb fields with the total number of RSC segments, RSC payload * length and packet type.
*/ staticint idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb, conststruct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, struct libeth_rx_pt decoded)
{
u16 rsc_segments, rsc_seg_len; bool ipv4, ipv6; int len;
if (unlikely(libeth_rx_pt_get_ip_ver(decoded) ==
LIBETH_RX_PT_OUTER_L2)) return -EINVAL;
rsc_seg_len = le16_to_cpu(rx_desc->misc.rscseglen); if (unlikely(!rsc_seg_len)) return -EINVAL;
/** * idpf_rx_hwtstamp - check for an RX timestamp and pass up the stack * @rxq: pointer to the rx queue that receives the timestamp * @rx_desc: pointer to rx descriptor containing timestamp * @skb: skb to put timestamp in
*/ staticvoid
idpf_rx_hwtstamp(conststruct idpf_rx_queue *rxq, conststruct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, struct sk_buff *skb)
{
u64 cached_time, ts_ns;
u32 ts_high;
if (!(rx_desc->ts_low & VIRTCHNL2_RX_FLEX_TSTAMP_VALID)) return;
/** * idpf_rx_process_skb_fields - Populate skb header fields from Rx descriptor * @rxq: Rx descriptor ring packet is being transacted on * @skb: pointer to current skb being populated * @rx_desc: Receive descriptor * * This function checks the ring, descriptor, and packet information in * order to populate the hash, checksum, protocol, and * other fields within the skb.
*/ staticint
idpf_rx_process_skb_fields(struct idpf_rx_queue *rxq, struct sk_buff *skb, conststruct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
{ struct libeth_rx_csum csum_bits; struct libeth_rx_pt decoded;
u16 rx_ptype;
/** * idpf_rx_add_frag - Add contents of Rx buffer to sk_buff as a frag * @rx_buf: buffer containing page to add * @skb: sk_buff to place the data into * @size: packet length from rx_desc * * This function will add the data contained in rx_buf->page to the skb. * It will just attach the page as a frag to the skb. * The function will then update the page offset.
*/ void idpf_rx_add_frag(struct idpf_rx_buf *rx_buf, struct sk_buff *skb, unsignedint size)
{
u32 hr = netmem_get_pp(rx_buf->netmem)->p.offset;
/** * idpf_rx_hsplit_wa - handle header buffer overflows and split errors * @hdr: Rx buffer for the headers * @buf: Rx buffer for the payload * @data_len: number of bytes received to the payload buffer * * When a header buffer overflow occurs or the HW was unable do parse the * packet type to perform header split, the whole frame gets placed to the * payload buffer. We can't build a valid skb around a payload buffer when * the header split is active since it doesn't reserve any head- or tailroom. * In that case, copy either the whole frame when it's short or just the * Ethernet header to the header buffer to be able to build an skb and adjust * the data offset in the payload buffer, IOW emulate the header split. * * Return: number of bytes copied to the header buffer.
*/ static u32 idpf_rx_hsplit_wa(conststruct libeth_fqe *hdr, struct libeth_fqe *buf, u32 data_len)
{
u32 copy = data_len <= L1_CACHE_BYTES ? data_len : ETH_HLEN; struct page *hdr_page, *buf_page; constvoid *src; void *dst;
if (unlikely(netmem_is_net_iov(buf->netmem)) ||
!libeth_rx_sync_for_cpu(buf, copy)) return 0;
/** * idpf_rx_build_skb - Allocate skb and populate it from header buffer * @buf: Rx buffer to pull data from * @size: the length of the packet * * This function allocates an skb. It then populates it with the page data from * the current receive descriptor, taking care to set up the skb correctly.
*/ struct sk_buff *idpf_rx_build_skb(conststruct libeth_fqe *buf, u32 size)
{ struct page *buf_page = __netmem_to_page(buf->netmem);
u32 hr = pp_page_to_nmdesc(buf_page)->pp->p.offset; struct sk_buff *skb; void *va;
va = page_address(buf_page) + buf->offset;
prefetch(va + hr);
skb = napi_build_skb(va, buf->truesize); if (unlikely(!skb)) return NULL;
skb_mark_for_recycle(skb);
skb_reserve(skb, hr);
__skb_put(skb, size);
return skb;
}
/** * idpf_rx_splitq_test_staterr - tests bits in Rx descriptor * status and error fields * @stat_err_field: field from descriptor to test bits in * @stat_err_bits: value to mask *
*/ staticbool idpf_rx_splitq_test_staterr(const u8 stat_err_field, const u8 stat_err_bits)
{ return !!(stat_err_field & stat_err_bits);
}
/** * idpf_rx_splitq_is_eop - process handling of EOP buffers * @rx_desc: Rx descriptor for current buffer * * If the buffer is an EOP buffer, this function exits returning true, * otherwise return false indicating that this is in fact a non-EOP buffer.
*/ staticbool idpf_rx_splitq_is_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
{ /* if we are the last buffer then there is nothing else to do */ return likely(idpf_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
IDPF_RXD_EOF_SPLITQ));
}
/** * idpf_rx_splitq_clean - Clean completed descriptors from Rx queue * @rxq: Rx descriptor queue to retrieve receive buffer queue * @budget: Total limit on number of packets to process * * This function provides a "bounce buffer" approach to Rx interrupt * processing. The advantage to this is that on systems that have * expensive overhead for IOMMU access this provides a means of avoiding * it by maintaining the mapping of the page to the system. * * Returns amount of work completed
*/ staticint idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
{ int total_rx_bytes = 0, total_rx_pkts = 0; struct idpf_buf_queue *rx_bufq = NULL; struct sk_buff *skb = rxq->skb;
u16 ntc = rxq->next_to_clean;
/* get the Rx desc from Rx queue based on 'next_to_clean' */
rx_desc = &rxq->rx[ntc].flex_adv_nic_3_wb;
/* if the descriptor isn't done, no work yet to do */
gen_id = le16_get_bits(rx_desc->pktlen_gen_bufq_id,
VIRTCHNL2_RX_FLEX_DESC_ADV_GEN_M); if (idpf_queue_has(GEN_CHK, rxq) != gen_id) break;
/* retrieve buffer from the rxq */
rx_bufq = &rxq->bufq_sets[bufq_id].bufq;
buf_id = le16_to_cpu(rx_desc->buf_id);
rx_buf = &rx_bufq->buf[buf_id];
if (!rx_bufq->hdr_pp) goto payload;
#define __HBO_BIT VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_M #define __HDR_LEN_MASK VIRTCHNL2_RX_FLEX_DESC_ADV_LEN_HDR_M if (likely(!(rx_desc->status_err0_qw1 & __HBO_BIT))) /* If a header buffer overflow, occurs, i.e. header is * too large to fit in the header split buffer, HW will * put the entire packet, including headers, in the * data/payload buffer.
*/
hdr_len = le16_get_bits(rx_desc->hdrlen_flags,
__HDR_LEN_MASK); #undef __HDR_LEN_MASK #undef __HBO_BIT
hdr = &rx_bufq->hdr_buf[buf_id];
if (unlikely(!hdr_len && !skb)) {
hdr_len = idpf_rx_hsplit_wa(hdr, rx_buf, pkt_len); /* If failed, drop both buffers by setting len to 0 */
pkt_len -= hdr_len ? : pkt_len;
addr = libeth_rx_alloc(&fq, buf_id); if (addr == DMA_MAPPING_ERROR) return -ENOMEM;
buf_desc->hdr_addr = cpu_to_le64(addr);
return 0;
}
/** * idpf_rx_clean_refillq - Clean refill queue buffers * @bufq: buffer queue to post buffers back to * @refillq: refill queue to clean * * This function takes care of the buffer refill management
*/ staticvoid idpf_rx_clean_refillq(struct idpf_buf_queue *bufq, struct idpf_sw_queue *refillq)
{ struct virtchnl2_splitq_rx_buf_desc *buf_desc;
u16 bufq_nta = bufq->next_to_alloc;
u16 ntc = refillq->next_to_clean; int cleaned = 0;
buf_desc = &bufq->split_buf[bufq_nta];
/* make sure we stop at ring wrap in the unlikely case ring is full */ while (likely(cleaned < refillq->desc_count)) {
u32 buf_id, refill_desc = refillq->ring[ntc]; bool failure;
if (idpf_queue_has(RFL_GEN_CHK, refillq) !=
!!(refill_desc & IDPF_RFL_BI_GEN_M)) break;
/* We want to limit how many transactions on the bus we trigger with * tail writes so we only do it in strides. It's also important we * align the write to a multiple of 8 as required by HW.
*/ if (((bufq->next_to_use <= bufq_nta ? 0 : bufq->desc_count) +
bufq_nta - bufq->next_to_use) >= IDPF_RX_BUF_POST_STRIDE)
idpf_rx_buf_hw_update(bufq, ALIGN_DOWN(bufq_nta,
IDPF_RX_BUF_POST_STRIDE));
/* update next to alloc since we have filled the ring */
refillq->next_to_clean = ntc;
bufq->next_to_alloc = bufq_nta;
}
/** * idpf_rx_clean_refillq_all - Clean all refill queues * @bufq: buffer queue with refill queues * @nid: ID of the closest NUMA node with memory * * Iterates through all refill queues assigned to the buffer queue assigned to * this vector. Returns true if clean is complete within budget, false * otherwise.
*/ staticvoid idpf_rx_clean_refillq_all(struct idpf_buf_queue *bufq, int nid)
{ struct idpf_bufq_set *bufq_set; int i;
page_pool_nid_changed(bufq->pp, nid); if (bufq->hdr_pp)
page_pool_nid_changed(bufq->hdr_pp, nid);
bufq_set = container_of(bufq, struct idpf_bufq_set, bufq); for (i = 0; i < bufq_set->num_refillqs; i++)
idpf_rx_clean_refillq(bufq, &bufq_set->refillqs[i]);
}
/** * idpf_vport_intr_napi_del_all - Unregister napi for all q_vectors in vport * @vport: virtual port structure *
*/ staticvoid idpf_vport_intr_napi_del_all(struct idpf_vport *vport)
{
u16 v_idx;
for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++)
netif_napi_del(&vport->q_vectors[v_idx].napi);
}
/** * idpf_vport_intr_napi_dis_all - Disable NAPI for all q_vectors in the vport * @vport: main vport structure
*/ staticvoid idpf_vport_intr_napi_dis_all(struct idpf_vport *vport)
{ int v_idx;
for (v_idx = 0; v_idx < vport->num_q_vectors; v_idx++)
napi_disable(&vport->q_vectors[v_idx].napi);
}
/** * idpf_vport_intr_rel - Free memory allocated for interrupt vectors * @vport: virtual port * * Free the memory allocated for interrupt vectors associated to a vport
*/ void idpf_vport_intr_rel(struct idpf_vport *vport)
{ for (u32 v_idx = 0; v_idx < vport->num_q_vectors; v_idx++) { struct idpf_q_vector *q_vector = &vport->q_vectors[v_idx];
for (u32 i = 0; i < q_vector->num_rxq; i++)
netif_queue_set_napi(dev, q_vector->rx[i]->idx,
NETDEV_QUEUE_TYPE_RX, napi);
for (u32 i = 0; i < q_vector->num_txq; i++)
netif_queue_set_napi(dev, q_vector->tx[i]->idx,
NETDEV_QUEUE_TYPE_TX, napi);
}
/** * idpf_vport_intr_rel_irq - Free the IRQ association with the OS * @vport: main vport structure
*/ staticvoid idpf_vport_intr_rel_irq(struct idpf_vport *vport)
{ struct idpf_adapter *adapter = vport->adapter; int vector;
for (vector = 0; vector < vport->num_q_vectors; vector++) { struct idpf_q_vector *q_vector = &vport->q_vectors[vector]; int irq_num, vidx;
/* free only the irqs that were actually requested */ if (!q_vector) continue;
if (q_vector->wb_on_itr) { /* * Trigger a software interrupt when exiting wb_on_itr, to make * sure we catch any pending write backs that might have been * missed due to interrupt state transition.
*/
itr_val |= q_vector->intr_reg.dyn_ctl_swint_trig_m |
q_vector->intr_reg.dyn_ctl_sw_itridx_ena_m;
type = IDPF_SW_ITR_UPDATE_IDX;
itr = IDPF_ITR_20K;
}
itr &= IDPF_ITR_MASK; /* Don't clear PBA because that can cause lost interrupts that * came in while we were cleaning/polling
*/
itr_val |= (type << q_vector->intr_reg.dyn_ctl_itridx_s) |
(itr << (q_vector->intr_reg.dyn_ctl_intrvl_s - 1));
return itr_val;
}
/** * idpf_update_dim_sample - Update dim sample with packets and bytes * @q_vector: the vector associated with the interrupt * @dim_sample: dim sample to update * @dim: dim instance structure * @packets: total packets * @bytes: total bytes * * Update the dim sample with the packets and bytes which are passed to this * function. Set the dim state appropriately if the dim settings gets stale.
*/ staticvoid idpf_update_dim_sample(struct idpf_q_vector *q_vector, struct dim_sample *dim_sample, struct dim *dim, u64 packets, u64 bytes)
{
dim_update_sample(q_vector->total_events, packets, bytes, dim_sample);
dim_sample->comp_ctr = 0;
/* if dim settings get stale, like when not updated for 1 second or * longer, force it to start again. This addresses the frequent case * of an idle queue being switched to by the scheduler.
*/ if (ktime_ms_delta(dim_sample->time, dim->start_sample.time) >= HZ)
dim->state = DIM_START_MEASURE;
}
/** * idpf_net_dim - Update net DIM algorithm * @q_vector: the vector associated with the interrupt * * Create a DIM sample and notify net_dim() so that it can possibly decide * a new ITR value based on incoming packets, bytes, and interrupts. * * This function is a no-op if the queue is not configured to dynamic ITR.
*/ staticvoid idpf_net_dim(struct idpf_q_vector *q_vector)
{ struct dim_sample dim_sample = { };
u64 packets, bytes;
u32 i;
if (!IDPF_ITR_IS_DYNAMIC(q_vector->tx_intr_mode)) goto check_rx_itr;
for (i = 0, packets = 0, bytes = 0; i < q_vector->num_txq; i++) { struct idpf_tx_queue *txq = q_vector->tx[i]; unsignedint start;
do {
start = u64_stats_fetch_begin(&txq->stats_sync);
packets += u64_stats_read(&txq->q_stats.packets);
bytes += u64_stats_read(&txq->q_stats.bytes);
} while (u64_stats_fetch_retry(&txq->stats_sync, start));
}
/** * idpf_vport_intr_update_itr_ena_irq - Update itr and re-enable MSIX interrupt * @q_vector: q_vector for which itr is being updated and interrupt enabled * * Update the net_dim() algorithm and re-enable the interrupt associated with * this vector.
*/ void idpf_vport_intr_update_itr_ena_irq(struct idpf_q_vector *q_vector)
{
u32 intval;
/* net_dim() updates ITR out-of-band using a work item */
idpf_net_dim(q_vector);
/** * idpf_vport_intr_req_irq - get MSI-X vectors from the OS for the vport * @vport: main vport structure
*/ staticint idpf_vport_intr_req_irq(struct idpf_vport *vport)
{ struct idpf_adapter *adapter = vport->adapter; constchar *drv_name, *if_name, *vec_name; int vector, err, irq_num, vidx;
/** * idpf_vport_intr_napi_ena_all - Enable NAPI for all q_vectors in the vport * @vport: main vport structure
*/ staticvoid idpf_vport_intr_napi_ena_all(struct idpf_vport *vport)
{ int q_idx;
/** * idpf_tx_splitq_clean_all- Clean completion queues * @q_vec: queue vector * @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * * Returns false if clean is not complete else returns true
*/ staticbool idpf_tx_splitq_clean_all(struct idpf_q_vector *q_vec, int budget, int *cleaned)
{
u16 num_complq = q_vec->num_complq; bool clean_complete = true; int i, budget_per_q;
if (unlikely(!num_complq)) returntrue;
budget_per_q = DIV_ROUND_UP(budget, num_complq);
for (i = 0; i < num_complq; i++)
clean_complete &= idpf_tx_clean_complq(q_vec->complq[i],
budget_per_q, cleaned);
return clean_complete;
}
/** * idpf_rx_splitq_clean_all- Clean completion queues * @q_vec: queue vector * @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * * Returns false if clean is not complete else returns true
*/ staticbool idpf_rx_splitq_clean_all(struct idpf_q_vector *q_vec, int budget, int *cleaned)
{
u16 num_rxq = q_vec->num_rxq; bool clean_complete = true; int pkts_cleaned = 0; int i, budget_per_q; int nid;
/* We attempt to distribute budget to each Rx queue fairly, but don't * allow the budget to go below 1 because that would exit polling early.
*/
budget_per_q = num_rxq ? max(budget / num_rxq, 1) : 0; for (i = 0; i < num_rxq; i++) { struct idpf_rx_queue *rxq = q_vec->rx[i]; int pkts_cleaned_per_q;
pkts_cleaned_per_q = idpf_rx_splitq_clean(rxq, budget_per_q); /* if we clean as many as budgeted, we must not be done */ if (pkts_cleaned_per_q >= budget_per_q)
clean_complete = false;
pkts_cleaned += pkts_cleaned_per_q;
}
*cleaned = pkts_cleaned;
nid = numa_mem_id();
for (i = 0; i < q_vec->num_bufq; i++)
idpf_rx_clean_refillq_all(q_vec->bufq[i], nid);
return clean_complete;
}
/** * idpf_vport_splitq_napi_poll - NAPI handler * @napi: struct from which you get q_vector * @budget: budget provided by stack
*/ staticint idpf_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
{ struct idpf_q_vector *q_vector =
container_of(napi, struct idpf_q_vector, napi); bool clean_complete; int work_done = 0;
/* Handle case where we are called by netpoll with a budget of 0 */ if (unlikely(!budget)) {
idpf_tx_splitq_clean_all(q_vector, budget, &work_done);
/* If work not completed, return budget and polling will return */ if (!clean_complete) {
idpf_vport_intr_set_wb_on_itr(q_vector); return budget;
}
/* Switch to poll mode in the tear-down path after sending disable * queues virtchnl message, as the interrupts will be disabled after * that.
*/ if (unlikely(q_vector->num_txq && idpf_queue_has(POLL_MODE,
q_vector->tx[0]))) return budget;
work_done = min_t(int, work_done, budget - 1);
/* Exit the polling mode, but don't re-enable interrupts if stack might * poll us due to busy-polling
*/ if (likely(napi_complete_done(napi, work_done)))
idpf_vport_intr_update_itr_ena_irq(q_vector); else
idpf_vport_intr_set_wb_on_itr(q_vector);
return work_done;
}
/** * idpf_vport_intr_map_vector_to_qs - Map vectors to queues * @vport: virtual port * * Mapping for vectors to queues
*/ staticvoid idpf_vport_intr_map_vector_to_qs(struct idpf_vport *vport)
{ bool split = idpf_is_queue_model_split(vport->rxq_model);
u16 num_txq_grp = vport->num_txq_grp; struct idpf_rxq_group *rx_qgrp; struct idpf_txq_group *tx_qgrp;
u32 i, qv_idx, q_index;
for (i = 0, qv_idx = 0; i < vport->num_rxq_grp; i++) {
u16 num_rxq;
for (i = 0; i < vport->num_q_vectors; i++)
vport->q_vectors[i].v_idx = vecids[vport->q_vector_idxs[i]];
kfree(vecids);
return 0;
}
/** * idpf_vport_intr_napi_add_all- Register napi handler for all qvectors * @vport: virtual port structure
*/ staticvoid idpf_vport_intr_napi_add_all(struct idpf_vport *vport)
{ int (*napi_poll)(struct napi_struct *napi, int budget);
u16 v_idx, qv_idx; int irq_num;
if (idpf_is_queue_model_split(vport->txq_model))
napi_poll = idpf_vport_splitq_napi_poll; else
napi_poll = idpf_vport_singleq_napi_poll;
q_vector->tx = kcalloc(txqs_per_vector, sizeof(*q_vector->tx),
GFP_KERNEL); if (!q_vector->tx) goto error;
q_vector->rx = kcalloc(rxqs_per_vector, sizeof(*q_vector->rx),
GFP_KERNEL); if (!q_vector->rx) goto error;
if (!idpf_is_queue_model_split(vport->rxq_model)) continue;
q_vector->bufq = kcalloc(bufqs_per_vector, sizeof(*q_vector->bufq),
GFP_KERNEL); if (!q_vector->bufq) goto error;
q_vector->complq = kcalloc(complqs_per_vector, sizeof(*q_vector->complq),
GFP_KERNEL); if (!q_vector->complq) goto error;
}
return 0;
error:
idpf_vport_intr_rel(vport);
return -ENOMEM;
}
/** * idpf_vport_intr_init - Setup all vectors for the given vport * @vport: virtual port * * Returns 0 on success or negative on failure
*/ int idpf_vport_intr_init(struct idpf_vport *vport)
{ int err;
err = idpf_vport_intr_init_vec_idx(vport); if (err) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.