Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1 | /* |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 2 | * Isochronous I/O functionality: |
| 3 | * - Isochronous DMA context management |
| 4 | * - Isochronous bus resource management (channels, bandwidth), client side |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 5 | * |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 6 | * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software Foundation, |
| 20 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 23 | #include <linux/dma-mapping.h> |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/firewire-constants.h> |
| 26 | #include <linux/kernel.h> |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 27 | #include <linux/mm.h> |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/vmalloc.h> |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 30 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 31 | #include "fw-topology.h" |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 32 | #include "fw-transaction.h" |
| 33 | |
| 34 | /* |
| 35 | * Isochronous DMA context management |
| 36 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 37 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 38 | int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, |
| 39 | int page_count, enum dma_data_direction direction) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 40 | { |
Stefan Richter | 2dbd7d7 | 2008-12-14 21:45:45 +0100 | [diff] [blame] | 41 | int i, j; |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 42 | dma_addr_t address; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 43 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 44 | buffer->page_count = page_count; |
| 45 | buffer->direction = direction; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 46 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 47 | buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]), |
| 48 | GFP_KERNEL); |
| 49 | if (buffer->pages == NULL) |
| 50 | goto out; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 51 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 52 | for (i = 0; i < buffer->page_count; i++) { |
Kristian Høgsberg | 68be3fa | 2007-02-16 17:34:48 -0500 | [diff] [blame] | 53 | buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO); |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 54 | if (buffer->pages[i] == NULL) |
| 55 | goto out_pages; |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 56 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 57 | address = dma_map_page(card->device, buffer->pages[i], |
| 58 | 0, PAGE_SIZE, direction); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 59 | if (dma_mapping_error(card->device, address)) { |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 60 | __free_page(buffer->pages[i]); |
| 61 | goto out_pages; |
| 62 | } |
| 63 | set_page_private(buffer->pages[i], address); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return 0; |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 67 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 68 | out_pages: |
| 69 | for (j = 0; j < i; j++) { |
| 70 | address = page_private(buffer->pages[j]); |
| 71 | dma_unmap_page(card->device, address, |
Kristian Høgsberg | 82eff9d | 2007-02-06 14:49:40 -0500 | [diff] [blame] | 72 | PAGE_SIZE, DMA_TO_DEVICE); |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 73 | __free_page(buffer->pages[j]); |
| 74 | } |
| 75 | kfree(buffer->pages); |
| 76 | out: |
| 77 | buffer->pages = NULL; |
Stefan Richter | e1eff7a | 2009-02-03 17:55:19 +0100 | [diff] [blame] | 78 | |
Stefan Richter | 2dbd7d7 | 2008-12-14 21:45:45 +0100 | [diff] [blame] | 79 | return -ENOMEM; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 80 | } |
| 81 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 82 | int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma) |
| 83 | { |
| 84 | unsigned long uaddr; |
Stefan Richter | e1eff7a | 2009-02-03 17:55:19 +0100 | [diff] [blame] | 85 | int i, err; |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 86 | |
| 87 | uaddr = vma->vm_start; |
| 88 | for (i = 0; i < buffer->page_count; i++) { |
Stefan Richter | e1eff7a | 2009-02-03 17:55:19 +0100 | [diff] [blame] | 89 | err = vm_insert_page(vma, uaddr, buffer->pages[i]); |
| 90 | if (err) |
| 91 | return err; |
| 92 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 93 | uaddr += PAGE_SIZE; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, |
| 100 | struct fw_card *card) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 101 | { |
| 102 | int i; |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 103 | dma_addr_t address; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 104 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 105 | for (i = 0; i < buffer->page_count; i++) { |
| 106 | address = page_private(buffer->pages[i]); |
| 107 | dma_unmap_page(card->device, address, |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 108 | PAGE_SIZE, DMA_TO_DEVICE); |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 109 | __free_page(buffer->pages[i]); |
| 110 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 111 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 112 | kfree(buffer->pages); |
| 113 | buffer->pages = NULL; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 116 | struct fw_iso_context *fw_iso_context_create(struct fw_card *card, |
| 117 | int type, int channel, int speed, size_t header_size, |
| 118 | fw_iso_callback_t callback, void *callback_data) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 119 | { |
| 120 | struct fw_iso_context *ctx; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 121 | |
Stefan Richter | 4817ed2 | 2008-12-21 16:39:46 +0100 | [diff] [blame] | 122 | ctx = card->driver->allocate_iso_context(card, |
| 123 | type, channel, header_size); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 124 | if (IS_ERR(ctx)) |
| 125 | return ctx; |
| 126 | |
| 127 | ctx->card = card; |
| 128 | ctx->type = type; |
Kristian Høgsberg | 21efb3c | 2007-02-16 17:34:50 -0500 | [diff] [blame] | 129 | ctx->channel = channel; |
| 130 | ctx->speed = speed; |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 131 | ctx->header_size = header_size; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 132 | ctx->callback = callback; |
| 133 | ctx->callback_data = callback_data; |
| 134 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 135 | return ctx; |
| 136 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 137 | |
| 138 | void fw_iso_context_destroy(struct fw_iso_context *ctx) |
| 139 | { |
| 140 | struct fw_card *card = ctx->card; |
| 141 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 142 | card->driver->free_iso_context(ctx); |
| 143 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 144 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 145 | int fw_iso_context_start(struct fw_iso_context *ctx, |
| 146 | int cycle, int sync, int tags) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 147 | { |
Kristian Høgsberg | eb0306e | 2007-03-14 17:34:54 -0400 | [diff] [blame] | 148 | return ctx->card->driver->start_iso(ctx, cycle, sync, tags); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 149 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 150 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 151 | int fw_iso_context_queue(struct fw_iso_context *ctx, |
| 152 | struct fw_iso_packet *packet, |
| 153 | struct fw_iso_buffer *buffer, |
| 154 | unsigned long payload) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 155 | { |
| 156 | struct fw_card *card = ctx->card; |
| 157 | |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 158 | return card->driver->queue_iso(ctx, packet, buffer, payload); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 159 | } |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 160 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 161 | int fw_iso_context_stop(struct fw_iso_context *ctx) |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 162 | { |
| 163 | return ctx->card->driver->stop_iso(ctx); |
| 164 | } |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * Isochronous bus resource management (channels, bandwidth), client side |
| 168 | */ |
| 169 | |
| 170 | static int manage_bandwidth(struct fw_card *card, int irm_id, int generation, |
| 171 | int bandwidth, bool allocate) |
| 172 | { |
| 173 | __be32 data[2]; |
| 174 | int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0; |
| 175 | |
| 176 | /* |
| 177 | * On a 1394a IRM with low contention, try < 1 is enough. |
| 178 | * On a 1394-1995 IRM, we need at least try < 2. |
| 179 | * Let's just do try < 5. |
| 180 | */ |
| 181 | for (try = 0; try < 5; try++) { |
| 182 | new = allocate ? old - bandwidth : old + bandwidth; |
| 183 | if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL) |
| 184 | break; |
| 185 | |
| 186 | data[0] = cpu_to_be32(old); |
| 187 | data[1] = cpu_to_be32(new); |
| 188 | switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, |
| 189 | irm_id, generation, SCODE_100, |
| 190 | CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE, |
| 191 | data, sizeof(data))) { |
| 192 | case RCODE_GENERATION: |
| 193 | /* A generation change frees all bandwidth. */ |
| 194 | return allocate ? -EAGAIN : bandwidth; |
| 195 | |
| 196 | case RCODE_COMPLETE: |
| 197 | if (be32_to_cpup(data) == old) |
| 198 | return bandwidth; |
| 199 | |
| 200 | old = be32_to_cpup(data); |
| 201 | /* Fall through. */ |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return -EIO; |
| 206 | } |
| 207 | |
| 208 | static int manage_channel(struct fw_card *card, int irm_id, int generation, |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 209 | u32 channels_mask, u64 offset, bool allocate) |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 210 | { |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 211 | __be32 data[2], c, all, old; |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 212 | int i, retry = 5; |
| 213 | |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 214 | old = all = allocate ? cpu_to_be32(~0) : 0; |
| 215 | |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 216 | for (i = 0; i < 32; i++) { |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 217 | if (!(channels_mask & 1 << i)) |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 218 | continue; |
| 219 | |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 220 | c = cpu_to_be32(1 << (31 - i)); |
| 221 | if ((old & c) != (all & c)) |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 222 | continue; |
| 223 | |
| 224 | data[0] = old; |
| 225 | data[1] = old ^ c; |
| 226 | switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, |
| 227 | irm_id, generation, SCODE_100, |
| 228 | offset, data, sizeof(data))) { |
| 229 | case RCODE_GENERATION: |
| 230 | /* A generation change frees all channels. */ |
| 231 | return allocate ? -EAGAIN : i; |
| 232 | |
| 233 | case RCODE_COMPLETE: |
| 234 | if (data[0] == old) |
| 235 | return i; |
| 236 | |
| 237 | old = data[0]; |
| 238 | |
| 239 | /* Is the IRM 1394a-2000 compliant? */ |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 240 | if ((data[0] & c) == (data[1] & c)) |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 241 | continue; |
| 242 | |
| 243 | /* 1394-1995 IRM, fall through to retry. */ |
| 244 | default: |
| 245 | if (retry--) |
| 246 | i--; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return -EIO; |
| 251 | } |
| 252 | |
| 253 | static void deallocate_channel(struct fw_card *card, int irm_id, |
| 254 | int generation, int channel) |
| 255 | { |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 256 | u32 mask; |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 257 | u64 offset; |
| 258 | |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 259 | mask = channel < 32 ? 1 << channel : 1 << (channel - 32); |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 260 | offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI : |
| 261 | CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO; |
| 262 | |
| 263 | manage_channel(card, irm_id, generation, mask, offset, false); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth |
| 268 | * |
| 269 | * In parameters: card, generation, channels_mask, bandwidth, allocate |
| 270 | * Out parameters: channel, bandwidth |
| 271 | * This function blocks (sleeps) during communication with the IRM. |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 272 | * |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 273 | * Allocates or deallocates at most one channel out of channels_mask. |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 274 | * channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0. |
| 275 | * (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for |
| 276 | * channel 0 and LSB for channel 63.) |
| 277 | * Allocates or deallocates as many bandwidth allocation units as specified. |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 278 | * |
| 279 | * Returns channel < 0 if no channel was allocated or deallocated. |
| 280 | * Returns bandwidth = 0 if no bandwidth was allocated or deallocated. |
| 281 | * |
| 282 | * If generation is stale, deallocations succeed but allocations fail with |
| 283 | * channel = -EAGAIN. |
| 284 | * |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 285 | * If channel allocation fails, no bandwidth will be allocated either. |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 286 | * If bandwidth allocation fails, no channel will be allocated either. |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 287 | * But deallocations of channel and bandwidth are tried independently |
| 288 | * of each other's success. |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 289 | */ |
| 290 | void fw_iso_resource_manage(struct fw_card *card, int generation, |
| 291 | u64 channels_mask, int *channel, int *bandwidth, |
| 292 | bool allocate) |
| 293 | { |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 294 | u32 channels_hi = channels_mask; /* channels 31...0 */ |
| 295 | u32 channels_lo = channels_mask >> 32; /* channels 63...32 */ |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 296 | int irm_id, ret, c = -EINVAL; |
| 297 | |
| 298 | spin_lock_irq(&card->lock); |
| 299 | irm_id = card->irm_node->node_id; |
| 300 | spin_unlock_irq(&card->lock); |
| 301 | |
| 302 | if (channels_hi) |
| 303 | c = manage_channel(card, irm_id, generation, channels_hi, |
| 304 | CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI, allocate); |
| 305 | if (channels_lo && c < 0) { |
| 306 | c = manage_channel(card, irm_id, generation, channels_lo, |
| 307 | CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO, allocate); |
| 308 | if (c >= 0) |
| 309 | c += 32; |
| 310 | } |
| 311 | *channel = c; |
| 312 | |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 313 | if (allocate && channels_mask != 0 && c < 0) |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 314 | *bandwidth = 0; |
| 315 | |
| 316 | if (*bandwidth == 0) |
| 317 | return; |
| 318 | |
| 319 | ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate); |
| 320 | if (ret < 0) |
| 321 | *bandwidth = 0; |
| 322 | |
Stefan Richter | 5d9cb7d | 2009-01-08 23:07:40 +0100 | [diff] [blame] | 323 | if (allocate && ret < 0 && c >= 0) { |
Jay Fenlason, Stefan Richter | b1bda4c | 2009-01-04 16:23:29 +0100 | [diff] [blame] | 324 | deallocate_channel(card, irm_id, generation, c); |
| 325 | *channel = ret; |
| 326 | } |
| 327 | } |