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 list_vccs(int vci
);
168 static void release_vccs(struct atm_dev
*dev
);
169 static int atm_init(struct solos_card
*, struct device
*);
170 static void atm_remove(struct solos_card
*);
171 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
);
172 static void solos_bh(unsigned long);
173 static int print_buffer(struct sk_buff
*buf
);
175 static inline void solos_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
180 dev_kfree_skb_any(skb
);
183 static ssize_t
solos_param_show(struct device
*dev
, struct device_attribute
*attr
,
186 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
187 struct solos_card
*card
= atmdev
->dev_data
;
188 struct solos_param prm
;
190 struct pkt_hdr
*header
;
193 buflen
= strlen(attr
->attr
.name
) + 10;
195 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
197 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_show()\n");
201 header
= (void *)skb_put(skb
, sizeof(*header
));
203 buflen
= snprintf((void *)&header
[1], buflen
- 1,
204 "L%05d\n%s\n", current
->pid
, attr
->attr
.name
);
205 skb_put(skb
, buflen
);
207 header
->size
= cpu_to_le16(buflen
);
208 header
->vpi
= cpu_to_le16(0);
209 header
->vci
= cpu_to_le16(0);
210 header
->type
= cpu_to_le16(PKT_COMMAND
);
212 prm
.pid
= current
->pid
;
214 prm
.port
= SOLOS_CHAN(atmdev
);
216 spin_lock_irq(&card
->param_queue_lock
);
217 list_add(&prm
.list
, &card
->param_queue
);
218 spin_unlock_irq(&card
->param_queue_lock
);
220 fpga_queue(card
, prm
.port
, skb
, NULL
);
222 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
224 spin_lock_irq(&card
->param_queue_lock
);
226 spin_unlock_irq(&card
->param_queue_lock
);
231 buflen
= prm
.response
->len
;
232 memcpy(buf
, prm
.response
->data
, buflen
);
233 kfree_skb(prm
.response
);
238 static ssize_t
solos_param_store(struct device
*dev
, struct device_attribute
*attr
,
239 const char *buf
, size_t count
)
241 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
242 struct solos_card
*card
= atmdev
->dev_data
;
243 struct solos_param prm
;
245 struct pkt_hdr
*header
;
249 buflen
= strlen(attr
->attr
.name
) + 11 + count
;
251 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
253 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_store()\n");
257 header
= (void *)skb_put(skb
, sizeof(*header
));
259 buflen
= snprintf((void *)&header
[1], buflen
- 1,
260 "L%05d\n%s\n%s\n", current
->pid
, attr
->attr
.name
, buf
);
262 skb_put(skb
, buflen
);
263 header
->size
= cpu_to_le16(buflen
);
264 header
->vpi
= cpu_to_le16(0);
265 header
->vci
= cpu_to_le16(0);
266 header
->type
= cpu_to_le16(PKT_COMMAND
);
268 prm
.pid
= current
->pid
;
270 prm
.port
= SOLOS_CHAN(atmdev
);
272 spin_lock_irq(&card
->param_queue_lock
);
273 list_add(&prm
.list
, &card
->param_queue
);
274 spin_unlock_irq(&card
->param_queue_lock
);
276 fpga_queue(card
, prm
.port
, skb
, NULL
);
278 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
280 spin_lock_irq(&card
->param_queue_lock
);
282 spin_unlock_irq(&card
->param_queue_lock
);
291 /* Sometimes it has a newline, sometimes it doesn't. */
292 if (skb
->data
[buflen
- 1] == '\n')
295 if (buflen
== 2 && !strncmp(skb
->data
, "OK", 2))
297 else if (buflen
== 5 && !strncmp(skb
->data
, "ERROR", 5))
300 /* We know we have enough space allocated for this; we allocated
302 skb
->data
[buflen
] = 0;
304 dev_warn(&card
->dev
->dev
, "Unexpected parameter response: '%s'\n",
313 static char *next_string(struct sk_buff
*skb
)
316 char *this = skb
->data
;
318 for (i
= 0; i
< skb
->len
; i
++) {
319 if (this[i
] == '\n') {
321 skb_pull(skb
, i
+ 1);
324 if (!isprint(this[i
]))
331 * Status packet has fields separated by \n, starting with a version number
332 * for the information therein. Fields are....
335 * RxBitRate (version >= 1)
336 * TxBitRate (version >= 1)
337 * State (version >= 1)
338 * LocalSNRMargin (version >= 1)
339 * LocalLineAttn (version >= 1)
341 static int process_status(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
343 char *str
, *end
, *state_str
, *snr
, *attn
;
344 int ver
, rate_up
, rate_down
;
346 if (!card
->atmdev
[port
])
349 str
= next_string(skb
);
353 ver
= simple_strtol(str
, NULL
, 10);
355 dev_warn(&card
->dev
->dev
, "Unexpected status interrupt version %d\n",
360 str
= next_string(skb
);
363 if (!strcmp(str
, "ERROR")) {
364 dev_dbg(&card
->dev
->dev
, "Status packet indicated Solos error on port %d (starting up?)\n",
369 rate_down
= simple_strtol(str
, &end
, 10);
373 str
= next_string(skb
);
376 rate_up
= simple_strtol(str
, &end
, 10);
380 state_str
= next_string(skb
);
384 /* Anything but 'Showtime' is down */
385 if (strcmp(state_str
, "Showtime")) {
386 atm_dev_signal_change(card
->atmdev
[port
], ATM_PHY_SIG_LOST
);
387 release_vccs(card
->atmdev
[port
]);
388 dev_info(&card
->dev
->dev
, "Port %d: %s\n", port
, state_str
);
392 snr
= next_string(skb
);
395 attn
= next_string(skb
);
399 dev_info(&card
->dev
->dev
, "Port %d: %s @%d/%d kb/s%s%s%s%s\n",
400 port
, state_str
, rate_down
/1000, rate_up
/1000,
401 snr
[0]?", SNR ":"", snr
, attn
[0]?", Attn ":"", attn
);
403 card
->atmdev
[port
]->link_rate
= rate_down
/ 424;
404 atm_dev_signal_change(card
->atmdev
[port
], ATM_PHY_SIG_FOUND
);
409 static int process_command(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
411 struct solos_param
*prm
;
419 if (skb
->data
[0] != 'L' || !isdigit(skb
->data
[1]) ||
420 !isdigit(skb
->data
[2]) || !isdigit(skb
->data
[3]) ||
421 !isdigit(skb
->data
[4]) || !isdigit(skb
->data
[5]) ||
422 skb
->data
[6] != '\n')
425 cmdpid
= simple_strtol(&skb
->data
[1], NULL
, 10);
427 spin_lock_irqsave(&card
->param_queue_lock
, flags
);
428 list_for_each_entry(prm
, &card
->param_queue
, list
) {
429 if (prm
->port
== port
&& prm
->pid
== cmdpid
) {
432 wake_up(&card
->param_wq
);
437 spin_unlock_irqrestore(&card
->param_queue_lock
, flags
);
441 static ssize_t
console_show(struct device
*dev
, struct device_attribute
*attr
,
444 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
445 struct solos_card
*card
= atmdev
->dev_data
;
449 spin_lock(&card
->cli_queue_lock
);
450 skb
= skb_dequeue(&card
->cli_queue
[SOLOS_CHAN(atmdev
)]);
451 spin_unlock(&card
->cli_queue_lock
);
453 return sprintf(buf
, "No data.\n");
456 memcpy(buf
, skb
->data
, len
);
457 dev_dbg(&card
->dev
->dev
, "len: %d\n", len
);
463 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
)
466 struct pkt_hdr
*header
;
468 if (size
> (BUF_SIZE
- sizeof(*header
))) {
469 dev_dbg(&card
->dev
->dev
, "Command is too big. Dropping request\n");
472 skb
= alloc_skb(size
+ sizeof(*header
), GFP_ATOMIC
);
474 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in send_command()\n");
478 header
= (void *)skb_put(skb
, sizeof(*header
));
480 header
->size
= cpu_to_le16(size
);
481 header
->vpi
= cpu_to_le16(0);
482 header
->vci
= cpu_to_le16(0);
483 header
->type
= cpu_to_le16(PKT_COMMAND
);
485 memcpy(skb_put(skb
, size
), buf
, size
);
487 fpga_queue(card
, dev
, skb
, NULL
);
492 static ssize_t
console_store(struct device
*dev
, struct device_attribute
*attr
,
493 const char *buf
, size_t count
)
495 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
496 struct solos_card
*card
= atmdev
->dev_data
;
499 err
= send_command(card
, SOLOS_CHAN(atmdev
), buf
, count
);
504 static DEVICE_ATTR(console
, 0644, console_show
, console_store
);
507 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
508 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
510 #include "solos-attrlist.c"
515 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
516 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
518 static struct attribute
*solos_attrs
[] = {
519 #include "solos-attrlist.c"
523 static struct attribute_group solos_attr_group
= {
524 .attrs
= solos_attrs
,
525 .name
= "parameters",
528 static int flash_upgrade(struct solos_card
*card
, int chip
)
530 const struct firmware
*fw
;
539 fw_name
= "solos-FPGA.bin";
540 blocksize
= FPGA_BLOCK
;
543 fw_name
= "solos-Firmware.bin";
544 blocksize
= SOLOS_BLOCK
;
547 if (card
->fpga_version
> LEGACY_BUFFERS
){
548 fw_name
= "solos-db-FPGA.bin";
549 blocksize
= FPGA_BLOCK
;
551 dev_info(&card
->dev
->dev
, "FPGA version doesn't support"
552 " daughter board upgrades\n");
557 if (card
->fpga_version
> LEGACY_BUFFERS
){
558 fw_name
= "solos-Firmware.bin";
559 blocksize
= SOLOS_BLOCK
;
561 dev_info(&card
->dev
->dev
, "FPGA version doesn't support"
562 " daughter board upgrades\n");
570 if (request_firmware(&fw
, fw_name
, &card
->dev
->dev
))
573 dev_info(&card
->dev
->dev
, "Flash upgrade starting\n");
575 numblocks
= fw
->size
/ blocksize
;
576 dev_info(&card
->dev
->dev
, "Firmware size: %zd\n", fw
->size
);
577 dev_info(&card
->dev
->dev
, "Number of blocks: %d\n", numblocks
);
579 dev_info(&card
->dev
->dev
, "Changing FPGA to Update mode\n");
580 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
581 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
583 /* Set mode to Chip Erase */
584 if(chip
== 0 || chip
== 2)
585 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to FPGA Chip Erase\n");
586 if(chip
== 1 || chip
== 3)
587 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to Solos Chip Erase\n");
588 iowrite32((chip
* 2), card
->config_regs
+ FLASH_MODE
);
591 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
592 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
594 for (offset
= 0; offset
< fw
->size
; offset
+= blocksize
) {
597 /* Clear write flag */
598 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
600 /* Set mode to Block Write */
601 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
602 iowrite32(((chip
* 2) + 1), card
->config_regs
+ FLASH_MODE
);
604 /* Copy block to buffer, swapping each 16 bits */
605 for(i
= 0; i
< blocksize
; i
+= 4) {
606 uint32_t word
= swahb32p((uint32_t *)(fw
->data
+ offset
+ i
));
607 if(card
->fpga_version
> LEGACY_BUFFERS
)
608 iowrite32(word
, FLASH_BUF
+ i
);
610 iowrite32(word
, RX_BUF(card
, 3) + i
);
613 /* Specify block number and then trigger flash write */
614 iowrite32(offset
/ blocksize
, card
->config_regs
+ FLASH_BLOCK
);
615 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
616 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
619 release_firmware(fw
);
620 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
621 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
622 iowrite32(0, card
->config_regs
+ FLASH_MODE
);
623 dev_info(&card
->dev
->dev
, "Returning FPGA to Data mode\n");
627 static irqreturn_t
solos_irq(int irq
, void *dev_id
)
629 struct solos_card
*card
= dev_id
;
632 iowrite32(0, card
->config_regs
+ IRQ_CLEAR
);
634 /* If we're up and running, just kick the tasklet to process TX/RX */
636 tasklet_schedule(&card
->tlet
);
638 wake_up(&card
->fw_wq
);
640 return IRQ_RETVAL(handled
);
643 void solos_bh(unsigned long card_arg
)
645 struct solos_card
*card
= (void *)card_arg
;
647 uint32_t rx_done
= 0;
651 * Since fpga_tx() is going to need to read the flags under its lock,
652 * it can return them to us so that we don't have to hit PCI MMIO
653 * again for the same information
655 card_flags
= fpga_tx(card
);
657 for (port
= 0; port
< card
->nr_ports
; port
++) {
658 if (card_flags
& (0x10 << port
)) {
659 struct pkt_hdr _hdr
, *header
;
664 if (card
->using_dma
) {
665 skb
= card
->rx_skb
[port
];
666 card
->rx_skb
[port
] = NULL
;
668 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
669 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
671 header
= (void *)skb
->data
;
672 size
= le16_to_cpu(header
->size
);
673 skb_put(skb
, size
+ sizeof(*header
));
674 skb_pull(skb
, sizeof(*header
));
678 rx_done
|= 0x10 << port
;
680 memcpy_fromio(header
, RX_BUF(card
, port
), sizeof(*header
));
682 size
= le16_to_cpu(header
->size
);
683 if (size
> (card
->buffer_size
- sizeof(*header
))){
684 dev_warn(&card
->dev
->dev
, "Invalid buffer size\n");
688 skb
= alloc_skb(size
+ 1, GFP_ATOMIC
);
691 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff for RX\n");
695 memcpy_fromio(skb_put(skb
, size
),
696 RX_BUF(card
, port
) + sizeof(*header
),
700 dev_info(&card
->dev
->dev
, "Received: device %d\n", port
);
701 dev_info(&card
->dev
->dev
, "size: %d VPI: %d VCI: %d\n",
702 size
, le16_to_cpu(header
->vpi
),
703 le16_to_cpu(header
->vci
));
707 switch (le16_to_cpu(header
->type
)) {
709 vcc
= find_vcc(card
->atmdev
[port
], le16_to_cpu(header
->vpi
),
710 le16_to_cpu(header
->vci
));
713 dev_warn(&card
->dev
->dev
, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
714 le16_to_cpu(header
->vci
), le16_to_cpu(header
->vpi
),
718 atm_charge(vcc
, skb
->truesize
);
720 atomic_inc(&vcc
->stats
->rx
);
724 if (process_status(card
, port
, skb
) &&
726 dev_warn(&card
->dev
->dev
, "Bad status packet of %d bytes on port %d:\n", skb
->len
, port
);
729 dev_kfree_skb_any(skb
);
733 default: /* FIXME: Not really, surely? */
734 if (process_command(card
, port
, skb
))
736 spin_lock(&card
->cli_queue_lock
);
737 if (skb_queue_len(&card
->cli_queue
[port
]) > 10) {
739 dev_warn(&card
->dev
->dev
, "Dropping console response on port %d\n",
741 dev_kfree_skb_any(skb
);
743 skb_queue_tail(&card
->cli_queue
[port
], skb
);
744 spin_unlock(&card
->cli_queue_lock
);
748 /* Allocate RX skbs for any ports which need them */
749 if (card
->using_dma
&& card
->atmdev
[port
] &&
750 !card
->rx_skb
[port
]) {
751 struct sk_buff
*skb
= alloc_skb(RX_DMA_SIZE
, GFP_ATOMIC
);
753 SKB_CB(skb
)->dma_addr
=
754 pci_map_single(card
->dev
, skb
->data
,
755 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
756 iowrite32(SKB_CB(skb
)->dma_addr
,
757 card
->config_regs
+ RX_DMA_ADDR(port
));
758 card
->rx_skb
[port
] = skb
;
761 dev_warn(&card
->dev
->dev
, "Failed to allocate RX skb");
763 /* We'll have to try again later */
764 tasklet_schedule(&card
->tlet
);
769 iowrite32(rx_done
, card
->config_regs
+ FLAGS_ADDR
);
774 static struct atm_vcc
*find_vcc(struct atm_dev
*dev
, short vpi
, int vci
)
776 struct hlist_head
*head
;
777 struct atm_vcc
*vcc
= NULL
;
778 struct hlist_node
*node
;
781 read_lock(&vcc_sklist_lock
);
782 head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
-1)];
783 sk_for_each(s
, node
, head
) {
785 if (vcc
->dev
== dev
&& vcc
->vci
== vci
&&
786 vcc
->vpi
== vpi
&& vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
787 test_bit(ATM_VF_READY
, &vcc
->flags
))
792 read_unlock(&vcc_sklist_lock
);
796 static int list_vccs(int vci
)
798 struct hlist_head
*head
;
800 struct hlist_node
*node
;
805 read_lock(&vcc_sklist_lock
);
807 head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
-1)];
808 sk_for_each(s
, node
, head
) {
811 printk(KERN_DEBUG
"Device: %d Vpi: %d Vci: %d\n",
817 for(i
= 0; i
< VCC_HTABLE_SIZE
; i
++){
819 sk_for_each(s
, node
, head
) {
822 printk(KERN_DEBUG
"Device: %d Vpi: %d Vci: %d\n",
829 read_unlock(&vcc_sklist_lock
);
833 static void release_vccs(struct atm_dev
*dev
)
837 write_lock_irq(&vcc_sklist_lock
);
838 for (i
= 0; i
< VCC_HTABLE_SIZE
; i
++) {
839 struct hlist_head
*head
= &vcc_hash
[i
];
840 struct hlist_node
*node
, *tmp
;
844 sk_for_each_safe(s
, node
, tmp
, head
) {
846 if (vcc
->dev
== dev
) {
847 vcc_release_async(vcc
, -EPIPE
);
852 write_unlock_irq(&vcc_sklist_lock
);
856 static int popen(struct atm_vcc
*vcc
)
858 struct solos_card
*card
= vcc
->dev
->dev_data
;
860 struct pkt_hdr
*header
;
862 if (vcc
->qos
.aal
!= ATM_AAL5
) {
863 dev_warn(&card
->dev
->dev
, "Unsupported ATM type %d\n",
868 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
869 if (!skb
&& net_ratelimit()) {
870 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in popen()\n");
873 header
= (void *)skb_put(skb
, sizeof(*header
));
875 header
->size
= cpu_to_le16(0);
876 header
->vpi
= cpu_to_le16(vcc
->vpi
);
877 header
->vci
= cpu_to_le16(vcc
->vci
);
878 header
->type
= cpu_to_le16(PKT_POPEN
);
880 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, NULL
);
882 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
883 set_bit(ATM_VF_READY
, &vcc
->flags
);
890 static void pclose(struct atm_vcc
*vcc
)
892 struct solos_card
*card
= vcc
->dev
->dev_data
;
894 struct pkt_hdr
*header
;
896 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
898 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in pclose()\n");
901 header
= (void *)skb_put(skb
, sizeof(*header
));
903 header
->size
= cpu_to_le16(0);
904 header
->vpi
= cpu_to_le16(vcc
->vpi
);
905 header
->vci
= cpu_to_le16(vcc
->vci
);
906 header
->type
= cpu_to_le16(PKT_PCLOSE
);
908 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, NULL
);
910 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
911 clear_bit(ATM_VF_READY
, &vcc
->flags
);
913 /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the
914 tasklet has finished processing any incoming packets (and, more to
915 the point, using the vcc pointer). */
916 tasklet_unlock_wait(&card
->tlet
);
920 static int print_buffer(struct sk_buff
*buf
)
927 for (i
= 0; i
< len
; i
++){
929 sprintf(msg
, "%02X: ", i
);
931 sprintf(item
,"%02X ",*(buf
->data
+ i
));
936 printk(KERN_DEBUG
"%s", msg
);
942 printk(KERN_DEBUG
"%s", msg
);
944 printk(KERN_DEBUG
"\n");
949 static void fpga_queue(struct solos_card
*card
, int port
, struct sk_buff
*skb
,
955 SKB_CB(skb
)->vcc
= vcc
;
957 spin_lock_irqsave(&card
->tx_queue_lock
, flags
);
958 old_len
= skb_queue_len(&card
->tx_queue
[port
]);
959 skb_queue_tail(&card
->tx_queue
[port
], skb
);
961 card
->tx_mask
|= (1 << port
);
962 spin_unlock_irqrestore(&card
->tx_queue_lock
, flags
);
964 /* Theoretically we could just schedule the tasklet here, but
965 that introduces latency we don't want -- it's noticeable */
970 static uint32_t fpga_tx(struct solos_card
*card
)
972 uint32_t tx_pending
, card_flags
;
973 uint32_t tx_started
= 0;
979 spin_lock_irqsave(&card
->tx_lock
, flags
);
981 card_flags
= ioread32(card
->config_regs
+ FLAGS_ADDR
);
983 * The queue lock is required for _writing_ to tx_mask, but we're
984 * OK to read it here without locking. The only potential update
985 * that we could race with is in fpga_queue() where it sets a bit
986 * for a new port... but it's going to call this function again if
987 * it's doing that, anyway.
989 tx_pending
= card
->tx_mask
& ~card_flags
;
991 for (port
= 0; tx_pending
; tx_pending
>>= 1, port
++) {
992 if (tx_pending
& 1) {
993 struct sk_buff
*oldskb
= card
->tx_skb
[port
];
995 pci_unmap_single(card
->dev
, SKB_CB(oldskb
)->dma_addr
,
996 oldskb
->len
, PCI_DMA_TODEVICE
);
998 spin_lock(&card
->tx_queue_lock
);
999 skb
= skb_dequeue(&card
->tx_queue
[port
]);
1001 card
->tx_mask
&= ~(1 << port
);
1002 spin_unlock(&card
->tx_queue_lock
);
1004 if (skb
&& !card
->using_dma
) {
1005 memcpy_toio(TX_BUF(card
, port
), skb
->data
, skb
->len
);
1006 tx_started
|= 1 << port
;
1007 oldskb
= skb
; /* We're done with this skb already */
1008 } else if (skb
&& card
->using_dma
) {
1009 SKB_CB(skb
)->dma_addr
= pci_map_single(card
->dev
, skb
->data
,
1010 skb
->len
, PCI_DMA_TODEVICE
);
1011 iowrite32(SKB_CB(skb
)->dma_addr
,
1012 card
->config_regs
+ TX_DMA_ADDR(port
));
1018 /* Clean up and free oldskb now it's gone */
1020 dev_info(&card
->dev
->dev
, "Transmitted: port %d\n",
1022 print_buffer(oldskb
);
1025 vcc
= SKB_CB(oldskb
)->vcc
;
1028 atomic_inc(&vcc
->stats
->tx
);
1029 solos_pop(vcc
, oldskb
);
1031 dev_kfree_skb_irq(oldskb
);
1035 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
1037 iowrite32(tx_started
, card
->config_regs
+ FLAGS_ADDR
);
1039 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
1043 static int psend(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1045 struct solos_card
*card
= vcc
->dev
->dev_data
;
1046 struct pkt_hdr
*header
;
1050 if (pktlen
> (BUF_SIZE
- sizeof(*header
))) {
1051 dev_warn(&card
->dev
->dev
, "Length of PDU is too large. Dropping PDU.\n");
1052 solos_pop(vcc
, skb
);
1056 if (!skb_clone_writable(skb
, sizeof(*header
))) {
1060 if (skb_headroom(skb
) < sizeof(*header
))
1061 expand_by
= sizeof(*header
) - skb_headroom(skb
);
1063 ret
= pskb_expand_head(skb
, expand_by
, 0, GFP_ATOMIC
);
1065 dev_warn(&card
->dev
->dev
, "pskb_expand_head failed.\n");
1066 solos_pop(vcc
, skb
);
1071 header
= (void *)skb_push(skb
, sizeof(*header
));
1073 /* This does _not_ include the size of the header */
1074 header
->size
= cpu_to_le16(pktlen
);
1075 header
->vpi
= cpu_to_le16(vcc
->vpi
);
1076 header
->vci
= cpu_to_le16(vcc
->vci
);
1077 header
->type
= cpu_to_le16(PKT_DATA
);
1079 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, vcc
);
1084 static struct atmdev_ops fpga_ops
= {
1096 .owner
= THIS_MODULE
1099 static int fpga_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
1103 uint8_t major_ver
, minor_ver
;
1105 struct solos_card
*card
;
1107 card
= kzalloc(sizeof(*card
), GFP_KERNEL
);
1112 init_waitqueue_head(&card
->fw_wq
);
1113 init_waitqueue_head(&card
->param_wq
);
1115 err
= pci_enable_device(dev
);
1117 dev_warn(&dev
->dev
, "Failed to enable PCI device\n");
1121 err
= pci_set_dma_mask(dev
, DMA_BIT_MASK(32));
1123 dev_warn(&dev
->dev
, "Failed to set 32-bit DMA mask\n");
1127 err
= pci_request_regions(dev
, "solos");
1129 dev_warn(&dev
->dev
, "Failed to request regions\n");
1133 card
->config_regs
= pci_iomap(dev
, 0, CONFIG_RAM_SIZE
);
1134 if (!card
->config_regs
) {
1135 dev_warn(&dev
->dev
, "Failed to ioremap config registers\n");
1136 goto out_release_regions
;
1138 card
->buffers
= pci_iomap(dev
, 1, DATA_RAM_SIZE
);
1139 if (!card
->buffers
) {
1140 dev_warn(&dev
->dev
, "Failed to ioremap data buffers\n");
1141 goto out_unmap_config
;
1145 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1146 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1148 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1149 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1152 data32
= ioread32(card
->config_regs
+ FPGA_VER
);
1153 fpga_ver
= (data32
& 0x0000FFFF);
1154 major_ver
= ((data32
& 0xFF000000) >> 24);
1155 minor_ver
= ((data32
& 0x00FF0000) >> 16);
1156 card
->fpga_version
= FPGA_VERSION(major_ver
,minor_ver
);
1157 if (card
->fpga_version
> LEGACY_BUFFERS
)
1158 card
->buffer_size
= BUF_SIZE
;
1160 card
->buffer_size
= OLD_BUF_SIZE
;
1161 dev_info(&dev
->dev
, "Solos FPGA Version %d.%02d svn-%d\n",
1162 major_ver
, minor_ver
, fpga_ver
);
1164 if (fpga_ver
< 37 && (fpga_upgrade
|| firmware_upgrade
||
1165 db_fpga_upgrade
|| db_firmware_upgrade
)) {
1167 "FPGA too old; cannot upgrade flash. Use JTAG.\n");
1168 fpga_upgrade
= firmware_upgrade
= 0;
1169 db_fpga_upgrade
= db_firmware_upgrade
= 0;
1172 if (card
->fpga_version
>= DMA_SUPPORTED
){
1173 card
->using_dma
= 1;
1175 card
->using_dma
= 0;
1176 /* Set RX empty flag for all ports */
1177 iowrite32(0xF0, card
->config_regs
+ FLAGS_ADDR
);
1180 data32
= ioread32(card
->config_regs
+ PORTS
);
1181 card
->nr_ports
= (data32
& 0x000000FF);
1183 pci_set_drvdata(dev
, card
);
1185 tasklet_init(&card
->tlet
, solos_bh
, (unsigned long)card
);
1186 spin_lock_init(&card
->tx_lock
);
1187 spin_lock_init(&card
->tx_queue_lock
);
1188 spin_lock_init(&card
->cli_queue_lock
);
1189 spin_lock_init(&card
->param_queue_lock
);
1190 INIT_LIST_HEAD(&card
->param_queue
);
1192 err
= request_irq(dev
->irq
, solos_irq
, IRQF_SHARED
,
1195 dev_dbg(&card
->dev
->dev
, "Failed to request interrupt IRQ: %d\n", dev
->irq
);
1196 goto out_unmap_both
;
1199 iowrite32(1, card
->config_regs
+ IRQ_EN_ADDR
);
1202 flash_upgrade(card
, 0);
1204 if (firmware_upgrade
)
1205 flash_upgrade(card
, 1);
1207 if (db_fpga_upgrade
)
1208 flash_upgrade(card
, 2);
1210 if (db_firmware_upgrade
)
1211 flash_upgrade(card
, 3);
1213 err
= atm_init(card
, &dev
->dev
);
1220 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1221 free_irq(dev
->irq
, card
);
1222 tasklet_kill(&card
->tlet
);
1225 pci_set_drvdata(dev
, NULL
);
1226 pci_iounmap(dev
, card
->config_regs
);
1228 pci_iounmap(dev
, card
->buffers
);
1229 out_release_regions
:
1230 pci_release_regions(dev
);
1236 static int atm_init(struct solos_card
*card
, struct device
*parent
)
1240 for (i
= 0; i
< card
->nr_ports
; i
++) {
1241 struct sk_buff
*skb
;
1242 struct pkt_hdr
*header
;
1244 skb_queue_head_init(&card
->tx_queue
[i
]);
1245 skb_queue_head_init(&card
->cli_queue
[i
]);
1247 card
->atmdev
[i
] = atm_dev_register("solos-pci", parent
, &fpga_ops
, -1, NULL
);
1248 if (!card
->atmdev
[i
]) {
1249 dev_err(&card
->dev
->dev
, "Could not register ATM device %d\n", i
);
1253 if (device_create_file(&card
->atmdev
[i
]->class_dev
, &dev_attr_console
))
1254 dev_err(&card
->dev
->dev
, "Could not register console for ATM device %d\n", i
);
1255 if (sysfs_create_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
))
1256 dev_err(&card
->dev
->dev
, "Could not register parameter group for ATM device %d\n", i
);
1258 dev_info(&card
->dev
->dev
, "Registered ATM device %d\n", card
->atmdev
[i
]->number
);
1260 card
->atmdev
[i
]->ci_range
.vpi_bits
= 8;
1261 card
->atmdev
[i
]->ci_range
.vci_bits
= 16;
1262 card
->atmdev
[i
]->dev_data
= card
;
1263 card
->atmdev
[i
]->phy_data
= (void *)(unsigned long)i
;
1264 atm_dev_signal_change(card
->atmdev
[i
], ATM_PHY_SIG_UNKNOWN
);
1266 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
1268 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in atm_init()\n");
1272 header
= (void *)skb_put(skb
, sizeof(*header
));
1274 header
->size
= cpu_to_le16(0);
1275 header
->vpi
= cpu_to_le16(0);
1276 header
->vci
= cpu_to_le16(0);
1277 header
->type
= cpu_to_le16(PKT_STATUS
);
1279 fpga_queue(card
, i
, skb
, NULL
);
1284 static void atm_remove(struct solos_card
*card
)
1288 for (i
= 0; i
< card
->nr_ports
; i
++) {
1289 if (card
->atmdev
[i
]) {
1290 struct sk_buff
*skb
;
1292 dev_info(&card
->dev
->dev
, "Unregistering ATM device %d\n", card
->atmdev
[i
]->number
);
1294 sysfs_remove_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
);
1295 atm_dev_deregister(card
->atmdev
[i
]);
1297 skb
= card
->rx_skb
[i
];
1299 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1300 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
1303 skb
= card
->tx_skb
[i
];
1305 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1306 skb
->len
, PCI_DMA_TODEVICE
);
1309 while ((skb
= skb_dequeue(&card
->tx_queue
[i
])))
1316 static void fpga_remove(struct pci_dev
*dev
)
1318 struct solos_card
*card
= pci_get_drvdata(dev
);
1321 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1324 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1325 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1329 free_irq(dev
->irq
, card
);
1330 tasklet_kill(&card
->tlet
);
1332 /* Release device from reset */
1333 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1334 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1336 pci_iounmap(dev
, card
->buffers
);
1337 pci_iounmap(dev
, card
->config_regs
);
1339 pci_release_regions(dev
);
1340 pci_disable_device(dev
);
1342 pci_set_drvdata(dev
, NULL
);
1346 static struct pci_device_id fpga_pci_tbl
[] __devinitdata
= {
1347 { 0x10ee, 0x0300, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
1351 MODULE_DEVICE_TABLE(pci
,fpga_pci_tbl
);
1353 static struct pci_driver fpga_driver
= {
1355 .id_table
= fpga_pci_tbl
,
1356 .probe
= fpga_probe
,
1357 .remove
= fpga_remove
,
1361 static int __init
solos_pci_init(void)
1363 printk(KERN_INFO
"Solos PCI Driver Version %s\n", VERSION
);
1364 return pci_register_driver(&fpga_driver
);
1367 static void __exit
solos_pci_exit(void)
1369 pci_unregister_driver(&fpga_driver
);
1370 printk(KERN_INFO
"Solos PCI Driver %s Unloaded\n", VERSION
);
1373 module_init(solos_pci_init
);
1374 module_exit(solos_pci_exit
);