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