Sat Mar 13 20:21:37 2021 UTC ()
sun4v: vnet - reception and transmission of eternet frames seems to work now (it is possible to ping 8.8.8.8 from inside a sun4v ldom). Still cleanup of debug code to be done.


(palle)
diff -r1.3 -r1.4 src/sys/arch/sparc64/dev/vnet.c

cvs diff -r1.3 -r1.4 src/sys/arch/sparc64/dev/vnet.c (switch to unified diff)

--- src/sys/arch/sparc64/dev/vnet.c 2021/03/11 19:34:11 1.3
+++ src/sys/arch/sparc64/dev/vnet.c 2021/03/13 20:21:37 1.4
@@ -1,2191 +1,2300 @@ @@ -1,2191 +1,2300 @@
1/* $NetBSD: vnet.c,v 1.3 2021/03/11 19:34:11 palle Exp $ */ 1/* $NetBSD: vnet.c,v 1.4 2021/03/13 20:21:37 palle Exp $ */
2/* $OpenBSD: vnet.c,v 1.62 2020/07/10 13:26:36 patrick Exp $ */ 2/* $OpenBSD: vnet.c,v 1.62 2020/07/10 13:26:36 patrick Exp $ */
3/* 3/*
4 * Copyright (c) 2009, 2015 Mark Kettenis 4 * Copyright (c) 2009, 2015 Mark Kettenis
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19#if 0 19#if 0
20FIXME openbsd 20FIXME openbsd
21#include "bpfilter.h" 21#include "bpfilter.h"
22#endif 22#endif
23 23
24#include <sys/kmem.h> 24#include <sys/kmem.h>
25#include <sys/param.h> 25#include <sys/param.h>
26#include <sys/atomic.h> 26#include <sys/atomic.h>
27#include <sys/device.h> 27#include <sys/device.h>
28#include <sys/malloc.h> 28#include <sys/malloc.h>
29#include <sys/pool.h> 29#include <sys/pool.h>
30#include <sys/mbuf.h> 30#include <sys/mbuf.h>
31#include <sys/socket.h> 31#include <sys/socket.h>
32#include <sys/sockio.h> 32#include <sys/sockio.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#if 0 34#if 0
35FIXME openbsd 35FIXME openbsd
36#include <sys/timeout.h> 36#include <sys/timeout.h>
37#else 37#else
38#include <sys/callout.h> 38#include <sys/callout.h>
39#endif 39#endif
40 40
41#include <machine/autoconf.h> 41#include <machine/autoconf.h>
42#include <machine/hypervisor.h> 42#include <machine/hypervisor.h>
43#include <machine/openfirm.h> 43#include <machine/openfirm.h>
44 44
45#include <net/if.h> 45#include <net/if.h>
46#include <net/if_media.h> 46#include <net/if_media.h>
47 47
48#include <netinet/in.h> 48#include <netinet/in.h>
49#include <net/if_ether.h> 49#include <net/if_ether.h>
50 50
51#if NBPFILTER > 0 51#if NBPFILTER > 0
52#include <net/bpf.h> 52#include <net/bpf.h>
53#endif 53#endif
54 54
55#include <uvm/uvm_extern.h> 55#include <uvm/uvm_extern.h>
56 56
57#include <sparc64/dev/cbusvar.h> 57#include <sparc64/dev/cbusvar.h>
58#include <sparc64/dev/ldcvar.h> 58#include <sparc64/dev/ldcvar.h>
59#include <sparc64/dev/viovar.h> 59#include <sparc64/dev/viovar.h>
60 60
61#if 1 61#if 1
62#define VNET_DEBUG 62#define VNET_DEBUG
63#endif 63#endif
64#ifdef VNET_DEBUG 64#ifdef VNET_DEBUG
65#define DPRINTF(x) printf x 65#define DPRINTF(x) printf x
66#else 66#else
67#define DPRINTF(x) 67#define DPRINTF(x)
68#endif 68#endif
69 69
70#define VNET_TX_ENTRIES 32 70#define VNET_TX_ENTRIES 32
71#define VNET_RX_ENTRIES 32 71#define VNET_RX_ENTRIES 32
72 72
73struct vnet_attr_info { 73struct vnet_attr_info {
74 struct vio_msg_tag tag; 74 struct vio_msg_tag tag;
75 uint8_t xfer_mode; 75 uint8_t xfer_mode;
76 uint8_t addr_type; 76 uint8_t addr_type;
77 uint16_t ack_freq; 77 uint16_t ack_freq;
78 uint32_t _reserved1; 78 uint32_t _reserved1;
79 uint64_t addr; 79 uint64_t addr;
80 uint64_t mtu; 80 uint64_t mtu;
81 uint64_t _reserved2[3]; 81 uint64_t _reserved2[3];
82}; 82};
83 83
84/* Address types. */ 84/* Address types. */
85#define VNET_ADDR_ETHERMAC 0x01 85#define VNET_ADDR_ETHERMAC 0x01
86 86
87/* Sub-Type envelopes. */ 87/* Sub-Type envelopes. */
88#define VNET_MCAST_INFO 0x0101 88#define VNET_MCAST_INFO 0x0101
89 89
90#define VNET_NUM_MCAST 7 90#define VNET_NUM_MCAST 7
91 91
92struct vnet_mcast_info { 92struct vnet_mcast_info {
93 struct vio_msg_tag tag; 93 struct vio_msg_tag tag;
94 uint8_t set; 94 uint8_t set;
95 uint8_t count; 95 uint8_t count;
96 uint8_t mcast_addr[VNET_NUM_MCAST][ETHER_ADDR_LEN]; 96 uint8_t mcast_addr[VNET_NUM_MCAST][ETHER_ADDR_LEN];
97 uint32_t _reserved; 97 uint32_t _reserved;
98}; 98};
99 99
100struct vnet_desc { 100struct vnet_desc {
101 struct vio_dring_hdr hdr; 101 struct vio_dring_hdr hdr;
102 uint32_t nbytes; 102 uint32_t nbytes;
103 uint32_t ncookies; 103 uint32_t ncookies;
104 struct ldc_cookie cookie[2]; 104 struct ldc_cookie cookie[2];
105}; 105};
106 106
107struct vnet_desc_msg { 107struct vnet_desc_msg {
108 struct vio_msg_tag tag; 108 struct vio_msg_tag tag;
109 uint64_t seq_no; 109 uint64_t seq_no;
110 uint64_t desc_handle; 110 uint64_t desc_handle;
111 uint32_t nbytes; 111 uint32_t nbytes;
112 uint32_t ncookies; 112 uint32_t ncookies;
113 struct ldc_cookie cookie[1]; 113 struct ldc_cookie cookie[1];
114}; 114};
115 115
116struct vnet_dring { 116struct vnet_dring {
117 bus_dmamap_t vd_map; 117 bus_dmamap_t vd_map;
118 bus_dma_segment_t vd_seg; 118 bus_dma_segment_t vd_seg;
119 struct vnet_desc *vd_desc; 119 struct vnet_desc *vd_desc;
120 int vd_nentries; 120 int vd_nentries;
121}; 121};
122 122
123struct vnet_dring *vnet_dring_alloc(bus_dma_tag_t, int); 123struct vnet_dring *vnet_dring_alloc(bus_dma_tag_t, int);
124void vnet_dring_free(bus_dma_tag_t, struct vnet_dring *); 124void vnet_dring_free(bus_dma_tag_t, struct vnet_dring *);
125 125
126/* 126/*
127 * For now, we only support vNet 1.0. 127 * For now, we only support vNet 1.0.
128 */ 128 */
129#define VNET_MAJOR 1 129#define VNET_MAJOR 1
130#define VNET_MINOR 0 130#define VNET_MINOR 0
131 131
132/* 132/*
133 * The vNet protocol wants the IP header to be 64-bit aligned, so 133 * The vNet protocol wants the IP header to be 64-bit aligned, so
134 * define out own variant of ETHER_ALIGN. 134 * define out own variant of ETHER_ALIGN.
135 */ 135 */
136#define VNET_ETHER_ALIGN 6 136#define VNET_ETHER_ALIGN 6
137 137
138struct vnet_soft_desc { 138struct vnet_soft_desc {
139 int vsd_map_idx; 139 int vsd_map_idx;
140#if 0 140#if 0
141FIXME openbsd  141FIXME openbsd
142 caddr_t vsd_buf; 142 caddr_t vsd_buf;
143#else  143#else
144 unsigned char *vsd_buf; 144 unsigned char *vsd_buf;
145#endif  145#endif
146}; 146};
147 147
148struct vnet_softc { 148struct vnet_softc {
149 struct device sc_dv; 149 struct device sc_dv;
150 bus_space_tag_t sc_bustag; 150 bus_space_tag_t sc_bustag;
151 bus_dma_tag_t sc_dmatag; 151 bus_dma_tag_t sc_dmatag;
152 152
153 uint64_t sc_tx_ino; 153 uint64_t sc_tx_ino;
154 uint64_t sc_rx_ino; 154 uint64_t sc_rx_ino;
155 void *sc_tx_ih; 155 void *sc_tx_ih;
156 void *sc_rx_ih; 156 void *sc_rx_ih;
157 157
158 struct ldc_conn sc_lc; 158 struct ldc_conn sc_lc;
159 159
160 uint16_t sc_vio_state; 160 uint16_t sc_vio_state;
161#define VIO_SND_VER_INFO 0x0001 161#define VIO_SND_VER_INFO 0x0001
162#define VIO_ACK_VER_INFO 0x0002 162#define VIO_ACK_VER_INFO 0x0002
163#define VIO_RCV_VER_INFO 0x0004 163#define VIO_RCV_VER_INFO 0x0004
164#define VIO_SND_ATTR_INFO 0x0008 164#define VIO_SND_ATTR_INFO 0x0008
165#define VIO_ACK_ATTR_INFO 0x0010 165#define VIO_ACK_ATTR_INFO 0x0010
166#define VIO_RCV_ATTR_INFO 0x0020 166#define VIO_RCV_ATTR_INFO 0x0020
167#define VIO_SND_DRING_REG 0x0040 167#define VIO_SND_DRING_REG 0x0040
168#define VIO_ACK_DRING_REG 0x0080 168#define VIO_ACK_DRING_REG 0x0080
169#define VIO_RCV_DRING_REG 0x0100 169#define VIO_RCV_DRING_REG 0x0100
170#define VIO_SND_RDX 0x0200 170#define VIO_SND_RDX 0x0200
171#define VIO_ACK_RDX 0x0400 171#define VIO_ACK_RDX 0x0400
172#define VIO_RCV_RDX 0x0800 172#define VIO_RCV_RDX 0x0800
173 173
174#if 0 174#if 0
175FIXME openbsd  175FIXME openbsd
176 struct timeout sc_handshake_to; 176 struct timeout sc_handshake_to;
177#else 177#else
178 struct callout sc_handshake_co; 178 struct callout sc_handshake_co;
179#endif  179#endif
180 180
181 uint8_t sc_xfer_mode; 181 uint8_t sc_xfer_mode;
182 182
183 uint32_t sc_local_sid; 183 uint32_t sc_local_sid;
184 uint64_t sc_dring_ident; 184 uint64_t sc_dring_ident;
185 uint64_t sc_seq_no; 185 uint64_t sc_seq_no;
186 186
187 u_int sc_tx_prod; 187 u_int sc_tx_prod;
188 u_int sc_tx_cons; 188 u_int sc_tx_cons;
189 189
190 u_int sc_peer_state; 190 u_int sc_peer_state;
191 191
192 struct ldc_map *sc_lm; 192 struct ldc_map *sc_lm;
193 struct vnet_dring *sc_vd; 193 struct vnet_dring *sc_vd;
194 struct vnet_soft_desc *sc_vsd; 194 struct vnet_soft_desc *sc_vsd;
195#define VNET_NUM_SOFT_DESC 128 195#define VNET_NUM_SOFT_DESC 128
196 196
197 size_t sc_peer_desc_size; 197 size_t sc_peer_desc_size;
198 struct ldc_cookie sc_peer_dring_cookie; 198 struct ldc_cookie sc_peer_dring_cookie;
199 int sc_peer_dring_nentries; 199 int sc_peer_dring_nentries;
200 200
201 struct pool sc_pool; 201 struct pool sc_pool;
202 202
203 struct ethercom sc_ethercom; 203 struct ethercom sc_ethercom;
204 struct ifmedia sc_media; 204 struct ifmedia sc_media;
205 u_int8_t sc_macaddr[ETHER_ADDR_LEN]; 205 u_int8_t sc_macaddr[ETHER_ADDR_LEN];
206}; 206};
207 207
208int vnet_match (device_t, cfdata_t, void *); 208int vnet_match (device_t, cfdata_t, void *);
209void vnet_attach (device_t, device_t, void *); 209void vnet_attach (device_t, device_t, void *);
210 210
211CFATTACH_DECL_NEW(vnet, sizeof(struct vnet_softc), 211CFATTACH_DECL_NEW(vnet, sizeof(struct vnet_softc),
212 vnet_match, vnet_attach, NULL, NULL); 212 vnet_match, vnet_attach, NULL, NULL);
213 213
214int vnet_tx_intr(void *); 214int vnet_tx_intr(void *);
215int vnet_rx_intr(void *); 215int vnet_rx_intr(void *);
216void vnet_handshake(void *); 216void vnet_handshake(void *);
217 217
218void vio_rx_data(struct ldc_conn *, struct ldc_pkt *); 218void vio_rx_data(struct ldc_conn *, struct ldc_pkt *);
219void vnet_rx_vio_ctrl(struct vnet_softc *, struct vio_msg *); 219void vnet_rx_vio_ctrl(struct vnet_softc *, struct vio_msg *);
220void vnet_rx_vio_ver_info(struct vnet_softc *, struct vio_msg_tag *); 220void vnet_rx_vio_ver_info(struct vnet_softc *, struct vio_msg_tag *);
221void vnet_rx_vio_attr_info(struct vnet_softc *, struct vio_msg_tag *); 221void vnet_rx_vio_attr_info(struct vnet_softc *, struct vio_msg_tag *);
222void vnet_rx_vio_dring_reg(struct vnet_softc *, struct vio_msg_tag *); 222void vnet_rx_vio_dring_reg(struct vnet_softc *, struct vio_msg_tag *);
223void vnet_rx_vio_rdx(struct vnet_softc *sc, struct vio_msg_tag *); 223void vnet_rx_vio_rdx(struct vnet_softc *sc, struct vio_msg_tag *);
 224void vnet_rx_vio_mcast_info(struct vnet_softc *sc, struct vio_msg_tag *);
