2 * Driver for the Solos PCI ADSL2+ card, designed to support Linux by
3 * Traverse Technologies -- http://www.traverse.com.au/
4 * Xrio Limited -- http://www.xrio.com/
7 * Copyright © 2008 Traverse Technologies
8 * Copyright © 2008 Intel Corporation
10 * Authors: Nathan Williams <nathan@traverse.com.au>
11 * David Woodhouse <dwmw2@infradead.org>
12 * Treker Chen <treker@xrio.com>
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * version 2, as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/ioport.h>
32 #include <linux/types.h>
33 #include <linux/pci.h>
34 #include <linux/atm.h>
35 #include <linux/atmdev.h>
36 #include <linux/skbuff.h>
37 #include <linux/sysfs.h>
38 #include <linux/device.h>
39 #include <linux/kobject.h>
40 #include <linux/firmware.h>
41 #include <linux/ctype.h>
42 #include <linux/swab.h>
44 #define VERSION "0.07"
45 #define PTAG "solos-pci"
47 #define CONFIG_RAM_SIZE 128
48 #define FLAGS_ADDR 0x7C
49 #define IRQ_EN_ADDR 0x78
51 #define IRQ_CLEAR 0x70
52 #define WRITE_FLASH 0x6C
54 #define FLASH_BLOCK 0x64
55 #define FLASH_BUSY 0x60
56 #define FPGA_MODE 0x5C
57 #define FLASH_MODE 0x58
59 #define DATA_RAM_SIZE 32768
61 #define FPGA_PAGE 528 /* FPGA flash page size*/
62 #define SOLOS_PAGE 512 /* Solos flash page size*/
63 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
64 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
66 #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
67 #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
70 static int atmdebug = 0;
71 static int firmware_upgrade = 0;
72 static int fpga_upgrade = 0;
87 void __iomem *config_regs;
88 void __iomem *buffers;
91 struct atm_dev *atmdev[4];
92 struct tasklet_struct tlet;
94 spinlock_t tx_queue_lock;
95 spinlock_t cli_queue_lock;
96 spinlock_t param_queue_lock;
97 struct list_head param_queue;
98 struct sk_buff_head tx_queue[4];
99 struct sk_buff_head cli_queue[4];
100 wait_queue_head_t param_wq;
101 wait_queue_head_t fw_wq;
106 struct list_head list;
109 struct sk_buff *response;
110 wait_queue_head_t wq;
113 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
115 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
116 MODULE_DESCRIPTION("Solos PCI driver");
117 MODULE_VERSION(VERSION);
118 MODULE_LICENSE("GPL");
119 MODULE_PARM_DESC(debug, "Enable Loopback");
120 MODULE_PARM_DESC(atmdebug, "Print ATM data");
121 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
122 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
123 module_param(debug, int, 0444);
124 module_param(atmdebug, int, 0644);
125 module_param(firmware_upgrade, int, 0444);
126 module_param(fpga_upgrade, int, 0444);
128 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
129 struct atm_vcc *vcc);
130 static int fpga_tx(struct solos_card *);
131 static irqreturn_t solos_irq(int irq, void *dev_id);
132 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
133 static int list_vccs(int vci);
134 static int atm_init(struct solos_card *);
135 static void atm_remove(struct solos_card *);
136 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
137 static void solos_bh(unsigned long);
138 static int print_buffer(struct sk_buff *buf);
140 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
145 dev_kfree_skb_any(skb);
148 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
151 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
152 struct solos_card *card = atmdev->dev_data;
153 struct solos_param prm;
155 struct pkt_hdr *header;
158 buflen = strlen(attr->attr.name) + 10;
160 skb = alloc_skb(buflen, GFP_KERNEL);
162 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
166 header = (void *)skb_put(skb, sizeof(*header));
168 buflen = snprintf((void *)&header[1], buflen - 1,
169 "L%05d\n%s\n", current->pid, attr->attr.name);
170 skb_put(skb, buflen);
172 header->size = cpu_to_le16(buflen);
173 header->vpi = cpu_to_le16(0);
174 header->vci = cpu_to_le16(0);
175 header->type = cpu_to_le16(PKT_COMMAND);
177 prm.pid = current->pid;
179 prm.port = SOLOS_CHAN(atmdev);
181 spin_lock_irq(&card->param_queue_lock);
182 list_add(&prm.list, &card->param_queue);
183 spin_unlock_irq(&card->param_queue_lock);
185 fpga_queue(card, prm.port, skb, NULL);
187 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
189 spin_lock_irq(&card->param_queue_lock);
191 spin_unlock_irq(&card->param_queue_lock);
196 buflen = prm.response->len;
197 memcpy(buf, prm.response->data, buflen);
198 kfree_skb(prm.response);
203 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
204 const char *buf, size_t count)
206 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
207 struct solos_card *card = atmdev->dev_data;
208 struct solos_param prm;
210 struct pkt_hdr *header;
214 buflen = strlen(attr->attr.name) + 11 + count;
216 skb = alloc_skb(buflen, GFP_KERNEL);
218 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
222 header = (void *)skb_put(skb, sizeof(*header));
224 buflen = snprintf((void *)&header[1], buflen - 1,
225 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
227 skb_put(skb, buflen);
228 header->size = cpu_to_le16(buflen);
229 header->vpi = cpu_to_le16(0);
230 header->vci = cpu_to_le16(0);
231 header->type = cpu_to_le16(PKT_COMMAND);
233 prm.pid = current->pid;
235 prm.port = SOLOS_CHAN(atmdev);
237 spin_lock_irq(&card->param_queue_lock);
238 list_add(&prm.list, &card->param_queue);
239 spin_unlock_irq(&card->param_queue_lock);
241 fpga_queue(card, prm.port, skb, NULL);
243 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
245 spin_lock_irq(&card->param_queue_lock);
247 spin_unlock_irq(&card->param_queue_lock);
256 /* Sometimes it has a newline, sometimes it doesn't. */
257 if (skb->data[buflen - 1] == '\n')
260 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
262 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
265 /* We know we have enough space allocated for this; we allocated
267 skb->data[buflen] = 0;
269 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
278 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
280 struct solos_param *prm;
288 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
289 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
290 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
291 skb->data[6] != '\n')
294 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
296 spin_lock_irqsave(&card->param_queue_lock, flags);
297 list_for_each_entry(prm, &card->param_queue, list) {
298 if (prm->port == port && prm->pid == cmdpid) {
301 wake_up(&card->param_wq);
306 spin_unlock_irqrestore(&card->param_queue_lock, flags);
310 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
313 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
314 struct solos_card *card = atmdev->dev_data;
317 spin_lock(&card->cli_queue_lock);
318 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
319 spin_unlock(&card->cli_queue_lock);
321 return sprintf(buf, "No data.\n");
323 memcpy(buf, skb->data, skb->len);
324 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
330 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
333 struct pkt_hdr *header;
335 // dev_dbg(&card->dev->dev, "size: %d\n", size);
337 if (size > (BUF_SIZE - sizeof(*header))) {
338 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
341 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
343 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
347 header = (void *)skb_put(skb, sizeof(*header));
349 header->size = cpu_to_le16(size);
350 header->vpi = cpu_to_le16(0);
351 header->vci = cpu_to_le16(0);
352 header->type = cpu_to_le16(PKT_COMMAND);
354 memcpy(skb_put(skb, size), buf, size);
356 fpga_queue(card, dev, skb, NULL);
361 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
362 const char *buf, size_t count)
364 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
365 struct solos_card *card = atmdev->dev_data;
368 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
373 static DEVICE_ATTR(console, 0644, console_show, console_store);
374 static DEVICE_ATTR(OperationalMode, 0444, solos_param_show, NULL);
375 static DEVICE_ATTR(AutoStart, 0644, solos_param_show, solos_param_store);
377 static int flash_upgrade(struct solos_card *card, int chip)
379 const struct firmware *fw;
387 fw_name = "solos-FPGA.bin";
388 blocksize = FPGA_BLOCK;
390 fw_name = "solos-Firmware.bin";
391 blocksize = SOLOS_BLOCK;
394 if (request_firmware(&fw, fw_name, &card->dev->dev))
397 dev_info(&card->dev->dev, "Flash upgrade starting\n");
399 numblocks = fw->size / blocksize;
400 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
401 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
403 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
404 iowrite32(1, card->config_regs + FPGA_MODE);
405 data32 = ioread32(card->config_regs + FPGA_MODE);
407 /* Set mode to Chip Erase */
408 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
409 chip?"Solos":"FPGA");
410 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
413 iowrite32(1, card->config_regs + WRITE_FLASH);
414 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
416 for (offset = 0; offset < fw->size; offset += blocksize) {
419 /* Clear write flag */
420 iowrite32(0, card->config_regs + WRITE_FLASH);
422 /* Set mode to Block Write */
423 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
424 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
426 /* Copy block to buffer, swapping each 16 bits */
427 for(i = 0; i < blocksize; i += 4) {
428 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
429 iowrite32(word, RX_BUF(card, 3) + i);
432 /* Specify block number and then trigger flash write */
433 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
434 iowrite32(1, card->config_regs + WRITE_FLASH);
435 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
438 release_firmware(fw);
439 iowrite32(0, card->config_regs + WRITE_FLASH);
440 iowrite32(0, card->config_regs + FPGA_MODE);
441 iowrite32(0, card->config_regs + FLASH_MODE);
442 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
446 static irqreturn_t solos_irq(int irq, void *dev_id)
448 struct solos_card *card = dev_id;
452 iowrite32(0, card->config_regs + IRQ_CLEAR);
453 //Disable IRQs from FPGA
454 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
457 tasklet_schedule(&card->tlet);
459 wake_up(&card->fw_wq);
461 //Enable IRQs from FPGA
462 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
463 return IRQ_RETVAL(handled);
466 void solos_bh(unsigned long card_arg)
468 struct solos_card *card = (void *)card_arg;
472 uint32_t rx_done = 0;
474 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
476 /* The TX bits are set if the channel is busy; clear if not. We want to
477 invoke fpga_tx() unless _all_ the bits for active channels are set */
478 tx_mask = (1 << card->nr_ports) - 1;
479 if ((card_flags & tx_mask) != tx_mask)
482 for (port = 0; port < card->nr_ports; port++) {
483 if (card_flags & (0x10 << port)) {
484 struct pkt_hdr header;
489 rx_done |= 0x10 << port;
491 memcpy_fromio(&header, RX_BUF(card, port), sizeof(header));
493 size = le16_to_cpu(header.size);
495 skb = alloc_skb(size, GFP_ATOMIC);
498 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
502 memcpy_fromio(skb_put(skb, size),
503 RX_BUF(card, port) + sizeof(header),
507 dev_info(&card->dev->dev, "Received: device %d\n", port);
508 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
509 size, le16_to_cpu(header.vpi),
510 le16_to_cpu(header.vci));
514 switch (le16_to_cpu(header.type)) {
516 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header.vpi),
517 le16_to_cpu(header.vci));
520 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
521 le16_to_cpu(header.vci), le16_to_cpu(header.vpi),
525 atm_charge(vcc, skb->truesize);
527 atomic_inc(&vcc->stats->rx);
531 default: /* FIXME: Not really, surely? */
532 if (process_command(card, port, skb))
534 spin_lock(&card->cli_queue_lock);
535 if (skb_queue_len(&card->cli_queue[port]) > 10) {
537 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
540 skb_queue_tail(&card->cli_queue[port], skb);
541 spin_unlock(&card->cli_queue_lock);
547 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
552 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
554 struct hlist_head *head;
555 struct atm_vcc *vcc = NULL;
556 struct hlist_node *node;
559 read_lock(&vcc_sklist_lock);
560 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
561 sk_for_each(s, node, head) {
563 if (vcc->dev == dev && vcc->vci == vci &&
564 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
569 read_unlock(&vcc_sklist_lock);
573 static int list_vccs(int vci)
575 struct hlist_head *head;
577 struct hlist_node *node;
582 read_lock(&vcc_sklist_lock);
584 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
585 sk_for_each(s, node, head) {
588 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
596 sk_for_each(s, node, head) {
599 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
606 read_unlock(&vcc_sklist_lock);
611 static int popen(struct atm_vcc *vcc)
613 struct solos_card *card = vcc->dev->dev_data;
615 struct pkt_hdr *header;
617 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
618 if (!skb && net_ratelimit()) {
619 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
622 header = (void *)skb_put(skb, sizeof(*header));
624 header->size = cpu_to_le16(0);
625 header->vpi = cpu_to_le16(vcc->vpi);
626 header->vci = cpu_to_le16(vcc->vci);
627 header->type = cpu_to_le16(PKT_POPEN);
629 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
631 // dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
632 set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
633 set_bit(ATM_VF_READY, &vcc->flags);
640 static void pclose(struct atm_vcc *vcc)
642 struct solos_card *card = vcc->dev->dev_data;
644 struct pkt_hdr *header;
646 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
648 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
651 header = (void *)skb_put(skb, sizeof(*header));
653 header->size = cpu_to_le16(0);
654 header->vpi = cpu_to_le16(vcc->vpi);
655 header->vci = cpu_to_le16(vcc->vci);
656 header->type = cpu_to_le16(PKT_PCLOSE);
658 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
660 // dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
662 clear_bit(ATM_VF_ADDR, &vcc->flags);
663 clear_bit(ATM_VF_READY, &vcc->flags);
668 static int print_buffer(struct sk_buff *buf)
675 for (i = 0; i < len; i++){
677 sprintf(msg, "%02X: ", i);
679 sprintf(item,"%02X ",*(buf->data + i));
684 printk(KERN_DEBUG "%s", msg);
690 printk(KERN_DEBUG "%s", msg);
692 printk(KERN_DEBUG "\n");
697 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
702 *(void **)skb->cb = vcc;
704 spin_lock(&card->tx_queue_lock);
705 old_len = skb_queue_len(&card->tx_queue[port]);
706 skb_queue_tail(&card->tx_queue[port], skb);
707 spin_unlock(&card->tx_queue_lock);
709 /* If TX might need to be started, do so */
714 static int fpga_tx(struct solos_card *card)
717 uint32_t tx_started = 0;
723 spin_lock_irqsave(&card->tx_lock, flags);
725 tx_pending = ioread32(card->config_regs + FLAGS_ADDR);
727 dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
729 for (port = 0; port < card->nr_ports; port++) {
730 if (!(tx_pending & (1 << port))) {
732 spin_lock(&card->tx_queue_lock);
733 skb = skb_dequeue(&card->tx_queue[port]);
734 spin_unlock(&card->tx_queue_lock);
740 dev_info(&card->dev->dev, "Transmitted: port %d\n",
744 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
746 vcc = *(void **)skb->cb;
749 atomic_inc(&vcc->stats->tx);
752 dev_kfree_skb_irq(skb);
754 tx_started |= 1 << port; //Set TX full flag
758 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
760 spin_unlock_irqrestore(&card->tx_lock, flags);
764 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
766 struct solos_card *card = vcc->dev->dev_data;
767 struct sk_buff *skb2 = NULL;
768 struct pkt_hdr *header;
771 //dev_dbg(&card->dev->dev, "psend called.\n");
772 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
775 skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
777 memcpy(skb2->data, skb->data, skb->len);
778 skb_put(skb2, skb->len);
779 vcc->push(vcc, skb2);
780 atomic_inc(&vcc->stats->rx);
782 atomic_inc(&vcc->stats->tx);
788 if (pktlen > (BUF_SIZE - sizeof(*header))) {
789 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
794 if (!skb_clone_writable(skb, sizeof(*header))) {
798 if (skb_headroom(skb) < sizeof(*header))
799 expand_by = sizeof(*header) - skb_headroom(skb);
801 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
803 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
809 header = (void *)skb_push(skb, sizeof(*header));
811 /* This does _not_ include the size of the header */
812 header->size = cpu_to_le16(pktlen);
813 header->vpi = cpu_to_le16(vcc->vpi);
814 header->vci = cpu_to_le16(vcc->vci);
815 header->type = cpu_to_le16(PKT_DATA);
817 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
822 static struct atmdev_ops fpga_ops = {
837 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
841 uint8_t major_ver, minor_ver;
843 struct solos_card *card;
848 card = kzalloc(sizeof(*card), GFP_KERNEL);
853 init_waitqueue_head(&card->fw_wq);
854 init_waitqueue_head(&card->param_wq);
856 err = pci_enable_device(dev);
858 dev_warn(&dev->dev, "Failed to enable PCI device\n");
862 err = pci_request_regions(dev, "solos");
864 dev_warn(&dev->dev, "Failed to request regions\n");
868 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
869 if (!card->config_regs) {
870 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
871 goto out_release_regions;
873 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
874 if (!card->buffers) {
875 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
876 goto out_unmap_config;
879 // for(i=0;i<64 ;i+=4){
880 // data32=ioread32(card->buffers + i);
881 // dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
884 //Fill Config Mem with zeros
885 for(i = 0; i < 128; i += 4)
886 iowrite32(0, card->config_regs + i);
889 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
891 data32 = ioread32(card->config_regs + FPGA_VER);
892 fpga_ver = (data32 & 0x0000FFFF);
893 major_ver = ((data32 & 0xFF000000) >> 24);
894 minor_ver = ((data32 & 0x00FF0000) >> 16);
895 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
896 major_ver, minor_ver, fpga_ver);
898 card->nr_ports = 2; /* FIXME: Detect daughterboard */
900 pci_set_drvdata(dev, card);
902 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
903 spin_lock_init(&card->tx_lock);
904 spin_lock_init(&card->tx_queue_lock);
905 spin_lock_init(&card->cli_queue_lock);
906 spin_lock_init(&card->param_queue_lock);
907 INIT_LIST_HEAD(&card->param_queue);
912 iowrite32(data32,card->config_regs + FLAGS_ADDR);
915 // Fill Buffers with zeros
916 for (i = 0; i < BUF_SIZE * 8; i += 4)
917 iowrite32(0, card->buffers + i);
920 for(i = 0; i < (BUF_SIZE * 1); i += 4)
921 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
922 for(i = 0; i < (BUF_SIZE * 1); i += 4)
923 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
925 // Read Config Memory
926 printk(KERN_DEBUG "Reading Config MEM\n");
928 for(i = 0; i < 16; i++) {
929 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
930 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
931 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
932 (unsigned long)data32);
935 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
936 err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
939 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
944 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
947 flash_upgrade(card, 0);
949 if (firmware_upgrade)
950 flash_upgrade(card, 1);
952 err = atm_init(card);
959 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
960 free_irq(dev->irq, card);
961 tasklet_kill(&card->tlet);
964 pci_set_drvdata(dev, NULL);
965 pci_iounmap(dev, card->config_regs);
967 pci_iounmap(dev, card->buffers);
969 pci_release_regions(dev);
974 static int atm_init(struct solos_card *card)
978 for (i = 0; i < card->nr_ports; i++) {
979 skb_queue_head_init(&card->tx_queue[i]);
980 skb_queue_head_init(&card->cli_queue[i]);
982 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
983 if (!card->atmdev[i]) {
984 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
988 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
989 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
990 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_OperationalMode))
991 dev_err(&card->dev->dev, "Could not register opmode attr for ATM device %d\n", i);
992 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_AutoStart))
993 dev_err(&card->dev->dev, "Could not register autostart attr for ATM device %d\n", i);
995 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
997 card->atmdev[i]->ci_range.vpi_bits = 8;
998 card->atmdev[i]->ci_range.vci_bits = 16;
999 card->atmdev[i]->dev_data = card;
1000 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1005 static void atm_remove(struct solos_card *card)
1009 for (i = 0; i < card->nr_ports; i++) {
1010 if (card->atmdev[i]) {
1011 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1012 atm_dev_deregister(card->atmdev[i]);
1017 static void fpga_remove(struct pci_dev *dev)
1019 struct solos_card *card = pci_get_drvdata(dev);
1026 dev_vdbg(&dev->dev, "Freeing IRQ\n");
1027 // Disable IRQs from FPGA
1028 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1029 free_irq(dev->irq, card);
1030 tasklet_kill(&card->tlet);
1032 // iowrite32(0x01,pciregs);
1033 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
1034 pci_iounmap(dev, card->buffers);
1035 pci_iounmap(dev, card->config_regs);
1037 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
1038 pci_release_regions(dev);
1039 pci_disable_device(dev);
1041 pci_set_drvdata(dev, NULL);
1043 // dev_dbg(&card->dev->dev, "fpga_remove\n");
1047 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1048 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1052 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1054 static struct pci_driver fpga_driver = {
1056 .id_table = fpga_pci_tbl,
1057 .probe = fpga_probe,
1058 .remove = fpga_remove,
1062 static int __init solos_pci_init(void)
1064 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1065 return pci_register_driver(&fpga_driver);
1068 static void __exit solos_pci_exit(void)
1070 pci_unregister_driver(&fpga_driver);
1071 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1074 module_init(solos_pci_init);
1075 module_exit(solos_pci_exit);