i40iw_hw.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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_BAD_CLOSE:
  324. /* fall through */
  325. case I40IW_AE_RESET_SENT:
  326. i40iw_next_iw_state(iwqp, I40IW_QP_STATE_ERROR, 1, 0, 0);
  327. i40iw_cm_disconn(iwqp);
  328. break;
  329. case I40IW_AE_LLP_CONNECTION_RESET:
  330. if (atomic_read(&iwqp->close_timer_started))
  331. continue;
  332. i40iw_cm_disconn(iwqp);
  333. break;
  334. case I40IW_AE_QP_SUSPEND_COMPLETE:
  335. i40iw_qp_suspend_resume(dev, &iwqp->sc_qp, false);
  336. break;
  337. case I40IW_AE_TERMINATE_SENT:
  338. i40iw_terminate_send_fin(qp);
  339. break;
  340. case I40IW_AE_LLP_TERMINATE_RECEIVED:
  341. i40iw_terminate_received(qp, info);
  342. break;
  343. case I40IW_AE_CQ_OPERATION_ERROR:
  344. i40iw_pr_err("Processing an iWARP related AE for CQ misc = 0x%04X\n",
  345. info->ae_id);
  346. cq = (struct i40iw_sc_cq *)(unsigned long)info->compl_ctx;
  347. iwcq = (struct i40iw_cq *)cq->back_cq;
  348. if (iwcq->ibcq.event_handler) {
  349. struct ib_event ibevent;
  350. ibevent.device = iwcq->ibcq.device;
  351. ibevent.event = IB_EVENT_CQ_ERR;
  352. ibevent.element.cq = &iwcq->ibcq;
  353. iwcq->ibcq.event_handler(&ibevent, iwcq->ibcq.cq_context);
  354. }
  355. break;
  356. case I40IW_AE_LLP_DOUBT_REACHABILITY:
  357. break;
  358. case I40IW_AE_PRIV_OPERATION_DENIED:
  359. case I40IW_AE_STAG_ZERO_INVALID:
  360. case I40IW_AE_IB_RREQ_AND_Q1_FULL:
  361. case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
  362. case I40IW_AE_DDP_UBE_INVALID_MO:
  363. case I40IW_AE_DDP_UBE_INVALID_QN:
  364. case I40IW_AE_DDP_NO_L_BIT:
  365. case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
  366. case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
  367. case I40IW_AE_ROE_INVALID_RDMA_READ_REQUEST:
  368. case I40IW_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
  369. case I40IW_AE_INVALID_ARP_ENTRY:
  370. case I40IW_AE_INVALID_TCP_OPTION_RCVD:
  371. case I40IW_AE_STALE_ARP_ENTRY:
  372. case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
  373. case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
  374. case I40IW_AE_LLP_SYN_RECEIVED:
  375. case I40IW_AE_LLP_TOO_MANY_RETRIES:
  376. case I40IW_AE_LCE_QP_CATASTROPHIC:
  377. case I40IW_AE_LCE_FUNCTION_CATASTROPHIC:
  378. case I40IW_AE_LCE_CQ_CATASTROPHIC:
  379. case I40IW_AE_UDA_XMIT_DGRAM_TOO_LONG:
  380. case I40IW_AE_UDA_XMIT_DGRAM_TOO_SHORT:
  381. ctx_info->err_rq_idx_valid = false;
  382. /* fall through */
  383. default:
  384. if (!info->sq && ctx_info->err_rq_idx_valid) {
  385. ctx_info->err_rq_idx = info->wqe_idx;
  386. ctx_info->tcp_info_valid = false;
  387. ctx_info->iwarp_info_valid = false;
  388. ret = dev->iw_priv_qp_ops->qp_setctx(&iwqp->sc_qp,
  389. iwqp->host_ctx.va,
  390. ctx_info);
  391. }
  392. i40iw_terminate_connection(qp, info);
  393. break;
  394. }
  395. if (info->qp)
  396. i40iw_rem_ref(&iwqp->ibqp);
  397. } while (1);
  398. if (aeqcnt)
  399. dev->aeq_ops->repost_aeq_entries(dev, aeqcnt);
  400. }
  401. /**
  402. * i40iw_manage_apbvt - add or delete tcp port
  403. * @iwdev: iwarp device
  404. * @accel_local_port: port for apbvt
  405. * @add_port: add or delete port
  406. */
  407. int i40iw_manage_apbvt(struct i40iw_device *iwdev, u16 accel_local_port, bool add_port)
  408. {
  409. struct i40iw_apbvt_info *info;
  410. enum i40iw_status_code status;
  411. struct i40iw_cqp_request *cqp_request;
  412. struct cqp_commands_info *cqp_info;
  413. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, add_port);
  414. if (!cqp_request)
  415. return -ENOMEM;
  416. cqp_info = &cqp_request->info;
  417. info = &cqp_info->in.u.manage_apbvt_entry.info;
  418. memset(info, 0, sizeof(*info));
  419. info->add = add_port;
  420. info->port = cpu_to_le16(accel_local_port);
  421. cqp_info->cqp_cmd = OP_MANAGE_APBVT_ENTRY;
  422. cqp_info->post_sq = 1;
  423. cqp_info->in.u.manage_apbvt_entry.cqp = &iwdev->cqp.sc_cqp;
  424. cqp_info->in.u.manage_apbvt_entry.scratch = (uintptr_t)cqp_request;
  425. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  426. if (status)
  427. i40iw_pr_err("CQP-OP Manage APBVT entry fail");
  428. return status;
  429. }
  430. /**
  431. * i40iw_manage_arp_cache - manage hw arp cache
  432. * @iwdev: iwarp device
  433. * @mac_addr: mac address ptr
  434. * @ip_addr: ip addr for arp cache
  435. * @action: add, delete or modify
  436. */
  437. void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
  438. unsigned char *mac_addr,
  439. u32 *ip_addr,
  440. bool ipv4,
  441. u32 action)
  442. {
  443. struct i40iw_add_arp_cache_entry_info *info;
  444. struct i40iw_cqp_request *cqp_request;
  445. struct cqp_commands_info *cqp_info;
  446. int arp_index;
  447. arp_index = i40iw_arp_table(iwdev, ip_addr, ipv4, mac_addr, action);
  448. if (arp_index == -1)
  449. return;
  450. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
  451. if (!cqp_request)
  452. return;
  453. cqp_info = &cqp_request->info;
  454. if (action == I40IW_ARP_ADD) {
  455. cqp_info->cqp_cmd = OP_ADD_ARP_CACHE_ENTRY;
  456. info = &cqp_info->in.u.add_arp_cache_entry.info;
  457. memset(info, 0, sizeof(*info));
  458. info->arp_index = cpu_to_le16((u16)arp_index);
  459. info->permanent = true;
  460. ether_addr_copy(info->mac_addr, mac_addr);
  461. cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
  462. cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
  463. } else {
  464. cqp_info->cqp_cmd = OP_DELETE_ARP_CACHE_ENTRY;
  465. cqp_info->in.u.del_arp_cache_entry.scratch = (uintptr_t)cqp_request;
  466. cqp_info->in.u.del_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
  467. cqp_info->in.u.del_arp_cache_entry.arp_index = arp_index;
  468. }
  469. cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
  470. cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
  471. cqp_info->post_sq = 1;
  472. if (i40iw_handle_cqp_op(iwdev, cqp_request))
  473. i40iw_pr_err("CQP-OP Add/Del Arp Cache entry fail");
  474. }
  475. /**
  476. * i40iw_send_syn_cqp_callback - do syn/ack after qhash
  477. * @cqp_request: qhash cqp completion
  478. * @send_ack: flag send ack
  479. */
  480. static void i40iw_send_syn_cqp_callback(struct i40iw_cqp_request *cqp_request, u32 send_ack)
  481. {
  482. i40iw_send_syn(cqp_request->param, send_ack);
  483. }
  484. /**
  485. * i40iw_manage_qhash - add or modify qhash
  486. * @iwdev: iwarp device
  487. * @cminfo: cm info for qhash
  488. * @etype: type (syn or quad)
  489. * @mtype: type of qhash
  490. * @cmnode: cmnode associated with connection
  491. * @wait: wait for completion
  492. * @user_pri:user pri of the connection
  493. */
  494. enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
  495. struct i40iw_cm_info *cminfo,
  496. enum i40iw_quad_entry_type etype,
  497. enum i40iw_quad_hash_manage_type mtype,
  498. void *cmnode,
  499. bool wait)
  500. {
  501. struct i40iw_qhash_table_info *info;
  502. struct i40iw_sc_dev *dev = &iwdev->sc_dev;
  503. struct i40iw_sc_vsi *vsi = &iwdev->vsi;
  504. enum i40iw_status_code status;
  505. struct i40iw_cqp *iwcqp = &iwdev->cqp;
  506. struct i40iw_cqp_request *cqp_request;
  507. struct cqp_commands_info *cqp_info;
  508. cqp_request = i40iw_get_cqp_request(iwcqp, wait);
  509. if (!cqp_request)
  510. return I40IW_ERR_NO_MEMORY;
  511. cqp_info = &cqp_request->info;
  512. info = &cqp_info->in.u.manage_qhash_table_entry.info;
  513. memset(info, 0, sizeof(*info));
  514. info->vsi = &iwdev->vsi;
  515. info->manage = mtype;
  516. info->entry_type = etype;
  517. if (cminfo->vlan_id != 0xFFFF) {
  518. info->vlan_valid = true;
  519. info->vlan_id = cpu_to_le16(cminfo->vlan_id);
  520. } else {
  521. info->vlan_valid = false;
  522. }
  523. info->ipv4_valid = cminfo->ipv4;
  524. info->user_pri = cminfo->user_pri;
  525. ether_addr_copy(info->mac_addr, iwdev->netdev->dev_addr);
  526. info->qp_num = cpu_to_le32(vsi->ilq->qp_id);
  527. info->dest_port = cpu_to_le16(cminfo->loc_port);
  528. info->dest_ip[0] = cpu_to_le32(cminfo->loc_addr[0]);
  529. info->dest_ip[1] = cpu_to_le32(cminfo->loc_addr[1]);
  530. info->dest_ip[2] = cpu_to_le32(cminfo->loc_addr[2]);
  531. info->dest_ip[3] = cpu_to_le32(cminfo->loc_addr[3]);
  532. if (etype == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
  533. info->src_port = cpu_to_le16(cminfo->rem_port);
  534. info->src_ip[0] = cpu_to_le32(cminfo->rem_addr[0]);
  535. info->src_ip[1] = cpu_to_le32(cminfo->rem_addr[1]);
  536. info->src_ip[2] = cpu_to_le32(cminfo->rem_addr[2]);
  537. info->src_ip[3] = cpu_to_le32(cminfo->rem_addr[3]);
  538. }
  539. if (cmnode) {
  540. cqp_request->callback_fcn = i40iw_send_syn_cqp_callback;
  541. cqp_request->param = (void *)cmnode;
  542. }
  543. if (info->ipv4_valid)
  544. i40iw_debug(dev, I40IW_DEBUG_CM,
  545. "%s:%s IP=%pI4, port=%d, mac=%pM, vlan_id=%d\n",
  546. __func__, (!mtype) ? "DELETE" : "ADD",
  547. info->dest_ip,
  548. info->dest_port, info->mac_addr, cminfo->vlan_id);
  549. else
  550. i40iw_debug(dev, I40IW_DEBUG_CM,
  551. "%s:%s IP=%pI6, port=%d, mac=%pM, vlan_id=%d\n",
  552. __func__, (!mtype) ? "DELETE" : "ADD",
  553. info->dest_ip,
  554. info->dest_port, info->mac_addr, cminfo->vlan_id);
  555. cqp_info->in.u.manage_qhash_table_entry.cqp = &iwdev->cqp.sc_cqp;
  556. cqp_info->in.u.manage_qhash_table_entry.scratch = (uintptr_t)cqp_request;
  557. cqp_info->cqp_cmd = OP_MANAGE_QHASH_TABLE_ENTRY;
  558. cqp_info->post_sq = 1;
  559. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  560. if (status)
  561. i40iw_pr_err("CQP-OP Manage Qhash Entry fail");
  562. return status;
  563. }
  564. /**
  565. * i40iw_hw_flush_wqes - flush qp's wqe
  566. * @iwdev: iwarp device
  567. * @qp: hardware control qp
  568. * @info: info for flush
  569. * @wait: flag wait for completion
  570. */
  571. enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
  572. struct i40iw_sc_qp *qp,
  573. struct i40iw_qp_flush_info *info,
  574. bool wait)
  575. {
  576. enum i40iw_status_code status;
  577. struct i40iw_qp_flush_info *hw_info;
  578. struct i40iw_cqp_request *cqp_request;
  579. struct cqp_commands_info *cqp_info;
  580. struct i40iw_qp *iwqp = (struct i40iw_qp *)qp->back_qp;
  581. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  582. if (!cqp_request)
  583. return I40IW_ERR_NO_MEMORY;
  584. cqp_info = &cqp_request->info;
  585. hw_info = &cqp_request->info.in.u.qp_flush_wqes.info;
  586. memcpy(hw_info, info, sizeof(*hw_info));
  587. cqp_info->cqp_cmd = OP_QP_FLUSH_WQES;
  588. cqp_info->post_sq = 1;
  589. cqp_info->in.u.qp_flush_wqes.qp = qp;
  590. cqp_info->in.u.qp_flush_wqes.scratch = (uintptr_t)cqp_request;
  591. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  592. if (status) {
  593. i40iw_pr_err("CQP-OP Flush WQE's fail");
  594. complete(&iwqp->sq_drained);
  595. complete(&iwqp->rq_drained);
  596. return status;
  597. }
  598. if (!cqp_request->compl_info.maj_err_code) {
  599. switch (cqp_request->compl_info.min_err_code) {
  600. case I40IW_CQP_COMPL_RQ_WQE_FLUSHED:
  601. complete(&iwqp->sq_drained);
  602. break;
  603. case I40IW_CQP_COMPL_SQ_WQE_FLUSHED:
  604. complete(&iwqp->rq_drained);
  605. break;
  606. case I40IW_CQP_COMPL_RQ_SQ_WQE_FLUSHED:
  607. break;
  608. default:
  609. complete(&iwqp->sq_drained);
  610. complete(&iwqp->rq_drained);
  611. break;
  612. }
  613. }
  614. return 0;
  615. }
  616. /**
  617. * i40iw_gen_ae - generate AE
  618. * @iwdev: iwarp device
  619. * @qp: qp associated with AE
  620. * @info: info for ae
  621. * @wait: wait for completion
  622. */
  623. void i40iw_gen_ae(struct i40iw_device *iwdev,
  624. struct i40iw_sc_qp *qp,
  625. struct i40iw_gen_ae_info *info,
  626. bool wait)
  627. {
  628. struct i40iw_gen_ae_info *ae_info;
  629. struct i40iw_cqp_request *cqp_request;
  630. struct cqp_commands_info *cqp_info;
  631. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  632. if (!cqp_request)
  633. return;
  634. cqp_info = &cqp_request->info;
  635. ae_info = &cqp_request->info.in.u.gen_ae.info;
  636. memcpy(ae_info, info, sizeof(*ae_info));
  637. cqp_info->cqp_cmd = OP_GEN_AE;
  638. cqp_info->post_sq = 1;
  639. cqp_info->in.u.gen_ae.qp = qp;
  640. cqp_info->in.u.gen_ae.scratch = (uintptr_t)cqp_request;
  641. if (i40iw_handle_cqp_op(iwdev, cqp_request))
  642. i40iw_pr_err("CQP OP failed attempting to generate ae_code=0x%x\n",
  643. info->ae_code);
  644. }
  645. /**
  646. * i40iw_hw_manage_vf_pble_bp - manage vf pbles
  647. * @iwdev: iwarp device
  648. * @info: info for managing pble
  649. * @wait: flag wait for completion
  650. */
  651. enum i40iw_status_code i40iw_hw_manage_vf_pble_bp(struct i40iw_device *iwdev,
  652. struct i40iw_manage_vf_pble_info *info,
  653. bool wait)
  654. {
  655. enum i40iw_status_code status;
  656. struct i40iw_manage_vf_pble_info *hw_info;
  657. struct i40iw_cqp_request *cqp_request;
  658. struct cqp_commands_info *cqp_info;
  659. if ((iwdev->init_state < CCQ_CREATED) && wait)
  660. wait = false;
  661. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  662. if (!cqp_request)
  663. return I40IW_ERR_NO_MEMORY;
  664. cqp_info = &cqp_request->info;
  665. hw_info = &cqp_request->info.in.u.manage_vf_pble_bp.info;
  666. memcpy(hw_info, info, sizeof(*hw_info));
  667. cqp_info->cqp_cmd = OP_MANAGE_VF_PBLE_BP;
  668. cqp_info->post_sq = 1;
  669. cqp_info->in.u.manage_vf_pble_bp.cqp = &iwdev->cqp.sc_cqp;
  670. cqp_info->in.u.manage_vf_pble_bp.scratch = (uintptr_t)cqp_request;
  671. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  672. if (status)
  673. i40iw_pr_err("CQP-OP Manage VF pble_bp fail");
  674. return status;
  675. }
  676. /**
  677. * i40iw_get_ib_wc - return change flush code to IB's
  678. * @opcode: iwarp flush code
  679. */
  680. static enum ib_wc_status i40iw_get_ib_wc(enum i40iw_flush_opcode opcode)
  681. {
  682. switch (opcode) {
  683. case FLUSH_PROT_ERR:
  684. return IB_WC_LOC_PROT_ERR;
  685. case FLUSH_REM_ACCESS_ERR:
  686. return IB_WC_REM_ACCESS_ERR;
  687. case FLUSH_LOC_QP_OP_ERR:
  688. return IB_WC_LOC_QP_OP_ERR;
  689. case FLUSH_REM_OP_ERR:
  690. return IB_WC_REM_OP_ERR;
  691. case FLUSH_LOC_LEN_ERR:
  692. return IB_WC_LOC_LEN_ERR;
  693. case FLUSH_GENERAL_ERR:
  694. return IB_WC_GENERAL_ERR;
  695. case FLUSH_FATAL_ERR:
  696. default:
  697. return IB_WC_FATAL_ERR;
  698. }
  699. }
  700. /**
  701. * i40iw_set_flush_info - set flush info
  702. * @pinfo: set flush info
  703. * @min: minor err
  704. * @maj: major err
  705. * @opcode: flush error code
  706. */
  707. static void i40iw_set_flush_info(struct i40iw_qp_flush_info *pinfo,
  708. u16 *min,
  709. u16 *maj,
  710. enum i40iw_flush_opcode opcode)
  711. {
  712. *min = (u16)i40iw_get_ib_wc(opcode);
  713. *maj = CQE_MAJOR_DRV;
  714. pinfo->userflushcode = true;
  715. }
  716. /**
  717. * i40iw_flush_wqes - flush wqe for qp
  718. * @iwdev: iwarp device
  719. * @iwqp: qp to flush wqes
  720. */
  721. void i40iw_flush_wqes(struct i40iw_device *iwdev, struct i40iw_qp *iwqp)
  722. {
  723. struct i40iw_qp_flush_info info;
  724. struct i40iw_qp_flush_info *pinfo = &info;
  725. struct i40iw_sc_qp *qp = &iwqp->sc_qp;
  726. memset(pinfo, 0, sizeof(*pinfo));
  727. info.sq = true;
  728. info.rq = true;
  729. if (qp->term_flags) {
  730. i40iw_set_flush_info(pinfo, &pinfo->sq_minor_code,
  731. &pinfo->sq_major_code, qp->flush_code);
  732. i40iw_set_flush_info(pinfo, &pinfo->rq_minor_code,
  733. &pinfo->rq_major_code, qp->flush_code);
  734. }
  735. (void)i40iw_hw_flush_wqes(iwdev, &iwqp->sc_qp, &info, true);
  736. }