ixgbe_sriov.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include <linux/types.h>
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/vmalloc.h>
  8. #include <linux/string.h>
  9. #include <linux/in.h>
  10. #include <linux/ip.h>
  11. #include <linux/tcp.h>
  12. #include <linux/ipv6.h>
  13. #include <linux/if_bridge.h>
  14. #ifdef NETIF_F_HW_VLAN_CTAG_TX
  15. #include <linux/if_vlan.h>
  16. #endif
  17. #include "ixgbe.h"
  18. #include "ixgbe_type.h"
  19. #include "ixgbe_sriov.h"
  20. #ifdef CONFIG_PCI_IOV
  21. static inline void ixgbe_alloc_vf_macvlans(struct ixgbe_adapter *adapter,
  22. unsigned int num_vfs)
  23. {
  24. struct ixgbe_hw *hw = &adapter->hw;
  25. struct vf_macvlans *mv_list;
  26. int num_vf_macvlans, i;
  27. num_vf_macvlans = hw->mac.num_rar_entries -
  28. (IXGBE_MAX_PF_MACVLANS + 1 + num_vfs);
  29. if (!num_vf_macvlans)
  30. return;
  31. mv_list = kcalloc(num_vf_macvlans, sizeof(struct vf_macvlans),
  32. GFP_KERNEL);
  33. if (mv_list) {
  34. /* Initialize list of VF macvlans */
  35. INIT_LIST_HEAD(&adapter->vf_mvs.l);
  36. for (i = 0; i < num_vf_macvlans; i++) {
  37. mv_list[i].vf = -1;
  38. mv_list[i].free = true;
  39. list_add(&mv_list[i].l, &adapter->vf_mvs.l);
  40. }
  41. adapter->mv_list = mv_list;
  42. }
  43. }
  44. static int __ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
  45. unsigned int num_vfs)
  46. {
  47. struct ixgbe_hw *hw = &adapter->hw;
  48. int i;
  49. if (adapter->xdp_prog) {
  50. e_warn(probe, "SRIOV is not supported with XDP\n");
  51. return -EINVAL;
  52. }
  53. /* Enable VMDq flag so device will be set in VM mode */
  54. adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED |
  55. IXGBE_FLAG_VMDQ_ENABLED;
  56. /* Allocate memory for per VF control structures */
  57. adapter->vfinfo = kcalloc(num_vfs, sizeof(struct vf_data_storage),
  58. GFP_KERNEL);
  59. if (!adapter->vfinfo)
  60. return -ENOMEM;
  61. adapter->num_vfs = num_vfs;
  62. ixgbe_alloc_vf_macvlans(adapter, num_vfs);
  63. adapter->ring_feature[RING_F_VMDQ].offset = num_vfs;
  64. /* Initialize default switching mode VEB */
  65. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  66. adapter->bridge_mode = BRIDGE_MODE_VEB;
  67. /* limit trafffic classes based on VFs enabled */
  68. if ((adapter->hw.mac.type == ixgbe_mac_82599EB) && (num_vfs < 16)) {
  69. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  70. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  71. } else if (num_vfs < 32) {
  72. adapter->dcb_cfg.num_tcs.pg_tcs = 4;
  73. adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
  74. } else {
  75. adapter->dcb_cfg.num_tcs.pg_tcs = 1;
  76. adapter->dcb_cfg.num_tcs.pfc_tcs = 1;
  77. }
  78. /* Disable RSC when in SR-IOV mode */
  79. adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
  80. IXGBE_FLAG2_RSC_ENABLED);
  81. for (i = 0; i < num_vfs; i++) {
  82. /* enable spoof checking for all VFs */
  83. adapter->vfinfo[i].spoofchk_enabled = true;
  84. /* We support VF RSS querying only for 82599 and x540
  85. * devices at the moment. These devices share RSS
  86. * indirection table and RSS hash key with PF therefore
  87. * we want to disable the querying by default.
  88. */
  89. adapter->vfinfo[i].rss_query_enabled = 0;
  90. /* Untrust all VFs */
  91. adapter->vfinfo[i].trusted = false;
  92. /* set the default xcast mode */
  93. adapter->vfinfo[i].xcast_mode = IXGBEVF_XCAST_MODE_NONE;
  94. }
  95. e_info(probe, "SR-IOV enabled with %d VFs\n", num_vfs);
  96. return 0;
  97. }
  98. /**
  99. * ixgbe_get_vfs - Find and take references to all vf devices
  100. * @adapter: Pointer to adapter struct
  101. */
  102. static void ixgbe_get_vfs(struct ixgbe_adapter *adapter)
  103. {
  104. struct pci_dev *pdev = adapter->pdev;
  105. u16 vendor = pdev->vendor;
  106. struct pci_dev *vfdev;
  107. int vf = 0;
  108. u16 vf_id;
  109. int pos;
  110. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  111. if (!pos)
  112. return;
  113. pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id);
  114. vfdev = pci_get_device(vendor, vf_id, NULL);
  115. for (; vfdev; vfdev = pci_get_device(vendor, vf_id, vfdev)) {
  116. if (!vfdev->is_virtfn)
  117. continue;
  118. if (vfdev->physfn != pdev)
  119. continue;
  120. if (vf >= adapter->num_vfs)
  121. continue;
  122. pci_dev_get(vfdev);
  123. adapter->vfinfo[vf].vfdev = vfdev;
  124. ++vf;
  125. }
  126. }
  127. /* Note this function is called when the user wants to enable SR-IOV
  128. * VFs using the now deprecated module parameter
  129. */
  130. void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, unsigned int max_vfs)
  131. {
  132. int pre_existing_vfs = 0;
  133. unsigned int num_vfs;
  134. pre_existing_vfs = pci_num_vf(adapter->pdev);
  135. if (!pre_existing_vfs && !max_vfs)
  136. return;
  137. /* If there are pre-existing VFs then we have to force
  138. * use of that many - over ride any module parameter value.
  139. * This may result from the user unloading the PF driver
  140. * while VFs were assigned to guest VMs or because the VFs
  141. * have been created via the new PCI SR-IOV sysfs interface.
  142. */
  143. if (pre_existing_vfs) {
  144. num_vfs = pre_existing_vfs;
  145. dev_warn(&adapter->pdev->dev,
  146. "Virtual Functions already enabled for this device - Please reload all VF drivers to avoid spoofed packet errors\n");
  147. } else {
  148. int err;
  149. /*
  150. * The 82599 supports up to 64 VFs per physical function
  151. * but this implementation limits allocation to 63 so that
  152. * basic networking resources are still available to the
  153. * physical function. If the user requests greater than
  154. * 63 VFs then it is an error - reset to default of zero.
  155. */
  156. num_vfs = min_t(unsigned int, max_vfs, IXGBE_MAX_VFS_DRV_LIMIT);
  157. err = pci_enable_sriov(adapter->pdev, num_vfs);
  158. if (err) {
  159. e_err(probe, "Failed to enable PCI sriov: %d\n", err);
  160. return;
  161. }
  162. }
  163. if (!__ixgbe_enable_sriov(adapter, num_vfs)) {
  164. ixgbe_get_vfs(adapter);
  165. return;
  166. }
  167. /* If we have gotten to this point then there is no memory available
  168. * to manage the VF devices - print message and bail.
  169. */
  170. e_err(probe, "Unable to allocate memory for VF Data Storage - "
  171. "SRIOV disabled\n");
  172. ixgbe_disable_sriov(adapter);
  173. }
  174. #endif /* #ifdef CONFIG_PCI_IOV */
  175. int ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
  176. {
  177. unsigned int num_vfs = adapter->num_vfs, vf;
  178. int rss;
  179. /* set num VFs to 0 to prevent access to vfinfo */
  180. adapter->num_vfs = 0;
  181. /* put the reference to all of the vf devices */
  182. for (vf = 0; vf < num_vfs; ++vf) {
  183. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  184. if (!vfdev)
  185. continue;
  186. adapter->vfinfo[vf].vfdev = NULL;
  187. pci_dev_put(vfdev);
  188. }
  189. /* free VF control structures */
  190. kfree(adapter->vfinfo);
  191. adapter->vfinfo = NULL;
  192. /* free macvlan list */
  193. kfree(adapter->mv_list);
  194. adapter->mv_list = NULL;
  195. /* if SR-IOV is already disabled then there is nothing to do */
  196. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  197. return 0;
  198. #ifdef CONFIG_PCI_IOV
  199. /*
  200. * If our VFs are assigned we cannot shut down SR-IOV
  201. * without causing issues, so just leave the hardware
  202. * available but disabled
  203. */
  204. if (pci_vfs_assigned(adapter->pdev)) {
  205. e_dev_warn("Unloading driver while VFs are assigned - VFs will not be deallocated\n");
  206. return -EPERM;
  207. }
  208. /* disable iov and allow time for transactions to clear */
  209. pci_disable_sriov(adapter->pdev);
  210. #endif
  211. /* Disable VMDq flag so device will be set in VM mode */
  212. if (bitmap_weight(adapter->fwd_bitmask, adapter->num_rx_pools) == 1) {
  213. adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED;
  214. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  215. rss = min_t(int, ixgbe_max_rss_indices(adapter),
  216. num_online_cpus());
  217. } else {
  218. rss = min_t(int, IXGBE_MAX_L2A_QUEUES, num_online_cpus());
  219. }
  220. adapter->ring_feature[RING_F_VMDQ].offset = 0;
  221. adapter->ring_feature[RING_F_RSS].limit = rss;
  222. /* take a breather then clean up driver data */
  223. msleep(100);
  224. return 0;
  225. }
  226. static int ixgbe_pci_sriov_enable(struct pci_dev *dev, int num_vfs)
  227. {
  228. #ifdef CONFIG_PCI_IOV
  229. struct ixgbe_adapter *adapter = pci_get_drvdata(dev);
  230. int pre_existing_vfs = pci_num_vf(dev);
  231. int err = 0, num_rx_pools, i, limit;
  232. u8 num_tc;
  233. if (pre_existing_vfs && pre_existing_vfs != num_vfs)
  234. err = ixgbe_disable_sriov(adapter);
  235. else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
  236. return num_vfs;
  237. if (err)
  238. return err;
  239. /* While the SR-IOV capability structure reports total VFs to be 64,
  240. * we limit the actual number allocated as below based on two factors.
  241. * Num_TCs MAX_VFs
  242. * 1 63
  243. * <=4 31
  244. * >4 15
  245. * First, we reserve some transmit/receive resources for the PF.
  246. * Second, VMDQ also uses the same pools that SR-IOV does. We need to
  247. * account for this, so that we don't accidentally allocate more VFs
  248. * than we have available pools. The PCI bus driver already checks for
  249. * other values out of range.
  250. */
  251. num_tc = adapter->hw_tcs;
  252. num_rx_pools = bitmap_weight(adapter->fwd_bitmask,
  253. adapter->num_rx_pools);
  254. limit = (num_tc > 4) ? IXGBE_MAX_VFS_8TC :
  255. (num_tc > 1) ? IXGBE_MAX_VFS_4TC : IXGBE_MAX_VFS_1TC;
  256. if (num_vfs > (limit - num_rx_pools)) {
  257. e_dev_err("Currently configured with %d TCs, and %d offloaded macvlans. Creating more than %d VFs is not allowed\n",
  258. num_tc, num_rx_pools - 1, limit - num_rx_pools);
  259. return -EPERM;
  260. }
  261. err = __ixgbe_enable_sriov(adapter, num_vfs);
  262. if (err)
  263. return err;
  264. for (i = 0; i < num_vfs; i++)
  265. ixgbe_vf_configuration(dev, (i | 0x10000000));
  266. /* reset before enabling SRIOV to avoid mailbox issues */
  267. ixgbe_sriov_reinit(adapter);
  268. err = pci_enable_sriov(dev, num_vfs);
  269. if (err) {
  270. e_dev_warn("Failed to enable PCI sriov: %d\n", err);
  271. return err;
  272. }
  273. ixgbe_get_vfs(adapter);
  274. return num_vfs;
  275. #else
  276. return 0;
  277. #endif
  278. }
  279. static int ixgbe_pci_sriov_disable(struct pci_dev *dev)
  280. {
  281. struct ixgbe_adapter *adapter = pci_get_drvdata(dev);
  282. int err;
  283. #ifdef CONFIG_PCI_IOV
  284. u32 current_flags = adapter->flags;
  285. int prev_num_vf = pci_num_vf(dev);
  286. #endif
  287. err = ixgbe_disable_sriov(adapter);
  288. /* Only reinit if no error and state changed */
  289. #ifdef CONFIG_PCI_IOV
  290. if (!err && (current_flags != adapter->flags ||
  291. prev_num_vf != pci_num_vf(dev)))
  292. ixgbe_sriov_reinit(adapter);
  293. #endif
  294. return err;
  295. }
  296. int ixgbe_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  297. {
  298. if (num_vfs == 0)
  299. return ixgbe_pci_sriov_disable(dev);
  300. else
  301. return ixgbe_pci_sriov_enable(dev, num_vfs);
  302. }
  303. static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter,
  304. u32 *msgbuf, u32 vf)
  305. {
  306. int entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
  307. >> IXGBE_VT_MSGINFO_SHIFT;
  308. u16 *hash_list = (u16 *)&msgbuf[1];
  309. struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
  310. struct ixgbe_hw *hw = &adapter->hw;
  311. int i;
  312. u32 vector_bit;
  313. u32 vector_reg;
  314. u32 mta_reg;
  315. u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
  316. /* only so many hash values supported */
  317. entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES);
  318. /*
  319. * salt away the number of multi cast addresses assigned
  320. * to this VF for later use to restore when the PF multi cast
  321. * list changes
  322. */
  323. vfinfo->num_vf_mc_hashes = entries;
  324. /*
  325. * VFs are limited to using the MTA hash table for their multicast
  326. * addresses
  327. */
  328. for (i = 0; i < entries; i++) {
  329. vfinfo->vf_mc_hashes[i] = hash_list[i];
  330. }
  331. for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
  332. vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
  333. vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
  334. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  335. mta_reg |= BIT(vector_bit);
  336. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  337. }
  338. vmolr |= IXGBE_VMOLR_ROMPE;
  339. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
  340. return 0;
  341. }
  342. #ifdef CONFIG_PCI_IOV
  343. void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter)
  344. {
  345. struct ixgbe_hw *hw = &adapter->hw;
  346. struct vf_data_storage *vfinfo;
  347. int i, j;
  348. u32 vector_bit;
  349. u32 vector_reg;
  350. u32 mta_reg;
  351. for (i = 0; i < adapter->num_vfs; i++) {
  352. u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(i));
  353. vfinfo = &adapter->vfinfo[i];
  354. for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) {
  355. hw->addr_ctrl.mta_in_use++;
  356. vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F;
  357. vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F;
  358. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  359. mta_reg |= BIT(vector_bit);
  360. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  361. }
  362. if (vfinfo->num_vf_mc_hashes)
  363. vmolr |= IXGBE_VMOLR_ROMPE;
  364. else
  365. vmolr &= ~IXGBE_VMOLR_ROMPE;
  366. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(i), vmolr);
  367. }
  368. /* Restore any VF macvlans */
  369. ixgbe_full_sync_mac_table(adapter);
  370. }
  371. #endif
  372. static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid,
  373. u32 vf)
  374. {
  375. struct ixgbe_hw *hw = &adapter->hw;
  376. int err;
  377. /* If VLAN overlaps with one the PF is currently monitoring make
  378. * sure that we are able to allocate a VLVF entry. This may be
  379. * redundant but it guarantees PF will maintain visibility to
  380. * the VLAN.
  381. */
  382. if (add && test_bit(vid, adapter->active_vlans)) {
  383. err = hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), true, false);
  384. if (err)
  385. return err;
  386. }
  387. err = hw->mac.ops.set_vfta(hw, vid, vf, !!add, false);
  388. if (add && !err)
  389. return err;
  390. /* If we failed to add the VF VLAN or we are removing the VF VLAN
  391. * we may need to drop the PF pool bit in order to allow us to free
  392. * up the VLVF resources.
  393. */
  394. if (test_bit(vid, adapter->active_vlans) ||
  395. (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  396. ixgbe_update_pf_promisc_vlvf(adapter, vid);
  397. return err;
  398. }
  399. static s32 ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
  400. {
  401. struct ixgbe_hw *hw = &adapter->hw;
  402. int max_frame = msgbuf[1];
  403. u32 max_frs;
  404. /*
  405. * For 82599EB we have to keep all PFs and VFs operating with
  406. * the same max_frame value in order to avoid sending an oversize
  407. * frame to a VF. In order to guarantee this is handled correctly
  408. * for all cases we have several special exceptions to take into
  409. * account before we can enable the VF for receive
  410. */
  411. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  412. struct net_device *dev = adapter->netdev;
  413. int pf_max_frame = dev->mtu + ETH_HLEN;
  414. u32 reg_offset, vf_shift, vfre;
  415. s32 err = 0;
  416. #ifdef CONFIG_FCOE
  417. if (dev->features & NETIF_F_FCOE_MTU)
  418. pf_max_frame = max_t(int, pf_max_frame,
  419. IXGBE_FCOE_JUMBO_FRAME_SIZE);
  420. #endif /* CONFIG_FCOE */
  421. switch (adapter->vfinfo[vf].vf_api) {
  422. case ixgbe_mbox_api_11:
  423. case ixgbe_mbox_api_12:
  424. case ixgbe_mbox_api_13:
  425. /* Version 1.1 supports jumbo frames on VFs if PF has
  426. * jumbo frames enabled which means legacy VFs are
  427. * disabled
  428. */
  429. if (pf_max_frame > ETH_FRAME_LEN)
  430. break;
  431. /* fall through */
  432. default:
  433. /* If the PF or VF are running w/ jumbo frames enabled
  434. * we need to shut down the VF Rx path as we cannot
  435. * support jumbo frames on legacy VFs
  436. */
  437. if ((pf_max_frame > ETH_FRAME_LEN) ||
  438. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  439. err = -EINVAL;
  440. break;
  441. }
  442. /* determine VF receive enable location */
  443. vf_shift = vf % 32;
  444. reg_offset = vf / 32;
  445. /* enable or disable receive depending on error */
  446. vfre = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
  447. if (err)
  448. vfre &= ~BIT(vf_shift);
  449. else
  450. vfre |= BIT(vf_shift);
  451. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), vfre);
  452. if (err) {
  453. e_err(drv, "VF max_frame %d out of range\n", max_frame);
  454. return err;
  455. }
  456. }
  457. /* MTU < 68 is an error and causes problems on some kernels */
  458. if (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE) {
  459. e_err(drv, "VF max_frame %d out of range\n", max_frame);
  460. return -EINVAL;
  461. }
  462. /* pull current max frame size from hardware */
  463. max_frs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
  464. max_frs &= IXGBE_MHADD_MFS_MASK;
  465. max_frs >>= IXGBE_MHADD_MFS_SHIFT;
  466. if (max_frs < max_frame) {
  467. max_frs = max_frame << IXGBE_MHADD_MFS_SHIFT;
  468. IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
  469. }
  470. e_info(hw, "VF requests change max MTU to %d\n", max_frame);
  471. return 0;
  472. }
  473. static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe)
  474. {
  475. u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
  476. vmolr |= IXGBE_VMOLR_BAM;
  477. if (aupe)
  478. vmolr |= IXGBE_VMOLR_AUPE;
  479. else
  480. vmolr &= ~IXGBE_VMOLR_AUPE;
  481. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
  482. }
  483. static void ixgbe_clear_vmvir(struct ixgbe_adapter *adapter, u32 vf)
  484. {
  485. struct ixgbe_hw *hw = &adapter->hw;
  486. IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
  487. }
  488. static void ixgbe_clear_vf_vlans(struct ixgbe_adapter *adapter, u32 vf)
  489. {
  490. struct ixgbe_hw *hw = &adapter->hw;
  491. u32 vlvfb_mask, pool_mask, i;
  492. /* create mask for VF and other pools */
  493. pool_mask = ~BIT(VMDQ_P(0) % 32);
  494. vlvfb_mask = BIT(vf % 32);
  495. /* post increment loop, covers VLVF_ENTRIES - 1 to 0 */
  496. for (i = IXGBE_VLVF_ENTRIES; i--;) {
  497. u32 bits[2], vlvfb, vid, vfta, vlvf;
  498. u32 word = i * 2 + vf / 32;
  499. u32 mask;
  500. vlvfb = IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  501. /* if our bit isn't set we can skip it */
  502. if (!(vlvfb & vlvfb_mask))
  503. continue;
  504. /* clear our bit from vlvfb */
  505. vlvfb ^= vlvfb_mask;
  506. /* create 64b mask to chedk to see if we should clear VLVF */
  507. bits[word % 2] = vlvfb;
  508. bits[~word % 2] = IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1));
  509. /* if other pools are present, just remove ourselves */
  510. if (bits[(VMDQ_P(0) / 32) ^ 1] ||
  511. (bits[VMDQ_P(0) / 32] & pool_mask))
  512. goto update_vlvfb;
  513. /* if PF is present, leave VFTA */
  514. if (bits[0] || bits[1])
  515. goto update_vlvf;
  516. /* if we cannot determine VLAN just remove ourselves */
  517. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  518. if (!vlvf)
  519. goto update_vlvfb;
  520. vid = vlvf & VLAN_VID_MASK;
  521. mask = BIT(vid % 32);
  522. /* clear bit from VFTA */
  523. vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid / 32));
  524. if (vfta & mask)
  525. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid / 32), vfta ^ mask);
  526. update_vlvf:
  527. /* clear POOL selection enable */
  528. IXGBE_WRITE_REG(hw, IXGBE_VLVF(i), 0);
  529. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  530. vlvfb = 0;
  531. update_vlvfb:
  532. /* clear pool bits */
  533. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), vlvfb);
  534. }
  535. }
  536. static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
  537. int vf, int index, unsigned char *mac_addr)
  538. {
  539. struct vf_macvlans *entry;
  540. struct list_head *pos;
  541. int retval = 0;
  542. if (index <= 1) {
  543. list_for_each(pos, &adapter->vf_mvs.l) {
  544. entry = list_entry(pos, struct vf_macvlans, l);
  545. if (entry->vf == vf) {
  546. entry->vf = -1;
  547. entry->free = true;
  548. entry->is_macvlan = false;
  549. ixgbe_del_mac_filter(adapter,
  550. entry->vf_macvlan, vf);
  551. }
  552. }
  553. }
  554. /*
  555. * If index was zero then we were asked to clear the uc list
  556. * for the VF. We're done.
  557. */
  558. if (!index)
  559. return 0;
  560. entry = NULL;
  561. list_for_each(pos, &adapter->vf_mvs.l) {
  562. entry = list_entry(pos, struct vf_macvlans, l);
  563. if (entry->free)
  564. break;
  565. }
  566. /*
  567. * If we traversed the entire list and didn't find a free entry
  568. * then we're out of space on the RAR table. Also entry may
  569. * be NULL because the original memory allocation for the list
  570. * failed, which is not fatal but does mean we can't support
  571. * VF requests for MACVLAN because we couldn't allocate
  572. * memory for the list management required.
  573. */
  574. if (!entry || !entry->free)
  575. return -ENOSPC;
  576. retval = ixgbe_add_mac_filter(adapter, mac_addr, vf);
  577. if (retval < 0)
  578. return retval;
  579. entry->free = false;
  580. entry->is_macvlan = true;
  581. entry->vf = vf;
  582. memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN);
  583. return 0;
  584. }
  585. static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
  586. {
  587. struct ixgbe_hw *hw = &adapter->hw;
  588. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  589. struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
  590. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  591. u8 num_tcs = adapter->hw_tcs;
  592. u32 reg_val;
  593. u32 queue;
  594. /* remove VLAN filters beloning to this VF */
  595. ixgbe_clear_vf_vlans(adapter, vf);
  596. /* add back PF assigned VLAN or VLAN 0 */
  597. ixgbe_set_vf_vlan(adapter, true, vfinfo->pf_vlan, vf);
  598. /* reset offloads to defaults */
  599. ixgbe_set_vmolr(hw, vf, !vfinfo->pf_vlan);
  600. /* set outgoing tags for VFs */
  601. if (!vfinfo->pf_vlan && !vfinfo->pf_qos && !num_tcs) {
  602. ixgbe_clear_vmvir(adapter, vf);
  603. } else {
  604. if (vfinfo->pf_qos || !num_tcs)
  605. ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
  606. vfinfo->pf_qos, vf);
  607. else
  608. ixgbe_set_vmvir(adapter, vfinfo->pf_vlan,
  609. adapter->default_up, vf);
  610. if (vfinfo->spoofchk_enabled) {
  611. hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf);
  612. hw->mac.ops.set_mac_anti_spoofing(hw, true, vf);
  613. }
  614. }
  615. /* reset multicast table array for vf */
  616. adapter->vfinfo[vf].num_vf_mc_hashes = 0;
  617. /* Flush and reset the mta with the new values */
  618. ixgbe_set_rx_mode(adapter->netdev);
  619. ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf);
  620. ixgbe_set_vf_macvlan(adapter, vf, 0, NULL);
  621. /* reset VF api back to unknown */
  622. adapter->vfinfo[vf].vf_api = ixgbe_mbox_api_10;
  623. /* Restart each queue for given VF */
  624. for (queue = 0; queue < q_per_pool; queue++) {
  625. unsigned int reg_idx = (vf * q_per_pool) + queue;
  626. reg_val = IXGBE_READ_REG(hw, IXGBE_PVFTXDCTL(reg_idx));
  627. /* Re-enabling only configured queues */
  628. if (reg_val) {
  629. reg_val |= IXGBE_TXDCTL_ENABLE;
  630. IXGBE_WRITE_REG(hw, IXGBE_PVFTXDCTL(reg_idx), reg_val);
  631. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  632. IXGBE_WRITE_REG(hw, IXGBE_PVFTXDCTL(reg_idx), reg_val);
  633. }
  634. }
  635. IXGBE_WRITE_FLUSH(hw);
  636. }
  637. static void ixgbe_vf_clear_mbx(struct ixgbe_adapter *adapter, u32 vf)
  638. {
  639. struct ixgbe_hw *hw = &adapter->hw;
  640. u32 word;
  641. /* Clear VF's mailbox memory */
  642. for (word = 0; word < IXGBE_VFMAILBOX_SIZE; word++)
  643. IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf), word, 0);
  644. IXGBE_WRITE_FLUSH(hw);
  645. }
  646. static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
  647. int vf, unsigned char *mac_addr)
  648. {
  649. s32 retval;
  650. ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf);
  651. retval = ixgbe_add_mac_filter(adapter, mac_addr, vf);
  652. if (retval >= 0)
  653. memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr,
  654. ETH_ALEN);
  655. else
  656. memset(adapter->vfinfo[vf].vf_mac_addresses, 0, ETH_ALEN);
  657. return retval;
  658. }
  659. int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask)
  660. {
  661. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  662. unsigned int vfn = (event_mask & 0x3f);
  663. bool enable = ((event_mask & 0x10000000U) != 0);
  664. if (enable)
  665. eth_zero_addr(adapter->vfinfo[vfn].vf_mac_addresses);
  666. return 0;
  667. }
  668. static inline void ixgbe_write_qde(struct ixgbe_adapter *adapter, u32 vf,
  669. u32 qde)
  670. {
  671. struct ixgbe_hw *hw = &adapter->hw;
  672. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  673. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  674. int i;
  675. for (i = vf * q_per_pool; i < ((vf + 1) * q_per_pool); i++) {
  676. u32 reg;
  677. /* flush previous write */
  678. IXGBE_WRITE_FLUSH(hw);
  679. /* indicate to hardware that we want to set drop enable */
  680. reg = IXGBE_QDE_WRITE | qde;
  681. reg |= i << IXGBE_QDE_IDX_SHIFT;
  682. IXGBE_WRITE_REG(hw, IXGBE_QDE, reg);
  683. }
  684. }
  685. static int ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf)
  686. {
  687. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  688. struct ixgbe_hw *hw = &adapter->hw;
  689. unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses;
  690. u32 reg, reg_offset, vf_shift;
  691. u32 msgbuf[4] = {0, 0, 0, 0};
  692. u8 *addr = (u8 *)(&msgbuf[1]);
  693. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  694. int i;
  695. e_info(probe, "VF Reset msg received from vf %d\n", vf);
  696. /* reset the filters for the device */
  697. ixgbe_vf_reset_event(adapter, vf);
  698. ixgbe_vf_clear_mbx(adapter, vf);
  699. /* set vf mac address */
  700. if (!is_zero_ether_addr(vf_mac))
  701. ixgbe_set_vf_mac(adapter, vf, vf_mac);
  702. vf_shift = vf % 32;
  703. reg_offset = vf / 32;
  704. /* enable transmit for vf */
  705. reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
  706. reg |= BIT(vf_shift);
  707. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
  708. /* force drop enable for all VF Rx queues */
  709. reg = IXGBE_QDE_ENABLE;
  710. if (adapter->vfinfo[vf].pf_vlan)
  711. reg |= IXGBE_QDE_HIDE_VLAN;
  712. ixgbe_write_qde(adapter, vf, reg);
  713. /* enable receive for vf */
  714. reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
  715. reg |= BIT(vf_shift);
  716. /*
  717. * The 82599 cannot support a mix of jumbo and non-jumbo PF/VFs.
  718. * For more info take a look at ixgbe_set_vf_lpe
  719. */
  720. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  721. struct net_device *dev = adapter->netdev;
  722. int pf_max_frame = dev->mtu + ETH_HLEN;
  723. #ifdef CONFIG_FCOE
  724. if (dev->features & NETIF_F_FCOE_MTU)
  725. pf_max_frame = max_t(int, pf_max_frame,
  726. IXGBE_FCOE_JUMBO_FRAME_SIZE);
  727. #endif /* CONFIG_FCOE */
  728. if (pf_max_frame > ETH_FRAME_LEN)
  729. reg &= ~BIT(vf_shift);
  730. }
  731. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
  732. /* enable VF mailbox for further messages */
  733. adapter->vfinfo[vf].clear_to_send = true;
  734. /* Enable counting of spoofed packets in the SSVPC register */
  735. reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
  736. reg |= BIT(vf_shift);
  737. IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
  738. /*
  739. * Reset the VFs TDWBAL and TDWBAH registers
  740. * which are not cleared by an FLR
  741. */
  742. for (i = 0; i < q_per_pool; i++) {
  743. IXGBE_WRITE_REG(hw, IXGBE_PVFTDWBAHn(q_per_pool, vf, i), 0);
  744. IXGBE_WRITE_REG(hw, IXGBE_PVFTDWBALn(q_per_pool, vf, i), 0);
  745. }
  746. /* reply to reset with ack and vf mac address */
  747. msgbuf[0] = IXGBE_VF_RESET;
  748. if (!is_zero_ether_addr(vf_mac) && adapter->vfinfo[vf].pf_set_mac) {
  749. msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
  750. memcpy(addr, vf_mac, ETH_ALEN);
  751. } else {
  752. msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
  753. }
  754. /*
  755. * Piggyback the multicast filter type so VF can compute the
  756. * correct vectors
  757. */
  758. msgbuf[3] = hw->mac.mc_filter_type;
  759. ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
  760. return 0;
  761. }
  762. static int ixgbe_set_vf_mac_addr(struct ixgbe_adapter *adapter,
  763. u32 *msgbuf, u32 vf)
  764. {
  765. u8 *new_mac = ((u8 *)(&msgbuf[1]));
  766. if (!is_valid_ether_addr(new_mac)) {
  767. e_warn(drv, "VF %d attempted to set invalid mac\n", vf);
  768. return -1;
  769. }
  770. if (adapter->vfinfo[vf].pf_set_mac && !adapter->vfinfo[vf].trusted &&
  771. !ether_addr_equal(adapter->vfinfo[vf].vf_mac_addresses, new_mac)) {
  772. e_warn(drv,
  773. "VF %d attempted to override administratively set MAC address\n"
  774. "Reload the VF driver to resume operations\n",
  775. vf);
  776. return -1;
  777. }
  778. return ixgbe_set_vf_mac(adapter, vf, new_mac) < 0;
  779. }
  780. static int ixgbe_set_vf_vlan_msg(struct ixgbe_adapter *adapter,
  781. u32 *msgbuf, u32 vf)
  782. {
  783. u32 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> IXGBE_VT_MSGINFO_SHIFT;
  784. u32 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
  785. u8 tcs = adapter->hw_tcs;
  786. if (adapter->vfinfo[vf].pf_vlan || tcs) {
  787. e_warn(drv,
  788. "VF %d attempted to override administratively set VLAN configuration\n"
  789. "Reload the VF driver to resume operations\n",
  790. vf);
  791. return -1;
  792. }
  793. /* VLAN 0 is a special case, don't allow it to be removed */
  794. if (!vid && !add)
  795. return 0;
  796. return ixgbe_set_vf_vlan(adapter, add, vid, vf);
  797. }
  798. static int ixgbe_set_vf_macvlan_msg(struct ixgbe_adapter *adapter,
  799. u32 *msgbuf, u32 vf)
  800. {
  801. u8 *new_mac = ((u8 *)(&msgbuf[1]));
  802. int index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
  803. IXGBE_VT_MSGINFO_SHIFT;
  804. int err;
  805. if (adapter->vfinfo[vf].pf_set_mac && !adapter->vfinfo[vf].trusted &&
  806. index > 0) {
  807. e_warn(drv,
  808. "VF %d requested MACVLAN filter but is administratively denied\n",
  809. vf);
  810. return -1;
  811. }
  812. /* An non-zero index indicates the VF is setting a filter */
  813. if (index) {
  814. if (!is_valid_ether_addr(new_mac)) {
  815. e_warn(drv, "VF %d attempted to set invalid mac\n", vf);
  816. return -1;
  817. }
  818. /*
  819. * If the VF is allowed to set MAC filters then turn off
  820. * anti-spoofing to avoid false positives.
  821. */
  822. if (adapter->vfinfo[vf].spoofchk_enabled) {
  823. struct ixgbe_hw *hw = &adapter->hw;
  824. hw->mac.ops.set_mac_anti_spoofing(hw, false, vf);
  825. hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf);
  826. }
  827. }
  828. err = ixgbe_set_vf_macvlan(adapter, vf, index, new_mac);
  829. if (err == -ENOSPC)
  830. e_warn(drv,
  831. "VF %d has requested a MACVLAN filter but there is no space for it\n",
  832. vf);
  833. return err < 0;
  834. }
  835. static int ixgbe_negotiate_vf_api(struct ixgbe_adapter *adapter,
  836. u32 *msgbuf, u32 vf)
  837. {
  838. int api = msgbuf[1];
  839. switch (api) {
  840. case ixgbe_mbox_api_10:
  841. case ixgbe_mbox_api_11:
  842. case ixgbe_mbox_api_12:
  843. case ixgbe_mbox_api_13:
  844. adapter->vfinfo[vf].vf_api = api;
  845. return 0;
  846. default:
  847. break;
  848. }
  849. e_info(drv, "VF %d requested invalid api version %u\n", vf, api);
  850. return -1;
  851. }
  852. static int ixgbe_get_vf_queues(struct ixgbe_adapter *adapter,
  853. u32 *msgbuf, u32 vf)
  854. {
  855. struct net_device *dev = adapter->netdev;
  856. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  857. unsigned int default_tc = 0;
  858. u8 num_tcs = adapter->hw_tcs;
  859. /* verify the PF is supporting the correct APIs */
  860. switch (adapter->vfinfo[vf].vf_api) {
  861. case ixgbe_mbox_api_20:
  862. case ixgbe_mbox_api_11:
  863. case ixgbe_mbox_api_12:
  864. case ixgbe_mbox_api_13:
  865. break;
  866. default:
  867. return -1;
  868. }
  869. /* only allow 1 Tx queue for bandwidth limiting */
  870. msgbuf[IXGBE_VF_TX_QUEUES] = __ALIGN_MASK(1, ~vmdq->mask);
  871. msgbuf[IXGBE_VF_RX_QUEUES] = __ALIGN_MASK(1, ~vmdq->mask);
  872. /* if TCs > 1 determine which TC belongs to default user priority */
  873. if (num_tcs > 1)
  874. default_tc = netdev_get_prio_tc_map(dev, adapter->default_up);
  875. /* notify VF of need for VLAN tag stripping, and correct queue */
  876. if (num_tcs)
  877. msgbuf[IXGBE_VF_TRANS_VLAN] = num_tcs;
  878. else if (adapter->vfinfo[vf].pf_vlan || adapter->vfinfo[vf].pf_qos)
  879. msgbuf[IXGBE_VF_TRANS_VLAN] = 1;
  880. else
  881. msgbuf[IXGBE_VF_TRANS_VLAN] = 0;
  882. /* notify VF of default queue */
  883. msgbuf[IXGBE_VF_DEF_QUEUE] = default_tc;
  884. return 0;
  885. }
  886. static int ixgbe_get_vf_reta(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
  887. {
  888. u32 i, j;
  889. u32 *out_buf = &msgbuf[1];
  890. const u8 *reta = adapter->rss_indir_tbl;
  891. u32 reta_size = ixgbe_rss_indir_tbl_entries(adapter);
  892. /* Check if operation is permitted */
  893. if (!adapter->vfinfo[vf].rss_query_enabled)
  894. return -EPERM;
  895. /* verify the PF is supporting the correct API */
  896. switch (adapter->vfinfo[vf].vf_api) {
  897. case ixgbe_mbox_api_13:
  898. case ixgbe_mbox_api_12:
  899. break;
  900. default:
  901. return -EOPNOTSUPP;
  902. }
  903. /* This mailbox command is supported (required) only for 82599 and x540
  904. * VFs which support up to 4 RSS queues. Therefore we will compress the
  905. * RETA by saving only 2 bits from each entry. This way we will be able
  906. * to transfer the whole RETA in a single mailbox operation.
  907. */
  908. for (i = 0; i < reta_size / 16; i++) {
  909. out_buf[i] = 0;
  910. for (j = 0; j < 16; j++)
  911. out_buf[i] |= (u32)(reta[16 * i + j] & 0x3) << (2 * j);
  912. }
  913. return 0;
  914. }
  915. static int ixgbe_get_vf_rss_key(struct ixgbe_adapter *adapter,
  916. u32 *msgbuf, u32 vf)
  917. {
  918. u32 *rss_key = &msgbuf[1];
  919. /* Check if the operation is permitted */
  920. if (!adapter->vfinfo[vf].rss_query_enabled)
  921. return -EPERM;
  922. /* verify the PF is supporting the correct API */
  923. switch (adapter->vfinfo[vf].vf_api) {
  924. case ixgbe_mbox_api_13:
  925. case ixgbe_mbox_api_12:
  926. break;
  927. default:
  928. return -EOPNOTSUPP;
  929. }
  930. memcpy(rss_key, adapter->rss_key, IXGBE_RSS_KEY_SIZE);
  931. return 0;
  932. }
  933. static int ixgbe_update_vf_xcast_mode(struct ixgbe_adapter *adapter,
  934. u32 *msgbuf, u32 vf)
  935. {
  936. struct ixgbe_hw *hw = &adapter->hw;
  937. int xcast_mode = msgbuf[1];
  938. u32 vmolr, fctrl, disable, enable;
  939. /* verify the PF is supporting the correct APIs */
  940. switch (adapter->vfinfo[vf].vf_api) {
  941. case ixgbe_mbox_api_12:
  942. /* promisc introduced in 1.3 version */
  943. if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
  944. return -EOPNOTSUPP;
  945. /* Fall threw */
  946. case ixgbe_mbox_api_13:
  947. break;
  948. default:
  949. return -EOPNOTSUPP;
  950. }
  951. if (xcast_mode > IXGBEVF_XCAST_MODE_MULTI &&
  952. !adapter->vfinfo[vf].trusted) {
  953. xcast_mode = IXGBEVF_XCAST_MODE_MULTI;
  954. }
  955. if (adapter->vfinfo[vf].xcast_mode == xcast_mode)
  956. goto out;
  957. switch (xcast_mode) {
  958. case IXGBEVF_XCAST_MODE_NONE:
  959. disable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE |
  960. IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
  961. enable = 0;
  962. break;
  963. case IXGBEVF_XCAST_MODE_MULTI:
  964. disable = IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
  965. enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE;
  966. break;
  967. case IXGBEVF_XCAST_MODE_ALLMULTI:
  968. disable = IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
  969. enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_MPE;
  970. break;
  971. case IXGBEVF_XCAST_MODE_PROMISC:
  972. if (hw->mac.type <= ixgbe_mac_82599EB)
  973. return -EOPNOTSUPP;
  974. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  975. if (!(fctrl & IXGBE_FCTRL_UPE)) {
  976. /* VF promisc requires PF in promisc */
  977. e_warn(drv,
  978. "Enabling VF promisc requires PF in promisc\n");
  979. return -EPERM;
  980. }
  981. disable = 0;
  982. enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE |
  983. IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
  984. break;
  985. default:
  986. return -EOPNOTSUPP;
  987. }
  988. vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
  989. vmolr &= ~disable;
  990. vmolr |= enable;
  991. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
  992. adapter->vfinfo[vf].xcast_mode = xcast_mode;
  993. out:
  994. msgbuf[1] = xcast_mode;
  995. return 0;
  996. }
  997. static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf)
  998. {
  999. u32 mbx_size = IXGBE_VFMAILBOX_SIZE;
  1000. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  1001. struct ixgbe_hw *hw = &adapter->hw;
  1002. s32 retval;
  1003. retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
  1004. if (retval) {
  1005. pr_err("Error receiving message from VF\n");
  1006. return retval;
  1007. }
  1008. /* this is a message we already processed, do nothing */
  1009. if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
  1010. return 0;
  1011. /* flush the ack before we write any messages back */
  1012. IXGBE_WRITE_FLUSH(hw);
  1013. if (msgbuf[0] == IXGBE_VF_RESET)
  1014. return ixgbe_vf_reset_msg(adapter, vf);
  1015. /*
  1016. * until the vf completes a virtual function reset it should not be
  1017. * allowed to start any configuration.
  1018. */
  1019. if (!adapter->vfinfo[vf].clear_to_send) {
  1020. msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
  1021. ixgbe_write_mbx(hw, msgbuf, 1, vf);
  1022. return 0;
  1023. }
  1024. switch ((msgbuf[0] & 0xFFFF)) {
  1025. case IXGBE_VF_SET_MAC_ADDR:
  1026. retval = ixgbe_set_vf_mac_addr(adapter, msgbuf, vf);
  1027. break;
  1028. case IXGBE_VF_SET_MULTICAST:
  1029. retval = ixgbe_set_vf_multicasts(adapter, msgbuf, vf);
  1030. break;
  1031. case IXGBE_VF_SET_VLAN:
  1032. retval = ixgbe_set_vf_vlan_msg(adapter, msgbuf, vf);
  1033. break;
  1034. case IXGBE_VF_SET_LPE:
  1035. retval = ixgbe_set_vf_lpe(adapter, msgbuf, vf);
  1036. break;
  1037. case IXGBE_VF_SET_MACVLAN:
  1038. retval = ixgbe_set_vf_macvlan_msg(adapter, msgbuf, vf);
  1039. break;
  1040. case IXGBE_VF_API_NEGOTIATE:
  1041. retval = ixgbe_negotiate_vf_api(adapter, msgbuf, vf);
  1042. break;
  1043. case IXGBE_VF_GET_QUEUES:
  1044. retval = ixgbe_get_vf_queues(adapter, msgbuf, vf);
  1045. break;
  1046. case IXGBE_VF_GET_RETA:
  1047. retval = ixgbe_get_vf_reta(adapter, msgbuf, vf);
  1048. break;
  1049. case IXGBE_VF_GET_RSS_KEY:
  1050. retval = ixgbe_get_vf_rss_key(adapter, msgbuf, vf);
  1051. break;
  1052. case IXGBE_VF_UPDATE_XCAST_MODE:
  1053. retval = ixgbe_update_vf_xcast_mode(adapter, msgbuf, vf);
  1054. break;
  1055. default:
  1056. e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]);
  1057. retval = IXGBE_ERR_MBX;
  1058. break;
  1059. }
  1060. /* notify the VF of the results of what it sent us */
  1061. if (retval)
  1062. msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
  1063. else
  1064. msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
  1065. msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
  1066. ixgbe_write_mbx(hw, msgbuf, mbx_size, vf);
  1067. return retval;
  1068. }
  1069. static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf)
  1070. {
  1071. struct ixgbe_hw *hw = &adapter->hw;
  1072. u32 msg = IXGBE_VT_MSGTYPE_NACK;
  1073. /* if device isn't clear to send it shouldn't be reading either */
  1074. if (!adapter->vfinfo[vf].clear_to_send)
  1075. ixgbe_write_mbx(hw, &msg, 1, vf);
  1076. }
  1077. void ixgbe_msg_task(struct ixgbe_adapter *adapter)
  1078. {
  1079. struct ixgbe_hw *hw = &adapter->hw;
  1080. u32 vf;
  1081. for (vf = 0; vf < adapter->num_vfs; vf++) {
  1082. /* process any reset requests */
  1083. if (!ixgbe_check_for_rst(hw, vf))
  1084. ixgbe_vf_reset_event(adapter, vf);
  1085. /* process any messages pending */
  1086. if (!ixgbe_check_for_msg(hw, vf))
  1087. ixgbe_rcv_msg_from_vf(adapter, vf);
  1088. /* process any acks */
  1089. if (!ixgbe_check_for_ack(hw, vf))
  1090. ixgbe_rcv_ack_from_vf(adapter, vf);
  1091. }
  1092. }
  1093. void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter)
  1094. {
  1095. struct ixgbe_hw *hw = &adapter->hw;
  1096. /* disable transmit and receive for all vfs */
  1097. IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0);
  1098. IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0);
  1099. IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0);
  1100. IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0);
  1101. }
  1102. static inline void ixgbe_ping_vf(struct ixgbe_adapter *adapter, int vf)
  1103. {
  1104. struct ixgbe_hw *hw = &adapter->hw;
  1105. u32 ping;
  1106. ping = IXGBE_PF_CONTROL_MSG;
  1107. if (adapter->vfinfo[vf].clear_to_send)
  1108. ping |= IXGBE_VT_MSGTYPE_CTS;
  1109. ixgbe_write_mbx(hw, &ping, 1, vf);
  1110. }
  1111. void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter)
  1112. {
  1113. struct ixgbe_hw *hw = &adapter->hw;
  1114. u32 ping;
  1115. int i;
  1116. for (i = 0 ; i < adapter->num_vfs; i++) {
  1117. ping = IXGBE_PF_CONTROL_MSG;
  1118. if (adapter->vfinfo[i].clear_to_send)
  1119. ping |= IXGBE_VT_MSGTYPE_CTS;
  1120. ixgbe_write_mbx(hw, &ping, 1, i);
  1121. }
  1122. }
  1123. int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
  1124. {
  1125. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1126. s32 retval;
  1127. if (vf >= adapter->num_vfs)
  1128. return -EINVAL;
  1129. if (is_valid_ether_addr(mac)) {
  1130. dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n",
  1131. mac, vf);
  1132. dev_info(&adapter->pdev->dev, "Reload the VF driver to make this change effective.");
  1133. retval = ixgbe_set_vf_mac(adapter, vf, mac);
  1134. if (retval >= 0) {
  1135. adapter->vfinfo[vf].pf_set_mac = true;
  1136. if (test_bit(__IXGBE_DOWN, &adapter->state)) {
  1137. dev_warn(&adapter->pdev->dev, "The VF MAC address has been set, but the PF device is not up.\n");
  1138. dev_warn(&adapter->pdev->dev, "Bring the PF device up before attempting to use the VF device.\n");
  1139. }
  1140. } else {
  1141. dev_warn(&adapter->pdev->dev, "The VF MAC address was NOT set due to invalid or duplicate MAC address.\n");
  1142. }
  1143. } else if (is_zero_ether_addr(mac)) {
  1144. unsigned char *vf_mac_addr =
  1145. adapter->vfinfo[vf].vf_mac_addresses;
  1146. /* nothing to do */
  1147. if (is_zero_ether_addr(vf_mac_addr))
  1148. return 0;
  1149. dev_info(&adapter->pdev->dev, "removing MAC on VF %d\n", vf);
  1150. retval = ixgbe_del_mac_filter(adapter, vf_mac_addr, vf);
  1151. if (retval >= 0) {
  1152. adapter->vfinfo[vf].pf_set_mac = false;
  1153. memcpy(vf_mac_addr, mac, ETH_ALEN);
  1154. } else {
  1155. dev_warn(&adapter->pdev->dev, "Could NOT remove the VF MAC address.\n");
  1156. }
  1157. } else {
  1158. retval = -EINVAL;
  1159. }
  1160. return retval;
  1161. }
  1162. static int ixgbe_enable_port_vlan(struct ixgbe_adapter *adapter, int vf,
  1163. u16 vlan, u8 qos)
  1164. {
  1165. struct ixgbe_hw *hw = &adapter->hw;
  1166. int err;
  1167. err = ixgbe_set_vf_vlan(adapter, true, vlan, vf);
  1168. if (err)
  1169. goto out;
  1170. /* Revoke tagless access via VLAN 0 */
  1171. ixgbe_set_vf_vlan(adapter, false, 0, vf);
  1172. ixgbe_set_vmvir(adapter, vlan, qos, vf);
  1173. ixgbe_set_vmolr(hw, vf, false);
  1174. /* enable hide vlan on X550 */
  1175. if (hw->mac.type >= ixgbe_mac_X550)
  1176. ixgbe_write_qde(adapter, vf, IXGBE_QDE_ENABLE |
  1177. IXGBE_QDE_HIDE_VLAN);
  1178. adapter->vfinfo[vf].pf_vlan = vlan;
  1179. adapter->vfinfo[vf].pf_qos = qos;
  1180. dev_info(&adapter->pdev->dev,
  1181. "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
  1182. if (test_bit(__IXGBE_DOWN, &adapter->state)) {
  1183. dev_warn(&adapter->pdev->dev,
  1184. "The VF VLAN has been set, but the PF device is not up.\n");
  1185. dev_warn(&adapter->pdev->dev,
  1186. "Bring the PF device up before attempting to use the VF device.\n");
  1187. }
  1188. out:
  1189. return err;
  1190. }
  1191. static int ixgbe_disable_port_vlan(struct ixgbe_adapter *adapter, int vf)
  1192. {
  1193. struct ixgbe_hw *hw = &adapter->hw;
  1194. int err;
  1195. err = ixgbe_set_vf_vlan(adapter, false,
  1196. adapter->vfinfo[vf].pf_vlan, vf);
  1197. /* Restore tagless access via VLAN 0 */
  1198. ixgbe_set_vf_vlan(adapter, true, 0, vf);
  1199. ixgbe_clear_vmvir(adapter, vf);
  1200. ixgbe_set_vmolr(hw, vf, true);
  1201. /* disable hide VLAN on X550 */
  1202. if (hw->mac.type >= ixgbe_mac_X550)
  1203. ixgbe_write_qde(adapter, vf, IXGBE_QDE_ENABLE);
  1204. adapter->vfinfo[vf].pf_vlan = 0;
  1205. adapter->vfinfo[vf].pf_qos = 0;
  1206. return err;
  1207. }
  1208. int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
  1209. u8 qos, __be16 vlan_proto)
  1210. {
  1211. int err = 0;
  1212. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1213. if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7))
  1214. return -EINVAL;
  1215. if (vlan_proto != htons(ETH_P_8021Q))
  1216. return -EPROTONOSUPPORT;
  1217. if (vlan || qos) {
  1218. /* Check if there is already a port VLAN set, if so
  1219. * we have to delete the old one first before we
  1220. * can set the new one. The usage model had
  1221. * previously assumed the user would delete the
  1222. * old port VLAN before setting a new one but this
  1223. * is not necessarily the case.
  1224. */
  1225. if (adapter->vfinfo[vf].pf_vlan)
  1226. err = ixgbe_disable_port_vlan(adapter, vf);
  1227. if (err)
  1228. goto out;
  1229. err = ixgbe_enable_port_vlan(adapter, vf, vlan, qos);
  1230. } else {
  1231. err = ixgbe_disable_port_vlan(adapter, vf);
  1232. }
  1233. out:
  1234. return err;
  1235. }
  1236. int ixgbe_link_mbps(struct ixgbe_adapter *adapter)
  1237. {
  1238. switch (adapter->link_speed) {
  1239. case IXGBE_LINK_SPEED_100_FULL:
  1240. return 100;
  1241. case IXGBE_LINK_SPEED_1GB_FULL:
  1242. return 1000;
  1243. case IXGBE_LINK_SPEED_10GB_FULL:
  1244. return 10000;
  1245. default:
  1246. return 0;
  1247. }
  1248. }
  1249. static void ixgbe_set_vf_rate_limit(struct ixgbe_adapter *adapter, int vf)
  1250. {
  1251. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  1252. struct ixgbe_hw *hw = &adapter->hw;
  1253. u32 bcnrc_val = 0;
  1254. u16 queue, queues_per_pool;
  1255. u16 tx_rate = adapter->vfinfo[vf].tx_rate;
  1256. if (tx_rate) {
  1257. /* start with base link speed value */
  1258. bcnrc_val = adapter->vf_rate_link_speed;
  1259. /* Calculate the rate factor values to set */
  1260. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  1261. bcnrc_val /= tx_rate;
  1262. /* clear everything but the rate factor */
  1263. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  1264. IXGBE_RTTBCNRC_RF_DEC_MASK;
  1265. /* enable the rate scheduler */
  1266. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  1267. }
  1268. /*
  1269. * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
  1270. * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported
  1271. * and 0x004 otherwise.
  1272. */
  1273. switch (hw->mac.type) {
  1274. case ixgbe_mac_82599EB:
  1275. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4);
  1276. break;
  1277. case ixgbe_mac_X540:
  1278. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14);
  1279. break;
  1280. default:
  1281. break;
  1282. }
  1283. /* determine how many queues per pool based on VMDq mask */
  1284. queues_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  1285. /* write value for all Tx queues belonging to VF */
  1286. for (queue = 0; queue < queues_per_pool; queue++) {
  1287. unsigned int reg_idx = (vf * queues_per_pool) + queue;
  1288. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, reg_idx);
  1289. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  1290. }
  1291. }
  1292. void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter)
  1293. {
  1294. int i;
  1295. /* VF Tx rate limit was not set */
  1296. if (!adapter->vf_rate_link_speed)
  1297. return;
  1298. if (ixgbe_link_mbps(adapter) != adapter->vf_rate_link_speed) {
  1299. adapter->vf_rate_link_speed = 0;
  1300. dev_info(&adapter->pdev->dev,
  1301. "Link speed has been changed. VF Transmit rate is disabled\n");
  1302. }
  1303. for (i = 0; i < adapter->num_vfs; i++) {
  1304. if (!adapter->vf_rate_link_speed)
  1305. adapter->vfinfo[i].tx_rate = 0;
  1306. ixgbe_set_vf_rate_limit(adapter, i);
  1307. }
  1308. }
  1309. int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int min_tx_rate,
  1310. int max_tx_rate)
  1311. {
  1312. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1313. int link_speed;
  1314. /* verify VF is active */
  1315. if (vf >= adapter->num_vfs)
  1316. return -EINVAL;
  1317. /* verify link is up */
  1318. if (!adapter->link_up)
  1319. return -EINVAL;
  1320. /* verify we are linked at 10Gbps */
  1321. link_speed = ixgbe_link_mbps(adapter);
  1322. if (link_speed != 10000)
  1323. return -EINVAL;
  1324. if (min_tx_rate)
  1325. return -EINVAL;
  1326. /* rate limit cannot be less than 10Mbs or greater than link speed */
  1327. if (max_tx_rate && ((max_tx_rate <= 10) || (max_tx_rate > link_speed)))
  1328. return -EINVAL;
  1329. /* store values */
  1330. adapter->vf_rate_link_speed = link_speed;
  1331. adapter->vfinfo[vf].tx_rate = max_tx_rate;
  1332. /* update hardware configuration */
  1333. ixgbe_set_vf_rate_limit(adapter, vf);
  1334. return 0;
  1335. }
  1336. int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
  1337. {
  1338. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1339. struct ixgbe_hw *hw = &adapter->hw;
  1340. if (vf >= adapter->num_vfs)
  1341. return -EINVAL;
  1342. adapter->vfinfo[vf].spoofchk_enabled = setting;
  1343. /* configure MAC spoofing */
  1344. hw->mac.ops.set_mac_anti_spoofing(hw, setting, vf);
  1345. /* configure VLAN spoofing */
  1346. hw->mac.ops.set_vlan_anti_spoofing(hw, setting, vf);
  1347. /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be
  1348. * calling set_ethertype_anti_spoofing for each VF in loop below
  1349. */
  1350. if (hw->mac.ops.set_ethertype_anti_spoofing) {
  1351. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
  1352. (IXGBE_ETQF_FILTER_EN |
  1353. IXGBE_ETQF_TX_ANTISPOOF |
  1354. IXGBE_ETH_P_LLDP));
  1355. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC),
  1356. (IXGBE_ETQF_FILTER_EN |
  1357. IXGBE_ETQF_TX_ANTISPOOF |
  1358. ETH_P_PAUSE));
  1359. hw->mac.ops.set_ethertype_anti_spoofing(hw, setting, vf);
  1360. }
  1361. return 0;
  1362. }
  1363. int ixgbe_ndo_set_vf_rss_query_en(struct net_device *netdev, int vf,
  1364. bool setting)
  1365. {
  1366. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1367. /* This operation is currently supported only for 82599 and x540
  1368. * devices.
  1369. */
  1370. if (adapter->hw.mac.type < ixgbe_mac_82599EB ||
  1371. adapter->hw.mac.type >= ixgbe_mac_X550)
  1372. return -EOPNOTSUPP;
  1373. if (vf >= adapter->num_vfs)
  1374. return -EINVAL;
  1375. adapter->vfinfo[vf].rss_query_enabled = setting;
  1376. return 0;
  1377. }
  1378. int ixgbe_ndo_set_vf_trust(struct net_device *netdev, int vf, bool setting)
  1379. {
  1380. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1381. if (vf >= adapter->num_vfs)
  1382. return -EINVAL;
  1383. /* nothing to do */
  1384. if (adapter->vfinfo[vf].trusted == setting)
  1385. return 0;
  1386. adapter->vfinfo[vf].trusted = setting;
  1387. /* reset VF to reconfigure features */
  1388. adapter->vfinfo[vf].clear_to_send = false;
  1389. ixgbe_ping_vf(adapter, vf);
  1390. e_info(drv, "VF %u is %strusted\n", vf, setting ? "" : "not ");
  1391. return 0;
  1392. }
  1393. int ixgbe_ndo_get_vf_config(struct net_device *netdev,
  1394. int vf, struct ifla_vf_info *ivi)
  1395. {
  1396. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1397. if (vf >= adapter->num_vfs)
  1398. return -EINVAL;
  1399. ivi->vf = vf;
  1400. memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN);
  1401. ivi->max_tx_rate = adapter->vfinfo[vf].tx_rate;
  1402. ivi->min_tx_rate = 0;
  1403. ivi->vlan = adapter->vfinfo[vf].pf_vlan;
  1404. ivi->qos = adapter->vfinfo[vf].pf_qos;
  1405. ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled;
  1406. ivi->rss_query_en = adapter->vfinfo[vf].rss_query_enabled;
  1407. ivi->trusted = adapter->vfinfo[vf].trusted;
  1408. return 0;
  1409. }