i40e_client.c 23 KB

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