i40iw_hw.c 22 KB

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