fm10k_iov.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. int fm10k_iov_resume(struct pci_dev *pdev)
  240. {
  241. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  242. struct fm10k_iov_data *iov_data = interface->iov_data;
  243. struct fm10k_dglort_cfg dglort = { 0 };
  244. struct fm10k_hw *hw = &interface->hw;
  245. int num_vfs, i;
  246. /* pull out num_vfs from iov_data */
  247. num_vfs = iov_data ? iov_data->num_vfs : 0;
  248. /* return error if iov_data is not already populated */
  249. if (!iov_data)
  250. return -ENOMEM;
  251. /* allocate hardware resources for the VFs */
  252. hw->iov.ops.assign_resources(hw, num_vfs, num_vfs);
  253. /* configure DGLORT mapping for RSS */
  254. dglort.glort = hw->mac.dglort_map & FM10K_DGLORTMAP_NONE;
  255. dglort.idx = fm10k_dglort_vf_rss;
  256. dglort.inner_rss = 1;
  257. dglort.rss_l = fls(fm10k_queues_per_pool(hw) - 1);
  258. dglort.queue_b = fm10k_vf_queue_index(hw, 0);
  259. dglort.vsi_l = fls(hw->iov.total_vfs - 1);
  260. dglort.vsi_b = 1;
  261. hw->mac.ops.configure_dglort_map(hw, &dglort);
  262. /* assign resources to the device */
  263. for (i = 0; i < num_vfs; i++) {
  264. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  265. /* allocate all but the last GLORT to the VFs */
  266. if (i == (~hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT))
  267. break;
  268. /* assign GLORT to VF, and restrict it to multicast */
  269. hw->iov.ops.set_lport(hw, vf_info, i,
  270. FM10K_VF_FLAG_MULTI_CAPABLE);
  271. /* mailbox is disconnected so we don't send a message */
  272. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  273. /* now we are ready so we can connect */
  274. vf_info->mbx.ops.connect(hw, &vf_info->mbx);
  275. }
  276. return 0;
  277. }
  278. s32 fm10k_iov_update_pvid(struct fm10k_intfc *interface, u16 glort, u16 pvid)
  279. {
  280. struct fm10k_iov_data *iov_data = interface->iov_data;
  281. struct fm10k_hw *hw = &interface->hw;
  282. struct fm10k_vf_info *vf_info;
  283. u16 vf_idx = (glort - hw->mac.dglort_map) & FM10K_DGLORTMAP_NONE;
  284. /* no IOV support, not our message to process */
  285. if (!iov_data)
  286. return FM10K_ERR_PARAM;
  287. /* glort outside our range, not our message to process */
  288. if (vf_idx >= iov_data->num_vfs)
  289. return FM10K_ERR_PARAM;
  290. /* determine if an update has occurred and if so notify the VF */
  291. vf_info = &iov_data->vf_info[vf_idx];
  292. if (vf_info->sw_vid != pvid) {
  293. vf_info->sw_vid = pvid;
  294. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  295. }
  296. return 0;
  297. }
  298. static void fm10k_iov_free_data(struct pci_dev *pdev)
  299. {
  300. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  301. if (!interface->iov_data)
  302. return;
  303. /* reclaim hardware resources */
  304. fm10k_iov_suspend(pdev);
  305. /* drop iov_data from interface */
  306. kfree_rcu(interface->iov_data, rcu);
  307. interface->iov_data = NULL;
  308. }
  309. static s32 fm10k_iov_alloc_data(struct pci_dev *pdev, int num_vfs)
  310. {
  311. struct fm10k_intfc *interface = pci_get_drvdata(pdev);
  312. struct fm10k_iov_data *iov_data = interface->iov_data;
  313. struct fm10k_hw *hw = &interface->hw;
  314. size_t size;
  315. int i, err;
  316. /* return error if iov_data is already populated */
  317. if (iov_data)
  318. return -EBUSY;
  319. /* The PF should always be able to assign resources */
  320. if (!hw->iov.ops.assign_resources)
  321. return -ENODEV;
  322. /* nothing to do if no VFs are requested */
  323. if (!num_vfs)
  324. return 0;
  325. /* allocate memory for VF storage */
  326. size = offsetof(struct fm10k_iov_data, vf_info[num_vfs]);
  327. iov_data = kzalloc(size, GFP_KERNEL);
  328. if (!iov_data)
  329. return -ENOMEM;
  330. /* record number of VFs */
  331. iov_data->num_vfs = num_vfs;
  332. /* loop through vf_info structures initializing each entry */
  333. for (i = 0; i < num_vfs; i++) {
  334. struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
  335. /* Record VF VSI value */
  336. vf_info->vsi = i + 1;
  337. vf_info->vf_idx = i;
  338. /* initialize mailbox memory */
  339. err = fm10k_pfvf_mbx_init(hw, &vf_info->mbx, iov_mbx_data, i);
  340. if (err) {
  341. dev_err(&pdev->dev,
  342. "Unable to initialize SR-IOV mailbox\n");
  343. kfree(iov_data);
  344. return err;
  345. }
  346. }
  347. /* assign iov_data to interface */
  348. interface->iov_data = iov_data;
  349. /* allocate hardware resources for the VFs */
  350. fm10k_iov_resume(pdev);
  351. return 0;
  352. }
  353. void fm10k_iov_disable(struct pci_dev *pdev)
  354. {
  355. if (pci_num_vf(pdev) && pci_vfs_assigned(pdev))
  356. dev_err(&pdev->dev,
  357. "Cannot disable SR-IOV while VFs are assigned\n");
  358. else
  359. pci_disable_sriov(pdev);
  360. fm10k_iov_free_data(pdev);
  361. }
  362. static void fm10k_disable_aer_comp_abort(struct pci_dev *pdev)
  363. {
  364. u32 err_sev;
  365. int pos;
  366. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
  367. if (!pos)
  368. return;
  369. pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, &err_sev);
  370. err_sev &= ~PCI_ERR_UNC_COMP_ABORT;
  371. pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, err_sev);
  372. }
  373. int fm10k_iov_configure(struct pci_dev *pdev, int num_vfs)
  374. {
  375. int current_vfs = pci_num_vf(pdev);
  376. int err = 0;
  377. if (current_vfs && pci_vfs_assigned(pdev)) {
  378. dev_err(&pdev->dev,
  379. "Cannot modify SR-IOV while VFs are assigned\n");
  380. num_vfs = current_vfs;
  381. } else {
  382. pci_disable_sriov(pdev);
  383. fm10k_iov_free_data(pdev);
  384. }
  385. /* allocate resources for the VFs */
  386. err = fm10k_iov_alloc_data(pdev, num_vfs);
  387. if (err)
  388. return err;
  389. /* allocate VFs if not already allocated */
  390. if (num_vfs && num_vfs != current_vfs) {
  391. /* Disable completer abort error reporting as
  392. * the VFs can trigger this any time they read a queue
  393. * that they don't own.
  394. */
  395. fm10k_disable_aer_comp_abort(pdev);
  396. err = pci_enable_sriov(pdev, num_vfs);
  397. if (err) {
  398. dev_err(&pdev->dev,
  399. "Enable PCI SR-IOV failed: %d\n", err);
  400. return err;
  401. }
  402. }
  403. return num_vfs;
  404. }
  405. static inline void fm10k_reset_vf_info(struct fm10k_intfc *interface,
  406. struct fm10k_vf_info *vf_info)
  407. {
  408. struct fm10k_hw *hw = &interface->hw;
  409. /* assigning the MAC address will send a mailbox message */
  410. fm10k_mbx_lock(interface);
  411. /* disable LPORT for this VF which clears switch rules */
  412. hw->iov.ops.reset_lport(hw, vf_info);
  413. fm10k_clear_macvlan_queue(interface, vf_info->glort, false);
  414. /* assign new MAC+VLAN for this VF */
  415. hw->iov.ops.assign_default_mac_vlan(hw, vf_info);
  416. /* re-enable the LPORT for this VF */
  417. hw->iov.ops.set_lport(hw, vf_info, vf_info->vf_idx,
  418. FM10K_VF_FLAG_MULTI_CAPABLE);
  419. fm10k_mbx_unlock(interface);
  420. }
  421. int fm10k_ndo_set_vf_mac(struct net_device *netdev, int vf_idx, u8 *mac)
  422. {
  423. struct fm10k_intfc *interface = netdev_priv(netdev);
  424. struct fm10k_iov_data *iov_data = interface->iov_data;
  425. struct fm10k_vf_info *vf_info;
  426. /* verify SR-IOV is active and that vf idx is valid */
  427. if (!iov_data || vf_idx >= iov_data->num_vfs)
  428. return -EINVAL;
  429. /* verify MAC addr is valid */
  430. if (!is_zero_ether_addr(mac) && !is_valid_ether_addr(mac))
  431. return -EINVAL;
  432. /* record new MAC address */
  433. vf_info = &iov_data->vf_info[vf_idx];
  434. ether_addr_copy(vf_info->mac, mac);
  435. fm10k_reset_vf_info(interface, vf_info);
  436. return 0;
  437. }
  438. int fm10k_ndo_set_vf_vlan(struct net_device *netdev, int vf_idx, u16 vid,
  439. u8 qos, __be16 vlan_proto)
  440. {
  441. struct fm10k_intfc *interface = netdev_priv(netdev);
  442. struct fm10k_iov_data *iov_data = interface->iov_data;
  443. struct fm10k_hw *hw = &interface->hw;
  444. struct fm10k_vf_info *vf_info;
  445. /* verify SR-IOV is active and that vf idx is valid */
  446. if (!iov_data || vf_idx >= iov_data->num_vfs)
  447. return -EINVAL;
  448. /* QOS is unsupported and VLAN IDs accepted range 0-4094 */
  449. if (qos || (vid > (VLAN_VID_MASK - 1)))
  450. return -EINVAL;
  451. /* VF VLAN Protocol part to default is unsupported */
  452. if (vlan_proto != htons(ETH_P_8021Q))
  453. return -EPROTONOSUPPORT;
  454. vf_info = &iov_data->vf_info[vf_idx];
  455. /* exit if there is nothing to do */
  456. if (vf_info->pf_vid == vid)
  457. return 0;
  458. /* record default VLAN ID for VF */
  459. vf_info->pf_vid = vid;
  460. /* Clear the VLAN table for the VF */
  461. hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, vf_info->vsi, false);
  462. fm10k_reset_vf_info(interface, vf_info);
  463. return 0;
  464. }
  465. int fm10k_ndo_set_vf_bw(struct net_device *netdev, int vf_idx,
  466. int __always_unused min_rate, int max_rate)
  467. {
  468. struct fm10k_intfc *interface = netdev_priv(netdev);
  469. struct fm10k_iov_data *iov_data = interface->iov_data;
  470. struct fm10k_hw *hw = &interface->hw;
  471. /* verify SR-IOV is active and that vf idx is valid */
  472. if (!iov_data || vf_idx >= iov_data->num_vfs)
  473. return -EINVAL;
  474. /* rate limit cannot be less than 10Mbs or greater than link speed */
  475. if (max_rate &&
  476. (max_rate < FM10K_VF_TC_MIN || max_rate > FM10K_VF_TC_MAX))
  477. return -EINVAL;
  478. /* store values */
  479. iov_data->vf_info[vf_idx].rate = max_rate;
  480. /* update hardware configuration */
  481. hw->iov.ops.configure_tc(hw, vf_idx, max_rate);
  482. return 0;
  483. }
  484. int fm10k_ndo_get_vf_config(struct net_device *netdev,
  485. int vf_idx, struct ifla_vf_info *ivi)
  486. {
  487. struct fm10k_intfc *interface = netdev_priv(netdev);
  488. struct fm10k_iov_data *iov_data = interface->iov_data;
  489. struct fm10k_vf_info *vf_info;
  490. /* verify SR-IOV is active and that vf idx is valid */
  491. if (!iov_data || vf_idx >= iov_data->num_vfs)
  492. return -EINVAL;
  493. vf_info = &iov_data->vf_info[vf_idx];
  494. ivi->vf = vf_idx;
  495. ivi->max_tx_rate = vf_info->rate;
  496. ivi->min_tx_rate = 0;
  497. ether_addr_copy(ivi->mac, vf_info->mac);
  498. ivi->vlan = vf_info->pf_vid;
  499. ivi->qos = 0;
  500. return 0;
  501. }