224void vnet_rx_vio_data(struct vnet_softc *sc, struct vio_msg *); 225void vnet_rx_vio_data(struct vnet_softc *sc, struct vio_msg *);
225void vnet_rx_vio_desc_data(struct vnet_softc *sc, struct vio_msg_tag *); 226void vnet_rx_vio_desc_data(struct vnet_softc *sc, struct vio_msg_tag *);
226void vnet_rx_vio_dring_data(struct vnet_softc *sc, struct vio_msg_tag *); 227void vnet_rx_vio_dring_data(struct vnet_softc *sc, struct vio_msg_tag *);
227 228
228void vnet_ldc_reset(struct ldc_conn *); 229void vnet_ldc_reset(struct ldc_conn *);
229void vnet_ldc_start(struct ldc_conn *); 230void vnet_ldc_start(struct ldc_conn *);
230 231
231void vnet_sendmsg(struct vnet_softc *, void *, size_t); 232void vnet_sendmsg(struct vnet_softc *, void *, size_t);
232void vnet_send_ver_info(struct vnet_softc *, uint16_t, uint16_t); 233void vnet_send_ver_info(struct vnet_softc *, uint16_t, uint16_t);
233void vnet_send_attr_info(struct vnet_softc *); 234void vnet_send_attr_info(struct vnet_softc *);
234void vnet_send_dring_reg(struct vnet_softc *); 235void vnet_send_dring_reg(struct vnet_softc *);
235void vio_send_rdx(struct vnet_softc *); 236void vio_send_rdx(struct vnet_softc *);
236void vnet_send_dring_data(struct vnet_softc *, uint32_t); 237void vnet_send_dring_data(struct vnet_softc *, uint32_t);
237 238
238void vnet_start(struct ifnet *); 239void vnet_start(struct ifnet *);
239void vnet_start_desc(struct ifnet *); 240void vnet_start_desc(struct ifnet *);
240int vnet_ioctl(struct ifnet *, u_long, void *); 241int vnet_ioctl(struct ifnet *, u_long, void *);
241void vnet_watchdog(struct ifnet *); 242void vnet_watchdog(struct ifnet *);
242 243
243int vnet_media_change(struct ifnet *); 244int vnet_media_change(struct ifnet *);
244void vnet_media_status(struct ifnet *, struct ifmediareq *); 245void vnet_media_status(struct ifnet *, struct ifmediareq *);
245 246
246void vnet_link_state(struct vnet_softc *sc); 247void vnet_link_state(struct vnet_softc *sc);
247 248
248void vnet_setmulti(struct vnet_softc *, int); 249void vnet_setmulti(struct vnet_softc *, int);
249 250
250int vnet_init(struct ifnet *); 251int vnet_init(struct ifnet *);
251void vnet_stop(struct ifnet *, int); 252void vnet_stop(struct ifnet *, int);
252 253
253int vnet_match(device_t parent, cfdata_t match, void *aux) 254int vnet_match(device_t parent, cfdata_t match, void *aux)
254{ 255{
255 256
256 struct cbus_attach_args *ca = aux; 257 struct cbus_attach_args *ca = aux;
257  258
258 if (strcmp(ca->ca_name, "network") == 0) 259 if (strcmp(ca->ca_name, "network") == 0)
259 return (1); 260 return (1);
260 261
261 return (0); 262 return (0);
262} 263}
263 264
264void 265void
265vnet_attach(struct device *parent, struct device *self, void *aux) 266vnet_attach(struct device *parent, struct device *self, void *aux)
266{ 267{
267 struct vnet_softc *sc = device_private(self); 268 struct vnet_softc *sc = device_private(self);
268 struct cbus_attach_args *ca = aux; 269 struct cbus_attach_args *ca = aux;
269 struct ldc_conn *lc; 270 struct ldc_conn *lc;
270 struct ifnet *ifp; 271 struct ifnet *ifp;
271 272
272 sc->sc_bustag = ca->ca_bustag; 273 sc->sc_bustag = ca->ca_bustag;
273 sc->sc_dmatag = ca->ca_dmatag; 274 sc->sc_dmatag = ca->ca_dmatag;
274 sc->sc_tx_ino = ca->ca_tx_ino; 275 sc->sc_tx_ino = ca->ca_tx_ino;
275 sc->sc_rx_ino = ca->ca_rx_ino; 276 sc->sc_rx_ino = ca->ca_rx_ino;
276 277
277 printf(": ivec 0x%" PRIx64 ", 0x%" PRIx64, sc->sc_tx_ino, sc->sc_rx_ino); 278 printf(": ivec 0x%" PRIx64 ", 0x%" PRIx64, sc->sc_tx_ino, sc->sc_rx_ino);
278 279
279 /* 280 /*
280 * Un-configure queues before registering interrupt handlers, 281 * Un-configure queues before registering interrupt handlers,
281 * such that we dont get any stale LDC packets or events. 282 * such that we dont get any stale LDC packets or events.
282 */ 283 */
283 hv_ldc_tx_qconf(ca->ca_id, 0, 0); 284 hv_ldc_tx_qconf(ca->ca_id, 0, 0);
284 hv_ldc_rx_qconf(ca->ca_id, 0, 0); 285 hv_ldc_rx_qconf(ca->ca_id, 0, 0);
285 286
286#if 0 287#if 0
287FIXME openbsd  288FIXME openbsd
288 sc->sc_tx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_tx_ino, 289 sc->sc_tx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_tx_ino,
289 IPL_NET, BUS_INTR_ESTABLISH_MPSAFE, vnet_tx_intr, 290 IPL_NET, BUS_INTR_ESTABLISH_MPSAFE, vnet_tx_intr,
290 sc, sc->sc_dv.dv_xname); 291 sc, sc->sc_dv.dv_xname);
291 sc->sc_rx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_rx_ino, 292 sc->sc_rx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_rx_ino,
292 IPL_NET, BUS_INTR_ESTABLISH_MPSAFE, vnet_rx_intr, 293 IPL_NET, BUS_INTR_ESTABLISH_MPSAFE, vnet_rx_intr,
293 sc, sc->sc_dv.dv_xname); 294 sc, sc->sc_dv.dv_xname);
294 if (sc->sc_tx_ih == NULL || sc->sc_rx_ih == NULL) { 295 if (sc->sc_tx_ih == NULL || sc->sc_rx_ih == NULL) {
295 printf(", can't establish interrupt\n"); 296 printf(", can't establish interrupt\n");
296 return; 297 return;
297 } 298 }
298#else 299#else
299 sc->sc_tx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_tx_ino, 300 sc->sc_tx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_tx_ino,
300 IPL_NET, vnet_tx_intr, sc); 301 IPL_NET, vnet_tx_intr, sc);
301 sc->sc_rx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_rx_ino, 302 sc->sc_rx_ih = bus_intr_establish(ca->ca_bustag, sc->sc_rx_ino,
302 IPL_NET, vnet_rx_intr, sc); 303 IPL_NET, vnet_rx_intr, sc);
303 if (sc->sc_tx_ih == NULL || sc->sc_rx_ih == NULL) { 304 if (sc->sc_tx_ih == NULL || sc->sc_rx_ih == NULL) {
304 printf(", can't establish interrupts\n"); 305 printf(", can't establish interrupts\n");
305 return; 306 return;
306 } 307 }
307#endif  308#endif
308 309
309 lc = &sc->sc_lc; 310 lc = &sc->sc_lc;
310 lc->lc_id = ca->ca_id; 311 lc->lc_id = ca->ca_id;
311 lc->lc_sc = sc; 312 lc->lc_sc = sc;
312 lc->lc_reset = vnet_ldc_reset; 313 lc->lc_reset = vnet_ldc_reset;
313 lc->lc_start = vnet_ldc_start; 314 lc->lc_start = vnet_ldc_start;
314 lc->lc_rx_data = vio_rx_data; 315 lc->lc_rx_data = vio_rx_data;
315 316
316#if 0 317#if 0
317FIXME openbsd  318FIXME openbsd
318 timeout_set(&sc->sc_handshake_to, vnet_handshake, sc); 319 timeout_set(&sc->sc_handshake_to, vnet_handshake, sc);
319#else 320#else
320 callout_init(&sc->sc_handshake_co, 0); 321 callout_init(&sc->sc_handshake_co, 0);
321/* netbsd callout do silmilar function...*/ 322/* netbsd callout do silmilar function...*/
322#endif  323#endif
323 sc->sc_peer_state = VIO_DP_STOPPED; 324 sc->sc_peer_state = VIO_DP_STOPPED;
324 325
325#if OPENBSD_BUSDMA 326#if OPENBSD_BUSDMA
326 lc->lc_txq = ldc_queue_alloc(sc->sc_dmatag, VNET_TX_ENTRIES); 327 lc->lc_txq = ldc_queue_alloc(sc->sc_dmatag, VNET_TX_ENTRIES);
327 if (lc->lc_txq == NULL) { 328 if (lc->lc_txq == NULL) {
328 printf(", can't allocate tx queue\n"); 329 printf(", can't allocate tx queue\n");
329 return; 330 return;
330 } 331 }
331 332
332 lc->lc_rxq = ldc_queue_alloc(sc->sc_dmatag, VNET_RX_ENTRIES); 333 lc->lc_rxq = ldc_queue_alloc(sc->sc_dmatag, VNET_RX_ENTRIES);
333 if (lc->lc_rxq == NULL) { 334 if (lc->lc_rxq == NULL) {
334 printf(", can't allocate rx queue\n"); 335 printf(", can't allocate rx queue\n");
335 goto free_txqueue; 336 goto free_txqueue;
336 } 337 }
337#else  338#else
338 lc->lc_txq = ldc_queue_alloc(VNET_TX_ENTRIES); 339 lc->lc_txq = ldc_queue_alloc(VNET_TX_ENTRIES);
339 if (lc->lc_txq == NULL) { 340 if (lc->lc_txq == NULL) {
340 printf(", can't allocate tx queue\n"); 341 printf(", can't allocate tx queue\n");
341 return; 342 return;
342 } 343 }
343 344
344 lc->lc_rxq = ldc_queue_alloc(VNET_RX_ENTRIES); 345 lc->lc_rxq = ldc_queue_alloc(VNET_RX_ENTRIES);
345 if (lc->lc_rxq == NULL) { 346 if (lc->lc_rxq == NULL) {
346 printf(", can't allocate rx queue\n"); 347 printf(", can't allocate rx queue\n");
347 goto free_txqueue; 348 goto free_txqueue;
348 } 349 }
349#endif 350#endif
350  351
351 if (OF_getprop(ca->ca_node, "local-mac-address", 352 if (OF_getprop(ca->ca_node, "local-mac-address",
352 sc->sc_macaddr, ETHER_ADDR_LEN) > 0) { 353 sc->sc_macaddr, ETHER_ADDR_LEN) > 0) {
353 printf(", address %s", ether_sprintf(sc->sc_macaddr)); 354 printf(", address %s", ether_sprintf(sc->sc_macaddr));
354 } else { 355 } else {
355 printf(", cannot retrieve local mac address\n"); 356 printf(", cannot retrieve local mac address\n");
356 return; 357 return;
357 } 358 }
358 359
359 /* 360 /*
360 * Each interface gets its own pool. 361 * Each interface gets its own pool.
361 */ 362 */
362#if 0 363#if 0
363FIXME openbsd  364FIXME openbsd
364 pool_init(&sc->sc_pool, 2048, 0, IPL_NET, 0, sc->sc_dv.dv_xname, NULL); 365 pool_init(&sc->sc_pool, 2048, 0, IPL_NET, 0, sc->sc_dv.dv_xname, NULL);
365#else 366#else
366 pool_init(&sc->sc_pool, 2048, 0, 0, 0, sc->sc_dv.dv_xname, NULL, IPL_NET); 367 pool_init(&sc->sc_pool, 2048, 0, 0, 0, sc->sc_dv.dv_xname, NULL, IPL_NET);
367#endif 368#endif
368  369
369 ifp = &sc->sc_ethercom.ec_if; 370 ifp = &sc->sc_ethercom.ec_if;
370 ifp->if_softc = sc; 371 ifp->if_softc = sc;
371 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 372 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
372#if 0  373#if 0
373 ifp->if_link_state = LINK_STATE_DOWN; 374 ifp->if_link_state = LINK_STATE_DOWN;
374#endif  375#endif
375 ifp->if_init = vnet_init; 376 ifp->if_init = vnet_init;
376 ifp->if_ioctl = vnet_ioctl; 377 ifp->if_ioctl = vnet_ioctl;
377 ifp->if_start = vnet_start; 378 ifp->if_start = vnet_start;
378 ifp->if_stop = vnet_stop; 379 ifp->if_stop = vnet_stop;
379 ifp->if_watchdog = vnet_watchdog; 380 ifp->if_watchdog = vnet_watchdog;
380 strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ); 381 strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
381#if 0 382#if 0
382FIXME openbsd  383FIXME openbsd
383 ifq_set_maxlen(&ifp->if_snd, 31); /* XXX */ 384 ifq_set_maxlen(&ifp->if_snd, 31); /* XXX */
384#else  385#else
385 IFQ_SET_MAXLEN(&ifp->if_snd, 31); /* XXX */ 386 IFQ_SET_MAXLEN(&ifp->if_snd, 31); /* XXX */
386#endif  387#endif
387 388
388 ifmedia_init(&sc->sc_media, 0, vnet_media_change, vnet_media_status); 389 ifmedia_init(&sc->sc_media, 0, vnet_media_change, vnet_media_status);
389 ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL); 390 ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
390 ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO); 391 ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
391 392
392#if 0  393#if 0
393 int error = if_initialize(ifp); 394 int error = if_initialize(ifp);
394 if (error != 0) { 395 if (error != 0) {
395 printf(", if_initialize() failed\n"); 396 printf(", if_initialize() failed\n");
396 return; 397 return;
397 } 398 }
398 ether_ifattach(ifp, sc->sc_macaddr); 399 ether_ifattach(ifp, sc->sc_macaddr);
399 if_register(ifp); 400 if_register(ifp);
400#else 401#else
401 if_attach(ifp); 402 if_attach(ifp);
402 ether_ifattach(ifp, sc->sc_macaddr); 403 ether_ifattach(ifp, sc->sc_macaddr);
403#endif  404#endif
404 printf("\n"); 405 printf("\n");
405 return; 406 return;
406free_txqueue: 407free_txqueue:
407#if OPENBSD_BUSDMA 408#if OPENBSD_BUSDMA
408 ldc_queue_free(sc->sc_dmatag, lc->lc_txq); 409 ldc_queue_free(sc->sc_dmatag, lc->lc_txq);
409#else  410#else
410 ldc_queue_free(lc->lc_txq); 411 ldc_queue_free(lc->lc_txq);
411#endif  412#endif
412} 413}
413 414
414int 415int
415vnet_tx_intr(void *arg) 416vnet_tx_intr(void *arg)
416{ 417{
417 DPRINTF(("%s: entry\n", __func__)); 418 DPRINTF(("%s: entry\n", __func__));
418 419
419 struct vnet_softc *sc = arg; 420 struct vnet_softc *sc = arg;
420 struct ldc_conn *lc = &sc->sc_lc; 421 struct ldc_conn *lc = &sc->sc_lc;
421 uint64_t tx_head, tx_tail, tx_state; 422 uint64_t tx_head, tx_tail, tx_state;
422 423
423 hv_ldc_tx_get_state(lc->lc_id, &tx_head, &tx_tail, &tx_state); 424 hv_ldc_tx_get_state(lc->lc_id, &tx_head, &tx_tail, &tx_state);
424 if (tx_state != lc->lc_tx_state) { 425 if (tx_state != lc->lc_tx_state) {
425 switch (tx_state) { 426 switch (tx_state) {
426 case LDC_CHANNEL_DOWN: 427 case LDC_CHANNEL_DOWN:
427 DPRINTF(("%s: Tx link down\n", __func__)); 428 DPRINTF(("%s: Tx link down\n", __func__));
428 break; 429 break;
429 case LDC_CHANNEL_UP: 430 case LDC_CHANNEL_UP:
430 DPRINTF(("%s: Tx link up\n", __func__)); 431 DPRINTF(("%s: Tx link up\n", __func__));
431 break; 432 break;
432 case LDC_CHANNEL_RESET: 433 case LDC_CHANNEL_RESET:
433 DPRINTF(("%s: Tx link reset\n", __func__)); 434 DPRINTF(("%s: Tx link reset\n", __func__));
434 break; 435 break;
435 } 436 }
436 lc->lc_tx_state = tx_state; 437 lc->lc_tx_state = tx_state;
437 } 438 }
438 439
439 DPRINTF(("%s: exit\n", __func__)); 440 DPRINTF(("%s: exit\n", __func__));
440 return (1); 441 return (1);
441} 442}
442  443
443int 444int
444vnet_rx_intr(void *arg) 445vnet_rx_intr(void *arg)
445{ 446{
446#if 0  447#if 0
447 DPRINTF(("%s: entry\n", __func__)); 448 DPRINTF(("%s: entry\n", __func__));
448#endif  449#endif
449 450
450 struct vnet_softc *sc = arg; 451 struct vnet_softc *sc = arg;
451 struct ldc_conn *lc = &sc->sc_lc; 452 struct ldc_conn *lc = &sc->sc_lc;
452 uint64_t rx_head, rx_tail, rx_state; 453 uint64_t rx_head, rx_tail, rx_state;
453 struct ldc_pkt *lp; 454 struct ldc_pkt *lp;
454 int err; 455 int err;
455 456
456 err = hv_ldc_rx_get_state(lc->lc_id, &rx_head, &rx_tail, &rx_state); 457 err = hv_ldc_rx_get_state(lc->lc_id, &rx_head, &rx_tail, &rx_state);
457 if (err == H_EINVAL) { 458 if (err == H_EINVAL) {
458 printf("hv_ldc_rx_get_state failed\n"); 459 printf("hv_ldc_rx_get_state failed\n");
459 return (0); 460 return (0);
460 } 461 }
461 if (err != H_EOK) { 462 if (err != H_EOK) {
462 printf("hv_ldc_rx_get_state %d\n", err); 463 printf("hv_ldc_rx_get_state %d\n", err);
463 return (0); 464 return (0);
464 } 465 }
465#if 0  466#if 0
466 DPRINTF(("%s: rx_state %" PRId64 " head %" PRId64 " tail %" PRId64 "\n", 467 DPRINTF(("%s: rx_state %" PRId64 " head %" PRId64 " tail %" PRId64 "\n",
467 __func__, rx_state, rx_head, rx_tail)); 468 __func__, rx_state, rx_head, rx_tail));
468#endif  469#endif
469 470
470 if (rx_state != lc->lc_rx_state) { 471 if (rx_state != lc->lc_rx_state) {
471#if 0  472#if 0
472 DPRINTF(("%s: rx_state %" PRId64 " != lc__rx_state %" PRId64 "\n", 473 DPRINTF(("%s: rx_state %" PRId64 " != lc__rx_state %" PRId64 "\n",
473 __func__, rx_state, lc->lc_rx_state)); 474 __func__, rx_state, lc->lc_rx_state));
474#endif  475#endif
475 switch (rx_state) { 476 switch (rx_state) {
476 case LDC_CHANNEL_DOWN: 477 case LDC_CHANNEL_DOWN:
477 lc->lc_tx_seqid = 0; 478 lc->lc_tx_seqid = 0;
478 lc->lc_state = 0; 479 lc->lc_state = 0;
479 lc->lc_reset(lc); 480 lc->lc_reset(lc);
480 if (rx_head == rx_tail) 481 if (rx_head == rx_tail)
481 break; 482 break;
482 /* Discard and ack pending I/O. */ 483 /* Discard and ack pending I/O. */
483 DPRINTF(("setting rx qhead to %" PRId64 "\n", rx_tail)); 484 DPRINTF(("setting rx qhead to %" PRId64 "\n", rx_tail));
484 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_tail); 485 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_tail);
485 if (err == H_EOK) 486 if (err == H_EOK)
486 break; 487 break;
487 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err); 488 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err);
488 break; 489 break;
489 case LDC_CHANNEL_UP: 490 case LDC_CHANNEL_UP:
490#if 0  491#if 0
491 DPRINTF(("%s: Rx link up\n", __func__)); 492 DPRINTF(("%s: Rx link up\n", __func__));
492#endif  493#endif
493#if 0 494#if 0
494FIXME openbsd  495FIXME openbsd
495 timeout_add_msec(&sc->sc_handshake_to, 500); 496 timeout_add_msec(&sc->sc_handshake_to, 500);
496#else  497#else
497 callout_reset(&sc->sc_handshake_co, hz / 2, vnet_handshake, sc); 498 callout_reset(&sc->sc_handshake_co, hz / 2, vnet_handshake, sc);
498#endif  499#endif
499 break; 500 break;
500 case LDC_CHANNEL_RESET: 501 case LDC_CHANNEL_RESET:
501 DPRINTF(("%s: Rx link reset\n", __func__)); 502 DPRINTF(("%s: Rx link reset\n", __func__));
502 lc->lc_tx_seqid = 0; 503 lc->lc_tx_seqid = 0;
503 lc->lc_state = 0; 504 lc->lc_state = 0;
504 lc->lc_reset(lc); 505 lc->lc_reset(lc);
505#if 0 506#if 0
506FIXME openbsd  507FIXME openbsd
507 timeout_add_msec(&sc->sc_handshake_to, 500); 508 timeout_add_msec(&sc->sc_handshake_to, 500);
508#else  509#else
509 callout_reset(&sc->sc_handshake_co, hz / 2, vnet_handshake, sc); 510 callout_reset(&sc->sc_handshake_co, hz / 2, vnet_handshake, sc);
510#endif  511#endif
511 if (rx_head == rx_tail) { 512 if (rx_head == rx_tail) {
512#if 0  513#if 0
513 DPRINTF(("%s: rx_head == rx_head\n", __func__)); 514 DPRINTF(("%s: rx_head == rx_head\n", __func__));
514#endif  515#endif
515 break; 516 break;
516 } 517 }
517 /* Discard and ack pending I/O. */ 518 /* Discard and ack pending I/O. */
518 DPRINTF(("setting rx qhead to %" PRId64 "\n", rx_tail)); 519 DPRINTF(("setting rx qhead to %" PRId64 "\n", rx_tail));
519 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_tail); 520 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_tail);
520 if (err == H_EOK) 521 if (err == H_EOK)
521 break; 522 break;
522 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err); 523 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err);
523 break; 524 break;
524 default:  525 default:
525 DPRINTF(("%s: unhandled rx_state %" PRIx64 "\n", __func__, rx_state)); 526 DPRINTF(("%s: unhandled rx_state %" PRIx64 "\n", __func__, rx_state));
526 break; 527 break;
527 } 528 }
528 lc->lc_rx_state = rx_state; 529 lc->lc_rx_state = rx_state;
529#if 0  530#if 0
530 DPRINTF(("%s: setting rx_state %" PRId64 " = lc__rx_state %" PRId64 "\n", 531 DPRINTF(("%s: setting rx_state %" PRId64 " = lc__rx_state %" PRId64 "\n",
531 __func__, rx_state, lc->lc_rx_state)); 532 __func__, rx_state, lc->lc_rx_state));
532#endif  533#endif
533 return (1); 534 return (1);
534 } else { 535 } else {
535#if 0  536#if 0
536 DPRINTF(("%s: rx_state %" PRId64 " == lc__rx_state %" PRId64 "\n", 537 DPRINTF(("%s: rx_state %" PRId64 " == lc__rx_state %" PRId64 "\n",
537 __func__, rx_state, lc->lc_rx_state)); 538 __func__, rx_state, lc->lc_rx_state));
538#endif  539#endif
539 } 540 }
540 541
541 if (rx_head == rx_tail) 542 if (rx_head == rx_tail)
542 { 543 {
543 DPRINTF(("%s: head eq tail\n", __func__)); 544 DPRINTF(("%s: head eq tail\n", __func__));
544 return (0); 545 return (0);
545 } 546 }
546 lp = (struct ldc_pkt *)(uintptr_t)(lc->lc_rxq->lq_va + rx_head); 547 lp = (struct ldc_pkt *)(uintptr_t)(lc->lc_rxq->lq_va + rx_head);
547#if 0  548#if 0
548 DPRINTF(("%s: lp->type %" PRId8 "\n", __func__, lp->type)); 549 DPRINTF(("%s: lp->type %" PRId8 "\n", __func__, lp->type));
549 DPRINTF(("%s: lp->stype %" PRId8 "\n", __func__, lp->stype)); 550 DPRINTF(("%s: lp->stype %" PRId8 "\n", __func__, lp->stype));
550 DPRINTF(("%s: lp->ctrl %" PRId8 "\n", __func__, lp->ctrl)); 551 DPRINTF(("%s: lp->ctrl %" PRId8 "\n", __func__, lp->ctrl));
551 DPRINTF(("%s: lp->env %" PRId8 "\n", __func__, lp->env)); 552 DPRINTF(("%s: lp->env %" PRId8 "\n", __func__, lp->env));
552 DPRINTF(("%s: lp->seqid %" PRId32 "\n", __func__, lp->seqid)); 553 DPRINTF(("%s: lp->seqid %" PRId32 "\n", __func__, lp->seqid));
553 DPRINTF(("%s: lp->major %" PRId16 "\n", __func__, lp->major)); 554 DPRINTF(("%s: lp->major %" PRId16 "\n", __func__, lp->major));
554 DPRINTF(("%s: lp->minor %" PRId16 "\n", __func__, lp->minor)); 555 DPRINTF(("%s: lp->minor %" PRId16 "\n", __func__, lp->minor));
555#endif 556#endif
556 switch (lp->type) { 557 switch (lp->type) {
557 case LDC_CTRL: 558 case LDC_CTRL:
558#if 0  559#if 0
559 DPRINTF(("%s: LDC_CTRL\n", __func__)); 560 DPRINTF(("%s: LDC_CTRL\n", __func__));
560#endif  561#endif
561 ldc_rx_ctrl(lc, lp); 562 ldc_rx_ctrl(lc, lp);
562 break; 563 break;
563 564
564 case LDC_DATA: 565 case LDC_DATA:
565#if 0  566#if 0
566 DPRINTF(("%s: LDC_DATA\n", __func__)); 567 DPRINTF(("%s: LDC_DATA\n", __func__));
567#endif  568#endif
568 ldc_rx_data(lc, lp); 569 ldc_rx_data(lc, lp);
569 break; 570 break;
570 571
571 default: 572 default:
572 DPRINTF(("%s: unhandled type %0x02/%0x02/%0x02\n", 573 DPRINTF(("%s: unhandled type %0x02/%0x02/%0x02\n",
573 __func__, lp->type, lp->stype, lp->ctrl)); 574 __func__, lp->type, lp->stype, lp->ctrl));
574 Debugger(); 575 Debugger();
575 ldc_reset(lc); 576 ldc_reset(lc);
576 break; 577 break;
577 } 578 }
578 579
579 if (lc->lc_state == 0) 580 if (lc->lc_state == 0)
580 return (1); 581 return (1);
581 582
582 rx_head += sizeof(*lp); 583 rx_head += sizeof(*lp);
583 rx_head &= ((lc->lc_rxq->lq_nentries * sizeof(*lp)) - 1); 584 rx_head &= ((lc->lc_rxq->lq_nentries * sizeof(*lp)) - 1);
584 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_head); 585 err = hv_ldc_rx_set_qhead(lc->lc_id, rx_head);
585 if (err != H_EOK) 586 if (err != H_EOK)
586 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err); 587 printf("%s: hv_ldc_rx_set_qhead %d\n", __func__, err);
587#if 0 588#if 0
588 DPRINTF(("%s: exit\n", __func__)); 589 DPRINTF(("%s: exit\n", __func__));
589#endif  590#endif
590 return (1); 591 return (1);
591} 592}
592  593
593void 594void
594vnet_handshake(void *arg) 595vnet_handshake(void *arg)
595{ 596{
596 DPRINTF(("%s: entry\n", __func__)); 597 DPRINTF(("%s: entry\n", __func__));
597  598
598 struct vnet_softc *sc = arg; 599 struct vnet_softc *sc = arg;
599 600
600 ldc_send_vers(&sc->sc_lc); 601 ldc_send_vers(&sc->sc_lc);
601} 602}
602  603
603void 604void
604vio_rx_data(struct ldc_conn *lc, struct ldc_pkt *lp) 605vio_rx_data(struct ldc_conn *lc, struct ldc_pkt *lp)
605{ 606{
606#if 0  607#if 0
607 DPRINTF(("%s: entry\n", __func__)); 608 DPRINTF(("%s: entry\n", __func__));
608#endif  609#endif
609  610
610 struct vio_msg *vm = (struct vio_msg *)lp; 611 struct vio_msg *vm = (struct vio_msg *)lp;
611 612
612 switch (vm->type) { 613 switch (vm->type) {
613 case VIO_TYPE_CTRL: 614 case VIO_TYPE_CTRL:
614 if ((lp->env & LDC_FRAG_START) == 0 && 615 if ((lp->env & LDC_FRAG_START) == 0 &&
615 (lp->env & LDC_FRAG_STOP) == 0) { 616 (lp->env & LDC_FRAG_STOP) == 0) {
616 DPRINTF(("%s: FRAG_START==0 and FRAG_STOP==0\n", __func__)); 617 DPRINTF(("%s: FRAG_START==0 and FRAG_STOP==0\n", __func__));
617 return; 618 return;
618 } 619 }
619 vnet_rx_vio_ctrl(lc->lc_sc, vm); 620 vnet_rx_vio_ctrl(lc->lc_sc, vm);
620 break; 621 break;
621 622
622 case VIO_TYPE_DATA: 623 case VIO_TYPE_DATA:
623 if((lp->env & LDC_FRAG_START) == 0) { 624 if((lp->env & LDC_FRAG_START) == 0) {
624 DPRINTF(("%s: FRAG_START==0\n", __func__)); 625 DPRINTF(("%s: FRAG_START==0\n", __func__));
625 return; 626 return;
626 } 627 }
627 vnet_rx_vio_data(lc->lc_sc, vm); 628 vnet_rx_vio_data(lc->lc_sc, vm);
628 break; 629 break;
629 630
630 default: 631 default:
631 DPRINTF(("Unhandled packet type 0x%02x\n", vm->type)); 632 DPRINTF(("Unhandled packet type 0x%02x\n", vm->type));
632 ldc_reset(lc); 633 ldc_reset(lc);
633 break; 634 break;
634 } 635 }
635} 636}
636 637
637void 638void
638vnet_rx_vio_ctrl(struct vnet_softc *sc, struct vio_msg *vm) 639vnet_rx_vio_ctrl(struct vnet_softc *sc, struct vio_msg *vm)
639{ 640{
640#if 0 641#if 0
641 DPRINTF(("%s: entry\n", __func__)); 642 DPRINTF(("%s: entry\n", __func__));
642#endif  643#endif
643 struct vio_msg_tag *tag = (struct vio_msg_tag *)&vm->type; 644 struct vio_msg_tag *tag = (struct vio_msg_tag *)&vm->type;
644 645
645 switch (tag->stype_env) { 646 switch (tag->stype_env) {
646 case VIO_VER_INFO: 647 case VIO_VER_INFO:
647 vnet_rx_vio_ver_info(sc, tag); 648 vnet_rx_vio_ver_info(sc, tag);
648 break; 649 break;
649 case VIO_ATTR_INFO: 650 case VIO_ATTR_INFO:
650 vnet_rx_vio_attr_info(sc, tag); 651 vnet_rx_vio_attr_info(sc, tag);
651 break; 652 break;
652 case VIO_DRING_REG: 653 case VIO_DRING_REG:
653 vnet_rx_vio_dring_reg(sc, tag); 654 vnet_rx_vio_dring_reg(sc, tag);
654 break; 655 break;
655 case VIO_RDX: 656 case VIO_RDX:
656 vnet_rx_vio_rdx(sc, tag); 657 vnet_rx_vio_rdx(sc, tag);
657 break; 658 break;
 659 case VNET_MCAST_INFO:
 660 vnet_rx_vio_mcast_info(sc, tag);
 661 break;
658 default: 662 default:
659 printf("%s: CTRL/0x%02x/0x%04x FIXME\n", 663 printf("%s: CTRL/0x%02x/0x%04x FIXME\n",
660 __func__, tag->stype, tag->stype_env); 664 __func__, tag->stype, tag->stype_env);
 665#if 0
 666 Debugger();
 667#endif
661 break; 668 break;
662 } 669 }
663} 670}
664 671
665void 672void
666vnet_rx_vio_ver_info(struct vnet_softc *sc, struct vio_msg_tag *tag) 673vnet_rx_vio_ver_info(struct vnet_softc *sc, struct vio_msg_tag *tag)
667{ 674{
668#if 0 675#if 0
669 DPRINTF(("%s: entry\n", __func__)); 676 DPRINTF(("%s: entry\n", __func__));
670#endif  677#endif
671 struct vio_ver_info *vi = (struct vio_ver_info *)tag; 678 struct vio_ver_info *vi = (struct vio_ver_info *)tag;
672 679
673 switch (vi->tag.stype) { 680 switch (vi->tag.stype) {
674 case VIO_SUBTYPE_INFO: 681 case VIO_SUBTYPE_INFO:
675#if 0  682#if 0
676 DPRINTF(("CTRL/INFO/VER_INFO\n")); 683 DPRINTF(("CTRL/INFO/VER_INFO\n"));
677#endif  684#endif
678 685
679 /* Make sure we're talking to a virtual network device. */ 686 /* Make sure we're talking to a virtual network device. */
680 if (vi->dev_class != VDEV_NETWORK && 687 if (vi->dev_class != VDEV_NETWORK &&
681 vi->dev_class != VDEV_NETWORK_SWITCH) { 688 vi->dev_class != VDEV_NETWORK_SWITCH) {
682 DPRINTF(("Class is not network or network switch\n")); 689 DPRINTF(("Class is not network or network switch\n"));
683 /* Huh, we're not talking to a network device? */ 690 /* Huh, we're not talking to a network device? */
684 printf("Not a network device\n"); 691 printf("Not a network device\n");
685 vi->tag.stype = VIO_SUBTYPE_NACK; 692 vi->tag.stype = VIO_SUBTYPE_NACK;
686 vnet_sendmsg(sc, vi, sizeof(*vi)); 693 vnet_sendmsg(sc, vi, sizeof(*vi));
687 return; 694 return;
688 } 695 }
689 696
690 if (vi->major != VNET_MAJOR) { 697 if (vi->major != VNET_MAJOR) {
691 DPRINTF(("Major mismatch %" PRId8 " vs %" PRId8 "\n", 698 DPRINTF(("Major mismatch %" PRId8 " vs %" PRId8 "\n",
692 vi->major, VNET_MAJOR)); 699 vi->major, VNET_MAJOR));
693 vi->tag.stype = VIO_SUBTYPE_NACK; 700 vi->tag.stype = VIO_SUBTYPE_NACK;
694 vi->major = VNET_MAJOR; 701 vi->major = VNET_MAJOR;
695 vi->minor = VNET_MINOR; 702 vi->minor = VNET_MINOR;
696 vnet_sendmsg(sc, vi, sizeof(*vi)); 703 vnet_sendmsg(sc, vi, sizeof(*vi));
697 return; 704 return;
698 } 705 }
699 706
700 vi->tag.stype = VIO_SUBTYPE_ACK; 707 vi->tag.stype = VIO_SUBTYPE_ACK;
701 vi->tag.sid = sc->sc_local_sid; 708 vi->tag.sid = sc->sc_local_sid;
702 vi->minor = VNET_MINOR; 709 vi->minor = VNET_MINOR;
703 vnet_sendmsg(sc, vi, sizeof(*vi)); 710 vnet_sendmsg(sc, vi, sizeof(*vi));
704 sc->sc_vio_state |= VIO_RCV_VER_INFO; 711 sc->sc_vio_state |= VIO_RCV_VER_INFO;
705 break; 712 break;
706 713
707 case VIO_SUBTYPE_ACK: 714 case VIO_SUBTYPE_ACK:
708#if 0  715#if 0
709 DPRINTF(("CTRL/ACK/VER_INFO\n")); 716 DPRINTF(("CTRL/ACK/VER_INFO\n"));
710#endif  717#endif
711 if (!ISSET(sc->sc_vio_state, VIO_SND_VER_INFO)) { 718 if (!ISSET(sc->sc_vio_state, VIO_SND_VER_INFO)) {
712 ldc_reset(&sc->sc_lc); 719 ldc_reset(&sc->sc_lc);
713 break; 720 break;
714 } 721 }
715 sc->sc_vio_state |= VIO_ACK_VER_INFO; 722 sc->sc_vio_state |= VIO_ACK_VER_INFO;
716 break; 723 break;
717 724
718 default: 725 default:
719 DPRINTF(("CTRL/0x%02x/VER_INFO\n", vi->tag.stype)); 726 DPRINTF(("CTRL/0x%02x/VER_INFO\n", vi->tag.stype));
720 break; 727 break;
721 } 728 }
722 729
723 if (ISSET(sc->sc_vio_state, VIO_RCV_VER_INFO) && 730 if (ISSET(sc->sc_vio_state, VIO_RCV_VER_INFO) &&
724 ISSET(sc->sc_vio_state, VIO_ACK_VER_INFO)) 731 ISSET(sc->sc_vio_state, VIO_ACK_VER_INFO))
725 vnet_send_attr_info(sc); 732 vnet_send_attr_info(sc);
726} 733}
727 734
728void 735void
729vnet_rx_vio_attr_info(struct vnet_softc *sc, struct vio_msg_tag *tag) 736vnet_rx_vio_attr_info(struct vnet_softc *sc, struct vio_msg_tag *tag)
730{ 737{
731#if 0 738#if 0
732 DPRINTF(("%s: entry\n", __func__)); 739 DPRINTF(("%s: entry\n", __func__));
733#endif  740#endif
734 struct vnet_attr_info *ai = (struct vnet_attr_info *)tag; 741 struct vnet_attr_info *ai = (struct vnet_attr_info *)tag;
735 742
736 switch (ai->tag.stype) { 743 switch (ai->tag.stype) {
737 case VIO_SUBTYPE_INFO: 744 case VIO_SUBTYPE_INFO:
738#if 0  745#if 0
739 DPRINTF(("CTRL/INFO/ATTR_INFO\n")); 746 DPRINTF(("CTRL/INFO/ATTR_INFO\n"));
740#endif  747#endif
741 sc->sc_xfer_mode = ai->xfer_mode; 748 sc->sc_xfer_mode = ai->xfer_mode;
 749#if 0
742 DPRINTF(("sc_xfer_mode %d\n", sc->sc_xfer_mode)); 750 DPRINTF(("sc_xfer_mode %d\n", sc->sc_xfer_mode));
 751#endif
743 752
744 ai->tag.stype = VIO_SUBTYPE_ACK; 753 ai->tag.stype = VIO_SUBTYPE_ACK;
745 ai->tag.sid = sc->sc_local_sid; 754 ai->tag.sid = sc->sc_local_sid;
746 vnet_sendmsg(sc, ai, sizeof(*ai)); 755 vnet_sendmsg(sc, ai, sizeof(*ai));
747 sc->sc_vio_state |= VIO_RCV_ATTR_INFO; 756 sc->sc_vio_state |= VIO_RCV_ATTR_INFO;
748 break; 757 break;
749 758
750 case VIO_SUBTYPE_ACK: 759 case VIO_SUBTYPE_ACK:
751#if 0  760#if 0
752 DPRINTF(("CTRL/ACK/ATTR_INFO\n")); 761 DPRINTF(("CTRL/ACK/ATTR_INFO\n"));
753#endif  762#endif
754 if (!ISSET(sc->sc_vio_state, VIO_SND_ATTR_INFO)) { 763 if (!ISSET(sc->sc_vio_state, VIO_SND_ATTR_INFO)) {
755 ldc_reset(&sc->sc_lc); 764 ldc_reset(&sc->sc_lc);
756 break; 765 break;
757 } 766 }
758 sc->sc_vio_state |= VIO_ACK_ATTR_INFO; 767 sc->sc_vio_state |= VIO_ACK_ATTR_INFO;
759 break; 768 break;
760 769
761 default: 770 default:
762 DPRINTF(("CTRL/0x%02x/ATTR_INFO\n", ai->tag.stype)); 771 DPRINTF(("CTRL/0x%02x/ATTR_INFO\n", ai->tag.stype));
763 break; 772 break;
764 } 773 }
765 774
766 if (ISSET(sc->sc_vio_state, VIO_RCV_ATTR_INFO) && 775 if (ISSET(sc->sc_vio_state, VIO_RCV_ATTR_INFO) &&
767 ISSET(sc->sc_vio_state, VIO_ACK_ATTR_INFO)) { 776 ISSET(sc->sc_vio_state, VIO_ACK_ATTR_INFO)) {
768 if (sc->sc_xfer_mode == VIO_DRING_MODE) 777 if (sc->sc_xfer_mode == VIO_DRING_MODE)
769 vnet_send_dring_reg(sc); 778 vnet_send_dring_reg(sc);
770 else 779 else
771 vio_send_rdx(sc); 780 vio_send_rdx(sc);
772 } 781 }
773} 782}
774 783
775void 784void
776vnet_rx_vio_dring_reg(struct vnet_softc *sc, struct vio_msg_tag *tag) 785vnet_rx_vio_dring_reg(struct vnet_softc *sc, struct vio_msg_tag *tag)
777{ 786{
778#if 0 787#if 0
779 DPRINTF(("%s: entry\n", __func__)); 788 DPRINTF(("%s: entry\n", __func__));
780#endif  789#endif
781 struct vio_dring_reg *dr = (struct vio_dring_reg *)tag; 790 struct vio_dring_reg *dr = (struct vio_dring_reg *)tag;
782 791
783 switch (dr->tag.stype) { 792 switch (dr->tag.stype) {
784 case VIO_SUBTYPE_INFO: 793 case VIO_SUBTYPE_INFO:
785#if 0  794#if 0
786 DPRINTF(("CTRL/INFO/DRING_REG\n")); 795 DPRINTF(("CTRL/INFO/DRING_REG\n"));
787#endif  796#endif
788 797
789 sc->sc_peer_dring_nentries = dr->num_descriptors; 798 sc->sc_peer_dring_nentries = dr->num_descriptors;
790 sc->sc_peer_desc_size = dr->descriptor_size; 799 sc->sc_peer_desc_size = dr->descriptor_size;
791 sc->sc_peer_dring_cookie = dr->cookie[0]; 800 sc->sc_peer_dring_cookie = dr->cookie[0];
792 801
793 dr->tag.stype = VIO_SUBTYPE_ACK; 802 dr->tag.stype = VIO_SUBTYPE_ACK;
794 dr->tag.sid = sc->sc_local_sid; 803 dr->tag.sid = sc->sc_local_sid;
795 vnet_sendmsg(sc, dr, sizeof(*dr)); 804 vnet_sendmsg(sc, dr, sizeof(*dr));
796 sc->sc_vio_state |= VIO_RCV_DRING_REG; 805 sc->sc_vio_state |= VIO_RCV_DRING_REG;
797 break; 806 break;
798 807
799 case VIO_SUBTYPE_ACK: 808 case VIO_SUBTYPE_ACK:
800#if 0  809#if 0
801 DPRINTF(("CTRL/ACK/DRING_REG\n")); 810 DPRINTF(("CTRL/ACK/DRING_REG\n"));
802#endif  811#endif
803 if (!ISSET(sc->sc_vio_state, VIO_SND_DRING_REG)) { 812 if (!ISSET(sc->sc_vio_state, VIO_SND_DRING_REG)) {
804 ldc_reset(&sc->sc_lc); 813 ldc_reset(&sc->sc_lc);
805 break; 814 break;
806 } 815 }
807 816
808 sc->sc_dring_ident = dr->dring_ident; 817 sc->sc_dring_ident = dr->dring_ident;
809 sc->sc_seq_no = 1; 818 sc->sc_seq_no = 1;
810 819
811 sc->sc_vio_state |= VIO_ACK_DRING_REG; 820 sc->sc_vio_state |= VIO_ACK_DRING_REG;
812 break; 821 break;
813 822
814 default: 823 default:
815 DPRINTF(("CTRL/0x%02x/DRING_REG\n", dr->tag.stype)); 824 DPRINTF(("CTRL/0x%02x/DRING_REG\n", dr->tag.stype));
816 break; 825 break;
817 } 826 }
818 827
819 if (ISSET(sc->sc_vio_state, VIO_RCV_DRING_REG) && 828 if (ISSET(sc->sc_vio_state, VIO_RCV_DRING_REG) &&
820 ISSET(sc->sc_vio_state, VIO_ACK_DRING_REG)) 829 ISSET(sc->sc_vio_state, VIO_ACK_DRING_REG))
821 vio_send_rdx(sc); 830 vio_send_rdx(sc);
822} 831}
823 832
824void 833void
825vnet_rx_vio_rdx(struct vnet_softc *sc, struct vio_msg_tag *tag) 834vnet_rx_vio_rdx(struct vnet_softc *sc, struct vio_msg_tag *tag)
826{ 835{
827#if 0 836#if 0
828 DPRINTF(("%s: entry\n", __func__)); 837 DPRINTF(("%s: entry\n", __func__));
829#endif  838#endif
830#if 0 839#if 0
831FIXME openbsd  840FIXME openbsd
832 struct ifnet *ifp = &sc->sc_ac.ac_if; 841 struct ifnet *ifp = &sc->sc_ac.ac_if;
833#else 842#else
834 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 843 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
835#endif  844#endif
836 845
837 switch(tag->stype) { 846 switch(tag->stype) {
838 case VIO_SUBTYPE_INFO: 847 case VIO_SUBTYPE_INFO:
839#if 0  848#if 0
840 DPRINTF(("CTRL/INFO/RDX\n")); 849 DPRINTF(("CTRL/INFO/RDX\n"));
841#endif  850#endif
842 851
843 tag->stype = VIO_SUBTYPE_ACK; 852 tag->stype = VIO_SUBTYPE_ACK;
844 tag->sid = sc->sc_local_sid; 853 tag->sid = sc->sc_local_sid;
845 vnet_sendmsg(sc, tag, sizeof(*tag)); 854 vnet_sendmsg(sc, tag, sizeof(*tag));
846 sc->sc_vio_state |= VIO_RCV_RDX; 855 sc->sc_vio_state |= VIO_RCV_RDX;
847 break; 856 break;
848 857
849 case VIO_SUBTYPE_ACK: 858 case VIO_SUBTYPE_ACK:
850#if 0  859#if 0
851 DPRINTF(("CTRL/ACK/RDX\n")); 860 DPRINTF(("CTRL/ACK/RDX\n"));
852#endif  861#endif
853 if (!ISSET(sc->sc_vio_state, VIO_SND_RDX)) { 862 if (!ISSET(sc->sc_vio_state, VIO_SND_RDX)) {
854 ldc_reset(&sc->sc_lc); 863 ldc_reset(&sc->sc_lc);
855 break; 864 break;
856 } 865 }
857 sc->sc_vio_state |= VIO_ACK_RDX; 866 sc->sc_vio_state |= VIO_ACK_RDX;
858 break; 867 break;
859 868
860 default: 869 default:
861 DPRINTF(("CTRL/0x%02x/RDX (VIO)\n", tag->stype)); 870 DPRINTF(("CTRL/0x%02x/RDX (VIO)\n", tag->stype));
862 break; 871 break;
863 } 872 }
864 873
865 if (ISSET(sc->sc_vio_state, VIO_RCV_RDX) && 874 if (ISSET(sc->sc_vio_state, VIO_RCV_RDX) &&
866 ISSET(sc->sc_vio_state, VIO_ACK_RDX)) { 875 ISSET(sc->sc_vio_state, VIO_ACK_RDX)) {
867 /* Link is up! */ 876 /* Link is up! */
868 vnet_link_state(sc); 877 vnet_link_state(sc);
869 878
870 /* Configure multicast now that we can. */ 879 /* Configure multicast now that we can. */
871 vnet_setmulti(sc, 1); 880 vnet_setmulti(sc, 1);
872 881
873#if 0 882#if 0
874FIXME openbsd  883FIXME openbsd
875 KERNEL_LOCK(); 884 KERNEL_LOCK();
876#else  885#else
877 KERNEL_LOCK(1, curlwp); 886 KERNEL_LOCK(1, curlwp);
878#endif  887#endif
879#if 0 888#if 0
880FIXME openbsd  889FIXME openbsd
881 ifq_clr_oactive(&ifp->if_snd); 890 ifq_clr_oactive(&ifp->if_snd);
882#else 891#else
883 ifp->if_flags &= ~IFF_OACTIVE; 892 ifp->if_flags &= ~IFF_OACTIVE;
884#endif  893#endif
885 vnet_start(ifp); 894 vnet_start(ifp);
886#if 0 895#if 0
887FIXME openbsd  896FIXME openbsd
888 KERNEL_UNLOCK(); 897 KERNEL_UNLOCK();
889#else 898#else
890 KERNEL_UNLOCK_ONE(curlwp); 899 KERNEL_UNLOCK_ONE(curlwp);
891#endif  900#endif
892 } 901 }
893} 902}
894 903
895void 904void
 905vnet_rx_vio_mcast_info(struct vnet_softc *sc, struct vio_msg_tag *tag)
 906{
 907#if 0
 908 DPRINTF(("%s: entry\n", __func__));
 909#endif
 910
 911 switch(tag->stype) {
 912
 913 case VIO_SUBTYPE_INFO:
 914#if 0
 915 DPRINTF(("CTRL/INFO/MCAST_INFO\n"));
 916#endif
 917 break;
 918
 919 case VIO_SUBTYPE_ACK:
 920#if 0
 921 DPRINTF(("CTRL/ACK/MCAST_INFO\n"));
 922#endif
 923 break;
 924
 925 case VIO_SUBTYPE_NACK:
 926#if 0
 927 DPRINTF(("CTRL/NACK/MCAST_INFO\n"));
 928#endif
 929 break;
 930
 931 default:
 932 printf("%s: CTRL/0x%02x/0x%04x\n",
 933 __func__, tag->stype, tag->stype_env);
 934 break;
 935 }
 936}
 937
 938void
