Deleted Added
full compact
if_an.c (108259) if_an.c (108401)
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: head/sys/dev/an/if_an.c 108259 2002-12-24 14:46:01Z rwatson $
32 * $FreeBSD: head/sys/dev/an/if_an.c 108401 2002-12-29 19:22:07Z ambrisko $
33 */
34
35/*
36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
37 *
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City

--- 50 unchanged lines hidden (view full) ---

91#include <sys/systm.h>
92#include <sys/sockio.h>
93#include <sys/mbuf.h>
94#include <sys/proc.h>
95#include <sys/kernel.h>
96#include <sys/socket.h>
97#ifdef ANCACHE
98#include <sys/syslog.h>
33 */
34
35/*
36 * Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
37 *
38 * Written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City

--- 50 unchanged lines hidden (view full) ---

91#include <sys/systm.h>
92#include <sys/sockio.h>
93#include <sys/mbuf.h>
94#include <sys/proc.h>
95#include <sys/kernel.h>
96#include <sys/socket.h>
97#ifdef ANCACHE
98#include <sys/syslog.h>
99#include <sys/sysctl.h>
100#endif
99#endif
100#include <sys/sysctl.h>
101#include <machine/clock.h> /* for DELAY */
101
102#include <sys/module.h>
103#include <sys/sysctl.h>
104#include <sys/bus.h>
105#include <machine/bus.h>
106#include <sys/rman.h>
107#include <sys/lock.h>
108#include <sys/mutex.h>
109#include <machine/resource.h>
102
103#include <sys/module.h>
104#include <sys/sysctl.h>
105#include <sys/bus.h>
106#include <machine/bus.h>
107#include <sys/rman.h>
108#include <sys/lock.h>
109#include <sys/mutex.h>
110#include <machine/resource.h>
111#include <sys/malloc.h>
110
111#include <net/if.h>
112#include <net/if_arp.h>
113#include <net/ethernet.h>
114#include <net/if_dl.h>
115#include <net/if_types.h>
116#include <net/if_ieee80211.h>
117#include <net/if_media.h>

--- 9 unchanged lines hidden (view full) ---

127
128#include <machine/md_var.h>
129
130#include <dev/an/if_aironet_ieee.h>
131#include <dev/an/if_anreg.h>
132
133#if !defined(lint)
134static const char rcsid[] =
112
113#include <net/if.h>
114#include <net/if_arp.h>
115#include <net/ethernet.h>
116#include <net/if_dl.h>
117#include <net/if_types.h>
118#include <net/if_ieee80211.h>
119#include <net/if_media.h>

--- 9 unchanged lines hidden (view full) ---

129
130#include <machine/md_var.h>
131
132#include <dev/an/if_aironet_ieee.h>
133#include <dev/an/if_anreg.h>
134
135#if !defined(lint)
136static const char rcsid[] =
135 "$FreeBSD: head/sys/dev/an/if_an.c 108259 2002-12-24 14:46:01Z rwatson $";
137 "$FreeBSD: head/sys/dev/an/if_an.c 108401 2002-12-29 19:22:07Z ambrisko $";
136#endif
137
138/* These are global because we need them in sys/pci/if_an_p.c. */
139static void an_reset (struct an_softc *);
138#endif
139
140/* These are global because we need them in sys/pci/if_an_p.c. */
141static void an_reset (struct an_softc *);
142static int an_init_mpi350_desc (struct an_softc *);
140static int an_ioctl (struct ifnet *, u_long, caddr_t);
141static void an_init (void *);
142static int an_init_tx_ring (struct an_softc *);
143static void an_start (struct ifnet *);
144static void an_watchdog (struct ifnet *);
145static void an_rxeof (struct an_softc *);
146static void an_txeof (struct an_softc *, int);
147
148static void an_promisc (struct an_softc *, int);
149static int an_cmd (struct an_softc *, int, int);
143static int an_ioctl (struct ifnet *, u_long, caddr_t);
144static void an_init (void *);
145static int an_init_tx_ring (struct an_softc *);
146static void an_start (struct ifnet *);
147static void an_watchdog (struct ifnet *);
148static void an_rxeof (struct an_softc *);
149static void an_txeof (struct an_softc *, int);
150
151static void an_promisc (struct an_softc *, int);
152static int an_cmd (struct an_softc *, int, int);
153static int an_cmd_struct (struct an_softc *, struct an_command *,
154 struct an_reply *);
150static int an_read_record (struct an_softc *, struct an_ltv_gen *);
151static int an_write_record (struct an_softc *, struct an_ltv_gen *);
155static int an_read_record (struct an_softc *, struct an_ltv_gen *);
156static int an_write_record (struct an_softc *, struct an_ltv_gen *);
157static void an_kick (struct an_softc *);
152static int an_read_data (struct an_softc *, int, int, caddr_t, int);
153static int an_write_data (struct an_softc *, int, int, caddr_t, int);
154static int an_seek (struct an_softc *, int, int, int);
155static int an_alloc_nicmem (struct an_softc *, int, int *);
158static int an_read_data (struct an_softc *, int, int, caddr_t, int);
159static int an_write_data (struct an_softc *, int, int, caddr_t, int);
160static int an_seek (struct an_softc *, int, int, int);
161static int an_alloc_nicmem (struct an_softc *, int, int *);
162static int an_dma_malloc (struct an_softc *, bus_size_t,
163 struct an_dma_alloc *, int);
164static void an_dma_free (struct an_softc *, struct an_dma_alloc *);
165static void an_dma_malloc_cb (void *, bus_dma_segment_t *, int, int);
156static void an_stats_update (void *);
157static void an_setdef (struct an_softc *, struct an_req *);
158#ifdef ANCACHE
159static void an_cache_store (struct an_softc *, struct ether_header *,
166static void an_stats_update (void *);
167static void an_setdef (struct an_softc *, struct an_req *);
168#ifdef ANCACHE
169static void an_cache_store (struct an_softc *, struct ether_header *,
160 struct mbuf *, unsigned short);
170 struct mbuf *, u_int8_t, u_int8_t);
161#endif
162
163/* function definitions for use with the Cisco's Linux configuration
164 utilities
165*/
166
167static int readrids(struct ifnet*, struct aironet_ioctl*);
168static int writerids(struct ifnet*, struct aironet_ioctl*);

--- 10 unchanged lines hidden (view full) ---

179
180static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
181 char *);
182
183static int an_media_change (struct ifnet *);
184static void an_media_status (struct ifnet *, struct ifmediareq *);
185
186static int an_dump = 0;
171#endif
172
173/* function definitions for use with the Cisco's Linux configuration
174 utilities
175*/
176
177static int readrids(struct ifnet*, struct aironet_ioctl*);
178static int writerids(struct ifnet*, struct aironet_ioctl*);

--- 10 unchanged lines hidden (view full) ---

189
190static void an_dump_record (struct an_softc *,struct an_ltv_gen *,
191 char *);
192
193static int an_media_change (struct ifnet *);
194static void an_media_status (struct ifnet *, struct ifmediareq *);
195
196static int an_dump = 0;
197static int an_cache_mode = 0;
187
198
199#define DBM 0
200#define PERCENT 1
201#define RAW 2
202
188static char an_conf[256];
203static char an_conf[256];
204static char an_conf_cache[256];
189
190/* sysctl vars */
205
206/* sysctl vars */
207
191SYSCTL_NODE(_machdep, OID_AUTO, an, CTLFLAG_RD, 0, "dump RID");
192
193/* XXX violate ethernet/netgraph callback hooks */
194extern void (*ng_ether_attach_p)(struct ifnet *ifp);
195extern void (*ng_ether_detach_p)(struct ifnet *ifp);
196
197static int
198sysctl_an_dump(SYSCTL_HANDLER_ARGS)
199{
200 int error, r, last;
201 char *s = an_conf;
202
203 last = an_dump;
208SYSCTL_NODE(_machdep, OID_AUTO, an, CTLFLAG_RD, 0, "dump RID");
209
210/* XXX violate ethernet/netgraph callback hooks */
211extern void (*ng_ether_attach_p)(struct ifnet *ifp);
212extern void (*ng_ether_detach_p)(struct ifnet *ifp);
213
214static int
215sysctl_an_dump(SYSCTL_HANDLER_ARGS)
216{
217 int error, r, last;
218 char *s = an_conf;
219
220 last = an_dump;
204 bzero(an_conf, sizeof(an_conf));
205
206 switch (an_dump) {
207 case 0:
221
222 switch (an_dump) {
223 case 0:
208 strcat(an_conf, "off");
224 strcpy(an_conf, "off");
209 break;
210 case 1:
225 break;
226 case 1:
211 strcat(an_conf, "type");
227 strcpy(an_conf, "type");
212 break;
213 case 2:
228 break;
229 case 2:
214 strcat(an_conf, "dump");
230 strcpy(an_conf, "dump");
215 break;
216 default:
217 snprintf(an_conf, 5, "%x", an_dump);
218 break;
219 }
220
221 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
222
231 break;
232 default:
233 snprintf(an_conf, 5, "%x", an_dump);
234 break;
235 }
236
237 error = sysctl_handle_string(oidp, an_conf, sizeof(an_conf), req);
238
223 if (strncmp(an_conf,"off", 4) == 0) {
239 if (strncmp(an_conf,"off", 3) == 0) {
224 an_dump = 0;
225 }
226 if (strncmp(an_conf,"dump", 4) == 0) {
227 an_dump = 1;
228 }
229 if (strncmp(an_conf,"type", 4) == 0) {
230 an_dump = 2;
231 }

--- 14 unchanged lines hidden (view full) ---

246 printf("Sysctl changed for Aironet driver\n");
247
248 return error;
249}
250
251SYSCTL_PROC(_machdep, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
252 0, sizeof(an_conf), sysctl_an_dump, "A", "");
253
240 an_dump = 0;
241 }
242 if (strncmp(an_conf,"dump", 4) == 0) {
243 an_dump = 1;
244 }
245 if (strncmp(an_conf,"type", 4) == 0) {
246 an_dump = 2;
247 }

--- 14 unchanged lines hidden (view full) ---

262 printf("Sysctl changed for Aironet driver\n");
263
264 return error;
265}
266
267SYSCTL_PROC(_machdep, OID_AUTO, an_dump, CTLTYPE_STRING | CTLFLAG_RW,
268 0, sizeof(an_conf), sysctl_an_dump, "A", "");
269
270static int
271sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
272{
273 int error, last;
274
275 last = an_cache_mode;
276
277 switch (an_cache_mode) {
278 case 1:
279 strcpy(an_conf_cache, "per");
280 break;
281 case 2:
282 strcpy(an_conf_cache, "raw");
283 break;
284 default:
285 strcpy(an_conf_cache, "dbm");
286 break;
287 }
288
289 error = sysctl_handle_string(oidp, an_conf_cache,
290 sizeof(an_conf_cache), req);
291
292 if (strncmp(an_conf_cache,"dbm", 3) == 0) {
293 an_cache_mode = 0;
294 }
295 if (strncmp(an_conf_cache,"per", 3) == 0) {
296 an_cache_mode = 1;
297 }
298 if (strncmp(an_conf_cache,"raw", 3) == 0) {
299 an_cache_mode = 2;
300 }
301
302 return error;
303}
304
305SYSCTL_PROC(_machdep, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
306 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
307
254/*
255 * We probe for an Aironet 4500/4800 card by attempting to
256 * read the default SSID list. On reset, the first entry in
257 * the SSID list will contain the name "tsunami." If we don't
258 * find this, then there's no card present.
259 */
260int
261an_probe(dev)

--- 21 unchanged lines hidden (view full) ---

283 sc->an_bhandle = rman_get_bushandle(sc->port_res);
284 sc->an_btag = rman_get_bustag(sc->port_res);
285 sc->an_unit = device_get_unit(dev);
286
287 ssid.an_len = sizeof(ssid);
288 ssid.an_type = AN_RID_SSIDLIST;
289
290 /* Make sure interrupts are disabled. */
308/*
309 * We probe for an Aironet 4500/4800 card by attempting to
310 * read the default SSID list. On reset, the first entry in
311 * the SSID list will contain the name "tsunami." If we don't
312 * find this, then there's no card present.
313 */
314int
315an_probe(dev)

--- 21 unchanged lines hidden (view full) ---

337 sc->an_bhandle = rman_get_bushandle(sc->port_res);
338 sc->an_btag = rman_get_bustag(sc->port_res);
339 sc->an_unit = device_get_unit(dev);
340
341 ssid.an_len = sizeof(ssid);
342 ssid.an_type = AN_RID_SSIDLIST;
343
344 /* Make sure interrupts are disabled. */
291 CSR_WRITE_2(sc, AN_INT_EN, 0);
292 CSR_WRITE_2(sc, AN_EVENT_ACK, 0xFFFF);
345 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
346 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
293
294 an_reset(sc);
347
348 an_reset(sc);
349 /* No need for an_init_mpi350_desc since it will be done in attach */
295
296 if (an_cmd(sc, AN_CMD_READCFG, 0))
297 return(0);
298
299 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
300 return(0);
301
302 /* See if the ssid matches what we expect ... but doesn't have to */

--- 22 unchanged lines hidden (view full) ---

325 sc->port_res = res;
326 return (0);
327 } else {
328 return (ENOENT);
329 }
330}
331
332/*
350
351 if (an_cmd(sc, AN_CMD_READCFG, 0))
352 return(0);
353
354 if (an_read_record(sc, (struct an_ltv_gen *)&ssid))
355 return(0);
356
357 /* See if the ssid matches what we expect ... but doesn't have to */

