2007-02-01 06:43:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006-2007 PA Semi, Inc
|
|
|
|
*
|
|
|
|
* Driver for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <asm/dma-mapping.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <net/checksum.h>
|
|
|
|
|
2007-05-08 09:47:21 +04:00
|
|
|
#include <asm/irq.h>
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
#include "pasemi_mac.h"
|
|
|
|
|
2007-10-03 01:26:53 +04:00
|
|
|
/* We have our own align, since ppc64 in general has it at 0 because
|
|
|
|
* of design flaws in some of the server bridge chips. However, for
|
|
|
|
* PWRficient doing the unaligned copies is more expensive than doing
|
|
|
|
* unaligned DMA, so make sure the data is aligned instead.
|
|
|
|
*/
|
|
|
|
#define LOCAL_SKB_ALIGN 2
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* TODO list
|
|
|
|
*
|
|
|
|
* - Multicast support
|
|
|
|
* - Large MTU support
|
2007-10-03 01:27:28 +04:00
|
|
|
* - SW LRO
|
|
|
|
* - Multiqueue RX/TX
|
2007-02-01 06:43:54 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Must be a power of two */
|
2007-10-03 01:27:15 +04:00
|
|
|
#define RX_RING_SIZE 4096
|
|
|
|
#define TX_RING_SIZE 4096
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:49 +04:00
|
|
|
#define DEFAULT_MSG_ENABLE \
|
|
|
|
(NETIF_MSG_DRV | \
|
|
|
|
NETIF_MSG_PROBE | \
|
|
|
|
NETIF_MSG_LINK | \
|
|
|
|
NETIF_MSG_TIMER | \
|
|
|
|
NETIF_MSG_IFDOWN | \
|
|
|
|
NETIF_MSG_IFUP | \
|
|
|
|
NETIF_MSG_RX_ERR | \
|
|
|
|
NETIF_MSG_TX_ERR)
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
#define TX_RING(mac, num) ((mac)->tx->ring[(num) & (TX_RING_SIZE-1)])
|
|
|
|
#define TX_RING_INFO(mac, num) ((mac)->tx->ring_info[(num) & (TX_RING_SIZE-1)])
|
|
|
|
#define RX_RING(mac, num) ((mac)->rx->ring[(num) & (RX_RING_SIZE-1)])
|
|
|
|
#define RX_RING_INFO(mac, num) ((mac)->rx->ring_info[(num) & (RX_RING_SIZE-1)])
|
2007-02-01 06:43:54 +03:00
|
|
|
#define RX_BUFF(mac, num) ((mac)->rx->buffers[(num) & (RX_RING_SIZE-1)])
|
|
|
|
|
2007-08-22 18:13:11 +04:00
|
|
|
#define RING_USED(ring) (((ring)->next_to_fill - (ring)->next_to_clean) \
|
|
|
|
& ((ring)->size - 1))
|
|
|
|
#define RING_AVAIL(ring) ((ring->size) - RING_USED(ring))
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
|
|
|
|
|
2007-05-08 09:47:49 +04:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
|
|
|
|
MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
|
|
|
|
|
|
|
|
static int debug = -1; /* -1 == use DEFAULT_MSG_ENABLE as value */
|
|
|
|
module_param(debug, int, 0);
|
|
|
|
MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
static struct pasdma_status *dma_status;
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
|
|
|
|
unsigned int val)
|
|
|
|
{
|
2007-09-16 00:44:07 +04:00
|
|
|
out_le32(mac->iob_regs+reg, val);
|
2007-09-16 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
|
|
|
|
{
|
2007-09-16 00:44:07 +04:00
|
|
|
return in_le32(mac->regs+reg);
|
2007-09-16 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
|
|
|
|
unsigned int val)
|
|
|
|
{
|
2007-09-16 00:44:07 +04:00
|
|
|
out_le32(mac->regs+reg, val);
|
2007-09-16 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
|
|
|
|
{
|
2007-09-16 00:44:07 +04:00
|
|
|
return in_le32(mac->dma_regs+reg);
|
2007-09-16 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
|
|
|
|
unsigned int val)
|
|
|
|
{
|
2007-09-16 00:44:07 +04:00
|
|
|
out_le32(mac->dma_regs+reg, val);
|
2007-09-16 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int pasemi_get_mac_addr(struct pasemi_mac *mac)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = mac->pdev;
|
|
|
|
struct device_node *dn = pci_device_to_OF_node(pdev);
|
2007-05-12 23:57:46 +04:00
|
|
|
int len;
|
2007-02-01 06:43:54 +03:00
|
|
|
const u8 *maddr;
|
|
|
|
u8 addr[6];
|
|
|
|
|
|
|
|
if (!dn) {
|
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"No device node for mac, not configuring\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2007-05-12 23:57:46 +04:00
|
|
|
maddr = of_get_property(dn, "local-mac-address", &len);
|
|
|
|
|
|
|
|
if (maddr && len == 6) {
|
|
|
|
memcpy(mac->mac_addr, maddr, 6);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some old versions of firmware mistakenly uses mac-address
|
|
|
|
* (and as a string) instead of a byte array in local-mac-address.
|
|
|
|
*/
|
2007-05-08 09:48:02 +04:00
|
|
|
|
|
|
|
if (maddr == NULL)
|
2007-05-08 22:57:17 +04:00
|
|
|
maddr = of_get_property(dn, "mac-address", NULL);
|
2007-05-08 09:48:02 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
if (maddr == NULL) {
|
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"no mac address in device tree, not configuring\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2007-05-12 23:57:46 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
|
|
|
|
&addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
|
|
|
|
dev_warn(&pdev->dev,
|
|
|
|
"can't parse mac address, not configuring\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-05-12 23:57:46 +04:00
|
|
|
memcpy(mac->mac_addr, addr, 6);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
static int pasemi_mac_unmap_tx_skb(struct pasemi_mac *mac,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
dma_addr_t *dmas)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
int nfrags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
|
|
|
pci_unmap_single(mac->dma_pdev, dmas[0], skb_headlen(skb),
|
|
|
|
PCI_DMA_TODEVICE);
|
|
|
|
|
|
|
|
for (f = 0; f < nfrags; f++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
|
|
|
|
|
|
|
|
pci_unmap_page(mac->dma_pdev, dmas[f+1], frag->size,
|
|
|
|
PCI_DMA_TODEVICE);
|
|
|
|
}
|
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
|
|
|
|
/* Freed descriptor slot + main SKB ptr + nfrags additional ptrs,
|
|
|
|
* aligned up to a power of 2
|
|
|
|
*/
|
|
|
|
return (nfrags + 3) & ~1;
|
|
|
|
}
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int pasemi_mac_setup_rx_resources(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac_rxring *ring;
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
int chan_id = mac->dma_rxch;
|
|
|
|
|
|
|
|
ring = kzalloc(sizeof(*ring), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!ring)
|
|
|
|
goto out_ring;
|
|
|
|
|
|
|
|
spin_lock_init(&ring->lock);
|
|
|
|
|
2007-08-22 18:13:11 +04:00
|
|
|
ring->size = RX_RING_SIZE;
|
2007-10-03 01:25:53 +04:00
|
|
|
ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
|
2007-02-01 06:43:54 +03:00
|
|
|
RX_RING_SIZE, GFP_KERNEL);
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
if (!ring->ring_info)
|
|
|
|
goto out_ring_info;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* Allocate descriptors */
|
2007-10-03 01:25:53 +04:00
|
|
|
ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev,
|
|
|
|
RX_RING_SIZE * sizeof(u64),
|
2007-02-01 06:43:54 +03:00
|
|
|
&ring->dma, GFP_KERNEL);
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
if (!ring->ring)
|
|
|
|
goto out_ring_desc;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
memset(ring->ring, 0, RX_RING_SIZE * sizeof(u64));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev,
|
|
|
|
RX_RING_SIZE * sizeof(u64),
|
|
|
|
&ring->buf_dma, GFP_KERNEL);
|
|
|
|
if (!ring->buffers)
|
|
|
|
goto out_buffers;
|
|
|
|
|
|
|
|
memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64));
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_BASEL(chan_id), PAS_DMA_RXCHAN_BASEL_BRBL(ring->dma));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_BASEU(chan_id),
|
|
|
|
PAS_DMA_RXCHAN_BASEU_BRBH(ring->dma >> 32) |
|
2007-10-03 01:25:53 +04:00
|
|
|
PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 3));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_CFG(chan_id),
|
2007-08-22 18:12:52 +04:00
|
|
|
PAS_DMA_RXCHAN_CFG_HBU(2));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_BASEL(mac->dma_if),
|
|
|
|
PAS_DMA_RXINT_BASEL_BRBL(__pa(ring->buffers)));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_BASEU(mac->dma_if),
|
|
|
|
PAS_DMA_RXINT_BASEU_BRBH(__pa(ring->buffers) >> 32) |
|
|
|
|
PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-08-22 18:12:52 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_CFG(mac->dma_if),
|
2007-10-03 01:27:57 +04:00
|
|
|
PAS_DMA_RXINT_CFG_DHL(3) | PAS_DMA_RXINT_CFG_L2 |
|
|
|
|
PAS_DMA_RXINT_CFG_LW | PAS_DMA_RXINT_CFG_RBP |
|
|
|
|
PAS_DMA_RXINT_CFG_HEN);
|
2007-08-22 18:12:52 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
ring->next_to_fill = 0;
|
|
|
|
ring->next_to_clean = 0;
|
|
|
|
|
|
|
|
snprintf(ring->irq_name, sizeof(ring->irq_name),
|
|
|
|
"%s rx", dev->name);
|
|
|
|
mac->rx = ring;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_buffers:
|
|
|
|
dma_free_coherent(&mac->dma_pdev->dev,
|
2007-10-03 01:25:53 +04:00
|
|
|
RX_RING_SIZE * sizeof(u64),
|
|
|
|
mac->rx->ring, mac->rx->dma);
|
|
|
|
out_ring_desc:
|
|
|
|
kfree(ring->ring_info);
|
|
|
|
out_ring_info:
|
2007-02-01 06:43:54 +03:00
|
|
|
kfree(ring);
|
|
|
|
out_ring:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int pasemi_mac_setup_tx_resources(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
u32 val;
|
|
|
|
int chan_id = mac->dma_txch;
|
|
|
|
struct pasemi_mac_txring *ring;
|
|
|
|
|
|
|
|
ring = kzalloc(sizeof(*ring), GFP_KERNEL);
|
|
|
|
if (!ring)
|
|
|
|
goto out_ring;
|
|
|
|
|
|
|
|
spin_lock_init(&ring->lock);
|
|
|
|
|
2007-08-22 18:13:11 +04:00
|
|
|
ring->size = TX_RING_SIZE;
|
2007-10-03 01:25:53 +04:00
|
|
|
ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
|
2007-02-01 06:43:54 +03:00
|
|
|
TX_RING_SIZE, GFP_KERNEL);
|
2007-10-03 01:25:53 +04:00
|
|
|
if (!ring->ring_info)
|
|
|
|
goto out_ring_info;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* Allocate descriptors */
|
2007-10-03 01:25:53 +04:00
|
|
|
ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev,
|
|
|
|
TX_RING_SIZE * sizeof(u64),
|
2007-02-01 06:43:54 +03:00
|
|
|
&ring->dma, GFP_KERNEL);
|
2007-10-03 01:25:53 +04:00
|
|
|
if (!ring->ring)
|
|
|
|
goto out_ring_desc;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
memset(ring->ring, 0, TX_RING_SIZE * sizeof(u64));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_BASEL(chan_id),
|
|
|
|
PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma));
|
2007-02-01 06:43:54 +03:00
|
|
|
val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32);
|
2007-10-03 01:25:53 +04:00
|
|
|
val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 3);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_BASEU(chan_id), val);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_CFG(chan_id),
|
|
|
|
PAS_DMA_TXCHAN_CFG_TY_IFACE |
|
|
|
|
PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
|
|
|
|
PAS_DMA_TXCHAN_CFG_UP |
|
|
|
|
PAS_DMA_TXCHAN_CFG_WT(2));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-08-22 18:13:11 +04:00
|
|
|
ring->next_to_fill = 0;
|
2007-02-01 06:43:54 +03:00
|
|
|
ring->next_to_clean = 0;
|
|
|
|
|
|
|
|
snprintf(ring->irq_name, sizeof(ring->irq_name),
|
|
|
|
"%s tx", dev->name);
|
|
|
|
mac->tx = ring;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
out_ring_desc:
|
|
|
|
kfree(ring->ring_info);
|
|
|
|
out_ring_info:
|
2007-02-01 06:43:54 +03:00
|
|
|
kfree(ring);
|
|
|
|
out_ring:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pasemi_mac_free_tx_resources(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
2007-10-03 01:26:13 +04:00
|
|
|
unsigned int i, j;
|
2007-02-01 06:43:54 +03:00
|
|
|
struct pasemi_mac_buffer *info;
|
2007-10-03 01:26:13 +04:00
|
|
|
dma_addr_t dmas[MAX_SKB_FRAGS+1];
|
|
|
|
int freed;
|
2007-10-03 01:27:15 +04:00
|
|
|
int start, limit;
|
2007-10-03 01:25:53 +04:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
start = mac->tx->next_to_clean;
|
|
|
|
limit = mac->tx->next_to_fill;
|
|
|
|
|
|
|
|
/* Compensate for when fill has wrapped and clean has not */
|
|
|
|
if (start > limit)
|
|
|
|
limit += TX_RING_SIZE;
|
|
|
|
|
|
|
|
for (i = start; i < limit; i += freed) {
|
2007-10-03 01:25:53 +04:00
|
|
|
info = &TX_RING_INFO(mac, i+1);
|
|
|
|
if (info->dma && info->skb) {
|
2007-10-03 01:26:13 +04:00
|
|
|
for (j = 0; j <= skb_shinfo(info->skb)->nr_frags; j++)
|
|
|
|
dmas[j] = TX_RING_INFO(mac, i+1+j).dma;
|
|
|
|
freed = pasemi_mac_unmap_tx_skb(mac, info->skb, dmas);
|
|
|
|
} else
|
|
|
|
freed = 2;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
for (i = 0; i < TX_RING_SIZE; i++)
|
|
|
|
TX_RING(mac, i) = 0;
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
dma_free_coherent(&mac->dma_pdev->dev,
|
2007-10-03 01:25:53 +04:00
|
|
|
TX_RING_SIZE * sizeof(u64),
|
|
|
|
mac->tx->ring, mac->tx->dma);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
kfree(mac->tx->ring_info);
|
2007-02-01 06:43:54 +03:00
|
|
|
kfree(mac->tx);
|
|
|
|
mac->tx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pasemi_mac_free_rx_resources(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
unsigned int i;
|
|
|
|
struct pasemi_mac_buffer *info;
|
|
|
|
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
2007-10-03 01:25:53 +04:00
|
|
|
info = &RX_RING_INFO(mac, i);
|
|
|
|
if (info->skb && info->dma) {
|
|
|
|
pci_unmap_single(mac->dma_pdev,
|
|
|
|
info->dma,
|
|
|
|
info->skb->len,
|
|
|
|
PCI_DMA_FROMDEVICE);
|
|
|
|
dev_kfree_skb_any(info->skb);
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
2007-10-03 01:25:53 +04:00
|
|
|
info->dma = 0;
|
|
|
|
info->skb = NULL;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
for (i = 0; i < RX_RING_SIZE; i++)
|
|
|
|
RX_RING(mac, i) = 0;
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
dma_free_coherent(&mac->dma_pdev->dev,
|
2007-10-03 01:25:53 +04:00
|
|
|
RX_RING_SIZE * sizeof(u64),
|
|
|
|
mac->rx->ring, mac->rx->dma);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
|
|
|
|
mac->rx->buffers, mac->rx->buf_dma);
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
kfree(mac->rx->ring_info);
|
2007-02-01 06:43:54 +03:00
|
|
|
kfree(mac->rx);
|
|
|
|
mac->rx = NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-27 01:25:06 +04:00
|
|
|
static void pasemi_mac_replenish_rx_ring(struct net_device *dev, int limit)
|
2007-02-01 06:43:54 +03:00
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
2007-10-03 01:27:57 +04:00
|
|
|
int fill, count;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:45 +04:00
|
|
|
if (limit <= 0)
|
2007-02-01 06:43:54 +03:00
|
|
|
return;
|
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
fill = mac->rx->next_to_fill;
|
2007-09-27 01:25:06 +04:00
|
|
|
for (count = 0; count < limit; count++) {
|
2007-10-03 01:25:53 +04:00
|
|
|
struct pasemi_mac_buffer *info = &RX_RING_INFO(mac, fill);
|
|
|
|
u64 *buff = &RX_BUFF(mac, fill);
|
2007-02-01 06:43:54 +03:00
|
|
|
struct sk_buff *skb;
|
|
|
|
dma_addr_t dma;
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
/* Entry in use? */
|
|
|
|
WARN_ON(*buff);
|
|
|
|
|
2007-05-08 09:47:37 +04:00
|
|
|
/* skb might still be in there for recycle on short receives */
|
|
|
|
if (info->skb)
|
|
|
|
skb = info->skb;
|
2007-10-03 01:26:53 +04:00
|
|
|
else {
|
2007-05-08 09:47:37 +04:00
|
|
|
skb = dev_alloc_skb(BUF_SIZE);
|
2007-10-03 01:26:53 +04:00
|
|
|
skb_reserve(skb, LOCAL_SKB_ALIGN);
|
|
|
|
}
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:37 +04:00
|
|
|
if (unlikely(!skb))
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
|
2007-10-03 01:26:53 +04:00
|
|
|
dma = pci_map_single(mac->dma_pdev, skb->data,
|
|
|
|
BUF_SIZE - LOCAL_SKB_ALIGN,
|
2007-02-01 06:43:54 +03:00
|
|
|
PCI_DMA_FROMDEVICE);
|
|
|
|
|
2007-05-08 09:47:45 +04:00
|
|
|
if (unlikely(dma_mapping_error(dma))) {
|
2007-02-01 06:43:54 +03:00
|
|
|
dev_kfree_skb_irq(info->skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->skb = skb;
|
|
|
|
info->dma = dma;
|
|
|
|
*buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
|
2007-10-03 01:25:53 +04:00
|
|
|
fill++;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
|
2007-09-27 01:25:06 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_INCR(mac->dma_if), count);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
mac->rx->next_to_fill = (mac->rx->next_to_fill + count) &
|
|
|
|
(RX_RING_SIZE - 1);
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-05-08 09:47:26 +04:00
|
|
|
static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
|
|
|
|
{
|
2007-05-13 03:01:09 +04:00
|
|
|
unsigned int reg, pcnt;
|
2007-05-08 09:47:26 +04:00
|
|
|
/* Re-enable packet count interrupts: finally
|
|
|
|
* ack the packet count interrupt we got in rx_intr.
|
|
|
|
*/
|
|
|
|
|
2007-05-13 03:01:09 +04:00
|
|
|
pcnt = *mac->rx_status & PAS_STATUS_PCNT_M;
|
2007-05-08 09:47:26 +04:00
|
|
|
|
2007-05-13 03:01:09 +04:00
|
|
|
reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
|
2007-05-08 09:47:26 +04:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
|
2007-05-08 09:47:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac)
|
|
|
|
{
|
2007-05-13 03:01:09 +04:00
|
|
|
unsigned int reg, pcnt;
|
2007-05-08 09:47:26 +04:00
|
|
|
|
|
|
|
/* Re-enable packet count interrupts */
|
2007-05-13 03:01:09 +04:00
|
|
|
pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
|
2007-05-08 09:47:26 +04:00
|
|
|
|
2007-05-13 03:01:09 +04:00
|
|
|
reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
|
2007-05-08 09:47:26 +04:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
|
2007-05-08 09:47:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-03 01:24:51 +04:00
|
|
|
static inline void pasemi_mac_rx_error(struct pasemi_mac *mac, u64 macrx)
|
|
|
|
{
|
|
|
|
unsigned int rcmdsta, ccmdsta;
|
|
|
|
|
|
|
|
if (!netif_msg_rx_err(mac))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rcmdsta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
|
|
|
|
ccmdsta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
|
|
|
|
|
|
|
|
printk(KERN_ERR "pasemi_mac: rx error. macrx %016lx, rx status %lx\n",
|
|
|
|
macrx, *mac->rx_status);
|
|
|
|
|
|
|
|
printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n",
|
|
|
|
rcmdsta, ccmdsta);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pasemi_mac_tx_error(struct pasemi_mac *mac, u64 mactx)
|
|
|
|
{
|
|
|
|
unsigned int cmdsta;
|
|
|
|
|
|
|
|
if (!netif_msg_tx_err(mac))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmdsta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
|
|
|
|
|
|
|
|
printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016lx, "\
|
|
|
|
"tx status 0x%016lx\n", mactx, *mac->tx_status);
|
|
|
|
|
|
|
|
printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta);
|
|
|
|
}
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
|
|
|
|
{
|
2007-05-08 09:47:45 +04:00
|
|
|
unsigned int n;
|
|
|
|
int count;
|
|
|
|
struct pasemi_mac_buffer *info;
|
|
|
|
struct sk_buff *skb;
|
2007-10-03 01:27:57 +04:00
|
|
|
unsigned int len;
|
2007-05-08 09:47:45 +04:00
|
|
|
u64 macrx;
|
|
|
|
dma_addr_t dma;
|
2007-10-03 01:27:57 +04:00
|
|
|
int buf_index;
|
|
|
|
u64 eval;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
spin_lock(&mac->rx->lock);
|
|
|
|
|
2007-05-08 09:47:45 +04:00
|
|
|
n = mac->rx->next_to_clean;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
prefetch(RX_RING(mac, n));
|
|
|
|
|
|
|
|
for (count = 0; count < limit; count++) {
|
2007-10-03 01:25:53 +04:00
|
|
|
macrx = RX_RING(mac, n);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:24:51 +04:00
|
|
|
if ((macrx & XCT_MACRX_E) ||
|
|
|
|
(*mac->rx_status & PAS_STATUS_ERROR))
|
|
|
|
pasemi_mac_rx_error(mac, macrx);
|
|
|
|
|
2007-05-08 09:47:45 +04:00
|
|
|
if (!(macrx & XCT_MACRX_O))
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
BUG_ON(!(macrx & XCT_MACRX_RR_8BRES));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
eval = (RX_RING(mac, n+1) & XCT_RXRES_8B_EVAL_M) >>
|
|
|
|
XCT_RXRES_8B_EVAL_S;
|
|
|
|
buf_index = eval-1;
|
|
|
|
|
|
|
|
dma = (RX_RING(mac, n+2) & XCT_PTR_ADDR_M);
|
|
|
|
info = &RX_RING_INFO(mac, buf_index);
|
2007-10-03 01:25:53 +04:00
|
|
|
|
2007-05-08 09:47:37 +04:00
|
|
|
skb = info->skb;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
prefetch(skb);
|
|
|
|
prefetch(&skb->data_len);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:45 +04:00
|
|
|
len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:37 +04:00
|
|
|
if (len < 256) {
|
2007-10-03 01:26:53 +04:00
|
|
|
struct sk_buff *new_skb;
|
|
|
|
|
|
|
|
new_skb = netdev_alloc_skb(mac->netdev,
|
|
|
|
len + LOCAL_SKB_ALIGN);
|
2007-05-08 09:47:37 +04:00
|
|
|
if (new_skb) {
|
2007-10-03 01:26:53 +04:00
|
|
|
skb_reserve(new_skb, LOCAL_SKB_ALIGN);
|
2007-08-22 18:12:55 +04:00
|
|
|
memcpy(new_skb->data, skb->data, len);
|
2007-05-08 09:47:37 +04:00
|
|
|
/* save the skb in buffer_info as good */
|
|
|
|
skb = new_skb;
|
|
|
|
}
|
|
|
|
/* else just continue with the old one */
|
|
|
|
} else
|
|
|
|
info->skb = NULL;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
pci_unmap_single(mac->dma_pdev, dma, len, PCI_DMA_FROMDEVICE);
|
|
|
|
|
|
|
|
info->dma = 0;
|
2007-10-03 01:25:53 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
skb_put(skb, len);
|
|
|
|
|
2007-08-22 18:12:59 +04:00
|
|
|
if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) {
|
2007-08-22 18:13:24 +04:00
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
2007-05-08 09:47:45 +04:00
|
|
|
skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
|
2007-02-01 06:43:54 +03:00
|
|
|
XCT_MACRX_CSUM_S;
|
|
|
|
} else
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
|
2007-10-04 04:41:50 +04:00
|
|
|
mac->netdev->stats.rx_bytes += len;
|
|
|
|
mac->netdev->stats.rx_packets++;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-08-22 18:12:59 +04:00
|
|
|
skb->protocol = eth_type_trans(skb, mac->netdev);
|
2007-02-01 06:43:54 +03:00
|
|
|
netif_receive_skb(skb);
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
RX_RING(mac, n) = 0;
|
|
|
|
RX_RING(mac, n+1) = 0;
|
2007-05-08 09:47:45 +04:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
/* Need to zero it out since hardware doesn't, since the
|
|
|
|
* replenish loop uses it to tell when it's done.
|
|
|
|
*/
|
2007-10-03 01:27:57 +04:00
|
|
|
RX_BUFF(mac, buf_index) = 0;
|
2007-10-03 01:27:15 +04:00
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
n += 4;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-10-03 01:26:30 +04:00
|
|
|
if (n > RX_RING_SIZE) {
|
|
|
|
/* Errata 5971 workaround: L2 target of headers */
|
|
|
|
write_iob_reg(mac, PAS_IOB_COM_PKTHDRCNT, 0);
|
|
|
|
n &= (RX_RING_SIZE-1);
|
|
|
|
}
|
2007-10-03 01:27:57 +04:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
mac->rx->next_to_clean = n;
|
2007-10-03 01:27:57 +04:00
|
|
|
|
|
|
|
/* Increase is in number of 16-byte entries, and since each descriptor
|
|
|
|
* with an 8BRES takes up 3x8 bytes (padded to 4x8), increase with
|
|
|
|
* count*2.
|
|
|
|
*/
|
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), count << 1);
|
|
|
|
|
|
|
|
pasemi_mac_replenish_rx_ring(mac->netdev, count);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
spin_unlock(&mac->rx->lock);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
/* Can't make this too large or we blow the kernel stack limits */
|
|
|
|
#define TX_CLEAN_BATCHSIZE (128/MAX_SKB_FRAGS)
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int pasemi_mac_clean_tx(struct pasemi_mac *mac)
|
|
|
|
{
|
2007-10-03 01:26:13 +04:00
|
|
|
int i, j;
|
2007-10-03 01:27:15 +04:00
|
|
|
unsigned int start, descr_count, buf_count, batch_limit;
|
|
|
|
unsigned int ring_limit;
|
2007-08-22 18:13:03 +04:00
|
|
|
unsigned int total_count;
|
2007-09-27 01:23:59 +04:00
|
|
|
unsigned long flags;
|
2007-10-03 01:26:13 +04:00
|
|
|
struct sk_buff *skbs[TX_CLEAN_BATCHSIZE];
|
|
|
|
dma_addr_t dmas[TX_CLEAN_BATCHSIZE][MAX_SKB_FRAGS+1];
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-08-22 18:13:03 +04:00
|
|
|
total_count = 0;
|
2007-10-03 01:27:15 +04:00
|
|
|
batch_limit = TX_CLEAN_BATCHSIZE;
|
2007-08-22 18:13:03 +04:00
|
|
|
restart:
|
2007-02-01 06:43:54 +03:00
|
|
|
spin_lock_irqsave(&mac->tx->lock, flags);
|
|
|
|
|
|
|
|
start = mac->tx->next_to_clean;
|
2007-10-03 01:27:15 +04:00
|
|
|
ring_limit = mac->tx->next_to_fill;
|
|
|
|
|
|
|
|
/* Compensate for when fill has wrapped but clean has not */
|
|
|
|
if (start > ring_limit)
|
|
|
|
ring_limit += TX_RING_SIZE;
|
2007-08-22 18:13:03 +04:00
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
buf_count = 0;
|
|
|
|
descr_count = 0;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
for (i = start;
|
2007-10-03 01:27:15 +04:00
|
|
|
descr_count < batch_limit && i < ring_limit;
|
2007-10-03 01:26:13 +04:00
|
|
|
i += buf_count) {
|
2007-10-03 01:25:53 +04:00
|
|
|
u64 mactx = TX_RING(mac, i);
|
2007-10-03 01:27:15 +04:00
|
|
|
struct sk_buff *skb;
|
2007-10-03 01:26:13 +04:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
if ((mactx & XCT_MACTX_E) ||
|
2007-10-03 01:24:51 +04:00
|
|
|
(*mac->tx_status & PAS_STATUS_ERROR))
|
2007-10-03 01:25:53 +04:00
|
|
|
pasemi_mac_tx_error(mac, mactx);
|
2007-10-03 01:24:51 +04:00
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
if (unlikely(mactx & XCT_MACTX_O))
|
2007-08-22 18:13:03 +04:00
|
|
|
/* Not yet transmitted */
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
skb = TX_RING_INFO(mac, i+1).skb;
|
|
|
|
skbs[descr_count] = skb;
|
2007-10-03 01:26:13 +04:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
buf_count = 2 + skb_shinfo(skb)->nr_frags;
|
|
|
|
for (j = 0; j <= skb_shinfo(skb)->nr_frags; j++)
|
2007-10-03 01:26:13 +04:00
|
|
|
dmas[descr_count][j] = TX_RING_INFO(mac, i+1+j).dma;
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
TX_RING(mac, i) = 0;
|
|
|
|
TX_RING(mac, i+1) = 0;
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
/* Since we always fill with an even number of entries, make
|
|
|
|
* sure we skip any unused one at the end as well.
|
|
|
|
*/
|
|
|
|
if (buf_count & 1)
|
|
|
|
buf_count++;
|
|
|
|
descr_count++;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
2007-10-03 01:27:15 +04:00
|
|
|
mac->tx->next_to_clean = i & (TX_RING_SIZE-1);
|
2007-10-03 01:26:13 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
spin_unlock_irqrestore(&mac->tx->lock, flags);
|
2007-04-29 00:36:40 +04:00
|
|
|
netif_wake_queue(mac->netdev);
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
for (i = 0; i < descr_count; i++)
|
|
|
|
pasemi_mac_unmap_tx_skb(mac, skbs[i], dmas[i]);
|
2007-08-22 18:13:03 +04:00
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
total_count += descr_count;
|
2007-08-22 18:13:03 +04:00
|
|
|
|
|
|
|
/* If the batch was full, try to clean more */
|
2007-10-03 01:27:15 +04:00
|
|
|
if (descr_count == batch_limit)
|
2007-08-22 18:13:03 +04:00
|
|
|
goto restart;
|
|
|
|
|
|
|
|
return total_count;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct net_device *dev = data;
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
unsigned int reg;
|
|
|
|
|
2007-05-08 09:47:32 +04:00
|
|
|
if (!(*mac->rx_status & PAS_STATUS_CAUSE_M))
|
2007-02-01 06:43:54 +03:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
2007-05-08 09:47:32 +04:00
|
|
|
/* Don't reset packet count so it won't fire again but clear
|
|
|
|
* all others.
|
|
|
|
*/
|
|
|
|
|
|
|
|
reg = 0;
|
|
|
|
if (*mac->rx_status & PAS_STATUS_SOFT)
|
|
|
|
reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
|
|
|
|
if (*mac->rx_status & PAS_STATUS_ERROR)
|
|
|
|
reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
|
2007-02-01 06:43:54 +03:00
|
|
|
if (*mac->rx_status & PAS_STATUS_TIMER)
|
|
|
|
reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
|
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
netif_rx_schedule(dev, &mac->napi);
|
2007-05-08 09:47:32 +04:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct net_device *dev = data;
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
2007-05-13 03:01:09 +04:00
|
|
|
unsigned int reg, pcnt;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:32 +04:00
|
|
|
if (!(*mac->tx_status & PAS_STATUS_CAUSE_M))
|
2007-02-01 06:43:54 +03:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
pasemi_mac_clean_tx(mac);
|
|
|
|
|
2007-05-13 03:01:09 +04:00
|
|
|
pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
|
|
|
|
|
|
|
|
reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
|
2007-05-08 09:47:32 +04:00
|
|
|
|
|
|
|
if (*mac->tx_status & PAS_STATUS_SOFT)
|
|
|
|
reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
|
|
|
|
if (*mac->tx_status & PAS_STATUS_ERROR)
|
|
|
|
reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2007-05-08 09:47:54 +04:00
|
|
|
static void pasemi_adjust_link(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
int msg;
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int new_flags;
|
|
|
|
|
|
|
|
if (!mac->phydev->link) {
|
|
|
|
/* If no link, MAC speed settings don't matter. Just report
|
|
|
|
* link down and return.
|
|
|
|
*/
|
|
|
|
if (mac->link && netif_msg_link(mac))
|
|
|
|
printk(KERN_INFO "%s: Link is down.\n", dev->name);
|
|
|
|
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
mac->link = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
netif_carrier_on(dev);
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
|
2007-05-08 09:47:54 +04:00
|
|
|
new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
|
|
|
|
PAS_MAC_CFG_PCFG_TSR_M);
|
|
|
|
|
|
|
|
if (!mac->phydev->duplex)
|
|
|
|
new_flags |= PAS_MAC_CFG_PCFG_HD;
|
|
|
|
|
|
|
|
switch (mac->phydev->speed) {
|
|
|
|
case 1000:
|
|
|
|
new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
|
|
|
|
PAS_MAC_CFG_PCFG_TSR_1G;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
|
|
|
|
PAS_MAC_CFG_PCFG_TSR_100M;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
|
|
|
|
PAS_MAC_CFG_PCFG_TSR_10M;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk("Unsupported speed %d\n", mac->phydev->speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print on link or speed/duplex change */
|
|
|
|
msg = mac->link != mac->phydev->link || flags != new_flags;
|
|
|
|
|
|
|
|
mac->duplex = mac->phydev->duplex;
|
|
|
|
mac->speed = mac->phydev->speed;
|
|
|
|
mac->link = mac->phydev->link;
|
|
|
|
|
|
|
|
if (new_flags != flags)
|
2007-09-16 00:40:59 +04:00
|
|
|
write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags);
|
2007-05-08 09:47:54 +04:00
|
|
|
|
|
|
|
if (msg && netif_msg_link(mac))
|
|
|
|
printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
|
|
|
|
dev->name, mac->speed, mac->duplex ? "full" : "half");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pasemi_mac_phy_init(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
struct device_node *dn, *phy_dn;
|
|
|
|
struct phy_device *phydev;
|
|
|
|
unsigned int phy_id;
|
|
|
|
const phandle *ph;
|
|
|
|
const unsigned int *prop;
|
|
|
|
struct resource r;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dn = pci_device_to_OF_node(mac->pdev);
|
2007-05-08 22:57:17 +04:00
|
|
|
ph = of_get_property(dn, "phy-handle", NULL);
|
2007-05-08 09:47:54 +04:00
|
|
|
if (!ph)
|
|
|
|
return -ENODEV;
|
|
|
|
phy_dn = of_find_node_by_phandle(*ph);
|
|
|
|
|
2007-05-08 22:57:17 +04:00
|
|
|
prop = of_get_property(phy_dn, "reg", NULL);
|
2007-05-08 09:47:54 +04:00
|
|
|
ret = of_address_to_resource(phy_dn->parent, 0, &r);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
phy_id = *prop;
|
|
|
|
snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
|
|
|
|
|
|
|
|
of_node_put(phy_dn);
|
|
|
|
|
|
|
|
mac->link = 0;
|
|
|
|
mac->speed = 0;
|
|
|
|
mac->duplex = -1;
|
|
|
|
|
|
|
|
phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
|
|
|
|
|
|
|
|
if (IS_ERR(phydev)) {
|
|
|
|
printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
|
|
|
|
return PTR_ERR(phydev);
|
|
|
|
}
|
|
|
|
|
|
|
|
mac->phydev = phydev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
of_node_put(phy_dn);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int pasemi_mac_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
2007-05-08 09:47:21 +04:00
|
|
|
int base_irq;
|
2007-02-01 06:43:54 +03:00
|
|
|
unsigned int flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* enable rx section */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* enable tx section */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
|
|
|
|
PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
|
|
|
|
PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_mac_reg(mac, PAS_MAC_CFG_TXP, flags);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch),
|
|
|
|
PAS_IOB_DMA_RXCH_CFG_CNTTH(0));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_TXCH_CFG(mac->dma_txch),
|
2007-08-22 18:13:03 +04:00
|
|
|
PAS_IOB_DMA_TXCH_CFG_CNTTH(128));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:26 +04:00
|
|
|
/* Clear out any residual packet count state from firmware */
|
|
|
|
pasemi_mac_restart_rx_intr(mac);
|
|
|
|
pasemi_mac_restart_tx_intr(mac);
|
|
|
|
|
2007-05-08 09:47:32 +04:00
|
|
|
/* 0xffffff is max value, about 16ms */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_iob_reg(mac, PAS_IOB_DMA_COM_TIMEOUTCFG,
|
|
|
|
PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0xffffff));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
ret = pasemi_mac_setup_rx_resources(dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_rx_resources;
|
|
|
|
|
|
|
|
ret = pasemi_mac_setup_tx_resources(dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_tx_resources;
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_mac_reg(mac, PAS_MAC_IPC_CHNL,
|
|
|
|
PAS_MAC_IPC_CHNL_DCHNO(mac->dma_rxch) |
|
|
|
|
PAS_MAC_IPC_CHNL_BCH(mac->dma_rxch));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* enable rx if */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
|
2007-10-03 01:27:39 +04:00
|
|
|
PAS_DMA_RXINT_RCMDSTA_EN |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_DROPS_M |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_BP |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_OO |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_BT);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* enable rx channel */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_EN |
|
2007-10-03 01:27:39 +04:00
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_DU |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_OD |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_FD |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_DT);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* enable tx channel */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
|
2007-10-03 01:27:39 +04:00
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_EN |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_SZ |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DB |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DE |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DA);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-27 01:25:06 +04:00
|
|
|
pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:57 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), RX_RING_SIZE>>1);
|
|
|
|
|
2007-09-27 01:24:42 +04:00
|
|
|
flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PE |
|
|
|
|
PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
|
|
|
|
|
|
|
|
if (mac->type == MAC_TYPE_GMAC)
|
|
|
|
flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
|
|
|
|
else
|
|
|
|
flags |= PAS_MAC_CFG_PCFG_TSR_10G | PAS_MAC_CFG_PCFG_SPD_10G;
|
|
|
|
|
|
|
|
/* Enable interface in MAC */
|
|
|
|
write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
|
|
|
|
|
2007-05-08 09:47:54 +04:00
|
|
|
ret = pasemi_mac_phy_init(dev);
|
|
|
|
/* Some configs don't have PHYs (XAUI etc), so don't complain about
|
|
|
|
* failed init due to -ENODEV.
|
|
|
|
*/
|
|
|
|
if (ret && ret != -ENODEV)
|
|
|
|
dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
netif_start_queue(dev);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
napi_enable(&mac->napi);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:21 +04:00
|
|
|
/* Interrupts are a bit different for our DMA controller: While
|
|
|
|
* it's got one a regular PCI device header, the interrupt there
|
|
|
|
* is really the base of the range it's using. Each tx and rx
|
|
|
|
* channel has it's own interrupt source.
|
|
|
|
*/
|
|
|
|
|
|
|
|
base_irq = virq_to_hw(mac->dma_pdev->irq);
|
|
|
|
|
|
|
|
mac->tx_irq = irq_create_mapping(NULL, base_irq + mac->dma_txch);
|
|
|
|
mac->rx_irq = irq_create_mapping(NULL, base_irq + 20 + mac->dma_txch);
|
|
|
|
|
|
|
|
ret = request_irq(mac->tx_irq, &pasemi_mac_tx_intr, IRQF_DISABLED,
|
2007-02-01 06:43:54 +03:00
|
|
|
mac->tx->irq_name, dev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
|
2007-05-08 09:47:21 +04:00
|
|
|
base_irq + mac->dma_txch, ret);
|
2007-02-01 06:43:54 +03:00
|
|
|
goto out_tx_int;
|
|
|
|
}
|
|
|
|
|
2007-05-08 09:47:21 +04:00
|
|
|
ret = request_irq(mac->rx_irq, &pasemi_mac_rx_intr, IRQF_DISABLED,
|
2007-02-01 06:43:54 +03:00
|
|
|
mac->rx->irq_name, dev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
|
2007-05-08 09:47:21 +04:00
|
|
|
base_irq + 20 + mac->dma_rxch, ret);
|
2007-02-01 06:43:54 +03:00
|
|
|
goto out_rx_int;
|
|
|
|
}
|
|
|
|
|
2007-05-08 09:47:54 +04:00
|
|
|
if (mac->phydev)
|
|
|
|
phy_start(mac->phydev);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_rx_int:
|
2007-05-08 09:47:21 +04:00
|
|
|
free_irq(mac->tx_irq, dev);
|
2007-02-01 06:43:54 +03:00
|
|
|
out_tx_int:
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
napi_disable(&mac->napi);
|
2007-02-01 06:43:54 +03:00
|
|
|
netif_stop_queue(dev);
|
|
|
|
pasemi_mac_free_tx_resources(dev);
|
|
|
|
out_tx_resources:
|
|
|
|
pasemi_mac_free_rx_resources(dev);
|
|
|
|
out_rx_resources:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_RETRIES 5000
|
|
|
|
|
|
|
|
static int pasemi_mac_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
2007-10-03 01:27:39 +04:00
|
|
|
unsigned int sta;
|
2007-02-01 06:43:54 +03:00
|
|
|
int retries;
|
|
|
|
|
2007-05-08 09:47:54 +04:00
|
|
|
if (mac->phydev) {
|
|
|
|
phy_stop(mac->phydev);
|
|
|
|
phy_disconnect(mac->phydev);
|
|
|
|
}
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
netif_stop_queue(dev);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
napi_disable(&mac->napi);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:27:39 +04:00
|
|
|
sta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
|
|
|
|
if (sta & (PAS_DMA_RXINT_RCMDSTA_BP |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_OO |
|
|
|
|
PAS_DMA_RXINT_RCMDSTA_BT))
|
|
|
|
printk(KERN_DEBUG "pasemi_mac: rcmdsta error: 0x%08x\n", sta);
|
|
|
|
|
|
|
|
sta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
|
|
|
|
if (sta & (PAS_DMA_RXCHAN_CCMDSTA_DU |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_OD |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_FD |
|
|
|
|
PAS_DMA_RXCHAN_CCMDSTA_DT))
|
|
|
|
printk(KERN_DEBUG "pasemi_mac: ccmdsta error: 0x%08x\n", sta);
|
|
|
|
|
|
|
|
sta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
|
|
|
|
if (sta & (PAS_DMA_TXCHAN_TCMDSTA_SZ |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DB |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DE |
|
|
|
|
PAS_DMA_TXCHAN_TCMDSTA_DA))
|
|
|
|
printk(KERN_DEBUG "pasemi_mac: tcmdsta error: 0x%08x\n", sta);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
/* Clean out any pending buffers */
|
|
|
|
pasemi_mac_clean_tx(mac);
|
|
|
|
pasemi_mac_clean_rx(mac, RX_RING_SIZE);
|
|
|
|
|
|
|
|
/* Disable interface */
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), PAS_DMA_TXCHAN_TCMDSTA_ST);
|
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), PAS_DMA_RXINT_RCMDSTA_ST);
|
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), PAS_DMA_RXCHAN_CCMDSTA_ST);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
for (retries = 0; retries < MAX_RETRIES; retries++) {
|
2007-10-03 01:27:39 +04:00
|
|
|
sta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
|
|
|
|
if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:27:39 +04:00
|
|
|
if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
|
2007-02-01 06:43:54 +03:00
|
|
|
dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n");
|
|
|
|
|
|
|
|
for (retries = 0; retries < MAX_RETRIES; retries++) {
|
2007-10-03 01:27:39 +04:00
|
|
|
sta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
|
|
|
|
if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:27:39 +04:00
|
|
|
if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
|
2007-02-01 06:43:54 +03:00
|
|
|
dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
|
|
|
|
|
|
|
|
for (retries = 0; retries < MAX_RETRIES; retries++) {
|
2007-10-03 01:27:39 +04:00
|
|
|
sta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
|
|
|
|
if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:27:39 +04:00
|
|
|
if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
|
2007-02-01 06:43:54 +03:00
|
|
|
dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
|
|
|
|
|
|
|
|
/* Then, disable the channel. This must be done separately from
|
|
|
|
* stopping, since you can't disable when active.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 0);
|
|
|
|
write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 0);
|
|
|
|
write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:21 +04:00
|
|
|
free_irq(mac->tx_irq, dev);
|
|
|
|
free_irq(mac->rx_irq, dev);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* Free resources */
|
|
|
|
pasemi_mac_free_rx_resources(dev);
|
|
|
|
pasemi_mac_free_tx_resources(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
struct pasemi_mac_txring *txring;
|
2007-10-03 01:26:13 +04:00
|
|
|
u64 dflags, mactx;
|
|
|
|
dma_addr_t map[MAX_SKB_FRAGS+1];
|
|
|
|
unsigned int map_size[MAX_SKB_FRAGS+1];
|
2007-09-27 01:23:59 +04:00
|
|
|
unsigned long flags;
|
2007-10-03 01:26:13 +04:00
|
|
|
int i, nfrags;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD;
|
|
|
|
|
|
|
|
if (skb->ip_summed == CHECKSUM_PARTIAL) {
|
2007-04-11 07:50:43 +04:00
|
|
|
const unsigned char *nh = skb_network_header(skb);
|
|
|
|
|
2007-04-21 09:47:35 +04:00
|
|
|
switch (ip_hdr(skb)->protocol) {
|
2007-02-01 06:43:54 +03:00
|
|
|
case IPPROTO_TCP:
|
|
|
|
dflags |= XCT_MACTX_CSUM_TCP;
|
2007-03-16 23:26:39 +03:00
|
|
|
dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
|
2007-04-11 07:50:43 +04:00
|
|
|
dflags |= XCT_MACTX_IPO(nh - skb->data);
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
dflags |= XCT_MACTX_CSUM_UDP;
|
2007-03-16 23:26:39 +03:00
|
|
|
dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
|
2007-04-11 07:50:43 +04:00
|
|
|
dflags |= XCT_MACTX_IPO(nh - skb->data);
|
2007-02-01 06:43:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
nfrags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
|
|
|
map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
|
|
|
|
PCI_DMA_TODEVICE);
|
|
|
|
map_size[0] = skb_headlen(skb);
|
|
|
|
if (dma_mapping_error(map[0]))
|
|
|
|
goto out_err_nolock;
|
|
|
|
|
|
|
|
for (i = 0; i < nfrags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
map[i+1] = pci_map_page(mac->dma_pdev, frag->page,
|
|
|
|
frag->page_offset, frag->size,
|
|
|
|
PCI_DMA_TODEVICE);
|
|
|
|
map_size[i+1] = frag->size;
|
|
|
|
if (dma_mapping_error(map[i+1])) {
|
|
|
|
nfrags = i;
|
|
|
|
goto out_err_nolock;
|
|
|
|
}
|
|
|
|
}
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-08-22 18:12:59 +04:00
|
|
|
mactx = dflags | XCT_MACTX_LLEN(skb->len);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
txring = mac->tx;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&txring->lock, flags);
|
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
/* Avoid stepping on the same cache line that the DMA controller
|
|
|
|
* is currently about to send, so leave at least 8 words available.
|
|
|
|
* Total free space needed is mactx + fragments + 8
|
|
|
|
*/
|
|
|
|
if (RING_AVAIL(txring) < nfrags + 10) {
|
|
|
|
/* no room -- stop the queue and wait for tx intr */
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
goto out_err;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-10-03 01:25:53 +04:00
|
|
|
TX_RING(mac, txring->next_to_fill) = mactx;
|
2007-10-03 01:26:13 +04:00
|
|
|
txring->next_to_fill++;
|
|
|
|
TX_RING_INFO(mac, txring->next_to_fill).skb = skb;
|
|
|
|
for (i = 0; i <= nfrags; i++) {
|
|
|
|
TX_RING(mac, txring->next_to_fill+i) =
|
|
|
|
XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
|
|
|
|
TX_RING_INFO(mac, txring->next_to_fill+i).dma = map[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to add an even number of 8-byte entries to the ring
|
|
|
|
* even if the last one is unused. That means always an odd number
|
|
|
|
* of pointers + one mactx descriptor.
|
|
|
|
*/
|
|
|
|
if (nfrags & 1)
|
|
|
|
nfrags++;
|
2007-10-03 01:25:53 +04:00
|
|
|
|
2007-10-03 01:27:15 +04:00
|
|
|
txring->next_to_fill = (txring->next_to_fill + nfrags + 1) &
|
|
|
|
(TX_RING_SIZE-1);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-10-04 04:41:50 +04:00
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += skb->len;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&txring->lock, flags);
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
write_dma_reg(mac, PAS_DMA_TXCHAN_INCR(mac->dma_txch), (nfrags+2) >> 1);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
spin_unlock_irqrestore(&txring->lock, flags);
|
2007-10-03 01:26:13 +04:00
|
|
|
out_err_nolock:
|
|
|
|
while (nfrags--)
|
|
|
|
pci_unmap_single(mac->dma_pdev, map[nfrags], map_size[nfrags],
|
|
|
|
PCI_DMA_TODEVICE);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pasemi_mac_set_rx_mode(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct pasemi_mac *mac = netdev_priv(dev);
|
|
|
|
unsigned int flags;
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
/* Set promiscuous */
|
|
|
|
if (dev->flags & IFF_PROMISC)
|
|
|
|
flags |= PAS_MAC_CFG_PCFG_PR;
|
|
|
|
else
|
|
|
|
flags &= ~PAS_MAC_CFG_PCFG_PR;
|
|
|
|
|
2007-09-16 00:40:59 +04:00
|
|
|
write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
static int pasemi_mac_poll(struct napi_struct *napi, int budget)
|
2007-02-01 06:43:54 +03:00
|
|
|
{
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
|
|
|
|
struct net_device *dev = mac->netdev;
|
|
|
|
int pkts;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-09-16 00:53:19 +04:00
|
|
|
pasemi_mac_clean_tx(mac);
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
pkts = pasemi_mac_clean_rx(mac, budget);
|
|
|
|
if (pkts < budget) {
|
2007-02-01 06:43:54 +03:00
|
|
|
/* all done, no more packets present */
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
netif_rx_complete(dev, napi);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
2007-05-08 09:47:26 +04:00
|
|
|
pasemi_mac_restart_rx_intr(mac);
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
return pkts;
|
2007-02-01 06:43:54 +03:00
|
|
|
}
|
|
|
|
|
2007-09-16 00:44:07 +04:00
|
|
|
static void __iomem * __devinit map_onedev(struct pci_dev *p, int index)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
void __iomem *ret;
|
|
|
|
|
|
|
|
dn = pci_device_to_OF_node(p);
|
|
|
|
if (!dn)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
ret = of_iomap(dn, index);
|
|
|
|
if (!ret)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
fallback:
|
|
|
|
/* This is hardcoded and ugly, but we have some firmware versions
|
|
|
|
* that don't provide the register space in the device tree. Luckily
|
|
|
|
* they are at well-known locations so we can just do the math here.
|
|
|
|
*/
|
|
|
|
return ioremap(0xe0000000 + (p->devfn << 12), 0x2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac)
|
|
|
|
{
|
|
|
|
struct resource res;
|
|
|
|
struct device_node *dn;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
|
|
|
|
if (!mac->dma_pdev) {
|
|
|
|
dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
|
|
|
|
if (!mac->iob_pdev) {
|
|
|
|
dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac->regs = map_onedev(mac->pdev, 0);
|
|
|
|
mac->dma_regs = map_onedev(mac->dma_pdev, 0);
|
|
|
|
mac->iob_regs = map_onedev(mac->iob_pdev, 0);
|
|
|
|
|
|
|
|
if (!mac->regs || !mac->dma_regs || !mac->iob_regs) {
|
|
|
|
dev_err(&mac->pdev->dev, "Can't map registers\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The dma status structure is located in the I/O bridge, and
|
|
|
|
* is cache coherent.
|
|
|
|
*/
|
|
|
|
if (!dma_status) {
|
|
|
|
dn = pci_device_to_OF_node(mac->iob_pdev);
|
|
|
|
if (dn)
|
|
|
|
err = of_address_to_resource(dn, 1, &res);
|
|
|
|
if (!dn || err) {
|
|
|
|
/* Fallback for old firmware */
|
|
|
|
res.start = 0xfd800000;
|
|
|
|
res.end = res.start + 0x1000;
|
|
|
|
}
|
|
|
|
dma_status = __ioremap(res.start, res.end-res.start, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
static int __devinit
|
|
|
|
pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
|
|
|
{
|
|
|
|
static int index = 0;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct pasemi_mac *mac;
|
|
|
|
int err;
|
2007-10-04 04:59:30 +04:00
|
|
|
DECLARE_MAC_BUF(mac_buf);
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
err = pci_enable_device(pdev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
dev = alloc_etherdev(sizeof(struct pasemi_mac));
|
|
|
|
if (dev == NULL) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"pasemi_mac: Could not allocate ethernet device.\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_disable_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_set_drvdata(pdev, dev);
|
|
|
|
SET_NETDEV_DEV(dev, &pdev->dev);
|
|
|
|
|
|
|
|
mac = netdev_priv(dev);
|
|
|
|
|
|
|
|
mac->pdev = pdev;
|
|
|
|
mac->netdev = dev;
|
|
|
|
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
|
|
|
|
|
2007-10-03 01:26:13 +04:00
|
|
|
dev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX | NETIF_F_SG;
|
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-10-04 03:41:36 +04:00
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
/* These should come out of the device tree eventually */
|
|
|
|
mac->dma_txch = index;
|
|
|
|
mac->dma_rxch = index;
|
|
|
|
|
|
|
|
/* We probe GMAC before XAUI, but the DMA interfaces are
|
|
|
|
* in XAUI, GMAC order.
|
|
|
|
*/
|
|
|
|
if (index < 4)
|
|
|
|
mac->dma_if = index + 2;
|
|
|
|
else
|
|
|
|
mac->dma_if = index - 4;
|
|
|
|
index++;
|
|
|
|
|
|
|
|
switch (pdev->device) {
|
|
|
|
case 0xa005:
|
|
|
|
mac->type = MAC_TYPE_GMAC;
|
|
|
|
break;
|
|
|
|
case 0xa006:
|
|
|
|
mac->type = MAC_TYPE_XAUI;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get mac addr from device tree */
|
|
|
|
if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
|
|
|
|
|
|
|
|
dev->open = pasemi_mac_open;
|
|
|
|
dev->stop = pasemi_mac_close;
|
|
|
|
dev->hard_start_xmit = pasemi_mac_start_tx;
|
|
|
|
dev->set_multicast_list = pasemi_mac_set_rx_mode;
|
|
|
|
|
2007-09-16 00:44:07 +04:00
|
|
|
err = pasemi_mac_map_regs(mac);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
mac->rx_status = &dma_status->rx_sta[mac->dma_rxch];
|
|
|
|
mac->tx_status = &dma_status->tx_sta[mac->dma_txch];
|
|
|
|
|
2007-05-08 09:47:49 +04:00
|
|
|
mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
|
|
|
|
|
2007-05-08 09:47:54 +04:00
|
|
|
/* Enable most messages by default */
|
|
|
|
mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
err = register_netdev(dev);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
|
|
|
|
err);
|
|
|
|
goto out;
|
2007-10-03 01:24:51 +04:00
|
|
|
} else if netif_msg_probe(mac)
|
2007-02-01 06:43:54 +03:00
|
|
|
printk(KERN_INFO "%s: PA Semi %s: intf %d, txch %d, rxch %d, "
|
2007-10-04 04:59:30 +04:00
|
|
|
"hw addr %s\n",
|
2007-02-01 06:43:54 +03:00
|
|
|
dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
|
|
|
|
mac->dma_if, mac->dma_txch, mac->dma_rxch,
|
2007-10-04 04:59:30 +04:00
|
|
|
print_mac(mac_buf, dev->dev_addr));
|
2007-02-01 06:43:54 +03:00
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
out:
|
2007-09-16 00:44:07 +04:00
|
|
|
if (mac->iob_pdev)
|
|
|
|
pci_dev_put(mac->iob_pdev);
|
|
|
|
if (mac->dma_pdev)
|
|
|
|
pci_dev_put(mac->dma_pdev);
|
|
|
|
if (mac->dma_regs)
|
|
|
|
iounmap(mac->dma_regs);
|
|
|
|
if (mac->iob_regs)
|
|
|
|
iounmap(mac->iob_regs);
|
|
|
|
if (mac->regs)
|
|
|
|
iounmap(mac->regs);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
free_netdev(dev);
|
|
|
|
out_disable_device:
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct net_device *netdev = pci_get_drvdata(pdev);
|
|
|
|
struct pasemi_mac *mac;
|
|
|
|
|
|
|
|
if (!netdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mac = netdev_priv(netdev);
|
|
|
|
|
|
|
|
unregister_netdev(netdev);
|
|
|
|
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
pci_dev_put(mac->dma_pdev);
|
|
|
|
pci_dev_put(mac->iob_pdev);
|
|
|
|
|
2007-09-16 00:44:07 +04:00
|
|
|
iounmap(mac->regs);
|
|
|
|
iounmap(mac->dma_regs);
|
|
|
|
iounmap(mac->iob_regs);
|
|
|
|
|
2007-02-01 06:43:54 +03:00
|
|
|
pci_set_drvdata(pdev, NULL);
|
|
|
|
free_netdev(netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_device_id pasemi_mac_pci_tbl[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
|
2007-05-12 23:57:36 +04:00
|
|
|
{ },
|
2007-02-01 06:43:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
|
|
|
|
|
|
|
|
static struct pci_driver pasemi_mac_driver = {
|
|
|
|
.name = "pasemi_mac",
|
|
|
|
.id_table = pasemi_mac_pci_tbl,
|
|
|
|
.probe = pasemi_mac_probe,
|
|
|
|
.remove = __devexit_p(pasemi_mac_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __exit pasemi_mac_cleanup_module(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&pasemi_mac_driver);
|
|
|
|
__iounmap(dma_status);
|
|
|
|
dma_status = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pasemi_mac_init_module(void)
|
|
|
|
{
|
|
|
|
return pci_register_driver(&pasemi_mac_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pasemi_mac_init_module);
|
|
|
|
module_exit(pasemi_mac_cleanup_module);
|