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