David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1 | /* |
| 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/ |
| 5 | * |
| 6 | * |
| 7 | * Copyright © 2008 Traverse Technologies |
| 8 | * Copyright © 2008 Intel Corporation |
| 9 | * |
| 10 | * Authors: Nathan Williams <nathan@traverse.com.au> |
| 11 | * David Woodhouse <dwmw2@infradead.org> |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 12 | * Treker Chen <treker@xrio.com> |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 13 | * |
| 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. |
| 17 | * |
| 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. |
| 22 | */ |
| 23 | |
| 24 | #define DEBUG |
| 25 | #define VERBOSE_DEBUG |
| 26 | |
| 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> |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 40 | #include <linux/firmware.h> |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 41 | #include <linux/ctype.h> |
| 42 | #include <linux/swab.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 44 | |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 45 | #define VERSION "1.04" |
| 46 | #define DRIVER_VERSION 0x01 |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 47 | #define PTAG "solos-pci" |
| 48 | |
| 49 | #define CONFIG_RAM_SIZE 128 |
| 50 | #define FLAGS_ADDR 0x7C |
| 51 | #define IRQ_EN_ADDR 0x78 |
| 52 | #define FPGA_VER 0x74 |
| 53 | #define IRQ_CLEAR 0x70 |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 54 | #define WRITE_FLASH 0x6C |
| 55 | #define PORTS 0x68 |
| 56 | #define FLASH_BLOCK 0x64 |
| 57 | #define FLASH_BUSY 0x60 |
| 58 | #define FPGA_MODE 0x5C |
| 59 | #define FLASH_MODE 0x58 |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 60 | #define GPIO_STATUS 0x54 |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 61 | #define DRIVER_VER 0x50 |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 62 | #define TX_DMA_ADDR(port) (0x40 + (4 * (port))) |
| 63 | #define RX_DMA_ADDR(port) (0x30 + (4 * (port))) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 64 | |
| 65 | #define DATA_RAM_SIZE 32768 |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 66 | #define BUF_SIZE 2048 |
| 67 | #define OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/ |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 68 | /* Old boards use ATMEL AD45DB161D flash */ |
| 69 | #define ATMEL_FPGA_PAGE 528 /* FPGA flash page size*/ |
| 70 | #define ATMEL_SOLOS_PAGE 512 /* Solos flash page size*/ |
| 71 | #define ATMEL_FPGA_BLOCK (ATMEL_FPGA_PAGE * 8) /* FPGA block size*/ |
| 72 | #define ATMEL_SOLOS_BLOCK (ATMEL_SOLOS_PAGE * 8) /* Solos block size*/ |
| 73 | /* Current boards use M25P/M25PE SPI flash */ |
| 74 | #define SPI_FLASH_BLOCK (256 * 64) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 75 | |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 76 | #define RX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2) |
| 77 | #define TX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size)) |
| 78 | #define FLASH_BUF ((card->buffers) + 4*(card->buffer_size)*2) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 79 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 80 | #define RX_DMA_SIZE 2048 |
| 81 | |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 82 | #define FPGA_VERSION(a,b) (((a) << 8) + (b)) |
| 83 | #define LEGACY_BUFFERS 2 |
| 84 | #define DMA_SUPPORTED 4 |
| 85 | |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 86 | static int reset = 0; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 87 | static int atmdebug = 0; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 88 | static int firmware_upgrade = 0; |
| 89 | static int fpga_upgrade = 0; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 90 | static int db_firmware_upgrade = 0; |
| 91 | static int db_fpga_upgrade = 0; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 92 | |
| 93 | struct pkt_hdr { |
| 94 | __le16 size; |
| 95 | __le16 vpi; |
| 96 | __le16 vci; |
| 97 | __le16 type; |
| 98 | }; |
| 99 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 100 | struct solos_skb_cb { |
| 101 | struct atm_vcc *vcc; |
| 102 | uint32_t dma_addr; |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb) |
| 107 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 108 | #define PKT_DATA 0 |
| 109 | #define PKT_COMMAND 1 |
| 110 | #define PKT_POPEN 3 |
| 111 | #define PKT_PCLOSE 4 |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 112 | #define PKT_STATUS 5 |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 113 | |
| 114 | struct solos_card { |
| 115 | void __iomem *config_regs; |
| 116 | void __iomem *buffers; |
| 117 | int nr_ports; |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 118 | int tx_mask; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 119 | struct pci_dev *dev; |
| 120 | struct atm_dev *atmdev[4]; |
| 121 | struct tasklet_struct tlet; |
| 122 | spinlock_t tx_lock; |
| 123 | spinlock_t tx_queue_lock; |
| 124 | spinlock_t cli_queue_lock; |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 125 | spinlock_t param_queue_lock; |
| 126 | struct list_head param_queue; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 127 | struct sk_buff_head tx_queue[4]; |
| 128 | struct sk_buff_head cli_queue[4]; |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 129 | struct sk_buff *tx_skb[4]; |
| 130 | struct sk_buff *rx_skb[4]; |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 131 | unsigned char *dma_bounce; |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 132 | wait_queue_head_t param_wq; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 133 | wait_queue_head_t fw_wq; |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 134 | int using_dma; |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 135 | int dma_alignment; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 136 | int fpga_version; |
| 137 | int buffer_size; |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 138 | int atmel_flash; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 141 | |
| 142 | struct solos_param { |
| 143 | struct list_head list; |
| 144 | pid_t pid; |
| 145 | int port; |
| 146 | struct sk_buff *response; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data) |
| 150 | |
| 151 | MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>"); |
| 152 | MODULE_DESCRIPTION("Solos PCI driver"); |
| 153 | MODULE_VERSION(VERSION); |
| 154 | MODULE_LICENSE("GPL"); |
Ben Hutchings | 9fca79d | 2009-11-07 11:40:32 +0000 | [diff] [blame] | 155 | MODULE_FIRMWARE("solos-FPGA.bin"); |
| 156 | MODULE_FIRMWARE("solos-Firmware.bin"); |
| 157 | MODULE_FIRMWARE("solos-db-FPGA.bin"); |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 158 | MODULE_PARM_DESC(reset, "Reset Solos chips on startup"); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 159 | MODULE_PARM_DESC(atmdebug, "Print ATM data"); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 160 | MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade"); |
| 161 | MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade"); |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 162 | MODULE_PARM_DESC(db_firmware_upgrade, "Initiate daughter board Solos firmware upgrade"); |
| 163 | MODULE_PARM_DESC(db_fpga_upgrade, "Initiate daughter board FPGA upgrade"); |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 164 | module_param(reset, int, 0444); |
Simon Farnsworth | 4306cad | 2009-01-19 21:19:29 +0000 | [diff] [blame] | 165 | module_param(atmdebug, int, 0644); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 166 | module_param(firmware_upgrade, int, 0444); |
| 167 | module_param(fpga_upgrade, int, 0444); |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 168 | module_param(db_firmware_upgrade, int, 0444); |
| 169 | module_param(db_fpga_upgrade, int, 0444); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 170 | |
| 171 | static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb, |
| 172 | struct atm_vcc *vcc); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 173 | static uint32_t fpga_tx(struct solos_card *); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 174 | static irqreturn_t solos_irq(int irq, void *dev_id); |
| 175 | static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci); |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 176 | static int atm_init(struct solos_card *, struct device *); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 177 | static void atm_remove(struct solos_card *); |
| 178 | static int send_command(struct solos_card *card, int dev, const char *buf, size_t size); |
| 179 | static void solos_bh(unsigned long); |
| 180 | static int print_buffer(struct sk_buff *buf); |
| 181 | |
| 182 | static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb) |
| 183 | { |
| 184 | if (vcc->pop) |
| 185 | vcc->pop(vcc, skb); |
| 186 | else |
| 187 | dev_kfree_skb_any(skb); |
| 188 | } |
| 189 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 190 | static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr, |
| 191 | char *buf) |
| 192 | { |
| 193 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 194 | struct solos_card *card = atmdev->dev_data; |
| 195 | struct solos_param prm; |
| 196 | struct sk_buff *skb; |
| 197 | struct pkt_hdr *header; |
| 198 | int buflen; |
| 199 | |
| 200 | buflen = strlen(attr->attr.name) + 10; |
| 201 | |
David Woodhouse | 3456b22 | 2009-01-28 10:39:23 +1100 | [diff] [blame] | 202 | skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 203 | if (!skb) { |
| 204 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n"); |
| 205 | return -ENOMEM; |
| 206 | } |
| 207 | |
| 208 | header = (void *)skb_put(skb, sizeof(*header)); |
| 209 | |
| 210 | buflen = snprintf((void *)&header[1], buflen - 1, |
| 211 | "L%05d\n%s\n", current->pid, attr->attr.name); |
| 212 | skb_put(skb, buflen); |
| 213 | |
| 214 | header->size = cpu_to_le16(buflen); |
| 215 | header->vpi = cpu_to_le16(0); |
| 216 | header->vci = cpu_to_le16(0); |
| 217 | header->type = cpu_to_le16(PKT_COMMAND); |
| 218 | |
| 219 | prm.pid = current->pid; |
| 220 | prm.response = NULL; |
| 221 | prm.port = SOLOS_CHAN(atmdev); |
| 222 | |
| 223 | spin_lock_irq(&card->param_queue_lock); |
| 224 | list_add(&prm.list, &card->param_queue); |
| 225 | spin_unlock_irq(&card->param_queue_lock); |
| 226 | |
| 227 | fpga_queue(card, prm.port, skb, NULL); |
| 228 | |
| 229 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); |
| 230 | |
| 231 | spin_lock_irq(&card->param_queue_lock); |
| 232 | list_del(&prm.list); |
| 233 | spin_unlock_irq(&card->param_queue_lock); |
| 234 | |
| 235 | if (!prm.response) |
| 236 | return -EIO; |
| 237 | |
| 238 | buflen = prm.response->len; |
| 239 | memcpy(buf, prm.response->data, buflen); |
| 240 | kfree_skb(prm.response); |
| 241 | |
| 242 | return buflen; |
| 243 | } |
| 244 | |
| 245 | static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr, |
| 246 | const char *buf, size_t count) |
| 247 | { |
| 248 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 249 | struct solos_card *card = atmdev->dev_data; |
| 250 | struct solos_param prm; |
| 251 | struct sk_buff *skb; |
| 252 | struct pkt_hdr *header; |
| 253 | int buflen; |
| 254 | ssize_t ret; |
| 255 | |
| 256 | buflen = strlen(attr->attr.name) + 11 + count; |
| 257 | |
David Woodhouse | 3456b22 | 2009-01-28 10:39:23 +1100 | [diff] [blame] | 258 | skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 259 | if (!skb) { |
| 260 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n"); |
| 261 | return -ENOMEM; |
| 262 | } |
| 263 | |
| 264 | header = (void *)skb_put(skb, sizeof(*header)); |
| 265 | |
| 266 | buflen = snprintf((void *)&header[1], buflen - 1, |
| 267 | "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf); |
| 268 | |
| 269 | skb_put(skb, buflen); |
| 270 | header->size = cpu_to_le16(buflen); |
| 271 | header->vpi = cpu_to_le16(0); |
| 272 | header->vci = cpu_to_le16(0); |
| 273 | header->type = cpu_to_le16(PKT_COMMAND); |
| 274 | |
| 275 | prm.pid = current->pid; |
| 276 | prm.response = NULL; |
| 277 | prm.port = SOLOS_CHAN(atmdev); |
| 278 | |
| 279 | spin_lock_irq(&card->param_queue_lock); |
| 280 | list_add(&prm.list, &card->param_queue); |
| 281 | spin_unlock_irq(&card->param_queue_lock); |
| 282 | |
| 283 | fpga_queue(card, prm.port, skb, NULL); |
| 284 | |
| 285 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); |
| 286 | |
| 287 | spin_lock_irq(&card->param_queue_lock); |
| 288 | list_del(&prm.list); |
| 289 | spin_unlock_irq(&card->param_queue_lock); |
| 290 | |
| 291 | skb = prm.response; |
| 292 | |
| 293 | if (!skb) |
| 294 | return -EIO; |
| 295 | |
| 296 | buflen = skb->len; |
| 297 | |
| 298 | /* Sometimes it has a newline, sometimes it doesn't. */ |
| 299 | if (skb->data[buflen - 1] == '\n') |
| 300 | buflen--; |
| 301 | |
| 302 | if (buflen == 2 && !strncmp(skb->data, "OK", 2)) |
| 303 | ret = count; |
| 304 | else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5)) |
| 305 | ret = -EIO; |
| 306 | else { |
| 307 | /* We know we have enough space allocated for this; we allocated |
| 308 | it ourselves */ |
| 309 | skb->data[buflen] = 0; |
| 310 | |
| 311 | dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n", |
| 312 | skb->data); |
| 313 | ret = -EIO; |
| 314 | } |
| 315 | kfree_skb(skb); |
| 316 | |
| 317 | return ret; |
| 318 | } |
| 319 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 320 | static char *next_string(struct sk_buff *skb) |
| 321 | { |
| 322 | int i = 0; |
| 323 | char *this = skb->data; |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 324 | |
| 325 | for (i = 0; i < skb->len; i++) { |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 326 | if (this[i] == '\n') { |
| 327 | this[i] = 0; |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 328 | skb_pull(skb, i + 1); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 329 | return this; |
| 330 | } |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 331 | if (!isprint(this[i])) |
| 332 | return NULL; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 333 | } |
| 334 | return NULL; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * Status packet has fields separated by \n, starting with a version number |
| 339 | * for the information therein. Fields are.... |
| 340 | * |
| 341 | * packet version |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 342 | * RxBitRate (version >= 1) |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 343 | * TxBitRate (version >= 1) |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 344 | * State (version >= 1) |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 345 | * LocalSNRMargin (version >= 1) |
| 346 | * LocalLineAttn (version >= 1) |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 347 | */ |
| 348 | static int process_status(struct solos_card *card, int port, struct sk_buff *skb) |
| 349 | { |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 350 | char *str, *end, *state_str, *snr, *attn; |
| 351 | int ver, rate_up, rate_down; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 352 | |
| 353 | if (!card->atmdev[port]) |
| 354 | return -ENODEV; |
| 355 | |
| 356 | str = next_string(skb); |
| 357 | if (!str) |
| 358 | return -EIO; |
| 359 | |
| 360 | ver = simple_strtol(str, NULL, 10); |
| 361 | if (ver < 1) { |
| 362 | dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n", |
| 363 | ver); |
| 364 | return -EIO; |
| 365 | } |
| 366 | |
| 367 | str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 368 | if (!str) |
| 369 | return -EIO; |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 370 | if (!strcmp(str, "ERROR")) { |
| 371 | dev_dbg(&card->dev->dev, "Status packet indicated Solos error on port %d (starting up?)\n", |
| 372 | port); |
| 373 | return 0; |
| 374 | } |
| 375 | |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 376 | rate_down = simple_strtol(str, &end, 10); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 377 | if (*end) |
| 378 | return -EIO; |
| 379 | |
| 380 | str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 381 | if (!str) |
| 382 | return -EIO; |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 383 | rate_up = simple_strtol(str, &end, 10); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 384 | if (*end) |
| 385 | return -EIO; |
| 386 | |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 387 | state_str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 388 | if (!state_str) |
| 389 | return -EIO; |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 390 | |
| 391 | /* Anything but 'Showtime' is down */ |
| 392 | if (strcmp(state_str, "Showtime")) { |
Karl Hiramoto | 49d4910 | 2010-07-08 20:55:34 +0000 | [diff] [blame] | 393 | atm_dev_signal_change(card->atmdev[port], ATM_PHY_SIG_LOST); |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 394 | dev_info(&card->dev->dev, "Port %d: %s\n", port, state_str); |
| 395 | return 0; |
David Woodhouse | 1e615df | 2009-01-27 21:47:47 +1100 | [diff] [blame] | 396 | } |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 397 | |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 398 | snr = next_string(skb); |
Julia Lawall | 6cf5767 | 2009-07-27 11:38:52 -0700 | [diff] [blame] | 399 | if (!snr) |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 400 | return -EIO; |
| 401 | attn = next_string(skb); |
| 402 | if (!attn) |
| 403 | return -EIO; |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 404 | |
David Woodhouse | f87b2ed | 2009-01-30 14:31:36 +1100 | [diff] [blame] | 405 | dev_info(&card->dev->dev, "Port %d: %s @%d/%d kb/s%s%s%s%s\n", |
| 406 | port, state_str, rate_down/1000, rate_up/1000, |
| 407 | snr[0]?", SNR ":"", snr, attn[0]?", Attn ":"", attn); |
| 408 | |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 409 | card->atmdev[port]->link_rate = rate_down / 424; |
Karl Hiramoto | 49d4910 | 2010-07-08 20:55:34 +0000 | [diff] [blame] | 410 | atm_dev_signal_change(card->atmdev[port], ATM_PHY_SIG_FOUND); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 411 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 415 | static int process_command(struct solos_card *card, int port, struct sk_buff *skb) |
| 416 | { |
| 417 | struct solos_param *prm; |
| 418 | unsigned long flags; |
| 419 | int cmdpid; |
| 420 | int found = 0; |
| 421 | |
| 422 | if (skb->len < 7) |
| 423 | return 0; |
| 424 | |
| 425 | if (skb->data[0] != 'L' || !isdigit(skb->data[1]) || |
| 426 | !isdigit(skb->data[2]) || !isdigit(skb->data[3]) || |
| 427 | !isdigit(skb->data[4]) || !isdigit(skb->data[5]) || |
| 428 | skb->data[6] != '\n') |
| 429 | return 0; |
| 430 | |
| 431 | cmdpid = simple_strtol(&skb->data[1], NULL, 10); |
| 432 | |
| 433 | spin_lock_irqsave(&card->param_queue_lock, flags); |
| 434 | list_for_each_entry(prm, &card->param_queue, list) { |
| 435 | if (prm->port == port && prm->pid == cmdpid) { |
| 436 | prm->response = skb; |
| 437 | skb_pull(skb, 7); |
| 438 | wake_up(&card->param_wq); |
| 439 | found = 1; |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | spin_unlock_irqrestore(&card->param_queue_lock, flags); |
| 444 | return found; |
| 445 | } |
| 446 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 447 | static ssize_t console_show(struct device *dev, struct device_attribute *attr, |
| 448 | char *buf) |
| 449 | { |
| 450 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 451 | struct solos_card *card = atmdev->dev_data; |
| 452 | struct sk_buff *skb; |
Jiri Slaby | f1ee89d | 2010-10-10 21:50:44 +0000 | [diff] [blame] | 453 | unsigned int len; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 454 | |
| 455 | spin_lock(&card->cli_queue_lock); |
| 456 | skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]); |
| 457 | spin_unlock(&card->cli_queue_lock); |
| 458 | if(skb == NULL) |
| 459 | return sprintf(buf, "No data.\n"); |
| 460 | |
Jiri Slaby | f1ee89d | 2010-10-10 21:50:44 +0000 | [diff] [blame] | 461 | len = skb->len; |
| 462 | memcpy(buf, skb->data, len); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 463 | |
| 464 | kfree_skb(skb); |
Jiri Slaby | f1ee89d | 2010-10-10 21:50:44 +0000 | [diff] [blame] | 465 | return len; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static int send_command(struct solos_card *card, int dev, const char *buf, size_t size) |
| 469 | { |
| 470 | struct sk_buff *skb; |
| 471 | struct pkt_hdr *header; |
| 472 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 473 | if (size > (BUF_SIZE - sizeof(*header))) { |
| 474 | dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n"); |
| 475 | return 0; |
| 476 | } |
| 477 | skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC); |
| 478 | if (!skb) { |
| 479 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n"); |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | header = (void *)skb_put(skb, sizeof(*header)); |
| 484 | |
| 485 | header->size = cpu_to_le16(size); |
| 486 | header->vpi = cpu_to_le16(0); |
| 487 | header->vci = cpu_to_le16(0); |
| 488 | header->type = cpu_to_le16(PKT_COMMAND); |
| 489 | |
| 490 | memcpy(skb_put(skb, size), buf, size); |
| 491 | |
| 492 | fpga_queue(card, dev, skb, NULL); |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | static ssize_t console_store(struct device *dev, struct device_attribute *attr, |
| 498 | const char *buf, size_t count) |
| 499 | { |
| 500 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 501 | struct solos_card *card = atmdev->dev_data; |
| 502 | int err; |
| 503 | |
| 504 | err = send_command(card, SOLOS_CHAN(atmdev), buf, count); |
| 505 | |
| 506 | return err?:count; |
| 507 | } |
| 508 | |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 509 | struct geos_gpio_attr { |
| 510 | struct device_attribute attr; |
| 511 | int offset; |
| 512 | }; |
| 513 | |
| 514 | #define SOLOS_GPIO_ATTR(_name, _mode, _show, _store, _offset) \ |
| 515 | struct geos_gpio_attr gpio_attr_##_name = { \ |
| 516 | .attr = __ATTR(_name, _mode, _show, _store), \ |
| 517 | .offset = _offset } |
| 518 | |
| 519 | static ssize_t geos_gpio_store(struct device *dev, struct device_attribute *attr, |
| 520 | const char *buf, size_t count) |
| 521 | { |
| 522 | struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); |
| 523 | struct geos_gpio_attr *gattr = container_of(attr, struct geos_gpio_attr, attr); |
| 524 | struct solos_card *card = pci_get_drvdata(pdev); |
| 525 | uint32_t data32; |
| 526 | |
| 527 | if (count != 1 && (count != 2 || buf[1] != '\n')) |
| 528 | return -EINVAL; |
| 529 | |
| 530 | spin_lock_irq(&card->param_queue_lock); |
| 531 | data32 = ioread32(card->config_regs + GPIO_STATUS); |
| 532 | if (buf[0] == '1') { |
| 533 | data32 |= 1 << gattr->offset; |
| 534 | iowrite32(data32, card->config_regs + GPIO_STATUS); |
| 535 | } else if (buf[0] == '0') { |
| 536 | data32 &= ~(1 << gattr->offset); |
| 537 | iowrite32(data32, card->config_regs + GPIO_STATUS); |
| 538 | } else { |
| 539 | count = -EINVAL; |
| 540 | } |
Dan Carpenter | 2904207 | 2012-12-19 21:48:45 +0000 | [diff] [blame] | 541 | spin_unlock_irq(&card->param_queue_lock); |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 542 | return count; |
| 543 | } |
| 544 | |
| 545 | static ssize_t geos_gpio_show(struct device *dev, struct device_attribute *attr, |
| 546 | char *buf) |
| 547 | { |
| 548 | struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); |
| 549 | struct geos_gpio_attr *gattr = container_of(attr, struct geos_gpio_attr, attr); |
| 550 | struct solos_card *card = pci_get_drvdata(pdev); |
| 551 | uint32_t data32; |
| 552 | |
| 553 | data32 = ioread32(card->config_regs + GPIO_STATUS); |
| 554 | data32 = (data32 >> gattr->offset) & 1; |
| 555 | |
| 556 | return sprintf(buf, "%d\n", data32); |
| 557 | } |
| 558 | |
| 559 | static ssize_t hardware_show(struct device *dev, struct device_attribute *attr, |
| 560 | char *buf) |
| 561 | { |
| 562 | struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); |
| 563 | struct geos_gpio_attr *gattr = container_of(attr, struct geos_gpio_attr, attr); |
| 564 | struct solos_card *card = pci_get_drvdata(pdev); |
| 565 | uint32_t data32; |
| 566 | |
| 567 | data32 = ioread32(card->config_regs + GPIO_STATUS); |
| 568 | switch (gattr->offset) { |
| 569 | case 0: |
| 570 | /* HardwareVersion */ |
| 571 | data32 = data32 & 0x1F; |
| 572 | break; |
| 573 | case 1: |
| 574 | /* HardwareVariant */ |
| 575 | data32 = (data32 >> 5) & 0x0F; |
| 576 | break; |
| 577 | } |
| 578 | return sprintf(buf, "%d\n", data32); |
| 579 | } |
| 580 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 581 | static DEVICE_ATTR(console, 0644, console_show, console_store); |
| 582 | |
David Woodhouse | d057f0a | 2009-01-27 16:52:07 +1100 | [diff] [blame] | 583 | |
| 584 | #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL); |
| 585 | #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store); |
| 586 | |
| 587 | #include "solos-attrlist.c" |
| 588 | |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 589 | static SOLOS_GPIO_ATTR(GPIO1, 0644, geos_gpio_show, geos_gpio_store, 9); |
| 590 | static SOLOS_GPIO_ATTR(GPIO2, 0644, geos_gpio_show, geos_gpio_store, 10); |
| 591 | static SOLOS_GPIO_ATTR(GPIO3, 0644, geos_gpio_show, geos_gpio_store, 11); |
| 592 | static SOLOS_GPIO_ATTR(GPIO4, 0644, geos_gpio_show, geos_gpio_store, 12); |
| 593 | static SOLOS_GPIO_ATTR(GPIO5, 0644, geos_gpio_show, geos_gpio_store, 13); |
| 594 | static SOLOS_GPIO_ATTR(PushButton, 0444, geos_gpio_show, NULL, 14); |
| 595 | static SOLOS_GPIO_ATTR(HardwareVersion, 0444, hardware_show, NULL, 0); |
| 596 | static SOLOS_GPIO_ATTR(HardwareVariant, 0444, hardware_show, NULL, 1); |
David Woodhouse | d057f0a | 2009-01-27 16:52:07 +1100 | [diff] [blame] | 597 | #undef SOLOS_ATTR_RO |
| 598 | #undef SOLOS_ATTR_RW |
| 599 | |
| 600 | #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr, |
| 601 | #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr, |
| 602 | |
| 603 | static struct attribute *solos_attrs[] = { |
| 604 | #include "solos-attrlist.c" |
| 605 | NULL |
| 606 | }; |
| 607 | |
| 608 | static struct attribute_group solos_attr_group = { |
| 609 | .attrs = solos_attrs, |
| 610 | .name = "parameters", |
| 611 | }; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 612 | |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 613 | static struct attribute *gpio_attrs[] = { |
| 614 | &gpio_attr_GPIO1.attr.attr, |
| 615 | &gpio_attr_GPIO2.attr.attr, |
| 616 | &gpio_attr_GPIO3.attr.attr, |
| 617 | &gpio_attr_GPIO4.attr.attr, |
| 618 | &gpio_attr_GPIO5.attr.attr, |
| 619 | &gpio_attr_PushButton.attr.attr, |
| 620 | &gpio_attr_HardwareVersion.attr.attr, |
| 621 | &gpio_attr_HardwareVariant.attr.attr, |
| 622 | NULL |
| 623 | }; |
| 624 | |
| 625 | static struct attribute_group gpio_attr_group = { |
| 626 | .attrs = gpio_attrs, |
| 627 | .name = "gpio", |
| 628 | }; |
| 629 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 630 | static int flash_upgrade(struct solos_card *card, int chip) |
| 631 | { |
| 632 | const struct firmware *fw; |
| 633 | const char *fw_name; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 634 | int blocksize = 0; |
| 635 | int numblocks = 0; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 636 | int offset; |
| 637 | |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 638 | switch (chip) { |
| 639 | case 0: |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 640 | fw_name = "solos-FPGA.bin"; |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 641 | if (card->atmel_flash) |
| 642 | blocksize = ATMEL_FPGA_BLOCK; |
| 643 | else |
| 644 | blocksize = SPI_FLASH_BLOCK; |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 645 | break; |
| 646 | case 1: |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 647 | fw_name = "solos-Firmware.bin"; |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 648 | if (card->atmel_flash) |
| 649 | blocksize = ATMEL_SOLOS_BLOCK; |
| 650 | else |
| 651 | blocksize = SPI_FLASH_BLOCK; |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 652 | break; |
| 653 | case 2: |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 654 | if (card->fpga_version > LEGACY_BUFFERS){ |
| 655 | fw_name = "solos-db-FPGA.bin"; |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 656 | if (card->atmel_flash) |
| 657 | blocksize = ATMEL_FPGA_BLOCK; |
| 658 | else |
| 659 | blocksize = SPI_FLASH_BLOCK; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 660 | } else { |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 661 | dev_info(&card->dev->dev, "FPGA version doesn't support" |
| 662 | " daughter board upgrades\n"); |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 663 | return -EPERM; |
| 664 | } |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 665 | break; |
| 666 | case 3: |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 667 | if (card->fpga_version > LEGACY_BUFFERS){ |
| 668 | fw_name = "solos-Firmware.bin"; |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 669 | if (card->atmel_flash) |
| 670 | blocksize = ATMEL_SOLOS_BLOCK; |
| 671 | else |
| 672 | blocksize = SPI_FLASH_BLOCK; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 673 | } else { |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 674 | dev_info(&card->dev->dev, "FPGA version doesn't support" |
| 675 | " daughter board upgrades\n"); |
| 676 | return -EPERM; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 677 | } |
Andrew Morton | 7adcdb4 | 2009-11-17 12:46:44 +0000 | [diff] [blame] | 678 | break; |
| 679 | default: |
| 680 | return -ENODEV; |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 681 | } |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 682 | |
| 683 | if (request_firmware(&fw, fw_name, &card->dev->dev)) |
| 684 | return -ENOENT; |
| 685 | |
| 686 | dev_info(&card->dev->dev, "Flash upgrade starting\n"); |
| 687 | |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 688 | /* New FPGAs require driver version before permitting flash upgrades */ |
| 689 | iowrite32(DRIVER_VERSION, card->config_regs + DRIVER_VER); |
| 690 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 691 | numblocks = fw->size / blocksize; |
| 692 | dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 693 | dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks); |
| 694 | |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 695 | dev_info(&card->dev->dev, "Changing FPGA to Update mode\n"); |
| 696 | iowrite32(1, card->config_regs + FPGA_MODE); |
David S. Miller | 06091ed | 2011-04-17 00:11:25 -0700 | [diff] [blame] | 697 | (void) ioread32(card->config_regs + FPGA_MODE); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 698 | |
| 699 | /* Set mode to Chip Erase */ |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 700 | if(chip == 0 || chip == 2) |
| 701 | dev_info(&card->dev->dev, "Set FPGA Flash mode to FPGA Chip Erase\n"); |
| 702 | if(chip == 1 || chip == 3) |
| 703 | dev_info(&card->dev->dev, "Set FPGA Flash mode to Solos Chip Erase\n"); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 704 | iowrite32((chip * 2), card->config_regs + FLASH_MODE); |
| 705 | |
| 706 | |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 707 | iowrite32(1, card->config_regs + WRITE_FLASH); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 708 | wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY)); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 709 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 710 | for (offset = 0; offset < fw->size; offset += blocksize) { |
| 711 | int i; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 712 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 713 | /* Clear write flag */ |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 714 | iowrite32(0, card->config_regs + WRITE_FLASH); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 715 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 716 | /* Set mode to Block Write */ |
| 717 | /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */ |
| 718 | iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE); |
| 719 | |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 720 | /* Copy block to buffer, swapping each 16 bits for Atmel flash */ |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 721 | for(i = 0; i < blocksize; i += 4) { |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 722 | uint32_t word; |
| 723 | if (card->atmel_flash) |
| 724 | word = swahb32p((uint32_t *)(fw->data + offset + i)); |
| 725 | else |
| 726 | word = *(uint32_t *)(fw->data + offset + i); |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 727 | if(card->fpga_version > LEGACY_BUFFERS) |
| 728 | iowrite32(word, FLASH_BUF + i); |
| 729 | else |
| 730 | iowrite32(word, RX_BUF(card, 3) + i); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 731 | } |
| 732 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 733 | /* Specify block number and then trigger flash write */ |
| 734 | iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK); |
| 735 | iowrite32(1, card->config_regs + WRITE_FLASH); |
| 736 | wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY)); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 737 | } |
| 738 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 739 | release_firmware(fw); |
| 740 | iowrite32(0, card->config_regs + WRITE_FLASH); |
| 741 | iowrite32(0, card->config_regs + FPGA_MODE); |
| 742 | iowrite32(0, card->config_regs + FLASH_MODE); |
| 743 | dev_info(&card->dev->dev, "Returning FPGA to Data mode\n"); |
| 744 | return 0; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 745 | } |
| 746 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 747 | static irqreturn_t solos_irq(int irq, void *dev_id) |
| 748 | { |
| 749 | struct solos_card *card = dev_id; |
| 750 | int handled = 1; |
| 751 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 752 | iowrite32(0, card->config_regs + IRQ_CLEAR); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 753 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 754 | /* If we're up and running, just kick the tasklet to process TX/RX */ |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 755 | if (card->atmdev[0]) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 756 | tasklet_schedule(&card->tlet); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 757 | else |
| 758 | wake_up(&card->fw_wq); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 759 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 760 | return IRQ_RETVAL(handled); |
| 761 | } |
| 762 | |
| 763 | void solos_bh(unsigned long card_arg) |
| 764 | { |
| 765 | struct solos_card *card = (void *)card_arg; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 766 | uint32_t card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 767 | uint32_t rx_done = 0; |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 768 | int port; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 769 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 770 | /* |
| 771 | * Since fpga_tx() is going to need to read the flags under its lock, |
| 772 | * it can return them to us so that we don't have to hit PCI MMIO |
| 773 | * again for the same information |
| 774 | */ |
| 775 | card_flags = fpga_tx(card); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 776 | |
| 777 | for (port = 0; port < card->nr_ports; port++) { |
| 778 | if (card_flags & (0x10 << port)) { |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 779 | struct pkt_hdr _hdr, *header; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 780 | struct sk_buff *skb; |
| 781 | struct atm_vcc *vcc; |
| 782 | int size; |
| 783 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 784 | if (card->using_dma) { |
| 785 | skb = card->rx_skb[port]; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 786 | card->rx_skb[port] = NULL; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 787 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 788 | pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr, |
| 789 | RX_DMA_SIZE, PCI_DMA_FROMDEVICE); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 790 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 791 | header = (void *)skb->data; |
| 792 | size = le16_to_cpu(header->size); |
| 793 | skb_put(skb, size + sizeof(*header)); |
| 794 | skb_pull(skb, sizeof(*header)); |
| 795 | } else { |
| 796 | header = &_hdr; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 797 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 798 | rx_done |= 0x10 << port; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 799 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 800 | memcpy_fromio(header, RX_BUF(card, port), sizeof(*header)); |
| 801 | |
| 802 | size = le16_to_cpu(header->size); |
Nathan Williams | 78f857f | 2009-03-25 20:33:42 +1100 | [diff] [blame] | 803 | if (size > (card->buffer_size - sizeof(*header))){ |
| 804 | dev_warn(&card->dev->dev, "Invalid buffer size\n"); |
| 805 | continue; |
| 806 | } |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 807 | |
| 808 | skb = alloc_skb(size + 1, GFP_ATOMIC); |
| 809 | if (!skb) { |
| 810 | if (net_ratelimit()) |
| 811 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n"); |
| 812 | continue; |
| 813 | } |
| 814 | |
| 815 | memcpy_fromio(skb_put(skb, size), |
| 816 | RX_BUF(card, port) + sizeof(*header), |
| 817 | size); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 818 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 819 | if (atmdebug) { |
Philip A. Prindeville | 18b429e | 2011-03-30 12:59:26 +0000 | [diff] [blame] | 820 | dev_info(&card->dev->dev, "Received: port %d\n", port); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 821 | dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n", |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 822 | size, le16_to_cpu(header->vpi), |
| 823 | le16_to_cpu(header->vci)); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 824 | print_buffer(skb); |
| 825 | } |
| 826 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 827 | switch (le16_to_cpu(header->type)) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 828 | case PKT_DATA: |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 829 | vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi), |
| 830 | le16_to_cpu(header->vci)); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 831 | if (!vcc) { |
| 832 | if (net_ratelimit()) |
Philip A. Prindeville | 1e19e65 | 2011-03-30 13:22:45 +0000 | [diff] [blame] | 833 | dev_warn(&card->dev->dev, "Received packet for unknown VPI.VCI %d.%d on port %d\n", |
| 834 | le16_to_cpu(header->vpi), le16_to_cpu(header->vci), |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 835 | port); |
Nathan Williams | 007ef52 | 2012-11-27 17:34:09 +1100 | [diff] [blame] | 836 | dev_kfree_skb_any(skb); |
| 837 | break; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 838 | } |
| 839 | atm_charge(vcc, skb->truesize); |
| 840 | vcc->push(vcc, skb); |
| 841 | atomic_inc(&vcc->stats->rx); |
| 842 | break; |
| 843 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 844 | case PKT_STATUS: |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 845 | if (process_status(card, port, skb) && |
| 846 | net_ratelimit()) { |
| 847 | dev_warn(&card->dev->dev, "Bad status packet of %d bytes on port %d:\n", skb->len, port); |
| 848 | print_buffer(skb); |
| 849 | } |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 850 | dev_kfree_skb_any(skb); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 851 | break; |
| 852 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 853 | case PKT_COMMAND: |
| 854 | default: /* FIXME: Not really, surely? */ |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 855 | if (process_command(card, port, skb)) |
| 856 | break; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 857 | spin_lock(&card->cli_queue_lock); |
| 858 | if (skb_queue_len(&card->cli_queue[port]) > 10) { |
| 859 | if (net_ratelimit()) |
| 860 | dev_warn(&card->dev->dev, "Dropping console response on port %d\n", |
| 861 | port); |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 862 | dev_kfree_skb_any(skb); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 863 | } else |
| 864 | skb_queue_tail(&card->cli_queue[port], skb); |
| 865 | spin_unlock(&card->cli_queue_lock); |
| 866 | break; |
| 867 | } |
| 868 | } |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 869 | /* Allocate RX skbs for any ports which need them */ |
| 870 | if (card->using_dma && card->atmdev[port] && |
| 871 | !card->rx_skb[port]) { |
| 872 | struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC); |
| 873 | if (skb) { |
| 874 | SKB_CB(skb)->dma_addr = |
| 875 | pci_map_single(card->dev, skb->data, |
| 876 | RX_DMA_SIZE, PCI_DMA_FROMDEVICE); |
| 877 | iowrite32(SKB_CB(skb)->dma_addr, |
| 878 | card->config_regs + RX_DMA_ADDR(port)); |
| 879 | card->rx_skb[port] = skb; |
| 880 | } else { |
| 881 | if (net_ratelimit()) |
| 882 | dev_warn(&card->dev->dev, "Failed to allocate RX skb"); |
| 883 | |
| 884 | /* We'll have to try again later */ |
| 885 | tasklet_schedule(&card->tlet); |
| 886 | } |
| 887 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 888 | } |
| 889 | if (rx_done) |
| 890 | iowrite32(rx_done, card->config_regs + FLAGS_ADDR); |
| 891 | |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci) |
| 896 | { |
| 897 | struct hlist_head *head; |
| 898 | struct atm_vcc *vcc = NULL; |
| 899 | struct hlist_node *node; |
| 900 | struct sock *s; |
| 901 | |
| 902 | read_lock(&vcc_sklist_lock); |
| 903 | head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)]; |
| 904 | sk_for_each(s, node, head) { |
| 905 | vcc = atm_sk(s); |
| 906 | if (vcc->dev == dev && vcc->vci == vci && |
David Woodhouse | 1f6ea6e | 2010-08-07 23:02:59 -0700 | [diff] [blame] | 907 | vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE && |
| 908 | test_bit(ATM_VF_READY, &vcc->flags)) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 909 | goto out; |
| 910 | } |
| 911 | vcc = NULL; |
| 912 | out: |
| 913 | read_unlock(&vcc_sklist_lock); |
| 914 | return vcc; |
| 915 | } |
| 916 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 917 | static int popen(struct atm_vcc *vcc) |
| 918 | { |
| 919 | struct solos_card *card = vcc->dev->dev_data; |
| 920 | struct sk_buff *skb; |
| 921 | struct pkt_hdr *header; |
| 922 | |
David Woodhouse | b28a4b9 | 2009-01-27 21:50:36 +1100 | [diff] [blame] | 923 | if (vcc->qos.aal != ATM_AAL5) { |
| 924 | dev_warn(&card->dev->dev, "Unsupported ATM type %d\n", |
| 925 | vcc->qos.aal); |
| 926 | return -EINVAL; |
| 927 | } |
| 928 | |
David Woodhouse | a1db5c5 | 2012-11-29 23:27:20 +0000 | [diff] [blame] | 929 | skb = alloc_skb(sizeof(*header), GFP_KERNEL); |
Jesper Juhl | da1ab3e | 2011-02-13 10:49:32 +0000 | [diff] [blame] | 930 | if (!skb) { |
| 931 | if (net_ratelimit()) |
| 932 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n"); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 933 | return -ENOMEM; |
| 934 | } |
| 935 | header = (void *)skb_put(skb, sizeof(*header)); |
| 936 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 937 | header->size = cpu_to_le16(0); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 938 | header->vpi = cpu_to_le16(vcc->vpi); |
| 939 | header->vci = cpu_to_le16(vcc->vci); |
| 940 | header->type = cpu_to_le16(PKT_POPEN); |
| 941 | |
| 942 | fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL); |
| 943 | |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 944 | set_bit(ATM_VF_ADDR, &vcc->flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 945 | set_bit(ATM_VF_READY, &vcc->flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | static void pclose(struct atm_vcc *vcc) |
| 951 | { |
| 952 | struct solos_card *card = vcc->dev->dev_data; |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 953 | unsigned char port = SOLOS_CHAN(vcc->dev); |
David Woodhouse | 213e85d | 2012-11-29 23:15:30 +0000 | [diff] [blame] | 954 | struct sk_buff *skb, *tmpskb; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 955 | struct pkt_hdr *header; |
| 956 | |
David Woodhouse | 213e85d | 2012-11-29 23:15:30 +0000 | [diff] [blame] | 957 | /* Remove any yet-to-be-transmitted packets from the pending queue */ |
| 958 | spin_lock(&card->tx_queue_lock); |
| 959 | skb_queue_walk_safe(&card->tx_queue[port], skb, tmpskb) { |
| 960 | if (SKB_CB(skb)->vcc == vcc) { |
| 961 | skb_unlink(skb, &card->tx_queue[port]); |
| 962 | solos_pop(vcc, skb); |
| 963 | } |
| 964 | } |
| 965 | spin_unlock(&card->tx_queue_lock); |
| 966 | |
David Woodhouse | a1db5c5 | 2012-11-29 23:27:20 +0000 | [diff] [blame] | 967 | skb = alloc_skb(sizeof(*header), GFP_KERNEL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 968 | if (!skb) { |
| 969 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n"); |
| 970 | return; |
| 971 | } |
| 972 | header = (void *)skb_put(skb, sizeof(*header)); |
| 973 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 974 | header->size = cpu_to_le16(0); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 975 | header->vpi = cpu_to_le16(vcc->vpi); |
| 976 | header->vci = cpu_to_le16(vcc->vci); |
| 977 | header->type = cpu_to_le16(PKT_PCLOSE); |
| 978 | |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 979 | skb_get(skb); |
| 980 | fpga_queue(card, port, skb, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 981 | |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 982 | if (!wait_event_timeout(card->param_wq, !skb_shared(skb), 5 * HZ)) |
| 983 | dev_warn(&card->dev->dev, |
| 984 | "Timeout waiting for VCC close on port %d\n", port); |
| 985 | |
| 986 | dev_kfree_skb(skb); |
| 987 | |
David Woodhouse | 1f6ea6e | 2010-08-07 23:02:59 -0700 | [diff] [blame] | 988 | /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the |
| 989 | tasklet has finished processing any incoming packets (and, more to |
| 990 | the point, using the vcc pointer). */ |
| 991 | tasklet_unlock_wait(&card->tlet); |
David Woodhouse | 213e85d | 2012-11-29 23:15:30 +0000 | [diff] [blame] | 992 | |
| 993 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 994 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 995 | return; |
| 996 | } |
| 997 | |
| 998 | static int print_buffer(struct sk_buff *buf) |
| 999 | { |
| 1000 | int len,i; |
| 1001 | char msg[500]; |
| 1002 | char item[10]; |
| 1003 | |
| 1004 | len = buf->len; |
| 1005 | for (i = 0; i < len; i++){ |
| 1006 | if(i % 8 == 0) |
| 1007 | sprintf(msg, "%02X: ", i); |
| 1008 | |
| 1009 | sprintf(item,"%02X ",*(buf->data + i)); |
| 1010 | strcat(msg, item); |
| 1011 | if(i % 8 == 7) { |
| 1012 | sprintf(item, "\n"); |
| 1013 | strcat(msg, item); |
| 1014 | printk(KERN_DEBUG "%s", msg); |
| 1015 | } |
| 1016 | } |
| 1017 | if (i % 8 != 0) { |
| 1018 | sprintf(item, "\n"); |
| 1019 | strcat(msg, item); |
| 1020 | printk(KERN_DEBUG "%s", msg); |
| 1021 | } |
| 1022 | printk(KERN_DEBUG "\n"); |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb, |
| 1028 | struct atm_vcc *vcc) |
| 1029 | { |
| 1030 | int old_len; |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1031 | unsigned long flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1032 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1033 | SKB_CB(skb)->vcc = vcc; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1034 | |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1035 | spin_lock_irqsave(&card->tx_queue_lock, flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1036 | old_len = skb_queue_len(&card->tx_queue[port]); |
| 1037 | skb_queue_tail(&card->tx_queue[port], skb); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1038 | if (!old_len) |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1039 | card->tx_mask |= (1 << port); |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1040 | spin_unlock_irqrestore(&card->tx_queue_lock, flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1041 | |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1042 | /* Theoretically we could just schedule the tasklet here, but |
| 1043 | that introduces latency we don't want -- it's noticeable */ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1044 | if (!old_len) |
| 1045 | fpga_tx(card); |
| 1046 | } |
| 1047 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1048 | static uint32_t fpga_tx(struct solos_card *card) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1049 | { |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1050 | uint32_t tx_pending, card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1051 | uint32_t tx_started = 0; |
| 1052 | struct sk_buff *skb; |
| 1053 | struct atm_vcc *vcc; |
| 1054 | unsigned char port; |
| 1055 | unsigned long flags; |
| 1056 | |
| 1057 | spin_lock_irqsave(&card->tx_lock, flags); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1058 | |
| 1059 | card_flags = ioread32(card->config_regs + FLAGS_ADDR); |
| 1060 | /* |
| 1061 | * The queue lock is required for _writing_ to tx_mask, but we're |
| 1062 | * OK to read it here without locking. The only potential update |
| 1063 | * that we could race with is in fpga_queue() where it sets a bit |
| 1064 | * for a new port... but it's going to call this function again if |
| 1065 | * it's doing that, anyway. |
| 1066 | */ |
| 1067 | tx_pending = card->tx_mask & ~card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1068 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1069 | for (port = 0; tx_pending; tx_pending >>= 1, port++) { |
| 1070 | if (tx_pending & 1) { |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1071 | struct sk_buff *oldskb = card->tx_skb[port]; |
David Woodhouse | cae49ed | 2012-12-11 14:57:14 +0000 | [diff] [blame] | 1072 | if (oldskb) { |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1073 | pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr, |
| 1074 | oldskb->len, PCI_DMA_TODEVICE); |
David Woodhouse | cae49ed | 2012-12-11 14:57:14 +0000 | [diff] [blame] | 1075 | card->tx_skb[port] = NULL; |
| 1076 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1077 | spin_lock(&card->tx_queue_lock); |
| 1078 | skb = skb_dequeue(&card->tx_queue[port]); |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 1079 | if (!skb) |
| 1080 | card->tx_mask &= ~(1 << port); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1081 | spin_unlock(&card->tx_queue_lock); |
| 1082 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1083 | if (skb && !card->using_dma) { |
| 1084 | memcpy_toio(TX_BUF(card, port), skb->data, skb->len); |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 1085 | tx_started |= 1 << port; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1086 | oldskb = skb; /* We're done with this skb already */ |
| 1087 | } else if (skb && card->using_dma) { |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 1088 | unsigned char *data = skb->data; |
| 1089 | if ((unsigned long)data & card->dma_alignment) { |
| 1090 | data = card->dma_bounce + (BUF_SIZE * port); |
| 1091 | memcpy(data, skb->data, skb->len); |
| 1092 | } |
| 1093 | SKB_CB(skb)->dma_addr = pci_map_single(card->dev, data, |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1094 | skb->len, PCI_DMA_TODEVICE); |
David Woodhouse | b4bd8ad | 2012-05-24 04:58:27 +0000 | [diff] [blame] | 1095 | card->tx_skb[port] = skb; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1096 | iowrite32(SKB_CB(skb)->dma_addr, |
| 1097 | card->config_regs + TX_DMA_ADDR(port)); |
| 1098 | } |
| 1099 | |
| 1100 | if (!oldskb) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1101 | continue; |
| 1102 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1103 | /* Clean up and free oldskb now it's gone */ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1104 | if (atmdebug) { |
Philip A. Prindeville | 18b429e | 2011-03-30 12:59:26 +0000 | [diff] [blame] | 1105 | struct pkt_hdr *header = (void *)oldskb->data; |
| 1106 | int size = le16_to_cpu(header->size); |
| 1107 | |
| 1108 | skb_pull(oldskb, sizeof(*header)); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1109 | dev_info(&card->dev->dev, "Transmitted: port %d\n", |
| 1110 | port); |
Philip A. Prindeville | 18b429e | 2011-03-30 12:59:26 +0000 | [diff] [blame] | 1111 | dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n", |
| 1112 | size, le16_to_cpu(header->vpi), |
| 1113 | le16_to_cpu(header->vci)); |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1114 | print_buffer(oldskb); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1115 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1116 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1117 | vcc = SKB_CB(oldskb)->vcc; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1118 | |
| 1119 | if (vcc) { |
| 1120 | atomic_inc(&vcc->stats->tx); |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1121 | solos_pop(vcc, oldskb); |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 1122 | } else { |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 1123 | dev_kfree_skb_irq(oldskb); |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 1124 | wake_up(&card->param_wq); |
| 1125 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 1128 | /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1129 | if (tx_started) |
| 1130 | iowrite32(tx_started, card->config_regs + FLAGS_ADDR); |
| 1131 | |
| 1132 | spin_unlock_irqrestore(&card->tx_lock, flags); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 1133 | return card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | static int psend(struct atm_vcc *vcc, struct sk_buff *skb) |
| 1137 | { |
| 1138 | struct solos_card *card = vcc->dev->dev_data; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1139 | struct pkt_hdr *header; |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 1140 | int pktlen; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1141 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 1142 | pktlen = skb->len; |
| 1143 | if (pktlen > (BUF_SIZE - sizeof(*header))) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1144 | dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n"); |
| 1145 | solos_pop(vcc, skb); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | if (!skb_clone_writable(skb, sizeof(*header))) { |
| 1150 | int expand_by = 0; |
| 1151 | int ret; |
| 1152 | |
| 1153 | if (skb_headroom(skb) < sizeof(*header)) |
| 1154 | expand_by = sizeof(*header) - skb_headroom(skb); |
| 1155 | |
| 1156 | ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC); |
| 1157 | if (ret) { |
Simon Farnsworth | 4306cad | 2009-01-19 21:19:29 +0000 | [diff] [blame] | 1158 | dev_warn(&card->dev->dev, "pskb_expand_head failed.\n"); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1159 | solos_pop(vcc, skb); |
| 1160 | return ret; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | header = (void *)skb_push(skb, sizeof(*header)); |
| 1165 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 1166 | /* This does _not_ include the size of the header */ |
| 1167 | header->size = cpu_to_le16(pktlen); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1168 | header->vpi = cpu_to_le16(vcc->vpi); |
| 1169 | header->vci = cpu_to_le16(vcc->vci); |
| 1170 | header->type = cpu_to_le16(PKT_DATA); |
| 1171 | |
| 1172 | fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc); |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static struct atmdev_ops fpga_ops = { |
| 1178 | .open = popen, |
| 1179 | .close = pclose, |
| 1180 | .ioctl = NULL, |
| 1181 | .getsockopt = NULL, |
| 1182 | .setsockopt = NULL, |
| 1183 | .send = psend, |
| 1184 | .send_oam = NULL, |
| 1185 | .phy_put = NULL, |
| 1186 | .phy_get = NULL, |
| 1187 | .change_qos = NULL, |
| 1188 | .proc_read = NULL, |
| 1189 | .owner = THIS_MODULE |
| 1190 | }; |
| 1191 | |
| 1192 | static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 1193 | { |
David Woodhouse | cd5549e | 2009-01-30 14:26:37 +1100 | [diff] [blame] | 1194 | int err; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1195 | uint16_t fpga_ver; |
| 1196 | uint8_t major_ver, minor_ver; |
| 1197 | uint32_t data32; |
| 1198 | struct solos_card *card; |
| 1199 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1200 | card = kzalloc(sizeof(*card), GFP_KERNEL); |
| 1201 | if (!card) |
| 1202 | return -ENOMEM; |
| 1203 | |
| 1204 | card->dev = dev; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1205 | init_waitqueue_head(&card->fw_wq); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 1206 | init_waitqueue_head(&card->param_wq); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1207 | |
| 1208 | err = pci_enable_device(dev); |
| 1209 | if (err) { |
| 1210 | dev_warn(&dev->dev, "Failed to enable PCI device\n"); |
| 1211 | goto out; |
| 1212 | } |
| 1213 | |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 1214 | err = pci_set_dma_mask(dev, DMA_BIT_MASK(32)); |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1215 | if (err) { |
| 1216 | dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n"); |
| 1217 | goto out; |
| 1218 | } |
| 1219 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1220 | err = pci_request_regions(dev, "solos"); |
| 1221 | if (err) { |
| 1222 | dev_warn(&dev->dev, "Failed to request regions\n"); |
| 1223 | goto out; |
| 1224 | } |
| 1225 | |
| 1226 | card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE); |
| 1227 | if (!card->config_regs) { |
| 1228 | dev_warn(&dev->dev, "Failed to ioremap config registers\n"); |
| 1229 | goto out_release_regions; |
| 1230 | } |
| 1231 | card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE); |
| 1232 | if (!card->buffers) { |
| 1233 | dev_warn(&dev->dev, "Failed to ioremap data buffers\n"); |
| 1234 | goto out_unmap_config; |
| 1235 | } |
| 1236 | |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 1237 | if (reset) { |
| 1238 | iowrite32(1, card->config_regs + FPGA_MODE); |
| 1239 | data32 = ioread32(card->config_regs + FPGA_MODE); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1240 | |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 1241 | iowrite32(0, card->config_regs + FPGA_MODE); |
| 1242 | data32 = ioread32(card->config_regs + FPGA_MODE); |
| 1243 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1244 | |
| 1245 | data32 = ioread32(card->config_regs + FPGA_VER); |
| 1246 | fpga_ver = (data32 & 0x0000FFFF); |
| 1247 | major_ver = ((data32 & 0xFF000000) >> 24); |
| 1248 | minor_ver = ((data32 & 0x00FF0000) >> 16); |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 1249 | card->fpga_version = FPGA_VERSION(major_ver,minor_ver); |
| 1250 | if (card->fpga_version > LEGACY_BUFFERS) |
| 1251 | card->buffer_size = BUF_SIZE; |
| 1252 | else |
| 1253 | card->buffer_size = OLD_BUF_SIZE; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1254 | dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n", |
| 1255 | major_ver, minor_ver, fpga_ver); |
| 1256 | |
David Woodhouse | 3ce1227 | 2010-11-01 10:35:28 +0000 | [diff] [blame] | 1257 | if (fpga_ver < 37 && (fpga_upgrade || firmware_upgrade || |
| 1258 | db_fpga_upgrade || db_firmware_upgrade)) { |
| 1259 | dev_warn(&dev->dev, |
| 1260 | "FPGA too old; cannot upgrade flash. Use JTAG.\n"); |
| 1261 | fpga_upgrade = firmware_upgrade = 0; |
| 1262 | db_fpga_upgrade = db_firmware_upgrade = 0; |
| 1263 | } |
| 1264 | |
Nathan Williams | 13af816 | 2012-12-19 11:01:20 +0000 | [diff] [blame] | 1265 | /* Stopped using Atmel flash after 0.03-38 */ |
| 1266 | if (fpga_ver < 39) |
| 1267 | card->atmel_flash = 1; |
| 1268 | else |
| 1269 | card->atmel_flash = 0; |
| 1270 | |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 1271 | data32 = ioread32(card->config_regs + PORTS); |
| 1272 | card->nr_ports = (data32 & 0x000000FF); |
| 1273 | |
David Woodhouse | b4bd8ad | 2012-05-24 04:58:27 +0000 | [diff] [blame] | 1274 | if (card->fpga_version >= DMA_SUPPORTED) { |
| 1275 | pci_set_master(dev); |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1276 | card->using_dma = 1; |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 1277 | if (1) { /* All known FPGA versions so far */ |
| 1278 | card->dma_alignment = 3; |
| 1279 | card->dma_bounce = kmalloc(card->nr_ports * BUF_SIZE, GFP_KERNEL); |
| 1280 | if (!card->dma_bounce) { |
| 1281 | dev_warn(&card->dev->dev, "Failed to allocate DMA bounce buffers\n"); |
| 1282 | /* Fallback to MMIO doesn't work */ |
| 1283 | goto out_unmap_both; |
| 1284 | } |
| 1285 | } |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 1286 | } else { |
| 1287 | card->using_dma = 0; |
David Woodhouse | eab50f7 | 2009-01-30 14:27:26 +1100 | [diff] [blame] | 1288 | /* Set RX empty flag for all ports */ |
| 1289 | iowrite32(0xF0, card->config_regs + FLAGS_ADDR); |
| 1290 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1291 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1292 | pci_set_drvdata(dev, card); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1293 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1294 | tasklet_init(&card->tlet, solos_bh, (unsigned long)card); |
| 1295 | spin_lock_init(&card->tx_lock); |
| 1296 | spin_lock_init(&card->tx_queue_lock); |
| 1297 | spin_lock_init(&card->cli_queue_lock); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 1298 | spin_lock_init(&card->param_queue_lock); |
| 1299 | INIT_LIST_HEAD(&card->param_queue); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1300 | |
David Woodhouse | fcd8266 | 2009-01-29 11:29:12 +1100 | [diff] [blame] | 1301 | err = request_irq(dev->irq, solos_irq, IRQF_SHARED, |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1302 | "solos-pci", card); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1303 | if (err) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1304 | dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1305 | goto out_unmap_both; |
| 1306 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1307 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1308 | iowrite32(1, card->config_regs + IRQ_EN_ADDR); |
| 1309 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1310 | if (fpga_upgrade) |
| 1311 | flash_upgrade(card, 0); |
| 1312 | |
| 1313 | if (firmware_upgrade) |
| 1314 | flash_upgrade(card, 1); |
| 1315 | |
Nathan Williams | 4dbedf4 | 2009-03-25 20:27:37 +1100 | [diff] [blame] | 1316 | if (db_fpga_upgrade) |
| 1317 | flash_upgrade(card, 2); |
| 1318 | |
| 1319 | if (db_firmware_upgrade) |
| 1320 | flash_upgrade(card, 3); |
| 1321 | |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 1322 | err = atm_init(card, &dev->dev); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1323 | if (err) |
| 1324 | goto out_free_irq; |
| 1325 | |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 1326 | if (card->fpga_version >= DMA_SUPPORTED && |
| 1327 | sysfs_create_group(&card->dev->dev.kobj, &gpio_attr_group)) |
| 1328 | dev_err(&card->dev->dev, "Could not register parameter group for GPIOs\n"); |
| 1329 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1330 | return 0; |
| 1331 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1332 | out_free_irq: |
| 1333 | iowrite32(0, card->config_regs + IRQ_EN_ADDR); |
| 1334 | free_irq(dev->irq, card); |
| 1335 | tasklet_kill(&card->tlet); |
| 1336 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1337 | out_unmap_both: |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 1338 | kfree(card->dma_bounce); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1339 | pci_set_drvdata(dev, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1340 | pci_iounmap(dev, card->buffers); |
Julia Lawall | 8ae0cfe | 2012-02-19 09:43:32 +0000 | [diff] [blame] | 1341 | out_unmap_config: |
| 1342 | pci_iounmap(dev, card->config_regs); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1343 | out_release_regions: |
| 1344 | pci_release_regions(dev); |
| 1345 | out: |
Julia Lawall | bc111d5 | 2009-02-08 17:00:02 -0800 | [diff] [blame] | 1346 | kfree(card); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1347 | return err; |
| 1348 | } |
| 1349 | |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 1350 | static int atm_init(struct solos_card *card, struct device *parent) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1351 | { |
| 1352 | int i; |
| 1353 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1354 | for (i = 0; i < card->nr_ports; i++) { |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 1355 | struct sk_buff *skb; |
| 1356 | struct pkt_hdr *header; |
| 1357 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1358 | skb_queue_head_init(&card->tx_queue[i]); |
| 1359 | skb_queue_head_init(&card->cli_queue[i]); |
| 1360 | |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 1361 | card->atmdev[i] = atm_dev_register("solos-pci", parent, &fpga_ops, -1, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1362 | if (!card->atmdev[i]) { |
| 1363 | dev_err(&card->dev->dev, "Could not register ATM device %d\n", i); |
| 1364 | atm_remove(card); |
| 1365 | return -ENODEV; |
| 1366 | } |
| 1367 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console)) |
| 1368 | dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i); |
David Woodhouse | d057f0a | 2009-01-27 16:52:07 +1100 | [diff] [blame] | 1369 | if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group)) |
| 1370 | dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1371 | |
| 1372 | dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number); |
| 1373 | |
| 1374 | card->atmdev[i]->ci_range.vpi_bits = 8; |
| 1375 | card->atmdev[i]->ci_range.vci_bits = 16; |
| 1376 | card->atmdev[i]->dev_data = card; |
| 1377 | card->atmdev[i]->phy_data = (void *)(unsigned long)i; |
Philip A. Prindeville | c031235 | 2011-03-30 13:17:04 +0000 | [diff] [blame] | 1378 | atm_dev_signal_change(card->atmdev[i], ATM_PHY_SIG_FOUND); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 1379 | |
David Woodhouse | a1db5c5 | 2012-11-29 23:27:20 +0000 | [diff] [blame] | 1380 | skb = alloc_skb(sizeof(*header), GFP_KERNEL); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 1381 | if (!skb) { |
| 1382 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n"); |
| 1383 | continue; |
| 1384 | } |
| 1385 | |
| 1386 | header = (void *)skb_put(skb, sizeof(*header)); |
| 1387 | |
| 1388 | header->size = cpu_to_le16(0); |
| 1389 | header->vpi = cpu_to_le16(0); |
| 1390 | header->vci = cpu_to_le16(0); |
| 1391 | header->type = cpu_to_le16(PKT_STATUS); |
| 1392 | |
| 1393 | fpga_queue(card, i, skb, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1394 | } |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | static void atm_remove(struct solos_card *card) |
| 1399 | { |
| 1400 | int i; |
| 1401 | |
| 1402 | for (i = 0; i < card->nr_ports; i++) { |
| 1403 | if (card->atmdev[i]) { |
David Woodhouse | 97d759d | 2009-03-17 14:59:34 +0000 | [diff] [blame] | 1404 | struct sk_buff *skb; |
| 1405 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1406 | dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number); |
David Woodhouse | c0fe302 | 2009-01-28 14:34:34 +1100 | [diff] [blame] | 1407 | |
| 1408 | sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1409 | atm_dev_deregister(card->atmdev[i]); |
David Woodhouse | 97d759d | 2009-03-17 14:59:34 +0000 | [diff] [blame] | 1410 | |
| 1411 | skb = card->rx_skb[i]; |
| 1412 | if (skb) { |
| 1413 | pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr, |
| 1414 | RX_DMA_SIZE, PCI_DMA_FROMDEVICE); |
| 1415 | dev_kfree_skb(skb); |
| 1416 | } |
| 1417 | skb = card->tx_skb[i]; |
| 1418 | if (skb) { |
| 1419 | pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr, |
| 1420 | skb->len, PCI_DMA_TODEVICE); |
| 1421 | dev_kfree_skb(skb); |
| 1422 | } |
| 1423 | while ((skb = skb_dequeue(&card->tx_queue[i]))) |
| 1424 | dev_kfree_skb(skb); |
| 1425 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | static void fpga_remove(struct pci_dev *dev) |
| 1431 | { |
| 1432 | struct solos_card *card = pci_get_drvdata(dev); |
David Woodhouse | 97d759d | 2009-03-17 14:59:34 +0000 | [diff] [blame] | 1433 | |
| 1434 | /* Disable IRQs */ |
| 1435 | iowrite32(0, card->config_regs + IRQ_EN_ADDR); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1436 | |
David Woodhouse | 97d759d | 2009-03-17 14:59:34 +0000 | [diff] [blame] | 1437 | /* Reset FPGA */ |
| 1438 | iowrite32(1, card->config_regs + FPGA_MODE); |
| 1439 | (void)ioread32(card->config_regs + FPGA_MODE); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1440 | |
Nathan Williams | f9baad0 | 2012-12-19 11:01:18 +0000 | [diff] [blame] | 1441 | if (card->fpga_version >= DMA_SUPPORTED) |
| 1442 | sysfs_remove_group(&card->dev->dev.kobj, &gpio_attr_group); |
| 1443 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1444 | atm_remove(card); |
| 1445 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1446 | free_irq(dev->irq, card); |
| 1447 | tasklet_kill(&card->tlet); |
| 1448 | |
David Woodhouse | 152a2a8 | 2012-12-19 11:01:21 +0000 | [diff] [blame] | 1449 | kfree(card->dma_bounce); |
| 1450 | |
David Woodhouse | 97d759d | 2009-03-17 14:59:34 +0000 | [diff] [blame] | 1451 | /* Release device from reset */ |
| 1452 | iowrite32(0, card->config_regs + FPGA_MODE); |
| 1453 | (void)ioread32(card->config_regs + FPGA_MODE); |
| 1454 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1455 | pci_iounmap(dev, card->buffers); |
| 1456 | pci_iounmap(dev, card->config_regs); |
| 1457 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1458 | pci_release_regions(dev); |
| 1459 | pci_disable_device(dev); |
| 1460 | |
| 1461 | pci_set_drvdata(dev, NULL); |
| 1462 | kfree(card); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Greg Kroah-Hartman | 6c44512 | 2012-12-21 13:25:04 -0800 | [diff] [blame] | 1465 | static struct pci_device_id fpga_pci_tbl[] = { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1466 | { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 1467 | { 0, } |
| 1468 | }; |
| 1469 | |
| 1470 | MODULE_DEVICE_TABLE(pci,fpga_pci_tbl); |
| 1471 | |
| 1472 | static struct pci_driver fpga_driver = { |
| 1473 | .name = "solos", |
| 1474 | .id_table = fpga_pci_tbl, |
| 1475 | .probe = fpga_probe, |
| 1476 | .remove = fpga_remove, |
| 1477 | }; |
| 1478 | |
| 1479 | |
| 1480 | static int __init solos_pci_init(void) |
| 1481 | { |
David Woodhouse | 7ad3ead | 2012-11-27 23:49:24 +0000 | [diff] [blame] | 1482 | BUILD_BUG_ON(sizeof(struct solos_skb_cb) > sizeof(((struct sk_buff *)0)->cb)); |
| 1483 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1484 | printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION); |
| 1485 | return pci_register_driver(&fpga_driver); |
| 1486 | } |
| 1487 | |
| 1488 | static void __exit solos_pci_exit(void) |
| 1489 | { |
| 1490 | pci_unregister_driver(&fpga_driver); |
| 1491 | printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION); |
| 1492 | } |
| 1493 | |
| 1494 | module_init(solos_pci_init); |
| 1495 | module_exit(solos_pci_exit); |