--- 22 unchanged lines hidden (view full) ---

380 sc->port_res = res;
381 return (0);
382 } else {
383 return (ENOENT);
384 }
385}
386
387/*
388 * Allocate a memory resource with the given resource id.
389 */
390int an_alloc_memory(device_t dev, int rid, int size)
391{
392 struct an_softc *sc = device_get_softc(dev);
393 struct resource *res;
394
395 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
396 0ul, ~0ul, size, RF_ACTIVE);
397 if (res) {
398 sc->mem_rid = rid;
399 sc->mem_res = res;
400 sc->mem_used = size;
401 return (0);
402 } else {
403 return (ENOENT);
404 }
405}
406
407/*
408 * Allocate a auxilary memory resource with the given resource id.
409 */
410int an_alloc_aux_memory(device_t dev, int rid, int size)
411{
412 struct an_softc *sc = device_get_softc(dev);
413 struct resource *res;
414
415 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
416 0ul, ~0ul, size, RF_ACTIVE);
417 if (res) {
418 sc->mem_aux_rid = rid;
419 sc->mem_aux_res = res;
420 sc->mem_aux_used = size;
421 return (0);
422 } else {
423 return (ENOENT);
424 }
425}
426
427/*
333 * Allocate an irq resource with the given resource id.
334 */
335int
336an_alloc_irq(dev, rid, flags)
337 device_t dev;
338 int rid;
339 int flags;
340{

--- 6 unchanged lines hidden (view full) ---

347 sc->irq_rid = rid;
348 sc->irq_res = res;
349 return (0);
350 } else {
351 return (ENOENT);
352 }
353}
354
428 * Allocate an irq resource with the given resource id.
429 */
430int
431an_alloc_irq(dev, rid, flags)
432 device_t dev;
433 int rid;
434 int flags;
435{

--- 6 unchanged lines hidden (view full) ---

442 sc->irq_rid = rid;
443 sc->irq_res = res;
444 return (0);
445 } else {
446 return (ENOENT);
447 }
448}
449
450static void
451an_dma_malloc_cb(arg, segs, nseg, error)
452 void *arg;
453 bus_dma_segment_t *segs;
454 int nseg;
455 int error;
456{
457 bus_addr_t *paddr = (bus_addr_t*) arg;
458 *paddr = segs->ds_addr;
459}
460
355/*
461/*
462 * Alloc DMA memory and set the pointer to it
463 */
464static int
465an_dma_malloc(sc, size, dma, mapflags)
466 struct an_softc *sc;
467 bus_size_t size;
468 struct an_dma_alloc *dma;
469 int mapflags;
470{
471 int r;
472
473 r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
474 if (r != 0)
475 goto fail_0;
476
477 r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
478 BUS_DMA_NOWAIT, &dma->an_dma_map);
479 if (r != 0)
480 goto fail_1;
481
482 r = bus_dmamap_load(sc->an_dtag, dma->an_dma_map, dma->an_dma_vaddr,
483 size,
484 an_dma_malloc_cb,
485 &dma->an_dma_paddr,
486 mapflags | BUS_DMA_NOWAIT);
487 if (r != 0)
488 goto fail_2;
489
490 dma->an_dma_size = size;
491 return (0);
492
493fail_2:
494 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
495fail_1:
496 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
497fail_0:
498 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
499 dma->an_dma_map = NULL;
500 return (r);
501}
502
503static void
504an_dma_free(sc, dma)
505 struct an_softc *sc;
506 struct an_dma_alloc *dma;
507{
508 bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
509 bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
510 bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
511}
512
513/*
356 * Release all resources
357 */
358void
359an_release_resources(dev)
360 device_t dev;
361{
362 struct an_softc *sc = device_get_softc(dev);
514 * Release all resources
515 */
516void
517an_release_resources(dev)
518 device_t dev;
519{
520 struct an_softc *sc = device_get_softc(dev);
521 int i;
363
364 if (sc->port_res) {
365 bus_release_resource(dev, SYS_RES_IOPORT,
366 sc->port_rid, sc->port_res);
367 sc->port_res = 0;
368 }
522
523 if (sc->port_res) {
524 bus_release_resource(dev, SYS_RES_IOPORT,
525 sc->port_rid, sc->port_res);
526 sc->port_res = 0;
527 }
528 if (sc->mem_res) {
529 bus_release_resource(dev, SYS_RES_MEMORY,
530 sc->mem_rid, sc->mem_res);
531 sc->mem_res = 0;
532 }
533 if (sc->mem_aux_res) {
534 bus_release_resource(dev, SYS_RES_MEMORY,
535 sc->mem_aux_rid, sc->mem_aux_res);
536 sc->mem_aux_res = 0;
537 }
369 if (sc->irq_res) {
370 bus_release_resource(dev, SYS_RES_IRQ,
371 sc->irq_rid, sc->irq_res);
372 sc->irq_res = 0;
373 }
538 if (sc->irq_res) {
539 bus_release_resource(dev, SYS_RES_IRQ,
540 sc->irq_rid, sc->irq_res);
541 sc->irq_res = 0;
542 }
543 if (sc->an_rid_buffer.an_dma_paddr) {
544 an_dma_free(sc, &sc->an_rid_buffer);
545 }
546 for (i = 0; i < AN_MAX_RX_DESC; i++)
547 if (sc->an_rx_buffer[i].an_dma_paddr) {
548 an_dma_free(sc, &sc->an_rx_buffer[i]);
549 }
550 for (i = 0; i < AN_MAX_TX_DESC; i++)
551 if (sc->an_tx_buffer[i].an_dma_paddr) {
552 an_dma_free(sc, &sc->an_tx_buffer[i]);
553 }
554 if (sc->an_dtag) {
555 bus_dma_tag_destroy(sc->an_dtag);
556 }
557
374}
375
376int
558}
559
560int
561an_init_mpi350_desc(sc)
562 struct an_softc *sc;
563{
564 struct an_command cmd_struct;
565 struct an_reply reply;
566 struct an_card_rid_desc an_rid_desc;
567 struct an_card_rx_desc an_rx_desc;
568 struct an_card_tx_desc an_tx_desc;
569 int i, desc;
570
571 if(!sc->an_rid_buffer.an_dma_paddr)
572 an_dma_malloc(sc, AN_RID_BUFFER_SIZE,
573 &sc->an_rid_buffer, 0);
574 for (i = 0; i < AN_MAX_RX_DESC; i++)
575 if(!sc->an_rx_buffer[i].an_dma_paddr)
576 an_dma_malloc(sc, AN_RX_BUFFER_SIZE,
577 &sc->an_rx_buffer[i], 0);
578 for (i = 0; i < AN_MAX_TX_DESC; i++)
579 if(!sc->an_tx_buffer[i].an_dma_paddr)
580 an_dma_malloc(sc, AN_TX_BUFFER_SIZE,
581 &sc->an_tx_buffer[i], 0);
582
583 /*
584 * Allocate RX descriptor
585 */
586 bzero(&reply,sizeof(reply));
587 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
588 cmd_struct.an_parm0 = AN_DESCRIPTOR_RX;
589 cmd_struct.an_parm1 = AN_RX_DESC_OFFSET;
590 cmd_struct.an_parm2 = AN_MAX_RX_DESC;
591 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
592 printf("an%d: failed to allocate RX descriptor\n",
593 sc->an_unit);
594 return(EIO);
595 }
596
597 for (desc = 0; desc < AN_MAX_RX_DESC; desc++) {
598 bzero(&an_rx_desc, sizeof(an_rx_desc));
599 an_rx_desc.an_valid = 1;
600 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
601 an_rx_desc.an_done = 0;
602 an_rx_desc.an_phys = sc->an_rx_buffer[desc].an_dma_paddr;
603
604 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
605 CSR_MEM_AUX_WRITE_4(sc, AN_RX_DESC_OFFSET
606 + (desc * sizeof(an_rx_desc))
607 + (i * 4),
608 ((u_int32_t*)&an_rx_desc)[i]);
609 }
610
611 /*
612 * Allocate TX descriptor
613 */
614
615 bzero(&reply,sizeof(reply));
616 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
617 cmd_struct.an_parm0 = AN_DESCRIPTOR_TX;
618 cmd_struct.an_parm1 = AN_TX_DESC_OFFSET;
619 cmd_struct.an_parm2 = AN_MAX_TX_DESC;
620 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
621 printf("an%d: failed to allocate TX descriptor\n",
622 sc->an_unit);
623 return(EIO);
624 }
625
626 for (desc = 0; desc < AN_MAX_TX_DESC; desc++) {
627 bzero(&an_tx_desc, sizeof(an_tx_desc));
628 an_tx_desc.an_offset = 0;
629 an_tx_desc.an_eoc = 0;
630 an_tx_desc.an_valid = 0;
631 an_tx_desc.an_len = 0;
632 an_tx_desc.an_phys = sc->an_tx_buffer[desc].an_dma_paddr;
633
634 for (i = 0; i < sizeof(an_tx_desc) / 4; i++)
635 CSR_MEM_AUX_WRITE_4(sc, AN_TX_DESC_OFFSET
636 + (desc * sizeof(an_tx_desc))
637 + (i * 4),
638 ((u_int32_t*)&an_tx_desc)[i]);
639 }
640
641 /*
642 * Allocate RID descriptor
643 */
644
645 bzero(&reply,sizeof(reply));
646 cmd_struct.an_cmd = AN_CMD_ALLOC_DESC;
647 cmd_struct.an_parm0 = AN_DESCRIPTOR_HOSTRW;
648 cmd_struct.an_parm1 = AN_HOST_DESC_OFFSET;
649 cmd_struct.an_parm2 = 1;
650 if (an_cmd_struct(sc, &cmd_struct, &reply)) {
651 printf("an%d: failed to allocate host descriptor\n",
652 sc->an_unit);
653 return(EIO);
654 }
655
656 bzero(&an_rid_desc, sizeof(an_rid_desc));
657 an_rid_desc.an_valid = 1;
658 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
659 an_rid_desc.an_rid = 0;
660 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
661
662 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
663 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
664 ((u_int32_t*)&an_rid_desc)[i]);
665
666 return(0);
667}
668
669int
377an_attach(sc, unit, flags)
378 struct an_softc *sc;
379 int unit;
380 int flags;
381{
382 struct ifnet *ifp = &sc->arpcom.ac_if;
670an_attach(sc, unit, flags)
671 struct an_softc *sc;
672 int unit;
673 int flags;
674{
675 struct ifnet *ifp = &sc->arpcom.ac_if;
676 int error;
383
384 mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK,
385 MTX_DEF | MTX_RECURSE);
386 AN_LOCK(sc);
387
388 sc->an_gone = 0;
389 sc->an_associated = 0;
390 sc->an_monitor = 0;
391 sc->an_was_monitor = 0;
677
678 mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK,
679 MTX_DEF | MTX_RECURSE);
680 AN_LOCK(sc);
681
682 sc->an_gone = 0;
683 sc->an_associated = 0;
684 sc->an_monitor = 0;
685 sc->an_was_monitor = 0;
686 sc->an_flash_buffer = NULL;
392
393 /* Reset the NIC. */
394 an_reset(sc);
687
688 /* Reset the NIC. */
689 an_reset(sc);
690 if(sc->mpi350) {
691 error = an_init_mpi350_desc(sc);
692 if (error)
693 return(error);
694 }
395
396 /* Load factory config */
397 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
398 printf("an%d: failed to load config data\n", sc->an_unit);
399 AN_UNLOCK(sc);
400 mtx_destroy(&sc->an_mtx);
401 return(EIO);
402 }

--- 33 unchanged lines hidden (view full) ---

436 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
437 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
438 printf("an%d: read record failed\n", sc->an_unit);
439 AN_UNLOCK(sc);
440 mtx_destroy(&sc->an_mtx);
441 return(EIO);
442 }
443
695
696 /* Load factory config */
697 if (an_cmd(sc, AN_CMD_READCFG, 0)) {
698 printf("an%d: failed to load config data\n", sc->an_unit);
699 AN_UNLOCK(sc);
700 mtx_destroy(&sc->an_mtx);
701 return(EIO);
702 }

--- 33 unchanged lines hidden (view full) ---

