2 * Copyright (c) 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
35 /* mlx5e global resources should be placed in this file.
36 * Global resources are common to all the netdevices crated on the same nic.
39 int mlx5e_create_tir(struct mlx5_core_dev
*mdev
,
40 struct mlx5e_tir
*tir
, u32
*in
, int inlen
)
44 err
= mlx5_core_create_tir(mdev
, in
, inlen
, &tir
->tirn
);
48 mutex_lock(&mdev
->mlx5e_res
.td
.list_lock
);
49 list_add(&tir
->list
, &mdev
->mlx5e_res
.td
.tirs_list
);
50 mutex_unlock(&mdev
->mlx5e_res
.td
.list_lock
);
55 void mlx5e_destroy_tir(struct mlx5_core_dev
*mdev
,
56 struct mlx5e_tir
*tir
)
58 mutex_lock(&mdev
->mlx5e_res
.td
.list_lock
);
59 mlx5_core_destroy_tir(mdev
, tir
->tirn
);
61 mutex_unlock(&mdev
->mlx5e_res
.td
.list_lock
);
64 static int mlx5e_create_mkey(struct mlx5_core_dev
*mdev
, u32 pdn
,
65 struct mlx5_core_mkey
*mkey
)
67 int inlen
= MLX5_ST_SZ_BYTES(create_mkey_in
);
72 in
= mlx5_vzalloc(inlen
);
76 mkc
= MLX5_ADDR_OF(create_mkey_in
, in
, memory_key_mkey_entry
);
77 MLX5_SET(mkc
, mkc
, access_mode
, MLX5_MKC_ACCESS_MODE_PA
);
78 MLX5_SET(mkc
, mkc
, lw
, 1);
79 MLX5_SET(mkc
, mkc
, lr
, 1);
81 MLX5_SET(mkc
, mkc
, pd
, pdn
);
82 MLX5_SET(mkc
, mkc
, length64
, 1);
83 MLX5_SET(mkc
, mkc
, qpn
, 0xffffff);
85 err
= mlx5_core_create_mkey(mdev
, mkey
, in
, inlen
);
91 int mlx5e_create_mdev_resources(struct mlx5_core_dev
*mdev
)
93 struct mlx5e_resources
*res
= &mdev
->mlx5e_res
;
96 err
= mlx5_alloc_map_uar(mdev
, &res
->cq_uar
, false);
98 mlx5_core_err(mdev
, "alloc_map uar failed, %d\n", err
);
102 err
= mlx5_core_alloc_pd(mdev
, &res
->pdn
);
104 mlx5_core_err(mdev
, "alloc pd failed, %d\n", err
);
105 goto err_unmap_free_uar
;
108 err
= mlx5_core_alloc_transport_domain(mdev
, &res
->td
.tdn
);
110 mlx5_core_err(mdev
, "alloc td failed, %d\n", err
);
114 err
= mlx5e_create_mkey(mdev
, res
->pdn
, &res
->mkey
);
116 mlx5_core_err(mdev
, "create mkey failed, %d\n", err
);
117 goto err_dealloc_transport_domain
;
120 INIT_LIST_HEAD(&mdev
->mlx5e_res
.td
.tirs_list
);
121 mutex_init(&mdev
->mlx5e_res
.td
.list_lock
);
125 err_dealloc_transport_domain
:
126 mlx5_core_dealloc_transport_domain(mdev
, res
->td
.tdn
);
128 mlx5_core_dealloc_pd(mdev
, res
->pdn
);
130 mlx5_unmap_free_uar(mdev
, &res
->cq_uar
);
135 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev
*mdev
)
137 struct mlx5e_resources
*res
= &mdev
->mlx5e_res
;
139 mlx5_core_destroy_mkey(mdev
, &res
->mkey
);
140 mlx5_core_dealloc_transport_domain(mdev
, res
->td
.tdn
);
141 mlx5_core_dealloc_pd(mdev
, res
->pdn
);
142 mlx5_unmap_free_uar(mdev
, &res
->cq_uar
);
145 int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5_core_dev
*mdev
)
147 struct mlx5e_tir
*tir
;
152 inlen
= MLX5_ST_SZ_BYTES(modify_tir_in
);
153 in
= mlx5_vzalloc(inlen
);
157 MLX5_SET(modify_tir_in
, in
, bitmask
.self_lb_en
, 1);
159 mutex_lock(&mdev
->mlx5e_res
.td
.list_lock
);
160 list_for_each_entry(tir
, &mdev
->mlx5e_res
.td
.tirs_list
, list
) {
161 err
= mlx5_core_modify_tir(mdev
, tir
->tirn
, in
, inlen
);
168 mutex_unlock(&mdev
->mlx5e_res
.td
.list_lock
);