i40e_client.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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 "i40e.h"
  6. #include "i40e_prototype.h"
  7. #include "i40e_client.h"
  8. static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
  9. static struct i40e_client *registered_client;
  10. static LIST_HEAD(i40e_devices);
  11. static DEFINE_MUTEX(i40e_device_mutex);
  12. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  13. struct i40e_client *client,
  14. u32 vf_id, u8 *msg, u16 len);
  15. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  16. struct i40e_client *client,
  17. struct i40e_qvlist_info *qvlist_info);
  18. static void i40e_client_request_reset(struct i40e_info *ldev,
  19. struct i40e_client *client,
  20. u32 reset_level);
  21. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  22. struct i40e_client *client,
  23. bool is_vf, u32 vf_id,
  24. u32 flag, u32 valid_flag);
  25. static struct i40e_ops i40e_lan_ops = {
  26. .virtchnl_send = i40e_client_virtchnl_send,
  27. .setup_qvlist = i40e_client_setup_qvlist,
  28. .request_reset = i40e_client_request_reset,
  29. .update_vsi_ctxt = i40e_client_update_vsi_ctxt,
  30. };
  31. /**
  32. * i40e_client_get_params - Get the params that can change at runtime
  33. * @vsi: the VSI with the message
  34. * @params: client param struct
  35. *
  36. **/
  37. static
  38. int i40e_client_get_params(struct i40e_vsi *vsi, struct i40e_params *params)
  39. {
  40. struct i40e_dcbx_config *dcb_cfg = &vsi->back->hw.local_dcbx_config;
  41. int i = 0;
  42. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  43. u8 tc = dcb_cfg->etscfg.prioritytable[i];
  44. u16 qs_handle;
  45. /* If TC is not enabled for VSI use TC0 for UP */
  46. if (!(vsi->tc_config.enabled_tc & BIT(tc)))
  47. tc = 0;
  48. qs_handle = le16_to_cpu(vsi->info.qs_handle[tc]);
  49. params->qos.prio_qos[i].tc = tc;
  50. params->qos.prio_qos[i].qs_handle = qs_handle;
  51. if (qs_handle == I40E_AQ_VSI_QS_HANDLE_INVALID) {
  52. dev_err(&vsi->back->pdev->dev, "Invalid queue set handle for TC = %d, vsi id = %d\n",
  53. tc, vsi->id);
  54. return -EINVAL;
  55. }
  56. }
  57. params->mtu = vsi->netdev->mtu;
  58. return 0;
  59. }
  60. /**
  61. * i40e_notify_client_of_vf_msg - call the client vf message callback
  62. * @vsi: the VSI with the message
  63. * @vf_id: the absolute VF id that sent the message
  64. * @msg: message buffer
  65. * @len: length of the message
  66. *
  67. * If there is a client to this VSI, call the client
  68. **/
  69. void
  70. i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
  71. {
  72. struct i40e_pf *pf = vsi->back;
  73. struct i40e_client_instance *cdev = pf->cinst;
  74. if (!cdev || !cdev->client)
  75. return;
  76. if (!cdev->client->ops || !cdev->client->ops->virtchnl_receive) {
  77. dev_dbg(&pf->pdev->dev,
  78. "Cannot locate client instance virtual channel receive routine\n");
  79. return;
  80. }
  81. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  82. dev_dbg(&pf->pdev->dev, "Client is not open, abort virtchnl_receive\n");
  83. return;
  84. }
  85. cdev->client->ops->virtchnl_receive(&cdev->lan_info, cdev->client,
  86. vf_id, msg, len);
  87. }
  88. /**
  89. * i40e_notify_client_of_l2_param_changes - call the client notify callback
  90. * @vsi: the VSI with l2 param changes
  91. *
  92. * If there is a client to this VSI, call the client
  93. **/
  94. void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
  95. {
  96. struct i40e_pf *pf = vsi->back;
  97. struct i40e_client_instance *cdev = pf->cinst;
  98. struct i40e_params params;
  99. if (!cdev || !cdev->client)
  100. return;
  101. if (!cdev->client->ops || !cdev->client->ops->l2_param_change) {
  102. dev_dbg(&vsi->back->pdev->dev,
  103. "Cannot locate client instance l2_param_change routine\n");
  104. return;
  105. }
  106. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  107. dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
  108. return;
  109. }
  110. memset(&params, 0, sizeof(params));
  111. i40e_client_get_params(vsi, &params);
  112. memcpy(&cdev->lan_info.params, &params, sizeof(struct i40e_params));
  113. cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client,
  114. &params);
  115. }
  116. /**
  117. * i40e_client_release_qvlist - release MSI-X vector mapping for client
  118. * @ldev: pointer to L2 context.
  119. *
  120. **/
  121. static void i40e_client_release_qvlist(struct i40e_info *ldev)
  122. {
  123. struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
  124. u32 i;
  125. if (!ldev->qvlist_info)
  126. return;
  127. for (i = 0; i < qvlist_info->num_vectors; i++) {
  128. struct i40e_pf *pf = ldev->pf;
  129. struct i40e_qv_info *qv_info;
  130. u32 reg_idx;
  131. qv_info = &qvlist_info->qv_info[i];
  132. if (!qv_info)
  133. continue;
  134. reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
  135. wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  136. }
  137. kfree(ldev->qvlist_info);
  138. ldev->qvlist_info = NULL;
  139. }
  140. /**
  141. * i40e_notify_client_of_netdev_close - call the client close callback
  142. * @vsi: the VSI with netdev closed
  143. * @reset: true when close called due to a reset pending
  144. *
  145. * If there is a client to this netdev, call the client with close
  146. **/
  147. void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
  148. {
  149. struct i40e_pf *pf = vsi->back;
  150. struct i40e_client_instance *cdev = pf->cinst;
  151. if (!cdev || !cdev->client)
  152. return;
  153. if (!cdev->client->ops || !cdev->client->ops->close) {
  154. dev_dbg(&vsi->back->pdev->dev,
  155. "Cannot locate client instance close routine\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. /**
  245. * i40e_client_add_instance - add a client instance struct to the instance list
  246. * @pf: pointer to the board struct
  247. * @client: pointer to a client struct in the client list.
  248. * @existing: if there was already an existing instance
  249. *
  250. **/
  251. static void i40e_client_add_instance(struct i40e_pf *pf)
  252. {
  253. struct i40e_client_instance *cdev = NULL;
  254. struct netdev_hw_addr *mac = NULL;
  255. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  256. if (!registered_client || pf->cinst)
  257. return;
  258. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  259. if (!cdev)
  260. return;
  261. cdev->lan_info.pf = (void *)pf;
  262. cdev->lan_info.netdev = vsi->netdev;
  263. cdev->lan_info.pcidev = pf->pdev;
  264. cdev->lan_info.fid = pf->hw.pf_id;
  265. cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
  266. cdev->lan_info.hw_addr = pf->hw.hw_addr;
  267. cdev->lan_info.ops = &i40e_lan_ops;
  268. cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
  269. cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
  270. cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
  271. cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
  272. cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
  273. cdev->lan_info.fw_build = pf->hw.aq.fw_build;
  274. set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
  275. if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
  276. kfree(cdev);
  277. cdev = NULL;
  278. return;
  279. }
  280. mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
  281. struct netdev_hw_addr, list);
  282. if (mac)
  283. ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
  284. else
  285. dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
  286. cdev->client = registered_client;
  287. pf->cinst = cdev;
  288. i40e_client_update_msix_info(pf);
  289. }
  290. /**
  291. * i40e_client_del_instance - removes a client instance from the list
  292. * @pf: pointer to the board struct
  293. *
  294. **/
  295. static
  296. void i40e_client_del_instance(struct i40e_pf *pf)
  297. {
  298. kfree(pf->cinst);
  299. pf->cinst = NULL;
  300. }
  301. /**
  302. * i40e_client_subtask - client maintenance work
  303. * @pf: board private structure
  304. **/
  305. void i40e_client_subtask(struct i40e_pf *pf)
  306. {
  307. struct i40e_client *client = registered_client;
  308. struct i40e_client_instance *cdev;
  309. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  310. int ret = 0;
  311. if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state))
  312. return;
  313. cdev = pf->cinst;
  314. /* If we're down or resetting, just bail */
  315. if (test_bit(__I40E_DOWN, pf->state) ||
  316. test_bit(__I40E_CONFIG_BUSY, pf->state))
  317. return;
  318. if (!client || !cdev)
  319. return;
  320. /* Here we handle client opens. If the client is down, and
  321. * the netdev is registered, then open the client.
  322. */
  323. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  324. if (vsi->netdev_registered &&
  325. client->ops && client->ops->open) {
  326. set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  327. ret = client->ops->open(&cdev->lan_info, client);
  328. if (ret) {
  329. /* Remove failed client instance */
  330. clear_bit(__I40E_CLIENT_INSTANCE_OPENED,
  331. &cdev->state);
  332. i40e_client_del_instance(pf);
  333. }
  334. }
  335. }
  336. /* enable/disable PE TCP_ENA flag based on netdev down/up
  337. */
  338. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  339. i40e_client_update_vsi_ctxt(&cdev->lan_info, client,
  340. 0, 0, 0,
  341. I40E_CLIENT_VSI_FLAG_TCP_ENABLE);
  342. else
  343. i40e_client_update_vsi_ctxt(&cdev->lan_info, client,
  344. 0, 0,
  345. I40E_CLIENT_VSI_FLAG_TCP_ENABLE,
  346. I40E_CLIENT_VSI_FLAG_TCP_ENABLE);
  347. }
  348. /**
  349. * i40e_lan_add_device - add a lan device struct to the list of lan devices
  350. * @pf: pointer to the board struct
  351. *
  352. * Returns 0 on success or none 0 on error
  353. **/
  354. int i40e_lan_add_device(struct i40e_pf *pf)
  355. {
  356. struct i40e_device *ldev;
  357. int ret = 0;
  358. mutex_lock(&i40e_device_mutex);
  359. list_for_each_entry(ldev, &i40e_devices, list) {
  360. if (ldev->pf == pf) {
  361. ret = -EEXIST;
  362. goto out;
  363. }
  364. }
  365. ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
  366. if (!ldev) {
  367. ret = -ENOMEM;
  368. goto out;
  369. }
  370. ldev->pf = pf;
  371. INIT_LIST_HEAD(&ldev->list);
  372. list_add(&ldev->list, &i40e_devices);
  373. dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  374. pf->hw.pf_id, pf->hw.bus.bus_id,
  375. pf->hw.bus.device, pf->hw.bus.func);
  376. /* If a client has already been registered, we need to add an instance
  377. * of it to our new LAN device.
  378. */
  379. if (registered_client)
  380. i40e_client_add_instance(pf);
  381. /* Since in some cases register may have happened before a device gets
  382. * added, we can schedule a subtask to go initiate the clients if
  383. * they can be launched at probe time.
  384. */
  385. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  386. i40e_service_event_schedule(pf);
  387. out:
  388. mutex_unlock(&i40e_device_mutex);
  389. return ret;
  390. }
  391. /**
  392. * i40e_lan_del_device - removes a lan device from the device list
  393. * @pf: pointer to the board struct
  394. *
  395. * Returns 0 on success or non-0 on error
  396. **/
  397. int i40e_lan_del_device(struct i40e_pf *pf)
  398. {
  399. struct i40e_device *ldev, *tmp;
  400. int ret = -ENODEV;
  401. /* First, remove any client instance. */
  402. i40e_client_del_instance(pf);
  403. mutex_lock(&i40e_device_mutex);
  404. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  405. if (ldev->pf == pf) {
  406. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  407. pf->hw.pf_id, pf->hw.bus.bus_id,
  408. pf->hw.bus.device, pf->hw.bus.func);
  409. list_del(&ldev->list);
  410. kfree(ldev);
  411. ret = 0;
  412. break;
  413. }
  414. }
  415. mutex_unlock(&i40e_device_mutex);
  416. return ret;
  417. }
  418. /**
  419. * i40e_client_release - release client specific resources
  420. * @client: pointer to the registered client
  421. *
  422. **/
  423. static void i40e_client_release(struct i40e_client *client)
  424. {
  425. struct i40e_client_instance *cdev;
  426. struct i40e_device *ldev;
  427. struct i40e_pf *pf;
  428. mutex_lock(&i40e_device_mutex);
  429. list_for_each_entry(ldev, &i40e_devices, list) {
  430. pf = ldev->pf;
  431. cdev = pf->cinst;
  432. if (!cdev)
  433. continue;
  434. while (test_and_set_bit(__I40E_SERVICE_SCHED,
  435. pf->state))
  436. usleep_range(500, 1000);
  437. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  438. if (client->ops && client->ops->close)
  439. client->ops->close(&cdev->lan_info, client,
  440. false);
  441. i40e_client_release_qvlist(&cdev->lan_info);
  442. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  443. dev_warn(&pf->pdev->dev,
  444. "Client %s instance for PF id %d closed\n",
  445. client->name, pf->hw.pf_id);
  446. }
  447. /* delete the client instance */
  448. i40e_client_del_instance(pf);
  449. dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
  450. client->name);
  451. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  452. }
  453. mutex_unlock(&i40e_device_mutex);
  454. }
  455. /**
  456. * i40e_client_prepare - prepare client specific resources
  457. * @client: pointer to the registered client
  458. *
  459. **/
  460. static void i40e_client_prepare(struct i40e_client *client)
  461. {
  462. struct i40e_device *ldev;
  463. struct i40e_pf *pf;
  464. mutex_lock(&i40e_device_mutex);
  465. list_for_each_entry(ldev, &i40e_devices, list) {
  466. pf = ldev->pf;
  467. i40e_client_add_instance(pf);
  468. /* Start the client subtask */
  469. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  470. i40e_service_event_schedule(pf);
  471. }
  472. mutex_unlock(&i40e_device_mutex);
  473. }
  474. /**
  475. * i40e_client_virtchnl_send - TBD
  476. * @ldev: pointer to L2 context
  477. * @client: Client pointer
  478. * @vf_id: absolute VF identifier
  479. * @msg: message buffer
  480. * @len: length of message buffer
  481. *
  482. * Return 0 on success or < 0 on error
  483. **/
  484. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  485. struct i40e_client *client,
  486. u32 vf_id, u8 *msg, u16 len)
  487. {
  488. struct i40e_pf *pf = ldev->pf;
  489. struct i40e_hw *hw = &pf->hw;
  490. i40e_status err;
  491. err = i40e_aq_send_msg_to_vf(hw, vf_id, VIRTCHNL_OP_IWARP,
  492. 0, msg, len, NULL);
  493. if (err)
  494. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  495. err, hw->aq.asq_last_status);
  496. return err;
  497. }
  498. /**
  499. * i40e_client_setup_qvlist
  500. * @ldev: pointer to L2 context.
  501. * @client: Client pointer.
  502. * @qvlist_info: queue and vector list
  503. *
  504. * Return 0 on success or < 0 on error
  505. **/
  506. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  507. struct i40e_client *client,
  508. struct i40e_qvlist_info *qvlist_info)
  509. {
  510. struct i40e_pf *pf = ldev->pf;
  511. struct i40e_hw *hw = &pf->hw;
  512. struct i40e_qv_info *qv_info;
  513. u32 v_idx, i, reg_idx, reg;
  514. u32 size;
  515. size = sizeof(struct i40e_qvlist_info) +
  516. (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
  517. ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
  518. if (!ldev->qvlist_info)
  519. return -ENOMEM;
  520. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  521. for (i = 0; i < qvlist_info->num_vectors; i++) {
  522. qv_info = &qvlist_info->qv_info[i];
  523. if (!qv_info)
  524. continue;
  525. v_idx = qv_info->v_idx;
  526. /* Validate vector id belongs to this client */
  527. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  528. (v_idx < pf->iwarp_base_vector))
  529. goto err;
  530. ldev->qvlist_info->qv_info[i] = *qv_info;
  531. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  532. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  533. /* Special case - No CEQ mapped on this vector */
  534. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  535. } else {
  536. reg = (qv_info->ceq_idx &
  537. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  538. (I40E_QUEUE_TYPE_PE_CEQ <<
  539. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  540. wr32(hw, reg_idx, reg);
  541. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  542. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  543. (qv_info->itr_idx <<
  544. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  545. (I40E_QUEUE_END_OF_LIST <<
  546. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  547. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  548. }
  549. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  550. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  551. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  552. (qv_info->itr_idx <<
  553. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  554. wr32(hw, I40E_PFINT_AEQCTL, reg);
  555. }
  556. }
  557. /* Mitigate sync problems with iwarp VF driver */
  558. i40e_flush(hw);
  559. return 0;
  560. err:
  561. kfree(ldev->qvlist_info);
  562. ldev->qvlist_info = NULL;
  563. return -EINVAL;
  564. }
  565. /**
  566. * i40e_client_request_reset
  567. * @ldev: pointer to L2 context.
  568. * @client: Client pointer.
  569. * @reset_level: reset level
  570. **/
  571. static void i40e_client_request_reset(struct i40e_info *ldev,
  572. struct i40e_client *client,
  573. u32 reset_level)
  574. {
  575. struct i40e_pf *pf = ldev->pf;
  576. switch (reset_level) {
  577. case I40E_CLIENT_RESET_LEVEL_PF:
  578. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  579. break;
  580. case I40E_CLIENT_RESET_LEVEL_CORE:
  581. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  582. break;
  583. default:
  584. dev_warn(&pf->pdev->dev,
  585. "Client for PF id %d requested an unsupported reset: %d.\n",
  586. pf->hw.pf_id, reset_level);
  587. break;
  588. }
  589. i40e_service_event_schedule(pf);
  590. }
  591. /**
  592. * i40e_client_update_vsi_ctxt
  593. * @ldev: pointer to L2 context.
  594. * @client: Client pointer.
  595. * @is_vf: if this for the VF
  596. * @vf_id: if is_vf true this carries the vf_id
  597. * @flag: Any device level setting that needs to be done for PE
  598. * @valid_flag: Bits in this match up and enable changing of flag bits
  599. *
  600. * Return 0 on success or < 0 on error
  601. **/
  602. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  603. struct i40e_client *client,
  604. bool is_vf, u32 vf_id,
  605. u32 flag, u32 valid_flag)
  606. {
  607. struct i40e_pf *pf = ldev->pf;
  608. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  609. struct i40e_vsi_context ctxt;
  610. bool update = true;
  611. i40e_status err;
  612. /* TODO: for now do not allow setting VF's VSI setting */
  613. if (is_vf)
  614. return -EINVAL;
  615. ctxt.seid = pf->main_vsi_seid;
  616. ctxt.pf_num = pf->hw.pf_id;
  617. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  618. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  619. if (err) {
  620. dev_info(&pf->pdev->dev,
  621. "couldn't get PF vsi config, err %s aq_err %s\n",
  622. i40e_stat_str(&pf->hw, err),
  623. i40e_aq_str(&pf->hw,
  624. pf->hw.aq.asq_last_status));
  625. return -ENOENT;
  626. }
  627. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) &&
  628. (flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) {
  629. ctxt.info.valid_sections =
  630. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  631. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  632. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE) &&
  633. !(flag & I40E_CLIENT_VSI_FLAG_TCP_ENABLE)) {
  634. ctxt.info.valid_sections =
  635. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  636. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  637. } else {
  638. update = false;
  639. dev_warn(&pf->pdev->dev,
  640. "Client for PF id %d request an unsupported Config: %x.\n",
  641. pf->hw.pf_id, flag);
  642. }
  643. if (update) {
  644. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  645. if (err) {
  646. dev_info(&pf->pdev->dev,
  647. "update VSI ctxt for PE failed, err %s aq_err %s\n",
  648. i40e_stat_str(&pf->hw, err),
  649. i40e_aq_str(&pf->hw,
  650. pf->hw.aq.asq_last_status));
  651. }
  652. }
  653. return err;
  654. }
  655. /**
  656. * i40e_register_client - Register a i40e client driver with the L2 driver
  657. * @client: pointer to the i40e_client struct
  658. *
  659. * Returns 0 on success or non-0 on error
  660. **/
  661. int i40e_register_client(struct i40e_client *client)
  662. {
  663. int ret = 0;
  664. if (!client) {
  665. ret = -EIO;
  666. goto out;
  667. }
  668. if (strlen(client->name) == 0) {
  669. pr_info("i40e: Failed to register client with no name\n");
  670. ret = -EIO;
  671. goto out;
  672. }
  673. if (registered_client) {
  674. pr_info("i40e: Client %s has already been registered!\n",
  675. client->name);
  676. ret = -EEXIST;
  677. goto out;
  678. }
  679. if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
  680. (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
  681. pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
  682. client->name);
  683. pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
  684. client->version.major, client->version.minor,
  685. client->version.build,
  686. i40e_client_interface_version_str);
  687. ret = -EIO;
  688. goto out;
  689. }
  690. registered_client = client;
  691. i40e_client_prepare(client);
  692. pr_info("i40e: Registered client %s\n", client->name);
  693. out:
  694. return ret;
  695. }
  696. EXPORT_SYMBOL(i40e_register_client);
  697. /**
  698. * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
  699. * @client: pointer to the i40e_client struct
  700. *
  701. * Returns 0 on success or non-0 on error
  702. **/
  703. int i40e_unregister_client(struct i40e_client *client)
  704. {
  705. int ret = 0;
  706. if (registered_client != client) {
  707. pr_info("i40e: Client %s has not been registered\n",
  708. client->name);
  709. ret = -ENODEV;
  710. goto out;
  711. }
  712. registered_client = NULL;
  713. /* When a unregister request comes through we would have to send
  714. * a close for each of the client instances that were opened.
  715. * client_release function is called to handle this.
  716. */
  717. i40e_client_release(client);
  718. pr_info("i40e: Unregistered client %s\n", client->name);
  719. out:
  720. return ret;
  721. }
  722. EXPORT_SYMBOL(i40e_unregister_client);