Changeset 273 for freebsd-mos-driver
- Timestamp:
- Feb 13, 2011, 2:54:18 PM (14 years ago)
- Location:
- freebsd-mos-driver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
freebsd-mos-driver/if_mos.c
r272 r273 1 1 /* $OpenBSD: if_mos.c,v 1.7 2009/10/13 19:33:17 pirofti Exp $ */ 2 #define USB_DEBUG 1 3 /* 2 /*- 4 3 * Copyright (c) 2011 Rick van der Zwet <info@rickvanderzwet.nl> 5 4 * … … 17 16 */ 18 17 19 /* 18 /*- 20 19 * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net> 21 20 * … … 33 32 */ 34 33 35 /* 34 /*- 36 35 * Copyright (c) 2005, 2006, 2007 Jonathan Gray <jsg@openbsd.org> 37 36 * … … 49 48 */ 50 49 51 /* 50 /*- 52 51 * Copyright (c) 1997, 1998, 1999, 2000-2003 53 52 * Bill Paul <wpaul@windriver.com>. All rights reserved. … … 84 83 85 84 /* 86 * Moschip MCS7730/MCS7830 USB to Ethernet controller 87 * The datasheet is available at the following URL: 85 * Moschip MCS7730/MCS7830 USB to Ethernet controller 86 * The datasheet is available at the following URL: 88 87 * http://www.moschip.com/data/products/MCS7830/Data%20Sheet_7830.pdf 89 88 */ … … 96 95 * Mixed together with the OpenBSD if_mos.c driver for validation and checking 97 96 * and the FreeBSD if_reu.c as reference for the USB Ethernet framework. 98 */ 97 */ 99 98 100 99 #include <sys/stdint.h> … … 143 142 DPRINTF("mos: %s: " fmt "\n",__FUNCTION__,## __VA_ARGS__) 144 143 145 #define USB_PRODUCT_MOSCHIP_MCS7730 0x7730 146 #define USB_PRODUCT_SITECOMEU_LN030 0x0021 144 #define USB_PRODUCT_MOSCHIP_MCS7730 0x7730 /* MCS7730 Ethernet */ 145 #define USB_PRODUCT_SITECOMEU_LN030 0x0021 /* LN-030 */ 147 146 148 147 … … 152 151 */ 153 152 static const struct usb_device_id mos_devs[] = { 154 { USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7730, MCS7730)},155 { USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830 , MCS7830)},156 { USB_VPI( USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN030 , MCS7830)},153 {USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7730, MCS7730)}, 154 {USB_VPI(USB_VENDOR_MOSCHIP, USB_PRODUCT_MOSCHIP_MCS7830, MCS7830)}, 155 {USB_VPI(USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN030, MCS7830)}, 157 156 }; 158 157 … … 170 169 static void mos_chip_init(struct mos_softc *); 171 170 static void mos_stop(struct usb_ether *); 172 static int mos_miibus_readreg(device_t 173 static int mos_miibus_writereg(device_t 171 static int mos_miibus_readreg(device_t, int, int); 172 static int mos_miibus_writereg(device_t, int, int, int); 174 173 static void mos_miibus_statchg(device_t); 175 174 static int mos_ifmedia_upd(struct ifnet *); … … 214 213 .direction = UE_DIR_IN, 215 214 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 216 .bufsize = 0, /* use wMaxPacketSize */215 .bufsize = 0, /* use wMaxPacketSize */ 217 216 .callback = mos_intr_callback, 218 217 }, … … 268 267 mos_reg_read_1(struct mos_softc *sc, int reg) 269 268 { 270 struct usb_device_request 271 usb_error_t 272 uByte 269 struct usb_device_request req; 270 usb_error_t err; 271 uByte val = 0; 273 272 274 273 req.bmRequestType = UT_READ_VENDOR_DEVICE; … … 284 283 return (-1); 285 284 } 286 287 285 return (val); 288 286 } … … 291 289 mos_reg_read_2(struct mos_softc *sc, int reg) 292 290 { 293 struct usb_device_request req; 294 usb_error_t err; 295 uWord val; 296 297 USETW(val,0); 298 299 req.bmRequestType = UT_READ_VENDOR_DEVICE; 300 req.bRequest = MOS_UR_READREG; 301 USETW(req.wValue, 0); 302 USETW(req.wIndex, reg); 303 USETW(req.wLength, 2); 304 305 err = uether_do_request(&sc->sc_ue, &req, &val, 1000); 306 307 if (err) { 308 MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg); 309 return (-1); 310 } 311 312 return(UGETW(val)); 291 struct usb_device_request req; 292 usb_error_t err; 293 uWord val; 294 295 USETW(val, 0); 296 297 req.bmRequestType = UT_READ_VENDOR_DEVICE; 298 req.bRequest = MOS_UR_READREG; 299 USETW(req.wValue, 0); 300 USETW(req.wIndex, reg); 301 USETW(req.wLength, 2); 302 303 err = uether_do_request(&sc->sc_ue, &req, &val, 1000); 304 305 if (err) { 306 MOS_DPRINTFN("mos_reg_read_2 error, reg: %d", reg); 307 return (-1); 308 } 309 return (UGETW(val)); 313 310 } 314 311 … … 316 313 mos_reg_write_1(struct mos_softc *sc, int reg, int aval) 317 314 { 318 struct usb_device_request 319 usb_error_t 320 uByte 315 struct usb_device_request req; 316 usb_error_t err; 317 uByte val; 321 318 322 319 val = aval; … … 334 331 return (-1); 335 332 } 336 337 return(0); 333 return (0); 338 334 } 339 335 … … 341 337 mos_reg_write_2(struct mos_softc *sc, int reg, int aval) 342 338 { 343 struct usb_device_request 344 usb_error_t 345 uWord 339 struct usb_device_request req; 340 usb_error_t err; 341 uWord val; 346 342 347 343 USETW(val, aval); … … 359 355 return (-1); 360 356 } 361 362 357 return (0); 363 358 } … … 366 361 mos_readmac(struct mos_softc *sc, u_char *mac) 367 362 { 368 struct usb_device_request 369 usb_error_t 363 struct usb_device_request req; 364 usb_error_t err; 370 365 371 366 req.bmRequestType = UT_READ_VENDOR_DEVICE; … … 380 375 return (-1); 381 376 } 382 383 377 return (0); 384 378 } … … 387 381 mos_writemac(struct mos_softc *sc, uint8_t *mac) 388 382 { 389 struct usb_device_request 390 usb_error_t 383 struct usb_device_request req; 384 usb_error_t err; 391 385 392 386 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; … … 402 396 return (-1); 403 397 } 404 405 398 return (0); 406 399 } … … 409 402 mos_write_mcast(struct mos_softc *sc, u_char *hashtbl) 410 403 { 411 struct usb_device_request 412 usb_error_t 404 struct usb_device_request req; 405 usb_error_t err; 413 406 414 407 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; … … 422 415 if (err) { 423 416 MOS_DPRINTFN("mos_reg_mcast error"); 424 return(-1); 425 } 426 427 return(0); 417 return (-1); 418 } 419 return (0); 428 420 } 429 421 … … 432 424 { 433 425 struct mos_softc *sc = device_get_softc(dev); 434 uWord 435 int i,res, locked;426 uWord val; 427 int i, res, locked; 436 428 437 429 USETW(val, 0); … … 454 446 MOS_DPRINTFN("MII read timeout"); 455 447 } 456 457 448 res = mos_reg_read_2(sc, MOS_PHY_DATA); 458 449 … … 466 457 { 467 458 struct mos_softc *sc = device_get_softc(dev); 468 int 459 int i, locked; 469 460 470 461 locked = mtx_owned(&sc->sc_mtx); … … 485 476 MOS_DPRINTFN("MII write timeout"); 486 477 } 487 488 478 if (!locked) 489 479 MOS_UNLOCK(sc); … … 496 486 struct mos_softc *sc = device_get_softc(dev); 497 487 struct mii_data *mii = GET_MII(sc); 498 int 488 int val, err, locked; 499 489 500 490 locked = mtx_owned(&sc->sc_mtx); … … 516 506 517 507 switch (IFM_SUBTYPE(mii->mii_media_active)) { 518 519 val |=MOS_CTL_SPEEDSEL;520 521 522 523 508 case IFM_100_TX: 509 val |= MOS_CTL_SPEEDSEL; 510 break; 511 case IFM_10_T: 512 val &= ~(MOS_CTL_SPEEDSEL); 513 break; 524 514 } 525 515 … … 541 531 mos_ifmedia_upd(struct ifnet *ifp) 542 532 { 543 struct mos_softc 544 struct mii_data 533 struct mos_softc *sc = ifp->if_softc; 534 struct mii_data *mii = GET_MII(sc); 545 535 546 536 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 551 541 552 542 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 553 543 mii_phy_reset(miisc); 554 544 } 555 545 mii_mediachg(mii); … … 563 553 mos_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 564 554 { 565 struct mos_softc 566 struct mii_data 555 struct mos_softc *sc = ifp->if_softc; 556 struct mii_data *mii = GET_MII(sc); 567 557 568 558 MOS_LOCK(sc); … … 580 570 struct ifnet *ifp = uether_getifp(ue); 581 571 582 u_int8_t 572 u_int8_t rxmode; 583 573 584 574 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 589 579 if (ifp->if_flags & IFF_PROMISC) { 590 580 rxmode |= MOS_CTL_RX_PROMISC; 591 592 593 581 } else { 582 rxmode &= ~MOS_CTL_RX_PROMISC; 583 } 594 584 595 585 mos_reg_write_1(sc, MOS_CTL, rxmode); … … 603 593 struct mos_softc *sc = uether_getsc(ue); 604 594 struct ifnet *ifp = uether_getifp(ue); 605 struct ifmultiaddr 606 607 u_int32_t 608 u_int8_t 609 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0};610 int 595 struct ifmultiaddr *ifma; 596 597 u_int32_t h = 0; 598 u_int8_t rxmode; 599 u_int8_t hashtbl[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 600 int allmulti = 0; 611 601 612 602 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 625 615 }; 626 616 h = ether_crc32_be(LLADDR((struct sockaddr_dl *) 627 ifma->ifma_addr), ETHER_ADDR_LEN) 617 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; 628 618 //h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26; 629 619 hashtbl[h / 8] |= 1 << (h % 8); … … 664 654 mos_chip_init(struct mos_softc *sc) 665 655 { 666 int 656 int i; 667 657 668 658 /* … … 671 661 */ 672 662 if (mos_reg_read_1(sc, MOS_PAUSE_TRHD) != -1) { 673 for (i =0;i<MOS_PAUSE_REWRITES;i++)663 for (i = 0; i < MOS_PAUSE_REWRITES; i++) 674 664 mos_reg_write_1(sc, MOS_PAUSE_TRHD, 0); 675 665 } 676 677 sc->mos_phyaddrs[ 0] = 1; sc->mos_phyaddrs[1] = 0xFF;666 sc->mos_phyaddrs[0] = 1; 667 sc->mos_phyaddrs[1] = 0xFF; 678 668 } 679 669 … … 691 681 return (ENXIO); 692 682 } 693 //uint8_t bIfaceIndex;694 //uint8_t bIfaceNum;695 //uint8_t bConfigIndex;696 //uint8_t bConfigNum;697 683 698 684 if (uaa->info.bConfigNum != MOS_CONFIG_NO) { 699 DPRINTFN(11, "mos: not MOS_CONFIG_NO %i vs %i\n", uaa->info.bConfigNum 685 DPRINTFN(11, "mos: not MOS_CONFIG_NO %i vs %i\n", uaa->info.bConfigNum, MOS_CONFIG_NO); 700 686 return (ENXIO); 701 687 } … … 704 690 return (ENXIO); 705 691 } 706 707 692 DPRINTFN(11, "mos: probe by generic means\n"); 708 693 int retval = usbd_lookup_id_by_uaa(mos_devs, sizeof(mos_devs), uaa); 694 709 695 DPRINTFN(11, "mos: probe retval: %i (ENXIO:%i)\n", retval, ENXIO); 710 696 return retval; … … 715 701 * setup and ethernet/BPF attach. 716 702 */ 717 static int 703 static int 718 704 mos_attach(device_t dev) 719 705 { … … 739 725 goto detach; 740 726 } 741 742 727 ue->ue_sc = sc; 743 728 ue->ue_dev = dev; … … 752 737 DPRINTF("model: MCS7830\n"); 753 738 } 754 755 739 error = uether_ifattach(ue); 756 740 if (error) { … … 771 755 { 772 756 struct mos_softc *sc = uether_getsc(ue); 757 773 758 /* 774 759 * Read MAC address, inform the world. 775 760 */ 776 761 int err = mos_readmac(sc, ue->ue_eaddr); 762 777 763 if (err) { 778 764 MOS_DPRINTFN("couldn't get MAC address"); … … 781 767 782 768 mos_chip_init(sc); 783 784 // ifp = GET_IFP(sc);785 // ifp->if_softc = sc;786 // ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST;787 // ifp->if_ioctl = mos_ioctl;788 // ifp->if_start = mos_start;789 // ifp->if_watchdog = mos_watchdog;790 // strlcpy(ifp->if_xname, sc->mos_dev.dv_xname, IFNAMSIZ);791 792 // IFQ_SET_READY(&ifp->if_snd);793 // ifp->if_capabilities = IFCAP_VLAN_MTU;794 795 sc->mos_attached = 1;796 769 } 797 770 … … 819 792 mos_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 820 793 { 821 struct mos_softc 822 struct usb_ether 823 struct ifnet 824 825 uint8_t 826 uint32_t 827 uint16_t 794 struct mos_softc *sc = usbd_xfer_softc(xfer); 795 struct usb_ether *ue = &sc->sc_ue; 796 struct ifnet *ifp = uether_getifp(ue); 797 798 uint8_t rxstat = 0; 799 uint32_t actlen; 800 uint16_t pktlen = 0; 828 801 struct usb_page_cache *pc; 829 802 … … 836 809 MOS_DPRINTFN("actlen : %d", actlen); 837 810 if (actlen <= 1) { 838 811 ifp->if_ierrors++; 839 812 goto tr_setup; 840 } 841 813 } 842 814 /* evaluate status byte at the end */ 843 815 usbd_copy_out(pc, actlen - sizeof(rxstat), &rxstat, … … 857 829 goto tr_setup; 858 830 } 859 860 /* Remember the last byte was used for the status fields */ 861 pktlen = actlen - 1; 862 if ( pktlen < sizeof(struct ether_header) ) { 863 MOS_DPRINTFN("error: pktlen %i is smaller than ether_header %i", pktlen, sizeof(struct ether_header)); 831 /* Remember the last byte was used for the status fields */ 832 pktlen = actlen - 1; 833 if (pktlen < sizeof(struct ether_header)) { 834 MOS_DPRINTFN("error: pktlen %i is smaller than ether_header %i", pktlen, sizeof(struct ether_header)); 864 835 ifp->if_ierrors++; 865 836 goto tr_setup; 866 837 } 867 868 838 uether_rxbuf(ue, pc, 0, actlen); 869 839 /* FALLTHROUGH */ 870 840 case USB_ST_SETUP: 871 841 tr_setup: … … 874 844 uether_rxflush(ue); 875 845 return; 876 default: 846 default: /* Error */ 877 847 MOS_DPRINTFN("bulk read error, %s", usbd_errstr(error)); 878 848 if (error != USB_ERR_CANCELLED) { … … 912 882 */ 913 883 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 914 915 916 917 884 if (m == NULL) 885 return; 886 887 pc = usbd_xfer_get_frame(xfer, 0); 918 888 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len); 919 889 … … 933 903 ifp->if_opackets++; 934 904 return; 935 default:/* Error */905 default: /* Error */ 936 906 MOS_DPRINTFN("usb error on tx: %s\n", usbd_errstr(error)); 937 907 ifp->if_oerrors++; 938 908 if (error != USB_ERR_CANCELLED) { 939 940 941 909 /* try to clear stall first */ 910 usbd_xfer_set_stall(xfer); 911 goto tr_setup; 942 912 } 943 913 return; 944 914 } 945 915 } … … 981 951 struct mos_softc *sc = uether_getsc(ue); 982 952 struct ifnet *ifp = uether_getifp(ue); 983 u_int8_t 953 u_int8_t rxmode; 984 954 985 955 MOS_LOCK_ASSERT(sc, MA_OWNED); … … 1003 973 mos_reg_write_1(sc, MOS_IPG1, sc->mos_ipgs[1]); 1004 974 1005 /* Enable receiver and transmitter, bridge controls speed/duplex mode */ 975 /* 976 * Enable receiver and transmitter, bridge controls speed/duplex 977 * mode 978 */ 1006 979 rxmode = mos_reg_read_1(sc, MOS_CTL); 1007 980 rxmode |= MOS_CTL_RX_ENB | MOS_CTL_TX_ENB | MOS_CTL_BS_ENB; 1008 981 rxmode &= ~(MOS_CTL_SLEEP); 1009 982 1010 983 mos_setpromisc(ue); 1011 984 1012 985 /* XXX: broadcast mode? */ … … 1029 1002 struct usb_page_cache *pc; 1030 1003 int actlen; 1031 1004 long pkt; 1032 1005 1033 1006 ifp->if_oerrors++; 1034 1007 1035 1008 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 1036 1009 MOS_DPRINTFN("actlen %i", actlen); 1037 1010 1038 1011 switch (USB_GET_STATE(xfer)) { 1039 1012 case USB_ST_TRANSFERRED: 1040 1013 1041 1042 1014 pc = usbd_xfer_get_frame(xfer, 0); 1015 usbd_copy_out(pc, 0, &pkt, sizeof(pkt)); 1043 1016 /* FALLTHROUGH */ 1044 1017 case USB_ST_SETUP: … … 1080 1053 sc->mos_link = 0; 1081 1054 } 1082 -
freebsd-mos-driver/if_mosreg.h
r176 r273 1 /* $OpenBSD: if_mosreg.h,v 1.3 2008/11/22 09:46:12 deraadt Exp $ */ 2 /* 3 * Copyright (c) 2010 Rick van der Zwet <info@rickvanderzwet.nl> 1 /*- 2 * Copyright (c) 2010, 2011 Rick van der Zwet <info@rickvanderzwet.nl> 4 3 * 5 4 * Permission to use, copy, modify, and distribute this software for any … … 16 15 */ 17 16 18 /* 17 /*- 19 18 * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net> 20 19 * … … 32 31 */ 33 32 34 /* 33 /*- 35 34 * Copyright (c) 1997, 1998, 1999, 2000-2003 36 35 * Bill Paul <wpaul@windriver.com>. All rights reserved. … … 151 150 #define MOS_IFACE_IDX 0 152 151 153 //struct mos_type {154 // struct usb_devno mos_dev;155 // u_int16_t mos_flags;156 152 #define MCS7730 0x0001 /* MCS7730 */ 157 153 #define MCS7830 0x0002 /* MCS7830 */ 158 //};159 154 160 155 #define MOS_INC(x, y) (x) = (x + 1) % y 161 162 //struct mos_softc;163 //164 struct mos_chain {165 char *mos_buf;166 struct mbuf *mos_mbuf;167 int mos_accum;168 int mos_idx;169 };170 //171 //struct mos_cdata {172 // struct mos_chain mos_tx_chain[MOS_TX_LIST_CNT];173 // struct mos_chain mos_rx_chain[MOS_RX_LIST_CNT];174 // int mos_tx_prod;175 // int mos_tx_cons;176 // int mos_tx_cnt;177 // int mos_rx_prod;178 //};179 156 180 157 struct mos_softc { … … 182 159 struct ifnet ifp; 183 160 184 // struct device mos_dev;185 //#define GET_MII(sc) (&(sc)->mos_mii)186 //#define GET_IFP(sc) (&(sc)->arpcom.ac_if)187 // struct mii_data mos_mii;188 // usbd_device_handle mos_udev;189 // usbd_interface_handle mos_iface;190 191 161 u_int16_t mos_flags; 192 193 // int mos_ed[MOS_ENDPT_MAX];194 // usbd_pipe_handle mos_ep[MOS_ENDPT_MAX];195 int mos_unit;196 int mos_if_flags;197 // struct mos_cdata mos_cdata;198 // struct timeout mos_stat_ch;199 200 int mos_refcnt;201 char mos_dying;202 char mos_attached;203 162 204 163 int mos_link; 205 164 unsigned char mos_ipgs[2]; 206 165 unsigned char mos_phyaddrs[2]; 207 struct timeval mos_rx_notice;208 209 u_int16_t mos_tspeed;210 u_int16_t mos_maxpacket;211 212 // struct usb_task mos_tick_task;213 // struct usb_task mos_stop_task;214 215 166 216 167 struct mtx sc_mtx; 217 168 struct usb_xfer *sc_xfer[MOS_ENDPT_MAX]; 218 219 u_int mos_bufsz;220 169 }; 221 170
Note:
See TracChangeset
for help on using the changeset viewer.