FreeBSD kernel IXGBE device code
if_fdir.c
Go to the documentation of this file.
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$*/
34
35#include "ixgbe.h"
36
37#ifdef IXGBE_FDIR
38
39void
41{
42 u32 hdrm = 32 << fdir_pballoc;
43
44 if (!(sc->feat_en & IXGBE_FEATURE_FDIR))
45 return;
46
47 sc->hw.mac.ops.setup_rxpba(&sc->hw, 0, hdrm,
49 ixgbe_init_fdir_signature_82599(&sc->hw, fdir_pballoc);
50} /* ixgbe_init_fdir */
51
52void
53ixgbe_reinit_fdir(void *context)
54{
55 if_ctx_t ctx = context;
56 struct ixgbe_softc *sc = iflib_get_softc(ctx);
57 struct ifnet *ifp = iflib_get_ifp(ctx);
58
59 if (!(sc->feat_en & IXGBE_FEATURE_FDIR))
60 return;
61 if (sc->fdir_reinit != 1) /* Shouldn't happen */
62 return;
64 sc->fdir_reinit = 0;
65 /* re-enable flow director interrupts */
67 /* Restart the interface */
68 ifp->if_drv_flags |= IFF_DRV_RUNNING;
69} /* ixgbe_reinit_fdir */
70
71/************************************************************************
72 * ixgbe_atr
73 *
74 * Parse packet headers so that Flow Director can make
75 * a hashed filter table entry allowing traffic flows
76 * to be identified and kept on the same cpu. This
77 * would be a performance hit, but we only do it at
78 * IXGBE_FDIR_RATE of packets.
79 ************************************************************************/
80void
81ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
82{
83 struct ixgbe_softc *sc = txr->sc;
84 struct ix_queue *que;
85 struct ip *ip;
86 struct tcphdr *th;
87 struct udphdr *uh;
88 struct ether_vlan_header *eh;
89 union ixgbe_atr_hash_dword input = {.dword = 0};
90 union ixgbe_atr_hash_dword common = {.dword = 0};
91 int ehdrlen, ip_hlen;
92 u16 etype;
93
94 eh = mtod(mp, struct ether_vlan_header *);
95 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
96 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
97 etype = eh->evl_proto;
98 } else {
99 ehdrlen = ETHER_HDR_LEN;
100 etype = eh->evl_encap_proto;
101 }
102
103 /* Only handling IPv4 */
104 if (etype != htons(ETHERTYPE_IP))
105 return;
106
107 ip = (struct ip *)(mp->m_data + ehdrlen);
108 ip_hlen = ip->ip_hl << 2;
109
110 /* check if we're UDP or TCP */
111 switch (ip->ip_p) {
112 case IPPROTO_TCP:
113 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
114 /* src and dst are inverted */
115 common.port.dst ^= th->th_sport;
116 common.port.src ^= th->th_dport;
118 break;
119 case IPPROTO_UDP:
120 uh = (struct udphdr *)((caddr_t)ip + ip_hlen);
121 /* src and dst are inverted */
122 common.port.dst ^= uh->uh_sport;
123 common.port.src ^= uh->uh_dport;
125 break;
126 default:
127 return;
128 }
129
130 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag);
131 if (mp->m_pkthdr.ether_vtag)
132 common.flex_bytes ^= htons(ETHERTYPE_VLAN);
133 else
134 common.flex_bytes ^= etype;
135 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr;
136
137 que = &sc->queues[txr->me];
138 /*
139 * This assumes the Rx queue and Tx
140 * queue are bound to the same CPU
141 */
143 input, common, que->msix);
144} /* ixgbe_atr */
145
146#else
147
148/* TASK_INIT needs this function defined regardless if it's enabled */
149void
150ixgbe_reinit_fdir(void *context)
151{
152 UNREFERENCED_PARAMETER(context);
153} /* ixgbe_reinit_fdir */
154
155void
156ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
157{
159} /* ixgbe_atr */
160
161#endif
void ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
Definition: if_fdir.c:156
void ixgbe_reinit_fdir(void *context)
Definition: if_fdir.c:150
s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
Definition: ixgbe_82599.c:1235
void ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw, union ixgbe_atr_hash_dword input, union ixgbe_atr_hash_dword common, u8 queue)
Definition: ixgbe_82599.c:1545
s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
Definition: ixgbe_82599.c:1351
#define ixgbe_init_fdir(_a)
Definition: ixgbe_fdir.h:51
#define IXGBE_FEATURE_FDIR
#define UNREFERENCED_2PARAMETER(_p, _q)
Definition: ixgbe_osdep.h:127
#define UNREFERENCED_PARAMETER(_p)
Definition: ixgbe_osdep.h:125
#define IXGBE_WRITE_REG(a, reg, val)
Definition: ixgbe_osdep.h:227
uint16_t u16
Definition: ixgbe_osdep.h:145
uint32_t u32
Definition: ixgbe_osdep.h:147
#define IXGBE_EIMS
Definition: ixgbe_type.h:352
@ IXGBE_ATR_FLOW_TYPE_TCPV4
Definition: ixgbe_type.h:3555
@ IXGBE_ATR_FLOW_TYPE_UDPV4
Definition: ixgbe_type.h:3554
@ PBA_STRATEGY_EQUAL
Definition: ixgbe_type.h:1771
#define IXGBE_EIMS_FLOW_DIR
Definition: ixgbe_type.h:1966
struct ixgbe_mac_info mac
Definition: ixgbe_type.h:4207
struct ixgbe_mac_operations ops
Definition: ixgbe_type.h:4114
void(* setup_rxpba)(struct ixgbe_hw *, int, u32, int)
Definition: ixgbe_type.h:3990
int fdir_reinit
Definition: ixgbe.h:413
u32 feat_en
Definition: ixgbe.h:463
struct ixgbe_hw hw
Definition: ixgbe.h:353
if_ctx_t ctx
Definition: ixgbe.h:355
Definition: ixgbe.h:262
uint8_t me
Definition: ixgbe.h:271
struct ixgbe_softc * sc
Definition: ixgbe.h:263
struct ixgbe_atr_hash_dword::@20 port
struct ixgbe_atr_hash_dword::@19 formatted