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