#include <linux/netdevice.h>
#include <linux/fddidevice.h>
#include <linux/skbuff.h>
+#include <linux/bitops.h>
#include <asm/byteorder.h>
-#include <asm/bitops.h>
#include <asm/io.h>
#include <asm/uaccess.h>
extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
extern void mac_drv_clear_rx_queue(struct s_smc *smc);
extern void enable_tx_irq(struct s_smc *smc, u_short queue);
-extern void mac_drv_clear_txd(struct s_smc *smc);
static struct pci_device_id skfddi_pci_tbl[] = {
{ PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
#define PRINTK(s, args...)
#endif // DRIVERDEBUG
-#define PRIV(dev) (&(((struct s_smc *)dev->priv)->os))
-
/*
* =================
* = skfp_init_one =
{
struct net_device *dev;
struct s_smc *smc; /* board pointer */
- unsigned long port, len;
+ void __iomem *mem;
int err;
PRINTK(KERN_INFO "entering skfp_init_one\n");
printk("%s\n", boot_msg);
err = pci_enable_device(pdev);
+ if (err)
+ return err;
+
+ err = pci_request_regions(pdev, "skfddi");
if (err)
goto err_out1;
+ pci_set_master(pdev);
#ifdef MEM_MAPPED_IO
if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
printk(KERN_ERR "skfp: region is not an MMIO resource\n");
err = -EIO;
- goto err_out1;
+ goto err_out2;
}
- port = pci_resource_start(pdev, 0);
- len = pci_resource_len(pdev, 0);
- if (len < 0x4000) {
- printk(KERN_ERR "skfp: Invalid PCI region size: %lu\n", len);
- err = -EIO;
- goto err_out1;
- }
+ mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
#else
if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
printk(KERN_ERR "skfp: region is not PIO resource\n");
err = -EIO;
- goto err_out1;
+ goto err_out2;
}
- port = pci_resource_start(pdev, 1);
- len = pci_resource_len(pdev, 1);
- if (len < FP_IO_LEN) {
- printk(KERN_ERR "skfp: Invalid PCI region size: %d\n",
- io_len);
+ mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
+#endif
+ if (!mem) {
+ printk(KERN_ERR "skfp: Unable to map register, "
+ "FDDI adapter will be disabled.\n");
err = -EIO;
- goto err_out1;
+ goto err_out2;
}
-#endif
- err = pci_request_regions(pdev, "skfddi");
- if (err)
- goto err_out1;
-
- pci_set_master(pdev);
dev = alloc_fddidev(sizeof(struct s_smc));
if (!dev) {
printk(KERN_ERR "skfp: Unable to allocate fddi device, "
"FDDI adapter will be disabled.\n");
err = -ENOMEM;
- goto err_out2;
- }
-
-#ifdef MEM_MAPPED_IO
- dev->base_addr = (unsigned long) ioremap(port, len);
- if (!dev->base_addr) {
- printk(KERN_ERR "skfp: Unable to map MEMORY register, "
- "FDDI adapter will be disabled.\n");
- err = -EIO;
goto err_out3;
}
-#else
- dev->base_addr = port;
-#endif
dev->irq = pdev->irq;
dev->get_stats = &skfp_ctl_get_stats;
SET_NETDEV_DEV(dev, &pdev->dev);
/* Initialize board structure with bus-specific info */
- smc = (struct s_smc *) dev->priv;
+ smc = netdev_priv(dev);
smc->os.dev = dev;
smc->os.bus_type = SK_BUS_TYPE_PCI;
smc->os.pdev = *pdev;
smc->os.MaxFrameSize = MAX_FRAME_SIZE;
smc->os.dev = dev;
smc->hw.slot = -1;
+ smc->hw.iop = mem;
smc->os.ResetRequested = FALSE;
skb_queue_head_init(&smc->os.SendSkbQueue);
+ dev->base_addr = (unsigned long)mem;
+
err = skfp_driver_init(dev);
if (err)
goto err_out4;
pci_free_consistent(pdev, MAX_FRAME_SIZE,
smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
err_out4:
+ free_netdev(dev);
+err_out3:
#ifdef MEM_MAPPED_IO
- iounmap((void *) dev->base_addr);
+ iounmap(mem);
+#else
+ ioport_unmap(mem);
#endif
-err_out3:
- free_netdev(dev);
err_out2:
pci_release_regions(pdev);
err_out1:
+ pci_disable_device(pdev);
return err;
}
static void __devexit skfp_remove_one(struct pci_dev *pdev)
{
struct net_device *p = pci_get_drvdata(pdev);
- struct s_smc *lp = p->priv;
+ struct s_smc *lp = netdev_priv(p);
unregister_netdev(p);
lp->os.LocalRxBuffer = NULL;
}
#ifdef MEM_MAPPED_IO
- iounmap((void *) p->base_addr);
+ iounmap(lp->hw.iop);
+#else
+ ioport_unmap(lp->hw.iop);
#endif
pci_release_regions(pdev);
free_netdev(p);
+ pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
}
*/
static int skfp_driver_init(struct net_device *dev)
{
- struct s_smc *smc = (struct s_smc *) dev->priv;
- skfddi_priv *bp = PRIV(dev);
+ struct s_smc *smc = netdev_priv(dev);
+ skfddi_priv *bp = &smc->os;
int err = -EIO;
PRINTK(KERN_INFO "entering skfp_driver_init\n");
// set the io address in private structures
bp->base_addr = dev->base_addr;
- smc->hw.iop = dev->base_addr;
// Get the interrupt level from the PCI Configuration Table
smc->hw.irq = dev->irq;
*/
static int skfp_open(struct net_device *dev)
{
- struct s_smc *smc = (struct s_smc *) dev->priv;
+ struct s_smc *smc = netdev_priv(dev);
int err;
PRINTK(KERN_INFO "entering skfp_open\n");
*/
static int skfp_close(struct net_device *dev)
{
- struct s_smc *smc = (struct s_smc *) dev->priv;
- skfddi_priv *bp = PRIV(dev);
+ struct s_smc *smc = netdev_priv(dev);
+ skfddi_priv *bp = &smc->os;
CLI_FBI();
smt_reset_defaults(smc, 1);
{
struct net_device *dev = (struct net_device *) dev_id;
struct s_smc *smc; /* private board structure pointer */
- skfddi_priv *bp = PRIV(dev);
-
+ skfddi_priv *bp;
if (dev == NULL) {
printk("%s: irq %d for unknown device\n", dev->name, irq);
return IRQ_NONE;
}
- smc = (struct s_smc *) dev->priv;
+ smc = netdev_priv(dev);
+ bp = &smc->os;
// IRQs enabled or disabled ?
if (inpd(ADDR(B0_IMSK)) == 0) {
*/
struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
{
- struct s_smc *bp = (struct s_smc *) dev->priv;
+ struct s_smc *bp = netdev_priv(dev);
/* Fill the bp->stats structure with driver-maintained counters */
*/
static void skfp_ctl_set_multicast_list(struct net_device *dev)
{
- skfddi_priv *bp = PRIV(dev);
+ struct s_smc *smc = netdev_priv(dev);
+ skfddi_priv *bp = &smc->os;
unsigned long Flags;
spin_lock_irqsave(&bp->DriverLock, Flags);
static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
{
- struct s_smc *smc = (struct s_smc *) dev->priv;
+ struct s_smc *smc = netdev_priv(dev);
struct dev_mc_list *dmi; /* ptr to multicast addr entry */
int i;
*/
static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
{
- struct s_smc *smc = (struct s_smc *) dev->priv;
+ struct s_smc *smc = netdev_priv(dev);
struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
unsigned long Flags;
static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
- skfddi_priv *lp = PRIV(dev);
+ struct s_smc *smc = netdev_priv(dev);
+ skfddi_priv *lp = &smc->os;
struct s_skfp_ioctl ioc;
int status = 0;
if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
return -EFAULT;
+
switch (ioc.cmd) {
case SKFP_GET_STATS: /* Get the driver statistics */
ioc.len = sizeof(lp->MacStat);
*/
static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
{
- skfddi_priv *bp = PRIV(dev);
+ struct s_smc *smc = netdev_priv(dev);
+ skfddi_priv *bp = &smc->os;
PRINTK(KERN_INFO "skfp_send_pkt\n");
}
bp->QueueSkb--;
skb_queue_tail(&bp->SendSkbQueue, skb);
- send_queued_packets((struct s_smc *) dev->priv);
+ send_queued_packets(netdev_priv(dev));
if (bp->QueueSkb == 0) {
netif_stop_queue(dev);
}
*/
static void send_queued_packets(struct s_smc *smc)
{
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
struct sk_buff *skb;
unsigned char fc;
int queue;
************************/
void llc_restart_tx(struct s_smc *smc)
{
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
PRINTK(KERN_INFO "[llc_restart_tx]\n");
* unmap first, the hardware module could read inconsistent data.
*/
if (flag & DMA_WR) {
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
volatile struct s_smt_fp_rxd *r = &descr->r;
/* If SKB is NULL, we used the local buffer. */
void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
int frag_count, int len)
{
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
struct sk_buff *skb;
unsigned char *virt, *cp;
unsigned short ri;
printk("fddi: Multi-fragment requeue!\n");
- MaxFrameSize = ((skfddi_priv *) & smc->os)->MaxFrameSize;
+ MaxFrameSize = smc->os.MaxFrameSize;
src_rxd = rxd;
for (; frag_count > 0; frag_count--) {
next_rxd = src_rxd->rxd_next;
// Walk through the list of free receive buffers, passing receive
// buffers to the HWM as long as RXDs are available.
- MaxFrameSize = ((skfddi_priv *) & smc->os)->MaxFrameSize;
+ MaxFrameSize = smc->os.MaxFrameSize;
// Check if there is any RXD left.
while (HWM_GET_RX_FREE(smc) > 0) {
PRINTK(KERN_INFO ".\n");
for (; frag_count > 0; frag_count--) {
skb = rxd->rxd_os.skb;
if (skb != NULL) {
- skfddi_priv *bp = (skfddi_priv *) & smc->os;
+ skfddi_priv *bp = &smc->os;
int MaxFrameSize = bp->MaxFrameSize;
pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
memcpy(skb->data, look_ahead, len);
// deliver frame to system
- skb->protocol = fddi_type_trans(skb, ((skfddi_priv *) & smc->os)->dev);
+ skb->protocol = fddi_type_trans(skb, smc->os.dev);
skb->dev->last_rx = jiffies;
netif_rx(skb);