3 #include <linux/kernel.h>
4 #include <linux/list.h>
6 struct uip_buf
*uip_buf_get_used(struct uip_info
*info
)
11 mutex_lock(&info
->buf_lock
);
13 while (!(info
->buf_used_nr
> 0))
14 pthread_cond_wait(&info
->buf_used_cond
, &info
->buf_lock
);
16 list_for_each_entry(buf
, &info
->buf_head
, list
) {
17 if (buf
->status
== UIP_BUF_STATUS_USED
) {
19 * Set status to INUSE immediately to prevent
20 * someone from using this buf until we free it
22 buf
->status
= UIP_BUF_STATUS_INUSE
;
29 mutex_unlock(&info
->buf_lock
);
31 return found
? buf
: NULL
;
34 struct uip_buf
*uip_buf_get_free(struct uip_info
*info
)
39 mutex_lock(&info
->buf_lock
);
41 while (!(info
->buf_free_nr
> 0))
42 pthread_cond_wait(&info
->buf_free_cond
, &info
->buf_lock
);
44 list_for_each_entry(buf
, &info
->buf_head
, list
) {
45 if (buf
->status
== UIP_BUF_STATUS_FREE
) {
47 * Set status to INUSE immediately to prevent
48 * someone from using this buf until we free it
50 buf
->status
= UIP_BUF_STATUS_INUSE
;
57 mutex_unlock(&info
->buf_lock
);
59 return found
? buf
: NULL
;
62 struct uip_buf
*uip_buf_set_used(struct uip_info
*info
, struct uip_buf
*buf
)
64 mutex_lock(&info
->buf_lock
);
66 buf
->status
= UIP_BUF_STATUS_USED
;
68 pthread_cond_signal(&info
->buf_used_cond
);
70 mutex_unlock(&info
->buf_lock
);
75 struct uip_buf
*uip_buf_set_free(struct uip_info
*info
, struct uip_buf
*buf
)
77 mutex_lock(&info
->buf_lock
);
79 buf
->status
= UIP_BUF_STATUS_FREE
;
81 pthread_cond_signal(&info
->buf_free_cond
);
83 mutex_unlock(&info
->buf_lock
);
88 struct uip_buf
*uip_buf_clone(struct uip_tx_arg
*arg
)
92 struct uip_info
*info
;
97 * Get buffer from device to guest
99 buf
= uip_buf_get_free(info
);
104 memcpy(buf
->vnet
, arg
->vnet
, arg
->vnet_len
);
105 memcpy(buf
->eth
, arg
->eth
, arg
->eth_len
);
106 buf
->vnet_len
= arg
->vnet_len
;
107 buf
->eth_len
= arg
->eth_len
;
109 eth2
= (struct uip_eth
*)buf
->eth
;
110 eth2
->src
= info
->host_mac
;
111 eth2
->dst
= arg
->eth
->src
;