git: 91fcacc35597 - main - if_bnxt: Add support for VLAN on Thor

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 04 Nov 2022 22:55:52 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=91fcacc355971f74aa26fc7861020dc3a2a2d717

commit 91fcacc355971f74aa26fc7861020dc3a2a2d717
Author:     Sumit Saxena <sumit.saxena@broadcom.com>
AuthorDate: 2022-11-04 22:24:32 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-11-04 22:24:32 +0000

    if_bnxt: Add support for VLAN on Thor
    
    Reviewed by: imp
    Differential Revision: https://reviews.freebsd.org/D36443
---
 sys/dev/bnxt/bnxt.h      |   3 +-
 sys/dev/bnxt/bnxt_hwrm.c | 110 ++++++++++++++++++++++++++++-------------------
 sys/dev/bnxt/bnxt_hwrm.h |   7 ++-
 sys/dev/bnxt/if_bnxt.c   |   7 ++-
 4 files changed, 74 insertions(+), 53 deletions(-)

diff --git a/sys/dev/bnxt/bnxt.h b/sys/dev/bnxt/bnxt.h
index 9638ad78fb6d..4cf93f1c7eeb 100644
--- a/sys/dev/bnxt/bnxt.h
+++ b/sys/dev/bnxt/bnxt.h
@@ -396,7 +396,7 @@ struct bnxt_vf_info {
 
 struct bnxt_vlan_tag {
 	SLIST_ENTRY(bnxt_vlan_tag) next;
-	uint16_t	tpid;
+	uint64_t	filter_id;
 	uint16_t	tag;
 };
 
@@ -419,7 +419,6 @@ struct bnxt_vnic_info {
 #define BNXT_VNIC_FLAG_VLAN_STRIP	0x04
 
 	uint64_t	filter_id;
-	uint32_t	flow_id;
 
 	uint16_t	rss_id;
 	uint32_t	rss_hash_type;
diff --git a/sys/dev/bnxt/bnxt_hwrm.c b/sys/dev/bnxt/bnxt_hwrm.c
index ebcfc5ef03ff..40c47ffe372c 100644
--- a/sys/dev/bnxt/bnxt_hwrm.c
+++ b/sys/dev/bnxt/bnxt_hwrm.c
@@ -1379,64 +1379,29 @@ bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt_softc *softc,
     struct bnxt_vnic_info *vnic)
 {
 	struct hwrm_cfa_l2_set_rx_mask_input req = {0};
-	struct bnxt_vlan_tag *tag;
-	uint32_t *tags;
-	uint32_t num_vlan_tags = 0;
-	uint32_t i;
 	uint32_t mask = vnic->rx_mask;
-	int rc;
-
-	SLIST_FOREACH(tag, &vnic->vlan_tags, next)
-		num_vlan_tags++;
-
-	if (num_vlan_tags) {
-		if (!(mask &
-		    HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN)) {
-			if (!vnic->vlan_only)
-				mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
-			else
-				mask |=
-				    HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
-		}
-		if (vnic->vlan_tag_list.idi_vaddr) {
-			iflib_dma_free(&vnic->vlan_tag_list);
-			vnic->vlan_tag_list.idi_vaddr = NULL;
-		}
-		rc = iflib_dma_alloc(softc->ctx, 4 * num_vlan_tags,
-		    &vnic->vlan_tag_list, BUS_DMA_NOWAIT);
-		if (rc)
-			return rc;
-		tags = (uint32_t *)vnic->vlan_tag_list.idi_vaddr;
 
-		i = 0;
-		SLIST_FOREACH(tag, &vnic->vlan_tags, next) {
-			tags[i] = htole32((tag->tpid << 16) | tag->tag);
-			i++;
-		}
-	}
 	bnxt_hwrm_cmd_hdr_init(softc, &req, HWRM_CFA_L2_SET_RX_MASK);
 
 	req.vnic_id = htole32(vnic->id);
 	req.mask = htole32(mask);
 	req.mc_tbl_addr = htole64(vnic->mc_list.idi_paddr);
 	req.num_mc_entries = htole32(vnic->mc_list_count);
-	req.vlan_tag_tbl_addr = htole64(vnic->vlan_tag_list.idi_paddr);
-	req.num_vlan_tags = htole32(num_vlan_tags);
 	return hwrm_send_message(softc, &req, sizeof(req));
 }
 
 int
-bnxt_hwrm_free_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic)
+bnxt_hwrm_l2_filter_free(struct bnxt_softc *softc, uint64_t filter_id)
 {
 	struct hwrm_cfa_l2_filter_free_input	req = {0};
 	int rc = 0;
 
-	if (vnic->filter_id == -1)
+	if (filter_id == -1)
 		return rc;
 
 	bnxt_hwrm_cmd_hdr_init(softc, &req, HWRM_CFA_L2_FILTER_FREE);
 
-	req.l2_filter_id = htole64(vnic->filter_id);
+	req.l2_filter_id = htole64(filter_id);
 
 	BNXT_HWRM_LOCK(softc);
 	rc = _hwrm_send_message(softc, &req, sizeof(req));
@@ -1449,16 +1414,40 @@ fail:
 }
 
 int
