i40e_client.c 23 KB

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