Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

igb: add pf side of VMDq support

Add the pf portion of vmdq support. This provides enough support so that
VMDq is enabled, and the pf is functional without enabling vfs.

Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alexander Duyck and committed by
David S. Miller
e1739522 1bfaf07b

+195 -19
+26
drivers/net/igb/e1000_82575.h
··· 40 40 #define E1000_SRRCTL_BSIZEHDRSIZE_SHIFT 2 /* Shift _left_ */ 41 41 #define E1000_SRRCTL_DESCTYPE_ADV_ONEBUF 0x02000000 42 42 #define E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS 0x0A000000 43 + #define E1000_SRRCTL_DROP_EN 0x80000000 43 44 44 45 #define E1000_MRQC_ENABLE_RSS_4Q 0x00000002 46 + #define E1000_MRQC_ENABLE_VMDQ 0x00000003 47 + #define E1000_MRQC_ENABLE_VMDQ_RSS_2Q 0x00000005 45 48 #define E1000_MRQC_RSS_FIELD_IPV4_UDP 0x00400000 46 49 #define E1000_MRQC_RSS_FIELD_IPV6_UDP 0x00800000 47 50 #define E1000_MRQC_RSS_FIELD_IPV6_UDP_EX 0x01000000 ··· 161 158 #define E1000_DCA_RXCTRL_CPUID_MASK_82576 0xFF000000 /* Rx CPUID Mask */ 162 159 #define E1000_DCA_TXCTRL_CPUID_SHIFT 24 /* Tx CPUID now in the last byte */ 163 160 #define E1000_DCA_RXCTRL_CPUID_SHIFT 24 /* Rx CPUID now in the last byte */ 161 + 162 + /* Easy defines for setting default pool, would normally be left a zero */ 163 + #define E1000_VT_CTL_DEFAULT_POOL_SHIFT 7 164 + #define E1000_VT_CTL_DEFAULT_POOL_MASK (0x7 << E1000_VT_CTL_DEFAULT_POOL_SHIFT) 165 + 166 + /* Other useful VMD_CTL register defines */ 167 + #define E1000_VT_CTL_IGNORE_MAC (1 << 28) 168 + #define E1000_VT_CTL_DISABLE_DEF_POOL (1 << 29) 169 + #define E1000_VT_CTL_VM_REPL_EN (1 << 30) 170 + 171 + /* Per VM Offload register setup */ 172 + #define E1000_VMOLR_RLPML_MASK 0x00003FFF /* Long Packet Maximum Length mask */ 173 + #define E1000_VMOLR_LPE 0x00010000 /* Accept Long packet */ 174 + #define E1000_VMOLR_RSSE 0x00020000 /* Enable RSS */ 175 + #define E1000_VMOLR_AUPE 0x01000000 /* Accept untagged packets */ 176 + #define E1000_VMOLR_ROMPE 0x02000000 /* Accept overflow multicast */ 177 + #define E1000_VMOLR_ROPE 0x04000000 /* Accept overflow unicast */ 178 + #define E1000_VMOLR_BAM 0x08000000 /* Accept Broadcast packets */ 179 + #define E1000_VMOLR_MPME 0x10000000 /* Multicast promiscuous mode */ 180 + #define E1000_VMOLR_STRVLAN 0x40000000 /* Vlan stripping enable */ 181 + 182 + #define ALL_QUEUES 0xFFFF 183 + 164 184 165 185 #endif
+2
drivers/net/igb/e1000_defines.h
··· 399 399 #define E1000_RAH_AV 0x80000000 /* Receive descriptor valid */ 400 400 #define E1000_RAL_MAC_ADDR_LEN 4 401 401 #define E1000_RAH_MAC_ADDR_LEN 2 402 + #define E1000_RAH_POOL_MASK 0x03FC0000 403 + #define E1000_RAH_POOL_1 0x00040000 402 404 403 405 /* Error Codes */ 404 406 #define E1000_ERR_NVM 1
+6 -1
drivers/net/igb/e1000_regs.h
··· 292 292 #define E1000_RAH(_i) (((_i) <= 15) ? (0x05404 + ((_i) * 8)) : \ 293 293 (0x054E4 + ((_i - 16) * 8))) 294 294 #define E1000_VFTA 0x05600 /* VLAN Filter Table Array - RW Array */ 295 - #define E1000_VMD_CTL 0x0581C /* VMDq Control - RW */ 295 + #define E1000_VT_CTL 0x0581C /* VMDq Control - RW */ 296 296 #define E1000_WUC 0x05800 /* Wakeup Control - RW */ 297 297 #define E1000_WUFC 0x05808 /* Wakeup Filter Control - RW */ 298 298 #define E1000_WUS 0x05810 /* Wakeup Status - RO */ ··· 319 319 /* Redirection Table - RW Array */ 320 320 #define E1000_RETA(_i) (0x05C00 + ((_i) * 4)) 321 321 #define E1000_RSSRK(_i) (0x05C80 + ((_i) * 4)) /* RSS Random Key - RW Array */ 322 + 323 + /* VT Registers */ 324 + #define E1000_QDE 0x02408 /* Queue Drop Enable - RW */ 325 + /* These act per VF so an array friendly macro is used */ 326 + #define E1000_VMOLR(_n) (0x05AD0 + (4 * (_n))) 322 327 323 328 #define wr32(reg, value) (writel(value, hw->hw_addr + reg)) 324 329 #define rd32(reg) (readl(hw->hw_addr + reg))
+1 -2
drivers/net/igb/igb.h
··· 88 88 #define IGB_RXBUFFER_2048 2048 89 89 #define IGB_RXBUFFER_16384 16384 90 90 91 - /* Packet Buffer allocations */ 92 - 91 + #define MAX_STD_JUMBO_FRAME_SIZE 9234 93 92 94 93 /* How many Tx Descriptors do we need to call netif_wake_queue ? */ 95 94 #define IGB_TX_QUEUE_WAKE 16
+1 -1
drivers/net/igb/igb_ethtool.c
··· 398 398 regs_buff[34] = rd32(E1000_RLPML); 399 399 regs_buff[35] = rd32(E1000_RFCTL); 400 400 regs_buff[36] = rd32(E1000_MRQC); 401 - regs_buff[37] = rd32(E1000_VMD_CTL); 401 + regs_buff[37] = rd32(E1000_VT_CTL); 402 402 403 403 /* Transmit */ 404 404 regs_buff[38] = rd32(E1000_TCTL);
+159 -15
drivers/net/igb/igb_main.c
··· 122 122 static void igb_vlan_rx_add_vid(struct net_device *, u16); 123 123 static void igb_vlan_rx_kill_vid(struct net_device *, u16); 124 124 static void igb_restore_vlan(struct igb_adapter *); 125 + static inline void igb_set_rah_pool(struct e1000_hw *, int , int); 126 + static void igb_set_mc_list_pools(struct igb_adapter *, int, u16); 127 + static inline void igb_set_vmolr(struct e1000_hw *, int); 128 + static inline void igb_set_vf_rlpml(struct igb_adapter *, int, int); 125 129 126 130 static int igb_suspend(struct pci_dev *, pm_message_t); 127 131 #ifdef CONFIG_PM ··· 892 888 if (adapter->msix_entries) 893 889 igb_configure_msix(adapter); 894 890 891 + igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); 892 + igb_set_vmolr(hw, adapter->vfs_allocated_count); 893 + 895 894 /* Clear any pending interrupts. */ 896 895 rd32(E1000_ICR); 897 896 igb_irq_enable(adapter); ··· 1624 1617 * clean_rx handler before we do so. */ 1625 1618 igb_configure(adapter); 1626 1619 1620 + igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); 1621 + igb_set_vmolr(hw, adapter->vfs_allocated_count); 1622 + 1627 1623 err = igb_request_irq(adapter); 1628 1624 if (err) 1629 1625 goto err_req_irq; ··· 1807 1797 wr32(E1000_DCA_TXCTRL(j), txctrl); 1808 1798 } 1809 1799 1810 - /* Use the default values for the Tx Inter Packet Gap (IPG) timer */ 1800 + /* disable queue 0 to prevent tail bump w/o re-configuration */ 1801 + if (adapter->vfs_allocated_count) 1802 + wr32(E1000_TXDCTL(0), 0); 1811 1803 1812 1804 /* Program the Transmit Control Register */ 1813 - 1814 1805 tctl = rd32(E1000_TCTL); 1815 1806 tctl &= ~E1000_TCTL_CT; 1816 1807 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | ··· 1965 1954 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF; 1966 1955 } 1967 1956 1957 + /* Attention!!! For SR-IOV PF driver operations you must enable 1958 + * queue drop for all VF and PF queues to prevent head of line blocking 1959 + * if an un-trusted VF does not provide descriptors to hardware. 1960 + */ 1961 + if (adapter->vfs_allocated_count) { 1962 + u32 vmolr; 1963 + 1964 + j = adapter->rx_ring[0].reg_idx; 1965 + 1966 + /* set all queue drop enable bits */ 1967 + wr32(E1000_QDE, ALL_QUEUES); 1968 + srrctl |= E1000_SRRCTL_DROP_EN; 1969 + 1970 + /* disable queue 0 to prevent tail write w/o re-config */ 1971 + wr32(E1000_RXDCTL(0), 0); 1972 + 1973 + vmolr = rd32(E1000_VMOLR(j)); 1974 + if (rctl & E1000_RCTL_LPE) 1975 + vmolr |= E1000_VMOLR_LPE; 1976 + if (adapter->num_rx_queues > 0) 1977 + vmolr |= E1000_VMOLR_RSSE; 1978 + wr32(E1000_VMOLR(j), vmolr); 1979 + } 1980 + 1968 1981 for (i = 0; i < adapter->num_rx_queues; i++) { 1969 1982 j = adapter->rx_ring[i].reg_idx; 1970 1983 wr32(E1000_SRRCTL(j), srrctl); 1971 1984 } 1972 1985 1973 1986 wr32(E1000_RCTL, rctl); 1987 + } 1988 + 1989 + /** 1990 + * igb_rlpml_set - set maximum receive packet size 1991 + * @adapter: board private structure 1992 + * 1993 + * Configure maximum receivable packet size. 1994 + **/ 1995 + static void igb_rlpml_set(struct igb_adapter *adapter) 1996 + { 1997 + u32 max_frame_size = adapter->max_frame_size; 1998 + struct e1000_hw *hw = &adapter->hw; 1999 + u16 pf_id = adapter->vfs_allocated_count; 2000 + 2001 + if (adapter->vlgrp) 2002 + max_frame_size += VLAN_TAG_SIZE; 2003 + 2004 + /* if vfs are enabled we set RLPML to the largest possible request 2005 + * size and set the VMOLR RLPML to the size we need */ 2006 + if (pf_id) { 2007 + igb_set_vf_rlpml(adapter, max_frame_size, pf_id); 2008 + max_frame_size = MAX_STD_JUMBO_FRAME_SIZE + VLAN_TAG_SIZE; 2009 + } 2010 + 2011 + wr32(E1000_RLPML, max_frame_size); 2012 + } 2013 + 2014 + /** 2015 + * igb_configure_vt_default_pool - Configure VT default pool 2016 + * @adapter: board private structure 2017 + * 2018 + * Configure the default pool 2019 + **/ 2020 + static void igb_configure_vt_default_pool(struct igb_adapter *adapter) 2021 + { 2022 + struct e1000_hw *hw = &adapter->hw; 2023 + u16 pf_id = adapter->vfs_allocated_count; 2024 + u32 vtctl; 2025 + 2026 + /* not in sr-iov mode - do nothing */ 2027 + if (!pf_id) 2028 + return; 2029 + 2030 + vtctl = rd32(E1000_VT_CTL); 2031 + vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK | 2032 + E1000_VT_CTL_DISABLE_DEF_POOL); 2033 + vtctl |= pf_id << E1000_VT_CTL_DEFAULT_POOL_SHIFT; 2034 + wr32(E1000_VT_CTL, vtctl); 1974 2035 } 1975 2036 1976 2037 /** ··· 2116 2033 writel(reta.dword, 2117 2034 hw->hw_addr + E1000_RETA(0) + (j & ~3)); 2118 2035 } 2119 - 2120 - mrqc = E1000_MRQC_ENABLE_RSS_4Q; 2036 + if (adapter->vfs_allocated_count) 2037 + mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q; 2038 + else 2039 + mrqc = E1000_MRQC_ENABLE_RSS_4Q; 2121 2040 2122 2041 /* Fill out hash function seeds */ 2123 2042 for (j = 0; j < 10; j++) ··· 2144 2059 rxcsum |= E1000_RXCSUM_PCSD; 2145 2060 wr32(E1000_RXCSUM, rxcsum); 2146 2061 } else { 2062 + /* Enable multi-queue for sr-iov */ 2063 + if (adapter->vfs_allocated_count) 2064 + wr32(E1000_MRQC, E1000_MRQC_ENABLE_VMDQ); 2147 2065 /* Enable Receive Checksum Offload for TCP and UDP */ 2148 2066 rxcsum = rd32(E1000_RXCSUM); 2149 2067 if (adapter->rx_csum) ··· 2157 2069 wr32(E1000_RXCSUM, rxcsum); 2158 2070 } 2159 2071 2160 - if (adapter->vlgrp) 2161 - wr32(E1000_RLPML, 2162 - adapter->max_frame_size + VLAN_TAG_SIZE); 2163 - else 2164 - wr32(E1000_RLPML, adapter->max_frame_size); 2072 + /* Set the default pool for the PF's first queue */ 2073 + igb_configure_vt_default_pool(adapter); 2074 + 2075 + igb_rlpml_set(adapter); 2165 2076 2166 2077 /* Enable Receives */ 2167 2078 wr32(E1000_RCTL, rctl); ··· 2390 2303 2391 2304 hw->mac.ops.rar_set(hw, hw->mac.addr, 0); 2392 2305 2306 + igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); 2307 + 2393 2308 return 0; 2394 2309 } 2395 2310 ··· 2451 2362 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN); 2452 2363 mc_ptr = mc_ptr->next; 2453 2364 } 2454 - igb_update_mc_addr_list(hw, mta_list, i, 1, mac->rar_entry_count); 2365 + igb_update_mc_addr_list(hw, mta_list, i, 2366 + adapter->vfs_allocated_count + 1, 2367 + mac->rar_entry_count); 2368 + 2369 + igb_set_mc_list_pools(adapter, i, mac->rar_entry_count); 2455 2370 kfree(mta_list); 2456 2371 } 2457 2372 ··· 3315 3222 return -EINVAL; 3316 3223 } 3317 3224 3318 - #define MAX_STD_JUMBO_FRAME_SIZE 9234 3319 3225 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { 3320 3226 dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n"); 3321 3227 return -EINVAL; ··· 3348 3256 #else 3349 3257 adapter->rx_buffer_len = PAGE_SIZE / 2; 3350 3258 #endif 3259 + 3260 + /* if sr-iov is enabled we need to force buffer size to 1K or larger */ 3261 + if (adapter->vfs_allocated_count && 3262 + (adapter->rx_buffer_len < IGB_RXBUFFER_1024)) 3263 + adapter->rx_buffer_len = IGB_RXBUFFER_1024; 3264 + 3351 3265 /* adjust allocation if LPE protects us, and we aren't using SBP */ 3352 3266 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || 3353 3267 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)) ··· 4560 4462 rctl &= ~E1000_RCTL_CFIEN; 4561 4463 wr32(E1000_RCTL, rctl); 4562 4464 igb_update_mng_vlan(adapter); 4563 - wr32(E1000_RLPML, 4564 - adapter->max_frame_size + VLAN_TAG_SIZE); 4565 4465 } else { 4566 4466 /* disable VLAN tag insert/strip */ 4567 4467 ctrl = rd32(E1000_CTRL); ··· 4570 4474 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 4571 4475 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; 4572 4476 } 4573 - wr32(E1000_RLPML, 4574 - adapter->max_frame_size); 4575 4477 } 4478 + 4479 + igb_rlpml_set(adapter); 4576 4480 4577 4481 if (!test_bit(__IGB_DOWN, &adapter->state)) 4578 4482 igb_irq_enable(adapter); ··· 4935 4839 /* let the f/w know that the h/w is now under the control of the 4936 4840 * driver. */ 4937 4841 igb_get_hw_control(adapter); 4842 + } 4843 + 4844 + static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn) 4845 + { 4846 + u32 reg_data; 4847 + 4848 + reg_data = rd32(E1000_VMOLR(vfn)); 4849 + reg_data |= E1000_VMOLR_BAM | /* Accept broadcast */ 4850 + E1000_VMOLR_ROPE | /* Accept packets matched in UTA */ 4851 + E1000_VMOLR_ROMPE | /* Accept packets matched in MTA */ 4852 + E1000_VMOLR_AUPE | /* Accept untagged packets */ 4853 + E1000_VMOLR_STRVLAN; /* Strip vlan tags */ 4854 + wr32(E1000_VMOLR(vfn), reg_data); 4855 + } 4856 + 4857 + static inline void igb_set_vf_rlpml(struct igb_adapter *adapter, int size, 4858 + int vfn) 4859 + { 4860 + struct e1000_hw *hw = &adapter->hw; 4861 + u32 vmolr; 4862 + 4863 + vmolr = rd32(E1000_VMOLR(vfn)); 4864 + vmolr &= ~E1000_VMOLR_RLPML_MASK; 4865 + vmolr |= size | E1000_VMOLR_LPE; 4866 + wr32(E1000_VMOLR(vfn), vmolr); 4867 + } 4868 + 4869 + static inline void igb_set_rah_pool(struct e1000_hw *hw, int pool, int entry) 4870 + { 4871 + u32 reg_data; 4872 + 4873 + reg_data = rd32(E1000_RAH(entry)); 4874 + reg_data &= ~E1000_RAH_POOL_MASK; 4875 + reg_data |= E1000_RAH_POOL_1 << pool;; 4876 + wr32(E1000_RAH(entry), reg_data); 4877 + } 4878 + 4879 + static void igb_set_mc_list_pools(struct igb_adapter *adapter, 4880 + int entry_count, u16 total_rar_filters) 4881 + { 4882 + struct e1000_hw *hw = &adapter->hw; 4883 + int i = adapter->vfs_allocated_count + 1; 4884 + 4885 + if ((i + entry_count) < total_rar_filters) 4886 + total_rar_filters = i + entry_count; 4887 + 4888 + for (; i < total_rar_filters; i++) 4889 + igb_set_rah_pool(hw, adapter->vfs_allocated_count, i); 4938 4890 } 4939 4891 4940 4892 /* igb_main.c */