16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/sched.h>
22 #include <linux/types.h>
23 #include <linux/fcntl.h>
24 #include <linux/string.h>
25 #include <linux/errno.h>
29 #include <linux/netdevice.h>
30 #include <linux/hdlc.h>
31 #include <linux/pci.h>
38 static const char*
version =
"wanXL serial card driver version: 0.48";
40 #define PLX_CTL_RESET 0x40000000
46 #define MBX1_CMD_ABORTJ 0x85000000
47 #ifdef __LITTLE_ENDIAN
48 #define MBX1_CMD_BSWAP 0x8C000001
50 #define MBX1_CMD_BSWAP 0x8C000000
54 #define MBX2_MEMSZ_MASK 0xFFFF0000
91 return (
port_t *)dev_to_hdlc(dev)->priv;
97 return &port->
card->status->port_status[port->
node];
106 if (addr + size > 0x100000000LL)
107 pr_crit(
"%s: pci_map_single() returned memory at 0x%llx!\n",
108 pci_name(pdev), (
unsigned long long)addr);
112 #undef pci_map_single
113 #define pci_map_single pci_map_single_debug
118 static inline void wanxl_cable_intr(
port_t *
port)
122 const char *cable, *
pm, *dte =
"", *dsr =
"", *dcd =
"";
124 switch(value & 0x7) {
130 default: cable =
"invalid";
139 default: pm =
"invalid personality"; valid = 0;
151 netdev_info(port->
dev,
"%s%s module, %s cable%s%s\n",
152 pm, dte, cable, dsr, dcd);
163 static inline void wanxl_tx_intr(
port_t *port)
170 switch (desc->
stat) {
173 netif_wake_queue(dev);
177 dev->
stats.tx_errors++;
178 dev->
stats.tx_fifo_errors++;
182 dev->
stats.tx_packets++;
196 static inline void wanxl_rx_intr(
card_t *
card)
202 pr_crit(
"%s: received packet for nonexistent port\n",
203 pci_name(card->
pdev));
211 dev->
stats.rx_dropped++;
223 dev->
stats.rx_packets++;
225 skb->
protocol = hdlc_type_trans(skb, dev);
233 pci_map_single(card->
pdev, skb->
data,
258 for (i = 0; i < card->
n_ports; i++) {
260 wanxl_tx_intr(&card->
ports[i]);
262 wanxl_cable_intr(&card->
ports[i]);
278 spin_lock(&port->
lock);
286 netif_stop_queue(dev);
287 spin_unlock(&port->
lock);
307 netif_stop_queue(dev);
313 spin_unlock(&port->
lock);
319 static int wanxl_attach(
struct net_device *dev,
unsigned short encoding,
320 unsigned short parity)
351 switch (ifr->ifr_settings.type) {
354 if (ifr->ifr_settings.size < size) {
355 ifr->ifr_settings.size =
size;
362 if (
copy_to_user(ifr->ifr_settings.ifs_ifsu.sync, &line, size))
401 netdev_err(dev,
"port already open\n");
416 netif_start_queue(dev);
421 netdev_err(dev,
"unable to open port\n");
429 static int wanxl_close(
struct net_device *dev)
432 unsigned long timeout;
447 netdev_err(dev,
"unable to close port\n");
449 netif_stop_queue(dev);
459 dev_kfree_skb(port->
tx_skbs[i]);
473 dev->
stats.rx_errors = dev->
stats.rx_over_errors +
474 dev->
stats.rx_frame_errors;
480 static int wanxl_puts_command(
card_t *card,
u32 cmd)
482 unsigned long timeout =
jiffies + 5 *
HZ;
497 static void wanxl_reset(
card_t *card)
511 static void wanxl_pci_remove_one(
struct pci_dev *pdev)
513 card_t *card = pci_get_drvdata(pdev);
516 for (i = 0; i < card->
n_ports; i++) {
529 pci_unmap_single(card->
pdev,
532 dev_kfree_skb(card->
rx_skbs[i]);
544 pci_set_drvdata(pdev,
NULL);
549 #include "wanxlfw.inc"
552 .ndo_open = wanxl_open,
553 .ndo_stop = wanxl_close,
556 .ndo_do_ioctl = wanxl_ioctl,
557 .ndo_get_stats = wanxl_get_stats,
565 unsigned long timeout;
586 if (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(28)) ||
588 pr_err(
"No usable DMA configuration\n");
612 pci_set_drvdata(pdev, card);
618 wanxl_pci_remove_one(pdev);
624 " at 0x%LX\n", pci_name(pdev),
631 if (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32)) ||
633 pr_err(
"No usable DMA configuration\n");
634 wanxl_pci_remove_one(pdev);
643 pr_err(
"ioremap() failed\n");
644 wanxl_pci_remove_one(pdev);
648 #if RESET_WHILE_LOADING
655 pr_warn(
"%s: timeout waiting for PUTS to complete\n",
657 wanxl_pci_remove_one(pdev);
661 switch(stat & 0xC0) {
667 pr_warn(
"%s: PUTS test 0x%X failed\n",
668 pci_name(pdev), stat & 0x30);
669 wanxl_pci_remove_one(pdev);
686 pr_warn(
"%s: no enough on-board RAM (%u bytes detected, %u bytes required)\n",
687 pci_name(pdev), ramsize,
690 wanxl_pci_remove_one(pdev);
695 pr_warn(
"%s: unable to Set Byte Swap Mode\n", pci_name(pdev));
696 wanxl_pci_remove_one(pdev);
705 pci_map_single(card->
pdev, skb->
data,
712 pr_err(
"ioremap() failed\n");
713 wanxl_pci_remove_one(pdev);
717 for (i = 0; i <
sizeof(
firmware); i += 4)
720 for (i = 0; i < ports; i++)
731 pr_warn(
"%s: unable to Abort and Jump\n", pci_name(pdev));
732 wanxl_pci_remove_one(pdev);
745 pr_warn(
"%s: timeout while initializing card firmware\n",
747 wanxl_pci_remove_one(pdev);
755 pr_info(
"%s: at 0x%X, %u KB of RAM at 0x%X, irq %u\n",
756 pci_name(pdev), plx_phy, ramsize / 1024, mem_phy, pdev->
irq);
760 pr_warn(
"%s: could not allocate IRQ%i\n",
761 pci_name(pdev), pdev->
irq);
762 wanxl_pci_remove_one(pdev);
767 for (i = 0; i < ports; i++) {
772 pr_err(
"%s: unable to allocate memory\n",
774 wanxl_pci_remove_one(pdev);
779 hdlc = dev_to_hdlc(dev);
783 hdlc->
attach = wanxl_attach;
784 hdlc->
xmit = wanxl_xmit;
789 pr_err(
"%s: unable to register hdlc device\n",
792 wanxl_pci_remove_one(pdev);
798 pr_info(
"%s: port", pci_name(pdev));
799 for (i = 0; i < ports; i++)
801 i ?
"," :
"", i, card->
ports[i].
dev->name);
804 for (i = 0; i < ports; i++)
805 wanxl_cable_intr(&card->
ports[i]);
823 .id_table = wanxl_pci_tbl,
824 .probe = wanxl_pci_init_one,
825 .remove = wanxl_pci_remove_one,
829 static int __init wanxl_init_module(
void)
834 return pci_register_driver(&wanxl_pci_driver);
837 static void __exit wanxl_cleanup_module(
void)