Debian Codegraph @

prov/usnic/src/usnic_direct/vnic_wq.c

raw symbols SCIP
1 /*
2 * Copyright 2008-2018 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * LICENSE_BEGIN
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 *
39 * LICENSE_END
40 *
41 *
42 */
43
44 #include <linux/kernel.h>
45 #include <linux/errno.h>
46 #include <linux/types.h>
47 #include <linux/pci.h>
48 #include <linux/delay.h>cxx . . $ `<file>/prov/usnic/src/usnic_direct/linux/delay.h`/
49 #include <linux/slab.h>cxx . . $ `<file>/prov/usnic/src/usnic_direct/linux/slab.h`/
50
51 #include "kcompat.h"cxx . . $ `<file>/prov/usnic/src/usnic_direct/kcompat.h`/
52 #include "vnic_dev.h"cxx . . $ `<file>/prov/usnic/src/usnic_direct/vnic_dev.h`/
53 #include "vnic_wq.h"cxx . . $ `<file>/prov/usnic/src/usnic_direct/vnic_wq.h`/
54
55 static inline
56 int vnic_wq_get_ctrlcxx . . $ vnic_wq_get_ctrl(6177ce3d4d65b89b).(struct vnic_devcxx . . $ vnic_dev# *vdev, struct vnic_wqcxx . . $ vnic_wq# *wq,
57 unsigned int index, enum vnic_res_typecxx . . $ vnic_res_type# res_type)
58 {
59 wq->ctrlcxx . . $ vnic_wq#ctrl. = vnic_dev_get_rescxx . . $ vnic_dev_get_res(5acd67ed2f089690).(vdev, res_type, index);
60 if (!wq->ctrlcxx . . $ vnic_wq#ctrl.)
61 return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
62 return 0;
63 }
64
65 static inline
66 int vnic_wq_alloc_ringcxx . . $ vnic_wq_alloc_ring(92cbe64ad38acab6).(struct vnic_devcxx . . $ vnic_dev# *vdev, struct vnic_wqcxx . . $ vnic_wq# *wq,
67 unsigned int desc_count, unsigned int desc_size)
68 {
69 return vnic_dev_alloc_desc_ringcxx . . $ vnic_dev_alloc_desc_ring(7c0f5d6775aab53b).(vdev, &wq->ringcxx . . $ vnic_wq#ring., desc_count, desc_size);
70 }
71
72 static int vnic_wq_alloc_bufscxx . . $ vnic_wq_alloc_bufs(2e28277d8ba28b12).(struct vnic_wqcxx . . $ vnic_wq# *wq)
73 {
74 struct vnic_wq_bufcxx . . $ vnic_wq_buf# *buf;
75 unsigned int i, j, count = wq->ringcxx . . $ vnic_wq#ring..desc_countcxx . . $ vnic_dev_ring#desc_count.;
76 unsigned int blks = VNIC_WQ_BUF_BLKS_NEEDEDcxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:100:9`!(count);
77
78 for (i = 0; i < blks; i++) {
79 wq->bufscxx . . $ vnic_wq#bufs.[i] = kzalloccxx . . $ `prov/usnic/src/usnic_direct/kcompat.h:65:9`!(VNIC_WQ_BUF_BLK_SZcxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:98:9`!(count), GFP_ATOMIC);
80 if (!wq->bufscxx . . $ vnic_wq#bufs.[i])
81 return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
82 }
83
84 for (i = 0; i < blks; i++) {
85 buf = wq->bufscxx . . $ vnic_wq#bufs.[i];
86 for (j = 0; j < VNIC_WQ_BUF_BLK_ENTRIEScxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:95:9`!(count); j++) {
87 buf->indexcxx . . $ vnic_wq_buf#index. = i * VNIC_WQ_BUF_BLK_ENTRIEScxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:95:9`!(count) + j;
88 buf->desccxx . . $ vnic_wq_buf#desc. = (u8cxx . . $ u8# *)wq->ringcxx . . $ vnic_wq#ring..descscxx . . $ vnic_dev_ring#descs. +
89 wq->ringcxx . . $ vnic_wq#ring..desc_sizecxx . . $ vnic_dev_ring#desc_size. * buf->indexcxx . . $ vnic_wq_buf#index.;
90 if (buf->indexcxx . . $ vnic_wq_buf#index. + 1 == count) {
91 buf->nextcxx . . $ vnic_wq_buf#next. = wq->bufscxx . . $ vnic_wq#bufs.[0];
92 buf->nextcxx . . $ vnic_wq_buf#next.->prevcxx . . $ vnic_wq_buf#prev. = buf;
93 break;
94 } else if (j + 1 == VNIC_WQ_BUF_BLK_ENTRIEScxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:95:9`!(count)) {
95 buf->nextcxx . . $ vnic_wq_buf#next. = wq->bufscxx . . $ vnic_wq#bufs.[i + 1];
96 buf->nextcxx . . $ vnic_wq_buf#next.->prevcxx . . $ vnic_wq_buf#prev. = buf;
97 } else {
98 buf->nextcxx . . $ vnic_wq_buf#next. = buf + 1;
99 buf->nextcxx . . $ vnic_wq_buf#next.->prevcxx . . $ vnic_wq_buf#prev. = buf;
100 buf++;
101 }
102 }
103 }
104
105 wq->to_usecxx . . $ vnic_wq#to_use. = wq->to_cleancxx . . $ vnic_wq#to_clean. = wq->bufscxx . . $ vnic_wq#bufs.[0];
106
107 return 0;
108 }
109
110 void vnic_wq_freecxx . . $ vnic_wq_free(83217dc180b9222e).(struct vnic_wqcxx . . $ vnic_wq# *wq)
111 {
112 struct vnic_devcxx . . $ vnic_dev# *vdev;
113 unsigned int i;
114
115 vdev = wq->vdevcxx . . $ vnic_wq#vdev.;
116
117 vnic_dev_free_desc_ringcxx . . $ vnic_dev_free_desc_ring(a14b3636c6573a1f).(vdev, &wq->ringcxx . . $ vnic_wq#ring.);
118
119 for (i = 0; i < VNIC_WQ_BUF_BLKS_MAXcxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:102:9`!; i++) {
120 if (wq->bufscxx . . $ vnic_wq#bufs.[i]) {
121 kfreecxx . . $ `prov/usnic/src/usnic_direct/kcompat.h:66:9`!(wq->bufs[i]);
122 wq->bufscxx . . $ vnic_wq#bufs.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
123 }
124 }
125
126 wq->ctrlcxx . . $ vnic_wq#ctrl. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
127 }
128
129 #ifndef NOT_FOR_OPEN_ENIC
130 int vnic_wq_mem_sizecxx . . $ vnic_wq_mem_size(edc4c246693e07c1).(struct vnic_wqcxx . . $ vnic_wq# *wq, unsigned int desc_count,
131 unsigned int desc_size)
132 {
133 int mem_size = 0;
134
135 mem_size += vnic_dev_desc_ring_sizecxx . . $ vnic_dev_desc_ring_size(7a5ad9da0ebcae78).(&wq->ringcxx . . $ vnic_wq#ring., desc_count, desc_size);
136
137 mem_size += VNIC_WQ_BUF_BLKS_NEEDEDcxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:100:9`!(wq->ring.desc_count) *
138 VNIC_WQ_BUF_BLK_SZcxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:98:9`!(wq->ring.desc_count);
139
140 return mem_size;
141 }
142
143 #endif
144
145 int vnic_wq_alloccxx . . $ vnic_wq_alloc(ed074b2f8a2f11be).(struct vnic_devcxx . . $ vnic_dev# *vdev, struct vnic_wqcxx . . $ vnic_wq# *wq, unsigned int index,
146 unsigned int desc_count, unsigned int desc_size)
147 {
148 int err;
149
150 wq->indexcxx . . $ vnic_wq#index. = index;
151 wq->vdevcxx . . $ vnic_wq#vdev. = vdev;
152
153 err = vnic_wq_get_ctrlcxx . . $ vnic_wq_get_ctrl(6177ce3d4d65b89b).(vdev, wq, index, RES_TYPE_WQcxx . . $ RES_TYPE_WQ.);
154 if (err) {
155 pr_errcxx . . $ `prov/usnic/src/usnic_direct/kcompat_priv.h:84:9`!("Failed to hook WQ[%d] resource, err %d\n", index, err);
156 return err;
157 }
158
159 vnic_wq_disablecxx . . $ vnic_wq_disable(2e28277d8ba28b12).(wq);
160
161 err = vnic_wq_alloc_ringcxx . . $ vnic_wq_alloc_ring(92cbe64ad38acab6).(vdev, wq, desc_count, desc_size);
162 if (err)
163 return err;
164
165 err = vnic_wq_alloc_bufscxx . . $ vnic_wq_alloc_bufs(2e28277d8ba28b12).(wq);
166 if (err) {
167 vnic_wq_freecxx . . $ vnic_wq_free(83217dc180b9222e).(wq);
168 return err;
169 }
170
171 return 0;
172 }
173
174 int vnic_wq_devcmd2_alloccxx . . $ vnic_wq_devcmd2_alloc(92cbe64ad38acab6).(struct vnic_devcxx . . $ vnic_dev# *vdev, struct vnic_wqcxx . . $ vnic_wq# *wq,
175 unsigned int desc_count, unsigned int desc_size)
176 {
177 int err;
178
179 wq->indexcxx . . $ vnic_wq#index. = 0;
180 wq->vdevcxx . . $ vnic_wq#vdev. = vdev;
181
182 err = vnic_wq_get_ctrlcxx . . $ vnic_wq_get_ctrl(6177ce3d4d65b89b).(vdev, wq, 0, RES_TYPE_DEVCMD2cxx . . $ RES_TYPE_DEVCMD2.);
183 if (err) {
184 pr_errcxx . . $ `prov/usnic/src/usnic_direct/kcompat_priv.h:84:9`!("Failed to get devcmd2 resource\n");
185 return err;
186 }
187 vnic_wq_disablecxx . . $ vnic_wq_disable(2e28277d8ba28b12).(wq);
188
189 err = vnic_wq_alloc_ringcxx . . $ vnic_wq_alloc_ring(92cbe64ad38acab6).(vdev, wq, desc_count, desc_size);
190 if (err)
191 return err;
192 return 0;
193 }
194
195 void vnic_wq_init_startcxx . . $ vnic_wq_init_start(ecc8e6c26ea41087).(struct vnic_wqcxx . . $ vnic_wq# *wq, unsigned int cq_index,
196 unsigned int fetch_index, unsigned int posted_index,
197 unsigned int error_interrupt_enable,
198 unsigned int error_interrupt_offset)
199 {
200 u64cxx . . $ u64# paddr;
201 unsigned int count = wq->ringcxx . . $ vnic_wq#ring..desc_countcxx . . $ vnic_dev_ring#desc_count.;
202
203 paddr = (u64cxx . . $ u64#)wq->ringcxx . . $ vnic_wq#ring..base_addrcxx . . $ vnic_dev_ring#base_addr. | VNIC_PADDR_TARGETcxx . . $ `prov/usnic/src/usnic_direct/vnic_dev.h:54:9`!;
204 writeqcxx . . $ writeq(3bdecba87b0fe3d5).(paddr, &wq->ctrlcxx . . $ vnic_wq#ctrl.->ring_basecxx . . $ vnic_wq_ctrl#ring_base.);
205 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(count, &wq->ctrlcxx . . $ vnic_wq#ctrl.->ring_sizecxx . . $ vnic_wq_ctrl#ring_size.);
206 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(fetch_index, &wq->ctrlcxx . . $ vnic_wq#ctrl.->fetch_indexcxx . . $ vnic_wq_ctrl#fetch_index.);
207 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(posted_index, &wq->ctrlcxx . . $ vnic_wq#ctrl.->posted_indexcxx . . $ vnic_wq_ctrl#posted_index.);
208 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(cq_index, &wq->ctrlcxx . . $ vnic_wq#ctrl.->cq_indexcxx . . $ vnic_wq_ctrl#cq_index.);
209 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(error_interrupt_enable, &wq->ctrlcxx . . $ vnic_wq#ctrl.->error_interrupt_enablecxx . . $ vnic_wq_ctrl#error_interrupt_enable.);
210 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(error_interrupt_offset, &wq->ctrlcxx . . $ vnic_wq#ctrl.->error_interrupt_offsetcxx . . $ vnic_wq_ctrl#error_interrupt_offset.);
211 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(0, &wq->ctrlcxx . . $ vnic_wq#ctrl.->error_statuscxx . . $ vnic_wq_ctrl#error_status.);
212
213 wq->to_usecxx . . $ vnic_wq#to_use. = wq->to_cleancxx . . $ vnic_wq#to_clean. =
214 &wq->bufscxx . . $ vnic_wq#bufs.[fetch_index / VNIC_WQ_BUF_BLK_ENTRIEScxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:95:9`!(count)]
215 [fetch_index % VNIC_WQ_BUF_BLK_ENTRIEScxx . . $ `prov/usnic/src/usnic_direct/vnic_wq.h:95:9`!(count)];
216 }
217
218 void vnic_wq_initcxx . . $ vnic_wq_init(e37148c8f2d03a1a).(struct vnic_wqcxx . . $ vnic_wq# *wq, unsigned int cq_index,
219 unsigned int error_interrupt_enable,
220 unsigned int error_interrupt_offset)
221 {
222 vnic_wq_init_startcxx . . $ vnic_wq_init_start(ecc8e6c26ea41087).(wq, cq_index, 0, 0,
223 error_interrupt_enable,
224 error_interrupt_offset);
225 }
226
227 void vnic_wq_error_outcxx . . $ vnic_wq_error_out(3a849d045fd25fea).(struct vnic_wqcxx . . $ vnic_wq# *wq, unsigned int error)
228 {
229 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(error, &wq->ctrlcxx . . $ vnic_wq#ctrl.->error_statuscxx . . $ vnic_wq_ctrl#error_status.);
230 }
231
232 unsigned int vnic_wq_error_statuscxx . . $ vnic_wq_error_status(6cc381581f864d80).(struct vnic_wqcxx . . $ vnic_wq# *wq)
233 {
234 return vnic_wq_ctrl_error_statuscxx . . $ vnic_wq_ctrl_error_status(f5289637a6b781de).(wq->ctrlcxx . . $ vnic_wq#ctrl.);
235 }
236
237 EXPORT_SYMBOLcxx . . $ `prov/usnic/src/usnic_direct/kcompat.h:58:9`!(vnic_wq_ctrl_error_status);
238 unsigned int vnic_wq_ctrl_error_statuscxx . . $ vnic_wq_ctrl_error_status(f5289637a6b781de).(struct vnic_wq_ctrlcxx . . $ vnic_wq_ctrl# *ctrl)
239 {
240 return ioread32cxx . . $ ioread32(42b2ce8dd08ea26d).(&ctrl->error_statuscxx . . $ vnic_wq_ctrl#error_status.);
241 }
242
243 void vnic_wq_enablecxx . . $ vnic_wq_enable(83217dc180b9222e).(struct vnic_wqcxx . . $ vnic_wq# *wq)
244 {
245 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(1, &wq->ctrlcxx . . $ vnic_wq#ctrl.->enablecxx . . $ vnic_wq_ctrl#enable.);
246 }
247
248 int vnic_wq_disablecxx . . $ vnic_wq_disable(2e28277d8ba28b12).(struct vnic_wqcxx . . $ vnic_wq# *wq)
249 {
250 unsigned int wait;
251
252 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(0, &wq->ctrlcxx . . $ vnic_wq#ctrl.->enablecxx . . $ vnic_wq_ctrl#enable.);
253
254 /* Wait for HW to ACK disable request */
255 for (wait = 0; wait < 1000; wait++) {
256 if (!(ioread32cxx . . $ ioread32(42b2ce8dd08ea26d).(&wq->ctrlcxx . . $ vnic_wq#ctrl.->runningcxx . . $ vnic_wq_ctrl#running.)))
257 return 0;
258 udelaycxx . . $ `prov/usnic/src/usnic_direct/kcompat.h:69:9`!(10);
259 }
260
261 pr_errcxx . . $ `prov/usnic/src/usnic_direct/kcompat_priv.h:84:9`!("Failed to disable WQ[%d]\n", wq->index);
262
263 return -ETIMEDOUTcxx . . $ `<external>/17922322188510340118/errno.h:94:9`!;
264 }
265
266 void vnic_wq_cleancxx . . $ vnic_wq_clean(fbb103b2594f4db3).(struct vnic_wqcxx . . $ vnic_wq# *wq,
267 void (*buf_clean)(struct vnic_wqcxx . . $ vnic_wq# *wq, struct vnic_wq_bufcxx . . $ vnic_wq_buf# *buf))
268 {
269 struct vnic_wq_bufcxx . . $ vnic_wq_buf# *buf;
270
271 buf = wq->to_cleancxx . . $ vnic_wq#to_clean.;
272
273 while (vnic_wq_desc_usedcxx . . $ vnic_wq_desc_used(6cc381581f864d80).(wq) > 0) {
274
275 (*buf_clean)(wq, buf);
276
277 buf = wq->to_cleancxx . . $ vnic_wq#to_clean. = buf->nextcxx . . $ vnic_wq_buf#next.;
278 wq->ringcxx . . $ vnic_wq#ring..desc_availcxx . . $ vnic_dev_ring#desc_avail.++;
279 }
280
281 wq->to_usecxx . . $ vnic_wq#to_use. = wq->to_cleancxx . . $ vnic_wq#to_clean. = wq->bufscxx . . $ vnic_wq#bufs.[0];
282
283 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(0, &wq->ctrlcxx . . $ vnic_wq#ctrl.->fetch_indexcxx . . $ vnic_wq_ctrl#fetch_index.);
284 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(0, &wq->ctrlcxx . . $ vnic_wq#ctrl.->posted_indexcxx . . $ vnic_wq_ctrl#posted_index.);
285 iowrite32cxx . . $ iowrite32(56cca040bbd65dce).(0, &wq->ctrlcxx . . $ vnic_wq#ctrl.->error_statuscxx . . $ vnic_wq_ctrl#error_status.);
286
287 vnic_dev_clear_desc_ringcxx . . $ vnic_dev_clear_desc_ring(96eb7ec68c001fdb).(&wq->ringcxx . . $ vnic_wq#ring.);
288 }