xref: /dpdk/drivers/net/virtio/virtio.c (revision 68a03efeed657e6e05f281479b33b51102797e15)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  * Copyright(c) 2020 Red Hat, Inc.
4  */
5 
6 #include "virtio.h"
7 
8 uint64_t
9 virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
10 {
11 	uint64_t features;
12 
13 	/*
14 	 * Limit negotiated features to what the driver, virtqueue, and
15 	 * host all support.
16 	 */
17 	features = host_features & hw->guest_features;
18 	VIRTIO_OPS(hw)->set_features(hw, features);
19 
20 	return features;
21 }
22 
23 
24 void
25 virtio_read_dev_config(struct virtio_hw *hw, size_t offset,
26 		      void *dst, int length)
27 {
28 	VIRTIO_OPS(hw)->read_dev_cfg(hw, offset, dst, length);
29 }
30 
31 void
32 virtio_write_dev_config(struct virtio_hw *hw, size_t offset,
33 		       const void *src, int length)
34 {
35 	VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length);
36 }
37 
38 void
39 virtio_reset(struct virtio_hw *hw)
40 {
41 	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
42 	/* flush status write */
43 	VIRTIO_OPS(hw)->get_status(hw);
44 }
45 
46 void
47 virtio_reinit_complete(struct virtio_hw *hw)
48 {
49 	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
50 }
51 
52 void
53 virtio_set_status(struct virtio_hw *hw, uint8_t status)
54 {
55 	if (status != VIRTIO_CONFIG_STATUS_RESET)
56 		status |= VIRTIO_OPS(hw)->get_status(hw);
57 
58 	VIRTIO_OPS(hw)->set_status(hw, status);
59 }
60 
61 uint8_t
62 virtio_get_status(struct virtio_hw *hw)
63 {
64 	return VIRTIO_OPS(hw)->get_status(hw);
65 }
66 
67 uint8_t
68 virtio_get_isr(struct virtio_hw *hw)
69 {
70 	return VIRTIO_OPS(hw)->get_isr(hw);
71 }
72