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> |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 43 | |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 44 | #define VERSION "0.07" |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 45 | #define PTAG "solos-pci" |
| 46 | |
| 47 | #define CONFIG_RAM_SIZE 128 |
| 48 | #define FLAGS_ADDR 0x7C |
| 49 | #define IRQ_EN_ADDR 0x78 |
| 50 | #define FPGA_VER 0x74 |
| 51 | #define IRQ_CLEAR 0x70 |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 52 | #define WRITE_FLASH 0x6C |
| 53 | #define PORTS 0x68 |
| 54 | #define FLASH_BLOCK 0x64 |
| 55 | #define FLASH_BUSY 0x60 |
| 56 | #define FPGA_MODE 0x5C |
| 57 | #define FLASH_MODE 0x58 |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 58 | #define TX_DMA_ADDR(port) (0x40 + (4 * (port))) |
| 59 | #define RX_DMA_ADDR(port) (0x30 + (4 * (port))) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 60 | |
| 61 | #define DATA_RAM_SIZE 32768 |
| 62 | #define BUF_SIZE 4096 |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 63 | #define FPGA_PAGE 528 /* FPGA flash page size*/ |
| 64 | #define SOLOS_PAGE 512 /* Solos flash page size*/ |
| 65 | #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/ |
| 66 | #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 67 | |
| 68 | #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2) |
| 69 | #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE) |
| 70 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 71 | #define RX_DMA_SIZE 2048 |
| 72 | |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 73 | static int reset = 0; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 74 | static int atmdebug = 0; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 75 | static int firmware_upgrade = 0; |
| 76 | static int fpga_upgrade = 0; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 77 | |
| 78 | struct pkt_hdr { |
| 79 | __le16 size; |
| 80 | __le16 vpi; |
| 81 | __le16 vci; |
| 82 | __le16 type; |
| 83 | }; |
| 84 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 85 | struct solos_skb_cb { |
| 86 | struct atm_vcc *vcc; |
| 87 | uint32_t dma_addr; |
| 88 | }; |
| 89 | |
| 90 | |
| 91 | #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb) |
| 92 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 93 | #define PKT_DATA 0 |
| 94 | #define PKT_COMMAND 1 |
| 95 | #define PKT_POPEN 3 |
| 96 | #define PKT_PCLOSE 4 |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 97 | #define PKT_STATUS 5 |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 98 | |
| 99 | struct solos_card { |
| 100 | void __iomem *config_regs; |
| 101 | void __iomem *buffers; |
| 102 | int nr_ports; |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 103 | int tx_mask; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 104 | struct pci_dev *dev; |
| 105 | struct atm_dev *atmdev[4]; |
| 106 | struct tasklet_struct tlet; |
| 107 | spinlock_t tx_lock; |
| 108 | spinlock_t tx_queue_lock; |
| 109 | spinlock_t cli_queue_lock; |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 110 | spinlock_t param_queue_lock; |
| 111 | struct list_head param_queue; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 112 | struct sk_buff_head tx_queue[4]; |
| 113 | struct sk_buff_head cli_queue[4]; |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 114 | struct sk_buff *tx_skb[4]; |
| 115 | struct sk_buff *rx_skb[4]; |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 116 | wait_queue_head_t param_wq; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 117 | wait_queue_head_t fw_wq; |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 118 | int using_dma; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 121 | |
| 122 | struct solos_param { |
| 123 | struct list_head list; |
| 124 | pid_t pid; |
| 125 | int port; |
| 126 | struct sk_buff *response; |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 127 | }; |
| 128 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 129 | #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data) |
| 130 | |
| 131 | MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>"); |
| 132 | MODULE_DESCRIPTION("Solos PCI driver"); |
| 133 | MODULE_VERSION(VERSION); |
| 134 | MODULE_LICENSE("GPL"); |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 135 | MODULE_PARM_DESC(reset, "Reset Solos chips on startup"); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 136 | MODULE_PARM_DESC(atmdebug, "Print ATM data"); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 137 | MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade"); |
| 138 | MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade"); |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 139 | module_param(reset, int, 0444); |
Simon Farnsworth | 4306cad | 2009-01-19 21:19:29 +0000 | [diff] [blame] | 140 | module_param(atmdebug, int, 0644); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 141 | module_param(firmware_upgrade, int, 0444); |
| 142 | module_param(fpga_upgrade, int, 0444); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 143 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 144 | static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb, |
| 145 | struct atm_vcc *vcc); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 146 | static uint32_t fpga_tx(struct solos_card *); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 147 | static irqreturn_t solos_irq(int irq, void *dev_id); |
| 148 | static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci); |
| 149 | static int list_vccs(int vci); |
David Woodhouse | 1e615df | 2009-01-27 21:47:47 +1100 | [diff] [blame] | 150 | static void release_vccs(struct atm_dev *dev); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 151 | static int atm_init(struct solos_card *); |
| 152 | static void atm_remove(struct solos_card *); |
| 153 | static int send_command(struct solos_card *card, int dev, const char *buf, size_t size); |
| 154 | static void solos_bh(unsigned long); |
| 155 | static int print_buffer(struct sk_buff *buf); |
| 156 | |
| 157 | static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb) |
| 158 | { |
| 159 | if (vcc->pop) |
| 160 | vcc->pop(vcc, skb); |
| 161 | else |
| 162 | dev_kfree_skb_any(skb); |
| 163 | } |
| 164 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 165 | static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr, |
| 166 | char *buf) |
| 167 | { |
| 168 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 169 | struct solos_card *card = atmdev->dev_data; |
| 170 | struct solos_param prm; |
| 171 | struct sk_buff *skb; |
| 172 | struct pkt_hdr *header; |
| 173 | int buflen; |
| 174 | |
| 175 | buflen = strlen(attr->attr.name) + 10; |
| 176 | |
David Woodhouse | 3456b22 | 2009-01-28 10:39:23 +1100 | [diff] [blame] | 177 | skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 178 | if (!skb) { |
| 179 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n"); |
| 180 | return -ENOMEM; |
| 181 | } |
| 182 | |
| 183 | header = (void *)skb_put(skb, sizeof(*header)); |
| 184 | |
| 185 | buflen = snprintf((void *)&header[1], buflen - 1, |
| 186 | "L%05d\n%s\n", current->pid, attr->attr.name); |
| 187 | skb_put(skb, buflen); |
| 188 | |
| 189 | header->size = cpu_to_le16(buflen); |
| 190 | header->vpi = cpu_to_le16(0); |
| 191 | header->vci = cpu_to_le16(0); |
| 192 | header->type = cpu_to_le16(PKT_COMMAND); |
| 193 | |
| 194 | prm.pid = current->pid; |
| 195 | prm.response = NULL; |
| 196 | prm.port = SOLOS_CHAN(atmdev); |
| 197 | |
| 198 | spin_lock_irq(&card->param_queue_lock); |
| 199 | list_add(&prm.list, &card->param_queue); |
| 200 | spin_unlock_irq(&card->param_queue_lock); |
| 201 | |
| 202 | fpga_queue(card, prm.port, skb, NULL); |
| 203 | |
| 204 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); |
| 205 | |
| 206 | spin_lock_irq(&card->param_queue_lock); |
| 207 | list_del(&prm.list); |
| 208 | spin_unlock_irq(&card->param_queue_lock); |
| 209 | |
| 210 | if (!prm.response) |
| 211 | return -EIO; |
| 212 | |
| 213 | buflen = prm.response->len; |
| 214 | memcpy(buf, prm.response->data, buflen); |
| 215 | kfree_skb(prm.response); |
| 216 | |
| 217 | return buflen; |
| 218 | } |
| 219 | |
| 220 | static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr, |
| 221 | const char *buf, size_t count) |
| 222 | { |
| 223 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 224 | struct solos_card *card = atmdev->dev_data; |
| 225 | struct solos_param prm; |
| 226 | struct sk_buff *skb; |
| 227 | struct pkt_hdr *header; |
| 228 | int buflen; |
| 229 | ssize_t ret; |
| 230 | |
| 231 | buflen = strlen(attr->attr.name) + 11 + count; |
| 232 | |
David Woodhouse | 3456b22 | 2009-01-28 10:39:23 +1100 | [diff] [blame] | 233 | skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 234 | if (!skb) { |
| 235 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n"); |
| 236 | return -ENOMEM; |
| 237 | } |
| 238 | |
| 239 | header = (void *)skb_put(skb, sizeof(*header)); |
| 240 | |
| 241 | buflen = snprintf((void *)&header[1], buflen - 1, |
| 242 | "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf); |
| 243 | |
| 244 | skb_put(skb, buflen); |
| 245 | header->size = cpu_to_le16(buflen); |
| 246 | header->vpi = cpu_to_le16(0); |
| 247 | header->vci = cpu_to_le16(0); |
| 248 | header->type = cpu_to_le16(PKT_COMMAND); |
| 249 | |
| 250 | prm.pid = current->pid; |
| 251 | prm.response = NULL; |
| 252 | prm.port = SOLOS_CHAN(atmdev); |
| 253 | |
| 254 | spin_lock_irq(&card->param_queue_lock); |
| 255 | list_add(&prm.list, &card->param_queue); |
| 256 | spin_unlock_irq(&card->param_queue_lock); |
| 257 | |
| 258 | fpga_queue(card, prm.port, skb, NULL); |
| 259 | |
| 260 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); |
| 261 | |
| 262 | spin_lock_irq(&card->param_queue_lock); |
| 263 | list_del(&prm.list); |
| 264 | spin_unlock_irq(&card->param_queue_lock); |
| 265 | |
| 266 | skb = prm.response; |
| 267 | |
| 268 | if (!skb) |
| 269 | return -EIO; |
| 270 | |
| 271 | buflen = skb->len; |
| 272 | |
| 273 | /* Sometimes it has a newline, sometimes it doesn't. */ |
| 274 | if (skb->data[buflen - 1] == '\n') |
| 275 | buflen--; |
| 276 | |
| 277 | if (buflen == 2 && !strncmp(skb->data, "OK", 2)) |
| 278 | ret = count; |
| 279 | else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5)) |
| 280 | ret = -EIO; |
| 281 | else { |
| 282 | /* We know we have enough space allocated for this; we allocated |
| 283 | it ourselves */ |
| 284 | skb->data[buflen] = 0; |
| 285 | |
| 286 | dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n", |
| 287 | skb->data); |
| 288 | ret = -EIO; |
| 289 | } |
| 290 | kfree_skb(skb); |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 295 | static char *next_string(struct sk_buff *skb) |
| 296 | { |
| 297 | int i = 0; |
| 298 | char *this = skb->data; |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 299 | |
| 300 | for (i = 0; i < skb->len; i++) { |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 301 | if (this[i] == '\n') { |
| 302 | this[i] = 0; |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 303 | skb_pull(skb, i + 1); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 304 | return this; |
| 305 | } |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 306 | if (!isprint(this[i])) |
| 307 | return NULL; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 308 | } |
| 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Status packet has fields separated by \n, starting with a version number |
| 314 | * for the information therein. Fields are.... |
| 315 | * |
| 316 | * packet version |
| 317 | * TxBitRate (version >= 1) |
| 318 | * RxBitRate (version >= 1) |
| 319 | * State (version >= 1) |
| 320 | */ |
| 321 | static int process_status(struct solos_card *card, int port, struct sk_buff *skb) |
| 322 | { |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 323 | char *str, *end, *state_str; |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 324 | int ver, rate_up, rate_down, state; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 325 | |
| 326 | if (!card->atmdev[port]) |
| 327 | return -ENODEV; |
| 328 | |
| 329 | str = next_string(skb); |
| 330 | if (!str) |
| 331 | return -EIO; |
| 332 | |
| 333 | ver = simple_strtol(str, NULL, 10); |
| 334 | if (ver < 1) { |
| 335 | dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n", |
| 336 | ver); |
| 337 | return -EIO; |
| 338 | } |
| 339 | |
| 340 | str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 341 | if (!str) |
| 342 | return -EIO; |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 343 | if (!strcmp(str, "ERROR")) { |
| 344 | dev_dbg(&card->dev->dev, "Status packet indicated Solos error on port %d (starting up?)\n", |
| 345 | port); |
| 346 | return 0; |
| 347 | } |
| 348 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 349 | rate_up = simple_strtol(str, &end, 10); |
| 350 | if (*end) |
| 351 | return -EIO; |
| 352 | |
| 353 | str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 354 | if (!str) |
| 355 | return -EIO; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 356 | rate_down = simple_strtol(str, &end, 10); |
| 357 | if (*end) |
| 358 | return -EIO; |
| 359 | |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 360 | state_str = next_string(skb); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 361 | if (!state_str) |
| 362 | return -EIO; |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 363 | if (!strcmp(state_str, "Showtime")) |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 364 | state = ATM_PHY_SIG_FOUND; |
David Woodhouse | 1e615df | 2009-01-27 21:47:47 +1100 | [diff] [blame] | 365 | else { |
| 366 | state = ATM_PHY_SIG_LOST; |
| 367 | release_vccs(card->atmdev[port]); |
| 368 | } |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 369 | |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 370 | if (state == ATM_PHY_SIG_LOST) { |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 371 | dev_info(&card->dev->dev, "Port %d: %s\n", port, state_str); |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 372 | } else { |
| 373 | char *snr, *attn; |
David Woodhouse | af78065 | 2009-01-28 10:22:57 +1100 | [diff] [blame] | 374 | |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 375 | snr = next_string(skb); |
| 376 | if (!str) |
| 377 | return -EIO; |
| 378 | attn = next_string(skb); |
| 379 | if (!attn) |
| 380 | return -EIO; |
| 381 | |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 382 | dev_info(&card->dev->dev, "Port %d: %s @%d/%d kb/s%s%s%s%s\n", |
David Woodhouse | c6428e5 | 2009-01-29 12:17:09 +1100 | [diff] [blame] | 383 | port, state_str, rate_down/1000, rate_up/1000, |
| 384 | snr[0]?", SNR ":"", snr, attn[0]?", Attn ":"", attn); |
| 385 | } |
| 386 | card->atmdev[port]->link_rate = rate_down / 424; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 387 | card->atmdev[port]->signal = state; |
| 388 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 392 | static int process_command(struct solos_card *card, int port, struct sk_buff *skb) |
| 393 | { |
| 394 | struct solos_param *prm; |
| 395 | unsigned long flags; |
| 396 | int cmdpid; |
| 397 | int found = 0; |
| 398 | |
| 399 | if (skb->len < 7) |
| 400 | return 0; |
| 401 | |
| 402 | if (skb->data[0] != 'L' || !isdigit(skb->data[1]) || |
| 403 | !isdigit(skb->data[2]) || !isdigit(skb->data[3]) || |
| 404 | !isdigit(skb->data[4]) || !isdigit(skb->data[5]) || |
| 405 | skb->data[6] != '\n') |
| 406 | return 0; |
| 407 | |
| 408 | cmdpid = simple_strtol(&skb->data[1], NULL, 10); |
| 409 | |
| 410 | spin_lock_irqsave(&card->param_queue_lock, flags); |
| 411 | list_for_each_entry(prm, &card->param_queue, list) { |
| 412 | if (prm->port == port && prm->pid == cmdpid) { |
| 413 | prm->response = skb; |
| 414 | skb_pull(skb, 7); |
| 415 | wake_up(&card->param_wq); |
| 416 | found = 1; |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | spin_unlock_irqrestore(&card->param_queue_lock, flags); |
| 421 | return found; |
| 422 | } |
| 423 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 424 | static ssize_t console_show(struct device *dev, struct device_attribute *attr, |
| 425 | char *buf) |
| 426 | { |
| 427 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 428 | struct solos_card *card = atmdev->dev_data; |
| 429 | struct sk_buff *skb; |
| 430 | |
| 431 | spin_lock(&card->cli_queue_lock); |
| 432 | skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]); |
| 433 | spin_unlock(&card->cli_queue_lock); |
| 434 | if(skb == NULL) |
| 435 | return sprintf(buf, "No data.\n"); |
| 436 | |
| 437 | memcpy(buf, skb->data, skb->len); |
| 438 | dev_dbg(&card->dev->dev, "len: %d\n", skb->len); |
| 439 | |
| 440 | kfree_skb(skb); |
| 441 | return skb->len; |
| 442 | } |
| 443 | |
| 444 | static int send_command(struct solos_card *card, int dev, const char *buf, size_t size) |
| 445 | { |
| 446 | struct sk_buff *skb; |
| 447 | struct pkt_hdr *header; |
| 448 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 449 | if (size > (BUF_SIZE - sizeof(*header))) { |
| 450 | dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n"); |
| 451 | return 0; |
| 452 | } |
| 453 | skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC); |
| 454 | if (!skb) { |
| 455 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n"); |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | header = (void *)skb_put(skb, sizeof(*header)); |
| 460 | |
| 461 | header->size = cpu_to_le16(size); |
| 462 | header->vpi = cpu_to_le16(0); |
| 463 | header->vci = cpu_to_le16(0); |
| 464 | header->type = cpu_to_le16(PKT_COMMAND); |
| 465 | |
| 466 | memcpy(skb_put(skb, size), buf, size); |
| 467 | |
| 468 | fpga_queue(card, dev, skb, NULL); |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static ssize_t console_store(struct device *dev, struct device_attribute *attr, |
| 474 | const char *buf, size_t count) |
| 475 | { |
| 476 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); |
| 477 | struct solos_card *card = atmdev->dev_data; |
| 478 | int err; |
| 479 | |
| 480 | err = send_command(card, SOLOS_CHAN(atmdev), buf, count); |
| 481 | |
| 482 | return err?:count; |
| 483 | } |
| 484 | |
| 485 | static DEVICE_ATTR(console, 0644, console_show, console_store); |
David Woodhouse | d057f0a | 2009-01-27 16:52:07 +1100 | [diff] [blame] | 486 | |
| 487 | |
| 488 | #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL); |
| 489 | #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store); |
| 490 | |
| 491 | #include "solos-attrlist.c" |
| 492 | |
| 493 | #undef SOLOS_ATTR_RO |
| 494 | #undef SOLOS_ATTR_RW |
| 495 | |
| 496 | #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr, |
| 497 | #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr, |
| 498 | |
| 499 | static struct attribute *solos_attrs[] = { |
| 500 | #include "solos-attrlist.c" |
| 501 | NULL |
| 502 | }; |
| 503 | |
| 504 | static struct attribute_group solos_attr_group = { |
| 505 | .attrs = solos_attrs, |
| 506 | .name = "parameters", |
| 507 | }; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 508 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 509 | static int flash_upgrade(struct solos_card *card, int chip) |
| 510 | { |
| 511 | const struct firmware *fw; |
| 512 | const char *fw_name; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 513 | uint32_t data32 = 0; |
| 514 | int blocksize = 0; |
| 515 | int numblocks = 0; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 516 | int offset; |
| 517 | |
| 518 | if (chip == 0) { |
| 519 | fw_name = "solos-FPGA.bin"; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 520 | blocksize = FPGA_BLOCK; |
| 521 | } else { |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 522 | fw_name = "solos-Firmware.bin"; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 523 | blocksize = SOLOS_BLOCK; |
| 524 | } |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 525 | |
| 526 | if (request_firmware(&fw, fw_name, &card->dev->dev)) |
| 527 | return -ENOENT; |
| 528 | |
| 529 | dev_info(&card->dev->dev, "Flash upgrade starting\n"); |
| 530 | |
| 531 | numblocks = fw->size / blocksize; |
| 532 | dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 533 | dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks); |
| 534 | |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 535 | dev_info(&card->dev->dev, "Changing FPGA to Update mode\n"); |
| 536 | iowrite32(1, card->config_regs + FPGA_MODE); |
| 537 | data32 = ioread32(card->config_regs + FPGA_MODE); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 538 | |
| 539 | /* Set mode to Chip Erase */ |
| 540 | dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n", |
| 541 | chip?"Solos":"FPGA"); |
| 542 | iowrite32((chip * 2), card->config_regs + FLASH_MODE); |
| 543 | |
| 544 | |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 545 | iowrite32(1, card->config_regs + WRITE_FLASH); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 546 | wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY)); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 547 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 548 | for (offset = 0; offset < fw->size; offset += blocksize) { |
| 549 | int i; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 550 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 551 | /* Clear write flag */ |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 552 | iowrite32(0, card->config_regs + WRITE_FLASH); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 553 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 554 | /* Set mode to Block Write */ |
| 555 | /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */ |
| 556 | iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE); |
| 557 | |
| 558 | /* Copy block to buffer, swapping each 16 bits */ |
| 559 | for(i = 0; i < blocksize; i += 4) { |
| 560 | uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i)); |
| 561 | iowrite32(word, RX_BUF(card, 3) + i); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 562 | } |
| 563 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 564 | /* Specify block number and then trigger flash write */ |
| 565 | iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK); |
| 566 | iowrite32(1, card->config_regs + WRITE_FLASH); |
| 567 | wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY)); |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 568 | } |
| 569 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 570 | release_firmware(fw); |
| 571 | iowrite32(0, card->config_regs + WRITE_FLASH); |
| 572 | iowrite32(0, card->config_regs + FPGA_MODE); |
| 573 | iowrite32(0, card->config_regs + FLASH_MODE); |
| 574 | dev_info(&card->dev->dev, "Returning FPGA to Data mode\n"); |
| 575 | return 0; |
Simon Farnsworth | 7c4015b | 2009-01-21 20:45:49 +0000 | [diff] [blame] | 576 | } |
| 577 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 578 | static irqreturn_t solos_irq(int irq, void *dev_id) |
| 579 | { |
| 580 | struct solos_card *card = dev_id; |
| 581 | int handled = 1; |
| 582 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 583 | iowrite32(0, card->config_regs + IRQ_CLEAR); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 584 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 585 | /* 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] | 586 | if (card->atmdev[0]) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 587 | tasklet_schedule(&card->tlet); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 588 | else |
| 589 | wake_up(&card->fw_wq); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 590 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 591 | return IRQ_RETVAL(handled); |
| 592 | } |
| 593 | |
| 594 | void solos_bh(unsigned long card_arg) |
| 595 | { |
| 596 | struct solos_card *card = (void *)card_arg; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 597 | uint32_t card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 598 | uint32_t rx_done = 0; |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 599 | int port; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 600 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 601 | /* |
| 602 | * Since fpga_tx() is going to need to read the flags under its lock, |
| 603 | * it can return them to us so that we don't have to hit PCI MMIO |
| 604 | * again for the same information |
| 605 | */ |
| 606 | card_flags = fpga_tx(card); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 607 | |
| 608 | for (port = 0; port < card->nr_ports; port++) { |
| 609 | if (card_flags & (0x10 << port)) { |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 610 | struct pkt_hdr _hdr, *header; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 611 | struct sk_buff *skb; |
| 612 | struct atm_vcc *vcc; |
| 613 | int size; |
| 614 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 615 | if (card->using_dma) { |
| 616 | skb = card->rx_skb[port]; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 617 | card->rx_skb[port] = NULL; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 618 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 619 | pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr, |
| 620 | RX_DMA_SIZE, PCI_DMA_FROMDEVICE); |
| 621 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 622 | header = (void *)skb->data; |
| 623 | size = le16_to_cpu(header->size); |
| 624 | skb_put(skb, size + sizeof(*header)); |
| 625 | skb_pull(skb, sizeof(*header)); |
| 626 | } else { |
| 627 | header = &_hdr; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 628 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 629 | rx_done |= 0x10 << port; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 630 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 631 | memcpy_fromio(header, RX_BUF(card, port), sizeof(*header)); |
| 632 | |
| 633 | size = le16_to_cpu(header->size); |
| 634 | |
| 635 | skb = alloc_skb(size + 1, GFP_ATOMIC); |
| 636 | if (!skb) { |
| 637 | if (net_ratelimit()) |
| 638 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n"); |
| 639 | continue; |
| 640 | } |
| 641 | |
| 642 | memcpy_fromio(skb_put(skb, size), |
| 643 | RX_BUF(card, port) + sizeof(*header), |
| 644 | size); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 645 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 646 | if (atmdebug) { |
| 647 | dev_info(&card->dev->dev, "Received: device %d\n", port); |
| 648 | dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n", |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 649 | size, le16_to_cpu(header->vpi), |
| 650 | le16_to_cpu(header->vci)); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 651 | print_buffer(skb); |
| 652 | } |
| 653 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 654 | switch (le16_to_cpu(header->type)) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 655 | case PKT_DATA: |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 656 | vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi), |
| 657 | le16_to_cpu(header->vci)); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 658 | if (!vcc) { |
| 659 | if (net_ratelimit()) |
| 660 | dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n", |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 661 | le16_to_cpu(header->vci), le16_to_cpu(header->vpi), |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 662 | port); |
| 663 | continue; |
| 664 | } |
| 665 | atm_charge(vcc, skb->truesize); |
| 666 | vcc->push(vcc, skb); |
| 667 | atomic_inc(&vcc->stats->rx); |
| 668 | break; |
| 669 | |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 670 | case PKT_STATUS: |
David Woodhouse | 95852f4 | 2009-01-30 14:23:52 +1100 | [diff] [blame] | 671 | if (process_status(card, port, skb) && |
| 672 | net_ratelimit()) { |
| 673 | dev_warn(&card->dev->dev, "Bad status packet of %d bytes on port %d:\n", skb->len, port); |
| 674 | print_buffer(skb); |
| 675 | } |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 676 | dev_kfree_skb_any(skb); |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 677 | break; |
| 678 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 679 | case PKT_COMMAND: |
| 680 | default: /* FIXME: Not really, surely? */ |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 681 | if (process_command(card, port, skb)) |
| 682 | break; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 683 | spin_lock(&card->cli_queue_lock); |
| 684 | if (skb_queue_len(&card->cli_queue[port]) > 10) { |
| 685 | if (net_ratelimit()) |
| 686 | dev_warn(&card->dev->dev, "Dropping console response on port %d\n", |
| 687 | port); |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 688 | dev_kfree_skb_any(skb); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 689 | } else |
| 690 | skb_queue_tail(&card->cli_queue[port], skb); |
| 691 | spin_unlock(&card->cli_queue_lock); |
| 692 | break; |
| 693 | } |
| 694 | } |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 695 | /* Allocate RX skbs for any ports which need them */ |
| 696 | if (card->using_dma && card->atmdev[port] && |
| 697 | !card->rx_skb[port]) { |
| 698 | struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC); |
| 699 | if (skb) { |
| 700 | SKB_CB(skb)->dma_addr = |
| 701 | pci_map_single(card->dev, skb->data, |
| 702 | RX_DMA_SIZE, PCI_DMA_FROMDEVICE); |
| 703 | iowrite32(SKB_CB(skb)->dma_addr, |
| 704 | card->config_regs + RX_DMA_ADDR(port)); |
| 705 | card->rx_skb[port] = skb; |
| 706 | } else { |
| 707 | if (net_ratelimit()) |
| 708 | dev_warn(&card->dev->dev, "Failed to allocate RX skb"); |
| 709 | |
| 710 | /* We'll have to try again later */ |
| 711 | tasklet_schedule(&card->tlet); |
| 712 | } |
| 713 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 714 | } |
| 715 | if (rx_done) |
| 716 | iowrite32(rx_done, card->config_regs + FLAGS_ADDR); |
| 717 | |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci) |
| 722 | { |
| 723 | struct hlist_head *head; |
| 724 | struct atm_vcc *vcc = NULL; |
| 725 | struct hlist_node *node; |
| 726 | struct sock *s; |
| 727 | |
| 728 | read_lock(&vcc_sklist_lock); |
| 729 | head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)]; |
| 730 | sk_for_each(s, node, head) { |
| 731 | vcc = atm_sk(s); |
| 732 | if (vcc->dev == dev && vcc->vci == vci && |
| 733 | vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE) |
| 734 | goto out; |
| 735 | } |
| 736 | vcc = NULL; |
| 737 | out: |
| 738 | read_unlock(&vcc_sklist_lock); |
| 739 | return vcc; |
| 740 | } |
| 741 | |
| 742 | static int list_vccs(int vci) |
| 743 | { |
| 744 | struct hlist_head *head; |
| 745 | struct atm_vcc *vcc; |
| 746 | struct hlist_node *node; |
| 747 | struct sock *s; |
| 748 | int num_found = 0; |
| 749 | int i; |
| 750 | |
| 751 | read_lock(&vcc_sklist_lock); |
| 752 | if (vci != 0){ |
| 753 | head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)]; |
| 754 | sk_for_each(s, node, head) { |
| 755 | num_found ++; |
| 756 | vcc = atm_sk(s); |
| 757 | printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n", |
| 758 | vcc->dev->number, |
| 759 | vcc->vpi, |
| 760 | vcc->vci); |
| 761 | } |
| 762 | } else { |
David Woodhouse | 1e615df | 2009-01-27 21:47:47 +1100 | [diff] [blame] | 763 | for(i = 0; i < VCC_HTABLE_SIZE; i++){ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 764 | head = &vcc_hash[i]; |
| 765 | sk_for_each(s, node, head) { |
| 766 | num_found ++; |
| 767 | vcc = atm_sk(s); |
| 768 | printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n", |
| 769 | vcc->dev->number, |
| 770 | vcc->vpi, |
| 771 | vcc->vci); |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | read_unlock(&vcc_sklist_lock); |
| 776 | return num_found; |
| 777 | } |
| 778 | |
David Woodhouse | 1e615df | 2009-01-27 21:47:47 +1100 | [diff] [blame] | 779 | static void release_vccs(struct atm_dev *dev) |
| 780 | { |
| 781 | int i; |
| 782 | |
| 783 | write_lock_irq(&vcc_sklist_lock); |
| 784 | for (i = 0; i < VCC_HTABLE_SIZE; i++) { |
| 785 | struct hlist_head *head = &vcc_hash[i]; |
| 786 | struct hlist_node *node, *tmp; |
| 787 | struct sock *s; |
| 788 | struct atm_vcc *vcc; |
| 789 | |
| 790 | sk_for_each_safe(s, node, tmp, head) { |
| 791 | vcc = atm_sk(s); |
| 792 | if (vcc->dev == dev) { |
| 793 | vcc_release_async(vcc, -EPIPE); |
| 794 | sk_del_node_init(s); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | write_unlock_irq(&vcc_sklist_lock); |
| 799 | } |
| 800 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 801 | |
| 802 | static int popen(struct atm_vcc *vcc) |
| 803 | { |
| 804 | struct solos_card *card = vcc->dev->dev_data; |
| 805 | struct sk_buff *skb; |
| 806 | struct pkt_hdr *header; |
| 807 | |
David Woodhouse | b28a4b9 | 2009-01-27 21:50:36 +1100 | [diff] [blame] | 808 | if (vcc->qos.aal != ATM_AAL5) { |
| 809 | dev_warn(&card->dev->dev, "Unsupported ATM type %d\n", |
| 810 | vcc->qos.aal); |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 814 | skb = alloc_skb(sizeof(*header), GFP_ATOMIC); |
| 815 | if (!skb && net_ratelimit()) { |
| 816 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n"); |
| 817 | return -ENOMEM; |
| 818 | } |
| 819 | header = (void *)skb_put(skb, sizeof(*header)); |
| 820 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 821 | header->size = cpu_to_le16(0); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 822 | header->vpi = cpu_to_le16(vcc->vpi); |
| 823 | header->vci = cpu_to_le16(vcc->vci); |
| 824 | header->type = cpu_to_le16(PKT_POPEN); |
| 825 | |
| 826 | fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL); |
| 827 | |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 828 | set_bit(ATM_VF_ADDR, &vcc->flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 829 | set_bit(ATM_VF_READY, &vcc->flags); |
| 830 | list_vccs(0); |
| 831 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static void pclose(struct atm_vcc *vcc) |
| 837 | { |
| 838 | struct solos_card *card = vcc->dev->dev_data; |
| 839 | struct sk_buff *skb; |
| 840 | struct pkt_hdr *header; |
| 841 | |
| 842 | skb = alloc_skb(sizeof(*header), GFP_ATOMIC); |
| 843 | if (!skb) { |
| 844 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n"); |
| 845 | return; |
| 846 | } |
| 847 | header = (void *)skb_put(skb, sizeof(*header)); |
| 848 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 849 | header->size = cpu_to_le16(0); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 850 | header->vpi = cpu_to_le16(vcc->vpi); |
| 851 | header->vci = cpu_to_le16(vcc->vci); |
| 852 | header->type = cpu_to_le16(PKT_PCLOSE); |
| 853 | |
| 854 | fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL); |
| 855 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 856 | clear_bit(ATM_VF_ADDR, &vcc->flags); |
| 857 | clear_bit(ATM_VF_READY, &vcc->flags); |
| 858 | |
| 859 | return; |
| 860 | } |
| 861 | |
| 862 | static int print_buffer(struct sk_buff *buf) |
| 863 | { |
| 864 | int len,i; |
| 865 | char msg[500]; |
| 866 | char item[10]; |
| 867 | |
| 868 | len = buf->len; |
| 869 | for (i = 0; i < len; i++){ |
| 870 | if(i % 8 == 0) |
| 871 | sprintf(msg, "%02X: ", i); |
| 872 | |
| 873 | sprintf(item,"%02X ",*(buf->data + i)); |
| 874 | strcat(msg, item); |
| 875 | if(i % 8 == 7) { |
| 876 | sprintf(item, "\n"); |
| 877 | strcat(msg, item); |
| 878 | printk(KERN_DEBUG "%s", msg); |
| 879 | } |
| 880 | } |
| 881 | if (i % 8 != 0) { |
| 882 | sprintf(item, "\n"); |
| 883 | strcat(msg, item); |
| 884 | printk(KERN_DEBUG "%s", msg); |
| 885 | } |
| 886 | printk(KERN_DEBUG "\n"); |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb, |
| 892 | struct atm_vcc *vcc) |
| 893 | { |
| 894 | int old_len; |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 895 | unsigned long flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 896 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 897 | SKB_CB(skb)->vcc = vcc; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 898 | |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 899 | spin_lock_irqsave(&card->tx_queue_lock, flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 900 | old_len = skb_queue_len(&card->tx_queue[port]); |
| 901 | skb_queue_tail(&card->tx_queue[port], skb); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 902 | if (!old_len) |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 903 | card->tx_mask |= (1 << port); |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 904 | spin_unlock_irqrestore(&card->tx_queue_lock, flags); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 905 | |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 906 | /* Theoretically we could just schedule the tasklet here, but |
| 907 | that introduces latency we don't want -- it's noticeable */ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 908 | if (!old_len) |
| 909 | fpga_tx(card); |
| 910 | } |
| 911 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 912 | static uint32_t fpga_tx(struct solos_card *card) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 913 | { |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 914 | uint32_t tx_pending, card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 915 | uint32_t tx_started = 0; |
| 916 | struct sk_buff *skb; |
| 917 | struct atm_vcc *vcc; |
| 918 | unsigned char port; |
| 919 | unsigned long flags; |
| 920 | |
| 921 | spin_lock_irqsave(&card->tx_lock, flags); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 922 | |
| 923 | card_flags = ioread32(card->config_regs + FLAGS_ADDR); |
| 924 | /* |
| 925 | * The queue lock is required for _writing_ to tx_mask, but we're |
| 926 | * OK to read it here without locking. The only potential update |
| 927 | * that we could race with is in fpga_queue() where it sets a bit |
| 928 | * for a new port... but it's going to call this function again if |
| 929 | * it's doing that, anyway. |
| 930 | */ |
| 931 | tx_pending = card->tx_mask & ~card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 932 | |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 933 | for (port = 0; tx_pending; tx_pending >>= 1, port++) { |
| 934 | if (tx_pending & 1) { |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 935 | struct sk_buff *oldskb = card->tx_skb[port]; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 936 | if (oldskb) |
| 937 | pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr, |
| 938 | oldskb->len, PCI_DMA_TODEVICE); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 939 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 940 | spin_lock(&card->tx_queue_lock); |
| 941 | skb = skb_dequeue(&card->tx_queue[port]); |
David Woodhouse | f69e417 | 2009-01-29 11:10:58 +1100 | [diff] [blame] | 942 | if (!skb) |
| 943 | card->tx_mask &= ~(1 << port); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 944 | spin_unlock(&card->tx_queue_lock); |
| 945 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 946 | if (skb && !card->using_dma) { |
| 947 | memcpy_toio(TX_BUF(card, port), skb->data, skb->len); |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 948 | tx_started |= 1 << port; |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 949 | oldskb = skb; /* We're done with this skb already */ |
| 950 | } else if (skb && card->using_dma) { |
| 951 | SKB_CB(skb)->dma_addr = pci_map_single(card->dev, skb->data, |
| 952 | skb->len, PCI_DMA_TODEVICE); |
| 953 | iowrite32(SKB_CB(skb)->dma_addr, |
| 954 | card->config_regs + TX_DMA_ADDR(port)); |
| 955 | } |
| 956 | |
| 957 | if (!oldskb) |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 958 | continue; |
| 959 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 960 | /* Clean up and free oldskb now it's gone */ |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 961 | if (atmdebug) { |
| 962 | dev_info(&card->dev->dev, "Transmitted: port %d\n", |
| 963 | port); |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 964 | print_buffer(oldskb); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 965 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 966 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 967 | vcc = SKB_CB(oldskb)->vcc; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 968 | |
David Woodhouse | eaf83e3 | 2009-01-29 10:51:11 +1100 | [diff] [blame] | 969 | if (vcc) { |
| 970 | atomic_inc(&vcc->stats->tx); |
| 971 | solos_pop(vcc, oldskb); |
| 972 | } else |
| 973 | dev_kfree_skb_irq(oldskb); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 974 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 975 | } |
| 976 | } |
David Woodhouse | bdc5462 | 2009-01-29 14:37:20 +1100 | [diff] [blame] | 977 | /* 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] | 978 | if (tx_started) |
| 979 | iowrite32(tx_started, card->config_regs + FLAGS_ADDR); |
| 980 | |
| 981 | spin_unlock_irqrestore(&card->tx_lock, flags); |
David Woodhouse | 35c2221 | 2009-01-29 14:08:27 +1100 | [diff] [blame] | 982 | return card_flags; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static int psend(struct atm_vcc *vcc, struct sk_buff *skb) |
| 986 | { |
| 987 | struct solos_card *card = vcc->dev->dev_data; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 988 | struct pkt_hdr *header; |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 989 | int pktlen; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 990 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 991 | pktlen = skb->len; |
| 992 | if (pktlen > (BUF_SIZE - sizeof(*header))) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 993 | dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n"); |
| 994 | solos_pop(vcc, skb); |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | if (!skb_clone_writable(skb, sizeof(*header))) { |
| 999 | int expand_by = 0; |
| 1000 | int ret; |
| 1001 | |
| 1002 | if (skb_headroom(skb) < sizeof(*header)) |
| 1003 | expand_by = sizeof(*header) - skb_headroom(skb); |
| 1004 | |
| 1005 | ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC); |
| 1006 | if (ret) { |
Simon Farnsworth | 4306cad | 2009-01-19 21:19:29 +0000 | [diff] [blame] | 1007 | dev_warn(&card->dev->dev, "pskb_expand_head failed.\n"); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1008 | solos_pop(vcc, skb); |
| 1009 | return ret; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | header = (void *)skb_push(skb, sizeof(*header)); |
| 1014 | |
David Woodhouse | b76811a | 2009-01-27 10:18:51 +1100 | [diff] [blame] | 1015 | /* This does _not_ include the size of the header */ |
| 1016 | header->size = cpu_to_le16(pktlen); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1017 | header->vpi = cpu_to_le16(vcc->vpi); |
| 1018 | header->vci = cpu_to_le16(vcc->vci); |
| 1019 | header->type = cpu_to_le16(PKT_DATA); |
| 1020 | |
| 1021 | fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc); |
| 1022 | |
| 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static struct atmdev_ops fpga_ops = { |
| 1027 | .open = popen, |
| 1028 | .close = pclose, |
| 1029 | .ioctl = NULL, |
| 1030 | .getsockopt = NULL, |
| 1031 | .setsockopt = NULL, |
| 1032 | .send = psend, |
| 1033 | .send_oam = NULL, |
| 1034 | .phy_put = NULL, |
| 1035 | .phy_get = NULL, |
| 1036 | .change_qos = NULL, |
| 1037 | .proc_read = NULL, |
| 1038 | .owner = THIS_MODULE |
| 1039 | }; |
| 1040 | |
| 1041 | static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 1042 | { |
David Woodhouse | cd5549e | 2009-01-30 14:26:37 +1100 | [diff] [blame] | 1043 | int err; |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1044 | uint16_t fpga_ver; |
| 1045 | uint8_t major_ver, minor_ver; |
| 1046 | uint32_t data32; |
| 1047 | struct solos_card *card; |
| 1048 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1049 | card = kzalloc(sizeof(*card), GFP_KERNEL); |
| 1050 | if (!card) |
| 1051 | return -ENOMEM; |
| 1052 | |
| 1053 | card->dev = dev; |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1054 | init_waitqueue_head(&card->fw_wq); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 1055 | init_waitqueue_head(&card->param_wq); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1056 | |
| 1057 | err = pci_enable_device(dev); |
| 1058 | if (err) { |
| 1059 | dev_warn(&dev->dev, "Failed to enable PCI device\n"); |
| 1060 | goto out; |
| 1061 | } |
| 1062 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1063 | err = pci_set_dma_mask(dev, DMA_32BIT_MASK); |
| 1064 | if (err) { |
| 1065 | dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n"); |
| 1066 | goto out; |
| 1067 | } |
| 1068 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1069 | err = pci_request_regions(dev, "solos"); |
| 1070 | if (err) { |
| 1071 | dev_warn(&dev->dev, "Failed to request regions\n"); |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
| 1075 | card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE); |
| 1076 | if (!card->config_regs) { |
| 1077 | dev_warn(&dev->dev, "Failed to ioremap config registers\n"); |
| 1078 | goto out_release_regions; |
| 1079 | } |
| 1080 | card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE); |
| 1081 | if (!card->buffers) { |
| 1082 | dev_warn(&dev->dev, "Failed to ioremap data buffers\n"); |
| 1083 | goto out_unmap_config; |
| 1084 | } |
| 1085 | |
David Woodhouse | cc3657e | 2009-01-30 14:23:22 +1100 | [diff] [blame] | 1086 | if (reset) { |
| 1087 | iowrite32(1, card->config_regs + FPGA_MODE); |
| 1088 | data32 = ioread32(card->config_regs + FPGA_MODE); |
| 1089 | |
| 1090 | iowrite32(0, card->config_regs + FPGA_MODE); |
| 1091 | data32 = ioread32(card->config_regs + FPGA_MODE); |
| 1092 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1093 | |
| 1094 | data32 = ioread32(card->config_regs + FPGA_VER); |
| 1095 | fpga_ver = (data32 & 0x0000FFFF); |
| 1096 | major_ver = ((data32 & 0xFF000000) >> 24); |
| 1097 | minor_ver = ((data32 & 0x00FF0000) >> 16); |
| 1098 | dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n", |
| 1099 | major_ver, minor_ver, fpga_ver); |
| 1100 | |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1101 | if (fpga_ver > 27) |
| 1102 | card->using_dma = 1; |
David Woodhouse | eab50f7 | 2009-01-30 14:27:26 +1100 | [diff] [blame^] | 1103 | else { |
| 1104 | /* Set RX empty flag for all ports */ |
| 1105 | iowrite32(0xF0, card->config_regs + FLAGS_ADDR); |
| 1106 | } |
David Woodhouse | 9093723 | 2009-01-28 16:46:56 +1100 | [diff] [blame] | 1107 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1108 | card->nr_ports = 2; /* FIXME: Detect daughterboard */ |
| 1109 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1110 | pci_set_drvdata(dev, card); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1111 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1112 | tasklet_init(&card->tlet, solos_bh, (unsigned long)card); |
| 1113 | spin_lock_init(&card->tx_lock); |
| 1114 | spin_lock_init(&card->tx_queue_lock); |
| 1115 | spin_lock_init(&card->cli_queue_lock); |
David Woodhouse | 01e2ffa | 2009-01-27 16:20:04 +1100 | [diff] [blame] | 1116 | spin_lock_init(&card->param_queue_lock); |
| 1117 | INIT_LIST_HEAD(&card->param_queue); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1118 | |
David Woodhouse | fcd8266 | 2009-01-29 11:29:12 +1100 | [diff] [blame] | 1119 | err = request_irq(dev->irq, solos_irq, IRQF_SHARED, |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1120 | "solos-pci", card); |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1121 | if (err) { |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1122 | 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] | 1123 | goto out_unmap_both; |
| 1124 | } |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1125 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1126 | iowrite32(1, card->config_regs + IRQ_EN_ADDR); |
| 1127 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1128 | if (fpga_upgrade) |
| 1129 | flash_upgrade(card, 0); |
| 1130 | |
| 1131 | if (firmware_upgrade) |
| 1132 | flash_upgrade(card, 1); |
| 1133 | |
| 1134 | err = atm_init(card); |
| 1135 | if (err) |
| 1136 | goto out_free_irq; |
| 1137 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1138 | return 0; |
| 1139 | |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1140 | out_free_irq: |
| 1141 | iowrite32(0, card->config_regs + IRQ_EN_ADDR); |
| 1142 | free_irq(dev->irq, card); |
| 1143 | tasklet_kill(&card->tlet); |
| 1144 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1145 | out_unmap_both: |
David Woodhouse | fa755b9 | 2009-01-27 14:16:12 +1100 | [diff] [blame] | 1146 | pci_set_drvdata(dev, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1147 | pci_iounmap(dev, card->config_regs); |
| 1148 | out_unmap_config: |
| 1149 | pci_iounmap(dev, card->buffers); |
| 1150 | out_release_regions: |
| 1151 | pci_release_regions(dev); |
| 1152 | out: |
| 1153 | return err; |
| 1154 | } |
| 1155 | |
| 1156 | static int atm_init(struct solos_card *card) |
| 1157 | { |
| 1158 | int i; |
| 1159 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1160 | for (i = 0; i < card->nr_ports; i++) { |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 1161 | struct sk_buff *skb; |
| 1162 | struct pkt_hdr *header; |
| 1163 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1164 | skb_queue_head_init(&card->tx_queue[i]); |
| 1165 | skb_queue_head_init(&card->cli_queue[i]); |
| 1166 | |
| 1167 | card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL); |
| 1168 | if (!card->atmdev[i]) { |
| 1169 | dev_err(&card->dev->dev, "Could not register ATM device %d\n", i); |
| 1170 | atm_remove(card); |
| 1171 | return -ENODEV; |
| 1172 | } |
| 1173 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console)) |
| 1174 | 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] | 1175 | if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group)) |
| 1176 | 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] | 1177 | |
| 1178 | dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number); |
| 1179 | |
| 1180 | card->atmdev[i]->ci_range.vpi_bits = 8; |
| 1181 | card->atmdev[i]->ci_range.vci_bits = 16; |
| 1182 | card->atmdev[i]->dev_data = card; |
| 1183 | card->atmdev[i]->phy_data = (void *)(unsigned long)i; |
David Woodhouse | 87ebb18 | 2009-01-27 20:02:30 +1100 | [diff] [blame] | 1184 | card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN; |
| 1185 | |
| 1186 | skb = alloc_skb(sizeof(*header), GFP_ATOMIC); |
| 1187 | if (!skb) { |
| 1188 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n"); |
| 1189 | continue; |
| 1190 | } |
| 1191 | |
| 1192 | header = (void *)skb_put(skb, sizeof(*header)); |
| 1193 | |
| 1194 | header->size = cpu_to_le16(0); |
| 1195 | header->vpi = cpu_to_le16(0); |
| 1196 | header->vci = cpu_to_le16(0); |
| 1197 | header->type = cpu_to_le16(PKT_STATUS); |
| 1198 | |
| 1199 | fpga_queue(card, i, skb, NULL); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1200 | } |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | static void atm_remove(struct solos_card *card) |
| 1205 | { |
| 1206 | int i; |
| 1207 | |
| 1208 | for (i = 0; i < card->nr_ports; i++) { |
| 1209 | if (card->atmdev[i]) { |
| 1210 | 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] | 1211 | |
| 1212 | sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1213 | atm_dev_deregister(card->atmdev[i]); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | static void fpga_remove(struct pci_dev *dev) |
| 1219 | { |
| 1220 | struct solos_card *card = pci_get_drvdata(dev); |
| 1221 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1222 | atm_remove(card); |
| 1223 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1224 | iowrite32(0, card->config_regs + IRQ_EN_ADDR); |
| 1225 | free_irq(dev->irq, card); |
| 1226 | tasklet_kill(&card->tlet); |
| 1227 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1228 | pci_iounmap(dev, card->buffers); |
| 1229 | pci_iounmap(dev, card->config_regs); |
| 1230 | |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1231 | pci_release_regions(dev); |
| 1232 | pci_disable_device(dev); |
| 1233 | |
| 1234 | pci_set_drvdata(dev, NULL); |
| 1235 | kfree(card); |
David Woodhouse | 9c54004 | 2008-12-23 04:09:02 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | static struct pci_device_id fpga_pci_tbl[] __devinitdata = { |
| 1239 | { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 1240 | { 0, } |
| 1241 | }; |
| 1242 | |
| 1243 | MODULE_DEVICE_TABLE(pci,fpga_pci_tbl); |
| 1244 | |
| 1245 | static struct pci_driver fpga_driver = { |
| 1246 | .name = "solos", |
| 1247 | .id_table = fpga_pci_tbl, |
| 1248 | .probe = fpga_probe, |
| 1249 | .remove = fpga_remove, |
| 1250 | }; |
| 1251 | |
| 1252 | |
| 1253 | static int __init solos_pci_init(void) |
| 1254 | { |
| 1255 | printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION); |
| 1256 | return pci_register_driver(&fpga_driver); |
| 1257 | } |
| 1258 | |
| 1259 | static void __exit solos_pci_exit(void) |
| 1260 | { |
| 1261 | pci_unregister_driver(&fpga_driver); |
| 1262 | printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION); |
| 1263 | } |
| 1264 | |
| 1265 | module_init(solos_pci_init); |
| 1266 | module_exit(solos_pci_exit); |