@@ -11,23 +11,40 @@ struct idpf_adapter;
11
11
#include <linux/etherdevice.h>
12
12
#include <linux/pci.h>
13
13
14
+ #include "virtchnl2.h"
15
+ #include "idpf_txrx.h"
14
16
#include "idpf_controlq.h"
15
17
16
18
/* Default Mailbox settings */
17
19
#define IDPF_NUM_DFLT_MBX_Q 2 /* includes both TX and RX */
18
20
#define IDPF_DFLT_MBX_Q_LEN 64
19
21
#define IDPF_DFLT_MBX_ID -1
22
+ /* maximum number of times to try before resetting mailbox */
23
+ #define IDPF_MB_MAX_ERR 20
24
+ #define IDPF_WAIT_FOR_EVENT_TIMEO_MIN 2000
25
+ #define IDPF_WAIT_FOR_EVENT_TIMEO 60000
26
+
27
+ #define IDPF_MAX_WAIT 500
20
28
21
29
/* available message levels */
22
30
#define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
23
31
32
+ #define IDPF_VIRTCHNL_VERSION_MAJOR VIRTCHNL2_VERSION_MAJOR_2
33
+ #define IDPF_VIRTCHNL_VERSION_MINOR VIRTCHNL2_VERSION_MINOR_0
34
+
24
35
/**
25
36
* enum idpf_state - State machine to handle bring up
26
37
* @__IDPF_STARTUP: Start the state machine
38
+ * @__IDPF_VER_CHECK: Negotiate virtchnl version
39
+ * @__IDPF_GET_CAPS: Negotiate capabilities
40
+ * @__IDPF_INIT_SW: Init based on given capabilities
27
41
* @__IDPF_STATE_LAST: Must be last, used to determine size
28
42
*/
29
43
enum idpf_state {
30
44
__IDPF_STARTUP ,
45
+ __IDPF_VER_CHECK ,
46
+ __IDPF_GET_CAPS ,
47
+ __IDPF_INIT_SW ,
31
48
__IDPF_STATE_LAST ,
32
49
};
33
50
@@ -37,13 +54,15 @@ enum idpf_state {
37
54
* @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW
38
55
* @IDPF_HR_RESET_IN_PROG: Reset in progress
39
56
* @IDPF_REMOVE_IN_PROG: Driver remove in progress
57
+ * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode
40
58
* @IDPF_FLAGS_NBITS: Must be last
41
59
*/
42
60
enum idpf_flags {
43
61
IDPF_HR_FUNC_RESET ,
44
62
IDPF_HR_DRV_LOAD ,
45
63
IDPF_HR_RESET_IN_PROG ,
46
64
IDPF_REMOVE_IN_PROG ,
65
+ IDPF_MB_INTR_MODE ,
47
66
IDPF_FLAGS_NBITS ,
48
67
};
49
68
@@ -60,11 +79,13 @@ struct idpf_reset_reg {
60
79
/**
61
80
* struct idpf_reg_ops - Device specific register operation function pointers
62
81
* @ctlq_reg_init: Mailbox control queue register initialization
82
+ * @mb_intr_reg_init: Mailbox interrupt register initialization
63
83
* @reset_reg_init: Reset register initialization
64
84
* @trigger_reset: Trigger a reset to occur
65
85
*/
66
86
struct idpf_reg_ops {
67
87
void (* ctlq_reg_init )(struct idpf_ctlq_create_info * cq );
88
+ void (* mb_intr_reg_init )(struct idpf_adapter * adapter );
68
89
void (* reset_reg_init )(struct idpf_adapter * adapter );
69
90
void (* trigger_reset )(struct idpf_adapter * adapter ,
70
91
enum idpf_flags trig_cause );
@@ -78,35 +99,149 @@ struct idpf_dev_ops {
78
99
struct idpf_reg_ops reg_ops ;
79
100
};
80
101
102
+ /* These macros allow us to generate an enum and a matching char * array of
103
+ * stringified enums that are always in sync. Checkpatch issues a bogus warning
104
+ * about this being a complex macro; but it's wrong, these are never used as a
105
+ * statement and instead only used to define the enum and array.
106
+ */
107
+ #define IDPF_FOREACH_VPORT_VC_STATE (STATE ) \
108
+ STATE(IDPF_VC_ALLOC_VECTORS) \
109
+ STATE(IDPF_VC_ALLOC_VECTORS_ERR) \
110
+ STATE(IDPF_VC_DEALLOC_VECTORS) \
111
+ STATE(IDPF_VC_DEALLOC_VECTORS_ERR) \
112
+ STATE(IDPF_VC_NBITS)
113
+
114
+ #define IDPF_GEN_ENUM (ENUM ) ENUM,
115
+ #define IDPF_GEN_STRING (STRING ) #STRING,
116
+
117
+ enum idpf_vport_vc_state {
118
+ IDPF_FOREACH_VPORT_VC_STATE (IDPF_GEN_ENUM )
119
+ };
120
+
121
+ extern const char * const idpf_vport_vc_state_str [];
122
+
123
+ /**
124
+ * struct idpf_vport - Handle for netdevices and queue resources
125
+ * @vport_id: Device given vport identifier
126
+ */
127
+ struct idpf_vport {
128
+ u32 vport_id ;
129
+ };
130
+
131
+ /**
132
+ * struct idpf_vector_lifo - Stack to maintain vector indexes used for vector
133
+ * distribution algorithm
134
+ * @top: Points to stack top i.e. next available vector index
135
+ * @base: Always points to start of the free pool
136
+ * @size: Total size of the vector stack
137
+ * @vec_idx: Array to store all the vector indexes
138
+ *
139
+ * Vector stack maintains all the relative vector indexes at the *adapter*
140
+ * level. This stack is divided into 2 parts, first one is called as 'default
141
+ * pool' and other one is called 'free pool'. Vector distribution algorithm
142
+ * gives priority to default vports in a way that at least IDPF_MIN_Q_VEC
143
+ * vectors are allocated per default vport and the relative vector indexes for
144
+ * those are maintained in default pool. Free pool contains all the unallocated
145
+ * vector indexes which can be allocated on-demand basis. Mailbox vector index
146
+ * is maintained in the default pool of the stack.
147
+ */
148
+ struct idpf_vector_lifo {
149
+ u16 top ;
150
+ u16 base ;
151
+ u16 size ;
152
+ u16 * vec_idx ;
153
+ };
154
+
81
155
/**
82
156
* struct idpf_adapter - Device data struct generated on probe
83
157
* @pdev: PCI device struct given on probe
158
+ * @virt_ver_maj: Virtchnl version major
159
+ * @virt_ver_min: Virtchnl version minor
84
160
* @msg_enable: Debug message level enabled
161
+ * @mb_wait_count: Number of times mailbox was attempted initialization
85
162
* @state: Init state machine
86
163
* @flags: See enum idpf_flags
87
164
* @reset_reg: See struct idpf_reset_reg
88
165
* @hw: Device access data
166
+ * @num_req_msix: Requested number of MSIX vectors
167
+ * @num_avail_msix: Available number of MSIX vectors
168
+ * @num_msix_entries: Number of entries in MSIX table
169
+ * @msix_entries: MSIX table
170
+ * @req_vec_chunks: Requested vector chunk data
171
+ * @mb_vector: Mailbox vector data
172
+ * @vector_stack: Stack to store the msix vector indexes
173
+ * @irq_mb_handler: Handler for hard interrupt for mailbox
174
+ * @serv_task: Periodically recurring maintenance task
175
+ * @serv_wq: Workqueue for service task
176
+ * @mbx_task: Task to handle mailbox interrupts
177
+ * @mbx_wq: Workqueue for mailbox responses
89
178
* @vc_event_task: Task to handle out of band virtchnl event notifications
90
179
* @vc_event_wq: Workqueue for virtchnl events
180
+ * @caps: Negotiated capabilities with device
181
+ * @vchnl_wq: Wait queue for virtchnl messages
182
+ * @vc_state: Virtchnl message state
183
+ * @vc_msg: Virtchnl message buffer
91
184
* @dev_ops: See idpf_dev_ops
92
185
* @vport_ctrl_lock: Lock to protect the vport control flow
186
+ * @vector_lock: Lock to protect vector distribution
187
+ * @vc_buf_lock: Lock to protect virtchnl buffer
93
188
*/
94
189
struct idpf_adapter {
95
190
struct pci_dev * pdev ;
191
+ u32 virt_ver_maj ;
192
+ u32 virt_ver_min ;
193
+
96
194
u32 msg_enable ;
195
+ u32 mb_wait_count ;
97
196
enum idpf_state state ;
98
197
DECLARE_BITMAP (flags , IDPF_FLAGS_NBITS );
99
198
struct idpf_reset_reg reset_reg ;
100
199
struct idpf_hw hw ;
200
+ u16 num_req_msix ;
201
+ u16 num_avail_msix ;
202
+ u16 num_msix_entries ;
203
+ struct msix_entry * msix_entries ;
204
+ struct virtchnl2_alloc_vectors * req_vec_chunks ;
205
+ struct idpf_q_vector mb_vector ;
206
+ struct idpf_vector_lifo vector_stack ;
207
+ irqreturn_t (* irq_mb_handler )(int irq , void * data );
101
208
209
+ struct delayed_work serv_task ;
210
+ struct workqueue_struct * serv_wq ;
211
+ struct delayed_work mbx_task ;
212
+ struct workqueue_struct * mbx_wq ;
102
213
struct delayed_work vc_event_task ;
103
214
struct workqueue_struct * vc_event_wq ;
215
+ struct virtchnl2_get_capabilities caps ;
104
216
217
+ wait_queue_head_t vchnl_wq ;
218
+ DECLARE_BITMAP (vc_state , IDPF_VC_NBITS );
219
+ char vc_msg [IDPF_CTLQ_MAX_BUF_LEN ];
105
220
struct idpf_dev_ops dev_ops ;
106
221
107
222
struct mutex vport_ctrl_lock ;
223
+ struct mutex vector_lock ;
224
+ struct mutex vc_buf_lock ;
108
225
};
109
226
227
+ /**
228
+ * idpf_get_reserved_vecs - Get reserved vectors
229
+ * @adapter: private data struct
230
+ */
231
+ static inline u16 idpf_get_reserved_vecs (struct idpf_adapter * adapter )
232
+ {
233
+ return le16_to_cpu (adapter -> caps .num_allocated_vectors );
234
+ }
235
+
236
+ /**
237
+ * idpf_get_default_vports - Get default number of vports
238
+ * @adapter: private data struct
239
+ */
240
+ static inline u16 idpf_get_default_vports (struct idpf_adapter * adapter )
241
+ {
242
+ return le16_to_cpu (adapter -> caps .default_num_vports );
243
+ }
244
+
110
245
/**
111
246
* idpf_get_reg_addr - Get BAR0 register address
112
247
* @adapter: private data struct
@@ -135,10 +270,38 @@ static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter)
135
270
adapter -> hw .arq -> reg .len_mask );
136
271
}
137
272
273
+ /**
274
+ * idpf_is_reset_in_prog - check if reset is in progress
275
+ * @adapter: driver specific private structure
276
+ *
277
+ * Returns true if hard reset is in progress, false otherwise
278
+ */
279
+ static inline bool idpf_is_reset_in_prog (struct idpf_adapter * adapter )
280
+ {
281
+ return (test_bit (IDPF_HR_RESET_IN_PROG , adapter -> flags ) ||
282
+ test_bit (IDPF_HR_FUNC_RESET , adapter -> flags ) ||
283
+ test_bit (IDPF_HR_DRV_LOAD , adapter -> flags ));
284
+ }
285
+
286
+ void idpf_service_task (struct work_struct * work );
287
+ void idpf_mbx_task (struct work_struct * work );
138
288
void idpf_vc_event_task (struct work_struct * work );
139
289
void idpf_dev_ops_init (struct idpf_adapter * adapter );
140
290
void idpf_vf_dev_ops_init (struct idpf_adapter * adapter );
141
291
int idpf_init_dflt_mbx (struct idpf_adapter * adapter );
142
292
void idpf_deinit_dflt_mbx (struct idpf_adapter * adapter );
293
+ int idpf_vc_core_init (struct idpf_adapter * adapter );
294
+ void idpf_vc_core_deinit (struct idpf_adapter * adapter );
295
+ int idpf_intr_req (struct idpf_adapter * adapter );
296
+ void idpf_intr_rel (struct idpf_adapter * adapter );
297
+ int idpf_send_dealloc_vectors_msg (struct idpf_adapter * adapter );
298
+ int idpf_send_alloc_vectors_msg (struct idpf_adapter * adapter , u16 num_vectors );
299
+ int idpf_get_vec_ids (struct idpf_adapter * adapter ,
300
+ u16 * vecids , int num_vecids ,
301
+ struct virtchnl2_vector_chunks * chunks );
302
+ int idpf_recv_mb_msg (struct idpf_adapter * adapter , u32 op ,
303
+ void * msg , int msg_size );
304
+ int idpf_send_mb_msg (struct idpf_adapter * adapter , u32 op ,
305
+ u16 msg_size , u8 * msg );
143
306
144
307
#endif /* !_IDPF_H_ */
0 commit comments