X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fvirtio%2Fvirtio.c;h=d9e642f412eb9ef707cc664b4753b277115f01cb;hb=99ebada2d6d9db23be39f737f26c7bf5f0a26b9c;hp=d8d6bf7add4371543d82be611eaddce5a2e89c81;hpb=b4f9a45affd26ddfdb373b79e4ebd78fe2da1383;p=dpdk.git diff --git a/drivers/net/virtio/virtio.c b/drivers/net/virtio/virtio.c index d8d6bf7add..d9e642f412 100644 --- a/drivers/net/virtio/virtio.c +++ b/drivers/net/virtio/virtio.c @@ -3,7 +3,10 @@ * Copyright(c) 2020 Red Hat, Inc. */ +#include + #include "virtio.h" +#include "virtio_logs.h" uint64_t virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features) @@ -20,3 +23,60 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features) return features; } + +void +virtio_read_dev_config(struct virtio_hw *hw, size_t offset, + void *dst, int length) +{ + VIRTIO_OPS(hw)->read_dev_cfg(hw, offset, dst, length); +} + +void +virtio_write_dev_config(struct virtio_hw *hw, size_t offset, + const void *src, int length) +{ + VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length); +} + +void +virtio_reset(struct virtio_hw *hw) +{ + uint32_t retry = 0; + + VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET); + /* Flush status write and wait device ready max 3 seconds. */ + while (VIRTIO_OPS(hw)->get_status(hw) != VIRTIO_CONFIG_STATUS_RESET) { + if (retry++ > 3000) { + PMD_INIT_LOG(WARNING, "port %u device reset timeout", hw->port_id); + break; + } + usleep(1000L); + } +} + +void +virtio_reinit_complete(struct virtio_hw *hw) +{ + virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK); +} + +void +virtio_set_status(struct virtio_hw *hw, uint8_t status) +{ + if (status != VIRTIO_CONFIG_STATUS_RESET) + status |= VIRTIO_OPS(hw)->get_status(hw); + + VIRTIO_OPS(hw)->set_status(hw, status); +} + +uint8_t +virtio_get_status(struct virtio_hw *hw) +{ + return VIRTIO_OPS(hw)->get_status(hw); +} + +uint8_t +virtio_get_isr(struct virtio_hw *hw) +{ + return VIRTIO_OPS(hw)->get_isr(hw); +}