fm10k_iov.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Intel(R) Ethernet Switch Host Interface Driver
  3. * Copyright(c) 2013 - 2017 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in
  15. * the file called "COPYING".
  16. *
  17. * Contact Information:
  18. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. #include "fm10k.h"
  22. #include "fm10k_vf.h"
  23. #include "fm10k_pf.h"
  24. static s32 fm10k_iov_msg_error(struct fm10k_hw *hw, u32 **results,
  25. struct fm10k_mbx_info *mbx)
  26. {
  27. struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
  28. struct fm10k_intfc *interface = hw->back;
  29. struct pci_dev *pdev = interface->pdev;
  30. dev_err(&pdev->dev, "Unknown message ID %u on VF %d\n",
  31. **results & FM10K_TLV_ID_MASK, vf_info->vf_idx);
  32. return fm10k_tlv_msg_error(hw, results, mbx);
  33. }
  34. /**
  35. * fm10k_iov_msg_queue_mac_vlan - Message handler for MAC/VLAN request from VF
  36. * @hw: Pointer to hardware structure
  37. * @results: Pointer array to message, results[0] is pointer to message
  38. * @mbx: Pointer to mailbox information structure
  39. *
  40. * This function is a custom handler for MAC/VLAN requests from the VF. The
  41. * assumption is that it is acceptable to directly hand off the message from
  42. * the VF to the PF's switch manager. However, we use a MAC/VLAN message
  43. * queue to avoid overloading the mailbox when a large number of requests
  44. * come in.
  45. **/
  46. static s32 fm10k_iov_msg_queue_mac_vlan(struct fm10k_hw *hw, u32 **results,
  47. struct fm10k_mbx_info *mbx)
  48. {
  49. struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
  50. struct fm10k_intfc *interface = hw->back;
  51. u8 mac[ETH_ALEN];
  52. u32 *result;
  53. int err = 0;
  54. bool set;
  55. u16 vlan;
  56. u32 vid;
  57. /* we shouldn't be updating rules on a disabled interface */
  58. if (!FM10K_VF_FLAG_ENABLED(vf_info))
  59. err = FM10K_ERR_PARAM;
  60. if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) {
  61. result = results[FM10K_MAC_VLAN_MSG_VLAN];
  62. /* record VLAN id requested */
  63. err = fm10k_tlv_attr_get_u32(result, &vid);
  64. if (err)
  65. return err;
  66. set = !(vid & FM10K_VLAN_CLEAR);
  67. vid &= ~FM10K_VLAN_CLEAR;
  68. /* if the length field has been set, this is a multi-bit
  69. * update request. For multi-bit requests, simply disallow
  70. * them when the pf_vid has been set. In this case, the PF
  71. * should have already cleared the VLAN_TABLE, and if we
  72. * allowed them, it could allow a rogue VF to receive traffic
  73. * on a VLAN it was not assigned. In the single-bit case, we
  74. * need to modify requests for VLAN 0 to use the default PF or
  75. * SW vid when assigned.
  76. */
  77. if (vid >> 16) {
  78. /* prevent multi-bit requests when PF has
  79. * administratively set the VLAN for this VF
  80. */
  81. if (vf_info->pf_vid)
  82. return FM10K_ERR_PARAM;
  83. } else {
  84. err = fm10k_iov_select_vid(vf_info, (u16)vid);
  85. if (err < 0)
  86. return err;
  87. vid = err;
  88. }
  89. /* update VSI info for VF in regards to VLAN table */
  90. err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
  91. }
  92. if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
  93. result = results[FM10K_MAC_VLAN_MSG_MAC];
  94. /* record unicast MAC address requested */
  95. err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
  96. if (err)
  97. return err;
  98. /* block attempts to set MAC for a locked device */
  99. if (is_valid_ether_addr(vf_info->mac) &&
  100. !ether_addr_equal(mac, vf_info->mac))
  101. return FM10K_ERR_PARAM;
  102. set = !(vlan & FM10K_VLAN_CLEAR);
  103. vlan &= ~FM10K_VLAN_CLEAR;
  104. err = fm10k_iov_select_vid(vf_info, vlan);
  105. if (err < 0)
  106. return err;
  107. vlan = (u16)err;
  108. /* Add this request to the MAC/VLAN queue */
  109. err = fm10k_queue_mac_request(interface, vf_info->glort,
  110. mac, vlan, set);
  111. }
  112. if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
  113. result = results[FM10K_MAC_VLAN_MSG_MULTICAST];
  114. /* record multicast MAC address requested */
  115. err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
  116. if (err)
  117. return err;
  118. /* verify that the VF is allowed to request multicast */
  119. if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
  120. return FM10K_ERR_PARAM;
  121. set = !(vlan & FM10K_VLAN_CLEAR);
  122. vlan &= ~FM10K_VLAN_CLEAR;
  123. err = fm10k_iov_select_vid(vf_info, vlan);
  124. if (err < 0)
  125. return err;
  126. vlan = (u16)err;
  127. /* Add this request to the MAC/VLAN queue */
  128. err = fm10k_queue_mac_request(interface, vf_info->glort,
  129. mac, vlan, set);
  130. }
  131. return err;
  132. }
  133. static const struct fm10k_msg_data iov_mbx_data[] = {
  134. FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
  135. FM10K_VF_MSG_MSIX_HANDLER(fm10k_iov_msg_msix_pf),
  136. FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_iov_msg_queue_mac_vlan),
  137. FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_iov_msg_lport_state_pf),
  138. FM10K_TLV_MSG_ERROR_HANDLER(fm10k_iov_msg_error),
  139. };
  140. s32 fm10k_iov_event(struct fm10k_intfc *interface)
  141. {
  142. struct fm10k_hw *hw = &interface->hw;
  143. struct fm10k_iov_data *iov_data;
  144. s64 vflre;
  145. int i;
  146. /* if there is no iov_data then there is no mailbox to process */
  147. if (!READ_ONCE(interface->iov_data))
  148. return 0;
  149. rcu_read_lock();
  150. iov_data = interface->iov_data;
  151. /* check again now that we are in the RCU block */
  152. if (!iov_data)
  153. goto read_unlock;
  154. if (!(fm10k_read_reg(hw, FM10K_EICR) & FM10K_EICR_VFLR))
  155. goto read_unlock;
  156. /* read VFLRE to determine if any VFs have been reset */
  157. vflre = fm10k_read_reg(hw, FM10K_PFVFLRE(1));
  158. vflre <<= 32;
  159. vflre |= fm10k_read_reg(hw, FM10K_PFVFLRE(0));
  160. i = iov_data->num_vfs;
  161. for (vflre <<= 64 - i; vflre && i--; vflre += vflre) {
  162. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  163. if (vflre >= 0)
  164. continue;
  165. hw->iov.ops.reset_resources(hw, vf_info);
  166. vf_info->mbx.ops.connect(hw, &vf_info->mbx);
  167. }
  168. read_unlock:
  169. rcu_read_unlock();
  170. return 0;
  171. }
  172. s32 fm10k_iov_mbx(struct fm10k_intfc *interface)
  173. {
  174. struct fm10k_hw *hw = &interface->hw;
  175. struct fm10k_iov_data *iov_data;
  176. int i;
  177. /* if there is no iov_data then there is no mailbox to process */
  178. if (!READ_ONCE(interface->iov_data))
  179. return 0;
  180. rcu_read_lock();
  181. iov_data = interface->iov_data;
  182. /* check again now that we are in the RCU block */
  183. if (!iov_data)
  184. goto read_unlock;
  185. /* lock the mailbox for transmit and receive */
  186. fm10k_mbx_lock(interface);
  187. /* Most VF messages sent to the PF cause the PF to respond by
  188. * requesting from the SM mailbox. This means that too many VF
  189. * messages processed at once could cause a mailbox timeout on the PF.
  190. * To prevent this, store a pointer to the next VF mbx to process. Use
  191. * that as the start of the loop so that we don't starve whichever VF
  192. * got ignored on the previous run.
  193. */
  194. process_mbx:
  195. for (i = iov_data->next_vf_mbx ? : iov_data->num_vfs; i--;) {
  196. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  197. struct fm10k_mbx_info *mbx = &vf_info->mbx;
  198. u16 glort = vf_info->glort;
  199. /* process the SM mailbox first to drain outgoing messages */
  200. hw->mbx.ops.process(hw, &hw->mbx);
  201. /* verify port mapping is valid, if not reset port */
  202. if (vf_info->vf_flags && !fm10k_glort_valid_pf(hw, glort)) {
  203. hw->iov.ops.reset_lport(hw, vf_info);
  204. fm10k_clear_macvlan_queue(interface, glort, false);
  205. }
  206. /* reset VFs that have mailbox timed out */
  207. if (!mbx->timeout) {
  208. hw->iov.ops.reset_resources(hw, vf_info);
  209. mbx->ops.connect(hw, mbx);
  210. }
  211. /* guarantee we have free space in the SM mailbox */
  212. if (!hw->mbx.ops.tx_ready(&hw->mbx, FM10K_VFMBX_MSG_MTU)) {
  213. /* keep track of how many times this occurs */
  214. interface->hw_sm_mbx_full++;
  215. /* make sure we try again momentarily */
  216. fm10k_service_event_schedule(interface);
  217. break;
  218. }
  219. /* cleanup mailbox and process received messages */
  220. mbx->ops.process(hw, mbx);
  221. }
  222. /* if we stopped processing mailboxes early, update next_vf_mbx.
  223. * Otherwise, reset next_vf_mbx, and restart loop so that we process
  224. * the remaining mailboxes we skipped at the start.
  225. */
  226. if (i >= 0) {
  227. iov_data->next_vf_mbx = i + 1;
  228. } else if (iov_data->next_vf_mbx) {
  229. iov_data->next_vf_mbx = 0;
  230. goto process_mbx;
  231. }
  232. /* free the lock */
  233. fm10k_mbx_unlock(interface);
  234. read_unlock:
  235. rcu_read_unlock();
  236. return 0;
  237. }
  238. void fm10k_iov_suspend(struct pci_dev *pdev)
  239. {
  240. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  241. struct fm10k_iov_data *iov_data = interface->iov_data;
  242. struct fm10k_hw *hw = &interface->hw;
  243. int num_vfs, i;
  244. /* pull out num_vfs from iov_data */
  245. num_vfs = iov_data ? iov_data->num_vfs : 0;
  246. /* shut down queue mapping for VFs */
  247. fm10k_write_reg(hw, FM10K_DGLORTMAP(fm10k_dglort_vf_rss),
  248. FM10K_DGLORTMAP_NONE);
  249. /* Stop any active VFs and reset their resources */
  250. for (i = 0; i < num_vfs; i++) {
  251. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  252. hw->iov.ops.reset_resources(hw, vf_info);
  253. hw->iov.ops.reset_lport(hw, vf_info);
  254. fm10k_clear_macvlan_queue(interface, vf_info->glort, false);
  255. }
  256. }
  257. int fm10k_iov_resume(struct pci_dev *pdev)
  258. {
  259. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  260. struct fm10k_iov_data *iov_data = interface->iov_data;
  261. struct fm10k_dglort_cfg dglort = { 0 };
  262. struct fm10k_hw *hw = &interface->hw;
  263. int num_vfs, i;
  264. /* pull out num_vfs from iov_data */
  265. num_vfs = iov_data ? iov_data->num_vfs : 0;
  266. /* return error if iov_data is not already populated */
  267. if (!iov_data)
  268. return -ENOMEM;
  269. /* allocate hardware resources for the VFs */
  270. hw->iov.ops.assign_resources(hw, num_vfs, num_vfs);
  271. /* configure DGLORT mapping for RSS */
  272. dglort.glort = hw->mac.dglort_map & FM10K_DGLORTMAP_NONE;
  273. dglort.idx = fm10k_dglort_vf_rss;
  274. dglort.inner_rss = 1;
  275. dglort.rss_l = fls(fm10k_queues_per_pool(hw) - 1);
  276. dglort.queue_b = fm10k_vf_queue_index(hw, 0);
  277. dglort.vsi_l = fls(hw->iov.total_vfs - 1);
  278. dglort.vsi_b = 1;
  279. hw->mac.ops.configure_dglort_map(hw, &dglort);
  280. /* assign resources to the device */
  281. for (i = 0; i < num_vfs; i++) {
  282. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  283. /* allocate all but the last GLORT to the VFs */
  284. if (i == (~hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT))
  285. break;
  286. /* assign GLORT to VF, and restrict it to multicast */
  287. hw->iov.ops.set_lport(hw, vf_info, i,
  288. FM10K_VF_FLAG_MULTI_CAPABLE);
  289. /* mailbox is disconnected so we don't send a message */
  290. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  291. /* now we are ready so we can connect */
  292. vf_info->mbx.ops.connect(hw, &vf_info->mbx);
  293. }
  294. return 0;
  295. }
  296. s32 fm10k_iov_update_pvid(struct fm10k_intfc *interface, u16 glort, u16 pvid)
  297. {
  298. struct fm10k_iov_data *iov_data = interface->iov_data;
  299. struct fm10k_hw *hw = &interface->hw;
  300. struct fm10k_vf_info *vf_info;
  301. u16 vf_idx = (glort - hw->mac.dglort_map) & FM10K_DGLORTMAP_NONE;
  302. /* no IOV support, not our message to process */
  303. if (!iov_data)
  304. return FM10K_ERR_PARAM;
  305. /* glort outside our range, not our message to process */
  306. if (vf_idx >= iov_data->num_vfs)
  307. return FM10K_ERR_PARAM;
  308. /* determine if an update has occurred and if so notify the VF */
  309. vf_info = &iov_data->vf_info[vf_idx];
  310. if (vf_info->sw_vid != pvid) {
  311. vf_info->sw_vid = pvid;
  312. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  313. }
  314. return 0;
  315. }
  316. static void fm10k_iov_free_data(struct pci_dev *pdev)
  317. {
  318. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  319. if (!interface->iov_data)
  320. return;
  321. /* reclaim hardware resources */
  322. fm10k_iov_suspend(pdev);
  323. /* drop iov_data from interface */
  324. kfree_rcu(interface->iov_data, rcu);
  325. interface->iov_data = NULL;
  326. }
  327. static s32 fm10k_iov_alloc_data(struct pci_dev *pdev, int num_vfs)
  328. {
  329. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  330. struct fm10k_iov_data *iov_data = interface->iov_data;
  331. struct fm10k_hw *hw = &interface->hw;
  332. size_t size;
  333. int i, err;
  334. /* return error if iov_data is already populated */
  335. if (iov_data)
  336. return -EBUSY;
  337. /* The PF should always be able to assign resources */
  338. if (!hw->iov.ops.assign_resources)
  339. return -ENODEV;
  340. /* nothing to do if no VFs are requested */
  341. if (!num_vfs)
  342. return 0;
  343. /* allocate memory for VF storage */
  344. size = offsetof(struct fm10k_iov_data, vf_info[num_vfs]);
  345. iov_data = kzalloc(size, GFP_KERNEL);
  346. if (!iov_data)
  347. return -ENOMEM;
  348. /* record number of VFs */
  349. iov_data->num_vfs = num_vfs;
  350. /* loop through vf_info structures initializing each entry */
  351. for (i = 0; i < num_vfs; i++) {
  352. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  353. /* Record VF VSI value */
  354. vf_info->vsi = i + 1;
  355. vf_info->vf_idx = i;
  356. /* initialize mailbox memory */
  357. err = fm10k_pfvf_mbx_init(hw, &vf_info->mbx, iov_mbx_data, i);
  358. if (err) {
  359. dev_err(&pdev->dev,
  360. "Unable to initialize SR-IOV mailbox\n");
  361. kfree(iov_data);
  362. return err;
  363. }
  364. }
  365. /* assign iov_data to interface */
  366. interface->iov_data = iov_data;
  367. /* allocate hardware resources for the VFs */
  368. fm10k_iov_resume(pdev);
  369. return 0;
  370. }
  371. void fm10k_iov_disable(struct pci_dev *pdev)
  372. {
  373. if (pci_num_vf(pdev) && pci_vfs_assigned(pdev))
  374. dev_err(&pdev->dev,
  375. "Cannot disable SR-IOV while VFs are assigned\n");
  376. else
  377. pci_disable_sriov(pdev);
  378. fm10k_iov_free_data(pdev);
  379. }
  380. static void fm10k_disable_aer_comp_abort(struct pci_dev *pdev)
  381. {
  382. u32 err_sev;
  383. int pos;
  384. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
  385. if (!pos)
  386. return;
  387. pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, &err_sev);
  388. err_sev &= ~PCI_ERR_UNC_COMP_ABORT;
  389. pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, err_sev);
  390. }
  391. int fm10k_iov_configure(struct pci_dev *pdev, int num_vfs)
  392. {
  393. int current_vfs = pci_num_vf(pdev);
  394. int err = 0;
  395. if (current_vfs && pci_vfs_assigned(pdev)) {
  396. dev_err(&pdev->dev,
  397. "Cannot modify SR-IOV while VFs are assigned\n");
  398. num_vfs = current_vfs;
  399. } else {
  400. pci_disable_sriov(pdev);
  401. fm10k_iov_free_data(pdev);
  402. }
  403. /* allocate resources for the VFs */
  404. err = fm10k_iov_alloc_data(pdev, num_vfs);
  405. if (err)
  406. return err;
  407. /* allocate VFs if not already allocated */
  408. if (num_vfs && num_vfs != current_vfs) {
  409. /* Disable completer abort error reporting as
  410. * the VFs can trigger this any time they read a queue
  411. * that they don't own.
  412. */
  413. fm10k_disable_aer_comp_abort(pdev);
  414. err = pci_enable_sriov(pdev, num_vfs);
  415. if (err) {
  416. dev_err(&pdev->dev,
  417. "Enable PCI SR-IOV failed: %d\n", err);
  418. return err;
  419. }
  420. }
  421. return num_vfs;
  422. }
  423. static inline void fm10k_reset_vf_info(struct fm10k_intfc *interface,
  424. struct fm10k_vf_info *vf_info)
  425. {
  426. struct fm10k_hw *hw = &interface->hw;
  427. /* assigning the MAC address will send a mailbox message */
  428. fm10k_mbx_lock(interface);
  429. /* disable LPORT for this VF which clears switch rules */
  430. hw->iov.ops.reset_lport(hw, vf_info);
  431. fm10k_clear_macvlan_queue(interface, vf_info->glort, false);
  432. /* assign new MAC+VLAN for this VF */
  433. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  434. /* re-enable the LPORT for this VF */
  435. hw->iov.ops.set_lport(hw, vf_info, vf_info->vf_idx,
  436. FM10K_VF_FLAG_MULTI_CAPABLE);
  437. fm10k_mbx_unlock(interface);
  438. }
  439. int fm10k_ndo_set_vf_mac(struct net_device *netdev, int vf_idx, u8 *mac)
  440. {
  441. struct fm10k_intfc *interface = netdev_priv(netdev);
  442. struct fm10k_iov_data *iov_data = interface->iov_data;
  443. struct fm10k_vf_info *vf_info;
  444. /* verify SR-IOV is active and that vf idx is valid */
  445. if (!iov_data || vf_idx >= iov_data->num_vfs)
  446. return -EINVAL;
  447. /* verify MAC addr is valid */
  448. if (!is_zero_ether_addr(mac) && !is_valid_ether_addr(mac))
  449. return -EINVAL;
  450. /* record new MAC address */
  451. vf_info = &iov_data->vf_info[vf_idx];
  452. ether_addr_copy(vf_info->mac, mac);
  453. fm10k_reset_vf_info(interface, vf_info);
  454. return 0;
  455. }
  456. int fm10k_ndo_set_vf_vlan(struct net_device *netdev, int vf_idx, u16 vid,
  457. u8 qos, __be16 vlan_proto)
  458. {
  459. struct fm10k_intfc *interface = netdev_priv(netdev);
  460. struct fm10k_iov_data *iov_data = interface->iov_data;
  461. struct fm10k_hw *hw = &interface->hw;
  462. struct fm10k_vf_info *vf_info;
  463. /* verify SR-IOV is active and that vf idx is valid */
  464. if (!iov_data || vf_idx >= iov_data->num_vfs)
  465. return -EINVAL;
  466. /* QOS is unsupported and VLAN IDs accepted range 0-4094 */
  467. if (qos || (vid > (VLAN_VID_MASK - 1)))
  468. return -EINVAL;
  469. /* VF VLAN Protocol part to default is unsupported */
  470. if (vlan_proto != htons(ETH_P_8021Q))
  471. return -EPROTONOSUPPORT;
  472. vf_info = &iov_data->vf_info[vf_idx];
  473. /* exit if there is nothing to do */
  474. if (vf_info->pf_vid == vid)
  475. return 0;
  476. /* record default VLAN ID for VF */
  477. vf_info->pf_vid = vid;
  478. /* Clear the VLAN table for the VF */
  479. hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, vf_info->vsi, false);
  480. fm10k_reset_vf_info(interface, vf_info);
  481. return 0;
  482. }
  483. int fm10k_ndo_set_vf_bw(struct net_device *netdev, int vf_idx,
  484. int __always_unused min_rate, int max_rate)
  485. {
  486. struct fm10k_intfc *interface = netdev_priv(netdev);
  487. struct fm10k_iov_data *iov_data = interface->iov_data;
  488. struct fm10k_hw *hw = &interface->hw;
  489. /* verify SR-IOV is active and that vf idx is valid */
  490. if (!iov_data || vf_idx >= iov_data->num_vfs)
  491. return -EINVAL;
  492. /* rate limit cannot be less than 10Mbs or greater than link speed */
  493. if (max_rate &&
  494. (max_rate < FM10K_VF_TC_MIN || max_rate > FM10K_VF_TC_MAX))
  495. return -EINVAL;
  496. /* store values */
  497. iov_data->vf_info[vf_idx].rate = max_rate;
  498. /* update hardware configuration */
  499. hw->iov.ops.configure_tc(hw, vf_idx, max_rate);
  500. return 0;
  501. }
  502. int fm10k_ndo_get_vf_config(struct net_device *netdev,
  503. int vf_idx, struct ifla_vf_info *ivi)
  504. {
  505. struct fm10k_intfc *interface = netdev_priv(netdev);
  506. struct fm10k_iov_data *iov_data = interface->iov_data;
  507. struct fm10k_vf_info *vf_info;
  508. /* verify SR-IOV is active and that vf idx is valid */
  509. if (!iov_data || vf_idx >= iov_data->num_vfs)
  510. return -EINVAL;
  511. vf_info = &iov_data->vf_info[vf_idx];
  512. ivi->vf = vf_idx;
  513. ivi->max_tx_rate = vf_info->rate;
  514. ivi->min_tx_rate = 0;
  515. ether_addr_copy(ivi->mac, vf_info->mac);
  516. ivi->vlan = vf_info->pf_vid;
  517. ivi->qos = 0;
  518. return 0;
  519. }