736 sc->an_aplist.an_len = sizeof(struct an_ltv_aplist);
737 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_aplist)) {
738 printf("an%d: read record failed\n", sc->an_unit);
739 AN_UNLOCK(sc);
740 mtx_destroy(&sc->an_mtx);
741 return(EIO);
742 }
743
744#ifdef ANCACHE
745 /* Read the RSSI <-> dBm map */
746 sc->an_have_rssimap = 0;
747 if (sc->an_caps.an_softcaps & 8) {
748 sc->an_rssimap.an_type = AN_RID_RSSI_MAP;
749 sc->an_rssimap.an_len = sizeof(struct an_ltv_rssi_map);
750 if (an_read_record(sc, (struct an_ltv_gen *)&sc->an_rssimap)) {
751 printf("an%d: unable to get RSSI <-> dBM map\n", sc->an_unit);
752 } else {
753 printf("an%d: got RSSI <-> dBM map\n", sc->an_unit);
754 sc->an_have_rssimap = 1;
755 }
756 } else {
757 printf("an%d: no RSSI <-> dBM map\n", sc->an_unit);
758 }
759#endif
760
444 bcopy((char *)&sc->an_caps.an_oemaddr,
445 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
446
447 printf("an%d: Ethernet address: %6D\n", sc->an_unit,
448 sc->arpcom.ac_enaddr, ":");
449
450 ifp->if_softc = sc;
451 ifp->if_unit = sc->an_unit = unit;

--- 63 unchanged lines hidden (view full) ---

515 struct an_softc *sc;
516{
517 struct ifnet *ifp;
518 struct ether_header *eh;
519 struct ieee80211_frame *ih;
520 struct an_rxframe rx_frame;
521 struct an_rxframe_802_3 rx_frame_802_3;
522 struct mbuf *m;
761 bcopy((char *)&sc->an_caps.an_oemaddr,
762 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
763
764 printf("an%d: Ethernet address: %6D\n", sc->an_unit,
765 sc->arpcom.ac_enaddr, ":");
766
767 ifp->if_softc = sc;
768 ifp->if_unit = sc->an_unit = unit;

--- 63 unchanged lines hidden (view full) ---

832 struct an_softc *sc;
833{
834 struct ifnet *ifp;
835 struct ether_header *eh;
836 struct ieee80211_frame *ih;
837 struct an_rxframe rx_frame;
838 struct an_rxframe_802_3 rx_frame_802_3;
839 struct mbuf *m;
523 int len, id, error = 0;
524 int ieee80211_header_len;
525 u_char *bpf_buf;
526 u_short fc1;
840 int len, id, error = 0, i, count = 0;
841 int ieee80211_header_len;
842 u_char *bpf_buf;
843 u_short fc1;
844 struct an_card_rx_desc an_rx_desc;
845 u_int8_t *buf;
527
528 ifp = &sc->arpcom.ac_if;
529
846
847 ifp = &sc->arpcom.ac_if;
848
530 id = CSR_READ_2(sc, AN_RX_FID);
849 if (!sc->mpi350) {
850 id = CSR_READ_2(sc, AN_RX_FID);
531
851
532 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
533 /* read raw 802.11 packet */
534 bpf_buf = sc->buf_802_11;
852 if (sc->an_monitor && (ifp->if_flags & IFF_PROMISC)) {
853 /* read raw 802.11 packet */
854 bpf_buf = sc->buf_802_11;
535
855
536 /* read header */
537 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
538 sizeof(rx_frame))) {
539 ifp->if_ierrors++;
540 return;
541 }
856 /* read header */
857 if (an_read_data(sc, id, 0x0, (caddr_t)&rx_frame,
858 sizeof(rx_frame))) {
859 ifp->if_ierrors++;
860 return;
861 }
542
862
543 /*
544 * skip beacon by default since this increases the
545 * system load a lot
546 */
863 /*
864 * skip beacon by default since this increases the
865 * system load a lot
866 */
547
867
548 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
549 (rx_frame.an_frame_ctl & IEEE80211_FC0_SUBTYPE_BEACON)) {
550 return;
551 }
552
553 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
554 len = rx_frame.an_rx_payload_len
555 + sizeof(rx_frame);
556 /* Check for insane frame length */
557 if (len > sizeof(sc->buf_802_11)) {
558 printf("an%d: oversized packet received (%d, %d)\n",
559 sc->an_unit, len, MCLBYTES);
560 ifp->if_ierrors++;
868 if (!(sc->an_monitor & AN_MONITOR_INCLUDE_BEACON) &&
869 (rx_frame.an_frame_ctl &
870 IEEE80211_FC0_SUBTYPE_BEACON)) {
561 return;
562 }
563
871 return;
872 }
873
564 bcopy((char *)&rx_frame,
565 bpf_buf, sizeof(rx_frame));
874 if (sc->an_monitor & AN_MONITOR_AIRONET_HEADER) {
875 len = rx_frame.an_rx_payload_len
876 + sizeof(rx_frame);
877 /* Check for insane frame length */
878 if (len > sizeof(sc->buf_802_11)) {
879 printf("an%d: oversized packet "
880 "received (%d, %d)\n",
881 sc->an_unit, len, MCLBYTES);
882 ifp->if_ierrors++;
883 return;
884 }
566
885
567 error = an_read_data(sc, id, sizeof(rx_frame),
568 (caddr_t)bpf_buf+sizeof(rx_frame),
569 rx_frame.an_rx_payload_len);
886 bcopy((char *)&rx_frame,
887 bpf_buf, sizeof(rx_frame));
888
889 error = an_read_data(sc, id, sizeof(rx_frame),
890 (caddr_t)bpf_buf+sizeof(rx_frame),
891 rx_frame.an_rx_payload_len);
892 } else {
893 fc1=rx_frame.an_frame_ctl >> 8;
894 ieee80211_header_len =
895 sizeof(struct ieee80211_frame);
896 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
897 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
898 ieee80211_header_len += ETHER_ADDR_LEN;
899 }
900
901 len = rx_frame.an_rx_payload_len
902 + ieee80211_header_len;
903 /* Check for insane frame length */
904 if (len > sizeof(sc->buf_802_11)) {
905 printf("an%d: oversized packet "
906 "received (%d, %d)\n",
907 sc->an_unit, len, MCLBYTES);
908 ifp->if_ierrors++;
909 return;
910 }
911
912 ih = (struct ieee80211_frame *)bpf_buf;
913
914 bcopy((char *)&rx_frame.an_frame_ctl,
915 (char *)ih, ieee80211_header_len);
916
917 error = an_read_data(sc, id, sizeof(rx_frame) +
918 rx_frame.an_gaplen,
919 (caddr_t)ih +ieee80211_header_len,
920 rx_frame.an_rx_payload_len);
921 }
922 /* dump raw 802.11 packet to bpf and skip ip stack */
923 BPF_TAP(ifp, bpf_buf, len);
570 } else {
924 } else {
571 fc1=rx_frame.an_frame_ctl >> 8;
572 ieee80211_header_len = sizeof(struct ieee80211_frame);
573 if ((fc1 & IEEE80211_FC1_DIR_TODS) &&
574 (fc1 & IEEE80211_FC1_DIR_FROMDS)) {
575 ieee80211_header_len += ETHER_ADDR_LEN;
925 MGETHDR(m, M_DONTWAIT, MT_DATA);
926 if (m == NULL) {
927 ifp->if_ierrors++;
928 return;
576 }
929 }
930 MCLGET(m, M_DONTWAIT);
931 if (!(m->m_flags & M_EXT)) {
932 m_freem(m);
933 ifp->if_ierrors++;
934 return;
935 }
936 m->m_pkthdr.rcvif = ifp;
937 /* Read Ethernet encapsulated packet */
577
938
578 len = rx_frame.an_rx_payload_len
579 + ieee80211_header_len;
939#ifdef ANCACHE
940 /* Read NIC frame header */
941 if (an_read_data(sc, id, 0, (caddr_t)&rx_frame,
942 sizeof(rx_frame))) {
943 ifp->if_ierrors++;
944 return;
945 }
946#endif
947 /* Read in the 802_3 frame header */
948 if (an_read_data(sc, id, 0x34,
949 (caddr_t)&rx_frame_802_3,
950 sizeof(rx_frame_802_3))) {
951 ifp->if_ierrors++;
952 return;
953 }
954 if (rx_frame_802_3.an_rx_802_3_status != 0) {
955 ifp->if_ierrors++;
956 return;
957 }
580 /* Check for insane frame length */
958 /* Check for insane frame length */
959 len = rx_frame_802_3.an_rx_802_3_payload_len;
581 if (len > sizeof(sc->buf_802_11)) {
960 if (len > sizeof(sc->buf_802_11)) {
582 printf("an%d: oversized packet received (%d, %d)\n",
961 printf("an%d: oversized packet "
962 "received (%d, %d)\n",
583 sc->an_unit, len, MCLBYTES);
584 ifp->if_ierrors++;
585 return;
586 }
963 sc->an_unit, len, MCLBYTES);
964 ifp->if_ierrors++;
965 return;
966 }
967 m->m_pkthdr.len = m->m_len =
968 rx_frame_802_3.an_rx_802_3_payload_len + 12;
587
969
588 ih = (struct ieee80211_frame *)bpf_buf;
970 eh = mtod(m, struct ether_header *);
589
971
590 bcopy((char *)&rx_frame.an_frame_ctl,
591 (char *)ih, ieee80211_header_len);
972 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
973 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
974 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
975 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
592
976
593 error = an_read_data(sc, id, sizeof(rx_frame) +
594 rx_frame.an_gaplen,
595 (caddr_t)ih +ieee80211_header_len,
596 rx_frame.an_rx_payload_len);
597 }
598 /* dump raw 802.11 packet to bpf and skip ip stack */
599 BPF_TAP(ifp, bpf_buf, len);
600 } else {
601 MGETHDR(m, M_DONTWAIT, MT_DATA);
602 if (m == NULL) {
603 ifp->if_ierrors++;
604 return;
605 }
606 MCLGET(m, M_DONTWAIT);
607 if (!(m->m_flags & M_EXT)) {
608 m_freem(m);
609 ifp->if_ierrors++;
610 return;
611 }
612 m->m_pkthdr.rcvif = ifp;
613 /* Read Ethernet encapsulated packet */
977 /* in mbuf header type is just before payload */
978 error = an_read_data(sc, id, 0x44,
979 (caddr_t)&(eh->ether_type),
980 rx_frame_802_3.an_rx_802_3_payload_len);
614
981
982 if (error) {
983 m_freem(m);
984 ifp->if_ierrors++;
985 return;
986 }
987 ifp->if_ipackets++;
988
989 /* Receive packet. */
615#ifdef ANCACHE
990#ifdef ANCACHE
616 /* Read NIC frame header */
617 if (an_read_data(sc, id, 0, (caddr_t) & rx_frame, sizeof(rx_frame))) {
618 ifp->if_ierrors++;
619 return;
620 }
991 an_cache_store(sc, eh, m,
992 rx_frame.an_rx_signal_strength,
993 rx_frame.an_rsvd0);
621#endif
994#endif
622 /* Read in the 802_3 frame header */
623 if (an_read_data(sc, id, 0x34, (caddr_t) & rx_frame_802_3,
624 sizeof(rx_frame_802_3))) {
625 ifp->if_ierrors++;
626 return;
995 (*ifp->if_input)(ifp, m);
627 }
996 }
628 if (rx_frame_802_3.an_rx_802_3_status != 0) {
629 ifp->if_ierrors++;
630 return;
631 }
632 /* Check for insane frame length */
633 if (rx_frame_802_3.an_rx_802_3_payload_len > MCLBYTES) {
634 ifp->if_ierrors++;
635 return;
636 }
637 m->m_pkthdr.len = m->m_len =
638 rx_frame_802_3.an_rx_802_3_payload_len + 12;
639
997
640 eh = mtod(m, struct ether_header *);
998 } else { /* MPI-350 */
999 for (count = 0; count < AN_MAX_RX_DESC; count++){
1000 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1001 ((u_int32_t*)&an_rx_desc)[i]
1002 = CSR_MEM_AUX_READ_4(sc,
1003 AN_RX_DESC_OFFSET
1004 + (count * sizeof(an_rx_desc))
1005 + (i * 4));
641
1006
642 bcopy((char *)&rx_frame_802_3.an_rx_dst_addr,
643 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
644 bcopy((char *)&rx_frame_802_3.an_rx_src_addr,
645 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
1007 if (an_rx_desc.an_done && !an_rx_desc.an_valid) {
1008 buf = sc->an_rx_buffer[count].an_dma_vaddr;
646
1009
647 /* in mbuf header type is just before payload */
648 error = an_read_data(sc, id, 0x44, (caddr_t)&(eh->ether_type),
649 rx_frame_802_3.an_rx_802_3_payload_len);
1010 MGETHDR(m, M_DONTWAIT, MT_DATA);
1011 if (m == NULL) {
1012 ifp->if_ierrors++;
1013 return;
1014 }
1015 MCLGET(m, M_DONTWAIT);
1016 if (!(m->m_flags & M_EXT)) {
1017 m_freem(m);
1018 ifp->if_ierrors++;
1019 return;
1020 }
1021 m->m_pkthdr.rcvif = ifp;
1022 /* Read Ethernet encapsulated packet */
650
1023
651 if (error) {
652 m_freem(m);
653 ifp->if_ierrors++;
654 return;
655 }
656 ifp->if_ipackets++;
1024 /*
1025 * No ANCACHE support since we just get back
1026 * an Ethernet packet no 802.11 info
1027 */
1028#if 0
1029#ifdef ANCACHE
1030 /* Read NIC frame header */
1031 bcopy(buf, (caddr_t)&rx_frame,
1032 sizeof(rx_frame));
1033#endif
1034#endif
1035 /* Check for insane frame length */
1036 len = an_rx_desc.an_len + 12;
1037 if (len > MCLBYTES) {
1038 printf("an%d: oversized packet "
1039 "received (%d, %d)\n",
1040 sc->an_unit, len, MCLBYTES);
1041 ifp->if_ierrors++;
1042 return;
1043 }
657
1044
658 /* Receive packet. */
1045 m->m_pkthdr.len = m->m_len =
1046 an_rx_desc.an_len + 12;
1047
1048 eh = mtod(m, struct ether_header *);
1049
1050 bcopy(buf, (char *)eh,
1051 m->m_pkthdr.len);
1052
1053 ifp->if_ipackets++;
1054
1055 /* Receive packet. */
1056#if 0
659#ifdef ANCACHE
1057#ifdef ANCACHE
660 an_cache_store(sc, eh, m, rx_frame.an_rx_signal_strength);
1058 an_cache_store(sc, eh, m,
1059 rx_frame.an_rx_signal_strength,
1060 rx_frame.an_rsvd0);
661#endif
1061#endif
662 (*ifp->if_input)(ifp, m);
1062#endif
1063 (*ifp->if_input)(ifp, m);
1064
1065 an_rx_desc.an_valid = 1;
1066 an_rx_desc.an_len = AN_RX_BUFFER_SIZE;
1067 an_rx_desc.an_done = 0;
1068 an_rx_desc.an_phys =
1069 sc->an_rx_buffer[count].an_dma_paddr;
1070
1071 for (i = 0; i < sizeof(an_rx_desc) / 4; i++)
1072 CSR_MEM_AUX_WRITE_4(sc,
1073 AN_RX_DESC_OFFSET
1074 + (count * sizeof(an_rx_desc))
1075 + (i * 4),
1076 ((u_int32_t*)&an_rx_desc)[i]);
1077
1078 } else {
1079 printf("an%d: Didn't get valid RX packet "
1080 "%x %x %d\n",
1081 sc->an_unit,
1082 an_rx_desc.an_done,
1083 an_rx_desc.an_valid, an_rx_desc.an_len);
1084 }
1085 }
663 }
664}
665
666static void
667an_txeof(sc, status)
668 struct an_softc *sc;
669 int status;
670{
671 struct ifnet *ifp;
672 int id, i;
673
674 ifp = &sc->arpcom.ac_if;
675
676 ifp->if_timer = 0;
677 ifp->if_flags &= ~IFF_OACTIVE;
678
1086 }
1087}
1088
1089static void
1090an_txeof(sc, status)
1091 struct an_softc *sc;
1092 int status;
1093{
1094 struct ifnet *ifp;
1095 int id, i;
1096
1097 ifp = &sc->arpcom.ac_if;
1098
1099 ifp->if_timer = 0;
1100 ifp->if_flags &= ~IFF_OACTIVE;
1101
679 id = CSR_READ_2(sc, AN_TX_CMP_FID);
1102 if (!sc->mpi350) {
1103 id = CSR_READ_2(sc, AN_TX_CMP_FID);
680
1104
681 if (status & AN_EV_TX_EXC) {
682 ifp->if_oerrors++;
683 } else
684 ifp->if_opackets++;
1105 if (status & AN_EV_TX_EXC) {
1106 ifp->if_oerrors++;
1107 } else
1108 ifp->if_opackets++;
685
1109
686 for (i = 0; i < AN_TX_RING_CNT; i++) {
687 if (id == sc->an_rdata.an_tx_ring[i]) {
688 sc->an_rdata.an_tx_ring[i] = 0;
689 break;
1110 for (i = 0; i < AN_TX_RING_CNT; i++) {
1111 if (id == sc->an_rdata.an_tx_ring[i]) {
1112 sc->an_rdata.an_tx_ring[i] = 0;
1113 break;
1114 }
690 }
1115 }
1116
1117 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
1118 } else { /* MPI 350 */
1119 AN_INC(sc->an_rdata.an_tx_cons, AN_MAX_TX_DESC);
1120 if (sc->an_rdata.an_tx_prod ==
1121 sc->an_rdata.an_tx_cons)
1122 sc->an_rdata.an_tx_empty = 1;
691 }
692
1123 }
1124
693 AN_INC(sc->an_rdata.an_tx_cons, AN_TX_RING_CNT);
694
695 return;
696}
697
698/*
699 * We abuse the stats updater to check the current NIC status. This
700 * is important because we don't want to allow transmissions until
701 * the NIC has synchronized to the current cell (either as the master
702 * in an ad-hoc group, or as a station connected to an access point).

--- 50 unchanged lines hidden (view full) ---

753 if (sc->an_gone) {
754 AN_UNLOCK(sc);
755 return;
756 }
757
758 ifp = &sc->arpcom.ac_if;
759
760 /* Disable interrupts. */
1125 return;
1126}
1127
1128/*
1129 * We abuse the stats updater to check the current NIC status. This
1130 * is important because we don't want to allow transmissions until
1131 * the NIC has synchronized to the current cell (either as the master
1132 * in an ad-hoc group, or as a station connected to an access point).

--- 50 unchanged lines hidden (view full) ---

1183 if (sc->an_gone) {
1184 AN_UNLOCK(sc);
1185 return;
1186 }
1187
1188 ifp = &sc->arpcom.ac_if;
1189
1190 /* Disable interrupts. */
761 CSR_WRITE_2(sc, AN_INT_EN, 0);
1191 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
762
1192
763 status = CSR_READ_2(sc, AN_EVENT_STAT);
764 CSR_WRITE_2(sc, AN_EVENT_ACK, ~AN_INTRS);
1193 status = CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350));
1194 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), ~AN_INTRS);
765
766 if (status & AN_EV_AWAKE) {
1195
1196 if (status & AN_EV_AWAKE) {
767 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_AWAKE);
1197 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_AWAKE);
768 }
769
770 if (status & AN_EV_LINKSTAT) {
1198 }
1199
1200 if (status & AN_EV_LINKSTAT) {
771 if (CSR_READ_2(sc, AN_LINKSTAT) == AN_LINKSTAT_ASSOCIATED)
1201 if (CSR_READ_2(sc, AN_LINKSTAT(sc->mpi350))
1202 == AN_LINKSTAT_ASSOCIATED)
772 sc->an_associated = 1;
773 else
774 sc->an_associated = 0;
1203 sc->an_associated = 1;
1204 else
1205 sc->an_associated = 0;
775 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_LINKSTAT);
1206 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_LINKSTAT);
776 }
777
778 if (status & AN_EV_RX) {
779 an_rxeof(sc);
1207 }
1208
1209 if (status & AN_EV_RX) {
1210 an_rxeof(sc);
780 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
1211 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_RX);
781 }
782
783 if (status & AN_EV_TX) {
784 an_txeof(sc, status);
1212 }
1213
1214 if (status & AN_EV_TX) {
1215 an_txeof(sc, status);
785 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_TX);
1216 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX);
786 }
787
788 if (status & AN_EV_TX_EXC) {
789 an_txeof(sc, status);
1217 }
1218
1219 if (status & AN_EV_TX_EXC) {
1220 an_txeof(sc, status);
790 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_TX_EXC);
1221 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_TX_EXC);
791 }
792
793 if (status & AN_EV_ALLOC)
1222 }
1223
1224 if (status & AN_EV_ALLOC)
794 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_ALLOC);
1225 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
795
796 /* Re-enable interrupts. */
1226
1227 /* Re-enable interrupts. */
797 CSR_WRITE_2(sc, AN_INT_EN, AN_INTRS);
1228 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
798
799 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
800 an_start(ifp);
801
802 AN_UNLOCK(sc);
803
804 return;
805}
806
1229
1230 if ((ifp->if_flags & IFF_UP) && (ifp->if_snd.ifq_head != NULL))
1231 an_start(ifp);
1232
1233 AN_UNLOCK(sc);
1234
1235 return;
1236}
1237
1238static void
1239an_kick(sc)
1240 struct an_softc *sc;
1241{
1242 int i;
1243
1244 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_NOOP2);
1245
1246 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1247 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1248 } else {
1249 for (i = 0; i < AN_TIMEOUT; i++) {
1250 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350))
1251 & AN_EV_CMD)
1252 break;
1253 }
1254 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1255 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1256 }
1257 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1258 if (i == AN_TIMEOUT) {
1259 printf ("COULDN'T CLEAR\n");
1260 }
1261 }
1262}
1263
807static int
1264static int
1265an_cmd_struct(sc, cmd, reply)
1266 struct an_softc *sc;
1267 struct an_command *cmd;
1268 struct an_reply *reply;
1269{
1270 int i;
1271
1272 for (i = 0; i != AN_TIMEOUT; i++) {
1273 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1274 DELAY(10);
1275 }
1276 else
1277 break;
1278 }
1279 if( i == AN_TIMEOUT) {
1280 printf("BUSY\n");
1281 return(ETIMEDOUT);
1282 }
1283
1284 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), cmd->an_parm0);
1285 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), cmd->an_parm1);
1286 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), cmd->an_parm2);
1287 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd->an_cmd);
1288
1289 for (i = 0; i < AN_TIMEOUT; i++) {
1290 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
1291 break;
1292 }
1293
1294 if (i == AN_TIMEOUT)
1295 an_kick(sc);
1296
1297 reply->an_resp0 = CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1298 reply->an_resp1 = CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1299 reply->an_resp2 = CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1300 reply->an_status = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
1301
1302 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1303 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
1304
1305 /* Ack the command */
1306 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
1307
1308 if (i == AN_TIMEOUT)
1309 return(ETIMEDOUT);
1310
1311 return(0);
1312}
1313
1314static int
808an_cmd(sc, cmd, val)
809 struct an_softc *sc;
810 int cmd;
811 int val;
812{
813 int i, s = 0;
814
1315an_cmd(sc, cmd, val)
1316 struct an_softc *sc;
1317 int cmd;
1318 int val;
1319{
1320 int i, s = 0;
1321
815 CSR_WRITE_2(sc, AN_PARAM0, val);
816 CSR_WRITE_2(sc, AN_PARAM1, 0);
817 CSR_WRITE_2(sc, AN_PARAM2, 0);
818 CSR_WRITE_2(sc, AN_COMMAND, cmd);
1322 CSR_WRITE_2(sc, AN_PARAM0(sc->mpi350), val);
1323 CSR_WRITE_2(sc, AN_PARAM1(sc->mpi350), 0);
1324 CSR_WRITE_2(sc, AN_PARAM2(sc->mpi350), 0);
1325 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
819
820 for (i = 0; i < AN_TIMEOUT; i++) {
1326
1327 for (i = 0; i < AN_TIMEOUT; i++) {
821 if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_CMD)
1328 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_CMD)
822 break;
823 else {
1329 break;
1330 else {
824 if (CSR_READ_2(sc, AN_COMMAND) == cmd)
825 CSR_WRITE_2(sc, AN_COMMAND, cmd);
1331 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) == cmd)
1332 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), cmd);
826 }
827 }
828
829 for (i = 0; i < AN_TIMEOUT; i++) {
1333 }
1334 }
1335
1336 for (i = 0; i < AN_TIMEOUT; i++) {
830 CSR_READ_2(sc, AN_RESP0);
831 CSR_READ_2(sc, AN_RESP1);
832 CSR_READ_2(sc, AN_RESP2);
833 s = CSR_READ_2(sc, AN_STATUS);
1337 CSR_READ_2(sc, AN_RESP0(sc->mpi350));
1338 CSR_READ_2(sc, AN_RESP1(sc->mpi350));
1339 CSR_READ_2(sc, AN_RESP2(sc->mpi350));
1340 s = CSR_READ_2(sc, AN_STATUS(sc->mpi350));
834 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
835 break;
836 }
837
838 /* Ack the command */
1341 if ((s & AN_STAT_CMD_CODE) == (cmd & AN_STAT_CMD_CODE))
1342 break;
1343 }
1344
1345 /* Ack the command */
839 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CMD);
1346 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CMD);
840
1347
841 if (CSR_READ_2(sc, AN_COMMAND) & AN_CMD_BUSY)
842 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CLR_STUCK_BUSY);
1348 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY)
1349 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_CLR_STUCK_BUSY);
843
844 if (i == AN_TIMEOUT)
845 return(ETIMEDOUT);
846
847 return(0);
848}
849
850/*

--- 23 unchanged lines hidden (view full) ---

874/*
875 * Read an LTV record from the NIC.
876 */
877static int
878an_read_record(sc, ltv)
879 struct an_softc *sc;
880 struct an_ltv_gen *ltv;
881{
1350
1351 if (i == AN_TIMEOUT)
1352 return(ETIMEDOUT);
1353
1354 return(0);
1355}
1356
1357/*

--- 23 unchanged lines hidden (view full) ---

1381/*
1382 * Read an LTV record from the NIC.
1383 */
1384static int
1385an_read_record(sc, ltv)
1386 struct an_softc *sc;
1387 struct an_ltv_gen *ltv;
1388{
1389 struct an_ltv_gen *an_ltv;
1390 struct an_card_rid_desc an_rid_desc;
1391 struct an_command cmd;
1392 struct an_reply reply;
882 u_int16_t *ptr;
883 u_int8_t *ptr2;
884 int i, len;
885
886 if (ltv->an_len < 4 || ltv->an_type == 0)
887 return(EINVAL);
888
1393 u_int16_t *ptr;
1394 u_int8_t *ptr2;
1395 int i, len;
1396
1397 if (ltv->an_len < 4 || ltv->an_type == 0)
1398 return(EINVAL);
1399
889 /* Tell the NIC to enter record read mode. */
890 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
891 printf("an%d: RID access failed\n", sc->an_unit);
892 return(EIO);
893 }
1400 if (!sc->mpi350){
1401 /* Tell the NIC to enter record read mode. */
1402 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type)) {
1403 printf("an%d: RID access failed\n", sc->an_unit);
1404 return(EIO);
1405 }
894
1406
895 /* Seek to the record. */
896 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
897 printf("an%d: seek to record failed\n", sc->an_unit);
898 return(EIO);
899 }
1407 /* Seek to the record. */
1408 if (an_seek(sc, ltv->an_type, 0, AN_BAP1)) {
1409 printf("an%d: seek to record failed\n", sc->an_unit);
1410 return(EIO);
1411 }
900
1412
901 /*
902 * Read the length and record type and make sure they
903 * match what we expect (this verifies that we have enough
904 * room to hold all of the returned data).
905 * Length includes type but not length.
906 */
907 len = CSR_READ_2(sc, AN_DATA1);
908 if (len > (ltv->an_len - 2)) {
909 printf("an%d: record length mismatch -- expected %d, "
910 "got %d for Rid %x\n", sc->an_unit,
911 ltv->an_len - 2, len, ltv->an_type);
912 len = ltv->an_len - 2;
913 } else {
914 ltv->an_len = len + 2;
915 }
1413 /*
1414 * Read the length and record type and make sure they
1415 * match what we expect (this verifies that we have enough
1416 * room to hold all of the returned data).
1417 * Length includes type but not length.
1418 */
1419 len = CSR_READ_2(sc, AN_DATA1);
1420 if (len > (ltv->an_len - 2)) {
1421 printf("an%d: record length mismatch -- expected %d, "
1422 "got %d for Rid %x\n", sc->an_unit,
1423 ltv->an_len - 2, len, ltv->an_type);
1424 len = ltv->an_len - 2;
1425 } else {
1426 ltv->an_len = len + 2;
1427 }
916
1428
917 /* Now read the data. */
918 len -= 2; /* skip the type */
919 ptr = <v->an_val;
920 for (i = len; i > 1; i -= 2)
921 *ptr++ = CSR_READ_2(sc, AN_DATA1);
922 if (i) {
923 ptr2 = (u_int8_t *)ptr;
924 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1429 /* Now read the data. */
1430 len -= 2; /* skip the type */
1431 ptr = &ltv->an_val;
1432 for (i = len; i > 1; i -= 2)
1433 *ptr++ = CSR_READ_2(sc, AN_DATA1);
1434 if (i) {
1435 ptr2 = (u_int8_t *)ptr;
1436 *ptr2 = CSR_READ_1(sc, AN_DATA1);
1437 }
1438 } else { /* MPI-350 */
1439 an_rid_desc.an_valid = 1;
1440 an_rid_desc.an_len = AN_RID_BUFFER_SIZE;
1441 an_rid_desc.an_rid = 0;
1442 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1443 bzero(sc->an_rid_buffer.an_dma_vaddr, AN_RID_BUFFER_SIZE);
1444
1445 bzero(&cmd, sizeof(cmd));
1446 bzero(&reply, sizeof(reply));
1447 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_READ;
1448 cmd.an_parm0 = ltv->an_type;
1449
1450 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1451 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1452 ((u_int32_t*)&an_rid_desc)[i]);
1453
1454 if (an_cmd_struct(sc, &cmd, &reply)
1455 || reply.an_status & AN_CMD_QUAL_MASK) {
1456 printf("an%d: failed to read RID %x %x %x %x %x, %d\n",
1457 sc->an_unit, ltv->an_type,
1458 reply.an_status,
1459 reply.an_resp0,
1460 reply.an_resp1,
1461 reply.an_resp2,
1462 i);
1463 return(EIO);
1464 }
1465
1466 an_ltv = (struct an_ltv_gen *)sc->an_rid_buffer.an_dma_vaddr;
1467 if (an_ltv->an_len + 2 < an_rid_desc.an_len) {
1468 an_rid_desc.an_len = an_ltv->an_len;
1469 }
1470
1471 if (an_rid_desc.an_len > 2)
1472 bcopy(&an_ltv->an_type,
1473 &ltv->an_val,
1474 an_rid_desc.an_len - 2);
1475 ltv->an_len = an_rid_desc.an_len + 2;
925 }
1476 }
1477
926 if (an_dump)
927 an_dump_record(sc, ltv, "Read");
928
929 return(0);
930}
931
932/*
933 * Same as read, except we inject data instead of reading it.
934 */
935static int
936an_write_record(sc, ltv)
937 struct an_softc *sc;
938 struct an_ltv_gen *ltv;
939{
1478 if (an_dump)
1479 an_dump_record(sc, ltv, "Read");
1480
1481 return(0);
1482}
1483
1484/*
1485 * Same as read, except we inject data instead of reading it.
1486 */
1487static int
1488an_write_record(sc, ltv)
1489 struct an_softc *sc;
1490 struct an_ltv_gen *ltv;
1491{
1492 struct an_card_rid_desc an_rid_desc;
1493 struct an_command cmd;
1494 struct an_reply reply;
1495 char *buf;
940 u_int16_t *ptr;
941 u_int8_t *ptr2;
942 int i, len;
943
944 if (an_dump)
945 an_dump_record(sc, ltv, "Write");
946
1496 u_int16_t *ptr;
1497 u_int8_t *ptr2;
1498 int i, len;
1499
1500 if (an_dump)
1501 an_dump_record(sc, ltv, "Write");
1502
947 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
948 return(EIO);
1503 if (!sc->mpi350){
1504 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_READ, ltv->an_type))
1505 return(EIO);
949
1506
950 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
951 return(EIO);
1507 if (an_seek(sc, ltv->an_type, 0, AN_BAP1))
1508 return(EIO);
952
1509
953 /*
954 * Length includes type but not length.
955 */
956 len = ltv->an_len - 2;
957 CSR_WRITE_2(sc, AN_DATA1, len);
1510 /*
1511 * Length includes type but not length.
1512 */
1513 len = ltv->an_len - 2;
1514 CSR_WRITE_2(sc, AN_DATA1, len);
958
1515
959 len -= 2; /* skip the type */
960 ptr = <v->an_val;
961 for (i = len; i > 1; i -= 2)
962 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
963 if (i) {
964 ptr2 = (u_int8_t *)ptr;
965 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
966 }
1516 len -= 2; /* skip the type */
1517 ptr = &ltv->an_val;
1518 for (i = len; i > 1; i -= 2)
1519 CSR_WRITE_2(sc, AN_DATA1, *ptr++);
1520 if (i) {
1521 ptr2 = (u_int8_t *)ptr;
1522 CSR_WRITE_1(sc, AN_DATA0, *ptr2);
1523 }
967
1524
968 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1525 if (an_cmd(sc, AN_CMD_ACCESS|AN_ACCESS_WRITE, ltv->an_type))
1526 return(EIO);
1527 } else { /* MPI-350 */
1528
1529 for (i = 0; i != AN_TIMEOUT; i++) {
1530 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
1531 DELAY(10);
1532 }
1533 else
1534 break;
1535 }
1536 if (i == AN_TIMEOUT) {
1537 printf("BUSY\n");
1538 }
1539
1540 an_rid_desc.an_valid = 1;
1541 an_rid_desc.an_len = ltv->an_len - 2;
1542 an_rid_desc.an_rid = ltv->an_type;
1543 an_rid_desc.an_phys = sc->an_rid_buffer.an_dma_paddr;
1544
1545 bcopy(&ltv->an_type, sc->an_rid_buffer.an_dma_vaddr,
1546 an_rid_desc.an_len);
1547
1548 bzero(&cmd,sizeof(cmd));
1549 bzero(&reply,sizeof(reply));
1550 cmd.an_cmd = AN_CMD_ACCESS|AN_ACCESS_WRITE;
1551 cmd.an_parm0 = ltv->an_type;
1552
1553 for (i = 0; i < sizeof(an_rid_desc) / 4; i++)
1554 CSR_MEM_AUX_WRITE_4(sc, AN_HOST_DESC_OFFSET + i * 4,
1555 ((u_int32_t*)&an_rid_desc)[i]);
1556
1557 if ((i = an_cmd_struct(sc, &cmd, &reply))) {
1558 printf("an%d: failed to write RID %x %x %x %x %x, %d\n",
1559 sc->an_unit, ltv->an_type,
1560 reply.an_status,
1561 reply.an_resp0,
1562 reply.an_resp1,
1563 reply.an_resp2,
1564 i);
969 return(EIO);
1565 return(EIO);
1566 }
970
1567
1568 ptr = (u_int16_t *)buf;
1569
1570 if (reply.an_status & AN_CMD_QUAL_MASK) {
1571 printf("an%d: failed to write RID %x %x %x %x %x, %d\n",
1572 sc->an_unit, ltv->an_type,
1573 reply.an_status,
1574 reply.an_resp0,
1575 reply.an_resp1,
1576 reply.an_resp2,
1577 i);
1578 return(EIO);
1579 }
1580 }
1581
971 return(0);
972}
973
974static void
975an_dump_record(sc, ltv, string)
976 struct an_softc *sc;
977 struct an_ltv_gen *ltv;
978 char *string;

