i40iw_virtchnl.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. if (vchnl_msg->iw_op_ver != I40IW_VCHNL_OP_GET_VER_V0)
  408. vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
  409. else
  410. vchnl_pf_send_get_ver_resp(dev, vf_id, vchnl_msg);
  411. return I40IW_SUCCESS;
  412. }
  413. for (iw_vf_idx = 0; iw_vf_idx < I40IW_MAX_PE_ENABLED_VF_COUNT; iw_vf_idx++) {
  414. if (!dev->vf_dev[iw_vf_idx]) {
  415. if (first_avail_iw_vf == I40IW_MAX_PE_ENABLED_VF_COUNT)
  416. first_avail_iw_vf = iw_vf_idx;
  417. continue;
  418. }
  419. if (dev->vf_dev[iw_vf_idx]->vf_id == vf_id) {
  420. vf_dev = dev->vf_dev[iw_vf_idx];
  421. break;
  422. }
  423. }
  424. if (vf_dev) {
  425. if (!vf_dev->msg_count) {
  426. vf_dev->msg_count++;
  427. } else {
  428. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  429. "VF%u already has a channel message in progress.\n",
  430. vf_id);
  431. return I40IW_SUCCESS;
  432. }
  433. }
  434. switch (vchnl_msg->iw_op_code) {
  435. case I40IW_VCHNL_OP_GET_HMC_FCN:
  436. if (!vf_dev &&
  437. (first_avail_iw_vf != I40IW_MAX_PE_ENABLED_VF_COUNT)) {
  438. ret_code = i40iw_allocate_virt_mem(dev->hw, &vf_dev_mem, sizeof(struct i40iw_vfdev) +
  439. (sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX));
  440. if (!ret_code) {
  441. vf_dev = vf_dev_mem.va;
  442. vf_dev->stats_initialized = false;
  443. vf_dev->pf_dev = dev;
  444. vf_dev->msg_count = 1;
  445. vf_dev->vf_id = vf_id;
  446. vf_dev->iw_vf_idx = first_avail_iw_vf;
  447. vf_dev->pf_hmc_initialized = false;
  448. vf_dev->hmc_info.hmc_obj = (struct i40iw_hmc_obj_info *)(&vf_dev[1]);
  449. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  450. "vf_dev %p, hmc_info %p, hmc_obj %p\n",
  451. vf_dev, &vf_dev->hmc_info, vf_dev->hmc_info.hmc_obj);
  452. dev->vf_dev[first_avail_iw_vf] = vf_dev;
  453. iw_vf_idx = first_avail_iw_vf;
  454. } else {
  455. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  456. "VF%u Unable to allocate a VF device structure.\n",
  457. vf_id);
  458. vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg, (u16)I40IW_ERR_NO_MEMORY);
  459. return I40IW_SUCCESS;
  460. }
  461. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  462. hmc_fcn_info.callback_fcn = pf_cqp_get_hmc_fcn_callback;
  463. hmc_fcn_info.vf_id = vf_id;
  464. hmc_fcn_info.iw_vf_idx = vf_dev->iw_vf_idx;
  465. hmc_fcn_info.cqp_callback_param = vf_dev;
  466. hmc_fcn_info.free_fcn = false;
  467. ret_code = i40iw_cqp_manage_hmc_fcn_cmd(dev, &hmc_fcn_info);
  468. if (ret_code)
  469. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  470. "VF%u error CQP HMC Function operation.\n",
  471. vf_id);
  472. i40iw_vf_init_pestat(dev, &vf_dev->pestat, vf_dev->pmf_index);
  473. vf_dev->stats_initialized = true;
  474. } else {
  475. if (vf_dev) {
  476. vf_dev->msg_count--;
  477. vchnl_pf_send_get_hmc_fcn_resp(dev, vf_id, vchnl_msg, vf_dev->pmf_index);
  478. } else {
  479. vchnl_pf_send_error_resp(dev, vf_id, vchnl_msg,
  480. (u16)I40IW_ERR_NO_MEMORY);
  481. }
  482. }
  483. break;
  484. case I40IW_VCHNL_OP_ADD_HMC_OBJ_RANGE:
  485. if (!vf_dev)
  486. return I40IW_ERR_BAD_PTR;
  487. work_info.worker_vf_dev = vf_dev;
  488. work_info.callback_fcn = pf_add_hmc_obj_callback;
  489. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  490. i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
  491. break;
  492. case I40IW_VCHNL_OP_DEL_HMC_OBJ_RANGE:
  493. if (!vf_dev)
  494. return I40IW_ERR_BAD_PTR;
  495. work_info.worker_vf_dev = vf_dev;
  496. work_info.callback_fcn = pf_del_hmc_obj_callback;
  497. memcpy(&vf_dev->vf_msg_buffer.vchnl_msg, vchnl_msg, len);
  498. i40iw_cqp_spawn_worker(dev, &work_info, vf_dev->iw_vf_idx);
  499. break;
  500. case I40IW_VCHNL_OP_GET_STATS:
  501. if (!vf_dev)
  502. return I40IW_ERR_BAD_PTR;
  503. stats = &vf_dev->pestat;
  504. i40iw_hw_stats_read_all(stats, &stats->hw_stats);
  505. vf_dev->msg_count--;
  506. vchnl_pf_send_get_pe_stats_resp(dev, vf_id, vchnl_msg, &stats->hw_stats);
  507. break;
  508. default:
  509. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  510. "40iw_vchnl_recv_pf: Invalid OpCode 0x%x\n",
  511. vchnl_msg->iw_op_code);
  512. vchnl_pf_send_error_resp(dev, vf_id,
  513. vchnl_msg, (u16)I40IW_ERR_NOT_IMPLEMENTED);
  514. }
  515. return I40IW_SUCCESS;
  516. }
  517. /**
  518. * i40iw_vchnl_recv_vf - Receive VF virtual channel messages
  519. * @dev: IWARP device pointer
  520. * @vf_id: Virtual function ID associated with the message
  521. * @msg: Virtual channel message buffer pointer
  522. * @len: Length of the virtual channels message
  523. */
  524. enum i40iw_status_code i40iw_vchnl_recv_vf(struct i40iw_sc_dev *dev,
  525. u32 vf_id,
  526. u8 *msg,
  527. u16 len)
  528. {
  529. struct i40iw_virtchnl_resp_buf *vchnl_msg_resp = (struct i40iw_virtchnl_resp_buf *)msg;
  530. struct i40iw_virtchnl_req *vchnl_req;
  531. vchnl_req = (struct i40iw_virtchnl_req *)(uintptr_t)vchnl_msg_resp->iw_chnl_op_ctx;
  532. vchnl_req->ret_code = (enum i40iw_status_code)vchnl_msg_resp->iw_op_ret_code;
  533. if (len == (sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1)) {
  534. if (vchnl_req->parm_len && vchnl_req->parm)
  535. memcpy(vchnl_req->parm, vchnl_msg_resp->iw_chnl_buf, vchnl_req->parm_len);
  536. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  537. "%s: Got response, data size %u\n", __func__,
  538. vchnl_req->parm_len);
  539. } else {
  540. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  541. "%s: error length on response, Got %u, expected %u\n", __func__,
  542. len, (u32)(sizeof(*vchnl_msg_resp) + vchnl_req->parm_len - 1));
  543. }
  544. return I40IW_SUCCESS;
  545. }
  546. /**
  547. * i40iw_vchnl_vf_get_ver - Request Channel version
  548. * @dev: IWARP device pointer
  549. * @vchnl_ver: Virtual channel message version pointer
  550. */
  551. enum i40iw_status_code i40iw_vchnl_vf_get_ver(struct i40iw_sc_dev *dev,
  552. u32 *vchnl_ver)
  553. {
  554. struct i40iw_virtchnl_req vchnl_req;
  555. enum i40iw_status_code ret_code;
  556. if (!i40iw_vf_clear_to_send(dev))
  557. return I40IW_ERR_TIMEOUT;
  558. memset(&vchnl_req, 0, sizeof(vchnl_req));
  559. vchnl_req.dev = dev;
  560. vchnl_req.parm = vchnl_ver;
  561. vchnl_req.parm_len = sizeof(*vchnl_ver);
  562. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  563. ret_code = vchnl_vf_send_get_ver_req(dev, &vchnl_req);
  564. if (ret_code) {
  565. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  566. "%s Send message failed 0x%0x\n", __func__, ret_code);
  567. return ret_code;
  568. }
  569. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  570. if (ret_code)
  571. return ret_code;
  572. else
  573. return vchnl_req.ret_code;
  574. }
  575. /**
  576. * i40iw_vchnl_vf_get_hmc_fcn - Request HMC Function
  577. * @dev: IWARP device pointer
  578. * @hmc_fcn: HMC function index pointer
  579. */
  580. enum i40iw_status_code i40iw_vchnl_vf_get_hmc_fcn(struct i40iw_sc_dev *dev,
  581. u16 *hmc_fcn)
  582. {
  583. struct i40iw_virtchnl_req vchnl_req;
  584. enum i40iw_status_code ret_code;
  585. if (!i40iw_vf_clear_to_send(dev))
  586. return I40IW_ERR_TIMEOUT;
  587. memset(&vchnl_req, 0, sizeof(vchnl_req));
  588. vchnl_req.dev = dev;
  589. vchnl_req.parm = hmc_fcn;
  590. vchnl_req.parm_len = sizeof(*hmc_fcn);
  591. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  592. ret_code = vchnl_vf_send_get_hmc_fcn_req(dev, &vchnl_req);
  593. if (ret_code) {
  594. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  595. "%s Send message failed 0x%0x\n", __func__, ret_code);
  596. return ret_code;
  597. }
  598. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  599. if (ret_code)
  600. return ret_code;
  601. else
  602. return vchnl_req.ret_code;
  603. }
  604. /**
  605. * i40iw_vchnl_vf_add_hmc_objs - Add HMC Object
  606. * @dev: IWARP device pointer
  607. * @rsrc_type: HMC Resource type
  608. * @start_index: Starting index of the objects to be added
  609. * @rsrc_count: Number of resources to be added
  610. */
  611. enum i40iw_status_code i40iw_vchnl_vf_add_hmc_objs(struct i40iw_sc_dev *dev,
  612. enum i40iw_hmc_rsrc_type rsrc_type,
  613. u32 start_index,
  614. u32 rsrc_count)
  615. {
  616. struct i40iw_virtchnl_req vchnl_req;
  617. enum i40iw_status_code ret_code;
  618. if (!i40iw_vf_clear_to_send(dev))
  619. return I40IW_ERR_TIMEOUT;
  620. memset(&vchnl_req, 0, sizeof(vchnl_req));
  621. vchnl_req.dev = dev;
  622. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  623. ret_code = vchnl_vf_send_add_hmc_objs_req(dev,
  624. &vchnl_req,
  625. rsrc_type,
  626. start_index,
  627. rsrc_count);
  628. if (ret_code) {
  629. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  630. "%s Send message failed 0x%0x\n", __func__, ret_code);
  631. return ret_code;
  632. }
  633. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  634. if (ret_code)
  635. return ret_code;
  636. else
  637. return vchnl_req.ret_code;
  638. }
  639. /**
  640. * i40iw_vchnl_vf_del_hmc_obj - del HMC obj
  641. * @dev: IWARP device pointer
  642. * @rsrc_type: HMC Resource type
  643. * @start_index: Starting index of the object to delete
  644. * @rsrc_count: Number of resources to be delete
  645. */
  646. enum i40iw_status_code i40iw_vchnl_vf_del_hmc_obj(struct i40iw_sc_dev *dev,
  647. enum i40iw_hmc_rsrc_type rsrc_type,
  648. u32 start_index,
  649. u32 rsrc_count)
  650. {
  651. struct i40iw_virtchnl_req vchnl_req;
  652. enum i40iw_status_code ret_code;
  653. if (!i40iw_vf_clear_to_send(dev))
  654. return I40IW_ERR_TIMEOUT;
  655. memset(&vchnl_req, 0, sizeof(vchnl_req));
  656. vchnl_req.dev = dev;
  657. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  658. ret_code = vchnl_vf_send_del_hmc_objs_req(dev,
  659. &vchnl_req,
  660. rsrc_type,
  661. start_index,
  662. rsrc_count);
  663. if (ret_code) {
  664. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  665. "%s Send message failed 0x%0x\n", __func__, ret_code);
  666. return ret_code;
  667. }
  668. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  669. if (ret_code)
  670. return ret_code;
  671. else
  672. return vchnl_req.ret_code;
  673. }
  674. /**
  675. * i40iw_vchnl_vf_get_pe_stats - Get PE stats
  676. * @dev: IWARP device pointer
  677. * @hw_stats: HW stats struct
  678. */
  679. enum i40iw_status_code i40iw_vchnl_vf_get_pe_stats(struct i40iw_sc_dev *dev,
  680. struct i40iw_dev_hw_stats *hw_stats)
  681. {
  682. struct i40iw_virtchnl_req vchnl_req;
  683. enum i40iw_status_code ret_code;
  684. if (!i40iw_vf_clear_to_send(dev))
  685. return I40IW_ERR_TIMEOUT;
  686. memset(&vchnl_req, 0, sizeof(vchnl_req));
  687. vchnl_req.dev = dev;
  688. vchnl_req.parm = hw_stats;
  689. vchnl_req.parm_len = sizeof(*hw_stats);
  690. vchnl_req.vchnl_msg = &dev->vchnl_vf_msg_buf.vchnl_msg;
  691. ret_code = vchnl_vf_send_get_pe_stats_req(dev, &vchnl_req);
  692. if (ret_code) {
  693. i40iw_debug(dev, I40IW_DEBUG_VIRT,
  694. "%s Send message failed 0x%0x\n", __func__, ret_code);
  695. return ret_code;
  696. }
  697. ret_code = i40iw_vf_wait_vchnl_resp(dev);
  698. if (ret_code)
  699. return ret_code;
  700. else
  701. return vchnl_req.ret_code;
  702. }