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
|
/* $OpenBSD: if_tht.c,v 1.5 2007/04/16 12:13:16 dlg Exp $ */
/*
* Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Driver for the Tehuti TN30xx multi port 10Gb Ethernet chipsets,
* see http://www.tehutinetworks.net/.
*
* This driver was made possible because Tehuti networks provided
* hardware and documentation. Thanks!
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <machine/bus.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
/* registers */
#define THT_PCI_BAR 0x10
#define THT_REG_10G_REV 0x6000
#define THT_REG_10G_SCR 0x6004
#define THT_REG_10G_CTL 0x6008
#define THT_REG_10G_FMT_LNG 0x6014
#define THT_REG_10G_PAUSE 0x6018
#define THT_REG_10G_RX_SEC 0x601c
#define THT_REG_10G_TX_SEC 0x6020
#define THT_REG_10G_RFIFO_AEF 0x6024
#define THT_REG_10G_TFIFO_AEF 0x6028
#define THT_REG_10G_SM_STAT 0x6030
#define THT_REG_10G_SM_CMD 0x6034
#define THT_REG_10G_SM_DAT 0x6038
#define THT_REG_10G_SM_ADD 0x603c
#define THT_REG_10G_STAT 0x6040
/* pci controller autoconf glue */
struct thtc_softc {
struct device sc_dev;
void *sc_ih;
bus_dma_tag_t sc_dmat;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
bus_size_t sc_mems;
};
int thtc_match(struct device *, void *, void *);
void thtc_attach(struct device *, struct device *, void *);
struct cfattach thtc_ca = {
sizeof(struct thtc_softc), thtc_match, thtc_attach
};
struct cfdriver thtc_cd = {
NULL, "thtc", DV_DULL
};
/* port autoconf glue */
struct tht_softc {
struct device csc_dev;
};
int tht_match(struct device *, void *, void *);
void tht_attach(struct device *, struct device *, void *);
struct cfattach tht_ca = {
sizeof(struct tht_softc), tht_match, tht_attach
};
struct cfdriver tht_cd = {
NULL, "tht", DV_IFNET
};
/* misc goo */
int thtc_intr(void *);
#define DEVNAME(_sc) ((_sc)->sc_dev.dv_xname)
#define sizeofa(_a) (sizeof(_a) / sizeof((_a)[0]))
struct thtc_device {
pci_vendor_id_t td_vendor;
pci_vendor_id_t td_product;
u_int td_nports;
};
const struct thtc_device *thtc_lookup(struct pci_attach_args *);
static const struct thtc_device thtc_devices[] = {
{ PCI_VENDOR_TEHUTI, PCI_PRODUCT_TEHUTI_TN3009, 1 },
{ PCI_VENDOR_TEHUTI, PCI_PRODUCT_TEHUTI_TN3010, 1 },
{ PCI_VENDOR_TEHUTI, PCI_PRODUCT_TEHUTI_TN3014, 2 }
};
const struct thtc_device *
thtc_lookup(struct pci_attach_args *pa)
{
int i;
const struct thtc_device *td;
for (i = 0; i < sizeofa(thtc_devices); i++) {
td = &thtc_devices[i];
if (td->td_vendor == PCI_VENDOR(pa->pa_id) &&
td->td_product == PCI_PRODUCT(pa->pa_id))
return (td);
}
return (NULL);
}
int
thtc_match(struct device *parent, void *match, void *aux)
{
struct pci_attach_args *pa = aux;
if (thtc_lookup(pa) != NULL)
return (1);
return (0);
}
void
thtc_attach(struct device *parent, struct device *self, void *aux)
{
struct thtc_softc *sc = (struct thtc_softc *)self;
struct pci_attach_args *pa = aux;
pcireg_t memtype;
pci_intr_handle_t ih;
const char *intrstr;
sc->sc_dmat = pa->pa_dmat;
memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, THT_PCI_BAR);
if (pci_mapreg_map(pa, THT_PCI_BAR, memtype, 0, &sc->sc_memt,
&sc->sc_memh, NULL, &sc->sc_mems, 0) != 0) {
printf(": unable to map host registers\n");
return;
}
if (pci_intr_map(pa, &ih) != 0) {
printf(": unable to map interrupt\n");
goto unmap;
}
intrstr = pci_intr_string(pa->pa_pc, ih);
sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET,
thtc_intr, sc, DEVNAME(sc));
if (sc->sc_ih == NULL) {
printf(": unable to map interrupt%s%s\n",
intrstr == NULL ? "" : " at ",
intrstr == NULL ? "" : intrstr);
goto unmap;
}
printf(": %s\n", intrstr);
return;
unmap:
bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
sc->sc_mems = 0;
}
int
tht_match(struct device *parent, void *match, void *aux)
{
return (0);
}
void
tht_attach(struct device *parent, struct device *self, void *aux)
{
printf("\n");
}
int
thtc_intr(void *arg)
{
return (0);
}
|