fm10k_iov.c 17 KB

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