Re: [PATCH 1/1] net: add dm9620 net usb driver
Joseph == Joseph Chang joseph_ch...@davicom.com.tw writes: Hi, Joseph This is Joseph CHANG, I am glade to contact and work with Joseph you. I am busy in some affairs else these days, and will Joseph like to be back soon. Joseph For the begin, We copy the source code 'dm9601.c' which was Joseph by you, In order to work for our new chips (DM9620, DM9621, Joseph DM9621A... series), We did modify to get 'dm9620.c' base on Joseph 'dm0601.c', Since you are the author and also the owner, so Joseph keep MODULE_AUTHOR() as you. Yes, that's what I learned from a number of bug reports. It would have been good if you would have worked with me to get your modifications integrated instead. Joseph To generate DM9620.c is a way to distinguish the different Joseph generation chips: (as below) JosephDM9601: old revision: USB1.1, Ethernet 10/100, Phase out JosephDM9620: current revision: USB2.0, Ethernet 10/100, Mass production state JosephDM9633: next revision: USB3.0, Ethernet 10/100/1000, Will to Joseph release on 2013/E dm9620 is basically backwards compatible with dm9601, so I added dm9620 support to the dm9601 driver earlier this year: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6642f91c92da0736 Is there anything missing from that? I don't see any dm9633 datasheet on the davicom website, so I cannot say if it makes sense to add support for it in the existing driver. Is the datasheet available somewhere? Joseph So want to make it from the configuration by make Joseph menuconfig. Joseph Can you help give further advices, we hope you can go ahead Joseph be the owner (author) of the 'dm9620.c', And then we make patch Joseph to it. Would you agree this idea? If so we will be happy Joseph because we did not ever create such a code. Joseph * Think about DM9633 driver to be, It will be is total Joseph different compare to DM9601 DM9620. And will get the same Joseph issue. If you can provide me with a dm9633 datasheet and a sample device then I can look into writing a driver for it / extending dm9601.c. Please contact me off list for that. Thanks! -- Bye, Peter Korsgaard -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 1/1] net: add dm9620 net usb driver
Dear Peter, This is Joseph CHANG, I am glade to contact and work with you. I am busy in some affairs else these days, and will like to be back soon. For the begin, We copy the source code 'dm9601.c' which was by you, In order to work for our new chips (DM9620, DM9621, DM9621A... series), We did modify to get 'dm9620.c' base on 'dm0601.c', Since you are the author and also the owner, so keep MODULE_AUTHOR() as you. To generate DM9620.c is a way to distinguish the different generation chips: (as below) DM9601: old revision: USB1.1, Ethernet 10/100, Phase out DM9620: current revision: USB2.0, Ethernet 10/100, Mass production state DM9633: next revision:USB3.0, Ethernet 10/100/1000, Will to release on 2013/E So want to make it from the configuration by make menuconfig. Can you help give further advices, we hope you can go ahead be the owner (author) of the 'dm9620.c', And then we make patch to it. Would you agree this idea? If so we will be happy because we did not ever create such a code. * Think about DM9633 driver to be, It will be is total different compare to DM9601 DM9620. And will get the same issue. ThankYou and Best Regards, Joseph CHANG System Application Engineering Division Davicom Semiconductor, Inc. No. 6 Li-Hsin Rd. VI, Science-Based Park, Hsin-Chu, Taiwan. Tel: 886-3-5798797 Ex 8534 Fax: 886-3-5646929 Web: http://www.davicom.com.tw -Original Message- From: Peter Korsgaard [mailto:jac...@gmail.com] On Behalf Of Peter Korsgaard Sent: Monday, June 24, 2013 4:01 AM To: Joseph CHANG Cc: Greg Kroah-Hartman; linux-ker...@vger.kernel.org; linux-usb@vger.kernel.org; net...@vger.kernel.org; joseph_ch...@davicom.com.tw; josri...@hotmail.com Subject: Re: [PATCH 1/1] net: add dm9620 net usb driver Joseph == Joseph CHANG josright...@gmail.com writes: Joseph DM9620 is an USB2.0 network adapter rather than DM9601 USB1.1. This Joseph driver processed the RX data 4 bytes header, TX data 2 bytes header, Joseph make the control bit exactly right in PHY write function, and optional Joseph IFF_ALLMUTLI bit for RX control. But dm9601.c already supports the dm9620 based devices. Why another driver for the same hardware? Please CC me on dm9601 related patches. Joseph Tested good for many platforms, include X86 desktop and ARM embedded. Joseph +static struct usb_driver dm9620_driver = { Joseph + .name = dm9620, Joseph + .id_table = products, Joseph + .probe = usbnet_probe, Joseph + .disconnect = usbnet_disconnect, Joseph + .suspend = usbnet_suspend, Joseph + .resume = usbnet_resume, Joseph + .disable_hub_initiated_lpm = 1, Joseph +}; Joseph + Joseph +module_usb_driver(dm9620_driver); Joseph + Joseph +MODULE_AUTHOR(Peter Korsgaard jac...@sunsite.dk); I'm not the author of this file. -- Bye, Peter Korsgaard -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/1] net: add dm9620 net usb driver
Joseph == Joseph CHANG josright...@gmail.com writes: Joseph DM9620 is an USB2.0 network adapter rather than DM9601 USB1.1. This Joseph driver processed the RX data 4 bytes header, TX data 2 bytes header, Joseph make the control bit exactly right in PHY write function, and optional Joseph IFF_ALLMUTLI bit for RX control. But dm9601.c already supports the dm9620 based devices. Why another driver for the same hardware? Please CC me on dm9601 related patches. Joseph Tested good for many platforms, include X86 desktop and ARM embedded. Joseph +static struct usb_driver dm9620_driver = { Joseph + .name = dm9620, Joseph + .id_table = products, Joseph + .probe = usbnet_probe, Joseph + .disconnect = usbnet_disconnect, Joseph + .suspend = usbnet_suspend, Joseph + .resume = usbnet_resume, Joseph + .disable_hub_initiated_lpm = 1, Joseph +}; Joseph + Joseph +module_usb_driver(dm9620_driver); Joseph + Joseph +MODULE_AUTHOR(Peter Korsgaard jac...@sunsite.dk); I'm not the author of this file. -- Bye, Peter Korsgaard -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/1] net: add dm9620 net usb driver
DM9620 is an USB2.0 network adapter rather than DM9601 USB1.1. This driver processed the RX data 4 bytes header, TX data 2 bytes header, make the control bit exactly right in PHY write function, and optional IFF_ALLMUTLI bit for RX control. Tested good for many platforms, include X86 desktop and ARM embedded. Signed-off-by: Joseph CHANG josright...@gmail.com --- drivers/net/usb/Kconfig | 13 + drivers/net/usb/Makefile |1 + drivers/net/usb/dm9620.c | 796 ++ 3 files changed, 810 insertions(+), 0 deletions(-) create mode 100644 drivers/net/usb/dm9620.c diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index 287cc62..e9c9e2a 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -272,6 +272,19 @@ config USB_NET_DM9601 This option adds support for Davicom DM9601 based USB 1.1 10/100 Ethernet adapters. +config USB_NET_DM9620 + tristate Davicom DM9620/21 based USB 2.0 10/100 ethernet devices + depends on USB_USBNET + select CRC32 + help + This option adds support for Davicom DM9620 based USB 2.0 + 10/100 Ethernet adapters. + + This driver creates an interface named ethX, where X depends on + what other networking devices you have in use. + + To compile this driver as a module, choose M here. + config USB_NET_SMSC75XX tristate SMSC LAN75XX based USB 2.0 gigabit ethernet devices depends on USB_USBNET diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile index 9ab5c9d..7d95e5c 100644 --- a/drivers/net/usb/Makefile +++ b/drivers/net/usb/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o obj-$(CONFIG_USB_NET_DM9601) += dm9601.o +obj-$(CONFIG_USB_NET_DM9620) += dm9620.o obj-$(CONFIG_USB_NET_SMSC75XX) += smsc75xx.o obj-$(CONFIG_USB_NET_SMSC95XX) += smsc95xx.o obj-$(CONFIG_USB_NET_GL620A) += gl620a.o diff --git a/drivers/net/usb/dm9620.c b/drivers/net/usb/dm9620.c new file mode 100644 index 000..aa4226b --- /dev/null +++ b/drivers/net/usb/dm9620.c @@ -0,0 +1,796 @@ +/* + * Davicom DM9620 USB 2.0 10/100Mbps ethernet devices + * + * Peter Korsgaard jac...@sunsite.dk + * + * This file is licensed under the terms of the GNU General Public License + * version 2. This program is licensed as is without any warranty of any + * kind, whether express or implied. + */ + +/* #define DEBUG */ + +#include linux/module.h +#include linux/sched.h +#include linux/stddef.h +#include linux/init.h +#include linux/netdevice.h +#include linux/etherdevice.h +#include linux/ethtool.h +#include linux/mii.h +#include linux/usb.h +#include linux/crc32.h +#include linux/usb/usbnet.h +#include linux/slab.h + +/* control requests */ +#define DM_READ_REGS 0x00 +#define DM_WRITE_REGS 0x01 +#define DM_READ_MEMS 0x02 +#define DM_WRITE_REG 0x03 +#define DM_WRITE_MEMS 0x05 +#define DM_WRITE_MEM 0x07 + +/* registers */ +#define DM_NET_CTRL0x00 +#define DM_RX_CTRL 0x05 +#define DM_FCR 0x0a +#define DM_SHARED_CTRL 0x0b +#define DM_SHARED_ADDR 0x0c +#define DM_SHARED_DATA 0x0d/* low + high */ +#define DM_SHARED_DL 0x0d +#define DM_SHARED_DH 0x0e +#define DM_WAKEUP_CTRL 0x0f +#define DM_PHY_ADDR0x10/* 6 bytes */ +#define DM_MCAST_ADDR 0x16/* 8 bytes */ +#define DM_GPR_CTRL0x1e +#define DM_GPR_DATA0x1f +#define DM_PID 0x2a +#define DM_CHIP_ID 0x2c +#define DM_XPHY_CTRL 0x2e/* reserved */ +#define DM_TX_CRC_CTRL 0x31 +#define DM_RX_CRC_CTRL 0x32 +#define DM_AZR 0x3f/* reserved */ +#define DM_USB_CTRL0xf4 +#define DM_MODE_CTRL 0x91/* only on dm9620 */ +#define DM_CHIP_ID_EX 0x5C + +#define MD96XX_EEPROM_MAGIC0x9620 +#define DM_MAX_MCAST 64 +#define DM_MCAST_SIZE 8 +#define DM_EEPROM_LEN 256 +#define DM_TX_OVERHEAD 2 /* 2 byte header */ +#define DM_RX_OVERHEAD 8 /* 4 byte header + 4 byte crc tail */ +#define DM_TIMEOUT 1000 + +#define DM_NCR_RST (10) +#define DM_NCR_WAKEEN (16) + +#define DM_FCR_TXPEN (15) +#define DM_FCR_BKPM(13) +#define DM_FCR_FLCE(10) + +#define DMSC_WEP (14) +#define DMSC_ERPRW (11) +#define DMSC_ERRE (10) + +#define DM_LINKEN (15) +#define DM_MAGICEN (13) + +#define DM_TX_UDPCSE (12) +#define DM_TX_TCPCSE (11) +#define DM_TX_IPCSE(10) +#define DM_RX_RCSEN(11) +#define DM_MODE_DM_TXRX(04) +#define DM_MODE_CDC_TRX(14) +#define DM_MODE_DM_DESC(05) +#define DM_MODE_CDC_DES(15) + +#define DM_USB_EP3ACK (15) + +#define DM_MODE9601(07) +#define DM_MODE9620(17) +#define DM9620_PHY_ID 1 /* Stone add For kernel read phy register */ + +#define VID_DAVICOM0x0a46 + +#define PID_DM9620 0x9620 +#define PID_DM9621 0x9621 +#define PID_DM9622 0x9622 +#define PID_DM9620A0x0269 +#define
[PATCH 1/1] net: add dm9620 net usb driver
DM9620 is an USB2.0 network adapter rather than DM9601 USB1.1. This driver processed the RX data with 4 bytes header, TX 2 bytes header, make the control bit exactly right in PHY write operation, and optional IFF_ALLMULTI bit for RX control. Tested good for many platforms, include X86 desktop and ARM embedded. Signed-off-by: Joseph CHANG josright...@gmail.com --- drivers/net/usb/Kconfig | 13 + drivers/net/usb/Makefile |1 + drivers/net/usb/dm9620.c | 798 ++ 3 files changed, 812 insertions(+), 0 deletions(-) create mode 100644 drivers/net/usb/dm9620.c diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index 287cc62..e9c9e2a 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -272,6 +272,19 @@ config USB_NET_DM9601 This option adds support for Davicom DM9601 based USB 1.1 10/100 Ethernet adapters. +config USB_NET_DM9620 + tristate Davicom DM9620/21 based USB 2.0 10/100 ethernet devices + depends on USB_USBNET + select CRC32 + help + This option adds support for Davicom DM9620 based USB 2.0 + 10/100 Ethernet adapters. + + This driver creates an interface named ethX, where X depends on + what other networking devices you have in use. + + To compile this driver as a module, choose M here. + config USB_NET_SMSC75XX tristate SMSC LAN75XX based USB 2.0 gigabit ethernet devices depends on USB_USBNET diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile index 9ab5c9d..7d95e5c 100644 --- a/drivers/net/usb/Makefile +++ b/drivers/net/usb/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o obj-$(CONFIG_USB_NET_DM9601) += dm9601.o +obj-$(CONFIG_USB_NET_DM9620) += dm9620.o obj-$(CONFIG_USB_NET_SMSC75XX) += smsc75xx.o obj-$(CONFIG_USB_NET_SMSC95XX) += smsc95xx.o obj-$(CONFIG_USB_NET_GL620A) += gl620a.o diff --git a/drivers/net/usb/dm9620.c b/drivers/net/usb/dm9620.c new file mode 100644 index 000..33ea9ac --- /dev/null +++ b/drivers/net/usb/dm9620.c @@ -0,0 +1,798 @@ +/* + * Davicom DM9620 USB 2.0 10/100Mbps ethernet devices + * + * Peter Korsgaard jac...@sunsite.dk + * + * This file is licensed under the terms of the GNU General Public License + * version 2. This program is licensed as is without any warranty of any + * kind, whether express or implied. + */ + +/* #define DEBUG */ + +#include linux/module.h +#include linux/sched.h +#include linux/stddef.h +#include linux/init.h +#include linux/netdevice.h +#include linux/etherdevice.h +#include linux/ethtool.h +#include linux/mii.h +#include linux/usb.h +#include linux/crc32.h +#include linux/usb/usbnet.h +#include linux/slab.h + +/* control requests */ +#define DM_READ_REGS 0x00 +#define DM_WRITE_REGS 0x01 +#define DM_READ_MEMS 0x02 +#define DM_WRITE_REG 0x03 +#define DM_WRITE_MEMS 0x05 +#define DM_WRITE_MEM 0x07 + +/* registers */ +#define DM_NET_CTRL0x00 +#define DM_RX_CTRL 0x05 +#define DM_FCR 0x0a +#define DM_SHARED_CTRL 0x0b +#define DM_SHARED_ADDR 0x0c +#define DM_SHARED_DATA 0x0d/* low + high */ +#define DM_SHARED_DL 0x0d +#define DM_SHARED_DH 0x0e +#define DM_WAKEUP_CTRL 0x0f +#define DM_PHY_ADDR0x10/* 6 bytes */ +#define DM_MCAST_ADDR 0x16/* 8 bytes */ +#define DM_GPR_CTRL0x1e +#define DM_GPR_DATA0x1f +#define DM_PID 0x2a +#define DM_CHIP_ID 0x2c +#define DM_XPHY_CTRL 0x2e/* reserved */ +#define DM_TX_CRC_CTRL 0x31 +#define DM_RX_CRC_CTRL 0x32 +#define DM_AZR 0x3f/* reserved */ +#define DM_USB_CTRL0xf4 +#define DM_MODE_CTRL 0x91/* only on dm9620 */ +#define DM_CHIP_ID_EX 0x5C + +#define MD96XX_EEPROM_MAGIC0x9620 +#define DM_MAX_MCAST 64 +#define DM_MCAST_SIZE 8 +#define DM_EEPROM_LEN 256 +#define DM_TX_OVERHEAD 2 /* 2 byte header */ +#define DM_RX_OVERHEAD 8 /* 4 byte header + 4 byte crc tail */ +#define DM_TIMEOUT 1000 + +#define DM_NCR_RST (10) +#define DM_NCR_WAKEEN (16) + +#define DM_FCR_TXPEN (15) +#define DM_FCR_BKPM(13) +#define DM_FCR_FLCE(10) + +#define DMSC_WEP (14) +#define DMSC_ERPRW (11) +#define DMSC_ERRE (10) + +#define DM_LINKEN (15) +#define DM_MAGICEN (13) + +#define DM_TX_UDPCSE (12) +#define DM_TX_TCPCSE (11) +#define DM_TX_IPCSE(10) +#define DM_RX_RCSEN(11) +#define DM_MODE_DM_TXRX(04) +#define DM_MODE_CDC_TRX(14) +#define DM_MODE_DM_DESC(05) +#define DM_MODE_CDC_DES(15) + +#define DM_USB_EP3ACK (15) + +#define DM_MODE9601(07) +#define DM_MODE9620(17) +#define DM9620_PHY_ID 1 /* Stone add For kernel read phy register */ + +static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) +{ + int err; + err = usbnet_read_cmd(dev, DM_READ_REGS, +
Re: [PATCH 1/1] net: add dm9620 net usb driver
Hi Joseph, had a fast look... [ ... ] +static int dm9620_set_eeprom(struct net_device *net, + struct ethtool_eeprom *eeprom, u8 *data) +{ + struct usbnet *dev = netdev_priv(net); + int offset = eeprom-offset; + int len = eeprom-len; + int done; + + if (eeprom-magic != MD96XX_EEPROM_MAGIC) { + netdev_err(dev-net, EEPROM: magic value mismatch, magic = 0x%x\n, + eeprom-magic); + return -EINVAL; + } + + while (len 0) { + if (len 1 || offset 1) { + int which = offset 1; + u8 tmp[2]; + dm_read_eeprom_word(dev, offset / 2, tmp); + tmp[which] = *data; + dm_write_eeprom_word(dev, offset / 2, tmp); + mdelay(10); Please don't use mdelay, use msleep or possibly msleep_interruptable + done = 1; + } else { + dm_write_eeprom_word(dev, offset / 2, data); + done = 2; + } + data += done; + offset += done; + len -= done; + } + return 0; +} [ ... ] +static int dm9620_bind(struct usbnet *dev, struct usb_interface *intf) +{ + int ret; + u8 mac[ETH_ALEN], id; + u16 value; + + ret = usbnet_get_endpoints(dev, intf); + if (ret) + goto out; maybe here is better if (ret) return ret; + + dev-net-netdev_ops = dm9620_netdev_ops; + dev-net-ethtool_ops = dm9620_ethtool_ops; + dev-net-hard_header_len += DM_TX_OVERHEAD; + dev-hard_mtu = dev-net-mtu + dev-net-hard_header_len; + + /* ftp fail fixed */ + dev-rx_urb_size = dev-net-mtu + ETH_HLEN + DM_RX_OVERHEAD+1; + + dev-mii.dev = dev-net; + dev-mii.mdio_read = dm9620_mdio_read; + dev-mii.mdio_write = dm9620_mdio_write; + dev-mii.phy_id_mask = 0x1f; + dev-mii.reg_num_mask = 0x1f; + dev-mii.phy_id = DM9620_PHY_ID; + + /* reset */ + dm_write_reg(dev, DM_NET_CTRL, 1); + udelay(20); from Documentation/timers/timers-howto.txt: SLEEPING FOR A FEW USECS ( ~10us? ): * Use udelay use udelay if you want to sleep for less than 10us, otherwise use usleep_range + + /* read MAC */ + if (dm_read(dev, DM_PHY_ADDR, ETH_ALEN, mac) 0) { + netdev_err(dev-net, Error reading MAC address\n); + ret = -ENODEV; + goto out; + } you can get read of the 'out' label if in all the goto you use you just 'return -ENODEV;' instead of 'goto out;' + + /* Overwrite the auto-generated address only with good ones */ + if (is_valid_ether_addr(mac)) + memcpy(dev-net-dev_addr, mac, ETH_ALEN); + else { + netdev_warn(dev-net, + dm9620: No valid MAC address in EEPROM, using %pM\n, + dev-net-dev_addr); + __dm9620_set_mac_address(dev); + } + + if (dm_read_reg(dev, DM_CHIP_ID, id) 0) { + netdev_err(dev-net, Error reading chip ID\n); + ret = -ENODEV; + goto out; same here + } + + dm_read(dev, DM_PID, 2, value); + + /* Add for check Product dm9620a/21a */ + if (value == 0x1269 || value == 0x0269) + dm_write_reg(dev, DM_MODE_CTRL, DM_MODE9620 | DM_MODE_CDC_DES); + else + dm_write_reg(dev, DM_MODE_CTRL, DM_MODE9620); + + dm_write_reg(dev, DM_RX_CRC_CTRL, DM_RX_RCSEN); + + /* power up phy */ + dm_write_reg(dev, DM_GPR_CTRL, 1); + dm_write_reg(dev, DM_GPR_DATA, 0); + + /* receive broadcast packets */ + dm9620_set_multicast(dev-net); + + dm9620_mdio_write(dev-net, dev-mii.phy_id, MII_BMCR, BMCR_RESET); + + /* TX Pause Packet Enable */ + dm_write_reg(dev, DM_FCR, DM_FCR_TXPEN | DM_FCR_BKPM | DM_FCR_FLCE); + + /* ADVERTISE_PAUSE_CAP */ + dm9620_mdio_write(dev-net, dev-mii.phy_id, MII_ADVERTISE, + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); + + dm_write_reg(dev, DM_USB_CTRL, DM_USB_EP3ACK); + + mii_nway_restart(dev-mii); + +out: + return ret; yeah... you wouldn't need this anymore +} + +void dm9620_unbind(struct usbnet *dev, struct usb_interface *intf) Should this be static? +{ + netdev_warn(dev-net, [dm962] Linux Driver = V2.6 - unbind\n); +} + +static int dm9620_rx_fixup(struct usbnet *dev, struct sk_buff *skb) +{ + u8 status; + int len; + + /* format: +b0: rx_flag +b1: rx status +b2: packet length (incl crc) low +b3: packet length (incl crc) high +b4..n-4: packet data +bn-3..bn: ethernet crc + */ Allow me this nitpick please check the coding style for comments in Documentation/CodyngStyle: For files in net/ and drivers/net/ the preferred