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
58 #define TX_DMA_ADDR(port) (0x40 + (4 * (port)))
59 #define RX_DMA_ADDR(port) (0x30 + (4 * (port)))
61 #define DATA_RAM_SIZE 32768
63 #define FPGA_PAGE 528 /* FPGA flash page size*/
64 #define SOLOS_PAGE 512 /* Solos flash page size*/
65 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
66 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
68 #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
69 #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
71 #define RX_DMA_SIZE 2048
74 static int atmdebug = 0;
75 static int firmware_upgrade = 0;
76 static int fpga_upgrade = 0;
91 #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb)
100 void __iomem *config_regs;
101 void __iomem *buffers;
105 struct atm_dev *atmdev[4];
106 struct tasklet_struct tlet;
108 spinlock_t tx_queue_lock;
109 spinlock_t cli_queue_lock;
110 spinlock_t param_queue_lock;
111 struct list_head param_queue;
112 struct sk_buff_head tx_queue[4];
113 struct sk_buff_head cli_queue[4];
114 struct sk_buff *tx_skb[4];
115 struct sk_buff *rx_skb[4];
116 wait_queue_head_t param_wq;
117 wait_queue_head_t fw_wq;
123 struct list_head list;
126 struct sk_buff *response;
129 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
131 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
132 MODULE_DESCRIPTION("Solos PCI driver");
133 MODULE_VERSION(VERSION);
134 MODULE_LICENSE("GPL");
135 MODULE_PARM_DESC(reset, "Reset Solos chips on startup");
136 MODULE_PARM_DESC(atmdebug, "Print ATM data");
137 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
138 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
139 module_param(reset, int, 0444);
140 module_param(atmdebug, int, 0644);
141 module_param(firmware_upgrade, int, 0444);
142 module_param(fpga_upgrade, int, 0444);
144 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
145 struct atm_vcc *vcc);
146 static uint32_t fpga_tx(struct solos_card *);
147 static irqreturn_t solos_irq(int irq, void *dev_id);
148 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
149 static int list_vccs(int vci);
150 static void release_vccs(struct atm_dev *dev);
151 static int atm_init(struct solos_card *);
152 static void atm_remove(struct solos_card *);
153 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
154 static void solos_bh(unsigned long);
155 static int print_buffer(struct sk_buff *buf);
157 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
162 dev_kfree_skb_any(skb);
165 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
168 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
169 struct solos_card *card = atmdev->dev_data;
170 struct solos_param prm;
172 struct pkt_hdr *header;
175 buflen = strlen(attr->attr.name) + 10;
177 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
179 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
183 header = (void *)skb_put(skb, sizeof(*header));
185 buflen = snprintf((void *)&header[1], buflen - 1,
186 "L%05d\n%s\n", current->pid, attr->attr.name);
187 skb_put(skb, buflen);
189 header->size = cpu_to_le16(buflen);
190 header->vpi = cpu_to_le16(0);
191 header->vci = cpu_to_le16(0);
192 header->type = cpu_to_le16(PKT_COMMAND);
194 prm.pid = current->pid;
196 prm.port = SOLOS_CHAN(atmdev);
198 spin_lock_irq(&card->param_queue_lock);
199 list_add(&prm.list, &card->param_queue);
200 spin_unlock_irq(&card->param_queue_lock);
202 fpga_queue(card, prm.port, skb, NULL);
204 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
206 spin_lock_irq(&card->param_queue_lock);
208 spin_unlock_irq(&card->param_queue_lock);
213 buflen = prm.response->len;
214 memcpy(buf, prm.response->data, buflen);
215 kfree_skb(prm.response);
220 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
221 const char *buf, size_t count)
223 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
224 struct solos_card *card = atmdev->dev_data;
225 struct solos_param prm;
227 struct pkt_hdr *header;
231 buflen = strlen(attr->attr.name) + 11 + count;
233 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
235 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
239 header = (void *)skb_put(skb, sizeof(*header));
241 buflen = snprintf((void *)&header[1], buflen - 1,
242 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
244 skb_put(skb, buflen);
245 header->size = cpu_to_le16(buflen);
246 header->vpi = cpu_to_le16(0);
247 header->vci = cpu_to_le16(0);
248 header->type = cpu_to_le16(PKT_COMMAND);
250 prm.pid = current->pid;
252 prm.port = SOLOS_CHAN(atmdev);
254 spin_lock_irq(&card->param_queue_lock);
255 list_add(&prm.list, &card->param_queue);
256 spin_unlock_irq(&card->param_queue_lock);
258 fpga_queue(card, prm.port, skb, NULL);
260 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
262 spin_lock_irq(&card->param_queue_lock);
264 spin_unlock_irq(&card->param_queue_lock);
273 /* Sometimes it has a newline, sometimes it doesn't. */
274 if (skb->data[buflen - 1] == '\n')
277 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
279 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
282 /* We know we have enough space allocated for this; we allocated
284 skb->data[buflen] = 0;
286 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
295 static char *next_string(struct sk_buff *skb)
298 char *this = skb->data;
300 for (i = 0; i < skb->len; i++) {
301 if (this[i] == '\n') {
303 skb_pull(skb, i + 1);
306 if (!isprint(this[i]))
313 * Status packet has fields separated by \n, starting with a version number
314 * for the information therein. Fields are....
317 * TxBitRate (version >= 1)
318 * RxBitRate (version >= 1)
319 * State (version >= 1)
321 static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
323 char *str, *end, *state_str;
324 int ver, rate_up, rate_down, state;
326 if (!card->atmdev[port])
329 str = next_string(skb);
333 ver = simple_strtol(str, NULL, 10);
335 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
340 str = next_string(skb);
343 rate_up = simple_strtol(str, &end, 10);
347 str = next_string(skb);
350 rate_down = simple_strtol(str, &end, 10);
354 state_str = next_string(skb);
357 if (!strcmp(state_str, "Showtime"))
358 state = ATM_PHY_SIG_FOUND;
360 state = ATM_PHY_SIG_LOST;
361 release_vccs(card->atmdev[port]);
364 if (state == ATM_PHY_SIG_LOST) {
365 dev_info(&card->dev->dev, "Port %d ATM state: %s\n",
370 snr = next_string(skb);
373 attn = next_string(skb);
377 dev_info(&card->dev->dev, "Port %d: %s (%d/%d kb/s%s%s%s%s)\n",
378 port, state_str, rate_down/1000, rate_up/1000,
379 snr[0]?", SNR ":"", snr, attn[0]?", Attn ":"", attn);
381 card->atmdev[port]->link_rate = rate_down / 424;
382 card->atmdev[port]->signal = state;
387 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
389 struct solos_param *prm;
397 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
398 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
399 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
400 skb->data[6] != '\n')
403 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
405 spin_lock_irqsave(&card->param_queue_lock, flags);
406 list_for_each_entry(prm, &card->param_queue, list) {
407 if (prm->port == port && prm->pid == cmdpid) {
410 wake_up(&card->param_wq);
415 spin_unlock_irqrestore(&card->param_queue_lock, flags);
419 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
422 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
423 struct solos_card *card = atmdev->dev_data;
426 spin_lock(&card->cli_queue_lock);
427 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
428 spin_unlock(&card->cli_queue_lock);
430 return sprintf(buf, "No data.\n");
432 memcpy(buf, skb->data, skb->len);
433 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
439 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
442 struct pkt_hdr *header;
444 if (size > (BUF_SIZE - sizeof(*header))) {
445 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
448 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
450 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
454 header = (void *)skb_put(skb, sizeof(*header));
456 header->size = cpu_to_le16(size);
457 header->vpi = cpu_to_le16(0);
458 header->vci = cpu_to_le16(0);
459 header->type = cpu_to_le16(PKT_COMMAND);
461 memcpy(skb_put(skb, size), buf, size);
463 fpga_queue(card, dev, skb, NULL);
468 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
469 const char *buf, size_t count)
471 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
472 struct solos_card *card = atmdev->dev_data;
475 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
480 static DEVICE_ATTR(console, 0644, console_show, console_store);
483 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
484 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
486 #include "solos-attrlist.c"
491 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
492 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
494 static struct attribute *solos_attrs[] = {
495 #include "solos-attrlist.c"
499 static struct attribute_group solos_attr_group = {
500 .attrs = solos_attrs,
501 .name = "parameters",
504 static int flash_upgrade(struct solos_card *card, int chip)
506 const struct firmware *fw;
514 fw_name = "solos-FPGA.bin";
515 blocksize = FPGA_BLOCK;
517 fw_name = "solos-Firmware.bin";
518 blocksize = SOLOS_BLOCK;
521 if (request_firmware(&fw, fw_name, &card->dev->dev))
524 dev_info(&card->dev->dev, "Flash upgrade starting\n");
526 numblocks = fw->size / blocksize;
527 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
528 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
530 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
531 iowrite32(1, card->config_regs + FPGA_MODE);
532 data32 = ioread32(card->config_regs + FPGA_MODE);
534 /* Set mode to Chip Erase */
535 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
536 chip?"Solos":"FPGA");
537 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
540 iowrite32(1, card->config_regs + WRITE_FLASH);
541 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
543 for (offset = 0; offset < fw->size; offset += blocksize) {
546 /* Clear write flag */
547 iowrite32(0, card->config_regs + WRITE_FLASH);
549 /* Set mode to Block Write */
550 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
551 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
553 /* Copy block to buffer, swapping each 16 bits */
554 for(i = 0; i < blocksize; i += 4) {
555 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
556 iowrite32(word, RX_BUF(card, 3) + i);
559 /* Specify block number and then trigger flash write */
560 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
561 iowrite32(1, card->config_regs + WRITE_FLASH);
562 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
565 release_firmware(fw);
566 iowrite32(0, card->config_regs + WRITE_FLASH);
567 iowrite32(0, card->config_regs + FPGA_MODE);
568 iowrite32(0, card->config_regs + FLASH_MODE);
569 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
573 static irqreturn_t solos_irq(int irq, void *dev_id)
575 struct solos_card *card = dev_id;
578 iowrite32(0, card->config_regs + IRQ_CLEAR);
580 /* If we're up and running, just kick the tasklet to process TX/RX */
582 tasklet_schedule(&card->tlet);
584 wake_up(&card->fw_wq);
586 return IRQ_RETVAL(handled);
589 void solos_bh(unsigned long card_arg)
591 struct solos_card *card = (void *)card_arg;
593 uint32_t rx_done = 0;
597 * Since fpga_tx() is going to need to read the flags under its lock,
598 * it can return them to us so that we don't have to hit PCI MMIO
599 * again for the same information
601 card_flags = fpga_tx(card);
603 for (port = 0; port < card->nr_ports; port++) {
604 if (card_flags & (0x10 << port)) {
605 struct pkt_hdr _hdr, *header;
610 if (card->using_dma) {
611 skb = card->rx_skb[port];
612 card->rx_skb[port] = NULL;
614 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
615 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
617 header = (void *)skb->data;
618 size = le16_to_cpu(header->size);
619 skb_put(skb, size + sizeof(*header));
620 skb_pull(skb, sizeof(*header));
624 rx_done |= 0x10 << port;
626 memcpy_fromio(header, RX_BUF(card, port), sizeof(*header));
628 size = le16_to_cpu(header->size);
630 skb = alloc_skb(size + 1, GFP_ATOMIC);
633 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
637 memcpy_fromio(skb_put(skb, size),
638 RX_BUF(card, port) + sizeof(*header),
642 dev_info(&card->dev->dev, "Received: device %d\n", port);
643 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
644 size, le16_to_cpu(header->vpi),
645 le16_to_cpu(header->vci));
649 switch (le16_to_cpu(header->type)) {
651 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi),
652 le16_to_cpu(header->vci));
655 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
656 le16_to_cpu(header->vci), le16_to_cpu(header->vpi),
660 atm_charge(vcc, skb->truesize);
662 atomic_inc(&vcc->stats->rx);
666 process_status(card, port, skb);
667 dev_kfree_skb_any(skb);
671 default: /* FIXME: Not really, surely? */
672 if (process_command(card, port, skb))
674 spin_lock(&card->cli_queue_lock);
675 if (skb_queue_len(&card->cli_queue[port]) > 10) {
677 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
679 dev_kfree_skb_any(skb);
681 skb_queue_tail(&card->cli_queue[port], skb);
682 spin_unlock(&card->cli_queue_lock);
686 /* Allocate RX skbs for any ports which need them */
687 if (card->using_dma && card->atmdev[port] &&
688 !card->rx_skb[port]) {
689 struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
691 SKB_CB(skb)->dma_addr =
692 pci_map_single(card->dev, skb->data,
693 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
694 iowrite32(SKB_CB(skb)->dma_addr,
695 card->config_regs + RX_DMA_ADDR(port));
696 card->rx_skb[port] = skb;
699 dev_warn(&card->dev->dev, "Failed to allocate RX skb");
701 /* We'll have to try again later */
702 tasklet_schedule(&card->tlet);
707 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
712 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
714 struct hlist_head *head;
715 struct atm_vcc *vcc = NULL;
716 struct hlist_node *node;
719 read_lock(&vcc_sklist_lock);
720 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
721 sk_for_each(s, node, head) {
723 if (vcc->dev == dev && vcc->vci == vci &&
724 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
729 read_unlock(&vcc_sklist_lock);
733 static int list_vccs(int vci)
735 struct hlist_head *head;
737 struct hlist_node *node;
742 read_lock(&vcc_sklist_lock);
744 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
745 sk_for_each(s, node, head) {
748 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
754 for(i = 0; i < VCC_HTABLE_SIZE; i++){
756 sk_for_each(s, node, head) {
759 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
766 read_unlock(&vcc_sklist_lock);
770 static void release_vccs(struct atm_dev *dev)
774 write_lock_irq(&vcc_sklist_lock);
775 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
776 struct hlist_head *head = &vcc_hash[i];
777 struct hlist_node *node, *tmp;
781 sk_for_each_safe(s, node, tmp, head) {
783 if (vcc->dev == dev) {
784 vcc_release_async(vcc, -EPIPE);
789 write_unlock_irq(&vcc_sklist_lock);
793 static int popen(struct atm_vcc *vcc)
795 struct solos_card *card = vcc->dev->dev_data;
797 struct pkt_hdr *header;
799 if (vcc->qos.aal != ATM_AAL5) {
800 dev_warn(&card->dev->dev, "Unsupported ATM type %d\n",
805 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
806 if (!skb && net_ratelimit()) {
807 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
810 header = (void *)skb_put(skb, sizeof(*header));
812 header->size = cpu_to_le16(0);
813 header->vpi = cpu_to_le16(vcc->vpi);
814 header->vci = cpu_to_le16(vcc->vci);
815 header->type = cpu_to_le16(PKT_POPEN);
817 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
819 set_bit(ATM_VF_ADDR, &vcc->flags);
820 set_bit(ATM_VF_READY, &vcc->flags);
827 static void pclose(struct atm_vcc *vcc)
829 struct solos_card *card = vcc->dev->dev_data;
831 struct pkt_hdr *header;
833 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
835 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
838 header = (void *)skb_put(skb, sizeof(*header));
840 header->size = cpu_to_le16(0);
841 header->vpi = cpu_to_le16(vcc->vpi);
842 header->vci = cpu_to_le16(vcc->vci);
843 header->type = cpu_to_le16(PKT_PCLOSE);
845 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
847 clear_bit(ATM_VF_ADDR, &vcc->flags);
848 clear_bit(ATM_VF_READY, &vcc->flags);
853 static int print_buffer(struct sk_buff *buf)
860 for (i = 0; i < len; i++){
862 sprintf(msg, "%02X: ", i);
864 sprintf(item,"%02X ",*(buf->data + i));
869 printk(KERN_DEBUG "%s", msg);
875 printk(KERN_DEBUG "%s", msg);
877 printk(KERN_DEBUG "\n");
882 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
888 SKB_CB(skb)->vcc = vcc;
890 spin_lock_irqsave(&card->tx_queue_lock, flags);
891 old_len = skb_queue_len(&card->tx_queue[port]);
892 skb_queue_tail(&card->tx_queue[port], skb);
894 card->tx_mask |= (1 << port);
895 spin_unlock_irqrestore(&card->tx_queue_lock, flags);
897 /* Theoretically we could just schedule the tasklet here, but
898 that introduces latency we don't want -- it's noticeable */
903 static uint32_t fpga_tx(struct solos_card *card)
905 uint32_t tx_pending, card_flags;
906 uint32_t tx_started = 0;
912 spin_lock_irqsave(&card->tx_lock, flags);
914 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
916 * The queue lock is required for _writing_ to tx_mask, but we're
917 * OK to read it here without locking. The only potential update
918 * that we could race with is in fpga_queue() where it sets a bit
919 * for a new port... but it's going to call this function again if
920 * it's doing that, anyway.
922 tx_pending = card->tx_mask & ~card_flags;
924 for (port = 0; tx_pending; tx_pending >>= 1, port++) {
925 if (tx_pending & 1) {
926 struct sk_buff *oldskb = card->tx_skb[port];
928 pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
929 oldskb->len, PCI_DMA_TODEVICE);
931 spin_lock(&card->tx_queue_lock);
932 skb = skb_dequeue(&card->tx_queue[port]);
934 card->tx_mask &= ~(1 << port);
935 spin_unlock(&card->tx_queue_lock);
937 if (skb && !card->using_dma) {
938 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
939 tx_started |= 1 << port;
940 oldskb = skb; /* We're done with this skb already */
941 } else if (skb && card->using_dma) {
942 SKB_CB(skb)->dma_addr = pci_map_single(card->dev, skb->data,
943 skb->len, PCI_DMA_TODEVICE);
944 iowrite32(SKB_CB(skb)->dma_addr,
945 card->config_regs + TX_DMA_ADDR(port));
951 /* Clean up and free oldskb now it's gone */
953 dev_info(&card->dev->dev, "Transmitted: port %d\n",
955 print_buffer(oldskb);
958 vcc = SKB_CB(oldskb)->vcc;
961 atomic_inc(&vcc->stats->tx);
962 solos_pop(vcc, oldskb);
964 dev_kfree_skb_irq(oldskb);
968 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
970 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
972 spin_unlock_irqrestore(&card->tx_lock, flags);
976 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
978 struct solos_card *card = vcc->dev->dev_data;
979 struct pkt_hdr *header;
983 if (pktlen > (BUF_SIZE - sizeof(*header))) {
984 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
989 if (!skb_clone_writable(skb, sizeof(*header))) {
993 if (skb_headroom(skb) < sizeof(*header))
994 expand_by = sizeof(*header) - skb_headroom(skb);
996 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
998 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
1004 header = (void *)skb_push(skb, sizeof(*header));
1006 /* This does _not_ include the size of the header */
1007 header->size = cpu_to_le16(pktlen);
1008 header->vpi = cpu_to_le16(vcc->vpi);
1009 header->vci = cpu_to_le16(vcc->vci);
1010 header->type = cpu_to_le16(PKT_DATA);
1012 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
1017 static struct atmdev_ops fpga_ops = {
1029 .owner = THIS_MODULE
1032 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1036 uint8_t major_ver, minor_ver;
1038 struct solos_card *card;
1040 card = kzalloc(sizeof(*card), GFP_KERNEL);
1045 init_waitqueue_head(&card->fw_wq);
1046 init_waitqueue_head(&card->param_wq);
1048 err = pci_enable_device(dev);
1050 dev_warn(&dev->dev, "Failed to enable PCI device\n");
1054 err = pci_set_dma_mask(dev, DMA_32BIT_MASK);
1056 dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n");
1060 err = pci_request_regions(dev, "solos");
1062 dev_warn(&dev->dev, "Failed to request regions\n");
1066 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1067 if (!card->config_regs) {
1068 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1069 goto out_release_regions;
1071 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1072 if (!card->buffers) {
1073 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1074 goto out_unmap_config;
1078 iowrite32(1, card->config_regs + FPGA_MODE);
1079 data32 = ioread32(card->config_regs + FPGA_MODE);
1081 iowrite32(0, card->config_regs + FPGA_MODE);
1082 data32 = ioread32(card->config_regs + FPGA_MODE);
1084 //Fill Config Mem with zeros
1085 for(i = 0; i < 128; i += 4)
1086 iowrite32(0, card->config_regs + i);
1088 //Set RX empty flags
1089 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
1091 data32 = ioread32(card->config_regs + FPGA_VER);
1092 fpga_ver = (data32 & 0x0000FFFF);
1093 major_ver = ((data32 & 0xFF000000) >> 24);
1094 minor_ver = ((data32 & 0x00FF0000) >> 16);
1095 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1096 major_ver, minor_ver, fpga_ver);
1099 card->using_dma = 1;
1101 card->nr_ports = 2; /* FIXME: Detect daughterboard */
1103 pci_set_drvdata(dev, card);
1105 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
1106 spin_lock_init(&card->tx_lock);
1107 spin_lock_init(&card->tx_queue_lock);
1108 spin_lock_init(&card->cli_queue_lock);
1109 spin_lock_init(&card->param_queue_lock);
1110 INIT_LIST_HEAD(&card->param_queue);
1112 err = request_irq(dev->irq, solos_irq, IRQF_SHARED,
1115 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
1116 goto out_unmap_both;
1119 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1122 flash_upgrade(card, 0);
1124 if (firmware_upgrade)
1125 flash_upgrade(card, 1);
1127 err = atm_init(card);
1134 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1135 free_irq(dev->irq, card);
1136 tasklet_kill(&card->tlet);
1139 pci_set_drvdata(dev, NULL);
1140 pci_iounmap(dev, card->config_regs);
1142 pci_iounmap(dev, card->buffers);
1143 out_release_regions:
1144 pci_release_regions(dev);
1149 static int atm_init(struct solos_card *card)
1153 for (i = 0; i < card->nr_ports; i++) {
1154 struct sk_buff *skb;
1155 struct pkt_hdr *header;
1157 skb_queue_head_init(&card->tx_queue[i]);
1158 skb_queue_head_init(&card->cli_queue[i]);
1160 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1161 if (!card->atmdev[i]) {
1162 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1166 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1167 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1168 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1169 dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1171 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1173 card->atmdev[i]->ci_range.vpi_bits = 8;
1174 card->atmdev[i]->ci_range.vci_bits = 16;
1175 card->atmdev[i]->dev_data = card;
1176 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1177 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1179 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1181 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1185 header = (void *)skb_put(skb, sizeof(*header));
1187 header->size = cpu_to_le16(0);
1188 header->vpi = cpu_to_le16(0);
1189 header->vci = cpu_to_le16(0);
1190 header->type = cpu_to_le16(PKT_STATUS);
1192 fpga_queue(card, i, skb, NULL);
1197 static void atm_remove(struct solos_card *card)
1201 for (i = 0; i < card->nr_ports; i++) {
1202 if (card->atmdev[i]) {
1203 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1205 sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group);
1206 atm_dev_deregister(card->atmdev[i]);
1211 static void fpga_remove(struct pci_dev *dev)
1213 struct solos_card *card = pci_get_drvdata(dev);
1217 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1218 free_irq(dev->irq, card);
1219 tasklet_kill(&card->tlet);
1221 pci_iounmap(dev, card->buffers);
1222 pci_iounmap(dev, card->config_regs);
1224 pci_release_regions(dev);
1225 pci_disable_device(dev);
1227 pci_set_drvdata(dev, NULL);
1231 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1232 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1236 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1238 static struct pci_driver fpga_driver = {
1240 .id_table = fpga_pci_tbl,
1241 .probe = fpga_probe,
1242 .remove = fpga_remove,
1246 static int __init solos_pci_init(void)
1248 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1249 return pci_register_driver(&fpga_driver);
1252 static void __exit solos_pci_exit(void)
1254 pci_unregister_driver(&fpga_driver);
1255 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1258 module_init(solos_pci_init);
1259 module_exit(solos_pci_exit);