Re: [U-Boot] [PATCH v2 2/2] usb: eth: add Realtek RTL8152B/RTL8153 driver
Hi Ted, On Tue, Nov 24, 2015 at 11:30 PM, Ted Chen wrote: > From: Ted Chen > > This patch adds driver support for the Realtek RTL8152B/RTL8153 USB > network adapters. > > Signed-off-by: Ted Chen > [swarren, fixed a few compiler warnings] > [swarren, with permission, converted license header to SPDX] > [swarren, removed printf() spew during probe()] > Signed-off-by: Stephen Warren > > Changes for v2: Modified by Marek's comments. > - Remove pattern informations. > - Don't allocate & free when read/write register. > - relpace udelay to mdelay. > - pull firmware into global variable. > - code review. > > Signed-off-by: Ted Chen > --- > drivers/usb/eth/Makefile|1 + > drivers/usb/eth/r8152.c | 3099 > +++ > drivers/usb/eth/usb_ether.c |8 + > include/usb_ether.h |6 + > 4 files changed, 3114 insertions(+) > create mode 100644 drivers/usb/eth/r8152.c > > diff --git a/drivers/usb/eth/Makefile b/drivers/usb/eth/Makefile > index c92d2b0..74f5f87 100644 > --- a/drivers/usb/eth/Makefile > +++ b/drivers/usb/eth/Makefile > @@ -9,3 +9,4 @@ obj-$(CONFIG_USB_ETHER_ASIX) += asix.o > obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o > obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o > obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o > +obj-$(CONFIG_USB_ETHER_RTL8152) += r8152.o > diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c > new file mode 100644 > index 000..345f2c3 > --- /dev/null > +++ b/drivers/usb/eth/r8152.c > @@ -0,0 +1,3099 @@ > +/* > + * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved. > + * > + * SPDX-License-Identifier:GPL-2.0 > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "usb_ether.h" > + > +#define DRIVER_VERSION "v1.0 (2015/11/24)" If this is somehow useful to link back to a Realtek release or something, then in belongs in the commit log, not in the code. > + > +#define R8152_PHY_ID 32 > + 8< snip >8 > + > +/* The forced speed, 10Mb, 100Mb, gigabit, [2.5|5|10|20|25|40|50|56|100]GbE. > */ > +#define SPEED_1010 > +#define SPEED_100 100 > +#define SPEED_1000 1000 > +#define SPEED_2500 2500 > +#define SPEED_5000 5000 > +#define SPEED_1 1 > +#define SPEED_2 2 > +#define SPEED_25000 25000 > +#define SPEED_4 4 > +#define SPEED_5 5 > +#define SPEED_56000 56000 > +#define SPEED_1010 Are all the speeds really relevant to define? They aren't used. Maybe lose all the unused ones. > +#define SPEED_UNKNOWN -1 > + > +/* Duplex, half or full. */ > +#define DUPLEX_HALF 0x00 > +#define DUPLEX_FULL 0x01 > +#define DUPLEX_UNKNOWN 0xff > + > +/* Enable or disable autonegotiation. */ > +#define AUTONEG_DISABLE 0x00 > +#define AUTONEG_ENABLE 0x01 > + > + > +/* Generic MII registers. */ > +#define MII_BMCR0x00/* Basic mode control register */ > +#define MII_BMSR0x01/* Basic mode status register */ > +#define MII_PHYSID1 0x02/* PHYS ID 1 */ > +#define MII_PHYSID2 0x03/* PHYS ID 2 */ > +#define MII_ADVERTISE 0x04/* Advertisement control reg */ > +#define MII_LPA 0x05/* Link partner ability reg*/ > +#define MII_EXPANSION 0x06/* Expansion register */ > +#define MII_CTRL10000x09/* 1000BASE-T control */ > +#define MII_STAT10000x0a/* 1000BASE-T status */ > +#define MII_MMD_CTRL0x0d/* MMD Access Control Register */ > +#define MII_MMD_DATA0x0e/* MMD Access Data Register */ > +#define MII_ESTATUS 0x0f/* Extended Status */ > +#define MII_DCOUNTER0x12/* Disconnect counter */ > +#define MII_FCSCOUNTER 0x13/* False carrier counter */ > +#define MII_NWAYTEST0x14/* N-way auto-neg test reg */ > +#define MII_RERRCOUNTER 0x15/* Receive error counter */ > +#define MII_SREVISION 0x16/* Silicon revision*/ > +#define MII_RESV1 0x17/* Reserved... */ > +#define MII_LBRERROR0x18/* Lpback, rx, bypass error*/ > +#define MII_PHYADDR 0x19/* PHY address */ > +#define MII_RESV2 0x1a/* Reserved... */ > +#define MII_TPISTATUS 0x1b/* TPI status for 10mbps */ > +#define MII_NCONFIG 0x1c/* Network interface config*/ > + > +#define agg_buf_sz 2048 > + > +/* local vars */ > +static int curr_eth_dev; /* index for name of next device detec
Re: [U-Boot] [PATCH v2 2/2] usb: eth: add Realtek RTL8152B/RTL8153 driver
On Wednesday, November 25, 2015 at 06:30:54 AM, Ted Chen wrote: > From: Ted Chen > > This patch adds driver support for the Realtek RTL8152B/RTL8153 USB > network adapters. > > Signed-off-by: Ted Chen > [swarren, fixed a few compiler warnings] > [swarren, with permission, converted license header to SPDX] > [swarren, removed printf() spew during probe()] > Signed-off-by: Stephen Warren > > Changes for v2: Modified by Marek's comments. > - Remove pattern informations. > - Don't allocate & free when read/write register. > - relpace udelay to mdelay. > - pull firmware into global variable. > - code review. The changelog should go into the diffstat part, otherwise it will be picked and become part of the commit message. We don't want that. I only have nitpicks below :) > Signed-off-by: Ted Chen > --- > drivers/usb/eth/Makefile|1 + > drivers/usb/eth/r8152.c | 3099 > +++ drivers/usb/eth/usb_ether.c | > 8 + > include/usb_ether.h |6 + > 4 files changed, 3114 insertions(+) > create mode 100644 drivers/usb/eth/r8152.c The changelog should go here. > diff --git a/drivers/usb/eth/Makefile b/drivers/usb/eth/Makefile > index c92d2b0..74f5f87 100644 > --- a/drivers/usb/eth/Makefile > +++ b/drivers/usb/eth/Makefile [...] > +#define DRIVER_VERSION "v1.0 (2015/11/24)" I don't think this is really relevant information. > +#define R8152_PHY_ID 32 [...] > +/* OCP_EEE_CONFIG3 */ > +#define fast_snr_mask0xff80 > +#define fast_snr(x) (min(x, 0x1ff) << 7)/* bit 7 ~ 15 */ Please add parenthesis around the x -- min((x), ... > +#define RG_LFS_SEL 0x0060 /* bit 6 ~ 5 */ > +#define MSK_PH 0x0006 /* bit 0 ~ 3 */ [...] > + > +#define msleep(a)mdelay(a) Please just drop this. > +static u8 r8152b_pla_patch_a[] = { > + 0x08, 0xe0, 0x40, 0xe0, 0x78, 0xe0, 0x85, 0xe0, Please add space after comma to make it consistent. Fix globally. > + 0x5d, 0xe1, 0xa1, 0xe1, 0xa3, 0xe1, 0xab, 0xe1, [...] > +static u16 r8152b_ram_code1[] = { > + 0x9700, 0x7fe0, 0x4c00, 0x4007, 0x4400, 0x4800, 0x7c1f, 0x4c00, Please drop the tab and add space. Fix globally. > + 0x5310, 0x6000, 0x7c07, 0x6800, 0x673e, 0x, 0x, 0x571f, [...] > +static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, > + void *data, u16 type) > +{ > + u16 limit = 64; > + int ret = 0; > + > + /* both size and indix must be 4 bytes align */ > + if ((size & 3) || !size || (index & 3) || !data) > + return -EPERM; > + > + if ((u32)index + (u32)size > 0x) Are the casts here needed ? > + return -EPERM; > + > + while (size) { > + if (size > limit) { > + ret = get_registers(tp, index, type, limit, data); > + if (ret < 0) > + break; > + > + index += limit; > + data += limit; > + size -= limit; > + } else { > + ret = get_registers(tp, index, type, size, data); > + if (ret < 0) > + break; > + > + index += size; > + data += size; > + size = 0; > + break; > + } > + } > + > + return ret; > +} > + > +static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, > + u16 size, void *data, u16 type) > +{ > + int ret; > + u16 byteen_start, byteen_end, byen; > + u16 limit = 512; > + > + /* both size and indix must be 4 bytes align */ > + if ((size & 3) || !size || (index & 3) || !data) > + return -EPERM; > + > + if ((u32)index + (u32)size > 0x) > + return -EPERM; > + > + byteen_start = byteen & BYTE_EN_START_MASK; > + byteen_end = byteen & BYTE_EN_END_MASK; > + > + byen = byteen_start | (byteen_start << 4); > + ret = set_registers(tp, index, type | byen, 4, data); > + if (ret < 0) > + goto error1; > + > + index += 4; > + data += 4; > + size -= 4; > + > + if (size) { > + size -= 4; > + > + while (size) { > + if (size > limit) { > + ret = set_registers(tp, index, > + type | BYTE_EN_DWORD, > + limit, data); > + if (ret < 0) > + goto error1; > + > + index += limit; > + data += limit; > + size -= limit; Cannot the branches of this code be rewritten in a more compact way ? It seems you're only decrementing two variables by a different factor, no? > +
[U-Boot] [PATCH v2 2/2] usb: eth: add Realtek RTL8152B/RTL8153 driver
From: Ted Chen This patch adds driver support for the Realtek RTL8152B/RTL8153 USB network adapters. Signed-off-by: Ted Chen [swarren, fixed a few compiler warnings] [swarren, with permission, converted license header to SPDX] [swarren, removed printf() spew during probe()] Signed-off-by: Stephen Warren Changes for v2: Modified by Marek's comments. - Remove pattern informations. - Don't allocate & free when read/write register. - relpace udelay to mdelay. - pull firmware into global variable. - code review. Signed-off-by: Ted Chen --- drivers/usb/eth/Makefile|1 + drivers/usb/eth/r8152.c | 3099 +++ drivers/usb/eth/usb_ether.c |8 + include/usb_ether.h |6 + 4 files changed, 3114 insertions(+) create mode 100644 drivers/usb/eth/r8152.c diff --git a/drivers/usb/eth/Makefile b/drivers/usb/eth/Makefile index c92d2b0..74f5f87 100644 --- a/drivers/usb/eth/Makefile +++ b/drivers/usb/eth/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_USB_ETHER_ASIX) += asix.o obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o +obj-$(CONFIG_USB_ETHER_RTL8152) += r8152.o diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c new file mode 100644 index 000..345f2c3 --- /dev/null +++ b/drivers/usb/eth/r8152.c @@ -0,0 +1,3099 @@ +/* + * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved. + * + * SPDX-License-Identifier:GPL-2.0 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "usb_ether.h" + +#define DRIVER_VERSION "v1.0 (2015/11/24)" + +#define R8152_PHY_ID 32 + +#define PLA_IDR0xc000 +#define PLA_RCR0xc010 +#define PLA_RMS0xc016 +#define PLA_RXFIFO_CTRL0 0xc0a0 +#define PLA_RXFIFO_CTRL1 0xc0a4 +#define PLA_RXFIFO_CTRL2 0xc0a8 +#define PLA_DMY_REG0 0xc0b0 +#define PLA_FMC0xc0b4 +#define PLA_CFG_WOL0xc0b6 +#define PLA_TEREDO_CFG 0xc0bc +#define PLA_MAR0xcd00 +#define PLA_BACKUP 0xd000 +#define PAL_BDC_CR 0xd1a0 +#define PLA_TEREDO_TIMER 0xd2cc +#define PLA_REALWOW_TIMER 0xd2e8 +#define PLA_LEDSEL 0xdd90 +#define PLA_LED_FEATURE0xdd92 +#define PLA_PHYAR 0xde00 +#define PLA_BOOT_CTRL 0xe004 +#define PLA_GPHY_INTR_IMR 0xe022 +#define PLA_EEE_CR 0xe040 +#define PLA_EEEP_CR0xe080 +#define PLA_MAC_PWR_CTRL 0xe0c0 +#define PLA_MAC_PWR_CTRL2 0xe0ca +#define PLA_MAC_PWR_CTRL3 0xe0cc +#define PLA_MAC_PWR_CTRL4 0xe0ce +#define PLA_WDT6_CTRL 0xe428 +#define PLA_TCR0 0xe610 +#define PLA_TCR1 0xe612 +#define PLA_MTPS 0xe615 +#define PLA_TXFIFO_CTRL0xe618 +#define PLA_RSTTALLY 0xe800 +#define PLA_CR 0xe813 +#define PLA_CRWECR 0xe81c +#define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */ +#define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */ +#define PLA_CONFIG50xe822 +#define PLA_PHY_PWR0xe84c +#define PLA_OOB_CTRL 0xe84f +#define PLA_CPCR 0xe854 +#define PLA_MISC_0 0xe858 +#define PLA_MISC_1 0xe85a +#define PLA_OCP_GPHY_BASE 0xe86c +#define PLA_TALLYCNT 0xe890 +#define PLA_SFF_STS_7 0xe8de +#define PLA_PHYSTATUS 0xe908 +#define PLA_BP_BA 0xfc26 +#define PLA_BP_0 0xfc28 +#define PLA_BP_1 0xfc2a +#define PLA_BP_2 0xfc2c +#define PLA_BP_3 0xfc2e +#define PLA_BP_4 0xfc30 +#define PLA_BP_5 0xfc32 +#define PLA_BP_6 0xfc34 +#define PLA_BP_7 0xfc36 +#define PLA_BP_EN 0xfc38 + +#define USB_USB2PHY0xb41e +#define USB_SSPHYLINK2 0xb428 +#define USB_U2P3_CTRL 0xb460 +#define USB_CSR_DUMMY1 0xb464 +#define USB_CSR_DUMMY2 0xb466 +#define USB_DEV_STAT 0xb808 +#define USB_CONNECT_TIMER 0xcbf8 +#define USB_BURST_SIZE 0xcfc0 +#define USB_USB_CTRL 0xd406 +#define USB_PHY_CTRL 0xd408 +#define USB_TX_AGG 0xd40a +#define USB_RX_BUF_TH 0xd40c +#define USB_USB_TIMER 0xd428 +#define USB_RX_EARLY_TIMEOUT 0xd42c +#define USB_RX_EARLY_SIZE 0xd42e +#define USB_PM_CTRL_STATUS 0xd432 +#define USB_TX_DMA 0xd434 +#define USB_TOLERANCE 0xd490 +#define USB_LPM_CTRL 0xd41a +#define USB_UPS_CTRL 0xd800 +#define USB_MISC_0 0xd81a +#define USB_POWER_CUT 0xd80a +#define USB_AFE_CTRL2 0xd824 +#define USB_WDT11_CTRL 0xe43c +#define USB_BP_BA
Re: [U-Boot] [PATCH v2 2/2] usb: eth: add Realtek RTL8152B/RTL8153 driver
Hi Ted, On 25 November 2015 at 11:00, Ted Chen wrote: > From: Ted Chen > > This patch adds driver support for the Realtek RTL8152B/RTL8153 USB > network adapters. > > Signed-off-by: Ted Chen > [swarren, fixed a few compiler warnings] > [swarren, with permission, converted license header to SPDX] > [swarren, removed printf() spew during probe()] > Signed-off-by: Stephen Warren > > Changes for v2: Modified by Marek's comments. > - Remove pattern informations. > - Don't allocate & free when read/write register. > - relpace udelay to mdelay. > - pull firmware into global variable. > - code review. > > Signed-off-by: Ted Chen > --- > drivers/usb/eth/Makefile|1 + > drivers/usb/eth/r8152.c | 3099 > +++ > drivers/usb/eth/usb_ether.c |8 + > include/usb_ether.h |6 + > 4 files changed, 3114 insertions(+) > create mode 100644 drivers/usb/eth/r8152.c > > diff --git a/drivers/usb/eth/Makefile b/drivers/usb/eth/Makefile > index c92d2b0..74f5f87 100644 > --- a/drivers/usb/eth/Makefile > +++ b/drivers/usb/eth/Makefile > @@ -9,3 +9,4 @@ obj-$(CONFIG_USB_ETHER_ASIX) += asix.o > obj-$(CONFIG_USB_ETHER_ASIX88179) += asix88179.o > obj-$(CONFIG_USB_ETHER_MCS7830) += mcs7830.o > obj-$(CONFIG_USB_ETHER_SMSC95XX) += smsc95xx.o > +obj-$(CONFIG_USB_ETHER_RTL8152) += r8152.o > diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c > new file mode 100644 > index 000..345f2c3 > --- /dev/null > +++ b/drivers/usb/eth/r8152.c > @@ -0,0 +1,3099 @@ > +/* > + * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved. > + * > + * SPDX-License-Identifier:GPL-2.0 > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "usb_ether.h" > + > +#define DRIVER_VERSION "v1.0 (2015/11/24)" > + > +#define R8152_PHY_ID 32 > + > +#define PLA_IDR0xc000 > +#define PLA_RCR0xc010 > +#define PLA_RMS0xc016 > +#define PLA_RXFIFO_CTRL0 0xc0a0 > +#define PLA_RXFIFO_CTRL1 0xc0a4 > +#define PLA_RXFIFO_CTRL2 0xc0a8 > +#define PLA_DMY_REG0 0xc0b0 > +#define PLA_FMC0xc0b4 > +#define PLA_CFG_WOL0xc0b6 > +#define PLA_TEREDO_CFG 0xc0bc > +#define PLA_MAR0xcd00 > +#define PLA_BACKUP 0xd000 > +#define PAL_BDC_CR 0xd1a0 > +#define PLA_TEREDO_TIMER 0xd2cc > +#define PLA_REALWOW_TIMER 0xd2e8 > +#define PLA_LEDSEL 0xdd90 > +#define PLA_LED_FEATURE0xdd92 > +#define PLA_PHYAR 0xde00 > +#define PLA_BOOT_CTRL 0xe004 > +#define PLA_GPHY_INTR_IMR 0xe022 > +#define PLA_EEE_CR 0xe040 > +#define PLA_EEEP_CR0xe080 > +#define PLA_MAC_PWR_CTRL 0xe0c0 > +#define PLA_MAC_PWR_CTRL2 0xe0ca > +#define PLA_MAC_PWR_CTRL3 0xe0cc > +#define PLA_MAC_PWR_CTRL4 0xe0ce > +#define PLA_WDT6_CTRL 0xe428 > +#define PLA_TCR0 0xe610 > +#define PLA_TCR1 0xe612 > +#define PLA_MTPS 0xe615 > +#define PLA_TXFIFO_CTRL0xe618 > +#define PLA_RSTTALLY 0xe800 > +#define PLA_CR 0xe813 > +#define PLA_CRWECR 0xe81c > +#define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */ > +#define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */ > +#define PLA_CONFIG50xe822 > +#define PLA_PHY_PWR0xe84c > +#define PLA_OOB_CTRL 0xe84f > +#define PLA_CPCR 0xe854 > +#define PLA_MISC_0 0xe858 > +#define PLA_MISC_1 0xe85a > +#define PLA_OCP_GPHY_BASE 0xe86c > +#define PLA_TALLYCNT 0xe890 > +#define PLA_SFF_STS_7 0xe8de > +#define PLA_PHYSTATUS 0xe908 > +#define PLA_BP_BA 0xfc26 > +#define PLA_BP_0 0xfc28 > +#define PLA_BP_1 0xfc2a > +#define PLA_BP_2 0xfc2c > +#define PLA_BP_3 0xfc2e > +#define PLA_BP_4 0xfc30 > +#define PLA_BP_5 0xfc32 > +#define PLA_BP_6 0xfc34 > +#define PLA_BP_7 0xfc36 > +#define PLA_BP_EN 0xfc38 > + > +#define USB_USB2PHY0xb41e > +#define USB_SSPHYLINK2 0xb428 > +#define USB_U2P3_CTRL 0xb460 > +#define USB_CSR_DUMMY1 0xb464 > +#define USB_CSR_DUMMY2 0xb466 > +#define USB_DEV_STAT 0xb808 > +#define USB_CONNECT_TIMER 0xcbf8 > +#define USB_BURST_SIZE 0xcfc0 > +#define USB_USB_CTRL 0xd406 > +#define USB_PHY_CTRL 0xd408 > +#define USB_TX_AGG 0xd40a > +#define USB_RX_BUF_TH 0xd40c > +#define USB_USB_TIMER 0xd428 > +#define USB_RX_EARLY_TIMEOUT 0xd42c > +#define USB_RX_EARLY_SIZE 0xd42e > +#define USB_PM_CTRL_STATUS 0xd432 > +#defi