Date: Tue, 24 Feb 2026 10:45:12 +0000 Message-ID: <699d8138.37282.48a9226f@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=eeb4c04dd12becd430e9367a679f72d6ee9100f0 commit eeb4c04dd12becd430e9367a679f72d6ee9100f0 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2026-02-06 17:52:54 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2026-02-24 10:15:37 +0000 qlnxe: Refactor setting the promiscuous and allmulti mode There are two entry points to set the promiscuous and allmulti mode. One is ioctl, and another is the init routine. Given they share almost the identical logic, refactor a little to make the code more clear. While here, for the ioctl, translate the error to EINVAL to avoid confusing the net stack. Reviewed by: kbowling MFC after: 5 days Differential Revision: https://reviews.freebsd.org/D54890 (cherry picked from commit 45b1718fadae7d56051ba04ef9d7a175a602a226) (cherry picked from commit b8d2c1c367465506b66a1696483caec1d04b2ea0) (cherry picked from commit 00ab0df79364f4567ad61f6a66eba1b2f0a7d507) --- sys/dev/qlnx/qlnxe/qlnx_def.h | 1 - sys/dev/qlnx/qlnxe/qlnx_os.c | 80 +++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/sys/dev/qlnx/qlnxe/qlnx_def.h b/sys/dev/qlnx/qlnxe/qlnx_def.h index 3e63bd2d1882..d647f928f6d4 100644 --- a/sys/dev/qlnx/qlnxe/qlnx_def.h +++ b/sys/dev/qlnx/qlnxe/qlnx_def.h @@ -370,7 +370,6 @@ struct qlnx_host { uint16_t device_id; struct ifnet *ifp; - int if_flags; volatile int link_up; struct ifmedia media; uint16_t max_frame_size; diff --git a/sys/dev/qlnx/qlnxe/qlnx_os.c b/sys/dev/qlnx/qlnxe/qlnx_os.c index cce23f0f7ea1..311ab73eb868 100644 --- a/sys/dev/qlnx/qlnxe/qlnx_os.c +++ b/sys/dev/qlnx/qlnxe/qlnx_os.c @@ -85,8 +85,8 @@ static void qlnx_init_ifnet(device_t dev, qlnx_host_t *ha); static void qlnx_init(void *arg); static void qlnx_init_locked(qlnx_host_t *ha); static int qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi); -static int qlnx_set_promisc(qlnx_host_t *ha, int enabled); -static int qlnx_set_allmulti(qlnx_host_t *ha, int enabled); +static int qlnx_set_promisc_allmulti(qlnx_host_t *ha, int flags); +static int _qlnx_set_promisc_allmulti(qlnx_host_t *ha, bool promisc, bool allmulti); static int qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); static int qlnx_media_change(struct ifnet *ifp); static void qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr); @@ -2624,44 +2624,49 @@ qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi) } static int -qlnx_set_promisc(qlnx_host_t *ha, int enabled) +qlnx_set_promisc_allmulti(qlnx_host_t *ha, int flags) { int rc = 0; - uint8_t filter; if (qlnx_vf_device(ha) == 0) return (0); - filter = ha->filter; - if (enabled) { - filter |= ECORE_ACCEPT_MCAST_UNMATCHED; - filter |= ECORE_ACCEPT_UCAST_UNMATCHED; - } else { - filter &= ~ECORE_ACCEPT_MCAST_UNMATCHED; - filter &= ~ECORE_ACCEPT_UCAST_UNMATCHED; - } - - rc = qlnx_set_rx_accept_filter(ha, filter); + rc = _qlnx_set_promisc_allmulti(ha, flags & IFF_PROMISC, + flags & IFF_ALLMULTI); return (rc); } static int -qlnx_set_allmulti(qlnx_host_t *ha, int enabled) +_qlnx_set_promisc_allmulti(qlnx_host_t *ha, bool promisc, bool allmulti) { int rc = 0; uint8_t filter; - - if (qlnx_vf_device(ha) == 0) - return (0); + bool mcast, ucast; filter = ha->filter; - if (enabled) { + filter |= ECORE_ACCEPT_UCAST_MATCHED; + filter |= ECORE_ACCEPT_MCAST_MATCHED; + filter |= ECORE_ACCEPT_BCAST; + + mcast = promisc || allmulti; + ucast = promisc; + + if (mcast) filter |= ECORE_ACCEPT_MCAST_UNMATCHED; - } else { + else filter &= ~ECORE_ACCEPT_MCAST_UNMATCHED; - } - rc = qlnx_set_rx_accept_filter(ha, filter); + if (ucast) + filter |= ECORE_ACCEPT_UCAST_UNMATCHED; + else + filter &= ~ECORE_ACCEPT_UCAST_UNMATCHED; + + if (filter == ha->filter) + return (0); + + rc = qlnx_set_rx_accept_filter(ha, filter); + if (rc == 0) + ha->filter = filter; return (rc); } @@ -2701,13 +2706,8 @@ qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if (ifp->if_flags & IFF_UP) { if (ifp->if_drv_flags & IFF_DRV_RUNNING) { - if ((ifp->if_flags ^ ha->if_flags) & - IFF_PROMISC) { - ret = qlnx_set_promisc(ha, ifp->if_flags & IFF_PROMISC); - } else if ((ifp->if_flags ^ ha->if_flags) & - IFF_ALLMULTI) { - ret = qlnx_set_allmulti(ha, ifp->if_flags & IFF_ALLMULTI); - } + if (qlnx_set_promisc_allmulti(ha, ifp->if_flags) != 0) + ret = EINVAL; } else { ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; @@ -2718,7 +2718,6 @@ qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) qlnx_stop(ha); } - ha->if_flags = ifp->if_flags; QLNX_UNLOCK(ha); break; @@ -7123,6 +7122,9 @@ qlnx_clean_filters(qlnx_host_t *ha) { int rc = 0; + /* Reset rx filter */ + ha->filter = 0; + /* Remove all unicast macs */ rc = qlnx_remove_all_ucast_mac(ha); if (rc) @@ -7166,7 +7168,6 @@ static int qlnx_set_rx_mode(qlnx_host_t *ha) { int rc = 0; - uint8_t filter; const struct ifnet *ifp = ha->ifp; rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_REPLACE, IF_LLADDR(ifp)); @@ -7177,19 +7178,10 @@ qlnx_set_rx_mode(qlnx_host_t *ha) if (rc) return rc; - filter = ECORE_ACCEPT_UCAST_MATCHED | - ECORE_ACCEPT_MCAST_MATCHED | - ECORE_ACCEPT_BCAST; - - if (qlnx_vf_device(ha) == 0 || (ha->ifp->if_flags & IFF_PROMISC)) { - filter |= ECORE_ACCEPT_UCAST_UNMATCHED; - filter |= ECORE_ACCEPT_MCAST_UNMATCHED; - } else if (ha->ifp->if_flags & IFF_ALLMULTI) { - filter |= ECORE_ACCEPT_MCAST_UNMATCHED; - } - ha->filter = filter; - - rc = qlnx_set_rx_accept_filter(ha, filter); + if (qlnx_vf_device(ha) == 0) + rc = _qlnx_set_promisc_allmulti(ha, true, true); + else + rc = qlnx_set_promisc_allmulti(ha, ifp->if_flags); return (rc); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?699d8138.37282.48a9226f>
