1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41#include <linux/if_vlan.h>
42
43#include "i40iw.h"
44
45
46
47
48
49u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev)
50{
51 unsigned long num_pds;
52 u32 resources_size;
53 u32 max_mr;
54 u32 max_qp;
55 u32 max_cq;
56 u32 arp_table_size;
57 u32 mrdrvbits;
58 void *resource_ptr;
59
60 max_qp = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt;
61 max_cq = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
62 max_mr = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt;
63 arp_table_size = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_ARP].cnt;
64 iwdev->max_cqe = 0xFFFFF;
65 num_pds = I40IW_MAX_PDS;
66 resources_size = sizeof(struct i40iw_arp_entry) * arp_table_size;
67 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
68 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
69 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
70 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
71 resources_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
72 resources_size += sizeof(struct i40iw_qp **) * max_qp;
73 iwdev->mem_resources = kzalloc(resources_size, GFP_KERNEL);
74
75 if (!iwdev->mem_resources)
76 return -ENOMEM;
77
78 iwdev->max_qp = max_qp;
79 iwdev->max_mr = max_mr;
80 iwdev->max_cq = max_cq;
81 iwdev->max_pd = num_pds;
82 iwdev->arp_table_size = arp_table_size;
83 iwdev->arp_table = (struct i40iw_arp_entry *)iwdev->mem_resources;
84 resource_ptr = iwdev->mem_resources + (sizeof(struct i40iw_arp_entry) * arp_table_size);
85
86 iwdev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY |
87 IB_DEVICE_MEM_WINDOW | IB_DEVICE_MEM_MGT_EXTENSIONS;
88
89 iwdev->allocated_qps = resource_ptr;
90 iwdev->allocated_cqs = &iwdev->allocated_qps[BITS_TO_LONGS(max_qp)];
91 iwdev->allocated_mrs = &iwdev->allocated_cqs[BITS_TO_LONGS(max_cq)];
92 iwdev->allocated_pds = &iwdev->allocated_mrs[BITS_TO_LONGS(max_mr)];
93 iwdev->allocated_arps = &iwdev->allocated_pds[BITS_TO_LONGS(num_pds)];
94 iwdev->qp_table = (struct i40iw_qp **)(&iwdev->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
95 set_bit(0, iwdev->allocated_mrs);
96 set_bit(0, iwdev->allocated_qps);
97 set_bit(0, iwdev->allocated_cqs);
98 set_bit(0, iwdev->allocated_pds);
99 set_bit(0, iwdev->allocated_arps);
100
101
102 set_bit(1, iwdev->allocated_qps);
103 set_bit(1, iwdev->allocated_cqs);
104 set_bit(1, iwdev->allocated_pds);
105 set_bit(2, iwdev->allocated_cqs);
106 set_bit(2, iwdev->allocated_pds);
107
108 spin_lock_init(&iwdev->resource_lock);
109 spin_lock_init(&iwdev->qptable_lock);
110
111 mrdrvbits = 24 - max(get_count_order(iwdev->max_mr), 14);
112 iwdev->mr_stagmask = ~(((1 << mrdrvbits) - 1) << (32 - mrdrvbits));
113 return 0;
114}
115
116
117
118
119
120
121
122static void i40iw_cqp_ce_handler(struct i40iw_device *iwdev, struct i40iw_sc_cq *cq, bool arm)
123{
124 struct i40iw_cqp_request *cqp_request;
125 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
126 u32 cqe_count = 0;
127 struct i40iw_ccq_cqe_info info;
128 int ret;
129
130 do {
131 memset(&info, 0, sizeof(info));
132 ret = dev->ccq_ops->ccq_get_cqe_info(cq, &info);
133 if (ret)
134 break;
135 cqp_request = (struct i40iw_cqp_request *)(unsigned long)info.scratch;
136 if (info.error)
137 i40iw_pr_err("opcode = 0x%x maj_err_code = 0x%x min_err_code = 0x%x\n",
138 info.op_code, info.maj_err_code, info.min_err_code);
139 if (cqp_request) {
140 cqp_request->compl_info.maj_err_code = info.maj_err_code;
141 cqp_request->compl_info.min_err_code = info.min_err_code;
142 cqp_request->compl_info.op_ret_val = info.op_ret_val;
143 cqp_request->compl_info.error = info.error;
144
145 if (cqp_request->waiting) {
146 cqp_request->request_done = true;
147 wake_up(&cqp_request->waitq);
148 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
149 } else {
150 if (cqp_request->callback_fcn)
151 cqp_request->callback_fcn(cqp_request, 1);
152 i40iw_put_cqp_request(&iwdev->cqp, cqp_request);
153 }
154 }
155
156 cqe_count++;
157 } while (1);
158
159 if (arm && cqe_count) {
160 i40iw_process_bh(dev);
161 dev->ccq_ops->ccq_arm(cq);
162 }
163}
164
165
166
167
168
169
170static void i40iw_iwarp_ce_handler(struct i40iw_device *iwdev,
171 struct i40iw_sc_cq *iwcq)
172{
173 struct i40iw_cq *i40iwcq = iwcq->back_cq;
174
175 if (i40iwcq->ibcq.comp_handler)
176 i40iwcq->ibcq.comp_handler(&i40iwcq->ibcq,
177 i40iwcq->ibcq.cq_context);
178}
179
180
181
182
183
184
185static void i40iw_puda_ce_handler(struct i40iw_device *iwdev,
186 struct i40iw_sc_cq *cq)
187{
188 struct i40iw_sc_dev *dev = (struct i40iw_sc_dev *)&iwdev->sc_dev;
189 enum i40iw_status_code status;
190 u32 compl_error;
191
192 do {
193 status = i40iw_puda_poll_completion(dev, cq, &compl_error);
194 if (status == I40IW_ERR_QUEUE_EMPTY)
195 break;
196 if (status) {
197 i40iw_pr_err("puda status = %d\n", status);
198 break;
199 }
200 if (compl_error) {
201 i40iw_pr_err("puda compl_err =0x%x\n", compl_error);
202 break;
203 }
204 } while (1);
205
206 dev->ccq_ops->ccq_arm(cq);
207}
208
209
210
211
212
213
214void i40iw_process_ceq(struct i40iw_device *iwdev, struct i40iw_ceq *ceq)
215{
216 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
217 struct i40iw_sc_ceq *sc_ceq;
218 struct i40iw_sc_cq *cq;
219 bool arm = true;
220
221 sc_ceq = &ceq->sc_ceq;
222 do {
223 cq = dev->ceq_ops->process_ceq(dev, sc_ceq);
224 if (!cq)
225 break;
226
227 if (cq->cq_type == I40IW_CQ_TYPE_CQP)
228 i40iw_cqp_ce_handler(iwdev, cq, arm);
229 else if (cq->cq_type == I40IW_CQ_TYPE_IWARP)
230 i40iw_iwarp_ce_handler(iwdev, cq);
231 else if ((cq->cq_type == I40IW_CQ_TYPE_ILQ) ||
232 (cq->cq_type == I40IW_CQ_TYPE_IEQ))
233 i40iw_puda_ce_handler(iwdev, cq);
234 } while (1);
235}
236
237
238
239
240
241
242
243
244
245void i40iw_next_iw_state(struct i40iw_qp *iwqp,
246 u8 state,
247 u8 del_hash,
248 u8 term,
249 u8 termlen)
250{
251 struct i40iw_modify_qp_info info;
252
253 memset(&info, 0, sizeof(info));
254 info.next_iwarp_state = state;
255 info.remove_hash_idx = del_hash;
256 info.cq_num_valid = true;
257 info.arp_cache_idx_valid = true;
258 info.dont_send_term = true;
259 info.dont_send_fin = true;
260 info.termlen = termlen;
261
262 if (term & I40IWQP_TERM_SEND_TERM_ONLY)
263 info.dont_send_term = false;
264 if (term & I40IWQP_TERM_SEND_FIN_ONLY)
265 info.dont_send_fin = false;
266 if (iwqp->sc_qp.term_flags && (state == I40IW_QP_STATE_ERROR))
267 info.reset_tcp_conn = true;
268 iwqp->hw_iwarp_state = state;
269 i40iw_hw_modify_qp(iwqp->iwdev, iwqp, &info, 0);
270}
271
272
273
274
275
276void i40iw_process_aeq(struct i40iw_device *iwdev)
277{
278 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
279 struct i40iw_aeq *aeq = &iwdev->aeq;
280 struct i40iw_sc_aeq *sc_aeq = &aeq->sc_aeq;
281 struct i40iw_aeqe_info aeinfo;
282 struct i40iw_aeqe_info *info = &aeinfo;
283 int ret;
284 struct i40iw_qp *iwqp = NULL;
285 struct i40iw_sc_cq *cq = NULL;
286 struct i40iw_cq *iwcq = NULL;
287 struct i40iw_sc_qp *qp = NULL;
288 struct i40iw_qp_host_ctx_info *ctx_info = NULL;
289 unsigned long flags;
290
291 u32 aeqcnt = 0;
292
293 if (!sc_aeq->size)
294 return;
295
296 do {
297 memset(info, 0, sizeof(*info));
298 ret = dev->aeq_ops->get_next_aeqe(sc_aeq, info);
299 if (ret)
300 break;
301
302 aeqcnt++;
303 i40iw_debug(dev, I40IW_DEBUG_AEQ,
304 "%s ae_id = 0x%x bool qp=%d qp_id = %d\n",
305 __func__, info->ae_id, info->qp, info->qp_cq_id);
306 if (info->qp) {
307 spin_lock_irqsave(&iwdev->qptable_lock, flags);
308 iwqp = iwdev->qp_table[info->qp_cq_id];
309 if (!iwqp) {
310 spin_unlock_irqrestore(&iwdev->qptable_lock, flags);
311 i40iw_debug(dev, I40IW_DEBUG_AEQ,
312 "%s qp_id %d is already freed\n",
313 __func__, info->qp_cq_id);
314 continue;
315 }
316 i40iw_add_ref(&iwqp->ibqp);
317 spin_unlock_irqrestore(&iwdev->qptable_lock, flags);
318 qp = &iwqp->sc_qp;
319 spin_lock_irqsave(&iwqp->lock, flags);
320 iwqp->hw_tcp_state = info->tcp_state;
321 iwqp->hw_iwarp_state = info->iwarp_state;
322 iwqp->last_aeq = info->ae_id;
323 spin_unlock_irqrestore(&iwqp->lock, flags);
324 ctx_info = &iwqp->ctx_info;
325 ctx_info->err_rq_idx_valid = true;
326 } else {
327 if (info->ae_id != I40IW_AE_CQ_OPERATION_ERROR)
328 continue;
329 }
330
331 switch (info->ae_id) {
332 case I40IW_AE_LLP_FIN_RECEIVED:
333 if (qp->term_flags)
334 break;
335 if (atomic_inc_return(&iwqp->close_timer_started) == 1) {
336 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSE_WAIT;
337 if ((iwqp->hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) &&
338 (iwqp->ibqp_state == IB_QPS_RTS)) {
339 i40iw_next_iw_state(iwqp,
340 I40IW_QP_STATE_CLOSING, 0, 0, 0);
341 i40iw_cm_disconn(iwqp);
342 }
343 iwqp->cm_id->add_ref(iwqp->cm_id);
344 i40iw_schedule_cm_timer(iwqp->cm_node,
345 (struct i40iw_puda_buf *)iwqp,
346 I40IW_TIMER_TYPE_CLOSE, 1, 0);
347 }
348 break;
349 case I40IW_AE_LLP_CLOSE_COMPLETE:
350 if (qp->term_flags)
351 i40iw_terminate_done(qp, 0);
352 else
353 i40iw_cm_disconn(iwqp);
354 break;
355 case I40IW_AE_BAD_CLOSE:
356
357 case I40IW_AE_RESET_SENT:
358 i40iw_next_iw_state(iwqp, I40IW_QP_STATE_ERROR, 1, 0, 0);
359 i40iw_cm_disconn(iwqp);
360 break;
361 case I40IW_AE_LLP_CONNECTION_RESET:
362 if (atomic_read(&iwqp->close_timer_started))
363 break;
364 i40iw_cm_disconn(iwqp);
365 break;
366 case I40IW_AE_QP_SUSPEND_COMPLETE:
367 i40iw_qp_suspend_resume(dev, &iwqp->sc_qp, false);
368 break;
369 case I40IW_AE_TERMINATE_SENT:
370 i40iw_terminate_send_fin(qp);
371 break;
372 case I40IW_AE_LLP_TERMINATE_RECEIVED:
373 i40iw_terminate_received(qp, info);
374 break;
375 case I40IW_AE_CQ_OPERATION_ERROR:
376 i40iw_pr_err("Processing an iWARP related AE for CQ misc = 0x%04X\n",
377 info->ae_id);
378 cq = (struct i40iw_sc_cq *)(unsigned long)info->compl_ctx;
379 iwcq = (struct i40iw_cq *)cq->back_cq;
380
381 if (iwcq->ibcq.event_handler) {
382 struct ib_event ibevent;
383
384 ibevent.device = iwcq->ibcq.device;
385 ibevent.event = IB_EVENT_CQ_ERR;
386 ibevent.element.cq = &iwcq->ibcq;
387 iwcq->ibcq.event_handler(&ibevent, iwcq->ibcq.cq_context);
388 }
389 break;
390 case I40IW_AE_LLP_DOUBT_REACHABILITY:
391 break;
392 case I40IW_AE_PRIV_OPERATION_DENIED:
393 case I40IW_AE_STAG_ZERO_INVALID:
394 case I40IW_AE_IB_RREQ_AND_Q1_FULL:
395 case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
396 case I40IW_AE_DDP_UBE_INVALID_MO:
397 case I40IW_AE_DDP_UBE_INVALID_QN:
398 case I40IW_AE_DDP_NO_L_BIT:
399 case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
400 case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
401 case I40IW_AE_ROE_INVALID_RDMA_READ_REQUEST:
402 case I40IW_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
403 case I40IW_AE_INVALID_ARP_ENTRY:
404 case I40IW_AE_INVALID_TCP_OPTION_RCVD:
405 case I40IW_AE_STALE_ARP_ENTRY:
406 case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
407 case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
408 case I40IW_AE_LLP_SYN_RECEIVED:
409 case I40IW_AE_LLP_TOO_MANY_RETRIES:
410 case I40IW_AE_LCE_QP_CATASTROPHIC:
411 case I40IW_AE_LCE_FUNCTION_CATASTROPHIC:
412 case I40IW_AE_LCE_CQ_CATASTROPHIC:
413 case I40IW_AE_UDA_XMIT_DGRAM_TOO_LONG:
414 case I40IW_AE_UDA_XMIT_DGRAM_TOO_SHORT:
415 ctx_info->err_rq_idx_valid = false;
416
417 default:
418 if (!info->sq && ctx_info->err_rq_idx_valid) {
419 ctx_info->err_rq_idx = info->wqe_idx;
420 ctx_info->tcp_info_valid = false;
421 ctx_info->iwarp_info_valid = false;
422 ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
423 iwqp->host_ctx.va,
424 ctx_info);
425 }
426 i40iw_terminate_connection(qp, info);
427 break;
428 }
429 if (info->qp)
430 i40iw_rem_ref(&iwqp->ibqp);
431 } while (1);
432
433 if (aeqcnt)
434 dev->aeq_ops->repost_aeq_entries(dev, aeqcnt);
435}
436
437
438
439
440
441
442
443int i40iw_manage_apbvt(struct i40iw_device *iwdev, u16 accel_local_port, bool add_port)
444{
445 struct i40iw_apbvt_info *info;
446 enum i40iw_status_code status;
447 struct i40iw_cqp_request *cqp_request;
448 struct cqp_commands_info *cqp_info;
449
450 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, add_port);
451 if (!cqp_request)
452 return -ENOMEM;
453
454 cqp_info = &cqp_request->info;
455 info = &cqp_info->in.u.manage_apbvt_entry.info;
456
457 memset(info, 0, sizeof(*info));
458 info->add = add_port;
459 info->port = cpu_to_le16(accel_local_port);
460
461 cqp_info->cqp_cmd = OP_MANAGE_APBVT_ENTRY;
462 cqp_info->post_sq = 1;
463 cqp_info->in.u.manage_apbvt_entry.cqp = &iwdev->cqp.sc_cqp;
464 cqp_info->in.u.manage_apbvt_entry.scratch = (uintptr_t)cqp_request;
465 status = i40iw_handle_cqp_op(iwdev, cqp_request);
466 if (status)
467 i40iw_pr_err("CQP-OP Manage APBVT entry fail");
468 return status;
469}
470
471
472
473
474
475
476
477
478void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
479 unsigned char *mac_addr,
480 u32 *ip_addr,
481 bool ipv4,
482 u32 action)
483{
484 struct i40iw_add_arp_cache_entry_info *info;
485 struct i40iw_cqp_request *cqp_request;
486 struct cqp_commands_info *cqp_info;
487 int arp_index;
488
489 arp_index = i40iw_arp_table(iwdev, ip_addr, ipv4, mac_addr, action);
490 if (arp_index == -1)
491 return;
492 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
493 if (!cqp_request)
494 return;
495
496 cqp_info = &cqp_request->info;
497 if (action == I40IW_ARP_ADD) {
498 cqp_info->cqp_cmd = OP_ADD_ARP_CACHE_ENTRY;
499 info = &cqp_info->in.u.add_arp_cache_entry.info;
500 memset(info, 0, sizeof(*info));
501 info->arp_index = cpu_to_le16((u16)arp_index);
502 info->permanent = true;
503 ether_addr_copy(info->mac_addr, mac_addr);
504 cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
505 cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
506 } else {
507 cqp_info->cqp_cmd = OP_DELETE_ARP_CACHE_ENTRY;
508 cqp_info->in.u.del_arp_cache_entry.scratch = (uintptr_t)cqp_request;
509 cqp_info->in.u.del_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
510 cqp_info->in.u.del_arp_cache_entry.arp_index = arp_index;
511 }
512
513 cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
514 cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
515 cqp_info->post_sq = 1;
516 if (i40iw_handle_cqp_op(iwdev, cqp_request))
517 i40iw_pr_err("CQP-OP Add/Del Arp Cache entry fail");
518}
519
520
521
522
523
524
525static void i40iw_send_syn_cqp_callback(struct i40iw_cqp_request *cqp_request, u32 send_ack)
526{
527 i40iw_send_syn(cqp_request->param, send_ack);
528}
529
530
531
532
533
534
535
536
537
538
539
540enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
541 struct i40iw_cm_info *cminfo,
542 enum i40iw_quad_entry_type etype,
543 enum i40iw_quad_hash_manage_type mtype,
544 void *cmnode,
545 bool wait)
546{
547 struct i40iw_qhash_table_info *info;
548 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
549 struct i40iw_sc_vsi *vsi = &iwdev->vsi;
550 enum i40iw_status_code status;
551 struct i40iw_cqp *iwcqp = &iwdev->cqp;
552 struct i40iw_cqp_request *cqp_request;
553 struct cqp_commands_info *cqp_info;
554
555 cqp_request = i40iw_get_cqp_request(iwcqp, wait);
556 if (!cqp_request)
557 return I40IW_ERR_NO_MEMORY;
558 cqp_info = &cqp_request->info;
559 info = &cqp_info->in.u.manage_qhash_table_entry.info;
560 memset(info, 0, sizeof(*info));
561
562 info->vsi = &iwdev->vsi;
563 info->manage = mtype;
564 info->entry_type = etype;
565 if (cminfo->vlan_id != 0xFFFF) {
566 info->vlan_valid = true;
567 info->vlan_id = cpu_to_le16(cminfo->vlan_id);
568 } else {
569 info->vlan_valid = false;
570 }
571
572 info->ipv4_valid = cminfo->ipv4;
573 info->user_pri = cminfo->user_pri;
574 ether_addr_copy(info->mac_addr, iwdev->netdev->dev_addr);
575 info->qp_num = cpu_to_le32(vsi->ilq->qp_id);
576 info->dest_port = cpu_to_le16(cminfo->loc_port);
577 info->dest_ip[0] = cpu_to_le32(cminfo->loc_addr[0]);
578 info->dest_ip[1] = cpu_to_le32(cminfo->loc_addr[1]);
579 info->dest_ip[2] = cpu_to_le32(cminfo->loc_addr[2]);
580 info->dest_ip[3] = cpu_to_le32(cminfo->loc_addr[3]);
581 if (etype == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
582 info->src_port = cpu_to_le16(cminfo->rem_port);
583 info->src_ip[0] = cpu_to_le32(cminfo->rem_addr[0]);
584 info->src_ip[1] = cpu_to_le32(cminfo->rem_addr[1]);
585 info->src_ip[2] = cpu_to_le32(cminfo->rem_addr[2]);
586 info->src_ip[3] = cpu_to_le32(cminfo->rem_addr[3]);
587 }
588 if (cmnode) {
589 cqp_request->callback_fcn = i40iw_send_syn_cqp_callback;
590 cqp_request->param = (void *)cmnode;
591 }
592
593 if (info->ipv4_valid)
594 i40iw_debug(dev, I40IW_DEBUG_CM,
595 "%s:%s IP=%pI4, port=%d, mac=%pM, vlan_id=%d\n",
596 __func__, (!mtype) ? "DELETE" : "ADD",
597 info->dest_ip,
598 info->dest_port, info->mac_addr, cminfo->vlan_id);
599 else
600 i40iw_debug(dev, I40IW_DEBUG_CM,
601 "%s:%s IP=%pI6, port=%d, mac=%pM, vlan_id=%d\n",
602 __func__, (!mtype) ? "DELETE" : "ADD",
603 info->dest_ip,
604 info->dest_port, info->mac_addr, cminfo->vlan_id);
605 cqp_info->in.u.manage_qhash_table_entry.cqp = &iwdev->cqp.sc_cqp;
606 cqp_info->in.u.manage_qhash_table_entry.scratch = (uintptr_t)cqp_request;
607 cqp_info->cqp_cmd = OP_MANAGE_QHASH_TABLE_ENTRY;
608 cqp_info->post_sq = 1;
609 status = i40iw_handle_cqp_op(iwdev, cqp_request);
610 if (status)
611 i40iw_pr_err("CQP-OP Manage Qhash Entry fail");
612 return status;
613}
614
615
616
617
618
619
620
621
622enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
623 struct i40iw_sc_qp *qp,
624 struct i40iw_qp_flush_info *info,
625 bool wait)
626{
627 enum i40iw_status_code status;
628 struct i40iw_qp_flush_info *hw_info;
629 struct i40iw_cqp_request *cqp_request;
630 struct cqp_commands_info *cqp_info;
631 struct i40iw_qp *iwqp = (struct i40iw_qp *)qp->back_qp;
632
633 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
634 if (!cqp_request)
635 return I40IW_ERR_NO_MEMORY;
636
637 cqp_info = &cqp_request->info;
638 hw_info = &cqp_request->info.in.u.qp_flush_wqes.info;
639 memcpy(hw_info, info, sizeof(*hw_info));
640
641 cqp_info->cqp_cmd = OP_QP_FLUSH_WQES;
642 cqp_info->post_sq = 1;
643 cqp_info->in.u.qp_flush_wqes.qp = qp;
644 cqp_info->in.u.qp_flush_wqes.scratch = (uintptr_t)cqp_request;
645 status = i40iw_handle_cqp_op(iwdev, cqp_request);
646 if (status) {
647 i40iw_pr_err("CQP-OP Flush WQE's fail");
648 complete(&iwqp->sq_drained);
649 complete(&iwqp->rq_drained);
650 return status;
651 }
652 if (!cqp_request->compl_info.maj_err_code) {
653 switch (cqp_request->compl_info.min_err_code) {
654 case I40IW_CQP_COMPL_RQ_WQE_FLUSHED:
655 complete(&iwqp->sq_drained);
656 break;
657 case I40IW_CQP_COMPL_SQ_WQE_FLUSHED:
658 complete(&iwqp->rq_drained);
659 break;
660 case I40IW_CQP_COMPL_RQ_SQ_WQE_FLUSHED:
661 break;
662 default:
663 complete(&iwqp->sq_drained);
664 complete(&iwqp->rq_drained);
665 break;
666 }
667 }
668
669 return 0;
670}
671
672
673
674
675
676
677
678
679void i40iw_gen_ae(struct i40iw_device *iwdev,
680 struct i40iw_sc_qp *qp,
681 struct i40iw_gen_ae_info *info,
682 bool wait)
683{
684 struct i40iw_gen_ae_info *ae_info;
685 struct i40iw_cqp_request *cqp_request;
686 struct cqp_commands_info *cqp_info;
687
688 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
689 if (!cqp_request)
690 return;
691
692 cqp_info = &cqp_request->info;
693 ae_info = &cqp_request->info.in.u.gen_ae.info;
694 memcpy(ae_info, info, sizeof(*ae_info));
695
696 cqp_info->cqp_cmd = OP_GEN_AE;
697 cqp_info->post_sq = 1;
698 cqp_info->in.u.gen_ae.qp = qp;
699 cqp_info->in.u.gen_ae.scratch = (uintptr_t)cqp_request;
700 if (i40iw_handle_cqp_op(iwdev, cqp_request))
701 i40iw_pr_err("CQP OP failed attempting to generate ae_code=0x%x\n",
702 info->ae_code);
703}
704
705
706
707
708
709
710
711enum i40iw_status_code i40iw_hw_manage_vf_pble_bp(struct i40iw_device *iwdev,
712 struct i40iw_manage_vf_pble_info *info,
713 bool wait)
714{
715 enum i40iw_status_code status;
716 struct i40iw_manage_vf_pble_info *hw_info;
717 struct i40iw_cqp_request *cqp_request;
718 struct cqp_commands_info *cqp_info;
719
720 if ((iwdev->init_state < CCQ_CREATED) && wait)
721 wait = false;
722
723 cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
724 if (!cqp_request)
725 return I40IW_ERR_NO_MEMORY;
726
727 cqp_info = &cqp_request->info;
728 hw_info = &cqp_request->info.in.u.manage_vf_pble_bp.info;
729 memcpy(hw_info, info, sizeof(*hw_info));
730
731 cqp_info->cqp_cmd = OP_MANAGE_VF_PBLE_BP;
732 cqp_info->post_sq = 1;
733 cqp_info->in.u.manage_vf_pble_bp.cqp = &iwdev->cqp.sc_cqp;
734 cqp_info->in.u.manage_vf_pble_bp.scratch = (uintptr_t)cqp_request;
735 status = i40iw_handle_cqp_op(iwdev, cqp_request);
736 if (status)
737 i40iw_pr_err("CQP-OP Manage VF pble_bp fail");
738 return status;
739}
740
741
742
743
744
745static enum ib_wc_status i40iw_get_ib_wc(enum i40iw_flush_opcode opcode)
746{
747 switch (opcode) {
748 case FLUSH_PROT_ERR:
749 return IB_WC_LOC_PROT_ERR;
750 case FLUSH_REM_ACCESS_ERR:
751 return IB_WC_REM_ACCESS_ERR;
752 case FLUSH_LOC_QP_OP_ERR:
753 return IB_WC_LOC_QP_OP_ERR;
754 case FLUSH_REM_OP_ERR:
755 return IB_WC_REM_OP_ERR;
756 case FLUSH_LOC_LEN_ERR:
757 return IB_WC_LOC_LEN_ERR;
758 case FLUSH_GENERAL_ERR:
759 return IB_WC_GENERAL_ERR;
760 case FLUSH_FATAL_ERR:
761 default:
762 return IB_WC_FATAL_ERR;
763 }
764}
765
766
767
768
769
770
771
772
773static void i40iw_set_flush_info(struct i40iw_qp_flush_info *pinfo,
774 u16 *min,
775 u16 *maj,
776 enum i40iw_flush_opcode opcode)
777{
778 *min = (u16)i40iw_get_ib_wc(opcode);
779 *maj = CQE_MAJOR_DRV;
780 pinfo->userflushcode = true;
781}
782
783
784
785
786
787
788void i40iw_flush_wqes(struct i40iw_device *iwdev, struct i40iw_qp *iwqp)
789{
790 struct i40iw_qp_flush_info info;
791 struct i40iw_qp_flush_info *pinfo = &info;
792
793 struct i40iw_sc_qp *qp = &iwqp->sc_qp;
794
795 memset(pinfo, 0, sizeof(*pinfo));
796 info.sq = true;
797 info.rq = true;
798 if (qp->term_flags) {
799 i40iw_set_flush_info(pinfo, &pinfo->sq_minor_code,
800 &pinfo->sq_major_code, qp->flush_code);
801 i40iw_set_flush_info(pinfo, &pinfo->rq_minor_code,
802 &pinfo->rq_major_code, qp->flush_code);
803 }
804 (void)i40iw_hw_flush_wqes(iwdev, &iwqp->sc_qp, &info, true);
805}
806