I am working on the ethernet driver code for e1000 ethernet adapter as part of the xv6 OS. There are two functions for transmitting and receiving ethernet frames: e1000_transmit and e1000_receive. The receive and transmit functions use ring buffers to hold the packets. I understand that the transmit function may be invoked from multiple processes or threads and hence requires locking to prevent data race on the pointer modification of the TX ring buffer.
The receive function is invoked by an interrupt handler and not in the context of a process. So my understanding is that when multiple interrupts occur, the ring buffer pointers may be corrupted. So is disabling the interrupts before starting the handler sufficient or do I need any locks too?
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()).
//
}
void
e1000_intr(void)
{
// tell the e1000 we've seen this interrupt;
// without this the e1000 won't raise any
// further interrupts.
regs[E1000_ICR] = 0xffffffff;
e1000_recv();
}