mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-03 12:49:45 +00:00
DM: virtio-heci: Add enum type status variable represent devices status
In virtio_heci struct there have deiniting/pending_reset/resetting variables. All these variables represent the status of virtio heci devices. Change them into one enum type variable for vheci status. Signed-off-by: Long Liu <long.liu@intel.com> Reviewed-by: Yu Wang <yu1.wang@intel.com> Reviewed-by: Shuo Liu <shuo.a.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
2b69329ec7
commit
c11a162993
@ -67,6 +67,13 @@
|
|||||||
|
|
||||||
#define HECI_NATIVE_DEVICE_NODE "/dev/mei0"
|
#define HECI_NATIVE_DEVICE_NODE "/dev/mei0"
|
||||||
|
|
||||||
|
enum vheci_status {
|
||||||
|
VHECI_READY,
|
||||||
|
VHECI_PENDING_RESET,
|
||||||
|
VHECI_RESET,
|
||||||
|
VHECI_DEINIT
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Different type has differnt emulation
|
* Different type has differnt emulation
|
||||||
*
|
*
|
||||||
@ -122,9 +129,7 @@ struct virtio_heci {
|
|||||||
struct virtio_vq_info vqs[VIRTIO_HECI_VQNUM];
|
struct virtio_vq_info vqs[VIRTIO_HECI_VQNUM];
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
struct mei_enumerate_me_clients me_clients_map;
|
struct mei_enumerate_me_clients me_clients_map;
|
||||||
volatile bool deiniting;
|
volatile enum vheci_status status;
|
||||||
volatile bool resetting;
|
|
||||||
volatile bool pending_reset;
|
|
||||||
|
|
||||||
pthread_t tx_thread;
|
pthread_t tx_thread;
|
||||||
pthread_mutex_t tx_mutex;
|
pthread_mutex_t tx_mutex;
|
||||||
@ -264,6 +269,15 @@ virtio_heci_add_client(struct virtio_heci *vheci,
|
|||||||
pthread_mutex_unlock(&vheci->list_mutex);
|
pthread_mutex_unlock(&vheci->list_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
virtio_heci_set_status(struct virtio_heci *vheci, enum vheci_status status)
|
||||||
|
{
|
||||||
|
if (status == VHECI_DEINIT ||
|
||||||
|
status == VHECI_READY ||
|
||||||
|
status > vheci->status)
|
||||||
|
vheci->status = status;
|
||||||
|
}
|
||||||
|
|
||||||
static struct virtio_heci_client *
|
static struct virtio_heci_client *
|
||||||
virtio_heci_find_client(struct virtio_heci *vheci, int client_addr)
|
virtio_heci_find_client(struct virtio_heci *vheci, int client_addr)
|
||||||
{
|
{
|
||||||
@ -426,7 +440,7 @@ virtio_heci_destroy_client(struct virtio_heci *vheci,
|
|||||||
client->client_id, client->client_fd,
|
client->client_id, client->client_fd,
|
||||||
client->client_addr));
|
client->client_addr));
|
||||||
virtio_heci_del_client(vheci, client);
|
virtio_heci_del_client(vheci, client);
|
||||||
if (client->type != TYPE_HBM && !vheci->deiniting)
|
if (client->type != TYPE_HBM)
|
||||||
mevent_delete_close(client->rx_mevp);
|
mevent_delete_close(client->rx_mevp);
|
||||||
free(client->send_buf);
|
free(client->send_buf);
|
||||||
free(client->recv_buf);
|
free(client->recv_buf);
|
||||||
@ -454,7 +468,7 @@ native_heci_read(struct virtio_heci_client *client)
|
|||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
WPRINTF(("vheci: read failed! read error[%d]\r\n", errno));
|
WPRINTF(("vheci: read failed! read error[%d]\r\n", errno));
|
||||||
if (errno == ENODEV)
|
if (errno == ENODEV)
|
||||||
vheci->pending_reset = true;
|
virtio_heci_set_status(vheci, VHECI_PENDING_RESET);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
DPRINTF(("vheci: RX: ME[%d]fd[%d] Append data(len[%d]) "
|
DPRINTF(("vheci: RX: ME[%d]fd[%d] Append data(len[%d]) "
|
||||||
@ -481,7 +495,7 @@ native_heci_write(struct virtio_heci_client *client)
|
|||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
WPRINTF(("vheci: write failed! write error[%d]\r\n", errno));
|
WPRINTF(("vheci: write failed! write error[%d]\r\n", errno));
|
||||||
if (errno == ENODEV)
|
if (errno == ENODEV)
|
||||||
vheci->pending_reset = true;
|
virtio_heci_set_status(vheci, VHECI_PENDING_RESET);
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
@ -499,7 +513,7 @@ virtio_heci_rx_callback(int fd, enum ev_type type, void *param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&vheci->rx_mutex);
|
pthread_mutex_lock(&vheci->rx_mutex);
|
||||||
if (client->recv_offset != 0 || vheci->resetting) {
|
if (client->recv_offset != 0 || vheci->status != VHECI_READY) {
|
||||||
/* still has data in recv_buf, wait guest reading */
|
/* still has data in recv_buf, wait guest reading */
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -520,8 +534,7 @@ virtio_heci_rx_callback(int fd, enum ev_type type, void *param)
|
|||||||
out:
|
out:
|
||||||
pthread_mutex_unlock(&vheci->rx_mutex);
|
pthread_mutex_unlock(&vheci->rx_mutex);
|
||||||
virtio_heci_client_put(vheci, client);
|
virtio_heci_client_put(vheci, client);
|
||||||
if (vheci->pending_reset) {
|
if (vheci->status == VHECI_PENDING_RESET) {
|
||||||
vheci->pending_reset = false;
|
|
||||||
virtio_heci_virtual_fw_reset(vheci);
|
virtio_heci_virtual_fw_reset(vheci);
|
||||||
/* Let's wait 100ms for HBM enumeration done */
|
/* Let's wait 100ms for HBM enumeration done */
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
@ -953,8 +966,7 @@ out:
|
|||||||
send_failed:
|
send_failed:
|
||||||
virtio_heci_client_put(vheci, client);
|
virtio_heci_client_put(vheci, client);
|
||||||
failed:
|
failed:
|
||||||
if (vheci->pending_reset) {
|
if (vheci->status == VHECI_PENDING_RESET) {
|
||||||
vheci->pending_reset = false;
|
|
||||||
virtio_heci_virtual_fw_reset(vheci);
|
virtio_heci_virtual_fw_reset(vheci);
|
||||||
/* Let's wait 100ms for HBM enumeration done */
|
/* Let's wait 100ms for HBM enumeration done */
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
@ -984,18 +996,19 @@ static void *virtio_heci_tx_thread(void *param)
|
|||||||
error = pthread_cond_wait(&vheci->tx_cond, &vheci->tx_mutex);
|
error = pthread_cond_wait(&vheci->tx_cond, &vheci->tx_mutex);
|
||||||
assert(error == 0);
|
assert(error == 0);
|
||||||
|
|
||||||
while (!vheci->deiniting) {
|
while (vheci->status != VHECI_DEINIT) {
|
||||||
/* note - tx mutex is locked here */
|
/* note - tx mutex is locked here */
|
||||||
while (!vq_has_descs(vq)) {
|
while (!vq_has_descs(vq)) {
|
||||||
vq->used->flags &= ~VRING_USED_F_NO_NOTIFY;
|
vq->used->flags &= ~VRING_USED_F_NO_NOTIFY;
|
||||||
mb();
|
mb();
|
||||||
if (vq_has_descs(vq) && !vheci->resetting)
|
if (vq_has_descs(vq) &&
|
||||||
|
vheci->status != VHECI_RESET)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
error = pthread_cond_wait(&vheci->tx_cond,
|
error = pthread_cond_wait(&vheci->tx_cond,
|
||||||
&vheci->tx_mutex);
|
&vheci->tx_mutex);
|
||||||
assert(error == 0);
|
assert(error == 0);
|
||||||
if (vheci->deiniting)
|
if (vheci->status == VHECI_DEINIT)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
vq->used->flags |= VRING_USED_F_NO_NOTIFY;
|
vq->used->flags |= VRING_USED_F_NO_NOTIFY;
|
||||||
@ -1136,20 +1149,20 @@ static void *virtio_heci_rx_thread(void *param)
|
|||||||
error = pthread_cond_wait(&vheci->rx_cond, &vheci->rx_mutex);
|
error = pthread_cond_wait(&vheci->rx_cond, &vheci->rx_mutex);
|
||||||
assert(error == 0);
|
assert(error == 0);
|
||||||
|
|
||||||
while (!vheci->deiniting) {
|
while (vheci->status != VHECI_DEINIT) {
|
||||||
/* note - rx mutex is locked here */
|
/* note - rx mutex is locked here */
|
||||||
while (vq_ring_ready(vq)) {
|
while (vq_ring_ready(vq)) {
|
||||||
vq->used->flags &= ~VRING_USED_F_NO_NOTIFY;
|
vq->used->flags &= ~VRING_USED_F_NO_NOTIFY;
|
||||||
mb();
|
mb();
|
||||||
if (vq_has_descs(vq) &&
|
if (vq_has_descs(vq) &&
|
||||||
vheci->rx_need_sched &&
|
vheci->rx_need_sched &&
|
||||||
!vheci->resetting)
|
vheci->status != VHECI_RESET)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
error = pthread_cond_wait(&vheci->rx_cond,
|
error = pthread_cond_wait(&vheci->rx_cond,
|
||||||
&vheci->rx_mutex);
|
&vheci->rx_mutex);
|
||||||
assert(error == 0);
|
assert(error == 0);
|
||||||
if (vheci->deiniting)
|
if (vheci->status == VHECI_DEINIT)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
vq->used->flags |= VRING_USED_F_NO_NOTIFY;
|
vq->used->flags |= VRING_USED_F_NO_NOTIFY;
|
||||||
@ -1212,6 +1225,7 @@ virtio_heci_start(struct virtio_heci *vheci)
|
|||||||
if (!vheci->hbm_client)
|
if (!vheci->hbm_client)
|
||||||
return -1;
|
return -1;
|
||||||
vheci->config->hw_ready = 1;
|
vheci->config->hw_ready = 1;
|
||||||
|
virtio_heci_set_status(vheci, VHECI_READY);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1219,7 +1233,7 @@ virtio_heci_start(struct virtio_heci *vheci)
|
|||||||
static int
|
static int
|
||||||
virtio_heci_stop(struct virtio_heci *vheci)
|
virtio_heci_stop(struct virtio_heci *vheci)
|
||||||
{
|
{
|
||||||
vheci->deiniting = true;
|
virtio_heci_set_status(vheci, VHECI_DEINIT);
|
||||||
pthread_mutex_lock(&vheci->tx_mutex);
|
pthread_mutex_lock(&vheci->tx_mutex);
|
||||||
pthread_cond_signal(&vheci->tx_cond);
|
pthread_cond_signal(&vheci->tx_cond);
|
||||||
pthread_mutex_unlock(&vheci->tx_mutex);
|
pthread_mutex_unlock(&vheci->tx_mutex);
|
||||||
@ -1244,7 +1258,7 @@ virtio_heci_virtual_fw_reset(struct virtio_heci *vheci)
|
|||||||
{
|
{
|
||||||
struct virtio_heci_client *client = NULL, *pclient = NULL;
|
struct virtio_heci_client *client = NULL, *pclient = NULL;
|
||||||
|
|
||||||
vheci->resetting = true;
|
virtio_heci_set_status(vheci, VHECI_RESET);
|
||||||
vheci->config->hw_ready = 0;
|
vheci->config->hw_ready = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&vheci->list_mutex);
|
pthread_mutex_lock(&vheci->list_mutex);
|
||||||
@ -1258,8 +1272,6 @@ virtio_heci_virtual_fw_reset(struct virtio_heci *vheci)
|
|||||||
while (!LIST_EMPTY(&vheci->active_clients))
|
while (!LIST_EMPTY(&vheci->active_clients))
|
||||||
;
|
;
|
||||||
vheci->hbm_client = NULL;
|
vheci->hbm_client = NULL;
|
||||||
|
|
||||||
vheci->resetting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user