18f19e816d08f2ce323f6b607ae10447a6990ff8
[dpdk.git] / drivers / common / sfc_efx / base / ef10_ev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 Xilinx, Inc.
4  * Copyright(c) 2012-2019 Solarflare Communications Inc.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9 #if EFSYS_OPT_MON_STATS
10 #include "mcdi_mon.h"
11 #endif
12
13 #if EFX_OPTS_EF10()
14
15 /*
16  * Non-interrupting event queue requires interrrupting event queue to
17  * refer to for wake-up events even if wake ups are never used.
18  * It could be even non-allocated event queue.
19  */
20 #define EFX_EF10_ALWAYS_INTERRUPTING_EVQ_INDEX  (0)
21
22 static  __checkReturn   boolean_t
23 ef10_ev_rx(
24         __in            efx_evq_t *eep,
25         __in            efx_qword_t *eqp,
26         __in            const efx_ev_callbacks_t *eecp,
27         __in_opt        void *arg);
28
29 static  __checkReturn   boolean_t
30 ef10_ev_tx(
31         __in            efx_evq_t *eep,
32         __in            efx_qword_t *eqp,
33         __in            const efx_ev_callbacks_t *eecp,
34         __in_opt        void *arg);
35
36 static  __checkReturn   boolean_t
37 ef10_ev_driver(
38         __in            efx_evq_t *eep,
39         __in            efx_qword_t *eqp,
40         __in            const efx_ev_callbacks_t *eecp,
41         __in_opt        void *arg);
42
43 static  __checkReturn   boolean_t
44 ef10_ev_drv_gen(
45         __in            efx_evq_t *eep,
46         __in            efx_qword_t *eqp,
47         __in            const efx_ev_callbacks_t *eecp,
48         __in_opt        void *arg);
49
50 static  __checkReturn   boolean_t
51 ef10_ev_mcdi(
52         __in            efx_evq_t *eep,
53         __in            efx_qword_t *eqp,
54         __in            const efx_ev_callbacks_t *eecp,
55         __in_opt        void *arg);
56
57
58 static  __checkReturn   efx_rc_t
59 efx_mcdi_set_evq_tmr(
60         __in            efx_nic_t *enp,
61         __in            uint32_t instance,
62         __in            uint32_t mode,
63         __in            uint32_t timer_ns)
64 {
65         efx_mcdi_req_t req;
66         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SET_EVQ_TMR_IN_LEN,
67                 MC_CMD_SET_EVQ_TMR_OUT_LEN);
68         efx_rc_t rc;
69
70         req.emr_cmd = MC_CMD_SET_EVQ_TMR;
71         req.emr_in_buf = payload;
72         req.emr_in_length = MC_CMD_SET_EVQ_TMR_IN_LEN;
73         req.emr_out_buf = payload;
74         req.emr_out_length = MC_CMD_SET_EVQ_TMR_OUT_LEN;
75
76         MCDI_IN_SET_DWORD(req, SET_EVQ_TMR_IN_INSTANCE, instance);
77         MCDI_IN_SET_DWORD(req, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, timer_ns);
78         MCDI_IN_SET_DWORD(req, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, timer_ns);
79         MCDI_IN_SET_DWORD(req, SET_EVQ_TMR_IN_TMR_MODE, mode);
80
81         efx_mcdi_execute(enp, &req);
82
83         if (req.emr_rc != 0) {
84                 rc = req.emr_rc;
85                 goto fail1;
86         }
87
88         if (req.emr_out_length_used < MC_CMD_SET_EVQ_TMR_OUT_LEN) {
89                 rc = EMSGSIZE;
90                 goto fail2;
91         }
92
93         return (0);
94
95 fail2:
96         EFSYS_PROBE(fail2);
97 fail1:
98         EFSYS_PROBE1(fail1, efx_rc_t, rc);
99
100         return (rc);
101 }
102
103
104         __checkReturn   efx_rc_t
105 ef10_ev_init(
106         __in            efx_nic_t *enp)
107 {
108         _NOTE(ARGUNUSED(enp))
109         return (0);
110 }
111
112                         void
113 ef10_ev_fini(
114         __in            efx_nic_t *enp)
115 {
116         _NOTE(ARGUNUSED(enp))
117 }
118
119         __checkReturn   efx_rc_t
120 ef10_ev_qcreate(
121         __in            efx_nic_t *enp,
122         __in            unsigned int index,
123         __in            efsys_mem_t *esmp,
124         __in            size_t ndescs,
125         __in            uint32_t id,
126         __in            uint32_t us,
127         __in            uint32_t flags,
128         __in            efx_evq_t *eep)
129 {
130         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
131         uint32_t irq;
132         efx_rc_t rc;
133
134         _NOTE(ARGUNUSED(id))    /* buftbl id managed by MC */
135
136         /*
137          * NO_CONT_EV mode is only requested from the firmware when creating
138          * receive queues, but here it needs to be specified at event queue
139          * creation, as the event handler needs to know which format is in use.
140          *
141          * If EFX_EVQ_FLAGS_NO_CONT_EV is specified, all receive queues for this
142          * event queue will be created in NO_CONT_EV mode.
143          *
144          * See SF-109306-TC 5.11 "Events for RXQs in NO_CONT_EV mode".
145          */
146         if (flags & EFX_EVQ_FLAGS_NO_CONT_EV) {
147                 if (enp->en_nic_cfg.enc_no_cont_ev_mode_supported == B_FALSE) {
148                         rc = EINVAL;
149                         goto fail1;
150                 }
151         }
152
153         /* Set up the handler table */
154         eep->ee_rx      = ef10_ev_rx;
155         eep->ee_tx      = ef10_ev_tx;
156         eep->ee_driver  = ef10_ev_driver;
157         eep->ee_drv_gen = ef10_ev_drv_gen;
158         eep->ee_mcdi    = ef10_ev_mcdi;
159
160         /* Set up the event queue */
161         /* INIT_EVQ expects function-relative vector number */
162         if ((flags & EFX_EVQ_FLAGS_NOTIFY_MASK) ==
163             EFX_EVQ_FLAGS_NOTIFY_INTERRUPT) {
164                 irq = index;
165         } else if (index == EFX_EF10_ALWAYS_INTERRUPTING_EVQ_INDEX) {
166                 irq = index;
167                 flags = (flags & ~EFX_EVQ_FLAGS_NOTIFY_MASK) |
168                     EFX_EVQ_FLAGS_NOTIFY_INTERRUPT;
169         } else {
170                 irq = EFX_EF10_ALWAYS_INTERRUPTING_EVQ_INDEX;
171         }
172
173         /*
174          * Interrupts may be raised for events immediately after the queue is
175          * created. See bug58606.
176          */
177
178         if (encp->enc_init_evq_v2_supported) {
179                 /*
180                  * On Medford the low latency license is required to enable RX
181                  * and event cut through and to disable RX batching.  If event
182                  * queue type in flags is auto, we let the firmware decide the
183                  * settings to use. If the adapter has a low latency license,
184                  * it will choose the best settings for low latency, otherwise
185                  * it will choose the best settings for throughput.
186                  */
187                 rc = efx_mcdi_init_evq_v2(enp, index, esmp, ndescs, irq, us,
188                     flags);
189                 if (rc != 0)
190                         goto fail2;
191         } else {
192                 /*
193                  * On Huntington we need to specify the settings to use.
194                  * If event queue type in flags is auto, we favour throughput
195                  * if the adapter is running virtualization supporting firmware
196                  * (i.e. the full featured firmware variant)
197                  * and latency otherwise. The Ethernet Virtual Bridging
198                  * capability is used to make this decision. (Note though that
199                  * the low latency firmware variant is also best for
200                  * throughput and corresponding type should be specified
201                  * to choose it.)
202                  */
203                 boolean_t low_latency = encp->enc_datapath_cap_evb ? 0 : 1;
204                 rc = efx_mcdi_init_evq(enp, index, esmp, ndescs, irq, us, flags,
205                     low_latency);
206                 if (rc != 0)
207                         goto fail3;
208         }
209
210         return (0);
211
212 fail3:
213         EFSYS_PROBE(fail3);
214 fail2:
215         EFSYS_PROBE(fail2);
216 fail1:
217         EFSYS_PROBE1(fail1, efx_rc_t, rc);
218
219         return (rc);
220 }
221
222                         void
223 ef10_ev_qdestroy(
224         __in            efx_evq_t *eep)
225 {
226         efx_nic_t *enp = eep->ee_enp;
227
228         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
229
230         (void) efx_mcdi_fini_evq(enp, eep->ee_index);
231 }
232
233         __checkReturn   efx_rc_t
234 ef10_ev_qprime(
235         __in            efx_evq_t *eep,
236         __in            unsigned int count)
237 {
238         efx_nic_t *enp = eep->ee_enp;
239         uint32_t rptr;
240         efx_dword_t dword;
241
242         rptr = count & eep->ee_mask;
243
244         if (enp->en_nic_cfg.enc_bug35388_workaround) {
245                 EFX_STATIC_ASSERT(EF10_EVQ_MINNEVS >
246                     (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
247                 EFX_STATIC_ASSERT(EF10_EVQ_MAXNEVS <
248                     (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
249
250                 EFX_POPULATE_DWORD_2(dword,
251                     ERF_DD_EVQ_IND_RPTR_FLAGS,
252                     EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
253                     ERF_DD_EVQ_IND_RPTR,
254                     (rptr >> ERF_DD_EVQ_IND_RPTR_WIDTH));
255                 EFX_BAR_VI_WRITED(enp, ER_DD_EVQ_INDIRECT, eep->ee_index,
256                     &dword, B_FALSE);
257
258                 EFX_POPULATE_DWORD_2(dword,
259                     ERF_DD_EVQ_IND_RPTR_FLAGS,
260                     EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
261                     ERF_DD_EVQ_IND_RPTR,
262                     rptr & ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
263                 EFX_BAR_VI_WRITED(enp, ER_DD_EVQ_INDIRECT, eep->ee_index,
264                     &dword, B_FALSE);
265         } else {
266                 EFX_POPULATE_DWORD_1(dword, ERF_DZ_EVQ_RPTR, rptr);
267                 EFX_BAR_VI_WRITED(enp, ER_DZ_EVQ_RPTR_REG, eep->ee_index,
268                     &dword, B_FALSE);
269         }
270
271         return (0);
272 }
273
274 static  __checkReturn   efx_rc_t
275 efx_mcdi_driver_event(
276         __in            efx_nic_t *enp,
277         __in            uint32_t evq,
278         __in            efx_qword_t data)
279 {
280         efx_mcdi_req_t req;
281         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_DRIVER_EVENT_IN_LEN,
282                 MC_CMD_DRIVER_EVENT_OUT_LEN);
283         efx_rc_t rc;
284
285         req.emr_cmd = MC_CMD_DRIVER_EVENT;
286         req.emr_in_buf = payload;
287         req.emr_in_length = MC_CMD_DRIVER_EVENT_IN_LEN;
288         req.emr_out_buf = payload;
289         req.emr_out_length = MC_CMD_DRIVER_EVENT_OUT_LEN;
290
291         MCDI_IN_SET_DWORD(req, DRIVER_EVENT_IN_EVQ, evq);
292
293         MCDI_IN_SET_DWORD(req, DRIVER_EVENT_IN_DATA_LO,
294             EFX_QWORD_FIELD(data, EFX_DWORD_0));
295         MCDI_IN_SET_DWORD(req, DRIVER_EVENT_IN_DATA_HI,
296             EFX_QWORD_FIELD(data, EFX_DWORD_1));
297
298         efx_mcdi_execute(enp, &req);
299
300         if (req.emr_rc != 0) {
301                 rc = req.emr_rc;
302                 goto fail1;
303         }
304
305         return (0);
306
307 fail1:
308         EFSYS_PROBE1(fail1, efx_rc_t, rc);
309
310         return (rc);
311 }
312
313                         void
314 ef10_ev_qpost(
315         __in    efx_evq_t *eep,
316         __in    uint16_t data)
317 {
318         efx_nic_t *enp = eep->ee_enp;
319         efx_qword_t event;
320
321         EFX_POPULATE_QWORD_3(event,
322             ESF_DZ_DRV_CODE, ESE_DZ_EV_CODE_DRV_GEN_EV,
323             ESF_DZ_DRV_SUB_CODE, 0,
324             ESF_DZ_DRV_SUB_DATA_DW0, (uint32_t)data);
325
326         (void) efx_mcdi_driver_event(enp, eep->ee_index, event);
327 }
328
329         __checkReturn   efx_rc_t
330 ef10_ev_qmoderate(
331         __in            efx_evq_t *eep,
332         __in            unsigned int us)
333 {
334         efx_nic_t *enp = eep->ee_enp;
335         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
336         efx_dword_t dword;
337         uint32_t mode;
338         efx_rc_t rc;
339
340         /* Check that hardware and MCDI use the same timer MODE values */
341         EFX_STATIC_ASSERT(FFE_CZ_TIMER_MODE_DIS ==
342             MC_CMD_SET_EVQ_TMR_IN_TIMER_MODE_DIS);
343         EFX_STATIC_ASSERT(FFE_CZ_TIMER_MODE_IMMED_START ==
344             MC_CMD_SET_EVQ_TMR_IN_TIMER_MODE_IMMED_START);
345         EFX_STATIC_ASSERT(FFE_CZ_TIMER_MODE_TRIG_START ==
346             MC_CMD_SET_EVQ_TMR_IN_TIMER_MODE_TRIG_START);
347         EFX_STATIC_ASSERT(FFE_CZ_TIMER_MODE_INT_HLDOFF ==
348             MC_CMD_SET_EVQ_TMR_IN_TIMER_MODE_INT_HLDOFF);
349
350         if (us > encp->enc_evq_timer_max_us) {
351                 rc = EINVAL;
352                 goto fail1;
353         }
354
355         /* If the value is zero then disable the timer */
356         if (us == 0) {
357                 mode = FFE_CZ_TIMER_MODE_DIS;
358         } else {
359                 mode = FFE_CZ_TIMER_MODE_INT_HLDOFF;
360         }
361
362         if (encp->enc_bug61265_workaround) {
363                 uint32_t ns = us * 1000;
364
365                 rc = efx_mcdi_set_evq_tmr(enp, eep->ee_index, mode, ns);
366                 if (rc != 0)
367                         goto fail2;
368         } else {
369                 unsigned int ticks;
370
371                 if ((rc = efx_ev_usecs_to_ticks(enp, us, &ticks)) != 0)
372                         goto fail3;
373
374                 if (encp->enc_bug35388_workaround) {
375                         EFX_POPULATE_DWORD_3(dword,
376                             ERF_DD_EVQ_IND_TIMER_FLAGS,
377                             EFE_DD_EVQ_IND_TIMER_FLAGS,
378                             ERF_DD_EVQ_IND_TIMER_MODE, mode,
379                             ERF_DD_EVQ_IND_TIMER_VAL, ticks);
380                         EFX_BAR_VI_WRITED(enp, ER_DD_EVQ_INDIRECT,
381                             eep->ee_index, &dword, 0);
382                 } else {
383                         /*
384                          * NOTE: The TMR_REL field introduced in Medford2 is
385                          * ignored on earlier EF10 controllers. See bug66418
386                          * comment 9 for details.
387                          */
388                         EFX_POPULATE_DWORD_3(dword,
389                             ERF_DZ_TC_TIMER_MODE, mode,
390                             ERF_DZ_TC_TIMER_VAL, ticks,
391                             ERF_FZ_TC_TMR_REL_VAL, ticks);
392                         EFX_BAR_VI_WRITED(enp, ER_DZ_EVQ_TMR_REG,
393                             eep->ee_index, &dword, 0);
394                 }
395         }
396
397         return (0);
398
399 fail3:
400         EFSYS_PROBE(fail3);
401 fail2:
402         EFSYS_PROBE(fail2);
403 fail1:
404         EFSYS_PROBE1(fail1, efx_rc_t, rc);
405
406         return (rc);
407 }
408
409
410 #if EFSYS_OPT_QSTATS
411                         void
412 ef10_ev_qstats_update(
413         __in                            efx_evq_t *eep,
414         __inout_ecount(EV_NQSTATS)      efsys_stat_t *stat)
415 {
416         unsigned int id;
417
418         for (id = 0; id < EV_NQSTATS; id++) {
419                 efsys_stat_t *essp = &stat[id];
420
421                 EFSYS_STAT_INCR(essp, eep->ee_stat[id]);
422                 eep->ee_stat[id] = 0;
423         }
424 }
425 #endif /* EFSYS_OPT_QSTATS */
426
427 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
428
429 static  __checkReturn   boolean_t
430 ef10_ev_rx_packed_stream(
431         __in            efx_evq_t *eep,
432         __in            efx_qword_t *eqp,
433         __in            const efx_ev_callbacks_t *eecp,
434         __in_opt        void *arg)
435 {
436         uint32_t label;
437         uint32_t pkt_count_lbits;
438         uint16_t flags;
439         boolean_t should_abort;
440         efx_evq_rxq_state_t *eersp;
441         unsigned int pkt_count;
442         unsigned int current_id;
443         boolean_t new_buffer;
444
445         pkt_count_lbits = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_DSC_PTR_LBITS);
446         label = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_QLABEL);
447         new_buffer = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_EV_ROTATE);
448
449         flags = 0;
450
451         eersp = &eep->ee_rxq_state[label];
452
453         /*
454          * RX_DSC_PTR_LBITS has least significant bits of the global
455          * (not per-buffer) packet counter. It is guaranteed that
456          * maximum number of completed packets fits in lbits-mask.
457          * So, modulo lbits-mask arithmetic should be used to calculate
458          * packet counter increment.
459          */
460         pkt_count = (pkt_count_lbits - eersp->eers_rx_stream_npackets) &
461             EFX_MASK32(ESF_DZ_RX_DSC_PTR_LBITS);
462         eersp->eers_rx_stream_npackets += pkt_count;
463
464         if (new_buffer) {
465                 flags |= EFX_PKT_PACKED_STREAM_NEW_BUFFER;
466 #if EFSYS_OPT_RX_PACKED_STREAM
467                 /*
468                  * If both packed stream and equal stride super-buffer
469                  * modes are compiled in, in theory credits should be
470                  * be maintained for packed stream only, but right now
471                  * these modes are not distinguished in the event queue
472                  * Rx queue state and it is OK to increment the counter
473                  * regardless (it might be event cheaper than branching
474                  * since neighbour structure member are updated as well).
475                  */
476                 eersp->eers_rx_packed_stream_credits++;
477 #endif
478                 eersp->eers_rx_read_ptr++;
479         }
480         current_id = eersp->eers_rx_read_ptr & eersp->eers_rx_mask;
481
482         /* Check for errors that invalidate checksum and L3/L4 fields */
483         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_TRUNC_ERR) != 0) {
484                 /* RX frame truncated */
485                 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
486                 flags |= EFX_DISCARD;
487                 goto deliver;
488         }
489         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_ECRC_ERR) != 0) {
490                 /* Bad Ethernet frame CRC */
491                 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
492                 flags |= EFX_DISCARD;
493                 goto deliver;
494         }
495
496         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_PARSE_INCOMPLETE)) {
497                 EFX_EV_QSTAT_INCR(eep, EV_RX_PARSE_INCOMPLETE);
498                 flags |= EFX_PKT_PACKED_STREAM_PARSE_INCOMPLETE;
499                 goto deliver;
500         }
501
502         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_IPCKSUM_ERR))
503                 EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
504
505         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_TCPUDP_CKSUM_ERR))
506                 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
507
508 deliver:
509         /* If we're not discarding the packet then it is ok */
510         if (~flags & EFX_DISCARD)
511                 EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
512
513         EFSYS_ASSERT(eecp->eec_rx_ps != NULL);
514         should_abort = eecp->eec_rx_ps(arg, label, current_id, pkt_count,
515             flags);
516
517         return (should_abort);
518 }
519
520 #endif /* EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER */
521
522 static  __checkReturn   boolean_t
523 ef10_ev_rx(
524         __in            efx_evq_t *eep,
525         __in            efx_qword_t *eqp,
526         __in            const efx_ev_callbacks_t *eecp,
527         __in_opt        void *arg)
528 {
529         efx_nic_t *enp = eep->ee_enp;
530         uint32_t size;
531         uint32_t label;
532         uint32_t mac_class;
533         uint32_t eth_tag_class;
534         uint32_t l3_class;
535         uint32_t l4_class;
536         uint32_t next_read_lbits;
537         uint16_t flags;
538         boolean_t cont;
539         boolean_t should_abort;
540         efx_evq_rxq_state_t *eersp;
541         unsigned int desc_count;
542         unsigned int last_used_id;
543
544         EFX_EV_QSTAT_INCR(eep, EV_RX);
545
546         /* Discard events after RXQ/TXQ errors, or hardware not available */
547         if (enp->en_reset_flags &
548             (EFX_RESET_RXQ_ERR | EFX_RESET_TXQ_ERR | EFX_RESET_HW_UNAVAIL))
549                 return (B_FALSE);
550
551         /* Basic packet information */
552         label = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_QLABEL);
553         eersp = &eep->ee_rxq_state[label];
554
555 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
556         /*
557          * Packed stream events are very different,
558          * so handle them separately
559          */
560         if (eersp->eers_rx_packed_stream)
561                 return (ef10_ev_rx_packed_stream(eep, eqp, eecp, arg));
562 #endif
563
564         size = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_BYTES);
565         cont = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_CONT);
566         next_read_lbits = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_DSC_PTR_LBITS);
567         eth_tag_class = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_ETH_TAG_CLASS);
568         mac_class = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_MAC_CLASS);
569         l3_class = EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_L3_CLASS);
570
571         /*
572          * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is only
573          * 2 bits wide on Medford2. Check it is safe to use the Medford2 field
574          * and values for all EF10 controllers.
575          */
576         EFX_STATIC_ASSERT(ESF_FZ_RX_L4_CLASS_LBN == ESF_DE_RX_L4_CLASS_LBN);
577         EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_TCP == ESE_DE_L4_CLASS_TCP);
578         EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UDP == ESE_DE_L4_CLASS_UDP);
579         EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UNKNOWN == ESE_DE_L4_CLASS_UNKNOWN);
580
581         l4_class = EFX_QWORD_FIELD(*eqp, ESF_FZ_RX_L4_CLASS);
582
583         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_DROP_EVENT) != 0) {
584                 /* Drop this event */
585                 return (B_FALSE);
586         }
587         flags = 0;
588
589         if (cont != 0) {
590                 /*
591                  * This may be part of a scattered frame, or it may be a
592                  * truncated frame if scatter is disabled on this RXQ.
593                  * Overlength frames can be received if e.g. a VF is configured
594                  * for 1500 MTU but connected to a port set to 9000 MTU
595                  * (see bug56567).
596                  * FIXME: There is not yet any driver that supports scatter on
597                  * Huntington.  Scatter support is required for OSX.
598                  */
599                 flags |= EFX_PKT_CONT;
600         }
601
602         if (mac_class == ESE_DZ_MAC_CLASS_UCAST)
603                 flags |= EFX_PKT_UNICAST;
604
605         /*
606          * Increment the count of descriptors read.
607          *
608          * In NO_CONT_EV mode, RX_DSC_PTR_LBITS is actually a packet count, but
609          * when scatter is disabled, there is only one descriptor per packet and
610          * so it can be treated the same.
611          *
612          * TODO: Support scatter in NO_CONT_EV mode.
613          */
614         desc_count = (next_read_lbits - eersp->eers_rx_read_ptr) &
615             EFX_MASK32(ESF_DZ_RX_DSC_PTR_LBITS);
616         eersp->eers_rx_read_ptr += desc_count;
617
618         /* Calculate the index of the last descriptor consumed */
619         last_used_id = (eersp->eers_rx_read_ptr - 1) & eersp->eers_rx_mask;
620
621         if (eep->ee_flags & EFX_EVQ_FLAGS_NO_CONT_EV) {
622                 if (desc_count > 1)
623                         EFX_EV_QSTAT_INCR(eep, EV_RX_BATCH);
624
625                 /* Always read the length from the prefix in NO_CONT_EV mode. */
626                 flags |= EFX_PKT_PREFIX_LEN;
627
628                 /*
629                  * Check for an aborted scatter, signalled by the ABORT bit in
630                  * NO_CONT_EV mode. The ABORT bit was not used before NO_CONT_EV
631                  * mode was added as it was broken in Huntington silicon.
632                  */
633                 if (EFX_QWORD_FIELD(*eqp, ESF_EZ_RX_ABORT) != 0) {
634                         flags |= EFX_DISCARD;
635                         goto deliver;
636                 }
637         } else if (desc_count > 1) {
638                 /*
639                  * FIXME: add error checking to make sure this a batched event.
640                  * This could also be an aborted scatter, see Bug36629.
641                  */
642                 EFX_EV_QSTAT_INCR(eep, EV_RX_BATCH);
643                 flags |= EFX_PKT_PREFIX_LEN;
644         }
645
646         /* Check for errors that invalidate checksum and L3/L4 fields */
647         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_TRUNC_ERR) != 0) {
648                 /* RX frame truncated */
649                 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
650                 flags |= EFX_DISCARD;
651                 goto deliver;
652         }
653         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_ECRC_ERR) != 0) {
654                 /* Bad Ethernet frame CRC */
655                 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
656                 flags |= EFX_DISCARD;
657                 goto deliver;
658         }
659         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_PARSE_INCOMPLETE)) {
660                 /*
661                  * Hardware parse failed, due to malformed headers
662                  * or headers that are too long for the parser.
663                  * Headers and checksums must be validated by the host.
664                  */
665                 EFX_EV_QSTAT_INCR(eep, EV_RX_PARSE_INCOMPLETE);
666                 goto deliver;
667         }
668
669         if ((eth_tag_class == ESE_DZ_ETH_TAG_CLASS_VLAN1) ||
670             (eth_tag_class == ESE_DZ_ETH_TAG_CLASS_VLAN2)) {
671                 flags |= EFX_PKT_VLAN_TAGGED;
672         }
673
674         switch (l3_class) {
675         case ESE_DZ_L3_CLASS_IP4:
676         case ESE_DZ_L3_CLASS_IP4_FRAG:
677                 flags |= EFX_PKT_IPV4;
678                 if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_IPCKSUM_ERR)) {
679                         EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
680                 } else {
681                         flags |= EFX_CKSUM_IPV4;
682                 }
683
684                 /*
685                  * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is
686                  * only 2 bits wide on Medford2. Check it is safe to use the
687                  * Medford2 field and values for all EF10 controllers.
688                  */
689                 EFX_STATIC_ASSERT(ESF_FZ_RX_L4_CLASS_LBN ==
690                     ESF_DE_RX_L4_CLASS_LBN);
691                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_TCP == ESE_DE_L4_CLASS_TCP);
692                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UDP == ESE_DE_L4_CLASS_UDP);
693                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UNKNOWN ==
694                     ESE_DE_L4_CLASS_UNKNOWN);
695
696                 if (l4_class == ESE_FZ_L4_CLASS_TCP) {
697                         EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4);
698                         flags |= EFX_PKT_TCP;
699                 } else if (l4_class == ESE_FZ_L4_CLASS_UDP) {
700                         EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4);
701                         flags |= EFX_PKT_UDP;
702                 } else {
703                         EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4);
704                 }
705                 break;
706
707         case ESE_DZ_L3_CLASS_IP6:
708         case ESE_DZ_L3_CLASS_IP6_FRAG:
709                 flags |= EFX_PKT_IPV6;
710
711                 /*
712                  * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is
713                  * only 2 bits wide on Medford2. Check it is safe to use the
714                  * Medford2 field and values for all EF10 controllers.
715                  */
716                 EFX_STATIC_ASSERT(ESF_FZ_RX_L4_CLASS_LBN ==
717                     ESF_DE_RX_L4_CLASS_LBN);
718                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_TCP == ESE_DE_L4_CLASS_TCP);
719                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UDP == ESE_DE_L4_CLASS_UDP);
720                 EFX_STATIC_ASSERT(ESE_FZ_L4_CLASS_UNKNOWN ==
721                     ESE_DE_L4_CLASS_UNKNOWN);
722
723                 if (l4_class == ESE_FZ_L4_CLASS_TCP) {
724                         EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6);
725                         flags |= EFX_PKT_TCP;
726                 } else if (l4_class == ESE_FZ_L4_CLASS_UDP) {
727                         EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6);
728                         flags |= EFX_PKT_UDP;
729                 } else {
730                         EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6);
731                 }
732                 break;
733
734         default:
735                 EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP);
736                 break;
737         }
738
739         if (flags & (EFX_PKT_TCP | EFX_PKT_UDP)) {
740                 if (EFX_QWORD_FIELD(*eqp, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
741                         EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
742                 } else {
743                         flags |= EFX_CKSUM_TCPUDP;
744                 }
745         }
746
747 deliver:
748         /* If we're not discarding the packet then it is ok */
749         if (~flags & EFX_DISCARD)
750                 EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
751
752         EFSYS_ASSERT(eecp->eec_rx != NULL);
753         should_abort = eecp->eec_rx(arg, label, last_used_id, size, flags);
754
755         return (should_abort);
756 }
757
758 static  __checkReturn   boolean_t
759 ef10_ev_tx(
760         __in            efx_evq_t *eep,
761         __in            efx_qword_t *eqp,
762         __in            const efx_ev_callbacks_t *eecp,
763         __in_opt        void *arg)
764 {
765         efx_nic_t *enp = eep->ee_enp;
766         uint32_t id;
767         uint32_t label;
768         boolean_t should_abort;
769
770         EFX_EV_QSTAT_INCR(eep, EV_TX);
771
772         /* Discard events after RXQ/TXQ errors, or hardware not available */
773         if (enp->en_reset_flags &
774             (EFX_RESET_RXQ_ERR | EFX_RESET_TXQ_ERR | EFX_RESET_HW_UNAVAIL))
775                 return (B_FALSE);
776
777         if (EFX_QWORD_FIELD(*eqp, ESF_DZ_TX_DROP_EVENT) != 0) {
778                 /* Drop this event */
779                 return (B_FALSE);
780         }
781
782         /* Per-packet TX completion (was per-descriptor for Falcon/Siena) */
783         id = EFX_QWORD_FIELD(*eqp, ESF_DZ_TX_DESCR_INDX);
784         label = EFX_QWORD_FIELD(*eqp, ESF_DZ_TX_QLABEL);
785
786         EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id);
787
788         EFSYS_ASSERT(eecp->eec_tx != NULL);
789         should_abort = eecp->eec_tx(arg, label, id);
790
791         return (should_abort);
792 }
793
794 static  __checkReturn   boolean_t
795 ef10_ev_driver(
796         __in            efx_evq_t *eep,
797         __in            efx_qword_t *eqp,
798         __in            const efx_ev_callbacks_t *eecp,
799         __in_opt        void *arg)
800 {
801         unsigned int code;
802         boolean_t should_abort;
803
804         EFX_EV_QSTAT_INCR(eep, EV_DRIVER);
805         should_abort = B_FALSE;
806
807         code = EFX_QWORD_FIELD(*eqp, ESF_DZ_DRV_SUB_CODE);
808         switch (code) {
809         case ESE_DZ_DRV_TIMER_EV: {
810                 uint32_t id;
811
812                 id = EFX_QWORD_FIELD(*eqp, ESF_DZ_DRV_TMR_ID);
813
814                 EFSYS_ASSERT(eecp->eec_timer != NULL);
815                 should_abort = eecp->eec_timer(arg, id);
816                 break;
817         }
818
819         case ESE_DZ_DRV_WAKE_UP_EV: {
820                 uint32_t id;
821
822                 id = EFX_QWORD_FIELD(*eqp, ESF_DZ_DRV_EVQ_ID);
823
824                 EFSYS_ASSERT(eecp->eec_wake_up != NULL);
825                 should_abort = eecp->eec_wake_up(arg, id);
826                 break;
827         }
828
829         case ESE_DZ_DRV_START_UP_EV:
830                 EFSYS_ASSERT(eecp->eec_initialized != NULL);
831                 should_abort = eecp->eec_initialized(arg);
832                 break;
833
834         default:
835                 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
836                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
837                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
838                 break;
839         }
840
841         return (should_abort);
842 }
843
844 static  __checkReturn   boolean_t
845 ef10_ev_drv_gen(
846         __in            efx_evq_t *eep,
847         __in            efx_qword_t *eqp,
848         __in            const efx_ev_callbacks_t *eecp,
849         __in_opt        void *arg)
850 {
851         uint32_t data;
852         boolean_t should_abort;
853
854         EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN);
855         should_abort = B_FALSE;
856
857         data = EFX_QWORD_FIELD(*eqp, ESF_DZ_DRV_SUB_DATA_DW0);
858         if (data >= ((uint32_t)1 << 16)) {
859                 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
860                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
861                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
862
863                 return (B_TRUE);
864         }
865
866         EFSYS_ASSERT(eecp->eec_software != NULL);
867         should_abort = eecp->eec_software(arg, (uint16_t)data);
868
869         return (should_abort);
870 }
871
872 static  __checkReturn   boolean_t
873 ef10_ev_mcdi(
874         __in            efx_evq_t *eep,
875         __in            efx_qword_t *eqp,
876         __in            const efx_ev_callbacks_t *eecp,
877         __in_opt        void *arg)
878 {
879         efx_nic_t *enp = eep->ee_enp;
880         unsigned int code;
881         boolean_t should_abort = B_FALSE;
882
883         EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE);
884
885         code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE);
886         switch (code) {
887         case MCDI_EVENT_CODE_BADSSERT:
888                 efx_mcdi_ev_death(enp, EINTR);
889                 break;
890
891         case MCDI_EVENT_CODE_CMDDONE:
892                 efx_mcdi_ev_cpl(enp,
893                     MCDI_EV_FIELD(eqp, CMDDONE_SEQ),
894                     MCDI_EV_FIELD(eqp, CMDDONE_DATALEN),
895                     MCDI_EV_FIELD(eqp, CMDDONE_ERRNO));
896                 break;
897
898 #if EFSYS_OPT_MCDI_PROXY_AUTH
899         case MCDI_EVENT_CODE_PROXY_RESPONSE:
900                 /*
901                  * This event notifies a function that an authorization request
902                  * has been processed. If the request was authorized then the
903                  * function can now re-send the original MCDI request.
904                  * See SF-113652-SW "SR-IOV Proxied Network Access Control".
905                  */
906                 efx_mcdi_ev_proxy_response(enp,
907                     MCDI_EV_FIELD(eqp, PROXY_RESPONSE_HANDLE),
908                     MCDI_EV_FIELD(eqp, PROXY_RESPONSE_RC));
909                 break;
910 #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
911
912 #if EFSYS_OPT_MCDI_PROXY_AUTH_SERVER
913         case MCDI_EVENT_CODE_PROXY_REQUEST:
914                 efx_mcdi_ev_proxy_request(enp,
915                         MCDI_EV_FIELD(eqp, PROXY_REQUEST_BUFF_INDEX));
916                 break;
917 #endif /* EFSYS_OPT_MCDI_PROXY_AUTH_SERVER */
918
919         case MCDI_EVENT_CODE_LINKCHANGE: {
920                 efx_link_mode_t link_mode;
921
922                 ef10_phy_link_ev(enp, eqp, &link_mode);
923                 should_abort = eecp->eec_link_change(arg, link_mode);
924                 break;
925         }
926
927         case MCDI_EVENT_CODE_SENSOREVT: {
928 #if EFSYS_OPT_MON_STATS
929                 efx_mon_stat_t id;
930                 efx_mon_stat_value_t value;
931                 efx_rc_t rc;
932
933                 /* Decode monitor stat for MCDI sensor (if supported) */
934                 if ((rc = mcdi_mon_ev(enp, eqp, &id, &value)) == 0) {
935                         /* Report monitor stat change */
936                         should_abort = eecp->eec_monitor(arg, id, value);
937                 } else if (rc == ENOTSUP) {
938                         should_abort = eecp->eec_exception(arg,
939                                 EFX_EXCEPTION_UNKNOWN_SENSOREVT,
940                                 MCDI_EV_FIELD(eqp, DATA));
941                 } else {
942                         EFSYS_ASSERT(rc == ENODEV);     /* Wrong port */
943                 }
944 #endif
945                 break;
946         }
947
948         case MCDI_EVENT_CODE_SCHEDERR:
949                 /* Informational only */
950                 break;
951
952         case MCDI_EVENT_CODE_REBOOT:
953                 /* Falcon/Siena only (should not been seen with Huntington). */
954                 efx_mcdi_ev_death(enp, EIO);
955                 break;
956
957         case MCDI_EVENT_CODE_MC_REBOOT:
958                 /* MC_REBOOT event is used for Huntington (EF10) and later. */
959                 efx_mcdi_ev_death(enp, EIO);
960                 break;
961
962         case MCDI_EVENT_CODE_MAC_STATS_DMA:
963 #if EFSYS_OPT_MAC_STATS
964                 if (eecp->eec_mac_stats != NULL) {
965                         eecp->eec_mac_stats(arg,
966                             MCDI_EV_FIELD(eqp, MAC_STATS_DMA_GENERATION));
967                 }
968 #endif
969                 break;
970
971         case MCDI_EVENT_CODE_FWALERT: {
972                 uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON);
973
974                 if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS)
975                         should_abort = eecp->eec_exception(arg,
976                                 EFX_EXCEPTION_FWALERT_SRAM,
977                                 MCDI_EV_FIELD(eqp, FWALERT_DATA));
978                 else
979                         should_abort = eecp->eec_exception(arg,
980                                 EFX_EXCEPTION_UNKNOWN_FWALERT,
981                                 MCDI_EV_FIELD(eqp, DATA));
982                 break;
983         }
984
985         case MCDI_EVENT_CODE_TX_ERR: {
986                 /*
987                  * After a TXQ error is detected, firmware sends a TX_ERR event.
988                  * This may be followed by TX completions (which we discard),
989                  * and then finally by a TX_FLUSH event. Firmware destroys the
990                  * TXQ automatically after sending the TX_FLUSH event.
991                  */
992                 enp->en_reset_flags |= EFX_RESET_TXQ_ERR;
993
994                 EFSYS_PROBE2(tx_descq_err,
995                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
996                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
997
998                 /* Inform the driver that a reset is required. */
999                 eecp->eec_exception(arg, EFX_EXCEPTION_TX_ERROR,
1000                     MCDI_EV_FIELD(eqp, TX_ERR_DATA));
1001                 break;
1002         }
1003
1004         case MCDI_EVENT_CODE_TX_FLUSH: {
1005                 uint32_t txq_index = MCDI_EV_FIELD(eqp, TX_FLUSH_TXQ);
1006
1007                 /*
1008                  * EF10 firmware sends two TX_FLUSH events: one to the txq's
1009                  * event queue, and one to evq 0 (with TX_FLUSH_TO_DRIVER set).
1010                  * We want to wait for all completions, so ignore the events
1011                  * with TX_FLUSH_TO_DRIVER.
1012                  */
1013                 if (MCDI_EV_FIELD(eqp, TX_FLUSH_TO_DRIVER) != 0) {
1014                         should_abort = B_FALSE;
1015                         break;
1016                 }
1017
1018                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE);
1019
1020                 EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index);
1021
1022                 EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL);
1023                 should_abort = eecp->eec_txq_flush_done(arg, txq_index);
1024                 break;
1025         }
1026
1027         case MCDI_EVENT_CODE_RX_ERR: {
1028                 /*
1029                  * After an RXQ error is detected, firmware sends an RX_ERR
1030                  * event. This may be followed by RX events (which we discard),
1031                  * and then finally by an RX_FLUSH event. Firmware destroys the
1032                  * RXQ automatically after sending the RX_FLUSH event.
1033                  */
1034                 enp->en_reset_flags |= EFX_RESET_RXQ_ERR;
1035
1036                 EFSYS_PROBE2(rx_descq_err,
1037                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
1038                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
1039
1040                 /* Inform the driver that a reset is required. */
1041                 eecp->eec_exception(arg, EFX_EXCEPTION_RX_ERROR,
1042                     MCDI_EV_FIELD(eqp, RX_ERR_DATA));
1043                 break;
1044         }
1045
1046         case MCDI_EVENT_CODE_RX_FLUSH: {
1047                 uint32_t rxq_index = MCDI_EV_FIELD(eqp, RX_FLUSH_RXQ);
1048
1049                 /*
1050                  * EF10 firmware sends two RX_FLUSH events: one to the rxq's
1051                  * event queue, and one to evq 0 (with RX_FLUSH_TO_DRIVER set).
1052                  * We want to wait for all completions, so ignore the events
1053                  * with RX_FLUSH_TO_DRIVER.
1054                  */
1055                 if (MCDI_EV_FIELD(eqp, RX_FLUSH_TO_DRIVER) != 0) {
1056                         should_abort = B_FALSE;
1057                         break;
1058                 }
1059
1060                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE);
1061
1062                 EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index);
1063
1064                 EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL);
1065                 should_abort = eecp->eec_rxq_flush_done(arg, rxq_index);
1066                 break;
1067         }
1068
1069         default:
1070                 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
1071                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
1072                     uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
1073                 break;
1074         }
1075
1076         return (should_abort);
1077 }
1078
1079                 void
1080 ef10_ev_rxlabel_init(
1081         __in            efx_evq_t *eep,
1082         __in            efx_rxq_t *erp,
1083         __in            unsigned int label,
1084         __in            efx_rxq_type_t type)
1085 {
1086         efx_evq_rxq_state_t *eersp;
1087 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
1088         boolean_t packed_stream = (type == EFX_RXQ_TYPE_PACKED_STREAM);
1089         boolean_t es_super_buffer = (type == EFX_RXQ_TYPE_ES_SUPER_BUFFER);
1090 #endif
1091
1092         _NOTE(ARGUNUSED(type))
1093         EFSYS_ASSERT3U(label, <, EFX_ARRAY_SIZE(eep->ee_rxq_state));
1094         eersp = &eep->ee_rxq_state[label];
1095
1096         EFSYS_ASSERT3U(eersp->eers_rx_mask, ==, 0);
1097
1098 #if EFSYS_OPT_RX_PACKED_STREAM
1099         /*
1100          * For packed stream modes, the very first event will
1101          * have a new buffer flag set, so it will be incremented,
1102          * yielding the correct pointer. That results in a simpler
1103          * code than trying to detect start-of-the-world condition
1104          * in the event handler.
1105          */
1106         eersp->eers_rx_read_ptr = packed_stream ? ~0 : 0;
1107 #else
1108         eersp->eers_rx_read_ptr = 0;
1109 #endif
1110         eersp->eers_rx_mask = erp->er_mask;
1111 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
1112         eersp->eers_rx_stream_npackets = 0;
1113         eersp->eers_rx_packed_stream = packed_stream || es_super_buffer;
1114 #endif
1115 #if EFSYS_OPT_RX_PACKED_STREAM
1116         if (packed_stream) {
1117                 eersp->eers_rx_packed_stream_credits = (eep->ee_mask + 1) /
1118                     EFX_DIV_ROUND_UP(EFX_RX_PACKED_STREAM_MEM_PER_CREDIT,
1119                     EFX_RX_PACKED_STREAM_MIN_PACKET_SPACE);
1120                 EFSYS_ASSERT3U(eersp->eers_rx_packed_stream_credits, !=, 0);
1121                 /*
1122                  * A single credit is allocated to the queue when it is started.
1123                  * It is immediately spent by the first packet which has NEW
1124                  * BUFFER flag set, though, but still we shall take into
1125                  * account, as to not wrap around the maximum number of credits
1126                  * accidentally
1127                  */
1128                 eersp->eers_rx_packed_stream_credits--;
1129                 EFSYS_ASSERT3U(eersp->eers_rx_packed_stream_credits, <=,
1130                     EFX_RX_PACKED_STREAM_MAX_CREDITS);
1131         }
1132 #endif
1133 }
1134
1135                 void
1136 ef10_ev_rxlabel_fini(
1137         __in            efx_evq_t *eep,
1138         __in            unsigned int label)
1139 {
1140         efx_evq_rxq_state_t *eersp;
1141
1142         EFSYS_ASSERT3U(label, <, EFX_ARRAY_SIZE(eep->ee_rxq_state));
1143         eersp = &eep->ee_rxq_state[label];
1144
1145         EFSYS_ASSERT3U(eersp->eers_rx_mask, !=, 0);
1146
1147         eersp->eers_rx_read_ptr = 0;
1148         eersp->eers_rx_mask = 0;
1149 #if EFSYS_OPT_RX_PACKED_STREAM || EFSYS_OPT_RX_ES_SUPER_BUFFER
1150         eersp->eers_rx_stream_npackets = 0;
1151         eersp->eers_rx_packed_stream = B_FALSE;
1152 #endif
1153 #if EFSYS_OPT_RX_PACKED_STREAM
1154         eersp->eers_rx_packed_stream_credits = 0;
1155 #endif
1156 }
1157
1158 #endif  /* EFX_OPTS_EF10() */