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>
43 MLX5_EN_QP_FLUSH_TIMEOUT_MS = 5000,
44 MLX5_EN_QP_FLUSH_MSLEEP_QUANT = 20,
45 MLX5_EN_QP_FLUSH_MAX_ITER = MLX5_EN_QP_FLUSH_TIMEOUT_MS /
46 MLX5_EN_QP_FLUSH_MSLEEP_QUANT,
49 struct mlx5e_rq_param {
50 u32 rqc[MLX5_ST_SZ_DW(rqc)];
51 struct mlx5_wq_param wq;
55 struct mlx5e_sq_param {
56 u32 sqc[MLX5_ST_SZ_DW(sqc)];
57 struct mlx5_wq_param wq;
63 struct mlx5e_cq_param {
64 u32 cqc[MLX5_ST_SZ_DW(cqc)];
65 struct mlx5_wq_param wq;
70 struct mlx5e_channel_param {
71 struct mlx5e_rq_param rq;
72 struct mlx5e_sq_param sq;
73 struct mlx5e_sq_param icosq;
74 struct mlx5e_cq_param rx_cq;
75 struct mlx5e_cq_param tx_cq;
76 struct mlx5e_cq_param icosq_cq;
79 static void mlx5e_update_carrier(struct mlx5e_priv *priv)
81 struct mlx5_core_dev *mdev = priv->mdev;
84 port_state = mlx5_query_vport_state(mdev,
85 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT, 0);
87 if (port_state == VPORT_STATE_UP) {
88 netdev_info(priv->netdev, "Link up\n");
89 netif_carrier_on(priv->netdev);
91 netdev_info(priv->netdev, "Link down\n");
92 netif_carrier_off(priv->netdev);
96 static void mlx5e_update_carrier_work(struct work_struct *work)
98 struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
101 mutex_lock(&priv->state_lock);
102 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
103 mlx5e_update_carrier(priv);
104 mutex_unlock(&priv->state_lock);
107 static void mlx5e_tx_timeout_work(struct work_struct *work)
109 struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
114 mutex_lock(&priv->state_lock);
115 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
117 mlx5e_close_locked(priv->netdev);
118 err = mlx5e_open_locked(priv->netdev);
120 netdev_err(priv->netdev, "mlx5e_open_locked failed recovering from a tx_timeout, err(%d).\n",
123 mutex_unlock(&priv->state_lock);
127 static void mlx5e_update_sw_counters(struct mlx5e_priv *priv)
129 struct mlx5e_sw_stats *s = &priv->stats.sw;
130 struct mlx5e_rq_stats *rq_stats;
131 struct mlx5e_sq_stats *sq_stats;
132 u64 tx_offload_none = 0;
135 memset(s, 0, sizeof(*s));
136 for (i = 0; i < priv->params.num_channels; i++) {
137 rq_stats = &priv->channel[i]->rq.stats;
139 s->rx_packets += rq_stats->packets;
140 s->rx_bytes += rq_stats->bytes;
141 s->rx_lro_packets += rq_stats->lro_packets;
142 s->rx_lro_bytes += rq_stats->lro_bytes;
143 s->rx_csum_none += rq_stats->csum_none;
144 s->rx_csum_complete += rq_stats->csum_complete;
145 s->rx_csum_unnecessary_inner += rq_stats->csum_unnecessary_inner;
146 s->rx_wqe_err += rq_stats->wqe_err;
147 s->rx_mpwqe_filler += rq_stats->mpwqe_filler;
148 s->rx_mpwqe_frag += rq_stats->mpwqe_frag;
149 s->rx_buff_alloc_err += rq_stats->buff_alloc_err;
150 s->rx_cqe_compress_blks += rq_stats->cqe_compress_blks;
151 s->rx_cqe_compress_pkts += rq_stats->cqe_compress_pkts;
153 for (j = 0; j < priv->params.num_tc; j++) {
154 sq_stats = &priv->channel[i]->sq[j].stats;
156 s->tx_packets += sq_stats->packets;
157 s->tx_bytes += sq_stats->bytes;
158 s->tx_tso_packets += sq_stats->tso_packets;
159 s->tx_tso_bytes += sq_stats->tso_bytes;
160 s->tx_tso_inner_packets += sq_stats->tso_inner_packets;
161 s->tx_tso_inner_bytes += sq_stats->tso_inner_bytes;
162 s->tx_queue_stopped += sq_stats->stopped;
163 s->tx_queue_wake += sq_stats->wake;
164 s->tx_queue_dropped += sq_stats->dropped;
165 s->tx_csum_partial_inner += sq_stats->csum_partial_inner;
166 tx_offload_none += sq_stats->csum_none;
170 /* Update calculated offload counters */
171 s->tx_csum_partial = s->tx_packets - tx_offload_none - s->tx_csum_partial_inner;
172 s->rx_csum_unnecessary = s->rx_packets - s->rx_csum_none - s->rx_csum_complete;
174 s->link_down_events_phy = MLX5_GET(ppcnt_reg,
175 priv->stats.pport.phy_counters,
176 counter_set.phys_layer_cntrs.link_down_events);
179 static void mlx5e_update_vport_counters(struct mlx5e_priv *priv)
181 int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
182 u32 *out = (u32 *)priv->stats.vport.query_vport_out;
183 u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)];
184 struct mlx5_core_dev *mdev = priv->mdev;
186 memset(in, 0, sizeof(in));
188 MLX5_SET(query_vport_counter_in, in, opcode,
189 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
190 MLX5_SET(query_vport_counter_in, in, op_mod, 0);
191 MLX5_SET(query_vport_counter_in, in, other_vport, 0);
193 memset(out, 0, outlen);
195 mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
198 static void mlx5e_update_pport_counters(struct mlx5e_priv *priv)
200 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
201 struct mlx5_core_dev *mdev = priv->mdev;
202 int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
207 in = mlx5_vzalloc(sz);
211 MLX5_SET(ppcnt_reg, in, local_port, 1);
213 out = pstats->IEEE_802_3_counters;
214 MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
215 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
217 out = pstats->RFC_2863_counters;
218 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
219 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
221 out = pstats->RFC_2819_counters;
222 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
223 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
225 out = pstats->phy_counters;
226 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
227 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
229 MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
230 for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
231 out = pstats->per_prio_counters[prio];
232 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
233 mlx5_core_access_reg(mdev, in, sz, out, sz,
234 MLX5_REG_PPCNT, 0, 0);
241 static void mlx5e_update_q_counter(struct mlx5e_priv *priv)
243 struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
245 if (!priv->q_counter)
248 mlx5_core_query_out_of_buffer(priv->mdev, priv->q_counter,
249 &qcnt->rx_out_of_buffer);
252 void mlx5e_update_stats(struct mlx5e_priv *priv)
254 mlx5e_update_q_counter(priv);
255 mlx5e_update_vport_counters(priv);
256 mlx5e_update_pport_counters(priv);
257 mlx5e_update_sw_counters(priv);
260 void mlx5e_update_stats_work(struct work_struct *work)
262 struct delayed_work *dwork = to_delayed_work(work);
263 struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
265 mutex_lock(&priv->state_lock);
266 if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
267 priv->profile->update_stats(priv);
268 queue_delayed_work(priv->wq, dwork,
269 msecs_to_jiffies(MLX5E_UPDATE_STATS_INTERVAL));
271 mutex_unlock(&priv->state_lock);
274 static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv,
275 enum mlx5_dev_event event, unsigned long param)
277 struct mlx5e_priv *priv = vpriv;
279 if (!test_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state))
283 case MLX5_DEV_EVENT_PORT_UP:
284 case MLX5_DEV_EVENT_PORT_DOWN:
285 queue_work(priv->wq, &priv->update_carrier_work);
293 static void mlx5e_enable_async_events(struct mlx5e_priv *priv)
295 set_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state);
298 static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
300 clear_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state);
301 synchronize_irq(mlx5_get_msix_vec(priv->mdev, MLX5_EQ_VEC_ASYNC));
304 #define MLX5E_HW2SW_MTU(hwmtu) (hwmtu - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
305 #define MLX5E_SW2HW_MTU(swmtu) (swmtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
307 static int mlx5e_create_rq(struct mlx5e_channel *c,
308 struct mlx5e_rq_param *param,
311 struct mlx5e_priv *priv = c->priv;
312 struct mlx5_core_dev *mdev = priv->mdev;
313 void *rqc = param->rqc;
314 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
320 param->wq.db_numa_node = cpu_to_node(c->cpu);
322 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
327 rq->wq.db = &rq->wq.db[MLX5_RCV_DBR];
329 wq_sz = mlx5_wq_ll_get_size(&rq->wq);
331 switch (priv->params.rq_wq_type) {
332 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
333 rq->wqe_info = kzalloc_node(wq_sz * sizeof(*rq->wqe_info),
334 GFP_KERNEL, cpu_to_node(c->cpu));
337 goto err_rq_wq_destroy;
339 rq->handle_rx_cqe = mlx5e_handle_rx_cqe_mpwrq;
340 rq->alloc_wqe = mlx5e_alloc_rx_mpwqe;
341 rq->dealloc_wqe = mlx5e_dealloc_rx_mpwqe;
343 rq->mpwqe_stride_sz = BIT(priv->params.mpwqe_log_stride_sz);
344 rq->mpwqe_num_strides = BIT(priv->params.mpwqe_log_num_strides);
345 rq->wqe_sz = rq->mpwqe_stride_sz * rq->mpwqe_num_strides;
346 byte_count = rq->wqe_sz;
348 default: /* MLX5_WQ_TYPE_LINKED_LIST */
349 rq->skb = kzalloc_node(wq_sz * sizeof(*rq->skb), GFP_KERNEL,
350 cpu_to_node(c->cpu));
353 goto err_rq_wq_destroy;
355 rq->handle_rx_cqe = mlx5e_handle_rx_cqe;
356 rq->alloc_wqe = mlx5e_alloc_rx_wqe;
357 rq->dealloc_wqe = mlx5e_dealloc_rx_wqe;
359 rq->wqe_sz = (priv->params.lro_en) ?
360 priv->params.lro_wqe_sz :
361 MLX5E_SW2HW_MTU(priv->netdev->mtu);
362 rq->wqe_sz = SKB_DATA_ALIGN(rq->wqe_sz);
363 byte_count = rq->wqe_sz;
364 byte_count |= MLX5_HW_START_PADDING;
367 for (i = 0; i < wq_sz; i++) {
368 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
370 wqe->data.byte_count = cpu_to_be32(byte_count);
373 INIT_WORK(&rq->am.work, mlx5e_rx_am_work);
374 rq->am.mode = priv->params.rx_cq_period_mode;
376 rq->wq_type = priv->params.rq_wq_type;
378 rq->netdev = c->netdev;
379 rq->tstamp = &priv->tstamp;
383 rq->mkey_be = c->mkey_be;
384 rq->umr_mkey_be = cpu_to_be32(c->priv->umr_mkey.key);
389 mlx5_wq_destroy(&rq->wq_ctrl);
394 static void mlx5e_destroy_rq(struct mlx5e_rq *rq)
396 switch (rq->wq_type) {
397 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
400 default: /* MLX5_WQ_TYPE_LINKED_LIST */
404 mlx5_wq_destroy(&rq->wq_ctrl);
407 static int mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param)
409 struct mlx5e_priv *priv = rq->priv;
410 struct mlx5_core_dev *mdev = priv->mdev;
418 inlen = MLX5_ST_SZ_BYTES(create_rq_in) +
419 sizeof(u64) * rq->wq_ctrl.buf.npages;
420 in = mlx5_vzalloc(inlen);
424 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx);
425 wq = MLX5_ADDR_OF(rqc, rqc, wq);
427 memcpy(rqc, param->rqc, sizeof(param->rqc));
429 MLX5_SET(rqc, rqc, cqn, rq->cq.mcq.cqn);
430 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST);
431 MLX5_SET(rqc, rqc, flush_in_error_en, 1);
432 MLX5_SET(rqc, rqc, vsd, priv->params.vlan_strip_disable);
433 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift -
434 MLX5_ADAPTER_PAGE_SHIFT);
435 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma);
437 mlx5_fill_page_array(&rq->wq_ctrl.buf,
438 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
440 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn);
447 static int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state,
450 struct mlx5e_channel *c = rq->channel;
451 struct mlx5e_priv *priv = c->priv;
452 struct mlx5_core_dev *mdev = priv->mdev;
459 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
460 in = mlx5_vzalloc(inlen);
464 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
466 MLX5_SET(modify_rq_in, in, rq_state, curr_state);
467 MLX5_SET(rqc, rqc, state, next_state);
469 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
476 static int mlx5e_modify_rq_vsd(struct mlx5e_rq *rq, bool vsd)
478 struct mlx5e_channel *c = rq->channel;
479 struct mlx5e_priv *priv = c->priv;
480 struct mlx5_core_dev *mdev = priv->mdev;
487 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
488 in = mlx5_vzalloc(inlen);
492 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
494 MLX5_SET(modify_rq_in, in, rq_state, MLX5_RQC_STATE_RDY);
495 MLX5_SET64(modify_rq_in, in, modify_bitmask, MLX5_RQ_BITMASK_VSD);
496 MLX5_SET(rqc, rqc, vsd, vsd);
497 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RDY);
499 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
506 static void mlx5e_disable_rq(struct mlx5e_rq *rq)
508 mlx5_core_destroy_rq(rq->priv->mdev, rq->rqn);
511 static int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq)
513 unsigned long exp_time = jiffies + msecs_to_jiffies(20000);
514 struct mlx5e_channel *c = rq->channel;
515 struct mlx5e_priv *priv = c->priv;
516 struct mlx5_wq_ll *wq = &rq->wq;
518 while (time_before(jiffies, exp_time)) {
519 if (wq->cur_sz >= priv->params.min_rx_wqes)
528 static int mlx5e_open_rq(struct mlx5e_channel *c,
529 struct mlx5e_rq_param *param,
532 struct mlx5e_sq *sq = &c->icosq;
533 u16 pi = sq->pc & sq->wq.sz_m1;
536 err = mlx5e_create_rq(c, param, rq);
540 err = mlx5e_enable_rq(rq, param);
544 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
548 if (param->am_enabled)
549 set_bit(MLX5E_RQ_STATE_AM, &c->rq.state);
551 set_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
553 sq->ico_wqe_info[pi].opcode = MLX5_OPCODE_NOP;
554 sq->ico_wqe_info[pi].num_wqebbs = 1;
555 mlx5e_send_nop(sq, true); /* trigger mlx5e_post_rx_wqes() */
560 mlx5e_disable_rq(rq);
562 mlx5e_destroy_rq(rq);
567 static void mlx5e_close_rq(struct mlx5e_rq *rq)
572 clear_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
573 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
575 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR);
576 while (!mlx5_wq_ll_is_empty(&rq->wq) && !err &&
577 tout++ < MLX5_EN_QP_FLUSH_MAX_ITER)
578 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
580 if (err || tout == MLX5_EN_QP_FLUSH_MAX_ITER)
581 set_bit(MLX5E_RQ_STATE_FLUSH_TIMEOUT, &rq->state);
583 /* avoid destroying rq before mlx5e_poll_rx_cq() is done with it */
584 napi_synchronize(&rq->channel->napi);
586 cancel_work_sync(&rq->am.work);
588 mlx5e_disable_rq(rq);
589 mlx5e_free_rx_descs(rq);
590 mlx5e_destroy_rq(rq);
593 static void mlx5e_free_sq_db(struct mlx5e_sq *sq)
600 static int mlx5e_alloc_sq_db(struct mlx5e_sq *sq, int numa)
602 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
603 int df_sz = wq_sz * MLX5_SEND_WQEBB_NUM_DS;
605 sq->skb = kzalloc_node(wq_sz * sizeof(*sq->skb), GFP_KERNEL, numa);
606 sq->dma_fifo = kzalloc_node(df_sz * sizeof(*sq->dma_fifo), GFP_KERNEL,
608 sq->wqe_info = kzalloc_node(wq_sz * sizeof(*sq->wqe_info), GFP_KERNEL,
611 if (!sq->skb || !sq->dma_fifo || !sq->wqe_info) {
612 mlx5e_free_sq_db(sq);
616 sq->dma_fifo_mask = df_sz - 1;
621 static int mlx5e_create_sq(struct mlx5e_channel *c,
623 struct mlx5e_sq_param *param,
626 struct mlx5e_priv *priv = c->priv;
627 struct mlx5_core_dev *mdev = priv->mdev;
629 void *sqc = param->sqc;
630 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq);
633 err = mlx5_alloc_map_uar(mdev, &sq->uar, !!MLX5_CAP_GEN(mdev, bf));
637 param->wq.db_numa_node = cpu_to_node(c->cpu);
639 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq,
642 goto err_unmap_free_uar;
644 sq->wq.db = &sq->wq.db[MLX5_SND_DBR];
645 if (sq->uar.bf_map) {
646 set_bit(MLX5E_SQ_STATE_BF_ENABLE, &sq->state);
647 sq->uar_map = sq->uar.bf_map;
649 sq->uar_map = sq->uar.map;
651 sq->bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
652 sq->max_inline = param->max_inline;
653 sq->min_inline_mode =
654 MLX5_CAP_ETH(mdev, wqe_inline_mode) == MLX5E_INLINE_MODE_VPORT_CONTEXT ?
655 param->min_inline_mode : 0;
657 err = mlx5e_alloc_sq_db(sq, cpu_to_node(c->cpu));
659 goto err_sq_wq_destroy;
662 u8 wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
664 sq->ico_wqe_info = kzalloc_node(sizeof(*sq->ico_wqe_info) *
667 cpu_to_node(c->cpu));
668 if (!sq->ico_wqe_info) {
675 txq_ix = c->ix + tc * priv->params.num_channels;
676 sq->txq = netdev_get_tx_queue(priv->netdev, txq_ix);
677 priv->txq_to_sq_map[txq_ix] = sq;
681 sq->tstamp = &priv->tstamp;
682 sq->mkey_be = c->mkey_be;
685 sq->edge = (sq->wq.sz_m1 + 1) - MLX5_SEND_WQE_MAX_WQEBBS;
686 sq->bf_budget = MLX5E_SQ_BF_BUDGET;
691 mlx5e_free_sq_db(sq);
694 mlx5_wq_destroy(&sq->wq_ctrl);
697 mlx5_unmap_free_uar(mdev, &sq->uar);
702 static void mlx5e_destroy_sq(struct mlx5e_sq *sq)
704 struct mlx5e_channel *c = sq->channel;
705 struct mlx5e_priv *priv = c->priv;
707 kfree(sq->ico_wqe_info);
708 mlx5e_free_sq_db(sq);
709 mlx5_wq_destroy(&sq->wq_ctrl);
710 mlx5_unmap_free_uar(priv->mdev, &sq->uar);
713 static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
715 struct mlx5e_channel *c = sq->channel;
716 struct mlx5e_priv *priv = c->priv;
717 struct mlx5_core_dev *mdev = priv->mdev;
725 inlen = MLX5_ST_SZ_BYTES(create_sq_in) +
726 sizeof(u64) * sq->wq_ctrl.buf.npages;
727 in = mlx5_vzalloc(inlen);
731 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx);
732 wq = MLX5_ADDR_OF(sqc, sqc, wq);
734 memcpy(sqc, param->sqc, sizeof(param->sqc));
736 MLX5_SET(sqc, sqc, tis_num_0, param->icosq ? 0 : priv->tisn[sq->tc]);
737 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn);
738 MLX5_SET(sqc, sqc, min_wqe_inline_mode, sq->min_inline_mode);
739 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
740 MLX5_SET(sqc, sqc, tis_lst_sz, param->icosq ? 0 : 1);
741 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
743 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
744 MLX5_SET(wq, wq, uar_page, sq->uar.index);
745 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift -
746 MLX5_ADAPTER_PAGE_SHIFT);
747 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma);
749 mlx5_fill_page_array(&sq->wq_ctrl.buf,
750 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
752 err = mlx5_core_create_sq(mdev, in, inlen, &sq->sqn);
759 static int mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state,
760 int next_state, bool update_rl, int rl_index)
762 struct mlx5e_channel *c = sq->channel;
763 struct mlx5e_priv *priv = c->priv;
764 struct mlx5_core_dev *mdev = priv->mdev;
771 inlen = MLX5_ST_SZ_BYTES(modify_sq_in);
772 in = mlx5_vzalloc(inlen);
776 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx);
778 MLX5_SET(modify_sq_in, in, sq_state, curr_state);
779 MLX5_SET(sqc, sqc, state, next_state);
780 if (update_rl && next_state == MLX5_SQC_STATE_RDY) {
781 MLX5_SET64(modify_sq_in, in, modify_bitmask, 1);
782 MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index);
785 err = mlx5_core_modify_sq(mdev, sq->sqn, in, inlen);
792 static void mlx5e_disable_sq(struct mlx5e_sq *sq)
794 struct mlx5e_channel *c = sq->channel;
795 struct mlx5e_priv *priv = c->priv;
796 struct mlx5_core_dev *mdev = priv->mdev;
798 mlx5_core_destroy_sq(mdev, sq->sqn);
800 mlx5_rl_remove_rate(mdev, sq->rate_limit);
803 static int mlx5e_open_sq(struct mlx5e_channel *c,
805 struct mlx5e_sq_param *param,
810 err = mlx5e_create_sq(c, tc, param, sq);
814 err = mlx5e_enable_sq(sq, param);
818 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY,
824 set_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
825 netdev_tx_reset_queue(sq->txq);
826 netif_tx_start_queue(sq->txq);
832 mlx5e_disable_sq(sq);
834 mlx5e_destroy_sq(sq);
839 static inline void netif_tx_disable_queue(struct netdev_queue *txq)
841 __netif_tx_lock_bh(txq);
842 netif_tx_stop_queue(txq);
843 __netif_tx_unlock_bh(txq);
846 static void mlx5e_close_sq(struct mlx5e_sq *sq)
852 clear_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
853 /* prevent netif_tx_wake_queue */
854 napi_synchronize(&sq->channel->napi);
855 netif_tx_disable_queue(sq->txq);
857 /* ensure hw is notified of all pending wqes */
858 if (mlx5e_sq_has_room_for(sq, 1))
859 mlx5e_send_nop(sq, true);
861 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
862 MLX5_SQC_STATE_ERR, false, 0);
864 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
867 /* wait till sq is empty, unless a TX timeout occurred on this SQ */
868 while (sq->cc != sq->pc &&
869 !test_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state)) {
870 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
871 if (tout++ > MLX5_EN_QP_FLUSH_MAX_ITER)
872 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
875 /* avoid destroying sq before mlx5e_poll_tx_cq() is done with it */
876 napi_synchronize(&sq->channel->napi);
878 mlx5e_free_tx_descs(sq);
879 mlx5e_disable_sq(sq);
880 mlx5e_destroy_sq(sq);
883 static int mlx5e_create_cq(struct mlx5e_channel *c,
884 struct mlx5e_cq_param *param,
887 struct mlx5e_priv *priv = c->priv;
888 struct mlx5_core_dev *mdev = priv->mdev;
889 struct mlx5_core_cq *mcq = &cq->mcq;
895 param->wq.buf_numa_node = cpu_to_node(c->cpu);
896 param->wq.db_numa_node = cpu_to_node(c->cpu);
897 param->eq_ix = c->ix;
899 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
904 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
909 mcq->set_ci_db = cq->wq_ctrl.db.db;
910 mcq->arm_db = cq->wq_ctrl.db.db + 1;
913 mcq->vector = param->eq_ix;
914 mcq->comp = mlx5e_completion_event;
915 mcq->event = mlx5e_cq_error_event;
917 mcq->uar = &mdev->mlx5e_res.cq_uar;
919 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
920 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
931 static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
933 mlx5_wq_destroy(&cq->wq_ctrl);
936 static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
938 struct mlx5e_priv *priv = cq->priv;
939 struct mlx5_core_dev *mdev = priv->mdev;
940 struct mlx5_core_cq *mcq = &cq->mcq;
945 unsigned int irqn_not_used;
949 inlen = MLX5_ST_SZ_BYTES(create_cq_in) +
950 sizeof(u64) * cq->wq_ctrl.buf.npages;
951 in = mlx5_vzalloc(inlen);
955 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
957 memcpy(cqc, param->cqc, sizeof(param->cqc));
959 mlx5_fill_page_array(&cq->wq_ctrl.buf,
960 (__be64 *)MLX5_ADDR_OF(create_cq_in, in, pas));
962 mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
964 MLX5_SET(cqc, cqc, cq_period_mode, param->cq_period_mode);
965 MLX5_SET(cqc, cqc, c_eqn, eqn);
966 MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
967 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
968 MLX5_ADAPTER_PAGE_SHIFT);
969 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
971 err = mlx5_core_create_cq(mdev, mcq, in, inlen);
983 static void mlx5e_disable_cq(struct mlx5e_cq *cq)
985 struct mlx5e_priv *priv = cq->priv;
986 struct mlx5_core_dev *mdev = priv->mdev;
988 mlx5_core_destroy_cq(mdev, &cq->mcq);
991 static int mlx5e_open_cq(struct mlx5e_channel *c,
992 struct mlx5e_cq_param *param,
994 struct mlx5e_cq_moder moderation)
997 struct mlx5e_priv *priv = c->priv;
998 struct mlx5_core_dev *mdev = priv->mdev;
1000 err = mlx5e_create_cq(c, param, cq);
1004 err = mlx5e_enable_cq(cq, param);
1006 goto err_destroy_cq;
1008 if (MLX5_CAP_GEN(mdev, cq_moderation))
1009 mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
1015 mlx5e_destroy_cq(cq);
1020 static void mlx5e_close_cq(struct mlx5e_cq *cq)
1022 mlx5e_disable_cq(cq);
1023 mlx5e_destroy_cq(cq);
1026 static int mlx5e_get_cpu(struct mlx5e_priv *priv, int ix)
1028 return cpumask_first(priv->mdev->priv.irq_info[ix].mask);
1031 static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
1032 struct mlx5e_channel_param *cparam)
1034 struct mlx5e_priv *priv = c->priv;
1038 for (tc = 0; tc < c->num_tc; tc++) {
1039 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
1040 priv->params.tx_cq_moderation);
1042 goto err_close_tx_cqs;
1048 for (tc--; tc >= 0; tc--)
1049 mlx5e_close_cq(&c->sq[tc].cq);
1054 static void mlx5e_close_tx_cqs(struct mlx5e_channel *c)
1058 for (tc = 0; tc < c->num_tc; tc++)
1059 mlx5e_close_cq(&c->sq[tc].cq);
1062 static int mlx5e_open_sqs(struct mlx5e_channel *c,
1063 struct mlx5e_channel_param *cparam)
1068 for (tc = 0; tc < c->num_tc; tc++) {
1069 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]);
1077 for (tc--; tc >= 0; tc--)
1078 mlx5e_close_sq(&c->sq[tc]);
1083 static void mlx5e_close_sqs(struct mlx5e_channel *c)
1087 for (tc = 0; tc < c->num_tc; tc++)
1088 mlx5e_close_sq(&c->sq[tc]);
1091 static void mlx5e_build_channeltc_to_txq_map(struct mlx5e_priv *priv, int ix)
1095 for (i = 0; i < priv->profile->max_tc; i++)
1096 priv->channeltc_to_txq_map[ix][i] =
1097 ix + i * priv->params.num_channels;
1100 static int mlx5e_set_sq_maxrate(struct net_device *dev,
1101 struct mlx5e_sq *sq, u32 rate)
1103 struct mlx5e_priv *priv = netdev_priv(dev);
1104 struct mlx5_core_dev *mdev = priv->mdev;
1108 if (rate == sq->rate_limit)
1113 /* remove current rl index to free space to next ones */
1114 mlx5_rl_remove_rate(mdev, sq->rate_limit);
1119 err = mlx5_rl_add_rate(mdev, rate, &rl_index);
1121 netdev_err(dev, "Failed configuring rate %u: %d\n",
1127 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
1128 MLX5_SQC_STATE_RDY, true, rl_index);
1130 netdev_err(dev, "Failed configuring rate %u: %d\n",
1132 /* remove the rate from the table */
1134 mlx5_rl_remove_rate(mdev, rate);
1138 sq->rate_limit = rate;
1142 static int mlx5e_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
1144 struct mlx5e_priv *priv = netdev_priv(dev);
1145 struct mlx5_core_dev *mdev = priv->mdev;
1146 struct mlx5e_sq *sq = priv->txq_to_sq_map[index];
1149 if (!mlx5_rl_is_supported(mdev)) {
1150 netdev_err(dev, "Rate limiting is not supported on this device\n");
1154 /* rate is given in Mb/sec, HW config is in Kb/sec */
1157 /* Check whether rate in valid range, 0 is always valid */
1158 if (rate && !mlx5_rl_is_in_range(mdev, rate)) {
1159 netdev_err(dev, "TX rate %u, is not in range\n", rate);
1163 mutex_lock(&priv->state_lock);
1164 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
1165 err = mlx5e_set_sq_maxrate(dev, sq, rate);
1167 priv->tx_rates[index] = rate;
1168 mutex_unlock(&priv->state_lock);
1173 static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1174 struct mlx5e_channel_param *cparam,
1175 struct mlx5e_channel **cp)
1177 struct mlx5e_cq_moder icosq_cq_moder = {0, 0};
1178 struct net_device *netdev = priv->netdev;
1179 struct mlx5e_cq_moder rx_cq_profile;
1180 int cpu = mlx5e_get_cpu(priv, ix);
1181 struct mlx5e_channel *c;
1182 struct mlx5e_sq *sq;
1186 c = kzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1193 c->pdev = &priv->mdev->pdev->dev;
1194 c->netdev = priv->netdev;
1195 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1196 c->num_tc = priv->params.num_tc;
1198 if (priv->params.rx_am_enabled)
1199 rx_cq_profile = mlx5e_am_get_def_profile(priv->params.rx_cq_period_mode);
1201 rx_cq_profile = priv->params.rx_cq_moderation;
1203 mlx5e_build_channeltc_to_txq_map(priv, ix);
1205 netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1207 err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, icosq_cq_moder);
1211 err = mlx5e_open_tx_cqs(c, cparam);
1213 goto err_close_icosq_cq;
1215 err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1218 goto err_close_tx_cqs;
1220 napi_enable(&c->napi);
1222 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
1224 goto err_disable_napi;
1226 err = mlx5e_open_sqs(c, cparam);
1228 goto err_close_icosq;
1230 for (i = 0; i < priv->params.num_tc; i++) {
1231 u32 txq_ix = priv->channeltc_to_txq_map[ix][i];
1233 if (priv->tx_rates[txq_ix]) {
1234 sq = priv->txq_to_sq_map[txq_ix];
1235 mlx5e_set_sq_maxrate(priv->netdev, sq,
1236 priv->tx_rates[txq_ix]);
1240 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1244 netif_set_xps_queue(netdev, get_cpu_mask(c->cpu), ix);
1253 mlx5e_close_sq(&c->icosq);
1256 napi_disable(&c->napi);
1257 mlx5e_close_cq(&c->rq.cq);
1260 mlx5e_close_tx_cqs(c);
1263 mlx5e_close_cq(&c->icosq.cq);
1266 netif_napi_del(&c->napi);
1267 napi_hash_del(&c->napi);
1273 static void mlx5e_close_channel(struct mlx5e_channel *c)
1275 mlx5e_close_rq(&c->rq);
1277 mlx5e_close_sq(&c->icosq);
1278 napi_disable(&c->napi);
1279 mlx5e_close_cq(&c->rq.cq);
1280 mlx5e_close_tx_cqs(c);
1281 mlx5e_close_cq(&c->icosq.cq);
1282 netif_napi_del(&c->napi);
1284 napi_hash_del(&c->napi);
1290 static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1291 struct mlx5e_rq_param *param)
1293 void *rqc = param->rqc;
1294 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1296 switch (priv->params.rq_wq_type) {
1297 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1298 MLX5_SET(wq, wq, log_wqe_num_of_strides,
1299 priv->params.mpwqe_log_num_strides - 9);
1300 MLX5_SET(wq, wq, log_wqe_stride_size,
1301 priv->params.mpwqe_log_stride_sz - 6);
1302 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
1304 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1305 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1308 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
1309 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1310 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1311 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1312 MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
1314 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1315 param->wq.linear = 1;
1317 param->am_enabled = priv->params.rx_am_enabled;
1320 static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param)
1322 void *rqc = param->rqc;
1323 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1325 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1326 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1329 static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
1330 struct mlx5e_sq_param *param)
1332 void *sqc = param->sqc;
1333 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1335 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1336 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1338 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1341 static void mlx5e_build_sq_param(struct mlx5e_priv *priv,
1342 struct mlx5e_sq_param *param)
1344 void *sqc = param->sqc;
1345 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1347 mlx5e_build_sq_param_common(priv, param);
1348 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size);
1350 param->max_inline = priv->params.tx_max_inline;
1351 param->min_inline_mode = priv->params.tx_min_inline_mode;
1354 static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
1355 struct mlx5e_cq_param *param)
1357 void *cqc = param->cqc;
1359 MLX5_SET(cqc, cqc, uar_page, priv->mdev->mlx5e_res.cq_uar.index);
1362 static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
1363 struct mlx5e_cq_param *param)
1365 void *cqc = param->cqc;
1368 switch (priv->params.rq_wq_type) {
1369 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1370 log_cq_size = priv->params.log_rq_size +
1371 priv->params.mpwqe_log_num_strides;
1373 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1374 log_cq_size = priv->params.log_rq_size;
1377 MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
1378 if (priv->params.rx_cqe_compress) {
1379 MLX5_SET(cqc, cqc, mini_cqe_res_format, MLX5_CQE_FORMAT_CSUM);
1380 MLX5_SET(cqc, cqc, cqe_comp_en, 1);
1383 mlx5e_build_common_cq_param(priv, param);
1385 param->cq_period_mode = priv->params.rx_cq_period_mode;
1388 static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
1389 struct mlx5e_cq_param *param)
1391 void *cqc = param->cqc;
1393 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
1395 mlx5e_build_common_cq_param(priv, param);
1397 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1400 static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
1401 struct mlx5e_cq_param *param,
1404 void *cqc = param->cqc;
1406 MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1408 mlx5e_build_common_cq_param(priv, param);
1410 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1413 static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
1414 struct mlx5e_sq_param *param,
1417 void *sqc = param->sqc;
1418 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1420 mlx5e_build_sq_param_common(priv, param);
1422 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1423 MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(priv->mdev, reg_umr_sq));
1425 param->icosq = true;
1428 static void mlx5e_build_channel_param(struct mlx5e_priv *priv, struct mlx5e_channel_param *cparam)
1430 u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1432 mlx5e_build_rq_param(priv, &cparam->rq);
1433 mlx5e_build_sq_param(priv, &cparam->sq);
1434 mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz);
1435 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq);
1436 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq);
1437 mlx5e_build_ico_cq_param(priv, &cparam->icosq_cq, icosq_log_wq_sz);
1440 static int mlx5e_open_channels(struct mlx5e_priv *priv)
1442 struct mlx5e_channel_param *cparam;
1443 int nch = priv->params.num_channels;
1448 priv->channel = kcalloc(nch, sizeof(struct mlx5e_channel *),
1451 priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc,
1452 sizeof(struct mlx5e_sq *), GFP_KERNEL);
1454 cparam = kzalloc(sizeof(struct mlx5e_channel_param), GFP_KERNEL);
1456 if (!priv->channel || !priv->txq_to_sq_map || !cparam)
1457 goto err_free_txq_to_sq_map;
1459 mlx5e_build_channel_param(priv, cparam);
1461 for (i = 0; i < nch; i++) {
1462 err = mlx5e_open_channel(priv, i, cparam, &priv->channel[i]);
1464 goto err_close_channels;
1467 for (j = 0; j < nch; j++) {
1468 err = mlx5e_wait_for_min_rx_wqes(&priv->channel[j]->rq);
1470 goto err_close_channels;
1473 /* FIXME: This is a W/A for tx timeout watch dog false alarm when
1474 * polling for inactive tx queues.
1476 netif_tx_start_all_queues(priv->netdev);
1482 for (i--; i >= 0; i--)
1483 mlx5e_close_channel(priv->channel[i]);
1485 err_free_txq_to_sq_map:
1486 kfree(priv->txq_to_sq_map);
1487 kfree(priv->channel);
1493 static void mlx5e_close_channels(struct mlx5e_priv *priv)
1497 /* FIXME: This is a W/A only for tx timeout watch dog false alarm when
1498 * polling for inactive tx queues.
1500 netif_tx_stop_all_queues(priv->netdev);
1501 netif_tx_disable(priv->netdev);
1503 for (i = 0; i < priv->params.num_channels; i++)
1504 mlx5e_close_channel(priv->channel[i]);
1506 kfree(priv->txq_to_sq_map);
1507 kfree(priv->channel);
1510 static int mlx5e_rx_hash_fn(int hfunc)
1512 return (hfunc == ETH_RSS_HASH_TOP) ?
1513 MLX5_RX_HASH_FN_TOEPLITZ :
1514 MLX5_RX_HASH_FN_INVERTED_XOR8;
1517 static int mlx5e_bits_invert(unsigned long a, int size)
1522 for (i = 0; i < size; i++)
1523 inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1528 static void mlx5e_fill_indir_rqt_rqns(struct mlx5e_priv *priv, void *rqtc)
1532 for (i = 0; i < MLX5E_INDIR_RQT_SIZE; i++) {
1536 if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1537 ix = mlx5e_bits_invert(i, MLX5E_LOG_INDIR_RQT_SIZE);
1539 ix = priv->params.indirection_rqt[ix];
1540 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1541 priv->channel[ix]->rq.rqn :
1543 MLX5_SET(rqtc, rqtc, rq_num[i], rqn);
1547 static void mlx5e_fill_direct_rqt_rqn(struct mlx5e_priv *priv, void *rqtc,
1550 u32 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1551 priv->channel[ix]->rq.rqn :
1554 MLX5_SET(rqtc, rqtc, rq_num[0], rqn);
1557 static int mlx5e_create_rqt(struct mlx5e_priv *priv, int sz,
1558 int ix, struct mlx5e_rqt *rqt)
1560 struct mlx5_core_dev *mdev = priv->mdev;
1566 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
1567 in = mlx5_vzalloc(inlen);
1571 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1573 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1574 MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
1576 if (sz > 1) /* RSS */
1577 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1579 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1581 err = mlx5_core_create_rqt(mdev, in, inlen, &rqt->rqtn);
1583 rqt->enabled = true;
1589 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt)
1591 rqt->enabled = false;
1592 mlx5_core_destroy_rqt(priv->mdev, rqt->rqtn);
1595 static int mlx5e_create_indirect_rqts(struct mlx5e_priv *priv)
1597 struct mlx5e_rqt *rqt = &priv->indir_rqt;
1599 return mlx5e_create_rqt(priv, MLX5E_INDIR_RQT_SIZE, 0, rqt);
1602 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv)
1604 struct mlx5e_rqt *rqt;
1608 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1609 rqt = &priv->direct_tir[ix].rqt;
1610 err = mlx5e_create_rqt(priv, 1 /*size */, ix, rqt);
1612 goto err_destroy_rqts;
1618 for (ix--; ix >= 0; ix--)
1619 mlx5e_destroy_rqt(priv, &priv->direct_tir[ix].rqt);
1624 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix)
1626 struct mlx5_core_dev *mdev = priv->mdev;
1632 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz;
1633 in = mlx5_vzalloc(inlen);
1637 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx);
1639 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1640 if (sz > 1) /* RSS */
1641 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1643 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1645 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1);
1647 err = mlx5_core_modify_rqt(mdev, rqtn, in, inlen);
1654 static void mlx5e_redirect_rqts(struct mlx5e_priv *priv)
1659 if (priv->indir_rqt.enabled) {
1660 rqtn = priv->indir_rqt.rqtn;
1661 mlx5e_redirect_rqt(priv, rqtn, MLX5E_INDIR_RQT_SIZE, 0);
1664 for (ix = 0; ix < priv->params.num_channels; ix++) {
1665 if (!priv->direct_tir[ix].rqt.enabled)
1667 rqtn = priv->direct_tir[ix].rqt.rqtn;
1668 mlx5e_redirect_rqt(priv, rqtn, 1, ix);
1672 static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1674 if (!priv->params.lro_en)
1677 #define ROUGH_MAX_L2_L3_HDR_SZ 256
1679 MLX5_SET(tirc, tirc, lro_enable_mask,
1680 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
1681 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO);
1682 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1683 (priv->params.lro_wqe_sz -
1684 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1685 MLX5_SET(tirc, tirc, lro_timeout_period_usecs,
1686 MLX5_CAP_ETH(priv->mdev,
1687 lro_timer_supported_periods[2]));
1690 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
1692 MLX5_SET(tirc, tirc, rx_hash_fn,
1693 mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1694 if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1695 void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1696 rx_hash_toeplitz_key);
1697 size_t len = MLX5_FLD_SZ_BYTES(tirc,
1698 rx_hash_toeplitz_key);
1700 MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1701 memcpy(rss_key, priv->params.toeplitz_hash_key, len);
1705 static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
1707 struct mlx5_core_dev *mdev = priv->mdev;
1716 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1717 in = mlx5_vzalloc(inlen);
1721 MLX5_SET(modify_tir_in, in, bitmask.lro, 1);
1722 tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
1724 mlx5e_build_tir_ctx_lro(tirc, priv);
1726 for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) {
1727 err = mlx5_core_modify_tir(mdev, priv->indir_tir[tt].tirn, in,
1733 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1734 err = mlx5_core_modify_tir(mdev, priv->direct_tir[ix].tirn,
1746 static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
1748 struct mlx5_core_dev *mdev = priv->mdev;
1749 u16 hw_mtu = MLX5E_SW2HW_MTU(mtu);
1752 err = mlx5_set_port_mtu(mdev, hw_mtu, 1);
1756 /* Update vport context MTU */
1757 mlx5_modify_nic_vport_mtu(mdev, hw_mtu);
1761 static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
1763 struct mlx5_core_dev *mdev = priv->mdev;
1767 err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
1768 if (err || !hw_mtu) /* fallback to port oper mtu */
1769 mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
1771 *mtu = MLX5E_HW2SW_MTU(hw_mtu);
1774 static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
1776 struct mlx5e_priv *priv = netdev_priv(netdev);
1780 err = mlx5e_set_mtu(priv, netdev->mtu);
1784 mlx5e_query_mtu(priv, &mtu);
1785 if (mtu != netdev->mtu)
1786 netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
1787 __func__, mtu, netdev->mtu);
1793 static void mlx5e_netdev_set_tcs(struct net_device *netdev)
1795 struct mlx5e_priv *priv = netdev_priv(netdev);
1796 int nch = priv->params.num_channels;
1797 int ntc = priv->params.num_tc;
1800 netdev_reset_tc(netdev);
1805 netdev_set_num_tc(netdev, ntc);
1807 /* Map netdev TCs to offset 0
1808 * We have our own UP to TXQ mapping for QoS
1810 for (tc = 0; tc < ntc; tc++)
1811 netdev_set_tc_queue(netdev, tc, nch, 0);
1814 int mlx5e_open_locked(struct net_device *netdev)
1816 struct mlx5e_priv *priv = netdev_priv(netdev);
1817 struct mlx5_core_dev *mdev = priv->mdev;
1821 set_bit(MLX5E_STATE_OPENED, &priv->state);
1823 mlx5e_netdev_set_tcs(netdev);
1825 num_txqs = priv->params.num_channels * priv->params.num_tc;
1826 netif_set_real_num_tx_queues(netdev, num_txqs);
1827 netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
1829 err = mlx5e_open_channels(priv);
1831 netdev_err(netdev, "%s: mlx5e_open_channels failed, %d\n",
1833 goto err_clear_state_opened_flag;
1836 err = mlx5e_refresh_tirs_self_loopback_enable(priv->mdev);
1838 netdev_err(netdev, "%s: mlx5e_refresh_tirs_self_loopback_enable failed, %d\n",
1840 goto err_close_channels;
1843 mlx5e_redirect_rqts(priv);
1844 mlx5e_update_carrier(priv);
1845 mlx5e_timestamp_init(priv);
1846 #ifdef CONFIG_RFS_ACCEL
1847 priv->netdev->rx_cpu_rmap = priv->mdev->rmap;
1849 if (priv->profile->update_stats)
1850 queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
1852 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
1853 err = mlx5e_add_sqs_fwd_rules(priv);
1855 goto err_close_channels;
1860 mlx5e_close_channels(priv);
1861 err_clear_state_opened_flag:
1862 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1866 int mlx5e_open(struct net_device *netdev)
1868 struct mlx5e_priv *priv = netdev_priv(netdev);
1871 mutex_lock(&priv->state_lock);
1872 err = mlx5e_open_locked(netdev);
1873 mutex_unlock(&priv->state_lock);
1878 int mlx5e_close_locked(struct net_device *netdev)
1880 struct mlx5e_priv *priv = netdev_priv(netdev);
1881 struct mlx5_core_dev *mdev = priv->mdev;
1883 /* May already be CLOSED in case a previous configuration operation
1884 * (e.g RX/TX queue size change) that involves close&open failed.
1886 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
1889 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1891 if (MLX5_CAP_GEN(mdev, vport_group_manager))
1892 mlx5e_remove_sqs_fwd_rules(priv);
1894 mlx5e_timestamp_cleanup(priv);
1895 netif_carrier_off(priv->netdev);
1896 mlx5e_redirect_rqts(priv);
1897 mlx5e_close_channels(priv);
1902 int mlx5e_close(struct net_device *netdev)
1904 struct mlx5e_priv *priv = netdev_priv(netdev);
1907 mutex_lock(&priv->state_lock);
1908 err = mlx5e_close_locked(netdev);
1909 mutex_unlock(&priv->state_lock);
1914 static int mlx5e_create_drop_rq(struct mlx5e_priv *priv,
1915 struct mlx5e_rq *rq,
1916 struct mlx5e_rq_param *param)
1918 struct mlx5_core_dev *mdev = priv->mdev;
1919 void *rqc = param->rqc;
1920 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
1923 param->wq.db_numa_node = param->wq.buf_numa_node;
1925 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
1935 static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
1936 struct mlx5e_cq *cq,
1937 struct mlx5e_cq_param *param)
1939 struct mlx5_core_dev *mdev = priv->mdev;
1940 struct mlx5_core_cq *mcq = &cq->mcq;
1945 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
1950 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
1953 mcq->set_ci_db = cq->wq_ctrl.db.db;
1954 mcq->arm_db = cq->wq_ctrl.db.db + 1;
1955 *mcq->set_ci_db = 0;
1957 mcq->vector = param->eq_ix;
1958 mcq->comp = mlx5e_completion_event;
1959 mcq->event = mlx5e_cq_error_event;
1961 mcq->uar = &mdev->mlx5e_res.cq_uar;
1968 static int mlx5e_open_drop_rq(struct mlx5e_priv *priv)
1970 struct mlx5e_cq_param cq_param;
1971 struct mlx5e_rq_param rq_param;
1972 struct mlx5e_rq *rq = &priv->drop_rq;
1973 struct mlx5e_cq *cq = &priv->drop_rq.cq;
1976 memset(&cq_param, 0, sizeof(cq_param));
1977 memset(&rq_param, 0, sizeof(rq_param));
1978 mlx5e_build_drop_rq_param(&rq_param);
1980 err = mlx5e_create_drop_cq(priv, cq, &cq_param);
1984 err = mlx5e_enable_cq(cq, &cq_param);
1986 goto err_destroy_cq;
1988 err = mlx5e_create_drop_rq(priv, rq, &rq_param);
1990 goto err_disable_cq;
1992 err = mlx5e_enable_rq(rq, &rq_param);
1994 goto err_destroy_rq;
1999 mlx5e_destroy_rq(&priv->drop_rq);
2002 mlx5e_disable_cq(&priv->drop_rq.cq);
2005 mlx5e_destroy_cq(&priv->drop_rq.cq);
2010 static void mlx5e_close_drop_rq(struct mlx5e_priv *priv)
2012 mlx5e_disable_rq(&priv->drop_rq);
2013 mlx5e_destroy_rq(&priv->drop_rq);
2014 mlx5e_disable_cq(&priv->drop_rq.cq);
2015 mlx5e_destroy_cq(&priv->drop_rq.cq);
2018 static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
2020 struct mlx5_core_dev *mdev = priv->mdev;
2021 u32 in[MLX5_ST_SZ_DW(create_tis_in)];
2022 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
2024 memset(in, 0, sizeof(in));
2026 MLX5_SET(tisc, tisc, prio, tc << 1);
2027 MLX5_SET(tisc, tisc, transport_domain, mdev->mlx5e_res.td.tdn);
2029 return mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc]);
2032 static void mlx5e_destroy_tis(struct mlx5e_priv *priv, int tc)
2034 mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc]);
2037 int mlx5e_create_tises(struct mlx5e_priv *priv)
2042 for (tc = 0; tc < priv->profile->max_tc; tc++) {
2043 err = mlx5e_create_tis(priv, tc);
2045 goto err_close_tises;
2051 for (tc--; tc >= 0; tc--)
2052 mlx5e_destroy_tis(priv, tc);
2057 void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv)
2061 for (tc = 0; tc < priv->profile->max_tc; tc++)
2062 mlx5e_destroy_tis(priv, tc);
2065 static void mlx5e_build_indir_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
2066 enum mlx5e_traffic_types tt)
2068 void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer);
2070 MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
2072 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
2073 MLX5_HASH_FIELD_SEL_DST_IP)
2075 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
2076 MLX5_HASH_FIELD_SEL_DST_IP |\
2077 MLX5_HASH_FIELD_SEL_L4_SPORT |\
2078 MLX5_HASH_FIELD_SEL_L4_DPORT)
2080 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
2081 MLX5_HASH_FIELD_SEL_DST_IP |\
2082 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
2084 mlx5e_build_tir_ctx_lro(tirc, priv);
2086 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
2087 MLX5_SET(tirc, tirc, indirect_table, priv->indir_rqt.rqtn);
2088 mlx5e_build_tir_ctx_hash(tirc, priv);
2091 case MLX5E_TT_IPV4_TCP:
2092 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2093 MLX5_L3_PROT_TYPE_IPV4);
2094 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2095 MLX5_L4_PROT_TYPE_TCP);
2096 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2097 MLX5_HASH_IP_L4PORTS);
2100 case MLX5E_TT_IPV6_TCP:
2101 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2102 MLX5_L3_PROT_TYPE_IPV6);
2103 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2104 MLX5_L4_PROT_TYPE_TCP);
2105 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2106 MLX5_HASH_IP_L4PORTS);
2109 case MLX5E_TT_IPV4_UDP:
2110 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2111 MLX5_L3_PROT_TYPE_IPV4);
2112 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2113 MLX5_L4_PROT_TYPE_UDP);
2114 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2115 MLX5_HASH_IP_L4PORTS);
2118 case MLX5E_TT_IPV6_UDP:
2119 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2120 MLX5_L3_PROT_TYPE_IPV6);
2121 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2122 MLX5_L4_PROT_TYPE_UDP);
2123 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2124 MLX5_HASH_IP_L4PORTS);
2127 case MLX5E_TT_IPV4_IPSEC_AH:
2128 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2129 MLX5_L3_PROT_TYPE_IPV4);
2130 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2131 MLX5_HASH_IP_IPSEC_SPI);
2134 case MLX5E_TT_IPV6_IPSEC_AH:
2135 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2136 MLX5_L3_PROT_TYPE_IPV6);
2137 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2138 MLX5_HASH_IP_IPSEC_SPI);
2141 case MLX5E_TT_IPV4_IPSEC_ESP:
2142 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2143 MLX5_L3_PROT_TYPE_IPV4);
2144 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2145 MLX5_HASH_IP_IPSEC_SPI);
2148 case MLX5E_TT_IPV6_IPSEC_ESP:
2149 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2150 MLX5_L3_PROT_TYPE_IPV6);
2151 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2152 MLX5_HASH_IP_IPSEC_SPI);
2156 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2157 MLX5_L3_PROT_TYPE_IPV4);
2158 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2163 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2164 MLX5_L3_PROT_TYPE_IPV6);
2165 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2170 "mlx5e_build_indir_tir_ctx: bad traffic type!\n");
2174 static void mlx5e_build_direct_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
2177 MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
2179 mlx5e_build_tir_ctx_lro(tirc, priv);
2181 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
2182 MLX5_SET(tirc, tirc, indirect_table, rqtn);
2183 MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_INVERTED_XOR8);
2186 static int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv)
2188 struct mlx5e_tir *tir;
2195 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
2196 in = mlx5_vzalloc(inlen);
2200 for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) {
2201 memset(in, 0, inlen);
2202 tir = &priv->indir_tir[tt];
2203 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
2204 mlx5e_build_indir_tir_ctx(priv, tirc, tt);
2205 err = mlx5e_create_tir(priv->mdev, tir, in, inlen);
2207 goto err_destroy_tirs;
2215 for (tt--; tt >= 0; tt--)
2216 mlx5e_destroy_tir(priv->mdev, &priv->indir_tir[tt]);
2223 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv)
2225 int nch = priv->profile->max_nch(priv->mdev);
2226 struct mlx5e_tir *tir;
2233 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
2234 in = mlx5_vzalloc(inlen);
2238 for (ix = 0; ix < nch; ix++) {
2239 memset(in, 0, inlen);
2240 tir = &priv->direct_tir[ix];
2241 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
2242 mlx5e_build_direct_tir_ctx(priv, tirc,
2243 priv->direct_tir[ix].rqt.rqtn);
2244 err = mlx5e_create_tir(priv->mdev, tir, in, inlen);
2246 goto err_destroy_ch_tirs;
2253 err_destroy_ch_tirs:
2254 for (ix--; ix >= 0; ix--)
2255 mlx5e_destroy_tir(priv->mdev, &priv->direct_tir[ix]);
2262 static void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv)
2266 for (i = 0; i < MLX5E_NUM_INDIR_TIRS; i++)
2267 mlx5e_destroy_tir(priv->mdev, &priv->indir_tir[i]);
2270 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv)
2272 int nch = priv->profile->max_nch(priv->mdev);
2275 for (i = 0; i < nch; i++)
2276 mlx5e_destroy_tir(priv->mdev, &priv->direct_tir[i]);
2279 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd)
2284 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
2287 for (i = 0; i < priv->params.num_channels; i++) {
2288 err = mlx5e_modify_rq_vsd(&priv->channel[i]->rq, vsd);
2296 static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
2298 struct mlx5e_priv *priv = netdev_priv(netdev);
2302 if (tc && tc != MLX5E_MAX_NUM_TC)
2305 mutex_lock(&priv->state_lock);
2307 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2309 mlx5e_close_locked(priv->netdev);
2311 priv->params.num_tc = tc ? tc : 1;
2314 err = mlx5e_open_locked(priv->netdev);
2316 mutex_unlock(&priv->state_lock);
2321 static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
2322 __be16 proto, struct tc_to_netdev *tc)
2324 struct mlx5e_priv *priv = netdev_priv(dev);
2326 if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
2330 case TC_SETUP_CLSFLOWER:
2331 switch (tc->cls_flower->command) {
2332 case TC_CLSFLOWER_REPLACE:
2333 return mlx5e_configure_flower(priv, proto, tc->cls_flower);
2334 case TC_CLSFLOWER_DESTROY:
2335 return mlx5e_delete_flower(priv, tc->cls_flower);
2336 case TC_CLSFLOWER_STATS:
2337 return mlx5e_stats_flower(priv, tc->cls_flower);
2344 if (tc->type != TC_SETUP_MQPRIO)
2347 return mlx5e_setup_tc(dev, tc->tc);
2350 struct rtnl_link_stats64 *
2351 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
2353 struct mlx5e_priv *priv = netdev_priv(dev);
2354 struct mlx5e_sw_stats *sstats = &priv->stats.sw;
2355 struct mlx5e_vport_stats *vstats = &priv->stats.vport;
2356 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
2358 stats->rx_packets = sstats->rx_packets;
2359 stats->rx_bytes = sstats->rx_bytes;
2360 stats->tx_packets = sstats->tx_packets;
2361 stats->tx_bytes = sstats->tx_bytes;
2363 stats->rx_dropped = priv->stats.qcnt.rx_out_of_buffer;
2364 stats->tx_dropped = sstats->tx_queue_dropped;
2366 stats->rx_length_errors =
2367 PPORT_802_3_GET(pstats, a_in_range_length_errors) +
2368 PPORT_802_3_GET(pstats, a_out_of_range_length_field) +
2369 PPORT_802_3_GET(pstats, a_frame_too_long_errors);
2370 stats->rx_crc_errors =
2371 PPORT_802_3_GET(pstats, a_frame_check_sequence_errors);
2372 stats->rx_frame_errors = PPORT_802_3_GET(pstats, a_alignment_errors);
2373 stats->tx_aborted_errors = PPORT_2863_GET(pstats, if_out_discards);
2374 stats->tx_carrier_errors =
2375 PPORT_802_3_GET(pstats, a_symbol_error_during_carrier);
2376 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
2377 stats->rx_frame_errors;
2378 stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors;
2380 /* vport multicast also counts packets that are dropped due to steering
2381 * or rx out of buffer
2384 VPORT_COUNTER_GET(vstats, received_eth_multicast.packets);
2389 static void mlx5e_set_rx_mode(struct net_device *dev)
2391 struct mlx5e_priv *priv = netdev_priv(dev);
2393 queue_work(priv->wq, &priv->set_rx_mode_work);
2396 static int mlx5e_set_mac(struct net_device *netdev, void *addr)
2398 struct mlx5e_priv *priv = netdev_priv(netdev);
2399 struct sockaddr *saddr = addr;
2401 if (!is_valid_ether_addr(saddr->sa_data))
2402 return -EADDRNOTAVAIL;
2404 netif_addr_lock_bh(netdev);
2405 ether_addr_copy(netdev->dev_addr, saddr->sa_data);
2406 netif_addr_unlock_bh(netdev);
2408 queue_work(priv->wq, &priv->set_rx_mode_work);
2413 #define MLX5E_SET_FEATURE(netdev, feature, enable) \
2416 netdev->features |= feature; \
2418 netdev->features &= ~feature; \
2421 typedef int (*mlx5e_feature_handler)(struct net_device *netdev, bool enable);
2423 static int set_feature_lro(struct net_device *netdev, bool enable)
2425 struct mlx5e_priv *priv = netdev_priv(netdev);
2426 bool was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2429 mutex_lock(&priv->state_lock);
2431 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2432 mlx5e_close_locked(priv->netdev);
2434 priv->params.lro_en = enable;
2435 err = mlx5e_modify_tirs_lro(priv);
2437 netdev_err(netdev, "lro modify failed, %d\n", err);
2438 priv->params.lro_en = !enable;
2441 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2442 mlx5e_open_locked(priv->netdev);
2444 mutex_unlock(&priv->state_lock);
2449 static int set_feature_vlan_filter(struct net_device *netdev, bool enable)
2451 struct mlx5e_priv *priv = netdev_priv(netdev);
2454 mlx5e_enable_vlan_filter(priv);
2456 mlx5e_disable_vlan_filter(priv);
2461 static int set_feature_tc_num_filters(struct net_device *netdev, bool enable)
2463 struct mlx5e_priv *priv = netdev_priv(netdev);
2465 if (!enable && mlx5e_tc_num_filters(priv)) {
2467 "Active offloaded tc filters, can't turn hw_tc_offload off\n");
2474 static int set_feature_rx_all(struct net_device *netdev, bool enable)
2476 struct mlx5e_priv *priv = netdev_priv(netdev);
2477 struct mlx5_core_dev *mdev = priv->mdev;
2479 return mlx5_set_port_fcs(mdev, !enable);
2482 static int set_feature_rx_vlan(struct net_device *netdev, bool enable)
2484 struct mlx5e_priv *priv = netdev_priv(netdev);
2487 mutex_lock(&priv->state_lock);
2489 priv->params.vlan_strip_disable = !enable;
2490 err = mlx5e_modify_rqs_vsd(priv, !enable);
2492 priv->params.vlan_strip_disable = enable;
2494 mutex_unlock(&priv->state_lock);
2499 #ifdef CONFIG_RFS_ACCEL
2500 static int set_feature_arfs(struct net_device *netdev, bool enable)
2502 struct mlx5e_priv *priv = netdev_priv(netdev);
2506 err = mlx5e_arfs_enable(priv);
2508 err = mlx5e_arfs_disable(priv);
2514 static int mlx5e_handle_feature(struct net_device *netdev,
2515 netdev_features_t wanted_features,
2516 netdev_features_t feature,
2517 mlx5e_feature_handler feature_handler)
2519 netdev_features_t changes = wanted_features ^ netdev->features;
2520 bool enable = !!(wanted_features & feature);
2523 if (!(changes & feature))
2526 err = feature_handler(netdev, enable);
2528 netdev_err(netdev, "%s feature 0x%llx failed err %d\n",
2529 enable ? "Enable" : "Disable", feature, err);
2533 MLX5E_SET_FEATURE(netdev, feature, enable);
2537 static int mlx5e_set_features(struct net_device *netdev,
2538 netdev_features_t features)
2542 err = mlx5e_handle_feature(netdev, features, NETIF_F_LRO,
2544 err |= mlx5e_handle_feature(netdev, features,
2545 NETIF_F_HW_VLAN_CTAG_FILTER,
2546 set_feature_vlan_filter);
2547 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_TC,
2548 set_feature_tc_num_filters);
2549 err |= mlx5e_handle_feature(netdev, features, NETIF_F_RXALL,
2550 set_feature_rx_all);
2551 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_VLAN_CTAG_RX,
2552 set_feature_rx_vlan);
2553 #ifdef CONFIG_RFS_ACCEL
2554 err |= mlx5e_handle_feature(netdev, features, NETIF_F_NTUPLE,
2558 return err ? -EINVAL : 0;
2561 #define MXL5_HW_MIN_MTU 64
2562 #define MXL5E_MIN_MTU (MXL5_HW_MIN_MTU + ETH_FCS_LEN)
2564 static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
2566 struct mlx5e_priv *priv = netdev_priv(netdev);
2567 struct mlx5_core_dev *mdev = priv->mdev;
2574 mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
2576 max_mtu = MLX5E_HW2SW_MTU(max_mtu);
2577 min_mtu = MLX5E_HW2SW_MTU(MXL5E_MIN_MTU);
2579 if (new_mtu > max_mtu || new_mtu < min_mtu) {
2581 "%s: Bad MTU (%d), valid range is: [%d..%d]\n",
2582 __func__, new_mtu, min_mtu, max_mtu);
2586 mutex_lock(&priv->state_lock);
2588 reset = !priv->params.lro_en &&
2589 (priv->params.rq_wq_type !=
2590 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
2592 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2593 if (was_opened && reset)
2594 mlx5e_close_locked(netdev);
2596 netdev->mtu = new_mtu;
2597 mlx5e_set_dev_port_mtu(netdev);
2599 if (was_opened && reset)
2600 err = mlx5e_open_locked(netdev);
2602 mutex_unlock(&priv->state_lock);
2607 static int mlx5e_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2611 return mlx5e_hwstamp_set(dev, ifr);
2613 return mlx5e_hwstamp_get(dev, ifr);
2619 static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2621 struct mlx5e_priv *priv = netdev_priv(dev);
2622 struct mlx5_core_dev *mdev = priv->mdev;
2624 return mlx5_eswitch_set_vport_mac(mdev->priv.eswitch, vf + 1, mac);
2627 static int mlx5e_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2629 struct mlx5e_priv *priv = netdev_priv(dev);
2630 struct mlx5_core_dev *mdev = priv->mdev;
2632 return mlx5_eswitch_set_vport_vlan(mdev->priv.eswitch, vf + 1,
2636 static int mlx5e_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2638 struct mlx5e_priv *priv = netdev_priv(dev);
2639 struct mlx5_core_dev *mdev = priv->mdev;
2641 return mlx5_eswitch_set_vport_spoofchk(mdev->priv.eswitch, vf + 1, setting);
2644 static int mlx5e_set_vf_trust(struct net_device *dev, int vf, bool setting)
2646 struct mlx5e_priv *priv = netdev_priv(dev);
2647 struct mlx5_core_dev *mdev = priv->mdev;
2649 return mlx5_eswitch_set_vport_trust(mdev->priv.eswitch, vf + 1, setting);
2651 static int mlx5_vport_link2ifla(u8 esw_link)
2654 case MLX5_ESW_VPORT_ADMIN_STATE_DOWN:
2655 return IFLA_VF_LINK_STATE_DISABLE;
2656 case MLX5_ESW_VPORT_ADMIN_STATE_UP:
2657 return IFLA_VF_LINK_STATE_ENABLE;
2659 return IFLA_VF_LINK_STATE_AUTO;
2662 static int mlx5_ifla_link2vport(u8 ifla_link)
2664 switch (ifla_link) {
2665 case IFLA_VF_LINK_STATE_DISABLE:
2666 return MLX5_ESW_VPORT_ADMIN_STATE_DOWN;
2667 case IFLA_VF_LINK_STATE_ENABLE:
2668 return MLX5_ESW_VPORT_ADMIN_STATE_UP;
2670 return MLX5_ESW_VPORT_ADMIN_STATE_AUTO;
2673 static int mlx5e_set_vf_link_state(struct net_device *dev, int vf,
2676 struct mlx5e_priv *priv = netdev_priv(dev);
2677 struct mlx5_core_dev *mdev = priv->mdev;
2679 return mlx5_eswitch_set_vport_state(mdev->priv.eswitch, vf + 1,
2680 mlx5_ifla_link2vport(link_state));
2683 static int mlx5e_get_vf_config(struct net_device *dev,
2684 int vf, struct ifla_vf_info *ivi)
2686 struct mlx5e_priv *priv = netdev_priv(dev);
2687 struct mlx5_core_dev *mdev = priv->mdev;
2690 err = mlx5_eswitch_get_vport_config(mdev->priv.eswitch, vf + 1, ivi);
2693 ivi->linkstate = mlx5_vport_link2ifla(ivi->linkstate);
2697 static int mlx5e_get_vf_stats(struct net_device *dev,
2698 int vf, struct ifla_vf_stats *vf_stats)
2700 struct mlx5e_priv *priv = netdev_priv(dev);
2701 struct mlx5_core_dev *mdev = priv->mdev;
2703 return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
2707 static void mlx5e_add_vxlan_port(struct net_device *netdev,
2708 struct udp_tunnel_info *ti)
2710 struct mlx5e_priv *priv = netdev_priv(netdev);
2712 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2715 if (!mlx5e_vxlan_allowed(priv->mdev))
2718 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 1);
2721 static void mlx5e_del_vxlan_port(struct net_device *netdev,
2722 struct udp_tunnel_info *ti)
2724 struct mlx5e_priv *priv = netdev_priv(netdev);
2726 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2729 if (!mlx5e_vxlan_allowed(priv->mdev))
2732 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 0);
2735 static netdev_features_t mlx5e_vxlan_features_check(struct mlx5e_priv *priv,
2736 struct sk_buff *skb,
2737 netdev_features_t features)
2739 struct udphdr *udph;
2743 switch (vlan_get_protocol(skb)) {
2744 case htons(ETH_P_IP):
2745 proto = ip_hdr(skb)->protocol;
2747 case htons(ETH_P_IPV6):
2748 proto = ipv6_hdr(skb)->nexthdr;
2754 if (proto == IPPROTO_UDP) {
2755 udph = udp_hdr(skb);
2756 port = be16_to_cpu(udph->dest);
2759 /* Verify if UDP port is being offloaded by HW */
2760 if (port && mlx5e_vxlan_lookup_port(priv, port))
2764 /* Disable CSUM and GSO if the udp dport is not offloaded by HW */
2765 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2768 static netdev_features_t mlx5e_features_check(struct sk_buff *skb,
2769 struct net_device *netdev,
2770 netdev_features_t features)
2772 struct mlx5e_priv *priv = netdev_priv(netdev);
2774 features = vlan_features_check(skb, features);
2775 features = vxlan_features_check(skb, features);
2777 /* Validate if the tunneled packet is being offloaded by HW */
2778 if (skb->encapsulation &&
2779 (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
2780 return mlx5e_vxlan_features_check(priv, skb, features);
2785 static void mlx5e_tx_timeout(struct net_device *dev)
2787 struct mlx5e_priv *priv = netdev_priv(dev);
2788 bool sched_work = false;
2791 netdev_err(dev, "TX timeout detected\n");
2793 for (i = 0; i < priv->params.num_channels * priv->params.num_tc; i++) {
2794 struct mlx5e_sq *sq = priv->txq_to_sq_map[i];
2796 if (!netif_xmit_stopped(netdev_get_tx_queue(dev, i)))
2799 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
2800 netdev_err(dev, "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x\n",
2801 i, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc);
2804 if (sched_work && test_bit(MLX5E_STATE_OPENED, &priv->state))
2805 schedule_work(&priv->tx_timeout_work);
2808 static const struct net_device_ops mlx5e_netdev_ops_basic = {
2809 .ndo_open = mlx5e_open,
2810 .ndo_stop = mlx5e_close,
2811 .ndo_start_xmit = mlx5e_xmit,
2812 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2813 .ndo_select_queue = mlx5e_select_queue,
2814 .ndo_get_stats64 = mlx5e_get_stats,
2815 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2816 .ndo_set_mac_address = mlx5e_set_mac,
2817 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2818 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2819 .ndo_set_features = mlx5e_set_features,
2820 .ndo_change_mtu = mlx5e_change_mtu,
2821 .ndo_do_ioctl = mlx5e_ioctl,
2822 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2823 #ifdef CONFIG_RFS_ACCEL
2824 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2826 .ndo_tx_timeout = mlx5e_tx_timeout,
2829 static const struct net_device_ops mlx5e_netdev_ops_sriov = {
2830 .ndo_open = mlx5e_open,
2831 .ndo_stop = mlx5e_close,
2832 .ndo_start_xmit = mlx5e_xmit,
2833 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2834 .ndo_select_queue = mlx5e_select_queue,
2835 .ndo_get_stats64 = mlx5e_get_stats,
2836 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2837 .ndo_set_mac_address = mlx5e_set_mac,
2838 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2839 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2840 .ndo_set_features = mlx5e_set_features,
2841 .ndo_change_mtu = mlx5e_change_mtu,
2842 .ndo_do_ioctl = mlx5e_ioctl,
2843 .ndo_udp_tunnel_add = mlx5e_add_vxlan_port,
2844 .ndo_udp_tunnel_del = mlx5e_del_vxlan_port,
2845 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2846 .ndo_features_check = mlx5e_features_check,
2847 #ifdef CONFIG_RFS_ACCEL
2848 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2850 .ndo_set_vf_mac = mlx5e_set_vf_mac,
2851 .ndo_set_vf_vlan = mlx5e_set_vf_vlan,
2852 .ndo_set_vf_spoofchk = mlx5e_set_vf_spoofchk,
2853 .ndo_set_vf_trust = mlx5e_set_vf_trust,
2854 .ndo_get_vf_config = mlx5e_get_vf_config,
2855 .ndo_set_vf_link_state = mlx5e_set_vf_link_state,
2856 .ndo_get_vf_stats = mlx5e_get_vf_stats,
2857 .ndo_tx_timeout = mlx5e_tx_timeout,
2860 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
2862 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
2864 if (!MLX5_CAP_GEN(mdev, eth_net_offloads) ||
2865 !MLX5_CAP_GEN(mdev, nic_flow_table) ||
2866 !MLX5_CAP_ETH(mdev, csum_cap) ||
2867 !MLX5_CAP_ETH(mdev, max_lso_cap) ||
2868 !MLX5_CAP_ETH(mdev, vlan_cap) ||
2869 !MLX5_CAP_ETH(mdev, rss_ind_tbl_cap) ||
2870 MLX5_CAP_FLOWTABLE(mdev,
2871 flow_table_properties_nic_receive.max_ft_level)
2873 mlx5_core_warn(mdev,
2874 "Not creating net device, some required device capabilities are missing\n");
2877 if (!MLX5_CAP_ETH(mdev, self_lb_en_modifiable))
2878 mlx5_core_warn(mdev, "Self loop back prevention is not supported\n");
2879 if (!MLX5_CAP_GEN(mdev, cq_moderation))
2880 mlx5_core_warn(mdev, "CQ modiration is not supported\n");
2885 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev)
2887 int bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
2889 return bf_buf_size -
2890 sizeof(struct mlx5e_tx_wqe) +
2891 2 /*sizeof(mlx5e_tx_wqe.inline_hdr_start)*/;
2894 #ifdef CONFIG_MLX5_CORE_EN_DCB
2895 static void mlx5e_ets_init(struct mlx5e_priv *priv)
2899 priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
2900 for (i = 0; i < priv->params.ets.ets_cap; i++) {
2901 priv->params.ets.tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
2902 priv->params.ets.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
2903 priv->params.ets.prio_tc[i] = i;
2906 /* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
2907 priv->params.ets.prio_tc[0] = 1;
2908 priv->params.ets.prio_tc[1] = 0;
2912 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
2913 u32 *indirection_rqt, int len,
2916 int node = mdev->priv.numa_node;
2917 int node_num_of_cores;
2921 node = first_online_node;
2923 node_num_of_cores = cpumask_weight(cpumask_of_node(node));
2925 if (node_num_of_cores)
2926 num_channels = min_t(int, num_channels, node_num_of_cores);
2928 for (i = 0; i < len; i++)
2929 indirection_rqt[i] = i % num_channels;
2932 static bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
2934 return MLX5_CAP_GEN(mdev, striding_rq) &&
2935 MLX5_CAP_GEN(mdev, umr_ptr_rlky) &&
2936 MLX5_CAP_ETH(mdev, reg_umr_sq);
2939 static int mlx5e_get_pci_bw(struct mlx5_core_dev *mdev, u32 *pci_bw)
2941 enum pcie_link_width width;
2942 enum pci_bus_speed speed;
2945 err = pcie_get_minimum_link(mdev->pdev, &speed, &width);
2949 if (speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
2953 case PCIE_SPEED_2_5GT:
2954 *pci_bw = 2500 * width;
2956 case PCIE_SPEED_5_0GT:
2957 *pci_bw = 5000 * width;
2959 case PCIE_SPEED_8_0GT:
2960 *pci_bw = 8000 * width;
2969 static bool cqe_compress_heuristic(u32 link_speed, u32 pci_bw)
2971 return (link_speed && pci_bw &&
2972 (pci_bw < 40000) && (pci_bw < link_speed));
2975 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode)
2977 params->rx_cq_period_mode = cq_period_mode;
2979 params->rx_cq_moderation.pkts =
2980 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2981 params->rx_cq_moderation.usec =
2982 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2984 if (cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE)
2985 params->rx_cq_moderation.usec =
2986 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE;
2989 static void mlx5e_query_min_inline(struct mlx5_core_dev *mdev,
2990 u8 *min_inline_mode)
2992 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
2993 case MLX5E_INLINE_MODE_L2:
2994 *min_inline_mode = MLX5_INLINE_MODE_L2;
2996 case MLX5E_INLINE_MODE_VPORT_CONTEXT:
2997 mlx5_query_nic_vport_min_inline(mdev,
3000 case MLX5_INLINE_MODE_NOT_REQUIRED:
3001 *min_inline_mode = MLX5_INLINE_MODE_NONE;
3006 static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
3007 struct net_device *netdev,
3008 const struct mlx5e_profile *profile,
3011 struct mlx5e_priv *priv = netdev_priv(netdev);
3014 u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
3015 MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
3016 MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
3018 priv->params.log_sq_size =
3019 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
3020 priv->params.rq_wq_type = mlx5e_check_fragmented_striding_rq_cap(mdev) ?
3021 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
3022 MLX5_WQ_TYPE_LINKED_LIST;
3024 /* set CQE compression */
3025 priv->params.rx_cqe_compress_admin = false;
3026 if (MLX5_CAP_GEN(mdev, cqe_compression) &&
3027 MLX5_CAP_GEN(mdev, vport_group_manager)) {
3028 mlx5e_get_max_linkspeed(mdev, &link_speed);
3029 mlx5e_get_pci_bw(mdev, &pci_bw);
3030 mlx5_core_dbg(mdev, "Max link speed = %d, PCI BW = %d\n",
3031 link_speed, pci_bw);
3032 priv->params.rx_cqe_compress_admin =
3033 cqe_compress_heuristic(link_speed, pci_bw);
3036 priv->params.rx_cqe_compress = priv->params.rx_cqe_compress_admin;
3038 switch (priv->params.rq_wq_type) {
3039 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
3040 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW;
3041 priv->params.mpwqe_log_stride_sz =
3042 priv->params.rx_cqe_compress ?
3043 MLX5_MPWRQ_LOG_STRIDE_SIZE_CQE_COMPRESS :
3044 MLX5_MPWRQ_LOG_STRIDE_SIZE;
3045 priv->params.mpwqe_log_num_strides = MLX5_MPWRQ_LOG_WQE_SZ -
3046 priv->params.mpwqe_log_stride_sz;
3047 priv->params.lro_en = true;
3049 default: /* MLX5_WQ_TYPE_LINKED_LIST */
3050 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
3053 mlx5_core_info(mdev,
3054 "MLX5E: StrdRq(%d) RqSz(%ld) StrdSz(%ld) RxCqeCmprss(%d)\n",
3055 priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ,
3056 BIT(priv->params.log_rq_size),
3057 BIT(priv->params.mpwqe_log_stride_sz),
3058 priv->params.rx_cqe_compress_admin);
3060 priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
3061 BIT(priv->params.log_rq_size));
3063 priv->params.rx_am_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
3064 mlx5e_set_rx_cq_mode_params(&priv->params, cq_period_mode);
3066 priv->params.tx_cq_moderation.usec =
3067 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
3068 priv->params.tx_cq_moderation.pkts =
3069 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
3070 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
3071 mlx5e_query_min_inline(mdev, &priv->params.tx_min_inline_mode);
3072 priv->params.num_tc = 1;
3073 priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
3075 netdev_rss_key_fill(priv->params.toeplitz_hash_key,
3076 sizeof(priv->params.toeplitz_hash_key));
3078 mlx5e_build_default_indir_rqt(mdev, priv->params.indirection_rqt,
3079 MLX5E_INDIR_RQT_SIZE, profile->max_nch(mdev));
3081 priv->params.lro_wqe_sz =
3082 MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
3084 /* Initialize pflags */
3085 MLX5E_SET_PRIV_FLAG(priv, MLX5E_PFLAG_RX_CQE_BASED_MODER,
3086 priv->params.rx_cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE);
3089 priv->netdev = netdev;
3090 priv->params.num_channels = profile->max_nch(mdev);
3091 priv->profile = profile;
3092 priv->ppriv = ppriv;
3094 #ifdef CONFIG_MLX5_CORE_EN_DCB
3095 mlx5e_ets_init(priv);
3098 mutex_init(&priv->state_lock);
3100 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
3101 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
3102 INIT_WORK(&priv->tx_timeout_work, mlx5e_tx_timeout_work);
3103 INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
3106 static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
3108 struct mlx5e_priv *priv = netdev_priv(netdev);
3110 mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
3111 if (is_zero_ether_addr(netdev->dev_addr) &&
3112 !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
3113 eth_hw_addr_random(netdev);
3114 mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr);
3118 static const struct switchdev_ops mlx5e_switchdev_ops = {
3119 .switchdev_port_attr_get = mlx5e_attr_get,
3122 static void mlx5e_build_nic_netdev(struct net_device *netdev)
3124 struct mlx5e_priv *priv = netdev_priv(netdev);
3125 struct mlx5_core_dev *mdev = priv->mdev;
3129 SET_NETDEV_DEV(netdev, &mdev->pdev->dev);
3131 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3132 netdev->netdev_ops = &mlx5e_netdev_ops_sriov;
3133 #ifdef CONFIG_MLX5_CORE_EN_DCB
3134 netdev->dcbnl_ops = &mlx5e_dcbnl_ops;
3137 netdev->netdev_ops = &mlx5e_netdev_ops_basic;
3140 netdev->watchdog_timeo = 15 * HZ;
3142 netdev->ethtool_ops = &mlx5e_ethtool_ops;
3144 netdev->vlan_features |= NETIF_F_SG;
3145 netdev->vlan_features |= NETIF_F_IP_CSUM;
3146 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
3147 netdev->vlan_features |= NETIF_F_GRO;
3148 netdev->vlan_features |= NETIF_F_TSO;
3149 netdev->vlan_features |= NETIF_F_TSO6;
3150 netdev->vlan_features |= NETIF_F_RXCSUM;
3151 netdev->vlan_features |= NETIF_F_RXHASH;
3153 if (!!MLX5_CAP_ETH(mdev, lro_cap))
3154 netdev->vlan_features |= NETIF_F_LRO;
3156 netdev->hw_features = netdev->vlan_features;
3157 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
3158 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
3159 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
3161 if (mlx5e_vxlan_allowed(mdev)) {
3162 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL |
3163 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3164 NETIF_F_GSO_PARTIAL;
3165 netdev->hw_enc_features |= NETIF_F_IP_CSUM;
3166 netdev->hw_enc_features |= NETIF_F_IPV6_CSUM;
3167 netdev->hw_enc_features |= NETIF_F_TSO;
3168 netdev->hw_enc_features |= NETIF_F_TSO6;
3169 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL;
3170 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3171 NETIF_F_GSO_PARTIAL;
3172 netdev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM;
3175 mlx5_query_port_fcs(mdev, &fcs_supported, &fcs_enabled);
3178 netdev->hw_features |= NETIF_F_RXALL;
3180 netdev->features = netdev->hw_features;
3181 if (!priv->params.lro_en)
3182 netdev->features &= ~NETIF_F_LRO;
3185 netdev->features &= ~NETIF_F_RXALL;
3187 #define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
3188 if (FT_CAP(flow_modify_en) &&
3189 FT_CAP(modify_root) &&
3190 FT_CAP(identified_miss_table_mode) &&
3191 FT_CAP(flow_table_modify)) {
3192 netdev->hw_features |= NETIF_F_HW_TC;
3193 #ifdef CONFIG_RFS_ACCEL
3194 netdev->hw_features |= NETIF_F_NTUPLE;
3198 netdev->features |= NETIF_F_HIGHDMA;
3200 netdev->priv_flags |= IFF_UNICAST_FLT;
3202 mlx5e_set_netdev_dev_addr(netdev);
3204 #ifdef CONFIG_NET_SWITCHDEV
3205 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3206 netdev->switchdev_ops = &mlx5e_switchdev_ops;
3210 static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
3212 struct mlx5_core_dev *mdev = priv->mdev;
3215 err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter);
3217 mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err);
3218 priv->q_counter = 0;
3222 static void mlx5e_destroy_q_counter(struct mlx5e_priv *priv)
3224 if (!priv->q_counter)
3227 mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter);
3230 static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
3232 struct mlx5_core_dev *mdev = priv->mdev;
3233 struct mlx5_create_mkey_mbox_in *in;
3234 struct mlx5_mkey_seg *mkc;
3235 int inlen = sizeof(*in);
3237 priv->profile->max_nch(mdev) * MLX5_CHANNEL_MAX_NUM_MTTS;
3240 in = mlx5_vzalloc(inlen);
3245 mkc->status = MLX5_MKEY_STATUS_FREE;
3246 mkc->flags = MLX5_PERM_UMR_EN |
3247 MLX5_PERM_LOCAL_READ |
3248 MLX5_PERM_LOCAL_WRITE |
3249 MLX5_ACCESS_MODE_MTT;
3251 mkc->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
3252 mkc->flags_pd = cpu_to_be32(mdev->mlx5e_res.pdn);
3253 mkc->len = cpu_to_be64(npages << PAGE_SHIFT);
3254 mkc->xlt_oct_size = cpu_to_be32(mlx5e_get_mtt_octw(npages));
3255 mkc->log2_page_size = PAGE_SHIFT;
3257 err = mlx5_core_create_mkey(mdev, &priv->umr_mkey, in, inlen, NULL,
3265 static void mlx5e_nic_init(struct mlx5_core_dev *mdev,
3266 struct net_device *netdev,
3267 const struct mlx5e_profile *profile,
3270 struct mlx5e_priv *priv = netdev_priv(netdev);
3272 mlx5e_build_nic_netdev_priv(mdev, netdev, profile, ppriv);
3273 mlx5e_build_nic_netdev(netdev);
3274 mlx5e_vxlan_init(priv);
3277 static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
3279 struct mlx5_core_dev *mdev = priv->mdev;
3280 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3282 mlx5e_vxlan_cleanup(priv);
3284 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3285 mlx5_eswitch_unregister_vport_rep(esw, 0);
3288 static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
3290 struct mlx5_core_dev *mdev = priv->mdev;
3294 err = mlx5e_create_indirect_rqts(priv);
3296 mlx5_core_warn(mdev, "create indirect rqts failed, %d\n", err);
3300 err = mlx5e_create_direct_rqts(priv);
3302 mlx5_core_warn(mdev, "create direct rqts failed, %d\n", err);
3303 goto err_destroy_indirect_rqts;
3306 err = mlx5e_create_indirect_tirs(priv);
3308 mlx5_core_warn(mdev, "create indirect tirs failed, %d\n", err);
3309 goto err_destroy_direct_rqts;
3312 err = mlx5e_create_direct_tirs(priv);
3314 mlx5_core_warn(mdev, "create direct tirs failed, %d\n", err);
3315 goto err_destroy_indirect_tirs;
3318 err = mlx5e_create_flow_steering(priv);
3320 mlx5_core_warn(mdev, "create flow steering failed, %d\n", err);
3321 goto err_destroy_direct_tirs;
3324 err = mlx5e_tc_init(priv);
3326 goto err_destroy_flow_steering;
3330 err_destroy_flow_steering:
3331 mlx5e_destroy_flow_steering(priv);
3332 err_destroy_direct_tirs:
3333 mlx5e_destroy_direct_tirs(priv);
3334 err_destroy_indirect_tirs:
3335 mlx5e_destroy_indirect_tirs(priv);
3336 err_destroy_direct_rqts:
3337 for (i = 0; i < priv->profile->max_nch(mdev); i++)
3338 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3339 err_destroy_indirect_rqts:
3340 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3344 static void mlx5e_cleanup_nic_rx(struct mlx5e_priv *priv)
3348 mlx5e_tc_cleanup(priv);
3349 mlx5e_destroy_flow_steering(priv);
3350 mlx5e_destroy_direct_tirs(priv);
3351 mlx5e_destroy_indirect_tirs(priv);
3352 for (i = 0; i < priv->profile->max_nch(priv->mdev); i++)
3353 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3354 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3357 static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
3361 err = mlx5e_create_tises(priv);
3363 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
3367 #ifdef CONFIG_MLX5_CORE_EN_DCB
3368 mlx5e_dcbnl_ieee_setets_core(priv, &priv->params.ets);
3373 static void mlx5e_nic_enable(struct mlx5e_priv *priv)
3375 struct net_device *netdev = priv->netdev;
3376 struct mlx5_core_dev *mdev = priv->mdev;
3377 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3378 struct mlx5_eswitch_rep rep;
3380 if (mlx5e_vxlan_allowed(mdev)) {
3382 udp_tunnel_get_rx_info(netdev);
3386 mlx5e_enable_async_events(priv);
3387 queue_work(priv->wq, &priv->set_rx_mode_work);
3389 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3390 rep.load = mlx5e_nic_rep_load;
3391 rep.unload = mlx5e_nic_rep_unload;
3393 rep.priv_data = priv;
3394 mlx5_eswitch_register_vport_rep(esw, &rep);
3398 static void mlx5e_nic_disable(struct mlx5e_priv *priv)
3400 queue_work(priv->wq, &priv->set_rx_mode_work);
3401 mlx5e_disable_async_events(priv);
3404 static const struct mlx5e_profile mlx5e_nic_profile = {
3405 .init = mlx5e_nic_init,
3406 .cleanup = mlx5e_nic_cleanup,
3407 .init_rx = mlx5e_init_nic_rx,
3408 .cleanup_rx = mlx5e_cleanup_nic_rx,
3409 .init_tx = mlx5e_init_nic_tx,
3410 .cleanup_tx = mlx5e_cleanup_nic_tx,
3411 .enable = mlx5e_nic_enable,
3412 .disable = mlx5e_nic_disable,
3413 .update_stats = mlx5e_update_stats,
3414 .max_nch = mlx5e_get_max_num_channels,
3415 .max_tc = MLX5E_MAX_NUM_TC,
3418 void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
3419 const struct mlx5e_profile *profile, void *ppriv)
3421 struct net_device *netdev;
3422 struct mlx5e_priv *priv;
3423 int nch = profile->max_nch(mdev);
3426 netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
3427 nch * profile->max_tc,
3430 mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
3434 profile->init(mdev, netdev, profile, ppriv);
3436 netif_carrier_off(netdev);
3438 priv = netdev_priv(netdev);
3440 priv->wq = create_singlethread_workqueue("mlx5e");
3442 goto err_free_netdev;
3444 err = mlx5e_create_umr_mkey(priv);
3446 mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
3447 goto err_destroy_wq;
3450 err = profile->init_tx(priv);
3452 goto err_destroy_umr_mkey;
3454 err = mlx5e_open_drop_rq(priv);
3456 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
3457 goto err_cleanup_tx;
3460 err = profile->init_rx(priv);
3462 goto err_close_drop_rq;
3464 mlx5e_create_q_counter(priv);
3466 mlx5e_init_l2_addr(priv);
3468 mlx5e_set_dev_port_mtu(netdev);
3470 err = register_netdev(netdev);
3472 mlx5_core_err(mdev, "register_netdev failed, %d\n", err);
3473 goto err_dealloc_q_counters;
3476 if (profile->enable)
3477 profile->enable(priv);
3481 err_dealloc_q_counters:
3482 mlx5e_destroy_q_counter(priv);
3483 profile->cleanup_rx(priv);
3486 mlx5e_close_drop_rq(priv);
3489 profile->cleanup_tx(priv);
3491 err_destroy_umr_mkey:
3492 mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
3495 destroy_workqueue(priv->wq);
3498 free_netdev(netdev);
3503 static void mlx5e_register_vport_rep(struct mlx5_core_dev *mdev)
3505 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3506 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3509 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
3512 for (vport = 1; vport < total_vfs; vport++) {
3513 struct mlx5_eswitch_rep rep;
3515 rep.load = mlx5e_vport_rep_load;
3516 rep.unload = mlx5e_vport_rep_unload;
3518 mlx5_eswitch_register_vport_rep(esw, &rep);
3522 static void *mlx5e_add(struct mlx5_core_dev *mdev)
3524 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3528 if (mlx5e_check_required_hca_cap(mdev))
3531 if (mlx5e_create_mdev_resources(mdev))
3534 mlx5e_register_vport_rep(mdev);
3536 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3537 ppriv = &esw->offloads.vport_reps[0];
3539 ret = mlx5e_create_netdev(mdev, &mlx5e_nic_profile, ppriv);
3541 mlx5e_destroy_mdev_resources(mdev);
3547 void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
3549 const struct mlx5e_profile *profile = priv->profile;
3550 struct net_device *netdev = priv->netdev;
3552 set_bit(MLX5E_STATE_DESTROYING, &priv->state);
3553 if (profile->disable)
3554 profile->disable(priv);
3556 flush_workqueue(priv->wq);
3557 if (test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state)) {
3558 netif_device_detach(netdev);
3559 mlx5e_close(netdev);
3561 unregister_netdev(netdev);
3564 mlx5e_destroy_q_counter(priv);
3565 profile->cleanup_rx(priv);
3566 mlx5e_close_drop_rq(priv);
3567 profile->cleanup_tx(priv);
3568 mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
3569 cancel_delayed_work_sync(&priv->update_stats_work);
3570 destroy_workqueue(priv->wq);
3571 if (profile->cleanup)
3572 profile->cleanup(priv);
3574 if (!test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state))
3575 free_netdev(netdev);
3578 static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
3580 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3581 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3582 struct mlx5e_priv *priv = vpriv;
3585 mlx5e_destroy_netdev(mdev, priv);
3587 for (vport = 1; vport < total_vfs; vport++)
3588 mlx5_eswitch_unregister_vport_rep(esw, vport);
3590 mlx5e_destroy_mdev_resources(mdev);
3593 static void *mlx5e_get_netdev(void *vpriv)
3595 struct mlx5e_priv *priv = vpriv;
3597 return priv->netdev;
3600 static struct mlx5_interface mlx5e_interface = {
3602 .remove = mlx5e_remove,
3603 .event = mlx5e_async_event,
3604 .protocol = MLX5_INTERFACE_PROTOCOL_ETH,
3605 .get_dev = mlx5e_get_netdev,
3608 void mlx5e_init(void)
3610 mlx5e_build_ptys2ethtool_map();
3611 mlx5_register_interface(&mlx5e_interface);
3614 void mlx5e_cleanup(void)
3616 mlx5_unregister_interface(&mlx5e_interface);