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;
119 padlen
= ((skb
->len
+ 4) % (dev
->maxpacket
- 1)) ? 0 : 4;
121 if ((!skb_cloned(skb
)) && ((headroom
+ tailroom
) >= (4 + padlen
))) {
122 if ((headroom
< 4) || (tailroom
< padlen
)) {
123 skb
->data
= memmove(skb
->head
+ 4, skb
->data
,
125 skb_set_tail_pointer(skb
, skb
->len
);
128 struct sk_buff
*skb2
;
129 skb2
= skb_copy_expand(skb
, 4, padlen
, flags
);
130 dev_kfree_skb_any(skb
);
137 packet_len
= (((skb
->len
- 4) ^ 0x0000ffff) << 16) + (skb
->len
- 4);
138 cpu_to_le32s(&packet_len
);
139 skb_copy_to_linear_data(skb
, &packet_len
, sizeof(packet_len
));
142 cpu_to_le32s(&padbytes
);
143 memcpy(skb_tail_pointer(skb
), &padbytes
, sizeof(padbytes
));
144 skb_put(skb
, sizeof(padbytes
));
147 usbnet_set_skb_tx_stats(skb
, 1, 0);
151 static void sr_status(struct usbnet
*dev
, struct urb
*urb
)
153 struct sr9800_int_data
*event
;
156 if (urb
->actual_length
< 8)
159 event
= urb
->transfer_buffer
;
160 link
= event
->link
& 0x01;
161 if (netif_carrier_ok(dev
->net
) != link
) {
162 usbnet_link_change(dev
, link
, 1);
163 netdev_dbg(dev
->net
, "Link Status is: %d\n", link
);
169 static inline int sr_set_sw_mii(struct usbnet
*dev
)
173 ret
= sr_write_cmd(dev
, SR_CMD_SET_SW_MII
, 0x0000, 0, 0, NULL
);
175 netdev_err(dev
->net
, "Failed to enable software MII access\n");
179 static inline int sr_set_hw_mii(struct usbnet
*dev
)
183 ret
= sr_write_cmd(dev
, SR_CMD_SET_HW_MII
, 0x0000, 0, 0, NULL
);
185 netdev_err(dev
->net
, "Failed to enable hardware MII access\n");
189 static inline int sr_get_phy_addr(struct usbnet
*dev
)
194 ret
= sr_read_cmd(dev
, SR_CMD_READ_PHY_ID
, 0, 0, 2, buf
);
196 netdev_err(dev
->net
, "%s : Error reading PHYID register:%02x\n",
200 netdev_dbg(dev
->net
, "%s : returning 0x%04x\n", __func__
,
209 static int sr_sw_reset(struct usbnet
*dev
, u8 flags
)
213 ret
= sr_write_cmd(dev
, SR_CMD_SW_RESET
, flags
, 0, 0, NULL
);
215 netdev_err(dev
->net
, "Failed to send software reset:%02x\n",
221 static u16
sr_read_rx_ctl(struct usbnet
*dev
)
226 ret
= sr_read_cmd(dev
, SR_CMD_READ_RX_CTL
, 0, 0, 2, &v
);
228 netdev_err(dev
->net
, "Error reading RX_CTL register:%02x\n",
233 ret
= le16_to_cpu(v
);
238 static int sr_write_rx_ctl(struct usbnet
*dev
, u16 mode
)
242 netdev_dbg(dev
->net
, "%s : mode = 0x%04x\n", __func__
, mode
);
243 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_RX_CTL
, mode
, 0, 0, NULL
);
246 "Failed to write RX_CTL mode to 0x%04x:%02x\n",
252 static u16
sr_read_medium_status(struct usbnet
*dev
)
257 ret
= sr_read_cmd(dev
, SR_CMD_READ_MEDIUM_STATUS
, 0, 0, 2, &v
);
260 "Error reading Medium Status register:%02x\n", ret
);
261 return ret
; /* TODO: callers not checking for error ret */
264 return le16_to_cpu(v
);
267 static int sr_write_medium_mode(struct usbnet
*dev
, u16 mode
)
271 netdev_dbg(dev
->net
, "%s : mode = 0x%04x\n", __func__
, mode
);
272 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_MEDIUM_MODE
, mode
, 0, 0, NULL
);
275 "Failed to write Medium Mode mode to 0x%04x:%02x\n",
280 static int sr_write_gpio(struct usbnet
*dev
, u16 value
, int sleep
)
284 netdev_dbg(dev
->net
, "%s : value = 0x%04x\n", __func__
, value
);
285 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_GPIOS
, value
, 0, 0, NULL
);
287 netdev_err(dev
->net
, "Failed to write GPIO value 0x%04x:%02x\n",
295 /* SR9800 have a 16-bit RX_CTL value */
296 static void sr_set_multicast(struct net_device
*net
)
298 struct usbnet
*dev
= netdev_priv(net
);
299 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
300 u16 rx_ctl
= SR_DEFAULT_RX_CTL
;
302 if (net
->flags
& IFF_PROMISC
) {
303 rx_ctl
|= SR_RX_CTL_PRO
;
304 } else if (net
->flags
& IFF_ALLMULTI
||
305 netdev_mc_count(net
) > SR_MAX_MCAST
) {
306 rx_ctl
|= SR_RX_CTL_AMALL
;
307 } else if (netdev_mc_empty(net
)) {
308 /* just broadcast and directed */
310 /* We use the 20 byte dev->data
311 * for our 8 byte filter buffer
312 * to avoid allocating memory that
313 * is tricky to free later
315 struct netdev_hw_addr
*ha
;
318 memset(data
->multi_filter
, 0, SR_MCAST_FILTER_SIZE
);
320 /* Build the multicast hash filter. */
321 netdev_for_each_mc_addr(ha
, net
) {
322 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
323 data
->multi_filter
[crc_bits
>> 3] |=
327 sr_write_cmd_async(dev
, SR_CMD_WRITE_MULTI_FILTER
, 0, 0,
328 SR_MCAST_FILTER_SIZE
, data
->multi_filter
);
330 rx_ctl
|= SR_RX_CTL_AM
;
333 sr_write_cmd_async(dev
, SR_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
336 static int sr_mdio_read(struct net_device
*net
, int phy_id
, int loc
)
338 struct usbnet
*dev
= netdev_priv(net
);
341 mutex_lock(&dev
->phy_mutex
);
343 sr_read_cmd(dev
, SR_CMD_READ_MII_REG
, phy_id
, (__u16
)loc
, 2, &res
);
345 mutex_unlock(&dev
->phy_mutex
);
348 "%s : phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", __func__
,
349 phy_id
, loc
, le16_to_cpu(res
));
351 return le16_to_cpu(res
);
355 sr_mdio_write(struct net_device
*net
, int phy_id
, int loc
, int val
)
357 struct usbnet
*dev
= netdev_priv(net
);
358 __le16 res
= cpu_to_le16(val
);
361 "%s : phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", __func__
,
363 mutex_lock(&dev
->phy_mutex
);
365 sr_write_cmd(dev
, SR_CMD_WRITE_MII_REG
, phy_id
, (__u16
)loc
, 2, &res
);
367 mutex_unlock(&dev
->phy_mutex
);
370 /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
371 static u32
sr_get_phyid(struct usbnet
*dev
)
377 /* Poll for the rare case the FW or phy isn't ready yet. */
378 for (i
= 0; i
< 100; i
++) {
379 phy_reg
= sr_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID1
);
380 if (phy_reg
!= 0 && phy_reg
!= 0xFFFF)
385 if (phy_reg
<= 0 || phy_reg
== 0xFFFF)
388 phy_id
= (phy_reg
& 0xffff) << 16;
390 phy_reg
= sr_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID2
);
394 phy_id
|= (phy_reg
& 0xffff);
400 sr_get_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
402 struct usbnet
*dev
= netdev_priv(net
);
405 if (sr_read_cmd(dev
, SR_CMD_READ_MONITOR_MODE
, 0, 0, 1, &opt
) < 0) {
406 wolinfo
->supported
= 0;
407 wolinfo
->wolopts
= 0;
410 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
;
411 wolinfo
->wolopts
= 0;
412 if (opt
& SR_MONITOR_LINK
)
413 wolinfo
->wolopts
|= WAKE_PHY
;
414 if (opt
& SR_MONITOR_MAGIC
)
415 wolinfo
->wolopts
|= WAKE_MAGIC
;
419 sr_set_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
421 struct usbnet
*dev
= netdev_priv(net
);
424 if (wolinfo
->wolopts
& WAKE_PHY
)
425 opt
|= SR_MONITOR_LINK
;
426 if (wolinfo
->wolopts
& WAKE_MAGIC
)
427 opt
|= SR_MONITOR_MAGIC
;
429 if (sr_write_cmd(dev
, SR_CMD_WRITE_MONITOR_MODE
,
430 opt
, 0, 0, NULL
) < 0)
436 static int sr_get_eeprom_len(struct net_device
*net
)
438 struct usbnet
*dev
= netdev_priv(net
);
439 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
441 return data
->eeprom_len
;
444 static int sr_get_eeprom(struct net_device
*net
,
445 struct ethtool_eeprom
*eeprom
, u8
*data
)
447 struct usbnet
*dev
= netdev_priv(net
);
448 __le16
*ebuf
= (__le16
*)data
;
452 /* Crude hack to ensure that we don't overwrite memory
453 * if an odd length is supplied
458 eeprom
->magic
= SR_EEPROM_MAGIC
;
460 /* sr9800 returns 2 bytes from eeprom on read */
461 for (i
= 0; i
< eeprom
->len
/ 2; i
++) {
462 ret
= sr_read_cmd(dev
, SR_CMD_READ_EEPROM
, eeprom
->offset
+ i
,
470 static void sr_get_drvinfo(struct net_device
*net
,
471 struct ethtool_drvinfo
*info
)
473 struct usbnet
*dev
= netdev_priv(net
);
474 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
476 /* Inherit standard device info */
477 usbnet_get_drvinfo(net
, info
);
478 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
));
479 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
480 info
->eedump_len
= data
->eeprom_len
;
483 static u32
sr_get_link(struct net_device
*net
)
485 struct usbnet
*dev
= netdev_priv(net
);
487 return mii_link_ok(&dev
->mii
);
490 static int sr_ioctl(struct net_device
*net
, struct ifreq
*rq
, int cmd
)
492 struct usbnet
*dev
= netdev_priv(net
);
494 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
497 static int sr_set_mac_address(struct net_device
*net
, void *p
)
499 struct usbnet
*dev
= netdev_priv(net
);
500 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
501 struct sockaddr
*addr
= p
;
503 if (netif_running(net
))
505 if (!is_valid_ether_addr(addr
->sa_data
))
506 return -EADDRNOTAVAIL
;
508 memcpy(net
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
510 /* We use the 20 byte dev->data
511 * for our 6 byte mac buffer
512 * to avoid allocating memory that
513 * is tricky to free later
515 memcpy(data
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
516 sr_write_cmd_async(dev
, SR_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
522 static const struct ethtool_ops sr9800_ethtool_ops
= {
523 .get_drvinfo
= sr_get_drvinfo
,
524 .get_link
= sr_get_link
,
525 .get_msglevel
= usbnet_get_msglevel
,
526 .set_msglevel
= usbnet_set_msglevel
,
527 .get_wol
= sr_get_wol
,
528 .set_wol
= sr_set_wol
,
529 .get_eeprom_len
= sr_get_eeprom_len
,
530 .get_eeprom
= sr_get_eeprom
,
531 .get_settings
= usbnet_get_settings
,
532 .set_settings
= usbnet_set_settings
,
533 .nway_reset
= usbnet_nway_reset
,
536 static int sr9800_link_reset(struct usbnet
*dev
)
538 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
541 mii_check_media(&dev
->mii
, 1, 1);
542 mii_ethtool_gset(&dev
->mii
, &ecmd
);
543 mode
= SR9800_MEDIUM_DEFAULT
;
545 if (ethtool_cmd_speed(&ecmd
) != SPEED_100
)
546 mode
&= ~SR_MEDIUM_PS
;
548 if (ecmd
.duplex
!= DUPLEX_FULL
)
549 mode
&= ~SR_MEDIUM_FD
;
551 netdev_dbg(dev
->net
, "%s : speed: %u duplex: %d mode: 0x%04x\n",
552 __func__
, ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
554 sr_write_medium_mode(dev
, mode
);
560 static int sr9800_set_default_mode(struct usbnet
*dev
)
565 sr_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
566 sr_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
567 ADVERTISE_ALL
| ADVERTISE_CSMA
);
568 mii_nway_restart(&dev
->mii
);
570 ret
= sr_write_medium_mode(dev
, SR9800_MEDIUM_DEFAULT
);
574 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_IPG012
,
575 SR9800_IPG0_DEFAULT
| SR9800_IPG1_DEFAULT
,
576 SR9800_IPG2_DEFAULT
, 0, NULL
);
578 netdev_dbg(dev
->net
, "Write IPG,IPG1,IPG2 failed: %d\n", ret
);
582 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
583 ret
= sr_write_rx_ctl(dev
, SR_DEFAULT_RX_CTL
);
587 rx_ctl
= sr_read_rx_ctl(dev
);
588 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after all initializations\n",
591 rx_ctl
= sr_read_medium_status(dev
);
592 netdev_dbg(dev
->net
, "Medium Status:0x%04x after all initializations\n",
600 static int sr9800_reset(struct usbnet
*dev
)
602 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
606 ret
= sr_write_gpio(dev
,
607 SR_GPIO_RSE
| SR_GPIO_GPO_2
| SR_GPIO_GPO2EN
, 5);
611 embd_phy
= ((sr_get_phy_addr(dev
) & 0x1f) == 0x10 ? 1 : 0);
613 ret
= sr_write_cmd(dev
, SR_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
615 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
619 ret
= sr_sw_reset(dev
, SR_SWRESET_IPPD
| SR_SWRESET_PRL
);
625 ret
= sr_sw_reset(dev
, SR_SWRESET_CLEAR
);
632 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
636 ret
= sr_sw_reset(dev
, SR_SWRESET_PRTE
);
642 rx_ctl
= sr_read_rx_ctl(dev
);
643 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after software reset\n", rx_ctl
);
644 ret
= sr_write_rx_ctl(dev
, 0x0000);
648 rx_ctl
= sr_read_rx_ctl(dev
);
649 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl
);
651 ret
= sr_sw_reset(dev
, SR_SWRESET_PRL
);
657 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
| SR_SWRESET_PRL
);
663 ret
= sr9800_set_default_mode(dev
);
667 /* Rewrite MAC address */
668 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
669 ret
= sr_write_cmd(dev
, SR_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
680 static const struct net_device_ops sr9800_netdev_ops
= {
681 .ndo_open
= usbnet_open
,
682 .ndo_stop
= usbnet_stop
,
683 .ndo_start_xmit
= usbnet_start_xmit
,
684 .ndo_tx_timeout
= usbnet_tx_timeout
,
685 .ndo_change_mtu
= usbnet_change_mtu
,
686 .ndo_set_mac_address
= sr_set_mac_address
,
687 .ndo_validate_addr
= eth_validate_addr
,
688 .ndo_do_ioctl
= sr_ioctl
,
689 .ndo_set_rx_mode
= sr_set_multicast
,
692 static int sr9800_phy_powerup(struct usbnet
*dev
)
696 /* set the embedded Ethernet PHY in power-down state */
697 ret
= sr_sw_reset(dev
, SR_SWRESET_IPPD
| SR_SWRESET_IPRL
);
699 netdev_err(dev
->net
, "Failed to power down PHY : %d\n", ret
);
704 /* set the embedded Ethernet PHY in power-up state */
705 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
707 netdev_err(dev
->net
, "Failed to reset PHY: %d\n", ret
);
712 /* set the embedded Ethernet PHY in reset state */
713 ret
= sr_sw_reset(dev
, SR_SWRESET_CLEAR
);
715 netdev_err(dev
->net
, "Failed to power up PHY: %d\n", ret
);
720 /* set the embedded Ethernet PHY in power-up state */
721 ret
= sr_sw_reset(dev
, SR_SWRESET_IPRL
);
723 netdev_err(dev
->net
, "Failed to reset PHY: %d\n", ret
);
730 static int sr9800_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
732 struct sr_data
*data
= (struct sr_data
*)&dev
->data
;
733 u16 led01_mux
, led23_mux
;
738 data
->eeprom_len
= SR9800_EEPROM_LEN
;
740 usbnet_get_endpoints(dev
, intf
);
742 /* LED Setting Rule :
746 * CC : MFA2(LED2), Reserved for SR9800
747 * DD : MFA3(LED3), Reserved for SR9800
749 led01_mux
= (SR_LED_MUX_LINK_ACTIVE
<< 8) | SR_LED_MUX_LINK
;
750 led23_mux
= (SR_LED_MUX_LINK_ACTIVE
<< 8) | SR_LED_MUX_TX_ACTIVE
;
751 ret
= sr_write_cmd(dev
, SR_CMD_LED_MUX
, led01_mux
, led23_mux
, 0, NULL
);
753 netdev_err(dev
->net
, "set LINK LED failed : %d\n", ret
);
757 /* Get the MAC address */
758 ret
= sr_read_cmd(dev
, SR_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
,
761 netdev_dbg(dev
->net
, "Failed to read MAC address: %d\n", ret
);
764 netdev_dbg(dev
->net
, "mac addr : %pM\n", dev
->net
->dev_addr
);
766 /* Initialize MII structure */
767 dev
->mii
.dev
= dev
->net
;
768 dev
->mii
.mdio_read
= sr_mdio_read
;
769 dev
->mii
.mdio_write
= sr_mdio_write
;
770 dev
->mii
.phy_id_mask
= 0x1f;
771 dev
->mii
.reg_num_mask
= 0x1f;
772 dev
->mii
.phy_id
= sr_get_phy_addr(dev
);
774 dev
->net
->netdev_ops
= &sr9800_netdev_ops
;
775 dev
->net
->ethtool_ops
= &sr9800_ethtool_ops
;
777 embd_phy
= ((dev
->mii
.phy_id
& 0x1f) == 0x10 ? 1 : 0);
778 /* Reset the PHY to normal operation mode */
779 ret
= sr_write_cmd(dev
, SR_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
781 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
785 /* Init PHY routine */
786 ret
= sr9800_phy_powerup(dev
);
790 rx_ctl
= sr_read_rx_ctl(dev
);
791 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after software reset\n", rx_ctl
);
792 ret
= sr_write_rx_ctl(dev
, 0x0000);
796 rx_ctl
= sr_read_rx_ctl(dev
);
797 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl
);
799 /* Read PHYID register *AFTER* the PHY was reset properly */
800 phyid
= sr_get_phyid(dev
);
801 netdev_dbg(dev
->net
, "PHYID=0x%08x\n", phyid
);
803 /* medium mode setting */
804 ret
= sr9800_set_default_mode(dev
);
808 if (dev
->udev
->speed
== USB_SPEED_HIGH
) {
809 ret
= sr_write_cmd(dev
, SR_CMD_BULKIN_SIZE
,
810 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].byte_cnt
,
811 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].threshold
,
814 netdev_err(dev
->net
, "Reset RX_CTL failed: %d\n", ret
);
818 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_4K
].size
;
820 ret
= sr_write_cmd(dev
, SR_CMD_BULKIN_SIZE
,
821 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].byte_cnt
,
822 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].threshold
,
825 netdev_err(dev
->net
, "Reset RX_CTL failed: %d\n", ret
);
829 SR9800_BULKIN_SIZE
[SR9800_MAX_BULKIN_2K
].size
;
831 netdev_dbg(dev
->net
, "%s : setting rx_urb_size with : %zu\n", __func__
,
839 static const struct driver_info sr9800_driver_info
= {
840 .description
= "CoreChip SR9800 USB 2.0 Ethernet",
843 .link_reset
= sr9800_link_reset
,
844 .reset
= sr9800_reset
,
845 .flags
= DRIVER_FLAG
,
846 .rx_fixup
= sr_rx_fixup
,
847 .tx_fixup
= sr_tx_fixup
,
850 static const struct usb_device_id products
[] = {
852 USB_DEVICE(0x0fe6, 0x9800), /* SR9800 Device */
853 .driver_info
= (unsigned long) &sr9800_driver_info
,
858 MODULE_DEVICE_TABLE(usb
, products
);
860 static struct usb_driver sr_driver
= {
862 .id_table
= products
,
863 .probe
= usbnet_probe
,
864 .suspend
= usbnet_suspend
,
865 .resume
= usbnet_resume
,
866 .disconnect
= usbnet_disconnect
,
867 .supports_autosuspend
= 1,
870 module_usb_driver(sr_driver
);
872 MODULE_AUTHOR("Liu Junliang <liujunliang_ljl@163.com");
873 MODULE_VERSION(DRIVER_VERSION
);
874 MODULE_DESCRIPTION("SR9800 USB 2.0 USB2NET Dev : http://www.corechip-sz.com");
875 MODULE_LICENSE("GPL");