Lines Matching refs:sc

134 sbni_inb(struct sbni_softc *sc, enum sbni_reg reg)  in sbni_inb()  argument
137 rman_get_bustag(sc->io_res), in sbni_inb()
138 rman_get_bushandle(sc->io_res), in sbni_inb()
139 sc->io_off + reg); in sbni_inb()
143 sbni_outb(struct sbni_softc *sc, enum sbni_reg reg, u_char value) in sbni_outb() argument
146 rman_get_bustag(sc->io_res), in sbni_outb()
147 rman_get_bushandle(sc->io_res), in sbni_outb()
148 sc->io_off + reg, value); in sbni_outb()
152 sbni_insb(struct sbni_softc *sc, u_char *to, u_int len) in sbni_insb() argument
155 rman_get_bustag(sc->io_res), in sbni_insb()
156 rman_get_bushandle(sc->io_res), in sbni_insb()
157 sc->io_off + DAT, to, len); in sbni_insb()
161 sbni_outsb(struct sbni_softc *sc, u_char *from, u_int len) in sbni_outsb() argument
164 rman_get_bustag(sc->io_res), in sbni_outsb()
165 rman_get_bushandle(sc->io_res), in sbni_outsb()
166 sc->io_off + DAT, from, len); in sbni_outsb()
195 sbni_probe(struct sbni_softc *sc) in sbni_probe() argument
199 csr0 = sbni_inb(sc, CSR0); in sbni_probe()
216 sbni_attach(struct sbni_softc *sc, int unit, struct sbni_flags flags) in sbni_attach() argument
222 ifp = sc->ifp = if_alloc(IFT_ETHER); in sbni_attach()
225 sbni_outb(sc, CSR0, 0); in sbni_attach()
226 set_initial_values(sc, flags); in sbni_attach()
229 if_setsoftc(ifp, sc); in sbni_attach()
237 csr0 = sbni_inb(sc, CSR0); in sbni_attach()
243 mtx_init(&sc->lock, if_name(ifp), MTX_NETWORK_LOCK, MTX_DEF); in sbni_attach()
244 callout_init_mtx(&sc->wch, &sc->lock, 0); in sbni_attach()
245 ether_ifattach(ifp, sc->enaddr); in sbni_attach()
249 if (sc->delta_rxl) in sbni_attach()
252 printf("%d (fixed)\n", sc->cur_rxl_index); in sbni_attach()
257 sbni_detach(struct sbni_softc *sc) in sbni_detach() argument
260 SBNI_LOCK(sc); in sbni_detach()
261 sbni_stop(sc); in sbni_detach()
262 SBNI_UNLOCK(sc); in sbni_detach()
263 callout_drain(&sc->wch); in sbni_detach()
264 ether_ifdetach(sc->ifp); in sbni_detach()
265 if (sc->irq_handle) in sbni_detach()
266 bus_teardown_intr(sc->dev, sc->irq_res, sc->irq_handle); in sbni_detach()
267 mtx_destroy(&sc->lock); in sbni_detach()
268 if_free(sc->ifp); in sbni_detach()
272 sbni_release_resources(struct sbni_softc *sc) in sbni_release_resources() argument
275 if (sc->irq_res) in sbni_release_resources()
276 bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irq_rid, in sbni_release_resources()
277 sc->irq_res); in sbni_release_resources()
278 if (sc->io_res && sc->io_off == 0) in sbni_release_resources()
279 bus_release_resource(sc->dev, SYS_RES_IOPORT, sc->io_rid, in sbni_release_resources()
280 sc->io_res); in sbni_release_resources()
288 struct sbni_softc *sc; in sbni_init() local
290 sc = (struct sbni_softc *)xsc; in sbni_init()
291 SBNI_LOCK(sc); in sbni_init()
292 sbni_init_locked(sc); in sbni_init()
293 SBNI_UNLOCK(sc); in sbni_init()
297 sbni_init_locked(struct sbni_softc *sc) in sbni_init_locked() argument
301 ifp = sc->ifp; in sbni_init_locked()
310 card_start(sc); in sbni_init_locked()
311 callout_reset(&sc->wch, hz/SBNI_HZ, sbni_timeout, sc); in sbni_init_locked()
323 struct sbni_softc *sc = if_getsoftc(ifp); in sbni_start() local
325 SBNI_LOCK(sc); in sbni_start()
327 SBNI_UNLOCK(sc); in sbni_start()
333 struct sbni_softc *sc = if_getsoftc(ifp); in sbni_start_locked() local
335 if (sc->tx_frameno == 0) in sbni_start_locked()
336 prepare_to_send(sc); in sbni_start_locked()
340 sbni_stop(struct sbni_softc *sc) in sbni_stop() argument
342 sbni_outb(sc, CSR0, 0); in sbni_stop()
343 drop_xmit_queue(sc); in sbni_stop()
345 if (sc->rx_buf_p) { in sbni_stop()
346 m_freem(sc->rx_buf_p); in sbni_stop()
347 sc->rx_buf_p = NULL; in sbni_stop()
350 callout_stop(&sc->wch); in sbni_stop()
351 if_setdrvflagbits(sc->ifp, 0, (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)); in sbni_stop()
374 struct sbni_softc *sc; in sbni_intr() local
377 sc = (struct sbni_softc *)arg; in sbni_intr()
381 SBNI_LOCK(sc); in sbni_intr()
382 if (sbni_inb(sc, CSR0) & (RC_RDY | TR_RDY)) { in sbni_intr()
383 handle_channel(sc); in sbni_intr()
386 SBNI_UNLOCK(sc); in sbni_intr()
387 if (sc->slave_sc) { in sbni_intr()
389 SBNI_LOCK(sc->slave_sc); in sbni_intr()
390 if (sbni_inb(sc->slave_sc, CSR0) & (RC_RDY | TR_RDY)) { in sbni_intr()
391 handle_channel(sc->slave_sc); in sbni_intr()
394 SBNI_UNLOCK(sc->slave_sc); in sbni_intr()
400 handle_channel(struct sbni_softc *sc) in handle_channel() argument
405 sbni_outb(sc, CSR0, (sbni_inb(sc, CSR0) & ~EN_INT) | TR_REQ); in handle_channel()
407 sc->timer_ticks = CHANGE_LEVEL_START_TICKS; in handle_channel()
409 csr0 = sbni_inb(sc, CSR0); in handle_channel()
413 req_ans = !(sc->state & FL_PREV_OK); in handle_channel()
416 req_ans = recv_frame(sc); in handle_channel()
422 csr0 = sbni_inb(sc, CSR0); in handle_channel()
424 if_printf(sc->ifp, "internal error!\n"); in handle_channel()
427 if (req_ans || sc->tx_frameno != 0) in handle_channel()
428 send_frame(sc); in handle_channel()
431 sbni_outb(sc, CSR0, sbni_inb(sc, CSR0) & ~TR_REQ); in handle_channel()
435 sbni_outb(sc, CSR0, sbni_inb(sc, CSR0) | EN_INT); in handle_channel()
444 recv_frame(struct sbni_softc *sc) in recv_frame() argument
451 if (check_fhdr(sc, &framelen, &frameno, &ack, &is_first, &crc)) { in recv_frame()
453 upload_data(sc, framelen, frameno, is_first, crc) : in recv_frame()
454 skip_tail(sc, framelen, crc); in recv_frame()
456 interpret_ack(sc, ack); in recv_frame()
462 sbni_outb(sc, CSR0, sbni_inb(sc, CSR0) ^ CT_ZER); in recv_frame()
464 sc->state |= FL_PREV_OK; in recv_frame()
466 sc->in_stats.all_rx_number++; in recv_frame()
468 sc->state &= ~FL_PREV_OK; in recv_frame()
469 change_level(sc); in recv_frame()
470 sc->in_stats.all_rx_number++; in recv_frame()
471 sc->in_stats.bad_rx_number++; in recv_frame()
478 send_frame(struct sbni_softc *sc) in send_frame() argument
484 if (sc->state & FL_NEED_RESEND) { in send_frame()
486 if (sc->trans_errors) { in send_frame()
487 sc->trans_errors--; in send_frame()
488 if (sc->framelen != 0) in send_frame()
489 sc->in_stats.resend_tx_number++; in send_frame()
492 drop_xmit_queue(sc); in send_frame()
496 sc->trans_errors = TR_ERROR_COUNT; in send_frame()
498 send_frame_header(sc, &crc); in send_frame()
499 sc->state |= FL_NEED_RESEND; in send_frame()
505 if (sc->framelen) { in send_frame()
506 download_data(sc, &crc); in send_frame()
507 sc->in_stats.all_tx_number++; in send_frame()
508 sc->state |= FL_WAIT_ACK; in send_frame()
511 sbni_outsb(sc, (u_char *)&crc, sizeof crc); in send_frame()
514 csr0 = sbni_inb(sc, CSR0); in send_frame()
515 sbni_outb(sc, CSR0, csr0 & ~TR_REQ); in send_frame()
517 if (sc->tx_frameno) { in send_frame()
519 sbni_outb(sc, CSR0, csr0 | TR_REQ); in send_frame()
524 download_data(struct sbni_softc *sc, u_int32_t *crc_p) in download_data() argument
533 for (m = sc->tx_buf_p; m != NULL && pos < sc->pktlen; m = m->m_next) { in download_data()
534 if (pos + m->m_len > sc->outpos) { in download_data()
535 data_len = m->m_len - (sc->outpos - pos); in download_data()
536 data_p = mtod(m, caddr_t) + (sc->outpos - pos); in download_data()
549 slice = min(data_len, sc->framelen - pos); in download_data()
550 sbni_outsb(sc, data_p, slice); in download_data()
569 pos = sc->framelen - pos; in download_data()
571 sbni_outb(sc, DAT, 0); in download_data()
576 } while (pos < sc->framelen); in download_data()
580 upload_data(struct sbni_softc *sc, u_int framelen, u_int frameno, in upload_data() argument
586 sc->wait_frameno = frameno; in upload_data()
587 sc->inppos = 0; in upload_data()
590 if (sc->wait_frameno == frameno) { in upload_data()
591 if (sc->inppos + framelen <= ETHER_MAX_LEN) { in upload_data()
592 frame_ok = append_frame_to_pkt(sc, framelen, crc); in upload_data()
598 } else if ((frame_ok = skip_tail(sc, framelen, crc)) != 0) { in upload_data()
599 sc->wait_frameno = 0; in upload_data()
600 sc->inppos = 0; in upload_data()
601 if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); in upload_data()
605 frame_ok = skip_tail(sc, framelen, crc); in upload_data()
612 sc->wait_frameno = 0; in upload_data()
613 if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); in upload_data()
622 send_complete(struct sbni_softc *sc) in send_complete() argument
624 m_freem(sc->tx_buf_p); in send_complete()
625 sc->tx_buf_p = NULL; in send_complete()
626 if_inc_counter(sc->ifp, IFCOUNTER_OPACKETS, 1); in send_complete()
630 interpret_ack(struct sbni_softc *sc, u_int ack) in interpret_ack() argument
633 sc->state &= ~FL_NEED_RESEND; in interpret_ack()
635 if (sc->state & FL_WAIT_ACK) { in interpret_ack()
636 sc->outpos += sc->framelen; in interpret_ack()
638 if (--sc->tx_frameno) { in interpret_ack()
639 sc->framelen = min( in interpret_ack()
640 sc->maxframe, sc->pktlen - sc->outpos); in interpret_ack()
642 send_complete(sc); in interpret_ack()
643 prepare_to_send(sc); in interpret_ack()
648 sc->state &= ~FL_WAIT_ACK; in interpret_ack()
657 append_frame_to_pkt(struct sbni_softc *sc, u_int framelen, u_int32_t crc) in append_frame_to_pkt() argument
661 if (sc->inppos + framelen > ETHER_MAX_LEN) in append_frame_to_pkt()
664 if (!sc->rx_buf_p && !get_rx_buf(sc)) in append_frame_to_pkt()
667 p = sc->rx_buf_p->m_data + sc->inppos; in append_frame_to_pkt()
668 sbni_insb(sc, p, framelen); in append_frame_to_pkt()
672 sc->inppos += framelen - 4; in append_frame_to_pkt()
673 if (--sc->wait_frameno == 0) { /* last frame received */ in append_frame_to_pkt()
674 indicate_pkt(sc); in append_frame_to_pkt()
675 if_inc_counter(sc->ifp, IFCOUNTER_IPACKETS, 1); in append_frame_to_pkt()
688 prepare_to_send(struct sbni_softc *sc) in prepare_to_send() argument
694 if (sc->tx_buf_p) in prepare_to_send()
697 sc->outpos = 0; in prepare_to_send()
698 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in prepare_to_send()
701 sc->tx_buf_p = if_dequeue(sc->ifp); in prepare_to_send()
702 if (!sc->tx_buf_p) { in prepare_to_send()
704 sc->pktlen = 0; in prepare_to_send()
705 sc->tx_frameno = 0; in prepare_to_send()
706 sc->framelen = 0; in prepare_to_send()
707 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_OACTIVE); in prepare_to_send()
711 for (len = 0, m = sc->tx_buf_p; m; m = m->m_next) in prepare_to_send()
716 m_freem(sc->tx_buf_p); in prepare_to_send()
722 sc->pktlen = len; in prepare_to_send()
723 sc->tx_frameno = howmany(len, sc->maxframe); in prepare_to_send()
724 sc->framelen = min(len, sc->maxframe); in prepare_to_send()
726 sbni_outb(sc, CSR0, sbni_inb(sc, CSR0) | TR_REQ); in prepare_to_send()
727 if_setdrvflagbits(sc->ifp, IFF_DRV_OACTIVE, 0); in prepare_to_send()
728 BPF_MTAP(sc->ifp, sc->tx_buf_p); in prepare_to_send()
732 drop_xmit_queue(struct sbni_softc *sc) in drop_xmit_queue() argument
736 if (sc->tx_buf_p) { in drop_xmit_queue()
737 m_freem(sc->tx_buf_p); in drop_xmit_queue()
738 sc->tx_buf_p = NULL; in drop_xmit_queue()
739 if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); in drop_xmit_queue()
743 m = if_dequeue(sc->ifp); in drop_xmit_queue()
747 if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); in drop_xmit_queue()
750 sc->tx_frameno = 0; in drop_xmit_queue()
751 sc->framelen = 0; in drop_xmit_queue()
752 sc->outpos = 0; in drop_xmit_queue()
753 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in drop_xmit_queue()
754 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_OACTIVE); in drop_xmit_queue()
758 send_frame_header(struct sbni_softc *sc, u_int32_t *crc_p) in send_frame_header() argument
765 len_field = sc->framelen + 6; /* CRC + frameno + reserved */ in send_frame_header()
767 if (sc->state & FL_NEED_RESEND) in send_frame_header()
770 if (sc->outpos == 0) in send_frame_header()
773 len_field |= (sc->state & FL_PREV_OK) ? FRAME_SENT_OK : FRAME_SENT_BAD; in send_frame_header()
774 sbni_outb(sc, DAT, SBNI_SIG); in send_frame_header()
777 sbni_outb(sc, DAT, value); in send_frame_header()
780 sbni_outb(sc, DAT, value); in send_frame_header()
783 sbni_outb(sc, DAT, sc->tx_frameno); in send_frame_header()
784 crc = CRC32(sc->tx_frameno, crc); in send_frame_header()
785 sbni_outb(sc, DAT, 0); in send_frame_header()
796 skip_tail(struct sbni_softc *sc, u_int tail_len, u_int32_t crc) in skip_tail() argument
799 crc = CRC32(sbni_inb(sc, DAT), crc); in skip_tail()
805 check_fhdr(struct sbni_softc *sc, u_int *framelen, u_int *frameno, in check_fhdr() argument
812 if (sbni_inb(sc, DAT) != SBNI_SIG) in check_fhdr()
815 value = sbni_inb(sc, DAT); in check_fhdr()
818 value = sbni_inb(sc, DAT); in check_fhdr()
828 value = sbni_inb(sc, DAT); in check_fhdr()
832 crc = CRC32(sbni_inb(sc, DAT), crc); /* reserved byte */ in check_fhdr()
840 get_rx_buf(struct sbni_softc *sc) in get_rx_buf() argument
846 if_printf(sc->ifp, "cannot allocate header mbuf\n"); in get_rx_buf()
871 sc->rx_buf_p = m; in get_rx_buf()
876 indicate_pkt(struct sbni_softc *sc) in indicate_pkt() argument
878 if_t ifp = sc->ifp; in indicate_pkt()
881 m = sc->rx_buf_p; in indicate_pkt()
883 m->m_pkthdr.len = m->m_len = sc->inppos; in indicate_pkt()
884 sc->rx_buf_p = NULL; in indicate_pkt()
886 SBNI_UNLOCK(sc); in indicate_pkt()
888 SBNI_LOCK(sc); in indicate_pkt()
901 struct sbni_softc *sc; in sbni_timeout() local
904 sc = (struct sbni_softc *)xsc; in sbni_timeout()
905 SBNI_ASSERT_LOCKED(sc); in sbni_timeout()
907 csr0 = sbni_inb(sc, CSR0); in sbni_timeout()
909 if (sc->timer_ticks) { in sbni_timeout()
912 sc->timer_ticks--; in sbni_timeout()
914 sc->in_stats.timeout_number++; in sbni_timeout()
915 if (sc->delta_rxl) in sbni_timeout()
916 timeout_change_level(sc); in sbni_timeout()
918 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1 | PR_RES); in sbni_timeout()
919 csr0 = sbni_inb(sc, CSR0); in sbni_timeout()
923 sbni_outb(sc, CSR0, csr0 | RC_CHK); in sbni_timeout()
924 callout_reset(&sc->wch, hz/SBNI_HZ, sbni_timeout, sc); in sbni_timeout()
930 card_start(struct sbni_softc *sc) in card_start() argument
932 sc->timer_ticks = CHANGE_LEVEL_START_TICKS; in card_start()
933 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in card_start()
934 sc->state |= FL_PREV_OK; in card_start()
936 sc->inppos = 0; in card_start()
937 sc->wait_frameno = 0; in card_start()
939 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1 | PR_RES); in card_start()
940 sbni_outb(sc, CSR0, EN_INT); in card_start()
956 set_initial_values(struct sbni_softc *sc, struct sbni_flags flags) in set_initial_values() argument
959 sc->delta_rxl = 0; /* disable receive level autodetection */ in set_initial_values()
960 sc->cur_rxl_index = flags.rxl; in set_initial_values()
962 sc->delta_rxl = DEF_RXL_DELTA; in set_initial_values()
963 sc->cur_rxl_index = DEF_RXL; in set_initial_values()
966 sc->csr1.rate = flags.fixed_rate ? flags.rate : DEFAULT_RATE; in set_initial_values()
967 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in set_initial_values()
968 sc->maxframe = DEFAULT_FRAME_LEN; in set_initial_values()
973 *(u_int16_t *) sc->enaddr = htons(0x00ff); in set_initial_values()
975 *(u_int32_t *) (sc->enaddr + 2) = in set_initial_values()
978 *(u_char *) (sc->enaddr + 2) = 0x01; in set_initial_values()
979 read_random(sc->enaddr + 3, 3); in set_initial_values()
985 sbni_add(struct sbni_softc *sc) in sbni_add() argument
989 sc->link = sbni_headlist; in sbni_add()
990 sbni_headlist = sc; in sbni_add()
995 connect_to_master(struct sbni_softc *sc) in connect_to_master() argument
1001 if (rman_get_start(p->io_res) == rman_get_start(sc->io_res) + 4 || in connect_to_master()
1002 rman_get_start(p->io_res) == rman_get_start(sc->io_res) - 4) { in connect_to_master()
1003 p->slave_sc = sc; in connect_to_master()
1022 change_level(struct sbni_softc *sc) in change_level() argument
1024 if (sc->delta_rxl == 0) /* do not auto-negotiate RxL */ in change_level()
1027 if (sc->cur_rxl_index == 0) in change_level()
1028 sc->delta_rxl = 1; in change_level()
1029 else if (sc->cur_rxl_index == 15) in change_level()
1030 sc->delta_rxl = -1; in change_level()
1031 else if (sc->cur_rxl_rcvd < sc->prev_rxl_rcvd) in change_level()
1032 sc->delta_rxl = -sc->delta_rxl; in change_level()
1034 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index += sc->delta_rxl]; in change_level()
1035 sbni_inb(sc, CSR0); /* it needed for PCI cards */ in change_level()
1036 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1); in change_level()
1038 sc->prev_rxl_rcvd = sc->cur_rxl_rcvd; in change_level()
1039 sc->cur_rxl_rcvd = 0; in change_level()
1043 timeout_change_level(struct sbni_softc *sc) in timeout_change_level() argument
1045 sc->cur_rxl_index = timeout_rxl_tab[sc->timeout_rxl]; in timeout_change_level()
1046 if (++sc->timeout_rxl >= 4) in timeout_change_level()
1047 sc->timeout_rxl = 0; in timeout_change_level()
1049 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in timeout_change_level()
1050 sbni_inb(sc, CSR0); in timeout_change_level()
1051 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1); in timeout_change_level()
1053 sc->prev_rxl_rcvd = sc->cur_rxl_rcvd; in timeout_change_level()
1054 sc->cur_rxl_rcvd = 0; in timeout_change_level()
1067 struct sbni_softc *sc; in sbni_ioctl() local
1074 sc = if_getsoftc(ifp); in sbni_ioctl()
1085 SBNI_LOCK(sc); in sbni_ioctl()
1088 sbni_init_locked(sc); in sbni_ioctl()
1091 sbni_stop(sc); in sbni_ioctl()
1094 SBNI_UNLOCK(sc); in sbni_ioctl()
1112 SBNI_LOCK(sc); in sbni_ioctl()
1113 bcopy((caddr_t)if_getlladdr(sc->ifp)+3, (caddr_t) &flags, 3); in sbni_ioctl()
1114 flags.rxl = sc->cur_rxl_index; in sbni_ioctl()
1115 flags.rate = sc->csr1.rate; in sbni_ioctl()
1116 flags.fixed_rxl = (sc->delta_rxl == 0); in sbni_ioctl()
1118 SBNI_UNLOCK(sc); in sbni_ioctl()
1125 SBNI_LOCK(sc); in sbni_ioctl()
1126 bcopy(&sc->in_stats, in_stats, sizeof(struct sbni_in_stats)); in sbni_ioctl()
1127 SBNI_UNLOCK(sc); in sbni_ioctl()
1139 SBNI_LOCK(sc); in sbni_ioctl()
1141 sc->delta_rxl = 0; in sbni_ioctl()
1142 sc->cur_rxl_index = flags.rxl; in sbni_ioctl()
1144 sc->delta_rxl = DEF_RXL_DELTA; in sbni_ioctl()
1145 sc->cur_rxl_index = DEF_RXL; in sbni_ioctl()
1147 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in sbni_ioctl()
1148 sc->csr1.rate = flags.fixed_rate ? flags.rate : DEFAULT_RATE; in sbni_ioctl()
1151 (caddr_t) if_getlladdr(sc->ifp)+3, 3); in sbni_ioctl()
1154 sbni_outb(sc, CSR1, *(char*)(&sc->csr1) | PR_RES); in sbni_ioctl()
1155 SBNI_UNLOCK(sc); in sbni_ioctl()
1159 SBNI_LOCK(sc); in sbni_ioctl()
1161 bzero(&sc->in_stats, sizeof(struct sbni_in_stats)); in sbni_ioctl()
1162 SBNI_UNLOCK(sc); in sbni_ioctl()