2007-07-05 11:11:16 +00:00
|
|
|
/*
|
|
|
|
* PS3 gelic network driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Sony Computer Entertainment Inc.
|
|
|
|
* Copyright 2006, 2007 Sony Corporation
|
|
|
|
*
|
|
|
|
* This file is based on: spider_net.c
|
|
|
|
*
|
|
|
|
* (C) Copyright IBM Corp. 2005
|
|
|
|
*
|
|
|
|
* Authors : Utz Bacher <utz.bacher@de.ibm.com>
|
|
|
|
* Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/if_vlan.h>
|
|
|
|
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <net/checksum.h>
|
|
|
|
#include <asm/firmware.h>
|
|
|
|
#include <asm/ps3.h>
|
|
|
|
#include <asm/lv1call.h>
|
|
|
|
|
|
|
|
#include "ps3_gelic_net.h"
|
|
|
|
|
|
|
|
#define DRV_NAME "Gelic Network Driver"
|
|
|
|
#define DRV_VERSION "1.0"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("SCE Inc.");
|
|
|
|
MODULE_DESCRIPTION("Gelic Network driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline struct device *ctodev(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
return &card->dev->core;
|
|
|
|
}
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline u64 bus_id(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
return card->dev->bus_id;
|
|
|
|
}
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline u64 dev_id(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
return card->dev->dev_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set irq_mask */
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
|
|
|
|
mask, 0);
|
|
|
|
if (status)
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"lv1_net_set_interrupt_mask failed %d\n", status);
|
|
|
|
return status;
|
|
|
|
}
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline void gelic_card_rx_irq_on(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_set_irq_mask(card, card->ghiintmask | GELIC_CARD_RXINT);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline void gelic_card_rx_irq_off(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_set_irq_mask(card, card->ghiintmask & ~GELIC_CARD_RXINT);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_get_status -- returns the status of a descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @descr: descriptor to look at
|
|
|
|
*
|
|
|
|
* returns the status as in the dmac_cmd_status field of the descriptor
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static enum gelic_descr_dma_status
|
|
|
|
gelic_descr_get_status(struct gelic_descr *descr)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_set_status -- sets the status of a descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @descr: descriptor to change
|
|
|
|
* @status: status to set in the descriptor
|
|
|
|
*
|
|
|
|
* changes the status to the specified value. Doesn't change other bits
|
|
|
|
* in the status
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_descr_set_status(struct gelic_descr *descr,
|
|
|
|
enum gelic_descr_dma_status status)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
descr->dmac_cmd_status = cpu_to_be32(status |
|
|
|
|
(be32_to_cpu(descr->dmac_cmd_status) &
|
|
|
|
~GELIC_DESCR_DMA_STAT_MASK));
|
2007-07-05 11:11:16 +00:00
|
|
|
/*
|
|
|
|
* dma_cmd_status field is used to indicate whether the descriptor
|
|
|
|
* is valid or not.
|
|
|
|
* Usually caller of this function wants to inform that to the
|
|
|
|
* hardware, so we assure here the hardware sees the change.
|
|
|
|
*/
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_free_chain - free descriptor chain
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @descr_in: address of desc
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_card_free_chain(struct gelic_card *card,
|
|
|
|
struct gelic_descr *descr_in)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr *descr;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
|
|
|
|
dma_unmap_single(ctodev(card), descr->bus_addr,
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
|
2007-07-05 11:11:16 +00:00
|
|
|
descr->bus_addr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_init_chain - links descriptor chain
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @chain: address of chain
|
|
|
|
* @start_descr: address of descriptor array
|
|
|
|
* @no: number of descriptors
|
|
|
|
*
|
|
|
|
* we manage a circular list that mirrors the hardware structure,
|
|
|
|
* except that the hardware uses bus addresses.
|
|
|
|
*
|
|
|
|
* returns 0 on success, <0 on failure
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_init_chain(struct gelic_card *card,
|
|
|
|
struct gelic_descr_chain *chain,
|
|
|
|
struct gelic_descr *start_descr, int no)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr *descr;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
descr = start_descr;
|
|
|
|
memset(descr, 0, sizeof(*descr) * no);
|
|
|
|
|
|
|
|
/* set up the hardware pointers in each descriptor */
|
|
|
|
for (i = 0; i < no; i++, descr++) {
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
|
2007-07-05 11:11:16 +00:00
|
|
|
descr->bus_addr =
|
|
|
|
dma_map_single(ctodev(card), descr,
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_DESCR_SIZE,
|
2007-07-05 11:11:16 +00:00
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
if (!descr->bus_addr)
|
|
|
|
goto iommu_error;
|
|
|
|
|
|
|
|
descr->next = descr + 1;
|
|
|
|
descr->prev = descr - 1;
|
|
|
|
}
|
|
|
|
/* make them as ring */
|
|
|
|
(descr - 1)->next = start_descr;
|
|
|
|
start_descr->prev = (descr - 1);
|
|
|
|
|
|
|
|
/* chain bus addr of hw descriptor */
|
|
|
|
descr = start_descr;
|
|
|
|
for (i = 0; i < no; i++, descr++) {
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chain->head = start_descr;
|
|
|
|
chain->tail = start_descr;
|
|
|
|
|
|
|
|
/* do not chain last hw descriptor */
|
|
|
|
(descr - 1)->next_descr_addr = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iommu_error:
|
|
|
|
for (i--, descr--; 0 <= i; i--, descr--)
|
|
|
|
if (descr->bus_addr)
|
|
|
|
dma_unmap_single(ctodev(card), descr->bus_addr,
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_DESCR_SIZE,
|
2007-07-05 11:11:16 +00:00
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_prepare_rx - reinitializes a rx descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @descr: descriptor to re-init
|
|
|
|
*
|
|
|
|
* return 0 on succes, <0 on failure
|
|
|
|
*
|
|
|
|
* allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
|
|
|
|
* Activate the descriptor state-wise
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_descr_prepare_rx(struct gelic_card *card,
|
|
|
|
struct gelic_descr *descr)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
unsigned int bufsize;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_info(ctodev(card), "%s: ERROR status \n", __func__);
|
2008-02-07 10:58:08 +00:00
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
/* we need to round up the buffer size to a multiple of 128 */
|
|
|
|
bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
|
|
|
|
|
|
|
|
/* and we need to have it 128 byte aligned, therefore we allocate a
|
|
|
|
* bit more */
|
|
|
|
descr->skb = netdev_alloc_skb(card->netdev,
|
|
|
|
bufsize + GELIC_NET_RXBUF_ALIGN - 1);
|
|
|
|
if (!descr->skb) {
|
|
|
|
descr->buf_addr = 0; /* tell DMAC don't touch memory */
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"%s:allocate skb failed !!\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->buf_size = cpu_to_be32(bufsize);
|
2007-07-05 11:11:16 +00:00
|
|
|
descr->dmac_cmd_status = 0;
|
|
|
|
descr->result_size = 0;
|
|
|
|
descr->valid_size = 0;
|
|
|
|
descr->data_error = 0;
|
|
|
|
|
|
|
|
offset = ((unsigned long)descr->skb->data) &
|
|
|
|
(GELIC_NET_RXBUF_ALIGN - 1);
|
|
|
|
if (offset)
|
|
|
|
skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
|
|
|
|
/* io-mmu-map the skb */
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
|
|
|
|
descr->skb->data,
|
|
|
|
GELIC_NET_MAX_MTU,
|
|
|
|
DMA_FROM_DEVICE));
|
2007-07-05 11:11:16 +00:00
|
|
|
if (!descr->buf_addr) {
|
|
|
|
dev_kfree_skb_any(descr->skb);
|
|
|
|
descr->skb = NULL;
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"%s:Could not iommu-map rx buffer\n", __func__);
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
|
2007-07-05 11:11:16 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
} else {
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
|
2007-07-05 11:11:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_release_rx_chain - free all skb of rx descr
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_card_release_rx_chain(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr *descr = card->rx_chain.head;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (descr->skb) {
|
|
|
|
dma_unmap_single(ctodev(card),
|
2008-02-07 10:57:54 +00:00
|
|
|
be32_to_cpu(descr->buf_addr),
|
2007-07-05 11:11:16 +00:00
|
|
|
descr->skb->len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
descr->buf_addr = 0;
|
|
|
|
dev_kfree_skb_any(descr->skb);
|
|
|
|
descr->skb = NULL;
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr,
|
|
|
|
GELIC_DESCR_DMA_NOT_IN_USE);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
descr = descr->next;
|
|
|
|
} while (descr != card->rx_chain.head);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
|
|
|
* fills all descriptors in the rx chain: allocates skbs
|
|
|
|
* and iommu-maps them.
|
2008-02-07 10:58:08 +00:00
|
|
|
* returns 0 on success, < 0 on failure
|
2007-07-05 11:11:16 +00:00
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_fill_rx_chain(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr *descr = card->rx_chain.head;
|
2007-07-05 11:11:16 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (!descr->skb) {
|
2008-02-07 10:58:08 +00:00
|
|
|
ret = gelic_descr_prepare_rx(card, descr);
|
2007-07-05 11:11:16 +00:00
|
|
|
if (ret)
|
|
|
|
goto rewind;
|
|
|
|
}
|
|
|
|
descr = descr->next;
|
|
|
|
} while (descr != card->rx_chain.head);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
rewind:
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_release_rx_chain(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
2008-02-07 10:58:08 +00:00
|
|
|
* returns 0 on success, < 0 on failure
|
2007-07-05 11:11:16 +00:00
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr_chain *chain;
|
2007-07-05 11:11:16 +00:00
|
|
|
int ret;
|
|
|
|
chain = &card->rx_chain;
|
2008-02-07 10:58:08 +00:00
|
|
|
ret = gelic_card_fill_rx_chain(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
chain->head = card->rx_top->prev; /* point to the last */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_release_tx - processes a used tx descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @descr: descriptor to release
|
|
|
|
*
|
|
|
|
* releases a used tx descriptor (unmapping, freeing of skb)
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_descr_release_tx(struct gelic_card *card,
|
|
|
|
struct gelic_descr *descr)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2007-08-31 13:22:32 +00:00
|
|
|
struct sk_buff *skb = descr->skb;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
#ifdef DEBUG
|
2008-02-07 10:57:54 +00:00
|
|
|
BUG_ON(!(be32_to_cpu(descr->data_status) &
|
2008-02-07 10:58:08 +00:00
|
|
|
(1 << GELIC_DESCR_TX_DMA_FRAME_TAIL)));
|
|
|
|
#endif
|
2008-02-07 10:57:54 +00:00
|
|
|
dma_unmap_single(ctodev(card),
|
|
|
|
be32_to_cpu(descr->buf_addr), skb->len, DMA_TO_DEVICE);
|
2007-08-31 13:22:32 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
descr->buf_addr = 0;
|
|
|
|
descr->buf_size = 0;
|
|
|
|
descr->next_descr_addr = 0;
|
|
|
|
descr->result_size = 0;
|
|
|
|
descr->valid_size = 0;
|
|
|
|
descr->data_status = 0;
|
|
|
|
descr->data_error = 0;
|
|
|
|
descr->skb = NULL;
|
|
|
|
|
|
|
|
/* set descr status */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_release_tx_chain - processes sent tx descriptors
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: adapter structure
|
|
|
|
* @stop: net_stop sequence
|
|
|
|
*
|
|
|
|
* releases the tx descriptors that gelic has finished with
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_descr_chain *tx_chain;
|
|
|
|
enum gelic_descr_dma_status status;
|
2007-07-05 11:11:16 +00:00
|
|
|
int release = 0;
|
|
|
|
|
|
|
|
for (tx_chain = &card->tx_chain;
|
|
|
|
tx_chain->head != tx_chain->tail && tx_chain->tail;
|
|
|
|
tx_chain->tail = tx_chain->tail->next) {
|
2008-02-07 10:58:08 +00:00
|
|
|
status = gelic_descr_get_status(tx_chain->tail);
|
2007-07-05 11:11:16 +00:00
|
|
|
switch (status) {
|
2008-02-07 10:58:08 +00:00
|
|
|
case GELIC_DESCR_DMA_RESPONSE_ERROR:
|
|
|
|
case GELIC_DESCR_DMA_PROTECTION_ERROR:
|
|
|
|
case GELIC_DESCR_DMA_FORCE_END:
|
2007-07-05 11:11:16 +00:00
|
|
|
if (printk_ratelimit())
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"%s: forcing end of tx descriptor " \
|
|
|
|
"with status %x\n",
|
|
|
|
__func__, status);
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.tx_dropped++;
|
2007-07-05 11:11:16 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
case GELIC_DESCR_DMA_COMPLETE:
|
2007-07-20 08:24:56 +00:00
|
|
|
if (tx_chain->tail->skb) {
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.tx_packets++;
|
|
|
|
card->netdev->stats.tx_bytes +=
|
2007-07-20 08:24:56 +00:00
|
|
|
tx_chain->tail->skb->len;
|
|
|
|
}
|
2007-07-05 11:11:16 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
case GELIC_DESCR_DMA_CARDOWNED:
|
2007-07-05 11:11:16 +00:00
|
|
|
/* pending tx request */
|
|
|
|
default:
|
2008-02-07 10:58:08 +00:00
|
|
|
/* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
|
2007-07-20 08:24:56 +00:00
|
|
|
if (!stop)
|
|
|
|
goto out;
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_release_tx(card, tx_chain->tail);
|
2007-07-20 08:24:56 +00:00
|
|
|
release ++;
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
out:
|
2007-08-31 13:22:32 +00:00
|
|
|
if (!stop && release)
|
2007-07-05 11:11:16 +00:00
|
|
|
netif_wake_queue(card->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_set_multi - sets multicast addresses and promisc flags
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* gelic_net_set_multi configures multicast addresses as needed for the
|
|
|
|
* netdev interface. It also sets up multicast, allmulti and promisc
|
|
|
|
* flags appropriately
|
|
|
|
*/
|
|
|
|
static void gelic_net_set_multi(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
struct dev_mc_list *mc;
|
|
|
|
unsigned int i;
|
|
|
|
uint8_t *p;
|
|
|
|
u64 addr;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* clear all multicast address */
|
|
|
|
status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
|
|
|
|
0, 1);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_remove_multicast_address failed %d\n",
|
|
|
|
status);
|
|
|
|
/* set broadcast address */
|
|
|
|
status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
|
|
|
|
GELIC_NET_BROADCAST_ADDR, 0);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_add_multicast_address failed, %d\n",
|
|
|
|
status);
|
|
|
|
|
|
|
|
if (netdev->flags & IFF_ALLMULTI
|
|
|
|
|| netdev->mc_count > GELIC_NET_MC_COUNT_MAX) { /* list max */
|
|
|
|
status = lv1_net_add_multicast_address(bus_id(card),
|
|
|
|
dev_id(card),
|
|
|
|
0, 1);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_add_multicast_address failed, %d\n",
|
|
|
|
status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set multicast address */
|
|
|
|
for (mc = netdev->mc_list; mc; mc = mc->next) {
|
|
|
|
addr = 0;
|
|
|
|
p = mc->dmi_addr;
|
|
|
|
for (i = 0; i < ETH_ALEN; i++) {
|
|
|
|
addr <<= 8;
|
|
|
|
addr |= *p++;
|
|
|
|
}
|
|
|
|
status = lv1_net_add_multicast_address(bus_id(card),
|
|
|
|
dev_id(card),
|
|
|
|
addr, 0);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_add_multicast_address failed, %d\n",
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_enable_rxdmac - enables the receive DMA controller
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
|
2007-07-05 11:11:16 +00:00
|
|
|
* in the GDADMACCNTR register
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline void gelic_card_enable_rxdmac(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
|
|
|
|
card->rx_chain.tail->bus_addr, 0);
|
|
|
|
if (status)
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"lv1_net_start_rx_dma failed, status=%d\n", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_disable_rxdmac - disables the receive DMA controller
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_disable_rxdmac terminates processing on the DMA controller by
|
2007-07-05 11:11:16 +00:00
|
|
|
* turing off DMA and issueing a force end
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline void gelic_card_disable_rxdmac(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* this hvc blocks until the DMA in progress really stopped */
|
|
|
|
status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card), 0);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_stop_rx_dma faild, %d\n", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_disable_txdmac - disables the transmit DMA controller
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_disable_txdmac terminates processing on the DMA controller by
|
2007-07-05 11:11:16 +00:00
|
|
|
* turing off DMA and issueing a force end
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static inline void gelic_card_disable_txdmac(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* this hvc blocks until the DMA in progress really stopped */
|
|
|
|
status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card), 0);
|
|
|
|
if (status)
|
|
|
|
dev_err(ctodev(card),
|
|
|
|
"lv1_net_stop_tx_dma faild, status=%d\n", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_stop - called upon ifconfig down
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* always returns 0
|
|
|
|
*/
|
|
|
|
static int gelic_net_stop(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00: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-03 23:41:36 +00:00
|
|
|
napi_disable(&card->napi);
|
2007-07-05 11:11:16 +00:00
|
|
|
netif_stop_queue(netdev);
|
|
|
|
|
|
|
|
/* turn off DMA, force end */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_disable_rxdmac(card);
|
|
|
|
gelic_card_disable_txdmac(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_set_irq_mask(card, 0);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
/* disconnect event port */
|
|
|
|
free_irq(card->netdev->irq, card->netdev);
|
|
|
|
ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq);
|
|
|
|
card->netdev->irq = NO_IRQ;
|
|
|
|
|
|
|
|
netif_carrier_off(netdev);
|
|
|
|
|
|
|
|
/* release chains */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_release_tx_chain(card, 1);
|
|
|
|
gelic_card_release_rx_chain(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_free_chain(card, card->tx_top);
|
|
|
|
gelic_card_free_chain(card, card->rx_top);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_get_next_tx_descr - returns the next available tx descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: device structure to get descriptor from
|
|
|
|
*
|
|
|
|
* returns the address of the next descriptor, or NULL if not available.
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static struct gelic_descr *
|
|
|
|
gelic_card_get_next_tx_descr(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
if (!card->tx_chain.head)
|
|
|
|
return NULL;
|
2007-08-31 13:22:32 +00:00
|
|
|
/* see if the next descriptor is free */
|
2007-07-05 11:11:16 +00:00
|
|
|
if (card->tx_chain.tail != card->tx_chain.head->next &&
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_get_status(card->tx_chain.head) ==
|
|
|
|
GELIC_DESCR_DMA_NOT_IN_USE)
|
2007-07-05 11:11:16 +00:00
|
|
|
return card->tx_chain.head;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_set_tx_cmdstat - sets the tx descriptor command field
|
2007-07-05 11:11:16 +00:00
|
|
|
* @descr: descriptor structure to fill out
|
|
|
|
* @skb: packet to consider
|
|
|
|
*
|
|
|
|
* fills out the command and status field of the descriptor structure,
|
|
|
|
* depending on hardware checksum settings. This function assumes a wmb()
|
|
|
|
* has executed before.
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
|
|
|
|
struct sk_buff *skb)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
if (skb->ip_summed != CHECKSUM_PARTIAL)
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->dmac_cmd_status =
|
2008-02-07 10:58:08 +00:00
|
|
|
cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
|
|
|
|
GELIC_DESCR_TX_DMA_FRAME_TAIL);
|
2007-07-05 11:11:16 +00:00
|
|
|
else {
|
|
|
|
/* is packet ip?
|
|
|
|
* if yes: tcp? udp? */
|
|
|
|
if (skb->protocol == htons(ETH_P_IP)) {
|
|
|
|
if (ip_hdr(skb)->protocol == IPPROTO_TCP)
|
|
|
|
descr->dmac_cmd_status =
|
2008-02-07 10:58:08 +00:00
|
|
|
cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
|
|
|
|
GELIC_DESCR_TX_DMA_FRAME_TAIL);
|
2007-08-31 13:22:32 +00:00
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
|
|
|
|
descr->dmac_cmd_status =
|
2008-02-07 10:58:08 +00:00
|
|
|
cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
|
|
|
|
GELIC_DESCR_TX_DMA_FRAME_TAIL);
|
2007-07-05 11:11:16 +00:00
|
|
|
else /*
|
|
|
|
* the stack should checksum non-tcp and non-udp
|
|
|
|
* packets on his own: NETIF_F_IP_CSUM
|
|
|
|
*/
|
|
|
|
descr->dmac_cmd_status =
|
2008-02-07 10:58:08 +00:00
|
|
|
cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
|
|
|
|
GELIC_DESCR_TX_DMA_FRAME_TAIL);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-31 13:22:32 +00:00
|
|
|
static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
|
|
|
|
unsigned short tag)
|
|
|
|
{
|
|
|
|
struct vlan_ethhdr *veth;
|
|
|
|
static unsigned int c;
|
|
|
|
|
|
|
|
if (skb_headroom(skb) < VLAN_HLEN) {
|
|
|
|
struct sk_buff *sk_tmp = skb;
|
|
|
|
pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
|
|
|
|
skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
|
|
|
|
if (!skb)
|
|
|
|
return NULL;
|
|
|
|
dev_kfree_skb_any(sk_tmp);
|
|
|
|
}
|
|
|
|
veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
|
|
|
|
|
|
|
|
/* Move the mac addresses to the top of buffer */
|
|
|
|
memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
|
|
|
|
|
|
|
|
veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
|
|
|
|
veth->h_vlan_TCI = htons(tag);
|
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_descr_prepare_tx - get dma address of skb_data
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @descr: descriptor structure
|
|
|
|
* @skb: packet to use
|
|
|
|
*
|
|
|
|
* returns 0 on success, <0 on failure.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_descr_prepare_tx(struct gelic_card *card,
|
|
|
|
struct gelic_descr *descr,
|
|
|
|
struct sk_buff *skb)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2007-08-31 13:22:32 +00:00
|
|
|
dma_addr_t buf;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
if (card->vlan_index != -1) {
|
2007-08-31 13:22:32 +00:00
|
|
|
struct sk_buff *skb_tmp;
|
|
|
|
skb_tmp = gelic_put_vlan_tag(skb,
|
|
|
|
card->vlan_id[card->vlan_index]);
|
|
|
|
if (!skb_tmp)
|
|
|
|
return -ENOMEM;
|
|
|
|
skb = skb_tmp;
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 13:22:32 +00:00
|
|
|
buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2007-08-31 13:22:32 +00:00
|
|
|
if (!buf) {
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_err(ctodev(card),
|
|
|
|
"dma map 2 failed (%p, %i). Dropping packet\n",
|
2007-08-31 13:22:32 +00:00
|
|
|
skb->data, skb->len);
|
2007-07-05 11:11:16 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->buf_addr = cpu_to_be32(buf);
|
|
|
|
descr->buf_size = cpu_to_be32(skb->len);
|
2007-08-31 13:22:32 +00:00
|
|
|
descr->skb = skb;
|
2007-07-05 11:11:16 +00:00
|
|
|
descr->data_status = 0;
|
2007-08-31 13:22:32 +00:00
|
|
|
descr->next_descr_addr = 0; /* terminate hw descr */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_tx_cmdstat(descr, skb);
|
2007-07-20 08:24:56 +00:00
|
|
|
|
|
|
|
/* bump free descriptor pointer */
|
2007-08-31 13:22:32 +00:00
|
|
|
card->tx_chain.head = descr->next;
|
2007-07-05 11:11:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_kick_txdma - enables TX DMA processing
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
* @descr: descriptor address to enable TX processing at
|
|
|
|
*
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_kick_txdma(struct gelic_card *card,
|
|
|
|
struct gelic_descr *descr)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2007-07-20 08:24:56 +00:00
|
|
|
int status = 0;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
if (card->tx_dma_progress)
|
|
|
|
return 0;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
|
2007-07-05 11:11:16 +00:00
|
|
|
card->tx_dma_progress = 1;
|
2007-08-31 13:25:09 +00:00
|
|
|
status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
|
|
|
|
descr->bus_addr, 0);
|
|
|
|
if (status)
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_info(ctodev(card), "lv1_net_start_txdma failed," \
|
2007-08-31 13:25:09 +00:00
|
|
|
"status=%d\n", status);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_xmit - transmits a frame over the device
|
|
|
|
* @skb: packet to send out
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* returns 0 on success, <0 on failure
|
|
|
|
*/
|
|
|
|
static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
|
|
|
struct gelic_descr *descr;
|
2007-07-05 11:11:16 +00:00
|
|
|
int result;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&card->tx_dma_lock, flags);
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_release_tx_chain(card, 0);
|
2007-07-20 08:24:56 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
descr = gelic_card_get_next_tx_descr(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
if (!descr) {
|
2007-07-20 08:24:56 +00:00
|
|
|
/*
|
|
|
|
* no more descriptors free
|
|
|
|
*/
|
2007-07-05 11:11:16 +00:00
|
|
|
netif_stop_queue(netdev);
|
|
|
|
spin_unlock_irqrestore(&card->tx_dma_lock, flags);
|
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
result = gelic_descr_prepare_tx(card, descr, skb);
|
2007-07-20 08:24:56 +00:00
|
|
|
if (result) {
|
|
|
|
/*
|
|
|
|
* DMA map failed. As chanses are that failure
|
|
|
|
* would continue, just release skb and return
|
|
|
|
*/
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.tx_dropped++;
|
2007-07-20 08:24:56 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
spin_unlock_irqrestore(&card->tx_dma_lock, flags);
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* link this prepared descriptor to previous one
|
|
|
|
* to achieve high performance
|
|
|
|
*/
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
|
2007-07-05 11:11:16 +00:00
|
|
|
/*
|
|
|
|
* as hardware descriptor is modified in the above lines,
|
|
|
|
* ensure that the hardware sees it
|
|
|
|
*/
|
|
|
|
wmb();
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_card_kick_txdma(card, descr)) {
|
2007-07-20 08:24:56 +00:00
|
|
|
/*
|
|
|
|
* kick failed.
|
|
|
|
* release descriptors which were just prepared
|
|
|
|
*/
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.tx_dropped++;
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_release_tx(card, descr);
|
|
|
|
gelic_descr_release_tx(card, descr->next);
|
2007-07-20 08:24:56 +00:00
|
|
|
card->tx_chain.tail = descr->next->next;
|
|
|
|
dev_info(ctodev(card), "%s: kick failure\n", __func__);
|
|
|
|
} else {
|
|
|
|
/* OK, DMA started/reserved */
|
|
|
|
netdev->trans_start = jiffies;
|
|
|
|
}
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&card->tx_dma_lock, flags);
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
|
|
|
|
* @descr: descriptor to process
|
|
|
|
* @card: card structure
|
|
|
|
*
|
|
|
|
* iommu-unmaps the skb, fills out skb structure and passes the data to the
|
|
|
|
* stack. The descriptor state is not changed.
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_net_pass_skb_up(struct gelic_descr *descr,
|
|
|
|
struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct net_device *netdev;
|
|
|
|
u32 data_status, data_error;
|
|
|
|
|
2008-02-07 10:57:54 +00:00
|
|
|
data_status = be32_to_cpu(descr->data_status);
|
|
|
|
data_error = be32_to_cpu(descr->data_error);
|
2007-07-05 11:11:16 +00:00
|
|
|
netdev = card->netdev;
|
|
|
|
/* unmap skb buffer */
|
|
|
|
skb = descr->skb;
|
2008-02-07 10:57:54 +00:00
|
|
|
dma_unmap_single(ctodev(card),
|
|
|
|
be32_to_cpu(descr->buf_addr), GELIC_NET_MAX_MTU,
|
2007-07-05 11:11:16 +00:00
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
2008-02-07 10:57:54 +00:00
|
|
|
skb_put(skb, descr->valid_size ?
|
|
|
|
be32_to_cpu(descr->valid_size) :
|
|
|
|
be32_to_cpu(descr->result_size));
|
2007-07-05 11:11:16 +00:00
|
|
|
if (!descr->valid_size)
|
|
|
|
dev_info(ctodev(card), "buffer full %x %x %x\n",
|
2008-02-07 10:57:54 +00:00
|
|
|
be32_to_cpu(descr->result_size),
|
|
|
|
be32_to_cpu(descr->buf_size),
|
|
|
|
be32_to_cpu(descr->dmac_cmd_status));
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
descr->skb = NULL;
|
|
|
|
/*
|
|
|
|
* the card put 2 bytes vlan tag in front
|
|
|
|
* of the ethernet frame
|
|
|
|
*/
|
|
|
|
skb_pull(skb, 2);
|
|
|
|
skb->protocol = eth_type_trans(skb, netdev);
|
|
|
|
|
|
|
|
/* checksum offload */
|
|
|
|
if (card->rx_csum) {
|
2008-02-07 10:58:08 +00:00
|
|
|
if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
|
|
|
|
(!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
|
2007-07-05 11:11:16 +00:00
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
else
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
} else
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
|
|
|
|
/* update netdevice statistics */
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.rx_packets++;
|
|
|
|
card->netdev->stats.rx_bytes += skb->len;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
/* pass skb up to stack */
|
|
|
|
netif_receive_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_decode_one_descr - processes an rx descriptor
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*
|
|
|
|
* returns 1 if a packet has been sent to the stack, otherwise 0
|
|
|
|
*
|
|
|
|
* processes an rx descriptor by iommu-unmapping the data buffer and passing
|
|
|
|
* the packet up to the stack
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_decode_one_descr(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
enum gelic_descr_dma_status status;
|
|
|
|
struct gelic_descr_chain *chain = &card->rx_chain;
|
|
|
|
struct gelic_descr *descr = chain->tail;
|
2007-07-05 11:11:16 +00:00
|
|
|
int dmac_chain_ended;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
status = gelic_descr_get_status(descr);
|
2007-07-05 11:11:16 +00:00
|
|
|
/* is this descriptor terminated with next_descr == NULL? */
|
|
|
|
dmac_chain_ended =
|
2008-02-07 10:57:54 +00:00
|
|
|
be32_to_cpu(descr->dmac_cmd_status) &
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_DESCR_RX_DMA_CHAIN_END;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status == GELIC_DESCR_DMA_CARDOWNED)
|
2007-07-05 11:11:16 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
|
|
|
|
(status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
|
|
|
|
(status == GELIC_DESCR_DMA_FORCE_END)) {
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
|
|
|
|
status);
|
2007-07-20 08:31:07 +00:00
|
|
|
card->netdev->stats.rx_dropped++;
|
2007-07-05 11:11:16 +00:00
|
|
|
goto refill;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
|
2007-07-20 08:39:25 +00:00
|
|
|
/*
|
|
|
|
* Buffer full would occur if and only if
|
|
|
|
* the frame length was longer than the size of this
|
|
|
|
* descriptor's buffer. If the frame length was equal
|
|
|
|
* to or shorter than buffer'size, FRAME_END condition
|
|
|
|
* would occur.
|
|
|
|
* Anyway this frame was longer than the MTU,
|
|
|
|
* just drop it.
|
|
|
|
*/
|
|
|
|
dev_info(ctodev(card), "overlength frame\n");
|
|
|
|
goto refill;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* descriptoers any other than FRAME_END here should
|
|
|
|
* be treated as error.
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status != GELIC_DESCR_DMA_FRAME_END) {
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_dbg(ctodev(card), "RX descriptor with state %x\n",
|
|
|
|
status);
|
|
|
|
goto refill;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok, we've got a packet in descr */
|
2007-07-20 08:39:25 +00:00
|
|
|
gelic_net_pass_skb_up(descr, card);
|
2007-07-05 11:11:16 +00:00
|
|
|
refill:
|
2007-07-20 08:39:25 +00:00
|
|
|
/*
|
|
|
|
* So that always DMAC can see the end
|
|
|
|
* of the descriptor chain to avoid
|
|
|
|
* from unwanted DMAC overrun.
|
|
|
|
*/
|
|
|
|
descr->next_descr_addr = 0;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
/* change the descriptor state: */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2007-07-20 08:39:25 +00:00
|
|
|
/*
|
|
|
|
* this call can fail, but for now, just leave this
|
|
|
|
* decriptor without skb
|
2007-07-05 11:11:16 +00:00
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_descr_prepare_rx(card, descr);
|
2007-07-20 08:39:25 +00:00
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
chain->head = descr;
|
|
|
|
chain->tail = descr->next;
|
2007-07-20 08:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set this descriptor the end of the chain.
|
|
|
|
*/
|
2008-02-07 10:57:54 +00:00
|
|
|
descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2007-07-20 08:39:25 +00:00
|
|
|
/*
|
|
|
|
* If dmac chain was met, DMAC stopped.
|
|
|
|
* thus re-enable it
|
|
|
|
*/
|
2007-07-05 11:11:16 +00:00
|
|
|
if (dmac_chain_ended) {
|
2007-07-20 08:35:54 +00:00
|
|
|
card->rx_dma_restart_required = 1;
|
|
|
|
dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_poll - NAPI poll function called by the stack to return packets
|
|
|
|
* @netdev: interface device structure
|
|
|
|
* @budget: number of packets we can pass to the stack at most
|
|
|
|
*
|
|
|
|
* returns 0 if no more packets available to the driver/stack. Returns 1,
|
|
|
|
* if the quota is exceeded, but the driver has still packets.
|
|
|
|
*
|
|
|
|
*/
|
[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-03 23:41:36 +00:00
|
|
|
static int gelic_net_poll(struct napi_struct *napi, int budget)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = container_of(napi, struct gelic_card, napi);
|
[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-03 23:41:36 +00:00
|
|
|
struct net_device *netdev = card->netdev;
|
|
|
|
int packets_done = 0;
|
2007-07-05 11:11:16 +00: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-03 23:41:36 +00:00
|
|
|
while (packets_done < budget) {
|
2008-02-07 10:58:08 +00:00
|
|
|
if (!gelic_card_decode_one_descr(card))
|
2007-07-05 11:11:16 +00:00
|
|
|
break;
|
[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-03 23:41:36 +00:00
|
|
|
|
|
|
|
packets_done++;
|
2007-07-05 11:11:16 +00: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-03 23:41:36 +00:00
|
|
|
|
|
|
|
if (packets_done < budget) {
|
|
|
|
netif_rx_complete(netdev, napi);
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_rx_irq_on(card);
|
[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-03 23:41:36 +00:00
|
|
|
}
|
|
|
|
return packets_done;
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* gelic_net_change_mtu - changes the MTU of an interface
|
|
|
|
* @netdev: interface device structure
|
|
|
|
* @new_mtu: new MTU value
|
|
|
|
*
|
|
|
|
* returns 0 on success, <0 on failure
|
|
|
|
*/
|
|
|
|
static int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
|
|
|
|
{
|
|
|
|
/* no need to re-alloc skbs or so -- the max mtu is about 2.3k
|
|
|
|
* and mtu is outbound only anyway */
|
|
|
|
if ((new_mtu < GELIC_NET_MIN_MTU) ||
|
|
|
|
(new_mtu > GELIC_NET_MAX_MTU)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
netdev->mtu = new_mtu;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_interrupt - event handler for gelic_net
|
2007-07-05 11:11:16 +00:00
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct net_device *netdev = ptr;
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
u64 status;
|
|
|
|
|
|
|
|
status = card->irq_status;
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2007-07-20 08:35:54 +00:00
|
|
|
if (card->rx_dma_restart_required) {
|
|
|
|
card->rx_dma_restart_required = 0;
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_enable_rxdmac(card);
|
2007-07-20 08:35:54 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status & GELIC_CARD_RXINT) {
|
|
|
|
gelic_card_rx_irq_off(card);
|
[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-03 23:41:36 +00:00
|
|
|
netif_rx_schedule(netdev, &card->napi);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status & GELIC_CARD_TXINT) {
|
2007-07-05 11:11:16 +00:00
|
|
|
spin_lock_irqsave(&card->tx_dma_lock, flags);
|
|
|
|
card->tx_dma_progress = 0;
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_release_tx_chain(card, 0);
|
2007-07-20 08:24:56 +00:00
|
|
|
/* kick outstanding tx descriptor if any */
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_kick_txdma(card, card->tx_chain.tail);
|
2007-07-05 11:11:16 +00:00
|
|
|
spin_unlock_irqrestore(&card->tx_dma_lock, flags);
|
|
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
/**
|
|
|
|
* gelic_net_poll_controller - artificial interrupt for netconsole etc.
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* see Documentation/networking/netconsole.txt
|
|
|
|
*/
|
|
|
|
static void gelic_net_poll_controller(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_set_irq_mask(card, 0);
|
|
|
|
gelic_card_interrupt(netdev->irq, netdev);
|
|
|
|
gelic_card_set_irq_mask(card, card->ghiintmask);
|
2007-07-05 11:11:16 +00:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_POLL_CONTROLLER */
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_card_open - open device and map dma region
|
2007-07-05 11:11:16 +00:00
|
|
|
* @card: card structure
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_card_open(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = ps3_sb_event_receive_port_setup(card->dev, PS3_BINDING_CPU_ANY,
|
|
|
|
&card->netdev->irq);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_info(ctodev(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
"%s:%d: recieve_port_setup failed (%d)\n",
|
2007-07-05 11:11:16 +00:00
|
|
|
__func__, __LINE__, result);
|
|
|
|
result = -EPERM;
|
|
|
|
goto fail_alloc_irq;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
result = request_irq(card->netdev->irq, gelic_card_interrupt,
|
2007-07-20 08:33:02 +00:00
|
|
|
IRQF_DISABLED, card->netdev->name, card->netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n",
|
|
|
|
__func__, __LINE__, result);
|
|
|
|
goto fail_request_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_request_irq:
|
|
|
|
ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq);
|
|
|
|
card->netdev->irq = NO_IRQ;
|
|
|
|
fail_alloc_irq:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_open - called upon ifonfig up
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* returns 0 on success, <0 on failure
|
|
|
|
*
|
|
|
|
* gelic_net_open allocates all the descriptors and memory needed for
|
|
|
|
* operation, sets up multicast list and enables interrupts
|
|
|
|
*/
|
|
|
|
static int gelic_net_open(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
dev_dbg(ctodev(card), " -> %s:%d\n", __func__, __LINE__);
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_open(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_card_init_chain(card, &card->tx_chain,
|
|
|
|
card->descr, GELIC_NET_TX_DESCRIPTORS))
|
2007-07-05 11:11:16 +00:00
|
|
|
goto alloc_tx_failed;
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_card_init_chain(card, &card->rx_chain,
|
|
|
|
card->descr + GELIC_NET_TX_DESCRIPTORS,
|
|
|
|
GELIC_NET_RX_DESCRIPTORS))
|
2007-07-05 11:11:16 +00:00
|
|
|
goto alloc_rx_failed;
|
|
|
|
|
|
|
|
/* head of chain */
|
|
|
|
card->tx_top = card->tx_chain.head;
|
|
|
|
card->rx_top = card->rx_chain.head;
|
|
|
|
dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
|
2008-02-07 10:58:08 +00:00
|
|
|
card->rx_top, card->tx_top, sizeof(struct gelic_descr),
|
2007-07-05 11:11:16 +00:00
|
|
|
GELIC_NET_RX_DESCRIPTORS);
|
|
|
|
/* allocate rx skbs */
|
2008-02-07 10:58:08 +00:00
|
|
|
if (gelic_card_alloc_rx_skbs(card))
|
2007-07-05 11:11:16 +00:00
|
|
|
goto alloc_skbs_failed;
|
|
|
|
|
[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-03 23:41:36 +00:00
|
|
|
napi_enable(&card->napi);
|
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
card->tx_dma_progress = 0;
|
2008-02-07 10:58:08 +00:00
|
|
|
card->ghiintmask = GELIC_CARD_RXINT | GELIC_CARD_TXINT;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_set_irq_mask(card, card->ghiintmask);
|
|
|
|
gelic_card_enable_rxdmac(card);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
netif_start_queue(netdev);
|
|
|
|
netif_carrier_on(netdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
alloc_skbs_failed:
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_free_chain(card, card->rx_top);
|
2007-07-05 11:11:16 +00:00
|
|
|
alloc_rx_failed:
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_card_free_chain(card, card->tx_top);
|
2007-07-05 11:11:16 +00:00
|
|
|
alloc_tx_failed:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_net_get_drvinfo(struct net_device *netdev,
|
|
|
|
struct ethtool_drvinfo *info)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
|
|
|
|
strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_ether_get_settings(struct net_device *netdev,
|
|
|
|
struct ethtool_cmd *cmd)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
int status;
|
|
|
|
u64 v1, v2;
|
|
|
|
int speed, duplex;
|
|
|
|
|
|
|
|
speed = duplex = -1;
|
|
|
|
status = lv1_net_control(bus_id(card), dev_id(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_LV1_GET_ETH_PORT_STATUS,
|
|
|
|
GELIC_LV1_VLAN_TX_ETHERNET, 0, 0,
|
|
|
|
&v1, &v2);
|
2007-07-05 11:11:16 +00:00
|
|
|
if (status) {
|
|
|
|
/* link down */
|
|
|
|
} else {
|
2008-02-07 10:58:08 +00:00
|
|
|
if (v1 & GELIC_LV1_ETHER_FULL_DUPLEX) {
|
2007-07-05 11:11:16 +00:00
|
|
|
duplex = DUPLEX_FULL;
|
|
|
|
} else {
|
|
|
|
duplex = DUPLEX_HALF;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (v1 & GELIC_LV1_ETHER_SPEED_10) {
|
2007-07-05 11:11:16 +00:00
|
|
|
speed = SPEED_10;
|
2008-02-07 10:58:08 +00:00
|
|
|
} else if (v1 & GELIC_LV1_ETHER_SPEED_100) {
|
2007-07-05 11:11:16 +00:00
|
|
|
speed = SPEED_100;
|
2008-02-07 10:58:08 +00:00
|
|
|
} else if (v1 & GELIC_LV1_ETHER_SPEED_1000) {
|
2007-07-05 11:11:16 +00:00
|
|
|
speed = SPEED_1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg |
|
|
|
|
SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
|
|
|
|
SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
|
|
|
|
SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full;
|
|
|
|
cmd->advertising = cmd->supported;
|
|
|
|
cmd->speed = speed;
|
|
|
|
cmd->duplex = duplex;
|
|
|
|
cmd->autoneg = AUTONEG_ENABLE; /* always enabled */
|
|
|
|
cmd->port = PORT_TP;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
static u32 gelic_ether_get_link(struct net_device *netdev)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
int status;
|
|
|
|
u64 v1, v2;
|
|
|
|
int link;
|
|
|
|
|
|
|
|
status = lv1_net_control(bus_id(card), dev_id(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_LV1_GET_ETH_PORT_STATUS,
|
|
|
|
GELIC_LV1_VLAN_TX_ETHERNET, 0, 0,
|
|
|
|
&v1, &v2);
|
2007-07-05 11:11:16 +00:00
|
|
|
if (status)
|
|
|
|
return 0; /* link down */
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (v1 & GELIC_LV1_ETHER_LINK_UP)
|
2007-07-05 11:11:16 +00:00
|
|
|
link = 1;
|
|
|
|
else
|
|
|
|
link = 0;
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gelic_net_nway_reset(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
if (netif_running(netdev)) {
|
|
|
|
gelic_net_stop(netdev);
|
|
|
|
gelic_net_open(netdev);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 gelic_net_get_tx_csum(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
return (netdev->features & NETIF_F_IP_CSUM) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gelic_net_set_tx_csum(struct net_device *netdev, u32 data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
netdev->features |= NETIF_F_IP_CSUM;
|
|
|
|
else
|
|
|
|
netdev->features &= ~NETIF_F_IP_CSUM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 gelic_net_get_rx_csum(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
return card->rx_csum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gelic_net_set_rx_csum(struct net_device *netdev, u32 data)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = netdev_priv(netdev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
card->rx_csum = data;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ethtool_ops gelic_net_ethtool_ops = {
|
|
|
|
.get_drvinfo = gelic_net_get_drvinfo,
|
2008-02-07 10:58:08 +00:00
|
|
|
.get_settings = gelic_ether_get_settings,
|
|
|
|
.get_link = gelic_ether_get_link,
|
2007-07-05 11:11:16 +00:00
|
|
|
.nway_reset = gelic_net_nway_reset,
|
|
|
|
.get_tx_csum = gelic_net_get_tx_csum,
|
|
|
|
.set_tx_csum = gelic_net_set_tx_csum,
|
|
|
|
.get_rx_csum = gelic_net_get_rx_csum,
|
|
|
|
.set_rx_csum = gelic_net_set_rx_csum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
|
|
|
|
* function (to be called not under interrupt status)
|
|
|
|
* @work: work is context of tx timout task
|
|
|
|
*
|
|
|
|
* called as task when tx hangs, resets interface (if interface is up)
|
|
|
|
*/
|
|
|
|
static void gelic_net_tx_timeout_task(struct work_struct *work)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card =
|
|
|
|
container_of(work, struct gelic_card, tx_timeout_task);
|
2007-07-05 11:11:16 +00:00
|
|
|
struct net_device *netdev = card->netdev;
|
|
|
|
|
|
|
|
dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__);
|
|
|
|
|
|
|
|
if (!(netdev->flags & IFF_UP))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
netif_device_detach(netdev);
|
|
|
|
gelic_net_stop(netdev);
|
|
|
|
|
|
|
|
gelic_net_open(netdev);
|
|
|
|
netif_device_attach(netdev);
|
|
|
|
|
|
|
|
out:
|
|
|
|
atomic_dec(&card->tx_timeout_task_counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
|
|
|
|
* @netdev: interface device structure
|
|
|
|
*
|
|
|
|
* called, if tx hangs. Schedules a task that resets the interface
|
|
|
|
*/
|
|
|
|
static void gelic_net_tx_timeout(struct net_device *netdev)
|
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card;
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
card = netdev_priv(netdev);
|
|
|
|
atomic_inc(&card->tx_timeout_task_counter);
|
|
|
|
if (netdev->flags & IFF_UP)
|
|
|
|
schedule_work(&card->tx_timeout_task);
|
|
|
|
else
|
|
|
|
atomic_dec(&card->tx_timeout_task_counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_ether_setup_netdev_ops - initialization of net_device operations
|
2007-07-05 11:11:16 +00:00
|
|
|
* @netdev: net_device structure
|
|
|
|
*
|
|
|
|
* fills out function pointers in the net_device structure
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static void gelic_ether_setup_netdev_ops(struct net_device *netdev)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
netdev->open = &gelic_net_open;
|
|
|
|
netdev->stop = &gelic_net_stop;
|
|
|
|
netdev->hard_start_xmit = &gelic_net_xmit;
|
|
|
|
netdev->set_multicast_list = &gelic_net_set_multi;
|
|
|
|
netdev->change_mtu = &gelic_net_change_mtu;
|
|
|
|
/* tx watchdog */
|
|
|
|
netdev->tx_timeout = &gelic_net_tx_timeout;
|
|
|
|
netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
|
|
|
|
netdev->ethtool_ops = &gelic_net_ethtool_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gelic_net_setup_netdev - initialization of net_device
|
|
|
|
* @card: card structure
|
|
|
|
*
|
|
|
|
* Returns 0 on success or <0 on failure
|
|
|
|
*
|
|
|
|
* gelic_net_setup_netdev initializes the net_device structure
|
|
|
|
**/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int gelic_net_setup_netdev(struct gelic_card *card)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
struct net_device *netdev = card->netdev;
|
|
|
|
struct sockaddr addr;
|
|
|
|
unsigned int i;
|
|
|
|
int status;
|
|
|
|
u64 v1, v2;
|
2007-10-04 00:59:30 +00:00
|
|
|
DECLARE_MAC_BUF(mac);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
SET_NETDEV_DEV(netdev, &card->dev->core);
|
|
|
|
spin_lock_init(&card->tx_dma_lock);
|
|
|
|
|
|
|
|
card->rx_csum = GELIC_NET_RX_CSUM_DEFAULT;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
gelic_ether_setup_netdev_ops(netdev);
|
2007-07-05 11:11:16 +00: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-03 23:41:36 +00:00
|
|
|
netif_napi_add(netdev, &card->napi,
|
|
|
|
gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
|
|
|
|
|
2007-07-05 11:11:16 +00:00
|
|
|
netdev->features = NETIF_F_IP_CSUM;
|
|
|
|
|
|
|
|
status = lv1_net_control(bus_id(card), dev_id(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_LV1_GET_MAC_ADDRESS,
|
2007-07-05 11:11:16 +00:00
|
|
|
0, 0, 0, &v1, &v2);
|
|
|
|
if (status || !is_valid_ether_addr((u8 *)&v1)) {
|
|
|
|
dev_info(ctodev(card),
|
|
|
|
"%s:lv1_net_control GET_MAC_ADDR failed %d\n",
|
|
|
|
__func__, status);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
v1 <<= 16;
|
|
|
|
memcpy(addr.sa_data, &v1, ETH_ALEN);
|
|
|
|
memcpy(netdev->dev_addr, addr.sa_data, ETH_ALEN);
|
2007-10-04 00:59:30 +00:00
|
|
|
dev_info(ctodev(card), "MAC addr %s\n",
|
|
|
|
print_mac(mac, netdev->dev_addr));
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
card->vlan_index = -1; /* no vlan */
|
|
|
|
for (i = 0; i < GELIC_NET_VLAN_MAX; i++) {
|
|
|
|
status = lv1_net_control(bus_id(card), dev_id(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
GELIC_LV1_GET_VLAN_ID,
|
2007-07-05 11:11:16 +00:00
|
|
|
i + 1, /* index; one based */
|
|
|
|
0, 0, &v1, &v2);
|
2008-02-07 10:58:08 +00:00
|
|
|
if (status == LV1_NO_ENTRY) {
|
2007-07-05 11:11:16 +00:00
|
|
|
dev_dbg(ctodev(card),
|
|
|
|
"GELIC_VLAN_ID no entry:%d, VLAN disabled\n",
|
|
|
|
status);
|
|
|
|
card->vlan_id[i] = 0;
|
|
|
|
} else if (status) {
|
|
|
|
dev_dbg(ctodev(card),
|
2008-02-07 10:58:08 +00:00
|
|
|
"%s:get vlan id faild, status=%d\n",
|
2007-07-05 11:11:16 +00:00
|
|
|
__func__, status);
|
|
|
|
card->vlan_id[i] = 0;
|
|
|
|
} else {
|
|
|
|
card->vlan_id[i] = (u32)v1;
|
|
|
|
dev_dbg(ctodev(card), "vlan_id:%d, %lx\n", i, v1);
|
|
|
|
}
|
|
|
|
}
|
2007-08-31 13:22:32 +00:00
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
if (card->vlan_id[GELIC_LV1_VLAN_TX_ETHERNET - 1]) {
|
|
|
|
card->vlan_index = GELIC_LV1_VLAN_TX_ETHERNET - 1;
|
2007-08-31 13:22:32 +00:00
|
|
|
netdev->hard_header_len += VLAN_HLEN;
|
|
|
|
}
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
status = register_netdev(netdev);
|
|
|
|
if (status) {
|
|
|
|
dev_err(ctodev(card), "%s:Couldn't register net_device: %d\n",
|
|
|
|
__func__, status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-07 10:58:08 +00:00
|
|
|
* gelic_alloc_card_net - allocates net_device and card structure
|
2007-07-05 11:11:16 +00:00
|
|
|
*
|
|
|
|
* returns the card structure or NULL in case of errors
|
|
|
|
*
|
|
|
|
* the card and net_device structures are linked to each other
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static struct gelic_card *gelic_alloc_card_net(void)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
|
|
|
struct net_device *netdev;
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card;
|
2007-07-05 11:11:16 +00:00
|
|
|
size_t alloc_size;
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
alloc_size = sizeof(*card) +
|
|
|
|
sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
|
|
|
|
sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS;
|
2007-07-05 11:11:16 +00:00
|
|
|
/*
|
|
|
|
* we assume private data is allocated 32 bytes (or more) aligned
|
2008-02-07 10:58:08 +00:00
|
|
|
* so that gelic_descr should be 32 bytes aligned.
|
2007-07-05 11:11:16 +00:00
|
|
|
* Current alloc_etherdev() does do it because NETDEV_ALIGN
|
|
|
|
* is 32.
|
|
|
|
* check this assumption here.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(NETDEV_ALIGN < 32);
|
2008-02-07 10:58:08 +00:00
|
|
|
BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
|
|
|
|
BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
netdev = alloc_etherdev(alloc_size);
|
|
|
|
if (!netdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
card = netdev_priv(netdev);
|
|
|
|
card->netdev = netdev;
|
|
|
|
INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
|
|
|
|
init_waitqueue_head(&card->waitq);
|
|
|
|
atomic_set(&card->tx_timeout_task_counter, 0);
|
|
|
|
|
|
|
|
return card;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ps3_gelic_driver_probe - add a device to the control of this driver
|
|
|
|
*/
|
2008-02-07 10:58:08 +00:00
|
|
|
static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = gelic_alloc_card_net();
|
2007-07-05 11:11:16 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
if (!card) {
|
|
|
|
dev_info(&dev->core, "gelic_net_alloc_card failed\n");
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto fail_alloc_card;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps3_system_bus_set_driver_data(dev, card);
|
|
|
|
card->dev = dev;
|
|
|
|
|
|
|
|
result = ps3_open_hv_device(dev);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_dbg(&dev->core, "ps3_open_hv_device failed\n");
|
|
|
|
goto fail_open;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ps3_dma_region_create(dev->d_region);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_dbg(&dev->core, "ps3_dma_region_create failed(%d)\n",
|
|
|
|
result);
|
|
|
|
BUG_ON("check region type");
|
|
|
|
goto fail_dma_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = lv1_net_set_interrupt_status_indicator(bus_id(card),
|
|
|
|
dev_id(card),
|
|
|
|
ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_dbg(&dev->core,
|
|
|
|
"lv1_net_set_interrupt_status_indicator failed: %s\n",
|
|
|
|
ps3_result(result));
|
|
|
|
result = -EIO;
|
|
|
|
goto fail_status_indicator;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = gelic_net_setup_netdev(card);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
|
|
|
|
"(%d)\n", __func__, __LINE__, result);
|
|
|
|
goto fail_setup_netdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_setup_netdev:
|
|
|
|
lv1_net_set_interrupt_status_indicator(bus_id(card),
|
2008-02-07 10:57:41 +00:00
|
|
|
dev_id(card),
|
2007-07-05 11:11:16 +00:00
|
|
|
0 , 0);
|
|
|
|
fail_status_indicator:
|
|
|
|
ps3_dma_region_free(dev->d_region);
|
|
|
|
fail_dma_region:
|
|
|
|
ps3_close_hv_device(dev);
|
|
|
|
fail_open:
|
|
|
|
ps3_system_bus_set_driver_data(dev, NULL);
|
|
|
|
free_netdev(card->netdev);
|
|
|
|
fail_alloc_card:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ps3_gelic_driver_remove - remove a device from the control of this driver
|
|
|
|
*/
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
|
2007-07-05 11:11:16 +00:00
|
|
|
{
|
2008-02-07 10:58:08 +00:00
|
|
|
struct gelic_card *card = ps3_system_bus_get_driver_data(dev);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
wait_event(card->waitq,
|
|
|
|
atomic_read(&card->tx_timeout_task_counter) == 0);
|
|
|
|
|
|
|
|
lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
|
|
|
|
0 , 0);
|
|
|
|
|
|
|
|
unregister_netdev(card->netdev);
|
|
|
|
free_netdev(card->netdev);
|
|
|
|
|
|
|
|
ps3_system_bus_set_driver_data(dev, NULL);
|
|
|
|
|
|
|
|
ps3_dma_region_free(dev->d_region);
|
|
|
|
|
|
|
|
ps3_close_hv_device(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ps3_system_bus_driver ps3_gelic_driver = {
|
|
|
|
.match_id = PS3_MATCH_ID_GELIC,
|
|
|
|
.probe = ps3_gelic_driver_probe,
|
|
|
|
.remove = ps3_gelic_driver_remove,
|
|
|
|
.shutdown = ps3_gelic_driver_remove,
|
|
|
|
.core.name = "ps3_gelic_driver",
|
|
|
|
.core.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ps3_gelic_driver_init (void)
|
|
|
|
{
|
|
|
|
return firmware_has_feature(FW_FEATURE_PS3_LV1)
|
|
|
|
? ps3_system_bus_driver_register(&ps3_gelic_driver)
|
|
|
|
: -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ps3_gelic_driver_exit (void)
|
|
|
|
{
|
|
|
|
ps3_system_bus_driver_unregister(&ps3_gelic_driver);
|
|
|
|
}
|
|
|
|
|
2008-02-07 10:58:08 +00:00
|
|
|
module_init(ps3_gelic_driver_init);
|
|
|
|
module_exit(ps3_gelic_driver_exit);
|
2007-07-05 11:11:16 +00:00
|
|
|
|
|
|
|
MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);
|
|
|
|
|