i40iw_hw.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. break;
  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. break;
  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_cqp_manage_abvpt_cmd - send cqp command manage abpvt
  403. * @iwdev: iwarp device
  404. * @accel_local_port: port for apbvt
  405. * @add_port: add or delete port
  406. */
  407. static enum i40iw_status_code
  408. i40iw_cqp_manage_abvpt_cmd(struct i40iw_device *iwdev,
  409. u16 accel_local_port,
  410. bool add_port)
  411. {
  412. struct i40iw_apbvt_info *info;
  413. struct i40iw_cqp_request *cqp_request;
  414. struct cqp_commands_info *cqp_info;
  415. enum i40iw_status_code status;
  416. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, add_port);
  417. if (!cqp_request)
  418. return I40IW_ERR_NO_MEMORY;
  419. cqp_info = &cqp_request->info;
  420. info = &cqp_info->in.u.manage_apbvt_entry.info;
  421. memset(info, 0, sizeof(*info));
  422. info->add = add_port;
  423. info->port = cpu_to_le16(accel_local_port);
  424. cqp_info->cqp_cmd = OP_MANAGE_APBVT_ENTRY;
  425. cqp_info->post_sq = 1;
  426. cqp_info->in.u.manage_apbvt_entry.cqp = &iwdev->cqp.sc_cqp;
  427. cqp_info->in.u.manage_apbvt_entry.scratch = (uintptr_t)cqp_request;
  428. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  429. if (status)
  430. i40iw_pr_err("CQP-OP Manage APBVT entry fail");
  431. return status;
  432. }
  433. /**
  434. * i40iw_manage_apbvt - add or delete tcp port
  435. * @iwdev: iwarp device
  436. * @accel_local_port: port for apbvt
  437. * @add_port: add or delete port
  438. */
  439. enum i40iw_status_code i40iw_manage_apbvt(struct i40iw_device *iwdev,
  440. u16 accel_local_port,
  441. bool add_port)
  442. {
  443. struct i40iw_cm_core *cm_core = &iwdev->cm_core;
  444. enum i40iw_status_code status;
  445. unsigned long flags;
  446. bool in_use;
  447. /* apbvt_lock is held across CQP delete APBVT OP (non-waiting) to
  448. * protect against race where add APBVT CQP can race ahead of the delete
  449. * APBVT for same port.
  450. */
  451. if (add_port) {
  452. spin_lock_irqsave(&cm_core->apbvt_lock, flags);
  453. in_use = __test_and_set_bit(accel_local_port,
  454. cm_core->ports_in_use);
  455. spin_unlock_irqrestore(&cm_core->apbvt_lock, flags);
  456. if (in_use)
  457. return 0;
  458. return i40iw_cqp_manage_abvpt_cmd(iwdev, accel_local_port,
  459. true);
  460. } else {
  461. spin_lock_irqsave(&cm_core->apbvt_lock, flags);
  462. in_use = i40iw_port_in_use(cm_core, accel_local_port);
  463. if (in_use) {
  464. spin_unlock_irqrestore(&cm_core->apbvt_lock, flags);
  465. return 0;
  466. }
  467. __clear_bit(accel_local_port, cm_core->ports_in_use);
  468. status = i40iw_cqp_manage_abvpt_cmd(iwdev, accel_local_port,
  469. false);
  470. spin_unlock_irqrestore(&cm_core->apbvt_lock, flags);
  471. return status;
  472. }
  473. }
  474. /**
  475. * i40iw_manage_arp_cache - manage hw arp cache
  476. * @iwdev: iwarp device
  477. * @mac_addr: mac address ptr
  478. * @ip_addr: ip addr for arp cache
  479. * @action: add, delete or modify
  480. */
  481. void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
  482. unsigned char *mac_addr,
  483. u32 *ip_addr,
  484. bool ipv4,
  485. u32 action)
  486. {
  487. struct i40iw_add_arp_cache_entry_info *info;
  488. struct i40iw_cqp_request *cqp_request;
  489. struct cqp_commands_info *cqp_info;
  490. int arp_index;
  491. arp_index = i40iw_arp_table(iwdev, ip_addr, ipv4, mac_addr, action);
  492. if (arp_index < 0)
  493. return;
  494. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, false);
  495. if (!cqp_request)
  496. return;
  497. cqp_info = &cqp_request->info;
  498. if (action == I40IW_ARP_ADD) {
  499. cqp_info->cqp_cmd = OP_ADD_ARP_CACHE_ENTRY;
  500. info = &cqp_info->in.u.add_arp_cache_entry.info;
  501. memset(info, 0, sizeof(*info));
  502. info->arp_index = cpu_to_le16((u16)arp_index);
  503. info->permanent = true;
  504. ether_addr_copy(info->mac_addr, mac_addr);
  505. cqp_info->in.u.add_arp_cache_entry.scratch = (uintptr_t)cqp_request;
  506. cqp_info->in.u.add_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
  507. } else {
  508. cqp_info->cqp_cmd = OP_DELETE_ARP_CACHE_ENTRY;
  509. cqp_info->in.u.del_arp_cache_entry.scratch = (uintptr_t)cqp_request;
  510. cqp_info->in.u.del_arp_cache_entry.cqp = &iwdev->cqp.sc_cqp;
  511. cqp_info->in.u.del_arp_cache_entry.arp_index = arp_index;
  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. * i40iw_send_syn_cqp_callback - do syn/ack after qhash
  521. * @cqp_request: qhash cqp completion
  522. * @send_ack: flag send ack
  523. */
  524. static void i40iw_send_syn_cqp_callback(struct i40iw_cqp_request *cqp_request, u32 send_ack)
  525. {
  526. i40iw_send_syn(cqp_request->param, send_ack);
  527. }
  528. /**
  529. * i40iw_manage_qhash - add or modify qhash
  530. * @iwdev: iwarp device
  531. * @cminfo: cm info for qhash
  532. * @etype: type (syn or quad)
  533. * @mtype: type of qhash
  534. * @cmnode: cmnode associated with connection
  535. * @wait: wait for completion
  536. * @user_pri:user pri of the connection
  537. */
  538. enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
  539. struct i40iw_cm_info *cminfo,
  540. enum i40iw_quad_entry_type etype,
  541. enum i40iw_quad_hash_manage_type mtype,
  542. void *cmnode,
  543. bool wait)
  544. {
  545. struct i40iw_qhash_table_info *info;
  546. struct i40iw_sc_dev *dev = &iwdev->sc_dev;
  547. struct i40iw_sc_vsi *vsi = &iwdev->vsi;
  548. enum i40iw_status_code status;
  549. struct i40iw_cqp *iwcqp = &iwdev->cqp;
  550. struct i40iw_cqp_request *cqp_request;
  551. struct cqp_commands_info *cqp_info;
  552. cqp_request = i40iw_get_cqp_request(iwcqp, wait);
  553. if (!cqp_request)
  554. return I40IW_ERR_NO_MEMORY;
  555. cqp_info = &cqp_request->info;
  556. info = &cqp_info->in.u.manage_qhash_table_entry.info;
  557. memset(info, 0, sizeof(*info));
  558. info->vsi = &iwdev->vsi;
  559. info->manage = mtype;
  560. info->entry_type = etype;
  561. if (cminfo->vlan_id != 0xFFFF) {
  562. info->vlan_valid = true;
  563. info->vlan_id = cpu_to_le16(cminfo->vlan_id);
  564. } else {
  565. info->vlan_valid = false;
  566. }
  567. info->ipv4_valid = cminfo->ipv4;
  568. info->user_pri = cminfo->user_pri;
  569. ether_addr_copy(info->mac_addr, iwdev->netdev->dev_addr);
  570. info->qp_num = cpu_to_le32(vsi->ilq->qp_id);
  571. info->dest_port = cpu_to_le16(cminfo->loc_port);
  572. info->dest_ip[0] = cpu_to_le32(cminfo->loc_addr[0]);
  573. info->dest_ip[1] = cpu_to_le32(cminfo->loc_addr[1]);
  574. info->dest_ip[2] = cpu_to_le32(cminfo->loc_addr[2]);
  575. info->dest_ip[3] = cpu_to_le32(cminfo->loc_addr[3]);
  576. if (etype == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
  577. info->src_port = cpu_to_le16(cminfo->rem_port);
  578. info->src_ip[0] = cpu_to_le32(cminfo->rem_addr[0]);
  579. info->src_ip[1] = cpu_to_le32(cminfo->rem_addr[1]);
  580. info->src_ip[2] = cpu_to_le32(cminfo->rem_addr[2]);
  581. info->src_ip[3] = cpu_to_le32(cminfo->rem_addr[3]);
  582. }
  583. if (cmnode) {
  584. cqp_request->callback_fcn = i40iw_send_syn_cqp_callback;
  585. cqp_request->param = (void *)cmnode;
  586. }
  587. if (info->ipv4_valid)
  588. i40iw_debug(dev, I40IW_DEBUG_CM,
  589. "%s:%s IP=%pI4, port=%d, mac=%pM, vlan_id=%d\n",
  590. __func__, (!mtype) ? "DELETE" : "ADD",
  591. info->dest_ip,
  592. info->dest_port, info->mac_addr, cminfo->vlan_id);
  593. else
  594. i40iw_debug(dev, I40IW_DEBUG_CM,
  595. "%s:%s IP=%pI6, 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. cqp_info->in.u.manage_qhash_table_entry.cqp = &iwdev->cqp.sc_cqp;
  600. cqp_info->in.u.manage_qhash_table_entry.scratch = (uintptr_t)cqp_request;
  601. cqp_info->cqp_cmd = OP_MANAGE_QHASH_TABLE_ENTRY;
  602. cqp_info->post_sq = 1;
  603. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  604. if (status)
  605. i40iw_pr_err("CQP-OP Manage Qhash Entry fail");
  606. return status;
  607. }
  608. /**
  609. * i40iw_hw_flush_wqes - flush qp's wqe
  610. * @iwdev: iwarp device
  611. * @qp: hardware control qp
  612. * @info: info for flush
  613. * @wait: flag wait for completion
  614. */
  615. enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
  616. struct i40iw_sc_qp *qp,
  617. struct i40iw_qp_flush_info *info,
  618. bool wait)
  619. {
  620. enum i40iw_status_code status;
  621. struct i40iw_qp_flush_info *hw_info;
  622. struct i40iw_cqp_request *cqp_request;
  623. struct cqp_commands_info *cqp_info;
  624. struct i40iw_qp *iwqp = (struct i40iw_qp *)qp->back_qp;
  625. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  626. if (!cqp_request)
  627. return I40IW_ERR_NO_MEMORY;
  628. cqp_info = &cqp_request->info;
  629. hw_info = &cqp_request->info.in.u.qp_flush_wqes.info;
  630. memcpy(hw_info, info, sizeof(*hw_info));
  631. cqp_info->cqp_cmd = OP_QP_FLUSH_WQES;
  632. cqp_info->post_sq = 1;
  633. cqp_info->in.u.qp_flush_wqes.qp = qp;
  634. cqp_info->in.u.qp_flush_wqes.scratch = (uintptr_t)cqp_request;
  635. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  636. if (status) {
  637. i40iw_pr_err("CQP-OP Flush WQE's fail");
  638. complete(&iwqp->sq_drained);
  639. complete(&iwqp->rq_drained);
  640. return status;
  641. }
  642. if (!cqp_request->compl_info.maj_err_code) {
  643. switch (cqp_request->compl_info.min_err_code) {
  644. case I40IW_CQP_COMPL_RQ_WQE_FLUSHED:
  645. complete(&iwqp->sq_drained);
  646. break;
  647. case I40IW_CQP_COMPL_SQ_WQE_FLUSHED:
  648. complete(&iwqp->rq_drained);
  649. break;
  650. case I40IW_CQP_COMPL_RQ_SQ_WQE_FLUSHED:
  651. break;
  652. default:
  653. complete(&iwqp->sq_drained);
  654. complete(&iwqp->rq_drained);
  655. break;
  656. }
  657. }
  658. return 0;
  659. }
  660. /**
  661. * i40iw_gen_ae - generate AE
  662. * @iwdev: iwarp device
  663. * @qp: qp associated with AE
  664. * @info: info for ae
  665. * @wait: wait for completion
  666. */
  667. void i40iw_gen_ae(struct i40iw_device *iwdev,
  668. struct i40iw_sc_qp *qp,
  669. struct i40iw_gen_ae_info *info,
  670. bool wait)
  671. {
  672. struct i40iw_gen_ae_info *ae_info;
  673. struct i40iw_cqp_request *cqp_request;
  674. struct cqp_commands_info *cqp_info;
  675. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  676. if (!cqp_request)
  677. return;
  678. cqp_info = &cqp_request->info;
  679. ae_info = &cqp_request->info.in.u.gen_ae.info;
  680. memcpy(ae_info, info, sizeof(*ae_info));
  681. cqp_info->cqp_cmd = OP_GEN_AE;
  682. cqp_info->post_sq = 1;
  683. cqp_info->in.u.gen_ae.qp = qp;
  684. cqp_info->in.u.gen_ae.scratch = (uintptr_t)cqp_request;
  685. if (i40iw_handle_cqp_op(iwdev, cqp_request))
  686. i40iw_pr_err("CQP OP failed attempting to generate ae_code=0x%x\n",
  687. info->ae_code);
  688. }
  689. /**
  690. * i40iw_hw_manage_vf_pble_bp - manage vf pbles
  691. * @iwdev: iwarp device
  692. * @info: info for managing pble
  693. * @wait: flag wait for completion
  694. */
  695. enum i40iw_status_code i40iw_hw_manage_vf_pble_bp(struct i40iw_device *iwdev,
  696. struct i40iw_manage_vf_pble_info *info,
  697. bool wait)
  698. {
  699. enum i40iw_status_code status;
  700. struct i40iw_manage_vf_pble_info *hw_info;
  701. struct i40iw_cqp_request *cqp_request;
  702. struct cqp_commands_info *cqp_info;
  703. if ((iwdev->init_state < CCQ_CREATED) && wait)
  704. wait = false;
  705. cqp_request = i40iw_get_cqp_request(&iwdev->cqp, wait);
  706. if (!cqp_request)
  707. return I40IW_ERR_NO_MEMORY;
  708. cqp_info = &cqp_request->info;
  709. hw_info = &cqp_request->info.in.u.manage_vf_pble_bp.info;
  710. memcpy(hw_info, info, sizeof(*hw_info));
  711. cqp_info->cqp_cmd = OP_MANAGE_VF_PBLE_BP;
  712. cqp_info->post_sq = 1;
  713. cqp_info->in.u.manage_vf_pble_bp.cqp = &iwdev->cqp.sc_cqp;
  714. cqp_info->in.u.manage_vf_pble_bp.scratch = (uintptr_t)cqp_request;
  715. status = i40iw_handle_cqp_op(iwdev, cqp_request);
  716. if (status)
  717. i40iw_pr_err("CQP-OP Manage VF pble_bp fail");
  718. return status;
  719. }
  720. /**
  721. * i40iw_get_ib_wc - return change flush code to IB's
  722. * @opcode: iwarp flush code
  723. */
  724. static enum ib_wc_status i40iw_get_ib_wc(enum i40iw_flush_opcode opcode)
  725. {
  726. switch (opcode) {
  727. case FLUSH_PROT_ERR:
  728. return IB_WC_LOC_PROT_ERR;
  729. case FLUSH_REM_ACCESS_ERR:
  730. return IB_WC_REM_ACCESS_ERR;
  731. case FLUSH_LOC_QP_OP_ERR:
  732. return IB_WC_LOC_QP_OP_ERR;
  733. case FLUSH_REM_OP_ERR:
  734. return IB_WC_REM_OP_ERR;
  735. case FLUSH_LOC_LEN_ERR:
  736. return IB_WC_LOC_LEN_ERR;
  737. case FLUSH_GENERAL_ERR:
  738. return IB_WC_GENERAL_ERR;
  739. case FLUSH_FATAL_ERR:
  740. default:
  741. return IB_WC_FATAL_ERR;
  742. }
  743. }
  744. /**
  745. * i40iw_set_flush_info - set flush info
  746. * @pinfo: set flush info
  747. * @min: minor err
  748. * @maj: major err
  749. * @opcode: flush error code
  750. */
  751. static void i40iw_set_flush_info(struct i40iw_qp_flush_info *pinfo,
  752. u16 *min,
  753. u16 *maj,
  754. enum i40iw_flush_opcode opcode)
  755. {
  756. *min = (u16)i40iw_get_ib_wc(opcode);
  757. *maj = CQE_MAJOR_DRV;
  758. pinfo->userflushcode = true;
  759. }
  760. /**
  761. * i40iw_flush_wqes - flush wqe for qp
  762. * @iwdev: iwarp device
  763. * @iwqp: qp to flush wqes
  764. */
  765. void i40iw_flush_wqes(struct i40iw_device *iwdev, struct i40iw_qp *iwqp)
  766. {
  767. struct i40iw_qp_flush_info info;
  768. struct i40iw_qp_flush_info *pinfo = &info;
  769. struct i40iw_sc_qp *qp = &iwqp->sc_qp;
  770. memset(pinfo, 0, sizeof(*pinfo));
  771. info.sq = true;
  772. info.rq = true;
  773. if (qp->term_flags) {
  774. i40iw_set_flush_info(pinfo, &pinfo->sq_minor_code,
  775. &pinfo->sq_major_code, qp->flush_code);
  776. i40iw_set_flush_info(pinfo, &pinfo->rq_minor_code,
  777. &pinfo->rq_major_code, qp->flush_code);
  778. }
  779. (void)i40iw_hw_flush_wqes(iwdev, &iwqp->sc_qp, &info, true);
  780. }