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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
/* $OpenBSD: cn30xxpip.c,v 1.1 2011/06/16 11:22:30 syuu Exp $ */
/*
* Copyright (c) 2007 Internet Initiative Japan, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/time.h>
#include <net/if.h>
#include <machine/octeonvar.h>
#include <octeon/dev/cn30xxpipreg.h>
#include <octeon/dev/cn30xxpipvar.h>
#ifndef SET
#define SET(t, f) ((t) |= (f))
#define ISSET(t, f) ((t) & (f))
#define CLR(t, f) ((t) &= ~(f))
#endif
#ifdef OCTEON_ETH_DEBUG
struct cn30xxpip_softc *__cn30xxpip_softc;
void cn30xxpip_intr_evcnt_attach(struct cn30xxpip_softc *);
void cn30xxpip_intr_rml(void *);
void cn30xxpip_dump(void);
void cn30xxpip_int_enable(struct cn30xxpip_softc *, int);
#endif
/*
* register definitions (for debug and statics)
*/
#define _ENTRY(x) { #x, x##_BITS, x##_OFFSET }
#define _ENTRY_0_3(x) \
_ENTRY(x## 0), _ENTRY(x## 1), _ENTRY(x## 2), _ENTRY(x## 3)
#define _ENTRY_0_7(x) \
_ENTRY(x## 0), _ENTRY(x## 1), _ENTRY(x## 2), _ENTRY(x## 3), \
_ENTRY(x## 4), _ENTRY(x## 5), _ENTRY(x## 6), _ENTRY(x## 7)
#define _ENTRY_0_1_2_32(x) \
_ENTRY(x## 0), _ENTRY(x## 1), _ENTRY(x## 2), _ENTRY(x##32)
struct cn30xxpip_dump_reg_ {
const char *name;
const char *format;
size_t offset;
};
static const struct cn30xxpip_dump_reg_ cn30xxpip_dump_stats_[] = {
/* PIP_QOS_DIFF[0-63] */
_ENTRY_0_1_2_32 (PIP_STAT0_PRT),
_ENTRY_0_1_2_32 (PIP_STAT1_PRT),
_ENTRY_0_1_2_32 (PIP_STAT2_PRT),
_ENTRY_0_1_2_32 (PIP_STAT3_PRT),
_ENTRY_0_1_2_32 (PIP_STAT4_PRT),
_ENTRY_0_1_2_32 (PIP_STAT5_PRT),
_ENTRY_0_1_2_32 (PIP_STAT6_PRT),
_ENTRY_0_1_2_32 (PIP_STAT7_PRT),
_ENTRY_0_1_2_32 (PIP_STAT8_PRT),
_ENTRY_0_1_2_32 (PIP_STAT9_PRT),
/* PIP_TAG_INC[0-63] */
_ENTRY_0_1_2_32 (PIP_STAT_INB_PKTS),
_ENTRY_0_1_2_32 (PIP_STAT_INB_OCTS),
_ENTRY_0_1_2_32 (PIP_STAT_INB_ERRS),
};
static const struct cn30xxpip_dump_reg_ cn30xxpip_dump_regs_[] = {
_ENTRY (PIP_BIST_STATUS),
_ENTRY (PIP_INT_REG),
_ENTRY (PIP_INT_EN),
_ENTRY (PIP_STAT_CTL),
_ENTRY (PIP_GBL_CTL),
_ENTRY (PIP_GBL_CFG),
_ENTRY (PIP_SOFT_RST),
_ENTRY (PIP_IP_OFFSET),
_ENTRY (PIP_TAG_SECRET),
_ENTRY (PIP_TAG_MASK),
_ENTRY_0_3 (PIP_DEC_IPSEC),
_ENTRY (PIP_RAW_WORD),
_ENTRY_0_7 (PIP_QOS_VLAN),
_ENTRY_0_3 (PIP_QOS_WATCH),
_ENTRY_0_1_2_32 (PIP_PRT_CFG),
_ENTRY_0_1_2_32 (PIP_PRT_TAG),
};
#undef _ENTRY
#undef _ENTRY_0_3
#undef _ENTRY_0_7
#undef _ENTRY_0_1_2_32
/* XXX */
void
cn30xxpip_init(struct cn30xxpip_attach_args *aa,
struct cn30xxpip_softc **rsc)
{
struct cn30xxpip_softc *sc;
int status;
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
if (sc == NULL)
panic("can't allocate memory: %s", __func__);
sc->sc_port = aa->aa_port;
sc->sc_regt = aa->aa_regt;
sc->sc_tag_type = aa->aa_tag_type;
sc->sc_receive_group = aa->aa_receive_group;
sc->sc_ip_offset = aa->aa_ip_offset;
status = bus_space_map(sc->sc_regt, PIP_BASE, PIP_SIZE, 0,
&sc->sc_regh);
if (status != 0)
panic("can't map %s space", "pip register");
*rsc = sc;
#ifdef OCTEON_ETH_DEBUG
cn30xxpip_int_enable(sc, 1);
cn30xxpip_intr_evcnt_attach(sc);
__cn30xxpip_softc = sc;
printf("PIP Code initialized.\n");
#endif
}
#define _PIP_RD8(sc, off) \
bus_space_read_8((sc)->sc_regt, (sc)->sc_regh, (off))
#define _PIP_WR8(sc, off, v) \
bus_space_write_8((sc)->sc_regt, (sc)->sc_regh, (off), (v))
int
cn30xxpip_port_config(struct cn30xxpip_softc *sc)
{
uint64_t prt_cfg;
uint64_t prt_tag;
uint64_t ip_offset;
/*
* Process the headers and place the IP header in the work queue
*/
prt_cfg = 0;
/* RAWDRP=0; don't allow raw packet drop */
/* TAGINC=0 */
SET(prt_cfg, PIP_PRT_CFGN_DYN_RS);
/* INST_HDR=0 */
/* GRP_WAT=0 */
SET(prt_cfg, (sc->sc_port << 24) & PIP_PRT_CFGN_QOS);
/* QOS_WAT=0 */
/* SPARE=0 */
/* QOS_DIFF=0 */
/* QOS_VLAN=0 */
SET(prt_cfg, PIP_PRT_CFGN_CRC_EN);
SET(prt_cfg, (PIP_PORT_CFG_MODE_L2) & PIP_PRT_CFGN_MODE);
/* SKIP=0 */
prt_tag = 0;
SET(prt_tag, PIP_PRT_TAGN_INC_PRT);
CLR(prt_tag, PIP_PRT_TAGN_IP6_DPRT);
CLR(prt_tag, PIP_PRT_TAGN_IP4_DPRT);
CLR(prt_tag, PIP_PRT_TAGN_IP6_SPRT);
CLR(prt_tag, PIP_PRT_TAGN_IP4_SPRT);
CLR(prt_tag, PIP_PRT_TAGN_IP6_NXTH);
CLR(prt_tag, PIP_PRT_TAGN_IP4_PCTL);
CLR(prt_tag, PIP_PRT_TAGN_IP6_DST);
CLR(prt_tag, PIP_PRT_TAGN_IP4_SRC);
CLR(prt_tag, PIP_PRT_TAGN_IP6_SRC);
CLR(prt_tag, PIP_PRT_TAGN_IP4_DST);
SET(prt_tag, PIP_PRT_TAGN_TCP6_TAG_ORDERED);
SET(prt_tag, PIP_PRT_TAGN_TCP4_TAG_ORDERED);
SET(prt_tag, PIP_PRT_TAGN_IP6_TAG_ORDERED);
SET(prt_tag, PIP_PRT_TAGN_IP4_TAG_ORDERED);
SET(prt_tag, PIP_PRT_TAGN_NON_TAG_ORDERED);
SET(prt_tag, sc->sc_receive_group & PIP_PRT_TAGN_GRP);
ip_offset = 0;
SET(ip_offset, (sc->sc_ip_offset / 8) & PIP_IP_OFFSET_MASK_OFFSET);
_PIP_WR8(sc, PIP_PRT_CFG0_OFFSET + (8 * sc->sc_port), prt_cfg);
_PIP_WR8(sc, PIP_PRT_TAG0_OFFSET + (8 * sc->sc_port), prt_tag);
_PIP_WR8(sc, PIP_IP_OFFSET_OFFSET, ip_offset);
return 0;
}
void
cn30xxpip_prt_cfg_enable(struct cn30xxpip_softc *sc, uint64_t prt_cfg,
int enable)
{
uint64_t tmp;
tmp = _PIP_RD8(sc, PIP_PRT_CFG0_OFFSET + (8 * sc->sc_port));
if (enable)
tmp |= prt_cfg;
else
tmp &= ~prt_cfg;
_PIP_WR8(sc, PIP_PRT_CFG0_OFFSET + (8 * sc->sc_port), tmp);
}
void
cn30xxpip_stats(struct cn30xxpip_softc *sc, struct ifnet *ifp, int gmx_port)
{
const struct cn30xxpip_dump_reg_ *reg;
uint64_t tmp, pkts, octs;
uint64_t pip_stat_ctl;
if (sc == NULL || ifp == NULL)
panic("%s: invalid argument. sc=%p, ifp=%p\n", __func__,
sc, ifp);
if (gmx_port < 0 || gmx_port > 2) {
printf("%s: invalid gmx_port %d\n", __func__, gmx_port);
return;
}
pip_stat_ctl = _PIP_RD8(sc, PIP_STAT_CTL_OFFSET);
_PIP_WR8(sc, PIP_STAT_CTL_OFFSET, pip_stat_ctl | PIP_STAT_CTL_RDCLR);
reg = &cn30xxpip_dump_stats_[gmx_port];
tmp = _PIP_RD8(sc, reg->offset);
octs = (tmp & 0x00000000ffffffffULL); /* XXX: no counter in ifp?? */
pkts = (tmp & 0xffffffff00000000ULL) >> 32;
ifp->if_iqdrops += pkts;
_PIP_WR8(sc, PIP_STAT_CTL_OFFSET, pip_stat_ctl);
}
#ifdef OCTEON_ETH_DEBUG
int cn30xxpip_intr_rml_verbose;
struct evcnt cn30xxpip_intr_evcnt;
static const struct octeon_evcnt_entry cn30xxpip_intr_evcnt_entries[] = {
#define _ENTRY(name, type, parent, descr) \
OCTEON_EVCNT_ENTRY(struct cn30xxpip_softc, name, type, parent, descr)
_ENTRY(pipbeperr, MISC, NULL, "pip parity error backend"),
_ENTRY(pipfeperr, MISC, NULL, "pip parity error frontend"),
_ENTRY(pipskprunt, MISC, NULL, "pip skiper"),
_ENTRY(pipbadtag, MISC, NULL, "pip bad tag"),
_ENTRY(pipprtnxa, MISC, NULL, "pip nonexistent port"),
_ENTRY(pippktdrp, MISC, NULL, "pip qos drop"),
#undef _ENTRY
};
void
cn30xxpip_intr_evcnt_attach(struct cn30xxpip_softc *sc)
{
OCTEON_EVCNT_ATTACH_EVCNTS(sc, cn30xxpip_intr_evcnt_entries, "pip0");
}
void
cn30xxpip_intr_rml(void *arg)
{
struct cn30xxpip_softc *sc;
uint64_t reg;
cn30xxpip_intr_evcnt.ev_count++;
sc = __cn30xxpip_softc;
KASSERT(sc != NULL);
reg = cn30xxpip_int_summary(sc);
if (cn30xxpip_intr_rml_verbose)
printf("%s: PIP_INT_REG=0x%016llx\n", __func__, reg);
if (reg & PIP_INT_REG_BEPERR)
OCTEON_EVCNT_INC(sc, pipbeperr);
if (reg & PIP_INT_REG_FEPERR)
OCTEON_EVCNT_INC(sc, pipfeperr);
if (reg & PIP_INT_REG_SKPRUNT)
OCTEON_EVCNT_INC(sc, pipskprunt);
if (reg & PIP_INT_REG_BADTAG)
OCTEON_EVCNT_INC(sc, pipbadtag);
if (reg & PIP_INT_REG_PRTNXA)
OCTEON_EVCNT_INC(sc, pipprtnxa);
if (reg & PIP_INT_REG_PKTDRP)
OCTEON_EVCNT_INC(sc, pippktdrp);
}
void cn30xxpip_dump_regs(void);
void cn30xxpip_dump_stats(void);
void
cn30xxpip_dump(void)
{
cn30xxpip_dump_regs();
cn30xxpip_dump_stats();
}
void
cn30xxpip_dump_regs(void)
{
struct cn30xxpip_softc *sc = __cn30xxpip_softc;
const struct cn30xxpip_dump_reg_ *reg;
uint64_t tmp;
char buf[512];
int i;
for (i = 0; i < (int)nitems(cn30xxpip_dump_regs_); i++) {
reg = &cn30xxpip_dump_regs_[i];
tmp = _PIP_RD8(sc, reg->offset);
snprintf(buf, sizeof(buf), "%16llx", tmp);
printf("\t%-24s: %s\n", reg->name, buf);
}
}
void
cn30xxpip_dump_stats(void)
{
struct cn30xxpip_softc *sc = __cn30xxpip_softc;
const struct cn30xxpip_dump_reg_ *reg;
uint64_t tmp;
char buf[512];
int i;
uint64_t pip_stat_ctl;
pip_stat_ctl = _PIP_RD8(sc, PIP_STAT_CTL_OFFSET);
_PIP_WR8(sc, PIP_STAT_CTL_OFFSET, pip_stat_ctl & ~PIP_STAT_CTL_RDCLR);
for (i = 0; i < (int)nitems(cn30xxpip_dump_stats_); i++) {
reg = &cn30xxpip_dump_stats_[i];
tmp = _PIP_RD8(sc, reg->offset);
if (reg->format == NULL) {
snprintf(buf, sizeof(buf), "%16llx", tmp);
}
printf("\t%-24s: %s\n", reg->name, buf);
}
printf("\t%-24s:\n", "PIP_QOS_DIFF[0-63]");
for (i = 0; i < 64; i++) {
tmp = _PIP_RD8(sc, PIP_QOS_DIFF0_OFFSET + sizeof(uint64_t) * i);
snprintf(buf, sizeof(buf), "%16" PRIx64, tmp);
printf("%s\t%s%s",
((i % 4) == 0) ? "\t" : "",
buf,
((i % 4) == 3) ? "\n" : "");
}
printf("\t%-24s:\n", "PIP_TAG_INC[0-63]");
for (i = 0; i < 64; i++) {
tmp = _PIP_RD8(sc, PIP_TAG_INC0_OFFSET + sizeof(uint64_t) * i);
snprintf(buf, sizeof(buf), "%16" PRIx64, tmp);
printf("%s\t%s%s",
((i % 4) == 0) ? "\t" : "",
buf,
((i % 4) == 3) ? "\n" : "");
}
_PIP_WR8(sc, PIP_STAT_CTL_OFFSET, pip_stat_ctl);
}
void
cn30xxpip_int_enable(struct cn30xxpip_softc *sc, int enable)
{
uint64_t pip_int_xxx = 0;
SET(pip_int_xxx,
PIP_INT_EN_BEPERR |
PIP_INT_EN_FEPERR |
PIP_INT_EN_SKPRUNT |
PIP_INT_EN_BADTAG |
PIP_INT_EN_PRTNXA |
PIP_INT_EN_PKTDRP);
_PIP_WR8(sc, PIP_INT_REG_OFFSET, pip_int_xxx);
_PIP_WR8(sc, PIP_INT_EN_OFFSET, enable ? pip_int_xxx : 0);
}
uint64_t
cn30xxpip_int_summary(struct cn30xxpip_softc *sc)
{
uint64_t summary;
summary = _PIP_RD8(sc, PIP_INT_REG_OFFSET);
_PIP_WR8(sc, PIP_INT_REG_OFFSET, summary);
return summary;
}
#endif /* OCTEON_ETH_DEBUG */
|