blob: 185b0b78b3d68c8d9e8b8135d3841a728602b109 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Kristian Høgsbergc781c062007-05-07 20:33:32 -04002/*
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +01003 * Isochronous I/O functionality:
4 * - Isochronous DMA context management
5 * - Isochronous bus resource management (channels, bandwidth), client side
Kristian Høgsberg3038e352006-12-19 19:58:27 -05006 *
Kristian Høgsberg3038e352006-12-19 19:58:27 -05007 * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
Kristian Høgsberg3038e352006-12-19 19:58:27 -05008 */
9
Kristian Høgsberg3038e352006-12-19 19:58:27 -050010#include <linux/dma-mapping.h>
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +010011#include <linux/errno.h>
Stefan Richter77c9a5d2009-06-05 16:26:18 +020012#include <linux/firewire.h>
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +010013#include <linux/firewire-constants.h>
14#include <linux/kernel.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050015#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +010017#include <linux/spinlock.h>
18#include <linux/vmalloc.h>
Paul Gortmaker823467e2011-07-10 12:16:32 -040019#include <linux/export.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050020
Stefan Richtere8ca9702009-06-04 21:09:38 +020021#include <asm/byteorder.h>
22
Stefan Richter77c9a5d2009-06-05 16:26:18 +020023#include "core.h"
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +010024
25/*
26 * Isochronous DMA context management
27 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -050028
Stefan Richter0b6c4852012-04-09 20:51:18 +020029int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050030{
Stefan Richter0b6c4852012-04-09 20:51:18 +020031 int i;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050032
Stefan Richter0b6c4852012-04-09 20:51:18 +020033 buffer->page_count = 0;
34 buffer->page_count_mapped = 0;
Kees Cook6da2ec52018-06-12 13:55:00 -070035 buffer->pages = kmalloc_array(page_count, sizeof(buffer->pages[0]),
36 GFP_KERNEL);
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050037 if (buffer->pages == NULL)
Stefan Richter0b6c4852012-04-09 20:51:18 +020038 return -ENOMEM;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050039
Stefan Richter0b6c4852012-04-09 20:51:18 +020040 for (i = 0; i < page_count; i++) {
Kristian Høgsberg68be3fa2007-02-16 17:34:48 -050041 buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050042 if (buffer->pages[i] == NULL)
Stefan Richter0b6c4852012-04-09 20:51:18 +020043 break;
44 }
45 buffer->page_count = i;
46 if (i < page_count) {
47 fw_iso_buffer_destroy(buffer, NULL);
48 return -ENOMEM;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050049 }
50
51 return 0;
Stefan Richter0b6c4852012-04-09 20:51:18 +020052}
Kristian Høgsberg82eff9d2007-02-06 14:49:40 -050053
Stefan Richter0b6c4852012-04-09 20:51:18 +020054int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card,
55 enum dma_data_direction direction)
56{
57 dma_addr_t address;
58 int i;
59
60 buffer->direction = direction;
61
62 for (i = 0; i < buffer->page_count; i++) {
63 address = dma_map_page(card->device, buffer->pages[i],
64 0, PAGE_SIZE, direction);
65 if (dma_mapping_error(card->device, address))
66 break;
67
68 set_page_private(buffer->pages[i], address);
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050069 }
Stefan Richter0b6c4852012-04-09 20:51:18 +020070 buffer->page_count_mapped = i;
71 if (i < buffer->page_count)
72 return -ENOMEM;
Stefan Richtere1eff7a2009-02-03 17:55:19 +010073
Stefan Richter0b6c4852012-04-09 20:51:18 +020074 return 0;
75}
76
77int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
78 int page_count, enum dma_data_direction direction)
79{
80 int ret;
81
82 ret = fw_iso_buffer_alloc(buffer, page_count);
83 if (ret < 0)
84 return ret;
85
86 ret = fw_iso_buffer_map_dma(buffer, card, direction);
87 if (ret < 0)
88 fw_iso_buffer_destroy(buffer, card);
89
90 return ret;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050091}
Jay Fenlasonc76acec2009-05-18 13:08:06 -040092EXPORT_SYMBOL(fw_iso_buffer_init);
Kristian Høgsberg3038e352006-12-19 19:58:27 -050093
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050094void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
95 struct fw_card *card)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050096{
97 int i;
Kristian Høgsberg9aad8122007-02-16 17:34:38 -050098 dma_addr_t address;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050099
Stefan Richter0b6c4852012-04-09 20:51:18 +0200100 for (i = 0; i < buffer->page_count_mapped; i++) {
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500101 address = page_private(buffer->pages[i]);
102 dma_unmap_page(card->device, address,
Stefan Richter29ad14c2009-06-15 00:38:50 +0200103 PAGE_SIZE, buffer->direction);
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500104 }
Stefan Richter0b6c4852012-04-09 20:51:18 +0200105 for (i = 0; i < buffer->page_count; i++)
106 __free_page(buffer->pages[i]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500107
Kristian Høgsberg9aad8122007-02-16 17:34:38 -0500108 kfree(buffer->pages);
109 buffer->pages = NULL;
Stefan Richter0b6c4852012-04-09 20:51:18 +0200110 buffer->page_count = 0;
111 buffer->page_count_mapped = 0;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500112}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400113EXPORT_SYMBOL(fw_iso_buffer_destroy);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500114
Stefan Richter872e3302010-07-29 18:19:22 +0200115/* Convert DMA address to offset into virtually contiguous buffer. */
116size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed)
117{
Clemens Ladisch9d23f9e2012-06-13 22:28:24 +0200118 size_t i;
Stefan Richter872e3302010-07-29 18:19:22 +0200119 dma_addr_t address;
120 ssize_t offset;
121
122 for (i = 0; i < buffer->page_count; i++) {
123 address = page_private(buffer->pages[i]);
124 offset = (ssize_t)completed - (ssize_t)address;
125 if (offset > 0 && offset <= PAGE_SIZE)
126 return (i << PAGE_SHIFT) + offset;
127 }
128
129 return 0;
130}
131
Stefan Richter53dca512008-12-14 21:47:04 +0100132struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
133 int type, int channel, int speed, size_t header_size,
134 fw_iso_callback_t callback, void *callback_data)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500135{
136 struct fw_iso_context *ctx;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500137
Stefan Richter4817ed22008-12-21 16:39:46 +0100138 ctx = card->driver->allocate_iso_context(card,
139 type, channel, header_size);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500140 if (IS_ERR(ctx))
141 return ctx;
142
143 ctx->card = card;
144 ctx->type = type;
Kristian Høgsberg21efb3c2007-02-16 17:34:50 -0500145 ctx->channel = channel;
146 ctx->speed = speed;
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500147 ctx->header_size = header_size;
Stefan Richter872e3302010-07-29 18:19:22 +0200148 ctx->callback.sc = callback;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500149 ctx->callback_data = callback_data;
150
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500151 return ctx;
152}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400153EXPORT_SYMBOL(fw_iso_context_create);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500154
155void fw_iso_context_destroy(struct fw_iso_context *ctx)
156{
Stefan Richter872e3302010-07-29 18:19:22 +0200157 ctx->card->driver->free_iso_context(ctx);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500158}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400159EXPORT_SYMBOL(fw_iso_context_destroy);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500160
Stefan Richter53dca512008-12-14 21:47:04 +0100161int fw_iso_context_start(struct fw_iso_context *ctx,
162 int cycle, int sync, int tags)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500163{
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400164 return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500165}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400166EXPORT_SYMBOL(fw_iso_context_start);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500167
Stefan Richter872e3302010-07-29 18:19:22 +0200168int fw_iso_context_set_channels(struct fw_iso_context *ctx, u64 *channels)
169{
170 return ctx->card->driver->set_iso_channels(ctx, channels);
171}
172
Stefan Richter53dca512008-12-14 21:47:04 +0100173int fw_iso_context_queue(struct fw_iso_context *ctx,
174 struct fw_iso_packet *packet,
175 struct fw_iso_buffer *buffer,
176 unsigned long payload)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500177{
Stefan Richter872e3302010-07-29 18:19:22 +0200178 return ctx->card->driver->queue_iso(ctx, packet, buffer, payload);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500179}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400180EXPORT_SYMBOL(fw_iso_context_queue);
Kristian Høgsbergb8295662007-02-16 17:34:42 -0500181
Clemens Ladisch13882a82011-05-02 09:33:56 +0200182void fw_iso_context_queue_flush(struct fw_iso_context *ctx)
183{
184 ctx->card->driver->flush_queue_iso(ctx);
185}
186EXPORT_SYMBOL(fw_iso_context_queue_flush);
187
Clemens Ladischd1bbd202012-03-18 19:06:39 +0100188int fw_iso_context_flush_completions(struct fw_iso_context *ctx)
189{
190 return ctx->card->driver->flush_iso_completions(ctx);
191}
192EXPORT_SYMBOL(fw_iso_context_flush_completions);
193
Stefan Richter53dca512008-12-14 21:47:04 +0100194int fw_iso_context_stop(struct fw_iso_context *ctx)
Kristian Høgsbergb8295662007-02-16 17:34:42 -0500195{
196 return ctx->card->driver->stop_iso(ctx);
197}
Jay Fenlasonc76acec2009-05-18 13:08:06 -0400198EXPORT_SYMBOL(fw_iso_context_stop);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100199
200/*
201 * Isochronous bus resource management (channels, bandwidth), client side
202 */
203
204static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200205 int bandwidth, bool allocate)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100206{
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100207 int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
Stefan Richterf30e6d32011-04-22 15:13:54 +0200208 __be32 data[2];
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100209
210 /*
211 * On a 1394a IRM with low contention, try < 1 is enough.
212 * On a 1394-1995 IRM, we need at least try < 2.
213 * Let's just do try < 5.
214 */
215 for (try = 0; try < 5; try++) {
216 new = allocate ? old - bandwidth : old + bandwidth;
217 if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL)
Clemens Ladischd6372b62010-04-12 10:35:18 +0200218 return -EBUSY;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100219
220 data[0] = cpu_to_be32(old);
221 data[1] = cpu_to_be32(new);
222 switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
223 irm_id, generation, SCODE_100,
224 CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
Stefan Richter1821bc12009-09-05 13:23:49 +0200225 data, 8)) {
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100226 case RCODE_GENERATION:
227 /* A generation change frees all bandwidth. */
228 return allocate ? -EAGAIN : bandwidth;
229
230 case RCODE_COMPLETE:
231 if (be32_to_cpup(data) == old)
232 return bandwidth;
233
234 old = be32_to_cpup(data);
235 /* Fall through. */
236 }
237 }
238
239 return -EIO;
240}
241
242static int manage_channel(struct fw_card *card, int irm_id, int generation,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200243 u32 channels_mask, u64 offset, bool allocate)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100244{
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100245 __be32 bit, all, old;
Stefan Richterf30e6d32011-04-22 15:13:54 +0200246 __be32 data[2];
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100247 int channel, ret = -EIO, retry = 5;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100248
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100249 old = all = allocate ? cpu_to_be32(~0) : 0;
250
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100251 for (channel = 0; channel < 32; channel++) {
252 if (!(channels_mask & 1 << channel))
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100253 continue;
254
Clemens Ladischd6372b62010-04-12 10:35:18 +0200255 ret = -EBUSY;
256
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100257 bit = cpu_to_be32(1 << (31 - channel));
258 if ((old & bit) != (all & bit))
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100259 continue;
260
261 data[0] = old;
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100262 data[1] = old ^ bit;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100263 switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
264 irm_id, generation, SCODE_100,
Stefan Richter1821bc12009-09-05 13:23:49 +0200265 offset, data, 8)) {
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100266 case RCODE_GENERATION:
267 /* A generation change frees all channels. */
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100268 return allocate ? -EAGAIN : channel;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100269
270 case RCODE_COMPLETE:
271 if (data[0] == old)
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100272 return channel;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100273
274 old = data[0];
275
276 /* Is the IRM 1394a-2000 compliant? */
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100277 if ((data[0] & bit) == (data[1] & bit))
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100278 continue;
279
Gustavo A. R. Silvaeba61202019-02-11 11:48:21 -0600280 /* fall through - It's a 1394-1995 IRM, retry. */
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100281 default:
Clemens Ladisch3a1f0a02010-04-12 10:35:05 +0200282 if (retry) {
283 retry--;
Clemens Ladisch5aaffc62011-01-31 11:58:58 +0100284 channel--;
Clemens Ladischd6372b62010-04-12 10:35:18 +0200285 } else {
286 ret = -EIO;
Clemens Ladisch3a1f0a02010-04-12 10:35:05 +0200287 }
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100288 }
289 }
290
Clemens Ladischd6372b62010-04-12 10:35:18 +0200291 return ret;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100292}
293
294static void deallocate_channel(struct fw_card *card, int irm_id,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200295 int generation, int channel)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100296{
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100297 u32 mask;
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100298 u64 offset;
299
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100300 mask = channel < 32 ? 1 << channel : 1 << (channel - 32);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100301 offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI :
302 CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO;
303
Stefan Richterf30e6d32011-04-22 15:13:54 +0200304 manage_channel(card, irm_id, generation, mask, offset, false);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100305}
306
307/**
Stefan Richter656b7af2010-07-07 13:26:18 +0200308 * fw_iso_resource_manage() - Allocate or deallocate a channel and/or bandwidth
Randy Dunlap48f02b82018-09-04 17:02:22 -0700309 * @card: card interface for this action
310 * @generation: bus generation
311 * @channels_mask: bitmask for channel allocation
312 * @channel: pointer for returning channel allocation result
313 * @bandwidth: pointer for returning bandwidth allocation result
314 * @allocate: whether to allocate (true) or deallocate (false)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100315 *
316 * In parameters: card, generation, channels_mask, bandwidth, allocate
317 * Out parameters: channel, bandwidth
Randy Dunlap48f02b82018-09-04 17:02:22 -0700318 *
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100319 * This function blocks (sleeps) during communication with the IRM.
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100320 *
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100321 * Allocates or deallocates at most one channel out of channels_mask.
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100322 * channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0.
323 * (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for
324 * channel 0 and LSB for channel 63.)
325 * Allocates or deallocates as many bandwidth allocation units as specified.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100326 *
327 * Returns channel < 0 if no channel was allocated or deallocated.
328 * Returns bandwidth = 0 if no bandwidth was allocated or deallocated.
329 *
330 * If generation is stale, deallocations succeed but allocations fail with
331 * channel = -EAGAIN.
332 *
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100333 * If channel allocation fails, no bandwidth will be allocated either.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100334 * If bandwidth allocation fails, no channel will be allocated either.
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100335 * But deallocations of channel and bandwidth are tried independently
336 * of each other's success.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100337 */
338void fw_iso_resource_manage(struct fw_card *card, int generation,
339 u64 channels_mask, int *channel, int *bandwidth,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200340 bool allocate)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100341{
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100342 u32 channels_hi = channels_mask; /* channels 31...0 */
343 u32 channels_lo = channels_mask >> 32; /* channels 63...32 */
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100344 int irm_id, ret, c = -EINVAL;
345
346 spin_lock_irq(&card->lock);
347 irm_id = card->irm_node->node_id;
348 spin_unlock_irq(&card->lock);
349
350 if (channels_hi)
351 c = manage_channel(card, irm_id, generation, channels_hi,
Stefan Richter6fdc0372009-06-20 13:23:59 +0200352 CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200353 allocate);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100354 if (channels_lo && c < 0) {
355 c = manage_channel(card, irm_id, generation, channels_lo,
Stefan Richter6fdc0372009-06-20 13:23:59 +0200356 CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO,
Stefan Richterf30e6d32011-04-22 15:13:54 +0200357 allocate);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100358 if (c >= 0)
359 c += 32;
360 }
361 *channel = c;
362
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100363 if (allocate && channels_mask != 0 && c < 0)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100364 *bandwidth = 0;
365
366 if (*bandwidth == 0)
367 return;
368
Stefan Richterf30e6d32011-04-22 15:13:54 +0200369 ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100370 if (ret < 0)
371 *bandwidth = 0;
372
Clemens Ladischcf36df62010-03-15 13:20:32 +0100373 if (allocate && ret < 0) {
374 if (c >= 0)
Stefan Richterf30e6d32011-04-22 15:13:54 +0200375 deallocate_channel(card, irm_id, generation, c);
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100376 *channel = ret;
377 }
378}
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100379EXPORT_SYMBOL(fw_iso_resource_manage);