1 /****************************************************************************** 2 3 Copyright (c) 2001-2017, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Intel Corporation nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 ******************************************************************************/ 33 /*$FreeBSD: head/sys/dev/ixgbe/if_fdir.c 327031 2017-12-20 18:15:06Z erj $*/ 34 35 #include "ixgbe.h" 36 37 #ifdef IXGBE_FDIR 38 39 void 40 ixgbe_init_fdir(struct adapter *adapter) 41 { 42 u32 hdrm = 32 << fdir_pballoc; 43 44 if (!(adapter->feat_en & IXGBE_FEATURE_FDIR)) 45 return; 46 47 adapter->hw.mac.ops.setup_rxpba(&adapter->hw, 0, hdrm, 48 PBA_STRATEGY_EQUAL); 49 ixgbe_init_fdir_signature_82599(&adapter->hw, fdir_pballoc); 50 } /* ixgbe_init_fdir */ 51 52 void 53 ixgbe_reinit_fdir(void *context) 54 { 55 struct adapter *adapter = context; 56 struct ifnet *ifp = adapter->ifp; 57 58 KASSERT(mutex_owned(&adapter->core_mtx)); 59 60 if (!(adapter->feat_en & IXGBE_FEATURE_FDIR)) 61 return; 62 if (adapter->fdir_reinit != 1) /* Shouldn't happen */ 63 return; 64 ixgbe_reinit_fdir_tables_82599(&adapter->hw); 65 adapter->fdir_reinit = 0; 66 /* re-enable flow director interrupts */ 67 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); 68 /* Restart the interface */ 69 ifp->if_drv_flags |= IFF_DRV_RUNNING; 70 } /* ixgbe_reinit_fdir */ 71 72 /************************************************************************ 73 * ixgbe_atr 74 * 75 * Parse packet headers so that Flow Director can make 76 * a hashed filter table entry allowing traffic flows 77 * to be identified and kept on the same cpu. This 78 * would be a performance hit, but we only do it at 79 * IXGBE_FDIR_RATE of packets. 80 ************************************************************************/ 81 void 82 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp) 83 { 84 struct adapter *adapter = txr->adapter; 85 struct ix_queue *que; 86 struct ip *ip; 87 struct tcphdr *th; 88 struct udphdr *uh; 89 struct ether_vlan_header *eh; 90 union ixgbe_atr_hash_dword input = {.dword = 0}; 91 union ixgbe_atr_hash_dword common = {.dword = 0}; 92 int ehdrlen, ip_hlen; 93 u16 etype; 94 95 eh = mtod(mp, struct ether_vlan_header *); 96 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { 97 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; 98 etype = eh->evl_proto; 99 } else { 100 ehdrlen = ETHER_HDR_LEN; 101 etype = eh->evl_encap_proto; 102 } 103 104 /* Only handling IPv4 */ 105 if (etype != htons(ETHERTYPE_IP)) 106 return; 107 108 ip = (struct ip *)(mp->m_data + ehdrlen); 109 ip_hlen = ip->ip_hl << 2; 110 111 /* check if we're UDP or TCP */ 112 switch (ip->ip_p) { 113 case IPPROTO_TCP: 114 th = (struct tcphdr *)((caddr_t)ip + ip_hlen); 115 /* src and dst are inverted */ 116 common.port.dst ^= th->th_sport; 117 common.port.src ^= th->th_dport; 118 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_TCPV4; 119 break; 120 case IPPROTO_UDP: 121 uh = (struct udphdr *)((caddr_t)ip + ip_hlen); 122 /* src and dst are inverted */ 123 common.port.dst ^= uh->uh_sport; 124 common.port.src ^= uh->uh_dport; 125 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_UDPV4; 126 break; 127 default: 128 return; 129 } 130 131 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag); 132 if (mp->m_pkthdr.ether_vtag) 133 common.flex_bytes ^= htons(ETHERTYPE_VLAN); 134 else 135 common.flex_bytes ^= etype; 136 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr; 137 138 que = &adapter->queues[txr->me]; 139 /* 140 * This assumes the Rx queue and Tx 141 * queue are bound to the same CPU 142 */ 143 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, 144 input, common, que->msix); 145 } /* ixgbe_atr */ 146 147 #else 148 149 /* TASK_INIT needs this function defined regardless if it's enabled */ 150 void 151 ixgbe_reinit_fdir(void *context) 152 { 153 UNREFERENCED_1PARAMETER(context); 154 } /* ixgbe_reinit_fdir */ 155 156 void 157 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp) 158 { 159 UNREFERENCED_2PARAMETER(txr, mp); 160 } /* ixgbe_atr */ 161 162 #endif 163