896vnet_rx_vio_data(struct vnet_softc *sc, struct vio_msg *vm) 939vnet_rx_vio_data(struct vnet_softc *sc, struct vio_msg *vm)
897{ 940{
898#if 0 941#if 0
899 DPRINTF(("%s: entry\n", __func__)); 942 DPRINTF(("%s: entry\n", __func__));
900#endif  943#endif
901 struct vio_msg_tag *tag = (struct vio_msg_tag *)&vm->type; 944 struct vio_msg_tag *tag = (struct vio_msg_tag *)&vm->type;
902 945
903 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) || 946 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) ||
904 !ISSET(sc->sc_vio_state, VIO_ACK_RDX)) { 947 !ISSET(sc->sc_vio_state, VIO_ACK_RDX)) {
905 DPRINTF(("Spurious DATA/0x%02x/0x%04x\n", tag->stype, 948 DPRINTF(("Spurious DATA/0x%02x/0x%04x\n", tag->stype,
906 tag->stype_env)); 949 tag->stype_env));
907 return; 950 return;
908 } 951 }
909 952
910 switch(tag->stype_env) { 953 switch(tag->stype_env) {
911 case VIO_DESC_DATA: 954 case VIO_DESC_DATA:
912 vnet_rx_vio_desc_data(sc, tag); 955 vnet_rx_vio_desc_data(sc, tag);
913 break; 956 break;
914 957
915 case VIO_DRING_DATA: 958 case VIO_DRING_DATA:
916 vnet_rx_vio_dring_data(sc, tag); 959 vnet_rx_vio_dring_data(sc, tag);
917 break; 960 break;
918 961
919 default: 962 default:
920 DPRINTF(("DATA/0x%02x/0x%04x\n", tag->stype, tag->stype_env)); 963 DPRINTF(("DATA/0x%02x/0x%04x\n", tag->stype, tag->stype_env));
921 break; 964 break;
922 } 965 }
923} 966}
924 967
925void 968void
926vnet_rx_vio_desc_data(struct vnet_softc *sc, struct vio_msg_tag *tag) 969vnet_rx_vio_desc_data(struct vnet_softc *sc, struct vio_msg_tag *tag)
927{ 970{
928 971
929 DPRINTF(("%s: entry\n", __func__)); 972 DPRINTF(("%s: entry\n", __func__));
930  973
931 struct vnet_desc_msg *dm = (struct vnet_desc_msg *)tag; 974 struct vnet_desc_msg *dm = (struct vnet_desc_msg *)tag;
932 struct ldc_conn *lc = &sc->sc_lc; 975 struct ldc_conn *lc = &sc->sc_lc;
933 struct ldc_map *map = sc->sc_lm; 976 struct ldc_map *map = sc->sc_lm;
934#if 0 977#if 0
935FIXME openbsd  978FIXME openbsd
936 struct ifnet *ifp = &sc->sc_ac.ac_if; 979 struct ifnet *ifp = &sc->sc_ac.ac_if;
937#else  980#else
938 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 981 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
939#endif 982#endif
940#if 0 983#if 0
941FIXME openbsd  984FIXME openbsd
942 struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 985 struct mbuf_list ml = MBUF_LIST_INITIALIZER();
943#endif  986#endif
944 struct mbuf *m; 987 struct mbuf *m;
945 unsigned char *buf; 988 unsigned char *buf;
946 paddr_t pa; 989 paddr_t pa;
947 psize_t nbytes; 990 psize_t nbytes;
948 u_int cons; 991 u_int cons;
949 int err; 992 int err;
950 993
951 switch(tag->stype) { 994 switch(tag->stype) {
952 case VIO_SUBTYPE_INFO: 995 case VIO_SUBTYPE_INFO:
953 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO); 996 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO);
954 if (buf == NULL) { 997 if (buf == NULL) {
955#if 0 998#if 0
956FIXME openbsd  999FIXME openbsd
957 ifp->if_ierrors++; 1000 ifp->if_ierrors++;
958#else 1001#else
959 if_statinc(ifp, if_ierrors); 1002 if_statinc(ifp, if_ierrors);
960#endif  1003#endif
961 goto skip; 1004 goto skip;
962 } 1005 }
963 nbytes = roundup(dm->nbytes, 8); 1006 nbytes = roundup(dm->nbytes, 8);
964 1007
965 if (dm->nbytes > (ETHER_MAX_LEN - ETHER_CRC_LEN)) { 1008 if (dm->nbytes > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
966#if 0 1009#if 0
967FIXME openbsd  1010FIXME openbsd
968 ifp->if_ierrors++; 1011 ifp->if_ierrors++;
969#else  1012#else
970 if_statinc(ifp, if_ierrors); 1013 if_statinc(ifp, if_ierrors);
971#endif  1014#endif
972 goto skip; 1015 goto skip;
973 } 1016 }
974 1017
975 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa); 1018 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa);
976 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN, 1019 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN,
977 dm->cookie[0].addr, pa, nbytes, &nbytes); 1020 dm->cookie[0].addr, pa, nbytes, &nbytes);
978 if (err != H_EOK) { 1021 if (err != H_EOK) {
979 pool_put(&sc->sc_pool, buf); 1022 pool_put(&sc->sc_pool, buf);
980#if 0 1023#if 0
981FIXME openbsd  1024FIXME openbsd
982 ifp->if_ierrors++; 1025 ifp->if_ierrors++;
983#else  1026#else
984 if_statinc(ifp, if_ierrors); 1027 if_statinc(ifp, if_ierrors);
985#endif  1028#endif
986 goto skip; 1029 goto skip;
987 } 1030 }
988 1031
989 /* Stupid OBP doesn't align properly. */ 1032 /* Stupid OBP doesn't align properly. */
990#if 0 1033#if 0
991FIXME openbsd  1034FIXME openbsd
992 m = m_devget(buf, dm->nbytes, ETHER_ALIGN); 1035 m = m_devget(buf, dm->nbytes, ETHER_ALIGN);
993#else 1036#else
994 m = m_devget(buf, dm->nbytes, 0, ifp); 1037 m = m_devget(buf, dm->nbytes, 0, ifp);
995#endif  1038#endif
996 pool_put(&sc->sc_pool, buf); 1039 pool_put(&sc->sc_pool, buf);
997 if (m == NULL) { 1040 if (m == NULL) {
998#if 0 1041#if 0
999FIXME openbsd  1042FIXME openbsd
1000 ifp->if_ierrors++; 1043 ifp->if_ierrors++;
1001#else  1044#else
1002 if_statinc(ifp, if_ierrors); 1045 if_statinc(ifp, if_ierrors);
1003#endif  1046#endif
1004 goto skip; 1047 goto skip;
1005 } 1048 }
1006 1049
1007 /* Pass it on. */ 1050 /* Pass it on. */
1008#if 0 1051#if 0
1009FIXME openbsd  1052FIXME openbsd
1010 ml_enqueue(&ml, m); 1053 ml_enqueue(&ml, m);
1011 if_input(ifp, &ml); 1054 if_input(ifp, &ml);
1012#else  1055#else
1013 if_percpuq_enqueue(ifp->if_percpuq, m); 1056 if_percpuq_enqueue(ifp->if_percpuq, m);
1014#endif 1057#endif
1015 skip: 1058 skip:
1016 dm->tag.stype = VIO_SUBTYPE_ACK; 1059 dm->tag.stype = VIO_SUBTYPE_ACK;
1017 dm->tag.sid = sc->sc_local_sid; 1060 dm->tag.sid = sc->sc_local_sid;
1018 vnet_sendmsg(sc, dm, sizeof(*dm)); 1061 vnet_sendmsg(sc, dm, sizeof(*dm));
1019 break; 1062 break;
1020 1063
1021 case VIO_SUBTYPE_ACK: 1064 case VIO_SUBTYPE_ACK:
1022 DPRINTF(("DATA/ACK/DESC_DATA\n")); 1065 DPRINTF(("DATA/ACK/DESC_DATA\n"));
1023 1066
1024 if (dm->desc_handle != sc->sc_tx_cons) { 1067 if (dm->desc_handle != sc->sc_tx_cons) {
1025 printf("out of order\n"); 1068 printf("out of order\n");
1026 return; 1069 return;
1027 } 1070 }
1028 1071
1029 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1); 1072 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1);
1030 1073
1031 map->lm_slot[sc->sc_vsd[cons].vsd_map_idx].entry = 0; 1074 map->lm_slot[sc->sc_vsd[cons].vsd_map_idx].entry = 0;
1032#if 0 1075#if 0
1033FIXME openbsd  1076FIXME openbsd
1034 atomic_dec_int(&map->lm_count); 1077 atomic_dec_int(&map->lm_count);
1035#else 1078#else
1036 map->lm_count--; 1079 map->lm_count--;
1037#endif  1080#endif
1038 1081
1039 pool_put(&sc->sc_pool, sc->sc_vsd[cons].vsd_buf); 1082 pool_put(&sc->sc_pool, sc->sc_vsd[cons].vsd_buf);
1040 sc->sc_vsd[cons].vsd_buf = NULL; 1083 sc->sc_vsd[cons].vsd_buf = NULL;
1041 1084
1042 sc->sc_tx_cons++; 1085 sc->sc_tx_cons++;
1043 break; 1086 break;
1044 1087
1045 case VIO_SUBTYPE_NACK: 1088 case VIO_SUBTYPE_NACK:
1046 DPRINTF(("DATA/NACK/DESC_DATA\n")); 1089 DPRINTF(("DATA/NACK/DESC_DATA\n"));
1047 break; 1090 break;
1048 1091
1049 default: 1092 default:
1050 DPRINTF(("DATA/0x%02x/DESC_DATA\n", tag->stype)); 1093 DPRINTF(("DATA/0x%02x/DESC_DATA\n", tag->stype));
1051 break; 1094 break;
1052 } 1095 }
1053} 1096}
1054 1097
1055void 1098void
1056vnet_rx_vio_dring_data(struct vnet_softc *sc, struct vio_msg_tag *tag) 1099vnet_rx_vio_dring_data(struct vnet_softc *sc, struct vio_msg_tag *tag)
1057{ 1100{
1058#if 0 1101#if 0
1059 DPRINTF(("%s: entry\n", __func__)); 1102 DPRINTF(("%s: entry\n", __func__));
1060#endif  1103#endif
1061  1104
1062 struct vio_dring_msg *dm = (struct vio_dring_msg *)tag; 1105 struct vio_dring_msg *dm = (struct vio_dring_msg *)tag;
1063 struct ldc_conn *lc = &sc->sc_lc; 1106 struct ldc_conn *lc = &sc->sc_lc;
1064#if 0 1107#if 0
1065FIXME openbsd  1108FIXME openbsd
1066 struct ifnet *ifp = &sc->sc_ac.ac_if; 1109 struct ifnet *ifp = &sc->sc_ac.ac_if;
1067#else  1110#else
1068 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 1111 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1069#endif 1112#endif
1070#if 1 1113#if 1
1071 struct mbuf *m = NULL; 1114 struct mbuf *m = NULL;
1072#endif  1115#endif
1073 paddr_t pa; 1116 paddr_t pa;
1074 psize_t nbytes; 1117 psize_t nbytes;
1075 int err; 1118 int err;
1076 1119
1077 switch(tag->stype) { 1120 switch(tag->stype) {
1078 case VIO_SUBTYPE_INFO: 1121 case VIO_SUBTYPE_INFO:
1079 { 1122 {
1080#if 0  1123#if 0
1081 DPRINTF(("%s: VIO_SUBTYPE_INFO\n", __func__)); 1124 DPRINTF(("%s: VIO_SUBTYPE_INFO\n", __func__));
1082#endif  1125#endif
1083 struct vnet_desc desc; 1126 struct vnet_desc desc;
1084 uint64_t cookie; 1127 uint64_t cookie;
1085 paddr_t desc_pa; 1128 paddr_t desc_pa;
1086 int idx, ack_end_idx = -1; 1129 int idx, ack_end_idx = -1;
1087#if 0 1130#if 0
1088FIXME openbsd  1131FIXME openbsd
1089 struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 1132 struct mbuf_list ml = MBUF_LIST_INITIALIZER();
1090#endif  1133#endif
1091 1134
1092 idx = dm->start_idx; 1135 idx = dm->start_idx;
1093 for (;;) { 1136 for (;;) {
1094 cookie = sc->sc_peer_dring_cookie.addr; 1137 cookie = sc->sc_peer_dring_cookie.addr;
1095 cookie += idx * sc->sc_peer_desc_size; 1138 cookie += idx * sc->sc_peer_desc_size;
1096 nbytes = sc->sc_peer_desc_size; 1139 nbytes = sc->sc_peer_desc_size;
1097 pmap_extract(pmap_kernel(), (vaddr_t)&desc, &desc_pa); 1140 pmap_extract(pmap_kernel(), (vaddr_t)&desc, &desc_pa);
1098 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN, cookie, 1141 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN, cookie,
1099 desc_pa, nbytes, &nbytes); 1142 desc_pa, nbytes, &nbytes);
1100 if (err != H_EOK) { 1143 if (err != H_EOK) {
1101 printf("hv_ldc_copy_in %d\n", err); 1144 printf("hv_ldc_copy_in %d\n", err);
1102 break; 1145 break;
1103 } 1146 }
1104 1147
1105 if (desc.hdr.dstate != VIO_DESC_READY) 1148 if (desc.hdr.dstate != VIO_DESC_READY)
1106 break; 1149 break;
1107 1150
1108 if (desc.nbytes > (ETHER_MAX_LEN - ETHER_CRC_LEN)) { 1151 if (desc.nbytes > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
1109#if 0 1152#if 0
1110FIXME openbsd  1153FIXME openbsd
1111 ifp->if_ierrors++; 1154 ifp->if_ierrors++;
1112#else 1155#else
1113 if_statinc(ifp, if_ierrors); 1156 if_statinc(ifp, if_ierrors);
1114#endif  1157#endif
1115 goto skip; 1158 goto skip;
1116 } 1159 }
1117#if 0 1160#if 0
1118FIXME openbsd  1161FIXME openbsd
1119 m = MCLGETI(NULL, M_DONTWAIT, NULL, desc.nbytes); 1162 m = MCLGETI(NULL, M_DONTWAIT, NULL, desc.nbytes);
1120 if (!m) 1163 if (!m)
1121 break; 1164 break;
1122#else 1165#else
1123#if 1 1166#if 1
1124#if 0  1167#if 0
1125 DPRINTF(("%s: before MGETHDR\n", __func__)); 1168 DPRINTF(("%s: before MGETHDR\n", __func__));
1126#endif  1169#endif
1127 MGETHDR(m, M_DONTWAIT, MT_DATA); 1170 MGETHDR(m, M_DONTWAIT, MT_DATA);
1128#if 0  1171#if 0
1129 DPRINTF(("%s: after MGETHDR\n", __func__)); 1172 DPRINTF(("%s: after MGETHDR\n", __func__));
1130#endif  1173#endif
1131 if (m == NULL) { 1174 if (m == NULL) {
1132 DPRINTF(("%s: MGETHDR failed\n", __func__)); 1175 DPRINTF(("%s: MGETHDR failed\n", __func__));
1133 if_statinc(ifp, if_ierrors); 1176 if_statinc(ifp, if_ierrors);
1134 goto skip; 1177 goto skip;
1135 } 1178 }
1136#if 0  1179#if 0
1137 DPRINTF(("%s: before MCLGET\n", __func__)); 1180 DPRINTF(("%s: before MCLGET\n", __func__));
1138#endif  1181#endif
1139 MCLGET(m, M_DONTWAIT); 1182 MCLGET(m, M_DONTWAIT);
1140 if ((m->m_flags & M_EXT) == 0) 1183 if ((m->m_flags & M_EXT) == 0)
1141 break; 1184 break;
1142#if 0  1185#if 0
1143 DPRINTF(("%s: after MCLGET\n", __func__)); 1186 DPRINTF(("%s: after MCLGET\n", __func__));
1144#endif  1187#endif
1145#endif  1188#endif
1146#endif 1189#endif
1147#if 1 1190#if 1
1148 m->m_len = m->m_pkthdr.len = desc.nbytes; 1191 m->m_len = m->m_pkthdr.len = desc.nbytes;
1149#endif  1192#endif
1150 nbytes = roundup(desc.nbytes + VNET_ETHER_ALIGN, 8); 1193 nbytes = roundup(desc.nbytes + VNET_ETHER_ALIGN, 8);
1151#if 1 1194#if 0
1152 DPRINTF(("%s: nbytes %" PRId64 " desc.nbytes %" PRId32 "\n", 1195 DPRINTF(("%s: RX frame size %" PRId16 "\n",
1153 __func__, nbytes, desc.nbytes)); 1196 __func__, (int)nbytes));
1154 uint8_t buf[ETHER_MAX_LEN]; 1197 uint8_t buf[ETHER_MAX_LEN];
1155 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa); 1198 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa);
1156 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN, 1199 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN,
1157 desc.cookie[0].addr, pa, nbytes, &nbytes); 1200 desc.cookie[0].addr, pa, nbytes, &nbytes);
1158 if (err != H_EOK) { 1201 if (err != H_EOK) {
1159 //m_freem(m); 1202 //m_freem(m);
1160 goto skip; 1203 goto skip;
1161 } 1204 }
1162 for (int i = 0; i < desc.nbytes; i++) { 1205 for (int i = 0; i < desc.nbytes; i++) {
1163 if (i % 16 == 0) { 1206 if (i % 16 == 0) {
1164 printf("\n"); 1207 DPRINTF(("\n"));
1165 } 1208 }
1166 printf("%02x ", buf[i]); 1209 DPRINTF(("%02x ", buf[i]));
1167 } 1210 }
1168 printf("\n"); 1211 DPRINTF(("\n"));
 1212 DPRINTF(("\n"));
1169#endif  1213#endif
1170#if 1 1214#if 1
1171 pmap_extract(pmap_kernel(), (vaddr_t)m->m_data, &pa); 1215 pmap_extract(pmap_kernel(), (vaddr_t)m->m_data, &pa);
1172 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN, 1216 err = hv_ldc_copy(lc->lc_id, LDC_COPY_IN,
1173 desc.cookie[0].addr, pa, nbytes, &nbytes); 1217 desc.cookie[0].addr, pa, nbytes, &nbytes);
1174 if (err != H_EOK) { 1218 if (err != H_EOK) {
1175 m_freem(m); 1219 m_freem(m);
1176 goto skip; 1220 goto skip;
1177 } 1221 }
1178 m->m_data += VNET_ETHER_ALIGN; 1222 m->m_data += VNET_ETHER_ALIGN;
 1223 m_set_rcvif(m, ifp);
1179 1224
1180#if 0 1225#if 0
1181FIXME openbsd  1226FIXME openbsd
1182 ml_enqueue(&ml, m); 1227 ml_enqueue(&ml, m);
1183#else 1228#else
1184#if 0  1229#if 0
1185 DPRINTF(("%s: before if_percpuq_enqueue\n", __func__)); 1230 DPRINTF(("%s: before if_percpuq_enqueue\n", __func__));
1186#endif  1231#endif
1187 if_percpuq_enqueue(ifp->if_percpuq, m); 1232 if_percpuq_enqueue(ifp->if_percpuq, m);
1188#if 0  1233#if 0
1189 DPRINTF(("%s: after if_percpuq_enqueue\n", __func__)); 1234 DPRINTF(("%s: after if_percpuq_enqueue\n", __func__));
1190#endif  1235#endif
1191#endif 1236#endif
1192#endif  1237#endif
1193 1238
1194 skip: 1239 skip:
1195 desc.hdr.dstate = VIO_DESC_DONE; 1240 desc.hdr.dstate = VIO_DESC_DONE;
1196 nbytes = sc->sc_peer_desc_size; 1241 nbytes = sc->sc_peer_desc_size;
1197 err = hv_ldc_copy(lc->lc_id, LDC_COPY_OUT, cookie, 1242 err = hv_ldc_copy(lc->lc_id, LDC_COPY_OUT, cookie,
1198 desc_pa, nbytes, &nbytes); 1243 desc_pa, nbytes, &nbytes);
1199 if (err != H_EOK) 1244 if (err != H_EOK)
1200 printf("hv_ldc_copy_out %d\n", err); 1245 printf("hv_ldc_copy_out %d\n", err);
1201 1246
1202 ack_end_idx = idx; 1247 ack_end_idx = idx;
1203 if (++idx == sc->sc_peer_dring_nentries) 1248 if (++idx == sc->sc_peer_dring_nentries)
1204 idx = 0; 1249 idx = 0;
1205 } 1250 }
1206#if 0 1251#if 0
1207FIXME openbd  1252FIXME openbd
1208 if_input(ifp, &ml); 1253 if_input(ifp, &ml);
1209#else 1254#else
1210// FIXME??? printf("vnet_rx_vio_dring_data() ignoring if_input - FIXME\n"); 1255// FIXME??? printf("vnet_rx_vio_dring_data() ignoring if_input - FIXME\n");
1211#endif  1256#endif
1212 1257
1213 if (ack_end_idx == -1) { 1258 if (ack_end_idx == -1) {
1214 dm->tag.stype = VIO_SUBTYPE_NACK; 1259 dm->tag.stype = VIO_SUBTYPE_NACK;
1215 } else { 1260 } else {
1216 dm->tag.stype = VIO_SUBTYPE_ACK; 1261 dm->tag.stype = VIO_SUBTYPE_ACK;
1217 dm->end_idx = ack_end_idx; 1262 dm->end_idx = ack_end_idx;
1218 } 1263 }
1219 dm->tag.sid = sc->sc_local_sid; 1264 dm->tag.sid = sc->sc_local_sid;
1220 dm->proc_state = VIO_DP_STOPPED; 1265 dm->proc_state = VIO_DP_STOPPED;
1221 vnet_sendmsg(sc, dm, sizeof(*dm)); 1266 vnet_sendmsg(sc, dm, sizeof(*dm));
1222 break; 1267 break;
1223 } 1268 }
1224 1269
1225 case VIO_SUBTYPE_ACK: 1270 case VIO_SUBTYPE_ACK:
1226 { 1271 {
1227#if 0  1272#if 0
1228 DPRINTF(("%s: VIO_SUBTYPE_ACK\n", __func__)); 1273 DPRINTF(("%s: VIO_SUBTYPE_ACK\n", __func__));
1229#endif  1274#endif
1230 struct ldc_map *map = sc->sc_lm; 1275 struct ldc_map *map = sc->sc_lm;
1231 u_int cons, count; 1276 u_int cons, count;
1232 1277
1233 sc->sc_peer_state = dm->proc_state; 1278 sc->sc_peer_state = dm->proc_state;
1234 1279
1235 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1); 1280 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1);
1236 while (sc->sc_vd->vd_desc[cons].hdr.dstate == VIO_DESC_DONE) { 1281 while (sc->sc_vd->vd_desc[cons].hdr.dstate == VIO_DESC_DONE) {
1237 map->lm_slot[sc->sc_vsd[cons].vsd_map_idx].entry = 0; 1282 map->lm_slot[sc->sc_vsd[cons].vsd_map_idx].entry = 0;
1238#if 0 1283#if 0
1239FIXME openbsd  1284FIXME openbsd
1240 atomic_dec_int(&map->lm_count); 1285 atomic_dec_int(&map->lm_count);
1241#else 1286#else
1242 map->lm_count--; 1287 map->lm_count--;
1243#endif  1288#endif
1244 1289
1245 pool_put(&sc->sc_pool, sc->sc_vsd[cons].vsd_buf); 1290 pool_put(&sc->sc_pool, sc->sc_vsd[cons].vsd_buf);
1246 sc->sc_vsd[cons].vsd_buf = NULL; 1291 sc->sc_vsd[cons].vsd_buf = NULL;
1247 1292
1248 sc->sc_vd->vd_desc[cons].hdr.dstate = VIO_DESC_FREE; 1293 sc->sc_vd->vd_desc[cons].hdr.dstate = VIO_DESC_FREE;
1249 sc->sc_tx_cons++; 1294 sc->sc_tx_cons++;
1250 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1); 1295 cons = sc->sc_tx_cons & (sc->sc_vd->vd_nentries - 1);
1251 } 1296 }
1252 1297
1253 count = sc->sc_tx_prod - sc->sc_tx_cons; 1298 count = sc->sc_tx_prod - sc->sc_tx_cons;
1254 if (count > 0 && sc->sc_peer_state != VIO_DP_ACTIVE) 1299 if (count > 0 && sc->sc_peer_state != VIO_DP_ACTIVE)
1255 vnet_send_dring_data(sc, cons); 1300 vnet_send_dring_data(sc, cons);
1256 1301
1257#if 0 1302#if 0
1258FIXME openbsd  1303FIXME openbsd
1259 KERNEL_LOCK(); 1304 KERNEL_LOCK();
1260#else  1305#else
1261 KERNEL_LOCK(1, curlwp); 1306 KERNEL_LOCK(1, curlwp);
1262#endif  1307#endif
1263 if (count < (sc->sc_vd->vd_nentries - 1)) 1308 if (count < (sc->sc_vd->vd_nentries - 1))
1264#if 0 1309#if 0
1265FIXME openbsd  1310FIXME openbsd
1266 ifq_clr_oactive(&ifp->if_snd); 1311 ifq_clr_oactive(&ifp->if_snd);
1267#else 1312#else
1268 ifp->if_flags &= ~IFF_OACTIVE; 1313 ifp->if_flags &= ~IFF_OACTIVE;
1269#endif  1314#endif
1270 if (count == 0) 1315 if (count == 0)
1271 ifp->if_timer = 0; 1316 ifp->if_timer = 0;
1272 1317
1273 vnet_start(ifp); 1318 vnet_start(ifp);
1274#if 0 1319#if 0
1275FIXME openbsd  1320FIXME openbsd
1276 KERNEL_UNLOCK(); 1321 KERNEL_UNLOCK();
1277#else 1322#else
1278 KERNEL_UNLOCK_ONE(curlwp); 1323 KERNEL_UNLOCK_ONE(curlwp);
1279#endif  1324#endif
1280 break; 1325 break;
1281 } 1326 }
1282 1327
1283 case VIO_SUBTYPE_NACK: 1328 case VIO_SUBTYPE_NACK:
1284 DPRINTF(("DATA/NACK/DRING_DATA\n")); 1329 DPRINTF(("DATA/NACK/DRING_DATA\n"));
1285 sc->sc_peer_state = VIO_DP_STOPPED; 1330 sc->sc_peer_state = VIO_DP_STOPPED;
1286 break; 1331 break;
1287 1332
1288 default: 1333 default:
1289 DPRINTF(("DATA/0x%02x/DRING_DATA\n", tag->stype)); 1334 DPRINTF(("DATA/0x%02x/DRING_DATA\n", tag->stype));
1290 break; 1335 break;
1291 } 1336 }
1292} 1337}
1293 1338
1294void 1339void
1295vnet_ldc_reset(struct ldc_conn *lc) 1340vnet_ldc_reset(struct ldc_conn *lc)
1296{ 1341{
1297 1342
1298 DPRINTF(("%s: entry\n", __func__)); 1343 DPRINTF(("%s: entry\n", __func__));
1299  1344
1300 struct vnet_softc *sc = lc->lc_sc; 1345 struct vnet_softc *sc = lc->lc_sc;
1301 int i; 1346 int i;
1302#if 0 1347#if 0
1303FIXME openbsd  1348FIXME openbsd
1304 timeout_del(&sc->sc_handshake_to); 1349 timeout_del(&sc->sc_handshake_to);
1305#else  1350#else
1306 callout_stop(&sc->sc_handshake_co); 1351 callout_stop(&sc->sc_handshake_co);
1307#endif  1352#endif
1308 sc->sc_tx_prod = sc->sc_tx_cons = 0; 1353 sc->sc_tx_prod = sc->sc_tx_cons = 0;
1309 sc->sc_peer_state = VIO_DP_STOPPED; 1354 sc->sc_peer_state = VIO_DP_STOPPED;
1310 sc->sc_vio_state = 0; 1355 sc->sc_vio_state = 0;
1311 vnet_link_state(sc); 1356 vnet_link_state(sc);
1312 1357
1313 sc->sc_lm->lm_next = 1; 1358 sc->sc_lm->lm_next = 1;
1314 sc->sc_lm->lm_count = 1; 1359 sc->sc_lm->lm_count = 1;
1315 for (i = 1; i < sc->sc_lm->lm_nentries; i++) 1360 for (i = 1; i < sc->sc_lm->lm_nentries; i++)
1316 sc->sc_lm->lm_slot[i].entry = 0; 1361 sc->sc_lm->lm_slot[i].entry = 0;
1317 1362
1318 for (i = 0; i < sc->sc_vd->vd_nentries; i++) { 1363 for (i = 0; i < sc->sc_vd->vd_nentries; i++) {
1319 if (sc->sc_vsd[i].vsd_buf) { 1364 if (sc->sc_vsd[i].vsd_buf) {
1320 pool_put(&sc->sc_pool, sc->sc_vsd[i].vsd_buf); 1365 pool_put(&sc->sc_pool, sc->sc_vsd[i].vsd_buf);
1321 sc->sc_vsd[i].vsd_buf = NULL; 1366 sc->sc_vsd[i].vsd_buf = NULL;
1322 } 1367 }
1323 sc->sc_vd->vd_desc[i].hdr.dstate = VIO_DESC_FREE; 1368 sc->sc_vd->vd_desc[i].hdr.dstate = VIO_DESC_FREE;
1324 } 1369 }
1325} 1370}
1326 1371
1327void 1372void
1328vnet_ldc_start(struct ldc_conn *lc) 1373vnet_ldc_start(struct ldc_conn *lc)
1329{ 1374{
1330#if 0 1375#if 0
1331 DPRINTF(("%s: entry\n", __func__)); 1376 DPRINTF(("%s: entry\n", __func__));
1332#endif  1377#endif
1333  1378
1334 struct vnet_softc *sc = lc->lc_sc; 1379 struct vnet_softc *sc = lc->lc_sc;
1335#if 0 1380#if 0
1336FIXME openbsd  1381FIXME openbsd
1337 timeout_del(&sc->sc_handshake_to); 1382 timeout_del(&sc->sc_handshake_to);
1338#else  1383#else
1339 callout_stop(&sc->sc_handshake_co); 1384 callout_stop(&sc->sc_handshake_co);
1340#endif  1385#endif
1341 vnet_send_ver_info(sc, VNET_MAJOR, VNET_MINOR); 1386 vnet_send_ver_info(sc, VNET_MAJOR, VNET_MINOR);
1342} 1387}
1343 1388
1344void 1389void
1345vnet_sendmsg(struct vnet_softc *sc, void *msg, size_t len) 1390vnet_sendmsg(struct vnet_softc *sc, void *msg, size_t len)
1346{ 1391{
1347#if 0 1392#if 0
1348 DPRINTF(("%s: entry\n", __func__)); 1393 DPRINTF(("%s: entry\n", __func__));
1349#endif  1394#endif
1350 struct ldc_conn *lc = &sc->sc_lc; 1395 struct ldc_conn *lc = &sc->sc_lc;
1351 int err; 1396 int err;
1352 1397
1353 err = ldc_send_unreliable(lc, msg, len); 1398 err = ldc_send_unreliable(lc, msg, len);
1354 if (err) 1399 if (err)
1355 printf("%s: ldc_send_unreliable: %d\n", __func__, err); 1400 printf("%s: ldc_send_unreliable: %d\n", __func__, err);
1356} 1401}
1357  1402
1358void 1403void
1359vnet_send_ver_info(struct vnet_softc *sc, uint16_t major, uint16_t minor) 1404vnet_send_ver_info(struct vnet_softc *sc, uint16_t major, uint16_t minor)
1360{ 1405{
1361#if 0 1406#if 0
1362 DPRINTF(("%s: entry\n", __func__)); 1407 DPRINTF(("%s: entry\n", __func__));
1363#endif  1408#endif
1364 struct vio_ver_info vi; 1409 struct vio_ver_info vi;
1365 1410
1366 bzero(&vi, sizeof(vi)); 1411 bzero(&vi, sizeof(vi));
1367 vi.tag.type = VIO_TYPE_CTRL; 1412 vi.tag.type = VIO_TYPE_CTRL;
1368 vi.tag.stype = VIO_SUBTYPE_INFO; 1413 vi.tag.stype = VIO_SUBTYPE_INFO;
1369 vi.tag.stype_env = VIO_VER_INFO; 1414 vi.tag.stype_env = VIO_VER_INFO;
1370 vi.tag.sid = sc->sc_local_sid; 1415 vi.tag.sid = sc->sc_local_sid;
1371 vi.major = major; 1416 vi.major = major;
1372 vi.minor = minor; 1417 vi.minor = minor;
1373 vi.dev_class = VDEV_NETWORK; 1418 vi.dev_class = VDEV_NETWORK;
1374 vnet_sendmsg(sc, &vi, sizeof(vi)); 1419 vnet_sendmsg(sc, &vi, sizeof(vi));
1375 1420
1376 sc->sc_vio_state |= VIO_SND_VER_INFO; 1421 sc->sc_vio_state |= VIO_SND_VER_INFO;
1377} 1422}
1378  1423
1379void 1424void
1380vnet_send_attr_info(struct vnet_softc *sc) 1425vnet_send_attr_info(struct vnet_softc *sc)
1381{ 1426{
1382#if 0 1427#if 0
1383 DPRINTF(("%s: entry\n", __func__)); 1428 DPRINTF(("%s: entry\n", __func__));
1384#endif  1429#endif
1385 struct vnet_attr_info ai; 1430 struct vnet_attr_info ai;
1386 int i; 1431 int i;
1387 1432
1388 bzero(&ai, sizeof(ai)); 1433 bzero(&ai, sizeof(ai));
1389 ai.tag.type = VIO_TYPE_CTRL; 1434 ai.tag.type = VIO_TYPE_CTRL;
1390 ai.tag.stype = VIO_SUBTYPE_INFO; 1435 ai.tag.stype = VIO_SUBTYPE_INFO;
1391 ai.tag.stype_env = VIO_ATTR_INFO; 1436 ai.tag.stype_env = VIO_ATTR_INFO;
1392 ai.tag.sid = sc->sc_local_sid; 1437 ai.tag.sid = sc->sc_local_sid;
1393 ai.xfer_mode = VIO_DRING_MODE; 1438 ai.xfer_mode = VIO_DRING_MODE;
1394 ai.addr_type = VNET_ADDR_ETHERMAC; 1439 ai.addr_type = VNET_ADDR_ETHERMAC;
1395 ai.ack_freq = 0; 1440 ai.ack_freq = 0;
1396 ai.addr = 0; 1441 ai.addr = 0;
1397 for (i = 0; i < ETHER_ADDR_LEN; i++) { 1442 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1398 ai.addr <<= 8; 1443 ai.addr <<= 8;
1399 ai.addr |= sc->sc_macaddr[i]; 1444 ai.addr |= sc->sc_macaddr[i];
1400 } 1445 }
1401 ai.mtu = ETHER_MAX_LEN - ETHER_CRC_LEN; 1446 ai.mtu = ETHER_MAX_LEN - ETHER_CRC_LEN;
 1447#if 0
 1448 DPRINTF(("%s: ai.addr %" PRIx64 "\n",
 1449 __func__, ai.addr));
 1450 DPRINTF(("%s: ai.mtu %" PRId64 "\n",
 1451 __func__, ai.mtu));
 1452#endif
1402 vnet_sendmsg(sc, &ai, sizeof(ai)); 1453 vnet_sendmsg(sc, &ai, sizeof(ai));
1403 1454
1404 sc->sc_vio_state |= VIO_SND_ATTR_INFO; 1455 sc->sc_vio_state |= VIO_SND_ATTR_INFO;
1405} 1456}
1406  1457
1407void 1458void
1408vnet_send_dring_reg(struct vnet_softc *sc) 1459vnet_send_dring_reg(struct vnet_softc *sc)
1409{ 1460{
1410#if 1 1461#if 0
1411 DPRINTF(("%s: entry\n", __func__)); 1462 DPRINTF(("%s: entry\n", __func__));
1412#endif  1463#endif
1413  1464
1414 struct vio_dring_reg dr; 1465 struct vio_dring_reg dr;
1415 1466
1416 bzero(&dr, sizeof(dr)); 1467 bzero(&dr, sizeof(dr));
1417 dr.tag.type = VIO_TYPE_CTRL; 1468 dr.tag.type = VIO_TYPE_CTRL;
1418 dr.tag.stype = VIO_SUBTYPE_INFO; 1469 dr.tag.stype = VIO_SUBTYPE_INFO;
1419 dr.tag.stype_env = VIO_DRING_REG; 1470 dr.tag.stype_env = VIO_DRING_REG;
1420 dr.tag.sid = sc->sc_local_sid; 1471 dr.tag.sid = sc->sc_local_sid;
1421 dr.dring_ident = 0; 1472 dr.dring_ident = 0;
1422 dr.num_descriptors = sc->sc_vd->vd_nentries; 1473 dr.num_descriptors = sc->sc_vd->vd_nentries;
1423 dr.descriptor_size = sizeof(struct vnet_desc); 1474 dr.descriptor_size = sizeof(struct vnet_desc);
1424 dr.options = VIO_TX_RING; 1475 dr.options = VIO_TX_RING;
1425 dr.ncookies = 1; 1476 dr.ncookies = 1;
1426 dr.cookie[0].addr = 0; 1477 dr.cookie[0].addr = 0;
1427 dr.cookie[0].size = PAGE_SIZE; 1478 dr.cookie[0].size = PAGE_SIZE;
1428 vnet_sendmsg(sc, &dr, sizeof(dr)); 1479 vnet_sendmsg(sc, &dr, sizeof(dr));
1429 1480
1430 sc->sc_vio_state |= VIO_SND_DRING_REG; 1481 sc->sc_vio_state |= VIO_SND_DRING_REG;
1431}; 1482};
1432  1483
1433void 1484void
1434vio_send_rdx(struct vnet_softc *sc) 1485vio_send_rdx(struct vnet_softc *sc)
1435{ 1486{
1436#if 1 1487#if 0
1437 DPRINTF(("%s: entry\n", __func__)); 1488 DPRINTF(("%s: entry\n", __func__));
1438#endif  1489#endif
1439 struct vio_msg_tag tag; 1490 struct vio_msg_tag tag;
1440 1491
1441 tag.type = VIO_TYPE_CTRL; 1492 tag.type = VIO_TYPE_CTRL;
1442 tag.stype = VIO_SUBTYPE_INFO; 1493 tag.stype = VIO_SUBTYPE_INFO;
1443 tag.stype_env = VIO_RDX; 1494 tag.stype_env = VIO_RDX;
1444 tag.sid = sc->sc_local_sid; 1495 tag.sid = sc->sc_local_sid;
1445 vnet_sendmsg(sc, &tag, sizeof(tag)); 1496 vnet_sendmsg(sc, &tag, sizeof(tag));
1446 1497
1447 sc->sc_vio_state |= VIO_SND_RDX; 1498 sc->sc_vio_state |= VIO_SND_RDX;
1448} 1499}
1449  1500
1450void 1501void
1451vnet_send_dring_data(struct vnet_softc *sc, uint32_t start_idx) 1502vnet_send_dring_data(struct vnet_softc *sc, uint32_t start_idx)
1452{ 1503{
1453#if 0 1504#if 0
1454 DPRINTF(("%s: entry\n", __func__)); 1505 DPRINTF(("%s: entry\n", __func__));
1455#endif  1506#endif
1456 struct vio_dring_msg dm; 1507 struct vio_dring_msg dm;
1457 u_int peer_state; 1508 u_int peer_state;
1458 1509
1459 peer_state = atomic_swap_uint(&sc->sc_peer_state, VIO_DP_ACTIVE); 1510 peer_state = atomic_swap_uint(&sc->sc_peer_state, VIO_DP_ACTIVE);
1460 if (peer_state == VIO_DP_ACTIVE) 1511 if (peer_state == VIO_DP_ACTIVE) {
 1512 DPRINTF(("%s: peer_state == VIO_DP_ACTIVE\n", __func__));
1461 return; 1513 return;
 1514 }
1462 1515
1463 bzero(&dm, sizeof(dm)); 1516 bzero(&dm, sizeof(dm));
1464 dm.tag.type = VIO_TYPE_DATA; 1517 dm.tag.type = VIO_TYPE_DATA;
1465 dm.tag.stype = VIO_SUBTYPE_INFO; 1518 dm.tag.stype = VIO_SUBTYPE_INFO;
1466 dm.tag.stype_env = VIO_DRING_DATA; 1519 dm.tag.stype_env = VIO_DRING_DATA;
1467 dm.tag.sid = sc->sc_local_sid; 1520 dm.tag.sid = sc->sc_local_sid;
1468 dm.seq_no = sc->sc_seq_no++; 1521 dm.seq_no = sc->sc_seq_no++;
 1522#if 0
 1523 DPRINTF(("%s: dm.seq_no %" PRId64 "\n",
 1524 __func__, dm.seq_no));
 1525#endif
1469 dm.dring_ident = sc->sc_dring_ident; 1526 dm.dring_ident = sc->sc_dring_ident;
1470 dm.start_idx = start_idx; 1527 dm.start_idx = start_idx;
1471 dm.end_idx = -1; 1528 dm.end_idx = -1;
1472 vnet_sendmsg(sc, &dm, sizeof(dm)); 1529 vnet_sendmsg(sc, &dm, sizeof(dm));
 1530#if 0
 1531 DPRINTF(("%s: exit\n", __func__));
 1532#endif
1473} 1533}
1474  1534
1475void 1535void
1476vnet_start(struct ifnet *ifp) 1536vnet_start(struct ifnet *ifp)
1477{ 1537{
1478#if 0 1538#if 0
1479 DPRINTF(("%s: entry\n", __func__)); 1539 DPRINTF(("%s: entry\n", __func__));
1480#endif  1540#endif
1481 struct vnet_softc *sc = ifp->if_softc; 1541 struct vnet_softc *sc = ifp->if_softc;
1482 struct ldc_conn *lc = &sc->sc_lc; 1542 struct ldc_conn *lc = &sc->sc_lc;
1483 struct ldc_map *map = sc->sc_lm; 1543 struct ldc_map *map = sc->sc_lm;
1484 struct mbuf *m; 1544 struct mbuf *m;
1485 paddr_t pa; 1545 paddr_t pa;
1486 unsigned char *buf; 1546 unsigned char *buf;
1487 uint64_t tx_head, tx_tail, tx_state; 1547 uint64_t tx_head, tx_tail, tx_state;
1488 u_int start, prod, count; 1548 u_int start, prod, count;
1489 int err; 1549 int err;
1490#if 0 1550#if 0
1491FIXME openbsd  1551FIXME openbsd
1492 if (!(ifp->if_flags & IFF_RUNNING) || ifq_is_oactive(&ifp->if_snd)) 1552 if (!(ifp->if_flags & IFF_RUNNING) || ifq_is_oactive(&ifp->if_snd))
1493 return;  1553 return;
1494#else  1554#else
1495 if (!(ifp->if_flags & IFF_RUNNING)) 1555 if (!(ifp->if_flags & IFF_RUNNING))
1496 { 1556 {
1497 DPRINTF(("%s: not in RUNNING state\n", __func__)); 1557 DPRINTF(("%s: not in RUNNING state\n", __func__));
1498 return; 1558 return;
1499 } 1559 }
1500 if (ifp->if_flags & IFF_OACTIVE) 1560 if (ifp->if_flags & IFF_OACTIVE)
1501 { 1561 {
1502 DPRINTF(("%s: already active\n", __func__)); 1562 DPRINTF(("%s: already active\n", __func__));
1503 return; 1563 return;
1504 } 1564 }
1505#endif 1565#endif
1506 1566
1507#if 0 1567#if 0
1508FIXME openbsd  1568FIXME openbsd
1509 if (ifq_empty(&ifp->if_snd)) 1569 if (ifq_empty(&ifp->if_snd))
1510#else 1570#else
1511 if (IFQ_IS_EMPTY(&ifp->if_snd)) 1571 if (IFQ_IS_EMPTY(&ifp->if_snd))
1512#endif 1572#endif
1513 { 1573 {
1514#if 0  1574#if 0
1515 DPRINTF(("%s: queue is empty\n", __func__)); 1575 DPRINTF(("%s: queue is empty\n", __func__));
1516#endif  1576#endif
1517 return; 1577 return;
 1578 } else {
 1579#if 0
 1580 DPRINTF(("%s: queue size %d\n", __func__, ifp->if_snd.ifq_len));
 1581#endif
1518 } 1582 }
1519 1583
1520 /* 1584 /*
1521 * We cannot transmit packets until a VIO connection has been 1585 * We cannot transmit packets until a VIO connection has been
1522 * established. 1586 * established.
1523 */ 1587 */
1524 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) || 1588 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) ||
1525 !ISSET(sc->sc_vio_state, VIO_ACK_RDX)) 1589 !ISSET(sc->sc_vio_state, VIO_ACK_RDX))
1526 { 1590 {
1527#if 0  1591#if 0
1528 DPRINTF(("%s: vio connection not established yet\n", __func__)); 1592 DPRINTF(("%s: vio connection not established yet\n", __func__));
1529#endif  1593#endif
1530 return; 1594 return;
1531 } 1595 }
1532 1596
1533 /* 1597 /*
1534 * Make sure there is room in the LDC transmit queue to send a 1598 * Make sure there is room in the LDC transmit queue to send a
1535 * DRING_DATA message. 1599 * DRING_DATA message.
1536 */ 1600 */
1537 err = hv_ldc_tx_get_state(lc->lc_id, &tx_head, &tx_tail, &tx_state); 1601 err = hv_ldc_tx_get_state(lc->lc_id, &tx_head, &tx_tail, &tx_state);
1538 if (err != H_EOK) { 1602 if (err != H_EOK) {
1539 DPRINTF(("%s: no room in ldc transmit queue\n", __func__)); 1603 DPRINTF(("%s: no room in ldc transmit queue\n", __func__));
1540 return; 1604 return;
1541 } 1605 }
1542 tx_tail += sizeof(struct ldc_pkt); 1606 tx_tail += sizeof(struct ldc_pkt);
1543 tx_tail &= ((lc->lc_txq->lq_nentries * sizeof(struct ldc_pkt)) - 1); 1607 tx_tail &= ((lc->lc_txq->lq_nentries * sizeof(struct ldc_pkt)) - 1);
1544 if (tx_tail == tx_head) { 1608 if (tx_tail == tx_head) {
1545#if 0 1609#if 0
1546FIXME openbsd  1610FIXME openbsd
1547 ifq_set_oactive(&ifp->if_snd); 1611 ifq_set_oactive(&ifp->if_snd);
1548#else 1612#else
1549 ifp->if_flags |= IFF_OACTIVE; 1613 ifp->if_flags |= IFF_OACTIVE;
1550#endif 1614#endif
1551 { 1615 {
1552 DPRINTF(("%s: tail equals head\n", __func__)); 1616 DPRINTF(("%s: tail equals head\n", __func__));
1553 return; 1617 return;
1554 } 1618 }
1555 } 1619 }
1556 1620
1557 if (sc->sc_xfer_mode == VIO_DESC_MODE) { 1621 if (sc->sc_xfer_mode == VIO_DESC_MODE) {
1558 DPRINTF(("%s: vio_desc_mode\n", __func__)); 1622 DPRINTF(("%s: vio_desc_mode\n", __func__));
1559 vnet_start_desc(ifp); 1623 vnet_start_desc(ifp);
1560 return; 1624 return;
1561 } 1625 }
1562 1626
1563 start = prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1); 1627 start = prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1);
1564 while (sc->sc_vd->vd_desc[prod].hdr.dstate == VIO_DESC_FREE) { 1628 while (sc->sc_vd->vd_desc[prod].hdr.dstate == VIO_DESC_FREE) {
1565 count = sc->sc_tx_prod - sc->sc_tx_cons; 1629 count = sc->sc_tx_prod - sc->sc_tx_cons;
 1630#if 0
 1631 DPRINTF(("%s: count %d\n", __func__, count));
 1632#endif
1566 if (count >= (sc->sc_vd->vd_nentries - 1) || 1633 if (count >= (sc->sc_vd->vd_nentries - 1) ||
1567 map->lm_count >= map->lm_nentries) { 1634 map->lm_count >= map->lm_nentries) {
 1635 DPRINTF(("%s: count issue\n", __func__));
1568#if 0 1636#if 0
1569FIXME openbsd 1637FIXME openbsd
1570 ifq_set_oactive(&ifp->if_snd); 1638 ifq_set_oactive(&ifp->if_snd);
1571#else 1639#else
1572 ifp->if_flags |= IFF_OACTIVE; 1640 ifp->if_flags |= IFF_OACTIVE;
1573#endif  1641#endif
1574 break; 1642 break;
1575 } 1643 }
1576 1644
1577 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO); 1645 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO);
1578 if (buf == NULL) { 1646 if (buf == NULL) {
 1647 DPRINTF(("%s: buff is NULL\n", __func__));
1579#if 0 1648#if 0
1580FIXME openbsd  1649FIXME openbsd
1581 ifq_set_oactive(&ifp->if_snd); 1650 ifq_set_oactive(&ifp->if_snd);
1582#else 1651#else
1583 ifp->if_flags |= IFF_OACTIVE; 1652 ifp->if_flags |= IFF_OACTIVE;
1584#endif  1653#endif
1585 break; 1654 break;
1586 } 1655 }
1587#if 0 1656#if 0
1588FIXME openbsd  1657FIXME openbsd
1589 m = ifq_dequeue(&ifp->if_snd); 1658 m = ifq_dequeue(&ifp->if_snd);
1590#else 1659#else
1591 IFQ_DEQUEUE(&ifp->if_snd, m); 1660 IFQ_DEQUEUE(&ifp->if_snd, m);
1592#endif  1661#endif
1593 if (m == NULL) { 1662 if (m == NULL) {
 1663#if 0
 1664 DPRINTF(("%s: m is NULL\n", __func__));
 1665#endif
1594 pool_put(&sc->sc_pool, buf); 1666 pool_put(&sc->sc_pool, buf);
1595 break; 1667 break;
 1668 } else {
 1669#if 0
 1670 DPRINTF(("%s: m is not NULL\n", __func__));
 1671#endif
1596 } 1672 }
1597 1673
 1674#if 1
