Thomas Gleixner | 25763b3 | 2019-05-28 10:10:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Intel IXP4xx Queue Manager driver for Linux |
| 4 | * |
| 5 | * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl> |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/ioport.h> |
| 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
Linus Walleij | 9540724 | 2019-01-27 14:08:36 +0100 | [diff] [blame] | 12 | #include <linux/of.h> |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
Linus Walleij | 4af20dc | 2019-02-10 14:55:58 +0100 | [diff] [blame] | 14 | #include <linux/soc/ixp4xx/qmgr.h> |
Arnd Bergmann | 09aa9aa | 2019-08-25 21:57:25 +0200 | [diff] [blame] | 15 | #include <linux/soc/ixp4xx/cpu.h> |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 16 | |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 17 | static struct qmgr_regs __iomem *qmgr_regs; |
| 18 | static int qmgr_irq_1; |
| 19 | static int qmgr_irq_2; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 20 | static spinlock_t qmgr_lock; |
| 21 | static u32 used_sram_bitmap[4]; /* 128 16-dword pages */ |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 22 | static void (*irq_handlers[QUEUES])(void *pdev); |
| 23 | static void *irq_pdevs[QUEUES]; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 24 | |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 25 | #if DEBUG_QMGR |
| 26 | char qmgr_queue_descs[QUEUES][32]; |
| 27 | #endif |
| 28 | |
Linus Walleij | d08502f | 2019-02-10 20:15:11 +0100 | [diff] [blame] | 29 | void qmgr_put_entry(unsigned int queue, u32 val) |
| 30 | { |
| 31 | #if DEBUG_QMGR |
| 32 | BUG_ON(!qmgr_queue_descs[queue]); /* not yet requested */ |
| 33 | |
| 34 | printk(KERN_DEBUG "Queue %s(%i) put %X\n", |
| 35 | qmgr_queue_descs[queue], queue, val); |
| 36 | #endif |
| 37 | __raw_writel(val, &qmgr_regs->acc[queue][0]); |
| 38 | } |
| 39 | |
| 40 | u32 qmgr_get_entry(unsigned int queue) |
| 41 | { |
| 42 | u32 val; |
| 43 | val = __raw_readl(&qmgr_regs->acc[queue][0]); |
| 44 | #if DEBUG_QMGR |
| 45 | BUG_ON(!qmgr_queue_descs[queue]); /* not yet requested */ |
| 46 | |
| 47 | printk(KERN_DEBUG "Queue %s(%i) get %X\n", |
| 48 | qmgr_queue_descs[queue], queue, val); |
| 49 | #endif |
| 50 | return val; |
| 51 | } |
| 52 | |
| 53 | static int __qmgr_get_stat1(unsigned int queue) |
| 54 | { |
| 55 | return (__raw_readl(&qmgr_regs->stat1[queue >> 3]) |
| 56 | >> ((queue & 7) << 2)) & 0xF; |
| 57 | } |
| 58 | |
| 59 | static int __qmgr_get_stat2(unsigned int queue) |
| 60 | { |
| 61 | BUG_ON(queue >= HALF_QUEUES); |
| 62 | return (__raw_readl(&qmgr_regs->stat2[queue >> 4]) |
| 63 | >> ((queue & 0xF) << 1)) & 0x3; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * qmgr_stat_empty() - checks if a hardware queue is empty |
| 68 | * @queue: queue number |
| 69 | * |
| 70 | * Returns non-zero value if the queue is empty. |
| 71 | */ |
| 72 | int qmgr_stat_empty(unsigned int queue) |
| 73 | { |
| 74 | BUG_ON(queue >= HALF_QUEUES); |
| 75 | return __qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * qmgr_stat_below_low_watermark() - checks if a queue is below low watermark |
| 80 | * @queue: queue number |
| 81 | * |
| 82 | * Returns non-zero value if the queue is below low watermark. |
| 83 | */ |
| 84 | int qmgr_stat_below_low_watermark(unsigned int queue) |
| 85 | { |
| 86 | if (queue >= HALF_QUEUES) |
| 87 | return (__raw_readl(&qmgr_regs->statne_h) >> |
| 88 | (queue - HALF_QUEUES)) & 0x01; |
| 89 | return __qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY; |
| 90 | } |
| 91 | |
| 92 | /** |
Linus Walleij | d08502f | 2019-02-10 20:15:11 +0100 | [diff] [blame] | 93 | * qmgr_stat_full() - checks if a hardware queue is full |
| 94 | * @queue: queue number |
| 95 | * |
| 96 | * Returns non-zero value if the queue is full. |
| 97 | */ |
| 98 | int qmgr_stat_full(unsigned int queue) |
| 99 | { |
| 100 | if (queue >= HALF_QUEUES) |
| 101 | return (__raw_readl(&qmgr_regs->statf_h) >> |
| 102 | (queue - HALF_QUEUES)) & 0x01; |
| 103 | return __qmgr_get_stat1(queue) & QUEUE_STAT1_FULL; |
| 104 | } |
| 105 | |
| 106 | /** |
Linus Walleij | d08502f | 2019-02-10 20:15:11 +0100 | [diff] [blame] | 107 | * qmgr_stat_overflow() - checks if a hardware queue experienced overflow |
| 108 | * @queue: queue number |
| 109 | * |
| 110 | * Returns non-zero value if the queue experienced overflow. |
| 111 | */ |
| 112 | int qmgr_stat_overflow(unsigned int queue) |
| 113 | { |
| 114 | return __qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW; |
| 115 | } |
| 116 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 117 | void qmgr_set_irq(unsigned int queue, int src, |
| 118 | void (*handler)(void *pdev), void *pdev) |
| 119 | { |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 120 | unsigned long flags; |
| 121 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 122 | spin_lock_irqsave(&qmgr_lock, flags); |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 123 | if (queue < HALF_QUEUES) { |
Arnd Bergmann | 0d2c9f05 | 2012-09-28 23:36:10 +0200 | [diff] [blame] | 124 | u32 __iomem *reg; |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 125 | int bit; |
| 126 | BUG_ON(src > QUEUE_IRQ_SRC_NOT_FULL); |
| 127 | reg = &qmgr_regs->irqsrc[queue >> 3]; /* 8 queues per u32 */ |
| 128 | bit = (queue % 8) * 4; /* 3 bits + 1 reserved bit per queue */ |
| 129 | __raw_writel((__raw_readl(reg) & ~(7 << bit)) | (src << bit), |
| 130 | reg); |
| 131 | } else |
| 132 | /* IRQ source for queues 32-63 is fixed */ |
| 133 | BUG_ON(src != QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY); |
| 134 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 135 | irq_handlers[queue] = handler; |
| 136 | irq_pdevs[queue] = pdev; |
| 137 | spin_unlock_irqrestore(&qmgr_lock, flags); |
| 138 | } |
| 139 | |
| 140 | |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 141 | static irqreturn_t qmgr_irq1_a0(int irq, void *pdev) |
| 142 | { |
| 143 | int i, ret = 0; |
Krzysztof Hałasa | 0771c69 | 2009-04-28 19:32:55 +0200 | [diff] [blame] | 144 | u32 en_bitmap, src, stat; |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 145 | |
| 146 | /* ACK - it may clear any bits so don't rely on it */ |
| 147 | __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[0]); |
| 148 | |
Arnd Bergmann | a8eee86 | 2021-08-03 10:12:34 +0200 | [diff] [blame] | 149 | en_bitmap = __raw_readl(&qmgr_regs->irqen[0]); |
Krzysztof Hałasa | 0771c69 | 2009-04-28 19:32:55 +0200 | [diff] [blame] | 150 | while (en_bitmap) { |
| 151 | i = __fls(en_bitmap); /* number of the last "low" queue */ |
| 152 | en_bitmap &= ~BIT(i); |
Arnd Bergmann | a8eee86 | 2021-08-03 10:12:34 +0200 | [diff] [blame] | 153 | src = __raw_readl(&qmgr_regs->irqsrc[i >> 3]); |
| 154 | stat = __raw_readl(&qmgr_regs->stat1[i >> 3]); |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 155 | if (src & 4) /* the IRQ condition is inverted */ |
| 156 | stat = ~stat; |
| 157 | if (stat & BIT(src & 3)) { |
| 158 | irq_handlers[i](irq_pdevs[i]); |
| 159 | ret = IRQ_HANDLED; |
| 160 | } |
| 161 | } |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | static irqreturn_t qmgr_irq2_a0(int irq, void *pdev) |
| 167 | { |
| 168 | int i, ret = 0; |
| 169 | u32 req_bitmap; |
| 170 | |
| 171 | /* ACK - it may clear any bits so don't rely on it */ |
| 172 | __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[1]); |
| 173 | |
Arnd Bergmann | a8eee86 | 2021-08-03 10:12:34 +0200 | [diff] [blame] | 174 | req_bitmap = __raw_readl(&qmgr_regs->irqen[1]) & |
| 175 | __raw_readl(&qmgr_regs->statne_h); |
Krzysztof Hałasa | 0771c69 | 2009-04-28 19:32:55 +0200 | [diff] [blame] | 176 | while (req_bitmap) { |
| 177 | i = __fls(req_bitmap); /* number of the last "high" queue */ |
| 178 | req_bitmap &= ~BIT(i); |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 179 | irq_handlers[HALF_QUEUES + i](irq_pdevs[HALF_QUEUES + i]); |
| 180 | ret = IRQ_HANDLED; |
| 181 | } |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 186 | static irqreturn_t qmgr_irq(int irq, void *pdev) |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 187 | { |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 188 | int i, half = (irq == qmgr_irq_1 ? 0 : 1); |
Krzysztof Hałasa | 0771c69 | 2009-04-28 19:32:55 +0200 | [diff] [blame] | 189 | u32 req_bitmap = __raw_readl(&qmgr_regs->irqstat[half]); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 190 | |
Krzysztof Hałasa | 0771c69 | 2009-04-28 19:32:55 +0200 | [diff] [blame] | 191 | if (!req_bitmap) |
| 192 | return 0; |
| 193 | __raw_writel(req_bitmap, &qmgr_regs->irqstat[half]); /* ACK */ |
| 194 | |
| 195 | while (req_bitmap) { |
| 196 | i = __fls(req_bitmap); /* number of the last queue */ |
| 197 | req_bitmap &= ~BIT(i); |
| 198 | i += half * HALF_QUEUES; |
| 199 | irq_handlers[i](irq_pdevs[i]); |
| 200 | } |
| 201 | return IRQ_HANDLED; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | void qmgr_enable_irq(unsigned int queue) |
| 206 | { |
| 207 | unsigned long flags; |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 208 | int half = queue / 32; |
| 209 | u32 mask = 1 << (queue & (HALF_QUEUES - 1)); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 210 | |
| 211 | spin_lock_irqsave(&qmgr_lock, flags); |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 212 | __raw_writel(__raw_readl(&qmgr_regs->irqen[half]) | mask, |
| 213 | &qmgr_regs->irqen[half]); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 214 | spin_unlock_irqrestore(&qmgr_lock, flags); |
| 215 | } |
| 216 | |
| 217 | void qmgr_disable_irq(unsigned int queue) |
| 218 | { |
| 219 | unsigned long flags; |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 220 | int half = queue / 32; |
| 221 | u32 mask = 1 << (queue & (HALF_QUEUES - 1)); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 222 | |
| 223 | spin_lock_irqsave(&qmgr_lock, flags); |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 224 | __raw_writel(__raw_readl(&qmgr_regs->irqen[half]) & ~mask, |
| 225 | &qmgr_regs->irqen[half]); |
| 226 | __raw_writel(mask, &qmgr_regs->irqstat[half]); /* clear */ |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 227 | spin_unlock_irqrestore(&qmgr_lock, flags); |
| 228 | } |
| 229 | |
| 230 | static inline void shift_mask(u32 *mask) |
| 231 | { |
| 232 | mask[3] = mask[3] << 1 | mask[2] >> 31; |
| 233 | mask[2] = mask[2] << 1 | mask[1] >> 31; |
| 234 | mask[1] = mask[1] << 1 | mask[0] >> 31; |
| 235 | mask[0] <<= 1; |
| 236 | } |
| 237 | |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 238 | #if DEBUG_QMGR |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 239 | int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */, |
| 240 | unsigned int nearly_empty_watermark, |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 241 | unsigned int nearly_full_watermark, |
| 242 | const char *desc_format, const char* name) |
| 243 | #else |
| 244 | int __qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */, |
| 245 | unsigned int nearly_empty_watermark, |
| 246 | unsigned int nearly_full_watermark) |
| 247 | #endif |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 248 | { |
| 249 | u32 cfg, addr = 0, mask[4]; /* in 16-dwords */ |
| 250 | int err; |
| 251 | |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 252 | BUG_ON(queue >= QUEUES); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 253 | |
| 254 | if ((nearly_empty_watermark | nearly_full_watermark) & ~7) |
| 255 | return -EINVAL; |
| 256 | |
| 257 | switch (len) { |
| 258 | case 16: |
| 259 | cfg = 0 << 24; |
| 260 | mask[0] = 0x1; |
| 261 | break; |
| 262 | case 32: |
| 263 | cfg = 1 << 24; |
| 264 | mask[0] = 0x3; |
| 265 | break; |
| 266 | case 64: |
| 267 | cfg = 2 << 24; |
| 268 | mask[0] = 0xF; |
| 269 | break; |
| 270 | case 128: |
| 271 | cfg = 3 << 24; |
| 272 | mask[0] = 0xFF; |
| 273 | break; |
| 274 | default: |
| 275 | return -EINVAL; |
| 276 | } |
| 277 | |
| 278 | cfg |= nearly_empty_watermark << 26; |
| 279 | cfg |= nearly_full_watermark << 29; |
| 280 | len /= 16; /* in 16-dwords: 1, 2, 4 or 8 */ |
| 281 | mask[1] = mask[2] = mask[3] = 0; |
| 282 | |
| 283 | if (!try_module_get(THIS_MODULE)) |
| 284 | return -ENODEV; |
| 285 | |
| 286 | spin_lock_irq(&qmgr_lock); |
| 287 | if (__raw_readl(&qmgr_regs->sram[queue])) { |
| 288 | err = -EBUSY; |
| 289 | goto err; |
| 290 | } |
| 291 | |
| 292 | while (1) { |
| 293 | if (!(used_sram_bitmap[0] & mask[0]) && |
| 294 | !(used_sram_bitmap[1] & mask[1]) && |
| 295 | !(used_sram_bitmap[2] & mask[2]) && |
| 296 | !(used_sram_bitmap[3] & mask[3])) |
| 297 | break; /* found free space */ |
| 298 | |
| 299 | addr++; |
| 300 | shift_mask(mask); |
| 301 | if (addr + len > ARRAY_SIZE(qmgr_regs->sram)) { |
| 302 | printk(KERN_ERR "qmgr: no free SRAM space for" |
| 303 | " queue %i\n", queue); |
| 304 | err = -ENOMEM; |
| 305 | goto err; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | used_sram_bitmap[0] |= mask[0]; |
| 310 | used_sram_bitmap[1] |= mask[1]; |
| 311 | used_sram_bitmap[2] |= mask[2]; |
| 312 | used_sram_bitmap[3] |= mask[3]; |
| 313 | __raw_writel(cfg | (addr << 14), &qmgr_regs->sram[queue]); |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 314 | #if DEBUG_QMGR |
| 315 | snprintf(qmgr_queue_descs[queue], sizeof(qmgr_queue_descs[0]), |
| 316 | desc_format, name); |
| 317 | printk(KERN_DEBUG "qmgr: requested queue %s(%i) addr = 0x%02X\n", |
| 318 | qmgr_queue_descs[queue], queue, addr); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 319 | #endif |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 320 | spin_unlock_irq(&qmgr_lock); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 321 | return 0; |
| 322 | |
| 323 | err: |
| 324 | spin_unlock_irq(&qmgr_lock); |
| 325 | module_put(THIS_MODULE); |
| 326 | return err; |
| 327 | } |
| 328 | |
| 329 | void qmgr_release_queue(unsigned int queue) |
| 330 | { |
| 331 | u32 cfg, addr, mask[4]; |
| 332 | |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 333 | BUG_ON(queue >= QUEUES); /* not in valid range */ |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 334 | |
| 335 | spin_lock_irq(&qmgr_lock); |
| 336 | cfg = __raw_readl(&qmgr_regs->sram[queue]); |
| 337 | addr = (cfg >> 14) & 0xFF; |
| 338 | |
| 339 | BUG_ON(!addr); /* not requested */ |
| 340 | |
| 341 | switch ((cfg >> 24) & 3) { |
| 342 | case 0: mask[0] = 0x1; break; |
| 343 | case 1: mask[0] = 0x3; break; |
| 344 | case 2: mask[0] = 0xF; break; |
| 345 | case 3: mask[0] = 0xFF; break; |
| 346 | } |
| 347 | |
Krzysztof Halasa | dac2f83 | 2008-04-20 19:06:39 +0200 | [diff] [blame] | 348 | mask[1] = mask[2] = mask[3] = 0; |
| 349 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 350 | while (addr--) |
| 351 | shift_mask(mask); |
| 352 | |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 353 | #if DEBUG_QMGR |
| 354 | printk(KERN_DEBUG "qmgr: releasing queue %s(%i)\n", |
| 355 | qmgr_queue_descs[queue], queue); |
| 356 | qmgr_queue_descs[queue][0] = '\x0'; |
| 357 | #endif |
Krzysztof Hałasa | 3c3a3b4 | 2010-05-03 23:22:06 +0200 | [diff] [blame] | 358 | |
| 359 | while ((addr = qmgr_get_entry(queue))) |
| 360 | printk(KERN_ERR "qmgr: released queue %i not empty: 0x%08X\n", |
| 361 | queue, addr); |
| 362 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 363 | __raw_writel(0, &qmgr_regs->sram[queue]); |
| 364 | |
| 365 | used_sram_bitmap[0] &= ~mask[0]; |
| 366 | used_sram_bitmap[1] &= ~mask[1]; |
| 367 | used_sram_bitmap[2] &= ~mask[2]; |
| 368 | used_sram_bitmap[3] &= ~mask[3]; |
| 369 | irq_handlers[queue] = NULL; /* catch IRQ bugs */ |
| 370 | spin_unlock_irq(&qmgr_lock); |
| 371 | |
| 372 | module_put(THIS_MODULE); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 373 | } |
| 374 | |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 375 | static int ixp4xx_qmgr_probe(struct platform_device *pdev) |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 376 | { |
| 377 | int i, err; |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 378 | irq_handler_t handler1, handler2; |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 379 | struct device *dev = &pdev->dev; |
| 380 | struct resource *res; |
| 381 | int irq1, irq2; |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 382 | |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 383 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 384 | if (!res) |
| 385 | return -ENODEV; |
| 386 | qmgr_regs = devm_ioremap_resource(dev, res); |
Dan Carpenter | c180d71 | 2019-05-06 08:31:08 +0200 | [diff] [blame] | 387 | if (IS_ERR(qmgr_regs)) |
| 388 | return PTR_ERR(qmgr_regs); |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 389 | |
| 390 | irq1 = platform_get_irq(pdev, 0); |
| 391 | if (irq1 <= 0) |
| 392 | return irq1 ? irq1 : -EINVAL; |
| 393 | qmgr_irq_1 = irq1; |
| 394 | irq2 = platform_get_irq(pdev, 1); |
| 395 | if (irq2 <= 0) |
| 396 | return irq2 ? irq2 : -EINVAL; |
| 397 | qmgr_irq_2 = irq2; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 398 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 399 | /* reset qmgr registers */ |
| 400 | for (i = 0; i < 4; i++) { |
| 401 | __raw_writel(0x33333333, &qmgr_regs->stat1[i]); |
| 402 | __raw_writel(0, &qmgr_regs->irqsrc[i]); |
| 403 | } |
| 404 | for (i = 0; i < 2; i++) { |
| 405 | __raw_writel(0, &qmgr_regs->stat2[i]); |
| 406 | __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[i]); /* clear */ |
| 407 | __raw_writel(0, &qmgr_regs->irqen[i]); |
| 408 | } |
| 409 | |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 410 | __raw_writel(0xFFFFFFFF, &qmgr_regs->statne_h); |
| 411 | __raw_writel(0, &qmgr_regs->statf_h); |
| 412 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 413 | for (i = 0; i < QUEUES; i++) |
| 414 | __raw_writel(0, &qmgr_regs->sram[i]); |
| 415 | |
Krzysztof Hałasa | d4c9e9f | 2009-05-23 23:36:03 +0200 | [diff] [blame] | 416 | if (cpu_is_ixp42x_rev_a0()) { |
| 417 | handler1 = qmgr_irq1_a0; |
| 418 | handler2 = qmgr_irq2_a0; |
| 419 | } else |
| 420 | handler1 = handler2 = qmgr_irq; |
| 421 | |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 422 | err = devm_request_irq(dev, irq1, handler1, 0, "IXP4xx Queue Manager", |
| 423 | NULL); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 424 | if (err) { |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 425 | dev_err(dev, "failed to request IRQ%i (%i)\n", |
| 426 | irq1, err); |
| 427 | return err; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 430 | err = devm_request_irq(dev, irq2, handler2, 0, "IXP4xx Queue Manager", |
| 431 | NULL); |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 432 | if (err) { |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 433 | dev_err(dev, "failed to request IRQ%i (%i)\n", |
| 434 | irq2, err); |
| 435 | return err; |
Krzysztof Hałasa | a6a9fb8 | 2009-02-20 01:01:33 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 438 | used_sram_bitmap[0] = 0xF; /* 4 first pages reserved for config */ |
| 439 | spin_lock_init(&qmgr_lock); |
| 440 | |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 441 | dev_info(dev, "IXP4xx Queue Manager initialized.\n"); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 442 | return 0; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 445 | static int ixp4xx_qmgr_remove(struct platform_device *pdev) |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 446 | { |
Linus Walleij | ecc133c | 2019-02-10 20:20:10 +0100 | [diff] [blame] | 447 | synchronize_irq(qmgr_irq_1); |
| 448 | synchronize_irq(qmgr_irq_2); |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 449 | return 0; |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Linus Walleij | 9e01a00 | 2019-02-10 23:41:49 +0100 | [diff] [blame] | 452 | static const struct of_device_id ixp4xx_qmgr_of_match[] = { |
| 453 | { |
| 454 | .compatible = "intel,ixp4xx-ahb-queue-manager", |
| 455 | }, |
| 456 | {}, |
| 457 | }; |
| 458 | |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 459 | static struct platform_driver ixp4xx_qmgr_driver = { |
| 460 | .driver = { |
| 461 | .name = "ixp4xx-qmgr", |
Linus Walleij | 9e01a00 | 2019-02-10 23:41:49 +0100 | [diff] [blame] | 462 | .of_match_table = of_match_ptr(ixp4xx_qmgr_of_match), |
Linus Walleij | 81bca32 | 2019-02-10 17:14:10 +0100 | [diff] [blame] | 463 | }, |
| 464 | .probe = ixp4xx_qmgr_probe, |
| 465 | .remove = ixp4xx_qmgr_remove, |
| 466 | }; |
| 467 | module_platform_driver(ixp4xx_qmgr_driver); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 468 | |
| 469 | MODULE_LICENSE("GPL v2"); |
| 470 | MODULE_AUTHOR("Krzysztof Halasa"); |
| 471 | |
Linus Walleij | d08502f | 2019-02-10 20:15:11 +0100 | [diff] [blame] | 472 | EXPORT_SYMBOL(qmgr_put_entry); |
| 473 | EXPORT_SYMBOL(qmgr_get_entry); |
| 474 | EXPORT_SYMBOL(qmgr_stat_empty); |
| 475 | EXPORT_SYMBOL(qmgr_stat_below_low_watermark); |
| 476 | EXPORT_SYMBOL(qmgr_stat_full); |
| 477 | EXPORT_SYMBOL(qmgr_stat_overflow); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 478 | EXPORT_SYMBOL(qmgr_set_irq); |
| 479 | EXPORT_SYMBOL(qmgr_enable_irq); |
| 480 | EXPORT_SYMBOL(qmgr_disable_irq); |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 481 | #if DEBUG_QMGR |
| 482 | EXPORT_SYMBOL(qmgr_queue_descs); |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 483 | EXPORT_SYMBOL(qmgr_request_queue); |
Krzysztof Hałasa | e6da96a | 2008-12-22 00:26:38 +0100 | [diff] [blame] | 484 | #else |
| 485 | EXPORT_SYMBOL(__qmgr_request_queue); |
| 486 | #endif |
Krzysztof Halasa | 82a96f5 | 2008-01-01 21:55:23 +0100 | [diff] [blame] | 487 | EXPORT_SYMBOL(qmgr_release_queue); |