Changeset 271 for freebsd-mos-driver
- Timestamp:
- Feb 6, 2011, 12:49:56 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freebsd-mos-driver/if_mos.c
r270 r271 131 131 #endif 132 132 133 #define MOS_DPRINTFN(fmt,...) \ 134 DPRINTF("mos: %s: " fmt "\n",__FUNCTION__,## __VA_ARGS__) 135 133 136 #define USB_PRODUCT_MOSCHIP_MCS7730 0x7730 /* MCS7730 Ethernet */ 134 137 #define USB_PRODUCT_SITECOMEU_LN030 0x0021 /* LN-030 */ … … 145 148 }; 146 149 147 int mos_probe(device_t dev); 148 int mos_attach(device_t dev); 149 void mos_attach_post(struct usb_ether *ue); 150 int mos_detach(device_t dev); 151 152 int mos_encap(struct mos_softc *, struct mbuf *, int); 153 void mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error); 154 void mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error); 155 void mos_intr_callback(struct usb_xfer *xfer, usb_error_t error); 156 void mos_tick(struct usb_ether *); 157 void mos_start(struct usb_ether *); 158 void mos_init(struct usb_ether *); 159 void mos_chip_init(struct mos_softc *); 160 void mos_stop(struct usb_ether *); 161 void mos_watchdog(struct usb_ether *); 162 int mos_miibus_readreg(device_t , int, int); 163 int mos_miibus_writereg(device_t , int, int, int); 164 void mos_miibus_statchg(device_t); 165 int mos_ifmedia_upd(struct ifnet *); 166 void mos_ifmedia_sts(struct ifnet *, struct ifmediareq *); 167 void mos_reset(struct mos_softc *sc); 168 169 int mos_reg_read_1(struct mos_softc *, int); 170 int mos_reg_read_2(struct mos_softc *, int); 171 int mos_reg_write_1(struct mos_softc *, int, int); 172 int mos_reg_write_2(struct mos_softc *, int, int); 173 int mos_readmac(struct mos_softc *, uint8_t *); 174 int mos_writemac(struct mos_softc *, uint8_t *); 175 int mos_write_mcast(struct mos_softc *, u_char *); 176 177 void mos_setmulti(struct usb_ether *); 150 static int mos_probe(device_t dev); 151 static int mos_attach(device_t dev); 152 static void mos_attach_post(struct usb_ether *ue); 153 static int mos_detach(device_t dev); 154 155 static void mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error); 156 static void mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error); 157 static void mos_intr_callback(struct usb_xfer *xfer, usb_error_t error); 158 static void mos_tick(struct usb_ether *); 159 static void mos_start(struct usb_ether *); 160 static void mos_init(struct usb_ether *); 161 static void mos_chip_init(struct mos_softc *); 162 static void mos_stop(struct usb_ether *); 163 static int mos_miibus_readreg(device_t , int, int); 164 static int mos_miibus_writereg(device_t , int, int, int); 165 static void mos_miibus_statchg(device_t); 166 static int mos_ifmedia_upd(struct ifnet *); 167 static void mos_ifmedia_sts(struct ifnet *, struct ifmediareq *); 168 static void mos_reset(struct mos_softc *sc); 169 170 static int mos_reg_read_1(struct mos_softc *, int); 171 static int mos_reg_read_2(struct mos_softc *, int); 172 static int mos_reg_write_1(struct mos_softc *, int, int); 173 static int mos_reg_write_2(struct mos_softc *, int, int); 174 static int mos_readmac(struct mos_softc *, uint8_t *); 175 static int mos_writemac(struct mos_softc *, uint8_t *); 176 static int mos_write_mcast(struct mos_softc *, u_char *); 177 178 static void mos_setmulti(struct usb_ether *); 179 static void mos_setpromisc(struct usb_ether *); 178 180 179 181 static const struct usb_config mos_config[MOS_ENDPT_MAX] = { … … 248 250 .ue_tick = mos_tick, 249 251 .ue_setmulti = mos_setmulti, 250 //.ue_setpromisc = mos_setpromisc,252 .ue_setpromisc = mos_setpromisc, 251 253 .ue_mii_upd = mos_ifmedia_upd, 252 254 .ue_mii_sts = mos_ifmedia_sts, … … 254 256 255 257 256 int258 static int 257 259 mos_reg_read_1(struct mos_softc *sc, int reg) 258 260 { … … 270 272 271 273 if (err) { 272 DPRINTF("mos_reg_read_1 error, reg: %d\n", reg);274 MOS_DPRINTFN("mos_reg_read_1 error, reg: %d\n", reg); 273 275 return (-1); 274 276 } … … 277 279 } 278 280 279 int281 static int 280 282 mos_reg_read_2(struct mos_softc *sc, int reg) 281 283 { … … 295 297 296 298 if (err) { 297 DPRINTF("mos_reg_read_2 error, reg: %d\n", reg);299 MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg); 298 300 return (-1); 299 301 } … … 302 304 } 303 305 304 int306 static int 305 307 mos_reg_write_1(struct mos_softc *sc, int reg, int aval) 306 308 { … … 320 322 321 323 if (err) { 322 DPRINTF("mos_reg_write_1 error, reg: %d\n", reg);324 MOS_DPRINTFN("mos_reg_write_1 error, reg: %d", reg); 323 325 return (-1); 324 326 } … … 327 329 } 328 330 329 int331 static int 330 332 mos_reg_write_2(struct mos_softc *sc, int reg, int aval) 331 333 { … … 345 347 346 348 if (err) { 347 DPRINTF("mos_reg_write_2 error, reg: %d\n", reg);349 MOS_DPRINTFN("mos_reg_write_2 error, reg: %d", reg); 348 350 return (-1); 349 351 } … … 352 354 } 353 355 354 int356 static int 355 357 mos_readmac(struct mos_softc *sc, u_char *mac) 356 358 { … … 373 375 } 374 376 375 int377 static int 376 378 mos_writemac(struct mos_softc *sc, uint8_t *mac) 377 379 { … … 388 390 389 391 if (err) { 390 DPRINTF("mos_writemac error");392 MOS_DPRINTFN("mos_writemac error"); 391 393 return (-1); 392 394 } … … 395 397 } 396 398 397 int399 static int 398 400 mos_write_mcast(struct mos_softc *sc, u_char *hashtbl) 399 401 { … … 410 412 411 413 if (err) { 412 DPRINTF("mos_reg_mcast error\n");414 MOS_DPRINTFN("mos_reg_mcast error"); 413 415 return(-1); 414 416 } … … 417 419 } 418 420 419 int421 static int 420 422 mos_miibus_readreg(struct device *dev, int phy, int reg) 421 423 { … … 441 443 } 442 444 if (i == MOS_TIMEOUT) { 443 DPRINTF("%s: %s: MII read timeout\n", "mos", __func__);445 MOS_DPRINTFN("MII read timeout"); 444 446 } 445 447 … … 451 453 } 452 454 453 int455 static int 454 456 mos_miibus_writereg(device_t dev, int phy, int reg, int val) 455 457 { 456 458 struct mos_softc *sc = device_get_softc(dev); 457 459 int i, locked; 458 DPRINTF("%s enter\n", __func__);459 460 460 461 locked = mtx_owned(&sc->sc_mtx); … … 473 474 } 474 475 if (i == MOS_TIMEOUT) { 475 DPRINTF("%s: MII write timeout\n", "mos");476 MOS_DPRINTFN("MII write timeout"); 476 477 } 477 478 … … 481 482 } 482 483 483 void484 static void 484 485 mos_miibus_statchg(device_t dev) 485 486 { … … 487 488 struct mii_data *mii = GET_MII(sc); 488 489 int val, err, locked; 489 DPRINTF("%s enter\n", __func__);490 490 491 491 locked = mtx_owned(&sc->sc_mtx); … … 520 520 521 521 if (err) 522 DPRINTF("%s: media change failed\n", "mos");522 MOS_DPRINTFN("media change failed"); 523 523 524 524 if (!locked) … … 529 529 * Set media options. 530 530 */ 531 int531 static int 532 532 mos_ifmedia_upd(struct ifnet *ifp) 533 533 { … … 551 551 * Report current media status. 552 552 */ 553 void553 static void 554 554 mos_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 555 555 { … … 565 565 } 566 566 567 void 567 static void 568 mos_setpromisc(struct usb_ether *ue) 569 { 570 struct mos_softc *sc = uether_getsc(ue); 571 struct ifnet *ifp = uether_getifp(ue); 572 573 u_int8_t rxmode; 574 575 MOS_LOCK_ASSERT(sc, MA_OWNED); 576 577 rxmode = mos_reg_read_1(sc, MOS_CTL); 578 579 /* If we want promiscuous mode, set the allframes bit. */ 580 if (ifp->if_flags & IFF_PROMISC) { 581 rxmode |= MOS_CTL_RX_PROMISC; 582 } else { 583 rxmode &= ~MOS_CTL_RX_PROMISC; 584 } 585 586 mos_reg_write_1(sc, MOS_CTL, rxmode); 587 } 588 589 590 591 static void 568 592 mos_setmulti(struct usb_ether *ue) 569 593 { … … 576 600 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 577 601 int allmulti = 0; 578 DPRINTF("%s enter\n", __func__);579 602 580 603 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 610 633 } 611 634 612 void635 static void 613 636 mos_reset(struct mos_softc *sc) 614 637 { 615 638 u_int8_t ctl; 616 DPRINTF("%s enter\n", __func__);617 639 618 640 ctl = mos_reg_read_1(sc, MOS_CTL); … … 630 652 } 631 653 632 void654 static void 633 655 mos_chip_init(struct mos_softc *sc) 634 656 { 635 657 int i; 636 DPRINTF("%s enter\n", __func__);637 658 638 659 /* … … 651 672 * Probe for a MCS7x30 chip. 652 673 */ 653 int674 static int 654 675 mos_probe(device_t dev) 655 676 { … … 685 706 * setup and ethernet/BPF attach. 686 707 */ 687 int708 static int 688 709 mos_attach(device_t dev) 689 710 { … … 737 758 738 759 739 void760 static void 740 761 mos_attach_post(struct usb_ether *ue) 741 762 { … … 746 767 int err = mos_readmac(sc, ue->ue_eaddr); 747 768 if (err) { 748 DPRINTF("couldn't get MAC address\n");749 } 750 DPRINTF("address: %s\n", ether_sprintf(ue->ue_eaddr));769 MOS_DPRINTFN("couldn't get MAC address"); 770 } 771 MOS_DPRINTFN("address: %s", ether_sprintf(ue->ue_eaddr)); 751 772 752 773 mos_chip_init(sc); … … 766 787 } 767 788 768 int789 static int 769 790 mos_detach(device_t dev) 770 791 { … … 786 807 * the higher level protocols. 787 808 */ 788 void809 static void 789 810 mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 790 811 { … … 798 819 struct usb_page_cache *pc; 799 820 800 DPRINTF("%s: %s: enter\n", "mos",__func__);801 821 802 822 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); … … 805 825 switch (USB_GET_STATE(xfer)) { 806 826 case USB_ST_TRANSFERRED: 807 DPRINTF("read_callback actlen : %d\n", actlen);827 MOS_DPRINTFN("actlen : %d", actlen); 808 828 if (actlen <= 1) { 809 829 ifp->if_ierrors++; … … 816 836 817 837 if (rxstat != MOS_RXSTS_VALID) { 818 DPRINTF("%s: erroneous frame received: ", 819 "mos"); 838 MOS_DPRINTFN("erroneous frame received"); 820 839 if (rxstat & MOS_RXSTS_SHORT_FRAME) 821 DPRINTF("frame size less than 64 bytes\n");840 MOS_DPRINTFN("frame size less than 64 bytes"); 822 841 if (rxstat & MOS_RXSTS_LARGE_FRAME) 823 DPRINTF("frame size larger than 1532 bytes\n");842 MOS_DPRINTFN("frame size larger than 1532 bytes"); 824 843 if (rxstat & MOS_RXSTS_CRC_ERROR) 825 DPRINTF("CRC error\n");844 MOS_DPRINTFN("CRC error"); 826 845 if (rxstat & MOS_RXSTS_ALIGN_ERROR) 827 DPRINTF("alignment error\n");846 MOS_DPRINTFN("alignment error"); 828 847 ifp->if_ierrors++; 829 848 goto tr_setup; … … 833 852 pktlen = actlen - 1; 834 853 if ( pktlen < sizeof(struct ether_header) ) { 835 DPRINTF("mos: pktlen %i is smaller than ether_header %i\n", pktlen, sizeof(struct ether_header));854 MOS_DPRINTFN("error: pktlen %i is smaller than ether_header %i", pktlen, sizeof(struct ether_header)); 836 855 ifp->if_ierrors++; 837 856 goto tr_setup; … … 847 866 return; 848 867 default: /* Error */ 849 DPRINTF("bulk read error, %s\n", usbd_errstr(error));868 MOS_DPRINTFN("bulk read error, %s", usbd_errstr(error)); 850 869 if (error != USB_ERR_CANCELLED) { 851 870 /* try to clear stall first */ … … 853 872 goto tr_setup; 854 873 } 855 DPRINTF("start rx %i\n", usbd_xfer_max_len(xfer));874 MOS_DPRINTFN("start rx %i", usbd_xfer_max_len(xfer)); 856 875 return; 857 876 } … … 863 882 */ 864 883 865 void884 static void 866 885 mos_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error) 867 886 { … … 871 890 struct mbuf *m; 872 891 873 DPRINTF("%s: %s: enter\n", "mos",__func__);874 892 875 893 876 894 switch (USB_GET_STATE(xfer)) { 877 895 case USB_ST_TRANSFERRED: 878 DPRINTF("transfer of complete\n");896 MOS_DPRINTFN("transfer of complete"); 879 897 ifp->if_opackets++; 880 898 /* FALLTHROUGH */ … … 907 925 return; 908 926 default: /* Error */ 909 DPRINTF("%s: usb error on tx: %s\n", "mos", usbd_errstr(error));927 MOS_DPRINTFN("usb error on tx: %s\n", usbd_errstr(error)); 910 928 ifp->if_oerrors++; 911 929 if (error != USB_ERR_CANCELLED) { … … 918 936 } 919 937 920 void938 static void 921 939 mos_tick(struct usb_ether *ue) 922 940 { … … 925 943 926 944 MOS_LOCK_ASSERT(sc, MA_OWNED); 927 DPRINTF("%s: %s: enter\n", "mos", __func__);928 945 929 946 mii_tick(mii); 930 947 if (!sc->mos_link && mii->mii_media_status & IFM_ACTIVE && 931 948 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 932 DPRINTF("%s: %s: got link\n", 933 "mos", __func__); 949 MOS_DPRINTFN("got link"); 934 950 sc->mos_link++; 935 951 mos_start(ue); … … 938 954 939 955 940 //int 941 //mos_encap(struct mos_softc *sc, struct mbuf *m, int idx) 942 //{ 943 // struct mos_chain *c; 944 // int err; 945 // int length; 946 // 947 // c = &sc->mos_cdata.mos_tx_chain[idx]; 948 // 949 // m_copydata(m, 0, m->m_pkthdr.len, c->mos_buf); 950 // length = m->m_pkthdr.len; 951 // 952 // c->mos_mbuf = m; 953 // 954 // usbd_setup_xfer(c->mos_xfer, sc->mos_ep[MOS_ENDPT_TX], 955 // c, c->mos_buf, length, USBD_FORCE_SHORT_XFER | USBD_NO_COPY, 956 // 10000, mos_txeof); 957 // 958 // /* Transmit */ 959 // err = usbd_transfer(c->mos_xfer); 960 // if (err != USBD_IN_PROGRESS) { 961 // mos_stop(sc); 962 // return(EIO); 963 // } 964 // 965 // sc->mos_cdata.mos_tx_cnt++; 966 // 967 // return(0); 968 //} 969 970 void 956 static void 971 957 mos_start(struct usb_ether *ue) 972 958 { … … 981 967 } 982 968 983 void969 static void 984 970 mos_init(struct usb_ether *ue) 985 971 { … … 987 973 struct ifnet *ifp = uether_getifp(ue); 988 974 u_int8_t rxmode; 989 DPRINTF("%s enter\n", __func__);990 975 991 976 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 1014 999 rxmode &= ~(MOS_CTL_SLEEP); 1015 1000 1016 /* If we want promiscuous mode, set the allframes bit. */ 1017 if (ifp->if_flags & IFF_PROMISC) 1018 rxmode |= MOS_CTL_RX_PROMISC; 1001 mos_setpromisc(ue); 1019 1002 1020 1003 /* XXX: broadcast mode? */ … … 1030 1013 1031 1014 1032 void1015 static void 1033 1016 mos_intr_callback(struct usb_xfer *xfer, usb_error_t error) 1034 1017 { … … 1039 1022 long pkt; 1040 1023 1041 //DPRINTF("%s: %s: enter\n", "mos", __func__);1042 1024 ifp->if_oerrors++; 1043 1025 1044 1026 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 1045 DPRINTF("%s: %s: actlen %i\n", "mos", __func__, actlen); 1046 1047 //XXX: Porting, how? mos_txeof(c->mos_xfer, c, stat); 1027 MOS_DPRINTFN("actlen %i", actlen); 1028 1048 1029 switch (USB_GET_STATE(xfer)) { 1049 1030 case USB_ST_TRANSFERRED: 1050 DPRINTF("State is ST_TRANS\n");1051 1031 1052 1032 pc = usbd_xfer_get_frame(xfer, 0); … … 1055 1035 case USB_ST_SETUP: 1056 1036 tr_setup: 1057 DPRINTF("State is ST_SETUP\n");1058 //usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));1059 //usbd_transfer_submit(xfer);1060 1037 return; 1061 1038 default: /* Error */ 1062 DPRINTF("State is default\n");1063 1039 if (error != USB_ERR_CANCELLED) { 1064 1040 /* try to clear stall first */ … … 1075 1051 * RX and TX lists. 1076 1052 */ 1077 void1053 static void 1078 1054 mos_stop(struct usb_ether *ue) 1079 1055 {
Note:
See TracChangeset
for help on using the changeset viewer.