MIT Operating Systems Lab: networking

networking


code

it would be better to have some knowledge about principles of Computer Composition, especially about PCI & NIC. qemu -machine virt maps PCIe config space into memory address space at 0x30000000L, then config e1000 registers.


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 index = regs[E1000_TDT];
  if((tx_ring[index].status & E1000_TXD_STAT_DD) == 0){
    release(&e1000_lock);
    return -1;
  }
  
  if(tx_mbufs[index])
    mbuffree(tx_mbufs[index]);
  
  tx_ring[index].addr = (uint64)m->head;
  tx_ring[index].length = m->len;
  tx_ring[index].cmd = E1000_TXD_CMD_RS | E1000_TXD_CMD_EOP;
  tx_mbufs[index] = m;

  regs[E1000_TDT] = (regs[E1000_TDT] + 1) % TX_RING_SIZE;
  release(&e1000_lock);
  return 0;
}
static void
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()).
  //
  while(1){
  int index = regs[E1000_RDT];
  index = (index + 1) % RX_RING_SIZE;
  if((rx_ring[index].status & E1000_TXD_STAT_DD) == 0)
    return;

  rx_mbufs[index]->len = rx_ring[index].length;
  net_rx(rx_mbufs[index]);
  rx_mbufs[index] = mbufalloc(0);
  rx_ring[index].addr = (uint64)rx_mbufs[index]->head;
  rx_ring[index].status = 0;
  regs[E1000_RDT] = index;
  }
}

conclusion

all labs finished now, this class is very good to make you have a strongly understanding about the system kernel. bye!

Please find complete code here github

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值