2 * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30 #include <ipxe/ethernet.h>
32 #include <ipxe/usbnet.h>
33 #include <ipxe/profile.h>
38 * SMSC LAN75xx USB Ethernet driver
42 /** Interrupt completion profiler */
43 static struct profiler smsc75xx_intr_profiler __profiler =
44 { .name = "smsc75xx.intr" };
46 /** Bulk IN completion profiler */
47 static struct profiler smsc75xx_in_profiler __profiler =
48 { .name = "smsc75xx.in" };
50 /** Bulk OUT profiler */
51 static struct profiler smsc75xx_out_profiler __profiler =
52 { .name = "smsc75xx.out" };
54 /******************************************************************************
58 ******************************************************************************
62 * Write register (without byte-swapping)
64 * @v smsc75xx SMSC75xx device
65 * @v address Register address
66 * @v value Register value
67 * @ret rc Return status code
69 static int smsc75xx_raw_writel ( struct smsc75xx_device *smsc75xx,
70 unsigned int address, uint32_t value ) {
74 if ( ( rc = usb_control ( smsc75xx->usb, SMSC75XX_REGISTER_WRITE, 0,
75 address, &value, sizeof ( value ) ) ) != 0 ) {
76 DBGC ( smsc75xx, "SMSC75XX %p could not write %03x: %s\n",
77 smsc75xx, address, strerror ( rc ) );
87 * @v smsc75xx SMSC75xx device
88 * @v address Register address
89 * @v value Register value
90 * @ret rc Return status code
92 static inline __attribute__ (( always_inline )) int
93 smsc75xx_writel ( struct smsc75xx_device *smsc75xx, unsigned int address,
98 if ( ( rc = smsc75xx_raw_writel ( smsc75xx, address,
99 cpu_to_le32 ( value ) ) ) != 0 )
106 * Read register (without byte-swapping)
108 * @v smsc75xx SMSC75xx device
109 * @v address Register address
110 * @ret value Register value
111 * @ret rc Return status code
113 static int smsc75xx_raw_readl ( struct smsc75xx_device *smsc75xx,
114 unsigned int address, uint32_t *value ) {
118 if ( ( rc = usb_control ( smsc75xx->usb, SMSC75XX_REGISTER_READ, 0,
119 address, value, sizeof ( *value ) ) ) != 0 ) {
120 DBGC ( smsc75xx, "SMSC75XX %p could not read %03x: %s\n",
121 smsc75xx, address, strerror ( rc ) );
131 * @v smsc75xx SMSC75xx device
132 * @v address Register address
133 * @ret value Register value
134 * @ret rc Return status code
136 static inline __attribute__ (( always_inline )) int
137 smsc75xx_readl ( struct smsc75xx_device *smsc75xx, unsigned int address,
142 if ( ( rc = smsc75xx_raw_readl ( smsc75xx, address, value ) ) != 0 )
144 le32_to_cpus ( value );
149 /******************************************************************************
153 ******************************************************************************
157 * Wait for EEPROM to become idle
159 * @v smsc75xx SMSC75xx device
160 * @ret rc Return status code
162 static int smsc75xx_eeprom_wait ( struct smsc75xx_device *smsc75xx ) {
167 /* Wait for EPC_BSY to become clear */
168 for ( i = 0 ; i < SMSC75XX_EEPROM_MAX_WAIT_MS ; i++ ) {
170 /* Read E2P_CMD and check EPC_BSY */
171 if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_E2P_CMD,
174 if ( ! ( e2p_cmd & SMSC75XX_E2P_CMD_EPC_BSY ) )
181 DBGC ( smsc75xx, "SMSC75XX %p timed out waiting for EEPROM\n",
187 * Read byte from EEPROM
189 * @v smsc75xx SMSC75xx device
190 * @v address EEPROM address
191 * @ret byte Byte read, or negative error
193 static int smsc75xx_eeprom_read_byte ( struct smsc75xx_device *smsc75xx,
194 unsigned int address ) {
199 /* Wait for EEPROM to become idle */
200 if ( ( rc = smsc75xx_eeprom_wait ( smsc75xx ) ) != 0 )
203 /* Initiate read command */
204 e2p_cmd = ( SMSC75XX_E2P_CMD_EPC_BSY | SMSC75XX_E2P_CMD_EPC_CMD_READ |
205 SMSC75XX_E2P_CMD_EPC_ADDR ( address ) );
206 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_E2P_CMD,
210 /* Wait for command to complete */
211 if ( ( rc = smsc75xx_eeprom_wait ( smsc75xx ) ) != 0 )
214 /* Read EEPROM data */
215 if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_E2P_DATA,
219 return SMSC75XX_E2P_DATA_GET ( e2p_data );
223 * Read data from EEPROM
225 * @v smsc75xx SMSC75xx device
226 * @v address EEPROM address
227 * @v data Data buffer
228 * @v len Length of data
229 * @ret rc Return status code
231 static int smsc75xx_eeprom_read ( struct smsc75xx_device *smsc75xx,
232 unsigned int address, void *data,
238 for ( bytes = data ; len-- ; address++, bytes++ ) {
239 byte = smsc75xx_eeprom_read_byte ( smsc75xx, address );
248 /******************************************************************************
252 ******************************************************************************
256 * Wait for MII to become idle
258 * @v smsc75xx SMSC75xx device
259 * @ret rc Return status code
261 static int smsc75xx_mii_wait ( struct smsc75xx_device *smsc75xx ) {
266 /* Wait for MIIBZY to become clear */
267 for ( i = 0 ; i < SMSC75XX_MII_MAX_WAIT_MS ; i++ ) {
269 /* Read MII_ACCESS and check MIIBZY */
270 if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_MII_ACCESS,
271 &mii_access ) ) != 0 )
273 if ( ! ( mii_access & SMSC75XX_MII_ACCESS_MIIBZY ) )
280 DBGC ( smsc75xx, "SMSC75XX %p timed out waiting for MII\n",
286 * Read from MII register
288 * @v mii MII interface
289 * @v reg Register address
290 * @ret value Data read, or negative error
292 static int smsc75xx_mii_read ( struct mii_interface *mii, unsigned int reg ) {
293 struct smsc75xx_device *smsc75xx =
294 container_of ( mii, struct smsc75xx_device, mii );
299 /* Wait for MII to become idle */
300 if ( ( rc = smsc75xx_mii_wait ( smsc75xx ) ) != 0 )
303 /* Initiate read command */
304 mii_access = ( SMSC75XX_MII_ACCESS_PHY_ADDRESS |
305 SMSC75XX_MII_ACCESS_MIIRINDA ( reg ) |
306 SMSC75XX_MII_ACCESS_MIIBZY );
307 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_MII_ACCESS,
308 mii_access ) ) != 0 )
311 /* Wait for command to complete */
312 if ( ( rc = smsc75xx_mii_wait ( smsc75xx ) ) != 0 )
316 if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_MII_DATA,
320 return SMSC75XX_MII_DATA_GET ( mii_data );
324 * Write to MII register
326 * @v mii MII interface
327 * @v reg Register address
328 * @v data Data to write
329 * @ret rc Return status code
331 static int smsc75xx_mii_write ( struct mii_interface *mii, unsigned int reg,
332 unsigned int data ) {
333 struct smsc75xx_device *smsc75xx =
334 container_of ( mii, struct smsc75xx_device, mii );
339 /* Wait for MII to become idle */
340 if ( ( rc = smsc75xx_mii_wait ( smsc75xx ) ) != 0 )
344 mii_data = SMSC75XX_MII_DATA_SET ( data );
345 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_MII_DATA,
349 /* Initiate write command */
350 mii_access = ( SMSC75XX_MII_ACCESS_PHY_ADDRESS |
351 SMSC75XX_MII_ACCESS_MIIRINDA ( reg ) |
352 SMSC75XX_MII_ACCESS_MIIWNR |
353 SMSC75XX_MII_ACCESS_MIIBZY );
354 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_MII_ACCESS,
355 mii_access ) ) != 0 )
358 /* Wait for command to complete */
359 if ( ( rc = smsc75xx_mii_wait ( smsc75xx ) ) != 0 )
365 /** MII operations */
366 static struct mii_operations smsc75xx_mii_operations = {
367 .read = smsc75xx_mii_read,
368 .write = smsc75xx_mii_write,
374 * @v smsc75xx SMSC75xx device
375 * @ret rc Return status code
377 static int smsc75xx_check_link ( struct smsc75xx_device *smsc75xx ) {
378 struct net_device *netdev = smsc75xx->netdev;
382 /* Read PHY interrupt source */
383 intr = mii_read ( &smsc75xx->mii, SMSC75XX_MII_PHY_INTR_SOURCE );
386 DBGC ( smsc75xx, "SMSC75XX %p could not get PHY interrupt "
387 "source: %s\n", smsc75xx, strerror ( rc ) );
391 /* Acknowledge PHY interrupt */
392 if ( ( rc = mii_write ( &smsc75xx->mii, SMSC75XX_MII_PHY_INTR_SOURCE,
394 DBGC ( smsc75xx, "SMSC75XX %p could not acknowledge PHY "
395 "interrupt: %s\n", smsc75xx, strerror ( rc ) );
399 /* Check link status */
400 if ( ( rc = mii_check_link ( &smsc75xx->mii, netdev ) ) != 0 ) {
401 DBGC ( smsc75xx, "SMSC75XX %p could not check link: %s\n",
402 smsc75xx, strerror ( rc ) );
406 DBGC ( smsc75xx, "SMSC75XX %p link %s (intr %#04x)\n",
407 smsc75xx, ( netdev_link_ok ( netdev ) ? "up" : "down" ), intr );
411 /******************************************************************************
413 * Statistics (for debugging)
415 ******************************************************************************
421 * @v smsc75xx SMSC75xx device
422 * @v stats Statistics to fill in
423 * @ret rc Return status code
425 static int smsc75xx_get_statistics ( struct smsc75xx_device *smsc75xx,
426 struct smsc75xx_statistics *stats ) {
430 if ( ( rc = usb_control ( smsc75xx->usb, SMSC75XX_GET_STATISTICS, 0, 0,
431 stats, sizeof ( *stats ) ) ) != 0 ) {
432 DBGC ( smsc75xx, "SMSC75XX %p could not get statistics: %s\n",
433 smsc75xx, strerror ( rc ) );
441 * Dump statistics (for debugging)
443 * @v smsc75xx SMSC75xx device
444 * @ret rc Return status code
446 static int smsc75xx_dump_statistics ( struct smsc75xx_device *smsc75xx ) {
447 struct smsc75xx_statistics stats;
450 /* Do nothing unless debugging is enabled */
455 if ( ( rc = smsc75xx_get_statistics ( smsc75xx, &stats ) ) != 0 )
458 /* Dump statistics */
459 DBGC ( smsc75xx, "SMSC75XX %p RXE fcs %d aln %d frg %d jab %d und %d "
460 "ovr %d drp %d\n", smsc75xx, le32_to_cpu ( stats.rx.err.fcs ),
461 le32_to_cpu ( stats.rx.err.alignment ),
462 le32_to_cpu ( stats.rx.err.fragment ),
463 le32_to_cpu ( stats.rx.err.jabber ),
464 le32_to_cpu ( stats.rx.err.undersize ),
465 le32_to_cpu ( stats.rx.err.oversize ),
466 le32_to_cpu ( stats.rx.err.dropped ) );
467 DBGC ( smsc75xx, "SMSC75XX %p RXB ucast %d bcast %d mcast %d\n",
468 smsc75xx, le32_to_cpu ( stats.rx.byte.unicast ),
469 le32_to_cpu ( stats.rx.byte.broadcast ),
470 le32_to_cpu ( stats.rx.byte.multicast ) );
471 DBGC ( smsc75xx, "SMSC75XX %p RXF ucast %d bcast %d mcast %d pause "
472 "%d\n", smsc75xx, le32_to_cpu ( stats.rx.frame.unicast ),
473 le32_to_cpu ( stats.rx.frame.broadcast ),
474 le32_to_cpu ( stats.rx.frame.multicast ),
475 le32_to_cpu ( stats.rx.frame.pause ) );
476 DBGC ( smsc75xx, "SMSC75XX %p TXE fcs %d def %d car %d cnt %d sgl %d "
477 "mul %d exc %d lat %d\n", smsc75xx,
478 le32_to_cpu ( stats.tx.err.fcs ),
479 le32_to_cpu ( stats.tx.err.deferral ),
480 le32_to_cpu ( stats.tx.err.carrier ),
481 le32_to_cpu ( stats.tx.err.count ),
482 le32_to_cpu ( stats.tx.err.single ),
483 le32_to_cpu ( stats.tx.err.multiple ),
484 le32_to_cpu ( stats.tx.err.excessive ),
485 le32_to_cpu ( stats.tx.err.late ) );
486 DBGC ( smsc75xx, "SMSC75XX %p TXB ucast %d bcast %d mcast %d\n",
487 smsc75xx, le32_to_cpu ( stats.tx.byte.unicast ),
488 le32_to_cpu ( stats.tx.byte.broadcast ),
489 le32_to_cpu ( stats.tx.byte.multicast ) );
490 DBGC ( smsc75xx, "SMSC75XX %p TXF ucast %d bcast %d mcast %d pause "
491 "%d\n", smsc75xx, le32_to_cpu ( stats.tx.frame.unicast ),
492 le32_to_cpu ( stats.tx.frame.broadcast ),
493 le32_to_cpu ( stats.tx.frame.multicast ),
494 le32_to_cpu ( stats.tx.frame.pause ) );
499 /******************************************************************************
503 ******************************************************************************
509 * @v smsc75xx SMSC75xx device
510 * @ret rc Return status code
512 static int smsc75xx_reset ( struct smsc75xx_device *smsc75xx ) {
517 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_HW_CFG,
518 SMSC75XX_HW_CFG_LRST ) ) != 0 )
521 /* Wait for reset to complete */
522 udelay ( SMSC75XX_RESET_DELAY_US );
524 /* Check that reset has completed */
525 if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_HW_CFG,
528 if ( hw_cfg & SMSC75XX_HW_CFG_LRST ) {
529 DBGC ( smsc75xx, "SMSC75XX %p failed to reset\n", smsc75xx );
536 /******************************************************************************
538 * Endpoint operations
540 ******************************************************************************
544 * Complete interrupt transfer
547 * @v iobuf I/O buffer
548 * @v rc Completion status code
550 static void smsc75xx_intr_complete ( struct usb_endpoint *ep,
551 struct io_buffer *iobuf, int rc ) {
552 struct smsc75xx_device *smsc75xx =
553 container_of ( ep, struct smsc75xx_device, usbnet.intr );
554 struct net_device *netdev = smsc75xx->netdev;
555 struct smsc75xx_interrupt *intr;
557 /* Profile completions */
558 profile_start ( &smsc75xx_intr_profiler );
560 /* Ignore packets cancelled when the endpoint closes */
564 /* Record USB errors against the network device */
566 DBGC ( smsc75xx, "SMSC75XX %p interrupt failed: %s\n",
567 smsc75xx, strerror ( rc ) );
568 DBGC_HDA ( smsc75xx, 0, iobuf->data, iob_len ( iobuf ) );
569 netdev_rx_err ( netdev, NULL, rc );
573 /* Extract interrupt data */
574 if ( iob_len ( iobuf ) != sizeof ( *intr ) ) {
575 DBGC ( smsc75xx, "SMSC75XX %p malformed interrupt\n",
577 DBGC_HDA ( smsc75xx, 0, iobuf->data, iob_len ( iobuf ) );
578 netdev_rx_err ( netdev, NULL, rc );
583 /* Record interrupt status */
584 smsc75xx->int_sts = le32_to_cpu ( intr->int_sts );
585 profile_stop ( &smsc75xx_intr_profiler );
588 /* Free I/O buffer */
592 /** Interrupt endpoint operations */
593 static struct usb_endpoint_driver_operations smsc75xx_intr_operations = {
594 .complete = smsc75xx_intr_complete,
598 * Complete bulk IN transfer
601 * @v iobuf I/O buffer
602 * @v rc Completion status code
604 static void smsc75xx_in_complete ( struct usb_endpoint *ep,
605 struct io_buffer *iobuf, int rc ) {
606 struct smsc75xx_device *smsc75xx =
607 container_of ( ep, struct smsc75xx_device, usbnet.in );
608 struct net_device *netdev = smsc75xx->netdev;
609 struct smsc75xx_rx_header *header;
611 /* Profile completions */
612 profile_start ( &smsc75xx_in_profiler );
614 /* Ignore packets cancelled when the endpoint closes */
620 /* Record USB errors against the network device */
622 DBGC ( smsc75xx, "SMSC75XX %p bulk IN failed: %s\n",
623 smsc75xx, strerror ( rc ) );
628 if ( iob_len ( iobuf ) < ( sizeof ( *header ) ) ) {
629 DBGC ( smsc75xx, "SMSC75XX %p underlength bulk IN\n",
631 DBGC_HDA ( smsc75xx, 0, iobuf->data, iob_len ( iobuf ) );
637 header = iobuf->data;
638 iob_pull ( iobuf, sizeof ( *header ) );
640 /* Check for errors */
641 if ( header->command & cpu_to_le32 ( SMSC75XX_RX_RED ) ) {
642 DBGC ( smsc75xx, "SMSC75XX %p receive error (%08x):\n",
643 smsc75xx, le32_to_cpu ( header->command ) );
644 DBGC_HDA ( smsc75xx, 0, iobuf->data, iob_len ( iobuf ) );
649 /* Hand off to network stack */
650 netdev_rx ( netdev, iob_disown ( iobuf ) );
652 profile_stop ( &smsc75xx_in_profiler );
656 /* Hand off to network stack */
657 netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
660 /** Bulk IN endpoint operations */
661 static struct usb_endpoint_driver_operations smsc75xx_in_operations = {
662 .complete = smsc75xx_in_complete,
668 * @v smsc75xx SMSC75xx device
669 * @v iobuf I/O buffer
670 * @ret rc Return status code
672 static int smsc75xx_out_transmit ( struct smsc75xx_device *smsc75xx,
673 struct io_buffer *iobuf ) {
674 struct smsc75xx_tx_header *header;
675 size_t len = iob_len ( iobuf );
678 /* Profile transmissions */
679 profile_start ( &smsc75xx_out_profiler );
682 if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
684 header = iob_push ( iobuf, sizeof ( *header ) );
685 header->command = cpu_to_le32 ( SMSC75XX_TX_FCS | len );
689 /* Enqueue I/O buffer */
690 if ( ( rc = usb_stream ( &smsc75xx->usbnet.out, iobuf, 0 ) ) != 0 )
693 profile_stop ( &smsc75xx_out_profiler );
698 * Complete bulk OUT transfer
701 * @v iobuf I/O buffer
702 * @v rc Completion status code
704 static void smsc75xx_out_complete ( struct usb_endpoint *ep,
705 struct io_buffer *iobuf, int rc ) {
706 struct smsc75xx_device *smsc75xx =
707 container_of ( ep, struct smsc75xx_device, usbnet.out );
708 struct net_device *netdev = smsc75xx->netdev;
710 /* Report TX completion */
711 netdev_tx_complete_err ( netdev, iobuf, rc );
714 /** Bulk OUT endpoint operations */
715 static struct usb_endpoint_driver_operations smsc75xx_out_operations = {
716 .complete = smsc75xx_out_complete,
719 /******************************************************************************
721 * Network device interface
723 ******************************************************************************
727 * Open network device
729 * @v netdev Network device
730 * @ret rc Return status code
732 static int smsc75xx_open ( struct net_device *netdev ) {
733 struct smsc75xx_device *smsc75xx = netdev->priv;
734 union smsc75xx_mac mac;
737 /* Clear stored interrupt status */
738 smsc75xx->int_sts = 0;
740 /* Copy MAC address */
741 memset ( &mac, 0, sizeof ( mac ) );
742 memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
744 /* Configure bulk IN empty response */
745 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_HW_CFG,
746 SMSC75XX_HW_CFG_BIR ) ) != 0 )
749 /* Open USB network device */
750 if ( ( rc = usbnet_open ( &smsc75xx->usbnet ) ) != 0 ) {
751 DBGC ( smsc75xx, "SMSC75XX %p could not open: %s\n",
752 smsc75xx, strerror ( rc ) );
756 /* Configure interrupt endpoint */
757 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_INT_EP_CTL,
758 ( SMSC75XX_INT_EP_CTL_RDFO_EN |
759 SMSC75XX_INT_EP_CTL_PHY_EN ) ) ) != 0 )
762 /* Configure bulk IN delay */
763 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_BULK_IN_DLY,
764 SMSC75XX_BULK_IN_DLY_SET ( 0 ) ) ) != 0 )
765 goto err_bulk_in_dly;
767 /* Configure receive filters */
768 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_RFE_CTL,
769 ( SMSC75XX_RFE_CTL_AB |
770 SMSC75XX_RFE_CTL_AM |
771 SMSC75XX_RFE_CTL_AU ) ) ) != 0 )
774 /* Configure receive FIFO */
775 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_FCT_RX_CTL,
776 ( SMSC75XX_FCT_RX_CTL_EN |
777 SMSC75XX_FCT_RX_CTL_BAD ) ) ) != 0 )
780 /* Configure transmit FIFO */
781 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_FCT_TX_CTL,
782 SMSC75XX_FCT_TX_CTL_EN ) ) != 0 )
785 /* Configure receive datapath */
786 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_MAC_RX,
787 ( SMSC75XX_MAC_RX_MAX_SIZE_DEFAULT |
788 SMSC75XX_MAC_RX_FCS |
789 SMSC75XX_MAC_RX_EN ) ) ) != 0 )
792 /* Configure transmit datapath */
793 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_MAC_TX,
794 SMSC75XX_MAC_TX_EN ) ) != 0 )
797 /* Write MAC address high register */
798 if ( ( rc = smsc75xx_raw_writel ( smsc75xx, SMSC75XX_RX_ADDRH,
799 mac.addr.h ) ) != 0 )
802 /* Write MAC address low register */
803 if ( ( rc = smsc75xx_raw_writel ( smsc75xx, SMSC75XX_RX_ADDRL,
804 mac.addr.l ) ) != 0 )
807 /* Write MAC address perfect filter high register */
808 mac.addr.h |= cpu_to_le32 ( SMSC75XX_ADDR_FILTH_VALID );
809 if ( ( rc = smsc75xx_raw_writel ( smsc75xx, SMSC75XX_ADDR_FILTH ( 0 ),
810 mac.addr.h ) ) != 0 )
813 /* Write MAC address perfect filter low register */
814 if ( ( rc = smsc75xx_raw_writel ( smsc75xx, SMSC75XX_ADDR_FILTL ( 0 ),
815 mac.addr.l ) ) != 0 )
818 /* Enable PHY interrupts */
819 if ( ( rc = mii_write ( &smsc75xx->mii, SMSC75XX_MII_PHY_INTR_MASK,
820 ( SMSC75XX_PHY_INTR_ANEG_DONE |
821 SMSC75XX_PHY_INTR_LINK_DOWN ) ) ) != 0 ) {
822 DBGC ( smsc75xx, "SMSC75XX %p could not set PHY interrupt "
823 "mask: %s\n", smsc75xx, strerror ( rc ) );
824 goto err_phy_intr_mask;
827 /* Update link status */
828 smsc75xx_check_link ( smsc75xx );
844 usbnet_close ( &smsc75xx->usbnet );
847 smsc75xx_reset ( smsc75xx );
852 * Close network device
854 * @v netdev Network device
856 static void smsc75xx_close ( struct net_device *netdev ) {
857 struct smsc75xx_device *smsc75xx = netdev->priv;
859 /* Close USB network device */
860 usbnet_close ( &smsc75xx->usbnet );
862 /* Dump statistics (for debugging) */
863 smsc75xx_dump_statistics ( smsc75xx );
866 smsc75xx_reset ( smsc75xx );
872 * @v netdev Network device
873 * @v iobuf I/O buffer
874 * @ret rc Return status code
876 static int smsc75xx_transmit ( struct net_device *netdev,
877 struct io_buffer *iobuf ) {
878 struct smsc75xx_device *smsc75xx = netdev->priv;
881 /* Transmit packet */
882 if ( ( rc = smsc75xx_out_transmit ( smsc75xx, iobuf ) ) != 0 )
889 * Poll for completed and received packets
891 * @v netdev Network device
893 static void smsc75xx_poll ( struct net_device *netdev ) {
894 struct smsc75xx_device *smsc75xx = netdev->priv;
899 usb_poll ( smsc75xx->bus );
901 /* Refill endpoints */
902 if ( ( rc = usbnet_refill ( &smsc75xx->usbnet ) ) != 0 )
903 netdev_rx_err ( netdev, NULL, rc );
905 /* Do nothing more unless there are interrupts to handle */
906 int_sts = smsc75xx->int_sts;
910 /* Check link status if applicable */
911 if ( int_sts & SMSC75XX_INT_STS_PHY_INT ) {
912 smsc75xx_check_link ( smsc75xx );
913 int_sts &= ~SMSC75XX_INT_STS_PHY_INT;
916 /* Record RX FIFO overflow if applicable */
917 if ( int_sts & SMSC75XX_INT_STS_RDFO_INT ) {
918 DBGC2 ( smsc75xx, "SMSC75XX %p RX FIFO overflowed\n",
920 netdev_rx_err ( netdev, NULL, -ENOBUFS );
921 int_sts &= ~SMSC75XX_INT_STS_RDFO_INT;
924 /* Check for unexpected interrupts */
926 DBGC ( smsc75xx, "SMSC75XX %p unexpected interrupt %#08x\n",
928 netdev_rx_err ( netdev, NULL, -ENOTTY );
931 /* Clear interrupts */
932 if ( ( rc = smsc75xx_writel ( smsc75xx, SMSC75XX_INT_STS,
933 smsc75xx->int_sts ) ) != 0 )
934 netdev_rx_err ( netdev, NULL, rc );
935 smsc75xx->int_sts = 0;
938 /** SMSC75xx network device operations */
939 static struct net_device_operations smsc75xx_operations = {
940 .open = smsc75xx_open,
941 .close = smsc75xx_close,
942 .transmit = smsc75xx_transmit,
943 .poll = smsc75xx_poll,
946 /******************************************************************************
950 ******************************************************************************
956 * @v func USB function
957 * @v config Configuration descriptor
958 * @ret rc Return status code
960 static int smsc75xx_probe ( struct usb_function *func,
961 struct usb_configuration_descriptor *config ) {
962 struct usb_device *usb = func->usb;
963 struct net_device *netdev;
964 struct smsc75xx_device *smsc75xx;
967 /* Allocate and initialise structure */
968 netdev = alloc_etherdev ( sizeof ( *smsc75xx ) );
973 netdev_init ( netdev, &smsc75xx_operations );
974 netdev->dev = &func->dev;
975 smsc75xx = netdev->priv;
976 memset ( smsc75xx, 0, sizeof ( *smsc75xx ) );
978 smsc75xx->bus = usb->port->hub->bus;
979 smsc75xx->netdev = netdev;
980 usbnet_init ( &smsc75xx->usbnet, func, &smsc75xx_intr_operations,
981 &smsc75xx_in_operations, &smsc75xx_out_operations );
982 usb_refill_init ( &smsc75xx->usbnet.intr, 0, SMSC75XX_INTR_MAX_FILL );
983 usb_refill_init ( &smsc75xx->usbnet.in, SMSC75XX_IN_MTU,
984 SMSC75XX_IN_MAX_FILL );
985 mii_init ( &smsc75xx->mii, &smsc75xx_mii_operations );
986 DBGC ( smsc75xx, "SMSC75XX %p on %s\n", smsc75xx, func->name );
988 /* Describe USB network device */
989 if ( ( rc = usbnet_describe ( &smsc75xx->usbnet, config ) ) != 0 ) {
990 DBGC ( smsc75xx, "SMSC75XX %p could not describe: %s\n",
991 smsc75xx, strerror ( rc ) );
996 if ( ( rc = smsc75xx_reset ( smsc75xx ) ) != 0 )
999 /* Read MAC address */
1000 if ( ( rc = smsc75xx_eeprom_read ( smsc75xx, SMSC75XX_EEPROM_MAC,
1001 netdev->hw_addr, ETH_ALEN ) ) != 0 )
1002 goto err_eeprom_read;
1004 /* Register network device */
1005 if ( ( rc = register_netdev ( netdev ) ) != 0 )
1008 usb_func_set_drvdata ( func, netdev );
1011 unregister_netdev ( netdev );
1016 netdev_nullify ( netdev );
1017 netdev_put ( netdev );
1025 * @v func USB function
1027 static void smsc75xx_remove ( struct usb_function *func ) {
1028 struct net_device *netdev = usb_func_get_drvdata ( func );
1030 unregister_netdev ( netdev );
1031 netdev_nullify ( netdev );
1032 netdev_put ( netdev );
1035 /** SMSC75xx device IDs */
1036 static struct usb_device_id smsc75xx_ids[] = {
1041 .class = { 0xff, 0x00, 0xff },
1047 .class = { 0xff, 0x00, 0xff },
1051 /** SMSC LAN75xx driver */
1052 struct usb_driver smsc75xx_driver __usb_driver = {
1053 .ids = smsc75xx_ids,
1054 .id_count = ( sizeof ( smsc75xx_ids ) / sizeof ( smsc75xx_ids[0] ) ),
1055 .probe = smsc75xx_probe,
1056 .remove = smsc75xx_remove,