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_mtt_offset = c->ix *
344 MLX5E_REQUIRED_MTTS(1, BIT(priv->params.log_rq_size));
346 rq->mpwqe_stride_sz = BIT(priv->params.mpwqe_log_stride_sz);
347 rq->mpwqe_num_strides = BIT(priv->params.mpwqe_log_num_strides);
348 rq->wqe_sz = rq->mpwqe_stride_sz * rq->mpwqe_num_strides;
349 byte_count = rq->wqe_sz;
351 default: /* MLX5_WQ_TYPE_LINKED_LIST */
352 rq->skb = kzalloc_node(wq_sz * sizeof(*rq->skb), GFP_KERNEL,
353 cpu_to_node(c->cpu));
356 goto err_rq_wq_destroy;
358 rq->handle_rx_cqe = mlx5e_handle_rx_cqe;
359 rq->alloc_wqe = mlx5e_alloc_rx_wqe;
360 rq->dealloc_wqe = mlx5e_dealloc_rx_wqe;
362 rq->wqe_sz = (priv->params.lro_en) ?
363 priv->params.lro_wqe_sz :
364 MLX5E_SW2HW_MTU(priv->netdev->mtu);
365 rq->wqe_sz = SKB_DATA_ALIGN(rq->wqe_sz);
366 byte_count = rq->wqe_sz;
367 byte_count |= MLX5_HW_START_PADDING;
370 for (i = 0; i < wq_sz; i++) {
371 struct mlx5e_rx_wqe *wqe = mlx5_wq_ll_get_wqe(&rq->wq, i);
373 wqe->data.byte_count = cpu_to_be32(byte_count);
376 INIT_WORK(&rq->am.work, mlx5e_rx_am_work);
377 rq->am.mode = priv->params.rx_cq_period_mode;
379 rq->wq_type = priv->params.rq_wq_type;
381 rq->netdev = c->netdev;
382 rq->tstamp = &priv->tstamp;
386 rq->mkey_be = c->mkey_be;
387 rq->umr_mkey_be = cpu_to_be32(c->priv->umr_mkey.key);
392 mlx5_wq_destroy(&rq->wq_ctrl);
397 static void mlx5e_destroy_rq(struct mlx5e_rq *rq)
399 switch (rq->wq_type) {
400 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
403 default: /* MLX5_WQ_TYPE_LINKED_LIST */
407 mlx5_wq_destroy(&rq->wq_ctrl);
410 static int mlx5e_enable_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param)
412 struct mlx5e_priv *priv = rq->priv;
413 struct mlx5_core_dev *mdev = priv->mdev;
421 inlen = MLX5_ST_SZ_BYTES(create_rq_in) +
422 sizeof(u64) * rq->wq_ctrl.buf.npages;
423 in = mlx5_vzalloc(inlen);
427 rqc = MLX5_ADDR_OF(create_rq_in, in, ctx);
428 wq = MLX5_ADDR_OF(rqc, rqc, wq);
430 memcpy(rqc, param->rqc, sizeof(param->rqc));
432 MLX5_SET(rqc, rqc, cqn, rq->cq.mcq.cqn);
433 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST);
434 MLX5_SET(rqc, rqc, flush_in_error_en, 1);
435 MLX5_SET(rqc, rqc, vsd, priv->params.vlan_strip_disable);
436 MLX5_SET(wq, wq, log_wq_pg_sz, rq->wq_ctrl.buf.page_shift -
437 MLX5_ADAPTER_PAGE_SHIFT);
438 MLX5_SET64(wq, wq, dbr_addr, rq->wq_ctrl.db.dma);
440 mlx5_fill_page_array(&rq->wq_ctrl.buf,
441 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
443 err = mlx5_core_create_rq(mdev, in, inlen, &rq->rqn);
450 static int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state,
453 struct mlx5e_channel *c = rq->channel;
454 struct mlx5e_priv *priv = c->priv;
455 struct mlx5_core_dev *mdev = priv->mdev;
462 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
463 in = mlx5_vzalloc(inlen);
467 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
469 MLX5_SET(modify_rq_in, in, rq_state, curr_state);
470 MLX5_SET(rqc, rqc, state, next_state);
472 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
479 static int mlx5e_modify_rq_vsd(struct mlx5e_rq *rq, bool vsd)
481 struct mlx5e_channel *c = rq->channel;
482 struct mlx5e_priv *priv = c->priv;
483 struct mlx5_core_dev *mdev = priv->mdev;
490 inlen = MLX5_ST_SZ_BYTES(modify_rq_in);
491 in = mlx5_vzalloc(inlen);
495 rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
497 MLX5_SET(modify_rq_in, in, rq_state, MLX5_RQC_STATE_RDY);
498 MLX5_SET64(modify_rq_in, in, modify_bitmask, MLX5_RQ_BITMASK_VSD);
499 MLX5_SET(rqc, rqc, vsd, vsd);
500 MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RDY);
502 err = mlx5_core_modify_rq(mdev, rq->rqn, in, inlen);
509 static void mlx5e_disable_rq(struct mlx5e_rq *rq)
511 mlx5_core_destroy_rq(rq->priv->mdev, rq->rqn);
514 static int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq)
516 unsigned long exp_time = jiffies + msecs_to_jiffies(20000);
517 struct mlx5e_channel *c = rq->channel;
518 struct mlx5e_priv *priv = c->priv;
519 struct mlx5_wq_ll *wq = &rq->wq;
521 while (time_before(jiffies, exp_time)) {
522 if (wq->cur_sz >= priv->params.min_rx_wqes)
531 static int mlx5e_open_rq(struct mlx5e_channel *c,
532 struct mlx5e_rq_param *param,
535 struct mlx5e_sq *sq = &c->icosq;
536 u16 pi = sq->pc & sq->wq.sz_m1;
539 err = mlx5e_create_rq(c, param, rq);
543 err = mlx5e_enable_rq(rq, param);
547 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
551 if (param->am_enabled)
552 set_bit(MLX5E_RQ_STATE_AM, &c->rq.state);
554 set_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
556 sq->ico_wqe_info[pi].opcode = MLX5_OPCODE_NOP;
557 sq->ico_wqe_info[pi].num_wqebbs = 1;
558 mlx5e_send_nop(sq, true); /* trigger mlx5e_post_rx_wqes() */
563 mlx5e_disable_rq(rq);
565 mlx5e_destroy_rq(rq);
570 static void mlx5e_close_rq(struct mlx5e_rq *rq)
575 clear_bit(MLX5E_RQ_STATE_POST_WQES_ENABLE, &rq->state);
576 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
578 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RDY, MLX5_RQC_STATE_ERR);
579 while (!mlx5_wq_ll_is_empty(&rq->wq) && !err &&
580 tout++ < MLX5_EN_QP_FLUSH_MAX_ITER)
581 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
583 if (err || tout == MLX5_EN_QP_FLUSH_MAX_ITER)
584 set_bit(MLX5E_RQ_STATE_FLUSH_TIMEOUT, &rq->state);
586 /* avoid destroying rq before mlx5e_poll_rx_cq() is done with it */
587 napi_synchronize(&rq->channel->napi);
589 cancel_work_sync(&rq->am.work);
591 mlx5e_disable_rq(rq);
592 mlx5e_free_rx_descs(rq);
593 mlx5e_destroy_rq(rq);
596 static void mlx5e_free_sq_db(struct mlx5e_sq *sq)
603 static int mlx5e_alloc_sq_db(struct mlx5e_sq *sq, int numa)
605 int wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
606 int df_sz = wq_sz * MLX5_SEND_WQEBB_NUM_DS;
608 sq->skb = kzalloc_node(wq_sz * sizeof(*sq->skb), GFP_KERNEL, numa);
609 sq->dma_fifo = kzalloc_node(df_sz * sizeof(*sq->dma_fifo), GFP_KERNEL,
611 sq->wqe_info = kzalloc_node(wq_sz * sizeof(*sq->wqe_info), GFP_KERNEL,
614 if (!sq->skb || !sq->dma_fifo || !sq->wqe_info) {
615 mlx5e_free_sq_db(sq);
619 sq->dma_fifo_mask = df_sz - 1;
624 static int mlx5e_create_sq(struct mlx5e_channel *c,
626 struct mlx5e_sq_param *param,
629 struct mlx5e_priv *priv = c->priv;
630 struct mlx5_core_dev *mdev = priv->mdev;
632 void *sqc = param->sqc;
633 void *sqc_wq = MLX5_ADDR_OF(sqc, sqc, wq);
636 err = mlx5_alloc_map_uar(mdev, &sq->uar, !!MLX5_CAP_GEN(mdev, bf));
640 param->wq.db_numa_node = cpu_to_node(c->cpu);
642 err = mlx5_wq_cyc_create(mdev, ¶m->wq, sqc_wq, &sq->wq,
645 goto err_unmap_free_uar;
647 sq->wq.db = &sq->wq.db[MLX5_SND_DBR];
648 if (sq->uar.bf_map) {
649 set_bit(MLX5E_SQ_STATE_BF_ENABLE, &sq->state);
650 sq->uar_map = sq->uar.bf_map;
652 sq->uar_map = sq->uar.map;
654 sq->bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
655 sq->max_inline = param->max_inline;
656 sq->min_inline_mode =
657 MLX5_CAP_ETH(mdev, wqe_inline_mode) == MLX5E_INLINE_MODE_VPORT_CONTEXT ?
658 param->min_inline_mode : 0;
660 err = mlx5e_alloc_sq_db(sq, cpu_to_node(c->cpu));
662 goto err_sq_wq_destroy;
665 u8 wq_sz = mlx5_wq_cyc_get_size(&sq->wq);
667 sq->ico_wqe_info = kzalloc_node(sizeof(*sq->ico_wqe_info) *
670 cpu_to_node(c->cpu));
671 if (!sq->ico_wqe_info) {
678 txq_ix = c->ix + tc * priv->params.num_channels;
679 sq->txq = netdev_get_tx_queue(priv->netdev, txq_ix);
680 priv->txq_to_sq_map[txq_ix] = sq;
684 sq->tstamp = &priv->tstamp;
685 sq->mkey_be = c->mkey_be;
688 sq->edge = (sq->wq.sz_m1 + 1) - MLX5_SEND_WQE_MAX_WQEBBS;
689 sq->bf_budget = MLX5E_SQ_BF_BUDGET;
694 mlx5e_free_sq_db(sq);
697 mlx5_wq_destroy(&sq->wq_ctrl);
700 mlx5_unmap_free_uar(mdev, &sq->uar);
705 static void mlx5e_destroy_sq(struct mlx5e_sq *sq)
707 struct mlx5e_channel *c = sq->channel;
708 struct mlx5e_priv *priv = c->priv;
710 kfree(sq->ico_wqe_info);
711 mlx5e_free_sq_db(sq);
712 mlx5_wq_destroy(&sq->wq_ctrl);
713 mlx5_unmap_free_uar(priv->mdev, &sq->uar);
716 static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
718 struct mlx5e_channel *c = sq->channel;
719 struct mlx5e_priv *priv = c->priv;
720 struct mlx5_core_dev *mdev = priv->mdev;
728 inlen = MLX5_ST_SZ_BYTES(create_sq_in) +
729 sizeof(u64) * sq->wq_ctrl.buf.npages;
730 in = mlx5_vzalloc(inlen);
734 sqc = MLX5_ADDR_OF(create_sq_in, in, ctx);
735 wq = MLX5_ADDR_OF(sqc, sqc, wq);
737 memcpy(sqc, param->sqc, sizeof(param->sqc));
739 MLX5_SET(sqc, sqc, tis_num_0, param->icosq ? 0 : priv->tisn[sq->tc]);
740 MLX5_SET(sqc, sqc, cqn, sq->cq.mcq.cqn);
741 MLX5_SET(sqc, sqc, min_wqe_inline_mode, sq->min_inline_mode);
742 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
743 MLX5_SET(sqc, sqc, tis_lst_sz, param->icosq ? 0 : 1);
744 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
746 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
747 MLX5_SET(wq, wq, uar_page, sq->uar.index);
748 MLX5_SET(wq, wq, log_wq_pg_sz, sq->wq_ctrl.buf.page_shift -
749 MLX5_ADAPTER_PAGE_SHIFT);
750 MLX5_SET64(wq, wq, dbr_addr, sq->wq_ctrl.db.dma);
752 mlx5_fill_page_array(&sq->wq_ctrl.buf,
753 (__be64 *)MLX5_ADDR_OF(wq, wq, pas));
755 err = mlx5_core_create_sq(mdev, in, inlen, &sq->sqn);
762 static int mlx5e_modify_sq(struct mlx5e_sq *sq, int curr_state,
763 int next_state, bool update_rl, int rl_index)
765 struct mlx5e_channel *c = sq->channel;
766 struct mlx5e_priv *priv = c->priv;
767 struct mlx5_core_dev *mdev = priv->mdev;
774 inlen = MLX5_ST_SZ_BYTES(modify_sq_in);
775 in = mlx5_vzalloc(inlen);
779 sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx);
781 MLX5_SET(modify_sq_in, in, sq_state, curr_state);
782 MLX5_SET(sqc, sqc, state, next_state);
783 if (update_rl && next_state == MLX5_SQC_STATE_RDY) {
784 MLX5_SET64(modify_sq_in, in, modify_bitmask, 1);
785 MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index);
788 err = mlx5_core_modify_sq(mdev, sq->sqn, in, inlen);
795 static void mlx5e_disable_sq(struct mlx5e_sq *sq)
797 struct mlx5e_channel *c = sq->channel;
798 struct mlx5e_priv *priv = c->priv;
799 struct mlx5_core_dev *mdev = priv->mdev;
801 mlx5_core_destroy_sq(mdev, sq->sqn);
803 mlx5_rl_remove_rate(mdev, sq->rate_limit);
806 static int mlx5e_open_sq(struct mlx5e_channel *c,
808 struct mlx5e_sq_param *param,
813 err = mlx5e_create_sq(c, tc, param, sq);
817 err = mlx5e_enable_sq(sq, param);
821 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY,
827 set_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
828 netdev_tx_reset_queue(sq->txq);
829 netif_tx_start_queue(sq->txq);
835 mlx5e_disable_sq(sq);
837 mlx5e_destroy_sq(sq);
842 static inline void netif_tx_disable_queue(struct netdev_queue *txq)
844 __netif_tx_lock_bh(txq);
845 netif_tx_stop_queue(txq);
846 __netif_tx_unlock_bh(txq);
849 static void mlx5e_close_sq(struct mlx5e_sq *sq)
855 clear_bit(MLX5E_SQ_STATE_WAKE_TXQ_ENABLE, &sq->state);
856 /* prevent netif_tx_wake_queue */
857 napi_synchronize(&sq->channel->napi);
858 netif_tx_disable_queue(sq->txq);
860 /* ensure hw is notified of all pending wqes */
861 if (mlx5e_sq_has_room_for(sq, 1))
862 mlx5e_send_nop(sq, true);
864 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
865 MLX5_SQC_STATE_ERR, false, 0);
867 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
870 /* wait till sq is empty, unless a TX timeout occurred on this SQ */
871 while (sq->cc != sq->pc &&
872 !test_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state)) {
873 msleep(MLX5_EN_QP_FLUSH_MSLEEP_QUANT);
874 if (tout++ > MLX5_EN_QP_FLUSH_MAX_ITER)
875 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
878 /* avoid destroying sq before mlx5e_poll_tx_cq() is done with it */
879 napi_synchronize(&sq->channel->napi);
881 mlx5e_free_tx_descs(sq);
882 mlx5e_disable_sq(sq);
883 mlx5e_destroy_sq(sq);
886 static int mlx5e_create_cq(struct mlx5e_channel *c,
887 struct mlx5e_cq_param *param,
890 struct mlx5e_priv *priv = c->priv;
891 struct mlx5_core_dev *mdev = priv->mdev;
892 struct mlx5_core_cq *mcq = &cq->mcq;
898 param->wq.buf_numa_node = cpu_to_node(c->cpu);
899 param->wq.db_numa_node = cpu_to_node(c->cpu);
900 param->eq_ix = c->ix;
902 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
907 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
912 mcq->set_ci_db = cq->wq_ctrl.db.db;
913 mcq->arm_db = cq->wq_ctrl.db.db + 1;
916 mcq->vector = param->eq_ix;
917 mcq->comp = mlx5e_completion_event;
918 mcq->event = mlx5e_cq_error_event;
920 mcq->uar = &mdev->mlx5e_res.cq_uar;
922 for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
923 struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
934 static void mlx5e_destroy_cq(struct mlx5e_cq *cq)
936 mlx5_wq_destroy(&cq->wq_ctrl);
939 static int mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param)
941 struct mlx5e_priv *priv = cq->priv;
942 struct mlx5_core_dev *mdev = priv->mdev;
943 struct mlx5_core_cq *mcq = &cq->mcq;
948 unsigned int irqn_not_used;
952 inlen = MLX5_ST_SZ_BYTES(create_cq_in) +
953 sizeof(u64) * cq->wq_ctrl.buf.npages;
954 in = mlx5_vzalloc(inlen);
958 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
960 memcpy(cqc, param->cqc, sizeof(param->cqc));
962 mlx5_fill_page_array(&cq->wq_ctrl.buf,
963 (__be64 *)MLX5_ADDR_OF(create_cq_in, in, pas));
965 mlx5_vector2eqn(mdev, param->eq_ix, &eqn, &irqn_not_used);
967 MLX5_SET(cqc, cqc, cq_period_mode, param->cq_period_mode);
968 MLX5_SET(cqc, cqc, c_eqn, eqn);
969 MLX5_SET(cqc, cqc, uar_page, mcq->uar->index);
970 MLX5_SET(cqc, cqc, log_page_size, cq->wq_ctrl.buf.page_shift -
971 MLX5_ADAPTER_PAGE_SHIFT);
972 MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
974 err = mlx5_core_create_cq(mdev, mcq, in, inlen);
986 static void mlx5e_disable_cq(struct mlx5e_cq *cq)
988 struct mlx5e_priv *priv = cq->priv;
989 struct mlx5_core_dev *mdev = priv->mdev;
991 mlx5_core_destroy_cq(mdev, &cq->mcq);
994 static int mlx5e_open_cq(struct mlx5e_channel *c,
995 struct mlx5e_cq_param *param,
997 struct mlx5e_cq_moder moderation)
1000 struct mlx5e_priv *priv = c->priv;
1001 struct mlx5_core_dev *mdev = priv->mdev;
1003 err = mlx5e_create_cq(c, param, cq);
1007 err = mlx5e_enable_cq(cq, param);
1009 goto err_destroy_cq;
1011 if (MLX5_CAP_GEN(mdev, cq_moderation))
1012 mlx5_core_modify_cq_moderation(mdev, &cq->mcq,
1018 mlx5e_destroy_cq(cq);
1023 static void mlx5e_close_cq(struct mlx5e_cq *cq)
1025 mlx5e_disable_cq(cq);
1026 mlx5e_destroy_cq(cq);
1029 static int mlx5e_get_cpu(struct mlx5e_priv *priv, int ix)
1031 return cpumask_first(priv->mdev->priv.irq_info[ix].mask);
1034 static int mlx5e_open_tx_cqs(struct mlx5e_channel *c,
1035 struct mlx5e_channel_param *cparam)
1037 struct mlx5e_priv *priv = c->priv;
1041 for (tc = 0; tc < c->num_tc; tc++) {
1042 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->sq[tc].cq,
1043 priv->params.tx_cq_moderation);
1045 goto err_close_tx_cqs;
1051 for (tc--; tc >= 0; tc--)
1052 mlx5e_close_cq(&c->sq[tc].cq);
1057 static void mlx5e_close_tx_cqs(struct mlx5e_channel *c)
1061 for (tc = 0; tc < c->num_tc; tc++)
1062 mlx5e_close_cq(&c->sq[tc].cq);
1065 static int mlx5e_open_sqs(struct mlx5e_channel *c,
1066 struct mlx5e_channel_param *cparam)
1071 for (tc = 0; tc < c->num_tc; tc++) {
1072 err = mlx5e_open_sq(c, tc, &cparam->sq, &c->sq[tc]);
1080 for (tc--; tc >= 0; tc--)
1081 mlx5e_close_sq(&c->sq[tc]);
1086 static void mlx5e_close_sqs(struct mlx5e_channel *c)
1090 for (tc = 0; tc < c->num_tc; tc++)
1091 mlx5e_close_sq(&c->sq[tc]);
1094 static void mlx5e_build_channeltc_to_txq_map(struct mlx5e_priv *priv, int ix)
1098 for (i = 0; i < priv->profile->max_tc; i++)
1099 priv->channeltc_to_txq_map[ix][i] =
1100 ix + i * priv->params.num_channels;
1103 static int mlx5e_set_sq_maxrate(struct net_device *dev,
1104 struct mlx5e_sq *sq, u32 rate)
1106 struct mlx5e_priv *priv = netdev_priv(dev);
1107 struct mlx5_core_dev *mdev = priv->mdev;
1111 if (rate == sq->rate_limit)
1116 /* remove current rl index to free space to next ones */
1117 mlx5_rl_remove_rate(mdev, sq->rate_limit);
1122 err = mlx5_rl_add_rate(mdev, rate, &rl_index);
1124 netdev_err(dev, "Failed configuring rate %u: %d\n",
1130 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RDY,
1131 MLX5_SQC_STATE_RDY, true, rl_index);
1133 netdev_err(dev, "Failed configuring rate %u: %d\n",
1135 /* remove the rate from the table */
1137 mlx5_rl_remove_rate(mdev, rate);
1141 sq->rate_limit = rate;
1145 static int mlx5e_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
1147 struct mlx5e_priv *priv = netdev_priv(dev);
1148 struct mlx5_core_dev *mdev = priv->mdev;
1149 struct mlx5e_sq *sq = priv->txq_to_sq_map[index];
1152 if (!mlx5_rl_is_supported(mdev)) {
1153 netdev_err(dev, "Rate limiting is not supported on this device\n");
1157 /* rate is given in Mb/sec, HW config is in Kb/sec */
1160 /* Check whether rate in valid range, 0 is always valid */
1161 if (rate && !mlx5_rl_is_in_range(mdev, rate)) {
1162 netdev_err(dev, "TX rate %u, is not in range\n", rate);
1166 mutex_lock(&priv->state_lock);
1167 if (test_bit(MLX5E_STATE_OPENED, &priv->state))
1168 err = mlx5e_set_sq_maxrate(dev, sq, rate);
1170 priv->tx_rates[index] = rate;
1171 mutex_unlock(&priv->state_lock);
1176 static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1177 struct mlx5e_channel_param *cparam,
1178 struct mlx5e_channel **cp)
1180 struct mlx5e_cq_moder icosq_cq_moder = {0, 0};
1181 struct net_device *netdev = priv->netdev;
1182 struct mlx5e_cq_moder rx_cq_profile;
1183 int cpu = mlx5e_get_cpu(priv, ix);
1184 struct mlx5e_channel *c;
1185 struct mlx5e_sq *sq;
1189 c = kzalloc_node(sizeof(*c), GFP_KERNEL, cpu_to_node(cpu));
1196 c->pdev = &priv->mdev->pdev->dev;
1197 c->netdev = priv->netdev;
1198 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1199 c->num_tc = priv->params.num_tc;
1201 if (priv->params.rx_am_enabled)
1202 rx_cq_profile = mlx5e_am_get_def_profile(priv->params.rx_cq_period_mode);
1204 rx_cq_profile = priv->params.rx_cq_moderation;
1206 mlx5e_build_channeltc_to_txq_map(priv, ix);
1208 netif_napi_add(netdev, &c->napi, mlx5e_napi_poll, 64);
1210 err = mlx5e_open_cq(c, &cparam->icosq_cq, &c->icosq.cq, icosq_cq_moder);
1214 err = mlx5e_open_tx_cqs(c, cparam);
1216 goto err_close_icosq_cq;
1218 err = mlx5e_open_cq(c, &cparam->rx_cq, &c->rq.cq,
1221 goto err_close_tx_cqs;
1223 napi_enable(&c->napi);
1225 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
1227 goto err_disable_napi;
1229 err = mlx5e_open_sqs(c, cparam);
1231 goto err_close_icosq;
1233 for (i = 0; i < priv->params.num_tc; i++) {
1234 u32 txq_ix = priv->channeltc_to_txq_map[ix][i];
1236 if (priv->tx_rates[txq_ix]) {
1237 sq = priv->txq_to_sq_map[txq_ix];
1238 mlx5e_set_sq_maxrate(priv->netdev, sq,
1239 priv->tx_rates[txq_ix]);
1243 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1247 netif_set_xps_queue(netdev, get_cpu_mask(c->cpu), ix);
1256 mlx5e_close_sq(&c->icosq);
1259 napi_disable(&c->napi);
1260 mlx5e_close_cq(&c->rq.cq);
1263 mlx5e_close_tx_cqs(c);
1266 mlx5e_close_cq(&c->icosq.cq);
1269 netif_napi_del(&c->napi);
1270 napi_hash_del(&c->napi);
1276 static void mlx5e_close_channel(struct mlx5e_channel *c)
1278 mlx5e_close_rq(&c->rq);
1280 mlx5e_close_sq(&c->icosq);
1281 napi_disable(&c->napi);
1282 mlx5e_close_cq(&c->rq.cq);
1283 mlx5e_close_tx_cqs(c);
1284 mlx5e_close_cq(&c->icosq.cq);
1285 netif_napi_del(&c->napi);
1287 napi_hash_del(&c->napi);
1293 static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
1294 struct mlx5e_rq_param *param)
1296 void *rqc = param->rqc;
1297 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1299 switch (priv->params.rq_wq_type) {
1300 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1301 MLX5_SET(wq, wq, log_wqe_num_of_strides,
1302 priv->params.mpwqe_log_num_strides - 9);
1303 MLX5_SET(wq, wq, log_wqe_stride_size,
1304 priv->params.mpwqe_log_stride_sz - 6);
1305 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
1307 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1308 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1311 MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
1312 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1313 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1314 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1315 MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
1317 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1318 param->wq.linear = 1;
1320 param->am_enabled = priv->params.rx_am_enabled;
1323 static void mlx5e_build_drop_rq_param(struct mlx5e_rq_param *param)
1325 void *rqc = param->rqc;
1326 void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1328 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_LINKED_LIST);
1329 MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
1332 static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
1333 struct mlx5e_sq_param *param)
1335 void *sqc = param->sqc;
1336 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1338 MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1339 MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
1341 param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
1344 static void mlx5e_build_sq_param(struct mlx5e_priv *priv,
1345 struct mlx5e_sq_param *param)
1347 void *sqc = param->sqc;
1348 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1350 mlx5e_build_sq_param_common(priv, param);
1351 MLX5_SET(wq, wq, log_wq_sz, priv->params.log_sq_size);
1353 param->max_inline = priv->params.tx_max_inline;
1354 param->min_inline_mode = priv->params.tx_min_inline_mode;
1357 static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
1358 struct mlx5e_cq_param *param)
1360 void *cqc = param->cqc;
1362 MLX5_SET(cqc, cqc, uar_page, priv->mdev->mlx5e_res.cq_uar.index);
1365 static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
1366 struct mlx5e_cq_param *param)
1368 void *cqc = param->cqc;
1371 switch (priv->params.rq_wq_type) {
1372 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
1373 log_cq_size = priv->params.log_rq_size +
1374 priv->params.mpwqe_log_num_strides;
1376 default: /* MLX5_WQ_TYPE_LINKED_LIST */
1377 log_cq_size = priv->params.log_rq_size;
1380 MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
1381 if (priv->params.rx_cqe_compress) {
1382 MLX5_SET(cqc, cqc, mini_cqe_res_format, MLX5_CQE_FORMAT_CSUM);
1383 MLX5_SET(cqc, cqc, cqe_comp_en, 1);
1386 mlx5e_build_common_cq_param(priv, param);
1388 param->cq_period_mode = priv->params.rx_cq_period_mode;
1391 static void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
1392 struct mlx5e_cq_param *param)
1394 void *cqc = param->cqc;
1396 MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_sq_size);
1398 mlx5e_build_common_cq_param(priv, param);
1400 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1403 static void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
1404 struct mlx5e_cq_param *param,
1407 void *cqc = param->cqc;
1409 MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1411 mlx5e_build_common_cq_param(priv, param);
1413 param->cq_period_mode = MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
1416 static void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
1417 struct mlx5e_sq_param *param,
1420 void *sqc = param->sqc;
1421 void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1423 mlx5e_build_sq_param_common(priv, param);
1425 MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1426 MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(priv->mdev, reg_umr_sq));
1428 param->icosq = true;
1431 static void mlx5e_build_channel_param(struct mlx5e_priv *priv, struct mlx5e_channel_param *cparam)
1433 u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1435 mlx5e_build_rq_param(priv, &cparam->rq);
1436 mlx5e_build_sq_param(priv, &cparam->sq);
1437 mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz);
1438 mlx5e_build_rx_cq_param(priv, &cparam->rx_cq);
1439 mlx5e_build_tx_cq_param(priv, &cparam->tx_cq);
1440 mlx5e_build_ico_cq_param(priv, &cparam->icosq_cq, icosq_log_wq_sz);
1443 static int mlx5e_open_channels(struct mlx5e_priv *priv)
1445 struct mlx5e_channel_param *cparam;
1446 int nch = priv->params.num_channels;
1451 priv->channel = kcalloc(nch, sizeof(struct mlx5e_channel *),
1454 priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc,
1455 sizeof(struct mlx5e_sq *), GFP_KERNEL);
1457 cparam = kzalloc(sizeof(struct mlx5e_channel_param), GFP_KERNEL);
1459 if (!priv->channel || !priv->txq_to_sq_map || !cparam)
1460 goto err_free_txq_to_sq_map;
1462 mlx5e_build_channel_param(priv, cparam);
1464 for (i = 0; i < nch; i++) {
1465 err = mlx5e_open_channel(priv, i, cparam, &priv->channel[i]);
1467 goto err_close_channels;
1470 for (j = 0; j < nch; j++) {
1471 err = mlx5e_wait_for_min_rx_wqes(&priv->channel[j]->rq);
1473 goto err_close_channels;
1476 /* FIXME: This is a W/A for tx timeout watch dog false alarm when
1477 * polling for inactive tx queues.
1479 netif_tx_start_all_queues(priv->netdev);
1485 for (i--; i >= 0; i--)
1486 mlx5e_close_channel(priv->channel[i]);
1488 err_free_txq_to_sq_map:
1489 kfree(priv->txq_to_sq_map);
1490 kfree(priv->channel);
1496 static void mlx5e_close_channels(struct mlx5e_priv *priv)
1500 /* FIXME: This is a W/A only for tx timeout watch dog false alarm when
1501 * polling for inactive tx queues.
1503 netif_tx_stop_all_queues(priv->netdev);
1504 netif_tx_disable(priv->netdev);
1506 for (i = 0; i < priv->params.num_channels; i++)
1507 mlx5e_close_channel(priv->channel[i]);
1509 kfree(priv->txq_to_sq_map);
1510 kfree(priv->channel);
1513 static int mlx5e_rx_hash_fn(int hfunc)
1515 return (hfunc == ETH_RSS_HASH_TOP) ?
1516 MLX5_RX_HASH_FN_TOEPLITZ :
1517 MLX5_RX_HASH_FN_INVERTED_XOR8;
1520 static int mlx5e_bits_invert(unsigned long a, int size)
1525 for (i = 0; i < size; i++)
1526 inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1531 static void mlx5e_fill_indir_rqt_rqns(struct mlx5e_priv *priv, void *rqtc)
1535 for (i = 0; i < MLX5E_INDIR_RQT_SIZE; i++) {
1539 if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1540 ix = mlx5e_bits_invert(i, MLX5E_LOG_INDIR_RQT_SIZE);
1542 ix = priv->params.indirection_rqt[ix];
1543 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1544 priv->channel[ix]->rq.rqn :
1546 MLX5_SET(rqtc, rqtc, rq_num[i], rqn);
1550 static void mlx5e_fill_direct_rqt_rqn(struct mlx5e_priv *priv, void *rqtc,
1553 u32 rqn = test_bit(MLX5E_STATE_OPENED, &priv->state) ?
1554 priv->channel[ix]->rq.rqn :
1557 MLX5_SET(rqtc, rqtc, rq_num[0], rqn);
1560 static int mlx5e_create_rqt(struct mlx5e_priv *priv, int sz,
1561 int ix, struct mlx5e_rqt *rqt)
1563 struct mlx5_core_dev *mdev = priv->mdev;
1569 inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
1570 in = mlx5_vzalloc(inlen);
1574 rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1576 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1577 MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
1579 if (sz > 1) /* RSS */
1580 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1582 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1584 err = mlx5_core_create_rqt(mdev, in, inlen, &rqt->rqtn);
1586 rqt->enabled = true;
1592 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt)
1594 rqt->enabled = false;
1595 mlx5_core_destroy_rqt(priv->mdev, rqt->rqtn);
1598 static int mlx5e_create_indirect_rqts(struct mlx5e_priv *priv)
1600 struct mlx5e_rqt *rqt = &priv->indir_rqt;
1602 return mlx5e_create_rqt(priv, MLX5E_INDIR_RQT_SIZE, 0, rqt);
1605 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv)
1607 struct mlx5e_rqt *rqt;
1611 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1612 rqt = &priv->direct_tir[ix].rqt;
1613 err = mlx5e_create_rqt(priv, 1 /*size */, ix, rqt);
1615 goto err_destroy_rqts;
1621 for (ix--; ix >= 0; ix--)
1622 mlx5e_destroy_rqt(priv, &priv->direct_tir[ix].rqt);
1627 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix)
1629 struct mlx5_core_dev *mdev = priv->mdev;
1635 inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + sizeof(u32) * sz;
1636 in = mlx5_vzalloc(inlen);
1640 rqtc = MLX5_ADDR_OF(modify_rqt_in, in, ctx);
1642 MLX5_SET(rqtc, rqtc, rqt_actual_size, sz);
1643 if (sz > 1) /* RSS */
1644 mlx5e_fill_indir_rqt_rqns(priv, rqtc);
1646 mlx5e_fill_direct_rqt_rqn(priv, rqtc, ix);
1648 MLX5_SET(modify_rqt_in, in, bitmask.rqn_list, 1);
1650 err = mlx5_core_modify_rqt(mdev, rqtn, in, inlen);
1657 static void mlx5e_redirect_rqts(struct mlx5e_priv *priv)
1662 if (priv->indir_rqt.enabled) {
1663 rqtn = priv->indir_rqt.rqtn;
1664 mlx5e_redirect_rqt(priv, rqtn, MLX5E_INDIR_RQT_SIZE, 0);
1667 for (ix = 0; ix < priv->params.num_channels; ix++) {
1668 if (!priv->direct_tir[ix].rqt.enabled)
1670 rqtn = priv->direct_tir[ix].rqt.rqtn;
1671 mlx5e_redirect_rqt(priv, rqtn, 1, ix);
1675 static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1677 if (!priv->params.lro_en)
1680 #define ROUGH_MAX_L2_L3_HDR_SZ 256
1682 MLX5_SET(tirc, tirc, lro_enable_mask,
1683 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
1684 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO);
1685 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1686 (priv->params.lro_wqe_sz -
1687 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1688 MLX5_SET(tirc, tirc, lro_timeout_period_usecs,
1689 MLX5_CAP_ETH(priv->mdev,
1690 lro_timer_supported_periods[2]));
1693 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
1695 MLX5_SET(tirc, tirc, rx_hash_fn,
1696 mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1697 if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1698 void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1699 rx_hash_toeplitz_key);
1700 size_t len = MLX5_FLD_SZ_BYTES(tirc,
1701 rx_hash_toeplitz_key);
1703 MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1704 memcpy(rss_key, priv->params.toeplitz_hash_key, len);
1708 static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
1710 struct mlx5_core_dev *mdev = priv->mdev;
1719 inlen = MLX5_ST_SZ_BYTES(modify_tir_in);
1720 in = mlx5_vzalloc(inlen);
1724 MLX5_SET(modify_tir_in, in, bitmask.lro, 1);
1725 tirc = MLX5_ADDR_OF(modify_tir_in, in, ctx);
1727 mlx5e_build_tir_ctx_lro(tirc, priv);
1729 for (tt = 0; tt < MLX5E_NUM_INDIR_TIRS; tt++) {
1730 err = mlx5_core_modify_tir(mdev, priv->indir_tir[tt].tirn, in,
1736 for (ix = 0; ix < priv->profile->max_nch(priv->mdev); ix++) {
1737 err = mlx5_core_modify_tir(mdev, priv->direct_tir[ix].tirn,
1749 static int mlx5e_set_mtu(struct mlx5e_priv *priv, u16 mtu)
1751 struct mlx5_core_dev *mdev = priv->mdev;
1752 u16 hw_mtu = MLX5E_SW2HW_MTU(mtu);
1755 err = mlx5_set_port_mtu(mdev, hw_mtu, 1);
1759 /* Update vport context MTU */
1760 mlx5_modify_nic_vport_mtu(mdev, hw_mtu);
1764 static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
1766 struct mlx5_core_dev *mdev = priv->mdev;
1770 err = mlx5_query_nic_vport_mtu(mdev, &hw_mtu);
1771 if (err || !hw_mtu) /* fallback to port oper mtu */
1772 mlx5_query_port_oper_mtu(mdev, &hw_mtu, 1);
1774 *mtu = MLX5E_HW2SW_MTU(hw_mtu);
1777 static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
1779 struct mlx5e_priv *priv = netdev_priv(netdev);
1783 err = mlx5e_set_mtu(priv, netdev->mtu);
1787 mlx5e_query_mtu(priv, &mtu);
1788 if (mtu != netdev->mtu)
1789 netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
1790 __func__, mtu, netdev->mtu);
1796 static void mlx5e_netdev_set_tcs(struct net_device *netdev)
1798 struct mlx5e_priv *priv = netdev_priv(netdev);
1799 int nch = priv->params.num_channels;
1800 int ntc = priv->params.num_tc;
1803 netdev_reset_tc(netdev);
1808 netdev_set_num_tc(netdev, ntc);
1810 /* Map netdev TCs to offset 0
1811 * We have our own UP to TXQ mapping for QoS
1813 for (tc = 0; tc < ntc; tc++)
1814 netdev_set_tc_queue(netdev, tc, nch, 0);
1817 int mlx5e_open_locked(struct net_device *netdev)
1819 struct mlx5e_priv *priv = netdev_priv(netdev);
1820 struct mlx5_core_dev *mdev = priv->mdev;
1824 set_bit(MLX5E_STATE_OPENED, &priv->state);
1826 mlx5e_netdev_set_tcs(netdev);
1828 num_txqs = priv->params.num_channels * priv->params.num_tc;
1829 netif_set_real_num_tx_queues(netdev, num_txqs);
1830 netif_set_real_num_rx_queues(netdev, priv->params.num_channels);
1832 err = mlx5e_open_channels(priv);
1834 netdev_err(netdev, "%s: mlx5e_open_channels failed, %d\n",
1836 goto err_clear_state_opened_flag;
1839 err = mlx5e_refresh_tirs_self_loopback_enable(priv->mdev);
1841 netdev_err(netdev, "%s: mlx5e_refresh_tirs_self_loopback_enable failed, %d\n",
1843 goto err_close_channels;
1846 mlx5e_redirect_rqts(priv);
1847 mlx5e_update_carrier(priv);
1848 mlx5e_timestamp_init(priv);
1849 #ifdef CONFIG_RFS_ACCEL
1850 priv->netdev->rx_cpu_rmap = priv->mdev->rmap;
1852 if (priv->profile->update_stats)
1853 queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
1855 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
1856 err = mlx5e_add_sqs_fwd_rules(priv);
1858 goto err_close_channels;
1863 mlx5e_close_channels(priv);
1864 err_clear_state_opened_flag:
1865 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1869 int mlx5e_open(struct net_device *netdev)
1871 struct mlx5e_priv *priv = netdev_priv(netdev);
1874 mutex_lock(&priv->state_lock);
1875 err = mlx5e_open_locked(netdev);
1876 mutex_unlock(&priv->state_lock);
1881 int mlx5e_close_locked(struct net_device *netdev)
1883 struct mlx5e_priv *priv = netdev_priv(netdev);
1884 struct mlx5_core_dev *mdev = priv->mdev;
1886 /* May already be CLOSED in case a previous configuration operation
1887 * (e.g RX/TX queue size change) that involves close&open failed.
1889 if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
1892 clear_bit(MLX5E_STATE_OPENED, &priv->state);
1894 if (MLX5_CAP_GEN(mdev, vport_group_manager))
1895 mlx5e_remove_sqs_fwd_rules(priv);
1897 mlx5e_timestamp_cleanup(priv);
1898 netif_carrier_off(priv->netdev);
1899 mlx5e_redirect_rqts(priv);
1900 mlx5e_close_channels(priv);
1905 int mlx5e_close(struct net_device *netdev)
1907 struct mlx5e_priv *priv = netdev_priv(netdev);
1910 mutex_lock(&priv->state_lock);
1911 err = mlx5e_close_locked(netdev);
1912 mutex_unlock(&priv->state_lock);
1917 static int mlx5e_create_drop_rq(struct mlx5e_priv *priv,
1918 struct mlx5e_rq *rq,
1919 struct mlx5e_rq_param *param)
1921 struct mlx5_core_dev *mdev = priv->mdev;
1922 void *rqc = param->rqc;
1923 void *rqc_wq = MLX5_ADDR_OF(rqc, rqc, wq);
1926 param->wq.db_numa_node = param->wq.buf_numa_node;
1928 err = mlx5_wq_ll_create(mdev, ¶m->wq, rqc_wq, &rq->wq,
1938 static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
1939 struct mlx5e_cq *cq,
1940 struct mlx5e_cq_param *param)
1942 struct mlx5_core_dev *mdev = priv->mdev;
1943 struct mlx5_core_cq *mcq = &cq->mcq;
1948 err = mlx5_cqwq_create(mdev, ¶m->wq, param->cqc, &cq->wq,
1953 mlx5_vector2eqn(mdev, param->eq_ix, &eqn_not_used, &irqn);
1956 mcq->set_ci_db = cq->wq_ctrl.db.db;
1957 mcq->arm_db = cq->wq_ctrl.db.db + 1;
1958 *mcq->set_ci_db = 0;
1960 mcq->vector = param->eq_ix;
1961 mcq->comp = mlx5e_completion_event;
1962 mcq->event = mlx5e_cq_error_event;
1964 mcq->uar = &mdev->mlx5e_res.cq_uar;
1971 static int mlx5e_open_drop_rq(struct mlx5e_priv *priv)
1973 struct mlx5e_cq_param cq_param;
1974 struct mlx5e_rq_param rq_param;
1975 struct mlx5e_rq *rq = &priv->drop_rq;
1976 struct mlx5e_cq *cq = &priv->drop_rq.cq;
1979 memset(&cq_param, 0, sizeof(cq_param));
1980 memset(&rq_param, 0, sizeof(rq_param));
1981 mlx5e_build_drop_rq_param(&rq_param);
1983 err = mlx5e_create_drop_cq(priv, cq, &cq_param);
1987 err = mlx5e_enable_cq(cq, &cq_param);
1989 goto err_destroy_cq;
1991 err = mlx5e_create_drop_rq(priv, rq, &rq_param);
1993 goto err_disable_cq;
1995 err = mlx5e_enable_rq(rq, &rq_param);
1997 goto err_destroy_rq;
2002 mlx5e_destroy_rq(&priv->drop_rq);
2005 mlx5e_disable_cq(&priv->drop_rq.cq);
2008 mlx5e_destroy_cq(&priv->drop_rq.cq);
2013 static void mlx5e_close_drop_rq(struct mlx5e_priv *priv)
2015 mlx5e_disable_rq(&priv->drop_rq);
2016 mlx5e_destroy_rq(&priv->drop_rq);
2017 mlx5e_disable_cq(&priv->drop_rq.cq);
2018 mlx5e_destroy_cq(&priv->drop_rq.cq);
2021 static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
2023 struct mlx5_core_dev *mdev = priv->mdev;
2024 u32 in[MLX5_ST_SZ_DW(create_tis_in)];
2025 void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx);
2027 memset(in, 0, sizeof(in));
2029 MLX5_SET(tisc, tisc, prio, tc << 1);
2030 MLX5_SET(tisc, tisc, transport_domain, mdev->mlx5e_res.td.tdn);
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;
2577 mlx5_query_port_max_mtu(mdev, &max_mtu, 1);
2579 max_mtu = MLX5E_HW2SW_MTU(max_mtu);
2580 min_mtu = MLX5E_HW2SW_MTU(MXL5E_MIN_MTU);
2582 if (new_mtu > max_mtu || new_mtu < min_mtu) {
2584 "%s: Bad MTU (%d), valid range is: [%d..%d]\n",
2585 __func__, new_mtu, min_mtu, max_mtu);
2589 mutex_lock(&priv->state_lock);
2591 reset = !priv->params.lro_en &&
2592 (priv->params.rq_wq_type !=
2593 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
2595 was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
2596 if (was_opened && reset)
2597 mlx5e_close_locked(netdev);
2599 netdev->mtu = new_mtu;
2600 mlx5e_set_dev_port_mtu(netdev);
2602 if (was_opened && reset)
2603 err = mlx5e_open_locked(netdev);
2605 mutex_unlock(&priv->state_lock);
2610 static int mlx5e_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2614 return mlx5e_hwstamp_set(dev, ifr);
2616 return mlx5e_hwstamp_get(dev, ifr);
2622 static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2624 struct mlx5e_priv *priv = netdev_priv(dev);
2625 struct mlx5_core_dev *mdev = priv->mdev;
2627 return mlx5_eswitch_set_vport_mac(mdev->priv.eswitch, vf + 1, mac);
2630 static int mlx5e_set_vf_vlan(struct net_device *dev, int vf, u16 vlan, u8 qos)
2632 struct mlx5e_priv *priv = netdev_priv(dev);
2633 struct mlx5_core_dev *mdev = priv->mdev;
2635 return mlx5_eswitch_set_vport_vlan(mdev->priv.eswitch, vf + 1,
2639 static int mlx5e_set_vf_spoofchk(struct net_device *dev, int vf, bool setting)
2641 struct mlx5e_priv *priv = netdev_priv(dev);
2642 struct mlx5_core_dev *mdev = priv->mdev;
2644 return mlx5_eswitch_set_vport_spoofchk(mdev->priv.eswitch, vf + 1, setting);
2647 static int mlx5e_set_vf_trust(struct net_device *dev, int vf, bool setting)
2649 struct mlx5e_priv *priv = netdev_priv(dev);
2650 struct mlx5_core_dev *mdev = priv->mdev;
2652 return mlx5_eswitch_set_vport_trust(mdev->priv.eswitch, vf + 1, setting);
2654 static int mlx5_vport_link2ifla(u8 esw_link)
2657 case MLX5_ESW_VPORT_ADMIN_STATE_DOWN:
2658 return IFLA_VF_LINK_STATE_DISABLE;
2659 case MLX5_ESW_VPORT_ADMIN_STATE_UP:
2660 return IFLA_VF_LINK_STATE_ENABLE;
2662 return IFLA_VF_LINK_STATE_AUTO;
2665 static int mlx5_ifla_link2vport(u8 ifla_link)
2667 switch (ifla_link) {
2668 case IFLA_VF_LINK_STATE_DISABLE:
2669 return MLX5_ESW_VPORT_ADMIN_STATE_DOWN;
2670 case IFLA_VF_LINK_STATE_ENABLE:
2671 return MLX5_ESW_VPORT_ADMIN_STATE_UP;
2673 return MLX5_ESW_VPORT_ADMIN_STATE_AUTO;
2676 static int mlx5e_set_vf_link_state(struct net_device *dev, int vf,
2679 struct mlx5e_priv *priv = netdev_priv(dev);
2680 struct mlx5_core_dev *mdev = priv->mdev;
2682 return mlx5_eswitch_set_vport_state(mdev->priv.eswitch, vf + 1,
2683 mlx5_ifla_link2vport(link_state));
2686 static int mlx5e_get_vf_config(struct net_device *dev,
2687 int vf, struct ifla_vf_info *ivi)
2689 struct mlx5e_priv *priv = netdev_priv(dev);
2690 struct mlx5_core_dev *mdev = priv->mdev;
2693 err = mlx5_eswitch_get_vport_config(mdev->priv.eswitch, vf + 1, ivi);
2696 ivi->linkstate = mlx5_vport_link2ifla(ivi->linkstate);
2700 static int mlx5e_get_vf_stats(struct net_device *dev,
2701 int vf, struct ifla_vf_stats *vf_stats)
2703 struct mlx5e_priv *priv = netdev_priv(dev);
2704 struct mlx5_core_dev *mdev = priv->mdev;
2706 return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
2710 static void mlx5e_add_vxlan_port(struct net_device *netdev,
2711 struct udp_tunnel_info *ti)
2713 struct mlx5e_priv *priv = netdev_priv(netdev);
2715 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2718 if (!mlx5e_vxlan_allowed(priv->mdev))
2721 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 1);
2724 static void mlx5e_del_vxlan_port(struct net_device *netdev,
2725 struct udp_tunnel_info *ti)
2727 struct mlx5e_priv *priv = netdev_priv(netdev);
2729 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2732 if (!mlx5e_vxlan_allowed(priv->mdev))
2735 mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 0);
2738 static netdev_features_t mlx5e_vxlan_features_check(struct mlx5e_priv *priv,
2739 struct sk_buff *skb,
2740 netdev_features_t features)
2742 struct udphdr *udph;
2746 switch (vlan_get_protocol(skb)) {
2747 case htons(ETH_P_IP):
2748 proto = ip_hdr(skb)->protocol;
2750 case htons(ETH_P_IPV6):
2751 proto = ipv6_hdr(skb)->nexthdr;
2757 if (proto == IPPROTO_UDP) {
2758 udph = udp_hdr(skb);
2759 port = be16_to_cpu(udph->dest);
2762 /* Verify if UDP port is being offloaded by HW */
2763 if (port && mlx5e_vxlan_lookup_port(priv, port))
2767 /* Disable CSUM and GSO if the udp dport is not offloaded by HW */
2768 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2771 static netdev_features_t mlx5e_features_check(struct sk_buff *skb,
2772 struct net_device *netdev,
2773 netdev_features_t features)
2775 struct mlx5e_priv *priv = netdev_priv(netdev);
2777 features = vlan_features_check(skb, features);
2778 features = vxlan_features_check(skb, features);
2780 /* Validate if the tunneled packet is being offloaded by HW */
2781 if (skb->encapsulation &&
2782 (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
2783 return mlx5e_vxlan_features_check(priv, skb, features);
2788 static void mlx5e_tx_timeout(struct net_device *dev)
2790 struct mlx5e_priv *priv = netdev_priv(dev);
2791 bool sched_work = false;
2794 netdev_err(dev, "TX timeout detected\n");
2796 for (i = 0; i < priv->params.num_channels * priv->params.num_tc; i++) {
2797 struct mlx5e_sq *sq = priv->txq_to_sq_map[i];
2799 if (!netif_xmit_stopped(netdev_get_tx_queue(dev, i)))
2802 set_bit(MLX5E_SQ_STATE_TX_TIMEOUT, &sq->state);
2803 netdev_err(dev, "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x\n",
2804 i, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc);
2807 if (sched_work && test_bit(MLX5E_STATE_OPENED, &priv->state))
2808 schedule_work(&priv->tx_timeout_work);
2811 static const struct net_device_ops mlx5e_netdev_ops_basic = {
2812 .ndo_open = mlx5e_open,
2813 .ndo_stop = mlx5e_close,
2814 .ndo_start_xmit = mlx5e_xmit,
2815 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2816 .ndo_select_queue = mlx5e_select_queue,
2817 .ndo_get_stats64 = mlx5e_get_stats,
2818 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2819 .ndo_set_mac_address = mlx5e_set_mac,
2820 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2821 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2822 .ndo_set_features = mlx5e_set_features,
2823 .ndo_change_mtu = mlx5e_change_mtu,
2824 .ndo_do_ioctl = mlx5e_ioctl,
2825 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2826 #ifdef CONFIG_RFS_ACCEL
2827 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2829 .ndo_tx_timeout = mlx5e_tx_timeout,
2832 static const struct net_device_ops mlx5e_netdev_ops_sriov = {
2833 .ndo_open = mlx5e_open,
2834 .ndo_stop = mlx5e_close,
2835 .ndo_start_xmit = mlx5e_xmit,
2836 .ndo_setup_tc = mlx5e_ndo_setup_tc,
2837 .ndo_select_queue = mlx5e_select_queue,
2838 .ndo_get_stats64 = mlx5e_get_stats,
2839 .ndo_set_rx_mode = mlx5e_set_rx_mode,
2840 .ndo_set_mac_address = mlx5e_set_mac,
2841 .ndo_vlan_rx_add_vid = mlx5e_vlan_rx_add_vid,
2842 .ndo_vlan_rx_kill_vid = mlx5e_vlan_rx_kill_vid,
2843 .ndo_set_features = mlx5e_set_features,
2844 .ndo_change_mtu = mlx5e_change_mtu,
2845 .ndo_do_ioctl = mlx5e_ioctl,
2846 .ndo_udp_tunnel_add = mlx5e_add_vxlan_port,
2847 .ndo_udp_tunnel_del = mlx5e_del_vxlan_port,
2848 .ndo_set_tx_maxrate = mlx5e_set_tx_maxrate,
2849 .ndo_features_check = mlx5e_features_check,
2850 #ifdef CONFIG_RFS_ACCEL
2851 .ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2853 .ndo_set_vf_mac = mlx5e_set_vf_mac,
2854 .ndo_set_vf_vlan = mlx5e_set_vf_vlan,
2855 .ndo_set_vf_spoofchk = mlx5e_set_vf_spoofchk,
2856 .ndo_set_vf_trust = mlx5e_set_vf_trust,
2857 .ndo_get_vf_config = mlx5e_get_vf_config,
2858 .ndo_set_vf_link_state = mlx5e_set_vf_link_state,
2859 .ndo_get_vf_stats = mlx5e_get_vf_stats,
2860 .ndo_tx_timeout = mlx5e_tx_timeout,
2863 static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
2865 if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
2867 if (!MLX5_CAP_GEN(mdev, eth_net_offloads) ||
2868 !MLX5_CAP_GEN(mdev, nic_flow_table) ||
2869 !MLX5_CAP_ETH(mdev, csum_cap) ||
2870 !MLX5_CAP_ETH(mdev, max_lso_cap) ||
2871 !MLX5_CAP_ETH(mdev, vlan_cap) ||
2872 !MLX5_CAP_ETH(mdev, rss_ind_tbl_cap) ||
2873 MLX5_CAP_FLOWTABLE(mdev,
2874 flow_table_properties_nic_receive.max_ft_level)
2876 mlx5_core_warn(mdev,
2877 "Not creating net device, some required device capabilities are missing\n");
2880 if (!MLX5_CAP_ETH(mdev, self_lb_en_modifiable))
2881 mlx5_core_warn(mdev, "Self loop back prevention is not supported\n");
2882 if (!MLX5_CAP_GEN(mdev, cq_moderation))
2883 mlx5_core_warn(mdev, "CQ modiration is not supported\n");
2888 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev)
2890 int bf_buf_size = (1 << MLX5_CAP_GEN(mdev, log_bf_reg_size)) / 2;
2892 return bf_buf_size -
2893 sizeof(struct mlx5e_tx_wqe) +
2894 2 /*sizeof(mlx5e_tx_wqe.inline_hdr_start)*/;
2897 #ifdef CONFIG_MLX5_CORE_EN_DCB
2898 static void mlx5e_ets_init(struct mlx5e_priv *priv)
2902 priv->params.ets.ets_cap = mlx5_max_tc(priv->mdev) + 1;
2903 for (i = 0; i < priv->params.ets.ets_cap; i++) {
2904 priv->params.ets.tc_tx_bw[i] = MLX5E_MAX_BW_ALLOC;
2905 priv->params.ets.tc_tsa[i] = IEEE_8021QAZ_TSA_VENDOR;
2906 priv->params.ets.prio_tc[i] = i;
2909 /* tclass[prio=0]=1, tclass[prio=1]=0, tclass[prio=i]=i (for i>1) */
2910 priv->params.ets.prio_tc[0] = 1;
2911 priv->params.ets.prio_tc[1] = 0;
2915 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
2916 u32 *indirection_rqt, int len,
2919 int node = mdev->priv.numa_node;
2920 int node_num_of_cores;
2924 node = first_online_node;
2926 node_num_of_cores = cpumask_weight(cpumask_of_node(node));
2928 if (node_num_of_cores)
2929 num_channels = min_t(int, num_channels, node_num_of_cores);
2931 for (i = 0; i < len; i++)
2932 indirection_rqt[i] = i % num_channels;
2935 static bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
2937 return MLX5_CAP_GEN(mdev, striding_rq) &&
2938 MLX5_CAP_GEN(mdev, umr_ptr_rlky) &&
2939 MLX5_CAP_ETH(mdev, reg_umr_sq);
2942 static int mlx5e_get_pci_bw(struct mlx5_core_dev *mdev, u32 *pci_bw)
2944 enum pcie_link_width width;
2945 enum pci_bus_speed speed;
2948 err = pcie_get_minimum_link(mdev->pdev, &speed, &width);
2952 if (speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
2956 case PCIE_SPEED_2_5GT:
2957 *pci_bw = 2500 * width;
2959 case PCIE_SPEED_5_0GT:
2960 *pci_bw = 5000 * width;
2962 case PCIE_SPEED_8_0GT:
2963 *pci_bw = 8000 * width;
2972 static bool cqe_compress_heuristic(u32 link_speed, u32 pci_bw)
2974 return (link_speed && pci_bw &&
2975 (pci_bw < 40000) && (pci_bw < link_speed));
2978 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode)
2980 params->rx_cq_period_mode = cq_period_mode;
2982 params->rx_cq_moderation.pkts =
2983 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS;
2984 params->rx_cq_moderation.usec =
2985 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC;
2987 if (cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE)
2988 params->rx_cq_moderation.usec =
2989 MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE;
2992 static void mlx5e_query_min_inline(struct mlx5_core_dev *mdev,
2993 u8 *min_inline_mode)
2995 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
2996 case MLX5E_INLINE_MODE_L2:
2997 *min_inline_mode = MLX5_INLINE_MODE_L2;
2999 case MLX5E_INLINE_MODE_VPORT_CONTEXT:
3000 mlx5_query_nic_vport_min_inline(mdev,
3003 case MLX5_INLINE_MODE_NOT_REQUIRED:
3004 *min_inline_mode = MLX5_INLINE_MODE_NONE;
3009 static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
3010 struct net_device *netdev,
3011 const struct mlx5e_profile *profile,
3014 struct mlx5e_priv *priv = netdev_priv(netdev);
3017 u8 cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ?
3018 MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
3019 MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
3021 priv->params.log_sq_size =
3022 MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
3023 priv->params.rq_wq_type = mlx5e_check_fragmented_striding_rq_cap(mdev) ?
3024 MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
3025 MLX5_WQ_TYPE_LINKED_LIST;
3027 /* set CQE compression */
3028 priv->params.rx_cqe_compress_admin = false;
3029 if (MLX5_CAP_GEN(mdev, cqe_compression) &&
3030 MLX5_CAP_GEN(mdev, vport_group_manager)) {
3031 mlx5e_get_max_linkspeed(mdev, &link_speed);
3032 mlx5e_get_pci_bw(mdev, &pci_bw);
3033 mlx5_core_dbg(mdev, "Max link speed = %d, PCI BW = %d\n",
3034 link_speed, pci_bw);
3035 priv->params.rx_cqe_compress_admin =
3036 cqe_compress_heuristic(link_speed, pci_bw);
3039 priv->params.rx_cqe_compress = priv->params.rx_cqe_compress_admin;
3041 switch (priv->params.rq_wq_type) {
3042 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
3043 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW;
3044 priv->params.mpwqe_log_stride_sz =
3045 priv->params.rx_cqe_compress ?
3046 MLX5_MPWRQ_LOG_STRIDE_SIZE_CQE_COMPRESS :
3047 MLX5_MPWRQ_LOG_STRIDE_SIZE;
3048 priv->params.mpwqe_log_num_strides = MLX5_MPWRQ_LOG_WQE_SZ -
3049 priv->params.mpwqe_log_stride_sz;
3050 priv->params.lro_en = true;
3052 default: /* MLX5_WQ_TYPE_LINKED_LIST */
3053 priv->params.log_rq_size = MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
3056 mlx5_core_info(mdev,
3057 "MLX5E: StrdRq(%d) RqSz(%ld) StrdSz(%ld) RxCqeCmprss(%d)\n",
3058 priv->params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ,
3059 BIT(priv->params.log_rq_size),
3060 BIT(priv->params.mpwqe_log_stride_sz),
3061 priv->params.rx_cqe_compress_admin);
3063 priv->params.min_rx_wqes = mlx5_min_rx_wqes(priv->params.rq_wq_type,
3064 BIT(priv->params.log_rq_size));
3066 priv->params.rx_am_enabled = MLX5_CAP_GEN(mdev, cq_moderation);
3067 mlx5e_set_rx_cq_mode_params(&priv->params, cq_period_mode);
3069 priv->params.tx_cq_moderation.usec =
3070 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC;
3071 priv->params.tx_cq_moderation.pkts =
3072 MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS;
3073 priv->params.tx_max_inline = mlx5e_get_max_inline_cap(mdev);
3074 mlx5e_query_min_inline(mdev, &priv->params.tx_min_inline_mode);
3075 priv->params.num_tc = 1;
3076 priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
3078 netdev_rss_key_fill(priv->params.toeplitz_hash_key,
3079 sizeof(priv->params.toeplitz_hash_key));
3081 mlx5e_build_default_indir_rqt(mdev, priv->params.indirection_rqt,
3082 MLX5E_INDIR_RQT_SIZE, profile->max_nch(mdev));
3084 priv->params.lro_wqe_sz =
3085 MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
3087 /* Initialize pflags */
3088 MLX5E_SET_PRIV_FLAG(priv, MLX5E_PFLAG_RX_CQE_BASED_MODER,
3089 priv->params.rx_cq_period_mode == MLX5_CQ_PERIOD_MODE_START_FROM_CQE);
3092 priv->netdev = netdev;
3093 priv->params.num_channels = profile->max_nch(mdev);
3094 priv->profile = profile;
3095 priv->ppriv = ppriv;
3097 #ifdef CONFIG_MLX5_CORE_EN_DCB
3098 mlx5e_ets_init(priv);
3101 mutex_init(&priv->state_lock);
3103 INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
3104 INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
3105 INIT_WORK(&priv->tx_timeout_work, mlx5e_tx_timeout_work);
3106 INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
3109 static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
3111 struct mlx5e_priv *priv = netdev_priv(netdev);
3113 mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
3114 if (is_zero_ether_addr(netdev->dev_addr) &&
3115 !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
3116 eth_hw_addr_random(netdev);
3117 mlx5_core_info(priv->mdev, "Assigned random MAC address %pM\n", netdev->dev_addr);
3121 static const struct switchdev_ops mlx5e_switchdev_ops = {
3122 .switchdev_port_attr_get = mlx5e_attr_get,
3125 static void mlx5e_build_nic_netdev(struct net_device *netdev)
3127 struct mlx5e_priv *priv = netdev_priv(netdev);
3128 struct mlx5_core_dev *mdev = priv->mdev;
3132 SET_NETDEV_DEV(netdev, &mdev->pdev->dev);
3134 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3135 netdev->netdev_ops = &mlx5e_netdev_ops_sriov;
3136 #ifdef CONFIG_MLX5_CORE_EN_DCB
3137 netdev->dcbnl_ops = &mlx5e_dcbnl_ops;
3140 netdev->netdev_ops = &mlx5e_netdev_ops_basic;
3143 netdev->watchdog_timeo = 15 * HZ;
3145 netdev->ethtool_ops = &mlx5e_ethtool_ops;
3147 netdev->vlan_features |= NETIF_F_SG;
3148 netdev->vlan_features |= NETIF_F_IP_CSUM;
3149 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
3150 netdev->vlan_features |= NETIF_F_GRO;
3151 netdev->vlan_features |= NETIF_F_TSO;
3152 netdev->vlan_features |= NETIF_F_TSO6;
3153 netdev->vlan_features |= NETIF_F_RXCSUM;
3154 netdev->vlan_features |= NETIF_F_RXHASH;
3156 if (!!MLX5_CAP_ETH(mdev, lro_cap))
3157 netdev->vlan_features |= NETIF_F_LRO;
3159 netdev->hw_features = netdev->vlan_features;
3160 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX;
3161 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
3162 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
3164 if (mlx5e_vxlan_allowed(mdev)) {
3165 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL |
3166 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3167 NETIF_F_GSO_PARTIAL;
3168 netdev->hw_enc_features |= NETIF_F_IP_CSUM;
3169 netdev->hw_enc_features |= NETIF_F_IPV6_CSUM;
3170 netdev->hw_enc_features |= NETIF_F_TSO;
3171 netdev->hw_enc_features |= NETIF_F_TSO6;
3172 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL;
3173 netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3174 NETIF_F_GSO_PARTIAL;
3175 netdev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM;
3178 mlx5_query_port_fcs(mdev, &fcs_supported, &fcs_enabled);
3181 netdev->hw_features |= NETIF_F_RXALL;
3183 netdev->features = netdev->hw_features;
3184 if (!priv->params.lro_en)
3185 netdev->features &= ~NETIF_F_LRO;
3188 netdev->features &= ~NETIF_F_RXALL;
3190 #define FT_CAP(f) MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive.f)
3191 if (FT_CAP(flow_modify_en) &&
3192 FT_CAP(modify_root) &&
3193 FT_CAP(identified_miss_table_mode) &&
3194 FT_CAP(flow_table_modify)) {
3195 netdev->hw_features |= NETIF_F_HW_TC;
3196 #ifdef CONFIG_RFS_ACCEL
3197 netdev->hw_features |= NETIF_F_NTUPLE;
3201 netdev->features |= NETIF_F_HIGHDMA;
3203 netdev->priv_flags |= IFF_UNICAST_FLT;
3205 mlx5e_set_netdev_dev_addr(netdev);
3207 #ifdef CONFIG_NET_SWITCHDEV
3208 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3209 netdev->switchdev_ops = &mlx5e_switchdev_ops;
3213 static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
3215 struct mlx5_core_dev *mdev = priv->mdev;
3218 err = mlx5_core_alloc_q_counter(mdev, &priv->q_counter);
3220 mlx5_core_warn(mdev, "alloc queue counter failed, %d\n", err);
3221 priv->q_counter = 0;
3225 static void mlx5e_destroy_q_counter(struct mlx5e_priv *priv)
3227 if (!priv->q_counter)
3230 mlx5_core_dealloc_q_counter(priv->mdev, priv->q_counter);
3233 static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
3235 struct mlx5_core_dev *mdev = priv->mdev;
3236 struct mlx5_create_mkey_mbox_in *in;
3237 struct mlx5_mkey_seg *mkc;
3238 int inlen = sizeof(*in);
3239 u64 npages = MLX5E_REQUIRED_MTTS(priv->profile->max_nch(mdev),
3240 BIT(MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW));
3243 in = mlx5_vzalloc(inlen);
3248 mkc->status = MLX5_MKEY_STATUS_FREE;
3249 mkc->flags = MLX5_PERM_UMR_EN |
3250 MLX5_PERM_LOCAL_READ |
3251 MLX5_PERM_LOCAL_WRITE |
3252 MLX5_ACCESS_MODE_MTT;
3254 npages = min_t(u32, ALIGN(U16_MAX, 4) * 2, npages);
3256 mkc->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
3257 mkc->flags_pd = cpu_to_be32(mdev->mlx5e_res.pdn);
3258 mkc->len = cpu_to_be64(npages << PAGE_SHIFT);
3259 mkc->xlt_oct_size = cpu_to_be32(MLX5_MTT_OCTW(npages));
3260 mkc->log2_page_size = PAGE_SHIFT;
3262 err = mlx5_core_create_mkey(mdev, &priv->umr_mkey, in, inlen, NULL,
3270 static void mlx5e_nic_init(struct mlx5_core_dev *mdev,
3271 struct net_device *netdev,
3272 const struct mlx5e_profile *profile,
3275 struct mlx5e_priv *priv = netdev_priv(netdev);
3277 mlx5e_build_nic_netdev_priv(mdev, netdev, profile, ppriv);
3278 mlx5e_build_nic_netdev(netdev);
3279 mlx5e_vxlan_init(priv);
3282 static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
3284 struct mlx5_core_dev *mdev = priv->mdev;
3285 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3287 mlx5e_vxlan_cleanup(priv);
3289 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3290 mlx5_eswitch_unregister_vport_rep(esw, 0);
3293 static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
3295 struct mlx5_core_dev *mdev = priv->mdev;
3299 err = mlx5e_create_indirect_rqts(priv);
3301 mlx5_core_warn(mdev, "create indirect rqts failed, %d\n", err);
3305 err = mlx5e_create_direct_rqts(priv);
3307 mlx5_core_warn(mdev, "create direct rqts failed, %d\n", err);
3308 goto err_destroy_indirect_rqts;
3311 err = mlx5e_create_indirect_tirs(priv);
3313 mlx5_core_warn(mdev, "create indirect tirs failed, %d\n", err);
3314 goto err_destroy_direct_rqts;
3317 err = mlx5e_create_direct_tirs(priv);
3319 mlx5_core_warn(mdev, "create direct tirs failed, %d\n", err);
3320 goto err_destroy_indirect_tirs;
3323 err = mlx5e_create_flow_steering(priv);
3325 mlx5_core_warn(mdev, "create flow steering failed, %d\n", err);
3326 goto err_destroy_direct_tirs;
3329 err = mlx5e_tc_init(priv);
3331 goto err_destroy_flow_steering;
3335 err_destroy_flow_steering:
3336 mlx5e_destroy_flow_steering(priv);
3337 err_destroy_direct_tirs:
3338 mlx5e_destroy_direct_tirs(priv);
3339 err_destroy_indirect_tirs:
3340 mlx5e_destroy_indirect_tirs(priv);
3341 err_destroy_direct_rqts:
3342 for (i = 0; i < priv->profile->max_nch(mdev); i++)
3343 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3344 err_destroy_indirect_rqts:
3345 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3349 static void mlx5e_cleanup_nic_rx(struct mlx5e_priv *priv)
3353 mlx5e_tc_cleanup(priv);
3354 mlx5e_destroy_flow_steering(priv);
3355 mlx5e_destroy_direct_tirs(priv);
3356 mlx5e_destroy_indirect_tirs(priv);
3357 for (i = 0; i < priv->profile->max_nch(priv->mdev); i++)
3358 mlx5e_destroy_rqt(priv, &priv->direct_tir[i].rqt);
3359 mlx5e_destroy_rqt(priv, &priv->indir_rqt);
3362 static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
3366 err = mlx5e_create_tises(priv);
3368 mlx5_core_warn(priv->mdev, "create tises failed, %d\n", err);
3372 #ifdef CONFIG_MLX5_CORE_EN_DCB
3373 mlx5e_dcbnl_ieee_setets_core(priv, &priv->params.ets);
3378 static void mlx5e_nic_enable(struct mlx5e_priv *priv)
3380 struct net_device *netdev = priv->netdev;
3381 struct mlx5_core_dev *mdev = priv->mdev;
3382 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3383 struct mlx5_eswitch_rep rep;
3385 if (mlx5e_vxlan_allowed(mdev)) {
3387 udp_tunnel_get_rx_info(netdev);
3391 mlx5e_enable_async_events(priv);
3392 queue_work(priv->wq, &priv->set_rx_mode_work);
3394 if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3395 mlx5_query_nic_vport_mac_address(mdev, 0, rep.hw_id);
3396 rep.load = mlx5e_nic_rep_load;
3397 rep.unload = mlx5e_nic_rep_unload;
3399 rep.priv_data = priv;
3400 mlx5_eswitch_register_vport_rep(esw, &rep);
3404 static void mlx5e_nic_disable(struct mlx5e_priv *priv)
3406 queue_work(priv->wq, &priv->set_rx_mode_work);
3407 mlx5e_disable_async_events(priv);
3410 static const struct mlx5e_profile mlx5e_nic_profile = {
3411 .init = mlx5e_nic_init,
3412 .cleanup = mlx5e_nic_cleanup,
3413 .init_rx = mlx5e_init_nic_rx,
3414 .cleanup_rx = mlx5e_cleanup_nic_rx,
3415 .init_tx = mlx5e_init_nic_tx,
3416 .cleanup_tx = mlx5e_cleanup_nic_tx,
3417 .enable = mlx5e_nic_enable,
3418 .disable = mlx5e_nic_disable,
3419 .update_stats = mlx5e_update_stats,
3420 .max_nch = mlx5e_get_max_num_channels,
3421 .max_tc = MLX5E_MAX_NUM_TC,
3424 void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
3425 const struct mlx5e_profile *profile, void *ppriv)
3427 struct net_device *netdev;
3428 struct mlx5e_priv *priv;
3429 int nch = profile->max_nch(mdev);
3432 netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
3433 nch * profile->max_tc,
3436 mlx5_core_err(mdev, "alloc_etherdev_mqs() failed\n");
3440 profile->init(mdev, netdev, profile, ppriv);
3442 netif_carrier_off(netdev);
3444 priv = netdev_priv(netdev);
3446 priv->wq = create_singlethread_workqueue("mlx5e");
3448 goto err_free_netdev;
3450 err = mlx5e_create_umr_mkey(priv);
3452 mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
3453 goto err_destroy_wq;
3456 err = profile->init_tx(priv);
3458 goto err_destroy_umr_mkey;
3460 err = mlx5e_open_drop_rq(priv);
3462 mlx5_core_err(mdev, "open drop rq failed, %d\n", err);
3463 goto err_cleanup_tx;
3466 err = profile->init_rx(priv);
3468 goto err_close_drop_rq;
3470 mlx5e_create_q_counter(priv);
3472 mlx5e_init_l2_addr(priv);
3474 mlx5e_set_dev_port_mtu(netdev);
3476 err = register_netdev(netdev);
3478 mlx5_core_err(mdev, "register_netdev failed, %d\n", err);
3479 goto err_dealloc_q_counters;
3482 if (profile->enable)
3483 profile->enable(priv);
3487 err_dealloc_q_counters:
3488 mlx5e_destroy_q_counter(priv);
3489 profile->cleanup_rx(priv);
3492 mlx5e_close_drop_rq(priv);
3495 profile->cleanup_tx(priv);
3497 err_destroy_umr_mkey:
3498 mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
3501 destroy_workqueue(priv->wq);
3504 free_netdev(netdev);
3509 static void mlx5e_register_vport_rep(struct mlx5_core_dev *mdev)
3511 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3512 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3516 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
3519 mlx5_query_nic_vport_mac_address(mdev, 0, mac);
3521 for (vport = 1; vport < total_vfs; vport++) {
3522 struct mlx5_eswitch_rep rep;
3524 rep.load = mlx5e_vport_rep_load;
3525 rep.unload = mlx5e_vport_rep_unload;
3527 ether_addr_copy(rep.hw_id, mac);
3528 mlx5_eswitch_register_vport_rep(esw, &rep);
3532 static void *mlx5e_add(struct mlx5_core_dev *mdev)
3534 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3538 if (mlx5e_check_required_hca_cap(mdev))
3541 if (mlx5e_create_mdev_resources(mdev))
3544 mlx5e_register_vport_rep(mdev);
3546 if (MLX5_CAP_GEN(mdev, vport_group_manager))
3547 ppriv = &esw->offloads.vport_reps[0];
3549 ret = mlx5e_create_netdev(mdev, &mlx5e_nic_profile, ppriv);
3551 mlx5e_destroy_mdev_resources(mdev);
3557 void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
3559 const struct mlx5e_profile *profile = priv->profile;
3560 struct net_device *netdev = priv->netdev;
3562 set_bit(MLX5E_STATE_DESTROYING, &priv->state);
3563 if (profile->disable)
3564 profile->disable(priv);
3566 flush_workqueue(priv->wq);
3567 if (test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state)) {
3568 netif_device_detach(netdev);
3569 mlx5e_close(netdev);
3571 unregister_netdev(netdev);
3574 mlx5e_destroy_q_counter(priv);
3575 profile->cleanup_rx(priv);
3576 mlx5e_close_drop_rq(priv);
3577 profile->cleanup_tx(priv);
3578 mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
3579 cancel_delayed_work_sync(&priv->update_stats_work);
3580 destroy_workqueue(priv->wq);
3581 if (profile->cleanup)
3582 profile->cleanup(priv);
3584 if (!test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state))
3585 free_netdev(netdev);
3588 static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
3590 struct mlx5_eswitch *esw = mdev->priv.eswitch;
3591 int total_vfs = MLX5_TOTAL_VPORTS(mdev);
3592 struct mlx5e_priv *priv = vpriv;
3595 mlx5e_destroy_netdev(mdev, priv);
3597 for (vport = 1; vport < total_vfs; vport++)
3598 mlx5_eswitch_unregister_vport_rep(esw, vport);
3600 mlx5e_destroy_mdev_resources(mdev);
3603 static void *mlx5e_get_netdev(void *vpriv)
3605 struct mlx5e_priv *priv = vpriv;
3607 return priv->netdev;
3610 static struct mlx5_interface mlx5e_interface = {
3612 .remove = mlx5e_remove,
3613 .event = mlx5e_async_event,
3614 .protocol = MLX5_INTERFACE_PROTOCOL_ETH,
3615 .get_dev = mlx5e_get_netdev,
3618 void mlx5e_init(void)
3620 mlx5e_build_ptys2ethtool_map();
3621 mlx5_register_interface(&mlx5e_interface);
3624 void mlx5e_cleanup(void)
3626 mlx5_unregister_interface(&mlx5e_interface);