i40e_client.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2017 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_dbg(&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_VSI_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_VSI_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. /* If a client has already been registered, we need to add an instance
  393. * of it to our new LAN device.
  394. */
  395. if (registered_client)
  396. i40e_client_add_instance(pf);
  397. /* Since in some cases register may have happened before a device gets
  398. * added, we can schedule a subtask to go initiate the clients if
  399. * they can be launched at probe time.
  400. */
  401. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  402. i40e_service_event_schedule(pf);
  403. out:
  404. mutex_unlock(&i40e_device_mutex);
  405. return ret;
  406. }
  407. /**
  408. * i40e_lan_del_device - removes a lan device from the device list
  409. * @pf: pointer to the board struct
  410. *
  411. * Returns 0 on success or non-0 on error
  412. **/
  413. int i40e_lan_del_device(struct i40e_pf *pf)
  414. {
  415. struct i40e_device *ldev, *tmp;
  416. int ret = -ENODEV;
  417. /* First, remove any client instance. */
  418. i40e_client_del_instance(pf);
  419. mutex_lock(&i40e_device_mutex);
  420. list_for_each_entry_safe(ldev, tmp, &i40e_devices, list) {
  421. if (ldev->pf == pf) {
  422. dev_info(&pf->pdev->dev, "Deleted LAN device PF%d bus=0x%02x dev=0x%02x func=0x%02x\n",
  423. pf->hw.pf_id, pf->hw.bus.bus_id,
  424. pf->hw.bus.device, pf->hw.bus.func);
  425. list_del(&ldev->list);
  426. kfree(ldev);
  427. ret = 0;
  428. break;
  429. }
  430. }
  431. mutex_unlock(&i40e_device_mutex);
  432. return ret;
  433. }
  434. /**
  435. * i40e_client_release - release client specific resources
  436. * @client: pointer to the registered client
  437. *
  438. **/
  439. static void i40e_client_release(struct i40e_client *client)
  440. {
  441. struct i40e_client_instance *cdev;
  442. struct i40e_device *ldev;
  443. struct i40e_pf *pf;
  444. mutex_lock(&i40e_device_mutex);
  445. list_for_each_entry(ldev, &i40e_devices, list) {
  446. pf = ldev->pf;
  447. cdev = pf->cinst;
  448. if (!cdev)
  449. continue;
  450. while (test_and_set_bit(__I40E_SERVICE_SCHED,
  451. pf->state))
  452. usleep_range(500, 1000);
  453. if (test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
  454. if (client->ops && client->ops->close)
  455. client->ops->close(&cdev->lan_info, client,
  456. false);
  457. i40e_client_release_qvlist(&cdev->lan_info);
  458. clear_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state);
  459. dev_warn(&pf->pdev->dev,
  460. "Client %s instance for PF id %d closed\n",
  461. client->name, pf->hw.pf_id);
  462. }
  463. /* delete the client instance */
  464. i40e_client_del_instance(pf);
  465. dev_info(&pf->pdev->dev, "Deleted client instance of Client %s\n",
  466. client->name);
  467. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  468. }
  469. mutex_unlock(&i40e_device_mutex);
  470. }
  471. /**
  472. * i40e_client_prepare - prepare client specific resources
  473. * @client: pointer to the registered client
  474. *
  475. **/
  476. static void i40e_client_prepare(struct i40e_client *client)
  477. {
  478. struct i40e_device *ldev;
  479. struct i40e_pf *pf;
  480. mutex_lock(&i40e_device_mutex);
  481. list_for_each_entry(ldev, &i40e_devices, list) {
  482. pf = ldev->pf;
  483. i40e_client_add_instance(pf);
  484. /* Start the client subtask */
  485. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  486. i40e_service_event_schedule(pf);
  487. }
  488. mutex_unlock(&i40e_device_mutex);
  489. }
  490. /**
  491. * i40e_client_virtchnl_send - TBD
  492. * @ldev: pointer to L2 context
  493. * @client: Client pointer
  494. * @vf_id: absolute VF identifier
  495. * @msg: message buffer
  496. * @len: length of message buffer
  497. *
  498. * Return 0 on success or < 0 on error
  499. **/
  500. static int i40e_client_virtchnl_send(struct i40e_info *ldev,
  501. struct i40e_client *client,
  502. u32 vf_id, u8 *msg, u16 len)
  503. {
  504. struct i40e_pf *pf = ldev->pf;
  505. struct i40e_hw *hw = &pf->hw;
  506. i40e_status err;
  507. err = i40e_aq_send_msg_to_vf(hw, vf_id, VIRTCHNL_OP_IWARP,
  508. 0, msg, len, NULL);
  509. if (err)
  510. dev_err(&pf->pdev->dev, "Unable to send iWarp message to VF, error %d, aq status %d\n",
  511. err, hw->aq.asq_last_status);
  512. return err;
  513. }
  514. /**
  515. * i40e_client_setup_qvlist
  516. * @ldev: pointer to L2 context.
  517. * @client: Client pointer.
  518. * @qv_info: queue and vector list
  519. *
  520. * Return 0 on success or < 0 on error
  521. **/
  522. static int i40e_client_setup_qvlist(struct i40e_info *ldev,
  523. struct i40e_client *client,
  524. struct i40e_qvlist_info *qvlist_info)
  525. {
  526. struct i40e_pf *pf = ldev->pf;
  527. struct i40e_hw *hw = &pf->hw;
  528. struct i40e_qv_info *qv_info;
  529. u32 v_idx, i, reg_idx, reg;
  530. u32 size;
  531. size = sizeof(struct i40e_qvlist_info) +
  532. (sizeof(struct i40e_qv_info) * (qvlist_info->num_vectors - 1));
  533. ldev->qvlist_info = kzalloc(size, GFP_KERNEL);
  534. if (!ldev->qvlist_info)
  535. return -ENOMEM;
  536. ldev->qvlist_info->num_vectors = qvlist_info->num_vectors;
  537. for (i = 0; i < qvlist_info->num_vectors; i++) {
  538. qv_info = &qvlist_info->qv_info[i];
  539. if (!qv_info)
  540. continue;
  541. v_idx = qv_info->v_idx;
  542. /* Validate vector id belongs to this client */
  543. if ((v_idx >= (pf->iwarp_base_vector + pf->num_iwarp_msix)) ||
  544. (v_idx < pf->iwarp_base_vector))
  545. goto err;
  546. ldev->qvlist_info->qv_info[i] = *qv_info;
  547. reg_idx = I40E_PFINT_LNKLSTN(v_idx - 1);
  548. if (qv_info->ceq_idx == I40E_QUEUE_INVALID_IDX) {
  549. /* Special case - No CEQ mapped on this vector */
  550. wr32(hw, reg_idx, I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
  551. } else {
  552. reg = (qv_info->ceq_idx &
  553. I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  554. (I40E_QUEUE_TYPE_PE_CEQ <<
  555. I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  556. wr32(hw, reg_idx, reg);
  557. reg = (I40E_PFINT_CEQCTL_CAUSE_ENA_MASK |
  558. (v_idx << I40E_PFINT_CEQCTL_MSIX_INDX_SHIFT) |
  559. (qv_info->itr_idx <<
  560. I40E_PFINT_CEQCTL_ITR_INDX_SHIFT) |
  561. (I40E_QUEUE_END_OF_LIST <<
  562. I40E_PFINT_CEQCTL_NEXTQ_INDX_SHIFT));
  563. wr32(hw, I40E_PFINT_CEQCTL(qv_info->ceq_idx), reg);
  564. }
  565. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  566. reg = (I40E_PFINT_AEQCTL_CAUSE_ENA_MASK |
  567. (v_idx << I40E_PFINT_AEQCTL_MSIX_INDX_SHIFT) |
  568. (qv_info->itr_idx <<
  569. I40E_PFINT_AEQCTL_ITR_INDX_SHIFT));
  570. wr32(hw, I40E_PFINT_AEQCTL, reg);
  571. }
  572. }
  573. /* Mitigate sync problems with iwarp VF driver */
  574. i40e_flush(hw);
  575. return 0;
  576. err:
  577. kfree(ldev->qvlist_info);
  578. ldev->qvlist_info = NULL;
  579. return -EINVAL;
  580. }
  581. /**
  582. * i40e_client_request_reset
  583. * @ldev: pointer to L2 context.
  584. * @client: Client pointer.
  585. * @level: reset level
  586. **/
  587. static void i40e_client_request_reset(struct i40e_info *ldev,
  588. struct i40e_client *client,
  589. u32 reset_level)
  590. {
  591. struct i40e_pf *pf = ldev->pf;
  592. switch (reset_level) {
  593. case I40E_CLIENT_RESET_LEVEL_PF:
  594. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  595. break;
  596. case I40E_CLIENT_RESET_LEVEL_CORE:
  597. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  598. break;
  599. default:
  600. dev_warn(&pf->pdev->dev,
  601. "Client for PF id %d requested an unsupported reset: %d.\n",
  602. pf->hw.pf_id, reset_level);
  603. break;
  604. }
  605. i40e_service_event_schedule(pf);
  606. }
  607. /**
  608. * i40e_client_update_vsi_ctxt
  609. * @ldev: pointer to L2 context.
  610. * @client: Client pointer.
  611. * @is_vf: if this for the VF
  612. * @vf_id: if is_vf true this carries the vf_id
  613. * @flag: Any device level setting that needs to be done for PE
  614. * @valid_flag: Bits in this match up and enable changing of flag bits
  615. *
  616. * Return 0 on success or < 0 on error
  617. **/
  618. static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
  619. struct i40e_client *client,
  620. bool is_vf, u32 vf_id,
  621. u32 flag, u32 valid_flag)
  622. {
  623. struct i40e_pf *pf = ldev->pf;
  624. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  625. struct i40e_vsi_context ctxt;
  626. bool update = true;
  627. i40e_status err;
  628. /* TODO: for now do not allow setting VF's VSI setting */
  629. if (is_vf)
  630. return -EINVAL;
  631. ctxt.seid = pf->main_vsi_seid;
  632. ctxt.pf_num = pf->hw.pf_id;
  633. err = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  634. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  635. if (err) {
  636. dev_info(&pf->pdev->dev,
  637. "couldn't get PF vsi config, err %s aq_err %s\n",
  638. i40e_stat_str(&pf->hw, err),
  639. i40e_aq_str(&pf->hw,
  640. pf->hw.aq.asq_last_status));
  641. return -ENOENT;
  642. }
  643. if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  644. (flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  645. ctxt.info.valid_sections =
  646. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  647. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  648. } else if ((valid_flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE) &&
  649. !(flag & I40E_CLIENT_VSI_FLAG_TCP_PACKET_ENABLE)) {
  650. ctxt.info.valid_sections =
  651. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  652. ctxt.info.queueing_opt_flags &= ~I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  653. } else {
  654. update = false;
  655. dev_warn(&pf->pdev->dev,
  656. "Client for PF id %d request an unsupported Config: %x.\n",
  657. pf->hw.pf_id, flag);
  658. }
  659. if (update) {
  660. err = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  661. if (err) {
  662. dev_info(&pf->pdev->dev,
  663. "update VSI ctxt for PE failed, err %s aq_err %s\n",
  664. i40e_stat_str(&pf->hw, err),
  665. i40e_aq_str(&pf->hw,
  666. pf->hw.aq.asq_last_status));
  667. }
  668. }
  669. return err;
  670. }
  671. /**
  672. * i40e_register_client - Register a i40e client driver with the L2 driver
  673. * @client: pointer to the i40e_client struct
  674. *
  675. * Returns 0 on success or non-0 on error
  676. **/
  677. int i40e_register_client(struct i40e_client *client)
  678. {
  679. int ret = 0;
  680. if (!client) {
  681. ret = -EIO;
  682. goto out;
  683. }
  684. if (strlen(client->name) == 0) {
  685. pr_info("i40e: Failed to register client with no name\n");
  686. ret = -EIO;
  687. goto out;
  688. }
  689. if (registered_client) {
  690. pr_info("i40e: Client %s has already been registered!\n",
  691. client->name);
  692. ret = -EEXIST;
  693. goto out;
  694. }
  695. if ((client->version.major != I40E_CLIENT_VERSION_MAJOR) ||
  696. (client->version.minor != I40E_CLIENT_VERSION_MINOR)) {
  697. pr_info("i40e: Failed to register client %s due to mismatched client interface version\n",
  698. client->name);
  699. pr_info("Client is using version: %02d.%02d.%02d while LAN driver supports %s\n",
  700. client->version.major, client->version.minor,
  701. client->version.build,
  702. i40e_client_interface_version_str);
  703. ret = -EIO;
  704. goto out;
  705. }
  706. registered_client = client;
  707. i40e_client_prepare(client);
  708. pr_info("i40e: Registered client %s\n", client->name);
  709. out:
  710. return ret;
  711. }
  712. EXPORT_SYMBOL(i40e_register_client);
  713. /**
  714. * i40e_unregister_client - Unregister a i40e client driver with the L2 driver
  715. * @client: pointer to the i40e_client struct
  716. *
  717. * Returns 0 on success or non-0 on error
  718. **/
  719. int i40e_unregister_client(struct i40e_client *client)
  720. {
  721. int ret = 0;
  722. if (registered_client != client) {
  723. pr_info("i40e: Client %s has not been registered\n",
  724. client->name);
  725. ret = -ENODEV;
  726. goto out;
  727. }
  728. registered_client = NULL;
  729. /* When a unregister request comes through we would have to send
  730. * a close for each of the client instances that were opened.
  731. * client_release function is called to handle this.
  732. */
  733. i40e_client_release(client);
  734. pr_info("i40e: Unregistered client %s\n", client->name);
  735. out:
  736. return ret;
  737. }
  738. EXPORT_SYMBOL(i40e_unregister_client);