i40iw_virtchnl.c 26 KB

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