1. 03 1月, 2017 1 次提交
  2. 12 5月, 2016 3 次提交
    • T
      ALSA: firewire-lib: drop skip argument from helper functions to queue a packet · ff38e0c7
      Takashi Sakamoto 提交于
      On most of audio and music units on IEEE 1394 bus which ALSA firewire stack
      supports (or plans to support), CIP with two quadlets header is used.
      Thus, there's no cases to queue packets with blank payload. If such packets
      are going to be queued, it means that they're for skips of the cycle.
      
      This commit simplifies helper functions to queue a packet.
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Acked-by: NClemens Ladisch <clemens@ladisch.de>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      ff38e0c7
    • T
      ALSA: firewire-lib: add context information to tracepoints · a9c4284b
      Takashi Sakamoto 提交于
      In current implementation, packet processing is done in both of software
      IRQ contexts of IR/IT contexts and process contexts.
      
      This is usual interrupt handling of IR/IT context for 1394 OHCI.
      (in hardware IRQ context)
      irq_handler() (drivers/firewire/ohci.c)
      ->tasklet_schedule()
      (in software IRQ context)
      handle_it_packet() or handle_ir_packet_per_buffer() (drivers/firewire/ohci.c)
      ->flush_iso_completions()
        ->struct fw_iso_context.callback.sc()
        = out_stream_callback() or in_stream_callback()
      
      However, we have another chance for packet processing. It's done in PCM
      frame handling via ALSA PCM interfaces.
      (in process context)
      ioctl(i.e. SNDRV_PCM_IOCTL_HWSYNC)
      ->snd_pcm_hwsync() (sound/core/pcm_native.c)
        ->snd_pcm_update_hw_ptr() (sound/core/pcm_lib.c)
          ->snd_pcm_update_hw_ptr0()
            ->struct snd_pcm_ops.pointer()
            = amdtp_stream_pcm_pointer()
              ->fw_iso_context_flush_completions() (drivers/firewire/core-iso.c)
                ->struct fw_card_driver.flush_iso_completions()
                = ohci_flush_iso_completions() (drivers/firewire/ohci.c)
                  ->flush_iso_completions()
                    ->struct fw_iso_context.callback.sc()
                    = out_stream_callback() or in_stream_callback()
      
      This design is for a better granularity of PCM pointer. When ioctl(2) is
      executed with some commands for ALSA PCM interface, queued packets are
      handled at first. Then, the latest number of handled PCM frames is
      reported. The number can represent PCM frames transferred in most near
      isochronous cycle.
      
      Current tracepoints include no information to distinguish running contexts.
      When tracing the interval of software IRQ context, this is not good.
      
      This commit adds more information for current context. Additionally, the
      index of packet processed in one context is added in a case that packet
      processing is executed in continuous context of the same kind,
      
      As a result, the output includes 11 fields with additional two fields
      to commit 0c95c1d6 ("ALSA: firewire-lib: add tracepoints to dump a part
      of isochronous packet data"):
      17131.9186: out_packet: 07 7494 ffc0 ffc1 00 000700c0 9001a496 058 45 1 13
      17131.9186: out_packet: 07 7495 ffc0 ffc1 00 000700c8 9001ba00 058 46 1 14
      17131.9186: out_packet: 07 7496 ffc0 ffc1 00 000700d0 9001ffff 002 47 1 15
      17131.9189: out_packet: 07 7497 ffc0 ffc1 00 000700d0 9001d36a 058 00 0 00
      17131.9189: out_packet: 07 7498 ffc0 ffc1 00 000700d8 9001e8d4 058 01 0 01
      17131.9189: out_packet: 07 7499 ffc0 ffc1 00 000700e0 9001023e 058 02 0 00
      17131.9206: in_packet:  07 7447 ffc1 ffc0 01 3f070072 9001783d 058 32 1 00
      17131.9206: in_packet:  07 7448 ffc1 ffc0 01 3f070072 90ffffff 002 33 1 01
      17131.9206: in_packet:  07 7449 ffc1 ffc0 01 3f07007a 900191a8 058 34 1 02
      (Here, some common fields are omitted so that a line is within 80
      characters.)
      
      The legend is:
       - The second of cycle scheduled for the packet
       - The count of cycle scheduled for the packet
       - The ID of node as source (hex)
       - The ID of node as destination (hex)
       - The value of isochronous channel
       - The first quadlet of CIP header (hex)
       - The second quadlet of CIP header (hex)
       - The number of included quadlets
       - The index of packet in a buffer maintained by this module
       - 0 in process context, 1 in IRQ context
       - The index of packet processed in the context
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      a9c4284b
    • T
      ALSA: firewire-lib: permit to flush queued packets only in process context for... · 1dba9db0
      Takashi Sakamoto 提交于
      ALSA: firewire-lib: permit to flush queued packets only in process context for better PCM period granularity
      
      These three commits were merged to improve PCM pointer granularity.
      commit 76fb8789 ("ALSA: firewire-lib: taskletize the snd_pcm_period_elapsed() call")
      commit e9148ddd ("ALSA: firewire-lib: flush completed packets when reading PCM position")
      commit 92b862c7 ("ALSA: firewire-lib: optimize packet flushing")
      
      The point of them is to handle queued packets not only in software IRQ
      context of IR/IT contexts, but also in process context. As a result of
      handling packets, period tasklet is scheduled when acrossing PCM period
      boundary. This is to prevent recursive call of
      'struct snd_pcm_ops.pointer()' in the same context.
      
      When the pointer callback is executed in the process context, it's
      better to avoid the second callback in the software IRQ context. The
      software IRQ context runs immediately after scheduled in the process
      context because few packets are queued yet.
      
      For the aim, 'pointer_flush' is used, however it causes a race condition
      between the process context and software IRQ context of IR/IT contexts.
      
      Practically, this race is not so critical because it influences process
      context to skip flushing queued packet and to get worse granularity of
      PCM pointer. The race condition is quite rare but it should be improved
      for stable service.
      
      The similar effect can be achieved by using 'in_interrupt()' macro. This
      commit obsoletes 'pointer_flush' with it.
      Acked-by: NClemens Ladisch <clemens@ladisch.de>
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      1dba9db0
  3. 10 5月, 2016 4 次提交
  4. 09 5月, 2016 3 次提交
    • T
      ALSA: firewire-lib: add tracepoints to dump a part of isochronous packet data · 0c95c1d6
      Takashi Sakamoto 提交于
      When audio and music units have some quirks in their sequence of packet,
      it's really hard for non-owners to identify the quirks. Although developers
      need dumps for sequence of packets, it's difficult for users who have no
      knowledges and no equipments for this purpose.
      
      This commit adds tracepoints for this situation. When users encounter
      the issue, they can dump a part of packet data via Linux tracing framework
      as long as using drivers in ALSA firewire stack.
      
      Additionally, tracepoints for outgoing packets will be our help to check
      and debug packet processing of ALSA firewire stack.
      
      This commit newly adds 'snd_firewire_lib' subsystem with 'in_packet' and
      'out_packet' events. In the events, some attributes of packets and the
      index of packet managed by this module are recorded per packet.
      
      This is an usage:
      
      $ trace-cmd record -e snd_firewire_lib:out_packet \
                         -e snd_firewire_lib:in_packet
      /sys/kernel/tracing/events/snd_firewire_lib/out_packet/filter
      /sys/kernel/tracing/events/snd_firewire_lib/in_packet/filter
      Hit Ctrl^C to stop recording
      ^C
      $ trace-cmd report trace.dat
      ...
      23647.033934: in_packet:  01 4073 ffc0 ffc1 00 000f0040 9001b2d1 122 44
      23647.033936: in_packet:  01 4074 ffc0 ffc1 00 000f0048 9001c83b 122 45
      23647.033937: in_packet:  01 4075 ffc0 ffc1 00 000f0050 9001ffff 002 46
      23647.033938: in_packet:  01 4076 ffc0 ffc1 00 000f0050 9001e1a6 122 47
      23647.035426: out_packet: 01 4123 ffc1 ffc0 01 010f00d0 9001fb40 122 17
      23647.035428: out_packet: 01 4124 ffc1 ffc0 01 010f00d8 9001ffff 002 18
      23647.035429: out_packet: 01 4125 ffc1 ffc0 01 010f00d8 900114aa 122 19
      23647.035430: out_packet: 01 4126 ffc1 ffc0 01 010f00e0 90012a15 122 20
      (Here, some common fields are omitted so that a line to be within 80
      characters.)
      ...
      
      One line represent one packet. The legend for the last nine fields is:
       - The second of cycle scheduled for the packet
       - The count of cycle scheduled for the packet
       - The ID of node as source (hex)
        - Some devices transfer packets with invalid source node ID in their CIP
          header.
       - The ID of node as destination (hex)
        - The value is not in CIP header of packets.
       - The value of isochronous channel
       - The first quadlet of CIP header (hex)
       - The second quadlet of CIP header (hex)
       - The number of included quadlets
       - The index of packet in a buffer maintained by this module
      
      This is an example to parse these lines from text file by Python3 script:
      
      \#!/usr/bin/env python3
      import sys
      
      def parse_ts(second, cycle, syt):
          offset = syt & 0xfff
          syt >>= 12
          if cycle & 0x0f > syt:
              cycle += 0x10
          cycle &= 0x1ff0
          cycle |= syt
          second += cycle // 8000
          cycle %= 8000
          # In CYCLE_TIMER of 1394 OHCI, second is represented in 8 bit.
          second %= 128
          return (second, cycle, offset)
      
      def calc_ts(second, cycle, offset):
          ts = offset
          ts += cycle * 3072
          # In DMA descriptor of 1394 OHCI, second is represented in 3 bit.
          ts += (second % 8) * 8000 * 3072
          return ts
      
      def subtract_ts(minuend, subtrahend):
          # In DMA descriptor of 1394 OHCI, second is represented in 3 bit.
          if minuend < subtrahend:
              minuend += 8 * 8000 * 3072
          return minuend - subtrahend
      
      if len(sys.argv) != 2:
          print('At least, one argument is required for packet dump.')
          sys.exit()
      
      filename = sys.argv[1]
      
      data = []
      
      prev = 0
      with open(filename, 'r') as f:
          for line in f:
              pos = line.find('packet:')
              if pos < 0:
                  continue
      
              pos += len('packet:')
              line = line[pos:].strip()
              fields = line.split(' ')
      
              datum = []
      
              datum.append(fields[8])
      
              syt = int(fields[6][4:], 16)
      
              # Empty packet in IEC 61883-1, or NODATA in IEC 61883-6
              if syt == 0xffff:
                  data_blocks = 0
              else:
                  payload_size = int(fields[7], 10)
                  data_block_size = int(fields[5][2:4], 16)
                  data_blocks = (payload_size - 2) / data_block_size
              datum.append(data_blocks)
      
              second = int(fields[0], 10)
              cycle = int(fields[1], 10)
              start = (second << 25) | (cycle << 12)
              datum.append('0x{0:08x}'.format(start))
              start = calc_ts(second, cycle, 0)
      
              datum.append("0x" + fields[5])
              datum.append("0x" + fields[6])
      
              if syt == 0xffff:
                  second = 0
                  cycle = 0
                  tick = 0
              else:
                  second, cycle, tick = parse_ts(second, cycle, syt)
              ts = calc_ts(second, cycle, tick)
              datum.append(start)
              datum.append(ts)
              if ts == 0:
                  datum.append(0)
                  datum.append(0)
              else:
                  # Usual case, or a case over 8 seconds.
                  if ts > start or start > 7 * 8000 * 3072:
                      datum.append(subtract_ts(ts, start))
                      if ts > prev or start > 7 * 8000 * 3072:
                          gap = subtract_ts(ts, prev)
                          datum.append(gap)
                      else:
                          datum.append('backward')
                  else:
                      datum.append('invalid')
                  prev = ts
      
              data.append(datum)
      
      sys.exit()
      
      The data variable includes array with these elements:
      - The index of the packet
      - The number of data blocks in the packet
      - The value of cycle count (hex)
      - The value of CIP header 1 (hex)
      - The value of CIP header 2 (hex)
      - The value of cycle count (tick)
      - The value of calculated presentation timestamp (tick)
      - The offset between the cycle count and presentation timestamp
      - The elapsed ticks from the previous presentation timestamp
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      0c95c1d6
    • T
      ALSA: firewire-lib: compute the value of second field in cycle count for IR context · f90e2ded
      Takashi Sakamoto 提交于
      In callback function of isochronous context, modules can queue packets to
      indicated isochronous cycles. Although the cycle to queue a packet is
      deterministic by calculation, this module doesn't implement the calculation
      because it's useless for processing.
      
      In future, the cycle count is going to be printed with the other parameters
      for debugging. This commit is the preparation. The cycle count is computed
      by cycle unit, and correctly arranged to corresponding packets. The
      calculated count is used in later commit.
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      f90e2ded
    • T
      ALSA: firewire-lib: compute the value of second field in cycle count for IT context · 73fc7f08
      Takashi Sakamoto 提交于
      In callback function of isochronous context, u32 variable is passed for
      cycle count. The value of this variable comes from DMA descriptors of 1394
      Open Host Controller Interface (1394 OHCI). In the specification, DMA
      descriptors transport lower 3 bits for second field and full cycle field in
      16 bits field, therefore 16 bits of the u32 variable are available. The
      value for second is modulo 8, and the value for cycle is modulo 8,000.
      
      Currently, ALSA firewire-lib module don't use the value of the second
      field, because the value is useless to calculate presentation timestamp in
      IEC 61883-6. However, the value may be useful for debugging. In later
      commit, it will be printed with the other parameters for debugging.
      
      This commit makes this module to handle the whole cycle count including
      second. The value is calculated by cycle unit. The existed code is already
      written with ignoring the value of second, thus this commit causes no
      issues.
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      73fc7f08
  5. 31 3月, 2016 1 次提交
  6. 12 10月, 2015 1 次提交
    • T
      ALSA: firewire-lib: continue packet processing at detecting wrong CIP headers · 2a7e1713
      Takashi Sakamoto 提交于
      In firewire-lib, isochronous packet streaming is stopped when detecting
      wrong value for FMT field of CIP headers. Although this is appropriate
      to IEC 61883-1 and 6, some BeBoB based devices with vendors' customization
      use invalid value to FMT field of CIP headers in the beginning of
      streaming.
      
      $ journalctl
        snd-bebob fw1.0: Detect unexpected protocol: 01000000 8000ffff
      
      I got this log with M-Audio FireWire 1814. In this line, the value of FMT
      field is 0x00, while it should be 0x10 in usual AMDTP.
      
      Except for the beginning, these devices continue to transfer packets with
      valid value for FMT field, except for the beginning. Therefore, in this
      case, firewire-lib should continue to process packets. The former
      implementation of firewire-lib performs it.
      
      This commit loosens the handling of wrong value, to continue packet
      processing in the case.
      
      Fixes: 414ba022 ('ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header')
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      2a7e1713
  7. 29 9月, 2015 12 次提交
  8. 05 8月, 2015 1 次提交
    • T
      ALSA: fireworks/firewire-lib: add support for recent firmware quirk · 18f5ed36
      Takashi Sakamoto 提交于
      Fireworks uses TSB43CB43(IceLynx-Micro) as its IEC 61883-1/6 interface.
      This chip includes ARM7 core, and loads and runs program. The firmware
      is stored in on-board memory and loaded every powering-on from it.
      
      Echo Audio ships several versions of firmwares for each model. These
      firmwares have each quirk and the quirk changes a sequence of packets.
      
      As long as I investigated, AudioFire2/AudioFire4/AudioFirePre8 have a
      quirk to transfer a first packet with 0x02 in its dbc field. This causes
      ALSA Fireworks driver to detect discontinuity. In this case, firmware
      version 5.7.0, 5.7.3 and 5.8.0 are used.
      
      Payload  CIP      CIP
      quadlets header1  header2
      02       00050002 90ffffff <-
      42       0005000a 90013000
      42       00050012 90014400
      42       0005001a 90015800
      02       0005001a 90ffffff
      42       00050022 90019000
      42       0005002a 9001a400
      42       00050032 9001b800
      02       00050032 90ffffff
      42       0005003a 9001d000
      42       00050042 9001e400
      42       0005004a 9001f800
      02       0005004a 90ffffff
      (AudioFire2 with firmware version 5.7.)
      
      $ dmesg
      snd-fireworks fw1.0: Detect discontinuity of CIP: 00 02
      
      These models, AudioFire8 (since Jul 2009 ) and Gibson Robot Interface
      Pack series uses the same ARM binary as their firmware. Thus, this
      quirk may be observed among them.
      
      This commit adds a new member for AMDTP structure. This member represents
      the value of dbc field in a first AMDTP packet. Drivers can set it with
      a preferred value according to model's quirk.
      Tested-by: NJohannes Oertei <johannes.oertel@uni-due.de>
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      18f5ed36
  9. 27 5月, 2015 1 次提交
    • T
      ALSA: firewire-lib: fix buffer-over-run when detecting packet discontinuity · 31ea49ba
      Takashi Sakamoto 提交于
      When detecting packet discontinuity, handle_in_packet() returns minus value
      and this value is assigned to unsigned int variable, then the variable has
      huge value. As a result, the variable causes buffer-over-run in
      handle_out_packet(). This brings invalid page request and system hangup.
      
      This commit fixes the bug to add a new argument into handle_in_packet()
      and the number of handled data blocks is assignd to it. The function
      return value is just used to check error.
      
      I also considered to change the type of local variable to 'int' in
      in_stream_callback(). This idea is based on type-conversion in C standard,
      while it may cause future problems when adding more works. Thus, I dropped
      this idea.
      
      Fixes: 6fc6b9ce('ALSA: firewire-lib: pass the number of data blocks in incoming packets to outgoing packets')
      Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      31ea49ba
  10. 24 5月, 2015 4 次提交
  11. 23 5月, 2015 5 次提交
  12. 10 3月, 2015 1 次提交
  13. 23 2月, 2015 2 次提交
  14. 17 1月, 2015 1 次提交