1598 m_copydata(m, 0, m->m_pkthdr.len, buf + VNET_ETHER_ALIGN); 1675 m_copydata(m, 0, m->m_pkthdr.len, buf + VNET_ETHER_ALIGN);
1599 1676#if 0
 1677 DPRINTF(("%s: TX frame size %" PRId16 "\n",
 1678 __func__, m->m_pkthdr.len));
 1679 for (int i = 0; i < m->m_pkthdr.len; i++) {
 1680 if (i % 16 == 0) {
 1681 DPRINTF(("\n"));
 1682 }
 1683 DPRINTF(("%02x ", buf[VNET_ETHER_ALIGN+i]));
 1684 }
 1685 DPRINTF(("\n"));
 1686#endif
 1687#else
 1688 m_copydata(m, 0, m->m_pkthdr.len, buf);
 1689 DPRINTF(("%s: TX frame size %" PRId16 "\n",
 1690 __func__, m->m_pkthdr.len));
 1691 for (int i = 0; i < m->m_pkthdr.len; i++) {
 1692 if (i % 16 == 0) {
 1693 DPRINTF(("\n"));
 1694 }
 1695 DPRINTF(("%02x ", buf[i]));
 1696 }
 1697 DPRINTF(("\n"));
 1698#endif
1600#if NBPFILTER > 0 1699#if NBPFILTER > 0
1601 /* 1700 /*
1602 * If BPF is listening on this interface, let it see the 1701 * If BPF is listening on this interface, let it see the
1603 * packet before we commit it to the wire. 1702 * packet before we commit it to the wire.
1604 */ 1703 */
1605 if (ifp->if_bpf) 1704 if (ifp->if_bpf)
1606 { 1705 {
 1706 DPRINTF(("%s: before bpf\n", __func__));
1607 bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT); 1707 bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT);
1608 } 1708 DPRINTF(("%s: after bpf\n", __func__));
 1709 }
