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_csum_inner += rq_stats->csum_inner;
113 s->rx_wqe_err += rq_stats->wqe_err;
114 s->rx_mpwqe_filler += rq_stats->mpwqe_filler;
115 s->rx_mpwqe_frag += rq_stats->mpwqe_frag;
116 s->rx_buff_alloc_err += rq_stats->buff_alloc_err;
118 for (j = 0; j < priv->params.num_tc; j++) {
119 sq_stats = &priv->channel[i]->sq[j].stats;
121 s->tx_packets += sq_stats->packets;
122 s->tx_bytes += sq_stats->bytes;
123 s->tso_packets += sq_stats->tso_packets;
124 s->tso_bytes += sq_stats->tso_bytes;
125 s->tso_inner_packets += sq_stats->tso_inner_packets;
126 s->tso_inner_bytes += sq_stats->tso_inner_bytes;
127 s->tx_queue_stopped += sq_stats->stopped;
128 s->tx_queue_wake += sq_stats->wake;
129 s->tx_queue_dropped += sq_stats->dropped;
130 s->tx_csum_inner += sq_stats->csum_offload_inner;
131 tx_offload_none += sq_stats->csum_offload_none;
135 /* Update calculated offload counters */
136 s->tx_csum_offload = s->tx_packets - tx_offload_none - s->tx_csum_inner;
137 s->rx_csum_good = s->rx_packets - s->rx_csum_none -
140 s->link_down_events = MLX5_GET(ppcnt_reg,
141 priv->stats.pport.phy_counters,
142 counter_set.phys_layer_cntrs.link_down_events);
145 static void mlx5e_update_vport_counters(struct mlx5e_priv *priv)
147 int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
148 u32 *out = (u32 *)priv->stats.vport.query_vport_out;
149 u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)];
150 struct mlx5_core_dev *mdev = priv->mdev;
152 memset(in, 0, sizeof(in));
154 MLX5_SET(query_vport_counter_in, in, opcode,
155 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
156 MLX5_SET(query_vport_counter_in, in, op_mod, 0);
157 MLX5_SET(query_vport_counter_in, in, other_vport, 0);
159 memset(out, 0, outlen);
161 mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
164 static void mlx5e_update_pport_counters(struct mlx5e_priv *priv)
166 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
167 struct mlx5_core_dev *mdev = priv->mdev;
168 int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
173 in = mlx5_vzalloc(sz);
177 MLX5_SET(ppcnt_reg, in, local_port, 1);
179 out = pstats->IEEE_802_3_counters;
180 MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
181 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
183 out = pstats->RFC_2863_counters;
184 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
185 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
187 out = pstats->RFC_2819_counters;
188 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
189 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
191 out = pstats->phy_counters;
192 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
193 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
195 MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
196 for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
197 out = pstats->per_prio_counters[prio];
198 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
199 mlx5_core_access_reg(mdev, in, sz, out, sz,
200 MLX5_REG_PPCNT, 0, 0);
207 static void mlx5e_update_q_counter(struct mlx5e_priv *priv)
209 struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
211 if (!priv->q_counter)
214 mlx5_core_query_out_of_buffer(priv->mdev, priv->q_counter,
215 &qcnt->rx_out_of_buffer);
218 void mlx5e_update_stats(struct mlx5e_priv *priv)
220 mlx5e_update_q_counter(priv);
221 mlx5e_update_vport_counters(priv);
222 mlx5e_update_pport_counters(priv);
223 mlx5e_update_sw_counters(priv);
226 static void mlx5e_update_stats_work(struct work_struct *work)
228 struct delayed_work *dwork = to_delayed_work(work);
229 struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
231 mutex_lock(&priv->state_lock);
232 if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
233 mlx5e_update_stats(priv);
234 schedule_delayed_work(dwork,
236 MLX5E_UPDATE_STATS_INTERVAL));
238 mutex_unlock(&priv->state_lock);
241 static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv,
242 enum mlx5_dev_event event, unsigned long param)
244 struct mlx5e_priv *priv = vpriv;
246 if (!test_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state))
250 case MLX5_DEV_EVENT_PORT_UP:
251 case MLX5_DEV_EVENT_PORT_DOWN:
252 schedule_work(&priv->update_carrier_work);
260 static void mlx5e_enable_async_events(struct mlx5e_priv *priv)
262 set_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state);
265 static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
267 clear_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLE, &priv->state);
268 synchronize_irq(mlx5_get_msix_vec(priv->mdev, MLX5_EQ_VEC_ASYNC));
271 #define MLX5E_HW2SW_MTU(hwmtu) (hwmtu - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
272 #define MLX5E_SW2HW_MTU(swmtu) (swmtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
274 static int mlx5e_create_rq(struct mlx5e_channel *c,
275 struct mlx5e_rq_param *param,
278 struct mlx5e_priv *priv = c->priv;
279 struct mlx5_core_dev *mdev = priv->mdev;
280 void *rqc = param->rqc;
281 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
287 param->wq.db_numa_node = cpu_to_node(c->cpu);
289 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
294 rq->wq.db = &rq->wq.db[MLX5_RCV_DBR];
296 wq_sz = mlx5_wq_ll_get_size(&rq->wq);
298 switch (priv->params.rq_wq_type) {
299 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
300 rq->wqe_info = kzalloc_node(wq_sz * sizeof(*rq->wqe_info),
301 GFP_KERNEL, cpu_to_node(c->cpu));
304 goto err_rq_wq_destroy;
306 rq->handle_rx_cqe = mlx5e_handle_rx_cqe_mpwrq;
307 rq->alloc_wqe = mlx5e_alloc_rx_mpwqe;
309 rq->wqe_sz = MLX5_MPWRQ_NUM_STRIDES * MLX5_MPWRQ_STRIDE_SIZE;
310 byte_count = rq->wqe_sz;
312 default: /* MLX5_WQ_TYPE_LINKED_LIST */
313 rq->skb = kzalloc_node(wq_sz * sizeof(*rq->skb), GFP_KERNEL,
314 cpu_to_node(c->cpu));
317 goto err_rq_wq_destroy;
319 rq->handle_rx_cqe = mlx5e_handle_rx_cqe;
320 rq->alloc_wqe = mlx5e_alloc_rx_wqe;
322 rq->wqe_sz = (priv->params.lro_en) ?
323 priv->params.lro_wqe_sz :
324 MLX5E_SW2HW_MTU(priv->netdev->mtu);
325 rq->wqe_sz = SKB_DATA_ALIGN(rq->wqe_sz);
326 byte_count = rq->wqe_sz;
327 byte_count |= MLX5_HW_START_PADDING;
330 for (i = 0; i < wq_sz; i++) {
331 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
333 wqe->data.byte_count = cpu_to_be32(byte_count);
336 rq->wq_type = priv->params.rq_wq_type;
338 rq->netdev = c->netdev;
339 rq->tstamp = &priv->tstamp;
343 rq->mkey_be = c->mkey_be;
344 rq->umr_mkey_be = cpu_to_be32(c->priv->umr_mkey.key);
349 mlx5_wq_destroy(&rq->wq_ctrl);
354 static void mlx5e_destroy_rq(struct mlx5e_rq *rq)
356 switch (rq->wq_type) {
357 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
360 default: /* MLX5_WQ_TYPE_LINKED_LIST */
364 mlx5_wq_destroy(&rq->wq_ctrl);
367 static int mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param)
369 struct mlx5e_priv *priv = rq->priv;
370 struct mlx5_core_dev *mdev = priv->mdev;
378 inlen = MLX5_ST_SZ_BYTES(create_rq_in) +
379 sizeof(u64) * rq->wq_ctrl.buf.npages;
380 in = mlx5_vzalloc(inlen);
384 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx);
385 wq = MLX5_ADDR_OF(rqc, rqc, wq);
387 memcpy(rqc, param->rqc, sizeof(param->rqc));
389 MLX5_SET(rqc, rqc, cqn, rq->cq.mcq.cqn);
390 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST);
391 MLX5_SET(rqc, rqc, flush_in_error_en, 1);
392 MLX5_SET(rqc, rqc, vsd, priv->params.vlan_strip_disable);
393 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift -
394 MLX5_ADAPTER_PAGE_SHIFT);
395 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma);
397 mlx5_fill_page_array(&rq->wq_ctrl.buf,
398 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
400 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn);
407 static int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state,
410 struct mlx5e_channel *c = rq->channel;
411 struct mlx5e_priv *priv = c->priv;
412 struct mlx5_core_dev *mdev = priv->mdev;
419 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
420 in = mlx5_vzalloc(inlen);
424 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
426 MLX5_SET(modify_rq_in, in, rq_state, curr_state);
427 MLX5_SET(rqc, rqc, state, next_state);
429 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
436 static int mlx5e_modify_rq_vsd(struct mlx5e_rq *rq, bool vsd)
438 struct mlx5e_channel *c = rq->channel;
439 struct mlx5e_priv *priv = c->priv;
440 struct mlx5_core_dev *mdev = priv->mdev;
447 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
448 in = mlx5_vzalloc(inlen);
452 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
454 MLX5_SET(modify_rq_in, in, rq_state, MLX5_RQC_STATE_RDY);
455 MLX5_SET64(modify_rq_in, in, modify_bitmask, MLX5_RQ_BITMASK_VSD);
456 MLX5_SET(rqc, rqc, vsd, vsd);
457 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RDY);
459 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
466 static void mlx5e_disable_rq(struct mlx5e_rq *rq)
468 mlx5_core_destroy_rq(rq->priv->mdev, rq->rqn);
471 static int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq)
473 unsigned long exp_time = jiffies + msecs_to_jiffies(20000);
474 struct mlx5e_channel *c = rq->channel;
475 struct mlx5e_priv *priv = c->priv;
476 struct mlx5_wq_ll *wq = &rq->wq;
478 while (time_before(jiffies, exp_time)) {
479 if (wq->cur_sz >= priv->params.min_rx_wqes)
488 static int mlx5e_open_rq(struct mlx5e_channel *c,
489 struct mlx5e_rq_param *param,
492 struct mlx5e_sq *sq = &c->icosq;
493 u16 pi = sq->pc & sq->wq.sz_m1;
496 err = mlx5e_create_rq(c, param, rq);
500 err = mlx5e_enable_rq(rq, param);
504 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
508 set_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
510 sq->ico_wqe_info[pi].opcode = MLX5_OPCODE_NOP;
511 sq->ico_wqe_info[pi].num_wqebbs = 1;
512 mlx5e_send_nop(sq, true); /* trigger mlx5e_post_rx_wqes() */
517 mlx5e_disable_rq(rq);
519 mlx5e_destroy_rq(rq);
524 static void mlx5e_close_rq(struct mlx5e_rq *rq)
526 clear_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
527 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
529 mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR);
530 while (!mlx5_wq_ll_is_empty(&rq->wq))
533 /* avoid destroying rq before mlx5e_poll_rx_cq() is done with it */
534 napi_synchronize(&rq->channel->napi);
536 mlx5e_disable_rq(rq);
537 mlx5e_destroy_rq(rq);
540 static void mlx5e_free_sq_db(struct mlx5e_sq *sq)
547 static int mlx5e_alloc_sq_db(struct mlx5e_sq *sq, int numa)
549 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
550 int df_sz = wq_sz * MLX5_SEND_WQEBB_NUM_DS;
552 sq->skb = kzalloc_node(wq_sz * sizeof(*sq->skb), GFP_KERNEL, numa);
553 sq->dma_fifo = kzalloc_node(df_sz * sizeof(*sq->dma_fifo), GFP_KERNEL,
555 sq->wqe_info = kzalloc_node(wq_sz * sizeof(*sq->wqe_info), GFP_KERNEL,
558 if (!sq->skb || !sq->dma_fifo || !sq->wqe_info) {
559 mlx5e_free_sq_db(sq);
563 sq->dma_fifo_mask = df_sz - 1;
568 static int mlx5e_create_sq(struct mlx5e_channel *c,
570 struct mlx5e_sq_param *param,
573 struct mlx5e_priv *priv = c->priv;
574 struct mlx5_core_dev *mdev = priv->mdev;
576 void *sqc = param->sqc;
577 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq);
580 err = mlx5_alloc_map_uar(mdev, &sq->uar, true);
584 param->wq.db_numa_node = cpu_to_node(c->cpu);
586 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq,
589 goto err_unmap_free_uar;
591 sq->wq.db = &sq->wq.db[MLX5_SND_DBR];
592 if (sq->uar.bf_map) {
593 set_bit(MLX5E_SQ_STATE_BF_ENABLE, &sq->state);
594 sq->uar_map = sq->uar.bf_map;
596 sq->uar_map = sq->uar.map;
598 sq->bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
599 sq->max_inline = param->max_inline;
601 err = mlx5e_alloc_sq_db(sq, cpu_to_node(c->cpu));
603 goto err_sq_wq_destroy;
606 u8 wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
608 sq->ico_wqe_info = kzalloc_node(sizeof(*sq->ico_wqe_info) *
611 cpu_to_node(c->cpu));
612 if (!sq->ico_wqe_info) {
619 txq_ix = c->ix + tc * priv->params.num_channels;
620 sq->txq = netdev_get_tx_queue(priv->netdev, txq_ix);
621 priv->txq_to_sq_map[txq_ix] = sq;
625 sq->tstamp = &priv->tstamp;
626 sq->mkey_be = c->mkey_be;
629 sq->edge = (sq->wq.sz_m1 + 1) - MLX5_SEND_WQE_MAX_WQEBBS;
630 sq->bf_budget = MLX5E_SQ_BF_BUDGET;
635 mlx5e_free_sq_db(sq);
638 mlx5_wq_destroy(&sq->wq_ctrl);
641 mlx5_unmap_free_uar(mdev, &sq->uar);
646 static void mlx5e_destroy_sq(struct mlx5e_sq *sq)
648 struct mlx5e_channel *c = sq->channel;
649 struct mlx5e_priv *priv = c->priv;
651 kfree(sq->ico_wqe_info);
652 mlx5e_free_sq_db(sq);
653 mlx5_wq_destroy(&sq->wq_ctrl);
654 mlx5_unmap_free_uar(priv->mdev, &sq->uar);
657 static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
659 struct mlx5e_channel *c = sq->channel;
660 struct mlx5e_priv *priv = c->priv;
661 struct mlx5_core_dev *mdev = priv->mdev;
669 inlen = MLX5_ST_SZ_BYTES(create_sq_in) +
670 sizeof(u64) * sq->wq_ctrl.buf.npages;
671 in = mlx5_vzalloc(inlen);
675 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx);
676 wq = MLX5_ADDR_OF(sqc, sqc, wq);
678 memcpy(sqc, param->sqc, sizeof(param->sqc));
680 MLX5_SET(sqc, sqc, tis_num_0, param->icosq ? 0 : priv->tisn[sq->tc]);
681 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn);
682 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
683 MLX5_SET(sqc, sqc, tis_lst_sz, param->icosq ? 0 : 1);
684 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
686 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
687 MLX5_SET(wq, wq, uar_page, sq->uar.index);
688 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift -
689 MLX5_ADAPTER_PAGE_SHIFT);
690 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma);
692 mlx5_fill_page_array(&sq->wq_ctrl.buf,
693 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
695 err = mlx5_core_create_sq(mdev, in, inlen, &sq->sqn);
702 static int mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state, int next_state)
704 struct mlx5e_channel *c = sq->channel;
705 struct mlx5e_priv *priv = c->priv;
706 struct mlx5_core_dev *mdev = priv->mdev;
713 inlen = MLX5_ST_SZ_BYTES(modify_sq_in);
714 in = mlx5_vzalloc(inlen);
718 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx);
720 MLX5_SET(modify_sq_in, in, sq_state, curr_state);
721 MLX5_SET(sqc, sqc, state, next_state);
723 err = mlx5_core_modify_sq(mdev, sq->sqn, in, inlen);
730 static void mlx5e_disable_sq(struct mlx5e_sq *sq)
732 struct mlx5e_channel *c = sq->channel;
733 struct mlx5e_priv *priv = c->priv;
734 struct mlx5_core_dev *mdev = priv->mdev;
736 mlx5_core_destroy_sq(mdev, sq->sqn);
739 static int mlx5e_open_sq(struct mlx5e_channel *c,
741 struct mlx5e_sq_param *param,
746 err = mlx5e_create_sq(c, tc, param, sq);
750 err = mlx5e_enable_sq(sq, param);
754 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY);
759 set_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
760 netdev_tx_reset_queue(sq->txq);
761 netif_tx_start_queue(sq->txq);
767 mlx5e_disable_sq(sq);
769 mlx5e_destroy_sq(sq);
774 static inline void netif_tx_disable_queue(struct netdev_queue *txq)
776 __netif_tx_lock_bh(txq);
777 netif_tx_stop_queue(txq);
778 __netif_tx_unlock_bh(txq);
781 static void mlx5e_close_sq(struct mlx5e_sq *sq)
784 clear_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
785 /* prevent netif_tx_wake_queue */
786 napi_synchronize(&sq->channel->napi);
787 netif_tx_disable_queue(sq->txq);
789 /* ensure hw is notified of all pending wqes */
790 if (mlx5e_sq_has_room_for(sq, 1))
791 mlx5e_send_nop(sq, true);
793 mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY, MLX5_SQC_STATE_ERR);
796 while (sq->cc != sq->pc) /* wait till sq is empty */
799 /* avoid destroying sq before mlx5e_poll_tx_cq() is done with it */
800 napi_synchronize(&sq->channel->napi);
802 mlx5e_disable_sq(sq);
803 mlx5e_destroy_sq(sq);
806 static int mlx5e_create_cq(struct mlx5e_channel *c,
807 struct mlx5e_cq_param *param,
810 struct mlx5e_priv *priv = c->priv;
811 struct mlx5_core_dev *mdev = priv->mdev;
812 struct mlx5_core_cq *mcq = &cq->mcq;
818 param->wq.buf_numa_node = cpu_to_node(c->cpu);
819 param->wq.db_numa_node = cpu_to_node(c->cpu);
820 param->eq_ix = c->ix;
822 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
827 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
832 mcq->set_ci_db = cq->wq_ctrl.db.db;
833 mcq->arm_db = cq->wq_ctrl.db.db + 1;
836 mcq->vector = param->eq_ix;
837 mcq->comp = mlx5e_completion_event;
838 mcq->event = mlx5e_cq_error_event;
840 mcq->uar = &priv->cq_uar;
842 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
843 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
854 static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
856 mlx5_wq_destroy(&cq->wq_ctrl);
859 static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
861 struct mlx5e_priv *priv = cq->priv;
862 struct mlx5_core_dev *mdev = priv->mdev;
863 struct mlx5_core_cq *mcq = &cq->mcq;
868 unsigned int irqn_not_used;
872 inlen = MLX5_ST_SZ_BYTES(create_cq_in) +
873 sizeof(u64) * cq->wq_ctrl.buf.npages;
874 in = mlx5_vzalloc(inlen);
878 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
880 memcpy(cqc, param->cqc, sizeof(param->cqc));
882 mlx5_fill_page_array(&cq->wq_ctrl.buf,
883 (__be64 *)MLX5_ADDR_OF(create_cq_in, in, pas));
885 mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
887 MLX5_SET(cqc, cqc, c_eqn, eqn);
888 MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
889 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
890 MLX5_ADAPTER_PAGE_SHIFT);
891 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
893 err = mlx5_core_create_cq(mdev, mcq, in, inlen);
905 static void mlx5e_disable_cq(struct mlx5e_cq *cq)
907 struct mlx5e_priv *priv = cq->priv;
908 struct mlx5_core_dev *mdev = priv->mdev;
910 mlx5_core_destroy_cq(mdev, &cq->mcq);
913 static int mlx5e_open_cq(struct mlx5e_channel *c,
914 struct mlx5e_cq_param *param,
916 u16 moderation_usecs,
917 u16 moderation_frames)
920 struct mlx5e_priv *priv = c->priv;
921 struct mlx5_core_dev *mdev = priv->mdev;
923 err = mlx5e_create_cq(c, param, cq);
927 err = mlx5e_enable_cq(cq, param);
931 if (MLX5_CAP_GEN(mdev, cq_moderation))
932 mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
938 mlx5e_destroy_cq(cq);
943 static void mlx5e_close_cq(struct mlx5e_cq *cq)
945 mlx5e_disable_cq(cq);
946 mlx5e_destroy_cq(cq);
949 static int mlx5e_get_cpu(struct mlx5e_priv *priv, int ix)
951 return cpumask_first(priv->mdev->priv.irq_info[ix].mask);
954 static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
955 struct mlx5e_channel_param *cparam)
957 struct mlx5e_priv *priv = c->priv;
961 for (tc = 0; tc < c->num_tc; tc++) {
962 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
963 priv->params.tx_cq_moderation_usec,
964 priv->params.tx_cq_moderation_pkts);
966 goto err_close_tx_cqs;
972 for (tc--; tc >= 0; tc--)
973 mlx5e_close_cq(&c->sq[tc].cq);
978 static void mlx5e_close_tx_cqs(struct mlx5e_channel *c)
982 for (tc = 0; tc < c->num_tc; tc++)
983 mlx5e_close_cq(&c->sq[tc].cq);
986 static int mlx5e_open_sqs(struct mlx5e_channel *c,
987 struct mlx5e_channel_param *cparam)
992 for (tc = 0; tc < c->num_tc; tc++) {
993 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]);
1001 for (tc--; tc >= 0; tc--)
1002 mlx5e_close_sq(&c->sq[tc]);
1007 static void mlx5e_close_sqs(struct mlx5e_channel *c)
1011 for (tc = 0; tc < c->num_tc; tc++)
1012 mlx5e_close_sq(&c->sq[tc]);
1015 static void mlx5e_build_channeltc_to_txq_map(struct mlx5e_priv *priv, int ix)
1019 for (i = 0; i < MLX5E_MAX_NUM_TC; i++)
1020 priv->channeltc_to_txq_map[ix][i] =
1021 ix + i * priv->params.num_channels;
1024 static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1025 struct mlx5e_channel_param *cparam,
1026 struct mlx5e_channel **cp)
1028 struct net_device *netdev = priv->netdev;
1029 int cpu = mlx5e_get_cpu(priv, ix);
1030 struct mlx5e_channel *c;
1033 c = kzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1040 c->pdev = &priv->mdev->pdev->dev;
1041 c->netdev = priv->netdev;
1042 c->mkey_be = cpu_to_be32(priv->mkey.key);
1043 c->num_tc = priv->params.num_tc;
1045 mlx5e_build_channeltc_to_txq_map(priv, ix);
1047 netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1049 err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, 0, 0);
1053 err = mlx5e_open_tx_cqs(c, cparam);
1055 goto err_close_icosq_cq;
1057 err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1058 priv->params.rx_cq_moderation_usec,
1059 priv->params.rx_cq_moderation_pkts);
1061 goto err_close_tx_cqs;
1063 napi_enable(&c->napi);
1065 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
1067 goto err_disable_napi;
1069 err = mlx5e_open_sqs(c, cparam);
1071 goto err_close_icosq;
1073 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1077 netif_set_xps_queue(netdev, get_cpu_mask(c->cpu), ix);
1086 mlx5e_close_sq(&c->icosq);
1089 napi_disable(&c->napi);
1090 mlx5e_close_cq(&c->rq.cq);
1093 mlx5e_close_tx_cqs(c);
1096 mlx5e_close_cq(&c->icosq.cq);
1099 netif_napi_del(&c->napi);
1100 napi_hash_del(&c->napi);
1106 static void mlx5e_close_channel(struct mlx5e_channel *c)
1108 mlx5e_close_rq(&c->rq);
1110 mlx5e_close_sq(&c->icosq);
1111 napi_disable(&c->napi);
1112 mlx5e_close_cq(&c->rq.cq);
1113 mlx5e_close_tx_cqs(c);
1114 mlx5e_close_cq(&c->icosq.cq);
1115 netif_napi_del(&c->napi);
1117 napi_hash_del(&c->napi);
1123 static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1124 struct mlx5e_rq_param *param)
1126 void *rqc = param->rqc;
1127 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1129 switch (priv->params.rq_wq_type) {
1130 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1131 MLX5_SET(wq, wq, log_wqe_num_of_strides,
1132 MLX5_MPWRQ_LOG_NUM_STRIDES - 9);
1133 MLX5_SET(wq, wq, log_wqe_stride_size,
1134 MLX5_MPWRQ_LOG_STRIDE_SIZE - 6);
1135 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
1137 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1138 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1141 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
1142 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1143 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1144 MLX5_SET(wq, wq, pd, priv->pdn);
1145 MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
1147 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1148 param->wq.linear = 1;
1151 static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param)
1153 void *rqc = param->rqc;
1154 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1156 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1157 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1160 static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
1161 struct mlx5e_sq_param *param)
1163 void *sqc = param->sqc;
1164 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1166 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1167 MLX5_SET(wq, wq, pd, priv->pdn);
1169 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1172 static void mlx5e_build_sq_param(struct mlx5e_priv *priv,
1173 struct mlx5e_sq_param *param)
1175 void *sqc = param->sqc;
1176 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1178 mlx5e_build_sq_param_common(priv, param);
1179 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size);
1181 param->max_inline = priv->params.tx_max_inline;
1184 static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
1185 struct mlx5e_cq_param *param)
1187 void *cqc = param->cqc;
1189 MLX5_SET(cqc, cqc, uar_page, priv->cq_uar.index);
1192 static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
1193 struct mlx5e_cq_param *param)
1195 void *cqc = param->cqc;
1198 switch (priv->params.rq_wq_type) {
1199 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1200 log_cq_size = priv->params.log_rq_size +
1201 MLX5_MPWRQ_LOG_NUM_STRIDES;
1203 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1204 log_cq_size = priv->params.log_rq_size;
1207 MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
1209 mlx5e_build_common_cq_param(priv, param);
1212 static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
1213 struct mlx5e_cq_param *param)
1215 void *cqc = param->cqc;
1217 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
1219 mlx5e_build_common_cq_param(priv, param);
1222 static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
1223 struct mlx5e_cq_param *param,
1226 void *cqc = param->cqc;
1228 MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1230 mlx5e_build_common_cq_param(priv, param);
1233 static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
1234 struct mlx5e_sq_param *param,
1237 void *sqc = param->sqc;
1238 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1240 mlx5e_build_sq_param_common(priv, param);
1242 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1243 MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(priv->mdev, reg_umr_sq));
1245 param->icosq = true;
1248 static void mlx5e_build_channel_param(struct mlx5e_priv *priv, struct mlx5e_channel_param *cparam)
1250 u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1252 mlx5e_build_rq_param(priv, &cparam->rq);
1253 mlx5e_build_sq_param(priv, &cparam->sq);
1254 mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz);
1255 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq);
1256 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq);
1257 mlx5e_build_ico_cq_param(priv, &cparam->icosq_cq, icosq_log_wq_sz);
1260 static int mlx5e_open_channels(struct mlx5e_priv *priv)
1262 struct mlx5e_channel_param *cparam;
1263 int nch = priv->params.num_channels;
1268 priv->channel = kcalloc(nch, sizeof(struct mlx5e_channel *),
1271 priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc,
1272 sizeof(struct mlx5e_sq *), GFP_KERNEL);
1274 cparam = kzalloc(sizeof(struct mlx5e_channel_param), GFP_KERNEL);
1276 if (!priv->channel || !priv->txq_to_sq_map || !cparam)
1277 goto err_free_txq_to_sq_map;
1279 mlx5e_build_channel_param(priv, cparam);
1281 for (i = 0; i < nch; i++) {
1282 err = mlx5e_open_channel(priv, i, cparam, &priv->channel[i]);
1284 goto err_close_channels;
1287 for (j = 0; j < nch; j++) {
1288 err = mlx5e_wait_for_min_rx_wqes(&priv->channel[j]->rq);
1290 goto err_close_channels;
1297 for (i--; i >= 0; i--)
1298 mlx5e_close_channel(priv->channel[i]);
1300 err_free_txq_to_sq_map:
1301 kfree(priv->txq_to_sq_map);
1302 kfree(priv->channel);
1308 static void mlx5e_close_channels(struct mlx5e_priv *priv)
1312 for (i = 0; i < priv->params.num_channels; i++)
1313 mlx5e_close_channel(priv->channel[i]);
1315 kfree(priv->txq_to_sq_map);
1316 kfree(priv->channel);
1319 static int mlx5e_rx_hash_fn(int hfunc)
1321 return (hfunc == ETH_RSS_HASH_TOP) ?
1322 MLX5_RX_HASH_FN_TOEPLITZ :
1323 MLX5_RX_HASH_FN_INVERTED_XOR8;
1326 static int mlx5e_bits_invert(unsigned long a, int size)
1331 for (i = 0; i < size; i++)
1332 inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1337 static void mlx5e_fill_indir_rqt_rqns(struct mlx5e_priv *priv, void *rqtc)
1341 for (i = 0; i < MLX5E_INDIR_RQT_SIZE; i++) {
1344 if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1345 ix = mlx5e_bits_invert(i, MLX5E_LOG_INDIR_RQT_SIZE);
1347 ix = priv->params.indirection_rqt[ix];
1348 MLX5_SET(rqtc, rqtc, rq_num[i],
1349 test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1350 priv->channel[ix]->rq.rqn :
1355 static void mlx5e_fill_rqt_rqns(struct mlx5e_priv *priv, void *rqtc,
1356 enum mlx5e_rqt_ix rqt_ix)
1360 case MLX5E_INDIRECTION_RQT:
1361 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1365 default: /* MLX5E_SINGLE_RQ_RQT */
1366 MLX5_SET(rqtc, rqtc, rq_num[0],
1367 test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1368 priv->channel[0]->rq.rqn :
1375 static int mlx5e_create_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1377 struct mlx5_core_dev *mdev = priv->mdev;
1384 sz = (rqt_ix == MLX5E_SINGLE_RQ_RQT) ? 1 : MLX5E_INDIR_RQT_SIZE;
1386 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
1387 in = mlx5_vzalloc(inlen);
1391 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1393 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1394 MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
1396 mlx5e_fill_rqt_rqns(priv, rqtc, rqt_ix);
1398 err = mlx5_core_create_rqt(mdev, in, inlen, &priv->rqtn[rqt_ix]);
1405 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1407 struct mlx5_core_dev *mdev = priv->mdev;
1414 sz = (rqt_ix == MLX5E_SINGLE_RQ_RQT) ? 1 : MLX5E_INDIR_RQT_SIZE;
1416 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz;
1417 in = mlx5_vzalloc(inlen);
1421 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx);
1423 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1425 mlx5e_fill_rqt_rqns(priv, rqtc, rqt_ix);
1427 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1);
1429 err = mlx5_core_modify_rqt(mdev, priv->rqtn[rqt_ix], in, inlen);
1436 static void mlx5e_destroy_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix)
1438 mlx5_core_destroy_rqt(priv->mdev, priv->rqtn[rqt_ix]);
1441 static void mlx5e_redirect_rqts(struct mlx5e_priv *priv)
1443 mlx5e_redirect_rqt(priv, MLX5E_INDIRECTION_RQT);
1444 mlx5e_redirect_rqt(priv, MLX5E_SINGLE_RQ_RQT);
1447 static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1449 if (!priv->params.lro_en)
1452 #define ROUGH_MAX_L2_L3_HDR_SZ 256
1454 MLX5_SET(tirc, tirc, lro_enable_mask,
1455 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
1456 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO);
1457 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1458 (priv->params.lro_wqe_sz -
1459 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1460 MLX5_SET(tirc, tirc, lro_timeout_period_usecs,
1461 MLX5_CAP_ETH(priv->mdev,
1462 lro_timer_supported_periods[2]));
1465 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
1467 MLX5_SET(tirc, tirc, rx_hash_fn,
1468 mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1469 if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1470 void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1471 rx_hash_toeplitz_key);
1472 size_t len = MLX5_FLD_SZ_BYTES(tirc,
1473 rx_hash_toeplitz_key);
1475 MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1476 memcpy(rss_key, priv->params.toeplitz_hash_key, len);
1480 static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
1482 struct mlx5_core_dev *mdev = priv->mdev;
1490 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1491 in = mlx5_vzalloc(inlen);
1495 MLX5_SET(modify_tir_in, in, bitmask.lro, 1);
1496 tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
1498 mlx5e_build_tir_ctx_lro(tirc, priv);
1500 for (tt = 0; tt < MLX5E_NUM_TT; tt++) {
1501 err = mlx5_core_modify_tir(mdev, priv->tirn[tt], in, inlen);
1511 static int mlx5e_refresh_tir_self_loopback_enable(struct mlx5_core_dev *mdev,
1518 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1519 in = mlx5_vzalloc(inlen);
1523 MLX5_SET(modify_tir_in, in, bitmask.self_lb_en, 1);
1525 err = mlx5_core_modify_tir(mdev, tirn, in, inlen);
1532 static int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5e_priv *priv)
1537 for (i = 0; i < MLX5E_NUM_TT; i++) {
1538 err = mlx5e_refresh_tir_self_loopback_enable(priv->mdev,
1547 static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
1549 struct mlx5_core_dev *mdev = priv->mdev;
1550 u16 hw_mtu = MLX5E_SW2HW_MTU(mtu);
1553 err = mlx5_set_port_mtu(mdev, hw_mtu, 1);
1557 /* Update vport context MTU */
1558 mlx5_modify_nic_vport_mtu(mdev, hw_mtu);
1562 static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
1564 struct mlx5_core_dev *mdev = priv->mdev;
1568 err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
1569 if (err || !hw_mtu) /* fallback to port oper mtu */
1570 mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
1572 *mtu = MLX5E_HW2SW_MTU(hw_mtu);
1575 static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
1577 struct mlx5e_priv *priv = netdev_priv(netdev);
1581 err = mlx5e_set_mtu(priv, netdev->mtu);
1585 mlx5e_query_mtu(priv, &mtu);
1586 if (mtu != netdev->mtu)
1587 netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
1588 __func__, mtu, netdev->mtu);
1594 static void mlx5e_netdev_set_tcs(struct net_device *netdev)
1596 struct mlx5e_priv *priv = netdev_priv(netdev);
1597 int nch = priv->params.num_channels;
1598 int ntc = priv->params.num_tc;
1601 netdev_reset_tc(netdev);
1606 netdev_set_num_tc(netdev, ntc);
1608 for (tc = 0; tc < ntc; tc++)
1609 netdev_set_tc_queue(netdev, tc, nch, tc * nch);
1612 int mlx5e_open_locked(struct net_device *netdev)
1614 struct mlx5e_priv *priv = netdev_priv(netdev);
1618 set_bit(MLX5E_STATE_OPENED, &priv->state);
1620 mlx5e_netdev_set_tcs(netdev);
1622 num_txqs = priv->params.num_channels * priv->params.num_tc;
1623 netif_set_real_num_tx_queues(netdev, num_txqs);
1624 netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
1626 err = mlx5e_set_dev_port_mtu(netdev);
1628 goto err_clear_state_opened_flag;
1630 err = mlx5e_open_channels(priv);
1632 netdev_err(netdev, "%s: mlx5e_open_channels failed, %d\n",
1634 goto err_clear_state_opened_flag;
1637 err = mlx5e_refresh_tirs_self_loopback_enable(priv);
1639 netdev_err(netdev, "%s: mlx5e_refresh_tirs_self_loopback_enable failed, %d\n",
1641 goto err_close_channels;
1644 mlx5e_redirect_rqts(priv);
1645 mlx5e_update_carrier(priv);
1646 mlx5e_timestamp_init(priv);
1648 schedule_delayed_work(&priv->update_stats_work, 0);
1653 mlx5e_close_channels(priv);
1654 err_clear_state_opened_flag:
1655 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1659 static int mlx5e_open(struct net_device *netdev)
1661 struct mlx5e_priv *priv = netdev_priv(netdev);
1664 mutex_lock(&priv->state_lock);
1665 err = mlx5e_open_locked(netdev);
1666 mutex_unlock(&priv->state_lock);
1671 int mlx5e_close_locked(struct net_device *netdev)
1673 struct mlx5e_priv *priv = netdev_priv(netdev);
1675 /* May already be CLOSED in case a previous configuration operation
1676 * (e.g RX/TX queue size change) that involves close&open failed.
1678 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
1681 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1683 mlx5e_timestamp_cleanup(priv);
1684 netif_carrier_off(priv->netdev);
1685 mlx5e_redirect_rqts(priv);
1686 mlx5e_close_channels(priv);
1691 static int mlx5e_close(struct net_device *netdev)
1693 struct mlx5e_priv *priv = netdev_priv(netdev);
1696 mutex_lock(&priv->state_lock);
1697 err = mlx5e_close_locked(netdev);
1698 mutex_unlock(&priv->state_lock);
1703 static int mlx5e_create_drop_rq(struct mlx5e_priv *priv,
1704 struct mlx5e_rq *rq,
1705 struct mlx5e_rq_param *param)
1707 struct mlx5_core_dev *mdev = priv->mdev;
1708 void *rqc = param->rqc;
1709 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
1712 param->wq.db_numa_node = param->wq.buf_numa_node;
1714 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
1724 static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
1725 struct mlx5e_cq *cq,
1726 struct mlx5e_cq_param *param)
1728 struct mlx5_core_dev *mdev = priv->mdev;
1729 struct mlx5_core_cq *mcq = &cq->mcq;
1734 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
1739 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
1742 mcq->set_ci_db = cq->wq_ctrl.db.db;
1743 mcq->arm_db = cq->wq_ctrl.db.db + 1;
1744 *mcq->set_ci_db = 0;
1746 mcq->vector = param->eq_ix;
1747 mcq->comp = mlx5e_completion_event;
1748 mcq->event = mlx5e_cq_error_event;
1750 mcq->uar = &priv->cq_uar;
1757 static int mlx5e_open_drop_rq(struct mlx5e_priv *priv)
1759 struct mlx5e_cq_param cq_param;
1760 struct mlx5e_rq_param rq_param;
1761 struct mlx5e_rq *rq = &priv->drop_rq;
1762 struct mlx5e_cq *cq = &priv->drop_rq.cq;
1765 memset(&cq_param, 0, sizeof(cq_param));
1766 memset(&rq_param, 0, sizeof(rq_param));
1767 mlx5e_build_drop_rq_param(&rq_param);
1769 err = mlx5e_create_drop_cq(priv, cq, &cq_param);
1773 err = mlx5e_enable_cq(cq, &cq_param);
1775 goto err_destroy_cq;
1777 err = mlx5e_create_drop_rq(priv, rq, &rq_param);
1779 goto err_disable_cq;
1781 err = mlx5e_enable_rq(rq, &rq_param);
1783 goto err_destroy_rq;
1788 mlx5e_destroy_rq(&priv->drop_rq);
1791 mlx5e_disable_cq(&priv->drop_rq.cq);
1794 mlx5e_destroy_cq(&priv->drop_rq.cq);
1799 static void mlx5e_close_drop_rq(struct mlx5e_priv *priv)
1801 mlx5e_disable_rq(&priv->drop_rq);
1802 mlx5e_destroy_rq(&priv->drop_rq);
1803 mlx5e_disable_cq(&priv->drop_rq.cq);
1804 mlx5e_destroy_cq(&priv->drop_rq.cq);
1807 static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
1809 struct mlx5_core_dev *mdev = priv->mdev;
1810 u32 in[MLX5_ST_SZ_DW(create_tis_in)];
1811 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
1813 memset(in, 0, sizeof(in));
1815 MLX5_SET(tisc, tisc, prio, tc << 1);
1816 MLX5_SET(tisc, tisc, transport_domain, priv->tdn);
1818 return mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc]);
1821 static void mlx5e_destroy_tis(struct mlx5e_priv *priv, int tc)
1823 mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc]);
1826 static int mlx5e_create_tises(struct mlx5e_priv *priv)
1831 for (tc = 0; tc < MLX5E_MAX_NUM_TC; tc++) {
1832 err = mlx5e_create_tis(priv, tc);
1834 goto err_close_tises;
1840 for (tc--; tc >= 0; tc--)
1841 mlx5e_destroy_tis(priv, tc);
1846 static void mlx5e_destroy_tises(struct mlx5e_priv *priv)
1850 for (tc = 0; tc < MLX5E_MAX_NUM_TC; tc++)
1851 mlx5e_destroy_tis(priv, tc);
1854 static void mlx5e_build_tir_ctx(struct mlx5e_priv *priv, u32 *tirc, int tt)
1856 void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer);
1858 MLX5_SET(tirc, tirc, transport_domain, priv->tdn);
1860 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
1861 MLX5_HASH_FIELD_SEL_DST_IP)
1863 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
1864 MLX5_HASH_FIELD_SEL_DST_IP |\
1865 MLX5_HASH_FIELD_SEL_L4_SPORT |\
1866 MLX5_HASH_FIELD_SEL_L4_DPORT)
1868 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
1869 MLX5_HASH_FIELD_SEL_DST_IP |\
1870 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
1872 mlx5e_build_tir_ctx_lro(tirc, priv);
1874 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
1878 MLX5_SET(tirc, tirc, indirect_table,
1879 priv->rqtn[MLX5E_SINGLE_RQ_RQT]);
1880 MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_INVERTED_XOR8);
1883 MLX5_SET(tirc, tirc, indirect_table,
1884 priv->rqtn[MLX5E_INDIRECTION_RQT]);
1885 mlx5e_build_tir_ctx_hash(tirc, priv);
1890 case MLX5E_TT_IPV4_TCP:
1891 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1892 MLX5_L3_PROT_TYPE_IPV4);
1893 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1894 MLX5_L4_PROT_TYPE_TCP);
1895 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1896 MLX5_HASH_IP_L4PORTS);
1899 case MLX5E_TT_IPV6_TCP:
1900 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1901 MLX5_L3_PROT_TYPE_IPV6);
1902 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1903 MLX5_L4_PROT_TYPE_TCP);
1904 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1905 MLX5_HASH_IP_L4PORTS);
1908 case MLX5E_TT_IPV4_UDP:
1909 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1910 MLX5_L3_PROT_TYPE_IPV4);
1911 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1912 MLX5_L4_PROT_TYPE_UDP);
1913 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1914 MLX5_HASH_IP_L4PORTS);
1917 case MLX5E_TT_IPV6_UDP:
1918 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1919 MLX5_L3_PROT_TYPE_IPV6);
1920 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
1921 MLX5_L4_PROT_TYPE_UDP);
1922 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1923 MLX5_HASH_IP_L4PORTS);
1926 case MLX5E_TT_IPV4_IPSEC_AH:
1927 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1928 MLX5_L3_PROT_TYPE_IPV4);
1929 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1930 MLX5_HASH_IP_IPSEC_SPI);
1933 case MLX5E_TT_IPV6_IPSEC_AH:
1934 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1935 MLX5_L3_PROT_TYPE_IPV6);
1936 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1937 MLX5_HASH_IP_IPSEC_SPI);
1940 case MLX5E_TT_IPV4_IPSEC_ESP:
1941 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1942 MLX5_L3_PROT_TYPE_IPV4);
1943 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1944 MLX5_HASH_IP_IPSEC_SPI);
1947 case MLX5E_TT_IPV6_IPSEC_ESP:
1948 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1949 MLX5_L3_PROT_TYPE_IPV6);
1950 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1951 MLX5_HASH_IP_IPSEC_SPI);
1955 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1956 MLX5_L3_PROT_TYPE_IPV4);
1957 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1962 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
1963 MLX5_L3_PROT_TYPE_IPV6);
1964 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
1970 static int mlx5e_create_tir(struct mlx5e_priv *priv, int tt)
1972 struct mlx5_core_dev *mdev = priv->mdev;
1978 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
1979 in = mlx5_vzalloc(inlen);
1983 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
1985 mlx5e_build_tir_ctx(priv, tirc, tt);
1987 err = mlx5_core_create_tir(mdev, in, inlen, &priv->tirn[tt]);
1994 static void mlx5e_destroy_tir(struct mlx5e_priv *priv, int tt)
1996 mlx5_core_destroy_tir(priv->mdev, priv->tirn[tt]);
1999 static int mlx5e_create_tirs(struct mlx5e_priv *priv)
2004 for (i = 0; i < MLX5E_NUM_TT; i++) {
2005 err = mlx5e_create_tir(priv, i);
2007 goto err_destroy_tirs;
2013 for (i--; i >= 0; i--)
2014 mlx5e_destroy_tir(priv, i);
2019 static void mlx5e_destroy_tirs(struct mlx5e_priv *priv)
2023 for (i = 0; i < MLX5E_NUM_TT; i++)
2024 mlx5e_destroy_tir(priv, i);
2027 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd)
2032 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
2035 for (i = 0; i < priv->params.num_channels; i++) {
2036 err = mlx5e_modify_rq_vsd(&priv->channel[i]->rq, vsd);
2044 static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
2046 struct mlx5e_priv *priv = netdev_priv(netdev);
2050 if (tc && tc != MLX5E_MAX_NUM_TC)
2053 mutex_lock(&priv->state_lock);
2055 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2057 mlx5e_close_locked(priv->netdev);
2059 priv->params.num_tc = tc ? tc : 1;
2062 err = mlx5e_open_locked(priv->netdev);
2064 mutex_unlock(&priv->state_lock);
2069 static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
2070 __be16 proto, struct tc_to_netdev *tc)
2072 struct mlx5e_priv *priv = netdev_priv(dev);
2074 if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
2078 case TC_SETUP_CLSFLOWER:
2079 switch (tc->cls_flower->command) {
2080 case TC_CLSFLOWER_REPLACE:
2081 return mlx5e_configure_flower(priv, proto, tc->cls_flower);
2082 case TC_CLSFLOWER_DESTROY:
2083 return mlx5e_delete_flower(priv, tc->cls_flower);
2090 if (tc->type != TC_SETUP_MQPRIO)
2093 return mlx5e_setup_tc(dev, tc->tc);
2096 static struct rtnl_link_stats64 *
2097 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
2099 struct mlx5e_priv *priv = netdev_priv(dev);
2100 struct mlx5e_sw_stats *sstats = &priv->stats.sw;
2101 struct mlx5e_vport_stats *vstats = &priv->stats.vport;
2102 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
2104 stats->rx_packets = sstats->rx_packets;
2105 stats->rx_bytes = sstats->rx_bytes;
2106 stats->tx_packets = sstats->tx_packets;
2107 stats->tx_bytes = sstats->tx_bytes;
2109 stats->rx_dropped = priv->stats.qcnt.rx_out_of_buffer;
2110 stats->tx_dropped = sstats->tx_queue_dropped;
2112 stats->rx_length_errors =
2113 PPORT_802_3_GET(pstats, a_in_range_length_errors) +
2114 PPORT_802_3_GET(pstats, a_out_of_range_length_field) +
2115 PPORT_802_3_GET(pstats, a_frame_too_long_errors);
2116 stats->rx_crc_errors =
2117 PPORT_802_3_GET(pstats, a_frame_check_sequence_errors);
2118 stats->rx_frame_errors = PPORT_802_3_GET(pstats, a_alignment_errors);
2119 stats->tx_aborted_errors = PPORT_2863_GET(pstats, if_out_discards);
2120 stats->tx_carrier_errors =
2121 PPORT_802_3_GET(pstats, a_symbol_error_during_carrier);
2122 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
2123 stats->rx_frame_errors;
2124 stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors;
2126 /* vport multicast also counts packets that are dropped due to steering
2127 * or rx out of buffer
2130 VPORT_COUNTER_GET(vstats, received_eth_multicast.packets);
2135 static void mlx5e_set_rx_mode(struct net_device *dev)
2137 struct mlx5e_priv *priv = netdev_priv(dev);
2139 schedule_work(&priv->set_rx_mode_work);
2142 static int mlx5e_set_mac(struct net_device *netdev, void *addr)
2144 struct mlx5e_priv *priv = netdev_priv(netdev);
2145 struct sockaddr *saddr = addr;
2147 if (!is_valid_ether_addr(saddr->sa_data))
2148 return -EADDRNOTAVAIL;
2150 netif_addr_lock_bh(netdev);
2151 ether_addr_copy(netdev->dev_addr, saddr->sa_data);
2152 netif_addr_unlock_bh(netdev);
2154 schedule_work(&priv->set_rx_mode_work);
2159 #define MLX5E_SET_FEATURE(netdev, feature, enable) \
2162 netdev->features |= feature; \
2164 netdev->features &= ~feature; \
2167 typedef int (*mlx5e_feature_handler)(struct net_device *netdev, bool enable);
2169 static int set_feature_lro(struct net_device *netdev, bool enable)
2171 struct mlx5e_priv *priv = netdev_priv(netdev);
2172 bool was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2175 mutex_lock(&priv->state_lock);
2177 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2178 mlx5e_close_locked(priv->netdev);
2180 priv->params.lro_en = enable;
2181 err = mlx5e_modify_tirs_lro(priv);
2183 netdev_err(netdev, "lro modify failed, %d\n", err);
2184 priv->params.lro_en = !enable;
2187 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2188 mlx5e_open_locked(priv->netdev);
2190 mutex_unlock(&priv->state_lock);
2195 static int set_feature_vlan_filter(struct net_device *netdev, bool enable)
2197 struct mlx5e_priv *priv = netdev_priv(netdev);
2200 mlx5e_enable_vlan_filter(priv);
2202 mlx5e_disable_vlan_filter(priv);
2207 static int set_feature_tc_num_filters(struct net_device *netdev, bool enable)
2209 struct mlx5e_priv *priv = netdev_priv(netdev);
2211 if (!enable && mlx5e_tc_num_filters(priv)) {
2213 "Active offloaded tc filters, can't turn hw_tc_offload off\n");
2220 static int set_feature_rx_all(struct net_device *netdev, bool enable)
2222 struct mlx5e_priv *priv = netdev_priv(netdev);
2223 struct mlx5_core_dev *mdev = priv->mdev;
2225 return mlx5_set_port_fcs(mdev, !enable);
2228 static int set_feature_rx_vlan(struct net_device *netdev, bool enable)
2230 struct mlx5e_priv *priv = netdev_priv(netdev);
2233 mutex_lock(&priv->state_lock);
2235 priv->params.vlan_strip_disable = !enable;
2236 err = mlx5e_modify_rqs_vsd(priv, !enable);
2238 priv->params.vlan_strip_disable = enable;
2240 mutex_unlock(&priv->state_lock);
2245 static int mlx5e_handle_feature(struct net_device *netdev,
2246 netdev_features_t wanted_features,
2247 netdev_features_t feature,
2248 mlx5e_feature_handler feature_handler)
2250 netdev_features_t changes = wanted_features ^ netdev->features;
2251 bool enable = !!(wanted_features & feature);
2254 if (!(changes & feature))
2257 err = feature_handler(netdev, enable);
2259 netdev_err(netdev, "%s feature 0x%llx failed err %d\n",
2260 enable ? "Enable" : "Disable", feature, err);
2264 MLX5E_SET_FEATURE(netdev, feature, enable);
2268 static int mlx5e_set_features(struct net_device *netdev,
2269 netdev_features_t features)
2273 err = mlx5e_handle_feature(netdev, features, NETIF_F_LRO,
2275 err |= mlx5e_handle_feature(netdev, features,
2276 NETIF_F_HW_VLAN_CTAG_FILTER,
2277 set_feature_vlan_filter);
2278 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_TC,
2279 set_feature_tc_num_filters);
2280 err |= mlx5e_handle_feature(netdev, features, NETIF_F_RXALL,
2281 set_feature_rx_all);
2282 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_VLAN_CTAG_RX,
2283 set_feature_rx_vlan);
2285 return err ? -EINVAL : 0;
2288 #define MXL5_HW_MIN_MTU 64
2289 #define MXL5E_MIN_MTU (MXL5_HW_MIN_MTU + ETH_FCS_LEN)
2291 static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
2293 struct mlx5e_priv *priv = netdev_priv(netdev);
2294 struct mlx5_core_dev *mdev = priv->mdev;
2300 mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
2302 max_mtu = MLX5E_HW2SW_MTU(max_mtu);
2303 min_mtu = MLX5E_HW2SW_MTU(MXL5E_MIN_MTU);
2305 if (new_mtu > max_mtu || new_mtu < min_mtu) {
2307 "%s: Bad MTU (%d), valid range is: [%d..%d]\n",
2308 __func__, new_mtu, min_mtu, max_mtu);
2312 mutex_lock(&priv->state_lock);
2314 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2316 mlx5e_close_locked(netdev);
2318 netdev->mtu = new_mtu;
2321 err = mlx5e_open_locked(netdev);
2323 mutex_unlock(&priv->state_lock);
2328 static int mlx5e_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2332 return mlx5e_hwstamp_set(dev, ifr);
2334 return mlx5e_hwstamp_get(dev, ifr);
2340 static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2342 struct mlx5e_priv *priv = netdev_priv(dev);
2343 struct mlx5_core_dev *mdev = priv->mdev;
2345 return mlx5_eswitch_set_vport_mac(mdev->priv.eswitch, vf + 1, mac);
2348 static int mlx5e_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2350 struct mlx5e_priv *priv = netdev_priv(dev);
2351 struct mlx5_core_dev *mdev = priv->mdev;
2353 return mlx5_eswitch_set_vport_vlan(mdev->priv.eswitch, vf + 1,
2357 static int mlx5_vport_link2ifla(u8 esw_link)
2360 case MLX5_ESW_VPORT_ADMIN_STATE_DOWN:
2361 return IFLA_VF_LINK_STATE_DISABLE;
2362 case MLX5_ESW_VPORT_ADMIN_STATE_UP:
2363 return IFLA_VF_LINK_STATE_ENABLE;
2365 return IFLA_VF_LINK_STATE_AUTO;
2368 static int mlx5_ifla_link2vport(u8 ifla_link)
2370 switch (ifla_link) {
2371 case IFLA_VF_LINK_STATE_DISABLE:
2372 return MLX5_ESW_VPORT_ADMIN_STATE_DOWN;
2373 case IFLA_VF_LINK_STATE_ENABLE:
2374 return MLX5_ESW_VPORT_ADMIN_STATE_UP;
2376 return MLX5_ESW_VPORT_ADMIN_STATE_AUTO;
2379 static int mlx5e_set_vf_link_state(struct net_device *dev, int vf,
2382 struct mlx5e_priv *priv = netdev_priv(dev);
2383 struct mlx5_core_dev *mdev = priv->mdev;
2385 return mlx5_eswitch_set_vport_state(mdev->priv.eswitch, vf + 1,
2386 mlx5_ifla_link2vport(link_state));
2389 static int mlx5e_get_vf_config(struct net_device *dev,
2390 int vf, struct ifla_vf_info *ivi)
2392 struct mlx5e_priv *priv = netdev_priv(dev);
2393 struct mlx5_core_dev *mdev = priv->mdev;
2396 err = mlx5_eswitch_get_vport_config(mdev->priv.eswitch, vf + 1, ivi);
2399 ivi->linkstate = mlx5_vport_link2ifla(ivi->linkstate);
2403 static int mlx5e_get_vf_stats(struct net_device *dev,
2404 int vf, struct ifla_vf_stats *vf_stats)
2406 struct mlx5e_priv *priv = netdev_priv(dev);
2407 struct mlx5_core_dev *mdev = priv->mdev;
2409 return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
2413 static void mlx5e_add_vxlan_port(struct net_device *netdev,
2414 sa_family_t sa_family, __be16 port)
2416 struct mlx5e_priv *priv = netdev_priv(netdev);
2418 if (!mlx5e_vxlan_allowed(priv->mdev))
2421 mlx5e_vxlan_add_port(priv, be16_to_cpu(port));
2424 static void mlx5e_del_vxlan_port(struct net_device *netdev,
2425 sa_family_t sa_family, __be16 port)
2427 struct mlx5e_priv *priv = netdev_priv(netdev);
2429 if (!mlx5e_vxlan_allowed(priv->mdev))
2432 mlx5e_vxlan_del_port(priv, be16_to_cpu(port));
2435 static netdev_features_t mlx5e_vxlan_features_check(struct mlx5e_priv *priv,
2436 struct sk_buff *skb,
2437 netdev_features_t features)
2439 struct udphdr *udph;
2443 switch (vlan_get_protocol(skb)) {
2444 case htons(ETH_P_IP):
2445 proto = ip_hdr(skb)->protocol;
2447 case htons(ETH_P_IPV6):
2448 proto = ipv6_hdr(skb)->nexthdr;
2454 if (proto == IPPROTO_UDP) {
2455 udph = udp_hdr(skb);
2456 port = be16_to_cpu(udph->dest);
2459 /* Verify if UDP port is being offloaded by HW */
2460 if (port && mlx5e_vxlan_lookup_port(priv, port))
2464 /* Disable CSUM and GSO if the udp dport is not offloaded by HW */
2465 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2468 static netdev_features_t mlx5e_features_check(struct sk_buff *skb,
2469 struct net_device *netdev,
2470 netdev_features_t features)
2472 struct mlx5e_priv *priv = netdev_priv(netdev);
2474 features = vlan_features_check(skb, features);
2475 features = vxlan_features_check(skb, features);
2477 /* Validate if the tunneled packet is being offloaded by HW */
2478 if (skb->encapsulation &&
2479 (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
2480 return mlx5e_vxlan_features_check(priv, skb, features);
2485 static const struct net_device_ops mlx5e_netdev_ops_basic = {
2486 .ndo_open = mlx5e_open,
2487 .ndo_stop = mlx5e_close,
2488 .ndo_start_xmit = mlx5e_xmit,
2489 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2490 .ndo_select_queue = mlx5e_select_queue,
2491 .ndo_get_stats64 = mlx5e_get_stats,
2492 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2493 .ndo_set_mac_address = mlx5e_set_mac,
2494 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2495 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2496 .ndo_set_features = mlx5e_set_features,
2497 .ndo_change_mtu = mlx5e_change_mtu,
2498 .ndo_do_ioctl = mlx5e_ioctl,
2501 static const struct net_device_ops mlx5e_netdev_ops_sriov = {
2502 .ndo_open = mlx5e_open,
2503 .ndo_stop = mlx5e_close,
2504 .ndo_start_xmit = mlx5e_xmit,
2505 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2506 .ndo_select_queue = mlx5e_select_queue,
2507 .ndo_get_stats64 = mlx5e_get_stats,
2508 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2509 .ndo_set_mac_address = mlx5e_set_mac,
2510 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2511 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2512 .ndo_set_features = mlx5e_set_features,
2513 .ndo_change_mtu = mlx5e_change_mtu,
2514 .ndo_do_ioctl = mlx5e_ioctl,
2515 .ndo_add_vxlan_port = mlx5e_add_vxlan_port,
2516 .ndo_del_vxlan_port = mlx5e_del_vxlan_port,
2517 .ndo_features_check = mlx5e_features_check,
2518 .ndo_set_vf_mac = mlx5e_set_vf_mac,
2519 .ndo_set_vf_vlan = mlx5e_set_vf_vlan,
2520 .ndo_get_vf_config = mlx5e_get_vf_config,
2521 .ndo_set_vf_link_state = mlx5e_set_vf_link_state,
2522 .ndo_get_vf_stats = mlx5e_get_vf_stats,
2525 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
2527 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
2529 if (!MLX5_CAP_GEN(mdev, eth_net_offloads) ||
2530 !MLX5_CAP_GEN(mdev, nic_flow_table) ||
2531 !MLX5_CAP_ETH(mdev, csum_cap) ||
2532 !MLX5_CAP_ETH(mdev, max_lso_cap) ||
2533 !MLX5_CAP_ETH(mdev, vlan_cap) ||
2534 !MLX5_CAP_ETH(mdev, rss_ind_tbl_cap) ||
2535 MLX5_CAP_FLOWTABLE(mdev,
2536 flow_table_properties_nic_receive.max_ft_level)
2538 mlx5_core_warn(mdev,
2539 "Not creating net device, some required device capabilities are missing\n");
2542 if (!MLX5_CAP_ETH(mdev, self_lb_en_modifiable))
2543 mlx5_core_warn(mdev, "Self loop back prevention is not supported\n");
2544 if (!MLX5_CAP_GEN(mdev, cq_moderation))
2545 mlx5_core_warn(mdev, "CQ modiration is not supported\n");
2550 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev)
2552 int bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
2554 return bf_buf_size -
2555 sizeof(struct mlx5e_tx_wqe) +
2556 2 /*sizeof(mlx5e_tx_wqe.inline_hdr_start)*/;
2559 #ifdef CONFIG_MLX5_CORE_EN_DCB
2560 static void mlx5e_ets_init(struct mlx5e_priv *priv)
2564 priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
2565 for (i = 0; i < priv->params.ets.ets_cap; i++) {
2566 priv->params.ets.tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
2567 priv->params.ets.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
2568 priv->params.ets.prio_tc[i] = i;
2571 /* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
2572 priv->params.ets.prio_tc[0] = 1;
2573 priv->params.ets.prio_tc[1] = 0;
2577 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
2578 u32 *indirection_rqt, int len,
2581 int node = mdev->priv.numa_node;
2582 int node_num_of_cores;
2586 node = first_online_node;
2588 node_num_of_cores = cpumask_weight(cpumask_of_node(node));
2590 if (node_num_of_cores)
2591 num_channels = min_t(int, num_channels, node_num_of_cores);
2593 for (i = 0; i < len; i++)
2594 indirection_rqt[i] = i % num_channels;
2597 static bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
2599 return MLX5_CAP_GEN(mdev, striding_rq) &&
2600 MLX5_CAP_GEN(mdev, umr_ptr_rlky) &&
2601 MLX5_CAP_ETH(mdev, reg_umr_sq);
2604 static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
2605 struct net_device *netdev,
2608 struct mlx5e_priv *priv = netdev_priv(netdev);
2610 priv->params.log_sq_size =
2611 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
2612 priv->params.rq_wq_type = mlx5e_check_fragmented_striding_rq_cap(mdev) ?
2613 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
2614 MLX5_WQ_TYPE_LINKED_LIST;
2616 switch (priv->params.rq_wq_type) {
2617 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
2618 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW;
2619 priv->params.lro_en = true;
2621 default: /* MLX5_WQ_TYPE_LINKED_LIST */
2622 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
2625 priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
2626 BIT(priv->params.log_rq_size));
2627 priv->params.rx_cq_moderation_usec =
2628 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2629 priv->params.rx_cq_moderation_pkts =
2630 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2631 priv->params.tx_cq_moderation_usec =
2632 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
2633 priv->params.tx_cq_moderation_pkts =
2634 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
2635 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
2636 priv->params.num_tc = 1;
2637 priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
2639 netdev_rss_key_fill(priv->params.toeplitz_hash_key,
2640 sizeof(priv->params.toeplitz_hash_key));
2642 mlx5e_build_default_indir_rqt(mdev, priv->params.indirection_rqt,
2643 MLX5E_INDIR_RQT_SIZE, num_channels);
2645 priv->params.lro_wqe_sz =
2646 MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
2649 priv->netdev = netdev;
2650 priv->params.num_channels = num_channels;
2652 #ifdef CONFIG_MLX5_CORE_EN_DCB
2653 mlx5e_ets_init(priv);
2656 mutex_init(&priv->state_lock);
2658 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
2659 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
2660 INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
2663 static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
2665 struct mlx5e_priv *priv = netdev_priv(netdev);
2667 mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
2668 if (is_zero_ether_addr(netdev->dev_addr) &&
2669 !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
2670 eth_hw_addr_random(netdev);
2671 mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr);
2675 static void mlx5e_build_netdev(struct net_device *netdev)
2677 struct mlx5e_priv *priv = netdev_priv(netdev);
2678 struct mlx5_core_dev *mdev = priv->mdev;
2682 SET_NETDEV_DEV(netdev, &mdev->pdev->dev);
2684 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
2685 netdev->netdev_ops = &mlx5e_netdev_ops_sriov;
2686 #ifdef CONFIG_MLX5_CORE_EN_DCB
2687 netdev->dcbnl_ops = &mlx5e_dcbnl_ops;
2690 netdev->netdev_ops = &mlx5e_netdev_ops_basic;
2693 netdev->watchdog_timeo = 15 * HZ;
2695 netdev->ethtool_ops = &mlx5e_ethtool_ops;
2697 netdev->vlan_features |= NETIF_F_SG;
2698 netdev->vlan_features |= NETIF_F_IP_CSUM;
2699 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
2700 netdev->vlan_features |= NETIF_F_GRO;
2701 netdev->vlan_features |= NETIF_F_TSO;
2702 netdev->vlan_features |= NETIF_F_TSO6;
2703 netdev->vlan_features |= NETIF_F_RXCSUM;
2704 netdev->vlan_features |= NETIF_F_RXHASH;
2706 if (!!MLX5_CAP_ETH(mdev, lro_cap))
2707 netdev->vlan_features |= NETIF_F_LRO;
2709 netdev->hw_features = netdev->vlan_features;
2710 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
2711 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
2712 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2714 if (mlx5e_vxlan_allowed(mdev)) {
2715 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2716 netdev->hw_enc_features |= NETIF_F_IP_CSUM;
2717 netdev->hw_enc_features |= NETIF_F_RXCSUM;
2718 netdev->hw_enc_features |= NETIF_F_TSO;
2719 netdev->hw_enc_features |= NETIF_F_TSO6;
2720 netdev->hw_enc_features |= NETIF_F_RXHASH;
2721 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL;
2724 mlx5_query_port_fcs(mdev, &fcs_supported, &fcs_enabled);
2727 netdev->hw_features |= NETIF_F_RXALL;
2729 netdev->features = netdev->hw_features;
2730 if (!priv->params.lro_en)
2731 netdev->features &= ~NETIF_F_LRO;
2734 netdev->features &= ~NETIF_F_RXALL;
2736 #define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
2737 if (FT_CAP(flow_modify_en) &&
2738 FT_CAP(modify_root) &&
2739 FT_CAP(identified_miss_table_mode) &&
2740 FT_CAP(flow_table_modify))
2741 priv->netdev->hw_features |= NETIF_F_HW_TC;
2743 netdev->features |= NETIF_F_HIGHDMA;
2745 netdev->priv_flags |= IFF_UNICAST_FLT;
2747 mlx5e_set_netdev_dev_addr(netdev);
2750 static int mlx5e_create_mkey(struct mlx5e_priv *priv, u32 pdn,
2751 struct mlx5_core_mkey *mkey)
2753 struct mlx5_core_dev *mdev = priv->mdev;
2754 struct mlx5_create_mkey_mbox_in *in;
2757 in = mlx5_vzalloc(sizeof(*in));
2761 in->seg.flags = MLX5_PERM_LOCAL_WRITE |
2762 MLX5_PERM_LOCAL_READ |
2763 MLX5_ACCESS_MODE_PA;
2764 in->seg.flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64);
2765 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
2767 err = mlx5_core_create_mkey(mdev, mkey, in, sizeof(*in), NULL, NULL,
2775 static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
2777 struct mlx5_core_dev *mdev = priv->mdev;
2780 err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter);
2782 mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err);
2783 priv->q_counter = 0;
2787 static void mlx5e_destroy_q_counter(struct mlx5e_priv *priv)
2789 if (!priv->q_counter)
2792 mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter);
2795 static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
2797 struct mlx5_core_dev *mdev = priv->mdev;
2798 struct mlx5_create_mkey_mbox_in *in;
2799 struct mlx5_mkey_seg *mkc;
2800 int inlen = sizeof(*in);
2802 mlx5e_get_max_num_channels(mdev) * MLX5_CHANNEL_MAX_NUM_MTTS;
2805 in = mlx5_vzalloc(inlen);
2810 mkc->status = MLX5_MKEY_STATUS_FREE;
2811 mkc->flags = MLX5_PERM_UMR_EN |
2812 MLX5_PERM_LOCAL_READ |
2813 MLX5_PERM_LOCAL_WRITE |
2814 MLX5_ACCESS_MODE_MTT;
2816 mkc->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
2817 mkc->flags_pd = cpu_to_be32(priv->pdn);
2818 mkc->len = cpu_to_be64(npages << PAGE_SHIFT);
2819 mkc->xlt_oct_size = cpu_to_be32(mlx5e_get_mtt_octw(npages));
2820 mkc->log2_page_size = PAGE_SHIFT;
2822 err = mlx5_core_create_mkey(mdev, &priv->umr_mkey, in, inlen, NULL,
2830 static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
2832 struct net_device *netdev;
2833 struct mlx5e_priv *priv;
2834 int nch = mlx5e_get_max_num_channels(mdev);
2837 if (mlx5e_check_required_hca_cap(mdev))
2840 netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
2841 nch * MLX5E_MAX_NUM_TC,
2844 mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
2848 mlx5e_build_netdev_priv(mdev, netdev, nch);
2849 mlx5e_build_netdev(netdev);
2851 netif_carrier_off(netdev);
2853 priv = netdev_priv(netdev);
2855 err = mlx5_alloc_map_uar(mdev, &priv->cq_uar, false);
2857 mlx5_core_err(mdev, "alloc_map uar failed, %d\n", err);
2858 goto err_free_netdev;
2861 err = mlx5_core_alloc_pd(mdev, &priv->pdn);
2863 mlx5_core_err(mdev, "alloc pd failed, %d\n", err);
2864 goto err_unmap_free_uar;
2867 err = mlx5_core_alloc_transport_domain(mdev, &priv->tdn);
2869 mlx5_core_err(mdev, "alloc td failed, %d\n", err);
2870 goto err_dealloc_pd;
2873 err = mlx5e_create_mkey(priv, priv->pdn, &priv->mkey);
2875 mlx5_core_err(mdev, "create mkey failed, %d\n", err);
2876 goto err_dealloc_transport_domain;
2879 err = mlx5e_create_umr_mkey(priv);
2881 mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
2882 goto err_destroy_mkey;
2885 err = mlx5e_create_tises(priv);
2887 mlx5_core_warn(mdev, "create tises failed, %d\n", err);
2888 goto err_destroy_umr_mkey;
2891 err = mlx5e_open_drop_rq(priv);
2893 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
2894 goto err_destroy_tises;
2897 err = mlx5e_create_rqt(priv, MLX5E_INDIRECTION_RQT);
2899 mlx5_core_warn(mdev, "create rqt(INDIR) failed, %d\n", err);
2900 goto err_close_drop_rq;
2903 err = mlx5e_create_rqt(priv, MLX5E_SINGLE_RQ_RQT);
2905 mlx5_core_warn(mdev, "create rqt(SINGLE) failed, %d\n", err);
2906 goto err_destroy_rqt_indir;
2909 err = mlx5e_create_tirs(priv);
2911 mlx5_core_warn(mdev, "create tirs failed, %d\n", err);
2912 goto err_destroy_rqt_single;
2915 err = mlx5e_create_flow_tables(priv);
2917 mlx5_core_warn(mdev, "create flow tables failed, %d\n", err);
2918 goto err_destroy_tirs;
2921 mlx5e_create_q_counter(priv);
2923 mlx5e_init_eth_addr(priv);
2925 mlx5e_vxlan_init(priv);
2927 err = mlx5e_tc_init(priv);
2929 goto err_dealloc_q_counters;
2931 #ifdef CONFIG_MLX5_CORE_EN_DCB
2932 mlx5e_dcbnl_ieee_setets_core(priv, &priv->params.ets);
2935 err = register_netdev(netdev);
2937 mlx5_core_err(mdev, "register_netdev failed, %d\n", err);
2938 goto err_tc_cleanup;
2941 if (mlx5e_vxlan_allowed(mdev)) {
2943 vxlan_get_rx_port(netdev);
2947 mlx5e_enable_async_events(priv);
2948 schedule_work(&priv->set_rx_mode_work);
2953 mlx5e_tc_cleanup(priv);
2955 err_dealloc_q_counters:
2956 mlx5e_destroy_q_counter(priv);
2957 mlx5e_destroy_flow_tables(priv);
2960 mlx5e_destroy_tirs(priv);
2962 err_destroy_rqt_single:
2963 mlx5e_destroy_rqt(priv, MLX5E_SINGLE_RQ_RQT);
2965 err_destroy_rqt_indir:
2966 mlx5e_destroy_rqt(priv, MLX5E_INDIRECTION_RQT);
2969 mlx5e_close_drop_rq(priv);
2972 mlx5e_destroy_tises(priv);
2974 err_destroy_umr_mkey:
2975 mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
2978 mlx5_core_destroy_mkey(mdev, &priv->mkey);
2980 err_dealloc_transport_domain:
2981 mlx5_core_dealloc_transport_domain(mdev, priv->tdn);
2984 mlx5_core_dealloc_pd(mdev, priv->pdn);
2987 mlx5_unmap_free_uar(mdev, &priv->cq_uar);
2990 free_netdev(netdev);
2995 static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, void *vpriv)
2997 struct mlx5e_priv *priv = vpriv;
2998 struct net_device *netdev = priv->netdev;
3000 set_bit(MLX5E_STATE_DESTROYING, &priv->state);
3002 schedule_work(&priv->set_rx_mode_work);
3003 mlx5e_disable_async_events(priv);
3004 flush_scheduled_work();
3005 if (test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state)) {
3006 netif_device_detach(netdev);
3007 mutex_lock(&priv->state_lock);
3008 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
3009 mlx5e_close_locked(netdev);
3010 mutex_unlock(&priv->state_lock);
3012 unregister_netdev(netdev);
3015 mlx5e_tc_cleanup(priv);
3016 mlx5e_vxlan_cleanup(priv);
3017 mlx5e_destroy_q_counter(priv);
3018 mlx5e_destroy_flow_tables(priv);
3019 mlx5e_destroy_tirs(priv);
3020 mlx5e_destroy_rqt(priv, MLX5E_SINGLE_RQ_RQT);
3021 mlx5e_destroy_rqt(priv, MLX5E_INDIRECTION_RQT);
3022 mlx5e_close_drop_rq(priv);
3023 mlx5e_destroy_tises(priv);
3024 mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
3025 mlx5_core_destroy_mkey(priv->mdev, &priv->mkey);
3026 mlx5_core_dealloc_transport_domain(priv->mdev, priv->tdn);
3027 mlx5_core_dealloc_pd(priv->mdev, priv->pdn);
3028 mlx5_unmap_free_uar(priv->mdev, &priv->cq_uar);
3030 if (!test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state))
3031 free_netdev(netdev);
3034 static void *mlx5e_get_netdev(void *vpriv)
3036 struct mlx5e_priv *priv = vpriv;
3038 return priv->netdev;
3041 static struct mlx5_interface mlx5e_interface = {
3042 .add = mlx5e_create_netdev,
3043 .remove = mlx5e_destroy_netdev,
3044 .event = mlx5e_async_event,
3045 .protocol = MLX5_INTERFACE_PROTOCOL_ETH,
3046 .get_dev = mlx5e_get_netdev,
3049 void mlx5e_init(void)
3051 mlx5_register_interface(&mlx5e_interface);
3054 void mlx5e_cleanup(void)
3056 mlx5_unregister_interface(&mlx5e_interface);