20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
25 #include <linux/sched.h>
26 #include <linux/types.h>
27 #include <linux/fcntl.h>
29 #include <linux/string.h>
30 #include <linux/errno.h>
34 #include <linux/netdevice.h>
35 #include <linux/hdlc.h>
36 #include <linux/pci.h>
45 #define PC300_PLX_SIZE 0x80
46 #define PC300_SCA_SIZE 0x400
47 #define MAX_TX_BUFFERS 10
49 static int pci_clock_freq = 33000000;
50 static int use_crystal_clock = 0;
54 #define PC300_CLKSEL_MASK (0x00000004UL)
55 #define PC300_CHMEDIA_MASK(port) (0x00000020UL << ((port) * 3))
56 #define PC300_CTYPE_MASK (0x00000800UL)
66 u32 loc_addr_range[4];
114 #define get_port(card, port) ((port) < (card)->n_ports ? \
115 (&(card)->ports[port]) : (NULL))
123 u32 __iomem * init_ctrl = &card->plxbase->init_ctrl;
160 writel(card->init_ctrl_value |
163 writel(card->init_ctrl_value &
179 pc300_set_iface(port);
185 static int pc300_close(
struct net_device *dev)
212 ifr->ifr_settings.type = port->iface;
213 if (ifr->ifr_settings.size < size) {
214 ifr->ifr_settings.size =
size;
255 memcpy(&port->settings, &new_line, size);
256 port->iface = new_type;
257 pc300_set_iface(port);
263 static void pc300_pci_remove_one(
struct pci_dev *pdev)
268 for (i = 0; i < 2; i++)
284 pci_set_drvdata(pdev,
NULL);
285 if (card->
ports[0].netdev)
287 if (card->
ports[1].netdev)
293 .ndo_open = pc300_open,
294 .ndo_stop = pc300_close,
297 .ndo_do_ioctl = pc300_ioctl,
327 pci_set_drvdata(pdev, card);
332 pr_err(
"invalid card EEPROM parameters\n");
333 pc300_pci_remove_one(pdev);
346 if (card->plxbase ==
NULL ||
347 card->scabase ==
NULL ||
348 card->rambase ==
NULL) {
349 pr_err(
"ioremap() failed\n");
350 pc300_pci_remove_one(pdev);
372 for (i = 0; i < card->
n_ports; i++)
374 pr_err(
"unable to allocate memory\n");
375 pc300_pci_remove_one(pdev);
380 p = &card->plxbase->init_ctrl;
381 writel(card->init_ctrl_value | 0x40000000, p);
385 writel(card->init_ctrl_value, p);
390 writel(card->init_ctrl_value | 0x20000000, p);
394 writel(card->init_ctrl_value, p);
398 ramsize = sca_detect_ram(card, card->rambase,
401 if (use_crystal_clock)
406 writel(card->init_ctrl_value, &card->plxbase->init_ctrl);
410 card->rx_ring_buffers = i - card->tx_ring_buffers;
413 (card->tx_ring_buffers + card->rx_ring_buffers);
415 pr_info(
"PC300/%s, %u KB RAM at 0x%x, IRQ%u, using %u TX + %u RX packets rings\n",
417 card->type ==
PC300_TE ?
"TE" :
"RSV",
418 ramsize / 1024, ramphys, pdev->
irq,
419 card->tx_ring_buffers, card->rx_ring_buffers);
421 if (card->tx_ring_buffers < 1) {
422 pr_err(
"RAM test failed\n");
423 pc300_pci_remove_one(pdev);
428 writew(0x0041, &card->plxbase->intr_ctrl_stat);
432 pr_warn(
"could not allocate IRQ%d\n", pdev->
irq);
433 pc300_pci_remove_one(pdev);
445 for (i = 0; i < card->
n_ports; i++) {
454 dev->
mem_end = ramphys + ramsize - 1;
457 hdlc->
attach = sca_attach;
458 hdlc->
xmit = sca_xmit;
468 pr_err(
"unable to register hdlc device\n");
470 pc300_pci_remove_one(pdev);
474 netdev_info(dev,
"PC300 channel %d\n", port->chan);
496 .id_table = pc300_pci_tbl,
497 .probe = pc300_pci_init_one,
498 .remove = pc300_pci_remove_one,
502 static int __init pc300_init_module(
void)
504 if (pci_clock_freq < 1000000 || pci_clock_freq > 80000000) {
505 pr_err(
"Invalid PCI clock frequency\n");
508 if (use_crystal_clock != 0 && use_crystal_clock != 1) {
509 pr_err(
"Invalid 'use_crystal_clock' value\n");
513 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq;
515 return pci_register_driver(&pc300_pci_driver);
520 static void __exit pc300_cleanup_module(
void)
533 "Use 24.576 MHz clock instead of PCI clock");