X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fbnxt%2Fbnxt_rxr.c;h=fdbe6f71eaa89026adc5991dfee06b918bff39f9;hb=a2999c7bfe395708a6a68ebb6f3199af7d25cffe;hp=5673e2b50feab62ef294673b289e1b1282606b26;hpb=04067844a3e9a058478f50eb61e391846e167865;p=dpdk.git diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c index 5673e2b50f..fdbe6f71ea 100644 --- a/drivers/net/bnxt/bnxt_rxr.c +++ b/drivers/net/bnxt/bnxt_rxr.c @@ -150,6 +150,7 @@ static void bnxt_tpa_start(struct bnxt_rx_queue *rxq, tpa_info->mbuf = mbuf; tpa_info->len = rte_le_to_cpu_32(tpa_start->len); + mbuf->data_off = RTE_PKTMBUF_HEADROOM; mbuf->nb_segs = 1; mbuf->next = NULL; mbuf->pkt_len = rte_le_to_cpu_32(tpa_start->len); @@ -305,7 +306,6 @@ static inline struct rte_mbuf *bnxt_tpa_end( mbuf = tpa_info->mbuf; RTE_ASSERT(mbuf != NULL); - rte_prefetch0(mbuf); if (agg_bufs) { bnxt_rx_pages(rxq, mbuf, raw_cp_cons, agg_bufs, tpa_info); } @@ -322,62 +322,177 @@ static inline struct rte_mbuf *bnxt_tpa_end( return mbuf; } +uint32_t bnxt_ptype_table[BNXT_PTYPE_TBL_DIM] __rte_cache_aligned; + +static void __rte_cold +bnxt_init_ptype_table(void) +{ + uint32_t *pt = bnxt_ptype_table; + static bool initialized; + int ip6, tun, type; + uint32_t l3; + int i; + + if (initialized) + return; + + for (i = 0; i < BNXT_PTYPE_TBL_DIM; i++) { + if (i & (RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN >> 2)) + pt[i] = RTE_PTYPE_L2_ETHER_VLAN; + else + pt[i] = RTE_PTYPE_L2_ETHER; + + ip6 = i & (RX_PKT_CMPL_FLAGS2_IP_TYPE >> 7); + tun = i & (RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC >> 2); + type = (i & 0x38) << 9; + + if (!tun && !ip6) + l3 = RTE_PTYPE_L3_IPV4_EXT_UNKNOWN; + else if (!tun && ip6) + l3 = RTE_PTYPE_L3_IPV6_EXT_UNKNOWN; + else if (tun && !ip6) + l3 = RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN; + else + l3 = RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN; + + switch (type) { + case RX_PKT_CMPL_FLAGS_ITYPE_ICMP: + if (tun) + pt[i] |= l3 | RTE_PTYPE_INNER_L4_ICMP; + else + pt[i] |= l3 | RTE_PTYPE_L4_ICMP; + break; + case RX_PKT_CMPL_FLAGS_ITYPE_TCP: + if (tun) + pt[i] |= l3 | RTE_PTYPE_INNER_L4_TCP; + else + pt[i] |= l3 | RTE_PTYPE_L4_TCP; + break; + case RX_PKT_CMPL_FLAGS_ITYPE_UDP: + if (tun) + pt[i] |= l3 | RTE_PTYPE_INNER_L4_UDP; + else + pt[i] |= l3 | RTE_PTYPE_L4_UDP; + break; + case RX_PKT_CMPL_FLAGS_ITYPE_IP: + pt[i] |= l3; + break; + } + } + initialized = true; +} + static uint32_t bnxt_parse_pkt_type(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1) { - uint32_t l3, pkt_type = 0; - uint32_t t_ipcs = 0, ip6 = 0, vlan = 0; - uint32_t flags_type; - - vlan = !!(rxcmp1->flags2 & - rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN)); - pkt_type |= vlan ? RTE_PTYPE_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER; - - t_ipcs = !!(rxcmp1->flags2 & - rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC)); - ip6 = !!(rxcmp1->flags2 & - rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_IP_TYPE)); - - flags_type = rxcmp->flags_type & - rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS_ITYPE_MASK); - - if (!t_ipcs && !ip6) - l3 = RTE_PTYPE_L3_IPV4_EXT_UNKNOWN; - else if (!t_ipcs && ip6) - l3 = RTE_PTYPE_L3_IPV6_EXT_UNKNOWN; - else if (t_ipcs && !ip6) - l3 = RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN; - else - l3 = RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN; + uint32_t flags_type, flags2; + uint8_t index; - switch (flags_type) { - case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_ICMP): - if (!t_ipcs) - pkt_type |= l3 | RTE_PTYPE_L4_ICMP; - else - pkt_type |= l3 | RTE_PTYPE_INNER_L4_ICMP; - break; + flags_type = rte_le_to_cpu_16(rxcmp->flags_type); + flags2 = rte_le_to_cpu_32(rxcmp1->flags2); - case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_TCP): - if (!t_ipcs) - pkt_type |= l3 | RTE_PTYPE_L4_TCP; - else - pkt_type |= l3 | RTE_PTYPE_INNER_L4_TCP; - break; + /* + * Index format: + * bit 0: RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC + * bit 1: RX_CMPL_FLAGS2_IP_TYPE + * bit 2: RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN + * bits 3-6: RX_PKT_CMPL_FLAGS_ITYPE + */ + index = ((flags_type & RX_PKT_CMPL_FLAGS_ITYPE_MASK) >> 9) | + ((flags2 & (RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN | + RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC)) >> 2) | + ((flags2 & RX_PKT_CMPL_FLAGS2_IP_TYPE) >> 7); - case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_UDP): - if (!t_ipcs) - pkt_type |= l3 | RTE_PTYPE_L4_UDP; - else - pkt_type |= l3 | RTE_PTYPE_INNER_L4_UDP; - break; + return bnxt_ptype_table[index]; +} - case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_IP): - pkt_type |= l3; - break; +uint32_t +bnxt_ol_flags_table[BNXT_OL_FLAGS_TBL_DIM] __rte_cache_aligned; + +uint32_t +bnxt_ol_flags_err_table[BNXT_OL_FLAGS_ERR_TBL_DIM] __rte_cache_aligned; + +static void __rte_cold +bnxt_init_ol_flags_tables(void) +{ + static bool initialized; + uint32_t *pt; + int i; + + if (initialized) + return; + + /* Initialize ol_flags table. */ + pt = bnxt_ol_flags_table; + for (i = 0; i < BNXT_OL_FLAGS_TBL_DIM; i++) { + pt[i] = 0; + if (i & RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN) + pt[i] |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED; + + if (i & RX_PKT_CMPL_FLAGS2_IP_CS_CALC) + pt[i] |= PKT_RX_IP_CKSUM_GOOD; + + if (i & RX_PKT_CMPL_FLAGS2_L4_CS_CALC) + pt[i] |= PKT_RX_L4_CKSUM_GOOD; + + if (i & RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC) + pt[i] |= PKT_RX_OUTER_L4_CKSUM_GOOD; + } + + /* Initialize checksum error table. */ + pt = bnxt_ol_flags_err_table; + for (i = 0; i < BNXT_OL_FLAGS_ERR_TBL_DIM; i++) { + pt[i] = 0; + if (i & (RX_PKT_CMPL_ERRORS_IP_CS_ERROR >> 4)) + pt[i] |= PKT_RX_IP_CKSUM_BAD; + + if (i & (RX_PKT_CMPL_ERRORS_L4_CS_ERROR >> 4)) + pt[i] |= PKT_RX_L4_CKSUM_BAD; + + if (i & (RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR >> 4)) + pt[i] |= PKT_RX_EIP_CKSUM_BAD; + + if (i & (RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR >> 4)) + pt[i] |= PKT_RX_OUTER_L4_CKSUM_BAD; + } + + initialized = true; +} + +static void +bnxt_set_ol_flags(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1, + struct rte_mbuf *mbuf) +{ + uint16_t flags_type, errors, flags; + uint64_t ol_flags; + + flags_type = rte_le_to_cpu_16(rxcmp->flags_type); + + flags = rte_le_to_cpu_32(rxcmp1->flags2) & + (RX_PKT_CMPL_FLAGS2_IP_CS_CALC | + RX_PKT_CMPL_FLAGS2_L4_CS_CALC | + RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC | + RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC | + RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN); + + errors = rte_le_to_cpu_16(rxcmp1->errors_v2) & + (RX_PKT_CMPL_ERRORS_IP_CS_ERROR | + RX_PKT_CMPL_ERRORS_L4_CS_ERROR | + RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR | + RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR); + errors = (errors >> 4) & flags; + + ol_flags = bnxt_ol_flags_table[flags & ~errors]; + + if (errors) + ol_flags |= bnxt_ol_flags_err_table[errors]; + + if (flags_type & RX_PKT_CMPL_FLAGS_RSS_VALID) { + mbuf->hash.rss = rte_le_to_cpu_32(rxcmp->rss_hash); + ol_flags |= PKT_RX_RSS_HASH; } - return pkt_type; + mbuf->ol_flags = ol_flags; } #ifdef RTE_LIBRTE_IEEE1588 @@ -491,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1, return mark_id; /* Got the mark, write it to the mbuf and return */ mbuf->hash.fdir.hi = mark_id; - mbuf->udata64 = (cfa_code & 0xffffffffull) << 32; + *bnxt_cfa_code_dynfield(mbuf) = cfa_code & 0xffffffffull; mbuf->hash.fdir.id = rxcmp1->cfa_code; mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID; return mark_id; @@ -557,8 +672,7 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, int rc = 0; uint8_t agg_buf = 0; uint16_t cmp_type; - uint32_t flags2_f = 0, vfr_flag = 0, mark_id = 0; - uint16_t flags_type; + uint32_t vfr_flag = 0, mark_id = 0; struct bnxt *bp = rxq->bp; rxcmp = (struct rx_pkt_cmpl *) @@ -619,21 +733,23 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, if (mbuf == NULL) return -EBUSY; - rte_prefetch0(mbuf); - mbuf->data_off = RTE_PKTMBUF_HEADROOM; mbuf->nb_segs = 1; mbuf->next = NULL; mbuf->pkt_len = rxcmp->len; mbuf->data_len = mbuf->pkt_len; mbuf->port = rxq->port_id; - mbuf->ol_flags = 0; - flags_type = rte_le_to_cpu_16(rxcmp->flags_type); - if (flags_type & RX_PKT_CMPL_FLAGS_RSS_VALID) { - mbuf->hash.rss = rxcmp->rss_hash; - mbuf->ol_flags |= PKT_RX_RSS_HASH; + bnxt_set_ol_flags(rxcmp, rxcmp1, mbuf); + +#ifdef RTE_LIBRTE_IEEE1588 + if (unlikely((rte_le_to_cpu_16(rxcmp->flags_type) & + RX_PKT_CMPL_FLAGS_MASK) == + RX_PKT_CMPL_FLAGS_ITYPE_PTP_W_TIMESTAMP)) { + mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | PKT_RX_IEEE1588_TMST; + bnxt_get_rx_ts_thor(rxq->bp, rxcmp1->reorder); } +#endif if (BNXT_TRUFLOW_EN(bp)) mark_id = bnxt_ulp_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf, @@ -641,66 +757,9 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, else bnxt_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf); -#ifdef RTE_LIBRTE_IEEE1588 - if (unlikely((flags_type & RX_PKT_CMPL_FLAGS_MASK) == - RX_PKT_CMPL_FLAGS_ITYPE_PTP_W_TIMESTAMP)) { - mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | PKT_RX_IEEE1588_TMST; - bnxt_get_rx_ts_thor(rxq->bp, rxcmp1->reorder); - } -#endif if (agg_buf) bnxt_rx_pages(rxq, mbuf, &tmp_raw_cons, agg_buf, NULL); - if (rxcmp1->flags2 & RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN) { - mbuf->vlan_tci = rxcmp1->metadata & - (RX_PKT_CMPL_METADATA_VID_MASK | - RX_PKT_CMPL_METADATA_DE | - RX_PKT_CMPL_METADATA_PRI_MASK); - mbuf->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED; - } - - flags2_f = flags2_0xf(rxcmp1); - /* IP Checksum */ - if (likely(IS_IP_NONTUNNEL_PKT(flags2_f))) { - if (unlikely(RX_CMP_IP_CS_ERROR(rxcmp1))) - mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD; - else if (unlikely(RX_CMP_IP_CS_UNKNOWN(rxcmp1))) - mbuf->ol_flags |= PKT_RX_IP_CKSUM_UNKNOWN; - else - mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD; - } else if (IS_IP_TUNNEL_PKT(flags2_f)) { - if (unlikely(RX_CMP_IP_OUTER_CS_ERROR(rxcmp1) || - RX_CMP_IP_CS_ERROR(rxcmp1))) - mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD; - else if (unlikely(RX_CMP_IP_CS_UNKNOWN(rxcmp1))) - mbuf->ol_flags |= PKT_RX_IP_CKSUM_UNKNOWN; - else - mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD; - } - - /* L4 Checksum */ - if (likely(IS_L4_NONTUNNEL_PKT(flags2_f))) { - if (unlikely(RX_CMP_L4_INNER_CS_ERR2(rxcmp1))) - mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD; - else - mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD; - } else if (IS_L4_TUNNEL_PKT(flags2_f)) { - if (unlikely(RX_CMP_L4_INNER_CS_ERR2(rxcmp1))) - mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD; - else - mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD; - if (unlikely(RX_CMP_L4_OUTER_CS_ERR2(rxcmp1))) { - mbuf->ol_flags |= PKT_RX_OUTER_L4_CKSUM_BAD; - } else if (unlikely(IS_L4_TUNNEL_PKT_ONLY_INNER_L4_CS - (flags2_f))) { - mbuf->ol_flags |= PKT_RX_OUTER_L4_CKSUM_UNKNOWN; - } else { - mbuf->ol_flags |= PKT_RX_OUTER_L4_CKSUM_GOOD; - } - } else if (unlikely(RX_CMP_L4_CS_UNKNOWN(rxcmp1))) { - mbuf->ol_flags |= PKT_RX_L4_CKSUM_UNKNOWN; - } - mbuf->packet_type = bnxt_parse_pkt_type(rxcmp, rxcmp1); #ifdef BNXT_DEBUG @@ -734,6 +793,19 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, goto rx; } rxr->rx_prod = prod; + + if (BNXT_TRUFLOW_EN(bp) && (BNXT_VF_IS_TRUSTED(bp) || BNXT_PF(bp)) && + vfr_flag) { + bnxt_vfr_recv(mark_id, rxq->queue_id, mbuf); + /* Now return an error so that nb_rx_pkts is not + * incremented. + * This packet was meant to be given to the representor. + * So no need to account the packet and give it to + * parent Rx burst function. + */ + rc = -ENODEV; + goto next_rx; + } /* * All MBUFs are allocated with the same size under DPDK, * no optimization for rx_copy_thresh @@ -741,20 +813,6 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, rx: *rx_pkt = mbuf; - if (BNXT_TRUFLOW_EN(bp) && - (BNXT_VF_IS_TRUSTED(bp) || BNXT_PF(bp)) && - vfr_flag) { - if (!bnxt_vfr_recv(mark_id, rxq->queue_id, mbuf)) { - /* Now return an error so that nb_rx_pkts is not - * incremented. - * This packet was meant to be given to the representor. - * So no need to account the packet and give it to - * parent Rx burst function. - */ - rc = -ENODEV; - } - } - next_rx: *raw_cons = tmp_raw_cons; @@ -782,8 +840,7 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, return 0; /* If Rx Q was stopped return */ - if (unlikely(!rxq->rx_started || - !rte_spinlock_trylock(&rxq->lock))) + if (unlikely(!rxq->rx_started)) return 0; #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64) @@ -807,7 +864,6 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, /* Handle RX burst request */ while (1) { cons = RING_CMP(cpr->cp_ring_struct, raw_cons); - rte_prefetch0(&cpr->cp_desc_ring[cons]); rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons]; if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct)) @@ -870,7 +926,7 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, struct rte_mbuf **rx_buf = &rxr->rx_buf_ring[i]; /* Buffer already allocated for this index. */ - if (*rx_buf != NULL) + if (*rx_buf != NULL && *rx_buf != &rxq->fake_mbuf) continue; /* This slot is empty. Alloc buffer for Rx */ @@ -885,8 +941,6 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, } done: - rte_spinlock_unlock(&rxq->lock); - return nb_rx_pkts; } @@ -964,7 +1018,11 @@ int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id) ring->ring_mask = ring->ring_size - 1; ring->bd = (void *)rxr->rx_desc_ring; ring->bd_dma = rxr->rx_desc_mapping; - ring->vmem_size = ring->ring_size * sizeof(struct rte_mbuf *); + + /* Allocate extra rx ring entries for vector rx. */ + ring->vmem_size = sizeof(struct rte_mbuf *) * + (ring->ring_size + RTE_BNXT_DESCS_PER_LOOP); + ring->vmem = (void **)&rxr->rx_buf_ring; ring->fw_ring_id = INVALID_HW_RING_ID; @@ -1046,6 +1104,12 @@ int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq) unsigned int i; uint16_t size; + /* Initialize packet type table. */ + bnxt_init_ptype_table(); + + /* Initialize offload flags parsing table. */ + bnxt_init_ol_flags_tables(); + size = rte_pktmbuf_data_room_size(rxq->mb_pool) - RTE_PKTMBUF_HEADROOM; size = RTE_MIN(BNXT_MAX_PKT_LEN, size); @@ -1069,6 +1133,12 @@ int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq) prod = RING_NEXT(rxr->rx_ring_struct, prod); } + /* Initialize dummy mbuf pointers for vector mode rx. */ + for (i = ring->ring_size; + i < ring->ring_size + RTE_BNXT_DESCS_PER_LOOP; i++) { + rxr->rx_buf_ring[i] = &rxq->fake_mbuf; + } + ring = rxr->ag_ring_struct; type = RX_PROD_AGG_BD_TYPE_RX_PROD_AGG; bnxt_init_rxbds(ring, type, size);