summaryrefslogtreecommitdiff
path: root/usr/src/uts/sun4v/io/nxge/nxge_classify.c
blob: bcb36b6bc606ff972143ccfa1a47a58f0a67e614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <npi_fflp.h>
#include <nxge_defs.h>
#include <nxge_fflp.h>
#include <nxge_flow.h>
#include <nxge_impl.h>
#include <nxge_common.h>

/*
 * Globals: tunable parameters (/etc/system or adb)
 *
 */
int nxge_tcam_class_enable = 0;
int nxge_tcam_lookup_enable = 0;
int nxge_flow_dist_enable = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

/*
 * Bit mapped
 * 0x80000000:      Drop
 * 0x0000:      NO TCAM Lookup Needed
 * 0x0001:      TCAM Lookup Needed with Dest Addr (IPv6)
 * 0x0003:      TCAM Lookup Needed with SRC Addr (IPv6)
 * 0x0010:      use MAC Port
 * 0x0020:      use L2DA
 * 0x0040:      use VLAN
 * 0x0080:      use proto
 * 0x0100:      use IP src addr
 * 0x0200:      use IP dest addr
 * 0x0400:      use Src Port
 * 0x0800:      use Dest Port
 * 0x0fff:      enable all options for IPv6 (with src addr)
 * 0x0ffd:      enable all options for IPv6 (with dest addr)
 * 0x0fff:      enable all options for IPv4
 * 0x0ffd:      enable all options for IPv4
 *
 */

/*
 * the default is to distribute as function of:
 * protocol
 * ip src address
 * ip dest address
 * src port
 * dest port
 *
 * 0x0f80
 *
 */

int nxge_tcp4_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_udp4_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_ah4_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;
int nxge_sctp4_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_tcp6_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_udp6_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_ah6_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

int nxge_sctp6_class = NXGE_CLASS_FLOW_USE_DST_PORT |
	NXGE_CLASS_FLOW_USE_SRC_PORT | NXGE_CLASS_FLOW_USE_IPDST |
	NXGE_CLASS_FLOW_USE_IPSRC | NXGE_CLASS_FLOW_USE_PROTO |
	NXGE_CLASS_FLOW_USE_PORTNUM;

uint32_t nxge_fflp_init_h1 = 0xffffffff;
uint32_t nxge_fflp_init_h2 = 0xffff;

uint64_t class_quick_config_distribute[NXGE_CLASS_CONFIG_PARAMS] = {
	0xffffffffULL,		/* h1_init */
	0xffffULL,		/* h2_init */
	0x0,			/* cfg_ether_usr1 */
	0x0,			/* cfg_ether_usr2 */
	0x0,			/* cfg_ip_usr4 */
	0x0,			/* cfg_ip_usr5 */
	0x0,			/* cfg_ip_usr6 */
	0x0,			/* cfg_ip_usr7 */
	0x0,			/* opt_ip_usr4 */
	0x0,			/* opt_ip_usr5 */
	0x0,			/* opt_ip_usr6 */
	0x0,			/* opt_ip_usr7 */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_tcp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_udp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_ah */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_sctp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_tcp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_udp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_ah */
	NXGE_CLASS_FLOW_GEN_SERVER	/* opt_ipv6_sctp */
};

uint64_t class_quick_config_web_server[NXGE_CLASS_CONFIG_PARAMS] = {
	0xffffffffULL,		/* h1_init */
	0xffffULL,		/* h2_init */
	0x0,			/* cfg_ether_usr1 */
	0x0,			/* cfg_ether_usr2 */
	0x0,			/* cfg_ip_usr4 */
	0x0,			/* cfg_ip_usr5 */
	0x0,			/* cfg_ip_usr6 */
	0x0,			/* cfg_ip_usr7 */
	0x0,			/* opt_ip_usr4 */
	0x0,			/* opt_ip_usr5 */
	0x0,			/* opt_ip_usr6 */
	0x0,			/* opt_ip_usr7 */
	NXGE_CLASS_FLOW_WEB_SERVER,	/* opt_ipv4_tcp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_udp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_ah */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv4_sctp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_tcp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_udp */
	NXGE_CLASS_FLOW_GEN_SERVER,	/* opt_ipv6_ah */
	NXGE_CLASS_FLOW_GEN_SERVER	/* opt_ipv6_sctp */
};

nxge_status_t
nxge_classify_init(p_nxge_t nxgep)
{
	nxge_status_t status = NXGE_OK;

	status = nxge_classify_init_sw(nxgep);
	if (status != NXGE_OK)
		return (status);
	status = nxge_set_hw_classify_config(nxgep);
	if (status != NXGE_OK)
		return (status);

	status = nxge_classify_init_hw(nxgep);
	if (status != NXGE_OK)
		return (status);

	return (NXGE_OK);
}

nxge_status_t
nxge_classify_uninit(p_nxge_t nxgep)
{
	nxge_status_t status = NXGE_OK;

	status = nxge_classify_exit_sw(nxgep);
	if (status != NXGE_OK) {
		return (status);
	}
	return (NXGE_OK);
}

/* ARGSUSED */
uint64_t
nxge_classify_get_cfg_value(p_nxge_t nxgep, uint8_t cfg_type, uint8_t cfg_param)
{
	uint64_t cfg_value;

	if (cfg_param >= NXGE_CLASS_CONFIG_PARAMS)
		return (-1);
	switch (cfg_type) {
	case CFG_L3_WEB:
		cfg_value = class_quick_config_web_server[cfg_param];
		break;
	case CFG_L3_DISTRIBUTE:
	default:
		cfg_value = class_quick_config_distribute[cfg_param];
		break;
	}
	return (cfg_value);
}

nxge_status_t
nxge_set_hw_classify_config(p_nxge_t nxgep)
{
	p_nxge_dma_pt_cfg_t p_all_cfgp;
	p_nxge_hw_pt_cfg_t p_cfgp;

	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_get_hw_classify_config"));

	/* Get mac rdc table info from HW/Prom/.conf etc ...... */
	/* for now, get it from dma configs */
	p_all_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_all_cfgp->hw_config;

	/*
	 * classify_init needs to call first.
	 */
	nxgep->class_config.mac_rdcgrp = p_cfgp->def_mac_rxdma_grpid;
	nxgep->class_config.mcast_rdcgrp = p_cfgp->def_mac_rxdma_grpid;
	NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_get_hw_classify_config"));

	return (NXGE_OK);
}