/* if netdev detected a packet in netdev buffer, driver can call this function to receive this packet.
notify:0 can transmit 1: can receive
qen:0 do not use netjob queue 1:use netjob queue */
int netdev_notify (struct netdev *netdev, netdev_inout inout, int q_en)
{
if (!netdev || (netdev->magic_no != NETDEV_MAGIC)) {
return (-1);
}
if (inout != LINK_INPUT) {
return (0);
}
if (q_en) {
if (netJobAdd(netdev->drv->receive, netdev,
(void *)netdev_netif_linkinput, 0, 0, 0, 0) == 0) {
return (0);
} else {
return (-1);
}
}
NETDEV_RECEIVE(netdev, netdev_netif_linkinput);
return (0);
}
在网卡驱动中,当netdev检测到有数据在缓冲区时,会产生接收中断,在接收中断中通知receive函数出来这个数据。
在接收中断中,通过调用netdev_notify函数通知receive函数处理。
- int netdev_notify(struct netdev *netdev, netdev_inout inout, int q_en);
netdev:指向netdev结构指针
inout:传参0表示接收操作,1表示发送操作。
q_en:传参0表示不使用网络异步处理作业队列,1表示使用网络队列。
对这边的理解是:
若q_en传参1,那netdev_notify会将receive函数添加至异步处理队列,退出中断,等待CPU空闲时接收数据。有点像中断底半部。
若q_en传参0,那netdev_notify会直接调用receive函数处理,等待接收完成后再退出中断。