Skip to content

Commit d9545ab

Browse files
Liu Shuojren1
authored andcommitted
virtio-heci: disconnect client when message buffer overflowed
Firmware need to disconnect the client connection when host's message overlow the receive buffer in firmware. We emulate this behavior in backend service. Signed-off-by: Liu Shuo <shuo.a.liu@intel.com> Reviewed-by: Li Hao <hao.l.li@intel.com> Reviewed-by: Wang Yu <yu1.wang@intel.com> Reviewed-by: Zhao, Yakui <yakui.zhao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 33e84ef commit d9545ab

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

devicemodel/hw/pci/virtio/virtio_heci.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,38 @@ virtio_heci_hbm_response(struct virtio_heci *vheci,
557557
virtio_heci_client_put(vheci, client);
558558
}
559559

560+
/*
561+
* This function is intend to send HBM disconnection command to guest.
562+
* Although the default name is for virtual, using vclient here for
563+
* better understanding.
564+
*/
565+
static void
566+
virtio_heci_disconnect_vclient(struct virtio_heci *vheci,
567+
struct virtio_heci_client *client)
568+
{
569+
struct heci_msg_hdr hdr = {0};
570+
struct heci_hbm_client_disconnect_req disconnect_req = {{0} };
571+
struct virtio_heci_client *hbm_client;
572+
573+
disconnect_req.hbm_cmd.cmd = HECI_HBM_CLIENT_DISCONNECT;
574+
disconnect_req.me_addr = client->client_id;
575+
disconnect_req.host_addr = client->client_addr;
576+
577+
hbm_client = virtio_heci_get_hbm_client(vheci);
578+
if (!hbm_client) {
579+
DPRINTF(("vheci: HBM client get fail!!\r\n"));
580+
return;
581+
}
582+
populate_heci_hdr(hbm_client, &hdr,
583+
sizeof(struct heci_hbm_client_disconnect_req), 1);
584+
585+
DPRINTF(("vheci: DM -> UOS disconnect client[%d]!\r\n",
586+
client->client_id));
587+
virtio_heci_hbm_response(vheci, &hdr,
588+
&disconnect_req, sizeof(disconnect_req));
589+
virtio_heci_client_put(vheci, hbm_client);
590+
}
591+
560592
static void
561593
virtio_heci_hbm_handler(struct virtio_heci *vheci, void *data)
562594
{
@@ -824,7 +856,8 @@ virtio_heci_proc_tx(struct virtio_heci *vheci, struct virtio_vq_info *vq)
824856
DPRINTF(("vheci: TX: ME[%d]fd[%d] overflow "
825857
"max_message_length in sendbuf!\n\r",
826858
client->client_id, client->client_fd));
827-
/* TODO: close the connection according to spec */
859+
/* close the connection according to spec */
860+
virtio_heci_disconnect_vclient(vheci, client);
828861
goto out;
829862
}
830863
/* copy buffer from virtqueue to send_buf */

0 commit comments

Comments
 (0)