2 * Copyright (c) 1997,1998 Maxim Bolotin and Oleg Sharoiko.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 * Device driver for Crystal Semiconductor CS8920 based ethernet
35 * adapters. By Maxim Bolotin and Oleg Sharoiko, 27-April-1997
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
46 #include <sys/socket.h>
47 #include <sys/sockio.h>
48 #include <sys/kernel.h>
49 #include <sys/sysctl.h>
50 #include <sys/syslog.h>
52 #include <sys/module.h>
54 #include <machine/bus.h>
56 #include <machine/resource.h>
59 #include <net/if_arp.h>
60 #include <net/if_media.h>
61 #include <net/ethernet.h>
64 #include <dev/cs/if_csvar.h>
65 #include <dev/cs/if_csreg.h>
68 #define CS_DMA_BUFFER_SIZE 65536
70 #define CS_DMA_BUFFER_SIZE 16384
73 static int cs_recv_delay = 570;
74 SYSCTL_INT(_machdep, OID_AUTO, cs_recv_delay, CTLFLAG_RW, &cs_recv_delay, 0, "");
76 static void cs_init (void *);
77 static int cs_ioctl (struct ifnet *, u_long, caddr_t);
78 static void cs_start (struct ifnet *);
79 static void cs_stop (struct cs_softc *);
80 static void cs_reset (struct cs_softc *);
81 static void cs_watchdog (struct ifnet *);
83 static int cs_mediachange (struct ifnet *);
84 static void cs_mediastatus (struct ifnet *, struct ifmediareq *);
85 static int cs_mediaset (struct cs_softc *, int);
87 static void cs_write_mbufs(struct cs_softc*, struct mbuf*);
88 static void cs_xmit_buf(struct cs_softc*);
89 static int cs_get_packet(struct cs_softc*);
90 static void cs_setmode(struct cs_softc*);
92 static int get_eeprom_data(struct cs_softc *sc, int, int, int *);
93 static int get_eeprom_cksum(int, int, int *);
94 static int wait_eeprom_ready( struct cs_softc *);
95 static void control_dc_dc( struct cs_softc *, int );
96 static int send_test_pkt( struct cs_softc * );
97 static int enable_tp(struct cs_softc *);
98 static int enable_aui(struct cs_softc *);
99 static int enable_bnc(struct cs_softc *);
100 static int cs_duplex_auto(struct cs_softc *);
102 devclass_t cs_devclass;
105 get_eeprom_data( struct cs_softc *sc, int off, int len, int *buffer)
110 printf(CS_NAME":EEPROM data from %x for %x:\n", off,len);
113 for (i=0;i<len;i++) {
114 if (wait_eeprom_ready(sc) < 0) return -1;
115 /* Send command to EEPROM to read */
116 cs_writereg(sc, PP_EECMD, (off + i) | EEPROM_READ_CMD);
117 if (wait_eeprom_ready(sc)<0)
119 buffer[i] = cs_readreg(sc, PP_EEData);
122 printf("%02x %02x ",(unsigned char)buffer[i],
123 (unsigned char)buffer[i+1]);
134 get_eeprom_cksum(int off, int len, int *buffer)
147 wait_eeprom_ready(struct cs_softc *sc)
149 DELAY ( 30000 ); /* XXX should we do some checks here ? */
154 control_dc_dc(struct cs_softc *sc, int on_not_off)
156 unsigned int self_control = HCB1_ENBL;
158 if (((sc->adapter_cnf & A_CNF_DC_DC_POLARITY)!=0) ^ on_not_off)
159 self_control |= HCB1;
161 self_control &= ~HCB1;
162 cs_writereg(sc, PP_SelfCTL, self_control);
169 cs_duplex_auto(struct cs_softc *sc)
173 cs_writereg(sc, PP_AutoNegCTL,
174 RE_NEG_NOW | ALLOW_FDX | AUTO_NEG_ENABLE);
175 for (i=0; cs_readreg(sc, PP_AutoNegST) & AUTO_NEG_BUSY; i++) {
177 if_printf(&sc->arpcom.ac_if,
178 "full/half duplex auto negotiation timeout\n");
189 enable_tp(struct cs_softc *sc)
192 cs_writereg(sc, PP_LineCTL, sc->line_ctl & ~AUI_ONLY);
193 control_dc_dc(sc, 0);
196 if ((cs_readreg(sc, PP_LineST) & LINK_OK)==0) {
197 if_printf(&sc->arpcom.ac_if, "failed to enable TP\n");
205 * XXX This was rewritten from Linux driver without any tests.
208 send_test_pkt(struct cs_softc *sc)
210 char test_packet[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
211 0, 46, /* A 46 in network order */
212 0, 0, /* DSAP=0 & SSAP=0 fields */
213 0xf3, 0 /* Control (Test Req + P bit set) */ };
215 u_char ether_address_backup[ETHER_ADDR_LEN];
217 for (i = 0; i < ETHER_ADDR_LEN; i++) {
218 ether_address_backup[i] = sc->arpcom.ac_enaddr[i];
221 cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) | SERIAL_TX_ON);
222 bcopy(test_packet, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
223 bcopy(test_packet+ETHER_ADDR_LEN,
224 sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
225 cs_outw(sc, TX_CMD_PORT, sc->send_cmd);
226 cs_outw(sc, TX_LEN_PORT, sizeof(test_packet));
228 /* Wait for chip to allocate memory */
230 if (!(cs_readreg(sc, PP_BusST) & READY_FOR_TX_NOW)) {
231 for (i = 0; i < ETHER_ADDR_LEN; i++) {
232 sc->arpcom.ac_enaddr[i] = ether_address_backup[i];
237 outsw(sc->nic_addr + TX_FRAME_PORT, test_packet, sizeof(test_packet));
241 if ((cs_readreg(sc, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
242 for (i = 0; i < ETHER_ADDR_LEN; i++) {
243 sc->arpcom.ac_enaddr[i] = ether_address_backup[i];
247 for (i = 0; i < ETHER_ADDR_LEN; i++) {
248 sc->arpcom.ac_enaddr[i] = ether_address_backup[i];
254 * XXX This was rewritten from Linux driver without any tests.
257 enable_aui(struct cs_softc *sc)
260 control_dc_dc(sc, 0);
261 cs_writereg(sc, PP_LineCTL,
262 (sc->line_ctl & ~AUTO_AUI_10BASET) | AUI_ONLY);
264 if (!send_test_pkt(sc)) {
265 if_printf(&sc->arpcom.ac_if, "failed to enable AUI\n");
272 * XXX This was rewritten from Linux driver without any tests.
275 enable_bnc(struct cs_softc *sc)
278 control_dc_dc(sc, 1);
279 cs_writereg(sc, PP_LineCTL,
280 (sc->line_ctl & ~AUTO_AUI_10BASET) | AUI_ONLY);
282 if (!send_test_pkt(sc)) {
283 if_printf(&sc->arpcom.ac_if, "failed to enable BNC\n");
290 cs_cs89x0_probe(device_t dev)
295 struct cs_softc *sc = device_get_softc(dev);
296 unsigned rev_type = 0;
299 int eeprom_buff[CHKSUM_LEN];
300 int chip_type, pp_isaint, pp_isadma;
302 error = cs_alloc_port(dev, 0, CS_89x0_IO_PORTS);
306 sc->nic_addr = rman_get_start(sc->port_res);
308 if ((cs_inw(sc, ADD_PORT) & ADD_MASK) != ADD_SIG) {
309 /* Chip not detected. Let's try to reset it */
311 device_printf(dev, "trying to reset the chip.\n");
312 cs_outw(sc, ADD_PORT, PP_SelfCTL);
313 i = cs_inw(sc, DATA_PORT);
314 cs_outw(sc, ADD_PORT, PP_SelfCTL);
315 cs_outw(sc, DATA_PORT, i | POWER_ON_RESET);
316 if ((cs_inw(sc, ADD_PORT) & ADD_MASK) != ADD_SIG)
320 for (i = 0; i < 10000; i++) {
321 id = cs_readreg(sc, PP_ChipID);
322 if (id == CHIP_EISA_ID_SIG)
328 rev_type = cs_readreg(sc, PRODUCT_ID_ADD);
329 chip_type = rev_type & ~REVISON_BITS;
330 chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
332 sc->chip_type = chip_type;
334 if(chip_type==CS8900) {
335 pp_isaint = PP_CS8900_ISAINT;
336 pp_isadma = PP_CS8900_ISADMA;
337 sc->send_cmd = TX_CS8900_AFTER_ALL;
339 pp_isaint = PP_CS8920_ISAINT;
340 pp_isadma = PP_CS8920_ISADMA;
341 sc->send_cmd = TX_CS8920_AFTER_ALL;
345 * Clear some fields so that fail of EEPROM will left them clean
347 sc->auto_neg_cnf = 0;
352 * If no interrupt specified (or "?"), use what the board tells us.
354 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, &junk);
357 * Get data from EEPROM
359 if((cs_readreg(sc, PP_SelfST) & EEPROM_PRESENT) == 0) {
360 device_printf(dev, "No EEPROM, assuming defaults.\n");
362 if (get_eeprom_data(sc,START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
363 device_printf(dev, "EEPROM read failed, "
364 "assuming defaults.\n");
366 if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN, eeprom_buff)<0) {
367 device_printf(dev, "EEPROM cheksum bad, "
368 "assuming defaults.\n");
371 eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
373 eeprom_buff[ADAPTER_CNF_OFFSET/2];
375 eeprom_buff[ISA_CNF_OFFSET/2];
377 for (i=0; i<ETHER_ADDR_LEN/2; i++) {
378 sc->arpcom.ac_enaddr[i*2]=
380 sc->arpcom.ac_enaddr[i*2+1]=
385 * If no interrupt specified (or "?"),
386 * use what the board tells us.
389 irq = sc->isa_config & INT_NO_MASK;
390 if (chip_type==CS8900) {
409 device_printf(dev, "invalid irq in EEPROM.\n");
413 if (irq>CS8920_NO_INTS) {
414 device_printf(dev, "invalid irq in EEPROM.\n");
422 bus_set_resource(dev, SYS_RES_IRQ, 0,
430 if (chip_type == CS8900) {
448 if (irq > CS8920_NO_INTS) {
455 cs_writereg(sc, pp_isaint, irq);
457 device_printf(dev, "Unknown or invalid irq\n");
465 cs_writereg(sc, pp_isadma, drq);
467 device_printf(dev, "incorrect drq\n",);
473 device_printf(dev, "CS89%c0%s rev %c media%s%s%s\n",
474 chip_type==CS8900 ? '0' : '2',
475 chip_type==CS8920M ? "M" : "",
477 (sc->adapter_cnf & A_CNF_10B_T) ? " TP" : "",
478 (sc->adapter_cnf & A_CNF_AUI) ? " AUI" : "",
479 (sc->adapter_cnf & A_CNF_10B_2) ? " BNC" : "");
481 if ((sc->adapter_cnf & A_CNF_EXTND_10B_2) &&
482 (sc->adapter_cnf & A_CNF_LOW_RX_SQUELCH))
483 sc->line_ctl = LOW_RX_SQUELCH;
492 * Allocate a port resource with the given resource id.
494 int cs_alloc_port(device_t dev, int rid, int size)
496 struct cs_softc *sc = device_get_softc(dev);
497 struct resource *res;
499 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
500 0ul, ~0ul, size, RF_ACTIVE);
504 sc->port_used = size;
512 * Allocate a memory resource with the given resource id.
514 int cs_alloc_memory(device_t dev, int rid, int size)
516 struct cs_softc *sc = device_get_softc(dev);
517 struct resource *res;
519 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
520 0ul, ~0ul, size, RF_ACTIVE);
532 * Allocate an irq resource with the given resource id.
534 int cs_alloc_irq(device_t dev, int rid, int flags)
536 struct cs_softc *sc = device_get_softc(dev);
537 struct resource *res;
539 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
540 0ul, ~0ul, 1, (RF_ACTIVE | flags));
551 * Release all resources
553 void cs_release_resources(device_t dev)
555 struct cs_softc *sc = device_get_softc(dev);
558 bus_release_resource(dev, SYS_RES_IOPORT,
559 sc->port_rid, sc->port_res);
563 bus_release_resource(dev, SYS_RES_MEMORY,
564 sc->mem_rid, sc->mem_res);
568 bus_release_resource(dev, SYS_RES_IRQ,
569 sc->irq_rid, sc->irq_res);
575 * Install the interface into kernel networking data structures
578 cs_attach(struct cs_softc *sc, int unit, int flags)
581 struct ifnet *ifp = &(sc->arpcom.ac_if);
589 ifp->if_output=ether_output;
590 ifp->if_start=cs_start;
591 ifp->if_ioctl=cs_ioctl;
592 ifp->if_watchdog=cs_watchdog;
593 ifp->if_init=cs_init;
594 ifp->if_snd.ifq_maxlen= IFQ_MAXLEN;
599 ifp->if_linkmib=&sc->mibdata;
600 ifp->if_linkmiblen=sizeof sc->mibdata;
603 ifp->if_flags=(IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST );
606 * this code still in progress (DMA support)
609 sc->recv_ring=malloc(CS_DMA_BUFFER_SIZE<<1, M_DEVBUF, M_NOWAIT);
610 if (sc->recv_ring == NULL) {
612 "%d: Couldn't allocate memory for NIC\n", unit);
615 if ((sc->recv_ring-(sc->recv_ring & 0x1FFFF))
616 < (128*1024-CS_DMA_BUFFER_SIZE))
617 sc->recv_ring+=16*1024;
621 sc->buffer=malloc(ETHER_MAX_LEN-ETHER_CRC_LEN,M_DEVBUF,M_NOWAIT);
622 if (sc->buffer == NULL) {
623 if_printf(ifp, "Couldn't allocate memory for NIC\n");
628 * Initialize the media structures.
630 ifmedia_init(&sc->media, 0, cs_mediachange, cs_mediastatus);
632 if (sc->adapter_cnf & A_CNF_10B_T) {
633 ifmedia_add(&sc->media, IFM_ETHER|IFM_10_T, 0, NULL);
634 if (sc->chip_type != CS8900) {
635 ifmedia_add(&sc->media,
636 IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
637 ifmedia_add(&sc->media,
638 IFM_ETHER|IFM_10_T|IFM_HDX, 0, NULL);
642 if (sc->adapter_cnf & A_CNF_10B_2)
643 ifmedia_add(&sc->media, IFM_ETHER|IFM_10_2, 0, NULL);
645 if (sc->adapter_cnf & A_CNF_AUI)
646 ifmedia_add(&sc->media, IFM_ETHER|IFM_10_5, 0, NULL);
648 if (sc->adapter_cnf & A_CNF_MEDIA)
649 ifmedia_add(&sc->media, IFM_ETHER|IFM_AUTO, 0, NULL);
651 /* Set default media from EEPROM */
652 switch (sc->adapter_cnf & A_CNF_MEDIA_TYPE) {
653 case A_CNF_MEDIA_AUTO: media = IFM_ETHER|IFM_AUTO; break;
654 case A_CNF_MEDIA_10B_T: media = IFM_ETHER|IFM_10_T; break;
655 case A_CNF_MEDIA_10B_2: media = IFM_ETHER|IFM_10_2; break;
656 case A_CNF_MEDIA_AUI: media = IFM_ETHER|IFM_10_5; break;
657 default: if_printf(ifp, "adapter has no media\n");
659 ifmedia_set(&sc->media, media);
660 cs_mediaset(sc, media);
662 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
666 if_printf(ifp, "ethernet address %6D\n",
667 sc->arpcom.ac_enaddr, ":");
673 * Initialize the board
678 struct cs_softc *sc=(struct cs_softc *)xsc;
679 struct ifnet *ifp = &sc->arpcom.ac_if;
682 /* address not known */
683 if (TAILQ_EMPTY(&ifp->if_addrhead)) /* unlikely? XXX */
687 * reset whatchdog timer
695 * Hardware initialization of cs
698 /* Enable receiver and transmitter */
699 cs_writereg(sc, PP_LineCTL,
700 cs_readreg(sc, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);
702 /* Configure the receiver mode */
706 * This defines what type of frames will cause interrupts
707 * Bad frames should generate interrupts so that the driver
708 * could track statistics of discarded packets
710 rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL | RX_RUNT_ENBL |
712 if (sc->isa_config & STREAM_TRANSFER)
713 rx_cfg |= RX_STREAM_ENBL;
714 cs_writereg(sc, PP_RxCFG, rx_cfg);
715 cs_writereg(sc, PP_TxCFG, TX_LOST_CRS_ENBL |
716 TX_SQE_ERROR_ENBL | TX_OK_ENBL | TX_LATE_COL_ENBL |
717 TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);
718 cs_writereg(sc, PP_BufCFG, READY_FOR_TX_ENBL |
719 RX_MISS_COUNT_OVRFLOW_ENBL | TX_COL_COUNT_OVRFLOW_ENBL |
720 TX_UNDERRUN_ENBL /*| RX_DMA_ENBL*/);
722 /* Write MAC address into IA filter */
723 for (i=0; i<ETHER_ADDR_LEN/2; i++)
724 cs_writereg(sc, PP_IA + i * 2,
725 sc->arpcom.ac_enaddr[i * 2] |
726 (sc->arpcom.ac_enaddr[i * 2 + 1] << 8) );
729 * Now enable everything
732 #ifdef CS_USE_64K_DMA
733 cs_writereg(sc, PP_BusCTL, ENABLE_IRQ | RX_DMA_SIZE_64K);
735 cs_writereg(sc, PP_BusCTL, ENABLE_IRQ);
738 cs_writereg(sc, PP_BusCTL, ENABLE_IRQ);
741 * Set running and clear output active flags
743 sc->arpcom.ac_if.if_flags |= IFF_RUNNING;
744 sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
747 * Start sending process
755 * Get the packet from the board and send it to the upper layer.
758 cs_get_packet(struct cs_softc *sc)
760 struct ifnet *ifp = &(sc->arpcom.ac_if);
761 int iobase = sc->nic_addr, status, length;
762 struct ether_header *eh;
769 status = cs_inw(sc, RX_FRAME_PORT);
770 length = cs_inw(sc, RX_FRAME_PORT);
773 if_printf(ifp, "rcvd: stat %x, len %d\n",
777 if (!(status & RX_OK)) {
779 if_printf(ifp, "bad pkt stat %x\n", status);
785 MGETHDR(m, M_DONTWAIT, MT_DATA);
789 if (length > MHLEN) {
790 MCLGET(m, M_DONTWAIT);
791 if (!(m->m_flags & M_EXT)) {
797 /* Initialize packet's header info */
798 m->m_pkthdr.rcvif = ifp;
799 m->m_pkthdr.len = length;
803 insw(iobase + RX_FRAME_PORT, m->m_data, (length+1)>>1);
805 eh = mtod(m, struct ether_header *);
808 for (i=0;i<length;i++)
809 printf(" %02x",(unsigned char)*((char *)(m->m_data+i)));
813 if (status & (RX_IA | RX_BROADCAST) ||
814 (ifp->if_flags & IFF_MULTICAST && status & RX_HASHED)) {
815 /* Feed the packet to the upper layer */
816 (*ifp->if_input)(ifp, m);
820 if (length==ETHER_MAX_LEN-ETHER_CRC_LEN)
821 DELAY( cs_recv_delay );
835 struct cs_softc *sc = (struct cs_softc*) arg;
836 struct ifnet *ifp = &(sc->arpcom.ac_if);
840 if_printf(ifp, "Interrupt.\n");
843 while ((status=cs_inw(sc, ISQ_PORT))) {
846 if_printf(ifp, "from ISQ: %04x\n", status);
849 switch (status & ISQ_EVENT_MASK) {
850 case ISQ_RECEIVER_EVENT:
854 case ISQ_TRANSMITTER_EVENT:
859 ifp->if_flags &= ~IFF_OACTIVE;
863 case ISQ_BUFFER_EVENT:
864 if (status & READY_FOR_TX) {
865 ifp->if_flags &= ~IFF_OACTIVE;
869 if (status & TX_UNDERRUN) {
870 ifp->if_flags &= ~IFF_OACTIVE;
876 case ISQ_RX_MISS_EVENT:
877 ifp->if_ierrors+=(status>>6);
880 case ISQ_TX_COL_EVENT:
881 ifp->if_collisions+=(status>>6);
886 if (!(ifp->if_flags & IFF_OACTIVE)) {
892 * Save the data in buffer
896 cs_write_mbufs( struct cs_softc *sc, struct mbuf *m )
900 unsigned char *data, *buf;
902 for (mp=m, buf=sc->buffer, sc->buf_len=0; mp != NULL; mp=mp->m_next) {
912 * Find actual data address
914 data = mtod(mp, caddr_t);
916 bcopy((caddr_t) data, (caddr_t) buf, len);
924 cs_xmit_buf( struct cs_softc *sc )
926 outsw(sc->nic_addr+TX_FRAME_PORT, sc->buffer, (sc->buf_len+1)>>1);
931 cs_start(struct ifnet *ifp)
935 struct cs_softc *sc = ifp->if_softc;
941 length = sc->buf_len;
943 IF_DEQUEUE( &ifp->if_snd, m );
950 for (length=0, mp=m; mp != NULL; mp=mp->m_next)
953 /* Skip zero-length packets */
959 cs_write_mbufs(sc, m);
967 * Issue a SEND command
969 cs_outw(sc, TX_CMD_PORT, sc->send_cmd);
970 cs_outw(sc, TX_LEN_PORT, length );
973 * If there's no free space in the buffer then leave
974 * this packet for the next time: indicate output active
977 if (!(cs_readreg(sc, PP_BusST) & READY_FOR_TX_NOW)) {
978 ifp->if_timer = sc->buf_len;
980 ifp->if_flags |= IFF_OACTIVE;
987 * Set the watchdog timer in case we never hear
988 * from board again. (I don't know about correct
989 * value for this timeout)
991 ifp->if_timer = length;
994 ifp->if_flags |= IFF_OACTIVE;
1000 * Stop everything on the interface
1003 cs_stop(struct cs_softc *sc)
1007 cs_writereg(sc, PP_RxCFG, 0);
1008 cs_writereg(sc, PP_TxCFG, 0);
1009 cs_writereg(sc, PP_BufCFG, 0);
1010 cs_writereg(sc, PP_BusCTL, 0);
1012 sc->arpcom.ac_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1013 sc->arpcom.ac_if.if_timer = 0;
1019 * Reset the interface
1022 cs_reset(struct cs_softc *sc)
1029 cs_setmode(struct cs_softc *sc)
1031 struct ifnet *ifp = &(sc->arpcom.ac_if);
1034 /* Stop the receiver while changing filters */
1035 cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) & ~SERIAL_RX_ON);
1037 if (ifp->if_flags & IFF_PROMISC) {
1038 /* Turn on promiscuous mode. */
1039 rx_ctl = RX_OK_ACCEPT | RX_PROM_ACCEPT;
1041 if (ifp->if_flags & IFF_MULTICAST) {
1042 /* Allow receiving frames with multicast addresses */
1043 rx_ctl = RX_IA_ACCEPT | RX_BROADCAST_ACCEPT |
1044 RX_OK_ACCEPT | RX_MULTCAST_ACCEPT;
1046 * Here the reconfiguration of chip's multicast
1047 * filters should be done but I've no idea about
1048 * hash transformation in this chip. If you can
1049 * add this code or describe me the transformation
1054 * Receive only good frames addressed for us and
1057 rx_ctl = RX_IA_ACCEPT | RX_BROADCAST_ACCEPT |
1062 /* Set up the filter */
1063 cs_writereg(sc, PP_RxCTL, RX_DEF_ACCEPT | rx_ctl);
1065 /* Turn on receiver */
1066 cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) | SERIAL_RX_ON);
1070 cs_ioctl(register struct ifnet *ifp, u_long command, caddr_t data)
1072 struct cs_softc *sc=ifp->if_softc;
1073 struct ifreq *ifr = (struct ifreq *)data;
1077 if_printf(ifp, "ioctl(%lx)\n", command);
1085 * Switch interface state between "running" and
1086 * "stopped", reflecting the UP flag.
1088 if (sc->arpcom.ac_if.if_flags & IFF_UP) {
1089 if ((sc->arpcom.ac_if.if_flags & IFF_RUNNING)==0) {
1093 if ((sc->arpcom.ac_if.if_flags & IFF_RUNNING)!=0) {
1098 * Promiscuous and/or multicast flags may have changed,
1099 * so reprogram the multicast filter and/or receive mode.
1101 * See note about multicasts in cs_setmode
1109 * Multicast list has changed; set the hardware filter
1112 * See note about multicasts in cs_setmode
1120 error = ifmedia_ioctl(ifp, ifr, &sc->media, command);
1124 ether_ioctl(ifp, command, data);
1133 * Device timeout/watchdog routine. Entered if the device neglects to
1134 * generate an interrupt after a transmit has been started on it.
1137 cs_watchdog(struct ifnet *ifp)
1139 struct cs_softc *sc = ifp->if_softc;
1142 log(LOG_ERR, CS_NAME"%d: device timeout\n", ifp->if_unit);
1144 /* Reset the interface */
1145 if (ifp->if_flags & IFF_UP)
1152 cs_mediachange(struct ifnet *ifp)
1154 struct cs_softc *sc = ifp->if_softc;
1155 struct ifmedia *ifm = &sc->media;
1157 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1160 return cs_mediaset(sc, ifm->ifm_media);
1164 cs_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
1167 struct cs_softc *sc = ifp->if_softc;
1169 ifmr->ifm_active = IFM_ETHER;
1170 line_status = cs_readreg(sc, PP_LineST);
1171 if (line_status & TENBASET_ON) {
1172 ifmr->ifm_active |= IFM_10_T;
1173 if (sc->chip_type != CS8900) {
1174 if (cs_readreg(sc, PP_AutoNegST) & FDX_ACTIVE)
1175 ifmr->ifm_active |= IFM_FDX;
1176 if (cs_readreg(sc, PP_AutoNegST) & HDX_ACTIVE)
1177 ifmr->ifm_active |= IFM_HDX;
1179 ifmr->ifm_status = IFM_AVALID;
1180 if (line_status & LINK_OK)
1181 ifmr->ifm_status |= IFM_ACTIVE;
1183 if (line_status & AUI_ON) {
1184 cs_writereg(sc, PP_SelfCTL, cs_readreg(sc, PP_SelfCTL) |
1186 if (((sc->adapter_cnf & A_CNF_DC_DC_POLARITY)!=0)^
1187 (cs_readreg(sc, PP_SelfCTL) & HCB1))
1188 ifmr->ifm_active |= IFM_10_2;
1190 ifmr->ifm_active |= IFM_10_5;
1196 cs_mediaset(struct cs_softc *sc, int media)
1200 /* Stop the receiver & transmitter */
1201 cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) &
1202 ~(SERIAL_RX_ON | SERIAL_TX_ON));
1205 if_printf(&sc->arpcom.ac_if, "cs_setmedia(%x)\n", media);
1208 switch (IFM_SUBTYPE(media)) {
1211 if ((error=enable_tp(sc))==0)
1212 error = cs_duplex_auto(sc);
1213 else if ((error=enable_bnc(sc)) != 0)
1214 error = enable_aui(sc);
1217 if ((error=enable_tp(sc)) != 0)
1219 if (media & IFM_FDX)
1221 else if (media & IFM_HDX)
1224 error = cs_duplex_auto(sc);
1227 error = enable_bnc(sc);
1230 error = enable_aui(sc);
1235 * Turn the transmitter & receiver back on
1237 cs_writereg(sc, PP_LineCTL, cs_readreg(sc, PP_LineCTL) |
1238 SERIAL_RX_ON | SERIAL_TX_ON);