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