mana_driver/
save_restore.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Types to save and restore the state of a MANA device.
5
6use mesh::payload::Protobuf;
7
8/// Mana saved state
9#[derive(Debug, Protobuf, Clone)]
10#[mesh(package = "mana_driver")]
11pub struct ManaSavedState {
12    /// The saved state of the MANA device driver
13    #[mesh(1)]
14    pub mana_device: ManaDeviceSavedState,
15
16    /// Id of the device
17    #[mesh(2)]
18    pub pci_id: String,
19}
20
21/// Mana device saved state
22#[derive(Debug, Protobuf, Clone)]
23#[mesh(package = "mana_driver")]
24pub struct ManaDeviceSavedState {
25    /// Saved state for restoration of the GDMA driver
26    #[mesh(1)]
27    pub gdma: GdmaDriverSavedState,
28}
29
30/// Top level saved state for the GDMA driver's saved state
31#[derive(Protobuf, Clone, Debug)]
32#[mesh(package = "mana_driver")]
33pub struct GdmaDriverSavedState {
34    /// Memory to be restored by a DMA client
35    #[mesh(1)]
36    pub mem: SavedMemoryState,
37
38    /// EQ to be restored
39    #[mesh(2)]
40    pub eq: CqEqSavedState,
41
42    /// CQ to be restored
43    #[mesh(3)]
44    pub cq: CqEqSavedState,
45
46    /// RQ to be restored
47    #[mesh(4)]
48    pub rq: WqSavedState,
49
50    /// SQ to be restored
51    #[mesh(5)]
52    pub sq: WqSavedState,
53
54    /// Doorbell id
55    #[mesh(6)]
56    pub db_id: u64,
57
58    /// Guest physical address memory key
59    #[mesh(7)]
60    pub gpa_mkey: u32,
61
62    /// Protection domain id
63    #[mesh(8)]
64    pub pdid: u32,
65
66    /// The id of the HWC activity
67    #[mesh(9)]
68    pub hwc_activity_id: u32,
69
70    /// How many msix vectors are available
71    #[mesh(10)]
72    pub num_msix: u32,
73
74    /// Minimum number of queues available
75    #[mesh(11)]
76    pub min_queue_avail: u32,
77    /// Link status by vport index
78    #[mesh(12)]
79    pub link_toggle: Vec<(u32, bool)>,
80}
81
82/// The saved state of a completion queue or event queue for restoration
83/// during servicing
84#[derive(Clone, Protobuf, Debug)]
85#[mesh(package = "mana_driver")]
86pub struct CqEqSavedState {
87    /// The doorbell state of the queue, which is how the device is notified
88    #[mesh(1)]
89    pub doorbell: DoorbellSavedState,
90
91    /// The address of the doorbell register
92    #[mesh(2)]
93    pub doorbell_addr: u32,
94
95    /// The id of the queue
96    #[mesh(3)]
97    pub id: u32,
98
99    /// The index of the next entry in the queue
100    #[mesh(4)]
101    pub next: u32,
102
103    /// The total size of the queue
104    #[mesh(5)]
105    pub size: u32,
106
107    /// The bit shift value for the queue
108    #[mesh(6)]
109    pub shift: u32,
110}
111
112/// Saved state of a doorbell for restoration during servicing
113#[derive(Clone, Protobuf, Debug)]
114#[mesh(package = "mana_driver")]
115pub struct DoorbellSavedState {
116    /// The doorbell's id
117    #[mesh(1)]
118    pub doorbell_id: u64,
119
120    /// The number of pages allocated for the doorbell
121    #[mesh(2)]
122    pub page_count: u32,
123}
124
125/// Saved state of a work queue for restoration during servicing
126#[derive(Debug, Protobuf, Clone)]
127#[mesh(package = "mana_driver")]
128pub struct WqSavedState {
129    /// The doorbell state of the queue, which is how the device is notified
130    #[mesh(1)]
131    pub doorbell: DoorbellSavedState,
132
133    /// The address of the doorbell
134    #[mesh(2)]
135    pub doorbell_addr: u32,
136
137    /// The id of the queue
138    #[mesh(3)]
139    pub id: u32,
140
141    /// The head of the queue
142    #[mesh(4)]
143    pub head: u32,
144
145    /// The tail of the queue
146    #[mesh(5)]
147    pub tail: u32,
148
149    /// The bitmask for wrapping queue indices
150    #[mesh(6)]
151    pub mask: u32,
152}
153
154/// Saved state for a memory region used by the driver
155/// to be restored by a DMA client during servicing
156#[derive(Debug, Protobuf, Clone)]
157#[mesh(package = "mana_driver")]
158pub struct SavedMemoryState {
159    /// The base page frame number of the memory region
160    #[mesh(1)]
161    pub base_pfn: u64,
162
163    /// How long the memory region is
164    #[mesh(2)]
165    pub len: usize,
166}