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