i40e_client.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  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. memset(&params, 0, sizeof(params));
  134. i40e_client_get_params(vsi, &params);
  135. memcpy(&cdev->lan_info.params, &params, sizeof(struct i40e_params));
  136. cdev->client->ops->l2_param_change(&cdev->lan_info, cdev->client,
  137. &params);
  138. }
  139. /**
  140. * i40e_client_release_qvlist - release MSI-X vector mapping for client
  141. * @ldev: pointer to L2 context.
  142. *
  143. **/
  144. static void i40e_client_release_qvlist(struct i40e_info *ldev)
  145. {
  146. struct i40e_qvlist_info *qvlist_info = ldev->qvlist_info;
  147. u32 i;
  148. if (!ldev->qvlist_info)
  149. return;
  150. for (i = 0; i < qvlist_info->num_vectors; i++) {
  151. struct i40e_pf *pf = ldev->pf;
  152. struct i40e_qv_info *qv_info;
  153. u32 reg_idx;
  154. qv_info = &qvlist_info->qv_info[i];
  155. if (!qv_info)
  156. continue;
  157. reg_idx = I40E_PFINT_LNKLSTN(qv_info->v_idx - 1);
  158. wr32(&pf->hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  159. }
  160. kfree(ldev->qvlist_info);
  161. ldev->qvlist_info = NULL;
  162. }
  163. /**
  164. * i40e_notify_client_of_netdev_close - call the client close callback
  165. * @vsi: the VSI with netdev closed
  166. * @reset: true when close called due to a reset pending
  167. *
  168. * If there is a client to this netdev, call the client with close
  169. **/
  170. void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
  171. {
  172. struct i40e_pf *pf = vsi->back;
  173. struct i40e_client_instance *cdev = pf->cinst;
  174. if (!cdev || !cdev->client)
  175. return;
  176. if (!cdev->client->ops || !cdev->client->ops->close) {
  177. dev_dbg(&vsi->back->pdev->dev,
  178. "Cannot locate client instance close routine\n");
  179. return;
  180. }
  181. cdev->client->ops->close(&cdev->lan_info, cdev->client, reset);
  182. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  183. i40e_client_release_qvlist(&cdev->lan_info);
  184. }
  185. /**
  186. * i40e_notify_client_of_vf_reset - call the client vf reset callback
  187. * @pf: PF device pointer
  188. * @vf_id: asolute id of VF being reset
  189. *
  190. * If there is a client attached to this PF, notify when a VF is reset
  191. **/
  192. void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id)
  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_reset) {
  198. dev_dbg(&pf->pdev->dev,
  199. "Cannot locate client instance VF reset routine\n");
  200. return;
  201. }
  202. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  203. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-reset\n");
  204. return;
  205. }
  206. cdev->client->ops->vf_reset(&cdev->lan_info, cdev->client, vf_id);
  207. }
  208. /**
  209. * i40e_notify_client_of_vf_enable - call the client vf notification callback
  210. * @pf: PF device pointer
  211. * @num_vfs: the number of VFs currently enabled, 0 for disable
  212. *
  213. * If there is a client attached to this PF, call its VF notification routine
  214. **/
  215. void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs)
  216. {
  217. struct i40e_client_instance *cdev = pf->cinst;
  218. if (!cdev || !cdev->client)
  219. return;
  220. if (!cdev->client->ops || !cdev->client->ops->vf_enable) {
  221. dev_dbg(&pf->pdev->dev,
  222. "Cannot locate client instance VF enable routine\n");
  223. return;
  224. }
  225. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED,
  226. &cdev->state)) {
  227. dev_dbg(&pf->pdev->dev, "Client is not open, abort vf-enable\n");
  228. return;
  229. }
  230. cdev->client->ops->vf_enable(&cdev->lan_info, cdev->client, num_vfs);
  231. }
  232. /**
  233. * i40e_vf_client_capable - ask the client if it likes the specified VF
  234. * @pf: PF device pointer
  235. * @vf_id: the VF in question
  236. *
  237. * If there is a client of the specified type attached to this PF, call
  238. * its vf_capable routine
  239. **/
  240. int i40e_vf_client_capable(struct i40e_pf *pf, u32 vf_id)
  241. {
  242. struct i40e_client_instance *cdev = pf->cinst;
  243. int capable = false;
  244. if (!cdev || !cdev->client)
  245. goto out;
  246. if (!cdev->client->ops || !cdev->client->ops->vf_capable) {
  247. dev_info(&pf->pdev->dev,
  248. "Cannot locate client instance VF capability routine\n");
  249. goto out;
  250. }
  251. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state))
  252. goto out;
  253. capable = cdev->client->ops->vf_capable(&cdev->lan_info,
  254. cdev->client,
  255. vf_id);
  256. out:
  257. return capable;
  258. }
  259. /**
  260. * i40e_client_add_instance - add a client instance struct to the instance list
  261. * @pf: pointer to the board struct
  262. * @client: pointer to a client struct in the client list.
  263. * @existing: if there was already an existing instance
  264. *
  265. **/
  266. static void i40e_client_add_instance(struct i40e_pf *pf)
  267. {
  268. struct i40e_client_instance *cdev = NULL;
  269. struct netdev_hw_addr *mac = NULL;
  270. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  271. if (!registered_client || pf->cinst)
  272. return;
  273. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  274. if (!cdev)
  275. return;
  276. cdev->lan_info.pf = (void *)pf;
  277. cdev->lan_info.netdev = vsi->netdev;
  278. cdev->lan_info.pcidev = pf->pdev;
  279. cdev->lan_info.fid = pf->hw.pf_id;
  280. cdev->lan_info.ftype = I40E_CLIENT_FTYPE_PF;
  281. cdev->lan_info.hw_addr = pf->hw.hw_addr;
  282. cdev->lan_info.ops = &i40e_lan_ops;
  283. cdev->lan_info.version.major = I40E_CLIENT_VERSION_MAJOR;
  284. cdev->lan_info.version.minor = I40E_CLIENT_VERSION_MINOR;
  285. cdev->lan_info.version.build = I40E_CLIENT_VERSION_BUILD;
  286. cdev->lan_info.fw_maj_ver = pf->hw.aq.fw_maj_ver;
  287. cdev->lan_info.fw_min_ver = pf->hw.aq.fw_min_ver;
  288. cdev->lan_info.fw_build = pf->hw.aq.fw_build;
  289. set_bit(__I40E_CLIENT_INSTANCE_NONE, &cdev->state);
  290. if (i40e_client_get_params(vsi, &cdev->lan_info.params)) {
  291. kfree(cdev);
  292. cdev = NULL;
  293. return;
  294. }
  295. cdev->lan_info.msix_count = pf->num_iwarp_msix;
  296. cdev->lan_info.msix_entries = &pf->msix_entries[pf->iwarp_base_vector];
  297. mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
  298. struct netdev_hw_addr, list);
  299. if (mac)
  300. ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
  301. else
  302. dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
  303. cdev->client = registered_client;
  304. pf->cinst = cdev;
  305. }
  306. /**
  307. * i40e_client_del_instance - removes a client instance from the list
  308. * @pf: pointer to the board struct
  309. *
  310. **/
  311. static
  312. void i40e_client_del_instance(struct i40e_pf *pf)
  313. {
  314. kfree(pf->cinst);
  315. pf->cinst = NULL;
  316. }
  317. /**
  318. * i40e_client_subtask - client maintenance work
  319. * @pf: board private structure
  320. **/
  321. void i40e_client_subtask(struct i40e_pf *pf)
  322. {
  323. struct i40e_client *client = registered_client;
  324. struct i40e_client_instance *cdev;
  325. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  326. int ret = 0;
  327. if (!(pf->flags & I40E_FLAG_SERVICE_CLIENT_REQUESTED))
  328. return;
  329. pf->flags &= ~I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  330. cdev = pf->cinst;
  331. /* If we're down or resetting, just bail */
  332. if (test_bit(__I40E_DOWN, &pf->state) ||
  333. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  334. return;
  335. if (!client || !cdev)
  336. return;
  337. /* Here we handle client opens. If the client is down, but
  338. * the netdev is up, then open the client.
  339. */
  340. if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  341. if (!test_bit(__I40E_DOWN, &vsi->state) &&
  342. client->ops && client->ops->open) {
  343. set_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  344. ret = client->ops->open(&cdev->lan_info, client);
  345. if (ret) {
  346. /* Remove failed client instance */
  347. clear_bit(__I40E_CLIENT_INSTANCE_OPENED,
  348. &cdev->state);
  349. i40e_client_del_instance(pf);
  350. }
  351. }
  352. } else {
  353. /* Likewise for client close. If the client is up, but the netdev
  354. * is down, then close the client.
  355. */
  356. if (test_bit(__I40E_DOWN, &vsi->state) &&
  357. client->ops && client->ops->close) {
  358. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  359. client->ops->close(&cdev->lan_info, client, false);
  360. i40e_client_release_qvlist(&cdev->lan_info);
  361. }
  362. }
  363. }
  364. /**
  365. * i40e_lan_add_device - add a lan device struct to the list of lan devices
  366. * @pf: pointer to the board struct
  367. *
  368. * Returns 0 on success or none 0 on error
  369. **/
  370. int i40e_lan_add_device(struct i40e_pf *pf)
  371. {
  372. struct i40e_device *ldev;
  373. int ret = 0;
  374. mutex_lock(&i40e_device_mutex);
  375. list_for_each_entry(ldev, &i40e_devices, list) {
  376. if (ldev->pf == pf) {
  377. ret = -EEXIST;
  378. goto out;
  379. }
  380. }
  381. ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
  382. if (!ldev) {
  383. ret = -ENOMEM;
  384. goto out;
  385. }
  386. ldev->pf = pf;
  387. INIT_LIST_HEAD(&ldev->list);
  388. list_add(&ldev->list, &i40e_devices);
  389. dev_info(&pf->pdev->dev, "Added LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  390. pf->hw.pf_id, pf->hw.bus.bus_id,
  391. pf->hw.bus.device, pf->hw.bus.func);
  392. /* Since in some cases register may have happened before a device gets
  393. * added, we can schedule a subtask to go initiate the clients if
  394. * they can be launched at probe time.
  395. */
  396. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  397. i40e_service_event_schedule(pf);
  398. out:
  399. mutex_unlock(&i40e_device_mutex);
  400. return ret;
  401. }
  402. /**
  403. * i40e_lan_del_device - removes a lan device from the device list
  404. * @pf: pointer to the board struct
  405. *
  406. * Returns 0 on success or non-0 on error
  407. **/
  408. int i40e_lan_del_device(struct i40e_pf *pf)
  409. {
  410. struct i40e_device *ldev, *tmp;
  411. int ret = -ENODEV;
  412. mutex_lock(&i40e_device_mutex);
  413. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  414. if (ldev->pf == pf) {
  415. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  416. pf->hw.pf_id, pf->hw.bus.bus_id,
  417. pf->hw.bus.device, pf->hw.bus.func);
  418. list_del(&ldev->list);
  419. kfree(ldev);
  420. ret = 0;
  421. break;
  422. }
  423. }
  424. mutex_unlock(&i40e_device_mutex);
  425. return ret;
  426. }
  427. /**
  428. * i40e_client_release - release client specific resources
  429. * @client: pointer to the registered client
  430. *
  431. **/
  432. static void i40e_client_release(struct i40e_client *client)
  433. {
  434. struct i40e_client_instance *cdev;
  435. struct i40e_device *ldev;
  436. struct i40e_pf *pf;
  437. mutex_lock(&i40e_device_mutex);
  438. list_for_each_entry(ldev, &i40e_devices, list) {
  439. pf = ldev->pf;
  440. cdev = pf->cinst;
  441. if (!cdev)
  442. continue;
  443. while (test_and_set_bit(__I40E_SERVICE_SCHED,
  444. &pf->state))
  445. usleep_range(500, 1000);
  446. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  447. if (client->ops && client->ops->close)
  448. client->ops->close(&cdev->lan_info, client,
  449. false);
  450. i40e_client_release_qvlist(&cdev->lan_info);
  451. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  452. dev_warn(&pf->pdev->dev,
  453. "Client %s instance for PF id %d closed\n",
  454. client->name, pf->hw.pf_id);
  455. }
  456. /* delete the client instance */
  457. i40e_client_del_instance(pf);
  458. dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
  459. client->name);
  460. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  461. }
  462. mutex_unlock(&i40e_device_mutex);
  463. }
  464. /**
  465. * i40e_client_prepare - prepare client specific resources
  466. * @client: pointer to the registered client
  467. *
  468. **/
  469. static void i40e_client_prepare(struct i40e_client *client)
  470. {
  471. struct i40e_device *ldev;
  472. struct i40e_pf *pf;
  473. mutex_lock(&i40e_device_mutex);
  474. list_for_each_entry(ldev, &i40e_devices, list) {
  475. pf = ldev->pf;
  476. i40e_client_add_instance(pf);
  477. /* Start the client subtask */
  478. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  479. i40e_service_event_schedule(pf);
  480. }
  481. mutex_unlock(&i40e_device_mutex);
  482. }
  483. /**
  484. * i40e_client_virtchnl_send - TBD
  485. * @ldev: pointer to L2 context
  486. * @client: Client pointer
  487. * @vf_id: absolute VF identifier
  488. * @msg: message buffer
  489. * @len: length of message buffer
  490. *
  491. * Return 0 on success or < 0 on error
  492. **/
  493. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  494. struct i40e_client *client,
  495. u32 vf_id, u8 *msg, u16 len)
  496. {
  497. struct i40e_pf *pf = ldev->pf;
  498. struct i40e_hw *hw = &pf->hw;
  499. i40e_status err;
  500. err = i40e_aq_send_msg_to_vf(hw, vf_id, I40E_VIRTCHNL_OP_IWARP,
  501. 0, msg, len, NULL);
  502. if (err)
  503. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  504. err, hw->aq.asq_last_status);
  505. return err;
  506. }
  507. /**
  508. * i40e_client_setup_qvlist
  509. * @ldev: pointer to L2 context.
  510. * @client: Client pointer.
  511. * @qv_info: queue and vector list
  512. *
  513. * Return 0 on success or < 0 on error
  514. **/
  515. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  516. struct i40e_client *client,
  517. struct i40e_qvlist_info *qvlist_info)
  518. {
  519. struct i40e_pf *pf = ldev->pf;
  520. struct i40e_hw *hw = &pf->hw;
  521. struct i40e_qv_info *qv_info;
  522. u32 v_idx, i, reg_idx, reg;
  523. u32 size;
  524. size = sizeof(struct i40e_qvlist_info) +
  525. (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
  526. ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
  527. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  528. for (i = 0; i < qvlist_info->num_vectors; i++) {
  529. qv_info = &qvlist_info->qv_info[i];
  530. if (!qv_info)
  531. continue;
  532. v_idx = qv_info->v_idx;
  533. /* Validate vector id belongs to this client */
  534. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  535. (v_idx < pf->iwarp_base_vector))
  536. goto err;
  537. ldev->qvlist_info->qv_info[i] = *qv_info;
  538. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  539. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  540. /* Special case - No CEQ mapped on this vector */
  541. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  542. } else {
  543. reg = (qv_info->ceq_idx &
  544. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  545. (I40E_QUEUE_TYPE_PE_CEQ <<
  546. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  547. wr32(hw, reg_idx, reg);
  548. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  549. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  550. (qv_info->itr_idx <<
  551. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  552. (I40E_QUEUE_END_OF_LIST <<
  553. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  554. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  555. }
  556. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  557. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  558. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  559. (qv_info->itr_idx <<
  560. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  561. wr32(hw, I40E_PFINT_AEQCTL, reg);
  562. }
  563. }
  564. /* Mitigate sync problems with iwarp VF driver */
  565. i40e_flush(hw);
  566. return 0;
  567. err:
  568. kfree(ldev->qvlist_info);
  569. ldev->qvlist_info = NULL;
  570. return -EINVAL;
  571. }
  572. /**
  573. * i40e_client_request_reset
  574. * @ldev: pointer to L2 context.
  575. * @client: Client pointer.
  576. * @level: reset level
  577. **/
  578. static void i40e_client_request_reset(struct i40e_info *ldev,
  579. struct i40e_client *client,
  580. u32 reset_level)
  581. {
  582. struct i40e_pf *pf = ldev->pf;
  583. switch (reset_level) {
  584. case I40E_CLIENT_RESET_LEVEL_PF:
  585. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  586. break;
  587. case I40E_CLIENT_RESET_LEVEL_CORE:
  588. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  589. break;
  590. default:
  591. dev_warn(&pf->pdev->dev,
  592. "Client for PF id %d requested an unsupported reset: %d.\n",
  593. pf->hw.pf_id, reset_level);
  594. break;
  595. }
  596. i40e_service_event_schedule(pf);
  597. }
  598. /**
  599. * i40e_client_update_vsi_ctxt
  600. * @ldev: pointer to L2 context.
  601. * @client: Client pointer.
  602. * @is_vf: if this for the VF
  603. * @vf_id: if is_vf true this carries the vf_id
  604. * @flag: Any device level setting that needs to be done for PE
  605. * @valid_flag: Bits in this match up and enable changing of flag bits
  606. *
  607. * Return 0 on success or < 0 on error
  608. **/
  609. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  610. struct i40e_client *client,
  611. bool is_vf, u32 vf_id,
  612. u32 flag, u32 valid_flag)
  613. {
  614. struct i40e_pf *pf = ldev->pf;
  615. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  616. struct i40e_vsi_context ctxt;
  617. bool update = true;
  618. i40e_status err;
  619. /* TODO: for now do not allow setting VF's VSI setting */
  620. if (is_vf)
  621. return -EINVAL;
  622. ctxt.seid = pf->main_vsi_seid;
  623. ctxt.pf_num = pf->hw.pf_id;
  624. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  625. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  626. if (err) {
  627. dev_info(&pf->pdev->dev,
  628. "couldn't get PF vsi config, err %s aq_err %s\n",
  629. i40e_stat_str(&pf->hw, err),
  630. i40e_aq_str(&pf->hw,
  631. pf->hw.aq.asq_last_status));
  632. return -ENOENT;
  633. }
  634. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  635. (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  636. ctxt.info.valid_sections =
  637. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  638. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  639. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  640. !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  641. ctxt.info.valid_sections =
  642. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  643. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  644. } else {
  645. update = false;
  646. dev_warn(&pf->pdev->dev,
  647. "Client for PF id %d request an unsupported Config: %x.\n",
  648. pf->hw.pf_id, flag);
  649. }
  650. if (update) {
  651. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  652. if (err) {
  653. dev_info(&pf->pdev->dev,
  654. "update VSI ctxt for PE failed, err %s aq_err %s\n",
  655. i40e_stat_str(&pf->hw, err),
  656. i40e_aq_str(&pf->hw,
  657. pf->hw.aq.asq_last_status));
  658. }
  659. }
  660. return err;
  661. }
  662. /**
  663. * i40e_register_client - Register a i40e client driver with the L2 driver
  664. * @client: pointer to the i40e_client struct
  665. *
  666. * Returns 0 on success or non-0 on error
  667. **/
  668. int i40e_register_client(struct i40e_client *client)
  669. {
  670. int ret = 0;
  671. if (!client) {
  672. ret = -EIO;
  673. goto out;
  674. }
  675. if (strlen(client->name) == 0) {
  676. pr_info("i40e: Failed to register client with no name\n");
  677. ret = -EIO;
  678. goto out;
  679. }
  680. if (registered_client) {
  681. pr_info("i40e: Client %s has already been registered!\n",
  682. client->name);
  683. ret = -EEXIST;
  684. goto out;
  685. }
  686. if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
  687. (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
  688. pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
  689. client->name);
  690. pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
  691. client->version.major, client->version.minor,
  692. client->version.build,
  693. i40e_client_interface_version_str);
  694. ret = -EIO;
  695. goto out;
  696. }
  697. registered_client = client;
  698. i40e_client_prepare(client);
  699. pr_info("i40e: Registered client %s\n", client->name);
  700. out:
  701. return ret;
  702. }
  703. EXPORT_SYMBOL(i40e_register_client);
  704. /**
  705. * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
  706. * @client: pointer to the i40e_client struct
  707. *
  708. * Returns 0 on success or non-0 on error
  709. **/
  710. int i40e_unregister_client(struct i40e_client *client)
  711. {
  712. int ret = 0;
  713. if (registered_client != client) {
  714. pr_info("i40e: Client %s has not been registered\n",
  715. client->name);
  716. ret = -ENODEV;
  717. goto out;
  718. }
  719. registered_client = NULL;
  720. /* When a unregister request comes through we would have to send
  721. * a close for each of the client instances that were opened.
  722. * client_release function is called to handle this.
  723. */
  724. i40e_client_release(client);
  725. pr_info("i40e: Unregistered client %s\n", client->name);
  726. out:
  727. return ret;
  728. }
  729. EXPORT_SYMBOL(i40e_unregister_client);