Commit | Line | Data |
---|---|---|
b50d292b HHZ |
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 | ||
724b2aa1 HHZ |
39 | int mlx5e_create_tir(struct mlx5_core_dev *mdev, |
40 | struct mlx5e_tir *tir, u32 *in, int inlen) | |
41 | { | |
42 | int err; | |
43 | ||
44 | err = mlx5_core_create_tir(mdev, in, inlen, &tir->tirn); | |
45 | if (err) | |
46 | return err; | |
47 | ||
48 | list_add(&tir->list, &mdev->mlx5e_res.td.tirs_list); | |
49 | ||
50 | return 0; | |
51 | } | |
52 | ||
53 | void mlx5e_destroy_tir(struct mlx5_core_dev *mdev, | |
54 | struct mlx5e_tir *tir) | |
55 | { | |
56 | mlx5_core_destroy_tir(mdev, tir->tirn); | |
57 | list_del(&tir->list); | |
58 | } | |
59 | ||
b50d292b HHZ |
60 | static int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn, |
61 | struct mlx5_core_mkey *mkey) | |
62 | { | |
63 | struct mlx5_create_mkey_mbox_in *in; | |
64 | int err; | |
65 | ||
66 | in = mlx5_vzalloc(sizeof(*in)); | |
67 | if (!in) | |
68 | return -ENOMEM; | |
69 | ||
70 | in->seg.flags = MLX5_PERM_LOCAL_WRITE | | |
71 | MLX5_PERM_LOCAL_READ | | |
72 | MLX5_ACCESS_MODE_PA; | |
73 | in->seg.flags_pd = cpu_to_be32(pdn | MLX5_MKEY_LEN64); | |
74 | in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); | |
75 | ||
76 | err = mlx5_core_create_mkey(mdev, mkey, in, sizeof(*in), NULL, NULL, | |
77 | NULL); | |
78 | ||
79 | kvfree(in); | |
80 | ||
81 | return err; | |
82 | } | |
83 | ||
84 | int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev) | |
85 | { | |
86 | struct mlx5e_resources *res = &mdev->mlx5e_res; | |
87 | int err; | |
88 | ||
89 | err = mlx5_alloc_map_uar(mdev, &res->cq_uar, false); | |
90 | if (err) { | |
91 | mlx5_core_err(mdev, "alloc_map uar failed, %d\n", err); | |
92 | return err; | |
93 | } | |
94 | ||
95 | err = mlx5_core_alloc_pd(mdev, &res->pdn); | |
96 | if (err) { | |
97 | mlx5_core_err(mdev, "alloc pd failed, %d\n", err); | |
98 | goto err_unmap_free_uar; | |
99 | } | |
100 | ||
101 | err = mlx5_core_alloc_transport_domain(mdev, &res->td.tdn); | |
102 | if (err) { | |
103 | mlx5_core_err(mdev, "alloc td failed, %d\n", err); | |
104 | goto err_dealloc_pd; | |
105 | } | |
106 | ||
107 | err = mlx5e_create_mkey(mdev, res->pdn, &res->mkey); | |
108 | if (err) { | |
109 | mlx5_core_err(mdev, "create mkey failed, %d\n", err); | |
110 | goto err_dealloc_transport_domain; | |
111 | } | |
112 | ||
724b2aa1 HHZ |
113 | INIT_LIST_HEAD(&mdev->mlx5e_res.td.tirs_list); |
114 | ||
b50d292b HHZ |
115 | return 0; |
116 | ||
117 | err_dealloc_transport_domain: | |
118 | mlx5_core_dealloc_transport_domain(mdev, res->td.tdn); | |
119 | err_dealloc_pd: | |
120 | mlx5_core_dealloc_pd(mdev, res->pdn); | |
121 | err_unmap_free_uar: | |
122 | mlx5_unmap_free_uar(mdev, &res->cq_uar); | |
123 | ||
124 | return err; | |
125 | } | |
126 | ||
127 | void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev) | |
128 | { | |
129 | struct mlx5e_resources *res = &mdev->mlx5e_res; | |
130 | ||
131 | mlx5_core_destroy_mkey(mdev, &res->mkey); | |
132 | mlx5_core_dealloc_transport_domain(mdev, res->td.tdn); | |
133 | mlx5_core_dealloc_pd(mdev, res->pdn); | |
134 | mlx5_unmap_free_uar(mdev, &res->cq_uar); | |
135 | } | |
724b2aa1 HHZ |
136 | |
137 | int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5_core_dev *mdev) | |
138 | { | |
139 | struct mlx5e_tir *tir; | |
140 | void *in; | |
141 | int inlen; | |
bf50082c | 142 | int err = 0; |
724b2aa1 HHZ |
143 | |
144 | inlen = MLX5_ST_SZ_BYTES(modify_tir_in); | |
145 | in = mlx5_vzalloc(inlen); | |
146 | if (!in) | |
147 | return -ENOMEM; | |
148 | ||
149 | MLX5_SET(modify_tir_in, in, bitmask.self_lb_en, 1); | |
150 | ||
151 | list_for_each_entry(tir, &mdev->mlx5e_res.td.tirs_list, list) { | |
152 | err = mlx5_core_modify_tir(mdev, tir->tirn, in, inlen); | |
153 | if (err) | |
bf50082c | 154 | goto out; |
724b2aa1 HHZ |
155 | } |
156 | ||
bf50082c | 157 | out: |
724b2aa1 HHZ |
158 | kvfree(in); |
159 | ||
bf50082c | 160 | return err; |
724b2aa1 | 161 | } |