Remove remaining uses of libsa/netif -- the "netif" structure was only

used to lookup a "struct of_dev", everything else was ballast.
Do it straightforward now and assign the ofdev directly to io_netif.
This commit is contained in:
drochner 2003-03-13 15:36:06 +00:00
parent 42cc9f8839
commit 66a5580c6e
6 changed files with 84 additions and 88 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.4 1999/05/07 16:19:28 drochner Exp $ */
/* $NetBSD: net.c,v 1.5 2003/03/13 15:36:06 drochner Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank.
@ -40,7 +40,7 @@
*
* At open time, this does:
*
* find interface - netif_open()
* find interface - netif_of_open()
* BOOTP - bootp()
* RPC/mountd - nfs_mount()
*
@ -59,10 +59,12 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>
#include <lib/libkern/libkern.h>
#include "ofdev.h"
#include "netif_of.h"
char rootpath[FNAME_SIZE];
static int netdev_sock = -1;
@ -77,13 +79,13 @@ net_open(op)
struct of_dev *op;
{
int error = 0;
/*
* On first open, do netif open, mount, etc.
*/
if (open_count == 0) {
/* Find network interface. */
if ((netdev_sock = netif_open(op)) < 0) {
if ((netdev_sock = netif_of_open(op)) < 0) {
error = errno;
goto bad;
}
@ -93,7 +95,7 @@ net_open(op)
open_count++;
bad:
if (netdev_sock >= 0 && open_count == 0) {
netif_close(netdev_sock);
netif_of_close(netdev_sock);
netdev_sock = -1;
}
return error;
@ -108,7 +110,7 @@ net_close(op)
*/
if (open_count > 0)
if (--open_count == 0) {
netif_close(netdev_sock);
netif_of_close(netdev_sock);
netdev_sock = -1;
}
}
@ -120,21 +122,21 @@ net_mountroot()
#ifdef DEBUG
printf("net_mountroot\n");
#endif
/*
* Get info for NFS boot: our IP address, out hostname,
* server IP address, and our root path on the server.
* We use BOOTP (RFC951, RFC1532) exclusively as mandated
* by PowerPC Reference Platform Specification I.4.2
*/
bootp(netdev_sock);
if (myip.s_addr == 0)
return ETIMEDOUT;
printf("Using IP address: %s\n", inet_ntoa(myip));
#ifdef DEBUG
printf("myip: %s (%s)", hostname, inet_ntoa(myip));
if (gateip.s_addr)
@ -144,7 +146,7 @@ net_mountroot()
printf("\n");
#endif
printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
/*
* Get the NFS file handle (mount).
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: netif_of.c,v 1.5 2001/07/22 14:43:15 wiz Exp $ */
/* $NetBSD: netif_of.c,v 1.6 2003/03/13 15:36:06 drochner Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank.
@ -50,14 +50,13 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>
#include "ofdev.h"
#include "openfirm.h"
static struct netif netif_of;
#include "netif_of.h"
struct iodesc sockets[SOPEN_MAX];
static struct iodesc sdesc;
struct iodesc *
socktodesc(sock)
@ -65,23 +64,22 @@ socktodesc(sock)
{
if (sock != 0)
return NULL;
return sockets;
return &sdesc;
}
int
netif_open(machdep_hint)
void *machdep_hint;
netif_of_open(op)
struct of_dev *op;
{
struct of_dev *op = machdep_hint;
struct iodesc *io;
int fd, error;
char addr[32];
#ifdef NETIF_DEBUG
printf("netif_open...");
#endif
/* find a free socket */
io = sockets;
io = &sdesc;
if (io->io_netif) {
#ifdef NETIF_DEBUG
printf("device busy\n");
@ -91,9 +89,8 @@ netif_open(machdep_hint)
}
memset(io, 0, sizeof *io);
netif_of.nif_devdata = op;
io->io_netif = &netif_of;
io->io_netif = (void *)op;
/* Put our ethernet address in io->myea */
OF_getprop(OF_instance_to_package(op->handle),
"mac-address", io->myea, sizeof io->myea);
@ -104,34 +101,29 @@ netif_open(machdep_hint)
return 0;
}
int
netif_close(fd)
void
netif_of_close(fd)
int fd;
{
struct iodesc *io;
struct netif *ni;
#ifdef NETIF_DEBUG
printf("netif_close(%x)...", fd);
#endif
if (fd != 0) {
#ifdef NETIF_DEBUG
printf("EBADF\n");
#endif
errno = EBADF;
return -1;
}
io = &sockets[fd];
ni = io->io_netif;
if (ni != NULL) {
ni->nif_devdata = NULL;
io->io_netif = NULL;
#ifdef NETIF_DEBUG
if (fd != 0) {
printf("EBADF\n");
return;
}
#endif
io = &sdesc;
io->io_netif = NULL;
#ifdef NETIF_DEBUG
printf("OK\n");
#endif
return 0;
}
/*
@ -148,7 +140,7 @@ netif_put(desc, pkt, len)
ssize_t rv;
size_t sendlen;
op = desc->io_netif->nif_devdata;
op = (struct of_dev *)desc->io_netif;
#ifdef NETIF_DEBUG
{
@ -195,7 +187,7 @@ netif_get(desc, pkt, maxlen, timo)
int tick0, tmo_ms;
int len;
op = desc->io_netif->nif_devdata;
op = (struct of_dev *)desc->io_netif;
#ifdef NETIF_DEBUG
printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",

View File

@ -0,0 +1,4 @@
/* $NetBSD: netif_of.h,v 1.1 2003/03/13 15:36:06 drochner Exp $ */
int netif_of_open(struct of_dev *);
void netif_of_close(int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.1 2002/02/10 01:58:17 thorpej Exp $ */
/* $NetBSD: net.c,v 1.2 2003/03/13 15:36:07 drochner Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank.
@ -40,7 +40,7 @@
*
* At open time, this does:
*
* find interface - netif_open()
* find interface - netif_of_open()
* BOOTP - bootp()
* RPC/mountd - nfs_mount()
*
@ -59,10 +59,12 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>
#include <lib/libkern/libkern.h>
#include "ofdev.h"
#include "netif_of.h"
char rootpath[FNAME_SIZE];
static int netdev_sock = -1;
@ -77,13 +79,13 @@ net_open(op)
struct of_dev *op;
{
int error = 0;
/*
* On first open, do netif open, mount, etc.
*/
if (open_count == 0) {
/* Find network interface. */
if ((netdev_sock = netif_open(op)) < 0) {
if ((netdev_sock = netif_of_open(op)) < 0) {
error = errno;
goto bad;
}
@ -93,7 +95,7 @@ net_open(op)
open_count++;
bad:
if (netdev_sock >= 0 && open_count == 0) {
netif_close(netdev_sock);
netif_of_close(netdev_sock);
netdev_sock = -1;
}
return error;
@ -108,7 +110,7 @@ net_close(op)
*/
if (open_count > 0)
if (--open_count == 0) {
netif_close(netdev_sock);
netif_of_close(netdev_sock);
netdev_sock = -1;
}
}
@ -120,21 +122,21 @@ net_mountroot()
#ifdef DEBUG
printf("net_mountroot\n");
#endif
/*
* Get info for NFS boot: our IP address, out hostname,
* server IP address, and our root path on the server.
* We use BOOTP (RFC951, RFC1532) exclusively as mandated
* by PowerPC Reference Platform Specification I.4.2
*/
bootp(netdev_sock);
if (myip.s_addr == 0)
return ETIMEDOUT;
printf("Using IP address: %s\n", inet_ntoa(myip));
#ifdef DEBUG
printf("myip: %s (%s)", hostname, inet_ntoa(myip));
if (gateip.s_addr)
@ -144,7 +146,7 @@ net_mountroot()
printf("\n");
#endif
printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
/*
* Get the NFS file handle (mount).
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: netif_of.c,v 1.1 2002/02/10 01:58:18 thorpej Exp $ */
/* $NetBSD: netif_of.c,v 1.2 2003/03/13 15:36:07 drochner Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank.
@ -50,14 +50,13 @@
#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>
#include "ofdev.h"
#include "openfirm.h"
static struct netif netif_of;
#include "netif_of.h"
struct iodesc sockets[SOPEN_MAX];
static struct iodesc sdesc;
struct iodesc *
socktodesc(sock)
@ -65,23 +64,22 @@ socktodesc(sock)
{
if (sock != 0)
return NULL;
return sockets;
return &sdesc;
}
int
netif_open(machdep_hint)
void *machdep_hint;
netif_of_open(op)
struct of_dev *op;
{
struct of_dev *op = machdep_hint;
struct iodesc *io;
int fd, error;
char addr[32];
#ifdef NETIF_DEBUG
printf("netif_open...");
#endif
/* find a free socket */
io = sockets;
io = &sdesc;
if (io->io_netif) {
#ifdef NETIF_DEBUG
printf("device busy\n");
@ -91,9 +89,8 @@ netif_open(machdep_hint)
}
memset(io, 0, sizeof *io);
netif_of.nif_devdata = op;
io->io_netif = &netif_of;
io->io_netif = (void *)op;
/* Put our ethernet address in io->myea */
OF_getprop(OF_instance_to_package(op->handle),
"mac-address", io->myea, sizeof io->myea);
@ -104,34 +101,29 @@ netif_open(machdep_hint)
return 0;
}
int
netif_close(fd)
void
netif_of_close(fd)
int fd;
{
struct iodesc *io;
struct netif *ni;
#ifdef NETIF_DEBUG
printf("netif_close(%x)...", fd);
#endif
if (fd != 0) {
#ifdef NETIF_DEBUG
printf("EBADF\n");
#endif
errno = EBADF;
return -1;
}
io = &sockets[fd];
ni = io->io_netif;
if (ni != NULL) {
ni->nif_devdata = NULL;
io->io_netif = NULL;
#ifdef NETIF_DEBUG
if (fd != 0) {
printf("EBADF\n");
return;
}
#endif
io = &sdesc;
io->io_netif = NULL;
#ifdef NETIF_DEBUG
printf("OK\n");
#endif
return 0;
}
/*
@ -148,7 +140,7 @@ netif_put(desc, pkt, len)
ssize_t rv;
size_t sendlen;
op = desc->io_netif->nif_devdata;
op = (struct of_dev *)desc->io_netif;
#ifdef NETIF_DEBUG
{
@ -195,7 +187,7 @@ netif_get(desc, pkt, maxlen, timo)
int tick0, tmo_ms;
int len;
op = desc->io_netif->nif_devdata;
op = (struct of_dev *)desc->io_netif;
#ifdef NETIF_DEBUG
printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",

View File

@ -0,0 +1,4 @@
/* $NetBSD: netif_of.h,v 1.1 2003/03/13 15:36:07 drochner Exp $ */
int netif_of_open(struct of_dev *);
void netif_of_close(int);