i40e_client.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include <linux/list.h>
  4. #include <linux/errno.h>
  5. #include <linux/net/intel/i40e_client.h>
  6. #include "i40e.h"
  7. static LIST_HEAD(i40e_devices);
  8. static DEFINE_MUTEX(i40e_device_mutex);
  9. DEFINE_IDA(i40e_client_ida);
  10. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  11. struct i40e_client *client,
  12. u32 vf_id, u8 *msg, u16 len);
  13. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  14. struct i40e_client *client,
  15. struct i40e_qvlist_info *qvlist_info);
  16. static void i40e_client_request_reset(struct i40e_info *ldev,
  17. struct i40e_client *client,
  18. u32 reset_level);
  19. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  20. struct i40e_client *client,
  21. bool is_vf, u32 vf_id,
  22. u32 flag, u32 valid_flag);
  23. static struct i40e_ops i40e_lan_ops = {
  24. .virtchnl_send = i40e_client_virtchnl_send,
  25. .setup_qvlist = i40e_client_setup_qvlist,
  26. .request_reset = i40e_client_request_reset,
  27. .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
  28. };
  29. /**
  30. * i40e_client_get_params - Get the params that can change at runtime
  31. * @vsi: the VSI with the message
  32. * @params: client param struct
  33. *
  34. **/
  35. static
  36. int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
  37. {
  38. struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
  39. int i = 0;
  40. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  41. u8 tc = dcb_cfg->etscfg.prioritytable[i];
  42. u16 qs_handle;
  43. /* If TC is not enabled for VSI use TC0 for UP */
  44. if (!(vsi->tc_config.enabled_tc & BIT(tc)))
  45. tc = 0;
  46. qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
  47. params->qos.prio_qos[i].tc = tc;
  48. params->qos.prio_qos[i].qs_handle = qs_handle;
  49. if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
  50. dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
  51. tc, vsi->id);
  52. return -EINVAL;
  53. }
  54. }
  55. params->mtu = vsi->netdev->mtu;
  56. return 0;
  57. }
  58. /**
  59. * i40e_notify_client_of_vf_msg - call the client vf message callback
  60. * @vsi: the VSI with the message
  61. * @vf_id: the absolute VF id that sent the message
  62. * @msg: message buffer
  63. * @len: length of the message
  64. *
  65. * If there is a client to this VSI, call the client
  66. **/
  67. void
  68. i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
  69. {
  70. struct i40e_pf *pf = vsi->back;
  71. struct i40e_client_instance *cdev = pf->cinst;
  72. if (!cdev || !cdev->client)
  73. return;
  74. if (!cdev->client->ops || !cdev->client->ops->virtchnl_receive) {
  75. dev_dbg(&pf->pdev->dev,
  76. "Cannot locate client instance virtual channel receive routine\n");
  77. return;
  78. }
  79. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  80. dev_dbg(&pf->pdev->dev, "Client is not open, abort virtchnl_receive\n");
  81. return;
  82. }
  83. cdev->client->ops->virtchnl_receive(&cdev->lan_info, cdev->client,
  84. vf_id, msg, len);
  85. }
  86. /**
  87. * i40e_notify_client_of_l2_param_changes - call the client notify callback
  88. * @pf: PF device pointer
  89. *
  90. * If there is a client, call its callback
  91. **/
  92. void i40e_notify_client_of_l2_param_changes(struct i40e_pf *pf)
  93. {
  94. struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
  95. struct i40e_client_instance *cdev = pf->cinst;
  96. struct i40e_params params;
  97. if (!cdev || !cdev->client)
  98. return;
  99. if (!cdev->client->ops || !cdev->client->ops->l2_param_change) {
  100. dev_dbg(&pf->pdev->dev,
  101. "Cannot locate client instance l2_param_change routine\n");
  102. return;
  103. }
  104. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  105. dev_dbg(&pf->pdev->dev,
  106. "Client is not open, abort l2 param change\n");
  107. return;
  108. }
  109. memset(&params, 0, sizeof(params));
  110. i40e_client_get_params(vsi, &params);
  111. memcpy(&cdev->lan_info.params, &params, sizeof(struct i40e_params));
  112. cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client,
  113. &params);
  114. }
  115. /**
  116. * i40e_client_release_qvlist - release MSI-X vector mapping for client
  117. * @ldev: pointer to L2 context.
  118. *
  119. **/
  120. static void i40e_client_release_qvlist(struct i40e_info *ldev)
  121. {
  122. struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
  123. u32 i;
  124. if (!ldev->qvlist_info)
  125. return;
  126. for (i = 0; i < qvlist_info->num_vectors; i++) {
  127. struct i40e_pf *pf = ldev->pf;
  128. struct i40e_qv_info *qv_info;
  129. u32 reg_idx;
  130. qv_info = &qvlist_info->qv_info[i];
  131. reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
  132. wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  133. }
  134. kfree(ldev->qvlist_info);
  135. ldev->qvlist_info = NULL;
  136. }
  137. /**
  138. * i40e_notify_client_of_netdev_close - call the client close callback
  139. * @pf: PF device pointer
  140. * @reset: true when close called due to a reset pending
  141. *
  142. * If there is a client to this netdev, call the client with close
  143. **/
  144. void i40e_notify_client_of_netdev_close(struct i40e_pf *pf, bool reset)
  145. {
  146. struct i40e_client_instance *cdev = pf->cinst;
  147. if (!cdev || !cdev->client)
  148. return;
  149. if (!cdev->client->ops || !cdev->client->ops->close) {
  150. dev_dbg(&pf->pdev->dev,
  151. "Cannot locate client instance close routine\n");
  152. return;
  153. }
  154. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  155. dev_dbg(&pf->pdev->dev, "Client is not open, abort close\n");
  156. return;
  157. }
  158. cdev->client->ops->close(&cdev->lan_info, cdev->client, reset);
  159. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  160. i40e_client_release_qvlist(&cdev->lan_info);
  161. }
  162. /**
  163. * i40e_notify_client_of_vf_reset - call the client vf reset callback
  164. * @pf: PF device pointer
  165. * @vf_id: asolute id of VF being reset
  166. *
  167. * If there is a client attached to this PF, notify when a VF is reset
  168. **/
  169. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
  170. {
  171. struct i40e_client_instance *cdev = pf->cinst;
  172. if (!cdev || !cdev->client)
  173. return;
  174. if (!cdev->client->ops || !cdev->client->ops->vf_reset) {
  175. dev_dbg(&pf->pdev->dev,
  176. "Cannot locate client instance VF reset routine\n");
  177. return;
  178. }
  179. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  180. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
  181. return;
  182. }
  183. cdev->client->ops->vf_reset(&cdev->lan_info, cdev->client, vf_id);
  184. }
  185. /**
  186. * i40e_notify_client_of_vf_enable - call the client vf notification callback
  187. * @pf: PF device pointer
  188. * @num_vfs: the number of VFs currently enabled, 0 for disable
  189. *
  190. * If there is a client attached to this PF, call its VF notification routine
  191. **/
  192. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
  193. {
  194. struct i40e_client_instance *cdev = pf->cinst;
  195. if (!cdev || !cdev->client)
  196. return;
  197. if (!cdev->client->ops || !cdev->client->ops->vf_enable) {
  198. dev_dbg(&pf->pdev->dev,
  199. "Cannot locate client instance VF enable routine\n");
  200. return;
  201. }
  202. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  203. &cdev->state)) {
  204. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
  205. return;
  206. }
  207. cdev->client->ops->vf_enable(&cdev->lan_info, cdev->client, num_vfs);
  208. }
  209. /**
  210. * i40e_vf_client_capable - ask the client if it likes the specified VF
  211. * @pf: PF device pointer
  212. * @vf_id: the VF in question
  213. *
  214. * If there is a client of the specified type attached to this PF, call
  215. * its vf_capable routine
  216. **/
  217. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id)
  218. {
  219. struct i40e_client_instance *cdev = pf->cinst;
  220. int capable = false;
  221. if (!cdev || !cdev->client)
  222. goto out;
  223. if (!cdev->client->ops || !cdev->client->ops->vf_capable) {
  224. dev_dbg(&pf->pdev->dev,
  225. "Cannot locate client instance VF capability routine\n");
  226. goto out;
  227. }
  228. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state))
  229. goto out;
  230. capable = cdev->client->ops->vf_capable(&cdev->lan_info,
  231. cdev->client,
  232. vf_id);
  233. out:
  234. return capable;
  235. }
  236. void i40e_client_update_msix_info(struct i40e_pf *pf)
  237. {
  238. struct i40e_client_instance *cdev = pf->cinst;
  239. if (!cdev || !cdev->client)
  240. return;
  241. cdev->lan_info.msix_count = pf->num_iwarp_msix;
  242. cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
  243. }
  244. static void i40e_auxiliary_dev_release(struct device *dev)
  245. {
  246. struct i40e_auxiliary_device *i40e_aux_dev =
  247. container_of(dev, struct i40e_auxiliary_device, aux_dev.dev);
  248. ida_free(&i40e_client_ida, i40e_aux_dev->aux_dev.id);
  249. kfree(i40e_aux_dev);
  250. }
  251. static int i40e_register_auxiliary_dev(struct i40e_info *ldev, const char *name)
  252. {
  253. struct i40e_auxiliary_device *i40e_aux_dev;
  254. struct pci_dev *pdev = ldev->pcidev;
  255. struct auxiliary_device *aux_dev;
  256. int ret;
  257. i40e_aux_dev = kzalloc(sizeof(*i40e_aux_dev), GFP_KERNEL);
  258. if (!i40e_aux_dev)
  259. return -ENOMEM;
  260. i40e_aux_dev->ldev = ldev;
  261. aux_dev = &i40e_aux_dev->aux_dev;
  262. aux_dev->name = name;
  263. aux_dev->dev.parent = &pdev->dev;
  264. aux_dev->dev.release = i40e_auxiliary_dev_release;
  265. ldev->aux_dev = aux_dev;
  266. ret = ida_alloc(&i40e_client_ida, GFP_KERNEL);
  267. if (ret < 0) {
  268. kfree(i40e_aux_dev);
  269. return ret;
  270. }
  271. aux_dev->id = ret;
  272. ret = auxiliary_device_init(aux_dev);
  273. if (ret < 0) {
  274. ida_free(&i40e_client_ida, aux_dev->id);
  275. kfree(i40e_aux_dev);
  276. return ret;
  277. }
  278. ret = auxiliary_device_add(aux_dev);
  279. if (ret) {
  280. auxiliary_device_uninit(aux_dev);
  281. return ret;
  282. }
  283. return ret;
  284. }
  285. /**
  286. * i40e_client_add_instance - add a client instance struct to the instance list
  287. * @pf: pointer to the board struct
  288. *
  289. **/
  290. static void i40e_client_add_instance(struct i40e_pf *pf)
  291. {
  292. struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
  293. struct i40e_client_instance *cdev = NULL;
  294. struct netdev_hw_addr *mac = NULL;
  295. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  296. if (!cdev)
  297. return;
  298. cdev->lan_info.pf = (void *)pf;
  299. cdev->lan_info.netdev = vsi->netdev;
  300. cdev->lan_info.pcidev = pf->pdev;
  301. cdev->lan_info.fid = pf->hw.pf_id;
  302. cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
  303. cdev->lan_info.hw_addr = pf->hw.hw_addr;
  304. cdev->lan_info.ops = &i40e_lan_ops;
  305. cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
  306. cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
  307. cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
  308. cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
  309. cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
  310. cdev->lan_info.fw_build = pf->hw.aq.fw_build;
  311. set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
  312. if (i40e_client_get_params(vsi, &cdev->lan_info.params))
  313. goto free_cdev;
  314. mac = list_first_entry_or_null(&cdev->lan_info.netdev->dev_addrs.list,
  315. struct netdev_hw_addr, list);
  316. if (mac)
  317. ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
  318. else
  319. dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
  320. pf->cinst = cdev;
  321. cdev->lan_info.msix_count = pf->num_iwarp_msix;
  322. cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
  323. if (i40e_register_auxiliary_dev(&cdev->lan_info, "iwarp"))
  324. goto free_cdev;
  325. return;
  326. free_cdev:
  327. kfree(cdev);
  328. pf->cinst = NULL;
  329. }
  330. /**
  331. * i40e_client_del_instance - removes a client instance from the list
  332. * @pf: pointer to the board struct
  333. *
  334. **/
  335. static
  336. void i40e_client_del_instance(struct i40e_pf *pf)
  337. {
  338. kfree(pf->cinst);
  339. pf->cinst = NULL;
  340. }
  341. /**
  342. * i40e_client_subtask - client maintenance work
  343. * @pf: board private structure
  344. **/
  345. void i40e_client_subtask(struct i40e_pf *pf)
  346. {
  347. struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
  348. struct i40e_client_instance *cdev;
  349. struct i40e_client *client;
  350. int ret = 0;
  351. if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state))
  352. return;
  353. cdev = pf->cinst;
  354. /* If we're down or resetting, just bail */
  355. if (test_bit(__I40E_DOWN, pf->state) ||
  356. test_bit(__I40E_CONFIG_BUSY, pf->state))
  357. return;
  358. if (!cdev || !cdev->client)
  359. return;
  360. client = cdev->client;
  361. /* Here we handle client opens. If the client is down, and
  362. * the netdev is registered, then open the client.
  363. */
  364. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  365. if (vsi->netdev_registered &&
  366. client->ops && client->ops->open) {
  367. set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  368. ret = client->ops->open(&cdev->lan_info, client);
  369. if (ret) {
  370. /* Remove failed client instance */
  371. clear_bit(__I40E_CLIENT_INSTANCE_OPENED,
  372. &cdev->state);
  373. return;
  374. }
  375. }
  376. }
  377. /* enable/disable PE TCP_ENA flag based on netdev down/up
  378. */
  379. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  380. i40e_client_update_vsi_ctxt(&cdev->lan_info, client,
  381. 0, 0, 0,
  382. I40E_CLIENT_VSI_FLAG_TCP_ENABLE);
  383. else
  384. i40e_client_update_vsi_ctxt(&cdev->lan_info, client,
  385. 0, 0,
  386. I40E_CLIENT_VSI_FLAG_TCP_ENABLE,
  387. I40E_CLIENT_VSI_FLAG_TCP_ENABLE);
  388. }
  389. /**
  390. * i40e_lan_add_device - add a lan device struct to the list of lan devices
  391. * @pf: pointer to the board struct
  392. *
  393. * Returns 0 on success or none 0 on error
  394. **/
  395. int i40e_lan_add_device(struct i40e_pf *pf)
  396. {
  397. struct i40e_device *ldev;
  398. int ret = 0;
  399. mutex_lock(&i40e_device_mutex);
  400. list_for_each_entry(ldev, &i40e_devices, list) {
  401. if (ldev->pf == pf) {
  402. ret = -EEXIST;
  403. goto out;
  404. }
  405. }
  406. ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
  407. if (!ldev) {
  408. ret = -ENOMEM;
  409. goto out;
  410. }
  411. ldev->pf = pf;
  412. INIT_LIST_HEAD(&ldev->list);
  413. list_add(&ldev->list, &i40e_devices);
  414. dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  415. pf->hw.pf_id, pf->hw.bus.bus_id,
  416. pf->hw.bus.device, pf->hw.bus.func);
  417. i40e_client_add_instance(pf);
  418. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  419. i40e_service_event_schedule(pf);
  420. out:
  421. mutex_unlock(&i40e_device_mutex);
  422. return ret;
  423. }
  424. /**
  425. * i40e_lan_del_device - removes a lan device from the device list
  426. * @pf: pointer to the board struct
  427. *
  428. * Returns 0 on success or non-0 on error
  429. **/
  430. int i40e_lan_del_device(struct i40e_pf *pf)
  431. {
  432. struct auxiliary_device *aux_dev = pf->cinst->lan_info.aux_dev;
  433. struct i40e_device *ldev, *tmp;
  434. int ret = -ENODEV;
  435. auxiliary_device_delete(aux_dev);
  436. auxiliary_device_uninit(aux_dev);
  437. /* First, remove any client instance. */
  438. i40e_client_del_instance(pf);
  439. mutex_lock(&i40e_device_mutex);
  440. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  441. if (ldev->pf == pf) {
  442. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  443. pf->hw.pf_id, pf->hw.bus.bus_id,
  444. pf->hw.bus.device, pf->hw.bus.func);
  445. list_del(&ldev->list);
  446. kfree(ldev);
  447. ret = 0;
  448. break;
  449. }
  450. }
  451. mutex_unlock(&i40e_device_mutex);
  452. return ret;
  453. }
  454. /**
  455. * i40e_client_virtchnl_send - TBD
  456. * @ldev: pointer to L2 context
  457. * @client: Client pointer
  458. * @vf_id: absolute VF identifier
  459. * @msg: message buffer
  460. * @len: length of message buffer
  461. *
  462. * Return 0 on success or < 0 on error
  463. **/
  464. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  465. struct i40e_client *client,
  466. u32 vf_id, u8 *msg, u16 len)
  467. {
  468. struct i40e_pf *pf = ldev->pf;
  469. struct i40e_hw *hw = &pf->hw;
  470. int err;
  471. err = i40e_aq_send_msg_to_vf(hw, vf_id, VIRTCHNL_OP_RDMA,
  472. 0, msg, len, NULL);
  473. if (err)
  474. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  475. err, hw->aq.asq_last_status);
  476. return err;
  477. }
  478. /**
  479. * i40e_client_setup_qvlist
  480. * @ldev: pointer to L2 context.
  481. * @client: Client pointer.
  482. * @qvlist_info: queue and vector list
  483. *
  484. * Return 0 on success or < 0 on error
  485. **/
  486. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  487. struct i40e_client *client,
  488. struct i40e_qvlist_info *qvlist_info)
  489. {
  490. struct i40e_pf *pf = ldev->pf;
  491. struct i40e_hw *hw = &pf->hw;
  492. struct i40e_qv_info *qv_info;
  493. u32 v_idx, i, reg_idx, reg;
  494. ldev->qvlist_info = kzalloc(struct_size(ldev->qvlist_info, qv_info,
  495. qvlist_info->num_vectors), GFP_KERNEL);
  496. if (!ldev->qvlist_info)
  497. return -ENOMEM;
  498. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  499. for (i = 0; i < qvlist_info->num_vectors; i++) {
  500. qv_info = &qvlist_info->qv_info[i];
  501. v_idx = qv_info->v_idx;
  502. /* Validate vector id belongs to this client */
  503. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  504. (v_idx < pf->iwarp_base_vector))
  505. goto err;
  506. ldev->qvlist_info->qv_info[i] = *qv_info;
  507. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  508. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  509. /* Special case - No CEQ mapped on this vector */
  510. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  511. } else {
  512. reg = (qv_info->ceq_idx &
  513. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  514. (I40E_QUEUE_TYPE_PE_CEQ <<
  515. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  516. wr32(hw, reg_idx, reg);
  517. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  518. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  519. (qv_info->itr_idx <<
  520. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  521. (I40E_QUEUE_END_OF_LIST <<
  522. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  523. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  524. }
  525. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  526. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  527. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  528. (qv_info->itr_idx <<
  529. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  530. wr32(hw, I40E_PFINT_AEQCTL, reg);
  531. }
  532. }
  533. /* Mitigate sync problems with iwarp VF driver */
  534. i40e_flush(hw);
  535. return 0;
  536. err:
  537. kfree(ldev->qvlist_info);
  538. ldev->qvlist_info = NULL;
  539. return -EINVAL;
  540. }
  541. /**
  542. * i40e_client_request_reset
  543. * @ldev: pointer to L2 context.
  544. * @client: Client pointer.
  545. * @reset_level: reset level
  546. **/
  547. static void i40e_client_request_reset(struct i40e_info *ldev,
  548. struct i40e_client *client,
  549. u32 reset_level)
  550. {
  551. struct i40e_pf *pf = ldev->pf;
  552. switch (reset_level) {
  553. case I40E_CLIENT_RESET_LEVEL_PF:
  554. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  555. break;
  556. case I40E_CLIENT_RESET_LEVEL_CORE:
  557. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  558. break;
  559. default:
  560. dev_warn(&pf->pdev->dev,
  561. "Client for PF id %d requested an unsupported reset: %d.\n",
  562. pf->hw.pf_id, reset_level);
  563. break;
  564. }
  565. i40e_service_event_schedule(pf);
  566. }
  567. /**
  568. * i40e_client_update_vsi_ctxt
  569. * @ldev: pointer to L2 context.
  570. * @client: Client pointer.
  571. * @is_vf: if this for the VF
  572. * @vf_id: if is_vf true this carries the vf_id
  573. * @flag: Any device level setting that needs to be done for PE
  574. * @valid_flag: Bits in this match up and enable changing of flag bits
  575. *
  576. * Return 0 on success or < 0 on error
  577. **/
  578. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  579. struct i40e_client *client,
  580. bool is_vf, u32 vf_id,
  581. u32 flag, u32 valid_flag)
  582. {
  583. struct i40e_vsi *vsi = i40e_pf_get_main_vsi(ldev->pf);
  584. struct i40e_pf *pf = ldev->pf;
  585. struct i40e_vsi_context ctxt;
  586. bool update = true;
  587. int err;
  588. /* TODO: for now do not allow setting VF's VSI setting */
  589. if (is_vf)
  590. return -EINVAL;
  591. ctxt.seid = pf->main_vsi_seid;
  592. ctxt.pf_num = pf->hw.pf_id;
  593. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  594. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  595. if (err) {
  596. dev_info(&pf->pdev->dev,
  597. "couldn't get PF vsi config, err %pe aq_err %s\n",
  598. ERR_PTR(err),
  599. i40e_aq_str(&pf->hw,
  600. pf->hw.aq.asq_last_status));
  601. return -ENOENT;
  602. }
  603. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) &&
  604. (flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) {
  605. ctxt.info.valid_sections =
  606. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  607. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  608. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) &&
  609. !(flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) {
  610. ctxt.info.valid_sections =
  611. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  612. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  613. } else {
  614. update = false;
  615. dev_warn(&pf->pdev->dev,
  616. "Client for PF id %d request an unsupported Config: %x.\n",
  617. pf->hw.pf_id, flag);
  618. }
  619. if (update) {
  620. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  621. if (err) {
  622. dev_info(&pf->pdev->dev,
  623. "update VSI ctxt for PE failed, err %pe aq_err %s\n",
  624. ERR_PTR(err),
  625. i40e_aq_str(&pf->hw,
  626. pf->hw.aq.asq_last_status));
  627. }
  628. }
  629. return err;
  630. }
  631. void i40e_client_device_register(struct i40e_info *ldev, struct i40e_client *client)
  632. {
  633. struct i40e_pf *pf = ldev->pf;
  634. pf->cinst->client = client;
  635. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  636. i40e_service_event_schedule(pf);
  637. }
  638. EXPORT_SYMBOL_GPL(i40e_client_device_register);
  639. void i40e_client_device_unregister(struct i40e_info *ldev)
  640. {
  641. struct i40e_pf *pf = ldev->pf;
  642. struct i40e_client_instance *cdev = pf->cinst;
  643. if (!cdev)
  644. return;
  645. while (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
  646. usleep_range(500, 1000);
  647. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  648. cdev->client->ops->close(&cdev->lan_info, cdev->client, false);
  649. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  650. i40e_client_release_qvlist(&cdev->lan_info);
  651. }
  652. pf->cinst->client = NULL;
  653. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  654. }
  655. EXPORT_SYMBOL_GPL(i40e_client_device_unregister);