1609#endif 1710#endif
1610 1711
1611 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa); 1712 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa);
1612 KASSERT((pa & ~PAGE_MASK) == (pa & LDC_MTE_RA_MASK)); 1713 KASSERT((pa & ~PAGE_MASK) == (pa & LDC_MTE_RA_MASK));
1613 while (map->lm_slot[map->lm_next].entry != 0) { 1714 while (map->lm_slot[map->lm_next].entry != 0) {
1614 map->lm_next++; 1715 map->lm_next++;
1615 map->lm_next &= (map->lm_nentries - 1); 1716 map->lm_next &= (map->lm_nentries - 1);
1616 } 1717 }
1617 map->lm_slot[map->lm_next].entry = (pa & LDC_MTE_RA_MASK); 1718 map->lm_slot[map->lm_next].entry = (pa & LDC_MTE_RA_MASK);
1618 map->lm_slot[map->lm_next].entry |= LDC_MTE_CPR; 1719 map->lm_slot[map->lm_next].entry |= LDC_MTE_CPR;
1619#if 0 1720#if 0
1620FIXME openbsd  1721FIXME openbsd
1621 atomic_inc_int(&map->lm_count); 1722 atomic_inc_int(&map->lm_count);
1622#else 1723#else
1623 map->lm_count++; 1724 map->lm_count++;
1624#endif  1725#endif
1625#if 0 1726#if 0
1626FIXME openbsd  1727FIXME openbsd
1627 sc->sc_vd->vd_desc[prod].nbytes = max(m->m_pkthdr.len, 60); 1728 sc->sc_vd->vd_desc[prod].nbytes = max(m->m_pkthdr.len, 60);
1628#else 1729#else
1629 sc->sc_vd->vd_desc[prod].nbytes = MAX(m->m_pkthdr.len, 60); 1730 sc->sc_vd->vd_desc[prod].nbytes = MAX(m->m_pkthdr.len, 60);
1630#endif  1731#endif
1631 sc->sc_vd->vd_desc[prod].ncookies = 1; 1732 sc->sc_vd->vd_desc[prod].ncookies = 1;
1632 sc->sc_vd->vd_desc[prod].cookie[0].addr = 1733 sc->sc_vd->vd_desc[prod].cookie[0].addr =
1633 map->lm_next << PAGE_SHIFT | (pa & PAGE_MASK); 1734 map->lm_next << PAGE_SHIFT | (pa & PAGE_MASK);
1634 sc->sc_vd->vd_desc[prod].cookie[0].size = 2048; 1735 sc->sc_vd->vd_desc[prod].cookie[0].size = 2048;
1635 membar_producer(); 1736 membar_producer();
1636 sc->sc_vd->vd_desc[prod].hdr.dstate = VIO_DESC_READY; 1737 sc->sc_vd->vd_desc[prod].hdr.dstate = VIO_DESC_READY;
1637 1738
1638 sc->sc_vsd[prod].vsd_map_idx = map->lm_next; 1739 sc->sc_vsd[prod].vsd_map_idx = map->lm_next;
1639 sc->sc_vsd[prod].vsd_buf = buf; 1740 sc->sc_vsd[prod].vsd_buf = buf;
1640 1741
1641 sc->sc_tx_prod++; 1742 sc->sc_tx_prod++;
1642 prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1); 1743 prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1);
1643 1744
1644 m_freem(m); 1745 m_freem(m);
1645 } 1746 }
1646 1747
1647 membar_producer(); 1748 membar_producer();
1648 1749
1649 if (start != prod && sc->sc_peer_state != VIO_DP_ACTIVE) { 1750 if (start != prod && sc->sc_peer_state != VIO_DP_ACTIVE) {
 1751#if 0
 1752 DPRINTF(("%s: before vnet_send_dring_data()\n", __func__));
 1753#endif
1650 vnet_send_dring_data(sc, start); 1754 vnet_send_dring_data(sc, start);
1651 ifp->if_timer = 5; 1755 ifp->if_timer = 5;
 1756 } else {
 1757 DPRINTF(("%s: no vnet_send_dring_data()\n", __func__));
1652 } 1758 }
1653#if 0  1759
 1760#if 0
