Skip to content

Commit b50d292

Browse files
hadarhenziondavem330
authored andcommitted
net/mlx5e: Create NIC global resources only once
To allow creating more than one netdev over the same PCI function, we change the driver such that global NIC resources are created once and later be shared amongst all the mlx5e netdevs running over that port. Move the CQ UAR, PD (pdn), Transport Domain (tdn), MKey resources from being kept in the mlx5e priv part to a new resources structure (mlx5e_resources) placed under the mlx5_core device. This patch doesn't add any new functionality. Signed-off-by: Hadar Hen Zion <[email protected]> Reviewed-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c930a3a commit b50d292

File tree

5 files changed

+171
-90
lines changed

5 files changed

+171
-90
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
66
fs_counters.o rl.o
77

88
mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o eswitch_offloads.o \
9-
en_main.o en_fs.o en_ethtool.o en_tx.o en_rx.o \
10-
en_rx_am.o en_txrx.o en_clock.o vxlan.o en_tc.o \
11-
en_arfs.o
9+
en_main.o en_common.o en_fs.o en_ethtool.o en_tx.o \
10+
en_rx.o en_rx_am.o en_txrx.o en_clock.o vxlan.o \
11+
en_tc.o en_arfs.o
1212

1313
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,6 @@ struct mlx5e_priv {
570570

571571
unsigned long state;
572572
struct mutex state_lock; /* Protects Interface state */
573-
struct mlx5_uar cq_uar;
574-
u32 pdn;
575-
u32 tdn;
576-
struct mlx5_core_mkey mkey;
577573
struct mlx5_core_mkey umr_mkey;
578574
struct mlx5e_rq drop_rq;
579575

@@ -788,5 +784,7 @@ int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
788784
#endif
789785

790786
u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
787+
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
788+
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
791789

792790
#endif /* __MLX5_EN_H__ */
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3+
*
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:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
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.
22+
*
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
30+
* SOFTWARE.
31+
*/
32+
33+
#include "en.h"
34+
35+
/* mlx5e global resources should be placed in this file.
36+
* Global resources are common to all the netdevices crated on the same nic.
37+
*/
38+
39+
static int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn,
40+
struct mlx5_core_mkey *mkey)
41+
{
42+
struct mlx5_create_mkey_mbox_in *in;
43+
int err;
44+
45+
in = mlx5_vzalloc(sizeof(*in));
46+
if (!in)
47+
return -ENOMEM;
48+
49+
in->seg.flags = MLX5_PERM_LOCAL_WRITE |
50+
MLX5_PERM_LOCAL_READ |
51+
MLX5_ACCESS_MODE_PA;
52+
in->seg.flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64);
53+
in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
54+
55+
err = mlx5_core_create_mkey(mdev, mkey, in, sizeof(*in), NULL, NULL,
56+
NULL);
57+
58+
kvfree(in);
59+
60+
return err;
61+
}
62+
63+
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev)
64+
{
65+
struct mlx5e_resources *res = &mdev->mlx5e_res;
66+
int err;
67+
68+
err = mlx5_alloc_map_uar(mdev, &res->cq_uar, false);
69+
if (err) {
70+
mlx5_core_err(mdev, "alloc_map uar failed, %d\n", err);
71+
return err;
72+
}
73+
74+
err = mlx5_core_alloc_pd(mdev, &res->pdn);
75+
if (err) {
76+
mlx5_core_err(mdev, "alloc pd failed, %d\n", err);
77+
goto err_unmap_free_uar;
78+
}
79+
80+
err = mlx5_core_alloc_transport_domain(mdev, &res->td.tdn);
81+
if (err) {
82+
mlx5_core_err(mdev, "alloc td failed, %d\n", err);
83+
goto err_dealloc_pd;
84+
}
85+
86+
err = mlx5e_create_mkey(mdev, res->pdn, &res->mkey);
87+
if (err) {
88+
mlx5_core_err(mdev, "create mkey failed, %d\n", err);
89+
goto err_dealloc_transport_domain;
90+
}
91+
92+
return 0;
93+
94+
err_dealloc_transport_domain:
95+
mlx5_core_dealloc_transport_domain(mdev, res->td.tdn);
96+
err_dealloc_pd:
97+
mlx5_core_dealloc_pd(mdev, res->pdn);
98+
err_unmap_free_uar:
99+
mlx5_unmap_free_uar(mdev, &res->cq_uar);
100+
101+
return err;
102+
}
103+
104+
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev)
105+
{
106+
struct mlx5e_resources *res = &mdev->mlx5e_res;
107+
108+
mlx5_core_destroy_mkey(mdev, &res->mkey);
109+
mlx5_core_dealloc_transport_domain(mdev, res->td.tdn);
110+
mlx5_core_dealloc_pd(mdev, res->pdn);
111+
mlx5_unmap_free_uar(mdev, &res->cq_uar);
112+
}

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static int mlx5e_create_cq(struct mlx5e_channel *c,
858858
mcq->comp = mlx5e_completion_event;
859859
mcq->event = mlx5e_cq_error_event;
860860
mcq->irqn = irqn;
861-
mcq->uar = &priv->cq_uar;
861+
mcq->uar = &mdev->mlx5e_res.cq_uar;
862862

863863
for (i = 0; i < mlx5_cqwq_get_size(&cq->wq); i++) {
864864
struct mlx5_cqe64 *cqe = mlx5_cqwq_get_wqe(&cq->wq, i);
@@ -1136,7 +1136,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
11361136
c->cpu = cpu;
11371137
c->pdev = &priv->mdev->pdev->dev;
11381138
c->netdev = priv->netdev;
1139-
c->mkey_be = cpu_to_be32(priv->mkey.key);
1139+
c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
11401140
c->num_tc = priv->params.num_tc;
11411141

11421142
if (priv->params.rx_am_enabled)
@@ -1252,7 +1252,7 @@ static void mlx5e_build_rq_param(struct mlx5e_priv *priv,
12521252
MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN);
12531253
MLX5_SET(wq, wq, log_wq_stride, ilog2(sizeof(struct mlx5e_rx_wqe)));
12541254
MLX5_SET(wq, wq, log_wq_sz, priv->params.log_rq_size);
1255-
MLX5_SET(wq, wq, pd, priv->pdn);
1255+
MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
12561256
MLX5_SET(rqc, rqc, counter_set_id, priv->q_counter);
12571257

12581258
param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
@@ -1277,7 +1277,7 @@ static void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
12771277
void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
12781278

12791279
MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1280-
MLX5_SET(wq, wq, pd, priv->pdn);
1280+
MLX5_SET(wq, wq, pd, priv->mdev->mlx5e_res.pdn);
12811281

12821282
param->wq.buf_numa_node = dev_to_node(&priv->mdev->pdev->dev);
12831283
}
@@ -1299,7 +1299,7 @@ static void mlx5e_build_common_cq_param(struct mlx5e_priv *priv,
12991299
{
13001300
void *cqc = param->cqc;
13011301

1302-
MLX5_SET(cqc, cqc, uar_page, priv->cq_uar.index);
1302+
MLX5_SET(cqc, cqc, uar_page, priv->mdev->mlx5e_res.cq_uar.index);
13031303
}
13041304

13051305
static void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
@@ -1920,7 +1920,7 @@ static int mlx5e_create_drop_cq(struct mlx5e_priv *priv,
19201920
mcq->comp = mlx5e_completion_event;
19211921
mcq->event = mlx5e_cq_error_event;
19221922
mcq->irqn = irqn;
1923-
mcq->uar = &priv->cq_uar;
1923+
mcq->uar = &mdev->mlx5e_res.cq_uar;
19241924

19251925
cq->priv = priv;
19261926

@@ -1986,7 +1986,7 @@ static int mlx5e_create_tis(struct mlx5e_priv *priv, int tc)
19861986
memset(in, 0, sizeof(in));
19871987

19881988
MLX5_SET(tisc, tisc, prio, tc << 1);
1989-
MLX5_SET(tisc, tisc, transport_domain, priv->tdn);
1989+
MLX5_SET(tisc, tisc, transport_domain, mdev->mlx5e_res.td.tdn);
19901990

19911991
return mlx5_core_create_tis(mdev, in, sizeof(in), &priv->tisn[tc]);
19921992
}
@@ -2029,7 +2029,7 @@ static void mlx5e_build_indir_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
20292029
{
20302030
void *hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer);
20312031

2032-
MLX5_SET(tirc, tirc, transport_domain, priv->tdn);
2032+
MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
20332033

20342034
#define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
20352035
MLX5_HASH_FIELD_SEL_DST_IP)
@@ -2136,7 +2136,7 @@ static void mlx5e_build_indir_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
21362136
static void mlx5e_build_direct_tir_ctx(struct mlx5e_priv *priv, u32 *tirc,
21372137
u32 rqtn)
21382138
{
2139-
MLX5_SET(tirc, tirc, transport_domain, priv->tdn);
2139+
MLX5_SET(tirc, tirc, transport_domain, priv->mdev->mlx5e_res.td.tdn);
21402140

21412141
mlx5e_build_tir_ctx_lro(tirc, priv);
21422142

@@ -3082,31 +3082,6 @@ static void mlx5e_build_netdev(struct net_device *netdev)
30823082
mlx5e_set_netdev_dev_addr(netdev);
30833083
}
30843084

3085-
static int mlx5e_create_mkey(struct mlx5e_priv *priv, u32 pdn,
3086-
struct mlx5_core_mkey *mkey)
3087-
{
3088-
struct mlx5_core_dev *mdev = priv->mdev;
3089-
struct mlx5_create_mkey_mbox_in *in;
3090-
int err;
3091-
3092-
in = mlx5_vzalloc(sizeof(*in));
3093-
if (!in)
3094-
return -ENOMEM;
3095-
3096-
in->seg.flags = MLX5_PERM_LOCAL_WRITE |
3097-
MLX5_PERM_LOCAL_READ |
3098-
MLX5_ACCESS_MODE_PA;
3099-
in->seg.flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64);
3100-
in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
3101-
3102-
err = mlx5_core_create_mkey(mdev, mkey, in, sizeof(*in), NULL, NULL,
3103-
NULL);
3104-
3105-
kvfree(in);
3106-
3107-
return err;
3108-
}
3109-
31103085
static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
31113086
{
31123087
struct mlx5_core_dev *mdev = priv->mdev;
@@ -3149,7 +3124,7 @@ static int mlx5e_create_umr_mkey(struct mlx5e_priv *priv)
31493124
MLX5_ACCESS_MODE_MTT;
31503125

31513126
mkc->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
3152-
mkc->flags_pd = cpu_to_be32(priv->pdn);
3127+
mkc->flags_pd = cpu_to_be32(mdev->mlx5e_res.pdn);
31533128
mkc->len = cpu_to_be64(npages << PAGE_SHIFT);
31543129
mkc->xlt_oct_size = cpu_to_be32(mlx5e_get_mtt_octw(npages));
31553130
mkc->log2_page_size = PAGE_SHIFT;
@@ -3169,9 +3144,6 @@ static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
31693144
int nch = mlx5e_get_max_num_channels(mdev);
31703145
int err;
31713146

3172-
if (mlx5e_check_required_hca_cap(mdev))
3173-
return NULL;
3174-
31753147
netdev = alloc_etherdev_mqs(sizeof(struct mlx5e_priv),
31763148
nch * MLX5E_MAX_NUM_TC,
31773149
nch);
@@ -3191,34 +3163,10 @@ static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
31913163
if (!priv->wq)
31923164
goto err_free_netdev;
31933165

3194-
err = mlx5_alloc_map_uar(mdev, &priv->cq_uar, false);
3195-
if (err) {
3196-
mlx5_core_err(mdev, "alloc_map uar failed, %d\n", err);
3197-
goto err_destroy_wq;
3198-
}
3199-
3200-
err = mlx5_core_alloc_pd(mdev, &priv->pdn);
3201-
if (err) {
3202-
mlx5_core_err(mdev, "alloc pd failed, %d\n", err);
3203-
goto err_unmap_free_uar;
3204-
}
3205-
3206-
err = mlx5_core_alloc_transport_domain(mdev, &priv->tdn);
3207-
if (err) {
3208-
mlx5_core_err(mdev, "alloc td failed, %d\n", err);
3209-
goto err_dealloc_pd;
3210-
}
3211-
3212-
err = mlx5e_create_mkey(priv, priv->pdn, &priv->mkey);
3213-
if (err) {
3214-
mlx5_core_err(mdev, "create mkey failed, %d\n", err);
3215-
goto err_dealloc_transport_domain;
3216-
}
3217-
32183166
err = mlx5e_create_umr_mkey(priv);
32193167
if (err) {
32203168
mlx5_core_err(mdev, "create umr mkey failed, %d\n", err);
3221-
goto err_destroy_mkey;
3169+
goto err_destroy_wq;
32223170
}
32233171

32243172
err = mlx5e_create_tises(priv);
@@ -3304,18 +3252,6 @@ static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
33043252
err_destroy_umr_mkey:
33053253
mlx5_core_destroy_mkey(mdev, &priv->umr_mkey);
33063254

3307-
err_destroy_mkey:
3308-
mlx5_core_destroy_mkey(mdev, &priv->mkey);
3309-
3310-
err_dealloc_transport_domain:
3311-
mlx5_core_dealloc_transport_domain(mdev, priv->tdn);
3312-
3313-
err_dealloc_pd:
3314-
mlx5_core_dealloc_pd(mdev, priv->pdn);
3315-
3316-
err_unmap_free_uar:
3317-
mlx5_unmap_free_uar(mdev, &priv->cq_uar);
3318-
33193255
err_destroy_wq:
33203256
destroy_workqueue(priv->wq);
33213257

@@ -3325,9 +3261,27 @@ static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev)
33253261
return NULL;
33263262
}
33273263