--- 141 unchanged lines hidden (view full) ---

1120
1121 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1122 printf("an%d: failed to allocate %d bytes on NIC\n",
1123 sc->an_unit, len);
1124 return(ENOMEM);
1125 }
1126
1127 for (i = 0; i < AN_TIMEOUT; i++) {
1582 return(0);
1583}
1584
1585static void
1586an_dump_record(sc, ltv, string)
1587 struct an_softc *sc;
1588 struct an_ltv_gen *ltv;
1589 char *string;

--- 141 unchanged lines hidden (view full) ---

1731
1732 if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
1733 printf("an%d: failed to allocate %d bytes on NIC\n",
1734 sc->an_unit, len);
1735 return(ENOMEM);
1736 }
1737
1738 for (i = 0; i < AN_TIMEOUT; i++) {
1128 if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_ALLOC)
1739 if (CSR_READ_2(sc, AN_EVENT_STAT(sc->mpi350)) & AN_EV_ALLOC)
1129 break;
1130 }
1131
1132 if (i == AN_TIMEOUT)
1133 return(ETIMEDOUT);
1134
1740 break;
1741 }
1742
1743 if (i == AN_TIMEOUT)
1744 return(ETIMEDOUT);
1745
1135 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_ALLOC);
1746 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
1136 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1137
1138 if (an_seek(sc, *id, 0, AN_BAP0))
1139 return(EIO);
1140
1141 for (i = 0; i < len / 2; i++)
1142 CSR_WRITE_2(sc, AN_DATA0, 0);
1143

