[haiku-commits] haiku: hrev53994 - src/add-ons/kernel/drivers/network/virtio src/add-ons/kernel/bus_managers/virtio headers/private/virtio

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 21 Mar 2020 13:16:49 -0400 (EDT)

hrev53994 adds 2 changesets to branch 'master'
old head: 58b3e1889160f4a01c6ad859a042cdffae96ebf4
new head: 6d72c4188e001484e81fe27174cd57a89d266971
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=6d72c4188e00+%5E58b3e1889160

----------------------------------------------------------------------------

d8e1fd6eda93: virtio: add clear_feature hook.
  
  Change-Id: I282ffc65a7bd692145626ab4272c5df4a792e9d4
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2383
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

6d72c4188e00: virtio_net: add VIRTIO_NET_F_MTU support
  
  Change-Id: Ie61fa0e0fe13a63d5b0ebde08303a1df836b1b52
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2384
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 42 insertions(+), 1 deletion(-)
headers/private/virtio/virtio.h                   |  2 ++
.../kernel/bus_managers/virtio/VirtioDevice.cpp   |  8 ++++++++
.../kernel/bus_managers/virtio/VirtioModule.cpp   | 11 +++++++++++
.../kernel/bus_managers/virtio/VirtioPrivate.h    |  1 +
.../kernel/drivers/network/virtio/virtio_net.cpp  | 19 ++++++++++++++++++-
.../kernel/drivers/network/virtio/virtio_net.h    |  2 ++

############################################################################

Commit:      d8e1fd6eda930f5b4c8ba531a5c84ca0cd54d318
URL:         https://git.haiku-os.org/haiku/commit/?id=d8e1fd6eda93
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Wed Mar 18 09:05:50 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Mar 21 17:16:45 2020 UTC

virtio: add clear_feature hook.

