mirror of
https://github.com/86Box/86Box.git
synced 2026-02-25 12:55:32 -07:00
Network overhaul : support for multiple NICs, performance improvement
- Add support for multiple NICs - Switch from polling to an event loop for the host networking to avoid latency and locking issues
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
#define HAVE_STDARG_H
|
||||
#include <86box/86box.h>
|
||||
#include <86box/device.h>
|
||||
@@ -63,6 +64,7 @@
|
||||
#include <86box/plat.h>
|
||||
#include <86box/thread.h>
|
||||
#include <86box/ui.h>
|
||||
#include <86box/timer.h>
|
||||
#include <86box/network.h>
|
||||
#include <86box/net_3c503.h>
|
||||
#include <86box/net_ne2000.h>
|
||||
@@ -70,6 +72,11 @@
|
||||
#include <86box/net_plip.h>
|
||||
#include <86box/net_wd8003.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
static const device_t net_none_device = {
|
||||
.name = "None",
|
||||
@@ -86,32 +93,32 @@ static const device_t net_none_device = {
|
||||
};
|
||||
|
||||
|
||||
static netcard_t net_cards[] = {
|
||||
// clang-format off
|
||||
{ &net_none_device, NULL },
|
||||
{ &threec503_device, NULL },
|
||||
{ &pcnet_am79c960_device, NULL },
|
||||
{ &pcnet_am79c961_device, NULL },
|
||||
{ &ne1000_device, NULL },
|
||||
{ &ne2000_device, NULL },
|
||||
{ &pcnet_am79c960_eb_device, NULL },
|
||||
{ &rtl8019as_device, NULL },
|
||||
{ &wd8003e_device, NULL },
|
||||
{ &wd8003eb_device, NULL },
|
||||
{ &wd8013ebt_device, NULL },
|
||||
{ &plip_device, NULL },
|
||||
{ ðernext_mc_device, NULL },
|
||||
{ &wd8003eta_device, NULL },
|
||||
{ &wd8003ea_device, NULL },
|
||||
{ &wd8013epa_device, NULL },
|
||||
{ &pcnet_am79c973_device, NULL },
|
||||
{ &pcnet_am79c970a_device, NULL },
|
||||
{ &rtl8029as_device, NULL },
|
||||
{ &pcnet_am79c960_vlb_device, NULL },
|
||||
{ NULL, NULL }
|
||||
// clang-format off
|
||||
static const device_t *net_cards[] = {
|
||||
&net_none_device,
|
||||
&threec503_device,
|
||||
&pcnet_am79c960_device,
|
||||
&pcnet_am79c961_device,
|
||||
&ne1000_device,
|
||||
&ne2000_device,
|
||||
&pcnet_am79c960_eb_device,
|
||||
&rtl8019as_device,
|
||||
&wd8003e_device,
|
||||
&wd8003eb_device,
|
||||
&wd8013ebt_device,
|
||||
&plip_device,
|
||||
ðernext_mc_device,
|
||||
&wd8003eta_device,
|
||||
&wd8003ea_device,
|
||||
&wd8013epa_device,
|
||||
&pcnet_am79c973_device,
|
||||
&pcnet_am79c970a_device,
|
||||
&rtl8029as_device,
|
||||
&pcnet_am79c960_vlb_device,
|
||||
NULL
|
||||
};
|
||||
|
||||
netcard_conf_t net_cards_conf[NET_CARD_MAX];
|
||||
int net_card_current = 0;
|
||||
|
||||
/* Global variables. */
|
||||
int network_type;
|
||||
@@ -119,20 +126,9 @@ int network_ndev;
|
||||
int network_card;
|
||||
char network_host[522];
|
||||
netdev_t network_devs[32];
|
||||
int network_rx_pause = 0,
|
||||
network_tx_pause = 0;
|
||||
|
||||
|
||||
/* Local variables. */
|
||||
static volatile atomic_int net_wait = 0;
|
||||
static mutex_t *network_mutex;
|
||||
static uint8_t *network_mac;
|
||||
static uint8_t network_timer_active = 0;
|
||||
static pc_timer_t network_rx_queue_timer;
|
||||
static netpkt_t *first_pkt[3] = { NULL, NULL, NULL },
|
||||
*last_pkt[3] = { NULL, NULL, NULL };
|
||||
static netpkt_t queued_pkt;
|
||||
|
||||
|
||||
#ifdef ENABLE_NETWORK_LOG
|
||||
int network_do_log = ENABLE_NETWORK_LOG;
|
||||
@@ -191,15 +187,13 @@ network_dump_packet(netpkt_t *pkt)
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
network_wait(uint8_t wait)
|
||||
#ifdef _WIN32
|
||||
static void
|
||||
network_winsock_clean(void)
|
||||
{
|
||||
if (wait)
|
||||
thread_wait_mutex(network_mutex);
|
||||
else
|
||||
thread_release_mutex(network_mutex);
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize the configured network cards.
|
||||
@@ -213,9 +207,11 @@ network_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Initialize to a known state. */
|
||||
network_type = NET_TYPE_NONE;
|
||||
network_card = 0;
|
||||
#ifdef _WIN32
|
||||
WSADATA Data;
|
||||
WSAStartup(MAKEWORD(2, 0), &Data);
|
||||
atexit(network_winsock_clean);
|
||||
#endif
|
||||
|
||||
/* Create a first device entry that's always there, as needed by UI. */
|
||||
strcpy(network_devs[0].device, "none");
|
||||
@@ -247,156 +243,133 @@ network_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_queue_put(int tx, void *priv, uint8_t *data, int len)
|
||||
{
|
||||
netpkt_t *temp;
|
||||
|
||||
temp = (netpkt_t *) calloc(sizeof(netpkt_t), 1);
|
||||
temp->priv = priv;
|
||||
memcpy(temp->data, data, len);
|
||||
temp->len = len;
|
||||
temp->prev = last_pkt[tx];
|
||||
temp->next = NULL;
|
||||
|
||||
if (last_pkt[tx] != NULL)
|
||||
last_pkt[tx]->next = temp;
|
||||
last_pkt[tx] = temp;
|
||||
|
||||
if (first_pkt[tx] == NULL)
|
||||
first_pkt[tx] = temp;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
network_queue_get(int tx, netpkt_t *pkt)
|
||||
network_queue_init(netqueue_t *queue)
|
||||
{
|
||||
netpkt_t *temp;
|
||||
|
||||
temp = first_pkt[tx];
|
||||
|
||||
if (temp == NULL) {
|
||||
memset(pkt, 0x00, sizeof(netpkt_t));
|
||||
return;
|
||||
queue->size = NET_QUEUE_LEN;
|
||||
queue->head = queue->tail = 0;
|
||||
for (int i=0; i<queue->size; i++) {
|
||||
queue->packets[i].data = calloc(1, NET_MAX_FRAME);
|
||||
queue->packets[i].len = 0;
|
||||
}
|
||||
|
||||
memcpy(pkt, temp, sizeof(netpkt_t));
|
||||
|
||||
first_pkt[tx] = temp->next;
|
||||
free(temp);
|
||||
|
||||
if (first_pkt[tx] == NULL)
|
||||
last_pkt[tx] = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
network_queue_transmit(int tx)
|
||||
static bool
|
||||
network_queue_full(netqueue_t *queue)
|
||||
{
|
||||
netpkt_t *temp;
|
||||
return ((queue->head + 1) % queue->size) == queue->tail;
|
||||
}
|
||||
|
||||
temp = first_pkt[tx];
|
||||
static bool
|
||||
network_queue_empty(netqueue_t *queue)
|
||||
{
|
||||
return (queue->head == queue->tail);
|
||||
}
|
||||
|
||||
if (temp == NULL)
|
||||
return;
|
||||
|
||||
if (temp->len > 0) {
|
||||
network_dump_packet(temp);
|
||||
/* Why on earth is this not a function pointer?! */
|
||||
switch(network_type) {
|
||||
case NET_TYPE_PCAP:
|
||||
net_pcap_in(temp->data, temp->len);
|
||||
break;
|
||||
|
||||
case NET_TYPE_SLIRP:
|
||||
net_slirp_in(temp->data, temp->len);
|
||||
break;
|
||||
}
|
||||
int
|
||||
network_queue_put(netqueue_t *queue, uint8_t *data, int len)
|
||||
{
|
||||
if (len > NET_MAX_FRAME || network_queue_full(queue)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
first_pkt[tx] = temp->next;
|
||||
free(temp);
|
||||
|
||||
if (first_pkt[tx] == NULL)
|
||||
last_pkt[tx] = NULL;
|
||||
netpkt_t *pkt = &queue->packets[queue->head];
|
||||
memcpy(pkt->data, data, len);
|
||||
pkt->len = len;
|
||||
queue->head = (queue->head + 1) % queue->size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
network_queue_get(netqueue_t *queue, netpkt_t *dst_pkt) {
|
||||
if (network_queue_empty(queue))
|
||||
return 0;
|
||||
|
||||
static void
|
||||
network_queue_copy(int dest, int src)
|
||||
{
|
||||
netpkt_t *temp, *temp2;
|
||||
netpkt_t *pkt = &queue->packets[queue->tail];
|
||||
memcpy(dst_pkt->data, pkt->data, pkt->len);
|
||||
dst_pkt->len = pkt->len;
|
||||
queue->tail = (queue->tail + 1) % queue->size;
|
||||
|
||||
temp = first_pkt[src];
|
||||
|
||||
if (temp == NULL)
|
||||
return;
|
||||
|
||||
temp2 = (netpkt_t *) calloc(sizeof(netpkt_t), 1);
|
||||
temp2->priv = temp->priv;
|
||||
memcpy(temp2->data, temp->data, temp->len);
|
||||
temp2->len = temp->len;
|
||||
temp2->prev = last_pkt[dest];
|
||||
temp2->next = NULL;
|
||||
|
||||
if (last_pkt[dest] != NULL)
|
||||
last_pkt[dest]->next = temp2;
|
||||
last_pkt[dest] = temp2;
|
||||
|
||||
if (first_pkt[dest] == NULL)
|
||||
first_pkt[dest] = temp2;
|
||||
|
||||
first_pkt[src] = temp->next;
|
||||
free(temp);
|
||||
|
||||
if (first_pkt[src] == NULL)
|
||||
last_pkt[src] = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
network_queue_move(netqueue_t *dst_q, netqueue_t *src_q)
|
||||
{
|
||||
if (network_queue_empty(src_q))
|
||||
return 0;
|
||||
|
||||
if (network_queue_full(dst_q)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
netpkt_t *src_pkt = &src_q->packets[src_q->tail];
|
||||
netpkt_t *dst_pkt = &dst_q->packets[dst_q->head];
|
||||
uint8_t *tmp_dat = dst_pkt->data;
|
||||
|
||||
dst_pkt->data = src_pkt->data;
|
||||
dst_pkt->len = src_pkt->len;
|
||||
dst_q->head = (dst_q->head + 1) % dst_q->size;
|
||||
|
||||
src_pkt->data = tmp_dat;
|
||||
src_pkt->len = 0;
|
||||
src_q->tail = (src_q->tail + 1) % src_q->size;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
network_queue_clear(int tx)
|
||||
network_queue_clear(netqueue_t *queue)
|
||||
{
|
||||
netpkt_t *temp = first_pkt[tx], *temp2;
|
||||
|
||||
if (temp == NULL)
|
||||
return;
|
||||
|
||||
do {
|
||||
temp2 = temp->next;
|
||||
free(temp);
|
||||
temp = temp2;
|
||||
} while (temp != NULL);
|
||||
|
||||
first_pkt[tx] = last_pkt[tx] = NULL;
|
||||
for (int i=0; i<queue->size; i++) {
|
||||
free(queue->packets[i].data);
|
||||
queue->packets[i].len = 0;
|
||||
}
|
||||
queue->tail = queue->head = 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
network_rx_queue(void *priv)
|
||||
{
|
||||
int ret = 1;
|
||||
netcard_t *card = (netcard_t *)priv;
|
||||
double timer_period;
|
||||
int ret = 0;
|
||||
|
||||
if (network_rx_pause || !thread_test_mutex(network_mutex)) {
|
||||
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0);
|
||||
return;
|
||||
bool activity = false;
|
||||
|
||||
if (card->queued_pkt.len == 0) {
|
||||
thread_wait_mutex(card->rx_mutex);
|
||||
network_queue_get(&card->queues[NET_QUEUE_RX], &card->queued_pkt);
|
||||
thread_release_mutex(card->rx_mutex);
|
||||
}
|
||||
|
||||
if (queued_pkt.len == 0)
|
||||
network_queue_get(0, &queued_pkt);
|
||||
if (queued_pkt.len > 0) {
|
||||
network_dump_packet(&queued_pkt);
|
||||
ret = net_cards[network_card].rx(queued_pkt.priv, queued_pkt.data, queued_pkt.len);
|
||||
if (card->queued_pkt.len > 0) {
|
||||
network_dump_packet(&card->queued_pkt);
|
||||
ret = card->rx(card->card_drv, card->queued_pkt.data, card->queued_pkt.len);
|
||||
}
|
||||
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * ((queued_pkt.len >= 128) ? ((double) queued_pkt.len) : 128.0));
|
||||
if (ret)
|
||||
queued_pkt.len = 0;
|
||||
|
||||
if (ret) {
|
||||
activity = true;
|
||||
timer_period = 0.762939453125 * ((card->queued_pkt.len >= 128) ? ((double) card->queued_pkt.len) : 128.0);
|
||||
card->queued_pkt.len = 0;
|
||||
} else {
|
||||
timer_period = 0.762939453125 * 128.0;
|
||||
}
|
||||
timer_on_auto(&card->timer, timer_period);
|
||||
|
||||
/* Transmission. */
|
||||
network_queue_copy(1, 2);
|
||||
thread_wait_mutex(card->tx_mutex);
|
||||
ret = network_queue_move(&card->queues[NET_QUEUE_TX_HOST], &card->queues[NET_QUEUE_TX_VM]);
|
||||
thread_release_mutex(card->tx_mutex);
|
||||
if (ret) {
|
||||
/* Notify host that a packet is available in the TX queue */
|
||||
card->host_drv.notify_in(card->host_drv.priv);
|
||||
activity = true;
|
||||
}
|
||||
|
||||
network_wait(0);
|
||||
ui_sb_update_icon(SB_NETWORK, activity);
|
||||
}
|
||||
|
||||
|
||||
@@ -407,51 +380,67 @@ network_rx_queue(void *priv)
|
||||
* finished initializing itself, to link itself to the platform support
|
||||
* modules.
|
||||
*/
|
||||
void
|
||||
network_attach(void *dev, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKSTATE set_link_state)
|
||||
netcard_t *
|
||||
network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKSTATE set_link_state)
|
||||
{
|
||||
if (network_card == 0) return;
|
||||
netcard_t *card = calloc(1, sizeof(netcard_t));
|
||||
card->queued_pkt.data = calloc(1, NET_MAX_FRAME);
|
||||
card->card_drv = card_drv;
|
||||
card->rx = rx;
|
||||
card->wait = wait;
|
||||
card->set_link_state = set_link_state;
|
||||
card->tx_mutex = thread_create_mutex();
|
||||
card->rx_mutex = thread_create_mutex();
|
||||
|
||||
/* Save the card's info. */
|
||||
net_cards[network_card].priv = dev;
|
||||
net_cards[network_card].rx = rx;
|
||||
net_cards[network_card].wait = wait;
|
||||
net_cards[network_card].set_link_state = set_link_state;
|
||||
network_mac = mac;
|
||||
|
||||
network_set_wait(0);
|
||||
|
||||
/* Activate the platform module. */
|
||||
switch(network_type) {
|
||||
case NET_TYPE_PCAP:
|
||||
(void)net_pcap_reset(&net_cards[network_card], network_mac);
|
||||
break;
|
||||
|
||||
case NET_TYPE_SLIRP:
|
||||
(void)net_slirp_reset(&net_cards[network_card], network_mac);
|
||||
break;
|
||||
for (int i=0; i<3; i++) {
|
||||
network_queue_init(&card->queues[i]);
|
||||
}
|
||||
|
||||
first_pkt[0] = first_pkt[1] = first_pkt[2] = NULL;
|
||||
last_pkt[0] = last_pkt[1] = last_pkt[2] = NULL;
|
||||
memset(&queued_pkt, 0x00, sizeof(netpkt_t));
|
||||
memset(&network_rx_queue_timer, 0x00, sizeof(pc_timer_t));
|
||||
timer_add(&network_rx_queue_timer, network_rx_queue, NULL, 0);
|
||||
/* 10 mbps. */
|
||||
timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0);
|
||||
network_timer_active = 1;
|
||||
switch (net_cards_conf[net_card_current].net_type) {
|
||||
case NET_TYPE_SLIRP:
|
||||
default:
|
||||
card->host_drv = net_slirp_drv;
|
||||
card->host_drv.priv = card->host_drv.init(card, mac, NULL);
|
||||
break;
|
||||
|
||||
case NET_TYPE_PCAP:
|
||||
card->host_drv = net_pcap_drv;
|
||||
card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!card->host_drv.priv) {
|
||||
thread_close_mutex(card->tx_mutex);
|
||||
thread_close_mutex(card->rx_mutex);
|
||||
for (int i=0; i<3; i++) {
|
||||
network_queue_clear(&card->queues[i]);
|
||||
}
|
||||
|
||||
free(card->queued_pkt.data);
|
||||
free(card);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
timer_add(&card->timer, network_rx_queue, card, 0);
|
||||
timer_on_auto(&card->timer, 0.762939453125 * 2.0);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
|
||||
/* Stop the network timer. */
|
||||
void
|
||||
network_timer_stop(void)
|
||||
netcard_close(netcard_t *card)
|
||||
{
|
||||
if (network_timer_active) {
|
||||
timer_stop(&network_rx_queue_timer);
|
||||
memset(&network_rx_queue_timer, 0x00, sizeof(pc_timer_t));
|
||||
network_timer_active = 0;
|
||||
timer_stop(&card->timer);
|
||||
card->host_drv.close(card->host_drv.priv);
|
||||
|
||||
thread_close_mutex(card->tx_mutex);
|
||||
thread_close_mutex(card->rx_mutex);
|
||||
for (int i=0; i<3; i++) {
|
||||
network_queue_clear(&card->queues[i]);
|
||||
}
|
||||
|
||||
free(card->queued_pkt.data);
|
||||
free(card);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,30 +448,11 @@ network_timer_stop(void)
|
||||
void
|
||||
network_close(void)
|
||||
{
|
||||
network_timer_stop();
|
||||
|
||||
/* If already closed, do nothing. */
|
||||
if (network_mutex == NULL) return;
|
||||
|
||||
/* Force-close the PCAP module. */
|
||||
net_pcap_close();
|
||||
|
||||
/* Force-close the SLIRP module. */
|
||||
net_slirp_close();
|
||||
|
||||
/* Close the network thread mutex. */
|
||||
thread_close_mutex(network_mutex);
|
||||
network_mutex = NULL;
|
||||
network_mac = NULL;
|
||||
#ifdef ENABLE_NETWORK_LOG
|
||||
thread_close_mutex(network_dump_mutex);
|
||||
network_dump_mutex = NULL;
|
||||
#endif
|
||||
|
||||
/* Here is where we clear the queues. */
|
||||
network_queue_clear(0);
|
||||
network_queue_clear(1);
|
||||
|
||||
network_log("NETWORK: closed.\n");
|
||||
}
|
||||
|
||||
@@ -500,86 +470,52 @@ network_reset(void)
|
||||
{
|
||||
int i = -1;
|
||||
|
||||
network_log("NETWORK: reset (type=%d, card=%d)\n",
|
||||
network_type, network_card);
|
||||
|
||||
ui_sb_update_icon(SB_NETWORK, 0);
|
||||
|
||||
/* Just in case.. */
|
||||
network_close();
|
||||
|
||||
/* If no active card, we're done. */
|
||||
if ((network_type==NET_TYPE_NONE) || (network_card==0)) return;
|
||||
|
||||
network_mutex = thread_create_mutex();
|
||||
#ifdef ENABLE_NETWORK_LOG
|
||||
network_dump_mutex = thread_create_mutex();
|
||||
#endif
|
||||
|
||||
/* Initialize the platform module. */
|
||||
switch(network_type) {
|
||||
case NET_TYPE_PCAP:
|
||||
i = net_pcap_init();
|
||||
break;
|
||||
for (i = 0; i < NET_CARD_MAX; i++) {
|
||||
if (!net_cards_conf[i].device_num || net_cards_conf[i].net_type == NET_TYPE_NONE ||
|
||||
(net_cards_conf[i].net_type == NET_TYPE_PCAP && !strcmp(net_cards_conf[i].host_dev_name, "none"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
case NET_TYPE_SLIRP:
|
||||
i = net_slirp_init();
|
||||
break;
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
/* Tell user we can't do this (at the moment.) */
|
||||
ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2093, (wchar_t *) IDS_2129);
|
||||
|
||||
// FIXME: we should ask in the dialog if they want to
|
||||
// reconfigure or quit, and throw them into the
|
||||
// Settings dialog if yes.
|
||||
|
||||
/* Disable network. */
|
||||
network_type = NET_TYPE_NONE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
network_log("NETWORK: set up for %s, card='%s'\n",
|
||||
(network_type==NET_TYPE_SLIRP)?"SLiRP":"Pcap",
|
||||
net_cards[network_card].device->name);
|
||||
|
||||
/* Add the (new?) card to the I/O system. */
|
||||
if (net_cards[network_card].device) {
|
||||
network_log("NETWORK: adding device '%s'\n",
|
||||
net_cards[network_card].device->name);
|
||||
device_add(net_cards[network_card].device);
|
||||
net_card_current = i;
|
||||
device_add_inst(net_cards[net_cards_conf[i].device_num], i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Queue a packet for transmission to one of the network providers. */
|
||||
void
|
||||
network_tx(uint8_t *bufp, int len)
|
||||
network_tx(netcard_t *card, uint8_t *bufp, int len)
|
||||
{
|
||||
ui_sb_update_icon(SB_NETWORK, 1);
|
||||
|
||||
network_queue_put(2, NULL, bufp, len);
|
||||
|
||||
ui_sb_update_icon(SB_NETWORK, 0);
|
||||
network_queue_put(&card->queues[NET_QUEUE_TX_VM], bufp, len);
|
||||
}
|
||||
|
||||
|
||||
/* Actually transmit the packet. */
|
||||
int
|
||||
network_tx_queue_check(void)
|
||||
int network_tx_pop(netcard_t *card, netpkt_t *out_pkt)
|
||||
{
|
||||
if ((first_pkt[1] == NULL) && (last_pkt[1] == NULL))
|
||||
return 0;
|
||||
int ret = 0;
|
||||
|
||||
if (network_tx_pause)
|
||||
return 1;
|
||||
thread_wait_mutex(card->tx_mutex);
|
||||
ret = network_queue_get(&card->queues[NET_QUEUE_TX_HOST], out_pkt);
|
||||
thread_release_mutex(card->tx_mutex);
|
||||
|
||||
network_queue_transmit(1);
|
||||
return 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int network_rx_put(netcard_t *card, uint8_t *bufp, int len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
thread_wait_mutex(card->rx_mutex);
|
||||
ret = network_queue_put(&card->queues[NET_QUEUE_RX], bufp, len);
|
||||
thread_release_mutex(card->rx_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
network_dev_to_id(char *devname)
|
||||
@@ -601,9 +537,13 @@ network_dev_to_id(char *devname)
|
||||
int
|
||||
network_available(void)
|
||||
{
|
||||
if ((network_type == NET_TYPE_NONE) || (network_card == 0)) return(0);
|
||||
int available = 0;
|
||||
|
||||
return(1);
|
||||
for (int i = 0; i < NET_CARD_MAX; i ++) {
|
||||
available |= (net_cards_conf[i].device_num > 0) && (net_cards_conf[i].net_type != NET_TYPE_NONE);
|
||||
}
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
@@ -611,8 +551,8 @@ network_available(void)
|
||||
int
|
||||
network_card_available(int card)
|
||||
{
|
||||
if (net_cards[card].device)
|
||||
return(device_available(net_cards[card].device));
|
||||
if (net_cards[card])
|
||||
return(device_available(net_cards[card]));
|
||||
|
||||
return(1);
|
||||
}
|
||||
@@ -622,7 +562,7 @@ network_card_available(int card)
|
||||
const device_t *
|
||||
network_card_getdevice(int card)
|
||||
{
|
||||
return(net_cards[card].device);
|
||||
return(net_cards[card]);
|
||||
}
|
||||
|
||||
|
||||
@@ -630,9 +570,9 @@ network_card_getdevice(int card)
|
||||
int
|
||||
network_card_has_config(int card)
|
||||
{
|
||||
if (! net_cards[card].device) return(0);
|
||||
if (!net_cards[card]) return(0);
|
||||
|
||||
return(device_has_config(net_cards[card].device) ? 1 : 0);
|
||||
return(device_has_config(net_cards[card]) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -640,7 +580,7 @@ network_card_has_config(int card)
|
||||
char *
|
||||
network_card_get_internal_name(int card)
|
||||
{
|
||||
return device_get_internal_name(net_cards[card].device);
|
||||
return device_get_internal_name(net_cards[card]);
|
||||
}
|
||||
|
||||
|
||||
@@ -650,28 +590,11 @@ network_card_get_from_internal_name(char *s)
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
while (net_cards[c].device != NULL) {
|
||||
if (! strcmp((char *)net_cards[c].device->internal_name, s))
|
||||
while (net_cards[c] != NULL) {
|
||||
if (! strcmp((char *)net_cards[c]->internal_name, s))
|
||||
return(c);
|
||||
c++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_set_wait(int wait)
|
||||
{
|
||||
net_wait = wait;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
network_get_wait(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = net_wait;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user