From f8a90df5fd348427c6475bcca99ba87dbe3afb89 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 28 Jan 2023 00:17:06 -0500 Subject: [PATCH] openbsd_network: New additions for rtl8125. Change-Id: Id2b2b58e8fe69b5b758ccd8161adcedd7ecaf717 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6041 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- .../openbsd_network/compat/net/if_var-obsd.h | 134 ++++++++++++++++++ .../openbsd_network/compat/net/if_var.h | 5 + .../compat/openbsd_network/compat/net/ifq.h | 14 ++ .../compat/openbsd_network/compat/sys/systm.h | 4 + 4 files changed, 157 insertions(+) create mode 100644 src/libs/compat/openbsd_network/compat/net/if_var-obsd.h diff --git a/src/libs/compat/openbsd_network/compat/net/if_var-obsd.h b/src/libs/compat/openbsd_network/compat/net/if_var-obsd.h new file mode 100644 index 0000000000..9b0269b9fb --- /dev/null +++ b/src/libs/compat/openbsd_network/compat/net/if_var-obsd.h @@ -0,0 +1,134 @@ +/* $OpenBSD: if.c,v 1.683 2022/11/23 16:57:37 kn Exp $ */ +/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1980, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if.c 8.3 (Berkeley) 1/4/94 + */ + + +struct if_rxring { + int rxr_adjusted; + u_int rxr_alive; + u_int rxr_cwm; + u_int rxr_lwm; + u_int rxr_hwm; +}; + +#define if_rxr_put(_r, _c) do { (_r)->rxr_alive -= (_c); } while (0) +#define if_rxr_needrefill(_r) ((_r)->rxr_alive < (_r)->rxr_lwm) +#define if_rxr_inuse(_r) ((_r)->rxr_alive) +#define if_rxr_cwm(_r) ((_r)->rxr_cwm) + +static inline void +if_rxr_init(struct if_rxring *rxr, u_int lwm, u_int hwm) +{ + extern int ticks; + + memset(rxr, 0, sizeof(*rxr)); + + rxr->rxr_adjusted = ticks; + rxr->rxr_cwm = rxr->rxr_lwm = lwm; + rxr->rxr_hwm = hwm; +} + +static inline void +if_rxr_adjust_cwm(struct if_rxring *rxr) +{ + extern int ticks; + + if (rxr->rxr_alive >= rxr->rxr_lwm) + return; + else if (rxr->rxr_cwm < rxr->rxr_hwm) + rxr->rxr_cwm++; + + rxr->rxr_adjusted = ticks; +} + +static inline void +if_rxr_livelocked(struct if_rxring *rxr) +{ + extern int ticks; + + if (ticks - rxr->rxr_adjusted >= 1) { + if (rxr->rxr_cwm > rxr->rxr_lwm) + rxr->rxr_cwm--; + + rxr->rxr_adjusted = ticks; + } +} + +static inline u_int +if_rxr_get(struct if_rxring *rxr, u_int max) +{ + extern int ticks; + u_int diff; + + if (ticks - rxr->rxr_adjusted >= 1) { + /* we're free to try for an adjustment */ + if_rxr_adjust_cwm(rxr); + } + + if (rxr->rxr_alive >= rxr->rxr_cwm) + return (0); + + diff = min(rxr->rxr_cwm - rxr->rxr_alive, max); + rxr->rxr_alive += diff; + + return (diff); +} diff --git a/src/libs/compat/openbsd_network/compat/net/if_var.h b/src/libs/compat/openbsd_network/compat/net/if_var.h index fafb0a0ba5..4927664f2d 100644 --- a/src/libs/compat/openbsd_network/compat/net/if_var.h +++ b/src/libs/compat/openbsd_network/compat/net/if_var.h @@ -41,4 +41,9 @@ ifq_dequeue(struct ifaltq *ifq) } +#ifndef __cplusplus +#include "if_var-obsd.h" +#endif + + #endif /* _OBSD_COMPAT_NET_IF_VAR_H_ */ diff --git a/src/libs/compat/openbsd_network/compat/net/ifq.h b/src/libs/compat/openbsd_network/compat/net/ifq.h index 948fe130eb..37ca1a5602 100644 --- a/src/libs/compat/openbsd_network/compat/net/ifq.h +++ b/src/libs/compat/openbsd_network/compat/net/ifq.h @@ -14,4 +14,18 @@ #define ifq_clr_oactive(IFQ) if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE) +static void +ifq_serialize(struct ifaltq* ifq, struct task* t) +{ + task_add(systq, t); +} + + +static void +ifq_barrier(struct ifaltq* ifq) +{ + taskqueue_drain_all(taskqueue_fast); +} + + #endif /* _OBSD_COMPAT_NET_IFQ_H_ */ diff --git a/src/libs/compat/openbsd_network/compat/sys/systm.h b/src/libs/compat/openbsd_network/compat/sys/systm.h index 70d5fe1820..e684d4b545 100644 --- a/src/libs/compat/openbsd_network/compat/sys/systm.h +++ b/src/libs/compat/openbsd_network/compat/sys/systm.h @@ -44,6 +44,10 @@ explicit_bzero(void *buf, size_t len) #define KASSERT KASSERT_OPENBSD +#define KERNEL_LOCK() mtx_lock(&Giant) +#define KERNEL_UNLOCK() mtx_unlock(&Giant) + + /* #pragma mark - interrupts */ #define IPL_NONE 0