Lines Matching +full:report +full:- +full:rate +full:- +full:hz
1 /*-
2 * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
56 * Support for PCI Dual cards and new SBNI12D-10, -11 Dual/ISA cards
131 /* -------------------------------------------------------------------------- */
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()
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()
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()
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()
174 ; 0 ; -
176 TR_RDY ; 2 ; -
180 BU_EMP TR_RDY ; 6 ; -
184 RC_RDY TR_RDY ; 10 ; -
185 RC_RDY TR_RDY TR_REQ ; 11 ; -
186 RC_RDY BU_EMP ; 12 ; -
187 RC_RDY BU_EMP TR_REQ ; 13 ; -
188 RC_RDY BU_EMP TR_RDY ; 14 ; -
189 RC_RDY BU_EMP TR_RDY TR_REQ ; 15 ; -
222 ifp = sc->ifp = if_alloc(IFT_ETHER); in sbni_attach()
234 /* report real baud rate */ in sbni_attach()
236 baudrate = (csr0 & 0x01 ? 500000 : 2000000) / (1 << flags.rate); in sbni_attach()
241 mtx_init(&sc->lock, if_name(ifp), MTX_NETWORK_LOCK, MTX_DEF); in sbni_attach()
242 callout_init_mtx(&sc->wch, &sc->lock, 0); in sbni_attach()
243 ether_ifattach(ifp, sc->enaddr); in sbni_attach()
247 if (sc->delta_rxl) in sbni_attach()
250 printf("%d (fixed)\n", sc->cur_rxl_index); in sbni_attach()
260 callout_drain(&sc->wch); in sbni_detach()
261 ether_ifdetach(sc->ifp); in sbni_detach()
262 if (sc->irq_handle) in sbni_detach()
263 bus_teardown_intr(sc->dev, sc->irq_res, sc->irq_handle); in sbni_detach()
264 mtx_destroy(&sc->lock); in sbni_detach()
265 if_free(sc->ifp); in sbni_detach()
272 if (sc->irq_res) in sbni_release_resources()
273 bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irq_rid, in sbni_release_resources()
274 sc->irq_res); in sbni_release_resources()
275 if (sc->io_res && sc->io_off == 0) in sbni_release_resources()
276 bus_release_resource(sc->dev, SYS_RES_IOPORT, sc->io_rid, in sbni_release_resources()
277 sc->io_res); in sbni_release_resources()
280 /* -------------------------------------------------------------------------- */
298 ifp = sc->ifp; in sbni_init_locked()
308 callout_reset(&sc->wch, hz/SBNI_HZ, sbni_timeout, sc); in sbni_init_locked()
332 if (sc->tx_frameno == 0) in sbni_start_locked()
342 if (sc->rx_buf_p) { in sbni_stop()
343 m_freem(sc->rx_buf_p); in sbni_stop()
344 sc->rx_buf_p = NULL; in sbni_stop()
347 callout_stop(&sc->wch); in sbni_stop()
348 if_setdrvflagbits(sc->ifp, 0, (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)); in sbni_stop()
351 /* -------------------------------------------------------------------------- */
356 * SBNI12D-10, -11/ISA boards within "common interrupt" mode could not
357 * be looked as two independent single-channel devices. Every channel seems
384 if (sc->slave_sc) { in sbni_intr()
386 SBNI_LOCK(sc->slave_sc); in sbni_intr()
387 if (sbni_inb(sc->slave_sc, CSR0) & (RC_RDY | TR_RDY)) { in sbni_intr()
388 handle_channel(sc->slave_sc); in sbni_intr()
391 SBNI_UNLOCK(sc->slave_sc); in sbni_intr()
404 sc->timer_ticks = CHANGE_LEVEL_START_TICKS; in handle_channel()
410 req_ans = !(sc->state & FL_PREV_OK); in handle_channel()
421 if_printf(sc->ifp, "internal error!\n"); in handle_channel()
424 if (req_ans || sc->tx_frameno != 0) in handle_channel()
461 sc->state |= FL_PREV_OK; in recv_frame()
463 sc->in_stats.all_rx_number++; in recv_frame()
465 sc->state &= ~FL_PREV_OK; in recv_frame()
467 sc->in_stats.all_rx_number++; in recv_frame()
468 sc->in_stats.bad_rx_number++; in recv_frame()
481 if (sc->state & FL_NEED_RESEND) { in send_frame()
482 /* if frame was sended but not ACK'ed - resend it */ in send_frame()
483 if (sc->trans_errors) { in send_frame()
484 sc->trans_errors--; in send_frame()
485 if (sc->framelen != 0) in send_frame()
486 sc->in_stats.resend_tx_number++; in send_frame()
493 sc->trans_errors = TR_ERROR_COUNT; in send_frame()
496 sc->state |= FL_NEED_RESEND; in send_frame()
502 if (sc->framelen) { in send_frame()
504 sc->in_stats.all_tx_number++; in send_frame()
505 sc->state |= FL_WAIT_ACK; in send_frame()
514 if (sc->tx_frameno) { in send_frame()
515 /* next frame exists - request to send */ in send_frame()
530 for (m = sc->tx_buf_p; m != NULL && pos < sc->pktlen; m = m->m_next) { in download_data()
531 if (pos + m->m_len > sc->outpos) { in download_data()
532 data_len = m->m_len - (sc->outpos - pos); in download_data()
533 data_p = mtod(m, caddr_t) + (sc->outpos - pos); in download_data()
537 pos += m->m_len; in download_data()
546 slice = min(data_len, sc->framelen - pos); in download_data()
551 if (data_len -= slice) in download_data()
555 m = m->m_next; in download_data()
556 } while (m != NULL && m->m_len == 0); in download_data()
559 data_len = m->m_len; in download_data()
564 /* frame too short - zero padding */ in download_data()
566 pos = sc->framelen - pos; in download_data()
567 while (pos--) { in download_data()
573 } while (pos < sc->framelen); in download_data()
583 sc->wait_frameno = frameno; in upload_data()
584 sc->inppos = 0; in upload_data()
587 if (sc->wait_frameno == frameno) { in upload_data()
588 if (sc->inppos + framelen <= ETHER_MAX_LEN) { in upload_data()
596 sc->wait_frameno = 0; in upload_data()
597 sc->inppos = 0; in upload_data()
598 if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); in upload_data()
609 sc->wait_frameno = 0; in upload_data()
610 if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); in upload_data()
621 m_freem(sc->tx_buf_p); in send_complete()
622 sc->tx_buf_p = NULL; in send_complete()
623 if_inc_counter(sc->ifp, IFCOUNTER_OPACKETS, 1); in send_complete()
630 sc->state &= ~FL_NEED_RESEND; in interpret_ack()
632 if (sc->state & FL_WAIT_ACK) { in interpret_ack()
633 sc->outpos += sc->framelen; in interpret_ack()
635 if (--sc->tx_frameno) { in interpret_ack()
636 sc->framelen = min( in interpret_ack()
637 sc->maxframe, sc->pktlen - sc->outpos); in interpret_ack()
645 sc->state &= ~FL_WAIT_ACK; in interpret_ack()
658 if (sc->inppos + framelen > ETHER_MAX_LEN) in append_frame_to_pkt()
661 if (!sc->rx_buf_p && !get_rx_buf(sc)) in append_frame_to_pkt()
664 p = sc->rx_buf_p->m_data + sc->inppos; in append_frame_to_pkt()
669 sc->inppos += framelen - 4; in append_frame_to_pkt()
670 if (--sc->wait_frameno == 0) { /* last frame received */ in append_frame_to_pkt()
672 if_inc_counter(sc->ifp, IFCOUNTER_IPACKETS, 1); in append_frame_to_pkt()
690 /* sc->tx_buf_p == NULL here! */ in prepare_to_send()
691 if (sc->tx_buf_p) in prepare_to_send()
694 sc->outpos = 0; in prepare_to_send()
695 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in prepare_to_send()
698 sc->tx_buf_p = if_dequeue(sc->ifp); in prepare_to_send()
699 if (!sc->tx_buf_p) { in prepare_to_send()
701 sc->pktlen = 0; in prepare_to_send()
702 sc->tx_frameno = 0; in prepare_to_send()
703 sc->framelen = 0; in prepare_to_send()
704 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_OACTIVE); in prepare_to_send()
708 for (len = 0, m = sc->tx_buf_p; m; m = m->m_next) in prepare_to_send()
709 len += m->m_len; in prepare_to_send()
713 m_freem(sc->tx_buf_p); in prepare_to_send()
719 sc->pktlen = len; in prepare_to_send()
720 sc->tx_frameno = howmany(len, sc->maxframe); in prepare_to_send()
721 sc->framelen = min(len, sc->maxframe); in prepare_to_send()
724 if_setdrvflagbits(sc->ifp, IFF_DRV_OACTIVE, 0); in prepare_to_send()
725 BPF_MTAP(sc->ifp, sc->tx_buf_p); in prepare_to_send()
733 if (sc->tx_buf_p) { in drop_xmit_queue()
734 m_freem(sc->tx_buf_p); in drop_xmit_queue()
735 sc->tx_buf_p = NULL; in drop_xmit_queue()
736 if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); in drop_xmit_queue()
740 m = if_dequeue(sc->ifp); in drop_xmit_queue()
744 if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); in drop_xmit_queue()
747 sc->tx_frameno = 0; in drop_xmit_queue()
748 sc->framelen = 0; in drop_xmit_queue()
749 sc->outpos = 0; in drop_xmit_queue()
750 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in drop_xmit_queue()
751 if_setdrvflagbits(sc->ifp, 0, IFF_DRV_OACTIVE); in drop_xmit_queue()
762 len_field = sc->framelen + 6; /* CRC + frameno + reserved */ in send_frame_header()
764 if (sc->state & FL_NEED_RESEND) in send_frame_header()
765 len_field |= FRAME_RETRY; /* non-first attempt... */ in send_frame_header()
767 if (sc->outpos == 0) in send_frame_header()
770 len_field |= (sc->state & FL_PREV_OK) ? FRAME_SENT_OK : FRAME_SENT_BAD; in send_frame_header()
780 sbni_outb(sc, DAT, sc->tx_frameno); in send_frame_header()
781 crc = CRC32(sc->tx_frameno, crc); in send_frame_header()
795 while (tail_len--) in skip_tail()
822 if ((*framelen &= FRAME_LEN_MASK) < 6 || *framelen > SBNI_MAX_FRAME - 3) in check_fhdr()
830 *framelen -= 2; in check_fhdr()
843 if_printf(sc->ifp, "cannot allocate header mbuf\n"); in get_rx_buf()
848 * We always put the received packet in a single buffer - in get_rx_buf()
860 m->m_pkthdr.len = m->m_len = ETHER_MAX_LEN + 2; in get_rx_buf()
868 sc->rx_buf_p = m; in get_rx_buf()
875 if_t ifp = sc->ifp; in indicate_pkt()
878 m = sc->rx_buf_p; in indicate_pkt()
879 m->m_pkthdr.rcvif = ifp; in indicate_pkt()
880 m->m_pkthdr.len = m->m_len = sc->inppos; in indicate_pkt()
881 sc->rx_buf_p = NULL; in indicate_pkt()
888 /* -------------------------------------------------------------------------- */
906 if (sc->timer_ticks) { in sbni_timeout()
909 sc->timer_ticks--; in sbni_timeout()
911 sc->in_stats.timeout_number++; in sbni_timeout()
912 if (sc->delta_rxl) in sbni_timeout()
915 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1 | PR_RES); in sbni_timeout()
921 callout_reset(&sc->wch, hz/SBNI_HZ, sbni_timeout, sc); in sbni_timeout()
924 /* -------------------------------------------------------------------------- */
929 sc->timer_ticks = CHANGE_LEVEL_START_TICKS; in card_start()
930 sc->state &= ~(FL_WAIT_ACK | FL_NEED_RESEND); in card_start()
931 sc->state |= FL_PREV_OK; in card_start()
933 sc->inppos = 0; in card_start()
934 sc->wait_frameno = 0; in card_start()
936 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1 | PR_RES); in card_start()
940 /* -------------------------------------------------------------------------- */
956 sc->delta_rxl = 0; /* disable receive level autodetection */ in set_initial_values()
957 sc->cur_rxl_index = flags.rxl; in set_initial_values()
959 sc->delta_rxl = DEF_RXL_DELTA; in set_initial_values()
960 sc->cur_rxl_index = DEF_RXL; in set_initial_values()
963 sc->csr1.rate = flags.fixed_rate ? flags.rate : DEFAULT_RATE; in set_initial_values()
964 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in set_initial_values()
965 sc->maxframe = DEFAULT_FRAME_LEN; in set_initial_values()
970 *(u_int16_t *) sc->enaddr = htons(0x00ff); in set_initial_values()
972 *(u_int32_t *) (sc->enaddr + 2) = in set_initial_values()
975 *(u_char *) (sc->enaddr + 2) = 0x01; in set_initial_values()
976 read_random(sc->enaddr + 3, 3); in set_initial_values()
986 sc->link = sbni_headlist; in sbni_add()
997 for (p = sbni_headlist, p_prev = NULL; p; p_prev = p, p = p->link) { in connect_to_master()
998 if (rman_get_start(p->io_res) == rman_get_start(sc->io_res) + 4 || in connect_to_master()
999 rman_get_start(p->io_res) == rman_get_start(sc->io_res) - 4) { in connect_to_master()
1000 p->slave_sc = sc; in connect_to_master()
1002 p_prev->link = p->link; in connect_to_master()
1004 sbni_headlist = p->link; in connect_to_master()
1016 /* Receive level auto-selection */
1021 if (sc->delta_rxl == 0) /* do not auto-negotiate RxL */ in change_level()
1024 if (sc->cur_rxl_index == 0) in change_level()
1025 sc->delta_rxl = 1; in change_level()
1026 else if (sc->cur_rxl_index == 15) in change_level()
1027 sc->delta_rxl = -1; in change_level()
1028 else if (sc->cur_rxl_rcvd < sc->prev_rxl_rcvd) in change_level()
1029 sc->delta_rxl = -sc->delta_rxl; in change_level()
1031 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index += sc->delta_rxl]; in change_level()
1033 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1); in change_level()
1035 sc->prev_rxl_rcvd = sc->cur_rxl_rcvd; in change_level()
1036 sc->cur_rxl_rcvd = 0; in change_level()
1042 sc->cur_rxl_index = timeout_rxl_tab[sc->timeout_rxl]; in timeout_change_level()
1043 if (++sc->timeout_rxl >= 4) in timeout_change_level()
1044 sc->timeout_rxl = 0; in timeout_change_level()
1046 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in timeout_change_level()
1048 sbni_outb(sc, CSR1, *(u_char *)&sc->csr1); in timeout_change_level()
1050 sc->prev_rxl_rcvd = sc->cur_rxl_rcvd; in timeout_change_level()
1051 sc->cur_rxl_rcvd = 0; in timeout_change_level()
1054 /* -------------------------------------------------------------------------- */
1057 * Process an ioctl request. This code needs some work - it looks
1110 bcopy((caddr_t)if_getlladdr(sc->ifp)+3, (caddr_t) &flags, 3); in sbni_ioctl()
1111 flags.rxl = sc->cur_rxl_index; in sbni_ioctl()
1112 flags.rate = sc->csr1.rate; in sbni_ioctl()
1113 flags.fixed_rxl = (sc->delta_rxl == 0); in sbni_ioctl()
1116 bcopy(&flags, &ifr->ifr_ifru, sizeof(flags)); in sbni_ioctl()
1123 bcopy(&sc->in_stats, in_stats, sizeof(struct sbni_in_stats)); in sbni_ioctl()
1135 bcopy(&ifr->ifr_ifru, &flags, sizeof(flags)); in sbni_ioctl()
1138 sc->delta_rxl = 0; in sbni_ioctl()
1139 sc->cur_rxl_index = flags.rxl; in sbni_ioctl()
1141 sc->delta_rxl = DEF_RXL_DELTA; in sbni_ioctl()
1142 sc->cur_rxl_index = DEF_RXL; in sbni_ioctl()
1144 sc->csr1.rxl = rxl_tab[sc->cur_rxl_index]; in sbni_ioctl()
1145 sc->csr1.rate = flags.fixed_rate ? flags.rate : DEFAULT_RATE; in sbni_ioctl()
1148 (caddr_t) if_getlladdr(sc->ifp)+3, 3); in sbni_ioctl()
1151 sbni_outb(sc, CSR1, *(char*)(&sc->csr1) | PR_RES); in sbni_ioctl()
1158 bzero(&sc->in_stats, sizeof(struct sbni_in_stats)); in sbni_ioctl()
1170 /* -------------------------------------------------------------------------- */
1175 while (len--) in calc_crc32()