2 * Copyright (c) 2007, 2014 Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/mlx4/cq.h>
35 #include <linux/slab.h>
36 #include <linux/mlx4/qp.h>
37 #include <linux/if_ether.h>
38 #include <linux/if_vlan.h>
39 #include <linux/vmalloc.h>
40 #include <linux/mlx4/driver.h>
41 #ifdef CONFIG_NET_RX_BUSY_POLL
42 #include <net/busy_poll.h>
48 static void mlx4_en_init_rx_desc(struct mlx4_en_priv *priv,
49 struct mlx4_en_rx_ring *ring,
52 struct mlx4_en_rx_desc *rx_desc = ring->buf + ring->stride * index;
57 /* Set size and memtype fields */
58 for (i = 0; i < priv->num_frags; i++) {
59 rx_desc->data[i].byte_count =
60 cpu_to_be32(priv->frag_info[i].frag_size);
61 rx_desc->data[i].lkey = cpu_to_be32(priv->mdev->mr.key);
64 /* If the number of used fragments does not fill up the ring stride,
65 * * remaining (unused) fragments must be padded with null address/size
66 * * and a special memory key */
67 possible_frags = (ring->stride - sizeof(struct mlx4_en_rx_desc)) / DS_SIZE;
68 for (i = priv->num_frags; i < possible_frags; i++) {
69 rx_desc->data[i].byte_count = 0;
70 rx_desc->data[i].lkey = cpu_to_be32(MLX4_EN_MEMTYPE_PAD);
71 rx_desc->data[i].addr = 0;
76 static int mlx4_en_alloc_buf(struct mlx4_en_priv *priv,
77 struct mlx4_en_rx_desc *rx_desc,
78 struct mbuf **mb_list,
81 struct mlx4_en_dev *mdev = priv->mdev;
82 struct mlx4_en_frag_info *frag_info = &priv->frag_info[i];
87 mb = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, frag_info->frag_size);
89 mb = m_getjcl(M_NOWAIT, MT_DATA, 0, frag_info->frag_size);
91 priv->port_stats.rx_alloc_failed++;
94 dma = pci_map_single(mdev->pdev, mb->m_data, frag_info->frag_size,
96 rx_desc->data[i].addr = cpu_to_be64(dma);
102 static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,
103 struct mlx4_en_rx_ring *ring, int index)
105 struct mlx4_en_rx_desc *rx_desc = ring->buf + (index * ring->stride);
106 struct mbuf **mb_list = ring->rx_info + (index << priv->log_rx_info);
109 for (i = 0; i < priv->num_frags; i++)
110 if (mlx4_en_alloc_buf(priv, rx_desc, mb_list, i))
121 static inline void mlx4_en_update_rx_prod_db(struct mlx4_en_rx_ring *ring)
123 *ring->wqres.db.db = cpu_to_be32(ring->prod & 0xffff);
126 static void mlx4_en_free_rx_desc(struct mlx4_en_priv *priv,
127 struct mlx4_en_rx_ring *ring,
130 struct mlx4_en_frag_info *frag_info;
131 struct mlx4_en_dev *mdev = priv->mdev;
132 struct mbuf **mb_list;
133 struct mlx4_en_rx_desc *rx_desc = ring->buf + (index << ring->log_stride);
137 mb_list = ring->rx_info + (index << priv->log_rx_info);
138 for (nr = 0; nr < priv->num_frags; nr++) {
139 en_dbg(DRV, priv, "Freeing fragment:%d\n", nr);
140 frag_info = &priv->frag_info[nr];
141 dma = be64_to_cpu(rx_desc->data[nr].addr);
143 #if BITS_PER_LONG == 64
144 en_dbg(DRV, priv, "Unmaping buffer at dma:0x%lx\n", (u64) dma);
145 #elif BITS_PER_LONG == 32
146 en_dbg(DRV, priv, "Unmaping buffer at dma:0x%llx\n", (u64) dma);
148 pci_unmap_single(mdev->pdev, dma, frag_info->frag_size,
154 static int mlx4_en_fill_rx_buffers(struct mlx4_en_priv *priv)
156 struct mlx4_en_rx_ring *ring;
162 for (buf_ind = 0; buf_ind < priv->prof->rx_ring_size; buf_ind++) {
163 for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) {
164 ring = priv->rx_ring[ring_ind];
166 err = mlx4_en_prepare_rx_desc(priv, ring,
169 if (ring->actual_size == 0) {
170 en_err(priv, "Failed to allocate "
171 "enough rx buffers\n");
175 rounddown_pow_of_two(ring->actual_size);
176 en_warn(priv, "Only %d buffers allocated "
177 "reducing ring size to %d\n",
178 ring->actual_size, new_size);
189 for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) {
190 ring = priv->rx_ring[ring_ind];
191 while (ring->actual_size > new_size) {
194 mlx4_en_free_rx_desc(priv, ring, ring->actual_size);
201 static void mlx4_en_free_rx_buf(struct mlx4_en_priv *priv,
202 struct mlx4_en_rx_ring *ring)
206 en_dbg(DRV, priv, "Freeing Rx buf - cons:%d prod:%d\n",
207 ring->cons, ring->prod);
209 /* Unmap and free Rx buffers */
210 BUG_ON((u32) (ring->prod - ring->cons) > ring->actual_size);
211 while (ring->cons != ring->prod) {
212 index = ring->cons & ring->size_mask;
213 en_dbg(DRV, priv, "Processing descriptor:%d\n", index);
214 mlx4_en_free_rx_desc(priv, ring, index);
219 #if MLX4_EN_MAX_RX_FRAGS == 3
220 static int frag_sizes[] = {
225 #elif MLX4_EN_MAX_RX_FRAGS == 2
226 static int frag_sizes[] = {
231 #error "Unknown MAX_RX_FRAGS"
234 void mlx4_en_calc_rx_buf(struct net_device *dev)
236 struct mlx4_en_priv *priv = netdev_priv(dev);
237 int eff_mtu = dev->if_mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
241 for (i = 0, frag = 0; buf_size < eff_mtu; frag++, i++) {
243 * Allocate small to large but only as much as is needed for
246 while (i > 0 && eff_mtu - buf_size <= frag_sizes[i - 1])
248 priv->frag_info[frag].frag_size = frag_sizes[i];
249 priv->frag_info[frag].frag_prefix_size = buf_size;
250 buf_size += priv->frag_info[frag].frag_size;
253 priv->num_frags = frag;
254 priv->rx_mb_size = eff_mtu;
256 ROUNDUP_LOG2(priv->num_frags * sizeof(struct mbuf *));
258 en_dbg(DRV, priv, "Rx buffer scatter-list (effective-mtu:%d "
259 "num_frags:%d):\n", eff_mtu, priv->num_frags);
260 for (i = 0; i < priv->num_frags; i++) {
261 en_dbg(DRV, priv, " frag:%d - size:%d prefix:%d\n", i,
262 priv->frag_info[i].frag_size,
263 priv->frag_info[i].frag_prefix_size);
268 int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
269 struct mlx4_en_rx_ring **pring,
272 struct mlx4_en_dev *mdev = priv->mdev;
273 struct mlx4_en_rx_ring *ring;
277 ring = kzalloc(sizeof(struct mlx4_en_rx_ring), GFP_KERNEL);
279 en_err(priv, "Failed to allocate RX ring structure\n");
286 ring->size_mask = size - 1;
287 ring->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
288 DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
289 ring->log_stride = ffs(ring->stride) - 1;
290 ring->buf_size = ring->size * ring->stride + TXBB_SIZE;
292 tmp = size * roundup_pow_of_two(MLX4_EN_MAX_RX_FRAGS *
293 sizeof(struct mbuf *));
295 ring->rx_info = kmalloc(tmp, GFP_KERNEL);
296 if (!ring->rx_info) {
301 en_dbg(DRV, priv, "Allocated rx_info ring at addr:%p size:%d\n",
304 err = mlx4_alloc_hwq_res(mdev->dev, &ring->wqres,
305 ring->buf_size, 2 * PAGE_SIZE);
309 err = mlx4_en_map_buffer(&ring->wqres.buf);
311 en_err(priv, "Failed to map RX buffer\n");
314 ring->buf = ring->wqres.buf.direct.buf;
319 mlx4_free_hwq_res(mdev->dev, &ring->wqres, ring->buf_size);
321 vfree(ring->rx_info);
329 int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv)
331 struct mlx4_en_rx_ring *ring;
335 int stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
336 DS_SIZE * priv->num_frags);
338 for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) {
339 ring = priv->rx_ring[ring_ind];
343 ring->actual_size = 0;
344 ring->cqn = priv->rx_cq[ring_ind]->mcq.cqn;
345 ring->rx_alloc_order = priv->rx_alloc_order;
346 ring->rx_alloc_size = priv->rx_alloc_size;
347 ring->rx_buf_size = priv->rx_buf_size;
348 ring->rx_mb_size = priv->rx_mb_size;
350 ring->stride = stride;
351 if (ring->stride <= TXBB_SIZE)
352 ring->buf += TXBB_SIZE;
354 ring->log_stride = ffs(ring->stride) - 1;
355 ring->buf_size = ring->size * ring->stride;
357 memset(ring->buf, 0, ring->buf_size);
358 mlx4_en_update_rx_prod_db(ring);
360 /* Initialize all descriptors */
361 for (i = 0; i < ring->size; i++)
362 mlx4_en_init_rx_desc(priv, ring, i);
365 /* Configure lro mngr */
366 if (priv->dev->if_capenable & IFCAP_LRO) {
367 if (tcp_lro_init(&ring->lro))
368 priv->dev->if_capenable &= ~IFCAP_LRO;
370 ring->lro.ifp = priv->dev;
376 err = mlx4_en_fill_rx_buffers(priv);
380 for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) {
381 ring = priv->rx_ring[ring_ind];
383 ring->size_mask = ring->actual_size - 1;
384 mlx4_en_update_rx_prod_db(ring);
390 for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++)
391 mlx4_en_free_rx_buf(priv, priv->rx_ring[ring_ind]);
393 ring_ind = priv->rx_ring_num - 1;
395 while (ring_ind >= 0) {
396 ring = priv->rx_ring[ring_ind];
397 if (ring->stride <= TXBB_SIZE)
398 ring->buf -= TXBB_SIZE;
406 void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
407 struct mlx4_en_rx_ring **pring,
408 u32 size, u16 stride)
410 struct mlx4_en_dev *mdev = priv->mdev;
411 struct mlx4_en_rx_ring *ring = *pring;
413 mlx4_en_unmap_buffer(&ring->wqres.buf);
414 mlx4_free_hwq_res(mdev->dev, &ring->wqres, size * stride + TXBB_SIZE);
415 vfree(ring->rx_info);
418 #ifdef CONFIG_RFS_ACCEL
419 mlx4_en_cleanup_filters(priv, ring);
424 void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
425 struct mlx4_en_rx_ring *ring)
428 tcp_lro_free(&ring->lro);
430 mlx4_en_free_rx_buf(priv, ring);
431 if (ring->stride <= TXBB_SIZE)
432 ring->buf -= TXBB_SIZE;
436 static void validate_loopback(struct mlx4_en_priv *priv, struct mbuf *mb)
439 int offset = ETHER_HDR_LEN;
441 for (i = 0; i < MLX4_LOOPBACK_TEST_PAYLOAD; i++, offset++) {
442 if (*(mb->m_data + offset) != (unsigned char) (i & 0xff))
446 priv->loopback_ok = 1;
453 static inline int invalid_cqe(struct mlx4_en_priv *priv,
454 struct mlx4_cqe *cqe)
456 /* Drop packet on bad receive or bad checksum */
457 if (unlikely((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) ==
458 MLX4_CQE_OPCODE_ERROR)) {
459 en_err(priv, "CQE completed in error - vendor syndrom:%d syndrom:%d\n",
460 ((struct mlx4_err_cqe *)cqe)->vendor_err_syndrome,
461 ((struct mlx4_err_cqe *)cqe)->syndrome);
464 if (unlikely(cqe->badfcs_enc & MLX4_CQE_BAD_FCS)) {
465 en_dbg(RX_ERR, priv, "Accepted frame with bad FCS\n");
473 /* Unmap a completed descriptor and free unused pages */
474 static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv,
475 struct mlx4_en_rx_desc *rx_desc,
476 struct mbuf **mb_list,
479 struct mlx4_en_dev *mdev = priv->mdev;
480 struct mlx4_en_frag_info *frag_info;
486 mb->m_pkthdr.len = length;
487 /* Collect used fragments while replacing them in the HW descirptors */
488 for (nr = 0; nr < priv->num_frags; nr++) {
489 frag_info = &priv->frag_info[nr];
490 if (length <= frag_info->frag_prefix_size)
493 mb->m_next = mb_list[nr];
495 mb->m_len = frag_info->frag_size;
496 dma = be64_to_cpu(rx_desc->data[nr].addr);
498 /* Allocate a replacement page */
499 if (mlx4_en_alloc_buf(priv, rx_desc, mb_list, nr))
503 pci_unmap_single(mdev->pdev, dma, frag_info->frag_size,
506 /* Adjust size of last fragment to match actual length */
507 mb->m_len = length - priv->frag_info[nr - 1].frag_prefix_size;
512 /* Drop all accumulated fragments (which have already been replaced in
513 * the descriptor) of this packet; remaining fragments are reused... */
522 static struct mbuf *mlx4_en_rx_mb(struct mlx4_en_priv *priv,
523 struct mlx4_en_rx_desc *rx_desc,
524 struct mbuf **mb_list,
530 /* Move relevant fragments to mb */
531 if (unlikely(mlx4_en_complete_rx_desc(priv, rx_desc, mb_list, length)))
537 /* For cpu arch with cache line of 64B the performance is better when cqe size==64B
538 * To enlarge cqe size from 32B to 64B --> 32B of garbage (i.e. 0xccccccc)
539 * was added in the beginning of each cqe (the real data is in the corresponding 32B).
540 * The following calc ensures that when factor==1, it means we are alligned to 64B
541 * and we get the real cqe data*/
542 #define CQE_FACTOR_INDEX(index, factor) ((index << factor) + factor)
543 int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budget)
545 struct mlx4_en_priv *priv = netdev_priv(dev);
546 struct mlx4_cqe *cqe;
547 struct mlx4_en_rx_ring *ring = priv->rx_ring[cq->ring];
548 struct mbuf **mb_list;
549 struct mlx4_en_rx_desc *rx_desc;
551 struct mlx4_cq *mcq = &cq->mcq;
552 struct mlx4_cqe *buf = cq->buf;
554 struct lro_entry *queued;
559 u32 cons_index = mcq->cons_index;
560 u32 size_mask = ring->size_mask;
562 int factor = priv->cqe_factor;
567 /* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx
568 * descriptor offset can be deducted from the CQE index instead of
569 * reading 'cqe->index' */
570 index = cons_index & size_mask;
571 cqe = &buf[CQE_FACTOR_INDEX(index, factor)];
573 /* Process all completed CQEs */
574 while (XNOR(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK,
575 cons_index & size)) {
576 mb_list = ring->rx_info + (index << priv->log_rx_info);
577 rx_desc = ring->buf + (index << ring->log_stride);
580 * make sure we read the CQE after we read the ownership bit
584 if (invalid_cqe(priv, cqe)) {
588 * Packet is OK - process it.
590 length = be32_to_cpu(cqe->byte_cnt);
591 length -= ring->fcs_del;
592 mb = mlx4_en_rx_mb(priv, rx_desc, mb_list, length);
598 ring->bytes += length;
601 if (unlikely(priv->validate_loopback)) {
602 validate_loopback(priv, mb);
606 mb->m_pkthdr.flowid = cq->ring;
607 M_HASHTYPE_SET(mb, M_HASHTYPE_OPAQUE);
608 mb->m_pkthdr.rcvif = dev;
609 if (be32_to_cpu(cqe->vlan_my_qpn) &
610 MLX4_CQE_VLAN_PRESENT_MASK) {
611 mb->m_pkthdr.ether_vtag = be16_to_cpu(cqe->sl_vid);
612 mb->m_flags |= M_VLANTAG;
614 if (likely(dev->if_capabilities & IFCAP_RXCSUM) &&
615 (cqe->status & cpu_to_be16(MLX4_CQE_STATUS_IPOK)) &&
616 (cqe->checksum == cpu_to_be16(0xffff))) {
617 priv->port_stats.rx_chksum_good++;
618 mb->m_pkthdr.csum_flags =
619 CSUM_IP_CHECKED | CSUM_IP_VALID |
620 CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
621 mb->m_pkthdr.csum_data = htons(0xffff);
622 /* This packet is eligible for LRO if it is:
623 * - DIX Ethernet (type interpretation)
625 * - without IP options
626 * - not an IP fragment
629 if (mlx4_en_can_lro(cqe->status) &&
630 (dev->if_capenable & IFCAP_LRO)) {
631 if (ring->lro.lro_cnt != 0 &&
632 tcp_lro_rx(&ring->lro, mb, 0) == 0)
637 /* LRO not possible, complete processing here */
638 INC_PERF_COUNTER(priv->pstats.lro_misses);
640 mb->m_pkthdr.csum_flags = 0;
641 priv->port_stats.rx_chksum_none++;
644 /* Push it up the stack */
645 dev->if_input(dev, mb);
649 index = cons_index & size_mask;
650 cqe = &buf[CQE_FACTOR_INDEX(index, factor)];
651 if (++polled == budget)
654 /* Flush all pending IP reassembly sessions */
657 while ((queued = SLIST_FIRST(&ring->lro.lro_active)) != NULL) {
658 SLIST_REMOVE_HEAD(&ring->lro.lro_active, next);
659 tcp_lro_flush(&ring->lro, queued);
662 AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled);
663 mcq->cons_index = cons_index;
665 wmb(); /* ensure HW sees CQ consumer before we post new buffers */
666 ring->cons = mcq->cons_index;
667 ring->prod += polled; /* Polled descriptors were realocated in place */
668 mlx4_en_update_rx_prod_db(ring);
673 /* Rx CQ polling - called by NAPI */
674 static int mlx4_en_poll_rx_cq(struct mlx4_en_cq *cq, int budget)
676 struct net_device *dev = cq->dev;
679 done = mlx4_en_process_rx_cq(dev, cq, budget);
685 void mlx4_en_rx_irq(struct mlx4_cq *mcq)
687 struct mlx4_en_cq *cq = container_of(mcq, struct mlx4_en_cq, mcq);
688 struct mlx4_en_priv *priv = netdev_priv(cq->dev);
691 // Shoot one within the irq context
692 // Because there is no NAPI in freeBSD
693 done = mlx4_en_poll_rx_cq(cq, MLX4_EN_RX_BUDGET);
694 if (priv->port_up && (done == MLX4_EN_RX_BUDGET) ) {
695 taskqueue_enqueue(cq->tq, &cq->cq_task);
698 mlx4_en_arm_cq(priv, cq);
702 void mlx4_en_rx_que(void *context, int pending)
704 struct mlx4_en_cq *cq;
707 while (mlx4_en_poll_rx_cq(cq, MLX4_EN_RX_BUDGET)
708 == MLX4_EN_RX_BUDGET);
709 mlx4_en_arm_cq(cq->dev->if_softc, cq);
713 /* RSS related functions */
715 static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn,
716 struct mlx4_en_rx_ring *ring,
717 enum mlx4_qp_state *state,
720 struct mlx4_en_dev *mdev = priv->mdev;
721 struct mlx4_qp_context *context;
724 context = kmalloc(sizeof *context , GFP_KERNEL);
726 en_err(priv, "Failed to allocate qp context\n");
730 err = mlx4_qp_alloc(mdev->dev, qpn, qp);
732 en_err(priv, "Failed to allocate qp #%x\n", qpn);
735 qp->event = mlx4_en_sqp_event;
737 memset(context, 0, sizeof *context);
738 mlx4_en_fill_qp_context(priv, ring->actual_size, ring->stride, 0, 0,
739 qpn, ring->cqn, -1, context);
740 context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma);
742 /* Cancel FCS removal if FW allows */
743 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP) {
744 context->param3 |= cpu_to_be32(1 << 29);
745 ring->fcs_del = ETH_FCS_LEN;
749 err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, context, qp, state);
751 mlx4_qp_remove(mdev->dev, qp);
752 mlx4_qp_free(mdev->dev, qp);
754 mlx4_en_update_rx_prod_db(ring);
760 int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv)
765 err = mlx4_qp_reserve_range(priv->mdev->dev, 1, 1, &qpn, 0);
767 en_err(priv, "Failed reserving drop qpn\n");
770 err = mlx4_qp_alloc(priv->mdev->dev, qpn, &priv->drop_qp);
772 en_err(priv, "Failed allocating drop qp\n");
773 mlx4_qp_release_range(priv->mdev->dev, qpn, 1);
780 void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv)
784 qpn = priv->drop_qp.qpn;
785 mlx4_qp_remove(priv->mdev->dev, &priv->drop_qp);
786 mlx4_qp_free(priv->mdev->dev, &priv->drop_qp);
787 mlx4_qp_release_range(priv->mdev->dev, qpn, 1);
790 /* Allocate rx qp's and configure them according to rss map */
791 int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
793 struct mlx4_en_dev *mdev = priv->mdev;
794 struct mlx4_en_rss_map *rss_map = &priv->rss_map;
795 struct mlx4_qp_context context;
796 struct mlx4_rss_context *rss_context;
799 u8 rss_mask = (MLX4_RSS_IPV4 | MLX4_RSS_TCP_IPV4 | MLX4_RSS_IPV6 |
804 static const u32 rsskey[10] = { 0xD181C62C, 0xF7F4DB5B, 0x1983A2FC,
805 0x943E1ADB, 0xD9389E6B, 0xD1039C2C, 0xA74499AD,
806 0x593D56D9, 0xF3253C06, 0x2ADC1FFC};
808 en_dbg(DRV, priv, "Configuring rss steering\n");
809 err = mlx4_qp_reserve_range(mdev->dev, priv->rx_ring_num,
811 &rss_map->base_qpn, 0);
813 en_err(priv, "Failed reserving %d qps\n", priv->rx_ring_num);
817 for (i = 0; i < priv->rx_ring_num; i++) {
818 priv->rx_ring[i]->qpn = rss_map->base_qpn + i;
819 err = mlx4_en_config_rss_qp(priv, priv->rx_ring[i]->qpn,
829 /* Configure RSS indirection qp */
830 err = mlx4_qp_alloc(mdev->dev, priv->base_qpn, &rss_map->indir_qp);
832 en_err(priv, "Failed to allocate RSS indirection QP\n");
835 rss_map->indir_qp.event = mlx4_en_sqp_event;
836 mlx4_en_fill_qp_context(priv, 0, 0, 0, 1, priv->base_qpn,
837 priv->rx_ring[0]->cqn, -1, &context);
839 if (!priv->prof->rss_rings || priv->prof->rss_rings > priv->rx_ring_num)
840 rss_rings = priv->rx_ring_num;
842 rss_rings = priv->prof->rss_rings;
844 ptr = ((void *) &context) + offsetof(struct mlx4_qp_context, pri_path)
845 + MLX4_RSS_OFFSET_IN_QPC_PRI_PATH;
847 rss_context->base_qpn = cpu_to_be32(ilog2(rss_rings) << 24 |
848 (rss_map->base_qpn));
849 rss_context->default_qpn = cpu_to_be32(rss_map->base_qpn);
850 if (priv->mdev->profile.udp_rss) {
851 rss_mask |= MLX4_RSS_UDP_IPV4 | MLX4_RSS_UDP_IPV6;
852 rss_context->base_qpn_udp = rss_context->default_qpn;
854 rss_context->flags = rss_mask;
855 rss_context->hash_fn = MLX4_RSS_HASH_TOP;
856 for (i = 0; i < 10; i++)
857 rss_context->rss_key[i] = cpu_to_be32(rsskey[i]);
859 err = mlx4_qp_to_ready(mdev->dev, &priv->res.mtt, &context,
860 &rss_map->indir_qp, &rss_map->indir_state);
867 mlx4_qp_modify(mdev->dev, NULL, rss_map->indir_state,
868 MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->indir_qp);
869 mlx4_qp_remove(mdev->dev, &rss_map->indir_qp);
870 mlx4_qp_free(mdev->dev, &rss_map->indir_qp);
872 for (i = 0; i < good_qps; i++) {
873 mlx4_qp_modify(mdev->dev, NULL, rss_map->state[i],
874 MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->qps[i]);
875 mlx4_qp_remove(mdev->dev, &rss_map->qps[i]);
876 mlx4_qp_free(mdev->dev, &rss_map->qps[i]);
878 mlx4_qp_release_range(mdev->dev, rss_map->base_qpn, priv->rx_ring_num);
882 void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv)
884 struct mlx4_en_dev *mdev = priv->mdev;
885 struct mlx4_en_rss_map *rss_map = &priv->rss_map;
888 mlx4_qp_modify(mdev->dev, NULL, rss_map->indir_state,
889 MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->indir_qp);
890 mlx4_qp_remove(mdev->dev, &rss_map->indir_qp);
891 mlx4_qp_free(mdev->dev, &rss_map->indir_qp);
893 for (i = 0; i < priv->rx_ring_num; i++) {
894 mlx4_qp_modify(mdev->dev, NULL, rss_map->state[i],
895 MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->qps[i]);
896 mlx4_qp_remove(mdev->dev, &rss_map->qps[i]);
897 mlx4_qp_free(mdev->dev, &rss_map->qps[i]);
899 mlx4_qp_release_range(mdev->dev, rss_map->base_qpn, priv->rx_ring_num);