Deleted Added
full compact
if_cs.c (67164) if_cs.c (71316)
1/*
2 * Copyright (c) 1997,1998 Maxim Bolotin and Oleg Sharoiko.
3 * 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

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

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29/*
1/*
2 * Copyright (c) 1997,1998 Maxim Bolotin and Oleg Sharoiko.
3 * 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

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

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29/*
30 * $FreeBSD: head/sys/dev/cs/if_cs.c 67164 2000-10-15 14:19:01Z phk $
30 * $FreeBSD: head/sys/dev/cs/if_cs.c 71316 2001-01-21 04:56:12Z imp $
31 *
32 * Device driver for Crystal Semiconductor CS8920 based ethernet
33 * adapters. By Maxim Bolotin and Oleg Sharoiko, 27-April-1997
34 */
35
36/*
37#define CS_DEBUG
38 */

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

52#include <machine/bus.h>
53#include <sys/rman.h>
54#include <machine/resource.h>
55
56#include <net/if.h>
57#include <net/if_arp.h>
58#include <net/if_media.h>
59#include <net/ethernet.h>
31 *
32 * Device driver for Crystal Semiconductor CS8920 based ethernet
33 * adapters. By Maxim Bolotin and Oleg Sharoiko, 27-April-1997
34 */
35
36/*
37#define CS_DEBUG
38 */

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