--- 98 unchanged lines hidden (view full) ---

1242
1243static void
1244an_promisc(sc, promisc)
1245 struct an_softc *sc;
1246 int promisc;
1247{
1248 if (sc->an_was_monitor)
1249 an_reset(sc);
1747 *id = CSR_READ_2(sc, AN_ALLOC_FID);
1748
1749 if (an_seek(sc, *id, 0, AN_BAP0))
1750 return(EIO);
1751
1752 for (i = 0; i < len / 2; i++)
1753 CSR_WRITE_2(sc, AN_DATA0, 0);
1754

--- 98 unchanged lines hidden (view full) ---

1853
1854static void
1855an_promisc(sc, promisc)
1856 struct an_softc *sc;
1857 int promisc;
1858{
1859 if (sc->an_was_monitor)
1860 an_reset(sc);
1861 if (sc->mpi350)
1862 an_init_mpi350_desc(sc);
1250 if (sc->an_monitor || sc->an_was_monitor)
1251 an_init(sc);
1252
1253 sc->an_was_monitor = sc->an_monitor;
1254 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1255
1256 return;
1257}

--- 564 unchanged lines hidden (view full) ---

1822 struct an_softc *sc;
1823{
1824 int i;
1825 int id;
1826
1827 if (sc->an_gone)
1828 return (0);
1829
1863 if (sc->an_monitor || sc->an_was_monitor)
1864 an_init(sc);
1865
1866 sc->an_was_monitor = sc->an_monitor;
1867 an_cmd(sc, AN_CMD_SET_MODE, promisc ? 0xffff : 0);
1868
1869 return;
1870}

--- 564 unchanged lines hidden (view full) ---

2435 struct an_softc *sc;
2436{
2437 int i;
2438 int id;
2439
2440 if (sc->an_gone)
2441 return (0);
2442
1830 for (i = 0; i < AN_TX_RING_CNT; i++) {
1831 if (an_alloc_nicmem(sc, 1518 +
1832 0x44, &id))
1833 return(ENOMEM);
1834 sc->an_rdata.an_tx_fids[i] = id;
1835 sc->an_rdata.an_tx_ring[i] = 0;
2443 if (!sc->mpi350) {
2444 for (i = 0; i < AN_TX_RING_CNT; i++) {
2445 if (an_alloc_nicmem(sc, 1518 +
2446 0x44, &id))
2447 return(ENOMEM);
2448 sc->an_rdata.an_tx_fids[i] = id;
2449 sc->an_rdata.an_tx_ring[i] = 0;
2450 }
1836 }
1837
1838 sc->an_rdata.an_tx_prod = 0;
1839 sc->an_rdata.an_tx_cons = 0;
2451 }
2452
2453 sc->an_rdata.an_tx_prod = 0;
2454 sc->an_rdata.an_tx_cons = 0;
2455 sc->an_rdata.an_tx_empty = 1;
1840
1841 return(0);
1842}
1843
1844static void
1845an_init(xsc)
1846 void *xsc;
1847{

--- 10 unchanged lines hidden (view full) ---

1858 if (ifp->if_flags & IFF_RUNNING)
1859 an_stop(sc);
1860
1861 sc->an_associated = 0;
1862
1863 /* Allocate the TX buffers */
1864 if (an_init_tx_ring(sc)) {
1865 an_reset(sc);
2456
2457 return(0);
2458}
2459
2460static void
2461an_init(xsc)
2462 void *xsc;
2463{

--- 10 unchanged lines hidden (view full) ---

2474 if (ifp->if_flags & IFF_RUNNING)
2475 an_stop(sc);
2476
2477 sc->an_associated = 0;
2478
2479 /* Allocate the TX buffers */
2480 if (an_init_tx_ring(sc)) {
2481 an_reset(sc);
2482 if (sc->mpi350)
2483 an_init_mpi350_desc(sc);
1866 if (an_init_tx_ring(sc)) {
1867 printf("an%d: tx buffer allocation "
1868 "failed\n", sc->an_unit);
1869 AN_UNLOCK(sc);
1870 return;
1871 }
1872 }
1873

--- 18 unchanged lines hidden (view full) ---

1892 } else {
1893 sc->an_config.an_rxmode |=
1894 AN_RXMODE_80211_MONITOR_CURBSS |
1895 AN_RXMODE_NO_8023_HEADER;
1896 }
1897 }
1898 }
1899
2484 if (an_init_tx_ring(sc)) {
2485 printf("an%d: tx buffer allocation "
2486 "failed\n", sc->an_unit);
2487 AN_UNLOCK(sc);
2488 return;
2489 }
2490 }
2491

