diff options
author | Marcus Brinkmann <marcus@gnu.org> | 2000-10-04 01:59:03 +0000 |
---|---|---|
committer | Marcus Brinkmann <marcus@gnu.org> | 2000-10-04 01:59:03 +0000 |
commit | 898424326fc1188384f67963ab6789f18dd57fd3 (patch) | |
tree | a4085609a66d34f0f0a59647ed236e64d3aa9bfc /pfinet/ethernet.c | |
parent | b81d9ec23532ba8b2519ba3b8bf68fcfeb0260c5 (diff) |
2000-10-04 Marcus Brinkmann <marcus@gnu.org>
* Makefile (SRCS): Add dummy.c
* dummy.c: New file.
* ethernet.c: Moved ETHER_PORT, READPT, READPTNAME to ...
(struct ether_device): ... here. New struct. ETHER_DEV is now a
pointer to a struct ether_device.
(ethernet_demuxer): New variables edev, dev. Iterate over linked
list ETHER_DEV to find correct readptname. Use dev instead
ETHER_DEV for socket buffer manipulation.
(ethernet_open): New variable edev. Use dev->priv to find correct
edev. Use members of edev instead global variables.
(ethernet_xmit): New variable edev. Use dev->priv to find correct
edev.Use member of edev instead global variable ETHER_PORT.
(setup_ethernet_device): New output argument DEVICE. New
variables edev and dev. Allocate memory for edev, add it to the
head of ETHER_DEV. Use dev instead ETHER_DEV. Use members of edev
instead global variables.
* main.c: ALREADY_OPEN removed.
(find_device): Fix comment. Redone to work with multiple devices
by iterating over DEV_BASE.
(enumerate_device): Likewise.
* pfinet.h: Add new argument to prototype of
setup_ethernet_device. Add prototype for setup_dummy_device.
Remove prototype for ETHER_DEV. Add prototype for DEV_BASE.
Diffstat (limited to 'pfinet/ethernet.c')
-rw-r--r-- | pfinet/ethernet.c | 110 |
1 files changed, 66 insertions, 44 deletions
diff --git a/pfinet/ethernet.c b/pfinet/ethernet.c index 1b81e1aa..f6e50a2c 100644 --- a/pfinet/ethernet.c +++ b/pfinet/ethernet.c @@ -31,13 +31,19 @@ #include <linux/if_arp.h> -device_t ether_port; - struct port_class *etherreadclass; -struct port_info *readpt; -mach_port_t readptname; -struct device ether_dev; +struct ether_device +{ + struct ether_device *next; + device_t ether_port; + struct port_info *readpt; + mach_port_t readptname; + struct device dev; +}; + +/* Linked list of all ethernet devices. */ +struct ether_device *ether_dev; struct enet_statistics retbuf; @@ -86,11 +92,17 @@ ethernet_demuxer (mach_msg_header_t *inp, struct net_rcv_msg *msg = (struct net_rcv_msg *) inp; struct sk_buff *skb; int datalen; + struct ether_device *edev; + struct device *dev = 0; if (inp->msgh_id != NET_RCV_MSG_ID) return 0; - if (inp->msgh_local_port != readptname) + for (edev = ether_dev; edev; edev = edev->next) + if (inp->msgh_local_port == edev->readptname) + dev = &edev->dev; + + if (! dev) { if (inp->msgh_remote_port != MACH_PORT_NULL) mach_port_deallocate (mach_task_self (), inp->msgh_remote_port); @@ -103,7 +115,7 @@ ethernet_demuxer (mach_msg_header_t *inp, __mutex_lock (&net_bh_lock); skb = alloc_skb (datalen, GFP_ATOMIC); skb->len = datalen; - skb->dev = ðer_dev; + skb->dev = dev; /* Copy the two parts of the frame into the buffer. */ bcopy (msg->header, skb->data, ETH_HLEN); @@ -112,7 +124,7 @@ ethernet_demuxer (mach_msg_header_t *inp, datalen - ETH_HLEN); /* Drop it on the queue. */ - skb->protocol = eth_type_trans (skb, ðer_dev); + skb->protocol = eth_type_trans (skb, dev); netif_rx (skb); __mutex_unlock (&net_bh_lock); @@ -134,28 +146,29 @@ ethernet_open (struct device *dev) { error_t err; device_t master_device; + struct ether_device *edev = (struct ether_device *) dev->priv; - assert (ether_port == MACH_PORT_NULL); + assert (edev->ether_port == MACH_PORT_NULL); err = ports_create_port (etherreadclass, etherport_bucket, - sizeof (struct port_info), &readpt); + sizeof (struct port_info), &edev->readpt); assert_perror (err); - readptname = ports_get_right (readpt); - mach_port_insert_right (mach_task_self (), readptname, readptname, + edev->readptname = ports_get_right (edev->readpt); + mach_port_insert_right (mach_task_self (), edev->readptname, edev->readptname, MACH_MSG_TYPE_MAKE_SEND); - mach_port_set_qlimit (mach_task_self (), readptname, MACH_PORT_QLIMIT_MAX); + mach_port_set_qlimit (mach_task_self (), edev->readptname, MACH_PORT_QLIMIT_MAX); err = get_privileged_ports (0, &master_device); if (err) error (2, err, "cannot get device master port"); - err = device_open (master_device, D_WRITE | D_READ, dev->name, ðer_port); + err = device_open (master_device, D_WRITE | D_READ, dev->name, &edev->ether_port); mach_port_deallocate (mach_task_self (), master_device); if (err) error (2, err, "%s", dev->name); - err = device_set_filter (ether_port, ports_get_right (readpt), + err = device_set_filter (edev->ether_port, ports_get_right (edev->readpt), MACH_MSG_TYPE_MAKE_SEND, 0, ether_filter, ether_filter_len); if (err) @@ -168,10 +181,11 @@ ethernet_open (struct device *dev) int ethernet_xmit (struct sk_buff *skb, struct device *dev) { - u_int count; error_t err; + struct ether_device *edev = (struct ether_device *) dev->priv; + u_int count; - err = device_write (ether_port, D_NOWAIT, 0, skb->data, skb->len, &count); + err = device_write (edev->ether_port, D_NOWAIT, 0, skb->data, skb->len, &count); assert_perror (err); assert (count == skb->len); dev_kfree_skb (skb); @@ -179,69 +193,77 @@ ethernet_xmit (struct sk_buff *skb, struct device *dev) } void -setup_ethernet_device (char *name) +setup_ethernet_device (char *name, struct device **device) { struct net_status netstat; u_int count; int net_address[2]; error_t err; + struct ether_device *edev; + struct device *dev; - bzero (ðer_dev, sizeof ether_dev); + edev = calloc (1, sizeof (struct ether_device)); + if (!edev) + error (2, ENOMEM, "%s", name); + edev->next = ether_dev; + ether_dev = edev; - ether_dev.name = strdup (name); + *device = dev = &edev->dev; + dev->name = strdup (name); /* Functions. These ones are the true "hardware layer" in Linux. */ - ether_dev.open = 0; /* We set up before calling dev_open. */ - ether_dev.stop = ethernet_stop; - ether_dev.hard_start_xmit = ethernet_xmit; - ether_dev.get_stats = ethernet_get_stats; - ether_dev.set_multicast_list = ethernet_set_multi; + dev->open = 0; /* We set up before calling dev_open. */ + dev->stop = ethernet_stop; + dev->hard_start_xmit = ethernet_xmit; + dev->get_stats = ethernet_get_stats; + dev->set_multicast_list = ethernet_set_multi; /* These are the ones set by drivers/net/net_init.c::ether_setup. */ - ether_dev.hard_header = eth_header; - ether_dev.rebuild_header = eth_rebuild_header; - ether_dev.hard_header_cache = eth_header_cache; - ether_dev.header_cache_update = eth_header_cache_update; - ether_dev.hard_header_parse = eth_header_parse; + dev->hard_header = eth_header; + dev->rebuild_header = eth_rebuild_header; + dev->hard_header_cache = eth_header_cache; + dev->header_cache_update = eth_header_cache_update; + dev->hard_header_parse = eth_header_parse; /* We can't do these two (and we never try anyway). */ - /* ether_dev.change_mtu = eth_change_mtu; */ - /* ether_dev.set_mac_address = eth_mac_addr; */ + /* dev->change_mtu = eth_change_mtu; */ + /* dev->set_mac_address = eth_mac_addr; */ /* Some more fields */ - ether_dev.type = ARPHRD_ETHER; - ether_dev.hard_header_len = ETH_HLEN; - ether_dev.addr_len = ETH_ALEN; - memset (ether_dev.broadcast, 0xff, ETH_ALEN); - ether_dev.flags = IFF_BROADCAST | IFF_MULTICAST; - dev_init_buffers (ðer_dev); + dev->priv = edev; /* For reverse lookup. */ + dev->type = ARPHRD_ETHER; + dev->hard_header_len = ETH_HLEN; + dev->addr_len = ETH_ALEN; + memset (dev->broadcast, 0xff, ETH_ALEN); + dev->flags = IFF_BROADCAST | IFF_MULTICAST; + dev_init_buffers (dev); - ethernet_open (ðer_dev); + ethernet_open (dev); /* Fetch hardware information */ count = NET_STATUS_COUNT; - err = device_get_status (ether_port, NET_STATUS, + err = device_get_status (edev->ether_port, NET_STATUS, (dev_status_t) &netstat, &count); if (err) error (2, err, "%s: Cannot get device status", name); - ether_dev.mtu = netstat.max_packet_size - ether_dev.hard_header_len; + dev->mtu = netstat.max_packet_size - dev->hard_header_len; assert (netstat.header_format == HDR_ETHERNET); assert (netstat.header_size == ETH_HLEN); assert (netstat.address_size == ETH_ALEN); count = 2; assert (count * sizeof (int) >= ETH_ALEN); - err = device_get_status (ether_port, NET_ADDRESS, net_address, &count); + err = device_get_status (edev->ether_port, NET_ADDRESS, net_address, &count); if (err) error (2, err, "%s: Cannot get hardware Ethernet address", name); net_address[0] = ntohl (net_address[0]); net_address[1] = ntohl (net_address[1]); - bcopy (net_address, ether_dev.dev_addr, ETH_ALEN); + bcopy (net_address, dev->dev_addr, ETH_ALEN); /* That should be enough. */ /* This call adds the device to the `dev_base' chain, initializes its `ifindex' member (which matters!), and tells the protocol stacks about the device. */ - err = - register_netdevice (ðer_dev); + err = - register_netdevice (dev); assert_perror (err); } |