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)] = {0};
184 struct mlx5_core_dev *mdev = priv->mdev;
186 MLX5_SET(query_vport_counter_in, in, opcode,
187 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
188 MLX5_SET(query_vport_counter_in, in, op_mod, 0);
189 MLX5_SET(query_vport_counter_in, in, other_vport, 0);
191 memset(out, 0, outlen);
192 mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
195 static void mlx5e_update_pport_counters(struct mlx5e_priv *priv)
197 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
198 struct mlx5_core_dev *mdev = priv->mdev;
199 int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
204 in = mlx5_vzalloc(sz);
208 MLX5_SET(ppcnt_reg, in, local_port, 1);
210 out = pstats->IEEE_802_3_counters;
211 MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
212 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
214 out = pstats->RFC_2863_counters;
215 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
216 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
218 out = pstats->RFC_2819_counters;
219 MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
220 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
222 out = pstats->phy_counters;
223 MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
224 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
226 MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
227 for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
228 out = pstats->per_prio_counters[prio];
229 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
230 mlx5_core_access_reg(mdev, in, sz, out, sz,
231 MLX5_REG_PPCNT, 0, 0);
238 static void mlx5e_update_q_counter(struct mlx5e_priv *priv)
240 struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
242 if (!priv->q_counter)
245 mlx5_core_query_out_of_buffer(priv->mdev, priv->q_counter,
246 &qcnt->rx_out_of_buffer);
249 void mlx5e_update_stats(struct mlx5e_priv *priv)
251 mlx5e_update_q_counter(priv);
252 mlx5e_update_vport_counters(priv);
253 mlx5e_update_pport_counters(priv);
254 mlx5e_update_sw_counters(priv);
257 void mlx5e_update_stats_work(struct work_struct *work)
259 struct delayed_work *dwork = to_delayed_work(work);
260 struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
262 mutex_lock(&priv->state_lock);
263 if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
264 priv->profile->update_stats(priv);
265 queue_delayed_work(priv->wq, dwork,
266 msecs_to_jiffies(MLX5E_UPDATE_STATS_INTERVAL));
268 mutex_unlock(&priv->state_lock);
271 static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv,
272 enum mlx5_dev_event event, unsigned long param)
274 struct mlx5e_priv *priv = vpriv;
276 if (!test_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state))
280 case MLX5_DEV_EVENT_PORT_UP:
281 case MLX5_DEV_EVENT_PORT_DOWN:
282 queue_work(priv->wq, &priv->update_carrier_work);
290 static void mlx5e_enable_async_events(struct mlx5e_priv *priv)
292 set_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state);
295 static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
297 clear_bit(MLX5E_STATE_ASYNC_EVENTS_ENABLED, &priv->state);
298 synchronize_irq(mlx5_get_msix_vec(priv->mdev, MLX5_EQ_VEC_ASYNC));
301 #define MLX5E_HW2SW_MTU(hwmtu) (hwmtu - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
302 #define MLX5E_SW2HW_MTU(swmtu) (swmtu + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
304 static int mlx5e_create_rq(struct mlx5e_channel *c,
305 struct mlx5e_rq_param *param,
308 struct mlx5e_priv *priv = c->priv;
309 struct mlx5_core_dev *mdev = priv->mdev;
310 void *rqc = param->rqc;
311 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
317 param->wq.db_numa_node = cpu_to_node(c->cpu);
319 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
324 rq->wq.db = &rq->wq.db[MLX5_RCV_DBR];
326 wq_sz = mlx5_wq_ll_get_size(&rq->wq);
328 switch (priv->params.rq_wq_type) {
329 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
330 rq->wqe_info = kzalloc_node(wq_sz * sizeof(*rq->wqe_info),
331 GFP_KERNEL, cpu_to_node(c->cpu));
334 goto err_rq_wq_destroy;
336 rq->handle_rx_cqe = mlx5e_handle_rx_cqe_mpwrq;
337 rq->alloc_wqe = mlx5e_alloc_rx_mpwqe;
338 rq->dealloc_wqe = mlx5e_dealloc_rx_mpwqe;
340 rq->mpwqe_stride_sz = BIT(priv->params.mpwqe_log_stride_sz);
341 rq->mpwqe_num_strides = BIT(priv->params.mpwqe_log_num_strides);
342 rq->wqe_sz = rq->mpwqe_stride_sz * rq->mpwqe_num_strides;
343 byte_count = rq->wqe_sz;
345 default: /* MLX5_WQ_TYPE_LINKED_LIST */
346 rq->skb = kzalloc_node(wq_sz * sizeof(*rq->skb), GFP_KERNEL,
347 cpu_to_node(c->cpu));
350 goto err_rq_wq_destroy;
352 rq->handle_rx_cqe = mlx5e_handle_rx_cqe;
353 rq->alloc_wqe = mlx5e_alloc_rx_wqe;
354 rq->dealloc_wqe = mlx5e_dealloc_rx_wqe;
356 rq->wqe_sz = (priv->params.lro_en) ?
357 priv->params.lro_wqe_sz :
358 MLX5E_SW2HW_MTU(priv->netdev->mtu);
359 rq->wqe_sz = SKB_DATA_ALIGN(rq->wqe_sz);
360 byte_count = rq->wqe_sz;
361 byte_count |= MLX5_HW_START_PADDING;
364 for (i = 0; i < wq_sz; i++) {
365 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
367 wqe->data.byte_count = cpu_to_be32(byte_count);
370 INIT_WORK(&rq->am.work, mlx5e_rx_am_work);
371 rq->am.mode = priv->params.rx_cq_period_mode;
373 rq->wq_type = priv->params.rq_wq_type;
375 rq->netdev = c->netdev;
376 rq->tstamp = &priv->tstamp;
380 rq->mkey_be = c->mkey_be;
381 rq->umr_mkey_be = cpu_to_be32(c->priv->umr_mkey.key);
386 mlx5_wq_destroy(&rq->wq_ctrl);
391 static void mlx5e_destroy_rq(struct mlx5e_rq *rq)
393 switch (rq->wq_type) {
394 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
397 default: /* MLX5_WQ_TYPE_LINKED_LIST */
401 mlx5_wq_destroy(&rq->wq_ctrl);
404 static int mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param)
406 struct mlx5e_priv *priv = rq->priv;
407 struct mlx5_core_dev *mdev = priv->mdev;
415 inlen = MLX5_ST_SZ_BYTES(create_rq_in) +
416 sizeof(u64) * rq->wq_ctrl.buf.npages;
417 in = mlx5_vzalloc(inlen);
421 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx);
422 wq = MLX5_ADDR_OF(rqc, rqc, wq);
424 memcpy(rqc, param->rqc, sizeof(param->rqc));
426 MLX5_SET(rqc, rqc, cqn, rq->cq.mcq.cqn);
427 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST);
428 MLX5_SET(rqc, rqc, flush_in_error_en, 1);
429 MLX5_SET(rqc, rqc, vsd, priv->params.vlan_strip_disable);
430 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift -
431 MLX5_ADAPTER_PAGE_SHIFT);
432 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma);
434 mlx5_fill_page_array(&rq->wq_ctrl.buf,
435 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
437 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn);
444 static int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state,
447 struct mlx5e_channel *c = rq->channel;
448 struct mlx5e_priv *priv = c->priv;
449 struct mlx5_core_dev *mdev = priv->mdev;
456 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
457 in = mlx5_vzalloc(inlen);
461 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
463 MLX5_SET(modify_rq_in, in, rq_state, curr_state);
464 MLX5_SET(rqc, rqc, state, next_state);
466 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
473 static int mlx5e_modify_rq_vsd(struct mlx5e_rq *rq, bool vsd)
475 struct mlx5e_channel *c = rq->channel;
476 struct mlx5e_priv *priv = c->priv;
477 struct mlx5_core_dev *mdev = priv->mdev;
484 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
485 in = mlx5_vzalloc(inlen);
489 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
491 MLX5_SET(modify_rq_in, in, rq_state, MLX5_RQC_STATE_RDY);
492 MLX5_SET64(modify_rq_in, in, modify_bitmask,
493 MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD);
494 MLX5_SET(rqc, rqc, vsd, vsd);
495 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RDY);
497 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
504 static void mlx5e_disable_rq(struct mlx5e_rq *rq)
506 mlx5_core_destroy_rq(rq->priv->mdev, rq->rqn);
509 static int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq)
511 unsigned long exp_time = jiffies + msecs_to_jiffies(20000);
512 struct mlx5e_channel *c = rq->channel;
513 struct mlx5e_priv *priv = c->priv;
514 struct mlx5_wq_ll *wq = &rq->wq;
516 while (time_before(jiffies, exp_time)) {
517 if (wq->cur_sz >= priv->params.min_rx_wqes)
526 static int mlx5e_open_rq(struct mlx5e_channel *c,
527 struct mlx5e_rq_param *param,
530 struct mlx5e_sq *sq = &c->icosq;
531 u16 pi = sq->pc & sq->wq.sz_m1;
534 err = mlx5e_create_rq(c, param, rq);
538 err = mlx5e_enable_rq(rq, param);
542 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
546 if (param->am_enabled)
547 set_bit(MLX5E_RQ_STATE_AM, &c->rq.state);
549 set_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
551 sq->ico_wqe_info[pi].opcode = MLX5_OPCODE_NOP;
552 sq->ico_wqe_info[pi].num_wqebbs = 1;
553 mlx5e_send_nop(sq, true); /* trigger mlx5e_post_rx_wqes() */
558 mlx5e_disable_rq(rq);
560 mlx5e_destroy_rq(rq);
565 static void mlx5e_close_rq(struct mlx5e_rq *rq)
570 clear_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
571 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
573 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR);
574 while (!mlx5_wq_ll_is_empty(&rq->wq) && !err &&
575 tout++ < MLX5_EN_QP_FLUSH_MAX_ITER)
576 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
578 if (err || tout == MLX5_EN_QP_FLUSH_MAX_ITER)
579 set_bit(MLX5E_RQ_STATE_FLUSH_TIMEOUT, &rq->state);
581 /* avoid destroying rq before mlx5e_poll_rx_cq() is done with it */
582 napi_synchronize(&rq->channel->napi);
584 cancel_work_sync(&rq->am.work);
586 mlx5e_disable_rq(rq);
587 mlx5e_free_rx_descs(rq);
588 mlx5e_destroy_rq(rq);
591 static void mlx5e_free_sq_db(struct mlx5e_sq *sq)
598 static int mlx5e_alloc_sq_db(struct mlx5e_sq *sq, int numa)
600 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
601 int df_sz = wq_sz * MLX5_SEND_WQEBB_NUM_DS;
603 sq->skb = kzalloc_node(wq_sz * sizeof(*sq->skb), GFP_KERNEL, numa);
604 sq->dma_fifo = kzalloc_node(df_sz * sizeof(*sq->dma_fifo), GFP_KERNEL,
606 sq->wqe_info = kzalloc_node(wq_sz * sizeof(*sq->wqe_info), GFP_KERNEL,
609 if (!sq->skb || !sq->dma_fifo || !sq->wqe_info) {
610 mlx5e_free_sq_db(sq);
614 sq->dma_fifo_mask = df_sz - 1;
619 static int mlx5e_create_sq(struct mlx5e_channel *c,
621 struct mlx5e_sq_param *param,
624 struct mlx5e_priv *priv = c->priv;
625 struct mlx5_core_dev *mdev = priv->mdev;
627 void *sqc = param->sqc;
628 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq);
631 err = mlx5_alloc_map_uar(mdev, &sq->uar, !!MLX5_CAP_GEN(mdev, bf));
635 param->wq.db_numa_node = cpu_to_node(c->cpu);
637 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq,
640 goto err_unmap_free_uar;
642 sq->wq.db = &sq->wq.db[MLX5_SND_DBR];
643 if (sq->uar.bf_map) {
644 set_bit(MLX5E_SQ_STATE_BF_ENABLE, &sq->state);
645 sq->uar_map = sq->uar.bf_map;
647 sq->uar_map = sq->uar.map;
649 sq->bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
650 sq->max_inline = param->max_inline;
651 sq->min_inline_mode =
652 MLX5_CAP_ETH(mdev, wqe_inline_mode) == MLX5E_INLINE_MODE_VPORT_CONTEXT ?
653 param->min_inline_mode : 0;
655 err = mlx5e_alloc_sq_db(sq, cpu_to_node(c->cpu));
657 goto err_sq_wq_destroy;
660 u8 wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
662 sq->ico_wqe_info = kzalloc_node(sizeof(*sq->ico_wqe_info) *
665 cpu_to_node(c->cpu));
666 if (!sq->ico_wqe_info) {
673 txq_ix = c->ix + tc * priv->params.num_channels;
674 sq->txq = netdev_get_tx_queue(priv->netdev, txq_ix);
675 priv->txq_to_sq_map[txq_ix] = sq;
679 sq->tstamp = &priv->tstamp;
680 sq->mkey_be = c->mkey_be;
683 sq->edge = (sq->wq.sz_m1 + 1) - MLX5_SEND_WQE_MAX_WQEBBS;
684 sq->bf_budget = MLX5E_SQ_BF_BUDGET;
689 mlx5e_free_sq_db(sq);
692 mlx5_wq_destroy(&sq->wq_ctrl);
695 mlx5_unmap_free_uar(mdev, &sq->uar);
700 static void mlx5e_destroy_sq(struct mlx5e_sq *sq)
702 struct mlx5e_channel *c = sq->channel;
703 struct mlx5e_priv *priv = c->priv;
705 kfree(sq->ico_wqe_info);
706 mlx5e_free_sq_db(sq);
707 mlx5_wq_destroy(&sq->wq_ctrl);
708 mlx5_unmap_free_uar(priv->mdev, &sq->uar);
711 static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
713 struct mlx5e_channel *c = sq->channel;
714 struct mlx5e_priv *priv = c->priv;
715 struct mlx5_core_dev *mdev = priv->mdev;
723 inlen = MLX5_ST_SZ_BYTES(create_sq_in) +
724 sizeof(u64) * sq->wq_ctrl.buf.npages;
725 in = mlx5_vzalloc(inlen);
729 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx);
730 wq = MLX5_ADDR_OF(sqc, sqc, wq);
732 memcpy(sqc, param->sqc, sizeof(param->sqc));
734 MLX5_SET(sqc, sqc, tis_num_0, param->icosq ? 0 : priv->tisn[sq->tc]);
735 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn);
736 MLX5_SET(sqc, sqc, min_wqe_inline_mode, sq->min_inline_mode);
737 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
738 MLX5_SET(sqc, sqc, tis_lst_sz, param->icosq ? 0 : 1);
739 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
741 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
742 MLX5_SET(wq, wq, uar_page, sq->uar.index);
743 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift -
744 MLX5_ADAPTER_PAGE_SHIFT);
745 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma);
747 mlx5_fill_page_array(&sq->wq_ctrl.buf,
748 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
750 err = mlx5_core_create_sq(mdev, in, inlen, &sq->sqn);
757 static int mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state,
758 int next_state, bool update_rl, int rl_index)
760 struct mlx5e_channel *c = sq->channel;
761 struct mlx5e_priv *priv = c->priv;
762 struct mlx5_core_dev *mdev = priv->mdev;
769 inlen = MLX5_ST_SZ_BYTES(modify_sq_in);
770 in = mlx5_vzalloc(inlen);
774 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx);
776 MLX5_SET(modify_sq_in, in, sq_state, curr_state);
777 MLX5_SET(sqc, sqc, state, next_state);
778 if (update_rl && next_state == MLX5_SQC_STATE_RDY) {
779 MLX5_SET64(modify_sq_in, in, modify_bitmask, 1);
780 MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index);
783 err = mlx5_core_modify_sq(mdev, sq->sqn, in, inlen);
790 static void mlx5e_disable_sq(struct mlx5e_sq *sq)
792 struct mlx5e_channel *c = sq->channel;
793 struct mlx5e_priv *priv = c->priv;
794 struct mlx5_core_dev *mdev = priv->mdev;
796 mlx5_core_destroy_sq(mdev, sq->sqn);
798 mlx5_rl_remove_rate(mdev, sq->rate_limit);
801 static int mlx5e_open_sq(struct mlx5e_channel *c,
803 struct mlx5e_sq_param *param,
808 err = mlx5e_create_sq(c, tc, param, sq);
812 err = mlx5e_enable_sq(sq, param);
816 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY,
822 set_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
823 netdev_tx_reset_queue(sq->txq);
824 netif_tx_start_queue(sq->txq);
830 mlx5e_disable_sq(sq);
832 mlx5e_destroy_sq(sq);
837 static inline void netif_tx_disable_queue(struct netdev_queue *txq)
839 __netif_tx_lock_bh(txq);
840 netif_tx_stop_queue(txq);
841 __netif_tx_unlock_bh(txq);
844 static void mlx5e_close_sq(struct mlx5e_sq *sq)
850 clear_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
851 /* prevent netif_tx_wake_queue */
852 napi_synchronize(&sq->channel->napi);
853 netif_tx_disable_queue(sq->txq);
855 /* ensure hw is notified of all pending wqes */
856 if (mlx5e_sq_has_room_for(sq, 1))
857 mlx5e_send_nop(sq, true);
859 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
860 MLX5_SQC_STATE_ERR, false, 0);
862 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
865 /* wait till sq is empty, unless a TX timeout occurred on this SQ */
866 while (sq->cc != sq->pc &&
867 !test_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state)) {
868 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
869 if (tout++ > MLX5_EN_QP_FLUSH_MAX_ITER)
870 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
873 /* avoid destroying sq before mlx5e_poll_tx_cq() is done with it */
874 napi_synchronize(&sq->channel->napi);
876 mlx5e_free_tx_descs(sq);
877 mlx5e_disable_sq(sq);
878 mlx5e_destroy_sq(sq);
881 static int mlx5e_create_cq(struct mlx5e_channel *c,
882 struct mlx5e_cq_param *param,
885 struct mlx5e_priv *priv = c->priv;
886 struct mlx5_core_dev *mdev = priv->mdev;
887 struct mlx5_core_cq *mcq = &cq->mcq;
893 param->wq.buf_numa_node = cpu_to_node(c->cpu);
894 param->wq.db_numa_node = cpu_to_node(c->cpu);
895 param->eq_ix = c->ix;
897 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
902 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
907 mcq->set_ci_db = cq->wq_ctrl.db.db;
908 mcq->arm_db = cq->wq_ctrl.db.db + 1;
911 mcq->vector = param->eq_ix;
912 mcq->comp = mlx5e_completion_event;
913 mcq->event = mlx5e_cq_error_event;
915 mcq->uar = &mdev->mlx5e_res.cq_uar;
917 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
918 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
929 static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
931 mlx5_wq_destroy(&cq->wq_ctrl);
934 static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
936 struct mlx5e_priv *priv = cq->priv;
937 struct mlx5_core_dev *mdev = priv->mdev;
938 struct mlx5_core_cq *mcq = &cq->mcq;
943 unsigned int irqn_not_used;
947 inlen = MLX5_ST_SZ_BYTES(create_cq_in) +
948 sizeof(u64) * cq->wq_ctrl.buf.npages;
949 in = mlx5_vzalloc(inlen);
953 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
955 memcpy(cqc, param->cqc, sizeof(param->cqc));
957 mlx5_fill_page_array(&cq->wq_ctrl.buf,
958 (__be64 *)MLX5_ADDR_OF(create_cq_in, in, pas));
960 mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
962 MLX5_SET(cqc, cqc, cq_period_mode, param->cq_period_mode);
963 MLX5_SET(cqc, cqc, c_eqn, eqn);
964 MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
965 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
966 MLX5_ADAPTER_PAGE_SHIFT);
967 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
969 err = mlx5_core_create_cq(mdev, mcq, in, inlen);
981 static void mlx5e_disable_cq(struct mlx5e_cq *cq)
983 struct mlx5e_priv *priv = cq->priv;
984 struct mlx5_core_dev *mdev = priv->mdev;
986 mlx5_core_destroy_cq(mdev, &cq->mcq);
989 static int mlx5e_open_cq(struct mlx5e_channel *c,
990 struct mlx5e_cq_param *param,
992 struct mlx5e_cq_moder moderation)
995 struct mlx5e_priv *priv = c->priv;
996 struct mlx5_core_dev *mdev = priv->mdev;
998 err = mlx5e_create_cq(c, param, cq);
1002 err = mlx5e_enable_cq(cq, param);
1004 goto err_destroy_cq;
1006 if (MLX5_CAP_GEN(mdev, cq_moderation))
1007 mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
1013 mlx5e_destroy_cq(cq);
1018 static void mlx5e_close_cq(struct mlx5e_cq *cq)
1020 mlx5e_disable_cq(cq);
1021 mlx5e_destroy_cq(cq);
1024 static int mlx5e_get_cpu(struct mlx5e_priv *priv, int ix)
1026 return cpumask_first(priv->mdev->priv.irq_info[ix].mask);
1029 static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
1030 struct mlx5e_channel_param *cparam)
1032 struct mlx5e_priv *priv = c->priv;
1036 for (tc = 0; tc < c->num_tc; tc++) {
1037 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
1038 priv->params.tx_cq_moderation);
1040 goto err_close_tx_cqs;
1046 for (tc--; tc >= 0; tc--)
1047 mlx5e_close_cq(&c->sq[tc].cq);
1052 static void mlx5e_close_tx_cqs(struct mlx5e_channel *c)
1056 for (tc = 0; tc < c->num_tc; tc++)
1057 mlx5e_close_cq(&c->sq[tc].cq);
1060 static int mlx5e_open_sqs(struct mlx5e_channel *c,
1061 struct mlx5e_channel_param *cparam)
1066 for (tc = 0; tc < c->num_tc; tc++) {
1067 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]);
1075 for (tc--; tc >= 0; tc--)
1076 mlx5e_close_sq(&c->sq[tc]);
1081 static void mlx5e_close_sqs(struct mlx5e_channel *c)
1085 for (tc = 0; tc < c->num_tc; tc++)
1086 mlx5e_close_sq(&c->sq[tc]);
1089 static void mlx5e_build_channeltc_to_txq_map(struct mlx5e_priv *priv, int ix)
1093 for (i = 0; i < priv->profile->max_tc; i++)
1094 priv->channeltc_to_txq_map[ix][i] =
1095 ix + i * priv->params.num_channels;
1098 static int mlx5e_set_sq_maxrate(struct net_device *dev,
1099 struct mlx5e_sq *sq, u32 rate)
1101 struct mlx5e_priv *priv = netdev_priv(dev);
1102 struct mlx5_core_dev *mdev = priv->mdev;
1106 if (rate == sq->rate_limit)
1111 /* remove current rl index to free space to next ones */
1112 mlx5_rl_remove_rate(mdev, sq->rate_limit);
1117 err = mlx5_rl_add_rate(mdev, rate, &rl_index);
1119 netdev_err(dev, "Failed configuring rate %u: %d\n",
1125 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
1126 MLX5_SQC_STATE_RDY, true, rl_index);
1128 netdev_err(dev, "Failed configuring rate %u: %d\n",
1130 /* remove the rate from the table */
1132 mlx5_rl_remove_rate(mdev, rate);
1136 sq->rate_limit = rate;
1140 static int mlx5e_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
1142 struct mlx5e_priv *priv = netdev_priv(dev);
1143 struct mlx5_core_dev *mdev = priv->mdev;
1144 struct mlx5e_sq *sq = priv->txq_to_sq_map[index];
1147 if (!mlx5_rl_is_supported(mdev)) {
1148 netdev_err(dev, "Rate limiting is not supported on this device\n");
1152 /* rate is given in Mb/sec, HW config is in Kb/sec */
1155 /* Check whether rate in valid range, 0 is always valid */
1156 if (rate && !mlx5_rl_is_in_range(mdev, rate)) {
1157 netdev_err(dev, "TX rate %u, is not in range\n", rate);
1161 mutex_lock(&priv->state_lock);
1162 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
1163 err = mlx5e_set_sq_maxrate(dev, sq, rate);
1165 priv->tx_rates[index] = rate;
1166 mutex_unlock(&priv->state_lock);
1171 static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1172 struct mlx5e_channel_param *cparam,
1173 struct mlx5e_channel **cp)
1175 struct mlx5e_cq_moder icosq_cq_moder = {0, 0};
1176 struct net_device *netdev = priv->netdev;
1177 struct mlx5e_cq_moder rx_cq_profile;
1178 int cpu = mlx5e_get_cpu(priv, ix);
1179 struct mlx5e_channel *c;
1180 struct mlx5e_sq *sq;
1184 c = kzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1191 c->pdev = &priv->mdev->pdev->dev;
1192 c->netdev = priv->netdev;
1193 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1194 c->num_tc = priv->params.num_tc;
1196 if (priv->params.rx_am_enabled)
1197 rx_cq_profile = mlx5e_am_get_def_profile(priv->params.rx_cq_period_mode);
1199 rx_cq_profile = priv->params.rx_cq_moderation;
1201 mlx5e_build_channeltc_to_txq_map(priv, ix);
1203 netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1205 err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, icosq_cq_moder);
1209 err = mlx5e_open_tx_cqs(c, cparam);
1211 goto err_close_icosq_cq;
1213 err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1216 goto err_close_tx_cqs;
1218 napi_enable(&c->napi);
1220 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
1222 goto err_disable_napi;
1224 err = mlx5e_open_sqs(c, cparam);
1226 goto err_close_icosq;
1228 for (i = 0; i < priv->params.num_tc; i++) {
1229 u32 txq_ix = priv->channeltc_to_txq_map[ix][i];
1231 if (priv->tx_rates[txq_ix]) {
1232 sq = priv->txq_to_sq_map[txq_ix];
1233 mlx5e_set_sq_maxrate(priv->netdev, sq,
1234 priv->tx_rates[txq_ix]);
1238 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1242 netif_set_xps_queue(netdev, get_cpu_mask(c->cpu), ix);
1251 mlx5e_close_sq(&c->icosq);
1254 napi_disable(&c->napi);
1255 mlx5e_close_cq(&c->rq.cq);
1258 mlx5e_close_tx_cqs(c);
1261 mlx5e_close_cq(&c->icosq.cq);
1264 netif_napi_del(&c->napi);
1265 napi_hash_del(&c->napi);
1271 static void mlx5e_close_channel(struct mlx5e_channel *c)
1273 mlx5e_close_rq(&c->rq);
1275 mlx5e_close_sq(&c->icosq);
1276 napi_disable(&c->napi);
1277 mlx5e_close_cq(&c->rq.cq);
1278 mlx5e_close_tx_cqs(c);
1279 mlx5e_close_cq(&c->icosq.cq);
1280 netif_napi_del(&c->napi);
1282 napi_hash_del(&c->napi);
1288 static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1289 struct mlx5e_rq_param *param)
1291 void *rqc = param->rqc;
1292 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1294 switch (priv->params.rq_wq_type) {
1295 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1296 MLX5_SET(wq, wq, log_wqe_num_of_strides,
1297 priv->params.mpwqe_log_num_strides - 9);
1298 MLX5_SET(wq, wq, log_wqe_stride_size,
1299 priv->params.mpwqe_log_stride_sz - 6);
1300 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
1302 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1303 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1306 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
1307 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1308 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1309 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1310 MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
1312 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1313 param->wq.linear = 1;
1315 param->am_enabled = priv->params.rx_am_enabled;
1318 static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param)
1320 void *rqc = param->rqc;
1321 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1323 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1324 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1327 static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
1328 struct mlx5e_sq_param *param)
1330 void *sqc = param->sqc;
1331 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1333 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1334 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1336 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1339 static void mlx5e_build_sq_param(struct mlx5e_priv *priv,
1340 struct mlx5e_sq_param *param)
1342 void *sqc = param->sqc;
1343 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1345 mlx5e_build_sq_param_common(priv, param);
1346 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size);
1348 param->max_inline = priv->params.tx_max_inline;
1349 param->min_inline_mode = priv->params.tx_min_inline_mode;
1352 static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
1353 struct mlx5e_cq_param *param)
1355 void *cqc = param->cqc;
1357 MLX5_SET(cqc, cqc, uar_page, priv->mdev->mlx5e_res.cq_uar.index);
1360 static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
1361 struct mlx5e_cq_param *param)
1363 void *cqc = param->cqc;
1366 switch (priv->params.rq_wq_type) {
1367 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1368 log_cq_size = priv->params.log_rq_size +
1369 priv->params.mpwqe_log_num_strides;
1371 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1372 log_cq_size = priv->params.log_rq_size;
1375 MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
1376 if (priv->params.rx_cqe_compress) {
1377 MLX5_SET(cqc, cqc, mini_cqe_res_format, MLX5_CQE_FORMAT_CSUM);
1378 MLX5_SET(cqc, cqc, cqe_comp_en, 1);
1381 mlx5e_build_common_cq_param(priv, param);
1383 param->cq_period_mode = priv->params.rx_cq_period_mode;
1386 static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
1387 struct mlx5e_cq_param *param)
1389 void *cqc = param->cqc;
1391 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
1393 mlx5e_build_common_cq_param(priv, param);
1395 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1398 static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
1399 struct mlx5e_cq_param *param,
1402 void *cqc = param->cqc;
1404 MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1406 mlx5e_build_common_cq_param(priv, param);
1408 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1411 static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
1412 struct mlx5e_sq_param *param,
1415 void *sqc = param->sqc;
1416 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1418 mlx5e_build_sq_param_common(priv, param);
1420 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1421 MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(priv->mdev, reg_umr_sq));
1423 param->icosq = true;
1426 static void mlx5e_build_channel_param(struct mlx5e_priv *priv, struct mlx5e_channel_param *cparam)
1428 u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1430 mlx5e_build_rq_param(priv, &cparam->rq);
1431 mlx5e_build_sq_param(priv, &cparam->sq);
1432 mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz);
1433 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq);
1434 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq);
1435 mlx5e_build_ico_cq_param(priv, &cparam->icosq_cq, icosq_log_wq_sz);
1438 static int mlx5e_open_channels(struct mlx5e_priv *priv)
1440 struct mlx5e_channel_param *cparam;
1441 int nch = priv->params.num_channels;
1446 priv->channel = kcalloc(nch, sizeof(struct mlx5e_channel *),
1449 priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc,
1450 sizeof(struct mlx5e_sq *), GFP_KERNEL);
1452 cparam = kzalloc(sizeof(struct mlx5e_channel_param), GFP_KERNEL);
1454 if (!priv->channel || !priv->txq_to_sq_map || !cparam)
1455 goto err_free_txq_to_sq_map;
1457 mlx5e_build_channel_param(priv, cparam);
1459 for (i = 0; i < nch; i++) {
1460 err = mlx5e_open_channel(priv, i, cparam, &priv->channel[i]);
1462 goto err_close_channels;
1465 for (j = 0; j < nch; j++) {
1466 err = mlx5e_wait_for_min_rx_wqes(&priv->channel[j]->rq);
1468 goto err_close_channels;
1471 /* FIXME: This is a W/A for tx timeout watch dog false alarm when
1472 * polling for inactive tx queues.
1474 netif_tx_start_all_queues(priv->netdev);
1480 for (i--; i >= 0; i--)
1481 mlx5e_close_channel(priv->channel[i]);
1483 err_free_txq_to_sq_map:
1484 kfree(priv->txq_to_sq_map);
1485 kfree(priv->channel);
1491 static void mlx5e_close_channels(struct mlx5e_priv *priv)
1495 /* FIXME: This is a W/A only for tx timeout watch dog false alarm when
1496 * polling for inactive tx queues.
1498 netif_tx_stop_all_queues(priv->netdev);
1499 netif_tx_disable(priv->netdev);
1501 for (i = 0; i < priv->params.num_channels; i++)
1502 mlx5e_close_channel(priv->channel[i]);
1504 kfree(priv->txq_to_sq_map);
1505 kfree(priv->channel);
1508 static int mlx5e_rx_hash_fn(int hfunc)
1510 return (hfunc == ETH_RSS_HASH_TOP) ?
1511 MLX5_RX_HASH_FN_TOEPLITZ :
1512 MLX5_RX_HASH_FN_INVERTED_XOR8;
1515 static int mlx5e_bits_invert(unsigned long a, int size)
1520 for (i = 0; i < size; i++)
1521 inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1526 static void mlx5e_fill_indir_rqt_rqns(struct mlx5e_priv *priv, void *rqtc)
1530 for (i = 0; i < MLX5E_INDIR_RQT_SIZE; i++) {
1534 if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1535 ix = mlx5e_bits_invert(i, MLX5E_LOG_INDIR_RQT_SIZE);
1537 ix = priv->params.indirection_rqt[ix];
1538 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1539 priv->channel[ix]->rq.rqn :
1541 MLX5_SET(rqtc, rqtc, rq_num[i], rqn);
1545 static void mlx5e_fill_direct_rqt_rqn(struct mlx5e_priv *priv, void *rqtc,
1548 u32 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1549 priv->channel[ix]->rq.rqn :
1552 MLX5_SET(rqtc, rqtc, rq_num[0], rqn);
1555 static int mlx5e_create_rqt(struct mlx5e_priv *priv, int sz,
1556 int ix, struct mlx5e_rqt *rqt)
1558 struct mlx5_core_dev *mdev = priv->mdev;
1564 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
1565 in = mlx5_vzalloc(inlen);
1569 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1571 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1572 MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
1574 if (sz > 1) /* RSS */
1575 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1577 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1579 err = mlx5_core_create_rqt(mdev, in, inlen, &rqt->rqtn);
1581 rqt->enabled = true;
1587 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt)
1589 rqt->enabled = false;
1590 mlx5_core_destroy_rqt(priv->mdev, rqt->rqtn);
1593 static int mlx5e_create_indirect_rqts(struct mlx5e_priv *priv)
1595 struct mlx5e_rqt *rqt = &priv->indir_rqt;
1597 return mlx5e_create_rqt(priv, MLX5E_INDIR_RQT_SIZE, 0, rqt);
1600 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv)
1602 struct mlx5e_rqt *rqt;
1606 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1607 rqt = &priv->direct_tir[ix].rqt;
1608 err = mlx5e_create_rqt(priv, 1 /*size */, ix, rqt);
1610 goto err_destroy_rqts;
1616 for (ix--; ix >= 0; ix--)
1617 mlx5e_destroy_rqt(priv, &priv->direct_tir[ix].rqt);
1622 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix)
1624 struct mlx5_core_dev *mdev = priv->mdev;
1630 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz;
1631 in = mlx5_vzalloc(inlen);
1635 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx);
1637 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1638 if (sz > 1) /* RSS */
1639 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1641 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1643 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1);
1645 err = mlx5_core_modify_rqt(mdev, rqtn, in, inlen);
1652 static void mlx5e_redirect_rqts(struct mlx5e_priv *priv)
1657 if (priv->indir_rqt.enabled) {
1658 rqtn = priv->indir_rqt.rqtn;
1659 mlx5e_redirect_rqt(priv, rqtn, MLX5E_INDIR_RQT_SIZE, 0);
1662 for (ix = 0; ix < priv->params.num_channels; ix++) {
1663 if (!priv->direct_tir[ix].rqt.enabled)
1665 rqtn = priv->direct_tir[ix].rqt.rqtn;
1666 mlx5e_redirect_rqt(priv, rqtn, 1, ix);
1670 static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1672 if (!priv->params.lro_en)
1675 #define ROUGH_MAX_L2_L3_HDR_SZ 256
1677 MLX5_SET(tirc, tirc, lro_enable_mask,
1678 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
1679 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO);
1680 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1681 (priv->params.lro_wqe_sz -
1682 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1683 MLX5_SET(tirc, tirc, lro_timeout_period_usecs,
1684 MLX5_CAP_ETH(priv->mdev,
1685 lro_timer_supported_periods[2]));
1688 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
1690 MLX5_SET(tirc, tirc, rx_hash_fn,
1691 mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1692 if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1693 void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1694 rx_hash_toeplitz_key);
1695 size_t len = MLX5_FLD_SZ_BYTES(tirc,
1696 rx_hash_toeplitz_key);
1698 MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1699 memcpy(rss_key, priv->params.toeplitz_hash_key, len);
1703 static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
1705 struct mlx5_core_dev *mdev = priv->mdev;
1714 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1715 in = mlx5_vzalloc(inlen);
1719 MLX5_SET(modify_tir_in, in, bitmask.lro, 1);
1720 tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
1722 mlx5e_build_tir_ctx_lro(tirc, priv);
1724 for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) {
1725 err = mlx5_core_modify_tir(mdev, priv->indir_tir[tt].tirn, in,
1731 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1732 err = mlx5_core_modify_tir(mdev, priv->direct_tir[ix].tirn,
1744 static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
1746 struct mlx5_core_dev *mdev = priv->mdev;
1747 u16 hw_mtu = MLX5E_SW2HW_MTU(mtu);
1750 err = mlx5_set_port_mtu(mdev, hw_mtu, 1);
1754 /* Update vport context MTU */
1755 mlx5_modify_nic_vport_mtu(mdev, hw_mtu);
1759 static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
1761 struct mlx5_core_dev *mdev = priv->mdev;
1765 err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
1766 if (err || !hw_mtu) /* fallback to port oper mtu */
1767 mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
1769 *mtu = MLX5E_HW2SW_MTU(hw_mtu);
1772 static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
1774 struct mlx5e_priv *priv = netdev_priv(netdev);
1778 err = mlx5e_set_mtu(priv, netdev->mtu);
1782 mlx5e_query_mtu(priv, &mtu);
1783 if (mtu != netdev->mtu)
1784 netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
1785 __func__, mtu, netdev->mtu);
1791 static void mlx5e_netdev_set_tcs(struct net_device *netdev)
1793 struct mlx5e_priv *priv = netdev_priv(netdev);
1794 int nch = priv->params.num_channels;
1795 int ntc = priv->params.num_tc;
1798 netdev_reset_tc(netdev);
1803 netdev_set_num_tc(netdev, ntc);
1805 /* Map netdev TCs to offset 0
1806 * We have our own UP to TXQ mapping for QoS
1808 for (tc = 0; tc < ntc; tc++)
1809 netdev_set_tc_queue(netdev, tc, nch, 0);
1812 int mlx5e_open_locked(struct net_device *netdev)
1814 struct mlx5e_priv *priv = netdev_priv(netdev);
1815 struct mlx5_core_dev *mdev = priv->mdev;
1819 set_bit(MLX5E_STATE_OPENED, &priv->state);
1821 mlx5e_netdev_set_tcs(netdev);
1823 num_txqs = priv->params.num_channels * priv->params.num_tc;
1824 netif_set_real_num_tx_queues(netdev, num_txqs);
1825 netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
1827 err = mlx5e_set_dev_port_mtu(netdev);
1829 goto err_clear_state_opened_flag;
1831 err = mlx5e_open_channels(priv);
1833 netdev_err(netdev, "%s: mlx5e_open_channels failed, %d\n",
1835 goto err_clear_state_opened_flag;
1838 err = mlx5e_refresh_tirs_self_loopback_enable(priv->mdev);
1840 netdev_err(netdev, "%s: mlx5e_refresh_tirs_self_loopback_enable failed, %d\n",
1842 goto err_close_channels;
1845 mlx5e_redirect_rqts(priv);
1846 mlx5e_update_carrier(priv);
1847 mlx5e_timestamp_init(priv);
1848 #ifdef CONFIG_RFS_ACCEL
1849 priv->netdev->rx_cpu_rmap = priv->mdev->rmap;
1851 if (priv->profile->update_stats)
1852 queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
1854 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
1855 err = mlx5e_add_sqs_fwd_rules(priv);
1857 goto err_close_channels;
1862 mlx5e_close_channels(priv);
1863 err_clear_state_opened_flag:
1864 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1868 int mlx5e_open(struct net_device *netdev)
1870 struct mlx5e_priv *priv = netdev_priv(netdev);
1873 mutex_lock(&priv->state_lock);
1874 err = mlx5e_open_locked(netdev);
1875 mutex_unlock(&priv->state_lock);
1880 int mlx5e_close_locked(struct net_device *netdev)
1882 struct mlx5e_priv *priv = netdev_priv(netdev);
1883 struct mlx5_core_dev *mdev = priv->mdev;
1885 /* May already be CLOSED in case a previous configuration operation
1886 * (e.g RX/TX queue size change) that involves close&open failed.
1888 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
1891 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1893 if (MLX5_CAP_GEN(mdev, vport_group_manager))
1894 mlx5e_remove_sqs_fwd_rules(priv);
1896 mlx5e_timestamp_cleanup(priv);
1897 netif_carrier_off(priv->netdev);
1898 mlx5e_redirect_rqts(priv);
1899 mlx5e_close_channels(priv);
1904 int mlx5e_close(struct net_device *netdev)
1906 struct mlx5e_priv *priv = netdev_priv(netdev);
1909 mutex_lock(&priv->state_lock);
1910 err = mlx5e_close_locked(netdev);
1911 mutex_unlock(&priv->state_lock);
1916 static int mlx5e_create_drop_rq(struct mlx5e_priv *priv,
1917 struct mlx5e_rq *rq,
1918 struct mlx5e_rq_param *param)
1920 struct mlx5_core_dev *mdev = priv->mdev;
1921 void *rqc = param->rqc;
1922 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
1925 param->wq.db_numa_node = param->wq.buf_numa_node;
1927 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
1937 static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
1938 struct mlx5e_cq *cq,
1939 struct mlx5e_cq_param *param)
1941 struct mlx5_core_dev *mdev = priv->mdev;
1942 struct mlx5_core_cq *mcq = &cq->mcq;
1947 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
1952 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
1955 mcq->set_ci_db = cq->wq_ctrl.db.db;
1956 mcq->arm_db = cq->wq_ctrl.db.db + 1;
1957 *mcq->set_ci_db = 0;
1959 mcq->vector = param->eq_ix;
1960 mcq->comp = mlx5e_completion_event;
1961 mcq->event = mlx5e_cq_error_event;
1963 mcq->uar = &mdev->mlx5e_res.cq_uar;
1970 static int mlx5e_open_drop_rq(struct mlx5e_priv *priv)
1972 struct mlx5e_cq_param cq_param;
1973 struct mlx5e_rq_param rq_param;
1974 struct mlx5e_rq *rq = &priv->drop_rq;
1975 struct mlx5e_cq *cq = &priv->drop_rq.cq;
1978 memset(&cq_param, 0, sizeof(cq_param));
1979 memset(&rq_param, 0, sizeof(rq_param));
1980 mlx5e_build_drop_rq_param(&rq_param);
1982 err = mlx5e_create_drop_cq(priv, cq, &cq_param);
1986 err = mlx5e_enable_cq(cq, &cq_param);
1988 goto err_destroy_cq;
1990 err = mlx5e_create_drop_rq(priv, rq, &rq_param);
1992 goto err_disable_cq;
1994 err = mlx5e_enable_rq(rq, &rq_param);
1996 goto err_destroy_rq;
2001 mlx5e_destroy_rq(&priv->drop_rq);
2004 mlx5e_disable_cq(&priv->drop_rq.cq);
2007 mlx5e_destroy_cq(&priv->drop_rq.cq);
2012 static void mlx5e_close_drop_rq(struct mlx5e_priv *priv)
2014 mlx5e_disable_rq(&priv->drop_rq);
2015 mlx5e_destroy_rq(&priv->drop_rq);
2016 mlx5e_disable_cq(&priv->drop_rq.cq);
2017 mlx5e_destroy_cq(&priv->drop_rq.cq);
2020 static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
2022 struct mlx5_core_dev *mdev = priv->mdev;
2023 u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {0};
2024 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
2026 MLX5_SET(tisc, tisc, prio, tc << 1);
2027 MLX5_SET(tisc, tisc, transport_domain, mdev->mlx5e_res.td.tdn);
2029 if (mlx5_lag_is_lacp_owner(mdev))
2030 MLX5_SET(tisc, tisc, strict_lag_tx_port_affinity, 1);
2032 return mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc]);
2035 static void mlx5e_destroy_tis(struct mlx5e_priv *priv, int tc)
2037 mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc]);
2040 int mlx5e_create_tises(struct mlx5e_priv *priv)
2045 for (tc = 0; tc < priv->profile->max_tc; tc++) {
2046 err = mlx5e_create_tis(priv, tc);
2048 goto err_close_tises;
2054 for (tc--; tc >= 0; tc--)
2055 mlx5e_destroy_tis(priv, tc);
2060 void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv)
2064 for (tc = 0; tc < priv->profile->max_tc; tc++)
2065 mlx5e_destroy_tis(priv, tc);
2068 static void mlx5e_build_indir_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
2069 enum mlx5e_traffic_types tt)
2071 void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer);
2073 MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
2075 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
2076 MLX5_HASH_FIELD_SEL_DST_IP)
2078 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
2079 MLX5_HASH_FIELD_SEL_DST_IP |\
2080 MLX5_HASH_FIELD_SEL_L4_SPORT |\
2081 MLX5_HASH_FIELD_SEL_L4_DPORT)
2083 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
2084 MLX5_HASH_FIELD_SEL_DST_IP |\
2085 MLX5_HASH_FIELD_SEL_IPSEC_SPI)
2087 mlx5e_build_tir_ctx_lro(tirc, priv);
2089 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
2090 MLX5_SET(tirc, tirc, indirect_table, priv->indir_rqt.rqtn);
2091 mlx5e_build_tir_ctx_hash(tirc, priv);
2094 case MLX5E_TT_IPV4_TCP:
2095 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2096 MLX5_L3_PROT_TYPE_IPV4);
2097 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2098 MLX5_L4_PROT_TYPE_TCP);
2099 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2100 MLX5_HASH_IP_L4PORTS);
2103 case MLX5E_TT_IPV6_TCP:
2104 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2105 MLX5_L3_PROT_TYPE_IPV6);
2106 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2107 MLX5_L4_PROT_TYPE_TCP);
2108 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2109 MLX5_HASH_IP_L4PORTS);
2112 case MLX5E_TT_IPV4_UDP:
2113 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2114 MLX5_L3_PROT_TYPE_IPV4);
2115 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2116 MLX5_L4_PROT_TYPE_UDP);
2117 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2118 MLX5_HASH_IP_L4PORTS);
2121 case MLX5E_TT_IPV6_UDP:
2122 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2123 MLX5_L3_PROT_TYPE_IPV6);
2124 MLX5_SET(rx_hash_field_select, hfso, l4_prot_type,
2125 MLX5_L4_PROT_TYPE_UDP);
2126 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2127 MLX5_HASH_IP_L4PORTS);
2130 case MLX5E_TT_IPV4_IPSEC_AH:
2131 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2132 MLX5_L3_PROT_TYPE_IPV4);
2133 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2134 MLX5_HASH_IP_IPSEC_SPI);
2137 case MLX5E_TT_IPV6_IPSEC_AH:
2138 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2139 MLX5_L3_PROT_TYPE_IPV6);
2140 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2141 MLX5_HASH_IP_IPSEC_SPI);
2144 case MLX5E_TT_IPV4_IPSEC_ESP:
2145 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2146 MLX5_L3_PROT_TYPE_IPV4);
2147 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2148 MLX5_HASH_IP_IPSEC_SPI);
2151 case MLX5E_TT_IPV6_IPSEC_ESP:
2152 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2153 MLX5_L3_PROT_TYPE_IPV6);
2154 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2155 MLX5_HASH_IP_IPSEC_SPI);
2159 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2160 MLX5_L3_PROT_TYPE_IPV4);
2161 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2166 MLX5_SET(rx_hash_field_select, hfso, l3_prot_type,
2167 MLX5_L3_PROT_TYPE_IPV6);
2168 MLX5_SET(rx_hash_field_select, hfso, selected_fields,
2173 "mlx5e_build_indir_tir_ctx: bad traffic type!\n");
2177 static void mlx5e_build_direct_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
2180 MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
2182 mlx5e_build_tir_ctx_lro(tirc, priv);
2184 MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_INDIRECT);
2185 MLX5_SET(tirc, tirc, indirect_table, rqtn);
2186 MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_INVERTED_XOR8);
2189 static int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv)
2191 struct mlx5e_tir *tir;
2198 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
2199 in = mlx5_vzalloc(inlen);
2203 for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) {
2204 memset(in, 0, inlen);
2205 tir = &priv->indir_tir[tt];
2206 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
2207 mlx5e_build_indir_tir_ctx(priv, tirc, tt);
2208 err = mlx5e_create_tir(priv->mdev, tir, in, inlen);
2210 goto err_destroy_tirs;
2218 for (tt--; tt >= 0; tt--)
2219 mlx5e_destroy_tir(priv->mdev, &priv->indir_tir[tt]);
2226 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv)
2228 int nch = priv->profile->max_nch(priv->mdev);
2229 struct mlx5e_tir *tir;
2236 inlen = MLX5_ST_SZ_BYTES(create_tir_in);
2237 in = mlx5_vzalloc(inlen);
2241 for (ix = 0; ix < nch; ix++) {
2242 memset(in, 0, inlen);
2243 tir = &priv->direct_tir[ix];
2244 tirc = MLX5_ADDR_OF(create_tir_in, in, ctx);
2245 mlx5e_build_direct_tir_ctx(priv, tirc,
2246 priv->direct_tir[ix].rqt.rqtn);
2247 err = mlx5e_create_tir(priv->mdev, tir, in, inlen);
2249 goto err_destroy_ch_tirs;
2256 err_destroy_ch_tirs:
2257 for (ix--; ix >= 0; ix--)
2258 mlx5e_destroy_tir(priv->mdev, &priv->direct_tir[ix]);
2265 static void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv)
2269 for (i = 0; i < MLX5E_NUM_INDIR_TIRS; i++)
2270 mlx5e_destroy_tir(priv->mdev, &priv->indir_tir[i]);
2273 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv)
2275 int nch = priv->profile->max_nch(priv->mdev);
2278 for (i = 0; i < nch; i++)
2279 mlx5e_destroy_tir(priv->mdev, &priv->direct_tir[i]);
2282 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd)
2287 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
2290 for (i = 0; i < priv->params.num_channels; i++) {
2291 err = mlx5e_modify_rq_vsd(&priv->channel[i]->rq, vsd);
2299 static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
2301 struct mlx5e_priv *priv = netdev_priv(netdev);
2305 if (tc && tc != MLX5E_MAX_NUM_TC)
2308 mutex_lock(&priv->state_lock);
2310 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2312 mlx5e_close_locked(priv->netdev);
2314 priv->params.num_tc = tc ? tc : 1;
2317 err = mlx5e_open_locked(priv->netdev);
2319 mutex_unlock(&priv->state_lock);
2324 static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
2325 __be16 proto, struct tc_to_netdev *tc)
2327 struct mlx5e_priv *priv = netdev_priv(dev);
2329 if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
2333 case TC_SETUP_CLSFLOWER:
2334 switch (tc->cls_flower->command) {
2335 case TC_CLSFLOWER_REPLACE:
2336 return mlx5e_configure_flower(priv, proto, tc->cls_flower);
2337 case TC_CLSFLOWER_DESTROY:
2338 return mlx5e_delete_flower(priv, tc->cls_flower);
2339 case TC_CLSFLOWER_STATS:
2340 return mlx5e_stats_flower(priv, tc->cls_flower);
2347 if (tc->type != TC_SETUP_MQPRIO)
2350 return mlx5e_setup_tc(dev, tc->tc);
2353 struct rtnl_link_stats64 *
2354 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
2356 struct mlx5e_priv *priv = netdev_priv(dev);
2357 struct mlx5e_sw_stats *sstats = &priv->stats.sw;
2358 struct mlx5e_vport_stats *vstats = &priv->stats.vport;
2359 struct mlx5e_pport_stats *pstats = &priv->stats.pport;
2361 stats->rx_packets = sstats->rx_packets;
2362 stats->rx_bytes = sstats->rx_bytes;
2363 stats->tx_packets = sstats->tx_packets;
2364 stats->tx_bytes = sstats->tx_bytes;
2366 stats->rx_dropped = priv->stats.qcnt.rx_out_of_buffer;
2367 stats->tx_dropped = sstats->tx_queue_dropped;
2369 stats->rx_length_errors =
2370 PPORT_802_3_GET(pstats, a_in_range_length_errors) +
2371 PPORT_802_3_GET(pstats, a_out_of_range_length_field) +
2372 PPORT_802_3_GET(pstats, a_frame_too_long_errors);
2373 stats->rx_crc_errors =
2374 PPORT_802_3_GET(pstats, a_frame_check_sequence_errors);
2375 stats->rx_frame_errors = PPORT_802_3_GET(pstats, a_alignment_errors);
2376 stats->tx_aborted_errors = PPORT_2863_GET(pstats, if_out_discards);
2377 stats->tx_carrier_errors =
2378 PPORT_802_3_GET(pstats, a_symbol_error_during_carrier);
2379 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
2380 stats->rx_frame_errors;
2381 stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors;
2383 /* vport multicast also counts packets that are dropped due to steering
2384 * or rx out of buffer
2387 VPORT_COUNTER_GET(vstats, received_eth_multicast.packets);
2392 static void mlx5e_set_rx_mode(struct net_device *dev)
2394 struct mlx5e_priv *priv = netdev_priv(dev);
2396 queue_work(priv->wq, &priv->set_rx_mode_work);
2399 static int mlx5e_set_mac(struct net_device *netdev, void *addr)
2401 struct mlx5e_priv *priv = netdev_priv(netdev);
2402 struct sockaddr *saddr = addr;
2404 if (!is_valid_ether_addr(saddr->sa_data))
2405 return -EADDRNOTAVAIL;
2407 netif_addr_lock_bh(netdev);
2408 ether_addr_copy(netdev->dev_addr, saddr->sa_data);
2409 netif_addr_unlock_bh(netdev);
2411 queue_work(priv->wq, &priv->set_rx_mode_work);
2416 #define MLX5E_SET_FEATURE(netdev, feature, enable) \
2419 netdev->features |= feature; \
2421 netdev->features &= ~feature; \
2424 typedef int (*mlx5e_feature_handler)(struct net_device *netdev, bool enable);
2426 static int set_feature_lro(struct net_device *netdev, bool enable)
2428 struct mlx5e_priv *priv = netdev_priv(netdev);
2429 bool was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2432 mutex_lock(&priv->state_lock);
2434 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2435 mlx5e_close_locked(priv->netdev);
2437 priv->params.lro_en = enable;
2438 err = mlx5e_modify_tirs_lro(priv);
2440 netdev_err(netdev, "lro modify failed, %d\n", err);
2441 priv->params.lro_en = !enable;
2444 if (was_opened && (priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
2445 mlx5e_open_locked(priv->netdev);
2447 mutex_unlock(&priv->state_lock);
2452 static int set_feature_vlan_filter(struct net_device *netdev, bool enable)
2454 struct mlx5e_priv *priv = netdev_priv(netdev);
2457 mlx5e_enable_vlan_filter(priv);
2459 mlx5e_disable_vlan_filter(priv);
2464 static int set_feature_tc_num_filters(struct net_device *netdev, bool enable)
2466 struct mlx5e_priv *priv = netdev_priv(netdev);
2468 if (!enable && mlx5e_tc_num_filters(priv)) {
2470 "Active offloaded tc filters, can't turn hw_tc_offload off\n");
2477 static int set_feature_rx_all(struct net_device *netdev, bool enable)
2479 struct mlx5e_priv *priv = netdev_priv(netdev);
2480 struct mlx5_core_dev *mdev = priv->mdev;
2482 return mlx5_set_port_fcs(mdev, !enable);
2485 static int set_feature_rx_vlan(struct net_device *netdev, bool enable)
2487 struct mlx5e_priv *priv = netdev_priv(netdev);
2490 mutex_lock(&priv->state_lock);
2492 priv->params.vlan_strip_disable = !enable;
2493 err = mlx5e_modify_rqs_vsd(priv, !enable);
2495 priv->params.vlan_strip_disable = enable;
2497 mutex_unlock(&priv->state_lock);
2502 #ifdef CONFIG_RFS_ACCEL
2503 static int set_feature_arfs(struct net_device *netdev, bool enable)
2505 struct mlx5e_priv *priv = netdev_priv(netdev);
2509 err = mlx5e_arfs_enable(priv);
2511 err = mlx5e_arfs_disable(priv);
2517 static int mlx5e_handle_feature(struct net_device *netdev,
2518 netdev_features_t wanted_features,
2519 netdev_features_t feature,
2520 mlx5e_feature_handler feature_handler)
2522 netdev_features_t changes = wanted_features ^ netdev->features;
2523 bool enable = !!(wanted_features & feature);
2526 if (!(changes & feature))
2529 err = feature_handler(netdev, enable);
2531 netdev_err(netdev, "%s feature 0x%llx failed err %d\n",
2532 enable ? "Enable" : "Disable", feature, err);
2536 MLX5E_SET_FEATURE(netdev, feature, enable);
2540 static int mlx5e_set_features(struct net_device *netdev,
2541 netdev_features_t features)
2545 err = mlx5e_handle_feature(netdev, features, NETIF_F_LRO,
2547 err |= mlx5e_handle_feature(netdev, features,
2548 NETIF_F_HW_VLAN_CTAG_FILTER,
2549 set_feature_vlan_filter);
2550 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_TC,
2551 set_feature_tc_num_filters);
2552 err |= mlx5e_handle_feature(netdev, features, NETIF_F_RXALL,
2553 set_feature_rx_all);
2554 err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_VLAN_CTAG_RX,
2555 set_feature_rx_vlan);
2556 #ifdef CONFIG_RFS_ACCEL
2557 err |= mlx5e_handle_feature(netdev, features, NETIF_F_NTUPLE,
2561 return err ? -EINVAL : 0;
2564 #define MXL5_HW_MIN_MTU 64
2565 #define MXL5E_MIN_MTU (MXL5_HW_MIN_MTU + ETH_FCS_LEN)
2567 static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
2569 struct mlx5e_priv *priv = netdev_priv(netdev);
2570 struct mlx5_core_dev *mdev = priv->mdev;
2576 mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
2578 max_mtu = MLX5E_HW2SW_MTU(max_mtu);
2579 min_mtu = MLX5E_HW2SW_MTU(MXL5E_MIN_MTU);
2581 if (new_mtu > max_mtu || new_mtu < min_mtu) {
2583 "%s: Bad MTU (%d), valid range is: [%d..%d]\n",
2584 __func__, new_mtu, min_mtu, max_mtu);
2588 mutex_lock(&priv->state_lock);
2590 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2592 mlx5e_close_locked(netdev);
2594 netdev->mtu = new_mtu;
2597 err = mlx5e_open_locked(netdev);
2599 mutex_unlock(&priv->state_lock);
2604 static int mlx5e_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2608 return mlx5e_hwstamp_set(dev, ifr);
2610 return mlx5e_hwstamp_get(dev, ifr);
2616 static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2618 struct mlx5e_priv *priv = netdev_priv(dev);
2619 struct mlx5_core_dev *mdev = priv->mdev;
2621 return mlx5_eswitch_set_vport_mac(mdev->priv.eswitch, vf + 1, mac);
2624 static int mlx5e_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2626 struct mlx5e_priv *priv = netdev_priv(dev);
2627 struct mlx5_core_dev *mdev = priv->mdev;
2629 return mlx5_eswitch_set_vport_vlan(mdev->priv.eswitch, vf + 1,
2633 static int mlx5e_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2635 struct mlx5e_priv *priv = netdev_priv(dev);
2636 struct mlx5_core_dev *mdev = priv->mdev;
2638 return mlx5_eswitch_set_vport_spoofchk(mdev->priv.eswitch, vf + 1, setting);
2641 static int mlx5e_set_vf_trust(struct net_device *dev, int vf, bool setting)
2643 struct mlx5e_priv *priv = netdev_priv(dev);
2644 struct mlx5_core_dev *mdev = priv->mdev;
2646 return mlx5_eswitch_set_vport_trust(mdev->priv.eswitch, vf + 1, setting);
2648 static int mlx5_vport_link2ifla(u8 esw_link)
2651 case MLX5_ESW_VPORT_ADMIN_STATE_DOWN:
2652 return IFLA_VF_LINK_STATE_DISABLE;
2653 case MLX5_ESW_VPORT_ADMIN_STATE_UP:
2654 return IFLA_VF_LINK_STATE_ENABLE;
2656 return IFLA_VF_LINK_STATE_AUTO;
2659 static int mlx5_ifla_link2vport(u8 ifla_link)
2661 switch (ifla_link) {
2662 case IFLA_VF_LINK_STATE_DISABLE:
2663 return MLX5_ESW_VPORT_ADMIN_STATE_DOWN;
2664 case IFLA_VF_LINK_STATE_ENABLE:
2665 return MLX5_ESW_VPORT_ADMIN_STATE_UP;
2667 return MLX5_ESW_VPORT_ADMIN_STATE_AUTO;
2670 static int mlx5e_set_vf_link_state(struct net_device *dev, int vf,
2673 struct mlx5e_priv *priv = netdev_priv(dev);
2674 struct mlx5_core_dev *mdev = priv->mdev;
2676 return mlx5_eswitch_set_vport_state(mdev->priv.eswitch, vf + 1,
2677 mlx5_ifla_link2vport(link_state));
2680 static int mlx5e_get_vf_config(struct net_device *dev,
2681 int vf, struct ifla_vf_info *ivi)
2683 struct mlx5e_priv *priv = netdev_priv(dev);
2684 struct mlx5_core_dev *mdev = priv->mdev;
2687 err = mlx5_eswitch_get_vport_config(mdev->priv.eswitch, vf + 1, ivi);
2690 ivi->linkstate = mlx5_vport_link2ifla(ivi->linkstate);
2694 static int mlx5e_get_vf_stats(struct net_device *dev,
2695 int vf, struct ifla_vf_stats *vf_stats)
2697 struct mlx5e_priv *priv = netdev_priv(dev);
2698 struct mlx5_core_dev *mdev = priv->mdev;
2700 return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
2704 static void mlx5e_add_vxlan_port(struct net_device *netdev,
2705 struct udp_tunnel_info *ti)
2707 struct mlx5e_priv *priv = netdev_priv(netdev);
2709 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2712 if (!mlx5e_vxlan_allowed(priv->mdev))
2715 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 1);
2718 static void mlx5e_del_vxlan_port(struct net_device *netdev,
2719 struct udp_tunnel_info *ti)
2721 struct mlx5e_priv *priv = netdev_priv(netdev);
2723 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2726 if (!mlx5e_vxlan_allowed(priv->mdev))
2729 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 0);
2732 static netdev_features_t mlx5e_vxlan_features_check(struct mlx5e_priv *priv,
2733 struct sk_buff *skb,
2734 netdev_features_t features)
2736 struct udphdr *udph;
2740 switch (vlan_get_protocol(skb)) {
2741 case htons(ETH_P_IP):
2742 proto = ip_hdr(skb)->protocol;
2744 case htons(ETH_P_IPV6):
2745 proto = ipv6_hdr(skb)->nexthdr;
2751 if (proto == IPPROTO_UDP) {
2752 udph = udp_hdr(skb);
2753 port = be16_to_cpu(udph->dest);
2756 /* Verify if UDP port is being offloaded by HW */
2757 if (port && mlx5e_vxlan_lookup_port(priv, port))
2761 /* Disable CSUM and GSO if the udp dport is not offloaded by HW */
2762 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2765 static netdev_features_t mlx5e_features_check(struct sk_buff *skb,
2766 struct net_device *netdev,
2767 netdev_features_t features)
2769 struct mlx5e_priv *priv = netdev_priv(netdev);
2771 features = vlan_features_check(skb, features);
2772 features = vxlan_features_check(skb, features);
2774 /* Validate if the tunneled packet is being offloaded by HW */
2775 if (skb->encapsulation &&
2776 (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
2777 return mlx5e_vxlan_features_check(priv, skb, features);
2782 static void mlx5e_tx_timeout(struct net_device *dev)
2784 struct mlx5e_priv *priv = netdev_priv(dev);
2785 bool sched_work = false;
2788 netdev_err(dev, "TX timeout detected\n");
2790 for (i = 0; i < priv->params.num_channels * priv->params.num_tc; i++) {
2791 struct mlx5e_sq *sq = priv->txq_to_sq_map[i];
2793 if (!netif_xmit_stopped(netdev_get_tx_queue(dev, i)))
2796 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
2797 netdev_err(dev, "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x\n",
2798 i, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc);
2801 if (sched_work && test_bit(MLX5E_STATE_OPENED, &priv->state))
2802 schedule_work(&priv->tx_timeout_work);
2805 static const struct net_device_ops mlx5e_netdev_ops_basic = {
2806 .ndo_open = mlx5e_open,
2807 .ndo_stop = mlx5e_close,
2808 .ndo_start_xmit = mlx5e_xmit,
2809 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2810 .ndo_select_queue = mlx5e_select_queue,
2811 .ndo_get_stats64 = mlx5e_get_stats,
2812 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2813 .ndo_set_mac_address = mlx5e_set_mac,
2814 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2815 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2816 .ndo_set_features = mlx5e_set_features,
2817 .ndo_change_mtu = mlx5e_change_mtu,
2818 .ndo_do_ioctl = mlx5e_ioctl,
2819 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2820 #ifdef CONFIG_RFS_ACCEL
2821 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2823 .ndo_tx_timeout = mlx5e_tx_timeout,
2826 static const struct net_device_ops mlx5e_netdev_ops_sriov = {
2827 .ndo_open = mlx5e_open,
2828 .ndo_stop = mlx5e_close,
2829 .ndo_start_xmit = mlx5e_xmit,
2830 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2831 .ndo_select_queue = mlx5e_select_queue,
2832 .ndo_get_stats64 = mlx5e_get_stats,
2833 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2834 .ndo_set_mac_address = mlx5e_set_mac,
2835 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2836 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2837 .ndo_set_features = mlx5e_set_features,
2838 .ndo_change_mtu = mlx5e_change_mtu,
2839 .ndo_do_ioctl = mlx5e_ioctl,
2840 .ndo_udp_tunnel_add = mlx5e_add_vxlan_port,
2841 .ndo_udp_tunnel_del = mlx5e_del_vxlan_port,
2842 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2843 .ndo_features_check = mlx5e_features_check,
2844 #ifdef CONFIG_RFS_ACCEL
2845 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2847 .ndo_set_vf_mac = mlx5e_set_vf_mac,
2848 .ndo_set_vf_vlan = mlx5e_set_vf_vlan,
2849 .ndo_set_vf_spoofchk = mlx5e_set_vf_spoofchk,
2850 .ndo_set_vf_trust = mlx5e_set_vf_trust,
2851 .ndo_get_vf_config = mlx5e_get_vf_config,
2852 .ndo_set_vf_link_state = mlx5e_set_vf_link_state,
2853 .ndo_get_vf_stats = mlx5e_get_vf_stats,
2854 .ndo_tx_timeout = mlx5e_tx_timeout,
2857 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
2859 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
2861 if (!MLX5_CAP_GEN(mdev, eth_net_offloads) ||
2862 !MLX5_CAP_GEN(mdev, nic_flow_table) ||
2863 !MLX5_CAP_ETH(mdev, csum_cap) ||
2864 !MLX5_CAP_ETH(mdev, max_lso_cap) ||
2865 !MLX5_CAP_ETH(mdev, vlan_cap) ||
2866 !MLX5_CAP_ETH(mdev, rss_ind_tbl_cap) ||
2867 MLX5_CAP_FLOWTABLE(mdev,
2868 flow_table_properties_nic_receive.max_ft_level)
2870 mlx5_core_warn(mdev,
2871 "Not creating net device, some required device capabilities are missing\n");
2874 if (!MLX5_CAP_ETH(mdev, self_lb_en_modifiable))
2875 mlx5_core_warn(mdev, "Self loop back prevention is not supported\n");
2876 if (!MLX5_CAP_GEN(mdev, cq_moderation))
2877 mlx5_core_warn(mdev, "CQ modiration is not supported\n");
2882 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev)
2884 int bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
2886 return bf_buf_size -
2887 sizeof(struct mlx5e_tx_wqe) +
2888 2 /*sizeof(mlx5e_tx_wqe.inline_hdr_start)*/;
2891 #ifdef CONFIG_MLX5_CORE_EN_DCB
2892 static void mlx5e_ets_init(struct mlx5e_priv *priv)
2896 priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
2897 for (i = 0; i < priv->params.ets.ets_cap; i++) {
2898 priv->params.ets.tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
2899 priv->params.ets.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
2900 priv->params.ets.prio_tc[i] = i;
2903 /* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
2904 priv->params.ets.prio_tc[0] = 1;
2905 priv->params.ets.prio_tc[1] = 0;
2909 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
2910 u32 *indirection_rqt, int len,
2913 int node = mdev->priv.numa_node;
2914 int node_num_of_cores;
2918 node = first_online_node;
2920 node_num_of_cores = cpumask_weight(cpumask_of_node(node));
2922 if (node_num_of_cores)
2923 num_channels = min_t(int, num_channels, node_num_of_cores);
2925 for (i = 0; i < len; i++)
2926 indirection_rqt[i] = i % num_channels;
2929 static bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
2931 return MLX5_CAP_GEN(mdev, striding_rq) &&
2932 MLX5_CAP_GEN(mdev, umr_ptr_rlky) &&
2933 MLX5_CAP_ETH(mdev, reg_umr_sq);
2936 static int mlx5e_get_pci_bw(struct mlx5_core_dev *mdev, u32 *pci_bw)
2938 enum pcie_link_width width;
2939 enum pci_bus_speed speed;
2942 err = pcie_get_minimum_link(mdev->pdev, &speed, &width);
2946 if (speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
2950 case PCIE_SPEED_2_5GT:
2951 *pci_bw = 2500 * width;
2953 case PCIE_SPEED_5_0GT:
2954 *pci_bw = 5000 * width;
2956 case PCIE_SPEED_8_0GT:
2957 *pci_bw = 8000 * width;
2966 static bool cqe_compress_heuristic(u32 link_speed, u32 pci_bw)
2968 return (link_speed && pci_bw &&
2969 (pci_bw < 40000) && (pci_bw < link_speed));
2972 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode)
2974 params->rx_cq_period_mode = cq_period_mode;
2976 params->rx_cq_moderation.pkts =
2977 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2978 params->rx_cq_moderation.usec =
2979 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2981 if (cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE)
2982 params->rx_cq_moderation.usec =
2983 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE;
2986 static void mlx5e_query_min_inline(struct mlx5_core_dev *mdev,
2987 u8 *min_inline_mode)
2989 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
2990 case MLX5E_INLINE_MODE_L2:
2991 *min_inline_mode = MLX5_INLINE_MODE_L2;
2993 case MLX5E_INLINE_MODE_VPORT_CONTEXT:
2994 mlx5_query_nic_vport_min_inline(mdev,
2997 case MLX5_INLINE_MODE_NOT_REQUIRED:
2998 *min_inline_mode = MLX5_INLINE_MODE_NONE;
3003 static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
3004 struct net_device *netdev,
3005 const struct mlx5e_profile *profile,
3008 struct mlx5e_priv *priv = netdev_priv(netdev);
3011 u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
3012 MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
3013 MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
3015 priv->params.log_sq_size =
3016 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
3017 priv->params.rq_wq_type = mlx5e_check_fragmented_striding_rq_cap(mdev) ?
3018 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
3019 MLX5_WQ_TYPE_LINKED_LIST;
3021 /* set CQE compression */
3022 priv->params.rx_cqe_compress_admin = false;
3023 if (MLX5_CAP_GEN(mdev, cqe_compression) &&
3024 MLX5_CAP_GEN(mdev, vport_group_manager)) {
3025 mlx5e_get_max_linkspeed(mdev, &link_speed);
3026 mlx5e_get_pci_bw(mdev, &pci_bw);
3027 mlx5_core_dbg(mdev, "Max link speed = %d, PCI BW = %d\n",
3028 link_speed, pci_bw);
3029 priv->params.rx_cqe_compress_admin =
3030 cqe_compress_heuristic(link_speed, pci_bw);
3033 priv->params.rx_cqe_compress = priv->params.rx_cqe_compress_admin;
3035 switch (priv->params.rq_wq_type) {
3036 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
3037 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW;
3038 priv->params.mpwqe_log_stride_sz =
3039 priv->params.rx_cqe_compress ?
3040 MLX5_MPWRQ_LOG_STRIDE_SIZE_CQE_COMPRESS :
3041 MLX5_MPWRQ_LOG_STRIDE_SIZE;
3042 priv->params.mpwqe_log_num_strides = MLX5_MPWRQ_LOG_WQE_SZ -
3043 priv->params.mpwqe_log_stride_sz;
3044 priv->params.lro_en = true;
3046 default: /* MLX5_WQ_TYPE_LINKED_LIST */
3047 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
3050 mlx5_core_info(mdev,
3051 "MLX5E: StrdRq(%d) RqSz(%ld) StrdSz(%ld) RxCqeCmprss(%d)\n",
3052 priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ,
3053 BIT(priv->params.log_rq_size),
3054 BIT(priv->params.mpwqe_log_stride_sz),
3055 priv->params.rx_cqe_compress_admin);
3057 priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
3058 BIT(priv->params.log_rq_size));
3060 priv->params.rx_am_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
3061 mlx5e_set_rx_cq_mode_params(&priv->params, cq_period_mode);
3063 priv->params.tx_cq_moderation.usec =
3064 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
3065 priv->params.tx_cq_moderation.pkts =
3066 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
3067 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
3068 mlx5e_query_min_inline(mdev, &priv->params.tx_min_inline_mode);
3069 priv->params.num_tc = 1;
3070 priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
3072 netdev_rss_key_fill(priv->params.toeplitz_hash_key,
3073 sizeof(priv->params.toeplitz_hash_key));
3075 mlx5e_build_default_indir_rqt(mdev, priv->params.indirection_rqt,
3076 MLX5E_INDIR_RQT_SIZE, profile->max_nch(mdev));
3078 priv->params.lro_wqe_sz =
3079 MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
3081 /* Initialize pflags */
3082 MLX5E_SET_PRIV_FLAG(priv, MLX5E_PFLAG_RX_CQE_BASED_MODER,
3083 priv->params.rx_cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE);
3086 priv->netdev = netdev;
3087 priv->params.num_channels = profile->max_nch(mdev);
3088 priv->profile = profile;
3089 priv->ppriv = ppriv;
3091 #ifdef CONFIG_MLX5_CORE_EN_DCB
3092 mlx5e_ets_init(priv);
3095 mutex_init(&priv->state_lock);
3097 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
3098 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
3099 INIT_WORK(&priv->tx_timeout_work, mlx5e_tx_timeout_work);
3100 INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
3103 static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
3105 struct mlx5e_priv *priv = netdev_priv(netdev);
3107 mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
3108 if (is_zero_ether_addr(netdev->dev_addr) &&
3109 !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
3110 eth_hw_addr_random(netdev);
3111 mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr);
3115 static const struct switchdev_ops mlx5e_switchdev_ops = {
3116 .switchdev_port_attr_get = mlx5e_attr_get,
3119 static void mlx5e_build_nic_netdev(struct net_device *netdev)
3121 struct mlx5e_priv *priv = netdev_priv(netdev);
3122 struct mlx5_core_dev *mdev = priv->mdev;
3126 SET_NETDEV_DEV(netdev, &mdev->pdev->dev);
3128 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3129 netdev->netdev_ops = &mlx5e_netdev_ops_sriov;
3130 #ifdef CONFIG_MLX5_CORE_EN_DCB
3131 netdev->dcbnl_ops = &mlx5e_dcbnl_ops;
3134 netdev->netdev_ops = &mlx5e_netdev_ops_basic;
3137 netdev->watchdog_timeo = 15 * HZ;
3139 netdev->ethtool_ops = &mlx5e_ethtool_ops;
3141 netdev->vlan_features |= NETIF_F_SG;
3142 netdev->vlan_features |= NETIF_F_IP_CSUM;
3143 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
3144 netdev->vlan_features |= NETIF_F_GRO;
3145 netdev->vlan_features |= NETIF_F_TSO;
3146 netdev->vlan_features |= NETIF_F_TSO6;
3147 netdev->vlan_features |= NETIF_F_RXCSUM;
3148 netdev->vlan_features |= NETIF_F_RXHASH;
3150 if (!!MLX5_CAP_ETH(mdev, lro_cap))
3151 netdev->vlan_features |= NETIF_F_LRO;
3153 netdev->hw_features = netdev->vlan_features;
3154 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
3155 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
3156 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
3158 if (mlx5e_vxlan_allowed(mdev)) {
3159 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL |
3160 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3161 NETIF_F_GSO_PARTIAL;
3162 netdev->hw_enc_features |= NETIF_F_IP_CSUM;
3163 netdev->hw_enc_features |= NETIF_F_IPV6_CSUM;
3164 netdev->hw_enc_features |= NETIF_F_TSO;
3165 netdev->hw_enc_features |= NETIF_F_TSO6;
3166 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL;
3167 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3168 NETIF_F_GSO_PARTIAL;
3169 netdev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM;
3172 mlx5_query_port_fcs(mdev, &fcs_supported, &fcs_enabled);
3175 netdev->hw_features |= NETIF_F_RXALL;
3177 netdev->features = netdev->hw_features;
3178 if (!priv->params.lro_en)
3179 netdev->features &= ~NETIF_F_LRO;
3182 netdev->features &= ~NETIF_F_RXALL;
3184 #define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
3185 if (FT_CAP(flow_modify_en) &&
3186 FT_CAP(modify_root) &&
3187 FT_CAP(identified_miss_table_mode) &&
3188 FT_CAP(flow_table_modify)) {
3189 netdev->hw_features |= NETIF_F_HW_TC;
3190 #ifdef CONFIG_RFS_ACCEL
3191 netdev->hw_features |= NETIF_F_NTUPLE;
3195 netdev->features |= NETIF_F_HIGHDMA;
3197 netdev->priv_flags |= IFF_UNICAST_FLT;
3199 mlx5e_set_netdev_dev_addr(netdev);
3201 #ifdef CONFIG_NET_SWITCHDEV
3202 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3203 netdev->switchdev_ops = &mlx5e_switchdev_ops;
3207 static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
3209 struct mlx5_core_dev *mdev = priv->mdev;
3212 err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter);
3214 mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err);
3215 priv->q_counter = 0;
3219 static void mlx5e_destroy_q_counter(struct mlx5e_priv *priv)
3221 if (!priv->q_counter)
3224 mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter);
3227 static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
3229 struct mlx5_core_dev *mdev = priv->mdev;
3230 u64 npages = priv->profile->max_nch(mdev) * MLX5_CHANNEL_MAX_NUM_MTTS;
3231 int inlen = MLX5_ST_SZ_BYTES(create_mkey_in);
3236 in = mlx5_vzalloc(inlen);
3240 mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
3242 MLX5_SET(mkc, mkc, free, 1);
3243 MLX5_SET(mkc, mkc, umr_en, 1);
3244 MLX5_SET(mkc, mkc, lw, 1);
3245 MLX5_SET(mkc, mkc, lr, 1);
3246 MLX5_SET(mkc, mkc, access_mode, MLX5_MKC_ACCESS_MODE_MTT);
3248 MLX5_SET(mkc, mkc, qpn, 0xffffff);
3249 MLX5_SET(mkc, mkc, pd, mdev->mlx5e_res.pdn);
3250 MLX5_SET64(mkc, mkc, len, npages << PAGE_SHIFT);
3251 MLX5_SET(mkc, mkc, translations_octword_size,
3252 mlx5e_get_mtt_octw(npages));
3253 MLX5_SET(mkc, mkc, log_page_size, PAGE_SHIFT);
3255 err = mlx5_core_create_mkey(mdev, &priv->umr_mkey, in, inlen);
3261 static void mlx5e_nic_init(struct mlx5_core_dev *mdev,
3262 struct net_device *netdev,
3263 const struct mlx5e_profile *profile,
3266 struct mlx5e_priv *priv = netdev_priv(netdev);
3268 mlx5e_build_nic_netdev_priv(mdev, netdev, profile, ppriv);
3269 mlx5e_build_nic_netdev(netdev);
3270 mlx5e_vxlan_init(priv);
3273 static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
3275 struct mlx5_core_dev *mdev = priv->mdev;
3276 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3278 mlx5e_vxlan_cleanup(priv);
3280 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3281 mlx5_eswitch_unregister_vport_rep(esw, 0);
3284 static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
3286 struct mlx5_core_dev *mdev = priv->mdev;
3290 err = mlx5e_create_indirect_rqts(priv);
3292 mlx5_core_warn(mdev, "create indirect rqts failed, %d\n", err);
3296 err = mlx5e_create_direct_rqts(priv);
3298 mlx5_core_warn(mdev, "create direct rqts failed, %d\n", err);
3299 goto err_destroy_indirect_rqts;
3302 err = mlx5e_create_indirect_tirs(priv);
3304 mlx5_core_warn(mdev, "create indirect tirs failed, %d\n", err);
3305 goto err_destroy_direct_rqts;
3308 err = mlx5e_create_direct_tirs(priv);
3310 mlx5_core_warn(mdev, "create direct tirs failed, %d\n", err);
3311 goto err_destroy_indirect_tirs;
3314 err = mlx5e_create_flow_steering(priv);
3316 mlx5_core_warn(mdev, "create flow steering failed, %d\n", err);
3317 goto err_destroy_direct_tirs;
3320 err = mlx5e_tc_init(priv);
3322 goto err_destroy_flow_steering;
3326 err_destroy_flow_steering:
3327 mlx5e_destroy_flow_steering(priv);
3328 err_destroy_direct_tirs:
3329 mlx5e_destroy_direct_tirs(priv);
3330 err_destroy_indirect_tirs:
3331 mlx5e_destroy_indirect_tirs(priv);
3332 err_destroy_direct_rqts:
3333 for (i = 0; i < priv->profile->max_nch(mdev); i++)
3334 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3335 err_destroy_indirect_rqts:
3336 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3340 static void mlx5e_cleanup_nic_rx(struct mlx5e_priv *priv)
3344 mlx5e_tc_cleanup(priv);
3345 mlx5e_destroy_flow_steering(priv);
3346 mlx5e_destroy_direct_tirs(priv);
3347 mlx5e_destroy_indirect_tirs(priv);
3348 for (i = 0; i < priv->profile->max_nch(priv->mdev); i++)
3349 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3350 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3353 static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
3357 err = mlx5e_create_tises(priv);
3359 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
3363 #ifdef CONFIG_MLX5_CORE_EN_DCB
3364 mlx5e_dcbnl_ieee_setets_core(priv, &priv->params.ets);
3369 static void mlx5e_nic_enable(struct mlx5e_priv *priv)
3371 struct net_device *netdev = priv->netdev;
3372 struct mlx5_core_dev *mdev = priv->mdev;
3373 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3374 struct mlx5_eswitch_rep rep;
3376 mlx5_lag_add(mdev, netdev);
3378 if (mlx5e_vxlan_allowed(mdev)) {
3380 udp_tunnel_get_rx_info(netdev);
3384 mlx5e_enable_async_events(priv);
3385 queue_work(priv->wq, &priv->set_rx_mode_work);
3387 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3388 rep.load = mlx5e_nic_rep_load;
3389 rep.unload = mlx5e_nic_rep_unload;
3391 rep.priv_data = priv;
3392 mlx5_eswitch_register_vport_rep(esw, &rep);
3396 static void mlx5e_nic_disable(struct mlx5e_priv *priv)
3398 queue_work(priv->wq, &priv->set_rx_mode_work);
3399 mlx5e_disable_async_events(priv);
3400 mlx5_lag_remove(priv->mdev);
3403 static const struct mlx5e_profile mlx5e_nic_profile = {
3404 .init = mlx5e_nic_init,
3405 .cleanup = mlx5e_nic_cleanup,
3406 .init_rx = mlx5e_init_nic_rx,
3407 .cleanup_rx = mlx5e_cleanup_nic_rx,
3408 .init_tx = mlx5e_init_nic_tx,
3409 .cleanup_tx = mlx5e_cleanup_nic_tx,
3410 .enable = mlx5e_nic_enable,
3411 .disable = mlx5e_nic_disable,
3412 .update_stats = mlx5e_update_stats,
3413 .max_nch = mlx5e_get_max_num_channels,
3414 .max_tc = MLX5E_MAX_NUM_TC,
3417 void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
3418 const struct mlx5e_profile *profile, void *ppriv)
3420 struct net_device *netdev;
3421 struct mlx5e_priv *priv;
3422 int nch = profile->max_nch(mdev);
3425 netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
3426 nch * profile->max_tc,
3429 mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
3433 profile->init(mdev, netdev, profile, ppriv);
3435 netif_carrier_off(netdev);
3437 priv = netdev_priv(netdev);
3439 priv->wq = create_singlethread_workqueue("mlx5e");
3441 goto err_free_netdev;
3443 err = mlx5e_create_umr_mkey(priv);
3445 mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
3446 goto err_destroy_wq;
3449 err = profile->init_tx(priv);
3451 goto err_destroy_umr_mkey;
3453 err = mlx5e_open_drop_rq(priv);
3455 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
3456 goto err_cleanup_tx;
3459 err = profile->init_rx(priv);
3461 goto err_close_drop_rq;
3463 mlx5e_create_q_counter(priv);
3465 mlx5e_init_l2_addr(priv);
3467 err = register_netdev(netdev);
3469 mlx5_core_err(mdev, "register_netdev failed, %d\n", err);
3470 goto err_dealloc_q_counters;
3473 if (profile->enable)
3474 profile->enable(priv);
3478 err_dealloc_q_counters:
3479 mlx5e_destroy_q_counter(priv);
3480 profile->cleanup_rx(priv);
3483 mlx5e_close_drop_rq(priv);
3486 profile->cleanup_tx(priv);
3488 err_destroy_umr_mkey:
3489 mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
3492 destroy_workqueue(priv->wq);
3495 free_netdev(netdev);
3500 static void mlx5e_register_vport_rep(struct mlx5_core_dev *mdev)
3502 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3503 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3506 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
3509 for (vport = 1; vport < total_vfs; vport++) {
3510 struct mlx5_eswitch_rep rep;
3512 rep.load = mlx5e_vport_rep_load;
3513 rep.unload = mlx5e_vport_rep_unload;
3515 mlx5_eswitch_register_vport_rep(esw, &rep);
3519 static void *mlx5e_add(struct mlx5_core_dev *mdev)
3521 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3525 if (mlx5e_check_required_hca_cap(mdev))
3528 if (mlx5e_create_mdev_resources(mdev))
3531 mlx5e_register_vport_rep(mdev);
3533 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3534 ppriv = &esw->offloads.vport_reps[0];
3536 ret = mlx5e_create_netdev(mdev, &mlx5e_nic_profile, ppriv);
3538 mlx5e_destroy_mdev_resources(mdev);
3544 void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
3546 const struct mlx5e_profile *profile = priv->profile;
3547 struct net_device *netdev = priv->netdev;
3549 set_bit(MLX5E_STATE_DESTROYING, &priv->state);
3550 if (profile->disable)
3551 profile->disable(priv);
3553 flush_workqueue(priv->wq);
3554 if (test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state)) {
3555 netif_device_detach(netdev);
3556 mlx5e_close(netdev);
3558 unregister_netdev(netdev);
3561 mlx5e_destroy_q_counter(priv);
3562 profile->cleanup_rx(priv);
3563 mlx5e_close_drop_rq(priv);
3564 profile->cleanup_tx(priv);
3565 mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
3566 cancel_delayed_work_sync(&priv->update_stats_work);
3567 destroy_workqueue(priv->wq);
3568 if (profile->cleanup)
3569 profile->cleanup(priv);
3571 if (!test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state))
3572 free_netdev(netdev);
3575 static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
3577 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3578 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3579 struct mlx5e_priv *priv = vpriv;
3582 mlx5e_destroy_netdev(mdev, priv);
3584 for (vport = 1; vport < total_vfs; vport++)
3585 mlx5_eswitch_unregister_vport_rep(esw, vport);
3587 mlx5e_destroy_mdev_resources(mdev);
3590 static void *mlx5e_get_netdev(void *vpriv)
3592 struct mlx5e_priv *priv = vpriv;
3594 return priv->netdev;
3597 static struct mlx5_interface mlx5e_interface = {
3599 .remove = mlx5e_remove,
3600 .event = mlx5e_async_event,
3601 .protocol = MLX5_INTERFACE_PROTOCOL_ETH,
3602 .get_dev = mlx5e_get_netdev,
3605 void mlx5e_init(void)
3607 mlx5e_build_ptys2ethtool_map();
3608 mlx5_register_interface(&mlx5e_interface);
3611 void mlx5e_cleanup(void)
3613 mlx5_unregister_interface(&mlx5e_interface);