-bnxt_hwrm_set_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic)
+bnxt_hwrm_free_filter(struct bnxt_softc *softc)
+{
+	struct bnxt_vnic_info *vnic = &softc->vnic_info;
+	struct bnxt_vlan_tag *tag;
+	int rc = 0;
+
+	rc = bnxt_hwrm_l2_filter_free(softc, softc->vnic_info.filter_id);
+	if (rc)
+		goto end;
+
+	SLIST_FOREACH(tag, &vnic->vlan_tags, next) {
+		rc = bnxt_hwrm_l2_filter_free(softc, tag->filter_id);
+		if (rc)
+			goto end;
+		tag->filter_id = -1;
+	}
+
+end:
+	return rc;
+}
+
+int
+bnxt_hwrm_l2_filter_alloc(struct bnxt_softc *softc, uint16_t vlan_tag,
+		uint64_t *filter_id)
 {
 	struct hwrm_cfa_l2_filter_alloc_input	req = {0};
 	struct hwrm_cfa_l2_filter_alloc_output	*resp;
+	struct bnxt_vnic_info *vnic = &softc->vnic_info;
 	uint32_t enables = 0;
 	int rc = 0;
 
-	if (vnic->filter_id != -1) {
-		device_printf(softc->dev,
-		    "Attempt to re-allocate l2 ctx filter\n");
+	if (*filter_id != -1) {
+		device_printf(softc->dev, "Attempt to re-allocate l2 ctx "
+				"filter (fid: 0x%lx)\n", *filter_id);
 		return EDOOFUS;
 	}
 
@@ -1469,6 +1458,17 @@ bnxt_hwrm_set_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic)
 	enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR
 	    | HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK
 	    | HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
+
+	if (vlan_tag != 0xffff) {
+		enables |=
+			HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
+			HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK |
+			HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_NUM_VLANS;
+		req.l2_ivlan_mask = 0xffff;
+		req.l2_ivlan = vlan_tag;
+		req.num_vlans = 1;
+	}
+
 	req.enables = htole32(enables);
 	req.dst_id = htole16(vnic->id);
 	memcpy(req.l2_addr, if_getlladdr(iflib_get_ifp(softc->ctx)),
@@ -1480,14 +1480,34 @@ bnxt_hwrm_set_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic)
 	if (rc)
 		goto fail;
 
-	vnic->filter_id = le64toh(resp->l2_filter_id);
-	vnic->flow_id = le64toh(resp->flow_id);
-
+	*filter_id = le64toh(resp->l2_filter_id);
 fail:
 	BNXT_HWRM_UNLOCK(softc);
 	return (rc);
 }
 
