1 /* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
3 * Author : Liu Junliang <liujunliang_ljl@163.com>
5 * Based on asix_common.c, asix_devices.c
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.*
12 #include <linux/module.h>
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18 #include <linux/workqueue.h>
19 #include <linux/mii.h>
20 #include <linux/usb.h>
21 #include <linux/crc32.h>
22 #include <linux/usb/usbnet.h>
23 #include <linux/slab.h>
24 #include <linux/if_vlan.h>
28 static int sr_read_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
33 err
= usbnet_read_cmd(dev
, cmd
, SR_REQ_RD_REG
, value
, index
,
35 if ((err
!= size
) && (err
>= 0))
41 static int sr_write_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
46 err
= usbnet_write_cmd(dev
, cmd
, SR_REQ_WR_REG
, value
, index
,
48 if ((err
!= size
) && (err
>= 0))
55 sr_write_cmd_async(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
58 usbnet_write_cmd_async(dev
, cmd
, SR_REQ_WR_REG
, value
, index
, data
,
62 static int sr_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
)
66 /* This check is no longer done by usbnet */
67 if (skb
->len
< dev
->net
->hard_header_len
)
70 while (offset
+ sizeof(u32
) < skb
->len
) {
71 struct sk_buff
*sr_skb
;
73 u32 header
= get_unaligned_le32(skb
->data
+ offset
);
75 offset
+= sizeof(u32
);
76 /* get the packet length */
77 size
= (u16
) (header
& 0x7ff);
78 if (size
!= ((~header
>> 16) & 0x07ff)) {
79 netdev_err(dev
->net
, "%s : Bad Header Length\n",
84 if ((size
> dev
->net
->mtu
+ ETH_HLEN
+ VLAN_HLEN
) ||
85 (size
+ offset
> skb
->len
)) {
86 netdev_err(dev
->net
, "%s : Bad RX Length %d\n",
90 sr_skb
= netdev_alloc_skb_ip_align(dev
->net
, size
);
94 skb_put(sr_skb
, size
);
95 memcpy(sr_skb
->data
, skb
->data
+ offset
, size
);
96 usbnet_skb_return(dev
, sr_skb
);
98 offset
+= (size
+ 1) & 0xfffe;
101 if (skb
->len
!= offset
) {
102 netdev_err(dev
->net
, "%s : Bad SKB Length %d\n", __func__
,
110 static struct sk_buff
*sr_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
,
113 int headroom
= skb_headroom(skb
);
114 int tailroom
= skb_tailroom(skb
);
115 u32 padbytes
= 0xffff0000;
120 padlen
= ((skb
->len
+ 4) % (dev
->maxpacket
- 1)) ? 0 : 4;
122 if ((!skb_cloned(skb
)) && ((headroom
+ tailroom
) >= (4 + padlen
))) {
123 if ((headroom
< 4) || (tailroom
< padlen
)) {
124 skb
->data
= memmove(skb
->head
+ 4, skb
->data
,
126 skb_set_tail_pointer(skb
, skb
->len
);
129 struct sk_buff
*skb2
;
130 skb2
= skb_copy_expand(skb
, 4, padlen
, flags
);
131 dev_kfree_skb_any(skb
);
137 ptr
= skb_push(skb
, 4);
138 packet_len
= (((skb
->len
- 4) ^ 0x0000ffff) << 16) + (skb
->len
- 4);
139 put_unaligned_le32(packet_len
, ptr
);
142 put_unaligned_le32(padbytes
, skb_tail_pointer(skb
));
143 skb_put(skb
, sizeof(padbytes
));
146 usbnet_set_skb_tx_stats(skb
, 1, 0);
150 static void sr_status(struct usbnet
*dev
, struct urb
*urb
)
152 struct sr9800_int_data
*event
;
155 if (urb
->actual_length
< 8)
158 event
= urb
->transfer_buffer
;
159 link
= event
->link
& 0x01;
160 if (netif_carrier_ok(dev
->net
) != link
) {
161 usbnet_link_change(dev
, link
, 1);
162 netdev_dbg(dev
->net
, "Link Status is: %d\n", link
);
168 static inline int sr_set_sw_mii(struct usbnet
*dev
)
172 ret
= sr_write_cmd(dev
, SR_CMD_SET_SW_MII
, 0x0000, 0, 0, NULL
);
174 netdev_err(dev
->net
, "Failed to enable software MII access\n");
178 static inline int sr_set_hw_mii(struct usbnet
*dev
)
182 ret
= sr_write_cmd(dev
, SR_CMD_SET_HW_MII
, 0x0000, 0, 0, NULL
);
184 netdev_err(dev
->net
, "Failed to enable hardware MII access\n");
188 static inline int sr_get_phy_addr(struct usbnet
*dev
)
193 ret
= sr_read_cmd(dev
, SR_CMD_READ_PHY_ID
, 0, 0, 2, buf
);
195 netdev_err(dev
->net
, "%s : Error reading PHYID register:%02x\n",
199 netdev_dbg(dev
->net
, "%s : returning 0x%04x\n", __func__
,
208 static int sr_sw_reset(struct usbnet
*dev
, u8 flags
)
212 ret
= sr_write_cmd(dev
, SR_CMD_SW_RESET
, flags
, 0, 0, NULL
);
214 netdev_err(dev
->net
, "Failed to send software reset:%02x\n",
220 static u16
sr_read_rx_ctl(struct usbnet
*dev
)
225 ret
= sr_read_cmd(dev
, SR_CMD_READ_RX_CTL
, 0, 0, 2, &v
);
227 netdev_err(dev
->net
, "Error reading RX_CTL register:%02x\n",
232 ret
= le16_to_cpu(v
);
237 static int sr_write_rx_ctl(struct usbnet
*dev
, u16 mode
)
241 netdev_dbg(dev
->net
, "%s : mode = 0x%04x\n", __func__
, mode
);
242 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_RX_CTL
, mode
, 0, 0, NULL
);
245 "Failed to write RX_CTL mode to 0x%04x:%02x\n",
251 static u16
sr_read_medium_status(struct usbnet
*dev
)
256 ret
= sr_read_cmd(dev
, SR_CMD_READ_MEDIUM_STATUS
, 0, 0, 2, &v
);
259 "Error reading Medium Status register:%02x\n", ret
);
260 return ret
; /* TODO: callers not checking for error ret */
263 return le16_to_cpu(v
);
266 static int sr_write_medium_mode(struct usbnet
*dev
, u16 mode
)
270 netdev_dbg(dev
->net
, "%s : mode = 0x%04x\n", __func__
, mode
);
271 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_MEDIUM_MODE
, mode
, 0, 0, NULL
);
274 "Failed to write Medium Mode mode to 0x%04x:%02x\n",
279 static int sr_write_gpio(struct usbnet
*dev
, u16 value
, int sleep
)
283 netdev_dbg(dev
->net
, "%s : value = 0x%04x\n", __func__
, value
);
284 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_GPIOS
, value
, 0, 0, NULL
);
286 netdev_err(dev
->net
, "Failed to write GPIO value 0x%04x:%02x\n",
294 /* SR9800 have a 16-bit RX_CTL value */
295 static void sr_set_multicast(struct net_device
*net
)
297 struct usbnet
*dev
= netdev_priv(net
);
298 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
299 u16 rx_ctl
= SR_DEFAULT_RX_CTL
;
301 if (net
->flags
& IFF_PROMISC
) {
302 rx_ctl
|= SR_RX_CTL_PRO
;
303 } else if (net
->flags
& IFF_ALLMULTI
||
304 netdev_mc_count(net
) > SR_MAX_MCAST
) {
305 rx_ctl
|= SR_RX_CTL_AMALL
;
306 } else if (netdev_mc_empty(net
)) {
307 /* just broadcast and directed */
309 /* We use the 20 byte dev->data
310 * for our 8 byte filter buffer
311 * to avoid allocating memory that
312 * is tricky to free later
314 struct netdev_hw_addr
*ha
;
317 memset(data
->multi_filter
, 0, SR_MCAST_FILTER_SIZE
);
319 /* Build the multicast hash filter. */
320 netdev_for_each_mc_addr(ha
, net
) {
321 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
322 data
->multi_filter
[crc_bits
>> 3] |=
326 sr_write_cmd_async(dev
, SR_CMD_WRITE_MULTI_FILTER
, 0, 0,
327 SR_MCAST_FILTER_SIZE
, data
->multi_filter
);
329 rx_ctl
|= SR_RX_CTL_AM
;
332 sr_write_cmd_async(dev
, SR_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
335 static int sr_mdio_read(struct net_device
*net
, int phy_id
, int loc
)
337 struct usbnet
*dev
= netdev_priv(net
);
340 mutex_lock(&dev
->phy_mutex
);
342 sr_read_cmd(dev
, SR_CMD_READ_MII_REG
, phy_id
, (__u16
)loc
, 2, &res
);
344 mutex_unlock(&dev
->phy_mutex
);
347 "%s : phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", __func__
,
348 phy_id
, loc
, le16_to_cpu(res
));
350 return le16_to_cpu(res
);
354 sr_mdio_write(struct net_device
*net
, int phy_id
, int loc
, int val
)
356 struct usbnet
*dev
= netdev_priv(net
);
357 __le16 res
= cpu_to_le16(val
);
360 "%s : phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", __func__
,
362 mutex_lock(&dev
->phy_mutex
);
364 sr_write_cmd(dev
, SR_CMD_WRITE_MII_REG
, phy_id
, (__u16
)loc
, 2, &res
);
366 mutex_unlock(&dev
->phy_mutex
);
369 /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
370 static u32
sr_get_phyid(struct usbnet
*dev
)
376 /* Poll for the rare case the FW or phy isn't ready yet. */
377 for (i
= 0; i
< 100; i
++) {
378 phy_reg
= sr_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID1
);
379 if (phy_reg
!= 0 && phy_reg
!= 0xFFFF)
384 if (phy_reg
<= 0 || phy_reg
== 0xFFFF)
387 phy_id
= (phy_reg
& 0xffff) << 16;
389 phy_reg
= sr_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID2
);
393 phy_id
|= (phy_reg
& 0xffff);
399 sr_get_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
401 struct usbnet
*dev
= netdev_priv(net
);
404 if (sr_read_cmd(dev
, SR_CMD_READ_MONITOR_MODE
, 0, 0, 1, &opt
) < 0) {
405 wolinfo
->supported
= 0;
406 wolinfo
->wolopts
= 0;
409 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
;
410 wolinfo
->wolopts
= 0;
411 if (opt
& SR_MONITOR_LINK
)
412 wolinfo
->wolopts
|= WAKE_PHY
;
413 if (opt
& SR_MONITOR_MAGIC
)
414 wolinfo
->wolopts
|= WAKE_MAGIC
;
418 sr_set_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
420 struct usbnet
*dev
= netdev_priv(net
);
423 if (wolinfo
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
426 if (wolinfo
->wolopts
& WAKE_PHY
)
427 opt
|= SR_MONITOR_LINK
;
428 if (wolinfo
->wolopts
& WAKE_MAGIC
)
429 opt
|= SR_MONITOR_MAGIC
;
431 if (sr_write_cmd(dev
, SR_CMD_WRITE_MONITOR_MODE
,
432 opt
, 0, 0, NULL
) < 0)
438 static int sr_get_eeprom_len(struct net_device
*net
)
440 struct usbnet
*dev
= netdev_priv(net
);
441 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
443 return data
->eeprom_len
;
446 static int sr_get_eeprom(struct net_device
*net
,
447 struct ethtool_eeprom
*eeprom
, u8
*data
)
449 struct usbnet
*dev
= netdev_priv(net
);
450 __le16
*ebuf
= (__le16
*)data
;
454 /* Crude hack to ensure that we don't overwrite memory
455 * if an odd length is supplied
460 eeprom
->magic
= SR_EEPROM_MAGIC
;
462 /* sr9800 returns 2 bytes from eeprom on read */
463 for (i
= 0; i
< eeprom
->len
/ 2; i
++) {
464 ret
= sr_read_cmd(dev
, SR_CMD_READ_EEPROM
, eeprom
->offset
+ i
,
472 static void sr_get_drvinfo(struct net_device
*net
,
473 struct ethtool_drvinfo
*info
)
475 /* Inherit standard device info */
476 usbnet_get_drvinfo(net
, info
);
477 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
));
478 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
481 static u32
sr_get_link(struct net_device
*net
)
483 struct usbnet
*dev
= netdev_priv(net
);
485 return mii_link_ok(&dev
->mii
);
488 static int sr_ioctl(struct net_device
*net
, struct ifreq
*rq
, int cmd
)
490 struct usbnet
*dev
= netdev_priv(net
);
492 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
495 static int sr_set_mac_address(struct net_device
*net
, void *p
)
497 struct usbnet
*dev
= netdev_priv(net
);
498 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
499 struct sockaddr
*addr
= p
;
501 if (netif_running(net
))
503 if (!is_valid_ether_addr(addr
->sa_data
))
504 return -EADDRNOTAVAIL
;
506 memcpy(net
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
508 /* We use the 20 byte dev->data
509 * for our 6 byte mac buffer
510 * to avoid allocating memory that
511 * is tricky to free later
513 memcpy(data
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
514 sr_write_cmd_async(dev
, SR_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
520 static const struct ethtool_ops sr9800_ethtool_ops
= {
521 .get_drvinfo
= sr_get_drvinfo
,
522 .get_link
= sr_get_link
,
523 .get_msglevel
= usbnet_get_msglevel
,
524 .set_msglevel
= usbnet_set_msglevel
,
525 .get_wol
= sr_get_wol
,
526 .set_wol
= sr_set_wol
,
527 .get_eeprom_len
= sr_get_eeprom_len
,
528 .get_eeprom
= sr_get_eeprom
,
529 .nway_reset
= usbnet_nway_reset
,
530 .get_link_ksettings
= usbnet_get_link_ksettings
,
531 .set_link_ksettings
= usbnet_set_link_ksettings
,
534 static int sr9800_link_reset(struct usbnet
*dev
)
536 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
539 mii_check_media(&dev
->mii
, 1, 1);
540 mii_ethtool_gset(&dev
->mii
, &ecmd
);
541 mode
= SR9800_MEDIUM_DEFAULT
;
543 if (ethtool_cmd_speed(&ecmd
) != SPEED_100
)
544 mode
&= ~SR_MEDIUM_PS
;
546 if (ecmd
.duplex
!= DUPLEX_FULL
)
547 mode
&= ~SR_MEDIUM_FD
;
549 netdev_dbg(dev
->net
, "%s : speed: %u duplex: %d mode: 0x%04x\n",
550 __func__
, ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
552 sr_write_medium_mode(dev
, mode
);
558 static int sr9800_set_default_mode(struct usbnet
*dev
)
563 sr_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
564 sr_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
565 ADVERTISE_ALL
| ADVERTISE_CSMA
);
566 mii_nway_restart(&dev
->mii
);
568 ret
= sr_write_medium_mode(dev
, SR9800_MEDIUM_DEFAULT
);
572 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_IPG012
,
573 SR9800_IPG0_DEFAULT
| SR9800_IPG1_DEFAULT
,
574 SR9800_IPG2_DEFAULT
, 0, NULL
);
576 netdev_dbg(dev
->net
, "Write IPG,IPG1,IPG2 failed: %d\n", ret
);
580 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
581 ret
= sr_write_rx_ctl(dev
, SR_DEFAULT_RX_CTL
);
585 rx_ctl
= sr_read_rx_ctl(dev
);
586 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after all initializations\n",
589 rx_ctl
= sr_read_medium_status(dev
);
590 netdev_dbg(dev
->net
, "Medium Status:0x%04x after all initializations\n",
598 static int sr9800_reset(struct usbnet
*dev
)
600 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
604 ret
= sr_write_gpio(dev
,
605 SR_GPIO_RSE
| SR_GPIO_GPO_2
| SR_GPIO_GPO2EN
, 5);
609 embd_phy
= ((sr_get_phy_addr(dev
) & 0x1f) == 0x10 ? 1 : 0);
611 ret
= sr_write_cmd(dev
, SR_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
613 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
617 ret
= sr_sw_reset(dev
, SR_SWRESET_IPPD
| SR_SWRESET_PRL
);
623 ret
= sr_sw_reset(dev
, SR_SWRESET_CLEAR
);
630 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
634 ret
= sr_sw_reset(dev
, SR_SWRESET_PRTE
);
640 rx_ctl
= sr_read_rx_ctl(dev
);
641 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after software reset\n", rx_ctl
);
642 ret
= sr_write_rx_ctl(dev
, 0x0000);
646 rx_ctl
= sr_read_rx_ctl(dev
);
647 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl
);
649 ret
= sr_sw_reset(dev
, SR_SWRESET_PRL
);
655 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
| SR_SWRESET_PRL
);
661 ret
= sr9800_set_default_mode(dev
);
665 /* Rewrite MAC address */
666 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
667 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
678 static const struct net_device_ops sr9800_netdev_ops
= {
679 .ndo_open
= usbnet_open
,
680 .ndo_stop
= usbnet_stop
,
681 .ndo_start_xmit
= usbnet_start_xmit
,
682 .ndo_tx_timeout
= usbnet_tx_timeout
,
683 .ndo_change_mtu
= usbnet_change_mtu
,
684 .ndo_get_stats64
= dev_get_tstats64
,
685 .ndo_set_mac_address
= sr_set_mac_address
,
686 .ndo_validate_addr
= eth_validate_addr
,
687 .ndo_do_ioctl
= sr_ioctl
,
688 .ndo_set_rx_mode
= sr_set_multicast
,
691 static int sr9800_phy_powerup(struct usbnet
*dev
)
695 /* set the embedded Ethernet PHY in power-down state */
696 ret
= sr_sw_reset(dev
, SR_SWRESET_IPPD
| SR_SWRESET_IPRL
);
698 netdev_err(dev
->net
, "Failed to power down PHY : %d\n", ret
);
703 /* set the embedded Ethernet PHY in power-up state */
704 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
706 netdev_err(dev
->net
, "Failed to reset PHY: %d\n", ret
);
711 /* set the embedded Ethernet PHY in reset state */
712 ret
= sr_sw_reset(dev
, SR_SWRESET_CLEAR
);
714 netdev_err(dev
->net
, "Failed to power up PHY: %d\n", ret
);
719 /* set the embedded Ethernet PHY in power-up state */
720 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
722 netdev_err(dev
->net
, "Failed to reset PHY: %d\n", ret
);
729 static int sr9800_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
731 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
732 u16 led01_mux
, led23_mux
;
737 data
->eeprom_len
= SR9800_EEPROM_LEN
;
739 usbnet_get_endpoints(dev
, intf
);
741 /* LED Setting Rule :
745 * CC : MFA2(LED2), Reserved for SR9800
746 * DD : MFA3(LED3), Reserved for SR9800
748 led01_mux
= (SR_LED_MUX_LINK_ACTIVE
<< 8) | SR_LED_MUX_LINK
;
749 led23_mux
= (SR_LED_MUX_LINK_ACTIVE
<< 8) | SR_LED_MUX_TX_ACTIVE
;
750 ret
= sr_write_cmd(dev
, SR_CMD_LED_MUX
, led01_mux
, led23_mux
, 0, NULL
);
752 netdev_err(dev
->net
, "set LINK LED failed : %d\n", ret
);
756 /* Get the MAC address */
757 ret
= sr_read_cmd(dev
, SR_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
,
760 netdev_dbg(dev
->net
, "Failed to read MAC address: %d\n", ret
);
763 netdev_dbg(dev
->net
, "mac addr : %pM\n", dev
->net
->dev_addr
);
765 /* Initialize MII structure */
766 dev
->mii
.dev
= dev
->net
;
767 dev
->mii
.mdio_read
= sr_mdio_read
;
768 dev
->mii
.mdio_write
= sr_mdio_write
;
769 dev
->mii
.phy_id_mask
= 0x1f;
770 dev
->mii
.reg_num_mask
= 0x1f;
771 dev
->mii
.phy_id
= sr_get_phy_addr(dev
);
773 dev
->net
->netdev_ops
= &sr9800_netdev_ops
;
774 dev
->net
->ethtool_ops
= &sr9800_ethtool_ops
;
776 embd_phy
= ((dev
->mii
.phy_id
& 0x1f) == 0x10 ? 1 : 0);
777 /* Reset the PHY to normal operation mode */
778 ret
= sr_write_cmd(dev
, SR_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
780 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
784 /* Init PHY routine */
785 ret
= sr9800_phy_powerup(dev
);
789 rx_ctl
= sr_read_rx_ctl(dev
);
790 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after software reset\n", rx_ctl
);
791 ret
= sr_write_rx_ctl(dev
, 0x0000);
795 rx_ctl
= sr_read_rx_ctl(dev
);
796 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl
);
798 /* Read PHYID register *AFTER* the PHY was reset properly */
799 phyid
= sr_get_phyid(dev
);
800 netdev_dbg(dev
->net
, "PHYID=0x%08x\n", phyid
);
802 /* medium mode setting */
803 ret
= sr9800_set_default_mode(dev
);
807 if (dev
->udev
->speed
== USB_SPEED_HIGH
) {
808 ret
= sr_write_cmd(dev
, SR_CMD_BULKIN_SIZE
,
809 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].byte_cnt
,
810 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].threshold
,
813 netdev_err(dev
->net
, "Reset RX_CTL failed: %d\n", ret
);
817 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].size
;
819 ret
= sr_write_cmd(dev
, SR_CMD_BULKIN_SIZE
,
820 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].byte_cnt
,
821 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].threshold
,
824 netdev_err(dev
->net
, "Reset RX_CTL failed: %d\n", ret
);
828 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].size
;
830 netdev_dbg(dev
->net
, "%s : setting rx_urb_size with : %zu\n", __func__
,
838 static const struct driver_info sr9800_driver_info
= {
839 .description
= "CoreChip SR9800 USB 2.0 Ethernet",
842 .link_reset
= sr9800_link_reset
,
843 .reset
= sr9800_reset
,
844 .flags
= DRIVER_FLAG
,
845 .rx_fixup
= sr_rx_fixup
,
846 .tx_fixup
= sr_tx_fixup
,
849 static const struct usb_device_id products
[] = {
851 USB_DEVICE(0x0fe6, 0x9800), /* SR9800 Device */
852 .driver_info
= (unsigned long) &sr9800_driver_info
,
857 MODULE_DEVICE_TABLE(usb
, products
);
859 static struct usb_driver sr_driver
= {
861 .id_table
= products
,
862 .probe
= usbnet_probe
,
863 .suspend
= usbnet_suspend
,
864 .resume
= usbnet_resume
,
865 .disconnect
= usbnet_disconnect
,
866 .supports_autosuspend
= 1,
869 module_usb_driver(sr_driver
);
871 MODULE_AUTHOR("Liu Junliang <liujunliang_ljl@163.com");
872 MODULE_VERSION(DRIVER_VERSION
);
873 MODULE_DESCRIPTION("SR9800 USB 2.0 USB2NET Dev : http://www.corechip-sz.com");
874 MODULE_LICENSE("GPL");