From nobody Thu May 2 03:00:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489478072470450.0540802590192; Tue, 14 Mar 2017 00:54:32 -0700 (PDT) Received: from localhost ([::1]:56944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnhHr-0001Ak-2l for importer@patchew.org; Tue, 14 Mar 2017 03:54:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnhHN-0001AV-Nh for qemu-devel@nongnu.org; Tue, 14 Mar 2017 03:54:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnhHK-0008OS-KY for qemu-devel@nongnu.org; Tue, 14 Mar 2017 03:54:01 -0400 Received: from [59.151.112.132] (port=64338 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnhHJ-0008KV-Lz; Tue, 14 Mar 2017 03:53:58 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Mar 2017 15:53:46 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 0DF1147D8B96; Tue, 14 Mar 2017 15:53:48 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 14 Mar 2017 15:53:46 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16545623" From: Zhang Chen To: qemu devel , Jason Wang , Laurent Vivier Date: Tue, 14 Mar 2017 15:52:32 +0800 Message-ID: <1489477952-6901-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 0DF1147D8B96.AEBE2 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH] hw/net/virtio-net.c: Follow CODING_STYLE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Trivial , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhang Chen Reviewed-by: Eric Blake --- hw/net/virtio-net.c | 53 +++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c321680..ede618e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -273,7 +273,7 @@ static void virtio_net_set_status(struct VirtIODevice *= vdev, uint8_t status) if (queue_started) { if (q->tx_timer) { timer_mod(q->tx_timer, - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->= tx_timeout); + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_tim= eout); } else { qemu_bh_schedule(q->tx_bh); } @@ -301,13 +301,15 @@ static void virtio_net_set_link_status(NetClientState= *nc) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); uint16_t old_status =3D n->status; =20 - if (nc->link_down) + if (nc->link_down) { n->status &=3D ~VIRTIO_NET_S_LINK_UP; - else + } else { n->status |=3D VIRTIO_NET_S_LINK_UP; + } =20 - if (n->status !=3D old_status) + if (n->status !=3D old_status) { virtio_notify_config(vdev); + } =20 virtio_net_set_status(vdev, vdev->status); } @@ -319,7 +321,8 @@ static void rxfilter_notify(NetClientState *nc) if (nc->rxfilter_notify_enabled) { gchar *path =3D object_get_canonical_path(OBJECT(n->qdev)); qapi_event_send_nic_rx_filter_changed(!!n->netclient_name, - n->netclient_name, path, &er= ror_abort); + n->netclient_name, + path, &error_abort); g_free(path); =20 /* disable event notification to avoid events flooding */ @@ -459,8 +462,9 @@ static int peer_has_vnet_hdr(VirtIONet *n) =20 static int peer_has_ufo(VirtIONet *n) { - if (!peer_has_vnet_hdr(n)) + if (!peer_has_vnet_hdr(n)) { return 0; + } =20 n->has_ufo =3D qemu_has_ufo(qemu_get_queue(n->nic)->peer); =20 @@ -847,15 +851,17 @@ static int virtio_net_handle_vlan_table(VirtIONet *n,= uint8_t cmd, return VIRTIO_NET_ERR; } =20 - if (vid >=3D MAX_VLAN) + if (vid >=3D MAX_VLAN) { return VIRTIO_NET_ERR; + } =20 - if (cmd =3D=3D VIRTIO_NET_CTRL_VLAN_ADD) + if (cmd =3D=3D VIRTIO_NET_CTRL_VLAN_ADD) { n->vlans[vid >> 5] |=3D (1U << (vid & 0x1f)); - else if (cmd =3D=3D VIRTIO_NET_CTRL_VLAN_DEL) + } else if (cmd =3D=3D VIRTIO_NET_CTRL_VLAN_DEL) { n->vlans[vid >> 5] &=3D ~(1U << (vid & 0x1f)); - else + } else { return VIRTIO_NET_ERR; + } =20 rxfilter_notify(nc); =20 @@ -938,7 +944,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, = VirtQueue *vq) } =20 iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup(elem->out_sg, sizeof(struct iovec) * ele= m->out_num); + iov2 =3D iov =3D g_memdup(elem->out_sg, + sizeof(struct iovec) * elem->out_num); s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); if (s !=3D sizeof(ctrl)) { @@ -1086,18 +1093,21 @@ static int receive_filter(VirtIONet *n, const uint8= _t *buf, int size) uint8_t *ptr =3D (uint8_t *)buf; int i; =20 - if (n->promisc) + if (n->promisc) { return 1; + } =20 ptr +=3D n->host_hdr_len; =20 if (!memcmp(&ptr[12], vlan, sizeof(vlan))) { int vid =3D lduw_be_p(ptr + 14) & 0xfff; - if (!(n->vlans[vid >> 5] & (1U << (vid & 0x1f)))) + if (!(n->vlans[vid >> 5] & (1U << (vid & 0x1f)))) { return 0; + } } =20 - if (ptr[0] & 1) { // multicast + if (ptr[0] & 1) { + /* multicast */ if (!memcmp(ptr, bcast, sizeof(bcast))) { return !n->nobcast; } else if (n->nomulti) { @@ -1111,7 +1121,8 @@ static int receive_filter(VirtIONet *n, const uint8_t= *buf, int size) return 1; } } - } else { // unicast + } else { + /* unicast */ if (n->nouni) { return 0; } else if (n->alluni || n->mac_table.uni_overflow) { @@ -1150,8 +1161,9 @@ static ssize_t virtio_net_receive_rcu(NetClientState = *nc, const uint8_t *buf, return 0; } =20 - if (!receive_filter(n, buf, size)) + if (!receive_filter(n, buf, size)) { return size; + } =20 offset =3D i =3D 0; =20 @@ -1283,7 +1295,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) for (;;) { ssize_t ret; unsigned int out_num; - struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE + 1], = *out_sg; + struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE + 1], + *out_sg; struct virtio_net_hdr_mrg_rxbuf mhdr; =20 elem =3D virtqueue_pop(q->tx_vq, sizeof(VirtQueueElement)); @@ -1317,10 +1330,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *= q) n->guest_hdr_len, -1); if (out_num =3D=3D VIRTQUEUE_MAX_SIZE) { goto drop; - } + } out_num +=3D 1; out_sg =3D sg2; - } + } } /* * If host wants to see the guest header as is, we can @@ -1384,7 +1397,7 @@ static void virtio_net_handle_tx_timer(VirtIODevice *= vdev, VirtQueue *vq) } } else { timer_mod(q->tx_timer, - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeo= ut); + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout); q->tx_waiting =3D 1; virtio_queue_set_notification(vq, 0); } --=20 2.7.4