From nobody Tue Jan 24 22:13:29 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P1h7Y2dZkz3bg9T; Tue, 24 Jan 2023 22:13:29 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P1h7Y1sTWz3Gyc; Tue, 24 Jan 2023 22:13:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zKtqHT9GkGakzAL+ey+9TX6IYWme/B7IWJJbIaJ/hpk=; b=q3S9/yleKFcMylDyGkJ40ElCNOqLA1Why5eK0jvoma6f7iro11j0OHyBaPDStMdHjy4M9/ z2PiURHkkM2JpUmao/QJ1rz9YeLntyIZuwVjkio+fJc0qPsl4UpWFq+lWSXZMNwy1nID0h /iAqz+OYBLUbAmqtAlAU+Q+2erO/LvHm+mR4K1mcy88hvsGGj3lQQHAsdY7nIoDL0CGG43 l5PyXXf4LQWZKLXgKse7EVPTznXYu+1dI6BBnnIOoXO2J+LQZ3Gz6e2Zxwn+FHB7LLhu4U kRvlNZjU0J21C0sMtXkI7+CMXWJSlVpex4ELNhnj+2gEM3zFmfuo89peWHeuIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zKtqHT9GkGakzAL+ey+9TX6IYWme/B7IWJJbIaJ/hpk=; b=LYvl+qK/LspLYxxaM2/4ehdXNvHYbh7EWK/CvfOqO4xfCasSMO5DVN7g0xg4D448Ad9zmn ejJlHy/NHMAOv+u2IEtLvCr2wRcdCcVqCUDZCB7GBEAqJR/nJXi67vRImtNvIouc08R0Fy L6rTTYbM4H+kWpZYwpaRpZ7YIkQ49Prdqx8EZTzhF3TsAa8Ecmmrze8fgAnzPRAdpRjJEZ y6xR28pNRFGQb56GhmeYu+GMzvXfEAI6GnwZVve7ZY4Imkv4SWxk6b/QFHSNA6me9NPRnM rcYliSz6S2ylYTJZHYcHuKUTChCDqOc1cAstTQGFOVJKr0Qv83sozVwjHhONKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598409; a=rsa-sha256; cv=none; b=I95AwWBczH2WJ74+8hIVp5dTknFfWRTnzhM8sAl50vGX5mKP3R50M0ZCfg4xUdlghyC4j4 AOxdkJfWj13IgJ+ixrXF/Ndwj1+vSQJ1CjwdI8b0tkA8DytUoNpw8d8IQYYIEfa/A6LEba SlmlGYOjW0BoCj761Qcee0QyJCKh4dbLD6z3ejAgywwVa1Dl3mwiDuACRsXOmuqKxaC/4P Tb0StPX4+cTng9kNRpKzAQN6ZyfwOJrJkzXzI4YGXdSNU1KgKGl+RsVm85RdTOLm63qWBI VRDUu7IAQuVJjJMx66kxa+RFjJM1+85PXDAkPGyi3SNQ+7pBb3eH3ZjD7lyhbA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P1h7Y0p6DzQYm; Tue, 24 Jan 2023 22:13:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OMDThp088492; Tue, 24 Jan 2023 22:13:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDTxF088491; Tue, 24 Jan 2023 22:13:29 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:29 GMT Message-Id: <202301242213.30OMDTxF088491@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 8bca927b88d6 - stable/13 - stand/ofw: Subclass devnet to cope with ofw's unique needs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8bca927b88d6b7e31b2f66a7f2f93684b7698797 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8bca927b88d6b7e31b2f66a7f2f93684b7698797 commit 8bca927b88d6b7e31b2f66a7f2f93684b7698797 Author: Warner Losh AuthorDate: 2022-11-30 22:10:05 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:40 +0000 stand/ofw: Subclass devnet to cope with ofw's unique needs We need to match devices in a slightly special way: We have to look up the path and see if the device is a 'network' device in order to use it. Sponsored by: Netflix Tested by: grehan@ (with tweaks to my original patch) Differential Revision: https://reviews.freebsd.org/D37557 (cherry picked from commit b8ff248f6595067ef9a31d5d4cec5fb9b9052fc3) --- stand/libofw/libofw.h | 1 + stand/libofw/ofw_net.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ stand/powerpc/ofw/conf.c | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/stand/libofw/libofw.h b/stand/libofw/libofw.h index 0494a78135e7..ce7e6e986029 100644 --- a/stand/libofw/libofw.h +++ b/stand/libofw/libofw.h @@ -48,6 +48,7 @@ extern int ofw_getdev(void **vdev, const char *devspec, const char **path); extern ev_sethook_t ofw_setcurrdev; extern struct devsw ofwdisk; +extern struct devsw ofw_netdev; extern struct netif_driver ofwnet; int ofwn_getunit(const char *); diff --git a/stand/libofw/ofw_net.c b/stand/libofw/ofw_net.c index fa4a3abd88e8..59b9f8de7efb 100644 --- a/stand/libofw/ofw_net.c +++ b/stand/libofw/ofw_net.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include "libofw.h" #include "openfirm.h" static int ofwn_probe(struct netif *, void *); @@ -267,3 +268,77 @@ ofwn_getunit(const char *path) return -1; } #endif + +/* + * To properly match network devices, we have to subclass the netdev device. + * It has a different devdesc than a normal network device (which is fine: + * it's a struct superset) and different matching criteria (since it has to + * look at the path, find a handle and see if that handle is a network node + * or not). + */ + +static int ofwnd_init(void); +static int ofwnd_parsedev(struct devdesc **, const char *, const char **); +static bool ofwnd_match(struct devsw *, const char *); +static char *ofwnd_fmtdev(struct devdesc *); + +struct devsw ofw_netdev = { + .dv_name = "network", + .dv_type = DEVT_NET, + .dv_init = ofwnd_init, + .dv_match = ofwnd_match, + .dv_fmtdev = ofwnd_fmtdev, + .dv_parsedev = ofwnd_parsedev, +}; + +static int ofwnd_init(void) +{ + netdev.dv_init(); + ofw_netdev.dv_strategy = netdev.dv_strategy; + ofw_netdev.dv_open = netdev.dv_open; + ofw_netdev.dv_close = netdev.dv_close; + ofw_netdev.dv_ioctl = netdev.dv_ioctl; + ofw_netdev.dv_print = netdev.dv_print; + ofw_netdev.dv_fmtdev = netdev.dv_fmtdev; + /* parsedev is unique to ofwnd */ + /* match is unique to ofwnd */ + return (0); +} + +static int +ofwnd_parsedev(struct devdesc **dev, const char *devspec, const char **path) +{ + const char *rem_path; + struct ofw_devdesc *idev; + + if (ofw_path_to_handle(devspec, ofw_netdev.dv_name, &rem_path) == -1) + return (ENOENT); + idev = malloc(sizeof(struct ofw_devdesc)); + if (idev == NULL) { + printf("ofw_parsedev: malloc failed\n"); + return ENOMEM; + }; + strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1, + sizeof(idev->d_path))); + if (dev != NULL) + *dev = &idev->dd; + if (path != NULL) + *path = rem_path; + return 0; +} + +static bool +ofwnd_match(struct devsw *devsw, const char *devspec) +{ + const char *path; + + return (ofw_path_to_handle(devspec, devsw->dv_name, &path) != -1); +} + +static char * +ofwnd_fmtdev(struct devdesc *idev) +{ + struct ofw_devdesc *dev = (struct ofw_devdesc *)idev; + + return (dev->d_path); +} diff --git a/stand/powerpc/ofw/conf.c b/stand/powerpc/ofw/conf.c index a472faeed97b..c2b28f4fe0f0 100644 --- a/stand/powerpc/ofw/conf.c +++ b/stand/powerpc/ofw/conf.c @@ -54,7 +54,7 @@ struct devsw *devsw[] = { &ofwdisk, #endif #if defined(LOADER_NET_SUPPORT) - &netdev, + &ofw_netdev, #endif NULL };