i40iw_hw.c 23 KB

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