Commit f8df510e authored by Chas Williams's avatar Chas Williams Committed by Stephen Hemminger

[ATM]: [nicstar] convert to new style pci module (by "Jorge Boncompte [DTI2]" <jorge@dti2.net>)

parent 8bc49a7e
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
#ifdef CONFIG_ATM_ZATM #ifdef CONFIG_ATM_ZATM
extern int zatm_detect(void); extern int zatm_detect(void);
#endif #endif
#ifdef CONFIG_ATM_NICSTAR
extern int nicstar_detect(void);
#endif
#ifdef CONFIG_ATM_AMBASSADOR #ifdef CONFIG_ATM_AMBASSADOR
extern int amb_detect(void); extern int amb_detect(void);
#endif #endif
...@@ -41,9 +38,6 @@ int __init atmdev_init(void) ...@@ -41,9 +38,6 @@ int __init atmdev_init(void)
#ifdef CONFIG_ATM_ZATM #ifdef CONFIG_ATM_ZATM
devs += zatm_detect(); devs += zatm_detect();
#endif #endif
#ifdef CONFIG_ATM_NICSTAR
devs += nicstar_detect();
#endif
#ifdef CONFIG_ATM_AMBASSADOR #ifdef CONFIG_ATM_AMBASSADOR
devs += amb_detect(); devs += amb_detect();
#endif #endif
......
...@@ -214,8 +214,8 @@ ...@@ -214,8 +214,8 @@
static u32 ns_read_sram(ns_dev *card, u32 sram_address); static u32 ns_read_sram(ns_dev *card, u32 sram_address);
static void ns_write_sram(ns_dev *card, u32 sram_address, u32 *value, int count); static void ns_write_sram(ns_dev *card, u32 sram_address, u32 *value, int count);
static int __init ns_init_card(int i, struct pci_dev *pcidev); static int __devinit ns_init_card(int i, struct pci_dev *pcidev);
static void __init ns_init_card_error(ns_dev *card, int error); static void __devinit ns_init_card_error(ns_dev *card, int error);
static scq_info *get_scq(int size, u32 scd); static scq_info *get_scq(int size, u32 scd);
static void free_scq(scq_info *scq, struct atm_vcc *vcc); static void free_scq(scq_info *scq, struct atm_vcc *vcc);
static void push_rxbufs(ns_dev *card, u32 type, u32 handle1, u32 addr1, static void push_rxbufs(ns_dev *card, u32 type, u32 handle1, u32 addr1,
...@@ -276,78 +276,41 @@ MODULE_LICENSE("GPL"); ...@@ -276,78 +276,41 @@ MODULE_LICENSE("GPL");
/* Functions*******************************************************************/ /* Functions*******************************************************************/
static int __init nicstar_module_init(void) static int __devinit nicstar_init_one(struct pci_dev *pcidev,
const struct pci_device_id *ent)
{ {
int i; static int index = -1;
unsigned error = 0; /* Initialized to remove compile warning */ unsigned int error;
struct pci_dev *pcidev;
XPRINTK("nicstar: nicstar_module_init() called.\n");
for(i = 0; i < NS_MAX_CARDS; i++) index++;
cards[i] = NULL; cards[index] = NULL;
pcidev = NULL;
for(i = 0; i < NS_MAX_CARDS; i++)
{
if ((pcidev = pci_find_device(PCI_VENDOR_ID_IDT,
PCI_DEVICE_ID_IDT_IDT77201,
pcidev)) == NULL)
break;
error = ns_init_card(i, pcidev); error = ns_init_card(index, pcidev);
if (error) if (error) {
cards[i--] = NULL; /* Try to find another card but don't increment index */ cards[index--] = NULL; /* don't increment index */
goto err_out;
} }
if (i == 0)
{
if (!error)
{
printk("nicstar: no cards found.\n");
return -ENXIO;
}
else
return -EIO;
}
TXPRINTK("nicstar: TX debug enabled.\n");
RXPRINTK("nicstar: RX debug enabled.\n");
PRINTK("nicstar: General debug enabled.\n");
#ifdef PHY_LOOPBACK
printk("nicstar: using PHY loopback.\n");
#endif /* PHY_LOOPBACK */
XPRINTK("nicstar: nicstar_module_init() returned.\n");
init_timer(&ns_timer);
ns_timer.expires = jiffies + NS_POLL_PERIOD;
ns_timer.data = 0UL;
ns_timer.function = ns_poll;
add_timer(&ns_timer);
return 0; return 0;
err_out:
return -ENODEV;
} }
static void __exit nicstar_module_exit(void) static void __devexit nicstar_remove_one(struct pci_dev *pcidev)
{ {
int i, j; int i, j;
unsigned short pci_command; ns_dev *card = pci_get_drvdata(pcidev);
ns_dev *card;
struct sk_buff *hb; struct sk_buff *hb;
struct sk_buff *iovb; struct sk_buff *iovb;
struct sk_buff *lb; struct sk_buff *lb;
struct sk_buff *sb; struct sk_buff *sb;
XPRINTK("nicstar: cleanup_module() called.\n"); i = card->index;
del_timer(&ns_timer);
for (i = 0; i < NS_MAX_CARDS; i++)
{
if (cards[i] == NULL) if (cards[i] == NULL)
continue; return;
card = cards[i];
if (card->atmdev->phy && card->atmdev->phy->stop) if (card->atmdev->phy && card->atmdev->phy->stop)
card->atmdev->phy->stop(card->atmdev); card->atmdev->phy->stop(card->atmdev);
...@@ -358,16 +321,8 @@ static void __exit nicstar_module_exit(void) ...@@ -358,16 +321,8 @@ static void __exit nicstar_module_exit(void)
/* De-register device */ /* De-register device */
atm_dev_deregister(card->atmdev); atm_dev_deregister(card->atmdev);
/* Disable memory mapping and busmastering */ /* Disable PCI device */
if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command) != 0) pci_disable_device(pcidev);
{
printk("nicstar%d: can't read PCI_COMMAND.\n", i);
}
pci_command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command) != 0)
{
printk("nicstar%d: can't write PCI_COMMAND.\n", i);
}
/* Free up resources */ /* Free up resources */
j = 0; j = 0;
...@@ -401,11 +356,71 @@ static void __exit nicstar_module_exit(void) ...@@ -401,11 +356,71 @@ static void __exit nicstar_module_exit(void)
free_irq(card->pcidev->irq, card); free_irq(card->pcidev->irq, card);
iounmap((void *) card->membase); iounmap((void *) card->membase);
kfree(card); kfree(card);
}
static struct pci_device_id nicstar_pci_tbl[] __devinitdata =
{
{PCI_VENDOR_ID_IDT, PCI_DEVICE_ID_IDT_IDT77201,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{0,} /* terminate list */
};
MODULE_DEVICE_TABLE(pci, nicstar_pci_tbl);
static struct pci_driver nicstar_driver = {
.name = "nicstar",
.id_table = nicstar_pci_tbl,
.probe = nicstar_init_one,
.remove = __devexit_p(nicstar_remove_one),
};
static int __init nicstar_init(void)
{
unsigned error = 0; /* Initialized to remove compile warning */
XPRINTK("nicstar: nicstar_init() called.\n");
error = pci_module_init(&nicstar_driver);
TXPRINTK("nicstar: TX debug enabled.\n");
RXPRINTK("nicstar: RX debug enabled.\n");
PRINTK("nicstar: General debug enabled.\n");
#ifdef PHY_LOOPBACK
printk("nicstar: using PHY loopback.\n");
#endif /* PHY_LOOPBACK */
XPRINTK("nicstar: nicstar_init() returned.\n");
if (!error) {
init_timer(&ns_timer);
ns_timer.expires = jiffies + NS_POLL_PERIOD;
ns_timer.data = 0UL;
ns_timer.function = ns_poll;
add_timer(&ns_timer);
} }
XPRINTK("nicstar: cleanup_module() returned.\n");
return error;
} }
static void __exit nicstar_cleanup(void)
{
XPRINTK("nicstar: nicstar_cleanup() called.\n");
del_timer(&ns_timer);
pci_unregister_driver(&nicstar_driver);
XPRINTK("nicstar: nicstar_cleanup() returned.\n");
}
static u32 ns_read_sram(ns_dev *card, u32 sram_address) static u32 ns_read_sram(ns_dev *card, u32 sram_address)
{ {
unsigned long flags; unsigned long flags;
...@@ -445,11 +460,10 @@ static void ns_write_sram(ns_dev *card, u32 sram_address, u32 *value, int count) ...@@ -445,11 +460,10 @@ static void ns_write_sram(ns_dev *card, u32 sram_address, u32 *value, int count)
} }
static int __init ns_init_card(int i, struct pci_dev *pcidev) static int __devinit ns_init_card(int i, struct pci_dev *pcidev)
{ {
int j; int j;
struct ns_dev *card = NULL; struct ns_dev *card = NULL;
unsigned short pci_command;
unsigned char pci_latency; unsigned char pci_latency;
unsigned error; unsigned error;
u32 data; u32 data;
...@@ -478,6 +492,8 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev) ...@@ -478,6 +492,8 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev)
spin_lock_init(&card->int_lock); spin_lock_init(&card->int_lock);
spin_lock_init(&card->res_lock); spin_lock_init(&card->res_lock);
pci_set_drvdata(pcidev, card);
card->index = i; card->index = i;
card->atmdev = NULL; card->atmdev = NULL;
card->pcidev = pcidev; card->pcidev = pcidev;
...@@ -492,21 +508,7 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev) ...@@ -492,21 +508,7 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev)
} }
PRINTK("nicstar%d: membase at 0x%x.\n", i, card->membase); PRINTK("nicstar%d: membase at 0x%x.\n", i, card->membase);
if (pci_read_config_word(pcidev, PCI_COMMAND, &pci_command) != 0) pci_set_master(pcidev);
{
printk("nicstar%d: can't read PCI_COMMAND.\n", i);
error = 4;
ns_init_card_error(card, error);
return error;
}
pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
if (pci_write_config_word(pcidev, PCI_COMMAND, pci_command) != 0)
{
printk("nicstar%d: can't write PCI_COMMAND.\n", i);
error = 5;
ns_init_card_error(card, error);
return error;
}
if (pci_read_config_byte(pcidev, PCI_LATENCY_TIMER, &pci_latency) != 0) if (pci_read_config_byte(pcidev, PCI_LATENCY_TIMER, &pci_latency) != 0)
{ {
...@@ -932,7 +934,7 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev) ...@@ -932,7 +934,7 @@ static int __init ns_init_card(int i, struct pci_dev *pcidev)
static void __init ns_init_card_error(ns_dev *card, int error) static void __devinit ns_init_card_error(ns_dev *card, int error)
{ {
if (error >= 17) if (error >= 17)
{ {
...@@ -981,6 +983,7 @@ static void __init ns_init_card_error(ns_dev *card, int error) ...@@ -981,6 +983,7 @@ static void __init ns_init_card_error(ns_dev *card, int error)
} }
if (error >= 3) if (error >= 3)
{ {
pci_disable_device(card->pcidev);
kfree(card); kfree(card);
} }
} }
...@@ -3099,5 +3102,7 @@ static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr) ...@@ -3099,5 +3102,7 @@ static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr)
return (unsigned char) data; return (unsigned char) data;
} }
module_init(nicstar_module_init);
module_exit(nicstar_module_exit);
module_init(nicstar_init);
module_exit(nicstar_cleanup);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment