int e1000_transmit(struct mbuf *m)
{
int idx;
acquire(&e1000_lock);
idx = regs[E1000_TDT];
if ((tx_ring[idx].status & E1000_TXD_STAT_DD) == 0)
{
release(&e1000_lock);
return -1;
}
if (tx_mbufs[idx])
{
mbuffree(tx_mbufs[idx]);
}
tx_ring[idx].addr = (uint64)m->head;
tx_ring[idx].length = m->len;
tx_ring[idx].cso = 0;
tx_ring[idx].cmd = E1000_TXD_CMD_RS | E1000_TXD_CMD_EOP;
tx_ring[idx].status = 0;
tx_ring[idx].css = 0;
tx_ring[idx].special = 0;
tx_mbufs[idx] = m;
regs[E1000_TDT] = (idx + 1) % TX_RING_SIZE;
release(&e1000_lock);
return 0;
}
static void e1000_recv(void)
{
int idx = (regs[E1000_RDT] + 1) % RX_RING_SIZE;
while ((rx_ring[idx].status & E1000_RXD_STAT_DD))
{
rx_mbufs[idx]->len = rx_ring[idx].length;
net_rx(rx_mbufs[idx]);
rx_mbufs[idx] = mbufalloc(0);
rx_ring[idx].addr = (uint64)rx_mbufs[idx]->head;
rx_ring[idx].status = 0;
regs[E1000_RDT] = idx;
idx = (idx + 1) % RX_RING_SIZE;
}
}