blob: a4bd968f8bc139839d93b22149b72d46b3774225 [file] [log] [blame]
Faisal Latif86dbcd02016-01-20 13:40:10 -06001/*******************************************************************************
2*
3* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
4*
5* This software is available to you under a choice of one of two
6* licenses. You may choose to be licensed under the terms of the GNU
7* General Public License (GPL) Version 2, available from the file
8* COPYING in the main directory of this source tree, or the
9* OpenFabrics.org BSD license below:
10*
11* Redistribution and use in source and binary forms, with or
12* without modification, are permitted provided that the following
13* conditions are met:
14*
15* - Redistributions of source code must retain the above
16* copyright notice, this list of conditions and the following
17* disclaimer.
18*
19* - Redistributions in binary form must reproduce the above
20* copyright notice, this list of conditions and the following
21* disclaimer in the documentation and/or other materials
22* provided with the distribution.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31* SOFTWARE.
32*
33*******************************************************************************/
34
35#include "i40iw_osdep.h"
36#include "i40iw_register.h"
37#include "i40iw_status.h"
38#include "i40iw_hmc.h"
39
40#include "i40iw_d.h"
41#include "i40iw_type.h"
42#include "i40iw_p.h"
43#include "i40iw_vf.h"
44#include "i40iw_virtchnl.h"
45
46/**
47 * i40iw_insert_wqe_hdr - write wqe header
48 * @wqe: cqp wqe for header
49 * @header: header for the cqp wqe
50 */
Mustafa Ismail43bfc242017-10-03 11:11:49 -050051void i40iw_insert_wqe_hdr(u64 *wqe, u64 header)
Faisal Latif86dbcd02016-01-20 13:40:10 -060052{
53 wmb(); /* make sure WQE is populated before polarity is set */
54 set_64bit_val(wqe, 24, header);
55}
56
Shiraz Saleemd26875b2017-08-08 20:38:45 -050057void i40iw_check_cqp_progress(struct i40iw_cqp_timeout *cqp_timeout, struct i40iw_sc_dev *dev)
58{
59 if (cqp_timeout->compl_cqp_cmds != dev->cqp_cmd_stats[OP_COMPLETED_COMMANDS]) {
60 cqp_timeout->compl_cqp_cmds = dev->cqp_cmd_stats[OP_COMPLETED_COMMANDS];
61 cqp_timeout->count = 0;
62 } else {
63 if (dev->cqp_cmd_stats[OP_REQUESTED_COMMANDS] != cqp_timeout->compl_cqp_cmds)
64 cqp_timeout->count++;
65 }
66}
67
Faisal Latif86dbcd02016-01-20 13:40:10 -060068/**
69 * i40iw_get_cqp_reg_info - get head and tail for cqp using registers
70 * @cqp: struct for cqp hw
71 * @val: cqp tail register value
72 * @tail:wqtail register value
73 * @error: cqp processing err
74 */
75static inline void i40iw_get_cqp_reg_info(struct i40iw_sc_cqp *cqp,
76 u32 *val,
77 u32 *tail,
78 u32 *error)
79{
80 if (cqp->dev->is_pf) {
81 *val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPTAIL);
82 *tail = RS_32(*val, I40E_PFPE_CQPTAIL_WQTAIL);
83 *error = RS_32(*val, I40E_PFPE_CQPTAIL_CQP_OP_ERR);
84 } else {
85 *val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPTAIL1);
86 *tail = RS_32(*val, I40E_VFPE_CQPTAIL_WQTAIL);
87 *error = RS_32(*val, I40E_VFPE_CQPTAIL_CQP_OP_ERR);
88 }
89}
90
91/**
92 * i40iw_cqp_poll_registers - poll cqp registers
93 * @cqp: struct for cqp hw
94 * @tail:wqtail register value
95 * @count: how many times to try for completion
96 */
97static enum i40iw_status_code i40iw_cqp_poll_registers(
98 struct i40iw_sc_cqp *cqp,
99 u32 tail,
100 u32 count)
101{
102 u32 i = 0;
103 u32 newtail, error, val;
104
105 while (i < count) {
106 i++;
107 i40iw_get_cqp_reg_info(cqp, &val, &newtail, &error);
108 if (error) {
109 error = (cqp->dev->is_pf) ?
110 i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES) :
111 i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
112 return I40IW_ERR_CQP_COMPL_ERROR;
113 }
114 if (newtail != tail) {
115 /* SUCCESS */
116 I40IW_RING_MOVE_TAIL(cqp->sq_ring);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600117 cqp->dev->cqp_cmd_stats[OP_COMPLETED_COMMANDS]++;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600118 return 0;
119 }
120 udelay(I40IW_SLEEP_COUNT);
121 }
122 return I40IW_ERR_TIMEOUT;
123}
124
125/**
126 * i40iw_sc_parse_fpm_commit_buf - parse fpm commit buffer
127 * @buf: ptr to fpm commit buffer
128 * @info: ptr to i40iw_hmc_obj_info struct
Ismail, Mustafafa415372016-04-18 10:33:08 -0500129 * @sd: number of SDs for HMC objects
Faisal Latif86dbcd02016-01-20 13:40:10 -0600130 *
131 * parses fpm commit info and copy base value
132 * of hmc objects in hmc_info
133 */
134static enum i40iw_status_code i40iw_sc_parse_fpm_commit_buf(
135 u64 *buf,
Ismail, Mustafafa415372016-04-18 10:33:08 -0500136 struct i40iw_hmc_obj_info *info,
137 u32 *sd)
Faisal Latif86dbcd02016-01-20 13:40:10 -0600138{
139 u64 temp;
Ismail, Mustafafa415372016-04-18 10:33:08 -0500140 u64 size;
141 u64 base = 0;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600142 u32 i, j;
Ismail, Mustafafa415372016-04-18 10:33:08 -0500143 u32 k = 0;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600144
145 /* copy base values in obj_info */
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500146 for (i = I40IW_HMC_IW_QP, j = 0; i <= I40IW_HMC_IW_PBLE; i++, j += 8) {
147 if ((i == I40IW_HMC_IW_SRQ) ||
148 (i == I40IW_HMC_IW_FSIMC) ||
149 (i == I40IW_HMC_IW_FSIAV)) {
150 info[i].base = 0;
151 info[i].cnt = 0;
152 continue;
153 }
Faisal Latif86dbcd02016-01-20 13:40:10 -0600154 get_64bit_val(buf, j, &temp);
155 info[i].base = RS_64_1(temp, 32) * 512;
Ismail, Mustafafa415372016-04-18 10:33:08 -0500156 if (info[i].base > base) {
157 base = info[i].base;
158 k = i;
159 }
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500160 if (i == I40IW_HMC_IW_APBVT_ENTRY) {
161 info[i].cnt = 1;
162 continue;
163 }
164 if (i == I40IW_HMC_IW_QP)
165 info[i].cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_QPS);
166 else if (i == I40IW_HMC_IW_CQ)
167 info[i].cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_CQS);
168 else
169 info[i].cnt = (u32)(temp);
Faisal Latif86dbcd02016-01-20 13:40:10 -0600170 }
Ismail, Mustafafa415372016-04-18 10:33:08 -0500171 size = info[k].cnt * info[k].size + info[k].base;
172 if (size & 0x1FFFFF)
173 *sd = (u32)((size >> 21) + 1); /* add 1 for remainder */
174 else
175 *sd = (u32)(size >> 21);
176
Faisal Latif86dbcd02016-01-20 13:40:10 -0600177 return 0;
178}
179
180/**
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500181 * i40iw_sc_decode_fpm_query() - Decode a 64 bit value into max count and size
182 * @buf: ptr to fpm query buffer
183 * @buf_idx: index into buf
184 * @info: ptr to i40iw_hmc_obj_info struct
185 * @rsrc_idx: resource index into info
186 *
187 * Decode a 64 bit value from fpm query buffer into max count and size
188 */
189static u64 i40iw_sc_decode_fpm_query(u64 *buf,
190 u32 buf_idx,
191 struct i40iw_hmc_obj_info *obj_info,
192 u32 rsrc_idx)
193{
194 u64 temp;
195 u32 size;
196
197 get_64bit_val(buf, buf_idx, &temp);
198 obj_info[rsrc_idx].max_cnt = (u32)temp;
199 size = (u32)RS_64_1(temp, 32);
200 obj_info[rsrc_idx].size = LS_64_1(1, size);
201
202 return temp;
203}
204
205/**
Faisal Latif86dbcd02016-01-20 13:40:10 -0600206 * i40iw_sc_parse_fpm_query_buf() - parses fpm query buffer
207 * @buf: ptr to fpm query buffer
208 * @info: ptr to i40iw_hmc_obj_info struct
209 * @hmc_fpm_misc: ptr to fpm data
210 *
211 * parses fpm query buffer and copy max_cnt and
212 * size value of hmc objects in hmc_info
213 */
214static enum i40iw_status_code i40iw_sc_parse_fpm_query_buf(
215 u64 *buf,
216 struct i40iw_hmc_info *hmc_info,
217 struct i40iw_hmc_fpm_misc *hmc_fpm_misc)
218{
Faisal Latif86dbcd02016-01-20 13:40:10 -0600219 struct i40iw_hmc_obj_info *obj_info;
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500220 u64 temp;
221 u32 size;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600222 u16 max_pe_sds;
223
224 obj_info = hmc_info->hmc_obj;
225
226 get_64bit_val(buf, 0, &temp);
227 hmc_info->first_sd_index = (u16)RS_64(temp, I40IW_QUERY_FPM_FIRST_PE_SD_INDEX);
228 max_pe_sds = (u16)RS_64(temp, I40IW_QUERY_FPM_MAX_PE_SDS);
229
230 /* Reduce SD count for VFs by 1 to account for PBLE backing page rounding */
231 if (hmc_info->hmc_fn_id >= I40IW_FIRST_VF_FPM_ID)
232 max_pe_sds--;
233 hmc_fpm_misc->max_sds = max_pe_sds;
234 hmc_info->sd_table.sd_cnt = max_pe_sds + hmc_info->first_sd_index;
235
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500236 get_64bit_val(buf, 8, &temp);
237 obj_info[I40IW_HMC_IW_QP].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_QPS);
238 size = (u32)RS_64_1(temp, 32);
239 obj_info[I40IW_HMC_IW_QP].size = LS_64_1(1, size);
Faisal Latif86dbcd02016-01-20 13:40:10 -0600240
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500241 get_64bit_val(buf, 16, &temp);
242 obj_info[I40IW_HMC_IW_CQ].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_CQS);
243 size = (u32)RS_64_1(temp, 32);
244 obj_info[I40IW_HMC_IW_CQ].size = LS_64_1(1, size);
Faisal Latif86dbcd02016-01-20 13:40:10 -0600245
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500246 i40iw_sc_decode_fpm_query(buf, 32, obj_info, I40IW_HMC_IW_HTE);
247 i40iw_sc_decode_fpm_query(buf, 40, obj_info, I40IW_HMC_IW_ARP);
248
249 obj_info[I40IW_HMC_IW_APBVT_ENTRY].size = 8192;
250 obj_info[I40IW_HMC_IW_APBVT_ENTRY].max_cnt = 1;
251
252 i40iw_sc_decode_fpm_query(buf, 48, obj_info, I40IW_HMC_IW_MR);
253 i40iw_sc_decode_fpm_query(buf, 56, obj_info, I40IW_HMC_IW_XF);
254
Faisal Latif86dbcd02016-01-20 13:40:10 -0600255 get_64bit_val(buf, 64, &temp);
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500256 obj_info[I40IW_HMC_IW_XFFL].max_cnt = (u32)temp;
257 obj_info[I40IW_HMC_IW_XFFL].size = 4;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600258 hmc_fpm_misc->xf_block_size = RS_64(temp, I40IW_QUERY_FPM_XFBLOCKSIZE);
259 if (!hmc_fpm_misc->xf_block_size)
260 return I40IW_ERR_INVALID_SIZE;
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500261
262 i40iw_sc_decode_fpm_query(buf, 72, obj_info, I40IW_HMC_IW_Q1);
263
Faisal Latif86dbcd02016-01-20 13:40:10 -0600264 get_64bit_val(buf, 80, &temp);
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500265 obj_info[I40IW_HMC_IW_Q1FL].max_cnt = (u32)temp;
266 obj_info[I40IW_HMC_IW_Q1FL].size = 4;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600267 hmc_fpm_misc->q1_block_size = RS_64(temp, I40IW_QUERY_FPM_Q1BLOCKSIZE);
268 if (!hmc_fpm_misc->q1_block_size)
269 return I40IW_ERR_INVALID_SIZE;
Chien Tin Tungf67ace22017-08-08 20:38:43 -0500270
271 i40iw_sc_decode_fpm_query(buf, 88, obj_info, I40IW_HMC_IW_TIMER);
272
273 get_64bit_val(buf, 112, &temp);
274 obj_info[I40IW_HMC_IW_PBLE].max_cnt = (u32)temp;
275 obj_info[I40IW_HMC_IW_PBLE].size = 8;
276
277 get_64bit_val(buf, 120, &temp);
278 hmc_fpm_misc->max_ceqs = (u8)RS_64(temp, I40IW_QUERY_FPM_MAX_CEQS);
279 hmc_fpm_misc->ht_multiplier = RS_64(temp, I40IW_QUERY_FPM_HTMULTIPLIER);
280 hmc_fpm_misc->timer_bucket = RS_64(temp, I40IW_QUERY_FPM_TIMERBUCKET);
281
Faisal Latif86dbcd02016-01-20 13:40:10 -0600282 return 0;
283}
284
285/**
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500286 * i40iw_fill_qos_list - Change all unknown qs handles to available ones
287 * @qs_list: list of qs_handles to be fixed with valid qs_handles
288 */
289static void i40iw_fill_qos_list(u16 *qs_list)
290{
291 u16 qshandle = qs_list[0];
292 int i;
293
294 for (i = 0; i < I40IW_MAX_USER_PRIORITY; i++) {
295 if (qs_list[i] == QS_HANDLE_UNKNOWN)
296 qs_list[i] = qshandle;
297 else
298 qshandle = qs_list[i];
299 }
300}
301
302/**
303 * i40iw_qp_from_entry - Given entry, get to the qp structure
304 * @entry: Points to list of qp structure
305 */
306static struct i40iw_sc_qp *i40iw_qp_from_entry(struct list_head *entry)
307{
308 if (!entry)
309 return NULL;
310
311 return (struct i40iw_sc_qp *)((char *)entry - offsetof(struct i40iw_sc_qp, list));
312}
313
314/**
315 * i40iw_get_qp - get the next qp from the list given current qp
316 * @head: Listhead of qp's
317 * @qp: current qp
318 */
319static struct i40iw_sc_qp *i40iw_get_qp(struct list_head *head, struct i40iw_sc_qp *qp)
320{
321 struct list_head *entry = NULL;
322 struct list_head *lastentry;
323
324 if (list_empty(head))
325 return NULL;
326
327 if (!qp) {
328 entry = head->next;
329 } else {
330 lastentry = &qp->list;
331 entry = (lastentry != head) ? lastentry->next : NULL;
332 }
333
334 return i40iw_qp_from_entry(entry);
335}
336
337/**
338 * i40iw_change_l2params - given the new l2 parameters, change all qp
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600339 * @vsi: pointer to the vsi structure
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500340 * @l2params: New paramaters from l2
341 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600342void i40iw_change_l2params(struct i40iw_sc_vsi *vsi, struct i40iw_l2params *l2params)
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500343{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600344 struct i40iw_sc_dev *dev = vsi->dev;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500345 struct i40iw_sc_qp *qp = NULL;
346 bool qs_handle_change = false;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500347 unsigned long flags;
348 u16 qs_handle;
349 int i;
350
Shiraz Saleemf300ba22017-05-19 16:14:02 -0500351 vsi->mss = l2params->mss;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500352
353 i40iw_fill_qos_list(l2params->qs_handle_list);
354 for (i = 0; i < I40IW_MAX_USER_PRIORITY; i++) {
355 qs_handle = l2params->qs_handle_list[i];
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600356 if (vsi->qos[i].qs_handle != qs_handle)
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500357 qs_handle_change = true;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600358 spin_lock_irqsave(&vsi->qos[i].lock, flags);
359 qp = i40iw_get_qp(&vsi->qos[i].qplist, qp);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500360 while (qp) {
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500361 if (qs_handle_change) {
362 qp->qs_handle = qs_handle;
363 /* issue cqp suspend command */
364 i40iw_qp_suspend_resume(dev, qp, true);
365 }
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600366 qp = i40iw_get_qp(&vsi->qos[i].qplist, qp);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500367 }
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600368 spin_unlock_irqrestore(&vsi->qos[i].lock, flags);
369 vsi->qos[i].qs_handle = qs_handle;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500370 }
371}
372
373/**
374 * i40iw_qp_rem_qos - remove qp from qos lists during destroy qp
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500375 * @qp: qp to be removed from qos
376 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600377static void i40iw_qp_rem_qos(struct i40iw_sc_qp *qp)
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500378{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600379 struct i40iw_sc_vsi *vsi = qp->vsi;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500380 unsigned long flags;
381
382 if (!qp->on_qoslist)
383 return;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600384 spin_lock_irqsave(&vsi->qos[qp->user_pri].lock, flags);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500385 list_del(&qp->list);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600386 spin_unlock_irqrestore(&vsi->qos[qp->user_pri].lock, flags);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500387}
388
389/**
390 * i40iw_qp_add_qos - called during setctx fot qp to be added to qos
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500391 * @qp: qp to be added to qos
392 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600393void i40iw_qp_add_qos(struct i40iw_sc_qp *qp)
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500394{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600395 struct i40iw_sc_vsi *vsi = qp->vsi;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500396 unsigned long flags;
397
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600398 if (qp->on_qoslist)
399 return;
400 spin_lock_irqsave(&vsi->qos[qp->user_pri].lock, flags);
401 qp->qs_handle = vsi->qos[qp->user_pri].qs_handle;
402 list_add(&qp->list, &vsi->qos[qp->user_pri].qplist);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500403 qp->on_qoslist = true;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600404 spin_unlock_irqrestore(&vsi->qos[qp->user_pri].lock, flags);
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500405}
406
407/**
Faisal Latif86dbcd02016-01-20 13:40:10 -0600408 * i40iw_sc_pd_init - initialize sc pd struct
409 * @dev: sc device struct
410 * @pd: sc pd ptr
411 * @pd_id: pd_id for allocated pd
Chien Tin Tung61f51b72016-12-21 08:53:46 -0600412 * @abi_ver: ABI version from user context, -1 if not valid
Faisal Latif86dbcd02016-01-20 13:40:10 -0600413 */
414static void i40iw_sc_pd_init(struct i40iw_sc_dev *dev,
415 struct i40iw_sc_pd *pd,
Chien Tin Tung61f51b72016-12-21 08:53:46 -0600416 u16 pd_id,
417 int abi_ver)
Faisal Latif86dbcd02016-01-20 13:40:10 -0600418{
419 pd->size = sizeof(*pd);
420 pd->pd_id = pd_id;
Chien Tin Tung61f51b72016-12-21 08:53:46 -0600421 pd->abi_ver = abi_ver;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600422 pd->dev = dev;
423}
424
425/**
426 * i40iw_get_encoded_wqe_size - given wq size, returns hardware encoded size
427 * @wqsize: size of the wq (sq, rq, srq) to encoded_size
428 * @cqpsq: encoded size for sq for cqp as its encoded size is 1+ other wq's
429 */
430u8 i40iw_get_encoded_wqe_size(u32 wqsize, bool cqpsq)
431{
432 u8 encoded_size = 0;
433
434 /* cqp sq's hw coded value starts from 1 for size of 4
435 * while it starts from 0 for qp' wq's.
436 */
437 if (cqpsq)
438 encoded_size = 1;
439 wqsize >>= 2;
440 while (wqsize >>= 1)
441 encoded_size++;
442 return encoded_size;
443}
444
445/**
446 * i40iw_sc_cqp_init - Initialize buffers for a control Queue Pair
447 * @cqp: IWARP control queue pair pointer
448 * @info: IWARP control queue pair init info pointer
449 *
450 * Initializes the object and context buffers for a control Queue Pair.
451 */
452static enum i40iw_status_code i40iw_sc_cqp_init(struct i40iw_sc_cqp *cqp,
453 struct i40iw_cqp_init_info *info)
454{
455 u8 hw_sq_size;
456
457 if ((info->sq_size > I40IW_CQP_SW_SQSIZE_2048) ||
458 (info->sq_size < I40IW_CQP_SW_SQSIZE_4) ||
459 ((info->sq_size & (info->sq_size - 1))))
460 return I40IW_ERR_INVALID_SIZE;
461
462 hw_sq_size = i40iw_get_encoded_wqe_size(info->sq_size, true);
463 cqp->size = sizeof(*cqp);
464 cqp->sq_size = info->sq_size;
465 cqp->hw_sq_size = hw_sq_size;
466 cqp->sq_base = info->sq;
467 cqp->host_ctx = info->host_ctx;
468 cqp->sq_pa = info->sq_pa;
469 cqp->host_ctx_pa = info->host_ctx_pa;
470 cqp->dev = info->dev;
471 cqp->struct_ver = info->struct_ver;
472 cqp->scratch_array = info->scratch_array;
473 cqp->polarity = 0;
474 cqp->en_datacenter_tcp = info->en_datacenter_tcp;
475 cqp->enabled_vf_count = info->enabled_vf_count;
476 cqp->hmc_profile = info->hmc_profile;
477 info->dev->cqp = cqp;
478
479 I40IW_RING_INIT(cqp->sq_ring, cqp->sq_size);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600480 cqp->dev->cqp_cmd_stats[OP_REQUESTED_COMMANDS] = 0;
481 cqp->dev->cqp_cmd_stats[OP_COMPLETED_COMMANDS] = 0;
482
Faisal Latif86dbcd02016-01-20 13:40:10 -0600483 i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
484 "%s: sq_size[%04d] hw_sq_size[%04d] sq_base[%p] sq_pa[%llxh] cqp[%p] polarity[x%04X]\n",
485 __func__, cqp->sq_size, cqp->hw_sq_size,
486 cqp->sq_base, cqp->sq_pa, cqp, cqp->polarity);
487 return 0;
488}
489
490/**
491 * i40iw_sc_cqp_create - create cqp during bringup
492 * @cqp: struct for cqp hw
Faisal Latif86dbcd02016-01-20 13:40:10 -0600493 * @maj_err: If error, major err number
494 * @min_err: If error, minor err number
495 */
496static enum i40iw_status_code i40iw_sc_cqp_create(struct i40iw_sc_cqp *cqp,
Faisal Latif86dbcd02016-01-20 13:40:10 -0600497 u16 *maj_err,
498 u16 *min_err)
499{
500 u64 temp;
501 u32 cnt = 0, p1, p2, val = 0, err_code;
502 enum i40iw_status_code ret_code;
503
Shiraz Saleem3f9fade2017-01-18 11:48:29 -0600504 *maj_err = 0;
505 *min_err = 0;
506
Faisal Latif86dbcd02016-01-20 13:40:10 -0600507 ret_code = i40iw_allocate_dma_mem(cqp->dev->hw,
508 &cqp->sdbuf,
509 128,
510 I40IW_SD_BUF_ALIGNMENT);
511
512 if (ret_code)
513 goto exit;
514
515 temp = LS_64(cqp->hw_sq_size, I40IW_CQPHC_SQSIZE) |
516 LS_64(cqp->struct_ver, I40IW_CQPHC_SVER);
517
Faisal Latif86dbcd02016-01-20 13:40:10 -0600518 set_64bit_val(cqp->host_ctx, 0, temp);
519 set_64bit_val(cqp->host_ctx, 8, cqp->sq_pa);
520 temp = LS_64(cqp->enabled_vf_count, I40IW_CQPHC_ENABLED_VFS) |
521 LS_64(cqp->hmc_profile, I40IW_CQPHC_HMC_PROFILE);
522 set_64bit_val(cqp->host_ctx, 16, temp);
523 set_64bit_val(cqp->host_ctx, 24, (uintptr_t)cqp);
524 set_64bit_val(cqp->host_ctx, 32, 0);
525 set_64bit_val(cqp->host_ctx, 40, 0);
526 set_64bit_val(cqp->host_ctx, 48, 0);
527 set_64bit_val(cqp->host_ctx, 56, 0);
528
529 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQP_HOST_CTX",
530 cqp->host_ctx, I40IW_CQP_CTX_SIZE * 8);
531
532 p1 = RS_32_1(cqp->host_ctx_pa, 32);
533 p2 = (u32)cqp->host_ctx_pa;
534
535 if (cqp->dev->is_pf) {
536 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, p1);
537 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, p2);
538 } else {
539 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, p1);
540 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, p2);
541 }
542 do {
543 if (cnt++ > I40IW_DONE_COUNT) {
544 i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
545 ret_code = I40IW_ERR_TIMEOUT;
546 /*
547 * read PFPE_CQPERRORCODES register to get the minor
548 * and major error code
549 */
550 if (cqp->dev->is_pf)
551 err_code = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES);
552 else
553 err_code = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
554 *min_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE);
555 *maj_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE);
556 goto exit;
557 }
558 udelay(I40IW_SLEEP_COUNT);
559 if (cqp->dev->is_pf)
560 val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CCQPSTATUS);
561 else
562 val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CCQPSTATUS1);
563 } while (!val);
564
565exit:
566 if (!ret_code)
567 cqp->process_cqp_sds = i40iw_update_sds_noccq;
568 return ret_code;
569}
570
571/**
572 * i40iw_sc_cqp_post_sq - post of cqp's sq
573 * @cqp: struct for cqp hw
574 */
575void i40iw_sc_cqp_post_sq(struct i40iw_sc_cqp *cqp)
576{
577 if (cqp->dev->is_pf)
578 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CQPDB, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
579 else
580 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CQPDB1, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
581
582 i40iw_debug(cqp->dev,
583 I40IW_DEBUG_WQE,
584 "%s: HEAD_TAIL[%04d,%04d,%04d]\n",
585 __func__,
586 cqp->sq_ring.head,
587 cqp->sq_ring.tail,
588 cqp->sq_ring.size);
589}
590
591/**
592 * i40iw_sc_cqp_get_next_send_wqe - get next wqe on cqp sq
593 * @cqp: struct for cqp hw
594 * @wqe_idx: we index of cqp ring
595 */
596u64 *i40iw_sc_cqp_get_next_send_wqe(struct i40iw_sc_cqp *cqp, u64 scratch)
597{
598 u64 *wqe = NULL;
599 u32 wqe_idx;
600 enum i40iw_status_code ret_code;
601
602 if (I40IW_RING_FULL_ERR(cqp->sq_ring)) {
603 i40iw_debug(cqp->dev,
604 I40IW_DEBUG_WQE,
605 "%s: ring is full head %x tail %x size %x\n",
606 __func__,
607 cqp->sq_ring.head,
608 cqp->sq_ring.tail,
609 cqp->sq_ring.size);
610 return NULL;
611 }
612 I40IW_ATOMIC_RING_MOVE_HEAD(cqp->sq_ring, wqe_idx, ret_code);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600613 cqp->dev->cqp_cmd_stats[OP_REQUESTED_COMMANDS]++;
Faisal Latif86dbcd02016-01-20 13:40:10 -0600614 if (ret_code)
615 return NULL;
616 if (!wqe_idx)
617 cqp->polarity = !cqp->polarity;
618
619 wqe = cqp->sq_base[wqe_idx].elem;
620 cqp->scratch_array[wqe_idx] = scratch;
621 I40IW_CQP_INIT_WQE(wqe);
622
623 return wqe;
624}
625
626/**
627 * i40iw_sc_cqp_destroy - destroy cqp during close
628 * @cqp: struct for cqp hw
629 */
630static enum i40iw_status_code i40iw_sc_cqp_destroy(struct i40iw_sc_cqp *cqp)
631{
632 u32 cnt = 0, val = 1;
633 enum i40iw_status_code ret_code = 0;
634 u32 cqpstat_addr;
635
636 if (cqp->dev->is_pf) {
637 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, 0);
638 i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, 0);
639 cqpstat_addr = I40E_PFPE_CCQPSTATUS;
640 } else {
641 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, 0);
642 i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, 0);
643 cqpstat_addr = I40E_VFPE_CCQPSTATUS1;
644 }
645 do {
646 if (cnt++ > I40IW_DONE_COUNT) {
647 ret_code = I40IW_ERR_TIMEOUT;
648 break;
649 }
650 udelay(I40IW_SLEEP_COUNT);
651 val = i40iw_rd32(cqp->dev->hw, cqpstat_addr);
652 } while (val);
653
654 i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
655 return ret_code;
656}
657
658/**
659 * i40iw_sc_ccq_arm - enable intr for control cq
660 * @ccq: ccq sc struct
661 */
662static void i40iw_sc_ccq_arm(struct i40iw_sc_cq *ccq)
663{
664 u64 temp_val;
665 u16 sw_cq_sel;
666 u8 arm_next_se;
667 u8 arm_seq_num;
668
669 /* write to cq doorbell shadow area */
670 /* arm next se should always be zero */
671 get_64bit_val(ccq->cq_uk.shadow_area, 32, &temp_val);
672
673 sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
674 arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
675
676 arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
677 arm_seq_num++;
678
679 temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
680 LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
681 LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
682 LS_64(1, I40IW_CQ_DBSA_ARM_NEXT);
683
684 set_64bit_val(ccq->cq_uk.shadow_area, 32, temp_val);
685
686 wmb(); /* make sure shadow area is updated before arming */
687
688 if (ccq->dev->is_pf)
689 i40iw_wr32(ccq->dev->hw, I40E_PFPE_CQARM, ccq->cq_uk.cq_id);
690 else
691 i40iw_wr32(ccq->dev->hw, I40E_VFPE_CQARM1, ccq->cq_uk.cq_id);
692}
693
694/**
695 * i40iw_sc_ccq_get_cqe_info - get ccq's cq entry
696 * @ccq: ccq sc struct
697 * @info: completion q entry to return
698 */
699static enum i40iw_status_code i40iw_sc_ccq_get_cqe_info(
700 struct i40iw_sc_cq *ccq,
701 struct i40iw_ccq_cqe_info *info)
702{
703 u64 qp_ctx, temp, temp1;
704 u64 *cqe;
705 struct i40iw_sc_cqp *cqp;
706 u32 wqe_idx;
707 u8 polarity;
708 enum i40iw_status_code ret_code = 0;
709
710 if (ccq->cq_uk.avoid_mem_cflct)
711 cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(&ccq->cq_uk);
712 else
713 cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(&ccq->cq_uk);
714
715 get_64bit_val(cqe, 24, &temp);
716 polarity = (u8)RS_64(temp, I40IW_CQ_VALID);
717 if (polarity != ccq->cq_uk.polarity)
718 return I40IW_ERR_QUEUE_EMPTY;
719
720 get_64bit_val(cqe, 8, &qp_ctx);
721 cqp = (struct i40iw_sc_cqp *)(unsigned long)qp_ctx;
722 info->error = (bool)RS_64(temp, I40IW_CQ_ERROR);
723 info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
724 if (info->error) {
725 info->maj_err_code = (u16)RS_64(temp, I40IW_CQ_MAJERR);
726 info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
727 }
728 wqe_idx = (u32)RS_64(temp, I40IW_CQ_WQEIDX);
729 info->scratch = cqp->scratch_array[wqe_idx];
730
731 get_64bit_val(cqe, 16, &temp1);
732 info->op_ret_val = (u32)RS_64(temp1, I40IW_CCQ_OPRETVAL);
733 get_64bit_val(cqp->sq_base[wqe_idx].elem, 24, &temp1);
734 info->op_code = (u8)RS_64(temp1, I40IW_CQPSQ_OPCODE);
735 info->cqp = cqp;
736
737 /* move the head for cq */
738 I40IW_RING_MOVE_HEAD(ccq->cq_uk.cq_ring, ret_code);
739 if (I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring) == 0)
740 ccq->cq_uk.polarity ^= 1;
741
742 /* update cq tail in cq shadow memory also */
743 I40IW_RING_MOVE_TAIL(ccq->cq_uk.cq_ring);
744 set_64bit_val(ccq->cq_uk.shadow_area,
745 0,
746 I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring));
747 wmb(); /* write shadow area before tail */
748 I40IW_RING_MOVE_TAIL(cqp->sq_ring);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -0600749 ccq->dev->cqp_cmd_stats[OP_COMPLETED_COMMANDS]++;
750
Faisal Latif86dbcd02016-01-20 13:40:10 -0600751 return ret_code;
752}
753
754/**
755 * i40iw_sc_poll_for_cqp_op_done - Waits for last write to complete in CQP SQ
756 * @cqp: struct for cqp hw
757 * @op_code: cqp opcode for completion
758 * @info: completion q entry to return
759 */
760static enum i40iw_status_code i40iw_sc_poll_for_cqp_op_done(
761 struct i40iw_sc_cqp *cqp,
762 u8 op_code,
763 struct i40iw_ccq_cqe_info *compl_info)
764{
765 struct i40iw_ccq_cqe_info info;
766 struct i40iw_sc_cq *ccq;
767 enum i40iw_status_code ret_code = 0;
768 u32 cnt = 0;
769
770 memset(&info, 0, sizeof(info));
771 ccq = cqp->dev->ccq;
772 while (1) {
773 if (cnt++ > I40IW_DONE_COUNT)
774 return I40IW_ERR_TIMEOUT;
775
776 if (i40iw_sc_ccq_get_cqe_info(ccq, &info)) {
777 udelay(I40IW_SLEEP_COUNT);
778 continue;
779 }
780
781 if (info.error) {
782 ret_code = I40IW_ERR_CQP_COMPL_ERROR;
783 break;
784 }
785 /* check if opcode is cq create */
786 if (op_code != info.op_code) {
787 i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
788 "%s: opcode mismatch for my op code 0x%x, returned opcode %x\n",
789 __func__, op_code, info.op_code);
790 }
791 /* success, exit out of the loop */
792 if (op_code == info.op_code)
793 break;
794 }
795
796 if (compl_info)
797 memcpy(compl_info, &info, sizeof(*compl_info));
798
799 return ret_code;
800}
801
802/**
803 * i40iw_sc_manage_push_page - Handle push page
804 * @cqp: struct for cqp hw
805 * @info: push page info
806 * @scratch: u64 saved to be used during cqp completion
807 * @post_sq: flag for cqp db to ring
808 */
809static enum i40iw_status_code i40iw_sc_manage_push_page(
810 struct i40iw_sc_cqp *cqp,
811 struct i40iw_cqp_manage_push_page_info *info,
812 u64 scratch,
813 bool post_sq)
814{
815 u64 *wqe;
816 u64 header;
817
818 if (info->push_idx >= I40IW_MAX_PUSH_PAGE_COUNT)
819 return I40IW_ERR_INVALID_PUSH_PAGE_INDEX;
820
821 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
822 if (!wqe)
823 return I40IW_ERR_RING_FULL;
824
825 set_64bit_val(wqe, 16, info->qs_handle);
826
827 header = LS_64(info->push_idx, I40IW_CQPSQ_MPP_PPIDX) |
828 LS_64(I40IW_CQP_OP_MANAGE_PUSH_PAGES, I40IW_CQPSQ_OPCODE) |
829 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
830 LS_64(info->free_page, I40IW_CQPSQ_MPP_FREE_PAGE);
831
832 i40iw_insert_wqe_hdr(wqe, header);
833
834 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_PUSH_PAGES WQE",
835 wqe, I40IW_CQP_WQE_SIZE * 8);
836
837 if (post_sq)
838 i40iw_sc_cqp_post_sq(cqp);
839 return 0;
840}
841
842/**
843 * i40iw_sc_manage_hmc_pm_func_table - manage of function table
844 * @cqp: struct for cqp hw
845 * @scratch: u64 saved to be used during cqp completion
846 * @vf_index: vf index for cqp
847 * @free_pm_fcn: function number
848 * @post_sq: flag for cqp db to ring
849 */
850static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table(
851 struct i40iw_sc_cqp *cqp,
852 u64 scratch,
853 u8 vf_index,
854 bool free_pm_fcn,
855 bool post_sq)
856{
857 u64 *wqe;
858 u64 header;
859
860 if (vf_index >= I40IW_MAX_VF_PER_PF)
861 return I40IW_ERR_INVALID_VF_ID;
862 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
863 if (!wqe)
864 return I40IW_ERR_RING_FULL;
865
866 header = LS_64(vf_index, I40IW_CQPSQ_MHMC_VFIDX) |
867 LS_64(I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, I40IW_CQPSQ_OPCODE) |
868 LS_64(free_pm_fcn, I40IW_CQPSQ_MHMC_FREEPMFN) |
869 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
870
871 i40iw_insert_wqe_hdr(wqe, header);
872 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
873 wqe, I40IW_CQP_WQE_SIZE * 8);
874 if (post_sq)
875 i40iw_sc_cqp_post_sq(cqp);
876 return 0;
877}
878
879/**
880 * i40iw_sc_set_hmc_resource_profile - cqp wqe for hmc profile
881 * @cqp: struct for cqp hw
882 * @scratch: u64 saved to be used during cqp completion
883 * @hmc_profile_type: type of profile to set
884 * @vf_num: vf number for profile
885 * @post_sq: flag for cqp db to ring
886 * @poll_registers: flag to poll register for cqp completion
887 */
888static enum i40iw_status_code i40iw_sc_set_hmc_resource_profile(
889 struct i40iw_sc_cqp *cqp,
890 u64 scratch,
891 u8 hmc_profile_type,
892 u8 vf_num, bool post_sq,
893 bool poll_registers)
894{
895 u64 *wqe;
896 u64 header;
897 u32 val, tail, error;
898 enum i40iw_status_code ret_code = 0;
899
900 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
901 if (!wqe)
902 return I40IW_ERR_RING_FULL;
903
904 set_64bit_val(wqe, 16,
905 (LS_64(hmc_profile_type, I40IW_CQPSQ_SHMCRP_HMC_PROFILE) |
906 LS_64(vf_num, I40IW_CQPSQ_SHMCRP_VFNUM)));
907
908 header = LS_64(I40IW_CQP_OP_SET_HMC_RESOURCE_PROFILE, I40IW_CQPSQ_OPCODE) |
909 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
910
911 i40iw_insert_wqe_hdr(wqe, header);
912
913 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
914 wqe, I40IW_CQP_WQE_SIZE * 8);
915
916 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
917 if (error)
918 return I40IW_ERR_CQP_COMPL_ERROR;
919
920 if (post_sq) {
921 i40iw_sc_cqp_post_sq(cqp);
922 if (poll_registers)
923 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000000);
924 else
925 ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
926 I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
927 NULL);
928 }
929
930 return ret_code;
931}
932
933/**
934 * i40iw_sc_manage_hmc_pm_func_table_done - wait for cqp wqe completion for function table
935 * @cqp: struct for cqp hw
936 */
937static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table_done(struct i40iw_sc_cqp *cqp)
938{
939 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, NULL);
940}
941
942/**
943 * i40iw_sc_commit_fpm_values_done - wait for cqp eqe completion for fpm commit
944 * @cqp: struct for cqp hw
945 */
946static enum i40iw_status_code i40iw_sc_commit_fpm_values_done(struct i40iw_sc_cqp *cqp)
947{
948 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_COMMIT_FPM_VALUES, NULL);
949}
950
951/**
952 * i40iw_sc_commit_fpm_values - cqp wqe for commit fpm values
953 * @cqp: struct for cqp hw
954 * @scratch: u64 saved to be used during cqp completion
955 * @hmc_fn_id: hmc function id
956 * @commit_fpm_mem; Memory for fpm values
957 * @post_sq: flag for cqp db to ring
958 * @wait_type: poll ccq or cqp registers for cqp completion
959 */
960static enum i40iw_status_code i40iw_sc_commit_fpm_values(
961 struct i40iw_sc_cqp *cqp,
962 u64 scratch,
963 u8 hmc_fn_id,
964 struct i40iw_dma_mem *commit_fpm_mem,
965 bool post_sq,
966 u8 wait_type)
967{
968 u64 *wqe;
969 u64 header;
970 u32 tail, val, error;
971 enum i40iw_status_code ret_code = 0;
972
973 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
974 if (!wqe)
975 return I40IW_ERR_RING_FULL;
976
977 set_64bit_val(wqe, 16, hmc_fn_id);
978 set_64bit_val(wqe, 32, commit_fpm_mem->pa);
979
980 header = LS_64(I40IW_CQP_OP_COMMIT_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
981 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
982
983 i40iw_insert_wqe_hdr(wqe, header);
984
985 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "COMMIT_FPM_VALUES WQE",
986 wqe, I40IW_CQP_WQE_SIZE * 8);
987
988 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
989 if (error)
990 return I40IW_ERR_CQP_COMPL_ERROR;
991
992 if (post_sq) {
993 i40iw_sc_cqp_post_sq(cqp);
994
995 if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
996 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
997 else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
998 ret_code = i40iw_sc_commit_fpm_values_done(cqp);
999 }
1000
1001 return ret_code;
1002}
1003
1004/**
1005 * i40iw_sc_query_fpm_values_done - poll for cqp wqe completion for query fpm
1006 * @cqp: struct for cqp hw
1007 */
1008static enum i40iw_status_code i40iw_sc_query_fpm_values_done(struct i40iw_sc_cqp *cqp)
1009{
1010 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_QUERY_FPM_VALUES, NULL);
1011}
1012
1013/**
1014 * i40iw_sc_query_fpm_values - cqp wqe query fpm values
1015 * @cqp: struct for cqp hw
1016 * @scratch: u64 saved to be used during cqp completion
1017 * @hmc_fn_id: hmc function id
1018 * @query_fpm_mem: memory for return fpm values
1019 * @post_sq: flag for cqp db to ring
1020 * @wait_type: poll ccq or cqp registers for cqp completion
1021 */
1022static enum i40iw_status_code i40iw_sc_query_fpm_values(
1023 struct i40iw_sc_cqp *cqp,
1024 u64 scratch,
1025 u8 hmc_fn_id,
1026 struct i40iw_dma_mem *query_fpm_mem,
1027 bool post_sq,
1028 u8 wait_type)
1029{
1030 u64 *wqe;
1031 u64 header;
1032 u32 tail, val, error;
1033 enum i40iw_status_code ret_code = 0;
1034
1035 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1036 if (!wqe)
1037 return I40IW_ERR_RING_FULL;
1038
1039 set_64bit_val(wqe, 16, hmc_fn_id);
1040 set_64bit_val(wqe, 32, query_fpm_mem->pa);
1041
1042 header = LS_64(I40IW_CQP_OP_QUERY_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
1043 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1044
1045 i40iw_insert_wqe_hdr(wqe, header);
1046
1047 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_FPM WQE",
1048 wqe, I40IW_CQP_WQE_SIZE * 8);
1049
1050 /* read the tail from CQP_TAIL register */
1051 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
1052
1053 if (error)
1054 return I40IW_ERR_CQP_COMPL_ERROR;
1055
1056 if (post_sq) {
1057 i40iw_sc_cqp_post_sq(cqp);
1058 if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
1059 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
1060 else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
1061 ret_code = i40iw_sc_query_fpm_values_done(cqp);
1062 }
1063
1064 return ret_code;
1065}
1066
1067/**
1068 * i40iw_sc_add_arp_cache_entry - cqp wqe add arp cache entry
1069 * @cqp: struct for cqp hw
1070 * @info: arp entry information
1071 * @scratch: u64 saved to be used during cqp completion
1072 * @post_sq: flag for cqp db to ring
1073 */
1074static enum i40iw_status_code i40iw_sc_add_arp_cache_entry(
1075 struct i40iw_sc_cqp *cqp,
1076 struct i40iw_add_arp_cache_entry_info *info,
1077 u64 scratch,
1078 bool post_sq)
1079{
1080 u64 *wqe;
1081 u64 temp, header;
1082
1083 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1084 if (!wqe)
1085 return I40IW_ERR_RING_FULL;
1086 set_64bit_val(wqe, 8, info->reach_max);
1087
1088 temp = info->mac_addr[5] |
1089 LS_64_1(info->mac_addr[4], 8) |
1090 LS_64_1(info->mac_addr[3], 16) |
1091 LS_64_1(info->mac_addr[2], 24) |
1092 LS_64_1(info->mac_addr[1], 32) |
1093 LS_64_1(info->mac_addr[0], 40);
1094
1095 set_64bit_val(wqe, 16, temp);
1096
1097 header = info->arp_index |
1098 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
1099 LS_64((info->permanent ? 1 : 0), I40IW_CQPSQ_MAT_PERMANENT) |
1100 LS_64(1, I40IW_CQPSQ_MAT_ENTRYVALID) |
1101 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1102
1103 i40iw_insert_wqe_hdr(wqe, header);
1104
1105 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_ENTRY WQE",
1106 wqe, I40IW_CQP_WQE_SIZE * 8);
1107
1108 if (post_sq)
1109 i40iw_sc_cqp_post_sq(cqp);
1110 return 0;
1111}
1112
1113/**
1114 * i40iw_sc_del_arp_cache_entry - dele arp cache entry
1115 * @cqp: struct for cqp hw
1116 * @scratch: u64 saved to be used during cqp completion
1117 * @arp_index: arp index to delete arp entry
1118 * @post_sq: flag for cqp db to ring
1119 */
1120static enum i40iw_status_code i40iw_sc_del_arp_cache_entry(
1121 struct i40iw_sc_cqp *cqp,
1122 u64 scratch,
1123 u16 arp_index,
1124 bool post_sq)
1125{
1126 u64 *wqe;
1127 u64 header;
1128
1129 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1130 if (!wqe)
1131 return I40IW_ERR_RING_FULL;
1132
1133 header = arp_index |
1134 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
1135 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1136 i40iw_insert_wqe_hdr(wqe, header);
1137
1138 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_DEL_ENTRY WQE",
1139 wqe, I40IW_CQP_WQE_SIZE * 8);
1140
1141 if (post_sq)
1142 i40iw_sc_cqp_post_sq(cqp);
1143 return 0;
1144}
1145
1146/**
1147 * i40iw_sc_query_arp_cache_entry - cqp wqe to query arp and arp index
1148 * @cqp: struct for cqp hw
1149 * @scratch: u64 saved to be used during cqp completion
1150 * @arp_index: arp index to delete arp entry
1151 * @post_sq: flag for cqp db to ring
1152 */
1153static enum i40iw_status_code i40iw_sc_query_arp_cache_entry(
1154 struct i40iw_sc_cqp *cqp,
1155 u64 scratch,
1156 u16 arp_index,
1157 bool post_sq)
1158{
1159 u64 *wqe;
1160 u64 header;
1161
1162 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1163 if (!wqe)
1164 return I40IW_ERR_RING_FULL;
1165
1166 header = arp_index |
1167 LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
1168 LS_64(1, I40IW_CQPSQ_MAT_QUERY) |
1169 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1170
1171 i40iw_insert_wqe_hdr(wqe, header);
1172
1173 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_ARP_CACHE_ENTRY WQE",
1174 wqe, I40IW_CQP_WQE_SIZE * 8);
1175
1176 if (post_sq)
1177 i40iw_sc_cqp_post_sq(cqp);
1178 return 0;
1179}
1180
1181/**
1182 * i40iw_sc_manage_apbvt_entry - for adding and deleting apbvt entries
1183 * @cqp: struct for cqp hw
1184 * @info: info for apbvt entry to add or delete
1185 * @scratch: u64 saved to be used during cqp completion
1186 * @post_sq: flag for cqp db to ring
1187 */
1188static enum i40iw_status_code i40iw_sc_manage_apbvt_entry(
1189 struct i40iw_sc_cqp *cqp,
1190 struct i40iw_apbvt_info *info,
1191 u64 scratch,
1192 bool post_sq)
1193{
1194 u64 *wqe;
1195 u64 header;
1196
1197 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1198 if (!wqe)
1199 return I40IW_ERR_RING_FULL;
1200
1201 set_64bit_val(wqe, 16, info->port);
1202
1203 header = LS_64(I40IW_CQP_OP_MANAGE_APBVT, I40IW_CQPSQ_OPCODE) |
1204 LS_64(info->add, I40IW_CQPSQ_MAPT_ADDPORT) |
1205 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1206
1207 i40iw_insert_wqe_hdr(wqe, header);
1208
1209 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_APBVT WQE",
1210 wqe, I40IW_CQP_WQE_SIZE * 8);
1211
1212 if (post_sq)
1213 i40iw_sc_cqp_post_sq(cqp);
1214 return 0;
1215}
1216
1217/**
1218 * i40iw_sc_manage_qhash_table_entry - manage quad hash entries
1219 * @cqp: struct for cqp hw
1220 * @info: info for quad hash to manage
1221 * @scratch: u64 saved to be used during cqp completion
1222 * @post_sq: flag for cqp db to ring
1223 *
1224 * This is called before connection establishment is started. For passive connections, when
1225 * listener is created, it will call with entry type of I40IW_QHASH_TYPE_TCP_SYN with local
1226 * ip address and tcp port. When SYN is received (passive connections) or
1227 * sent (active connections), this routine is called with entry type of
1228 * I40IW_QHASH_TYPE_TCP_ESTABLISHED and quad is passed in info.
1229 *
1230 * When iwarp connection is done and its state moves to RTS, the quad hash entry in
1231 * the hardware will point to iwarp's qp number and requires no calls from the driver.
1232 */
1233static enum i40iw_status_code i40iw_sc_manage_qhash_table_entry(
1234 struct i40iw_sc_cqp *cqp,
1235 struct i40iw_qhash_table_info *info,
1236 u64 scratch,
1237 bool post_sq)
1238{
1239 u64 *wqe;
1240 u64 qw1 = 0;
1241 u64 qw2 = 0;
1242 u64 temp;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06001243 struct i40iw_sc_vsi *vsi = info->vsi;
Faisal Latif86dbcd02016-01-20 13:40:10 -06001244
1245 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1246 if (!wqe)
1247 return I40IW_ERR_RING_FULL;
1248
1249 temp = info->mac_addr[5] |
1250 LS_64_1(info->mac_addr[4], 8) |
1251 LS_64_1(info->mac_addr[3], 16) |
1252 LS_64_1(info->mac_addr[2], 24) |
1253 LS_64_1(info->mac_addr[1], 32) |
1254 LS_64_1(info->mac_addr[0], 40);
1255
1256 set_64bit_val(wqe, 0, temp);
1257
1258 qw1 = LS_64(info->qp_num, I40IW_CQPSQ_QHASH_QPN) |
1259 LS_64(info->dest_port, I40IW_CQPSQ_QHASH_DEST_PORT);
1260 if (info->ipv4_valid) {
1261 set_64bit_val(wqe,
1262 48,
1263 LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
1264 } else {
1265 set_64bit_val(wqe,
1266 56,
1267 LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
1268 LS_64(info->dest_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
1269
1270 set_64bit_val(wqe,
1271 48,
1272 LS_64(info->dest_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
1273 LS_64(info->dest_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
1274 }
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06001275 qw2 = LS_64(vsi->qos[info->user_pri].qs_handle, I40IW_CQPSQ_QHASH_QS_HANDLE);
Faisal Latif86dbcd02016-01-20 13:40:10 -06001276 if (info->vlan_valid)
1277 qw2 |= LS_64(info->vlan_id, I40IW_CQPSQ_QHASH_VLANID);
1278 set_64bit_val(wqe, 16, qw2);
1279 if (info->entry_type == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
1280 qw1 |= LS_64(info->src_port, I40IW_CQPSQ_QHASH_SRC_PORT);
1281 if (!info->ipv4_valid) {
1282 set_64bit_val(wqe,
1283 40,
1284 LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
1285 LS_64(info->src_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
1286 set_64bit_val(wqe,
1287 32,
1288 LS_64(info->src_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
1289 LS_64(info->src_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
1290 } else {
1291 set_64bit_val(wqe,
1292 32,
1293 LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
1294 }
1295 }
1296
1297 set_64bit_val(wqe, 8, qw1);
1298 temp = LS_64(cqp->polarity, I40IW_CQPSQ_QHASH_WQEVALID) |
1299 LS_64(I40IW_CQP_OP_MANAGE_QUAD_HASH_TABLE_ENTRY, I40IW_CQPSQ_QHASH_OPCODE) |
1300 LS_64(info->manage, I40IW_CQPSQ_QHASH_MANAGE) |
1301 LS_64(info->ipv4_valid, I40IW_CQPSQ_QHASH_IPV4VALID) |
1302 LS_64(info->vlan_valid, I40IW_CQPSQ_QHASH_VLANVALID) |
1303 LS_64(info->entry_type, I40IW_CQPSQ_QHASH_ENTRYTYPE);
1304
1305 i40iw_insert_wqe_hdr(wqe, temp);
1306
1307 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_QHASH WQE",
1308 wqe, I40IW_CQP_WQE_SIZE * 8);
1309
1310 if (post_sq)
1311 i40iw_sc_cqp_post_sq(cqp);
1312 return 0;
1313}
1314
1315/**
1316 * i40iw_sc_alloc_local_mac_ipaddr_entry - cqp wqe for loc mac entry
1317 * @cqp: struct for cqp hw
1318 * @scratch: u64 saved to be used during cqp completion
1319 * @post_sq: flag for cqp db to ring
1320 */
1321static enum i40iw_status_code i40iw_sc_alloc_local_mac_ipaddr_entry(
1322 struct i40iw_sc_cqp *cqp,
1323 u64 scratch,
1324 bool post_sq)
1325{
1326 u64 *wqe;
1327 u64 header;
1328
1329 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1330 if (!wqe)
1331 return I40IW_ERR_RING_FULL;
1332 header = LS_64(I40IW_CQP_OP_ALLOCATE_LOC_MAC_IP_TABLE_ENTRY, I40IW_CQPSQ_OPCODE) |
1333 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1334
1335 i40iw_insert_wqe_hdr(wqe, header);
1336 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ALLOCATE_LOCAL_MAC_IPADDR WQE",
1337 wqe, I40IW_CQP_WQE_SIZE * 8);
1338 if (post_sq)
1339 i40iw_sc_cqp_post_sq(cqp);
1340 return 0;
1341}
1342
1343/**
1344 * i40iw_sc_add_local_mac_ipaddr_entry - add mac enry
1345 * @cqp: struct for cqp hw
1346 * @info:mac addr info
1347 * @scratch: u64 saved to be used during cqp completion
1348 * @post_sq: flag for cqp db to ring
1349 */
1350static enum i40iw_status_code i40iw_sc_add_local_mac_ipaddr_entry(
1351 struct i40iw_sc_cqp *cqp,
1352 struct i40iw_local_mac_ipaddr_entry_info *info,
1353 u64 scratch,
1354 bool post_sq)
1355{
1356 u64 *wqe;
1357 u64 temp, header;
1358
1359 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1360 if (!wqe)
1361 return I40IW_ERR_RING_FULL;
1362 temp = info->mac_addr[5] |
1363 LS_64_1(info->mac_addr[4], 8) |
1364 LS_64_1(info->mac_addr[3], 16) |
1365 LS_64_1(info->mac_addr[2], 24) |
1366 LS_64_1(info->mac_addr[1], 32) |
1367 LS_64_1(info->mac_addr[0], 40);
1368
1369 set_64bit_val(wqe, 32, temp);
1370
1371 header = LS_64(info->entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
1372 LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
1373 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1374
1375 i40iw_insert_wqe_hdr(wqe, header);
1376
1377 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ADD_LOCAL_MAC_IPADDR WQE",
1378 wqe, I40IW_CQP_WQE_SIZE * 8);
1379
1380 if (post_sq)
1381 i40iw_sc_cqp_post_sq(cqp);
1382 return 0;
1383}
1384
1385/**
1386 * i40iw_sc_del_local_mac_ipaddr_entry - cqp wqe to dele local mac
1387 * @cqp: struct for cqp hw
1388 * @scratch: u64 saved to be used during cqp completion
1389 * @entry_idx: index of mac entry
1390 * @ ignore_ref_count: to force mac adde delete
1391 * @post_sq: flag for cqp db to ring
1392 */
1393static enum i40iw_status_code i40iw_sc_del_local_mac_ipaddr_entry(
1394 struct i40iw_sc_cqp *cqp,
1395 u64 scratch,
1396 u8 entry_idx,
1397 u8 ignore_ref_count,
1398 bool post_sq)
1399{
1400 u64 *wqe;
1401 u64 header;
1402
1403 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1404 if (!wqe)
1405 return I40IW_ERR_RING_FULL;
1406 header = LS_64(entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
1407 LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
1408 LS_64(1, I40IW_CQPSQ_MLIPA_FREEENTRY) |
1409 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
1410 LS_64(ignore_ref_count, I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT);
1411
1412 i40iw_insert_wqe_hdr(wqe, header);
1413
1414 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "DEL_LOCAL_MAC_IPADDR WQE",
1415 wqe, I40IW_CQP_WQE_SIZE * 8);
1416
1417 if (post_sq)
1418 i40iw_sc_cqp_post_sq(cqp);
1419 return 0;
1420}
1421
1422/**
1423 * i40iw_sc_cqp_nop - send a nop wqe
1424 * @cqp: struct for cqp hw
1425 * @scratch: u64 saved to be used during cqp completion
1426 * @post_sq: flag for cqp db to ring
1427 */
1428static enum i40iw_status_code i40iw_sc_cqp_nop(struct i40iw_sc_cqp *cqp,
1429 u64 scratch,
1430 bool post_sq)
1431{
1432 u64 *wqe;
1433 u64 header;
1434
1435 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1436 if (!wqe)
1437 return I40IW_ERR_RING_FULL;
1438 header = LS_64(I40IW_CQP_OP_NOP, I40IW_CQPSQ_OPCODE) |
1439 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1440 i40iw_insert_wqe_hdr(wqe, header);
1441 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "NOP WQE",
1442 wqe, I40IW_CQP_WQE_SIZE * 8);
1443
1444 if (post_sq)
1445 i40iw_sc_cqp_post_sq(cqp);
1446 return 0;
1447}
1448
1449/**
1450 * i40iw_sc_ceq_init - initialize ceq
1451 * @ceq: ceq sc structure
1452 * @info: ceq initialization info
1453 */
1454static enum i40iw_status_code i40iw_sc_ceq_init(struct i40iw_sc_ceq *ceq,
1455 struct i40iw_ceq_init_info *info)
1456{
1457 u32 pble_obj_cnt;
1458
1459 if ((info->elem_cnt < I40IW_MIN_CEQ_ENTRIES) ||
1460 (info->elem_cnt > I40IW_MAX_CEQ_ENTRIES))
1461 return I40IW_ERR_INVALID_SIZE;
1462
1463 if (info->ceq_id >= I40IW_MAX_CEQID)
1464 return I40IW_ERR_INVALID_CEQ_ID;
1465
1466 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1467
1468 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1469 return I40IW_ERR_INVALID_PBLE_INDEX;
1470
1471 ceq->size = sizeof(*ceq);
1472 ceq->ceqe_base = (struct i40iw_ceqe *)info->ceqe_base;
1473 ceq->ceq_id = info->ceq_id;
1474 ceq->dev = info->dev;
1475 ceq->elem_cnt = info->elem_cnt;
1476 ceq->ceq_elem_pa = info->ceqe_pa;
1477 ceq->virtual_map = info->virtual_map;
1478
1479 ceq->pbl_chunk_size = (ceq->virtual_map ? info->pbl_chunk_size : 0);
1480 ceq->first_pm_pbl_idx = (ceq->virtual_map ? info->first_pm_pbl_idx : 0);
1481 ceq->pbl_list = (ceq->virtual_map ? info->pbl_list : NULL);
1482
1483 ceq->tph_en = info->tph_en;
1484 ceq->tph_val = info->tph_val;
1485 ceq->polarity = 1;
1486 I40IW_RING_INIT(ceq->ceq_ring, ceq->elem_cnt);
1487 ceq->dev->ceq[info->ceq_id] = ceq;
1488
1489 return 0;
1490}
1491
1492/**
1493 * i40iw_sc_ceq_create - create ceq wqe
1494 * @ceq: ceq sc structure
1495 * @scratch: u64 saved to be used during cqp completion
1496 * @post_sq: flag for cqp db to ring
1497 */
1498static enum i40iw_status_code i40iw_sc_ceq_create(struct i40iw_sc_ceq *ceq,
1499 u64 scratch,
1500 bool post_sq)
1501{
1502 struct i40iw_sc_cqp *cqp;
1503 u64 *wqe;
1504 u64 header;
1505
1506 cqp = ceq->dev->cqp;
1507 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1508 if (!wqe)
1509 return I40IW_ERR_RING_FULL;
1510 set_64bit_val(wqe, 16, ceq->elem_cnt);
1511 set_64bit_val(wqe, 32, (ceq->virtual_map ? 0 : ceq->ceq_elem_pa));
1512 set_64bit_val(wqe, 48, (ceq->virtual_map ? ceq->first_pm_pbl_idx : 0));
1513 set_64bit_val(wqe, 56, LS_64(ceq->tph_val, I40IW_CQPSQ_TPHVAL));
1514
1515 header = ceq->ceq_id |
1516 LS_64(I40IW_CQP_OP_CREATE_CEQ, I40IW_CQPSQ_OPCODE) |
1517 LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
1518 LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
1519 LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
1520 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1521
1522 i40iw_insert_wqe_hdr(wqe, header);
1523
1524 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_CREATE WQE",
1525 wqe, I40IW_CQP_WQE_SIZE * 8);
1526
1527 if (post_sq)
1528 i40iw_sc_cqp_post_sq(cqp);
1529 return 0;
1530}
1531
1532/**
1533 * i40iw_sc_cceq_create_done - poll for control ceq wqe to complete
1534 * @ceq: ceq sc structure
1535 */
1536static enum i40iw_status_code i40iw_sc_cceq_create_done(struct i40iw_sc_ceq *ceq)
1537{
1538 struct i40iw_sc_cqp *cqp;
1539
1540 cqp = ceq->dev->cqp;
1541 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CEQ, NULL);
1542}
1543
1544/**
1545 * i40iw_sc_cceq_destroy_done - poll for destroy cceq to complete
1546 * @ceq: ceq sc structure
1547 */
1548static enum i40iw_status_code i40iw_sc_cceq_destroy_done(struct i40iw_sc_ceq *ceq)
1549{
1550 struct i40iw_sc_cqp *cqp;
1551
1552 cqp = ceq->dev->cqp;
1553 cqp->process_cqp_sds = i40iw_update_sds_noccq;
1554 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_CEQ, NULL);
1555}
1556
1557/**
1558 * i40iw_sc_cceq_create - create cceq
1559 * @ceq: ceq sc structure
1560 * @scratch: u64 saved to be used during cqp completion
1561 */
1562static enum i40iw_status_code i40iw_sc_cceq_create(struct i40iw_sc_ceq *ceq, u64 scratch)
1563{
1564 enum i40iw_status_code ret_code;
1565
1566 ret_code = i40iw_sc_ceq_create(ceq, scratch, true);
1567 if (!ret_code)
1568 ret_code = i40iw_sc_cceq_create_done(ceq);
1569 return ret_code;
1570}
1571
1572/**
1573 * i40iw_sc_ceq_destroy - destroy ceq
1574 * @ceq: ceq sc structure
1575 * @scratch: u64 saved to be used during cqp completion
1576 * @post_sq: flag for cqp db to ring
1577 */
1578static enum i40iw_status_code i40iw_sc_ceq_destroy(struct i40iw_sc_ceq *ceq,
1579 u64 scratch,
1580 bool post_sq)
1581{
1582 struct i40iw_sc_cqp *cqp;
1583 u64 *wqe;
1584 u64 header;
1585
1586 cqp = ceq->dev->cqp;
1587 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1588 if (!wqe)
1589 return I40IW_ERR_RING_FULL;
1590 set_64bit_val(wqe, 16, ceq->elem_cnt);
1591 set_64bit_val(wqe, 48, ceq->first_pm_pbl_idx);
1592 header = ceq->ceq_id |
1593 LS_64(I40IW_CQP_OP_DESTROY_CEQ, I40IW_CQPSQ_OPCODE) |
1594 LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
1595 LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
1596 LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
1597 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1598 i40iw_insert_wqe_hdr(wqe, header);
1599 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_DESTROY WQE",
1600 wqe, I40IW_CQP_WQE_SIZE * 8);
1601
1602 if (post_sq)
1603 i40iw_sc_cqp_post_sq(cqp);
1604 return 0;
1605}
1606
1607/**
1608 * i40iw_sc_process_ceq - process ceq
1609 * @dev: sc device struct
1610 * @ceq: ceq sc structure
1611 */
1612static void *i40iw_sc_process_ceq(struct i40iw_sc_dev *dev, struct i40iw_sc_ceq *ceq)
1613{
1614 u64 temp;
1615 u64 *ceqe;
1616 struct i40iw_sc_cq *cq = NULL;
1617 u8 polarity;
1618
1619 ceqe = (u64 *)I40IW_GET_CURRENT_CEQ_ELEMENT(ceq);
1620 get_64bit_val(ceqe, 0, &temp);
1621 polarity = (u8)RS_64(temp, I40IW_CEQE_VALID);
1622 if (polarity != ceq->polarity)
1623 return cq;
1624
1625 cq = (struct i40iw_sc_cq *)(unsigned long)LS_64_1(temp, 1);
1626
1627 I40IW_RING_MOVE_TAIL(ceq->ceq_ring);
1628 if (I40IW_RING_GETCURRENT_TAIL(ceq->ceq_ring) == 0)
1629 ceq->polarity ^= 1;
1630
1631 if (dev->is_pf)
1632 i40iw_wr32(dev->hw, I40E_PFPE_CQACK, cq->cq_uk.cq_id);
1633 else
1634 i40iw_wr32(dev->hw, I40E_VFPE_CQACK1, cq->cq_uk.cq_id);
1635
1636 return cq;
1637}
1638
1639/**
1640 * i40iw_sc_aeq_init - initialize aeq
1641 * @aeq: aeq structure ptr
1642 * @info: aeq initialization info
1643 */
1644static enum i40iw_status_code i40iw_sc_aeq_init(struct i40iw_sc_aeq *aeq,
1645 struct i40iw_aeq_init_info *info)
1646{
1647 u32 pble_obj_cnt;
1648
1649 if ((info->elem_cnt < I40IW_MIN_AEQ_ENTRIES) ||
1650 (info->elem_cnt > I40IW_MAX_AEQ_ENTRIES))
1651 return I40IW_ERR_INVALID_SIZE;
1652 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1653
1654 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1655 return I40IW_ERR_INVALID_PBLE_INDEX;
1656
1657 aeq->size = sizeof(*aeq);
1658 aeq->polarity = 1;
1659 aeq->aeqe_base = (struct i40iw_sc_aeqe *)info->aeqe_base;
1660 aeq->dev = info->dev;
1661 aeq->elem_cnt = info->elem_cnt;
1662
1663 aeq->aeq_elem_pa = info->aeq_elem_pa;
1664 I40IW_RING_INIT(aeq->aeq_ring, aeq->elem_cnt);
1665 info->dev->aeq = aeq;
1666
1667 aeq->virtual_map = info->virtual_map;
1668 aeq->pbl_list = (aeq->virtual_map ? info->pbl_list : NULL);
1669 aeq->pbl_chunk_size = (aeq->virtual_map ? info->pbl_chunk_size : 0);
1670 aeq->first_pm_pbl_idx = (aeq->virtual_map ? info->first_pm_pbl_idx : 0);
1671 info->dev->aeq = aeq;
1672 return 0;
1673}
1674
1675/**
1676 * i40iw_sc_aeq_create - create aeq
1677 * @aeq: aeq structure ptr
1678 * @scratch: u64 saved to be used during cqp completion
1679 * @post_sq: flag for cqp db to ring
1680 */
1681static enum i40iw_status_code i40iw_sc_aeq_create(struct i40iw_sc_aeq *aeq,
1682 u64 scratch,
1683 bool post_sq)
1684{
1685 u64 *wqe;
1686 struct i40iw_sc_cqp *cqp;
1687 u64 header;
1688
1689 cqp = aeq->dev->cqp;
1690 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1691 if (!wqe)
1692 return I40IW_ERR_RING_FULL;
1693 set_64bit_val(wqe, 16, aeq->elem_cnt);
1694 set_64bit_val(wqe, 32,
1695 (aeq->virtual_map ? 0 : aeq->aeq_elem_pa));
1696 set_64bit_val(wqe, 48,
1697 (aeq->virtual_map ? aeq->first_pm_pbl_idx : 0));
1698
1699 header = LS_64(I40IW_CQP_OP_CREATE_AEQ, I40IW_CQPSQ_OPCODE) |
1700 LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
1701 LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
1702 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1703
1704 i40iw_insert_wqe_hdr(wqe, header);
1705 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_CREATE WQE",
1706 wqe, I40IW_CQP_WQE_SIZE * 8);
1707 if (post_sq)
1708 i40iw_sc_cqp_post_sq(cqp);
1709 return 0;
1710}
1711
1712/**
1713 * i40iw_sc_aeq_destroy - destroy aeq during close
1714 * @aeq: aeq structure ptr
1715 * @scratch: u64 saved to be used during cqp completion
1716 * @post_sq: flag for cqp db to ring
1717 */
1718static enum i40iw_status_code i40iw_sc_aeq_destroy(struct i40iw_sc_aeq *aeq,
1719 u64 scratch,
1720 bool post_sq)
1721{
1722 u64 *wqe;
1723 struct i40iw_sc_cqp *cqp;
1724 u64 header;
1725
1726 cqp = aeq->dev->cqp;
1727 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1728 if (!wqe)
1729 return I40IW_ERR_RING_FULL;
1730 set_64bit_val(wqe, 16, aeq->elem_cnt);
1731 set_64bit_val(wqe, 48, aeq->first_pm_pbl_idx);
1732 header = LS_64(I40IW_CQP_OP_DESTROY_AEQ, I40IW_CQPSQ_OPCODE) |
1733 LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
1734 LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
1735 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
1736 i40iw_insert_wqe_hdr(wqe, header);
1737
1738 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_DESTROY WQE",
1739 wqe, I40IW_CQP_WQE_SIZE * 8);
1740 if (post_sq)
1741 i40iw_sc_cqp_post_sq(cqp);
1742 return 0;
1743}
1744
1745/**
1746 * i40iw_sc_get_next_aeqe - get next aeq entry
1747 * @aeq: aeq structure ptr
1748 * @info: aeqe info to be returned
1749 */
1750static enum i40iw_status_code i40iw_sc_get_next_aeqe(struct i40iw_sc_aeq *aeq,
1751 struct i40iw_aeqe_info *info)
1752{
1753 u64 temp, compl_ctx;
1754 u64 *aeqe;
1755 u16 wqe_idx;
1756 u8 ae_src;
1757 u8 polarity;
1758
1759 aeqe = (u64 *)I40IW_GET_CURRENT_AEQ_ELEMENT(aeq);
1760 get_64bit_val(aeqe, 0, &compl_ctx);
1761 get_64bit_val(aeqe, 8, &temp);
1762 polarity = (u8)RS_64(temp, I40IW_AEQE_VALID);
1763
1764 if (aeq->polarity != polarity)
1765 return I40IW_ERR_QUEUE_EMPTY;
1766
1767 i40iw_debug_buf(aeq->dev, I40IW_DEBUG_WQE, "AEQ_ENTRY", aeqe, 16);
1768
1769 ae_src = (u8)RS_64(temp, I40IW_AEQE_AESRC);
1770 wqe_idx = (u16)RS_64(temp, I40IW_AEQE_WQDESCIDX);
1771 info->qp_cq_id = (u32)RS_64(temp, I40IW_AEQE_QPCQID);
1772 info->ae_id = (u16)RS_64(temp, I40IW_AEQE_AECODE);
1773 info->tcp_state = (u8)RS_64(temp, I40IW_AEQE_TCPSTATE);
1774 info->iwarp_state = (u8)RS_64(temp, I40IW_AEQE_IWSTATE);
1775 info->q2_data_written = (u8)RS_64(temp, I40IW_AEQE_Q2DATA);
1776 info->aeqe_overflow = (bool)RS_64(temp, I40IW_AEQE_OVERFLOW);
Mustafa Ismail4236f4b2017-10-16 15:45:55 -05001777
1778 switch (info->ae_id) {
1779 case I40IW_AE_PRIV_OPERATION_DENIED:
1780 case I40IW_AE_UDA_XMIT_DGRAM_TOO_LONG:
1781 case I40IW_AE_UDA_XMIT_DGRAM_TOO_SHORT:
1782 case I40IW_AE_BAD_CLOSE:
1783 case I40IW_AE_RDMAP_ROE_BAD_LLP_CLOSE:
1784 case I40IW_AE_RDMA_READ_WHILE_ORD_ZERO:
1785 case I40IW_AE_STAG_ZERO_INVALID:
1786 case I40IW_AE_IB_RREQ_AND_Q1_FULL:
1787 case I40IW_AE_WQE_UNEXPECTED_OPCODE:
1788 case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
1789 case I40IW_AE_DDP_UBE_INVALID_MO:
1790 case I40IW_AE_DDP_UBE_INVALID_QN:
1791 case I40IW_AE_DDP_NO_L_BIT:
1792 case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
1793 case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
1794 case I40IW_AE_ROE_INVALID_RDMA_READ_REQUEST:
1795 case I40IW_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
1796 case I40IW_AE_INVALID_ARP_ENTRY:
1797 case I40IW_AE_INVALID_TCP_OPTION_RCVD:
1798 case I40IW_AE_STALE_ARP_ENTRY:
1799 case I40IW_AE_LLP_CLOSE_COMPLETE:
1800 case I40IW_AE_LLP_CONNECTION_RESET:
1801 case I40IW_AE_LLP_FIN_RECEIVED:
1802 case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
1803 case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
1804 case I40IW_AE_LLP_SYN_RECEIVED:
1805 case I40IW_AE_LLP_TERMINATE_RECEIVED:
1806 case I40IW_AE_LLP_TOO_MANY_RETRIES:
1807 case I40IW_AE_LLP_DOUBT_REACHABILITY:
1808 case I40IW_AE_RESET_SENT:
1809 case I40IW_AE_TERMINATE_SENT:
1810 case I40IW_AE_RESET_NOT_SENT:
1811 case I40IW_AE_LCE_QP_CATASTROPHIC:
1812 case I40IW_AE_QP_SUSPEND_COMPLETE:
1813 info->qp = true;
1814 info->compl_ctx = compl_ctx;
1815 ae_src = I40IW_AE_SOURCE_RSVD;
1816 break;
1817 case I40IW_AE_LCE_CQ_CATASTROPHIC:
1818 info->cq = true;
1819 info->compl_ctx = LS_64_1(compl_ctx, 1);
1820 ae_src = I40IW_AE_SOURCE_RSVD;
1821 break;
1822 }
1823
Faisal Latif86dbcd02016-01-20 13:40:10 -06001824 switch (ae_src) {
1825 case I40IW_AE_SOURCE_RQ:
1826 case I40IW_AE_SOURCE_RQ_0011:
1827 info->qp = true;
1828 info->wqe_idx = wqe_idx;
1829 info->compl_ctx = compl_ctx;
1830 break;
1831 case I40IW_AE_SOURCE_CQ:
1832 case I40IW_AE_SOURCE_CQ_0110:
1833 case I40IW_AE_SOURCE_CQ_1010:
1834 case I40IW_AE_SOURCE_CQ_1110:
1835 info->cq = true;
1836 info->compl_ctx = LS_64_1(compl_ctx, 1);
1837 break;
1838 case I40IW_AE_SOURCE_SQ:
1839 case I40IW_AE_SOURCE_SQ_0111:
1840 info->qp = true;
1841 info->sq = true;
1842 info->wqe_idx = wqe_idx;
1843 info->compl_ctx = compl_ctx;
1844 break;
1845 case I40IW_AE_SOURCE_IN_RR_WR:
1846 case I40IW_AE_SOURCE_IN_RR_WR_1011:
1847 info->qp = true;
1848 info->compl_ctx = compl_ctx;
1849 info->in_rdrsp_wr = true;
1850 break;
1851 case I40IW_AE_SOURCE_OUT_RR:
1852 case I40IW_AE_SOURCE_OUT_RR_1111:
1853 info->qp = true;
1854 info->compl_ctx = compl_ctx;
1855 info->out_rdrsp = true;
1856 break;
Mustafa Ismail4236f4b2017-10-16 15:45:55 -05001857 case I40IW_AE_SOURCE_RSVD:
1858 /* fallthrough */
Faisal Latif86dbcd02016-01-20 13:40:10 -06001859 default:
1860 break;
1861 }
1862 I40IW_RING_MOVE_TAIL(aeq->aeq_ring);
1863 if (I40IW_RING_GETCURRENT_TAIL(aeq->aeq_ring) == 0)
1864 aeq->polarity ^= 1;
1865 return 0;
1866}
1867
1868/**
1869 * i40iw_sc_repost_aeq_entries - repost completed aeq entries
1870 * @dev: sc device struct
1871 * @count: allocate count
1872 */
1873static enum i40iw_status_code i40iw_sc_repost_aeq_entries(struct i40iw_sc_dev *dev,
1874 u32 count)
1875{
1876 if (count > I40IW_MAX_AEQ_ALLOCATE_COUNT)
1877 return I40IW_ERR_INVALID_SIZE;
1878
1879 if (dev->is_pf)
1880 i40iw_wr32(dev->hw, I40E_PFPE_AEQALLOC, count);
1881 else
1882 i40iw_wr32(dev->hw, I40E_VFPE_AEQALLOC1, count);
1883
1884 return 0;
1885}
1886
1887/**
1888 * i40iw_sc_aeq_create_done - create aeq
1889 * @aeq: aeq structure ptr
1890 */
1891static enum i40iw_status_code i40iw_sc_aeq_create_done(struct i40iw_sc_aeq *aeq)
1892{
1893 struct i40iw_sc_cqp *cqp;
1894
1895 cqp = aeq->dev->cqp;
1896 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_AEQ, NULL);
1897}
1898
1899/**
1900 * i40iw_sc_aeq_destroy_done - destroy of aeq during close
1901 * @aeq: aeq structure ptr
1902 */
1903static enum i40iw_status_code i40iw_sc_aeq_destroy_done(struct i40iw_sc_aeq *aeq)
1904{
1905 struct i40iw_sc_cqp *cqp;
1906
1907 cqp = aeq->dev->cqp;
1908 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_AEQ, NULL);
1909}
1910
1911/**
1912 * i40iw_sc_ccq_init - initialize control cq
1913 * @cq: sc's cq ctruct
1914 * @info: info for control cq initialization
1915 */
1916static enum i40iw_status_code i40iw_sc_ccq_init(struct i40iw_sc_cq *cq,
1917 struct i40iw_ccq_init_info *info)
1918{
1919 u32 pble_obj_cnt;
1920
1921 if (info->num_elem < I40IW_MIN_CQ_SIZE || info->num_elem > I40IW_MAX_CQ_SIZE)
1922 return I40IW_ERR_INVALID_SIZE;
1923
1924 if (info->ceq_id > I40IW_MAX_CEQID)
1925 return I40IW_ERR_INVALID_CEQ_ID;
1926
1927 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
1928
1929 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
1930 return I40IW_ERR_INVALID_PBLE_INDEX;
1931
1932 cq->cq_pa = info->cq_pa;
1933 cq->cq_uk.cq_base = info->cq_base;
1934 cq->shadow_area_pa = info->shadow_area_pa;
1935 cq->cq_uk.shadow_area = info->shadow_area;
1936 cq->shadow_read_threshold = info->shadow_read_threshold;
1937 cq->dev = info->dev;
1938 cq->ceq_id = info->ceq_id;
1939 cq->cq_uk.cq_size = info->num_elem;
1940 cq->cq_type = I40IW_CQ_TYPE_CQP;
1941 cq->ceqe_mask = info->ceqe_mask;
1942 I40IW_RING_INIT(cq->cq_uk.cq_ring, info->num_elem);
1943
1944 cq->cq_uk.cq_id = 0; /* control cq is id 0 always */
1945 cq->ceq_id_valid = info->ceq_id_valid;
1946 cq->tph_en = info->tph_en;
1947 cq->tph_val = info->tph_val;
1948 cq->cq_uk.avoid_mem_cflct = info->avoid_mem_cflct;
1949
1950 cq->pbl_list = info->pbl_list;
1951 cq->virtual_map = info->virtual_map;
1952 cq->pbl_chunk_size = info->pbl_chunk_size;
1953 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
1954 cq->cq_uk.polarity = true;
1955
1956 /* following are only for iw cqs so initialize them to zero */
1957 cq->cq_uk.cqe_alloc_reg = NULL;
1958 info->dev->ccq = cq;
1959 return 0;
1960}
1961
1962/**
1963 * i40iw_sc_ccq_create_done - poll cqp for ccq create
1964 * @ccq: ccq sc struct
1965 */
1966static enum i40iw_status_code i40iw_sc_ccq_create_done(struct i40iw_sc_cq *ccq)
1967{
1968 struct i40iw_sc_cqp *cqp;
1969
1970 cqp = ccq->dev->cqp;
1971 return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CQ, NULL);
1972}
1973
1974/**
1975 * i40iw_sc_ccq_create - create control cq
1976 * @ccq: ccq sc struct
1977 * @scratch: u64 saved to be used during cqp completion
1978 * @check_overflow: overlow flag for ccq
1979 * @post_sq: flag for cqp db to ring
1980 */
1981static enum i40iw_status_code i40iw_sc_ccq_create(struct i40iw_sc_cq *ccq,
1982 u64 scratch,
1983 bool check_overflow,
1984 bool post_sq)
1985{
1986 u64 *wqe;
1987 struct i40iw_sc_cqp *cqp;
1988 u64 header;
1989 enum i40iw_status_code ret_code;
1990
1991 cqp = ccq->dev->cqp;
1992 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
1993 if (!wqe)
1994 return I40IW_ERR_RING_FULL;
1995 set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
1996 set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
1997 set_64bit_val(wqe, 16,
1998 LS_64(ccq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
1999 set_64bit_val(wqe, 32, (ccq->virtual_map ? 0 : ccq->cq_pa));
2000 set_64bit_val(wqe, 40, ccq->shadow_area_pa);
2001 set_64bit_val(wqe, 48,
2002 (ccq->virtual_map ? ccq->first_pm_pbl_idx : 0));
2003 set_64bit_val(wqe, 56,
2004 LS_64(ccq->tph_val, I40IW_CQPSQ_TPHVAL));
2005
2006 header = ccq->cq_uk.cq_id |
2007 LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
2008 LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
2009 LS_64(ccq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
2010 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
2011 LS_64(ccq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
2012 LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2013 LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2014 LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
2015 LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2016 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2017
2018 i40iw_insert_wqe_hdr(wqe, header);
2019
2020 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_CREATE WQE",
2021 wqe, I40IW_CQP_WQE_SIZE * 8);
2022
2023 if (post_sq) {
2024 i40iw_sc_cqp_post_sq(cqp);
2025 ret_code = i40iw_sc_ccq_create_done(ccq);
2026 if (ret_code)
2027 return ret_code;
2028 }
2029 cqp->process_cqp_sds = i40iw_cqp_sds_cmd;
2030
2031 return 0;
2032}
2033
2034/**
2035 * i40iw_sc_ccq_destroy - destroy ccq during close
2036 * @ccq: ccq sc struct
2037 * @scratch: u64 saved to be used during cqp completion
2038 * @post_sq: flag for cqp db to ring
2039 */
2040static enum i40iw_status_code i40iw_sc_ccq_destroy(struct i40iw_sc_cq *ccq,
2041 u64 scratch,
2042 bool post_sq)
2043{
2044 struct i40iw_sc_cqp *cqp;
2045 u64 *wqe;
2046 u64 header;
2047 enum i40iw_status_code ret_code = 0;
2048 u32 tail, val, error;
2049
2050 cqp = ccq->dev->cqp;
2051 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2052 if (!wqe)
2053 return I40IW_ERR_RING_FULL;
2054 set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
2055 set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
2056 set_64bit_val(wqe, 40, ccq->shadow_area_pa);
2057
2058 header = ccq->cq_uk.cq_id |
2059 LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
2060 LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
2061 LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2062 LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2063 LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
2064 LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2065 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2066
2067 i40iw_insert_wqe_hdr(wqe, header);
2068
2069 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_DESTROY WQE",
2070 wqe, I40IW_CQP_WQE_SIZE * 8);
2071
2072 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
2073 if (error)
2074 return I40IW_ERR_CQP_COMPL_ERROR;
2075
2076 if (post_sq) {
2077 i40iw_sc_cqp_post_sq(cqp);
2078 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
2079 }
2080
Mustafa Ismail415920a2017-06-23 16:03:56 -05002081 cqp->process_cqp_sds = i40iw_update_sds_noccq;
2082
Faisal Latif86dbcd02016-01-20 13:40:10 -06002083 return ret_code;
2084}
2085
2086/**
2087 * i40iw_sc_cq_init - initialize completion q
2088 * @cq: cq struct
2089 * @info: cq initialization info
2090 */
2091static enum i40iw_status_code i40iw_sc_cq_init(struct i40iw_sc_cq *cq,
2092 struct i40iw_cq_init_info *info)
2093{
2094 u32 __iomem *cqe_alloc_reg = NULL;
2095 enum i40iw_status_code ret_code;
2096 u32 pble_obj_cnt;
2097 u32 arm_offset;
2098
2099 pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2100
2101 if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
2102 return I40IW_ERR_INVALID_PBLE_INDEX;
2103
2104 cq->cq_pa = info->cq_base_pa;
2105 cq->dev = info->dev;
2106 cq->ceq_id = info->ceq_id;
2107 arm_offset = (info->dev->is_pf) ? I40E_PFPE_CQARM : I40E_VFPE_CQARM1;
2108 if (i40iw_get_hw_addr(cq->dev))
2109 cqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(cq->dev) +
2110 arm_offset);
2111 info->cq_uk_init_info.cqe_alloc_reg = cqe_alloc_reg;
2112 ret_code = i40iw_cq_uk_init(&cq->cq_uk, &info->cq_uk_init_info);
2113 if (ret_code)
2114 return ret_code;
2115 cq->virtual_map = info->virtual_map;
2116 cq->pbl_chunk_size = info->pbl_chunk_size;
2117 cq->ceqe_mask = info->ceqe_mask;
2118 cq->cq_type = (info->type) ? info->type : I40IW_CQ_TYPE_IWARP;
2119
2120 cq->shadow_area_pa = info->shadow_area_pa;
2121 cq->shadow_read_threshold = info->shadow_read_threshold;
2122
2123 cq->ceq_id_valid = info->ceq_id_valid;
2124 cq->tph_en = info->tph_en;
2125 cq->tph_val = info->tph_val;
2126
2127 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
2128
2129 return 0;
2130}
2131
2132/**
2133 * i40iw_sc_cq_create - create completion q
2134 * @cq: cq struct
2135 * @scratch: u64 saved to be used during cqp completion
2136 * @check_overflow: flag for overflow check
2137 * @post_sq: flag for cqp db to ring
2138 */
2139static enum i40iw_status_code i40iw_sc_cq_create(struct i40iw_sc_cq *cq,
2140 u64 scratch,
2141 bool check_overflow,
2142 bool post_sq)
2143{
2144 u64 *wqe;
2145 struct i40iw_sc_cqp *cqp;
2146 u64 header;
2147
2148 if (cq->cq_uk.cq_id > I40IW_MAX_CQID)
2149 return I40IW_ERR_INVALID_CQ_ID;
2150
2151 if (cq->ceq_id > I40IW_MAX_CEQID)
2152 return I40IW_ERR_INVALID_CEQ_ID;
2153
2154 cqp = cq->dev->cqp;
2155 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2156 if (!wqe)
2157 return I40IW_ERR_RING_FULL;
2158
2159 set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
2160 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
2161 set_64bit_val(wqe,
2162 16,
2163 LS_64(cq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
2164
2165 set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
2166
2167 set_64bit_val(wqe, 40, cq->shadow_area_pa);
2168 set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
2169 set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
2170
2171 header = cq->cq_uk.cq_id |
2172 LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
2173 LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
2174 LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
2175 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
2176 LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
2177 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2178 LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2179 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
2180 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2181 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2182
2183 i40iw_insert_wqe_hdr(wqe, header);
2184
2185 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_CREATE WQE",
2186 wqe, I40IW_CQP_WQE_SIZE * 8);
2187
2188 if (post_sq)
2189 i40iw_sc_cqp_post_sq(cqp);
2190 return 0;
2191}
2192
2193/**
2194 * i40iw_sc_cq_destroy - destroy completion q
2195 * @cq: cq struct
2196 * @scratch: u64 saved to be used during cqp completion
2197 * @post_sq: flag for cqp db to ring
2198 */
2199static enum i40iw_status_code i40iw_sc_cq_destroy(struct i40iw_sc_cq *cq,
2200 u64 scratch,
2201 bool post_sq)
2202{
2203 struct i40iw_sc_cqp *cqp;
2204 u64 *wqe;
2205 u64 header;
2206
2207 cqp = cq->dev->cqp;
2208 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2209 if (!wqe)
2210 return I40IW_ERR_RING_FULL;
2211 set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
2212 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
2213 set_64bit_val(wqe, 40, cq->shadow_area_pa);
2214 set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
2215
2216 header = cq->cq_uk.cq_id |
2217 LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
2218 LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
2219 LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
2220 LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
2221 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2222 LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2223 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
2224 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2225 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2226
2227 i40iw_insert_wqe_hdr(wqe, header);
2228
2229 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_DESTROY WQE",
2230 wqe, I40IW_CQP_WQE_SIZE * 8);
2231
2232 if (post_sq)
2233 i40iw_sc_cqp_post_sq(cqp);
2234 return 0;
2235}
2236
2237/**
2238 * i40iw_sc_cq_modify - modify a Completion Queue
2239 * @cq: cq struct
2240 * @info: modification info struct
2241 * @scratch:
2242 * @post_sq: flag to post to sq
2243 */
2244static enum i40iw_status_code i40iw_sc_cq_modify(struct i40iw_sc_cq *cq,
2245 struct i40iw_modify_cq_info *info,
2246 u64 scratch,
2247 bool post_sq)
2248{
2249 struct i40iw_sc_cqp *cqp;
2250 u64 *wqe;
2251 u64 header;
2252 u32 cq_size, ceq_id, first_pm_pbl_idx;
2253 u8 pbl_chunk_size;
2254 bool virtual_map, ceq_id_valid, check_overflow;
2255 u32 pble_obj_cnt;
2256
2257 if (info->ceq_valid && (info->ceq_id > I40IW_MAX_CEQID))
2258 return I40IW_ERR_INVALID_CEQ_ID;
2259
2260 pble_obj_cnt = cq->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2261
2262 if (info->cq_resize && info->virtual_map &&
2263 (info->first_pm_pbl_idx >= pble_obj_cnt))
2264 return I40IW_ERR_INVALID_PBLE_INDEX;
2265
2266 cqp = cq->dev->cqp;
2267 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2268 if (!wqe)
2269 return I40IW_ERR_RING_FULL;
2270
2271 cq->pbl_list = info->pbl_list;
2272 cq->cq_pa = info->cq_pa;
2273 cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
2274
2275 cq_size = info->cq_resize ? info->cq_size : cq->cq_uk.cq_size;
2276 if (info->ceq_change) {
2277 ceq_id_valid = true;
2278 ceq_id = info->ceq_id;
2279 } else {
2280 ceq_id_valid = cq->ceq_id_valid;
2281 ceq_id = ceq_id_valid ? cq->ceq_id : 0;
2282 }
2283 virtual_map = info->cq_resize ? info->virtual_map : cq->virtual_map;
2284 first_pm_pbl_idx = (info->cq_resize ?
2285 (info->virtual_map ? info->first_pm_pbl_idx : 0) :
2286 (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
2287 pbl_chunk_size = (info->cq_resize ?
2288 (info->virtual_map ? info->pbl_chunk_size : 0) :
2289 (cq->virtual_map ? cq->pbl_chunk_size : 0));
2290 check_overflow = info->check_overflow_change ? info->check_overflow :
2291 cq->check_overflow;
2292 cq->cq_uk.cq_size = cq_size;
2293 cq->ceq_id_valid = ceq_id_valid;
2294 cq->ceq_id = ceq_id;
2295 cq->virtual_map = virtual_map;
2296 cq->first_pm_pbl_idx = first_pm_pbl_idx;
2297 cq->pbl_chunk_size = pbl_chunk_size;
2298 cq->check_overflow = check_overflow;
2299
2300 set_64bit_val(wqe, 0, cq_size);
2301 set_64bit_val(wqe, 8, RS_64_1(cq, 1));
2302 set_64bit_val(wqe, 16,
2303 LS_64(info->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
2304 set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
2305 set_64bit_val(wqe, 40, cq->shadow_area_pa);
2306 set_64bit_val(wqe, 48, (cq->virtual_map ? first_pm_pbl_idx : 0));
2307 set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
2308
2309 header = cq->cq_uk.cq_id |
2310 LS_64(ceq_id, I40IW_CQPSQ_CQ_CEQID) |
2311 LS_64(I40IW_CQP_OP_MODIFY_CQ, I40IW_CQPSQ_OPCODE) |
2312 LS_64(info->cq_resize, I40IW_CQPSQ_CQ_CQRESIZE) |
2313 LS_64(pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
2314 LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
2315 LS_64(virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
2316 LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
2317 LS_64(ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
2318 LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
2319 LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
2320 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2321
2322 i40iw_insert_wqe_hdr(wqe, header);
2323
2324 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_MODIFY WQE",
2325 wqe, I40IW_CQP_WQE_SIZE * 8);
2326
2327 if (post_sq)
2328 i40iw_sc_cqp_post_sq(cqp);
2329 return 0;
2330}
2331
2332/**
2333 * i40iw_sc_qp_init - initialize qp
2334 * @qp: sc qp
2335 * @info: initialization qp info
2336 */
2337static enum i40iw_status_code i40iw_sc_qp_init(struct i40iw_sc_qp *qp,
2338 struct i40iw_qp_init_info *info)
2339{
2340 u32 __iomem *wqe_alloc_reg = NULL;
2341 enum i40iw_status_code ret_code;
2342 u32 pble_obj_cnt;
2343 u8 wqe_size;
2344 u32 offset;
2345
2346 qp->dev = info->pd->dev;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002347 qp->vsi = info->vsi;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002348 qp->sq_pa = info->sq_pa;
2349 qp->rq_pa = info->rq_pa;
2350 qp->hw_host_ctx_pa = info->host_ctx_pa;
2351 qp->q2_pa = info->q2_pa;
2352 qp->shadow_area_pa = info->shadow_area_pa;
2353
2354 qp->q2_buf = info->q2;
2355 qp->pd = info->pd;
2356 qp->hw_host_ctx = info->host_ctx;
2357 offset = (qp->pd->dev->is_pf) ? I40E_PFPE_WQEALLOC : I40E_VFPE_WQEALLOC1;
2358 if (i40iw_get_hw_addr(qp->pd->dev))
2359 wqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(qp->pd->dev) +
2360 offset);
2361
2362 info->qp_uk_init_info.wqe_alloc_reg = wqe_alloc_reg;
Chien Tin Tung61f51b72016-12-21 08:53:46 -06002363 info->qp_uk_init_info.abi_ver = qp->pd->abi_ver;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002364 ret_code = i40iw_qp_uk_init(&qp->qp_uk, &info->qp_uk_init_info);
2365 if (ret_code)
2366 return ret_code;
2367 qp->virtual_map = info->virtual_map;
2368
2369 pble_obj_cnt = info->pd->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2370
2371 if ((info->virtual_map && (info->sq_pa >= pble_obj_cnt)) ||
2372 (info->virtual_map && (info->rq_pa >= pble_obj_cnt)))
2373 return I40IW_ERR_INVALID_PBLE_INDEX;
2374
2375 qp->llp_stream_handle = (void *)(-1);
2376 qp->qp_type = (info->type) ? info->type : I40IW_QP_TYPE_IWARP;
2377
2378 qp->hw_sq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.sq_ring.size,
2379 false);
2380 i40iw_debug(qp->dev, I40IW_DEBUG_WQE, "%s: hw_sq_size[%04d] sq_ring.size[%04d]\n",
2381 __func__, qp->hw_sq_size, qp->qp_uk.sq_ring.size);
Chien Tin Tung61f51b72016-12-21 08:53:46 -06002382
2383 switch (qp->pd->abi_ver) {
2384 case 4:
2385 ret_code = i40iw_fragcnt_to_wqesize_rq(qp->qp_uk.max_rq_frag_cnt,
2386 &wqe_size);
2387 if (ret_code)
2388 return ret_code;
2389 break;
2390 case 5: /* fallthrough until next ABI version */
2391 default:
2392 if (qp->qp_uk.max_rq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
2393 return I40IW_ERR_INVALID_FRAG_COUNT;
2394 wqe_size = I40IW_MAX_WQE_SIZE_RQ;
2395 break;
2396 }
Faisal Latif86dbcd02016-01-20 13:40:10 -06002397 qp->hw_rq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.rq_size *
2398 (wqe_size / I40IW_QP_WQE_MIN_SIZE), false);
2399 i40iw_debug(qp->dev, I40IW_DEBUG_WQE,
2400 "%s: hw_rq_size[%04d] qp_uk.rq_size[%04d] wqe_size[%04d]\n",
2401 __func__, qp->hw_rq_size, qp->qp_uk.rq_size, wqe_size);
2402 qp->sq_tph_val = info->sq_tph_val;
2403 qp->rq_tph_val = info->rq_tph_val;
2404 qp->sq_tph_en = info->sq_tph_en;
2405 qp->rq_tph_en = info->rq_tph_en;
2406 qp->rcv_tph_en = info->rcv_tph_en;
2407 qp->xmit_tph_en = info->xmit_tph_en;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002408 qp->qs_handle = qp->vsi->qos[qp->user_pri].qs_handle;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002409 qp->exception_lan_queue = qp->pd->dev->exception_lan_queue;
2410
2411 return 0;
2412}
2413
2414/**
2415 * i40iw_sc_qp_create - create qp
2416 * @qp: sc qp
2417 * @info: qp create info
2418 * @scratch: u64 saved to be used during cqp completion
2419 * @post_sq: flag for cqp db to ring
2420 */
2421static enum i40iw_status_code i40iw_sc_qp_create(
2422 struct i40iw_sc_qp *qp,
2423 struct i40iw_create_qp_info *info,
2424 u64 scratch,
2425 bool post_sq)
2426{
2427 struct i40iw_sc_cqp *cqp;
2428 u64 *wqe;
2429 u64 header;
2430
2431 if ((qp->qp_uk.qp_id < I40IW_MIN_IW_QP_ID) ||
2432 (qp->qp_uk.qp_id > I40IW_MAX_IW_QP_ID))
2433 return I40IW_ERR_INVALID_QP_ID;
2434
2435 cqp = qp->pd->dev->cqp;
2436 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2437 if (!wqe)
2438 return I40IW_ERR_RING_FULL;
2439
2440 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2441
2442 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2443
2444 header = qp->qp_uk.qp_id |
2445 LS_64(I40IW_CQP_OP_CREATE_QP, I40IW_CQPSQ_OPCODE) |
2446 LS_64((info->ord_valid ? 1 : 0), I40IW_CQPSQ_QP_ORDVALID) |
2447 LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
2448 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
2449 LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
2450 LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
Faisal Latif86dbcd02016-01-20 13:40:10 -06002451 LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
2452 LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
2453 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2454
2455 i40iw_insert_wqe_hdr(wqe, header);
2456 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_CREATE WQE",
2457 wqe, I40IW_CQP_WQE_SIZE * 8);
2458
2459 if (post_sq)
2460 i40iw_sc_cqp_post_sq(cqp);
2461 return 0;
2462}
2463
2464/**
2465 * i40iw_sc_qp_modify - modify qp cqp wqe
2466 * @qp: sc qp
2467 * @info: modify qp info
2468 * @scratch: u64 saved to be used during cqp completion
2469 * @post_sq: flag for cqp db to ring
2470 */
2471static enum i40iw_status_code i40iw_sc_qp_modify(
2472 struct i40iw_sc_qp *qp,
2473 struct i40iw_modify_qp_info *info,
2474 u64 scratch,
2475 bool post_sq)
2476{
2477 u64 *wqe;
2478 struct i40iw_sc_cqp *cqp;
2479 u64 header;
2480 u8 term_actions = 0;
2481 u8 term_len = 0;
2482
2483 cqp = qp->pd->dev->cqp;
2484 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2485 if (!wqe)
2486 return I40IW_ERR_RING_FULL;
2487 if (info->next_iwarp_state == I40IW_QP_STATE_TERMINATE) {
2488 if (info->dont_send_fin)
2489 term_actions += I40IWQP_TERM_SEND_TERM_ONLY;
2490 if (info->dont_send_term)
2491 term_actions += I40IWQP_TERM_SEND_FIN_ONLY;
2492 if ((term_actions == I40IWQP_TERM_SEND_TERM_AND_FIN) ||
2493 (term_actions == I40IWQP_TERM_SEND_TERM_ONLY))
2494 term_len = info->termlen;
2495 }
2496
2497 set_64bit_val(wqe,
2498 8,
Faisal Latif86dbcd02016-01-20 13:40:10 -06002499 LS_64(term_len, I40IW_CQPSQ_QP_TERMLEN));
2500
2501 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2502 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2503
2504 header = qp->qp_uk.qp_id |
2505 LS_64(I40IW_CQP_OP_MODIFY_QP, I40IW_CQPSQ_OPCODE) |
2506 LS_64(info->ord_valid, I40IW_CQPSQ_QP_ORDVALID) |
2507 LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
2508 LS_64(info->cached_var_valid, I40IW_CQPSQ_QP_CACHEDVARVALID) |
2509 LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
2510 LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
2511 LS_64(info->force_loopback, I40IW_CQPSQ_QP_FORCELOOPBACK) |
2512 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
Faisal Latif86dbcd02016-01-20 13:40:10 -06002513 LS_64(info->remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
2514 LS_64(term_actions, I40IW_CQPSQ_QP_TERMACT) |
2515 LS_64(info->reset_tcp_conn, I40IW_CQPSQ_QP_RESETCON) |
2516 LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
2517 LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
2518 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2519
2520 i40iw_insert_wqe_hdr(wqe, header);
2521
2522 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_MODIFY WQE",
2523 wqe, I40IW_CQP_WQE_SIZE * 8);
2524
2525 if (post_sq)
2526 i40iw_sc_cqp_post_sq(cqp);
2527 return 0;
2528}
2529
2530/**
2531 * i40iw_sc_qp_destroy - cqp destroy qp
2532 * @qp: sc qp
2533 * @scratch: u64 saved to be used during cqp completion
2534 * @remove_hash_idx: flag if to remove hash idx
2535 * @ignore_mw_bnd: memory window bind flag
2536 * @post_sq: flag for cqp db to ring
2537 */
2538static enum i40iw_status_code i40iw_sc_qp_destroy(
2539 struct i40iw_sc_qp *qp,
2540 u64 scratch,
2541 bool remove_hash_idx,
2542 bool ignore_mw_bnd,
2543 bool post_sq)
2544{
2545 u64 *wqe;
2546 struct i40iw_sc_cqp *cqp;
2547 u64 header;
2548
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002549 i40iw_qp_rem_qos(qp);
Faisal Latif86dbcd02016-01-20 13:40:10 -06002550 cqp = qp->pd->dev->cqp;
2551 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2552 if (!wqe)
2553 return I40IW_ERR_RING_FULL;
2554 set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
2555 set_64bit_val(wqe, 40, qp->shadow_area_pa);
2556
2557 header = qp->qp_uk.qp_id |
2558 LS_64(I40IW_CQP_OP_DESTROY_QP, I40IW_CQPSQ_OPCODE) |
2559 LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
2560 LS_64(ignore_mw_bnd, I40IW_CQPSQ_QP_IGNOREMWBOUND) |
2561 LS_64(remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
2562 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2563
2564 i40iw_insert_wqe_hdr(wqe, header);
2565 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_DESTROY WQE",
2566 wqe, I40IW_CQP_WQE_SIZE * 8);
2567
2568 if (post_sq)
2569 i40iw_sc_cqp_post_sq(cqp);
2570 return 0;
2571}
2572
2573/**
2574 * i40iw_sc_qp_flush_wqes - flush qp's wqe
2575 * @qp: sc qp
2576 * @info: dlush information
2577 * @scratch: u64 saved to be used during cqp completion
2578 * @post_sq: flag for cqp db to ring
2579 */
2580static enum i40iw_status_code i40iw_sc_qp_flush_wqes(
2581 struct i40iw_sc_qp *qp,
2582 struct i40iw_qp_flush_info *info,
2583 u64 scratch,
2584 bool post_sq)
2585{
2586 u64 temp = 0;
2587 u64 *wqe;
2588 struct i40iw_sc_cqp *cqp;
2589 u64 header;
2590 bool flush_sq = false, flush_rq = false;
2591
2592 if (info->rq && !qp->flush_rq)
2593 flush_rq = true;
2594
2595 if (info->sq && !qp->flush_sq)
2596 flush_sq = true;
2597
2598 qp->flush_sq |= flush_sq;
2599 qp->flush_rq |= flush_rq;
2600 if (!flush_sq && !flush_rq) {
2601 if (info->ae_code != I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR)
2602 return 0;
2603 }
2604
2605 cqp = qp->pd->dev->cqp;
2606 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2607 if (!wqe)
2608 return I40IW_ERR_RING_FULL;
2609 if (info->userflushcode) {
2610 if (flush_rq) {
2611 temp |= LS_64(info->rq_minor_code, I40IW_CQPSQ_FWQE_RQMNERR) |
2612 LS_64(info->rq_major_code, I40IW_CQPSQ_FWQE_RQMJERR);
2613 }
2614 if (flush_sq) {
2615 temp |= LS_64(info->sq_minor_code, I40IW_CQPSQ_FWQE_SQMNERR) |
2616 LS_64(info->sq_major_code, I40IW_CQPSQ_FWQE_SQMJERR);
2617 }
2618 }
2619 set_64bit_val(wqe, 16, temp);
2620
2621 temp = (info->generate_ae) ?
2622 info->ae_code | LS_64(info->ae_source, I40IW_CQPSQ_FWQE_AESOURCE) : 0;
2623
2624 set_64bit_val(wqe, 8, temp);
2625
2626 header = qp->qp_uk.qp_id |
2627 LS_64(I40IW_CQP_OP_FLUSH_WQES, I40IW_CQPSQ_OPCODE) |
2628 LS_64(info->generate_ae, I40IW_CQPSQ_FWQE_GENERATE_AE) |
2629 LS_64(info->userflushcode, I40IW_CQPSQ_FWQE_USERFLCODE) |
2630 LS_64(flush_sq, I40IW_CQPSQ_FWQE_FLUSHSQ) |
2631 LS_64(flush_rq, I40IW_CQPSQ_FWQE_FLUSHRQ) |
2632 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2633
2634 i40iw_insert_wqe_hdr(wqe, header);
2635
2636 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_FLUSH WQE",
2637 wqe, I40IW_CQP_WQE_SIZE * 8);
2638
2639 if (post_sq)
2640 i40iw_sc_cqp_post_sq(cqp);
2641 return 0;
2642}
2643
2644/**
2645 * i40iw_sc_qp_upload_context - upload qp's context
2646 * @dev: sc device struct
2647 * @info: upload context info ptr for return
2648 * @scratch: u64 saved to be used during cqp completion
2649 * @post_sq: flag for cqp db to ring
2650 */
2651static enum i40iw_status_code i40iw_sc_qp_upload_context(
2652 struct i40iw_sc_dev *dev,
2653 struct i40iw_upload_context_info *info,
2654 u64 scratch,
2655 bool post_sq)
2656{
2657 u64 *wqe;
2658 struct i40iw_sc_cqp *cqp;
2659 u64 header;
2660
2661 cqp = dev->cqp;
2662 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2663 if (!wqe)
2664 return I40IW_ERR_RING_FULL;
2665 set_64bit_val(wqe, 16, info->buf_pa);
2666
2667 header = LS_64(info->qp_id, I40IW_CQPSQ_UCTX_QPID) |
2668 LS_64(I40IW_CQP_OP_UPLOAD_CONTEXT, I40IW_CQPSQ_OPCODE) |
2669 LS_64(info->qp_type, I40IW_CQPSQ_UCTX_QPTYPE) |
2670 LS_64(info->raw_format, I40IW_CQPSQ_UCTX_RAWFORMAT) |
2671 LS_64(info->freeze_qp, I40IW_CQPSQ_UCTX_FREEZEQP) |
2672 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2673
2674 i40iw_insert_wqe_hdr(wqe, header);
2675
2676 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QP_UPLOAD_CTX WQE",
2677 wqe, I40IW_CQP_WQE_SIZE * 8);
2678
2679 if (post_sq)
2680 i40iw_sc_cqp_post_sq(cqp);
2681 return 0;
2682}
2683
2684/**
2685 * i40iw_sc_qp_setctx - set qp's context
2686 * @qp: sc qp
2687 * @qp_ctx: context ptr
2688 * @info: ctx info
2689 */
2690static enum i40iw_status_code i40iw_sc_qp_setctx(
2691 struct i40iw_sc_qp *qp,
2692 u64 *qp_ctx,
2693 struct i40iw_qp_host_ctx_info *info)
2694{
2695 struct i40iwarp_offload_info *iw;
2696 struct i40iw_tcp_offload_info *tcp;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002697 struct i40iw_sc_vsi *vsi;
2698 struct i40iw_sc_dev *dev;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002699 u64 qw0, qw3, qw7 = 0;
2700
2701 iw = info->iwarp_info;
2702 tcp = info->tcp_info;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002703 vsi = qp->vsi;
2704 dev = qp->dev;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05002705 if (info->add_to_qoslist) {
2706 qp->user_pri = info->user_pri;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002707 i40iw_qp_add_qos(qp);
Henry Orosco0fc2dc52016-10-10 21:12:10 -05002708 i40iw_debug(qp->dev, I40IW_DEBUG_DCB, "%s qp[%d] UP[%d] qset[%d]\n",
2709 __func__, qp->qp_uk.qp_id, qp->user_pri, qp->qs_handle);
2710 }
Faisal Latif86dbcd02016-01-20 13:40:10 -06002711 qw0 = LS_64(qp->qp_uk.rq_wqe_size, I40IWQPC_RQWQESIZE) |
2712 LS_64(info->err_rq_idx_valid, I40IWQPC_ERR_RQ_IDX_VALID) |
2713 LS_64(qp->rcv_tph_en, I40IWQPC_RCVTPHEN) |
2714 LS_64(qp->xmit_tph_en, I40IWQPC_XMITTPHEN) |
2715 LS_64(qp->rq_tph_en, I40IWQPC_RQTPHEN) |
2716 LS_64(qp->sq_tph_en, I40IWQPC_SQTPHEN) |
2717 LS_64(info->push_idx, I40IWQPC_PPIDX) |
2718 LS_64(info->push_mode_en, I40IWQPC_PMENA);
2719
2720 set_64bit_val(qp_ctx, 8, qp->sq_pa);
2721 set_64bit_val(qp_ctx, 16, qp->rq_pa);
2722
2723 qw3 = LS_64(qp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
2724 LS_64(qp->hw_rq_size, I40IWQPC_RQSIZE) |
2725 LS_64(qp->hw_sq_size, I40IWQPC_SQSIZE);
2726
2727 set_64bit_val(qp_ctx,
2728 128,
2729 LS_64(info->err_rq_idx, I40IWQPC_ERR_RQ_IDX));
2730
2731 set_64bit_val(qp_ctx,
2732 136,
2733 LS_64(info->send_cq_num, I40IWQPC_TXCQNUM) |
2734 LS_64(info->rcv_cq_num, I40IWQPC_RXCQNUM));
2735
2736 set_64bit_val(qp_ctx,
2737 168,
2738 LS_64(info->qp_compl_ctx, I40IWQPC_QPCOMPCTX));
2739 set_64bit_val(qp_ctx,
2740 176,
2741 LS_64(qp->sq_tph_val, I40IWQPC_SQTPHVAL) |
2742 LS_64(qp->rq_tph_val, I40IWQPC_RQTPHVAL) |
2743 LS_64(qp->qs_handle, I40IWQPC_QSHANDLE) |
2744 LS_64(qp->exception_lan_queue, I40IWQPC_EXCEPTION_LAN_QUEUE));
2745
2746 if (info->iwarp_info_valid) {
2747 qw0 |= LS_64(iw->ddp_ver, I40IWQPC_DDP_VER) |
2748 LS_64(iw->rdmap_ver, I40IWQPC_RDMAP_VER);
2749
2750 qw7 |= LS_64(iw->pd_id, I40IWQPC_PDIDX);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002751 set_64bit_val(qp_ctx,
2752 144,
2753 LS_64(qp->q2_pa, I40IWQPC_Q2ADDR) |
2754 LS_64(vsi->fcn_id, I40IWQPC_STAT_INDEX));
Faisal Latif86dbcd02016-01-20 13:40:10 -06002755 set_64bit_val(qp_ctx,
2756 152,
2757 LS_64(iw->last_byte_sent, I40IWQPC_LASTBYTESENT));
2758
Faisal Latif86dbcd02016-01-20 13:40:10 -06002759 set_64bit_val(qp_ctx,
2760 160,
2761 LS_64(iw->ord_size, I40IWQPC_ORDSIZE) |
2762 LS_64(iw->ird_size, I40IWQPC_IRDSIZE) |
2763 LS_64(iw->wr_rdresp_en, I40IWQPC_WRRDRSPOK) |
2764 LS_64(iw->rd_enable, I40IWQPC_RDOK) |
2765 LS_64(iw->snd_mark_en, I40IWQPC_SNDMARKERS) |
2766 LS_64(iw->bind_en, I40IWQPC_BINDEN) |
2767 LS_64(iw->fast_reg_en, I40IWQPC_FASTREGEN) |
2768 LS_64(iw->priv_mode_en, I40IWQPC_PRIVEN) |
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06002769 LS_64((((vsi->stats_fcn_id_alloc) &&
2770 (dev->is_pf) && (vsi->fcn_id >= I40IW_FIRST_NON_PF_STAT)) ? 1 : 0),
2771 I40IWQPC_USESTATSINSTANCE) |
Faisal Latif86dbcd02016-01-20 13:40:10 -06002772 LS_64(1, I40IWQPC_IWARPMODE) |
2773 LS_64(iw->rcv_mark_en, I40IWQPC_RCVMARKERS) |
2774 LS_64(iw->align_hdrs, I40IWQPC_ALIGNHDRS) |
2775 LS_64(iw->rcv_no_mpa_crc, I40IWQPC_RCVNOMPACRC) |
2776 LS_64(iw->rcv_mark_offset, I40IWQPC_RCVMARKOFFSET) |
2777 LS_64(iw->snd_mark_offset, I40IWQPC_SNDMARKOFFSET));
2778 }
2779 if (info->tcp_info_valid) {
2780 qw0 |= LS_64(tcp->ipv4, I40IWQPC_IPV4) |
2781 LS_64(tcp->no_nagle, I40IWQPC_NONAGLE) |
2782 LS_64(tcp->insert_vlan_tag, I40IWQPC_INSERTVLANTAG) |
2783 LS_64(tcp->time_stamp, I40IWQPC_TIMESTAMP) |
2784 LS_64(tcp->cwnd_inc_limit, I40IWQPC_LIMIT) |
2785 LS_64(tcp->drop_ooo_seg, I40IWQPC_DROPOOOSEG) |
2786 LS_64(tcp->dup_ack_thresh, I40IWQPC_DUPACK_THRESH);
2787
2788 qw3 |= LS_64(tcp->ttl, I40IWQPC_TTL) |
2789 LS_64(tcp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
2790 LS_64(tcp->avoid_stretch_ack, I40IWQPC_AVOIDSTRETCHACK) |
2791 LS_64(tcp->tos, I40IWQPC_TOS) |
2792 LS_64(tcp->src_port, I40IWQPC_SRCPORTNUM) |
2793 LS_64(tcp->dst_port, I40IWQPC_DESTPORTNUM);
2794
2795 qp->src_mac_addr_idx = tcp->src_mac_addr_idx;
2796 set_64bit_val(qp_ctx,
2797 32,
2798 LS_64(tcp->dest_ip_addr2, I40IWQPC_DESTIPADDR2) |
2799 LS_64(tcp->dest_ip_addr3, I40IWQPC_DESTIPADDR3));
2800
2801 set_64bit_val(qp_ctx,
2802 40,
2803 LS_64(tcp->dest_ip_addr0, I40IWQPC_DESTIPADDR0) |
2804 LS_64(tcp->dest_ip_addr1, I40IWQPC_DESTIPADDR1));
2805
2806 set_64bit_val(qp_ctx,
2807 48,
2808 LS_64(tcp->snd_mss, I40IWQPC_SNDMSS) |
2809 LS_64(tcp->vlan_tag, I40IWQPC_VLANTAG) |
2810 LS_64(tcp->arp_idx, I40IWQPC_ARPIDX));
2811
2812 qw7 |= LS_64(tcp->flow_label, I40IWQPC_FLOWLABEL) |
2813 LS_64(tcp->wscale, I40IWQPC_WSCALE) |
2814 LS_64(tcp->ignore_tcp_opt, I40IWQPC_IGNORE_TCP_OPT) |
2815 LS_64(tcp->ignore_tcp_uns_opt, I40IWQPC_IGNORE_TCP_UNS_OPT) |
2816 LS_64(tcp->tcp_state, I40IWQPC_TCPSTATE) |
2817 LS_64(tcp->rcv_wscale, I40IWQPC_RCVSCALE) |
2818 LS_64(tcp->snd_wscale, I40IWQPC_SNDSCALE);
2819
2820 set_64bit_val(qp_ctx,
2821 72,
2822 LS_64(tcp->time_stamp_recent, I40IWQPC_TIMESTAMP_RECENT) |
2823 LS_64(tcp->time_stamp_age, I40IWQPC_TIMESTAMP_AGE));
2824 set_64bit_val(qp_ctx,
2825 80,
2826 LS_64(tcp->snd_nxt, I40IWQPC_SNDNXT) |
2827 LS_64(tcp->snd_wnd, I40IWQPC_SNDWND));
2828
2829 set_64bit_val(qp_ctx,
2830 88,
2831 LS_64(tcp->rcv_nxt, I40IWQPC_RCVNXT) |
2832 LS_64(tcp->rcv_wnd, I40IWQPC_RCVWND));
2833 set_64bit_val(qp_ctx,
2834 96,
2835 LS_64(tcp->snd_max, I40IWQPC_SNDMAX) |
2836 LS_64(tcp->snd_una, I40IWQPC_SNDUNA));
2837 set_64bit_val(qp_ctx,
2838 104,
2839 LS_64(tcp->srtt, I40IWQPC_SRTT) |
2840 LS_64(tcp->rtt_var, I40IWQPC_RTTVAR));
2841 set_64bit_val(qp_ctx,
2842 112,
2843 LS_64(tcp->ss_thresh, I40IWQPC_SSTHRESH) |
2844 LS_64(tcp->cwnd, I40IWQPC_CWND));
2845 set_64bit_val(qp_ctx,
2846 120,
2847 LS_64(tcp->snd_wl1, I40IWQPC_SNDWL1) |
2848 LS_64(tcp->snd_wl2, I40IWQPC_SNDWL2));
2849 set_64bit_val(qp_ctx,
2850 128,
2851 LS_64(tcp->max_snd_window, I40IWQPC_MAXSNDWND) |
2852 LS_64(tcp->rexmit_thresh, I40IWQPC_REXMIT_THRESH));
2853 set_64bit_val(qp_ctx,
2854 184,
2855 LS_64(tcp->local_ipaddr3, I40IWQPC_LOCAL_IPADDR3) |
2856 LS_64(tcp->local_ipaddr2, I40IWQPC_LOCAL_IPADDR2));
2857 set_64bit_val(qp_ctx,
2858 192,
2859 LS_64(tcp->local_ipaddr1, I40IWQPC_LOCAL_IPADDR1) |
2860 LS_64(tcp->local_ipaddr0, I40IWQPC_LOCAL_IPADDR0));
2861 }
2862
2863 set_64bit_val(qp_ctx, 0, qw0);
2864 set_64bit_val(qp_ctx, 24, qw3);
2865 set_64bit_val(qp_ctx, 56, qw7);
2866
2867 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "QP_HOST)CTX WQE",
2868 qp_ctx, I40IW_QP_CTX_SIZE);
2869 return 0;
2870}
2871
2872/**
2873 * i40iw_sc_alloc_stag - mr stag alloc
2874 * @dev: sc device struct
2875 * @info: stag info
2876 * @scratch: u64 saved to be used during cqp completion
2877 * @post_sq: flag for cqp db to ring
2878 */
2879static enum i40iw_status_code i40iw_sc_alloc_stag(
2880 struct i40iw_sc_dev *dev,
2881 struct i40iw_allocate_stag_info *info,
2882 u64 scratch,
2883 bool post_sq)
2884{
2885 u64 *wqe;
2886 struct i40iw_sc_cqp *cqp;
2887 u64 header;
Henry Orosco68583ca2016-11-19 20:26:25 -06002888 enum i40iw_page_size page_size;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002889
Henry Orosco68583ca2016-11-19 20:26:25 -06002890 page_size = (info->page_size == 0x200000) ? I40IW_PAGE_SIZE_2M : I40IW_PAGE_SIZE_4K;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002891 cqp = dev->cqp;
2892 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2893 if (!wqe)
2894 return I40IW_ERR_RING_FULL;
2895 set_64bit_val(wqe,
2896 8,
2897 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID) |
2898 LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN));
2899 set_64bit_val(wqe,
2900 16,
2901 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
2902 set_64bit_val(wqe,
2903 40,
2904 LS_64(info->hmc_fcn_index, I40IW_CQPSQ_STAG_HMCFNIDX));
2905
2906 header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
2907 LS_64(1, I40IW_CQPSQ_STAG_MR) |
2908 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
2909 LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
Henry Orosco68583ca2016-11-19 20:26:25 -06002910 LS_64(page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
Faisal Latif86dbcd02016-01-20 13:40:10 -06002911 LS_64(info->remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
2912 LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
2913 LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
2914 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2915
2916 i40iw_insert_wqe_hdr(wqe, header);
2917
2918 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "ALLOC_STAG WQE",
2919 wqe, I40IW_CQP_WQE_SIZE * 8);
2920
2921 if (post_sq)
2922 i40iw_sc_cqp_post_sq(cqp);
2923 return 0;
2924}
2925
2926/**
2927 * i40iw_sc_mr_reg_non_shared - non-shared mr registration
2928 * @dev: sc device struct
2929 * @info: mr info
2930 * @scratch: u64 saved to be used during cqp completion
2931 * @post_sq: flag for cqp db to ring
2932 */
2933static enum i40iw_status_code i40iw_sc_mr_reg_non_shared(
2934 struct i40iw_sc_dev *dev,
2935 struct i40iw_reg_ns_stag_info *info,
2936 u64 scratch,
2937 bool post_sq)
2938{
2939 u64 *wqe;
2940 u64 temp;
2941 struct i40iw_sc_cqp *cqp;
2942 u64 header;
2943 u32 pble_obj_cnt;
2944 bool remote_access;
2945 u8 addr_type;
Henry Orosco68583ca2016-11-19 20:26:25 -06002946 enum i40iw_page_size page_size;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002947
Henry Orosco68583ca2016-11-19 20:26:25 -06002948 page_size = (info->page_size == 0x200000) ? I40IW_PAGE_SIZE_2M : I40IW_PAGE_SIZE_4K;
Faisal Latif86dbcd02016-01-20 13:40:10 -06002949 if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
2950 I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
2951 remote_access = true;
2952 else
2953 remote_access = false;
2954
2955 pble_obj_cnt = dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
2956
2957 if (info->chunk_size && (info->first_pm_pbl_index >= pble_obj_cnt))
2958 return I40IW_ERR_INVALID_PBLE_INDEX;
2959
2960 cqp = dev->cqp;
2961 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
2962 if (!wqe)
2963 return I40IW_ERR_RING_FULL;
2964
2965 temp = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? (uintptr_t)info->va : info->fbo;
2966 set_64bit_val(wqe, 0, temp);
2967
2968 set_64bit_val(wqe,
2969 8,
2970 LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN) |
2971 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
2972
2973 set_64bit_val(wqe,
2974 16,
2975 LS_64(info->stag_key, I40IW_CQPSQ_STAG_KEY) |
2976 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
2977 if (!info->chunk_size) {
2978 set_64bit_val(wqe, 32, info->reg_addr_pa);
2979 set_64bit_val(wqe, 48, 0);
2980 } else {
2981 set_64bit_val(wqe, 32, 0);
2982 set_64bit_val(wqe, 48, info->first_pm_pbl_index);
2983 }
2984 set_64bit_val(wqe, 40, info->hmc_fcn_index);
2985 set_64bit_val(wqe, 56, 0);
2986
2987 addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
2988 header = LS_64(I40IW_CQP_OP_REG_MR, I40IW_CQPSQ_OPCODE) |
2989 LS_64(1, I40IW_CQPSQ_STAG_MR) |
2990 LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
Henry Orosco68583ca2016-11-19 20:26:25 -06002991 LS_64(page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
Faisal Latif86dbcd02016-01-20 13:40:10 -06002992 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
2993 LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
2994 LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
2995 LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
2996 LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
2997 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
2998
2999 i40iw_insert_wqe_hdr(wqe, header);
3000
3001 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_NS WQE",
3002 wqe, I40IW_CQP_WQE_SIZE * 8);
3003
3004 if (post_sq)
3005 i40iw_sc_cqp_post_sq(cqp);
3006 return 0;
3007}
3008
3009/**
3010 * i40iw_sc_mr_reg_shared - registered shared memory region
3011 * @dev: sc device struct
3012 * @info: info for shared memory registeration
3013 * @scratch: u64 saved to be used during cqp completion
3014 * @post_sq: flag for cqp db to ring
3015 */
3016static enum i40iw_status_code i40iw_sc_mr_reg_shared(
3017 struct i40iw_sc_dev *dev,
3018 struct i40iw_register_shared_stag *info,
3019 u64 scratch,
3020 bool post_sq)
3021{
3022 u64 *wqe;
3023 struct i40iw_sc_cqp *cqp;
3024 u64 temp, va64, fbo, header;
3025 u32 va32;
3026 bool remote_access;
3027 u8 addr_type;
3028
3029 if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
3030 I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
3031 remote_access = true;
3032 else
3033 remote_access = false;
3034 cqp = dev->cqp;
3035 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3036 if (!wqe)
3037 return I40IW_ERR_RING_FULL;
3038 va64 = (uintptr_t)(info->va);
3039 va32 = (u32)(va64 & 0x00000000FFFFFFFF);
3040 fbo = (u64)(va32 & (4096 - 1));
3041
3042 set_64bit_val(wqe,
3043 0,
3044 (info->addr_type == I40IW_ADDR_TYPE_VA_BASED ? (uintptr_t)info->va : fbo));
3045
3046 set_64bit_val(wqe,
3047 8,
3048 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
3049 temp = LS_64(info->new_stag_key, I40IW_CQPSQ_STAG_KEY) |
3050 LS_64(info->new_stag_idx, I40IW_CQPSQ_STAG_IDX) |
3051 LS_64(info->parent_stag_idx, I40IW_CQPSQ_STAG_PARENTSTAGIDX);
3052 set_64bit_val(wqe, 16, temp);
3053
3054 addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
3055 header = LS_64(I40IW_CQP_OP_REG_SMR, I40IW_CQPSQ_OPCODE) |
3056 LS_64(1, I40IW_CQPSQ_STAG_MR) |
3057 LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
3058 LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
3059 LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
3060 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3061
3062 i40iw_insert_wqe_hdr(wqe, header);
3063
3064 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_SHARED WQE",
3065 wqe, I40IW_CQP_WQE_SIZE * 8);
3066
3067 if (post_sq)
3068 i40iw_sc_cqp_post_sq(cqp);
3069 return 0;
3070}
3071
3072/**
3073 * i40iw_sc_dealloc_stag - deallocate stag
3074 * @dev: sc device struct
3075 * @info: dealloc stag info
3076 * @scratch: u64 saved to be used during cqp completion
3077 * @post_sq: flag for cqp db to ring
3078 */
3079static enum i40iw_status_code i40iw_sc_dealloc_stag(
3080 struct i40iw_sc_dev *dev,
3081 struct i40iw_dealloc_stag_info *info,
3082 u64 scratch,
3083 bool post_sq)
3084{
3085 u64 header;
3086 u64 *wqe;
3087 struct i40iw_sc_cqp *cqp;
3088
3089 cqp = dev->cqp;
3090 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3091 if (!wqe)
3092 return I40IW_ERR_RING_FULL;
3093 set_64bit_val(wqe,
3094 8,
3095 LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
3096 set_64bit_val(wqe,
3097 16,
3098 LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
3099
3100 header = LS_64(I40IW_CQP_OP_DEALLOC_STAG, I40IW_CQPSQ_OPCODE) |
3101 LS_64(info->mr, I40IW_CQPSQ_STAG_MR) |
3102 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3103
3104 i40iw_insert_wqe_hdr(wqe, header);
3105
3106 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "DEALLOC_STAG WQE",
3107 wqe, I40IW_CQP_WQE_SIZE * 8);
3108
3109 if (post_sq)
3110 i40iw_sc_cqp_post_sq(cqp);
3111 return 0;
3112}
3113
3114/**
3115 * i40iw_sc_query_stag - query hardware for stag
3116 * @dev: sc device struct
3117 * @scratch: u64 saved to be used during cqp completion
3118 * @stag_index: stag index for query
3119 * @post_sq: flag for cqp db to ring
3120 */
3121static enum i40iw_status_code i40iw_sc_query_stag(struct i40iw_sc_dev *dev,
3122 u64 scratch,
3123 u32 stag_index,
3124 bool post_sq)
3125{
3126 u64 header;
3127 u64 *wqe;
3128 struct i40iw_sc_cqp *cqp;
3129
3130 cqp = dev->cqp;
3131 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3132 if (!wqe)
3133 return I40IW_ERR_RING_FULL;
3134 set_64bit_val(wqe,
3135 16,
3136 LS_64(stag_index, I40IW_CQPSQ_QUERYSTAG_IDX));
3137
3138 header = LS_64(I40IW_CQP_OP_QUERY_STAG, I40IW_CQPSQ_OPCODE) |
3139 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3140
3141 i40iw_insert_wqe_hdr(wqe, header);
3142
3143 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QUERY_STAG WQE",
3144 wqe, I40IW_CQP_WQE_SIZE * 8);
3145
3146 if (post_sq)
3147 i40iw_sc_cqp_post_sq(cqp);
3148 return 0;
3149}
3150
3151/**
3152 * i40iw_sc_mw_alloc - mw allocate
3153 * @dev: sc device struct
3154 * @scratch: u64 saved to be used during cqp completion
3155 * @mw_stag_index:stag index
3156 * @pd_id: pd is for this mw
3157 * @post_sq: flag for cqp db to ring
3158 */
3159static enum i40iw_status_code i40iw_sc_mw_alloc(
3160 struct i40iw_sc_dev *dev,
3161 u64 scratch,
3162 u32 mw_stag_index,
3163 u16 pd_id,
3164 bool post_sq)
3165{
3166 u64 header;
3167 struct i40iw_sc_cqp *cqp;
3168 u64 *wqe;
3169
3170 cqp = dev->cqp;
3171 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3172 if (!wqe)
3173 return I40IW_ERR_RING_FULL;
3174 set_64bit_val(wqe, 8, LS_64(pd_id, I40IW_CQPSQ_STAG_PDID));
3175 set_64bit_val(wqe,
3176 16,
3177 LS_64(mw_stag_index, I40IW_CQPSQ_STAG_IDX));
3178
3179 header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
3180 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3181
3182 i40iw_insert_wqe_hdr(wqe, header);
3183
3184 i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MW_ALLOC WQE",
3185 wqe, I40IW_CQP_WQE_SIZE * 8);
3186
3187 if (post_sq)
3188 i40iw_sc_cqp_post_sq(cqp);
3189 return 0;
3190}
3191
3192/**
Ismail, Mustafab7aee852016-04-18 10:33:06 -05003193 * i40iw_sc_mr_fast_register - Posts RDMA fast register mr WR to iwarp qp
3194 * @qp: sc qp struct
3195 * @info: fast mr info
3196 * @post_sq: flag for cqp db to ring
3197 */
3198enum i40iw_status_code i40iw_sc_mr_fast_register(
3199 struct i40iw_sc_qp *qp,
3200 struct i40iw_fast_reg_stag_info *info,
3201 bool post_sq)
3202{
3203 u64 temp, header;
3204 u64 *wqe;
3205 u32 wqe_idx;
Henry Orosco68583ca2016-11-19 20:26:25 -06003206 enum i40iw_page_size page_size;
Ismail, Mustafab7aee852016-04-18 10:33:06 -05003207
Henry Orosco68583ca2016-11-19 20:26:25 -06003208 page_size = (info->page_size == 0x200000) ? I40IW_PAGE_SIZE_2M : I40IW_PAGE_SIZE_4K;
Ismail, Mustafab7aee852016-04-18 10:33:06 -05003209 wqe = i40iw_qp_get_next_send_wqe(&qp->qp_uk, &wqe_idx, I40IW_QP_WQE_MIN_SIZE,
3210 0, info->wr_id);
3211 if (!wqe)
3212 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
3213
3214 i40iw_debug(qp->dev, I40IW_DEBUG_MR, "%s: wr_id[%llxh] wqe_idx[%04d] location[%p]\n",
3215 __func__, info->wr_id, wqe_idx,
3216 &qp->qp_uk.sq_wrtrk_array[wqe_idx].wrid);
3217 temp = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? (uintptr_t)info->va : info->fbo;
3218 set_64bit_val(wqe, 0, temp);
3219
3220 temp = RS_64(info->first_pm_pbl_index >> 16, I40IWQPSQ_FIRSTPMPBLIDXHI);
3221 set_64bit_val(wqe,
3222 8,
3223 LS_64(temp, I40IWQPSQ_FIRSTPMPBLIDXHI) |
3224 LS_64(info->reg_addr_pa >> I40IWQPSQ_PBLADDR_SHIFT, I40IWQPSQ_PBLADDR));
3225
3226 set_64bit_val(wqe,
3227 16,
3228 info->total_len |
3229 LS_64(info->first_pm_pbl_index, I40IWQPSQ_FIRSTPMPBLIDXLO));
3230
3231 header = LS_64(info->stag_key, I40IWQPSQ_STAGKEY) |
3232 LS_64(info->stag_idx, I40IWQPSQ_STAGINDEX) |
3233 LS_64(I40IWQP_OP_FAST_REGISTER, I40IWQPSQ_OPCODE) |
3234 LS_64(info->chunk_size, I40IWQPSQ_LPBLSIZE) |
Henry Orosco68583ca2016-11-19 20:26:25 -06003235 LS_64(page_size, I40IWQPSQ_HPAGESIZE) |
Ismail, Mustafab7aee852016-04-18 10:33:06 -05003236 LS_64(info->access_rights, I40IWQPSQ_STAGRIGHTS) |
3237 LS_64(info->addr_type, I40IWQPSQ_VABASEDTO) |
3238 LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
3239 LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
3240 LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
3241 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3242
3243 i40iw_insert_wqe_hdr(wqe, header);
3244
3245 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "FAST_REG WQE",
3246 wqe, I40IW_QP_WQE_MIN_SIZE);
3247
3248 if (post_sq)
3249 i40iw_qp_post_wr(&qp->qp_uk);
3250 return 0;
3251}
3252
3253/**
Faisal Latif86dbcd02016-01-20 13:40:10 -06003254 * i40iw_sc_send_lsmm - send last streaming mode message
3255 * @qp: sc qp struct
3256 * @lsmm_buf: buffer with lsmm message
3257 * @size: size of lsmm buffer
3258 * @stag: stag of lsmm buffer
3259 */
3260static void i40iw_sc_send_lsmm(struct i40iw_sc_qp *qp,
3261 void *lsmm_buf,
3262 u32 size,
3263 i40iw_stag stag)
3264{
3265 u64 *wqe;
3266 u64 header;
3267 struct i40iw_qp_uk *qp_uk;
3268
3269 qp_uk = &qp->qp_uk;
3270 wqe = qp_uk->sq_base->elem;
3271
3272 set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
3273
3274 set_64bit_val(wqe, 8, (size | LS_64(stag, I40IWQPSQ_FRAG_STAG)));
3275
3276 set_64bit_val(wqe, 16, 0);
3277
3278 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
3279 LS_64(1, I40IWQPSQ_STREAMMODE) |
3280 LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
3281 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3282
3283 i40iw_insert_wqe_hdr(wqe, header);
3284
3285 i40iw_debug_buf(qp->dev, I40IW_DEBUG_QP, "SEND_LSMM WQE",
3286 wqe, I40IW_QP_WQE_MIN_SIZE);
3287}
3288
3289/**
3290 * i40iw_sc_send_lsmm_nostag - for privilege qp
3291 * @qp: sc qp struct
3292 * @lsmm_buf: buffer with lsmm message
3293 * @size: size of lsmm buffer
3294 */
3295static void i40iw_sc_send_lsmm_nostag(struct i40iw_sc_qp *qp,
3296 void *lsmm_buf,
3297 u32 size)
3298{
3299 u64 *wqe;
3300 u64 header;
3301 struct i40iw_qp_uk *qp_uk;
3302
3303 qp_uk = &qp->qp_uk;
3304 wqe = qp_uk->sq_base->elem;
3305
3306 set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
3307
3308 set_64bit_val(wqe, 8, size);
3309
3310 set_64bit_val(wqe, 16, 0);
3311
3312 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
3313 LS_64(1, I40IWQPSQ_STREAMMODE) |
3314 LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
3315 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3316
3317 i40iw_insert_wqe_hdr(wqe, header);
3318
3319 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "SEND_LSMM_NOSTAG WQE",
3320 wqe, I40IW_QP_WQE_MIN_SIZE);
3321}
3322
3323/**
3324 * i40iw_sc_send_rtt - send last read0 or write0
3325 * @qp: sc qp struct
3326 * @read: Do read0 or write0
3327 */
3328static void i40iw_sc_send_rtt(struct i40iw_sc_qp *qp, bool read)
3329{
3330 u64 *wqe;
3331 u64 header;
3332 struct i40iw_qp_uk *qp_uk;
3333
3334 qp_uk = &qp->qp_uk;
3335 wqe = qp_uk->sq_base->elem;
3336
3337 set_64bit_val(wqe, 0, 0);
3338 set_64bit_val(wqe, 8, 0);
3339 set_64bit_val(wqe, 16, 0);
3340 if (read) {
3341 header = LS_64(0x1234, I40IWQPSQ_REMSTAG) |
3342 LS_64(I40IWQP_OP_RDMA_READ, I40IWQPSQ_OPCODE) |
3343 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3344 set_64bit_val(wqe, 8, ((u64)0xabcd << 32));
3345 } else {
3346 header = LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
3347 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3348 }
3349
3350 i40iw_insert_wqe_hdr(wqe, header);
3351
3352 i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "RTR WQE",
3353 wqe, I40IW_QP_WQE_MIN_SIZE);
3354}
3355
3356/**
3357 * i40iw_sc_post_wqe0 - send wqe with opcode
3358 * @qp: sc qp struct
3359 * @opcode: opcode to use for wqe0
3360 */
3361static enum i40iw_status_code i40iw_sc_post_wqe0(struct i40iw_sc_qp *qp, u8 opcode)
3362{
3363 u64 *wqe;
3364 u64 header;
3365 struct i40iw_qp_uk *qp_uk;
3366
3367 qp_uk = &qp->qp_uk;
3368 wqe = qp_uk->sq_base->elem;
3369
3370 if (!wqe)
3371 return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
3372 switch (opcode) {
3373 case I40IWQP_OP_NOP:
3374 set_64bit_val(wqe, 0, 0);
3375 set_64bit_val(wqe, 8, 0);
3376 set_64bit_val(wqe, 16, 0);
3377 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
3378 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3379
3380 i40iw_insert_wqe_hdr(wqe, header);
3381 break;
3382 case I40IWQP_OP_RDMA_SEND:
3383 set_64bit_val(wqe, 0, 0);
3384 set_64bit_val(wqe, 8, 0);
3385 set_64bit_val(wqe, 16, 0);
3386 header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
3387 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID) |
3388 LS_64(1, I40IWQPSQ_STREAMMODE) |
3389 LS_64(1, I40IWQPSQ_WAITFORRCVPDU);
3390
3391 i40iw_insert_wqe_hdr(wqe, header);
3392 break;
3393 default:
3394 i40iw_debug(qp->dev, I40IW_DEBUG_QP, "%s: Invalid WQE zero opcode\n",
3395 __func__);
3396 break;
3397 }
3398 return 0;
3399}
3400
3401/**
3402 * i40iw_sc_init_iw_hmc() - queries fpm values using cqp and populates hmc_info
3403 * @dev : ptr to i40iw_dev struct
3404 * @hmc_fn_id: hmc function id
3405 */
3406enum i40iw_status_code i40iw_sc_init_iw_hmc(struct i40iw_sc_dev *dev, u8 hmc_fn_id)
3407{
3408 struct i40iw_hmc_info *hmc_info;
3409 struct i40iw_dma_mem query_fpm_mem;
3410 struct i40iw_virt_mem virt_mem;
3411 struct i40iw_vfdev *vf_dev = NULL;
3412 u32 mem_size;
3413 enum i40iw_status_code ret_code = 0;
3414 bool poll_registers = true;
3415 u16 iw_vf_idx;
3416 u8 wait_type;
3417
3418 if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
3419 (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
3420 return I40IW_ERR_INVALID_HMCFN_ID;
3421
3422 i40iw_debug(dev, I40IW_DEBUG_HMC, "hmc_fn_id %u, dev->hmc_fn_id %u\n", hmc_fn_id,
3423 dev->hmc_fn_id);
3424 if (hmc_fn_id == dev->hmc_fn_id) {
3425 hmc_info = dev->hmc_info;
3426 query_fpm_mem.pa = dev->fpm_query_buf_pa;
3427 query_fpm_mem.va = dev->fpm_query_buf;
3428 } else {
3429 vf_dev = i40iw_vfdev_from_fpm(dev, hmc_fn_id);
3430 if (!vf_dev)
3431 return I40IW_ERR_INVALID_VF_ID;
3432
3433 hmc_info = &vf_dev->hmc_info;
3434 iw_vf_idx = vf_dev->iw_vf_idx;
3435 i40iw_debug(dev, I40IW_DEBUG_HMC, "vf_dev %p, hmc_info %p, hmc_obj %p\n", vf_dev,
3436 hmc_info, hmc_info->hmc_obj);
3437 if (!vf_dev->fpm_query_buf) {
3438 if (!dev->vf_fpm_query_buf[iw_vf_idx].va) {
3439 ret_code = i40iw_alloc_query_fpm_buf(dev,
3440 &dev->vf_fpm_query_buf[iw_vf_idx]);
3441 if (ret_code)
3442 return ret_code;
3443 }
3444 vf_dev->fpm_query_buf = dev->vf_fpm_query_buf[iw_vf_idx].va;
3445 vf_dev->fpm_query_buf_pa = dev->vf_fpm_query_buf[iw_vf_idx].pa;
3446 }
3447 query_fpm_mem.pa = vf_dev->fpm_query_buf_pa;
3448 query_fpm_mem.va = vf_dev->fpm_query_buf;
3449 /**
3450 * It is HARDWARE specific:
3451 * this call is done by PF for VF and
3452 * i40iw_sc_query_fpm_values needs ccq poll
3453 * because PF ccq is already created.
3454 */
3455 poll_registers = false;
3456 }
3457
3458 hmc_info->hmc_fn_id = hmc_fn_id;
3459
3460 if (hmc_fn_id != dev->hmc_fn_id) {
3461 ret_code =
3462 i40iw_cqp_query_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
3463 } else {
3464 wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
3465 (u8)I40IW_CQP_WAIT_POLL_CQ;
3466
3467 ret_code = i40iw_sc_query_fpm_values(
3468 dev->cqp,
3469 0,
3470 hmc_info->hmc_fn_id,
3471 &query_fpm_mem,
3472 true,
3473 wait_type);
3474 }
3475 if (ret_code)
3476 return ret_code;
3477
3478 /* parse the fpm_query_buf and fill hmc obj info */
3479 ret_code =
3480 i40iw_sc_parse_fpm_query_buf((u64 *)query_fpm_mem.va,
3481 hmc_info,
3482 &dev->hmc_fpm_misc);
3483 if (ret_code)
3484 return ret_code;
3485 i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "QUERY FPM BUFFER",
3486 query_fpm_mem.va, I40IW_QUERY_FPM_BUF_SIZE);
3487
3488 if (hmc_fn_id != dev->hmc_fn_id) {
3489 i40iw_cqp_commit_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
3490
3491 /* parse the fpm_commit_buf and fill hmc obj info */
Ismail, Mustafafa415372016-04-18 10:33:08 -05003492 i40iw_sc_parse_fpm_commit_buf((u64 *)query_fpm_mem.va, hmc_info->hmc_obj, &hmc_info->sd_table.sd_cnt);
Faisal Latif86dbcd02016-01-20 13:40:10 -06003493 mem_size = sizeof(struct i40iw_hmc_sd_entry) *
3494 (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index);
3495 ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
3496 if (ret_code)
3497 return ret_code;
3498 hmc_info->sd_table.sd_entry = virt_mem.va;
3499 }
3500
Faisal Latif86dbcd02016-01-20 13:40:10 -06003501 return ret_code;
3502}
3503
3504/**
3505 * i40iw_sc_configure_iw_fpm() - commits hmc obj cnt values using cqp command and
3506 * populates fpm base address in hmc_info
3507 * @dev : ptr to i40iw_dev struct
3508 * @hmc_fn_id: hmc function id
3509 */
3510static enum i40iw_status_code i40iw_sc_configure_iw_fpm(struct i40iw_sc_dev *dev,
3511 u8 hmc_fn_id)
3512{
3513 struct i40iw_hmc_info *hmc_info;
3514 struct i40iw_hmc_obj_info *obj_info;
3515 u64 *buf;
3516 struct i40iw_dma_mem commit_fpm_mem;
3517 u32 i, j;
3518 enum i40iw_status_code ret_code = 0;
3519 bool poll_registers = true;
3520 u8 wait_type;
3521
3522 if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
3523 (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
3524 return I40IW_ERR_INVALID_HMCFN_ID;
3525
3526 if (hmc_fn_id == dev->hmc_fn_id) {
3527 hmc_info = dev->hmc_info;
3528 } else {
3529 hmc_info = i40iw_vf_hmcinfo_from_fpm(dev, hmc_fn_id);
3530 poll_registers = false;
3531 }
3532 if (!hmc_info)
3533 return I40IW_ERR_BAD_PTR;
3534
3535 obj_info = hmc_info->hmc_obj;
3536 buf = dev->fpm_commit_buf;
3537
3538 /* copy cnt values in commit buf */
3539 for (i = I40IW_HMC_IW_QP, j = 0; i <= I40IW_HMC_IW_PBLE;
3540 i++, j += 8)
3541 set_64bit_val(buf, j, (u64)obj_info[i].cnt);
3542
3543 set_64bit_val(buf, 40, 0); /* APBVT rsvd */
3544
3545 commit_fpm_mem.pa = dev->fpm_commit_buf_pa;
3546 commit_fpm_mem.va = dev->fpm_commit_buf;
3547 wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
3548 (u8)I40IW_CQP_WAIT_POLL_CQ;
3549 ret_code = i40iw_sc_commit_fpm_values(
3550 dev->cqp,
3551 0,
3552 hmc_info->hmc_fn_id,
3553 &commit_fpm_mem,
3554 true,
3555 wait_type);
3556
3557 /* parse the fpm_commit_buf and fill hmc obj info */
3558 if (!ret_code)
Ismail, Mustafafa415372016-04-18 10:33:08 -05003559 ret_code = i40iw_sc_parse_fpm_commit_buf(dev->fpm_commit_buf,
3560 hmc_info->hmc_obj,
3561 &hmc_info->sd_table.sd_cnt);
Faisal Latif86dbcd02016-01-20 13:40:10 -06003562
3563 i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "COMMIT FPM BUFFER",
3564 commit_fpm_mem.va, I40IW_COMMIT_FPM_BUF_SIZE);
3565
3566 return ret_code;
3567}
3568
3569/**
3570 * cqp_sds_wqe_fill - fill cqp wqe doe sd
3571 * @cqp: struct for cqp hw
3572 * @info; sd info for wqe
3573 * @scratch: u64 saved to be used during cqp completion
3574 */
3575static enum i40iw_status_code cqp_sds_wqe_fill(struct i40iw_sc_cqp *cqp,
3576 struct i40iw_update_sds_info *info,
3577 u64 scratch)
3578{
3579 u64 data;
3580 u64 header;
3581 u64 *wqe;
3582 int mem_entries, wqe_entries;
3583 struct i40iw_dma_mem *sdbuf = &cqp->sdbuf;
3584
3585 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3586 if (!wqe)
3587 return I40IW_ERR_RING_FULL;
3588
3589 I40IW_CQP_INIT_WQE(wqe);
3590 wqe_entries = (info->cnt > 3) ? 3 : info->cnt;
3591 mem_entries = info->cnt - wqe_entries;
3592
3593 header = LS_64(I40IW_CQP_OP_UPDATE_PE_SDS, I40IW_CQPSQ_OPCODE) |
3594 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
3595 LS_64(mem_entries, I40IW_CQPSQ_UPESD_ENTRY_COUNT);
3596
3597 if (mem_entries) {
3598 memcpy(sdbuf->va, &info->entry[3], (mem_entries << 4));
3599 data = sdbuf->pa;
3600 } else {
3601 data = 0;
3602 }
3603 data |= LS_64(info->hmc_fn_id, I40IW_CQPSQ_UPESD_HMCFNID);
3604
3605 set_64bit_val(wqe, 16, data);
3606
3607 switch (wqe_entries) {
3608 case 3:
3609 set_64bit_val(wqe, 48,
3610 (LS_64(info->entry[2].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
3611 LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
3612
3613 set_64bit_val(wqe, 56, info->entry[2].data);
3614 /* fallthrough */
3615 case 2:
3616 set_64bit_val(wqe, 32,
3617 (LS_64(info->entry[1].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
3618 LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
3619
3620 set_64bit_val(wqe, 40, info->entry[1].data);
3621 /* fallthrough */
3622 case 1:
3623 set_64bit_val(wqe, 0,
3624 LS_64(info->entry[0].cmd, I40IW_CQPSQ_UPESD_SDCMD));
3625
3626 set_64bit_val(wqe, 8, info->entry[0].data);
3627 break;
3628 default:
3629 break;
3630 }
3631
3632 i40iw_insert_wqe_hdr(wqe, header);
3633
3634 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "UPDATE_PE_SDS WQE",
3635 wqe, I40IW_CQP_WQE_SIZE * 8);
3636 return 0;
3637}
3638
3639/**
3640 * i40iw_update_pe_sds - cqp wqe for sd
3641 * @dev: ptr to i40iw_dev struct
3642 * @info: sd info for sd's
3643 * @scratch: u64 saved to be used during cqp completion
3644 */
3645static enum i40iw_status_code i40iw_update_pe_sds(struct i40iw_sc_dev *dev,
3646 struct i40iw_update_sds_info *info,
3647 u64 scratch)
3648{
3649 struct i40iw_sc_cqp *cqp = dev->cqp;
3650 enum i40iw_status_code ret_code;
3651
3652 ret_code = cqp_sds_wqe_fill(cqp, info, scratch);
3653 if (!ret_code)
3654 i40iw_sc_cqp_post_sq(cqp);
3655
3656 return ret_code;
3657}
3658
3659/**
3660 * i40iw_update_sds_noccq - update sd before ccq created
3661 * @dev: sc device struct
3662 * @info: sd info for sd's
3663 */
3664enum i40iw_status_code i40iw_update_sds_noccq(struct i40iw_sc_dev *dev,
3665 struct i40iw_update_sds_info *info)
3666{
3667 u32 error, val, tail;
3668 struct i40iw_sc_cqp *cqp = dev->cqp;
3669 enum i40iw_status_code ret_code;
3670
3671 ret_code = cqp_sds_wqe_fill(cqp, info, 0);
3672 if (ret_code)
3673 return ret_code;
3674 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
3675 if (error)
3676 return I40IW_ERR_CQP_COMPL_ERROR;
3677
3678 i40iw_sc_cqp_post_sq(cqp);
3679 ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
3680
3681 return ret_code;
3682}
3683
3684/**
3685 * i40iw_sc_suspend_qp - suspend qp for param change
3686 * @cqp: struct for cqp hw
3687 * @qp: sc qp struct
3688 * @scratch: u64 saved to be used during cqp completion
3689 */
3690enum i40iw_status_code i40iw_sc_suspend_qp(struct i40iw_sc_cqp *cqp,
3691 struct i40iw_sc_qp *qp,
3692 u64 scratch)
3693{
3694 u64 header;
3695 u64 *wqe;
3696
3697 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3698 if (!wqe)
3699 return I40IW_ERR_RING_FULL;
3700 header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_SUSPENDQP_QPID) |
3701 LS_64(I40IW_CQP_OP_SUSPEND_QP, I40IW_CQPSQ_OPCODE) |
3702 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3703
3704 i40iw_insert_wqe_hdr(wqe, header);
3705
3706 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SUSPEND_QP WQE",
3707 wqe, I40IW_CQP_WQE_SIZE * 8);
3708
3709 i40iw_sc_cqp_post_sq(cqp);
3710 return 0;
3711}
3712
3713/**
3714 * i40iw_sc_resume_qp - resume qp after suspend
3715 * @cqp: struct for cqp hw
3716 * @qp: sc qp struct
3717 * @scratch: u64 saved to be used during cqp completion
3718 */
3719enum i40iw_status_code i40iw_sc_resume_qp(struct i40iw_sc_cqp *cqp,
3720 struct i40iw_sc_qp *qp,
3721 u64 scratch)
3722{
3723 u64 header;
3724 u64 *wqe;
3725
3726 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3727 if (!wqe)
3728 return I40IW_ERR_RING_FULL;
3729 set_64bit_val(wqe,
3730 16,
3731 LS_64(qp->qs_handle, I40IW_CQPSQ_RESUMEQP_QSHANDLE));
3732
3733 header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_RESUMEQP_QPID) |
3734 LS_64(I40IW_CQP_OP_RESUME_QP, I40IW_CQPSQ_OPCODE) |
3735 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3736
3737 i40iw_insert_wqe_hdr(wqe, header);
3738
3739 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "RESUME_QP WQE",
3740 wqe, I40IW_CQP_WQE_SIZE * 8);
3741
3742 i40iw_sc_cqp_post_sq(cqp);
3743 return 0;
3744}
3745
3746/**
3747 * i40iw_sc_static_hmc_pages_allocated - cqp wqe to allocate hmc pages
3748 * @cqp: struct for cqp hw
3749 * @scratch: u64 saved to be used during cqp completion
3750 * @hmc_fn_id: hmc function id
3751 * @post_sq: flag for cqp db to ring
3752 * @poll_registers: flag to poll register for cqp completion
3753 */
3754enum i40iw_status_code i40iw_sc_static_hmc_pages_allocated(
3755 struct i40iw_sc_cqp *cqp,
3756 u64 scratch,
3757 u8 hmc_fn_id,
3758 bool post_sq,
3759 bool poll_registers)
3760{
3761 u64 header;
3762 u64 *wqe;
3763 u32 tail, val, error;
3764 enum i40iw_status_code ret_code = 0;
3765
3766 wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
3767 if (!wqe)
3768 return I40IW_ERR_RING_FULL;
3769 set_64bit_val(wqe,
3770 16,
3771 LS_64(hmc_fn_id, I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID));
3772
3773 header = LS_64(I40IW_CQP_OP_SHMC_PAGES_ALLOCATED, I40IW_CQPSQ_OPCODE) |
3774 LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
3775
3776 i40iw_insert_wqe_hdr(wqe, header);
3777
3778 i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SHMC_PAGES_ALLOCATED WQE",
3779 wqe, I40IW_CQP_WQE_SIZE * 8);
3780 i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
3781 if (error) {
3782 ret_code = I40IW_ERR_CQP_COMPL_ERROR;
3783 return ret_code;
3784 }
3785 if (post_sq) {
3786 i40iw_sc_cqp_post_sq(cqp);
3787 if (poll_registers)
3788 /* check for cqp sq tail update */
3789 ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
3790 else
3791 ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
3792 I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
3793 NULL);
3794 }
3795
3796 return ret_code;
3797}
3798
3799/**
3800 * i40iw_ring_full - check if cqp ring is full
3801 * @cqp: struct for cqp hw
3802 */
3803static bool i40iw_ring_full(struct i40iw_sc_cqp *cqp)
3804{
3805 return I40IW_RING_FULL_ERR(cqp->sq_ring);
3806}
3807
3808/**
Ismail, Mustafafa415372016-04-18 10:33:08 -05003809 * i40iw_est_sd - returns approximate number of SDs for HMC
3810 * @dev: sc device struct
3811 * @hmc_info: hmc structure, size and count for HMC objects
3812 */
3813static u64 i40iw_est_sd(struct i40iw_sc_dev *dev, struct i40iw_hmc_info *hmc_info)
3814{
3815 int i;
3816 u64 size = 0;
3817 u64 sd;
3818
3819 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_PBLE; i++)
3820 size += hmc_info->hmc_obj[i].cnt * hmc_info->hmc_obj[i].size;
3821
3822 if (dev->is_pf)
3823 size += hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt * hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size;
3824
3825 if (size & 0x1FFFFF)
3826 sd = (size >> 21) + 1; /* add 1 for remainder */
3827 else
3828 sd = size >> 21;
3829
3830 if (!dev->is_pf) {
3831 /* 2MB alignment for VF PBLE HMC */
3832 size = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt * hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size;
3833 if (size & 0x1FFFFF)
3834 sd += (size >> 21) + 1; /* add 1 for remainder */
3835 else
3836 sd += size >> 21;
3837 }
3838
3839 return sd;
3840}
3841
3842/**
Faisal Latif86dbcd02016-01-20 13:40:10 -06003843 * i40iw_config_fpm_values - configure HMC objects
3844 * @dev: sc device struct
3845 * @qp_count: desired qp count
3846 */
3847enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_count)
3848{
3849 struct i40iw_virt_mem virt_mem;
3850 u32 i, mem_size;
3851 u32 qpwantedoriginal, qpwanted, mrwanted, pblewanted;
3852 u32 powerof2;
Ismail, Mustafafa415372016-04-18 10:33:08 -05003853 u64 sd_needed;
Faisal Latif86dbcd02016-01-20 13:40:10 -06003854 u32 loop_count = 0;
3855
3856 struct i40iw_hmc_info *hmc_info;
3857 struct i40iw_hmc_fpm_misc *hmc_fpm_misc;
3858 enum i40iw_status_code ret_code = 0;
3859
3860 hmc_info = dev->hmc_info;
3861 hmc_fpm_misc = &dev->hmc_fpm_misc;
3862
3863 ret_code = i40iw_sc_init_iw_hmc(dev, dev->hmc_fn_id);
3864 if (ret_code) {
3865 i40iw_debug(dev, I40IW_DEBUG_HMC,
3866 "i40iw_sc_init_iw_hmc returned error_code = %d\n",
3867 ret_code);
3868 return ret_code;
3869 }
3870
Ismail, Mustafafa415372016-04-18 10:33:08 -05003871 for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++)
Faisal Latif86dbcd02016-01-20 13:40:10 -06003872 hmc_info->hmc_obj[i].cnt = hmc_info->hmc_obj[i].max_cnt;
Ismail, Mustafafa415372016-04-18 10:33:08 -05003873 sd_needed = i40iw_est_sd(dev, hmc_info);
Faisal Latif86dbcd02016-01-20 13:40:10 -06003874 i40iw_debug(dev, I40IW_DEBUG_HMC,
3875 "%s: FW initial max sd_count[%08lld] first_sd_index[%04d]\n",
3876 __func__, sd_needed, hmc_info->first_sd_index);
3877 i40iw_debug(dev, I40IW_DEBUG_HMC,
Ismail, Mustafafa415372016-04-18 10:33:08 -05003878 "%s: sd count %d where max sd is %d\n",
3879 __func__, hmc_info->sd_table.sd_cnt,
Faisal Latif86dbcd02016-01-20 13:40:10 -06003880 hmc_fpm_misc->max_sds);
3881
3882 qpwanted = min(qp_count, hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt);
3883 qpwantedoriginal = qpwanted;
3884 mrwanted = hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt;
3885 pblewanted = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt;
3886
3887 i40iw_debug(dev, I40IW_DEBUG_HMC,
3888 "req_qp=%d max_sd=%d, max_qp = %d, max_cq=%d, max_mr=%d, max_pble=%d\n",
3889 qp_count, hmc_fpm_misc->max_sds,
3890 hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt,
3891 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].max_cnt,
3892 hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt,
3893 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt);
3894
3895 do {
3896 ++loop_count;
3897 hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt = qpwanted;
3898 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt =
3899 min(2 * qpwanted, hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt);
3900 hmc_info->hmc_obj[I40IW_HMC_IW_SRQ].cnt = 0x00; /* Reserved */
3901 hmc_info->hmc_obj[I40IW_HMC_IW_HTE].cnt =
3902 qpwanted * hmc_fpm_misc->ht_multiplier;
3903 hmc_info->hmc_obj[I40IW_HMC_IW_ARP].cnt =
3904 hmc_info->hmc_obj[I40IW_HMC_IW_ARP].max_cnt;
3905 hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].cnt = 1;
3906 hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt = mrwanted;
3907
3908 hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt = I40IW_MAX_WQ_ENTRIES * qpwanted;
3909 hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt = 4 * I40IW_MAX_IRD_SIZE * qpwanted;
3910 hmc_info->hmc_obj[I40IW_HMC_IW_XFFL].cnt =
3911 hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt / hmc_fpm_misc->xf_block_size;
3912 hmc_info->hmc_obj[I40IW_HMC_IW_Q1FL].cnt =
3913 hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt / hmc_fpm_misc->q1_block_size;
3914 hmc_info->hmc_obj[I40IW_HMC_IW_TIMER].cnt =
3915 ((qpwanted) / 512 + 1) * hmc_fpm_misc->timer_bucket;
3916 hmc_info->hmc_obj[I40IW_HMC_IW_FSIMC].cnt = 0x00;
3917 hmc_info->hmc_obj[I40IW_HMC_IW_FSIAV].cnt = 0x00;
3918 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt = pblewanted;
3919
3920 /* How much memory is needed for all the objects. */
Ismail, Mustafafa415372016-04-18 10:33:08 -05003921 sd_needed = i40iw_est_sd(dev, hmc_info);
Faisal Latif86dbcd02016-01-20 13:40:10 -06003922 if ((loop_count > 1000) ||
3923 ((!(loop_count % 10)) &&
3924 (qpwanted > qpwantedoriginal * 2 / 3))) {
3925 if (qpwanted > FPM_MULTIPLIER) {
3926 qpwanted -= FPM_MULTIPLIER;
3927 powerof2 = 1;
3928 while (powerof2 < qpwanted)
3929 powerof2 *= 2;
3930 powerof2 /= 2;
3931 qpwanted = powerof2;
3932 } else {
3933 qpwanted /= 2;
3934 }
3935 }
3936 if (mrwanted > FPM_MULTIPLIER * 10)
3937 mrwanted -= FPM_MULTIPLIER * 10;
3938 if (pblewanted > FPM_MULTIPLIER * 1000)
3939 pblewanted -= FPM_MULTIPLIER * 1000;
3940 } while (sd_needed > hmc_fpm_misc->max_sds && loop_count < 2000);
3941
Ismail, Mustafafa415372016-04-18 10:33:08 -05003942 sd_needed = i40iw_est_sd(dev, hmc_info);
Faisal Latif86dbcd02016-01-20 13:40:10 -06003943
3944 i40iw_debug(dev, I40IW_DEBUG_HMC,
3945 "loop_cnt=%d, sd_needed=%lld, qpcnt = %d, cqcnt=%d, mrcnt=%d, pblecnt=%d\n",
3946 loop_count, sd_needed,
3947 hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt,
3948 hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt,
3949 hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt,
3950 hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt);
3951
3952 ret_code = i40iw_sc_configure_iw_fpm(dev, dev->hmc_fn_id);
3953 if (ret_code) {
3954 i40iw_debug(dev, I40IW_DEBUG_HMC,
3955 "configure_iw_fpm returned error_code[x%08X]\n",
3956 i40iw_rd32(dev->hw, dev->is_pf ? I40E_PFPE_CQPERRCODES : I40E_VFPE_CQPERRCODES1));
3957 return ret_code;
3958 }
3959
Faisal Latif86dbcd02016-01-20 13:40:10 -06003960 mem_size = sizeof(struct i40iw_hmc_sd_entry) *
3961 (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index + 1);
3962 ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
3963 if (ret_code) {
3964 i40iw_debug(dev, I40IW_DEBUG_HMC,
3965 "%s: failed to allocate memory for sd_entry buffer\n",
3966 __func__);
3967 return ret_code;
3968 }
3969 hmc_info->sd_table.sd_entry = virt_mem.va;
3970
3971 return ret_code;
3972}
3973
3974/**
3975 * i40iw_exec_cqp_cmd - execute cqp cmd when wqe are available
3976 * @dev: rdma device
3977 * @pcmdinfo: cqp command info
3978 */
3979static enum i40iw_status_code i40iw_exec_cqp_cmd(struct i40iw_sc_dev *dev,
3980 struct cqp_commands_info *pcmdinfo)
3981{
3982 enum i40iw_status_code status;
3983 struct i40iw_dma_mem values_mem;
3984
3985 dev->cqp_cmd_stats[pcmdinfo->cqp_cmd]++;
3986 switch (pcmdinfo->cqp_cmd) {
3987 case OP_DELETE_LOCAL_MAC_IPADDR_ENTRY:
3988 status = i40iw_sc_del_local_mac_ipaddr_entry(
3989 pcmdinfo->in.u.del_local_mac_ipaddr_entry.cqp,
3990 pcmdinfo->in.u.del_local_mac_ipaddr_entry.scratch,
3991 pcmdinfo->in.u.del_local_mac_ipaddr_entry.entry_idx,
3992 pcmdinfo->in.u.del_local_mac_ipaddr_entry.ignore_ref_count,
3993 pcmdinfo->post_sq);
3994 break;
3995 case OP_CEQ_DESTROY:
3996 status = i40iw_sc_ceq_destroy(pcmdinfo->in.u.ceq_destroy.ceq,
3997 pcmdinfo->in.u.ceq_destroy.scratch,
3998 pcmdinfo->post_sq);
3999 break;
4000 case OP_AEQ_DESTROY:
4001 status = i40iw_sc_aeq_destroy(pcmdinfo->in.u.aeq_destroy.aeq,
4002 pcmdinfo->in.u.aeq_destroy.scratch,
4003 pcmdinfo->post_sq);
4004
4005 break;
4006 case OP_DELETE_ARP_CACHE_ENTRY:
4007 status = i40iw_sc_del_arp_cache_entry(
4008 pcmdinfo->in.u.del_arp_cache_entry.cqp,
4009 pcmdinfo->in.u.del_arp_cache_entry.scratch,
4010 pcmdinfo->in.u.del_arp_cache_entry.arp_index,
4011 pcmdinfo->post_sq);
4012 break;
4013 case OP_MANAGE_APBVT_ENTRY:
4014 status = i40iw_sc_manage_apbvt_entry(
4015 pcmdinfo->in.u.manage_apbvt_entry.cqp,
4016 &pcmdinfo->in.u.manage_apbvt_entry.info,
4017 pcmdinfo->in.u.manage_apbvt_entry.scratch,
4018 pcmdinfo->post_sq);
4019 break;
4020 case OP_CEQ_CREATE:
4021 status = i40iw_sc_ceq_create(pcmdinfo->in.u.ceq_create.ceq,
4022 pcmdinfo->in.u.ceq_create.scratch,
4023 pcmdinfo->post_sq);
4024 break;
4025 case OP_AEQ_CREATE:
4026 status = i40iw_sc_aeq_create(pcmdinfo->in.u.aeq_create.aeq,
4027 pcmdinfo->in.u.aeq_create.scratch,
4028 pcmdinfo->post_sq);
4029 break;
4030 case OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY:
4031 status = i40iw_sc_alloc_local_mac_ipaddr_entry(
4032 pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.cqp,
4033 pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.scratch,
4034 pcmdinfo->post_sq);
4035 break;
4036 case OP_ADD_LOCAL_MAC_IPADDR_ENTRY:
4037 status = i40iw_sc_add_local_mac_ipaddr_entry(
4038 pcmdinfo->in.u.add_local_mac_ipaddr_entry.cqp,
4039 &pcmdinfo->in.u.add_local_mac_ipaddr_entry.info,
4040 pcmdinfo->in.u.add_local_mac_ipaddr_entry.scratch,
4041 pcmdinfo->post_sq);
4042 break;
4043 case OP_MANAGE_QHASH_TABLE_ENTRY:
4044 status = i40iw_sc_manage_qhash_table_entry(
4045 pcmdinfo->in.u.manage_qhash_table_entry.cqp,
4046 &pcmdinfo->in.u.manage_qhash_table_entry.info,
4047 pcmdinfo->in.u.manage_qhash_table_entry.scratch,
4048 pcmdinfo->post_sq);
4049
4050 break;
4051 case OP_QP_MODIFY:
4052 status = i40iw_sc_qp_modify(
4053 pcmdinfo->in.u.qp_modify.qp,
4054 &pcmdinfo->in.u.qp_modify.info,
4055 pcmdinfo->in.u.qp_modify.scratch,
4056 pcmdinfo->post_sq);
4057
4058 break;
4059 case OP_QP_UPLOAD_CONTEXT:
4060 status = i40iw_sc_qp_upload_context(
4061 pcmdinfo->in.u.qp_upload_context.dev,
4062 &pcmdinfo->in.u.qp_upload_context.info,
4063 pcmdinfo->in.u.qp_upload_context.scratch,
4064 pcmdinfo->post_sq);
4065
4066 break;
4067 case OP_CQ_CREATE:
4068 status = i40iw_sc_cq_create(
4069 pcmdinfo->in.u.cq_create.cq,
4070 pcmdinfo->in.u.cq_create.scratch,
4071 pcmdinfo->in.u.cq_create.check_overflow,
4072 pcmdinfo->post_sq);
4073 break;
4074 case OP_CQ_DESTROY:
4075 status = i40iw_sc_cq_destroy(
4076 pcmdinfo->in.u.cq_destroy.cq,
4077 pcmdinfo->in.u.cq_destroy.scratch,
4078 pcmdinfo->post_sq);
4079
4080 break;
4081 case OP_QP_CREATE:
4082 status = i40iw_sc_qp_create(
4083 pcmdinfo->in.u.qp_create.qp,
4084 &pcmdinfo->in.u.qp_create.info,
4085 pcmdinfo->in.u.qp_create.scratch,
4086 pcmdinfo->post_sq);
4087 break;
4088 case OP_QP_DESTROY:
4089 status = i40iw_sc_qp_destroy(
4090 pcmdinfo->in.u.qp_destroy.qp,
4091 pcmdinfo->in.u.qp_destroy.scratch,
4092 pcmdinfo->in.u.qp_destroy.remove_hash_idx,
4093 pcmdinfo->in.u.qp_destroy.
4094 ignore_mw_bnd,
4095 pcmdinfo->post_sq);
4096
4097 break;
4098 case OP_ALLOC_STAG:
4099 status = i40iw_sc_alloc_stag(
4100 pcmdinfo->in.u.alloc_stag.dev,
4101 &pcmdinfo->in.u.alloc_stag.info,
4102 pcmdinfo->in.u.alloc_stag.scratch,
4103 pcmdinfo->post_sq);
4104 break;
4105 case OP_MR_REG_NON_SHARED:
4106 status = i40iw_sc_mr_reg_non_shared(
4107 pcmdinfo->in.u.mr_reg_non_shared.dev,
4108 &pcmdinfo->in.u.mr_reg_non_shared.info,
4109 pcmdinfo->in.u.mr_reg_non_shared.scratch,
4110 pcmdinfo->post_sq);
4111
4112 break;
4113 case OP_DEALLOC_STAG:
4114 status = i40iw_sc_dealloc_stag(
4115 pcmdinfo->in.u.dealloc_stag.dev,
4116 &pcmdinfo->in.u.dealloc_stag.info,
4117 pcmdinfo->in.u.dealloc_stag.scratch,
4118 pcmdinfo->post_sq);
4119
4120 break;
4121 case OP_MW_ALLOC:
4122 status = i40iw_sc_mw_alloc(
4123 pcmdinfo->in.u.mw_alloc.dev,
4124 pcmdinfo->in.u.mw_alloc.scratch,
4125 pcmdinfo->in.u.mw_alloc.mw_stag_index,
4126 pcmdinfo->in.u.mw_alloc.pd_id,
4127 pcmdinfo->post_sq);
4128
4129 break;
4130 case OP_QP_FLUSH_WQES:
4131 status = i40iw_sc_qp_flush_wqes(
4132 pcmdinfo->in.u.qp_flush_wqes.qp,
4133 &pcmdinfo->in.u.qp_flush_wqes.info,
4134 pcmdinfo->in.u.qp_flush_wqes.
4135 scratch, pcmdinfo->post_sq);
4136 break;
4137 case OP_ADD_ARP_CACHE_ENTRY:
4138 status = i40iw_sc_add_arp_cache_entry(
4139 pcmdinfo->in.u.add_arp_cache_entry.cqp,
4140 &pcmdinfo->in.u.add_arp_cache_entry.info,
4141 pcmdinfo->in.u.add_arp_cache_entry.scratch,
4142 pcmdinfo->post_sq);
4143 break;
4144 case OP_MANAGE_PUSH_PAGE:
4145 status = i40iw_sc_manage_push_page(
4146 pcmdinfo->in.u.manage_push_page.cqp,
4147 &pcmdinfo->in.u.manage_push_page.info,
4148 pcmdinfo->in.u.manage_push_page.scratch,
4149 pcmdinfo->post_sq);
4150 break;
4151 case OP_UPDATE_PE_SDS:
4152 /* case I40IW_CQP_OP_UPDATE_PE_SDS */
4153 status = i40iw_update_pe_sds(
4154 pcmdinfo->in.u.update_pe_sds.dev,
4155 &pcmdinfo->in.u.update_pe_sds.info,
4156 pcmdinfo->in.u.update_pe_sds.
4157 scratch);
4158
4159 break;
4160 case OP_MANAGE_HMC_PM_FUNC_TABLE:
4161 status = i40iw_sc_manage_hmc_pm_func_table(
4162 pcmdinfo->in.u.manage_hmc_pm.dev->cqp,
4163 pcmdinfo->in.u.manage_hmc_pm.scratch,
4164 (u8)pcmdinfo->in.u.manage_hmc_pm.info.vf_id,
4165 pcmdinfo->in.u.manage_hmc_pm.info.free_fcn,
4166 true);
4167 break;
4168 case OP_SUSPEND:
4169 status = i40iw_sc_suspend_qp(
4170 pcmdinfo->in.u.suspend_resume.cqp,
4171 pcmdinfo->in.u.suspend_resume.qp,
4172 pcmdinfo->in.u.suspend_resume.scratch);
4173 break;
4174 case OP_RESUME:
4175 status = i40iw_sc_resume_qp(
4176 pcmdinfo->in.u.suspend_resume.cqp,
4177 pcmdinfo->in.u.suspend_resume.qp,
4178 pcmdinfo->in.u.suspend_resume.scratch);
4179 break;
4180 case OP_MANAGE_VF_PBLE_BP:
4181 status = i40iw_manage_vf_pble_bp(
4182 pcmdinfo->in.u.manage_vf_pble_bp.cqp,
4183 &pcmdinfo->in.u.manage_vf_pble_bp.info,
4184 pcmdinfo->in.u.manage_vf_pble_bp.scratch, true);
4185 break;
4186 case OP_QUERY_FPM_VALUES:
4187 values_mem.pa = pcmdinfo->in.u.query_fpm_values.fpm_values_pa;
4188 values_mem.va = pcmdinfo->in.u.query_fpm_values.fpm_values_va;
4189 status = i40iw_sc_query_fpm_values(
4190 pcmdinfo->in.u.query_fpm_values.cqp,
4191 pcmdinfo->in.u.query_fpm_values.scratch,
4192 pcmdinfo->in.u.query_fpm_values.hmc_fn_id,
4193 &values_mem, true, I40IW_CQP_WAIT_EVENT);
4194 break;
4195 case OP_COMMIT_FPM_VALUES:
4196 values_mem.pa = pcmdinfo->in.u.commit_fpm_values.fpm_values_pa;
4197 values_mem.va = pcmdinfo->in.u.commit_fpm_values.fpm_values_va;
4198 status = i40iw_sc_commit_fpm_values(
4199 pcmdinfo->in.u.commit_fpm_values.cqp,
4200 pcmdinfo->in.u.commit_fpm_values.scratch,
4201 pcmdinfo->in.u.commit_fpm_values.hmc_fn_id,
4202 &values_mem,
4203 true,
4204 I40IW_CQP_WAIT_EVENT);
4205 break;
4206 default:
4207 status = I40IW_NOT_SUPPORTED;
4208 break;
4209 }
4210
4211 return status;
4212}
4213
4214/**
4215 * i40iw_process_cqp_cmd - process all cqp commands
4216 * @dev: sc device struct
4217 * @pcmdinfo: cqp command info
4218 */
4219enum i40iw_status_code i40iw_process_cqp_cmd(struct i40iw_sc_dev *dev,
4220 struct cqp_commands_info *pcmdinfo)
4221{
4222 enum i40iw_status_code status = 0;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05004223 unsigned long flags;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004224
4225 spin_lock_irqsave(&dev->cqp_lock, flags);
4226 if (list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp))
4227 status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
4228 else
4229 list_add_tail(&pcmdinfo->cqp_cmd_entry, &dev->cqp_cmd_head);
4230 spin_unlock_irqrestore(&dev->cqp_lock, flags);
4231 return status;
4232}
4233
4234/**
4235 * i40iw_process_bh - called from tasklet for cqp list
4236 * @dev: sc device struct
4237 */
4238enum i40iw_status_code i40iw_process_bh(struct i40iw_sc_dev *dev)
4239{
4240 enum i40iw_status_code status = 0;
4241 struct cqp_commands_info *pcmdinfo;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05004242 unsigned long flags;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004243
4244 spin_lock_irqsave(&dev->cqp_lock, flags);
4245 while (!list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp)) {
4246 pcmdinfo = (struct cqp_commands_info *)i40iw_remove_head(&dev->cqp_cmd_head);
4247
4248 status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
4249 if (status)
4250 break;
4251 }
4252 spin_unlock_irqrestore(&dev->cqp_lock, flags);
4253 return status;
4254}
4255
4256/**
4257 * i40iw_iwarp_opcode - determine if incoming is rdma layer
4258 * @info: aeq info for the packet
4259 * @pkt: packet for error
4260 */
4261static u32 i40iw_iwarp_opcode(struct i40iw_aeqe_info *info, u8 *pkt)
4262{
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05004263 __be16 *mpa;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004264 u32 opcode = 0xffffffff;
4265
4266 if (info->q2_data_written) {
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05004267 mpa = (__be16 *)pkt;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004268 opcode = ntohs(mpa[1]) & 0xf;
4269 }
4270 return opcode;
4271}
4272
4273/**
4274 * i40iw_locate_mpa - return pointer to mpa in the pkt
4275 * @pkt: packet with data
4276 */
4277static u8 *i40iw_locate_mpa(u8 *pkt)
4278{
4279 /* skip over ethernet header */
4280 pkt += I40IW_MAC_HLEN;
4281
4282 /* Skip over IP and TCP headers */
4283 pkt += 4 * (pkt[0] & 0x0f);
4284 pkt += 4 * ((pkt[12] >> 4) & 0x0f);
4285 return pkt;
4286}
4287
4288/**
4289 * i40iw_setup_termhdr - termhdr for terminate pkt
4290 * @qp: sc qp ptr for pkt
4291 * @hdr: term hdr
4292 * @opcode: flush opcode for termhdr
4293 * @layer_etype: error layer + error type
4294 * @err: error cod ein the header
4295 */
4296static void i40iw_setup_termhdr(struct i40iw_sc_qp *qp,
4297 struct i40iw_terminate_hdr *hdr,
4298 enum i40iw_flush_opcode opcode,
4299 u8 layer_etype,
4300 u8 err)
4301{
4302 qp->flush_code = opcode;
4303 hdr->layer_etype = layer_etype;
4304 hdr->error_code = err;
4305}
4306
4307/**
4308 * i40iw_bld_terminate_hdr - build terminate message header
4309 * @qp: qp associated with received terminate AE
4310 * @info: the struct contiaing AE information
4311 */
4312static int i40iw_bld_terminate_hdr(struct i40iw_sc_qp *qp,
4313 struct i40iw_aeqe_info *info)
4314{
4315 u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
4316 u16 ddp_seg_len;
4317 int copy_len = 0;
4318 u8 is_tagged = 0;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004319 u32 opcode;
4320 struct i40iw_terminate_hdr *termhdr;
4321
4322 termhdr = (struct i40iw_terminate_hdr *)qp->q2_buf;
4323 memset(termhdr, 0, Q2_BAD_FRAME_OFFSET);
4324
4325 if (info->q2_data_written) {
4326 /* Use data from offending packet to fill in ddp & rdma hdrs */
4327 pkt = i40iw_locate_mpa(pkt);
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05004328 ddp_seg_len = ntohs(*(__be16 *)pkt);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004329 if (ddp_seg_len) {
4330 copy_len = 2;
4331 termhdr->hdrct = DDP_LEN_FLAG;
4332 if (pkt[2] & 0x80) {
4333 is_tagged = 1;
4334 if (ddp_seg_len >= TERM_DDP_LEN_TAGGED) {
4335 copy_len += TERM_DDP_LEN_TAGGED;
4336 termhdr->hdrct |= DDP_HDR_FLAG;
4337 }
4338 } else {
4339 if (ddp_seg_len >= TERM_DDP_LEN_UNTAGGED) {
4340 copy_len += TERM_DDP_LEN_UNTAGGED;
4341 termhdr->hdrct |= DDP_HDR_FLAG;
4342 }
4343
4344 if (ddp_seg_len >= (TERM_DDP_LEN_UNTAGGED + TERM_RDMA_LEN)) {
4345 if ((pkt[3] & RDMA_OPCODE_MASK) == RDMA_READ_REQ_OPCODE) {
4346 copy_len += TERM_RDMA_LEN;
4347 termhdr->hdrct |= RDMA_HDR_FLAG;
4348 }
4349 }
4350 }
4351 }
4352 }
4353
4354 opcode = i40iw_iwarp_opcode(info, pkt);
4355
4356 switch (info->ae_id) {
4357 case I40IW_AE_AMP_UNALLOCATED_STAG:
4358 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4359 if (opcode == I40IW_OP_TYPE_RDMA_WRITE)
4360 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4361 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_STAG);
4362 else
4363 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4364 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
4365 break;
4366 case I40IW_AE_AMP_BOUNDS_VIOLATION:
4367 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4368 if (info->q2_data_written)
4369 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4370 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_BOUNDS);
4371 else
4372 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4373 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_BOUNDS);
4374 break;
4375 case I40IW_AE_AMP_BAD_PD:
4376 switch (opcode) {
4377 case I40IW_OP_TYPE_RDMA_WRITE:
4378 i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
4379 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_UNASSOC_STAG);
4380 break;
4381 case I40IW_OP_TYPE_SEND_INV:
4382 case I40IW_OP_TYPE_SEND_SOL_INV:
4383 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4384 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_CANT_INV_STAG);
4385 break;
4386 default:
4387 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4388 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_UNASSOC_STAG);
4389 }
4390 break;
4391 case I40IW_AE_AMP_INVALID_STAG:
4392 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4393 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4394 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
4395 break;
4396 case I40IW_AE_AMP_BAD_QP:
4397 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
4398 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
4399 break;
4400 case I40IW_AE_AMP_BAD_STAG_KEY:
4401 case I40IW_AE_AMP_BAD_STAG_INDEX:
4402 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4403 switch (opcode) {
4404 case I40IW_OP_TYPE_SEND_INV:
4405 case I40IW_OP_TYPE_SEND_SOL_INV:
4406 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
4407 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_CANT_INV_STAG);
4408 break;
4409 default:
4410 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4411 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_STAG);
4412 }
4413 break;
4414 case I40IW_AE_AMP_RIGHTS_VIOLATION:
4415 case I40IW_AE_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS:
4416 case I40IW_AE_PRIV_OPERATION_DENIED:
4417 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4418 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4419 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_ACCESS);
4420 break;
4421 case I40IW_AE_AMP_TO_WRAP:
4422 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4423 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
4424 (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_TO_WRAP);
4425 break;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004426 case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
4427 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4428 (LAYER_MPA << 4) | DDP_LLP, MPA_CRC);
4429 break;
4430 case I40IW_AE_LLP_SEGMENT_TOO_LARGE:
4431 case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
4432 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
4433 (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
4434 break;
4435 case I40IW_AE_LCE_QP_CATASTROPHIC:
4436 case I40IW_AE_DDP_NO_L_BIT:
4437 i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
4438 (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
4439 break;
4440 case I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN:
Faisal Latif86dbcd02016-01-20 13:40:10 -06004441 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4442 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_RANGE);
4443 break;
4444 case I40IW_AE_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
4445 qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
4446 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
4447 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_TOO_LONG);
4448 break;
4449 case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
4450 if (is_tagged)
4451 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4452 (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_DDP_VER);
4453 else
4454 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4455 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_DDP_VER);
4456 break;
4457 case I40IW_AE_DDP_UBE_INVALID_MO:
4458 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4459 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MO);
4460 break;
4461 case I40IW_AE_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
4462 i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
4463 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_NO_BUF);
4464 break;
4465 case I40IW_AE_DDP_UBE_INVALID_QN:
4466 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4467 (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
4468 break;
4469 case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
4470 i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
4471 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_RDMAP_VER);
4472 break;
4473 case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
4474 i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
4475 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNEXPECTED_OP);
4476 break;
4477 default:
4478 i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
4479 (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNSPECIFIED);
4480 break;
4481 }
4482
4483 if (copy_len)
4484 memcpy(termhdr + 1, pkt, copy_len);
4485
Faisal Latif86dbcd02016-01-20 13:40:10 -06004486 return sizeof(struct i40iw_terminate_hdr) + copy_len;
4487}
4488
4489/**
4490 * i40iw_terminate_send_fin() - Send fin for terminate message
4491 * @qp: qp associated with received terminate AE
4492 */
4493void i40iw_terminate_send_fin(struct i40iw_sc_qp *qp)
4494{
4495 /* Send the fin only */
4496 i40iw_term_modify_qp(qp,
4497 I40IW_QP_STATE_TERMINATE,
4498 I40IWQP_TERM_SEND_FIN_ONLY,
4499 0);
4500}
4501
4502/**
4503 * i40iw_terminate_connection() - Bad AE and send terminate to remote QP
4504 * @qp: qp associated with received terminate AE
4505 * @info: the struct contiaing AE information
4506 */
4507void i40iw_terminate_connection(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
4508{
4509 u8 termlen = 0;
4510
4511 if (qp->term_flags & I40IW_TERM_SENT)
4512 return; /* Sanity check */
4513
4514 /* Eventtype can change from bld_terminate_hdr */
4515 qp->eventtype = TERM_EVENT_QP_FATAL;
4516 termlen = i40iw_bld_terminate_hdr(qp, info);
4517 i40iw_terminate_start_timer(qp);
4518 qp->term_flags |= I40IW_TERM_SENT;
4519 i40iw_term_modify_qp(qp, I40IW_QP_STATE_TERMINATE,
4520 I40IWQP_TERM_SEND_TERM_ONLY, termlen);
4521}
4522
4523/**
4524 * i40iw_terminate_received - handle terminate received AE
4525 * @qp: qp associated with received terminate AE
4526 * @info: the struct contiaing AE information
4527 */
4528void i40iw_terminate_received(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
4529{
4530 u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05004531 __be32 *mpa;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004532 u8 ddp_ctl;
4533 u8 rdma_ctl;
4534 u16 aeq_id = 0;
4535 struct i40iw_terminate_hdr *termhdr;
4536
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05004537 mpa = (__be32 *)i40iw_locate_mpa(pkt);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004538 if (info->q2_data_written) {
4539 /* did not validate the frame - do it now */
4540 ddp_ctl = (ntohl(mpa[0]) >> 8) & 0xff;
4541 rdma_ctl = ntohl(mpa[0]) & 0xff;
4542 if ((ddp_ctl & 0xc0) != 0x40)
4543 aeq_id = I40IW_AE_LCE_QP_CATASTROPHIC;
4544 else if ((ddp_ctl & 0x03) != 1)
4545 aeq_id = I40IW_AE_DDP_UBE_INVALID_DDP_VERSION;
4546 else if (ntohl(mpa[2]) != 2)
4547 aeq_id = I40IW_AE_DDP_UBE_INVALID_QN;
4548 else if (ntohl(mpa[3]) != 1)
4549 aeq_id = I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN;
4550 else if (ntohl(mpa[4]) != 0)
4551 aeq_id = I40IW_AE_DDP_UBE_INVALID_MO;
4552 else if ((rdma_ctl & 0xc0) != 0x40)
4553 aeq_id = I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION;
4554
4555 info->ae_id = aeq_id;
4556 if (info->ae_id) {
4557 /* Bad terminate recvd - send back a terminate */
4558 i40iw_terminate_connection(qp, info);
4559 return;
4560 }
4561 }
4562
4563 qp->term_flags |= I40IW_TERM_RCVD;
4564 qp->eventtype = TERM_EVENT_QP_FATAL;
4565 termhdr = (struct i40iw_terminate_hdr *)&mpa[5];
4566 if (termhdr->layer_etype == RDMAP_REMOTE_PROT ||
4567 termhdr->layer_etype == RDMAP_REMOTE_OP) {
4568 i40iw_terminate_done(qp, 0);
4569 } else {
4570 i40iw_terminate_start_timer(qp);
4571 i40iw_terminate_send_fin(qp);
4572 }
4573}
4574
4575/**
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004576 * i40iw_sc_vsi_init - Initialize virtual device
4577 * @vsi: pointer to the vsi structure
4578 * @info: parameters to initialize vsi
4579 **/
4580void i40iw_sc_vsi_init(struct i40iw_sc_vsi *vsi, struct i40iw_vsi_init_info *info)
4581{
4582 int i;
4583
4584 vsi->dev = info->dev;
4585 vsi->back_vsi = info->back_vsi;
4586 vsi->mss = info->params->mss;
4587 i40iw_fill_qos_list(info->params->qs_handle_list);
4588
4589 for (i = 0; i < I40IW_MAX_USER_PRIORITY; i++) {
Dan Carpenter820cd302017-01-09 23:12:16 +03004590 vsi->qos[i].qs_handle = info->params->qs_handle_list[i];
4591 i40iw_debug(vsi->dev, I40IW_DEBUG_DCB, "qset[%d]: %d\n", i,
4592 vsi->qos[i].qs_handle);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004593 spin_lock_init(&vsi->qos[i].lock);
4594 INIT_LIST_HEAD(&vsi->qos[i].qplist);
4595 }
4596}
4597
4598/**
4599 * i40iw_hw_stats_init - Initiliaze HW stats table
4600 * @stats: pestat struct
Faisal Latif86dbcd02016-01-20 13:40:10 -06004601 * @fcn_idx: PCI fn id
Faisal Latif86dbcd02016-01-20 13:40:10 -06004602 * @is_pf: Is it a PF?
4603 *
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004604 * Populate the HW stats table with register offset addr for each
4605 * stats. And start the perioidic stats timer.
Faisal Latif86dbcd02016-01-20 13:40:10 -06004606 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004607void i40iw_hw_stats_init(struct i40iw_vsi_pestat *stats, u8 fcn_idx, bool is_pf)
Faisal Latif86dbcd02016-01-20 13:40:10 -06004608{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004609 u32 stats_reg_offset;
4610 u32 stats_index;
4611 struct i40iw_dev_hw_stats_offsets *stats_table =
4612 &stats->hw_stats_offsets;
4613 struct i40iw_dev_hw_stats *last_rd_stats = &stats->last_read_hw_stats;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004614
4615 if (is_pf) {
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004616 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004617 I40E_GLPES_PFIP4RXDISCARD(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004618 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004619 I40E_GLPES_PFIP4RXTRUNC(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004620 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004621 I40E_GLPES_PFIP4TXNOROUTE(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004622 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004623 I40E_GLPES_PFIP6RXDISCARD(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004624 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004625 I40E_GLPES_PFIP6RXTRUNC(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004626 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004627 I40E_GLPES_PFIP6TXNOROUTE(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004628 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004629 I40E_GLPES_PFTCPRTXSEG(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004630 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004631 I40E_GLPES_PFTCPRXOPTERR(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004632 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004633 I40E_GLPES_PFTCPRXPROTOERR(fcn_idx);
4634
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004635 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004636 I40E_GLPES_PFIP4RXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004637 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004638 I40E_GLPES_PFIP4RXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004639 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004640 I40E_GLPES_PFIP4RXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004641 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004642 I40E_GLPES_PFIP4RXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004643 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004644 I40E_GLPES_PFIP4TXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004645 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004646 I40E_GLPES_PFIP4TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004647 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004648 I40E_GLPES_PFIP4TXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004649 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004650 I40E_GLPES_PFIP4TXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004651 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004652 I40E_GLPES_PFIP6RXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004653 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004654 I40E_GLPES_PFIP6RXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004655 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004656 I40E_GLPES_PFIP6RXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004657 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004658 I40E_GLPES_PFIP6RXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004659 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004660 I40E_GLPES_PFIP6TXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004661 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004662 I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004663 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004664 I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004665 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004666 I40E_GLPES_PFIP6TXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004667 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004668 I40E_GLPES_PFTCPRXSEGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004669 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004670 I40E_GLPES_PFTCPTXSEGLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004671 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004672 I40E_GLPES_PFRDMARXRDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004673 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004674 I40E_GLPES_PFRDMARXSNDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004675 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004676 I40E_GLPES_PFRDMARXWRSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004677 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004678 I40E_GLPES_PFRDMATXRDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004679 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004680 I40E_GLPES_PFRDMATXSNDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004681 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004682 I40E_GLPES_PFRDMATXWRSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004683 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004684 I40E_GLPES_PFRDMAVBNDLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004685 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004686 I40E_GLPES_PFRDMAVINVLO(fcn_idx);
4687 } else {
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004688 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004689 I40E_GLPES_VFIP4RXDISCARD(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004690 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004691 I40E_GLPES_VFIP4RXTRUNC(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004692 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004693 I40E_GLPES_VFIP4TXNOROUTE(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004694 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004695 I40E_GLPES_VFIP6RXDISCARD(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004696 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004697 I40E_GLPES_VFIP6RXTRUNC(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004698 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004699 I40E_GLPES_VFIP6TXNOROUTE(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004700 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004701 I40E_GLPES_VFTCPRTXSEG(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004702 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004703 I40E_GLPES_VFTCPRXOPTERR(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004704 stats_table->stats_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004705 I40E_GLPES_VFTCPRXPROTOERR(fcn_idx);
4706
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004707 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004708 I40E_GLPES_VFIP4RXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004709 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004710 I40E_GLPES_VFIP4RXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004711 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004712 I40E_GLPES_VFIP4RXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004713 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004714 I40E_GLPES_VFIP4RXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004715 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004716 I40E_GLPES_VFIP4TXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004717 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004718 I40E_GLPES_VFIP4TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004719 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004720 I40E_GLPES_VFIP4TXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004721 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004722 I40E_GLPES_VFIP4TXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004723 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004724 I40E_GLPES_VFIP6RXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004725 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004726 I40E_GLPES_VFIP6RXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004727 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004728 I40E_GLPES_VFIP6RXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004729 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004730 I40E_GLPES_VFIP6RXMCPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004731 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004732 I40E_GLPES_VFIP6TXOCTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004733 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004734 I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004735 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004736 I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004737 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004738 I40E_GLPES_VFIP6TXFRAGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004739 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004740 I40E_GLPES_VFTCPRXSEGSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004741 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004742 I40E_GLPES_VFTCPTXSEGLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004743 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004744 I40E_GLPES_VFRDMARXRDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004745 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004746 I40E_GLPES_VFRDMARXSNDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004747 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004748 I40E_GLPES_VFRDMARXWRSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004749 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004750 I40E_GLPES_VFRDMATXRDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004751 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004752 I40E_GLPES_VFRDMATXSNDSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004753 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004754 I40E_GLPES_VFRDMATXWRSLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004755 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004756 I40E_GLPES_VFRDMAVBNDLO(fcn_idx);
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004757 stats_table->stats_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
Faisal Latif86dbcd02016-01-20 13:40:10 -06004758 I40E_GLPES_VFRDMAVINVLO(fcn_idx);
4759 }
4760
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004761 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_64;
4762 stats_index++) {
4763 stats_reg_offset = stats_table->stats_offset_64[stats_index];
4764 last_rd_stats->stats_value_64[stats_index] =
4765 readq(stats->hw->hw_addr + stats_reg_offset);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004766 }
4767
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004768 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_32;
4769 stats_index++) {
4770 stats_reg_offset = stats_table->stats_offset_32[stats_index];
4771 last_rd_stats->stats_value_32[stats_index] =
4772 i40iw_rd32(stats->hw, stats_reg_offset);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004773 }
4774}
4775
4776/**
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004777 * i40iw_hw_stats_read_32 - Read 32-bit HW stats counters and accommodates for roll-overs.
4778 * @stat: pestat struct
4779 * @index: index in HW stats table which contains offset reg-addr
4780 * @value: hw stats value
Faisal Latif86dbcd02016-01-20 13:40:10 -06004781 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004782void i40iw_hw_stats_read_32(struct i40iw_vsi_pestat *stats,
4783 enum i40iw_hw_stats_index_32b index,
4784 u64 *value)
Faisal Latif86dbcd02016-01-20 13:40:10 -06004785{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004786 struct i40iw_dev_hw_stats_offsets *stats_table =
4787 &stats->hw_stats_offsets;
4788 struct i40iw_dev_hw_stats *last_rd_stats = &stats->last_read_hw_stats;
4789 struct i40iw_dev_hw_stats *hw_stats = &stats->hw_stats;
4790 u64 new_stats_value = 0;
4791 u32 stats_reg_offset = stats_table->stats_offset_32[index];
Faisal Latif86dbcd02016-01-20 13:40:10 -06004792
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004793 new_stats_value = i40iw_rd32(stats->hw, stats_reg_offset);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004794 /*roll-over case */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004795 if (new_stats_value < last_rd_stats->stats_value_32[index])
4796 hw_stats->stats_value_32[index] += new_stats_value;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004797 else
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004798 hw_stats->stats_value_32[index] +=
4799 new_stats_value - last_rd_stats->stats_value_32[index];
4800 last_rd_stats->stats_value_32[index] = new_stats_value;
4801 *value = hw_stats->stats_value_32[index];
Faisal Latif86dbcd02016-01-20 13:40:10 -06004802}
4803
4804/**
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004805 * i40iw_hw_stats_read_64 - Read HW stats counters (greater than 32-bit) and accommodates for roll-overs.
4806 * @stats: pestat struct
4807 * @index: index in HW stats table which contains offset reg-addr
4808 * @value: hw stats value
Faisal Latif86dbcd02016-01-20 13:40:10 -06004809 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004810void i40iw_hw_stats_read_64(struct i40iw_vsi_pestat *stats,
4811 enum i40iw_hw_stats_index_64b index,
4812 u64 *value)
Faisal Latif86dbcd02016-01-20 13:40:10 -06004813{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004814 struct i40iw_dev_hw_stats_offsets *stats_table =
4815 &stats->hw_stats_offsets;
4816 struct i40iw_dev_hw_stats *last_rd_stats = &stats->last_read_hw_stats;
4817 struct i40iw_dev_hw_stats *hw_stats = &stats->hw_stats;
4818 u64 new_stats_value = 0;
4819 u32 stats_reg_offset = stats_table->stats_offset_64[index];
Faisal Latif86dbcd02016-01-20 13:40:10 -06004820
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004821 new_stats_value = readq(stats->hw->hw_addr + stats_reg_offset);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004822 /*roll-over case */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004823 if (new_stats_value < last_rd_stats->stats_value_64[index])
4824 hw_stats->stats_value_64[index] += new_stats_value;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004825 else
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004826 hw_stats->stats_value_64[index] +=
4827 new_stats_value - last_rd_stats->stats_value_64[index];
4828 last_rd_stats->stats_value_64[index] = new_stats_value;
4829 *value = hw_stats->stats_value_64[index];
Faisal Latif86dbcd02016-01-20 13:40:10 -06004830}
4831
4832/**
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004833 * i40iw_hw_stats_read_all - read all HW stat counters
4834 * @stats: pestat struct
4835 * @stats_values: hw stats structure
Faisal Latif86dbcd02016-01-20 13:40:10 -06004836 *
4837 * Read all the HW stat counters and populates hw_stats structure
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004838 * of passed-in vsi's pestat as well as copy created in stat_values.
Faisal Latif86dbcd02016-01-20 13:40:10 -06004839 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004840void i40iw_hw_stats_read_all(struct i40iw_vsi_pestat *stats,
4841 struct i40iw_dev_hw_stats *stats_values)
Faisal Latif86dbcd02016-01-20 13:40:10 -06004842{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004843 u32 stats_index;
4844 unsigned long flags;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004845
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004846 spin_lock_irqsave(&stats->lock, flags);
4847
4848 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_32;
4849 stats_index++)
4850 i40iw_hw_stats_read_32(stats, stats_index,
4851 &stats_values->stats_value_32[stats_index]);
4852 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_64;
4853 stats_index++)
4854 i40iw_hw_stats_read_64(stats, stats_index,
4855 &stats_values->stats_value_64[stats_index]);
4856 spin_unlock_irqrestore(&stats->lock, flags);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004857}
4858
4859/**
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004860 * i40iw_hw_stats_refresh_all - Update all HW stats structs
4861 * @stats: pestat struct
Faisal Latif86dbcd02016-01-20 13:40:10 -06004862 *
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004863 * Read all the HW stats counters to refresh values in hw_stats structure
Faisal Latif86dbcd02016-01-20 13:40:10 -06004864 * of passed-in dev's pestat
4865 */
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004866void i40iw_hw_stats_refresh_all(struct i40iw_vsi_pestat *stats)
Faisal Latif86dbcd02016-01-20 13:40:10 -06004867{
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004868 u64 stats_value;
4869 u32 stats_index;
4870 unsigned long flags;
Faisal Latif86dbcd02016-01-20 13:40:10 -06004871
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004872 spin_lock_irqsave(&stats->lock, flags);
4873
4874 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_32;
4875 stats_index++)
4876 i40iw_hw_stats_read_32(stats, stats_index, &stats_value);
4877 for (stats_index = 0; stats_index < I40IW_HW_STAT_INDEX_MAX_64;
4878 stats_index++)
4879 i40iw_hw_stats_read_64(stats, stats_index, &stats_value);
4880 spin_unlock_irqrestore(&stats->lock, flags);
4881}
4882
4883/**
4884 * i40iw_get_fcn_id - Return the function id
4885 * @dev: pointer to the device
4886 */
4887static u8 i40iw_get_fcn_id(struct i40iw_sc_dev *dev)
4888{
4889 u8 fcn_id = I40IW_INVALID_FCN_ID;
4890 u8 i;
4891
4892 for (i = I40IW_FIRST_NON_PF_STAT; i < I40IW_MAX_STATS_COUNT; i++)
4893 if (!dev->fcn_id_array[i]) {
4894 fcn_id = i;
4895 dev->fcn_id_array[i] = true;
4896 break;
4897 }
4898 return fcn_id;
4899}
4900
4901/**
4902 * i40iw_vsi_stats_init - Initialize the vsi statistics
4903 * @vsi: pointer to the vsi structure
4904 * @info: The info structure used for initialization
4905 */
4906enum i40iw_status_code i40iw_vsi_stats_init(struct i40iw_sc_vsi *vsi, struct i40iw_vsi_stats_info *info)
4907{
4908 u8 fcn_id = info->fcn_id;
4909
4910 if (info->alloc_fcn_id)
4911 fcn_id = i40iw_get_fcn_id(vsi->dev);
4912
4913 if (fcn_id == I40IW_INVALID_FCN_ID)
4914 return I40IW_ERR_NOT_READY;
4915
4916 vsi->pestat = info->pestat;
4917 vsi->pestat->hw = vsi->dev->hw;
Kees Cook605cbb22017-10-04 17:45:41 -07004918 vsi->pestat->vsi = vsi;
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004919
4920 if (info->stats_initialize) {
4921 i40iw_hw_stats_init(vsi->pestat, fcn_id, true);
4922 spin_lock_init(&vsi->pestat->lock);
4923 i40iw_hw_stats_start_timer(vsi);
4924 }
4925 vsi->stats_fcn_id_alloc = info->alloc_fcn_id;
4926 vsi->fcn_id = fcn_id;
4927 return I40IW_SUCCESS;
4928}
4929
4930/**
4931 * i40iw_vsi_stats_free - Free the vsi stats
4932 * @vsi: pointer to the vsi structure
4933 */
4934void i40iw_vsi_stats_free(struct i40iw_sc_vsi *vsi)
4935{
4936 u8 fcn_id = vsi->fcn_id;
4937
Christopher N Bednarzaa939c12017-08-08 20:38:48 -05004938 if (vsi->stats_fcn_id_alloc && fcn_id < I40IW_MAX_STATS_COUNT)
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06004939 vsi->dev->fcn_id_array[fcn_id] = false;
4940 i40iw_hw_stats_stop_timer(vsi);
Faisal Latif86dbcd02016-01-20 13:40:10 -06004941}
4942
4943static struct i40iw_cqp_ops iw_cqp_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08004944 .cqp_init = i40iw_sc_cqp_init,
4945 .cqp_create = i40iw_sc_cqp_create,
4946 .cqp_post_sq = i40iw_sc_cqp_post_sq,
4947 .cqp_get_next_send_wqe = i40iw_sc_cqp_get_next_send_wqe,
4948 .cqp_destroy = i40iw_sc_cqp_destroy,
4949 .poll_for_cqp_op_done = i40iw_sc_poll_for_cqp_op_done
Faisal Latif86dbcd02016-01-20 13:40:10 -06004950};
4951
4952static struct i40iw_ccq_ops iw_ccq_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08004953 .ccq_init = i40iw_sc_ccq_init,
4954 .ccq_create = i40iw_sc_ccq_create,
4955 .ccq_destroy = i40iw_sc_ccq_destroy,
4956 .ccq_create_done = i40iw_sc_ccq_create_done,
4957 .ccq_get_cqe_info = i40iw_sc_ccq_get_cqe_info,
4958 .ccq_arm = i40iw_sc_ccq_arm
Faisal Latif86dbcd02016-01-20 13:40:10 -06004959};
4960
4961static struct i40iw_ceq_ops iw_ceq_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08004962 .ceq_init = i40iw_sc_ceq_init,
4963 .ceq_create = i40iw_sc_ceq_create,
4964 .cceq_create_done = i40iw_sc_cceq_create_done,
4965 .cceq_destroy_done = i40iw_sc_cceq_destroy_done,
4966 .cceq_create = i40iw_sc_cceq_create,
4967 .ceq_destroy = i40iw_sc_ceq_destroy,
4968 .process_ceq = i40iw_sc_process_ceq
Faisal Latif86dbcd02016-01-20 13:40:10 -06004969};
4970
4971static struct i40iw_aeq_ops iw_aeq_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08004972 .aeq_init = i40iw_sc_aeq_init,
4973 .aeq_create = i40iw_sc_aeq_create,
4974 .aeq_destroy = i40iw_sc_aeq_destroy,
4975 .get_next_aeqe = i40iw_sc_get_next_aeqe,
4976 .repost_aeq_entries = i40iw_sc_repost_aeq_entries,
4977 .aeq_create_done = i40iw_sc_aeq_create_done,
4978 .aeq_destroy_done = i40iw_sc_aeq_destroy_done
Faisal Latif86dbcd02016-01-20 13:40:10 -06004979};
4980
4981/* iwarp pd ops */
4982static struct i40iw_pd_ops iw_pd_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08004983 .pd_init = i40iw_sc_pd_init,
Faisal Latif86dbcd02016-01-20 13:40:10 -06004984};
4985
4986static struct i40iw_priv_qp_ops iw_priv_qp_ops = {
Ismail, Mustafab7aee852016-04-18 10:33:06 -05004987 .qp_init = i40iw_sc_qp_init,
4988 .qp_create = i40iw_sc_qp_create,
4989 .qp_modify = i40iw_sc_qp_modify,
4990 .qp_destroy = i40iw_sc_qp_destroy,
4991 .qp_flush_wqes = i40iw_sc_qp_flush_wqes,
4992 .qp_upload_context = i40iw_sc_qp_upload_context,
4993 .qp_setctx = i40iw_sc_qp_setctx,
4994 .qp_send_lsmm = i40iw_sc_send_lsmm,
4995 .qp_send_lsmm_nostag = i40iw_sc_send_lsmm_nostag,
4996 .qp_send_rtt = i40iw_sc_send_rtt,
4997 .qp_post_wqe0 = i40iw_sc_post_wqe0,
4998 .iw_mr_fast_register = i40iw_sc_mr_fast_register
Faisal Latif86dbcd02016-01-20 13:40:10 -06004999};
5000
5001static struct i40iw_priv_cq_ops iw_priv_cq_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08005002 .cq_init = i40iw_sc_cq_init,
5003 .cq_create = i40iw_sc_cq_create,
5004 .cq_destroy = i40iw_sc_cq_destroy,
5005 .cq_modify = i40iw_sc_cq_modify,
Faisal Latif86dbcd02016-01-20 13:40:10 -06005006};
5007
5008static struct i40iw_mr_ops iw_mr_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08005009 .alloc_stag = i40iw_sc_alloc_stag,
5010 .mr_reg_non_shared = i40iw_sc_mr_reg_non_shared,
5011 .mr_reg_shared = i40iw_sc_mr_reg_shared,
5012 .dealloc_stag = i40iw_sc_dealloc_stag,
5013 .query_stag = i40iw_sc_query_stag,
5014 .mw_alloc = i40iw_sc_mw_alloc
Faisal Latif86dbcd02016-01-20 13:40:10 -06005015};
5016
5017static struct i40iw_cqp_misc_ops iw_cqp_misc_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08005018 .manage_push_page = i40iw_sc_manage_push_page,
5019 .manage_hmc_pm_func_table = i40iw_sc_manage_hmc_pm_func_table,
5020 .set_hmc_resource_profile = i40iw_sc_set_hmc_resource_profile,
5021 .commit_fpm_values = i40iw_sc_commit_fpm_values,
5022 .query_fpm_values = i40iw_sc_query_fpm_values,
5023 .static_hmc_pages_allocated = i40iw_sc_static_hmc_pages_allocated,
5024 .add_arp_cache_entry = i40iw_sc_add_arp_cache_entry,
5025 .del_arp_cache_entry = i40iw_sc_del_arp_cache_entry,
5026 .query_arp_cache_entry = i40iw_sc_query_arp_cache_entry,
5027 .manage_apbvt_entry = i40iw_sc_manage_apbvt_entry,
5028 .manage_qhash_table_entry = i40iw_sc_manage_qhash_table_entry,
5029 .alloc_local_mac_ipaddr_table_entry = i40iw_sc_alloc_local_mac_ipaddr_entry,
5030 .add_local_mac_ipaddr_entry = i40iw_sc_add_local_mac_ipaddr_entry,
5031 .del_local_mac_ipaddr_entry = i40iw_sc_del_local_mac_ipaddr_entry,
5032 .cqp_nop = i40iw_sc_cqp_nop,
5033 .commit_fpm_values_done = i40iw_sc_commit_fpm_values_done,
5034 .query_fpm_values_done = i40iw_sc_query_fpm_values_done,
5035 .manage_hmc_pm_func_table_done = i40iw_sc_manage_hmc_pm_func_table_done,
5036 .update_suspend_qp = i40iw_sc_suspend_qp,
5037 .update_resume_qp = i40iw_sc_resume_qp
Faisal Latif86dbcd02016-01-20 13:40:10 -06005038};
5039
5040static struct i40iw_hmc_ops iw_hmc_ops = {
Kees Cook7f6856b2016-12-16 17:05:42 -08005041 .init_iw_hmc = i40iw_sc_init_iw_hmc,
5042 .parse_fpm_query_buf = i40iw_sc_parse_fpm_query_buf,
5043 .configure_iw_fpm = i40iw_sc_configure_iw_fpm,
5044 .parse_fpm_commit_buf = i40iw_sc_parse_fpm_commit_buf,
5045 .create_hmc_object = i40iw_sc_create_hmc_obj,
5046 .del_hmc_object = i40iw_sc_del_hmc_obj
Faisal Latif86dbcd02016-01-20 13:40:10 -06005047};
5048
Faisal Latif86dbcd02016-01-20 13:40:10 -06005049/**
5050 * i40iw_device_init - Initialize IWARP device
5051 * @dev: IWARP device pointer
5052 * @info: IWARP init info
5053 */
5054enum i40iw_status_code i40iw_device_init(struct i40iw_sc_dev *dev,
5055 struct i40iw_device_init_info *info)
5056{
5057 u32 val;
5058 u32 vchnl_ver = 0;
5059 u16 hmc_fcn = 0;
5060 enum i40iw_status_code ret_code = 0;
5061 u8 db_size;
5062
5063 spin_lock_init(&dev->cqp_lock);
5064 INIT_LIST_HEAD(&dev->cqp_cmd_head); /* for the cqp commands backlog. */
5065
5066 i40iw_device_init_uk(&dev->dev_uk);
5067
5068 dev->debug_mask = info->debug_mask;
5069
Faisal Latif86dbcd02016-01-20 13:40:10 -06005070 dev->hmc_fn_id = info->hmc_fn_id;
Faisal Latif86dbcd02016-01-20 13:40:10 -06005071 dev->exception_lan_queue = info->exception_lan_queue;
5072 dev->is_pf = info->is_pf;
5073
5074 dev->fpm_query_buf_pa = info->fpm_query_buf_pa;
5075 dev->fpm_query_buf = info->fpm_query_buf;
5076
5077 dev->fpm_commit_buf_pa = info->fpm_commit_buf_pa;
5078 dev->fpm_commit_buf = info->fpm_commit_buf;
5079
5080 dev->hw = info->hw;
5081 dev->hw->hw_addr = info->bar0;
5082
Faisal Latif86dbcd02016-01-20 13:40:10 -06005083 if (dev->is_pf) {
Henry Oroscod6f7bbc2016-12-06 16:16:20 -06005084 val = i40iw_rd32(dev->hw, I40E_GLPCI_DREVID);
5085 dev->hw_rev = (u8)RS_32(val, I40E_GLPCI_DREVID_DEFAULT_REVID);
5086
Faisal Latif86dbcd02016-01-20 13:40:10 -06005087 val = i40iw_rd32(dev->hw, I40E_GLPCI_LBARCTRL);
5088 db_size = (u8)RS_32(val, I40E_GLPCI_LBARCTRL_PE_DB_SIZE);
5089 if ((db_size != I40IW_PE_DB_SIZE_4M) &&
5090 (db_size != I40IW_PE_DB_SIZE_8M)) {
5091 i40iw_debug(dev, I40IW_DEBUG_DEV,
5092 "%s: PE doorbell is not enabled in CSR val 0x%x\n",
5093 __func__, val);
5094 ret_code = I40IW_ERR_PE_DOORBELL_NOT_ENABLED;
5095 return ret_code;
5096 }
5097 dev->db_addr = dev->hw->hw_addr + I40IW_DB_ADDR_OFFSET;
5098 dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_pf;
5099 } else {
5100 dev->db_addr = dev->hw->hw_addr + I40IW_VF_DB_ADDR_OFFSET;
5101 }
5102
5103 dev->cqp_ops = &iw_cqp_ops;
5104 dev->ccq_ops = &iw_ccq_ops;
5105 dev->ceq_ops = &iw_ceq_ops;
5106 dev->aeq_ops = &iw_aeq_ops;
5107 dev->cqp_misc_ops = &iw_cqp_misc_ops;
5108 dev->iw_pd_ops = &iw_pd_ops;
5109 dev->iw_priv_qp_ops = &iw_priv_qp_ops;
5110 dev->iw_priv_cq_ops = &iw_priv_cq_ops;
5111 dev->mr_ops = &iw_mr_ops;
5112 dev->hmc_ops = &iw_hmc_ops;
5113 dev->vchnl_if.vchnl_send = info->vchnl_send;
5114 if (dev->vchnl_if.vchnl_send)
5115 dev->vchnl_up = true;
5116 else
5117 dev->vchnl_up = false;
5118 if (!dev->is_pf) {
5119 dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_vf;
5120 ret_code = i40iw_vchnl_vf_get_ver(dev, &vchnl_ver);
5121 if (!ret_code) {
5122 i40iw_debug(dev, I40IW_DEBUG_DEV,
5123 "%s: Get Channel version rc = 0x%0x, version is %u\n",
5124 __func__, ret_code, vchnl_ver);
5125 ret_code = i40iw_vchnl_vf_get_hmc_fcn(dev, &hmc_fcn);
5126 if (!ret_code) {
5127 i40iw_debug(dev, I40IW_DEBUG_DEV,
5128 "%s Get HMC function rc = 0x%0x, hmc fcn is %u\n",
5129 __func__, ret_code, hmc_fcn);
5130 dev->hmc_fn_id = (u8)hmc_fcn;
5131 }
5132 }
5133 }
5134 dev->iw_vf_cqp_ops = &iw_vf_cqp_ops;
5135
5136 return ret_code;
5137}