1654 DPRINTF(("%s: exit\n", __func__)); 1761 DPRINTF(("%s: exit\n", __func__));
1655#endif  1762#endif
1656} 1763}
1657 1764
1658void 1765void
1659vnet_start_desc(struct ifnet *ifp) 1766vnet_start_desc(struct ifnet *ifp)
1660{ 1767{
1661 1768
1662 DPRINTF(("%s: entry\n", __func__)); 1769 DPRINTF(("%s: entry\n", __func__));
1663  1770
1664 struct vnet_softc *sc = ifp->if_softc; 1771 struct vnet_softc *sc = ifp->if_softc;
1665 struct ldc_map *map = sc->sc_lm; 1772 struct ldc_map *map = sc->sc_lm;
1666 struct vnet_desc_msg dm; 1773 struct vnet_desc_msg dm;
1667 struct mbuf *m; 1774 struct mbuf *m;
1668 paddr_t pa; 1775 paddr_t pa;
1669 unsigned char *buf; 1776 unsigned char *buf;
1670 u_int prod, count; 1777 u_int prod, count;
1671 1778
1672 for (;;) { 1779 for (;;) {
1673 count = sc->sc_tx_prod - sc->sc_tx_cons; 1780 count = sc->sc_tx_prod - sc->sc_tx_cons;
1674 if (count >= (sc->sc_vd->vd_nentries - 1) || 1781 if (count >= (sc->sc_vd->vd_nentries - 1) ||
1675 map->lm_count >= map->lm_nentries) { 1782 map->lm_count >= map->lm_nentries) {
1676#if 0 1783#if 0
1677FIXME openbsd  1784FIXME openbsd
1678 ifq_set_oactive(&ifp->if_snd); 1785 ifq_set_oactive(&ifp->if_snd);
1679#else 1786#else
1680 ifp->if_flags |= IFF_OACTIVE; 1787 ifp->if_flags |= IFF_OACTIVE;
1681#endif  1788#endif
1682 return; 1789 return;
1683 } 1790 }
1684 1791
1685 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO); 1792 buf = pool_get(&sc->sc_pool, PR_NOWAIT|PR_ZERO);
1686 if (buf == NULL) { 1793 if (buf == NULL) {
1687#if 0 1794#if 0
1688FIXME openbsd  1795FIXME openbsd
1689 ifq_set_oactive(&ifp->if_snd); 1796 ifq_set_oactive(&ifp->if_snd);
1690#else 1797#else
1691 ifp->if_flags |= IFF_OACTIVE; 1798 ifp->if_flags |= IFF_OACTIVE;
1692#endif  1799#endif
1693 return; 1800 return;
1694 } 1801 }
1695 1802
1696#if 0 1803#if 0
1697FIXME openbsd  1804FIXME openbsd
1698 m = ifq_dequeue(&ifp->if_snd); 1805 m = ifq_dequeue(&ifp->if_snd);
1699#else 1806#else
1700 IFQ_DEQUEUE(&ifp->if_snd, m); 1807 IFQ_DEQUEUE(&ifp->if_snd, m);
1701#endif  1808#endif
1702  1809
1703 if (m == NULL) { 1810 if (m == NULL) {
1704 pool_put(&sc->sc_pool, buf); 1811 pool_put(&sc->sc_pool, buf);
1705 return; 1812 return;
1706 } 1813 }
1707 1814
1708 m_copydata(m, 0, m->m_pkthdr.len, buf); 1815 m_copydata(m, 0, m->m_pkthdr.len, buf);
1709 1816
1710#if NBPFILTER > 0 1817#if NBPFILTER > 0
1711 /* 1818 /*
1712 * If BPF is listening on this interface, let it see the 1819 * If BPF is listening on this interface, let it see the
1713 * packet before we commit it to the wire. 1820 * packet before we commit it to the wire.
1714 */ 1821 */
1715 if (ifp->if_bpf) 1822 if (ifp->if_bpf)
1716 bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT); 1823 bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT);
1717#endif 1824#endif
1718 1825
1719 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa); 1826 pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa);
1720 KASSERT((pa & ~PAGE_MASK) == (pa & LDC_MTE_RA_MASK)); 1827 KASSERT((pa & ~PAGE_MASK) == (pa & LDC_MTE_RA_MASK));
1721 while (map->lm_slot[map->lm_next].entry != 0) { 1828 while (map->lm_slot[map->lm_next].entry != 0) {
1722 map->lm_next++; 1829 map->lm_next++;
1723 map->lm_next &= (map->lm_nentries - 1); 1830 map->lm_next &= (map->lm_nentries - 1);
1724 } 1831 }
1725 map->lm_slot[map->lm_next].entry = (pa & LDC_MTE_RA_MASK); 1832 map->lm_slot[map->lm_next].entry = (pa & LDC_MTE_RA_MASK);
1726 map->lm_slot[map->lm_next].entry |= LDC_MTE_CPR; 1833 map->lm_slot[map->lm_next].entry |= LDC_MTE_CPR;
1727#if 0 1834#if 0
1728FIXME openbsd  1835FIXME openbsd
1729 atomic_inc_int(&map->lm_count); 1836 atomic_inc_int(&map->lm_count);
1730#else 1837#else
1731 map->lm_count++; 1838 map->lm_count++;
1732#endif 1839#endif
1733 1840
1734 prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1); 1841 prod = sc->sc_tx_prod & (sc->sc_vd->vd_nentries - 1);
1735 sc->sc_vsd[prod].vsd_map_idx = map->lm_next; 1842 sc->sc_vsd[prod].vsd_map_idx = map->lm_next;
1736 sc->sc_vsd[prod].vsd_buf = buf; 1843 sc->sc_vsd[prod].vsd_buf = buf;
1737 1844
1738 bzero(&dm, sizeof(dm)); 1845 bzero(&dm, sizeof(dm));
1739 dm.tag.type = VIO_TYPE_DATA; 1846 dm.tag.type = VIO_TYPE_DATA;
1740 dm.tag.stype = VIO_SUBTYPE_INFO; 1847 dm.tag.stype = VIO_SUBTYPE_INFO;
1741 dm.tag.stype_env = VIO_DESC_DATA; 1848 dm.tag.stype_env = VIO_DESC_DATA;
1742 dm.tag.sid = sc->sc_local_sid; 1849 dm.tag.sid = sc->sc_local_sid;
1743 dm.seq_no = sc->sc_seq_no++; 1850 dm.seq_no = sc->sc_seq_no++;
1744 dm.desc_handle = sc->sc_tx_prod; 1851 dm.desc_handle = sc->sc_tx_prod;
1745#if 0 1852#if 0
1746FIXME openbsd  1853FIXME openbsd
1747 dm.nbytes = max(m->m_pkthdr.len, 60); 1854 dm.nbytes = max(m->m_pkthdr.len, 60);
1748#else 1855#else
1749 dm.nbytes = MAX(m->m_pkthdr.len, 60); 1856 dm.nbytes = MAX(m->m_pkthdr.len, 60);
1750#endif  1857#endif
1751 dm.ncookies = 1; 1858 dm.ncookies = 1;
1752 dm.cookie[0].addr = 1859 dm.cookie[0].addr =
1753 map->lm_next << PAGE_SHIFT | (pa & PAGE_MASK); 1860 map->lm_next << PAGE_SHIFT | (pa & PAGE_MASK);
1754 dm.cookie[0].size = 2048; 1861 dm.cookie[0].size = 2048;
1755 vnet_sendmsg(sc, &dm, sizeof(dm)); 1862 vnet_sendmsg(sc, &dm, sizeof(dm));
1756 1863
1757 sc->sc_tx_prod++; 1864 sc->sc_tx_prod++;
1758 sc->sc_tx_prod &= (sc->sc_vd->vd_nentries - 1); 1865 sc->sc_tx_prod &= (sc->sc_vd->vd_nentries - 1);
1759 1866
1760 m_freem(m); 1867 m_freem(m);
1761 } 1868 }
1762} 1869}
1763 1870
1764int 1871int
1765vnet_ioctl(struct ifnet *ifp, u_long cmd, void* data) 1872vnet_ioctl(struct ifnet *ifp, u_long cmd, void* data)
1766{ 1873{
1767#if 0 1874#if 0
1768 DPRINTF(("%s: entry\n", __func__)); 1875 DPRINTF(("%s: entry\n", __func__));
1769#endif  1876#endif
1770 struct vnet_softc *sc = ifp->if_softc; 1877 struct vnet_softc *sc = ifp->if_softc;
1771 struct ifreq *ifr = (struct ifreq *)data; 1878 struct ifreq *ifr = (struct ifreq *)data;
1772 int s, error = 0; 1879 int s, error = 0;
1773 1880
1774 s = splnet(); 1881 s = splnet();
1775 1882
1776 switch (cmd) { 1883 switch (cmd) {
1777 1884
1778 case SIOCSIFADDR: 1885 case SIOCSIFADDR:
1779 ifp->if_flags |= IFF_UP; 1886 ifp->if_flags |= IFF_UP;
1780 /* FALLTHROUGH */ 1887 /* FALLTHROUGH */
1781 case SIOCSIFFLAGS: 1888 case SIOCSIFFLAGS:
1782 if (ifp->if_flags & IFF_UP) { 1889 if (ifp->if_flags & IFF_UP) {
1783 if ((ifp->if_flags & IFF_RUNNING) == 0) 1890 if ((ifp->if_flags & IFF_RUNNING) == 0)
1784 vnet_init(ifp); 1891 vnet_init(ifp);
1785 } else { 1892 } else {
1786 if (ifp->if_flags & IFF_RUNNING) 1893 if (ifp->if_flags & IFF_RUNNING)
1787 vnet_stop(ifp, 0); 1894 vnet_stop(ifp, 0);
1788 } 1895 }
1789 break; 1896 break;
1790 1897
1791 case SIOCGIFMEDIA: 1898 case SIOCGIFMEDIA:
1792 case SIOCSIFMEDIA: 1899 case SIOCSIFMEDIA:
1793 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd); 1900 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
1794 break; 1901 break;
1795 1902
1796 case SIOCADDMULTI: 1903 case SIOCADDMULTI:
1797 case SIOCDELMULTI: 1904 case SIOCDELMULTI:
1798 /* 1905 /*
1799 * XXX Removing all multicast addresses and adding 1906 * XXX Removing all multicast addresses and adding
1800 * most of them back, is somewhat retarded. 1907 * most of them back, is somewhat retarded.
1801 */ 1908 */
1802 vnet_setmulti(sc, 0); 1909 vnet_setmulti(sc, 0);
1803 error = ether_ioctl(ifp, cmd, data); 1910 error = ether_ioctl(ifp, cmd, data);
1804 vnet_setmulti(sc, 1); 1911 vnet_setmulti(sc, 1);
1805 if (error == ENETRESET) 1912 if (error == ENETRESET)
1806 error = 0; 1913 error = 0;
1807 break; 1914 break;
1808 1915
1809 default: 1916 default:
1810 error = ether_ioctl(ifp, cmd, data); 1917 error = ether_ioctl(ifp, cmd, data);
1811 } 1918 }
1812 1919
1813 splx(s); 1920 splx(s);
1814 1921
1815 return (error); 1922 return (error);
1816} 1923}
1817 1924
1818void 1925void
1819vnet_watchdog(struct ifnet *ifp) 1926vnet_watchdog(struct ifnet *ifp)
1820{ 1927{
1821 1928
1822 DPRINTF(("%s: entry\n", __func__)); 1929 DPRINTF(("%s: entry\n", __func__));
1823  1930
1824 struct vnet_softc *sc = ifp->if_softc; 1931 struct vnet_softc *sc = ifp->if_softc;
1825 1932
1826 printf("%s: watchdog timeout\n", sc->sc_dv.dv_xname); 1933 printf("%s: watchdog timeout\n", sc->sc_dv.dv_xname);
1827} 1934}
1828 1935
1829int 1936int
1830vnet_media_change(struct ifnet *ifp) 1937vnet_media_change(struct ifnet *ifp)
1831{ 1938{
1832 1939#if 0
1833 DPRINTF(("%s: entry\n", __func__)); 1940 DPRINTF(("%s: entry\n", __func__));
 1941#endif
1834  1942
1835 return (0); 1943 return (0);
1836} 1944}
1837 1945
1838void 1946void
1839vnet_media_status(struct ifnet *ifp, struct ifmediareq *imr) 1947vnet_media_status(struct ifnet *ifp, struct ifmediareq *imr)
1840{ 1948{
1841 1949#if 0
1842 DPRINTF(("%s: entry\n", __func__)); 1950 DPRINTF(("%s: entry\n", __func__));
 1951#endif
1843  1952
1844 imr->ifm_active = IFM_ETHER | IFM_AUTO; 1953 imr->ifm_active = IFM_ETHER | IFM_AUTO;
1845 imr->ifm_status = IFM_AVALID; 1954 imr->ifm_status = IFM_AVALID;
1846#if 0 1955#if 0
1847FIXME openbsd  1956FIXME openbsd
1848 if (LINK_STATE_IS_UP(ifp->if_link_state) && 1957 if (LINK_STATE_IS_UP(ifp->if_link_state) &&
1849#else 1958#else
1850 if (ifp->if_link_state == LINK_STATE_UP && 1959 if (ifp->if_link_state == LINK_STATE_UP &&
1851#endif  1960#endif
1852 ifp->if_flags & IFF_UP) 1961 ifp->if_flags & IFF_UP)
1853 imr->ifm_status |= IFM_ACTIVE; 1962 imr->ifm_status |= IFM_ACTIVE;
1854} 1963}
1855 1964
1856void 1965void
1857vnet_link_state(struct vnet_softc *sc) 1966vnet_link_state(struct vnet_softc *sc)
1858{ 1967{
1859#if 0 1968#if 0
1860 DPRINTF(("%s: entry\n", __func__)); 1969 DPRINTF(("%s: entry\n", __func__));
1861#endif  1970#endif
1862  1971
1863#if 0 1972#if 0
1864FIXME openbsd  1973FIXME openbsd
1865 struct ifnet *ifp = &sc->sc_ac.ac_if; 1974 struct ifnet *ifp = &sc->sc_ac.ac_if;
1866#else 1975#else
1867 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 1976 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1868#endif  1977#endif
1869 int link_state = LINK_STATE_DOWN; 1978 int link_state = LINK_STATE_DOWN;
1870 1979
1871#if 0 1980#if 0
1872FIXME openbsd  1981FIXME openbsd
1873 KERNEL_LOCK(); 1982 KERNEL_LOCK();
1874#else 1983#else
1875 KERNEL_LOCK(1, curlwp); 1984 KERNEL_LOCK(1, curlwp);
1876#endif  1985#endif
1877 if (ISSET(sc->sc_vio_state, VIO_RCV_RDX) && 1986 if (ISSET(sc->sc_vio_state, VIO_RCV_RDX) &&
1878 ISSET(sc->sc_vio_state, VIO_ACK_RDX)) 1987 ISSET(sc->sc_vio_state, VIO_ACK_RDX))
1879#if 0 1988#if 0
1880FIXME openbsd  1989FIXME openbsd
1881 link_state = LINK_STATE_FULL_DUPLEX; 1990 link_state = LINK_STATE_FULL_DUPLEX;
1882#else 1991#else
1883 link_state = LINK_STATE_UP; 1992 link_state = LINK_STATE_UP;
1884#endif  1993#endif
1885 if (ifp->if_link_state != link_state) { 1994 if (ifp->if_link_state != link_state) {
1886#if 0 1995#if 0
1887FIXME openbsd  1996FIXME openbsd
1888 ifp->if_link_state = link_state; 1997 ifp->if_link_state = link_state;
1889 if_link_state_change(ifp); 1998 if_link_state_change(ifp);
1890#else 1999#else
1891 if_link_state_change(ifp, link_state); 2000 if_link_state_change(ifp, link_state);
1892#endif  2001#endif
1893 } 2002 }
1894#if 0 2003#if 0
1895FIXME openbsd  2004FIXME openbsd
1896 KERNEL_UNLOCK(); 2005 KERNEL_UNLOCK();
1897#else 2006#else
1898 KERNEL_UNLOCK_ONE(curlwp); 2007 KERNEL_UNLOCK_ONE(curlwp);
1899#endif  2008#endif
1900} 2009}
1901 2010
1902void 2011void
1903vnet_setmulti(struct vnet_softc *sc, int set) 2012vnet_setmulti(struct vnet_softc *sc, int set)
1904{ 2013{
1905#if 0 2014#if 0
1906 DPRINTF(("%s: entry\n", __func__)); 2015 DPRINTF(("%s: entry\n", __func__));
1907#endif  2016#endif
1908 struct ethercom *ec = &sc->sc_ethercom; 2017 struct ethercom *ec = &sc->sc_ethercom;
1909 struct ether_multi *enm; 2018 struct ether_multi *enm;
1910 struct ether_multistep step; 2019 struct ether_multistep step;
1911 struct vnet_mcast_info mi; 2020 struct vnet_mcast_info mi;
1912 int count = 0; 2021 int count = 0;
1913 2022
1914 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) || 2023 if (!ISSET(sc->sc_vio_state, VIO_RCV_RDX) ||
1915 !ISSET(sc->sc_vio_state, VIO_ACK_RDX)) 2024 !ISSET(sc->sc_vio_state, VIO_ACK_RDX))
1916 return; 2025 return;
1917 2026
1918 bzero(&mi, sizeof(mi)); 2027 bzero(&mi, sizeof(mi));
1919 mi.tag.type = VIO_TYPE_CTRL; 2028 mi.tag.type = VIO_TYPE_CTRL;
1920 mi.tag.stype = VIO_SUBTYPE_INFO; 2029 mi.tag.stype = VIO_SUBTYPE_INFO;
1921 mi.tag.stype_env = VNET_MCAST_INFO; 2030 mi.tag.stype_env = VNET_MCAST_INFO;
1922 mi.tag.sid = sc->sc_local_sid; 2031 mi.tag.sid = sc->sc_local_sid;
1923 mi.set = set ? 1 : 0; 2032 mi.set = set ? 1 : 0;
1924#if 0 2033#if 0
1925FIXME openbsd  2034FIXME openbsd
1926 KERNEL_LOCK(); 2035 KERNEL_LOCK();
1927#else 2036#else
1928 KERNEL_LOCK(1, curlwp); 2037 KERNEL_LOCK(1, curlwp);
1929#endif  2038#endif
1930 ETHER_FIRST_MULTI(step, ec, enm); 2039 ETHER_FIRST_MULTI(step, ec, enm);
1931 while (enm != NULL) { 2040 while (enm != NULL) {
1932 /* XXX What about multicast ranges? */ 2041 /* XXX What about multicast ranges? */
1933 bcopy(enm->enm_addrlo, mi.mcast_addr[count], ETHER_ADDR_LEN); 2042 bcopy(enm->enm_addrlo, mi.mcast_addr[count], ETHER_ADDR_LEN);
1934 ETHER_NEXT_MULTI(step, enm); 2043 ETHER_NEXT_MULTI(step, enm);
1935 2044
1936 count++; 2045 count++;
1937 if (count < VNET_NUM_MCAST) 2046 if (count < VNET_NUM_MCAST)
1938 continue; 2047 continue;
1939 2048
1940 mi.count = VNET_NUM_MCAST; 2049 mi.count = VNET_NUM_MCAST;
1941 vnet_sendmsg(sc, &mi, sizeof(mi)); 2050 vnet_sendmsg(sc, &mi, sizeof(mi));
1942 count = 0; 2051 count = 0;
1943 } 2052 }
1944 2053
1945 if (count > 0) { 2054 if (count > 0) {
1946 mi.count = count; 2055 mi.count = count;
1947 vnet_sendmsg(sc, &mi, sizeof(mi)); 2056 vnet_sendmsg(sc, &mi, sizeof(mi));
1948 } 2057 }
1949#if 0 2058#if 0
1950FIXME openbsd  2059FIXME openbsd
1951 KERNEL_UNLOCK(); 2060 KERNEL_UNLOCK();
1952#else 2061#else
1953 KERNEL_UNLOCK_ONE(curlwp); 2062 KERNEL_UNLOCK_ONE(curlwp);
1954#endif  2063#endif
1955} 2064}
1956 2065
1957 2066
1958int 2067int
1959vnet_init(struct ifnet *ifp) 2068vnet_init(struct ifnet *ifp)
1960{ 2069{
1961#if 0 2070#if 0
1962 DPRINTF(("%s: entry\n", __func__)); 2071 DPRINTF(("%s: entry\n", __func__));
1963#endif  2072#endif
1964  2073
1965 struct vnet_softc *sc = ifp->if_softc; 2074 struct vnet_softc *sc = ifp->if_softc;
1966 struct ldc_conn *lc = &sc->sc_lc; 2075 struct ldc_conn *lc = &sc->sc_lc;
1967 int err; 2076 int err;
1968 vaddr_t va; 2077 vaddr_t va;
1969 paddr_t pa; 2078 paddr_t pa;
1970#if OPENBSD_BUSDMA 2079#if OPENBSD_BUSDMA
1971 sc->sc_lm = ldc_map_alloc(sc->sc_dmatag, 2048); 2080 sc->sc_lm = ldc_map_alloc(sc->sc_dmatag, 2048);
1972#else  2081#else
1973 sc->sc_lm = ldc_map_alloc(2048); 2082 sc->sc_lm = ldc_map_alloc(2048);
1974#endif  2083#endif
1975 if (sc->sc_lm == NULL) 2084 if (sc->sc_lm == NULL)
1976 return ENOMEM; 2085 return ENOMEM;
1977 2086
1978#if OPENBSD_BUSDMA 2087#if OPENBSD_BUSDMA
1979 err = hv_ldc_set_map_table(lc->lc_id, 2088 err = hv_ldc_set_map_table(lc->lc_id,
1980 sc->sc_lm->lm_map->dm_segs[0].ds_addr, sc->sc_lm->lm_nentries); 2089 sc->sc_lm->lm_map->dm_segs[0].ds_addr, sc->sc_lm->lm_nentries);
1981#else 2090#else
1982 va = (vaddr_t)sc->sc_lm->lm_slot; 2091 va = (vaddr_t)sc->sc_lm->lm_slot;
1983 pa = 0; 2092 pa = 0;
1984 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) 2093 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE)
1985 panic("pmap_extract failed %lx\n", va); 2094 panic("pmap_extract failed %lx\n", va);
1986 err = hv_ldc_set_map_table(lc->lc_id, pa, 2048); 2095 err = hv_ldc_set_map_table(lc->lc_id, pa, 2048);
1987#endif  2096#endif
1988 if (err != H_EOK) { 2097 if (err != H_EOK) {
1989 printf("hv_ldc_set_map_table %d\n", err); 2098 printf("hv_ldc_set_map_table %d\n", err);
1990 return EINVAL; 2099 return EINVAL;
1991 } 2100 }
1992 2101
1993 sc->sc_vd = vnet_dring_alloc(sc->sc_dmatag, VNET_NUM_SOFT_DESC); 2102 sc->sc_vd = vnet_dring_alloc(sc->sc_dmatag, VNET_NUM_SOFT_DESC);
1994 if (sc->sc_vd == NULL) 2103 if (sc->sc_vd == NULL)
1995 return ENOMEM; 2104 return ENOMEM;
1996 sc->sc_vsd = malloc(VNET_NUM_SOFT_DESC * sizeof(*sc->sc_vsd), M_DEVBUF, 2105 sc->sc_vsd = malloc(VNET_NUM_SOFT_DESC * sizeof(*sc->sc_vsd), M_DEVBUF,
1997 M_NOWAIT|M_ZERO); 2106 M_NOWAIT|M_ZERO);
1998 if (sc->sc_vsd == NULL) 2107 if (sc->sc_vsd == NULL)
1999 return ENOMEM; 2108 return ENOMEM;
2000 2109
2001#if OPENBSD_BUSDMA 2110#if OPENBSD_BUSDMA
2002 sc->sc_lm->lm_slot[0].entry = sc->sc_vd->vd_map->dm_segs[0].ds_addr; 2111 sc->sc_lm->lm_slot[0].entry = sc->sc_vd->vd_map->dm_segs[0].ds_addr;
2003#else 2112#else
2004 va = (vaddr_t)sc->sc_vd->vd_desc; 2113 va = (vaddr_t)sc->sc_vd->vd_desc;
2005 pa = 0; 2114 pa = 0;
2006 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) 2115 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE)
2007 panic("pmap_extract failed %lx\n", va); 2116 panic("pmap_extract failed %lx\n", va);
2008 sc->sc_lm->lm_slot[0].entry = pa; 2117 sc->sc_lm->lm_slot[0].entry = pa;
2009#endif  2118#endif
2010 sc->sc_lm->lm_slot[0].entry &= LDC_MTE_RA_MASK; 2119 sc->sc_lm->lm_slot[0].entry &= LDC_MTE_RA_MASK;
2011 sc->sc_lm->lm_slot[0].entry |= LDC_MTE_CPR | LDC_MTE_CPW; 2120 sc->sc_lm->lm_slot[0].entry |= LDC_MTE_CPR | LDC_MTE_CPW;
2012 sc->sc_lm->lm_next = 1; 2121 sc->sc_lm->lm_next = 1;
2013 sc->sc_lm->lm_count = 1; 2122 sc->sc_lm->lm_count = 1;
2014  2123
2015 va = lc->lc_txq->lq_va; 2124 va = lc->lc_txq->lq_va;
2016 pa = 0; 2125 pa = 0;
2017 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) 2126 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE)
2018 panic("pmap_extract failed %lx\n", va); 2127 panic("pmap_extract failed %lx\n", va);
2019#if OPENBSD_BUSDMA 2128#if OPENBSD_BUSDMA
2020 err = hv_ldc_tx_qconf(lc->lc_id, 2129 err = hv_ldc_tx_qconf(lc->lc_id,
2021 lc->lc_txq->lq_map->dm_segs[0].ds_addr, lc->lc_txq->lq_nentries); 2130 lc->lc_txq->lq_map->dm_segs[0].ds_addr, lc->lc_txq->lq_nentries);
2022#else 2131#else
2023 err = hv_ldc_tx_qconf(lc->lc_id, pa, lc->lc_txq->lq_nentries); 2132 err = hv_ldc_tx_qconf(lc->lc_id, pa, lc->lc_txq->lq_nentries);
2024#endif  2133#endif
2025 if (err != H_EOK) 2134 if (err != H_EOK)
2026 printf("hv_ldc_tx_qconf %d\n", err); 2135 printf("hv_ldc_tx_qconf %d\n", err);
2027  2136
2028 va = (vaddr_t)lc->lc_rxq->lq_va; 2137 va = (vaddr_t)lc->lc_rxq->lq_va;
2029 pa = 0; 2138 pa = 0;
2030 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) 2139 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE)
2031 panic("pmap_extract failed %lx\n", va); 2140 panic("pmap_extract failed %lx\n", va);
2032 2141
2033#if OPENBSD_BUSDMA 2142#if OPENBSD_BUSDMA
2034 err = hv_ldc_rx_qconf(lc->lc_id, 2143 err = hv_ldc_rx_qconf(lc->lc_id,
2035 lc->lc_rxq->lq_map->dm_segs[0].ds_addr, lc->lc_rxq->lq_nentries); 2144 lc->lc_rxq->lq_map->dm_segs[0].ds_addr, lc->lc_rxq->lq_nentries);
2036#else 2145#else
2037 err = hv_ldc_rx_qconf(lc->lc_id, pa, lc->lc_rxq->lq_nentries); 2146 err = hv_ldc_rx_qconf(lc->lc_id, pa, lc->lc_rxq->lq_nentries);
2038#endif  2147#endif
2039 if (err != H_EOK) 2148 if (err != H_EOK)
2040 printf("hv_ldc_rx_qconf %d\n", err); 2149 printf("hv_ldc_rx_qconf %d\n", err);
2041 2150
2042 cbus_intr_setenabled(sc->sc_bustag, sc->sc_tx_ino, INTR_ENABLED); 2151 cbus_intr_setenabled(sc->sc_bustag, sc->sc_tx_ino, INTR_ENABLED);
2043 cbus_intr_setenabled(sc->sc_bustag, sc->sc_rx_ino, INTR_ENABLED); 2152 cbus_intr_setenabled(sc->sc_bustag, sc->sc_rx_ino, INTR_ENABLED);
2044 2153
2045 ldc_send_vers(lc); 2154 ldc_send_vers(lc);
2046 2155
2047 ifp->if_flags |= IFF_RUNNING; 2156 ifp->if_flags |= IFF_RUNNING;
2048 2157
2049#if 0  2158#if 0
2050 DPRINTF(("%s: exit\n", __func__)); 2159 DPRINTF(("%s: exit\n", __func__));
2051#endif  2160#endif
2052 return 0; 2161 return 0;
2053} 2162}
2054 2163
2055void 2164void
2056vnet_stop(struct ifnet *ifp, int disable) 2165vnet_stop(struct ifnet *ifp, int disable)
2057  2166
2058{ 2167{
2059 2168
2060 DPRINTF(("%s: entry\n", __func__)); 2169 DPRINTF(("%s: entry\n", __func__));
2061  2170
2062 struct vnet_softc *sc = ifp->if_softc; 2171 struct vnet_softc *sc = ifp->if_softc;
2063 struct ldc_conn *lc = &sc->sc_lc; 2172 struct ldc_conn *lc = &sc->sc_lc;
2064 2173
2065 /* FIXME */ 2174 /* FIXME */
2066 printf("vnet_stop() disable %d\n", disable); 2175 printf("vnet_stop() disable %d\n", disable);
2067  2176
2068 ifp->if_flags &= ~IFF_RUNNING; 2177 ifp->if_flags &= ~IFF_RUNNING;
2069#if 0 2178#if 0
2070FIXME openbsd  2179FIXME openbsd
2071 ifq_clr_oactive(&ifp->if_snd); 2180 ifq_clr_oactive(&ifp->if_snd);
2072#else 2181#else
2073 ifp->if_flags &= ~IFF_OACTIVE; 2182 ifp->if_flags &= ~IFF_OACTIVE;
2074#endif  2183#endif
2075 ifp->if_timer = 0; 2184 ifp->if_timer = 0;
2076 2185
2077 cbus_intr_setenabled(sc->sc_bustag, sc->sc_tx_ino, INTR_DISABLED); 2186 cbus_intr_setenabled(sc->sc_bustag, sc->sc_tx_ino, INTR_DISABLED);
2078 cbus_intr_setenabled(sc->sc_bustag, sc->sc_rx_ino, INTR_DISABLED); 2187 cbus_intr_setenabled(sc->sc_bustag, sc->sc_rx_ino, INTR_DISABLED);
2079 2188
2080#if 0 2189#if 0
2081FIXME openbsd 2190FIXME openbsd
2082 intr_barrier(sc->sc_tx_ih); 2191 intr_barrier(sc->sc_tx_ih);
2083 intr_barrier(sc->sc_rx_ih); 2192 intr_barrier(sc->sc_rx_ih);
2084#else 2193#else
2085 printf("vnet_stop() intr_barrier() FIXME\n"); 2194 printf("vnet_stop() intr_barrier() FIXME\n");
2086#endif  2195#endif
2087 2196
2088 hv_ldc_tx_qconf(lc->lc_id, 0, 0); 2197 hv_ldc_tx_qconf(lc->lc_id, 0, 0);
2089 hv_ldc_rx_qconf(lc->lc_id, 0, 0); 2198 hv_ldc_rx_qconf(lc->lc_id, 0, 0);
2090 lc->lc_tx_seqid = 0; 2199 lc->lc_tx_seqid = 0;
2091 lc->lc_state = 0; 2200 lc->lc_state = 0;
2092 lc->lc_tx_state = lc->lc_rx_state = LDC_CHANNEL_DOWN; 2201 lc->lc_tx_state = lc->lc_rx_state = LDC_CHANNEL_DOWN;
2093 vnet_ldc_reset(lc); 2202 vnet_ldc_reset(lc);
2094 2203
2095#if 0 2204#if 0
2096FIXME openbsd  2205FIXME openbsd
2097 free(sc->sc_vsd, M_DEVBUF, VNET_NUM_SOFT_DESC * sizeof(*sc->sc_vsd)); 2206 free(sc->sc_vsd, M_DEVBUF, VNET_NUM_SOFT_DESC * sizeof(*sc->sc_vsd));
2098#else 2207#else
2099 free(sc->sc_vsd, M_DEVBUF); 2208 free(sc->sc_vsd, M_DEVBUF);
2100#endif  2209#endif
2101 2210
2102 vnet_dring_free(sc->sc_dmatag, sc->sc_vd); 2211 vnet_dring_free(sc->sc_dmatag, sc->sc_vd);
2103 2212
2104 hv_ldc_set_map_table(lc->lc_id, 0, 0); 2213 hv_ldc_set_map_table(lc->lc_id, 0, 0);
2105#if OPENBSD_BUSDMA 2214#if OPENBSD_BUSDMA
2106 ldc_map_free(sc->sc_dmatag, sc->sc_lm); 2215 ldc_map_free(sc->sc_dmatag, sc->sc_lm);
2107#else 2216#else
2108 ldc_map_free(sc->sc_lm); 2217 ldc_map_free(sc->sc_lm);
2109#endif  2218#endif
2110} 2219}
2111 2220
2112struct vnet_dring * 2221struct vnet_dring *
2113vnet_dring_alloc(bus_dma_tag_t t, int nentries) 2222vnet_dring_alloc(bus_dma_tag_t t, int nentries)
2114{ 2223{
2115#if 0 2224#if 0
2116 DPRINTF(("%s: entry\n", __func__)); 2225 DPRINTF(("%s: entry\n", __func__));
2117#endif  2226#endif
2118  2227
2119 struct vnet_dring *vd; 2228 struct vnet_dring *vd;
2120 bus_size_t size; 2229 bus_size_t size;
2121 vaddr_t va; 2230 vaddr_t va;
2122#if OPENBSD_BUSDMA 2231#if OPENBSD_BUSDMA
2123 int nsegs; 2232 int nsegs;
2124#endif  2233#endif
2125 int i; 2234 int i;
2126 2235
2127 vd = kmem_zalloc(sizeof(struct vnet_dring), KM_SLEEP); 2236 vd = kmem_zalloc(sizeof(struct vnet_dring), KM_SLEEP);
2128 if (vd == NULL) 2237 if (vd == NULL)
2129 return NULL; 2238 return NULL;
2130 2239
2131 size = roundup(nentries * sizeof(struct vnet_desc), PAGE_SIZE); 2240 size = roundup(nentries * sizeof(struct vnet_desc), PAGE_SIZE);
2132 2241
2133#if OPENBSD_BUSDMA 2242#if OPENBSD_BUSDMA
2134 if (bus_dmamap_create(t, size, 1, size, 0, 2243 if (bus_dmamap_create(t, size, 1, size, 0,
2135 BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &vd->vd_map) != 0) 2244 BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &vd->vd_map) != 0)
2136 return (NULL); 2245 return (NULL);
2137 2246
2138 if (bus_dmamem_alloc(t, size, PAGE_SIZE, 0, &vd->vd_seg, 1, 2247 if (bus_dmamem_alloc(t, size, PAGE_SIZE, 0, &vd->vd_seg, 1,
2139 &nsegs, BUS_DMA_NOWAIT) != 0) 2248 &nsegs, BUS_DMA_NOWAIT) != 0)
2140 goto destroy; 2249 goto destroy;
2141 2250
2142 if (bus_dmamem_map(t, &vd->vd_seg, 1, size, &va, 2251 if (bus_dmamem_map(t, &vd->vd_seg, 1, size, &va,
2143 BUS_DMA_NOWAIT) != 0) 2252 BUS_DMA_NOWAIT) != 0)
2144 goto free; 2253 goto free;
2145 2254
2146 if (bus_dmamap_load(t, vd->vd_map, va, size, NULL, 2255 if (bus_dmamap_load(t, vd->vd_map, va, size, NULL,
2147 BUS_DMA_NOWAIT) != 0) 2256 BUS_DMA_NOWAIT) != 0)
2148 goto unmap; 2257 goto unmap;
2149#else 2258#else
2150 va = (vaddr_t)kmem_zalloc(size, KM_SLEEP); 2259 va = (vaddr_t)kmem_zalloc(size, KM_SLEEP);
2151#endif  2260#endif
2152 vd->vd_desc = (struct vnet_desc *)va; 2261 vd->vd_desc = (struct vnet_desc *)va;
2153 vd->vd_nentries = nentries; 2262 vd->vd_nentries = nentries;
2154 bzero(vd->vd_desc, nentries * sizeof(struct vnet_desc)); 2263 bzero(vd->vd_desc, nentries * sizeof(struct vnet_desc));
2155 for (i = 0; i < vd->vd_nentries; i++) 2264 for (i = 0; i < vd->vd_nentries; i++)
2156 vd->vd_desc[i].hdr.dstate = VIO_DESC_FREE; 2265 vd->vd_desc[i].hdr.dstate = VIO_DESC_FREE;
2157 return (vd); 2266 return (vd);
2158 2267
2159#if OPENBSD_BUSDMA 2268#if OPENBSD_BUSDMA
2160unmap: 2269unmap:
2161 bus_dmamem_unmap(t, va, size); 2270 bus_dmamem_unmap(t, va, size);
2162free: 2271free:
2163 bus_dmamem_free(t, &vd->vd_seg, 1); 2272 bus_dmamem_free(t, &vd->vd_seg, 1);
2164destroy: 2273destroy:
2165 bus_dmamap_destroy(t, vd->vd_map); 2274 bus_dmamap_destroy(t, vd->vd_map);
2166#endif 2275#endif
2167 return (NULL); 2276 return (NULL);
2168} 2277}
2169 2278
2170void 2279void
2171vnet_dring_free(bus_dma_tag_t t, struct vnet_dring *vd) 2280vnet_dring_free(bus_dma_tag_t t, struct vnet_dring *vd)
2172{ 2281{
2173 2282
2174 DPRINTF(("%s: entry\n", __func__)); 2283 DPRINTF(("%s: entry\n", __func__));
2175  2284
2176 bus_size_t size; 2285 bus_size_t size;
2177 2286
2178 size = vd->vd_nentries * sizeof(struct vnet_desc); 2287 size = vd->vd_nentries * sizeof(struct vnet_desc);
2179 size = roundup(size, PAGE_SIZE); 2288 size = roundup(size, PAGE_SIZE);
2180 2289
2181#if OPENBSD_BUSDMA 2290#if OPENBSD_BUSDMA
2182 bus_dmamap_unload(t, vd->vd_map); 2291 bus_dmamap_unload(t, vd->vd_map);
2183 bus_dmamem_unmap(t, (caddr_t)vd->vd_desc, size); 2292 bus_dmamem_unmap(t, (caddr_t)vd->vd_desc, size);
2184 bus_dmamem_free(t, &vd->vd_seg, 1); 2293 bus_dmamem_free(t, &vd->vd_seg, 1);
2185 bus_dmamap_destroy(t, vd->vd_map); 2294 bus_dmamap_destroy(t, vd->vd_map);
2186#else  2295#else
2187 kmem_free(vd->vd_desc, size); 2296 kmem_free(vd->vd_desc, size);
2188#endif  2297#endif
2189 kmem_free(vd, size); 2298 kmem_free(vd, size);
2190} 2299}
2191 2300