}
static int manage_channel(struct fw_card *card, int irm_id, int generation,
- __be32 channels_mask, u64 offset, bool allocate)
+ u32 channels_mask, u64 offset, bool allocate)
{
- __be32 data[2], c, old = allocate ? cpu_to_be32(~0) : 0;
+ __be32 data[2], c, all, old;
int i, retry = 5;
+ old = all = allocate ? cpu_to_be32(~0) : 0;
+
for (i = 0; i < 32; i++) {
- c = cpu_to_be32(1 << (31 - i));
- if (!(channels_mask & c))
+ if (!(channels_mask & 1 << i))
continue;
- if (allocate == !(old & c))
+ c = cpu_to_be32(1 << (31 - i));
+ if ((old & c) != (all & c))
continue;
data[0] = old;
old = data[0];
/* Is the IRM 1394a-2000 compliant? */
- if ((data[0] & c) != (data[1] & c))
+ if ((data[0] & c) == (data[1] & c))
continue;
/* 1394-1995 IRM, fall through to retry. */
static void deallocate_channel(struct fw_card *card, int irm_id,
int generation, int channel)
{
- __be32 mask;
+ u32 mask;
u64 offset;
- mask = channel < 32 ? cpu_to_be32(1 << (31 - channel)) :
- cpu_to_be32(1 << (63 - channel));
+ mask = channel < 32 ? 1 << channel : 1 << (channel - 32);
offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI :
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO;
* In parameters: card, generation, channels_mask, bandwidth, allocate
* Out parameters: channel, bandwidth
* This function blocks (sleeps) during communication with the IRM.
+ *
* Allocates or deallocates at most one channel out of channels_mask.
+ * channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0.
+ * (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for
+ * channel 0 and LSB for channel 63.)
+ * Allocates or deallocates as many bandwidth allocation units as specified.
*
* Returns channel < 0 if no channel was allocated or deallocated.
* Returns bandwidth = 0 if no bandwidth was allocated or deallocated.
* If generation is stale, deallocations succeed but allocations fail with
* channel = -EAGAIN.
*
- * If channel (de)allocation fails, bandwidth (de)allocation fails too.
+ * If channel allocation fails, no bandwidth will be allocated either.
* If bandwidth allocation fails, no channel will be allocated either.
- * If bandwidth deallocation fails, channel deallocation may still have been
- * successful.
+ * But deallocations of channel and bandwidth are tried independently
+ * of each other's success.
*/
void fw_iso_resource_manage(struct fw_card *card, int generation,
u64 channels_mask, int *channel, int *bandwidth,
bool allocate)
{
- __be32 channels_hi = cpu_to_be32(channels_mask >> 32);
- __be32 channels_lo = cpu_to_be32(channels_mask);
+ u32 channels_hi = channels_mask; /* channels 31...0 */
+ u32 channels_lo = channels_mask >> 32; /* channels 63...32 */
int irm_id, ret, c = -EINVAL;
spin_lock_irq(&card->lock);
}
*channel = c;
- if (channels_mask != 0 && c < 0)
+ if (allocate && channels_mask != 0 && c < 0)
*bandwidth = 0;
if (*bandwidth == 0)
if (ret < 0)
*bandwidth = 0;
- if (ret < 0 && c >= 0 && allocate) {
+ if (allocate && ret < 0 && c >= 0) {
deallocate_channel(card, irm_id, generation, c);
*channel = ret;
}
* @handle: Reference by which an allocated resource can be deallocated
* @channel: Isochronous channel which was (de)allocated, if any
* @bandwidth: Bandwidth allocation units which were (de)allocated, if any
- * @channels_available: Last known availability of channels
- * @bandwidth_available: Last known availability of bandwidth
*
* An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
* resource was allocated at the IRM. The client has to check @channel and
*
* The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
* %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
- * instead of allocated. At most one channel may be specified in this ioctl.
+ * instead of allocated.
* An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
*
* To summarize, %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE allocates iso resources
* In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
* for the duration of a bus generation.
*
- * @channels is a host-endian bitfield with the most significant bit
- * representing channel 0 and the least significant bit representing channel 63:
- * 1ULL << (63 - c)
+ * @channels is a host-endian bitfield with the least significant bit
+ * representing channel 0 and the most significant bit representing channel 63:
+ * 1ULL << c for each channel c that is a candidate for (de)allocation.
*
* @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
* one quadlet of data (payload or header data) at speed S1600.