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;
88 void __iomem *config_regs;
89 void __iomem *buffers;
92 struct atm_dev *atmdev[4];
93 struct tasklet_struct tlet;
95 spinlock_t tx_queue_lock;
96 spinlock_t cli_queue_lock;
97 spinlock_t param_queue_lock;
98 struct list_head param_queue;
99 struct sk_buff_head tx_queue[4];
100 struct sk_buff_head cli_queue[4];
101 wait_queue_head_t param_wq;
102 wait_queue_head_t fw_wq;
107 struct list_head list;
110 struct sk_buff *response;
111 wait_queue_head_t wq;
114 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
116 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
117 MODULE_DESCRIPTION("Solos PCI driver");
118 MODULE_VERSION(VERSION);
119 MODULE_LICENSE("GPL");
120 MODULE_PARM_DESC(debug, "Enable Loopback");
121 MODULE_PARM_DESC(atmdebug, "Print ATM data");
122 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
123 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
124 module_param(debug, int, 0444);
125 module_param(atmdebug, int, 0644);
126 module_param(firmware_upgrade, int, 0444);
127 module_param(fpga_upgrade, int, 0444);
129 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
130 struct atm_vcc *vcc);
131 static int fpga_tx(struct solos_card *);
132 static irqreturn_t solos_irq(int irq, void *dev_id);
133 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
134 static int list_vccs(int vci);
135 static int atm_init(struct solos_card *);
136 static void atm_remove(struct solos_card *);
137 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
138 static void solos_bh(unsigned long);
139 static int print_buffer(struct sk_buff *buf);
141 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
146 dev_kfree_skb_any(skb);
149 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
152 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
153 struct solos_card *card = atmdev->dev_data;
154 struct solos_param prm;
156 struct pkt_hdr *header;
159 buflen = strlen(attr->attr.name) + 10;
161 skb = alloc_skb(buflen, GFP_KERNEL);
163 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
167 header = (void *)skb_put(skb, sizeof(*header));
169 buflen = snprintf((void *)&header[1], buflen - 1,
170 "L%05d\n%s\n", current->pid, attr->attr.name);
171 skb_put(skb, buflen);
173 header->size = cpu_to_le16(buflen);
174 header->vpi = cpu_to_le16(0);
175 header->vci = cpu_to_le16(0);
176 header->type = cpu_to_le16(PKT_COMMAND);
178 prm.pid = current->pid;
180 prm.port = SOLOS_CHAN(atmdev);
182 spin_lock_irq(&card->param_queue_lock);
183 list_add(&prm.list, &card->param_queue);
184 spin_unlock_irq(&card->param_queue_lock);
186 fpga_queue(card, prm.port, skb, NULL);
188 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
190 spin_lock_irq(&card->param_queue_lock);
192 spin_unlock_irq(&card->param_queue_lock);
197 buflen = prm.response->len;
198 memcpy(buf, prm.response->data, buflen);
199 kfree_skb(prm.response);
204 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
205 const char *buf, size_t count)
207 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
208 struct solos_card *card = atmdev->dev_data;
209 struct solos_param prm;
211 struct pkt_hdr *header;
215 buflen = strlen(attr->attr.name) + 11 + count;
217 skb = alloc_skb(buflen, GFP_KERNEL);
219 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
223 header = (void *)skb_put(skb, sizeof(*header));
225 buflen = snprintf((void *)&header[1], buflen - 1,
226 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
228 skb_put(skb, buflen);
229 header->size = cpu_to_le16(buflen);
230 header->vpi = cpu_to_le16(0);
231 header->vci = cpu_to_le16(0);
232 header->type = cpu_to_le16(PKT_COMMAND);
234 prm.pid = current->pid;
236 prm.port = SOLOS_CHAN(atmdev);
238 spin_lock_irq(&card->param_queue_lock);
239 list_add(&prm.list, &card->param_queue);
240 spin_unlock_irq(&card->param_queue_lock);
242 fpga_queue(card, prm.port, skb, NULL);
244 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
246 spin_lock_irq(&card->param_queue_lock);
248 spin_unlock_irq(&card->param_queue_lock);
257 /* Sometimes it has a newline, sometimes it doesn't. */
258 if (skb->data[buflen - 1] == '\n')
261 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
263 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
266 /* We know we have enough space allocated for this; we allocated
268 skb->data[buflen] = 0;
270 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
279 static char *next_string(struct sk_buff *skb)
282 char *this = skb->data;
284 while (i < skb->len) {
285 if (this[i] == '\n') {
295 * Status packet has fields separated by \n, starting with a version number
296 * for the information therein. Fields are....
299 * TxBitRate (version >= 1)
300 * RxBitRate (version >= 1)
301 * State (version >= 1)
303 static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
306 int ver, rate_up, rate_down, state;
308 if (!card->atmdev[port])
311 str = next_string(skb);
315 ver = simple_strtol(str, NULL, 10);
317 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
322 str = next_string(skb);
323 rate_up = simple_strtol(str, &end, 10);
327 str = next_string(skb);
328 rate_down = simple_strtol(str, &end, 10);
332 str = next_string(skb);
333 if (!strcmp(str, "Showtime"))
334 state = ATM_PHY_SIG_FOUND;
335 else state = ATM_PHY_SIG_LOST;
337 card->atmdev[port]->link_rate = rate_down;
338 card->atmdev[port]->signal = state;
340 dev_info(&card->dev->dev, "ATM state: '%s', %d/%d kb/s up/down.\n",
341 str, rate_up/1000, rate_down/1000);
345 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
347 struct solos_param *prm;
355 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
356 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
357 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
358 skb->data[6] != '\n')
361 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
363 spin_lock_irqsave(&card->param_queue_lock, flags);
364 list_for_each_entry(prm, &card->param_queue, list) {
365 if (prm->port == port && prm->pid == cmdpid) {
368 wake_up(&card->param_wq);
373 spin_unlock_irqrestore(&card->param_queue_lock, flags);
377 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
380 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
381 struct solos_card *card = atmdev->dev_data;
384 spin_lock(&card->cli_queue_lock);
385 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
386 spin_unlock(&card->cli_queue_lock);
388 return sprintf(buf, "No data.\n");
390 memcpy(buf, skb->data, skb->len);
391 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
397 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
400 struct pkt_hdr *header;
402 // dev_dbg(&card->dev->dev, "size: %d\n", size);
404 if (size > (BUF_SIZE - sizeof(*header))) {
405 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
408 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
410 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
414 header = (void *)skb_put(skb, sizeof(*header));
416 header->size = cpu_to_le16(size);
417 header->vpi = cpu_to_le16(0);
418 header->vci = cpu_to_le16(0);
419 header->type = cpu_to_le16(PKT_COMMAND);
421 memcpy(skb_put(skb, size), buf, size);
423 fpga_queue(card, dev, skb, NULL);
428 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
429 const char *buf, size_t count)
431 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
432 struct solos_card *card = atmdev->dev_data;
435 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
440 static DEVICE_ATTR(console, 0644, console_show, console_store);
443 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
444 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
446 #include "solos-attrlist.c"
451 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
452 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
454 static struct attribute *solos_attrs[] = {
455 #include "solos-attrlist.c"
459 static struct attribute_group solos_attr_group = {
460 .attrs = solos_attrs,
461 .name = "parameters",
464 static int flash_upgrade(struct solos_card *card, int chip)
466 const struct firmware *fw;
474 fw_name = "solos-FPGA.bin";
475 blocksize = FPGA_BLOCK;
477 fw_name = "solos-Firmware.bin";
478 blocksize = SOLOS_BLOCK;
481 if (request_firmware(&fw, fw_name, &card->dev->dev))
484 dev_info(&card->dev->dev, "Flash upgrade starting\n");
486 numblocks = fw->size / blocksize;
487 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
488 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
490 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
491 iowrite32(1, card->config_regs + FPGA_MODE);
492 data32 = ioread32(card->config_regs + FPGA_MODE);
494 /* Set mode to Chip Erase */
495 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
496 chip?"Solos":"FPGA");
497 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
500 iowrite32(1, card->config_regs + WRITE_FLASH);
501 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
503 for (offset = 0; offset < fw->size; offset += blocksize) {
506 /* Clear write flag */
507 iowrite32(0, card->config_regs + WRITE_FLASH);
509 /* Set mode to Block Write */
510 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
511 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
513 /* Copy block to buffer, swapping each 16 bits */
514 for(i = 0; i < blocksize; i += 4) {
515 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
516 iowrite32(word, RX_BUF(card, 3) + i);
519 /* Specify block number and then trigger flash write */
520 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
521 iowrite32(1, card->config_regs + WRITE_FLASH);
522 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
525 release_firmware(fw);
526 iowrite32(0, card->config_regs + WRITE_FLASH);
527 iowrite32(0, card->config_regs + FPGA_MODE);
528 iowrite32(0, card->config_regs + FLASH_MODE);
529 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
533 static irqreturn_t solos_irq(int irq, void *dev_id)
535 struct solos_card *card = dev_id;
539 iowrite32(0, card->config_regs + IRQ_CLEAR);
540 //Disable IRQs from FPGA
541 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
544 tasklet_schedule(&card->tlet);
546 wake_up(&card->fw_wq);
548 //Enable IRQs from FPGA
549 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
550 return IRQ_RETVAL(handled);
553 void solos_bh(unsigned long card_arg)
555 struct solos_card *card = (void *)card_arg;
559 uint32_t rx_done = 0;
561 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
563 /* The TX bits are set if the channel is busy; clear if not. We want to
564 invoke fpga_tx() unless _all_ the bits for active channels are set */
565 tx_mask = (1 << card->nr_ports) - 1;
566 if ((card_flags & tx_mask) != tx_mask)
569 for (port = 0; port < card->nr_ports; port++) {
570 if (card_flags & (0x10 << port)) {
571 struct pkt_hdr header;
576 rx_done |= 0x10 << port;
578 memcpy_fromio(&header, RX_BUF(card, port), sizeof(header));
580 size = le16_to_cpu(header.size);
582 skb = alloc_skb(size + 1, GFP_ATOMIC);
585 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
589 memcpy_fromio(skb_put(skb, size),
590 RX_BUF(card, port) + sizeof(header),
594 dev_info(&card->dev->dev, "Received: device %d\n", port);
595 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
596 size, le16_to_cpu(header.vpi),
597 le16_to_cpu(header.vci));
601 switch (le16_to_cpu(header.type)) {
603 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header.vpi),
604 le16_to_cpu(header.vci));
607 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
608 le16_to_cpu(header.vci), le16_to_cpu(header.vpi),
612 atm_charge(vcc, skb->truesize);
614 atomic_inc(&vcc->stats->rx);
618 process_status(card, port, skb);
623 default: /* FIXME: Not really, surely? */
624 if (process_command(card, port, skb))
626 spin_lock(&card->cli_queue_lock);
627 if (skb_queue_len(&card->cli_queue[port]) > 10) {
629 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
632 skb_queue_tail(&card->cli_queue[port], skb);
633 spin_unlock(&card->cli_queue_lock);
639 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
644 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
646 struct hlist_head *head;
647 struct atm_vcc *vcc = NULL;
648 struct hlist_node *node;
651 read_lock(&vcc_sklist_lock);
652 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
653 sk_for_each(s, node, head) {
655 if (vcc->dev == dev && vcc->vci == vci &&
656 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
661 read_unlock(&vcc_sklist_lock);
665 static int list_vccs(int vci)
667 struct hlist_head *head;
669 struct hlist_node *node;
674 read_lock(&vcc_sklist_lock);
676 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
677 sk_for_each(s, node, head) {
680 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
688 sk_for_each(s, node, head) {
691 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
698 read_unlock(&vcc_sklist_lock);
703 static int popen(struct atm_vcc *vcc)
705 struct solos_card *card = vcc->dev->dev_data;
707 struct pkt_hdr *header;
709 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
710 if (!skb && net_ratelimit()) {
711 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
714 header = (void *)skb_put(skb, sizeof(*header));
716 header->size = cpu_to_le16(0);
717 header->vpi = cpu_to_le16(vcc->vpi);
718 header->vci = cpu_to_le16(vcc->vci);
719 header->type = cpu_to_le16(PKT_POPEN);
721 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
723 // dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
724 set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
725 set_bit(ATM_VF_READY, &vcc->flags);
732 static void pclose(struct atm_vcc *vcc)
734 struct solos_card *card = vcc->dev->dev_data;
736 struct pkt_hdr *header;
738 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
740 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
743 header = (void *)skb_put(skb, sizeof(*header));
745 header->size = cpu_to_le16(0);
746 header->vpi = cpu_to_le16(vcc->vpi);
747 header->vci = cpu_to_le16(vcc->vci);
748 header->type = cpu_to_le16(PKT_PCLOSE);
750 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
752 // dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
754 clear_bit(ATM_VF_ADDR, &vcc->flags);
755 clear_bit(ATM_VF_READY, &vcc->flags);
760 static int print_buffer(struct sk_buff *buf)
767 for (i = 0; i < len; i++){
769 sprintf(msg, "%02X: ", i);
771 sprintf(item,"%02X ",*(buf->data + i));
776 printk(KERN_DEBUG "%s", msg);
782 printk(KERN_DEBUG "%s", msg);
784 printk(KERN_DEBUG "\n");
789 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
794 *(void **)skb->cb = vcc;
796 spin_lock(&card->tx_queue_lock);
797 old_len = skb_queue_len(&card->tx_queue[port]);
798 skb_queue_tail(&card->tx_queue[port], skb);
799 spin_unlock(&card->tx_queue_lock);
801 /* If TX might need to be started, do so */
806 static int fpga_tx(struct solos_card *card)
809 uint32_t tx_started = 0;
815 spin_lock_irqsave(&card->tx_lock, flags);
817 tx_pending = ioread32(card->config_regs + FLAGS_ADDR);
819 dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
821 for (port = 0; port < card->nr_ports; port++) {
822 if (!(tx_pending & (1 << port))) {
824 spin_lock(&card->tx_queue_lock);
825 skb = skb_dequeue(&card->tx_queue[port]);
826 spin_unlock(&card->tx_queue_lock);
832 dev_info(&card->dev->dev, "Transmitted: port %d\n",
836 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
838 vcc = *(void **)skb->cb;
841 atomic_inc(&vcc->stats->tx);
844 dev_kfree_skb_irq(skb);
846 tx_started |= 1 << port; //Set TX full flag
850 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
852 spin_unlock_irqrestore(&card->tx_lock, flags);
856 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
858 struct solos_card *card = vcc->dev->dev_data;
859 struct sk_buff *skb2 = NULL;
860 struct pkt_hdr *header;
863 //dev_dbg(&card->dev->dev, "psend called.\n");
864 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
867 skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
869 memcpy(skb2->data, skb->data, skb->len);
870 skb_put(skb2, skb->len);
871 vcc->push(vcc, skb2);
872 atomic_inc(&vcc->stats->rx);
874 atomic_inc(&vcc->stats->tx);
880 if (pktlen > (BUF_SIZE - sizeof(*header))) {
881 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
886 if (!skb_clone_writable(skb, sizeof(*header))) {
890 if (skb_headroom(skb) < sizeof(*header))
891 expand_by = sizeof(*header) - skb_headroom(skb);
893 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
895 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
901 header = (void *)skb_push(skb, sizeof(*header));
903 /* This does _not_ include the size of the header */
904 header->size = cpu_to_le16(pktlen);
905 header->vpi = cpu_to_le16(vcc->vpi);
906 header->vci = cpu_to_le16(vcc->vci);
907 header->type = cpu_to_le16(PKT_DATA);
909 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
914 static struct atmdev_ops fpga_ops = {
929 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
933 uint8_t major_ver, minor_ver;
935 struct solos_card *card;
940 card = kzalloc(sizeof(*card), GFP_KERNEL);
945 init_waitqueue_head(&card->fw_wq);
946 init_waitqueue_head(&card->param_wq);
948 err = pci_enable_device(dev);
950 dev_warn(&dev->dev, "Failed to enable PCI device\n");
954 err = pci_request_regions(dev, "solos");
956 dev_warn(&dev->dev, "Failed to request regions\n");
960 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
961 if (!card->config_regs) {
962 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
963 goto out_release_regions;
965 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
966 if (!card->buffers) {
967 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
968 goto out_unmap_config;
971 // for(i=0;i<64 ;i+=4){
972 // data32=ioread32(card->buffers + i);
973 // dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
976 //Fill Config Mem with zeros
977 for(i = 0; i < 128; i += 4)
978 iowrite32(0, card->config_regs + i);
981 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
983 data32 = ioread32(card->config_regs + FPGA_VER);
984 fpga_ver = (data32 & 0x0000FFFF);
985 major_ver = ((data32 & 0xFF000000) >> 24);
986 minor_ver = ((data32 & 0x00FF0000) >> 16);
987 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
988 major_ver, minor_ver, fpga_ver);
990 card->nr_ports = 2; /* FIXME: Detect daughterboard */
992 pci_set_drvdata(dev, card);
994 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
995 spin_lock_init(&card->tx_lock);
996 spin_lock_init(&card->tx_queue_lock);
997 spin_lock_init(&card->cli_queue_lock);
998 spin_lock_init(&card->param_queue_lock);
999 INIT_LIST_HEAD(&card->param_queue);
1002 // Set Loopback mode
1003 data32 = 0x00010000;
1004 iowrite32(data32,card->config_regs + FLAGS_ADDR);
1007 // Fill Buffers with zeros
1008 for (i = 0; i < BUF_SIZE * 8; i += 4)
1009 iowrite32(0, card->buffers + i);
1012 for(i = 0; i < (BUF_SIZE * 1); i += 4)
1013 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
1014 for(i = 0; i < (BUF_SIZE * 1); i += 4)
1015 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
1017 // Read Config Memory
1018 printk(KERN_DEBUG "Reading Config MEM\n");
1020 for(i = 0; i < 16; i++) {
1021 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
1022 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
1023 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
1024 (unsigned long)data32);
1027 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
1028 err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
1031 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
1032 goto out_unmap_both;
1036 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1039 flash_upgrade(card, 0);
1041 if (firmware_upgrade)
1042 flash_upgrade(card, 1);
1044 err = atm_init(card);
1051 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1052 free_irq(dev->irq, card);
1053 tasklet_kill(&card->tlet);
1056 pci_set_drvdata(dev, NULL);
1057 pci_iounmap(dev, card->config_regs);
1059 pci_iounmap(dev, card->buffers);
1060 out_release_regions:
1061 pci_release_regions(dev);
1066 static int atm_init(struct solos_card *card)
1070 for (i = 0; i < card->nr_ports; i++) {
1071 struct sk_buff *skb;
1072 struct pkt_hdr *header;
1074 skb_queue_head_init(&card->tx_queue[i]);
1075 skb_queue_head_init(&card->cli_queue[i]);
1077 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1078 if (!card->atmdev[i]) {
1079 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1083 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1084 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1085 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1086 dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1088 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1090 card->atmdev[i]->ci_range.vpi_bits = 8;
1091 card->atmdev[i]->ci_range.vci_bits = 16;
1092 card->atmdev[i]->dev_data = card;
1093 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1094 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1096 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1098 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1102 header = (void *)skb_put(skb, sizeof(*header));
1104 header->size = cpu_to_le16(0);
1105 header->vpi = cpu_to_le16(0);
1106 header->vci = cpu_to_le16(0);
1107 header->type = cpu_to_le16(PKT_STATUS);
1109 fpga_queue(card, i, skb, NULL);
1114 static void atm_remove(struct solos_card *card)
1118 for (i = 0; i < card->nr_ports; i++) {
1119 if (card->atmdev[i]) {
1120 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1121 atm_dev_deregister(card->atmdev[i]);
1126 static void fpga_remove(struct pci_dev *dev)
1128 struct solos_card *card = pci_get_drvdata(dev);
1135 dev_vdbg(&dev->dev, "Freeing IRQ\n");
1136 // Disable IRQs from FPGA
1137 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1138 free_irq(dev->irq, card);
1139 tasklet_kill(&card->tlet);
1141 // iowrite32(0x01,pciregs);
1142 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
1143 pci_iounmap(dev, card->buffers);
1144 pci_iounmap(dev, card->config_regs);
1146 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
1147 pci_release_regions(dev);
1148 pci_disable_device(dev);
1150 pci_set_drvdata(dev, NULL);
1152 // dev_dbg(&card->dev->dev, "fpga_remove\n");
1156 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1157 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1161 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1163 static struct pci_driver fpga_driver = {
1165 .id_table = fpga_pci_tbl,
1166 .probe = fpga_probe,
1167 .remove = fpga_remove,
1171 static int __init solos_pci_init(void)
1173 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1174 return pci_register_driver(&fpga_driver);
1177 static void __exit solos_pci_exit(void)
1179 pci_unregister_driver(&fpga_driver);
1180 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1183 module_init(solos_pci_init);
1184 module_exit(solos_pci_exit);