Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
Lennert Buytenhek wrote: +struct rx_desc { + u32 cmd_sts; + u16 size; + u16 count; + u32 buf; + u32 next; +}; + +struct tx_desc { + u32 cmd_sts; + u16 l4i_chk; + u16 count; + u32 buf; + u32 next; +}; should use sparse type (__le32, etc.) and make sure this driver passes sparse checks ditto for checkpatch (except for the excessively anal stuff) +struct orion_priv { + unsigned long base_addr; + + /* +* RX stuff +*/ + u32 rxd_used; + u32 rxd_curr; + u32 rxd_count; + u32 rxd_max_pending; + struct sk_buff *rx_skb[RX_DESC_NR]; + struct rx_desc *rxd_base; + dma_addr_t rxd_base_dma; + spinlock_t rx_lock; + struct timer_list rx_fill_timer; + + /* +* TX stuff +*/ + u32 txd_used; + u32 txd_curr; + u32 txd_count; + u32 txd_max_pending; + struct sk_buff *tx_skb[TX_DESC_NR]; + struct tx_desc *txd_base; + dma_addr_t txd_base_dma; + spinlock_t tx_lock; + + /* +* PHY stuff +*/ + struct mii_if_info mii; + spinlock_t mii_lock; + + /* +* Statistics counters +*/ + struct net_device_stats stats; +}; + +/* + * PHY access + / +static int orion_mii_read(struct net_device *dev, int phy_id, int reg) +{ + struct orion_priv *op = netdev_priv(dev); + int val, i; + + spin_lock(op-mii_lock); + + /* +* Poll until not busy +*/ + for (i = 1; i (rdl(op, ETH_SMI) SMI_BUSY); i--) + rmb(); + + if (i == 0) { + printk(orion-eth mii read busy timeout\n); + val = -1; + goto out; + } + + /* +* Issue read command +*/ + wrl(op, ETH_SMI, (phy_id SMI_DEV_OFFS) | +(reg SMI_REG_OFFS) | SMI_READ); + + /* +* Poll until data is ready +*/ + for (i = 1; i !(rdl(op, ETH_SMI) SMI_READ_VALID); i--) + rmb(); + + if (i == 0) { + printk(orion-eth mii read busy timeout\n); + val = -1; + goto out; + } + + /* +* Read data +*/ + val = rdl(op, ETH_SMI) 0x; + +out: + spin_unlock(op-mii_lock); + return val; +} + +static void orion_mii_write(struct net_device *dev, int phy_id, int reg, int data) +{ + struct orion_priv *op = netdev_priv(dev); + int i; + + spin_lock(op-mii_lock); + + /* +* Poll until not busy +*/ + for (i = 1; i (rdl(op, ETH_SMI) SMI_BUSY); i--) + rmb(); + + if (i == 0) { + printk(orion-eth mii write busy timeout\n); + goto out; + } + + /* +* Issue write command +*/ + wrl(op, ETH_SMI, (phy_id 16) | (reg 21) | data); + +out: + spin_unlock(op-mii_lock); +} + +/* + * Called from orion_irq in interrupt context. + * Not going out to read PHY status, using Orion registers instead. + */ +static inline void orion_phy_link_change(struct net_device *dev) +{ + struct orion_priv *op = netdev_priv(dev); + u32 stat = rdl(op, PORT_STAT); + + if (!(stat STAT_LINK_UP)) { + netif_carrier_off(dev); + netif_stop_queue(dev); + printk(KERN_NOTICE %s: link down.\n, dev-name); + } else { + netif_carrier_on(dev); + netif_wake_queue(dev); + netif_poll_enable(dev); + printk(KERN_NOTICE %s: link up, , dev-name); + if (stat STAT_FULL_DUPLEX) + printk(full duplex, ); + else + printk(half duplex, ); + if (stat STAT_SPEED_1000) + printk(1000Mbps.\n); + else if (stat STAT_SPEED_100) + printk(100Mbps\n); + else + printk(10Mbps\n); + } +} + +/* + * MAC address filtering + / +static void orion_set_unicast(struct orion_priv *op, u8 *addr) +{ + int i; + + /* +* Clear unicast table +*/ + for (i = 0; i PORT_UCAST_SIZE; i += 4) + wrl(op, PORT_UCAST_BASE + i, 0); + + /* +* Setup MAC addr registers +*/ + wrl(op, PORT_MAC_HI, (addr[0] 24) | (addr[1] 16) | +(addr[2] 8) | addr[3]); + wrl(op, PORT_MAC_LO, (addr[4] 8) | addr[5]); + + /* +* Enable our entry in unicat table +*/ + wrb(op, PORT_UCAST_BASE + (addr[5] 0xf), 1); +} +
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
On Thu, Oct 25, 2007 at 05:12:04AM -0400, Jeff Garzik wrote: +struct rx_desc { +u32 cmd_sts; +u16 size; +u16 count; +u32 buf; +u32 next; +}; + +struct tx_desc { +u32 cmd_sts; +u16 l4i_chk; +u16 count; +u32 buf; +u32 next; +}; should use sparse type (__le32, etc.) and make sure this driver passes sparse checks ditto for checkpatch (except for the excessively anal stuff) Sorry if it wasn't clear from the thread -- the mainline mv643xx_eth driver turns out to support the same silicon block (but as part of a different chip), so we've dropped orion_eth and submitted patches to make mv643xx_eth work on both the Discovery (what it was originally written for) and the Orion, and these patches are in -rc1 already. - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
On Thu, Oct 18, 2007 at 03:15:36AM +0200, Lennert Buytenhek wrote: +#define PORT_CONF0x400 +#define PORT_CONF_EXT0x404 +#define PORT_MAC_LO 0x414 +#define PORT_MAC_HI 0x418 +#define PORT_SDMA0x41c +#define PORT_SERIAL 0x43c +#define PORT_STAT0x444 +#define PORT_TXQ_CMD 0x448 +#define PORT_MTU 0x458 +#define PORT_CAUSE 0x460 +#define PORT_CAUSE_EXT 0x464 +#define PORT_MASK0x468 +#define PORT_MASK_EXT0x46c +#define PORT_TX_THRESH 0x474 This driver seems to support the same hardware as mv643xx_eth, any chance you could use it to avoid code duplication ? Interesting. After some asking around, it appears that the mv643xx ethernet silicon block is indeed very similar to the ethernet silicon block found the in Orion ARM SoCs. We'll work on getting Orion to use mv643xx_eth. Thanks for pointing this out. Okay, patchset coming up. - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
On Tue, Oct 16, 2007 at 11:31:15PM +0200, Maxime Bizon wrote: Hello, Hi, +#define PORT_CONF 0x400 +#define PORT_CONF_EXT 0x404 +#define PORT_MAC_LO0x414 +#define PORT_MAC_HI0x418 +#define PORT_SDMA 0x41c +#define PORT_SERIAL0x43c +#define PORT_STAT 0x444 +#define PORT_TXQ_CMD 0x448 +#define PORT_MTU 0x458 +#define PORT_CAUSE 0x460 +#define PORT_CAUSE_EXT 0x464 +#define PORT_MASK 0x468 +#define PORT_MASK_EXT 0x46c +#define PORT_TX_THRESH 0x474 This driver seems to support the same hardware as mv643xx_eth, any chance you could use it to avoid code duplication ? Interesting. After some asking around, it appears that the mv643xx ethernet silicon block is indeed very similar to the ethernet silicon block found the in Orion ARM SoCs. We'll work on getting Orion to use mv643xx_eth. Thanks for pointing this out. thanks, Lennert - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
In article [EMAIL PROTECTED] you write: Interesting. After some asking around, it appears that the mv643xx ethernet silicon block is indeed very similar to the ethernet silicon block found the in Orion ARM SoCs. We'll work on getting Orion to use mv643xx_eth. Thanks for pointing this out. Cool. I'd be very receptive to any cleanups you might provide for the mv643xx_eth driver. -Dale - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
On Tue, 16 Oct 2007 21:28:06 +0200 Lennert Buytenhek [EMAIL PROTECTED] wrote: Attached is a driver for the built-in 10/100/1000 ethernet MAC in the Marvell Orion series of ARM SoCs. This ethernet MAC supports the MII/GMII/RGMII PCS interface types, and offers a pretty standard set of MAC features, such as RX/TX checksum offload, scatter-gather, interrupt coalescing, PAUSE, jumbo frames, etc. This patch is against 2.6.22.1, and the driver has not yet been adapted to the recent NAPI changes. Nevertheless, we wanted to get this out there for feedback/review. Comments appreciated! Signed-off-by: Tzachi Perelstein [EMAIL PROTECTED] Signed-off-by: Lennert Buytenhek [EMAIL PROTECTED] Signed-off-by: Nicolas Pitre [EMAIL PROTECTED] +static u8 orion_mcast_hash(u8 *addr) +{ + /* + * CRC-8 x^8+x^2+x^1+1 + */ Why not add a crc-8 set of generic code? +static void orion_rx_fill(struct orion_priv *op) +{ + struct sk_buff *skb; + struct rx_desc *rxd; + int alloc_skb_failed = 0; + u32 unaligned; + + spin_lock_bh(op-rx_lock); + + while (op-rxd_count RX_DESC_NR) { + + rxd = op-rxd_base[op-rxd_used]; + + if (rxd-cmd_sts RXD_DMA) { + printk(KERN_ERR orion_rx_fill error, desc owned by DMA\n); + break; + } + + skb = dev_alloc_skb(MAX_PKT_SIZE + dma_get_cache_alignment()); + if (!skb) { + alloc_skb_failed = 1; + break; + } Use netdev_alloc_skb in new drivers. If you define SLAB DEBUGGING skb-data won't be aligned?? + unaligned = (u32)skb-data (dma_get_cache_alignment() - 1); + if (unaligned) + skb_reserve(skb, dma_get_cache_alignment() - unaligned); + + /* + * HW skips on first 2B to align the IP header + */ + skb_reserve(skb, 2); Use NET_IP_ALIGN instead of 2. That way platforms that don't like unaligned dma's can override it. + + op-rx_skb[op-rxd_used] = skb; + + rxd-buf = dma_map_single(NULL, skb-data, MAX_PKT_SIZE - 2, + DMA_FROM_DEVICE); + rxd-size = MAX_PKT_SIZE RXD_SIZE_MASK; + rxd-count = 0; + wmb(); + rxd-cmd_sts = RXD_DMA | RXD_INT; + + op-rxd_count++; + op-rxd_used = (op-rxd_used + 1) % RX_DESC_NR; + } + + /* + * If skb_alloc failed and the number of rx buffers in the ring is + * less than half of the ring size, then set a timer to try again + * later (100ms). + */ + if (alloc_skb_failed op-rxd_count RX_DESC_NR / 2) { + printk(KERN_INFO orion_rx_fill set timer to alloc bufs\n); + if (!timer_pending(op-rx_fill_timer)) + mod_timer(op-rx_fill_timer, jiffies + (HZ / 10)); + } + + spin_unlock_bh(op-rx_lock); +} +static u32 orion_get_rx_csum(struct net_device *netdev) +{ +#ifdef ORION_RX_CSUM_OFFLOAD + return 1; +#else + return 0; +#endif +} Please allow real disabling of rx checksum. +static u32 orion_get_tx_csum(struct net_device *netdev) +{ +#ifdef ORION_TX_CSUM_OFFLOAD + return 1; +#else + return 0; +#endif +} Please allow control of tx checksum via ethtool_op_get_tx_sum()?? +static struct ethtool_ops orion_ethtool_ops = { + .get_drvinfo= orion_get_drvinfo, + .get_settings = orion_get_settings, + .set_settings = orion_set_settings, + .nway_reset = orion_nway_reset, + .get_link = orion_get_link, + .get_ringparam = orion_get_ringparam, + .get_rx_csum= orion_get_rx_csum, + .get_tx_csum= orion_get_tx_csum, +}; + +static int orion_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + struct orion_priv *op = netdev_priv(dev); + struct mii_ioctl_data *data = if_mii(ifr); + + return generic_mii_ioctl(op-mii, data, cmd, NULL); +} -- Stephen Hemminger [EMAIL PROTECTED] - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH,RFC] Marvell Orion SoC ethernet driver
On Tue, 2007-10-16 at 21:28 +0200, Lennert Buytenhek wrote: Hello, +#define PORT_CONF0x400 +#define PORT_CONF_EXT0x404 +#define PORT_MAC_LO 0x414 +#define PORT_MAC_HI 0x418 +#define PORT_SDMA0x41c +#define PORT_SERIAL 0x43c +#define PORT_STAT0x444 +#define PORT_TXQ_CMD 0x448 +#define PORT_MTU 0x458 +#define PORT_CAUSE 0x460 +#define PORT_CAUSE_EXT 0x464 +#define PORT_MASK0x468 +#define PORT_MASK_EXT0x46c +#define PORT_TX_THRESH 0x474 This driver seems to support the same hardware as mv643xx_eth, any chance you could use it to avoid code duplication ? Regards, -- Maxime - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html