#define pr_fmt(fmt) …
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/list.h>
#include <linux/dma-mapping.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/skbuff_ref.h>
#include <linux/ethtool.h>
#include <linux/crc32.h>
#include <linux/random.h>
#include <linux/mii.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/mutex.h>
#include <linux/firmware.h>
#include <net/checksum.h>
#include <linux/atomic.h>
#include <asm/io.h>
#include <asm/byteorder.h>
#include <linux/uaccess.h>
#include <linux/jiffies.h>
#define CAS_NCPUS …
#define cas_skb_release(x) …
#define USE_HP_WORKAROUND
#define HP_WORKAROUND_DEFAULT …
#define CAS_HP_ALT_FIRMWARE …
#include "cassini.h"
#define USE_TX_COMPWB …
#define USE_CSMA_CD_PROTO …
#define USE_RX_BLANK …
#undef USE_ENTROPY_DEV
#undef USE_PCI_INTB
#undef USE_PCI_INTC
#undef USE_PCI_INTD
#undef USE_QOS
#undef USE_VPD_DEBUG
#define USE_PAGE_ORDER …
#define RX_DONT_BATCH …
#define RX_COPY_ALWAYS …
#define RX_COPY_MIN …
#undef RX_COUNT_BUFFERS
#define DRV_MODULE_NAME …
#define DRV_MODULE_VERSION …
#define DRV_MODULE_RELDATE …
#define CAS_DEF_MSG_ENABLE …
#define CAS_TX_TIMEOUT …
#define CAS_LINK_TIMEOUT …
#define CAS_LINK_FAST_TIMEOUT …
#define STOP_TRIES_PHY …
#define STOP_TRIES …
#define CAS_MIN_FRAME …
#define CAS_1000MB_MIN_FRAME …
#define CAS_MIN_MTU …
#define CAS_MAX_MTU …
#if 1
#else
#define CAS_RESET_MTU …
#define CAS_RESET_ALL …
#define CAS_RESET_SPARE …
#endif
static char version[] = …;
static int cassini_debug = …;
static int link_mode;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
MODULE_FIRMWARE(…) …;
module_param(cassini_debug, int, 0);
MODULE_PARM_DESC(…) …;
module_param(link_mode, int, 0);
MODULE_PARM_DESC(…) …;
#define DEFAULT_LINKDOWN_TIMEOUT …
static int linkdown_timeout = …;
module_param(linkdown_timeout, int, 0);
MODULE_PARM_DESC(…) …;
static int link_transition_timeout;
static u16 link_modes[] = …;
static const struct pci_device_id cas_pci_tbl[] = …;
MODULE_DEVICE_TABLE(pci, cas_pci_tbl);
static void cas_set_link_modes(struct cas *cp);
static inline void cas_lock_tx(struct cas *cp)
{ … }
#define cas_lock_all_save(cp, flags) …
static inline void cas_unlock_tx(struct cas *cp)
{ … }
#define cas_unlock_all_restore(cp, flags) …
static void cas_disable_irq(struct cas *cp, const int ring)
{ … }
static inline void cas_mask_intr(struct cas *cp)
{ … }
static void cas_enable_irq(struct cas *cp, const int ring)
{ … }
static inline void cas_unmask_intr(struct cas *cp)
{ … }
static inline void cas_entropy_gather(struct cas *cp)
{ … }
static inline void cas_entropy_reset(struct cas *cp)
{ … }
static u16 cas_phy_read(struct cas *cp, int reg)
{ … }
static int cas_phy_write(struct cas *cp, int reg, u16 val)
{ … }
static void cas_phy_powerup(struct cas *cp)
{ … }
static void cas_phy_powerdown(struct cas *cp)
{ … }
static int cas_page_free(struct cas *cp, cas_page_t *page)
{ … }
#ifdef RX_COUNT_BUFFERS
#define RX_USED_ADD …
#define RX_USED_SET …
#else
#define RX_USED_ADD(x, y) …
#define RX_USED_SET(x, y) …
#endif
static cas_page_t *cas_page_alloc(struct cas *cp, const gfp_t flags)
{ … }
static void cas_spare_init(struct cas *cp)
{ … }
static void cas_spare_free(struct cas *cp)
{ … }
static void cas_spare_recover(struct cas *cp, const gfp_t flags)
{ … }
static cas_page_t *cas_page_dequeue(struct cas *cp)
{ … }
static void cas_mif_poll(struct cas *cp, const int enable)
{ … }
static void cas_begin_auto_negotiation(struct cas *cp,
const struct ethtool_link_ksettings *ep)
{ … }
static int cas_reset_mii_phy(struct cas *cp)
{ … }
static void cas_saturn_firmware_init(struct cas *cp)
{ … }
static void cas_saturn_firmware_load(struct cas *cp)
{ … }
static void cas_phy_init(struct cas *cp)
{ … }
static int cas_pcs_link_check(struct cas *cp)
{ … }
static int cas_pcs_interrupt(struct net_device *dev,
struct cas *cp, u32 status)
{ … }
static int cas_txmac_interrupt(struct net_device *dev,
struct cas *cp, u32 status)
{ … }
static void cas_load_firmware(struct cas *cp, cas_hp_inst_t *firmware)
{ … }
static void cas_init_rx_dma(struct cas *cp)
{ … }
static inline void cas_rxc_init(struct cas_rx_comp *rxc)
{ … }
static inline cas_page_t *cas_page_spare(struct cas *cp, const int index)
{ … }
static cas_page_t *cas_page_swap(struct cas *cp, const int ring,
const int index)
{ … }
static void cas_clean_rxds(struct cas *cp)
{ … }
static void cas_clean_rxcs(struct cas *cp)
{ … }
#if 0
static int cas_rxmac_reset(struct cas *cp)
{
struct net_device *dev = cp->dev;
int limit;
u32 val;
writel(cp->mac_rx_cfg & ~MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG);
for (limit = 0; limit < STOP_TRIES; limit++) {
if (!(readl(cp->regs + REG_MAC_RX_CFG) & MAC_RX_CFG_EN))
break;
udelay(10);
}
if (limit == STOP_TRIES) {
netdev_err(dev, "RX MAC will not disable, resetting whole chip\n");
return 1;
}
writel(0, cp->regs + REG_RX_CFG);
for (limit = 0; limit < STOP_TRIES; limit++) {
if (!(readl(cp->regs + REG_RX_CFG) & RX_CFG_DMA_EN))
break;
udelay(10);
}
if (limit == STOP_TRIES) {
netdev_err(dev, "RX DMA will not disable, resetting whole chip\n");
return 1;
}
mdelay(5);
writel(SW_RESET_RX, cp->regs + REG_SW_RESET);
for (limit = 0; limit < STOP_TRIES; limit++) {
if (!(readl(cp->regs + REG_SW_RESET) & SW_RESET_RX))
break;
udelay(10);
}
if (limit == STOP_TRIES) {
netdev_err(dev, "RX reset command will not execute, resetting whole chip\n");
return 1;
}
cas_clean_rxds(cp);
cas_clean_rxcs(cp);
cas_init_rx_dma(cp);
val = readl(cp->regs + REG_RX_CFG);
writel(val | RX_CFG_DMA_EN, cp->regs + REG_RX_CFG);
writel(MAC_RX_FRAME_RECV, cp->regs + REG_MAC_RX_MASK);
val = readl(cp->regs + REG_MAC_RX_CFG);
writel(val | MAC_RX_CFG_EN, cp->regs + REG_MAC_RX_CFG);
return 0;
}
#endif
static int cas_rxmac_interrupt(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
static int cas_mac_interrupt(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
static inline int cas_mdio_link_not_up(struct cas *cp)
{ … }
static int cas_mii_link_check(struct cas *cp, const u16 bmsr)
{ … }
static int cas_mif_interrupt(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
static int cas_pci_interrupt(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
static int cas_abnormal_irq(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
#define CAS_TABORT(x) …
#define CAS_ROUND_PAGE(x) …
static inline int cas_calc_tabort(struct cas *cp, const unsigned long addr,
const int len)
{ … }
static inline void cas_tx_ringN(struct cas *cp, int ring, int limit)
{ … }
static void cas_tx(struct net_device *dev, struct cas *cp,
u32 status)
{ … }
static int cas_rx_process_pkt(struct cas *cp, struct cas_rx_comp *rxc,
int entry, const u64 *words,
struct sk_buff **skbref)
{ … }
static inline void cas_rx_flow_pkt(struct cas *cp, const u64 *words,
struct sk_buff *skb)
{ … }
static void cas_post_page(struct cas *cp, const int ring, const int index)
{ … }
static int cas_post_rxds_ringN(struct cas *cp, int ring, int num)
{ … }
static int cas_rx_ringN(struct cas *cp, int ring, int budget)
{ … }
static void cas_post_rxcs_ringN(struct net_device *dev,
struct cas *cp, int ring)
{ … }
#if defined(USE_PCI_INTC) || defined(USE_PCI_INTD)
static inline void cas_handle_irqN(struct net_device *dev,
struct cas *cp, const u32 status,
const int ring)
{
if (status & (INTR_RX_COMP_FULL_ALT | INTR_RX_COMP_AF_ALT))
cas_post_rxcs_ringN(dev, cp, ring);
}
static irqreturn_t cas_interruptN(int irq, void *dev_id)
{
struct net_device *dev = dev_id;
struct cas *cp = netdev_priv(dev);
unsigned long flags;
int ring = (irq == cp->pci_irq_INTC) ? 2 : 3;
u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(ring));
if (status == 0)
return IRQ_NONE;
spin_lock_irqsave(&cp->lock, flags);
if (status & INTR_RX_DONE_ALT) {
#ifdef USE_NAPI
cas_mask_intr(cp);
napi_schedule(&cp->napi);
#else
cas_rx_ringN(cp, ring, 0);
#endif
status &= ~INTR_RX_DONE_ALT;
}
if (status)
cas_handle_irqN(dev, cp, status, ring);
spin_unlock_irqrestore(&cp->lock, flags);
return IRQ_HANDLED;
}
#endif
#ifdef USE_PCI_INTB
static inline void cas_handle_irq1(struct cas *cp, const u32 status)
{
if (status & INTR_RX_BUF_UNAVAIL_1) {
cas_post_rxds_ringN(cp, 1, 0);
spin_lock(&cp->stat_lock[1]);
cp->net_stats[1].rx_dropped++;
spin_unlock(&cp->stat_lock[1]);
}
if (status & INTR_RX_BUF_AE_1)
cas_post_rxds_ringN(cp, 1, RX_DESC_RINGN_SIZE(1) -
RX_AE_FREEN_VAL(1));
if (status & (INTR_RX_COMP_AF | INTR_RX_COMP_FULL))
cas_post_rxcs_ringN(cp, 1);
}
static irqreturn_t cas_interrupt1(int irq, void *dev_id)
{
struct net_device *dev = dev_id;
struct cas *cp = netdev_priv(dev);
unsigned long flags;
u32 status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1));
if (status == 0)
return IRQ_NONE;
spin_lock_irqsave(&cp->lock, flags);
if (status & INTR_RX_DONE_ALT) {
#ifdef USE_NAPI
cas_mask_intr(cp);
napi_schedule(&cp->napi);
#else
cas_rx_ringN(cp, 1, 0);
#endif
status &= ~INTR_RX_DONE_ALT;
}
if (status)
cas_handle_irq1(cp, status);
spin_unlock_irqrestore(&cp->lock, flags);
return IRQ_HANDLED;
}
#endif
static inline void cas_handle_irq(struct net_device *dev,
struct cas *cp, const u32 status)
{ … }
static irqreturn_t cas_interrupt(int irq, void *dev_id)
{ … }
#ifdef USE_NAPI
static int cas_poll(struct napi_struct *napi, int budget)
{
struct cas *cp = container_of(napi, struct cas, napi);
struct net_device *dev = cp->dev;
int i, enable_intr, credits;
u32 status = readl(cp->regs + REG_INTR_STATUS);
unsigned long flags;
spin_lock_irqsave(&cp->lock, flags);
cas_tx(dev, cp, status);
spin_unlock_irqrestore(&cp->lock, flags);
enable_intr = 1;
credits = 0;
for (i = 0; i < N_RX_COMP_RINGS; i++) {
int j;
for (j = 0; j < N_RX_COMP_RINGS; j++) {
credits += cas_rx_ringN(cp, j, budget / N_RX_COMP_RINGS);
if (credits >= budget) {
enable_intr = 0;
goto rx_comp;
}
}
}
rx_comp:
spin_lock_irqsave(&cp->lock, flags);
if (status)
cas_handle_irq(dev, cp, status);
#ifdef USE_PCI_INTB
if (N_RX_COMP_RINGS > 1) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(1));
if (status)
cas_handle_irq1(dev, cp, status);
}
#endif
#ifdef USE_PCI_INTC
if (N_RX_COMP_RINGS > 2) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(2));
if (status)
cas_handle_irqN(dev, cp, status, 2);
}
#endif
#ifdef USE_PCI_INTD
if (N_RX_COMP_RINGS > 3) {
status = readl(cp->regs + REG_PLUS_INTRN_STATUS(3));
if (status)
cas_handle_irqN(dev, cp, status, 3);
}
#endif
spin_unlock_irqrestore(&cp->lock, flags);
if (enable_intr) {
napi_complete(napi);
cas_unmask_intr(cp);
}
return credits;
}
#endif
#ifdef CONFIG_NET_POLL_CONTROLLER
static void cas_netpoll(struct net_device *dev)
{ … }
#endif
static void cas_tx_timeout(struct net_device *dev, unsigned int txqueue)
{ … }
static inline int cas_intme(int ring, int entry)
{ … }
static void cas_write_txd(struct cas *cp, int ring, int entry,
dma_addr_t mapping, int len, u64 ctrl, int last)
{ … }
static inline void *tx_tiny_buf(struct cas *cp, const int ring,
const int entry)
{ … }
static inline dma_addr_t tx_tiny_map(struct cas *cp, const int ring,
const int entry, const int tentry)
{ … }
static inline int cas_xmit_tx_ringN(struct cas *cp, int ring,
struct sk_buff *skb)
{ … }
static netdev_tx_t cas_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ … }
static void cas_init_tx_dma(struct cas *cp)
{ … }
static inline void cas_init_dma(struct cas *cp)
{ … }
static void cas_process_mc_list(struct cas *cp)
{ … }
static u32 cas_setup_multicast(struct cas *cp)
{ … }
static void cas_clear_mac_err(struct cas *cp)
{ … }
static void cas_mac_reset(struct cas *cp)
{ … }
static void cas_init_mac(struct cas *cp)
{ … }
static void cas_init_pause_thresholds(struct cas *cp)
{ … }
static int cas_vpd_match(const void __iomem *p, const char *str)
{ … }
static int cas_get_vpd_info(struct cas *cp, unsigned char *dev_addr,
const int offset)
{ … }
static void cas_check_pci_invariants(struct cas *cp)
{ … }
static int cas_check_invariants(struct cas *cp)
{ … }
static inline void cas_start_dma(struct cas *cp)
{ … }
static void cas_read_pcs_link_mode(struct cas *cp, int *fd, int *spd,
int *pause)
{ … }
static void cas_read_mii_link_mode(struct cas *cp, int *fd, int *spd,
int *pause)
{ … }
static void cas_set_link_modes(struct cas *cp)
{ … }
static void cas_init_hw(struct cas *cp, int restart_link)
{ … }
static void cas_hard_reset(struct cas *cp)
{ … }
static void cas_global_reset(struct cas *cp, int blkflag)
{ … }
static void cas_reset(struct cas *cp, int blkflag)
{ … }
static void cas_shutdown(struct cas *cp)
{ … }
static int cas_change_mtu(struct net_device *dev, int new_mtu)
{ … }
static void cas_clean_txd(struct cas *cp, int ring)
{ … }
static inline void cas_free_rx_desc(struct cas *cp, int ring)
{ … }
static void cas_free_rxds(struct cas *cp)
{ … }
static void cas_clean_rings(struct cas *cp)
{ … }
static inline int cas_alloc_rx_desc(struct cas *cp, int ring)
{ … }
static int cas_alloc_rxds(struct cas *cp)
{ … }
static void cas_reset_task(struct work_struct *work)
{ … }
static void cas_link_timer(struct timer_list *t)
{ … }
static void cas_tx_tiny_free(struct cas *cp)
{ … }
static int cas_tx_tiny_alloc(struct cas *cp)
{ … }
static int cas_open(struct net_device *dev)
{ … }
static int cas_close(struct net_device *dev)
{ … }
static struct { … } ethtool_cassini_statnames[] = …;
#define CAS_NUM_STAT_KEYS …
static struct { … } ethtool_register_table[] = …;
#define CAS_REG_LEN …
#define CAS_MAX_REGS …
static void cas_read_regs(struct cas *cp, u8 *ptr, int len)
{ … }
static struct net_device_stats *cas_get_stats(struct net_device *dev)
{ … }
static void cas_set_multicast(struct net_device *dev)
{ … }
static void cas_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
{ … }
static int cas_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{ … }
static int cas_set_link_ksettings(struct net_device *dev,
const struct ethtool_link_ksettings *cmd)
{ … }
static int cas_nway_reset(struct net_device *dev)
{ … }
static u32 cas_get_link(struct net_device *dev)
{ … }
static u32 cas_get_msglevel(struct net_device *dev)
{ … }
static void cas_set_msglevel(struct net_device *dev, u32 value)
{ … }
static int cas_get_regs_len(struct net_device *dev)
{ … }
static void cas_get_regs(struct net_device *dev, struct ethtool_regs *regs,
void *p)
{ … }
static int cas_get_sset_count(struct net_device *dev, int sset)
{ … }
static void cas_get_strings(struct net_device *dev, u32 stringset, u8 *data)
{ … }
static void cas_get_ethtool_stats(struct net_device *dev,
struct ethtool_stats *estats, u64 *data)
{ … }
static const struct ethtool_ops cas_ethtool_ops = …;
static int cas_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ … }
static void cas_program_bridge(struct pci_dev *cas_pdev)
{ … }
static const struct net_device_ops cas_netdev_ops = …;
static int cas_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{ … }
static void cas_remove_one(struct pci_dev *pdev)
{ … }
static int __maybe_unused cas_suspend(struct device *dev_d)
{ … }
static int __maybe_unused cas_resume(struct device *dev_d)
{ … }
static SIMPLE_DEV_PM_OPS(cas_pm_ops, cas_suspend, cas_resume);
static struct pci_driver cas_driver = …;
static int __init cas_init(void)
{ … }
static void __exit cas_cleanup(void)
{ … }
module_init(…) …;
module_exit(cas_cleanup);