1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2019-2020 Xilinx, Inc.
* Copyright(c) 2018-2019 Solarflare Communications Inc.
*/
#include "efx.h"
#include "efx_impl.h"
#if EFSYS_OPT_MCDI_PROXY_AUTH_SERVER
__checkReturn efx_rc_t
ef10_proxy_auth_init(
__in efx_nic_t *enp)
{
EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
return (0);
}
void
ef10_proxy_auth_fini(
__in efx_nic_t *enp)
{
EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
}
static __checkReturn efx_rc_t
efx_mcdi_proxy_configure(
__in efx_nic_t *enp,
__in boolean_t disable_proxy,
__in uint64_t req_buffer_addr,
__in uint64_t resp_buffer_addr,
__in uint64_t stat_buffer_addr,
__in size_t req_size,
__in size_t resp_size,
__in uint32_t block_cnt,
__in uint8_t *op_maskp,
__in size_t op_mask_size)
{
EFX_MCDI_DECLARE_BUF(payload, MC_CMD_PROXY_CONFIGURE_EXT_IN_LEN,
MC_CMD_PROXY_CONFIGURE_OUT_LEN);
efx_mcdi_req_t req;
efx_rc_t rc;
req.emr_cmd = MC_CMD_PROXY_CONFIGURE;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_PROXY_CONFIGURE_EXT_IN_LEN;
req.emr_out_buf = payload;
req.emr_out_length = MC_CMD_PROXY_CONFIGURE_OUT_LEN;
if (!disable_proxy) {
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_FLAGS, 1);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REQUEST_BUFF_ADDR_LO,
req_buffer_addr & 0xffffffff);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REQUEST_BUFF_ADDR_HI,
req_buffer_addr >> 32);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REPLY_BUFF_ADDR_LO,
resp_buffer_addr & 0xffffffff);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REPLY_BUFF_ADDR_HI,
resp_buffer_addr >> 32);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_STATUS_BUFF_ADDR_LO,
stat_buffer_addr & 0xffffffff);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_STATUS_BUFF_ADDR_HI,
stat_buffer_addr >> 32);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REQUEST_BLOCK_SIZE,
req_size);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_REPLY_BLOCK_SIZE,
resp_size);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_STATUS_BLOCK_SIZE,
MC_PROXY_STATUS_BUFFER_LEN);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_IN_NUM_BLOCKS,
block_cnt);
memcpy(MCDI_IN2(req, efx_byte_t,
PROXY_CONFIGURE_IN_ALLOWED_MCDI_MASK),
op_maskp, op_mask_size);
MCDI_IN_SET_DWORD(req, PROXY_CONFIGURE_EXT_IN_RESERVED,
EFX_PROXY_CONFIGURE_MAGIC);
}
efx_mcdi_execute(enp, &req);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail1;
}
return (0);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
static __checkReturn efx_rc_t
efx_mcdi_privilege_modify(
__in efx_nic_t *enp,
__in uint32_t fn_group,
__in uint32_t pf_index,
__in uint32_t vf_index,
__in uint32_t add_privileges_mask,
__in uint32_t remove_privileges_mask)
{
EFX_MCDI_DECLARE_BUF(payload, MC_CMD_PRIVILEGE_MODIFY_IN_LEN,
MC_CMD_PRIVILEGE_MODIFY_OUT_LEN);
efx_mcdi_req_t req;
efx_rc_t rc;
req.emr_cmd = MC_CMD_PRIVILEGE_MODIFY;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_PRIVILEGE_MODIFY_IN_LEN;
req.emr_out_buf = payload;
req.emr_out_length = MC_CMD_PRIVILEGE_MODIFY_OUT_LEN;
EFSYS_ASSERT(fn_group <= MC_CMD_PRIVILEGE_MODIFY_IN_ONE);
MCDI_IN_SET_DWORD(req, PRIVILEGE_MODIFY_IN_FN_GROUP, fn_group);
if ((fn_group == MC_CMD_PRIVILEGE_MODIFY_IN_ONE) ||
(fn_group == MC_CMD_PRIVILEGE_MODIFY_IN_VFS_OF_PF)) {
MCDI_IN_POPULATE_DWORD_2(req,
PRIVILEGE_MODIFY_IN_FUNCTION,
PRIVILEGE_MODIFY_IN_FUNCTION_PF, pf_index,
PRIVILEGE_MODIFY_IN_FUNCTION_VF, vf_index);
}
MCDI_IN_SET_DWORD(req, PRIVILEGE_MODIFY_IN_ADD_MASK,
add_privileges_mask);
MCDI_IN_SET_DWORD(req, PRIVILEGE_MODIFY_IN_REMOVE_MASK,
remove_privileges_mask);
efx_mcdi_execute(enp, &req);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail1;
}
return (0);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
static __checkReturn efx_rc_t
efx_proxy_auth_fill_op_mask(
__in_ecount(op_count) uint32_t *op_listp,
__in size_t op_count,
__out_ecount(op_mask_size) uint32_t *op_maskp,
__in size_t op_mask_size)
{
efx_rc_t rc;
uint32_t op;
if ((op_listp == NULL) || (op_maskp == NULL)) {
rc = EINVAL;
goto fail1;
}
while (op_count--) {
op = *op_listp++;
if (op > op_mask_size * 32) {
rc = EINVAL;
goto fail2;
}
op_maskp[op / 32] |= 1u << (op & 31);
}
return (0);
fail2:
EFSYS_PROBE(fail2);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_mc_config(
__in efx_nic_t *enp,
__in_ecount(block_cnt) efsys_mem_t *request_bufferp,
__in_ecount(block_cnt) efsys_mem_t *response_bufferp,
__in_ecount(block_cnt) efsys_mem_t *status_bufferp,
__in uint32_t block_cnt,
__in_ecount(op_count) uint32_t *op_listp,
__in size_t op_count)
{
#define PROXY_OPS_MASK_SIZE \
(EFX_DIV_ROUND_UP( \
MC_CMD_PROXY_CONFIGURE_IN_ALLOWED_MCDI_MASK_LEN, \
sizeof (uint32_t)))
efx_rc_t rc;
uint32_t op_mask[PROXY_OPS_MASK_SIZE] = {0};
/* Prepare the operation mask from operation list array */
if ((rc = efx_proxy_auth_fill_op_mask(op_listp, op_count,
op_mask, PROXY_OPS_MASK_SIZE) != 0))
goto fail1;
if ((rc = efx_mcdi_proxy_configure(enp, B_FALSE,
EFSYS_MEM_ADDR(request_bufferp),
EFSYS_MEM_ADDR(response_bufferp),
EFSYS_MEM_ADDR(status_bufferp),
EFSYS_MEM_SIZE(request_bufferp) / block_cnt,
EFSYS_MEM_SIZE(response_bufferp) / block_cnt,
block_cnt, (uint8_t *)&op_mask,
sizeof (op_mask))) != 0)
goto fail2;
return (0);
fail2:
EFSYS_PROBE(fail2);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_disable(
__in efx_nic_t *enp)
{
efx_rc_t rc;
if ((rc = efx_mcdi_proxy_configure(enp, B_TRUE,
0, 0, 0, 0, 0, 0, NULL, 0) != 0))
goto fail1;
return (0);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_privilege_modify(
__in efx_nic_t *enp,
__in uint32_t fn_group,
__in uint32_t pf_index,
__in uint32_t vf_index,
__in uint32_t add_privileges_mask,
__in uint32_t remove_privileges_mask)
{
return (efx_mcdi_privilege_modify(enp, fn_group, pf_index, vf_index,
add_privileges_mask, remove_privileges_mask));
}
static __checkReturn efx_rc_t
efx_mcdi_privilege_mask_set(
__in efx_nic_t *enp,
__in uint32_t vf_index,
__in uint32_t mask,
__in uint32_t value)
{
EFX_MCDI_DECLARE_BUF(payload, MC_CMD_PRIVILEGE_MASK_IN_LEN,
MC_CMD_PRIVILEGE_MASK_OUT_LEN);
efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
efx_mcdi_req_t req;
efx_rc_t rc;
uint32_t old_mask = 0;
uint32_t new_mask = 0;
EFSYS_ASSERT((value & ~mask) == 0);
req.emr_cmd = MC_CMD_PRIVILEGE_MASK;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_PRIVILEGE_MASK_IN_LEN;
req.emr_out_buf = payload;
req.emr_out_length = MC_CMD_PRIVILEGE_MASK_OUT_LEN;
/* Get privilege mask */
MCDI_IN_POPULATE_DWORD_2(req, PRIVILEGE_MASK_IN_FUNCTION,
PRIVILEGE_MASK_IN_FUNCTION_PF, encp->enc_pf,
PRIVILEGE_MASK_IN_FUNCTION_VF, vf_index);
efx_mcdi_execute(enp, &req);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail1;
}
if (req.emr_out_length_used != MC_CMD_PRIVILEGE_MASK_OUT_LEN) {
rc = EMSGSIZE;
goto fail2;
}
old_mask = *MCDI_OUT2(req, uint32_t, PRIVILEGE_MASK_OUT_OLD_MASK);
new_mask = old_mask & ~mask;
new_mask |= (value & mask);
if (new_mask == old_mask)
return (0);
new_mask |= MC_CMD_PRIVILEGE_MASK_IN_DO_CHANGE;
memset(payload, 0, sizeof (payload));
req.emr_cmd = MC_CMD_PRIVILEGE_MASK;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_PRIVILEGE_MASK_IN_LEN;
req.emr_out_buf = payload;
req.emr_out_length = MC_CMD_PRIVILEGE_MASK_OUT_LEN;
/* Set privilege mask */
MCDI_IN_SET_DWORD(req, PRIVILEGE_MASK_IN_NEW_MASK, new_mask);
efx_mcdi_execute(enp, &req);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail3;
}
if (req.emr_out_length_used != MC_CMD_PRIVILEGE_MASK_OUT_LEN) {
rc = EMSGSIZE;
goto fail4;
}
return (0);
fail4:
EFSYS_PROBE(fail4);
fail3:
EFSYS_PROBE(fail3);
fail2:
EFSYS_PROBE(fail2);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_set_privilege_mask(
__in efx_nic_t *enp,
__in uint32_t vf_index,
__in uint32_t mask,
__in uint32_t value)
{
return (efx_mcdi_privilege_mask_set(enp, vf_index,
mask, value));
}
static __checkReturn efx_rc_t
efx_mcdi_proxy_complete(
__in efx_nic_t *enp,
__in uint32_t fn_index,
__in uint32_t proxy_result,
__in uint32_t handle)
{
EFX_MCDI_DECLARE_BUF(payload, MC_CMD_PROXY_COMPLETE_IN_LEN,
MC_CMD_PROXY_COMPLETE_OUT_LEN);
efx_mcdi_req_t req;
efx_rc_t rc;
req.emr_cmd = MC_CMD_PROXY_COMPLETE;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_PROXY_COMPLETE_IN_LEN;
req.emr_out_buf = payload;
req.emr_out_length = MC_CMD_PROXY_COMPLETE_OUT_LEN;
MCDI_IN_SET_DWORD(req, PROXY_COMPLETE_IN_BLOCK_INDEX, fn_index);
MCDI_IN_SET_DWORD(req, PROXY_COMPLETE_IN_STATUS, proxy_result);
MCDI_IN_SET_DWORD(req, PROXY_COMPLETE_IN_HANDLE, handle);
efx_mcdi_execute(enp, &req);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail1;
}
return (0);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_complete_request(
__in efx_nic_t *enp,
__in uint32_t fn_index,
__in uint32_t proxy_result,
__in uint32_t handle)
{
return (efx_mcdi_proxy_complete(enp, fn_index,
proxy_result, handle));
}
static __checkReturn efx_rc_t
efx_mcdi_proxy_cmd(
__in efx_nic_t *enp,
__in uint32_t pf_index,
__in uint32_t vf_index,
__in_bcount(request_size) uint8_t *request_bufferp,
__in size_t request_size,
__out_bcount(response_size) uint8_t *response_bufferp,
__in size_t response_size,
__out_opt size_t *response_size_actualp)
{
efx_dword_t *inbufp;
efx_mcdi_req_t req;
efx_rc_t rc;
if (request_size % sizeof (*inbufp) != 0) {
rc = EINVAL;
goto fail1;
}
EFSYS_KMEM_ALLOC(enp, (MC_CMD_PROXY_CMD_IN_LEN + request_size), inbufp);
req.emr_cmd = MC_CMD_PROXY_CMD;
req.emr_in_buf = (uint8_t *) inbufp;
req.emr_in_length = MC_CMD_PROXY_CMD_IN_LEN + request_size;
req.emr_out_buf = response_bufferp;
req.emr_out_length = response_size;
MCDI_IN_POPULATE_DWORD_2(req, PROXY_CMD_IN_TARGET,
PROXY_CMD_IN_TARGET_PF, pf_index,
PROXY_CMD_IN_TARGET_VF, vf_index);
/* Proxied command should be located just after PROXY_CMD */
memcpy(&inbufp[MC_CMD_PROXY_CMD_IN_LEN / sizeof (*inbufp)],
request_bufferp, request_size);
efx_mcdi_execute(enp, &req);
EFSYS_KMEM_FREE(enp, (MC_CMD_PROXY_CMD_IN_LEN + request_size), inbufp);
if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail2;
}
if (response_size_actualp != NULL)
*response_size_actualp = req.emr_out_length_used;
return (0);
fail2:
EFSYS_PROBE(fail2);
fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}
__checkReturn efx_rc_t
ef10_proxy_auth_get_privilege_mask(
__in efx_nic_t *enp,
__in uint32_t pf_index,
__in uint32_t vf_index,
__out uint32_t *maskp)
{
return (efx_mcdi_privilege_mask(enp, pf_index, vf_index, maskp));
}
__checkReturn efx_rc_t
ef10_proxy_auth_exec_cmd(
__in efx_nic_t *enp,
__inout efx_proxy_cmd_params_t *paramsp)
{
return (efx_mcdi_proxy_cmd(enp, paramsp->pf_index, paramsp->vf_index,
paramsp->request_bufferp, paramsp->request_size,
paramsp->response_bufferp, paramsp->response_size,
paramsp->response_size_actualp));
}
#endif /* EFSYS_OPT_MCDI_PROXY_AUTH_SERVER */
|