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>
43 #include <linux/slab.h>
45 #define VERSION "0.07"
46 #define PTAG "solos-pci"
48 #define CONFIG_RAM_SIZE 128
49 #define FLAGS_ADDR 0x7C
50 #define IRQ_EN_ADDR 0x78
52 #define IRQ_CLEAR 0x70
53 #define WRITE_FLASH 0x6C
55 #define FLASH_BLOCK 0x64
56 #define FLASH_BUSY 0x60
57 #define FPGA_MODE 0x5C
58 #define FLASH_MODE 0x58
59 #define TX_DMA_ADDR(port) (0x40 + (4 * (port)))
60 #define RX_DMA_ADDR(port) (0x30 + (4 * (port)))
62 #define DATA_RAM_SIZE 32768
64 #define OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/
65 #define FPGA_PAGE 528 /* FPGA flash page size*/
66 #define SOLOS_PAGE 512 /* Solos flash page size*/
67 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
68 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
70 #define RX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2)
71 #define TX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size))
72 #define FLASH_BUF ((card->buffers) + 4*(card->buffer_size)*2)
74 #define RX_DMA_SIZE 2048
76 #define FPGA_VERSION(a,b) (((a) << 8) + (b))
77 #define LEGACY_BUFFERS 2
78 #define DMA_SUPPORTED 4
81 static int atmdebug
= 0;
82 static int firmware_upgrade
= 0;
83 static int fpga_upgrade
= 0;
84 static int db_firmware_upgrade
= 0;
85 static int db_fpga_upgrade
= 0;
100 #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb)
103 #define PKT_COMMAND 1
109 void __iomem
*config_regs
;
110 void __iomem
*buffers
;
114 struct atm_dev
*atmdev
[4];
115 struct tasklet_struct tlet
;
117 spinlock_t tx_queue_lock
;
118 spinlock_t cli_queue_lock
;
119 spinlock_t param_queue_lock
;
120 struct list_head param_queue
;
121 struct sk_buff_head tx_queue
[4];
122 struct sk_buff_head cli_queue
[4];
123 struct sk_buff
*tx_skb
[4];
124 struct sk_buff
*rx_skb
[4];
125 wait_queue_head_t param_wq
;
126 wait_queue_head_t fw_wq
;
134 struct list_head list
;
137 struct sk_buff
*response
;
140 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
142 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
143 MODULE_DESCRIPTION("Solos PCI driver");
144 MODULE_VERSION(VERSION
);
145 MODULE_LICENSE("GPL");
146 MODULE_FIRMWARE("solos-FPGA.bin");
147 MODULE_FIRMWARE("solos-Firmware.bin");
148 MODULE_FIRMWARE("solos-db-FPGA.bin");
149 MODULE_PARM_DESC(reset
, "Reset Solos chips on startup");
150 MODULE_PARM_DESC(atmdebug
, "Print ATM data");
151 MODULE_PARM_DESC(firmware_upgrade
, "Initiate Solos firmware upgrade");
152 MODULE_PARM_DESC(fpga_upgrade
, "Initiate FPGA upgrade");
153 MODULE_PARM_DESC(db_firmware_upgrade
, "Initiate daughter board Solos firmware upgrade");
154 MODULE_PARM_DESC(db_fpga_upgrade
, "Initiate daughter board FPGA upgrade");
155 module_param(reset
, int, 0444);
156 module_param(atmdebug
, int, 0644);
157 module_param(firmware_upgrade
, int, 0444);
158 module_param(fpga_upgrade
, int, 0444);
159 module_param(db_firmware_upgrade
, int, 0444);
160 module_param(db_fpga_upgrade
, int, 0444);
162 static void fpga_queue(struct solos_card
*card
, int port
, struct sk_buff
*skb
,
163 struct atm_vcc
*vcc
);
164 static uint32_t fpga_tx(struct solos_card
*);
165 static irqreturn_t
solos_irq(int irq
, void *dev_id
);
166 static struct atm_vcc
* find_vcc(struct atm_dev
*dev
, short vpi
, int vci
);
167 static int atm_init(struct solos_card
*, struct device
*);
168 static void atm_remove(struct solos_card
*);
169 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
);
170 static void solos_bh(unsigned long);
171 static int print_buffer(struct sk_buff
*buf
);
173 static inline void solos_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
178 dev_kfree_skb_any(skb
);
181 static ssize_t
solos_param_show(struct device
*dev
, struct device_attribute
*attr
,
184 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
185 struct solos_card
*card
= atmdev
->dev_data
;
186 struct solos_param prm
;
188 struct pkt_hdr
*header
;
191 buflen
= strlen(attr
->attr
.name
) + 10;
193 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
195 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_show()\n");
199 header
= (void *)skb_put(skb
, sizeof(*header
));
201 buflen
= snprintf((void *)&header
[1], buflen
- 1,
202 "L%05d\n%s\n", current
->pid
, attr
->attr
.name
);
203 skb_put(skb
, buflen
);
205 header
->size
= cpu_to_le16(buflen
);
206 header
->vpi
= cpu_to_le16(0);
207 header
->vci
= cpu_to_le16(0);
208 header
->type
= cpu_to_le16(PKT_COMMAND
);
210 prm
.pid
= current
->pid
;
212 prm
.port
= SOLOS_CHAN(atmdev
);
214 spin_lock_irq(&card
->param_queue_lock
);
215 list_add(&prm
.list
, &card
->param_queue
);
216 spin_unlock_irq(&card
->param_queue_lock
);
218 fpga_queue(card
, prm
.port
, skb
, NULL
);
220 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
222 spin_lock_irq(&card
->param_queue_lock
);
224 spin_unlock_irq(&card
->param_queue_lock
);
229 buflen
= prm
.response
->len
;
230 memcpy(buf
, prm
.response
->data
, buflen
);
231 kfree_skb(prm
.response
);
236 static ssize_t
solos_param_store(struct device
*dev
, struct device_attribute
*attr
,
237 const char *buf
, size_t count
)
239 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
240 struct solos_card
*card
= atmdev
->dev_data
;
241 struct solos_param prm
;
243 struct pkt_hdr
*header
;
247 buflen
= strlen(attr
->attr
.name
) + 11 + count
;
249 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
251 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_store()\n");
255 header
= (void *)skb_put(skb
, sizeof(*header
));
257 buflen
= snprintf((void *)&header
[1], buflen
- 1,
258 "L%05d\n%s\n%s\n", current
->pid
, attr
->attr
.name
, buf
);
260 skb_put(skb
, buflen
);
261 header
->size
= cpu_to_le16(buflen
);
262 header
->vpi
= cpu_to_le16(0);
263 header
->vci
= cpu_to_le16(0);
264 header
->type
= cpu_to_le16(PKT_COMMAND
);
266 prm
.pid
= current
->pid
;
268 prm
.port
= SOLOS_CHAN(atmdev
);
270 spin_lock_irq(&card
->param_queue_lock
);
271 list_add(&prm
.list
, &card
->param_queue
);
272 spin_unlock_irq(&card
->param_queue_lock
);
274 fpga_queue(card
, prm
.port
, skb
, NULL
);
276 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
278 spin_lock_irq(&card
->param_queue_lock
);
280 spin_unlock_irq(&card
->param_queue_lock
);
289 /* Sometimes it has a newline, sometimes it doesn't. */
290 if (skb
->data
[buflen
- 1] == '\n')
293 if (buflen
== 2 && !strncmp(skb
->data
, "OK", 2))
295 else if (buflen
== 5 && !strncmp(skb
->data
, "ERROR", 5))
298 /* We know we have enough space allocated for this; we allocated
300 skb
->data
[buflen
] = 0;
302 dev_warn(&card
->dev
->dev
, "Unexpected parameter response: '%s'\n",
311 static char *next_string(struct sk_buff
*skb
)
314 char *this = skb
->data
;
316 for (i
= 0; i
< skb
->len
; i
++) {
317 if (this[i
] == '\n') {
319 skb_pull(skb
, i
+ 1);
322 if (!isprint(this[i
]))
329 * Status packet has fields separated by \n, starting with a version number
330 * for the information therein. Fields are....
333 * RxBitRate (version >= 1)
334 * TxBitRate (version >= 1)
335 * State (version >= 1)
336 * LocalSNRMargin (version >= 1)
337 * LocalLineAttn (version >= 1)
339 static int process_status(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
341 char *str
, *end
, *state_str
, *snr
, *attn
;
342 int ver
, rate_up
, rate_down
;
344 if (!card
->atmdev
[port
])
347 str
= next_string(skb
);
351 ver
= simple_strtol(str
, NULL
, 10);
353 dev_warn(&card
->dev
->dev
, "Unexpected status interrupt version %d\n",
358 str
= next_string(skb
);
361 if (!strcmp(str
, "ERROR")) {
362 dev_dbg(&card
->dev
->dev
, "Status packet indicated Solos error on port %d (starting up?)\n",
367 rate_down
= simple_strtol(str
, &end
, 10);
371 str
= next_string(skb
);
374 rate_up
= simple_strtol(str
, &end
, 10);
378 state_str
= next_string(skb
);
382 /* Anything but 'Showtime' is down */
383 if (strcmp(state_str
, "Showtime")) {
384 atm_dev_signal_change(card
->atmdev
[port
], ATM_PHY_SIG_LOST
);
385 dev_info(&card
->dev
->dev
, "Port %d: %s\n", port
, state_str
);
389 snr
= next_string(skb
);
392 attn
= next_string(skb
);
396 dev_info(&card
->dev
->dev
, "Port %d: %s @%d/%d kb/s%s%s%s%s\n",
397 port
, state_str
, rate_down
/1000, rate_up
/1000,
398 snr
[0]?", SNR ":"", snr
, attn
[0]?", Attn ":"", attn
);
400 card
->atmdev
[port
]->link_rate
= rate_down
/ 424;
401 atm_dev_signal_change(card
->atmdev
[port
], ATM_PHY_SIG_FOUND
);
406 static int process_command(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
408 struct solos_param
*prm
;
416 if (skb
->data
[0] != 'L' || !isdigit(skb
->data
[1]) ||
417 !isdigit(skb
->data
[2]) || !isdigit(skb
->data
[3]) ||
418 !isdigit(skb
->data
[4]) || !isdigit(skb
->data
[5]) ||
419 skb
->data
[6] != '\n')
422 cmdpid
= simple_strtol(&skb
->data
[1], NULL
, 10);
424 spin_lock_irqsave(&card
->param_queue_lock
, flags
);
425 list_for_each_entry(prm
, &card
->param_queue
, list
) {
426 if (prm
->port
== port
&& prm
->pid
== cmdpid
) {
429 wake_up(&card
->param_wq
);
434 spin_unlock_irqrestore(&card
->param_queue_lock
, flags
);
438 static ssize_t
console_show(struct device
*dev
, struct device_attribute
*attr
,
441 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
442 struct solos_card
*card
= atmdev
->dev_data
;
446 spin_lock(&card
->cli_queue_lock
);
447 skb
= skb_dequeue(&card
->cli_queue
[SOLOS_CHAN(atmdev
)]);
448 spin_unlock(&card
->cli_queue_lock
);
450 return sprintf(buf
, "No data.\n");
453 memcpy(buf
, skb
->data
, len
);
454 dev_dbg(&card
->dev
->dev
, "len: %d\n", len
);
460 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
)
463 struct pkt_hdr
*header
;
465 if (size
> (BUF_SIZE
- sizeof(*header
))) {
466 dev_dbg(&card
->dev
->dev
, "Command is too big. Dropping request\n");
469 skb
= alloc_skb(size
+ sizeof(*header
), GFP_ATOMIC
);
471 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in send_command()\n");
475 header
= (void *)skb_put(skb
, sizeof(*header
));
477 header
->size
= cpu_to_le16(size
);
478 header
->vpi
= cpu_to_le16(0);
479 header
->vci
= cpu_to_le16(0);
480 header
->type
= cpu_to_le16(PKT_COMMAND
);
482 memcpy(skb_put(skb
, size
), buf
, size
);
484 fpga_queue(card
, dev
, skb
, NULL
);
489 static ssize_t
console_store(struct device
*dev
, struct device_attribute
*attr
,
490 const char *buf
, size_t count
)
492 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
493 struct solos_card
*card
= atmdev
->dev_data
;
496 err
= send_command(card
, SOLOS_CHAN(atmdev
), buf
, count
);
501 static DEVICE_ATTR(console
, 0644, console_show
, console_store
);
504 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
505 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
507 #include "solos-attrlist.c"
512 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
513 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
515 static struct attribute
*solos_attrs
[] = {
516 #include "solos-attrlist.c"
520 static struct attribute_group solos_attr_group
= {
521 .attrs
= solos_attrs
,
522 .name
= "parameters",
525 static int flash_upgrade(struct solos_card
*card
, int chip
)
527 const struct firmware
*fw
;
535 fw_name
= "solos-FPGA.bin";
536 blocksize
= FPGA_BLOCK
;
539 fw_name
= "solos-Firmware.bin";
540 blocksize
= SOLOS_BLOCK
;
543 if (card
->fpga_version
> LEGACY_BUFFERS
){
544 fw_name
= "solos-db-FPGA.bin";
545 blocksize
= FPGA_BLOCK
;
547 dev_info(&card
->dev
->dev
, "FPGA version doesn't support"
548 " daughter board upgrades\n");
553 if (card
->fpga_version
> LEGACY_BUFFERS
){
554 fw_name
= "solos-Firmware.bin";
555 blocksize
= SOLOS_BLOCK
;
557 dev_info(&card
->dev
->dev
, "FPGA version doesn't support"
558 " daughter board upgrades\n");
566 if (request_firmware(&fw
, fw_name
, &card
->dev
->dev
))
569 dev_info(&card
->dev
->dev
, "Flash upgrade starting\n");
571 numblocks
= fw
->size
/ blocksize
;
572 dev_info(&card
->dev
->dev
, "Firmware size: %zd\n", fw
->size
);
573 dev_info(&card
->dev
->dev
, "Number of blocks: %d\n", numblocks
);
575 dev_info(&card
->dev
->dev
, "Changing FPGA to Update mode\n");
576 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
577 (void) ioread32(card
->config_regs
+ FPGA_MODE
);
579 /* Set mode to Chip Erase */
580 if(chip
== 0 || chip
== 2)
581 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to FPGA Chip Erase\n");
582 if(chip
== 1 || chip
== 3)
583 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to Solos Chip Erase\n");
584 iowrite32((chip
* 2), card
->config_regs
+ FLASH_MODE
);
587 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
588 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
590 for (offset
= 0; offset
< fw
->size
; offset
+= blocksize
) {
593 /* Clear write flag */
594 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
596 /* Set mode to Block Write */
597 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
598 iowrite32(((chip
* 2) + 1), card
->config_regs
+ FLASH_MODE
);
600 /* Copy block to buffer, swapping each 16 bits */
601 for(i
= 0; i
< blocksize
; i
+= 4) {
602 uint32_t word
= swahb32p((uint32_t *)(fw
->data
+ offset
+ i
));
603 if(card
->fpga_version
> LEGACY_BUFFERS
)
604 iowrite32(word
, FLASH_BUF
+ i
);
606 iowrite32(word
, RX_BUF(card
, 3) + i
);
609 /* Specify block number and then trigger flash write */
610 iowrite32(offset
/ blocksize
, card
->config_regs
+ FLASH_BLOCK
);
611 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
612 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
615 release_firmware(fw
);
616 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
617 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
618 iowrite32(0, card
->config_regs
+ FLASH_MODE
);
619 dev_info(&card
->dev
->dev
, "Returning FPGA to Data mode\n");
623 static irqreturn_t
solos_irq(int irq
, void *dev_id
)
625 struct solos_card
*card
= dev_id
;
628 iowrite32(0, card
->config_regs
+ IRQ_CLEAR
);
630 /* If we're up and running, just kick the tasklet to process TX/RX */
632 tasklet_schedule(&card
->tlet
);
634 wake_up(&card
->fw_wq
);
636 return IRQ_RETVAL(handled
);
639 void solos_bh(unsigned long card_arg
)
641 struct solos_card
*card
= (void *)card_arg
;
643 uint32_t rx_done
= 0;
647 * Since fpga_tx() is going to need to read the flags under its lock,
648 * it can return them to us so that we don't have to hit PCI MMIO
649 * again for the same information
651 card_flags
= fpga_tx(card
);
653 for (port
= 0; port
< card
->nr_ports
; port
++) {
654 if (card_flags
& (0x10 << port
)) {
655 struct pkt_hdr _hdr
, *header
;
660 if (card
->using_dma
) {
661 skb
= card
->rx_skb
[port
];
662 card
->rx_skb
[port
] = NULL
;
664 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
665 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
667 header
= (void *)skb
->data
;
668 size
= le16_to_cpu(header
->size
);
669 skb_put(skb
, size
+ sizeof(*header
));
670 skb_pull(skb
, sizeof(*header
));
674 rx_done
|= 0x10 << port
;
676 memcpy_fromio(header
, RX_BUF(card
, port
), sizeof(*header
));
678 size
= le16_to_cpu(header
->size
);
679 if (size
> (card
->buffer_size
- sizeof(*header
))){
680 dev_warn(&card
->dev
->dev
, "Invalid buffer size\n");
684 skb
= alloc_skb(size
+ 1, GFP_ATOMIC
);
687 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff for RX\n");
691 memcpy_fromio(skb_put(skb
, size
),
692 RX_BUF(card
, port
) + sizeof(*header
),
696 dev_info(&card
->dev
->dev
, "Received: port %d\n", port
);
697 dev_info(&card
->dev
->dev
, "size: %d VPI: %d VCI: %d\n",
698 size
, le16_to_cpu(header
->vpi
),
699 le16_to_cpu(header
->vci
));
703 switch (le16_to_cpu(header
->type
)) {
705 vcc
= find_vcc(card
->atmdev
[port
], le16_to_cpu(header
->vpi
),
706 le16_to_cpu(header
->vci
));
709 dev_warn(&card
->dev
->dev
, "Received packet for unknown VPI.VCI %d.%d on port %d\n",
710 le16_to_cpu(header
->vpi
), le16_to_cpu(header
->vci
),
712 dev_kfree_skb_any(skb
);
715 atm_charge(vcc
, skb
->truesize
);
717 atomic_inc(&vcc
->stats
->rx
);
721 if (process_status(card
, port
, skb
) &&
723 dev_warn(&card
->dev
->dev
, "Bad status packet of %d bytes on port %d:\n", skb
->len
, port
);
726 dev_kfree_skb_any(skb
);
730 default: /* FIXME: Not really, surely? */
731 if (process_command(card
, port
, skb
))
733 spin_lock(&card
->cli_queue_lock
);
734 if (skb_queue_len(&card
->cli_queue
[port
]) > 10) {
736 dev_warn(&card
->dev
->dev
, "Dropping console response on port %d\n",
738 dev_kfree_skb_any(skb
);
740 skb_queue_tail(&card
->cli_queue
[port
], skb
);
741 spin_unlock(&card
->cli_queue_lock
);
745 /* Allocate RX skbs for any ports which need them */
746 if (card
->using_dma
&& card
->atmdev
[port
] &&
747 !card
->rx_skb
[port
]) {
748 struct sk_buff
*skb
= alloc_skb(RX_DMA_SIZE
, GFP_ATOMIC
);
750 SKB_CB(skb
)->dma_addr
=
751 pci_map_single(card
->dev
, skb
->data
,
752 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
753 iowrite32(SKB_CB(skb
)->dma_addr
,
754 card
->config_regs
+ RX_DMA_ADDR(port
));
755 card
->rx_skb
[port
] = skb
;
758 dev_warn(&card
->dev
->dev
, "Failed to allocate RX skb");
760 /* We'll have to try again later */
761 tasklet_schedule(&card
->tlet
);
766 iowrite32(rx_done
, card
->config_regs
+ FLAGS_ADDR
);
771 static struct atm_vcc
*find_vcc(struct atm_dev
*dev
, short vpi
, int vci
)
773 struct hlist_head
*head
;
774 struct atm_vcc
*vcc
= NULL
;
775 struct hlist_node
*node
;
778 read_lock(&vcc_sklist_lock
);
779 head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
-1)];
780 sk_for_each(s
, node
, head
) {
782 if (vcc
->dev
== dev
&& vcc
->vci
== vci
&&
783 vcc
->vpi
== vpi
&& vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
784 test_bit(ATM_VF_READY
, &vcc
->flags
))
789 read_unlock(&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_KERNEL
);
808 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in popen()\n");
811 header
= (void *)skb_put(skb
, sizeof(*header
));
813 header
->size
= cpu_to_le16(0);
814 header
->vpi
= cpu_to_le16(vcc
->vpi
);
815 header
->vci
= cpu_to_le16(vcc
->vci
);
816 header
->type
= cpu_to_le16(PKT_POPEN
);
818 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, NULL
);
820 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
821 set_bit(ATM_VF_READY
, &vcc
->flags
);
826 static void pclose(struct atm_vcc
*vcc
)
828 struct solos_card
*card
= vcc
->dev
->dev_data
;
829 unsigned char port
= SOLOS_CHAN(vcc
->dev
);
830 struct sk_buff
*skb
, *tmpskb
;
831 struct pkt_hdr
*header
;
833 /* Remove any yet-to-be-transmitted packets from the pending queue */
834 spin_lock(&card
->tx_queue_lock
);
835 skb_queue_walk_safe(&card
->tx_queue
[port
], skb
, tmpskb
) {
836 if (SKB_CB(skb
)->vcc
== vcc
) {
837 skb_unlink(skb
, &card
->tx_queue
[port
]);
841 spin_unlock(&card
->tx_queue_lock
);
843 skb
= alloc_skb(sizeof(*header
), GFP_KERNEL
);
845 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in pclose()\n");
848 header
= (void *)skb_put(skb
, sizeof(*header
));
850 header
->size
= cpu_to_le16(0);
851 header
->vpi
= cpu_to_le16(vcc
->vpi
);
852 header
->vci
= cpu_to_le16(vcc
->vci
);
853 header
->type
= cpu_to_le16(PKT_PCLOSE
);
856 fpga_queue(card
, port
, skb
, NULL
);
858 if (!wait_event_timeout(card
->param_wq
, !skb_shared(skb
), 5 * HZ
))
859 dev_warn(&card
->dev
->dev
,
860 "Timeout waiting for VCC close on port %d\n", port
);
864 /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the
865 tasklet has finished processing any incoming packets (and, more to
866 the point, using the vcc pointer). */
867 tasklet_unlock_wait(&card
->tlet
);
869 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
874 static int print_buffer(struct sk_buff
*buf
)
881 for (i
= 0; i
< len
; i
++){
883 sprintf(msg
, "%02X: ", i
);
885 sprintf(item
,"%02X ",*(buf
->data
+ i
));
890 printk(KERN_DEBUG
"%s", msg
);
896 printk(KERN_DEBUG
"%s", msg
);
898 printk(KERN_DEBUG
"\n");
903 static void fpga_queue(struct solos_card
*card
, int port
, struct sk_buff
*skb
,
909 SKB_CB(skb
)->vcc
= vcc
;
911 spin_lock_irqsave(&card
->tx_queue_lock
, flags
);
912 old_len
= skb_queue_len(&card
->tx_queue
[port
]);
913 skb_queue_tail(&card
->tx_queue
[port
], skb
);
915 card
->tx_mask
|= (1 << port
);
916 spin_unlock_irqrestore(&card
->tx_queue_lock
, flags
);
918 /* Theoretically we could just schedule the tasklet here, but
919 that introduces latency we don't want -- it's noticeable */
924 static uint32_t fpga_tx(struct solos_card
*card
)
926 uint32_t tx_pending
, card_flags
;
927 uint32_t tx_started
= 0;
933 spin_lock_irqsave(&card
->tx_lock
, flags
);
935 card_flags
= ioread32(card
->config_regs
+ FLAGS_ADDR
);
937 * The queue lock is required for _writing_ to tx_mask, but we're
938 * OK to read it here without locking. The only potential update
939 * that we could race with is in fpga_queue() where it sets a bit
940 * for a new port... but it's going to call this function again if
941 * it's doing that, anyway.
943 tx_pending
= card
->tx_mask
& ~card_flags
;
945 for (port
= 0; tx_pending
; tx_pending
>>= 1, port
++) {
946 if (tx_pending
& 1) {
947 struct sk_buff
*oldskb
= card
->tx_skb
[port
];
949 pci_unmap_single(card
->dev
, SKB_CB(oldskb
)->dma_addr
,
950 oldskb
->len
, PCI_DMA_TODEVICE
);
952 spin_lock(&card
->tx_queue_lock
);
953 skb
= skb_dequeue(&card
->tx_queue
[port
]);
955 card
->tx_mask
&= ~(1 << port
);
956 spin_unlock(&card
->tx_queue_lock
);
958 if (skb
&& !card
->using_dma
) {
959 memcpy_toio(TX_BUF(card
, port
), skb
->data
, skb
->len
);
960 tx_started
|= 1 << port
;
961 oldskb
= skb
; /* We're done with this skb already */
962 } else if (skb
&& card
->using_dma
) {
963 SKB_CB(skb
)->dma_addr
= pci_map_single(card
->dev
, skb
->data
,
964 skb
->len
, PCI_DMA_TODEVICE
);
965 card
->tx_skb
[port
] = skb
;
966 iowrite32(SKB_CB(skb
)->dma_addr
,
967 card
->config_regs
+ TX_DMA_ADDR(port
));
973 /* Clean up and free oldskb now it's gone */
975 struct pkt_hdr
*header
= (void *)oldskb
->data
;
976 int size
= le16_to_cpu(header
->size
);
978 skb_pull(oldskb
, sizeof(*header
));
979 dev_info(&card
->dev
->dev
, "Transmitted: port %d\n",
981 dev_info(&card
->dev
->dev
, "size: %d VPI: %d VCI: %d\n",
982 size
, le16_to_cpu(header
->vpi
),
983 le16_to_cpu(header
->vci
));
984 print_buffer(oldskb
);
987 vcc
= SKB_CB(oldskb
)->vcc
;
990 atomic_inc(&vcc
->stats
->tx
);
991 solos_pop(vcc
, oldskb
);
993 dev_kfree_skb_irq(oldskb
);
994 wake_up(&card
->param_wq
);
998 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
1000 iowrite32(tx_started
, card
->config_regs
+ FLAGS_ADDR
);
1002 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
1006 static int psend(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1008 struct solos_card
*card
= vcc
->dev
->dev_data
;
1009 struct pkt_hdr
*header
;
1013 if (pktlen
> (BUF_SIZE
- sizeof(*header
))) {
1014 dev_warn(&card
->dev
->dev
, "Length of PDU is too large. Dropping PDU.\n");
1015 solos_pop(vcc
, skb
);
1019 if (!skb_clone_writable(skb
, sizeof(*header
))) {
1023 if (skb_headroom(skb
) < sizeof(*header
))
1024 expand_by
= sizeof(*header
) - skb_headroom(skb
);
1026 ret
= pskb_expand_head(skb
, expand_by
, 0, GFP_ATOMIC
);
1028 dev_warn(&card
->dev
->dev
, "pskb_expand_head failed.\n");
1029 solos_pop(vcc
, skb
);
1034 header
= (void *)skb_push(skb
, sizeof(*header
));
1036 /* This does _not_ include the size of the header */
1037 header
->size
= cpu_to_le16(pktlen
);
1038 header
->vpi
= cpu_to_le16(vcc
->vpi
);
1039 header
->vci
= cpu_to_le16(vcc
->vci
);
1040 header
->type
= cpu_to_le16(PKT_DATA
);
1042 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, vcc
);
1047 static struct atmdev_ops fpga_ops
= {
1059 .owner
= THIS_MODULE
1062 static int fpga_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
1066 uint8_t major_ver
, minor_ver
;
1068 struct solos_card
*card
;
1070 card
= kzalloc(sizeof(*card
), GFP_KERNEL
);
1075 init_waitqueue_head(&card
->fw_wq
);
1076 init_waitqueue_head(&card
->param_wq
);
1078 err
= pci_enable_device(dev
);
1080 dev_warn(&dev
->dev
, "Failed to enable PCI device\n");
1084 err
= pci_set_dma_mask(dev
, DMA_BIT_MASK(32));
1086 dev_warn(&dev
->dev
, "Failed to set 32-bit DMA mask\n");
1090 err
= pci_request_regions(dev
, "solos");
1092 dev_warn(&dev
->dev
, "Failed to request regions\n");
1096 card
->config_regs
= pci_iomap(dev
, 0, CONFIG_RAM_SIZE
);
1097 if (!card
->config_regs
) {
1098 dev_warn(&dev
->dev
, "Failed to ioremap config registers\n");
1099 goto out_release_regions
;
1101 card
->buffers
= pci_iomap(dev
, 1, DATA_RAM_SIZE
);
1102 if (!card
->buffers
) {
1103 dev_warn(&dev
->dev
, "Failed to ioremap data buffers\n");
1104 goto out_unmap_config
;
1108 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1109 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1111 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1112 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1115 data32
= ioread32(card
->config_regs
+ FPGA_VER
);
1116 fpga_ver
= (data32
& 0x0000FFFF);
1117 major_ver
= ((data32
& 0xFF000000) >> 24);
1118 minor_ver
= ((data32
& 0x00FF0000) >> 16);
1119 card
->fpga_version
= FPGA_VERSION(major_ver
,minor_ver
);
1120 if (card
->fpga_version
> LEGACY_BUFFERS
)
1121 card
->buffer_size
= BUF_SIZE
;
1123 card
->buffer_size
= OLD_BUF_SIZE
;
1124 dev_info(&dev
->dev
, "Solos FPGA Version %d.%02d svn-%d\n",
1125 major_ver
, minor_ver
, fpga_ver
);
1127 if (fpga_ver
< 37 && (fpga_upgrade
|| firmware_upgrade
||
1128 db_fpga_upgrade
|| db_firmware_upgrade
)) {
1130 "FPGA too old; cannot upgrade flash. Use JTAG.\n");
1131 fpga_upgrade
= firmware_upgrade
= 0;
1132 db_fpga_upgrade
= db_firmware_upgrade
= 0;
1135 if (card
->fpga_version
>= DMA_SUPPORTED
) {
1136 pci_set_master(dev
);
1137 card
->using_dma
= 1;
1139 card
->using_dma
= 0;
1140 /* Set RX empty flag for all ports */
1141 iowrite32(0xF0, card
->config_regs
+ FLAGS_ADDR
);
1144 data32
= ioread32(card
->config_regs
+ PORTS
);
1145 card
->nr_ports
= (data32
& 0x000000FF);
1147 pci_set_drvdata(dev
, card
);
1149 tasklet_init(&card
->tlet
, solos_bh
, (unsigned long)card
);
1150 spin_lock_init(&card
->tx_lock
);
1151 spin_lock_init(&card
->tx_queue_lock
);
1152 spin_lock_init(&card
->cli_queue_lock
);
1153 spin_lock_init(&card
->param_queue_lock
);
1154 INIT_LIST_HEAD(&card
->param_queue
);
1156 err
= request_irq(dev
->irq
, solos_irq
, IRQF_SHARED
,
1159 dev_dbg(&card
->dev
->dev
, "Failed to request interrupt IRQ: %d\n", dev
->irq
);
1160 goto out_unmap_both
;
1163 iowrite32(1, card
->config_regs
+ IRQ_EN_ADDR
);
1166 flash_upgrade(card
, 0);
1168 if (firmware_upgrade
)
1169 flash_upgrade(card
, 1);
1171 if (db_fpga_upgrade
)
1172 flash_upgrade(card
, 2);
1174 if (db_firmware_upgrade
)
1175 flash_upgrade(card
, 3);
1177 err
= atm_init(card
, &dev
->dev
);
1184 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1185 free_irq(dev
->irq
, card
);
1186 tasklet_kill(&card
->tlet
);
1189 pci_set_drvdata(dev
, NULL
);
1190 pci_iounmap(dev
, card
->buffers
);
1192 pci_iounmap(dev
, card
->config_regs
);
1193 out_release_regions
:
1194 pci_release_regions(dev
);
1200 static int atm_init(struct solos_card
*card
, struct device
*parent
)
1204 for (i
= 0; i
< card
->nr_ports
; i
++) {
1205 struct sk_buff
*skb
;
1206 struct pkt_hdr
*header
;
1208 skb_queue_head_init(&card
->tx_queue
[i
]);
1209 skb_queue_head_init(&card
->cli_queue
[i
]);
1211 card
->atmdev
[i
] = atm_dev_register("solos-pci", parent
, &fpga_ops
, -1, NULL
);
1212 if (!card
->atmdev
[i
]) {
1213 dev_err(&card
->dev
->dev
, "Could not register ATM device %d\n", i
);
1217 if (device_create_file(&card
->atmdev
[i
]->class_dev
, &dev_attr_console
))
1218 dev_err(&card
->dev
->dev
, "Could not register console for ATM device %d\n", i
);
1219 if (sysfs_create_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
))
1220 dev_err(&card
->dev
->dev
, "Could not register parameter group for ATM device %d\n", i
);
1222 dev_info(&card
->dev
->dev
, "Registered ATM device %d\n", card
->atmdev
[i
]->number
);
1224 card
->atmdev
[i
]->ci_range
.vpi_bits
= 8;
1225 card
->atmdev
[i
]->ci_range
.vci_bits
= 16;
1226 card
->atmdev
[i
]->dev_data
= card
;
1227 card
->atmdev
[i
]->phy_data
= (void *)(unsigned long)i
;
1228 atm_dev_signal_change(card
->atmdev
[i
], ATM_PHY_SIG_FOUND
);
1230 skb
= alloc_skb(sizeof(*header
), GFP_KERNEL
);
1232 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in atm_init()\n");
1236 header
= (void *)skb_put(skb
, sizeof(*header
));
1238 header
->size
= cpu_to_le16(0);
1239 header
->vpi
= cpu_to_le16(0);
1240 header
->vci
= cpu_to_le16(0);
1241 header
->type
= cpu_to_le16(PKT_STATUS
);
1243 fpga_queue(card
, i
, skb
, NULL
);
1248 static void atm_remove(struct solos_card
*card
)
1252 for (i
= 0; i
< card
->nr_ports
; i
++) {
1253 if (card
->atmdev
[i
]) {
1254 struct sk_buff
*skb
;
1256 dev_info(&card
->dev
->dev
, "Unregistering ATM device %d\n", card
->atmdev
[i
]->number
);
1258 sysfs_remove_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
);
1259 atm_dev_deregister(card
->atmdev
[i
]);
1261 skb
= card
->rx_skb
[i
];
1263 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1264 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
1267 skb
= card
->tx_skb
[i
];
1269 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1270 skb
->len
, PCI_DMA_TODEVICE
);
1273 while ((skb
= skb_dequeue(&card
->tx_queue
[i
])))
1280 static void fpga_remove(struct pci_dev
*dev
)
1282 struct solos_card
*card
= pci_get_drvdata(dev
);
1285 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1288 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1289 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1293 free_irq(dev
->irq
, card
);
1294 tasklet_kill(&card
->tlet
);
1296 /* Release device from reset */
1297 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1298 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1300 pci_iounmap(dev
, card
->buffers
);
1301 pci_iounmap(dev
, card
->config_regs
);
1303 pci_release_regions(dev
);
1304 pci_disable_device(dev
);
1306 pci_set_drvdata(dev
, NULL
);
1310 static struct pci_device_id fpga_pci_tbl
[] __devinitdata
= {
1311 { 0x10ee, 0x0300, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
1315 MODULE_DEVICE_TABLE(pci
,fpga_pci_tbl
);
1317 static struct pci_driver fpga_driver
= {
1319 .id_table
= fpga_pci_tbl
,
1320 .probe
= fpga_probe
,
1321 .remove
= fpga_remove
,
1325 static int __init
solos_pci_init(void)
1327 BUILD_BUG_ON(sizeof(struct solos_skb_cb
) > sizeof(((struct sk_buff
*)0)->cb
));
1329 printk(KERN_INFO
"Solos PCI Driver Version %s\n", VERSION
);
1330 return pci_register_driver(&fpga_driver
);
1333 static void __exit
solos_pci_exit(void)
1335 pci_unregister_driver(&fpga_driver
);
1336 printk(KERN_INFO
"Solos PCI Driver %s Unloaded\n", VERSION
);
1339 module_init(solos_pci_init
);
1340 module_exit(solos_pci_exit
);