firewire-lib: fix failure to capture MIDI messages in second or more port

amdtp_pull_midi() don't increment a buffer pointer when pointers for MIDI
ports are NULL. This causes failure to capture MIDI messages in devices with
second or more port such like M-Audio Ozonic and ProjectMix I/O.

This bug is reported:
[PATCH 06/39] firewire-lib: Add support for MIDI capture/playback
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074037.html
firewire-lib/bebob: obsolete NULL check before kfree()

To read /mm/slab.c, kfree() check a given pointer whether NULL or not
with ZERO_OR_NULL_PTR(). This commit obsoletes NULL check before calling
kfree().

This bug is reported:
[alsa-devel] [PATCH 09/39] firewire-lib: Add sort function for transmitted packet
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074039.html
firewire-lib: remove initial NULL for pcm pointer in handle_out_packet()

It's needless.

[alsa-devel] [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074038.html
firewire-lib: remove add_transfer_delay()
firewire-lib: rename 'amdtp_stream_callback' to 'amdtp_stream_first_callback'

This function is called just for first callback from Linux Firewire subsystem.
So its name should be with something like 'first' or 'initial'.

[alsa-devel] [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074038.html
firewire-lib: remove needless return in void function

It's needless.

[alsa-devel] [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074038.html
firewire-lib: arrange format for condition

There are no actual differences but maintainer hopes it.

[alsa-devel] [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074036.html
firewire-lib: use NULL instead of ERR_PTR(-1) for sync_slave pointer

This never gives any actual error code.

[alsa-devel] [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074038.html
firewire-lib: change amdtp_stream_set_sync()

I programmed this function as:
 - Clearing a flag at first
 - Setting the flag at last

But the flag was assigned twice. The first operation should be in branch of condition.

[alsa-devel] [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074038.html
firewire-lib: change codes to be a compile time constant

For efficiency.

[alsa-devel] [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074036.html
firewire-lib: normal NULL check for pcm pointer

This pointer doesn't become error pointer.

[alsa-devel] [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074037.html
firewire-lib: use stack to reduce executed opcodes in loop

As long as I know, in this case of write/read fuction, using auto variable
brings an advantage in loop. When I use structure member for loop index,
gcc generates opcodes to compare two registers after pushing the end value
into one of register. When I use auto variable for this purpose, gcc
generates opcodes to compare pointer value and register.

[alsa-devel] [PATCH 11/39] firewire-lib: Add support for channel mapping
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074041.html
firewire-lib: remove confirm to be zero when snd_rawmidi_transmit() fails

The snd_rawmidi_transmit() don't write bytes when failing.

[alsa-devel] [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074037.html
firewire-lib: replace hexadecimap 8bit value to int value

Here I expect compiler to apply widening conversion from int to __be32.

[alsa-devel] [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074037.html
firewire-lib: remove sort processing

I need more time to gather information to persist my reasoning but currently
I don't have...

[alsa-devel] [PATCH 09/39] firewire-lib: Add sort function for transmitted packet
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-March/074157.html
firewire-lib/bebob: Add a quirk for initial tx packets

BeBoB has a quirk for continuity of transmitted packet.
It don't increment dbc at the beginning of its transmittion.

For example, Yamaha GO46:
[13803.762518] 00050000 9001ffff
[13803.762523] 00050000 9001ffff
[13803.762525] 00050000 9001ffff
[13803.762527] 00050000 9001ffff
...
[13804.737925] 00050000 90014a1d
[13804.737927] 00050008 90016387
[13804.737929] 00050010 9001ffff
...

This commit adds a flag named 'skip_initial_tx_packets'. When this flag is true,
in_packets are not handled till dbc is incremented. Once incremented, this flag
becomes false.
firewire-lib: Add checking continuity of data block counter

In IEC 61883-1, the value of dbc refers to the first data block following
a CIP header in current bus packet and a first packet a sequence number with
value zero.
In IEC 61883-6, data block count is running count of transmitted data blocks.

According to these specifications, this commit add codes to check continuity
of data blocks. When detecting discontinuity, streaming is stopped.

I note that discontinuity means there are some packets lost in theory. But
there may be devices which don't report continuous value for dbc field.
firewire-lib/fireworks: Add a quirk for the meaning of dbc

Fireworks has a quirk for the value of dbc field in transmitted packets.
For Fireworks, dbc means the end of events in current packet. This is out
of specification.

For example, AudioFire4:
CIP0	CIP1	Payload
01070092 90FFFFFF 02
0107009A 9001E17B 3A
010700A2 9001F6E5 3A
010700A2 90FFFFFF 02
010700AA 9001104F 3A
010700B2 900125B9 3A
010700BA 90013B23 3A
010700BA 90FFFFFF 02
010700C2 9001548E 3A
010700CA 900169F8 3A
010700CA 90FFFFFF 02
010700D2 90018362 3A
010700DA 900198CC 3A

According to IEC 61883-6, empty packet doesn't increment dbc in next packet.
But for Fireworks, it's incremented and empty packet has dbc which is not be
incremented.

This commit adds a flag for Fireworks and some codes to checking dbc continuity.
firewire-lib/fireworks: Add a quirk for wrong dbs in tx packets

One of Fireworks firmware, named  as 'AudioFire9', seems to transmit
packets with wrong value of dbs. It's always 0x11 but actual size of
data block size is different.

This commit adds a flag for this quirk and some codes to calculate
correct size.
firewire-lib/fireworks: Add a quirk for fixed interval of reported dbc

Fireworks firmware version 5.5 reports fix interval for dbc in each packet.

For example, AudioFire4:
CIP0	CIP1	Payload
00070000 900484FF 72
00070008 9004A8FF 72
00070008 90FFFFFF 02
00070010 9004D0FF 72
00070018 9004C4FF 72
00070020 9004E8FF 72
00070020 90FFFFFF 02
00070028 900410FE 72

The interval of each dbc should be 16 except for empty packet but it's not.

This commit adds a flag for this quirk and codes to refer to a fixed value.