@@ -49,22 +49,24 @@ struct lkl_dev_blk_ops {
4949
5050struct lkl_netdev {
5151 struct lkl_dev_net_ops * ops ;
52- lkl_thread_t rx_tid , tx_tid ;
5352 uint8_t has_vnet_hdr : 1 ;
5453};
5554
5655struct lkl_dev_net_ops {
57- /* Writes a L2 packet into the net device.
56+ /*
57+ * Writes a L2 packet into the net device.
5858 *
5959 * The data buffer can only hold 0 or 1 complete packets.
6060 *
6161 * @nd - pointer to the network device
6262 * @iov - pointer to the buffer vector
6363 * @cnt - # of vectors in iov.
6464 * @returns number of bytes transmitted
65- */
65+ */
6666 int (* tx )(struct lkl_netdev * nd , struct lkl_dev_buf * iov , int cnt );
67- /* Reads a packet from the net device.
67+
68+ /*
69+ * Reads a packet from the net device.
6870 *
6971 * It must only read one complete packet if present.
7072 *
@@ -75,43 +77,32 @@ struct lkl_dev_net_ops {
7577 * @iov - pointer to the buffer vector to store the packet
7678 * @cnt - # of vectors in iov.
7779 * @returns number of bytes read for success or < 0 if error
78- */
80+ */
7981 int (* rx )(struct lkl_netdev * nd , struct lkl_dev_buf * iov , int cnt );
82+
8083#define LKL_DEV_NET_POLL_RX 1
8184#define LKL_DEV_NET_POLL_TX 2
82- /* Polls a net device.
83- *
84- * Supports only one of two events: LKL_DEV_NET_POLL_RX (readable) and
85- * LKL_DEV_NET_POLL_TX (writable). Blocks until one event is available.
86- *
87- * Implementation can assume only one of LKL_DEV_NET_POLL_RX or
88- * LKL_DEV_NET_POLL_TX is set in @events.
85+ #define LKL_DEV_NET_POLL_HUP 4
86+
87+ /*
88+ * Polls a net device.
8989 *
90- * Both LKL_DEV_NET_POLL_RX and LKL_DEV_NET_POLL_TX can be
91- * level-triggered or edge-triggered. When it's level-triggered,
92- * rx/tx thread can become a busy waiting loop which burns out CPU.
93- * This is more of a problem for tx, because LKL_DEV_NET_POLL_TX event
94- * is present most of the time.
90+ * Supports the following events: LKL_DEV_NET_POLL_RX (readable),
91+ * LKL_DEV_NET_POLL_TX (writable) or LKL_DEV_NET_POLL_HUP (the close
92+ * operations has been issued and we need to clean up). Blocks until one
93+ * event is available.
9594 *
9695 * @nd - pointer to the network device
97- * @events - a bit mask specifying the events to poll on. Only one of
98- * LKL_DEV_NET_POLL_RX or LKL_DEV_NET_POLL_TX is set.
99- * @returns the events triggered for success. -1 for failure.
10096 */
101- int (* poll )(struct lkl_netdev * nd , int events );
102- /* Closes a net device.
103- *
104- * Implementation can choose to release any resources releated to it. In
105- * particular, the polling threads are to be killed in this function.
106- *
107- * Implemenation must guarantee it's safe to call free_mem() after this
108- * function call.
109- *
110- * Not implemented by all netdev types.
97+ int (* poll )(struct lkl_netdev * nd );
98+
99+ /*
100+ * Closes a net device.
111101 *
112- * @returns 0 for success. -1 for failure.
102+ * Implementation must release its resources and poll must wakeup and
103+ * return LKL_DEV_NET_POLL_HUP.
113104 */
114- int (* close )(struct lkl_netdev * nd );
105+ void (* close )(struct lkl_netdev * nd );
115106};
116107
117108#ifdef __cplusplus
0 commit comments