minix/minix/include/minix/netdriver.h
David van Moolenbroek dbcce9ddb0 libnetdriver: turn into network driver framework
The new implementation of this library provides abstractions for
network drivers, and should be used for all network drivers from now
on.  It provides the following functionality:

  - a function call table abstraction, hiding the details of the
    datalink protocol with simple parameters;
  - a state machine for sending and receiving packets, freeing the
    actual driver from keeping track of pending requests;
  - an abstraction for copying data from and to the network driver,
    freeing the actual driver from dealing with I/O vectors while at
    the same time providing a copy implementation which is more
    efficient than most current driver implementations;
  - a generalized implementation of zero-copy port-based I/O;
  - a clearer set of policies and defaults.

While the concept is very similar to lib{block,char,fs,input}driver,
one main difference is that libnetdriver now also takes care of SEF
initialization, mainly so that aspects such as recovery policies and
live-update aspects can be changed for all network drivers in a
single place.  As always, for the case that the provided message loop
is too restrictive, a set of more low-level message processing
functions is provided.

The netdriver API has been designed so as to allow alleviation of one
current protocol bottleneck: the fact that at most one send request
and one receive request may be pending at any time.  Changing this
aspect will however require a significant rewrite of libnetdriver,
and possibly debugging of drivers that are not able to cope with (in
particular) queuing multiple packets for transmission at once.

Beyond that, the design of the new API is based on the current
protocol, and may be changed/extended later to allow for non-ethernet
network drivers, exposure of link status, multicast address
configuration, suspend and resume, and any other features that are in
fact long overdue.

Change-Id: I47ec47e05852c42f92af04549d41524f928efec2
2014-12-04 12:10:48 +00:00

68 lines
2.3 KiB
C

/* Prototypes and definitions for network drivers. */
#ifndef _MINIX_NETDRIVER_H
#define _MINIX_NETDRIVER_H
#include <minix/endpoint.h>
#include <minix/ipc.h>
#include <minix/com.h>
/* The flags that make up the requested receive mode. */
#define NDEV_NOMODE DL_NOMODE /* targeted packets only */
#define NDEV_PROMISC DL_PROMISC_REQ /* promiscuous mode */
#define NDEV_MULTI DL_MULTI_REQ /* receive multicast packets */
#define NDEV_BROAD DL_BROAD_REQ /* receive broadcast packets */
/*
* For now, only ethernet-type network drivers are supported, and thus, we use
* some ethernet-specific data structures.
*/
#include <net/gen/ether.h>
#include <net/gen/eth_io.h>
/* Opaque data structure for copying in and out actual packet data. */
struct netdriver_data;
/* Function call table for network drivers. */
struct netdriver {
int (*ndr_init)(unsigned int instance, ether_addr_t *addr);
void (*ndr_stop)(void);
void (*ndr_mode)(unsigned int mode);
ssize_t (*ndr_recv)(struct netdriver_data *data, size_t max);
int (*ndr_send)(struct netdriver_data *data, size_t size);
void (*ndr_stat)(eth_stat_t *stat);
void (*ndr_intr)(unsigned int mask);
void (*ndr_alarm)(clock_t stamp);
void (*ndr_other)(const message *m_ptr, int ipc_status);
};
/* Functions defined by libnetdriver. */
void netdriver_task(const struct netdriver *ndp);
void netdriver_announce(void); /* legacy; deprecated */
int netdriver_init(const struct netdriver *ndp);
void netdriver_process(const struct netdriver * __restrict ndp,
const message * __restrict m_ptr, int ipc_status);
void netdriver_terminate(void);
void netdriver_recv(void);
void netdriver_send(void);
void netdriver_copyin(struct netdriver_data * __restrict data, size_t off,
void * __restrict ptr, size_t size);
void netdriver_copyout(struct netdriver_data * __restrict data, size_t off,
const void * __restrict ptr, size_t size);
void netdriver_portinb(struct netdriver_data *data, size_t off, long port,
size_t size);
void netdriver_portoutb(struct netdriver_data *data, size_t off, long port,
size_t size);
void netdriver_portinw(struct netdriver_data *data, size_t off, long port,
size_t size);
void netdriver_portoutw(struct netdriver_data *data, size_t off, long port,
size_t size);
#define netdriver_receive sef_receive_status /* legacy; deprecated */
#endif /* _MINIX_NETDRIVER_H */