From owner-svn-src-head@freebsd.org Mon Nov 9 00:01:14 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2CEA02E1C0F; Mon, 9 Nov 2020 00:01:14 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CTrkL0YwCz3HgZ; Mon, 9 Nov 2020 00:01:14 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 048AE398; Mon, 9 Nov 2020 00:01:14 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0A901DH9061856; Mon, 9 Nov 2020 00:01:13 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0A901DcA061853; Mon, 9 Nov 2020 00:01:13 GMT (envelope-from np@FreeBSD.org) Message-Id: <202011090001.0A901DcA061853@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Mon, 9 Nov 2020 00:01:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367497 - in head/sys/dev/cxgbe: . common X-SVN-Group: head X-SVN-Commit-Author: np X-SVN-Commit-Paths: in head/sys/dev/cxgbe: . common X-SVN-Commit-Revision: 367497 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2020 00:01:14 -0000 Author: np Date: Mon Nov 9 00:01:13 2020 New Revision: 367497 URL: https://svnweb.freebsd.org/changeset/base/367497 Log: cxgbev(4): Use the MAC address set by the the PF if there is one. Query the firmware for the MAC address set by the PF for the VF and use it instead of the firmware generated MAC if it's available. MFC after: 2 weeks Sponsored by: Chelsio Communications Modified: head/sys/dev/cxgbe/common/common.h head/sys/dev/cxgbe/common/t4vf_hw.c head/sys/dev/cxgbe/t4_vf.c Modified: head/sys/dev/cxgbe/common/common.h ============================================================================== --- head/sys/dev/cxgbe/common/common.h Sun Nov 8 23:34:06 2020 (r367496) +++ head/sys/dev/cxgbe/common/common.h Mon Nov 9 00:01:13 2020 (r367497) @@ -912,6 +912,8 @@ int t4vf_get_sge_params(struct adapter *adapter); int t4vf_get_rss_glb_config(struct adapter *adapter); int t4vf_get_vfres(struct adapter *adapter); int t4vf_prep_adapter(struct adapter *adapter); +int t4vf_get_vf_mac(struct adapter *adapter, unsigned int port, + unsigned int *naddr, u8 *addr); int t4_bar2_sge_qregs(struct adapter *adapter, unsigned int qid, enum t4_bar2_qtype qtype, int user, u64 *pbar2_qoffset, unsigned int *pbar2_qid); Modified: head/sys/dev/cxgbe/common/t4vf_hw.c ============================================================================== --- head/sys/dev/cxgbe/common/t4vf_hw.c Sun Nov 8 23:34:06 2020 (r367496) +++ head/sys/dev/cxgbe/common/t4vf_hw.c Mon Nov 9 00:01:13 2020 (r367497) @@ -382,3 +382,49 @@ int t4vf_prep_adapter(struct adapter *adapter) return 0; } + +/* + * t4vf_get_vf_mac - Get the MAC address to be set to the VI of this VF. + * @adapter: The adapter + * @port: The port associated with vf + * @naddr: the number of ACL MAC addresses returned in addr + * @addr: Placeholder for MAC addresses + * + * Find the MAC address to be set to the VF's VI. The requested MAC address + * is from the host OS via callback in the PF driver. + */ +int t4vf_get_vf_mac(struct adapter *adapter, unsigned int port, + unsigned int *naddr, u8 *addr) +{ + struct fw_acl_mac_cmd cmd; + int ret; + + memset(&cmd, 0, sizeof(cmd)); + cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_ACL_MAC_CMD) | + F_FW_CMD_REQUEST | + F_FW_CMD_READ); + cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd)); + ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &cmd); + if (ret) + return ret; + + if (cmd.nmac < *naddr) + *naddr = cmd.nmac; + + switch (port) { + case 3: + memcpy(addr, cmd.macaddr3, sizeof(cmd.macaddr3)); + break; + case 2: + memcpy(addr, cmd.macaddr2, sizeof(cmd.macaddr2)); + break; + case 1: + memcpy(addr, cmd.macaddr1, sizeof(cmd.macaddr1)); + break; + case 0: + memcpy(addr, cmd.macaddr0, sizeof(cmd.macaddr0)); + break; + } + + return ret; +} Modified: head/sys/dev/cxgbe/t4_vf.c ============================================================================== --- head/sys/dev/cxgbe/t4_vf.c Sun Nov 8 23:34:06 2020 (r367496) +++ head/sys/dev/cxgbe/t4_vf.c Mon Nov 9 00:01:13 2020 (r367497) @@ -481,7 +481,7 @@ static int t4vf_attach(device_t dev) { struct adapter *sc; - int rc = 0, i, j, rqidx, tqidx; + int rc = 0, i, j, rqidx, tqidx, n, p, pmask; struct make_dev_args mda; struct intrs_and_queues iaq; struct sge *s; @@ -618,8 +618,10 @@ t4vf_attach(device_t dev) * First pass over all the ports - allocate VIs and initialize some * basic parameters like mac address, port type, etc. */ + pmask = sc->params.vfres.pmask; for_each_port(sc, i) { struct port_info *pi; + uint8_t mac[ETHER_ADDR_LEN]; pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK); sc->port[i] = pi; @@ -644,6 +646,15 @@ t4vf_attach(device_t dev) sc->port[i] = NULL; goto done; } + + /* Prefer the MAC address set by the PF, if there is one. */ + n = 1; + p = ffs(pmask) - 1; + MPASS(p >= 0); + rc = t4vf_get_vf_mac(sc, p, &n, mac); + if (rc == 0 && n == 1) + t4_os_set_hw_addr(pi, mac); + pmask &= ~(1 << p); /* No t4_link_start. */