[MIT 6.1810 2023]Lab7: networking

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;
	}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值