--- 18 unchanged lines hidden (view full) ---

2510 } else {
2511 sc->an_config.an_rxmode |=
2512 AN_RXMODE_80211_MONITOR_CURBSS |
2513 AN_RXMODE_NO_8023_HEADER;
2514 }
2515 }
2516 }
2517
2518 if (sc->an_have_rssimap)
2519 sc->an_config.an_rxmode |= AN_RXMODE_NORMALIZED_RSSI;
2520
1900 /* Set the ssid list */
1901 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
1902 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
1903 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
1904 printf("an%d: failed to set ssid list\n", sc->an_unit);
1905 AN_UNLOCK(sc);
1906 return;
1907 }

--- 22 unchanged lines hidden (view full) ---

1930 AN_UNLOCK(sc);
1931 return;
1932 }
1933
1934 if (ifp->if_flags & IFF_PROMISC)
1935 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
1936
1937 /* enable interrupts */
2521 /* Set the ssid list */
2522 sc->an_ssidlist.an_type = AN_RID_SSIDLIST;
2523 sc->an_ssidlist.an_len = sizeof(struct an_ltv_ssidlist);
2524 if (an_write_record(sc, (struct an_ltv_gen *)&sc->an_ssidlist)) {
2525 printf("an%d: failed to set ssid list\n", sc->an_unit);
2526 AN_UNLOCK(sc);
2527 return;
2528 }

--- 22 unchanged lines hidden (view full) ---

2551 AN_UNLOCK(sc);
2552 return;
2553 }
2554
2555 if (ifp->if_flags & IFF_PROMISC)
2556 an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
2557
2558 /* enable interrupts */
1938 CSR_WRITE_2(sc, AN_INT_EN, AN_INTRS);
2559 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), AN_INTRS);
1939
1940 ifp->if_flags |= IFF_RUNNING;
1941 ifp->if_flags &= ~IFF_OACTIVE;
1942
1943 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
1944 AN_UNLOCK(sc);
1945
1946 return;
1947}
1948
1949static void
1950an_start(ifp)
1951 struct ifnet *ifp;
1952{
1953 struct an_softc *sc;
1954 struct mbuf *m0 = NULL;
1955 struct an_txframe_802_3 tx_frame_802_3;
1956 struct ether_header *eh;
2560
2561 ifp->if_flags |= IFF_RUNNING;
2562 ifp->if_flags &= ~IFF_OACTIVE;
2563
2564 sc->an_stat_ch = timeout(an_stats_update, sc, hz);
2565 AN_UNLOCK(sc);
2566
2567 return;
2568}
2569
2570static void
2571an_start(ifp)
2572 struct ifnet *ifp;
2573{
2574 struct an_softc *sc;
2575 struct mbuf *m0 = NULL;
2576 struct an_txframe_802_3 tx_frame_802_3;
2577 struct ether_header *eh;
1957 int id;
1958 int idx;
2578 int id, idx, i;
1959 unsigned char txcontrol;
2579 unsigned char txcontrol;
2580 struct an_card_tx_desc an_tx_desc;
2581 u_int8_t *ptr;
2582 u_int8_t *buf;
1960
1961 sc = ifp->if_softc;
1962
1963 if (sc->an_gone)
1964 return;
1965
1966 if (ifp->if_flags & IFF_OACTIVE)
1967 return;

--- 8 unchanged lines hidden (view full) ---

1976 if (m0 == NULL)
1977 break;
1978 m_freem(m0);
1979 }
1980 return;
1981 }
1982
1983 idx = sc->an_rdata.an_tx_prod;
2583
2584 sc = ifp->if_softc;
2585
2586 if (sc->an_gone)
2587 return;
2588
2589 if (ifp->if_flags & IFF_OACTIVE)
2590 return;

--- 8 unchanged lines hidden (view full) ---

2599 if (m0 == NULL)
2600 break;
2601 m_freem(m0);
2602 }
2603 return;
2604 }
2605
2606 idx = sc->an_rdata.an_tx_prod;
1984 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
1985
2607
1986 while (sc->an_rdata.an_tx_ring[idx] == 0) {
1987 IF_DEQUEUE(&ifp->if_snd, m0);
1988 if (m0 == NULL)
1989 break;
2608 if (!sc->mpi350) {
2609 bzero((char *)&tx_frame_802_3, sizeof(tx_frame_802_3));
1990
2610
1991 id = sc->an_rdata.an_tx_fids[idx];
1992 eh = mtod(m0, struct ether_header *);
2611 while (sc->an_rdata.an_tx_ring[idx] == 0) {
2612 IF_DEQUEUE(&ifp->if_snd, m0);
2613 if (m0 == NULL)
2614 break;
1993
2615
1994 bcopy((char *)&eh->ether_dhost,
1995 (char *)&tx_frame_802_3.an_tx_dst_addr, ETHER_ADDR_LEN);
1996 bcopy((char *)&eh->ether_shost,
1997 (char *)&tx_frame_802_3.an_tx_src_addr, ETHER_ADDR_LEN);
2616 id = sc->an_rdata.an_tx_fids[idx];
2617 eh = mtod(m0, struct ether_header *);
1998
2618
1999 tx_frame_802_3.an_tx_802_3_payload_len =
2000 m0->m_pkthdr.len - 12; /* minus src/dest mac & type */
2619 bcopy((char *)&eh->ether_dhost,
2620 (char *)&tx_frame_802_3.an_tx_dst_addr,
2621 ETHER_ADDR_LEN);
2622 bcopy((char *)&eh->ether_shost,
2623 (char *)&tx_frame_802_3.an_tx_src_addr,
2624 ETHER_ADDR_LEN);
2001
2625
2002 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2003 tx_frame_802_3.an_tx_802_3_payload_len,
2004 (caddr_t)&sc->an_txbuf);
2626 /* minus src/dest mac & type */
2627 tx_frame_802_3.an_tx_802_3_payload_len =
2628 m0->m_pkthdr.len - 12;
2005
2629
2006 txcontrol = AN_TXCTL_8023;
2007 /* write the txcontrol only */
2008 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2630 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2631 tx_frame_802_3.an_tx_802_3_payload_len,
2632 (caddr_t)&sc->an_txbuf);
2633
2634 txcontrol = AN_TXCTL_8023;
2635 /* write the txcontrol only */
2636 an_write_data(sc, id, 0x08, (caddr_t)&txcontrol,
2637 sizeof(txcontrol));
2638
2639 /* 802_3 header */
2640 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2641 sizeof(struct an_txframe_802_3));
2642
2643 /* in mbuf header type is just before payload */
2644 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2645 tx_frame_802_3.an_tx_802_3_payload_len);
2646
2647 /*
2648 * If there's a BPF listner, bounce a copy of
2649 * this frame to him.
2650 */
2651 BPF_MTAP(ifp, m0);
2652
2653 m_freem(m0);
2654 m0 = NULL;
2655
2656 sc->an_rdata.an_tx_ring[idx] = id;
2657 if (an_cmd(sc, AN_CMD_TX, id))
2658 printf("an%d: xmit failed\n", sc->an_unit);
2659
2660 AN_INC(idx, AN_TX_RING_CNT);
2661 }
2662 } else { /* MPI-350 */
2663 while (sc->an_rdata.an_tx_empty ||
2664 idx != sc->an_rdata.an_tx_cons) {
2665 IF_DEQUEUE(&ifp->if_snd, m0);
2666 if (m0 == NULL) {
2667 break;
2668 }
2669 buf = sc->an_tx_buffer[idx].an_dma_vaddr;
2670
2671 eh = mtod(m0, struct ether_header *);
2672
2673 /* DJA optimize this to limit bcopy */
2674 bcopy((char *)&eh->ether_dhost,
2675 (char *)&tx_frame_802_3.an_tx_dst_addr,
2676 ETHER_ADDR_LEN);
2677 bcopy((char *)&eh->ether_shost,
2678 (char *)&tx_frame_802_3.an_tx_src_addr,
2679 ETHER_ADDR_LEN);
2680
2681 /* minus src/dest mac & type */
2682 tx_frame_802_3.an_tx_802_3_payload_len =
2683 m0->m_pkthdr.len - 12;
2684
2685 m_copydata(m0, sizeof(struct ether_header) - 2 ,
2686 tx_frame_802_3.an_tx_802_3_payload_len,
2687 (caddr_t)&sc->an_txbuf);
2688
2689 txcontrol = AN_TXCTL_8023;
2690 /* write the txcontrol only */
2691 bcopy((caddr_t)&txcontrol, &buf[0x08],
2009 sizeof(txcontrol));
2010
2692 sizeof(txcontrol));
2693
2011 /* 802_3 header */
2012 an_write_data(sc, id, 0x34, (caddr_t)&tx_frame_802_3,
2694 /* 802_3 header */
2695 bcopy((caddr_t)&tx_frame_802_3, &buf[0x34],
2013 sizeof(struct an_txframe_802_3));
2014
2696 sizeof(struct an_txframe_802_3));
2697
2015 /* in mbuf header type is just before payload */
2016 an_write_data(sc, id, 0x44, (caddr_t)&sc->an_txbuf,
2017 tx_frame_802_3.an_tx_802_3_payload_len);
2698 /* in mbuf header type is just before payload */
2699 bcopy((caddr_t)&sc->an_txbuf, &buf[0x44],
2700 tx_frame_802_3.an_tx_802_3_payload_len);
2018
2701
2019 /*
2020 * If there's a BPF listner, bounce a copy of
2021 * this frame to him.
2022 */
2023 BPF_MTAP(ifp, m0);
2024
2702
2025 m_freem(m0);
2026 m0 = NULL;
2703 bzero(&an_tx_desc, sizeof(an_tx_desc));
2704 an_tx_desc.an_offset = 0;
2705 an_tx_desc.an_eoc = 1;
2706 an_tx_desc.an_valid = 1;
2707 an_tx_desc.an_len = 0x44 +
2708 tx_frame_802_3.an_tx_802_3_payload_len;
2709 an_tx_desc.an_phys = sc->an_tx_buffer[idx].an_dma_paddr;
2710 ptr = (u_int8_t*)&an_tx_desc;
2711 for (i = 0; i < sizeof(an_tx_desc); i++) {
2712 CSR_MEM_AUX_WRITE_1(sc, AN_TX_DESC_OFFSET + i,
2713 ptr[i]);
2714 }
2027
2715
2028 sc->an_rdata.an_tx_ring[idx] = id;
2029 if (an_cmd(sc, AN_CMD_TX, id))
2030 printf("an%d: xmit failed\n", sc->an_unit);
2716 /*
2717 * If there's a BPF listner, bounce a copy of
2718 * this frame to him.
2719 */
2720 BPF_MTAP(ifp, m0);
2031
2721
2032 AN_INC(idx, AN_TX_RING_CNT);
2722 m_freem(m0);
2723 m0 = NULL;
2724
2725 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), AN_EV_ALLOC);
2726
2727 AN_INC(idx, AN_MAX_TX_DESC);
2728 sc->an_rdata.an_tx_empty = 0;
2729 }
2033 }
2034
2035 if (m0 != NULL)
2036 ifp->if_flags |= IFF_OACTIVE;
2037
2038 sc->an_rdata.an_tx_prod = idx;
2039
2040 /*

--- 16 unchanged lines hidden (view full) ---

2057 if (sc->an_gone) {
2058 AN_UNLOCK(sc);
2059 return;
2060 }
2061
2062 ifp = &sc->arpcom.ac_if;
2063
2064 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2730 }
2731
2732 if (m0 != NULL)
2733 ifp->if_flags |= IFF_OACTIVE;
2734
2735 sc->an_rdata.an_tx_prod = idx;
2736
2737 /*

--- 16 unchanged lines hidden (view full) ---

2754 if (sc->an_gone) {
2755 AN_UNLOCK(sc);
2756 return;
2757 }
2758
2759 ifp = &sc->arpcom.ac_if;
2760
2761 an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
2065 CSR_WRITE_2(sc, AN_INT_EN, 0);
2762 CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
2066 an_cmd(sc, AN_CMD_DISABLE, 0);
2067
2068 for (i = 0; i < AN_TX_RING_CNT; i++)
2069 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2070
2071 untimeout(an_stats_update, sc, sc->an_stat_ch);
2072
2073 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2074
2763 an_cmd(sc, AN_CMD_DISABLE, 0);
2764
2765 for (i = 0; i < AN_TX_RING_CNT; i++)
2766 an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->an_rdata.an_tx_fids[i]);
2767
2768 untimeout(an_stats_update, sc, sc->an_stat_ch);
2769
2770 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2771
2772 if (sc->an_flash_buffer) {
2773 free(sc->an_flash_buffer, M_DEVBUF);
2774 sc->an_flash_buffer = NULL;
2775 }
2776
2075 AN_UNLOCK(sc);
2076
2077 return;
2078}
2079
2080static void
2081an_watchdog(ifp)
2082 struct ifnet *ifp;

--- 6 unchanged lines hidden (view full) ---

2089 if (sc->an_gone) {
2090 AN_UNLOCK(sc);
2091 return;
2092 }
2093
2094 printf("an%d: device timeout\n", sc->an_unit);
2095
2096 an_reset(sc);
2777 AN_UNLOCK(sc);
2778
2779 return;
2780}
2781
2782static void
2783an_watchdog(ifp)
2784 struct ifnet *ifp;

--- 6 unchanged lines hidden (view full) ---

2791 if (sc->an_gone) {
2792 AN_UNLOCK(sc);
2793 return;
2794 }
2795
2796 printf("an%d: device timeout\n", sc->an_unit);
2797
2798 an_reset(sc);
2799 if (sc->mpi350)
2800 an_init_mpi350_desc(sc);
2097 an_init(sc);
2098
2099 ifp->if_oerrors++;
2100 AN_UNLOCK(sc);
2101
2102 return;
2103}
2104

--- 65 unchanged lines hidden (view full) ---

2170SYSCTL_INT(_machdep, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2171 &an_cache_iponly, 0, "");
2172
2173/*
2174 * an_cache_store, per rx packet store signal
2175 * strength in MAC (src) indexed cache.
2176 */
2177static void
2801 an_init(sc);
2802
2803 ifp->if_oerrors++;
2804 AN_UNLOCK(sc);
2805
2806 return;
2807}
2808

