2 * Copyright (c) 2015-2016, 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
33 #include <net/tc_act/tc_gact.h>
34 #include <net/pkt_cls.h>
35 #include <linux/mlx5/fs.h>
36 #include <net/vxlan.h>
42 struct mlx5e_rq_param {
43 u32 rqc[MLX5_ST_SZ_DW(rqc)];
44 struct mlx5_wq_param wq;
47 struct mlx5e_sq_param {
48 u32 sqc[MLX5_ST_SZ_DW(sqc)];
49 struct mlx5_wq_param wq;
54 struct mlx5e_cq_param {
55 u32 cqc[MLX5_ST_SZ_DW(cqc)];
56 struct mlx5_wq_param wq;
60 struct mlx5e_channel_param {
61 struct mlx5e_rq_param rq;
62 struct mlx5e_sq_param sq;
63 struct mlx5e_sq_param icosq;
64 struct mlx5e_cq_param rx_cq;
65 struct mlx5e_cq_param tx_cq;
66 struct mlx5e_cq_param icosq_cq;
69 static void mlx5e_update_carrier(struct mlx5e_priv *priv)
71 struct mlx5_core_dev *mdev = priv->mdev;
74 port_state = mlx5_query_vport_state(mdev,
75 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT, 0);
77 if (port_state == VPORT_STATE_UP)
78 netif_carrier_on(priv->netdev);
80 netif_carrier_off(priv->netdev);
83 static void mlx5e_update_carrier_work(struct work_struct *work)
85 struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
88 mutex_lock(&priv->state_lock);
89 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
90 mlx5e_update_carrier(priv);
91 mutex_unlock(&priv->state_lock);
94 static void mlx5e_update_sw_counters(struct mlx5e_priv *priv)
96 struct mlx5e_sw_stats *s = &priv->stats.sw;
97 struct mlx5e_rq_stats *rq_stats;
98 struct mlx5e_sq_stats *sq_stats;
99 u64 tx_offload_none = 0;
102 memset(s, 0, sizeof(*s));
103 for (i = 0; i < priv->params.num_channels; i++) {
104 rq_stats = &priv->channel[i]->rq.stats;
106 s->rx_packets += rq_stats->packets;
107 s->rx_bytes += rq_stats->bytes;
108 s->lro_packets += rq_stats->lro_packets;
109 s->lro_bytes += rq_stats->lro_bytes;
110 s->rx_csum_none += rq_stats->csum_none;
111 s->rx_csum_sw += rq_stats->csum_sw;
112 s->rx_wqe_err += rq_stats->wqe_err;
113 s->rx_mpwqe_filler += rq_stats->mpwqe_filler;
114 s->rx_mpwqe_frag += rq_stats->mpwqe_frag;
115 s->rx_buff_alloc_err += rq_stats->buff_alloc_err;
117 for (j = 0; j < priv->params.num_tc; j++) {
118 sq_stats = &priv->channel[i]->sq[j].stats;
120 s->tx_packets += sq_stats->packets;
121 s->tx_bytes += sq_stats->bytes;
122 s->tso_packets += sq_stats->tso_packets;
123 s->tso_bytes += sq_stats->tso_bytes;
124 s->tso_inner_packets += sq_stats->tso_inner_packets;
125 s->tso_inner_bytes += sq_stats->tso_inner_bytes;
126 s->tx_queue_stopped += sq_stats->stopped;
127 s->tx_queue_wake += sq_stats->wake;
128 s->tx_queue_dropped += sq_stats->dropped;
129 s->tx_csum_inner += sq_stats->csum_offload_inner;
130 tx_offload_none += sq_stats->csum_offload_none;
134 /* Update calculated offload counters */
135 s->tx_csum_offload = s->tx_packets - tx_offload_none - s->tx_csum_inner;
136 s->rx_csum_good = s->rx_packets - s->rx_csum_none -
139 s->link_down_events = MLX5_GET(ppcnt_reg,
140 priv->stats.pport.phy_counters,
141 counter_set.phys_layer_cntrs.link_down_events);
144 static void mlx5e_update_vport_counters(struct mlx5e_priv *priv)
146 int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
147 u32 *out = (u32 *)priv->stats.vport.query_vport_out;
148 u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)];
149 struct mlx5_core_dev *mdev = priv->mdev;
151 memset(in, 0, sizeof(in));
153 MLX5_SET(query_vport_counter_in, in, opcode,
154 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
155 MLX5_SET(query_vport_counter_in, in, op_mod, 0);
156 MLX5_SET(query_vport_counter_in, in, other_vport, 0);
158 memset(out, 0, outlen);
160 mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
163 static void mlx5e_update_pport_counters(struct mlx5e_priv *priv)
165 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
166 struct mlx5_core_dev *mdev = priv->mdev;
167 int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
172 in = mlx5_vzalloc(sz);
176 MLX5_SET(ppcnt_reg, in, local_port, 1);
178 out = pstats->IEEE_802_3_counters;
179 MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
180 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
182 out = pstats->RFC_2863_counters;
183 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
184 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
186 out = pstats->RFC_2819_counters;
187 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
188 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
190 out = pstats->phy_counters;
191 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
192 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
194 MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
195 for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
196 out = pstats->per_prio_counters[prio];
197 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
198 mlx5_core_access_reg(mdev, in, sz, out, sz,
199 MLX5_REG_PPCNT, 0, 0);
206 static void mlx5e_update_q_counter(struct mlx5e_priv *priv)
208 struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
210 if (!priv->q_counter)
213 mlx5_core_query_out_of_buffer(priv->mdev, priv->q_counter,
214 &qcnt->rx_out_of_buffer);
217 void mlx5e_update_stats(struct mlx5e_priv *priv)
219 mlx5e_update_q_counter(priv);
220 mlx5e_update_vport_counters(priv);
221 mlx5e_update_pport_counters(priv);
222 mlx5e_update_sw_counters(priv);
225 static void mlx5e_update_stats_work(struct work_struct *work)
227 struct delayed_work *dwork = to_delayed_work(work);
228 struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
230 mutex_lock(&priv->state_lock);
231 if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
232 mlx5e_update_stats(priv);
233 schedule_delayed_work(dwork,
235 MLX5E_UPDATE_STATS_INTERVAL));
237 mutex_unlock(&priv->state_lock);
240 static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv,
241 enum mlx5_dev_event event, unsigned long param)
243 struct mlx5e_priv *priv = vpriv;
245 if (!test_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state))
249 case MLX5_DEV_EVENT_PORT_UP:
250 case MLX5_DEV_EVENT_PORT_DOWN:
251 schedule_work(&priv->update_carrier_work);
259 static void mlx5e_enable_async_events(struct mlx5e_priv *priv)
261 set_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state);
264 static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
266 clear_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state);
267 synchronize_irq(mlx5_get_msix_vec(priv->mdev, MLX5_EQ_VEC_ASYNC));
270 #define MLX5E_HW2SW_MTU(hwmtu) (hwmtu - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
271 #define MLX5E_SW2HW_MTU(swmtu) (swmtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
273 static int mlx5e_create_rq(struct mlx5e_channel *c,
274 struct mlx5e_rq_param *param,
277 struct mlx5e_priv *priv = c->priv;
278 struct mlx5_core_dev *mdev = priv->mdev;
279 void *rqc = param->rqc;
280 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
286 param->wq.db_numa_node = cpu_to_node(c->cpu);
288 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
293 rq->wq.db = &rq->wq.db[MLX5_RCV_DBR];
295 wq_sz = mlx5_wq_ll_get_size(&rq->wq);
297 switch (priv->params.rq_wq_type) {
298 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
299 rq->wqe_info = kzalloc_node(wq_sz * sizeof(*rq->wqe_info),
300 GFP_KERNEL, cpu_to_node(c->cpu));
303 goto err_rq_wq_destroy;
305 rq->handle_rx_cqe = mlx5e_handle_rx_cqe_mpwrq;
306 rq->alloc_wqe = mlx5e_alloc_rx_mpwqe;
308 rq->wqe_sz = MLX5_MPWRQ_NUM_STRIDES * MLX5_MPWRQ_STRIDE_SIZE;
309 byte_count = rq->wqe_sz;
311 default: /* MLX5_WQ_TYPE_LINKED_LIST */
312 rq->skb = kzalloc_node(wq_sz * sizeof(*rq->skb), GFP_KERNEL,
313 cpu_to_node(c->cpu));
316 goto err_rq_wq_destroy;
318 rq->handle_rx_cqe = mlx5e_handle_rx_cqe;
319 rq->alloc_wqe = mlx5e_alloc_rx_wqe;
321 rq->wqe_sz = (priv->params.lro_en) ?
322 priv->params.lro_wqe_sz :
323 MLX5E_SW2HW_MTU(priv->netdev->mtu);
324 rq->wqe_sz = SKB_DATA_ALIGN(rq->wqe_sz);
325 byte_count = rq->wqe_sz;
326 byte_count |= MLX5_HW_START_PADDING;
329 for (i = 0; i < wq_sz; i++) {
330 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
332 wqe->data.byte_count = cpu_to_be32(byte_count);
335 rq->wq_type = priv->params.rq_wq_type;
337 rq->netdev = c->netdev;
338 rq->tstamp = &priv->tstamp;
342 rq->mkey_be = c->mkey_be;
343 rq->umr_mkey_be = cpu_to_be32(c->priv->umr_mkey.key);
348 mlx5_wq_destroy(&rq->wq_ctrl);
353 static void mlx5e_destroy_rq(struct mlx5e_rq *rq)
355 switch (rq->wq_type) {
356 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
359 default: /* MLX5_WQ_TYPE_LINKED_LIST */
363 mlx5_wq_destroy(&rq->wq_ctrl);
366 static int mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param)
368 struct mlx5e_priv *priv = rq->priv;
369 struct mlx5_core_dev *mdev = priv->mdev;
377 inlen = MLX5_ST_SZ_BYTES(create_rq_in) +
378 sizeof(u64) * rq->wq_ctrl.buf.npages;
379 in = mlx5_vzalloc(inlen);
383 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx);
384 wq = MLX5_ADDR_OF(rqc, rqc, wq);
386 memcpy(rqc, param->rqc, sizeof(param->rqc));
388 MLX5_SET(rqc, rqc, cqn, rq->cq.mcq.cqn);
389 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST);
390 MLX5_SET(rqc, rqc, flush_in_error_en, 1);
391 MLX5_SET(rqc, rqc, vsd, priv->params.vlan_strip_disable);
392 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift -
393 MLX5_ADAPTER_PAGE_SHIFT);
394 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma);
396 mlx5_fill_page_array(&rq->wq_ctrl.buf,
397 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
399 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn);
406 static int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state,
409 struct mlx5e_channel *c = rq->channel;
410 struct mlx5e_priv *priv = c->priv;
411 struct mlx5_core_dev *mdev = priv->mdev;
418 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
419 in = mlx5_vzalloc(inlen);
423 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
425 MLX5_SET(modify_rq_in, in, rq_state, curr_state);
426 MLX5_SET(rqc, rqc, state, next_state);
428 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
435 static int mlx5e_modify_rq_vsd(struct mlx5e_rq *rq, bool vsd)
437 struct mlx5e_channel *c = rq->channel;
438 struct mlx5e_priv *priv = c->priv;
439 struct mlx5_core_dev *mdev = priv->mdev;
446 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
447 in = mlx5_vzalloc(inlen);
451 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
453 MLX5_SET(modify_rq_in, in, rq_state, MLX5_RQC_STATE_RDY);
454 MLX5_SET64(modify_rq_in, in, modify_bitmask, MLX5_RQ_BITMASK_VSD);
455 MLX5_SET(rqc, rqc, vsd, vsd);
456 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RDY);
458 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
465 static void mlx5e_disable_rq(struct mlx5e_rq *rq)
467 mlx5_core_destroy_rq(rq->priv->mdev, rq->rqn);
470 static int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq)
472 unsigned long exp_time = jiffies + msecs_to_jiffies(20000);
473 struct mlx5e_channel *c = rq->channel;
474 struct mlx5e_priv *priv = c->priv;
475 struct mlx5_wq_ll *wq = &rq->wq;
477 while (time_before(jiffies, exp_time)) {
478 if (wq->cur_sz >= priv->params.min_rx_wqes)
487 static int mlx5e_open_rq(struct mlx5e_channel *c,
488 struct mlx5e_rq_param *param,
491 struct mlx5e_sq *sq = &c->icosq;
492 u16 pi = sq->pc & sq->wq.sz_m1;
495 err = mlx5e_create_rq(c, param, rq);
499 err = mlx5e_enable_rq(rq, param);
503 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
507 set_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
509 sq->ico_wqe_info[pi].opcode = MLX5_OPCODE_NOP;
510 sq->ico_wqe_info[pi].num_wqebbs = 1;
511 mlx5e_send_nop(sq, true); /* trigger mlx5e_post_rx_wqes() */
516 mlx5e_disable_rq(rq);
518 mlx5e_destroy_rq(rq);
523 static void mlx5e_close_rq(struct mlx5e_rq *rq)
525 clear_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
526 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
528 mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR);
529 while (!mlx5_wq_ll_is_empty(&rq->wq))
532 /* avoid destroying rq before mlx5e_poll_rx_cq() is done with it */
533 napi_synchronize(&rq->channel->napi);
535 mlx5e_disable_rq(rq);
536 mlx5e_destroy_rq(rq);
539 static void mlx5e_free_sq_db(struct mlx5e_sq *sq)
546 static int mlx5e_alloc_sq_db(struct mlx5e_sq *sq, int numa)
548 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
549 int df_sz = wq_sz * MLX5_SEND_WQEBB_NUM_DS;
551 sq->skb = kzalloc_node(wq_sz * sizeof(*sq->skb), GFP_KERNEL, numa);
552 sq->dma_fifo = kzalloc_node(df_sz * sizeof(*sq->dma_fifo), GFP_KERNEL,
554 sq->wqe_info = kzalloc_node(wq_sz * sizeof(*sq->wqe_info), GFP_KERNEL,
557 if (!sq->skb || !sq->dma_fifo || !sq->wqe_info) {
558 mlx5e_free_sq_db(sq);
562 sq->dma_fifo_mask = df_sz - 1;
567 static int mlx5e_create_sq(struct mlx5e_channel *c,
569 struct mlx5e_sq_param *param,
572 struct mlx5e_priv *priv = c->priv;
573 struct mlx5_core_dev *mdev = priv->mdev;
575 void *sqc = param->sqc;
576 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq);
579 err = mlx5_alloc_map_uar(mdev, &sq->uar, true);
583 param->wq.db_numa_node = cpu_to_node(c->cpu);
585 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq,
588 goto err_unmap_free_uar;
590 sq->wq.db = &sq->wq.db[MLX5_SND_DBR];
591 if (sq->uar.bf_map) {
592 set_bit(MLX5E_SQ_STATE_BF_ENABLE, &sq->state);
593 sq->uar_map = sq->uar.bf_map;
595 sq->uar_map = sq->uar.map;
597 sq->bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
598 sq->max_inline = param->max_inline;
600 err = mlx5e_alloc_sq_db(sq, cpu_to_node(c->cpu));
602 goto err_sq_wq_destroy;
605 u8 wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
607 sq->ico_wqe_info = kzalloc_node(sizeof(*sq->ico_wqe_info) *
610 cpu_to_node(c->cpu));
611 if (!sq->ico_wqe_info) {
618 txq_ix = c->ix + tc * priv->params.num_channels;
619 sq->txq = netdev_get_tx_queue(priv->netdev, txq_ix);
620 priv->txq_to_sq_map[txq_ix] = sq;
624 sq->tstamp = &priv->tstamp;
625 sq->mkey_be = c->mkey_be;
628 sq->edge = (sq->wq.sz_m1 + 1) - MLX5_SEND_WQE_MAX_WQEBBS;
629 sq->bf_budget = MLX5E_SQ_BF_BUDGET;
634 mlx5e_free_sq_db(sq);
637 mlx5_wq_destroy(&sq->wq_ctrl);
640 mlx5_unmap_free_uar(mdev, &sq->uar);
645 static void mlx5e_destroy_sq(struct mlx5e_sq *sq)
647 struct mlx5e_channel *c = sq->channel;
648 struct mlx5e_priv *priv = c->priv;
650 kfree(sq->ico_wqe_info);
651 mlx5e_free_sq_db(sq);
652 mlx5_wq_destroy(&sq->wq_ctrl);
653 mlx5_unmap_free_uar(priv->mdev, &sq->uar);
656 static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
658 struct mlx5e_channel *c = sq->channel;
659 struct mlx5e_priv *priv = c->priv;
660 struct mlx5_core_dev *mdev = priv->mdev;
668 inlen = MLX5_ST_SZ_BYTES(create_sq_in) +
669 sizeof(u64) * sq->wq_ctrl.buf.npages;
670 in = mlx5_vzalloc(inlen);
674 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx);
675 wq = MLX5_ADDR_OF(sqc, sqc, wq);
677 memcpy(sqc, param->sqc, sizeof(param->sqc));
679 MLX5_SET(sqc, sqc, tis_num_0, param->icosq ? 0 : priv->tisn[sq->tc]);
680 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn);
681 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
682 MLX5_SET(sqc, sqc, tis_lst_sz, param->icosq ? 0 : 1);
683 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
685 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
686 MLX5_SET(wq, wq, uar_page, sq->uar.index);
687 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift -
688 MLX5_ADAPTER_PAGE_SHIFT);
689 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma);
691 mlx5_fill_page_array(&sq->wq_ctrl.buf,
692 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
694 err = mlx5_core_create_sq(mdev, in, inlen, &sq->sqn);
701 static int mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state, int next_state)
703 struct mlx5e_channel *c = sq->channel;
704 struct mlx5e_priv *priv = c->priv;
705 struct mlx5_core_dev *mdev = priv->mdev;
712 inlen = MLX5_ST_SZ_BYTES(modify_sq_in);
713 in = mlx5_vzalloc(inlen);
717 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx);
719 MLX5_SET(modify_sq_in, in, sq_state, curr_state);
720 MLX5_SET(sqc, sqc, state, next_state);
722 err = mlx5_core_modify_sq(mdev, sq->sqn, in, inlen);
729 static void mlx5e_disable_sq(struct mlx5e_sq *sq)
731 struct mlx5e_channel *c = sq->channel;
732 struct mlx5e_priv *priv = c->priv;
733 struct mlx5_core_dev *mdev = priv->mdev;
735 mlx5_core_destroy_sq(mdev, sq->sqn);
738 static int mlx5e_open_sq(struct mlx5e_channel *c,
740 struct mlx5e_sq_param *param,
745 err = mlx5e_create_sq(c, tc, param, sq);
749 err = mlx5e_enable_sq(sq, param);
753 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY);
758 set_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
759 netdev_tx_reset_queue(sq->txq);
760 netif_tx_start_queue(sq->txq);
766 mlx5e_disable_sq(sq);
768 mlx5e_destroy_sq(sq);
773 static inline void netif_tx_disable_queue(struct netdev_queue *txq)
775 __netif_tx_lock_bh(txq);
776 netif_tx_stop_queue(txq);
777 __netif_tx_unlock_bh(txq);
780 static void mlx5e_close_sq(struct mlx5e_sq *sq)
783 clear_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
784 /* prevent netif_tx_wake_queue */
785 napi_synchronize(&sq->channel->napi);
786 netif_tx_disable_queue(sq->txq);
788 /* ensure hw is notified of all pending wqes */
789 if (mlx5e_sq_has_room_for(sq, 1))
790 mlx5e_send_nop(sq, true);
792 mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY, MLX5_SQC_STATE_ERR);
795 while (sq->cc != sq->pc) /* wait till sq is empty */
798 /* avoid destroying sq before mlx5e_poll_tx_cq() is done with it */
799 napi_synchronize(&sq->channel->napi);
801 mlx5e_disable_sq(sq);
802 mlx5e_destroy_sq(sq);
805 static int mlx5e_create_cq(struct mlx5e_channel *c,
806 struct mlx5e_cq_param *param,
809 struct mlx5e_priv *priv = c->priv;
810 struct mlx5_core_dev *mdev = priv->mdev;
811 struct mlx5_core_cq *mcq = &cq->mcq;
817 param->wq.buf_numa_node = cpu_to_node(c->cpu);
818 param->wq.db_numa_node = cpu_to_node(c->cpu);
819 param->eq_ix = c->ix;
821 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
826 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
831 mcq->set_ci_db = cq->wq_ctrl.db.db;
832 mcq->arm_db = cq->wq_ctrl.db.db + 1;
835 mcq->vector = param->eq_ix;
836 mcq->comp = mlx5e_completion_event;
837 mcq->event = mlx5e_cq_error_event;
839 mcq->uar = &priv->cq_uar;
841 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
842 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
853 static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
855 mlx5_wq_destroy(&cq->wq_ctrl);
858 static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
860 struct mlx5e_priv *priv = cq->priv;
861 struct mlx5_core_dev *mdev = priv->mdev;
862 struct mlx5_core_cq *mcq = &cq->mcq;
867 unsigned int irqn_not_used;
871 inlen = MLX5_ST_SZ_BYTES(create_cq_in) +
872 sizeof(u64) * cq->wq_ctrl.buf.npages;
873 in = mlx5_vzalloc(inlen);
877 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
879 memcpy(cqc, param->cqc, sizeof(param->cqc));
881 mlx5_fill_page_array(&cq->wq_ctrl.buf,
882 (__be64 *)MLX5_ADDR_OF(create_cq_in, in, pas));
884 mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
886 MLX5_SET(cqc, cqc, c_eqn, eqn);
887 MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
888 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
889 MLX5_ADAPTER_PAGE_SHIFT);
890 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
892 err = mlx5_core_create_cq(mdev, mcq, in, inlen);
904 static void mlx5e_disable_cq(struct mlx5e_cq *cq)
906 struct mlx5e_priv *priv = cq->priv;
907 struct mlx5_core_dev *mdev = priv->mdev;
909 mlx5_core_destroy_cq(mdev, &cq->mcq);
912 static int mlx5e_open_cq(struct mlx5e_channel *c,
913 struct mlx5e_cq_param *param,
915 u16 moderation_usecs,
916 u16 moderation_frames)
919 struct mlx5e_priv *priv = c->priv;
920 struct mlx5_core_dev *mdev = priv->mdev;
922 err = mlx5e_create_cq(c, param, cq);
926 err = mlx5e_enable_cq(cq, param);
930 if (MLX5_CAP_GEN(mdev, cq_moderation))
931 mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
937 mlx5e_destroy_cq(cq);
942 static void mlx5e_close_cq(struct mlx5e_cq *cq)
944 mlx5e_disable_cq(cq);
945 mlx5e_destroy_cq(cq);
948 static int mlx5e_get_cpu(struct mlx5e_priv *priv, int ix)
950 return cpumask_first(priv->mdev->priv.irq_info[ix].mask);
953 static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
954 struct mlx5e_channel_param *cparam)
956 struct mlx5e_priv *priv = c->priv;
960 for (tc = 0; tc < c->num_tc; tc++) {
961 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
962 priv->params.tx_cq_moderation_usec,
963 priv->params.tx_cq_moderation_pkts);
965 goto err_close_tx_cqs;
971 for (tc--; tc >= 0; tc--)
972 mlx5e_close_cq(&c->sq[tc].cq);
977 static void mlx5e_close_tx_cqs(struct mlx5e_channel *c)
981 for (tc = 0; tc < c->num_tc; tc++)
982 mlx5e_close_cq(&c->sq[tc].cq);
985 static int mlx5e_open_sqs(struct mlx5e_channel *c,
986 struct mlx5e_channel_param *cparam)
991 for (tc = 0; tc < c->num_tc; tc++) {
992 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]);
1000 for (tc--; tc >= 0; tc--)
1001 mlx5e_close_sq(&c->sq[tc]);
1006 static void mlx5e_close_sqs(struct mlx5e_channel *c)
1010 for (tc = 0; tc < c->num_tc; tc++)
1011 mlx5e_close_sq(&c->sq[tc]);
1014 static void mlx5e_build_channeltc_to_txq_map(struct mlx5e_priv *priv, int ix)
1018 for (i = 0; i < MLX5E_MAX_NUM_TC; i++)
1019 priv->channeltc_to_txq_map[ix][i] =
1020 ix + i * priv->params.num_channels;
1023 static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1024 struct mlx5e_channel_param *cparam,
1025 struct mlx5e_channel **cp)
1027 struct net_device *netdev = priv->netdev;
1028 int cpu = mlx5e_get_cpu(priv, ix);
1029 struct mlx5e_channel *c;
1032 c = kzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1039 c->pdev = &priv->mdev->pdev->dev;
1040 c->netdev = priv->netdev;
1041 c->mkey_be = cpu_to_be32(priv->mkey.key);
1042 c->num_tc = priv->params.num_tc;
1044 mlx5e_build_channeltc_to_txq_map(priv, ix);
1046 netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1048 err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, 0, 0);
1052 err = mlx5e_open_tx_cqs(c, cparam);
1054 goto err_close_icosq_cq;
1056 err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1057 priv->params.rx_cq_moderation_usec,
1058 priv->params.rx_cq_moderation_pkts);
1060 goto err_close_tx_cqs;
1062 napi_enable(&c->napi);
1064 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
1066 goto err_disable_napi;
1068 err = mlx5e_open_sqs(c, cparam);
1070 goto err_close_icosq;
1072 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1076 netif_set_xps_queue(netdev, get_cpu_mask(c->cpu), ix);
1085 mlx5e_close_sq(&c->icosq);
1088 napi_disable(&c->napi);
1089 mlx5e_close_cq(&c->rq.cq);
1092 mlx5e_close_tx_cqs(c);
1095 mlx5e_close_cq(&c->icosq.cq);
1098 netif_napi_del(&c->napi);
1099 napi_hash_del(&c->napi);
1105 static void mlx5e_close_channel(struct mlx5e_channel *c)
1107 mlx5e_close_rq(&c->rq);
1109 mlx5e_close_sq(&c->icosq);
1110 napi_disable(&c->napi);
1111 mlx5e_close_cq(&c->rq.cq);
1112 mlx5e_close_tx_cqs(c);
1113 mlx5e_close_cq(&c->icosq.cq);
1114 netif_napi_del(&c->napi);
1116 napi_hash_del(&c->napi);
1122 static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1123 struct mlx5e_rq_param *param)
1125 void *rqc = param->rqc;
1126 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1128 switch (priv->params.rq_wq_type) {
1129 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1130 MLX5_SET(wq, wq, log_wqe_num_of_strides,
1131 MLX5_MPWRQ_LOG_NUM_STRIDES - 9);
1132 MLX5_SET(wq, wq, log_wqe_stride_size,
1133 MLX5_MPWRQ_LOG_STRIDE_SIZE - 6);
1134 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
1136 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1137 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1140 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
1141 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1142 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1143 MLX5_SET(wq, wq, pd, priv->pdn);
1144 MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
1146 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1147 param->wq.linear = 1;
1150 static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param)
1152 void *rqc = param->rqc;
1153 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1155 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1156 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1159 static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
1160 struct mlx5e_sq_param *param)
1162 void *sqc = param->sqc;
1163 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1165 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1166 MLX5_SET(wq, wq, pd, priv->pdn);
1168 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1171 static void mlx5e_build_sq_param(struct mlx5e_priv *priv,
1172 struct mlx5e_sq_param *param)
1174 void *sqc = param->sqc;
1175 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1177 mlx5e_build_sq_param_common(priv, param);
1178 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size);
1180 param->max_inline = priv->params.tx_max_inline;
1183 static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
1184 struct mlx5e_cq_param *param)
1186 void *cqc = param->cqc;
1188 MLX5_SET(cqc, cqc, uar_page, priv->cq_uar.index);
1191 static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
1192 struct mlx5e_cq_param *param)
1194 void *cqc = param->cqc;
1197 switch (priv->params.rq_wq_type) {
1198 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1199 log_cq_size = priv->params.log_rq_size +
1200 MLX5_MPWRQ_LOG_NUM_STRIDES;
1202 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1203 log_cq_size = priv->params.log_rq_size;
1206 MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
1208 mlx5e_build_common_cq_param(priv, param);
1211 static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
1212 struct mlx5e_cq_param *param)
1214 void *cqc = param->cqc;
1216 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
1218 mlx5e_build_common_cq_param(priv, param);
1221 static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
1222 struct mlx5e_cq_param *param,
1225 void *cqc = param->cqc;
1227 MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1229 mlx5e_build_common_cq_param(priv, param);
1232 static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
1233 struct mlx5e_sq_param *param,
1236 void *sqc = param->sqc;
1237 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1239 mlx5e_build_sq_param_common(priv, param);
1241 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1242 MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(priv->mdev, reg_umr_sq));
1244 param->icosq = true;
1247 static void mlx5e_build_channel_param(struct mlx5e_priv *priv,
1248 struct mlx5e_channel_param *cparam)
1250 u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1252 memset(cparam, 0, sizeof(*cparam));
1254 mlx5e_build_rq_param(priv, &cparam->rq);
1255 mlx5e_build_sq_param(priv, &cparam->sq);
1256 mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz);
1257 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq);
1258 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq);
1259 mlx5e_build_ico_cq_param(priv, &cparam->icosq_cq, icosq_log_wq_sz);
1262 static int mlx5e_open_channels(struct mlx5e_priv *priv)
1264 struct mlx5e_channel_param cparam;
1265 int nch = priv->params.num_channels;
1270 priv->channel = kcalloc(nch, sizeof(struct mlx5e_channel *),
1273 priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc,
1274 sizeof(struct mlx5e_sq *), GFP_KERNEL);
1276 if (!priv->channel || !priv->txq_to_sq_map)
1277 goto err_free_txq_to_sq_map;
1279 mlx5e_build_channel_param(priv, &cparam);
1280 for (i = 0; i < nch; i++) {
1281 err = mlx5e_open_channel(priv, i, &cparam, &priv->channel[i]);
1283 goto err_close_channels;
1286 for (j = 0; j < nch; j++) {
1287 err = mlx5e_wait_for_min_rx_wqes(&priv->channel[j]->rq);
1289 goto err_close_channels;
1295 for (i--; i >= 0; i--)
1296 mlx5e_close_channel(priv->channel[i]);
1298 err_free_txq_to_sq_map:
1299 kfree(priv->txq_to_sq_map);
1300 kfree(priv->channel);
1305 static void mlx5e_close_channels(struct mlx5e_priv *priv)
1309 for (i = 0; i < priv->params.num_channels; i++)
1310 mlx5e_close_channel(priv->channel[i]);
1312 kfree(priv->txq_to_sq_map);
1313 kfree(priv->channel);
1316 static int mlx5e_rx_hash_fn(int hfunc)
1318 return (hfunc == ETH_RSS_HASH_TOP) ?
1319 MLX5_RX_HASH_FN_TOEPLITZ :
1320 MLX5_RX_HASH_FN_INVERTED_XOR8;
1323 static int mlx5e_bits_invert(unsigned long a, int size)
1328 for (i = 0; i < size; i++)
1329 inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1334 static void mlx5e_fill_indir_rqt_rqns(struct mlx5e_priv *priv, void *rqtc)
1338 for (i = 0; i < MLX5E_INDIR_RQT_SIZE; i++) {
1341 if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1342 ix = mlx5e_bits_invert(i, MLX5E_LOG_INDIR_RQT_SIZE);
1344 ix = priv->params.indirection_rqt[ix];
1345 MLX5_SET(rqtc, rqtc, rq_num[i],
1346 test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1347 priv->channel[ix]->rq.rqn :
1352 static void mlx5e_fill_rqt_rqns(struct mlx5e_priv *priv, void *rqtc,
1353 enum mlx5e_rqt_ix rqt_ix)
1357 case MLX5E_INDIRECTION_RQT:
1358 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1362 default: /* MLX5E_SINGLE_RQ_RQT */
1363 MLX5_SET(rqtc, rqtc, rq_num[0],
1364 test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1365 priv->channel[0]->rq.rqn :
1372 static int mlx5e_create_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1374 struct mlx5_core_dev *mdev = priv->mdev;
1381 sz = (rqt_ix == MLX5E_SINGLE_RQ_RQT) ? 1 : MLX5E_INDIR_RQT_SIZE;
1383 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
1384 in = mlx5_vzalloc(inlen);
1388 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1390 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1391 MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
1393 mlx5e_fill_rqt_rqns(priv, rqtc, rqt_ix);
1395 err = mlx5_core_create_rqt(mdev, in, inlen, &priv->rqtn[rqt_ix]);
1402 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1404 struct mlx5_core_dev *mdev = priv->mdev;
1411 sz = (rqt_ix == MLX5E_SINGLE_RQ_RQT) ? 1 : MLX5E_INDIR_RQT_SIZE;
1413 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz;
1414 in = mlx5_vzalloc(inlen);
1418 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx);
1420 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1422 mlx5e_fill_rqt_rqns(priv, rqtc, rqt_ix);
1424 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1);
1426 err = mlx5_core_modify_rqt(mdev, priv->rqtn[rqt_ix], in, inlen);
1433 static void mlx5e_destroy_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1435 mlx5_core_destroy_rqt(priv->mdev, priv->rqtn[rqt_ix]);
1438 static void mlx5e_redirect_rqts(struct mlx5e_priv *priv)
1440 mlx5e_redirect_rqt(priv, MLX5E_INDIRECTION_RQT);
1441 mlx5e_redirect_rqt(priv, MLX5E_SINGLE_RQ_RQT);
1444 static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1446 if (!priv->params.lro_en)
1449 #define ROUGH_MAX_L2_L3_HDR_SZ 256
1451 MLX5_SET(tirc, tirc, lro_enable_mask,
1452 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
1453 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO);
1454 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1455 (priv->params.lro_wqe_sz -
1456 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1457 MLX5_SET(tirc, tirc, lro_timeout_period_usecs,
1458 MLX5_CAP_ETH(priv->mdev,
1459 lro_timer_supported_periods[2]));
1462 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
1464 MLX5_SET(tirc, tirc, rx_hash_fn,
1465 mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1466 if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1467 void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1468 rx_hash_toeplitz_key);
1469 size_t len = MLX5_FLD_SZ_BYTES(tirc,
1470 rx_hash_toeplitz_key);
1472 MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1473 memcpy(rss_key, priv->params.toeplitz_hash_key, len);
1477 static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
1479 struct mlx5_core_dev *mdev = priv->mdev;
1487 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1488 in = mlx5_vzalloc(inlen);
1492 MLX5_SET(modify_tir_in, in, bitmask.lro, 1);
1493 tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
1495 mlx5e_build_tir_ctx_lro(tirc, priv);
1497 for (tt = 0; tt < MLX5E_NUM_TT; tt++) {
1498 err = mlx5_core_modify_tir(mdev, priv->tirn[tt], in, inlen);
1508 static int mlx5e_refresh_tir_self_loopback_enable(struct mlx5_core_dev *mdev,
1515 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1516 in = mlx5_vzalloc(inlen);
1520 MLX5_SET(modify_tir_in, in, bitmask.self_lb_en, 1);
1522 err = mlx5_core_modify_tir(mdev, tirn, in, inlen);
1529 static int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5e_priv *priv)
1534 for (i = 0; i < MLX5E_NUM_TT; i++) {
1535 err = mlx5e_refresh_tir_self_loopback_enable(priv->mdev,
1544 static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
1546 struct mlx5e_priv *priv = netdev_priv(netdev);
1547 struct mlx5_core_dev *mdev = priv->mdev;
1551 err = mlx5_set_port_mtu(mdev, MLX5E_SW2HW_MTU(netdev->mtu), 1);
1555 mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
1557 if (MLX5E_HW2SW_MTU(hw_mtu) != netdev->mtu)
1558 netdev_warn(netdev, "%s: Port MTU %d is different than netdev mtu %d\n",
1559 __func__, MLX5E_HW2SW_MTU(hw_mtu), netdev->mtu);
1561 netdev->mtu = MLX5E_HW2SW_MTU(hw_mtu);
1565 static void mlx5e_netdev_set_tcs(struct net_device *netdev)
1567 struct mlx5e_priv *priv = netdev_priv(netdev);
1568 int nch = priv->params.num_channels;
1569 int ntc = priv->params.num_tc;
1572 netdev_reset_tc(netdev);
1577 netdev_set_num_tc(netdev, ntc);
1579 for (tc = 0; tc < ntc; tc++)
1580 netdev_set_tc_queue(netdev, tc, nch, tc * nch);
1583 int mlx5e_open_locked(struct net_device *netdev)
1585 struct mlx5e_priv *priv = netdev_priv(netdev);
1589 set_bit(MLX5E_STATE_OPENED, &priv->state);
1591 mlx5e_netdev_set_tcs(netdev);
1593 num_txqs = priv->params.num_channels * priv->params.num_tc;
1594 netif_set_real_num_tx_queues(netdev, num_txqs);
1595 netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
1597 err = mlx5e_set_dev_port_mtu(netdev);
1599 goto err_clear_state_opened_flag;
1601 err = mlx5e_open_channels(priv);
1603 netdev_err(netdev, "%s: mlx5e_open_channels failed, %d\n",
1605 goto err_clear_state_opened_flag;
1608 err = mlx5e_refresh_tirs_self_loopback_enable(priv);
1610 netdev_err(netdev, "%s: mlx5e_refresh_tirs_self_loopback_enable failed, %d\n",
1612 goto err_close_channels;
1615 mlx5e_redirect_rqts(priv);
1616 mlx5e_update_carrier(priv);
1617 mlx5e_timestamp_init(priv);
1619 schedule_delayed_work(&priv->update_stats_work, 0);
1624 mlx5e_close_channels(priv);
1625 err_clear_state_opened_flag:
1626 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1630 static int mlx5e_open(struct net_device *netdev)
1632 struct mlx5e_priv *priv = netdev_priv(netdev);
1635 mutex_lock(&priv->state_lock);
1636 err = mlx5e_open_locked(netdev);
1637 mutex_unlock(&priv->state_lock);
1642 int mlx5e_close_locked(struct net_device *netdev)
1644 struct mlx5e_priv *priv = netdev_priv(netdev);
1646 /* May already be CLOSED in case a previous configuration operation
1647 * (e.g RX/TX queue size change) that involves close&open failed.
1649 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
1652 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1654 mlx5e_timestamp_cleanup(priv);
1655 netif_carrier_off(priv->netdev);
1656 mlx5e_redirect_rqts(priv);
1657 mlx5e_close_channels(priv);
1662 static int mlx5e_close(struct net_device *netdev)
1664 struct mlx5e_priv *priv = netdev_priv(netdev);
1667 mutex_lock(&priv->state_lock);
1668 err = mlx5e_close_locked(netdev);
1669 mutex_unlock(&priv->state_lock);
1674 static int mlx5e_create_drop_rq(struct mlx5e_priv *priv,
1675 struct mlx5e_rq *rq,
1676 struct mlx5e_rq_param *param)
1678 struct mlx5_core_dev *mdev = priv->mdev;
1679 void *rqc = param->rqc;
1680 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
1683 param->wq.db_numa_node = param->wq.buf_numa_node;
1685 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
1695 static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
1696 struct mlx5e_cq *cq,
1697 struct mlx5e_cq_param *param)
1699 struct mlx5_core_dev *mdev = priv->mdev;
1700 struct mlx5_core_cq *mcq = &cq->mcq;
1705 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
1710 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
1713 mcq->set_ci_db = cq->wq_ctrl.db.db;
1714 mcq->arm_db = cq->wq_ctrl.db.db + 1;
1715 *mcq->set_ci_db = 0;
1717 mcq->vector = param->eq_ix;
1718 mcq->comp = mlx5e_completion_event;
1719 mcq->event = mlx5e_cq_error_event;
1721 mcq->uar = &priv->cq_uar;
1728 static int mlx5e_open_drop_rq(struct mlx5e_priv *priv)
1730 struct mlx5e_cq_param cq_param;
1731 struct mlx5e_rq_param rq_param;
1732 struct mlx5e_rq *rq = &priv->drop_rq;
1733 struct mlx5e_cq *cq = &priv->drop_rq.cq;
1736 memset(&cq_param, 0, sizeof(cq_param));
1737 memset(&rq_param, 0, sizeof(rq_param));
1738 mlx5e_build_drop_rq_param(&rq_param);
1740 err = mlx5e_create_drop_cq(priv, cq, &cq_param);
1744 err = mlx5e_enable_cq(cq, &cq_param);
1746 goto err_destroy_cq;
1748 err = mlx5e_create_drop_rq(priv, rq, &rq_param);
1750 goto err_disable_cq;
1752 err = mlx5e_enable_rq(rq, &rq_param);
1754 goto err_destroy_rq;
1759 mlx5e_destroy_rq(&priv->drop_rq);
1762 mlx5e_disable_cq(&priv->drop_rq.cq);
1765 mlx5e_destroy_cq(&priv->drop_rq.cq);
1770 static void mlx5e_close_drop_rq(struct mlx5e_priv *priv)
1772 mlx5e_disable_rq(&priv->drop_rq);
1773 mlx5e_destroy_rq(&priv->drop_rq);
1774 mlx5e_disable_cq(&priv->drop_rq.cq);
1775 mlx5e_destroy_cq(&priv->drop_rq.cq);
1778 static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
1780 struct mlx5_core_dev *mdev = priv->mdev;
1781 u32 in[MLX5_ST_SZ_DW(create_tis_in)];
1782 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
1784 memset(in, 0, sizeof(in));
1786 MLX5_SET(tisc, tisc, prio, tc << 1);
1787 MLX5_SET(tisc, tisc, transport_domain, priv->tdn);
1789 return mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc]);
1792 static void mlx5e_destroy_tis(struct mlx5e_priv *priv, int tc)
1794 mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc]);
1797 static int mlx5e_create_tises(struct mlx5e_priv *priv)
1802 for (tc = 0; tc < MLX5E_MAX_NUM_TC; tc++) {
1803 err = mlx5e_create_tis(priv, tc);
1805 goto err_close_tises;
1811 for (tc--; tc >= 0; tc--)
1812 mlx5e_destroy_tis(priv, tc);
1817 static void mlx5e_destroy_tises(struct mlx5e_priv *priv)
1821 for (tc = 0; tc < MLX5E_MAX_NUM_TC; tc++)
1822 mlx5e_destroy_tis(priv, tc);
1825 static void mlx5e_build_tir_ctx(struct mlx5e_priv *priv, u32 *tirc, int tt)
1827 void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer);
1829 MLX5_SET(tirc, tirc, transport_domain, priv->tdn);
1831 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
1832 MLX5_HASH_FIELD_SEL_DST_IP)
1834 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
1835 MLX5_HASH_FIELD_SEL_DST_IP |\
1836 MLX5_HASH_FIELD_SEL_L4_SPORT |\
1837 MLX5_HASH_FIELD_SEL_L4_DPORT)
1839 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
1840 MLX5_HASH_FIELD_SEL_DST_IP |\
1841 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
1843 mlx5e_build_tir_ctx_lro(tirc, priv);
1845 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
1849 MLX5_SET(tirc, tirc, indirect_table,
1850 priv->rqtn[MLX5E_SINGLE_RQ_RQT]);
1851 MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_INVERTED_XOR8);
1854 MLX5_SET(tirc, tirc, indirect_table,
1855 priv->rqtn[MLX5E_INDIRECTION_RQT]);
1856 mlx5e_build_tir_ctx_hash(tirc, priv);
1861 case MLX5E_TT_IPV4_TCP:
1862 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1863 MLX5_L3_PROT_TYPE_IPV4);
1864 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1865 MLX5_L4_PROT_TYPE_TCP);
1866 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1867 MLX5_HASH_IP_L4PORTS);
1870 case MLX5E_TT_IPV6_TCP:
1871 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1872 MLX5_L3_PROT_TYPE_IPV6);
1873 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1874 MLX5_L4_PROT_TYPE_TCP);
1875 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1876 MLX5_HASH_IP_L4PORTS);
1879 case MLX5E_TT_IPV4_UDP:
1880 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1881 MLX5_L3_PROT_TYPE_IPV4);
1882 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1883 MLX5_L4_PROT_TYPE_UDP);
1884 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1885 MLX5_HASH_IP_L4PORTS);
1888 case MLX5E_TT_IPV6_UDP:
1889 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1890 MLX5_L3_PROT_TYPE_IPV6);
1891 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1892 MLX5_L4_PROT_TYPE_UDP);
1893 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1894 MLX5_HASH_IP_L4PORTS);
1897 case MLX5E_TT_IPV4_IPSEC_AH:
1898 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1899 MLX5_L3_PROT_TYPE_IPV4);
1900 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1901 MLX5_HASH_IP_IPSEC_SPI);
1904 case MLX5E_TT_IPV6_IPSEC_AH:
1905 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1906 MLX5_L3_PROT_TYPE_IPV6);
1907 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1908 MLX5_HASH_IP_IPSEC_SPI);
1911 case MLX5E_TT_IPV4_IPSEC_ESP:
1912 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1913 MLX5_L3_PROT_TYPE_IPV4);
1914 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1915 MLX5_HASH_IP_IPSEC_SPI);
1918 case MLX5E_TT_IPV6_IPSEC_ESP:
1919 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1920 MLX5_L3_PROT_TYPE_IPV6);
1921 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1922 MLX5_HASH_IP_IPSEC_SPI);
1926 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1927 MLX5_L3_PROT_TYPE_IPV4);
1928 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1933 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1934 MLX5_L3_PROT_TYPE_IPV6);
1935 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1941 static int mlx5e_create_tir(struct mlx5e_priv *priv, int tt)
1943 struct mlx5_core_dev *mdev = priv->mdev;
1949 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
1950 in = mlx5_vzalloc(inlen);
1954 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
1956 mlx5e_build_tir_ctx(priv, tirc, tt);
1958 err = mlx5_core_create_tir(mdev, in, inlen, &priv->tirn[tt]);
1965 static void mlx5e_destroy_tir(struct mlx5e_priv *priv, int tt)
1967 mlx5_core_destroy_tir(priv->mdev, priv->tirn[tt]);
1970 static int mlx5e_create_tirs(struct mlx5e_priv *priv)
1975 for (i = 0; i < MLX5E_NUM_TT; i++) {
1976 err = mlx5e_create_tir(priv, i);
1978 goto err_destroy_tirs;
1984 for (i--; i >= 0; i--)
1985 mlx5e_destroy_tir(priv, i);
1990 static void mlx5e_destroy_tirs(struct mlx5e_priv *priv)
1994 for (i = 0; i < MLX5E_NUM_TT; i++)
1995 mlx5e_destroy_tir(priv, i);
1998 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd)
2003 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
2006 for (i = 0; i < priv->params.num_channels; i++) {
2007 err = mlx5e_modify_rq_vsd(&priv->channel[i]->rq, vsd);
2015 static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
2017 struct mlx5e_priv *priv = netdev_priv(netdev);
2021 if (tc && tc != MLX5E_MAX_NUM_TC)
2024 mutex_lock(&priv->state_lock);
2026 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2028 mlx5e_close_locked(priv->netdev);
2030 priv->params.num_tc = tc ? tc : 1;
2033 err = mlx5e_open_locked(priv->netdev);
2035 mutex_unlock(&priv->state_lock);
2040 static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
2041 __be16 proto, struct tc_to_netdev *tc)
2043 struct mlx5e_priv *priv = netdev_priv(dev);
2045 if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
2049 case TC_SETUP_CLSFLOWER:
2050 switch (tc->cls_flower->command) {
2051 case TC_CLSFLOWER_REPLACE:
2052 return mlx5e_configure_flower(priv, proto, tc->cls_flower);
2053 case TC_CLSFLOWER_DESTROY:
2054 return mlx5e_delete_flower(priv, tc->cls_flower);
2061 if (tc->type != TC_SETUP_MQPRIO)
2064 return mlx5e_setup_tc(dev, tc->tc);
2067 static struct rtnl_link_stats64 *
2068 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
2070 struct mlx5e_priv *priv = netdev_priv(dev);
2071 struct mlx5e_sw_stats *sstats = &priv->stats.sw;
2072 struct mlx5e_vport_stats *vstats = &priv->stats.vport;
2073 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
2075 stats->rx_packets = sstats->rx_packets;
2076 stats->rx_bytes = sstats->rx_bytes;
2077 stats->tx_packets = sstats->tx_packets;
2078 stats->tx_bytes = sstats->tx_bytes;
2080 stats->rx_dropped = priv->stats.qcnt.rx_out_of_buffer;
2081 stats->tx_dropped = sstats->tx_queue_dropped;
2083 stats->rx_length_errors =
2084 PPORT_802_3_GET(pstats, a_in_range_length_errors) +
2085 PPORT_802_3_GET(pstats, a_out_of_range_length_field) +
2086 PPORT_802_3_GET(pstats, a_frame_too_long_errors);
2087 stats->rx_crc_errors =
2088 PPORT_802_3_GET(pstats, a_frame_check_sequence_errors);
2089 stats->rx_frame_errors = PPORT_802_3_GET(pstats, a_alignment_errors);
2090 stats->tx_aborted_errors = PPORT_2863_GET(pstats, if_out_discards);
2091 stats->tx_carrier_errors =
2092 PPORT_802_3_GET(pstats, a_symbol_error_during_carrier);
2093 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
2094 stats->rx_frame_errors;
2095 stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors;
2097 /* vport multicast also counts packets that are dropped due to steering
2098 * or rx out of buffer
2101 VPORT_COUNTER_GET(vstats, received_eth_multicast.packets);
2106 static void mlx5e_set_rx_mode(struct net_device *dev)
2108 struct mlx5e_priv *priv = netdev_priv(dev);
2110 schedule_work(&priv->set_rx_mode_work);
2113 static int mlx5e_set_mac(struct net_device *netdev, void *addr)
2115 struct mlx5e_priv *priv = netdev_priv(netdev);
2116 struct sockaddr *saddr = addr;
2118 if (!is_valid_ether_addr(saddr->sa_data))
2119 return -EADDRNOTAVAIL;
2121 netif_addr_lock_bh(netdev);
2122 ether_addr_copy(netdev->dev_addr, saddr->sa_data);
2123 netif_addr_unlock_bh(netdev);
2125 schedule_work(&priv->set_rx_mode_work);
2130 #define MLX5E_SET_FEATURE(netdev, feature, enable) \
2133 netdev->features |= feature; \
2135 netdev->features &= ~feature; \
2138 typedef int (*mlx5e_feature_handler)(struct net_device *netdev, bool enable);
2140 static int set_feature_lro(struct net_device *netdev, bool enable)
2142 struct mlx5e_priv *priv = netdev_priv(netdev);
2143 bool was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2146 mutex_lock(&priv->state_lock);
2148 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2149 mlx5e_close_locked(priv->netdev);
2151 priv->params.lro_en = enable;
2152 err = mlx5e_modify_tirs_lro(priv);
2154 netdev_err(netdev, "lro modify failed, %d\n", err);
2155 priv->params.lro_en = !enable;
2158 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2159 mlx5e_open_locked(priv->netdev);
2161 mutex_unlock(&priv->state_lock);
2166 static int set_feature_vlan_filter(struct net_device *netdev, bool enable)
2168 struct mlx5e_priv *priv = netdev_priv(netdev);
2171 mlx5e_enable_vlan_filter(priv);
2173 mlx5e_disable_vlan_filter(priv);
2178 static int set_feature_tc_num_filters(struct net_device *netdev, bool enable)
2180 struct mlx5e_priv *priv = netdev_priv(netdev);
2182 if (!enable && mlx5e_tc_num_filters(priv)) {
2184 "Active offloaded tc filters, can't turn hw_tc_offload off\n");
2191 static int set_feature_rx_all(struct net_device *netdev, bool enable)
2193 struct mlx5e_priv *priv = netdev_priv(netdev);
2194 struct mlx5_core_dev *mdev = priv->mdev;
2196 return mlx5_set_port_fcs(mdev, !enable);
2199 static int set_feature_rx_vlan(struct net_device *netdev, bool enable)
2201 struct mlx5e_priv *priv = netdev_priv(netdev);
2204 mutex_lock(&priv->state_lock);
2206 priv->params.vlan_strip_disable = !enable;
2207 err = mlx5e_modify_rqs_vsd(priv, !enable);
2209 priv->params.vlan_strip_disable = enable;
2211 mutex_unlock(&priv->state_lock);
2216 static int mlx5e_handle_feature(struct net_device *netdev,
2217 netdev_features_t wanted_features,
2218 netdev_features_t feature,
2219 mlx5e_feature_handler feature_handler)
2221 netdev_features_t changes = wanted_features ^ netdev->features;
2222 bool enable = !!(wanted_features & feature);
2225 if (!(changes & feature))
2228 err = feature_handler(netdev, enable);
2230 netdev_err(netdev, "%s feature 0x%llx failed err %d\n",
2231 enable ? "Enable" : "Disable", feature, err);
2235 MLX5E_SET_FEATURE(netdev, feature, enable);
2239 static int mlx5e_set_features(struct net_device *netdev,
2240 netdev_features_t features)
2244 err = mlx5e_handle_feature(netdev, features, NETIF_F_LRO,
2246 err |= mlx5e_handle_feature(netdev, features,
2247 NETIF_F_HW_VLAN_CTAG_FILTER,
2248 set_feature_vlan_filter);
2249 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_TC,
2250 set_feature_tc_num_filters);
2251 err |= mlx5e_handle_feature(netdev, features, NETIF_F_RXALL,
2252 set_feature_rx_all);
2253 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_VLAN_CTAG_RX,
2254 set_feature_rx_vlan);
2256 return err ? -EINVAL : 0;
2259 static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
2261 struct mlx5e_priv *priv = netdev_priv(netdev);
2262 struct mlx5_core_dev *mdev = priv->mdev;
2267 mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
2269 max_mtu = MLX5E_HW2SW_MTU(max_mtu);
2271 if (new_mtu > max_mtu) {
2273 "%s: Bad MTU (%d) > (%d) Max\n",
2274 __func__, new_mtu, max_mtu);
2278 mutex_lock(&priv->state_lock);
2280 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2282 mlx5e_close_locked(netdev);
2284 netdev->mtu = new_mtu;
2287 err = mlx5e_open_locked(netdev);
2289 mutex_unlock(&priv->state_lock);
2294 static int mlx5e_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2298 return mlx5e_hwstamp_set(dev, ifr);
2300 return mlx5e_hwstamp_get(dev, ifr);
2306 static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2308 struct mlx5e_priv *priv = netdev_priv(dev);
2309 struct mlx5_core_dev *mdev = priv->mdev;
2311 return mlx5_eswitch_set_vport_mac(mdev->priv.eswitch, vf + 1, mac);
2314 static int mlx5e_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2316 struct mlx5e_priv *priv = netdev_priv(dev);
2317 struct mlx5_core_dev *mdev = priv->mdev;
2319 return mlx5_eswitch_set_vport_vlan(mdev->priv.eswitch, vf + 1,
2323 static int mlx5_vport_link2ifla(u8 esw_link)
2326 case MLX5_ESW_VPORT_ADMIN_STATE_DOWN:
2327 return IFLA_VF_LINK_STATE_DISABLE;
2328 case MLX5_ESW_VPORT_ADMIN_STATE_UP:
2329 return IFLA_VF_LINK_STATE_ENABLE;
2331 return IFLA_VF_LINK_STATE_AUTO;
2334 static int mlx5_ifla_link2vport(u8 ifla_link)
2336 switch (ifla_link) {
2337 case IFLA_VF_LINK_STATE_DISABLE:
2338 return MLX5_ESW_VPORT_ADMIN_STATE_DOWN;
2339 case IFLA_VF_LINK_STATE_ENABLE:
2340 return MLX5_ESW_VPORT_ADMIN_STATE_UP;
2342 return MLX5_ESW_VPORT_ADMIN_STATE_AUTO;
2345 static int mlx5e_set_vf_link_state(struct net_device *dev, int vf,
2348 struct mlx5e_priv *priv = netdev_priv(dev);
2349 struct mlx5_core_dev *mdev = priv->mdev;
2351 return mlx5_eswitch_set_vport_state(mdev->priv.eswitch, vf + 1,
2352 mlx5_ifla_link2vport(link_state));
2355 static int mlx5e_get_vf_config(struct net_device *dev,
2356 int vf, struct ifla_vf_info *ivi)
2358 struct mlx5e_priv *priv = netdev_priv(dev);
2359 struct mlx5_core_dev *mdev = priv->mdev;
2362 err = mlx5_eswitch_get_vport_config(mdev->priv.eswitch, vf + 1, ivi);
2365 ivi->linkstate = mlx5_vport_link2ifla(ivi->linkstate);
2369 static int mlx5e_get_vf_stats(struct net_device *dev,
2370 int vf, struct ifla_vf_stats *vf_stats)
2372 struct mlx5e_priv *priv = netdev_priv(dev);
2373 struct mlx5_core_dev *mdev = priv->mdev;
2375 return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
2379 static void mlx5e_add_vxlan_port(struct net_device *netdev,
2380 sa_family_t sa_family, __be16 port)
2382 struct mlx5e_priv *priv = netdev_priv(netdev);
2384 if (!mlx5e_vxlan_allowed(priv->mdev))
2387 mlx5e_vxlan_add_port(priv, be16_to_cpu(port));
2390 static void mlx5e_del_vxlan_port(struct net_device *netdev,
2391 sa_family_t sa_family, __be16 port)
2393 struct mlx5e_priv *priv = netdev_priv(netdev);
2395 if (!mlx5e_vxlan_allowed(priv->mdev))
2398 mlx5e_vxlan_del_port(priv, be16_to_cpu(port));
2401 static netdev_features_t mlx5e_vxlan_features_check(struct mlx5e_priv *priv,
2402 struct sk_buff *skb,
2403 netdev_features_t features)
2405 struct udphdr *udph;
2409 switch (vlan_get_protocol(skb)) {
2410 case htons(ETH_P_IP):
2411 proto = ip_hdr(skb)->protocol;
2413 case htons(ETH_P_IPV6):
2414 proto = ipv6_hdr(skb)->nexthdr;
2420 if (proto == IPPROTO_UDP) {
2421 udph = udp_hdr(skb);
2422 port = be16_to_cpu(udph->dest);
2425 /* Verify if UDP port is being offloaded by HW */
2426 if (port && mlx5e_vxlan_lookup_port(priv, port))
2430 /* Disable CSUM and GSO if the udp dport is not offloaded by HW */
2431 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2434 static netdev_features_t mlx5e_features_check(struct sk_buff *skb,
2435 struct net_device *netdev,
2436 netdev_features_t features)
2438 struct mlx5e_priv *priv = netdev_priv(netdev);
2440 features = vlan_features_check(skb, features);
2441 features = vxlan_features_check(skb, features);
2443 /* Validate if the tunneled packet is being offloaded by HW */
2444 if (skb->encapsulation &&
2445 (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
2446 return mlx5e_vxlan_features_check(priv, skb, features);
2451 static const struct net_device_ops mlx5e_netdev_ops_basic = {
2452 .ndo_open = mlx5e_open,
2453 .ndo_stop = mlx5e_close,
2454 .ndo_start_xmit = mlx5e_xmit,
2455 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2456 .ndo_select_queue = mlx5e_select_queue,
2457 .ndo_get_stats64 = mlx5e_get_stats,
2458 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2459 .ndo_set_mac_address = mlx5e_set_mac,
2460 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2461 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2462 .ndo_set_features = mlx5e_set_features,
2463 .ndo_change_mtu = mlx5e_change_mtu,
2464 .ndo_do_ioctl = mlx5e_ioctl,
2467 static const struct net_device_ops mlx5e_netdev_ops_sriov = {
2468 .ndo_open = mlx5e_open,
2469 .ndo_stop = mlx5e_close,
2470 .ndo_start_xmit = mlx5e_xmit,
2471 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2472 .ndo_select_queue = mlx5e_select_queue,
2473 .ndo_get_stats64 = mlx5e_get_stats,
2474 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2475 .ndo_set_mac_address = mlx5e_set_mac,
2476 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2477 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2478 .ndo_set_features = mlx5e_set_features,
2479 .ndo_change_mtu = mlx5e_change_mtu,
2480 .ndo_do_ioctl = mlx5e_ioctl,
2481 .ndo_add_vxlan_port = mlx5e_add_vxlan_port,
2482 .ndo_del_vxlan_port = mlx5e_del_vxlan_port,
2483 .ndo_features_check = mlx5e_features_check,
2484 .ndo_set_vf_mac = mlx5e_set_vf_mac,
2485 .ndo_set_vf_vlan = mlx5e_set_vf_vlan,
2486 .ndo_get_vf_config = mlx5e_get_vf_config,
2487 .ndo_set_vf_link_state = mlx5e_set_vf_link_state,
2488 .ndo_get_vf_stats = mlx5e_get_vf_stats,
2491 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
2493 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
2495 if (!MLX5_CAP_GEN(mdev, eth_net_offloads) ||
2496 !MLX5_CAP_GEN(mdev, nic_flow_table) ||
2497 !MLX5_CAP_ETH(mdev, csum_cap) ||
2498 !MLX5_CAP_ETH(mdev, max_lso_cap) ||
2499 !MLX5_CAP_ETH(mdev, vlan_cap) ||
2500 !MLX5_CAP_ETH(mdev, rss_ind_tbl_cap) ||
2501 MLX5_CAP_FLOWTABLE(mdev,
2502 flow_table_properties_nic_receive.max_ft_level)
2504 mlx5_core_warn(mdev,
2505 "Not creating net device, some required device capabilities are missing\n");
2508 if (!MLX5_CAP_ETH(mdev, self_lb_en_modifiable))
2509 mlx5_core_warn(mdev, "Self loop back prevention is not supported\n");
2510 if (!MLX5_CAP_GEN(mdev, cq_moderation))
2511 mlx5_core_warn(mdev, "CQ modiration is not supported\n");
2516 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev)
2518 int bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
2520 return bf_buf_size -
2521 sizeof(struct mlx5e_tx_wqe) +
2522 2 /*sizeof(mlx5e_tx_wqe.inline_hdr_start)*/;
2525 #ifdef CONFIG_MLX5_CORE_EN_DCB
2526 static void mlx5e_ets_init(struct mlx5e_priv *priv)
2530 priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
2531 for (i = 0; i < priv->params.ets.ets_cap; i++) {
2532 priv->params.ets.tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
2533 priv->params.ets.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
2534 priv->params.ets.prio_tc[i] = i;
2537 /* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
2538 priv->params.ets.prio_tc[0] = 1;
2539 priv->params.ets.prio_tc[1] = 0;
2543 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
2544 u32 *indirection_rqt, int len,
2547 int node = mdev->priv.numa_node;
2548 int node_num_of_cores;
2552 node = first_online_node;
2554 node_num_of_cores = cpumask_weight(cpumask_of_node(node));
2556 if (node_num_of_cores)
2557 num_channels = min_t(int, num_channels, node_num_of_cores);
2559 for (i = 0; i < len; i++)
2560 indirection_rqt[i] = i % num_channels;
2563 static bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
2565 return MLX5_CAP_GEN(mdev, striding_rq) &&
2566 MLX5_CAP_GEN(mdev, umr_ptr_rlky) &&
2567 MLX5_CAP_ETH(mdev, reg_umr_sq);
2570 static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
2571 struct net_device *netdev,
2574 struct mlx5e_priv *priv = netdev_priv(netdev);
2576 priv->params.log_sq_size =
2577 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
2578 priv->params.rq_wq_type = mlx5e_check_fragmented_striding_rq_cap(mdev) ?
2579 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
2580 MLX5_WQ_TYPE_LINKED_LIST;
2582 switch (priv->params.rq_wq_type) {
2583 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
2584 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW;
2585 priv->params.lro_en = true;
2587 default: /* MLX5_WQ_TYPE_LINKED_LIST */
2588 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
2591 priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
2592 BIT(priv->params.log_rq_size));
2593 priv->params.rx_cq_moderation_usec =
2594 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2595 priv->params.rx_cq_moderation_pkts =
2596 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2597 priv->params.tx_cq_moderation_usec =
2598 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
2599 priv->params.tx_cq_moderation_pkts =
2600 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
2601 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
2602 priv->params.num_tc = 1;
2603 priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
2605 netdev_rss_key_fill(priv->params.toeplitz_hash_key,
2606 sizeof(priv->params.toeplitz_hash_key));
2608 mlx5e_build_default_indir_rqt(mdev, priv->params.indirection_rqt,
2609 MLX5E_INDIR_RQT_SIZE, num_channels);
2611 priv->params.lro_wqe_sz =
2612 MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
2615 priv->netdev = netdev;
2616 priv->params.num_channels = num_channels;
2618 #ifdef CONFIG_MLX5_CORE_EN_DCB
2619 mlx5e_ets_init(priv);
2622 mutex_init(&priv->state_lock);
2624 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
2625 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
2626 INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
2629 static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
2631 struct mlx5e_priv *priv = netdev_priv(netdev);
2633 mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
2634 if (is_zero_ether_addr(netdev->dev_addr) &&
2635 !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
2636 eth_hw_addr_random(netdev);
2637 mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr);
2641 static void mlx5e_build_netdev(struct net_device *netdev)
2643 struct mlx5e_priv *priv = netdev_priv(netdev);
2644 struct mlx5_core_dev *mdev = priv->mdev;
2648 SET_NETDEV_DEV(netdev, &mdev->pdev->dev);
2650 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
2651 netdev->netdev_ops = &mlx5e_netdev_ops_sriov;
2652 #ifdef CONFIG_MLX5_CORE_EN_DCB
2653 netdev->dcbnl_ops = &mlx5e_dcbnl_ops;
2656 netdev->netdev_ops = &mlx5e_netdev_ops_basic;
2659 netdev->watchdog_timeo = 15 * HZ;
2661 netdev->ethtool_ops = &mlx5e_ethtool_ops;
2663 netdev->vlan_features |= NETIF_F_SG;
2664 netdev->vlan_features |= NETIF_F_IP_CSUM;
2665 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
2666 netdev->vlan_features |= NETIF_F_GRO;
2667 netdev->vlan_features |= NETIF_F_TSO;
2668 netdev->vlan_features |= NETIF_F_TSO6;
2669 netdev->vlan_features |= NETIF_F_RXCSUM;
2670 netdev->vlan_features |= NETIF_F_RXHASH;
2672 if (!!MLX5_CAP_ETH(mdev, lro_cap))
2673 netdev->vlan_features |= NETIF_F_LRO;
2675 netdev->hw_features = netdev->vlan_features;
2676 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
2677 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
2678 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2680 if (mlx5e_vxlan_allowed(mdev)) {
2681 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2682 netdev->hw_enc_features |= NETIF_F_IP_CSUM;
2683 netdev->hw_enc_features |= NETIF_F_RXCSUM;
2684 netdev->hw_enc_features |= NETIF_F_TSO;
2685 netdev->hw_enc_features |= NETIF_F_TSO6;
2686 netdev->hw_enc_features |= NETIF_F_RXHASH;
2687 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL;
2690 mlx5_query_port_fcs(mdev, &fcs_supported, &fcs_enabled);
2693 netdev->hw_features |= NETIF_F_RXALL;
2695 netdev->features = netdev->hw_features;
2696 if (!priv->params.lro_en)
2697 netdev->features &= ~NETIF_F_LRO;
2700 netdev->features &= ~NETIF_F_RXALL;
2702 #define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
2703 if (FT_CAP(flow_modify_en) &&
2704 FT_CAP(modify_root) &&
2705 FT_CAP(identified_miss_table_mode) &&
2706 FT_CAP(flow_table_modify))
2707 priv->netdev->hw_features |= NETIF_F_HW_TC;
2709 netdev->features |= NETIF_F_HIGHDMA;
2711 netdev->priv_flags |= IFF_UNICAST_FLT;
2713 mlx5e_set_netdev_dev_addr(netdev);
2716 static int mlx5e_create_mkey(struct mlx5e_priv *priv, u32 pdn,
2717 struct mlx5_core_mkey *mkey)
2719 struct mlx5_core_dev *mdev = priv->mdev;
2720 struct mlx5_create_mkey_mbox_in *in;
2723 in = mlx5_vzalloc(sizeof(*in));
2727 in->seg.flags = MLX5_PERM_LOCAL_WRITE |
2728 MLX5_PERM_LOCAL_READ |
2729 MLX5_ACCESS_MODE_PA;
2730 in->seg.flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64);
2731 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
2733 err = mlx5_core_create_mkey(mdev, mkey, in, sizeof(*in), NULL, NULL,
2741 static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
2743 struct mlx5_core_dev *mdev = priv->mdev;
2746 err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter);
2748 mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err);
2749 priv->q_counter = 0;
2753 static void mlx5e_destroy_q_counter(struct mlx5e_priv *priv)
2755 if (!priv->q_counter)
2758 mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter);
2761 static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
2763 struct mlx5_core_dev *mdev = priv->mdev;
2764 struct mlx5_create_mkey_mbox_in *in;
2765 struct mlx5_mkey_seg *mkc;
2766 int inlen = sizeof(*in);
2768 mlx5e_get_max_num_channels(mdev) * MLX5_CHANNEL_MAX_NUM_MTTS;
2771 in = mlx5_vzalloc(inlen);
2776 mkc->status = MLX5_MKEY_STATUS_FREE;
2777 mkc->flags = MLX5_PERM_UMR_EN |
2778 MLX5_PERM_LOCAL_READ |
2779 MLX5_PERM_LOCAL_WRITE |
2780 MLX5_ACCESS_MODE_MTT;
2782 mkc->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
2783 mkc->flags_pd = cpu_to_be32(priv->pdn);
2784 mkc->len = cpu_to_be64(npages << PAGE_SHIFT);
2785 mkc->xlt_oct_size = cpu_to_be32(mlx5e_get_mtt_octw(npages));
2786 mkc->log2_page_size = PAGE_SHIFT;
2788 err = mlx5_core_create_mkey(mdev, &priv->umr_mkey, in, inlen, NULL,
2796 static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
2798 struct net_device *netdev;
2799 struct mlx5e_priv *priv;
2800 int nch = mlx5e_get_max_num_channels(mdev);
2803 if (mlx5e_check_required_hca_cap(mdev))
2806 netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
2807 nch * MLX5E_MAX_NUM_TC,
2810 mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
2814 mlx5e_build_netdev_priv(mdev, netdev, nch);
2815 mlx5e_build_netdev(netdev);
2817 netif_carrier_off(netdev);
2819 priv = netdev_priv(netdev);
2821 err = mlx5_alloc_map_uar(mdev, &priv->cq_uar, false);
2823 mlx5_core_err(mdev, "alloc_map uar failed, %d\n", err);
2824 goto err_free_netdev;
2827 err = mlx5_core_alloc_pd(mdev, &priv->pdn);
2829 mlx5_core_err(mdev, "alloc pd failed, %d\n", err);
2830 goto err_unmap_free_uar;
2833 err = mlx5_core_alloc_transport_domain(mdev, &priv->tdn);
2835 mlx5_core_err(mdev, "alloc td failed, %d\n", err);
2836 goto err_dealloc_pd;
2839 err = mlx5e_create_mkey(priv, priv->pdn, &priv->mkey);
2841 mlx5_core_err(mdev, "create mkey failed, %d\n", err);
2842 goto err_dealloc_transport_domain;
2845 err = mlx5e_create_umr_mkey(priv);
2847 mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
2848 goto err_destroy_mkey;
2851 err = mlx5e_create_tises(priv);
2853 mlx5_core_warn(mdev, "create tises failed, %d\n", err);
2854 goto err_destroy_umr_mkey;
2857 err = mlx5e_open_drop_rq(priv);
2859 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
2860 goto err_destroy_tises;
2863 err = mlx5e_create_rqt(priv, MLX5E_INDIRECTION_RQT);
2865 mlx5_core_warn(mdev, "create rqt(INDIR) failed, %d\n", err);
2866 goto err_close_drop_rq;
2869 err = mlx5e_create_rqt(priv, MLX5E_SINGLE_RQ_RQT);
2871 mlx5_core_warn(mdev, "create rqt(SINGLE) failed, %d\n", err);
2872 goto err_destroy_rqt_indir;
2875 err = mlx5e_create_tirs(priv);
2877 mlx5_core_warn(mdev, "create tirs failed, %d\n", err);
2878 goto err_destroy_rqt_single;
2881 err = mlx5e_create_flow_tables(priv);
2883 mlx5_core_warn(mdev, "create flow tables failed, %d\n", err);
2884 goto err_destroy_tirs;
2887 mlx5e_create_q_counter(priv);
2889 mlx5e_init_eth_addr(priv);
2891 mlx5e_vxlan_init(priv);
2893 err = mlx5e_tc_init(priv);
2895 goto err_dealloc_q_counters;
2897 #ifdef CONFIG_MLX5_CORE_EN_DCB
2898 mlx5e_dcbnl_ieee_setets_core(priv, &priv->params.ets);
2901 err = register_netdev(netdev);
2903 mlx5_core_err(mdev, "register_netdev failed, %d\n", err);
2904 goto err_tc_cleanup;
2907 if (mlx5e_vxlan_allowed(mdev))
2908 vxlan_get_rx_port(netdev);
2910 mlx5e_enable_async_events(priv);
2911 schedule_work(&priv->set_rx_mode_work);
2916 mlx5e_tc_cleanup(priv);
2918 err_dealloc_q_counters:
2919 mlx5e_destroy_q_counter(priv);
2920 mlx5e_destroy_flow_tables(priv);
2923 mlx5e_destroy_tirs(priv);
2925 err_destroy_rqt_single:
2926 mlx5e_destroy_rqt(priv, MLX5E_SINGLE_RQ_RQT);
2928 err_destroy_rqt_indir:
2929 mlx5e_destroy_rqt(priv, MLX5E_INDIRECTION_RQT);
2932 mlx5e_close_drop_rq(priv);
2935 mlx5e_destroy_tises(priv);
2937 err_destroy_umr_mkey:
2938 mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
2941 mlx5_core_destroy_mkey(mdev, &priv->mkey);
2943 err_dealloc_transport_domain:
2944 mlx5_core_dealloc_transport_domain(mdev, priv->tdn);
2947 mlx5_core_dealloc_pd(mdev, priv->pdn);
2950 mlx5_unmap_free_uar(mdev, &priv->cq_uar);
2953 free_netdev(netdev);
2958 static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, void *vpriv)
2960 struct mlx5e_priv *priv = vpriv;
2961 struct net_device *netdev = priv->netdev;
2963 set_bit(MLX5E_STATE_DESTROYING, &priv->state);
2965 schedule_work(&priv->set_rx_mode_work);
2966 mlx5e_disable_async_events(priv);
2967 flush_scheduled_work();
2968 unregister_netdev(netdev);
2969 mlx5e_tc_cleanup(priv);
2970 mlx5e_vxlan_cleanup(priv);
2971 mlx5e_destroy_q_counter(priv);
2972 mlx5e_destroy_flow_tables(priv);
2973 mlx5e_destroy_tirs(priv);
2974 mlx5e_destroy_rqt(priv, MLX5E_SINGLE_RQ_RQT);
2975 mlx5e_destroy_rqt(priv, MLX5E_INDIRECTION_RQT);
2976 mlx5e_close_drop_rq(priv);
2977 mlx5e_destroy_tises(priv);
2978 mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
2979 mlx5_core_destroy_mkey(priv->mdev, &priv->mkey);
2980 mlx5_core_dealloc_transport_domain(priv->mdev, priv->tdn);
2981 mlx5_core_dealloc_pd(priv->mdev, priv->pdn);
2982 mlx5_unmap_free_uar(priv->mdev, &priv->cq_uar);
2983 free_netdev(netdev);
2986 static void *mlx5e_get_netdev(void *vpriv)
2988 struct mlx5e_priv *priv = vpriv;
2990 return priv->netdev;
2993 static struct mlx5_interface mlx5e_interface = {
2994 .add = mlx5e_create_netdev,
2995 .remove = mlx5e_destroy_netdev,
2996 .event = mlx5e_async_event,
2997 .protocol = MLX5_INTERFACE_PROTOCOL_ETH,
2998 .get_dev = mlx5e_get_netdev,
3001 void mlx5e_init(void)
3003 mlx5_register_interface(&mlx5e_interface);
3006 void mlx5e_cleanup(void)
3008 mlx5_unregister_interface(&mlx5e_interface);