+int
+bnxt_hwrm_set_filter(struct bnxt_softc *softc)
+{
+	struct bnxt_vnic_info *vnic = &softc->vnic_info;
+	struct bnxt_vlan_tag *tag;
+	int rc = 0;
+
+	rc = bnxt_hwrm_l2_filter_alloc(softc, 0xffff, &vnic->filter_id);
+	if (rc)
+		goto end;
+
+	SLIST_FOREACH(tag, &vnic->vlan_tags, next) {
+		rc = bnxt_hwrm_l2_filter_alloc(softc, tag->tag,
+				&tag->filter_id);
+		if (rc)
+			goto end;
+	}
+
+end:
+	return rc;
+}
+
 int
 bnxt_hwrm_rss_cfg(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic,
     uint32_t hash_type)
diff --git a/sys/dev/bnxt/bnxt_hwrm.h b/sys/dev/bnxt/bnxt_hwrm.h
index ad308f0bbbdd..8033ddb50136 100644
--- a/sys/dev/bnxt/bnxt_hwrm.h
+++ b/sys/dev/bnxt/bnxt_hwrm.h
@@ -70,8 +70,11 @@ int bnxt_hwrm_ring_grp_alloc(struct bnxt_softc *softc,
 int bnxt_hwrm_ring_grp_free(struct bnxt_softc *softc, struct bnxt_grp_info *gr);
 int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt_softc *softc,
     struct bnxt_vnic_info *vnic);
-int bnxt_hwrm_set_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic);
-int bnxt_hwrm_free_filter(struct bnxt_softc *softc, struct bnxt_vnic_info *vnc);
+int bnxt_hwrm_set_filter(struct bnxt_softc *softc);
+int bnxt_hwrm_free_filter(struct bnxt_softc *softc);
+int bnxt_hwrm_l2_filter_alloc(struct bnxt_softc *softc, uint16_t vlan_tag,
+		uint64_t *filter_id);
+int bnxt_hwrm_l2_filter_free(struct bnxt_softc *softc, uint64_t filter_id);
 int bnxt_hwrm_rss_cfg(struct bnxt_softc *softc, struct bnxt_vnic_info *vnic,
     uint32_t hash_type);
 int bnxt_cfg_async_cr(struct bnxt_softc *softc);
diff --git a/sys/dev/bnxt/if_bnxt.c b/sys/dev/bnxt/if_bnxt.c
index c63b47da4a89..bc6dd1c2b1c5 100644
--- a/sys/dev/bnxt/if_bnxt.c
+++ b/sys/dev/bnxt/if_bnxt.c
@@ -653,7 +653,6 @@ bnxt_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs,
 
 	/* And finally, the VNIC */
 	softc->vnic_info.id = (uint16_t)HWRM_NA_SIGNATURE;
-	softc->vnic_info.flow_id = (uint16_t)HWRM_NA_SIGNATURE;
 	softc->vnic_info.filter_id = -1;
 	softc->vnic_info.def_ring_grp = (uint16_t)HWRM_NA_SIGNATURE;
 	softc->vnic_info.cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
@@ -1649,7 +1648,7 @@ bnxt_hwrm_resource_free(struct bnxt_softc *softc)
 		if (rc)
 			goto fail;
 	}
-	rc = bnxt_hwrm_free_filter(softc, &softc->vnic_info);
+	rc = bnxt_hwrm_free_filter(softc);
 	if (rc)
 		goto fail;
 
@@ -1850,7 +1849,7 @@ skip_def_cp_ring:
 	rc = bnxt_hwrm_vnic_set_hds(softc, &softc->vnic_info);
 	if (rc)
 		goto fail;
-	rc = bnxt_hwrm_set_filter(softc, &softc->vnic_info);
+	rc = bnxt_hwrm_set_filter(softc);
 	if (rc)
 		goto fail;
 
@@ -2406,7 +2405,7 @@ bnxt_vlan_register(if_ctx_t ctx, uint16_t vtag)
 	if (new_tag == NULL)
 		return;
 	new_tag->tag = vtag;
-	new_tag->tpid = 8100;
+	new_tag->filter_id = -1;
 	SLIST_INSERT_HEAD(&softc->vnic_info.vlan_tags, new_tag, next);
 };