--- 65 unchanged lines hidden (view full) ---

2874SYSCTL_INT(_machdep, OID_AUTO, an_cache_iponly, CTLFLAG_RW,
2875 &an_cache_iponly, 0, "");
2876
2877/*
2878 * an_cache_store, per rx packet store signal
2879 * strength in MAC (src) indexed cache.
2880 */
2881static void
2178an_cache_store (sc, eh, m, rx_quality)
2882an_cache_store (sc, eh, m, rx_rssi, rx_quality)
2179 struct an_softc *sc;
2180 struct ether_header *eh;
2181 struct mbuf *m;
2883 struct an_softc *sc;
2884 struct ether_header *eh;
2885 struct mbuf *m;
2182 unsigned short rx_quality;
2886 u_int8_t rx_rssi;
2887 u_int8_t rx_quality;
2183{
2184 struct ip *ip = 0;
2185 int i;
2186 static int cache_slot = 0; /* use this cache entry */
2187 static int wrapindex = 0; /* next "free" cache entry */
2188 int type_ipv4 = 0;
2189
2190 /* filters:

--- 15 unchanged lines hidden (view full) ---

2206 /* filter for broadcast/multicast only
2207 */
2208 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2209 return;
2210 }
2211
2212#ifdef SIGDEBUG
2213 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2888{
2889 struct ip *ip = 0;
2890 int i;
2891 static int cache_slot = 0; /* use this cache entry */
2892 static int wrapindex = 0; /* next "free" cache entry */
2893 int type_ipv4 = 0;
2894
2895 /* filters:

--- 15 unchanged lines hidden (view full) ---

2911 /* filter for broadcast/multicast only
2912 */
2913 if (an_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2914 return;
2915 }
2916
2917#ifdef SIGDEBUG
2918 printf("an: q value %x (MSB=0x%x, LSB=0x%x) \n",
2214 rx_quality & 0xffff, rx_quality >> 8, rx_quality & 0xff);
2919 rx_rssi & 0xffff, rx_rssi >> 8, rx_rssi & 0xff);
2215#endif
2216
2217 /* find the ip header. we want to store the ip_src
2218 * address.
2219 */
2220 if (type_ipv4) {
2221 ip = mtod(m, struct ip *);
2222 }

--- 60 unchanged lines hidden (view full) ---

2283 * .mac src
2284 * .signal, etc.
2285 */
2286 if (type_ipv4) {
2287 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2288 }
2289 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2290
2920#endif
2921
2922 /* find the ip header. we want to store the ip_src
2923 * address.
2924 */
2925 if (type_ipv4) {
2926 ip = mtod(m, struct ip *);
2927 }

--- 60 unchanged lines hidden (view full) ---

2988 * .mac src
2989 * .signal, etc.
2990 */
2991 if (type_ipv4) {
2992 sc->an_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2993 }
2994 bcopy( eh->ether_shost, sc->an_sigcache[cache_slot].macsrc, 6);
2995
2291 sc->an_sigcache[cache_slot].signal = rx_quality;
2292
2996
2997 switch (an_cache_mode) {
2998 case DBM:
2999 if (sc->an_have_rssimap) {
3000 sc->an_sigcache[cache_slot].signal =
3001 - sc->an_rssimap.an_entries[rx_rssi].an_rss_dbm;
3002 sc->an_sigcache[cache_slot].quality =
3003 - sc->an_rssimap.an_entries[rx_quality].an_rss_dbm;
3004 } else {
3005 sc->an_sigcache[cache_slot].signal = rx_rssi - 100;
3006 sc->an_sigcache[cache_slot].quality = rx_quality - 100;
3007 }
3008 break;
3009 case PERCENT:
3010 if (sc->an_have_rssimap) {
3011 sc->an_sigcache[cache_slot].signal =
3012 sc->an_rssimap.an_entries[rx_rssi].an_rss_pct;
3013 sc->an_sigcache[cache_slot].quality =
3014 sc->an_rssimap.an_entries[rx_quality].an_rss_pct;
3015 } else {
3016 if (rx_rssi > 100)
3017 rx_rssi = 100;
3018 if (rx_quality > 100)
3019 rx_quality = 100;
3020 sc->an_sigcache[cache_slot].signal = rx_rssi;
3021 sc->an_sigcache[cache_slot].quality = rx_quality;
3022 }
3023 break;
3024 case RAW:
3025 sc->an_sigcache[cache_slot].signal = rx_rssi;
3026 sc->an_sigcache[cache_slot].quality = rx_quality;
3027 break;
3028 }
3029
3030 sc->an_sigcache[cache_slot].noise = 0;
3031
2293 return;
2294}
2295#endif
2296
2297static int
2298an_media_change(ifp)
2299 struct ifnet *ifp;
2300{

--- 246 unchanged lines hidden (view full) ---

2547 return -EOPNOTSUPP;
2548}
2549
2550/*
2551 * General Flash utilities derived from Cisco driver additions to Ben Reed's
2552 * Linux driver
2553 */
2554
3032 return;
3033}
3034#endif
3035
3036static int
3037an_media_change(ifp)
3038 struct ifnet *ifp;
3039{

--- 246 unchanged lines hidden (view full) ---

3286 return -EOPNOTSUPP;
3287}
3288
3289/*
3290 * General Flash utilities derived from Cisco driver additions to Ben Reed's
3291 * Linux driver
3292 */
3293
2555#define FLASH_DELAY(x) tsleep(ifp, PZERO, "flash", ((x) / hz) + 1);
3294#define FLASH_DELAY(x) tsleep(ifp, PZERO, "flash", ((x) / hz) + 1);
3295#define FLASH_COMMAND 0x7e7e
3296#define FLASH_SIZE 32 * 1024
2556
2557static int
2558unstickbusy(ifp)
2559 struct ifnet *ifp;
2560{
2561 struct an_softc *sc = ifp->if_softc;
2562
3297
3298static int
3299unstickbusy(ifp)
3300 struct ifnet *ifp;
3301{
3302 struct an_softc *sc = ifp->if_softc;
3303
2563 if (CSR_READ_2(sc, AN_COMMAND) & AN_CMD_BUSY) {
2564 CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CLR_STUCK_BUSY);
3304 if (CSR_READ_2(sc, AN_COMMAND(sc->mpi350)) & AN_CMD_BUSY) {
3305 CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350),
3306 AN_EV_CLR_STUCK_BUSY);
2565 return 1;
2566 }
2567 return 0;
2568}
2569
2570/*
2571 * Wait for busy completion from card wait for delay uSec's Return true for
2572 * success meaning command reg is clear

--- 6 unchanged lines hidden (view full) ---

2579{
2580 int statword = 0xffff;
2581 int delay = 0;
2582 struct an_softc *sc = ifp->if_softc;
2583
2584 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
2585 FLASH_DELAY(10);
2586 delay += 10;
3307 return 1;
3308 }
3309 return 0;
3310}
3311
3312/*
3313 * Wait for busy completion from card wait for delay uSec's Return true for
3314 * success meaning command reg is clear

--- 6 unchanged lines hidden (view full) ---

3321{
3322 int statword = 0xffff;
3323 int delay = 0;
3324 struct an_softc *sc = ifp->if_softc;
3325
3326 while ((statword & AN_CMD_BUSY) && delay <= (1000 * 100)) {
3327 FLASH_DELAY(10);
3328 delay += 10;
2587 statword = CSR_READ_2(sc, AN_COMMAND);
3329 statword = CSR_READ_2(sc, AN_COMMAND(sc->mpi350));
2588
2589 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
2590 unstickbusy(ifp);
2591 }
2592 }
2593
2594 return 0 == (AN_CMD_BUSY & statword);
2595}

--- 8 unchanged lines hidden (view full) ---

2604{
2605 int status;
2606 struct an_softc *sc = ifp->if_softc;
2607
2608 an_stop(sc);
2609
2610 an_cmd(sc, AN_CMD_DISABLE, 0);
2611
3330
3331 if ((AN_CMD_BUSY & statword) && (delay % 200)) {
3332 unstickbusy(ifp);
3333 }
3334 }
3335
3336 return 0 == (AN_CMD_BUSY & statword);
3337}

--- 8 unchanged lines hidden (view full) ---

3346{
3347 int status;
3348 struct an_softc *sc = ifp->if_softc;
3349
3350 an_stop(sc);
3351
3352 an_cmd(sc, AN_CMD_DISABLE, 0);
3353
2612 if (!(status = WaitBusy(ifp, 600))) {
3354 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
2613 printf("an%d: Waitbusy hang b4 RESET =%d\n",
2614 sc->an_unit, status);
2615 return -EBUSY;
2616 }
3355 printf("an%d: Waitbusy hang b4 RESET =%d\n",
3356 sc->an_unit, status);
3357 return -EBUSY;
3358 }
2617 CSR_WRITE_2(sc, AN_COMMAND, AN_CMD_FW_RESTART);
3359 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), AN_CMD_FW_RESTART);
2618
2619 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
2620
2621
2622 if (!(status = WaitBusy(ifp, 100))) {
2623 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
2624 sc->an_unit, status);
2625 return -EBUSY;
2626 }
2627 return 0;
2628}
2629
2630/*
2631 * STEP 2) Put the card in legendary flash mode
2632 */
3360
3361 FLASH_DELAY(1000); /* WAS 600 12/7/00 */
3362
3363
3364 if (!(status = WaitBusy(ifp, 100))) {
3365 printf("an%d: Waitbusy hang AFTER RESET =%d\n",
3366 sc->an_unit, status);
3367 return -EBUSY;
3368 }
3369 return 0;
3370}
3371
3372/*
3373 * STEP 2) Put the card in legendary flash mode
3374 */
2633#define FLASH_COMMAND 0x7e7e
2634
2635static int
2636setflashmode(ifp)
2637 struct ifnet *ifp;
2638{
2639 int status;
2640 struct an_softc *sc = ifp->if_softc;
2641
3375
3376static int
3377setflashmode(ifp)
3378 struct ifnet *ifp;
3379{
3380 int status;
3381 struct an_softc *sc = ifp->if_softc;
3382
2642 CSR_WRITE_2(sc, AN_SW0, FLASH_COMMAND);
2643 CSR_WRITE_2(sc, AN_SW1, FLASH_COMMAND);
2644 CSR_WRITE_2(sc, AN_SW0, FLASH_COMMAND);
2645 CSR_WRITE_2(sc, AN_COMMAND, FLASH_COMMAND);
3383 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3384 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), FLASH_COMMAND);
3385 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), FLASH_COMMAND);
3386 CSR_WRITE_2(sc, AN_COMMAND(sc->mpi350), FLASH_COMMAND);
2646
2647 /*
2648 * mdelay(500); // 500ms delay
2649 */
2650
2651 FLASH_DELAY(500);
2652
3387
3388 /*
3389 * mdelay(500); // 500ms delay
3390 */
3391
3392 FLASH_DELAY(500);
3393
2653 if (!(status = WaitBusy(ifp, 600))) {
3394 if (!(status = WaitBusy(ifp, AN_TIMEOUT))) {
2654 printf("Waitbusy hang after setflash mode\n");
2655 return -EIO;
2656 }
2657 return 0;
2658}
2659
2660/*
2661 * Get a character from the card matching matchbyte Step 3)

--- 7 unchanged lines hidden (view full) ---

2669{
2670 int rchar;
2671 unsigned char rbyte = 0;
2672 int success = -1;
2673 struct an_softc *sc = ifp->if_softc;
2674
2675
2676 do {
3395 printf("Waitbusy hang after setflash mode\n");
3396 return -EIO;
3397 }
3398 return 0;
3399}
3400
3401/*
3402 * Get a character from the card matching matchbyte Step 3)

--- 7 unchanged lines hidden (view full) ---

3410{
3411 int rchar;
3412 unsigned char rbyte = 0;
3413 int success = -1;
3414 struct an_softc *sc = ifp->if_softc;
3415
3416
3417 do {
2677 rchar = CSR_READ_2(sc, AN_SW1);
3418 rchar = CSR_READ_2(sc, AN_SW1(sc->mpi350));
2678
2679 if (dwelltime && !(0x8000 & rchar)) {
2680 dwelltime -= 10;
2681 FLASH_DELAY(10);
2682 continue;
2683 }
2684 rbyte = 0xff & rchar;
2685
2686 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
3419
3420 if (dwelltime && !(0x8000 & rchar)) {
3421 dwelltime -= 10;
3422 FLASH_DELAY(10);
3423 continue;
3424 }
3425 rbyte = 0xff & rchar;
3426
3427 if ((rbyte == matchbyte) && (0x8000 & rchar)) {
2687 CSR_WRITE_2(sc, AN_SW1, 0);
3428 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
2688 success = 1;
2689 break;
2690 }
2691 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
2692 break;
3429 success = 1;
3430 break;
3431 }
3432 if (rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
3433 break;
2693 CSR_WRITE_2(sc, AN_SW1, 0);
3434 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
2694
2695 } while (dwelltime > 0);
2696 return success;
2697}
2698
2699/*
2700 * Put character to SWS0 wait for dwelltime x 50us for echo .
2701 */