Change-Id: I282ffc65a7bd692145626ab4272c5df4a792e9d4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2383
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/headers/private/virtio/virtio.h b/headers/private/virtio/virtio.h
index cb0c1760e6..2e17f725c1 100644
--- a/headers/private/virtio/virtio.h
+++ b/headers/private/virtio/virtio.h
@@ -101,6 +101,8 @@ typedef struct {
        status_t (*negotiate_features)(virtio_device cookie, uint32 supported,
                uint32* negotiated, const char* (*get_feature_name)(uint32));
 
+       status_t (*clear_feature)(virtio_device cookie, uint32 feature);
+
        status_t (*read_device_config)(virtio_device cookie, uint8 offset,
                void* buffer, size_t bufferSize);
        status_t (*write_device_config)(virtio_device cookie, uint8 offset,
diff --git a/src/add-ons/kernel/bus_managers/virtio/VirtioDevice.cpp 
b/src/add-ons/kernel/bus_managers/virtio/VirtioDevice.cpp
index 012f192598..2ef33a7fad 100644
--- a/src/add-ons/kernel/bus_managers/virtio/VirtioDevice.cpp
+++ b/src/add-ons/kernel/bus_managers/virtio/VirtioDevice.cpp
@@ -126,6 +126,14 @@ VirtioDevice::NegotiateFeatures(uint32 supported, uint32* 
negotiated,
 }
 
 
+status_t
+VirtioDevice::ClearFeature(uint32 feature)
+{
+       fFeatures &= ~feature;
+       return fController->write_guest_features(fCookie, fFeatures);
+}
+
+
 status_t
 VirtioDevice::ReadDeviceConfig(uint8 offset, void* buffer, size_t bufferSize)
 {
diff --git a/src/add-ons/kernel/bus_managers/virtio/VirtioModule.cpp 
b/src/add-ons/kernel/bus_managers/virtio/VirtioModule.cpp
index 4ad32a019d..3bfecb7fb3 100644
--- a/src/add-ons/kernel/bus_managers/virtio/VirtioModule.cpp
+++ b/src/add-ons/kernel/bus_managers/virtio/VirtioModule.cpp
@@ -63,6 +63,16 @@ virtio_negotiate_features(void* _device, uint32 supported,
 }
 
 
+status_t
+virtio_clear_feature(void* _device, uint32 feature)
+{
+       CALLED();
+       VirtioDevice *device = (VirtioDevice *)_device;
+
+       return device->ClearFeature(feature);
+}
+
+
 status_t
 virtio_read_device_config(void* _device, uint8 offset, void* buffer,
                size_t bufferSize)
@@ -275,6 +285,7 @@ virtio_device_interface virtio_device_module = {
        },
 
        virtio_negotiate_features,
+       virtio_clear_feature,
        virtio_read_device_config,
        virtio_write_device_config,
        virtio_alloc_queues,
diff --git a/src/add-ons/kernel/bus_managers/virtio/VirtioPrivate.h 
b/src/add-ons/kernel/bus_managers/virtio/VirtioPrivate.h
index 5a1b7dbc3a..e91244d012 100644
--- a/src/add-ons/kernel/bus_managers/virtio/VirtioPrivate.h
+++ b/src/add-ons/kernel/bus_managers/virtio/VirtioPrivate.h
@@ -48,6 +48,7 @@ public:
                        status_t                        
NegotiateFeatures(uint32 supported,
                                                                        uint32* 
negotiated,
                                                                        const 
char* (*get_feature_name)(uint32));
+                       status_t                        ClearFeature(uint32 
feature);
 
                        status_t                        ReadDeviceConfig(uint8 
offset, void* buffer,
                                                                        size_t 
bufferSize);

############################################################################

Revision:    hrev53994
Commit:      6d72c4188e001484e81fe27174cd57a89d266971
URL:         https://git.haiku-os.org/haiku/commit/?id=6d72c4188e00
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Wed Mar 18 09:07:48 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Mar 21 17:16:45 2020 UTC

virtio_net: add VIRTIO_NET_F_MTU support

Change-Id: Ie61fa0e0fe13a63d5b0ebde08303a1df836b1b52
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2384
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp 
b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp
index d6af769a6f..6bc10073fd 100644
--- a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp
+++ b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp
@@ -125,6 +125,8 @@ get_feature_name(uint32 feature)
                        return "host checksum";
                case VIRTIO_NET_F_GUEST_CSUM:
                        return "guest checksum";
+               case VIRTIO_NET_F_MTU:
+                       return "mtu";
                case VIRTIO_NET_F_MAC:
                        return "macaddress";
                case VIRTIO_NET_F_GSO:
@@ -224,7 +226,7 @@ virtio_net_init_device(void* _info, void** _cookie)
        sDeviceManager->put_node(parent);
 
        info->virtio->negotiate_features(info->virtio_device,
-               VIRTIO_NET_F_STATUS | VIRTIO_NET_F_MAC
+               VIRTIO_NET_F_STATUS | VIRTIO_NET_F_MAC | VIRTIO_NET_F_MTU
                /* VIRTIO_NET_F_CTRL_VQ | VIRTIO_NET_F_MQ */,
                 &info->features, &get_feature_name);
 
@@ -474,6 +476,21 @@ virtio_net_open(void* _info, const char* path, int 
openMode, void** _cookie)
                        &info->macaddr, sizeof(info->macaddr));
        }
 
+       if ((info->features & VIRTIO_NET_F_MTU) != 0) {
+               dprintf("mtu feature\n");
+               uint16 mtu;
+               info->virtio->read_device_config(info->virtio_device,
+                       offsetof(struct virtio_net_config, mtu),
+                       &mtu, sizeof(mtu));
+               // check against minimum MTU
+               if (mtu > 68)
+                       info->maxframesize = mtu;
+               else
+                       info->virtio->clear_feature(info->virtio_device, 
VIRTIO_NET_F_MTU);
+       } else {
+               dprintf("no mtu feature\n");
+       }
+
        for (int i = 0; i < info->rxSizes[0]; i++)
                virtio_net_rx_enqueue_buf(info, info->rxBufInfos[i]);
 
diff --git a/src/add-ons/kernel/drivers/network/virtio/virtio_net.h 
b/src/add-ons/kernel/drivers/network/virtio/virtio_net.h
index 315b730006..a7f8f70abe 100644
--- a/src/add-ons/kernel/drivers/network/virtio/virtio_net.h
+++ b/src/add-ons/kernel/drivers/network/virtio/virtio_net.h
@@ -34,6 +34,7 @@
 /* The feature bitmap for virtio net */
 #define VIRTIO_NET_F_CSUM      0x00001 /* Host handles pkts w/ partial csum */
 #define VIRTIO_NET_F_GUEST_CSUM 0x00002 /* Guest handles pkts w/ partial csum*/
+#define VIRTIO_NET_F_MTU       0x00008 /* Initial MTU advice. */
 #define VIRTIO_NET_F_MAC       0x00020 /* Host has given MAC address. */
 #define VIRTIO_NET_F_GSO       0x00040 /* Host handles pkts w/ any GSO type */
 #define VIRTIO_NET_F_GUEST_TSO4        0x00080 /* Guest can handle TSOv4 in. */
@@ -66,6 +67,7 @@ struct virtio_net_config {
         * Legal values are between 1 and 0x8000.
         */
        uint16_t        max_virtqueue_pairs;
+       uint16_t        mtu;
 } _PACKED;
 
 /*


Other related posts:

  • » [haiku-commits] haiku: hrev53994 - src/add-ons/kernel/drivers/network/virtio src/add-ons/kernel/bus_managers/virtio headers/private/virtio - waddlesplash