summaryrefslogtreecommitdiffstats
path: root/sound/firewire/cmp.c
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2019-06-15 11:11:01 +0200
committerTakashi Iwai <tiwai@suse.de>2019-06-17 08:18:36 +0200
commit7bc93821a70adc621df443c8b7a4745023c36e7c (patch)
tree0474e9b97389716fb9e1320d6ceeba6b61be03d2 /sound/firewire/cmp.c
parentALSA: fireworks: change the range of critical section for stream data in PCM.... (diff)
downloadlinux-7bc93821a70adc621df443c8b7a4745023c36e7c.tar.xz
linux-7bc93821a70adc621df443c8b7a4745023c36e7c.zip
ALSA: firewire-lib: split allocation of isochronous resources from establishment of connection
In current implementation, establishment connection corresponds to allocation of isochronous resources. Although this is an ideal implementation of CMP described in IEC 61883-1, it's not enough efficient to recover PCM substream multiplexed in packet streaming. The packet streaming can always restart on the same allocated isochronous resources even if the previous packet streaming corrupted. This commit splits allocation of isochronous resources from establishment of connection so that CMP runs with allocated isochronous resources. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/firewire/cmp.c')
-rw-r--r--sound/firewire/cmp.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/sound/firewire/cmp.c b/sound/firewire/cmp.c
index ae3bc1940efa..5dedc4f31842 100644
--- a/sound/firewire/cmp.c
+++ b/sound/firewire/cmp.c
@@ -185,6 +185,37 @@ void cmp_connection_destroy(struct cmp_connection *c)
}
EXPORT_SYMBOL(cmp_connection_destroy);
+int cmp_connection_reserve(struct cmp_connection *c,
+ unsigned int max_payload_bytes)
+{
+ int err;
+
+ mutex_lock(&c->mutex);
+
+ if (WARN_ON(c->resources.allocated)) {
+ err = -EBUSY;
+ goto end;
+ }
+
+ c->speed = min(c->max_speed,
+ fw_parent_device(c->resources.unit)->max_speed);
+
+ err = fw_iso_resources_allocate(&c->resources, max_payload_bytes,
+ c->speed);
+end:
+ mutex_unlock(&c->mutex);
+
+ return err;
+}
+EXPORT_SYMBOL(cmp_connection_reserve);
+
+void cmp_connection_release(struct cmp_connection *c)
+{
+ mutex_lock(&c->mutex);
+ fw_iso_resources_free(&c->resources);
+ mutex_unlock(&c->mutex);
+}
+EXPORT_SYMBOL(cmp_connection_release);
static __be32 ipcr_set_modify(struct cmp_connection *c, __be32 ipcr)
{
@@ -270,25 +301,18 @@ static int pcr_set_check(struct cmp_connection *c, __be32 pcr)
* When this function succeeds, the caller is responsible for starting
* transmitting packets.
*/
-int cmp_connection_establish(struct cmp_connection *c,
- unsigned int max_payload_bytes)
+int cmp_connection_establish(struct cmp_connection *c)
{
int err;
- if (WARN_ON(c->connected))
- return -EISCONN;
-
- c->speed = min(c->max_speed,
- fw_parent_device(c->resources.unit)->max_speed);
-
mutex_lock(&c->mutex);
-retry_after_bus_reset:
- err = fw_iso_resources_allocate(&c->resources,
- max_payload_bytes, c->speed);
- if (err < 0)
- goto err_mutex;
+ if (WARN_ON(c->connected)) {
+ mutex_unlock(&c->mutex);
+ return -EISCONN;
+ }
+retry_after_bus_reset:
if (c->direction == CMP_OUTPUT)
err = pcr_modify(c, opcr_set_modify, pcr_set_check,
ABORT_ON_BUS_RESET);
@@ -297,21 +321,13 @@ retry_after_bus_reset:
ABORT_ON_BUS_RESET);
if (err == -EAGAIN) {
- fw_iso_resources_free(&c->resources);
- goto retry_after_bus_reset;
+ err = fw_iso_resources_update(&c->resources);
+ if (err >= 0)
+ goto retry_after_bus_reset;
}
- if (err < 0)
- goto err_resources;
-
- c->connected = true;
-
- mutex_unlock(&c->mutex);
-
- return 0;
+ if (err >= 0)
+ c->connected = true;
-err_resources:
- fw_iso_resources_free(&c->resources);
-err_mutex:
mutex_unlock(&c->mutex);
return err;
@@ -351,14 +367,12 @@ int cmp_connection_update(struct cmp_connection *c)
SUCCEED_ON_BUS_RESET);
if (err < 0)
- goto err_resources;
+ goto err_unconnect;
mutex_unlock(&c->mutex);
return 0;
-err_resources:
- fw_iso_resources_free(&c->resources);
err_unconnect:
c->connected = false;
mutex_unlock(&c->mutex);
@@ -395,8 +409,6 @@ void cmp_connection_break(struct cmp_connection *c)
if (err < 0)
cmp_error(c, "plug is still connected\n");
- fw_iso_resources_free(&c->resources);
-
c->connected = false;
mutex_unlock(&c->mutex);