Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: b1dma.c,v 1.1.2.3 2004/02/10 01:07:12 keil Exp $ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Common module for AVM B1 cards that support dma with AMCC |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright 2000 by Carsten Paeth <calle@calle.de> |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This software may be used and distributed according to the terms |
| 8 | * of the GNU General Public License, incorporated herein by reference. |
| 9 | * |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 14 | #include <linux/proc_fs.h> |
| 15 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/ioport.h> |
| 21 | #include <linux/capi.h> |
| 22 | #include <linux/kernelcapi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <asm/uaccess.h> |
| 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/isdn/capilli.h> |
| 29 | #include "avmcard.h" |
| 30 | #include <linux/isdn/capicmd.h> |
| 31 | #include <linux/isdn/capiutil.h> |
| 32 | |
| 33 | static char *revision = "$Revision: 1.1.2.3 $"; |
| 34 | |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 35 | #undef AVM_B1DMA_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* ------------------------------------------------------------- */ |
| 38 | |
| 39 | MODULE_DESCRIPTION("CAPI4Linux: DMA support for active AVM cards"); |
| 40 | MODULE_AUTHOR("Carsten Paeth"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 43 | static bool suppress_pollack = 0; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 44 | module_param(suppress_pollack, bool, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* ------------------------------------------------------------- */ |
| 47 | |
| 48 | static void b1dma_dispatch_tx(avmcard *card); |
| 49 | |
| 50 | /* ------------------------------------------------------------- */ |
| 51 | |
| 52 | /* S5933 */ |
| 53 | |
| 54 | #define AMCC_RXPTR 0x24 |
| 55 | #define AMCC_RXLEN 0x28 |
| 56 | #define AMCC_TXPTR 0x2c |
| 57 | #define AMCC_TXLEN 0x30 |
| 58 | |
| 59 | #define AMCC_INTCSR 0x38 |
| 60 | # define EN_READ_TC_INT 0x00008000L |
| 61 | # define EN_WRITE_TC_INT 0x00004000L |
| 62 | # define EN_TX_TC_INT EN_READ_TC_INT |
| 63 | # define EN_RX_TC_INT EN_WRITE_TC_INT |
| 64 | # define AVM_FLAG 0x30000000L |
| 65 | |
| 66 | # define ANY_S5933_INT 0x00800000L |
| 67 | # define READ_TC_INT 0x00080000L |
| 68 | # define WRITE_TC_INT 0x00040000L |
| 69 | # define TX_TC_INT READ_TC_INT |
| 70 | # define RX_TC_INT WRITE_TC_INT |
| 71 | # define MASTER_ABORT_INT 0x00100000L |
| 72 | # define TARGET_ABORT_INT 0x00200000L |
| 73 | # define BUS_MASTER_INT 0x00200000L |
| 74 | # define ALL_INT 0x000C0000L |
| 75 | |
| 76 | #define AMCC_MCSR 0x3c |
| 77 | # define A2P_HI_PRIORITY 0x00000100L |
| 78 | # define EN_A2P_TRANSFERS 0x00000400L |
| 79 | # define P2A_HI_PRIORITY 0x00001000L |
| 80 | # define EN_P2A_TRANSFERS 0x00004000L |
| 81 | # define RESET_A2P_FLAGS 0x04000000L |
| 82 | # define RESET_P2A_FLAGS 0x02000000L |
| 83 | |
| 84 | /* ------------------------------------------------------------- */ |
| 85 | |
| 86 | static inline void b1dma_writel(avmcard *card, u32 value, int off) |
| 87 | { |
| 88 | writel(value, card->mbase + off); |
| 89 | } |
| 90 | |
| 91 | static inline u32 b1dma_readl(avmcard *card, int off) |
| 92 | { |
| 93 | return readl(card->mbase + off); |
| 94 | } |
| 95 | |
| 96 | /* ------------------------------------------------------------- */ |
| 97 | |
| 98 | static inline int b1dma_tx_empty(unsigned int port) |
| 99 | { |
| 100 | return inb(port + 0x03) & 0x1; |
| 101 | } |
| 102 | |
| 103 | static inline int b1dma_rx_full(unsigned int port) |
| 104 | { |
| 105 | return inb(port + 0x02) & 0x1; |
| 106 | } |
| 107 | |
| 108 | static int b1dma_tolink(avmcard *card, void *buf, unsigned int len) |
| 109 | { |
| 110 | unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */ |
| 111 | unsigned char *s = (unsigned char *)buf; |
| 112 | while (len--) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 113 | while (!b1dma_tx_empty(card->port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | && time_before(jiffies, stop)); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 115 | if (!b1dma_tx_empty(card->port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return -1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 117 | t1outp(card->port, 0x01, *s++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static int b1dma_fromlink(avmcard *card, void *buf, unsigned int len) |
| 123 | { |
| 124 | unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */ |
| 125 | unsigned char *s = (unsigned char *)buf; |
| 126 | while (len--) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 127 | while (!b1dma_rx_full(card->port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | && time_before(jiffies, stop)); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 129 | if (!b1dma_rx_full(card->port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return -1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 131 | *s++ = t1inp(card->port, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static int WriteReg(avmcard *card, u32 reg, u8 val) |
| 137 | { |
| 138 | u8 cmd = 0x00; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 139 | if (b1dma_tolink(card, &cmd, 1) == 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | && b1dma_tolink(card, ®, 4) == 0) { |
| 141 | u32 tmp = val; |
| 142 | return b1dma_tolink(card, &tmp, 4); |
| 143 | } |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | static u8 ReadReg(avmcard *card, u32 reg) |
| 148 | { |
| 149 | u8 cmd = 0x01; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 150 | if (b1dma_tolink(card, &cmd, 1) == 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | && b1dma_tolink(card, ®, 4) == 0) { |
| 152 | u32 tmp; |
| 153 | if (b1dma_fromlink(card, &tmp, 4) == 0) |
| 154 | return (u8)tmp; |
| 155 | } |
| 156 | return 0xff; |
| 157 | } |
| 158 | |
| 159 | /* ------------------------------------------------------------- */ |
| 160 | |
| 161 | static inline void _put_byte(void **pp, u8 val) |
| 162 | { |
| 163 | u8 *s = *pp; |
| 164 | *s++ = val; |
| 165 | *pp = s; |
| 166 | } |
| 167 | |
| 168 | static inline void _put_word(void **pp, u32 val) |
| 169 | { |
| 170 | u8 *s = *pp; |
| 171 | *s++ = val & 0xff; |
| 172 | *s++ = (val >> 8) & 0xff; |
| 173 | *s++ = (val >> 16) & 0xff; |
| 174 | *s++ = (val >> 24) & 0xff; |
| 175 | *pp = s; |
| 176 | } |
| 177 | |
| 178 | static inline void _put_slice(void **pp, unsigned char *dp, unsigned int len) |
| 179 | { |
| 180 | unsigned i = len; |
| 181 | _put_word(pp, i); |
| 182 | while (i-- > 0) |
| 183 | _put_byte(pp, *dp++); |
| 184 | } |
| 185 | |
| 186 | static inline u8 _get_byte(void **pp) |
| 187 | { |
| 188 | u8 *s = *pp; |
| 189 | u8 val; |
| 190 | val = *s++; |
| 191 | *pp = s; |
| 192 | return val; |
| 193 | } |
| 194 | |
| 195 | static inline u32 _get_word(void **pp) |
| 196 | { |
| 197 | u8 *s = *pp; |
| 198 | u32 val; |
| 199 | val = *s++; |
| 200 | val |= (*s++ << 8); |
| 201 | val |= (*s++ << 16); |
| 202 | val |= (*s++ << 24); |
| 203 | *pp = s; |
| 204 | return val; |
| 205 | } |
| 206 | |
| 207 | static inline u32 _get_slice(void **pp, unsigned char *dp) |
| 208 | { |
| 209 | unsigned int len, i; |
| 210 | |
| 211 | len = i = _get_word(pp); |
| 212 | while (i-- > 0) *dp++ = _get_byte(pp); |
| 213 | return len; |
| 214 | } |
| 215 | |
| 216 | /* ------------------------------------------------------------- */ |
| 217 | |
| 218 | void b1dma_reset(avmcard *card) |
| 219 | { |
| 220 | card->csr = 0x0; |
| 221 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
| 222 | b1dma_writel(card, 0, AMCC_MCSR); |
| 223 | b1dma_writel(card, 0, AMCC_RXLEN); |
| 224 | b1dma_writel(card, 0, AMCC_TXLEN); |
| 225 | |
| 226 | t1outp(card->port, 0x10, 0x00); |
| 227 | t1outp(card->port, 0x07, 0x00); |
| 228 | |
| 229 | b1dma_writel(card, 0, AMCC_MCSR); |
| 230 | mdelay(10); |
| 231 | b1dma_writel(card, 0x0f000000, AMCC_MCSR); /* reset all */ |
| 232 | mdelay(10); |
| 233 | b1dma_writel(card, 0, AMCC_MCSR); |
| 234 | if (card->cardtype == avm_t1pci) |
| 235 | mdelay(42); |
| 236 | else |
| 237 | mdelay(10); |
| 238 | } |
| 239 | |
| 240 | /* ------------------------------------------------------------- */ |
| 241 | |
| 242 | static int b1dma_detect(avmcard *card) |
| 243 | { |
| 244 | b1dma_writel(card, 0, AMCC_MCSR); |
| 245 | mdelay(10); |
| 246 | b1dma_writel(card, 0x0f000000, AMCC_MCSR); /* reset all */ |
| 247 | mdelay(10); |
| 248 | b1dma_writel(card, 0, AMCC_MCSR); |
| 249 | mdelay(42); |
| 250 | |
| 251 | b1dma_writel(card, 0, AMCC_RXLEN); |
| 252 | b1dma_writel(card, 0, AMCC_TXLEN); |
| 253 | card->csr = 0x0; |
| 254 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
| 255 | |
| 256 | if (b1dma_readl(card, AMCC_MCSR) != 0x000000E6) |
| 257 | return 1; |
| 258 | |
| 259 | b1dma_writel(card, 0xffffffff, AMCC_RXPTR); |
| 260 | b1dma_writel(card, 0xffffffff, AMCC_TXPTR); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 261 | if (b1dma_readl(card, AMCC_RXPTR) != 0xfffffffc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | || b1dma_readl(card, AMCC_TXPTR) != 0xfffffffc) |
| 263 | return 2; |
| 264 | |
| 265 | b1dma_writel(card, 0x0, AMCC_RXPTR); |
| 266 | b1dma_writel(card, 0x0, AMCC_TXPTR); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 267 | if (b1dma_readl(card, AMCC_RXPTR) != 0x0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | || b1dma_readl(card, AMCC_TXPTR) != 0x0) |
| 269 | return 3; |
| 270 | |
| 271 | t1outp(card->port, 0x10, 0x00); |
| 272 | t1outp(card->port, 0x07, 0x00); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | t1outp(card->port, 0x02, 0x02); |
| 275 | t1outp(card->port, 0x03, 0x02); |
| 276 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 277 | if ((t1inp(card->port, 0x02) & 0xFE) != 0x02 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | || t1inp(card->port, 0x3) != 0x03) |
| 279 | return 4; |
| 280 | |
| 281 | t1outp(card->port, 0x02, 0x00); |
| 282 | t1outp(card->port, 0x03, 0x00); |
| 283 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 284 | if ((t1inp(card->port, 0x02) & 0xFE) != 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | || t1inp(card->port, 0x3) != 0x01) |
| 286 | return 5; |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | int t1pci_detect(avmcard *card) |
| 292 | { |
| 293 | int ret; |
| 294 | |
| 295 | if ((ret = b1dma_detect(card)) != 0) |
| 296 | return ret; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* Transputer test */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 299 | |
| 300 | if (WriteReg(card, 0x80001000, 0x11) != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | || WriteReg(card, 0x80101000, 0x22) != 0 |
| 302 | || WriteReg(card, 0x80201000, 0x33) != 0 |
| 303 | || WriteReg(card, 0x80301000, 0x44) != 0) |
| 304 | return 6; |
| 305 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 306 | if (ReadReg(card, 0x80001000) != 0x11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | || ReadReg(card, 0x80101000) != 0x22 |
| 308 | || ReadReg(card, 0x80201000) != 0x33 |
| 309 | || ReadReg(card, 0x80301000) != 0x44) |
| 310 | return 7; |
| 311 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 312 | if (WriteReg(card, 0x80001000, 0x55) != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | || WriteReg(card, 0x80101000, 0x66) != 0 |
| 314 | || WriteReg(card, 0x80201000, 0x77) != 0 |
| 315 | || WriteReg(card, 0x80301000, 0x88) != 0) |
| 316 | return 8; |
| 317 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 318 | if (ReadReg(card, 0x80001000) != 0x55 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | || ReadReg(card, 0x80101000) != 0x66 |
| 320 | || ReadReg(card, 0x80201000) != 0x77 |
| 321 | || ReadReg(card, 0x80301000) != 0x88) |
| 322 | return 9; |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | int b1pciv4_detect(avmcard *card) |
| 328 | { |
| 329 | int ret, i; |
| 330 | |
| 331 | if ((ret = b1dma_detect(card)) != 0) |
| 332 | return ret; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 333 | |
| 334 | for (i = 0; i < 5; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if (WriteReg(card, 0x80A00000, 0x21) != 0) |
| 336 | return 6; |
| 337 | if ((ReadReg(card, 0x80A00000) & 0x01) != 0x01) |
| 338 | return 7; |
| 339 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 340 | for (i = 0; i < 5; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (WriteReg(card, 0x80A00000, 0x20) != 0) |
| 342 | return 8; |
| 343 | if ((ReadReg(card, 0x80A00000) & 0x01) != 0x00) |
| 344 | return 9; |
| 345 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static void b1dma_queue_tx(avmcard *card, struct sk_buff *skb) |
| 351 | { |
| 352 | unsigned long flags; |
| 353 | |
| 354 | spin_lock_irqsave(&card->lock, flags); |
| 355 | |
| 356 | skb_queue_tail(&card->dma->send_queue, skb); |
| 357 | |
| 358 | if (!(card->csr & EN_TX_TC_INT)) { |
| 359 | b1dma_dispatch_tx(card); |
| 360 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
| 361 | } |
| 362 | |
| 363 | spin_unlock_irqrestore(&card->lock, flags); |
| 364 | } |
| 365 | |
| 366 | /* ------------------------------------------------------------- */ |
| 367 | |
| 368 | static void b1dma_dispatch_tx(avmcard *card) |
| 369 | { |
| 370 | avmcard_dmainfo *dma = card->dma; |
| 371 | struct sk_buff *skb; |
| 372 | u8 cmd, subcmd; |
| 373 | u16 len; |
| 374 | u32 txlen; |
| 375 | void *p; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | skb = skb_dequeue(&dma->send_queue); |
| 378 | |
| 379 | len = CAPIMSG_LEN(skb->data); |
| 380 | |
| 381 | if (len) { |
| 382 | cmd = CAPIMSG_COMMAND(skb->data); |
| 383 | subcmd = CAPIMSG_SUBCOMMAND(skb->data); |
| 384 | |
| 385 | p = dma->sendbuf.dmabuf; |
| 386 | |
| 387 | if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) { |
| 388 | u16 dlen = CAPIMSG_DATALEN(skb->data); |
| 389 | _put_byte(&p, SEND_DATA_B3_REQ); |
| 390 | _put_slice(&p, skb->data, len); |
| 391 | _put_slice(&p, skb->data + len, dlen); |
| 392 | } else { |
| 393 | _put_byte(&p, SEND_MESSAGE); |
| 394 | _put_slice(&p, skb->data, len); |
| 395 | } |
| 396 | txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf; |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 397 | #ifdef AVM_B1DMA_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | printk(KERN_DEBUG "tx: put msg len=%d\n", txlen); |
| 399 | #endif |
| 400 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 401 | txlen = skb->len - 2; |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 402 | #ifdef AVM_B1DMA_POLLDEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (skb->data[2] == SEND_POLLACK) |
| 404 | printk(KERN_INFO "%s: send ack\n", card->name); |
| 405 | #endif |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 406 | #ifdef AVM_B1DMA_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 407 | printk(KERN_DEBUG "tx: put 0x%x len=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | skb->data[2], txlen); |
| 409 | #endif |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 410 | skb_copy_from_linear_data_offset(skb, 2, dma->sendbuf.dmabuf, |
| 411 | skb->len - 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | txlen = (txlen + 3) & ~3; |
| 414 | |
| 415 | b1dma_writel(card, dma->sendbuf.dmaaddr, AMCC_TXPTR); |
| 416 | b1dma_writel(card, txlen, AMCC_TXLEN); |
| 417 | |
| 418 | card->csr |= EN_TX_TC_INT; |
| 419 | |
| 420 | dev_kfree_skb_any(skb); |
| 421 | } |
| 422 | |
| 423 | /* ------------------------------------------------------------- */ |
| 424 | |
| 425 | static void queue_pollack(avmcard *card) |
| 426 | { |
| 427 | struct sk_buff *skb; |
| 428 | void *p; |
| 429 | |
| 430 | skb = alloc_skb(3, GFP_ATOMIC); |
| 431 | if (!skb) { |
| 432 | printk(KERN_CRIT "%s: no memory, lost poll ack\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 433 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | p = skb->data; |
| 437 | _put_byte(&p, 0); |
| 438 | _put_byte(&p, 0); |
| 439 | _put_byte(&p, SEND_POLLACK); |
| 440 | skb_put(skb, (u8 *)p - (u8 *)skb->data); |
| 441 | |
| 442 | b1dma_queue_tx(card, skb); |
| 443 | } |
| 444 | |
| 445 | /* ------------------------------------------------------------- */ |
| 446 | |
| 447 | static void b1dma_handle_rx(avmcard *card) |
| 448 | { |
| 449 | avmctrl_info *cinfo = &card->ctrlinfo[0]; |
| 450 | avmcard_dmainfo *dma = card->dma; |
| 451 | struct capi_ctr *ctrl = &cinfo->capi_ctrl; |
| 452 | struct sk_buff *skb; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 453 | void *p = dma->recvbuf.dmabuf + 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; |
| 455 | u8 b1cmd = _get_byte(&p); |
| 456 | |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 457 | #ifdef AVM_B1DMA_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | printk(KERN_DEBUG "rx: 0x%x %lu\n", b1cmd, (unsigned long)dma->recvlen); |
| 459 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | switch (b1cmd) { |
| 462 | case RECEIVE_DATA_B3_IND: |
| 463 | |
| 464 | ApplId = (unsigned) _get_word(&p); |
| 465 | MsgLen = _get_slice(&p, card->msgbuf); |
| 466 | DataB3Len = _get_slice(&p, card->databuf); |
| 467 | |
| 468 | if (MsgLen < 30) { /* not CAPI 64Bit */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 469 | memset(card->msgbuf + MsgLen, 0, 30 - MsgLen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | MsgLen = 30; |
| 471 | CAPIMSG_SETLEN(card->msgbuf, 30); |
| 472 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 473 | if (!(skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | printk(KERN_ERR "%s: incoming packet dropped\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 475 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } else { |
| 477 | memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); |
| 478 | memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len); |
| 479 | capi_ctr_handle_message(ctrl, ApplId, skb); |
| 480 | } |
| 481 | break; |
| 482 | |
| 483 | case RECEIVE_MESSAGE: |
| 484 | |
| 485 | ApplId = (unsigned) _get_word(&p); |
| 486 | MsgLen = _get_slice(&p, card->msgbuf); |
| 487 | if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) { |
| 488 | printk(KERN_ERR "%s: incoming packet dropped\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 489 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } else { |
| 491 | memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 492 | if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF) { |
| 493 | spin_lock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | capilib_data_b3_conf(&cinfo->ncci_head, ApplId, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 495 | CAPIMSG_NCCI(skb->data), |
| 496 | CAPIMSG_MSGID(skb->data)); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 497 | spin_unlock(&card->lock); |
| 498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | capi_ctr_handle_message(ctrl, ApplId, skb); |
| 500 | } |
| 501 | break; |
| 502 | |
| 503 | case RECEIVE_NEW_NCCI: |
| 504 | |
| 505 | ApplId = _get_word(&p); |
| 506 | NCCI = _get_word(&p); |
| 507 | WindowSize = _get_word(&p); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 508 | spin_lock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | capilib_new_ncci(&cinfo->ncci_head, ApplId, NCCI, WindowSize); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 510 | spin_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | break; |
| 512 | |
| 513 | case RECEIVE_FREE_NCCI: |
| 514 | |
| 515 | ApplId = _get_word(&p); |
| 516 | NCCI = _get_word(&p); |
| 517 | |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 518 | if (NCCI != 0xffffffff) { |
| 519 | spin_lock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | capilib_free_ncci(&cinfo->ncci_head, ApplId, NCCI); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 521 | spin_unlock(&card->lock); |
| 522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | break; |
| 524 | |
| 525 | case RECEIVE_START: |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 526 | #ifdef AVM_B1DMA_POLLDEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | printk(KERN_INFO "%s: receive poll\n", card->name); |
| 528 | #endif |
| 529 | if (!suppress_pollack) |
| 530 | queue_pollack(card); |
| 531 | capi_ctr_resume_output(ctrl); |
| 532 | break; |
| 533 | |
| 534 | case RECEIVE_STOP: |
| 535 | capi_ctr_suspend_output(ctrl); |
| 536 | break; |
| 537 | |
| 538 | case RECEIVE_INIT: |
| 539 | |
| 540 | cinfo->versionlen = _get_slice(&p, cinfo->versionbuf); |
| 541 | b1_parse_version(cinfo); |
| 542 | printk(KERN_INFO "%s: %s-card (%s) now active\n", |
| 543 | card->name, |
| 544 | cinfo->version[VER_CARDTYPE], |
| 545 | cinfo->version[VER_DRIVER]); |
| 546 | capi_ctr_ready(ctrl); |
| 547 | break; |
| 548 | |
| 549 | case RECEIVE_TASK_READY: |
| 550 | ApplId = (unsigned) _get_word(&p); |
| 551 | MsgLen = _get_slice(&p, card->msgbuf); |
| 552 | card->msgbuf[MsgLen] = 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 553 | while (MsgLen > 0 |
| 554 | && (card->msgbuf[MsgLen - 1] == '\n' |
| 555 | || card->msgbuf[MsgLen - 1] == '\r')) { |
| 556 | card->msgbuf[MsgLen - 1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | MsgLen--; |
| 558 | } |
| 559 | printk(KERN_INFO "%s: task %d \"%s\" ready.\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 560 | card->name, ApplId, card->msgbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | case RECEIVE_DEBUGMSG: |
| 564 | MsgLen = _get_slice(&p, card->msgbuf); |
| 565 | card->msgbuf[MsgLen] = 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 566 | while (MsgLen > 0 |
| 567 | && (card->msgbuf[MsgLen - 1] == '\n' |
| 568 | || card->msgbuf[MsgLen - 1] == '\r')) { |
| 569 | card->msgbuf[MsgLen - 1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | MsgLen--; |
| 571 | } |
| 572 | printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf); |
| 573 | break; |
| 574 | |
| 575 | default: |
| 576 | printk(KERN_ERR "%s: b1dma_interrupt: 0x%x ???\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 577 | card->name, b1cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /* ------------------------------------------------------------- */ |
| 583 | |
| 584 | static void b1dma_handle_interrupt(avmcard *card) |
| 585 | { |
| 586 | u32 status; |
| 587 | u32 newcsr; |
| 588 | |
| 589 | spin_lock(&card->lock); |
| 590 | |
| 591 | status = b1dma_readl(card, AMCC_INTCSR); |
| 592 | if ((status & ANY_S5933_INT) == 0) { |
| 593 | spin_unlock(&card->lock); |
| 594 | return; |
| 595 | } |
| 596 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 597 | newcsr = card->csr | (status & ALL_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (status & TX_TC_INT) newcsr &= ~EN_TX_TC_INT; |
| 599 | if (status & RX_TC_INT) newcsr &= ~EN_RX_TC_INT; |
| 600 | b1dma_writel(card, newcsr, AMCC_INTCSR); |
| 601 | |
| 602 | if ((status & RX_TC_INT) != 0) { |
| 603 | struct avmcard_dmainfo *dma = card->dma; |
| 604 | u32 rxlen; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 605 | if (card->dma->recvlen == 0) { |
| 606 | rxlen = b1dma_readl(card, AMCC_RXLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | if (rxlen == 0) { |
| 608 | dma->recvlen = *((u32 *)dma->recvbuf.dmabuf); |
| 609 | rxlen = (dma->recvlen + 3) & ~3; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 610 | b1dma_writel(card, dma->recvbuf.dmaaddr + 4, AMCC_RXPTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | b1dma_writel(card, rxlen, AMCC_RXLEN); |
Robert P. J. Day | 26fb5c5 | 2007-02-12 00:53:20 -0800 | [diff] [blame] | 612 | #ifdef AVM_B1DMA_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } else { |
| 614 | printk(KERN_ERR "%s: rx not complete (%d).\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 615 | card->name, rxlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | #endif |
| 617 | } |
| 618 | } else { |
| 619 | spin_unlock(&card->lock); |
| 620 | b1dma_handle_rx(card); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 621 | dma->recvlen = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | spin_lock(&card->lock); |
| 623 | b1dma_writel(card, dma->recvbuf.dmaaddr, AMCC_RXPTR); |
| 624 | b1dma_writel(card, 4, AMCC_RXLEN); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | if ((status & TX_TC_INT) != 0) { |
| 629 | if (skb_queue_empty(&card->dma->send_queue)) |
| 630 | card->csr &= ~EN_TX_TC_INT; |
| 631 | else |
| 632 | b1dma_dispatch_tx(card); |
| 633 | } |
| 634 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
| 635 | |
| 636 | spin_unlock(&card->lock); |
| 637 | } |
| 638 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 639 | irqreturn_t b1dma_interrupt(int interrupt, void *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
| 641 | avmcard *card = devptr; |
| 642 | |
| 643 | b1dma_handle_interrupt(card); |
| 644 | return IRQ_HANDLED; |
| 645 | } |
| 646 | |
| 647 | /* ------------------------------------------------------------- */ |
| 648 | |
| 649 | static int b1dma_loaded(avmcard *card) |
| 650 | { |
| 651 | unsigned long stop; |
| 652 | unsigned char ans; |
| 653 | unsigned long tout = 2; |
| 654 | unsigned int base = card->port; |
| 655 | |
| 656 | for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) { |
| 657 | if (b1_tx_empty(base)) |
| 658 | break; |
| 659 | } |
| 660 | if (!b1_tx_empty(base)) { |
| 661 | printk(KERN_ERR "%s: b1dma_loaded: tx err, corrupted t4 file ?\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 662 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | return 0; |
| 664 | } |
| 665 | b1_put_byte(base, SEND_POLLACK); |
| 666 | for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) { |
| 667 | if (b1_rx_full(base)) { |
| 668 | if ((ans = b1_get_byte(base)) == RECEIVE_POLLDWORD) { |
| 669 | return 1; |
| 670 | } |
| 671 | printk(KERN_ERR "%s: b1dma_loaded: got 0x%x, firmware not running in dword mode\n", card->name, ans); |
| 672 | return 0; |
| 673 | } |
| 674 | } |
| 675 | printk(KERN_ERR "%s: b1dma_loaded: firmware not running\n", card->name); |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* ------------------------------------------------------------- */ |
| 680 | |
| 681 | static void b1dma_send_init(avmcard *card) |
| 682 | { |
| 683 | struct sk_buff *skb; |
| 684 | void *p; |
| 685 | |
| 686 | skb = alloc_skb(15, GFP_ATOMIC); |
| 687 | if (!skb) { |
| 688 | printk(KERN_CRIT "%s: no memory, lost register appl.\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 689 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | return; |
| 691 | } |
| 692 | p = skb->data; |
| 693 | _put_byte(&p, 0); |
| 694 | _put_byte(&p, 0); |
| 695 | _put_byte(&p, SEND_INIT); |
| 696 | _put_word(&p, CAPI_MAXAPPL); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 697 | _put_word(&p, AVM_NCCI_PER_CHANNEL * 30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | _put_word(&p, card->cardnr - 1); |
| 699 | skb_put(skb, (u8 *)p - (u8 *)skb->data); |
| 700 | |
| 701 | b1dma_queue_tx(card, skb); |
| 702 | } |
| 703 | |
| 704 | int b1dma_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) |
| 705 | { |
| 706 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 707 | avmcard *card = cinfo->card; |
| 708 | int retval; |
| 709 | |
| 710 | b1dma_reset(card); |
| 711 | |
| 712 | if ((retval = b1_load_t4file(card, &data->firmware))) { |
| 713 | b1dma_reset(card); |
| 714 | printk(KERN_ERR "%s: failed to load t4file!!\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 715 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | return retval; |
| 717 | } |
| 718 | |
| 719 | if (data->configuration.len > 0 && data->configuration.data) { |
| 720 | if ((retval = b1_load_config(card, &data->configuration))) { |
| 721 | b1dma_reset(card); |
| 722 | printk(KERN_ERR "%s: failed to load config!!\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 723 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | return retval; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | if (!b1dma_loaded(card)) { |
| 729 | b1dma_reset(card); |
| 730 | printk(KERN_ERR "%s: failed to load t4file.\n", card->name); |
| 731 | return -EIO; |
| 732 | } |
| 733 | |
| 734 | card->csr = AVM_FLAG; |
| 735 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 736 | b1dma_writel(card, EN_A2P_TRANSFERS | EN_P2A_TRANSFERS | A2P_HI_PRIORITY | |
| 737 | P2A_HI_PRIORITY | RESET_A2P_FLAGS | RESET_P2A_FLAGS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | AMCC_MCSR); |
| 739 | t1outp(card->port, 0x07, 0x30); |
| 740 | t1outp(card->port, 0x10, 0xF0); |
| 741 | |
| 742 | card->dma->recvlen = 0; |
| 743 | b1dma_writel(card, card->dma->recvbuf.dmaaddr, AMCC_RXPTR); |
| 744 | b1dma_writel(card, 4, AMCC_RXLEN); |
| 745 | card->csr |= EN_RX_TC_INT; |
| 746 | b1dma_writel(card, card->csr, AMCC_INTCSR); |
| 747 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 748 | b1dma_send_init(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | void b1dma_reset_ctr(struct capi_ctr *ctrl) |
| 754 | { |
| 755 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 756 | avmcard *card = cinfo->card; |
| 757 | unsigned long flags; |
| 758 | |
| 759 | spin_lock_irqsave(&card->lock, flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 760 | b1dma_reset(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | memset(cinfo->version, 0, sizeof(cinfo->version)); |
| 763 | capilib_release(&cinfo->ncci_head); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 764 | spin_unlock_irqrestore(&card->lock, flags); |
Tilman Schmidt | 4e32997 | 2009-06-07 09:09:23 +0000 | [diff] [blame] | 765 | capi_ctr_down(ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /* ------------------------------------------------------------- */ |
| 769 | |
| 770 | void b1dma_register_appl(struct capi_ctr *ctrl, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 771 | u16 appl, |
| 772 | capi_register_params *rp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
| 774 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 775 | avmcard *card = cinfo->card; |
| 776 | struct sk_buff *skb; |
| 777 | int want = rp->level3cnt; |
| 778 | int nconn; |
| 779 | void *p; |
| 780 | |
| 781 | if (want > 0) nconn = want; |
| 782 | else nconn = ctrl->profile.nbchannel * -want; |
| 783 | if (nconn == 0) nconn = ctrl->profile.nbchannel; |
| 784 | |
| 785 | skb = alloc_skb(23, GFP_ATOMIC); |
| 786 | if (!skb) { |
| 787 | printk(KERN_CRIT "%s: no memory, lost register appl.\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 788 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | p = skb->data; |
| 792 | _put_byte(&p, 0); |
| 793 | _put_byte(&p, 0); |
| 794 | _put_byte(&p, SEND_REGISTER); |
| 795 | _put_word(&p, appl); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 796 | _put_word(&p, 1024 * (nconn + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | _put_word(&p, nconn); |
| 798 | _put_word(&p, rp->datablkcnt); |
| 799 | _put_word(&p, rp->datablklen); |
| 800 | skb_put(skb, (u8 *)p - (u8 *)skb->data); |
| 801 | |
| 802 | b1dma_queue_tx(card, skb); |
| 803 | } |
| 804 | |
| 805 | /* ------------------------------------------------------------- */ |
| 806 | |
| 807 | void b1dma_release_appl(struct capi_ctr *ctrl, u16 appl) |
| 808 | { |
| 809 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 810 | avmcard *card = cinfo->card; |
| 811 | struct sk_buff *skb; |
| 812 | void *p; |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 813 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 815 | spin_lock_irqsave(&card->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | capilib_release_appl(&cinfo->ncci_head, appl); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 817 | spin_unlock_irqrestore(&card->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | skb = alloc_skb(7, GFP_ATOMIC); |
| 820 | if (!skb) { |
| 821 | printk(KERN_CRIT "%s: no memory, lost release appl.\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 822 | card->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | p = skb->data; |
| 826 | _put_byte(&p, 0); |
| 827 | _put_byte(&p, 0); |
| 828 | _put_byte(&p, SEND_RELEASE); |
| 829 | _put_word(&p, appl); |
| 830 | |
| 831 | skb_put(skb, (u8 *)p - (u8 *)skb->data); |
| 832 | |
| 833 | b1dma_queue_tx(card, skb); |
| 834 | } |
| 835 | |
| 836 | /* ------------------------------------------------------------- */ |
| 837 | |
| 838 | u16 b1dma_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) |
| 839 | { |
| 840 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 841 | avmcard *card = cinfo->card; |
| 842 | u16 retval = CAPI_NOERROR; |
| 843 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 844 | if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) { |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 845 | unsigned long flags; |
| 846 | spin_lock_irqsave(&card->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | retval = capilib_data_b3_req(&cinfo->ncci_head, |
| 848 | CAPIMSG_APPID(skb->data), |
| 849 | CAPIMSG_NCCI(skb->data), |
| 850 | CAPIMSG_MSGID(skb->data)); |
Karsten Keil | 1e9c7813 | 2007-10-18 23:39:19 -0700 | [diff] [blame] | 851 | spin_unlock_irqrestore(&card->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 853 | if (retval == CAPI_NOERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | b1dma_queue_tx(card, skb); |
| 855 | |
| 856 | return retval; |
| 857 | } |
| 858 | |
| 859 | /* ------------------------------------------------------------- */ |
| 860 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 861 | static int b1dmactl_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 863 | struct capi_ctr *ctrl = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); |
| 865 | avmcard *card = cinfo->card; |
| 866 | u8 flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | char *s; |
| 868 | u32 txoff, txlen, rxoff, rxlen, csr; |
| 869 | unsigned long flags; |
| 870 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 871 | seq_printf(m, "%-16s %s\n", "name", card->name); |
| 872 | seq_printf(m, "%-16s 0x%x\n", "io", card->port); |
| 873 | seq_printf(m, "%-16s %d\n", "irq", card->irq); |
| 874 | seq_printf(m, "%-16s 0x%lx\n", "membase", card->membase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | switch (card->cardtype) { |
| 876 | case avm_b1isa: s = "B1 ISA"; break; |
| 877 | case avm_b1pci: s = "B1 PCI"; break; |
| 878 | case avm_b1pcmcia: s = "B1 PCMCIA"; break; |
| 879 | case avm_m1: s = "M1"; break; |
| 880 | case avm_m2: s = "M2"; break; |
| 881 | case avm_t1isa: s = "T1 ISA (HEMA)"; break; |
| 882 | case avm_t1pci: s = "T1 PCI"; break; |
| 883 | case avm_c4: s = "C4"; break; |
| 884 | case avm_c2: s = "C2"; break; |
| 885 | default: s = "???"; break; |
| 886 | } |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 887 | seq_printf(m, "%-16s %s\n", "type", s); |
Harvey Harrison | 8e44b29 | 2008-04-28 02:14:38 -0700 | [diff] [blame] | 888 | if ((s = cinfo->version[VER_DRIVER]) != NULL) |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 889 | seq_printf(m, "%-16s %s\n", "ver_driver", s); |
Harvey Harrison | 8e44b29 | 2008-04-28 02:14:38 -0700 | [diff] [blame] | 890 | if ((s = cinfo->version[VER_CARDTYPE]) != NULL) |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 891 | seq_printf(m, "%-16s %s\n", "ver_cardtype", s); |
Harvey Harrison | 8e44b29 | 2008-04-28 02:14:38 -0700 | [diff] [blame] | 892 | if ((s = cinfo->version[VER_SERIAL]) != NULL) |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 893 | seq_printf(m, "%-16s %s\n", "ver_serial", s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | if (card->cardtype != avm_m1) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 896 | flag = ((u8 *)(ctrl->profile.manu))[3]; |
| 897 | if (flag) |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 898 | seq_printf(m, "%-16s%s%s%s%s%s%s%s\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 899 | "protocol", |
| 900 | (flag & 0x01) ? " DSS1" : "", |
| 901 | (flag & 0x02) ? " CT1" : "", |
| 902 | (flag & 0x04) ? " VN3" : "", |
| 903 | (flag & 0x08) ? " NI1" : "", |
| 904 | (flag & 0x10) ? " AUSTEL" : "", |
| 905 | (flag & 0x20) ? " ESS" : "", |
| 906 | (flag & 0x40) ? " 1TR6" : "" |
| 907 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | if (card->cardtype != avm_m1) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 910 | flag = ((u8 *)(ctrl->profile.manu))[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (flag) |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 912 | seq_printf(m, "%-16s%s%s%s%s\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 913 | "linetype", |
| 914 | (flag & 0x01) ? " point to point" : "", |
| 915 | (flag & 0x02) ? " point to multipoint" : "", |
| 916 | (flag & 0x08) ? " leased line without D-channel" : "", |
| 917 | (flag & 0x04) ? " leased line with D-channel" : "" |
| 918 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 920 | seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
| 922 | |
| 923 | spin_lock_irqsave(&card->lock, flags); |
| 924 | |
| 925 | txoff = (dma_addr_t)b1dma_readl(card, AMCC_TXPTR)-card->dma->sendbuf.dmaaddr; |
| 926 | txlen = b1dma_readl(card, AMCC_TXLEN); |
| 927 | |
| 928 | rxoff = (dma_addr_t)b1dma_readl(card, AMCC_RXPTR)-card->dma->recvbuf.dmaaddr; |
| 929 | rxlen = b1dma_readl(card, AMCC_RXLEN); |
| 930 | |
| 931 | csr = b1dma_readl(card, AMCC_INTCSR); |
| 932 | |
| 933 | spin_unlock_irqrestore(&card->lock, flags); |
| 934 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 935 | seq_printf(m, "%-16s 0x%lx\n", "csr (cached)", (unsigned long)card->csr); |
| 936 | seq_printf(m, "%-16s 0x%lx\n", "csr", (unsigned long)csr); |
| 937 | seq_printf(m, "%-16s %lu\n", "txoff", (unsigned long)txoff); |
| 938 | seq_printf(m, "%-16s %lu\n", "txlen", (unsigned long)txlen); |
| 939 | seq_printf(m, "%-16s %lu\n", "rxoff", (unsigned long)rxoff); |
| 940 | seq_printf(m, "%-16s %lu\n", "rxlen", (unsigned long)rxlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 942 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 945 | static int b1dmactl_proc_open(struct inode *inode, struct file *file) |
| 946 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 947 | return single_open(file, b1dmactl_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | const struct file_operations b1dmactl_proc_fops = { |
| 951 | .owner = THIS_MODULE, |
| 952 | .open = b1dmactl_proc_open, |
| 953 | .read = seq_read, |
| 954 | .llseek = seq_lseek, |
| 955 | .release = single_release, |
| 956 | }; |
| 957 | EXPORT_SYMBOL(b1dmactl_proc_fops); |
| 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | /* ------------------------------------------------------------- */ |
| 960 | |
| 961 | EXPORT_SYMBOL(b1dma_reset); |
| 962 | EXPORT_SYMBOL(t1pci_detect); |
| 963 | EXPORT_SYMBOL(b1pciv4_detect); |
| 964 | EXPORT_SYMBOL(b1dma_interrupt); |
| 965 | |
| 966 | EXPORT_SYMBOL(b1dma_load_firmware); |
| 967 | EXPORT_SYMBOL(b1dma_reset_ctr); |
| 968 | EXPORT_SYMBOL(b1dma_register_appl); |
| 969 | EXPORT_SYMBOL(b1dma_release_appl); |
| 970 | EXPORT_SYMBOL(b1dma_send_message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
Adrian Bunk | 08e5153 | 2005-06-25 14:58:37 -0700 | [diff] [blame] | 972 | static int __init b1dma_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
| 974 | char *p; |
| 975 | char rev[32]; |
| 976 | |
Harvey Harrison | 8e44b29 | 2008-04-28 02:14:38 -0700 | [diff] [blame] | 977 | if ((p = strchr(revision, ':')) != NULL && p[1]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | strlcpy(rev, p + 2, sizeof(rev)); |
Harvey Harrison | 8e44b29 | 2008-04-28 02:14:38 -0700 | [diff] [blame] | 979 | if ((p = strchr(rev, '$')) != NULL && p > rev) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 980 | *(p - 1) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } else |
| 982 | strcpy(rev, "1.0"); |
| 983 | |
| 984 | printk(KERN_INFO "b1dma: revision %s\n", rev); |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Adrian Bunk | 08e5153 | 2005-06-25 14:58:37 -0700 | [diff] [blame] | 989 | static void __exit b1dma_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
| 991 | } |
| 992 | |
| 993 | module_init(b1dma_init); |
| 994 | module_exit(b1dma_exit); |