int e1000_transmit(struct mbuf *m) { // // Your code here. // // the mbuf contains an ethernet frame; program it into // the TX descriptor ring so that the e1000 sends it. Stash // a pointer so that it can be freed after sending. // acquire(&e1000_lock); int i = regs[E1000_TDT]; if((tx_ring[i].status & E1000_TXD_STAT_DD) == 0) { release(&e1000_lock); return-1; }
staticvoid e1000_recv(void) { // // Your code here. // // Check for packets that have arrived from the e1000 // Create and deliver an mbuf for each packet (using net_rx()). // //acquire(&e1000_lock); int i = (regs[E1000_RDT] + 1) % RX_RING_SIZE; while(1) { if((rx_ring[i].status & E1000_RXD_STAT_DD) == 0) { break; } rx_mbufs[i]->len = rx_ring[i].length; net_rx(rx_mbufs[i]);
rx_mbufs[i] = mbufalloc(0); if (!rx_mbufs[i]) panic("e1000_recv");
rx_ring[i].addr = (uint64) rx_mbufs[i]->head; rx_ring[i].status = 0; i = (i + 1) % RX_RING_SIZE; }
regs[E1000_RDT] = (i - 1 + RX_RING_SIZE) % RX_RING_SIZE;