--- 14 unchanged lines hidden (view full) ---

2716 dwelltime = 200;
2717
2718 waittime = dwelltime;
2719
2720 /*
2721 * Wait for busy bit d15 to go false indicating buffer empty
2722 */
2723 do {
3435
3436 } while (dwelltime > 0);
3437 return success;
3438}
3439
3440/*
3441 * Put character to SWS0 wait for dwelltime x 50us for echo .
3442 */

--- 14 unchanged lines hidden (view full) ---

3457 dwelltime = 200;
3458
3459 waittime = dwelltime;
3460
3461 /*
3462 * Wait for busy bit d15 to go false indicating buffer empty
3463 */
3464 do {
2724 pollbusy = CSR_READ_2(sc, AN_SW0);
3465 pollbusy = CSR_READ_2(sc, AN_SW0(sc->mpi350));
2725
2726 if (pollbusy & 0x8000) {
2727 FLASH_DELAY(50);
2728 waittime -= 50;
2729 continue;
2730 } else
2731 break;
2732 }

--- 5 unchanged lines hidden (view full) ---

2738 printf("an%d: flash putchar busywait timeout! \n",
2739 sc->an_unit);
2740 return -1;
2741 }
2742 /*
2743 * Port is clear now write byte and wait for it to echo back
2744 */
2745 do {
3466
3467 if (pollbusy & 0x8000) {
3468 FLASH_DELAY(50);
3469 waittime -= 50;
3470 continue;
3471 } else
3472 break;
3473 }

--- 5 unchanged lines hidden (view full) ---

3479 printf("an%d: flash putchar busywait timeout! \n",
3480 sc->an_unit);
3481 return -1;
3482 }
3483 /*
3484 * Port is clear now write byte and wait for it to echo back
3485 */
3486 do {
2746 CSR_WRITE_2(sc, AN_SW0, byte);
3487 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), byte);
2747 FLASH_DELAY(50);
2748 dwelltime -= 50;
3488 FLASH_DELAY(50);
3489 dwelltime -= 50;
2749 echo = CSR_READ_2(sc, AN_SW1);
3490 echo = CSR_READ_2(sc, AN_SW1(sc->mpi350));
2750 } while (dwelltime >= 0 && echo != byte);
2751
2752
3491 } while (dwelltime >= 0 && echo != byte);
3492
3493
2753 CSR_WRITE_2(sc, AN_SW1, 0);
3494 CSR_WRITE_2(sc, AN_SW1(sc->mpi350), 0);
2754
2755 return echo == byte;
2756}
2757
2758/*
2759 * Transfer 32k of firmware data from user buffer to our buffer and send to
2760 * the card
2761 */
2762
3495
3496 return echo == byte;
3497}
3498
3499/*
3500 * Transfer 32k of firmware data from user buffer to our buffer and send to
3501 * the card
3502 */
3503
2763static char flashbuffer[1024 * 38]; /* RAW Buffer for flash will be
2764 * dynamic next */
2765
2766static int
2767flashputbuf(ifp)
2768 struct ifnet *ifp;
2769{
2770 unsigned short *bufp;
2771 int nwords;
2772 struct an_softc *sc = ifp->if_softc;
2773
2774 /* Write stuff */
2775
3504static int
3505flashputbuf(ifp)
3506 struct ifnet *ifp;
3507{
3508 unsigned short *bufp;
3509 int nwords;
3510 struct an_softc *sc = ifp->if_softc;
3511
3512 /* Write stuff */
3513
2776 bufp = (unsigned short *)flashbuffer;
3514 bufp = sc->an_flash_buffer;
2777
3515
2778 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
2779 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
3516 if (!sc->mpi350) {
3517 CSR_WRITE_2(sc, AN_AUX_PAGE, 0x100);
3518 CSR_WRITE_2(sc, AN_AUX_OFFSET, 0);
2780
3519
2781 for (nwords = 0; nwords != 16384; nwords++) {
2782 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3520 for (nwords = 0; nwords != FLASH_SIZE / 2; nwords++) {
3521 CSR_WRITE_2(sc, AN_AUX_DATA, bufp[nwords] & 0xffff);
3522 }
3523 } else {
3524 for (nwords = 0; nwords != FLASH_SIZE / 4; nwords++) {
3525 CSR_MEM_AUX_WRITE_4(sc, 0x8000,
3526 ((u_int32_t *)bufp)[nwords] & 0xffff);
3527 }
2783 }
2784
3528 }
3529
2785 CSR_WRITE_2(sc, AN_SW0, 0x8000);
3530 CSR_WRITE_2(sc, AN_SW0(sc->mpi350), 0x8000);
2786
2787 return 0;
2788}
2789
2790/*
2791 * After flashing restart the card.
2792 */
2793

--- 20 unchanged lines hidden (view full) ---

2814flashcard(ifp, l_ioctl)
2815 struct ifnet *ifp;
2816 struct aironet_ioctl *l_ioctl;
2817{
2818 int z = 0, status;
2819 struct an_softc *sc;
2820
2821 sc = ifp->if_softc;
3531
3532 return 0;
3533}
3534
3535/*
3536 * After flashing restart the card.
3537 */
3538

--- 20 unchanged lines hidden (view full) ---

3559flashcard(ifp, l_ioctl)
3560 struct ifnet *ifp;
3561 struct aironet_ioctl *l_ioctl;
3562{
3563 int z = 0, status;
3564 struct an_softc *sc;
3565
3566 sc = ifp->if_softc;
3567 if (sc->mpi350) {
3568 printf("an%d: flashing not supported on MPI 350 yet\n",
3569 sc->an_unit);
3570 return(-1);
3571 }
2822 status = l_ioctl->command;
2823
2824 switch (l_ioctl->command) {
2825 case AIROFLSHRST:
2826 return cmdreset(ifp);
2827 break;
2828 case AIROFLSHSTFL:
3572 status = l_ioctl->command;
3573
3574 switch (l_ioctl->command) {
3575 case AIROFLSHRST:
3576 return cmdreset(ifp);
3577 break;
3578 case AIROFLSHSTFL:
2829 return setflashmode(ifp);
3579 if (sc->an_flash_buffer) {
3580 free(sc->an_flash_buffer, M_DEVBUF);
3581 sc->an_flash_buffer = NULL;
3582 }
3583 sc->an_flash_buffer = malloc(FLASH_SIZE, M_DEVBUF, M_WAITOK);
3584 if (sc->an_flash_buffer)
3585 return setflashmode(ifp);
3586 else
3587 return ENOBUFS;
2830 break;
2831 case AIROFLSHGCHR: /* Get char from aux */
2832 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
2833 z = *(int *)&sc->areq;
2834 if ((status = flashgchar(ifp, z, 8000)) == 1)
2835 return 0;
2836 else
2837 return -1;
2838 break;
2839 case AIROFLSHPCHR: /* Send char to card. */
2840 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
2841 z = *(int *)&sc->areq;
2842 if ((status = flashpchar(ifp, z, 8000)) == -1)
2843 return -EIO;
2844 else
2845 return 0;
2846 break;
2847 case AIROFLPUTBUF: /* Send 32k to card */
3588 break;
3589 case AIROFLSHGCHR: /* Get char from aux */
3590 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3591 z = *(int *)&sc->areq;
3592 if ((status = flashgchar(ifp, z, 8000)) == 1)
3593 return 0;
3594 else
3595 return -1;
3596 break;
3597 case AIROFLSHPCHR: /* Send char to card. */
3598 copyin(l_ioctl->data, &sc->areq, l_ioctl->len);
3599 z = *(int *)&sc->areq;
3600 if ((status = flashpchar(ifp, z, 8000)) == -1)
3601 return -EIO;
3602 else
3603 return 0;
3604 break;
3605 case AIROFLPUTBUF: /* Send 32k to card */
2848 if (l_ioctl->len > sizeof(flashbuffer)) {
2849 printf("an%d: Buffer to big, %x %zx\n", sc->an_unit,
2850 l_ioctl->len, sizeof(flashbuffer));
3606 if (l_ioctl->len > FLASH_SIZE) {
3607 printf("an%d: Buffer to big, %x %x\n", sc->an_unit,
3608 l_ioctl->len, FLASH_SIZE);
2851 return -EINVAL;
2852 }
3609 return -EINVAL;
3610 }
2853 copyin(l_ioctl->data, &flashbuffer, l_ioctl->len);
3611 copyin(l_ioctl->data, sc->an_flash_buffer, l_ioctl->len);
2854
2855 if ((status = flashputbuf(ifp)) != 0)
2856 return -EIO;
2857 else
2858 return 0;
2859 break;
2860 case AIRORESTART:
2861 if ((status = flashrestart(ifp)) != 0) {

--- 5 unchanged lines hidden (view full) ---

2867
2868 break;
2869 default:
2870 return -EINVAL;
2871 }
2872
2873 return -EINVAL;
2874}
3612
3613 if ((status = flashputbuf(ifp)) != 0)
3614 return -EIO;
3615 else
3616 return 0;
3617 break;
3618 case AIRORESTART:
3619 if ((status = flashrestart(ifp)) != 0) {

--- 5 unchanged lines hidden (view full) ---

3625
3626 break;
3627 default:
3628 return -EINVAL;
3629 }
3630
3631 return -EINVAL;
3632}
2875