net/sfc/base: get actions MARK and FLAG support
[dpdk.git] / drivers / net / sfc / base / ef10_nic.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2012-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9 #if EFSYS_OPT_MON_MCDI
10 #include "mcdi_mon.h"
11 #endif
12
13 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
14
15 #include "ef10_tlv_layout.h"
16
17         __checkReturn   efx_rc_t
18 efx_mcdi_get_port_assignment(
19         __in            efx_nic_t *enp,
20         __out           uint32_t *portp)
21 {
22         efx_mcdi_req_t req;
23         uint8_t payload[MAX(MC_CMD_GET_PORT_ASSIGNMENT_IN_LEN,
24                             MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN)];
25         efx_rc_t rc;
26
27         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
28             enp->en_family == EFX_FAMILY_MEDFORD ||
29             enp->en_family == EFX_FAMILY_MEDFORD2);
30
31         (void) memset(payload, 0, sizeof (payload));
32         req.emr_cmd = MC_CMD_GET_PORT_ASSIGNMENT;
33         req.emr_in_buf = payload;
34         req.emr_in_length = MC_CMD_GET_PORT_ASSIGNMENT_IN_LEN;
35         req.emr_out_buf = payload;
36         req.emr_out_length = MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN;
37
38         efx_mcdi_execute(enp, &req);
39
40         if (req.emr_rc != 0) {
41                 rc = req.emr_rc;
42                 goto fail1;
43         }
44
45         if (req.emr_out_length_used < MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN) {
46                 rc = EMSGSIZE;
47                 goto fail2;
48         }
49
50         *portp = MCDI_OUT_DWORD(req, GET_PORT_ASSIGNMENT_OUT_PORT);
51
52         return (0);
53
54 fail2:
55         EFSYS_PROBE(fail2);
56 fail1:
57         EFSYS_PROBE1(fail1, efx_rc_t, rc);
58
59         return (rc);
60 }
61
62         __checkReturn   efx_rc_t
63 efx_mcdi_get_port_modes(
64         __in            efx_nic_t *enp,
65         __out           uint32_t *modesp,
66         __out_opt       uint32_t *current_modep)
67 {
68         efx_mcdi_req_t req;
69         uint8_t payload[MAX(MC_CMD_GET_PORT_MODES_IN_LEN,
70                             MC_CMD_GET_PORT_MODES_OUT_LEN)];
71         efx_rc_t rc;
72
73         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
74             enp->en_family == EFX_FAMILY_MEDFORD ||
75             enp->en_family == EFX_FAMILY_MEDFORD2);
76
77         (void) memset(payload, 0, sizeof (payload));
78         req.emr_cmd = MC_CMD_GET_PORT_MODES;
79         req.emr_in_buf = payload;
80         req.emr_in_length = MC_CMD_GET_PORT_MODES_IN_LEN;
81         req.emr_out_buf = payload;
82         req.emr_out_length = MC_CMD_GET_PORT_MODES_OUT_LEN;
83
84         efx_mcdi_execute(enp, &req);
85
86         if (req.emr_rc != 0) {
87                 rc = req.emr_rc;
88                 goto fail1;
89         }
90
91         /*
92          * Require only Modes and DefaultMode fields, unless the current mode
93          * was requested (CurrentMode field was added for Medford).
94          */
95         if (req.emr_out_length_used <
96             MC_CMD_GET_PORT_MODES_OUT_CURRENT_MODE_OFST) {
97                 rc = EMSGSIZE;
98                 goto fail2;
99         }
100         if ((current_modep != NULL) && (req.emr_out_length_used <
101             MC_CMD_GET_PORT_MODES_OUT_CURRENT_MODE_OFST + 4)) {
102                 rc = EMSGSIZE;
103                 goto fail3;
104         }
105
106         *modesp = MCDI_OUT_DWORD(req, GET_PORT_MODES_OUT_MODES);
107
108         if (current_modep != NULL) {
109                 *current_modep = MCDI_OUT_DWORD(req,
110                                             GET_PORT_MODES_OUT_CURRENT_MODE);
111         }
112
113         return (0);
114
115 fail3:
116         EFSYS_PROBE(fail3);
117 fail2:
118         EFSYS_PROBE(fail2);
119 fail1:
120         EFSYS_PROBE1(fail1, efx_rc_t, rc);
121
122         return (rc);
123 }
124
125         __checkReturn   efx_rc_t
126 ef10_nic_get_port_mode_bandwidth(
127         __in            uint32_t port_mode,
128         __out           uint32_t *bandwidth_mbpsp)
129 {
130         uint32_t bandwidth;
131         efx_rc_t rc;
132
133         switch (port_mode) {
134         case TLV_PORT_MODE_10G:
135                 bandwidth = 10000;
136                 break;
137         case TLV_PORT_MODE_10G_10G:
138                 bandwidth = 10000 * 2;
139                 break;
140         case TLV_PORT_MODE_10G_10G_10G_10G:
141         case TLV_PORT_MODE_10G_10G_10G_10G_Q:
142         case TLV_PORT_MODE_10G_10G_10G_10G_Q1_Q2:
143         case TLV_PORT_MODE_10G_10G_10G_10G_Q2:
144                 bandwidth = 10000 * 4;
145                 break;
146         case TLV_PORT_MODE_40G:
147                 bandwidth = 40000;
148                 break;
149         case TLV_PORT_MODE_40G_40G:
150                 bandwidth = 40000 * 2;
151                 break;
152         case TLV_PORT_MODE_40G_10G_10G:
153         case TLV_PORT_MODE_10G_10G_40G:
154                 bandwidth = 40000 + (10000 * 2);
155                 break;
156         default:
157                 rc = EINVAL;
158                 goto fail1;
159         }
160
161         *bandwidth_mbpsp = bandwidth;
162
163         return (0);
164
165 fail1:
166         EFSYS_PROBE1(fail1, efx_rc_t, rc);
167
168         return (rc);
169 }
170
171 static  __checkReturn           efx_rc_t
172 efx_mcdi_vadaptor_alloc(
173         __in                    efx_nic_t *enp,
174         __in                    uint32_t port_id)
175 {
176         efx_mcdi_req_t req;
177         uint8_t payload[MAX(MC_CMD_VADAPTOR_ALLOC_IN_LEN,
178                             MC_CMD_VADAPTOR_ALLOC_OUT_LEN)];
179         efx_rc_t rc;
180
181         EFSYS_ASSERT3U(enp->en_vport_id, ==, EVB_PORT_ID_NULL);
182
183         (void) memset(payload, 0, sizeof (payload));
184         req.emr_cmd = MC_CMD_VADAPTOR_ALLOC;
185         req.emr_in_buf = payload;
186         req.emr_in_length = MC_CMD_VADAPTOR_ALLOC_IN_LEN;
187         req.emr_out_buf = payload;
188         req.emr_out_length = MC_CMD_VADAPTOR_ALLOC_OUT_LEN;
189
190         MCDI_IN_SET_DWORD(req, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
191         MCDI_IN_POPULATE_DWORD_1(req, VADAPTOR_ALLOC_IN_FLAGS,
192             VADAPTOR_ALLOC_IN_FLAG_PERMIT_SET_MAC_WHEN_FILTERS_INSTALLED,
193             enp->en_nic_cfg.enc_allow_set_mac_with_installed_filters ? 1 : 0);
194
195         efx_mcdi_execute(enp, &req);
196
197         if (req.emr_rc != 0) {
198                 rc = req.emr_rc;
199                 goto fail1;
200         }
201
202         return (0);
203
204 fail1:
205         EFSYS_PROBE1(fail1, efx_rc_t, rc);
206
207         return (rc);
208 }
209
210 static  __checkReturn           efx_rc_t
211 efx_mcdi_vadaptor_free(
212         __in                    efx_nic_t *enp,
213         __in                    uint32_t port_id)
214 {
215         efx_mcdi_req_t req;
216         uint8_t payload[MAX(MC_CMD_VADAPTOR_FREE_IN_LEN,
217                             MC_CMD_VADAPTOR_FREE_OUT_LEN)];
218         efx_rc_t rc;
219
220         (void) memset(payload, 0, sizeof (payload));
221         req.emr_cmd = MC_CMD_VADAPTOR_FREE;
222         req.emr_in_buf = payload;
223         req.emr_in_length = MC_CMD_VADAPTOR_FREE_IN_LEN;
224         req.emr_out_buf = payload;
225         req.emr_out_length = MC_CMD_VADAPTOR_FREE_OUT_LEN;
226
227         MCDI_IN_SET_DWORD(req, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
228
229         efx_mcdi_execute(enp, &req);
230
231         if (req.emr_rc != 0) {
232                 rc = req.emr_rc;
233                 goto fail1;
234         }
235
236         return (0);
237
238 fail1:
239         EFSYS_PROBE1(fail1, efx_rc_t, rc);
240
241         return (rc);
242 }
243
244         __checkReturn   efx_rc_t
245 efx_mcdi_get_mac_address_pf(
246         __in                    efx_nic_t *enp,
247         __out_ecount_opt(6)     uint8_t mac_addrp[6])
248 {
249         efx_mcdi_req_t req;
250         uint8_t payload[MAX(MC_CMD_GET_MAC_ADDRESSES_IN_LEN,
251                             MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)];
252         efx_rc_t rc;
253
254         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
255             enp->en_family == EFX_FAMILY_MEDFORD ||
256             enp->en_family == EFX_FAMILY_MEDFORD2);
257
258         (void) memset(payload, 0, sizeof (payload));
259         req.emr_cmd = MC_CMD_GET_MAC_ADDRESSES;
260         req.emr_in_buf = payload;
261         req.emr_in_length = MC_CMD_GET_MAC_ADDRESSES_IN_LEN;
262         req.emr_out_buf = payload;
263         req.emr_out_length = MC_CMD_GET_MAC_ADDRESSES_OUT_LEN;
264
265         efx_mcdi_execute(enp, &req);
266
267         if (req.emr_rc != 0) {
268                 rc = req.emr_rc;
269                 goto fail1;
270         }
271
272         if (req.emr_out_length_used < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) {
273                 rc = EMSGSIZE;
274                 goto fail2;
275         }
276
277         if (MCDI_OUT_DWORD(req, GET_MAC_ADDRESSES_OUT_MAC_COUNT) < 1) {
278                 rc = ENOENT;
279                 goto fail3;
280         }
281
282         if (mac_addrp != NULL) {
283                 uint8_t *addrp;
284
285                 addrp = MCDI_OUT2(req, uint8_t,
286                     GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE);
287
288                 EFX_MAC_ADDR_COPY(mac_addrp, addrp);
289         }
290
291         return (0);
292
293 fail3:
294         EFSYS_PROBE(fail3);
295 fail2:
296         EFSYS_PROBE(fail2);
297 fail1:
298         EFSYS_PROBE1(fail1, efx_rc_t, rc);
299
300         return (rc);
301 }
302
303         __checkReturn   efx_rc_t
304 efx_mcdi_get_mac_address_vf(
305         __in                    efx_nic_t *enp,
306         __out_ecount_opt(6)     uint8_t mac_addrp[6])
307 {
308         efx_mcdi_req_t req;
309         uint8_t payload[MAX(MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN,
310                             MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX)];
311         efx_rc_t rc;
312
313         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
314             enp->en_family == EFX_FAMILY_MEDFORD ||
315             enp->en_family == EFX_FAMILY_MEDFORD2);
316
317         (void) memset(payload, 0, sizeof (payload));
318         req.emr_cmd = MC_CMD_VPORT_GET_MAC_ADDRESSES;
319         req.emr_in_buf = payload;
320         req.emr_in_length = MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN;
321         req.emr_out_buf = payload;
322         req.emr_out_length = MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX;
323
324         MCDI_IN_SET_DWORD(req, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
325             EVB_PORT_ID_ASSIGNED);
326
327         efx_mcdi_execute(enp, &req);
328
329         if (req.emr_rc != 0) {
330                 rc = req.emr_rc;
331                 goto fail1;
332         }
333
334         if (req.emr_out_length_used <
335             MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN) {
336                 rc = EMSGSIZE;
337                 goto fail2;
338         }
339
340         if (MCDI_OUT_DWORD(req,
341                 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT) < 1) {
342                 rc = ENOENT;
343                 goto fail3;
344         }
345
346         if (mac_addrp != NULL) {
347                 uint8_t *addrp;
348
349                 addrp = MCDI_OUT2(req, uint8_t,
350                     VPORT_GET_MAC_ADDRESSES_OUT_MACADDR);
351
352                 EFX_MAC_ADDR_COPY(mac_addrp, addrp);
353         }
354
355         return (0);
356
357 fail3:
358         EFSYS_PROBE(fail3);
359 fail2:
360         EFSYS_PROBE(fail2);
361 fail1:
362         EFSYS_PROBE1(fail1, efx_rc_t, rc);
363
364         return (rc);
365 }
366
367         __checkReturn   efx_rc_t
368 efx_mcdi_get_clock(
369         __in            efx_nic_t *enp,
370         __out           uint32_t *sys_freqp,
371         __out           uint32_t *dpcpu_freqp)
372 {
373         efx_mcdi_req_t req;
374         uint8_t payload[MAX(MC_CMD_GET_CLOCK_IN_LEN,
375                             MC_CMD_GET_CLOCK_OUT_LEN)];
376         efx_rc_t rc;
377
378         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
379             enp->en_family == EFX_FAMILY_MEDFORD ||
380             enp->en_family == EFX_FAMILY_MEDFORD2);
381
382         (void) memset(payload, 0, sizeof (payload));
383         req.emr_cmd = MC_CMD_GET_CLOCK;
384         req.emr_in_buf = payload;
385         req.emr_in_length = MC_CMD_GET_CLOCK_IN_LEN;
386         req.emr_out_buf = payload;
387         req.emr_out_length = MC_CMD_GET_CLOCK_OUT_LEN;
388
389         efx_mcdi_execute(enp, &req);
390
391         if (req.emr_rc != 0) {
392                 rc = req.emr_rc;
393                 goto fail1;
394         }
395
396         if (req.emr_out_length_used < MC_CMD_GET_CLOCK_OUT_LEN) {
397                 rc = EMSGSIZE;
398                 goto fail2;
399         }
400
401         *sys_freqp = MCDI_OUT_DWORD(req, GET_CLOCK_OUT_SYS_FREQ);
402         if (*sys_freqp == 0) {
403                 rc = EINVAL;
404                 goto fail3;
405         }
406         *dpcpu_freqp = MCDI_OUT_DWORD(req, GET_CLOCK_OUT_DPCPU_FREQ);
407         if (*dpcpu_freqp == 0) {
408                 rc = EINVAL;
409                 goto fail4;
410         }
411
412         return (0);
413
414 fail4:
415         EFSYS_PROBE(fail4);
416 fail3:
417         EFSYS_PROBE(fail3);
418 fail2:
419         EFSYS_PROBE(fail2);
420 fail1:
421         EFSYS_PROBE1(fail1, efx_rc_t, rc);
422
423         return (rc);
424 }
425
426         __checkReturn   efx_rc_t
427 efx_mcdi_get_rxdp_config(
428         __in            efx_nic_t *enp,
429         __out           uint32_t *end_paddingp)
430 {
431         efx_mcdi_req_t req;
432         uint8_t payload[MAX(MC_CMD_GET_RXDP_CONFIG_IN_LEN,
433                             MC_CMD_GET_RXDP_CONFIG_OUT_LEN)];
434         uint32_t end_padding;
435         efx_rc_t rc;
436
437         memset(payload, 0, sizeof (payload));
438         req.emr_cmd = MC_CMD_GET_RXDP_CONFIG;
439         req.emr_in_buf = payload;
440         req.emr_in_length = MC_CMD_GET_RXDP_CONFIG_IN_LEN;
441         req.emr_out_buf = payload;
442         req.emr_out_length = MC_CMD_GET_RXDP_CONFIG_OUT_LEN;
443
444         efx_mcdi_execute(enp, &req);
445         if (req.emr_rc != 0) {
446                 rc = req.emr_rc;
447                 goto fail1;
448         }
449
450         if (MCDI_OUT_DWORD_FIELD(req, GET_RXDP_CONFIG_OUT_DATA,
451                                     GET_RXDP_CONFIG_OUT_PAD_HOST_DMA) == 0) {
452                 /* RX DMA end padding is disabled */
453                 end_padding = 0;
454         } else {
455                 switch (MCDI_OUT_DWORD_FIELD(req, GET_RXDP_CONFIG_OUT_DATA,
456                                             GET_RXDP_CONFIG_OUT_PAD_HOST_LEN)) {
457                 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_64:
458                         end_padding = 64;
459                         break;
460                 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_128:
461                         end_padding = 128;
462                         break;
463                 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_256:
464                         end_padding = 256;
465                         break;
466                 default:
467                         rc = ENOTSUP;
468                         goto fail2;
469                 }
470         }
471
472         *end_paddingp = end_padding;
473
474         return (0);
475
476 fail2:
477         EFSYS_PROBE(fail2);
478 fail1:
479         EFSYS_PROBE1(fail1, efx_rc_t, rc);
480
481         return (rc);
482 }
483
484         __checkReturn   efx_rc_t
485 efx_mcdi_get_vector_cfg(
486         __in            efx_nic_t *enp,
487         __out_opt       uint32_t *vec_basep,
488         __out_opt       uint32_t *pf_nvecp,
489         __out_opt       uint32_t *vf_nvecp)
490 {
491         efx_mcdi_req_t req;
492         uint8_t payload[MAX(MC_CMD_GET_VECTOR_CFG_IN_LEN,
493                             MC_CMD_GET_VECTOR_CFG_OUT_LEN)];
494         efx_rc_t rc;
495
496         (void) memset(payload, 0, sizeof (payload));
497         req.emr_cmd = MC_CMD_GET_VECTOR_CFG;
498         req.emr_in_buf = payload;
499         req.emr_in_length = MC_CMD_GET_VECTOR_CFG_IN_LEN;
500         req.emr_out_buf = payload;
501         req.emr_out_length = MC_CMD_GET_VECTOR_CFG_OUT_LEN;
502
503         efx_mcdi_execute(enp, &req);
504
505         if (req.emr_rc != 0) {
506                 rc = req.emr_rc;
507                 goto fail1;
508         }
509
510         if (req.emr_out_length_used < MC_CMD_GET_VECTOR_CFG_OUT_LEN) {
511                 rc = EMSGSIZE;
512                 goto fail2;
513         }
514
515         if (vec_basep != NULL)
516                 *vec_basep = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VEC_BASE);
517         if (pf_nvecp != NULL)
518                 *pf_nvecp = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VECS_PER_PF);
519         if (vf_nvecp != NULL)
520                 *vf_nvecp = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VECS_PER_VF);
521
522         return (0);
523
524 fail2:
525         EFSYS_PROBE(fail2);
526 fail1:
527         EFSYS_PROBE1(fail1, efx_rc_t, rc);
528
529         return (rc);
530 }
531
532 static  __checkReturn   efx_rc_t
533 efx_mcdi_alloc_vis(
534         __in            efx_nic_t *enp,
535         __in            uint32_t min_vi_count,
536         __in            uint32_t max_vi_count,
537         __out           uint32_t *vi_basep,
538         __out           uint32_t *vi_countp,
539         __out           uint32_t *vi_shiftp)
540 {
541         efx_mcdi_req_t req;
542         uint8_t payload[MAX(MC_CMD_ALLOC_VIS_IN_LEN,
543                             MC_CMD_ALLOC_VIS_EXT_OUT_LEN)];
544         efx_rc_t rc;
545
546         if (vi_countp == NULL) {
547                 rc = EINVAL;
548                 goto fail1;
549         }
550
551         (void) memset(payload, 0, sizeof (payload));
552         req.emr_cmd = MC_CMD_ALLOC_VIS;
553         req.emr_in_buf = payload;
554         req.emr_in_length = MC_CMD_ALLOC_VIS_IN_LEN;
555         req.emr_out_buf = payload;
556         req.emr_out_length = MC_CMD_ALLOC_VIS_EXT_OUT_LEN;
557
558         MCDI_IN_SET_DWORD(req, ALLOC_VIS_IN_MIN_VI_COUNT, min_vi_count);
559         MCDI_IN_SET_DWORD(req, ALLOC_VIS_IN_MAX_VI_COUNT, max_vi_count);
560
561         efx_mcdi_execute(enp, &req);
562
563         if (req.emr_rc != 0) {
564                 rc = req.emr_rc;
565                 goto fail2;
566         }
567
568         if (req.emr_out_length_used < MC_CMD_ALLOC_VIS_OUT_LEN) {
569                 rc = EMSGSIZE;
570                 goto fail3;
571         }
572
573         *vi_basep = MCDI_OUT_DWORD(req, ALLOC_VIS_OUT_VI_BASE);
574         *vi_countp = MCDI_OUT_DWORD(req, ALLOC_VIS_OUT_VI_COUNT);
575
576         /* Report VI_SHIFT if available (always zero for Huntington) */
577         if (req.emr_out_length_used < MC_CMD_ALLOC_VIS_EXT_OUT_LEN)
578                 *vi_shiftp = 0;
579         else
580                 *vi_shiftp = MCDI_OUT_DWORD(req, ALLOC_VIS_EXT_OUT_VI_SHIFT);
581
582         return (0);
583
584 fail3:
585         EFSYS_PROBE(fail3);
586 fail2:
587         EFSYS_PROBE(fail2);
588 fail1:
589         EFSYS_PROBE1(fail1, efx_rc_t, rc);
590
591         return (rc);
592 }
593
594
595 static  __checkReturn   efx_rc_t
596 efx_mcdi_free_vis(
597         __in            efx_nic_t *enp)
598 {
599         efx_mcdi_req_t req;
600         efx_rc_t rc;
601
602         EFX_STATIC_ASSERT(MC_CMD_FREE_VIS_IN_LEN == 0);
603         EFX_STATIC_ASSERT(MC_CMD_FREE_VIS_OUT_LEN == 0);
604
605         req.emr_cmd = MC_CMD_FREE_VIS;
606         req.emr_in_buf = NULL;
607         req.emr_in_length = 0;
608         req.emr_out_buf = NULL;
609         req.emr_out_length = 0;
610
611         efx_mcdi_execute_quiet(enp, &req);
612
613         /* Ignore ELREADY (no allocated VIs, so nothing to free) */
614         if ((req.emr_rc != 0) && (req.emr_rc != EALREADY)) {
615                 rc = req.emr_rc;
616                 goto fail1;
617         }
618
619         return (0);
620
621 fail1:
622         EFSYS_PROBE1(fail1, efx_rc_t, rc);
623
624         return (rc);
625 }
626
627
628 static  __checkReturn   efx_rc_t
629 efx_mcdi_alloc_piobuf(
630         __in            efx_nic_t *enp,
631         __out           efx_piobuf_handle_t *handlep)
632 {
633         efx_mcdi_req_t req;
634         uint8_t payload[MAX(MC_CMD_ALLOC_PIOBUF_IN_LEN,
635                             MC_CMD_ALLOC_PIOBUF_OUT_LEN)];
636         efx_rc_t rc;
637
638         if (handlep == NULL) {
639                 rc = EINVAL;
640                 goto fail1;
641         }
642
643         (void) memset(payload, 0, sizeof (payload));
644         req.emr_cmd = MC_CMD_ALLOC_PIOBUF;
645         req.emr_in_buf = payload;
646         req.emr_in_length = MC_CMD_ALLOC_PIOBUF_IN_LEN;
647         req.emr_out_buf = payload;
648         req.emr_out_length = MC_CMD_ALLOC_PIOBUF_OUT_LEN;
649
650         efx_mcdi_execute_quiet(enp, &req);
651
652         if (req.emr_rc != 0) {
653                 rc = req.emr_rc;
654                 goto fail2;
655         }
656
657         if (req.emr_out_length_used < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
658                 rc = EMSGSIZE;
659                 goto fail3;
660         }
661
662         *handlep = MCDI_OUT_DWORD(req, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
663
664         return (0);
665
666 fail3:
667         EFSYS_PROBE(fail3);
668 fail2:
669         EFSYS_PROBE(fail2);
670 fail1:
671         EFSYS_PROBE1(fail1, efx_rc_t, rc);
672
673         return (rc);
674 }
675
676 static  __checkReturn   efx_rc_t
677 efx_mcdi_free_piobuf(
678         __in            efx_nic_t *enp,
679         __in            efx_piobuf_handle_t handle)
680 {
681         efx_mcdi_req_t req;
682         uint8_t payload[MAX(MC_CMD_FREE_PIOBUF_IN_LEN,
683                             MC_CMD_FREE_PIOBUF_OUT_LEN)];
684         efx_rc_t rc;
685
686         (void) memset(payload, 0, sizeof (payload));
687         req.emr_cmd = MC_CMD_FREE_PIOBUF;
688         req.emr_in_buf = payload;
689         req.emr_in_length = MC_CMD_FREE_PIOBUF_IN_LEN;
690         req.emr_out_buf = payload;
691         req.emr_out_length = MC_CMD_FREE_PIOBUF_OUT_LEN;
692
693         MCDI_IN_SET_DWORD(req, FREE_PIOBUF_IN_PIOBUF_HANDLE, handle);
694
695         efx_mcdi_execute_quiet(enp, &req);
696
697         if (req.emr_rc != 0) {
698                 rc = req.emr_rc;
699                 goto fail1;
700         }
701
702         return (0);
703
704 fail1:
705         EFSYS_PROBE1(fail1, efx_rc_t, rc);
706
707         return (rc);
708 }
709
710 static  __checkReturn   efx_rc_t
711 efx_mcdi_link_piobuf(
712         __in            efx_nic_t *enp,
713         __in            uint32_t vi_index,
714         __in            efx_piobuf_handle_t handle)
715 {
716         efx_mcdi_req_t req;
717         uint8_t payload[MAX(MC_CMD_LINK_PIOBUF_IN_LEN,
718                             MC_CMD_LINK_PIOBUF_OUT_LEN)];
719         efx_rc_t rc;
720
721         (void) memset(payload, 0, sizeof (payload));
722         req.emr_cmd = MC_CMD_LINK_PIOBUF;
723         req.emr_in_buf = payload;
724         req.emr_in_length = MC_CMD_LINK_PIOBUF_IN_LEN;
725         req.emr_out_buf = payload;
726         req.emr_out_length = MC_CMD_LINK_PIOBUF_OUT_LEN;
727
728         MCDI_IN_SET_DWORD(req, LINK_PIOBUF_IN_PIOBUF_HANDLE, handle);
729         MCDI_IN_SET_DWORD(req, LINK_PIOBUF_IN_TXQ_INSTANCE, vi_index);
730
731         efx_mcdi_execute(enp, &req);
732
733         if (req.emr_rc != 0) {
734                 rc = req.emr_rc;
735                 goto fail1;
736         }
737
738         return (0);
739
740 fail1:
741         EFSYS_PROBE1(fail1, efx_rc_t, rc);
742
743         return (rc);
744 }
745
746 static  __checkReturn   efx_rc_t
747 efx_mcdi_unlink_piobuf(
748         __in            efx_nic_t *enp,
749         __in            uint32_t vi_index)
750 {
751         efx_mcdi_req_t req;
752         uint8_t payload[MAX(MC_CMD_UNLINK_PIOBUF_IN_LEN,
753                             MC_CMD_UNLINK_PIOBUF_OUT_LEN)];
754         efx_rc_t rc;
755
756         (void) memset(payload, 0, sizeof (payload));
757         req.emr_cmd = MC_CMD_UNLINK_PIOBUF;
758         req.emr_in_buf = payload;
759         req.emr_in_length = MC_CMD_UNLINK_PIOBUF_IN_LEN;
760         req.emr_out_buf = payload;
761         req.emr_out_length = MC_CMD_UNLINK_PIOBUF_OUT_LEN;
762
763         MCDI_IN_SET_DWORD(req, UNLINK_PIOBUF_IN_TXQ_INSTANCE, vi_index);
764
765         efx_mcdi_execute_quiet(enp, &req);
766
767         if (req.emr_rc != 0) {
768                 rc = req.emr_rc;
769                 goto fail1;
770         }
771
772         return (0);
773
774 fail1:
775         EFSYS_PROBE1(fail1, efx_rc_t, rc);
776
777         return (rc);
778 }
779
780 static                  void
781 ef10_nic_alloc_piobufs(
782         __in            efx_nic_t *enp,
783         __in            uint32_t max_piobuf_count)
784 {
785         efx_piobuf_handle_t *handlep;
786         unsigned int i;
787
788         EFSYS_ASSERT3U(max_piobuf_count, <=,
789             EFX_ARRAY_SIZE(enp->en_arch.ef10.ena_piobuf_handle));
790
791         enp->en_arch.ef10.ena_piobuf_count = 0;
792
793         for (i = 0; i < max_piobuf_count; i++) {
794                 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
795
796                 if (efx_mcdi_alloc_piobuf(enp, handlep) != 0)
797                         goto fail1;
798
799                 enp->en_arch.ef10.ena_pio_alloc_map[i] = 0;
800                 enp->en_arch.ef10.ena_piobuf_count++;
801         }
802
803         return;
804
805 fail1:
806         for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
807                 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
808
809                 efx_mcdi_free_piobuf(enp, *handlep);
810                 *handlep = EFX_PIOBUF_HANDLE_INVALID;
811         }
812         enp->en_arch.ef10.ena_piobuf_count = 0;
813 }
814
815
816 static                  void
817 ef10_nic_free_piobufs(
818         __in            efx_nic_t *enp)
819 {
820         efx_piobuf_handle_t *handlep;
821         unsigned int i;
822
823         for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
824                 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
825
826                 efx_mcdi_free_piobuf(enp, *handlep);
827                 *handlep = EFX_PIOBUF_HANDLE_INVALID;
828         }
829         enp->en_arch.ef10.ena_piobuf_count = 0;
830 }
831
832 /* Sub-allocate a block from a piobuf */
833         __checkReturn   efx_rc_t
834 ef10_nic_pio_alloc(
835         __inout         efx_nic_t *enp,
836         __out           uint32_t *bufnump,
837         __out           efx_piobuf_handle_t *handlep,
838         __out           uint32_t *blknump,
839         __out           uint32_t *offsetp,
840         __out           size_t *sizep)
841 {
842         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
843         efx_drv_cfg_t *edcp = &enp->en_drv_cfg;
844         uint32_t blk_per_buf;
845         uint32_t buf, blk;
846         efx_rc_t rc;
847
848         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
849             enp->en_family == EFX_FAMILY_MEDFORD ||
850             enp->en_family == EFX_FAMILY_MEDFORD2);
851         EFSYS_ASSERT(bufnump);
852         EFSYS_ASSERT(handlep);
853         EFSYS_ASSERT(blknump);
854         EFSYS_ASSERT(offsetp);
855         EFSYS_ASSERT(sizep);
856
857         if ((edcp->edc_pio_alloc_size == 0) ||
858             (enp->en_arch.ef10.ena_piobuf_count == 0)) {
859                 rc = ENOMEM;
860                 goto fail1;
861         }
862         blk_per_buf = encp->enc_piobuf_size / edcp->edc_pio_alloc_size;
863
864         for (buf = 0; buf < enp->en_arch.ef10.ena_piobuf_count; buf++) {
865                 uint32_t *map = &enp->en_arch.ef10.ena_pio_alloc_map[buf];
866
867                 if (~(*map) == 0)
868                         continue;
869
870                 EFSYS_ASSERT3U(blk_per_buf, <=, (8 * sizeof (*map)));
871                 for (blk = 0; blk < blk_per_buf; blk++) {
872                         if ((*map & (1u << blk)) == 0) {
873                                 *map |= (1u << blk);
874                                 goto done;
875                         }
876                 }
877         }
878         rc = ENOMEM;
879         goto fail2;
880
881 done:
882         *handlep = enp->en_arch.ef10.ena_piobuf_handle[buf];
883         *bufnump = buf;
884         *blknump = blk;
885         *sizep = edcp->edc_pio_alloc_size;
886         *offsetp = blk * (*sizep);
887
888         return (0);
889
890 fail2:
891         EFSYS_PROBE(fail2);
892 fail1:
893         EFSYS_PROBE1(fail1, efx_rc_t, rc);
894
895         return (rc);
896 }
897
898 /* Free a piobuf sub-allocated block */
899         __checkReturn   efx_rc_t
900 ef10_nic_pio_free(
901         __inout         efx_nic_t *enp,
902         __in            uint32_t bufnum,
903         __in            uint32_t blknum)
904 {
905         uint32_t *map;
906         efx_rc_t rc;
907
908         if ((bufnum >= enp->en_arch.ef10.ena_piobuf_count) ||
909             (blknum >= (8 * sizeof (*map)))) {
910                 rc = EINVAL;
911                 goto fail1;
912         }
913
914         map = &enp->en_arch.ef10.ena_pio_alloc_map[bufnum];
915         if ((*map & (1u << blknum)) == 0) {
916                 rc = ENOENT;
917                 goto fail2;
918         }
919         *map &= ~(1u << blknum);
920
921         return (0);
922
923 fail2:
924         EFSYS_PROBE(fail2);
925 fail1:
926         EFSYS_PROBE1(fail1, efx_rc_t, rc);
927
928         return (rc);
929 }
930
931         __checkReturn   efx_rc_t
932 ef10_nic_pio_link(
933         __inout         efx_nic_t *enp,
934         __in            uint32_t vi_index,
935         __in            efx_piobuf_handle_t handle)
936 {
937         return (efx_mcdi_link_piobuf(enp, vi_index, handle));
938 }
939
940         __checkReturn   efx_rc_t
941 ef10_nic_pio_unlink(
942         __inout         efx_nic_t *enp,
943         __in            uint32_t vi_index)
944 {
945         return (efx_mcdi_unlink_piobuf(enp, vi_index));
946 }
947
948 static  __checkReturn   efx_rc_t
949 ef10_mcdi_get_pf_count(
950         __in            efx_nic_t *enp,
951         __out           uint32_t *pf_countp)
952 {
953         efx_mcdi_req_t req;
954         uint8_t payload[MAX(MC_CMD_GET_PF_COUNT_IN_LEN,
955                             MC_CMD_GET_PF_COUNT_OUT_LEN)];
956         efx_rc_t rc;
957
958         (void) memset(payload, 0, sizeof (payload));
959         req.emr_cmd = MC_CMD_GET_PF_COUNT;
960         req.emr_in_buf = payload;
961         req.emr_in_length = MC_CMD_GET_PF_COUNT_IN_LEN;
962         req.emr_out_buf = payload;
963         req.emr_out_length = MC_CMD_GET_PF_COUNT_OUT_LEN;
964
965         efx_mcdi_execute(enp, &req);
966
967         if (req.emr_rc != 0) {
968                 rc = req.emr_rc;
969                 goto fail1;
970         }
971
972         if (req.emr_out_length_used < MC_CMD_GET_PF_COUNT_OUT_LEN) {
973                 rc = EMSGSIZE;
974                 goto fail2;
975         }
976
977         *pf_countp = *MCDI_OUT(req, uint8_t,
978                                 MC_CMD_GET_PF_COUNT_OUT_PF_COUNT_OFST);
979
980         EFSYS_ASSERT(*pf_countp != 0);
981
982         return (0);
983
984 fail2:
985         EFSYS_PROBE(fail2);
986 fail1:
987         EFSYS_PROBE1(fail1, efx_rc_t, rc);
988
989         return (rc);
990 }
991
992 static  __checkReturn   efx_rc_t
993 ef10_get_datapath_caps(
994         __in            efx_nic_t *enp)
995 {
996         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
997         efx_mcdi_req_t req;
998         uint8_t payload[MAX(MC_CMD_GET_CAPABILITIES_IN_LEN,
999                             MC_CMD_GET_CAPABILITIES_V4_OUT_LEN)];
1000         efx_rc_t rc;
1001
1002         if ((rc = ef10_mcdi_get_pf_count(enp, &encp->enc_hw_pf_count)) != 0)
1003                 goto fail1;
1004
1005
1006         (void) memset(payload, 0, sizeof (payload));
1007         req.emr_cmd = MC_CMD_GET_CAPABILITIES;
1008         req.emr_in_buf = payload;
1009         req.emr_in_length = MC_CMD_GET_CAPABILITIES_IN_LEN;
1010         req.emr_out_buf = payload;
1011         req.emr_out_length = MC_CMD_GET_CAPABILITIES_V4_OUT_LEN;
1012
1013         efx_mcdi_execute_quiet(enp, &req);
1014
1015         if (req.emr_rc != 0) {
1016                 rc = req.emr_rc;
1017                 goto fail2;
1018         }
1019
1020         if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
1021                 rc = EMSGSIZE;
1022                 goto fail3;
1023         }
1024
1025 #define CAP_FLAGS1(_req, _flag)                                         \
1026         (MCDI_OUT_DWORD((_req), GET_CAPABILITIES_OUT_FLAGS1) &          \
1027         (1u << (MC_CMD_GET_CAPABILITIES_V2_OUT_ ## _flag ## _LBN)))
1028
1029 #define CAP_FLAGS2(_req, _flag)                                         \
1030         (((_req).emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) && \
1031             (MCDI_OUT_DWORD((_req), GET_CAPABILITIES_V2_OUT_FLAGS2) &   \
1032             (1u << (MC_CMD_GET_CAPABILITIES_V2_OUT_ ## _flag ## _LBN))))
1033
1034         /*
1035          * Huntington RXDP firmware inserts a 0 or 14 byte prefix.
1036          * We only support the 14 byte prefix here.
1037          */
1038         if (CAP_FLAGS1(req, RX_PREFIX_LEN_14) == 0) {
1039                 rc = ENOTSUP;
1040                 goto fail4;
1041         }
1042         encp->enc_rx_prefix_size = 14;
1043
1044         /* Check if the firmware supports additional RSS modes */
1045         if (CAP_FLAGS1(req, ADDITIONAL_RSS_MODES))
1046                 encp->enc_rx_scale_additional_modes_supported = B_TRUE;
1047         else
1048                 encp->enc_rx_scale_additional_modes_supported = B_FALSE;
1049
1050         /* Check if the firmware supports TSO */
1051         if (CAP_FLAGS1(req, TX_TSO))
1052                 encp->enc_fw_assisted_tso_enabled = B_TRUE;
1053         else
1054                 encp->enc_fw_assisted_tso_enabled = B_FALSE;
1055
1056         /* Check if the firmware supports FATSOv2 */
1057         if (CAP_FLAGS2(req, TX_TSO_V2)) {
1058                 encp->enc_fw_assisted_tso_v2_enabled = B_TRUE;
1059                 encp->enc_fw_assisted_tso_v2_n_contexts = MCDI_OUT_WORD(req,
1060                     GET_CAPABILITIES_V2_OUT_TX_TSO_V2_N_CONTEXTS);
1061         } else {
1062                 encp->enc_fw_assisted_tso_v2_enabled = B_FALSE;
1063                 encp->enc_fw_assisted_tso_v2_n_contexts = 0;
1064         }
1065
1066         /* Check if the firmware supports FATSOv2 encap */
1067         if (CAP_FLAGS2(req, TX_TSO_V2_ENCAP))
1068                 encp->enc_fw_assisted_tso_v2_encap_enabled = B_TRUE;
1069         else
1070                 encp->enc_fw_assisted_tso_v2_encap_enabled = B_FALSE;
1071
1072         /* Check if the firmware has vadapter/vport/vswitch support */
1073         if (CAP_FLAGS1(req, EVB))
1074                 encp->enc_datapath_cap_evb = B_TRUE;
1075         else
1076                 encp->enc_datapath_cap_evb = B_FALSE;
1077
1078         /* Check if the firmware supports VLAN insertion */
1079         if (CAP_FLAGS1(req, TX_VLAN_INSERTION))
1080                 encp->enc_hw_tx_insert_vlan_enabled = B_TRUE;
1081         else
1082                 encp->enc_hw_tx_insert_vlan_enabled = B_FALSE;
1083
1084         /* Check if the firmware supports RX event batching */
1085         if (CAP_FLAGS1(req, RX_BATCHING))
1086                 encp->enc_rx_batching_enabled = B_TRUE;
1087         else
1088                 encp->enc_rx_batching_enabled = B_FALSE;
1089
1090         /*
1091          * Even if batching isn't reported as supported, we may still get
1092          * batched events (see bug61153).
1093          */
1094         encp->enc_rx_batch_max = 16;
1095
1096         /* Check if the firmware supports disabling scatter on RXQs */
1097         if (CAP_FLAGS1(req, RX_DISABLE_SCATTER))
1098                 encp->enc_rx_disable_scatter_supported = B_TRUE;
1099         else
1100                 encp->enc_rx_disable_scatter_supported = B_FALSE;
1101
1102         /* Check if the firmware supports packed stream mode */
1103         if (CAP_FLAGS1(req, RX_PACKED_STREAM))
1104                 encp->enc_rx_packed_stream_supported = B_TRUE;
1105         else
1106                 encp->enc_rx_packed_stream_supported = B_FALSE;
1107
1108         /*
1109          * Check if the firmware supports configurable buffer sizes
1110          * for packed stream mode (otherwise buffer size is 1Mbyte)
1111          */
1112         if (CAP_FLAGS1(req, RX_PACKED_STREAM_VAR_BUFFERS))
1113                 encp->enc_rx_var_packed_stream_supported = B_TRUE;
1114         else
1115                 encp->enc_rx_var_packed_stream_supported = B_FALSE;
1116
1117         /* Check if the firmware supports equal stride super-buffer mode */
1118         if (CAP_FLAGS2(req, EQUAL_STRIDE_SUPER_BUFFER))
1119                 encp->enc_rx_es_super_buffer_supported = B_TRUE;
1120         else
1121                 encp->enc_rx_es_super_buffer_supported = B_FALSE;
1122
1123         /* Check if the firmware supports FW subvariant w/o Tx checksumming */
1124         if (CAP_FLAGS2(req, FW_SUBVARIANT_NO_TX_CSUM))
1125                 encp->enc_fw_subvariant_no_tx_csum_supported = B_TRUE;
1126         else
1127                 encp->enc_fw_subvariant_no_tx_csum_supported = B_FALSE;
1128
1129         /* Check if the firmware supports set mac with running filters */
1130         if (CAP_FLAGS1(req, VADAPTOR_PERMIT_SET_MAC_WHEN_FILTERS_INSTALLED))
1131                 encp->enc_allow_set_mac_with_installed_filters = B_TRUE;
1132         else
1133                 encp->enc_allow_set_mac_with_installed_filters = B_FALSE;
1134
1135         /*
1136          * Check if firmware supports the extended MC_CMD_SET_MAC, which allows
1137          * specifying which parameters to configure.
1138          */
1139         if (CAP_FLAGS1(req, SET_MAC_ENHANCED))
1140                 encp->enc_enhanced_set_mac_supported = B_TRUE;
1141         else
1142                 encp->enc_enhanced_set_mac_supported = B_FALSE;
1143
1144         /*
1145          * Check if firmware supports version 2 of MC_CMD_INIT_EVQ, which allows
1146          * us to let the firmware choose the settings to use on an EVQ.
1147          */
1148         if (CAP_FLAGS2(req, INIT_EVQ_V2))
1149                 encp->enc_init_evq_v2_supported = B_TRUE;
1150         else
1151                 encp->enc_init_evq_v2_supported = B_FALSE;
1152
1153         /*
1154          * Check if firmware-verified NVRAM updates must be used.
1155          *
1156          * The firmware trusted installer requires all NVRAM updates to use
1157          * version 2 of MC_CMD_NVRAM_UPDATE_START (to enable verified update)
1158          * and version 2 of MC_CMD_NVRAM_UPDATE_FINISH (to verify the updated
1159          * partition and report the result).
1160          */
1161         if (CAP_FLAGS2(req, NVRAM_UPDATE_REPORT_VERIFY_RESULT))
1162                 encp->enc_nvram_update_verify_result_supported = B_TRUE;
1163         else
1164                 encp->enc_nvram_update_verify_result_supported = B_FALSE;
1165
1166         /*
1167          * Check if firmware provides packet memory and Rx datapath
1168          * counters.
1169          */
1170         if (CAP_FLAGS1(req, PM_AND_RXDP_COUNTERS))
1171                 encp->enc_pm_and_rxdp_counters = B_TRUE;
1172         else
1173                 encp->enc_pm_and_rxdp_counters = B_FALSE;
1174
1175         /*
1176          * Check if the 40G MAC hardware is capable of reporting
1177          * statistics for Tx size bins.
1178          */
1179         if (CAP_FLAGS2(req, MAC_STATS_40G_TX_SIZE_BINS))
1180                 encp->enc_mac_stats_40g_tx_size_bins = B_TRUE;
1181         else
1182                 encp->enc_mac_stats_40g_tx_size_bins = B_FALSE;
1183
1184         /*
1185          * Check if firmware supports VXLAN and NVGRE tunnels.
1186          * The capability indicates Geneve protocol support as well.
1187          */
1188         if (CAP_FLAGS1(req, VXLAN_NVGRE)) {
1189                 encp->enc_tunnel_encapsulations_supported =
1190                     (1u << EFX_TUNNEL_PROTOCOL_VXLAN) |
1191                     (1u << EFX_TUNNEL_PROTOCOL_GENEVE) |
1192                     (1u << EFX_TUNNEL_PROTOCOL_NVGRE);
1193
1194                 EFX_STATIC_ASSERT(EFX_TUNNEL_MAXNENTRIES ==
1195                     MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
1196                 encp->enc_tunnel_config_udp_entries_max =
1197                     EFX_TUNNEL_MAXNENTRIES;
1198         } else {
1199                 encp->enc_tunnel_config_udp_entries_max = 0;
1200         }
1201
1202         /*
1203          * Check if firmware reports the VI window mode.
1204          * Medford2 has a variable VI window size (8K, 16K or 64K).
1205          * Medford and Huntington have a fixed 8K VI window size.
1206          */
1207         if (req.emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
1208                 uint8_t mode =
1209                     MCDI_OUT_BYTE(req, GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
1210
1211                 switch (mode) {
1212                 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
1213                         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
1214                         break;
1215                 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
1216                         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_16K;
1217                         break;
1218                 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
1219                         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_64K;
1220                         break;
1221                 default:
1222                         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_INVALID;
1223                         break;
1224                 }
1225         } else if ((enp->en_family == EFX_FAMILY_HUNTINGTON) ||
1226                     (enp->en_family == EFX_FAMILY_MEDFORD)) {
1227                 /* Huntington and Medford have fixed 8K window size */
1228                 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
1229         } else {
1230                 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_INVALID;
1231         }
1232
1233         /* Check if firmware supports extended MAC stats. */
1234         if (req.emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
1235                 /* Extended stats buffer supported */
1236                 encp->enc_mac_stats_nstats = MCDI_OUT_WORD(req,
1237                     GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
1238         } else {
1239                 /* Use Siena-compatible legacy MAC stats */
1240                 encp->enc_mac_stats_nstats = MC_CMD_MAC_NSTATS;
1241         }
1242
1243         if (encp->enc_mac_stats_nstats >= MC_CMD_MAC_NSTATS_V2)
1244                 encp->enc_fec_counters = B_TRUE;
1245         else
1246                 encp->enc_fec_counters = B_FALSE;
1247
1248         if (CAP_FLAGS1(req, RX_RSS_LIMITED)) {
1249                 /* Only one exclusive RSS context is available per port. */
1250                 encp->enc_rx_scale_max_exclusive_contexts = 1;
1251
1252                 switch (enp->en_family) {
1253                 case EFX_FAMILY_MEDFORD2:
1254                         encp->enc_rx_scale_hash_alg_mask =
1255                             (1U << EFX_RX_HASHALG_TOEPLITZ);
1256                         break;
1257
1258                 case EFX_FAMILY_MEDFORD:
1259                 case EFX_FAMILY_HUNTINGTON:
1260                         /*
1261                          * Packed stream firmware variant maintains a
1262                          * non-standard algorithm for hash computation.
1263                          * It implies explicit XORing together
1264                          * source + destination IP addresses (or last
1265                          * four bytes in the case of IPv6) and using the
1266                          * resulting value as the input to a Toeplitz hash.
1267                          */
1268                         encp->enc_rx_scale_hash_alg_mask =
1269                             (1U << EFX_RX_HASHALG_PACKED_STREAM);
1270                         break;
1271
1272                 default:
1273                         rc = EINVAL;
1274                         goto fail5;
1275                 }
1276
1277                 /* Port numbers cannot contribute to the hash value */
1278                 encp->enc_rx_scale_l4_hash_supported = B_FALSE;
1279         } else {
1280                 /*
1281                  * Maximum number of exclusive RSS contexts.
1282                  * EF10 hardware supports 64 in total, but 6 are reserved
1283                  * for shared contexts. They are a global resource so
1284                  * not all may be available.
1285                  */
1286                 encp->enc_rx_scale_max_exclusive_contexts = 64 - 6;
1287
1288                 encp->enc_rx_scale_hash_alg_mask =
1289                     (1U << EFX_RX_HASHALG_TOEPLITZ);
1290
1291                 /*
1292                  * It is possible to use port numbers as
1293                  * the input data for hash computation.
1294                  */
1295                 encp->enc_rx_scale_l4_hash_supported = B_TRUE;
1296         }
1297         /* Check if the firmware supports "FLAG" and "MARK" filter actions */
1298         if (CAP_FLAGS2(req, FILTER_ACTION_FLAG))
1299                 encp->enc_filter_action_flag_supported = B_TRUE;
1300         else
1301                 encp->enc_filter_action_flag_supported = B_FALSE;
1302
1303         if (CAP_FLAGS2(req, FILTER_ACTION_MARK))
1304                 encp->enc_filter_action_mark_supported = B_TRUE;
1305         else
1306                 encp->enc_filter_action_mark_supported = B_FALSE;
1307
1308 #undef CAP_FLAGS1
1309 #undef CAP_FLAGS2
1310
1311         return (0);
1312
1313 fail5:
1314         EFSYS_PROBE(fail5);
1315 fail4:
1316         EFSYS_PROBE(fail4);
1317 fail3:
1318         EFSYS_PROBE(fail3);
1319 fail2:
1320         EFSYS_PROBE(fail2);
1321 fail1:
1322         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1323
1324         return (rc);
1325 }
1326
1327
1328 #define EF10_LEGACY_PF_PRIVILEGE_MASK                                   \
1329         (MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN                     |       \
1330         MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK                       |       \
1331         MC_CMD_PRIVILEGE_MASK_IN_GRP_ONLOAD                     |       \
1332         MC_CMD_PRIVILEGE_MASK_IN_GRP_PTP                        |       \
1333         MC_CMD_PRIVILEGE_MASK_IN_GRP_INSECURE_FILTERS           |       \
1334         MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING               |       \
1335         MC_CMD_PRIVILEGE_MASK_IN_GRP_UNICAST                    |       \
1336         MC_CMD_PRIVILEGE_MASK_IN_GRP_MULTICAST                  |       \
1337         MC_CMD_PRIVILEGE_MASK_IN_GRP_BROADCAST                  |       \
1338         MC_CMD_PRIVILEGE_MASK_IN_GRP_ALL_MULTICAST              |       \
1339         MC_CMD_PRIVILEGE_MASK_IN_GRP_PROMISCUOUS)
1340
1341 #define EF10_LEGACY_VF_PRIVILEGE_MASK   0
1342
1343
1344         __checkReturn           efx_rc_t
1345 ef10_get_privilege_mask(
1346         __in                    efx_nic_t *enp,
1347         __out                   uint32_t *maskp)
1348 {
1349         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1350         uint32_t mask;
1351         efx_rc_t rc;
1352
1353         if ((rc = efx_mcdi_privilege_mask(enp, encp->enc_pf, encp->enc_vf,
1354                                             &mask)) != 0) {
1355                 if (rc != ENOTSUP)
1356                         goto fail1;
1357
1358                 /* Fallback for old firmware without privilege mask support */
1359                 if (EFX_PCI_FUNCTION_IS_PF(encp)) {
1360                         /* Assume PF has admin privilege */
1361                         mask = EF10_LEGACY_PF_PRIVILEGE_MASK;
1362                 } else {
1363                         /* VF is always unprivileged by default */
1364                         mask = EF10_LEGACY_VF_PRIVILEGE_MASK;
1365                 }
1366         }
1367
1368         *maskp = mask;
1369
1370         return (0);
1371
1372 fail1:
1373         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1374
1375         return (rc);
1376 }
1377
1378
1379 /*
1380  * Table of mapping schemes from port number to external number.
1381  *
1382  * Each port number ultimately corresponds to a connector: either as part of
1383  * a cable assembly attached to a module inserted in an SFP+/QSFP+ cage on
1384  * the board, or fixed to the board (e.g. 10GBASE-T magjack on SFN5121T
1385  * "Salina"). In general:
1386  *
1387  * Port number (0-based)
1388  *     |
1389  *   port mapping (n:1)
1390  *     |
1391  *     v
1392  * External port number (normally 1-based)
1393  *     |
1394  *   fixed (1:1) or cable assembly (1:m)
1395  *     |
1396  *     v
1397  * Connector
1398  *
1399  * The external numbering refers to the cages or magjacks on the board,
1400  * as visibly annotated on the board or back panel. This table describes
1401  * how to determine which external cage/magjack corresponds to the port
1402  * numbers used by the driver.
1403  *
1404  * The count of adjacent port numbers that map to each external number,
1405  * and the offset in the numbering, is determined by the chip family and
1406  * current port mode.
1407  *
1408  * For the Huntington family, the current port mode cannot be discovered,
1409  * but a single mapping is used by all modes for a given chip variant,
1410  * so the mapping used is instead the last match in the table to the full
1411  * set of port modes to which the NIC can be configured. Therefore the
1412  * ordering of entries in the mapping table is significant.
1413  */
1414 static struct ef10_external_port_map_s {
1415         efx_family_t    family;
1416         uint32_t        modes_mask;
1417         int32_t         count;
1418         int32_t         offset;
1419 }       __ef10_external_port_mappings[] = {
1420         /*
1421          * Modes used by Huntington family controllers where each port
1422          * number maps to a separate cage.
1423          * SFN7x22F (Torino):
1424          *      port 0 -> cage 1
1425          *      port 1 -> cage 2
1426          * SFN7xx4F (Pavia):
1427          *      port 0 -> cage 1
1428          *      port 1 -> cage 2
1429          *      port 2 -> cage 3
1430          *      port 3 -> cage 4
1431          */
1432         {
1433                 EFX_FAMILY_HUNTINGTON,
1434                 (1U << TLV_PORT_MODE_10G) |                     /* mode 0 */
1435                 (1U << TLV_PORT_MODE_10G_10G) |                 /* mode 2 */
1436                 (1U << TLV_PORT_MODE_10G_10G_10G_10G),          /* mode 4 */
1437                 1,      /* ports per cage */
1438                 1       /* first cage */
1439         },
1440         /*
1441          * Modes which for Huntington identify a chip variant where 2
1442          * adjacent port numbers map to each cage.
1443          * SFN7x42Q (Monza):
1444          *      port 0 -> cage 1
1445          *      port 1 -> cage 1
1446          *      port 2 -> cage 2
1447          *      port 3 -> cage 2
1448          */
1449         {
1450                 EFX_FAMILY_HUNTINGTON,
1451                 (1U << TLV_PORT_MODE_40G) |                     /* mode 1 */
1452                 (1U << TLV_PORT_MODE_40G_40G) |                 /* mode 3 */
1453                 (1U << TLV_PORT_MODE_40G_10G_10G) |             /* mode 6 */
1454                 (1U << TLV_PORT_MODE_10G_10G_40G),              /* mode 7 */
1455                 2,      /* ports per cage */
1456                 1       /* first cage */
1457         },
1458         /*
1459          * Modes that on Medford allocate each port number to a separate
1460          * cage.
1461          *      port 0 -> cage 1
1462          *      port 1 -> cage 2
1463          *      port 2 -> cage 3
1464          *      port 3 -> cage 4
1465          */
1466         {
1467                 EFX_FAMILY_MEDFORD,
1468                 (1U << TLV_PORT_MODE_10G) |                     /* mode 0 */
1469                 (1U << TLV_PORT_MODE_10G_10G),                  /* mode 2 */
1470                 1,      /* ports per cage */
1471                 1       /* first cage */
1472         },
1473         /*
1474          * Modes that on Medford allocate 2 adjacent port numbers to each
1475          * cage.
1476          *      port 0 -> cage 1
1477          *      port 1 -> cage 1
1478          *      port 2 -> cage 2
1479          *      port 3 -> cage 2
1480          */
1481         {
1482                 EFX_FAMILY_MEDFORD,
1483                 (1U << TLV_PORT_MODE_40G) |                     /* mode 1 */
1484                 (1U << TLV_PORT_MODE_40G_40G) |                 /* mode 3 */
1485                 (1U << TLV_PORT_MODE_40G_10G_10G) |             /* mode 6 */
1486                 (1U << TLV_PORT_MODE_10G_10G_40G) |             /* mode 7 */
1487                 /* Do not use 10G_10G_10G_10G_Q1_Q2 (see bug63270) */
1488                 (1U << TLV_PORT_MODE_10G_10G_10G_10G_Q1_Q2),    /* mode 9 */
1489                 2,      /* ports per cage */
1490                 1       /* first cage */
1491         },
1492         /*
1493          * Modes that on Medford allocate 4 adjacent port numbers to each
1494          * connector, starting on cage 1.
1495          *      port 0 -> cage 1
1496          *      port 1 -> cage 1
1497          *      port 2 -> cage 1
1498          *      port 3 -> cage 1
1499          */
1500         {
1501                 EFX_FAMILY_MEDFORD,
1502                 (1U << TLV_PORT_MODE_10G_10G_10G_10G_Q) |       /* mode 5 */
1503                 /* Do not use 10G_10G_10G_10G_Q1 (see bug63270) */
1504                 (1U << TLV_PORT_MODE_10G_10G_10G_10G_Q1),       /* mode 4 */
1505                 4,      /* ports per cage */
1506                 1       /* first cage */
1507         },
1508         /*
1509          * Modes that on Medford allocate 4 adjacent port numbers to each
1510          * connector, starting on cage 2.
1511          *      port 0 -> cage 2
1512          *      port 1 -> cage 2
1513          *      port 2 -> cage 2
1514          *      port 3 -> cage 2
1515          */
1516         {
1517                 EFX_FAMILY_MEDFORD,
1518                 (1U << TLV_PORT_MODE_10G_10G_10G_10G_Q2),       /* mode 8 */
1519                 4,      /* ports per cage */
1520                 2       /* first cage */
1521         },
1522         /*
1523          * Modes that on Medford2 allocate each port number to a separate
1524          * cage.
1525          *      port 0 -> cage 1
1526          *      port 1 -> cage 2
1527          *      port 2 -> cage 3
1528          *      port 3 -> cage 4
1529          */
1530         {
1531                 EFX_FAMILY_MEDFORD2,
1532                 (1U << TLV_PORT_MODE_1x1_NA) |                  /* mode 0 */
1533                 (1U << TLV_PORT_MODE_1x4_NA) |                  /* mode 1 */
1534                 (1U << TLV_PORT_MODE_1x1_1x1) |                 /* mode 2 */
1535                 (1U << TLV_PORT_MODE_1x2_NA) |                  /* mode 10 */
1536                 (1U << TLV_PORT_MODE_1x2_1x2) |                 /* mode 12 */
1537                 (1U << TLV_PORT_MODE_1x4_1x2) |                 /* mode 15 */
1538                 (1U << TLV_PORT_MODE_1x2_1x4),                  /* mode 16 */
1539                 1,      /* ports per cage */
1540                 1       /* first cage */
1541         },
1542         /*
1543          * FIXME: Some port modes are not representable in this mapping:
1544          *  - TLV_PORT_MODE_1x2_2x1 (mode 17):
1545          *      port 0 -> cage 1
1546          *      port 1 -> cage 2
1547          *      port 2 -> cage 2
1548          */
1549         /*
1550          * Modes that on Medford2 allocate 2 adjacent port numbers to each
1551          * cage, starting on cage 1.
1552          *      port 0 -> cage 1
1553          *      port 1 -> cage 1
1554          *      port 2 -> cage 2
1555          *      port 3 -> cage 2
1556          */
1557         {
1558                 EFX_FAMILY_MEDFORD2,
1559                 (1U << TLV_PORT_MODE_1x4_1x4) |                 /* mode 3 */
1560                 (1U << TLV_PORT_MODE_2x1_2x1) |                 /* mode 4 */
1561                 (1U << TLV_PORT_MODE_1x4_2x1) |                 /* mode 6 */
1562                 (1U << TLV_PORT_MODE_2x1_1x4) |                 /* mode 7 */
1563                 (1U << TLV_PORT_MODE_2x2_NA) |                  /* mode 13 */
1564                 (1U << TLV_PORT_MODE_2x1_1x2),                  /* mode 18 */
1565                 2,      /* ports per cage */
1566                 1       /* first cage */
1567         },
1568         /*
1569          * Modes that on Medford2 allocate 2 adjacent port numbers to each
1570          * cage, starting on cage 2.
1571          *      port 0 -> cage 2
1572          *      port 1 -> cage 2
1573          */
1574         {
1575                 EFX_FAMILY_MEDFORD2,
1576                 (1U << TLV_PORT_MODE_NA_2x2),                   /* mode 14 */
1577                 2,      /* ports per cage */
1578                 2       /* first cage */
1579         },
1580         /*
1581          * Modes that on Medford2 allocate 4 adjacent port numbers to each
1582          * connector, starting on cage 1.
1583          *      port 0 -> cage 1
1584          *      port 1 -> cage 1
1585          *      port 2 -> cage 1
1586          *      port 3 -> cage 1
1587          */
1588         {
1589                 EFX_FAMILY_MEDFORD2,
1590                 (1U << TLV_PORT_MODE_4x1_NA),                   /* mode 5 */
1591                 4,      /* ports per cage */
1592                 1       /* first cage */
1593         },
1594         /*
1595          * Modes that on Medford2 allocate 4 adjacent port numbers to each
1596          * connector, starting on cage 2.
1597          *      port 0 -> cage 2
1598          *      port 1 -> cage 2
1599          *      port 2 -> cage 2
1600          *      port 3 -> cage 2
1601          */
1602         {
1603                 EFX_FAMILY_MEDFORD2,
1604                 (1U << TLV_PORT_MODE_NA_4x1) |                  /* mode 8 */
1605                 (1U << TLV_PORT_MODE_NA_1x2),                   /* mode 11 */
1606                 4,      /* ports per cage */
1607                 2       /* first cage */
1608         },
1609 };
1610
1611 static  __checkReturn   efx_rc_t
1612 ef10_external_port_mapping(
1613         __in            efx_nic_t *enp,
1614         __in            uint32_t port,
1615         __out           uint8_t *external_portp)
1616 {
1617         efx_rc_t rc;
1618         int i;
1619         uint32_t port_modes;
1620         uint32_t matches;
1621         uint32_t current;
1622         int32_t count = 1; /* Default 1-1 mapping */
1623         int32_t offset = 1; /* Default starting external port number */
1624
1625         if ((rc = efx_mcdi_get_port_modes(enp, &port_modes, &current)) != 0) {
1626                 /*
1627                  * No current port mode information (i.e. Huntington)
1628                  * - infer mapping from available modes
1629                  */
1630                 if ((rc = efx_mcdi_get_port_modes(enp,
1631                             &port_modes, NULL)) != 0) {
1632                         /*
1633                          * No port mode information available
1634                          * - use default mapping
1635                          */
1636                         goto out;
1637                 }
1638         } else {
1639                 /* Only need to scan the current mode */
1640                 port_modes = 1 << current;
1641         }
1642
1643         /*
1644          * Infer the internal port -> external number mapping from
1645          * the possible port modes for this NIC.
1646          */
1647         for (i = 0; i < EFX_ARRAY_SIZE(__ef10_external_port_mappings); ++i) {
1648                 struct ef10_external_port_map_s *eepmp =
1649                     &__ef10_external_port_mappings[i];
1650                 if (eepmp->family != enp->en_family)
1651                         continue;
1652                 matches = (eepmp->modes_mask & port_modes);
1653                 if (matches != 0) {
1654                         /*
1655                          * Some modes match. For some Huntington boards
1656                          * there will be multiple matches. The mapping on the
1657                          * last match is used.
1658                          */
1659                         count = eepmp->count;
1660                         offset = eepmp->offset;
1661                         port_modes &= ~matches;
1662                 }
1663         }
1664
1665         if (port_modes != 0) {
1666                 /* Some advertised modes are not supported */
1667                 rc = ENOTSUP;
1668                 goto fail1;
1669         }
1670
1671 out:
1672         /*
1673          * Scale as required by last matched mode and then convert to
1674          * correctly offset numbering
1675          */
1676         *external_portp = (uint8_t)((port / count) + offset);
1677         return (0);
1678
1679 fail1:
1680         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1681
1682         return (rc);
1683 }
1684
1685 static  __checkReturn   efx_rc_t
1686 ef10_nic_board_cfg(
1687         __in            efx_nic_t *enp)
1688 {
1689         const efx_nic_ops_t *enop = enp->en_enop;
1690         efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
1691         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1692         ef10_link_state_t els;
1693         efx_port_t *epp = &(enp->en_port);
1694         uint32_t board_type = 0;
1695         uint32_t base, nvec;
1696         uint32_t port;
1697         uint32_t mask;
1698         uint32_t pf;
1699         uint32_t vf;
1700         uint8_t mac_addr[6] = { 0 };
1701         efx_rc_t rc;
1702
1703         /* Get the (zero-based) MCDI port number */
1704         if ((rc = efx_mcdi_get_port_assignment(enp, &port)) != 0)
1705                 goto fail1;
1706
1707         /* EFX MCDI interface uses one-based port numbers */
1708         emip->emi_port = port + 1;
1709
1710         if ((rc = ef10_external_port_mapping(enp, port,
1711                     &encp->enc_external_port)) != 0)
1712                 goto fail2;
1713
1714         /*
1715          * Get PCIe function number from firmware (used for
1716          * per-function privilege and dynamic config info).
1717          *  - PCIe PF: pf = PF number, vf = 0xffff.
1718          *  - PCIe VF: pf = parent PF, vf = VF number.
1719          */
1720         if ((rc = efx_mcdi_get_function_info(enp, &pf, &vf)) != 0)
1721                 goto fail3;
1722
1723         encp->enc_pf = pf;
1724         encp->enc_vf = vf;
1725
1726         /* MAC address for this function */
1727         if (EFX_PCI_FUNCTION_IS_PF(encp)) {
1728                 rc = efx_mcdi_get_mac_address_pf(enp, mac_addr);
1729 #if EFSYS_OPT_ALLOW_UNCONFIGURED_NIC
1730                 /*
1731                  * Disable static config checking, ONLY for manufacturing test
1732                  * and setup at the factory, to allow the static config to be
1733                  * installed.
1734                  */
1735 #else /* EFSYS_OPT_ALLOW_UNCONFIGURED_NIC */
1736                 if ((rc == 0) && (mac_addr[0] & 0x02)) {
1737                         /*
1738                          * If the static config does not include a global MAC
1739                          * address pool then the board may return a locally
1740                          * administered MAC address (this should only happen on
1741                          * incorrectly programmed boards).
1742                          */
1743                         rc = EINVAL;
1744                 }
1745 #endif /* EFSYS_OPT_ALLOW_UNCONFIGURED_NIC */
1746         } else {
1747                 rc = efx_mcdi_get_mac_address_vf(enp, mac_addr);
1748         }
1749         if (rc != 0)
1750                 goto fail4;
1751
1752         EFX_MAC_ADDR_COPY(encp->enc_mac_addr, mac_addr);
1753
1754         /* Board configuration (legacy) */
1755         rc = efx_mcdi_get_board_cfg(enp, &board_type, NULL, NULL);
1756         if (rc != 0) {
1757                 /* Unprivileged functions may not be able to read board cfg */
1758                 if (rc == EACCES)
1759                         board_type = 0;
1760                 else
1761                         goto fail5;
1762         }
1763
1764         encp->enc_board_type = board_type;
1765         encp->enc_clk_mult = 1; /* not used for EF10 */
1766
1767         /* Fill out fields in enp->en_port and enp->en_nic_cfg from MCDI */
1768         if ((rc = efx_mcdi_get_phy_cfg(enp)) != 0)
1769                 goto fail6;
1770
1771         /* Obtain the default PHY advertised capabilities */
1772         if ((rc = ef10_phy_get_link(enp, &els)) != 0)
1773                 goto fail7;
1774         epp->ep_default_adv_cap_mask = els.els_adv_cap_mask;
1775         epp->ep_adv_cap_mask = els.els_adv_cap_mask;
1776
1777         /* Check capabilities of running datapath firmware */
1778         if ((rc = ef10_get_datapath_caps(enp)) != 0)
1779                 goto fail8;
1780
1781         /* Alignment for WPTR updates */
1782         encp->enc_rx_push_align = EF10_RX_WPTR_ALIGN;
1783
1784         encp->enc_tx_dma_desc_size_max = EFX_MASK32(ESF_DZ_RX_KER_BYTE_CNT);
1785         /* No boundary crossing limits */
1786         encp->enc_tx_dma_desc_boundary = 0;
1787
1788         /*
1789          * Maximum number of bytes into the frame the TCP header can start for
1790          * firmware assisted TSO to work.
1791          */
1792         encp->enc_tx_tso_tcp_header_offset_limit = EF10_TCP_HEADER_OFFSET_LIMIT;
1793
1794         /*
1795          * Set resource limits for MC_CMD_ALLOC_VIS. Note that we cannot use
1796          * MC_CMD_GET_RESOURCE_LIMITS here as that reports the available
1797          * resources (allocated to this PCIe function), which is zero until
1798          * after we have allocated VIs.
1799          */
1800         encp->enc_evq_limit = 1024;
1801         encp->enc_rxq_limit = EFX_RXQ_LIMIT_TARGET;
1802         encp->enc_txq_limit = EFX_TXQ_LIMIT_TARGET;
1803
1804         encp->enc_buftbl_limit = 0xFFFFFFFF;
1805
1806         /* Get interrupt vector limits */
1807         if ((rc = efx_mcdi_get_vector_cfg(enp, &base, &nvec, NULL)) != 0) {
1808                 if (EFX_PCI_FUNCTION_IS_PF(encp))
1809                         goto fail9;
1810
1811                 /* Ignore error (cannot query vector limits from a VF). */
1812                 base = 0;
1813                 nvec = 1024;
1814         }
1815         encp->enc_intr_vec_base = base;
1816         encp->enc_intr_limit = nvec;
1817
1818         /*
1819          * Get the current privilege mask. Note that this may be modified
1820          * dynamically, so this value is informational only. DO NOT use
1821          * the privilege mask to check for sufficient privileges, as that
1822          * can result in time-of-check/time-of-use bugs.
1823          */
1824         if ((rc = ef10_get_privilege_mask(enp, &mask)) != 0)
1825                 goto fail10;
1826         encp->enc_privilege_mask = mask;
1827
1828         /* Get remaining controller-specific board config */
1829         if ((rc = enop->eno_board_cfg(enp)) != 0)
1830                 if (rc != EACCES)
1831                         goto fail11;
1832
1833         return (0);
1834
1835 fail11:
1836         EFSYS_PROBE(fail11);
1837 fail10:
1838         EFSYS_PROBE(fail10);
1839 fail9:
1840         EFSYS_PROBE(fail9);
1841 fail8:
1842         EFSYS_PROBE(fail8);
1843 fail7:
1844         EFSYS_PROBE(fail7);
1845 fail6:
1846         EFSYS_PROBE(fail6);
1847 fail5:
1848         EFSYS_PROBE(fail5);
1849 fail4:
1850         EFSYS_PROBE(fail4);
1851 fail3:
1852         EFSYS_PROBE(fail3);
1853 fail2:
1854         EFSYS_PROBE(fail2);
1855 fail1:
1856         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1857
1858         return (rc);
1859 }
1860
1861         __checkReturn   efx_rc_t
1862 ef10_nic_probe(
1863         __in            efx_nic_t *enp)
1864 {
1865         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1866         efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
1867         efx_rc_t rc;
1868
1869         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
1870             enp->en_family == EFX_FAMILY_MEDFORD ||
1871             enp->en_family == EFX_FAMILY_MEDFORD2);
1872
1873         /* Read and clear any assertion state */
1874         if ((rc = efx_mcdi_read_assertion(enp)) != 0)
1875                 goto fail1;
1876
1877         /* Exit the assertion handler */
1878         if ((rc = efx_mcdi_exit_assertion_handler(enp)) != 0)
1879                 if (rc != EACCES)
1880                         goto fail2;
1881
1882         if ((rc = efx_mcdi_drv_attach(enp, B_TRUE)) != 0)
1883                 goto fail3;
1884
1885         if ((rc = ef10_nic_board_cfg(enp)) != 0)
1886                 goto fail4;
1887
1888         /*
1889          * Set default driver config limits (based on board config).
1890          *
1891          * FIXME: For now allocate a fixed number of VIs which is likely to be
1892          * sufficient and small enough to allow multiple functions on the same
1893          * port.
1894          */
1895         edcp->edc_min_vi_count = edcp->edc_max_vi_count =
1896             MIN(128, MAX(encp->enc_rxq_limit, encp->enc_txq_limit));
1897
1898         /* The client driver must configure and enable PIO buffer support */
1899         edcp->edc_max_piobuf_count = 0;
1900         edcp->edc_pio_alloc_size = 0;
1901
1902 #if EFSYS_OPT_MAC_STATS
1903         /* Wipe the MAC statistics */
1904         if ((rc = efx_mcdi_mac_stats_clear(enp)) != 0)
1905                 goto fail5;
1906 #endif
1907
1908 #if EFSYS_OPT_LOOPBACK
1909         if ((rc = efx_mcdi_get_loopback_modes(enp)) != 0)
1910                 goto fail6;
1911 #endif
1912
1913 #if EFSYS_OPT_MON_STATS
1914         if ((rc = mcdi_mon_cfg_build(enp)) != 0) {
1915                 /* Unprivileged functions do not have access to sensors */
1916                 if (rc != EACCES)
1917                         goto fail7;
1918         }
1919 #endif
1920
1921         encp->enc_features = enp->en_features;
1922
1923         return (0);
1924
1925 #if EFSYS_OPT_MON_STATS
1926 fail7:
1927         EFSYS_PROBE(fail7);
1928 #endif
1929 #if EFSYS_OPT_LOOPBACK
1930 fail6:
1931         EFSYS_PROBE(fail6);
1932 #endif
1933 #if EFSYS_OPT_MAC_STATS
1934 fail5:
1935         EFSYS_PROBE(fail5);
1936 #endif
1937 fail4:
1938         EFSYS_PROBE(fail4);
1939 fail3:
1940         EFSYS_PROBE(fail3);
1941 fail2:
1942         EFSYS_PROBE(fail2);
1943 fail1:
1944         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1945
1946         return (rc);
1947 }
1948
1949         __checkReturn   efx_rc_t
1950 ef10_nic_set_drv_limits(
1951         __inout         efx_nic_t *enp,
1952         __in            efx_drv_limits_t *edlp)
1953 {
1954         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1955         efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
1956         uint32_t min_evq_count, max_evq_count;
1957         uint32_t min_rxq_count, max_rxq_count;
1958         uint32_t min_txq_count, max_txq_count;
1959         efx_rc_t rc;
1960
1961         if (edlp == NULL) {
1962                 rc = EINVAL;
1963                 goto fail1;
1964         }
1965
1966         /* Get minimum required and maximum usable VI limits */
1967         min_evq_count = MIN(edlp->edl_min_evq_count, encp->enc_evq_limit);
1968         min_rxq_count = MIN(edlp->edl_min_rxq_count, encp->enc_rxq_limit);
1969         min_txq_count = MIN(edlp->edl_min_txq_count, encp->enc_txq_limit);
1970
1971         edcp->edc_min_vi_count =
1972             MAX(min_evq_count, MAX(min_rxq_count, min_txq_count));
1973
1974         max_evq_count = MIN(edlp->edl_max_evq_count, encp->enc_evq_limit);
1975         max_rxq_count = MIN(edlp->edl_max_rxq_count, encp->enc_rxq_limit);
1976         max_txq_count = MIN(edlp->edl_max_txq_count, encp->enc_txq_limit);
1977
1978         edcp->edc_max_vi_count =
1979             MAX(max_evq_count, MAX(max_rxq_count, max_txq_count));
1980
1981         /*
1982          * Check limits for sub-allocated piobuf blocks.
1983          * PIO is optional, so don't fail if the limits are incorrect.
1984          */
1985         if ((encp->enc_piobuf_size == 0) ||
1986             (encp->enc_piobuf_limit == 0) ||
1987             (edlp->edl_min_pio_alloc_size == 0) ||
1988             (edlp->edl_min_pio_alloc_size > encp->enc_piobuf_size)) {
1989                 /* Disable PIO */
1990                 edcp->edc_max_piobuf_count = 0;
1991                 edcp->edc_pio_alloc_size = 0;
1992         } else {
1993                 uint32_t blk_size, blk_count, blks_per_piobuf;
1994
1995                 blk_size =
1996                     MAX(edlp->edl_min_pio_alloc_size,
1997                             encp->enc_piobuf_min_alloc_size);
1998
1999                 blks_per_piobuf = encp->enc_piobuf_size / blk_size;
2000                 EFSYS_ASSERT3U(blks_per_piobuf, <=, 32);
2001
2002                 blk_count = (encp->enc_piobuf_limit * blks_per_piobuf);
2003
2004                 /* A zero max pio alloc count means unlimited */
2005                 if ((edlp->edl_max_pio_alloc_count > 0) &&
2006                     (edlp->edl_max_pio_alloc_count < blk_count)) {
2007                         blk_count = edlp->edl_max_pio_alloc_count;
2008                 }
2009
2010                 edcp->edc_pio_alloc_size = blk_size;
2011                 edcp->edc_max_piobuf_count =
2012                     (blk_count + (blks_per_piobuf - 1)) / blks_per_piobuf;
2013         }
2014
2015         return (0);
2016
2017 fail1:
2018         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2019
2020         return (rc);
2021 }
2022
2023
2024         __checkReturn   efx_rc_t
2025 ef10_nic_reset(
2026         __in            efx_nic_t *enp)
2027 {
2028         efx_mcdi_req_t req;
2029         uint8_t payload[MAX(MC_CMD_ENTITY_RESET_IN_LEN,
2030                             MC_CMD_ENTITY_RESET_OUT_LEN)];
2031         efx_rc_t rc;
2032
2033         /* ef10_nic_reset() is called to recover from BADASSERT failures. */
2034         if ((rc = efx_mcdi_read_assertion(enp)) != 0)
2035                 goto fail1;
2036         if ((rc = efx_mcdi_exit_assertion_handler(enp)) != 0)
2037                 goto fail2;
2038
2039         (void) memset(payload, 0, sizeof (payload));
2040         req.emr_cmd = MC_CMD_ENTITY_RESET;
2041         req.emr_in_buf = payload;
2042         req.emr_in_length = MC_CMD_ENTITY_RESET_IN_LEN;
2043         req.emr_out_buf = payload;
2044         req.emr_out_length = MC_CMD_ENTITY_RESET_OUT_LEN;
2045
2046         MCDI_IN_POPULATE_DWORD_1(req, ENTITY_RESET_IN_FLAG,
2047             ENTITY_RESET_IN_FUNCTION_RESOURCE_RESET, 1);
2048
2049         efx_mcdi_execute(enp, &req);
2050
2051         if (req.emr_rc != 0) {
2052                 rc = req.emr_rc;
2053                 goto fail3;
2054         }
2055
2056         /* Clear RX/TX DMA queue errors */
2057         enp->en_reset_flags &= ~(EFX_RESET_RXQ_ERR | EFX_RESET_TXQ_ERR);
2058
2059         return (0);
2060
2061 fail3:
2062         EFSYS_PROBE(fail3);
2063 fail2:
2064         EFSYS_PROBE(fail2);
2065 fail1:
2066         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2067
2068         return (rc);
2069 }
2070
2071         __checkReturn   efx_rc_t
2072 ef10_nic_init(
2073         __in            efx_nic_t *enp)
2074 {
2075         efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
2076         uint32_t min_vi_count, max_vi_count;
2077         uint32_t vi_count, vi_base, vi_shift;
2078         uint32_t i;
2079         uint32_t retry;
2080         uint32_t delay_us;
2081         uint32_t vi_window_size;
2082         efx_rc_t rc;
2083
2084         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
2085             enp->en_family == EFX_FAMILY_MEDFORD ||
2086             enp->en_family == EFX_FAMILY_MEDFORD2);
2087
2088         /* Enable reporting of some events (e.g. link change) */
2089         if ((rc = efx_mcdi_log_ctrl(enp)) != 0)
2090                 goto fail1;
2091
2092         /* Allocate (optional) on-chip PIO buffers */
2093         ef10_nic_alloc_piobufs(enp, edcp->edc_max_piobuf_count);
2094
2095         /*
2096          * For best performance, PIO writes should use a write-combined
2097          * (WC) memory mapping. Using a separate WC mapping for the PIO
2098          * aperture of each VI would be a burden to drivers (and not
2099          * possible if the host page size is >4Kbyte).
2100          *
2101          * To avoid this we use a single uncached (UC) mapping for VI
2102          * register access, and a single WC mapping for extra VIs used
2103          * for PIO writes.
2104          *
2105          * Each piobuf must be linked to a VI in the WC mapping, and to
2106          * each VI that is using a sub-allocated block from the piobuf.
2107          */
2108         min_vi_count = edcp->edc_min_vi_count;
2109         max_vi_count =
2110             edcp->edc_max_vi_count + enp->en_arch.ef10.ena_piobuf_count;
2111
2112         /* Ensure that the previously attached driver's VIs are freed */
2113         if ((rc = efx_mcdi_free_vis(enp)) != 0)
2114                 goto fail2;
2115
2116         /*
2117          * Reserve VI resources (EVQ+RXQ+TXQ) for this PCIe function. If this
2118          * fails then retrying the request for fewer VI resources may succeed.
2119          */
2120         vi_count = 0;
2121         if ((rc = efx_mcdi_alloc_vis(enp, min_vi_count, max_vi_count,
2122                     &vi_base, &vi_count, &vi_shift)) != 0)
2123                 goto fail3;
2124
2125         EFSYS_PROBE2(vi_alloc, uint32_t, vi_base, uint32_t, vi_count);
2126
2127         if (vi_count < min_vi_count) {
2128                 rc = ENOMEM;
2129                 goto fail4;
2130         }
2131
2132         enp->en_arch.ef10.ena_vi_base = vi_base;
2133         enp->en_arch.ef10.ena_vi_count = vi_count;
2134         enp->en_arch.ef10.ena_vi_shift = vi_shift;
2135
2136         if (vi_count < min_vi_count + enp->en_arch.ef10.ena_piobuf_count) {
2137                 /* Not enough extra VIs to map piobufs */
2138                 ef10_nic_free_piobufs(enp);
2139         }
2140
2141         enp->en_arch.ef10.ena_pio_write_vi_base =
2142             vi_count - enp->en_arch.ef10.ena_piobuf_count;
2143
2144         EFSYS_ASSERT3U(enp->en_nic_cfg.enc_vi_window_shift, !=,
2145             EFX_VI_WINDOW_SHIFT_INVALID);
2146         EFSYS_ASSERT3U(enp->en_nic_cfg.enc_vi_window_shift, <=,
2147             EFX_VI_WINDOW_SHIFT_64K);
2148         vi_window_size = 1U << enp->en_nic_cfg.enc_vi_window_shift;
2149
2150         /* Save UC memory mapping details */
2151         enp->en_arch.ef10.ena_uc_mem_map_offset = 0;
2152         if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2153                 enp->en_arch.ef10.ena_uc_mem_map_size =
2154                     (vi_window_size *
2155                     enp->en_arch.ef10.ena_pio_write_vi_base);
2156         } else {
2157                 enp->en_arch.ef10.ena_uc_mem_map_size =
2158                     (vi_window_size *
2159                     enp->en_arch.ef10.ena_vi_count);
2160         }
2161
2162         /* Save WC memory mapping details */
2163         enp->en_arch.ef10.ena_wc_mem_map_offset =
2164             enp->en_arch.ef10.ena_uc_mem_map_offset +
2165             enp->en_arch.ef10.ena_uc_mem_map_size;
2166
2167         enp->en_arch.ef10.ena_wc_mem_map_size =
2168             (vi_window_size *
2169             enp->en_arch.ef10.ena_piobuf_count);
2170
2171         /* Link piobufs to extra VIs in WC mapping */
2172         if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2173                 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
2174                         rc = efx_mcdi_link_piobuf(enp,
2175                             enp->en_arch.ef10.ena_pio_write_vi_base + i,
2176                             enp->en_arch.ef10.ena_piobuf_handle[i]);
2177                         if (rc != 0)
2178                                 break;
2179                 }
2180         }
2181
2182         /*
2183          * Allocate a vAdaptor attached to our upstream vPort/pPort.
2184          *
2185          * On a VF, this may fail with MC_CMD_ERR_NO_EVB_PORT (ENOENT) if the PF
2186          * driver has yet to bring up the EVB port. See bug 56147. In this case,
2187          * retry the request several times after waiting a while. The wait time
2188          * between retries starts small (10ms) and exponentially increases.
2189          * Total wait time is a little over two seconds. Retry logic in the
2190          * client driver may mean this whole loop is repeated if it continues to
2191          * fail.
2192          */
2193         retry = 0;
2194         delay_us = 10000;
2195         while ((rc = efx_mcdi_vadaptor_alloc(enp, EVB_PORT_ID_ASSIGNED)) != 0) {
2196                 if (EFX_PCI_FUNCTION_IS_PF(&enp->en_nic_cfg) ||
2197                     (rc != ENOENT)) {
2198                         /*
2199                          * Do not retry alloc for PF, or for other errors on
2200                          * a VF.
2201                          */
2202                         goto fail5;
2203                 }
2204
2205                 /* VF startup before PF is ready. Retry allocation. */
2206                 if (retry > 5) {
2207                         /* Too many attempts */
2208                         rc = EINVAL;
2209                         goto fail6;
2210                 }
2211                 EFSYS_PROBE1(mcdi_no_evb_port_retry, int, retry);
2212                 EFSYS_SLEEP(delay_us);
2213                 retry++;
2214                 if (delay_us < 500000)
2215                         delay_us <<= 2;
2216         }
2217
2218         enp->en_vport_id = EVB_PORT_ID_ASSIGNED;
2219         enp->en_nic_cfg.enc_mcdi_max_payload_length = MCDI_CTL_SDU_LEN_MAX_V2;
2220
2221         return (0);
2222
2223 fail6:
2224         EFSYS_PROBE(fail6);
2225 fail5:
2226         EFSYS_PROBE(fail5);
2227 fail4:
2228         EFSYS_PROBE(fail4);
2229 fail3:
2230         EFSYS_PROBE(fail3);
2231 fail2:
2232         EFSYS_PROBE(fail2);
2233
2234         ef10_nic_free_piobufs(enp);
2235
2236 fail1:
2237         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2238
2239         return (rc);
2240 }
2241
2242         __checkReturn   efx_rc_t
2243 ef10_nic_get_vi_pool(
2244         __in            efx_nic_t *enp,
2245         __out           uint32_t *vi_countp)
2246 {
2247         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
2248             enp->en_family == EFX_FAMILY_MEDFORD ||
2249             enp->en_family == EFX_FAMILY_MEDFORD2);
2250
2251         /*
2252          * Report VIs that the client driver can use.
2253          * Do not include VIs used for PIO buffer writes.
2254          */
2255         *vi_countp = enp->en_arch.ef10.ena_pio_write_vi_base;
2256
2257         return (0);
2258 }
2259
2260         __checkReturn   efx_rc_t
2261 ef10_nic_get_bar_region(
2262         __in            efx_nic_t *enp,
2263         __in            efx_nic_region_t region,
2264         __out           uint32_t *offsetp,
2265         __out           size_t *sizep)
2266 {
2267         efx_rc_t rc;
2268
2269         EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
2270             enp->en_family == EFX_FAMILY_MEDFORD ||
2271             enp->en_family == EFX_FAMILY_MEDFORD2);
2272
2273         /*
2274          * TODO: Specify host memory mapping alignment and granularity
2275          * in efx_drv_limits_t so that they can be taken into account
2276          * when allocating extra VIs for PIO writes.
2277          */
2278         switch (region) {
2279         case EFX_REGION_VI:
2280                 /* UC mapped memory BAR region for VI registers */
2281                 *offsetp = enp->en_arch.ef10.ena_uc_mem_map_offset;
2282                 *sizep = enp->en_arch.ef10.ena_uc_mem_map_size;
2283                 break;
2284
2285         case EFX_REGION_PIO_WRITE_VI:
2286                 /* WC mapped memory BAR region for piobuf writes */
2287                 *offsetp = enp->en_arch.ef10.ena_wc_mem_map_offset;
2288                 *sizep = enp->en_arch.ef10.ena_wc_mem_map_size;
2289                 break;
2290
2291         default:
2292                 rc = EINVAL;
2293                 goto fail1;
2294         }
2295
2296         return (0);
2297
2298 fail1:
2299         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2300
2301         return (rc);
2302 }
2303
2304                         void
2305 ef10_nic_fini(
2306         __in            efx_nic_t *enp)
2307 {
2308         uint32_t i;
2309         efx_rc_t rc;
2310
2311         (void) efx_mcdi_vadaptor_free(enp, enp->en_vport_id);
2312         enp->en_vport_id = 0;
2313
2314         /* Unlink piobufs from extra VIs in WC mapping */
2315         if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2316                 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
2317                         rc = efx_mcdi_unlink_piobuf(enp,
2318                             enp->en_arch.ef10.ena_pio_write_vi_base + i);
2319                         if (rc != 0)
2320                                 break;
2321                 }
2322         }
2323
2324         ef10_nic_free_piobufs(enp);
2325
2326         (void) efx_mcdi_free_vis(enp);
2327         enp->en_arch.ef10.ena_vi_count = 0;
2328 }
2329
2330                         void
2331 ef10_nic_unprobe(
2332         __in            efx_nic_t *enp)
2333 {
2334 #if EFSYS_OPT_MON_STATS
2335         mcdi_mon_cfg_free(enp);
2336 #endif /* EFSYS_OPT_MON_STATS */
2337         (void) efx_mcdi_drv_attach(enp, B_FALSE);
2338 }
2339
2340 #if EFSYS_OPT_DIAG
2341
2342         __checkReturn   efx_rc_t
2343 ef10_nic_register_test(
2344         __in            efx_nic_t *enp)
2345 {
2346         efx_rc_t rc;
2347
2348         /* FIXME */
2349         _NOTE(ARGUNUSED(enp))
2350         _NOTE(CONSTANTCONDITION)
2351         if (B_FALSE) {
2352                 rc = ENOTSUP;
2353                 goto fail1;
2354         }
2355         /* FIXME */
2356
2357         return (0);
2358
2359 fail1:
2360         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2361
2362         return (rc);
2363 }
2364
2365 #endif  /* EFSYS_OPT_DIAG */
2366
2367 #if EFSYS_OPT_FW_SUBVARIANT_AWARE
2368
2369         __checkReturn   efx_rc_t
2370 efx_mcdi_get_nic_global(
2371         __in            efx_nic_t *enp,
2372         __in            uint32_t key,
2373         __out           uint32_t *valuep)
2374 {
2375         efx_mcdi_req_t req;
2376         uint8_t payload[MAX(MC_CMD_GET_NIC_GLOBAL_IN_LEN,
2377                             MC_CMD_GET_NIC_GLOBAL_OUT_LEN)];
2378         efx_rc_t rc;
2379
2380         (void) memset(payload, 0, sizeof (payload));
2381         req.emr_cmd = MC_CMD_GET_NIC_GLOBAL;
2382         req.emr_in_buf = payload;
2383         req.emr_in_length = MC_CMD_GET_NIC_GLOBAL_IN_LEN;
2384         req.emr_out_buf = payload;
2385         req.emr_out_length = MC_CMD_GET_NIC_GLOBAL_OUT_LEN;
2386
2387         MCDI_IN_SET_DWORD(req, GET_NIC_GLOBAL_IN_KEY, key);
2388
2389         efx_mcdi_execute(enp, &req);
2390
2391         if (req.emr_rc != 0) {
2392                 rc = req.emr_rc;
2393                 goto fail1;
2394         }
2395
2396         if (req.emr_out_length_used != MC_CMD_GET_NIC_GLOBAL_OUT_LEN) {
2397                 rc = EMSGSIZE;
2398                 goto fail2;
2399         }
2400
2401         *valuep = MCDI_OUT_DWORD(req, GET_NIC_GLOBAL_OUT_VALUE);
2402
2403         return (0);
2404
2405 fail2:
2406         EFSYS_PROBE(fail2);
2407 fail1:
2408         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2409
2410         return (rc);
2411 }
2412
2413         __checkReturn   efx_rc_t
2414 efx_mcdi_set_nic_global(
2415         __in            efx_nic_t *enp,
2416         __in            uint32_t key,
2417         __in            uint32_t value)
2418 {
2419         efx_mcdi_req_t req;
2420         uint8_t payload[MC_CMD_SET_NIC_GLOBAL_IN_LEN];
2421         efx_rc_t rc;
2422
2423         (void) memset(payload, 0, sizeof (payload));
2424         req.emr_cmd = MC_CMD_SET_NIC_GLOBAL;
2425         req.emr_in_buf = payload;
2426         req.emr_in_length = MC_CMD_SET_NIC_GLOBAL_IN_LEN;
2427         req.emr_out_buf = NULL;
2428         req.emr_out_length = 0;
2429
2430         MCDI_IN_SET_DWORD(req, SET_NIC_GLOBAL_IN_KEY, key);
2431         MCDI_IN_SET_DWORD(req, SET_NIC_GLOBAL_IN_VALUE, value);
2432
2433         efx_mcdi_execute(enp, &req);
2434
2435         if (req.emr_rc != 0) {
2436                 rc = req.emr_rc;
2437                 goto fail1;
2438         }
2439
2440         return (0);
2441
2442 fail1:
2443         EFSYS_PROBE1(fail1, efx_rc_t, rc);
2444
2445         return (rc);
2446 }
2447
2448 #endif  /* EFSYS_OPT_FW_SUBVARIANT_AWARE */
2449
2450 #endif  /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */