i40iw_virtchnl.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 "i40iw_osdep.h"
  35. #include "i40iw_register.h"
  36. #include "i40iw_status.h"
  37. #include "i40iw_hmc.h"
  38. #include "i40iw_d.h"
  39. #include "i40iw_type.h"
  40. #include "i40iw_p.h"
  41. #include "i40iw_virtchnl.h"
  42. /**
  43. * vchnl_vf_send_get_ver_req - Request Channel version
  44. * @dev: IWARP device pointer
  45. * @vchnl_req: Virtual channel message request pointer
  46. */
  47. static enum i40iw_status_code vchnl_vf_send_get_ver_req(struct i40iw_sc_dev *dev,
  48. struct i40iw_virtchnl_req *vchnl_req)
  49. {
  50. enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
  51. struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
  52. if (!dev->vchnl_up)
  53. return ret_code;
  54. memset(vchnl_msg, 0, sizeof(*vchnl_msg));
  55. vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
  56. vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg);
  57. vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_VER;
  58. vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_VER_V0;
  59. ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
  60. if (ret_code)
  61. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  62. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  63. return ret_code;
  64. }
  65. /**
  66. * vchnl_vf_send_get_hmc_fcn_req - Request HMC Function from VF
  67. * @dev: IWARP device pointer
  68. * @vchnl_req: Virtual channel message request pointer
  69. */
  70. static enum i40iw_status_code vchnl_vf_send_get_hmc_fcn_req(struct i40iw_sc_dev *dev,
  71. struct i40iw_virtchnl_req *vchnl_req)
  72. {
  73. enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
  74. struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
  75. if (!dev->vchnl_up)
  76. return ret_code;
  77. memset(vchnl_msg, 0, sizeof(*vchnl_msg));
  78. vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
  79. vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg);
  80. vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_HMC_FCN;
  81. vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_HMC_FCN_V0;
  82. ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
  83. if (ret_code)
  84. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  85. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  86. return ret_code;
  87. }
  88. /**
  89. * vchnl_vf_send_get_pe_stats_req - Request PE stats from VF
  90. * @dev: IWARP device pointer
  91. * @vchnl_req: Virtual channel message request pointer
  92. */
  93. static enum i40iw_status_code vchnl_vf_send_get_pe_stats_req(struct i40iw_sc_dev *dev,
  94. struct i40iw_virtchnl_req *vchnl_req)
  95. {
  96. enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
  97. struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
  98. if (!dev->vchnl_up)
  99. return ret_code;
  100. memset(vchnl_msg, 0, sizeof(*vchnl_msg));
  101. vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
  102. vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_dev_hw_stats) - 1;
  103. vchnl_msg->iw_op_code = I40IW_VCHNL_OP_GET_STATS;
  104. vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_GET_STATS_V0;
  105. ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
  106. if (ret_code)
  107. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  108. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  109. return ret_code;
  110. }
  111. /**
  112. * vchnl_vf_send_add_hmc_objs_req - Add HMC objects
  113. * @dev: IWARP device pointer
  114. * @vchnl_req: Virtual channel message request pointer
  115. */
  116. static enum i40iw_status_code vchnl_vf_send_add_hmc_objs_req(struct i40iw_sc_dev *dev,
  117. struct i40iw_virtchnl_req *vchnl_req,
  118. enum i40iw_hmc_rsrc_type rsrc_type,
  119. u32 start_index,
  120. u32 rsrc_count)
  121. {
  122. enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
  123. struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
  124. struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
  125. if (!dev->vchnl_up)
  126. return ret_code;
  127. add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
  128. memset(vchnl_msg, 0, sizeof(*vchnl_msg));
  129. memset(add_hmc_obj, 0, sizeof(*add_hmc_obj));
  130. vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
  131. vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_virtchnl_hmc_obj_range) - 1;
  132. vchnl_msg->iw_op_code = I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE;
  133. vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE_V0;
  134. add_hmc_obj->obj_type = (u16)rsrc_type;
  135. add_hmc_obj->start_index = start_index;
  136. add_hmc_obj->obj_count = rsrc_count;
  137. ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
  138. if (ret_code)
  139. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  140. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  141. return ret_code;
  142. }
  143. /**
  144. * vchnl_vf_send_del_hmc_objs_req - del HMC objects
  145. * @dev: IWARP device pointer
  146. * @vchnl_req: Virtual channel message request pointer
  147. * @ rsrc_type - resource type to delete
  148. * @ start_index - starting index for resource
  149. * @ rsrc_count - number of resource type to delete
  150. */
  151. static enum i40iw_status_code vchnl_vf_send_del_hmc_objs_req(struct i40iw_sc_dev *dev,
  152. struct i40iw_virtchnl_req *vchnl_req,
  153. enum i40iw_hmc_rsrc_type rsrc_type,
  154. u32 start_index,
  155. u32 rsrc_count)
  156. {
  157. enum i40iw_status_code ret_code = I40IW_ERR_NOT_READY;
  158. struct i40iw_virtchnl_op_buf *vchnl_msg = vchnl_req->vchnl_msg;
  159. struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
  160. if (!dev->vchnl_up)
  161. return ret_code;
  162. add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
  163. memset(vchnl_msg, 0, sizeof(*vchnl_msg));
  164. memset(add_hmc_obj, 0, sizeof(*add_hmc_obj));
  165. vchnl_msg->iw_chnl_op_ctx = (uintptr_t)vchnl_req;
  166. vchnl_msg->iw_chnl_buf_len = sizeof(*vchnl_msg) + sizeof(struct i40iw_virtchnl_hmc_obj_range) - 1;
  167. vchnl_msg->iw_op_code = I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE;
  168. vchnl_msg->iw_op_ver = I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE_V0;
  169. add_hmc_obj->obj_type = (u16)rsrc_type;
  170. add_hmc_obj->start_index = start_index;
  171. add_hmc_obj->obj_count = rsrc_count;
  172. ret_code = dev->vchnl_if.vchnl_send(dev, 0, (u8 *)vchnl_msg, vchnl_msg->iw_chnl_buf_len);
  173. if (ret_code)
  174. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  175. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  176. return ret_code;
  177. }
  178. /**
  179. * vchnl_pf_send_get_ver_resp - Send channel version to VF
  180. * @dev: IWARP device pointer
  181. * @vf_id: Virtual function ID associated with the message
  182. * @vchnl_msg: Virtual channel message buffer pointer
  183. */
  184. static void vchnl_pf_send_get_ver_resp(struct i40iw_sc_dev *dev,
  185. u32 vf_id,
  186. struct i40iw_virtchnl_op_buf *vchnl_msg)
  187. {
  188. enum i40iw_status_code ret_code;
  189. u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(u32) - 1];
  190. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
  191. memset(resp_buffer, 0, sizeof(*resp_buffer));
  192. vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
  193. vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
  194. vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
  195. *((u32 *)vchnl_msg_resp->iw_chnl_buf) = I40IW_VCHNL_CHNL_VER_V0;
  196. ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
  197. if (ret_code)
  198. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  199. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  200. }
  201. /**
  202. * vchnl_pf_send_get_hmc_fcn_resp - Send HMC Function to VF
  203. * @dev: IWARP device pointer
  204. * @vf_id: Virtual function ID associated with the message
  205. * @vchnl_msg: Virtual channel message buffer pointer
  206. */
  207. static void vchnl_pf_send_get_hmc_fcn_resp(struct i40iw_sc_dev *dev,
  208. u32 vf_id,
  209. struct i40iw_virtchnl_op_buf *vchnl_msg,
  210. u16 hmc_fcn)
  211. {
  212. enum i40iw_status_code ret_code;
  213. u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(u16) - 1];
  214. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
  215. memset(resp_buffer, 0, sizeof(*resp_buffer));
  216. vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
  217. vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
  218. vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
  219. *((u16 *)vchnl_msg_resp->iw_chnl_buf) = hmc_fcn;
  220. ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
  221. if (ret_code)
  222. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  223. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  224. }
  225. /**
  226. * vchnl_pf_send_get_pe_stats_resp - Send PE Stats to VF
  227. * @dev: IWARP device pointer
  228. * @vf_id: Virtual function ID associated with the message
  229. * @vchnl_msg: Virtual channel message buffer pointer
  230. * @hw_stats: HW Stats struct
  231. */
  232. static void vchnl_pf_send_get_pe_stats_resp(struct i40iw_sc_dev *dev,
  233. u32 vf_id,
  234. struct i40iw_virtchnl_op_buf *vchnl_msg,
  235. struct i40iw_dev_hw_stats *hw_stats)
  236. {
  237. enum i40iw_status_code ret_code;
  238. u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf) + sizeof(struct i40iw_dev_hw_stats) - 1];
  239. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
  240. memset(resp_buffer, 0, sizeof(*resp_buffer));
  241. vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
  242. vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
  243. vchnl_msg_resp->iw_op_ret_code = I40IW_SUCCESS;
  244. *((struct i40iw_dev_hw_stats *)vchnl_msg_resp->iw_chnl_buf) = *hw_stats;
  245. ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
  246. if (ret_code)
  247. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  248. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  249. }
  250. /**
  251. * vchnl_pf_send_error_resp - Send an error response to VF
  252. * @dev: IWARP device pointer
  253. * @vf_id: Virtual function ID associated with the message
  254. * @vchnl_msg: Virtual channel message buffer pointer
  255. */
  256. static void vchnl_pf_send_error_resp(struct i40iw_sc_dev *dev, u32 vf_id,
  257. struct i40iw_virtchnl_op_buf *vchnl_msg,
  258. u16 op_ret_code)
  259. {
  260. enum i40iw_status_code ret_code;
  261. u8 resp_buffer[sizeof(struct i40iw_virtchnl_resp_buf)];
  262. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)resp_buffer;
  263. memset(resp_buffer, 0, sizeof(resp_buffer));
  264. vchnl_msg_resp->iw_chnl_op_ctx = vchnl_msg->iw_chnl_op_ctx;
  265. vchnl_msg_resp->iw_chnl_buf_len = sizeof(resp_buffer);
  266. vchnl_msg_resp->iw_op_ret_code = (u16)op_ret_code;
  267. ret_code = dev->vchnl_if.vchnl_send(dev, vf_id, resp_buffer, sizeof(resp_buffer));
  268. if (ret_code)
  269. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  270. "%s: virt channel send failed 0x%x\n", __func__, ret_code);
  271. }
  272. /**
  273. * pf_cqp_get_hmc_fcn_callback - Callback for Get HMC Fcn
  274. * @cqp_req_param: CQP Request param value
  275. * @not_used: unused CQP callback parameter
  276. */
  277. static void pf_cqp_get_hmc_fcn_callback(struct i40iw_sc_dev *dev, void *callback_param,
  278. struct i40iw_ccq_cqe_info *cqe_info)
  279. {
  280. struct i40iw_vfdev *vf_dev = callback_param;
  281. struct i40iw_virt_mem vf_dev_mem;
  282. if (cqe_info->error) {
  283. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  284. "CQP Completion Error on Get HMC Function. Maj = 0x%04x, Minor = 0x%04x\n",
  285. cqe_info->maj_err_code, cqe_info->min_err_code);
  286. dev->vf_dev[vf_dev->iw_vf_idx] = NULL;
  287. vchnl_pf_send_error_resp(dev, vf_dev->vf_id, &vf_dev->vf_msg_buffer.vchnl_msg,
  288. (u16)I40IW_ERR_CQP_COMPL_ERROR);
  289. vf_dev_mem.va = vf_dev;
  290. vf_dev_mem.size = sizeof(*vf_dev);
  291. i40iw_free_virt_mem(dev->hw, &vf_dev_mem);
  292. } else {
  293. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  294. "CQP Completion Operation Return information = 0x%08x\n",
  295. cqe_info->op_ret_val);
  296. vf_dev->pmf_index = (u16)cqe_info->op_ret_val;
  297. vf_dev->msg_count--;
  298. vchnl_pf_send_get_hmc_fcn_resp(dev,
  299. vf_dev->vf_id,
  300. &vf_dev->vf_msg_buffer.vchnl_msg,
  301. vf_dev->pmf_index);
  302. }
  303. }
  304. /**
  305. * pf_add_hmc_obj - Callback for Add HMC Object
  306. * @vf_dev: pointer to the VF Device
  307. */
  308. static void pf_add_hmc_obj_callback(void *work_vf_dev)
  309. {
  310. struct i40iw_vfdev *vf_dev = (struct i40iw_vfdev *)work_vf_dev;
  311. struct i40iw_hmc_info *hmc_info = &vf_dev->hmc_info;
  312. struct i40iw_virtchnl_op_buf *vchnl_msg = &vf_dev->vf_msg_buffer.vchnl_msg;
  313. struct i40iw_hmc_create_obj_info info;
  314. struct i40iw_virtchnl_hmc_obj_range *add_hmc_obj;
  315. enum i40iw_status_code ret_code;
  316. if (!vf_dev->pf_hmc_initialized) {
  317. ret_code = i40iw_pf_init_vfhmc(vf_dev->pf_dev, (u8)vf_dev->pmf_index, NULL);
  318. if (ret_code)
  319. goto add_out;
  320. vf_dev->pf_hmc_initialized = true;
  321. }
  322. add_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
  323. memset(&info, 0, sizeof(info));
  324. info.hmc_info = hmc_info;
  325. info.is_pf = false;
  326. info.rsrc_type = (u32)add_hmc_obj->obj_type;
  327. info.entry_type = (info.rsrc_type == I40IW_HMC_IW_PBLE) ? I40IW_SD_TYPE_PAGED : I40IW_SD_TYPE_DIRECT;
  328. info.start_idx = add_hmc_obj->start_index;
  329. info.count = add_hmc_obj->obj_count;
  330. i40iw_debug(vf_dev->pf_dev, I40IW_DEBUG_VIRT,
  331. "I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE. Add %u type %u objects\n",
  332. info.count, info.rsrc_type);
  333. ret_code = i40iw_sc_create_hmc_obj(vf_dev->pf_dev, &info);
  334. if (!ret_code)
  335. vf_dev->hmc_info.hmc_obj[add_hmc_obj->obj_type].cnt = add_hmc_obj->obj_count;
  336. add_out:
  337. vf_dev->msg_count--;
  338. vchnl_pf_send_error_resp(vf_dev->pf_dev, vf_dev->vf_id, vchnl_msg, (u16)ret_code);
  339. }
  340. /**
  341. * pf_del_hmc_obj_callback - Callback for delete HMC Object
  342. * @work_vf_dev: pointer to the VF Device
  343. */
  344. static void pf_del_hmc_obj_callback(void *work_vf_dev)
  345. {
  346. struct i40iw_vfdev *vf_dev = (struct i40iw_vfdev *)work_vf_dev;
  347. struct i40iw_hmc_info *hmc_info = &vf_dev->hmc_info;
  348. struct i40iw_virtchnl_op_buf *vchnl_msg = &vf_dev->vf_msg_buffer.vchnl_msg;
  349. struct i40iw_hmc_del_obj_info info;
  350. struct i40iw_virtchnl_hmc_obj_range *del_hmc_obj;
  351. enum i40iw_status_code ret_code = I40IW_SUCCESS;
  352. if (!vf_dev->pf_hmc_initialized)
  353. goto del_out;
  354. del_hmc_obj = (struct i40iw_virtchnl_hmc_obj_range *)vchnl_msg->iw_chnl_buf;
  355. memset(&info, 0, sizeof(info));
  356. info.hmc_info = hmc_info;
  357. info.is_pf = false;
  358. info.rsrc_type = (u32)del_hmc_obj->obj_type;
  359. info.start_idx = del_hmc_obj->start_index;
  360. info.count = del_hmc_obj->obj_count;
  361. i40iw_debug(vf_dev->pf_dev, I40IW_DEBUG_VIRT,
  362. "I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE. Delete %u type %u objects\n",
  363. info.count, info.rsrc_type);
  364. ret_code = i40iw_sc_del_hmc_obj(vf_dev->pf_dev, &info, false);
  365. del_out:
  366. vf_dev->msg_count--;
  367. vchnl_pf_send_error_resp(vf_dev->pf_dev, vf_dev->vf_id, vchnl_msg, (u16)ret_code);
  368. }
  369. /**
  370. * i40iw_vf_init_pestat - Initialize stats for VF
  371. * @devL pointer to the VF Device
  372. * @stats: Statistics structure pointer
  373. * @index: Stats index
  374. */
  375. static void i40iw_vf_init_pestat(struct i40iw_sc_dev *dev, struct i40iw_vsi_pestat *stats, u16 index)
  376. {
  377. stats->hw = dev->hw;
  378. i40iw_hw_stats_init(stats, (u8)index, false);
  379. spin_lock_init(&stats->lock);
  380. }
  381. /**
  382. * i40iw_vchnl_recv_pf - Receive PF virtual channel messages
  383. * @dev: IWARP device pointer
  384. * @vf_id: Virtual function ID associated with the message
  385. * @msg: Virtual channel message buffer pointer
  386. * @len: Length of the virtual channels message
  387. */
  388. enum i40iw_status_code i40iw_vchnl_recv_pf(struct i40iw_sc_dev *dev,
  389. u32 vf_id,
  390. u8 *msg,
  391. u16 len)
  392. {
  393. struct i40iw_virtchnl_op_buf *vchnl_msg = (struct i40iw_virtchnl_op_buf *)msg;
  394. struct i40iw_vfdev *vf_dev = NULL;
  395. struct i40iw_hmc_fcn_info hmc_fcn_info;
  396. u16 iw_vf_idx;
  397. u16 first_avail_iw_vf = I40IW_MAX_PE_ENABLED_VF_COUNT;
  398. struct i40iw_virt_mem vf_dev_mem;
  399. struct i40iw_virtchnl_work_info work_info;
  400. struct i40iw_vsi_pestat *stats;
  401. enum i40iw_status_code ret_code;
  402. if (!dev || !msg || !len)
  403. return I40IW_ERR_PARAM;
  404. if (!dev->vchnl_up)
  405. return I40IW_ERR_NOT_READY;
  406. if (vchnl_msg->iw_op_code == I40IW_VCHNL_OP_GET_VER) {
  407. vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
  408. return I40IW_SUCCESS;
  409. }
  410. for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {
  411. if (!dev->vf_dev[iw_vf_idx]) {
  412. if (first_avail_iw_vf == I40IW_MAX_PE_ENABLED_VF_COUNT)
  413. first_avail_iw_vf = iw_vf_idx;
  414. continue;
  415. }
  416. if (dev->vf_dev[iw_vf_idx]->vf_id == vf_id) {
  417. vf_dev = dev->vf_dev[iw_vf_idx];
  418. break;
  419. }
  420. }
  421. if (vf_dev) {
  422. if (!vf_dev->msg_count) {
  423. vf_dev->msg_count++;
  424. } else {
  425. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  426. "VF%u already has a channel message in progress.\n",
  427. vf_id);
  428. return I40IW_SUCCESS;
  429. }
  430. }
  431. switch (vchnl_msg->iw_op_code) {
  432. case I40IW_VCHNL_OP_GET_HMC_FCN:
  433. if (!vf_dev &&
  434. (first_avail_iw_vf != I40IW_MAX_PE_ENABLED_VF_COUNT)) {
  435. ret_code = i40iw_allocate_virt_mem(dev->hw, &vf_dev_mem, sizeof(struct i40iw_vfdev) +
  436. (sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX));
  437. if (!ret_code) {
  438. vf_dev = vf_dev_mem.va;
  439. vf_dev->stats_initialized = false;
  440. vf_dev->pf_dev = dev;
  441. vf_dev->msg_count = 1;
  442. vf_dev->vf_id = vf_id;
  443. vf_dev->iw_vf_idx = first_avail_iw_vf;
  444. vf_dev->pf_hmc_initialized = false;
  445. vf_dev->hmc_info.hmc_obj = (struct i40iw_hmc_obj_info *)(&vf_dev[1]);
  446. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  447. "vf_dev %p, hmc_info %p, hmc_obj %p\n",
  448. vf_dev, &vf_dev->hmc_info, vf_dev->hmc_info.hmc_obj);
  449. dev->vf_dev[first_avail_iw_vf] = vf_dev;
  450. iw_vf_idx = first_avail_iw_vf;
  451. } else {
  452. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  453. "VF%u Unable to allocate a VF device structure.\n",
  454. vf_id);
  455. vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg, (u16)I40IW_ERR_NO_MEMORY);
  456. return I40IW_SUCCESS;
  457. }
  458. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  459. hmc_fcn_info.callback_fcn = pf_cqp_get_hmc_fcn_callback;
  460. hmc_fcn_info.vf_id = vf_id;
  461. hmc_fcn_info.iw_vf_idx = vf_dev->iw_vf_idx;
  462. hmc_fcn_info.cqp_callback_param = vf_dev;
  463. hmc_fcn_info.free_fcn = false;
  464. ret_code = i40iw_cqp_manage_hmc_fcn_cmd(dev, &hmc_fcn_info);
  465. if (ret_code)
  466. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  467. "VF%u error CQP HMC Function operation.\n",
  468. vf_id);
  469. i40iw_vf_init_pestat(dev, &vf_dev->pestat, vf_dev->pmf_index);
  470. vf_dev->stats_initialized = true;
  471. } else {
  472. if (vf_dev) {
  473. vf_dev->msg_count--;
  474. vchnl_pf_send_get_hmc_fcn_resp(dev, vf_id, vchnl_msg, vf_dev->pmf_index);
  475. } else {
  476. vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg,
  477. (u16)I40IW_ERR_NO_MEMORY);
  478. }
  479. }
  480. break;
  481. case I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE:
  482. if (!vf_dev)
  483. return I40IW_ERR_BAD_PTR;
  484. work_info.worker_vf_dev = vf_dev;
  485. work_info.callback_fcn = pf_add_hmc_obj_callback;
  486. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  487. i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
  488. break;
  489. case I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE:
  490. if (!vf_dev)
  491. return I40IW_ERR_BAD_PTR;
  492. work_info.worker_vf_dev = vf_dev;
  493. work_info.callback_fcn = pf_del_hmc_obj_callback;
  494. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  495. i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
  496. break;
  497. case I40IW_VCHNL_OP_GET_STATS:
  498. if (!vf_dev)
  499. return I40IW_ERR_BAD_PTR;
  500. stats = &vf_dev->pestat;
  501. i40iw_hw_stats_read_all(stats, &stats->hw_stats);
  502. vf_dev->msg_count--;
  503. vchnl_pf_send_get_pe_stats_resp(dev, vf_id, vchnl_msg, &stats->hw_stats);
  504. break;
  505. default:
  506. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  507. "40iw_vchnl_recv_pf: Invalid OpCode 0x%x\n",
  508. vchnl_msg->iw_op_code);
  509. vchnl_pf_send_error_resp(dev, vf_id,
  510. vchnl_msg, (u16)I40IW_ERR_NOT_IMPLEMENTED);
  511. }
  512. return I40IW_SUCCESS;
  513. }
  514. /**
  515. * i40iw_vchnl_recv_vf - Receive VF virtual channel messages
  516. * @dev: IWARP device pointer
  517. * @vf_id: Virtual function ID associated with the message
  518. * @msg: Virtual channel message buffer pointer
  519. * @len: Length of the virtual channels message
  520. */
  521. enum i40iw_status_code i40iw_vchnl_recv_vf(struct i40iw_sc_dev *dev,
  522. u32 vf_id,
  523. u8 *msg,
  524. u16 len)
  525. {
  526. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)msg;
  527. struct i40iw_virtchnl_req *vchnl_req;
  528. vchnl_req = (struct i40iw_virtchnl_req *)(uintptr_t)vchnl_msg_resp->iw_chnl_op_ctx;
  529. vchnl_req->ret_code = (enum i40iw_status_code)vchnl_msg_resp->iw_op_ret_code;
  530. if (len == (sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1)) {
  531. if (vchnl_req->parm_len && vchnl_req->parm)
  532. memcpy(vchnl_req->parm, vchnl_msg_resp->iw_chnl_buf, vchnl_req->parm_len);
  533. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  534. "%s: Got response, data size %u\n", __func__,
  535. vchnl_req->parm_len);
  536. } else {
  537. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  538. "%s: error length on response, Got %u, expected %u\n", __func__,
  539. len, (u32)(sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1));
  540. }
  541. return I40IW_SUCCESS;
  542. }
  543. /**
  544. * i40iw_vchnl_vf_get_ver - Request Channel version
  545. * @dev: IWARP device pointer
  546. * @vchnl_ver: Virtual channel message version pointer
  547. */
  548. enum i40iw_status_code i40iw_vchnl_vf_get_ver(struct i40iw_sc_dev *dev,
  549. u32 *vchnl_ver)
  550. {
  551. struct i40iw_virtchnl_req vchnl_req;
  552. enum i40iw_status_code ret_code;
  553. if (!i40iw_vf_clear_to_send(dev))
  554. return I40IW_ERR_TIMEOUT;
  555. memset(&vchnl_req, 0, sizeof(vchnl_req));
  556. vchnl_req.dev = dev;
  557. vchnl_req.parm = vchnl_ver;
  558. vchnl_req.parm_len = sizeof(*vchnl_ver);
  559. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  560. ret_code = vchnl_vf_send_get_ver_req(dev, &vchnl_req);
  561. if (ret_code) {
  562. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  563. "%s Send message failed 0x%0x\n", __func__, ret_code);
  564. return ret_code;
  565. }
  566. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  567. if (ret_code)
  568. return ret_code;
  569. else
  570. return vchnl_req.ret_code;
  571. }
  572. /**
  573. * i40iw_vchnl_vf_get_hmc_fcn - Request HMC Function
  574. * @dev: IWARP device pointer
  575. * @hmc_fcn: HMC function index pointer
  576. */
  577. enum i40iw_status_code i40iw_vchnl_vf_get_hmc_fcn(struct i40iw_sc_dev *dev,
  578. u16 *hmc_fcn)
  579. {
  580. struct i40iw_virtchnl_req vchnl_req;
  581. enum i40iw_status_code ret_code;
  582. if (!i40iw_vf_clear_to_send(dev))
  583. return I40IW_ERR_TIMEOUT;
  584. memset(&vchnl_req, 0, sizeof(vchnl_req));
  585. vchnl_req.dev = dev;
  586. vchnl_req.parm = hmc_fcn;
  587. vchnl_req.parm_len = sizeof(*hmc_fcn);
  588. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  589. ret_code = vchnl_vf_send_get_hmc_fcn_req(dev, &vchnl_req);
  590. if (ret_code) {
  591. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  592. "%s Send message failed 0x%0x\n", __func__, ret_code);
  593. return ret_code;
  594. }
  595. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  596. if (ret_code)
  597. return ret_code;
  598. else
  599. return vchnl_req.ret_code;
  600. }
  601. /**
  602. * i40iw_vchnl_vf_add_hmc_objs - Add HMC Object
  603. * @dev: IWARP device pointer
  604. * @rsrc_type: HMC Resource type
  605. * @start_index: Starting index of the objects to be added
  606. * @rsrc_count: Number of resources to be added
  607. */
  608. enum i40iw_status_code i40iw_vchnl_vf_add_hmc_objs(struct i40iw_sc_dev *dev,
  609. enum i40iw_hmc_rsrc_type rsrc_type,
  610. u32 start_index,
  611. u32 rsrc_count)
  612. {
  613. struct i40iw_virtchnl_req vchnl_req;
  614. enum i40iw_status_code ret_code;
  615. if (!i40iw_vf_clear_to_send(dev))
  616. return I40IW_ERR_TIMEOUT;
  617. memset(&vchnl_req, 0, sizeof(vchnl_req));
  618. vchnl_req.dev = dev;
  619. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  620. ret_code = vchnl_vf_send_add_hmc_objs_req(dev,
  621. &vchnl_req,
  622. rsrc_type,
  623. start_index,
  624. rsrc_count);
  625. if (ret_code) {
  626. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  627. "%s Send message failed 0x%0x\n", __func__, ret_code);
  628. return ret_code;
  629. }
  630. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  631. if (ret_code)
  632. return ret_code;
  633. else
  634. return vchnl_req.ret_code;
  635. }
  636. /**
  637. * i40iw_vchnl_vf_del_hmc_obj - del HMC obj
  638. * @dev: IWARP device pointer
  639. * @rsrc_type: HMC Resource type
  640. * @start_index: Starting index of the object to delete
  641. * @rsrc_count: Number of resources to be delete
  642. */
  643. enum i40iw_status_code i40iw_vchnl_vf_del_hmc_obj(struct i40iw_sc_dev *dev,
  644. enum i40iw_hmc_rsrc_type rsrc_type,
  645. u32 start_index,
  646. u32 rsrc_count)
  647. {
  648. struct i40iw_virtchnl_req vchnl_req;
  649. enum i40iw_status_code ret_code;
  650. if (!i40iw_vf_clear_to_send(dev))
  651. return I40IW_ERR_TIMEOUT;
  652. memset(&vchnl_req, 0, sizeof(vchnl_req));
  653. vchnl_req.dev = dev;
  654. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  655. ret_code = vchnl_vf_send_del_hmc_objs_req(dev,
  656. &vchnl_req,
  657. rsrc_type,
  658. start_index,
  659. rsrc_count);
  660. if (ret_code) {
  661. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  662. "%s Send message failed 0x%0x\n", __func__, ret_code);
  663. return ret_code;
  664. }
  665. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  666. if (ret_code)
  667. return ret_code;
  668. else
  669. return vchnl_req.ret_code;
  670. }
  671. /**
  672. * i40iw_vchnl_vf_get_pe_stats - Get PE stats
  673. * @dev: IWARP device pointer
  674. * @hw_stats: HW stats struct
  675. */
  676. enum i40iw_status_code i40iw_vchnl_vf_get_pe_stats(struct i40iw_sc_dev *dev,
  677. struct i40iw_dev_hw_stats *hw_stats)
  678. {
  679. struct i40iw_virtchnl_req vchnl_req;
  680. enum i40iw_status_code ret_code;
  681. if (!i40iw_vf_clear_to_send(dev))
  682. return I40IW_ERR_TIMEOUT;
  683. memset(&vchnl_req, 0, sizeof(vchnl_req));
  684. vchnl_req.dev = dev;
  685. vchnl_req.parm = hw_stats;
  686. vchnl_req.parm_len = sizeof(*hw_stats);
  687. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  688. ret_code = vchnl_vf_send_get_pe_stats_req(dev, &vchnl_req);
  689. if (ret_code) {
  690. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  691. "%s Send message failed 0x%0x\n", __func__, ret_code);
  692. return ret_code;
  693. }
  694. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  695. if (ret_code)
  696. return ret_code;
  697. else
  698. return vchnl_req.ret_code;
  699. }