52#include <machine/bus.h>
53#include <sys/rman.h>
54#include <machine/resource.h>
55
56#include <net/if.h>
57#include <net/if_arp.h>
58#include <net/if_media.h>
59#include <net/ethernet.h>
60
61#include <net/bpf.h>
62
60#include <net/bpf.h>
61
63#include <isa/isavar.h>
64
65
66#include <dev/cs/if_csreg.h>
62#include <dev/cs/if_csreg.h>
63#include <dev/cs/if_csvar.h>
67
68#ifdef CS_USE_64K_DMA
69#define CS_DMA_BUFFER_SIZE 65536
70#else
71#define CS_DMA_BUFFER_SIZE 16384
72#endif
73
64
65#ifdef CS_USE_64K_DMA
66#define CS_DMA_BUFFER_SIZE 65536
67#else
68#define CS_DMA_BUFFER_SIZE 16384
69#endif
70
74/*
75 * cs_softc: per line info and status
76 */
77struct cs_softc {
78
79 /* Ethernet common code */
80 struct arpcom arpcom;
81
82 /* Configuration words from EEPROM */
83 int auto_neg_cnf; /* AutoNegotitation configuration */
84 int adapter_cnf; /* Adapter configuration */
85 int isa_config; /* ISA configuration */
86 int chip_type; /* Type of chip */
87
88 struct ifmedia media; /* Media information */
89
90 int port_rid; /* resource id for port range */
91 int port_used; /* nonzero if ports used */
92 struct resource* port_res; /* resource for port range */
93 int mem_rid; /* resource id for memory range */
94 int mem_used; /* nonzero if memory used */
95 struct resource* mem_res; /* resource for memory range */
96 int irq_rid; /* resource id for irq */
97 struct resource* irq_res; /* resource for irq */
98 void* irq_handle; /* handle for irq handler */
99
100 int nic_addr; /* Base IO address of card */
101 int send_cmd;
102 int line_ctl; /* */
103 int send_underrun;
104 void *recv_ring;
105
106 unsigned char *buffer;
107 int buf_len;
108};
109
110static int cs_recv_delay = 570;
111SYSCTL_INT(_machdep, OID_AUTO, cs_recv_delay, CTLFLAG_RW, &cs_recv_delay, 0, "");
112
71static int cs_recv_delay = 570;
72SYSCTL_INT(_machdep, OID_AUTO, cs_recv_delay, CTLFLAG_RW, &cs_recv_delay, 0, "");
73
113static int cs_isa_probe __P((device_t dev));
114static int cs_isa_attach __P((device_t dev));
74static void cs_init (void *);
75static int cs_ioctl (struct ifnet *, u_long, caddr_t);
76static void cs_start (struct ifnet *);
77static void cs_stop (struct cs_softc *);
78static void cs_reset (struct cs_softc *);
79static void cs_watchdog (struct ifnet *);
115
80
116static int cs_cs89x0_probe __P((device_t dev));
81static int cs_mediachange (struct ifnet *);
82static void cs_mediastatus (struct ifnet *, struct ifmediareq *);
83static int cs_mediaset (struct cs_softc *, int);
117
84
118driver_intr_t csintr;
119
120static int cs_attach __P((struct cs_softc *, int, int));
121
122static void cs_init __P((void *));
123static int cs_ioctl __P((struct ifnet *, u_long, caddr_t));
124static void cs_start __P((struct ifnet *));
125static void cs_stop __P((struct cs_softc *));
126static void cs_reset __P((struct cs_softc *));
127static void cs_watchdog __P((struct ifnet *));
128
129static int cs_alloc_port(device_t dev, int rid, int size);
130static int cs_alloc_memory(device_t dev, int rid, int size);
131static int cs_alloc_irq(device_t dev, int rid, int flags);
132static void cs_release_resources(device_t dev);
133
134static int cs_mediachange __P((struct ifnet *));
135static void cs_mediastatus __P((struct ifnet *, struct ifmediareq *));
136static int cs_mediaset __P((struct cs_softc *, int));
137
138static void cs_write_mbufs(struct cs_softc*, struct mbuf*);
139static void cs_xmit_buf(struct cs_softc*);
140static int cs_get_packet(struct cs_softc*);
141static void cs_setmode(struct cs_softc*);
142
143static int get_eeprom_data(struct cs_softc *sc, int, int, int *);
144static int get_eeprom_cksum(int, int, int *);
145static int wait_eeprom_ready( struct cs_softc *);
146static void control_dc_dc( struct cs_softc *, int );
147static int send_test_pkt( struct cs_softc * );
148static int enable_tp(struct cs_softc *);
149static int enable_aui(struct cs_softc *);
150static int enable_bnc(struct cs_softc *);
151static int cs_duplex_auto(struct cs_softc *);
152
85static void cs_write_mbufs(struct cs_softc*, struct mbuf*);
86static void cs_xmit_buf(struct cs_softc*);
87static int cs_get_packet(struct cs_softc*);
88static void cs_setmode(struct cs_softc*);
89
90static int get_eeprom_data(struct cs_softc *sc, int, int, int *);
91static int get_eeprom_cksum(int, int, int *);
92static int wait_eeprom_ready( struct cs_softc *);
93static void control_dc_dc( struct cs_softc *, int );
94static int send_test_pkt( struct cs_softc * );
95static int enable_tp(struct cs_softc *);
96static int enable_aui(struct cs_softc *);
97static int enable_bnc(struct cs_softc *);
98static int cs_duplex_auto(struct cs_softc *);
99
153static device_method_t cs_methods[] = {
154 /* Device interface */
155 DEVMETHOD(device_probe, cs_isa_probe),
156 DEVMETHOD(device_attach, cs_isa_attach),
157 { 0, 0 }
158};
100devclass_t cs_devclass;
159
101
160static driver_t cs_driver = {
161 "cs",
162 cs_methods,
163 sizeof(struct cs_softc)
164};
165
166static devclass_t cs_devclass;
167
168DRIVER_MODULE(cs, isa, cs_driver, cs_devclass, 0, 0);
169
170static int
171get_eeprom_data( struct cs_softc *sc, int off, int len, int *buffer)
172{
173 int i;
174
175#ifdef CS_DEBUG
176 printf(CS_NAME":EEPROM data from %x for %x:\n", off,len);
177#endif

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

353
354 if (!send_test_pkt(sc)) {
355 printf(CS_NAME"%1d failed to enable BNC\n", unit);
356 return EINVAL;
357 }
358 return 0;
359}
360
102static int
103get_eeprom_data( struct cs_softc *sc, int off, int len, int *buffer)
104{
105 int i;
106
107#ifdef CS_DEBUG
108 printf(CS_NAME":EEPROM data from %x for %x:\n", off,len);
109#endif

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

285
286 if (!send_test_pkt(sc)) {
287 printf(CS_NAME"%1d failed to enable BNC\n", unit);
288 return EINVAL;
289 }
290 return 0;
291}
292
361static int
293int
362cs_cs89x0_probe(device_t dev)
363{
364 int i;
365 int iobase;
366 int error;
367
368 u_long irq, junk;
369

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

638 }
639 if (sc->irq_res) {
640 bus_release_resource(dev, SYS_RES_IRQ,
641 sc->irq_rid, sc->irq_res);
642 sc->irq_res = 0;
643 }
644}
645
294cs_cs89x0_probe(device_t dev)
295{
296 int i;
297 int iobase;
298 int error;
299
300 u_long irq, junk;
301

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

570 }
571 if (sc->irq_res) {
572 bus_release_resource(dev, SYS_RES_IRQ,
573 sc->irq_rid, sc->irq_res);
574 sc->irq_res = 0;
575 }
576}
577
646static struct isa_pnp_id cs_ids[] = {
647 { 0x4060630e, NULL }, /* CSC6040 */
648 { 0x10104d24, NULL }, /* IBM EtherJet */
649 { 0, NULL }
650};
651
652/*
578/*
653 * Determine if the device is present
654 */
655static int
656cs_isa_probe(device_t dev)
657{
658 int error = 0;
659
660 struct cs_softc *sc = device_get_softc(dev);
661
662 bzero(sc, sizeof(struct cs_softc));
663
664 /* Check isapnp ids */
665 error = ISA_PNP_PROBE(device_get_parent(dev), dev, cs_ids);
666
667 /* If the card had a PnP ID that didn't match any we know about */
668 if (error == ENXIO) {
669 goto end;
670 }
671
672 /* If we had some other problem. */
673 if (!(error == 0 || error == ENOENT)) {
674 goto end;
675 }
676
677 error=cs_cs89x0_probe(dev);
678
679end:
680 if (error == 0)
681 error = cs_alloc_irq(dev, 0, 0);
682
683 cs_release_resources(dev);
684 return (error);
685}
686
687static int cs_isa_attach(device_t dev)
688{
689 struct cs_softc *sc = device_get_softc(dev);
690 int flags = device_get_flags(dev);
691 int error;
692
693 if (sc->port_used > 0)
694 cs_alloc_port(dev, sc->port_rid, sc->port_used);
695 if (sc->mem_used)
696 cs_alloc_memory(dev, sc->mem_rid, sc->mem_used);
697 cs_alloc_irq(dev, sc->irq_rid, 0);
698
699 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
700 csintr, sc, &sc->irq_handle);
701 if (error) {
702 cs_release_resources(dev);
703 return (error);
704 }
705
706 return cs_attach(sc, device_get_unit(dev), flags);
707}
708
709/*
710 * Install the interface into kernel networking data structures
711 */
579 * Install the interface into kernel networking data structures
580 */
712static int
581int
713cs_attach(struct cs_softc *sc, int unit, int flags)
714{
715 int media=0;
716 struct ifnet *ifp = &(sc->arpcom.ac_if);
717
718 cs_stop( sc );
719
720 if (!ifp->if_name) {

--- 679 unchanged lines hidden ---
582cs_attach(struct cs_softc *sc, int unit, int flags)
583{
584 int media=0;
585 struct ifnet *ifp = &(sc->arpcom.ac_if);
586
587 cs_stop( sc );
588
589 if (!ifp->if_name) {

--- 679 unchanged lines hidden ---