3328-
static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, void *vpriv)
3264+
static void *mlx5e_add(struct mlx5_core_dev *mdev)
3265+
{
3266+
void *ret;
3267+
3268+
if (mlx5e_check_required_hca_cap(mdev))
3269+
return NULL;
3270+
3271+
if (mlx5e_create_mdev_resources(mdev))
3272+
return NULL;
3273+
3274+
ret = mlx5e_create_netdev(mdev);
3275+
if (!ret) {
3276+
mlx5e_destroy_mdev_resources(mdev);
3277+
return NULL;
3278+
}
3279+
return ret;
3280+
}
3281+
3282+
static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev,
3283+
struct mlx5e_priv *priv)
33293284
{
3330-
struct mlx5e_priv *priv = vpriv;
33313285
struct net_device *netdev = priv->netdev;
33323286

33333287
set_bit(MLX5E_STATE_DESTROYING, &priv->state);
@@ -3351,17 +3305,21 @@ static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, void *vpriv)
33513305
mlx5e_close_drop_rq(priv);
33523306
mlx5e_destroy_tises(priv);
33533307
mlx5_core_destroy_mkey(priv->mdev, &priv->umr_mkey);
3354-
mlx5_core_destroy_mkey(priv->mdev, &priv->mkey);
3355-
mlx5_core_dealloc_transport_domain(priv->mdev, priv->tdn);
3356-
mlx5_core_dealloc_pd(priv->mdev, priv->pdn);
3357-
mlx5_unmap_free_uar(priv->mdev, &priv->cq_uar);
33583308
cancel_delayed_work_sync(&priv->update_stats_work);
33593309
destroy_workqueue(priv->wq);
33603310

33613311
if (!test_bit(MLX5_INTERFACE_STATE_SHUTDOWN, &mdev->intf_state))
33623312
free_netdev(netdev);
33633313
}
33643314

3315+
static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
3316+
{
3317+
struct mlx5e_priv *priv = vpriv;
3318+
3319+
mlx5e_destroy_netdev(mdev, priv);
3320+
mlx5e_destroy_mdev_resources(mdev);
3321+
}
3322+
33653323
static void *mlx5e_get_netdev(void *vpriv)
33663324
{
33673325
struct mlx5e_priv *priv = vpriv;
@@ -3370,8 +3328,8 @@ static void *mlx5e_get_netdev(void *vpriv)
33703328
}
33713329

33723330
static struct mlx5_interface mlx5e_interface = {
3373-
.add = mlx5e_create_netdev,
3374-
.remove = mlx5e_destroy_netdev,
3331+
.add = mlx5e_add,
3332+
.remove = mlx5e_remove,
33753333
.event = mlx5e_async_event,
33763334
.protocol = MLX5_INTERFACE_PROTOCOL_ETH,
33773335
.get_dev = mlx5e_get_netdev,

0 commit comments

Comments
 (0)