1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2012-2018 Solarflare Communications Inc.
11 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
14 static __checkReturn efx_rc_t
18 __in uint32_t target_evq,
20 __in uint32_t instance,
21 __in efsys_mem_t *esmp,
22 __in boolean_t disable_scatter,
23 __in boolean_t want_inner_classes,
24 __in uint32_t ps_bufsize,
25 __in uint32_t es_bufs_per_desc,
26 __in uint32_t es_max_dma_len,
27 __in uint32_t es_buf_stride,
28 __in uint32_t hol_block_timeout)
30 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
32 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_INIT_RXQ_V3_IN_LEN,
33 MC_CMD_INIT_RXQ_V3_OUT_LEN);
34 int npages = efx_rxq_nbufs(enp, ndescs);
36 efx_qword_t *dma_addr;
40 boolean_t want_outer_classes;
42 EFSYS_ASSERT3U(ndescs, <=, encp->enc_rxq_max_ndescs);
45 (EFSYS_MEM_SIZE(esmp) < efx_rxq_size(enp, ndescs))) {
51 dma_mode = MC_CMD_INIT_RXQ_EXT_IN_PACKED_STREAM;
52 else if (es_bufs_per_desc > 0)
53 dma_mode = MC_CMD_INIT_RXQ_V3_IN_EQUAL_STRIDE_SUPER_BUFFER;
55 dma_mode = MC_CMD_INIT_RXQ_EXT_IN_SINGLE_PACKET;
57 if (encp->enc_tunnel_encapsulations_supported != 0 &&
58 !want_inner_classes) {
60 * WANT_OUTER_CLASSES can only be specified on hardware which
61 * supports tunnel encapsulation offloads, even though it is
62 * effectively the behaviour the hardware gives.
64 * Also, on hardware which does support such offloads, older
65 * firmware rejects the flag if the offloads are not supported
66 * by the current firmware variant, which means this may fail if
67 * the capabilities are not updated when the firmware variant
68 * changes. This is not an issue on newer firmware, as it was
69 * changed in bug 69842 (v6.4.2.1007) to permit this flag to be
70 * specified on all firmware variants.
72 want_outer_classes = B_TRUE;
74 want_outer_classes = B_FALSE;
77 req.emr_cmd = MC_CMD_INIT_RXQ;
78 req.emr_in_buf = payload;
79 req.emr_in_length = MC_CMD_INIT_RXQ_V3_IN_LEN;
80 req.emr_out_buf = payload;
81 req.emr_out_length = MC_CMD_INIT_RXQ_V3_OUT_LEN;
83 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_SIZE, ndescs);
84 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_TARGET_EVQ, target_evq);
85 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_LABEL, label);
86 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_INSTANCE, instance);
87 MCDI_IN_POPULATE_DWORD_9(req, INIT_RXQ_EXT_IN_FLAGS,
88 INIT_RXQ_EXT_IN_FLAG_BUFF_MODE, 0,
89 INIT_RXQ_EXT_IN_FLAG_HDR_SPLIT, 0,
90 INIT_RXQ_EXT_IN_FLAG_TIMESTAMP, 0,
91 INIT_RXQ_EXT_IN_CRC_MODE, 0,
92 INIT_RXQ_EXT_IN_FLAG_PREFIX, 1,
93 INIT_RXQ_EXT_IN_FLAG_DISABLE_SCATTER, disable_scatter,
94 INIT_RXQ_EXT_IN_DMA_MODE,
96 INIT_RXQ_EXT_IN_PACKED_STREAM_BUFF_SIZE, ps_bufsize,
97 INIT_RXQ_EXT_IN_FLAG_WANT_OUTER_CLASSES, want_outer_classes);
98 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_OWNER_ID, 0);
99 MCDI_IN_SET_DWORD(req, INIT_RXQ_EXT_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
101 if (es_bufs_per_desc > 0) {
102 MCDI_IN_SET_DWORD(req,
103 INIT_RXQ_V3_IN_ES_PACKET_BUFFERS_PER_BUCKET,
105 MCDI_IN_SET_DWORD(req,
106 INIT_RXQ_V3_IN_ES_MAX_DMA_LEN, es_max_dma_len);
107 MCDI_IN_SET_DWORD(req,
108 INIT_RXQ_V3_IN_ES_PACKET_STRIDE, es_buf_stride);
109 MCDI_IN_SET_DWORD(req,
110 INIT_RXQ_V3_IN_ES_HEAD_OF_LINE_BLOCK_TIMEOUT,
114 dma_addr = MCDI_IN2(req, efx_qword_t, INIT_RXQ_IN_DMA_ADDR);
115 addr = EFSYS_MEM_ADDR(esmp);
117 for (i = 0; i < npages; i++) {
118 EFX_POPULATE_QWORD_2(*dma_addr,
119 EFX_DWORD_1, (uint32_t)(addr >> 32),
120 EFX_DWORD_0, (uint32_t)(addr & 0xffffffff));
123 addr += EFX_BUF_SIZE;
126 efx_mcdi_execute(enp, &req);
128 if (req.emr_rc != 0) {
138 EFSYS_PROBE1(fail1, efx_rc_t, rc);
143 static __checkReturn efx_rc_t
146 __in uint32_t instance)
149 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FINI_RXQ_IN_LEN,
150 MC_CMD_FINI_RXQ_OUT_LEN);
153 req.emr_cmd = MC_CMD_FINI_RXQ;
154 req.emr_in_buf = payload;
155 req.emr_in_length = MC_CMD_FINI_RXQ_IN_LEN;
156 req.emr_out_buf = payload;
157 req.emr_out_length = MC_CMD_FINI_RXQ_OUT_LEN;
159 MCDI_IN_SET_DWORD(req, FINI_RXQ_IN_INSTANCE, instance);
161 efx_mcdi_execute_quiet(enp, &req);
163 if (req.emr_rc != 0) {
172 * EALREADY is not an error, but indicates that the MC has rebooted and
173 * that the RXQ has already been destroyed.
176 EFSYS_PROBE1(fail1, efx_rc_t, rc);
181 #if EFSYS_OPT_RX_SCALE
182 static __checkReturn efx_rc_t
183 efx_mcdi_rss_context_alloc(
185 __in efx_rx_scale_context_type_t type,
186 __in uint32_t num_queues,
187 __out uint32_t *rss_contextp)
190 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN,
191 MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
192 uint32_t rss_context;
193 uint32_t context_type;
196 if (num_queues > EFX_MAXRSS) {
202 case EFX_RX_SCALE_EXCLUSIVE:
203 context_type = MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE;
205 case EFX_RX_SCALE_SHARED:
206 context_type = MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
213 req.emr_cmd = MC_CMD_RSS_CONTEXT_ALLOC;
214 req.emr_in_buf = payload;
215 req.emr_in_length = MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN;
216 req.emr_out_buf = payload;
217 req.emr_out_length = MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN;
219 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
220 EVB_PORT_ID_ASSIGNED);
221 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_ALLOC_IN_TYPE, context_type);
224 * For exclusive contexts, NUM_QUEUES is only used to validate
225 * indirection table offsets.
226 * For shared contexts, the provided context will spread traffic over
227 * NUM_QUEUES many queues.
229 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, num_queues);
231 efx_mcdi_execute(enp, &req);
233 if (req.emr_rc != 0) {
238 if (req.emr_out_length_used < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) {
243 rss_context = MCDI_OUT_DWORD(req, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
244 if (rss_context == EF10_RSS_CONTEXT_INVALID) {
249 *rss_contextp = rss_context;
262 EFSYS_PROBE1(fail1, efx_rc_t, rc);
266 #endif /* EFSYS_OPT_RX_SCALE */
268 #if EFSYS_OPT_RX_SCALE
270 efx_mcdi_rss_context_free(
272 __in uint32_t rss_context)
275 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_RSS_CONTEXT_FREE_IN_LEN,
276 MC_CMD_RSS_CONTEXT_FREE_OUT_LEN);
279 if (rss_context == EF10_RSS_CONTEXT_INVALID) {
284 req.emr_cmd = MC_CMD_RSS_CONTEXT_FREE;
285 req.emr_in_buf = payload;
286 req.emr_in_length = MC_CMD_RSS_CONTEXT_FREE_IN_LEN;
287 req.emr_out_buf = payload;
288 req.emr_out_length = MC_CMD_RSS_CONTEXT_FREE_OUT_LEN;
290 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, rss_context);
292 efx_mcdi_execute_quiet(enp, &req);
294 if (req.emr_rc != 0) {
304 EFSYS_PROBE1(fail1, efx_rc_t, rc);
308 #endif /* EFSYS_OPT_RX_SCALE */
310 #if EFSYS_OPT_RX_SCALE
312 efx_mcdi_rss_context_set_flags(
314 __in uint32_t rss_context,
315 __in efx_rx_hash_type_t type)
317 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
319 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN,
320 MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN);
323 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV4_TCP_LBN ==
324 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV4_RSS_MODE_LBN);
325 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV4_TCP_WIDTH ==
326 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV4_RSS_MODE_WIDTH);
327 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV4_LBN ==
328 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV4_RSS_MODE_LBN);
329 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV4_WIDTH ==
330 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV4_RSS_MODE_WIDTH);
331 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV6_TCP_LBN ==
332 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV6_RSS_MODE_LBN);
333 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV6_TCP_WIDTH ==
334 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV6_RSS_MODE_WIDTH);
335 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV6_LBN ==
336 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV6_RSS_MODE_LBN);
337 EFX_STATIC_ASSERT(EFX_RX_CLASS_IPV6_WIDTH ==
338 MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV6_RSS_MODE_WIDTH);
340 if (rss_context == EF10_RSS_CONTEXT_INVALID) {
345 req.emr_cmd = MC_CMD_RSS_CONTEXT_SET_FLAGS;
346 req.emr_in_buf = payload;
347 req.emr_in_length = MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN;
348 req.emr_out_buf = payload;
349 req.emr_out_length = MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN;
351 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID,
355 * If the firmware lacks support for additional modes, RSS_MODE
356 * fields must contain zeros, otherwise the operation will fail.
358 if (encp->enc_rx_scale_additional_modes_supported == B_FALSE)
359 type &= EFX_RX_HASH_LEGACY_MASK;
361 MCDI_IN_POPULATE_DWORD_10(req, RSS_CONTEXT_SET_FLAGS_IN_FLAGS,
362 RSS_CONTEXT_SET_FLAGS_IN_TOEPLITZ_IPV4_EN,
363 (type & EFX_RX_HASH_IPV4) ? 1 : 0,
364 RSS_CONTEXT_SET_FLAGS_IN_TOEPLITZ_TCPV4_EN,
365 (type & EFX_RX_HASH_TCPIPV4) ? 1 : 0,
366 RSS_CONTEXT_SET_FLAGS_IN_TOEPLITZ_IPV6_EN,
367 (type & EFX_RX_HASH_IPV6) ? 1 : 0,
368 RSS_CONTEXT_SET_FLAGS_IN_TOEPLITZ_TCPV6_EN,
369 (type & EFX_RX_HASH_TCPIPV6) ? 1 : 0,
370 RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV4_RSS_MODE,
371 (type >> EFX_RX_CLASS_IPV4_TCP_LBN) &
372 EFX_MASK32(EFX_RX_CLASS_IPV4_TCP),
373 RSS_CONTEXT_SET_FLAGS_IN_UDP_IPV4_RSS_MODE,
374 (type >> EFX_RX_CLASS_IPV4_UDP_LBN) &
375 EFX_MASK32(EFX_RX_CLASS_IPV4_UDP),
376 RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV4_RSS_MODE,
377 (type >> EFX_RX_CLASS_IPV4_LBN) & EFX_MASK32(EFX_RX_CLASS_IPV4),
378 RSS_CONTEXT_SET_FLAGS_IN_TCP_IPV6_RSS_MODE,
379 (type >> EFX_RX_CLASS_IPV6_TCP_LBN) &
380 EFX_MASK32(EFX_RX_CLASS_IPV6_TCP),
381 RSS_CONTEXT_SET_FLAGS_IN_UDP_IPV6_RSS_MODE,
382 (type >> EFX_RX_CLASS_IPV6_UDP_LBN) &
383 EFX_MASK32(EFX_RX_CLASS_IPV6_UDP),
384 RSS_CONTEXT_SET_FLAGS_IN_OTHER_IPV6_RSS_MODE,
385 (type >> EFX_RX_CLASS_IPV6_LBN) & EFX_MASK32(EFX_RX_CLASS_IPV6));
387 efx_mcdi_execute(enp, &req);
389 if (req.emr_rc != 0) {
399 EFSYS_PROBE1(fail1, efx_rc_t, rc);
403 #endif /* EFSYS_OPT_RX_SCALE */
405 #if EFSYS_OPT_RX_SCALE
407 efx_mcdi_rss_context_set_key(
409 __in uint32_t rss_context,
410 __in_ecount(n) uint8_t *key,
414 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN,
415 MC_CMD_RSS_CONTEXT_SET_KEY_OUT_LEN);
418 if (rss_context == EF10_RSS_CONTEXT_INVALID) {
423 req.emr_cmd = MC_CMD_RSS_CONTEXT_SET_KEY;
424 req.emr_in_buf = payload;
425 req.emr_in_length = MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN;
426 req.emr_out_buf = payload;
427 req.emr_out_length = MC_CMD_RSS_CONTEXT_SET_KEY_OUT_LEN;
429 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
432 EFSYS_ASSERT3U(n, ==, MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
433 if (n != MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN) {
438 memcpy(MCDI_IN2(req, uint8_t, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY),
441 efx_mcdi_execute(enp, &req);
443 if (req.emr_rc != 0) {
455 EFSYS_PROBE1(fail1, efx_rc_t, rc);
459 #endif /* EFSYS_OPT_RX_SCALE */
461 #if EFSYS_OPT_RX_SCALE
463 efx_mcdi_rss_context_set_table(
465 __in uint32_t rss_context,
466 __in_ecount(n) unsigned int *table,
470 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN,
471 MC_CMD_RSS_CONTEXT_SET_TABLE_OUT_LEN);
475 if (rss_context == EF10_RSS_CONTEXT_INVALID) {
480 req.emr_cmd = MC_CMD_RSS_CONTEXT_SET_TABLE;
481 req.emr_in_buf = payload;
482 req.emr_in_length = MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN;
483 req.emr_out_buf = payload;
484 req.emr_out_length = MC_CMD_RSS_CONTEXT_SET_TABLE_OUT_LEN;
486 MCDI_IN_SET_DWORD(req, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
490 MCDI_IN2(req, uint8_t, RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE);
493 i < MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN;
495 req_table[i] = (n > 0) ? (uint8_t)table[i % n] : 0;
498 efx_mcdi_execute(enp, &req);
500 if (req.emr_rc != 0) {
510 EFSYS_PROBE1(fail1, efx_rc_t, rc);
514 #endif /* EFSYS_OPT_RX_SCALE */
517 __checkReturn efx_rc_t
521 #if EFSYS_OPT_RX_SCALE
523 if (efx_mcdi_rss_context_alloc(enp, EFX_RX_SCALE_EXCLUSIVE, EFX_MAXRSS,
524 &enp->en_rss_context) == 0) {
526 * Allocated an exclusive RSS context, which allows both the
527 * indirection table and key to be modified.
529 enp->en_rss_context_type = EFX_RX_SCALE_EXCLUSIVE;
530 enp->en_hash_support = EFX_RX_HASH_AVAILABLE;
533 * Failed to allocate an exclusive RSS context. Continue
534 * operation without support for RSS. The pseudo-header in
535 * received packets will not contain a Toeplitz hash value.
537 enp->en_rss_context_type = EFX_RX_SCALE_UNAVAILABLE;
538 enp->en_hash_support = EFX_RX_HASH_UNAVAILABLE;
541 #endif /* EFSYS_OPT_RX_SCALE */
546 #if EFSYS_OPT_RX_SCATTER
547 __checkReturn efx_rc_t
548 ef10_rx_scatter_enable(
550 __in unsigned int buf_size)
552 _NOTE(ARGUNUSED(enp, buf_size))
555 #endif /* EFSYS_OPT_RX_SCATTER */
557 #if EFSYS_OPT_RX_SCALE
558 __checkReturn efx_rc_t
559 ef10_rx_scale_context_alloc(
561 __in efx_rx_scale_context_type_t type,
562 __in uint32_t num_queues,
563 __out uint32_t *rss_contextp)
567 rc = efx_mcdi_rss_context_alloc(enp, type, num_queues, rss_contextp);
574 EFSYS_PROBE1(fail1, efx_rc_t, rc);
577 #endif /* EFSYS_OPT_RX_SCALE */
579 #if EFSYS_OPT_RX_SCALE
580 __checkReturn efx_rc_t
581 ef10_rx_scale_context_free(
583 __in uint32_t rss_context)
587 rc = efx_mcdi_rss_context_free(enp, rss_context);
594 EFSYS_PROBE1(fail1, efx_rc_t, rc);
597 #endif /* EFSYS_OPT_RX_SCALE */
599 #if EFSYS_OPT_RX_SCALE
600 __checkReturn efx_rc_t
601 ef10_rx_scale_mode_set(
603 __in uint32_t rss_context,
604 __in efx_rx_hash_alg_t alg,
605 __in efx_rx_hash_type_t type,
606 __in boolean_t insert)
608 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
611 EFSYS_ASSERT3U(insert, ==, B_TRUE);
613 if ((encp->enc_rx_scale_hash_alg_mask & (1U << alg)) == 0 ||
619 if (rss_context == EFX_RSS_CONTEXT_DEFAULT) {
620 if (enp->en_rss_context_type == EFX_RX_SCALE_UNAVAILABLE) {
624 rss_context = enp->en_rss_context;
627 if ((rc = efx_mcdi_rss_context_set_flags(enp,
628 rss_context, type)) != 0)
638 EFSYS_PROBE1(fail1, efx_rc_t, rc);
642 #endif /* EFSYS_OPT_RX_SCALE */
644 #if EFSYS_OPT_RX_SCALE
645 __checkReturn efx_rc_t
646 ef10_rx_scale_key_set(
648 __in uint32_t rss_context,
649 __in_ecount(n) uint8_t *key,
654 EFX_STATIC_ASSERT(EFX_RSS_KEY_SIZE ==
655 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
657 if (rss_context == EFX_RSS_CONTEXT_DEFAULT) {
658 if (enp->en_rss_context_type == EFX_RX_SCALE_UNAVAILABLE) {
662 rss_context = enp->en_rss_context;
665 if ((rc = efx_mcdi_rss_context_set_key(enp, rss_context, key, n)) != 0)
673 EFSYS_PROBE1(fail1, efx_rc_t, rc);
677 #endif /* EFSYS_OPT_RX_SCALE */
679 #if EFSYS_OPT_RX_SCALE
680 __checkReturn efx_rc_t
681 ef10_rx_scale_tbl_set(
683 __in uint32_t rss_context,
684 __in_ecount(n) unsigned int *table,
690 if (rss_context == EFX_RSS_CONTEXT_DEFAULT) {
691 if (enp->en_rss_context_type == EFX_RX_SCALE_UNAVAILABLE) {
695 rss_context = enp->en_rss_context;
698 if ((rc = efx_mcdi_rss_context_set_table(enp,
699 rss_context, table, n)) != 0)
707 EFSYS_PROBE1(fail1, efx_rc_t, rc);
711 #endif /* EFSYS_OPT_RX_SCALE */
715 * EF10 RX pseudo-header
716 * ---------------------
718 * Receive packets are prefixed by an (optional) 14 byte pseudo-header:
720 * +00: Toeplitz hash value.
721 * (32bit little-endian)
722 * +04: Outer VLAN tag. Zero if the packet did not have an outer VLAN tag.
724 * +06: Inner VLAN tag. Zero if the packet did not have an inner VLAN tag.
726 * +08: Packet Length. Zero if the RX datapath was in cut-through mode.
727 * (16bit little-endian)
728 * +10: MAC timestamp. Zero if timestamping is not enabled.
729 * (32bit little-endian)
731 * See "The RX Pseudo-header" in SF-109306-TC.
734 __checkReturn efx_rc_t
735 ef10_rx_prefix_pktlen(
737 __in uint8_t *buffer,
738 __out uint16_t *lengthp)
740 _NOTE(ARGUNUSED(enp))
743 * The RX pseudo-header contains the packet length, excluding the
744 * pseudo-header. If the hardware receive datapath was operating in
745 * cut-through mode then the length in the RX pseudo-header will be
746 * zero, and the packet length must be obtained from the DMA length
747 * reported in the RX event.
749 *lengthp = buffer[8] | (buffer[9] << 8);
753 #if EFSYS_OPT_RX_SCALE
754 __checkReturn uint32_t
757 __in efx_rx_hash_alg_t func,
758 __in uint8_t *buffer)
760 _NOTE(ARGUNUSED(enp))
763 case EFX_RX_HASHALG_PACKED_STREAM:
764 case EFX_RX_HASHALG_TOEPLITZ:
775 #endif /* EFSYS_OPT_RX_SCALE */
777 #if EFSYS_OPT_RX_PACKED_STREAM
779 * Fake length for RXQ descriptors in packed stream mode
780 * to make hardware happy
782 #define EFX_RXQ_PACKED_STREAM_FAKE_BUF_SIZE 32
788 __in_ecount(ndescs) efsys_dma_addr_t *addrp,
790 __in unsigned int ndescs,
791 __in unsigned int completed,
792 __in unsigned int added)
799 _NOTE(ARGUNUSED(completed))
801 #if EFSYS_OPT_RX_PACKED_STREAM
803 * Real size of the buffer does not fit into ESF_DZ_RX_KER_BYTE_CNT
804 * and equal to 0 after applying mask. Hardware does not like it.
806 if (erp->er_ev_qstate->eers_rx_packed_stream)
807 size = EFX_RXQ_PACKED_STREAM_FAKE_BUF_SIZE;
810 /* The client driver must not overfill the queue */
811 EFSYS_ASSERT3U(added - completed + ndescs, <=,
812 EFX_RXQ_LIMIT(erp->er_mask + 1));
814 id = added & (erp->er_mask);
815 for (i = 0; i < ndescs; i++) {
816 EFSYS_PROBE4(rx_post, unsigned int, erp->er_index,
817 unsigned int, id, efsys_dma_addr_t, addrp[i],
820 EFX_POPULATE_QWORD_3(qword,
821 ESF_DZ_RX_KER_BYTE_CNT, (uint32_t)(size),
822 ESF_DZ_RX_KER_BUF_ADDR_DW0,
823 (uint32_t)(addrp[i] & 0xffffffff),
824 ESF_DZ_RX_KER_BUF_ADDR_DW1,
825 (uint32_t)(addrp[i] >> 32));
827 offset = id * sizeof (efx_qword_t);
828 EFSYS_MEM_WRITEQ(erp->er_esmp, offset, &qword);
830 id = (id + 1) & (erp->er_mask);
837 __in unsigned int added,
838 __inout unsigned int *pushedp)
840 efx_nic_t *enp = erp->er_enp;
841 unsigned int pushed = *pushedp;
845 /* Hardware has alignment restriction for WPTR */
846 wptr = P2ALIGN(added, EF10_RX_WPTR_ALIGN);
852 /* Push the populated descriptors out */
853 wptr &= erp->er_mask;
855 EFX_POPULATE_DWORD_1(dword, ERF_DZ_RX_DESC_WPTR, wptr);
857 /* Guarantee ordering of memory (descriptors) and PIO (doorbell) */
858 EFX_DMA_SYNC_QUEUE_FOR_DEVICE(erp->er_esmp, erp->er_mask + 1,
859 wptr, pushed & erp->er_mask);
860 EFSYS_PIO_WRITE_BARRIER();
861 EFX_BAR_VI_WRITED(enp, ER_DZ_RX_DESC_UPD_REG,
862 erp->er_index, &dword, B_FALSE);
865 #if EFSYS_OPT_RX_PACKED_STREAM
868 ef10_rx_qpush_ps_credits(
871 efx_nic_t *enp = erp->er_enp;
873 efx_evq_rxq_state_t *rxq_state = erp->er_ev_qstate;
876 EFSYS_ASSERT(rxq_state->eers_rx_packed_stream);
878 if (rxq_state->eers_rx_packed_stream_credits == 0)
882 * It is a bug if we think that FW has utilized more
883 * credits than it is allowed to have (maximum). However,
884 * make sure that we do not credit more than maximum anyway.
886 credits = MIN(rxq_state->eers_rx_packed_stream_credits,
887 EFX_RX_PACKED_STREAM_MAX_CREDITS);
888 EFX_POPULATE_DWORD_3(dword,
889 ERF_DZ_RX_DESC_MAGIC_DOORBELL, 1,
890 ERF_DZ_RX_DESC_MAGIC_CMD,
891 ERE_DZ_RX_DESC_MAGIC_CMD_PS_CREDITS,
892 ERF_DZ_RX_DESC_MAGIC_DATA, credits);
893 EFX_BAR_VI_WRITED(enp, ER_DZ_RX_DESC_UPD_REG,
894 erp->er_index, &dword, B_FALSE);
896 rxq_state->eers_rx_packed_stream_credits = 0;
900 * In accordance with SF-112241-TC the received data has the following layout:
901 * - 8 byte pseudo-header which consist of:
902 * - 4 byte little-endian timestamp
903 * - 2 byte little-endian captured length in bytes
904 * - 2 byte little-endian original packet length in bytes
905 * - captured packet bytes
906 * - optional padding to align to 64 bytes boundary
907 * - 64 bytes scratch space for the host software
909 __checkReturn uint8_t *
910 ef10_rx_qps_packet_info(
912 __in uint8_t *buffer,
913 __in uint32_t buffer_length,
914 __in uint32_t current_offset,
915 __out uint16_t *lengthp,
916 __out uint32_t *next_offsetp,
917 __out uint32_t *timestamp)
922 efx_evq_rxq_state_t *rxq_state = erp->er_ev_qstate;
924 EFSYS_ASSERT(rxq_state->eers_rx_packed_stream);
926 buffer += current_offset;
927 pkt_start = buffer + EFX_RX_PACKED_STREAM_RX_PREFIX_SIZE;
929 qwordp = (efx_qword_t *)buffer;
930 *timestamp = EFX_QWORD_FIELD(*qwordp, ES_DZ_PS_RX_PREFIX_TSTAMP);
931 *lengthp = EFX_QWORD_FIELD(*qwordp, ES_DZ_PS_RX_PREFIX_ORIG_LEN);
932 buf_len = EFX_QWORD_FIELD(*qwordp, ES_DZ_PS_RX_PREFIX_CAP_LEN);
934 buf_len = P2ROUNDUP(buf_len + EFX_RX_PACKED_STREAM_RX_PREFIX_SIZE,
935 EFX_RX_PACKED_STREAM_ALIGNMENT);
937 current_offset + buf_len + EFX_RX_PACKED_STREAM_ALIGNMENT;
939 EFSYS_ASSERT3U(*next_offsetp, <=, buffer_length);
940 EFSYS_ASSERT3U(current_offset + *lengthp, <, *next_offsetp);
942 if ((*next_offsetp ^ current_offset) &
943 EFX_RX_PACKED_STREAM_MEM_PER_CREDIT)
944 rxq_state->eers_rx_packed_stream_credits++;
952 __checkReturn efx_rc_t
956 efx_nic_t *enp = erp->er_enp;
959 if ((rc = efx_mcdi_fini_rxq(enp, erp->er_index)) != 0)
966 * EALREADY is not an error, but indicates that the MC has rebooted and
967 * that the RXQ has already been destroyed. Callers need to know that
968 * the RXQ flush has completed to avoid waiting until timeout for a
969 * flush done event that will not be delivered.
972 EFSYS_PROBE1(fail1, efx_rc_t, rc);
982 _NOTE(ARGUNUSED(erp))
986 __checkReturn efx_rc_t
989 __in unsigned int index,
990 __in unsigned int label,
991 __in efx_rxq_type_t type,
992 __in_opt const efx_rxq_type_data_t *type_data,
993 __in efsys_mem_t *esmp,
996 __in unsigned int flags,
1000 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1002 boolean_t disable_scatter;
1003 boolean_t want_inner_classes;
1004 unsigned int ps_buf_size;
1005 uint32_t es_bufs_per_desc = 0;
1006 uint32_t es_max_dma_len = 0;
1007 uint32_t es_buf_stride = 0;
1008 uint32_t hol_block_timeout = 0;
1010 _NOTE(ARGUNUSED(id, erp, type_data))
1012 EFX_STATIC_ASSERT(EFX_EV_RX_NLABELS == (1 << ESF_DZ_RX_QLABEL_WIDTH));
1013 EFSYS_ASSERT3U(label, <, EFX_EV_RX_NLABELS);
1014 EFSYS_ASSERT3U(enp->en_rx_qcount + 1, <, encp->enc_rxq_limit);
1016 if (index >= encp->enc_rxq_limit) {
1022 case EFX_RXQ_TYPE_DEFAULT:
1025 #if EFSYS_OPT_RX_PACKED_STREAM
1026 case EFX_RXQ_TYPE_PACKED_STREAM:
1027 if (type_data == NULL) {
1031 switch (type_data->ertd_packed_stream.eps_buf_size) {
1032 case EFX_RXQ_PACKED_STREAM_BUF_SIZE_1M:
1033 ps_buf_size = MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_1M;
1035 case EFX_RXQ_PACKED_STREAM_BUF_SIZE_512K:
1036 ps_buf_size = MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_512K;
1038 case EFX_RXQ_PACKED_STREAM_BUF_SIZE_256K:
1039 ps_buf_size = MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_256K;
1041 case EFX_RXQ_PACKED_STREAM_BUF_SIZE_128K:
1042 ps_buf_size = MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_128K;
1044 case EFX_RXQ_PACKED_STREAM_BUF_SIZE_64K:
1045 ps_buf_size = MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_64K;
1052 #endif /* EFSYS_OPT_RX_PACKED_STREAM */
1053 #if EFSYS_OPT_RX_ES_SUPER_BUFFER
1054 case EFX_RXQ_TYPE_ES_SUPER_BUFFER:
1055 if (type_data == NULL) {
1061 type_data->ertd_es_super_buffer.eessb_bufs_per_desc;
1063 type_data->ertd_es_super_buffer.eessb_max_dma_len;
1065 type_data->ertd_es_super_buffer.eessb_buf_stride;
1067 type_data->ertd_es_super_buffer.eessb_hol_block_timeout;
1069 #endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
1075 #if EFSYS_OPT_RX_PACKED_STREAM
1076 if (ps_buf_size != 0) {
1077 /* Check if datapath firmware supports packed stream mode */
1078 if (encp->enc_rx_packed_stream_supported == B_FALSE) {
1082 /* Check if packed stream allows configurable buffer sizes */
1083 if ((ps_buf_size != MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_1M) &&
1084 (encp->enc_rx_var_packed_stream_supported == B_FALSE)) {
1089 #else /* EFSYS_OPT_RX_PACKED_STREAM */
1090 EFSYS_ASSERT(ps_buf_size == 0);
1091 #endif /* EFSYS_OPT_RX_PACKED_STREAM */
1093 #if EFSYS_OPT_RX_ES_SUPER_BUFFER
1094 if (es_bufs_per_desc > 0) {
1095 if (encp->enc_rx_es_super_buffer_supported == B_FALSE) {
1099 if (!IS_P2ALIGNED(es_max_dma_len,
1100 EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
1104 if (!IS_P2ALIGNED(es_buf_stride,
1105 EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
1110 #else /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
1111 EFSYS_ASSERT(es_bufs_per_desc == 0);
1112 #endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
1114 /* Scatter can only be disabled if the firmware supports doing so */
1115 if (flags & EFX_RXQ_FLAG_SCATTER)
1116 disable_scatter = B_FALSE;
1118 disable_scatter = encp->enc_rx_disable_scatter_supported;
1120 if (flags & EFX_RXQ_FLAG_INNER_CLASSES)
1121 want_inner_classes = B_TRUE;
1123 want_inner_classes = B_FALSE;
1125 if ((rc = efx_mcdi_init_rxq(enp, ndescs, eep->ee_index, label, index,
1126 esmp, disable_scatter, want_inner_classes,
1127 ps_buf_size, es_bufs_per_desc, es_max_dma_len,
1128 es_buf_stride, hol_block_timeout)) != 0)
1132 erp->er_label = label;
1134 ef10_ev_rxlabel_init(eep, erp, label, type);
1136 erp->er_ev_qstate = &erp->er_eep->ee_rxq_state[label];
1141 EFSYS_PROBE(fail11);
1142 #if EFSYS_OPT_RX_ES_SUPER_BUFFER
1144 EFSYS_PROBE(fail10);
1149 #endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
1150 #if EFSYS_OPT_RX_PACKED_STREAM
1155 #endif /* EFSYS_OPT_RX_PACKED_STREAM */
1158 #if EFSYS_OPT_RX_ES_SUPER_BUFFER
1161 #endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
1162 #if EFSYS_OPT_RX_PACKED_STREAM
1167 #endif /* EFSYS_OPT_RX_PACKED_STREAM */
1169 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1176 __in efx_rxq_t *erp)
1178 efx_nic_t *enp = erp->er_enp;
1179 efx_evq_t *eep = erp->er_eep;
1180 unsigned int label = erp->er_label;
1182 ef10_ev_rxlabel_fini(eep, label);
1184 EFSYS_ASSERT(enp->en_rx_qcount != 0);
1185 --enp->en_rx_qcount;
1187 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_rxq_t), erp);
1192 __in efx_nic_t *enp)
1194 #if EFSYS_OPT_RX_SCALE
1195 if (enp->en_rss_context_type != EFX_RX_SCALE_UNAVAILABLE)
1196 (void) efx_mcdi_rss_context_free(enp, enp->en_rss_context);
1197 enp->en_rss_context = 0;
1198 enp->en_rss_context_type = EFX_RX_SCALE_UNAVAILABLE;
1200 _NOTE(ARGUNUSED(enp))
1201 #endif /* EFSYS_OPT_RX_SCALE */
1204 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */