From nobody Wed Nov 30 22:31:30 2022 X-Original-To: dev-commits-src-main@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 4NMv7k5jGpz4jCXy; Wed, 30 Nov 2022 22:31:30 +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 4NMv7k56lqz44rZ; Wed, 30 Nov 2022 22:31:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847490; 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=NzPP0eolbYWJrSHPJV1Ksoir5vUsRu8xs2k8NrVbTss=; b=uVbXQg2ZjDreEJEzC2sGloZhzK6h8jXzAPILFWTxatPnoliaAH1aeGATeiS/Z69CxaHY8Q yyQz6akxqT9FBt1wB6sx8O9ZJM26PoNldy2+aYzPfUSAgnKJ4nJUnj7KK5tGkbc4QQdEK3 kHztaDSF4Dy+98L3xeTeypodShoMJ4CxfM1e4Bbo4QU/hmldmeOYcmF6htxJIKiA6eZwLy B+vlOv7cqNN0W+QzDYzLMEsKj1BRYuG6YUcoYTeZqJsOPg8HzrzvLbj3/cLOtDJ8AQO6xw EcMycm3S+iWN9Rt3yvdZfEh9UfNasGOylhxrZoDLTU49qzHn8o6nbL0b6sskCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847490; 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=NzPP0eolbYWJrSHPJV1Ksoir5vUsRu8xs2k8NrVbTss=; b=ZB7E1FamDYFUJ0rLNq1PqRVylimRKH4dNYlb246Hb3lvlqmn/00E3/UAybaDbWzWw5jGWW oFZVHL4j0N6aQnjz0ezdpNSLFqBkBiXJE0+nDUu1/ebgnAMG7/nD26LxsuW6ZxBc9bXkEO 0eaCYRmwFC9LMgAzy7Rju7lL/1uGMzxyE6Bjg9f/ksa3m/ao27Mx9XCSOeFv5qjloBa923 5VsTBZ0KJyfDb79mrMEt//a6Ttisg17s1UExevejErOXtnUNL/T3gmiJ8vEcLbSyQydxQz W9LipIAaaNhAcmfYAdvmmG5dKOWLqew5lS1n5SR+M/tN78inPS5beAMuPFEFwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669847490; a=rsa-sha256; cv=none; b=b8LQoGJsxBZCh6KR7R4EilaJsSkw/sbUJd7TAX+/gBJg9YfD7TSu6MsRu4sKqN5EnYpeRr l9zFhN7ke107UaT9d/xmcAS/KySnRlgZ6Rh0sznrsjodCBCkDejeFqFunBXd2TyWw1Sy7X ar+phdc1yIXW/1ZQ/ltzyKIZLqdAp0/01/ZLMq6dp8Kpg9qNRrHAgt4Di/BUOyVbpcinLw 4RZl1duzPpao471WX19GGP0Vv7y/82cbkhoTCITd/vATtJ39VxXdNRsP7rNEywTPPnH81B MHWGN93OXpTb/mNFGoUhIR6oJIE4QKtitnMg260olzLfqRJDgY0x0J9syA4CJg== 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 4NMv7k4DLcz1Cg3; Wed, 30 Nov 2022 22:31:30 +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 2AUMVUbS023712; Wed, 30 Nov 2022 22:31:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AUMVUY6023711; Wed, 30 Nov 2022 22:31:30 GMT (envelope-from git) Date: Wed, 30 Nov 2022 22:31:30 GMT Message-Id: <202211302231.2AUMVUY6023711@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: b8ff248f6595 - main - stand/ofw: Subclass devnet to cope with ofw's unique needs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b8ff248f6595067ef9a31d5d4cec5fb9b9052fc3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b8ff248f6595067ef9a31d5d4cec5fb9b9052fc3 commit b8ff248f6595067ef9a31d5d4cec5fb9b9052fc3 Author: Warner Losh AuthorDate: 2022-11-30 22:10:05 +0000 Commit: Warner Losh CommitDate: 2022-11-30 22:30:33 +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 --- 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 };